Commit 94e187c0 authored by Amerigo Wang's avatar Amerigo Wang Committed by David S. Miller

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: default avatarCong Wang <amwang@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6da025fa
...@@ -213,6 +213,15 @@ static inline void rt6_set_from(struct rt6_info *rt, struct rt6_info *from) ...@@ -213,6 +213,15 @@ static inline void rt6_set_from(struct rt6_info *rt, struct rt6_info *from)
dst_hold(new); dst_hold(new);
} }
static inline void ip6_rt_put(struct rt6_info *rt)
{
/* dst_release() accepts a NULL parameter.
* We rely on dst being first structure in struct rt6_info
*/
BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
dst_release(&rt->dst);
}
struct fib6_walker_t { struct fib6_walker_t {
struct list_head lh; struct list_head lh;
struct fib6_node *root, *node; struct fib6_node *root, *node;
......
...@@ -699,7 +699,7 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) ...@@ -699,7 +699,7 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
pr_warn("Freeing alive inet6 address %p\n", ifp); pr_warn("Freeing alive inet6 address %p\n", ifp);
return; return;
} }
dst_release(&ifp->rt->dst); ip6_rt_put(ifp->rt);
kfree_rcu(ifp, rcu); kfree_rcu(ifp, rcu);
} }
...@@ -951,7 +951,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp) ...@@ -951,7 +951,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
rt6_set_expires(rt, expires); rt6_set_expires(rt, expires);
} }
} }
dst_release(&rt->dst); ip6_rt_put(rt);
} }
/* clean up prefsrc entries */ /* clean up prefsrc entries */
...@@ -2027,8 +2027,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) ...@@ -2027,8 +2027,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
dev, expires, flags); dev, expires, flags);
} }
if (rt) ip6_rt_put(rt);
dst_release(&rt->dst);
} }
/* Try to figure out our local address for this prefix */ /* Try to figure out our local address for this prefix */
......
...@@ -84,7 +84,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr) ...@@ -84,7 +84,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr)
rt = rt6_lookup(net, addr, NULL, 0, 0); rt = rt6_lookup(net, addr, NULL, 0, 0);
if (rt) { if (rt) {
dev = rt->dst.dev; dev = rt->dst.dev;
dst_release(&rt->dst); ip6_rt_put(rt);
} else if (ishost) { } else if (ishost) {
err = -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
goto error; goto error;
......
...@@ -100,7 +100,7 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp, ...@@ -100,7 +100,7 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
goto out; goto out;
} }
again: again:
dst_release(&rt->dst); ip6_rt_put(rt);
rt = NULL; rt = NULL;
goto out; goto out;
......
...@@ -1069,7 +1069,7 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu) ...@@ -1069,7 +1069,7 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
dev->mtu = IPV6_MIN_MTU; dev->mtu = IPV6_MIN_MTU;
} }
} }
dst_release(&rt->dst); ip6_rt_put(rt);
} }
t->hlen = addend; t->hlen = addend;
......
...@@ -755,7 +755,7 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -755,7 +755,7 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
if (err == 0) { if (err == 0) {
IP6_INC_STATS(net, ip6_dst_idev(&rt->dst), IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
IPSTATS_MIB_FRAGOKS); IPSTATS_MIB_FRAGOKS);
dst_release(&rt->dst); ip6_rt_put(rt);
return 0; return 0;
} }
...@@ -767,7 +767,7 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -767,7 +767,7 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
IP6_INC_STATS(net, ip6_dst_idev(&rt->dst), IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
IPSTATS_MIB_FRAGFAILS); IPSTATS_MIB_FRAGFAILS);
dst_release(&rt->dst); ip6_rt_put(rt);
return err; return err;
slow_path_clean: slow_path_clean:
......
...@@ -663,8 +663,7 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, ...@@ -663,8 +663,7 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
icmpv6_send(skb2, rel_type, rel_code, rel_info); icmpv6_send(skb2, rel_type, rel_code, rel_info);
if (rt) ip6_rt_put(rt);
dst_release(&rt->dst);
kfree_skb(skb2); kfree_skb(skb2);
} }
...@@ -1208,7 +1207,7 @@ static void ip6_tnl_link_config(struct ip6_tnl *t) ...@@ -1208,7 +1207,7 @@ static void ip6_tnl_link_config(struct ip6_tnl *t)
if (dev->mtu < IPV6_MIN_MTU) if (dev->mtu < IPV6_MIN_MTU)
dev->mtu = IPV6_MIN_MTU; dev->mtu = IPV6_MIN_MTU;
} }
dst_release(&rt->dst); ip6_rt_put(rt);
} }
} }
......
...@@ -163,7 +163,7 @@ int ipv6_sock_mc_join(struct sock *sk, int ifindex, const struct in6_addr *addr) ...@@ -163,7 +163,7 @@ int ipv6_sock_mc_join(struct sock *sk, int ifindex, const struct in6_addr *addr)
rt = rt6_lookup(net, addr, NULL, 0, 0); rt = rt6_lookup(net, addr, NULL, 0, 0);
if (rt) { if (rt) {
dev = rt->dst.dev; dev = rt->dst.dev;
dst_release(&rt->dst); ip6_rt_put(rt);
} }
} else } else
dev = dev_get_by_index_rcu(net, ifindex); dev = dev_get_by_index_rcu(net, ifindex);
...@@ -260,7 +260,7 @@ static struct inet6_dev *ip6_mc_find_dev_rcu(struct net *net, ...@@ -260,7 +260,7 @@ static struct inet6_dev *ip6_mc_find_dev_rcu(struct net *net,
if (rt) { if (rt) {
dev = rt->dst.dev; dev = rt->dst.dev;
dst_release(&rt->dst); ip6_rt_put(rt);
} }
} else } else
dev = dev_get_by_index_rcu(net, ifindex); dev = dev_get_by_index_rcu(net, ifindex);
......
...@@ -1145,7 +1145,7 @@ static void ndisc_router_discovery(struct sk_buff *skb) ...@@ -1145,7 +1145,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
ND_PRINTK(0, err, ND_PRINTK(0, err,
"RA: %s got default router without neighbour\n", "RA: %s got default router without neighbour\n",
__func__); __func__);
dst_release(&rt->dst); ip6_rt_put(rt);
return; return;
} }
} }
...@@ -1170,7 +1170,7 @@ static void ndisc_router_discovery(struct sk_buff *skb) ...@@ -1170,7 +1170,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
ND_PRINTK(0, err, ND_PRINTK(0, err,
"RA: %s got default router without neighbour\n", "RA: %s got default router without neighbour\n",
__func__); __func__);
dst_release(&rt->dst); ip6_rt_put(rt);
return; return;
} }
neigh->flags |= NTF_ROUTER; neigh->flags |= NTF_ROUTER;
...@@ -1326,8 +1326,7 @@ static void ndisc_router_discovery(struct sk_buff *skb) ...@@ -1326,8 +1326,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
ND_PRINTK(2, warn, "RA: invalid RA options\n"); ND_PRINTK(2, warn, "RA: invalid RA options\n");
} }
out: out:
if (rt) ip6_rt_put(rt);
dst_release(&rt->dst);
if (neigh) if (neigh)
neigh_release(neigh); neigh_release(neigh);
} }
......
...@@ -67,7 +67,7 @@ static bool rpfilter_lookup_reverse6(const struct sk_buff *skb, ...@@ -67,7 +67,7 @@ static bool rpfilter_lookup_reverse6(const struct sk_buff *skb,
if (rt->rt6i_idev->dev == dev || (flags & XT_RPFILTER_LOOSE)) if (rt->rt6i_idev->dev == dev || (flags & XT_RPFILTER_LOOSE))
ret = true; ret = true;
out: out:
dst_release(&rt->dst); ip6_rt_put(rt);
return ret; return ret;
} }
......
...@@ -732,7 +732,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, ...@@ -732,7 +732,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
else else
rt6_set_expires(rt, jiffies + HZ * lifetime); rt6_set_expires(rt, jiffies + HZ * lifetime);
dst_release(&rt->dst); ip6_rt_put(rt);
} }
return 0; return 0;
} }
...@@ -948,7 +948,7 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, ...@@ -948,7 +948,7 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
else else
goto out2; goto out2;
dst_release(&rt->dst); ip6_rt_put(rt);
rt = nrt ? : net->ipv6.ip6_null_entry; rt = nrt ? : net->ipv6.ip6_null_entry;
dst_hold(&rt->dst); dst_hold(&rt->dst);
...@@ -965,7 +965,7 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, ...@@ -965,7 +965,7 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
* Race condition! In the gap, when table->tb6_lock was * Race condition! In the gap, when table->tb6_lock was
* released someone could insert this route. Relookup. * released someone could insert this route. Relookup.
*/ */
dst_release(&rt->dst); ip6_rt_put(rt);
goto relookup; goto relookup;
out: out:
...@@ -1576,7 +1576,7 @@ int ip6_route_add(struct fib6_config *cfg) ...@@ -1576,7 +1576,7 @@ int ip6_route_add(struct fib6_config *cfg)
goto out; goto out;
if (dev) { if (dev) {
if (dev != grt->dst.dev) { if (dev != grt->dst.dev) {
dst_release(&grt->dst); ip6_rt_put(grt);
goto out; goto out;
} }
} else { } else {
...@@ -1587,7 +1587,7 @@ int ip6_route_add(struct fib6_config *cfg) ...@@ -1587,7 +1587,7 @@ int ip6_route_add(struct fib6_config *cfg)
} }
if (!(grt->rt6i_flags & RTF_GATEWAY)) if (!(grt->rt6i_flags & RTF_GATEWAY))
err = 0; err = 0;
dst_release(&grt->dst); ip6_rt_put(grt);
if (err) if (err)
goto out; goto out;
...@@ -1673,7 +1673,7 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info) ...@@ -1673,7 +1673,7 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info)
write_unlock_bh(&table->tb6_lock); write_unlock_bh(&table->tb6_lock);
out: out:
dst_release(&rt->dst); ip6_rt_put(rt);
return err; return err;
} }
...@@ -2732,7 +2732,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void ...@@ -2732,7 +2732,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
if (!skb) { if (!skb) {
dst_release(&rt->dst); ip6_rt_put(rt);
err = -ENOBUFS; err = -ENOBUFS;
goto errout; goto errout;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment