Commit 5968250c authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

vlan: introduce *vlan_hwaccel_push_inside helpers

Use them to push skb->vlan_tci into the payload and avoid code
duplication.
Signed-off-by: default avatarJiri Pirko <jiri@resnulli.us>
Acked-by: default avatarPravin B Shelar <pshelar@nicira.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 62749e2c
...@@ -1599,14 +1599,9 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs, ...@@ -1599,14 +1599,9 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs,
if (unlikely(err)) if (unlikely(err))
return err; return err;
if (vlan_tx_tag_present(skb)) { skb = vlan_hwaccel_push_inside(skb);
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto, if (WARN_ON(!skb))
vlan_tx_tag_get(skb)); return -ENOMEM;
if (WARN_ON(!skb))
return -ENOMEM;
skb->vlan_tci = 0;
}
vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh)); vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
vxh->vx_flags = htonl(VXLAN_FLAGS); vxh->vx_flags = htonl(VXLAN_FLAGS);
...@@ -1643,14 +1638,9 @@ int vxlan_xmit_skb(struct vxlan_sock *vs, ...@@ -1643,14 +1638,9 @@ int vxlan_xmit_skb(struct vxlan_sock *vs,
if (unlikely(err)) if (unlikely(err))
return err; return err;
if (vlan_tx_tag_present(skb)) { skb = vlan_hwaccel_push_inside(skb);
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto, if (WARN_ON(!skb))
vlan_tx_tag_get(skb)); return -ENOMEM;
if (WARN_ON(!skb))
return -ENOMEM;
skb->vlan_tci = 0;
}
vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh)); vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
vxh->vx_flags = htonl(VXLAN_FLAGS); vxh->vx_flags = htonl(VXLAN_FLAGS);
......
...@@ -341,6 +341,40 @@ static inline struct sk_buff *vlan_insert_tag_set_proto(struct sk_buff *skb, ...@@ -341,6 +341,40 @@ static inline struct sk_buff *vlan_insert_tag_set_proto(struct sk_buff *skb,
return 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 * __vlan_hwaccel_put_tag - hardware accelerated VLAN inserting
* @skb: skbuff to tag * @skb: skbuff to tag
......
...@@ -2644,12 +2644,8 @@ static struct sk_buff *validate_xmit_vlan(struct sk_buff *skb, ...@@ -2644,12 +2644,8 @@ static struct sk_buff *validate_xmit_vlan(struct sk_buff *skb,
netdev_features_t features) netdev_features_t features)
{ {
if (vlan_tx_tag_present(skb) && if (vlan_tx_tag_present(skb) &&
!vlan_hw_offload_capable(features, skb->vlan_proto)) { !vlan_hw_offload_capable(features, skb->vlan_proto))
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto, skb = __vlan_hwaccel_push_inside(skb);
vlan_tx_tag_get(skb));
if (skb)
skb->vlan_tci = 0;
}
return skb; return skb;
} }
......
...@@ -79,8 +79,7 @@ static int netpoll_start_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -79,8 +79,7 @@ static int netpoll_start_xmit(struct sk_buff *skb, struct net_device *dev,
if (vlan_tx_tag_present(skb) && if (vlan_tx_tag_present(skb) &&
!vlan_hw_offload_capable(features, skb->vlan_proto)) { !vlan_hw_offload_capable(features, skb->vlan_proto)) {
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto, skb = __vlan_hwaccel_push_inside(skb);
vlan_tx_tag_get(skb));
if (unlikely(!skb)) { if (unlikely(!skb)) {
/* This is actually a packet drop, but we /* This is actually a packet drop, but we
* don't want the code that calls this * 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, ...@@ -88,7 +87,6 @@ static int netpoll_start_xmit(struct sk_buff *skb, struct net_device *dev,
*/ */
goto out; goto out;
} }
skb->vlan_tci = 0;
} }
status = netdev_start_xmit(skb, dev, txq, false); status = netdev_start_xmit(skb, dev, txq, false);
......
...@@ -131,14 +131,9 @@ int geneve_xmit_skb(struct geneve_sock *gs, struct rtable *rt, ...@@ -131,14 +131,9 @@ int geneve_xmit_skb(struct geneve_sock *gs, struct rtable *rt,
if (unlikely(err)) if (unlikely(err))
return err; return err;
if (vlan_tx_tag_present(skb)) { skb = vlan_hwaccel_push_inside(skb);
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto, if (unlikely(!skb))
vlan_tx_tag_get(skb)); return -ENOMEM;
if (unlikely(!skb)
return -ENOMEM;
skb->vlan_tci = 0;
}
gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len); gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len);
geneve_build_header(gnvh, tun_flags, vni, opt_len, opt); geneve_build_header(gnvh, tun_flags, vni, opt_len, opt);
......
...@@ -425,12 +425,10 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, ...@@ -425,12 +425,10 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
if (!nskb) if (!nskb)
return -ENOMEM; return -ENOMEM;
nskb = vlan_insert_tag_set_proto(nskb, nskb->vlan_proto, nskb = __vlan_hwaccel_push_inside(nskb);
vlan_tx_tag_get(nskb));
if (!nskb) if (!nskb)
return -ENOMEM; return -ENOMEM;
nskb->vlan_tci = 0;
skb = nskb; skb = nskb;
} }
......
...@@ -175,14 +175,10 @@ static int gre_tnl_send(struct vport *vport, struct sk_buff *skb) ...@@ -175,14 +175,10 @@ static int gre_tnl_send(struct vport *vport, struct sk_buff *skb)
goto err_free_rt; goto err_free_rt;
} }
if (vlan_tx_tag_present(skb)) { skb = vlan_hwaccel_push_inside(skb);
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto, if (unlikely(!skb)) {
vlan_tx_tag_get(skb)); err = -ENOMEM;
if (unlikely(!skb) { goto err_free_rt;
err = -ENOMEM;
goto err_free_rt;
}
skb->vlan_tci = 0;
} }
/* Push Tunnel header. */ /* Push Tunnel header. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment