diff options
author | Patrick McHardy <kaber@trash.net> | 2006-06-09 15:18:47 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-06-18 00:30:11 -0400 |
commit | bf0857ea32addb6bc8b46383604b218b8ec09f19 (patch) | |
tree | 84b92a237f4f5e538f401dcbcc2725c75cc06955 | |
parent | 2b2283d0302d520f08ded41c2ca17886dfbb865a (diff) |
[NETFILTER]: hashlimit match: fix random initialization
hashlimit does:
if (!ht->rnd)
get_random_bytes(&ht->rnd, 4);
ignoring that 0 is also a valid random number.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/ipv4/netfilter/ipt_hashlimit.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/net/ipv4/netfilter/ipt_hashlimit.c b/net/ipv4/netfilter/ipt_hashlimit.c index 85edfb79469a..92980ab8ce48 100644 --- a/net/ipv4/netfilter/ipt_hashlimit.c +++ b/net/ipv4/netfilter/ipt_hashlimit.c | |||
@@ -80,6 +80,7 @@ struct ipt_hashlimit_htable { | |||
80 | /* used internally */ | 80 | /* used internally */ |
81 | spinlock_t lock; /* lock for list_head */ | 81 | spinlock_t lock; /* lock for list_head */ |
82 | u_int32_t rnd; /* random seed for hash */ | 82 | u_int32_t rnd; /* random seed for hash */ |
83 | int rnd_initialized; | ||
83 | struct timer_list timer; /* timer for gc */ | 84 | struct timer_list timer; /* timer for gc */ |
84 | atomic_t count; /* number entries in table */ | 85 | atomic_t count; /* number entries in table */ |
85 | 86 | ||
@@ -134,8 +135,10 @@ __dsthash_alloc_init(struct ipt_hashlimit_htable *ht, struct dsthash_dst *dst) | |||
134 | 135 | ||
135 | /* initialize hash with random val at the time we allocate | 136 | /* initialize hash with random val at the time we allocate |
136 | * the first hashtable entry */ | 137 | * the first hashtable entry */ |
137 | if (!ht->rnd) | 138 | if (!ht->rnd_initialized) { |
138 | get_random_bytes(&ht->rnd, 4); | 139 | get_random_bytes(&ht->rnd, 4); |
140 | ht->rnd_initialized = 1; | ||
141 | } | ||
139 | 142 | ||
140 | if (ht->cfg.max && | 143 | if (ht->cfg.max && |
141 | atomic_read(&ht->count) >= ht->cfg.max) { | 144 | atomic_read(&ht->count) >= ht->cfg.max) { |
@@ -214,7 +217,7 @@ static int htable_create(struct ipt_hashlimit_info *minfo) | |||
214 | 217 | ||
215 | atomic_set(&hinfo->count, 0); | 218 | atomic_set(&hinfo->count, 0); |
216 | atomic_set(&hinfo->use, 1); | 219 | atomic_set(&hinfo->use, 1); |
217 | hinfo->rnd = 0; | 220 | hinfo->rnd_initialized = 0; |
218 | spin_lock_init(&hinfo->lock); | 221 | spin_lock_init(&hinfo->lock); |
219 | hinfo->pde = create_proc_entry(minfo->name, 0, hashlimit_procdir); | 222 | hinfo->pde = create_proc_entry(minfo->name, 0, hashlimit_procdir); |
220 | if (!hinfo->pde) { | 223 | if (!hinfo->pde) { |