[ovs-dev] [PATCH v3 1/5] datapath: backport: vlan: Introduce helper functions to check if skb is tagged

Yi Yang yi.y.yang at intel.com
Mon Feb 13 02:39:12 UTC 2017


    commit f5a7fb88e1f82542ca14ba93a1d4fa35471c60ca
    Author: Toshiaki Makita <makita.toshiaki at lab.ntt.co.jp>
    Date:   Fri Mar 27 14:31:11 2015 +0900

    vlan: Introduce helper functions to check if skb is tagged

    Separate the two checks for single vlan and multiple vlans in
    netif_skb_features().  This allows us to move the check for multiple
    vlans to another function later.

    Signed-off-by: Toshiaki Makita <makita.toshiaki at lab.ntt.co.jp>
    Signed-off-by: David S. Miller <davem at davemloft.net>

Signed-off-by: Yi Yang <yi.y.yang at intel.com>
Acked-by: Eric Garver <e at erig.me>
---
 acinclude.m4                                  |  1 +
 datapath/linux/compat/include/linux/if_vlan.h | 49 +++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/acinclude.m4 b/acinclude.m4
index e8b64b5..9166da8 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -663,6 +663,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
   OVS_GREP_IFELSE([$KSRC/include/linux/if_vlan.h], [vlan_insert_tag_set_proto])
   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/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 a8d7bfa..c8ddef1 100644
--- a/datapath/linux/compat/include/linux/if_vlan.h
+++ b/datapath/linux/compat/include/linux/if_vlan.h
@@ -229,4 +229,53 @@ static inline __be16 vlan_get_protocol(struct sk_buff *skb)
 }
 
 #endif
+
+#ifndef HAVE_SKB_VLAN_TAGGED
+/**
+ * skb_vlan_tagged - check if skb is vlan tagged.
+ * @skb: skbuff to query
+ *
+ * Returns true if the skb is tagged, regardless of whether it is hardware
+ * accelerated or not.
+ */
+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)))
+		return false;
+
+	return true;
+}
+
+/**
+ * skb_vlan_tagged_multi - check if skb is vlan tagged with multiple headers.
+ * @skb: skbuff to query
+ *
+ * Returns true if the skb is tagged with multiple vlan headers, regardless
+ * of whether it is hardware accelerated or not.
+ */
+static inline bool skb_vlan_tagged_multi(const struct sk_buff *skb)
+{
+	__be16 protocol = skb->protocol;
+
+	if (!skb_vlan_tag_present(skb)) {
+		struct vlan_ethhdr *veh;
+
+		if (likely(protocol != htons(ETH_P_8021Q) &&
+			   protocol != htons(ETH_P_8021AD)))
+			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))
+		return false;
+
+	return true;
+}
+
+#endif /* HAVE_SKB_VLAN_TAGGED */
+
 #endif	/* linux/if_vlan.h wrapper */
-- 
2.1.0



More information about the dev mailing list