Skip to contentSkip to conversation

openvswitch: enable NSH support

PATCH Superseded Yi Yang 3 participants 4 messages Aug 21, 2017 – Aug 22, 2017 1 message not in the archive

Subsystems (3)

v5 of 17 Superseded Latest is v17 →

lore
Share & tools
lore

Yi Yang

author
#0 lore raw

PATCH v5 1/1 openvswitch: enable NSH support

v4->v5
- Fix many comments by Jiri Benc and Eric Garver for v4.

v3->v4
- Add new NSH match field ttl
- Update NSH header to the latest format which will be final format and won't change per its author's confirmation.
- Fix comments for v3.

v2->v3
- Change OVS_KEY_ATTR_NSH to nested key to handle length-fixed attributes and length-variable attriubte more flexibly.
- Remove struct ovs_action_push_nsh completely
- Add code to handle nested attribute for SET_MASKED
- Change PUSH_NSH to use the nested OVS_KEY_ATTR_NSH to transfer NSH header data.
- Fix comments and coding style issues by Jiri and Eric

v1->v2
- Change encap_nsh and decap_nsh to push_nsh and pop_nsh
- Dynamically allocate struct ovs_action_push_nsh for length-variable metadata.

OVS master and 2.8 branch has merged NSH userspace patch series, this patch is to enable NSH support in kernel data path in order that OVS can support NSH in 2.8 release in compat mode by porting this.

---
 drivers/net/vxlan.c              |   7 +
 include/net/nsh.h                | 307 +++++++++++++++++++++++++++++
 include/uapi/linux/if_ether.h    |   1 +
 include/uapi/linux/openvswitch.h |  28 +++
 net/openvswitch/actions.c        | 181 ++++++++++++++++++
 net/openvswitch/flow.c           |  50 +++++
 net/openvswitch/flow.h           |  11 ++
 net/openvswitch/flow_netlink.c   | 404 ++++++++++++++++++++++++++++++++++++++-
 net/openvswitch/flow_netlink.h   |   4 +
 9 files changed, 992 insertions(+), 1 deletion(-)
 create mode 100644 include/net/nsh.h
drivers/net/vxlan.c +7 -0
index ae3a1da..a36c41e 100644
@@ -27,6 +27,7 @@
 #include <net/net_namespace.h>
 #include <net/netns/generic.h>
 #include <net/vxlan.h>
+#include <net/nsh.h>
 
 #if IS_ENABLED(CONFIG_IPV6)
 #include <net/ip6_tunnel.h>
@@ -1268,6 +1269,9 @@ static bool vxlan_parse_gpe_hdr(struct vxlanhdr *unparsed,
 	case VXLAN_GPE_NP_IPV6:
 		*protocol = htons(ETH_P_IPV6);
 		break;
+	case VXLAN_GPE_NP_NSH:
+		*protocol = htons(ETH_P_NSH);
+		break;
 	case VXLAN_GPE_NP_ETHERNET:
 		*protocol = htons(ETH_P_TEB);
 		break;
@@ -1807,6 +1811,9 @@ static int vxlan_build_gpe_hdr(struct vxlanhdr *vxh, u32 vxflags,
 	case htons(ETH_P_IPV6):
 		gpe->next_protocol = VXLAN_GPE_NP_IPV6;
 		return 0;
+	case htons(ETH_P_NSH):
+		gpe->next_protocol = VXLAN_GPE_NP_NSH;
+		return 0;
 	case htons(ETH_P_TEB):
 		gpe->next_protocol = VXLAN_GPE_NP_ETHERNET;
 		return 0;
include/net/nsh.h new file +307 -0

307 lines not on this page · raw message

include/uapi/linux/if_ether.h +1 -0
index 5bc9bfd..e7f1a61 100644
@@ -137,6 +137,7 @@
 #define ETH_P_IEEE802154 0x00F6		/* IEEE802.15.4 frame		*/
 #define ETH_P_CAIF	0x00F7		/* ST-Ericsson CAIF protocol	*/
 #define ETH_P_XDSA	0x00F8		/* Multiplexed DSA protocol	*/
+#define ETH_P_NSH	0x894F		/* Ethertype for NSH. */
 
 /*
  *	This is an Ethernet frame header.
include/uapi/linux/openvswitch.h +28 -0
index 156ee4c..91dee5b 100644
@@ -333,6 +333,7 @@ enum ovs_key_attr {
 	OVS_KEY_ATTR_CT_LABELS,	/* 16-octet connection tracking label */
 	OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4,   /* struct ovs_key_ct_tuple_ipv4 */
 	OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6,   /* struct ovs_key_ct_tuple_ipv6 */
+	OVS_KEY_ATTR_NSH,       /* Nested set of ovs_nsh_key_* */
 
 #ifdef __KERNEL__
 	OVS_KEY_ATTR_TUNNEL_INFO,  /* struct ip_tunnel_info */
@@ -491,6 +492,29 @@ struct ovs_key_ct_tuple_ipv6 {
 	__u8   ipv6_proto;
 };
 
+enum ovs_nsh_key_attr {
+	OVS_NSH_KEY_ATTR_BASE,  /* struct ovs_nsh_key_base. */
+	OVS_NSH_KEY_ATTR_MD1,   /* struct ovs_nsh_key_md1. */
+	OVS_NSH_KEY_ATTR_MD2,   /* variable-length octets for MD type 2. */
+	__OVS_NSH_KEY_ATTR_MAX
+};
+
+#define OVS_NSH_KEY_ATTR_MAX (__OVS_NSH_KEY_ATTR_MAX - 1)
+
+struct ovs_nsh_key_base {
+	__u8 flags;
+	__u8 ttl;
+	__u8 mdtype;
+	__u8 np;
+	__be32 path_hdr;
+};
+
+#define NSH_MD1_CONTEXT_SIZE 4
+
+struct ovs_nsh_key_md1 {
+	__be32 context[NSH_MD1_CONTEXT_SIZE];
+};
+
 /**
  * enum ovs_flow_attr - attributes for %OVS_FLOW_* commands.
  * @OVS_FLOW_ATTR_KEY: Nested %OVS_KEY_ATTR_* attributes specifying the flow
@@ -806,6 +830,8 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_PUSH_NSH: push NSH header to the packet.
+ * @OVS_ACTION_ATTR_POP_NSH: pop the outermost NSH header off the packet.
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -835,6 +861,8 @@ enum ovs_action_attr {
 	OVS_ACTION_ATTR_TRUNC,        /* u32 struct ovs_action_trunc. */
 	OVS_ACTION_ATTR_PUSH_ETH,     /* struct ovs_action_push_eth. */
 	OVS_ACTION_ATTR_POP_ETH,      /* No argument. */
+	OVS_ACTION_ATTR_PUSH_NSH,     /* Nested OVS_NSH_KEY_ATTR_*. */
+	OVS_ACTION_ATTR_POP_NSH,      /* No argument. */
 
 	__OVS_ACTION_ATTR_MAX,	      /* Nothing past this will be accepted
 				       * from userspace. */
net/openvswitch/actions.c +181 -0

211 lines not on this page · raw message

net/openvswitch/flow.c +50 -0

68 lines not on this page · raw message

net/openvswitch/flow.h +11 -0
index 1875bba..6a3cd9c 100644
@@ -35,6 +35,7 @@
 #include <net/inet_ecn.h>
 #include <net/ip_tunnels.h>
 #include <net/dst_metadata.h>
+#include <net/nsh.h>
 
 struct sk_buff;
 
@@ -66,6 +67,15 @@ struct vlan_head {
 	(offsetof(struct sw_flow_key, recirc_id) +	\
 	FIELD_SIZEOF(struct sw_flow_key, recirc_id))
 
+struct ovs_key_nsh {
+	u8 flags;
+	u8 ttl;
+	u8 mdtype;
+	u8 np;
+	__be32 path_hdr;
+	__be32 context[NSH_MD1_CONTEXT_SIZE];
+};
+
 struct sw_flow_key {
 	u8 tun_opts[IP_TUNNEL_OPTS_MAX];
 	u8 tun_opts_len;
@@ -144,6 +154,7 @@ struct sw_flow_key {
 			};
 		} ipv6;
 	};
+	struct ovs_key_nsh nsh;         /* network service header */
 	struct {
 		/* Connection tracking fields not packed above. */
 		struct {
net/openvswitch/flow_netlink.c +403 -1

490 lines not on this page · raw message

net/openvswitch/flow_netlink.h +4 -0
index 929c665..a849945 100644
@@ -79,4 +79,8 @@ int ovs_nla_put_actions(const struct nlattr *attr,
 void ovs_nla_free_flow_actions(struct sw_flow_actions *);
 void ovs_nla_free_flow_actions_rcu(struct sw_flow_actions *);
 
+int nsh_key_from_nlattr(const struct nlattr *attr, struct ovs_key_nsh *nsh);
+int nsh_hdr_from_nlattr(const struct nlattr *attr, struct nsh_hdr *nsh_src,
+			size_t size);
+
 #endif /* flow_netlink.h */
Signature · 1 line
2.5.5
#2 lore raw
In reply to a message not in the archive
Quoted 3 lines · Yi Yang

v4->v5
- Fix many comments by Jiri Benc and Eric Garver
for v4.

NACK for v5, we haven't finished discussing v4. You're sending new versions too quickly.

My comment about sending a new version was meant only for the rest of the patch that I have not reviewed - i.e. that once the comments I've made so far are addressed, I'm fine with continuing reviewing in a new version.

It did not mean that I'm okay with sending a new version without my comments to the first part being addressed. Which they are not, see my reply to your mail at v4.

Sorry if that was not clear but I won't review v5 until we have conclusion for the v4 comments.

Jiri

author
#3 lore raw
Quoted 13 lines · Jiri Benc
Quoted 3 lines · Yi Yang

v4->v5
- Fix many comments by Jiri Benc and Eric Garver
for v4.

NACK for v5, we haven't finished discussing v4. You're sending new versions too quickly.

My comment about sending a new version was meant only for the rest of the patch that I have not reviewed - i.e. that once the comments I've made so far are addressed, I'm fine with continuing reviewing in a new version.

Quoted 6 lines

It did not mean that I'm okay with sending a new version without my comments to the first part being addressed. Which they are not, see my reply to your mail at v4.

Sorry if that was not clear but I won't review v5 until we have conclusion for the v4 comments.

Ok, let me fix comments for v4 first.

Quoted 2 lines

Jiri

#4 lore raw
In reply to a message not in the archive
url: https://github.com/0day-ci/linux/commits/Yi-Yang/openvswitch-enable-NSH-support/20170822-184251 config: x86_64-randconfig-a0-08230538 (attached as .config) compiler: gcc-4.4 (Debian 4.4.7-8)…

Hi Yi,

[auto build test WARNING on net-next/master]

url: https://github.com/0day-ci/linux/commits/Yi-Yang/openvswitch-enable-NSH-support/20170822-184251
config: x86_64-randconfig-a0-08230538 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

net//openvswitch/flow.c: In function 'parse_nsh':

>> net//openvswitch/flow.c:498: warning: unused variable 'err'

vim +/err +498 net//openvswitch/flow.c

493
494 static int parse_nsh(struct sk_buff *skb, struct sw_flow_key *key)
495 {
496 struct nsh_hdr *nsh = (struct nsh_hdr *)skb_network_header(skb);
497 u8 version, length;

 > 498		int err;

499
500 if (unlikely(skb->len < NSH_BASE_HDR_LEN))
501 return -EINVAL;
502
503 version = nsh_get_ver(nsh);
504 length = nsh_hdr_len(nsh);
505
506 if (version != 0)
507 return -EINVAL;
508
509 if (unlikely(skb->len < length))
510 return -EINVAL;
511
512 key->nsh.flags = nsh_get_flags(nsh);
513 key->nsh.ttl = nsh_get_ttl(nsh);
514 key->nsh.mdtype = nsh->md_type;
515 key->nsh.np = nsh->next_proto;
516 key->nsh.path_hdr = nsh->path_hdr;
517 switch (key->nsh.mdtype) {
518 case NSH_M_TYPE1:
519 if (length != NSH_M_TYPE1_LEN)
520 return -EINVAL;
521 memcpy(key->nsh.context, nsh->md1.context,
522 sizeof(nsh->md1));
523 break;
524 case NSH_M_TYPE2:
525 /* Don't support MD type 2 metedata parsing yet */
526 if (length < NSH_BASE_HDR_LEN)
527 return -EINVAL;
528
529 memset(key->nsh.context, 0,
530 sizeof(nsh->md1));
531 break;
532 default:
533 return -EINVAL;
534 }
535
536 return 0;
537 }
538

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation