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_all(struct sock_fprog
*bpf
);
18 extern int bpf_validate(const struct sock_fprog
*bpf
);
19 extern uint32_t bpf_run_filter(const struct sock_fprog
*bpf
, uint8_t *packet
,
21 extern void bpf_attach_to_sock(int sock
, struct sock_fprog
*bpf
);
22 extern void bpf_detach_from_sock(int sock
);
23 extern void enable_kernel_bpf_jit_compiler(void);
24 extern void bpf_parse_rules(char *rulefile
, struct sock_fprog
*bpf
);
26 static inline void bpf_release(struct sock_fprog
*bpf
)
32 * The instruction encodings.
34 /* instruction classes */
35 #define BPF_CLASS(code) ((code) & 0x07)
46 #define BPF_SIZE(code) ((code) & 0x18)
50 #define BPF_MODE(code) ((code) & 0xe0)
59 #define BPF_OP(code) ((code) & 0xf0)
74 #define BPF_SRC(code) ((code) & 0x08)
78 /* ret - BPF_K and BPF_X also apply */
79 #define BPF_RVAL(code) ((code) & 0x18)
83 #define BPF_MISCOP(code) ((code) & 0xf8)
87 /* Hidden Linux kernel BPF extensions */
89 * RATIONALE. Negative offsets are invalid in BPF.
90 * We use them to reference ancillary data.
91 * Unlike introduction new instructions, it does not break
92 * existing compilers/optimizers.
96 # define SKF_AD_OFF (-0x1000)
98 #ifndef SKF_AD_PROTOCOL
99 # define SKF_AD_PROTOCOL 0
101 #ifndef SKF_AD_PKTTYPE
102 # define SKF_AD_PKTTYPE 4
104 #ifndef SKF_AD_IFINDEX
105 # define SKF_AD_IFINDEX 8
107 #ifndef SKF_AD_NLATTR
108 # define SKF_AD_NLATTR 12
110 #ifndef SKF_AD_NLATTR_NEST
111 # define SKF_AD_NLATTR_NEST 16
114 # define SKF_AD_MARK 20
117 # define SKF_AD_QUEUE 24
119 #ifndef SKF_AD_HATYPE
120 # define SKF_AD_HATYPE 28
122 #ifndef SKF_AD_RXHASH
123 # define SKF_AD_RXHASH 32
126 # define SKF_AD_CPU 36