openvswitch: enable NSH support
Subsystems (3)
PATCH v15 1/1 openvswitch: enable NSH support
v14->v15
- Check size in nsh_hdr_from_nlattr
- Fixed four small issues pointed out By Jiri and Eric
v13->v14
- Rename skb_push_nsh to nsh_push per Dave's comment
- Rename skb_pop_nsh to nsh_pop per Dave's comment
v12->v13
- Fix NSH header length check in set_nsh
v11->v12
- Fix missing changes old comments pointed out
- Fix new comments for v11
v10->v11
- Fix the left three disputable comments for v9 but not fixed in v10.
v9->v10
- Change struct ovs_key_nsh to
struct ovs_nsh_key_base base;
__be32 context[NSH_MD1_CONTEXT_SIZE];- Fix new comments for v9
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 | 59 ++++++++ net/openvswitch/Kconfig | 1 + net/openvswitch/actions.c | 119 +++++++++++++++ net/openvswitch/flow.c | 51 +++++++ net/openvswitch/flow.h | 7 + net/openvswitch/flow_netlink.c | 315 ++++++++++++++++++++++++++++++++++++++- 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 nsh_push (struct sk_buff *skb,const struct nshhdr *pushed_nh); +int nsh_pop (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 */
@@ -492,6 +493,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
@@ -808,6 +833,8 @@ struct ovs_action_push_eth {* @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the * packet. * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from 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
@@ -838,6 +865,8 @@ enum ovs_action_attr {OVS_ACTION_ATTR_PUSH_ETH ,/* struct ovs_action_push_eth. */ OVS_ACTION_ATTR_POP_ETH ,/* No argument. */ OVS_ACTION_ATTR_CT_CLEAR ,/* 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 +59 -0
65 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 +119 -0
149 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 +7 -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,11 @@ struct vlan_head { (offsetof(struct sw_flow_key , recirc_id) + \ FIELD_SIZEOF(struct sw_flow_key, recirc_id)) +struct ovs_key_nsh { +struct ovs_nsh_key_base base; +__be32 context[NSH_MD1_CONTEXT_SIZE ]; +}; +struct sw_flow_key {u8 tun_opts[IP_TUNNEL_OPTS_MAX ];u8 tun_opts_len;
@@ -144,6 +150,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 +314 -1
407 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 *nh, +size_t size); +#endif /* flow_netlink.h */
Signature · 1 line
2.5.5
Quoted 3 lines · Yi Yang
v14->v15
- Check size innsh_hdr_from_nlattr
- Fixed four small issues pointed out By Jiri and Eric
Quoted 3 lines · Yi Yang
v14->v15
- Check size innsh_hdr_from_nlattr
- Fixed four small issues pointed out By Jiri and Eric
Thanks Yi.
Quoted 72 lines · Yi Yang
v14->v15
- Check size innsh_hdr_from_nlattr
- Fixed four small issues pointed out By Jiri and Eric
v13->v14
- Renameskb_push_nshtonsh_pushper Dave's comment
- Renameskb_pop_nshtonsh_popper Dave's comment
v12->v13
- Fix NSH header length check inset_nsh
v11->v12
- Fix missing changes old comments pointed out
- Fix new comments for v11
v10->v11
- Fix the left three disputable comments for v9 but not fixed in v10.
v9->v10
- Change structovs_key_nshtostruct ovs_nsh_key_base base; __be32 context[NSH_MD1_CONTEXT_SIZE];- Fix new comments for v9
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.
Quoted 7 lines
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]>---
I have comment related to checksum, otherwise patch looks good to me.
Quoted 11 lines
include/net/nsh.h | 3 + include/uapi/linux/openvswitch.h | 29 ++++ net/nsh/nsh.c | 59 ++++++++ net/openvswitch/Kconfig | 1 + net/openvswitch/actions.c | 119 +++++++++++++++ net/openvswitch/flow.c | 51 +++++++ net/openvswitch/flow.h | 7 + net/openvswitch/flow_netlink.c | 315 ++++++++++++++++++++++++++++++++++++++- net/openvswitch/flow_netlink.h | 5 + 9 files changed, 588 insertions(+), 1 deletion(-)
...
Quoted 20 lines
net/nsh/nsh.c +12
-0@@ -14,6 +14,65 @@#include <net/nsh.h> #include <net/tun_proto.h> +int nsh_push (struct sk_buff *skb,const struct nshhdr *pushed_nh) +{ +struct nshhdr *nh; +size_t length =nsh_hdr_len (pushed_nh); +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 ;
net/nsh/nsh.c line 38
Quoted 10 lines
net/nsh/nsh.c +10
-0+ } + +/* Add the NSH header */ +if (skb_cow_head (skb, length) <0 ) +return -ENOMEM ; + +skb_push (skb, length); + nh = (struct nshhdr *)(skb->data); +memcpy (nh, pushed_nh, length); + nh->np = next_proto;
dont you need to update checksum for CHECKSUM_COMPLETE case?
Quoted 18 lines
net/nsh/nsh.c +18
-0+ + skb->protocol =htons (ETH_P_NSH ); +skb_reset_mac_header (skb); +skb_reset_network_header (skb); +skb_reset_mac_len (skb); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nsh_push); + +int nsh_pop (struct sk_buff *skb) +{ +struct nshhdr *nh; +size_t length; +__be16 inner_proto; + +if (!pskb_may_pull (skb,NSH_BASE_HDR_LEN )) +return -ENOMEM ;
net/nsh/nsh.c line 66
Quoted 10 lines
net/nsh/nsh.c +10
-0+ nh = (struct nshhdr *)(skb->data); + length =nsh_hdr_len (nh); + inner_proto =tun_p_to_eth_p (nh->np); +if (!pskb_may_pull (skb, length)) +return -ENOMEM ; + +if (!inner_proto) +return -EAFNOSUPPORT ; + +skb_pull (skb, length);
same as above, we need to update the checksum.
Quoted 12 lines
net/nsh/nsh.c +9
-0+skb_reset_mac_header (skb); +skb_reset_network_header (skb); +skb_reset_mac_len (skb); + skb->protocol = inner_proto; + +return 0 ; +} +EXPORT_SYMBOL_GPL (nsh_pop); +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 52 lines
net/openvswitch/actions.c +48
-0@@ -602,6 +640,67 @@ 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 *nh; +size_t length; +int err; +u8 flags; +u8 ttl; +int i; + +struct ovs_key_nsh key; +struct ovs_key_nsh mask; + + err =nsh_key_from_nlattr (a, &key, &mask); +if (err) +return err; + +/* Make sure the NSH base header is there */ +if (!pskb_may_pull (skb,skb_network_offset (skb) +NSH_BASE_HDR_LEN )) +return -ENOMEM ; + + nh =nsh_hdr (skb); + length =nsh_hdr_len (nh); + +/* Make sure the whole NSH header is there */ + err =skb_ensure_writable (skb,skb_network_offset (skb) + + length); +if (unlikely (err)) +return err; + + nh =nsh_hdr (skb); + flags =nsh_get_flags (nh); + flags =OVS_MASKED (flags, key.base.flags, mask.base.flags); + flow_key->nsh.base.flags = flags; + ttl =nsh_get_ttl (nh); + ttl =OVS_MASKED (ttl, key.base.ttl, mask.base.ttl); + flow_key->nsh.base.ttl = ttl; +nsh_set_flags_and_ttl (nh, flags, ttl); + nh->path_hdr =OVS_MASKED (nh->path_hdr, key.base.path_hdr, + mask.base.path_hdr); + flow_key->nsh.base.path_hdr = nh->path_hdr; +switch (nh->mdtype) { +case NSH_M_TYPE1 : +for (i =0 ; i <NSH_MD1_CONTEXT_SIZE ; i++) { + nh->md1.context[i] = +OVS_MASKED (nh->md1.context[i], key.context[i], + mask.context[i]); + }
net/openvswitch/actions.c static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key, · line 700
Quoted 10 lines
net/openvswitch/actions.c +10
-0+memcpy (flow_key->nsh.context, nh->md1.context, +sizeof (nh->md1.context)); +break ; +case NSH_M_TYPE2 : +memset (flow_key->nsh.context,0 , +sizeof (flow_key->nsh.context)); +break ; +default : +return -EINVAL ; + }
same as above need to fix checksum for CHECKSUM_COMPLETE case.
Quoted 3 lines
net/openvswitch/actions.c +3
-0+return 0 ; +} +
Quoted 10 lines · Pravin Shelar
Quoted 8 lines · Yi Yang
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]>---
I have comment related to checksum, otherwise patch looks good to me.
Pravin, thank you for your comments, the below part is incremental patch for checksum, please help check it, I'll send out v16 with this after you confirm.
net/nsh/nsh.c +2 -1
@@ -36,6 +36,7 @@ int nsh_push(struct sk_buff *skb, const struct nshhdr *pushed_nh) nh = (struct nshhdr *)(skb->data);memcpy (nh, pushed_nh, length); nh->np = next_proto; +skb_postpush_rcsum (skb, nh, length); skb->protocol =htons (ETH_P_NSH );skb_reset_mac_header (skb);
@@ -63,7 +64,7 @@ int nsh_pop(struct sk_buff *skb)if (!inner_proto)return -EAFNOSUPPORT ; -skb_pull (skb, length); +skb_pull_rcsum (skb, length);skb_reset_mac_header (skb);skb_reset_network_header (skb);skb_reset_mac_len (skb);
net/openvswitch/actions.c +2 -0
@@ -671,6 +671,7 @@ static int set_nsh(struct sk_buff *skb, struct sw_flow_key *flow_key,return err; nh =nsh_hdr (skb); +skb_postpull_rcsum (skb, nh, length); flags =nsh_get_flags (nh); flags =OVS_MASKED (flags, key.base.flags, mask.base.flags); flow_key->nsh.base.flags = flags;
@@ -698,6 +699,7 @@ static int set_nsh(struct sk_buff *skb, struct sw_flow_key *flow_key,default :return -EINVAL ; } +skb_postpush_rcsum (skb, nh, length);return 0 ; }
Quoted 8 lines · Yi
Quoted 7 lines · Pravin Shelar
Quoted 6 lines · Yi Yang
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.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Signed-off-by Yi Yang <[email protected]>---
I have comment related to checksum, otherwise patch looks good to me.
Pravin, thank you for your comments, the below part is incremental patch for checksum, please help check it, I'll send out v16 with this after you confirm.
This change looks good to me.
I noticed couple of more issues.
1. Can you move the ovs_key_nsh to the union of ipv4 an ipv6? ipv4/ipv6/nsh key data is mutually exclusive so there is no need for separate space for nsh key in the ovs key.
2. We need to fix match_validate() with nsh check. Datapath can not allow any l3 or l4 match if the flow key contains nsh match and vice-versa. such flow key should be rejected.
A message that is not in the archive (sent off-list or not yet received): CAOrHB_BaUS7WfisvX6G+450tEQ2skmsE0v-b27s-_21s25bigw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 17 lines · Pravin Shelar
Quoted 8 lines · Yi
Quoted 7 lines · Pravin Shelar
Quoted 6 lines · Yi Yang
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.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Signed-off-by Yi Yang <[email protected]>---
I have comment related to checksum, otherwise patch looks good to me.
Pravin, thank you for your comments, the below part is incremental patch for checksum, please help check it, I'll send out v16 with this after you confirm.
Quoted 8 lines
This change looks good to me.
I noticed couple of more issues.
1. Can you move theovs_key_nshto the union of ipv4 an ipv6? ipv4/ipv6/nsh key data is mutually exclusive so there is no need for separate space for nsh key in the ovs key.
2. We need to fixmatch_validate()with nsh check. Datapath can not allow any l3 or l4 match if the flow key contains nsh match and vice-versa. such flow key should be rejected.
Ok, I'll fix them ASAP.
Quoted 17 lines · Pravin Shelar
Quoted 8 lines · Yi
Quoted 7 lines · Pravin Shelar
Quoted 6 lines · Yi Yang
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.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Signed-off-by Yi Yang <[email protected]>---
I have comment related to checksum, otherwise patch looks good to me.
Pravin, thank you for your comments, the below part is incremental patch for checksum, please help check it, I'll send out v16 with this after you confirm.
Quoted 8 lines
This change looks good to me.
I noticed couple of more issues.
1. Can you move theovs_key_nshto the union of ipv4 an ipv6? ipv4/ipv6/nsh key data is mutually exclusive so there is no need for separate space for nsh key in the ovs key.
2. We need to fixmatch_validate()with nsh check. Datapath can not allow any l3 or l4 match if the flow key contains nsh match and vice-versa. such flow key should be rejected.
Pravin, the below incremental patch should fix the issues you pionted out, please help confirm/ack, then I'll send out v16 with all acks from you all for merge. BTW, it has been verified in my sfc test environment.
net/openvswitch/flow.h +1 -1
@@ -149,8 +149,8 @@ struct sw_flow_key { } nd; }; } ipv6; +struct ovs_key_nsh nsh;/* network service header */ }; -struct ovs_key_nsh nsh;/* network service header */ struct { /* Connection tracking fields not packed above. */ struct {
net/openvswitch/flow_netlink.c +10 -1
@@ -178,7 +178,8 @@ static bool match_validate(const struct sw_flow_match *match, | (1 << OVS_KEY_ATTR_ICMPV6) | (1 <<OVS_KEY_ATTR_ARP ) | (1 <<OVS_KEY_ATTR_ND ) - | (1 << OVS_KEY_ATTR_MPLS)); + | (1 <<OVS_KEY_ATTR_MPLS ) + | (1 << OVS_KEY_ATTR_NSH));/* Always allowed mask fields. */ mask_allowed |= ((1 << OVS_KEY_ATTR_TUNNEL)
@@ -287,6 +288,14 @@ static bool match_validate(const struct sw_flow_match *match, } } +if (match->key->eth.type ==htons (ETH_P_NSH )) { + key_expected |=1 <<OVS_KEY_ATTR_NSH ; +if (match->mask && + match->mask->key.eth.type ==htons (0xffff )) { + mask_allowed |=1 <<OVS_KEY_ATTR_NSH ; + } + } +if ((key_attrs & key_expected) != key_expected) {/* Key attributes check failed. */ OVS_NLERR(log, "Missing key (keys=%llx, expected=%llx)",
Quoted 27 lines · Yi
Quoted 17 lines · Pravin Shelar
Quoted 8 lines · Yi
Quoted 7 lines · Pravin Shelar
Quoted 6 lines · Yi Yang
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.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Signed-off-by Yi Yang <[email protected]>---
I have comment related to checksum, otherwise patch looks good to me.
Pravin, thank you for your comments, the below part is incremental patch for checksum, please help check it, I'll send out v16 with this after you confirm.
Quoted 8 lines
This change looks good to me.
I noticed couple of more issues.
1. Can you move theovs_key_nshto the union of ipv4 an ipv6? ipv4/ipv6/nsh key data is mutually exclusive so there is no need for separate space for nsh key in the ovs key.
2. We need to fixmatch_validate()with nsh check. Datapath can not allow any l3 or l4 match if the flow key contains nsh match and vice-versa. such flow key should be rejected.
Quoted 5 lines
Pravin, the below incremental patch should fix the issues you pionted out, please help confirm/ack, then I'll send out v16 with all acks from you all for merge. BTW, it has been verified in my sfc test environment.
Following patch looks good to me. But I think we needs similar eth_type check for nsh set action in validate_set() and in __ovs_nla_copy_actions() for NSH_POP action.
Can you send patch with all changes?
Thanks.
Quoted 43 lines
net/openvswitch/flow.h +1
-1@@ -149,8 +149,8 @@ struct sw_flow_key { } nd; }; } ipv6; +struct ovs_key_nsh nsh;/* network service header */ }; -struct ovs_key_nsh nsh;/* network service header */ struct { /* Connection tracking fields not packed above. */ struct {net/openvswitch/flow_netlink.c +10
-1@@ -178,7 +178,8 @@ static bool match_validate(const struct sw_flow_match *match, | (1 << OVS_KEY_ATTR_ICMPV6) | (1 <<OVS_KEY_ATTR_ARP ) | (1 <<OVS_KEY_ATTR_ND ) - | (1 << OVS_KEY_ATTR_MPLS)); + | (1 <<OVS_KEY_ATTR_MPLS ) + | (1 << OVS_KEY_ATTR_NSH));/* Always allowed mask fields. */ mask_allowed |= ((1 << OVS_KEY_ATTR_TUNNEL)@@ -287,6 +288,14 @@ static bool match_validate(const struct sw_flow_match *match, } } +if (match->key->eth.type ==htons (ETH_P_NSH )) { + key_expected |=1 <<OVS_KEY_ATTR_NSH ; +if (match->mask && + match->mask->key.eth.type ==htons (0xffff )) { + mask_allowed |=1 <<OVS_KEY_ATTR_NSH ; + } + } +if ((key_attrs & key_expected) != key_expected) {/* Key attributes check failed. */ OVS_NLERR(log, "Missing key (keys=%llx, expected=%llx)",
A message that is not in the archive (sent off-list or not yet received): 1509508981-66202-1-git-send-email-yi.y.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Quoted 72 lines · Yi Yang
v14->v15
- Check size innsh_hdr_from_nlattr
- Fixed four small issues pointed out By Jiri and Eric
v13->v14
- Renameskb_push_nshtonsh_pushper Dave's comment
- Renameskb_pop_nshtonsh_popper Dave's comment
v12->v13
- Fix NSH header length check inset_nsh
v11->v12
- Fix missing changes old comments pointed out
- Fix new comments for v11
v10->v11
- Fix the left three disputable comments for v9 but not fixed in v10.
v9->v10
- Change structovs_key_nshtostruct ovs_nsh_key_base base; __be32 context[NSH_MD1_CONTEXT_SIZE];- Fix new comments for v9
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.
Quoted 6 lines
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]>
As commented earlier following are action related validations that can be moved to flow install phase.
Quoted 12 lines
--- include/net/nsh.h | 3 + include/uapi/linux/openvswitch.h | 29 ++++ net/nsh/nsh.c | 59 ++++++++ net/openvswitch/Kconfig | 1 + net/openvswitch/actions.c | 119 +++++++++++++++ net/openvswitch/flow.c | 51 +++++++ net/openvswitch/flow.h | 7 + net/openvswitch/flow_netlink.c | 315 ++++++++++++++++++++++++++++++++++++++- net/openvswitch/flow_netlink.h | 5 + 9 files changed, 588 insertions(+), 1 deletion(-)
...
Quoted 10 lines
net/nsh/nsh.c +2
-0@@ -14,6 +14,65 @@#include <net/nsh.h> #include <net/tun_proto.h> +int nsh_push (struct sk_buff *skb,const struct nshhdr *pushed_nh) +{
net/nsh/nsh.c line 28
Quoted 10 lines
net/nsh/nsh.c +10
-0+struct nshhdr *nh; +size_t length =nsh_hdr_len (pushed_nh); +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 ;
check for supported protocols can be moved to flow install validation in __ovs_nla_copy_actions().
Quoted 21 lines
net/nsh/nsh.c +21
-0+ } + +/* Add the NSH header */ +if (skb_cow_head (skb, length) <0 ) +return -ENOMEM ; + +skb_push (skb, length); + nh = (struct nshhdr *)(skb->data); +memcpy (nh, pushed_nh, length); + nh->np = next_proto; + + skb->protocol =htons (ETH_P_NSH ); +skb_reset_mac_header (skb); +skb_reset_network_header (skb); +skb_reset_mac_len (skb); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nsh_push); + +int nsh_pop (struct sk_buff *skb)
net/nsh/nsh.c line 59
Quoted 10 lines
net/nsh/nsh.c +10
-0+{ +struct nshhdr *nh; +size_t length; +__be16 inner_proto; + +if (!pskb_may_pull (skb,NSH_BASE_HDR_LEN )) +return -ENOMEM ; + nh = (struct nshhdr *)(skb->data); + length =nsh_hdr_len (nh); + inner_proto =tun_p_to_eth_p (nh->np);
same as above, this check can be moved to flow install __ovs_nla_copy_actions().
Quoted 16 lines
net/nsh/nsh.c +16
-0+if (!pskb_may_pull (skb, length)) +return -ENOMEM ; + +if (!inner_proto) +return -EAFNOSUPPORT ; + +skb_pull (skb, length); +skb_reset_mac_header (skb); +skb_reset_network_header (skb); +skb_reset_mac_len (skb); + skb->protocol = inner_proto; + +return 0 ; +} +EXPORT_SYMBOL_GPL (nsh_pop); +
...
Quoted 4 lines
net/openvswitch/actions.c +0
-0
...
net/openvswitch/actions.c static int push_eth(struct sk_buff *skb, struct sw_flow_key *key, · line 407
Quoted 9 lines
net/openvswitch/actions.c +9
-0+static int pop_nsh (struct sk_buff *skb,struct sw_flow_key *key) +{ +int err; + +if (ovs_key_mac_proto (key) !=MAC_PROTO_NONE || + skb->protocol !=htons (ETH_P_NSH )) { +return -EINVAL ; + } +
These checks can be moved to flow install.
Quoted 13 lines
net/openvswitch/actions.c +13
-0+ err =nsh_pop (skb); +if (err) +return err; + +/* safe right before invalidate_flow_key */ +if (skb->protocol ==htons (ETH_P_TEB )) + key->mac_proto =MAC_PROTO_ETHERNET ; +else + key->mac_proto =MAC_PROTO_NONE ; +invalidate_flow_key (key); +return 0 ; +} +
Quoted 40 lines · Pravin Shelar
Review
Quoted 12 lines · Yi Yang
(quoted diff) +12
-0+int nsh_push(struct sk_buff *skb, const struct nshhdr *pushed_nh) +{ + struct nshhdr *nh; + size_t length = nsh_hdr_len(pushed_nh); + 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;check for supported protocols can be moved to flow install validation in
__ovs_nla_copy_actions().Quoted 24 lines
(quoted diff) +24
-0+ } + + /* Add the NSH header */ + if (skb_cow_head(skb, length) < 0) + return -ENOMEM; + + skb_push(skb, length); + nh = (struct nshhdr *)(skb->data); + memcpy(nh, pushed_nh, length); + nh->np = next_proto; + + skb->protocol = htons(ETH_P_NSH); + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb_reset_mac_len(skb); + + return 0; +} +EXPORT_SYMBOL_GPL(nsh_push); + +int nsh_pop(struct sk_buff *skb) +{ + struct nshhdr *nh; + size_t length;
Quoted 8 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ __be16 inner_proto; + + if (!pskb_may_pull(skb, NSH_BASE_HDR_LEN)) + return -ENOMEM; + nh = (struct nshhdr *)(skb->data); + length = nsh_hdr_len(nh); + inner_proto = tun_p_to_eth_p(nh->np);same as above, this check can be moved to flow install
__ovs_nla_copy_actions().
Pravin, these two functions are not only for OVS, you can see it is net/nsh/nsh.c, Jiri and Eric mentioned they also could be used by TC.
I understand you expect some checks should be moved to slow path, but for there two cases, we can't remove them into __ovs_nla_copy_actions.
Quoted 23 lines
Quoted 17 lines
(quoted diff) +16
-0+ if (!pskb_may_pull(skb, length)) + return -ENOMEM; + + if (!inner_proto) + return -EAFNOSUPPORT; + + skb_pull(skb, length); + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb_reset_mac_len(skb); + skb->protocol = inner_proto; + + return 0; +} +EXPORT_SYMBOL_GPL(nsh_pop); +...
Quoted 4 lines
net/openvswitch/actions.c +0
-0...
Quoted 10 lines
net/openvswitch/actions.c
Quoted 9 lines
net/openvswitch/actions.c +9
-0+static int pop_nsh (struct sk_buff *skb,struct sw_flow_key *key) +{ +int err; + +if (ovs_key_mac_proto (key) !=MAC_PROTO_NONE || + skb->protocol !=htons (ETH_P_NSH )) { +return -EINVAL ; + } +These checks can be moved to flow install.
Done in v16, here is incremental patch. I have sent out v16.
net/openvswitch/actions.c +0 -5
@@ -400,11 +400,6 @@ {int err; -if (ovs_key_mac_proto (key) !=MAC_PROTO_NONE || - skb->protocol !=htons (ETH_P_NSH )) { -return -EINVAL ; - } - err =nsh_pop (skb);if (err)return err;
net/openvswitch/flow_netlink.c +4 -0
@@ -2737,6 +2737,8 @@break ;case OVS_KEY_ATTR_NSH : +if (eth_type !=htons (ETH_P_NSH )) +return -EINVAL ;if (!validate_nsh (nla_data (a), masked, false, log))return -EINVAL ;break ;
@@ -3006,6 +3008,8 @@break ;case OVS_ACTION_ATTR_POP_NSH : +if (eth_type !=htons (ETH_P_NSH )) +return -EINVAL ;if (key->nsh.base.np ==TUN_P_ETHERNET ) mac_proto =MAC_PROTO_ETHERNET ;else
Quoted 14 lines
Quoted 14 lines
net/openvswitch/actions.c +13
-0+ err =nsh_pop (skb); +if (err) +return err; + +/* safe right before invalidate_flow_key */ +if (skb->protocol ==htons (ETH_P_TEB )) + key->mac_proto =MAC_PROTO_ETHERNET ; +else + key->mac_proto =MAC_PROTO_NONE ; +invalidate_flow_key (key); +return 0 ; +} +
Quoted 50 lines · Yi
Quoted 40 lines · Pravin Shelar
Review
Quoted 12 lines · Yi Yang
(quoted diff) +12
-0+int nsh_push(struct sk_buff *skb, const struct nshhdr *pushed_nh) +{ + struct nshhdr *nh; + size_t length = nsh_hdr_len(pushed_nh); + 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;check for supported protocols can be moved to flow install validation in
__ovs_nla_copy_actions().Quoted 24 lines
(quoted diff) +24
-0+ } + + /* Add the NSH header */ + if (skb_cow_head(skb, length) < 0) + return -ENOMEM; + + skb_push(skb, length); + nh = (struct nshhdr *)(skb->data); + memcpy(nh, pushed_nh, length); + nh->np = next_proto; + + skb->protocol = htons(ETH_P_NSH); + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb_reset_mac_len(skb); + + return 0; +} +EXPORT_SYMBOL_GPL(nsh_push); + +int nsh_pop(struct sk_buff *skb) +{ + struct nshhdr *nh; + size_t length;Quoted 8 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ __be16 inner_proto; + + if (!pskb_may_pull(skb, NSH_BASE_HDR_LEN)) + return -ENOMEM; + nh = (struct nshhdr *)(skb->data); + length = nsh_hdr_len(nh); + inner_proto = tun_p_to_eth_p(nh->np);same as above, this check can be moved to flow install
__ovs_nla_copy_actions().
Quoted 3 lines
Pravin, these two functions are not only for OVS, you can see it is
net/nsh/nsh.c, Jiri and Eric mentioned they also could be used by TC.
I think it can be easily done by other caller of these function, or you can refactor the APIs itself.
Quoted 3 lines
I understand you expect some checks should be moved to slow path, but for there two cases, we can't remove them into
__ovs_nla_copy_actions.
It is not just about optimization, but having these check in flow install allows OVS userspace to probe level of NSH support in datapath.
A message that is not in the archive (sent off-list or not yet received): CAOrHB_COGWb78kN70QFKgA3w5v3zasAW=TJbzoE5zZYKao_GvA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 6 lines · Pravin Shelar
Quoted 6 lines
net/nsh/nsh.c +6
-0+int nsh_push (struct sk_buff *skb,const struct nshhdr *pushed_nh) +{ +struct nshhdr *nh; +size_t length =nsh_hdr_len (pushed_nh); +u8 next_proto; +
Quoted 8 lines
net/nsh/nsh.c line 28
Quoted 6 lines
net/nsh/nsh.c +6
-0+if (skb->mac_len) { + next_proto =TUN_P_ETHERNET ; + }else { + next_proto =tun_p_from_eth_p (skb->protocol); +if (!next_proto) +return -EAFNOSUPPORT ;check for supported protocols can be moved to flow install validation in
__ovs_nla_copy_actions().
You mean the check for !next_proto? It needs to be present for correctness of nsh_push. This function has to be self contained, it will be used by more callers than opevswitch, namely tc.
It's actually not so much a check for "supported protocols", it's rather a check of return value of a function that converts ethertype to a 1 byte tunnel type. Blindly using a result of a function that may return error would be wrong. Openvswitch is free to perform additional checks but this needs to stay.
Quoted 4 lines
Quoted 4 lines
net/nsh/nsh.c +4
-0+int nsh_pop (struct sk_buff *skb) +{ +struct nshhdr *nh; +size_t length;
Quoted 8 lines
net/nsh/nsh.c line 59
Quoted 7 lines
net/nsh/nsh.c +7
-0+__be16 inner_proto; + +if (!pskb_may_pull (skb,NSH_BASE_HDR_LEN )) +return -ENOMEM ; + nh = (struct nshhdr *)(skb->data); + length =nsh_hdr_len (nh); + inner_proto =tun_p_to_eth_p (nh->np);same as above, this check can be moved to flow install
__ovs_nla_copy_actions().
There's no check here.
Quoted 5 lines
net/nsh/nsh.c line 64
Quoted 5 lines
net/nsh/nsh.c +5
-0+if (!pskb_may_pull (skb, length)) +return -ENOMEM ; + +if (!inner_proto) +return -EAFNOSUPPORT ;
Did you mean this one instead? Then see above, this has to stay.
Jiri
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 20 lines · Jiri Benc
Quoted 6 lines · Pravin Shelar
Quoted 6 lines
net/nsh/nsh.c +6
-0+int nsh_push (struct sk_buff *skb,const struct nshhdr *pushed_nh) +{ +struct nshhdr *nh; +size_t length =nsh_hdr_len (pushed_nh); +u8 next_proto; +Quoted 8 lines
net/nsh/nsh.c line 28
Quoted 6 lines
net/nsh/nsh.c +6
-0+if (skb->mac_len) { + next_proto =TUN_P_ETHERNET ; + }else { + next_proto =tun_p_from_eth_p (skb->protocol); +if (!next_proto) +return -EAFNOSUPPORT ;check for supported protocols can be moved to flow install validation in
__ovs_nla_copy_actions().You mean the check for !next_proto? It needs to be present for correctness of
nsh_push. This function has to be self contained, it will be used by more callers than opevswitch, namely tc.
Quoted 6 lines
It's actually not so much a check for "supported protocols", it's rather a check of return value of a function that converts ethertype to a 1 byte tunnel type. Blindly using a result of a function that may return error would be wrong. Openvswitch is free to perform additional checks but this needs to stay.
I am not disputing validity of the checks, but it could be done at flow install phase.
For other use case we could refactor code. If it is too complex, I am fine with duplicate code that check the protocol in flow install for now.
Quoted 24 lines
Quoted 4 lines
Quoted 4 lines
net/nsh/nsh.c +4
-0+int nsh_pop (struct sk_buff *skb) +{ +struct nshhdr *nh; +size_t length;Quoted 8 lines
net/nsh/nsh.c line 59
Quoted 7 lines
net/nsh/nsh.c +7
-0+__be16 inner_proto; + +if (!pskb_may_pull (skb,NSH_BASE_HDR_LEN )) +return -ENOMEM ; + nh = (struct nshhdr *)(skb->data); + length =nsh_hdr_len (nh); + inner_proto =tun_p_to_eth_p (nh->np);same as above, this check can be moved to flow install
__ovs_nla_copy_actions().There's no check here.
Quoted 5 lines
net/nsh/nsh.c line 64
Quoted 5 lines
net/nsh/nsh.c +5
-0+if (!pskb_may_pull (skb, length)) +return -ENOMEM ; + +if (!inner_proto) +return -EAFNOSUPPORT ;Did you mean this one instead? Then see above, this has to stay.
Jiri
Quoted 27 lines · Pravin Shelar
Quoted 20 lines · Jiri Benc
Quoted 6 lines · Pravin Shelar
Quoted 6 lines
(quoted diff) +6
-0+int nsh_push(struct sk_buff *skb, const struct nshhdr *pushed_nh) +{ + struct nshhdr *nh; + size_t length = nsh_hdr_len(pushed_nh); + u8 next_proto; +Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ if (skb->mac_len) { + next_proto = TUN_P_ETHERNET; + } else { + next_proto = tun_p_from_eth_p(skb->protocol); + if (!next_proto) + return -EAFNOSUPPORT;check for supported protocols can be moved to flow install validation in
__ovs_nla_copy_actions().You mean the check for !next_proto? It needs to be present for correctness of
nsh_push. This function has to be self contained, it will be used by more callers than opevswitch, namely tc.Quoted 6 lines
It's actually not so much a check for "supported protocols", it's rather a check of return value of a function that converts ethertype to a 1 byte tunnel type. Blindly using a result of a function that may return error would be wrong. Openvswitch is free to perform additional checks but this needs to stay.
Quoted 5 lines
I am not disputing validity of the checks, but it could be done at flow install phase.
For other use case we could refactor code. If it is too complex, I am fine with duplicate code that check the protocol in flow install for now.
Ok, I'll add check code in __ovs_nla_copy_actions for both nsh_push and nsh_pop, but how can we get value of skb->protocol in __ovs_nla_copy_actions? Is it argument eth_type of __ovs_nla_copy_actions?
Quoted 25 lines
Quoted 25 lines
Quoted 13 lines
Review
Quoted 12 lines
(quoted diff) +11
-0+int nsh_pop(struct sk_buff *skb) +{ + struct nshhdr *nh; + size_t length; + __be16 inner_proto; + + if (!pskb_may_pull(skb, NSH_BASE_HDR_LEN)) + return -ENOMEM; + nh = (struct nshhdr *)(skb->data); + length = nsh_hdr_len(nh); + inner_proto = tun_p_to_eth_p(nh->np);same as above, this check can be moved to flow install
__ovs_nla_copy_actions().There's no check here.
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (!pskb_may_pull(skb, length)) + return -ENOMEM; + + if (!inner_proto) + return -EAFNOSUPPORT;Did you mean this one instead? Then see above, this has to stay.
Jiri
A message that is not in the archive (sent off-list or not yet received): 20171107112833.GA56179-re2EX8HDrk21gSHoDXDV2kEOCMrvLtNR@public.gmane.org
Quoted 34 lines · Yi
Quoted 27 lines · Pravin Shelar
Quoted 20 lines · Jiri Benc
Quoted 6 lines · Pravin Shelar
Quoted 6 lines
(quoted diff) +6
-0+int nsh_push(struct sk_buff *skb, const struct nshhdr *pushed_nh) +{ + struct nshhdr *nh; + size_t length = nsh_hdr_len(pushed_nh); + u8 next_proto; +Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ if (skb->mac_len) { + next_proto = TUN_P_ETHERNET; + } else { + next_proto = tun_p_from_eth_p(skb->protocol); + if (!next_proto) + return -EAFNOSUPPORT;check for supported protocols can be moved to flow install validation in
__ovs_nla_copy_actions().You mean the check for !next_proto? It needs to be present for correctness of
nsh_push. This function has to be self contained, it will be used by more callers than opevswitch, namely tc.Quoted 6 lines
It's actually not so much a check for "supported protocols", it's rather a check of return value of a function that converts ethertype to a 1 byte tunnel type. Blindly using a result of a function that may return error would be wrong. Openvswitch is free to perform additional checks but this needs to stay.
Quoted 5 lines
I am not disputing validity of the checks, but it could be done at flow install phase.
For other use case we could refactor code. If it is too complex, I am fine with duplicate code that check the protocol in flow install for now.
Quoted 5 lines
Ok, I'll add check code in
__ovs_nla_copy_actionsfor bothnsh_pushandnsh_pop, but how can we get value ofskb->protocolin__ovs_nla_copy_actions? Is it argumenteth_typeof__ovs_nla_copy_actions?
Yes.
A message that is not in the archive (sent off-list or not yet received): CAOrHB_D2khYGGJxNA8hpE4Qnhm7ONKrH=kcNteV=iYWLRnaGHQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 35 lines · Pravin Shelar
Quoted 34 lines · Yi
Quoted 32 lines · Pravin Shelar
Quoted 20 lines · Jiri Benc
Quoted 6 lines · Pravin Shelar
Quoted 6 lines
(quoted diff) +6
-0+int nsh_push(struct sk_buff *skb, const struct nshhdr *pushed_nh) +{ + struct nshhdr *nh; + size_t length = nsh_hdr_len(pushed_nh); + u8 next_proto; +Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ if (skb->mac_len) { + next_proto = TUN_P_ETHERNET; + } else { + next_proto = tun_p_from_eth_p(skb->protocol); + if (!next_proto) + return -EAFNOSUPPORT;check for supported protocols can be moved to flow install validation in
__ovs_nla_copy_actions().You mean the check for !next_proto? It needs to be present for correctness of
nsh_push. This function has to be self contained, it will be used by more callers than opevswitch, namely tc.Quoted 6 lines
It's actually not so much a check for "supported protocols", it's rather a check of return value of a function that converts ethertype to a 1 byte tunnel type. Blindly using a result of a function that may return error would be wrong. Openvswitch is free to perform additional checks but this needs to stay.
I am not disputing validity of the checks, but it could be done at flow install phase.
For other use case we could refactor code. If it is too complex, I am fine with duplicate code that check the protocol in flow install for now.
Quoted 6 lines
Quoted 5 lines
Ok, I'll add check code in
__ovs_nla_copy_actionsfor bothnsh_pushandnsh_pop, but how can we get value ofskb->protocolin__ovs_nla_copy_actions? Is it argumenteth_typeof__ovs_nla_copy_actions?Yes.
So here is newly-added check code, is it ok?
net/openvswitch/flow_netlink.c +16 -2
@@ -3001,20 +3001,34 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, mac_proto =MAC_PROTO_ETHERNET ;break ; -case OVS_ACTION_ATTR_PUSH_NSH : +case OVS_ACTION_ATTR_PUSH_NSH : { +u8 next_proto; + +if (mac_proto !=MAC_PROTO_ETHERNET ) { + next_proto =tun_p_from_eth_p (eth_type); +if (!next_proto) +return -EINVAL ; + } mac_proto =MAC_PROTO_NONE ;if (!validate_nsh (nla_data (a), false, true, true))return -EINVAL ;break ; + } + +case OVS_ACTION_ATTR_POP_NSH : { +__be16 inner_proto; -case OVS_ACTION_ATTR_POP_NSH :if (eth_type !=htons (ETH_P_NSH ))return -EINVAL ; + inner_proto =tun_p_to_eth_p (key->nsh.base.np); +if (!inner_proto) +return -EINVAL ;if (key->nsh.base.np ==TUN_P_ETHERNET ) mac_proto =MAC_PROTO_ETHERNET ;else mac_proto =MAC_PROTO_NONE ;break ; + }default :OVS_NLERR (log,"Unknown Action type %d" , type);
Quoted 50 lines · Yi
Quoted 35 lines · Pravin Shelar
Quoted 34 lines · Yi
Quoted 32 lines · Pravin Shelar
Quoted 20 lines · Jiri Benc
Quoted 6 lines · Pravin Shelar
Quoted 6 lines
(quoted diff) +6
-0+int nsh_push(struct sk_buff *skb, const struct nshhdr *pushed_nh) +{ + struct nshhdr *nh; + size_t length = nsh_hdr_len(pushed_nh); + u8 next_proto; +Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ if (skb->mac_len) { + next_proto = TUN_P_ETHERNET; + } else { + next_proto = tun_p_from_eth_p(skb->protocol); + if (!next_proto) + return -EAFNOSUPPORT;check for supported protocols can be moved to flow install validation in
__ovs_nla_copy_actions().You mean the check for !next_proto? It needs to be present for correctness of
nsh_push. This function has to be self contained, it will be used by more callers than opevswitch, namely tc.Quoted 6 lines
It's actually not so much a check for "supported protocols", it's rather a check of return value of a function that converts ethertype to a 1 byte tunnel type. Blindly using a result of a function that may return error would be wrong. Openvswitch is free to perform additional checks but this needs to stay.
I am not disputing validity of the checks, but it could be done at flow install phase.
For other use case we could refactor code. If it is too complex, I am fine with duplicate code that check the protocol in flow install for now.Quoted 6 lines
Quoted 5 lines
Ok, I'll add check code in
__ovs_nla_copy_actionsfor bothnsh_pushandnsh_pop, but how can we get value ofskb->protocolin__ovs_nla_copy_actions? Is it argumenteth_typeof__ovs_nla_copy_actions?Yes.
So here is newly-added check code, is it ok?
net/openvswitch/flow_netlink.c +0
-0
net/openvswitch/flow_netlink.c static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, · line 3006
Quoted 7 lines
net/openvswitch/flow_netlink.c +3
-1@@ -3001,20 +3001,34 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, mac_proto =MAC_PROTO_ETHERNET ;break ; -case OVS_ACTION_ATTR_PUSH_NSH : +case OVS_ACTION_ATTR_PUSH_NSH : { +u8 next_proto; +
next_proto can be moved to the if () block, otherwise, I am fine with this change.
Quoted 29 lines
net/openvswitch/flow_netlink.c +13
-1+if (mac_proto !=MAC_PROTO_ETHERNET ) { + next_proto =tun_p_from_eth_p (eth_type); +if (!next_proto) +return -EINVAL ; + } mac_proto =MAC_PROTO_NONE ;if (!validate_nsh (nla_data (a), false, true, true))return -EINVAL ;break ; + } + +case OVS_ACTION_ATTR_POP_NSH : { +__be16 inner_proto; -case OVS_ACTION_ATTR_POP_NSH :if (eth_type !=htons (ETH_P_NSH ))return -EINVAL ; + inner_proto =tun_p_to_eth_p (key->nsh.base.np); +if (!inner_proto) +return -EINVAL ;if (key->nsh.base.np ==TUN_P_ETHERNET ) mac_proto =MAC_PROTO_ETHERNET ;else mac_proto =MAC_PROTO_NONE ;break ; + }default :OVS_NLERR (log,"Unknown Action type %d" , type);
Quoted 48 lines · Pravin Shelar
Quoted 47 lines · Yi
Quoted 29 lines · Pravin Shelar
Quoted 28 lines · Yi
Quoted 26 lines · Pravin Shelar
Quoted 14 lines · Jiri Benc
Quoted 8 lines · Pravin Shelar
Review
Quoted 6 lines
(quoted diff) +6
-0+ if (skb->mac_len) { + next_proto = TUN_P_ETHERNET; + } else { + next_proto = tun_p_from_eth_p(skb->protocol); + if (!next_proto) + return -EAFNOSUPPORT;check for supported protocols can be moved to flow install validation in
__ovs_nla_copy_actions().You mean the check for !next_proto? It needs to be present for correctness of
nsh_push. This function has to be self contained, it will be used by more callers than opevswitch, namely tc.Quoted 6 lines
It's actually not so much a check for "supported protocols", it's rather a check of return value of a function that converts ethertype to a 1 byte tunnel type. Blindly using a result of a function that may return error would be wrong. Openvswitch is free to perform additional checks but this needs to stay.
I am not disputing validity of the checks, but it could be done at flow install phase.
For other use case we could refactor code. If it is too complex, I am fine with duplicate code that check the protocol in flow install for now.Quoted 6 lines
Quoted 5 lines
Ok, I'll add check code in
__ovs_nla_copy_actionsfor bothnsh_pushandnsh_pop, but how can we get value ofskb->protocolin__ovs_nla_copy_actions? Is it argumenteth_typeof__ovs_nla_copy_actions?Yes.
So here is newly-added check code, is it ok?
net/openvswitch/flow_netlink.c +0
-0@@ -3001,20 +3001,34 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, mac_proto =MAC_PROTO_ETHERNET ;break ;
Quoted 6 lines
net/openvswitch/flow_netlink.c static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, · line 3006
Quoted 4 lines
net/openvswitch/flow_netlink.c +3
-1-case OVS_ACTION_ATTR_PUSH_NSH : +case OVS_ACTION_ATTR_PUSH_NSH : { +u8 next_proto; +
next_protocan be moved to the if () block, otherwise, I am fine with this change.
Thanks, fixed it and sent out v17.