linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Vladimir B. Savkin" <master@sectorb.msk.ru>
To: Carlos Velasco <carlosev@newipnet.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	"David S. Miller" <davem@redhat.com>,
	Marcelo Tosatti <marcelo@conectiva.com.br>,
	netdev@oss.sgi.com, linux-net@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: SRC IP selection in ARP request (Was: bugfix: ARP respond on all devices)
Date: Mon, 18 Aug 2003 19:49:46 +0400	[thread overview]
Message-ID: <20030818154945.GA32191@tentacle.sectorb.msk.ru> (raw)
In-Reply-To: <200308171827130739.00C3905F@192.168.128.16>

On Sun, Aug 17, 2003 at 06:27:13PM +0200, Carlos Velasco wrote:
> If you send a packet through dev eth0 to dev lo IP address or other
                                        ^^
	Did you mean "from"?

> interface, when Linux try to map the MAC address with the IP address of
> the default gateway (or the gateway to reach the packet Source IP
> address), it uses the lo IP address (or other dev) in the ARP Request.

I think I saw this problem, but in another situation:
Suppose we are the server and have TCP connection established,
using src address 10.0.0.1 (because the client have chosen this address 
to connect to). But the route to the client leads via gateway 10.1.0.1,
reachable through dev eth0. We have address 10.1.0.2/24 assigned to
eth0. All is fine until ARP table entry for 10.1.0.1 is expired and
we start to send ARP requests. We choose 10.0.0.1 for src ip in the
requests, because that's what upper layer uses, and gateway doesn't
respond because it's Cisco or BSD.

I didn't test arpfilter (I think it wasn't there when I met this
problem), but it can be solved with the following simple patch
(implemented as a new per-interface sysctl). I just tested it, works for
me. echo 1 > /proc/sys/net/ipv4/conf/all/arp_select_clean_src

diff -ur _orig_linux/include/linux/inetdevice.h linux/include/linux/inetdevice.h
--- _orig_linux/include/linux/inetdevice.h	Mon Aug 11 13:24:51 2003
+++ linux/include/linux/inetdevice.h	Mon Aug 18 18:21:30 2003
@@ -18,6 +18,7 @@
 	int	mc_forwarding;
 	int	tag;
 	int     arp_filter;
+	int 	arp_select_clean_src;
 	int	medium_id;
 	void	*sysctl;
 };
@@ -68,6 +69,7 @@
 	  (ipv4_devconf.accept_redirects || (in_dev)->cnf.accept_redirects)))
 
 #define IN_DEV_ARPFILTER(in_dev)	(ipv4_devconf.arp_filter || (in_dev)->cnf.arp_filter)
+#define IN_DEV_ARP_CLEAN_SRC(in_dev)	(ipv4_devconf.arp_select_clean_src || (in_dev)->cnf.arp_select_clean_src)
 
 struct in_ifaddr
 {
diff -ur _orig_linux/include/linux/sysctl.h linux/include/linux/sysctl.h
--- _orig_linux/include/linux/sysctl.h	Mon Aug 11 13:28:18 2003
+++ linux/include/linux/sysctl.h	Mon Aug 18 18:52:01 2003
@@ -349,6 +349,7 @@
 	NET_IPV4_CONF_TAG=12,
 	NET_IPV4_CONF_ARPFILTER=13,
 	NET_IPV4_CONF_MEDIUM_ID=14,
+	NET_IPV4_CONF_ARPSRC=15,
 };
 
 /* /proc/sys/net/ipv6 */
diff -ur _orig_linux/net/ipv4/arp.c linux/net/ipv4/arp.c
--- _orig_linux/net/ipv4/arp.c	Mon Aug 11 13:24:52 2003
+++ linux/net/ipv4/arp.c	Mon Aug 18 18:36:44 2003
@@ -322,8 +322,20 @@
 	struct net_device *dev = neigh->dev;
 	u32 target = *(u32*)neigh->primary_key;
 	int probes = atomic_read(&neigh->probes);
+	int inherit_src;
+	struct in_device *in_dev;
 
-	if (skb && inet_addr_type(skb->nh.iph->saddr) == RTN_LOCAL)
+	read_lock(&inetdev_lock);
+	in_dev = __in_dev_get(dev);
+	if (in_dev != NULL) {
+		inherit_src = !IN_DEV_ARP_CLEAN_SRC(in_dev);
+	} else {
+		inherit_src = 1;
+	}
+	read_unlock(&inetdev_lock);
+
+	if ( inherit_src &&
+		  skb && inet_addr_type(skb->nh.iph->saddr) == RTN_LOCAL)
 		saddr = skb->nh.iph->saddr;
 	else
 		saddr = inet_select_addr(dev, target, RT_SCOPE_LINK);
diff -ur _orig_linux/net/ipv4/devinet.c linux/net/ipv4/devinet.c
--- _orig_linux/net/ipv4/devinet.c	Fri Jun 13 18:51:39 2003
+++ linux/net/ipv4/devinet.c	Mon Aug 18 18:54:07 2003
@@ -1056,7 +1056,7 @@
 static struct devinet_sysctl_table
 {
 	struct ctl_table_header *sysctl_header;
-	ctl_table devinet_vars[15];
+	ctl_table devinet_vars[16];
 	ctl_table devinet_dev[2];
 	ctl_table devinet_conf_dir[2];
 	ctl_table devinet_proto_dir[2];
@@ -1104,6 +1104,9 @@
 	 &proc_dointvec},
 	{NET_IPV4_CONF_ARPFILTER, "arp_filter",
 	 &ipv4_devconf.arp_filter, sizeof(int), 0644, NULL,
+	 &proc_dointvec},
+	{NET_IPV4_CONF_ARPSRC, "arp_select_clean_src",
+	 &ipv4_devconf.arp_select_clean_src, sizeof(int), 0644, NULL,
 	 &proc_dointvec},
 	 {0}},
 

:wq
                                        With best regards, 
                                           Vladimir Savkin. 


  parent reply	other threads:[~2003-08-18 15:50 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-27 20:52 [2.4 PATCH] bugfix: ARP respond on all devices Bas Bloemsaat
2003-07-27 22:12 ` David S. Miller
2003-07-28  2:31   ` Ben Greear
2003-07-28  7:33     ` Bas Bloemsaat
2003-07-27 23:40 ` Carlos Velasco
2003-07-27 23:46   ` David S. Miller
2003-07-27 23:58     ` Carlos Velasco
2003-07-27 23:58       ` David S. Miller
2003-07-28  0:11         ` Carlos Velasco
2003-07-28  0:14           ` David S. Miller
2003-07-28  0:35             ` Carlos Velasco
2003-07-28  0:36               ` David S. Miller
2003-07-28  0:53                 ` Carlos Velasco
2003-07-28  0:55                   ` David S. Miller
2003-07-28  1:23                     ` Carlos Velasco
2003-07-28  1:35                       ` David S. Miller
2003-07-28 10:43                         ` Carlos Velasco
2003-07-28 17:09                           ` Phil Oester
2003-07-28 18:56                             ` Bas Bloemsaat
2003-07-28  4:37                     ` David Lang
2003-07-28  4:39                       ` David S. Miller
2003-07-28 10:49                       ` Carlos Velasco
2003-07-28  0:57           ` Assorted 2.6.0-test2 build warnings J.C. Wren
2003-07-28 22:11             ` Randy.Dunlap
2003-07-29 10:42               ` Adrian Bunk
2003-07-29  2:51     ` [2.4 PATCH] bugfix: ARP respond on all devices Bill Davidsen
2003-07-29  4:48       ` Lamont Granquist
2003-08-04  6:10         ` Pekka Savola
2003-08-17 13:09         ` Carlos Velasco
2003-08-17 13:16           ` Carlos Velasco
2003-08-17 13:41             ` Alan Cox
2003-08-17 13:55               ` Carlos Velasco
2003-08-17 15:12                 ` Bernd Eckenfels
2003-08-17 15:28                 ` Alan Cox
2003-08-17 15:57                   ` Bas Bloemsaat
2003-08-17 15:59                   ` Carlos Velasco
2003-08-17 16:26                     ` Alan Cox
2003-08-17 16:27                       ` Carlos Velasco
2003-08-17 17:24                         ` Alan Cox
2003-08-17 22:48                           ` Willy Tarreau
2003-08-18  5:22                             ` David S. Miller
2003-08-18  6:56                               ` Willy Tarreau
2003-08-18  7:01                                 ` David S. Miller
2003-08-18  7:29                                   ` Willy Tarreau
2003-08-18  7:43                                     ` Willy Tarreau
2003-08-18  5:31                             ` David S. Miller
2003-08-18 11:39                               ` Stephan von Krawczynski
2003-08-18 11:44                                 ` David S. Miller
2003-08-18 12:34                                   ` Stephan von Krawczynski
2003-08-18 12:30                                     ` David S. Miller
2003-08-18 12:51                                       ` Mr. James W. Laferriere
2003-08-18 12:53                                       ` Stephan von Krawczynski
2003-08-18 12:55                                         ` David S. Miller
2003-08-18 13:17                                           ` Stephan von Krawczynski
2003-08-18 13:14                                             ` David S. Miller
2003-08-18 14:23                                               ` Stephan von Krawczynski
2003-08-18 14:19                                                 ` David S. Miller
2003-08-18 15:46                                                   ` Stephan von Krawczynski
2003-08-18 13:23                                           ` jamal
2003-08-18 13:21                                             ` David S. Miller
2003-08-18 13:40                                               ` Stephan von Krawczynski
2003-08-20  6:55                                             ` Bas Bloemsaat
2003-08-18 21:54                                       ` Bill Davidsen
2003-08-18 13:40                                     ` Dominik Kubla
2003-08-18 12:51                                   ` Willy Tarreau
2003-08-18 12:53                                     ` David S. Miller
2003-08-18 14:28                                       ` Willy Tarreau
2003-08-18 14:28                                         ` David S. Miller
2003-08-18 12:08                                 ` Bas Bloemsaat
2003-08-18 12:03                                   ` David S. Miller
2003-08-18 21:32                               ` Bill Davidsen
2003-08-19  3:21                                 ` Ben Greear
2003-08-19 15:22                                   ` David S. Miller
2003-08-19  7:58                                 ` Bas Bloemsaat
2003-08-18 15:49                         ` Vladimir B. Savkin [this message]
2003-08-17 16:51                     ` David T Hollis
2003-08-17 16:45                       ` Carlos Velasco
2003-08-17 17:13                         ` Arjan van de Ven
2003-08-17 19:46                           ` insecure
2003-08-18  5:11                             ` David S. Miller
2003-08-18  5:29                 ` David S. Miller
2003-08-17 13:59               ` Bas Bloemsaat
2003-08-18 10:48               ` Robert Collier
2003-08-17 13:38           ` Alan Cox

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=20030818154945.GA32191@tentacle.sectorb.msk.ru \
    --to=master@sectorb.msk.ru \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=carlosev@newipnet.com \
    --cc=davem@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-net@vger.kernel.org \
    --cc=marcelo@conectiva.com.br \
    --cc=netdev@oss.sgi.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).