From: timg@tpi.com (Tim Gardner)
To: kaber@trash.net
Cc: coreteam@netfilter.org, netfilter-devel@vger.kernel.org,
netfilter@vger.kernel.org
Subject: linux-next netfilter: xt_recent: Add an entry reaper
Date: Sat, 27 Feb 2010 20:38:41 -0700 (MST) [thread overview]
Message-ID: <20100228033841.265CFF8BB0@sepang.rtg.net> (raw)
From 03b1a0171cd3b7eb680ec738ddcc21c59688f6fe Mon Sep 17 00:00:00 2001
From: Tim Gardner <tim.gardner@canonical.com>
Date: Sat, 27 Feb 2010 20:22:07 -0700
Subject: [PATCH] netfilter: xt_recent: Add an entry reaper
One of the problems with the way xt_recent is implemented is that
there is no efficient way to remove expired entries. Of course,
one can write a rule '-m recent --remove', but you have to know
beforehand which entry to delete. This commit adds reaper
logic which checks one entry on the LRU list each time a rule
is invoked that has a '--seconds' value. If an entry ceases
to accumulate time stamps, then eventually the reaper will
encounter it in the LRU list and remove it.
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---
net/netfilter/xt_recent.c | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index 7073dbb..5747440 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -76,6 +76,7 @@ struct recent_table {
unsigned int refcnt;
unsigned int entries;
struct list_head lru_list;
+ struct list_head *reaper; /* points to the lru_list */
struct list_head iphash[0];
};
@@ -140,12 +141,41 @@ recent_entry_lookup(const struct recent_table *table,
static void recent_entry_remove(struct recent_table *t, struct recent_entry *e)
{
+ /*
+ * Advance the reaper if its about to be deleted.
+ */
+ if (list_entry(t->reaper, struct recent_entry, lru_list) == e)
+ t->reaper = t->reaper->next;
+
list_del(&e->list);
list_del(&e->lru_list);
kfree(e);
t->entries--;
}
+/*
+ * Drop entries with timestamps older then 'time'.
+ */
+static void recent_entry_reap(struct recent_table *t, unsigned long time)
+{
+ struct recent_entry *e;
+
+ /*
+ * Don't reap the list head.
+ */
+ t->reaper = t->reaper->next;
+ if (t->reaper == (&t->lru_list))
+ return;
+
+ e = list_entry(t->reaper, struct recent_entry, lru_list);
+
+ /*
+ * The last time stamp is the most recent.
+ */
+ if (time_after(time, e->stamps[e->index-1]))
+ recent_entry_remove(t, e);
+}
+
static struct recent_entry *
recent_entry_init(struct recent_table *t, const union nf_inet_addr *addr,
u_int16_t family, u_int8_t ttl)
@@ -272,6 +302,8 @@ recent_mt(const struct sk_buff *skb, const struct xt_match_param *par)
break;
}
}
+
+ recent_entry_reap(t, time);
}
if (info->check_set & XT_RECENT_SET ||
@@ -331,6 +363,7 @@ static bool recent_mt_check(const struct xt_mtchk_param *par)
t->refcnt = 1;
strcpy(t->name, info->name);
INIT_LIST_HEAD(&t->lru_list);
+ t->reaper = t->lru_list.next;
for (i = 0; i < ip_list_hash_size; i++)
INIT_LIST_HEAD(&t->iphash[i]);
#ifdef CONFIG_PROC_FS
--
1.7.0
next reply other threads:[~2010-02-28 3:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-28 3:38 Tim Gardner [this message]
2010-02-28 4:34 ` linux-next netfilter: xt_recent: Add an entry reaper Eric Dumazet
2010-02-28 10:50 ` Jan Engelhardt
2010-02-28 20:26 ` Eric Dumazet
2010-02-28 22:42 ` Tim Gardner
2010-02-28 18:23 ` Tim Gardner
2010-02-28 20:02 ` Jan Engelhardt
2010-02-28 20:20 ` Eric Dumazet
2010-02-28 23:12 ` Tim Gardner
2010-03-01 2:17 ` Eric Dumazet
2010-03-01 20:24 ` Tim Gardner
2010-03-01 20:40 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100228033841.265CFF8BB0@sepang.rtg.net \
--to=timg@tpi.com \
--cc=coreteam@netfilter.org \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=netfilter@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox