net: Refactor path selection in __ip_route_output_key_hash
authorDavid Ahern <dsa@cumulusnetworks.com>
Mon, 5 Oct 2015 15:51:25 +0000 (08:51 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 7 Oct 2015 11:27:44 +0000 (04:27 -0700)
VRF device needs the same path selection following lookup to set source
address. Rather than duplicating code, move existing code into a
function that is exported to modules.

Code move only; no functional change.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip_fib.h
net/ipv4/fib_semantics.c
net/ipv4/route.c

index 7a51fd8d99e45d6e019dc0e4ff89267050974a9f..ac5c6e80586a446946e20b27ab1e0f78d5b94fc3 100644 (file)
@@ -329,6 +329,8 @@ static inline int fib_multipath_hash(__be32 saddr, __be32 daddr)
 }
 
 void fib_select_multipath(struct fib_result *res, int hash);
+void fib_select_path(struct net *net, struct fib_result *res,
+                    struct flowi4 *fl4, int mp_hash);
 
 /* Exported by fib_trie.c */
 void fib_trie_init(void);
index 7bd698c3bd3a4ceebfb291096ef8e9d7ae222f38..af77298c8b4f01594fa1c98173ef26068ef874a5 100644 (file)
@@ -1557,3 +1557,24 @@ void fib_select_multipath(struct fib_result *res, int hash)
        res->nh_sel = 0;
 }
 #endif
+
+void fib_select_path(struct net *net, struct fib_result *res,
+                    struct flowi4 *fl4, int mp_hash)
+{
+#ifdef CONFIG_IP_ROUTE_MULTIPATH
+       if (res->fi->fib_nhs > 1 && fl4->flowi4_oif == 0) {
+               if (mp_hash < 0)
+                       mp_hash = fib_multipath_hash(fl4->saddr, fl4->daddr);
+               fib_select_multipath(res, mp_hash);
+       }
+       else
+#endif
+       if (!res->prefixlen &&
+           res->table->tb_num_default > 1 &&
+           res->type == RTN_UNICAST && !fl4->flowi4_oif)
+               fib_select_default(fl4, res);
+
+       if (!fl4->saddr)
+               fl4->saddr = FIB_RES_PREFSRC(net, *res);
+}
+EXPORT_SYMBOL_GPL(fib_select_path);
index 54297d3a05590861ddf480a6fbe1499c0fdd4a8f..54e6f456a760b35928e094ef29174a8d77c281a5 100644 (file)
@@ -2238,21 +2238,7 @@ struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
                goto make_route;
        }
 
-#ifdef CONFIG_IP_ROUTE_MULTIPATH
-       if (res.fi->fib_nhs > 1 && fl4->flowi4_oif == 0) {
-               if (mp_hash < 0)
-                       mp_hash = fib_multipath_hash(fl4->saddr, fl4->daddr);
-               fib_select_multipath(&res, mp_hash);
-       }
-       else
-#endif
-       if (!res.prefixlen &&
-           res.table->tb_num_default > 1 &&
-           res.type == RTN_UNICAST && !fl4->flowi4_oif)
-               fib_select_default(fl4, &res);
-
-       if (!fl4->saddr)
-               fl4->saddr = FIB_RES_PREFSRC(net, res);
+       fib_select_path(net, &res, fl4, mp_hash);
 
        dev_out = FIB_RES_DEV(res);
        fl4->flowi4_oif = dev_out->ifindex;