tailcfg: make SelfNodeV4MasqAddrForThisPeer a pointer

This makes `omitempty` actually work, and saves bytes in each map response.

Updates tailscale/corp#8020

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2023-04-13 10:12:31 -07:00
committed by Maisem Ali
parent a5fd51ebdc
commit 64bbf1738e
11 changed files with 38 additions and 22 deletions

View File

@@ -580,12 +580,12 @@ func natConfigFromWGConfig(wcfg *wgcfg.Config) *natV4Config {
)
for i := range wcfg.Peers {
p := &wcfg.Peers[i]
if !p.V4MasqAddr.IsValid() {
if p.V4MasqAddr == nil || !p.V4MasqAddr.IsValid() {
continue
}
rt.InsertOrReplace(p.PublicKey, p.AllowedIPs...)
mak.Set(&dstMasqAddrs, p.PublicKey, p.V4MasqAddr)
mak.Set(&listenAddrs, p.V4MasqAddr, struct{}{})
mak.Set(&dstMasqAddrs, p.PublicKey, *p.V4MasqAddr)
mak.Set(&listenAddrs, *p.V4MasqAddr, struct{}{})
}
if len(listenAddrs) == 0 || len(dstMasqAddrs) == 0 {
return nil

View File

@@ -31,6 +31,7 @@ import (
"tailscale.com/types/key"
"tailscale.com/types/logger"
"tailscale.com/types/netlogtype"
"tailscale.com/types/ptr"
"tailscale.com/util/must"
"tailscale.com/wgengine/filter"
"tailscale.com/wgengine/wgcfg"
@@ -602,7 +603,7 @@ func TestNATCfg(t *testing.T) {
AllowedIPs: []netip.Prefix{
netip.PrefixFrom(ip, ip.BitLen()),
},
V4MasqAddr: eip,
V4MasqAddr: ptr.To(eip),
}
p.AllowedIPs = append(p.AllowedIPs, otherAllowedIPs...)
return p