aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/feature-removal-schedule.txt3
-rw-r--r--net/netfilter/Kconfig7
-rw-r--r--net/netfilter/xt_recent.c300
3 files changed, 256 insertions, 54 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index d0f22fac55da..3d2d0c29f027 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -250,6 +250,9 @@ What (Why):
250 - xt_mark match revision 0 250 - xt_mark match revision 0
251 (superseded by xt_mark match revision 1) 251 (superseded by xt_mark match revision 1)
252 252
253 - xt_recent: the old ipt_recent proc dir
254 (superseded by /proc/net/xt_recent)
255
253When: January 2009 or Linux 2.7.0, whichever comes first 256When: January 2009 or Linux 2.7.0, whichever comes first
254Why: Superseded by newer revisions or modules 257Why: Superseded by newer revisions or modules
255Who: Jan Engelhardt <jengelh@computergmbh.de> 258Who: Jan Engelhardt <jengelh@computergmbh.de>
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index ccc78b07a1a4..4a464857f216 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -743,6 +743,13 @@ config NETFILTER_XT_MATCH_RECENT
743 Short options are available by using 'iptables -m recent -h' 743 Short options are available by using 'iptables -m recent -h'
744 Official Website: <http://snowman.net/projects/ipt_recent/> 744 Official Website: <http://snowman.net/projects/ipt_recent/>
745 745
746config NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
747 bool 'Enable obsolete /proc/net/ipt_recent'
748 depends on NETFILTER_XT_MATCH_RECENT && PROC_FS
749 ---help---
750 This option enables the old /proc/net/ipt_recent interface,
751 which has been obsoleted by /proc/net/xt_recent.
752
746config NETFILTER_XT_MATCH_SCTP 753config NETFILTER_XT_MATCH_SCTP
747 tristate '"sctp" protocol match support (EXPERIMENTAL)' 754 tristate '"sctp" protocol match support (EXPERIMENTAL)'
748 depends on NETFILTER_XTABLES && EXPERIMENTAL 755 depends on NETFILTER_XTABLES && EXPERIMENTAL
diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index 422c0e4d66b7..adc2e2f1b09c 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2006 Patrick McHardy <kaber@trash.net> 2 * Copyright (c) 2006 Patrick McHardy <kaber@trash.net>
3 * Copyright © CC Computer Consultants GmbH, 2007 - 2008
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as 6 * it under the terms of the GNU General Public License version 2 as
@@ -13,6 +14,8 @@
13 */ 14 */
14#include <linux/init.h> 15#include <linux/init.h>
15#include <linux/ip.h> 16#include <linux/ip.h>
17#include <linux/ipv6.h>
18#include <linux/module.h>
16#include <linux/moduleparam.h> 19#include <linux/moduleparam.h>
17#include <linux/proc_fs.h> 20#include <linux/proc_fs.h>
18#include <linux/seq_file.h> 21#include <linux/seq_file.h>
@@ -30,9 +33,11 @@
30#include <linux/netfilter/xt_recent.h> 33#include <linux/netfilter/xt_recent.h>
31 34
32MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); 35MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
36MODULE_AUTHOR("Jan Engelhardt <jengelh@computergmbh.de>");
33MODULE_DESCRIPTION("Xtables: \"recently-seen\" host matching for IPv4"); 37MODULE_DESCRIPTION("Xtables: \"recently-seen\" host matching for IPv4");
34MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
35MODULE_ALIAS("ipt_recent"); 39MODULE_ALIAS("ipt_recent");
40MODULE_ALIAS("ip6t_recent");
36 41
37static unsigned int ip_list_tot = 100; 42static unsigned int ip_list_tot = 100;
38static unsigned int ip_pkt_list_tot = 20; 43static unsigned int ip_pkt_list_tot = 20;
@@ -49,14 +54,15 @@ module_param(ip_list_gid, uint, 0400);
49MODULE_PARM_DESC(ip_list_tot, "number of IPs to remember per list"); 54MODULE_PARM_DESC(ip_list_tot, "number of IPs to remember per list");
50MODULE_PARM_DESC(ip_pkt_list_tot, "number of packets per IP to remember (max. 255)"); 55MODULE_PARM_DESC(ip_pkt_list_tot, "number of packets per IP to remember (max. 255)");
51MODULE_PARM_DESC(ip_list_hash_size, "size of hash table used to look up IPs"); 56MODULE_PARM_DESC(ip_list_hash_size, "size of hash table used to look up IPs");
52MODULE_PARM_DESC(ip_list_perms, "permissions on /proc/net/ipt_recent/* files"); 57MODULE_PARM_DESC(ip_list_perms, "permissions on /proc/net/xt_recent/* files");
53MODULE_PARM_DESC(ip_list_uid,"owner of /proc/net/ipt_recent/* files"); 58MODULE_PARM_DESC(ip_list_uid,"owner of /proc/net/xt_recent/* files");
54MODULE_PARM_DESC(ip_list_gid,"owning group of /proc/net/ipt_recent/* files"); 59MODULE_PARM_DESC(ip_list_gid,"owning group of /proc/net/xt_recent/* files");
55 60
56struct recent_entry { 61struct recent_entry {
57 struct list_head list; 62 struct list_head list;
58 struct list_head lru_list; 63 struct list_head lru_list;
59 __be32 addr; 64 union nf_inet_addr addr;
65 u_int16_t family;
60 u_int8_t ttl; 66 u_int8_t ttl;
61 u_int8_t index; 67 u_int8_t index;
62 u_int16_t nstamps; 68 u_int16_t nstamps;
@@ -67,7 +73,7 @@ struct recent_table {
67 struct list_head list; 73 struct list_head list;
68 char name[XT_RECENT_NAME_LEN]; 74 char name[XT_RECENT_NAME_LEN];
69#ifdef CONFIG_PROC_FS 75#ifdef CONFIG_PROC_FS
70 struct proc_dir_entry *proc; 76 struct proc_dir_entry *proc_old, *proc;
71#endif 77#endif
72 unsigned int refcnt; 78 unsigned int refcnt;
73 unsigned int entries; 79 unsigned int entries;
@@ -80,31 +86,53 @@ static DEFINE_SPINLOCK(recent_lock);
80static DEFINE_MUTEX(recent_mutex); 86static DEFINE_MUTEX(recent_mutex);
81 87
82#ifdef CONFIG_PROC_FS 88#ifdef CONFIG_PROC_FS
83static struct proc_dir_entry *proc_dir; 89#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
84static const struct file_operations recent_fops; 90static struct proc_dir_entry *proc_old_dir;
91#endif
92static struct proc_dir_entry *recent_proc_dir;
93static const struct file_operations recent_old_fops, recent_mt_fops;
85#endif 94#endif
86 95
87static u_int32_t hash_rnd; 96static u_int32_t hash_rnd;
88static int hash_rnd_initted; 97static bool hash_rnd_initted;
98
99static unsigned int recent_entry_hash4(const union nf_inet_addr *addr)
100{
101 if (!hash_rnd_initted) {
102 get_random_bytes(&hash_rnd, sizeof(hash_rnd));
103 hash_rnd_initted = true;
104 }
105 return jhash_1word((__force u32)addr->ip, hash_rnd) &
106 (ip_list_hash_size - 1);
107}
89 108
90static unsigned int recent_entry_hash(__be32 addr) 109static unsigned int recent_entry_hash6(const union nf_inet_addr *addr)
91{ 110{
92 if (!hash_rnd_initted) { 111 if (!hash_rnd_initted) {
93 get_random_bytes(&hash_rnd, 4); 112 get_random_bytes(&hash_rnd, sizeof(hash_rnd));
94 hash_rnd_initted = 1; 113 hash_rnd_initted = true;
95 } 114 }
96 return jhash_1word((__force u32)addr, hash_rnd) & (ip_list_hash_size - 1); 115 return jhash2((u32 *)addr->ip6, ARRAY_SIZE(addr->ip6), hash_rnd) &
116 (ip_list_hash_size - 1);
97} 117}
98 118
99static struct recent_entry * 119static struct recent_entry *
100recent_entry_lookup(const struct recent_table *table, __be32 addr, u_int8_t ttl) 120recent_entry_lookup(const struct recent_table *table,
121 const union nf_inet_addr *addrp, u_int16_t family,
122 u_int8_t ttl)
101{ 123{
102 struct recent_entry *e; 124 struct recent_entry *e;
103 unsigned int h; 125 unsigned int h;
104 126
105 h = recent_entry_hash(addr); 127 if (family == AF_INET)
128 h = recent_entry_hash4(addrp);
129 else
130 h = recent_entry_hash6(addrp);
131
106 list_for_each_entry(e, &table->iphash[h], list) 132 list_for_each_entry(e, &table->iphash[h], list)
107 if (e->addr == addr && (ttl == e->ttl || !ttl || !e->ttl)) 133 if (e->family == family &&
134 memcmp(&e->addr, addrp, sizeof(e->addr)) == 0 &&
135 (ttl == e->ttl || ttl == 0 || e->ttl == 0))
108 return e; 136 return e;
109 return NULL; 137 return NULL;
110} 138}
@@ -118,7 +146,8 @@ static void recent_entry_remove(struct recent_table *t, struct recent_entry *e)
118} 146}
119 147
120static struct recent_entry * 148static struct recent_entry *
121recent_entry_init(struct recent_table *t, __be32 addr, u_int8_t ttl) 149recent_entry_init(struct recent_table *t, const union nf_inet_addr *addr,
150 u_int16_t family, u_int8_t ttl)
122{ 151{
123 struct recent_entry *e; 152 struct recent_entry *e;
124 153
@@ -130,12 +159,16 @@ recent_entry_init(struct recent_table *t, __be32 addr, u_int8_t ttl)
130 GFP_ATOMIC); 159 GFP_ATOMIC);
131 if (e == NULL) 160 if (e == NULL)
132 return NULL; 161 return NULL;
133 e->addr = addr; 162 memcpy(&e->addr, addr, sizeof(e->addr));
134 e->ttl = ttl; 163 e->ttl = ttl;
135 e->stamps[0] = jiffies; 164 e->stamps[0] = jiffies;
136 e->nstamps = 1; 165 e->nstamps = 1;
137 e->index = 1; 166 e->index = 1;
138 list_add_tail(&e->list, &t->iphash[recent_entry_hash(addr)]); 167 e->family = family;
168 if (family == AF_INET)
169 list_add_tail(&e->list, &t->iphash[recent_entry_hash4(addr)]);
170 else
171 list_add_tail(&e->list, &t->iphash[recent_entry_hash6(addr)]);
139 list_add_tail(&e->lru_list, &t->lru_list); 172 list_add_tail(&e->lru_list, &t->lru_list);
140 t->entries++; 173 t->entries++;
141 return e; 174 return e;
@@ -179,28 +212,42 @@ recent_mt(const struct sk_buff *skb, const struct net_device *in,
179 const struct xt_recent_mtinfo *info = matchinfo; 212 const struct xt_recent_mtinfo *info = matchinfo;
180 struct recent_table *t; 213 struct recent_table *t;
181 struct recent_entry *e; 214 struct recent_entry *e;
182 __be32 addr; 215 union nf_inet_addr addr = {};
183 u_int8_t ttl; 216 u_int8_t ttl;
184 bool ret = info->invert; 217 bool ret = info->invert;
185 218
186 if (info->side == XT_RECENT_DEST) 219 if (match->family == AF_INET) {
187 addr = ip_hdr(skb)->daddr; 220 const struct iphdr *iph = ip_hdr(skb);
188 else 221
189 addr = ip_hdr(skb)->saddr; 222 if (info->side == XT_RECENT_DEST)
223 addr.ip = iph->daddr;
224 else
225 addr.ip = iph->saddr;
226
227 ttl = iph->ttl;
228 } else {
229 const struct ipv6hdr *iph = ipv6_hdr(skb);
230
231 if (info->side == XT_RECENT_DEST)
232 memcpy(&addr.in6, &iph->daddr, sizeof(addr.in6));
233 else
234 memcpy(&addr.in6, &iph->saddr, sizeof(addr.in6));
235
236 ttl = iph->hop_limit;
237 }
190 238
191 ttl = ip_hdr(skb)->ttl;
192 /* use TTL as seen before forwarding */ 239 /* use TTL as seen before forwarding */
193 if (out && !skb->sk) 240 if (out && !skb->sk)
194 ttl++; 241 ttl++;
195 242
196 spin_lock_bh(&recent_lock); 243 spin_lock_bh(&recent_lock);
197 t = recent_table_lookup(info->name); 244 t = recent_table_lookup(info->name);
198 e = recent_entry_lookup(t, addr, 245 e = recent_entry_lookup(t, &addr, match->family,
199 info->check_set & XT_RECENT_TTL ? ttl : 0); 246 (info->check_set & XT_RECENT_TTL) ? ttl : 0);
200 if (e == NULL) { 247 if (e == NULL) {
201 if (!(info->check_set & XT_RECENT_SET)) 248 if (!(info->check_set & XT_RECENT_SET))
202 goto out; 249 goto out;
203 e = recent_entry_init(t, addr, ttl); 250 e = recent_entry_init(t, &addr, match->family, ttl);
204 if (e == NULL) 251 if (e == NULL)
205 *hotdrop = true; 252 *hotdrop = true;
206 ret = !ret; 253 ret = !ret;
@@ -277,11 +324,24 @@ recent_mt_check(const char *tablename, const void *ip,
277 for (i = 0; i < ip_list_hash_size; i++) 324 for (i = 0; i < ip_list_hash_size; i++)
278 INIT_LIST_HEAD(&t->iphash[i]); 325 INIT_LIST_HEAD(&t->iphash[i]);
279#ifdef CONFIG_PROC_FS 326#ifdef CONFIG_PROC_FS
280 t->proc = proc_create(t->name, ip_list_perms, proc_dir, &recent_fops); 327 t->proc = proc_create(t->name, ip_list_perms, recent_proc_dir,
328 &recent_mt_fops);
281 if (t->proc == NULL) { 329 if (t->proc == NULL) {
282 kfree(t); 330 kfree(t);
283 goto out; 331 goto out;
284 } 332 }
333#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
334 t->proc_old = proc_create(t->name, ip_list_perms, proc_old_dir,
335 &recent_old_fops);
336 if (t->proc_old == NULL) {
337 remove_proc_entry(t->name, proc_old_dir);
338 kfree(t);
339 goto out;
340 }
341 t->proc_old->uid = ip_list_uid;
342 t->proc_old->gid = ip_list_gid;
343 t->proc_old->data = t;
344#endif
285 t->proc->uid = ip_list_uid; 345 t->proc->uid = ip_list_uid;
286 t->proc->gid = ip_list_gid; 346 t->proc->gid = ip_list_gid;
287 t->proc->data = t; 347 t->proc->data = t;
@@ -307,7 +367,10 @@ static void recent_mt_destroy(const struct xt_match *match, void *matchinfo)
307 list_del(&t->list); 367 list_del(&t->list);
308 spin_unlock_bh(&recent_lock); 368 spin_unlock_bh(&recent_lock);
309#ifdef CONFIG_PROC_FS 369#ifdef CONFIG_PROC_FS
310 remove_proc_entry(t->name, proc_dir); 370#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
371 remove_proc_entry(t->name, proc_old_dir);
372#endif
373 remove_proc_entry(t->name, recent_proc_dir);
311#endif 374#endif
312 recent_table_flush(t); 375 recent_table_flush(t);
313 kfree(t); 376 kfree(t);
@@ -317,7 +380,7 @@ static void recent_mt_destroy(const struct xt_match *match, void *matchinfo)
317 380
318#ifdef CONFIG_PROC_FS 381#ifdef CONFIG_PROC_FS
319struct recent_iter_state { 382struct recent_iter_state {
320 struct recent_table *table; 383 const struct recent_table *table;
321 unsigned int bucket; 384 unsigned int bucket;
322}; 385};
323 386
@@ -342,8 +405,8 @@ static void *recent_seq_next(struct seq_file *seq, void *v, loff_t *pos)
342{ 405{
343 struct recent_iter_state *st = seq->private; 406 struct recent_iter_state *st = seq->private;
344 const struct recent_table *t = st->table; 407 const struct recent_table *t = st->table;
345 struct recent_entry *e = v; 408 const struct recent_entry *e = v;
346 struct list_head *head = e->list.next; 409 const struct list_head *head = e->list.next;
347 410
348 while (head == &t->iphash[st->bucket]) { 411 while (head == &t->iphash[st->bucket]) {
349 if (++st->bucket >= ip_list_hash_size) 412 if (++st->bucket >= ip_list_hash_size)
@@ -366,8 +429,14 @@ static int recent_seq_show(struct seq_file *seq, void *v)
366 unsigned int i; 429 unsigned int i;
367 430
368 i = (e->index - 1) % ip_pkt_list_tot; 431 i = (e->index - 1) % ip_pkt_list_tot;
369 seq_printf(seq, "src=%u.%u.%u.%u ttl: %u last_seen: %lu oldest_pkt: %u", 432 if (e->family == AF_INET)
370 NIPQUAD(e->addr), e->ttl, e->stamps[i], e->index); 433 seq_printf(seq, "src=" NIPQUAD_FMT " ttl: %u last_seen: %lu "
434 "oldest_pkt: %u", NIPQUAD(e->addr.ip), e->ttl,
435 e->stamps[i], e->index);
436 else
437 seq_printf(seq, "src=" NIP6_FMT " ttl: %u last_seen: %lu "
438 "oldest_pkt: %u", NIP6(e->addr.in6), e->ttl,
439 e->stamps[i], e->index);
371 for (i = 0; i < e->nstamps; i++) 440 for (i = 0; i < e->nstamps; i++)
372 seq_printf(seq, "%s %lu", i ? "," : "", e->stamps[i]); 441 seq_printf(seq, "%s %lu", i ? "," : "", e->stamps[i]);
373 seq_printf(seq, "\n"); 442 seq_printf(seq, "\n");
@@ -394,8 +463,22 @@ static int recent_seq_open(struct inode *inode, struct file *file)
394 return 0; 463 return 0;
395} 464}
396 465
397static ssize_t recent_proc_write(struct file *file, const char __user *input, 466#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
398 size_t size, loff_t *loff) 467static int recent_old_seq_open(struct inode *inode, struct file *filp)
468{
469 static bool warned_of_old;
470
471 if (unlikely(!warned_of_old)) {
472 printk(KERN_INFO KBUILD_MODNAME ": Use of /proc/net/ipt_recent"
473 " is deprecated; use /proc/net/xt_recent.\n");
474 warned_of_old = true;
475 }
476 return recent_seq_open(inode, filp);
477}
478
479static ssize_t recent_old_proc_write(struct file *file,
480 const char __user *input,
481 size_t size, loff_t *loff)
399{ 482{
400 const struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); 483 const struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
401 struct recent_table *t = pde->data; 484 struct recent_table *t = pde->data;
@@ -408,6 +491,7 @@ static ssize_t recent_proc_write(struct file *file, const char __user *input,
408 size = sizeof(buf); 491 size = sizeof(buf);
409 if (copy_from_user(buf, input, size)) 492 if (copy_from_user(buf, input, size))
410 return -EFAULT; 493 return -EFAULT;
494
411 while (isspace(*c)) 495 while (isspace(*c))
412 c++; 496 c++;
413 497
@@ -435,10 +519,10 @@ static ssize_t recent_proc_write(struct file *file, const char __user *input,
435 addr = in_aton(c); 519 addr = in_aton(c);
436 520
437 spin_lock_bh(&recent_lock); 521 spin_lock_bh(&recent_lock);
438 e = recent_entry_lookup(t, addr, 0); 522 e = recent_entry_lookup(t, (const void *)&addr, PF_INET, 0);
439 if (e == NULL) { 523 if (e == NULL) {
440 if (add) 524 if (add)
441 recent_entry_init(t, addr, 0); 525 recent_entry_init(t, (const void *)&addr, PF_INET, 0);
442 } else { 526 } else {
443 if (add) 527 if (add)
444 recent_entry_update(t, e); 528 recent_entry_update(t, e);
@@ -449,23 +533,118 @@ static ssize_t recent_proc_write(struct file *file, const char __user *input,
449 return size; 533 return size;
450} 534}
451 535
452static const struct file_operations recent_fops = { 536static const struct file_operations recent_old_fops = {
453 .open = recent_seq_open, 537 .open = recent_old_seq_open,
454 .read = seq_read, 538 .read = seq_read,
455 .write = recent_proc_write, 539 .write = recent_old_proc_write,
456 .release = seq_release_private, 540 .release = seq_release_private,
457 .owner = THIS_MODULE, 541 .owner = THIS_MODULE,
458}; 542};
543#endif
544
545static ssize_t
546recent_mt_proc_write(struct file *file, const char __user *input,
547 size_t size, loff_t *loff)
548{
549 const struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
550 struct recent_table *t = pde->data;
551 struct recent_entry *e;
552 char buf[sizeof("+b335:1d35:1e55:dead:c0de:1715:5afe:c0de")];
553 const char *c = buf;
554 union nf_inet_addr addr;
555 u_int16_t family;
556 bool add, succ;
557
558 if (size == 0)
559 return 0;
560 if (size > sizeof(buf))
561 size = sizeof(buf);
562 if (copy_from_user(buf, input, size) != 0)
563 return -EFAULT;
564
565 /* Strict protocol! */
566 if (*loff != 0)
567 return -ESPIPE;
568 switch (*c) {
569 case '/': /* flush table */
570 spin_lock_bh(&recent_lock);
571 recent_table_flush(t);
572 spin_unlock_bh(&recent_lock);
573 return size;
574 case '-': /* remove address */
575 add = false;
576 break;
577 case '+': /* add address */
578 add = true;
579 break;
580 default:
581 printk(KERN_INFO KBUILD_MODNAME ": Need +ip, -ip or /\n");
582 return -EINVAL;
583 }
584
585 ++c;
586 --size;
587 if (strnchr(c, size, ':') != NULL) {
588 family = AF_INET6;
589 succ = in6_pton(c, size, (void *)&addr, '\n', NULL);
590 } else {
591 family = AF_INET;
592 succ = in4_pton(c, size, (void *)&addr, '\n', NULL);
593 }
594
595 if (!succ) {
596 printk(KERN_INFO KBUILD_MODNAME ": illegal address written "
597 "to procfs\n");
598 return -EINVAL;
599 }
600
601 spin_lock_bh(&recent_lock);
602 e = recent_entry_lookup(t, &addr, family, 0);
603 if (e == NULL) {
604 if (add)
605 recent_entry_init(t, &addr, family, 0);
606 } else {
607 if (add)
608 recent_entry_update(t, e);
609 else
610 recent_entry_remove(t, e);
611 }
612 spin_unlock_bh(&recent_lock);
613 /* Note we removed one above */
614 *loff += size + 1;
615 return size + 1;
616}
617
618static const struct file_operations recent_mt_fops = {
619 .open = recent_seq_open,
620 .read = seq_read,
621 .write = recent_mt_proc_write,
622 .release = seq_release_private,
623 .owner = THIS_MODULE,
624};
459#endif /* CONFIG_PROC_FS */ 625#endif /* CONFIG_PROC_FS */
460 626
461static struct xt_match recent_mt_reg __read_mostly = { 627static struct xt_match recent_mt_reg[] __read_mostly = {
462 .name = "recent", 628 {
463 .family = AF_INET, 629 .name = "recent",
464 .match = recent_mt, 630 .revision = 0,
465 .matchsize = sizeof(struct xt_recent_mtinfo), 631 .family = AF_INET,
466 .checkentry = recent_mt_check, 632 .match = recent_mt,
467 .destroy = recent_mt_destroy, 633 .matchsize = sizeof(struct xt_recent_mtinfo),
468 .me = THIS_MODULE, 634 .checkentry = recent_mt_check,
635 .destroy = recent_mt_destroy,
636 .me = THIS_MODULE,
637 },
638 {
639 .name = "recent",
640 .revision = 0,
641 .family = AF_INET6,
642 .match = recent_mt,
643 .matchsize = sizeof(struct xt_recent_mtinfo),
644 .checkentry = recent_mt_check,
645 .destroy = recent_mt_destroy,
646 .me = THIS_MODULE,
647 },
469}; 648};
470 649
471static int __init recent_mt_init(void) 650static int __init recent_mt_init(void)
@@ -476,26 +655,39 @@ static int __init recent_mt_init(void)
476 return -EINVAL; 655 return -EINVAL;
477 ip_list_hash_size = 1 << fls(ip_list_tot); 656 ip_list_hash_size = 1 << fls(ip_list_tot);
478 657
479 err = xt_register_match(&recent_mt_reg); 658 err = xt_register_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg));
480#ifdef CONFIG_PROC_FS 659#ifdef CONFIG_PROC_FS
481 if (err) 660 if (err)
482 return err; 661 return err;
483 proc_dir = proc_mkdir("ipt_recent", init_net.proc_net); 662 recent_proc_dir = proc_mkdir("xt_recent", init_net.proc_net);
484 if (proc_dir == NULL) { 663 if (recent_proc_dir == NULL) {
485 xt_unregister_match(&recent_mt_reg); 664 xt_unregister_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg));
665 err = -ENOMEM;
666 }
667#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
668 if (err < 0)
669 return err;
670 proc_old_dir = proc_mkdir("ipt_recent", init_net.proc_net);
671 if (proc_old_dir == NULL) {
672 remove_proc_entry("xt_recent", init_net.proc_net);
673 xt_unregister_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg));
486 err = -ENOMEM; 674 err = -ENOMEM;
487 } 675 }
488#endif 676#endif
677#endif
489 return err; 678 return err;
490} 679}
491 680
492static void __exit recent_mt_exit(void) 681static void __exit recent_mt_exit(void)
493{ 682{
494 BUG_ON(!list_empty(&tables)); 683 BUG_ON(!list_empty(&tables));
495 xt_unregister_match(&recent_mt_reg); 684 xt_unregister_matches(recent_mt_reg, ARRAY_SIZE(recent_mt_reg));
496#ifdef CONFIG_PROC_FS 685#ifdef CONFIG_PROC_FS
686#ifdef CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
497 remove_proc_entry("ipt_recent", init_net.proc_net); 687 remove_proc_entry("ipt_recent", init_net.proc_net);
498#endif 688#endif
689 remove_proc_entry("xt_recent", init_net.proc_net);
690#endif
499} 691}
500 692
501module_init(recent_mt_init); 693module_init(recent_mt_init);