dissector: ip_authentication_hdr: Remove trailing whitespaces
[netsniff-ng.git] / bpf.h
blob07631d62b51ec6355322864afab31d4a9eef1c62
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, struct sock_fprog *bpf,
30 uint32_t link_type)
32 panic("Cannot open file %s!\n", rulefile);
34 #endif
36 static inline void bpf_release(struct sock_fprog *bpf)
38 free(bpf->filter);
41 #define BPF_CLASS(code) ((code) & 0x07)
42 #define BPF_LD 0x00
43 #define BPF_LDX 0x01
44 #define BPF_ST 0x02
45 #define BPF_STX 0x03
46 #define BPF_ALU 0x04
47 #define BPF_JMP 0x05
48 #define BPF_RET 0x06
49 #define BPF_MISC 0x07
51 #define BPF_SIZE(code) ((code) & 0x18)
52 #define BPF_W 0x00
53 #define BPF_H 0x08
54 #define BPF_B 0x10
56 #define BPF_MODE(code) ((code) & 0xe0)
57 #define BPF_IMM 0x00
58 #define BPF_ABS 0x20
59 #define BPF_IND 0x40
60 #define BPF_MEM 0x60
61 #define BPF_LEN 0x80
62 #define BPF_MSH 0xa0
64 #define BPF_OP(code) ((code) & 0xf0)
65 #define BPF_ADD 0x00
66 #define BPF_SUB 0x10
67 #define BPF_MUL 0x20
68 #define BPF_DIV 0x30
69 #define BPF_OR 0x40
70 #define BPF_AND 0x50
71 #define BPF_LSH 0x60
72 #define BPF_RSH 0x70
73 #define BPF_NEG 0x80
74 #define BPF_MOD 0x90
75 #define BPF_XOR 0xa0
77 #define BPF_JA 0x00
78 #define BPF_JEQ 0x10
79 #define BPF_JGT 0x20
80 #define BPF_JGE 0x30
81 #define BPF_JSET 0x40
83 #define BPF_SRC(code) ((code) & 0x08)
84 #define BPF_K 0x00
85 #define BPF_X 0x08
87 /* ret - BPF_K and BPF_X also apply */
88 #define BPF_RVAL(code) ((code) & 0x18)
89 #define BPF_A 0x10
91 #define BPF_MISCOP(code) ((code) & 0xf8)
92 #define BPF_TAX 0x00
93 #define BPF_TXA 0x80
95 #ifndef SKF_AD_OFF
96 # define SKF_AD_OFF (-0x1000)
97 #endif
98 #ifndef SKF_AD_PROTOCOL
99 # define SKF_AD_PROTOCOL 0
100 #endif
101 #ifndef SKF_AD_PKTTYPE
102 # define SKF_AD_PKTTYPE 4
103 #endif
104 #ifndef SKF_AD_IFINDEX
105 # define SKF_AD_IFINDEX 8
106 #endif
107 #ifndef SKF_AD_NLATTR
108 # define SKF_AD_NLATTR 12
109 #endif
110 #ifndef SKF_AD_NLATTR_NEST
111 # define SKF_AD_NLATTR_NEST 16
112 #endif
113 #ifndef SKF_AD_MARK
114 # define SKF_AD_MARK 20
115 #endif
116 #ifndef SKF_AD_QUEUE
117 # define SKF_AD_QUEUE 24
118 #endif
119 #ifndef SKF_AD_HATYPE
120 # define SKF_AD_HATYPE 28
121 #endif
122 #ifndef SKF_AD_RXHASH
123 # define SKF_AD_RXHASH 32
124 #endif
125 #ifndef SKF_AD_CPU
126 # define SKF_AD_CPU 36
127 #endif
128 #ifndef SKF_AD_VLAN_TAG
129 # define SKF_AD_VLAN_TAG 44
130 #endif
131 #ifndef SKF_AD_VLAN_TAG_PRESENT
132 # define SKF_AD_VLAN_TAG_PRESENT 48
133 #endif
134 #ifndef SKF_AD_PAY_OFFSET
135 # define SKF_AD_PAY_OFFSET 52
136 #endif
138 #endif /* BPF_I_H */