mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-27 12:05:40 +00:00
af97e7a793
This adds a new bool that can be sent down from control to do jailing on the client side. Previously this would only be done from control by modifying the packet filter we sent down to clients. This would result in a lot of additional work/CPU on control, we could instead just do this on the client. This has always been a TODO which we keep putting off, might as well do it now. Updates tailscale/corp#19623 Signed-off-by: Maisem Ali <maisem@tailscale.com>
62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package wgcfg has types and a parser for representing WireGuard config.
|
|
package wgcfg
|
|
|
|
import (
|
|
"net/netip"
|
|
|
|
"tailscale.com/tailcfg"
|
|
"tailscale.com/types/key"
|
|
"tailscale.com/types/logid"
|
|
)
|
|
|
|
//go:generate go run tailscale.com/cmd/cloner -type=Config,Peer
|
|
|
|
// Config is a WireGuard configuration.
|
|
// It only supports the set of things Tailscale uses.
|
|
type Config struct {
|
|
Name string
|
|
NodeID tailcfg.StableNodeID
|
|
PrivateKey key.NodePrivate
|
|
Addresses []netip.Prefix
|
|
MTU uint16
|
|
DNS []netip.Addr
|
|
Peers []Peer
|
|
|
|
// NetworkLogging enables network logging.
|
|
// It is disabled if either ID is the zero value.
|
|
// LogExitFlowEnabled indicates whether or not exit flows should be logged.
|
|
NetworkLogging struct {
|
|
NodeID logid.PrivateID
|
|
DomainID logid.PrivateID
|
|
LogExitFlowEnabled bool
|
|
}
|
|
}
|
|
|
|
type Peer struct {
|
|
PublicKey key.NodePublic
|
|
DiscoKey key.DiscoPublic // present only so we can handle restarts within wgengine, not passed to WireGuard
|
|
AllowedIPs []netip.Prefix
|
|
V4MasqAddr *netip.Addr // if non-nil, masquerade IPv4 traffic to this peer using this address
|
|
V6MasqAddr *netip.Addr // if non-nil, masquerade IPv6 traffic to this peer using this address
|
|
IsJailed bool // if true, this peer is jailed and cannot initiate connections
|
|
PersistentKeepalive uint16 // in seconds between keep-alives; 0 to disable
|
|
// wireguard-go's endpoint for this peer. It should always equal Peer.PublicKey.
|
|
// We represent it explicitly so that we can detect if they diverge and recover.
|
|
// There is no need to set WGEndpoint explicitly when constructing a Peer by hand.
|
|
// It is only populated when reading Peers from wireguard-go.
|
|
WGEndpoint key.NodePublic
|
|
}
|
|
|
|
// PeerWithKey returns the Peer with key k and reports whether it was found.
|
|
func (config Config) PeerWithKey(k key.NodePublic) (Peer, bool) {
|
|
for _, p := range config.Peers {
|
|
if p.PublicKey == k {
|
|
return p, true
|
|
}
|
|
}
|
|
return Peer{}, false
|
|
}
|