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>
14 extern void bpf_dump_all(struct sock_fprog
*bpf
);
15 extern int bpf_validate(const struct sock_fprog
*bpf
);
16 extern uint32_t bpf_run_filter(const struct sock_fprog
*bpf
, uint8_t *packet
,
18 extern void bpf_attach_to_sock(int sock
, struct sock_fprog
*bpf
);
19 extern void bpf_detach_from_sock(int sock
);
20 extern void enable_kernel_bpf_jit_compiler(void);
21 extern void bpf_parse_rules(char *rulefile
, struct sock_fprog
*bpf
);
24 * The instruction encodings.
26 /* instruction classes */
27 #define BPF_CLASS(code) ((code) & 0x07)
38 #define BPF_SIZE(code) ((code) & 0x18)
42 #define BPF_MODE(code) ((code) & 0xe0)
51 #define BPF_OP(code) ((code) & 0xf0)
66 #define BPF_SRC(code) ((code) & 0x08)
70 /* ret - BPF_K and BPF_X also apply */
71 #define BPF_RVAL(code) ((code) & 0x18)
75 #define BPF_MISCOP(code) ((code) & 0xf8)
79 /* Hidden Linux kernel BPF extensions */
81 * RATIONALE. Negative offsets are invalid in BPF.
82 * We use them to reference ancillary data.
83 * Unlike introduction new instructions, it does not break
84 * existing compilers/optimizers.
88 # define SKF_AD_OFF (-0x1000)
90 #ifndef SKF_AD_PROTOCOL
91 # define SKF_AD_PROTOCOL 0
93 #ifndef SKF_AD_PKTTYPE
94 # define SKF_AD_PKTTYPE 4
96 #ifndef SKF_AD_IFINDEX
97 # define SKF_AD_IFINDEX 8
100 # define SKF_AD_NLATTR 12
102 #ifndef SKF_AD_NLATTR_NEST
103 # define SKF_AD_NLATTR_NEST 16
106 # define SKF_AD_MARK 20
109 # define SKF_AD_QUEUE 24
111 #ifndef SKF_AD_HATYPE
112 # define SKF_AD_HATYPE 28
114 #ifndef SKF_AD_RXHASH
115 # define SKF_AD_RXHASH 32
118 # define SKF_AD_CPU 36