net/ipv6: Extract table lookup from ip6_pol_route
authorDavid Ahern <dsahern@gmail.com>
Thu, 10 May 2018 03:34:21 +0000 (20:34 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 10 May 2018 22:10:56 +0000 (00:10 +0200)
ip6_pol_route is used for ingress and egress FIB lookups. Refactor it
moving the table lookup into a separate fib6_table_lookup that can be
invoked separately and export the new function.

ip6_pol_route now calls fib6_table_lookup and uses the result to generate
a dst based rt6_info.

Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/net/ip6_fib.h
net/ipv6/route.c

index 2597d8fdd92f80c5c7eea26eef30123a81b2364e..c70705f2647a5c44978f26afa5f9eaadce8de153 100644 (file)
@@ -376,6 +376,10 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
                                   const struct sk_buff *skb,
                                   int flags, pol_lookup_t lookup);
 
+/* called with rcu lock held; caller needs to select path */
+struct fib6_info *fib6_table_lookup(struct net *net, struct fib6_table *table,
+                                   int oif, struct flowi6 *fl6, int strict);
+
 struct fib6_info *fib6_multipath_select(const struct net *net,
                                        struct fib6_info *match,
                                        struct flowi6 *fl6, int oif,
index 6a10608d9025850005c0933bdb4b2efb868f42dd..019d8ba9021e164fc1a2bfcdfe4a34954d3e8f1b 100644 (file)
@@ -1800,21 +1800,12 @@ void rt6_age_exceptions(struct fib6_info *rt,
        rcu_read_unlock_bh();
 }
 
-struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
-                              int oif, struct flowi6 *fl6,
-                              const struct sk_buff *skb, int flags)
+/* must be called with rcu lock held */
+struct fib6_info *fib6_table_lookup(struct net *net, struct fib6_table *table,
+                                   int oif, struct flowi6 *fl6, int strict)
 {
        struct fib6_node *fn, *saved_fn;
        struct fib6_info *f6i;
-       struct rt6_info *rt;
-       int strict = 0;
-
-       strict |= flags & RT6_LOOKUP_F_IFACE;
-       strict |= flags & RT6_LOOKUP_F_IGNORE_LINKSTATE;
-       if (net->ipv6.devconf_all->forwarding == 0)
-               strict |= RT6_LOOKUP_F_REACHABLE;
-
-       rcu_read_lock();
 
        fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
        saved_fn = fn;
@@ -1824,8 +1815,6 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 
 redo_rt6_select:
        f6i = rt6_select(net, fn, oif, strict);
-       if (f6i->fib6_nsiblings)
-               f6i = fib6_multipath_select(net, f6i, fl6, oif, skb, strict);
        if (f6i == net->ipv6.fib6_null_entry) {
                fn = fib6_backtrack(fn, &fl6->saddr);
                if (fn)
@@ -1838,6 +1827,28 @@ redo_rt6_select:
                }
        }
 
+       return f6i;
+}
+
+struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
+                              int oif, struct flowi6 *fl6,
+                              const struct sk_buff *skb, int flags)
+{
+       struct fib6_info *f6i;
+       struct rt6_info *rt;
+       int strict = 0;
+
+       strict |= flags & RT6_LOOKUP_F_IFACE;
+       strict |= flags & RT6_LOOKUP_F_IGNORE_LINKSTATE;
+       if (net->ipv6.devconf_all->forwarding == 0)
+               strict |= RT6_LOOKUP_F_REACHABLE;
+
+       rcu_read_lock();
+
+       f6i = fib6_table_lookup(net, table, oif, fl6, strict);
+       if (f6i->fib6_nsiblings)
+               f6i = fib6_multipath_select(net, f6i, fl6, oif, skb, strict);
+
        if (f6i == net->ipv6.fib6_null_entry) {
                rt = net->ipv6.ip6_null_entry;
                rcu_read_unlock();