diff options
| author | Alexei Starovoitov <ast@plumgrid.com> | 2014-07-30 23:34:16 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2014-08-02 18:03:58 -0400 |
| commit | 7ae457c1e5b45a1b826fad9d62b32191d2bdcfdb (patch) | |
| tree | dcb1aba57530e6c9426a81758173ca146ffafcaf /drivers/net | |
| parent | 8fb575ca396bc31d9fa99c26336e2432b41d1bfc (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 'drivers/net')
| -rw-r--r-- | drivers/net/ppp/ppp_generic.c | 28 | ||||
| -rw-r--r-- | drivers/net/team/team_mode_loadbalance.c | 14 |
2 files changed, 21 insertions, 21 deletions
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index 765248b42a0a..fa0d71727894 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c | |||
| @@ -143,8 +143,8 @@ struct ppp { | |||
| 143 | struct sk_buff_head mrq; /* MP: receive reconstruction queue */ | 143 | struct sk_buff_head mrq; /* MP: receive reconstruction queue */ |
| 144 | #endif /* CONFIG_PPP_MULTILINK */ | 144 | #endif /* CONFIG_PPP_MULTILINK */ |
| 145 | #ifdef CONFIG_PPP_FILTER | 145 | #ifdef CONFIG_PPP_FILTER |
| 146 | struct sk_filter *pass_filter; /* filter for packets to pass */ | 146 | struct bpf_prog *pass_filter; /* filter for packets to pass */ |
| 147 | struct sk_filter *active_filter;/* filter for pkts to reset idle */ | 147 | struct bpf_prog *active_filter; /* filter for pkts to reset idle */ |
| 148 | #endif /* CONFIG_PPP_FILTER */ | 148 | #endif /* CONFIG_PPP_FILTER */ |
| 149 | struct net *ppp_net; /* the net we belong to */ | 149 | struct net *ppp_net; /* the net we belong to */ |
| 150 | struct ppp_link_stats stats64; /* 64 bit network stats */ | 150 | struct ppp_link_stats stats64; /* 64 bit network stats */ |
| @@ -762,12 +762,12 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
| 762 | 762 | ||
| 763 | ppp_lock(ppp); | 763 | ppp_lock(ppp); |
| 764 | if (ppp->pass_filter) { | 764 | if (ppp->pass_filter) { |
| 765 | sk_unattached_filter_destroy(ppp->pass_filter); | 765 | bpf_prog_destroy(ppp->pass_filter); |
| 766 | ppp->pass_filter = NULL; | 766 | ppp->pass_filter = NULL; |
| 767 | } | 767 | } |
| 768 | if (fprog.filter != NULL) | 768 | if (fprog.filter != NULL) |
| 769 | err = sk_unattached_filter_create(&ppp->pass_filter, | 769 | err = bpf_prog_create(&ppp->pass_filter, |
| 770 | &fprog); | 770 | &fprog); |
| 771 | else | 771 | else |
| 772 | err = 0; | 772 | err = 0; |
| 773 | kfree(code); | 773 | kfree(code); |
| @@ -788,12 +788,12 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
| 788 | 788 | ||
| 789 | ppp_lock(ppp); | 789 | ppp_lock(ppp); |
| 790 | if (ppp->active_filter) { | 790 | if (ppp->active_filter) { |
| 791 | sk_unattached_filter_destroy(ppp->active_filter); | 791 | bpf_prog_destroy(ppp->active_filter); |
| 792 | ppp->active_filter = NULL; | 792 | ppp->active_filter = NULL; |
| 793 | } | 793 | } |
| 794 | if (fprog.filter != NULL) | 794 | if (fprog.filter != NULL) |
| 795 | err = sk_unattached_filter_create(&ppp->active_filter, | 795 | err = bpf_prog_create(&ppp->active_filter, |
| 796 | &fprog); | 796 | &fprog); |
| 797 | else | 797 | else |
| 798 | err = 0; | 798 | err = 0; |
| 799 | kfree(code); | 799 | kfree(code); |
| @@ -1205,7 +1205,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb) | |||
| 1205 | a four-byte PPP header on each packet */ | 1205 | a four-byte PPP header on each packet */ |
| 1206 | *skb_push(skb, 2) = 1; | 1206 | *skb_push(skb, 2) = 1; |
| 1207 | if (ppp->pass_filter && | 1207 | if (ppp->pass_filter && |
| 1208 | SK_RUN_FILTER(ppp->pass_filter, skb) == 0) { | 1208 | BPF_PROG_RUN(ppp->pass_filter, skb) == 0) { |
| 1209 | if (ppp->debug & 1) | 1209 | if (ppp->debug & 1) |
| 1210 | netdev_printk(KERN_DEBUG, ppp->dev, | 1210 | netdev_printk(KERN_DEBUG, ppp->dev, |
| 1211 | "PPP: outbound frame " | 1211 | "PPP: outbound frame " |
| @@ -1215,7 +1215,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb) | |||
| 1215 | } | 1215 | } |
| 1216 | /* if this packet passes the active filter, record the time */ | 1216 | /* if this packet passes the active filter, record the time */ |
| 1217 | if (!(ppp->active_filter && | 1217 | if (!(ppp->active_filter && |
| 1218 | SK_RUN_FILTER(ppp->active_filter, skb) == 0)) | 1218 | BPF_PROG_RUN(ppp->active_filter, skb) == 0)) |
| 1219 | ppp->last_xmit = jiffies; | 1219 | ppp->last_xmit = jiffies; |
| 1220 | skb_pull(skb, 2); | 1220 | skb_pull(skb, 2); |
| 1221 | #else | 1221 | #else |
| @@ -1839,7 +1839,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb) | |||
| 1839 | 1839 | ||
| 1840 | *skb_push(skb, 2) = 0; | 1840 | *skb_push(skb, 2) = 0; |
| 1841 | if (ppp->pass_filter && | 1841 | if (ppp->pass_filter && |
| 1842 | SK_RUN_FILTER(ppp->pass_filter, skb) == 0) { | 1842 | BPF_PROG_RUN(ppp->pass_filter, skb) == 0) { |
| 1843 | if (ppp->debug & 1) | 1843 | if (ppp->debug & 1) |
| 1844 | netdev_printk(KERN_DEBUG, ppp->dev, | 1844 | netdev_printk(KERN_DEBUG, ppp->dev, |
| 1845 | "PPP: inbound frame " | 1845 | "PPP: inbound frame " |
| @@ -1848,7 +1848,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb) | |||
| 1848 | return; | 1848 | return; |
| 1849 | } | 1849 | } |
| 1850 | if (!(ppp->active_filter && | 1850 | if (!(ppp->active_filter && |
| 1851 | SK_RUN_FILTER(ppp->active_filter, skb) == 0)) | 1851 | BPF_PROG_RUN(ppp->active_filter, skb) == 0)) |
| 1852 | ppp->last_recv = jiffies; | 1852 | ppp->last_recv = jiffies; |
| 1853 | __skb_pull(skb, 2); | 1853 | __skb_pull(skb, 2); |
| 1854 | } else | 1854 | } else |
| @@ -2829,12 +2829,12 @@ static void ppp_destroy_interface(struct ppp *ppp) | |||
| 2829 | #endif /* CONFIG_PPP_MULTILINK */ | 2829 | #endif /* CONFIG_PPP_MULTILINK */ |
| 2830 | #ifdef CONFIG_PPP_FILTER | 2830 | #ifdef CONFIG_PPP_FILTER |
| 2831 | if (ppp->pass_filter) { | 2831 | if (ppp->pass_filter) { |
| 2832 | sk_unattached_filter_destroy(ppp->pass_filter); | 2832 | bpf_prog_destroy(ppp->pass_filter); |
| 2833 | ppp->pass_filter = NULL; | 2833 | ppp->pass_filter = NULL; |
| 2834 | } | 2834 | } |
| 2835 | 2835 | ||
| 2836 | if (ppp->active_filter) { | 2836 | if (ppp->active_filter) { |
| 2837 | sk_unattached_filter_destroy(ppp->active_filter); | 2837 | bpf_prog_destroy(ppp->active_filter); |
| 2838 | ppp->active_filter = NULL; | 2838 | ppp->active_filter = NULL; |
| 2839 | } | 2839 | } |
| 2840 | #endif /* CONFIG_PPP_FILTER */ | 2840 | #endif /* CONFIG_PPP_FILTER */ |
diff --git a/drivers/net/team/team_mode_loadbalance.c b/drivers/net/team/team_mode_loadbalance.c index d7be9b36bce6..a1536d0d83a9 100644 --- a/drivers/net/team/team_mode_loadbalance.c +++ b/drivers/net/team/team_mode_loadbalance.c | |||
| @@ -58,7 +58,7 @@ struct lb_priv_ex { | |||
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | struct lb_priv { | 60 | struct lb_priv { |
| 61 | struct sk_filter __rcu *fp; | 61 | struct bpf_prog __rcu *fp; |
| 62 | lb_select_tx_port_func_t __rcu *select_tx_port_func; | 62 | lb_select_tx_port_func_t __rcu *select_tx_port_func; |
| 63 | struct lb_pcpu_stats __percpu *pcpu_stats; | 63 | struct lb_pcpu_stats __percpu *pcpu_stats; |
| 64 | struct lb_priv_ex *ex; /* priv extension */ | 64 | struct lb_priv_ex *ex; /* priv extension */ |
| @@ -174,14 +174,14 @@ static lb_select_tx_port_func_t *lb_select_tx_port_get_func(const char *name) | |||
| 174 | static unsigned int lb_get_skb_hash(struct lb_priv *lb_priv, | 174 | static unsigned int lb_get_skb_hash(struct lb_priv *lb_priv, |
| 175 | struct sk_buff *skb) | 175 | struct sk_buff *skb) |
| 176 | { | 176 | { |
| 177 | struct sk_filter *fp; | 177 | struct bpf_prog *fp; |
| 178 | uint32_t lhash; | 178 | uint32_t lhash; |
| 179 | unsigned char *c; | 179 | unsigned char *c; |
| 180 | 180 | ||
| 181 | fp = rcu_dereference_bh(lb_priv->fp); | 181 | fp = rcu_dereference_bh(lb_priv->fp); |
| 182 | if (unlikely(!fp)) | 182 | if (unlikely(!fp)) |
| 183 | return 0; | 183 | return 0; |
| 184 | lhash = SK_RUN_FILTER(fp, skb); | 184 | lhash = BPF_PROG_RUN(fp, skb); |
| 185 | c = (char *) &lhash; | 185 | c = (char *) &lhash; |
| 186 | return c[0] ^ c[1] ^ c[2] ^ c[3]; | 186 | return c[0] ^ c[1] ^ c[2] ^ c[3]; |
| 187 | } | 187 | } |
| @@ -271,8 +271,8 @@ static void __fprog_destroy(struct sock_fprog_kern *fprog) | |||
| 271 | static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx) | 271 | static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx) |
| 272 | { | 272 | { |
| 273 | struct lb_priv *lb_priv = get_lb_priv(team); | 273 | struct lb_priv *lb_priv = get_lb_priv(team); |
| 274 | struct sk_filter *fp = NULL; | 274 | struct bpf_prog *fp = NULL; |
| 275 | struct sk_filter *orig_fp = NULL; | 275 | struct bpf_prog *orig_fp = NULL; |
| 276 | struct sock_fprog_kern *fprog = NULL; | 276 | struct sock_fprog_kern *fprog = NULL; |
| 277 | int err; | 277 | int err; |
| 278 | 278 | ||
| @@ -281,7 +281,7 @@ static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx) | |||
| 281 | ctx->data.bin_val.ptr); | 281 | ctx->data.bin_val.ptr); |
| 282 | if (err) | 282 | if (err) |
| 283 | return err; | 283 | return err; |
| 284 | err = sk_unattached_filter_create(&fp, fprog); | 284 | err = bpf_prog_create(&fp, fprog); |
| 285 | if (err) { | 285 | if (err) { |
| 286 | __fprog_destroy(fprog); | 286 | __fprog_destroy(fprog); |
| 287 | return err; | 287 | return err; |
| @@ -300,7 +300,7 @@ static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx) | |||
| 300 | 300 | ||
| 301 | if (orig_fp) { | 301 | if (orig_fp) { |
| 302 | synchronize_rcu(); | 302 | synchronize_rcu(); |
| 303 | sk_unattached_filter_destroy(orig_fp); | 303 | bpf_prog_destroy(orig_fp); |
| 304 | } | 304 | } |
| 305 | return 0; | 305 | return 0; |
| 306 | } | 306 | } |
