mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 19:45:35 +00:00
85184a58ed
In rare circumstances (tailscale/corp#3016), the PublicKey and Endpoints can diverge. This by itself doesn't cause any harm, but our early exit in response did, because it prevented us from recovering from it. Remove the early exit. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
// Copyright (c) 2021 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 wgcfg has types and a parser for representing WireGuard config.
|
|
package wgcfg
|
|
|
|
import (
|
|
"inet.af/netaddr"
|
|
"tailscale.com/types/key"
|
|
)
|
|
|
|
//go:generate go run tailscale.com/cmd/cloner -type=Config,Peer -output=clone.go
|
|
|
|
// Config is a WireGuard configuration.
|
|
// It only supports the set of things Tailscale uses.
|
|
type Config struct {
|
|
Name string
|
|
PrivateKey key.NodePrivate
|
|
Addresses []netaddr.IPPrefix
|
|
MTU uint16
|
|
DNS []netaddr.IP
|
|
Peers []Peer
|
|
}
|
|
|
|
type Peer struct {
|
|
PublicKey key.NodePublic
|
|
DiscoKey key.DiscoPublic // present only so we can handle restarts within wgengine, not passed to WireGuard
|
|
AllowedIPs []netaddr.IPPrefix
|
|
PersistentKeepalive uint16
|
|
// 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
|
|
}
|