2 * Linux Socket Filter Data Structures
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>
13 * A struct sock_filter is architecture independent.
15 struct compat_sock_fprog {
17 compat_uptr_t filter; /* struct sock_filter * */
27 unsigned int len; /* Number of filter blocks */
28 unsigned int (*bpf_func)(const struct sk_buff *skb,
29 const struct sock_filter *filter);
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);
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=%pK\n",
63 flen, proglen, pass, image);
65 print_hex_dump(KERN_ERR, "JIT code: ", DUMP_PREFIX_OFFSET,
66 16, 1, image, proglen, false);
68 #define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
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)
134 BPF_S_ANC_NLATTR_NEST,
141 BPF_S_ANC_SECCOMP_LD_W,
143 BPF_S_ANC_VLAN_TAG_PRESENT,
144 BPF_S_ANC_PAY_OFFSET,
147 #endif /* __LINUX_FILTER_H__ */