]> www.infradead.org Git - users/dwmw2/vpnc-scripts.git/log
users/dwmw2/vpnc-scripts.git
4 years agoDocument split tunnel EXC variables
Thomas Bregolin [Sun, 10 Jan 2021 05:00:51 +0000 (05:00 +0000)]
Document split tunnel EXC variables

4 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

4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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

4 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>
4 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

4 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>
4 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>
4 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

4 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>
4 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>
4 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

4 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

4 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>
4 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>
4 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

4 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>
4 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>
4 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

4 years agoinclude calling process ID in DEFAULT_ROUTE_FILE{,_IPV6}
Daniel Lenski [Wed, 25 Nov 2020 16:37:05 +0000 (08:37 -0800)]
include calling process ID in DEFAULT_ROUTE_FILE{,_IPV6}

This should allow multiple "stacked" VPNs to run concurrently while
preserving the default route(s).  There is still a race condition if they
aren't terminated in the correct order.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agowith BSD 'route', save-and-restore IPv6 default routes
Daniel Lenski [Tue, 24 Nov 2020 23:12:32 +0000 (15:12 -0800)]
with BSD 'route', save-and-restore IPv6 default routes

This should be a safer way to implement the desired behavior on *BSDs which do not
have a concept of routing metric. See discussion threads:

- https://gitlab.com/openconnect/vpnc-scripts/-/merge_requests/12#note_453784389
- https://gitlab.com/openconnect/vpnc-scripts/-/merge_requests/12#note_344089196

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agosimplify cases and add ifconfig_syntax_del variable
Daniel Lenski [Wed, 18 Nov 2020 04:52:36 +0000 (20:52 -0800)]
simplify cases and add ifconfig_syntax_del variable

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agoPatch: make ipv6 in ipv4 and ipv6 in ipv6 tunnels work on (Net)BSD
Ignatios Souvatzis [Thu, 14 May 2020 12:02:08 +0000 (14:02 +0200)]
Patch: make ipv6 in ipv4 and ipv6 in ipv6 tunnels work on (Net)BSD

Hello all,

since my uni's computing centre added inside ipv6 to their tunnel two
days ago I found that OpenConnect hat problems tearing down and
often, setting up the routes.

Three items I had to fix or enhance:

a) an ifconfig ... del ... somewhere. Correct syntax on all BSD's
   I've been in touch with over the last decades is ifconifg ... delete ...

b) route handling for the default route was not really there - it wasn't
   restored on shutting down the tunnel.

   I've done a ::/1 + 8000::1 instead of default (== ::/0) trick here,
   in concept what OpenVPN does for IPv4 (0.0.0.0/1 + 128.0.0.0/1)
   (has higher priority as more-specific than default due to the shorter
   mask, and is unlikely to be more specific than any real local route).

c) protection of the ipv6 transport route didn't work, as it implicitly
   assumed always going via ipv4.

   This wasn't a problem as long as the inner addresses were
   IPv4-only, but broke the tunnel once the effective ipv6 default
   route kicked in via the tunnel.

Regards,
Ignatios Souvatzis

Signed-off-by: Ignatios Souvatzis <is@beverly.kleinbus.org>
4 years agoMerge branch 'tmp-sanity-check' into 'master'
Daniel Lenski [Wed, 25 Nov 2020 18:23:24 +0000 (18:23 +0000)]
Merge branch 'tmp-sanity-check' into 'master'

vpnc-scripts: added sanity check

See merge request openconnect/vpnc-scripts!15

4 years agovpnc-scripts: added a sanity check of routes and resolv.conf generation
Nikos Mavrogiannopoulos [Wed, 18 Nov 2020 09:37:58 +0000 (10:37 +0100)]
vpnc-scripts: added a sanity check of routes and resolv.conf generation

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
4 years agoMerge branch 'do_attempt_reconnect' into 'master'
Daniel Lenski [Tue, 10 Nov 2020 22:39:34 +0000 (22:39 +0000)]
Merge branch 'do_attempt_reconnect' into 'master'

Fill out the attempt-reconnect handler

See merge request openconnect/vpnc-scripts!14

4 years agopreserve metric in fix_ip_get_output
Daniel Lenski [Wed, 30 Sep 2020 19:22:43 +0000 (12:22 -0700)]
preserve metric in fix_ip_get_output

This will allow us to keep, for example, both a lower-metric route to the
VPN gateway through an Ethernet interface, and a higher-metric route to the
VPN gateway through a WiFi interface.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agowith iproute2, sort the routes to the VPN gateway by metric before trying to create...
Daniel Lenski [Wed, 30 Sep 2020 18:52:06 +0000 (11:52 -0700)]
with iproute2, sort the routes to the VPN gateway by metric before trying to create an explicit route to the gateway via each of them

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agomake do_attempt_reconnect work with route/ifconfig
Daniel Lenski [Fri, 25 Sep 2020 00:16:00 +0000 (17:16 -0700)]
make do_attempt_reconnect work with route/ifconfig

Unlike with iproute2, there is no way to determine which interface(s)
have routes that actually match the VPN gateway, so we simply try
finding a default-route gateway, as upon initial connection.

For this to work properly, we need to ensure that get_default_gw excludes
TUNDEV (since the goal is to prevent loopback), and only uses the first
match.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agoadd working do_attempt_reconnect
Daniel Lenski [Fri, 25 Sep 2020 00:14:00 +0000 (17:14 -0700)]
add working do_attempt_reconnect

This initial implementation requires iproute2.  It find all routes that match
the VPN gateway (excluding those matching "dev $TUNDEV", since the goal is
to prevent loopback), and simply tries adding them one-by-one.

See https://gitlab.com/openconnect/openconnect/-/issues/17 for the original
motivation for adding `reason=attempt-reconnect`.

See https://github.com/dlenski/vpn-slice/pull/14#issuecomment-489293114 for
a discussion of the complexities of implementing it correctly.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agodon't try to set an explicit route to VPN gateway if localhost, and ignore bogus...
Daniel Lenski [Thu, 8 Oct 2020 00:51:29 +0000 (17:51 -0700)]
don't try to set an explicit route to VPN gateway if localhost, and ignore bogus non-forwardable exclude routes

This should fix confusing errors (see https://gitlab.com/openconnect/openconnect/-/issues/172 and
https://gitlab.com/openconnect/openconnect/-/issues/173) and close #8.

Per IANA (https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml#note1),
there are other IPv4 blocks which are effectively unrouteable (not "Forwardable"), but the ones included here
(0.*, 127.*, 169.254.*) are the ones we've actually seen in real VPNs in the wild.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agoIgnore link-local routes in set_default_route
Daniel Lenski [Fri, 25 Sep 2020 16:14:02 +0000 (16:14 +0000)]
Ignore link-local routes in set_default_route

See https://gitlab.com/openconnect/openconnect/-/issues/180#note_418673102, and https://superuser.com/a/1067742 for an explanation of what these routes mean on macOS.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agoMerge branch 'resolvectl' into master
Daniel Lenski [Wed, 9 Sep 2020 02:32:40 +0000 (19:32 -0700)]
Merge branch 'resolvectl' into master

Fix IPv6 DNS nameserver and add split DNS support for systems using systemd-resolved

See merge request !13

4 years agoleave support for older systemd-resolved (v229-v238) in place
Daniel Lenski [Wed, 9 Sep 2020 02:23:35 +0000 (19:23 -0700)]
leave support for older systemd-resolved (v229-v238) in place

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
4 years agoWindows IPv6: remove hard-coded next-hop of fe80::8
Daniel Lenski [Sat, 5 Sep 2020 19:05:13 +0000 (12:05 -0700)]
Windows IPv6: remove hard-coded next-hop of fe80::8

Closes #6. This was added in 3d2c68280b591322021f157e1533473356f1e3ef, which originally added Windows IPv6 support.

4 years agoMerge branch 'kinolaev/vpnc-scripts-kinolaev-master-patch-75707' into 'master'
Daniel Lenski [Sat, 5 Sep 2020 18:10:12 +0000 (11:10 -0700)]
Merge branch 'kinolaev/vpnc-scripts-kinolaev-master-patch-75707' into 'master'

Windows: Specify interface when adding routes

See merge request !10

4 years agoAdd split DNS support for systemd-resolved
Florian Domain [Mon, 10 Aug 2020 12:17:13 +0000 (14:17 +0200)]
Add split DNS support for systemd-resolved

4 years agoUse resolvectl for systemd-resolved
Florian Domain [Mon, 10 Aug 2020 12:13:26 +0000 (14:13 +0200)]
Use resolvectl for systemd-resolved

- resolvectl is embedded in systemd-resolved and is more simpler
to use than calling directly busctl as we don't have to format IPs or
specify which address family it belongs.
- fix IPv6 nameserver, address family was previously hardcoded to IPv4
so the call to the busctl was failing.

4 years agofix tabs/spaces in POSIX vpnc-script as well
Daniel Lenski [Fri, 7 Aug 2020 00:53:24 +0000 (17:53 -0700)]
fix tabs/spaces in POSIX vpnc-script as well

Used `wtf -i -sy8 vpnc-script` to replace 8×space with TAB

Signed-off-by: Daniel Lenski <dlenski@amazon.com>
4 years agocleanup whitespace in vpnc-script-win.js
Daniel Lenski [Fri, 7 Aug 2020 00:49:35 +0000 (17:49 -0700)]
cleanup whitespace in vpnc-script-win.js

Current indentation is a mixture of 4×space and TAB, which is bad practice
and very confusing when browsing in GitLab's web UI (defaults to
TAB=8×space.  Cleaned up indentation with `wtf -i -sx4`
(https://github.com/dlenski/wtf/)

Signed-off-by: Daniel Lenski <dlenski@amazon.com>
5 years agospecify interface when adding routes
Sergej [Fri, 17 Apr 2020 19:04:21 +0000 (19:04 +0000)]
specify interface when adding routes

5 years agoMerge branch 'slackware_netconfig_fix' into 'master'
Daniel Lenski [Tue, 17 Mar 2020 17:45:01 +0000 (17:45 +0000)]
Merge branch 'slackware_netconfig_fix' into 'master'

fix Slackware issue (netconfig is an unrelated tool, not relevant for resolv.conf handling)

See merge request openconnect/vpnc-scripts!7

5 years agofix Slackware issue (netconfig is an unrelated tool, not relevant for resolv.conf...
Daniel Lenski [Tue, 10 Mar 2020 20:08:35 +0000 (20:08 +0000)]
fix Slackware issue (netconfig is an unrelated tool, not relevant for resolv.conf handling)

Reports:

- https://github.com/dlenski/openconnect/issues/165#issuecomment-597286178
- https://www.linuxquestions.org/questions/slackware-14/vpnc-on-slackware-14-2-is-bringing-up-network-configuration-dialog-each-time-4175595447/#post5646866

5 years agoMerge branch 'ip_route_get' into 'master'
Daniel Lenski [Fri, 21 Feb 2020 17:51:17 +0000 (17:51 +0000)]
Merge branch 'ip_route_get' into 'master'

iproute2 5.1+ doesn't allow prefixlen!=32 in get

See merge request openconnect/vpnc-scripts!5

5 years agoNo need to add a separate sed invocation for `$NETMASKLEN` fixing
Daniel Lenski [Fri, 21 Feb 2020 17:49:45 +0000 (17:49 +0000)]
No need to add a separate sed invocation for `$NETMASKLEN` fixing

5 years agoiproute2 5.1+ doesn't allow prefixlen!=32 in get
Rafał Florczak [Sun, 29 Sep 2019 20:05:46 +0000 (22:05 +0200)]
iproute2 5.1+ doesn't allow prefixlen!=32 in get

In order to set up routing exclusions properly, we now ask for routes without
specified prefixlen and later add it manually before calling `ip route add`.
Older versions of `ip` silently ignored the prefixlen -- as confirmed in:
https://www.spinics.net/lists/netdev/msg570803.html.

Reproduction:
$ ip route get 1.2.0.0/24
Error: ipv4: Invalid values in header for route get request.

Signed-off-by: Rafał Florczak <rafal.florczak@nokia.com>
5 years agoMerge branch 'ahrex/set-correct-ipv6-route' into 'master'
David Woodhouse [Thu, 6 Jun 2019 09:58:20 +0000 (09:58 +0000)]
Merge branch 'ahrex/set-correct-ipv6-route' into 'master'

set correct ipv6 route

See merge request openconnect/vpnc-scripts!1

5 years agoMerge branch 'iproute2_is_Linux_only' into 'master'
David Woodhouse [Thu, 6 Jun 2019 09:56:27 +0000 (09:56 +0000)]
Merge branch 'iproute2_is_Linux_only' into 'master'

iproute2 is Linux only; don't try to set IPROUTE on another OS

See merge request openconnect/vpnc-scripts!2

5 years agoiproute2 is Linux only; don't try to set IPROUTE on another OS
Daniel Lenski [Thu, 6 Jun 2019 00:31:38 +0000 (17:31 -0700)]
iproute2 is Linux only; don't try to set IPROUTE on another OS

If `which ip` returns something on another OS, it's an unrelated tool that
won't work for routing configuration. This should fix the macOS issue
discovered at:
https://github.com/dlenski/openconnect/issues/132#issuecomment-470475009

Signed-off-by: Daniel Lenski <daniel.lenski@finalphasesystems.com>
5 years agoFix tab typo
Alexander Huynh [Tue, 19 Mar 2019 06:31:08 +0000 (06:31 +0000)]
Fix tab typo

Signed-off-by: Alexander Huynh <alex@grande.coffee>
5 years agoFix IPv6 /128 route addition
Alexander Huynh [Tue, 19 Mar 2019 06:18:51 +0000 (06:18 +0000)]
Fix IPv6 /128 route addition

Previously, a split tunnel with a /128 request would result in a default
tunnel, rather than a specific route.

Correctly set the default route if we request a /0.

Signed-off-by: Alexander Huynh <alex@grande.coffee>
6 years agovpnc-script: hide EROFS for ip route flush cache
Robin H. Johnson [Wed, 20 Jun 2018 06:34:16 +0000 (06:34 +0000)]
vpnc-script: hide EROFS for ip route flush cache

Inside a container, running 'ip route flush cache' can spam with
"ip: can't open '/proc/sys/net/ipv4/route/flush': Read-only file system"

Hide that the error output for that command.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
6 years agovpnc-script: squelch EEXIST from grep
Robin H. Johnson [Wed, 20 Jun 2018 06:26:38 +0000 (06:26 +0000)]
vpnc-script: squelch EEXIST from grep

In a container, /etc/nsswitch.conf might not exist.
Silence the error grep: /etc/nsswitch.conf: No such file or directory

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
6 years agoresolvconf: set search instead of domain
Robin H. Johnson [Wed, 20 Jun 2018 06:26:37 +0000 (06:26 +0000)]
resolvconf: set search instead of domain

Some vpn clients pass multiple domains for DNS search scope, which
requires that we use search rather than domain. The generic path was
already using search, so just switch the resolvconf path to also use
search.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
6 years agoDetect iproute2 ip binary path
Robin H. Johnson [Wed, 20 Jun 2018 06:26:36 +0000 (06:26 +0000)]
Detect iproute2 ip binary path

vpnc-script correctly detects the path to the 'ip' binary, but
vpnc-script-ptrtd and vpnc-script-sshd never got the same fix.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
6 years agoAdd attempt-reconnect invocation
David Woodhouse [Wed, 16 Jan 2019 08:33:50 +0000 (10:33 +0200)]
Add attempt-reconnect invocation

See https://gitlab.com/openconnect/openconnect/issues/17

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
6 years agoAdd IPv6 DNS addresses using "netsh interface ipv6 add dns" command.
Kai Takahashi [Thu, 10 Jan 2019 21:13:40 +0000 (21:13 +0000)]
Add IPv6 DNS addresses using "netsh interface ipv6 add dns" command.

Signed-off-by: Kai Takahashi <www.carrotsoft@gmail.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
7 years agoSupport routes with different devs and gateways
Gernot Hillier [Wed, 21 Feb 2018 16:46:44 +0000 (17:46 +0100)]
Support routes with different devs and gateways

Extend the *_network_route helper functions by parameters to specify device
and, optionally, gateway for the route.

Signed-off-by: Gernot Hillier <gernot.hillier@siemens.com>
Tested-by: Thomas Zander <thomas.zander@siemens.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
7 years agoRevive route cleanup for /sbin/route code
Gernot Hillier [Wed, 21 Feb 2018 16:46:43 +0000 (17:46 +0100)]
Revive route cleanup for /sbin/route code

Cleanup our routes upon disconnect also when using /sbin/route command - even
if OS will do it for us when TUNDEV gets removed. That's the same what the
ip-route code already does.

Additionally, we obviously didn't need route deletion in set_network_route for
/sbin/route mode - this function didn't do anything until now. So remove this
call -- it's a bad idea to call del_network_route inside set_network_route
anyways because both modify the same global variables.

Signed-off-by: Gernot Hillier <gernot.hillier@siemens.com>
Tested-by: Thomas Zander <thomas.zander@siemens.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
7 years agoSupport split-exclude rules from Pulse gateway
Gernot Hillier [Wed, 21 Feb 2018 16:46:42 +0000 (17:46 +0100)]
Support split-exclude rules from Pulse gateway

The vpnc-script used by OpenConnect only supports "split include" rules (default
route unchanged, specific VPN routes added). We add support for Pulse's "split
exclude" rules (default route to VPN, exclude rules for targets to be connected
via normal uplink).

For targets specified as split-exclude by the gateway, we add additional routes
which keep traffic as-is (i.e. separate from tunnel). On platforms only
providing /sbin/route, we guess that those are reached via default gateway.
Please note that IPv6 variant is completely untested as I have no
access to according testbeds.

Tested on Linux (using ip and route command) in a IPv4 environment, "ip"
case also tested in a IPv6 dialup config (gateway is IPv4 only).

Signed-off-by: Gernot Hillier <gernot.hillier@siemens.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
7 years agoCheck if resolved is enabled in nsswitch.conf prior to using it
Nikos Mavrogiannopoulos [Wed, 4 Oct 2017 09:53:06 +0000 (11:53 +0200)]
Check if resolved is enabled in nsswitch.conf prior to using it

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
8 years agoAdd support for systemd-resolved
Thiago Padilha [Thu, 20 Oct 2016 05:03:50 +0000 (02:03 -0300)]
Add support for systemd-resolved

Add support for modifying DNS information on systems using systemd-resolved.
The communication with systemd-resolved is done through dbus, which is
possible with the `busctl` program that comes with systemd version 229
and later.

Signed-off-by: Thiago de Arruda <tpadilha84@gmail.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
8 years agoMerge branch 'master' of bombadil.infradead.org:/home/dwmw2/public_git/vpnc-scripts
David Woodhouse [Wed, 14 Dec 2016 13:11:39 +0000 (13:11 +0000)]
Merge branch 'master' of bombadil.infradead.org:/home/dwmw2/public_git/vpnc-scripts

8 years agorewrite resolv.conf parsing
Corey Hickey [Sun, 28 Aug 2016 05:45:14 +0000 (22:45 -0700)]
rewrite resolv.conf parsing

This patch simplifies parsing and changes behavior in two ways:

1. Domains for searching are now parsed from "search" and "domain"
lines. Only a "search" line is outputted, since "search" supports
multiple domains and is mutually exclusive with "domain". The motivation
for this is to make vpnc-script behave sanely when there are existing
resolv.conf files with only "domain" or with both "domain" and "search".

2. All original "nameserver" lines are discarded and replaced rather
than only the number of nameservers from $INTERNAL_IP4_DNS. The
rationale here is that vpnc-script should be consistent and either
retain all original nameservers or overwrite all of them. Retaining them
is problematic because there is a limit of three, and overwriting is
closer to the original behavior.

The Darwin changes are untested, but are a simple search/replace and
thus should work fine.

Signed-off-by: Corey Hickey <bugfood-ml@fatooh.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
8 years agoavoid multiple "domain" entries in resolv.conf
Corey Hickey [Sat, 6 Aug 2016 03:21:33 +0000 (20:21 -0700)]
avoid multiple "domain" entries in resolv.conf

This fixes a bug when $CISCO_DEF_DOMAIN contains multiple domains. When
resolv.conf has a line like this:

domain example.com example.org

...then the "host" command fails:

 $ host web001
host: parse of /etc/resolv.conf failed

This patch makes vpnc-script use the first entry in CISCO_DEF_DOMAIN for
the "domain" entry.

Signed-off-by: Corey Hickey <bugfood-ml@fatooh.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
10 years agoDo not create /dev/net/tun when checking for its existence
David Woodhouse [Wed, 25 Mar 2015 11:30:46 +0000 (11:30 +0000)]
Do not create /dev/net/tun when checking for its existence

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
10 years agofix comment
David Woodhouse [Tue, 17 Mar 2015 08:05:51 +0000 (08:05 +0000)]
fix comment

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
10 years agoOSX - Fix split DNS when doing split routing
Björn Ketelaars [Sat, 14 Mar 2015 18:31:38 +0000 (19:31 +0100)]
OSX - Fix split DNS when doing split routing

Currently one can choose between two scenarios:

- overriding the default gateway, which breaks split routing, and honoring the
  DNS server as proposed by the server
- not overriding the default gateway, which enables split routing, but without
  honoring the DNS server as proposed by the server

446  # next line overrides the default gateway and breaks split routing
447  # d.add Router $INTERNAL_IP4_ADDRESS

Split DNS, when doing split routing, is enabled by adding INTERNAL_IP4_DNS to
the list of DNS servers.

Signed-off-by: Björn Ketelaars <bjorn.ketelaars@hydroxide.nl>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
10 years agoEnable resolvconf on FreeBSD too
John Baldwin [Thu, 12 Mar 2015 15:28:51 +0000 (15:28 +0000)]
Enable resolvconf on FreeBSD too

According to https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=195359
this should work fine. I've no idea why it wasn't enable for FreeBSD
in the first place; perhaps just lack of testing and conservatism.

Signed-off-by: John Baldwin <jhb@FreeBSD.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
10 years agoAdd support for "unbound" DNS resolver
Antonio Borneo [Sun, 1 Dec 2013 07:06:41 +0000 (15:06 +0800)]
Add support for "unbound" DNS resolver

Original patch from Erinn Looney-Triggs <erinn.looneytriggs@gmail.com>
posted at Red Hat Bugzilla - Bug #865092
https://bugzilla.redhat.com/show_bug.cgi?id=865092

Removed bashism, removed trailing spaces, use tab for indentation.

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
10 years agoFix quoting on network comparisons
David Woodhouse [Thu, 31 Jul 2014 22:03:00 +0000 (23:03 +0100)]
Fix quoting on network comparisons

Spotted by Marcus Müller <marcus@hostalia.de>

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
11 years agoFix default route handling in vpnc-script-win.js
Jonathan Lauvernier [Fri, 21 Mar 2014 09:02:40 +0000 (09:02 +0000)]
Fix default route handling in vpnc-script-win.js

Implement full tunnel route setup, and get the $VPNGATEWAY route correct.

Signed-off-by: Jonathan Lauvernier <Jonathan.Lauvernier@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
11 years agoSet MTU on Windows
David Woodhouse [Tue, 11 Mar 2014 18:44:07 +0000 (11:44 -0700)]
Set MTU on Windows

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
11 years agoSupport IPv6 on Windows
David Woodhouse [Thu, 13 Feb 2014 15:29:35 +0000 (15:29 +0000)]
Support IPv6 on Windows

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
11 years agoImport vpnc-script-win.js from vpnc (r540).
David Woodhouse [Wed, 12 Feb 2014 14:28:28 +0000 (14:28 +0000)]
Import vpnc-script-win.js from vpnc (r540).

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 years agovpnc-script: document "reason=reconnect"
Antonio Borneo [Sun, 10 Mar 2013 11:53:37 +0000 (19:53 +0800)]
vpnc-script: document "reason=reconnect"

After recent modification, a new value can be passed through
environment variable "reason".
Add it in comment header.

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 years agoFix various issues on FreeBSD
Emanuel Haupt [Mon, 28 Jan 2013 15:33:38 +0000 (15:33 +0000)]
Fix various issues on FreeBSD

- duplicate creation of tun devices
- cleanup of created tun device
- deadlock of vpnc holding an open file descriptor on /dev/tunN
- properly restoring /etc/resolv.conf

Signed-off-by: Emanuel Haupt <ehaupt@FreeBSD.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 years agohandle creating/destroying the tun device on OpenBSD
Stuart Henderson [Thu, 8 Nov 2012 19:37:59 +0000 (19:37 +0000)]
handle creating/destroying the tun device on OpenBSD

Signed-off-by: Stuart Henderson <sthen@openbsd.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 years agoredirect stderr from which (not grep) to /dev/null
Stuart Henderson [Thu, 8 Nov 2012 19:37:35 +0000 (19:37 +0000)]
redirect stderr from which (not grep) to /dev/null

Signed-off-by: Stuart Henderson <sthen@openbsd.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 years agoFix bashisms for shell compatibility
Mike Miller [Fri, 1 Jun 2012 12:53:25 +0000 (08:53 -0400)]
Fix bashisms for shell compatibility

Signed-off-by: Mike Miller <mtmiller@ieee.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 years agoHandle IPv6 configuration in sshd variant
Mike Miller [Fri, 1 Jun 2012 12:53:12 +0000 (08:53 -0400)]
Handle IPv6 configuration in sshd variant

Signed-off-by: Mike Miller <mtmiller@ieee.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 years agoReplace netunshare with ip netns
Mike Miller [Fri, 1 Jun 2012 12:53:03 +0000 (08:53 -0400)]
Replace netunshare with ip netns

Signed-off-by: Mike Miller <mtmiller@ieee.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 years agoUse /32 for netmask to iproute, not /255.255.255.255
David Woodhouse [Fri, 25 May 2012 07:03:37 +0000 (08:03 +0100)]
Use /32 for netmask to iproute, not /255.255.255.255

Older versions of iproute (e.g. 2.6.18-7 on RHEL5.2) can't cope with seeing
/255.255.255.255.

Thanks to Andrew Daviel for pointing it out.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 years agoAdd COPYING file and clarify licences
David Woodhouse [Thu, 17 May 2012 00:19:36 +0000 (01:19 +0100)]
Add COPYING file and clarify licences

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
13 years agoAdd script hooks
David Woodhouse [Mon, 23 Apr 2012 00:20:34 +0000 (01:20 +0100)]
Add script hooks

This is based loosely in concept on the Debian patch, and is also needed for
OpenWrt unless we want to add a bunch of OpenWrt-specific stuff in here too.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
13 years agoAdd support for OpenWrt DNS management
David Woodhouse [Mon, 23 Apr 2012 00:04:54 +0000 (01:04 +0100)]
Add support for OpenWrt DNS management

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
13 years agoBusyBox ifconfig doesn't like the "inet" argument.
David Woodhouse [Mon, 23 Apr 2012 00:04:27 +0000 (01:04 +0100)]
BusyBox ifconfig doesn't like the "inet" argument.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
13 years agoFix compatibility with Solaris 10 /bin/sh
David Woodhouse [Thu, 19 Apr 2012 23:21:31 +0000 (00:21 +0100)]
Fix compatibility with Solaris 10 /bin/sh

It doesn't support $( ) or $(( )) or [ -e ] or if !

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
13 years agodocument INTERNAL_IP4_MTU
Antonio Borneo [Sun, 8 Jan 2012 03:37:00 +0000 (11:37 +0800)]
document INTERNAL_IP4_MTU

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
13 years agoSupport for /sbin/netconfig under OpenSuse 11.1
Mike Kienenberger [Sun, 8 Jan 2012 03:36:59 +0000 (11:36 +0800)]
Support for /sbin/netconfig under OpenSuse 11.1

I added support for OpenSuse 11.1's netconfig system for managing
resolv.conf as modify_resolvconf no longer exists.

Signed-off-by: Mike Kienenberger <mkienenb@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
13 years agoFix typo inside comment
Antonio Borneo [Sun, 8 Jan 2012 03:36:58 +0000 (11:36 +0800)]
Fix typo inside comment

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
13 years agoAdd IPv6 new variables to comment header
Antonio Borneo [Sun, 8 Jan 2012 03:36:57 +0000 (11:36 +0800)]
Add IPv6 new variables to comment header

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
13 years agoReuse function and value for default GW
Antonio Borneo [Sun, 8 Jan 2012 03:36:56 +0000 (11:36 +0800)]
Reuse function and value for default GW

Remove duplicated code to get default GW and
use existing get_default_gw().

Reuse default GW value just obtained, don't
call get_default_gw() twice.

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>