1 diff -urN linux-2.4.30.orig/Documentation/Configure.help linux-2.4.30/Documentation/Configure.help
2 --- linux-2.4.30.orig/Documentation/Configure.help 2005-07-01 02:06:36.000000000 +0200
3 +++ linux-2.4.30/Documentation/Configure.help 2005-07-01 00:41:09.000000000 +0200
5 If you want to compile it as a module, say M here and read
6 <file:Documentation/modules.txt>. If unsure, say `N'.
9 +CONFIG_IP_NF_TARGET_NETMAP
10 + NETMAP is an implementation of static 1:1 NAT mapping of network
11 + addresses. It maps the network address part, while keeping the
12 + host address part intact. It is similar to Fast NAT, except that
13 + Netfilter's connection tracking doesn't work well with Fast NAT.
15 + If you want to compile it as a module, say M here and read
16 + Documentation/modules.txt. The module will be called
17 + ipt_NETMAP.o. If unsure, say `N'.
21 This option adds a `mangle' table to iptables: see the man page for
22 diff -urN linux-2.4.30.orig/net/ipv4/netfilter/Config.in linux-2.4.30/net/ipv4/netfilter/Config.in
23 --- linux-2.4.30.orig/net/ipv4/netfilter/Config.in 2005-07-01 02:06:35.000000000 +0200
24 +++ linux-2.4.30/net/ipv4/netfilter/Config.in 2005-07-01 00:41:09.000000000 +0200
26 define_bool CONFIG_IP_NF_NAT_NEEDED y
27 dep_tristate ' MASQUERADE target support' CONFIG_IP_NF_TARGET_MASQUERADE $CONFIG_IP_NF_NAT
28 dep_tristate ' REDIRECT target support' CONFIG_IP_NF_TARGET_REDIRECT $CONFIG_IP_NF_NAT
29 + dep_tristate ' NETMAP target support' CONFIG_IP_NF_TARGET_NETMAP $CONFIG_IP_NF_NAT
30 if [ "$CONFIG_IP_NF_PPTP" = "m" ]; then
31 define_tristate CONFIG_IP_NF_NAT_PPTP m
33 diff -urN linux-2.4.30.orig/net/ipv4/netfilter/ipt_NETMAP.c linux-2.4.30/net/ipv4/netfilter/ipt_NETMAP.c
34 --- linux-2.4.30.orig/net/ipv4/netfilter/ipt_NETMAP.c 1970-01-01 01:00:00.000000000 +0100
35 +++ linux-2.4.30/net/ipv4/netfilter/ipt_NETMAP.c 2005-07-01 00:41:09.000000000 +0200
37 +/* NETMAP - static NAT mapping of IP network addresses (1:1).
38 + The mapping can be applied to source (POSTROUTING),
39 + destination (PREROUTING), or both (with separate rules).
41 + Author: Svenning Soerensen <svenning@post5.tele.dk>
44 +#include <linux/config.h>
45 +#include <linux/ip.h>
46 +#include <linux/module.h>
47 +#include <linux/netdevice.h>
48 +#include <linux/netfilter.h>
49 +#include <linux/netfilter_ipv4.h>
50 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
52 +#define MODULENAME "NETMAP"
53 +MODULE_LICENSE("GPL");
54 +MODULE_AUTHOR("Svenning Soerensen <svenning@post5.tele.dk>");
55 +MODULE_DESCRIPTION("iptables 1:1 NAT mapping of IP networks target");
58 +#define DEBUGP printk
60 +#define DEBUGP(format, args...)
64 +check(const char *tablename,
65 + const struct ipt_entry *e,
67 + unsigned int targinfosize,
68 + unsigned int hook_mask)
70 + const struct ip_nat_multi_range *mr = targinfo;
72 + if (strcmp(tablename, "nat") != 0) {
73 + DEBUGP(MODULENAME":check: bad table `%s'.\n", tablename);
76 + if (targinfosize != IPT_ALIGN(sizeof(*mr))) {
77 + DEBUGP(MODULENAME":check: size %u.\n", targinfosize);
80 + if (hook_mask & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_POST_ROUTING))) {
81 + DEBUGP(MODULENAME":check: bad hooks %x.\n", hook_mask);
84 + if (!(mr->range[0].flags & IP_NAT_RANGE_MAP_IPS)) {
85 + DEBUGP(MODULENAME":check: bad MAP_IPS.\n");
88 + if (mr->rangesize != 1) {
89 + DEBUGP(MODULENAME":check: bad rangesize %u.\n", mr->rangesize);
96 +target(struct sk_buff **pskb,
97 + unsigned int hooknum,
98 + const struct net_device *in,
99 + const struct net_device *out,
100 + const void *targinfo,
103 + struct ip_conntrack *ct;
104 + enum ip_conntrack_info ctinfo;
105 + u_int32_t new_ip, netmask;
106 + const struct ip_nat_multi_range *mr = targinfo;
107 + struct ip_nat_multi_range newrange;
109 + IP_NF_ASSERT(hooknum == NF_IP_PRE_ROUTING
110 + || hooknum == NF_IP_POST_ROUTING);
111 + ct = ip_conntrack_get(*pskb, &ctinfo);
113 + netmask = ~(mr->range[0].min_ip ^ mr->range[0].max_ip);
115 + if (hooknum == NF_IP_PRE_ROUTING)
116 + new_ip = (*pskb)->nh.iph->daddr & ~netmask;
118 + new_ip = (*pskb)->nh.iph->saddr & ~netmask;
119 + new_ip |= mr->range[0].min_ip & netmask;
121 + newrange = ((struct ip_nat_multi_range)
122 + { 1, { { mr->range[0].flags | IP_NAT_RANGE_MAP_IPS,
124 + mr->range[0].min, mr->range[0].max } } });
126 + /* Hand modified range to generic setup. */
127 + return ip_nat_setup_info(ct, &newrange, hooknum);
130 +static struct ipt_target target_module = {
131 + .name = MODULENAME,
133 + .checkentry = check,
137 +static int __init init(void)
139 + return ipt_register_target(&target_module);
142 +static void __exit fini(void)
144 + ipt_unregister_target(&target_module);
149 diff -urN linux-2.4.30.orig/net/ipv4/netfilter/Makefile linux-2.4.30/net/ipv4/netfilter/Makefile
150 --- linux-2.4.30.orig/net/ipv4/netfilter/Makefile 2005-07-01 02:06:35.000000000 +0200
151 +++ linux-2.4.30/net/ipv4/netfilter/Makefile 2005-07-01 00:41:09.000000000 +0200
153 obj-$(CONFIG_IP_NF_TARGET_MARK) += ipt_MARK.o
154 obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
155 obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
156 +obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
157 obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
158 obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
159 obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o