]> git.ipfire.org Git - thirdparty/wireguard-tools.git/log
thirdparty/wireguard-tools.git
2 weeks agowg-quick: use addconf instead of setconf master
Jason A. Donenfeld [Thu, 19 Jun 2025 14:58:39 +0000 (16:58 +0200)] 
wg-quick: use addconf instead of setconf

The example in the man page at some point changed:

-    \fBPostUp = wg set %i private-key <(pass WireGuard/private-keys/%i)\fP
+    \fBPreUp = wg set %i private-key <(pass WireGuard/private-keys/%i)\fP

This is actually wrong because PreUp is followed by set_config(), which
calls `wg setconf`, which in turn deletes the private key from the
interface because it is missing from the configuration. Replacing this
with `wg addconf` is safe to do because the interface is newly created.

Suggested-by: Matthias Dressel <code@deadcode.eu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agowg-quick: linux: deal with resolvconf migration more gracefully
Jason A. Donenfeld [Fri, 23 May 2025 18:59:38 +0000 (20:59 +0200)] 
wg-quick: linux: deal with resolvconf migration more gracefully

When Ubuntu systems upgrade from Debian's atrocious resolvconf to the
systemd-resolve symlink, they sometimes leave around
/etc/resolvconf/interface-order, which then winds up breaking the
detection and passing the bogus 'tun.' prefix to systemd's resolvconf,
resulting in failure. Work around this by only doing the 'tun.' prefix
hack if resolvconf isn't a symlink. This is ugly but so it goes.

Reported-by: Andrei Borzenkov <arvidjaar@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agowg-quick: pass on # comments to {Pre,Post}{Up,Down}
Robyn Kosching [Wed, 15 Jan 2025 11:33:50 +0000 (12:33 +0100)] 
wg-quick: pass on # comments to {Pre,Post}{Up,Down}

Currently commands in {Pre,Post}{Up,Down} are stripped of everything
starting with the first #, even if the # is escaped or in a string. This
patch leaves comment interpretation to the shell, as it can presumably
already handle the difference between comments and escaped #.

Signed-off-by: Robyn Kosching <robyn@kosching.me>
[Jason: massage commit message, port to other platforms]
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agosyncconf: account for psks removed from config file
Jason A. Donenfeld [Fri, 23 May 2025 18:22:37 +0000 (20:22 +0200)] 
syncconf: account for psks removed from config file

Otherwise removing a psk from a config file wouldn't reflect on the
runtime state.

Note that this could have been implemented more simply, by just setting
WGPEER_HAS_PRESHARED_KEY on all of the file's peers, since the psk slot
is zeroed by calloc in config.c, and this way ones with no set key will
be cleared. The downside is that this means every peer update will take
the handshake lock in the kernel, creating more work and possibly
contention:

        if (preshared_key) {
                down_write(&peer->handshake.lock);
                memcpy(&peer->handshake.preshared_key, preshared_key,
                       NOISE_SYMMETRIC_KEY_LEN);
                up_write(&peer->handshake.lock);
        }

Avoid this by only setting it if there's a mismatch between the runtime
and the file. Computationally this shouldn't make much of a difference
because we can do it in the same iteration as the peer removal
detection.

Reported-by: Patrick Havelange <patrick.havelange_ext@softathome.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agowg-quick: linux: use smallest mtu, not largest
Jason A. Donenfeld [Wed, 21 May 2025 21:03:08 +0000 (23:03 +0200)] 
wg-quick: linux: use smallest mtu, not largest

By accident, this function was looking at the endpoint with the largest
MTU rather than the smallest one.

Reported-by: Ismael Bouya <ismael@bouya.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agoversion: bump v1.0.20250521
Jason A. Donenfeld [Tue, 20 May 2025 23:05:38 +0000 (01:05 +0200)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agoconfig: handle strdup failure
Ilia Shipitsin [Tue, 20 May 2025 22:57:50 +0000 (00:57 +0200)] 
config: handle strdup failure

Signed-off-by: Ilia Shipitsin <chipitsine@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agowg-quick: linux: add 'dev' to 'ip link add' to avoid keyword conflicts
TriangleSnake [Mon, 5 May 2025 07:13:06 +0000 (15:13 +0800)] 
wg-quick: linux: add 'dev' to 'ip link add' to avoid keyword conflicts

Signed-off-by: TriangleSnake <trianglesnake2002@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agoipc: add stub for allowedips flags on other platforms
Jason A. Donenfeld [Tue, 20 May 2025 20:12:39 +0000 (22:12 +0200)] 
ipc: add stub for allowedips flags on other platforms

On UAPI, just pass along the -. On other platforms, return an error and
add a TODO comment.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agoipc: linux: support incremental allowed ips updates
Jordan Rife [Sat, 17 May 2025 19:29:51 +0000 (12:29 -0700)] 
ipc: linux: support incremental allowed ips updates

Extend the interface of `wg set` to leverage the WGALLOWEDIP_F_REMOVE_ME
flag, a direct way of removing a single allowed ip from a peer,
allowing for incremental updates to a peer's configuration. By default,
allowed-ips fully replaces a peer's allowed ips using
WGPEER_REPLACE_ALLOWEDIPS under the hood. When '+' or '-' is prepended
to any ip in the list, wg clears WGPEER_F_REPLACE_ALLOWEDIPS and sets
the WGALLOWEDIP_F_REMOVE_ME flag on any ip prefixed with '-'.

$ wg set wg0 peer <PUBKEY> allowed-ips +192.168.88.0/24,-192.168.0.1/32

This command means "add 192.168.88.0/24 to this peer's allowed ips if
not present, and remove 192.168.0.1/32 if present".

Use -isystem so that headers in uapi/ take precedence over system
headers; otherwise, the build will fail on systems running kernels
without the WGALLOWEDIP_F_REMOVE_ME flag.

Note that this patch is meant to be merged alongside the kernel patch
that introduces the flag.

Signed-off-by: Jordan Rife <jordan@jrife.io>
[Jason: removed linux ifdefs; this will eventually come to other platforms too. minor style nits.]
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 weeks agoipc: freebsd: use AF_LOCAL for the control socket
Kyle Evans [Sat, 12 Apr 2025 02:46:03 +0000 (21:46 -0500)] 
ipc: freebsd: use AF_LOCAL for the control socket

AF_INET assumes that IPv4 is built into the kernel, but it's completely
valid to build a kernel without it.  unix(4) sockets, on the other hand,
are not-optional in the kernel build.  Given that interface ioctls can
be invoked on any kind of socket, switch to the safer one to avoid
breaking on IPv6-only kernels.

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
23 months agoipc: linux: enforce IFNAMSIZ limit
Jason A. Donenfeld [Fri, 4 Aug 2023 14:04:36 +0000 (16:04 +0200)] 
ipc: linux: enforce IFNAMSIZ limit

libmnl doesn't check lengths, so do our own checking before copying the
interface name to the netlink buffer.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2 years agoman: set private key in PreUp rather than PostUp
Jason A. Donenfeld [Thu, 18 May 2023 01:17:02 +0000 (03:17 +0200)] 
man: set private key in PreUp rather than PostUp

This is probably more sensible, since there's no point in letting
traffic flow before the interface is configured.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2 years agowg-quick: run PreUp hook after creating interface
Daniel Gröber [Wed, 7 Dec 2022 18:00:31 +0000 (19:00 +0100)] 
wg-quick: run PreUp hook after creating interface

Currently PreUp hooks run before the interface is created. This is
problematic for moving the device into a Linux VRFs as this will
currently clear all assigned IPv6 addressess (possibly a bug), so if we
did this in PostUp (i.e. before add_addr) we'll have to manually re-add
all assigned addresses. This is obviously less than ideal.

Instead create the wg device just before running PreUp hooks. We apply
this to all platforms for consistency.

Test case:

    $ ip link add vrf-test type vrf table 1234
    $ ip link add wg-test type wireguard
    $ ip addr add dev wg-test 192.168.42.42/24
    $ ip addr add dev wg-test fe80::/64

    $ ip -br addr show wg-test
    wg-test          DOWN           192.168.42.42/24 fe80::/64

    $ ip link set dev wg-test master vrf-test

    $ ip -br addr show wg-test
    wg-test          DOWN           192.168.42.42/32

Signed-off-by: Daniel Gröber <dxld@darkboxed.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2 years agoshow: fix show all endpoints output
Dmitry Selivanov [Wed, 8 Feb 2023 06:30:16 +0000 (09:30 +0300)] 
show: fix show all endpoints output

Currently "wg show all endpoints" prints interface name only once
while other "show all" commands print it on each line as man says.

Signed-off-by: Dmitry Selivanov <dseliv@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2 years agoipc: freebsd: NULL out some freed memory in kernel_set_device()
Kyle Evans [Thu, 3 Nov 2022 18:20:29 +0000 (13:20 -0500)] 
ipc: freebsd: NULL out some freed memory in kernel_set_device()

The `err` path in kernel_set_device() will attempt to free() allocated
nvl_peers, but these two cases meant we could end up attempting a use
after free or a double free, as we rely on nvlist_destroy(NULL) being
a NOP as well as free(NULL).

FreeBSD-Coverity: 1500421
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2 years agoipc: freebsd: avoid leaking memory in kernel_get_device()
Kyle Evans [Thu, 3 Nov 2022 17:59:01 +0000 (12:59 -0500)] 
ipc: freebsd: avoid leaking memory in kernel_get_device()

Primarily, front-load validation of an allowed-ip entry to before we
allocate `aip`, so that we don't need to free() it if we end up skipping
this entry.  Assert that `aip` is NULL after we exit the loop, as we
should have transfered ownership to the `peer` or freed it in all paths
through the allowed-ip loop.

FreeBSD-Coverity: 1500405
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2 years agoshow: apply const to right part of pointer
Jason A. Donenfeld [Mon, 31 Oct 2022 14:38:58 +0000 (15:38 +0100)] 
show: apply const to right part of pointer

Without this -Wcast-qual complains:

show.c:30:43: warning: cast from 'const void *' to 'const void **' drops const qualifier [-Wcast-qual]
        const struct wgpeer *a = *(const void **)first, *b = *(const void **)second;
                                                 ^
show.c:30:71: warning: cast from 'const void *' to 'const void **' drops const qualifier [-Wcast-qual]
        const struct wgpeer *a = *(const void **)first, *b = *(const void **)second;

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2 years agoipc: freebsd: move if_wg path to reflect new in-tree location
Kyle Evans [Sat, 29 Oct 2022 01:45:05 +0000 (20:45 -0500)] 
ipc: freebsd: move if_wg path to reflect new in-tree location

When we re-added if_wg to the tree, we changed directories in dev to
strip the if_ (we don't use this prefix for other interfaces'
directories). Adjust it here as a convenience, so that when we import
wireguard-tools to FreeBSD the path will just work as-is with our usual
build.

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agowg-quick: linux: prevent traffic from momentarily leaking into tunnel
Tom Yan [Fri, 17 Jun 2022 11:34:19 +0000 (19:34 +0800)] 
wg-quick: linux: prevent traffic from momentarily leaking into tunnel

The wireguard route table ip rule should stay as a no-op until the
`suppress_prefixlength 0 table main` rule is in effect. Therefore, add
the wireguard default route to its route table after the latter rule is
added.

Signed-off-by: Tom Yan <tom.ty89@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoglobal: dual license core files as MIT for FreeBSD
Jason A. Donenfeld [Fri, 10 Jun 2022 17:35:38 +0000 (19:35 +0200)] 
global: dual license core files as MIT for FreeBSD

To make it easier for FreeBSD to import wg(8), dual license the core
files as MIT, so that they don't have any trouble.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agowg-quick: android: use right regex for host-vs-IP
Jason A. Donenfeld [Tue, 10 May 2022 10:40:49 +0000 (12:40 +0200)] 
wg-quick: android: use right regex for host-vs-IP

Looks like the "is valid ifname" regex was copy and pasted from
wg-quick.bash instead of the "is valid IP" regex.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoreresolve-dns: use $EPOCHSECONDS instead of $(date +%s)
Jason A. Donenfeld [Tue, 4 Jan 2022 12:07:49 +0000 (13:07 +0100)] 
reresolve-dns: use $EPOCHSECONDS instead of $(date +%s)

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoembeddable-wg-library: add named wg_endpoint union
Mikael Magnusson [Sat, 7 Nov 2020 12:32:56 +0000 (13:32 +0100)] 
embeddable-wg-library: add named wg_endpoint union

Define wg_endpoint as a named union to allow users of the emeddable
library to use the type in function arguments, variables etc.

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoipc: use more clever PnP enumerator
Jason A. Donenfeld [Wed, 6 Oct 2021 23:18:40 +0000 (17:18 -0600)] 
ipc: use more clever PnP enumerator

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoversion: bump v1.0.20210914
Jason A. Donenfeld [Mon, 13 Sep 2021 22:43:31 +0000 (00:43 +0200)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agowg-quick: openbsd: set DNS with resolvd(8)
Matt Dunwoodie [Tue, 7 Sep 2021 11:48:53 +0000 (21:48 +1000)] 
wg-quick: openbsd: set DNS with resolvd(8)

OpenBSD has introduced a new daemon named resolvd(8) to manage
resolv.conf. This creates problems with the old "horrible way" of
completely replacing resolv.conf. Resolvd will attempt to merge manual
changes with DNS servers discovered through dhcpleased(8) and slaacd(8).
Unfortunately, resolvd puts any manual modifications at the end of
resolv.conf, meaning that the wg-quick name servers will be queried
last.

The process for handling multiple name servers (at least with libc) is
to try a name server, and if the query times out, try the next, until
out of name servers, then repeat trying all name servers until a maximum
number of retries are performed. The name servers are queried in the
order listed in resolv.conf and the timeout is 5 seconds.

With this patch, we ensure the wg-quick name server is first in
resolv.conf (as route creates the name server with "static" priority),
but cannot ensure it is exclusive. Therfore, it may be possible that
queries are leaked to other name servers if the wg-quick name server
doesn't respond within 5 seconds.

We have another problem however, and that is if resolvd detects unwind
is running, it will set 127.0.0.1 as the only name server in
resolv.conf. unwind does not have deterministic name server selection in
the default configuration.  This means, all a user would need to do to
inadvertently cause persistent query leaks would be to run `rcctl enable
unwind`.

There are warnings added when these situations may occur.

The next step is to add an exclusive flag and search to route and
resolvd.

Reported-by: Matthieu Herrb <matthieu@herrb.eu>
Signed-off-by: Matt Dunwoodie <ncon@noconroy.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agowg-quick: android: adjust for android 12
Jason A. Donenfeld [Thu, 9 Sep 2021 21:22:17 +0000 (23:22 +0200)] 
wg-quick: android: adjust for android 12

https://android-review.googlesource.com/c/platform/system/netd/+/1671532

Reported-by: engstk <eng.stk@sapo.pt>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agowg-quick: darwin: account for "link#XX" gateways
Laura Hausmann [Thu, 12 Aug 2021 19:29:15 +0000 (21:29 +0200)] 
wg-quick: darwin: account for "link#XX" gateways

On macOS, under specific configurations, the `netstat -nr -f inet` and
`netstat -nr -f inet6` outputs break gateway collection.

Signed-off-by: Laura Hausmann <laura@hausmann.dev>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoipc: windows: use devpkey instead of nci for name
Jason A. Donenfeld [Fri, 30 Jul 2021 22:39:58 +0000 (00:39 +0200)] 
ipc: windows: use devpkey instead of nci for name

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoipc: windows: don't display disabled adapters
Jason A. Donenfeld [Tue, 29 Jun 2021 23:56:24 +0000 (01:56 +0200)] 
ipc: windows: don't display disabled adapters

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoipc: remove windows elevation
Jason A. Donenfeld [Wed, 23 Jun 2021 23:52:06 +0000 (01:52 +0200)] 
ipc: remove windows elevation

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoipc: cache windows lookups to avoid O(n^2) with nested lookups
Jason A. Donenfeld [Thu, 24 Jun 2021 11:35:48 +0000 (13:35 +0200)] 
ipc: cache windows lookups to avoid O(n^2) with nested lookups

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoipc: add wireguard-nt support
Jason A. Donenfeld [Wed, 23 Jun 2021 13:43:39 +0000 (15:43 +0200)] 
ipc: add wireguard-nt support

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agocontrib/launchd: fix xml syntax error
Hangbin Liu [Mon, 17 May 2021 08:17:30 +0000 (16:17 +0800)] 
contrib/launchd: fix xml syntax error

The current plist xml gets error "DOCTYPE improperly terminated" with xml
syntax checker[1]. The example in apple doc[2] also doesn't have semicolon
at the end of DOCTYPE line.

[1] https://www.w3schools.com/xml/xml_validator.asp
[2] https://opensource.apple.com/source/launchd/launchd-257/launchd/doc/HOWTO.html

Fixes: b30e74b5956a ("wg-quick: darwin: support being called from launchd")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoman: mention BSD debugging
Jason A. Donenfeld [Thu, 6 May 2021 10:54:29 +0000 (12:54 +0200)] 
man: mention BSD debugging

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoversion: bump v1.0.20210424
Jason A. Donenfeld [Sat, 24 Apr 2021 20:43:19 +0000 (16:43 -0400)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: kill route monitor when loop terminates
Jason A. Donenfeld [Wed, 21 Apr 2021 03:31:45 +0000 (21:31 -0600)] 
wg-quick: kill route monitor when loop terminates

If the route monitor doesn't attempt to write more to stdout, then this
leaves a process hanging around. Kill it explicitly. We also switch to
using exec in the process substitution, to reduce a bash process.

Closes: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255286
Reported-by: Christos Chatzaras <chris@cretaforce.gr>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: freebsd: use ifconfig for determining if interface is up
Jason A. Donenfeld [Mon, 19 Apr 2021 02:40:02 +0000 (20:40 -0600)] 
wg-quick: freebsd: use ifconfig for determining if interface is up

We no longer need the arp hack, as these bugs have been fixed in the
FreeBSD kernel.

This partially reverts 090639ae90fb45ac05e3158e1e31e5bf15fd9559.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: freebsd: do not assume point-to-point interface flag
Jason A. Donenfeld [Tue, 23 Mar 2021 18:28:22 +0000 (12:28 -0600)] 
wg-quick: freebsd: do not assume point-to-point interface flag

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: freebsd: check for socket using -S, not -f
Jason A. Donenfeld [Sun, 21 Mar 2021 16:15:32 +0000 (10:15 -0600)] 
wg-quick: freebsd: check for socket using -S, not -f

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoversion: bump v1.0.20210315
Jason A. Donenfeld [Mon, 15 Mar 2021 14:04:02 +0000 (08:04 -0600)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: freebsd: avoid writing private keys to /tmp
Jason A. Donenfeld [Sun, 14 Mar 2021 04:20:19 +0000 (21:20 -0700)] 
wg-quick: freebsd: avoid writing private keys to /tmp

FreeBSD's bash doesn't handle <(...) safely, creating a temporary file
instead of using /proc/self/fd/N like on Linux. Work around this by
using a simple pipeline with /dev/stdin.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoipc: uniformly ignore preshared keys that are zero
Jason A. Donenfeld [Thu, 11 Mar 2021 22:35:15 +0000 (15:35 -0700)] 
ipc: uniformly ignore preshared keys that are zero

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoipc: freebsd: add initial FreeBSD support
Jason A. Donenfeld [Thu, 11 Mar 2021 03:24:40 +0000 (20:24 -0700)] 
ipc: freebsd: add initial FreeBSD support

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: freebsd: add kernel support
Jason A. Donenfeld [Thu, 11 Mar 2021 04:17:59 +0000 (21:17 -0700)] 
wg-quick: freebsd: add kernel support

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowireguard-tools: drag in headers for prototypes
Kyle Evans [Wed, 10 Mar 2021 14:44:36 +0000 (08:44 -0600)] 
wireguard-tools: drag in headers for prototypes

ipc.c and terminal.c provide definitions for prototypes in their
respective headers, drag those in.

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
4 years agowireguard-tools: const correctness
Kyle Evans [Wed, 10 Mar 2021 14:43:56 +0000 (08:43 -0600)] 
wireguard-tools: const correctness

Fixes much of the noise from a FreeBSD WARNS=6 build of wg(8)

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
4 years agoMakefile: fix version indicator
Florian Eckert [Thu, 14 May 2020 09:35:20 +0000 (11:35 +0200)] 
Makefile: fix version indicator

If we execute `wg --version` we get a different version string that does
not match with the version string in the openwrt makefile.

Current version string:
`wireguard-tools vreboot-13159-gac5caa2718 -https://git.zx2c4.com/wireguard-tools/`

Corrected versions string:
`wireguard-tools v1.0.20200319 -https://git.zx2c4.com/wireguard-tools/`

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoversion: bump v1.0.20210223
Jason A. Donenfeld [Tue, 23 Feb 2021 18:32:18 +0000 (19:32 +0100)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoipc: read trailing responses after set operation
Jason A. Donenfeld [Wed, 27 Jan 2021 14:22:20 +0000 (15:22 +0100)] 
ipc: read trailing responses after set operation

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoman: LOG_LEVEL variables changed nae
Jason A. Donenfeld [Tue, 26 Jan 2021 22:02:37 +0000 (23:02 +0100)] 
man: LOG_LEVEL variables changed nae

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoipc: do not use fscanf with trailing \n
Jason A. Donenfeld [Mon, 25 Jan 2021 20:22:36 +0000 (21:22 +0100)] 
ipc: do not use fscanf with trailing \n

If the stream is not closed, then this winds up hanging forever. So
remove the trailing \n\n and check manually after.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agosticky-sockets: do not use SO_REUSEADDR
Jason A. Donenfeld [Fri, 18 Dec 2020 22:40:15 +0000 (23:40 +0100)] 
sticky-sockets: do not use SO_REUSEADDR

This makes little sense for unicast UDP sockets.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agocompletion: add help and syncconf completions
Jason A. Donenfeld [Sun, 13 Dec 2020 21:29:09 +0000 (22:29 +0100)] 
completion: add help and syncconf completions

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowincompat: do not elevate by default
Jason A. Donenfeld [Fri, 11 Dec 2020 13:17:27 +0000 (14:17 +0100)] 
wincompat: do not elevate by default

Elevation makes it detach from the console, which means the results are
hidden.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowincompat: add resource and manifest and enable lto
Jason A. Donenfeld [Fri, 11 Dec 2020 12:59:14 +0000 (13:59 +0100)] 
wincompat: add resource and manifest and enable lto

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowincompat: recent mingw has inet_ntop/inet_pton
Jason A. Donenfeld [Mon, 9 Nov 2020 10:46:01 +0000 (11:46 +0100)] 
wincompat: recent mingw has inet_ntop/inet_pton

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoembeddable-wg-library: sync latest from netlink.h
Jason A. Donenfeld [Thu, 29 Oct 2020 11:44:08 +0000 (12:44 +0100)] 
embeddable-wg-library: sync latest from netlink.h

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: openbsd: no use for userspace support
Jason A. Donenfeld [Sun, 18 Oct 2020 20:27:22 +0000 (22:27 +0200)] 
wg-quick: openbsd: no use for userspace support

With alignment between the kernel and userspace, along with userspace
packages, we can now rely on the kernel in the future always having
wg(4).

This also simplifies the interface selection logic, and stores the
wg-quick interface name as the description.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: android: do not free iterated pointer
Jason A. Donenfeld [Tue, 15 Sep 2020 14:19:49 +0000 (16:19 +0200)] 
wg-quick: android: do not free iterated pointer

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoversion: bump v1.0.20200827
Jason A. Donenfeld [Thu, 27 Aug 2020 08:22:09 +0000 (10:22 +0200)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoRevert "wg-quick: wait on process substitutions"
Jason A. Donenfeld [Thu, 27 Aug 2020 08:17:42 +0000 (10:17 +0200)] 
Revert "wg-quick: wait on process substitutions"

This reverts commit 26683f6c9ad18d9914b23312c221f27fd5ecab51, which
means the old problem comes back. That's an issue. But waiting on
process substitutions is not available with commonly used bash versions:

  # wg-quick up demo
  [#] ip link add demo type wireguard
  [#] wg setconf demo /dev/fd/63
  /usr/bin/wg-quick: line 251: wait: pid 2955 is not a child of this shell
  [#] ip link delete dev demo

This means we have to wait a few years before fixing this issue. IOW,
bash limitation; can't fix.

Reported-by: Theodore Mozzo <theodore.mozzo@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: android: use iproute2 to bring up interface instead of ndc
Jason A. Donenfeld [Tue, 25 Aug 2020 19:54:22 +0000 (21:54 +0200)] 
wg-quick: android: use iproute2 to bring up interface instead of ndc

Android 11's ndc regresses even more, but it turns out that netd doesn't
need to track up/down state via direct invocation, so just set the
interface up by way of normal iproute2.

Reported-by: Harsh Shandilya <me@msfjarvis.dev>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoversion: bump v1.0.20200820
Jason A. Donenfeld [Thu, 20 Aug 2020 10:06:22 +0000 (12:06 +0200)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowg-quick: wait on process substitutions
Jason A. Donenfeld [Mon, 3 Aug 2020 08:18:40 +0000 (10:18 +0200)] 
wg-quick: wait on process substitutions

Bash does not propagate error values, which is a bummer, but process
substitutions are a useful feature. Introduce a new idiom to deal with
this: either "; wait $!" after the line to propagate the error, or "||
true" to indicate explicitly that we don't care about the error.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoctype: use non-locale-specific ctype.h
Jason A. Donenfeld [Tue, 4 Aug 2020 12:49:21 +0000 (14:49 +0200)] 
ctype: use non-locale-specific ctype.h

We also make these constant time, even though we're never distinguishing
between bits of a secret using them. From that perspective, though, this
is markedly better than the locale-specific table lookups in glibc, even
though base64 characters span two cache lines and valid private keys
must hit both.

Co-authored-by: Samuel Neves <sneves@dei.uc.pt>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Samuel Neves <sneves@dei.uc.pt>
4 years agopubkey: isblank is a subset of isspace
Jason A. Donenfeld [Tue, 4 Aug 2020 12:04:52 +0000 (14:04 +0200)] 
pubkey: isblank is a subset of isspace

Therefore, there's no need to test both.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoman: wg-quick: use syncconf instead of addconf for strip example
Jason A. Donenfeld [Tue, 28 Jul 2020 08:57:54 +0000 (10:57 +0200)] 
man: wg-quick: use syncconf instead of addconf for strip example

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agosystemd: add reload target to systemd unit
Domonkos P. Tomcsanyi [Fri, 24 Jul 2020 14:21:52 +0000 (16:21 +0200)] 
systemd: add reload target to systemd unit

Users can now run `systemctl reload wg-quick@wgnet0`, as described in
the wg-quick(8) man page. Note that this won't adjust Address=, DNS=, or
the various other non-wg(8) fields.

Signed-off-by: Domonkos P. Tomcsanyi <domi@tomcsanyi.net>
[zx2c4: use exec for bash commands to reduce excess forks, and rewrite
        commit message]
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agowincompat: fold random into genkey
Jason A. Donenfeld [Tue, 26 May 2020 00:05:14 +0000 (18:05 -0600)] 
wincompat: fold random into genkey

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoipc: split into separate files per-platform
Jason A. Donenfeld [Mon, 25 May 2020 23:13:20 +0000 (17:13 -0600)] 
ipc: split into separate files per-platform

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoversion: bump v1.0.20200513
Jason A. Donenfeld [Thu, 14 May 2020 00:29:41 +0000 (18:29 -0600)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoipc: openbsd: switch to array ioctl interface
Jason A. Donenfeld [Wed, 13 May 2020 06:37:46 +0000 (00:37 -0600)] 
ipc: openbsd: switch to array ioctl interface

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoMakefile: remember to install all systemd units
Jason A. Donenfeld [Tue, 12 May 2020 03:31:05 +0000 (21:31 -0600)] 
Makefile: remember to install all systemd units

Reported-by: Unit 193 <unit193@unit193.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoversion: bump v1.0.20200510
Jason A. Donenfeld [Mon, 11 May 2020 04:20:44 +0000 (22:20 -0600)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agowg-quick: cleanup openbsd support
Jason A. Donenfeld [Sun, 10 May 2020 06:58:31 +0000 (00:58 -0600)] 
wg-quick: cleanup openbsd support

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agowg-quick: add support for openbsd kernel implementation
Matt Dunwoodie [Sun, 10 May 2020 08:06:14 +0000 (02:06 -0600)] 
wg-quick: add support for openbsd kernel implementation

Signed-off-by: Matt Dunwoodie <ncon@noconroy.net>
5 years agoipc: cleanup openbsd support
Jason A. Donenfeld [Sun, 10 May 2020 06:24:46 +0000 (00:24 -0600)] 
ipc: cleanup openbsd support

We also add a wg_if.h in the fallback include path.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoipc: add support for openbsd kernel implementation
Matt Dunwoodie [Sun, 29 Dec 2019 01:48:38 +0000 (12:48 +1100)] 
ipc: add support for openbsd kernel implementation

Signed-off-by: Matt Dunwoodie <ncon@noconroy.net>
5 years agoipc: remove extra space
Jason A. Donenfeld [Sun, 10 May 2020 05:20:03 +0000 (23:20 -0600)] 
ipc: remove extra space

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agowg-quick: support dns search domains
Jason A. Donenfeld [Sat, 9 May 2020 05:15:50 +0000 (23:15 -0600)] 
wg-quick: support dns search domains

If DNS= has an IP in it, treat it as a DNS server. If DNS= has a non-IP
in it, treat it as a DNS search domain.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agosystemd: add wg-quick.target
Martin Hauke [Fri, 1 May 2020 21:55:55 +0000 (23:55 +0200)] 
systemd: add wg-quick.target

Add file wg-quick.target, which allows starting and stopping all
wg-quick@.service instances at once.

Signed-off-by: Martin Hauke <mardnh@gmx.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoterminal: specialize color_mode to stdout only
Jason A. Donenfeld [Tue, 21 Apr 2020 04:52:35 +0000 (22:52 -0600)] 
terminal: specialize color_mode to stdout only

By specializing this to stdout, we can cache the isatty result.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agogit: add gitattributes so tarball doesn't have gitignore files
Jason A. Donenfeld [Thu, 9 Apr 2020 05:51:16 +0000 (23:51 -0600)] 
git: add gitattributes so tarball doesn't have gitignore files

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agowg-quick: android: support application whitelist
Jason A. Donenfeld [Mon, 6 Apr 2020 01:38:11 +0000 (19:38 -0600)] 
wg-quick: android: support application whitelist

Prior we only supported a blacklist, but actually a whitelist is an
easier algorithm because that's internally how netd considers it, so we
don't need to find range spans. This commit adds an IncludedApplications
key.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agohighlighter: insist on 256-bit keys, not 257-bit or 258-bit
Jason A. Donenfeld [Sat, 4 Apr 2020 05:14:07 +0000 (23:14 -0600)] 
highlighter: insist on 256-bit keys, not 257-bit or 258-bit

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoMakefile: simplify silent cleaning
Jason A. Donenfeld [Mon, 23 Mar 2020 06:06:24 +0000 (00:06 -0600)] 
Makefile: simplify silent cleaning

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoversion: bump v1.0.20200319
Jason A. Donenfeld [Thu, 19 Mar 2020 22:46:35 +0000 (16:46 -0600)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agowincompat: use new protected prefix on Windows
Jason A. Donenfeld [Thu, 19 Mar 2020 22:33:14 +0000 (16:33 -0600)] 
wincompat: use new protected prefix on Windows

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agowincompat: use string_list instead of inflatable_buffer
Jason A. Donenfeld [Thu, 19 Mar 2020 22:29:27 +0000 (16:29 -0600)] 
wincompat: use string_list instead of inflatable_buffer

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoman: add a warning to the SaveConfig description
Luis Ressel [Mon, 24 Feb 2020 12:00:08 +0000 (13:00 +0100)] 
man: add a warning to the SaveConfig description

Signed-off-by: Luis Ressel <aranea@aixah.de>
[zx2c4: slightly adjusted wording]
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoman: backlink wg-quick(8) in wg(8)
Jason A. Donenfeld [Wed, 12 Feb 2020 14:46:23 +0000 (15:46 +0100)] 
man: backlink wg-quick(8) in wg(8)

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoman: fix grammar in wg(8) and wg-quick(8)
Kai Haberzettl [Sat, 8 Feb 2020 20:23:47 +0000 (21:23 +0100)] 
man: fix grammar in wg(8) and wg-quick(8)

This fixes a few grammatical errors.

Signed-off-by: Kai Haberzettl <khaberz@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agocurve25519: squelch warnings on clang
Jason A. Donenfeld [Fri, 7 Feb 2020 14:46:59 +0000 (15:46 +0100)] 
curve25519: squelch warnings on clang

These are generic helper functions we don't want to move into the actual
implementations, so that it's easy to keep parity with the kernel code.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agonetlink: initialize mostly unused field
Jason A. Donenfeld [Thu, 6 Feb 2020 16:20:15 +0000 (17:20 +0100)] 
netlink: initialize mostly unused field

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoversion: bump v1.0.20200206
Jason A. Donenfeld [Thu, 6 Feb 2020 15:19:47 +0000 (16:19 +0100)] 
version: bump

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agonetlink: don't pretend that sysconf isn't a function
Jason A. Donenfeld [Wed, 5 Feb 2020 22:59:55 +0000 (23:59 +0100)] 
netlink: don't pretend that sysconf isn't a function

We can cache the value of this instead of evaluating every time.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agonetlink: remove libmnl requirement
Jason A. Donenfeld [Mon, 3 Feb 2020 15:52:29 +0000 (16:52 +0100)] 
netlink: remove libmnl requirement

It turns out that the binary actually gets smaller if we simply inline
the very small parts of libmnl that we need. Since we wind up needing
the mnlg bits anyway, there's little benefit in linking to libmnl.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
5 years agoembeddable-wg-library: use newer string_list
Jason A. Donenfeld [Mon, 3 Feb 2020 15:35:01 +0000 (16:35 +0100)] 
embeddable-wg-library: use newer string_list

This ports 1d2d6200b8ff517db0f7530645180df3cc4afa74.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>