From 5637061f6c87649f9433072138ea44ac07e9743e Mon Sep 17 00:00:00 2001 From: Jonathan David Amery Date: Fri, 18 May 2018 18:01:20 +0100 Subject: [PATCH] * We need to add the local network rule as well. * Add ipv4. --- source-route-watch.sh | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/source-route-watch.sh b/source-route-watch.sh index 3dd0452..b54d650 100755 --- a/source-route-watch.sh +++ b/source-route-watch.sh @@ -9,26 +9,37 @@ do read -t 1 -N 100000 || true # clear stdin for int in $( sed -n '/# local/,$ { /^[^#]/ s/.* // p }' /etc/iproute2/rt_tables ) do - tab=$(ip -6 route list table "$int" | - sed 's/\(dev [^ ]*\) .*/\1/') - def=$(ip -6 route list match default | - sed -n '/dev '"$int"'/ { + for proto in 4 6 + do + tab=$(ip -"$proto" route list table "$int" match default | + sed 's/\(dev [^ ]*\) .*/\1/') + def=$(ip -"$proto" route list match default | + sed -n '/dev '"$int"'/ { s/\(dev [^ ]*\) .*/\1/ p }') - if [ "x$def" != "x$tab" ] - then - ip -6 route del $tab table "$int" || true - ip -6 route add $def table "$int" || true - ip -6 rule del table "$int" || true - ip -6 rule add from $( - ip -6 addr show "$int" scope global | sed -n ' - /inet6/ { - s/.*inet6 // + if [ "x$def" != "x$tab" ] + then + ip -"$proto" route flush table "$int" || true + ip -"$proto" route add $def table "$int" || true + ip -"$proto" route add $( + ip -"$proto" route list proto kernel | + sed -n '/dev '"$int"'/ { + s/\(dev [^ ]*\) .*/\1/ + p + q + }' + ) table "$int" || true + ip -"$proto" rule del table "$int" || true + ip -"$proto" rule add from $( + ip -"$proto" addr show "$int" scope global | sed -n ' + /inet/ { + s/.*inet[^ ]* // s/ .*// p }') table "$int" - fi + fi + done done done ) -- 2.30.2