mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
all: declare & plumb IPv6 masquerade address for peer
This PR plumbs through awareness of an IPv6 SNAT/masquerade address from the wire protocol through to the low-level (tstun / wgengine). This PR is the first in two PRs for implementing IPv6 NAT support to/from peers. A subsequent PR will implement the data-plane changes to implement IPv6 NAT - this is just plumbing. Signed-off-by: Tom DNetto <tom@tailscale.com> Updates ENG-991
This commit is contained in:
@@ -98,7 +98,7 @@ type Wrapper struct {
|
||||
// timeNow, if non-nil, will be used to obtain the current time.
|
||||
timeNow func() time.Time
|
||||
|
||||
// natV4Config stores the current NAT configuration.
|
||||
// natV4Config stores the current IPv4 NAT configuration.
|
||||
natV4Config atomic.Pointer[natV4Config]
|
||||
|
||||
// vectorBuffer stores the oldest unconsumed packet vector from tdev. It is
|
||||
@@ -577,9 +577,9 @@ func (c *natV4Config) selectSrcIP(oldSrc, dst netip.Addr) netip.Addr {
|
||||
return oldSrc
|
||||
}
|
||||
|
||||
// natConfigFromWireGuardConfig generates a natV4Config from nm.
|
||||
// natV4ConfigFromWGConfig generates a natV4Config from nm.
|
||||
// If v4 NAT is not required, it returns nil.
|
||||
func natConfigFromWGConfig(wcfg *wgcfg.Config) *natV4Config {
|
||||
func natV4ConfigFromWGConfig(wcfg *wgcfg.Config) *natV4Config {
|
||||
if wcfg == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -632,7 +632,7 @@ func natConfigFromWGConfig(wcfg *wgcfg.Config) *natV4Config {
|
||||
// SetNetMap is called when a new NetworkMap is received.
|
||||
// It currently (2023-03-01) only updates the IPv4 NAT configuration.
|
||||
func (t *Wrapper) SetWGConfig(wcfg *wgcfg.Config) {
|
||||
cfg := natConfigFromWGConfig(wcfg)
|
||||
cfg := natV4ConfigFromWGConfig(wcfg)
|
||||
old := t.natV4Config.Swap(cfg)
|
||||
if !reflect.DeepEqual(old, cfg) {
|
||||
t.logf("nat config: %+v", cfg)
|
||||
|
@@ -780,7 +780,7 @@ func TestNATCfg(t *testing.T) {
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
ncfg := natConfigFromWGConfig(tc.wcfg)
|
||||
ncfg := natV4ConfigFromWGConfig(tc.wcfg)
|
||||
for peer, want := range tc.snatMap {
|
||||
if got := ncfg.selectSrcIP(selfNativeIP, peer); got != want {
|
||||
t.Errorf("selectSrcIP[%v]: got %v; want %v", peer, got, want)
|
||||
|
Reference in New Issue
Block a user