All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MASQUERADE handling of device events
@ 2004-11-07 18:18 Phil Oester
  2004-11-08  1:06 ` Henrik Nordstrom
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Phil Oester @ 2004-11-07 18:18 UTC (permalink / raw)
  To: netfilter-devel; +Cc: linux-net

[-- 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);
 

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2004-11-24 15:39 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.