JackDoan 8 месяцев назад
Родитель
Сommit
7498c6846d

+ 1 - 1
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)
 	}
 

+ 4 - 0
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

+ 9 - 7
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 {

+ 4 - 0
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

+ 4 - 0
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

+ 1 - 1
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)
 	}