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 <eric.dumazet@gmail.com> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Cong Wang <amwang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6da025f commit 94e187c

11 files changed

Lines changed: 32 additions & 26 deletions

File tree

‎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

0 commit comments

Comments
 (0)