chiark / gitweb /
* We need to add the local network rule as well. master
authorJonathan David Amery <jdamery@dorothee.ysolde.ucam.org>
Fri, 18 May 2018 17:01:20 +0000 (18:01 +0100)
committerJonathan David Amery <jdamery@dorothee.ysolde.ucam.org>
Fri, 18 May 2018 17:01:20 +0000 (18:01 +0100)
* Add ipv4.

source-route-watch.sh

index 3dd0452a8b8117424fbf5a78bba6a1b8a5890e3b..b54d6508b1a012469c16b46bcc2e68ec2fd68446 100755 (executable)
@@ -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
     )