1
From 79ddbf202a06e6f018e087a328c2ca91e65a8463 Mon Sep 17 00:00:00 2001
2
From: Tim Gardner <tim.gardner@canonical.com>
3
Date: Wed, 30 Nov 2011 08:16:53 -0700
4
Subject: [PATCH] libxt_recent: Add support for --reap option
6
Support for the reap option was merged in the kernel as of 2.6.35.
8
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
9
Cc: Jan Engelhardt <jengelh@medozas.de>
10
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
12
extensions/libxt_recent.c | 17 ++++++++++++++++-
13
extensions/libxt_recent.man | 5 +++++
14
2 files changed, 21 insertions(+), 1 deletions(-)
16
diff --git a/extensions/libxt_recent.c b/extensions/libxt_recent.c
17
index 1e1a111..c7dce4e 100644
18
--- a/extensions/libxt_recent.c
19
+++ b/extensions/libxt_recent.c
20
@@ -10,6 +10,7 @@ enum {
28
@@ -19,6 +20,7 @@ enum {
29
F_RCHECK = 1 << O_RCHECK,
30
F_UPDATE = 1 << O_UPDATE,
31
F_REMOVE = 1 << O_REMOVE,
32
+ F_SECONDS = 1 << O_SECONDS,
33
F_ANY_OP = F_SET | F_RCHECK | F_UPDATE | F_REMOVE,
36
@@ -33,7 +35,9 @@ static const struct xt_option_entry recent_opts[] = {
37
{.name = "remove", .id = O_REMOVE, .type = XTTYPE_NONE,
38
.excl = F_ANY_OP, .flags = XTOPT_INVERT},
39
{.name = "seconds", .id = O_SECONDS, .type = XTTYPE_UINT32,
40
- .flags = XTOPT_PUT, XTOPT_POINTER(s, seconds)},
41
+ .flags = XTOPT_PUT, XTOPT_POINTER(s, seconds), .min = 1},
42
+ {.name = "reap", .id = O_REAP, .type = XTTYPE_NONE,
43
+ .also = F_SECONDS },
44
{.name = "hitcount", .id = O_HITCOUNT, .type = XTTYPE_UINT32,
45
.flags = XTOPT_PUT, XTOPT_POINTER(s, hit_count)},
46
{.name = "rttl", .id = O_RTTL, .type = XTTYPE_NONE,
47
@@ -57,6 +61,8 @@ static void recent_help(void)
48
" --seconds seconds For check and update commands above.\n"
49
" Specifies that the match will only occur if source address last seen within\n"
50
" the last 'seconds' seconds.\n"
51
+" --reap Purge entries older then 'seconds'.\n"
52
+" Can only be used in conjunction with the seconds option.\n"
53
" --hitcount hits For check and update commands above.\n"
54
" Specifies that the match will only occur if source address seen hits times.\n"
55
" May be used in conjunction with the seconds option.\n"
56
@@ -117,11 +123,16 @@ static void recent_parse(struct xt_option_call *cb)
58
info->side = XT_RECENT_DEST;
61
+ info->check_set |= XT_RECENT_REAP;
66
static void recent_check(struct xt_fcheck_call *cb)
68
+ struct xt_recent_mtinfo *info = cb->data;
70
if (!(cb->xflags & F_ANY_OP))
71
xtables_error(PARAMETER_PROBLEM,
72
"recent: you must specify one of `--set', `--rcheck' "
73
@@ -146,6 +157,8 @@ static void recent_print(const void *ip, const struct xt_entry_match *match,
74
if (info->check_set & XT_RECENT_REMOVE)
76
if(info->seconds) printf(" seconds: %d", info->seconds);
77
+ if (info->check_set & XT_RECENT_REAP)
79
if(info->hit_count) printf(" hit_count: %d", info->hit_count);
80
if (info->check_set & XT_RECENT_TTL)
82
@@ -172,6 +185,8 @@ static void recent_save(const void *ip, const struct xt_entry_match *match)
83
if (info->check_set & XT_RECENT_REMOVE)
85
if(info->seconds) printf(" --seconds %d", info->seconds);
86
+ if (info->check_set & XT_RECENT_REAP)
88
if(info->hit_count) printf(" --hitcount %d", info->hit_count);
89
if (info->check_set & XT_RECENT_TTL)
91
diff --git a/extensions/libxt_recent.man b/extensions/libxt_recent.man
92
index 0392c2c..8043df4 100644
93
--- a/extensions/libxt_recent.man
94
+++ b/extensions/libxt_recent.man
95
@@ -41,6 +41,11 @@ This option must be used in conjunction with one of \fB\-\-rcheck\fP or
96
\fB\-\-update\fP. When used, this will narrow the match to only happen when the
97
address is in the list and was seen within the last given number of seconds.
100
+This option can only be used in conjunction with \fB\-\-seconds\fP.
101
+When used, this will cause entries older than the last given number of seconds
104
\fB\-\-hitcount\fP \fIhits\fP
105
This option must be used in conjunction with one of \fB\-\-rcheck\fP or
106
\fB\-\-update\fP. When used, this will narrow the match to only happen when the