]> git.infradead.org Git - users/dwmw2/vpnc-scripts.git/log
users/dwmw2/vpnc-scripts.git
2 years agoRemoved automatic adding of NS routes master
Heiko Schabert [Fri, 6 May 2022 12:08:32 +0000 (14:08 +0200)]
Removed automatic adding of NS routes

With openconnect version 9.01 include-split was modified, in a way that
a announced route with netwask 0.0.0.0 will leverage env variable `CISCO_SPLIT_INC`.

Entries inside `CISCO_SPLIT_INC`, always causes that routes to the NS
`INTERNAL_IP4_DNS` are created.

This commit, removes that NS routes are automatically are added.

The same mechanism applies to IP6 as well, which uses
env variable `CISCO_IPV6_SPLIT_INC`

Resolves #38. Alignment with behaviour of NetworkManager openconnect
see [1].

[1] https://gitlab.gnome.org/GNOME/NetworkManager-openconnect/-/blob/main/src/nm-openconnect-service-openconnect-helper.c

Signed-off-by: Heiko Schabert <heiko.schabert@siemens.com>
2 years agoMerge branch 'obs' into 'master'
David Woodhouse [Sat, 16 Apr 2022 14:44:15 +0000 (14:44 +0000)]
Merge branch 'obs' into 'master'

Add configuration for OBS workflow

See merge request openconnect/vpnc-scripts!48

2 years agoMerge branch 'sshd' into 'master'
David Woodhouse [Sat, 16 Apr 2022 14:43:05 +0000 (14:43 +0000)]
Merge branch 'sshd' into 'master'

vpnc-script-sshd: use ip link peer name syntax

See merge request openconnect/vpnc-scripts!47

2 years agoAdd configuration for OBS workflow
Luca Boccassi [Sat, 16 Apr 2022 10:27:29 +0000 (12:27 +0200)]
Add configuration for OBS workflow

Signed-off-by: Luca Boccassi <bluca@debian.org>
2 years agoAdd RPM packaging for OBS workflow
Luca Boccassi [Sat, 16 Apr 2022 10:37:09 +0000 (12:37 +0200)]
Add RPM packaging for OBS workflow

Signed-off-by: Luca Boccassi <bluca@debian.org>
2 years agoAdd Debian packaging for OBS workflow
Luca Boccassi [Sat, 16 Apr 2022 10:27:13 +0000 (12:27 +0200)]
Add Debian packaging for OBS workflow

Signed-off-by: Luca Boccassi <bluca@debian.org>
2 years agovpnc-script-sshd: use ip link peer name syntax
Luca Boccassi [Sat, 5 Mar 2022 15:41:48 +0000 (15:41 +0000)]
vpnc-script-sshd: use ip link peer name syntax

iproute2 since at least v4.20 supports specifying local and remote
peer names. Use that instead of guessing. Support older iproute2
versions by falling back to guessing.

Reported-by: Karl O. Pinc <kop@karlpinc.com>
Signed-off-by: Luca Boccassi <bluca@debian.org>
2 years agoMerge branch 'detect-systemd-resolvectl' into 'master'
Luca Boccassi [Sat, 5 Mar 2022 15:24:43 +0000 (15:24 +0000)]
Merge branch 'detect-systemd-resolvectl' into 'master'

vpnc-script: Detect systemd with resolvectl status

See merge request openconnect/vpnc-scripts!38

2 years agoCleanup error status in vpnc-script-win.js
Dimitri Papadopoulos [Sat, 1 Jan 2022 16:40:46 +0000 (17:40 +0100)]
Cleanup error status in vpnc-script-win.js

Either semicolon or parentheses

The current error message is:
"..." returned non-zero exit status: 1)

It should be either:
        "..." returned non-zero exit status (1)
or:
        "..." returned non-zero exit status: 1

I chose the latter.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
2 years agoMerge branch 'various_improvements' into 'master'
Daniel Lenski [Mon, 24 Jan 2022 19:33:17 +0000 (19:33 +0000)]
Merge branch 'various_improvements' into 'master'

Various improvements to vpnc-script-win.js

Closes openconnect#375

See merge request openconnect/vpnc-scripts!45

2 years agoUpdate copyright/origin notices in scripts
Daniel Lenski [Mon, 24 Jan 2022 01:19:10 +0000 (17:19 -0800)]
Update copyright/origin notices in scripts

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
2 years agoOn newer versions of Windows, need `validate=no` when adding DNS servers
Daniel Lenski [Sat, 22 Jan 2022 21:48:16 +0000 (13:48 -0800)]
On newer versions of Windows, need `validate=no` when adding DNS servers

This should fix https://gitlab.com/openconnect/openconnect/-/issues/375.
It appears that on newer Windows systems, `netsh interface ipvX add dns` can
take a long time to run, over 10 seconds. (See
https://gitlab.com/openconnect/openconnect/-/issues/375#note_818616048 for
examples.)

This appears to be because of unwanted network I/O. Specifically, unless
`validate=no` is specified, Windows will try to immediately connect to the
server. Because OpenConnect is not yet exchanging packets over the tunnel
when the vpnc-script is invoked, and hasn't even added IP *routes* for the
tunnel yet, this connection cannot succeed in most configurations. If it
can't connect:

1. It times out after ~10 seconds.
2. It prints a warning: "The configured DNS server is incorrect or does not exist."
3. It nevertheless adds the specified DNS server for the interface.
4. It returns success (exit status 0).

This combination of effects explains why we weren't detecting and displaying
the error.

The `validate` option appears to be poorly documented; it appears in the help
output of `netsh interface ipvX add dns` on Windows 10, but it doesn't
appear in Microsoft's web documentation of `netsh interface ipvX add dns`
for Windows 2008
(https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-r2-and-2008/cc731521(v=ws.10)#add-dnsserver),
which is what their "netsh overview" documentation for Windows 2012
(https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/jj129394(v=ws.11))
refers readers to for comprehensive information.

Furthermore, the `validate` option does not exist on older versions of
Windows, but it's *enabled by default* on Windows 10. This means that
we have to be sure to append `validate=no` on newer versions of Windows,
but *not* to append it on older version.

Bang-up job as usual, Microsoft. 🤬

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
2 years agoBetter ordering, more logging, and disconnect handler fixes on Windows
Daniel Lenski [Sat, 22 Jan 2022 20:58:55 +0000 (12:58 -0800)]
Better ordering, more logging, and disconnect handler fixes on Windows

Set up the explicit route to the VPN gateway before configuring *anything else*,
and include default/Internet-facing gateway in the logging output.

Fixed a couple issues in the 'disconnect' handler.  We missed these until
now because the 'disconnect' handler was *never being run on Windows* due to
https://gitlab.com/openconnect/openconnect/-/issues/362, until this was
fixed in https://gitlab.com/openconnect/openconnect/-/merge_requests/323

1. Need to specify 'store=active' when deleting an IPv6 address on disconnect
   (missed this in 3a11fc7c971a28e375cc1fb2defe9d829aed2a4f)
2. Put some logging on the 'disconnect' handler.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
2 years agoAdd logLevel and logTimestamps options to vpnc-script-win.js
Daniel Lenski [Sat, 22 Jan 2022 20:52:35 +0000 (12:52 -0800)]
Add logLevel and logTimestamps options to vpnc-script-win.js

Based on discussions about how to improve vpnc-script logging in
https://gitlab.com/openconnect/vpnc-scripts/-/issues/32#note_810779624.

See https://gitlab.com/openconnect/openconnect/-/merge_requests/328,
which makes OpenConnect send its verbosity level to the vpnc-script
as $LOG_LEVEL.

In the future, $LOG_TIMESTAMPS should probably also be passed by
OpenConnect, although this may be unnecessary since most OS's logging
systems can add timestamps on their own.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
2 years agoRemove unnecessary quotes around numeric interface identifier (TUNIDX) in vpnc-script...
Daniel Lenski [Sat, 22 Jan 2022 20:54:13 +0000 (12:54 -0800)]
Remove unnecessary quotes around numeric interface identifier (TUNIDX) in vpnc-script-win.js

Missed these in 6a78d3c703103afacd64c908597aa442e2e96ad5.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
2 years agovpnc-script-win.js: replace incorrect exec() call with run()
Tim De Baets [Wed, 12 Jan 2022 20:36:25 +0000 (21:36 +0100)]
vpnc-script-win.js: replace incorrect exec() call with run()

Signed-off-by: Tim De Baets <10608063-tdebaets@users.noreply.gitlab.com>
2 years agoMerge branch 'always_use_INTERNAL_IP4_ADDRESS_as_gateway_on_Windows' into 'master'
Daniel Lenski [Wed, 1 Dec 2021 19:59:32 +0000 (19:59 +0000)]
Merge branch 'always_use_INTERNAL_IP4_ADDRESS_as_gateway_on_Windows' into 'master'

Always use INTERNAL_IP4_ADDRESS as "gateway" on Windows

Closes #30

See merge request openconnect/vpnc-scripts!41

2 years agoAlways use INTERNAL_IP4_ADDRESS as "gateway" on Windows
Daniel Lenski [Tue, 30 Nov 2021 18:06:44 +0000 (10:06 -0800)]
Always use INTERNAL_IP4_ADDRESS as "gateway" on Windows

It appears that Windows's 'netsh' utility doesn't like the VPN interface
having a "gateway" address of 0.0.0.1, which is what vpnc-script-win.js
would attempt to use if INTERNAL_IP4_NETMASK is /0.  See
https://gitlab.com/openconnect/openconnect/-/merge_requests/306#note_745139972.

As noted in the OpenConnect source, "It's a tunnel; having a gateway is
meaningless."

Setting the "gateway" address for Windows to match INTERNAL_IP4_ADDRESS
seems like the simplest way to make 'netsh' configure routingly correctly in
all cases, including when the INTERNAL_IP4_NETMASK is either /0 or /32.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
2 years agoSupport for OpenBSD's resolvd via route messages
Andrew Hewus Fresh [Sat, 30 Oct 2021 19:10:06 +0000 (12:10 -0700)]
Support for OpenBSD's resolvd via route messages

This adds support for managing resolv.conf via resolvd(8),
by sending nameserver messages with route(8) to add and
remove nameservers.

https://man.openbsd.org/resolvd.8
https://man.openbsd.org/route.8#nameserver

2 years agovpnc-script: Detect systemd with resolvectl status
Jordan Justen [Mon, 25 Oct 2021 07:54:20 +0000 (00:54 -0700)]
vpnc-script: Detect systemd with resolvectl status

It appears that the "resolvectl status" command has been available since:

Ref: https://github.com/systemd/systemd/commit/c2e84cab3afb09e726be40ce80b6ce6129c8af32
Ref: https://github.com/systemd/systemd/commit/a7a4c60a253a181385764bcb542906a312b68fe9

which was first released in systemd v239 from June 2018.

systemd-resolve is usually symlinked to resolvectl, but it appears to
be deprecated. This change will still fallback to trying
systemd-resolve if resolvectl fails.

Signed-off-by: Jordan Justen <jljusten@gmail.com>
2 years agoAnother bugfix when determining the controlling PID
Daniel Lenski [Wed, 17 Nov 2021 19:34:00 +0000 (19:34 +0000)]
Another bugfix when determining the controlling PID

In 596d947a ("Use $VPNPID when provided by OpenConnect"), I inadvertently
included an extra space, which entirely defeated the purpose of checking
if this variable is empty.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
2 years agoMerge branch 'command-grep-portability' into 'master'
Daniel Lenski [Sun, 14 Nov 2021 17:41:57 +0000 (17:41 +0000)]
Merge branch 'command-grep-portability' into 'master'

command/which and grep portability improvements

See merge request openconnect/vpnc-scripts!40

2 years agoUse `type -P` instead of `command -v` in tests/ bash scripts
Ville Skyttä [Sun, 14 Nov 2021 09:18:43 +0000 (11:18 +0200)]
Use `type -P` instead of `command -v` in tests/ bash scripts

The output of `command -v` is not helpful for our purposes for aliases.
`type -P` works, and unportability of `-P` is not a problem in bash
scripts.

2 years agoUse `grep -E` instead of `egrep`
Ville Skyttä [Fri, 12 Nov 2021 22:06:22 +0000 (00:06 +0200)]
Use `grep -E` instead of `egrep`

`egrep` has been deprecated in GNU grep since 2007, and in current
post 3.7 Git it has been made to emit obsolescence warnings:
https://git.savannah.gnu.org/cgit/grep.git/commit/?id=a9515624709865d480e3142fd959bccd1c9372d1

2 years agoUse `command -v` instead of `which`
Ville Skyttä [Fri, 12 Nov 2021 21:47:56 +0000 (23:47 +0200)]
Use `command -v` instead of `which`

`which` is not standard and might not be installed, whereas `command -v`
is in POSIX and its predecessor specs at least since 1994,
specified to produce no output when the arg command is not found.
https://pubs.opengroup.org/onlinepubs/7908799/xcu/command.html

`which` is also deprecated in Debian's debianutils 5.0+ and emits a
warning when used. At the moment, 5.0+ is only in Debian unstable, and
there is no other package in it providing `which`.
https://salsa.debian.org/debian/debianutils/-/commit/3a8dd10b4502f7bae8fc6973c13ce23fc9da7efb

3 years agoEnsure that vpnc-script-win.js works even if INTERNAL_IP4_{NETADDR,NETMASK} are unset
Daniel Lenski [Fri, 24 Sep 2021 15:07:00 +0000 (08:07 -0700)]
Ensure that vpnc-script-win.js works even if INTERNAL_IP4_{NETADDR,NETMASK} are unset

Not all protocols supported by OpenConnect consistently set the variables
INTERNAL_IP4_{NETADDR,NETMASK} in all cases.

This should be fixed within OpenConnect itself as part of
https://gitlab.com/openconnect/openconnect/-/merge_requests/215, but in the
meantime (and for older versions of OpenConnect/vpnc) we need to ensure that
vpnc-script-win.js works correctly even when these are unset.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoAdd polyfill for String.prototype.trim in vpnc-script-win.js
Daniel Lenski [Wed, 22 Sep 2021 19:12:00 +0000 (19:12 +0000)]
Add polyfill for String.prototype.trim in vpnc-script-win.js

As noted in https://gitlab.com/openconnect/openconnect/-/issues/312#note_684460541,
Windows Scripting Host's "JScript" does not appear to support
the `String.prototype.trim` method, apparently due to being
based on a very old ECMAScript standard.

The straightforward solution is to use the JavaScript polyfill
described in https://stackoverflow.com/a/35456830.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'typo' into 'master'
Nikos Mavrogiannopoulos [Sat, 18 Sep 2021 17:40:28 +0000 (17:40 +0000)]
Merge branch 'typo' into 'master'

Minor typo

See merge request openconnect/vpnc-scripts!37

3 years agoMinor typo
Dimitri Papadopoulos [Fri, 17 Sep 2021 07:37:31 +0000 (09:37 +0200)]
Minor typo

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
3 years agoFix spacing
Daniel Lenski [Thu, 16 Sep 2021 20:59:40 +0000 (13:59 -0700)]
Fix spacing

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'fix_default_route_restoration' into 'master'
Daniel Lenski [Thu, 16 Sep 2021 20:59:05 +0000 (20:59 +0000)]
Merge branch 'fix_default_route_restoration' into 'master'

Bugfix default route handling by using $VPNPID (or GRANDparent process ID) to uniquely identify connection

Closes #28

See merge request openconnect/vpnc-scripts!36

3 years agoUse $VPNPID when provided by OpenConnect
Daniel Lenski [Thu, 16 Sep 2021 19:56:55 +0000 (12:56 -0700)]
Use $VPNPID when provided by OpenConnect

See https://gitlab.com/openconnect/openconnect/-/merge_requests/278.  Once
merged, OpenConnect will send its PID to the vpnc-script as $VPNPID.  The
vpnc-script should use this in preference to trying to figure out its
grandparent's PID on its own.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoAlso include controlling process identifier in resolv.conf backup path
Daniel Lenski [Thu, 16 Sep 2021 03:02:07 +0000 (20:02 -0700)]
Also include controlling process identifier in resolv.conf backup path

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoBugfix default route handling by using GRANDparent process ID to uniquely identify...
Daniel Lenski [Thu, 16 Sep 2021 03:00:08 +0000 (20:00 -0700)]
Bugfix default route handling by using GRANDparent process ID to uniquely identify connection

In 01d3b8c0, I tried to fix an issue with default route restoration when
multiple "stacked" VPNs were running.  However, this actually caused more
problems than it solved, by breaking default route restoration in the
"usual" case of a single VPN.

The problem is that OpenConnect (and vpnc) always call the vpnc-script via
an intermediary, ephemeral shell process.  So the GRANDparent process ID
must be used to persistently identify the VPN connection between vpnc-script
'connect' and 'disconnect' invocations.

Fixes #28.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'codespell' into 'master'
Daniel Lenski [Mon, 6 Sep 2021 23:14:41 +0000 (23:14 +0000)]
Merge branch 'codespell' into 'master'

Typos found by codespell

See merge request openconnect/vpnc-scripts!35

3 years agoTypos found by codespell
Dimitri Papadopoulos [Sat, 4 Sep 2021 04:45:19 +0000 (07:45 +0300)]
Typos found by codespell

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
3 years agoMerge branch 'Windows_fix_internal_gw_for_255.255.255.255_netmask' into 'master'
Daniel Lenski [Fri, 3 Sep 2021 21:30:52 +0000 (21:30 +0000)]
Merge branch 'Windows_fix_internal_gw_for_255.255.255.255_netmask' into 'master'

Ensure that vpnc-script-win.js picks a legal "internal gateway" address even for /32 netmask

See merge request openconnect/vpnc-scripts!34

3 years agoEnsure that vpnc-script-win.js picks a legal "internal gateway" address even for...
Daniel Lenski [Tue, 31 Aug 2021 21:30:38 +0000 (21:30 +0000)]
Ensure that vpnc-script-win.js picks a legal "internal gateway" address even for /32 netmask

Attempted fix for https://gitlab.com/openconnect/vpnc-scripts/-/issues/26
(formerly https://gitlab.com/openconnect/openconnect/-/issues/306).

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'test_log_typo' into 'master'
Daniel Lenski [Tue, 31 Aug 2021 22:19:36 +0000 (22:19 +0000)]
Merge branch 'test_log_typo' into 'master'

tests: fix error message about missing ocserv

See merge request openconnect/vpnc-scripts!33

3 years agotests: fix error message about missing ocserv
Luca Boccassi [Thu, 19 Aug 2021 14:33:27 +0000 (15:33 +0100)]
tests: fix error message about missing ocserv

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
3 years agoTypos caught by codespell
Dimitri Papadopoulos [Sat, 7 Aug 2021 12:43:39 +0000 (14:43 +0200)]
Typos caught by codespell

Signed-off-by: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com>
3 years agoFix set_vpngateway_route
Daniel Lenski [Wed, 14 Jul 2021 18:51:19 +0000 (11:51 -0700)]
Fix set_vpngateway_route

Should fix #23

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoExclude routes may use a different address family from VPNGATEWAY
Daniel Lenski [Tue, 22 Jun 2021 00:26:47 +0000 (17:26 -0700)]
Exclude routes may use a different address family from VPNGATEWAY

This patch should fix #22, which was caused by a mistake in !28.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'fix_20_for_split_exclude_routes_also' into 'master'
Daniel Lenski [Wed, 14 Apr 2021 18:58:53 +0000 (18:58 +0000)]
Merge branch 'fix_20_for_split_exclude_routes_also' into 'master'

factor out list_non_loopback_routes and use for split-exclude routes as well

See merge request openconnect/vpnc-scripts!28

3 years agofactor out list_non_loopback_routes and use for split-exclude routes as well
Daniel Lenski [Wed, 7 Apr 2021 22:04:41 +0000 (15:04 -0700)]
factor out list_non_loopback_routes and use for split-exclude routes as well

See https://gitlab.com/openconnect/vpnc-scripts/-/issues/20#note_546699195

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agotests: 'route flush' doesn't work properly on Linux'
Daniel Lenski [Sun, 11 Apr 2021 16:37:34 +0000 (09:37 -0700)]
tests: 'route flush' doesn't work properly on Linux'

Need to use `ip route flush` in test scripts as a workaround:

# route flush
Flushing `inet' routing table not supported

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoLinux: fix IPv6 route flushing
Daniel Lenski [Sun, 11 Apr 2021 02:21:20 +0000 (19:21 -0700)]
Linux: fix IPv6 route flushing

Thanks @sledge.ez for pointing this out in https://gitlab.com/openconnect/vpnc-scripts/-/issues/19#note_507409565

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agotest timing: wait up to 10s for OpenConnect client to terminating
Daniel Lenski [Sun, 11 Apr 2021 02:02:26 +0000 (19:02 -0700)]
test timing: wait up to 10s for OpenConnect client to terminating

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agofix syntax error in 64cc6d66
Daniel Lenski [Sun, 11 Apr 2021 01:30:51 +0000 (18:30 -0700)]
fix syntax error in 64cc6d66

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'fix_onlink_routes_and_deduplicate_set_vpngateway_route' into 'master'
Daniel Lenski [Wed, 7 Apr 2021 13:08:51 +0000 (13:08 +0000)]
Merge branch 'fix_onlink_routes_and_deduplicate_set_vpngateway_route' into 'master'

deduplicate set_vpngateway_route

Closes #20

See merge request openconnect/vpnc-scripts!27

3 years agoalways exclude TUNDEV when finding/setting gateway route
Daniel Lenski [Thu, 1 Apr 2021 15:43:12 +0000 (08:43 -0700)]
always exclude TUNDEV when finding/setting gateway route

The previous commit didn't fix #20, because 'ip route get' doesn't preserve the onlink flag.
(See https://gitlab.com/openconnect/vpnc-scripts/-/issues/20#note_542783676)

We should just use the 'ip route show' version across-the-board; it's more complex, but appears
to be quite robus. If we have to use it to get the gateway route correctly, then we simply
remove the redundancy in the code. *BSD code ('route'-based) can be similarly simplified.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agopreserve onlink flag in gateway/exclude routes
Daniel Lenski [Thu, 1 Apr 2021 16:52:19 +0000 (09:52 -0700)]
preserve onlink flag in gateway/exclude routes

Attempting to fix #20

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agofix IPv6 split masklen
Daniel Lenski [Thu, 1 Apr 2021 02:19:10 +0000 (19:19 -0700)]
fix IPv6 split masklen

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'improve_vpnc_script_win_js' into 'master'
Daniel Lenski [Thu, 1 Apr 2021 01:13:05 +0000 (01:13 +0000)]
Merge branch 'improve_vpnc_script_win_js' into 'master'

vpnc-script-win: simplify 'internal gateway' calculation

See merge request openconnect/vpnc-scripts!26

3 years agovpnc-script-win: tidy up, more logging
Daniel Lenski [Wed, 31 Mar 2021 23:56:09 +0000 (16:56 -0700)]
vpnc-script-win: tidy up, more logging

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agovpnc-script-win: make VPN addresses/gateways "non-persistent", and delete them on...
Daniel Lenski [Wed, 31 Mar 2021 23:23:38 +0000 (16:23 -0700)]
vpnc-script-win: make VPN addresses/gateways "non-persistent", and delete them on disconnect

Persisting the state of IPv4 configuration of these interfaces is generally
unhelpful (as with DNS/WINS settings).

Two approaches. We do both:

1. Make the addresses ephemeral ("netsh ... store=active", as opposed to the
   "store=persistent" default). This ensures that the addresses won't last
   past reboot.
2. Delete the addresses upon disconnection.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agovpnc-script-win: delete DNS and WINS servers before adding them
Daniel Lenski [Wed, 31 Mar 2021 21:56:38 +0000 (14:56 -0700)]
vpnc-script-win: delete DNS and WINS servers before adding them

If not, "leftover" servers will persist from previous use of the adapter.

This will result in errors: "The object is already in the list."

And also could be a source of buggy behavior, even security issues,
if the "same" TAP/TUN adapter was used to access a different VPN. 🙊

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agovpnc-script-win: dump stdout and stderr when a command fails
Daniel Lenski [Wed, 31 Mar 2021 21:21:52 +0000 (14:21 -0700)]
vpnc-script-win: dump stdout and stderr when a command fails

Technique borrowed from https://github.com/horar/vpnc-scripts/blob/master/vpnc-script-win.js

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agovpnc-script-win: use TUNIDX in all netsh commands, remove waitForInterface()
Daniel Lenski [Wed, 31 Mar 2021 20:48:58 +0000 (13:48 -0700)]
vpnc-script-win: use TUNIDX in all netsh commands, remove waitForInterface()

This waitForInterface() kludge didn't work well.

If we use the numeric TUNIDX identifiers instead of the TUNDEV strings in
all `netsh` commands, it doesn't appear to be needed.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agovpnc-script-win: add FIXMEs regard IPv6 split-excludes and gateways
Daniel Lenski [Tue, 30 Mar 2021 23:20:34 +0000 (16:20 -0700)]
vpnc-script-win: add FIXMEs regard IPv6 split-excludes and gateways

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agovpnc-script-win: add legacy IP split-exclude handling
Daniel Lenski [Tue, 30 Mar 2021 23:05:05 +0000 (16:05 -0700)]
vpnc-script-win: add legacy IP split-exclude handling

Based on https://lists.infradead.org/pipermail/openconnect-devel/2020-June/004869.html

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agovpnc-script-win: cleanup spacing, clarify comments
Daniel Lenski [Tue, 30 Mar 2021 23:01:20 +0000 (16:01 -0700)]
vpnc-script-win: cleanup spacing, clarify comments

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agovpnc-script-win: simplify 'internal gateway' calculation
Daniel Lenski [Tue, 30 Mar 2021 22:58:50 +0000 (15:58 -0700)]
vpnc-script-win: simplify 'internal gateway' calculation

OpenConnect already provides INTERNAL_IP4_NETADDR, so let's use it.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'fix_17' into 'master'
Daniel Lenski [Sun, 7 Feb 2021 02:13:09 +0000 (02:13 +0000)]
Merge branch 'fix_17' into 'master'

GNU awk regex fix

Closes #17

See merge request openconnect/vpnc-scripts!25

3 years agoGNU awk regex fix
Daniel Lenski [Fri, 5 Feb 2021 23:20:15 +0000 (15:20 -0800)]
GNU awk regex fix

The character `#` does not need to be backslash-escaped in awk regexes, and
GNU awk v5.1.0 complains about these regexes (first added in 3885f8bb).

Fixes #17

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'cleanup' into 'master'
Daniel Lenski [Mon, 25 Jan 2021 05:50:23 +0000 (05:50 +0000)]
Merge branch 'cleanup' into 'master'

cleanup

See merge request openconnect/vpnc-scripts!20

3 years agomove destroy_tun_device into do_disconnect (called only here)
Daniel Lenski [Tue, 8 Dec 2020 07:12:19 +0000 (23:12 -0800)]
move destroy_tun_device into do_disconnect (called only here)

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoremove bits for ancient Linux 2.6.x kernels
Daniel Lenski [Tue, 8 Dec 2020 07:05:02 +0000 (23:05 -0800)]
remove bits for ancient Linux 2.6.x kernels

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agomention IDLE_TIMEOUT
Daniel Lenski [Tue, 8 Dec 2020 06:44:46 +0000 (22:44 -0800)]
mention IDLE_TIMEOUT

(added in https://gitlab.com/openconnect/openconnect/commit/9182af61920ea4e63831f3bd474e31b639f0b378)

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agocleanup whitespace and clarify comments
Daniel Lenski [Tue, 8 Dec 2020 06:25:31 +0000 (22:25 -0800)]
cleanup whitespace and clarify comments

3 years agotweak warning message about un-routable exclude routes
Daniel Lenski [Sun, 24 Jan 2021 15:00:57 +0000 (07:00 -0800)]
tweak warning message about un-routable exclude routes

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'ignore-unreachable-exc' into 'master'
Daniel Lenski [Sun, 24 Jan 2021 14:57:57 +0000 (14:57 +0000)]
Merge branch 'ignore-unreachable-exc' into 'master'

Ignore unreachable exclude routes

Closes #16

See merge request openconnect/vpnc-scripts!23

3 years agoIgnore unreachable exclude routes
Thomas Bregolin [Sun, 24 Jan 2021 09:43:44 +0000 (09:43 +0000)]
Ignore unreachable exclude routes

Otherwise a malformed ip route command is executed.

Signed-off-by: Thomas Bregolin <tbregolin@cloudflare.com>
3 years agoMerge branch 'document-exc' into 'master'
Daniel Lenski [Sun, 24 Jan 2021 02:43:58 +0000 (02:43 +0000)]
Merge branch 'document-exc' into 'master'

Document split tunnel EXC variables

See merge request openconnect/vpnc-scripts!24

3 years agoDocument split tunnel EXC variables
Thomas Bregolin [Sun, 10 Jan 2021 05:00:51 +0000 (05:00 +0000)]
Document split tunnel EXC variables

3 years agoMerge branch 'fix_default_route_filter_BSDs' into 'master'
Daniel Lenski [Thu, 17 Dec 2020 00:28:52 +0000 (00:28 +0000)]
Merge branch 'fix_default_route_filter_BSDs' into 'master'

DragonFly and FreeBSD fixes

See merge request openconnect/vpnc-scripts!22

3 years agoignore bogus non-forwardable exclude routes on disconnect too
Daniel Lenski [Thu, 17 Dec 2020 00:14:50 +0000 (16:14 -0800)]
ignore bogus non-forwardable exclude routes on disconnect too

Improves upon 1fdc3e6494650d309418bec7ceb0c310cf500541.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years ago*BSDs: get_default_gw needs to EXCLUDE routes through tunnel for attempt-reconnect...
Daniel Lenski [Tue, 15 Dec 2020 01:40:23 +0000 (17:40 -0800)]
*BSDs: get_default_gw needs to EXCLUDE routes through tunnel for attempt-reconnect, but should NOT exclude them otherwise

See explanation here: https://gitlab.com/openconnect/vpnc-scripts/-/commit/ecf656700c283267912a7c073bb75e8100064316#note_466648051

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agomark tunnel device 'down' before destroying
Aaron LI [Sun, 13 Dec 2020 08:39:44 +0000 (16:39 +0800)]
mark tunnel device 'down' before destroying

Signed-off-by: Aaron LI <aly@aaronly.me>
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoAdd DragonFly BSD support and improve FreeBSD support
Aaron LI [Sun, 13 Dec 2020 08:38:38 +0000 (16:38 +0800)]
Add DragonFly BSD support and improve FreeBSD support

Support DragonFly BSD for TUN creation and destroy in the same way as
FreeBSD.

No need to load the `if_tun` kernel module, because the `ifconfig(8)`
utility on FreeBSD and DragonFly BSD will auto load it if necessary
(the `-n` option suppresses this behavior; see man page for details).
This feature was added to `ifconfig(8)` in 1999:
https://github.com/freebsd/freebsd/commit/4d16916f800d4c5ee37fb3c93ca6981ad9b33eb3

In addition, FreeBSD 13 has merged `if_tun` and `if_tap` into a single
module named `if_tuntap`.  So this change improves the FreeBSD
support.

Signed-off-by: Aaron LI <aly@aaronly.me>
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoUse '[[:space:]]' instead of '\s' to support POSIX awk
Aaron LI [Sun, 13 Dec 2020 08:45:45 +0000 (16:45 +0800)]
Use '[[:space:]]' instead of '\s' to support POSIX awk

The `\s` is a GNU extension to awk and doesn't work on BSD's awk.  Use
`[[:space:]]` instead to work with BSD's awk.

Signed-off-by: Aaron LI <aly@aaronly.me>
3 years ago*BSDs: don't inadvertently pick up a bogus 0.0.0.0/32 route as a default route
Daniel Lenski [Mon, 14 Dec 2020 18:33:06 +0000 (10:33 -0800)]
*BSDs: don't inadvertently pick up a bogus 0.0.0.0/32 route as a default route

See https://gitlab.com/openconnect/vpnc-scripts/-/merge_requests/9#note_465753189 for example and discussion.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoFix basename invocation on *BSD shells
Daniel Lenski [Mon, 14 Dec 2020 21:37:31 +0000 (13:37 -0800)]
Fix basename invocation on *BSD shells

Modified version of !21. See discussion https://gitlab.com/openconnect/vpnc-scripts/-/merge_requests/21#note_465757246

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agofix another ifconfig syntax difference between Linux and *BSDs
Daniel Lenski [Tue, 8 Dec 2020 07:31:50 +0000 (23:31 -0800)]
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 <dlenski@gmail.com>
3 years agoMerge branch 'use_ip_netns_instead_of_listen-netns' into 'master'
Nikos Mavrogiannopoulos [Tue, 8 Dec 2020 13:22:02 +0000 (13:22 +0000)]
Merge branch 'use_ip_netns_instead_of_listen-netns' into 'master'

use `ip netns` instead of ocserv `listen-netns` config option for test configs

See merge request openconnect/vpnc-scripts!19

3 years agouse `ip netns` instead of ocserv `listen-netns` config option for test configs
Daniel Lenski [Tue, 8 Dec 2020 06:12:05 +0000 (22:12 -0800)]
use `ip netns` instead of ocserv `listen-netns` config option for test configs

`listen-netns` is new in ocserv 1.1.1, while iproute2's `ip netns` will work
more universally on Linux, allowing testing on older Linux distributions (see
https://gitlab.com/openconnect/vpnc-scripts/-/commit/c95a3ad0e77963fea73c185ff0308e1edabe522c#note_457425702)

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'use_systemd-resolve_to_check_if_resolved_is_running' into 'master'
Daniel Lenski [Mon, 30 Nov 2020 19:38:50 +0000 (19:38 +0000)]
Merge branch 'use_systemd-resolve_to_check_if_resolved_is_running' into 'master'

Use systemd resolve to check if resolved is running

See merge request openconnect/vpnc-scripts!18

3 years agomatch preexisting code style
Daniel Lenski [Mon, 30 Nov 2020 02:24:06 +0000 (18:24 -0800)]
match preexisting code style

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoUse systemd-resolve to check if resolved is running
Trygve Aaberge [Sun, 12 Aug 2018 09:53:31 +0000 (11:53 +0200)]
Use systemd-resolve to check if resolved is running

resolved may be included in nsswitch.conf even though systemd-resolved
is not running. E.g. Arch Linux includes resolved in nsswitch.conf by
default, but systemd-resolved is not enabled by default, which causes
this script to fail updating dns.

This patch uses the systemd-resolve command, which is included with
systemd, to check if systemd-resolved is actually running.

Signed-off-by: Trygve Aaberge <trygveaa@gmail.com>
Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'test-bsdish' into 'master'
Daniel Lenski [Mon, 30 Nov 2020 19:36:40 +0000 (19:36 +0000)]
Merge branch 'test-bsdish' into 'master'

run tests with *BSD-ish tools (ifconfig/route/netstat) for additional coverage

See merge request openconnect/vpnc-scripts!16

3 years agoFIXME add mock IPv6 configuration to get CI to work
Daniel Lenski [Sat, 28 Nov 2020 00:40:20 +0000 (16:40 -0800)]
FIXME add mock IPv6 configuration to get CI to work

See https://gitlab.com/openconnect/vpnc-scripts/-/merge_requests/16#note_454710802 and #12.

This at least should allow the CI to pass while fully exercising the BSD-ish routing configuration code paths. Should be removed once #12 is resolved.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoadd a bit more logging to test scripts
Daniel Lenski [Sat, 28 Nov 2020 02:20:27 +0000 (18:20 -0800)]
add a bit more logging to test scripts

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agosplit iproute2 and *BSD-ish into separate CI runs
Daniel Lenski [Fri, 27 Nov 2020 20:38:02 +0000 (12:38 -0800)]
split iproute2 and *BSD-ish into separate CI runs

3 years agoCI: don't need to install ocserv and which
Daniel Lenski [Fri, 27 Nov 2020 19:54:23 +0000 (11:54 -0800)]
CI: don't need to install ocserv and which

These are already included in the Centos7 build image: https://gitlab.com/openconnect/build-images/-/blob/master/openconnect-cli/centos7/Dockerfile#L11

3 years agonumerous fixes for Linux IPv6 configuration using ifconfig/route/netstat
Daniel Lenski [Sat, 28 Nov 2020 02:27:08 +0000 (18:27 -0800)]
numerous fixes for Linux IPv6 configuration using ifconfig/route/netstat

Trying to ensure that none of the commands executed change in any way on the actual non-Linux OSes which
we cannot directly test with CI currently.

- add missing $route_syntax_gw
- need new syntax variants:
  - $ifconfig_syntax_add_inet6 ('add' on Linux, 'inet6' on *BSDs)
  - $route_syntax_ipv6 ('-6' on Linux, '-inet6' on *BSDs)
- special handling for IPv6 route addition deletion on Linux:
  - '-host'/-net' are REQUIRED on *BSDs but Linux 'route' rejects them
    ⇒ add $route_syntax_ipv6_{host,net} for these cases
  - Linux 'route' rejects local adapter's IPv6 address as gateway with "SIOCADDRT: invalid argument"
    ⇒ use 'dev $DEVICE' instead of 'gw $NETGW' in this case on Linux

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agotry running tests with *BSD-ish tools (ifconfig/route/netstat) for additional coverage
Daniel Lenski [Wed, 25 Nov 2020 21:48:20 +0000 (13:48 -0800)]
try running tests with *BSD-ish tools (ifconfig/route/netstat) for additional coverage

Things that should be improved:

* Need a better way to disable iproute2. Most likely the sanest way to
  do this will actually be to split the vpnc-script into two versions, rather than
  try to maintain its one-size-fits-all structure.
* Need a better way to enable tracing in vpnc-script. This really should be added
  to OpenConnect itself (in part, by adding `-x` to the `sh /path/to/vpnc-script`
  exec) since we're frequently requesting it of real users for real issues.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'use_resolvconf_only_if_not_symlink_to_resolvctl' into 'master'
Daniel Lenski [Mon, 30 Nov 2020 19:34:52 +0000 (19:34 +0000)]
Merge branch 'use_resolvconf_only_if_not_symlink_to_resolvctl' into 'master'

Use resolvconf only if not symlink to resolvctl

See merge request openconnect/vpnc-scripts!17

3 years agomatch code style
Daniel Lenski [Mon, 30 Nov 2020 02:08:05 +0000 (18:08 -0800)]
match code style

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoDon't use /sbin/resolvconf if it just points to resolvectl.
James Hennessy [Sun, 17 Feb 2019 19:18:05 +0000 (14:18 -0500)]
Don't use /sbin/resolvconf if it just points to resolvectl.

On Fedora 29 systems, resolvconf is a symbolic link to resolvectl, but
using resolvectl won't work unless "resolve" appears on the "hosts" line
of /etc/nsswitch.  If we reach the point of considering resolvconf, then
"resolve" is not enabled and resolvectl should be avoided.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
3 years agoMerge branch 'NetBSD_patches' into 'master'
Daniel Lenski [Wed, 25 Nov 2020 18:47:08 +0000 (18:47 +0000)]
Merge branch 'NetBSD_patches' into 'master'

Patch: make ipv6 in ipv4 and ipv6 in ipv6 tunnels work on (Net)BSD

See merge request openconnect/vpnc-scripts!12