Skip to content

Commit b92cf4a

Browse files
committed
net: Create and use new helper xfrm_dst_child().
Only IPSEC routes have a non-NULL dst->child pointer. And IPSEC routes are identified by a non-NULL dst->xfrm pointer. Signed-off-by: David S. Miller <[email protected]>
1 parent 071fb37 commit b92cf4a

File tree

8 files changed

+26
-15
lines changed

8 files changed

+26
-15
lines changed

include/net/xfrm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,15 @@ struct xfrm_dst {
994994
u32 path_cookie;
995995
};
996996

997+
static inline struct dst_entry *xfrm_dst_child(const struct dst_entry *dst)
998+
{
999+
#ifdef CONFIG_XFRM
1000+
if (dst->xfrm)
1001+
return dst->child;
1002+
#endif
1003+
return NULL;
1004+
}
1005+
9971006
#ifdef CONFIG_XFRM
9981007
static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
9991008
{

net/core/dst.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ EXPORT_SYMBOL(dst_alloc);
116116

117117
struct dst_entry *dst_destroy(struct dst_entry * dst)
118118
{
119-
struct dst_entry *child;
119+
struct dst_entry *child = NULL;
120120

121121
smp_rmb();
122122

123-
child = dst->child;
124-
123+
#ifdef CONFIG_XFRM
124+
if (dst->xfrm)
125+
child = dst->child;
126+
#endif
125127
if (!(dst->flags & DST_NOCOUNT))
126128
dst_entries_add(dst->ops, -1);
127129

net/ipv4/xfrm4_mode_tunnel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
6262
top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
6363
0 : (XFRM_MODE_SKB_CB(skb)->frag_off & htons(IP_DF));
6464

65-
top_iph->ttl = ip4_dst_hoplimit(dst->child);
65+
top_iph->ttl = ip4_dst_hoplimit(xfrm_dst_child(dst));
6666

6767
top_iph->saddr = x->props.saddr.a4;
6868
top_iph->daddr = x->id.daddr.a4;

net/ipv6/xfrm6_mode_tunnel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int xfrm6_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
5959
if (x->props.flags & XFRM_STATE_NOECN)
6060
dsfield &= ~INET_ECN_MASK;
6161
ipv6_change_dsfield(top_iph, 0, dsfield);
62-
top_iph->hop_limit = ip6_dst_hoplimit(dst->child);
62+
top_iph->hop_limit = ip6_dst_hoplimit(xfrm_dst_child(dst));
6363
top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
6464
top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
6565
return 0;

net/ipv6/xfrm6_policy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static void xfrm6_dst_ifdown(struct dst_entry *dst, struct net_device *dev,
265265
in6_dev_put(xdst->u.rt6.rt6i_idev);
266266
xdst->u.rt6.rt6i_idev = loopback_idev;
267267
in6_dev_hold(loopback_idev);
268-
xdst = (struct xfrm_dst *)xdst->u.dst.child;
268+
xdst = (struct xfrm_dst *)xfrm_dst_child(&xdst->u.dst);
269269
} while (xdst->u.dst.xfrm);
270270

271271
__in6_dev_put(loopback_idev);

net/xfrm/xfrm_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int xfrm_skb_check_space(struct sk_buff *skb)
4444

4545
static struct dst_entry *skb_dst_pop(struct sk_buff *skb)
4646
{
47-
struct dst_entry *child = dst_clone(skb_dst(skb)->child);
47+
struct dst_entry *child = dst_clone(xfrm_dst_child(skb_dst(skb)));
4848

4949
skb_dst_drop(skb);
5050
return child;

net/xfrm/xfrm_policy.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
16361636
xfrm_init_path((struct xfrm_dst *)dst0, dst, nfheader_len);
16371637
xfrm_init_pmtu(dst_prev);
16381638

1639-
for (dst_prev = dst0; dst_prev != dst; dst_prev = dst_prev->child) {
1639+
for (dst_prev = dst0; dst_prev != dst; dst_prev = xfrm_dst_child(dst_prev)) {
16401640
struct xfrm_dst *xdst = (struct xfrm_dst *)dst_prev;
16411641

16421642
err = xfrm_fill_dst(xdst, dev, fl);
@@ -1800,7 +1800,7 @@ static bool xfrm_xdst_can_reuse(struct xfrm_dst *xdst,
18001800
for (i = 0; i < num; i++) {
18011801
if (!dst || dst->xfrm != xfrm[i])
18021802
return false;
1803-
dst = dst->child;
1803+
dst = xfrm_dst_child(dst);
18041804
}
18051805

18061806
return xfrm_bundle_ok(xdst);
@@ -2576,7 +2576,7 @@ static int stale_bundle(struct dst_entry *dst)
25762576

25772577
void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev)
25782578
{
2579-
while ((dst = dst->child) && dst->xfrm && dst->dev == dev) {
2579+
while ((dst = xfrm_dst_child(dst)) && dst->xfrm && dst->dev == dev) {
25802580
dst->dev = dev_net(dev)->loopback_dev;
25812581
dev_hold(dst->dev);
25822582
dev_put(dev);
@@ -2606,7 +2606,7 @@ static void xfrm_init_pmtu(struct dst_entry *dst)
26062606
struct xfrm_dst *xdst = (struct xfrm_dst *)dst;
26072607
u32 pmtu, route_mtu_cached;
26082608

2609-
pmtu = dst_mtu(dst->child);
2609+
pmtu = dst_mtu(xfrm_dst_child(dst));
26102610
xdst->child_mtu_cached = pmtu;
26112611

26122612
pmtu = xfrm_state_mtu(dst->xfrm, pmtu);
@@ -2651,7 +2651,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
26512651
xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
26522652
return 0;
26532653

2654-
mtu = dst_mtu(dst->child);
2654+
mtu = dst_mtu(xfrm_dst_child(dst));
26552655
if (xdst->child_mtu_cached != mtu) {
26562656
last = xdst;
26572657
xdst->child_mtu_cached = mtu;
@@ -2665,7 +2665,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
26652665
xdst->route_mtu_cached = mtu;
26662666
}
26672667

2668-
dst = dst->child;
2668+
dst = xfrm_dst_child(dst);
26692669
} while (dst->xfrm);
26702670

26712671
if (likely(!last))
@@ -2707,7 +2707,7 @@ static const void *xfrm_get_dst_nexthop(const struct dst_entry *dst,
27072707
{
27082708
const struct dst_entry *path = dst->path;
27092709

2710-
for (; dst != path; dst = dst->child) {
2710+
for (; dst != path; dst = xfrm_dst_child(dst)) {
27112711
const struct xfrm_state *xfrm = dst->xfrm;
27122712

27132713
if (xfrm->props.mode == XFRM_MODE_TRANSPORT)

security/selinux/xfrm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb,
452452
if (dst) {
453453
struct dst_entry *iter;
454454

455-
for (iter = dst; iter != NULL; iter = iter->child) {
455+
for (iter = dst; iter != NULL; iter = xfrm_dst_child(iter)) {
456456
struct xfrm_state *x = iter->xfrm;
457457

458458
if (x && selinux_authorizable_xfrm(x))

0 commit comments

Comments
 (0)