ip6_fib.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. /*
  2. * Linux INET6 implementation
  3. * Forwarding Information Database
  4. *
  5. * Authors:
  6. * Pedro Roque <roque@di.fc.ul.pt>
  7. *
  8. * $Id: ip6_fib.c,v 1.25 2001/10/31 21:55:55 davem Exp $
  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. /*
  16. * Changes:
  17. * Yuji SEKIYA @USAGI: Support default route on router node;
  18. * remove ip6_null_entry from the top of
  19. * routing table.
  20. */
  21. #include <linux/errno.h>
  22. #include <linux/types.h>
  23. #include <linux/net.h>
  24. #include <linux/route.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/in6.h>
  27. #include <linux/init.h>
  28. #include <linux/list.h>
  29. #ifdef CONFIG_PROC_FS
  30. #include <linux/proc_fs.h>
  31. #endif
  32. #include <net/ipv6.h>
  33. #include <net/ndisc.h>
  34. #include <net/addrconf.h>
  35. #include <net/ip6_fib.h>
  36. #include <net/ip6_route.h>
  37. #define RT6_DEBUG 2
  38. #if RT6_DEBUG >= 3
  39. #define RT6_TRACE(x...) printk(KERN_DEBUG x)
  40. #else
  41. #define RT6_TRACE(x...) do { ; } while (0)
  42. #endif
  43. struct rt6_statistics rt6_stats;
  44. static kmem_cache_t * fib6_node_kmem __read_mostly;
  45. enum fib_walk_state_t
  46. {
  47. #ifdef CONFIG_IPV6_SUBTREES
  48. FWS_S,
  49. #endif
  50. FWS_L,
  51. FWS_R,
  52. FWS_C,
  53. FWS_U
  54. };
  55. struct fib6_cleaner_t
  56. {
  57. struct fib6_walker_t w;
  58. int (*func)(struct rt6_info *, void *arg);
  59. void *arg;
  60. };
  61. static DEFINE_RWLOCK(fib6_walker_lock);
  62. #ifdef CONFIG_IPV6_SUBTREES
  63. #define FWS_INIT FWS_S
  64. #else
  65. #define FWS_INIT FWS_L
  66. #endif
  67. static void fib6_prune_clones(struct fib6_node *fn, struct rt6_info *rt);
  68. static struct rt6_info * fib6_find_prefix(struct fib6_node *fn);
  69. static struct fib6_node * fib6_repair_tree(struct fib6_node *fn);
  70. static int fib6_walk(struct fib6_walker_t *w);
  71. static int fib6_walk_continue(struct fib6_walker_t *w);
  72. /*
  73. * A routing update causes an increase of the serial number on the
  74. * affected subtree. This allows for cached routes to be asynchronously
  75. * tested when modifications are made to the destination cache as a
  76. * result of redirects, path MTU changes, etc.
  77. */
  78. static __u32 rt_sernum;
  79. static DEFINE_TIMER(ip6_fib_timer, fib6_run_gc, 0, 0);
  80. static struct fib6_walker_t fib6_walker_list = {
  81. .prev = &fib6_walker_list,
  82. .next = &fib6_walker_list,
  83. };
  84. #define FOR_WALKERS(w) for ((w)=fib6_walker_list.next; (w) != &fib6_walker_list; (w)=(w)->next)
  85. static inline void fib6_walker_link(struct fib6_walker_t *w)
  86. {
  87. write_lock_bh(&fib6_walker_lock);
  88. w->next = fib6_walker_list.next;
  89. w->prev = &fib6_walker_list;
  90. w->next->prev = w;
  91. w->prev->next = w;
  92. write_unlock_bh(&fib6_walker_lock);
  93. }
  94. static inline void fib6_walker_unlink(struct fib6_walker_t *w)
  95. {
  96. write_lock_bh(&fib6_walker_lock);
  97. w->next->prev = w->prev;
  98. w->prev->next = w->next;
  99. w->prev = w->next = w;
  100. write_unlock_bh(&fib6_walker_lock);
  101. }
  102. static __inline__ u32 fib6_new_sernum(void)
  103. {
  104. u32 n = ++rt_sernum;
  105. if ((__s32)n <= 0)
  106. rt_sernum = n = 1;
  107. return n;
  108. }
  109. /*
  110. * Auxiliary address test functions for the radix tree.
  111. *
  112. * These assume a 32bit processor (although it will work on
  113. * 64bit processors)
  114. */
  115. /*
  116. * test bit
  117. */
  118. static __inline__ int addr_bit_set(void *token, int fn_bit)
  119. {
  120. __u32 *addr = token;
  121. return htonl(1 << ((~fn_bit)&0x1F)) & addr[fn_bit>>5];
  122. }
  123. static __inline__ struct fib6_node * node_alloc(void)
  124. {
  125. struct fib6_node *fn;
  126. if ((fn = kmem_cache_alloc(fib6_node_kmem, SLAB_ATOMIC)) != NULL)
  127. memset(fn, 0, sizeof(struct fib6_node));
  128. return fn;
  129. }
  130. static __inline__ void node_free(struct fib6_node * fn)
  131. {
  132. kmem_cache_free(fib6_node_kmem, fn);
  133. }
  134. static __inline__ void rt6_release(struct rt6_info *rt)
  135. {
  136. if (atomic_dec_and_test(&rt->rt6i_ref))
  137. dst_free(&rt->u.dst);
  138. }
  139. static struct fib6_table fib6_main_tbl = {
  140. .tb6_id = RT6_TABLE_MAIN,
  141. .tb6_lock = RW_LOCK_UNLOCKED,
  142. .tb6_root = {
  143. .leaf = &ip6_null_entry,
  144. .fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO,
  145. },
  146. };
  147. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  148. #define FIB_TABLE_HASHSZ 256
  149. #else
  150. #define FIB_TABLE_HASHSZ 1
  151. #endif
  152. static struct hlist_head fib_table_hash[FIB_TABLE_HASHSZ];
  153. static void fib6_link_table(struct fib6_table *tb)
  154. {
  155. unsigned int h;
  156. h = tb->tb6_id & (FIB_TABLE_HASHSZ - 1);
  157. /*
  158. * No protection necessary, this is the only list mutatation
  159. * operation, tables never disappear once they exist.
  160. */
  161. hlist_add_head_rcu(&tb->tb6_hlist, &fib_table_hash[h]);
  162. }
  163. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  164. static struct fib6_table fib6_local_tbl = {
  165. .tb6_id = RT6_TABLE_LOCAL,
  166. .tb6_lock = RW_LOCK_UNLOCKED,
  167. .tb6_root = {
  168. .leaf = &ip6_null_entry,
  169. .fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO,
  170. },
  171. };
  172. static struct fib6_table *fib6_alloc_table(u32 id)
  173. {
  174. struct fib6_table *table;
  175. table = kzalloc(sizeof(*table), GFP_ATOMIC);
  176. if (table != NULL) {
  177. table->tb6_id = id;
  178. table->tb6_lock = RW_LOCK_UNLOCKED;
  179. table->tb6_root.leaf = &ip6_null_entry;
  180. table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
  181. }
  182. return table;
  183. }
  184. struct fib6_table *fib6_new_table(u32 id)
  185. {
  186. struct fib6_table *tb;
  187. if (id == 0)
  188. id = RT6_TABLE_MAIN;
  189. tb = fib6_get_table(id);
  190. if (tb)
  191. return tb;
  192. tb = fib6_alloc_table(id);
  193. if (tb != NULL)
  194. fib6_link_table(tb);
  195. return tb;
  196. }
  197. struct fib6_table *fib6_get_table(u32 id)
  198. {
  199. struct fib6_table *tb;
  200. struct hlist_node *node;
  201. unsigned int h;
  202. if (id == 0)
  203. id = RT6_TABLE_MAIN;
  204. h = id & (FIB_TABLE_HASHSZ - 1);
  205. rcu_read_lock();
  206. hlist_for_each_entry_rcu(tb, node, &fib_table_hash[h], tb6_hlist) {
  207. if (tb->tb6_id == id) {
  208. rcu_read_unlock();
  209. return tb;
  210. }
  211. }
  212. rcu_read_unlock();
  213. return NULL;
  214. }
  215. static void __init fib6_tables_init(void)
  216. {
  217. fib6_link_table(&fib6_main_tbl);
  218. fib6_link_table(&fib6_local_tbl);
  219. }
  220. #else
  221. struct fib6_table *fib6_new_table(u32 id)
  222. {
  223. return fib6_get_table(id);
  224. }
  225. struct fib6_table *fib6_get_table(u32 id)
  226. {
  227. return &fib6_main_tbl;
  228. }
  229. struct dst_entry *fib6_rule_lookup(struct flowi *fl, int flags,
  230. pol_lookup_t lookup)
  231. {
  232. return (struct dst_entry *) lookup(&fib6_main_tbl, fl, flags);
  233. }
  234. static void __init fib6_tables_init(void)
  235. {
  236. fib6_link_table(&fib6_main_tbl);
  237. }
  238. #endif
  239. static int fib6_dump_node(struct fib6_walker_t *w)
  240. {
  241. int res;
  242. struct rt6_info *rt;
  243. for (rt = w->leaf; rt; rt = rt->u.next) {
  244. res = rt6_dump_route(rt, w->args);
  245. if (res < 0) {
  246. /* Frame is full, suspend walking */
  247. w->leaf = rt;
  248. return 1;
  249. }
  250. BUG_TRAP(res!=0);
  251. }
  252. w->leaf = NULL;
  253. return 0;
  254. }
  255. static void fib6_dump_end(struct netlink_callback *cb)
  256. {
  257. struct fib6_walker_t *w = (void*)cb->args[2];
  258. if (w) {
  259. cb->args[2] = 0;
  260. kfree(w);
  261. }
  262. cb->done = (void*)cb->args[3];
  263. cb->args[1] = 3;
  264. }
  265. static int fib6_dump_done(struct netlink_callback *cb)
  266. {
  267. fib6_dump_end(cb);
  268. return cb->done ? cb->done(cb) : 0;
  269. }
  270. static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
  271. struct netlink_callback *cb)
  272. {
  273. struct fib6_walker_t *w;
  274. int res;
  275. w = (void *)cb->args[2];
  276. w->root = &table->tb6_root;
  277. if (cb->args[4] == 0) {
  278. read_lock_bh(&table->tb6_lock);
  279. res = fib6_walk(w);
  280. read_unlock_bh(&table->tb6_lock);
  281. if (res > 0)
  282. cb->args[4] = 1;
  283. } else {
  284. read_lock_bh(&table->tb6_lock);
  285. res = fib6_walk_continue(w);
  286. read_unlock_bh(&table->tb6_lock);
  287. if (res != 0) {
  288. if (res < 0)
  289. fib6_walker_unlink(w);
  290. goto end;
  291. }
  292. fib6_walker_unlink(w);
  293. cb->args[4] = 0;
  294. }
  295. end:
  296. return res;
  297. }
  298. int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
  299. {
  300. unsigned int h, s_h;
  301. unsigned int e = 0, s_e;
  302. struct rt6_rtnl_dump_arg arg;
  303. struct fib6_walker_t *w;
  304. struct fib6_table *tb;
  305. struct hlist_node *node;
  306. int res = 0;
  307. s_h = cb->args[0];
  308. s_e = cb->args[1];
  309. w = (void *)cb->args[2];
  310. if (w == NULL) {
  311. /* New dump:
  312. *
  313. * 1. hook callback destructor.
  314. */
  315. cb->args[3] = (long)cb->done;
  316. cb->done = fib6_dump_done;
  317. /*
  318. * 2. allocate and initialize walker.
  319. */
  320. w = kzalloc(sizeof(*w), GFP_ATOMIC);
  321. if (w == NULL)
  322. return -ENOMEM;
  323. w->func = fib6_dump_node;
  324. cb->args[2] = (long)w;
  325. }
  326. arg.skb = skb;
  327. arg.cb = cb;
  328. w->args = &arg;
  329. for (h = s_h; h < FIB_TABLE_HASHSZ; h++, s_e = 0) {
  330. e = 0;
  331. hlist_for_each_entry(tb, node, &fib_table_hash[h], tb6_hlist) {
  332. if (e < s_e)
  333. goto next;
  334. res = fib6_dump_table(tb, skb, cb);
  335. if (res != 0)
  336. goto out;
  337. next:
  338. e++;
  339. }
  340. }
  341. out:
  342. cb->args[1] = e;
  343. cb->args[0] = h;
  344. res = res < 0 ? res : skb->len;
  345. if (res <= 0)
  346. fib6_dump_end(cb);
  347. return res;
  348. }
  349. /*
  350. * Routing Table
  351. *
  352. * return the appropriate node for a routing tree "add" operation
  353. * by either creating and inserting or by returning an existing
  354. * node.
  355. */
  356. static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr,
  357. int addrlen, int plen,
  358. int offset)
  359. {
  360. struct fib6_node *fn, *in, *ln;
  361. struct fib6_node *pn = NULL;
  362. struct rt6key *key;
  363. int bit;
  364. int dir = 0;
  365. __u32 sernum = fib6_new_sernum();
  366. RT6_TRACE("fib6_add_1\n");
  367. /* insert node in tree */
  368. fn = root;
  369. do {
  370. key = (struct rt6key *)((u8 *)fn->leaf + offset);
  371. /*
  372. * Prefix match
  373. */
  374. if (plen < fn->fn_bit ||
  375. !ipv6_prefix_equal(&key->addr, addr, fn->fn_bit))
  376. goto insert_above;
  377. /*
  378. * Exact match ?
  379. */
  380. if (plen == fn->fn_bit) {
  381. /* clean up an intermediate node */
  382. if ((fn->fn_flags & RTN_RTINFO) == 0) {
  383. rt6_release(fn->leaf);
  384. fn->leaf = NULL;
  385. }
  386. fn->fn_sernum = sernum;
  387. return fn;
  388. }
  389. /*
  390. * We have more bits to go
  391. */
  392. /* Try to walk down on tree. */
  393. fn->fn_sernum = sernum;
  394. dir = addr_bit_set(addr, fn->fn_bit);
  395. pn = fn;
  396. fn = dir ? fn->right: fn->left;
  397. } while (fn);
  398. /*
  399. * We walked to the bottom of tree.
  400. * Create new leaf node without children.
  401. */
  402. ln = node_alloc();
  403. if (ln == NULL)
  404. return NULL;
  405. ln->fn_bit = plen;
  406. ln->parent = pn;
  407. ln->fn_sernum = sernum;
  408. if (dir)
  409. pn->right = ln;
  410. else
  411. pn->left = ln;
  412. return ln;
  413. insert_above:
  414. /*
  415. * split since we don't have a common prefix anymore or
  416. * we have a less significant route.
  417. * we've to insert an intermediate node on the list
  418. * this new node will point to the one we need to create
  419. * and the current
  420. */
  421. pn = fn->parent;
  422. /* find 1st bit in difference between the 2 addrs.
  423. See comment in __ipv6_addr_diff: bit may be an invalid value,
  424. but if it is >= plen, the value is ignored in any case.
  425. */
  426. bit = __ipv6_addr_diff(addr, &key->addr, addrlen);
  427. /*
  428. * (intermediate)[in]
  429. * / \
  430. * (new leaf node)[ln] (old node)[fn]
  431. */
  432. if (plen > bit) {
  433. in = node_alloc();
  434. ln = node_alloc();
  435. if (in == NULL || ln == NULL) {
  436. if (in)
  437. node_free(in);
  438. if (ln)
  439. node_free(ln);
  440. return NULL;
  441. }
  442. /*
  443. * new intermediate node.
  444. * RTN_RTINFO will
  445. * be off since that an address that chooses one of
  446. * the branches would not match less specific routes
  447. * in the other branch
  448. */
  449. in->fn_bit = bit;
  450. in->parent = pn;
  451. in->leaf = fn->leaf;
  452. atomic_inc(&in->leaf->rt6i_ref);
  453. in->fn_sernum = sernum;
  454. /* update parent pointer */
  455. if (dir)
  456. pn->right = in;
  457. else
  458. pn->left = in;
  459. ln->fn_bit = plen;
  460. ln->parent = in;
  461. fn->parent = in;
  462. ln->fn_sernum = sernum;
  463. if (addr_bit_set(addr, bit)) {
  464. in->right = ln;
  465. in->left = fn;
  466. } else {
  467. in->left = ln;
  468. in->right = fn;
  469. }
  470. } else { /* plen <= bit */
  471. /*
  472. * (new leaf node)[ln]
  473. * / \
  474. * (old node)[fn] NULL
  475. */
  476. ln = node_alloc();
  477. if (ln == NULL)
  478. return NULL;
  479. ln->fn_bit = plen;
  480. ln->parent = pn;
  481. ln->fn_sernum = sernum;
  482. if (dir)
  483. pn->right = ln;
  484. else
  485. pn->left = ln;
  486. if (addr_bit_set(&key->addr, plen))
  487. ln->right = fn;
  488. else
  489. ln->left = fn;
  490. fn->parent = ln;
  491. }
  492. return ln;
  493. }
  494. /*
  495. * Insert routing information in a node.
  496. */
  497. static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
  498. struct nl_info *info)
  499. {
  500. struct rt6_info *iter = NULL;
  501. struct rt6_info **ins;
  502. ins = &fn->leaf;
  503. if (fn->fn_flags&RTN_TL_ROOT &&
  504. fn->leaf == &ip6_null_entry &&
  505. !(rt->rt6i_flags & (RTF_DEFAULT | RTF_ADDRCONF)) ){
  506. fn->leaf = rt;
  507. rt->u.next = NULL;
  508. goto out;
  509. }
  510. for (iter = fn->leaf; iter; iter=iter->u.next) {
  511. /*
  512. * Search for duplicates
  513. */
  514. if (iter->rt6i_metric == rt->rt6i_metric) {
  515. /*
  516. * Same priority level
  517. */
  518. if (iter->rt6i_dev == rt->rt6i_dev &&
  519. iter->rt6i_idev == rt->rt6i_idev &&
  520. ipv6_addr_equal(&iter->rt6i_gateway,
  521. &rt->rt6i_gateway)) {
  522. if (!(iter->rt6i_flags&RTF_EXPIRES))
  523. return -EEXIST;
  524. iter->rt6i_expires = rt->rt6i_expires;
  525. if (!(rt->rt6i_flags&RTF_EXPIRES)) {
  526. iter->rt6i_flags &= ~RTF_EXPIRES;
  527. iter->rt6i_expires = 0;
  528. }
  529. return -EEXIST;
  530. }
  531. }
  532. if (iter->rt6i_metric > rt->rt6i_metric)
  533. break;
  534. ins = &iter->u.next;
  535. }
  536. /*
  537. * insert node
  538. */
  539. out:
  540. rt->u.next = iter;
  541. *ins = rt;
  542. rt->rt6i_node = fn;
  543. atomic_inc(&rt->rt6i_ref);
  544. inet6_rt_notify(RTM_NEWROUTE, rt, info);
  545. rt6_stats.fib_rt_entries++;
  546. if ((fn->fn_flags & RTN_RTINFO) == 0) {
  547. rt6_stats.fib_route_nodes++;
  548. fn->fn_flags |= RTN_RTINFO;
  549. }
  550. return 0;
  551. }
  552. static __inline__ void fib6_start_gc(struct rt6_info *rt)
  553. {
  554. if (ip6_fib_timer.expires == 0 &&
  555. (rt->rt6i_flags & (RTF_EXPIRES|RTF_CACHE)))
  556. mod_timer(&ip6_fib_timer, jiffies + ip6_rt_gc_interval);
  557. }
  558. void fib6_force_start_gc(void)
  559. {
  560. if (ip6_fib_timer.expires == 0)
  561. mod_timer(&ip6_fib_timer, jiffies + ip6_rt_gc_interval);
  562. }
  563. /*
  564. * Add routing information to the routing tree.
  565. * <destination addr>/<source addr>
  566. * with source addr info in sub-trees
  567. */
  568. int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
  569. {
  570. struct fib6_node *fn, *pn = NULL;
  571. int err = -ENOMEM;
  572. fn = fib6_add_1(root, &rt->rt6i_dst.addr, sizeof(struct in6_addr),
  573. rt->rt6i_dst.plen, offsetof(struct rt6_info, rt6i_dst));
  574. if (fn == NULL)
  575. goto out;
  576. pn = fn;
  577. #ifdef CONFIG_IPV6_SUBTREES
  578. if (rt->rt6i_src.plen) {
  579. struct fib6_node *sn;
  580. if (fn->subtree == NULL) {
  581. struct fib6_node *sfn;
  582. /*
  583. * Create subtree.
  584. *
  585. * fn[main tree]
  586. * |
  587. * sfn[subtree root]
  588. * \
  589. * sn[new leaf node]
  590. */
  591. /* Create subtree root node */
  592. sfn = node_alloc();
  593. if (sfn == NULL)
  594. goto st_failure;
  595. sfn->leaf = &ip6_null_entry;
  596. atomic_inc(&ip6_null_entry.rt6i_ref);
  597. sfn->fn_flags = RTN_ROOT;
  598. sfn->fn_sernum = fib6_new_sernum();
  599. /* Now add the first leaf node to new subtree */
  600. sn = fib6_add_1(sfn, &rt->rt6i_src.addr,
  601. sizeof(struct in6_addr), rt->rt6i_src.plen,
  602. offsetof(struct rt6_info, rt6i_src));
  603. if (sn == NULL) {
  604. /* If it is failed, discard just allocated
  605. root, and then (in st_failure) stale node
  606. in main tree.
  607. */
  608. node_free(sfn);
  609. goto st_failure;
  610. }
  611. /* Now link new subtree to main tree */
  612. sfn->parent = fn;
  613. fn->subtree = sfn;
  614. } else {
  615. sn = fib6_add_1(fn->subtree, &rt->rt6i_src.addr,
  616. sizeof(struct in6_addr), rt->rt6i_src.plen,
  617. offsetof(struct rt6_info, rt6i_src));
  618. if (sn == NULL)
  619. goto st_failure;
  620. }
  621. if (fn->leaf == NULL) {
  622. fn->leaf = rt;
  623. atomic_inc(&rt->rt6i_ref);
  624. }
  625. fn = sn;
  626. }
  627. #endif
  628. err = fib6_add_rt2node(fn, rt, info);
  629. if (err == 0) {
  630. fib6_start_gc(rt);
  631. if (!(rt->rt6i_flags&RTF_CACHE))
  632. fib6_prune_clones(pn, rt);
  633. }
  634. out:
  635. if (err) {
  636. #ifdef CONFIG_IPV6_SUBTREES
  637. /*
  638. * If fib6_add_1 has cleared the old leaf pointer in the
  639. * super-tree leaf node we have to find a new one for it.
  640. */
  641. if (pn != fn && !pn->leaf && !(pn->fn_flags & RTN_RTINFO)) {
  642. pn->leaf = fib6_find_prefix(pn);
  643. #if RT6_DEBUG >= 2
  644. if (!pn->leaf) {
  645. BUG_TRAP(pn->leaf != NULL);
  646. pn->leaf = &ip6_null_entry;
  647. }
  648. #endif
  649. atomic_inc(&pn->leaf->rt6i_ref);
  650. }
  651. #endif
  652. dst_free(&rt->u.dst);
  653. }
  654. return err;
  655. #ifdef CONFIG_IPV6_SUBTREES
  656. /* Subtree creation failed, probably main tree node
  657. is orphan. If it is, shoot it.
  658. */
  659. st_failure:
  660. if (fn && !(fn->fn_flags & (RTN_RTINFO|RTN_ROOT)))
  661. fib6_repair_tree(fn);
  662. dst_free(&rt->u.dst);
  663. return err;
  664. #endif
  665. }
  666. /*
  667. * Routing tree lookup
  668. *
  669. */
  670. struct lookup_args {
  671. int offset; /* key offset on rt6_info */
  672. struct in6_addr *addr; /* search key */
  673. };
  674. static struct fib6_node * fib6_lookup_1(struct fib6_node *root,
  675. struct lookup_args *args)
  676. {
  677. struct fib6_node *fn;
  678. int dir;
  679. if (unlikely(args->offset == 0))
  680. return NULL;
  681. /*
  682. * Descend on a tree
  683. */
  684. fn = root;
  685. for (;;) {
  686. struct fib6_node *next;
  687. dir = addr_bit_set(args->addr, fn->fn_bit);
  688. next = dir ? fn->right : fn->left;
  689. if (next) {
  690. fn = next;
  691. continue;
  692. }
  693. break;
  694. }
  695. while(fn) {
  696. if (FIB6_SUBTREE(fn) || fn->fn_flags & RTN_RTINFO) {
  697. struct rt6key *key;
  698. key = (struct rt6key *) ((u8 *) fn->leaf +
  699. args->offset);
  700. if (ipv6_prefix_equal(&key->addr, args->addr, key->plen)) {
  701. #ifdef CONFIG_IPV6_SUBTREES
  702. if (fn->subtree)
  703. fn = fib6_lookup_1(fn->subtree, args + 1);
  704. #endif
  705. if (!fn || fn->fn_flags & RTN_RTINFO)
  706. return fn;
  707. }
  708. }
  709. if (fn->fn_flags & RTN_ROOT)
  710. break;
  711. fn = fn->parent;
  712. }
  713. return NULL;
  714. }
  715. struct fib6_node * fib6_lookup(struct fib6_node *root, struct in6_addr *daddr,
  716. struct in6_addr *saddr)
  717. {
  718. struct fib6_node *fn;
  719. struct lookup_args args[] = {
  720. {
  721. .offset = offsetof(struct rt6_info, rt6i_dst),
  722. .addr = daddr,
  723. },
  724. #ifdef CONFIG_IPV6_SUBTREES
  725. {
  726. .offset = offsetof(struct rt6_info, rt6i_src),
  727. .addr = saddr,
  728. },
  729. #endif
  730. {
  731. .offset = 0, /* sentinel */
  732. }
  733. };
  734. fn = fib6_lookup_1(root, daddr ? args : args + 1);
  735. if (fn == NULL || fn->fn_flags & RTN_TL_ROOT)
  736. fn = root;
  737. return fn;
  738. }
  739. /*
  740. * Get node with specified destination prefix (and source prefix,
  741. * if subtrees are used)
  742. */
  743. static struct fib6_node * fib6_locate_1(struct fib6_node *root,
  744. struct in6_addr *addr,
  745. int plen, int offset)
  746. {
  747. struct fib6_node *fn;
  748. for (fn = root; fn ; ) {
  749. struct rt6key *key = (struct rt6key *)((u8 *)fn->leaf + offset);
  750. /*
  751. * Prefix match
  752. */
  753. if (plen < fn->fn_bit ||
  754. !ipv6_prefix_equal(&key->addr, addr, fn->fn_bit))
  755. return NULL;
  756. if (plen == fn->fn_bit)
  757. return fn;
  758. /*
  759. * We have more bits to go
  760. */
  761. if (addr_bit_set(addr, fn->fn_bit))
  762. fn = fn->right;
  763. else
  764. fn = fn->left;
  765. }
  766. return NULL;
  767. }
  768. struct fib6_node * fib6_locate(struct fib6_node *root,
  769. struct in6_addr *daddr, int dst_len,
  770. struct in6_addr *saddr, int src_len)
  771. {
  772. struct fib6_node *fn;
  773. fn = fib6_locate_1(root, daddr, dst_len,
  774. offsetof(struct rt6_info, rt6i_dst));
  775. #ifdef CONFIG_IPV6_SUBTREES
  776. if (src_len) {
  777. BUG_TRAP(saddr!=NULL);
  778. if (fn && fn->subtree)
  779. fn = fib6_locate_1(fn->subtree, saddr, src_len,
  780. offsetof(struct rt6_info, rt6i_src));
  781. }
  782. #endif
  783. if (fn && fn->fn_flags&RTN_RTINFO)
  784. return fn;
  785. return NULL;
  786. }
  787. /*
  788. * Deletion
  789. *
  790. */
  791. static struct rt6_info * fib6_find_prefix(struct fib6_node *fn)
  792. {
  793. if (fn->fn_flags&RTN_ROOT)
  794. return &ip6_null_entry;
  795. while(fn) {
  796. if(fn->left)
  797. return fn->left->leaf;
  798. if(fn->right)
  799. return fn->right->leaf;
  800. fn = FIB6_SUBTREE(fn);
  801. }
  802. return NULL;
  803. }
  804. /*
  805. * Called to trim the tree of intermediate nodes when possible. "fn"
  806. * is the node we want to try and remove.
  807. */
  808. static struct fib6_node * fib6_repair_tree(struct fib6_node *fn)
  809. {
  810. int children;
  811. int nstate;
  812. struct fib6_node *child, *pn;
  813. struct fib6_walker_t *w;
  814. int iter = 0;
  815. for (;;) {
  816. RT6_TRACE("fixing tree: plen=%d iter=%d\n", fn->fn_bit, iter);
  817. iter++;
  818. BUG_TRAP(!(fn->fn_flags&RTN_RTINFO));
  819. BUG_TRAP(!(fn->fn_flags&RTN_TL_ROOT));
  820. BUG_TRAP(fn->leaf==NULL);
  821. children = 0;
  822. child = NULL;
  823. if (fn->right) child = fn->right, children |= 1;
  824. if (fn->left) child = fn->left, children |= 2;
  825. if (children == 3 || FIB6_SUBTREE(fn)
  826. #ifdef CONFIG_IPV6_SUBTREES
  827. /* Subtree root (i.e. fn) may have one child */
  828. || (children && fn->fn_flags&RTN_ROOT)
  829. #endif
  830. ) {
  831. fn->leaf = fib6_find_prefix(fn);
  832. #if RT6_DEBUG >= 2
  833. if (fn->leaf==NULL) {
  834. BUG_TRAP(fn->leaf);
  835. fn->leaf = &ip6_null_entry;
  836. }
  837. #endif
  838. atomic_inc(&fn->leaf->rt6i_ref);
  839. return fn->parent;
  840. }
  841. pn = fn->parent;
  842. #ifdef CONFIG_IPV6_SUBTREES
  843. if (FIB6_SUBTREE(pn) == fn) {
  844. BUG_TRAP(fn->fn_flags&RTN_ROOT);
  845. FIB6_SUBTREE(pn) = NULL;
  846. nstate = FWS_L;
  847. } else {
  848. BUG_TRAP(!(fn->fn_flags&RTN_ROOT));
  849. #endif
  850. if (pn->right == fn) pn->right = child;
  851. else if (pn->left == fn) pn->left = child;
  852. #if RT6_DEBUG >= 2
  853. else BUG_TRAP(0);
  854. #endif
  855. if (child)
  856. child->parent = pn;
  857. nstate = FWS_R;
  858. #ifdef CONFIG_IPV6_SUBTREES
  859. }
  860. #endif
  861. read_lock(&fib6_walker_lock);
  862. FOR_WALKERS(w) {
  863. if (child == NULL) {
  864. if (w->root == fn) {
  865. w->root = w->node = NULL;
  866. RT6_TRACE("W %p adjusted by delroot 1\n", w);
  867. } else if (w->node == fn) {
  868. RT6_TRACE("W %p adjusted by delnode 1, s=%d/%d\n", w, w->state, nstate);
  869. w->node = pn;
  870. w->state = nstate;
  871. }
  872. } else {
  873. if (w->root == fn) {
  874. w->root = child;
  875. RT6_TRACE("W %p adjusted by delroot 2\n", w);
  876. }
  877. if (w->node == fn) {
  878. w->node = child;
  879. if (children&2) {
  880. RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w, w->state);
  881. w->state = w->state>=FWS_R ? FWS_U : FWS_INIT;
  882. } else {
  883. RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w, w->state);
  884. w->state = w->state>=FWS_C ? FWS_U : FWS_INIT;
  885. }
  886. }
  887. }
  888. }
  889. read_unlock(&fib6_walker_lock);
  890. node_free(fn);
  891. if (pn->fn_flags&RTN_RTINFO || FIB6_SUBTREE(pn))
  892. return pn;
  893. rt6_release(pn->leaf);
  894. pn->leaf = NULL;
  895. fn = pn;
  896. }
  897. }
  898. static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
  899. struct nl_info *info)
  900. {
  901. struct fib6_walker_t *w;
  902. struct rt6_info *rt = *rtp;
  903. RT6_TRACE("fib6_del_route\n");
  904. /* Unlink it */
  905. *rtp = rt->u.next;
  906. rt->rt6i_node = NULL;
  907. rt6_stats.fib_rt_entries--;
  908. rt6_stats.fib_discarded_routes++;
  909. /* Adjust walkers */
  910. read_lock(&fib6_walker_lock);
  911. FOR_WALKERS(w) {
  912. if (w->state == FWS_C && w->leaf == rt) {
  913. RT6_TRACE("walker %p adjusted by delroute\n", w);
  914. w->leaf = rt->u.next;
  915. if (w->leaf == NULL)
  916. w->state = FWS_U;
  917. }
  918. }
  919. read_unlock(&fib6_walker_lock);
  920. rt->u.next = NULL;
  921. if (fn->leaf == NULL && fn->fn_flags&RTN_TL_ROOT)
  922. fn->leaf = &ip6_null_entry;
  923. /* If it was last route, expunge its radix tree node */
  924. if (fn->leaf == NULL) {
  925. fn->fn_flags &= ~RTN_RTINFO;
  926. rt6_stats.fib_route_nodes--;
  927. fn = fib6_repair_tree(fn);
  928. }
  929. if (atomic_read(&rt->rt6i_ref) != 1) {
  930. /* This route is used as dummy address holder in some split
  931. * nodes. It is not leaked, but it still holds other resources,
  932. * which must be released in time. So, scan ascendant nodes
  933. * and replace dummy references to this route with references
  934. * to still alive ones.
  935. */
  936. while (fn) {
  937. if (!(fn->fn_flags&RTN_RTINFO) && fn->leaf == rt) {
  938. fn->leaf = fib6_find_prefix(fn);
  939. atomic_inc(&fn->leaf->rt6i_ref);
  940. rt6_release(rt);
  941. }
  942. fn = fn->parent;
  943. }
  944. /* No more references are possible at this point. */
  945. if (atomic_read(&rt->rt6i_ref) != 1) BUG();
  946. }
  947. inet6_rt_notify(RTM_DELROUTE, rt, info);
  948. rt6_release(rt);
  949. }
  950. int fib6_del(struct rt6_info *rt, struct nl_info *info)
  951. {
  952. struct fib6_node *fn = rt->rt6i_node;
  953. struct rt6_info **rtp;
  954. #if RT6_DEBUG >= 2
  955. if (rt->u.dst.obsolete>0) {
  956. BUG_TRAP(fn==NULL);
  957. return -ENOENT;
  958. }
  959. #endif
  960. if (fn == NULL || rt == &ip6_null_entry)
  961. return -ENOENT;
  962. BUG_TRAP(fn->fn_flags&RTN_RTINFO);
  963. if (!(rt->rt6i_flags&RTF_CACHE)) {
  964. struct fib6_node *pn = fn;
  965. #ifdef CONFIG_IPV6_SUBTREES
  966. /* clones of this route might be in another subtree */
  967. if (rt->rt6i_src.plen) {
  968. while (!(pn->fn_flags&RTN_ROOT))
  969. pn = pn->parent;
  970. pn = pn->parent;
  971. }
  972. #endif
  973. fib6_prune_clones(pn, rt);
  974. }
  975. /*
  976. * Walk the leaf entries looking for ourself
  977. */
  978. for (rtp = &fn->leaf; *rtp; rtp = &(*rtp)->u.next) {
  979. if (*rtp == rt) {
  980. fib6_del_route(fn, rtp, info);
  981. return 0;
  982. }
  983. }
  984. return -ENOENT;
  985. }
  986. /*
  987. * Tree traversal function.
  988. *
  989. * Certainly, it is not interrupt safe.
  990. * However, it is internally reenterable wrt itself and fib6_add/fib6_del.
  991. * It means, that we can modify tree during walking
  992. * and use this function for garbage collection, clone pruning,
  993. * cleaning tree when a device goes down etc. etc.
  994. *
  995. * It guarantees that every node will be traversed,
  996. * and that it will be traversed only once.
  997. *
  998. * Callback function w->func may return:
  999. * 0 -> continue walking.
  1000. * positive value -> walking is suspended (used by tree dumps,
  1001. * and probably by gc, if it will be split to several slices)
  1002. * negative value -> terminate walking.
  1003. *
  1004. * The function itself returns:
  1005. * 0 -> walk is complete.
  1006. * >0 -> walk is incomplete (i.e. suspended)
  1007. * <0 -> walk is terminated by an error.
  1008. */
  1009. static int fib6_walk_continue(struct fib6_walker_t *w)
  1010. {
  1011. struct fib6_node *fn, *pn;
  1012. for (;;) {
  1013. fn = w->node;
  1014. if (fn == NULL)
  1015. return 0;
  1016. if (w->prune && fn != w->root &&
  1017. fn->fn_flags&RTN_RTINFO && w->state < FWS_C) {
  1018. w->state = FWS_C;
  1019. w->leaf = fn->leaf;
  1020. }
  1021. switch (w->state) {
  1022. #ifdef CONFIG_IPV6_SUBTREES
  1023. case FWS_S:
  1024. if (FIB6_SUBTREE(fn)) {
  1025. w->node = FIB6_SUBTREE(fn);
  1026. continue;
  1027. }
  1028. w->state = FWS_L;
  1029. #endif
  1030. case FWS_L:
  1031. if (fn->left) {
  1032. w->node = fn->left;
  1033. w->state = FWS_INIT;
  1034. continue;
  1035. }
  1036. w->state = FWS_R;
  1037. case FWS_R:
  1038. if (fn->right) {
  1039. w->node = fn->right;
  1040. w->state = FWS_INIT;
  1041. continue;
  1042. }
  1043. w->state = FWS_C;
  1044. w->leaf = fn->leaf;
  1045. case FWS_C:
  1046. if (w->leaf && fn->fn_flags&RTN_RTINFO) {
  1047. int err = w->func(w);
  1048. if (err)
  1049. return err;
  1050. continue;
  1051. }
  1052. w->state = FWS_U;
  1053. case FWS_U:
  1054. if (fn == w->root)
  1055. return 0;
  1056. pn = fn->parent;
  1057. w->node = pn;
  1058. #ifdef CONFIG_IPV6_SUBTREES
  1059. if (FIB6_SUBTREE(pn) == fn) {
  1060. BUG_TRAP(fn->fn_flags&RTN_ROOT);
  1061. w->state = FWS_L;
  1062. continue;
  1063. }
  1064. #endif
  1065. if (pn->left == fn) {
  1066. w->state = FWS_R;
  1067. continue;
  1068. }
  1069. if (pn->right == fn) {
  1070. w->state = FWS_C;
  1071. w->leaf = w->node->leaf;
  1072. continue;
  1073. }
  1074. #if RT6_DEBUG >= 2
  1075. BUG_TRAP(0);
  1076. #endif
  1077. }
  1078. }
  1079. }
  1080. static int fib6_walk(struct fib6_walker_t *w)
  1081. {
  1082. int res;
  1083. w->state = FWS_INIT;
  1084. w->node = w->root;
  1085. fib6_walker_link(w);
  1086. res = fib6_walk_continue(w);
  1087. if (res <= 0)
  1088. fib6_walker_unlink(w);
  1089. return res;
  1090. }
  1091. static int fib6_clean_node(struct fib6_walker_t *w)
  1092. {
  1093. int res;
  1094. struct rt6_info *rt;
  1095. struct fib6_cleaner_t *c = (struct fib6_cleaner_t*)w;
  1096. for (rt = w->leaf; rt; rt = rt->u.next) {
  1097. res = c->func(rt, c->arg);
  1098. if (res < 0) {
  1099. w->leaf = rt;
  1100. res = fib6_del(rt, NULL);
  1101. if (res) {
  1102. #if RT6_DEBUG >= 2
  1103. printk(KERN_DEBUG "fib6_clean_node: del failed: rt=%p@%p err=%d\n", rt, rt->rt6i_node, res);
  1104. #endif
  1105. continue;
  1106. }
  1107. return 0;
  1108. }
  1109. BUG_TRAP(res==0);
  1110. }
  1111. w->leaf = rt;
  1112. return 0;
  1113. }
  1114. /*
  1115. * Convenient frontend to tree walker.
  1116. *
  1117. * func is called on each route.
  1118. * It may return -1 -> delete this route.
  1119. * 0 -> continue walking
  1120. *
  1121. * prune==1 -> only immediate children of node (certainly,
  1122. * ignoring pure split nodes) will be scanned.
  1123. */
  1124. static void fib6_clean_tree(struct fib6_node *root,
  1125. int (*func)(struct rt6_info *, void *arg),
  1126. int prune, void *arg)
  1127. {
  1128. struct fib6_cleaner_t c;
  1129. c.w.root = root;
  1130. c.w.func = fib6_clean_node;
  1131. c.w.prune = prune;
  1132. c.func = func;
  1133. c.arg = arg;
  1134. fib6_walk(&c.w);
  1135. }
  1136. void fib6_clean_all(int (*func)(struct rt6_info *, void *arg),
  1137. int prune, void *arg)
  1138. {
  1139. struct fib6_table *table;
  1140. struct hlist_node *node;
  1141. unsigned int h;
  1142. rcu_read_lock();
  1143. for (h = 0; h < FIB_TABLE_HASHSZ; h++) {
  1144. hlist_for_each_entry_rcu(table, node, &fib_table_hash[h],
  1145. tb6_hlist) {
  1146. write_lock_bh(&table->tb6_lock);
  1147. fib6_clean_tree(&table->tb6_root, func, prune, arg);
  1148. write_unlock_bh(&table->tb6_lock);
  1149. }
  1150. }
  1151. rcu_read_unlock();
  1152. }
  1153. static int fib6_prune_clone(struct rt6_info *rt, void *arg)
  1154. {
  1155. if (rt->rt6i_flags & RTF_CACHE) {
  1156. RT6_TRACE("pruning clone %p\n", rt);
  1157. return -1;
  1158. }
  1159. return 0;
  1160. }
  1161. static void fib6_prune_clones(struct fib6_node *fn, struct rt6_info *rt)
  1162. {
  1163. fib6_clean_tree(fn, fib6_prune_clone, 1, rt);
  1164. }
  1165. /*
  1166. * Garbage collection
  1167. */
  1168. static struct fib6_gc_args
  1169. {
  1170. int timeout;
  1171. int more;
  1172. } gc_args;
  1173. static int fib6_age(struct rt6_info *rt, void *arg)
  1174. {
  1175. unsigned long now = jiffies;
  1176. /*
  1177. * check addrconf expiration here.
  1178. * Routes are expired even if they are in use.
  1179. *
  1180. * Also age clones. Note, that clones are aged out
  1181. * only if they are not in use now.
  1182. */
  1183. if (rt->rt6i_flags&RTF_EXPIRES && rt->rt6i_expires) {
  1184. if (time_after(now, rt->rt6i_expires)) {
  1185. RT6_TRACE("expiring %p\n", rt);
  1186. return -1;
  1187. }
  1188. gc_args.more++;
  1189. } else if (rt->rt6i_flags & RTF_CACHE) {
  1190. if (atomic_read(&rt->u.dst.__refcnt) == 0 &&
  1191. time_after_eq(now, rt->u.dst.lastuse + gc_args.timeout)) {
  1192. RT6_TRACE("aging clone %p\n", rt);
  1193. return -1;
  1194. } else if ((rt->rt6i_flags & RTF_GATEWAY) &&
  1195. (!(rt->rt6i_nexthop->flags & NTF_ROUTER))) {
  1196. RT6_TRACE("purging route %p via non-router but gateway\n",
  1197. rt);
  1198. return -1;
  1199. }
  1200. gc_args.more++;
  1201. }
  1202. return 0;
  1203. }
  1204. static DEFINE_SPINLOCK(fib6_gc_lock);
  1205. void fib6_run_gc(unsigned long dummy)
  1206. {
  1207. if (dummy != ~0UL) {
  1208. spin_lock_bh(&fib6_gc_lock);
  1209. gc_args.timeout = dummy ? (int)dummy : ip6_rt_gc_interval;
  1210. } else {
  1211. local_bh_disable();
  1212. if (!spin_trylock(&fib6_gc_lock)) {
  1213. mod_timer(&ip6_fib_timer, jiffies + HZ);
  1214. local_bh_enable();
  1215. return;
  1216. }
  1217. gc_args.timeout = ip6_rt_gc_interval;
  1218. }
  1219. gc_args.more = 0;
  1220. ndisc_dst_gc(&gc_args.more);
  1221. fib6_clean_all(fib6_age, 0, NULL);
  1222. if (gc_args.more)
  1223. mod_timer(&ip6_fib_timer, jiffies + ip6_rt_gc_interval);
  1224. else {
  1225. del_timer(&ip6_fib_timer);
  1226. ip6_fib_timer.expires = 0;
  1227. }
  1228. spin_unlock_bh(&fib6_gc_lock);
  1229. }
  1230. void __init fib6_init(void)
  1231. {
  1232. fib6_node_kmem = kmem_cache_create("fib6_nodes",
  1233. sizeof(struct fib6_node),
  1234. 0, SLAB_HWCACHE_ALIGN,
  1235. NULL, NULL);
  1236. if (!fib6_node_kmem)
  1237. panic("cannot create fib6_nodes cache");
  1238. fib6_tables_init();
  1239. }
  1240. void fib6_gc_cleanup(void)
  1241. {
  1242. del_timer(&ip6_fib_timer);
  1243. kmem_cache_destroy(fib6_node_kmem);
  1244. }