From: Patrick McHardy <kaber@trash.net>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Harald Welte <laforge@netfilter.org>,
kuznet@ms2.inr.ac.ru, fenio@o2.pl, davem@redhat.com,
linux-net@vger.kernel.org,
Netfilter Development Mailinglist
<netfilter-devel@lists.netfilter.org>,
boris@boris.ca, email@cs-ware.de, Jan.Schubert@GMX.li
Subject: Re: MASQUERADE: Route sent us somewhere else (was Re: Fw: Rusty's brain broke!)
Date: Tue, 13 Jan 2004 05:30:55 +0100 [thread overview]
Message-ID: <4003747F.40304@trash.net> (raw)
In-Reply-To: <20040112234710.1B13C2C0C4@lists.samba.org>
[-- Attachment #1: Type: text/plain, Size: 561 bytes --]
Rusty Russell wrote:
> You take all the fun out.
>
> Yes, this is the best. It always does *something*, and is
> predictable. People with really complex routing shouldn't really use
> MASQUERADE, since it's designed for a specific, simple case.
I'm not sure about this, as Julian mentioned it breaks some setups,
but that's your decision.
>
> Patch?
Patches for 2.4+2.6 attached. Both patches compile, 2.6 version is also
tested.
Best regards,
Patrick
>
> Cheers,
> Rusty.
> --
> Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
>
[-- Attachment #2: 2.4-masq-ifa_local.diff --]
[-- Type: text/plain, Size: 2543 bytes --]
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
# 2004/01/13 05:05:13+01:00 kaber@trash.net
# Use indev->ifa_list->ifa_local for MASQUERADE
#
# net/ipv4/netfilter/ipt_MASQUERADE.c
# 2004/01/13 05:05:11+01:00 kaber@trash.net +16 -24
# Use indev->ifa_list->ifa_local for MASQUERADE
#
diff -Nru a/net/ipv4/netfilter/ipt_MASQUERADE.c b/net/ipv4/netfilter/ipt_MASQUERADE.c
--- a/net/ipv4/netfilter/ipt_MASQUERADE.c Tue Jan 13 05:09:32 2004
+++ b/net/ipv4/netfilter/ipt_MASQUERADE.c Tue Jan 13 05:09:32 2004
@@ -1,10 +1,13 @@
-/* Masquerade. Simple mapping which alters range to a local IP address
- (depending on route). */
+/* Masquerade. Simple mapping which alters range to a local IP address. */
+#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/types.h>
#include <linux/ip.h>
#include <linux/timer.h>
#include <linux/module.h>
+#include <linux/skbuff.h>
+#include <linux/netdevice.h>
+#include <linux/inetdevice.h>
#include <linux/netfilter.h>
#include <net/protocol.h>
#include <net/checksum.h>
@@ -67,9 +70,8 @@
enum ip_conntrack_info ctinfo;
const struct ip_nat_multi_range *mr;
struct ip_nat_multi_range newrange;
+ struct in_device *indev;
u_int32_t newsrc;
- struct rtable *rt;
- struct rt_key key;
IP_NF_ASSERT(hooknum == NF_IP_POST_ROUTING);
@@ -84,30 +86,20 @@
mr = targinfo;
- key.dst = (*pskb)->nh.iph->daddr;
- key.src = 0; /* Unknown: that's what we're trying to establish */
- key.tos = RT_TOS((*pskb)->nh.iph->tos)|RTO_CONN;
- key.oif = 0;
-#ifdef CONFIG_IP_ROUTE_FWMARK
- key.fwmark = (*pskb)->nfmark;
-#endif
- if (ip_route_output_key(&rt, &key) != 0) {
- /* Funky routing can do this. */
- if (net_ratelimit())
- printk("MASQUERADE:"
- " No route: Rusty's brain broke!\n");
- return NF_DROP;
- }
- if (rt->u.dst.dev != out) {
- if (net_ratelimit())
- printk("MASQUERADE:"
- " Route sent us somewhere else.\n");
+ indev = in_dev_get(out);
+ if (indev == NULL)
+ return NF_DROP;
+ read_lock(&indev->lock);
+ if (indev->ifa_list == NULL) {
+ read_unlock(&indev->lock);
+ in_dev_put(indev);
return NF_DROP;
}
+ newsrc = indev->ifa_list->ifa_local;
+ read_unlock(&indev->lock);
+ in_dev_put(indev);
- newsrc = rt->rt_src;
DEBUGP("newsrc = %u.%u.%u.%u\n", NIPQUAD(newsrc));
- ip_rt_put(rt);
WRITE_LOCK(&masq_lock);
ct->nat.masq_index = out->ifindex;
[-- Attachment #3: 2.6-masq-ifa_local.diff --]
[-- Type: text/plain, Size: 2415 bytes --]
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
# 2004/01/13 05:08:46+01:00 kaber@trash.net
# Use indev->ifa_list->ifa_local for MASQUERADE
#
# net/ipv4/netfilter/ipt_MASQUERADE.c
# 2004/01/13 05:05:49+01:00 kaber@trash.net +18 -28
# Use indev->ifa_list->ifa_local for MASQUERADE
#
diff -Nru a/net/ipv4/netfilter/ipt_MASQUERADE.c b/net/ipv4/netfilter/ipt_MASQUERADE.c
--- a/net/ipv4/netfilter/ipt_MASQUERADE.c Tue Jan 13 05:09:17 2004
+++ b/net/ipv4/netfilter/ipt_MASQUERADE.c Tue Jan 13 05:09:17 2004
@@ -1,10 +1,13 @@
-/* Masquerade. Simple mapping which alters range to a local IP address
- (depending on route). */
+/* Masquerade. Simple mapping which alters range to a local IP address. */
+#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/types.h>
#include <linux/ip.h>
#include <linux/timer.h>
#include <linux/module.h>
+#include <linux/skbuff.h>
+#include <linux/netdevice.h>
+#include <linux/inetdevice.h>
#include <linux/netfilter.h>
#include <net/protocol.h>
#include <net/checksum.h>
@@ -71,8 +74,8 @@
enum ip_conntrack_info ctinfo;
const struct ip_nat_multi_range *mr;
struct ip_nat_multi_range newrange;
+ struct in_device *indev;
u_int32_t newsrc;
- struct rtable *rt;
IP_NF_ASSERT(hooknum == NF_IP_POST_ROUTING);
@@ -87,33 +90,20 @@
mr = targinfo;
- {
- struct flowi fl = { .nl_u = { .ip4_u =
- { .daddr = (*pskb)->nh.iph->daddr,
- .tos = (RT_TOS((*pskb)->nh.iph->tos) |
- RTO_CONN),
-#ifdef CONFIG_IP_ROUTE_FWMARK
- .fwmark = (*pskb)->nfmark
-#endif
- } } };
- if (ip_route_output_key(&rt, &fl) != 0) {
- /* Funky routing can do this. */
- if (net_ratelimit())
- printk("MASQUERADE:"
- " No route: Rusty's brain broke!\n");
- return NF_DROP;
- }
- if (rt->u.dst.dev != out) {
- if (net_ratelimit())
- printk("MASQUERADE:"
- " Route sent us somewhere else.\n");
- return NF_DROP;
- }
- }
+ indev = in_dev_get(out);
+ if (indev == NULL)
+ return NF_DROP;
+ read_lock(&indev->lock);
+ if (indev->ifa_list == NULL) {
+ read_unlock(&indev->lock);
+ in_dev_put(indev);
+ return NF_DROP;
+ }
+ newsrc = indev->ifa_list->ifa_local;
+ read_unlock(&indev->lock);
+ in_dev_put(indev);
- newsrc = rt->rt_src;
DEBUGP("newsrc = %u.%u.%u.%u\n", NIPQUAD(newsrc));
- ip_rt_put(rt);
WRITE_LOCK(&masq_lock);
ct->nat.masq_index = out->ifindex;
next prev parent reply other threads:[~2004-01-13 4:30 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20030725173900.E6E952C2AE@lists.samba.org>
[not found] ` <200307251756.VAA12609@dub.inr.ac.ru>
2004-01-11 13:01 ` MASQUERADE: Route sent us somewhere else (was Re: Fw: Rusty's brain broke!) Harald Welte
2004-01-11 13:55 ` Julian Anastasov
2004-01-11 21:11 ` Henrik Nordstrom
2004-01-17 11:09 ` Future of CONNMARK (was " Harald Welte
2004-01-17 17:50 ` Henrik Nordstrom
2004-01-17 12:54 ` IP Options with libipq XiChimos
2004-01-21 13:44 ` Harald Welte
2004-01-18 13:20 ` Future of CONNMARK (was Re: MASQUERADE: Route sent us somewhere else (was Re: Fw: Rusty's brain broke!) Harald Welte
2004-01-18 17:16 ` Henrik Nordstrom
2004-01-19 23:15 ` Herve Eychenne
2004-01-19 23:48 ` Henrik Nordstrom
2004-01-20 1:13 ` Herve Eychenne
2004-01-20 7:05 ` Henrik Nordstrom
2004-01-20 7:12 ` Henrik Nordstrom
2004-01-20 23:21 ` Herve Eychenne
2004-01-20 18:34 ` Buffer size XiChimos
2004-01-21 0:45 ` Henrik Nordstrom
2004-01-20 19:58 ` XiChimos
2004-01-21 2:25 ` Henrik Nordstrom
2004-01-21 2:47 ` XiChimos
2004-01-21 8:45 ` Henrik Nordstrom
2004-01-20 23:55 ` Future of CONNMARK (was Re: MASQUERADE: Route sent us somewhere else (was Re: Fw: Rusty's brain broke!) Henrik Nordstrom
2004-01-21 23:49 ` Harald Welte
2004-01-20 13:01 ` Harald Welte
2004-01-21 0:17 ` extensions manpage, howto etc Henrik Nordstrom
2004-01-21 22:02 ` Harald Welte
2004-01-21 0:44 ` iptables error reporting Henrik Nordstrom
2004-01-21 2:16 ` iptables extensions manpage Henrik Nordstrom
2004-01-21 22:00 ` Harald Welte
2004-02-02 23:40 ` [patch, resent] Updated CONNMARK Henrik Nordstrom
2004-02-03 8:20 ` Harald Welte
2004-02-03 9:03 ` Henrik Nordstrom
2004-02-03 9:50 ` Harald Welte
2004-01-18 19:14 ` iptables extension manpages Henrik Nordstrom
2004-01-17 18:46 ` Future of CONNMARK (was Re: MASQUERADE: Route sent us somewhere else (was Re: Fw: Rusty's brain broke!) Tom Eastep
2004-01-17 23:40 ` Henrik Nordstrom
2004-01-18 0:20 ` Tom Eastep
2004-01-12 1:07 ` Patrick McHardy
2004-01-12 4:30 ` Rusty Russell
2004-01-13 4:30 ` Patrick McHardy [this message]
2004-01-13 8:21 ` Julian Anastasov
2004-01-13 11:54 ` Harald Welte
2004-01-14 5:20 ` Rusty Russell
2004-01-12 11:08 ` Julian Anastasov
2004-01-14 16:11 ` kuznet
2004-01-14 23:42 ` Julian Anastasov
2004-01-15 0:29 Henrik Nordstrom
2004-01-15 2:15 ` Patrick McHardy
2004-01-15 7:00 ` Henrik Nordstrom
2004-01-15 11:58 ` Patrick McHardy
2004-01-15 13:07 ` Henrik Nordstrom
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=4003747F.40304@trash.net \
--to=kaber@trash.net \
--cc=Jan.Schubert@GMX.li \
--cc=boris@boris.ca \
--cc=davem@redhat.com \
--cc=email@cs-ware.de \
--cc=fenio@o2.pl \
--cc=kuznet@ms2.inr.ac.ru \
--cc=laforge@netfilter.org \
--cc=linux-net@vger.kernel.org \
--cc=netfilter-devel@lists.netfilter.org \
--cc=rusty@rustcorp.com.au \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.