aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2014-03-28 13:58:21 -0400
committerDavid S. Miller <davem@davemloft.net>2014-03-31 00:45:09 -0400
commite62d2df084e2849edffb206559725fa81bb569a8 (patch)
tree61e780e343f2c78d4f1ad0be6035ccdff467a36b /net/core
parentfbc907f0b1386c02e00516aa78a0fa6b0454fd0b (diff)
net: ptp: use sk_unattached_filter_create() for BPF
This patch migrates an open-coded sk_run_filter() implementation with proper use of the BPF API, that is, sk_unattached_filter_create(). This migration is needed, as we will be internally transforming the filter to a different representation, and therefore needs to be decoupled. It is okay to do so as skb_timestamping_init() is called during initialization of the network stack in core initcall via sock_init(). This would effectively also allow for PTP filters to be jit compiled if bpf_jit_enable is set. For better readability, there are also some newlines introduced, also ptp_classify.h is only in kernel space. Joint work with Alexei Starovoitov. Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Cc: Richard Cochran <richard.cochran@omicron.at> Cc: Jiri Benc <jbenc@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/timestamping.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/net/core/timestamping.c b/net/core/timestamping.c
index 661b5a40ec10..e43d56acf803 100644
--- a/net/core/timestamping.c
+++ b/net/core/timestamping.c
@@ -23,16 +23,13 @@
23#include <linux/skbuff.h> 23#include <linux/skbuff.h>
24#include <linux/export.h> 24#include <linux/export.h>
25 25
26static struct sock_filter ptp_filter[] = { 26static struct sk_filter *ptp_insns __read_mostly;
27 PTP_FILTER
28};
29 27
30static unsigned int classify(const struct sk_buff *skb) 28static unsigned int classify(const struct sk_buff *skb)
31{ 29{
32 if (likely(skb->dev && 30 if (likely(skb->dev && skb->dev->phydev &&
33 skb->dev->phydev &&
34 skb->dev->phydev->drv)) 31 skb->dev->phydev->drv))
35 return sk_run_filter(skb, ptp_filter); 32 return SK_RUN_FILTER(ptp_insns, skb);
36 else 33 else
37 return PTP_CLASS_NONE; 34 return PTP_CLASS_NONE;
38} 35}
@@ -60,11 +57,13 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
60 if (likely(phydev->drv->txtstamp)) { 57 if (likely(phydev->drv->txtstamp)) {
61 if (!atomic_inc_not_zero(&sk->sk_refcnt)) 58 if (!atomic_inc_not_zero(&sk->sk_refcnt))
62 return; 59 return;
60
63 clone = skb_clone(skb, GFP_ATOMIC); 61 clone = skb_clone(skb, GFP_ATOMIC);
64 if (!clone) { 62 if (!clone) {
65 sock_put(sk); 63 sock_put(sk);
66 return; 64 return;
67 } 65 }
66
68 clone->sk = sk; 67 clone->sk = sk;
69 phydev->drv->txtstamp(phydev, clone, type); 68 phydev->drv->txtstamp(phydev, clone, type);
70 } 69 }
@@ -89,12 +88,15 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
89 } 88 }
90 89
91 *skb_hwtstamps(skb) = *hwtstamps; 90 *skb_hwtstamps(skb) = *hwtstamps;
91
92 serr = SKB_EXT_ERR(skb); 92 serr = SKB_EXT_ERR(skb);
93 memset(serr, 0, sizeof(*serr)); 93 memset(serr, 0, sizeof(*serr));
94 serr->ee.ee_errno = ENOMSG; 94 serr->ee.ee_errno = ENOMSG;
95 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING; 95 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
96 skb->sk = NULL; 96 skb->sk = NULL;
97
97 err = sock_queue_err_skb(sk, skb); 98 err = sock_queue_err_skb(sk, skb);
99
98 sock_put(sk); 100 sock_put(sk);
99 if (err) 101 if (err)
100 kfree_skb(skb); 102 kfree_skb(skb);
@@ -135,5 +137,10 @@ EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);
135 137
136void __init skb_timestamping_init(void) 138void __init skb_timestamping_init(void)
137{ 139{
138 BUG_ON(sk_chk_filter(ptp_filter, ARRAY_SIZE(ptp_filter))); 140 static struct sock_filter ptp_filter[] = { PTP_FILTER };
141 struct sock_fprog ptp_prog = {
142 .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
143 };
144
145 BUG_ON(sk_unattached_filter_create(&ptp_insns, &ptp_prog));
139} 146}