Commit a84e3f53 authored by Florian Westphal's avatar Florian Westphal Committed by David S. Miller

xfrm: prefer secpath_set over secpath_dup

secpath_set is a wrapper for secpath_dup that will not perform
an allocation if the secpath attached to the skb has a reference count
of one, i.e., it doesn't need to be COW'ed.

Also, secpath_dup doesn't attach the secpath to the skb, it leaves
this to the caller.

Use secpath_set in places that immediately assign the return value to
skb.

This allows to remove skb->sp without touching these spots again.

secpath_dup can eventually be removed in followup patch.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a053c866
...@@ -1161,6 +1161,7 @@ void ixgbe_ipsec_rx(struct ixgbe_ring *rx_ring, ...@@ -1161,6 +1161,7 @@ void ixgbe_ipsec_rx(struct ixgbe_ring *rx_ring,
struct xfrm_state *xs = NULL; struct xfrm_state *xs = NULL;
struct ipv6hdr *ip6 = NULL; struct ipv6hdr *ip6 = NULL;
struct iphdr *ip4 = NULL; struct iphdr *ip4 = NULL;
struct sec_path *sp;
void *daddr; void *daddr;
__be32 spi; __be32 spi;
u8 *c_hdr; u8 *c_hdr;
...@@ -1200,12 +1201,12 @@ void ixgbe_ipsec_rx(struct ixgbe_ring *rx_ring, ...@@ -1200,12 +1201,12 @@ void ixgbe_ipsec_rx(struct ixgbe_ring *rx_ring,
if (unlikely(!xs)) if (unlikely(!xs))
return; return;
skb->sp = secpath_dup(skb->sp); sp = secpath_set(skb);
if (unlikely(!skb->sp)) if (unlikely(!sp))
return; return;
skb->sp->xvec[skb->sp->len++] = xs; sp->xvec[sp->len++] = xs;
skb->sp->olen++; sp->olen++;
xo = xfrm_offload(skb); xo = xfrm_offload(skb);
xo->flags = CRYPTO_DONE; xo->flags = CRYPTO_DONE;
xo->status = CRYPTO_SUCCESS; xo->status = CRYPTO_SUCCESS;
......
...@@ -548,6 +548,7 @@ void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring, ...@@ -548,6 +548,7 @@ void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring,
struct xfrm_state *xs = NULL; struct xfrm_state *xs = NULL;
struct ipv6hdr *ip6 = NULL; struct ipv6hdr *ip6 = NULL;
struct iphdr *ip4 = NULL; struct iphdr *ip4 = NULL;
struct sec_path *sp;
void *daddr; void *daddr;
__be32 spi; __be32 spi;
u8 *c_hdr; u8 *c_hdr;
...@@ -587,12 +588,12 @@ void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring, ...@@ -587,12 +588,12 @@ void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring,
if (unlikely(!xs)) if (unlikely(!xs))
return; return;
skb->sp = secpath_dup(skb->sp); sp = secpath_set(skb);
if (unlikely(!skb->sp)) if (unlikely(!sp))
return; return;
skb->sp->xvec[skb->sp->len++] = xs; sp->xvec[sp->len++] = xs;
skb->sp->olen++; sp->olen++;
xo = xfrm_offload(skb); xo = xfrm_offload(skb);
xo->flags = CRYPTO_DONE; xo->flags = CRYPTO_DONE;
xo->status = CRYPTO_SUCCESS; xo->status = CRYPTO_SUCCESS;
......
...@@ -307,10 +307,11 @@ mlx5e_ipsec_build_sp(struct net_device *netdev, struct sk_buff *skb, ...@@ -307,10 +307,11 @@ mlx5e_ipsec_build_sp(struct net_device *netdev, struct sk_buff *skb,
struct mlx5e_priv *priv = netdev_priv(netdev); struct mlx5e_priv *priv = netdev_priv(netdev);
struct xfrm_offload *xo; struct xfrm_offload *xo;
struct xfrm_state *xs; struct xfrm_state *xs;
struct sec_path *sp;
u32 sa_handle; u32 sa_handle;
skb->sp = secpath_dup(skb->sp); sp = secpath_set(skb);
if (unlikely(!skb->sp)) { if (unlikely(!sp)) {
atomic64_inc(&priv->ipsec->sw_stats.ipsec_rx_drop_sp_alloc); atomic64_inc(&priv->ipsec->sw_stats.ipsec_rx_drop_sp_alloc);
return NULL; return NULL;
} }
...@@ -322,8 +323,9 @@ mlx5e_ipsec_build_sp(struct net_device *netdev, struct sk_buff *skb, ...@@ -322,8 +323,9 @@ mlx5e_ipsec_build_sp(struct net_device *netdev, struct sk_buff *skb,
return NULL; return NULL;
} }
skb->sp->xvec[skb->sp->len++] = xs; sp = skb_sec_path(skb);
skb->sp->olen++; sp->xvec[sp->len++] = xs;
sp->olen++;
xo = xfrm_offload(skb); xo = xfrm_offload(skb);
xo->flags = CRYPTO_DONE; xo->flags = CRYPTO_DONE;
......
...@@ -5,6 +5,7 @@ config XFRM ...@@ -5,6 +5,7 @@ config XFRM
bool bool
depends on NET depends on NET
select GRO_CELLS select GRO_CELLS
select SKB_EXTENSIONS
config XFRM_OFFLOAD config XFRM_OFFLOAD
bool bool
......
...@@ -218,19 +218,16 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb) ...@@ -218,19 +218,16 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
if (xfrm_dev_offload_ok(skb, x)) { if (xfrm_dev_offload_ok(skb, x)) {
struct sec_path *sp; struct sec_path *sp;
sp = secpath_dup(skb->sp); sp = secpath_set(skb);
if (!sp) { if (!sp) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR); XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
kfree_skb(skb); kfree_skb(skb);
return -ENOMEM; return -ENOMEM;
} }
if (skb->sp)
secpath_put(skb->sp);
skb->sp = sp;
skb->encapsulation = 1; skb->encapsulation = 1;
sp->olen++; sp->olen++;
sp->xvec[skb->sp->len++] = x; sp->xvec[sp->len++] = x;
xfrm_state_hold(x); xfrm_state_hold(x);
if (skb_is_gso(skb)) { if (skb_is_gso(skb)) {
......
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