Skip to content

Commit

Permalink
datapath: backport: vlan: Check for vlan ethernet types for 8021.q or…
Browse files Browse the repository at this point in the history
… 802.1ad

Upstream commit:
    commit fe19c4f971a55cea3be442d8032a5f6021702791
    Author: Eric Garver <[email protected]>
    Date:   Wed Sep 7 12:56:58 2016 -0400

    This is to simplify using double tagged vlans. This function allows all
    valid vlan ethertypes to be checked in a single function call.
    Also replace some instances that check for both ETH_P_8021Q and
    ETH_P_8021AD.

    Patch based on one originally by Thomas F Herbert.

    Signed-off-by: Thomas F Herbert <[email protected]>
    Signed-off-by: Eric Garver <[email protected]>
    Acked-by: Pravin B Shelar <[email protected]>
    Signed-off-by: David S. Miller <[email protected]>

Signed-off-by: Yi Yang <[email protected]>
Acked-by: Eric Garver <[email protected]>
Signed-off-by: Joe Stringer <[email protected]>
  • Loading branch information
yi-y-yang authored and joestringer committed Mar 2, 2017
1 parent 051f4b4 commit ca6da1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
OVS_GREP_IFELSE([$KSRC/include/linux/if_vlan.h], [__vlan_insert_tag])
OVS_GREP_IFELSE([$KSRC/include/linux/if_vlan.h], [vlan_get_protocol])
OVS_GREP_IFELSE([$KSRC/include/linux/if_vlan.h], [skb_vlan_tagged])
OVS_GREP_IFELSE([$KSRC/include/linux/if_vlan.h], [eth_type_vlan])
OVS_GREP_IFELSE([$KSRC/include/linux/u64_stats_sync.h], [u64_stats_fetch_begin_irq])
Expand Down
32 changes: 24 additions & 8 deletions datapath/linux/compat/include/linux/if_vlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ static inline struct sk_buff *rpl___vlan_hwaccel_put_tag(struct sk_buff *skb,
#define __vlan_hwaccel_put_tag rpl___vlan_hwaccel_put_tag
#endif

#ifndef HAVE_ETH_TYPE_VLAN
/**
* eth_type_vlan - check for valid vlan ether type.
* @ethertype: ether type to check
*
* Returns true if the ether type is a vlan ether type.
*/
static inline bool eth_type_vlan(__be16 ethertype)
{
switch (ethertype) {
case htons(ETH_P_8021Q):
case htons(ETH_P_8021AD):
return true;
default:
return false;
}
}
#endif

/* All of these were introduced in a single commit preceding 2.6.33, so
* presumably all of them or none of them are present. */
#ifndef VLAN_PRIO_MASK
Expand Down Expand Up @@ -189,7 +208,7 @@ static inline __be16 __vlan_get_protocol(struct sk_buff *skb, __be16 type,
* present at mac_len - VLAN_HLEN (if mac_len > 0), or at
* ETH_HLEN otherwise
*/
if (type == htons(ETH_P_8021Q) || type == htons(ETH_P_8021AD)) {
if (eth_type_vlan(type)) {
if (vlan_depth) {
if (WARN_ON(vlan_depth < VLAN_HLEN))
return 0;
Expand All @@ -207,8 +226,7 @@ static inline __be16 __vlan_get_protocol(struct sk_buff *skb, __be16 type,
vh = (struct vlan_hdr *)(skb->data + vlan_depth);
type = vh->h_vlan_encapsulated_proto;
vlan_depth += VLAN_HLEN;
} while (type == htons(ETH_P_8021Q) ||
type == htons(ETH_P_8021AD));
} while (eth_type_vlan(type));
}

if (depth)
Expand Down Expand Up @@ -242,8 +260,7 @@ static inline __be16 vlan_get_protocol(struct sk_buff *skb)
static inline bool skb_vlan_tagged(const struct sk_buff *skb)
{
if (!skb_vlan_tag_present(skb) &&
likely(skb->protocol != htons(ETH_P_8021Q) &&
skb->protocol != htons(ETH_P_8021AD)))
likely(!eth_type_vlan(skb->protocol)))
return false;

return true;
Expand All @@ -263,15 +280,14 @@ static inline bool skb_vlan_tagged_multi(const struct sk_buff *skb)
if (!skb_vlan_tag_present(skb)) {
struct vlan_ethhdr *veh;

if (likely(protocol != htons(ETH_P_8021Q) &&
protocol != htons(ETH_P_8021AD)))
if (likely(!eth_type_vlan(protocol)))
return false;

veh = (struct vlan_ethhdr *)skb->data;
protocol = veh->h_vlan_encapsulated_proto;
}

if (protocol != htons(ETH_P_8021Q) && protocol != htons(ETH_P_8021AD))
if (!eth_type_vlan(protocol))
return false;

return true;
Expand Down

0 comments on commit ca6da1b

Please sign in to comment.