xref: /linux/include/uapi/linux/filter.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*6f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells /*
3607ca46eSDavid Howells  * Linux Socket Filter Data Structures
4607ca46eSDavid Howells  */
5607ca46eSDavid Howells 
6607ca46eSDavid Howells #ifndef _UAPI__LINUX_FILTER_H__
7607ca46eSDavid Howells #define _UAPI__LINUX_FILTER_H__
8607ca46eSDavid Howells 
9607ca46eSDavid Howells #include <linux/compiler.h>
10607ca46eSDavid Howells #include <linux/types.h>
11c15952dcSAlexei Starovoitov #include <linux/bpf_common.h>
12607ca46eSDavid Howells 
13607ca46eSDavid Howells /*
14607ca46eSDavid Howells  * Current version of the filter code architecture.
15607ca46eSDavid Howells  */
16607ca46eSDavid Howells #define BPF_MAJOR_VERSION 1
17607ca46eSDavid Howells #define BPF_MINOR_VERSION 1
18607ca46eSDavid Howells 
19607ca46eSDavid Howells /*
20607ca46eSDavid Howells  *	Try and keep these values and structures similar to BSD, especially
21607ca46eSDavid Howells  *	the BPF code definitions which need to match so you can share filters
22607ca46eSDavid Howells  */
23607ca46eSDavid Howells 
24607ca46eSDavid Howells struct sock_filter {	/* Filter block */
25607ca46eSDavid Howells 	__u16	code;   /* Actual filter code */
26607ca46eSDavid Howells 	__u8	jt;	/* Jump true */
27607ca46eSDavid Howells 	__u8	jf;	/* Jump false */
28607ca46eSDavid Howells 	__u32	k;      /* Generic multiuse field */
29607ca46eSDavid Howells };
30607ca46eSDavid Howells 
31607ca46eSDavid Howells struct sock_fprog {	/* Required for SO_ATTACH_FILTER. */
32607ca46eSDavid Howells 	unsigned short		len;	/* Number of filter blocks */
33607ca46eSDavid Howells 	struct sock_filter __user *filter;
34607ca46eSDavid Howells };
35607ca46eSDavid Howells 
36607ca46eSDavid Howells /* ret - BPF_K and BPF_X also apply */
37607ca46eSDavid Howells #define BPF_RVAL(code)  ((code) & 0x18)
38607ca46eSDavid Howells #define         BPF_A           0x10
39607ca46eSDavid Howells 
40607ca46eSDavid Howells /* misc */
41607ca46eSDavid Howells #define BPF_MISCOP(code) ((code) & 0xf8)
42607ca46eSDavid Howells #define         BPF_TAX         0x00
43607ca46eSDavid Howells #define         BPF_TXA         0x80
44607ca46eSDavid Howells 
45607ca46eSDavid Howells /*
46607ca46eSDavid Howells  * Macros for filter block array initializers.
47607ca46eSDavid Howells  */
48607ca46eSDavid Howells #ifndef BPF_STMT
49607ca46eSDavid Howells #define BPF_STMT(code, k) { (unsigned short)(code), 0, 0, k }
50607ca46eSDavid Howells #endif
51607ca46eSDavid Howells #ifndef BPF_JUMP
52607ca46eSDavid Howells #define BPF_JUMP(code, k, jt, jf) { (unsigned short)(code), jt, jf, k }
53607ca46eSDavid Howells #endif
54607ca46eSDavid Howells 
55607ca46eSDavid Howells /*
56607ca46eSDavid Howells  * Number of scratch memory words for: BPF_ST and BPF_STX
57607ca46eSDavid Howells  */
58607ca46eSDavid Howells #define BPF_MEMWORDS 16
59607ca46eSDavid Howells 
60607ca46eSDavid Howells /* RATIONALE. Negative offsets are invalid in BPF.
61607ca46eSDavid Howells    We use them to reference ancillary data.
62607ca46eSDavid Howells    Unlike introduction new instructions, it does not break
63607ca46eSDavid Howells    existing compilers/optimizers.
64607ca46eSDavid Howells  */
65607ca46eSDavid Howells #define SKF_AD_OFF    (-0x1000)
66607ca46eSDavid Howells #define SKF_AD_PROTOCOL 0
67607ca46eSDavid Howells #define SKF_AD_PKTTYPE 	4
68607ca46eSDavid Howells #define SKF_AD_IFINDEX 	8
69607ca46eSDavid Howells #define SKF_AD_NLATTR	12
70607ca46eSDavid Howells #define SKF_AD_NLATTR_NEST	16
71607ca46eSDavid Howells #define SKF_AD_MARK 	20
72607ca46eSDavid Howells #define SKF_AD_QUEUE	24
73607ca46eSDavid Howells #define SKF_AD_HATYPE	28
74607ca46eSDavid Howells #define SKF_AD_RXHASH	32
75607ca46eSDavid Howells #define SKF_AD_CPU	36
76607ca46eSDavid Howells #define SKF_AD_ALU_XOR_X	40
77f3335031SEric Dumazet #define SKF_AD_VLAN_TAG	44
78f3335031SEric Dumazet #define SKF_AD_VLAN_TAG_PRESENT 48
793e5289d5SDaniel Borkmann #define SKF_AD_PAY_OFFSET	52
804cd3675eSChema Gonzalez #define SKF_AD_RANDOM	56
8127cd5452SMichal Sekletar #define SKF_AD_VLAN_TPID	60
8227cd5452SMichal Sekletar #define SKF_AD_MAX	64
83a166151cSAlexei Starovoitov 
84607ca46eSDavid Howells #define SKF_NET_OFF	(-0x100000)
85607ca46eSDavid Howells #define SKF_LL_OFF	(-0x200000)
86607ca46eSDavid Howells 
87a166151cSAlexei Starovoitov #define BPF_NET_OFF	SKF_NET_OFF
88a166151cSAlexei Starovoitov #define BPF_LL_OFF	SKF_LL_OFF
89607ca46eSDavid Howells 
90607ca46eSDavid Howells #endif /* _UAPI__LINUX_FILTER_H__ */
91