linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / net / ipv4 / fib_trie.c
index 01801c0..24009be 100644 (file)
@@ -50,8 +50,9 @@
  *             Patrick McHardy <kaber@trash.net>
  */
 
-#define VERSION "0.407"
+#define VERSION "0.404"
 
+#include <linux/config.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #include <asm/bitops.h>
@@ -83,7 +84,7 @@
 #include "fib_lookup.h"
 
 #undef CONFIG_IP_FIB_TRIE_STATS
-#define MAX_STAT_DEPTH 32
+#define MAX_CHILDS 16384
 
 #define KEYLENGTH (8*sizeof(t_key))
 #define MASK_PFX(k, l) (((l)==0)?0:(k >> (KEYLENGTH-l)) << (KEYLENGTH-l))
@@ -153,7 +154,7 @@ struct trie_stat {
        unsigned int tnodes;
        unsigned int leaves;
        unsigned int nullpointers;
-       unsigned int nodesizes[MAX_STAT_DEPTH];
+       unsigned int nodesizes[MAX_CHILDS];
 };
 
 struct trie {
@@ -1252,8 +1253,8 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
         */
 
        if (!fa_head) {
-               err = 0;
                fa_head = fib_insert_node(t, &err, key, plen);
+               err = 0;
                if (err)
                        goto out_free_new_fa;
        }
@@ -1281,18 +1282,18 @@ static inline int check_leaf(struct trie *t, struct leaf *l,
                             struct fib_result *res)
 {
        int err, i;
-       __be32 mask;
+       t_key mask;
        struct leaf_info *li;
        struct hlist_head *hhead = &l->list;
        struct hlist_node *node;
 
        hlist_for_each_entry_rcu(li, node, hhead, hlist) {
                i = li->plen;
-               mask = inet_make_mask(i);
-               if (l->key != (key & ntohl(mask)))
+               mask = ntohl(inet_make_mask(i));
+               if (l->key != (key & mask))
                        continue;
 
-               if ((err = fib_semantic_match(&li->falh, flp, res, htonl(l->key), mask, i)) <= 0) {
+               if ((err = fib_semantic_match(&li->falh, flp, res, l->key, mask, i)) <= 0) {
                        *plen = i;
 #ifdef CONFIG_IP_FIB_TRIE_STATS
                        t->stats.semantic_match_passed++;
@@ -2039,15 +2040,7 @@ rescan:
 static struct node *fib_trie_get_first(struct fib_trie_iter *iter,
                                       struct trie *t)
 {
-       struct node *n ;
-
-       if(!t)
-               return NULL;
-
-       n = rcu_dereference(t->trie);
-
-       if(!iter)
-               return NULL;
+       struct node *n = rcu_dereference(t->trie);
 
        if (n && IS_TNODE(n)) {
                iter->tnode = (struct tnode *) n;
@@ -2079,9 +2072,7 @@ static void trie_collect_stats(struct trie *t, struct trie_stat *s)
                        int i;
 
                        s->tnodes++;
-                       if(tn->bits < MAX_STAT_DEPTH)
-                               s->nodesizes[tn->bits]++;
-
+                       s->nodesizes[tn->bits]++;
                        for (i = 0; i < (1<<tn->bits); i++)
                                if (!tn->child[i])
                                        s->nullpointers++;
@@ -2111,8 +2102,8 @@ static void trie_show_stats(struct seq_file *seq, struct trie_stat *stat)
        seq_printf(seq, "\tInternal nodes: %d\n\t", stat->tnodes);
        bytes += sizeof(struct tnode) * stat->tnodes;
 
-       max = MAX_STAT_DEPTH;
-       while (max > 0 && stat->nodesizes[max-1] == 0)
+       max = MAX_CHILDS-1;
+       while (max >= 0 && stat->nodesizes[max] == 0)
                max--;
 
        pointers = 0;