Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
filter.h
Go to the documentation of this file.
1 /*
2  * Linux Socket Filter Data Structures
3  */
4 #ifndef __LINUX_FILTER_H__
5 #define __LINUX_FILTER_H__
6 
7 #include <linux/atomic.h>
8 #include <linux/compat.h>
9 #include <uapi/linux/filter.h>
10 
11 #ifdef CONFIG_COMPAT
12 /*
13  * A struct sock_filter is architecture independent.
14  */
15 struct compat_sock_fprog {
16  u16 len;
17  compat_uptr_t filter; /* struct sock_filter * */
18 };
19 #endif
20 
21 struct sk_buff;
22 struct sock;
23 
24 struct sk_filter
25 {
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];
32 };
33 
34 static inline unsigned int sk_filter_len(const struct sk_filter *fp)
35 {
36  return fp->len * sizeof(struct sock_filter) + sizeof(*fp);
37 }
38 
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 
49 #ifdef CONFIG_BPF_JIT
50 extern void bpf_jit_compile(struct sk_filter *fp);
51 extern void bpf_jit_free(struct sk_filter *fp);
52 #define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
53 #else
54 static inline void bpf_jit_compile(struct sk_filter *fp)
55 {
56 }
57 static inline void bpf_jit_free(struct sk_filter *fp)
58 {
59 }
60 #define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
61 #endif
62 
63 enum {
113  /* Ancillary data */
126 };
127 
128 #endif /* __LINUX_FILTER_H__ */