ipv6: Remove external dependency on rt6i_gateway and RTF_ANYCAST
authorMartin KaFai Lau <kafai@fb.com>
Sat, 23 May 2015 03:55:58 +0000 (20:55 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 25 May 2015 17:25:33 +0000 (13:25 -0400)
When creating a RTF_CACHE route, RTF_ANYCAST is set based on rt6i_dst.
Also, rt6i_gateway is always set to the nexthop while the nexthop
could be a gateway or the rt6i_dst.addr.

After removing the rt6i_dst and rt6i_src dependency in the last patch,
we also need to stop the caller from depending on rt6i_gateway and
RTF_ANYCAST.

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_route.h
net/bluetooth/6lowpan.c
net/ipv6/icmp.c
net/ipv6/ip6_output.c
net/ipv6/route.c
net/netfilter/nf_conntrack_h323_main.c
net/netfilter/xt_addrtype.c

index 5e192068e6cb61a78d9b19b2b58bffd7c68b44bb..4caf7d697dee1ff7352e37c07104b13907682931 100644 (file)
@@ -163,11 +163,14 @@ static inline bool ipv6_unicast_destination(const struct sk_buff *skb)
        return rt->rt6i_flags & RTF_LOCAL;
 }
 
-static inline bool ipv6_anycast_destination(const struct sk_buff *skb)
+static inline bool ipv6_anycast_destination(const struct dst_entry *dst,
+                                           const struct in6_addr *daddr)
 {
-       struct rt6_info *rt = (struct rt6_info *) skb_dst(skb);
+       struct rt6_info *rt = (struct rt6_info *)dst;
 
-       return rt->rt6i_flags & RTF_ANYCAST;
+       return rt->rt6i_flags & RTF_ANYCAST ||
+               (rt->rt6i_dst.plen != 128 &&
+                ipv6_addr_equal(&rt->rt6i_dst.addr, daddr));
 }
 
 int ip6_fragment(struct sock *sk, struct sk_buff *skb,
@@ -194,9 +197,15 @@ static inline bool ip6_sk_ignore_df(const struct sock *sk)
               inet6_sk(sk)->pmtudisc == IPV6_PMTUDISC_OMIT;
 }
 
-static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt)
+static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt,
+                                          struct in6_addr *daddr)
 {
-       return &rt->rt6i_gateway;
+       if (rt->rt6i_flags & RTF_GATEWAY)
+               return &rt->rt6i_gateway;
+       else if (rt->rt6i_flags & RTF_CACHE)
+               return &rt->rt6i_dst.addr;
+       else
+               return daddr;
 }
 
 #endif
index 1742b849fcff7ca6d5bb9fbe8b375c2514992531..f3d6046c8ee743cc05a46750e7027149676c8832 100644 (file)
@@ -192,7 +192,7 @@ static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_dev *dev,
                if (ipv6_addr_any(nexthop))
                        return NULL;
        } else {
-               nexthop = rt6_nexthop(rt);
+               nexthop = rt6_nexthop(rt, daddr);
 
                /* We need to remember the address because it is needed
                 * by bt_xmit() when sending the packet. In bt_xmit(), the
index 24b359d1425bc8f1937cfc1d709b82658fda8250..713d7434c9112432f800f377925ca68534094c34 100644 (file)
@@ -337,7 +337,7 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net,
         * We won't send icmp if the destination is known
         * anycast.
         */
-       if (((struct rt6_info *)dst)->rt6i_flags & RTF_ANYCAST) {
+       if (ipv6_anycast_destination(dst, &fl6->daddr)) {
                net_dbg_ratelimited("icmp6_send: acast source\n");
                dst_release(dst);
                return ERR_PTR(-EINVAL);
@@ -564,7 +564,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
 
        if (!ipv6_unicast_destination(skb) &&
            !(net->ipv6.sysctl.anycast_src_echo_reply &&
-             ipv6_anycast_destination(skb)))
+             ipv6_anycast_destination(skb_dst(skb), saddr)))
                saddr = NULL;
 
        memcpy(&tmp_hdr, icmph, sizeof(tmp_hdr));
index 3097f2c5e8903ab44cf91a1781be578f18ec9700..61741676b987eb196b167a33acb25739403ed169 100644 (file)
@@ -105,7 +105,7 @@ static int ip6_finish_output2(struct sock *sk, struct sk_buff *skb)
        }
 
        rcu_read_lock_bh();
-       nexthop = rt6_nexthop((struct rt6_info *)dst);
+       nexthop = rt6_nexthop((struct rt6_info *)dst, &ipv6_hdr(skb)->daddr);
        neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop);
        if (unlikely(!neigh))
                neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);
@@ -934,7 +934,8 @@ static int ip6_dst_lookup_tail(struct sock *sk,
         */
        rt = (struct rt6_info *) *dst;
        rcu_read_lock_bh();
-       n = __ipv6_neigh_lookup_noref(rt->dst.dev, rt6_nexthop(rt));
+       n = __ipv6_neigh_lookup_noref(rt->dst.dev,
+                                     rt6_nexthop(rt, &fl6->daddr));
        err = n && !(n->nud_state & NUD_VALID) ? -EINVAL : 0;
        rcu_read_unlock_bh();
 
index 0c889cb89cc329410523559cb2f6bfd8660af54e..ce3b1754b4f5c5d83debb5de76632a9df94a7a54 100644 (file)
@@ -1945,11 +1945,7 @@ static struct rt6_info *ip6_rt_copy(struct rt6_info *ort,
                if (rt->rt6i_idev)
                        in6_dev_hold(rt->rt6i_idev);
                rt->dst.lastuse = jiffies;
-
-               if (ort->rt6i_flags & RTF_GATEWAY)
-                       rt->rt6i_gateway = ort->rt6i_gateway;
-               else
-                       rt->rt6i_gateway = *dest;
+               rt->rt6i_gateway = ort->rt6i_gateway;
                rt->rt6i_flags = ort->rt6i_flags;
                rt6_set_from(rt, ort);
                rt->rt6i_metric = 0;
index 1d69f5b9748fd760630b998493d96ad84d998aba..9511af04dc814258ddc136bdaabe02fd053720fc 100644 (file)
@@ -779,8 +779,8 @@ static int callforward_do_filter(struct net *net,
                                   flowi6_to_flowi(&fl1), false)) {
                        if (!afinfo->route(net, (struct dst_entry **)&rt2,
                                           flowi6_to_flowi(&fl2), false)) {
-                               if (ipv6_addr_equal(rt6_nexthop(rt1),
-                                                   rt6_nexthop(rt2)) &&
+                               if (ipv6_addr_equal(rt6_nexthop(rt1, &fl1.daddr),
+                                                   rt6_nexthop(rt2, &fl2.daddr)) &&
                                    rt1->dst.dev == rt2->dst.dev)
                                        ret = 1;
                                dst_release(&rt2->dst);
index fab6eea1bf382704b07449d88deaece0aa9d7d7e..5b4743cc0436105f51cca8cc4ec71cf4a0ed730e 100644 (file)
@@ -73,7 +73,7 @@ static u32 match_lookup_rt6(struct net *net, const struct net_device *dev,
 
        if (dev == NULL && rt->rt6i_flags & RTF_LOCAL)
                ret |= XT_ADDRTYPE_LOCAL;
-       if (rt->rt6i_flags & RTF_ANYCAST)
+       if (ipv6_anycast_destination((struct dst_entry *)rt, addr))
                ret |= XT_ADDRTYPE_ANYCAST;
 
        dst_release(&rt->dst);