Skip to content

Commit

Permalink
xfrm: change secpath_set to return secpath struct, not error value
Browse files Browse the repository at this point in the history
It can only return 0 (success) or -ENOMEM.
Change return value to a pointer to secpath struct.

This avoids direct access to skb->sp:

err = secpath_set(skb);
if (!err) ..
skb->sp-> ...

Becomes:
sp = secpath_set(skb)
if (!sp) ..
sp-> ..

This reduces noise in followup patch which is going to remove skb->sp.

Signed-off-by: Florian Westphal <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Florian Westphal authored and davem330 committed Dec 19, 2018
1 parent de8bda1 commit 0ca64da
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion include/net/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ secpath_put(struct sec_path *sp)
}

struct sec_path *secpath_dup(struct sec_path *src);
int secpath_set(struct sk_buff *skb);
struct sec_path *secpath_set(struct sk_buff *skb);

static inline void
secpath_reset(struct sk_buff *skb)
Expand Down
11 changes: 6 additions & 5 deletions net/ipv4/esp4_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head,

xo = xfrm_offload(skb);
if (!xo || !(xo->flags & CRYPTO_DONE)) {
err = secpath_set(skb);
if (err)
struct sec_path *sp = secpath_set(skb);

if (!sp)
goto out;

if (skb->sp->len == XFRM_MAX_DEPTH)
if (sp->len == XFRM_MAX_DEPTH)
goto out;

x = xfrm_state_lookup(dev_net(skb->dev), skb->mark,
Expand All @@ -59,8 +60,8 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head,
if (!x)
goto out;

skb->sp->xvec[skb->sp->len++] = x;
skb->sp->olen++;
sp->xvec[sp->len++] = x;
sp->olen++;

xo = xfrm_offload(skb);
if (!xo) {
Expand Down
11 changes: 6 additions & 5 deletions net/ipv6/esp6_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head,

xo = xfrm_offload(skb);
if (!xo || !(xo->flags & CRYPTO_DONE)) {
err = secpath_set(skb);
if (err)
struct sec_path *sp = secpath_set(skb);

if (!sp)
goto out;

if (skb->sp->len == XFRM_MAX_DEPTH)
if (sp->len == XFRM_MAX_DEPTH)
goto out;

x = xfrm_state_lookup(dev_net(skb->dev), skb->mark,
Expand All @@ -81,8 +82,8 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head,
if (!x)
goto out;

skb->sp->xvec[skb->sp->len++] = x;
skb->sp->olen++;
sp->xvec[sp->len++] = x;
sp->olen++;

xo = xfrm_offload(skb);
if (!xo) {
Expand Down
6 changes: 4 additions & 2 deletions net/ipv6/xfrm6_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
{
struct net *net = dev_net(skb->dev);
struct xfrm_state *x = NULL;
struct sec_path *sp;
int i = 0;

if (secpath_set(skb)) {
sp = secpath_set(skb);
if (!sp) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
goto drop;
}

if (1 + skb->sp->len == XFRM_MAX_DEPTH) {
if (1 + sp->len == XFRM_MAX_DEPTH) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
goto drop;
}
Expand Down
16 changes: 9 additions & 7 deletions net/xfrm/xfrm_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,22 @@ struct sec_path *secpath_dup(struct sec_path *src)
}
EXPORT_SYMBOL(secpath_dup);

int secpath_set(struct sk_buff *skb)
struct sec_path *secpath_set(struct sk_buff *skb)
{
struct sec_path *sp;
struct sec_path *sp = skb->sp;

/* Allocate new secpath or COW existing one. */
if (!skb->sp || refcount_read(&skb->sp->refcnt) != 1) {
if (!sp || refcount_read(&sp->refcnt) != 1) {
sp = secpath_dup(skb->sp);
if (!sp)
return -ENOMEM;
return NULL;

if (skb->sp)
secpath_put(skb->sp);
skb->sp = sp;
}
return 0;

return sp;
}
EXPORT_SYMBOL(secpath_set);

Expand Down Expand Up @@ -236,6 +237,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
bool xfrm_gro = false;
bool crypto_done = false;
struct xfrm_offload *xo = xfrm_offload(skb);
struct sec_path *sp;

if (encap_type < 0) {
x = xfrm_input_state(skb);
Expand Down Expand Up @@ -312,8 +314,8 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
break;
}

err = secpath_set(skb);
if (err) {
sp = secpath_set(skb);
if (!sp) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
goto drop;
}
Expand Down

0 comments on commit 0ca64da

Please sign in to comment.