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 82edf94df7.

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
pull/1464/head
Denton Gentry 3 years ago committed by Denton Gentry
parent c8af6bc009
commit bcea88da46

@ -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)

Loading…
Cancel
Save