Skip to content

Commit 9e67512

Browse files
Dont reset dns
1 parent 45d17da commit 9e67512

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

wgnetstack/wgnetstack.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ func (s *WireGuardService) keepSendingUDPHolePunch(host string) {
10841084
}
10851085

10861086
func (s *WireGuardService) updateTargets(pm *proxy.ProxyManager, action string, tunnelIP string, proto string, targetData TargetData) error {
1087-
var replace = true
1087+
var replace = false
10881088
for _, t := range targetData.Targets {
10891089
// Split the first number off of the target with : separator and use as the port
10901090
parts := strings.Split(t, ":")
@@ -1113,9 +1113,9 @@ func (s *WireGuardService) updateTargets(pm *proxy.ProxyManager, action string,
11131113
// Ignore "target not found" errors as this is expected for new targets
11141114
if !strings.Contains(err.Error(), "target not found") {
11151115
logger.Error("Failed to remove existing target: %v", err)
1116-
} else {
1117-
replace = false // If we got here, it means the target didn't exist, so we can add it without replacing
11181116
}
1117+
} else {
1118+
replace = true // We successfully removed an existing target
11191119
}
11201120

11211121
// Add the new target
@@ -1134,7 +1134,7 @@ func (s *WireGuardService) updateTargets(pm *proxy.ProxyManager, action string,
11341134

11351135
if replace {
11361136
// If we replaced any targets, we need to hot swap the netstack
1137-
if err := s.ReplaceNetstack(s.dns); err != nil {
1137+
if err := s.ReplaceNetstack(); err != nil {
11381138
logger.Error("Failed to replace netstack after updating targets: %v", err)
11391139
return err
11401140
}
@@ -1162,7 +1162,7 @@ func parseTargetData(data interface{}) (TargetData, error) {
11621162
}
11631163

11641164
// Add this method to WireGuardService
1165-
func (s *WireGuardService) ReplaceNetstack(newDNS []netip.Addr) error {
1165+
func (s *WireGuardService) ReplaceNetstack() error {
11661166
s.mu.Lock()
11671167
defer s.mu.Unlock()
11681168

@@ -1183,7 +1183,7 @@ func (s *WireGuardService) ReplaceNetstack(newDNS []netip.Addr) error {
11831183
// Create new TUN device and netstack with new DNS
11841184
newTun, newTnet, err := netstack.CreateNetTUN(
11851185
[]netip.Addr{tunnelIP},
1186-
newDNS,
1186+
s.dns,
11871187
s.mtu)
11881188
if err != nil {
11891189
// Restart proxy manager with old tnet on failure
@@ -1213,7 +1213,6 @@ func (s *WireGuardService) ReplaceNetstack(newDNS []netip.Addr) error {
12131213
// Update references
12141214
s.tun = newTun
12151215
s.tnet = newTnet
1216-
s.dns = newDNS
12171216

12181217
// Create new WireGuard device with same port
12191218
s.device = device.NewDevice(s.tun, NewFixedPortBind(s.Port), device.NewLogger(
@@ -1244,7 +1243,6 @@ func (s *WireGuardService) ReplaceNetstack(newDNS []netip.Addr) error {
12441243
go s.onNetstackReady(s.tnet)
12451244
}
12461245

1247-
logger.Info("Netstack replaced successfully with new DNS servers")
12481246
return nil
12491247
}
12501248

0 commit comments

Comments
 (0)