From bcea88da46e0536cb255784c086021ae80c55837 Mon Sep 17 00:00:00 2001 From: Denton Gentry Date: Thu, 4 Mar 2021 16:36:28 -0800 Subject: [PATCH] wgengine: support FreeBSD with IPv6. Fixes https://github.com/tailscale/tailscale/issues/1307 for keepsies. We cannot set the tun interface address as a /128 on FreeBSD, due to https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=218508 Instead we set the interface address as a /48, which is enabled by commit 82edf94df72a52bcdc95fe37b20217e6003d92c0. Signed-off-by: Denton Gentry --- wgengine/router/router_userspace_bsd.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wgengine/router/router_userspace_bsd.go b/wgengine/router/router_userspace_bsd.go index fb81d62fb..419a6d914 100644 --- a/wgengine/router/router_userspace_bsd.go +++ b/wgengine/router/router_userspace_bsd.go @@ -10,6 +10,7 @@ import ( "fmt" "log" "os/exec" + "runtime" "github.com/tailscale/wireguard-go/device" "github.com/tailscale/wireguard-go/tun" @@ -123,7 +124,17 @@ func (r *userspaceBSDRouter) Set(cfg *Config) (reterr error) { } } for _, addr := range r.addrsToAdd(cfg.LocalAddrs) { - arg := []string{"ifconfig", r.tunname, inet(addr), addr.String(), addr.IP.String()} + var arg []string + if runtime.GOOS == "freebsd" && addr.IP.Is6() && addr.Bits == 128 { + // FreeBSD rejects tun addresses of the form fc00::1/128 -> fc00::1, + // https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=218508 + // Instead add our whole /48, which works because we use a /48 route. + // Full history: https://github.com/tailscale/tailscale/issues/1307 + tmp := netaddr.IPPrefix{addr.IP, 48} + arg = []string{"ifconfig", r.tunname, inet(tmp), tmp.String()} + } else { + arg = []string{"ifconfig", r.tunname, inet(addr), addr.String(), addr.IP.String()} + } out, err := cmd(arg...).CombinedOutput() if err != nil { r.logf("addr add failed: %v => %v\n%s", arg, err, out)