080-05-fib_trie-Merge-leaf-into-tnode.patch 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. From: Alexander Duyck <alexander.h.duyck@redhat.com>
  2. Date: Wed, 31 Dec 2014 10:55:47 -0800
  3. Subject: [PATCH] fib_trie: Merge leaf into tnode
  4. This change makes it so that leaf and tnode are the same struct. As a
  5. result there is no need for rt_trie_node anymore since everyting can be
  6. merged into tnode.
  7. On 32b systems this results in the leaf being 4 bytes larger, however I
  8. don't know if that is really an issue as this and an eariler patch that
  9. added bits & pos have increased the size from 20 to 28. If I am not
  10. mistaken slub/slab allocate on power of 2 sizes so 20 was likely being
  11. rounded up to 32 anyway.
  12. Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
  13. Signed-off-by: David S. Miller <davem@davemloft.net>
  14. ---
  15. --- a/net/ipv4/fib_trie.c
  16. +++ b/net/ipv4/fib_trie.c
  17. @@ -96,32 +96,16 @@ struct tnode {
  18. unsigned char pos; /* 2log(KEYLENGTH) bits needed */
  19. struct tnode __rcu *parent;
  20. struct rcu_head rcu;
  21. - /* everything above this comment must be the same as rt_trie_node */
  22. - unsigned int full_children; /* KEYLENGTH bits needed */
  23. - unsigned int empty_children; /* KEYLENGTH bits needed */
  24. - struct rt_trie_node __rcu *child[0];
  25. -};
  26. -
  27. -/* This struct represents the shared bits between tnode and leaf. If any
  28. - * ordering is changed here is must also be updated in tnode and leaf as
  29. - * well.
  30. - */
  31. -struct rt_trie_node {
  32. - t_key key;
  33. - unsigned char bits;
  34. - unsigned char pos;
  35. - struct tnode __rcu *parent;
  36. - struct rcu_head rcu;
  37. -};
  38. -
  39. -struct leaf {
  40. - t_key key;
  41. - unsigned char bits;
  42. - unsigned char pos;
  43. - struct tnode __rcu *parent;
  44. - struct rcu_head rcu;
  45. - /* everything above this comment must be the same as rt_trie_node */
  46. - struct hlist_head list;
  47. + union {
  48. + /* The fields in this struct are valid if bits > 0 (TNODE) */
  49. + struct {
  50. + unsigned int full_children; /* KEYLENGTH bits needed */
  51. + unsigned int empty_children; /* KEYLENGTH bits needed */
  52. + struct tnode __rcu *child[0];
  53. + };
  54. + /* This list pointer if valid if bits == 0 (LEAF) */
  55. + struct hlist_head list;
  56. + };
  57. };
  58. struct leaf_info {
  59. @@ -154,15 +138,15 @@ struct trie_stat {
  60. };
  61. struct trie {
  62. - struct rt_trie_node __rcu *trie;
  63. + struct tnode __rcu *trie;
  64. #ifdef CONFIG_IP_FIB_TRIE_STATS
  65. struct trie_use_stats __percpu *stats;
  66. #endif
  67. };
  68. -static void tnode_put_child_reorg(struct tnode *tn, int i, struct rt_trie_node *n,
  69. +static void tnode_put_child_reorg(struct tnode *tn, int i, struct tnode *n,
  70. int wasfull);
  71. -static struct rt_trie_node *resize(struct trie *t, struct tnode *tn);
  72. +static struct tnode *resize(struct trie *t, struct tnode *tn);
  73. static struct tnode *inflate(struct trie *t, struct tnode *tn);
  74. static struct tnode *halve(struct trie *t, struct tnode *tn);
  75. /* tnodes to free after resize(); protected by RTNL */
  76. @@ -186,10 +170,10 @@ static struct kmem_cache *trie_leaf_kmem
  77. #define node_parent_rcu(n) rcu_dereference_rtnl((n)->parent)
  78. /* wrapper for rcu_assign_pointer */
  79. -static inline void node_set_parent(struct rt_trie_node *node, struct tnode *ptr)
  80. +static inline void node_set_parent(struct tnode *n, struct tnode *tp)
  81. {
  82. - if (node)
  83. - rcu_assign_pointer(node->parent, ptr);
  84. + if (n)
  85. + rcu_assign_pointer(n->parent, tp);
  86. }
  87. #define NODE_INIT_PARENT(n, p) RCU_INIT_POINTER((n)->parent, p)
  88. @@ -205,7 +189,7 @@ static inline int tnode_child_length(con
  89. /*
  90. * caller must hold RTNL
  91. */
  92. -static inline struct rt_trie_node *tnode_get_child(const struct tnode *tn, unsigned int i)
  93. +static inline struct tnode *tnode_get_child(const struct tnode *tn, unsigned int i)
  94. {
  95. BUG_ON(i >= tnode_child_length(tn));
  96. @@ -215,7 +199,7 @@ static inline struct rt_trie_node *tnode
  97. /*
  98. * caller must hold RCU read lock or RTNL
  99. */
  100. -static inline struct rt_trie_node *tnode_get_child_rcu(const struct tnode *tn, unsigned int i)
  101. +static inline struct tnode *tnode_get_child_rcu(const struct tnode *tn, unsigned int i)
  102. {
  103. BUG_ON(i >= tnode_child_length(tn));
  104. @@ -340,11 +324,11 @@ static inline void alias_free_mem_rcu(st
  105. }
  106. #define TNODE_KMALLOC_MAX \
  107. - ilog2((PAGE_SIZE - sizeof(struct tnode)) / sizeof(struct rt_trie_node *))
  108. + ilog2((PAGE_SIZE - sizeof(struct tnode)) / sizeof(struct tnode *))
  109. static void __node_free_rcu(struct rcu_head *head)
  110. {
  111. - struct rt_trie_node *n = container_of(head, struct rt_trie_node, rcu);
  112. + struct tnode *n = container_of(head, struct tnode, rcu);
  113. if (IS_LEAF(n))
  114. kmem_cache_free(trie_leaf_kmem, n);
  115. @@ -395,9 +379,9 @@ static void tnode_free_flush(void)
  116. }
  117. }
  118. -static struct leaf *leaf_new(t_key key)
  119. +static struct tnode *leaf_new(t_key key)
  120. {
  121. - struct leaf *l = kmem_cache_alloc(trie_leaf_kmem, GFP_KERNEL);
  122. + struct tnode *l = kmem_cache_alloc(trie_leaf_kmem, GFP_KERNEL);
  123. if (l) {
  124. l->parent = NULL;
  125. /* set key and pos to reflect full key value
  126. @@ -444,7 +428,7 @@ static struct tnode *tnode_new(t_key key
  127. }
  128. pr_debug("AT %p s=%zu %zu\n", tn, sizeof(struct tnode),
  129. - sizeof(struct rt_trie_node *) << bits);
  130. + sizeof(struct tnode *) << bits);
  131. return tn;
  132. }
  133. @@ -453,13 +437,13 @@ static struct tnode *tnode_new(t_key key
  134. * and no bits are skipped. See discussion in dyntree paper p. 6
  135. */
  136. -static inline int tnode_full(const struct tnode *tn, const struct rt_trie_node *n)
  137. +static inline int tnode_full(const struct tnode *tn, const struct tnode *n)
  138. {
  139. return n && IS_TNODE(n) && (n->pos == (tn->pos + tn->bits));
  140. }
  141. static inline void put_child(struct tnode *tn, int i,
  142. - struct rt_trie_node *n)
  143. + struct tnode *n)
  144. {
  145. tnode_put_child_reorg(tn, i, n, -1);
  146. }
  147. @@ -469,10 +453,10 @@ static inline void put_child(struct tnod
  148. * Update the value of full_children and empty_children.
  149. */
  150. -static void tnode_put_child_reorg(struct tnode *tn, int i, struct rt_trie_node *n,
  151. +static void tnode_put_child_reorg(struct tnode *tn, int i, struct tnode *n,
  152. int wasfull)
  153. {
  154. - struct rt_trie_node *chi = rtnl_dereference(tn->child[i]);
  155. + struct tnode *chi = rtnl_dereference(tn->child[i]);
  156. int isfull;
  157. BUG_ON(i >= 1<<tn->bits);
  158. @@ -499,10 +483,9 @@ static void tnode_put_child_reorg(struct
  159. }
  160. #define MAX_WORK 10
  161. -static struct rt_trie_node *resize(struct trie *t, struct tnode *tn)
  162. +static struct tnode *resize(struct trie *t, struct tnode *tn)
  163. {
  164. - struct rt_trie_node *n = NULL;
  165. - struct tnode *old_tn;
  166. + struct tnode *old_tn, *n = NULL;
  167. int inflate_threshold_use;
  168. int halve_threshold_use;
  169. int max_work;
  170. @@ -614,7 +597,7 @@ static struct rt_trie_node *resize(struc
  171. /* Return if at least one inflate is run */
  172. if (max_work != MAX_WORK)
  173. - return (struct rt_trie_node *) tn;
  174. + return tn;
  175. /*
  176. * Halve as long as the number of empty children in this
  177. @@ -650,13 +633,13 @@ no_children:
  178. tnode_free_safe(tn);
  179. return n;
  180. }
  181. - return (struct rt_trie_node *) tn;
  182. + return tn;
  183. }
  184. static void tnode_clean_free(struct tnode *tn)
  185. {
  186. - struct rt_trie_node *tofree;
  187. + struct tnode *tofree;
  188. int i;
  189. for (i = 0; i < tnode_child_length(tn); i++) {
  190. @@ -667,10 +650,10 @@ static void tnode_clean_free(struct tnod
  191. node_free(tn);
  192. }
  193. -static struct tnode *inflate(struct trie *t, struct tnode *tn)
  194. +static struct tnode *inflate(struct trie *t, struct tnode *oldtnode)
  195. {
  196. - struct tnode *oldtnode = tn;
  197. - int olen = tnode_child_length(tn);
  198. + int olen = tnode_child_length(oldtnode);
  199. + struct tnode *tn;
  200. int i;
  201. pr_debug("In inflate\n");
  202. @@ -690,11 +673,8 @@ static struct tnode *inflate(struct trie
  203. for (i = 0; i < olen; i++) {
  204. struct tnode *inode;
  205. - inode = (struct tnode *) tnode_get_child(oldtnode, i);
  206. - if (inode &&
  207. - IS_TNODE(inode) &&
  208. - inode->pos == oldtnode->pos + oldtnode->bits &&
  209. - inode->bits > 1) {
  210. + inode = tnode_get_child(oldtnode, i);
  211. + if (tnode_full(oldtnode, inode) && inode->bits > 1) {
  212. struct tnode *left, *right;
  213. t_key m = ~0U << (KEYLENGTH - 1) >> inode->pos;
  214. @@ -711,33 +691,29 @@ static struct tnode *inflate(struct trie
  215. goto nomem;
  216. }
  217. - put_child(tn, 2*i, (struct rt_trie_node *) left);
  218. - put_child(tn, 2*i+1, (struct rt_trie_node *) right);
  219. + put_child(tn, 2*i, left);
  220. + put_child(tn, 2*i+1, right);
  221. }
  222. }
  223. for (i = 0; i < olen; i++) {
  224. - struct tnode *inode;
  225. - struct rt_trie_node *node = tnode_get_child(oldtnode, i);
  226. + struct tnode *inode = tnode_get_child(oldtnode, i);
  227. struct tnode *left, *right;
  228. int size, j;
  229. /* An empty child */
  230. - if (node == NULL)
  231. + if (inode == NULL)
  232. continue;
  233. /* A leaf or an internal node with skipped bits */
  234. -
  235. - if (IS_LEAF(node) || (node->pos > (tn->pos + tn->bits - 1))) {
  236. + if (!tnode_full(oldtnode, inode)) {
  237. put_child(tn,
  238. - tkey_extract_bits(node->key, oldtnode->pos, oldtnode->bits + 1),
  239. - node);
  240. + tkey_extract_bits(inode->key, tn->pos, tn->bits),
  241. + inode);
  242. continue;
  243. }
  244. /* An internal node with two children */
  245. - inode = (struct tnode *) node;
  246. -
  247. if (inode->bits == 1) {
  248. put_child(tn, 2*i, rtnl_dereference(inode->child[0]));
  249. put_child(tn, 2*i+1, rtnl_dereference(inode->child[1]));
  250. @@ -769,12 +745,12 @@ static struct tnode *inflate(struct trie
  251. * bit to zero.
  252. */
  253. - left = (struct tnode *) tnode_get_child(tn, 2*i);
  254. + left = tnode_get_child(tn, 2*i);
  255. put_child(tn, 2*i, NULL);
  256. BUG_ON(!left);
  257. - right = (struct tnode *) tnode_get_child(tn, 2*i+1);
  258. + right = tnode_get_child(tn, 2*i+1);
  259. put_child(tn, 2*i+1, NULL);
  260. BUG_ON(!right);
  261. @@ -796,12 +772,11 @@ nomem:
  262. return ERR_PTR(-ENOMEM);
  263. }
  264. -static struct tnode *halve(struct trie *t, struct tnode *tn)
  265. +static struct tnode *halve(struct trie *t, struct tnode *oldtnode)
  266. {
  267. - struct tnode *oldtnode = tn;
  268. - struct rt_trie_node *left, *right;
  269. + int olen = tnode_child_length(oldtnode);
  270. + struct tnode *tn, *left, *right;
  271. int i;
  272. - int olen = tnode_child_length(tn);
  273. pr_debug("In halve\n");
  274. @@ -830,7 +805,7 @@ static struct tnode *halve(struct trie *
  275. if (!newn)
  276. goto nomem;
  277. - put_child(tn, i/2, (struct rt_trie_node *)newn);
  278. + put_child(tn, i/2, newn);
  279. }
  280. }
  281. @@ -855,7 +830,7 @@ static struct tnode *halve(struct trie *
  282. }
  283. /* Two nonempty children */
  284. - newBinNode = (struct tnode *) tnode_get_child(tn, i/2);
  285. + newBinNode = tnode_get_child(tn, i/2);
  286. put_child(tn, i/2, NULL);
  287. put_child(newBinNode, 0, left);
  288. put_child(newBinNode, 1, right);
  289. @@ -871,7 +846,7 @@ nomem:
  290. /* readside must use rcu_read_lock currently dump routines
  291. via get_fa_head and dump */
  292. -static struct leaf_info *find_leaf_info(struct leaf *l, int plen)
  293. +static struct leaf_info *find_leaf_info(struct tnode *l, int plen)
  294. {
  295. struct hlist_head *head = &l->list;
  296. struct leaf_info *li;
  297. @@ -883,7 +858,7 @@ static struct leaf_info *find_leaf_info(
  298. return NULL;
  299. }
  300. -static inline struct list_head *get_fa_head(struct leaf *l, int plen)
  301. +static inline struct list_head *get_fa_head(struct tnode *l, int plen)
  302. {
  303. struct leaf_info *li = find_leaf_info(l, plen);
  304. @@ -915,32 +890,25 @@ static void insert_leaf_info(struct hlis
  305. /* rcu_read_lock needs to be hold by caller from readside */
  306. -static struct leaf *
  307. -fib_find_node(struct trie *t, u32 key)
  308. +static struct tnode *fib_find_node(struct trie *t, u32 key)
  309. {
  310. - int pos;
  311. - struct tnode *tn;
  312. - struct rt_trie_node *n;
  313. -
  314. - pos = 0;
  315. - n = rcu_dereference_rtnl(t->trie);
  316. + struct tnode *n = rcu_dereference_rtnl(t->trie);
  317. + int pos = 0;
  318. while (n && IS_TNODE(n)) {
  319. - tn = (struct tnode *) n;
  320. -
  321. - if (tkey_sub_equals(tn->key, pos, tn->pos-pos, key)) {
  322. - pos = tn->pos + tn->bits;
  323. - n = tnode_get_child_rcu(tn,
  324. + if (tkey_sub_equals(n->key, pos, n->pos-pos, key)) {
  325. + pos = n->pos + n->bits;
  326. + n = tnode_get_child_rcu(n,
  327. tkey_extract_bits(key,
  328. - tn->pos,
  329. - tn->bits));
  330. + n->pos,
  331. + n->bits));
  332. } else
  333. break;
  334. }
  335. /* Case we have found a leaf. Compare prefixes */
  336. if (n != NULL && IS_LEAF(n) && tkey_equals(key, n->key))
  337. - return (struct leaf *)n;
  338. + return n;
  339. return NULL;
  340. }
  341. @@ -956,14 +924,13 @@ static void trie_rebalance(struct trie *
  342. while (tn != NULL && (tp = node_parent(tn)) != NULL) {
  343. cindex = tkey_extract_bits(key, tp->pos, tp->bits);
  344. wasfull = tnode_full(tp, tnode_get_child(tp, cindex));
  345. - tn = (struct tnode *)resize(t, tn);
  346. + tn = resize(t, tn);
  347. - tnode_put_child_reorg(tp, cindex,
  348. - (struct rt_trie_node *)tn, wasfull);
  349. + tnode_put_child_reorg(tp, cindex, tn, wasfull);
  350. tp = node_parent(tn);
  351. if (!tp)
  352. - rcu_assign_pointer(t->trie, (struct rt_trie_node *)tn);
  353. + rcu_assign_pointer(t->trie, tn);
  354. tnode_free_flush();
  355. if (!tp)
  356. @@ -973,9 +940,9 @@ static void trie_rebalance(struct trie *
  357. /* Handle last (top) tnode */
  358. if (IS_TNODE(tn))
  359. - tn = (struct tnode *)resize(t, tn);
  360. + tn = resize(t, tn);
  361. - rcu_assign_pointer(t->trie, (struct rt_trie_node *)tn);
  362. + rcu_assign_pointer(t->trie, tn);
  363. tnode_free_flush();
  364. }
  365. @@ -985,8 +952,8 @@ static struct list_head *fib_insert_node
  366. {
  367. int pos, newpos;
  368. struct tnode *tp = NULL, *tn = NULL;
  369. - struct rt_trie_node *n;
  370. - struct leaf *l;
  371. + struct tnode *n;
  372. + struct tnode *l;
  373. int missbit;
  374. struct list_head *fa_head = NULL;
  375. struct leaf_info *li;
  376. @@ -1014,17 +981,15 @@ static struct list_head *fib_insert_node
  377. */
  378. while (n && IS_TNODE(n)) {
  379. - tn = (struct tnode *) n;
  380. -
  381. - if (tkey_sub_equals(tn->key, pos, tn->pos-pos, key)) {
  382. - tp = tn;
  383. - pos = tn->pos + tn->bits;
  384. - n = tnode_get_child(tn,
  385. + if (tkey_sub_equals(n->key, pos, n->pos-pos, key)) {
  386. + tp = n;
  387. + pos = n->pos + n->bits;
  388. + n = tnode_get_child(n,
  389. tkey_extract_bits(key,
  390. - tn->pos,
  391. - tn->bits));
  392. + n->pos,
  393. + n->bits));
  394. - BUG_ON(n && node_parent(n) != tn);
  395. + BUG_ON(n && node_parent(n) != tp);
  396. } else
  397. break;
  398. }
  399. @@ -1040,14 +1005,13 @@ static struct list_head *fib_insert_node
  400. /* Case 1: n is a leaf. Compare prefixes */
  401. if (n != NULL && IS_LEAF(n) && tkey_equals(key, n->key)) {
  402. - l = (struct leaf *) n;
  403. li = leaf_info_new(plen);
  404. if (!li)
  405. return NULL;
  406. fa_head = &li->falh;
  407. - insert_leaf_info(&l->list, li);
  408. + insert_leaf_info(&n->list, li);
  409. goto done;
  410. }
  411. l = leaf_new(key);
  412. @@ -1068,10 +1032,10 @@ static struct list_head *fib_insert_node
  413. if (t->trie && n == NULL) {
  414. /* Case 2: n is NULL, and will just insert a new leaf */
  415. - node_set_parent((struct rt_trie_node *)l, tp);
  416. + node_set_parent(l, tp);
  417. cindex = tkey_extract_bits(key, tp->pos, tp->bits);
  418. - put_child(tp, cindex, (struct rt_trie_node *)l);
  419. + put_child(tp, cindex, l);
  420. } else {
  421. /* Case 3: n is a LEAF or a TNODE and the key doesn't match. */
  422. /*
  423. @@ -1094,17 +1058,17 @@ static struct list_head *fib_insert_node
  424. return NULL;
  425. }
  426. - node_set_parent((struct rt_trie_node *)tn, tp);
  427. + node_set_parent(tn, tp);
  428. missbit = tkey_extract_bits(key, newpos, 1);
  429. - put_child(tn, missbit, (struct rt_trie_node *)l);
  430. + put_child(tn, missbit, l);
  431. put_child(tn, 1-missbit, n);
  432. if (tp) {
  433. cindex = tkey_extract_bits(key, tp->pos, tp->bits);
  434. - put_child(tp, cindex, (struct rt_trie_node *)tn);
  435. + put_child(tp, cindex, tn);
  436. } else {
  437. - rcu_assign_pointer(t->trie, (struct rt_trie_node *)tn);
  438. + rcu_assign_pointer(t->trie, tn);
  439. }
  440. tp = tn;
  441. @@ -1134,7 +1098,7 @@ int fib_table_insert(struct fib_table *t
  442. u8 tos = cfg->fc_tos;
  443. u32 key, mask;
  444. int err;
  445. - struct leaf *l;
  446. + struct tnode *l;
  447. if (plen > 32)
  448. return -EINVAL;
  449. @@ -1292,7 +1256,7 @@ err:
  450. }
  451. /* should be called with rcu_read_lock */
  452. -static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l,
  453. +static int check_leaf(struct fib_table *tb, struct trie *t, struct tnode *l,
  454. t_key key, const struct flowi4 *flp,
  455. struct fib_result *res, int fib_flags)
  456. {
  457. @@ -1365,7 +1329,7 @@ int fib_table_lookup(struct fib_table *t
  458. struct trie_use_stats __percpu *stats = t->stats;
  459. #endif
  460. int ret;
  461. - struct rt_trie_node *n;
  462. + struct tnode *n;
  463. struct tnode *pn;
  464. unsigned int pos, bits;
  465. t_key key = ntohl(flp->daddr);
  466. @@ -1387,11 +1351,11 @@ int fib_table_lookup(struct fib_table *t
  467. /* Just a leaf? */
  468. if (IS_LEAF(n)) {
  469. - ret = check_leaf(tb, t, (struct leaf *)n, key, flp, res, fib_flags);
  470. + ret = check_leaf(tb, t, n, key, flp, res, fib_flags);
  471. goto found;
  472. }
  473. - pn = (struct tnode *) n;
  474. + pn = n;
  475. chopped_off = 0;
  476. while (pn) {
  477. @@ -1412,13 +1376,13 @@ int fib_table_lookup(struct fib_table *t
  478. }
  479. if (IS_LEAF(n)) {
  480. - ret = check_leaf(tb, t, (struct leaf *)n, key, flp, res, fib_flags);
  481. + ret = check_leaf(tb, t, n, key, flp, res, fib_flags);
  482. if (ret > 0)
  483. goto backtrace;
  484. goto found;
  485. }
  486. - cn = (struct tnode *)n;
  487. + cn = n;
  488. /*
  489. * It's a tnode, and we can do some extra checks here if we
  490. @@ -1506,7 +1470,7 @@ int fib_table_lookup(struct fib_table *t
  491. current_prefix_length = mp;
  492. }
  493. - pn = (struct tnode *)n; /* Descend */
  494. + pn = n; /* Descend */
  495. chopped_off = 0;
  496. continue;
  497. @@ -1557,7 +1521,7 @@ EXPORT_SYMBOL_GPL(fib_table_lookup);
  498. /*
  499. * Remove the leaf and return parent.
  500. */
  501. -static void trie_leaf_remove(struct trie *t, struct leaf *l)
  502. +static void trie_leaf_remove(struct trie *t, struct tnode *l)
  503. {
  504. struct tnode *tp = node_parent(l);
  505. @@ -1584,7 +1548,7 @@ int fib_table_delete(struct fib_table *t
  506. u8 tos = cfg->fc_tos;
  507. struct fib_alias *fa, *fa_to_delete;
  508. struct list_head *fa_head;
  509. - struct leaf *l;
  510. + struct tnode *l;
  511. struct leaf_info *li;
  512. if (plen > 32)
  513. @@ -1682,7 +1646,7 @@ static int trie_flush_list(struct list_h
  514. return found;
  515. }
  516. -static int trie_flush_leaf(struct leaf *l)
  517. +static int trie_flush_leaf(struct tnode *l)
  518. {
  519. int found = 0;
  520. struct hlist_head *lih = &l->list;
  521. @@ -1704,7 +1668,7 @@ static int trie_flush_leaf(struct leaf *
  522. * Scan for the next right leaf starting at node p->child[idx]
  523. * Since we have back pointer, no recursion necessary.
  524. */
  525. -static struct leaf *leaf_walk_rcu(struct tnode *p, struct rt_trie_node *c)
  526. +static struct tnode *leaf_walk_rcu(struct tnode *p, struct tnode *c)
  527. {
  528. do {
  529. t_key idx;
  530. @@ -1720,47 +1684,46 @@ static struct leaf *leaf_walk_rcu(struct
  531. continue;
  532. if (IS_LEAF(c))
  533. - return (struct leaf *) c;
  534. + return c;
  535. /* Rescan start scanning in new node */
  536. - p = (struct tnode *) c;
  537. + p = c;
  538. idx = 0;
  539. }
  540. /* Node empty, walk back up to parent */
  541. - c = (struct rt_trie_node *) p;
  542. + c = p;
  543. } while ((p = node_parent_rcu(c)) != NULL);
  544. return NULL; /* Root of trie */
  545. }
  546. -static struct leaf *trie_firstleaf(struct trie *t)
  547. +static struct tnode *trie_firstleaf(struct trie *t)
  548. {
  549. - struct tnode *n = (struct tnode *)rcu_dereference_rtnl(t->trie);
  550. + struct tnode *n = rcu_dereference_rtnl(t->trie);
  551. if (!n)
  552. return NULL;
  553. if (IS_LEAF(n)) /* trie is just a leaf */
  554. - return (struct leaf *) n;
  555. + return n;
  556. return leaf_walk_rcu(n, NULL);
  557. }
  558. -static struct leaf *trie_nextleaf(struct leaf *l)
  559. +static struct tnode *trie_nextleaf(struct tnode *l)
  560. {
  561. - struct rt_trie_node *c = (struct rt_trie_node *) l;
  562. - struct tnode *p = node_parent_rcu(c);
  563. + struct tnode *p = node_parent_rcu(l);
  564. if (!p)
  565. return NULL; /* trie with just one leaf */
  566. - return leaf_walk_rcu(p, c);
  567. + return leaf_walk_rcu(p, l);
  568. }
  569. -static struct leaf *trie_leafindex(struct trie *t, int index)
  570. +static struct tnode *trie_leafindex(struct trie *t, int index)
  571. {
  572. - struct leaf *l = trie_firstleaf(t);
  573. + struct tnode *l = trie_firstleaf(t);
  574. while (l && index-- > 0)
  575. l = trie_nextleaf(l);
  576. @@ -1775,7 +1738,7 @@ static struct leaf *trie_leafindex(struc
  577. int fib_table_flush(struct fib_table *tb)
  578. {
  579. struct trie *t = (struct trie *) tb->tb_data;
  580. - struct leaf *l, *ll = NULL;
  581. + struct tnode *l, *ll = NULL;
  582. int found = 0;
  583. for (l = trie_firstleaf(t); l; l = trie_nextleaf(l)) {
  584. @@ -1840,7 +1803,7 @@ static int fn_trie_dump_fa(t_key key, in
  585. return skb->len;
  586. }
  587. -static int fn_trie_dump_leaf(struct leaf *l, struct fib_table *tb,
  588. +static int fn_trie_dump_leaf(struct tnode *l, struct fib_table *tb,
  589. struct sk_buff *skb, struct netlink_callback *cb)
  590. {
  591. struct leaf_info *li;
  592. @@ -1876,7 +1839,7 @@ static int fn_trie_dump_leaf(struct leaf
  593. int fib_table_dump(struct fib_table *tb, struct sk_buff *skb,
  594. struct netlink_callback *cb)
  595. {
  596. - struct leaf *l;
  597. + struct tnode *l;
  598. struct trie *t = (struct trie *) tb->tb_data;
  599. t_key key = cb->args[2];
  600. int count = cb->args[3];
  601. @@ -1922,7 +1885,7 @@ void __init fib_trie_init(void)
  602. 0, SLAB_PANIC, NULL);
  603. trie_leaf_kmem = kmem_cache_create("ip_fib_trie",
  604. - max(sizeof(struct leaf),
  605. + max(sizeof(struct tnode),
  606. sizeof(struct leaf_info)),
  607. 0, SLAB_PANIC, NULL);
  608. }
  609. @@ -1965,7 +1928,7 @@ struct fib_trie_iter {
  610. unsigned int depth;
  611. };
  612. -static struct rt_trie_node *fib_trie_get_next(struct fib_trie_iter *iter)
  613. +static struct tnode *fib_trie_get_next(struct fib_trie_iter *iter)
  614. {
  615. struct tnode *tn = iter->tnode;
  616. unsigned int cindex = iter->index;
  617. @@ -1979,7 +1942,7 @@ static struct rt_trie_node *fib_trie_get
  618. iter->tnode, iter->index, iter->depth);
  619. rescan:
  620. while (cindex < (1<<tn->bits)) {
  621. - struct rt_trie_node *n = tnode_get_child_rcu(tn, cindex);
  622. + struct tnode *n = tnode_get_child_rcu(tn, cindex);
  623. if (n) {
  624. if (IS_LEAF(n)) {
  625. @@ -1987,7 +1950,7 @@ rescan:
  626. iter->index = cindex + 1;
  627. } else {
  628. /* push down one level */
  629. - iter->tnode = (struct tnode *) n;
  630. + iter->tnode = n;
  631. iter->index = 0;
  632. ++iter->depth;
  633. }
  634. @@ -1998,7 +1961,7 @@ rescan:
  635. }
  636. /* Current node exhausted, pop back up */
  637. - p = node_parent_rcu((struct rt_trie_node *)tn);
  638. + p = node_parent_rcu(tn);
  639. if (p) {
  640. cindex = tkey_extract_bits(tn->key, p->pos, p->bits)+1;
  641. tn = p;
  642. @@ -2010,10 +1973,10 @@ rescan:
  643. return NULL;
  644. }
  645. -static struct rt_trie_node *fib_trie_get_first(struct fib_trie_iter *iter,
  646. +static struct tnode *fib_trie_get_first(struct fib_trie_iter *iter,
  647. struct trie *t)
  648. {
  649. - struct rt_trie_node *n;
  650. + struct tnode *n;
  651. if (!t)
  652. return NULL;
  653. @@ -2023,7 +1986,7 @@ static struct rt_trie_node *fib_trie_get
  654. return NULL;
  655. if (IS_TNODE(n)) {
  656. - iter->tnode = (struct tnode *) n;
  657. + iter->tnode = n;
  658. iter->index = 0;
  659. iter->depth = 1;
  660. } else {
  661. @@ -2037,7 +2000,7 @@ static struct rt_trie_node *fib_trie_get
  662. static void trie_collect_stats(struct trie *t, struct trie_stat *s)
  663. {
  664. - struct rt_trie_node *n;
  665. + struct tnode *n;
  666. struct fib_trie_iter iter;
  667. memset(s, 0, sizeof(*s));
  668. @@ -2045,7 +2008,6 @@ static void trie_collect_stats(struct tr
  669. rcu_read_lock();
  670. for (n = fib_trie_get_first(&iter, t); n; n = fib_trie_get_next(&iter)) {
  671. if (IS_LEAF(n)) {
  672. - struct leaf *l = (struct leaf *)n;
  673. struct leaf_info *li;
  674. s->leaves++;
  675. @@ -2053,18 +2015,17 @@ static void trie_collect_stats(struct tr
  676. if (iter.depth > s->maxdepth)
  677. s->maxdepth = iter.depth;
  678. - hlist_for_each_entry_rcu(li, &l->list, hlist)
  679. + hlist_for_each_entry_rcu(li, &n->list, hlist)
  680. ++s->prefixes;
  681. } else {
  682. - const struct tnode *tn = (const struct tnode *) n;
  683. int i;
  684. s->tnodes++;
  685. - if (tn->bits < MAX_STAT_DEPTH)
  686. - s->nodesizes[tn->bits]++;
  687. + if (n->bits < MAX_STAT_DEPTH)
  688. + s->nodesizes[n->bits]++;
  689. - for (i = 0; i < (1<<tn->bits); i++)
  690. - if (!tn->child[i])
  691. + for (i = 0; i < tnode_child_length(n); i++)
  692. + if (!rcu_access_pointer(n->child[i]))
  693. s->nullpointers++;
  694. }
  695. }
  696. @@ -2088,7 +2049,7 @@ static void trie_show_stats(struct seq_f
  697. seq_printf(seq, "\tMax depth: %u\n", stat->maxdepth);
  698. seq_printf(seq, "\tLeaves: %u\n", stat->leaves);
  699. - bytes = sizeof(struct leaf) * stat->leaves;
  700. + bytes = sizeof(struct tnode) * stat->leaves;
  701. seq_printf(seq, "\tPrefixes: %u\n", stat->prefixes);
  702. bytes += sizeof(struct leaf_info) * stat->prefixes;
  703. @@ -2109,7 +2070,7 @@ static void trie_show_stats(struct seq_f
  704. seq_putc(seq, '\n');
  705. seq_printf(seq, "\tPointers: %u\n", pointers);
  706. - bytes += sizeof(struct rt_trie_node *) * pointers;
  707. + bytes += sizeof(struct tnode *) * pointers;
  708. seq_printf(seq, "Null ptrs: %u\n", stat->nullpointers);
  709. seq_printf(seq, "Total size: %u kB\n", (bytes + 1023) / 1024);
  710. }
  711. @@ -2163,7 +2124,7 @@ static int fib_triestat_seq_show(struct
  712. seq_printf(seq,
  713. "Basic info: size of leaf:"
  714. " %Zd bytes, size of tnode: %Zd bytes.\n",
  715. - sizeof(struct leaf), sizeof(struct tnode));
  716. + sizeof(struct tnode), sizeof(struct tnode));
  717. for (h = 0; h < FIB_TABLE_HASHSZ; h++) {
  718. struct hlist_head *head = &net->ipv4.fib_table_hash[h];
  719. @@ -2202,7 +2163,7 @@ static const struct file_operations fib_
  720. .release = single_release_net,
  721. };
  722. -static struct rt_trie_node *fib_trie_get_idx(struct seq_file *seq, loff_t pos)
  723. +static struct tnode *fib_trie_get_idx(struct seq_file *seq, loff_t pos)
  724. {
  725. struct fib_trie_iter *iter = seq->private;
  726. struct net *net = seq_file_net(seq);
  727. @@ -2214,7 +2175,7 @@ static struct rt_trie_node *fib_trie_get
  728. struct fib_table *tb;
  729. hlist_for_each_entry_rcu(tb, head, tb_hlist) {
  730. - struct rt_trie_node *n;
  731. + struct tnode *n;
  732. for (n = fib_trie_get_first(iter,
  733. (struct trie *) tb->tb_data);
  734. @@ -2243,7 +2204,7 @@ static void *fib_trie_seq_next(struct se
  735. struct fib_table *tb = iter->tb;
  736. struct hlist_node *tb_node;
  737. unsigned int h;
  738. - struct rt_trie_node *n;
  739. + struct tnode *n;
  740. ++*pos;
  741. /* next node in same table */
  742. @@ -2329,29 +2290,26 @@ static inline const char *rtn_type(char
  743. static int fib_trie_seq_show(struct seq_file *seq, void *v)
  744. {
  745. const struct fib_trie_iter *iter = seq->private;
  746. - struct rt_trie_node *n = v;
  747. + struct tnode *n = v;
  748. if (!node_parent_rcu(n))
  749. fib_table_print(seq, iter->tb);
  750. if (IS_TNODE(n)) {
  751. - struct tnode *tn = (struct tnode *) n;
  752. - __be32 prf = htonl(tn->key);
  753. + __be32 prf = htonl(n->key);
  754. - seq_indent(seq, iter->depth-1);
  755. + seq_indent(seq, iter->depth - 1);
  756. seq_printf(seq, " +-- %pI4/%d %d %d %d\n",
  757. - &prf, tn->pos, tn->bits, tn->full_children,
  758. - tn->empty_children);
  759. -
  760. + &prf, n->pos, n->bits, n->full_children,
  761. + n->empty_children);
  762. } else {
  763. - struct leaf *l = (struct leaf *) n;
  764. struct leaf_info *li;
  765. - __be32 val = htonl(l->key);
  766. + __be32 val = htonl(n->key);
  767. seq_indent(seq, iter->depth);
  768. seq_printf(seq, " |-- %pI4\n", &val);
  769. - hlist_for_each_entry_rcu(li, &l->list, hlist) {
  770. + hlist_for_each_entry_rcu(li, &n->list, hlist) {
  771. struct fib_alias *fa;
  772. list_for_each_entry_rcu(fa, &li->falh, fa_list) {
  773. @@ -2401,9 +2359,9 @@ struct fib_route_iter {
  774. t_key key;
  775. };
  776. -static struct leaf *fib_route_get_idx(struct fib_route_iter *iter, loff_t pos)
  777. +static struct tnode *fib_route_get_idx(struct fib_route_iter *iter, loff_t pos)
  778. {
  779. - struct leaf *l = NULL;
  780. + struct tnode *l = NULL;
  781. struct trie *t = iter->main_trie;
  782. /* use cache location of last found key */
  783. @@ -2448,7 +2406,7 @@ static void *fib_route_seq_start(struct
  784. static void *fib_route_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  785. {
  786. struct fib_route_iter *iter = seq->private;
  787. - struct leaf *l = v;
  788. + struct tnode *l = v;
  789. ++*pos;
  790. if (v == SEQ_START_TOKEN) {
  791. @@ -2494,7 +2452,7 @@ static unsigned int fib_flag_trans(int t
  792. */
  793. static int fib_route_seq_show(struct seq_file *seq, void *v)
  794. {
  795. - struct leaf *l = v;
  796. + struct tnode *l = v;
  797. struct leaf_info *li;
  798. if (v == SEQ_START_TOKEN) {