All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Borkmann <dborkman@redhat.com>
To: davem@davemloft.net
Cc: ast@plumgrid.com, netdev@vger.kernel.org,
	Richard Cochran <richard.cochran@omicron.at>,
	Jiri Benc <jbenc@redhat.com>
Subject: [PATCH net-next 4/9] net: ptp: use sk_unattached_filter_create() for BPF
Date: Fri, 21 Mar 2014 13:20:13 +0100	[thread overview]
Message-ID: <1395404418-25376-5-git-send-email-dborkman@redhat.com> (raw)
In-Reply-To: <1395404418-25376-1-git-send-email-dborkman@redhat.com>

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>
---
 include/linux/ptp_classify.h |  4 ----
 net/core/timestamping.c      | 21 ++++++++++++++-------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h
index 1dc420b..3decfa4 100644
--- a/include/linux/ptp_classify.h
+++ b/include/linux/ptp_classify.h
@@ -27,11 +27,7 @@
 #include <linux/if_vlan.h>
 #include <linux/ip.h>
 #include <linux/filter.h>
-#ifdef __KERNEL__
 #include <linux/in.h>
-#else
-#include <netinet/in.h>
-#endif
 
 #define PTP_CLASS_NONE  0x00 /* not a PTP event message */
 #define PTP_CLASS_V1    0x01 /* protocol version 1 */
diff --git a/net/core/timestamping.c b/net/core/timestamping.c
index 661b5a4..837485d 100644
--- a/net/core/timestamping.c
+++ b/net/core/timestamping.c
@@ -23,16 +23,13 @@
 #include <linux/skbuff.h>
 #include <linux/export.h>
 
-static struct sock_filter ptp_filter[] = {
-	PTP_FILTER
-};
+static struct sk_filter *ptp_insns __read_mostly;
 
 static unsigned int classify(const struct sk_buff *skb)
 {
-	if (likely(skb->dev &&
-		   skb->dev->phydev &&
+	if (likely(skb->dev && skb->dev->phydev &&
 		   skb->dev->phydev->drv))
-		return sk_run_filter(skb, ptp_filter);
+		return SK_RUN_FILTER(ptp_insns, skb);
 	else
 		return PTP_CLASS_NONE;
 }
@@ -60,11 +57,13 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
 		if (likely(phydev->drv->txtstamp)) {
 			if (!atomic_inc_not_zero(&sk->sk_refcnt))
 				return;
+
 			clone = skb_clone(skb, GFP_ATOMIC);
 			if (!clone) {
 				sock_put(sk);
 				return;
 			}
+
 			clone->sk = sk;
 			phydev->drv->txtstamp(phydev, clone, type);
 		}
@@ -89,12 +88,15 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
 	}
 
 	*skb_hwtstamps(skb) = *hwtstamps;
+
 	serr = SKB_EXT_ERR(skb);
 	memset(serr, 0, sizeof(*serr));
 	serr->ee.ee_errno = ENOMSG;
 	serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
 	skb->sk = NULL;
+
 	err = sock_queue_err_skb(sk, skb);
+
 	sock_put(sk);
 	if (err)
 		kfree_skb(skb);
@@ -135,5 +137,10 @@ EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);
 
 void __init skb_timestamping_init(void)
 {
-	BUG_ON(sk_chk_filter(ptp_filter, ARRAY_SIZE(ptp_filter)));
+	struct sock_filter ptp_filter[] = { PTP_FILTER };
+	struct sock_fprog ptp_prog = {
+		.len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
+	};
+
+	BUG_ON(sk_unattached_filter_create(&ptp_insns, &ptp_prog));
 }
-- 
1.7.11.7

  parent reply	other threads:[~2014-03-21 12:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-21 12:20 [PATCH net-next 0/9] BPF updates Daniel Borkmann
2014-03-21 12:20 ` [PATCH net-next 1/9] net: filter: add jited flag to indicate jit compiled filters Daniel Borkmann
2014-03-21 12:20 ` [PATCH net-next 2/9] net: filter: keep original BPF program around Daniel Borkmann
2014-03-21 12:20 ` [PATCH net-next 3/9] net: filter: move filter accounting to filter core Daniel Borkmann
2014-03-21 12:20 ` Daniel Borkmann [this message]
2014-03-24 22:39   ` [PATCH net-next 4/9] net: ptp: use sk_unattached_filter_create() for BPF David Miller
2014-03-21 12:20 ` [PATCH net-next 5/9] net: ptp: do not reimplement PTP/BPF classifier Daniel Borkmann
2014-03-21 12:20 ` [PATCH net-next 6/9] net: ppp: use sk_unattached_filter api Daniel Borkmann
2014-03-21 12:20   ` Daniel Borkmann
2014-03-21 12:20 ` [PATCH net-next 7/9] net: isdn: " Daniel Borkmann
2014-03-21 12:20 ` [PATCH net-next 8/9] net: filter: rework/optimize internal BPF interpreter's instruction set Daniel Borkmann
2014-03-21 15:40   ` Kees Cook
2014-03-21 12:20 ` [PATCH net-next 9/9] doc: filter: extend BPF documentation to document new internals Daniel Borkmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1395404418-25376-5-git-send-email-dborkman@redhat.com \
    --to=dborkman@redhat.com \
    --cc=ast@plumgrid.com \
    --cc=davem@davemloft.net \
    --cc=jbenc@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=richard.cochran@omicron.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.