Skip to content

Commit a67e2e8

Browse files
jpirkosashalevin
authored andcommitted
vlan: introduce *vlan_hwaccel_push_inside helpers
[ Upstream commit 5968250 ] 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>
1 parent d329729 commit a67e2e8

7 files changed

Lines changed: 51 additions & 44 deletions

File tree

‎drivers/net/vxlan.c‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,14 +1593,9 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs,
15931593
if (unlikely(err))
15941594
return err;
15951595

1596-
if (vlan_tx_tag_present(skb)) {
1597-
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
1598-
vlan_tx_tag_get(skb));
1599-
if (WARN_ON(!skb))
1600-
return -ENOMEM;
1601-
1602-
skb->vlan_tci = 0;
1603-
}
1596+
skb = vlan_hwaccel_push_inside(skb);
1597+
if (WARN_ON(!skb))
1598+
return -ENOMEM;
16041599

16051600
vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
16061601
vxh->vx_flags = htonl(VXLAN_FLAGS);
@@ -1637,14 +1632,9 @@ int vxlan_xmit_skb(struct vxlan_sock *vs,
16371632
if (unlikely(err))
16381633
return err;
16391634

1640-
if (vlan_tx_tag_present(skb)) {
1641-
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
1642-
vlan_tx_tag_get(skb));
1643-
if (WARN_ON(!skb))
1644-
return -ENOMEM;
1645-
1646-
skb->vlan_tci = 0;
1647-
}
1635+
skb = vlan_hwaccel_push_inside(skb);
1636+
if (WARN_ON(!skb))
1637+
return -ENOMEM;
16481638

16491639
vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
16501640
vxh->vx_flags = htonl(VXLAN_FLAGS);

‎include/linux/if_vlan.h‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,40 @@ static inline struct sk_buff *vlan_insert_tag_set_proto(struct sk_buff *skb,
341341
return skb;
342342
}
343343

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+
344378
/**
345379
* __vlan_hwaccel_put_tag - hardware accelerated VLAN inserting
346380
* @skb: skbuff to tag

‎net/core/dev.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,12 +2663,8 @@ static struct sk_buff *validate_xmit_vlan(struct sk_buff *skb,
26632663
netdev_features_t features)
26642664
{
26652665
if (vlan_tx_tag_present(skb) &&
2666-
!vlan_hw_offload_capable(features, skb->vlan_proto)) {
2667-
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
2668-
vlan_tx_tag_get(skb));
2669-
if (skb)
2670-
skb->vlan_tci = 0;
2671-
}
2666+
!vlan_hw_offload_capable(features, skb->vlan_proto))
2667+
skb = __vlan_hwaccel_push_inside(skb);
26722668
return skb;
26732669
}
26742670

‎net/core/netpoll.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,14 @@ static int netpoll_start_xmit(struct sk_buff *skb, struct net_device *dev,
7979

8080
if (vlan_tx_tag_present(skb) &&
8181
!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);
8483
if (unlikely(!skb)) {
8584
/* This is actually a packet drop, but we
8685
* don't want the code that calls this
8786
* function to try and operate on a NULL skb.
8887
*/
8988
goto out;
9089
}
91-
skb->vlan_tci = 0;
9290
}
9391

9492
status = netdev_start_xmit(skb, dev, txq, false);

‎net/ipv4/geneve.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,9 @@ int geneve_xmit_skb(struct geneve_sock *gs, struct rtable *rt,
131131
if (unlikely(err))
132132
return err;
133133

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;
142137

143138
gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len);
144139
geneve_build_header(gnvh, tun_flags, vni, opt_len, opt);

‎net/openvswitch/datapath.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,10 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
423423
if (!nskb)
424424
return -ENOMEM;
425425

426-
nskb = vlan_insert_tag_set_proto(nskb, nskb->vlan_proto,
427-
vlan_tx_tag_get(nskb));
426+
nskb = __vlan_hwaccel_push_inside(nskb);
428427
if (!nskb)
429428
return -ENOMEM;
430429

431-
nskb->vlan_tci = 0;
432430
skb = nskb;
433431
}
434432

‎net/openvswitch/vport-gre.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,10 @@ static int gre_tnl_send(struct vport *vport, struct sk_buff *skb)
172172
goto err_free_rt;
173173
}
174174

175-
if (vlan_tx_tag_present(skb)) {
176-
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
177-
vlan_tx_tag_get(skb));
178-
if (unlikely(!skb) {
179-
err = -ENOMEM;
180-
goto err_free_rt;
181-
}
182-
skb->vlan_tci = 0;
175+
skb = vlan_hwaccel_push_inside(skb);
176+
if (unlikely(!skb)) {
177+
err = -ENOMEM;
178+
goto err_free_rt;
183179
}
184180

185181
/* Push Tunnel header. */

0 commit comments

Comments
 (0)