From: Patrick McHardy <kaber@trash.net>
To: Phil Oester <kernel@linuxace.com>
Cc: linux-net@vger.kernel.org, netfilter-devel@lists.netfilter.org
Subject: Re: [PATCH] MASQUERADE handling of device events
Date: Mon, 08 Nov 2004 17:05:38 +0100 [thread overview]
Message-ID: <418F9952.5030004@trash.net> (raw)
In-Reply-To: <20041107181825.GA3522@linuxace.com>
Phil Oester wrote:
>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.
>
But without the ifindex comparison, a situation like this can happen:
ppp0 goes down
ppp1 goes down
ppp0 comes up again, same IP as before
ppp1 connections get killed
ppp1 comes up again
So we should keep this.
Regards
Patrick
>
>
>------------------------------------------------------------------------
>
>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 prev parent reply other threads:[~2004-11-08 16:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-07 18:18 [PATCH] MASQUERADE handling of device events Phil Oester
2004-11-08 1:06 ` Henrik Nordstrom
2004-11-08 13:50 ` Harald Welte
2004-11-11 22:58 ` David S. Miller
2004-11-08 16:05 ` Patrick McHardy [this message]
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=418F9952.5030004@trash.net \
--to=kaber@trash.net \
--cc=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.