2020-02-05 22:16:58 +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 controlclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-07-23 15:30:09 +00:00
|
|
|
"net"
|
2020-06-24 22:00:02 +00:00
|
|
|
"reflect"
|
2020-07-23 15:30:09 +00:00
|
|
|
"strconv"
|
2020-02-05 22:16:58 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/tailscale/wireguard-go/wgcfg"
|
2020-12-24 20:33:55 +00:00
|
|
|
"inet.af/netaddr"
|
2020-02-05 22:16:58 +00:00
|
|
|
"tailscale.com/tailcfg"
|
2020-06-18 23:24:44 +00:00
|
|
|
"tailscale.com/types/logger"
|
2020-12-30 01:22:56 +00:00
|
|
|
"tailscale.com/types/wgkey"
|
2020-02-05 22:16:58 +00:00
|
|
|
"tailscale.com/wgengine/filter"
|
|
|
|
)
|
|
|
|
|
|
|
|
type NetworkMap struct {
|
|
|
|
// Core networking
|
|
|
|
|
2021-01-27 16:50:31 +00:00
|
|
|
SelfNode *tailcfg.Node
|
2020-07-29 01:47:23 +00:00
|
|
|
NodeKey tailcfg.NodeKey
|
2020-12-30 01:22:56 +00:00
|
|
|
PrivateKey wgkey.Private
|
2020-07-29 01:47:23 +00:00
|
|
|
Expiry time.Time
|
|
|
|
// Name is the DNS name assigned to this node.
|
2021-01-27 16:50:31 +00:00
|
|
|
Name string
|
2020-12-24 20:33:55 +00:00
|
|
|
Addresses []netaddr.IPPrefix
|
2020-02-05 22:16:58 +00:00
|
|
|
LocalPort uint16 // used for debugging
|
|
|
|
MachineStatus tailcfg.MachineStatus
|
2020-09-28 22:28:26 +00:00
|
|
|
MachineKey tailcfg.MachineKey
|
2020-07-23 17:50:06 +00:00
|
|
|
Peers []*tailcfg.Node // sorted by Node.ID
|
2020-07-31 20:27:09 +00:00
|
|
|
DNS tailcfg.DNSConfig
|
2020-02-05 22:16:58 +00:00
|
|
|
Hostinfo tailcfg.Hostinfo
|
2020-11-10 05:33:41 +00:00
|
|
|
PacketFilter []filter.Match
|
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
|
|
|
|
|
2020-06-25 17:47:33 +00:00
|
|
|
// Debug knobs from control server for debug or feature gating.
|
|
|
|
Debug *tailcfg.Debug
|
|
|
|
|
2020-02-05 22:16:58 +00:00
|
|
|
// ACLs
|
|
|
|
|
2020-09-30 04:39:43 +00:00
|
|
|
User tailcfg.UserID
|
|
|
|
Domain string
|
|
|
|
// TODO(crawshaw): reduce UserProfiles to []tailcfg.UserProfile?
|
|
|
|
// There are lots of ways to slice this data, leave it up to users.
|
|
|
|
UserProfiles map[tailcfg.UserID]tailcfg.UserProfile
|
2020-02-05 22:16:58 +00:00
|
|
|
// TODO(crawshaw): Groups []tailcfg.Group
|
|
|
|
// TODO(crawshaw): Capabilities []tailcfg.Capability
|
|
|
|
}
|
|
|
|
|
2021-01-22 22:28:44 +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.
|
2021-01-10 20:03:01 +00:00
|
|
|
func (nm *NetworkMap) MagicDNSSuffix() string {
|
2021-01-22 22:28:44 +00:00
|
|
|
name := strings.Trim(nm.Name, ".")
|
|
|
|
if i := strings.Index(name, "."); i != -1 {
|
|
|
|
name = name[i+1:]
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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",
|
|
|
|
nm.NodeKey.ShortString(), nm.MachineStatus)
|
2020-10-27 20:46:05 +00:00
|
|
|
login := nm.UserProfiles[nm.User].LoginName
|
|
|
|
if login == "" {
|
|
|
|
if nm.User.IsZero() {
|
|
|
|
login = "?"
|
|
|
|
} else {
|
|
|
|
login = fmt.Sprint(nm.User)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Fprintf(buf, " u=%s", login)
|
2020-06-25 17:47:33 +00:00
|
|
|
if nm.LocalPort != 0 {
|
|
|
|
fmt.Fprintf(buf, " port=%v", nm.LocalPort)
|
|
|
|
}
|
|
|
|
if nm.Debug != nil {
|
|
|
|
j, _ := json.Marshal(nm.Debug)
|
|
|
|
fmt.Fprintf(buf, " debug=%s", j)
|
|
|
|
}
|
|
|
|
fmt.Fprintf(buf, " %v", nm.Addresses)
|
|
|
|
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 {
|
|
|
|
if a.NodeKey != b.NodeKey ||
|
|
|
|
a.MachineStatus != b.MachineStatus ||
|
|
|
|
a.LocalPort != b.LocalPort ||
|
2020-10-27 20:46:05 +00:00
|
|
|
a.User != b.User ||
|
2020-07-23 17:50:06 +00:00
|
|
|
len(a.Addresses) != len(b.Addresses) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, a := range a.Addresses {
|
|
|
|
if b.Addresses[i] != a {
|
|
|
|
return false
|
2020-03-13 02:29:24 +00:00
|
|
|
}
|
2020-07-23 17:50:06 +00:00
|
|
|
}
|
|
|
|
return (a.Debug == nil && b.Debug == nil) || reflect.DeepEqual(a.Debug, b.Debug)
|
|
|
|
}
|
|
|
|
|
|
|
|
// printPeerConcise appends to buf a line repsenting the peer p.
|
|
|
|
//
|
|
|
|
// If this function is changed to access different fields of p, keep
|
|
|
|
// in nodeConciseEqual in sync.
|
|
|
|
func printPeerConcise(buf *strings.Builder, p *tailcfg.Node) {
|
|
|
|
aip := make([]string, len(p.AllowedIPs))
|
|
|
|
for i, a := range p.AllowedIPs {
|
|
|
|
s := strings.TrimSuffix(fmt.Sprint(a), "/32")
|
|
|
|
aip[i] = s
|
|
|
|
}
|
2020-03-13 02:29:24 +00:00
|
|
|
|
2020-07-23 17:50:06 +00:00
|
|
|
ep := make([]string, len(p.Endpoints))
|
|
|
|
for i, e := range p.Endpoints {
|
|
|
|
// 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
|
|
|
|
2020-07-23 17:50:06 +00:00
|
|
|
derp := p.DERP
|
|
|
|
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
|
|
|
|
if !p.DiscoKey.IsZero() {
|
|
|
|
discoShort = p.DiscoKey.ShortString() + " "
|
|
|
|
}
|
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",
|
|
|
|
p.Key.ShortString(),
|
|
|
|
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.
|
|
|
|
func nodeConciseEqual(a, b *tailcfg.Node) bool {
|
|
|
|
return a.Key == b.Key &&
|
|
|
|
a.DERP == b.DERP &&
|
2020-08-03 17:00:16 +00:00
|
|
|
a.DiscoKey == b.DiscoKey &&
|
2020-07-23 17:50:06 +00:00
|
|
|
eqCIDRsIgnoreNil(a.AllowedIPs, b.AllowedIPs) &&
|
|
|
|
eqStringsIgnoreNil(a.Endpoints, b.Endpoints)
|
|
|
|
}
|
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 {
|
|
|
|
case pa.ID == pb.ID:
|
|
|
|
if !nodeConciseEqual(pa, pb) {
|
|
|
|
diff.WriteByte('-')
|
|
|
|
printPeerConcise(&diff, pa)
|
|
|
|
diff.WriteByte('+')
|
|
|
|
printPeerConcise(&diff, pb)
|
|
|
|
}
|
|
|
|
aps, bps = aps[1:], bps[1:]
|
|
|
|
case pa.ID > pb.ID:
|
|
|
|
// New peer in b.
|
|
|
|
diff.WriteByte('+')
|
|
|
|
printPeerConcise(&diff, pb)
|
|
|
|
bps = bps[1:]
|
|
|
|
case pb.ID > pa.ID:
|
|
|
|
// 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
|
|
|
|
AllowDefaultRoute
|
2020-02-05 22:16:58 +00:00
|
|
|
)
|
|
|
|
|
2020-06-28 18:53:37 +00:00
|
|
|
// EndpointDiscoSuffix is appended to the hex representation of a peer's discovery key
|
|
|
|
// and is then the sole wireguard endpoint for peers with a non-zero discovery key.
|
|
|
|
// This form is then recognize by magicsock's CreateEndpoint.
|
|
|
|
const EndpointDiscoSuffix = ".disco.tailscale:12345"
|
|
|
|
|
2020-07-23 15:30:09 +00:00
|
|
|
// WGCfg returns the NetworkMaps's Wireguard configuration.
|
2020-07-31 20:27:09 +00:00
|
|
|
func (nm *NetworkMap) WGCfg(logf logger.Logf, flags WGConfigFlags) (*wgcfg.Config, error) {
|
2020-07-23 15:30:09 +00:00
|
|
|
cfg := &wgcfg.Config{
|
|
|
|
Name: "tailscale",
|
2020-12-30 01:22:56 +00:00
|
|
|
PrivateKey: wgcfg.PrivateKey(nm.PrivateKey),
|
2020-07-23 15:30:09 +00:00
|
|
|
Addresses: nm.Addresses,
|
|
|
|
ListenPort: nm.LocalPort,
|
|
|
|
Peers: make([]wgcfg.Peer, 0, len(nm.Peers)),
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 15:30:09 +00:00
|
|
|
for _, peer := range nm.Peers {
|
2020-06-28 18:53:37 +00:00
|
|
|
if Debug.OnlyDisco && peer.DiscoKey.IsZero() {
|
|
|
|
continue
|
|
|
|
}
|
2020-07-23 15:38:14 +00:00
|
|
|
if (flags&AllowSingleHosts) == 0 && len(peer.AllowedIPs) < 2 {
|
2020-07-23 15:30:09 +00:00
|
|
|
logf("wgcfg: %v skipping a single-host peer.", peer.Key.ShortString())
|
2020-02-05 22:16:58 +00:00
|
|
|
continue
|
|
|
|
}
|
2020-07-23 15:30:09 +00:00
|
|
|
cfg.Peers = append(cfg.Peers, wgcfg.Peer{
|
|
|
|
PublicKey: wgcfg.Key(peer.Key),
|
|
|
|
})
|
|
|
|
cpeer := &cfg.Peers[len(cfg.Peers)-1]
|
|
|
|
if peer.KeepAlive {
|
|
|
|
cpeer.PersistentKeepalive = 25 // seconds
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
2020-07-23 15:30:09 +00:00
|
|
|
|
2020-06-28 18:53:37 +00:00
|
|
|
if !peer.DiscoKey.IsZero() {
|
2020-07-23 15:30:09 +00:00
|
|
|
if err := appendEndpoint(cpeer, fmt.Sprintf("%x%s", peer.DiscoKey[:], EndpointDiscoSuffix)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-14 01:10:41 +00:00
|
|
|
cpeer.Endpoints = fmt.Sprintf("%x.disco.tailscale:12345", peer.DiscoKey[:])
|
2020-06-28 18:53:37 +00:00
|
|
|
} else {
|
2020-07-23 15:30:09 +00:00
|
|
|
if err := appendEndpoint(cpeer, peer.DERP); err != nil {
|
|
|
|
return nil, err
|
2020-06-28 18:53:37 +00:00
|
|
|
}
|
2020-07-23 15:30:09 +00:00
|
|
|
for _, ep := range peer.Endpoints {
|
|
|
|
if err := appendEndpoint(cpeer, ep); err != nil {
|
|
|
|
return nil, err
|
2020-06-28 18:53:37 +00:00
|
|
|
}
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, allowedIP := range peer.AllowedIPs {
|
2020-12-24 20:33:55 +00:00
|
|
|
if allowedIP.Bits == 0 {
|
2020-07-23 15:38:14 +00:00
|
|
|
if (flags & AllowDefaultRoute) == 0 {
|
2021-01-21 03:28:21 +00:00
|
|
|
logf("[v1] wgcfg: not accepting default route from %q (%v)",
|
|
|
|
nodeDebugName(peer), peer.Key.ShortString())
|
2020-02-05 22:16:58 +00:00
|
|
|
continue
|
|
|
|
}
|
2020-09-15 17:00:23 +00:00
|
|
|
} else if cidrIsSubnet(peer, allowedIP) {
|
2020-07-23 15:38:14 +00:00
|
|
|
if (flags & AllowSubnetRoutes) == 0 {
|
2021-01-21 03:28:21 +00:00
|
|
|
logf("[v1] wgcfg: not accepting subnet route %v from %q (%v)",
|
|
|
|
allowedIP, nodeDebugName(peer), peer.Key.ShortString())
|
2020-02-05 22:16:58 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2020-07-23 15:30:09 +00:00
|
|
|
cpeer.AllowedIPs = append(cpeer.AllowedIPs, allowedIP)
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 15:30:09 +00:00
|
|
|
return cfg, nil
|
|
|
|
}
|
|
|
|
|
2021-01-21 03:28:21 +00:00
|
|
|
func nodeDebugName(n *tailcfg.Node) string {
|
|
|
|
name := n.Name
|
|
|
|
if name == "" {
|
|
|
|
name = n.Hostinfo.Hostname
|
|
|
|
}
|
|
|
|
if i := strings.Index(name, "."); i != -1 {
|
|
|
|
name = name[:i]
|
|
|
|
}
|
|
|
|
if name == "" && len(n.Addresses) != 0 {
|
|
|
|
return n.Addresses[0].String()
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2020-09-15 17:00:23 +00:00
|
|
|
// cidrIsSubnet reports whether cidr is a non-default-route subnet
|
|
|
|
// exported by node that is not one of its own self addresses.
|
2020-12-24 20:33:55 +00:00
|
|
|
func cidrIsSubnet(node *tailcfg.Node, cidr netaddr.IPPrefix) bool {
|
|
|
|
if cidr.Bits == 0 {
|
2020-09-15 17:00:23 +00:00
|
|
|
return false
|
|
|
|
}
|
2020-12-24 20:33:55 +00:00
|
|
|
if !cidr.IsSingleIP() {
|
2020-09-15 17:00:23 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
for _, selfCIDR := range node.Addresses {
|
|
|
|
if cidr == selfCIDR {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-07-23 15:30:09 +00:00
|
|
|
func appendEndpoint(peer *wgcfg.Peer, epStr string) error {
|
|
|
|
if epStr == "" {
|
|
|
|
return nil
|
|
|
|
}
|
2021-01-14 01:10:41 +00:00
|
|
|
_, port, err := net.SplitHostPort(epStr)
|
2020-07-23 15:30:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("malformed endpoint %q for peer %v", epStr, peer.PublicKey.ShortString())
|
|
|
|
}
|
2021-01-14 01:10:41 +00:00
|
|
|
_, err = strconv.ParseUint(port, 10, 16)
|
2020-07-23 15:30:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid port in endpoint %q for peer %v", epStr, peer.PublicKey.ShortString())
|
|
|
|
}
|
2021-01-14 01:10:41 +00:00
|
|
|
if peer.Endpoints != "" {
|
|
|
|
peer.Endpoints += ","
|
|
|
|
}
|
|
|
|
peer.Endpoints += epStr
|
2020-07-23 15:30:09 +00:00
|
|
|
return nil
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
2020-07-23 17:50:06 +00:00
|
|
|
|
|
|
|
// eqStringsIgnoreNil reports whether a and b have the same length and
|
|
|
|
// contents, but ignore whether a or b are nil.
|
|
|
|
func eqStringsIgnoreNil(a, b []string) bool {
|
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, v := range a {
|
|
|
|
if v != b[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// eqCIDRsIgnoreNil reports whether a and b have the same length and
|
|
|
|
// contents, but ignore whether a or b are nil.
|
2020-12-24 20:33:55 +00:00
|
|
|
func eqCIDRsIgnoreNil(a, b []netaddr.IPPrefix) bool {
|
2020-07-23 17:50:06 +00:00
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, v := range a {
|
|
|
|
if v != b[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|