Commit 5968250c868ceee680aa77395b24e6ddcae17d36

Authored by Jiri Pirko
Committed by David S. Miller
1 parent 62749e2cb3

vlan: introduce *vlan_hwaccel_push_inside helpers

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>

Showing 7 changed files with 51 additions and 44 deletions Side-by-side Diff

... ... @@ -1599,15 +1599,10 @@
1599 1599 if (unlikely(err))
1600 1600 return err;
1601 1601  
1602   - if (vlan_tx_tag_present(skb)) {
1603   - skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
1604   - vlan_tx_tag_get(skb));
1605   - if (WARN_ON(!skb))
1606   - return -ENOMEM;
  1602 + skb = vlan_hwaccel_push_inside(skb);
  1603 + if (WARN_ON(!skb))
  1604 + return -ENOMEM;
1607 1605  
1608   - skb->vlan_tci = 0;
1609   - }
1610   -
1611 1606 vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
1612 1607 vxh->vx_flags = htonl(VXLAN_FLAGS);
1613 1608 vxh->vx_vni = vni;
... ... @@ -1643,14 +1638,9 @@
1643 1638 if (unlikely(err))
1644 1639 return err;
1645 1640  
1646   - if (vlan_tx_tag_present(skb)) {
1647   - skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
1648   - vlan_tx_tag_get(skb));
1649   - if (WARN_ON(!skb))
1650   - return -ENOMEM;
1651   -
1652   - skb->vlan_tci = 0;
1653   - }
  1641 + skb = vlan_hwaccel_push_inside(skb);
  1642 + if (WARN_ON(!skb))
  1643 + return -ENOMEM;
1654 1644  
1655 1645 vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
1656 1646 vxh->vx_flags = htonl(VXLAN_FLAGS);
include/linux/if_vlan.h
... ... @@ -341,6 +341,40 @@
341 341 return skb;
342 342 }
343 343  
  344 +/*
  345 + * __vlan_hwaccel_push_inside - pushes vlan tag to the payload
  346 + * @skb: skbuff to tag
  347 + *
  348 + * Pushes the VLAN tag from @skb->vlan_tci inside to the payload.
  349 + *
  350 + * Following the skb_unshare() example, in case of error, the calling function
  351 + * doesn't have to worry about freeing the original skb.
  352 + */
  353 +static inline struct sk_buff *__vlan_hwaccel_push_inside(struct sk_buff *skb)
  354 +{
  355 + skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
  356 + vlan_tx_tag_get(skb));
  357 + if (likely(skb))
  358 + skb->vlan_tci = 0;
  359 + return skb;
  360 +}
  361 +/*
  362 + * vlan_hwaccel_push_inside - pushes vlan tag to the payload
  363 + * @skb: skbuff to tag
  364 + *
  365 + * Checks is tag is present in @skb->vlan_tci and if it is, it pushes the
  366 + * VLAN tag from @skb->vlan_tci inside to the payload.
  367 + *
  368 + * Following the skb_unshare() example, in case of error, the calling function
  369 + * doesn't have to worry about freeing the original skb.
  370 + */
  371 +static inline struct sk_buff *vlan_hwaccel_push_inside(struct sk_buff *skb)
  372 +{
  373 + if (vlan_tx_tag_present(skb))
  374 + skb = __vlan_hwaccel_push_inside(skb);
  375 + return skb;
  376 +}
  377 +
344 378 /**
345 379 * __vlan_hwaccel_put_tag - hardware accelerated VLAN inserting
346 380 * @skb: skbuff to tag
... ... @@ -2644,12 +2644,8 @@
2644 2644 netdev_features_t features)
2645 2645 {
2646 2646 if (vlan_tx_tag_present(skb) &&
2647   - !vlan_hw_offload_capable(features, skb->vlan_proto)) {
2648   - skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
2649   - vlan_tx_tag_get(skb));
2650   - if (skb)
2651   - skb->vlan_tci = 0;
2652   - }
  2647 + !vlan_hw_offload_capable(features, skb->vlan_proto))
  2648 + skb = __vlan_hwaccel_push_inside(skb);
2653 2649 return skb;
2654 2650 }
2655 2651  
... ... @@ -79,8 +79,7 @@
79 79  
80 80 if (vlan_tx_tag_present(skb) &&
81 81 !vlan_hw_offload_capable(features, skb->vlan_proto)) {
82   - skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
83   - vlan_tx_tag_get(skb));
  82 + skb = __vlan_hwaccel_push_inside(skb);
84 83 if (unlikely(!skb)) {
85 84 /* This is actually a packet drop, but we
86 85 * don't want the code that calls this
... ... @@ -88,7 +87,6 @@
88 87 */
89 88 goto out;
90 89 }
91   - skb->vlan_tci = 0;
92 90 }
93 91  
94 92 status = netdev_start_xmit(skb, dev, txq, false);
... ... @@ -131,14 +131,9 @@
131 131 if (unlikely(err))
132 132 return err;
133 133  
134   - if (vlan_tx_tag_present(skb)) {
135   - skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
136   - vlan_tx_tag_get(skb));
137   - if (unlikely(!skb)
138   - return -ENOMEM;
139   -
140   - skb->vlan_tci = 0;
141   - }
  134 + skb = vlan_hwaccel_push_inside(skb);
  135 + if (unlikely(!skb))
  136 + return -ENOMEM;
142 137  
143 138 gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len);
144 139 geneve_build_header(gnvh, tun_flags, vni, opt_len, opt);
net/openvswitch/datapath.c
... ... @@ -425,12 +425,10 @@
425 425 if (!nskb)
426 426 return -ENOMEM;
427 427  
428   - nskb = vlan_insert_tag_set_proto(nskb, nskb->vlan_proto,
429   - vlan_tx_tag_get(nskb));
  428 + nskb = __vlan_hwaccel_push_inside(nskb);
430 429 if (!nskb)
431 430 return -ENOMEM;
432 431  
433   - nskb->vlan_tci = 0;
434 432 skb = nskb;
435 433 }
436 434  
net/openvswitch/vport-gre.c
... ... @@ -175,14 +175,10 @@
175 175 goto err_free_rt;
176 176 }
177 177  
178   - if (vlan_tx_tag_present(skb)) {
179   - skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
180   - vlan_tx_tag_get(skb));
181   - if (unlikely(!skb) {
182   - err = -ENOMEM;
183   - goto err_free_rt;
184   - }
185   - skb->vlan_tci = 0;
  178 + skb = vlan_hwaccel_push_inside(skb);
  179 + if (unlikely(!skb)) {
  180 + err = -ENOMEM;
  181 + goto err_free_rt;
186 182 }
187 183  
188 184 /* Push Tunnel header. */