xutils: break out string handling and locking
[netsniff-ng.git] / bpf.h
blob942f54e6764876d6147b582a7da238d9e54e6e87
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #ifndef BPF_I_H
8 #define BPF_I_H
10 #include <linux/filter.h>
11 #include <stdint.h>
12 #include <stdlib.h>
14 #include "xmalloc.h"
16 extern void bpf_dump_op_table(void);
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,
20 size_t plen);
21 extern void bpf_attach_to_sock(int sock, struct sock_fprog *bpf);
22 extern void bpf_detach_from_sock(int sock);
23 extern int enable_kernel_bpf_jit_compiler(void);
24 extern void bpf_parse_rules(char *rulefile, struct sock_fprog *bpf, uint32_t link_type);
25 #ifdef __WITH_TCPDUMP_LIKE_FILTER
26 extern void bpf_try_compile(const char *rulefile, struct sock_fprog *bpf,
27 uint32_t link_type);
28 #else
29 static inline void bpf_try_compile(const char *rulefile,
30 struct sock_fprog *bpf __maybe_unused,
31 uint32_t link_type __maybe_unused)
33 panic("Cannot open file %s!\n", rulefile);
35 #endif
37 static inline void bpf_release(struct sock_fprog *bpf)
39 free(bpf->filter);
42 #define BPF_CLASS(code) ((code) & 0x07)
43 #define BPF_LD 0x00
44 #define BPF_LDX 0x01
45 #define BPF_ST 0x02
46 #define BPF_STX 0x03
47 #define BPF_ALU 0x04
48 #define BPF_JMP 0x05
49 #define BPF_RET 0x06
50 #define BPF_MISC 0x07
52 #define BPF_SIZE(code) ((code) & 0x18)
53 #define BPF_W 0x00
54 #define BPF_H 0x08
55 #define BPF_B 0x10
57 #define BPF_MODE(code) ((code) & 0xe0)
58 #define BPF_IMM 0x00
59 #define BPF_ABS 0x20
60 #define BPF_IND 0x40
61 #define BPF_MEM 0x60
62 #define BPF_LEN 0x80
63 #define BPF_MSH 0xa0
65 #define BPF_OP(code) ((code) & 0xf0)
66 #define BPF_ADD 0x00
67 #define BPF_SUB 0x10
68 #define BPF_MUL 0x20
69 #define BPF_DIV 0x30
70 #define BPF_OR 0x40
71 #define BPF_AND 0x50
72 #define BPF_LSH 0x60
73 #define BPF_RSH 0x70
74 #define BPF_NEG 0x80
75 #define BPF_MOD 0x90
76 #define BPF_XOR 0xa0
78 #define BPF_JA 0x00
79 #define BPF_JEQ 0x10
80 #define BPF_JGT 0x20
81 #define BPF_JGE 0x30
82 #define BPF_JSET 0x40
84 #define BPF_SRC(code) ((code) & 0x08)
85 #define BPF_K 0x00
86 #define BPF_X 0x08
88 /* ret - BPF_K and BPF_X also apply */
89 #define BPF_RVAL(code) ((code) & 0x18)
90 #define BPF_A 0x10
92 #define BPF_MISCOP(code) ((code) & 0xf8)
93 #define BPF_TAX 0x00
94 #define BPF_TXA 0x80
96 #ifndef SKF_AD_OFF
97 # define SKF_AD_OFF (-0x1000)
98 #endif
99 #ifndef SKF_AD_PROTOCOL
100 # define SKF_AD_PROTOCOL 0
101 #endif
102 #ifndef SKF_AD_PKTTYPE
103 # define SKF_AD_PKTTYPE 4
104 #endif
105 #ifndef SKF_AD_IFINDEX
106 # define SKF_AD_IFINDEX 8
107 #endif
108 #ifndef SKF_AD_NLATTR
109 # define SKF_AD_NLATTR 12
110 #endif
111 #ifndef SKF_AD_NLATTR_NEST
112 # define SKF_AD_NLATTR_NEST 16
113 #endif
114 #ifndef SKF_AD_MARK
115 # define SKF_AD_MARK 20
116 #endif
117 #ifndef SKF_AD_QUEUE
118 # define SKF_AD_QUEUE 24
119 #endif
120 #ifndef SKF_AD_HATYPE
121 # define SKF_AD_HATYPE 28
122 #endif
123 #ifndef SKF_AD_RXHASH
124 # define SKF_AD_RXHASH 32
125 #endif
126 #ifndef SKF_AD_CPU
127 # define SKF_AD_CPU 36
128 #endif
129 #ifndef SKF_AD_VLAN_TAG
130 # define SKF_AD_VLAN_TAG 44
131 #endif
132 #ifndef SKF_AD_VLAN_TAG_PRESENT
133 # define SKF_AD_VLAN_TAG_PRESENT 48
134 #endif
135 #ifndef SKF_AD_PAY_OFFSET
136 # define SKF_AD_PAY_OFFSET 52
137 #endif
139 #endif /* BPF_I_H */