From 7498c6846d4eeefddd7d17843aa0da2c286986c2 Mon Sep 17 00:00:00 2001 From: JackDoan Date: Tue, 17 Feb 2026 15:00:00 -0600 Subject: [PATCH] checkpt --- overlay/tun_darwin.go | 2 +- overlay/tun_freebsd.go | 4 ++++ overlay/tun_linux.go | 16 +++++++++------- overlay/tun_netbsd.go | 4 ++++ overlay/tun_openbsd.go | 4 ++++ overlay/tun_windows.go | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/overlay/tun_darwin.go b/overlay/tun_darwin.go index 651f4b2d..0ab331bb 100644 --- a/overlay/tun_darwin.go +++ b/overlay/tun_darwin.go @@ -322,7 +322,7 @@ func (t *tun) reload(c *config.C, initial bool) error { return nil } - if !initial { + if initial { t.snatAddr = prepareSnatAddr(t, t.l, c, routes) } diff --git a/overlay/tun_freebsd.go b/overlay/tun_freebsd.go index bae53235..31289d55 100644 --- a/overlay/tun_freebsd.go +++ b/overlay/tun_freebsd.go @@ -413,6 +413,10 @@ func (t *tun) reload(c *config.C, initial bool) error { return nil } + if initial { + t.snatAddr = prepareSnatAddr(t, t.l, c, routes) + } + routeTree, err := makeRouteTree(t.l, routes, false) if err != nil { return err diff --git a/overlay/tun_linux.go b/overlay/tun_linux.go index 1b604c2a..0f3bec96 100644 --- a/overlay/tun_linux.go +++ b/overlay/tun_linux.go @@ -182,7 +182,7 @@ func (t *tun) reload(c *config.C, initial bool) error { return nil } - if !initial { + if initial { t.snatAddr = prepareSnatAddr(t, t.l, c, routes) } @@ -328,7 +328,8 @@ func (t *tun) addIPs(link netlink.Link) error { Label: t.vpnNetworks[i].Addr().Zone(), } } - if t.snatAddr.IsValid() { + + if t.snatAddr.IsValid() && len(t.vpnNetworks) > 0 { //TODO unsafe-routers should be able to snat and be snatted newAddrs = append(newAddrs, &netlink.Addr{ IPNet: &net.IPNet{ IP: t.snatAddr.Addr().AsSlice(), @@ -429,11 +430,12 @@ func (t *tun) Activate() error { return fmt.Errorf("failed to set default route MTU for %s: %w", t.vpnNetworks[i], err) } } - if t.snatAddr.IsValid() { - if err = t.setDefaultRoute(t.snatAddr); err != nil { - return fmt.Errorf("failed to set default route MTU for %s: %w", t.snatAddr, err) - } - } + //TODO snat and be snatted + //if t.snatAddr.IsValid() { + // if err = t.setDefaultRoute(t.snatAddr); err != nil { + // return fmt.Errorf("failed to set default route MTU for %s: %w", t.snatAddr, err) + // } + //} // Set the routes if err = t.addRoutes(false); err != nil { diff --git a/overlay/tun_netbsd.go b/overlay/tun_netbsd.go index 5174adb3..e81e466c 100644 --- a/overlay/tun_netbsd.go +++ b/overlay/tun_netbsd.go @@ -352,6 +352,10 @@ func (t *tun) reload(c *config.C, initial bool) error { return nil } + if initial { + t.snatAddr = prepareSnatAddr(t, t.l, c, routes) + } + routeTree, err := makeRouteTree(t.l, routes, false) if err != nil { return err diff --git a/overlay/tun_openbsd.go b/overlay/tun_openbsd.go index 9f0d6567..e88bd0f4 100644 --- a/overlay/tun_openbsd.go +++ b/overlay/tun_openbsd.go @@ -273,6 +273,10 @@ func (t *tun) reload(c *config.C, initial bool) error { return nil } + if initial { + t.snatAddr = prepareSnatAddr(t, t.l, c, routes) + } + routeTree, err := makeRouteTree(t.l, routes, false) if err != nil { return err diff --git a/overlay/tun_windows.go b/overlay/tun_windows.go index 248db47c..4f8bb5b9 100644 --- a/overlay/tun_windows.go +++ b/overlay/tun_windows.go @@ -105,7 +105,7 @@ func (t *winTun) reload(c *config.C, initial bool) error { return nil } - if !initial { + if initial { t.snatAddr = prepareSnatAddr(t, t.l, c, routes) }