aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@plumgrid.com>2014-07-30 23:34:16 -0400
committerDavid S. Miller <davem@davemloft.net>2014-08-02 18:03:58 -0400
commit7ae457c1e5b45a1b826fad9d62b32191d2bdcfdb (patch)
treedcb1aba57530e6c9426a81758173ca146ffafcaf /include
parent8fb575ca396bc31d9fa99c26336e2432b41d1bfc (diff)
net: filter: split 'struct sk_filter' into socket and bpf parts
clean up names related to socket filtering and bpf in the following way: - everything that deals with sockets keeps 'sk_*' prefix - everything that is pure BPF is changed to 'bpf_*' prefix split 'struct sk_filter' into struct sk_filter { atomic_t refcnt; struct rcu_head rcu; struct bpf_prog *prog; }; and struct bpf_prog { u32 jited:1, len:31; struct sock_fprog_kern *orig_prog; unsigned int (*bpf_func)(const struct sk_buff *skb, const struct bpf_insn *filter); union { struct sock_filter insns[0]; struct bpf_insn insnsi[0]; struct work_struct work; }; }; so that 'struct bpf_prog' can be used independent of sockets and cleans up 'unattached' bpf use cases split SK_RUN_FILTER macro into: SK_RUN_FILTER to be used with 'struct sk_filter *' and BPF_PROG_RUN to be used with 'struct bpf_prog *' __sk_filter_release(struct sk_filter *) gains __bpf_prog_release(struct bpf_prog *) helper function also perform related renames for the functions that work with 'struct bpf_prog *', since they're on the same lines: sk_filter_size -> bpf_prog_size sk_filter_select_runtime -> bpf_prog_select_runtime sk_filter_free -> bpf_prog_free sk_unattached_filter_create -> bpf_prog_create sk_unattached_filter_destroy -> bpf_prog_destroy sk_store_orig_filter -> bpf_prog_store_orig_filter sk_release_orig_filter -> bpf_release_orig_filter __sk_migrate_filter -> bpf_migrate_filter __sk_prepare_filter -> bpf_prepare_filter API for attaching classic BPF to a socket stays the same: sk_attach_filter(prog, struct sock *)/sk_detach_filter(struct sock *) and SK_RUN_FILTER(struct sk_filter *, ctx) to execute a program which is used by sockets, tun, af_packet API for 'unattached' BPF programs becomes: bpf_prog_create(struct bpf_prog **)/bpf_prog_destroy(struct bpf_prog *) and BPF_PROG_RUN(struct bpf_prog *, ctx) to execute a program which is used by isdn, ppp, team, seccomp, ptp, xt_bpf, cls_bpf, test_bpf Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r--include/linux/filter.h40
-rw-r--r--include/linux/isdn_ppp.h4
-rw-r--r--include/uapi/linux/netfilter/xt_bpf.h4
3 files changed, 27 insertions, 21 deletions
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 7cb9b40e9a2f..a5227ab8ccb1 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -296,7 +296,8 @@ enum {
296}) 296})
297 297
298/* Macro to invoke filter function. */ 298/* Macro to invoke filter function. */
299#define SK_RUN_FILTER(filter, ctx) (*filter->bpf_func)(ctx, filter->insnsi) 299#define SK_RUN_FILTER(filter, ctx) \
300 (*filter->prog->bpf_func)(ctx, filter->prog->insnsi)
300 301
301struct bpf_insn { 302struct bpf_insn {
302 __u8 code; /* opcode */ 303 __u8 code; /* opcode */
@@ -323,12 +324,10 @@ struct sk_buff;
323struct sock; 324struct sock;
324struct seccomp_data; 325struct seccomp_data;
325 326
326struct sk_filter { 327struct bpf_prog {
327 atomic_t refcnt;
328 u32 jited:1, /* Is our filter JIT'ed? */ 328 u32 jited:1, /* Is our filter JIT'ed? */
329 len:31; /* Number of filter blocks */ 329 len:31; /* Number of filter blocks */
330 struct sock_fprog_kern *orig_prog; /* Original BPF program */ 330 struct sock_fprog_kern *orig_prog; /* Original BPF program */
331 struct rcu_head rcu;
332 unsigned int (*bpf_func)(const struct sk_buff *skb, 331 unsigned int (*bpf_func)(const struct sk_buff *skb,
333 const struct bpf_insn *filter); 332 const struct bpf_insn *filter);
334 union { 333 union {
@@ -338,25 +337,32 @@ struct sk_filter {
338 }; 337 };
339}; 338};
340 339
341static inline unsigned int sk_filter_size(unsigned int proglen) 340struct sk_filter {
341 atomic_t refcnt;
342 struct rcu_head rcu;
343 struct bpf_prog *prog;
344};
345
346#define BPF_PROG_RUN(filter, ctx) (*filter->bpf_func)(ctx, filter->insnsi)
347
348static inline unsigned int bpf_prog_size(unsigned int proglen)
342{ 349{
343 return max(sizeof(struct sk_filter), 350 return max(sizeof(struct bpf_prog),
344 offsetof(struct sk_filter, insns[proglen])); 351 offsetof(struct bpf_prog, insns[proglen]));
345} 352}
346 353
347#define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0])) 354#define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
348 355
349int sk_filter(struct sock *sk, struct sk_buff *skb); 356int sk_filter(struct sock *sk, struct sk_buff *skb);
350 357
351void sk_filter_select_runtime(struct sk_filter *fp); 358void bpf_prog_select_runtime(struct bpf_prog *fp);
352void sk_filter_free(struct sk_filter *fp); 359void bpf_prog_free(struct bpf_prog *fp);
353 360
354int bpf_convert_filter(struct sock_filter *prog, int len, 361int bpf_convert_filter(struct sock_filter *prog, int len,
355 struct bpf_insn *new_prog, int *new_len); 362 struct bpf_insn *new_prog, int *new_len);
356 363
357int sk_unattached_filter_create(struct sk_filter **pfp, 364int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);
358 struct sock_fprog_kern *fprog); 365void bpf_prog_destroy(struct bpf_prog *fp);
359void sk_unattached_filter_destroy(struct sk_filter *fp);
360 366
361int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk); 367int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
362int sk_detach_filter(struct sock *sk); 368int sk_detach_filter(struct sock *sk);
@@ -369,7 +375,7 @@ bool sk_filter_charge(struct sock *sk, struct sk_filter *fp);
369void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp); 375void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);
370 376
371u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); 377u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
372void bpf_int_jit_compile(struct sk_filter *fp); 378void bpf_int_jit_compile(struct bpf_prog *fp);
373 379
374#define BPF_ANC BIT(15) 380#define BPF_ANC BIT(15)
375 381
@@ -423,8 +429,8 @@ static inline void *bpf_load_pointer(const struct sk_buff *skb, int k,
423#include <linux/linkage.h> 429#include <linux/linkage.h>
424#include <linux/printk.h> 430#include <linux/printk.h>
425 431
426void bpf_jit_compile(struct sk_filter *fp); 432void bpf_jit_compile(struct bpf_prog *fp);
427void bpf_jit_free(struct sk_filter *fp); 433void bpf_jit_free(struct bpf_prog *fp);
428 434
429static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen, 435static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
430 u32 pass, void *image) 436 u32 pass, void *image)
@@ -438,11 +444,11 @@ static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
438#else 444#else
439#include <linux/slab.h> 445#include <linux/slab.h>
440 446
441static inline void bpf_jit_compile(struct sk_filter *fp) 447static inline void bpf_jit_compile(struct bpf_prog *fp)
442{ 448{
443} 449}
444 450
445static inline void bpf_jit_free(struct sk_filter *fp) 451static inline void bpf_jit_free(struct bpf_prog *fp)
446{ 452{
447 kfree(fp); 453 kfree(fp);
448} 454}
diff --git a/include/linux/isdn_ppp.h b/include/linux/isdn_ppp.h
index 8e10f57f109f..a0070c6dfaf8 100644
--- a/include/linux/isdn_ppp.h
+++ b/include/linux/isdn_ppp.h
@@ -180,8 +180,8 @@ struct ippp_struct {
180 struct slcompress *slcomp; 180 struct slcompress *slcomp;
181#endif 181#endif
182#ifdef CONFIG_IPPP_FILTER 182#ifdef CONFIG_IPPP_FILTER
183 struct sk_filter *pass_filter; /* filter for packets to pass */ 183 struct bpf_prog *pass_filter; /* filter for packets to pass */
184 struct sk_filter *active_filter; /* filter for pkts to reset idle */ 184 struct bpf_prog *active_filter; /* filter for pkts to reset idle */
185#endif 185#endif
186 unsigned long debug; 186 unsigned long debug;
187 struct isdn_ppp_compressor *compressor,*decompressor; 187 struct isdn_ppp_compressor *compressor,*decompressor;
diff --git a/include/uapi/linux/netfilter/xt_bpf.h b/include/uapi/linux/netfilter/xt_bpf.h
index 2ec9fbcd06f9..1fad2c27ac32 100644
--- a/include/uapi/linux/netfilter/xt_bpf.h
+++ b/include/uapi/linux/netfilter/xt_bpf.h
@@ -6,14 +6,14 @@
6 6
7#define XT_BPF_MAX_NUM_INSTR 64 7#define XT_BPF_MAX_NUM_INSTR 64
8 8
9struct sk_filter; 9struct bpf_prog;
10 10
11struct xt_bpf_info { 11struct xt_bpf_info {
12 __u16 bpf_program_num_elem; 12 __u16 bpf_program_num_elem;
13 struct sock_filter bpf_program[XT_BPF_MAX_NUM_INSTR]; 13 struct sock_filter bpf_program[XT_BPF_MAX_NUM_INSTR];
14 14
15 /* only used in the kernel */ 15 /* only used in the kernel */
16 struct sk_filter *filter __attribute__((aligned(8))); 16 struct bpf_prog *filter __attribute__((aligned(8)));
17}; 17};
18 18
19#endif /*_XT_BPF_H */ 19#endif /*_XT_BPF_H */