Skip to contentSkip to conversation

openvswitch: enable NSH support

PATCH Superseded Yi Yang 4 participants 6 messages Sep 26, 2017 – Sep 27, 2017 1 message not in the archive

Subsystems (3)

v10 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Yi Yang

author
#0 lore raw

PATCH v10 1/1 openvswitch: enable NSH support

v9->v10
- Change struct ovs_key_nsh to

       struct ovs_nsh_key_base base;
       __be32 context[NSH_MD1_CONTEXT_SIZE];

- Fix new comments for v9

v8->v9
- Fix build error reported by daily intel build because nsh module isn't selected by openvswitch

v7->v8
- Rework nested value and mask for OVS_KEY_ATTR_NSH
- Change pop_nsh to adapt to nsh kernel module
- Fix many issues per comments from Jiri Benc

v6->v7
- Remove NSH GSO patches in v6 because Jiri Benc reworked it as another patch series and they have been merged.
- Change it to adapt to nsh kernel module added by NSH GSO patch series

v5->v6
- Fix the rest comments for v4.
- Add NSH GSO support for VxLAN-gpe + NSH and Eth + NSH.

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 compat mode by porting this.

---
 include/net/nsh.h                |   3 +
 include/uapi/linux/openvswitch.h |  29 ++++
 net/nsh/nsh.c                    |  53 +++++++
 net/openvswitch/Kconfig          |   1 +
 net/openvswitch/actions.c        | 116 ++++++++++++++
 net/openvswitch/flow.c           |  51 +++++++
 net/openvswitch/flow.h           |   7 +
 net/openvswitch/flow_netlink.c   | 317 ++++++++++++++++++++++++++++++++++++++-
 net/openvswitch/flow_netlink.h   |   5 +
 9 files changed, 581 insertions(+), 1 deletion(-)
include/net/nsh.h +3 -0
index a1eaea2..c03b089 100644
@@ -304,4 +304,7 @@ static inline void nsh_set_flags_ttl_len(struct nshhdr *nsh, u8 flags,
 			NSH_FLAGS_MASK | NSH_TTL_MASK | NSH_LEN_MASK);
 }
 
+int skb_push_nsh(struct sk_buff *skb, const struct nshhdr *nh);
+int skb_pop_nsh(struct sk_buff *skb);
+
 #endif /* __NET_NSH_H */
include/uapi/linux/openvswitch.h +29 -0
index 156ee4c..c1a785c 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,30 @@ struct ovs_key_ct_tuple_ipv6 {
 	__u8   ipv6_proto;
 };
 
+enum ovs_nsh_key_attr {
+	OVS_NSH_KEY_ATTR_UNSPEC,
+	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 +831,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 +862,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/nsh/nsh.c +53 -0

59 lines not on this page · raw message

net/openvswitch/Kconfig +1 -0
index ce94729..2650205 100644
@@ -14,6 +14,7 @@ config OPENVSWITCH
 	select MPLS
 	select NET_MPLS_GSO
 	select DST_CACHE
+	select NET_NSH
 	---help---
 	  Open vSwitch is a multilayer Ethernet switch targeted at virtualized
 	  environments.  In addition to supporting a variety of features
net/openvswitch/actions.c +116 -0

146 lines not on this page · raw message

net/openvswitch/flow.c +51 -0

69 lines not on this page · raw message

net/openvswitch/flow.h +7 -0
index 1875bba..8eeae749 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,11 @@ struct vlan_head {
 	(offsetof(struct sw_flow_key, recirc_id) +	\
 	FIELD_SIZEOF(struct sw_flow_key, recirc_id))
 
+struct ovs_key_nsh {
+	struct ovs_nsh_key_base base;
+	__be32 context[NSH_MD1_CONTEXT_SIZE];
+};
+
 struct sw_flow_key {
 	u8 tun_opts[IP_TUNNEL_OPTS_MAX];
 	u8 tun_opts_len;
@@ -144,6 +150,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 +316 -1

409 lines not on this page · raw message

net/openvswitch/flow_netlink.h +5 -0
index 929c665..6657606 100644
@@ -79,4 +79,9 @@ 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,
+			struct ovs_key_nsh *nsh_mask);
+int nsh_hdr_from_nlattr(const struct nlattr *attr, struct nshhdr *nh,
+			size_t size);
+
 #endif /* flow_netlink.h */
Signature · 1 line
2.5.5
#1 lore raw
Quoted 5 lines · Yi Yang

v9->v10
- Change struct ovs_key_nsh to

       struct ovs_nsh_key_base base;
       __be32 context[NSH_MD1_CONTEXT_SIZE];

- Fix new comments for v9

NAK, we haven't finished the discussion for v9 yet. It's not appropriate to send a new version until there's a conclusion (or at least until the discussion dies).

Jiri

#3 lore raw
In reply to a message not in the archive

net/openvswitch/flow_netlink.c static int validate_and_copy_set_tun(const struct nlattr *attr, · line 2537

Quoted 1 line · Yi Yang
net/openvswitch/flow_netlink.c +1 -0
+	return ((ret != 0) ? false : true);

I'm not going to review this version but this caught my eye - I pointed out this silly construct in my review of v9. I can understand that working late in the night and rewriting the code back and forth, one could end up with such construct and overlook it at the final self-review before submission. Happens to everyone.

But leaving this after a review pointed it out means you're not paying enough attention to your work. Even the fact that you sent v10 so shortly after v9 means you did not spend the needed time on reflecting on the review and that you did not properly test the new version. And I told you exactly this before.

Honestly, I'm starting to be tired with reviewing your patch again and again and pointing out silly mistakes like this one and repeating basic things to you again and again.

Jiri

author
#4 lore raw
Quoted 2 lines · Jiri Benc

net/openvswitch/flow_netlink.c static int validate_and_copy_set_tun(const struct nlattr *attr, · line 2537

Quoted 1 line · Yi Yang
net/openvswitch/flow_netlink.c +1 -0
+	return ((ret != 0) ? false : true);

Jiri, I appriciate your review very carefully and professionally from my heart for 10 versions, that is really very very big effort.

I carefully thought this comment:

"""

net/openvswitch/flow_netlink.c static int validate_and_copy_set_tun(const struct nlattr *attr, · line 2537

Quoted 1 line
net/openvswitch/flow_netlink.c +1 -0
+	return ((ret != 0) ? false : true);

Too little coffee or too late in the night, right? ;-) """

But I don't think this is a problematic line from my understanding, because validate_nsh is declared to return bool. I had thought you were saying "it was late, it was time for you to leave office, so no more comments", this is my readout :-)

So the best comment you can give out here is one line you prefer :-)

I'm not a kernel developer full time, I'm adapting to several coding style at the time in kernel, OVS and Opendaylight.

Quoted 13 lines

I'm not going to review this version but this caught my eye - I pointed out this silly construct in my review of v9. I can understand that working late in the night and rewriting the code back and forth, one could end up with such construct and overlook it at the final self-review before submission. Happens to everyone.

But leaving this after a review pointed it out means you're not paying enough attention to your work. Even the fact that you sent v10 so shortly after v9 means you did not spend the needed time on reflecting on the review and that you did not properly test the new version. And I told you exactly this before.

Quoted 3 lines

Honestly, I'm starting to be tired with reviewing your patch again and again and pointing out silly mistakes like this one and repeating basic things to you again and again.

I did test it in my sfc test environment, I don't see any warning, error during build and runtime, it can work well.

Sorry if missing your comments, that is understanding issue in most cases but not I don't take your comments seriously. You know English isn't my native language, it is a big challenge for me to understand your comments very well. Neverthless, code is our common language, I can understand code better than your descriptive words :-)

Quoted 2 lines

Jiri

#5 lore raw
Quoted 3 lines · Yi

net/openvswitch/flow_netlink.c static int validate_and_copy_set_tun(const struct nlattr *attr, · line 2537

Quoted 1 line
net/openvswitch/flow_netlink.c +1 -0
+	return ((ret != 0) ? false : true);

But I don't think this is a problematic line from my understanding,

Why not:

	return ((ret != 0 == true) ? false : true) == true;

?

Sigh. This is equal to:

	return !ret;

which you should use.

Jiri

#6 lore raw
Quoted 9 lines · Jiri Benc
Quoted 3 lines · Yi

net/openvswitch/flow_netlink.c static int validate_and_copy_set_tun(const struct nlattr *attr, · line 2537

Quoted 1 line
net/openvswitch/flow_netlink.c +1 -0
+	return ((ret != 0) ? false : true);

But I don't think this is a problematic line from my understanding,

Why not:

	return ((ret != 0 == true) ? false : true) == true;
Quoted 7 lines

?

Sigh. This is equal to:

	return !ret;

which you should use.

Ok, got it, I'll use "return !ret;", real programming art :-), I also saw !!(condition), personally its readability is not good, typical kernel style :-)