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 <linux/workqueue.h>
10 #include <uapi/linux/filter.h>
14 * A struct sock_filter is architecture independent.
16 struct compat_sock_fprog {
18 compat_uptr_t filter; /* struct sock_filter * */
22 struct sock_fprog_kern {
24 struct sock_filter *filter;
32 u32 jited:1, /* Is our filter JIT'ed? */
33 len:31; /* Number of filter blocks */
34 struct sock_fprog_kern *orig_prog; /* Original BPF program */
36 unsigned int (*bpf_func)(const struct sk_buff *skb,
37 const struct sock_filter *filter);
39 struct sock_filter insns[0];
40 struct work_struct work;
44 static inline unsigned int sk_filter_size(unsigned int proglen)
46 return max(sizeof(struct sk_filter),
47 offsetof(struct sk_filter, insns[proglen]));
50 #define sk_filter_proglen(fprog) \
51 (fprog->len * sizeof(fprog->filter[0]))
53 int sk_filter(struct sock *sk, struct sk_buff *skb);
54 unsigned int sk_run_filter(const struct sk_buff *skb,
55 const struct sock_filter *filter);
57 int sk_unattached_filter_create(struct sk_filter **pfp,
58 struct sock_fprog *fprog);
59 void sk_unattached_filter_destroy(struct sk_filter *fp);
61 int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
62 int sk_detach_filter(struct sock *sk);
64 int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
65 int sk_get_filter(struct sock *sk, struct sock_filter __user *filter,
67 void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to);
69 void sk_filter_charge(struct sock *sk, struct sk_filter *fp);
70 void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);
74 #include <linux/linkage.h>
75 #include <linux/printk.h>
77 void bpf_jit_compile(struct sk_filter *fp);
78 void bpf_jit_free(struct sk_filter *fp);
80 static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
81 u32 pass, void *image)
83 pr_err("flen=%u proglen=%u pass=%u image=%pK\n",
84 flen, proglen, pass, image);
86 print_hex_dump(KERN_ERR, "JIT code: ", DUMP_PREFIX_OFFSET,
87 16, 1, image, proglen, false);
89 #define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
91 #include <linux/slab.h>
92 static inline void bpf_jit_compile(struct sk_filter *fp)
95 static inline void bpf_jit_free(struct sk_filter *fp)
99 #define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
102 static inline int bpf_tell_extensions(void)
162 BPF_S_ANC_NLATTR_NEST,
169 BPF_S_ANC_SECCOMP_LD_W,
171 BPF_S_ANC_VLAN_TAG_PRESENT,
172 BPF_S_ANC_PAY_OFFSET,
175 #endif /* __LINUX_FILTER_H__ */