aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/ip_fib.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/ip_fib.h')
-rw-r--r--include/net/ip_fib.h50
1 files changed, 29 insertions, 21 deletions
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 09a819ee2151..5bd120e4bc0a 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -222,16 +222,19 @@ static inline struct fib_table *fib_new_table(struct net *net, u32 id)
222static inline int fib_lookup(struct net *net, const struct flowi4 *flp, 222static inline int fib_lookup(struct net *net, const struct flowi4 *flp,
223 struct fib_result *res) 223 struct fib_result *res)
224{ 224{
225 struct fib_table *table; 225 int err = -ENETUNREACH;
226
227 rcu_read_lock();
228
229 if (!fib_table_lookup(fib_get_table(net, RT_TABLE_LOCAL), flp, res,
230 FIB_LOOKUP_NOREF) ||
231 !fib_table_lookup(fib_get_table(net, RT_TABLE_MAIN), flp, res,
232 FIB_LOOKUP_NOREF))
233 err = 0;
226 234
227 table = fib_get_table(net, RT_TABLE_LOCAL); 235 rcu_read_unlock();
228 if (!fib_table_lookup(table, flp, res, FIB_LOOKUP_NOREF))
229 return 0;
230 236
231 table = fib_get_table(net, RT_TABLE_MAIN); 237 return err;
232 if (!fib_table_lookup(table, flp, res, FIB_LOOKUP_NOREF))
233 return 0;
234 return -ENETUNREACH;
235} 238}
236 239
237#else /* CONFIG_IP_MULTIPLE_TABLES */ 240#else /* CONFIG_IP_MULTIPLE_TABLES */
@@ -247,20 +250,25 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp,
247 struct fib_result *res) 250 struct fib_result *res)
248{ 251{
249 if (!net->ipv4.fib_has_custom_rules) { 252 if (!net->ipv4.fib_has_custom_rules) {
253 int err = -ENETUNREACH;
254
255 rcu_read_lock();
256
250 res->tclassid = 0; 257 res->tclassid = 0;
251 if (net->ipv4.fib_local && 258 if ((net->ipv4.fib_local &&
252 !fib_table_lookup(net->ipv4.fib_local, flp, res, 259 !fib_table_lookup(net->ipv4.fib_local, flp, res,
253 FIB_LOOKUP_NOREF)) 260 FIB_LOOKUP_NOREF)) ||
254 return 0; 261 (net->ipv4.fib_main &&
255 if (net->ipv4.fib_main && 262 !fib_table_lookup(net->ipv4.fib_main, flp, res,
256 !fib_table_lookup(net->ipv4.fib_main, flp, res, 263 FIB_LOOKUP_NOREF)) ||
257 FIB_LOOKUP_NOREF)) 264 (net->ipv4.fib_default &&
258 return 0; 265 !fib_table_lookup(net->ipv4.fib_default, flp, res,
259 if (net->ipv4.fib_default && 266 FIB_LOOKUP_NOREF)))
260 !fib_table_lookup(net->ipv4.fib_default, flp, res, 267 err = 0;
261 FIB_LOOKUP_NOREF)) 268
262 return 0; 269 rcu_read_unlock();
263 return -ENETUNREACH; 270
271 return err;
264 } 272 }
265 return __fib_lookup(net, flp, res); 273 return __fib_lookup(net, flp, res);
266} 274}