Bug 279850 - wireguard: wg(8) fails on INET6-only kernel
Summary: wireguard: wg(8) fails on INET6-only kernel
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Kyle Evans
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-19 05:22 UTC by Lexi Winter
Modified: 2024-06-25 20:46 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lexi Winter 2024-06-19 05:22:20 UTC
when the kernel does not have 'options INET', wg(8) doesn't work:

# uname -v
FreeBSD 15.0-CURRENT #1 lf/main-n269054-1557b4dd4096: Tue Jun 18 02:22:42 BST 2024     srcmastr@daphne.eden.le-fay.org:/src/obj/src/freebsd/lf/main/arm64.aarch64/sys/LFV6
# wg
Unable to list interfaces: Address family not supported by protocol family
#

truss:

socket(PF_INET,SOCK_DGRAM,0)			 ERR#47 'Address family not supported by protocol family'
issetugid()					 = 0 (0x0)
fstatat(AT_FDCWD,"/usr/share/nls/C/libc.cat",0x4bf984865b90,0x0) ERR#2 'No such file or directory'
fstatat(AT_FDCWD,"/usr/share/nls/libc/C",0x4bf984865b90,0x0) ERR#2 'No such file or directory'
fstatat(AT_FDCWD,"/usr/local/share/nls/C/libc.cat",0x4bf984865b90,0x0) ERR#2 'No such file or directory'
fstatat(AT_FDCWD,"/usr/local/share/nls/libc/C",0x4bf984865b90,0x0) ERR#2 'No such file or directory'
Unable to list interfaces: Address family not supported by protocol family
writev(2,[{"Unable to list interfaces",25},{": ",2},{"Address family not supported by "...,47},{"\n",1}],4) = 75 (0x4b)
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2024-06-19 22:33:17 UTC
How does this feel?

diff --git a/contrib/wireguard-tools/ipc-freebsd.h b/contrib/wireguard-tools/ipc-freebsd.h
index fa74edda5a3d..446f13cacac2 100644
--- a/contrib/wireguard-tools/ipc-freebsd.h
+++ b/contrib/wireguard-tools/ipc-freebsd.h
@@ -15,7 +15,7 @@ static int get_dgram_socket(void)
 {
        static int sock = -1;
        if (sock < 0)
-               sock = socket(AF_INET, SOCK_DGRAM, 0);
+               sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
        return sock;
 }
Comment 2 crest 2024-06-25 16:13:44 UTC
From running `truss wg` on a system with IPv4 support in the kernel and a single unconfigured WireGuard interface it looks like the socket is used at least for the SIOCGIFGMEMB and SIOCGWG:

ioctl(3,SIOCGIFGMEMB,0x1...)		 = 0 (0x0)
ioctl(3,SIOCGIFGMEMB,0x1...)		 = 0 (0x0)
ioctl(3,SIOCGWG,0x1...)			 = 0 (0x0)
ioctl(3,SIOCGWG,0x1...)			 = 0 (0x0)

Are those ioctl()s available on AF_UNIX and AF_INET6 sockets or only on AF_INET sockets?
Comment 3 Kyle Evans freebsd_committer freebsd_triage 2024-06-25 20:46:40 UTC
(In reply to crest from comment #2)

There's a patch in comment #1 that you're welcome to test.