NSH(Network Service Header) implementation
Subsystems (3)
PATCH 1/1 NSH(Network Service Header) implementation
IETF defined NSH(Network Service Header) for Service Function Chaining, this is an IETF draft
https://tools.ietf.org/html/draft-ietf-sfc-nsh-05
It will be a IETF standard shortly, this patch implemented NSH for Open vSwitch.
--- drivers/net/vxlan.c | 7 ++ include/net/nsh.h | 117 +++++++++++++++++++++++ include/uapi/linux/openvswitch.h | 32 +++++++ net/openvswitch/actions.c | 68 +++++++++++++ net/openvswitch/flow.c | 45 ++++++++- net/openvswitch/flow.h | 15 +++ net/openvswitch/flow_netlink.c | 202 ++++++++++++++++++++++++++++++++++++++- net/openvswitch/vport-netdev.c | 3 +- net/openvswitch/vport-vxlan.c | 15 +++ 9 files changed, 501 insertions(+), 3 deletions(-) create mode 100644 include/net/nsh.h
drivers/net/vxlan.c +7 -0
@@ -42,6 +42,7 @@#include <net/netns/generic.h> #include <net/vxlan.h> #include <net/protocol.h> +#include <net/nsh.h> #if IS_ENABLED (CONFIG_IPV6 )#include <net/ipv6.h>
@@ -1225,6 +1226,9 @@ static bool vxlan_parse_gpe_hdr(struct vxlanhdr *unparsed,case VXLAN_GPE_NP_ETHERNET : *protocol =htons (ETH_P_TEB );break ; +case VXLAN_GPE_NP_NSH : + *protocol =htons (ETH_P_NSH ); +break ;default :return false; }
@@ -1760,6 +1764,9 @@ static int vxlan_build_gpe_hdr(struct vxlanhdr *vxh, u32 vxflags,case htons (ETH_P_TEB ): gpe->next_protocol =VXLAN_GPE_NP_ETHERNET ;return 0 ; +case htons (ETH_P_NSH ): + gpe->next_protocol =VXLAN_GPE_NP_NSH ; +return 0 ; }return -EPFNOSUPPORT ; }
include/net/nsh.h new file +117 -0
117 lines not on this page · raw message
include/uapi/linux/openvswitch.h +32 -0
@@ -263,6 +263,7 @@ enum ovs_vport_attr {enum {OVS_VXLAN_EXT_UNSPEC ,OVS_VXLAN_EXT_GBP ,/* Flag or __u32 */ +OVS_VXLAN_EXT_GPE ,/* Flag, Generic Protocol Extension */ __OVS_VXLAN_EXT_MAX, };
@@ -317,6 +318,7 @@ enum ovs_key_attr {OVS_KEY_ATTR_ND ,/* struct ovs_key_nd */ OVS_KEY_ATTR_SKB_MARK ,/* u32 skb mark */ OVS_KEY_ATTR_TUNNEL ,/* Nested set of ovs_tunnel attributes */ +OVS_KEY_ATTR_NSH ,/* Nested set of ovs_nsh attributes */ OVS_KEY_ATTR_SCTP ,/* struct ovs_key_sctp */ OVS_KEY_ATTR_TCP_FLAGS ,/* be16 TCP flags. */ OVS_KEY_ATTR_DP_HASH, /* u32 hash value. Value 0 indicates the hash
@@ -359,6 +361,21 @@ enum ovs_tunnel_key_attr {#define OVS_TUNNEL_KEY_ATTR_MAX (__OVS_TUNNEL_KEY_ATTR_MAX - 1) +enum ovs_nsh_key_attr { +OVS_NSH_KEY_ATTR_FLAGS ,/* u8 NSH header flags */ +OVS_NSH_KEY_ATTR_MD_TYPE ,/* u8 Metadata Type */ +OVS_NSH_KEY_ATTR_NEXT_PROTO ,/* u8 Next Protocol */ +OVS_NSH_KEY_ATTR_NSI ,/* u8 Service Index */ +OVS_NSH_KEY_ATTR_NSP ,/* be32 Service Path ID */ +OVS_NSH_KEY_ATTR_NSHC1 ,/* be32 NSH Context Header 1 */ +OVS_NSH_KEY_ATTR_NSHC2 ,/* be32 NSH Context Header 2 */ +OVS_NSH_KEY_ATTR_NSHC3 ,/* be32 NSH Context Header 3 */ +OVS_NSH_KEY_ATTR_NSHC4 ,/* be32 NSH Context Header 4 */ + __OVS_NSH_KEY_ATTR_MAX +}; + +#define OVS_NSH_KEY_ATTR_MAX (__OVS_NSH_KEY_ATTR_MAX - 1) +/** * enum ovs_frag_type - IPv4 and IPv6 fragment type * @OVS_FRAG_TYPE_NONE: Packet is not a fragment.
@@ -609,6 +626,17 @@ struct ovs_action_push_vlan {__be16 vlan_tci;/* 802.1Q TCI (VLAN ID and priority). */ }; +/** +* struct ovs_action_push_nsh - %OVS_ACTION_ATTR_PUSH_NSH action argument. +* @len: length of NSH header. Differs since different metadata type. +* @header: RAW value for the NSH header. +*/ +#define NSH_HEADER_LEN_MAX 256 +struct ovs_action_push_nsh { +uint16_t len; +uint8_t header[NSH_HEADER_LEN_MAX ];/* NSH header */ +}; +/* Data path hash algorithm for computing Datapath hash. * * The algorithm type only specifies the fields in a flow
@@ -730,6 +758,8 @@ enum ovs_nat_attr {* is no MPLS label stack, as determined by ethertype, no action is taken. * @OVS_ACTION_ATTR_CT: Track the connection. Populate the conntrack-related * entries in the flow key. +* @OVS_ACTION_ATTR_PUSH_NSH: Push a Network Service Header into the packets. +* @OVS_ACTION_ATTR_POP_NSH: Strip the Network Service Header from packets. * * 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
@@ -756,6 +786,8 @@ enum ovs_action_attr {* The data must be zero for the unmasked * bits. */ OVS_ACTION_ATTR_CT ,/* Nested OVS_CT_ATTR_* . */ +OVS_ACTION_ATTR_PUSH_NSH ,/* struct ovs_action_push_nsh. */ +OVS_ACTION_ATTR_POP_NSH ,/* No argument. */ __OVS_ACTION_ATTR_MAX, /* Nothing past this will be accepted* from userspace. */
net/openvswitch/actions.c +68 -0
92 lines not on this page · raw message
net/openvswitch/flow.c +44 -1
75 lines not on this page · raw message
net/openvswitch/flow.h +15 -0
@@ -54,10 +54,25 @@ struct ovs_tunnel_info { (offsetof(struct sw_flow_key , recirc_id) + \ FIELD_SIZEOF(struct sw_flow_key, recirc_id)) +/* Network Service Header, MD Type I only for the moment. + */ +struct ovs_nsh_key { +u8 flags; +u8 md_type;/* NSH metadata type */ +u8 next_proto;/* NSH next protocol */ +u8 nsi;/* NSH index */ +u32 nsp;/* NSH path id */ +u32 nshc1;/* NSH context C1-C4 */ +u32 nshc2; +u32 nshc3; +u32 nshc4; +} __packed__aligned(4) ;/* Minimize padding. */ +struct sw_flow_key {u8 tun_opts[IP_TUNNEL_OPTS_MAX ];u8 tun_opts_len;struct ip_tunnel_key tun_key;/* Encapsulating tunnel key. */ +struct ovs_nsh_key nsh;/* network service header */ struct {u32 priority;/* Packet QoS priority. */ u32 skb_mark;/* SKB mark. */
net/openvswitch/flow_netlink.c +201 -1
267 lines not on this page · raw message
net/openvswitch/vport-netdev.c +2 -1
@@ -97,7 +97,8 @@ struct vport *ovs_netdev_link(struct vport *vport, const char *name) }if (vport->dev->flags &IFF_LOOPBACK || - vport->dev->type !=ARPHRD_ETHER || + (vport->dev->type !=ARPHRD_ETHER && + vport->dev->type !=ARPHRD_NONE ) ||ovs_is_internal_dev (vport->dev)) { err = -EINVAL ; goto error_put;
net/openvswitch/vport-vxlan.c +15 -0
@@ -52,6 +52,18 @@ static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)return -EMSGSIZE ;nla_nest_end (skb, exts); + }else if (vxlan->flags &VXLAN_F_GPE ) { +struct nlattr *exts; + + exts =nla_nest_start (skb,OVS_TUNNEL_ATTR_EXTENSION ); +if (!exts) +return -EMSGSIZE ; + +if (vxlan->flags &VXLAN_F_GPE && +nla_put_flag (skb,OVS_VXLAN_EXT_GPE )) +return -EMSGSIZE ; + +nla_nest_end (skb, exts); }return 0 ;
@@ -59,6 +71,7 @@ static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)static const struct nla_policy exts_policy[OVS_VXLAN_EXT_MAX +1 ] = { [OVS_VXLAN_EXT_GBP ] = { .type =NLA_FLAG , }, + [OVS_VXLAN_EXT_GPE ] = { .type =NLA_FLAG , }, }; static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr,
@@ -76,6 +89,8 @@ static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr,if (exts[OVS_VXLAN_EXT_GBP ]) conf->flags |=VXLAN_F_GBP ; +else if (exts[OVS_VXLAN_EXT_GPE ]) + conf->flags |=VXLAN_F_GPE ;return 0 ; }
Signature · 6 lines
1.9.3 _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
Quoted 23 lines · Yi Yang
IETF defined NSH(Network Service Header) for Service Function Chaining, this is an IETF draft
https://tools.ietf.org/html/draft-ietf-sfc-nsh-05
It will be a IETF standard shortly, this patch implemented NSH for Open vSwitch.
Signed-off-by Johnson Li <[email protected]>Signed-off-by Yi Yang <[email protected]>--- drivers/net/vxlan.c | 7 ++ include/net/nsh.h | 117 +++++++++++++++++++++++ include/uapi/linux/openvswitch.h | 32 +++++++ net/openvswitch/actions.c | 68 +++++++++++++ net/openvswitch/flow.c | 45 ++++++++- net/openvswitch/flow.h | 15 +++ net/openvswitch/flow_netlink.c | 202 ++++++++++++++++++++++++++++++++++++++- net/openvswitch/vport-netdev.c | 3 +- net/openvswitch/vport-vxlan.c | 15 +++ 9 files changed, 501 insertions(+), 3 deletions(-) create mode 100644 include/net/nsh.h
...
...
Quoted 24 lines
net/openvswitch/actions.c +2
-0@@ -29,6 +29,7 @@#include <linux/in6.h> #include <linux/if_arp.h> #include <linux/if_vlan.h> +#include <linux/if_ether.h> #include <net/dst.h> #include <net/ip.h> @@ -38,6 +39,7 @@#include <net/dsfield.h> #include <net/mpls.h> #include <net/sctp/checksum.h> +#include <net/nsh.h> #include "datapath.h" #include "flow.h" @@ -259,6 +261,64 @@ static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key, ntohs(vlan->vlan_tci) & ~VLAN_TAG_PRESENT); }
...
...
Quoted 15 lines
net/openvswitch/actions.c +15
-0+ +static int push_nsh (struct sk_buff *skb,struct sw_flow_key *key, +const struct ovs_action_push_nsh *nsh) +{ +if (nsh->len >0 && nsh->len <=256 ) { +struct nsh_hdr *nsh_hdr =NULL ; + +if (skb_cow_head (skb, nsh->len) <0 ) +return -ENOMEM ; + +skb_push (skb, nsh->len); + nsh_hdr = (struct nsh_hdr *)(skb->data); +memcpy (nsh_hdr, nsh->header, nsh->len); + +if (!skb->inner_protocol)
net/openvswitch/actions.c static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key, · line 320
Quoted 10 lines
net/openvswitch/actions.c +10
-0+skb_set_inner_protocol (skb, skb->protocol); + + skb->protocol =htons (ETH_P_NSH );/* 0x894F */ + key->eth.type =htons (ETH_P_NSH ); + }else { +return -EINVAL ; + } + +return 0 ; +}
Networking stack or OVS can not handle arbitrary skb-protocol. For example what happens if OVS has push vlan action or it sends this nsh packet to net device which can not handle nsh packet? Even networking stack can not parse such packet for handling offloads in software.
...
Quoted 32 lines
net/openvswitch/vport-vxlan.c +13
-0@@ -52,6 +52,18 @@ static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)return -EMSGSIZE ;nla_nest_end (skb, exts); + }else if (vxlan->flags &VXLAN_F_GPE ) { +struct nlattr *exts; + + exts =nla_nest_start (skb,OVS_TUNNEL_ATTR_EXTENSION ); +if (!exts) +return -EMSGSIZE ; + +if (vxlan->flags &VXLAN_F_GPE && +nla_put_flag (skb,OVS_VXLAN_EXT_GPE )) +return -EMSGSIZE ; + +nla_nest_end (skb, exts); }return 0 ;@@ -59,6 +71,7 @@ static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)static const struct nla_policy exts_policy[OVS_VXLAN_EXT_MAX +1 ] = { [OVS_VXLAN_EXT_GBP ] = { .type =NLA_FLAG , }, + [OVS_VXLAN_EXT_GPE ] = { .type =NLA_FLAG , }, }; static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr,
net/openvswitch/vport-vxlan.c static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr, · line 94
Quoted 6 lines
net/openvswitch/vport-vxlan.c +2
-0@@ -76,6 +89,8 @@ static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr,if (exts[OVS_VXLAN_EXT_GBP ]) conf->flags |=VXLAN_F_GBP ; +else if (exts[OVS_VXLAN_EXT_GPE ]) + conf->flags |=VXLAN_F_GPE ;
This is compatibility code, no need to add new features to this code. Now we should be directly using net devices.
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev
Quoted 76 lines · pravin shelar
Quoted 23 lines · Yi Yang
IETF defined NSH(Network Service Header) for Service Function Chaining, this is an IETF draft
https://tools.ietf.org/html/draft-ietf-sfc-nsh-05
It will be a IETF standard shortly, this patch implemented NSH for Open vSwitch.
Signed-off-by Johnson Li <[email protected]>Signed-off-by Yi Yang <[email protected]>--- drivers/net/vxlan.c | 7 ++ include/net/nsh.h | 117 +++++++++++++++++++++++ include/uapi/linux/openvswitch.h | 32 +++++++ net/openvswitch/actions.c | 68 +++++++++++++ net/openvswitch/flow.c | 45 ++++++++- net/openvswitch/flow.h | 15 +++ net/openvswitch/flow_netlink.c | 202 ++++++++++++++++++++++++++++++++++++++- net/openvswitch/vport-netdev.c | 3 +- net/openvswitch/vport-vxlan.c | 15 +++ 9 files changed, 501 insertions(+), 3 deletions(-) create mode 100644 include/net/nsh.h...
...Quoted 24 lines
net/openvswitch/actions.c +2
-0@@ -29,6 +29,7 @@#include <linux/in6.h> #include <linux/if_arp.h> #include <linux/if_vlan.h> +#include <linux/if_ether.h> #include <net/dst.h> #include <net/ip.h> @@ -38,6 +39,7 @@#include <net/dsfield.h> #include <net/mpls.h> #include <net/sctp/checksum.h> +#include <net/nsh.h> #include "datapath.h" #include "flow.h" @@ -259,6 +261,64 @@ static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key, ntohs(vlan->vlan_tci) & ~VLAN_TAG_PRESENT); }...
...Quoted 23 lines
net/openvswitch/actions.c +23
-0+ +static int push_nsh (struct sk_buff *skb,struct sw_flow_key *key, +const struct ovs_action_push_nsh *nsh) +{ +if (nsh->len >0 && nsh->len <=256 ) { +struct nsh_hdr *nsh_hdr =NULL ; + +if (skb_cow_head (skb, nsh->len) <0 ) +return -ENOMEM ; + +skb_push (skb, nsh->len); + nsh_hdr = (struct nsh_hdr *)(skb->data); +memcpy (nsh_hdr, nsh->header, nsh->len); + +if (!skb->inner_protocol) +skb_set_inner_protocol (skb, skb->protocol); + + skb->protocol =htons (ETH_P_NSH );/* 0x894F */ + key->eth.type =htons (ETH_P_NSH ); + }else { +return -EINVAL ; + } +
Quoted 9 lines
net/openvswitch/actions.c
Quoted 2 lines
net/openvswitch/actions.c +2
-0+return 0 ; +}Networking stack or OVS can not handle arbitrary skb-protocol. For example what happens if OVS has push vlan action or it sends this nsh packet to net device which can not handle nsh packet? Even networking stack can not parse such packet for handling offloads in software.
...
ovs nsh patch set have been sent out, they can handle nsh header. This patch just implemented NSH push and pop actions, we do need some cdoe to do some sanity check for the case you mentioned, but I think it is out of scope of thi patch.
Quoted 33 lines
Quoted 33 lines
net/openvswitch/vport-vxlan.c +13
-0@@ -52,6 +52,18 @@ static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)return -EMSGSIZE ;nla_nest_end (skb, exts); + }else if (vxlan->flags &VXLAN_F_GPE ) { +struct nlattr *exts; + + exts =nla_nest_start (skb,OVS_TUNNEL_ATTR_EXTENSION ); +if (!exts) +return -EMSGSIZE ; + +if (vxlan->flags &VXLAN_F_GPE && +nla_put_flag (skb,OVS_VXLAN_EXT_GPE )) +return -EMSGSIZE ; + +nla_nest_end (skb, exts); }return 0 ;@@ -59,6 +71,7 @@ static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)static const struct nla_policy exts_policy[OVS_VXLAN_EXT_MAX +1 ] = { [OVS_VXLAN_EXT_GBP ] = { .type =NLA_FLAG , }, + [OVS_VXLAN_EXT_GPE ] = { .type =NLA_FLAG , }, }; static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr,@@ -76,6 +89,8 @@ static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr,
Quoted 7 lines
net/openvswitch/vport-vxlan.c static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr, · line 94
Quoted 5 lines
net/openvswitch/vport-vxlan.c +2
-0if (exts[OVS_VXLAN_EXT_GBP ]) conf->flags |=VXLAN_F_GBP ; +else if (exts[OVS_VXLAN_EXT_GPE ]) + conf->flags |=VXLAN_F_GPE ;This is compatibility code, no need to add new features to this code. Now we should be directly using net devices.
Will use net device after those patches are merged into net-next, It seems current net device implementation in net-next doesn't include it, do you mean this one "http://article.gmane.org/gmane.network.openvswitch.devel/64799"?
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev
Quoted 2 lines · Yi
Will use net device after those patches are merged into net-next, It seems current net device implementation in net-next doesn't include it,
The current kernel should have everything that's needed for VXLAN-GPE support.
Quoted 2 lines
do you mean this one "http://article.gmane.org/gmane.network.openvswitch.devel/64799"?
This patchset is absolutely needed for ovs to support new VXLAN features, including VXLAN-GPE.
Jiri
Quoted 7 lines · Jiri Benc
Quoted 2 lines · Yi
Will use net device after those patches are merged into net-next, It seems current net device implementation in net-next doesn't include it,
The current kernel should have everything that's needed for VXLAN-GPE support.
Quoted 7 lines
Quoted 2 lines
do you mean this one "http://article.gmane.org/gmane.network.openvswitch.devel/64799"?
This patchset is absolutely needed for ovs to support new VXLAN features, including VXLAN-GPE.
Jiri
Got it, I'll rework it after Simon and Thadeu Lima de Souza Cascardo's patches are merged.
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev