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 int sk_filter_trim_cap(struct sock
*sk
, struct sk_buff
*skb
, unsigned int cap
);
40 static inline int sk_filter(struct sock
*sk
, struct sk_buff
*skb
)
42 return sk_filter_trim_cap(sk
, skb
, 1);
44 extern unsigned int sk_run_filter(const struct sk_buff
*skb
,
45 const struct sock_filter
*filter
);
46 extern int sk_unattached_filter_create(struct sk_filter
**pfp
,
47 struct sock_fprog
*fprog
);
48 extern void sk_unattached_filter_destroy(struct sk_filter
*fp
);
49 extern int sk_attach_filter(struct sock_fprog
*fprog
, struct sock
*sk
);
50 extern int sk_detach_filter(struct sock
*sk
);
51 extern int sk_chk_filter(struct sock_filter
*filter
, unsigned int flen
);
52 extern int sk_get_filter(struct sock
*sk
, struct sock_filter __user
*filter
, unsigned len
);
53 extern void sk_decode_filter(struct sock_filter
*filt
, struct sock_filter
*to
);
57 #include <linux/linkage.h>
58 #include <linux/printk.h>
60 extern void bpf_jit_compile(struct sk_filter
*fp
);
61 extern void bpf_jit_free(struct sk_filter
*fp
);
63 static inline void bpf_jit_dump(unsigned int flen
, unsigned int proglen
,
64 u32 pass
, void *image
)
66 pr_err("flen=%u proglen=%u pass=%u image=%p\n",
67 flen
, proglen
, pass
, image
);
69 print_hex_dump(KERN_ERR
, "JIT code: ", DUMP_PREFIX_ADDRESS
,
70 16, 1, image
, proglen
, false);
72 #define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
74 static inline void bpf_jit_compile(struct sk_filter
*fp
)
77 static inline void bpf_jit_free(struct sk_filter
*fp
)
80 #define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
138 BPF_S_ANC_NLATTR_NEST
,
145 BPF_S_ANC_SECCOMP_LD_W
,
147 BPF_S_ANC_VLAN_TAG_PRESENT
,
148 BPF_S_ANC_PAY_OFFSET
,
151 #endif /* __LINUX_FILTER_H__ */