[ovs-dev] [PATCH v2 3/4] datapath: backport: vlan: Check for vlan ethernet types for 8021.q or 802.1ad

Eric Garver e at erig.me
Thu Feb 9 15:36:47 UTC 2017


On Mon, Feb 06, 2017 at 08:36:50PM +0800, Yi Yang wrote:
>     commit fe19c4f971a55cea3be442d8032a5f6021702791
>     Author: Eric Garver <e at erig.me>
>     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 <thomasfherbert at gmail.com>
>     Signed-off-by: Eric Garver <e at erig.me>
>     Acked-by: Pravin B Shelar <pshelar at ovn.org>
>     Signed-off-by: David S. Miller <davem at davemloft.net>
> 
> Signed-off-by: Yi Yang <yi.y.yang at intel.com>
> ---
>  acinclude.m4                                  |  1 +
>  datapath/linux/compat/include/linux/if_vlan.h | 24 +++++++++++++++++++++---
>  2 files changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/acinclude.m4 b/acinclude.m4
> index 9166da8..f219bec 100644
> --- a/acinclude.m4
> +++ b/acinclude.m4
> @@ -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])
>  
> diff --git a/datapath/linux/compat/include/linux/if_vlan.h b/datapath/linux/compat/include/linux/if_vlan.h
> index c8ddef1..ff55fb8 100644
> --- a/datapath/linux/compat/include/linux/if_vlan.h
> +++ b/datapath/linux/compat/include/linux/if_vlan.h
> @@ -100,6 +100,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
> @@ -188,7 +207,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;
> @@ -206,8 +225,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)

I think you can also take the hunks for skb_vlan_tagged() and
skb_vlan_tagged_multi() since you add them in the previous patch.

__vlan_get_tag() isn't in the OVS datapath, so that hunk can be omitted.


More information about the dev mailing list