openvswitch: enable NSH support
Subsystems (3)
PATCH v11 1/1 openvswitch: enable NSH support
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 | 109 ++++++++++++++ net/openvswitch/flow.c | 51 +++++++ net/openvswitch/flow.h | 7 + net/openvswitch/flow_netlink.c | 317 ++++++++++++++++++++++++++++++++++++++- net/openvswitch/flow_netlink.h | 5 + 9 files changed, 580 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 *nh); +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 +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 +109 -0
139 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 +316 -1
409 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
A message that is not in the archive (sent off-list or not yet received): 1506668610-18505-1-git-send-email-yi.y.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Quoted 7 lines · Yi Yang
include/net/nsh.h +1
-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 *nh);
[...]
Quoted 1 line
+int
skb_push_nsh(struct sk_buff *skb, const struct nshhdr *src_nsh_hdr)
This is minor but since this patch will need a respin anyway, please name the variables in the forward declaration and here the same.
include/net/nsh.h
Quoted 4 lines
include/net/nsh.h +4
-0+int skb_pop_nsh (struct sk_buff *skb) +{ +int err; +struct nshhdr *nsh_hdr = (struct nshhdr *)(skb->data);
Bad name of the variable, clashes with the nsh_hdr function. I pointed that out already.
include/net/nsh.h
Quoted 5 lines
include/net/nsh.h +5
-0+size_t length; +__be16 inner_proto; + + err =skb_ensure_writable (skb,skb_network_offset (skb) + +sizeof (struct nshhdr ));
You assume that the skb starts at the NSH header, thus the skb_network_offset is completely unnecessary and introduces just another assumption on the caller. Also, the sizeof(struct nshhdr) is
wrong: there's no guarantee that the header is not smaller or larger than that.
More importantly though, why do you need skb_ensure_writable? You don't write into the header. pkskb_may_pull is enough.
if (!pskb_may_pull(skb, NSH_BASE_HDR_LEN)) return -ENOMEM; length = nsh_hdr_len(nsh_hdr); if (!pskb_may_pull(skb, length)) return -ENOMEM;
Quoted 8 lines
include/net/nsh.h +8
-0+static int set_nsh (struct sk_buff *skb,struct sw_flow_key *flow_key, +const struct nlattr *a) +{ +struct nshhdr *nh; +int err; +u8 flags; +u8 ttl; +int i;
include/net/nsh.h
Quoted 10 lines
include/net/nsh.h +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 ));
I missed this before: this is wrong, too. You need to use the real header size, not sizeof(struct nshhdr). It should be computable from the flow key.
include/net/nsh.h
Quoted 7 lines
include/net/nsh.h +7
-0+case OVS_ACTION_ATTR_PUSH_NSH : { +u8 buffer[NSH_HDR_MAX_LEN ]; +struct nshhdr *nh = (struct nshhdr *)buffer; + +nsh_hdr_from_nlattr (nla_data (a), nh, +NSH_HDR_MAX_LEN ); + err =push_nsh (skb, key, (const struct nshhdr *)nh);
Is the cast to const really needed? It looks suspicious. If you added it because a compiler complained, it's even more suspicious.
Quoted 13 lines
include/net/nsh.h +13
-0+static int parse_nsh (struct sk_buff *skb,struct sw_flow_key *key) +{ +struct nshhdr *nh; +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; + + nh =nsh_hdr (skb); + version =nsh_get_ver (nh);
include/net/nsh.h
Quoted 10 lines
include/net/nsh.h +10
-0+ length =nsh_hdr_len (nh); + +if (version !=0 ) +return -EINVAL ; + + err =check_header (skb, nh_ofs + length); +if (unlikely (err)) +return err; + + nh = (struct nshhdr *)skb_network_header (skb);
I really really really hate this. This is the third time I'm telling you to use the nsh_hdr function. Every time, you change only part of the places. And this one I even explicitly pointed out in the previous review.
I'm not supposed to look at my previous review to verify that you addressed everything. That's your responsibility. Yet I need to do it because every time, some of my comments remain unaddressed.
Quoted 21 lines
include/net/nsh.h +21
-0+int nsh_hdr_from_nlattr (const struct nlattr *attr, +struct nshhdr *nh,size_t size) +{ +struct nlattr *a; +int rem; +u8 flags =0 ; +u8 ttl =0 ; +int mdlen =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 =nla_data (a); + + flags = base->flags; + ttl = base->ttl; + nh->np = base->np;
include/net/nsh.h
Quoted 10 lines
include/net/nsh.h +10
-0+ nh->mdtype = base->mdtype; + nh->path_hdr = base->path_hdr; +break ; + } +case OVS_NSH_KEY_ATTR_MD1 : { +const struct ovs_nsh_key_md1 *md1 =nla_data (a); + + mdlen =nla_len (a); +memcpy (&nh->md1, md1, mdlen); +break ;
Looks better. Why not simplify it even more?
case OVS_NSH_KEY_ATTR_MD1: mdlen = nla_len(a); memcpy(&nh->md1, nla_data(a), mdlen); break;
It's still perfectly readable this way and there's no need for the braces.
include/net/nsh.h
Quoted 6 lines
include/net/nsh.h +6
-0+ } +case OVS_NSH_KEY_ATTR_MD2 : { +const struct u8 *md2 =nla_data (a); + + mdlen =nla_len (a); +memcpy (&nh->md2, md2, mdlen);
And here, too.
Quoted 13 lines
include/net/nsh.h +13
-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; + +/* 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 : {
include/net/nsh.h
Quoted 10 lines
include/net/nsh.h +10
-0+const struct ovs_nsh_key_base *base =nla_data (a); +const struct ovs_nsh_key_base *base_mask = base +1 ; + + nsh->base = *base; + nsh_mask->base = *base_mask; +break ; + } +case OVS_NSH_KEY_ATTR_MD1 : { +const struct ovs_nsh_key_md1 *md1 = + (struct ovs_nsh_key_md1 *)nla_data (a);
I'm speechless.
Yes, I don't like the line above. For a reason that I already pointed out.
I expected more of this version.
Jiri
Quoted 7 lines · Jiri Benc
Quoted 6 lines · Yi Yang
include/net/nsh.h +0
-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); }
Quoted 7 lines
Quoted 1 line
include/net/nsh.h +1
-0+int skb_push_nsh (struct sk_buff *skb,const struct nshhdr *nh);[...]
Quoted 1 line
+int
skb_push_nsh(struct sk_buff *skb, const struct nshhdr *src_nsh_hdr)This is minor but since this patch will need a respin anyway, please name the variables in the forward declaration and here the same.
Sorry for late reply, I was taking vacation from Oct. 1 to Oct. 8. I will change "nh" and "src_nsh_hdr" to "pushed_nsh" because there is another nh inside of skb_push_nsh.
Quoted 8 lines
include/net/nsh.h
Quoted 5 lines
include/net/nsh.h +4
-0+int skb_pop_nsh (struct sk_buff *skb) +{ +int err; +struct nshhdr *nsh_hdr = (struct nshhdr *)(skb->data);Bad name of the variable, clashes with the
nsh_hdrfunction. I pointed that out already.
Sorry for missing this, I just did change in one .c file, forgot to do the same thing in other .c files.
Quoted 13 lines
include/net/nsh.h
Quoted 6 lines
include/net/nsh.h +5
-0+size_t length; +__be16 inner_proto; + + err =skb_ensure_writable (skb,skb_network_offset (skb) + +sizeof (struct nshhdr ));You assume that the skb starts at the NSH header, thus the
skb_network_offsetis completely unnecessary and introduces just another assumption on the caller. Also, the sizeof(struct nshhdr) is
wrong: there's no guarantee that the header is not smaller or larger than that.
Quoted 9 lines
More importantly though, why do you need
skb_ensure_writable? You don't write into the header.pkskb_may_pullis enough.if (!pskb_may_pull(skb, NSH_BASE_HDR_LEN)) return -ENOMEM; length = nsh_hdr_len(nsh_hdr); if (!pskb_may_pull(skb, length)) return -ENOMEM;
Thank you for pointing out this, your version is the best one.
Quoted 14 lines
Quoted 14 lines
include/net/nsh.h +14
-0+static int set_nsh (struct sk_buff *skb,struct sw_flow_key *flow_key, +const struct nlattr *a) +{ +struct nshhdr *nh; +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)
Quoted 8 lines
include/net/nsh.h
Quoted 4 lines
include/net/nsh.h +4
-0+return err; + + err =skb_ensure_writable (skb,skb_network_offset (skb) + +sizeof (struct nshhdr ));I missed this before: this is wrong, too. You need to use the real header size, not sizeof(struct nshhdr). It should be computable from the flow key.
It will be better to use code you provided above.
Quoted 11 lines
include/net/nsh.h
Quoted 8 lines
include/net/nsh.h +7
-0+case OVS_ACTION_ATTR_PUSH_NSH : { +u8 buffer[NSH_HDR_MAX_LEN ]; +struct nshhdr *nh = (struct nshhdr *)buffer; + +nsh_hdr_from_nlattr (nla_data (a), nh, +NSH_HDR_MAX_LEN ); + err =push_nsh (skb, key, (const struct nshhdr *)nh);Is the cast to const really needed? It looks suspicious. If you added it because a compiler complained, it's even more suspicious.
You're right, it is ok after I remove "(const struct nshhdr *)".
Quoted 30 lines
Quoted 14 lines
include/net/nsh.h +13
-0+static int parse_nsh (struct sk_buff *skb,struct sw_flow_key *key) +{ +struct nshhdr *nh; +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; + + nh =nsh_hdr (skb); + version =nsh_get_ver (nh);include/net/nsh.h
Quoted 10 lines
include/net/nsh.h +10
-0+ length =nsh_hdr_len (nh); + +if (version !=0 ) +return -EINVAL ; + + err =check_header (skb, nh_ofs + length); +if (unlikely (err)) +return err; + + nh = (struct nshhdr *)skb_network_header (skb);I really really really hate this. This is the third time I'm telling you to use the
nsh_hdrfunction. Every time, you change only part of the places. And this one I even explicitly pointed out in the previous review.
Quoted 3 lines
I'm not supposed to look at my previous review to verify that you addressed everything. That's your responsibility. Yet I need to do it because every time, some of my comments remain unaddressed.
Sorry, it is a missing change, accumulated comments overwhelmed this.
Quoted 44 lines
Quoted 22 lines
include/net/nsh.h +21
-0+int nsh_hdr_from_nlattr (const struct nlattr *attr, +struct nshhdr *nh,size_t size) +{ +struct nlattr *a; +int rem; +u8 flags =0 ; +u8 ttl =0 ; +int mdlen =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 =nla_data (a); + + flags = base->flags; + ttl = base->ttl; + nh->np = base->np;include/net/nsh.h
Quoted 10 lines
include/net/nsh.h +10
-0+ nh->mdtype = base->mdtype; + nh->path_hdr = base->path_hdr; +break ; + } +case OVS_NSH_KEY_ATTR_MD1 : { +const struct ovs_nsh_key_md1 *md1 =nla_data (a); + + mdlen =nla_len (a); +memcpy (&nh->md1, md1, mdlen); +break ;Looks better. Why not simplify it even more?
case OVS_NSH_KEY_ATTR_MD1: mdlen = nla_len(a); memcpy(&nh->md1, nla_data(a), mdlen); break;It's still perfectly readable this way and there's no need for the braces.
Quoted 8 lines
include/net/nsh.h
Quoted 6 lines
include/net/nsh.h +6
-0+ } +case OVS_NSH_KEY_ATTR_MD2 : { +const struct u8 *md2 =nla_data (a); + + mdlen =nla_len (a); +memcpy (&nh->md2, md2, mdlen);And here, too.
Yes, the code you provided is better.
Quoted 27 lines
Quoted 14 lines
include/net/nsh.h +13
-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; + +/* 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 : {include/net/nsh.h
Quoted 10 lines
include/net/nsh.h +10
-0+const struct ovs_nsh_key_base *base =nla_data (a); +const struct ovs_nsh_key_base *base_mask = base +1 ; + + nsh->base = *base; + nsh_mask->base = *base_mask; +break ; + } +case OVS_NSH_KEY_ATTR_MD1 : { +const struct ovs_nsh_key_md1 *md1 = + (struct ovs_nsh_key_md1 *)nla_data (a);I'm speechless.
Quoted 4 lines
Yes, I don't like the line above. For a reason that I already pointed out.
I expected more of this version.
Sorry, these are also missing changes, I remember I did global change about this comment, it is my bad.
Here is incremental patch against v11, I'll send out v12 if you haven't more comments about this.
include/net/nsh.h +1 -1
@@ -304,7 +304,7 @@ NSH_FLAGS_MASK | NSH_TTL_MASK | NSH_LEN_MASK); } -int skb_push_nsh (struct sk_buff *skb,const struct nshhdr *nh); +int skb_push_nsh (struct sk_buff *skb,const struct nshhdr *pushed_nh);int skb_pop_nsh (struct sk_buff *skb);#endif /* __NET_NSH_H */
net/nsh/nsh.c +16 -14
@@ -14,10 +14,10 @@#include <net/nsh.h> #include <net/tun_proto.h> -int skb_push_nsh (struct sk_buff *skb,const struct nshhdr *src_nsh_hdr) +int skb_push_nsh (struct sk_buff *skb,const struct nshhdr *pushed_nh) { -struct nshhdr *nsh_hdr; -size_t length =nsh_hdr_len (src_nsh_hdr); +struct nshhdr *nh; +size_t length =nsh_hdr_len (pushed_nh);u8 next_proto;if (skb->mac_len) {
@@ -33,9 +33,9 @@return -ENOMEM ;skb_push (skb, length); - nsh_hdr = (struct nshhdr *)(skb->data); -memcpy (nsh_hdr, src_nsh_hdr, length); - nsh_hdr->np = next_proto; + 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);
@@ -48,21 +48,23 @@int skb_pop_nsh (struct sk_buff *skb) { -int err; -struct nshhdr *nsh_hdr = (struct nshhdr *)(skb->data); +struct nshhdr *nh;size_t length;__be16 inner_proto; - err =skb_ensure_writable (skb,skb_network_offset (skb) + -sizeof (struct nshhdr )); -if (unlikely (err)) -return err; +if (!pskb_may_pull (skb,NSH_BASE_HDR_LEN )) +return -ENOMEM ; + nh = (struct nshhdr *)(skb->data); + length =nsh_hdr_len (nh); +if (!pskb_may_pull (skb, length)) +return -ENOMEM ; - inner_proto =tun_p_to_eth_p (nsh_hdr->np); + nh = (struct nshhdr *)(skb->data); + inner_proto =tun_p_to_eth_p (nh->np);if (!inner_proto)return -EAFNOSUPPORT ; - length =nsh_hdr_len (nsh_hdr); + length =nsh_hdr_len (nh);skb_pull (skb, length);skb_reset_mac_header (skb);skb_reset_network_header (skb);
net/openvswitch/actions.c +12 -2
@@ -644,6 +644,7 @@ const struct nlattr *a) {struct nshhdr *nh; +size_t length;int err;u8 flags;u8 ttl;
@@ -656,13 +657,22 @@if (err)return err; +/* Make sure the NSH base header is there */ err =skb_ensure_writable (skb,skb_network_offset (skb) + -sizeof (struct nshhdr )); +NSH_BASE_HDR_LEN );if (unlikely (err))return err; 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;
@@ -1312,7 +1322,7 @@nsh_hdr_from_nlattr (nla_data (a), nh,NSH_HDR_MAX_LEN ); - err =push_nsh (skb, key, (const struct nshhdr *)nh); + err =push_nsh (skb, key, nh);break ; }
net/openvswitch/flow.c +1 -1
@@ -513,7 +513,7 @@if (unlikely (err))return err; - nh = (struct nshhdr *)skb_network_header (skb); + nh =nsh_hdr (skb); key->nsh.base.flags =nsh_get_flags (nh); key->nsh.base.ttl =nsh_get_ttl (nh); key->nsh.base.mdtype = nh->mdtype;
net/openvswitch/flow_netlink.c +8 -15
@@ -1233,20 +1233,16 @@ nh->path_hdr = base->path_hdr;break ; } -case OVS_NSH_KEY_ATTR_MD1 : { -const struct ovs_nsh_key_md1 *md1 =nla_data (a); - +case OVS_NSH_KEY_ATTR_MD1 : mdlen =nla_len (a); -memcpy (&nh->md1, md1, mdlen); +memcpy (&nh->md1,nla_data (a), mdlen);break ; - } -case OVS_NSH_KEY_ATTR_MD2 : { -const struct u8 *md2 =nla_data (a); +case OVS_NSH_KEY_ATTR_MD2 : mdlen =nla_len (a); -memcpy (&nh->md2, md2, mdlen); +memcpy (&nh->md2,nla_data (a), mdlen);break ; - } +default :return -EINVAL ; }
@@ -1280,8 +1276,7 @@break ; }case OVS_NSH_KEY_ATTR_MD1 : { -const struct ovs_nsh_key_md1 *md1 = - (struct ovs_nsh_key_md1 *)nla_data (a); +const struct ovs_nsh_key_md1 *md1 =nla_data (a);const struct ovs_nsh_key_md1 *md1_mask = md1 +1 ;memcpy (nsh->context, md1->context,sizeof (*md1));
@@ -1339,8 +1334,7 @@switch (type) {case OVS_NSH_KEY_ATTR_BASE : { -const struct ovs_nsh_key_base *base = - (struct ovs_nsh_key_base *)nla_data (a); +const struct ovs_nsh_key_base *base =nla_data (a); has_base = true; mdtype = base->mdtype;
@@ -1357,8 +1351,7 @@break ; }case OVS_NSH_KEY_ATTR_MD1 : { -const struct ovs_nsh_key_md1 *md1 = - (struct ovs_nsh_key_md1 *)nla_data (a); +const struct ovs_nsh_key_md1 *md1 =nla_data (a); has_md1 = true;for (i =0 ; i <NSH_MD1_CONTEXT_SIZE ; i++)