diff -ur v2.4.21/linux/Documentation/filesystems/proc.txt linux/Documentation/filesystems/proc.txt
--- v2.4.21/linux/Documentation/filesystems/proc.txt	Sat Jun 14 08:41:59 2003
+++ linux/Documentation/filesystems/proc.txt	Tue Jul  1 23:32:09 2003
@@ -1527,6 +1527,15 @@
 
 Log packets with source addresses with no known route to kernel log.
 
+loop
+----
+
+By default (loop=0) the traffic between local IP addresses
+is routed via interface "lo". Setting this flag for two
+interfaces allows traffic between their IP addresses to
+be looped externally. This is useful for setups where the
+interfaces are attached to same broadcast medium.
+
 mc_forwarding
 -------------
 
diff -ur v2.4.21/linux/Documentation/networking/ip-sysctl.txt linux/Documentation/networking/ip-sysctl.txt
--- v2.4.21/linux/Documentation/networking/ip-sysctl.txt	Sat Jun 14 08:41:59 2003
+++ linux/Documentation/networking/ip-sysctl.txt	Tue Jul  1 23:31:32 2003
@@ -391,6 +391,13 @@
 	conf/all/mc_forwarding must also be set to TRUE to enable multicast routing
 	for the interface
 
+loop - BOOLEAN
+	By default (loop=0) the traffic between local IP addresses
+	is routed via interface "lo". Setting this flag for two
+	interfaces allows traffic between their IP addresses to
+	be looped externally. This is useful for setups where the
+	interfaces are attached to same broadcast medium.
+
 medium_id - INTEGER
 	Integer value used to differentiate the devices by the medium they
 	are attached to. Two devices can have different id values when
diff -ur v2.4.21/linux/include/linux/inetdevice.h linux/include/linux/inetdevice.h
--- v2.4.21/linux/include/linux/inetdevice.h	Sat Aug  3 12:13:46 2002
+++ linux/include/linux/inetdevice.h	Sun Jun 29 15:47:00 2003
@@ -19,6 +19,7 @@
 	int	tag;
 	int     arp_filter;
 	int	medium_id;
+	int	loop;
 	void	*sysctl;
 };
 
@@ -58,6 +59,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_LOOP(in_dev)	((in_dev)->cnf.loop)
 
 struct in_ifaddr
 {
diff -ur v2.4.21/linux/include/linux/sysctl.h linux/include/linux/sysctl.h
--- v2.4.21/linux/include/linux/sysctl.h	Sat Jun 14 08:42:54 2003
+++ linux/include/linux/sysctl.h	Sun Jun 29 15:47:26 2003
@@ -344,6 +344,7 @@
 	NET_IPV4_CONF_TAG=12,
 	NET_IPV4_CONF_ARPFILTER=13,
 	NET_IPV4_CONF_MEDIUM_ID=14,
+	NET_IPV4_CONF_LOOP=15,
 };
 
 /* /proc/sys/net/ipv6 */
diff -ur v2.4.21/linux/net/ipv4/devinet.c linux/net/ipv4/devinet.c
--- v2.4.21/linux/net/ipv4/devinet.c	Sat Jun 14 08:42:55 2003
+++ linux/net/ipv4/devinet.c	Sun Jun 29 15:48:25 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_LOOP, "loop",
+	 &ipv4_devconf.loop, sizeof(int), 0644, NULL,
 	 &proc_dointvec},
 	 {0}},
 
diff -ur v2.4.21/linux/net/ipv4/fib_frontend.c linux/net/ipv4/fib_frontend.c
--- v2.4.21/linux/net/ipv4/fib_frontend.c	Sat Aug  3 12:13:52 2002
+++ linux/net/ipv4/fib_frontend.c	Sun Jun 29 16:19:57 2003
@@ -209,7 +209,7 @@
 	struct in_device *in_dev;
 	struct rt_key key;
 	struct fib_result res;
-	int no_addr, rpf;
+	int no_addr, rpf, loop;
 	int ret;
 
 	key.dst = src;
@@ -219,12 +219,13 @@
 	key.iif = oif;
 	key.scope = RT_SCOPE_UNIVERSE;
 
-	no_addr = rpf = 0;
+	no_addr = rpf = loop = 0;
 	read_lock(&inetdev_lock);
 	in_dev = __in_dev_get(dev);
 	if (in_dev) {
 		no_addr = in_dev->ifa_list == NULL;
 		rpf = IN_DEV_RPFILTER(in_dev);
+		loop = IN_DEV_LOOP(in_dev);
 	}
 	read_unlock(&inetdev_lock);
 
@@ -233,6 +234,11 @@
 
 	if (fib_lookup(&key, &res))
 		goto last_resort;
+	if (loop && res.type == RTN_LOCAL) {
+		*spec_dst = FIB_RES_PREFSRC(res);
+		fib_res_put(&res);
+		return 0;
+	}
 	if (res.type != RTN_UNICAST)
 		goto e_inval_res;
 	*spec_dst = FIB_RES_PREFSRC(res);
diff -ur v2.4.21/linux/net/ipv4/route.c linux/net/ipv4/route.c
--- v2.4.21/linux/net/ipv4/route.c	Sat Jun 14 08:42:55 2003
+++ linux/net/ipv4/route.c	Tue Jul  1 00:29:39 2003
@@ -1793,6 +1793,11 @@
 			dev_put(dev_out);
 			goto out;	/* Wrong error code */
 		}
+		err = -ENETDOWN;
+		if (!(dev_out->flags&IFF_UP)) {
+			dev_put(dev_out);
+			goto out;
+		}
 
 		if (LOCAL_MCAST(oldkey->dst) || oldkey->dst == 0xFFFFFFFF) {
 			if (!key.src)
@@ -1862,10 +1867,41 @@
 		goto e_inval;
 
 	if (res.type == RTN_LOCAL) {
-		if (!key.src)
-			key.src = key.dst;
+		struct in_device *in_dev;
+		u32 src;
+
 		if (dev_out)
 			dev_put(dev_out);
+		dev_out = FIB_RES_DEV(res);
+		in_dev = in_dev_get(dev_out);
+		src = key.src? : FIB_RES_PREFSRC(res);
+		if (in_dev && IN_DEV_LOOP(in_dev) && src) {
+			struct net_device *dev_src;
+
+			in_dev_put(in_dev);
+			in_dev = NULL;
+			dev_src = ip_dev_find(src);
+			if (dev_src && dev_src != dev_out &&
+			    (in_dev = in_dev_get(dev_src)) &&
+			    IN_DEV_LOOP(in_dev)) {
+				in_dev_put(in_dev);
+				dev_out = dev_src;
+				key.src = src;
+				key.oif = dev_out->ifindex;
+				res.type = RTN_UNICAST;
+				if (res.fi) {
+					fib_info_put(res.fi);
+					res.fi = NULL;
+				}
+				goto make_route;
+			}
+			if (dev_src)
+				dev_put(dev_src);
+		}
+		if (in_dev)
+			in_dev_put(in_dev);
+		if (!key.src)
+			key.src = key.dst;
 		dev_out = &loopback_dev;
 		dev_hold(dev_out);
 		key.oif = dev_out->ifindex;
