2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-01-29 20:16:36 +00:00
|
|
|
|
|
|
|
// Package wgcfg has types and a parser for representing WireGuard config.
|
|
|
|
package wgcfg
|
|
|
|
|
|
|
|
import (
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
"net/netip"
|
|
|
|
|
2022-10-28 18:09:30 +01:00
|
|
|
"tailscale.com/tailcfg"
|
2021-10-28 01:42:33 +01:00
|
|
|
"tailscale.com/types/key"
|
2023-03-01 03:00:00 +00:00
|
|
|
"tailscale.com/types/logid"
|
2021-01-29 20:16:36 +00:00
|
|
|
)
|
|
|
|
|
2022-05-02 00:15:14 +01:00
|
|
|
//go:generate go run tailscale.com/cmd/cloner -type=Config,Peer
|
2021-02-05 20:44:43 +00:00
|
|
|
|
2021-01-29 20:16:36 +00:00
|
|
|
// Config is a WireGuard configuration.
|
|
|
|
// It only supports the set of things Tailscale uses.
|
|
|
|
type Config struct {
|
|
|
|
Name string
|
2022-10-28 18:09:30 +01:00
|
|
|
NodeID tailcfg.StableNodeID
|
2021-10-28 01:42:33 +01:00
|
|
|
PrivateKey key.NodePrivate
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Addresses []netip.Prefix
|
2021-01-29 20:16:36 +00:00
|
|
|
MTU uint16
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
DNS []netip.Addr
|
2021-01-29 20:16:36 +00:00
|
|
|
Peers []Peer
|
2022-10-07 00:19:38 +01:00
|
|
|
|
|
|
|
// NetworkLogging enables network logging.
|
|
|
|
// It is disabled if either ID is the zero value.
|
|
|
|
NetworkLogging struct {
|
2023-03-01 03:00:00 +00:00
|
|
|
NodeID logid.PrivateID
|
|
|
|
DomainID logid.PrivateID
|
2022-10-07 00:19:38 +01:00
|
|
|
}
|
2021-01-29 20:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Peer struct {
|
2021-10-28 01:42:33 +01:00
|
|
|
PublicKey key.NodePublic
|
2021-10-29 22:27:29 +01:00
|
|
|
DiscoKey key.DiscoPublic // present only so we can handle restarts within wgengine, not passed to WireGuard
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
AllowedIPs []netip.Prefix
|
2023-03-29 17:51:18 +01:00
|
|
|
V4MasqAddr netip.Addr // if non-zero, masquerade IPv4 traffic to this peer using this address
|
2021-01-29 20:16:36 +00:00
|
|
|
PersistentKeepalive uint16
|
2021-11-11 02:42:16 +00:00
|
|
|
// 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
|
2021-01-29 20:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PeerWithKey returns the Peer with key k and reports whether it was found.
|
2021-10-28 01:42:33 +01:00
|
|
|
func (config Config) PeerWithKey(k key.NodePublic) (Peer, bool) {
|
2021-01-29 20:16:36 +00:00
|
|
|
for _, p := range config.Peers {
|
|
|
|
if p.PublicKey == k {
|
|
|
|
return p, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Peer{}, false
|
|
|
|
}
|