Skip to content

Commit 94e187c

Browse files
Amerigo Wangdavem330
authored andcommitted
ipv6: introduce ip6_rt_put()
As suggested by Eric, we could introduce a helper function for ipv6 too, to avoid checking if rt is NULL before dst_release(). Cc: Eric Dumazet <[email protected]> Cc: David S. Miller <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6da025f commit 94e187c

File tree

11 files changed

+32
-26
lines changed

11 files changed

+32
-26
lines changed

include/net/ip6_fib.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ static inline void rt6_set_from(struct rt6_info *rt, struct rt6_info *from)
213213
dst_hold(new);
214214
}
215215

216+
static inline void ip6_rt_put(struct rt6_info *rt)
217+
{
218+
/* dst_release() accepts a NULL parameter.
219+
* We rely on dst being first structure in struct rt6_info
220+
*/
221+
BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
222+
dst_release(&rt->dst);
223+
}
224+
216225
struct fib6_walker_t {
217226
struct list_head lh;
218227
struct fib6_node *root, *node;

net/ipv6/addrconf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
699699
pr_warn("Freeing alive inet6 address %p\n", ifp);
700700
return;
701701
}
702-
dst_release(&ifp->rt->dst);
702+
ip6_rt_put(ifp->rt);
703703

704704
kfree_rcu(ifp, rcu);
705705
}
@@ -951,7 +951,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
951951
rt6_set_expires(rt, expires);
952952
}
953953
}
954-
dst_release(&rt->dst);
954+
ip6_rt_put(rt);
955955
}
956956

957957
/* clean up prefsrc entries */
@@ -2027,8 +2027,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
20272027
addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
20282028
dev, expires, flags);
20292029
}
2030-
if (rt)
2031-
dst_release(&rt->dst);
2030+
ip6_rt_put(rt);
20322031
}
20332032

20342033
/* Try to figure out our local address for this prefix */

net/ipv6/anycast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr)
8484
rt = rt6_lookup(net, addr, NULL, 0, 0);
8585
if (rt) {
8686
dev = rt->dst.dev;
87-
dst_release(&rt->dst);
87+
ip6_rt_put(rt);
8888
} else if (ishost) {
8989
err = -EADDRNOTAVAIL;
9090
goto error;

net/ipv6/fib6_rules.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
100100
goto out;
101101
}
102102
again:
103-
dst_release(&rt->dst);
103+
ip6_rt_put(rt);
104104
rt = NULL;
105105
goto out;
106106

net/ipv6/ip6_gre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
10691069
dev->mtu = IPV6_MIN_MTU;
10701070
}
10711071
}
1072-
dst_release(&rt->dst);
1072+
ip6_rt_put(rt);
10731073
}
10741074

10751075
t->hlen = addend;

net/ipv6/ip6_output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
755755
if (err == 0) {
756756
IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
757757
IPSTATS_MIB_FRAGOKS);
758-
dst_release(&rt->dst);
758+
ip6_rt_put(rt);
759759
return 0;
760760
}
761761

@@ -767,7 +767,7 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
767767

768768
IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
769769
IPSTATS_MIB_FRAGFAILS);
770-
dst_release(&rt->dst);
770+
ip6_rt_put(rt);
771771
return err;
772772

773773
slow_path_clean:

net/ipv6/ip6_tunnel.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
663663

664664
icmpv6_send(skb2, rel_type, rel_code, rel_info);
665665

666-
if (rt)
667-
dst_release(&rt->dst);
666+
ip6_rt_put(rt);
668667

669668
kfree_skb(skb2);
670669
}
@@ -1208,7 +1207,7 @@ static void ip6_tnl_link_config(struct ip6_tnl *t)
12081207
if (dev->mtu < IPV6_MIN_MTU)
12091208
dev->mtu = IPV6_MIN_MTU;
12101209
}
1211-
dst_release(&rt->dst);
1210+
ip6_rt_put(rt);
12121211
}
12131212
}
12141213

net/ipv6/mcast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int ipv6_sock_mc_join(struct sock *sk, int ifindex, const struct in6_addr *addr)
163163
rt = rt6_lookup(net, addr, NULL, 0, 0);
164164
if (rt) {
165165
dev = rt->dst.dev;
166-
dst_release(&rt->dst);
166+
ip6_rt_put(rt);
167167
}
168168
} else
169169
dev = dev_get_by_index_rcu(net, ifindex);
@@ -260,7 +260,7 @@ static struct inet6_dev *ip6_mc_find_dev_rcu(struct net *net,
260260

261261
if (rt) {
262262
dev = rt->dst.dev;
263-
dst_release(&rt->dst);
263+
ip6_rt_put(rt);
264264
}
265265
} else
266266
dev = dev_get_by_index_rcu(net, ifindex);

net/ipv6/ndisc.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
11451145
ND_PRINTK(0, err,
11461146
"RA: %s got default router without neighbour\n",
11471147
__func__);
1148-
dst_release(&rt->dst);
1148+
ip6_rt_put(rt);
11491149
return;
11501150
}
11511151
}
@@ -1170,7 +1170,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
11701170
ND_PRINTK(0, err,
11711171
"RA: %s got default router without neighbour\n",
11721172
__func__);
1173-
dst_release(&rt->dst);
1173+
ip6_rt_put(rt);
11741174
return;
11751175
}
11761176
neigh->flags |= NTF_ROUTER;
@@ -1326,8 +1326,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
13261326
ND_PRINTK(2, warn, "RA: invalid RA options\n");
13271327
}
13281328
out:
1329-
if (rt)
1330-
dst_release(&rt->dst);
1329+
ip6_rt_put(rt);
13311330
if (neigh)
13321331
neigh_release(neigh);
13331332
}

net/ipv6/netfilter/ip6t_rpfilter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static bool rpfilter_lookup_reverse6(const struct sk_buff *skb,
6767
if (rt->rt6i_idev->dev == dev || (flags & XT_RPFILTER_LOOSE))
6868
ret = true;
6969
out:
70-
dst_release(&rt->dst);
70+
ip6_rt_put(rt);
7171
return ret;
7272
}
7373

net/ipv6/route.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
732732
else
733733
rt6_set_expires(rt, jiffies + HZ * lifetime);
734734

735-
dst_release(&rt->dst);
735+
ip6_rt_put(rt);
736736
}
737737
return 0;
738738
}
@@ -948,7 +948,7 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
948948
else
949949
goto out2;
950950

951-
dst_release(&rt->dst);
951+
ip6_rt_put(rt);
952952
rt = nrt ? : net->ipv6.ip6_null_entry;
953953

954954
dst_hold(&rt->dst);
@@ -965,7 +965,7 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
965965
* Race condition! In the gap, when table->tb6_lock was
966966
* released someone could insert this route. Relookup.
967967
*/
968-
dst_release(&rt->dst);
968+
ip6_rt_put(rt);
969969
goto relookup;
970970

971971
out:
@@ -1576,7 +1576,7 @@ int ip6_route_add(struct fib6_config *cfg)
15761576
goto out;
15771577
if (dev) {
15781578
if (dev != grt->dst.dev) {
1579-
dst_release(&grt->dst);
1579+
ip6_rt_put(grt);
15801580
goto out;
15811581
}
15821582
} else {
@@ -1587,7 +1587,7 @@ int ip6_route_add(struct fib6_config *cfg)
15871587
}
15881588
if (!(grt->rt6i_flags & RTF_GATEWAY))
15891589
err = 0;
1590-
dst_release(&grt->dst);
1590+
ip6_rt_put(grt);
15911591

15921592
if (err)
15931593
goto out;
@@ -1673,7 +1673,7 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info)
16731673
write_unlock_bh(&table->tb6_lock);
16741674

16751675
out:
1676-
dst_release(&rt->dst);
1676+
ip6_rt_put(rt);
16771677
return err;
16781678
}
16791679

@@ -2732,7 +2732,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
27322732

27332733
skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
27342734
if (!skb) {
2735-
dst_release(&rt->dst);
2735+
ip6_rt_put(rt);
27362736
err = -ENOBUFS;
27372737
goto errout;
27382738
}

0 commit comments

Comments
 (0)