Advanced Source Routing using "ip rule add from <x.x.x.x> lookup <table>" returns error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[1.] One line summary of the problem:    
Advanced Source Routing using "ip rule add from <x.x.x.x> lookup <table>" returns error.

[2.] Full description of the problem/report:
I am trying to do advanced source routing. My setup is as follows
 tunnel-client                        tunnel-server
          ()==============================()
  eth0    10.3.30.115/16            10.3.30.93
  eth1    192.168.0.10/24
  relay   221.221.1.1/32

"relay" is virtual ppp interface, which encapsulates packets into tunnel
connecting the tunnel-server at 10.3.30.93.  Both boxes are on 10.3/16 LAN.

I have a kernel module (code below) which does route lookup using
ip_route_output(dst, src, 0, 0).
I have an "ip rule" to send all packets with src ip address 10.81.15.108 to
lookup into table "rlm". Table "rlm" has only a default route towards "relay"
device.
When I do ip_route_output(dst, 0, 0, 0) it succeeds returning next hop as the
default gw. If I do the lookup specifying the src ip address, the route lookup
fails.

I am not able to figure out why the route lookup should fail when src ip address
is specified as a parameter. It should give me the outgoing device as "relay". 
Or even if the "ip rule" has not taken effect, it should atleast return the 
default route from main table.

Output of the test code and system setup is in section 7.7
Please see the workaround in last section, although its not a feasible solution.
Any help in greatly appreciated.

Best Regards,
Santosh





[3.] Keywords (i.e., modules, networking, kernel):
kernel module
kernel 2.4.26 on Redhat 9.0
advanced routing based on source ip address
ip_route_output()

[4.] Kernel version (from /proc/version):
Linux version 2.4.26 (root@buddy) (gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #2 Wed Jul 20 18:09:53 PDT 2005

[6.] A small shell script or example program which triggers the
     problem (if possible)

<code>
#ifndef __KERNEL__
#  define __KERNEL__
#endif

/* The Makefile takes care of adding -DMODULE */

#include <linux/module.h>

#include <linux/kernel.h>    /* printk() */
#include <linux/slab.h>    /* kmalloc() */
#include <linux/errno.h>     /* error codes */
#include <linux/netdevice.h> /* basic data structures */
#include <linux/init.h>      /* __init */
#include <linux/skbuff.h>
#include <linux/if_arp.h>    /* ARPHRD_ETHER */
#include <linux/if.h>         /* ip header */
#include <linux/in.h>
#include <linux/inet.h>
#include <net/arp.h>         /* neighbor stuff */
#include <net/ip.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <linux/netfilter_ipv4.h>
#include <net/icmp.h>

#include <asm/uaccess.h>  /* memcpy and such */

MODULE_AUTHOR("Santosh Gupta.");
MODULE_LICENSE("GPL");

int my_route_lookup (unsigned int dst, unsigned int src)
{
  struct rtable *rt;
  int rval;

        rval = ip_route_output(&rt, dst, src, 0, 0);
  if (rval < 0)
  {
    printk (KERN_EMERG "inquiry for dst:0x%08x src:0x%08x failed", ntohl(dst), ntohl(src));
  }
  else
  {
    printk (KERN_EMERG "inquiry for dst:0x%08x src:0x%08x succeeded nh : 0x%08x ifnum  %d\n", 
              ntohl(dst), ntohl(src), ntohl(rt->rt_gateway), rt->u.dst.dev->ifindex);
  }

  return rval;
}

int init_module(void)
{
  unsigned int dst, src;

  dst = in_aton("66.94.230.32");
  src = in_aton("10.81.15.108");

  my_route_lookup (dst, src);
  my_route_lookup (dst, 0);

  return 0;
}

void cleanup_module(void)
{
}
</code>
To compile, copy the code above to myrelay.c
# gcc -Wall -O -g -DINSANE_DEBUG  -I/usr/src/linux/include  -DMODULE -o myrelay.o -c myrelay.c

[7.] Environment
[7.1.] Software (add the output of the ver_linux script here)
[dev/9.0/V3_1-RH@macho(115) sgupta]$ sh ver_linux 
If some fields are empty or look unusual you may have an old version.
Compare to the current minimal requirements in Documentation/Changes.
 
Linux macho 2.4.26 #2 Wed Jul 20 18:09:53 PDT 2005 i686 i686 i386 GNU/Linux
 
Gnu C                  3.2.2
Gnu make               3.79.1
util-linux             2.11y
mount                  2.11y
modutils               2.4.22
e2fsprogs              1.32
jfsutils               1.0.17
reiserfsprogs          3.6.4
pcmcia-cs              3.1.31
quota-tools            3.06.
isdn4k-utils           3.1pre4
Linux C Library        2.3.2
Dynamic linker (ldd)   2.3.2
Procps                 2.0.11
Net-tools              1.60
Kbd                    1.08
Sh-utils               4.5.3
Modules Loaded         myrelay pppot relay nfs nfsd lockd sunrpc autofs e100 microcode keybdev mousedev input hid usb-uhci ehci-hcd usbcore ext3 jbd

[7.2.] Processor information (from /proc/cpuinfo):
[dev/9.0/V3_1-RH@macho(115) sgupta]$ cat /proc/cpuinfo 
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 2
model name      : Intel(R) Pentium(R) 4 CPU 2.00GHz
stepping        : 9
cpu MHz         : 1993.555
cache size      : 512 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid
bogomips        : 3971.48

[7.3.] Module information (from /proc/modules):
[dev/9.0/V3_1-RH@macho(115) sgupta]$ cat /proc/modules 
myrelay                 1096   0 (unused)          <--- test code kernel module
pppot                   5696   0 (unused)          <--- my module
relay                   9948   1                   <--- relay device
nfs                    81304   1 (autoclean)
nfsd                   80336   8 (autoclean)
lockd                  60016   1 (autoclean) [nfs nfsd]
sunrpc                 85084   1 (autoclean) [nfs nfsd lockd]
autofs                 13460   1 (autoclean)
e100                   56964   2
microcode               5892   0 (autoclean)
keybdev                 3136   0 (unused)
mousedev                5556   0 (unused)
input                   5760   0 [keybdev mousedev]
hid                    19556   0 (unused)
usb-uhci               26348   0 (unused)
ehci-hcd               21160   0 (unused)
usbcore                79008   1 [hid usb-uhci ehci-hcd]
ext3                   71588   2
jbd                    52212   2 [ext3]

[7.7.] Other information that might be relevant to the problem
       (please look in /proc and include all information that you
       think to be relevant):
[dev/9.0/V3_1-RH@macho(115) ipv4]# pwd
/proc/sys/net/ipv4
[dev/9.0/V3_1-RH@macho(115) ipv4]# cat ip_forward 
1
[dev/9.0/V3_1-RH@macho(115) ipv4]# cd conf/
[dev/9.0/V3_1-RH@macho(115) conf]#  cat `find . -name rp_filter`
0
0
0
0
0
0
[dev/9.0/V3_1-RH@macho(115) conf]# cat `find . -name arp_filter`
0
0
0
0
0
0
[dev/9.0/V3_1-RH@macho(115) ipv4]# ip rule list
0:      from all lookup local 
32764:  from 10.81.15.108 lookup rlm 
32765:  from all fwmark 0x3 lookup rlm 
32766:  from all lookup main 
32767:  from all lookup 253 
[dev/9.0/V3_1-RH@macho(115) ipv4]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
10.3.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth1
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         10.3.1.3        0.0.0.0         UG    0      0        0 eth0
[dev/9.0/V3_1-RH@macho(115) ipv4]# ip route show table rlm
default dev relay  scope link 
[dev/9.0/V3_1-RH@macho(115) ipv4]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0B:AB:07:CE:23  
          inet addr:10.3.30.115  Bcast:10.3.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:333228 errors:32 dropped:0 overruns:0 frame:32
          TX packets:207739 errors:0 dropped:0 overruns:0 carrier:0
          collisions:3968 txqueuelen:1000 
          RX bytes:42179686 (40.2 Mb)  TX bytes:39108537 (37.2 Mb)
          Interrupt:11 Base address:0xc000 Memory:fc020000-fc020038 

eth0:1    Link encap:Ethernet  HWaddr 00:0B:AB:07:CE:23  
          inet addr:172.16.0.20  Bcast:172.16.255.255  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:11 Base address:0xc000 Memory:fc020000-fc020038 

eth0:18   Link encap:Ethernet  HWaddr 00:0B:AB:07:CE:23  
          inet addr:10.3.30.115  Bcast:255.255.255.255  Mask:0.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:11 Base address:0xc000 Memory:fc020000-fc020038 

eth1      Link encap:Ethernet  HWaddr 00:0B:AB:07:CE:22  
          inet addr:192.168.0.10  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:50 errors:0 dropped:0 overruns:0 frame:0
          TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8336 (8.1 Kb)  TX bytes:7357 (7.1 Kb)
          Interrupt:10 Base address:0xc400 Memory:fc021000-fc021038 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:26658 errors:0 dropped:0 overruns:0 frame:0
          TX packets:26658 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1561321 (1.4 Mb)  TX bytes:1561321 (1.4 Mb)

pppot     Link encap:Point-to-Point Protocol  
          POINTOPOINT NOARP MULTICAST  MTU:1472  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

relay     Link encap:Point-to-Point Protocol  
          inet addr:221.221.1.1  P-t-P:221.221.1.1  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1464  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

eth0:1 and eth0:18 are required for some redundancy purposes.

<output>
Message from syslogd@macho at Wed Nov  2 22:06:56 2005 ...
macho kernel: inquiry for dst:0x425ee620 src:0x0a510f6c failed<0>inquiry for dst:0x425ee620 src:0x00000000 succeeded nh : 0x0a030103 ifnum  2
</output>

[X.] Other notes, patches, fixes, workarounds:
If I add an ip rule to do destination based routing, the ip_route_output() gives
correct output when no src ip address is specified as parameter. If src ip
address is specified, it still returns an error.

[dev/9.0/V3_1-RH@macho(115) relay]# ip rule add to  66.94.230.32 lookup rlm
[dev/9.0/V3_1-RH@macho(115) relay]# ip route flush cache
[dev/9.0/V3_1-RH@macho(115) relay]# ip rule list
0:      from all lookup local 
32763:  from all to 66.94.230.32 lookup rlm 
32764:  from 10.81.15.108 lookup rlm 
32765:  from all fwmark 0x3 lookup rlm 
32766:  from all lookup main 
32767:  from all lookup 253 

Note the ifnum is 7 in this case when no src ip address is specified.
<output>
Message from syslogd@macho at Wed Nov  2 22:08:05 2005 ...
macho kernel: inquiry for dst:0x425ee620 src:0x0a510f6c failed<0>inquiry for dst:0x425ee620 src:0x00000000 succeeded nh : 0x425ee620 ifnum  7
</output>
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux