Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-2.6.git] / include / linux / filter.h
blobf65f5a69db8f8b93a4c85862748c0904350af576
1 /*
2 * Linux Socket Filter Data Structures
3 */
4 #ifndef __LINUX_FILTER_H__
5 #define __LINUX_FILTER_H__
7 #include <linux/atomic.h>
8 #include <linux/compat.h>
9 #include <uapi/linux/filter.h>
11 #ifdef CONFIG_COMPAT
13 * A struct sock_filter is architecture independent.
15 struct compat_sock_fprog {
16 u16 len;
17 compat_uptr_t filter; /* struct sock_filter * */
19 #endif
21 struct sk_buff;
22 struct sock;
24 struct sk_filter
26 atomic_t refcnt;
27 unsigned int len; /* Number of filter blocks */
28 unsigned int (*bpf_func)(const struct sk_buff *skb,
29 const struct sock_filter *filter);
30 struct rcu_head rcu;
31 struct sock_filter insns[0];
34 static inline unsigned int sk_filter_len(const struct sk_filter *fp)
36 return fp->len * sizeof(struct sock_filter) + sizeof(*fp);
39 extern int sk_filter(struct sock *sk, struct sk_buff *skb);
40 extern unsigned int sk_run_filter(const struct sk_buff *skb,
41 const struct sock_filter *filter);
42 extern int sk_unattached_filter_create(struct sk_filter **pfp,
43 struct sock_fprog *fprog);
44 extern void sk_unattached_filter_destroy(struct sk_filter *fp);
45 extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
46 extern int sk_detach_filter(struct sock *sk);
47 extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
48 extern int sk_get_filter(struct sock *sk, struct sock_filter __user *filter, unsigned len);
49 extern void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to);
51 #ifdef CONFIG_BPF_JIT
52 #include <stdarg.h>
53 #include <linux/linkage.h>
54 #include <linux/printk.h>
56 extern void bpf_jit_compile(struct sk_filter *fp);
57 extern void bpf_jit_free(struct sk_filter *fp);
59 static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
60 u32 pass, void *image)
62 pr_err("flen=%u proglen=%u pass=%u image=%p\n",
63 flen, proglen, pass, image);
64 if (image)
65 print_hex_dump(KERN_ERR, "JIT code: ", DUMP_PREFIX_ADDRESS,
66 16, 1, image, proglen, false);
68 #define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
69 #else
70 static inline void bpf_jit_compile(struct sk_filter *fp)
73 static inline void bpf_jit_free(struct sk_filter *fp)
76 #define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
77 #endif
79 enum {
80 BPF_S_RET_K = 1,
81 BPF_S_RET_A,
82 BPF_S_ALU_ADD_K,
83 BPF_S_ALU_ADD_X,
84 BPF_S_ALU_SUB_K,
85 BPF_S_ALU_SUB_X,
86 BPF_S_ALU_MUL_K,
87 BPF_S_ALU_MUL_X,
88 BPF_S_ALU_DIV_X,
89 BPF_S_ALU_MOD_K,
90 BPF_S_ALU_MOD_X,
91 BPF_S_ALU_AND_K,
92 BPF_S_ALU_AND_X,
93 BPF_S_ALU_OR_K,
94 BPF_S_ALU_OR_X,
95 BPF_S_ALU_XOR_K,
96 BPF_S_ALU_XOR_X,
97 BPF_S_ALU_LSH_K,
98 BPF_S_ALU_LSH_X,
99 BPF_S_ALU_RSH_K,
100 BPF_S_ALU_RSH_X,
101 BPF_S_ALU_NEG,
102 BPF_S_LD_W_ABS,
103 BPF_S_LD_H_ABS,
104 BPF_S_LD_B_ABS,
105 BPF_S_LD_W_LEN,
106 BPF_S_LD_W_IND,
107 BPF_S_LD_H_IND,
108 BPF_S_LD_B_IND,
109 BPF_S_LD_IMM,
110 BPF_S_LDX_W_LEN,
111 BPF_S_LDX_B_MSH,
112 BPF_S_LDX_IMM,
113 BPF_S_MISC_TAX,
114 BPF_S_MISC_TXA,
115 BPF_S_ALU_DIV_K,
116 BPF_S_LD_MEM,
117 BPF_S_LDX_MEM,
118 BPF_S_ST,
119 BPF_S_STX,
120 BPF_S_JMP_JA,
121 BPF_S_JMP_JEQ_K,
122 BPF_S_JMP_JEQ_X,
123 BPF_S_JMP_JGE_K,
124 BPF_S_JMP_JGE_X,
125 BPF_S_JMP_JGT_K,
126 BPF_S_JMP_JGT_X,
127 BPF_S_JMP_JSET_K,
128 BPF_S_JMP_JSET_X,
129 /* Ancillary data */
130 BPF_S_ANC_PROTOCOL,
131 BPF_S_ANC_PKTTYPE,
132 BPF_S_ANC_IFINDEX,
133 BPF_S_ANC_NLATTR,
134 BPF_S_ANC_NLATTR_NEST,
135 BPF_S_ANC_MARK,
136 BPF_S_ANC_QUEUE,
137 BPF_S_ANC_HATYPE,
138 BPF_S_ANC_RXHASH,
139 BPF_S_ANC_CPU,
140 BPF_S_ANC_ALU_XOR_X,
141 BPF_S_ANC_SECCOMP_LD_W,
142 BPF_S_ANC_VLAN_TAG,
143 BPF_S_ANC_VLAN_TAG_PRESENT,
144 BPF_S_ANC_PAY_OFFSET,
147 #endif /* __LINUX_FILTER_H__ */