]> www.infradead.org Git - users/dwmw2/vpnc-scripts.git/commitdiff
fix another ifconfig syntax difference between Linux and *BSDs
authorDaniel Lenski <dlenski@gmail.com>
Tue, 8 Dec 2020 07:31:50 +0000 (23:31 -0800)
committerDaniel Lenski <dlenski@gmail.com>
Mon, 14 Dec 2020 17:45:05 +0000 (09:45 -0800)
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 <dlenski@gmail.com>
vpnc-script

index a2bf4a09a1b1fee5de0a9a0ad0bba705634ecd15..984eb5f6d93b437798f9a4ca5ba8a19978465f6e 100755 (executable)
@@ -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