mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-08 21:54:57 +02:00
xt_DNETMAP: support for kernels below 2.6.34
This commit is contained in:

committed by
Jan Engelhardt

parent
8fd3eb56eb
commit
f4882ca029
@@ -5,6 +5,7 @@ Fixes:
|
|||||||
- xt_pknock: avoid crash when hash TFM could not be allocated
|
- xt_pknock: avoid crash when hash TFM could not be allocated
|
||||||
- xt_pknock: avoid inversion of rule lookup that led to warnings
|
- xt_pknock: avoid inversion of rule lookup that led to warnings
|
||||||
- xt_DNETMAP: add missing module alias
|
- xt_DNETMAP: add missing module alias
|
||||||
|
- xt_DNETMAP: support for kernels below 2.6.34
|
||||||
|
|
||||||
|
|
||||||
v1.33 (2011-02-02)
|
v1.33 (2011-02-02)
|
||||||
|
@@ -3,10 +3,12 @@
|
|||||||
* or destination (PREROUTING),
|
* or destination (PREROUTING),
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* (C) 2010 Marek Kierdelewicz <marek@koba.pl>
|
/* (C) 2011 Marek Kierdelewicz <marek@koba.pl>
|
||||||
*
|
*
|
||||||
* module is dedicated to my wife Eliza and my daughters Jula and Ola :* :* :*
|
* module is dedicated to my wife Eliza and my daughters Jula and Ola :* :* :*
|
||||||
*
|
*
|
||||||
|
* module audited and cleaned-up by Jan Engelhardt
|
||||||
|
*
|
||||||
* module uses some code and ideas from following modules:
|
* module uses some code and ideas from following modules:
|
||||||
* - "NETMAP" module by Svenning Soerensen <svenning@post5.tele.dk>
|
* - "NETMAP" module by Svenning Soerensen <svenning@post5.tele.dk>
|
||||||
* - "recent" module by Stephen Frost <sfrost@snowman.net>
|
* - "recent" module by Stephen Frost <sfrost@snowman.net>
|
||||||
@@ -23,9 +25,12 @@
|
|||||||
#include <linux/netfilter.h>
|
#include <linux/netfilter.h>
|
||||||
#include <linux/netfilter_ipv4.h>
|
#include <linux/netfilter_ipv4.h>
|
||||||
#include <linux/netfilter/x_tables.h>
|
#include <linux/netfilter/x_tables.h>
|
||||||
|
#include <linux/version.h>
|
||||||
#include <net/netfilter/nf_nat_rule.h>
|
#include <net/netfilter/nf_nat_rule.h>
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)
|
||||||
#include <net/net_namespace.h>
|
#include <net/net_namespace.h>
|
||||||
#include <net/netns/generic.h>
|
#include <net/netns/generic.h>
|
||||||
|
#endif
|
||||||
#include "xt_DNETMAP.h"
|
#include "xt_DNETMAP.h"
|
||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
|
|
||||||
@@ -91,11 +96,16 @@ struct dnetmap_net {
|
|||||||
struct list_head *dnetmap_iphash;
|
struct list_head *dnetmap_iphash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)
|
||||||
static int dnetmap_net_id;
|
static int dnetmap_net_id;
|
||||||
static inline struct dnetmap_net *dnetmap_pernet(struct net *net)
|
static inline struct dnetmap_net *dnetmap_pernet(struct net *net)
|
||||||
{
|
{
|
||||||
return net_generic(net, dnetmap_net_id);
|
return net_generic(net, dnetmap_net_id);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
struct dnetmap_net *dnetmap;
|
||||||
|
#define dnetmap_pernet(x) dnetmap
|
||||||
|
#endif
|
||||||
|
|
||||||
static DEFINE_SPINLOCK(dnetmap_lock);
|
static DEFINE_SPINLOCK(dnetmap_lock);
|
||||||
static DEFINE_MUTEX(dnetmap_mutex);
|
static DEFINE_MUTEX(dnetmap_mutex);
|
||||||
@@ -237,12 +247,12 @@ static int dnetmap_tg_check(const struct xt_tgchk_param *par)
|
|||||||
ip_min = ntohl(mr->range[0].min_ip) + (whole_prefix == 0);
|
ip_min = ntohl(mr->range[0].min_ip) + (whole_prefix == 0);
|
||||||
ip_max = ntohl(mr->range[0].max_ip) - (whole_prefix == 0);
|
ip_max = ntohl(mr->range[0].max_ip) - (whole_prefix == 0);
|
||||||
|
|
||||||
sprintf(p->prefix_str, "%pI4/%u", &mr->range[0].min_ip,
|
sprintf(p->prefix_str, NIPQUAD_FMT "/%u", NIPQUAD(mr->range[0].min_ip),
|
||||||
33 - ffs(~(ip_min ^ ip_max)));
|
33 - ffs(~(ip_min ^ ip_max)));
|
||||||
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
||||||
sprintf(proc_str_data, "%pI4_%u", &mr->range[0].min_ip,
|
sprintf(proc_str_data, NIPQUAD_FMT "_%u", NIPQUAD(mr->range[0].min_ip),
|
||||||
33 - ffs(~(ip_min ^ ip_max)));
|
33 - ffs(~(ip_min ^ ip_max)));
|
||||||
sprintf(proc_str_stat, "%pI4_%u_stat", &mr->range[0].min_ip,
|
sprintf(proc_str_stat, NIPQUAD_FMT "_%u_stat", NIPQUAD(mr->range[0].min_ip),
|
||||||
33 - ffs(~(ip_min ^ ip_max)));
|
33 - ffs(~(ip_min ^ ip_max)));
|
||||||
#endif
|
#endif
|
||||||
printk(KERN_INFO KBUILD_MODNAME ": new prefix %s\n", p->prefix_str);
|
printk(KERN_INFO KBUILD_MODNAME ": new prefix %s\n", p->prefix_str);
|
||||||
@@ -369,8 +379,8 @@ bind_new_prefix:
|
|||||||
if (e->prenat_addr != 0 && time_before(jiffies, e->stamp)) {
|
if (e->prenat_addr != 0 && time_before(jiffies, e->stamp)) {
|
||||||
if (!disable_log)
|
if (!disable_log)
|
||||||
printk(KERN_INFO KBUILD_MODNAME
|
printk(KERN_INFO KBUILD_MODNAME
|
||||||
": ip %pI4 - no free adresses in prefix %s\n",
|
": ip " NIPQUAD_FMT " - no free adresses in prefix %s\n",
|
||||||
&prenat_ip, p->prefix_str);
|
NIPQUAD(prenat_ip), p->prefix_str);
|
||||||
goto no_free_ip;
|
goto no_free_ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,8 +390,8 @@ bind_new_prefix:
|
|||||||
prenat_ip_prev = e->prenat_addr;
|
prenat_ip_prev = e->prenat_addr;
|
||||||
if (!disable_log)
|
if (!disable_log)
|
||||||
printk(KERN_INFO KBUILD_MODNAME
|
printk(KERN_INFO KBUILD_MODNAME
|
||||||
": timeout binding %pI4 -> %pI4\n",
|
": timeout binding " NIPQUAD_FMT " -> " NIPQUAD_FMT "\n",
|
||||||
&prenat_ip_prev, &postnat_ip);
|
NIPQUAD(prenat_ip_prev), NIPQUAD(postnat_ip) );
|
||||||
list_del(&e->list);
|
list_del(&e->list);
|
||||||
list_del(&e->glist);
|
list_del(&e->glist);
|
||||||
list_del(&e->grlist);
|
list_del(&e->grlist);
|
||||||
@@ -401,8 +411,8 @@ bind_new_prefix:
|
|||||||
(postnat_ip)]);
|
(postnat_ip)]);
|
||||||
if (!disable_log)
|
if (!disable_log)
|
||||||
printk(KERN_INFO KBUILD_MODNAME
|
printk(KERN_INFO KBUILD_MODNAME
|
||||||
": add binding %pI4 -> %pI4\n", &prenat_ip,
|
": add binding " NIPQUAD_FMT " -> " NIPQUAD_FMT "\n",
|
||||||
&postnat_ip);
|
NIPQUAD(prenat_ip),NIPQUAD(postnat_ip));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -410,9 +420,9 @@ bind_new_prefix:
|
|||||||
if (time_before(e->stamp, jiffies) && p != e->prefix) {
|
if (time_before(e->stamp, jiffies) && p != e->prefix) {
|
||||||
if (!disable_log)
|
if (!disable_log)
|
||||||
printk(KERN_INFO KBUILD_MODNAME
|
printk(KERN_INFO KBUILD_MODNAME
|
||||||
": timeout binding %pI4 -> %pI4\n",
|
": timeout binding " NIPQUAD_FMT " -> " NIPQUAD_FMT "\n",
|
||||||
&e->prenat_addr,
|
NIPQUAD(e->prenat_addr),
|
||||||
&e->postnat_addr);
|
NIPQUAD(e->postnat_addr));
|
||||||
list_del(&e->list);
|
list_del(&e->list);
|
||||||
list_del(&e->glist);
|
list_del(&e->glist);
|
||||||
list_del(&e->grlist);
|
list_del(&e->grlist);
|
||||||
@@ -465,11 +475,11 @@ static void dnetmap_tg_destroy(const struct xt_tgdtor_param *par)
|
|||||||
list_del(&p->list);
|
list_del(&p->list);
|
||||||
spin_unlock_bh(&dnetmap_lock);
|
spin_unlock_bh(&dnetmap_lock);
|
||||||
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
||||||
sprintf(str, "%pI4_%u", &mr->range[0].min_ip,
|
sprintf(str, NIPQUAD_FMT "_%u", NIPQUAD(mr->range[0].min_ip),
|
||||||
33 - ffs(~(ntohl(mr->range[0].min_ip ^
|
33 - ffs(~(ntohl(mr->range[0].min_ip ^
|
||||||
mr->range[0].max_ip))));
|
mr->range[0].max_ip))));
|
||||||
remove_proc_entry(str, dnetmap_net->xt_dnetmap);
|
remove_proc_entry(str, dnetmap_net->xt_dnetmap);
|
||||||
sprintf(str, "%pI4_%u_stat", &mr->range[0].min_ip,
|
sprintf(str, NIPQUAD_FMT "_%u_stat", NIPQUAD(mr->range[0].min_ip),
|
||||||
33 - ffs(~(ntohl(mr->range[0].min_ip ^
|
33 - ffs(~(ntohl(mr->range[0].min_ip ^
|
||||||
mr->range[0].max_ip))));
|
mr->range[0].max_ip))));
|
||||||
remove_proc_entry(str, dnetmap_net->xt_dnetmap);
|
remove_proc_entry(str, dnetmap_net->xt_dnetmap);
|
||||||
@@ -526,8 +536,8 @@ static int dnetmap_seq_show(struct seq_file *seq, void *v)
|
|||||||
{
|
{
|
||||||
const struct dnetmap_entry *e = v;
|
const struct dnetmap_entry *e = v;
|
||||||
|
|
||||||
seq_printf(seq, "%pI4 -> %pI4 --- ttl: %d lasthit: %lu\n",
|
seq_printf(seq, NIPQUAD_FMT " -> " NIPQUAD_FMT " --- ttl: %d lasthit: %lu\n",
|
||||||
&e->prenat_addr, &e->postnat_addr,
|
NIPQUAD(e->prenat_addr), NIPQUAD(e->postnat_addr),
|
||||||
(int)(e->stamp - jiffies) / HZ, (e->stamp - jtimeout) / HZ);
|
(int)(e->stamp - jiffies) / HZ, (e->stamp - jtimeout) / HZ);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -610,6 +620,7 @@ static void __net_exit dnetmap_proc_net_exit(struct net *net)
|
|||||||
{
|
{
|
||||||
proc_net_remove(net, "xt_DNETMAP");
|
proc_net_remove(net, "xt_DNETMAP");
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
static inline int dnetmap_proc_net_init(struct net *net)
|
static inline int dnetmap_proc_net_init(struct net *net)
|
||||||
{
|
{
|
||||||
@@ -619,7 +630,6 @@ static inline int dnetmap_proc_net_init(struct net *net)
|
|||||||
static inline void dnetmap_proc_net_exit(struct net *net)
|
static inline void dnetmap_proc_net_exit(struct net *net)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_PROC_FS */
|
#endif /* CONFIG_PROC_FS */
|
||||||
|
|
||||||
static int __net_init dnetmap_net_init(struct net *net)
|
static int __net_init dnetmap_net_init(struct net *net)
|
||||||
@@ -627,6 +637,13 @@ static int __net_init dnetmap_net_init(struct net *net)
|
|||||||
struct dnetmap_net *dnetmap_net = dnetmap_pernet(net);
|
struct dnetmap_net *dnetmap_net = dnetmap_pernet(net);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)
|
||||||
|
dnetmap = kmalloc(sizeof(struct dnetmap_net),GFP_ATOMIC);
|
||||||
|
if (dnetmap == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
dnetmap_net = dnetmap;
|
||||||
|
#endif
|
||||||
|
|
||||||
dnetmap_net->dnetmap_iphash = kmalloc(sizeof(struct list_head) *
|
dnetmap_net->dnetmap_iphash = kmalloc(sizeof(struct list_head) *
|
||||||
hash_size * 2, GFP_ATOMIC);
|
hash_size * 2, GFP_ATOMIC);
|
||||||
if (dnetmap_net->dnetmap_iphash == NULL)
|
if (dnetmap_net->dnetmap_iphash == NULL)
|
||||||
@@ -644,14 +661,19 @@ static void __net_exit dnetmap_net_exit(struct net *net)
|
|||||||
|
|
||||||
BUG_ON(!list_empty(&dnetmap_net->prefixes));
|
BUG_ON(!list_empty(&dnetmap_net->prefixes));
|
||||||
kfree(dnetmap_net->dnetmap_iphash);
|
kfree(dnetmap_net->dnetmap_iphash);
|
||||||
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)
|
||||||
|
kfree(dnetmap_net);
|
||||||
|
#endif
|
||||||
dnetmap_proc_net_exit(net);
|
dnetmap_proc_net_exit(net);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct pernet_operations dnetmap_net_ops = {
|
static struct pernet_operations dnetmap_net_ops = {
|
||||||
.init = dnetmap_net_init,
|
.init = dnetmap_net_init,
|
||||||
.exit = dnetmap_net_exit,
|
.exit = dnetmap_net_exit,
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)
|
||||||
.id = &dnetmap_net_id,
|
.id = &dnetmap_net_id,
|
||||||
.size = sizeof(struct dnetmap_net),
|
.size = sizeof(struct dnetmap_net),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct xt_target dnetmap_tg_reg __read_mostly = {
|
static struct xt_target dnetmap_tg_reg __read_mostly = {
|
||||||
|
Reference in New Issue
Block a user