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 struct kmem_cache * 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__ __be32 addr_bit_set(void *token, int fn_bit)
  120. {
  121. __be32 *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. fn = kmem_cache_zalloc(fib6_node_kmem, GFP_ATOMIC);
  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_root = {
  142. .leaf = &ip6_null_entry,
  143. .fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO,
  144. },
  145. };
  146. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  147. #define FIB_TABLE_HASHSZ 256
  148. #else
  149. #define FIB_TABLE_HASHSZ 1
  150. #endif
  151. static struct hlist_head fib_table_hash[FIB_TABLE_HASHSZ];
  152. static void fib6_link_table(struct fib6_table *tb)
  153. {
  154. unsigned int h;
  155. /*
  156. * Initialize table lock at a single place to give lockdep a key,
  157. * tables aren't visible prior to being linked to the list.
  158. */
  159. rwlock_init(&tb->tb6_lock);
  160. h = tb->tb6_id & (FIB_TABLE_HASHSZ - 1);
  161. /*
  162. * No protection necessary, this is the only list mutatation
  163. * operation, tables never disappear once they exist.
  164. */
  165. hlist_add_head_rcu(&tb->tb6_hlist, &fib_table_hash[h]);
  166. }
  167. #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  168. static struct fib6_table fib6_local_tbl = {
  169. .tb6_id = RT6_TABLE_LOCAL,
  170. .tb6_root = {
  171. .leaf = &ip6_null_entry,
  172. .fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO,
  173. },
  174. };
  175. static struct fib6_table *fib6_alloc_table(u32 id)
  176. {
  177. struct fib6_table *table;
  178. table = kzalloc(sizeof(*table), GFP_ATOMIC);
  179. if (table != NULL) {
  180. table->tb6_id = id;
  181. table->tb6_root.leaf = &ip6_null_entry;
  182. table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
  183. }
  184. return table;
  185. }
  186. struct fib6_table *fib6_new_table(u32 id)
  187. {
  188. struct fib6_table *tb;
  189. if (id == 0)
  190. id = RT6_TABLE_MAIN;
  191. tb = fib6_get_table(id);
  192. if (tb)
  193. return tb;
  194. tb = fib6_alloc_table(id);
  195. if (tb != NULL)
  196. fib6_link_table(tb);
  197. return tb;
  198. }
  199. struct fib6_table *fib6_get_table(u32 id)
  200. {
  201. struct fib6_table *tb;
  202. struct hlist_node *node;
  203. unsigned int h;
  204. if (id == 0)
  205. id = RT6_TABLE_MAIN;
  206. h = id & (FIB_TABLE_HASHSZ - 1);
  207. rcu_read_lock();
  208. hlist_for_each_entry_rcu(tb, node, &fib_table_hash[h], tb6_hlist) {
  209. if (tb->tb6_id == id) {
  210. rcu_read_unlock();
  211. return tb;
  212. }
  213. }
  214. rcu_read_unlock();
  215. return NULL;
  216. }
  217. static void __init fib6_tables_init(void)
  218. {
  219. fib6_link_table(&fib6_main_tbl);
  220. fib6_link_table(&fib6_local_tbl);
  221. }
  222. #else
  223. struct fib6_table *fib6_new_table(u32 id)
  224. {
  225. return fib6_get_table(id);
  226. }
  227. struct fib6_table *fib6_get_table(u32 id)
  228. {
  229. return &fib6_main_tbl;
  230. }
  231. struct dst_entry *fib6_rule_lookup(struct flowi *fl, int flags,
  232. pol_lookup_t lookup)
  233. {
  234. return (struct dst_entry *) lookup(&fib6_main_tbl, fl, flags);
  235. }
  236. static void __init fib6_tables_init(void)
  237. {
  238. fib6_link_table(&fib6_main_tbl);
  239. }
  240. #endif
  241. static int fib6_dump_node(struct fib6_walker_t *w)
  242. {
  243. int res;
  244. struct rt6_info *rt;
  245. for (rt = w->leaf; rt; rt = rt->u.dst.rt6_next) {
  246. res = rt6_dump_route(rt, w->args);
  247. if (res < 0) {
  248. /* Frame is full, suspend walking */
  249. w->leaf = rt;
  250. return 1;
  251. }
  252. BUG_TRAP(res!=0);
  253. }
  254. w->leaf = NULL;
  255. return 0;
  256. }
  257. static void fib6_dump_end(struct netlink_callback *cb)
  258. {
  259. struct fib6_walker_t *w = (void*)cb->args[2];
  260. if (w) {
  261. cb->args[2] = 0;
  262. kfree(w);
  263. }
  264. cb->done = (void*)cb->args[3];
  265. cb->args[1] = 3;
  266. }
  267. static int fib6_dump_done(struct netlink_callback *cb)
  268. {
  269. fib6_dump_end(cb);
  270. return cb->done ? cb->done(cb) : 0;
  271. }
  272. static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
  273. struct netlink_callback *cb)
  274. {
  275. struct fib6_walker_t *w;
  276. int res;
  277. w = (void *)cb->args[2];
  278. w->root = &table->tb6_root;
  279. if (cb->args[4] == 0) {
  280. read_lock_bh(&table->tb6_lock);
  281. res = fib6_walk(w);
  282. read_unlock_bh(&table->tb6_lock);
  283. if (res > 0)
  284. cb->args[4] = 1;
  285. } else {
  286. read_lock_bh(&table->tb6_lock);
  287. res = fib6_walk_continue(w);
  288. read_unlock_bh(&table->tb6_lock);
  289. if (res != 0) {
  290. if (res < 0)
  291. fib6_walker_unlink(w);
  292. goto end;
  293. }
  294. fib6_walker_unlink(w);
  295. cb->args[4] = 0;
  296. }
  297. end:
  298. return res;
  299. }
  300. static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
  301. {
  302. unsigned int h, s_h;
  303. unsigned int e = 0, s_e;
  304. struct rt6_rtnl_dump_arg arg;
  305. struct fib6_walker_t *w;
  306. struct fib6_table *tb;
  307. struct hlist_node *node;
  308. int res = 0;
  309. s_h = cb->args[0];
  310. s_e = cb->args[1];
  311. w = (void *)cb->args[2];
  312. if (w == NULL) {
  313. /* New dump:
  314. *
  315. * 1. hook callback destructor.
  316. */
  317. cb->args[3] = (long)cb->done;
  318. cb->done = fib6_dump_done;
  319. /*
  320. * 2. allocate and initialize walker.
  321. */
  322. w = kzalloc(sizeof(*w), GFP_ATOMIC);
  323. if (w == NULL)
  324. return -ENOMEM;
  325. w->func = fib6_dump_node;
  326. cb->args[2] = (long)w;
  327. }
  328. arg.skb = skb;
  329. arg.cb = cb;
  330. w->args = &arg;
  331. for (h = s_h; h < FIB_TABLE_HASHSZ; h++, s_e = 0) {
  332. e = 0;
  333. hlist_for_each_entry(tb, node, &fib_table_hash[h], tb6_hlist) {
  334. if (e < s_e)
  335. goto next;
  336. res = fib6_dump_table(tb, skb, cb);
  337. if (res != 0)
  338. goto out;
  339. next:
  340. e++;
  341. }
  342. }
  343. out:
  344. cb->args[1] = e;
  345. cb->args[0] = h;
  346. res = res < 0 ? res : skb->len;
  347. if (res <= 0)
  348. fib6_dump_end(cb);
  349. return res;
  350. }
  351. /*
  352. * Routing Table
  353. *
  354. * return the appropriate node for a routing tree "add" operation
  355. * by either creating and inserting or by returning an existing
  356. * node.
  357. */
  358. static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr,
  359. int addrlen, int plen,
  360. int offset)
  361. {
  362. struct fib6_node *fn, *in, *ln;
  363. struct fib6_node *pn = NULL;
  364. struct rt6key *key;
  365. int bit;
  366. __be32 dir = 0;
  367. __u32 sernum = fib6_new_sernum();
  368. RT6_TRACE("fib6_add_1\n");
  369. /* insert node in tree */
  370. fn = root;
  371. do {
  372. key = (struct rt6key *)((u8 *)fn->leaf + offset);
  373. /*
  374. * Prefix match
  375. */
  376. if (plen < fn->fn_bit ||
  377. !ipv6_prefix_equal(&key->addr, addr, fn->fn_bit))
  378. goto insert_above;
  379. /*
  380. * Exact match ?
  381. */
  382. if (plen == fn->fn_bit) {
  383. /* clean up an intermediate node */
  384. if ((fn->fn_flags & RTN_RTINFO) == 0) {
  385. rt6_release(fn->leaf);
  386. fn->leaf = NULL;
  387. }
  388. fn->fn_sernum = sernum;
  389. return fn;
  390. }
  391. /*
  392. * We have more bits to go
  393. */
  394. /* Try to walk down on tree. */
  395. fn->fn_sernum = sernum;
  396. dir = addr_bit_set(addr, fn->fn_bit);
  397. pn = fn;
  398. fn = dir ? fn->right: fn->left;
  399. } while (fn);
  400. /*
  401. * We walked to the bottom of tree.
  402. * Create new leaf node without children.
  403. */
  404. ln = node_alloc();
  405. if (ln == NULL)
  406. return NULL;
  407. ln->fn_bit = plen;
  408. ln->parent = pn;
  409. ln->fn_sernum = sernum;
  410. if (dir)
  411. pn->right = ln;
  412. else
  413. pn->left = ln;
  414. return ln;
  415. insert_above:
  416. /*
  417. * split since we don't have a common prefix anymore or
  418. * we have a less significant route.
  419. * we've to insert an intermediate node on the list
  420. * this new node will point to the one we need to create
  421. * and the current
  422. */
  423. pn = fn->parent;
  424. /* find 1st bit in difference between the 2 addrs.
  425. See comment in __ipv6_addr_diff: bit may be an invalid value,
  426. but if it is >= plen, the value is ignored in any case.
  427. */
  428. bit = __ipv6_addr_diff(addr, &key->addr, addrlen);
  429. /*
  430. * (intermediate)[in]
  431. * / \
  432. * (new leaf node)[ln] (old node)[fn]
  433. */
  434. if (plen > bit) {
  435. in = node_alloc();
  436. ln = node_alloc();
  437. if (in == NULL || ln == NULL) {
  438. if (in)
  439. node_free(in);
  440. if (ln)
  441. node_free(ln);
  442. return NULL;
  443. }
  444. /*
  445. * new intermediate node.
  446. * RTN_RTINFO will
  447. * be off since that an address that chooses one of
  448. * the branches would not match less specific routes
  449. * in the other branch
  450. */
  451. in->fn_bit = bit;
  452. in->parent = pn;
  453. in->leaf = fn->leaf;
  454. atomic_inc(&in->leaf->rt6i_ref);
  455. in->fn_sernum = sernum;
  456. /* update parent pointer */
  457. if (dir)
  458. pn->right = in;
  459. else
  460. pn->left = in;
  461. ln->fn_bit = plen;
  462. ln->parent = in;
  463. fn->parent = in;
  464. ln->fn_sernum = sernum;
  465. if (addr_bit_set(addr, bit)) {
  466. in->right = ln;
  467. in->left = fn;
  468. } else {
  469. in->left = ln;
  470. in->right = fn;
  471. }
  472. } else { /* plen <= bit */
  473. /*
  474. * (new leaf node)[ln]
  475. * / \
  476. * (old node)[fn] NULL
  477. */
  478. ln = node_alloc();
  479. if (ln == NULL)
  480. return NULL;
  481. ln->fn_bit = plen;
  482. ln->parent = pn;
  483. ln->fn_sernum = sernum;
  484. if (dir)
  485. pn->right = ln;
  486. else
  487. pn->left = ln;
  488. if (addr_bit_set(&key->addr, plen))
  489. ln->right = fn;
  490. else
  491. ln->left = fn;
  492. fn->parent = ln;
  493. }
  494. return ln;
  495. }
  496. /*
  497. * Insert routing information in a node.
  498. */
  499. static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
  500. struct nl_info *info)
  501. {
  502. struct rt6_info *iter = NULL;
  503. struct rt6_info **ins;
  504. ins = &fn->leaf;
  505. for (iter = fn->leaf; iter; iter=iter->u.dst.rt6_next) {
  506. /*
  507. * Search for duplicates
  508. */
  509. if (iter->rt6i_metric == rt->rt6i_metric) {
  510. /*
  511. * Same priority level
  512. */
  513. if (iter->rt6i_dev == rt->rt6i_dev &&
  514. iter->rt6i_idev == rt->rt6i_idev &&
  515. ipv6_addr_equal(&iter->rt6i_gateway,
  516. &rt->rt6i_gateway)) {
  517. if (!(iter->rt6i_flags&RTF_EXPIRES))
  518. return -EEXIST;
  519. iter->rt6i_expires = rt->rt6i_expires;
  520. if (!(rt->rt6i_flags&RTF_EXPIRES)) {
  521. iter->rt6i_flags &= ~RTF_EXPIRES;
  522. iter->rt6i_expires = 0;
  523. }
  524. return -EEXIST;
  525. }
  526. }
  527. if (iter->rt6i_metric > rt->rt6i_metric)
  528. break;
  529. ins = &iter->u.dst.rt6_next;
  530. }
  531. /* Reset round-robin state, if necessary */
  532. if (ins == &fn->leaf)
  533. fn->rr_ptr = NULL;
  534. /*
  535. * insert node
  536. */
  537. rt->u.dst.rt6_next = iter;
  538. *ins = rt;
  539. rt->rt6i_node = fn;
  540. atomic_inc(&rt->rt6i_ref);
  541. inet6_rt_notify(RTM_NEWROUTE, rt, info);
  542. rt6_stats.fib_rt_entries++;
  543. if ((fn->fn_flags & RTN_RTINFO) == 0) {
  544. rt6_stats.fib_route_nodes++;
  545. fn->fn_flags |= RTN_RTINFO;
  546. }
  547. return 0;
  548. }
  549. static __inline__ void fib6_start_gc(struct rt6_info *rt)
  550. {
  551. if (ip6_fib_timer.expires == 0 &&
  552. (rt->rt6i_flags & (RTF_EXPIRES|RTF_CACHE)))
  553. mod_timer(&ip6_fib_timer, jiffies + ip6_rt_gc_interval);
  554. }
  555. void fib6_force_start_gc(void)
  556. {
  557. if (ip6_fib_timer.expires == 0)
  558. mod_timer(&ip6_fib_timer, jiffies + ip6_rt_gc_interval);
  559. }
  560. /*
  561. * Add routing information to the routing tree.
  562. * <destination addr>/<source addr>
  563. * with source addr info in sub-trees
  564. */
  565. int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
  566. {
  567. struct fib6_node *fn, *pn = NULL;
  568. int err = -ENOMEM;
  569. fn = fib6_add_1(root, &rt->rt6i_dst.addr, sizeof(struct in6_addr),
  570. rt->rt6i_dst.plen, offsetof(struct rt6_info, rt6i_dst));
  571. if (fn == NULL)
  572. goto out;
  573. pn = fn;
  574. #ifdef CONFIG_IPV6_SUBTREES
  575. if (rt->rt6i_src.plen) {
  576. struct fib6_node *sn;
  577. if (fn->subtree == NULL) {
  578. struct fib6_node *sfn;
  579. /*
  580. * Create subtree.
  581. *
  582. * fn[main tree]
  583. * |
  584. * sfn[subtree root]
  585. * \
  586. * sn[new leaf node]
  587. */
  588. /* Create subtree root node */
  589. sfn = node_alloc();
  590. if (sfn == NULL)
  591. goto st_failure;
  592. sfn->leaf = &ip6_null_entry;
  593. atomic_inc(&ip6_null_entry.rt6i_ref);
  594. sfn->fn_flags = RTN_ROOT;
  595. sfn->fn_sernum = fib6_new_sernum();
  596. /* Now add the first leaf node to new subtree */
  597. sn = fib6_add_1(sfn, &rt->rt6i_src.addr,
  598. sizeof(struct in6_addr), rt->rt6i_src.plen,
  599. offsetof(struct rt6_info, rt6i_src));
  600. if (sn == NULL) {
  601. /* If it is failed, discard just allocated
  602. root, and then (in st_failure) stale node
  603. in main tree.
  604. */
  605. node_free(sfn);
  606. goto st_failure;
  607. }
  608. /* Now link new subtree to main tree */
  609. sfn->parent = fn;
  610. fn->subtree = sfn;
  611. } else {
  612. sn = fib6_add_1(fn->subtree, &rt->rt6i_src.addr,
  613. sizeof(struct in6_addr), rt->rt6i_src.plen,
  614. offsetof(struct rt6_info, rt6i_src));
  615. if (sn == NULL)
  616. goto st_failure;
  617. }
  618. if (fn->leaf == NULL) {
  619. fn->leaf = rt;
  620. atomic_inc(&rt->rt6i_ref);
  621. }
  622. fn = sn;
  623. }
  624. #endif
  625. err = fib6_add_rt2node(fn, rt, info);
  626. if (err == 0) {
  627. fib6_start_gc(rt);
  628. if (!(rt->rt6i_flags&RTF_CACHE))
  629. fib6_prune_clones(pn, rt);
  630. }
  631. out:
  632. if (err) {
  633. #ifdef CONFIG_IPV6_SUBTREES
  634. /*
  635. * If fib6_add_1 has cleared the old leaf pointer in the
  636. * super-tree leaf node we have to find a new one for it.
  637. */
  638. if (pn != fn && !pn->leaf && !(pn->fn_flags & RTN_RTINFO)) {
  639. pn->leaf = fib6_find_prefix(pn);
  640. #if RT6_DEBUG >= 2
  641. if (!pn->leaf) {
  642. BUG_TRAP(pn->leaf != NULL);
  643. pn->leaf = &ip6_null_entry;
  644. }
  645. #endif
  646. atomic_inc(&pn->leaf->rt6i_ref);
  647. }
  648. #endif
  649. dst_free(&rt->u.dst);
  650. }
  651. return err;
  652. #ifdef CONFIG_IPV6_SUBTREES
  653. /* Subtree creation failed, probably main tree node
  654. is orphan. If it is, shoot it.
  655. */
  656. st_failure:
  657. if (fn && !(fn->fn_flags & (RTN_RTINFO|RTN_ROOT)))
  658. fib6_repair_tree(fn);
  659. dst_free(&rt->u.dst);
  660. return err;
  661. #endif
  662. }
  663. /*
  664. * Routing tree lookup
  665. *
  666. */
  667. struct lookup_args {
  668. int offset; /* key offset on rt6_info */
  669. struct in6_addr *addr; /* search key */
  670. };
  671. static struct fib6_node * fib6_lookup_1(struct fib6_node *root,
  672. struct lookup_args *args)
  673. {
  674. struct fib6_node *fn;
  675. __be32 dir;
  676. if (unlikely(args->offset == 0))
  677. return NULL;
  678. /*
  679. * Descend on a tree
  680. */
  681. fn = root;
  682. for (;;) {
  683. struct fib6_node *next;
  684. dir = addr_bit_set(args->addr, fn->fn_bit);
  685. next = dir ? fn->right : fn->left;
  686. if (next) {
  687. fn = next;
  688. continue;
  689. }
  690. break;
  691. }
  692. while(fn) {
  693. if (FIB6_SUBTREE(fn) || fn->fn_flags & RTN_RTINFO) {
  694. struct rt6key *key;
  695. key = (struct rt6key *) ((u8 *) fn->leaf +
  696. args->offset);
  697. if (ipv6_prefix_equal(&key->addr, args->addr, key->plen)) {
  698. #ifdef CONFIG_IPV6_SUBTREES
  699. if (fn->subtree)
  700. fn = fib6_lookup_1(fn->subtree, args + 1);
  701. #endif
  702. if (!fn || fn->fn_flags & RTN_RTINFO)
  703. return fn;
  704. }
  705. }
  706. if (fn->fn_flags & RTN_ROOT)
  707. break;
  708. fn = fn->parent;
  709. }
  710. return NULL;
  711. }
  712. struct fib6_node * fib6_lookup(struct fib6_node *root, struct in6_addr *daddr,
  713. struct in6_addr *saddr)
  714. {
  715. struct fib6_node *fn;
  716. struct lookup_args args[] = {
  717. {
  718. .offset = offsetof(struct rt6_info, rt6i_dst),
  719. .addr = daddr,
  720. },
  721. #ifdef CONFIG_IPV6_SUBTREES
  722. {
  723. .offset = offsetof(struct rt6_info, rt6i_src),
  724. .addr = saddr,
  725. },
  726. #endif
  727. {
  728. .offset = 0, /* sentinel */
  729. }
  730. };
  731. fn = fib6_lookup_1(root, daddr ? args : args + 1);
  732. if (fn == NULL || fn->fn_flags & RTN_TL_ROOT)
  733. fn = root;
  734. return fn;
  735. }
  736. /*
  737. * Get node with specified destination prefix (and source prefix,
  738. * if subtrees are used)
  739. */
  740. static struct fib6_node * fib6_locate_1(struct fib6_node *root,
  741. struct in6_addr *addr,
  742. int plen, int offset)
  743. {
  744. struct fib6_node *fn;
  745. for (fn = root; fn ; ) {
  746. struct rt6key *key = (struct rt6key *)((u8 *)fn->leaf + offset);
  747. /*
  748. * Prefix match
  749. */
  750. if (plen < fn->fn_bit ||
  751. !ipv6_prefix_equal(&key->addr, addr, fn->fn_bit))
  752. return NULL;
  753. if (plen == fn->fn_bit)
  754. return fn;
  755. /*
  756. * We have more bits to go
  757. */
  758. if (addr_bit_set(addr, fn->fn_bit))
  759. fn = fn->right;
  760. else
  761. fn = fn->left;
  762. }
  763. return NULL;
  764. }
  765. struct fib6_node * fib6_locate(struct fib6_node *root,
  766. struct in6_addr *daddr, int dst_len,
  767. struct in6_addr *saddr, int src_len)
  768. {
  769. struct fib6_node *fn;
  770. fn = fib6_locate_1(root, daddr, dst_len,
  771. offsetof(struct rt6_info, rt6i_dst));
  772. #ifdef CONFIG_IPV6_SUBTREES
  773. if (src_len) {
  774. BUG_TRAP(saddr!=NULL);
  775. if (fn && fn->subtree)
  776. fn = fib6_locate_1(fn->subtree, saddr, src_len,
  777. offsetof(struct rt6_info, rt6i_src));
  778. }
  779. #endif
  780. if (fn && fn->fn_flags&RTN_RTINFO)
  781. return fn;
  782. return NULL;
  783. }
  784. /*
  785. * Deletion
  786. *
  787. */
  788. static struct rt6_info * fib6_find_prefix(struct fib6_node *fn)
  789. {
  790. if (fn->fn_flags&RTN_ROOT)
  791. return &ip6_null_entry;
  792. while(fn) {
  793. if(fn->left)
  794. return fn->left->leaf;
  795. if(fn->right)
  796. return fn->right->leaf;
  797. fn = FIB6_SUBTREE(fn);
  798. }
  799. return NULL;
  800. }
  801. /*
  802. * Called to trim the tree of intermediate nodes when possible. "fn"
  803. * is the node we want to try and remove.
  804. */
  805. static struct fib6_node * fib6_repair_tree(struct fib6_node *fn)
  806. {
  807. int children;
  808. int nstate;
  809. struct fib6_node *child, *pn;
  810. struct fib6_walker_t *w;
  811. int iter = 0;
  812. for (;;) {
  813. RT6_TRACE("fixing tree: plen=%d iter=%d\n", fn->fn_bit, iter);
  814. iter++;
  815. BUG_TRAP(!(fn->fn_flags&RTN_RTINFO));
  816. BUG_TRAP(!(fn->fn_flags&RTN_TL_ROOT));
  817. BUG_TRAP(fn->leaf==NULL);
  818. children = 0;
  819. child = NULL;
  820. if (fn->right) child = fn->right, children |= 1;
  821. if (fn->left) child = fn->left, children |= 2;
  822. if (children == 3 || FIB6_SUBTREE(fn)
  823. #ifdef CONFIG_IPV6_SUBTREES
  824. /* Subtree root (i.e. fn) may have one child */
  825. || (children && fn->fn_flags&RTN_ROOT)
  826. #endif
  827. ) {
  828. fn->leaf = fib6_find_prefix(fn);
  829. #if RT6_DEBUG >= 2
  830. if (fn->leaf==NULL) {
  831. BUG_TRAP(fn->leaf);
  832. fn->leaf = &ip6_null_entry;
  833. }
  834. #endif
  835. atomic_inc(&fn->leaf->rt6i_ref);
  836. return fn->parent;
  837. }
  838. pn = fn->parent;
  839. #ifdef CONFIG_IPV6_SUBTREES
  840. if (FIB6_SUBTREE(pn) == fn) {
  841. BUG_TRAP(fn->fn_flags&RTN_ROOT);
  842. FIB6_SUBTREE(pn) = NULL;
  843. nstate = FWS_L;
  844. } else {
  845. BUG_TRAP(!(fn->fn_flags&RTN_ROOT));
  846. #endif
  847. if (pn->right == fn) pn->right = child;
  848. else if (pn->left == fn) pn->left = child;
  849. #if RT6_DEBUG >= 2
  850. else BUG_TRAP(0);
  851. #endif
  852. if (child)
  853. child->parent = pn;
  854. nstate = FWS_R;
  855. #ifdef CONFIG_IPV6_SUBTREES
  856. }
  857. #endif
  858. read_lock(&fib6_walker_lock);
  859. FOR_WALKERS(w) {
  860. if (child == NULL) {
  861. if (w->root == fn) {
  862. w->root = w->node = NULL;
  863. RT6_TRACE("W %p adjusted by delroot 1\n", w);
  864. } else if (w->node == fn) {
  865. RT6_TRACE("W %p adjusted by delnode 1, s=%d/%d\n", w, w->state, nstate);
  866. w->node = pn;
  867. w->state = nstate;
  868. }
  869. } else {
  870. if (w->root == fn) {
  871. w->root = child;
  872. RT6_TRACE("W %p adjusted by delroot 2\n", w);
  873. }
  874. if (w->node == fn) {
  875. w->node = child;
  876. if (children&2) {
  877. RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w, w->state);
  878. w->state = w->state>=FWS_R ? FWS_U : FWS_INIT;
  879. } else {
  880. RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w, w->state);
  881. w->state = w->state>=FWS_C ? FWS_U : FWS_INIT;
  882. }
  883. }
  884. }
  885. }
  886. read_unlock(&fib6_walker_lock);
  887. node_free(fn);
  888. if (pn->fn_flags&RTN_RTINFO || FIB6_SUBTREE(pn))
  889. return pn;
  890. rt6_release(pn->leaf);
  891. pn->leaf = NULL;
  892. fn = pn;
  893. }
  894. }
  895. static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
  896. struct nl_info *info)
  897. {
  898. struct fib6_walker_t *w;
  899. struct rt6_info *rt = *rtp;
  900. RT6_TRACE("fib6_del_route\n");
  901. /* Unlink it */
  902. *rtp = rt->u.dst.rt6_next;
  903. rt->rt6i_node = NULL;
  904. rt6_stats.fib_rt_entries--;
  905. rt6_stats.fib_discarded_routes++;
  906. /* Reset round-robin state, if necessary */
  907. if (fn->rr_ptr == rt)
  908. fn->rr_ptr = NULL;
  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.dst.rt6_next;
  915. if (w->leaf == NULL)
  916. w->state = FWS_U;
  917. }
  918. }
  919. read_unlock(&fib6_walker_lock);
  920. rt->u.dst.rt6_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.dst.rt6_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 = container_of(w, struct fib6_cleaner_t, w);
  1096. for (rt = w->leaf; rt; rt = rt->u.dst.rt6_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|SLAB_PANIC,
  1235. NULL);
  1236. fib6_tables_init();
  1237. __rtnl_register(PF_INET6, RTM_GETROUTE, NULL, inet6_dump_fib);
  1238. }
  1239. void fib6_gc_cleanup(void)
  1240. {
  1241. del_timer(&ip6_fib_timer);
  1242. kmem_cache_destroy(fib6_node_kmem);
  1243. }