From c8fef3b54eb30b3cd89b82cf9bc04afe99db7b82 Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Mon, 7 Dec 2020 23:31:50 -0800 Subject: [PATCH] fix another ifconfig syntax difference between Linux and *BSDs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- vpnc-script | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 -- 2.50.1