diff options
author | Stephen Hemminger <shemminger@linux-foundation.org> | 2007-08-10 18:22:58 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:48:01 -0400 |
commit | ab66b4a7a3969077f6e2a18a0d2d849d3b84a337 (patch) | |
tree | 03418252b556fa94eb0daad2d8fc2a59ad79ce78 /net/ipv4 | |
parent | 0680191642c27c81c9be4557d9c6aa3487c15f69 (diff) |
[IPV4] fib_trie: macro cleanup
This patch converts the messy macro for MASK_PFX to inline function
and expands TKEY_GET_MASK in the one place it is used.
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/fib_trie.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index f28f9f5f240c..52b2891c63b7 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c | |||
@@ -85,8 +85,6 @@ | |||
85 | #define MAX_STAT_DEPTH 32 | 85 | #define MAX_STAT_DEPTH 32 |
86 | 86 | ||
87 | #define KEYLENGTH (8*sizeof(t_key)) | 87 | #define KEYLENGTH (8*sizeof(t_key)) |
88 | #define MASK_PFX(k, l) (((l)==0)?0:(k >> (KEYLENGTH-l)) << (KEYLENGTH-l)) | ||
89 | #define TKEY_GET_MASK(offset, bits) (((bits)==0)?0:((t_key)(-1) << (KEYLENGTH - bits) >> offset)) | ||
90 | 88 | ||
91 | typedef unsigned int t_key; | 89 | typedef unsigned int t_key; |
92 | 90 | ||
@@ -195,6 +193,11 @@ static inline int tnode_child_length(const struct tnode *tn) | |||
195 | return 1 << tn->bits; | 193 | return 1 << tn->bits; |
196 | } | 194 | } |
197 | 195 | ||
196 | static inline t_key mask_pfx(t_key k, unsigned short l) | ||
197 | { | ||
198 | return (l == 0) ? 0 : k >> (KEYLENGTH-l) << (KEYLENGTH-l); | ||
199 | } | ||
200 | |||
198 | static inline t_key tkey_extract_bits(t_key a, int offset, int bits) | 201 | static inline t_key tkey_extract_bits(t_key a, int offset, int bits) |
199 | { | 202 | { |
200 | if (offset < KEYLENGTH) | 203 | if (offset < KEYLENGTH) |
@@ -679,7 +682,7 @@ static struct tnode *inflate(struct trie *t, struct tnode *tn) | |||
679 | inode->pos == oldtnode->pos + oldtnode->bits && | 682 | inode->pos == oldtnode->pos + oldtnode->bits && |
680 | inode->bits > 1) { | 683 | inode->bits > 1) { |
681 | struct tnode *left, *right; | 684 | struct tnode *left, *right; |
682 | t_key m = TKEY_GET_MASK(inode->pos, 1); | 685 | t_key m = ~0U << (KEYLENGTH - 1) >> inode->pos; |
683 | 686 | ||
684 | left = tnode_new(inode->key&(~m), inode->pos + 1, | 687 | left = tnode_new(inode->key&(~m), inode->pos + 1, |
685 | inode->bits - 1); | 688 | inode->bits - 1); |
@@ -1367,7 +1370,8 @@ fn_trie_lookup(struct fib_table *tb, const struct flowi *flp, struct fib_result | |||
1367 | bits = pn->bits; | 1370 | bits = pn->bits; |
1368 | 1371 | ||
1369 | if (!chopped_off) | 1372 | if (!chopped_off) |
1370 | cindex = tkey_extract_bits(MASK_PFX(key, current_prefix_length), pos, bits); | 1373 | cindex = tkey_extract_bits(mask_pfx(key, current_prefix_length), |
1374 | pos, bits); | ||
1371 | 1375 | ||
1372 | n = tnode_get_child(pn, cindex); | 1376 | n = tnode_get_child(pn, cindex); |
1373 | 1377 | ||
@@ -1453,8 +1457,8 @@ fn_trie_lookup(struct fib_table *tb, const struct flowi *flp, struct fib_result | |||
1453 | * to find a matching prefix. | 1457 | * to find a matching prefix. |
1454 | */ | 1458 | */ |
1455 | 1459 | ||
1456 | node_prefix = MASK_PFX(cn->key, cn->pos); | 1460 | node_prefix = mask_pfx(cn->key, cn->pos); |
1457 | key_prefix = MASK_PFX(key, cn->pos); | 1461 | key_prefix = mask_pfx(key, cn->pos); |
1458 | pref_mismatch = key_prefix^node_prefix; | 1462 | pref_mismatch = key_prefix^node_prefix; |
1459 | mp = 0; | 1463 | mp = 0; |
1460 | 1464 | ||
@@ -2330,7 +2334,7 @@ static int fib_trie_seq_show(struct seq_file *seq, void *v) | |||
2330 | 2334 | ||
2331 | if (IS_TNODE(n)) { | 2335 | if (IS_TNODE(n)) { |
2332 | struct tnode *tn = (struct tnode *) n; | 2336 | struct tnode *tn = (struct tnode *) n; |
2333 | __be32 prf = htonl(MASK_PFX(tn->key, tn->pos)); | 2337 | __be32 prf = htonl(mask_pfx(tn->key, tn->pos)); |
2334 | 2338 | ||
2335 | seq_indent(seq, iter->depth-1); | 2339 | seq_indent(seq, iter->depth-1); |
2336 | seq_printf(seq, " +-- %d.%d.%d.%d/%d %d %d %d\n", | 2340 | seq_printf(seq, " +-- %d.%d.%d.%d/%d %d %d %d\n", |