control/controlclient: make netmap generation use rate-limited logger.

This commit is contained in:
David Anderson 2020-06-18 23:24:44 +00:00
parent 401e2ec307
commit 0ecaf7b5ed
2 changed files with 10 additions and 9 deletions

View File

@ -15,6 +15,7 @@
"github.com/tailscale/wireguard-go/wgcfg" "github.com/tailscale/wireguard-go/wgcfg"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/logger"
"tailscale.com/wgengine/filter" "tailscale.com/wgengine/filter"
) )
@ -173,7 +174,7 @@ func UFlagsHelper(uroutes, rroutes, droutes bool) int {
// TODO(bradfitz): UAPI seems to only be used by the old confnode and // TODO(bradfitz): UAPI seems to only be used by the old confnode and
// pingnode; delete this when those are deleted/rewritten? // pingnode; delete this when those are deleted/rewritten?
func (nm *NetworkMap) UAPI(uflags int, dnsOverride []wgcfg.IP) string { func (nm *NetworkMap) UAPI(uflags int, dnsOverride []wgcfg.IP) string {
wgcfg, err := nm.WGCfg(uflags, dnsOverride) wgcfg, err := nm.WGCfg(log.Printf, uflags, dnsOverride)
if err != nil { if err != nil {
log.Fatalf("WGCfg() failed unexpectedly: %v\n", err) log.Fatalf("WGCfg() failed unexpectedly: %v\n", err)
} }
@ -184,12 +185,12 @@ func (nm *NetworkMap) UAPI(uflags int, dnsOverride []wgcfg.IP) string {
return s return s
} }
func (nm *NetworkMap) WGCfg(uflags int, dnsOverride []wgcfg.IP) (*wgcfg.Config, error) { func (nm *NetworkMap) WGCfg(logf logger.Logf, uflags int, dnsOverride []wgcfg.IP) (*wgcfg.Config, error) {
s := nm._WireGuardConfig(uflags, dnsOverride, true) s := nm._WireGuardConfig(logf, uflags, dnsOverride, true)
return wgcfg.FromWgQuick(s, "tailscale") return wgcfg.FromWgQuick(s, "tailscale")
} }
func (nm *NetworkMap) _WireGuardConfig(uflags int, dnsOverride []wgcfg.IP, allEndpoints bool) string { func (nm *NetworkMap) _WireGuardConfig(logf logger.Logf, uflags int, dnsOverride []wgcfg.IP, allEndpoints bool) string {
buf := new(strings.Builder) buf := new(strings.Builder)
fmt.Fprintf(buf, "[Interface]\n") fmt.Fprintf(buf, "[Interface]\n")
fmt.Fprintf(buf, "PrivateKey = %s\n", base64.StdEncoding.EncodeToString(nm.PrivateKey[:])) fmt.Fprintf(buf, "PrivateKey = %s\n", base64.StdEncoding.EncodeToString(nm.PrivateKey[:]))
@ -215,7 +216,7 @@ func (nm *NetworkMap) _WireGuardConfig(uflags int, dnsOverride []wgcfg.IP, allEn
for i, peer := range nm.Peers { for i, peer := range nm.Peers {
if (uflags&UAllowSingleHosts) == 0 && len(peer.AllowedIPs) < 2 { if (uflags&UAllowSingleHosts) == 0 && len(peer.AllowedIPs) < 2 {
log.Printf("wgcfg: %v skipping a single-host peer.\n", peer.Key.ShortString()) logf("wgcfg: %v skipping a single-host peer.\n", peer.Key.ShortString())
continue continue
} }
if i > 0 { if i > 0 {
@ -249,16 +250,16 @@ func (nm *NetworkMap) _WireGuardConfig(uflags int, dnsOverride []wgcfg.IP, allEn
aip := allowedIP.String() aip := allowedIP.String()
if allowedIP.Mask == 0 { if allowedIP.Mask == 0 {
if (uflags & UAllowDefaultRoute) == 0 { if (uflags & UAllowDefaultRoute) == 0 {
log.Printf("wgcfg: %v skipping default route\n", peer.Key.ShortString()) logf("wgcfg: %v skipping default route\n", peer.Key.ShortString())
continue continue
} }
if (uflags & UHackDefaultRoute) != 0 { if (uflags & UHackDefaultRoute) != 0 {
aip = "10.0.0.0/8" aip = "10.0.0.0/8"
log.Printf("wgcfg: %v converting default route => %v\n", peer.Key.ShortString(), aip) logf("wgcfg: %v converting default route => %v\n", peer.Key.ShortString(), aip)
} }
} else if allowedIP.Mask < 32 { } else if allowedIP.Mask < 32 {
if (uflags & UAllowSubnetRoutes) == 0 { if (uflags & UAllowSubnetRoutes) == 0 {
log.Printf("wgcfg: %v skipping subnet route\n", peer.Key.ShortString()) logf("wgcfg: %v skipping subnet route\n", peer.Key.ShortString())
continue continue
} }
} }

View File

@ -818,7 +818,7 @@ func (b *LocalBackend) authReconfig() {
dns = []wgcfg.IP{} dns = []wgcfg.IP{}
dom = []string{} dom = []string{}
} }
cfg, err := nm.WGCfg(uflags, dns) cfg, err := nm.WGCfg(b.logf, uflags, dns)
if err != nil { if err != nil {
b.logf("wgcfg: %v", err) b.logf("wgcfg: %v", err)
return return