2020-04-30 20:20:09 +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.
|
|
|
|
|
|
|
|
// Package router presents an interface to manipulate the host network
|
|
|
|
// stack's state.
|
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tailscale/wireguard-go/device"
|
|
|
|
"github.com/tailscale/wireguard-go/tun"
|
2020-05-08 05:17:30 +00:00
|
|
|
"inet.af/netaddr"
|
2020-04-30 20:20:09 +00:00
|
|
|
"tailscale.com/types/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Router is responsible for managing the system network stack.
|
|
|
|
//
|
|
|
|
// There is typically only one instance of this interface per process.
|
|
|
|
type Router interface {
|
|
|
|
// Up brings the router up.
|
|
|
|
Up() error
|
|
|
|
|
2020-05-08 01:07:13 +00:00
|
|
|
// Set updates the OS network stack with new settings. It may be
|
|
|
|
// called multiple times with identical Settings, which the
|
|
|
|
// implementation should handle gracefully.
|
|
|
|
Set(Settings) error
|
2020-04-30 20:20:09 +00:00
|
|
|
|
|
|
|
// Close closes the router.
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:37:30 +00:00
|
|
|
// New returns a new Router for the current platform, using the
|
|
|
|
// provided tun device.
|
2020-04-30 20:20:09 +00:00
|
|
|
func New(logf logger.Logf, wgdev *device.Device, tundev tun.Device) (Router, error) {
|
|
|
|
return newUserspaceRouter(logf, wgdev, tundev)
|
|
|
|
}
|
|
|
|
|
2020-05-08 01:07:13 +00:00
|
|
|
// Settings is the subset of Tailscale configuration that is relevant
|
|
|
|
// to the OS's network stack.
|
|
|
|
type Settings struct {
|
2020-05-08 05:17:30 +00:00
|
|
|
LocalAddrs []netaddr.IPPrefix
|
|
|
|
DNS []netaddr.IP
|
2020-05-02 01:55:38 +00:00
|
|
|
DNSDomains []string
|
2020-05-08 05:17:30 +00:00
|
|
|
Routes []netaddr.IPPrefix // routes to point into the Tailscale interface
|
|
|
|
SubnetRoutes []netaddr.IPPrefix // subnets being advertised to other Tailscale nodes
|
2020-04-30 20:20:09 +00:00
|
|
|
}
|