Skip to content

Commit 45b018b

Browse files
committed
ipsec: Create and use new helpers for dst child access.
This will make a future change moving the dst->child pointer less invasive. Signed-off-by: David S. Miller <[email protected]> Reviewed-by: Eric Dumazet <[email protected]>
1 parent b92cf4a commit 45b018b

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

include/net/xfrm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,11 @@ static inline struct dst_entry *xfrm_dst_child(const struct dst_entry *dst)
10041004
}
10051005

10061006
#ifdef CONFIG_XFRM
1007+
static inline void xfrm_dst_set_child(struct xfrm_dst *xdst, struct dst_entry *child)
1008+
{
1009+
xdst->u.dst.child = child;
1010+
}
1011+
10071012
static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
10081013
{
10091014
xfrm_pols_put(xdst->pols, xdst->num_pols);

net/xfrm/xfrm_policy.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,8 +1546,8 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
15461546
unsigned long now = jiffies;
15471547
struct net_device *dev;
15481548
struct xfrm_mode *inner_mode;
1549-
struct dst_entry *dst_prev = NULL;
1550-
struct dst_entry *dst0 = NULL;
1549+
struct xfrm_dst *xdst_prev = NULL;
1550+
struct xfrm_dst *xdst0 = NULL;
15511551
int i = 0;
15521552
int err;
15531553
int header_len = 0;
@@ -1573,13 +1573,13 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
15731573
goto put_states;
15741574
}
15751575

1576-
if (!dst_prev)
1577-
dst0 = dst1;
1576+
if (!xdst_prev)
1577+
xdst0 = xdst;
15781578
else
15791579
/* Ref count is taken during xfrm_alloc_dst()
15801580
* No need to do dst_clone() on dst1
15811581
*/
1582-
dst_prev->child = dst1;
1582+
xfrm_dst_set_child(xdst_prev, &xdst->u.dst);
15831583

15841584
if (xfrm[i]->sel.family == AF_UNSPEC) {
15851585
inner_mode = xfrm_ip2inner_mode(xfrm[i],
@@ -1616,49 +1616,48 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
16161616
dst1->input = dst_discard;
16171617
dst1->output = inner_mode->afinfo->output;
16181618

1619-
dst1->next = dst_prev;
1620-
dst_prev = dst1;
1619+
dst1->next = &xdst_prev->u.dst;
1620+
xdst_prev = xdst;
16211621

16221622
header_len += xfrm[i]->props.header_len;
16231623
if (xfrm[i]->type->flags & XFRM_TYPE_NON_FRAGMENT)
16241624
nfheader_len += xfrm[i]->props.header_len;
16251625
trailer_len += xfrm[i]->props.trailer_len;
16261626
}
16271627

1628-
dst_prev->child = dst;
1629-
dst0->path = dst;
1628+
xfrm_dst_set_child(xdst_prev, dst);
1629+
xdst0->u.dst.path = dst;
16301630

16311631
err = -ENODEV;
16321632
dev = dst->dev;
16331633
if (!dev)
16341634
goto free_dst;
16351635

1636-
xfrm_init_path((struct xfrm_dst *)dst0, dst, nfheader_len);
1637-
xfrm_init_pmtu(dst_prev);
1636+
xfrm_init_path(xdst0, dst, nfheader_len);
1637+
xfrm_init_pmtu(&xdst_prev->u.dst);
16381638

1639-
for (dst_prev = dst0; dst_prev != dst; dst_prev = xfrm_dst_child(dst_prev)) {
1640-
struct xfrm_dst *xdst = (struct xfrm_dst *)dst_prev;
1641-
1642-
err = xfrm_fill_dst(xdst, dev, fl);
1639+
for (xdst_prev = xdst0; xdst_prev != (struct xfrm_dst *)dst;
1640+
xdst_prev = (struct xfrm_dst *) xfrm_dst_child(&xdst_prev->u.dst)) {
1641+
err = xfrm_fill_dst(xdst_prev, dev, fl);
16431642
if (err)
16441643
goto free_dst;
16451644

1646-
dst_prev->header_len = header_len;
1647-
dst_prev->trailer_len = trailer_len;
1648-
header_len -= xdst->u.dst.xfrm->props.header_len;
1649-
trailer_len -= xdst->u.dst.xfrm->props.trailer_len;
1645+
xdst_prev->u.dst.header_len = header_len;
1646+
xdst_prev->u.dst.trailer_len = trailer_len;
1647+
header_len -= xdst_prev->u.dst.xfrm->props.header_len;
1648+
trailer_len -= xdst_prev->u.dst.xfrm->props.trailer_len;
16501649
}
16511650

16521651
out:
1653-
return dst0;
1652+
return &xdst0->u.dst;
16541653

16551654
put_states:
16561655
for (; i < nx; i++)
16571656
xfrm_state_put(xfrm[i]);
16581657
free_dst:
1659-
if (dst0)
1660-
dst_release_immediate(dst0);
1661-
dst0 = ERR_PTR(err);
1658+
if (xdst0)
1659+
dst_release_immediate(&xdst0->u.dst);
1660+
xdst0 = ERR_PTR(err);
16621661
goto out;
16631662
}
16641663

@@ -2012,7 +2011,7 @@ static struct xfrm_dst *xfrm_create_dummy_bundle(struct net *net,
20122011
dst1->output = xdst_queue_output;
20132012

20142013
dst_hold(dst);
2015-
dst1->child = dst;
2014+
xfrm_dst_set_child(xdst, dst);
20162015
dst1->path = dst;
20172016

20182017
xfrm_init_path((struct xfrm_dst *)dst1, dst, 0);

0 commit comments

Comments
 (0)