send to self patch
Subsystems (5)
Hi,
Here in the lab we often want to send TCP/IP data out over looped back networks. We do have tools to send and receive raw packets but sometimes thats not enough.
eg When running netperf, you dont always need two machines. If you are just trying to stress a box (eg to find a bug like the NAPI one we hit a week or two ago) then running loopback is fine.
We also have exercisers that run over TCP/IP and checksum sent data vs received data.
I stumbled upon a patch by Julian Anastasov, and have found it works well. Is there any chance of getting this (or something like it) into 2.6?
Anton
Documentation/filesystems/proc.txt renamed from linux/Documentation/filesystems/proc.txt +9 -0
@@ -1502,6 +1502,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 -------------
Documentation/networking/ip-sysctl.txt renamed from linux/Documentation/networking/ip-sysctl.txt +7 -0
@@ -390,6 +390,13 @@ forwarding - BOOLEAN Enable IP forwarding on this 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. + mc_forwarding - BOOLEAN Do multicast routing. The kernel needs to be compiled with CONFIG_MROUTE and a multicast routing daemon is required.
include/linux/inetdevice.h renamed from linux/include/linux/inetdevice.h +2 -0
@@ -21,6 +21,7 @@int medium_id;int no_xfrm;int no_policy; +int loop;void *sysctl; };
@@ -70,6 +71,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 {
include/linux/sysctl.h renamed from linux/include/linux/sysctl.h +1 -0
@@ -359,6 +359,7 @@NET_IPV4_CONF_MEDIUM_ID =14 ,NET_IPV4_CONF_NOXFRM =15 ,NET_IPV4_CONF_NOPOLICY =16 , + NET_IPV4_CONF_LOOP=17, };/* /proc/sys/net/ipv6 */
net/ipv4/devinet.c renamed from linux/net/ipv4/devinet.c +9 -1
@@ -1122,7 +1122,7 @@ static struct devinet_sysctl_table { struct ctl_table_header *sysctl_header; - ctl_table devinet_vars[17]; + ctl_table devinet_vars[18]; ctl_table devinet_dev[2]; ctl_table devinet_conf_dir[2]; ctl_table devinet_proto_dir[2];
@@ -1258,6 +1258,14 @@ .mode = 0644, .proc_handler = &ipv4_doint_and_flush, .strategy = &ipv4_doint_and_flush_strategy, + }, + { + .ctl_name = NET_IPV4_CONF_LOOP, + .procname = "loop", + .data = &ipv4_devconf.loop, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec, }, }, .devinet_dev = {
net/ipv4/fib_frontend.c renamed from linux/net/ipv4/fib_frontend.c +8 -2
@@ -167,15 +167,16 @@ .tos = tos } }, .iif = oif };struct fib_result res; -int no_addr, rpf; +int no_addr, rpf, loop;int ret; - 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);
@@ -184,6 +185,11 @@if (fib_lookup (&fl, &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);
net/ipv4/route.c renamed from linux/net/ipv4/route.c +38 -2
@@ -1967,6 +1967,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 (oldflp->fl4_dst) || oldflp->fl4_dst ==0xFFFFFFFF ) {if (!fl.fl4_src)
@@ -2036,10 +2041,41 @@ goto e_inval;if (res.type ==RTN_LOCAL ) { -if (!fl.fl4_src) - fl.fl4_src = fl.fl4_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 = fl.fl4_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; + fl.fl4_src = src; + fl.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 (!fl.fl4_src) + fl.fl4_src = fl.fl4_dst; dev_out = &loopback_dev;dev_hold (dev_out); fl.oif = dev_out->ifindex;
While the various 'send-to-self' patches are useful for exactly what you are trying to do, I think a more generic solution, which has as one of it's features the ability to 'send-to-self', should be integrated into the kernel (I think it might be too late for anything new to be added to 2.6).
Since I'm not the type to criticize without providing an alternate solution, take a look at http://linux-vrf.sf.net/ for my attempt at solving a larger problem (virtual routing and forwarding), which also solves the 'send-to-self' problem (by creating a vrf and place one of the 'send-to-self' interfaces in that vrf). The patch is against a 2.4.19 kernel, but should apply to 2.4.20-21.
Quoted 207 lines · Anton Blanchard
Hi,
Here in the lab we often want to send TCP/IP data out over looped back networks. We do have tools to send and receive raw packets but sometimes thats not enough.
eg When running netperf, you dont always need two machines. If you are just trying to stress a box (eg to find a bug like the NAPI one we hit a week or two ago) then running loopback is fine.
We also have exercisers that run over TCP/IP and checksum sent data vs received data.
I stumbled upon a patch by Julian Anastasov, and have found it works well. Is there any chance of getting this (or something like it) into 2.6?
Anton
diff -ur
v2.5.73/linux/Documentation/filesystems/proc.txtlinux/Documentation/filesystems/proc.txtDocumentation/filesystems/proc.txt renamed from linux/Documentation/filesystems/proc.txt +9
-0@@ -1502,6 +1502,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.5.73/linux/Documentation/networking/ip-sysctl.txtlinux/Documentation/networking/ip-sysctl.txtDocumentation/networking/ip-sysctl.txt renamed from linux/Documentation/networking/ip-sysctl.txt +7
-0@@ -390,6 +390,13 @@ forwarding - BOOLEAN Enable IP forwarding on this 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. + mc_forwarding - BOOLEAN Do multicast routing. The kernel needs to be compiled with CONFIG_MROUTE and a multicast routing daemon is required.diff -ur
v2.5.73/linux/include/linux/inetdevice.hlinux/include/linux/inetdevice.hinclude/linux/inetdevice.h renamed from linux/include/linux/inetdevice.h +2
-0@@ -21,6 +21,7 @@int medium_id;int no_xfrm;int no_policy; +int loop;void *sysctl; };@@ -70,6 +71,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.5.73/linux/include/linux/sysctl.hlinux/include/linux/sysctl.hinclude/linux/sysctl.h renamed from linux/include/linux/sysctl.h +1
-0@@ -359,6 +359,7 @@NET_IPV4_CONF_MEDIUM_ID =14 ,NET_IPV4_CONF_NOXFRM =15 ,NET_IPV4_CONF_NOPOLICY =16 , + NET_IPV4_CONF_LOOP=17, };/* /proc/sys/net/ipv6 */ diff -ur
v2.5.73/linux/net/ipv4/devinet.clinux/net/ipv4/devinet.cnet/ipv4/devinet.c renamed from linux/net/ipv4/devinet.c +9
-1@@ -1122,7 +1122,7 @@ static struct devinet_sysctl_table { struct ctl_table_header *sysctl_header; - ctl_table devinet_vars[17]; + ctl_table devinet_vars[18]; ctl_table devinet_dev[2]; ctl_table devinet_conf_dir[2]; ctl_table devinet_proto_dir[2];@@ -1258,6 +1258,14 @@ .mode = 0644, .proc_handler = &ipv4_doint_and_flush, .strategy = &ipv4_doint_and_flush_strategy, + }, + { + .ctl_name = NET_IPV4_CONF_LOOP, + .procname = "loop", + .data = &ipv4_devconf.loop, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec, }, }, .devinet_dev = {diff -ur
v2.5.73/linux/net/ipv4/fib_frontend.clinux/net/ipv4/fib_frontend.cnet/ipv4/fib_frontend.c renamed from linux/net/ipv4/fib_frontend.c +8
-2@@ -167,15 +167,16 @@ .tos = tos } }, .iif = oif };struct fib_result res; -int no_addr, rpf; +int no_addr, rpf, loop;int ret; - 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);@@ -184,6 +185,11 @@if (fib_lookup (&fl, &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.5.73/linux/net/ipv4/route.clinux/net/ipv4/route.cnet/ipv4/route.c renamed from linux/net/ipv4/route.c +38
-2@@ -1967,6 +1967,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 (oldflp->fl4_dst) || oldflp->fl4_dst ==0xFFFFFFFF ) {if (!fl.fl4_src)@@ -2036,10 +2041,41 @@ goto e_inval;if (res.type ==RTN_LOCAL ) { -if (!fl.fl4_src) - fl.fl4_src = fl.fl4_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 = fl.fl4_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; + fl.fl4_src = src; + fl.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 (!fl.fl4_src) + fl.fl4_src = fl.fl4_dst; dev_out = &loopback_dev;dev_hold (dev_out); fl.oif = dev_out->ifindex;
Signature · 1 line
James R. Leu