2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
11 #include <linux/filter.h>
17 extern void bpf_dump_op_table(void);
18 extern void bpf_dump_all(struct sock_fprog
*bpf
);
19 extern int bpf_validate(const struct sock_fprog
*bpf
);
20 extern uint32_t bpf_run_filter(const struct sock_fprog
*bpf
, uint8_t *packet
,
22 extern void bpf_attach_to_sock(int sock
, struct sock_fprog
*bpf
);
23 extern void bpf_detach_from_sock(int sock
);
24 extern void enable_kernel_bpf_jit_compiler(void);
25 extern void bpf_parse_rules(char *rulefile
, struct sock_fprog
*bpf
);
27 static inline void bpf_release(struct sock_fprog
*bpf
)
33 * The instruction encodings.
35 /* instruction classes */
36 #define BPF_CLASS(code) ((code) & 0x07)
47 #define BPF_SIZE(code) ((code) & 0x18)
51 #define BPF_MODE(code) ((code) & 0xe0)
60 #define BPF_OP(code) ((code) & 0xf0)
78 #define BPF_SRC(code) ((code) & 0x08)
82 /* ret - BPF_K and BPF_X also apply */
83 #define BPF_RVAL(code) ((code) & 0x18)
87 #define BPF_MISCOP(code) ((code) & 0xf8)
91 /* Hidden Linux kernel BPF extensions */
93 * RATIONALE. Negative offsets are invalid in BPF.
94 * We use them to reference ancillary data.
95 * Unlike introduction new instructions, it does not break
96 * existing compilers/optimizers.
100 # define SKF_AD_OFF (-0x1000)
102 #ifndef SKF_AD_PROTOCOL
103 # define SKF_AD_PROTOCOL 0
105 #ifndef SKF_AD_PKTTYPE
106 # define SKF_AD_PKTTYPE 4
108 #ifndef SKF_AD_IFINDEX
109 # define SKF_AD_IFINDEX 8
111 #ifndef SKF_AD_NLATTR
112 # define SKF_AD_NLATTR 12
114 #ifndef SKF_AD_NLATTR_NEST
115 # define SKF_AD_NLATTR_NEST 16
118 # define SKF_AD_MARK 20
121 # define SKF_AD_QUEUE 24
123 #ifndef SKF_AD_HATYPE
124 # define SKF_AD_HATYPE 28
126 #ifndef SKF_AD_RXHASH
127 # define SKF_AD_RXHASH 32
130 # define SKF_AD_CPU 36
132 #ifndef SKF_AD_VLAN_TAG
133 # define SKF_AD_VLAN_TAG 44
135 #ifndef SKF_AD_VLAN_TAG_PRESENT
136 # define SKF_AD_VLAN_TAG_PRESENT 48