Skip to content

Commit 06ef921

Browse files
Robert Olssondavem330
authored andcommitted
[IPV4]: fib_trie stats fix
fib_triestats has been buggy and caused oopses some platforms as openwrt. The patch below should cure those problems. Signed-off-by: Robert Olsson <robert.olsson@its.uu.se> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5ddf0eb commit 06ef921

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎net/ipv4/fib_trie.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* Patrick McHardy <kaber@trash.net>
5151
*/
5252

53-
#define VERSION "0.405"
53+
#define VERSION "0.406"
5454

5555
#include <linux/config.h>
5656
#include <asm/uaccess.h>
@@ -84,7 +84,7 @@
8484
#include "fib_lookup.h"
8585

8686
#undef CONFIG_IP_FIB_TRIE_STATS
87-
#define MAX_CHILDS 16384
87+
#define MAX_STAT_DEPTH 32
8888

8989
#define KEYLENGTH (8*sizeof(t_key))
9090
#define MASK_PFX(k, l) (((l)==0)?0:(k >> (KEYLENGTH-l)) << (KEYLENGTH-l))
@@ -154,7 +154,7 @@ struct trie_stat {
154154
unsigned int tnodes;
155155
unsigned int leaves;
156156
unsigned int nullpointers;
157-
unsigned int nodesizes[MAX_CHILDS];
157+
unsigned int nodesizes[MAX_STAT_DEPTH];
158158
};
159159

160160
struct trie {
@@ -2080,7 +2080,9 @@ static void trie_collect_stats(struct trie *t, struct trie_stat *s)
20802080
int i;
20812081

20822082
s->tnodes++;
2083-
s->nodesizes[tn->bits]++;
2083+
if(tn->bits < MAX_STAT_DEPTH)
2084+
s->nodesizes[tn->bits]++;
2085+
20842086
for (i = 0; i < (1<<tn->bits); i++)
20852087
if (!tn->child[i])
20862088
s->nullpointers++;
@@ -2110,8 +2112,8 @@ static void trie_show_stats(struct seq_file *seq, struct trie_stat *stat)
21102112
seq_printf(seq, "\tInternal nodes: %d\n\t", stat->tnodes);
21112113
bytes += sizeof(struct tnode) * stat->tnodes;
21122114

2113-
max = MAX_CHILDS-1;
2114-
while (max >= 0 && stat->nodesizes[max] == 0)
2115+
max = MAX_STAT_DEPTH;
2116+
while (max > 0 && stat->nodesizes[max-1] == 0)
21152117
max--;
21162118

21172119
pointers = 0;

0 commit comments

Comments
 (0)