net: openvswitch: IPv6: Add IPv6 extension header support
Subsystems (3)
PATCH 1/1 net: openvswitch: IPv6: Add IPv6 extension header support
IPv6 extension headers carry optional internet layer information and are placed between the fixed header and the upper-layer protocol header.
This change adds a new OpenFlow field OFPXMT_OFB_IPV6_EXTHDR and packets can be filtered using ipv6_ext flag.
Tested-at: https://github.com/TomCodeLV/ovs/actions/runs/504185214
--- include/uapi/linux/openvswitch.h | 1 + net/openvswitch/flow.c | 141 +++++++++++++++++++++++++++++++ net/openvswitch/flow.h | 14 +++ net/openvswitch/flow_netlink.c | 5 +- 4 files changed, 160 insertions(+), 1 deletion(-)
include/uapi/linux/openvswitch.h +1 -0
@@ -420,6 +420,7 @@ struct ovs_key_ipv6 {__u8 ipv6_tclass;__u8 ipv6_hlimit;__u8 ipv6_frag;/* One of OVS_FRAG_TYPE_*. */ +__u16 ipv6_exthdr; };struct ovs_key_tcp {
net/openvswitch/flow.c +141 -0
153 lines not on this page · raw message
net/openvswitch/flow.h +14 -0
@@ -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 +4 -1
@@ -367,7 +367,7 @@ size_t ovs_key_attr_size(void) +nla_total_size (4 )/* OVS_KEY_ATTR_VLAN */ +nla_total_size (0 )/* OVS_KEY_ATTR_ENCAP */ +nla_total_size (2 )/* OVS_KEY_ATTR_ETHERTYPE */ - +nla_total_size (40 )/* OVS_KEY_ATTR_IPV6 */ + +nla_total_size (42 )/* OVS_KEY_ATTR_IPV6 */ +nla_total_size (2 )/* OVS_KEY_ATTR_ICMPV6 */ +nla_total_size (28 );/* OVS_KEY_ATTR_ND */ }
@@ -1585,6 +1585,8 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match, ipv6_key->ipv6_hlimit, is_mask);SW_FLOW_KEY_PUT (match, ip.frag, ipv6_key->ipv6_frag, is_mask); +SW_FLOW_KEY_PUT (match, ipv6.exthdrs, + ipv6_key->ipv6_exthdr, is_mask); SW_FLOW_KEY_MEMCPY(match, ipv6.addr.src, ipv6_key->ipv6_src, sizeof(match->key->ipv6.addr.src),
@@ -2113,6 +2115,7 @@ 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; + ipv6_key->ipv6_exthdr = 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;
base-commit: 5d869070569a23aa909c6e7e9d010fc438a492ef
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerQuoted 6 lines · On Thu, 6 May 2021 11:30:53 -0700 Toms Atteka wrote:
+/**
+ * Parses packet and sets IPv6 extension header flags.
+ *+ * skb buffer where extension header data starts in packet + * nh ipv6 header + * ext_hdrs flags are stored here
This is not a valid kdoc comment. Please fix.
Quoted 20 lines
+ *
OFPIEH12_UNREPis set if more than one of a given IPv6 extension header
+ * is unexpectedly encountered. (Two destination options headers may be
+ * expected and would not cause this bit to be set.)
+ *
+ *OFPIEH12_UNSEQis set if IPv6 extension headers were not in the order
+ * preferred (but not required) by RFC 2460:
+ *
+ * When more than one extension header is used in the same packet, it is
+ * recommended that those headers appear in the following order:+ * IPv6 header + * Hop-by-Hop Options header + * Destination Options header + * Routing header + * Fragment header + * Authentication header + * Encapsulating Security Payload header + * Destination Options header + * upper-layer header+ */
+static voidget_ipv6_ext_hdrs(struct sk_buff *skb, struct ipv6hdr *nh, u16 *ext_hdrs)