[INET]: Consolidate xxx_the secret_rebuild

This code works with the generic data types as well, so
move this into inet_fragment.c

This move makes it possible to hide the secret_timer
management and the secret_rebuild routine completely in
the inet_fragment.c

Introduce the ->hashfn() callback in inet_frags() to get
the hashfun for a given inet_frag_queue() object.

Signed-off-by: Pavel Emelyanov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
This commit is contained in:
Pavel Emelyanov 2007-10-15 02:38:08 -07:00 • committed by David S. Miller
commit 321a3a99e4
5 changed files with 52 additions and 90 deletions

View file

@ -16,9 +16,38 @@
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/mm.h>
#include <linux/random.h>
#include <net/inet_frag.h>
static void inet_frag_secret_rebuild(unsigned long dummy)
{
struct inet_frags *f = (struct inet_frags *)dummy;
unsigned long now = jiffies;
int i;
write_lock(&f->lock);
get_random_bytes(&f->rnd, sizeof(u32));
for (i = 0; i < INETFRAGS_HASHSZ; i++) {
struct inet_frag_queue *q;
struct hlist_node *p, *n;
hlist_for_each_entry_safe(q, p, n, &f->hash[i], list) {
unsigned int hval = f->hashfn(q);
if (hval != i) {
hlist_del(&q->list);
/* Relink to new hash chain. */
hlist_add_head(&q->list, &f->hash[hval]);
}
}
}
write_unlock(&f->lock);
mod_timer(&f->secret_timer, now + f->ctl->secret_interval);
}
void inet_frags_init(struct inet_frags *f)
{
int i;
@ -35,11 +64,17 @@ void inet_frags_init(struct inet_frags *f)
f->nqueues = 0;
atomic_set(&f->mem, 0);
init_timer(&f->secret_timer);
f->secret_timer.function = inet_frag_secret_rebuild;
f->secret_timer.data = (unsigned long)f;
f->secret_timer.expires = jiffies + f->ctl->secret_interval;
add_timer(&f->secret_timer);
}
EXPORT_SYMBOL(inet_frags_init);
void inet_frags_fini(struct inet_frags *f)
{
del_timer(&f->secret_timer);
}
EXPORT_SYMBOL(inet_frags_fini);

View file

@ -115,32 +115,12 @@ static unsigned int ipqhashfn(__be16 id, __be32 saddr, __be32 daddr, u8 prot)
ip4_frags.rnd) & (INETFRAGS_HASHSZ - 1);
}
static void ipfrag_secret_rebuild(unsigned long dummy)
static unsigned int ip4_hashfn(struct inet_frag_queue *q)
{
unsigned long now = jiffies;
int i;
struct ipq *ipq;
write_lock(&ip4_frags.lock);
get_random_bytes(&ip4_frags.rnd, sizeof(u32));
for (i = 0; i < INETFRAGS_HASHSZ; i++) {
struct ipq *q;
struct hlist_node *p, *n;
hlist_for_each_entry_safe(q, p, n, &ip4_frags.hash[i], q.list) {
unsigned int hval = ipqhashfn(q->id, q->saddr,
q->daddr, q->protocol);
if (hval != i) {
hlist_del(&q->q.list);
/* Relink to new hash chain. */
hlist_add_head(&q->q.list, &ip4_frags.hash[hval]);
}
}
}
write_unlock(&ip4_frags.lock);
mod_timer(&ip4_frags.secret_timer, now + ip4_frags_ctl.secret_interval);
ipq = container_of(q, struct ipq, q);
return ipqhashfn(ipq->id, ipq->saddr, ipq->daddr, ipq->protocol);
}
/* Memory Tracking Functions. */
@ -739,12 +719,8 @@ int ip_defrag(struct sk_buff *skb, u32 user)
void __init ipfrag_init(void)
{
init_timer(&ip4_frags.secret_timer);
ip4_frags.secret_timer.function = ipfrag_secret_rebuild;
ip4_frags.secret_timer.expires = jiffies + ip4_frags_ctl.secret_interval;
add_timer(&ip4_frags.secret_timer);
ip4_frags.ctl = &ip4_frags_ctl;
ip4_frags.hashfn = ip4_hashfn;
inet_frags_init(&ip4_frags);
}