2020-02-12 06:57:45 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-04-30 20:20:09 +00:00
|
|
|
package router
|
2020-02-12 06:57:45 +00:00
|
|
|
|
|
|
|
import (
|
2020-07-14 13:12:00 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-02-12 06:57:45 +00:00
|
|
|
"github.com/tailscale/wireguard-go/device"
|
|
|
|
"github.com/tailscale/wireguard-go/tun"
|
2020-02-15 03:23:16 +00:00
|
|
|
"tailscale.com/types/logger"
|
2020-02-12 06:57:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// For now this router only supports the userspace WireGuard implementations.
|
|
|
|
//
|
2020-02-17 02:37:45 +00:00
|
|
|
// Work is currently underway for an in-kernel FreeBSD implementation of wireguard
|
|
|
|
// https://svnweb.freebsd.org/base?view=revision&revision=357986
|
2020-02-12 06:57:45 +00:00
|
|
|
|
2020-02-17 17:00:38 +00:00
|
|
|
func newUserspaceRouter(logf logger.Logf, _ *device.Device, tundev tun.Device) (Router, error) {
|
2020-06-14 12:18:38 +00:00
|
|
|
return newUserspaceBSDRouter(logf, nil, tundev)
|
2020-02-12 06:57:45 +00:00
|
|
|
}
|
2020-07-14 13:12:00 +00:00
|
|
|
|
|
|
|
func upDNS(config DNSConfig, interfaceName string) error {
|
|
|
|
if len(config.Nameservers) == 0 {
|
|
|
|
return downDNS(interfaceName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resolvconfIsActive() {
|
|
|
|
if err := dnsResolvconfUp(config, interfaceName); err != nil {
|
|
|
|
return fmt.Errorf("resolvconf: %w")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := dnsDirectUp(config); err != nil {
|
|
|
|
return fmt.Errorf("direct: %w")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func downDNS(interfaceName string) error {
|
|
|
|
if resolvconfIsActive() {
|
|
|
|
if err := dnsResolvconfDown(interfaceName); err != nil {
|
|
|
|
return fmt.Errorf("resolvconf: %w")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := dnsDirectDown(); err != nil {
|
|
|
|
return fmt.Errorf("direct: %w")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|