# advanced routing problems

## hfish2

hi everyone

i have a problem that is making me crazy

i have a pc with four real nics, eth0 through eth3.

eth0 is in subnet 10.0.0.0/24

eth1 is in subnet 10.0.1.0/24

eth2 is in subnet 10.0.2.0/24

eth3 is in subnet 10.0.3.0/24

eth1 and eth2 are directly connected by a router that does his job and keeps track of "some useful information", i.e. it is pretty useless but it needs to stay there and i cannot move it from there

what i need is traffic from eth0 to flow through eth1, eth2 and eth3, regardless the destination address. i want also traffic coming from eth3 to travel through eth2, eth1 and finally eth0

simpler... all traffic coming from eth0 should go on eth1, all traffic coming from eth2 should go on eth3, all traffic coming from eth3 should go on eth2, and all traffic coming from eth1 should go on eth0

how can i do that? i tried ip route add 10.0.3.0/24 via 10.0.1.x dev eth1, but the traffic coming from eth0 and directed to eth3 doesn't follow the flow i want, but is directly delivered to eth3

thanks in advance

luca

----------

## Hu

You might be able to do this by bridging the interfaces, but this seems like a very inefficient way to handle traffic.  Could you explain why you want to do this?

----------

## hfish2

eth1 and eth0 are not real card... they are tap interfaces offered by a net simulation program. i need the machine to act like a trasparent proxy so i can test a client/server application in lots of conditions, i.e. i can simulate an arbitrary number of nodes, delay, error rate, etc...

----------

## Hu

Do you need it to be a transparent proxy or do you only need it to route the traffic without terminating the TCP connections locally?  Those are different requests, and this would be easier if you can act as a router instead of a bridge.

----------

## hfish2

my bad.

i need all traffic coming from eth0 be redirected on eth1, no matter what

idem, i need all traffic coming from eth2 be routed through eth3

is that feasible?

----------

## Hu

If you can act as a router instead of a bridge, then this could probably be done with policy based routing.  If you must act as a bridge, then I do not know if this can be done.

----------

## AngelKnight

Give the post a read: http://article.gmane.org/gmane.linux.network/146810

Note that this *is* a while ago... though I don't think that queueing disciplines have changed much, it's possible this feature doesn't exist anymore, or exists under a different qdisc name.

(Edit: correct a thinko)

----------

## hfish2

i'll have a look, thanks

----------

## malern

Depending on your throughput requirements you might be able to do what you want with net-misc/vde.

Run vde_switch in hub mode to create a virtual hub, then "plug" all your interfaces into it. That should cause all traffic coming in one interface to be sent to all the others. That might be a bit more than you want, but I think you should be able to use netfilter to block the traffic you don't want.

----------

## hfish2

i don't think i have understood what you're saying... can you please explain a little bit more?

thanks

----------

## malern

Sure, net-misc/vde is a set of tools for creating virtual ethernet devices (switches, hubs, etc). It comes with a program called vde_switch. If you run "vde_switch -hub" you create a virtual hub. You can then virtually plug your interfaces into the hub by running "vde_plug2tap <interface>" (you said your interfaces are actually tap devices, so I believe this should work). Once you have that setup then any traffic coming into your interfaces will be sent to the virtual hub. The hub will then send that traffic out to all the other connected interfaces.

So anything coming in on eth0 will go out to eth1, eth2 and eth3. And anything coming in on eth3 will go out to eth0, eth1 and eth2. Which I'm assuming is what you wanted. The only issue is stuff coming in on eth1 will also go to eth0, eth2 and eth3 (and eth2 will go to eth0, the1 and eth3) as you'd expect with a hub setup. Not sure if this is a problem for you, but if it is you can probably block the unwanted traffic with some iptables rules.

The other thing to note is the vde_switch program runs in userspace so it won't be as efficient as in-kernel routing. Therefore the amount of data you can send per second through a system like this will be lower than a kernel solution. Whether this is a problem depends on how much throughput you need and how powerful your hardware is.

----------

## hfish2

definetely clearer, thanks!

i'll try  :Smile: 

----------

