Skip to content

Commit 568f194

Browse files
Daniel Borkmanndavem330
authored andcommitted
net: ppp: use sk_unattached_filter api
For the ppp driver, there are currently two open-coded BPF filters in use, that is, pass_filter and active_filter. Migrate both to make proper use of sk_unattached_filter_{create,destroy} API so that the actual BPF code is decoupled from direct access, and filters can be jited as a side-effect by the internal filter compiler. Joint work with Alexei Starovoitov. Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Cc: Paul Mackerras <paulus@samba.org> Cc: linux-ppp@vger.kernel.org Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 164d8c6 commit 568f194

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

drivers/net/ppp/ppp_generic.c

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ struct ppp {
143143
struct sk_buff_head mrq; /* MP: receive reconstruction queue */
144144
#endif /* CONFIG_PPP_MULTILINK */
145145
#ifdef CONFIG_PPP_FILTER
146-
struct sock_filter *pass_filter; /* filter for packets to pass */
147-
struct sock_filter *active_filter;/* filter for pkts to reset idle */
148-
unsigned pass_len, active_len;
146+
struct sk_filter *pass_filter; /* filter for packets to pass */
147+
struct sk_filter *active_filter;/* filter for pkts to reset idle */
149148
#endif /* CONFIG_PPP_FILTER */
150149
struct net *ppp_net; /* the net we belong to */
151150
struct ppp_link_stats stats64; /* 64 bit network stats */
@@ -755,28 +754,42 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
755754
case PPPIOCSPASS:
756755
{
757756
struct sock_filter *code;
757+
758758
err = get_filter(argp, &code);
759759
if (err >= 0) {
760+
struct sock_fprog fprog = {
761+
.len = err,
762+
.filter = code,
763+
};
764+
760765
ppp_lock(ppp);
761-
kfree(ppp->pass_filter);
762-
ppp->pass_filter = code;
763-
ppp->pass_len = err;
766+
if (ppp->pass_filter)
767+
sk_unattached_filter_destroy(ppp->pass_filter);
768+
err = sk_unattached_filter_create(&ppp->pass_filter,
769+
&fprog);
770+
kfree(code);
764771
ppp_unlock(ppp);
765-
err = 0;
766772
}
767773
break;
768774
}
769775
case PPPIOCSACTIVE:
770776
{
771777
struct sock_filter *code;
778+
772779
err = get_filter(argp, &code);
773780
if (err >= 0) {
781+
struct sock_fprog fprog = {
782+
.len = err,
783+
.filter = code,
784+
};
785+
774786
ppp_lock(ppp);
775-
kfree(ppp->active_filter);
776-
ppp->active_filter = code;
777-
ppp->active_len = err;
787+
if (ppp->active_filter)
788+
sk_unattached_filter_destroy(ppp->active_filter);
789+
err = sk_unattached_filter_create(&ppp->active_filter,
790+
&fprog);
791+
kfree(code);
778792
ppp_unlock(ppp);
779-
err = 0;
780793
}
781794
break;
782795
}
@@ -1184,7 +1197,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
11841197
a four-byte PPP header on each packet */
11851198
*skb_push(skb, 2) = 1;
11861199
if (ppp->pass_filter &&
1187-
sk_run_filter(skb, ppp->pass_filter) == 0) {
1200+
SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
11881201
if (ppp->debug & 1)
11891202
netdev_printk(KERN_DEBUG, ppp->dev,
11901203
"PPP: outbound frame "
@@ -1194,7 +1207,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
11941207
}
11951208
/* if this packet passes the active filter, record the time */
11961209
if (!(ppp->active_filter &&
1197-
sk_run_filter(skb, ppp->active_filter) == 0))
1210+
SK_RUN_FILTER(ppp->active_filter, skb) == 0))
11981211
ppp->last_xmit = jiffies;
11991212
skb_pull(skb, 2);
12001213
#else
@@ -1818,7 +1831,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
18181831

18191832
*skb_push(skb, 2) = 0;
18201833
if (ppp->pass_filter &&
1821-
sk_run_filter(skb, ppp->pass_filter) == 0) {
1834+
SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
18221835
if (ppp->debug & 1)
18231836
netdev_printk(KERN_DEBUG, ppp->dev,
18241837
"PPP: inbound frame "
@@ -1827,7 +1840,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
18271840
return;
18281841
}
18291842
if (!(ppp->active_filter &&
1830-
sk_run_filter(skb, ppp->active_filter) == 0))
1843+
SK_RUN_FILTER(ppp->active_filter, skb) == 0))
18311844
ppp->last_recv = jiffies;
18321845
__skb_pull(skb, 2);
18331846
} else
@@ -2672,6 +2685,10 @@ ppp_create_interface(struct net *net, int unit, int *retp)
26722685
ppp->minseq = -1;
26732686
skb_queue_head_init(&ppp->mrq);
26742687
#endif /* CONFIG_PPP_MULTILINK */
2688+
#ifdef CONFIG_PPP_FILTER
2689+
ppp->pass_filter = NULL;
2690+
ppp->active_filter = NULL;
2691+
#endif /* CONFIG_PPP_FILTER */
26752692

26762693
/*
26772694
* drum roll: don't forget to set
@@ -2802,10 +2819,15 @@ static void ppp_destroy_interface(struct ppp *ppp)
28022819
skb_queue_purge(&ppp->mrq);
28032820
#endif /* CONFIG_PPP_MULTILINK */
28042821
#ifdef CONFIG_PPP_FILTER
2805-
kfree(ppp->pass_filter);
2806-
ppp->pass_filter = NULL;
2807-
kfree(ppp->active_filter);
2808-
ppp->active_filter = NULL;
2822+
if (ppp->pass_filter) {
2823+
sk_unattached_filter_destroy(ppp->pass_filter);
2824+
ppp->pass_filter = NULL;
2825+
}
2826+
2827+
if (ppp->active_filter) {
2828+
sk_unattached_filter_destroy(ppp->active_filter);
2829+
ppp->active_filter = NULL;
2830+
}
28092831
#endif /* CONFIG_PPP_FILTER */
28102832

28112833
kfree_skb(ppp->xmit_pending);

0 commit comments

Comments
 (0)