fib_semantics.c 29 KB

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