Skip to content

Commit c647ddf

Browse files
committed
fix gateway
1 parent a0c0410 commit c647ddf

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

cmd/swgp-go/main_darwin.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ func addGatewayRoute(cfg *service.Config, logger *zap.Logger, gatewayIP net.IP)
6868
if gatewayIP.To4() != nil {
6969
// IPv4 gateway
7070
commands = []string{
71-
"sudo route delete " + client.ProxyEndpointAddress.IP().String(),
72-
"sudo route add " + client.ProxyEndpointAddress.IP().String() + "/32 " + gatewayIP.String(),
71+
"sudo route -n delete -net " + client.ProxyEndpointAddress.IP().String(),
72+
"sudo route -n add -net " + client.ProxyEndpointAddress.IP().String() + "/32 -gateway " + gatewayIP.String(),
7373
}
7474
} else {
7575
// IPv6 gateway
7676
commands = []string{
77-
"sudo route delete -inet6 " + client.ProxyEndpointAddress.IP().String(),
78-
"sudo route add -inet6 " + client.ProxyEndpointAddress.IP().String() + "/128 " + gatewayIP.String(),
77+
"sudo route -n delete -inet6 -net " + client.ProxyEndpointAddress.IP().String(),
78+
"sudo route -n add -inet6 -net " + client.ProxyEndpointAddress.IP().String() + "/128 -gateway " + gatewayIP.String(),
7979
}
8080
}
8181
err := executeCommands(logger, commands)
@@ -88,7 +88,7 @@ func addGatewayRoute(cfg *service.Config, logger *zap.Logger, gatewayIP net.IP)
8888

8989
func deleteGatewayRoute(cfg *service.Config, logger *zap.Logger) {
9090
for _, client := range cfg.Clients {
91-
err := executeCommands(logger, []string{"sudo route delete " + client.ProxyEndpointAddress.IP().String()})
91+
err := executeCommands(logger, []string{"sudo route -n delete -net " + client.ProxyEndpointAddress.IP().String()})
9292
if err != nil {
9393
logger.Error("Failed to delete route:", zap.Error(err))
9494
}
@@ -116,7 +116,6 @@ func (g *gatewayMonitor) watch() {
116116
}
117117
if !g.ip.Equal(ip) {
118118
g.logger.Info("Gateway address changed, reconfiguring routes")
119-
deleteGatewayRoute(g.cfg, g.logger)
120119
err = addGatewayRoute(g.cfg, g.logger, ip)
121120
if err != nil {
122121
g.logger.Error("Failed to reconfigure routes:", zap.Error(err))

0 commit comments

Comments
 (0)