@@ -159,9 +159,11 @@ static struct kmem_cache *trie_leaf_kmem __read_mostly;
159
159
160
160
/* caller must hold RTNL */
161
161
#define node_parent (n ) rtnl_dereference((n)->parent)
162
+ #define get_child (tn , i ) rtnl_dereference((tn)->tnode[i])
162
163
163
164
/* caller must hold RCU read lock or RTNL */
164
165
#define node_parent_rcu (n ) rcu_dereference_rtnl((n)->parent)
166
+ #define get_child_rcu (tn , i ) rcu_dereference_rtnl((tn)->tnode[i])
165
167
166
168
/* wrapper for rcu_assign_pointer */
167
169
static inline void node_set_parent (struct key_vector * n , struct key_vector * tp )
@@ -180,20 +182,6 @@ static inline unsigned long tnode_child_length(const struct key_vector *tn)
180
182
return (1ul << tn -> bits ) & ~(1ul );
181
183
}
182
184
183
- /* caller must hold RTNL */
184
- static inline struct key_vector * tnode_get_child (struct key_vector * tn ,
185
- unsigned long i )
186
- {
187
- return rtnl_dereference (tn -> tnode [i ]);
188
- }
189
-
190
- /* caller must hold RCU read lock or RTNL */
191
- static inline struct key_vector * tnode_get_child_rcu (struct key_vector * tn ,
192
- unsigned long i )
193
- {
194
- return rcu_dereference_rtnl (tn -> tnode [i ]);
195
- }
196
-
197
185
static inline struct fib_table * trie_get_table (struct trie * t )
198
186
{
199
187
unsigned long * tb_data = (unsigned long * )t ;
@@ -383,7 +371,7 @@ static inline int tnode_full(struct key_vector *tn, struct key_vector *n)
383
371
static void put_child (struct key_vector * tn , unsigned long i ,
384
372
struct key_vector * n )
385
373
{
386
- struct key_vector * chi = tnode_get_child (tn , i );
374
+ struct key_vector * chi = get_child (tn , i );
387
375
int isfull , wasfull ;
388
376
389
377
BUG_ON (i >= tnode_child_length (tn ));
@@ -415,7 +403,7 @@ static void update_children(struct key_vector *tn)
415
403
416
404
/* update all of the child parent pointers */
417
405
for (i = tnode_child_length (tn ); i ;) {
418
- struct key_vector * inode = tnode_get_child (tn , -- i );
406
+ struct key_vector * inode = get_child (tn , -- i );
419
407
420
408
if (!inode )
421
409
continue ;
@@ -493,7 +481,7 @@ static struct key_vector __rcu **replace(struct trie *t,
493
481
494
482
/* resize children now that oldtnode is freed */
495
483
for (i = tnode_child_length (tn ); i ;) {
496
- struct key_vector * inode = tnode_get_child (tn , -- i );
484
+ struct key_vector * inode = get_child (tn , -- i );
497
485
498
486
/* resize child node */
499
487
if (tnode_full (tn , inode ))
@@ -525,7 +513,7 @@ static struct key_vector __rcu **inflate(struct trie *t,
525
513
* nodes.
526
514
*/
527
515
for (i = tnode_child_length (oldtnode ), m = 1u << tn -> pos ; i ;) {
528
- struct key_vector * inode = tnode_get_child (oldtnode , -- i );
516
+ struct key_vector * inode = get_child (oldtnode , -- i );
529
517
struct key_vector * node0 , * node1 ;
530
518
unsigned long j , k ;
531
519
@@ -544,8 +532,8 @@ static struct key_vector __rcu **inflate(struct trie *t,
544
532
545
533
/* An internal node with two children */
546
534
if (inode -> bits == 1 ) {
547
- put_child (tn , 2 * i + 1 , tnode_get_child (inode , 1 ));
548
- put_child (tn , 2 * i , tnode_get_child (inode , 0 ));
535
+ put_child (tn , 2 * i + 1 , get_child (inode , 1 ));
536
+ put_child (tn , 2 * i , get_child (inode , 0 ));
549
537
continue ;
550
538
}
551
539
@@ -575,10 +563,10 @@ static struct key_vector __rcu **inflate(struct trie *t,
575
563
576
564
/* populate child pointers in new nodes */
577
565
for (k = tnode_child_length (inode ), j = k / 2 ; j ;) {
578
- put_child (node1 , -- j , tnode_get_child (inode , -- k ));
579
- put_child (node0 , j , tnode_get_child (inode , j ));
580
- put_child (node1 , -- j , tnode_get_child (inode , -- k ));
581
- put_child (node0 , j , tnode_get_child (inode , j ));
566
+ put_child (node1 , -- j , get_child (inode , -- k ));
567
+ put_child (node0 , j , get_child (inode , j ));
568
+ put_child (node1 , -- j , get_child (inode , -- k ));
569
+ put_child (node0 , j , get_child (inode , j ));
582
570
}
583
571
584
572
/* link new nodes to parent */
@@ -620,8 +608,8 @@ static struct key_vector __rcu **halve(struct trie *t,
620
608
* nodes.
621
609
*/
622
610
for (i = tnode_child_length (oldtnode ); i ;) {
623
- struct key_vector * node1 = tnode_get_child (oldtnode , -- i );
624
- struct key_vector * node0 = tnode_get_child (oldtnode , -- i );
611
+ struct key_vector * node1 = get_child (oldtnode , -- i );
612
+ struct key_vector * node0 = get_child (oldtnode , -- i );
625
613
struct key_vector * inode ;
626
614
627
615
/* At least one of the children is empty */
@@ -661,7 +649,7 @@ static void collapse(struct trie *t, struct key_vector *oldtnode)
661
649
662
650
/* scan the tnode looking for that one child that might still exist */
663
651
for (n = NULL , i = tnode_child_length (oldtnode ); !n && i ;)
664
- n = tnode_get_child (oldtnode , -- i );
652
+ n = get_child (oldtnode , -- i );
665
653
666
654
/* compress one level */
667
655
tp = node_parent (oldtnode );
@@ -683,7 +671,7 @@ static unsigned char update_suffix(struct key_vector *tn)
683
671
* represent the nodes with suffix length equal to tn->pos
684
672
*/
685
673
for (i = 0 , stride = 0x2ul ; i < tnode_child_length (tn ); i += stride ) {
686
- struct key_vector * n = tnode_get_child (tn , i );
674
+ struct key_vector * n = get_child (tn , i );
687
675
688
676
if (!n || (n -> slen <= slen ))
689
677
continue ;
@@ -942,7 +930,7 @@ static struct key_vector *fib_find_node(struct trie *t,
942
930
break ;
943
931
944
932
pn = n ;
945
- n = tnode_get_child_rcu (n , index );
933
+ n = get_child_rcu (n , index );
946
934
}
947
935
948
936
* tp = pn ;
@@ -1000,7 +988,7 @@ static int fib_insert_node(struct trie *t, struct key_vector *tp,
1000
988
1001
989
/* retrieve child from parent node */
1002
990
if (tp )
1003
- n = tnode_get_child (tp , get_index (key , tp ));
991
+ n = get_child (tp , get_index (key , tp ));
1004
992
else
1005
993
n = rcu_dereference_rtnl (t -> tnode [0 ]);
1006
994
@@ -1309,7 +1297,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
1309
1297
cindex = index ;
1310
1298
}
1311
1299
1312
- n = tnode_get_child_rcu (n , index );
1300
+ n = get_child_rcu (n , index );
1313
1301
if (unlikely (!n ))
1314
1302
goto backtrace ;
1315
1303
}
@@ -1551,7 +1539,7 @@ static struct key_vector *leaf_walk_rcu(struct key_vector **tn, t_key key)
1551
1539
cindex = idx ;
1552
1540
1553
1541
/* descend into the next child */
1554
- n = tnode_get_child_rcu (pn , cindex ++ );
1542
+ n = get_child_rcu (pn , cindex ++ );
1555
1543
}
1556
1544
1557
1545
/* this loop will search for the next leaf with a greater key */
@@ -1569,7 +1557,7 @@ static struct key_vector *leaf_walk_rcu(struct key_vector **tn, t_key key)
1569
1557
}
1570
1558
1571
1559
/* grab the next available node */
1572
- n = tnode_get_child_rcu (pn , cindex ++ );
1560
+ n = get_child_rcu (pn , cindex ++ );
1573
1561
if (!n )
1574
1562
continue ;
1575
1563
@@ -1624,7 +1612,7 @@ void fib_table_flush_external(struct fib_table *tb)
1624
1612
}
1625
1613
1626
1614
/* grab the next available node */
1627
- n = tnode_get_child (pn , cindex );
1615
+ n = get_child (pn , cindex );
1628
1616
} while (!n );
1629
1617
}
1630
1618
@@ -1690,7 +1678,7 @@ int fib_table_flush(struct fib_table *tb)
1690
1678
}
1691
1679
1692
1680
/* grab the next available node */
1693
- n = tnode_get_child (pn , cindex );
1681
+ n = get_child (pn , cindex );
1694
1682
} while (!n );
1695
1683
}
1696
1684
@@ -1887,7 +1875,7 @@ static struct key_vector *fib_trie_get_next(struct fib_trie_iter *iter)
1887
1875
iter -> tnode , iter -> index , iter -> depth );
1888
1876
rescan :
1889
1877
while (cindex < tnode_child_length (tn )) {
1890
- struct key_vector * n = tnode_get_child_rcu (tn , cindex );
1878
+ struct key_vector * n = get_child_rcu (tn , cindex );
1891
1879
1892
1880
if (n ) {
1893
1881
if (IS_LEAF (n )) {
0 commit comments