|
|
@ -63,19 +63,10 @@ func (nm NetworkMap) String() string {
|
|
|
|
return nm.Concise()
|
|
|
|
return nm.Concise()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func keyString(key [32]byte) string {
|
|
|
|
|
|
|
|
b64 := base64.StdEncoding.EncodeToString(key[:])
|
|
|
|
|
|
|
|
abbrev := "invalid"
|
|
|
|
|
|
|
|
if len(b64) == 44 {
|
|
|
|
|
|
|
|
abbrev = b64[0:4] + "…" + b64[39:43]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("[%s]", abbrev)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (nm *NetworkMap) Concise() string {
|
|
|
|
func (nm *NetworkMap) Concise() string {
|
|
|
|
buf := new(strings.Builder)
|
|
|
|
buf := new(strings.Builder)
|
|
|
|
fmt.Fprintf(buf, "netmap: self: %v auth=%v :%v %v\n",
|
|
|
|
fmt.Fprintf(buf, "netmap: self: %v auth=%v :%v %v\n",
|
|
|
|
keyString(nm.NodeKey), nm.MachineStatus,
|
|
|
|
nm.NodeKey.ShortString(), nm.MachineStatus,
|
|
|
|
nm.LocalPort, nm.Addresses)
|
|
|
|
nm.LocalPort, nm.Addresses)
|
|
|
|
for _, p := range nm.Peers {
|
|
|
|
for _, p := range nm.Peers {
|
|
|
|
aip := make([]string, len(p.AllowedIPs))
|
|
|
|
aip := make([]string, len(p.AllowedIPs))
|
|
|
@ -108,7 +99,7 @@ func (nm *NetworkMap) Concise() string {
|
|
|
|
// table to look good in that case. This will also make multi-
|
|
|
|
// table to look good in that case. This will also make multi-
|
|
|
|
// subnet nodes stand out visually.
|
|
|
|
// subnet nodes stand out visually.
|
|
|
|
fmt.Fprintf(buf, " %v %-2v %-15v : %v\n",
|
|
|
|
fmt.Fprintf(buf, " %v %-2v %-15v : %v\n",
|
|
|
|
keyString(p.Key), derp,
|
|
|
|
p.Key.ShortString(), derp,
|
|
|
|
strings.Join(aip, " "),
|
|
|
|
strings.Join(aip, " "),
|
|
|
|
strings.Join(ep, " "))
|
|
|
|
strings.Join(ep, " "))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -277,7 +268,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.AbbrevString())
|
|
|
|
log.Printf("wgcfg: %v skipping a single-host peer.\n", peer.Key.ShortString())
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if i > 0 {
|
|
|
|
if i > 0 {
|
|
|
@ -311,16 +302,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.AbbrevString())
|
|
|
|
log.Printf("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.AbbrevString(), aip)
|
|
|
|
log.Printf("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.AbbrevString())
|
|
|
|
log.Printf("wgcfg: %v skipping subnet route\n", peer.Key.ShortString())
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|