datapath: Add __vlan_insert_tag() compat helper if not available
[cascardo/ovs.git] / datapath / linux / compat / include / linux / if_vlan.h
index dc4b15e..28c4dae 100644 (file)
@@ -5,8 +5,10 @@
 #include <linux/version.h>
 #include_next <linux/if_vlan.h>
 
+#ifndef HAVE_VLAN_INSERT_TAG_SET_PROTO
 /*
- * The behavior of __vlan_put_tag() has changed over time:
+ * The behavior of __vlan_put_tag()/vlan_insert_tag_set_proto() has changed
+ * over time:
  *
  *      - In 2.6.26 and earlier, it adjusted both MAC and network header
  *        pointers.  (The latter didn't make any sense.)
  *
  *      - In 2.6.29 and later, it adjusts the MAC header pointer only.
  *
+ *      - In 3.19 and later, it was renamed to vlan_insert_tag_set_proto()
+ *
  * This is the version from 2.6.33.  We unconditionally substitute this version
  * to avoid the need to guess whether the version in the kernel tree is
  * acceptable.
  */
-#define __vlan_put_tag rpl_vlan_put_tag
-static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, u16 vlan_tci)
+#define vlan_insert_tag_set_proto(skb, proto, vlan_tci) \
+       rpl_vlan_insert_tag_set_proto(skb, vlan_tci)
+static inline struct sk_buff *rpl_vlan_insert_tag_set_proto(struct sk_buff *skb,
+                                                           u16 vlan_tci)
 {
        struct vlan_ethhdr *veth;
 
@@ -44,7 +50,18 @@ static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, u16 vlan_tci)
 
        return skb;
 }
+#endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
+static inline struct sk_buff *rpl___vlan_hwaccel_put_tag(struct sk_buff *skb,
+                                                    __be16 vlan_proto,
+                                                    u16 vlan_tci)
+{
+       return __vlan_hwaccel_put_tag(skb, vlan_tci);
+}
+
+#define __vlan_hwaccel_put_tag rpl___vlan_hwaccel_put_tag
+#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. */
@@ -55,7 +72,7 @@ static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, u16 vlan_tci)
 #define VLAN_TAG_PRESENT       VLAN_CFI_MASK
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)
+#ifndef HAVE_VLAN_SET_ENCAP_PROTO
 static inline void vlan_set_encap_proto(struct sk_buff *skb, struct vlan_hdr *vhdr)
 {
        __be16 proto;
@@ -89,4 +106,33 @@ static inline void vlan_set_encap_proto(struct sk_buff *skb, struct vlan_hdr *vh
                skb->protocol = htons(ETH_P_802_2);
 }
 #endif
+
+#ifndef HAVE___VLAN_INSERT_TAG
+/* Kernels which don't have __vlan_insert_tag() also don't have skb->vlan_proto
+ * so ignore the proto paramter.
+ */
+#define __vlan_insert_tag(skb, proto, tci) rpl_vlan_insert_tag(skb, tci)
+static inline int rpl_vlan_insert_tag(struct sk_buff *skb, u16 vlan_tci)
+{
+       struct vlan_ethhdr *veth;
+
+       if (skb_cow_head(skb, VLAN_HLEN) < 0)
+               return -ENOMEM;
+
+       veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
+
+       /* Move the mac addresses to the beginning of the new header. */
+       memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
+       skb->mac_header -= VLAN_HLEN;
+
+       /* first, the ethernet type */
+       veth->h_vlan_proto = htons(ETH_P_8021Q);
+
+       /* now, the TCI */
+       veth->h_vlan_TCI = htons(ETH_P_8021Q);
+
+       return 0;
+}
+#endif
+
 #endif /* linux/if_vlan.h wrapper */