chiark / gitweb /
svc/tripe-ifup.in: Better error handling.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 14 Mar 2015 14:39:42 +0000 (14:39 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 14 Mar 2015 14:48:41 +0000 (14:48 +0000)
Don't give up as soon as a network configuration command fails.  That
tends to leave the device's routing in a hopelessly broken state.
Instead, catch errors, report them via the server, and issue a slightly
different notification on completion.

svc/tripe-ifup.8.in
svc/tripe-ifup.in

index 2b500412aeba6a344776d637b5daa95c93f67d9e..f9a783cc771a9aa9a73ac57cb1318d359cddc205 100644 (file)
@@ -125,6 +125,16 @@ the link, over the tunnel interface.  The
 may be IPv4 or IPv6 addresses.  If the interface has only an IPv4
 address then IPv6 routes will be ignored, and
 .IR "vice versa" .
+.RS
+.PP
+If any configuration commands fail, a warning
+.IP
+.B USER tripe-ifup command-failed
+.BI rc= rc
+.I command
+.PP
+is issued.
+.RE
 .hP 4.
 Configure the interface MTU and bring it up.  The
 interface MTU is configured based on the path MTU to the peer's external
@@ -143,8 +153,11 @@ Notify services.  A notification
 .IP
 .B USER tripe-ifup configured
 .I peer
+.RB [ failed ]
 .PP
-is issued.
+is issued: the
+.B failed
+token is included if any of the configuration commands failed.
 .RE
 .
 .\"--------------------------------------------------------------------------
index ae447db8561b542ac4207a5d6a35f0cbc5ec78f1..e92c0fd553baa8149245c6d3d03f328ec5fe8160 100644 (file)
@@ -24,6 +24,18 @@ export PATH TRIPEDIR
 ## Determine whether we have IPv6 support.
 if [ -d /proc/sys/net/ipv6 ]; then have6=t; else have6=nil; fi
 
+###--------------------------------------------------------------------------
+### Error handling.
+
+win=t
+try () {
+  if "$@"; then :; else
+    rc=$?
+    tripectl warn tripe-ifup command-failed rc=$rc "$*"
+    win=nil
+  fi
+}
+
 ###--------------------------------------------------------------------------
 ### Collect arguments.
 
@@ -46,7 +58,7 @@ esac
 
 case "${P_IFNAME+set}" in
   set)
-    ip link set "$ifname" name "$P_IFNAME"
+    try ip link set "$ifname" name "$P_IFNAME"
     ifname=$P_IFNAME
     $tripectl setifname "$peer" "$ifname"
     ;;
@@ -80,13 +92,13 @@ haveaddr4=nil
 set -- $l4addr
 case $#,${r4addr+set} in
   [1-9]*,set)
-    ip addr add "$1" peer "$r4addr" dev "$ifname"
+    try ip addr add "$1" peer "$r4addr" dev "$ifname"
     haveaddr4=t
     shift
     ;;
 esac
 for a in "$@"; do
-  ip addr add "$a" dev "$ifname"
+  try ip addr add "$a" dev "$ifname"
   haveaddr4=t
 done
 
@@ -97,11 +109,11 @@ set -- $l6addr
 case $have6,$# in
   t,[1-9]*)
     for a in "$@"; do
-      ip addr add "$a" dev "$ifname"
+      try ip addr add "$a" dev "$ifname"
       haveaddr6=t
     done
     case ${r6addr+set} in
-      set) ip route add $r6addr proto static dev "$ifname" ;;
+      set) try ip route add $r6addr proto static dev "$ifname" ;;
     esac
     ;;
 esac
@@ -121,7 +133,7 @@ case $haveaddr4,$haveaddr6 in
        mtu=$(expr "$pathmtu" - 29 - $A_BULK_OVERHEAD)
        ;;
     esac
-    ip link set dev "$ifname" up mtu "$mtu"
+    try ip link set dev "$ifname" up mtu "$mtu"
     ;;
 esac
 
@@ -142,7 +154,7 @@ set -- $route4
 case $haveaddr4,$# in
   t,[1-9]*)
     for p in "$@"; do
-      ip route add $p proto static via "$r4addr"
+      try ip route add $p proto static via "$r4addr"
     done
     ;;
 esac
@@ -152,7 +164,7 @@ set -- $route6
 case $haveaddr6,$# in
   t,[1-9]*)
     for p in "$@"; do
-      ip route add $p proto static via "${r6addr%/*}"
+      try ip route add $p proto static via "${r6addr%/*}"
     done
     ;;
 esac
@@ -169,6 +181,9 @@ esac
 ###--------------------------------------------------------------------------
 ### Issue a notification that we've won.
 
-$tripectl notify tripe-ifup configured "$peer"
+case $win in
+  t) $tripectl notify tripe-ifup configured "$peer" ;;
+  nil) $tripectl notify tripe-ifup configured "$peer" failed ;;
+esac
 
 ###----- That's all, folks --------------------------------------------------