openvswitch: enable NSH support
Subsystems (3)
PATCH v9 1/1 openvswitch: enable NSH support
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 | 112 ++++++++++++++ net/openvswitch/flow.c | 51 ++++++ net/openvswitch/flow.h | 11 ++ net/openvswitch/flow_netlink.c | 324 ++++++++++++++++++++++++++++++++++++++- net/openvswitch/flow_netlink.h | 5 + 9 files changed, 588 insertions(+), 1 deletion(-)
include/net/nsh.h +3 -0
@@ -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 *src_nsh_hdr); +int skb_pop_nsh (struct sk_buff *skb); +#endif /* __NET_NSH_H */
include/uapi/linux/openvswitch.h +29 -0
@@ -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
@@ -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 +112 -0
142 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 +11 -0
@@ -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,15 @@ struct vlan_head { (offsetof(struct sw_flow_key , recirc_id) + \ FIELD_SIZEOF(struct sw_flow_key, recirc_id)) +struct ovs_key_nsh { +u8 flags; +u8 ttl; +u8 mdtype; +u8 np; +__be32 path_hdr; +__be32 context[NSH_MD1_CONTEXT_SIZE ]; +}; +struct sw_flow_key {u8 tun_opts[IP_TUNNEL_OPTS_MAX ];u8 tun_opts_len;
@@ -144,6 +154,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 +323 -1
416 lines not on this page · raw message
net/openvswitch/flow_netlink.h +5 -0
@@ -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 *src_nsh_hdr, +size_t size); +#endif /* flow_netlink.h */
Signature · 1 line
2.5.5
net/nsh/nsh.c line 43
Quoted 4 lines · Yi Yang
net/nsh/nsh.c +4
-0+ skb->protocol =htons (ETH_P_NSH ); +skb_reset_mac_header (skb); +skb_reset_mac_len (skb); +skb_reset_network_header (skb);
The last two lines are swapped. Network header needs to be reset before mac_len.
net/nsh/nsh.c line 53
Quoted 10 lines
net/nsh/nsh.c +10
-0+ +return 0 ; +} +EXPORT_SYMBOL_GPL (skb_push_nsh); + +int skb_pop_nsh (struct sk_buff *skb) +{ +struct nshhdr *nsh_hdr = (struct nshhdr *)(skb->data); +size_t length; +u16 inner_proto;
__be16 inner_proto.
net/openvswitch/actions.c static int push_eth(struct sk_buff *skb, struct sw_flow_key *key, · line 393
Quoted 10 lines
net/openvswitch/actions.c +10
-0+static int push_nsh (struct sk_buff *skb,struct sw_flow_key *key, +const struct nshhdr *src_nsh_hdr) +{ +int err; + + err =skb_push_nsh (skb, src_nsh_hdr); +if (err) +return err; + + key->eth.type =htons (ETH_P_NSH );
I wonder why you have this assignment here. The key is invalidated, thus nothing should rely on key->eth.type. However, looking at the code and ovs_fragment in particular, I'm not sure that's the case. Could you please explain why it is needed? And why the reverse of it is not needed in pop_nsh?
Quoted 6 lines
net/openvswitch/actions.c +6
-0+ +/* safe right before invalidate_flow_key */ + key->mac_proto =MAC_PROTO_NONE ; +invalidate_flow_key (key); +return 0 ; +}
[...]
Quoted 8 lines
net/openvswitch/actions.c +8
-0+static int set_nsh (struct sk_buff *skb,struct sw_flow_key *flow_key, +const struct nlattr *a) +{ +struct nshhdr *nsh_hdr; +int err; +u8 flags; +u8 ttl; +int i;
net/openvswitch/actions.c static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key, · line 662
Quoted 10 lines
net/openvswitch/actions.c +10
-0+ +struct ovs_key_nsh key; +struct ovs_key_nsh mask; + + err =nsh_key_from_nlattr (a, &key, &mask); +if (err) +return err; + + err =skb_ensure_writable (skb,skb_network_offset (skb) + +sizeof (struct nshhdr ));
Whitespace nit: the sizeof should be aligned to skb_network_offset.
net/openvswitch/actions.c static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key, · line 666
Quoted 4 lines
net/openvswitch/actions.c +4
-0+if (unlikely (err)) +return err; + + nsh_hdr = (struct nshhdr *)skb_network_header (skb);
Please use the nsh_hdr function (I'm sure I already requested that in the previous review?). It means renaming the nsh_hdr variable.
net/openvswitch/actions.c static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, · line 1318
Quoted 13 lines
net/openvswitch/actions.c +9
-0@@ -1210,6 +1307,21 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,case OVS_ACTION_ATTR_POP_ETH : err =pop_eth (skb, key);break ; + +case OVS_ACTION_ATTR_PUSH_NSH : { +u8 buffer[NSH_HDR_MAX_LEN ]; +struct nshhdr *nsh_hdr = (struct nshhdr *)buffer; +const struct nshhdr *src_nsh_hdr = nsh_hdr; + +nsh_hdr_from_nlattr (nla_data (a), nsh_hdr, +NSH_HDR_MAX_LEN ); + err =push_nsh (skb, key, src_nsh_hdr);
Is the src_nsh_hdr variable really necessary? Cannot be nsh_hdr passed directly to push_nsh, relying on automatic retyping to const?
By the way, nsh_hdr is a poor name for a variable, it clashes with the nsh_hdr function. For clarity, please rename the variables in the whole patch to something else.
net/openvswitch/flow.c static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key, · line 505
Quoted 12 lines
net/openvswitch/flow.c +12
-0+static int parse_nsh (struct sk_buff *skb,struct sw_flow_key *key) +{ +struct nshhdr *nsh_hdr; +unsigned int nh_ofs =skb_network_offset (skb); +u8 version, length; +int err; + + err =check_header (skb, nh_ofs +NSH_BASE_HDR_LEN ); +if (unlikely (err)) +return err; + + nsh_hdr = (struct nshhdr *)skb_network_header (skb);
Again, rename the variable and use the nsh_hdr function.
net/openvswitch/flow.c static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key, · line 516
Quoted 11 lines
net/openvswitch/flow.c +11
-0+ version =nsh_get_ver (nsh_hdr); + length =nsh_hdr_len (nsh_hdr); + +if (version !=0 ) +return -EINVAL ; + + err =check_header (skb, nh_ofs + length); +if (unlikely (err)) +return err; + + nsh_hdr = (struct nshhdr *)skb_network_header (skb);
Ditto.
net/openvswitch/flow.h struct vlan_head { · line 77
Quoted 8 lines
net/openvswitch/flow.h +8
-0+struct ovs_key_nsh { +u8 flags; +u8 ttl; +u8 mdtype; +u8 np; +__be32 path_hdr; +__be32 context[NSH_MD1_CONTEXT_SIZE ]; +};
This should be:
struct ovs_key_nsh {
struct ovs_nsh_key_base base;
__be32 context[NSH_MD1_CONTEXT_SIZE];
};to capture the real dependency. Implicitly depending on ovs_key_nsh starting with the same fields as ovs_nsh_key_base will only lead to bugs in the future.
Quoted 8 lines
net/openvswitch/flow_netlink.c +8
-0+int nsh_hdr_from_nlattr (const struct nlattr *attr, +struct nshhdr *nsh,size_t size) +{ +struct nlattr *a; +int rem; +u8 flags =0 ; +u8 ttl =0 ; +int mdlen =0 ;
net/openvswitch/flow_netlink.c static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 1228
Quoted 10 lines
net/openvswitch/flow_netlink.c +10
-0+ +/* validate_nsh has check this, so we needn't do duplicate check here +*/ +nla_for_each_nested (a, attr, rem) { +int type =nla_type (a); + +switch (type) { +case OVS_NSH_KEY_ATTR_BASE : { +const struct ovs_nsh_key_base *base = + (struct ovs_nsh_key_base *)nla_data (a);
It's not necessary to retype void * explicitly. Just assign it.
net/openvswitch/flow_netlink.c static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 1238
Quoted 10 lines
net/openvswitch/flow_netlink.c +10
-0+ flags = base->flags; + ttl = base->ttl; + nsh->np = base->np; + nsh->mdtype = base->mdtype; + nsh->path_hdr = base->path_hdr; +break ; + } +case OVS_NSH_KEY_ATTR_MD1 : { +const struct ovs_nsh_key_md1 *md1 = + (struct ovs_nsh_key_md1 *)nla_data (a);
It's not necessary to retype void * explicitly. Just assign it.
net/openvswitch/flow_netlink.c static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 1242
Quoted 4 lines
net/openvswitch/flow_netlink.c +4
-0+struct nsh_md1_ctx *md1_dst = &nsh->md1; + + mdlen =nla_len (a); +memcpy (md1_dst, md1, mdlen);
Why the variable? Just memcpy to &nsh->md1.
net/openvswitch/flow_netlink.c static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 1250
Quoted 8 lines
net/openvswitch/flow_netlink.c +8
-0+break ; + } +case OVS_NSH_KEY_ATTR_MD2 : { +const struct u8 *md2 =nla_data (a); +struct nsh_md2_tlv *md2_dst = &nsh->md2; + + mdlen =nla_len (a); +memcpy (md2_dst, md2, mdlen);
Ditto.
Quoted 5 lines
net/openvswitch/flow_netlink.c +5
-0+int nsh_key_from_nlattr (const struct nlattr *attr, +struct ovs_key_nsh *nsh,struct ovs_key_nsh *nsh_mask) +{ +struct nlattr *a; +int rem;
net/openvswitch/flow_netlink.c static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 1279
Quoted 10 lines
net/openvswitch/flow_netlink.c +10
-0+ +/* validate_nsh has check this, so we needn't do duplicate check here +*/ +nla_for_each_nested (a, attr, rem) { +int type =nla_type (a); + +switch (type) { +case OVS_NSH_KEY_ATTR_BASE : { +const struct ovs_nsh_key_base *base = + (struct ovs_nsh_key_base *)nla_data (a);
It's not necessary to retype void * explicitly. Just assign it.
net/openvswitch/flow_netlink.c static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 1283
Quoted 4 lines
net/openvswitch/flow_netlink.c +4
-0+const struct ovs_nsh_key_base *base_mask = base +1 ; + +memcpy (nsh, base,sizeof (*base)); +memcpy (nsh, base_mask,sizeof (*base_mask));
The second memcpy should copy to nsh_mask, not nsh.
If you modify struct ovs_key_nsh as suggested above, this becomes a simple:
nsh->base = *base;nsh_mask->base = *base_mask;
I'm perfectly fine with memcpy, too, though.
Quoted 4 lines
net/openvswitch/flow_netlink.c +4
-0+static int nsh_key_put_from_nlattr (const struct nlattr *attr, +struct sw_flow_match *match,bool is_mask, +bool is_push_nsh,bool log) +{
net/openvswitch/flow_netlink.c static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 1320
Quoted 10 lines
net/openvswitch/flow_netlink.c +10
-0+struct nlattr *a; +int rem; +bool has_base = false; +bool has_md1 = false; +bool has_md2 = false; +u8 mdtype =0 ; +int mdlen =0 ; + +if (unlikely (is_push_nsh && is_mask)) +return -EINVAL ;
Wrap this in WARN_ON. (And note that you don't need unlikely with WARN_ON.)
net/openvswitch/flow_netlink.c static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 1381
Quoted 9 lines
net/openvswitch/flow_netlink.c +9
-0+case OVS_NSH_KEY_ATTR_MD2 : +if (!is_push_nsh)/* Not supported MD type 2 yet */ +return -ENOTSUPP ; + + has_md2 = true; + mdlen =nla_len (a); +if ((mdlen >NSH_CTX_HDRS_MAX_LEN ) || + (mdlen <=0 )) { +WARN_ON_ONCE (1 );
But here, the WARN_ON_ONCE is completely inappropriate. This condition does not indicate a kernel bug but rather invalid data from the user space. OVS_NLERR should be here instead.
net/openvswitch/flow_netlink.c static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 1419
Quoted 7 lines
net/openvswitch/flow_netlink.c +7
-0+if (is_push_nsh && + (!has_base || (!has_md1 && !has_md2))) { +OVS_NLERR ( +1 , +"push nsh attributes are invalid for type %d." , + mdtype + );
"Missing nsh base and/or metadata attribute." or something like that would be a better error message.
Quoted 7 lines
net/openvswitch/flow_netlink.c +7
-0+static int nsh_key_to_nlattr (const struct ovs_key_nsh *nsh,bool is_mask, +struct sk_buff *skb) +{ +struct nlattr *start; +struct ovs_nsh_key_base base; +struct ovs_nsh_key_md1 md1; +
net/openvswitch/flow_netlink.c static int ovs_nla_put_vlan(struct sk_buff *skb, const struct vlan_head *vh, · line 1893
Quoted 10 lines
net/openvswitch/flow_netlink.c +10
-0+memcpy (&base, nsh,sizeof (base)); + +if (is_mask || nsh->mdtype ==NSH_M_TYPE1 ) +memcpy (md1.context, nsh->context,sizeof (md1)); + + start =nla_nest_start (skb,OVS_KEY_ATTR_NSH ); +if (!start) +return -EMSGSIZE ; + +if (nla_put (skb,OVS_NSH_KEY_ATTR_BASE ,sizeof (base), &base))
The 'base' variable is not needed, let alone copy to it, just use &nsh->base here.
net/openvswitch/flow_netlink.c static int ovs_nla_put_vlan(struct sk_buff *skb, const struct vlan_head *vh, · line 1897
Quoted 4 lines
net/openvswitch/flow_netlink.c +4
-0+ goto nla_put_failure; + +if (is_mask || nsh->mdtype ==NSH_M_TYPE1 ) { +if (nla_put (skb,OVS_NSH_KEY_ATTR_MD1 ,sizeof (md1), &md1))
Likewise, no need for the copy.
net/openvswitch/flow_netlink.c static int validate_and_copy_set_tun(const struct nlattr *attr, · line 2544
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? ;-)
Jiri
Quoted 65 lines · Yi Yang
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 forOVS_KEY_ATTR_NSH
- Changepop_nshto 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
- ChangeOVS_KEY_ATTR_NSHto nested key to handle length-fixed attributes and length-variable attriubte more flexibly.
- Remove structovs_action_push_nshcompletely
- Add code to handle nested attribute forSET_MASKED
- ChangePUSH_NSHto use the nestedOVS_KEY_ATTR_NSHto transfer NSH header data.
- Fix comments and coding style issues by Jiri and Eric
v1->v2
- Changeencap_nshanddecap_nshtopush_nshandpop_nsh
- Dynamically allocate structovs_action_push_nshfor 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.
Signed-off-by Yi Yang <[email protected]>--- include/net/nsh.h | 3 + include/uapi/linux/openvswitch.h | 29 ++++ net/nsh/nsh.c | 53 +++++++ net/openvswitch/Kconfig | 1 + net/openvswitch/actions.c | 112 ++++++++++++++ net/openvswitch/flow.c | 51 ++++++ net/openvswitch/flow.h | 11 ++ net/openvswitch/flow_netlink.c | 324 ++++++++++++++++++++++++++++++++++++++- net/openvswitch/flow_netlink.h | 5 + 9 files changed, 588 insertions(+), 1 deletion(-)
[...]
Quoted 25 lines
net/nsh/nsh.c +17
-0@@ -14,6 +14,59 @@#include <net/nsh.h> #include <net/tun_proto.h> +int skb_push_nsh (struct sk_buff *skb,const struct nshhdr *src_nsh_hdr) +{ +struct nshhdr *nsh_hdr; +size_t length =nsh_hdr_len (src_nsh_hdr); +u8 next_proto; + +if (skb->mac_len) { + next_proto =TUN_P_ETHERNET ; + }else { + next_proto =tun_p_from_eth_p (skb->protocol); +if (!next_proto) +return -EAFNOSUPPORT ; + } + +/* Add the NSH header */ +if (skb_cow_head (skb, length) <0 ) +return -ENOMEM ;
net/nsh/nsh.c line 43
Quoted 10 lines
net/nsh/nsh.c +10
-0+ +skb_push (skb, length); + nsh_hdr = (struct nshhdr *)(skb->data); +memcpy (nsh_hdr, src_nsh_hdr, length); + nsh_hdr->np = next_proto; + + skb->protocol =htons (ETH_P_NSH ); +skb_reset_mac_header (skb); +skb_reset_mac_len (skb); +skb_reset_network_header (skb);
I think you mean to reset network_header before mac_len.
Quoted 7 lines
net/nsh/nsh.c +7
-0+ +return 0 ; +} +EXPORT_SYMBOL_GPL (skb_push_nsh); + +int skb_pop_nsh (struct sk_buff *skb) +{
net/nsh/nsh.c line 60
Quoted 10 lines
net/nsh/nsh.c +10
-0+struct nshhdr *nsh_hdr = (struct nshhdr *)(skb->data); +size_t length; +u16 inner_proto; + + inner_proto =tun_p_to_eth_p (nsh_hdr->np); +if (!inner_proto) +return -EAFNOSUPPORT ; + + length =nsh_hdr_len (nsh_hdr); +skb_pull (skb, length);
Do you need to verify you can actually pull length bytes? I don't see any guarantee.
net/nsh/nsh.c line 43
Quoted 3 lines
net/nsh/nsh.c +3
-0+skb_reset_mac_header (skb); +skb_reset_mac_len (skb); +skb_reset_network_header (skb);
Reset network before mac_len.
Quoted 9 lines
net/nsh/nsh.c +6
-0+ skb->protocol = inner_proto; + +return 0 ; +} +EXPORT_SYMBOL_GPL (skb_pop_nsh); +static struct sk_buff *nsh_gso_segment (struct sk_buff *skb,netdev_features_t features) {
[...]
Quoted 4 lines
net/openvswitch/actions.c +0
-0
[...]
Quoted 12 lines
net/openvswitch/actions.c +8
-0@@ -602,6 +642,59 @@ static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key,return 0 ; } +static int set_nsh (struct sk_buff *skb,struct sw_flow_key *flow_key, +const struct nlattr *a) +{ +struct nshhdr *nsh_hdr; +int err; +u8 flags; +u8 ttl; +int i;
net/openvswitch/actions.c static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key, · line 662
Quoted 10 lines
net/openvswitch/actions.c +10
-0+ +struct ovs_key_nsh key; +struct ovs_key_nsh mask; + + err =nsh_key_from_nlattr (a, &key, &mask); +if (err) +return err; + + err =skb_ensure_writable (skb,skb_network_offset (skb) + +sizeof (struct nshhdr ));
This calls pskb_may_pull(), but you're not pulling any data here.
Quoted 38 lines
net/openvswitch/actions.c +35
-0+if (unlikely (err)) +return err; + + nsh_hdr = (struct nshhdr *)skb_network_header (skb); + + flags =nsh_get_flags (nsh_hdr); + flags =OVS_MASKED (flags, key.flags, mask.flags); + flow_key->nsh.flags = flags; + ttl =nsh_get_ttl (nsh_hdr); + ttl =OVS_MASKED (ttl, key.ttl, mask.ttl); + flow_key->nsh.ttl = ttl; +nsh_set_flags_and_ttl (nsh_hdr, flags, ttl); + nsh_hdr->path_hdr =OVS_MASKED (nsh_hdr->path_hdr, key.path_hdr, + mask.path_hdr); + flow_key->nsh.path_hdr = nsh_hdr->path_hdr; +switch (nsh_hdr->mdtype) { +case NSH_M_TYPE1 : +for (i =0 ; i <NSH_MD1_CONTEXT_SIZE ; i++) { + nsh_hdr->md1.context[i] = +OVS_MASKED (nsh_hdr->md1.context[i], key.context[i], + mask.context[i]); + } +memcpy (flow_key->nsh.context, nsh_hdr->md1.context, +sizeof (nsh_hdr->md1.context)); +break ; +case NSH_M_TYPE2 : +memset (flow_key->nsh.context,0 , +sizeof (flow_key->nsh.context)); +break ; +default : +return -EINVAL ; + } +return 0 ; +} +/* Must follow skb_ensure_writable() since that can move the skb data. */ static void set_tp_port (struct sk_buff *skb,__be16 *port,__be16 new_port,__sum16 *check)
[...]
Quoted 10 lines · Jiri Benc
net/openvswitch/actions.c static int push_eth(struct sk_buff *skb, struct sw_flow_key *key, · line 393
Quoted 3 lines · Yi Yang
net/openvswitch/actions.c +3
-0+return err; + + key->eth.type =htons (ETH_P_NSH );I wonder why you have this assignment here. The key is invalidated, thus nothing should rely on
key->eth.type. However, looking at the code andovs_fragmentin particular, I'm not sure that's the case. Could you please explain why it is needed? And why the reverse of it is not needed inpop_nsh?
After push_nsh, the packet won't be recirculated to flow pipeline, so key->eth.type must be set explicitly here, but for pop_nsh, the packet will be recirculated to flow pipeline, it will be reparsed, so key->eth.type will be set in packet parse function, we needn't handle it in pop_nsh.
I have sent out v10 to fix all the comments for v9, please review v10, thanks a lot.
Quoted 7 lines · Eric Garver
net/nsh/nsh.c line 60
Quoted 3 lines · Yi Yang
net/nsh/nsh.c +3
-0+ + length =nsh_hdr_len (nsh_hdr); +skb_pull (skb, length);Do you need to verify you can actually pull length bytes? I don't see any guarantee.
I have added skb length check in pop_nsh, so that can verify this.
Quoted 4 lines
net/openvswitch/actions.c static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key, · line 662
Quoted 2 lines
net/openvswitch/actions.c +2
-0+ err =skb_ensure_writable (skb,skb_network_offset (skb) + +sizeof (struct nshhdr ));This calls
pskb_may_pull(), but you're not pulling any data here.
set_ipv4 and set_ipv6 also used skb_ensure_writable to check if skb has enough header length, they didn't call skb_pull in the following part, so I think this is ok.
I have sent out v10 to fix all of your comments for v9, please help review v10, thanks a lot.
Quoted 5 lines · Yi
After
push_nsh, the packet won't be recirculated to flow pipeline, sokey->eth.typemust be set explicitly here, but forpop_nsh, the packet will be recirculated to flow pipeline, it will be reparsed, sokey->eth.typewill be set in packet parse function, we needn't handle it inpop_nsh.
This seems to be a very different approach than what we currently have. Looking at the code, the requirement after "destructive" actions such as pushing or popping headers is to recirculate.
Setting key->eth.type to satisfy conditions in the output path without updating the rest of the key looks very hacky and fragile to me. There might be other conditions and dependencies that are not obvious. I don't think the code was written with such code path in mind.
I'd like to hear what Pravin thinks about this.
Jiri
Quoted 10 lines · Yi
Quoted 7 lines · Eric Garver
net/nsh/nsh.c line 60
Quoted 3 lines · Yi Yang
net/nsh/nsh.c +3
-0+ + length =nsh_hdr_len (nsh_hdr); +skb_pull (skb, length);Do you need to verify you can actually pull length bytes? I don't see any guarantee.
I have added skb length check in
pop_nsh, so that can verify this.
That doesn't help other code that may call skb_pop_nsh(). skb_vlan_pop() calls skb_ensure_writable() which seems like the right thing to do.
Quoted 10 lines · Eric Garver
Quoted 9 lines · Yi
Quoted 7 lines · Eric Garver
net/nsh/nsh.c line 60
Quoted 3 lines · Yi Yang
net/nsh/nsh.c +3
-0+ + length =nsh_hdr_len (nsh_hdr); +skb_pull (skb, length);Do you need to verify you can actually pull length bytes? I don't see any guarantee.
Quoted 4 lines
Quoted 1 line
I have added skb length check in
pop_nsh, so that can verify this.That doesn't help other code that may call
skb_pop_nsh().skb_vlan_pop()callsskb_ensure_writable()which seems like the right thing to do.
Make sense, I will move it to skp_pop_nsh, thanks.
Quoted 10 lines · Jiri Benc
Quoted 5 lines · Yi
After
push_nsh, the packet won't be recirculated to flow pipeline, sokey->eth.typemust be set explicitly here, but forpop_nsh, the packet will be recirculated to flow pipeline, it will be reparsed, sokey->eth.typewill be set in packet parse function, we needn't handle it inpop_nsh.This seems to be a very different approach than what we currently have. Looking at the code, the requirement after "destructive" actions such as pushing or popping headers is to recirculate.
This is optimization proposed by Jan Scheurich, recurculating after push_nsh will impact on performance, recurculating after pop_nsh is unavoidable, So also cc [email protected].
Actucally all the keys before push_nsh are still there after push_nsh, push_nsh has updated all the nsh keys, so recirculating remains avoidable.
Quoted 9 lines
Setting
key->eth.typeto satisfy conditions in the output path without updating the rest of the key looks very hacky and fragile to me. There might be other conditions and dependencies that are not obvious. I don't think the code was written with such code path in mind.I'd like to hear what Pravin thinks about this.
Jiri
Quoted 12 lines · Yi
Quoted 10 lines · Jiri Benc
Quoted 5 lines · Yi
After
push_nsh, the packet won't be recirculated to flow pipeline, sokey->eth.typemust be set explicitly here, but forpop_nsh, the packet will be recirculated to flow pipeline, it will be reparsed, sokey->eth.typewill be set in packet parse function, we needn't handle it inpop_nsh.This seems to be a very different approach than what we currently have. Looking at the code, the requirement after "destructive" actions such as pushing or popping headers is to recirculate.
Quoted 7 lines
This is optimization proposed by Jan Scheurich, recurculating after
push_nshwill impact on performance, recurculating afterpop_nshis unavoidable, So also cc [email protected].Actucally all the keys before
push_nshare still there afterpush_nsh,push_nshhas updated all the nsh keys, so recirculating remains avoidable.
We should keep existing model for this patch. Later you can submit optimization patch with specific use cases and performance improvement. So that we can evaluate code complexity and benefits.
Quoted 9 lines
Quoted 9 lines
Setting
key->eth.typeto satisfy conditions in the output path without updating the rest of the key looks very hacky and fragile to me. There might be other conditions and dependencies that are not obvious. I don't think the code was written with such code path in mind.I'd like to hear what Pravin thinks about this.
Jiri
Quoted 17 lines · Pravin Shelar
Quoted 16 lines · Yi
Quoted 10 lines · Jiri Benc
Quoted 5 lines · Yi
After
push_nsh, the packet won't be recirculated to flow pipeline, sokey->eth.typemust be set explicitly here, but forpop_nsh, the packet will be recirculated to flow pipeline, it will be reparsed, sokey->eth.typewill be set in packet parse function, we needn't handle it inpop_nsh.This seems to be a very different approach than what we currently have. Looking at the code, the requirement after "destructive" actions such as pushing or popping headers is to recirculate.
This is optimization proposed by Jan Scheurich, recurculating after
push_nshwill impact on performance, recurculating afterpop_nshis unavoidable, So also cc [email protected].
Quoted 8 lines
Quoted 3 lines
Actucally all the keys before
push_nshare still there afterpush_nsh,push_nshhas updated all the nsh keys, so recirculating remains avoidable.We should keep existing model for this patch. Later you can submit optimization patch with specific use cases and performance improvement. So that we can evaluate code complexity and benefits.
Ok, I'll remove the below line in push_nsh and send out v11, thanks.
key->eth.type = htons(ETH_P_NSH);
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Setting
key->eth.typeto satisfy conditions in the output path without updating the rest of the key looks very hacky and fragile to me. There might be other conditions and dependencies that are not obvious. I don't think the code was written with such code path in mind.I'd like to hear what Pravin thinks about this.
Jiri
Quoted 30 lines
From: Yang, Yi [mailto:[email protected]]
Sent: Friday, 29 September, 2017 08:41
To: Pravin Shelar <[email protected]>
Cc: Jiri Benc <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Jan Scheurich <[email protected]>
Subject: Re: [PATCH net-next v9] openvswitch: enable NSH supportQuoted 22 lines · Pravin Shelar
Quoted 19 lines · Yi
Quoted 10 lines · Jiri Benc
Quoted 5 lines · Yi
After
push_nsh, the packet won't be recirculated to flow pipeline, sokey->eth.typemust be set explicitly here, but forpop_nsh, the packet will be recirculated to flow pipeline, it will be reparsed, sokey->eth.typewill be set in packet parse function, we needn't handle it inpop_nsh.This seems to be a very different approach than what we currently have. Looking at the code, the requirement after "destructive" actions such as pushing or popping headers is to recirculate.
This is optimization proposed by Jan Scheurich, recurculating after
push_nshwill impact on performance, recurculating afterpop_nshis unavoidable, So also cc [email protected].Actucally all the keys before
push_nshare still there afterpush_nsh,push_nshhas updated all the nsh keys, so recirculating remains avoidable.
Quoted 7 lines
Quoted 3 lines
We should keep existing model for this patch. Later you can submit optimization patch with specific use cases and performance improvement. So that we can evaluate code complexity and benefits.
Ok, I'll remove the below line in
push_nshand send out v11, thanks.key->eth.type = htons(ETH_P_NSH);
The optimization Yi refers to only affects the slow path translation.
OVS 2.8 does not immediately trigger an immediate recirculation after translating encap(nsh,...). There is no need to do so as the flow key of the resulting packet can be determined from the encap() action and its properties. Translation continues with the rewritten flow key and subsequent OpenFlow actions will typically set the new fields in the new NSH header. The push_nsh datapath action (including all NSH header fields) is only generated at the next commit, e.g. for output, cloning, recirculation, encap/decap or another destructive change of the flow key.
The implementation of push_nsh in the user-space datapath does not update the miniflow (key) of the packet, only the packet data and some metadata. If the packet needs to be looked up again the slow path triggers recirculation to re-parse the packet. There should be no need for the datapath push_nsh action to try to update the flow key.
BR, Jan
Quoted 49 lines · Jan Scheurich
Quoted 30 lines
From: Yang, Yi [mailto:[email protected]]
Sent: Friday, 29 September, 2017 08:41
To: Pravin Shelar <[email protected]>
Cc: Jiri Benc <[email protected]>; [email protected]; [email protected]; [email protected]; davem-fT/PcQaiUtIeIZ0/[email protected]; Jan Scheurich <jan.scheurich-IzeFyvvaP7pWk0Htik3J/[email protected]>
Subject: Re: [PATCH net-next v9] openvswitch: enable NSH supportQuoted 22 lines · Pravin Shelar
Quoted 19 lines · Yi
Quoted 10 lines · Jiri Benc
Quoted 5 lines · Yi
After
push_nsh, the packet won't be recirculated to flow pipeline, sokey->eth.typemust be set explicitly here, but forpop_nsh, the packet will be recirculated to flow pipeline, it will be reparsed, sokey->eth.typewill be set in packet parse function, we needn't handle it inpop_nsh.This seems to be a very different approach than what we currently have. Looking at the code, the requirement after "destructive" actions such as pushing or popping headers is to recirculate.
This is optimization proposed by Jan Scheurich, recurculating after
push_nshwill impact on performance, recurculating afterpop_nshis unavoidable, So also cc [email protected]Actucally all the keys before
push_nshare still there afterpush_nsh,push_nshhas updated all the nsh keys, so recirculating remains avoidable.Quoted 7 lines
Quoted 3 lines
We should keep existing model for this patch. Later you can submit optimization patch with specific use cases and performance improvement. So that we can evaluate code complexity and benefits.
Ok, I'll remove the below line in
push_nshand send out v11, thanks.key->eth.type = htons(ETH_P_NSH);The optimization Yi refers to only affects the slow path translation.
OVS 2.8 does not immediately trigger an immediate recirculation after translating
encap(nsh,...). There is no need to do so as the flow key of the resulting packet can be determined from theencap()action and its properties. Translation continues with the rewritten flow key and subsequent OpenFlow actions will typically set the new fields in the new NSH header. Thepush_nshdatapath action (including all NSH header fields) is only generated at the next commit, e.g. for output, cloning, recirculation, encap/decap or another destructive change of the flow key.
Quoted 5 lines
The implementation of
push_nshin the user-space datapath does not update the miniflow (key) of the packet, only the packet data and some metadata. If the packet needs to be looked up again the slow path triggers recirculation to re-parse the packet. There should be no need for the datapathpush_nshaction to try to update the flow key.
Thanks Jan for clarification, it can still work after removing that line, our flows didn't match it after push_nsh, it is output to VxLAN-gpe port after push_nsh, I'm not sure if we can match dl_type and NSH fields if we don't output and don't recirculate.
Quoted 2 lines
BR, Jan
Quoted 17 lines
Quoted 11 lines
The optimization Yi refers to only affects the slow path translation.
OVS 2.8 does not immediately trigger an immediate recirculation after translating
encap(nsh,...). There is no need to do so as the flow key of the resulting packet can be determined from theencap()action and its properties. Translation continues with the rewritten flow key and subsequent OpenFlow actions will typically set the new fields in the new NSH header. Thepush_nshdatapath action (including all NSH header fields) is only generated at the next commit, e.g. for output, cloning, recirculation, encap/decap or another destructive change of the flow key.Quoted 5 lines
The implementation of
push_nshin the user-space datapath does not update the miniflow (key) of the packet, only the packet data and some metadata. If the packet needs to be looked up again the slow path triggers recirculation to re-parse the packet. There should be no need for the datapathpush_nshaction to try to update the flow key.
Quoted 4 lines
Thanks Jan for clarification, it can still work after removing that line, our flows didn't match it after
push_nsh, it is output to VxLAN-gpe port afterpush_nsh, I'm not sure if we can matchdl_typeand NSH fields if we don't output and don't recirculate.
No worries, a packet cannot be matched again in the datapath unless it is recirculated. And recirculation today always implies re-parsing.
In the future we want to look into possibilities to optimize performance of recirculation, for example by skipping the parsing stage if it is unnecessary. For that we may need to invalidate the flow key in packet metadata when the packet is modified without corresponding update of the key itself. But that is music of the future.
/Jan