wgengine: support FreeBSD with IPv6.
Fixes for keepsies.
We cannot set the tun interface address as a /128 on FreeBSD,
due to
Instead we set the interface address as a /48, which is enabled
by commit
"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)
