This commit is contained in:
JackDoan
2026-02-17 15:00:00 -06:00
parent 27d764ba57
commit 7498c6846d
6 changed files with 23 additions and 9 deletions

View File

@@ -322,7 +322,7 @@ func (t *tun) reload(c *config.C, initial bool) error {
return nil return nil
} }
if !initial { if initial {
t.snatAddr = prepareSnatAddr(t, t.l, c, routes) t.snatAddr = prepareSnatAddr(t, t.l, c, routes)
} }

View File

@@ -413,6 +413,10 @@ func (t *tun) reload(c *config.C, initial bool) error {
return nil return nil
} }
if initial {
t.snatAddr = prepareSnatAddr(t, t.l, c, routes)
}
routeTree, err := makeRouteTree(t.l, routes, false) routeTree, err := makeRouteTree(t.l, routes, false)
if err != nil { if err != nil {
return err return err

View File

@@ -182,7 +182,7 @@ func (t *tun) reload(c *config.C, initial bool) error {
return nil return nil
} }
if !initial { if initial {
t.snatAddr = prepareSnatAddr(t, t.l, c, routes) 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(), 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{ newAddrs = append(newAddrs, &netlink.Addr{
IPNet: &net.IPNet{ IPNet: &net.IPNet{
IP: t.snatAddr.Addr().AsSlice(), 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) return fmt.Errorf("failed to set default route MTU for %s: %w", t.vpnNetworks[i], err)
} }
} }
if t.snatAddr.IsValid() { //TODO snat and be snatted
if err = t.setDefaultRoute(t.snatAddr); err != nil { //if t.snatAddr.IsValid() {
return fmt.Errorf("failed to set default route MTU for %s: %w", t.snatAddr, err) // 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 // Set the routes
if err = t.addRoutes(false); err != nil { if err = t.addRoutes(false); err != nil {

View File

@@ -352,6 +352,10 @@ func (t *tun) reload(c *config.C, initial bool) error {
return nil return nil
} }
if initial {
t.snatAddr = prepareSnatAddr(t, t.l, c, routes)
}
routeTree, err := makeRouteTree(t.l, routes, false) routeTree, err := makeRouteTree(t.l, routes, false)
if err != nil { if err != nil {
return err return err

View File

@@ -273,6 +273,10 @@ func (t *tun) reload(c *config.C, initial bool) error {
return nil return nil
} }
if initial {
t.snatAddr = prepareSnatAddr(t, t.l, c, routes)
}
routeTree, err := makeRouteTree(t.l, routes, false) routeTree, err := makeRouteTree(t.l, routes, false)
if err != nil { if err != nil {
return err return err

View File

@@ -105,7 +105,7 @@ func (t *winTun) reload(c *config.C, initial bool) error {
return nil return nil
} }
if !initial { if initial {
t.snatAddr = prepareSnatAddr(t, t.l, c, routes) t.snatAddr = prepareSnatAddr(t, t.l, c, routes)
} }