I'm trying to generate Ip-traffic for testing purproses. As we now are
testing multipoint performance of PLC networks I need some 4 to 8
endpoints to communicate but I can't afford to set up a dedicated
linux box for each endpoint.
After looking into kernel routing I found that the routing of packets
can also depend of the incoming device. So basically I tried to set up
a routing which send out any packet generated on this host to an
external interface even if the IP address is assigned to interface
attached on this host.
Here is my solution:
---------------
clapham:~# ip addr show
4: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000
link/ether 00:50:8b:b2:47:fb brd ff:ff:ff:ff:ff:ff
inet 10.0.1.1/24 brd 10.0.1.255 scope global eth1
inet6 fe80::250:8bff:feb2:47fb/64 scope link
valid_lft forever preferred_lft forever
5: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000
link/ether 00:50:8b:b2:47:fc brd ff:ff:ff:ff:ff:ff
inet 10.0.1.11/24 brd 10.0.1.255 scope global eth2
inet6 fe80::250:8bff:feb2:47fc/64 scope link
valid_lft forever preferred_lft forever
--------------
I will try to run traffic from eth1 to eth2. Here is my batch file to
modify the routing:
--------------
clapham:~# cat setnetix
# add routing policy if packet generated on host
ip rule add to 10.0.1.0/24 iif lo table ixchariot
# if all packets generated on host are sent out on the other interface
ip route add 10.0.1.11 table ixchariot dev eth1 src 10.0.1.1 proto
ixchariot
ip route add 10.0.1.1 table ixchariot dev eth2 src 10.0.1.11 proto
ixchariot
# routes in table local are always processed - delete the routes
# making local delivery of the packets with the interface ip address
ip route del local 10.0.1.1 table local
ip route del local 10.0.1.11 table local
# add local delivery route for the packets coming from outside
# basically it's moving the routes deleted above from table local to
table main
ip route add local 10.0.1.1 dev eth1 proto kernel table main
ip route add local 10.0.1.11 dev eth2 proto kernel table main
---------------
I have added the table "ixchariot" into \etc\iproute2\rt_tables with
the ID 7 and the protocol "ixchariot" into \etc\iproute2\rt_protos
with the ID 77.
My routing policy seems O.K.:
---------------
clapham:~# ip rule show
0: from all lookup local
32765: from all to 10.0.1.0/24 iif lo lookup ixchariot
32766: from all lookup main
32767: from all lookup default
---------------
The main table seems O.K.:
---------------
clapham:~# ip route show table main
local 10.0.1.11 dev eth2 proto kernel scope host
local 10.0.1.1 dev eth1 proto kernel scope host
192.168.178.0/24 dev eth0 proto kernel scope link src
192.168.178.98
10.0.1.0/24 dev eth1 proto kernel scope link src 10.0.1.1
10.0.1.0/24 dev eth2 proto kernel scope link src 10.0.1.11
default via 192.168.178.254 dev eth0
---------------
But it does't work:
---------------
clapham:~# ping 10.0.1.1
connect: Invalid argument
clapham:~# ping 10.0.1.11
connect: Invalid argument
clapham:~# ping 192.168.178.98
PING 192.168.178.98 (192.168.178.98) 56(84) bytes of data.
64 bytes from 192.168.178.98: icmp_seq=1 ttl=64 time=0.132 ms
64 bytes from 192.168.178.98: icmp_seq=2 ttl=64 time=0.047 ms
------------------
the "connect: Invalid argument" message is somewhat disturbing. It
seems like an sytax error in the routing tables. But everything is
O.K. until I delete the routes in the local table. So the first part
af the changes:
-------------
ip rule add to 10.0.1.0/24 iif lo table ixchariot
ip route add 10.0.1.11 table ixchariot dev eth1 src 10.0.1.1 proto
ixchariot
ip route add 10.0.1.1 table ixchariot dev eth2 src 10.0.1.11 proto
ixchariot
ip route add local 10.0.1.1 dev eth1 proto ixchariot scope host src
10.0.1.1 table main
ip route add local 10.0.1.11 dev eth2 proto ixchariot scope host src
10.0.1.11 table main
------------
has no effect on the routing of packets to 10.0.1.1 as the route in
the local table are processed first. I delete the one route in the
local table:
------------
ip route del local 10.0.1.1 table local
-------------
pinging 10.0.1.1 is now partly successful:
-------------
clapham:~# ping 10.0.1.1
PING 10.0.1.1 (10.0.1.1) 56(84) bytes of data.
From 10.0.1.11 icmp_seq=1 Destination Host Unreachable
From 10.0.1.11 icmp_seq=2 Destination Host Unreachable
-----------
the packets are sent out on the other interface eth2 as the "From
10.0.1.11" tells - just as intended. Both interfaces are connected to
the same switch. But the packet is not recognized as local entering
eth1.
If I delete the other route in the local table I get the strange error
message again:
----------
clapham:~# ip route del local 10.0.1.11 table local
clapham:~# ping 10.0.1.1
connect: Invalid argument
clapham:~# ping 10.0.1.11
connect: Invalid argument
--------------
it seems that the following lines in table main:
--------------
local 10.0.1.11 dev eth2 proto ixchariot scope host src 10.0.1.11
local 10.0.1.1 dev eth1 proto ixchariot scope host src 10.0.1.1
--------------
have not the same effect as the deleted lines from table local:
--------------
local 10.0.1.11 dev eth2 proto kernel scope host src 10.0.1.11
local 10.0.1.1 dev eth1 proto kernel scope host src 10.0.1.1
-------------
Any hints?
|