2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-02-05 22:16:58 +00:00
|
|
|
|
2021-02-05 23:44:46 +00:00
|
|
|
// Package netmap contains the netmap.NetworkMap type.
|
|
|
|
package netmap
|
2020-02-05 22:16:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
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 04:14:09 +00:00
|
|
|
"net/netip"
|
2023-09-02 02:28:00 +00:00
|
|
|
"sort"
|
2020-02-05 22:16:58 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"tailscale.com/tailcfg"
|
2022-09-06 23:34:16 +00:00
|
|
|
"tailscale.com/tka"
|
2021-09-03 20:17:46 +00:00
|
|
|
"tailscale.com/types/key"
|
2023-01-03 23:39:32 +00:00
|
|
|
"tailscale.com/types/views"
|
2023-09-02 02:28:00 +00:00
|
|
|
"tailscale.com/util/cmpx"
|
2020-02-05 22:16:58 +00:00
|
|
|
"tailscale.com/wgengine/filter"
|
|
|
|
)
|
|
|
|
|
2021-04-12 19:49:23 +00:00
|
|
|
// NetworkMap is the current state of the world.
|
|
|
|
//
|
|
|
|
// The fields should all be considered read-only. They might
|
|
|
|
// alias parts of previous NetworkMap values.
|
2020-02-05 22:16:58 +00:00
|
|
|
type NetworkMap struct {
|
2023-08-21 17:53:57 +00:00
|
|
|
SelfNode tailcfg.NodeView
|
2021-10-30 01:01:03 +00:00
|
|
|
NodeKey key.NodePublic
|
2021-10-28 17:44:34 +00:00
|
|
|
PrivateKey key.NodePrivate
|
2020-07-29 01:47:23 +00:00
|
|
|
Expiry time.Time
|
|
|
|
// Name is the DNS name assigned to this node.
|
2023-08-20 22:17:25 +00:00
|
|
|
// It is the MapResponse.Node.Name value and ends with a period.
|
|
|
|
Name string
|
|
|
|
|
|
|
|
MachineKey key.MachinePublic
|
2023-08-22 16:41:52 +00:00
|
|
|
|
|
|
|
Peers []tailcfg.NodeView // sorted by Node.ID
|
|
|
|
DNS tailcfg.DNSConfig
|
|
|
|
|
2023-01-03 23:39:32 +00:00
|
|
|
PacketFilter []filter.Match
|
|
|
|
PacketFilterRules views.Slice[tailcfg.FilterRule]
|
|
|
|
SSHPolicy *tailcfg.SSHPolicy // or nil, if not enabled/allowed
|
2020-02-05 22:16:58 +00:00
|
|
|
|
2021-01-11 22:24:32 +00:00
|
|
|
// CollectServices reports whether this node's Tailnet has
|
|
|
|
// requested that info about services be included in HostInfo.
|
|
|
|
// If set, Hostinfo.ShieldsUp blocks services collection; that
|
|
|
|
// takes precedence over this field.
|
|
|
|
CollectServices bool
|
|
|
|
|
2020-05-17 16:51:38 +00:00
|
|
|
// DERPMap is the last DERP server map received. It's reused
|
|
|
|
// between updates and should not be modified.
|
|
|
|
DERPMap *tailcfg.DERPMap
|
|
|
|
|
2021-09-18 19:59:55 +00:00
|
|
|
// ControlHealth are the list of health check problems for this
|
|
|
|
// node from the perspective of the control plane.
|
|
|
|
// If empty, there are no known problems from the control plane's
|
|
|
|
// point of view, but the node might know about its own health
|
|
|
|
// check problems.
|
|
|
|
ControlHealth []string
|
|
|
|
|
2022-09-06 23:34:16 +00:00
|
|
|
// TKAEnabled indicates whether the tailnet key authority should be
|
|
|
|
// enabled, from the perspective of the control plane.
|
|
|
|
TKAEnabled bool
|
|
|
|
// TKAHead indicates the control plane's understanding of 'head' (the
|
|
|
|
// hash of the latest update message to tick through TKA).
|
|
|
|
TKAHead tka.AUMHash
|
|
|
|
|
2022-01-26 17:38:13 +00:00
|
|
|
// Domain is the current Tailnet name.
|
2020-09-30 04:39:43 +00:00
|
|
|
Domain string
|
2021-04-19 02:29:53 +00:00
|
|
|
|
2022-10-06 23:19:38 +00:00
|
|
|
// DomainAuditLogID is an audit log ID provided by control and
|
|
|
|
// only populated if the domain opts into data-plane audit logging.
|
|
|
|
// If this is empty, then data-plane audit logging is disabled.
|
|
|
|
DomainAuditLogID string
|
|
|
|
|
2020-09-30 04:39:43 +00:00
|
|
|
UserProfiles map[tailcfg.UserID]tailcfg.UserProfile
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2023-08-20 22:17:25 +00:00
|
|
|
// User returns nm.SelfNode.User if nm.SelfNode is non-nil, otherwise it returns
|
|
|
|
// 0.
|
|
|
|
func (nm *NetworkMap) User() tailcfg.UserID {
|
2023-08-21 17:53:57 +00:00
|
|
|
if nm.SelfNode.Valid() {
|
|
|
|
return nm.SelfNode.User()
|
2023-08-20 22:17:25 +00:00
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-09-17 17:53:23 +00:00
|
|
|
// GetAddresses returns the self node's addresses, or the zero value
|
|
|
|
// if SelfNode is invalid.
|
|
|
|
func (nm *NetworkMap) GetAddresses() views.Slice[netip.Prefix] {
|
|
|
|
var zero views.Slice[netip.Prefix]
|
|
|
|
if !nm.SelfNode.Valid() {
|
|
|
|
return zero
|
|
|
|
}
|
|
|
|
return nm.SelfNode.Addresses()
|
|
|
|
}
|
|
|
|
|
2022-11-11 17:43:49 +00:00
|
|
|
// AnyPeersAdvertiseRoutes reports whether any peer is advertising non-exit node routes.
|
|
|
|
func (nm *NetworkMap) AnyPeersAdvertiseRoutes() bool {
|
|
|
|
for _, p := range nm.Peers {
|
2023-08-18 14:57:44 +00:00
|
|
|
if p.PrimaryRoutes().Len() > 0 {
|
2022-11-11 17:43:49 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-09-13 17:20:51 +00:00
|
|
|
// GetMachineStatus returns the MachineStatus of the local node.
|
|
|
|
func (nm *NetworkMap) GetMachineStatus() tailcfg.MachineStatus {
|
|
|
|
if !nm.SelfNode.Valid() {
|
|
|
|
return tailcfg.MachineUnknown
|
|
|
|
}
|
|
|
|
if nm.SelfNode.MachineAuthorized() {
|
|
|
|
return tailcfg.MachineAuthorized
|
|
|
|
}
|
|
|
|
return tailcfg.MachineUnauthorized
|
|
|
|
}
|
|
|
|
|
2022-05-28 04:34:36 +00:00
|
|
|
// PeerByTailscaleIP returns a peer's Node based on its Tailscale IP.
|
|
|
|
//
|
|
|
|
// If nm is nil or no peer is found, ok is false.
|
2023-08-18 14:57:44 +00:00
|
|
|
func (nm *NetworkMap) PeerByTailscaleIP(ip netip.Addr) (peer tailcfg.NodeView, ok bool) {
|
2022-05-28 04:34:36 +00:00
|
|
|
// TODO(bradfitz):
|
|
|
|
if nm == nil {
|
2023-08-18 14:57:44 +00:00
|
|
|
return tailcfg.NodeView{}, false
|
2022-05-28 04:34:36 +00:00
|
|
|
}
|
|
|
|
for _, n := range nm.Peers {
|
2023-08-18 14:57:44 +00:00
|
|
|
ad := n.Addresses()
|
|
|
|
for i := 0; i < ad.Len(); i++ {
|
|
|
|
a := ad.At(i)
|
2022-07-25 03:08:42 +00:00
|
|
|
if a.Addr() == ip {
|
2022-05-28 04:34:36 +00:00
|
|
|
return n, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-18 14:57:44 +00:00
|
|
|
return tailcfg.NodeView{}, false
|
2022-05-28 04:34:36 +00:00
|
|
|
}
|
|
|
|
|
2023-09-02 02:28:00 +00:00
|
|
|
// PeerIndexByNodeID returns the index of the peer with the given nodeID
|
|
|
|
// in nm.Peers, or -1 if nm is nil or not found.
|
|
|
|
//
|
|
|
|
// It assumes nm.Peers is sorted by Node.ID.
|
|
|
|
func (nm *NetworkMap) PeerIndexByNodeID(nodeID tailcfg.NodeID) int {
|
|
|
|
if nm == nil {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
idx, ok := sort.Find(len(nm.Peers), func(i int) int {
|
|
|
|
return cmpx.Compare(nodeID, nm.Peers[i].ID())
|
|
|
|
})
|
|
|
|
if !ok {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
return idx
|
|
|
|
}
|
|
|
|
|
2023-08-20 22:17:25 +00:00
|
|
|
// MagicDNSSuffix returns the domain's MagicDNS suffix (even if MagicDNS isn't
|
|
|
|
// necessarily in use) of the provided Node.Name value.
|
2021-01-22 22:28:44 +00:00
|
|
|
//
|
|
|
|
// It will neither start nor end with a period.
|
2023-08-20 22:17:25 +00:00
|
|
|
func MagicDNSSuffixOfNodeName(nodeName string) string {
|
|
|
|
name := strings.Trim(nodeName, ".")
|
2022-03-16 21:25:31 +00:00
|
|
|
if _, rest, ok := strings.Cut(name, "."); ok {
|
|
|
|
return rest
|
2021-01-10 20:03:01 +00:00
|
|
|
}
|
2021-01-22 22:28:44 +00:00
|
|
|
return name
|
2021-01-10 20:03:01 +00:00
|
|
|
}
|
|
|
|
|
2023-08-20 22:17:25 +00:00
|
|
|
// MagicDNSSuffix returns the domain's MagicDNS suffix (even if
|
|
|
|
// MagicDNS isn't necessarily in use).
|
|
|
|
//
|
|
|
|
// It will neither start nor end with a period.
|
|
|
|
func (nm *NetworkMap) MagicDNSSuffix() string {
|
2023-09-08 16:04:54 +00:00
|
|
|
if nm == nil {
|
|
|
|
return ""
|
|
|
|
}
|
2023-08-20 22:17:25 +00:00
|
|
|
return MagicDNSSuffixOfNodeName(nm.Name)
|
|
|
|
}
|
|
|
|
|
2023-03-15 13:24:24 +00:00
|
|
|
// SelfCapabilities returns SelfNode.Capabilities if nm and nm.SelfNode are
|
|
|
|
// non-nil. This is a method so we can use it in envknob/logknob without a
|
|
|
|
// circular dependency.
|
2023-09-06 17:17:25 +00:00
|
|
|
func (nm *NetworkMap) SelfCapabilities() views.Slice[tailcfg.NodeCapability] {
|
|
|
|
var zero views.Slice[tailcfg.NodeCapability]
|
2023-08-21 17:53:57 +00:00
|
|
|
if nm == nil || !nm.SelfNode.Valid() {
|
|
|
|
return zero
|
2023-03-15 13:24:24 +00:00
|
|
|
}
|
2023-09-18 15:52:22 +00:00
|
|
|
out := nm.SelfNode.Capabilities().AsSlice()
|
|
|
|
nm.SelfNode.CapMap().Range(func(k tailcfg.NodeCapability, _ views.Slice[tailcfg.RawMessage]) (cont bool) {
|
|
|
|
out = append(out, k)
|
|
|
|
return true
|
|
|
|
})
|
2023-03-15 13:24:24 +00:00
|
|
|
|
2023-09-18 15:52:22 +00:00
|
|
|
return views.SliceOf(out)
|
2023-03-15 13:24:24 +00:00
|
|
|
}
|
|
|
|
|
2021-01-10 20:03:01 +00:00
|
|
|
func (nm *NetworkMap) String() string {
|
2020-02-05 22:16:58 +00:00
|
|
|
return nm.Concise()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nm *NetworkMap) Concise() string {
|
|
|
|
buf := new(strings.Builder)
|
2020-07-23 17:50:06 +00:00
|
|
|
|
|
|
|
nm.printConciseHeader(buf)
|
|
|
|
for _, p := range nm.Peers {
|
|
|
|
printPeerConcise(buf, p)
|
|
|
|
}
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
|
2021-08-17 17:05:20 +00:00
|
|
|
func (nm *NetworkMap) VeryConcise() string {
|
|
|
|
buf := new(strings.Builder)
|
|
|
|
nm.printConciseHeader(buf)
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:31:10 +00:00
|
|
|
// PeerWithStableID finds and returns the peer associated to the inputted StableNodeID.
|
2023-08-18 14:57:44 +00:00
|
|
|
func (nm *NetworkMap) PeerWithStableID(pid tailcfg.StableNodeID) (_ tailcfg.NodeView, ok bool) {
|
2022-06-07 19:31:10 +00:00
|
|
|
for _, p := range nm.Peers {
|
2023-08-18 14:57:44 +00:00
|
|
|
if p.StableID() == pid {
|
2022-06-07 19:31:10 +00:00
|
|
|
return p, true
|
|
|
|
}
|
|
|
|
}
|
2023-08-18 14:57:44 +00:00
|
|
|
return tailcfg.NodeView{}, false
|
2022-06-07 19:31:10 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 17:50:06 +00:00
|
|
|
// printConciseHeader prints a concise header line representing nm to buf.
|
|
|
|
//
|
|
|
|
// If this function is changed to access different fields of nm, keep
|
|
|
|
// in equalConciseHeader in sync.
|
|
|
|
func (nm *NetworkMap) printConciseHeader(buf *strings.Builder) {
|
2020-06-25 17:47:33 +00:00
|
|
|
fmt.Fprintf(buf, "netmap: self: %v auth=%v",
|
2023-09-13 17:20:51 +00:00
|
|
|
nm.NodeKey.ShortString(), nm.GetMachineStatus())
|
2023-08-20 22:17:25 +00:00
|
|
|
login := nm.UserProfiles[nm.User()].LoginName
|
2020-10-27 20:46:05 +00:00
|
|
|
if login == "" {
|
2023-08-20 22:17:25 +00:00
|
|
|
if nm.User().IsZero() {
|
2020-10-27 20:46:05 +00:00
|
|
|
login = "?"
|
|
|
|
} else {
|
2023-08-20 22:17:25 +00:00
|
|
|
login = fmt.Sprint(nm.User())
|
2020-10-27 20:46:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Fprintf(buf, " u=%s", login)
|
2023-09-18 06:31:34 +00:00
|
|
|
fmt.Fprintf(buf, " %v", nm.GetAddresses().AsSlice())
|
2020-06-25 17:47:33 +00:00
|
|
|
buf.WriteByte('\n')
|
2020-07-23 17:50:06 +00:00
|
|
|
}
|
2020-03-13 02:29:24 +00:00
|
|
|
|
2020-07-23 17:50:06 +00:00
|
|
|
// equalConciseHeader reports whether a and b are equal for the fields
|
|
|
|
// used by printConciseHeader.
|
|
|
|
func (a *NetworkMap) equalConciseHeader(b *NetworkMap) bool {
|
2023-09-18 06:31:34 +00:00
|
|
|
return a.NodeKey == b.NodeKey &&
|
|
|
|
a.GetMachineStatus() == b.GetMachineStatus() &&
|
|
|
|
a.User() == b.User() &&
|
|
|
|
views.SliceEqual(a.GetAddresses(), b.GetAddresses())
|
2020-07-23 17:50:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 17:05:20 +00:00
|
|
|
// printPeerConcise appends to buf a line representing the peer p.
|
2020-07-23 17:50:06 +00:00
|
|
|
//
|
|
|
|
// If this function is changed to access different fields of p, keep
|
|
|
|
// in nodeConciseEqual in sync.
|
2023-08-18 14:57:44 +00:00
|
|
|
func printPeerConcise(buf *strings.Builder, p tailcfg.NodeView) {
|
|
|
|
aip := make([]string, p.AllowedIPs().Len())
|
|
|
|
for i := range aip {
|
|
|
|
a := p.AllowedIPs().At(i)
|
2020-07-23 17:50:06 +00:00
|
|
|
s := strings.TrimSuffix(fmt.Sprint(a), "/32")
|
|
|
|
aip[i] = s
|
|
|
|
}
|
2020-03-13 02:29:24 +00:00
|
|
|
|
2023-08-18 14:57:44 +00:00
|
|
|
ep := make([]string, p.Endpoints().Len())
|
|
|
|
for i := range ep {
|
2023-10-01 04:05:02 +00:00
|
|
|
e := p.Endpoints().At(i).String()
|
2020-07-23 17:50:06 +00:00
|
|
|
// Align vertically on the ':' between IP and port
|
|
|
|
colon := strings.IndexByte(e, ':')
|
|
|
|
spaces := 0
|
|
|
|
for colon > 0 && len(e)+spaces-colon < 6 {
|
|
|
|
spaces++
|
|
|
|
colon--
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
2020-07-23 17:50:06 +00:00
|
|
|
ep[i] = fmt.Sprintf("%21v", e+strings.Repeat(" ", spaces))
|
|
|
|
}
|
2020-03-13 02:29:24 +00:00
|
|
|
|
2023-08-18 14:57:44 +00:00
|
|
|
derp := p.DERP()
|
2020-07-23 17:50:06 +00:00
|
|
|
const derpPrefix = "127.3.3.40:"
|
|
|
|
if strings.HasPrefix(derp, derpPrefix) {
|
|
|
|
derp = "D" + derp[len(derpPrefix):]
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
2020-08-03 17:00:16 +00:00
|
|
|
var discoShort string
|
2023-08-18 14:57:44 +00:00
|
|
|
if !p.DiscoKey().IsZero() {
|
|
|
|
discoShort = p.DiscoKey().ShortString() + " "
|
2020-08-03 17:00:16 +00:00
|
|
|
}
|
2020-07-23 17:50:06 +00:00
|
|
|
|
|
|
|
// Most of the time, aip is just one element, so format the
|
|
|
|
// table to look good in that case. This will also make multi-
|
|
|
|
// subnet nodes stand out visually.
|
2020-08-03 17:00:16 +00:00
|
|
|
fmt.Fprintf(buf, " %v %s%-2v %-15v : %v\n",
|
2023-08-18 14:57:44 +00:00
|
|
|
p.Key().ShortString(),
|
2020-08-03 17:00:16 +00:00
|
|
|
discoShort,
|
|
|
|
derp,
|
2020-07-23 17:50:06 +00:00
|
|
|
strings.Join(aip, " "),
|
|
|
|
strings.Join(ep, " "))
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 17:50:06 +00:00
|
|
|
// nodeConciseEqual reports whether a and b are equal for the fields accessed by printPeerConcise.
|
2023-08-18 14:57:44 +00:00
|
|
|
func nodeConciseEqual(a, b tailcfg.NodeView) bool {
|
|
|
|
return a.Key() == b.Key() &&
|
|
|
|
a.DERP() == b.DERP() &&
|
|
|
|
a.DiscoKey() == b.DiscoKey() &&
|
2023-09-09 03:40:43 +00:00
|
|
|
views.SliceEqual(a.AllowedIPs(), b.AllowedIPs()) &&
|
|
|
|
views.SliceEqual(a.Endpoints(), b.Endpoints())
|
2020-07-23 17:50:06 +00:00
|
|
|
}
|
2020-03-13 03:01:08 +00:00
|
|
|
|
2020-07-23 17:50:06 +00:00
|
|
|
func (b *NetworkMap) ConciseDiffFrom(a *NetworkMap) string {
|
|
|
|
var diff strings.Builder
|
2020-03-13 03:01:08 +00:00
|
|
|
|
2020-07-23 17:50:06 +00:00
|
|
|
// See if header (non-peers, "bare") part of the network map changed.
|
|
|
|
// If so, print its diff lines first.
|
|
|
|
if !a.equalConciseHeader(b) {
|
|
|
|
diff.WriteByte('-')
|
|
|
|
a.printConciseHeader(&diff)
|
|
|
|
diff.WriteByte('+')
|
|
|
|
b.printConciseHeader(&diff)
|
2020-03-13 03:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 17:50:06 +00:00
|
|
|
aps, bps := a.Peers, b.Peers
|
|
|
|
for len(aps) > 0 && len(bps) > 0 {
|
|
|
|
pa, pb := aps[0], bps[0]
|
|
|
|
switch {
|
2023-08-18 14:57:44 +00:00
|
|
|
case pa.ID() == pb.ID():
|
2020-07-23 17:50:06 +00:00
|
|
|
if !nodeConciseEqual(pa, pb) {
|
|
|
|
diff.WriteByte('-')
|
|
|
|
printPeerConcise(&diff, pa)
|
|
|
|
diff.WriteByte('+')
|
|
|
|
printPeerConcise(&diff, pb)
|
|
|
|
}
|
|
|
|
aps, bps = aps[1:], bps[1:]
|
2023-08-18 14:57:44 +00:00
|
|
|
case pa.ID() > pb.ID():
|
2020-07-23 17:50:06 +00:00
|
|
|
// New peer in b.
|
|
|
|
diff.WriteByte('+')
|
|
|
|
printPeerConcise(&diff, pb)
|
|
|
|
bps = bps[1:]
|
2023-08-18 14:57:44 +00:00
|
|
|
case pb.ID() > pa.ID():
|
2020-07-23 17:50:06 +00:00
|
|
|
// Deleted peer in b.
|
|
|
|
diff.WriteByte('-')
|
|
|
|
printPeerConcise(&diff, pa)
|
|
|
|
aps = aps[1:]
|
2020-03-13 03:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-23 17:50:06 +00:00
|
|
|
for _, pa := range aps {
|
|
|
|
diff.WriteByte('-')
|
|
|
|
printPeerConcise(&diff, pa)
|
2020-03-13 03:01:08 +00:00
|
|
|
}
|
2020-07-23 17:50:06 +00:00
|
|
|
for _, pb := range bps {
|
|
|
|
diff.WriteByte('+')
|
|
|
|
printPeerConcise(&diff, pb)
|
|
|
|
}
|
|
|
|
return diff.String()
|
2020-03-13 03:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 22:16:58 +00:00
|
|
|
func (nm *NetworkMap) JSON() string {
|
|
|
|
b, err := json.MarshalIndent(*nm, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Sprintf("[json error: %v]", err)
|
|
|
|
}
|
|
|
|
return string(b)
|
|
|
|
}
|
|
|
|
|
2020-07-23 15:38:14 +00:00
|
|
|
// WGConfigFlags is a bitmask of flags to control the behavior of the
|
|
|
|
// wireguard configuration generation done by NetMap.WGCfg.
|
|
|
|
type WGConfigFlags int
|
2020-02-05 22:16:58 +00:00
|
|
|
|
2020-07-23 15:38:14 +00:00
|
|
|
const (
|
|
|
|
AllowSingleHosts WGConfigFlags = 1 << iota
|
|
|
|
AllowSubnetRoutes
|
2020-02-05 22:16:58 +00:00
|
|
|
)
|