From: Daniel Lenski Date: Tue, 8 Dec 2020 07:31:50 +0000 (-0800) Subject: fix another ifconfig syntax difference between Linux and *BSDs X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c8fef3b54eb30b3cd89b82cf9bc04afe99db7b82;p=users%2Fdwmw2%2Fvpnc-scripts.git fix another ifconfig syntax difference between Linux and *BSDs See https://gitlab.com/openconnect/vpnc-scripts/-/merge_requests/9#note_466328301 : > Thanks. I don't know how this one was missed; the [FreeBSD man > page](https://www.freebsd.org/cgi/man.cgi?ifconfig) and [macOS man > page](https://ss64.com/osx/ifconfig.html) clearly show that `delete` has > to come _after_ the address. > > However, Linux's ifconfig [requires `del` to come > before](https://linux.die.net/man/8/ifconfig), and _only_ works for > removing IPv6 addresses… so this needs to be reworked a bit to not break > on Linux. Signed-off-by: Daniel Lenski --- diff --git a/vpnc-script b/vpnc-script index a2bf4a0..984eb5f 100755 --- a/vpnc-script +++ b/vpnc-script @@ -111,7 +111,7 @@ if [ "$OS" = "Linux" ]; then route_syntax_inet6_host="-6" route_syntax_inet6_net="-6" ifconfig_syntax_add_inet6="add" - ifconfig_syntax_del="del" + ifconfig_syntax_del() { case "$1" in *:*) echo del "$1" ;; *) echo 0.0.0.0 ;; esac; } netstat_syntax_ipv6="-6" else # iproute2 is Linux only; if `which ip` returns something on another OS, it's likely an unrelated tool @@ -124,7 +124,7 @@ else route_syntax_inet6="-inet6" route_syntax_inet6_host="-inet6 -host" route_syntax_inet6_net="-inet6 -net" - ifconfig_syntax_del="delete" + ifconfig_syntax_del() { case "$1" in *:*) echo inet6 "$1" delete ;; *) echo "$1" delete ;; esac; } ifconfig_syntax_add_inet6="inet6" netstat_syntax_ipv6="-f inet6" fi @@ -1107,13 +1107,13 @@ do_disconnect() { fi else if [ -n "$INTERNAL_IP4_ADDRESS" ]; then - ifconfig "$TUNDEV" 0.0.0.0 + ifconfig "$TUNDEV" `ifconfig_syntax_del "$INTERNAL_IP4_ADDRESS"` fi if [ -n "$INTERNAL_IP6_ADDRESS" ] && [ -z "$INTERNAL_IP6_NETMASK" ]; then INTERNAL_IP6_NETMASK="$INTERNAL_IP6_ADDRESS/128" fi if [ -n "$INTERNAL_IP6_NETMASK" ]; then - ifconfig "$TUNDEV" inet6 $ifconfig_syntax_del $INTERNAL_IP6_NETMASK + ifconfig "$TUNDEV" `ifconfig_syntax_del "$INTERNAL_IP6_NETMASK"` fi fi