net/ipv6: Add rt6_info create function for ip6_pol_route_lookup
authorDavid Ahern <dsahern@gmail.com>
Wed, 18 Apr 2018 00:33:19 +0000 (17:33 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 18 Apr 2018 03:41:17 +0000 (23:41 -0400)
ip6_pol_route_lookup is the lookup function for ip6_route_lookup and
rt6_lookup. At the moment it returns either a reference to a FIB entry
or a cached exception. To move FIB entries to a separate struct, this
lookup function needs to convert FIB entries to an rt6_info that is
returned to the caller.

Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/route.c

index 7c141394d4f10d311e4f97d3a22babf7d786f3f7..e293692174bae52e279ff67b89a9e38e2e3f0964 100644 (file)
@@ -1055,6 +1055,19 @@ static bool ip6_hold_safe(struct net *net, struct rt6_info **prt,
        return false;
 }
 
+/* called with rcu_lock held */
+static struct rt6_info *ip6_create_rt_rcu(struct rt6_info *rt)
+{
+       struct net_device *dev = rt->fib6_nh.nh_dev;
+       struct rt6_info *nrt;
+
+       nrt = __ip6_dst_alloc(dev_net(dev), dev, 0);
+       if (nrt)
+               ip6_rt_copy_init(nrt, rt);
+
+       return nrt;
+}
+
 static struct rt6_info *ip6_pol_route_lookup(struct net *net,
                                             struct fib6_table *table,
                                             struct flowi6 *fl6,
@@ -1087,18 +1100,26 @@ restart:
        }
        /* Search through exception table */
        rt_cache = rt6_find_cached_rt(rt, &fl6->daddr, &fl6->saddr);
-       if (rt_cache)
+       if (rt_cache) {
                rt = rt_cache;
+               if (ip6_hold_safe(net, &rt, true))
+                       dst_use_noref(&rt->dst, jiffies);
+       } else if (dst_hold_safe(&rt->dst)) {
+               struct rt6_info *nrt;
 
-       if (ip6_hold_safe(net, &rt, true))
-               dst_use_noref(&rt->dst, jiffies);
+               nrt = ip6_create_rt_rcu(rt);
+               dst_release(&rt->dst);
+               rt = nrt;
+       } else {
+               rt = net->ipv6.ip6_null_entry;
+               dst_hold(&rt->dst);
+       }
 
        rcu_read_unlock();
 
        trace_fib6_table_lookup(net, rt, table, fl6);
 
        return rt;
-
 }
 
 struct dst_entry *ip6_route_lookup(struct net *net, struct flowi6 *fl6,