From 49bfe6a28c92c377a3c5227b0b6bd45053c18cef Mon Sep 17 00:00:00 2001 Message-Id: <49bfe6a28c92c377a3c5227b0b6bd45053c18cef.1713262624.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 14 Mar 2015 14:39:42 +0000 Subject: [PATCH] svc/tripe-ifup.in: Better error handling. Organization: Straylight/Edgeware From: Mark Wooding 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 | 15 ++++++++++++++- svc/tripe-ifup.in | 33 ++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/svc/tripe-ifup.8.in b/svc/tripe-ifup.8.in index 2b500412..f9a783cc 100644 --- a/svc/tripe-ifup.8.in +++ b/svc/tripe-ifup.8.in @@ -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 . .\"-------------------------------------------------------------------------- diff --git a/svc/tripe-ifup.in b/svc/tripe-ifup.in index ae447db8..e92c0fd5 100644 --- a/svc/tripe-ifup.in +++ b/svc/tripe-ifup.in @@ -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 -------------------------------------------------- -- [mdw]