diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/fib_trie.c | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 2a6fdc2708c6..f0cdb30921c0 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c | |||
@@ -159,7 +159,6 @@ struct trie { | |||
159 | #endif | 159 | #endif |
160 | }; | 160 | }; |
161 | 161 | ||
162 | static void put_child(struct trie *t, struct tnode *tn, int i, struct rt_trie_node *n); | ||
163 | static void tnode_put_child_reorg(struct tnode *tn, int i, struct rt_trie_node *n, | 162 | static void tnode_put_child_reorg(struct tnode *tn, int i, struct rt_trie_node *n, |
164 | int wasfull); | 163 | int wasfull); |
165 | static struct rt_trie_node *resize(struct trie *t, struct tnode *tn); | 164 | static struct rt_trie_node *resize(struct trie *t, struct tnode *tn); |
@@ -490,7 +489,7 @@ static inline int tnode_full(const struct tnode *tn, const struct rt_trie_node * | |||
490 | return ((struct tnode *) n)->pos == tn->pos + tn->bits; | 489 | return ((struct tnode *) n)->pos == tn->pos + tn->bits; |
491 | } | 490 | } |
492 | 491 | ||
493 | static inline void put_child(struct trie *t, struct tnode *tn, int i, | 492 | static inline void put_child(struct tnode *tn, int i, |
494 | struct rt_trie_node *n) | 493 | struct rt_trie_node *n) |
495 | { | 494 | { |
496 | tnode_put_child_reorg(tn, i, n, -1); | 495 | tnode_put_child_reorg(tn, i, n, -1); |
@@ -754,8 +753,8 @@ static struct tnode *inflate(struct trie *t, struct tnode *tn) | |||
754 | goto nomem; | 753 | goto nomem; |
755 | } | 754 | } |
756 | 755 | ||
757 | put_child(t, tn, 2*i, (struct rt_trie_node *) left); | 756 | put_child(tn, 2*i, (struct rt_trie_node *) left); |
758 | put_child(t, tn, 2*i+1, (struct rt_trie_node *) right); | 757 | put_child(tn, 2*i+1, (struct rt_trie_node *) right); |
759 | } | 758 | } |
760 | } | 759 | } |
761 | 760 | ||
@@ -776,9 +775,9 @@ static struct tnode *inflate(struct trie *t, struct tnode *tn) | |||
776 | if (tkey_extract_bits(node->key, | 775 | if (tkey_extract_bits(node->key, |
777 | oldtnode->pos + oldtnode->bits, | 776 | oldtnode->pos + oldtnode->bits, |
778 | 1) == 0) | 777 | 1) == 0) |
779 | put_child(t, tn, 2*i, node); | 778 | put_child(tn, 2*i, node); |
780 | else | 779 | else |
781 | put_child(t, tn, 2*i+1, node); | 780 | put_child(tn, 2*i+1, node); |
782 | continue; | 781 | continue; |
783 | } | 782 | } |
784 | 783 | ||
@@ -786,8 +785,8 @@ static struct tnode *inflate(struct trie *t, struct tnode *tn) | |||
786 | inode = (struct tnode *) node; | 785 | inode = (struct tnode *) node; |
787 | 786 | ||
788 | if (inode->bits == 1) { | 787 | if (inode->bits == 1) { |
789 | put_child(t, tn, 2*i, rtnl_dereference(inode->child[0])); | 788 | put_child(tn, 2*i, rtnl_dereference(inode->child[0])); |
790 | put_child(t, tn, 2*i+1, rtnl_dereference(inode->child[1])); | 789 | put_child(tn, 2*i+1, rtnl_dereference(inode->child[1])); |
791 | 790 | ||
792 | tnode_free_safe(inode); | 791 | tnode_free_safe(inode); |
793 | continue; | 792 | continue; |
@@ -817,22 +816,22 @@ static struct tnode *inflate(struct trie *t, struct tnode *tn) | |||
817 | */ | 816 | */ |
818 | 817 | ||
819 | left = (struct tnode *) tnode_get_child(tn, 2*i); | 818 | left = (struct tnode *) tnode_get_child(tn, 2*i); |
820 | put_child(t, tn, 2*i, NULL); | 819 | put_child(tn, 2*i, NULL); |
821 | 820 | ||
822 | BUG_ON(!left); | 821 | BUG_ON(!left); |
823 | 822 | ||
824 | right = (struct tnode *) tnode_get_child(tn, 2*i+1); | 823 | right = (struct tnode *) tnode_get_child(tn, 2*i+1); |
825 | put_child(t, tn, 2*i+1, NULL); | 824 | put_child(tn, 2*i+1, NULL); |
826 | 825 | ||
827 | BUG_ON(!right); | 826 | BUG_ON(!right); |
828 | 827 | ||
829 | size = tnode_child_length(left); | 828 | size = tnode_child_length(left); |
830 | for (j = 0; j < size; j++) { | 829 | for (j = 0; j < size; j++) { |
831 | put_child(t, left, j, rtnl_dereference(inode->child[j])); | 830 | put_child(left, j, rtnl_dereference(inode->child[j])); |
832 | put_child(t, right, j, rtnl_dereference(inode->child[j + size])); | 831 | put_child(right, j, rtnl_dereference(inode->child[j + size])); |
833 | } | 832 | } |
834 | put_child(t, tn, 2*i, resize(t, left)); | 833 | put_child(tn, 2*i, resize(t, left)); |
835 | put_child(t, tn, 2*i+1, resize(t, right)); | 834 | put_child(tn, 2*i+1, resize(t, right)); |
836 | 835 | ||
837 | tnode_free_safe(inode); | 836 | tnode_free_safe(inode); |
838 | } | 837 | } |
@@ -877,7 +876,7 @@ static struct tnode *halve(struct trie *t, struct tnode *tn) | |||
877 | if (!newn) | 876 | if (!newn) |
878 | goto nomem; | 877 | goto nomem; |
879 | 878 | ||
880 | put_child(t, tn, i/2, (struct rt_trie_node *)newn); | 879 | put_child(tn, i/2, (struct rt_trie_node *)newn); |
881 | } | 880 | } |
882 | 881 | ||
883 | } | 882 | } |
@@ -892,21 +891,21 @@ static struct tnode *halve(struct trie *t, struct tnode *tn) | |||
892 | if (left == NULL) { | 891 | if (left == NULL) { |
893 | if (right == NULL) /* Both are empty */ | 892 | if (right == NULL) /* Both are empty */ |
894 | continue; | 893 | continue; |
895 | put_child(t, tn, i/2, right); | 894 | put_child(tn, i/2, right); |
896 | continue; | 895 | continue; |
897 | } | 896 | } |
898 | 897 | ||
899 | if (right == NULL) { | 898 | if (right == NULL) { |
900 | put_child(t, tn, i/2, left); | 899 | put_child(tn, i/2, left); |
901 | continue; | 900 | continue; |
902 | } | 901 | } |
903 | 902 | ||
904 | /* Two nonempty children */ | 903 | /* Two nonempty children */ |
905 | newBinNode = (struct tnode *) tnode_get_child(tn, i/2); | 904 | newBinNode = (struct tnode *) tnode_get_child(tn, i/2); |
906 | put_child(t, tn, i/2, NULL); | 905 | put_child(tn, i/2, NULL); |
907 | put_child(t, newBinNode, 0, left); | 906 | put_child(newBinNode, 0, left); |
908 | put_child(t, newBinNode, 1, right); | 907 | put_child(newBinNode, 1, right); |
909 | put_child(t, tn, i/2, resize(t, newBinNode)); | 908 | put_child(tn, i/2, resize(t, newBinNode)); |
910 | } | 909 | } |
911 | tnode_free_safe(oldtnode); | 910 | tnode_free_safe(oldtnode); |
912 | return tn; | 911 | return tn; |
@@ -1125,7 +1124,7 @@ static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen) | |||
1125 | node_set_parent((struct rt_trie_node *)l, tp); | 1124 | node_set_parent((struct rt_trie_node *)l, tp); |
1126 | 1125 | ||
1127 | cindex = tkey_extract_bits(key, tp->pos, tp->bits); | 1126 | cindex = tkey_extract_bits(key, tp->pos, tp->bits); |
1128 | put_child(t, tp, cindex, (struct rt_trie_node *)l); | 1127 | put_child(tp, cindex, (struct rt_trie_node *)l); |
1129 | } else { | 1128 | } else { |
1130 | /* Case 3: n is a LEAF or a TNODE and the key doesn't match. */ | 1129 | /* Case 3: n is a LEAF or a TNODE and the key doesn't match. */ |
1131 | /* | 1130 | /* |
@@ -1155,12 +1154,12 @@ static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen) | |||
1155 | node_set_parent((struct rt_trie_node *)tn, tp); | 1154 | node_set_parent((struct rt_trie_node *)tn, tp); |
1156 | 1155 | ||
1157 | missbit = tkey_extract_bits(key, newpos, 1); | 1156 | missbit = tkey_extract_bits(key, newpos, 1); |
1158 | put_child(t, tn, missbit, (struct rt_trie_node *)l); | 1157 | put_child(tn, missbit, (struct rt_trie_node *)l); |
1159 | put_child(t, tn, 1-missbit, n); | 1158 | put_child(tn, 1-missbit, n); |
1160 | 1159 | ||
1161 | if (tp) { | 1160 | if (tp) { |
1162 | cindex = tkey_extract_bits(key, tp->pos, tp->bits); | 1161 | cindex = tkey_extract_bits(key, tp->pos, tp->bits); |
1163 | put_child(t, tp, cindex, (struct rt_trie_node *)tn); | 1162 | put_child(tp, cindex, (struct rt_trie_node *)tn); |
1164 | } else { | 1163 | } else { |
1165 | rcu_assign_pointer(t->trie, (struct rt_trie_node *)tn); | 1164 | rcu_assign_pointer(t->trie, (struct rt_trie_node *)tn); |
1166 | tp = tn; | 1165 | tp = tn; |
@@ -1619,7 +1618,7 @@ static void trie_leaf_remove(struct trie *t, struct leaf *l) | |||
1619 | 1618 | ||
1620 | if (tp) { | 1619 | if (tp) { |
1621 | t_key cindex = tkey_extract_bits(l->key, tp->pos, tp->bits); | 1620 | t_key cindex = tkey_extract_bits(l->key, tp->pos, tp->bits); |
1622 | put_child(t, tp, cindex, NULL); | 1621 | put_child(tp, cindex, NULL); |
1623 | trie_rebalance(t, tp); | 1622 | trie_rebalance(t, tp); |
1624 | } else | 1623 | } else |
1625 | RCU_INIT_POINTER(t->trie, NULL); | 1624 | RCU_INIT_POINTER(t->trie, NULL); |