Skip to contentSkip to conversation

net: openvswitch: IPv6: Add IPv6 extension header support

PATCH Superseded Toms Atteka 3 participants 6 messages Sep 21, 2021 – Sep 28, 2021

Subsystems (3)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 net: openvswitch: IPv6: Add IPv6 extension header support

This change adds a new OpenFlow field OFPXMT_OFB_IPV6_EXTHDR and packets can be filtered using ipv6_ext flag.

---
 include/uapi/linux/openvswitch.h |  12 +++
 net/openvswitch/flow.c           | 140 +++++++++++++++++++++++++++++++
 net/openvswitch/flow.h           |  14 ++++
 net/openvswitch/flow_netlink.c   |  24 +++++-
 4 files changed, 189 insertions(+), 1 deletion(-)
include/uapi/linux/openvswitch.h +12 -0
index a87b44cd5590..dc6eb5f6399f 100644
@@ -346,6 +346,13 @@ enum ovs_key_attr {
 #ifdef __KERNEL__
 	OVS_KEY_ATTR_TUNNEL_INFO,  /* struct ip_tunnel_info */
 #endif
+
+#ifndef __KERNEL__
+	PADDING,  /* Padding so kernel and non kernel field count would match */
+#endif
+
+	OVS_KEY_ATTR_IPV6_EXTHDRS,  /* struct ovs_key_ipv6_exthdr */
+
 	__OVS_KEY_ATTR_MAX
 };
 
@@ -421,6 +428,11 @@ struct ovs_key_ipv6 {
 	__u8   ipv6_frag;	/* One of OVS_FRAG_TYPE_*. */
 };
 
+/* separate structure to support backward compatibility with older user space */
+struct ovs_key_ipv6_exthdrs {
+	__u16  hdrs;
+};
+
 struct ovs_key_tcp {
 	__be16 tcp_src;
 	__be16 tcp_dst;
net/openvswitch/flow.c +140 -0

152 lines not on this page · raw message

net/openvswitch/flow.h +14 -0
index 758a8c77f736..073ab73ffeaa 100644
@@ -32,6 +32,19 @@ enum sw_flow_mac_proto {
 #define SW_FLOW_KEY_INVALID	0x80
 #define MPLS_LABEL_DEPTH       3
 
+/* Bit definitions for IPv6 Extension Header pseudo-field. */
+enum ofp12_ipv6exthdr_flags {
+	OFPIEH12_NONEXT = 1 << 0,   /* "No next header" encountered. */
+	OFPIEH12_ESP    = 1 << 1,   /* Encrypted Sec Payload header present. */
+	OFPIEH12_AUTH   = 1 << 2,   /* Authentication header present. */
+	OFPIEH12_DEST   = 1 << 3,   /* 1 or 2 dest headers present. */
+	OFPIEH12_FRAG   = 1 << 4,   /* Fragment header present. */
+	OFPIEH12_ROUTER = 1 << 5,   /* Router header present. */
+	OFPIEH12_HOP    = 1 << 6,   /* Hop-by-hop header present. */
+	OFPIEH12_UNREP  = 1 << 7,   /* Unexpected repeats encountered. */
+	OFPIEH12_UNSEQ  = 1 << 8    /* Unexpected sequencing encountered. */
+};
+
 /* Store options at the end of the array if they are less than the
  * maximum size. This allows us to get the benefits of variable length
  * matching for small options.
@@ -121,6 +134,7 @@ struct sw_flow_key {
 				struct in6_addr dst;	/* IPv6 destination address. */
 			} addr;
 			__be32 label;			/* IPv6 flow label. */
+			u16 exthdrs;	/* IPv6 extension header flags */
 			union {
 				struct {
 					struct in6_addr src;
net/openvswitch/flow_netlink.c +23 -1
index 65c2e3458ff5..2fbf324fcfff 100644
@@ -367,7 +367,8 @@ size_t ovs_key_attr_size(void)
 		+ nla_total_size(2)   /* OVS_KEY_ATTR_ETHERTYPE */
 		+ nla_total_size(40)  /* OVS_KEY_ATTR_IPV6 */
 		+ nla_total_size(2)   /* OVS_KEY_ATTR_ICMPV6 */
-		+ nla_total_size(28); /* OVS_KEY_ATTR_ND */
+		+ nla_total_size(28)  /* OVS_KEY_ATTR_ND */
+		+ nla_total_size(2);  /* OVS_KEY_ATTR_IPV6_EXTHDRS */
 }
 
 static const struct ovs_len_tbl ovs_vxlan_ext_key_lens[OVS_VXLAN_EXT_MAX + 1] = {
@@ -435,6 +436,8 @@ static const struct ovs_len_tbl ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
 		.len = sizeof(struct ovs_key_ct_tuple_ipv6) },
 	[OVS_KEY_ATTR_NSH]       = { .len = OVS_ATTR_NESTED,
 				     .next = ovs_nsh_key_attr_lens, },
+	[OVS_KEY_ATTR_IPV6_EXTHDRS] = {
+		.len = sizeof(struct ovs_key_ipv6_exthdrs) },
 };
 
 static bool check_attr_len(unsigned int attr_len, unsigned int expected_len)
@@ -1595,6 +1598,17 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
 		attrs &= ~(1 << OVS_KEY_ATTR_IPV6);
 	}
 
+	if (attrs & (1ULL << OVS_KEY_ATTR_IPV6_EXTHDRS)) {
+		const struct ovs_key_ipv6_exthdrs *ipv6_exthdrs_key;
+
+		ipv6_exthdrs_key = nla_data(a[OVS_KEY_ATTR_IPV6_EXTHDRS]);
+
+		SW_FLOW_KEY_PUT(match, ipv6.exthdrs,
+				ipv6_exthdrs_key->hdrs, is_mask);
+
+		attrs &= ~(1ULL << OVS_KEY_ATTR_IPV6_EXTHDRS);
+	}
+
 	if (attrs & (1 << OVS_KEY_ATTR_ARP)) {
 		const struct ovs_key_arp *arp_key;
 
@@ -2097,6 +2111,7 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
 		ipv4_key->ipv4_frag = output->ip.frag;
 	} else if (swkey->eth.type == htons(ETH_P_IPV6)) {
 		struct ovs_key_ipv6 *ipv6_key;
+		struct ovs_key_ipv6_exthdrs *ipv6_exthdrs_key;
 
 		nla = nla_reserve(skb, OVS_KEY_ATTR_IPV6, sizeof(*ipv6_key));
 		if (!nla)
@@ -2111,6 +2126,13 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
 		ipv6_key->ipv6_tclass = output->ip.tos;
 		ipv6_key->ipv6_hlimit = output->ip.ttl;
 		ipv6_key->ipv6_frag = output->ip.frag;
+
+		nla = nla_reserve(skb, OVS_KEY_ATTR_IPV6_EXTHDRS,
+				  sizeof(*ipv6_exthdrs_key));
+		if (!nla)
+			goto nla_put_failure;
+		ipv6_exthdrs_key = nla_data(nla);
+		ipv6_exthdrs_key->hdrs = output->ipv6.exthdrs;
 	} else if (swkey->eth.type == htons(ETH_P_NSH)) {
 		if (nsh_key_to_nlattr(&output->nsh, is_mask, skb))
 			goto nla_put_failure;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 4 lines · On Mon, 20 Sep 2021 11:20:38 -0700 Toms Atteka wrote:

This change adds a new OpenFlow field OFPXMT_OFB_IPV6_EXTHDR and packets can be filtered using ipv6_ext flag.

Please make sure to check the files you touch with

./scripts/kernel-doc -none

You're adding kdoc warnings by using the /** comments which are in fact not kdoc-formatted. Please fix and repost.

#2 lore raw
In reply to Toms Atteka

Le 20/09/2021 à 20:20, Toms Atteka a écrit :

Quoted 16 lines

This change adds a new OpenFlow field OFPXMT_OFB_IPV6_EXTHDR and packets can be filtered using ipv6_ext flag.

---
 include/uapi/linux/openvswitch.h |  12 +++
 net/openvswitch/flow.c           | 140 +++++++++++++++++++++++++++++++
 net/openvswitch/flow.h           |  14 ++++
 net/openvswitch/flow_netlink.c   |  24 +++++-
 4 files changed, 189 insertions(+), 1 deletion(-)
include/uapi/linux/openvswitch.h +0 -0
index a87b44cd5590..dc6eb5f6399f 100644

include/uapi/linux/openvswitch.h enum ovs_key_attr { · line 354

Quoted 9 lines
include/uapi/linux/openvswitch.h +6 -0
@@ -346,6 +346,13 @@ enum ovs_key_attr {
 #ifdef __KERNEL__
 	OVS_KEY_ATTR_TUNNEL_INFO,  /* struct ip_tunnel_info */
 #endif
+
+#ifndef __KERNEL__
+	PADDING,  /* Padding so kernel and non kernel field count would match */
+#endif
+
+	OVS_KEY_ATTR_IPV6_EXTHDRS,  /* struct ovs_key_ipv6_exthdr */

Naive question, why not moving OVS_KEY_ATTR_IPV6_EXTHDRS above OVS_KEY_ATTR_TUNNEL_INFO?

Regards,
Nicolas

author
#3 lore raw

To use this code there is a part of code in the userspace. We want to keep compatibility when we only update userspace part code or only kernel part code. This means we should have same values for constants and we can only add new ones at the end of list.

Best,
Tom

Quoted 34 lines · Nicolas Dichtel
Quoted 16 lines · Toms Atteka

This change adds a new OpenFlow field OFPXMT_OFB_IPV6_EXTHDR and packets can be filtered using ipv6_ext flag.

---
 include/uapi/linux/openvswitch.h |  12 +++
 net/openvswitch/flow.c           | 140 +++++++++++++++++++++++++++++++
 net/openvswitch/flow.h           |  14 ++++
 net/openvswitch/flow_netlink.c   |  24 +++++-
 4 files changed, 189 insertions(+), 1 deletion(-)
include/uapi/linux/openvswitch.h +0 -0
index a87b44cd5590..dc6eb5f6399f 100644

include/uapi/linux/openvswitch.h enum ovs_key_attr { · line 354

Quoted 9 lines
include/uapi/linux/openvswitch.h +6 -0
@@ -346,6 +346,13 @@ enum ovs_key_attr {
 #ifdef __KERNEL__
      OVS_KEY_ATTR_TUNNEL_INFO,  /* struct ip_tunnel_info */
 #endif
+
+#ifndef __KERNEL__
+     PADDING,  /* Padding so kernel and non kernel field count would match */
+#endif
+
+     OVS_KEY_ATTR_IPV6_EXTHDRS,  /* struct ovs_key_ipv6_exthdr */

Naive question, why not moving OVS_KEY_ATTR_IPV6_EXTHDRS above OVS_KEY_ATTR_TUNNEL_INFO?

Regards,
Nicolas

#4 lore raw

Le 27/09/2021 à 21:12, Cpp Code a écrit :

Quoted 4 lines

To use this code there is a part of code in the userspace. We want to keep compatibility when we only update userspace part code or only kernel part code. This means we should have same values for constants and we can only add new ones at the end of list.

All attributes after OVS_KEY_ATTR_CT_STATE (ie 7 attributes) were added before OVS_KEY_ATTR_TUNNEL_INFO.
Why is it not possible anymore?

Regards,
Nicolas

Quoted 40 lines

Best,
Tom

Quoted 34 lines · Nicolas Dichtel
Quoted 16 lines · Toms Atteka

This change adds a new OpenFlow field OFPXMT_OFB_IPV6_EXTHDR and packets can be filtered using ipv6_ext flag.

---
 include/uapi/linux/openvswitch.h |  12 +++
 net/openvswitch/flow.c           | 140 +++++++++++++++++++++++++++++++
 net/openvswitch/flow.h           |  14 ++++
 net/openvswitch/flow_netlink.c   |  24 +++++-
 4 files changed, 189 insertions(+), 1 deletion(-)
include/uapi/linux/openvswitch.h +0 -0
index a87b44cd5590..dc6eb5f6399f 100644

include/uapi/linux/openvswitch.h enum ovs_key_attr { · line 354

Quoted 9 lines
include/uapi/linux/openvswitch.h +6 -0
@@ -346,6 +346,13 @@ enum ovs_key_attr {
 #ifdef __KERNEL__
      OVS_KEY_ATTR_TUNNEL_INFO,  /* struct ip_tunnel_info */
 #endif
+
+#ifndef __KERNEL__
+     PADDING,  /* Padding so kernel and non kernel field count would match */
+#endif
+
+     OVS_KEY_ATTR_IPV6_EXTHDRS,  /* struct ovs_key_ipv6_exthdr */

Naive question, why not moving OVS_KEY_ATTR_IPV6_EXTHDRS above OVS_KEY_ATTR_TUNNEL_INFO?

Regards,
Nicolas

author
#5 lore raw
Quoted 6 lines · Nicolas Dichtel
Quoted 4 lines · Cpp Code

To use this code there is a part of code in the userspace. We want to keep compatibility when we only update userspace part code or only kernel part code. This means we should have same values for constants and we can only add new ones at the end of list.

Quoted 48 lines

All attributes after OVS_KEY_ATTR_CT_STATE (ie 7 attributes) were added before OVS_KEY_ATTR_TUNNEL_INFO.
Why is it not possible anymore?

Regards,
Nicolas

Quoted 40 lines

Best,
Tom

Quoted 34 lines · Nicolas Dichtel
Quoted 16 lines · Toms Atteka

This change adds a new OpenFlow field OFPXMT_OFB_IPV6_EXTHDR and packets can be filtered using ipv6_ext flag.

---
 include/uapi/linux/openvswitch.h |  12 +++
 net/openvswitch/flow.c           | 140 +++++++++++++++++++++++++++++++
 net/openvswitch/flow.h           |  14 ++++
 net/openvswitch/flow_netlink.c   |  24 +++++-
 4 files changed, 189 insertions(+), 1 deletion(-)
include/uapi/linux/openvswitch.h +0 -0
index a87b44cd5590..dc6eb5f6399f 100644

include/uapi/linux/openvswitch.h enum ovs_key_attr { · line 354

Quoted 9 lines
include/uapi/linux/openvswitch.h +6 -0
@@ -346,6 +346,13 @@ enum ovs_key_attr {
 #ifdef __KERNEL__
      OVS_KEY_ATTR_TUNNEL_INFO,  /* struct ip_tunnel_info */
 #endif
+
+#ifndef __KERNEL__
+     PADDING,  /* Padding so kernel and non kernel field count would match */
+#endif
+
+     OVS_KEY_ATTR_IPV6_EXTHDRS,  /* struct ovs_key_ipv6_exthdr */

Naive question, why not moving OVS_KEY_ATTR_IPV6_EXTHDRS above OVS_KEY_ATTR_TUNNEL_INFO?

Regards,
Nicolas

These 3 commits does not support compatibility for scenarios when only kernel gets updated. I assume at that point this requirement wasn't required.

Best,
Tom