ip6_fib.c 29 KB

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