Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  * Linux Socket Filter Data Structures
0004  */
0005 
0006 #ifndef __LINUX_FILTER_H__
0007 #define __LINUX_FILTER_H__
0008 
0009 
0010 #include <linux/types.h>
0011 #include <linux/bpf_common.h>
0012 
0013 /*
0014  * Current version of the filter code architecture.
0015  */
0016 #define BPF_MAJOR_VERSION 1
0017 #define BPF_MINOR_VERSION 1
0018 
0019 /*
0020  *  Try and keep these values and structures similar to BSD, especially
0021  *  the BPF code definitions which need to match so you can share filters
0022  */
0023  
0024 struct sock_filter {    /* Filter block */
0025     __u16   code;   /* Actual filter code */
0026     __u8    jt; /* Jump true */
0027     __u8    jf; /* Jump false */
0028     __u32   k;      /* Generic multiuse field */
0029 };
0030 
0031 struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
0032     unsigned short      len;    /* Number of filter blocks */
0033     struct sock_filter *filter;
0034 };
0035 
0036 /* ret - BPF_K and BPF_X also apply */
0037 #define BPF_RVAL(code)  ((code) & 0x18)
0038 #define         BPF_A           0x10
0039 
0040 /* misc */
0041 #define BPF_MISCOP(code) ((code) & 0xf8)
0042 #define         BPF_TAX         0x00
0043 #define         BPF_TXA         0x80
0044 
0045 /*
0046  * Macros for filter block array initializers.
0047  */
0048 #ifndef BPF_STMT
0049 #define BPF_STMT(code, k) { (unsigned short)(code), 0, 0, k }
0050 #endif
0051 #ifndef BPF_JUMP
0052 #define BPF_JUMP(code, k, jt, jf) { (unsigned short)(code), jt, jf, k }
0053 #endif
0054 
0055 /*
0056  * Number of scratch memory words for: BPF_ST and BPF_STX
0057  */
0058 #define BPF_MEMWORDS 16
0059 
0060 /* RATIONALE. Negative offsets are invalid in BPF.
0061    We use them to reference ancillary data.
0062    Unlike introduction new instructions, it does not break
0063    existing compilers/optimizers.
0064  */
0065 #define SKF_AD_OFF    (-0x1000)
0066 #define SKF_AD_PROTOCOL 0
0067 #define SKF_AD_PKTTYPE  4
0068 #define SKF_AD_IFINDEX  8
0069 #define SKF_AD_NLATTR   12
0070 #define SKF_AD_NLATTR_NEST  16
0071 #define SKF_AD_MARK     20
0072 #define SKF_AD_QUEUE    24
0073 #define SKF_AD_HATYPE   28
0074 #define SKF_AD_RXHASH   32
0075 #define SKF_AD_CPU  36
0076 #define SKF_AD_ALU_XOR_X    40
0077 #define SKF_AD_VLAN_TAG 44
0078 #define SKF_AD_VLAN_TAG_PRESENT 48
0079 #define SKF_AD_PAY_OFFSET   52
0080 #define SKF_AD_RANDOM   56
0081 #define SKF_AD_VLAN_TPID    60
0082 #define SKF_AD_MAX  64
0083 
0084 #define SKF_NET_OFF (-0x100000)
0085 #define SKF_LL_OFF  (-0x200000)
0086 
0087 #define BPF_NET_OFF SKF_NET_OFF
0088 #define BPF_LL_OFF  SKF_LL_OFF
0089 
0090 #endif /* __LINUX_FILTER_H__ */