3 # rrqnet helper script for establishing a rule based route table for a
4 # given interface with given IP with default route to given gateway IP
5 # on the interface link.
10 # This will retry every second until the setup is successful. Should
11 # be spawned in a conf file, eg:
12 # /etc/rrqnet/set-source-route.sh $TAP $IP $GW > /dev/null 2>&1 &
20 function set-source-route() {
21 grep -q "$TIX $TAP" /etc/iproute2/rt_tables || \
22 echo "$TIX $TAP" >> /etc/iproute2/rt_tables
23 if [ -z "$(ip rule list from ${IP%/*})" ] ; then
24 ip rule add from ${IP%/*} lookup $TAP || return 1
26 if [ -z "$(ip route show table $TAP | grep ^$GW)" ] ; then
27 ip route add $GW dev $TAP scope link src ${IP%/*} table $TAP || \
30 if [ -z "$(ip route show table $TAP | grep default)" ] ; then
31 ip route add default via $GW dev $TAP table $TAP || return 1
33 ip route show table $TAP
36 set-source-route && exit 0