ip6_fib.c 29 KB

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