]> git.hungrycats.org Git - linux/commitdiff
vlan: introduce *vlan_hwaccel_push_inside helpers
authorJiri Pirko <jiri@resnulli.us>
Wed, 19 Nov 2014 13:04:59 +0000 (14:04 +0100)
committerSasha Levin <sasha.levin@oracle.com>
Mon, 27 Apr 2015 20:48:34 +0000 (16:48 -0400)
[ Upstream commit 5968250c868ceee680aa77395b24e6ddcae17d36 ]

Use them to push skb->vlan_tci into the payload and avoid code
duplication.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
drivers/net/vxlan.c
include/linux/if_vlan.h
net/core/dev.c
net/core/netpoll.c
net/ipv4/geneve.c
net/openvswitch/datapath.c
net/openvswitch/vport-gre.c

index aa7b5af6293ef9691f541f035c261f388384040b..bcb1778bf478ff4d4bb3eee73547ce0e68a176f6 100644 (file)
@@ -1593,14 +1593,9 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs,
        if (unlikely(err))
                return err;
 
-       if (vlan_tx_tag_present(skb)) {
-               skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
-                                               vlan_tx_tag_get(skb));
-               if (WARN_ON(!skb))
-                       return -ENOMEM;
-
-               skb->vlan_tci = 0;
-       }
+       skb = vlan_hwaccel_push_inside(skb);
+       if (WARN_ON(!skb))
+               return -ENOMEM;
 
        vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
        vxh->vx_flags = htonl(VXLAN_FLAGS);
@@ -1637,14 +1632,9 @@ int vxlan_xmit_skb(struct vxlan_sock *vs,
        if (unlikely(err))
                return err;
 
-       if (vlan_tx_tag_present(skb)) {
-               skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
-                                               vlan_tx_tag_get(skb));
-               if (WARN_ON(!skb))
-                       return -ENOMEM;
-
-               skb->vlan_tci = 0;
-       }
+       skb = vlan_hwaccel_push_inside(skb);
+       if (WARN_ON(!skb))
+               return -ENOMEM;
 
        vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
        vxh->vx_flags = htonl(VXLAN_FLAGS);
index 309a06042d0ba0b7f2494a95ed6cbbce45c02ae5..3a3c4fadcc64ef99dc67228a80c0c5d9abb0c178 100644 (file)
@@ -341,6 +341,40 @@ static inline struct sk_buff *vlan_insert_tag_set_proto(struct sk_buff *skb,
        return skb;
 }
 
+/*
+ * __vlan_hwaccel_push_inside - pushes vlan tag to the payload
+ * @skb: skbuff to tag
+ *
+ * Pushes the VLAN tag from @skb->vlan_tci inside to the payload.
+ *
+ * Following the skb_unshare() example, in case of error, the calling function
+ * doesn't have to worry about freeing the original skb.
+ */
+static inline struct sk_buff *__vlan_hwaccel_push_inside(struct sk_buff *skb)
+{
+       skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
+                                       vlan_tx_tag_get(skb));
+       if (likely(skb))
+               skb->vlan_tci = 0;
+       return skb;
+}
+/*
+ * vlan_hwaccel_push_inside - pushes vlan tag to the payload
+ * @skb: skbuff to tag
+ *
+ * Checks is tag is present in @skb->vlan_tci and if it is, it pushes the
+ * VLAN tag from @skb->vlan_tci inside to the payload.
+ *
+ * Following the skb_unshare() example, in case of error, the calling function
+ * doesn't have to worry about freeing the original skb.
+ */
+static inline struct sk_buff *vlan_hwaccel_push_inside(struct sk_buff *skb)
+{
+       if (vlan_tx_tag_present(skb))
+               skb = __vlan_hwaccel_push_inside(skb);
+       return skb;
+}
+
 /**
  * __vlan_hwaccel_put_tag - hardware accelerated VLAN inserting
  * @skb: skbuff to tag
index 8a57104a17dd740dfd8294dfe1652f07db96dfe4..5cdbc1bd9783fef139b09886e21a913c6d5bfc23 100644 (file)
@@ -2663,12 +2663,8 @@ static struct sk_buff *validate_xmit_vlan(struct sk_buff *skb,
                                          netdev_features_t features)
 {
        if (vlan_tx_tag_present(skb) &&
-           !vlan_hw_offload_capable(features, skb->vlan_proto)) {
-               skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
-                                               vlan_tx_tag_get(skb));
-               if (skb)
-                       skb->vlan_tci = 0;
-       }
+           !vlan_hw_offload_capable(features, skb->vlan_proto))
+               skb = __vlan_hwaccel_push_inside(skb);
        return skb;
 }
 
index 65d372384a3fd2b6881a92b358ad8ac75292f45d..e0ad5d16c9c56947163d81201af07e26d1d3017c 100644 (file)
@@ -79,8 +79,7 @@ static int netpoll_start_xmit(struct sk_buff *skb, struct net_device *dev,
 
        if (vlan_tx_tag_present(skb) &&
            !vlan_hw_offload_capable(features, skb->vlan_proto)) {
-               skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
-                                               vlan_tx_tag_get(skb));
+               skb = __vlan_hwaccel_push_inside(skb);
                if (unlikely(!skb)) {
                        /* This is actually a packet drop, but we
                         * don't want the code that calls this
@@ -88,7 +87,6 @@ static int netpoll_start_xmit(struct sk_buff *skb, struct net_device *dev,
                         */
                        goto out;
                }
-               skb->vlan_tci = 0;
        }
 
        status = netdev_start_xmit(skb, dev, txq, false);
index 6cdcd8cbb90248e212718242d2a4db7f332d9492..fd0fe18e3e3e16cbeda1e5c6ae2dfc8b40c13b9d 100644 (file)
@@ -131,14 +131,9 @@ int geneve_xmit_skb(struct geneve_sock *gs, struct rtable *rt,
        if (unlikely(err))
                return err;
 
-       if (vlan_tx_tag_present(skb)) {
-               skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
-                                               vlan_tx_tag_get(skb));
-               if (unlikely(!skb)
-                       return -ENOMEM;
-
-               skb->vlan_tci = 0;
-       }
+       skb = vlan_hwaccel_push_inside(skb);
+       if (unlikely(!skb))
+               return -ENOMEM;
 
        gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len);
        geneve_build_header(gnvh, tun_flags, vni, opt_len, opt);
index c0ef691c150a0280c410d5288072afadef53e16b..28213dff723de6d1d07f6d724a47f955bb4c63e9 100644 (file)
@@ -423,12 +423,10 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
                if (!nskb)
                        return -ENOMEM;
 
-               nskb = vlan_insert_tag_set_proto(nskb, nskb->vlan_proto,
-                                                vlan_tx_tag_get(nskb));
+               nskb = __vlan_hwaccel_push_inside(nskb);
                if (!nskb)
                        return -ENOMEM;
 
-               nskb->vlan_tci = 0;
                skb = nskb;
        }
 
index d2f2658e23481699a212d455d35106132869fa1c..e88fa34b004188f3ff8496a948913daf031c3b88 100644 (file)
@@ -172,14 +172,10 @@ static int gre_tnl_send(struct vport *vport, struct sk_buff *skb)
                        goto err_free_rt;
        }
 
-       if (vlan_tx_tag_present(skb)) {
-               skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
-                                               vlan_tx_tag_get(skb));
-               if (unlikely(!skb) {
-                       err = -ENOMEM;
-                       goto err_free_rt;
-               }
-               skb->vlan_tci = 0;
+       skb = vlan_hwaccel_push_inside(skb);
+       if (unlikely(!skb)) {
+               err = -ENOMEM;
+               goto err_free_rt;
        }
 
        /* Push Tunnel header. */