Skip to contentSkip to conversation

openvswitch: add NSH support

PATCH Superseded Yi Yang 6 participants 10 messages Aug 8, 2017 – Aug 9, 2017 4 messages not in the archive

Subsystems (4)

v1 of 17 Superseded Latest is v17 →

lore
Share & tools
lore

Yi Yang

author
#0 lore raw

PATCH 1/1 openvswitch: add NSH support

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                | 126 ++++++++++++++++++++++++++++++
 include/uapi/linux/openvswitch.h |  33 ++++++++
 net/openvswitch/actions.c        | 165 +++++++++++++++++++++++++++++++++++++++
 net/openvswitch/flow.c           |  41 ++++++++++
 net/openvswitch/flow.h           |   1 +
 net/openvswitch/flow_netlink.c   |  54 ++++++++++++-
 7 files changed, 426 insertions(+), 1 deletion(-)
 create mode 100644 include/net/nsh.h
drivers/net/vxlan.c +7 -0
index dbca067..843714c 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>
@@ -1267,6 +1268,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;
@@ -1806,6 +1810,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 +126 -0

126 lines not on this page · raw message

include/uapi/linux/openvswitch.h +33 -0
index 156ee4c..b9c072c 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,                  /* struct ovs_key_nsh */
 
 #ifdef __KERNEL__
 	OVS_KEY_ATTR_TUNNEL_INFO,  /* struct ip_tunnel_info */
@@ -491,6 +492,15 @@ struct ovs_key_ct_tuple_ipv6 {
 	__u8   ipv6_proto;
 };
 
+struct ovs_key_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 np;
+	__u8 pad;
+	__be32 path_hdr;
+	__be32 c[4];
+};
+
 /**
  * enum ovs_flow_attr - attributes for %OVS_FLOW_* commands.
  * @OVS_FLOW_ATTR_KEY: Nested %OVS_KEY_ATTR_* attributes specifying the flow
@@ -769,6 +779,25 @@ struct ovs_action_push_eth {
 	struct ovs_key_ethernet addresses;
 };
 
+#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+/*
+ * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
+ * @flags: NSH header flags.
+ * @mdtype: NSH metadata type.
+ * @mdlen: Length of NSH metadata in bytes.
+ * @np: NSH next_protocol: Inner packet type.
+ * @path_hdr: NSH service path id and service index.
+ * @metadata: NSH metadata for MD type 1 or 2
+ */
+struct ovs_action_encap_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 mdlen;
+	__u8 np;
+	__be32 path_hdr;
+	__u8 metadata[OVS_ENCAP_NSH_MAX_MD_LEN];
+};
+
 /**
  * enum ovs_action_attr - Action types.
  *
@@ -806,6 +835,8 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_ENCAP_NSH: encap NSH action to push NSH header.
+ * @OVS_ACTION_ATTR_DECAP_NSH: decap NSH action to remove NSH header.
  *
  * 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 +866,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_ENCAP_NSH,    /* struct ovs_action_encap_nsh. */
+	OVS_ACTION_ATTR_DECAP_NSH,    /* No argument. */
 
 	__OVS_ACTION_ATTR_MAX,	      /* Nothing past this will be accepted
 				       * from userspace. */
net/openvswitch/actions.c +165 -0

195 lines not on this page · raw message

net/openvswitch/flow.c +41 -0

59 lines not on this page · raw message

net/openvswitch/flow.h +1 -0
index 1875bba..d2a0e56 100644
@@ -144,6 +144,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 +53 -1

117 lines not on this page · raw message

Signature · 1 line
2.5.5
#1 lore raw

include/uapi/linux/openvswitch.h struct ovs_key_ct_tuple_ipv6 { · line 501

Quoted 7 lines · Yi Yang
include/uapi/linux/openvswitch.h +7 -0
+struct ovs_key_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 np;
+	__u8 pad;
+	__be32 path_hdr;
+	__be32 c[4];

"c" is a very poor name. Please rename it to something that expresses what this field contains.

Also, this looks like MD type 1 only. How are those fields going to work with MD type 2? I don't think MD type 2 implementation is necessary in this patch but I'd like to know how this is going to work - it's uAPI and thus set in stone once this is merged. The uAPI needs to be designed with future use in mind.

Quoted 7 lines
include/uapi/linux/openvswitch.h +7 -0
+#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+/*
+ * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
+ * @flags: NSH header flags.
+ * @mdtype: NSH metadata type.
+ * @mdlen: Length of NSH metadata in bytes.
+ * @np: NSH next_protocol: Inner packet type.

include/uapi/linux/openvswitch.h struct ovs_action_push_eth { · line 798

Quoted 10 lines
include/uapi/linux/openvswitch.h +10 -0
+ * @path_hdr: NSH service path id and service index.
+ * @metadata: NSH metadata for MD type 1 or 2
+ */
+struct ovs_action_encap_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 mdlen;
+	__u8 np;
+	__be32 path_hdr;
+	__u8 metadata[OVS_ENCAP_NSH_MAX_MD_LEN];

This is wrong. The metadata size is set to a fixed size by this and cannot be ever extended, or at least not easily. Netlink has attributes for exactly these cases and that's what needs to be used here.

include/uapi/linux/openvswitch.h enum ovs_action_attr { · line 870

Quoted 6 lines
include/uapi/linux/openvswitch.h +2 -0
@@ -835,6 +866,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_ENCAP_NSH,    /* struct ovs_action_encap_nsh. */
+	OVS_ACTION_ATTR_DECAP_NSH,    /* No argument. */

Use "push" and "pop", not "encap" and "decap" to be consistent with the naming in the rest of the file. We use encap and decap for tunnel operations. This code does not use lwtunnels, thus push and pop is more appropriate.

Jiri

#2 lore raw

Hi, Jiri

Thank you for your comments.

__be32 c[4] is the name Ben Pfaff suggested, the original name is c1, c2, c3, c4, they are context data, so c seems ok, too :-)

OVS has merged it and has the same name, maybe the better way is adding comment /* Context data */ after it.

For MD type 2, struct ovs_key_nsh is very difficult to cover it, so far we don't know how to support MD type 2 better, Geneve defined 64 tun_metadata0-63 to handle this, those keys are parts of struct flow_tnl, the highest possibility is to reuse those keys.

So for future MD type 2, we will have two parts of keys, one is from struct ovs_key_nsh, another is from struct flow_tnl, this won't break the old uAPI.

"#define OVS_ENCAP_NSH_MAX_MD_LEN 16" is changed per Ben's comment from 256, Ben thinks 256 is too big but we only support MD type 1 now. We still have ways to extend it, for example:

struct ovs_action_encap_nsh * oaen = (struct ovs_action_encap_nsh *) malloc (sizeof(struct ovs_action_encap_nsh) + ANY_SIZE);

nl_msg_put_unspec(actions, OVS_ACTION_ATTR_ENCAP_NSH,

                          oaen, sizeof(struct ovs_action_encap_nsh) + ANY_SIZE);

In addition, we also need to consider, OVS userspace code must be consistent with here, so keeping it intact will be better, we have way to support dynamically extension when we add MD type 2 support.

About action name, unfortunately, userspace data plane has named them as encap_nsh & decap_nsh, Jan, what do you think about Jiri's suggestion?

But from my understanding, encap_* & decap_* are better because they corresponding to generic encap & decap actions, in addition, encap semantics are different from push, encap just pushed an empty header with default values, users must use set_field to set the content of the header.

Again, OVS userspace code must be consistent with here, so keeping it intact will be better because OVS userspace code was there.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jiri Benc
Sent: Tuesday, August 8, 2017 10:28 PM
To: Yang, Yi Y <[email protected]>
Cc: [email protected]; [email protected]; davem-fT/PcQaiUtIeIZ0/[email protected]
Subject: Re: [PATCH net-next] openvswitch: add NSH support

include/uapi/linux/openvswitch.h struct ovs_key_ct_tuple_ipv6 { · line 501

Quoted 7 lines · Yi Yang
include/uapi/linux/openvswitch.h +7 -0
+struct ovs_key_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 np;
+	__u8 pad;
+	__be32 path_hdr;
+	__be32 c[4];

"c" is a very poor name. Please rename it to something that expresses what this field contains.

Also, this looks like MD type 1 only. How are those fields going to work with MD type 2? I don't think MD type 2 implementation is necessary in this patch but I'd like to know how this is going to work - it's uAPI and thus set in stone once this is merged. The uAPI needs to be designed with future use in mind.

Quoted 6 lines
include/uapi/linux/openvswitch.h +6 -0
+#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+/*
+ * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
+ * @flags: NSH header flags.
+ * @mdtype: NSH metadata type.
+ * @mdlen: Length of NSH metadata in bytes.

include/uapi/linux/openvswitch.h struct ovs_action_push_eth { · line 798

Quoted 10 lines
include/uapi/linux/openvswitch.h +10 -0
+ * @np: NSH next_protocol: Inner packet type.
+ * @path_hdr: NSH service path id and service index.
+ * @metadata: NSH metadata for MD type 1 or 2  */ struct 
+ovs_action_encap_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 mdlen;
+	__u8 np;
+	__be32 path_hdr;
+	__u8 metadata[OVS_ENCAP_NSH_MAX_MD_LEN];

This is wrong. The metadata size is set to a fixed size by this and cannot be ever extended, or at least not easily. Netlink has attributes for exactly these cases and that's what needs to be used here.

include/uapi/linux/openvswitch.h enum ovs_action_attr { · line 870

Quoted 6 lines
include/uapi/linux/openvswitch.h +2 -0
@@ -835,6 +866,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_ENCAP_NSH,    /* struct ovs_action_encap_nsh. */
+	OVS_ACTION_ATTR_DECAP_NSH,    /* No argument. */

Use "push" and "pop", not "encap" and "decap" to be consistent with the naming in the rest of the file. We use encap and decap for tunnel operations. This code does not use lwtunnels, thus push and pop is more appropriate.

Jiri

A message that is not in the archive (sent off-list or not yet received): 79BBBFE6CB6C9B488C1A45ACD284F51961C391CA-0J0gbvR4kTggGBtAFL8yw7fspsVTdybXVpNB7YpNyf8@public.gmane.org

#4 lore raw

To be clear, the OVS implementation is a placeholder. It will get replaced by whatever netdev implements, and that's OK. I didn't focus on making it perfect because I knew that. Instead, I just made sure it was good enough for an internal OVS implementation that doesn't fix any ABI or API. OVS can even change the user-visible action names, as long as we do that soon (and encap/decap versus push/pop doesn't matter to me).

The considerations for netdev are different and more permanent.

Quoted 81 lines · Yi Y

Hi, Jiri

Thank you for your comments.

__be32 c[4] is the name Ben Pfaff suggested, the original name is c1, c2, c3, c4, they are context data, so c seems ok, too :-)

OVS has merged it and has the same name, maybe the better way is adding comment /* Context data */ after it.

For MD type 2, struct ovs_key_nsh is very difficult to cover it, so far we don't know how to support MD type 2 better, Geneve defined 64 tun_metadata0-63 to handle this, those keys are parts of struct flow_tnl, the highest possibility is to reuse those keys.

So for future MD type 2, we will have two parts of keys, one is from struct ovs_key_nsh, another is from struct flow_tnl, this won't break the old uAPI.

"#define OVS_ENCAP_NSH_MAX_MD_LEN 16" is changed per Ben's comment from 256, Ben thinks 256 is too big but we only support MD type 1 now. We still have ways to extend it, for example:

struct ovs_action_encap_nsh * oaen = (struct ovs_action_encap_nsh *) malloc (sizeof(struct ovs_action_encap_nsh) + ANY_SIZE);

nl_msg_put_unspec(actions, OVS_ACTION_ATTR_ENCAP_NSH,

                          oaen, sizeof(struct ovs_action_encap_nsh) + ANY_SIZE);

In addition, we also need to consider, OVS userspace code must be consistent with here, so keeping it intact will be better, we have way to support dynamically extension when we add MD type 2 support.

About action name, unfortunately, userspace data plane has named them as encap_nsh & decap_nsh, Jan, what do you think about Jiri's suggestion?

But from my understanding, encap_* & decap_* are better because they corresponding to generic encap & decap actions, in addition, encap semantics are different from push, encap just pushed an empty header with default values, users must use set_field to set the content of the header.

Again, OVS userspace code must be consistent with here, so keeping it intact will be better because OVS userspace code was there.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jiri Benc
Sent: Tuesday, August 8, 2017 10:28 PM
To: Yang, Yi Y <[email protected]>
Cc: [email protected]; [email protected]; davem-fT/PcQaiUtIeIZ0/[email protected]
Subject: Re: [PATCH net-next] openvswitch: add NSH support

include/uapi/linux/openvswitch.h struct ovs_key_ct_tuple_ipv6 { · line 501

Quoted 7 lines · Yi Yang
include/uapi/linux/openvswitch.h +7 -0
+struct ovs_key_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 np;
+	__u8 pad;
+	__be32 path_hdr;
+	__be32 c[4];

"c" is a very poor name. Please rename it to something that expresses what this field contains.

Also, this looks like MD type 1 only. How are those fields going to work with MD type 2? I don't think MD type 2 implementation is necessary in this patch but I'd like to know how this is going to work - it's uAPI and thus set in stone once this is merged. The uAPI needs to be designed with future use in mind.

Quoted 6 lines
include/uapi/linux/openvswitch.h +6 -0
+#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+/*
+ * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
+ * @flags: NSH header flags.
+ * @mdtype: NSH metadata type.
+ * @mdlen: Length of NSH metadata in bytes.

include/uapi/linux/openvswitch.h struct ovs_action_push_eth { · line 798

Quoted 10 lines
include/uapi/linux/openvswitch.h +10 -0
+ * @np: NSH next_protocol: Inner packet type.
+ * @path_hdr: NSH service path id and service index.
+ * @metadata: NSH metadata for MD type 1 or 2  */ struct 
+ovs_action_encap_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 mdlen;
+	__u8 np;
+	__be32 path_hdr;
+	__u8 metadata[OVS_ENCAP_NSH_MAX_MD_LEN];

This is wrong. The metadata size is set to a fixed size by this and cannot be ever extended, or at least not easily. Netlink has attributes for exactly these cases and that's what needs to be used here.

include/uapi/linux/openvswitch.h enum ovs_action_attr { · line 870

Quoted 6 lines
include/uapi/linux/openvswitch.h +2 -0
@@ -835,6 +866,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_ENCAP_NSH,    /* struct ovs_action_encap_nsh. */
+	OVS_ACTION_ATTR_DECAP_NSH,    /* No argument. */

Use "push" and "pop", not "encap" and "decap" to be consistent with the naming in the rest of the file. We use encap and decap for tunnel operations. This code does not use lwtunnels, thus push and pop is more appropriate.

Jiri
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Hi all,

In OVS 2.8 we support only fixed size NSH MD1 context data for matching and in set/copy_field actions. OVS parses an MD2 NSH header but does not make any TLV headers available to OF. The plan is to add support for matching/manipulating NSH MD2 TLVs through a new infrastructure of generic TLV match fields that can be dynamically mapped to specific protocol TLVs, similar to the way this is done for GENEVE tunnel metadata TLVs today. But this is work for an upcoming OVS release.

However, in encap() and decap() NSH actions we do support MD2 format already. The encap_nsh datapath action is agnostic of the MD format. Any MD2 TLV metadata are provided as encap properties in the OF encap() operation. They are translated by the ofproto layer and forwarded as opaque byte sequence in the encap_nsh datapath action.

Conversely, the decap_nsh() action pops any TLV metadata using the metadata length in the NSH header.

Consequently the datapath action OVS_ACTION_ATTR_ENCAP_NSH is already declared variable length:

odp_action_len(uint16_t type)

{
    switch ((enum ovs_action_attr) type) {
...
    case OVS_ACTION_ATTR_ENCAP_NSH: return ATTR_LEN_VARIABLE;
    case OVS_ACTION_ATTR_DECAP_NSH: return 0;

...
}

Unfortunately, that has only partially been reflected in the rest of the code. The action struct should have a variable length metadata[] member and the function odp_put_encap_nsh_action() should set the action nl_attr length dynamically.

I'll provide a patch to fix that shortly.

BTW: I have no objections to renaming these datapath actions to push_nsh and pop_nsh if that helps avoiding confusion with the existing encap attributes on the netlink interface. But we should do that quickly as it is user-visible and affects unit test cases.

BR, Jan

Quoted 114 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ben Pfaff
Sent: Wednesday, 09 August, 2017 04:42
To: Yang, Yi Y <[email protected]>
Cc: [email protected]; [email protected]; Jiri Benc <[email protected]>; davem-fT/PcQaiUtIeIZ0/[email protected]
Subject: Re: [ovs-dev] [PATCH net-next] openvswitch: add NSH support

To be clear, the OVS implementation is a placeholder. It will get replaced by whatever netdev implements, and that's OK. I didn't focus on making it perfect because I knew that. Instead, I just made sure it was good enough for an internal OVS implementation that doesn't fix any ABI or API. OVS can even change the user-visible action names, as long as we do that soon (and encap/decap versus push/pop doesn't matter to me).

The considerations for netdev are different and more permanent.

Quoted 9 lines · Yi Y

Hi, Jiri

Thank you for your comments.

__be32 c[4] is the name Ben Pfaff suggested, the original name is c1, c2, c3, c4, they are context data, so c seems ok, too :-)

OVS has merged it and has the same name, maybe the better way is adding comment /* Context data */ after it.

For MD type 2, struct ovs_key_nsh is very difficult to cover it, so far we don't know how to support MD type 2 better, Geneve defined 64

tun_metadata0-63 to handle this, those keys are parts of struct flow_tnl, the highest possibility is to reuse those keys.

Quoted 2 lines

So for future MD type 2, we will have two parts of keys, one is from struct ovs_key_nsh, another is from struct flow_tnl, this won't break

the old uAPI.

Quoted 2 lines

"#define OVS_ENCAP_NSH_MAX_MD_LEN 16" is changed per Ben's comment from 256, Ben thinks 256 is too big but we only support

MD type 1 now. We still have ways to extend it, for example:

Quoted 7 lines

struct ovs_action_encap_nsh * oaen = (struct ovs_action_encap_nsh *) malloc (sizeof(struct ovs_action_encap_nsh) + ANY_SIZE);

nl_msg_put_unspec(actions, OVS_ACTION_ATTR_ENCAP_NSH,

                          oaen, sizeof(struct ovs_action_encap_nsh) + ANY_SIZE);

In addition, we also need to consider, OVS userspace code must be consistent with here, so keeping it intact will be better, we have way

to support dynamically extension when we add MD type 2 support.

Quoted 2 lines

About action name, unfortunately, userspace data plane has named them as encap_nsh & decap_nsh, Jan, what do you think about Jiri's

suggestion?

Quoted 2 lines

But from my understanding, encap_* & decap_* are better because they corresponding to generic encap & decap actions, in addition,

encap semantics are different from push, encap just pushed an empty header with default values, users must use set_field to set the content of the header.

Quoted 22 lines

Again, OVS userspace code must be consistent with here, so keeping it intact will be better because OVS userspace code was there.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jiri Benc
Sent: Tuesday, August 8, 2017 10:28 PM
To: Yang, Yi Y <[email protected]>
Cc: [email protected]; [email protected]; davem-fT/PcQaiUtIeIZ0/[email protected]
Subject: Re: [PATCH net-next] openvswitch: add NSH support

include/uapi/linux/openvswitch.h struct ovs_key_ct_tuple_ipv6 { · line 501

Quoted 7 lines · Yi Yang
include/uapi/linux/openvswitch.h +7 -0
+struct ovs_key_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 np;
+	__u8 pad;
+	__be32 path_hdr;
+	__be32 c[4];

"c" is a very poor name. Please rename it to something that expresses what this field contains.

Quoted 1 line

Also, this looks like MD type 1 only. How are those fields going to work with MD type 2? I don't think MD type 2 implementation is

necessary in this patch but I'd like to know how this is going to work - it's uAPI and thus set in stone once this is merged. The uAPI needs to be designed with future use in mind.

Quoted 11 lines
Quoted 11 lines
include/uapi/linux/openvswitch.h +10 -0
+#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+/*
+ * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
+ * @flags: NSH header flags.
+ * @mdtype: NSH metadata type.
+ * @mdlen: Length of NSH metadata in bytes.
+ * @np: NSH next_protocol: Inner packet type.
+ * @path_hdr: NSH service path id and service index.
+ * @metadata: NSH metadata for MD type 1 or 2  */ struct
+ovs_action_encap_nsh {
Quoted 8 lines

include/uapi/linux/openvswitch.h struct ovs_action_push_eth { · line 798

Quoted 6 lines
include/uapi/linux/openvswitch.h +6 -0
+	__u8 flags;
+	__u8 mdtype;
+	__u8 mdlen;
+	__u8 np;
+	__be32 path_hdr;
+	__u8 metadata[OVS_ENCAP_NSH_MAX_MD_LEN];

This is wrong. The metadata size is set to a fixed size by this and cannot be ever extended, or at least not easily. Netlink has attributes

for exactly these cases and that's what needs to be used here.

Quoted 9 lines

include/uapi/linux/openvswitch.h enum ovs_action_attr { · line 870

Quoted 7 lines
include/uapi/linux/openvswitch.h +2 -0
@@ -835,6 +866,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_ENCAP_NSH,    /* struct ovs_action_encap_nsh. */
+	OVS_ACTION_ATTR_DECAP_NSH,    /* No argument. */

Use "push" and "pop", not "encap" and "decap" to be consistent with the naming in the rest of the file. We use encap and decap for

tunnel operations. This code does not use lwtunnels, thus push and pop is more appropriate.

Quoted 6 lines

Jiri
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

A message that is not in the archive (sent off-list or not yet received): CFF8EF42F1132E4CBE2BF0AB6C21C58D72735682-hqolJogE5njKJFWPz4pdheaU1rCVNFv4@public.gmane.org

#8 lore raw

Hi, Jan

I have worked out a patch, will send it quickly for Ben. In addition, I also will send out a patch to change encap_nsh &decap_nsh to push_nsh and pop_nsh. Per comments from all the people, we all agreed to do so :-)

datapath/linux/compat/include/linux/openvswitch.h +2 -2
index bc6c94b..4936c12 100644
@@ -793,7 +793,7 @@ struct ovs_action_push_eth {
        struct ovs_key_ethernet addresses;
 };
 
-#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+#define OVS_ENCAP_NSH_MAX_MD_LEN 248
 /*
  * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
  * @flags: NSH header flags.
@@ -809,7 +809,7 @@ struct ovs_action_encap_nsh {
     uint8_t mdlen;
     uint8_t np;
     __be32 path_hdr;
-    uint8_t metadata[OVS_ENCAP_NSH_MAX_MD_LEN];
+    uint8_t metadata[];
 };
 
 /**
lib/odp-util.c +58 -43

184 lines not on this page · raw message

-----Original Message-----
From: Jan Scheurich [mailto:jan.scheurich-IzeFyvvaP7pWk0Htik3J/[email protected]]
Sent: Wednesday, August 9, 2017 4:32 PM
To: Ben Pfaff <[email protected]>; Yang, Yi Y <[email protected]>
Cc: [email protected]; [email protected]; Jiri Benc <[email protected]>; davem-fT/PcQaiUtIeIZ0/[email protected]; Zoltán Balogh <zoltan.balogh-IzeFyvvaP7pWk0Htik3J/[email protected]>
Subject: RE: [ovs-dev] [PATCH net-next] openvswitch: add NSH support

Hi all,

In OVS 2.8 we support only fixed size NSH MD1 context data for matching and in set/copy_field actions. OVS parses an MD2 NSH header but does not make any TLV headers available to OF. The plan is to add support for matching/manipulating NSH MD2 TLVs through a new infrastructure of generic TLV match fields that can be dynamically mapped to specific protocol TLVs, similar to the way this is done for GENEVE tunnel metadata TLVs today. But this is work for an upcoming OVS release.

However, in encap() and decap() NSH actions we do support MD2 format already. The encap_nsh datapath action is agnostic of the MD format. Any MD2 TLV metadata are provided as encap properties in the OF encap() operation. They are translated by the ofproto layer and forwarded as opaque byte sequence in the encap_nsh datapath action.

Conversely, the decap_nsh() action pops any TLV metadata using the metadata length in the NSH header.

Consequently the datapath action OVS_ACTION_ATTR_ENCAP_NSH is already declared variable length:

odp_action_len(uint16_t type)
{
switch ((enum ovs_action_attr) type) { ...
case OVS_ACTION_ATTR_ENCAP_NSH: return ATTR_LEN_VARIABLE; case OVS_ACTION_ATTR_DECAP_NSH: return 0; ...
}

Unfortunately, that has only partially been reflected in the rest of the code. The action struct should have a variable length metadata[] member and the function odp_put_encap_nsh_action() should set the action nl_attr length dynamically.

I'll provide a patch to fix that shortly.

BTW: I have no objections to renaming these datapath actions to push_nsh and pop_nsh if that helps avoiding confusion with the existing encap attributes on the netlink interface. But we should do that quickly as it is user-visible and affects unit test cases.

BR, Jan

Quoted 132 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ben Pfaff
Sent: Wednesday, 09 August, 2017 04:42
To: Yang, Yi Y <[email protected]>
Cc: [email protected]; [email protected]; Jiri Benc <[email protected]>; davem-fT/PcQaiUtIeIZ0/[email protected]
Subject: Re: [ovs-dev] [PATCH net-next] openvswitch: add NSH support

To be clear, the OVS implementation is a placeholder. It will get replaced by whatever netdev implements, and that's OK. I didn't focus on making it perfect because I knew that. Instead, I just made sure it was good enough for an internal OVS implementation that doesn't fix any ABI or API. OVS can even change the user-visible action names, as long as we do that soon (and encap/decap versus push/pop doesn't matter to me).

The considerations for netdev are different and more permanent.

Quoted 11 lines · Yi Y

Hi, Jiri

Thank you for your comments.

__be32 c[4] is the name Ben Pfaff suggested, the original name is c1, c2, c3, c4, they are context data, so c seems ok, too :-)

OVS has merged it and has the same name, maybe the better way is adding comment /* Context data */ after it.

For MD type 2, struct ovs_key_nsh is very difficult to cover it, so far we don't know how to support MD type 2 better, Geneve defined 64

tun_metadata0-63 to handle this, those keys are parts of struct flow_tnl, the highest possibility is to reuse those keys.

Quoted 4 lines

So for future MD type 2, we will have two parts of keys, one is from struct ovs_key_nsh, another is from struct flow_tnl, this won't break

the old uAPI.

Quoted 3 lines

"#define OVS_ENCAP_NSH_MAX_MD_LEN 16" is changed per Ben's comment from 256, Ben thinks 256 is too big but we only support

MD type 1 now. We still have ways to extend it, for example:

Quoted 11 lines

struct ovs_action_encap_nsh * oaen = (struct ovs_action_encap_nsh *) malloc (sizeof(struct ovs_action_encap_nsh) + ANY_SIZE);

nl_msg_put_unspec(actions, OVS_ACTION_ATTR_ENCAP_NSH,
oaen, sizeof(struct ovs_action_encap_nsh)
+ ANY_SIZE);

In addition, we also need to consider, OVS userspace code must be consistent with here, so keeping it intact will be better, we have way

to support dynamically extension when we add MD type 2 support.

Quoted 3 lines

About action name, unfortunately, userspace data plane has named them as encap_nsh & decap_nsh, Jan, what do you think about Jiri's

suggestion?

Quoted 3 lines

But from my understanding, encap_* & decap_* are better because they corresponding to generic encap & decap actions, in addition,

encap semantics are different from push, encap just pushed an empty header with default values, users must use set_field to set the content of the header.

Quoted 23 lines

Again, OVS userspace code must be consistent with here, so keeping it intact will be better because OVS userspace code was there.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jiri Benc
Sent: Tuesday, August 8, 2017 10:28 PM
To: Yang, Yi Y <[email protected]>
Cc: [email protected]; [email protected]; davem-fT/PcQaiUtIeIZ0/[email protected]
Subject: Re: [PATCH net-next] openvswitch: add NSH support

Review

Quoted 7 lines · Yi Yang
(quoted diff) +7 -0
+struct ovs_key_nsh {
+	__u8 flags;
+	__u8 mdtype;
+	__u8 np;
+	__u8 pad;
+	__be32 path_hdr;
+	__be32 c[4];

"c" is a very poor name. Please rename it to something that expresses what this field contains.

Quoted 2 lines

Also, this looks like MD type 1 only. How are those fields going to work with MD type 2? I don't think MD type 2 implementation is

necessary in this patch but I'd like to know how this is going to work
- it's uAPI and thus set in stone once this is merged. The uAPI needs to be designed with future use in mind.

Quoted 13 lines
Quoted 13 lines
(quoted diff) +12 -0
+#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+/*
+ * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
+ * @flags: NSH header flags.
+ * @mdtype: NSH metadata type.
+ * @mdlen: Length of NSH metadata in bytes.
+ * @np: NSH next_protocol: Inner packet type.
+ * @path_hdr: NSH service path id and service index.
+ * @metadata: NSH metadata for MD type 1 or 2  */ struct 
+ovs_action_encap_nsh {
+	__u8 flags;
+	__u8 mdtype;
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	__u8 mdlen;
+	__u8 np;
+	__be32 path_hdr;
+	__u8 metadata[OVS_ENCAP_NSH_MAX_MD_LEN];

This is wrong. The metadata size is set to a fixed size by this and cannot be ever extended, or at least not easily. Netlink has attributes

for exactly these cases and that's what needs to be used here.

Quoted 10 lines

Review enum ovs_action_attr { · line 870

Quoted 7 lines
(quoted diff) +2 -0
@@ -835,6 +866,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_ENCAP_NSH,    /* struct ovs_action_encap_nsh. */
+	OVS_ACTION_ATTR_DECAP_NSH,    /* No argument. */

Use "push" and "pop", not "encap" and "decap" to be consistent with the naming in the rest of the file. We use encap and decap for

tunnel operations. This code does not use lwtunnels, thus push and pop is more appropriate.

Quoted 6 lines

Jiri
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

#9 lore raw
Quoted 18 lines · Yi Y

Hi, Jan

I have worked out a patch, will send it quickly for Ben. In addition, I also will send out a patch to change encap_nsh &decap_nsh to push_nsh and pop_nsh. Per comments from all the people, we all agreed to do so :-)

datapath/linux/compat/include/linux/openvswitch.h +1 -1
index bc6c94b..4936c12 100644
@@ -793,7 +793,7 @@ struct ovs_action_push_eth {
        struct ovs_key_ethernet addresses;
 };
 
-#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+#define OVS_ENCAP_NSH_MAX_MD_LEN 248
 /*
  * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
  * @flags: NSH header flags.

datapath/linux/compat/include/linux/openvswitch.h struct ovs_action_encap_nsh { · line 813

Quoted 6 lines
datapath/linux/compat/include/linux/openvswitch.h +1 -1
@@ -809,7 +809,7 @@ struct ovs_action_encap_nsh {
     uint8_t mdlen;
     uint8_t np;
     __be32 path_hdr;
-    uint8_t metadata[OVS_ENCAP_NSH_MAX_MD_LEN];
+    uint8_t metadata[];
 };

This brings the overall format of ovs_action_encap_nsh to:

struct ovs_action_encap_nsh {
    uint8_t flags;
    uint8_t mdtype;
    uint8_t mdlen;
    uint8_t np;
    __be32 path_hdr;
    uint8_t metadata[];
};

This is an unusual format for a Netlink attribute. More commonly, one would put variable-length data into an attribute of its own, which allows that data to be handled using the regular Netlink means. Then the mdlen and metadata members could be removed, since they would be part of the additional attribute, and one might expect the mdtype member to be removed as well since each type of metadata would be in a different attribute type.

So, a format closer to what I expect to see in Netlink is something like this:

/**
* enum ovs_nsh_attr - Metadata attributes for %OVS_ACTION_ENCAP_NSH action. *
* @OVS_NSH_ATTR_MD1: Contains 16-byte NSH type-1 metadata.
* @OVS_NSH_ATTR_MD2: Contains 0- to 255-byte variable-length NSH type-2
* metadata. */

enum ovs_nsh_attr {
    OVS_NSH_ATTR_MD1,
    OVS_NSH_ATTR_MD2
};

/*
* struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH *
* @path_hdr: NSH service path id and service index.
* @flags: NSH header flags.
* @np: NSH next_protocol: Inner packet type.
*
* Followed by either %OVS_NSH_ATTR_MD1 or %OVS_NSH_ATTR_MD2 attribute. */

struct ovs_action_encap_nsh {
    __be32 path_hdr;
    uint8_t flags;
    uint8_t np;
};
author
#10 lore raw

Ben, do you mean we bring two new attributes (OVS_NSH_ATTR_MD1 and OVS_NSH_ATTR_MD2) and embed one of them in OVS_ACTION_ATTR_ENCAP_NSH? Anyway we need to use a struct or something else to transfer those metadata between functions, how do you think we can handle this without metadata in struct ovs_action_encap_nsh? I mean how we handle the arguments for function encap_nsh.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ben Pfaff
Sent: Thursday, August 10, 2017 2:09 AM
To: Yang, Yi Y <[email protected]>
Cc: Jan Scheurich <[email protected]>; [email protected]; [email protected]; Jiri Benc <[email protected]>; [email protected]; Zoltán Balogh <[email protected]>
Subject: Re: [ovs-dev] [PATCH net-next] openvswitch: add NSH support

Quoted 21 lines · Yi Y

Hi, Jan

I have worked out a patch, will send it quickly for Ben. In addition, I also will send out a patch to change encap_nsh &decap_nsh to push_nsh and pop_nsh. Per comments from all the people, we all agreed to do so :-)

datapath/linux/compat/include/linux/openvswitch.h +1 -1
index bc6c94b..4936c12 100644
@@ -793,7 +793,7 @@ struct ovs_action_push_eth {
        struct ovs_key_ethernet addresses;  };
 
-#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+#define OVS_ENCAP_NSH_MAX_MD_LEN 248
 /*
  * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
  * @flags: NSH header flags.

datapath/linux/compat/include/linux/openvswitch.h struct ovs_action_encap_nsh { · line 813

Quoted 6 lines
datapath/linux/compat/include/linux/openvswitch.h +1 -1
@@ -809,7 +809,7 @@ struct ovs_action_encap_nsh {
     uint8_t mdlen;
     uint8_t np;
     __be32 path_hdr;
-    uint8_t metadata[OVS_ENCAP_NSH_MAX_MD_LEN];
+    uint8_t metadata[];
 };

This brings the overall format of ovs_action_encap_nsh to:

struct ovs_action_encap_nsh {
    uint8_t flags;
    uint8_t mdtype;
    uint8_t mdlen;
    uint8_t np;
    __be32 path_hdr;
    uint8_t metadata[];
};

This is an unusual format for a Netlink attribute. More commonly, one would put variable-length data into an attribute of its own, which allows that data to be handled using the regular Netlink means. Then the mdlen and metadata members could be removed, since they would be part of the additional attribute, and one might expect the mdtype member to be removed as well since each type of metadata would be in a different attribute type.

So, a format closer to what I expect to see in Netlink is something like this:

/**
* enum ovs_nsh_attr - Metadata attributes for %OVS_ACTION_ENCAP_NSH action. *
* @OVS_NSH_ATTR_MD1: Contains 16-byte NSH type-1 metadata.
* @OVS_NSH_ATTR_MD2: Contains 0- to 255-byte variable-length NSH type-2
* metadata. */

enum ovs_nsh_attr {
    OVS_NSH_ATTR_MD1,
    OVS_NSH_ATTR_MD2
};

/*
* struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH *
* @path_hdr: NSH service path id and service index.
* @flags: NSH header flags.
* @np: NSH next_protocol: Inner packet type.
*
* Followed by either %OVS_NSH_ATTR_MD1 or %OVS_NSH_ATTR_MD2 attribute. */

struct ovs_action_encap_nsh {
    __be32 path_hdr;
    uint8_t flags;
    uint8_t np;
};

A message that is not in the archive (sent off-list or not yet received): 79BBBFE6CB6C9B488C1A45ACD284F51961C3C14A-0J0gbvR4kTggGBtAFL8yw7fspsVTdybXVpNB7YpNyf8@public.gmane.org

#12 lore raw
Quoted 2 lines · Yi Y

Ben, do you mean we bring two new attributes (OVS_NSH_ATTR_MD1 and OVS_NSH_ATTR_MD2) and embed one of them in OVS_ACTION_ATTR_ENCAP_NSH?

Yes.

Quoted 4 lines

Anyway we need to use a struct or something else to transfer those metadata between functions, how do you think we can handle this without metadata in struct ovs_action_encap_nsh? I mean how we handle the arguments for function encap_nsh.

I guess that a pointer to the embedded nlattr with type OVS_NSH_ATTR_MD1 or OVS_NSH_ATTR2 should work OK.

Keep in mind that I'm not a kernel-side maintainer of any kind. I am only passing along what I've perceived to be common Netlink protocol design patterns.

Quoted 77 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ben Pfaff
Sent: Thursday, August 10, 2017 2:09 AM
To: Yang, Yi Y <[email protected]>
Cc: Jan Scheurich <jan.scheurich-IzeFyvvaP7pWk0Htik3J/[email protected]>; [email protected]; [email protected]; Jiri Benc <[email protected]>; davem-fT/PcQaiUtIeIZ0/[email protected]; Zoltán Balogh <zoltan.balogh-IzeFyvvaP7pWk0Htik3J/[email protected]>
Subject: Re: [ovs-dev] [PATCH net-next] openvswitch: add NSH support

Quoted 21 lines · Yi Y

Hi, Jan

I have worked out a patch, will send it quickly for Ben. In addition, I also will send out a patch to change encap_nsh &decap_nsh to push_nsh and pop_nsh. Per comments from all the people, we all agreed to do so :-)

datapath/linux/compat/include/linux/openvswitch.h +1 -1
index bc6c94b..4936c12 100644
@@ -793,7 +793,7 @@ struct ovs_action_push_eth {
        struct ovs_key_ethernet addresses;  };
 
-#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+#define OVS_ENCAP_NSH_MAX_MD_LEN 248
 /*
  * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
  * @flags: NSH header flags.

datapath/linux/compat/include/linux/openvswitch.h struct ovs_action_encap_nsh { · line 813

Quoted 6 lines
datapath/linux/compat/include/linux/openvswitch.h +1 -1
@@ -809,7 +809,7 @@ struct ovs_action_encap_nsh {
     uint8_t mdlen;
     uint8_t np;
     __be32 path_hdr;
-    uint8_t metadata[OVS_ENCAP_NSH_MAX_MD_LEN];
+    uint8_t metadata[];
 };

This brings the overall format of ovs_action_encap_nsh to:

struct ovs_action_encap_nsh {
    uint8_t flags;
    uint8_t mdtype;
    uint8_t mdlen;
    uint8_t np;
    __be32 path_hdr;
    uint8_t metadata[];
};

This is an unusual format for a Netlink attribute. More commonly, one would put variable-length data into an attribute of its own, which allows that data to be handled using the regular Netlink means. Then the mdlen and metadata members could be removed, since they would be part of the additional attribute, and one might expect the mdtype member to be removed as well since each type of metadata would be in a different attribute type.

So, a format closer to what I expect to see in Netlink is something like this:

/**
* enum ovs_nsh_attr - Metadata attributes for %OVS_ACTION_ENCAP_NSH action. *
* @OVS_NSH_ATTR_MD1: Contains 16-byte NSH type-1 metadata.
* @OVS_NSH_ATTR_MD2: Contains 0- to 255-byte variable-length NSH type-2
* metadata. */

enum ovs_nsh_attr {
    OVS_NSH_ATTR_MD1,
    OVS_NSH_ATTR_MD2
};

/*
* struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH *
* @path_hdr: NSH service path id and service index.
* @flags: NSH header flags.
* @np: NSH next_protocol: Inner packet type.
*
* Followed by either %OVS_NSH_ATTR_MD1 or %OVS_NSH_ATTR_MD2 attribute. */

struct ovs_action_encap_nsh {
    __be32 path_hdr;
    uint8_t flags;
    uint8_t np;
};
author
#13 lore raw

struct ovs_action_encap_nsh is the only one way we transfer all the data for encap_nsh, netlink allows variable attribute, so I don't think we break netlink convention or abuse this variable feature.

Even if we bring nested attributes to handle this, OVS_ACTION_ATTR_ENCAP_NSH is still length-variable, OVS_NSH_ATTR_MD2 is also length-variable (it can be from 0 to 248), so I don't think such way can avoid the issue you're addressing.

The result will be worse, it will make many difficulties when we transfer all the data for encap_nsh between OVS' components.

-----Original Message-----
From: Ben Pfaff [mailto:[email protected]]
Sent: Thursday, August 10, 2017 4:54 AM
To: Yang, Yi Y <[email protected]>
Cc: Jan Scheurich <[email protected]>; [email protected]; [email protected]; Jiri Benc <[email protected]>; [email protected]; Zoltán Balogh <[email protected]>
Subject: Re: [ovs-dev] [PATCH net-next] openvswitch: add NSH support

Quoted 2 lines · Yi Y

Ben, do you mean we bring two new attributes (OVS_NSH_ATTR_MD1 and OVS_NSH_ATTR_MD2) and embed one of them in OVS_ACTION_ATTR_ENCAP_NSH?

Yes.

Quoted 4 lines

Anyway we need to use a struct or something else to transfer those metadata between functions, how do you think we can handle this without metadata in struct ovs_action_encap_nsh? I mean how we handle the arguments for function encap_nsh.

I guess that a pointer to the embedded nlattr with type OVS_NSH_ATTR_MD1 or OVS_NSH_ATTR2 should work OK.

Keep in mind that I'm not a kernel-side maintainer of any kind. I am only passing along what I've perceived to be common Netlink protocol design patterns.

Quoted 82 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ben Pfaff
Sent: Thursday, August 10, 2017 2:09 AM
To: Yang, Yi Y <[email protected]>
Cc: Jan Scheurich <[email protected]>; [email protected]; [email protected]; Jiri Benc <[email protected]>; [email protected]; Zoltán Balogh <[email protected]>
Subject: Re: [ovs-dev] [PATCH net-next] openvswitch: add NSH support

Quoted 21 lines · Yi Y

Hi, Jan

I have worked out a patch, will send it quickly for Ben. In addition, I also will send out a patch to change encap_nsh &decap_nsh to push_nsh and pop_nsh. Per comments from all the people, we all agreed to do so :-)

datapath/linux/compat/include/linux/openvswitch.h +1 -1
index bc6c94b..4936c12 100644
@@ -793,7 +793,7 @@ struct ovs_action_push_eth {
        struct ovs_key_ethernet addresses;  };
 
-#define OVS_ENCAP_NSH_MAX_MD_LEN 16
+#define OVS_ENCAP_NSH_MAX_MD_LEN 248
 /*
  * struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH
  * @flags: NSH header flags.

datapath/linux/compat/include/linux/openvswitch.h struct ovs_action_encap_nsh { · line 813

Quoted 6 lines
datapath/linux/compat/include/linux/openvswitch.h +1 -1
@@ -809,7 +809,7 @@ struct ovs_action_encap_nsh {
     uint8_t mdlen;
     uint8_t np;
     __be32 path_hdr;
-    uint8_t metadata[OVS_ENCAP_NSH_MAX_MD_LEN];
+    uint8_t metadata[];
 };

This brings the overall format of ovs_action_encap_nsh to:

struct ovs_action_encap_nsh {
    uint8_t flags;
    uint8_t mdtype;
    uint8_t mdlen;
    uint8_t np;
    __be32 path_hdr;
    uint8_t metadata[];
};

This is an unusual format for a Netlink attribute. More commonly, one would put variable-length data into an attribute of its own, which allows that data to be handled using the regular Netlink means. Then the mdlen and metadata members could be removed, since they would be part of the additional attribute, and one might expect the mdtype member to be removed as well since each type of metadata would be in a different attribute type.

So, a format closer to what I expect to see in Netlink is something like
this:

/**
* enum ovs_nsh_attr - Metadata attributes for %OVS_ACTION_ENCAP_NSH action. *
* @OVS_NSH_ATTR_MD1: Contains 16-byte NSH type-1 metadata.
* @OVS_NSH_ATTR_MD2: Contains 0- to 255-byte variable-length NSH
type-2
* metadata. */

enum ovs_nsh_attr {
    OVS_NSH_ATTR_MD1,
    OVS_NSH_ATTR_MD2
};

/*
* struct ovs_action_encap_nsh - %OVS_ACTION_ATTR_ENCAP_NSH *
* @path_hdr: NSH service path id and service index.
* @flags: NSH header flags.
* @np: NSH next_protocol: Inner packet type.
*
* Followed by either %OVS_NSH_ATTR_MD1 or %OVS_NSH_ATTR_MD2 attribute. */

struct ovs_action_encap_nsh {
    __be32 path_hdr;
    uint8_t flags;
    uint8_t np;
};