| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Will setup netns $1 so that traffic from ifa is routed with a default route to gateway b on ifb |
| 4 |
# and traffic from ifb is routed with a default route to gateway a on ifa. |
| 5 |
# |
| 6 |
# Example use: setup-cross-routing mynetns eth_left 100.0.0.254 eth_right 200.0.0.254 |
| 7 |
# |
| 8 |
|
| 9 |
netns=$1 |
| 10 |
if_a=$2 |
| 11 |
gw_a=$3 |
| 12 |
if_b=$4 |
| 13 |
gw_b=$5 |
| 14 |
|
| 15 |
table_to_a=11 |
| 16 |
table_to_b=12 |
| 17 |
|
| 18 |
exec="ip netns exec $netns" |
| 19 |
|
| 20 |
echo "Setting up cross-routing in $netns between $if_a/$gw_a and $if_b/$gw_b" |
| 21 |
|
| 22 |
$exec ip route add table $table_to_a default via $gw_a dev $if_a |
| 23 |
$exec ip route add table $table_to_b default via $gw_b dev $if_b |
| 24 |
|
| 25 |
$exec ip rule add iif $if_a table $table_to_b prio 1000 |
| 26 |
$exec ip rule add iif $if_b table $table_to_a prio 1000 |
| 27 |
|
| 28 |
for if_ in $if_a $if_b; do |
| 29 |
$exec sysctl -w "net.ipv4.conf.${if_}.forwarding=1" |
| 30 |
done |
| 31 |
|
| 32 |
|