From: Phil Oester <kernel@linuxace.com>
To: netfilter-devel@lists.netfilter.org
Cc: linux-net@vger.kernel.org
Subject: [PATCH] MASQUERADE handling of device events
Date: Sun, 7 Nov 2004 10:18:25 -0800 [thread overview]
Message-ID: <20041107181825.GA3522@linuxace.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 804 bytes --]
As discussed in recent days, MASQUERADE target handling of device events
is broken in a couple of ways:
1) when ppp interfaces cycle, conntracks with old ip addresses are not
flushed
2) an 'ip addr add' on an interface used for masquerading flushes all
conntracks associated with that interface
The below patch addresses these issues by changing from using ifindex
comparisons to verifying that the masquerading ip still exists on the
box.
To achieve this, two changes were required to core networking code (thus
the linux-net cc):
1) export inet_confirm_addr
2) change inet_ifa_match to use ifa_local instead of ifa_address.
Since ifa_local != ifa_address on ppp interfaces, inet_ifa_match
could not be used to verify ppp interface addresses without
this change.
Comments?
Phil
[-- Attachment #2: patch-masq2 --]
[-- Type: text/plain, Size: 2466 bytes --]
diff -ru linux-orig/include/linux/inetdevice.h linux-diff/include/linux/inetdevice.h
--- linux-orig/include/linux/inetdevice.h 2004-11-04 17:32:05.573870736 -0500
+++ linux-diff/include/linux/inetdevice.h 2004-11-07 12:57:50.674323160 -0500
@@ -114,7 +114,7 @@
static __inline__ int inet_ifa_match(u32 addr, struct in_ifaddr *ifa)
{
- return !((addr^ifa->ifa_address)&ifa->ifa_mask);
+ return !((addr^ifa->ifa_local)&ifa->ifa_mask);
}
/*
diff -ru linux-orig/net/ipv4/devinet.c linux-diff/net/ipv4/devinet.c
--- linux-orig/net/ipv4/devinet.c 2004-11-04 17:32:05.000000000 -0500
+++ linux-diff/net/ipv4/devinet.c 2004-11-07 12:56:27.738931256 -0500
@@ -1493,6 +1493,7 @@
EXPORT_SYMBOL(devinet_ioctl);
EXPORT_SYMBOL(in_dev_finish_destroy);
+EXPORT_SYMBOL(inet_confirm_addr);
EXPORT_SYMBOL(inet_select_addr);
EXPORT_SYMBOL(inetdev_by_index);
EXPORT_SYMBOL(register_inetaddr_notifier);
diff -ru linux-orig/net/ipv4/netfilter/ipt_MASQUERADE.c linux-diff/net/ipv4/netfilter/ipt_MASQUERADE.c
--- linux-orig/net/ipv4/netfilter/ipt_MASQUERADE.c 2004-11-04 17:32:05.000000000 -0500
+++ linux-diff/net/ipv4/netfilter/ipt_MASQUERADE.c 2004-11-07 12:55:56.501680040 -0500
@@ -118,16 +118,15 @@
}
static inline int
-device_cmp(const struct ip_conntrack *i, void *_ina)
+device_cmp(const struct ip_conntrack *i, void *junk)
{
int ret = 0;
- struct in_ifaddr *ina = _ina;
READ_LOCK(&masq_lock);
- /* If it's masquerading out this interface with a different address,
- or we don't know the new address of this interface. */
- if (i->nat.masq_index == ina->ifa_dev->dev->ifindex
- && i->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip != ina->ifa_address)
+ /* If masquerading this conntrack but the masquerading ip
+ no longer exists locally, drop conntrack. */
+ if (i->nat.masq_index && !(inet_confirm_addr(NULL, 0,
+ i->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip, RT_SCOPE_HOST)))
ret = 1;
READ_UNLOCK(&masq_lock);
@@ -150,11 +149,10 @@
unsigned long event,
void *ptr)
{
- /* For some configurations, interfaces often come back with
- * the same address. If not, clean up old conntrack
- * entries. */
+ /* In some configurations, interfaces come back with the
+ * same address. If not, clean up old conntrack entries. */
if (event == NETDEV_UP)
- ip_ct_selective_cleanup(device_cmp, ptr);
+ ip_ct_selective_cleanup(device_cmp, NULL);
else if (event == NETDEV_DOWN)
ip_ct_selective_cleanup(connect_unassure, ptr);
next reply other threads:[~2004-11-07 18:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-07 18:18 Phil Oester [this message]
2004-11-08 1:06 ` [PATCH] MASQUERADE handling of device events Henrik Nordstrom
2004-11-08 13:50 ` Harald Welte
2004-11-11 22:58 ` David S. Miller
2004-11-08 16:05 ` Patrick McHardy
2004-11-08 16:15 ` Phil Oester
2004-11-08 16:24 ` Patrick McHardy
2004-11-08 16:34 ` Phil Oester
2004-11-08 21:55 ` Phil Oester
2004-11-09 11:04 ` Patrick McHardy
2004-11-09 16:53 ` Phil Oester
2004-11-09 17:44 ` Patrick McHardy
2004-11-21 2:58 ` Rusty Russell
2004-11-23 21:16 ` Phil Oester
2004-11-24 3:37 ` Rusty Russell
2004-11-24 9:24 ` Henrik Nordstrom
2004-11-24 15:39 ` Herve Eychenne
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=20041107181825.GA3522@linuxace.com \
--to=kernel@linuxace.com \
--cc=linux-net@vger.kernel.org \
--cc=netfilter-devel@lists.netfilter.org \
/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.