mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-28 03:52:35 +00:00
router: split off sandboxed path from router_darwin (#624)
Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
This commit is contained in:
parent
cb970539a6
commit
8c850947db
@ -10,55 +10,14 @@ import (
|
|||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type darwinRouter struct {
|
func newUserspaceRouter(logf logger.Logf, wgdev *device.Device, tundev tun.Device) (Router, error) {
|
||||||
logf logger.Logf
|
return newUserspaceBSDRouter(logf, wgdev, tundev)
|
||||||
tunname string
|
|
||||||
Router
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUserspaceRouter(logf logger.Logf, _ *device.Device, tundev tun.Device) (Router, error) {
|
// TODO(dmytro): the following should use a macOS-specific method such as scutil.
|
||||||
tunname, err := tundev.Name()
|
// This is currently not implemented. Editing /etc/resolv.conf does not work,
|
||||||
if err != nil {
|
// as most applications use the system resolver, which disregards it.
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
userspaceRouter, err := newUserspaceBSDRouter(logf, nil, tundev)
|
func upDNS(DNSConfig, string) error { return nil }
|
||||||
if err != nil {
|
func downDNS(string) error { return nil }
|
||||||
return nil, err
|
func cleanup(logger.Logf, string) {}
|
||||||
}
|
|
||||||
|
|
||||||
return &darwinRouter{
|
|
||||||
logf: logf,
|
|
||||||
tunname: tunname,
|
|
||||||
Router: userspaceRouter,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *darwinRouter) Set(cfg *Config) error {
|
|
||||||
if cfg == nil {
|
|
||||||
cfg = &shutdownConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
if SetRoutesFunc != nil {
|
|
||||||
return SetRoutesFunc(cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.Router.Set(cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *darwinRouter) Up() error {
|
|
||||||
if SetRoutesFunc != nil {
|
|
||||||
return nil // bringing up the tunnel is handled externally
|
|
||||||
}
|
|
||||||
return r.Router.Up()
|
|
||||||
}
|
|
||||||
|
|
||||||
func upDNS(config DNSConfig, interfaceName string) error {
|
|
||||||
// Handled by IPNExtension
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func downDNS(interfaceName string) error {
|
|
||||||
// Handled by IPNExtension
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
package router
|
|
||||||
|
|
||||||
// SetRoutesFunc applies the given router settings to the OS network
|
|
||||||
// stack. cfg is guaranteed to be non-nil.
|
|
||||||
//
|
|
||||||
// This is logically part of the router_darwin.go implementation, and
|
|
||||||
// should not be used on other platforms.
|
|
||||||
//
|
|
||||||
// The code to reconfigure the network stack on MacOS and iOS is in
|
|
||||||
// the non-open `ipn-go-bridge` package, which bridges between the Go
|
|
||||||
// and Swift pieces of the application. The ipn-go-bridge sets
|
|
||||||
// SetRoutesFunc at startup.
|
|
||||||
//
|
|
||||||
// So why isn't this in router_darwin.go? Because in the non-oss
|
|
||||||
// repository, we build ipn-go-bridge when developing on Linux as well
|
|
||||||
// as MacOS, so that we don't have to wait until the Mac CI to
|
|
||||||
// discover that we broke it. So this one definition needs to exist in
|
|
||||||
// both the darwin and linux builds. Hence this file and build tag.
|
|
||||||
var SetRoutesFunc func(cfg *Config) error
|
|
@ -52,3 +52,17 @@ func downDNS(interfaceName string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanup(logf logger.Logf, interfaceName string) {
|
||||||
|
if err := downDNS(interfaceName); err != nil {
|
||||||
|
logf("dns down: %v", err)
|
||||||
|
}
|
||||||
|
// If the interface was left behind, ifconfig down will not remove it.
|
||||||
|
// In fact, this will leave a system in a tainted state where starting tailscaled
|
||||||
|
// will result in "interface tailscale0 already exists"
|
||||||
|
// until the defunct interface is ifconfig-destroyed.
|
||||||
|
ifup := []string{"ifconfig", interfaceName, "destroy"}
|
||||||
|
if out, err := cmd(ifup...).CombinedOutput(); err != nil {
|
||||||
|
logf("ifconfig destroy: %v\n%s", err, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -159,17 +159,3 @@ func (r *userspaceBSDRouter) Close() error {
|
|||||||
// No interface cleanup is necessary during normal shutdown.
|
// No interface cleanup is necessary during normal shutdown.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanup(logf logger.Logf, interfaceName string) {
|
|
||||||
if err := downDNS(interfaceName); err != nil {
|
|
||||||
logf("dns down: %v", err)
|
|
||||||
}
|
|
||||||
// If the interface was left behind, ifconfig down will not remove it.
|
|
||||||
// In fact, this will leave a system in a tainted state where starting tailscaled
|
|
||||||
// will result in "interface tailscale0 already exists"
|
|
||||||
// until the defunct interface is ifconfig-destroyed.
|
|
||||||
ifup := []string{"ifconfig", interfaceName, "destroy"}
|
|
||||||
if out, err := cmd(ifup...).CombinedOutput(); err != nil {
|
|
||||||
logf("ifconfig destroy: %v\n%s", err, out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user