openvswitch: make vlan handling consistent
Subsystems (3)
v2 cover openvswitch: make vlan handling consistent
Always keep the first vlan tag "accelerated", i.e. in skb->vlan_tci. This simplifies things considerably.
v2: added the first patch
Jiri Benc (3):
openvswitch: normalize vlan rx path
openvswitch: remove unreachable code in vlan parsing
openvswitch: fix vlan subtraction from packet length
net/openvswitch/datapath.c | 10 ++++++++++ net/openvswitch/flow.c | 28 ++++++++-------------------- net/openvswitch/vport.c | 10 +++------- 3 files changed, 21 insertions(+), 27 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/3 openvswitch: normalize vlan rx path
Similarly to how the core networking stack behaves, let the first vlan tag be always stored in skb->vlan_tci. This is already ensured in __netif_receive_skb_core for packets that were received from the kernel and honored by skb_vlan_push and skb_vlan_pop. The only remaining place are packets received from the user space. Just do the same things with vlan frames as __netif_receive_skb_core does.
--- net/openvswitch/datapath.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/openvswitch/datapath.c +10 -0
@@ -594,6 +594,16 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)else packet->protocol =htons (ETH_P_802_2 ); +if (eth_type_vlan (packet->protocol)) { +__skb_pull (packet,ETH_HLEN ); +skb_reset_network_header (packet); +skb_reset_mac_len (packet); + packet =skb_vlan_untag (packet); +if (unlikely (!packet)) + goto err; +skb_push (packet,ETH_HLEN ); + } +/* Set packet's mru */ if (a[OVS_PACKET_ATTR_MRU ]) { mru =nla_get_u16 (a[OVS_PACKET_ATTR_MRU ]);
Signature · 1 line
1.8.3.1
Re: [PATCH net-next v2 1/3] openvswitch: normalize vlan rx path
Hi,
Quoted 5 lines · Jiri Benc
net/openvswitch/datapath.c +0
-0
net/openvswitch/datapath.c static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) · line 603
Quoted 10 lines
net/openvswitch/datapath.c +7
-0@@ -594,6 +594,16 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)else packet->protocol =htons (ETH_P_802_2 ); +if (eth_type_vlan (packet->protocol)) { +__skb_pull (packet,ETH_HLEN ); +skb_reset_network_header (packet); +skb_reset_mac_len (packet); + packet =skb_vlan_untag (packet); +if (unlikely (!packet)) + goto err;
I think at this point, 'eth' may point to a freed packet. Maybe replace the 'eth' variable with a 'proto' variable caching the value of eth_hdr(packet)->h_proto?
Quoted 9 lines
net/openvswitch/datapath.c +3
-1+skb_push (packet,ETH_HLEN ); + } +/* Set packet's mru */ if (a[OVS_PACKET_ATTR_MRU ]) { mru =nla_get_u16 (a[OVS_PACKET_ATTR_MRU ]); --1.8.3.1
Eyal.
Re: [PATCH net-next v2 1/3] openvswitch: normalize vlan rx path
Quoted 1 line · Eyal Birger
I think at this point, 'eth' may point to a freed packet.
It may but how does that matter? eth is not used beyond that point.
Jiri
Re: [PATCH net-next v2 1/3] openvswitch: normalize vlan rx path
Quoted 4 lines · Jiri Benc
Quoted 1 line · Eyal Birger
I think at this point, 'eth' may point to a freed packet.
It may but how does that matter? eth is not used beyond that point.
Definitely a nit. For sure not critical.
Just seemed less future safe to keep a pointer to an old packet lying around.
Eyal.
Re: [PATCH net-next v2 1/3] openvswitch: normalize vlan rx path
Quoted 9 lines · Eyal Birger
Quoted 4 lines · Jiri Benc
Quoted 1 line · Eyal Birger
I think at this point, 'eth' may point to a freed packet.
It may but how does that matter? eth is not used beyond that point.
Definitely a nit. For sure not critical.
Just seemed less future safe to keep a pointer to an old packet lying around.
I agree. Alternatively refresh the eth pointer.
Re: [PATCH net-next v2 1/3] openvswitch: normalize vlan rx path
Quoted 4 lines · Eric Garver
Quoted 1 line · Eyal Birger
Just seemed less future safe to keep a pointer to an old packet lying around.
I agree. Alternatively refresh the eth pointer.
Sorry guys, that just doesn't make sense. Everyone should know that reloading of skb pointer means the former pointers to its data may become invalid. Please point me to any place in the kernel where we reload the data pointer "just because" even when not used.
Jiri
Re: [PATCH net-next v2 1/3] openvswitch: normalize vlan rx path
Quoted 11 lines · Jiri Benc
Quoted 4 lines · Eric Garver
Quoted 1 line · Eyal Birger
Just seemed less future safe to keep a pointer to an old packet lying around.
I agree. Alternatively refresh the eth pointer.
Sorry guys, that just doesn't make sense. Everyone should know that reloading of skb pointer means the former pointers to its data may become invalid. Please point me to any place in the kernel where we reload the data pointer "just because" even when not used.
How about this incremental change?
net/openvswitch/datapath.c +2 -5
@@ -562,7 +562,6 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)struct sw_flow *flow;struct sw_flow_actions *sf_acts;struct datapath *dp; -struct ethhdr *eth;struct vport *input_vport;u16 mru =0 ;int len;
@@ -584,14 +583,12 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)nla_memcpy (__skb_put (packet, len), a[OVS_PACKET_ATTR_PACKET ], len);skb_reset_mac_header (packet); - eth =eth_hdr (packet);/* Normally, setting the skb 'protocol' field would be handled by a * call to eth_type_trans(), but it assumes there's a sending * device, which we may not have. */ -if (eth_proto_is_802_3 (eth->h_proto)) - packet->protocol = eth->h_proto; -else + packet->protocol =eth_hdr (packet)->h_proto; +if (!eth_proto_is_802_3 (packet->protocol)) packet->protocol =htons (ETH_P_802_2 );if (eth_type_vlan (packet->protocol)) {
Re: [PATCH net-next v2 1/3] openvswitch: normalize vlan rx path
Quoted 1 line · Eric Garver
How about this incremental change?
Feel free to submit it as a standalone patch. It has nothing to do with this patchset. In this particular regard, the code is identical before and after the patchset and is in no way altered by this patch.
Jiri
PATCH v2 2/3 openvswitch: remove unreachable code in vlan parsing
In reply to Jiri BencNow when the first vlan tag is always in skb->vlan_tci, drop code that assumed it might not be the case.
This patch also removes the wrong likely() statement around skb_vlan_tag_present introduced by 018c1dda5ff1 ("openvswitch: 802.1AD Flow handling, actions, vlan parsing, netlink attributes"). This code is called whenever flow key is being extracted from the packet, the packet may be as likely vlan tagged as not.
--- net/openvswitch/flow.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-)
net/openvswitch/flow.c +8 -20
@@ -308,9 +308,7 @@ static bool icmp6hdr_ok(struct sk_buff *skb)/** * Parse vlan tag from vlan header. -* Returns ERROR on memory error. -* Returns 0 if it encounters a non-vlan or incomplete packet. -* Returns 1 after successfully parsing vlan tag. +* Returns ERROR on memory error, 0 otherwise. */ static int parse_vlan_tag (struct sk_buff *skb,struct vlan_head *key_vh) {
@@ -331,34 +329,24 @@ static int parse_vlan_tag(struct sk_buff *skb, struct vlan_head *key_vh) key_vh->tpid = vh->tpid;__skb_pull (skb,sizeof (struct vlan_head )); -return 1 ; +return 0 ; }static int parse_vlan (struct sk_buff *skb,struct sw_flow_key *key) { -int res; - key->eth.vlan.tci =0 ; key->eth.vlan.tpid =0 ; key->eth.cvlan.tci =0 ; key->eth.cvlan.tpid =0 ; -if (likely (skb_vlan_tag_present (skb))) { - key->eth.vlan.tci =htons (skb->vlan_tci); - key->eth.vlan.tpid = skb->vlan_proto; - }else { -/* Parse outer vlan tag in the non-accelerated case. */ - res =parse_vlan_tag (skb, &key->eth.vlan); -if (res <=0 ) -return res; - } +if (!skb_vlan_tag_present (skb)) +return 0 ; -/* Parse inner vlan tag. */ - res =parse_vlan_tag (skb, &key->eth.cvlan); -if (res <=0 ) -return res; + key->eth.vlan.tci =htons (skb->vlan_tci); + key->eth.vlan.tpid = skb->vlan_proto; -return 0 ; +/* Parse inner vlan tag. */ +return parse_vlan_tag (skb, &key->eth.cvlan); }static __be16 parse_ethertype (struct sk_buff *skb)
Signature · 1 line
1.8.3.1
Re: [PATCH net-next v2 2/3] openvswitch: remove unreachable code in vlan parsing
Quoted 3 lines · Jiri Benc
Now when the first vlan tag is always in
skb->vlan_tci, drop code that assumed it might not be the case.
User can turn off TX vlan offload for OVS internal device that would allow vlan tagged packet with vlan header on the skb-data. This case will cause issue here.
We could handle this case by not allowing this configuration.
Quoted 7 lines
This patch also removes the wrong
likely()statement aroundskb_vlan_tag_presentintroduced by018c1dda5ff1("openvswitch: 802.1AD Flow handling, actions, vlan parsing, netlink attributes"). This code is called whenever flow key is being extracted from the packet, the packet may be as likely vlan tagged as not.Signed-off-by Jiri Benc <[email protected]>
Re: [PATCH net-next v2 2/3] openvswitch: remove unreachable code in vlan parsing
Quoted 3 lines · Pravin Shelar
User can turn off TX vlan offload for OVS internal device that would allow vlan tagged packet with vlan header on the skb-data. This case will cause issue here.
Good catch. This is the feedback I hoped for, not the bikesheding about a value of unused variable :-)
Quoted 1 line
We could handle this case by not allowing this configuration.
I'm not sure how clean this is but let's try and see if anyone objects. I'll send v3.
I also noticed we don't set NETIF_F_HW_VLAN_STAG_TX on internal ports. I'll fix it, too.
Thanks!
Jiri
PATCH v2 3/3 openvswitch: fix vlan subtraction from packet length
In reply to Jiri BencWhen the packet has its vlan tag in skb->vlan_tci, the length of the VLAN header is not counted in skb->len. It doesn't make sense to subtract it.
In addition, to honor the comment below the code, the VLAN header length should not be subtracted if there's a vlan tag in skb->vlan_tci. This leads to the code simply subtracting the Ethernet header length.
--- net/openvswitch/vport.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
net/openvswitch/vport.c +3 -7
@@ -483,17 +483,13 @@ EXPORT_SYMBOL_GPL(ovs_vport_deferred_free);static unsigned int packet_length (const struct sk_buff *skb) { -unsigned int length = skb->len -ETH_HLEN ; - -if (skb_vlan_tagged (skb)) - length -=VLAN_HLEN ; -/* Don't subtract for multiple VLAN tags. Most (all?) drivers allow * (ETH_LEN + VLAN_HLEN) in addition to the mtu value, but almost none * account for 802.1ad. e.g. is_skb_forwardable(). +* Note that the first VLAN tag is always in skb->vlan_tci, thus not +* accounted for in skb->len. */ - -return length; +return skb->len -ETH_HLEN ; }void ovs_vport_send (struct vport *vport,struct sk_buff *skb)
Signature · 1 line
1.8.3.1