mirror of
https://github.com/fosrl/newt.git
synced 2026-03-08 03:36:40 +00:00
Dont reset dns
This commit is contained in:
@@ -1084,7 +1084,7 @@ func (s *WireGuardService) keepSendingUDPHolePunch(host string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *WireGuardService) updateTargets(pm *proxy.ProxyManager, action string, tunnelIP string, proto string, targetData TargetData) error {
|
func (s *WireGuardService) updateTargets(pm *proxy.ProxyManager, action string, tunnelIP string, proto string, targetData TargetData) error {
|
||||||
var replace = true
|
var replace = false
|
||||||
for _, t := range targetData.Targets {
|
for _, t := range targetData.Targets {
|
||||||
// Split the first number off of the target with : separator and use as the port
|
// Split the first number off of the target with : separator and use as the port
|
||||||
parts := strings.Split(t, ":")
|
parts := strings.Split(t, ":")
|
||||||
@@ -1113,9 +1113,9 @@ func (s *WireGuardService) updateTargets(pm *proxy.ProxyManager, action string,
|
|||||||
// Ignore "target not found" errors as this is expected for new targets
|
// Ignore "target not found" errors as this is expected for new targets
|
||||||
if !strings.Contains(err.Error(), "target not found") {
|
if !strings.Contains(err.Error(), "target not found") {
|
||||||
logger.Error("Failed to remove existing target: %v", err)
|
logger.Error("Failed to remove existing target: %v", err)
|
||||||
} else {
|
|
||||||
replace = false // If we got here, it means the target didn't exist, so we can add it without replacing
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
replace = true // We successfully removed an existing target
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the new target
|
// Add the new target
|
||||||
@@ -1134,7 +1134,7 @@ func (s *WireGuardService) updateTargets(pm *proxy.ProxyManager, action string,
|
|||||||
|
|
||||||
if replace {
|
if replace {
|
||||||
// If we replaced any targets, we need to hot swap the netstack
|
// If we replaced any targets, we need to hot swap the netstack
|
||||||
if err := s.ReplaceNetstack(s.dns); err != nil {
|
if err := s.ReplaceNetstack(); err != nil {
|
||||||
logger.Error("Failed to replace netstack after updating targets: %v", err)
|
logger.Error("Failed to replace netstack after updating targets: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1162,7 +1162,7 @@ func parseTargetData(data interface{}) (TargetData, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add this method to WireGuardService
|
// Add this method to WireGuardService
|
||||||
func (s *WireGuardService) ReplaceNetstack(newDNS []netip.Addr) error {
|
func (s *WireGuardService) ReplaceNetstack() error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
@@ -1183,7 +1183,7 @@ func (s *WireGuardService) ReplaceNetstack(newDNS []netip.Addr) error {
|
|||||||
// Create new TUN device and netstack with new DNS
|
// Create new TUN device and netstack with new DNS
|
||||||
newTun, newTnet, err := netstack.CreateNetTUN(
|
newTun, newTnet, err := netstack.CreateNetTUN(
|
||||||
[]netip.Addr{tunnelIP},
|
[]netip.Addr{tunnelIP},
|
||||||
newDNS,
|
s.dns,
|
||||||
s.mtu)
|
s.mtu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Restart proxy manager with old tnet on failure
|
// Restart proxy manager with old tnet on failure
|
||||||
@@ -1213,7 +1213,6 @@ func (s *WireGuardService) ReplaceNetstack(newDNS []netip.Addr) error {
|
|||||||
// Update references
|
// Update references
|
||||||
s.tun = newTun
|
s.tun = newTun
|
||||||
s.tnet = newTnet
|
s.tnet = newTnet
|
||||||
s.dns = newDNS
|
|
||||||
|
|
||||||
// Create new WireGuard device with same port
|
// Create new WireGuard device with same port
|
||||||
s.device = device.NewDevice(s.tun, NewFixedPortBind(s.Port), device.NewLogger(
|
s.device = device.NewDevice(s.tun, NewFixedPortBind(s.Port), device.NewLogger(
|
||||||
@@ -1244,7 +1243,6 @@ func (s *WireGuardService) ReplaceNetstack(newDNS []netip.Addr) error {
|
|||||||
go s.onNetstackReady(s.tnet)
|
go s.onNetstackReady(s.tnet)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("Netstack replaced successfully with new DNS servers")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user