ipv6: Add rt6_get_cookie() function
authorMartin KaFai Lau <kafai@fb.com>
Sat, 23 May 2015 03:56:01 +0000 (20:56 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 25 May 2015 17:25:34 +0000 (13:25 -0400)
Instead of doing the rt6->rt6i_node check whenever we need
to get the route's cookie.  Refactor it into rt6_get_cookie().
It is a prep work to handle FLOWI_FLAG_KNOWN_NH and also
percpu rt6_info later.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Cc: Julian Anastasov <ja@ssi.bg>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip6_fib.h
include/net/ip6_route.h
net/ipv6/ip6_tunnel.c
net/ipv6/tcp_ipv6.c
net/ipv6/xfrm6_policy.c
net/netfilter/ipvs/ip_vs_xmit.c
net/sctp/ipv6.c

index e00018011028fb270ace544d7243e261e37fef4e..a4bece6797da217edf561c1099ae9d02de14a4e7 100644 (file)
@@ -159,6 +159,11 @@ static inline void rt6_update_expires(struct rt6_info *rt0, int timeout)
        rt0->rt6i_flags |= RTF_EXPIRES;
 }
 
+static inline u32 rt6_get_cookie(const struct rt6_info *rt)
+{
+       return rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
+}
+
 static inline void ip6_rt_put(struct rt6_info *rt)
 {
        /* dst_release() accepts a NULL parameter.
index 784ee3d01dbf5adad590c1baf82faf96d7632bac..297629aadb190d4cfcdec41c241efa2b0db76a71 100644 (file)
@@ -145,7 +145,7 @@ static inline void __ip6_dst_store(struct sock *sk, struct dst_entry *dst,
 #ifdef CONFIG_IPV6_SUBTREES
        np->saddr_cache = saddr;
 #endif
-       np->dst_cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
+       np->dst_cookie = rt6_get_cookie(rt);
 }
 
 static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
index 5cafd92c231270703af5bf948d131d99c5e9c193..2e67b660118bf7eeaf2f08033aa759190dea0c3a 100644 (file)
@@ -151,7 +151,7 @@ EXPORT_SYMBOL_GPL(ip6_tnl_dst_reset);
 void ip6_tnl_dst_store(struct ip6_tnl *t, struct dst_entry *dst)
 {
        struct rt6_info *rt = (struct rt6_info *) dst;
-       t->dst_cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
+       t->dst_cookie = rt6_get_cookie(rt);
        dst_release(t->dst_cache);
        t->dst_cache = dst;
 }
index 1a9390a370c003d531c69ef67e164f5ca8cf15a5..7be3d858cbf0a4f5b7f4ecce8788aa8e4136d6fa 100644 (file)
@@ -99,8 +99,7 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
                dst_hold(dst);
                sk->sk_rx_dst = dst;
                inet_sk(sk)->rx_dst_ifindex = skb->skb_iif;
-               if (rt->rt6i_node)
-                       inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
+               inet6_sk(sk)->rx_dst_cookie = rt6_get_cookie(rt);
        }
 }
 
index 6ae256b4c55a49d5832d688aab82baa365db8d47..ed0583c1b9fc2e0033912e2d4c7177a12f17e8b7 100644 (file)
@@ -76,8 +76,7 @@ static int xfrm6_init_path(struct xfrm_dst *path, struct dst_entry *dst,
 {
        if (dst->ops->family == AF_INET6) {
                struct rt6_info *rt = (struct rt6_info *)dst;
-               if (rt->rt6i_node)
-                       path->path_cookie = rt->rt6i_node->fn_sernum;
+               path->path_cookie = rt6_get_cookie(rt);
        }
 
        path->u.rt6.rt6i_nfheader_len = nfheader_len;
@@ -105,8 +104,7 @@ static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
                                                   RTF_LOCAL);
        xdst->u.rt6.rt6i_metric = rt->rt6i_metric;
        xdst->u.rt6.rt6i_node = rt->rt6i_node;
-       if (rt->rt6i_node)
-               xdst->route_cookie = rt->rt6i_node->fn_sernum;
+       xdst->route_cookie = rt6_get_cookie(rt);
        xdst->u.rt6.rt6i_gateway = rt->rt6i_gateway;
        xdst->u.rt6.rt6i_dst = rt->rt6i_dst;
        xdst->u.rt6.rt6i_src = rt->rt6i_src;
index 38f862728f75744037f2d28468b31af469b253c7..5eff9f6dcfb80d49331a73101f1cddf89aef0713 100644 (file)
@@ -435,7 +435,7 @@ __ip_vs_get_out_rt_v6(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,
                                goto err_unreach;
                        }
                        rt = (struct rt6_info *) dst;
-                       cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
+                       cookie = rt6_get_cookie(rt);
                        __ip_vs_dst_set(dest, dest_dst, &rt->dst, cookie);
                        spin_unlock_bh(&dest->dst_lock);
                        IP_VS_DBG(10, "new dst %pI6, src %pI6, refcnt=%d\n",
index 17a0120ae5a5491f9464a9c565640b3abcf112d0..e917d27328ea835419ba3e4c26eae1d7b7fade77 100644 (file)
@@ -331,7 +331,7 @@ out:
 
                rt = (struct rt6_info *)dst;
                t->dst = dst;
-               t->dst_cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
+               t->dst_cookie = rt6_get_cookie(rt);
                pr_debug("rt6_dst:%pI6/%d rt6_src:%pI6\n",
                         &rt->rt6i_dst.addr, rt->rt6i_dst.plen,
                         &fl6->saddr);