fib_semantics.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * IPv4 Forwarding Information Base: semantics.
  7. *
  8. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. */
  15. #include <asm/uaccess.h>
  16. #include <linux/bitops.h>
  17. #include <linux/types.h>
  18. #include <linux/kernel.h>
  19. #include <linux/jiffies.h>
  20. #include <linux/mm.h>
  21. #include <linux/string.h>
  22. #include <linux/socket.h>
  23. #include <linux/sockios.h>
  24. #include <linux/errno.h>
  25. #include <linux/in.h>
  26. #include <linux/inet.h>
  27. #include <linux/inetdevice.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/if_arp.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/init.h>
  33. #include <linux/slab.h>
  34. #include <net/arp.h>
  35. #include <net/ip.h>
  36. #include <net/protocol.h>
  37. #include <net/route.h>
  38. #include <net/tcp.h>
  39. #include <net/sock.h>
  40. #include <net/ip_fib.h>
  41. #include <net/netlink.h>
  42. #include <net/nexthop.h>
  43. #include "fib_lookup.h"
  44. static DEFINE_SPINLOCK(fib_info_lock);
  45. static struct hlist_head *fib_info_hash;
  46. static struct hlist_head *fib_info_laddrhash;
  47. static unsigned int fib_info_hash_size;
  48. static unsigned int fib_info_cnt;
  49. #define DEVINDEX_HASHBITS 8
  50. #define DEVINDEX_HASHSIZE (1U << DEVINDEX_HASHBITS)
  51. static struct hlist_head fib_info_devhash[DEVINDEX_HASHSIZE];
  52. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  53. static DEFINE_SPINLOCK(fib_multipath_lock);
  54. #define for_nexthops(fi) { \
  55. int nhsel; const struct fib_nh *nh; \
  56. for (nhsel = 0, nh = (fi)->fib_nh; \
  57. nhsel < (fi)->fib_nhs; \
  58. nh++, nhsel++)
  59. #define change_nexthops(fi) { \
  60. int nhsel; struct fib_nh *nexthop_nh; \
  61. for (nhsel = 0, nexthop_nh = (struct fib_nh *)((fi)->fib_nh); \
  62. nhsel < (fi)->fib_nhs; \
  63. nexthop_nh++, nhsel++)
  64. #else /* CONFIG_IP_ROUTE_MULTIPATH */
  65. /* Hope, that gcc will optimize it to get rid of dummy loop */
  66. #define for_nexthops(fi) { \
  67. int nhsel; const struct fib_nh *nh = (fi)->fib_nh; \
  68. for (nhsel = 0; nhsel < 1; nhsel++)
  69. #define change_nexthops(fi) { \
  70. int nhsel; \
  71. struct fib_nh *nexthop_nh = (struct fib_nh *)((fi)->fib_nh); \
  72. for (nhsel = 0; nhsel < 1; nhsel++)
  73. #endif /* CONFIG_IP_ROUTE_MULTIPATH */
  74. #define endfor_nexthops(fi) }
  75. const struct fib_prop fib_props[RTN_MAX + 1] = {
  76. [RTN_UNSPEC] = {
  77. .error = 0,
  78. .scope = RT_SCOPE_NOWHERE,
  79. },
  80. [RTN_UNICAST] = {
  81. .error = 0,
  82. .scope = RT_SCOPE_UNIVERSE,
  83. },
  84. [RTN_LOCAL] = {
  85. .error = 0,
  86. .scope = RT_SCOPE_HOST,
  87. },
  88. [RTN_BROADCAST] = {
  89. .error = 0,
  90. .scope = RT_SCOPE_LINK,
  91. },
  92. [RTN_ANYCAST] = {
  93. .error = 0,
  94. .scope = RT_SCOPE_LINK,
  95. },
  96. [RTN_MULTICAST] = {
  97. .error = 0,
  98. .scope = RT_SCOPE_UNIVERSE,
  99. },
  100. [RTN_BLACKHOLE] = {
  101. .error = -EINVAL,
  102. .scope = RT_SCOPE_UNIVERSE,
  103. },
  104. [RTN_UNREACHABLE] = {
  105. .error = -EHOSTUNREACH,
  106. .scope = RT_SCOPE_UNIVERSE,
  107. },
  108. [RTN_PROHIBIT] = {
  109. .error = -EACCES,
  110. .scope = RT_SCOPE_UNIVERSE,
  111. },
  112. [RTN_THROW] = {
  113. .error = -EAGAIN,
  114. .scope = RT_SCOPE_UNIVERSE,
  115. },
  116. [RTN_NAT] = {
  117. .error = -EINVAL,
  118. .scope = RT_SCOPE_NOWHERE,
  119. },
  120. [RTN_XRESOLVE] = {
  121. .error = -EINVAL,
  122. .scope = RT_SCOPE_NOWHERE,
  123. },
  124. };
  125. /* Release a nexthop info record */
  126. static void free_fib_info_rcu(struct rcu_head *head)
  127. {
  128. struct fib_info *fi = container_of(head, struct fib_info, rcu);
  129. change_nexthops(fi) {
  130. if (nexthop_nh->nh_dev)
  131. dev_put(nexthop_nh->nh_dev);
  132. } endfor_nexthops(fi);
  133. release_net(fi->fib_net);
  134. if (fi->fib_metrics != (u32 *) dst_default_metrics)
  135. kfree(fi->fib_metrics);
  136. kfree(fi);
  137. }
  138. void free_fib_info(struct fib_info *fi)
  139. {
  140. if (fi->fib_dead == 0) {
  141. pr_warn("Freeing alive fib_info %p\n", fi);
  142. return;
  143. }
  144. fib_info_cnt--;
  145. call_rcu(&fi->rcu, free_fib_info_rcu);
  146. }
  147. void fib_release_info(struct fib_info *fi)
  148. {
  149. spin_lock_bh(&fib_info_lock);
  150. if (fi && --fi->fib_treeref == 0) {
  151. hlist_del(&fi->fib_hash);
  152. if (fi->fib_prefsrc)
  153. hlist_del(&fi->fib_lhash);
  154. change_nexthops(fi) {
  155. if (!nexthop_nh->nh_dev)
  156. continue;
  157. hlist_del(&nexthop_nh->nh_hash);
  158. } endfor_nexthops(fi)
  159. fi->fib_dead = 1;
  160. fib_info_put(fi);
  161. }
  162. spin_unlock_bh(&fib_info_lock);
  163. }
  164. static inline int nh_comp(const struct fib_info *fi, const struct fib_info *ofi)
  165. {
  166. const struct fib_nh *onh = ofi->fib_nh;
  167. for_nexthops(fi) {
  168. if (nh->nh_oif != onh->nh_oif ||
  169. nh->nh_gw != onh->nh_gw ||
  170. nh->nh_scope != onh->nh_scope ||
  171. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  172. nh->nh_weight != onh->nh_weight ||
  173. #endif
  174. #ifdef CONFIG_IP_ROUTE_CLASSID
  175. nh->nh_tclassid != onh->nh_tclassid ||
  176. #endif
  177. ((nh->nh_flags ^ onh->nh_flags) & ~RTNH_F_DEAD))
  178. return -1;
  179. onh++;
  180. } endfor_nexthops(fi);
  181. return 0;
  182. }
  183. static inline unsigned int fib_devindex_hashfn(unsigned int val)
  184. {
  185. unsigned int mask = DEVINDEX_HASHSIZE - 1;
  186. return (val ^
  187. (val >> DEVINDEX_HASHBITS) ^
  188. (val >> (DEVINDEX_HASHBITS * 2))) & mask;
  189. }
  190. static inline unsigned int fib_info_hashfn(const struct fib_info *fi)
  191. {
  192. unsigned int mask = (fib_info_hash_size - 1);
  193. unsigned int val = fi->fib_nhs;
  194. val ^= (fi->fib_protocol << 8) | fi->fib_scope;
  195. val ^= (__force u32)fi->fib_prefsrc;
  196. val ^= fi->fib_priority;
  197. for_nexthops(fi) {
  198. val ^= fib_devindex_hashfn(nh->nh_oif);
  199. } endfor_nexthops(fi)
  200. return (val ^ (val >> 7) ^ (val >> 12)) & mask;
  201. }
  202. static struct fib_info *fib_find_info(const struct fib_info *nfi)
  203. {
  204. struct hlist_head *head;
  205. struct hlist_node *node;
  206. struct fib_info *fi;
  207. unsigned int hash;
  208. hash = fib_info_hashfn(nfi);
  209. head = &fib_info_hash[hash];
  210. hlist_for_each_entry(fi, node, head, fib_hash) {
  211. if (!net_eq(fi->fib_net, nfi->fib_net))
  212. continue;
  213. if (fi->fib_nhs != nfi->fib_nhs)
  214. continue;
  215. if (nfi->fib_protocol == fi->fib_protocol &&
  216. nfi->fib_scope == fi->fib_scope &&
  217. nfi->fib_prefsrc == fi->fib_prefsrc &&
  218. nfi->fib_priority == fi->fib_priority &&
  219. memcmp(nfi->fib_metrics, fi->fib_metrics,
  220. sizeof(u32) * RTAX_MAX) == 0 &&
  221. ((nfi->fib_flags ^ fi->fib_flags) & ~RTNH_F_DEAD) == 0 &&
  222. (nfi->fib_nhs == 0 || nh_comp(fi, nfi) == 0))
  223. return fi;
  224. }
  225. return NULL;
  226. }
  227. /* Check, that the gateway is already configured.
  228. * Used only by redirect accept routine.
  229. */
  230. int ip_fib_check_default(__be32 gw, struct net_device *dev)
  231. {
  232. struct hlist_head *head;
  233. struct hlist_node *node;
  234. struct fib_nh *nh;
  235. unsigned int hash;
  236. spin_lock(&fib_info_lock);
  237. hash = fib_devindex_hashfn(dev->ifindex);
  238. head = &fib_info_devhash[hash];
  239. hlist_for_each_entry(nh, node, head, nh_hash) {
  240. if (nh->nh_dev == dev &&
  241. nh->nh_gw == gw &&
  242. !(nh->nh_flags & RTNH_F_DEAD)) {
  243. spin_unlock(&fib_info_lock);
  244. return 0;
  245. }
  246. }
  247. spin_unlock(&fib_info_lock);
  248. return -1;
  249. }
  250. static inline size_t fib_nlmsg_size(struct fib_info *fi)
  251. {
  252. size_t payload = NLMSG_ALIGN(sizeof(struct rtmsg))
  253. + nla_total_size(4) /* RTA_TABLE */
  254. + nla_total_size(4) /* RTA_DST */
  255. + nla_total_size(4) /* RTA_PRIORITY */
  256. + nla_total_size(4); /* RTA_PREFSRC */
  257. /* space for nested metrics */
  258. payload += nla_total_size((RTAX_MAX * nla_total_size(4)));
  259. if (fi->fib_nhs) {
  260. /* Also handles the special case fib_nhs == 1 */
  261. /* each nexthop is packed in an attribute */
  262. size_t nhsize = nla_total_size(sizeof(struct rtnexthop));
  263. /* may contain flow and gateway attribute */
  264. nhsize += 2 * nla_total_size(4);
  265. /* all nexthops are packed in a nested attribute */
  266. payload += nla_total_size(fi->fib_nhs * nhsize);
  267. }
  268. return payload;
  269. }
  270. void rtmsg_fib(int event, __be32 key, struct fib_alias *fa,
  271. int dst_len, u32 tb_id, struct nl_info *info,
  272. unsigned int nlm_flags)
  273. {
  274. struct sk_buff *skb;
  275. u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0;
  276. int err = -ENOBUFS;
  277. skb = nlmsg_new(fib_nlmsg_size(fa->fa_info), GFP_KERNEL);
  278. if (skb == NULL)
  279. goto errout;
  280. err = fib_dump_info(skb, info->pid, seq, event, tb_id,
  281. fa->fa_type, key, dst_len,
  282. fa->fa_tos, fa->fa_info, nlm_flags);
  283. if (err < 0) {
  284. /* -EMSGSIZE implies BUG in fib_nlmsg_size() */
  285. WARN_ON(err == -EMSGSIZE);
  286. kfree_skb(skb);
  287. goto errout;
  288. }
  289. rtnl_notify(skb, info->nl_net, info->pid, RTNLGRP_IPV4_ROUTE,
  290. info->nlh, GFP_KERNEL);
  291. return;
  292. errout:
  293. if (err < 0)
  294. rtnl_set_sk_err(info->nl_net, RTNLGRP_IPV4_ROUTE, err);
  295. }
  296. /* Return the first fib alias matching TOS with
  297. * priority less than or equal to PRIO.
  298. */
  299. struct fib_alias *fib_find_alias(struct list_head *fah, u8 tos, u32 prio)
  300. {
  301. if (fah) {
  302. struct fib_alias *fa;
  303. list_for_each_entry(fa, fah, fa_list) {
  304. if (fa->fa_tos > tos)
  305. continue;
  306. if (fa->fa_info->fib_priority >= prio ||
  307. fa->fa_tos < tos)
  308. return fa;
  309. }
  310. }
  311. return NULL;
  312. }
  313. int fib_detect_death(struct fib_info *fi, int order,
  314. struct fib_info **last_resort, int *last_idx, int dflt)
  315. {
  316. struct neighbour *n;
  317. int state = NUD_NONE;
  318. n = neigh_lookup(&arp_tbl, &fi->fib_nh[0].nh_gw, fi->fib_dev);
  319. if (n) {
  320. state = n->nud_state;
  321. neigh_release(n);
  322. }
  323. if (state == NUD_REACHABLE)
  324. return 0;
  325. if ((state & NUD_VALID) && order != dflt)
  326. return 0;
  327. if ((state & NUD_VALID) ||
  328. (*last_idx < 0 && order > dflt)) {
  329. *last_resort = fi;
  330. *last_idx = order;
  331. }
  332. return 1;
  333. }
  334. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  335. static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining)
  336. {
  337. int nhs = 0;
  338. while (rtnh_ok(rtnh, remaining)) {
  339. nhs++;
  340. rtnh = rtnh_next(rtnh, &remaining);
  341. }
  342. /* leftover implies invalid nexthop configuration, discard it */
  343. return remaining > 0 ? 0 : nhs;
  344. }
  345. static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
  346. int remaining, struct fib_config *cfg)
  347. {
  348. change_nexthops(fi) {
  349. int attrlen;
  350. if (!rtnh_ok(rtnh, remaining))
  351. return -EINVAL;
  352. nexthop_nh->nh_flags =
  353. (cfg->fc_flags & ~0xFF) | rtnh->rtnh_flags;
  354. nexthop_nh->nh_oif = rtnh->rtnh_ifindex;
  355. nexthop_nh->nh_weight = rtnh->rtnh_hops + 1;
  356. attrlen = rtnh_attrlen(rtnh);
  357. if (attrlen > 0) {
  358. struct nlattr *nla, *attrs = rtnh_attrs(rtnh);
  359. nla = nla_find(attrs, attrlen, RTA_GATEWAY);
  360. nexthop_nh->nh_gw = nla ? nla_get_be32(nla) : 0;
  361. #ifdef CONFIG_IP_ROUTE_CLASSID
  362. nla = nla_find(attrs, attrlen, RTA_FLOW);
  363. nexthop_nh->nh_tclassid = nla ? nla_get_u32(nla) : 0;
  364. #endif
  365. }
  366. rtnh = rtnh_next(rtnh, &remaining);
  367. } endfor_nexthops(fi);
  368. return 0;
  369. }
  370. #endif
  371. int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
  372. {
  373. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  374. struct rtnexthop *rtnh;
  375. int remaining;
  376. #endif
  377. if (cfg->fc_priority && cfg->fc_priority != fi->fib_priority)
  378. return 1;
  379. if (cfg->fc_oif || cfg->fc_gw) {
  380. if ((!cfg->fc_oif || cfg->fc_oif == fi->fib_nh->nh_oif) &&
  381. (!cfg->fc_gw || cfg->fc_gw == fi->fib_nh->nh_gw))
  382. return 0;
  383. return 1;
  384. }
  385. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  386. if (cfg->fc_mp == NULL)
  387. return 0;
  388. rtnh = cfg->fc_mp;
  389. remaining = cfg->fc_mp_len;
  390. for_nexthops(fi) {
  391. int attrlen;
  392. if (!rtnh_ok(rtnh, remaining))
  393. return -EINVAL;
  394. if (rtnh->rtnh_ifindex && rtnh->rtnh_ifindex != nh->nh_oif)
  395. return 1;
  396. attrlen = rtnh_attrlen(rtnh);
  397. if (attrlen < 0) {
  398. struct nlattr *nla, *attrs = rtnh_attrs(rtnh);
  399. nla = nla_find(attrs, attrlen, RTA_GATEWAY);
  400. if (nla && nla_get_be32(nla) != nh->nh_gw)
  401. return 1;
  402. #ifdef CONFIG_IP_ROUTE_CLASSID
  403. nla = nla_find(attrs, attrlen, RTA_FLOW);
  404. if (nla && nla_get_u32(nla) != nh->nh_tclassid)
  405. return 1;
  406. #endif
  407. }
  408. rtnh = rtnh_next(rtnh, &remaining);
  409. } endfor_nexthops(fi);
  410. #endif
  411. return 0;
  412. }
  413. /*
  414. * Picture
  415. * -------
  416. *
  417. * Semantics of nexthop is very messy by historical reasons.
  418. * We have to take into account, that:
  419. * a) gateway can be actually local interface address,
  420. * so that gatewayed route is direct.
  421. * b) gateway must be on-link address, possibly
  422. * described not by an ifaddr, but also by a direct route.
  423. * c) If both gateway and interface are specified, they should not
  424. * contradict.
  425. * d) If we use tunnel routes, gateway could be not on-link.
  426. *
  427. * Attempt to reconcile all of these (alas, self-contradictory) conditions
  428. * results in pretty ugly and hairy code with obscure logic.
  429. *
  430. * I chose to generalized it instead, so that the size
  431. * of code does not increase practically, but it becomes
  432. * much more general.
  433. * Every prefix is assigned a "scope" value: "host" is local address,
  434. * "link" is direct route,
  435. * [ ... "site" ... "interior" ... ]
  436. * and "universe" is true gateway route with global meaning.
  437. *
  438. * Every prefix refers to a set of "nexthop"s (gw, oif),
  439. * where gw must have narrower scope. This recursion stops
  440. * when gw has LOCAL scope or if "nexthop" is declared ONLINK,
  441. * which means that gw is forced to be on link.
  442. *
  443. * Code is still hairy, but now it is apparently logically
  444. * consistent and very flexible. F.e. as by-product it allows
  445. * to co-exists in peace independent exterior and interior
  446. * routing processes.
  447. *
  448. * Normally it looks as following.
  449. *
  450. * {universe prefix} -> (gw, oif) [scope link]
  451. * |
  452. * |-> {link prefix} -> (gw, oif) [scope local]
  453. * |
  454. * |-> {local prefix} (terminal node)
  455. */
  456. static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
  457. struct fib_nh *nh)
  458. {
  459. int err;
  460. struct net *net;
  461. struct net_device *dev;
  462. net = cfg->fc_nlinfo.nl_net;
  463. if (nh->nh_gw) {
  464. struct fib_result res;
  465. if (nh->nh_flags & RTNH_F_ONLINK) {
  466. if (cfg->fc_scope >= RT_SCOPE_LINK)
  467. return -EINVAL;
  468. if (inet_addr_type(net, nh->nh_gw) != RTN_UNICAST)
  469. return -EINVAL;
  470. dev = __dev_get_by_index(net, nh->nh_oif);
  471. if (!dev)
  472. return -ENODEV;
  473. if (!(dev->flags & IFF_UP))
  474. return -ENETDOWN;
  475. nh->nh_dev = dev;
  476. dev_hold(dev);
  477. nh->nh_scope = RT_SCOPE_LINK;
  478. return 0;
  479. }
  480. rcu_read_lock();
  481. {
  482. struct flowi4 fl4 = {
  483. .daddr = nh->nh_gw,
  484. .flowi4_scope = cfg->fc_scope + 1,
  485. .flowi4_oif = nh->nh_oif,
  486. .flowi4_iif = LOOPBACK_IFINDEX,
  487. };
  488. /* It is not necessary, but requires a bit of thinking */
  489. if (fl4.flowi4_scope < RT_SCOPE_LINK)
  490. fl4.flowi4_scope = RT_SCOPE_LINK;
  491. err = fib_lookup(net, &fl4, &res);
  492. if (err) {
  493. rcu_read_unlock();
  494. return err;
  495. }
  496. }
  497. err = -EINVAL;
  498. if (res.type != RTN_UNICAST && res.type != RTN_LOCAL)
  499. goto out;
  500. nh->nh_scope = res.scope;
  501. nh->nh_oif = FIB_RES_OIF(res);
  502. nh->nh_dev = dev = FIB_RES_DEV(res);
  503. if (!dev)
  504. goto out;
  505. dev_hold(dev);
  506. err = (dev->flags & IFF_UP) ? 0 : -ENETDOWN;
  507. } else {
  508. struct in_device *in_dev;
  509. if (nh->nh_flags & (RTNH_F_PERVASIVE | RTNH_F_ONLINK))
  510. return -EINVAL;
  511. rcu_read_lock();
  512. err = -ENODEV;
  513. in_dev = inetdev_by_index(net, nh->nh_oif);
  514. if (in_dev == NULL)
  515. goto out;
  516. err = -ENETDOWN;
  517. if (!(in_dev->dev->flags & IFF_UP))
  518. goto out;
  519. nh->nh_dev = in_dev->dev;
  520. dev_hold(nh->nh_dev);
  521. nh->nh_scope = RT_SCOPE_HOST;
  522. err = 0;
  523. }
  524. out:
  525. rcu_read_unlock();
  526. return err;
  527. }
  528. static inline unsigned int fib_laddr_hashfn(__be32 val)
  529. {
  530. unsigned int mask = (fib_info_hash_size - 1);
  531. return ((__force u32)val ^
  532. ((__force u32)val >> 7) ^
  533. ((__force u32)val >> 14)) & mask;
  534. }
  535. static struct hlist_head *fib_info_hash_alloc(int bytes)
  536. {
  537. if (bytes <= PAGE_SIZE)
  538. return kzalloc(bytes, GFP_KERNEL);
  539. else
  540. return (struct hlist_head *)
  541. __get_free_pages(GFP_KERNEL | __GFP_ZERO,
  542. get_order(bytes));
  543. }
  544. static void fib_info_hash_free(struct hlist_head *hash, int bytes)
  545. {
  546. if (!hash)
  547. return;
  548. if (bytes <= PAGE_SIZE)
  549. kfree(hash);
  550. else
  551. free_pages((unsigned long) hash, get_order(bytes));
  552. }
  553. static void fib_info_hash_move(struct hlist_head *new_info_hash,
  554. struct hlist_head *new_laddrhash,
  555. unsigned int new_size)
  556. {
  557. struct hlist_head *old_info_hash, *old_laddrhash;
  558. unsigned int old_size = fib_info_hash_size;
  559. unsigned int i, bytes;
  560. spin_lock_bh(&fib_info_lock);
  561. old_info_hash = fib_info_hash;
  562. old_laddrhash = fib_info_laddrhash;
  563. fib_info_hash_size = new_size;
  564. for (i = 0; i < old_size; i++) {
  565. struct hlist_head *head = &fib_info_hash[i];
  566. struct hlist_node *node, *n;
  567. struct fib_info *fi;
  568. hlist_for_each_entry_safe(fi, node, n, head, fib_hash) {
  569. struct hlist_head *dest;
  570. unsigned int new_hash;
  571. hlist_del(&fi->fib_hash);
  572. new_hash = fib_info_hashfn(fi);
  573. dest = &new_info_hash[new_hash];
  574. hlist_add_head(&fi->fib_hash, dest);
  575. }
  576. }
  577. fib_info_hash = new_info_hash;
  578. for (i = 0; i < old_size; i++) {
  579. struct hlist_head *lhead = &fib_info_laddrhash[i];
  580. struct hlist_node *node, *n;
  581. struct fib_info *fi;
  582. hlist_for_each_entry_safe(fi, node, n, lhead, fib_lhash) {
  583. struct hlist_head *ldest;
  584. unsigned int new_hash;
  585. hlist_del(&fi->fib_lhash);
  586. new_hash = fib_laddr_hashfn(fi->fib_prefsrc);
  587. ldest = &new_laddrhash[new_hash];
  588. hlist_add_head(&fi->fib_lhash, ldest);
  589. }
  590. }
  591. fib_info_laddrhash = new_laddrhash;
  592. spin_unlock_bh(&fib_info_lock);
  593. bytes = old_size * sizeof(struct hlist_head *);
  594. fib_info_hash_free(old_info_hash, bytes);
  595. fib_info_hash_free(old_laddrhash, bytes);
  596. }
  597. __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
  598. {
  599. nh->nh_saddr = inet_select_addr(nh->nh_dev,
  600. nh->nh_gw,
  601. nh->nh_parent->fib_scope);
  602. nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
  603. return nh->nh_saddr;
  604. }
  605. struct fib_info *fib_create_info(struct fib_config *cfg)
  606. {
  607. int err;
  608. struct fib_info *fi = NULL;
  609. struct fib_info *ofi;
  610. int nhs = 1;
  611. struct net *net = cfg->fc_nlinfo.nl_net;
  612. if (cfg->fc_type > RTN_MAX)
  613. goto err_inval;
  614. /* Fast check to catch the most weird cases */
  615. if (fib_props[cfg->fc_type].scope > cfg->fc_scope)
  616. goto err_inval;
  617. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  618. if (cfg->fc_mp) {
  619. nhs = fib_count_nexthops(cfg->fc_mp, cfg->fc_mp_len);
  620. if (nhs == 0)
  621. goto err_inval;
  622. }
  623. #endif
  624. err = -ENOBUFS;
  625. if (fib_info_cnt >= fib_info_hash_size) {
  626. unsigned int new_size = fib_info_hash_size << 1;
  627. struct hlist_head *new_info_hash;
  628. struct hlist_head *new_laddrhash;
  629. unsigned int bytes;
  630. if (!new_size)
  631. new_size = 1;
  632. bytes = new_size * sizeof(struct hlist_head *);
  633. new_info_hash = fib_info_hash_alloc(bytes);
  634. new_laddrhash = fib_info_hash_alloc(bytes);
  635. if (!new_info_hash || !new_laddrhash) {
  636. fib_info_hash_free(new_info_hash, bytes);
  637. fib_info_hash_free(new_laddrhash, bytes);
  638. } else
  639. fib_info_hash_move(new_info_hash, new_laddrhash, new_size);
  640. if (!fib_info_hash_size)
  641. goto failure;
  642. }
  643. fi = kzalloc(sizeof(*fi)+nhs*sizeof(struct fib_nh), GFP_KERNEL);
  644. if (fi == NULL)
  645. goto failure;
  646. fib_info_cnt++;
  647. if (cfg->fc_mx) {
  648. fi->fib_metrics = kzalloc(sizeof(u32) * RTAX_MAX, GFP_KERNEL);
  649. if (!fi->fib_metrics)
  650. goto failure;
  651. } else
  652. fi->fib_metrics = (u32 *) dst_default_metrics;
  653. fi->fib_net = hold_net(net);
  654. fi->fib_protocol = cfg->fc_protocol;
  655. fi->fib_scope = cfg->fc_scope;
  656. fi->fib_flags = cfg->fc_flags;
  657. fi->fib_priority = cfg->fc_priority;
  658. fi->fib_prefsrc = cfg->fc_prefsrc;
  659. fi->fib_nhs = nhs;
  660. change_nexthops(fi) {
  661. nexthop_nh->nh_parent = fi;
  662. } endfor_nexthops(fi)
  663. if (cfg->fc_mx) {
  664. struct nlattr *nla;
  665. int remaining;
  666. nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) {
  667. int type = nla_type(nla);
  668. if (type) {
  669. if (type > RTAX_MAX)
  670. goto err_inval;
  671. fi->fib_metrics[type - 1] = nla_get_u32(nla);
  672. }
  673. }
  674. }
  675. if (cfg->fc_mp) {
  676. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  677. err = fib_get_nhs(fi, cfg->fc_mp, cfg->fc_mp_len, cfg);
  678. if (err != 0)
  679. goto failure;
  680. if (cfg->fc_oif && fi->fib_nh->nh_oif != cfg->fc_oif)
  681. goto err_inval;
  682. if (cfg->fc_gw && fi->fib_nh->nh_gw != cfg->fc_gw)
  683. goto err_inval;
  684. #ifdef CONFIG_IP_ROUTE_CLASSID
  685. if (cfg->fc_flow && fi->fib_nh->nh_tclassid != cfg->fc_flow)
  686. goto err_inval;
  687. #endif
  688. #else
  689. goto err_inval;
  690. #endif
  691. } else {
  692. struct fib_nh *nh = fi->fib_nh;
  693. nh->nh_oif = cfg->fc_oif;
  694. nh->nh_gw = cfg->fc_gw;
  695. nh->nh_flags = cfg->fc_flags;
  696. #ifdef CONFIG_IP_ROUTE_CLASSID
  697. nh->nh_tclassid = cfg->fc_flow;
  698. #endif
  699. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  700. nh->nh_weight = 1;
  701. #endif
  702. }
  703. if (fib_props[cfg->fc_type].error) {
  704. if (cfg->fc_gw || cfg->fc_oif || cfg->fc_mp)
  705. goto err_inval;
  706. goto link_it;
  707. } else {
  708. switch (cfg->fc_type) {
  709. case RTN_UNICAST:
  710. case RTN_LOCAL:
  711. case RTN_BROADCAST:
  712. case RTN_ANYCAST:
  713. case RTN_MULTICAST:
  714. break;
  715. default:
  716. goto err_inval;
  717. }
  718. }
  719. if (cfg->fc_scope > RT_SCOPE_HOST)
  720. goto err_inval;
  721. if (cfg->fc_scope == RT_SCOPE_HOST) {
  722. struct fib_nh *nh = fi->fib_nh;
  723. /* Local address is added. */
  724. if (nhs != 1 || nh->nh_gw)
  725. goto err_inval;
  726. nh->nh_scope = RT_SCOPE_NOWHERE;
  727. nh->nh_dev = dev_get_by_index(net, fi->fib_nh->nh_oif);
  728. err = -ENODEV;
  729. if (nh->nh_dev == NULL)
  730. goto failure;
  731. } else {
  732. change_nexthops(fi) {
  733. err = fib_check_nh(cfg, fi, nexthop_nh);
  734. if (err != 0)
  735. goto failure;
  736. } endfor_nexthops(fi)
  737. }
  738. if (fi->fib_prefsrc) {
  739. if (cfg->fc_type != RTN_LOCAL || !cfg->fc_dst ||
  740. fi->fib_prefsrc != cfg->fc_dst)
  741. if (inet_addr_type(net, fi->fib_prefsrc) != RTN_LOCAL)
  742. goto err_inval;
  743. }
  744. change_nexthops(fi) {
  745. fib_info_update_nh_saddr(net, nexthop_nh);
  746. } endfor_nexthops(fi)
  747. link_it:
  748. ofi = fib_find_info(fi);
  749. if (ofi) {
  750. fi->fib_dead = 1;
  751. free_fib_info(fi);
  752. ofi->fib_treeref++;
  753. return ofi;
  754. }
  755. fi->fib_treeref++;
  756. atomic_inc(&fi->fib_clntref);
  757. spin_lock_bh(&fib_info_lock);
  758. hlist_add_head(&fi->fib_hash,
  759. &fib_info_hash[fib_info_hashfn(fi)]);
  760. if (fi->fib_prefsrc) {
  761. struct hlist_head *head;
  762. head = &fib_info_laddrhash[fib_laddr_hashfn(fi->fib_prefsrc)];
  763. hlist_add_head(&fi->fib_lhash, head);
  764. }
  765. change_nexthops(fi) {
  766. struct hlist_head *head;
  767. unsigned int hash;
  768. if (!nexthop_nh->nh_dev)
  769. continue;
  770. hash = fib_devindex_hashfn(nexthop_nh->nh_dev->ifindex);
  771. head = &fib_info_devhash[hash];
  772. hlist_add_head(&nexthop_nh->nh_hash, head);
  773. } endfor_nexthops(fi)
  774. spin_unlock_bh(&fib_info_lock);
  775. return fi;
  776. err_inval:
  777. err = -EINVAL;
  778. failure:
  779. if (fi) {
  780. fi->fib_dead = 1;
  781. free_fib_info(fi);
  782. }
  783. return ERR_PTR(err);
  784. }
  785. int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
  786. u32 tb_id, u8 type, __be32 dst, int dst_len, u8 tos,
  787. struct fib_info *fi, unsigned int flags)
  788. {
  789. struct nlmsghdr *nlh;
  790. struct rtmsg *rtm;
  791. nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), flags);
  792. if (nlh == NULL)
  793. return -EMSGSIZE;
  794. rtm = nlmsg_data(nlh);
  795. rtm->rtm_family = AF_INET;
  796. rtm->rtm_dst_len = dst_len;
  797. rtm->rtm_src_len = 0;
  798. rtm->rtm_tos = tos;
  799. if (tb_id < 256)
  800. rtm->rtm_table = tb_id;
  801. else
  802. rtm->rtm_table = RT_TABLE_COMPAT;
  803. NLA_PUT_U32(skb, RTA_TABLE, tb_id);
  804. rtm->rtm_type = type;
  805. rtm->rtm_flags = fi->fib_flags;
  806. rtm->rtm_scope = fi->fib_scope;
  807. rtm->rtm_protocol = fi->fib_protocol;
  808. if (rtm->rtm_dst_len)
  809. NLA_PUT_BE32(skb, RTA_DST, dst);
  810. if (fi->fib_priority)
  811. NLA_PUT_U32(skb, RTA_PRIORITY, fi->fib_priority);
  812. if (rtnetlink_put_metrics(skb, fi->fib_metrics) < 0)
  813. goto nla_put_failure;
  814. if (fi->fib_prefsrc)
  815. NLA_PUT_BE32(skb, RTA_PREFSRC, fi->fib_prefsrc);
  816. if (fi->fib_nhs == 1) {
  817. if (fi->fib_nh->nh_gw)
  818. NLA_PUT_BE32(skb, RTA_GATEWAY, fi->fib_nh->nh_gw);
  819. if (fi->fib_nh->nh_oif)
  820. NLA_PUT_U32(skb, RTA_OIF, fi->fib_nh->nh_oif);
  821. #ifdef CONFIG_IP_ROUTE_CLASSID
  822. if (fi->fib_nh[0].nh_tclassid)
  823. NLA_PUT_U32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid);
  824. #endif
  825. }
  826. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  827. if (fi->fib_nhs > 1) {
  828. struct rtnexthop *rtnh;
  829. struct nlattr *mp;
  830. mp = nla_nest_start(skb, RTA_MULTIPATH);
  831. if (mp == NULL)
  832. goto nla_put_failure;
  833. for_nexthops(fi) {
  834. rtnh = nla_reserve_nohdr(skb, sizeof(*rtnh));
  835. if (rtnh == NULL)
  836. goto nla_put_failure;
  837. rtnh->rtnh_flags = nh->nh_flags & 0xFF;
  838. rtnh->rtnh_hops = nh->nh_weight - 1;
  839. rtnh->rtnh_ifindex = nh->nh_oif;
  840. if (nh->nh_gw)
  841. NLA_PUT_BE32(skb, RTA_GATEWAY, nh->nh_gw);
  842. #ifdef CONFIG_IP_ROUTE_CLASSID
  843. if (nh->nh_tclassid)
  844. NLA_PUT_U32(skb, RTA_FLOW, nh->nh_tclassid);
  845. #endif
  846. /* length of rtnetlink header + attributes */
  847. rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *) rtnh;
  848. } endfor_nexthops(fi);
  849. nla_nest_end(skb, mp);
  850. }
  851. #endif
  852. return nlmsg_end(skb, nlh);
  853. nla_put_failure:
  854. nlmsg_cancel(skb, nlh);
  855. return -EMSGSIZE;
  856. }
  857. /*
  858. * Update FIB if:
  859. * - local address disappeared -> we must delete all the entries
  860. * referring to it.
  861. * - device went down -> we must shutdown all nexthops going via it.
  862. */
  863. int fib_sync_down_addr(struct net *net, __be32 local)
  864. {
  865. int ret = 0;
  866. unsigned int hash = fib_laddr_hashfn(local);
  867. struct hlist_head *head = &fib_info_laddrhash[hash];
  868. struct hlist_node *node;
  869. struct fib_info *fi;
  870. if (fib_info_laddrhash == NULL || local == 0)
  871. return 0;
  872. hlist_for_each_entry(fi, node, head, fib_lhash) {
  873. if (!net_eq(fi->fib_net, net))
  874. continue;
  875. if (fi->fib_prefsrc == local) {
  876. fi->fib_flags |= RTNH_F_DEAD;
  877. ret++;
  878. }
  879. }
  880. return ret;
  881. }
  882. int fib_sync_down_dev(struct net_device *dev, int force)
  883. {
  884. int ret = 0;
  885. int scope = RT_SCOPE_NOWHERE;
  886. struct fib_info *prev_fi = NULL;
  887. unsigned int hash = fib_devindex_hashfn(dev->ifindex);
  888. struct hlist_head *head = &fib_info_devhash[hash];
  889. struct hlist_node *node;
  890. struct fib_nh *nh;
  891. if (force)
  892. scope = -1;
  893. hlist_for_each_entry(nh, node, head, nh_hash) {
  894. struct fib_info *fi = nh->nh_parent;
  895. int dead;
  896. BUG_ON(!fi->fib_nhs);
  897. if (nh->nh_dev != dev || fi == prev_fi)
  898. continue;
  899. prev_fi = fi;
  900. dead = 0;
  901. change_nexthops(fi) {
  902. if (nexthop_nh->nh_flags & RTNH_F_DEAD)
  903. dead++;
  904. else if (nexthop_nh->nh_dev == dev &&
  905. nexthop_nh->nh_scope != scope) {
  906. nexthop_nh->nh_flags |= RTNH_F_DEAD;
  907. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  908. spin_lock_bh(&fib_multipath_lock);
  909. fi->fib_power -= nexthop_nh->nh_power;
  910. nexthop_nh->nh_power = 0;
  911. spin_unlock_bh(&fib_multipath_lock);
  912. #endif
  913. dead++;
  914. }
  915. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  916. if (force > 1 && nexthop_nh->nh_dev == dev) {
  917. dead = fi->fib_nhs;
  918. break;
  919. }
  920. #endif
  921. } endfor_nexthops(fi)
  922. if (dead == fi->fib_nhs) {
  923. fi->fib_flags |= RTNH_F_DEAD;
  924. ret++;
  925. }
  926. }
  927. return ret;
  928. }
  929. /* Must be invoked inside of an RCU protected region. */
  930. void fib_select_default(struct fib_result *res)
  931. {
  932. struct fib_info *fi = NULL, *last_resort = NULL;
  933. struct list_head *fa_head = res->fa_head;
  934. struct fib_table *tb = res->table;
  935. int order = -1, last_idx = -1;
  936. struct fib_alias *fa;
  937. list_for_each_entry_rcu(fa, fa_head, fa_list) {
  938. struct fib_info *next_fi = fa->fa_info;
  939. if (next_fi->fib_scope != res->scope ||
  940. fa->fa_type != RTN_UNICAST)
  941. continue;
  942. if (next_fi->fib_priority > res->fi->fib_priority)
  943. break;
  944. if (!next_fi->fib_nh[0].nh_gw ||
  945. next_fi->fib_nh[0].nh_scope != RT_SCOPE_LINK)
  946. continue;
  947. fib_alias_accessed(fa);
  948. if (fi == NULL) {
  949. if (next_fi != res->fi)
  950. break;
  951. } else if (!fib_detect_death(fi, order, &last_resort,
  952. &last_idx, tb->tb_default)) {
  953. fib_result_assign(res, fi);
  954. tb->tb_default = order;
  955. goto out;
  956. }
  957. fi = next_fi;
  958. order++;
  959. }
  960. if (order <= 0 || fi == NULL) {
  961. tb->tb_default = -1;
  962. goto out;
  963. }
  964. if (!fib_detect_death(fi, order, &last_resort, &last_idx,
  965. tb->tb_default)) {
  966. fib_result_assign(res, fi);
  967. tb->tb_default = order;
  968. goto out;
  969. }
  970. if (last_idx >= 0)
  971. fib_result_assign(res, last_resort);
  972. tb->tb_default = last_idx;
  973. out:
  974. return;
  975. }
  976. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  977. /*
  978. * Dead device goes up. We wake up dead nexthops.
  979. * It takes sense only on multipath routes.
  980. */
  981. int fib_sync_up(struct net_device *dev)
  982. {
  983. struct fib_info *prev_fi;
  984. unsigned int hash;
  985. struct hlist_head *head;
  986. struct hlist_node *node;
  987. struct fib_nh *nh;
  988. int ret;
  989. if (!(dev->flags & IFF_UP))
  990. return 0;
  991. prev_fi = NULL;
  992. hash = fib_devindex_hashfn(dev->ifindex);
  993. head = &fib_info_devhash[hash];
  994. ret = 0;
  995. hlist_for_each_entry(nh, node, head, nh_hash) {
  996. struct fib_info *fi = nh->nh_parent;
  997. int alive;
  998. BUG_ON(!fi->fib_nhs);
  999. if (nh->nh_dev != dev || fi == prev_fi)
  1000. continue;
  1001. prev_fi = fi;
  1002. alive = 0;
  1003. change_nexthops(fi) {
  1004. if (!(nexthop_nh->nh_flags & RTNH_F_DEAD)) {
  1005. alive++;
  1006. continue;
  1007. }
  1008. if (nexthop_nh->nh_dev == NULL ||
  1009. !(nexthop_nh->nh_dev->flags & IFF_UP))
  1010. continue;
  1011. if (nexthop_nh->nh_dev != dev ||
  1012. !__in_dev_get_rtnl(dev))
  1013. continue;
  1014. alive++;
  1015. spin_lock_bh(&fib_multipath_lock);
  1016. nexthop_nh->nh_power = 0;
  1017. nexthop_nh->nh_flags &= ~RTNH_F_DEAD;
  1018. spin_unlock_bh(&fib_multipath_lock);
  1019. } endfor_nexthops(fi)
  1020. if (alive > 0) {
  1021. fi->fib_flags &= ~RTNH_F_DEAD;
  1022. ret++;
  1023. }
  1024. }
  1025. return ret;
  1026. }
  1027. /*
  1028. * The algorithm is suboptimal, but it provides really
  1029. * fair weighted route distribution.
  1030. */
  1031. void fib_select_multipath(struct fib_result *res)
  1032. {
  1033. struct fib_info *fi = res->fi;
  1034. int w;
  1035. spin_lock_bh(&fib_multipath_lock);
  1036. if (fi->fib_power <= 0) {
  1037. int power = 0;
  1038. change_nexthops(fi) {
  1039. if (!(nexthop_nh->nh_flags & RTNH_F_DEAD)) {
  1040. power += nexthop_nh->nh_weight;
  1041. nexthop_nh->nh_power = nexthop_nh->nh_weight;
  1042. }
  1043. } endfor_nexthops(fi);
  1044. fi->fib_power = power;
  1045. if (power <= 0) {
  1046. spin_unlock_bh(&fib_multipath_lock);
  1047. /* Race condition: route has just become dead. */
  1048. res->nh_sel = 0;
  1049. return;
  1050. }
  1051. }
  1052. /* w should be random number [0..fi->fib_power-1],
  1053. * it is pretty bad approximation.
  1054. */
  1055. w = jiffies % fi->fib_power;
  1056. change_nexthops(fi) {
  1057. if (!(nexthop_nh->nh_flags & RTNH_F_DEAD) &&
  1058. nexthop_nh->nh_power) {
  1059. w -= nexthop_nh->nh_power;
  1060. if (w <= 0) {
  1061. nexthop_nh->nh_power--;
  1062. fi->fib_power--;
  1063. res->nh_sel = nhsel;
  1064. spin_unlock_bh(&fib_multipath_lock);
  1065. return;
  1066. }
  1067. }
  1068. } endfor_nexthops(fi);
  1069. /* Race condition: route has just become dead. */
  1070. res->nh_sel = 0;
  1071. spin_unlock_bh(&fib_multipath_lock);
  1072. }
  1073. #endif