ipv6: introduce ip6_rt_put()
authorAmerigo Wang <amwang@redhat.com>
Mon, 29 Oct 2012 00:13:19 +0000 (00:13 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 3 Nov 2012 18:59:05 +0000 (14:59 -0400)
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>
include/net/ip6_fib.h
net/ipv6/addrconf.c
net/ipv6/anycast.c
net/ipv6/fib6_rules.c
net/ipv6/ip6_gre.c
net/ipv6/ip6_output.c
net/ipv6/ip6_tunnel.c
net/ipv6/mcast.c
net/ipv6/ndisc.c
net/ipv6/netfilter/ip6t_rpfilter.c
net/ipv6/route.c

index 20210d79e36aaa8dade4e1b3c706392a02e7c986..d1327e4d126bc8cf5fd8bc8197ade3ef08fae4cf 100644 (file)
@@ -213,6 +213,15 @@ static inline void rt6_set_from(struct rt6_info *rt, struct rt6_info *from)
        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 list_head lh;
        struct fib6_node *root, *node;
index ced58e1d91b6593a4e6df6259b6c8c77127a7c60..fab23db8ee73fa49979172ce24623b70b7f17664 100644 (file)
@@ -699,7 +699,7 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
                pr_warn("Freeing alive inet6 address %p\n", ifp);
                return;
        }
-       dst_release(&ifp->rt->dst);
+       ip6_rt_put(ifp->rt);
 
        kfree_rcu(ifp, rcu);
 }
@@ -951,7 +951,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
                                rt6_set_expires(rt, expires);
                        }
                }
-               dst_release(&rt->dst);
+               ip6_rt_put(rt);
        }
 
        /* clean up prefsrc entries */
@@ -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,
                                              dev, expires, flags);
                }
-               if (rt)
-                       dst_release(&rt->dst);
+               ip6_rt_put(rt);
        }
 
        /* Try to figure out our local address for this prefix */
index cdf02be5f191405de1587f4d03b3c12f3fe4cc9d..4963c769a13f0a1a4e1b19fa51a3f9a891d50afd 100644 (file)
@@ -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);
                if (rt) {
                        dev = rt->dst.dev;
-                       dst_release(&rt->dst);
+                       ip6_rt_put(rt);
                } else if (ishost) {
                        err = -EADDRNOTAVAIL;
                        goto error;
index d9fb9110f607e8c587667147739979f34d52bc0a..2e1a432867c0897f4e0d4439f9c6fd5d3f4c66cb 100644 (file)
@@ -100,7 +100,7 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
                goto out;
        }
 again:
-       dst_release(&rt->dst);
+       ip6_rt_put(rt);
        rt = NULL;
        goto out;
 
index 0185679c5f536c1fa98d71ac90a2c24cd6481d8f..bbe2e7b538b4072acee6051b642e6d568d75f0f0 100644 (file)
@@ -1069,7 +1069,7 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
                                        dev->mtu = IPV6_MIN_MTU;
                        }
                }
-               dst_release(&rt->dst);
+               ip6_rt_put(rt);
        }
 
        t->hlen = addend;
index e10c77b4fbecf8e1ea5bc96361eced7c19af5ef9..3deaa4e2e8e2ead3f8bc4c33e4fbe48b9fa6dd25 100644 (file)
@@ -755,7 +755,7 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
                if (err == 0) {
                        IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
                                      IPSTATS_MIB_FRAGOKS);
-                       dst_release(&rt->dst);
+                       ip6_rt_put(rt);
                        return 0;
                }
 
@@ -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),
                              IPSTATS_MIB_FRAGFAILS);
-               dst_release(&rt->dst);
+               ip6_rt_put(rt);
                return err;
 
 slow_path_clean:
index cb7e2ded6f08cce17f8fb11a7e7e119e8564d661..09482f723064e88a4be559d957bde897e2d9dc3c 100644 (file)
@@ -663,8 +663,7 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
 
                icmpv6_send(skb2, rel_type, rel_code, rel_info);
 
-               if (rt)
-                       dst_release(&rt->dst);
+               ip6_rt_put(rt);
 
                kfree_skb(skb2);
        }
@@ -1208,7 +1207,7 @@ static void ip6_tnl_link_config(struct ip6_tnl *t)
                        if (dev->mtu < IPV6_MIN_MTU)
                                dev->mtu = IPV6_MIN_MTU;
                }
-               dst_release(&rt->dst);
+               ip6_rt_put(rt);
        }
 }
 
index 92f8e48e4ba4e63606412e317c28d2153eddccb0..b19ed51a45bbe1e42a4405902bedfd2b4bdd49dc 100644 (file)
@@ -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);
                if (rt) {
                        dev = rt->dst.dev;
-                       dst_release(&rt->dst);
+                       ip6_rt_put(rt);
                }
        } else
                dev = dev_get_by_index_rcu(net, ifindex);
@@ -260,7 +260,7 @@ static struct inet6_dev *ip6_mc_find_dev_rcu(struct net *net,
 
                if (rt) {
                        dev = rt->dst.dev;
-                       dst_release(&rt->dst);
+                       ip6_rt_put(rt);
                }
        } else
                dev = dev_get_by_index_rcu(net, ifindex);
index ff36194a71aa7dd0fe0f707cff80afd83e40102e..ae0cf818a8f02f61b6c7a5c4b04193b357d38f19 100644 (file)
@@ -1145,7 +1145,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
                        ND_PRINTK(0, err,
                                  "RA: %s got default router without neighbour\n",
                                  __func__);
-                       dst_release(&rt->dst);
+                       ip6_rt_put(rt);
                        return;
                }
        }
@@ -1170,7 +1170,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
                        ND_PRINTK(0, err,
                                  "RA: %s got default router without neighbour\n",
                                  __func__);
-                       dst_release(&rt->dst);
+                       ip6_rt_put(rt);
                        return;
                }
                neigh->flags |= NTF_ROUTER;
@@ -1326,8 +1326,7 @@ skip_routeinfo:
                ND_PRINTK(2, warn, "RA: invalid RA options\n");
        }
 out:
-       if (rt)
-               dst_release(&rt->dst);
+       ip6_rt_put(rt);
        if (neigh)
                neigh_release(neigh);
 }
index 5d1d8b04d6943df82a68da781a475b8eb506cde3..5060d54199abbc180d7dc87ba072bace2bc167f7 100644 (file)
@@ -67,7 +67,7 @@ static bool rpfilter_lookup_reverse6(const struct sk_buff *skb,
        if (rt->rt6i_idev->dev == dev || (flags & XT_RPFILTER_LOOSE))
                ret = true;
  out:
-       dst_release(&rt->dst);
+       ip6_rt_put(rt);
        return ret;
 }
 
index 9c7b5d80049563b02b152c1535c1735d98bce173..c1cfcb7e563298db86e555567f7e1e6e33335bce 100644 (file)
@@ -732,7 +732,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
                else
                        rt6_set_expires(rt, jiffies + HZ * lifetime);
 
-               dst_release(&rt->dst);
+               ip6_rt_put(rt);
        }
        return 0;
 }
@@ -948,7 +948,7 @@ restart:
        else
                goto out2;
 
-       dst_release(&rt->dst);
+       ip6_rt_put(rt);
        rt = nrt ? : net->ipv6.ip6_null_entry;
 
        dst_hold(&rt->dst);
@@ -965,7 +965,7 @@ restart:
         * Race condition! In the gap, when table->tb6_lock was
         * released someone could insert this route.  Relookup.
         */
-       dst_release(&rt->dst);
+       ip6_rt_put(rt);
        goto relookup;
 
 out:
@@ -1576,7 +1576,7 @@ int ip6_route_add(struct fib6_config *cfg)
                                goto out;
                        if (dev) {
                                if (dev != grt->dst.dev) {
-                                       dst_release(&grt->dst);
+                                       ip6_rt_put(grt);
                                        goto out;
                                }
                        } else {
@@ -1587,7 +1587,7 @@ int ip6_route_add(struct fib6_config *cfg)
                        }
                        if (!(grt->rt6i_flags & RTF_GATEWAY))
                                err = 0;
-                       dst_release(&grt->dst);
+                       ip6_rt_put(grt);
 
                        if (err)
                                goto out;
@@ -1673,7 +1673,7 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info)
        write_unlock_bh(&table->tb6_lock);
 
 out:
-       dst_release(&rt->dst);
+       ip6_rt_put(rt);
        return err;
 }
 
@@ -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);
        if (!skb) {
-               dst_release(&rt->dst);
+               ip6_rt_put(rt);
                err = -ENOBUFS;
                goto errout;
        }