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
+2 -1
View File
@@ -50,6 +50,7 @@ import (
"tailscale.com/types/netlogtype"
"tailscale.com/types/netmap"
"tailscale.com/types/nettype"
"tailscale.com/types/ptr"
"tailscale.com/util/cibuild"
"tailscale.com/util/racebuild"
"tailscale.com/wgengine/filter"
@@ -2240,7 +2241,7 @@ func TestIsWireGuardOnlyPeerWithMasquerade(t *testing.T) {
IsWireGuardOnly: true,
Addresses: []netip.Prefix{wgaip},
AllowedIPs: []netip.Prefix{wgaip},
SelfNodeV4MasqAddrForThisPeer: masqip.Addr(),
SelfNodeV4MasqAddrForThisPeer: ptr.To(masqip.Addr()),
},
},
}
+1 -1
View File
@@ -37,7 +37,7 @@ type Peer struct {
PublicKey key.NodePublic
DiscoKey key.DiscoPublic // present only so we can handle restarts within wgengine, not passed to WireGuard
AllowedIPs []netip.Prefix
V4MasqAddr netip.Addr // if non-zero, masquerade IPv4 traffic to this peer using this address
V4MasqAddr *netip.Addr // if non-nil, masquerade IPv4 traffic to this peer using this address
PersistentKeepalive uint16
// wireguard-go's endpoint for this peer. It should always equal Peer.PublicKey.
// We represent it explicitly so that we can detect if they diverge and recover.
+5 -1
View File
@@ -54,6 +54,10 @@ func (src *Peer) Clone() *Peer {
dst := new(Peer)
*dst = *src
dst.AllowedIPs = append(src.AllowedIPs[:0:0], src.AllowedIPs...)
if dst.V4MasqAddr != nil {
dst.V4MasqAddr = new(netip.Addr)
*dst.V4MasqAddr = *src.V4MasqAddr
}
return dst
}
@@ -62,7 +66,7 @@ var _PeerCloneNeedsRegeneration = Peer(struct {
PublicKey key.NodePublic
DiscoKey key.DiscoPublic
AllowedIPs []netip.Prefix
V4MasqAddr netip.Addr
V4MasqAddr *netip.Addr
PersistentKeepalive uint16
WGEndpoint key.NodePublic
}{})