net: filter: rename 'struct sk_filter' to 'struct bpf_prog'
Subsystems (26)
PATCH v2 1/1 net: filter: rename 'struct sk_filter' to 'struct bpf_prog'
'sk_filter' name is used as 'struct sk_filter', function sk_filter() and as variable 'sk_filter', which makes code hard to read.
Also it's easily confused with 'struct sock_filter'
Rename 'struct sk_filter' to 'struct bpf_prog' to clarify semantics and align the name with generic BPF use model.
The only ugly place is uapi/linux/netfilter/xt_bpf.h which managed to expose kernel internal structure into uapi header. So replace 'struct sk_filter *' there with 'void *' and type cast it to 'struct bpf_prog *' inside kernel in net/netfilter/xt_bpf.c
---v1->v2:
replace 'struct sk_filter *' with 'void *' in uapi/../xt_bpf.h (seems Daniel and Willem prefere this option)
Documentation/networking/filter.txt | 2 +- arch/arm/net/bpf_jit_32.c | 8 +++--- arch/mips/net/bpf_jit.c | 8 +++--- arch/powerpc/net/bpf_jit_comp.c | 8 +++--- arch/s390/net/bpf_jit_comp.c | 4 +-- arch/sparc/net/bpf_jit_comp.c | 4 +-- arch/x86/net/bpf_jit_comp.c | 10 +++---- drivers/net/ppp/ppp_generic.c | 4 +-- drivers/net/team/team_mode_loadbalance.c | 8 +++--- include/linux/filter.h | 28 +++++++++---------- include/linux/isdn_ppp.h | 4 +-- include/net/sock.h | 2 +- include/uapi/linux/netfilter/xt_bpf.h | 2 +- kernel/bpf/core.c | 6 ++--- kernel/seccomp.c | 2 +- lib/test_bpf.c | 12 ++++----- net/core/filter.c | 43 +++++++++++++++--------------- net/core/ptp_classifier.c | 2 +- net/core/sock.c | 4 +-- net/core/sock_diag.c | 2 +- net/netfilter/xt_bpf.c | 7 ++--- net/packet/af_packet.c | 2 +- net/sched/cls_bpf.c | 4 +-- 23 files changed, 88 insertions(+), 88 deletions(-)
Documentation/networking/filter.txt +1 -1
@@ -589,7 +589,7 @@ in the eBPF interpreter. For in-kernel handlers, this all works transparently by using sk_unattached_filter_create() for setting up the filter, resp. sk_unattached_filter_destroy() for destroying it. The macro SK_RUN_FILTER(filter, ctx) transparently invokes eBPF interpreter or JITed -code to run the filter. 'filter' is a pointer to struct sk_filter that we +code to run the filter. 'filter' is a pointer to struct bpf_prog that we got from sk_unattached_filter_create(), and 'ctx' the given context (e.g. skb pointer). All constraints and restrictions from sk_chk_filter() apply before a conversion to the new layout is being done behind the scenes!
arch/arm/net/bpf_jit_32.c +4 -4
@@ -56,7 +56,7 @@#define FLAG_NEED_X_RESET (1 << 0)struct jit_ctx { -const struct sk_filter *skf; +const struct bpf_prog *skf;unsigned idx;unsigned prologue_bytes;int ret0_fp_idx;
@@ -465,7 +465,7 @@ static inline void update_on_xread(struct jit_ctx *ctx)static int build_body (struct jit_ctx *ctx) {void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w}; -const struct sk_filter *prog = ctx->skf; +const struct bpf_prog *prog = ctx->skf;const struct sock_filter *inst;unsigned i, load_order, off, condt;int imm12;
@@ -857,7 +857,7 @@ b_epilogue: } -void bpf_jit_compile (struct sk_filter *fp) +void bpf_jit_compile (struct bpf_prog *fp) {struct jit_ctx ctx;unsigned tmp_idx;
@@ -926,7 +926,7 @@ out:return ; } -void bpf_jit_free (struct sk_filter *fp) +void bpf_jit_free (struct bpf_prog *fp) {if (fp->jited)module_free (NULL , fp->bpf_func);
arch/mips/net/bpf_jit.c +4 -4
@@ -131,7 +131,7 @@* @target: Memory location for the compiled filter */ struct jit_ctx { -const struct sk_filter *skf; +const struct bpf_prog *skf;unsigned int prologue_bytes;u32 idx;u32 flags;
@@ -789,7 +789,7 @@ static int pkt_type_offset(void)static int build_body (struct jit_ctx *ctx) {void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w}; -const struct sk_filter *prog = ctx->skf; +const struct bpf_prog *prog = ctx->skf;const struct sock_filter *inst;unsigned int i, off, load_order, condt;u32 k, b_off__maybe_unused ;
@@ -1369,7 +1369,7 @@ jmp_cmp:int bpf_jit_enable__read_mostly ; -void bpf_jit_compile (struct sk_filter *fp) +void bpf_jit_compile (struct bpf_prog *fp) {struct jit_ctx ctx;unsigned int alloc_size, tmp_idx;
@@ -1423,7 +1423,7 @@ out:kfree (ctx.offsets); } -void bpf_jit_free (struct sk_filter *fp) +void bpf_jit_free (struct bpf_prog *fp) {if (fp->jited)module_free (NULL , fp->bpf_func);
arch/powerpc/net/bpf_jit_comp.c +4 -4
@@ -25,7 +25,7 @@ static inline void bpf_flush_icache(void *start, void *end)flush_icache_range ((unsigned long )start, (unsigned long )end); } -static void bpf_jit_build_prologue (struct sk_filter *fp,u32 *image, +static void bpf_jit_build_prologue (struct bpf_prog *fp,u32 *image,struct codegen_context *ctx) {int i;
@@ -121,7 +121,7 @@ static void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx) ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset) /* Assemble the body code between the prologue & epilogue. */ -static int bpf_jit_build_body (struct sk_filter *fp,u32 *image, +static int bpf_jit_build_body (struct bpf_prog *fp,u32 *image,struct codegen_context *ctx,unsigned int *addrs) {
@@ -569,7 +569,7 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,return 0 ; } -void bpf_jit_compile (struct sk_filter *fp) +void bpf_jit_compile (struct bpf_prog *fp) {unsigned int proglen;unsigned int alloclen;
@@ -693,7 +693,7 @@ out:return ; } -void bpf_jit_free (struct sk_filter *fp) +void bpf_jit_free (struct bpf_prog *fp) {if (fp->jited)module_free (NULL , fp->bpf_func);
arch/s390/net/bpf_jit_comp.c +2 -2
@@ -812,7 +812,7 @@ static struct bpf_binary_header *bpf_alloc_binary(unsigned int bpfsize,return header; } -void bpf_jit_compile (struct sk_filter *fp) +void bpf_jit_compile (struct bpf_prog *fp) {struct bpf_binary_header *header =NULL ;unsigned long size, prg_len, lit_len;
@@ -875,7 +875,7 @@ out:kfree (addrs); } -void bpf_jit_free (struct sk_filter *fp) +void bpf_jit_free (struct bpf_prog *fp) {unsigned long addr = (unsigned long )fp->bpf_func &PAGE_MASK ;struct bpf_binary_header *header = (void *)addr;
arch/sparc/net/bpf_jit_comp.c +2 -2
@@ -354,7 +354,7 @@ do { *prog++ = BR_OPC | WDISP22(OFF); \* emit_jump() calls with adjusted offsets. */ -void bpf_jit_compile (struct sk_filter *fp) +void bpf_jit_compile (struct bpf_prog *fp) {unsigned int cleanup_addr, proglen, oldproglen =0 ;u32 temp[8 ], *prog, *func, seen =0 , pass;
@@ -808,7 +808,7 @@ out:return ; } -void bpf_jit_free (struct sk_filter *fp) +void bpf_jit_free (struct bpf_prog *fp) {if (fp->jited)module_free (NULL , fp->bpf_func);
arch/x86/net/bpf_jit_comp.c +5 -5
@@ -211,7 +211,7 @@ struct jit_context {bool seen_ld_abs; }; -static int do_jit (struct sk_filter *bpf_prog,int *addrs,u8 *image, +static int do_jit (struct bpf_prog *bpf_prog,int *addrs,u8 *image,int oldproglen,struct jit_context *ctx) {struct bpf_insn *insn = bpf_prog->insnsi;
@@ -862,11 +862,11 @@ common_load: ctx->seen_ld_abs = true;return proglen; } -void bpf_jit_compile (struct sk_filter *prog) +void bpf_jit_compile (struct bpf_prog *prog) { } -void bpf_int_jit_compile (struct sk_filter *prog) +void bpf_int_jit_compile (struct bpf_prog *prog) {struct bpf_binary_header *header =NULL ;int proglen, oldproglen =0 ;
@@ -932,7 +932,7 @@ out:static void bpf_jit_free_deferred (struct work_struct *work) { - struct sk_filter *fp = container_of(work, struct sk_filter, work); + struct bpf_prog *fp = container_of(work, struct bpf_prog, work);unsigned long addr = (unsigned long )fp->bpf_func &PAGE_MASK ;struct bpf_binary_header *header = (void *)addr;
@@ -941,7 +941,7 @@ static void bpf_jit_free_deferred(struct work_struct *work)kfree (fp); } -void bpf_jit_free (struct sk_filter *fp) +void bpf_jit_free (struct bpf_prog *fp) {if (fp->jited) {INIT_WORK (&fp->work, bpf_jit_free_deferred);
drivers/net/ppp/ppp_generic.c +2 -2
@@ -143,8 +143,8 @@ struct ppp {struct sk_buff_head mrq;/* MP: receive reconstruction queue */ #endif /* CONFIG_PPP_MULTILINK */ #ifdef CONFIG_PPP_FILTER -struct sk_filter *pass_filter;/* filter for packets to pass */ -struct sk_filter *active_filter;/* filter for pkts to reset idle */ +struct bpf_prog *pass_filter;/* filter for packets to pass */ +struct bpf_prog *active_filter;/* filter for pkts to reset idle */ #endif /* CONFIG_PPP_FILTER */ struct net *ppp_net;/* the net we belong to */ struct ppp_link_stats stats64;/* 64 bit network stats */
drivers/net/team/team_mode_loadbalance.c +4 -4
@@ -58,7 +58,7 @@ struct lb_priv_ex { };struct lb_priv { -struct sk_filter __rcu *fp; +struct bpf_prog __rcu *fp;lb_select_tx_port_func_t __rcu *select_tx_port_func;struct lb_pcpu_stats __percpu *pcpu_stats;struct lb_priv_ex *ex;/* priv extension */
@@ -174,7 +174,7 @@ static lb_select_tx_port_func_t *lb_select_tx_port_get_func(const char *name)static unsigned int lb_get_skb_hash (struct lb_priv *lb_priv,struct sk_buff *skb) { -struct sk_filter *fp; +struct bpf_prog *fp;uint32_t lhash;unsigned char *c;
@@ -271,8 +271,8 @@ static void __fprog_destroy(struct sock_fprog_kern *fprog)static int lb_bpf_func_set (struct team *team,struct team_gsetter_ctx *ctx) {struct lb_priv *lb_priv =get_lb_priv (team); -struct sk_filter *fp =NULL ; -struct sk_filter *orig_fp; +struct bpf_prog *fp =NULL ; +struct bpf_prog *orig_fp;struct sock_fprog_kern *fprog =NULL ;int err;
include/linux/filter.h +14 -14
@@ -323,7 +323,7 @@ struct sk_buff;struct sock ;struct seccomp_data ; -struct sk_filter { +struct bpf_prog {atomic_t refcnt;u32 jited:1 ,/* Is our filter JIT'ed? */ len:31 ;/* Number of filter blocks */
@@ -340,8 +340,8 @@ struct sk_filter {static inline unsigned int sk_filter_size (unsigned int proglen) { -return max (sizeof (struct sk_filter ), - offsetof(struct sk_filter, insns[proglen])); +return max (sizeof (struct bpf_prog ), + offsetof(struct bpf_prog, insns[proglen])); }#define sk_filter_proglen (fprog) \
@@ -349,15 +349,15 @@ static inline unsigned int sk_filter_size(unsigned int proglen)int sk_filter (struct sock *sk,struct sk_buff *skb); -void sk_filter_select_runtime (struct sk_filter *fp); -void sk_filter_free (struct sk_filter *fp); +void sk_filter_select_runtime (struct bpf_prog *fp); +void sk_filter_free (struct bpf_prog *fp);int sk_convert_filter (struct sock_filter *prog,int len,struct bpf_insn *new_prog,int *new_len); -int sk_unattached_filter_create (struct sk_filter **pfp, +int sk_unattached_filter_create (struct bpf_prog **pfp,struct sock_fprog_kern *fprog); -void sk_unattached_filter_destroy (struct sk_filter *fp); +void sk_unattached_filter_destroy (struct bpf_prog *fp);int sk_attach_filter (struct sock_fprog *fprog,struct sock *sk);int sk_detach_filter (struct sock *sk);
@@ -366,11 +366,11 @@ int sk_chk_filter(const struct sock_filter *filter, unsigned int flen);int sk_get_filter (struct sock *sk,struct sock_filter __user *filter,unsigned int len); -void sk_filter_charge (struct sock *sk,struct sk_filter *fp); -void sk_filter_uncharge (struct sock *sk,struct sk_filter *fp); +void sk_filter_charge (struct sock *sk,struct bpf_prog *fp); +void sk_filter_uncharge (struct sock *sk,struct bpf_prog *fp);u64 __bpf_call_base (u64 r1,u64 r2,u64 r3,u64 r4,u64 r5); -void bpf_int_jit_compile (struct sk_filter *fp); +void bpf_int_jit_compile (struct bpf_prog *fp);#define BPF_ANC BIT(15)
@@ -424,8 +424,8 @@ static inline void *bpf_load_pointer(const struct sk_buff *skb, int k,#include <linux/linkage.h> #include <linux/printk.h> -void bpf_jit_compile (struct sk_filter *fp); -void bpf_jit_free (struct sk_filter *fp); +void bpf_jit_compile (struct bpf_prog *fp); +void bpf_jit_free (struct bpf_prog *fp);static inline void bpf_jit_dump (unsigned int flen,unsigned int proglen,u32 pass,void *image)
@@ -439,11 +439,11 @@ static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,#else #include <linux/slab.h> -static inline void bpf_jit_compile (struct sk_filter *fp) +static inline void bpf_jit_compile (struct bpf_prog *fp) { } -static inline void bpf_jit_free (struct sk_filter *fp) +static inline void bpf_jit_free (struct bpf_prog *fp) {kfree (fp); }
include/linux/isdn_ppp.h +2 -2
@@ -180,8 +180,8 @@ struct ippp_struct {struct slcompress *slcomp;#endif #ifdef CONFIG_IPPP_FILTER -struct sk_filter *pass_filter;/* filter for packets to pass */ -struct sk_filter *active_filter;/* filter for pkts to reset idle */ +struct bpf_prog *pass_filter;/* filter for packets to pass */ +struct bpf_prog *active_filter;/* filter for pkts to reset idle */ #endif unsigned long debug;struct isdn_ppp_compressor *compressor,*decompressor;
include/net/sock.h +1 -1
@@ -356,7 +356,7 @@ struct sock {atomic_t sk_drops;int sk_rcvbuf; -struct sk_filter __rcu *sk_filter; +struct bpf_prog __rcu *sk_filter;struct socket_wq __rcu *sk_wq;#ifdef CONFIG_NET_DMA
include/uapi/linux/netfilter/xt_bpf.h +1 -1
@@ -11,7 +11,7 @@ struct xt_bpf_info {struct sock_filter bpf_program[XT_BPF_MAX_NUM_INSTR ];/* only used in the kernel */ - struct sk_filter *filter __attribute__((aligned(8))); + void *filter __attribute__((aligned(8))); };#endif /*_XT_BPF_H */
kernel/bpf/core.c +3 -3
@@ -508,7 +508,7 @@ load_byte:return 0 ; } -void __weak bpf_int_jit_compile (struct sk_filter *prog) +void __weak bpf_int_jit_compile (struct bpf_prog *prog) { }
@@ -519,7 +519,7 @@ void __weak bpf_int_jit_compile(struct sk_filter *prog)* try to JIT internal BPF program, if JIT is not available select interpreter * BPF program will be executed via SK_RUN_FILTER() macro */ -void sk_filter_select_runtime (struct sk_filter *fp) +void sk_filter_select_runtime (struct bpf_prog *fp) { fp->bpf_func = (void *) __sk_run_filter;
@@ -529,7 +529,7 @@ void sk_filter_select_runtime(struct sk_filter *fp)EXPORT_SYMBOL_GPL (sk_filter_select_runtime);/* free internal BPF program */ -void sk_filter_free (struct sk_filter *fp) +void sk_filter_free (struct bpf_prog *fp) {bpf_jit_free (fp); }
kernel/seccomp.c +1 -1
@@ -54,7 +54,7 @@struct seccomp_filter {atomic_t usage;struct seccomp_filter *prev; -struct sk_filter *prog; +struct bpf_prog *prog; };/* Limit any path through the tree to 256KB worth of instructions. */
lib/test_bpf.c +6 -6
@@ -1761,9 +1761,9 @@ static int probe_filter_length(struct sock_filter *fp)return len +1 ; } -static struct sk_filter *generate_filter (int which,int *err) +static struct bpf_prog *generate_filter (int which,int *err) { -struct sk_filter *fp; +struct bpf_prog *fp;struct sock_fprog_kern fprog;unsigned int flen =probe_filter_length (tests[which].u.insns);__u8 test_type = tests[which].aux &TEST_TYPE_MASK ;
@@ -1817,7 +1817,7 @@ static struct sk_filter *generate_filter(int which, int *err)return fp; } -static void release_filter (struct sk_filter *fp,int which) +static void release_filter (struct bpf_prog *fp,int which) {__u8 test_type = tests[which].aux &TEST_TYPE_MASK ;
@@ -1831,7 +1831,7 @@ static void release_filter(struct sk_filter *fp, int which) } } -static int __run_one (const struct sk_filter *fp,const void *data, +static int __run_one (const struct bpf_prog *fp,const void *data,int runs,u64 *duration) {u64 start, finish;
@@ -1850,7 +1850,7 @@ static int __run_one(const struct sk_filter *fp, const void *data,return ret; } -static int run_one (const struct sk_filter *fp,struct bpf_test *test) +static int run_one (const struct bpf_prog *fp,struct bpf_test *test) {int err_cnt =0 , i, runs =MAX_TESTRUNS ;
@@ -1884,7 +1884,7 @@ static __init int test_bpf(void)int i, err_cnt =0 , pass_cnt =0 ;for (i =0 ; i <ARRAY_SIZE (tests); i++) { -struct sk_filter *fp; +struct bpf_prog *fp;int err;pr_info ("#%d %s " , i, tests[i].descr);
net/core/filter.c +21 -22
136 lines not on this page · raw message
net/core/ptp_classifier.c +1 -1
@@ -107,7 +107,7 @@#include <linux/filter.h> #include <linux/ptp_classify.h> -static struct sk_filter *ptp_insns__read_mostly ; +static struct bpf_prog *ptp_insns__read_mostly ;unsigned int ptp_classify_raw (const struct sk_buff *skb) {
net/core/sock.c +2 -2
@@ -1405,7 +1405,7 @@ EXPORT_SYMBOL(sk_alloc);static void __sk_free (struct sock *sk) { -struct sk_filter *filter; +struct bpf_prog *filter;if (sk->sk_destruct) sk->sk_destruct (sk);
@@ -1481,7 +1481,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority) newsk =sk_prot_alloc (sk->sk_prot, priority, sk->sk_family);if (newsk !=NULL ) { -struct sk_filter *filter; +struct bpf_prog *filter;sock_copy (newsk, sk);
net/core/sock_diag.c +1 -1
@@ -53,7 +53,7 @@ int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk, struct sk_buff *skb, int attrtype) {struct sock_fprog_kern *fprog; -struct sk_filter *filter; +struct bpf_prog *filter;struct nlattr *attr;unsigned int flen;int err =0 ;
net/netfilter/xt_bpf.c +4 -3
@@ -28,7 +28,8 @@ static int bpf_mt_check(const struct xt_mtchk_param *par) program.len = info->bpf_program_num_elem; program.filter = info->bpf_program; -if (sk_unattached_filter_create (&info->filter, &program)) { +if (sk_unattached_filter_create ((struct bpf_prog **) &info->filter, + &program)) {pr_info ("bpf: check failed: parse error\n" );return -EINVAL ; }
@@ -40,13 +41,13 @@ static bool bpf_mt(const struct sk_buff *skb, struct xt_action_param *par) {const struct xt_bpf_info *info = par->matchinfo; -return SK_RUN_FILTER (info->filter, skb); +return SK_RUN_FILTER (((struct bpf_prog *) info->filter), skb); }static void bpf_mt_destroy (const struct xt_mtdtor_param *par) {const struct xt_bpf_info *info = par->matchinfo; -sk_unattached_filter_destroy (info->filter); +sk_unattached_filter_destroy ((struct bpf_prog *) info->filter); }static struct xt_match bpf_mt_reg__read_mostly = {
net/packet/af_packet.c +1 -1
@@ -1732,7 +1732,7 @@ static unsigned int run_filter(const struct sk_buff *skb,const struct sock *sk, unsigned int res) { -struct sk_filter *filter; + struct bpf_prog *filter;rcu_read_lock (); filter =rcu_dereference (sk->sk_filter);
net/sched/cls_bpf.c +2 -2
@@ -30,7 +30,7 @@ struct cls_bpf_head { };struct cls_bpf_prog { -struct sk_filter *filter; +struct bpf_prog *filter;struct sock_filter *bpf_ops;struct tcf_exts exts;struct tcf_result res;
@@ -161,7 +161,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,struct sock_filter *bpf_ops, *bpf_old;struct tcf_exts exts;struct sock_fprog_kern tmp; -struct sk_filter *fp, *fp_old; +struct bpf_prog *fp, *fp_old;u16 bpf_size, bpf_len;u32 classid;int ret;
Signature · 1 line
1.7.9.5
Pablo Neira Ayuso
maintainerQuoted 11 lines · Alexei Starovoitov
'
sk_filter' name is used as 'structsk_filter', functionsk_filter()and as variable 'sk_filter', which makes code hard to read.
Also it's easily confused with 'structsock_filter'
Rename 'structsk_filter' to 'structbpf_prog' to clarify semantics and align the name with generic BPF use model.The only ugly place is
uapi/linux/netfilter/xt_bpf.hwhich managed to expose kernel internal structure into uapi header. So replace 'structsk_filter*' there with 'void *' and type cast it to 'structbpf_prog*' inside kernel innet/netfilter/xt_bpf.c
Quoted 5 lines
Signed-off-by Alexei Starovoitov <[email protected]>---
v1->v2:
replace 'structsk_filter*' with 'void *' inuapi/../xt_bpf.h(seems Daniel and Willem prefere this option)
Please, we're still discussing this in the original thread:
http://marc.info/?l=netfilter-devel&m=140632686726741&w=2
http://marc.info/?l=netfilter-devel&m=140632663526671&w=2
And don't trim me off from the CC. Thanks.