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 * */
28 unsigned int len
; /* Number of filter blocks */
30 unsigned int (*bpf_func
)(const struct sk_buff
*skb
,
31 const struct sock_filter
*filter
);
33 struct sock_filter insns
[0];
34 struct work_struct work
;
38 static inline unsigned int sk_filter_size(unsigned int proglen
)
40 return max(sizeof(struct sk_filter
),
41 offsetof(struct sk_filter
, insns
[proglen
]));
44 extern int sk_filter(struct sock
*sk
, struct sk_buff
*skb
);
45 extern unsigned int sk_run_filter(const struct sk_buff
*skb
,
46 const struct sock_filter
*filter
);
47 extern int sk_unattached_filter_create(struct sk_filter
**pfp
,
48 struct sock_fprog
*fprog
);
49 extern void sk_unattached_filter_destroy(struct sk_filter
*fp
);
50 extern int sk_attach_filter(struct sock_fprog
*fprog
, struct sock
*sk
);
51 extern int sk_detach_filter(struct sock
*sk
);
52 extern int sk_chk_filter(struct sock_filter
*filter
, unsigned int flen
);
53 extern int sk_get_filter(struct sock
*sk
, struct sock_filter __user
*filter
, unsigned len
);
54 extern void sk_decode_filter(struct sock_filter
*filt
, struct sock_filter
*to
);
58 #include <linux/linkage.h>
59 #include <linux/printk.h>
61 extern void bpf_jit_compile(struct sk_filter
*fp
);
62 extern void bpf_jit_free(struct sk_filter
*fp
);
64 static inline void bpf_jit_dump(unsigned int flen
, unsigned int proglen
,
65 u32 pass
, void *image
)
67 pr_err("flen=%u proglen=%u pass=%u image=%pK\n",
68 flen
, proglen
, pass
, image
);
70 print_hex_dump(KERN_ERR
, "JIT code: ", DUMP_PREFIX_OFFSET
,
71 16, 1, image
, proglen
, false);
73 #define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
75 #include <linux/slab.h>
76 static inline void bpf_jit_compile(struct sk_filter
*fp
)
79 static inline void bpf_jit_free(struct sk_filter
*fp
)
83 #define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
141 BPF_S_ANC_NLATTR_NEST
,
148 BPF_S_ANC_SECCOMP_LD_W
,
150 BPF_S_ANC_VLAN_TAG_PRESENT
,
151 BPF_S_ANC_PAY_OFFSET
,
154 #endif /* __LINUX_FILTER_H__ */