Netdev List
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jhs@mojatatu.com, tgraf@suug.ch,
	jesse@nicira.com, kaber@trash.net, therbert@google.com,
	edumazet@google.com, alexander.h.duyck@redhat.com,
	hannes@stressinduktion.org, ast@plumgrid.com,
	daniel@iogearbox.net, herbert@gondor.apana.org.au,
	cwang@twopensource.com, john.fastabend@gmail.com
Subject: [patch net-next v4 RFC 09/15] flow_dissector: introduce programable flow_dissector
Date: Fri, 24 Apr 2015 17:51:35 +0200	[thread overview]
Message-ID: <1429890701-30052-10-git-send-email-jiri@resnulli.us> (raw)
In-Reply-To: <1429890701-30052-1-git-send-email-jiri@resnulli.us>

Introduce dissector infrastructure which allows user to specify which
parts of skb he wants to dissect.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 include/net/flow_dissector.h | 61 ++++++++++++++++++++++++++++++++++++++++++++
 net/core/flow_dissector.c    | 48 ++++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)

diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index 8a5bf48..3bdf6a1 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -1,6 +1,64 @@
 #ifndef _NET_FLOW_DISSECTOR_H
 #define _NET_FLOW_DISSECTOR_H
 
+/**
+ * struct flow_dissector_key_basic:
+ * @thoff: Transport header offset
+ * @n_proto: Network header protocol (eg. IPv4/IPv6)
+ * @ip_proto: Transport header protocol (eg. TCP/UDP)
+ */
+struct flow_dissector_key_basic {
+	u16	thoff;
+	__be16	n_proto;
+	u8	ip_proto;
+};
+
+/**
+ * struct flow_dissector_key_addrs:
+ * @src: source ip address in case of IPv4
+ *	 For IPv6 it contains 32bit hash of src address
+ * @dst: destination ip address in case of IPv4
+ *	 For IPv6 it contains 32bit hash of dst address
+ */
+struct flow_dissector_key_addrs {
+	/* (src,dst) must be grouped, in the same way than in IP header */
+	__be32 src;
+	__be32 dst;
+};
+
+/**
+ * flow_dissector_key_tp_ports:
+ *	@ports: port numbers of Transport header
+ *		port16[0]: src port number
+ *		port16[1]: dst port number
+ */
+struct flow_dissector_key_ports {
+	union {
+		__be32 ports;
+		__be16 port16[2];
+	};
+};
+
+enum flow_dissector_key_id {
+	FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
+	FLOW_DISSECTOR_KEY_IPV4_ADDRS, /* struct flow_dissector_key_addrs */
+	FLOW_DISSECTOR_KEY_IPV6_HASH_ADDRS, /* struct flow_dissector_key_addrs */
+	FLOW_DISSECTOR_KEY_PORTS, /* struct flow_dissector_key_ports */
+
+	FLOW_DISSECTOR_KEY_MAX,
+};
+
+struct flow_dissector_key {
+	enum flow_dissector_key_id key_id;
+	size_t offset; /* offset of struct flow_dissector_key_*
+			  in target the struct */
+};
+
+struct flow_dissector {
+	unsigned int used_keys; /* each bit repesents presence of one key id */
+	unsigned short int offset[FLOW_DISSECTOR_KEY_MAX];
+};
+
 /* struct flow_keys:
  *	@src: source ip address in case of IPv4
  *	      For IPv6 it contains 32bit hash of src address
@@ -27,6 +85,9 @@ struct flow_keys {
 	u8	ip_proto;
 };
 
+void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
+			     const struct flow_dissector_key *key,
+			     unsigned int key_count);
 bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,
 			void *data, __be16 proto, int nhoff, int hlen);
 
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 5213d73..1566768 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -1,3 +1,4 @@
+#include <linux/kernel.h>
 #include <linux/skbuff.h>
 #include <linux/export.h>
 #include <linux/ip.h>
@@ -15,6 +16,53 @@
 #include <net/flow_dissector.h>
 #include <scsi/fc/fc_fcoe.h>
 
+static bool skb_flow_dissector_uses_key(struct flow_dissector *flow_dissector,
+					enum flow_dissector_key_id key_id)
+{
+	return flow_dissector->used_keys & (1 << key_id);
+}
+
+static void skb_flow_dissector_set_key(struct flow_dissector *flow_dissector,
+				       enum flow_dissector_key_id key_id)
+{
+	flow_dissector->used_keys |= (1 << key_id);
+}
+
+static void *skb_flow_dissector_target(struct flow_dissector *flow_dissector,
+				       enum flow_dissector_key_id key_id,
+				       void *target_container)
+{
+	return ((char *) target_container) + flow_dissector->offset[key_id];
+}
+
+void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
+			     const struct flow_dissector_key *key,
+			     unsigned int key_count)
+{
+	unsigned int i;
+
+	memset(flow_dissector, 0, sizeof(*flow_dissector));
+
+	for (i = 0; i < key_count; i++, key++) {
+		/* User should make sure that every key target offset is withing
+		 * boundaries of unsigned short.
+		 */
+		BUG_ON(key->offset > USHRT_MAX);
+		BUG_ON(skb_flow_dissector_uses_key(flow_dissector,
+						   key->key_id));
+
+		skb_flow_dissector_set_key(flow_dissector, key->key_id);
+		flow_dissector->offset[key->key_id] = key->offset;
+	}
+
+	/* Ensure that the dissector always includes basic key. That way
+	 * we are able to avoid handling lack of it in fast path.
+	 */
+	BUG_ON(!skb_flow_dissector_uses_key(flow_dissector,
+					    FLOW_DISSECTOR_KEY_BASIC));
+}
+EXPORT_SYMBOL(skb_flow_dissector_init);
+
 /* copy saddr & daddr, possibly using 64bit load/store
  * Equivalent to :	flow->src = iph->saddr;
  *			flow->dst = iph->daddr;
-- 
1.9.3

  parent reply	other threads:[~2015-04-24 15:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-24 15:51 [patch net-next v4 RFC 00/15] introduce programable flow dissector and cls_flower Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 01/15] net: change name of flow_dissector header to match the .c file name Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 02/15] flow_dissector: remove unused function flow_get_hlen declaration Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 03/15] net: move *skb_get_poff declarations into correct header Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 04/15] flow_dissector: fix doc for __skb_get_hash and remove couple of empty lines Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 05/15] net: move __skb_get_hash function declaration to flow_dissector.h Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 06/15] net: move __skb_tx_hash to skbuff.c Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 07/15] net: move netdev_pick_tx and dependencies to net/core/dev.c Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 08/15] flow_dissector: fix doc for skb_get_poff Jiri Pirko
2015-04-24 15:51 ` Jiri Pirko [this message]
2015-04-24 15:51 ` [patch net-next v4 RFC 10/15] flow_dissect: use programable dissector in skb_flow_dissect and friends Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 11/15] flow_dissector: add missing header includes Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 12/15] flow_dissector: introduce support for ipv6 addressses Jiri Pirko
2015-04-24 17:28   ` Tom Herbert
2015-04-25 19:17     ` Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 13/15] flow_dissector: introduce support for Ethernet addresses Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 14/15] flow_dissector: change port array into src,dst tuple Jiri Pirko
2015-04-24 15:51 ` [patch net-next v4 RFC 15/15] tc: introduce Flower classifier Jiri Pirko
2015-04-26 19:55 ` [patch net-next v4 RFC 00/15] introduce programable flow dissector and cls_flower Or Gerlitz
2015-04-26 19:57   ` Or Gerlitz
2015-04-26 23:33 ` Tom Herbert

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=1429890701-30052-10-git-send-email-jiri@resnulli.us \
    --to=jiri@resnulli.us \
    --cc=alexander.h.duyck@redhat.com \
    --cc=ast@plumgrid.com \
    --cc=cwang@twopensource.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hannes@stressinduktion.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=jesse@nicira.com \
    --cc=jhs@mojatatu.com \
    --cc=john.fastabend@gmail.com \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    --cc=therbert@google.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox