From e07c3a7fe072f8450629369059411fc7616b9d40 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sun, 20 Mar 2022 04:19:48 +0800 Subject: [PATCH] Fix: wintun dns address --- listener/tun/ipstack/commons/router_windows.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/listener/tun/ipstack/commons/router_windows.go b/listener/tun/ipstack/commons/router_windows.go index 5ddcf709..0168f88d 100644 --- a/listener/tun/ipstack/commons/router_windows.go +++ b/listener/tun/ipstack/commons/router_windows.go @@ -39,9 +39,11 @@ startOver: tryTimes++ var ( - luid = winipcfg.LUID(dev.(*tun.TUN).LUID()) - ip = addr.Masked().Addr().Next() - addresses = []netip.Prefix{netip.PrefixFrom(ip, addr.Bits())} + luid = winipcfg.LUID(dev.(*tun.TUN).LUID()) + ip = addr.Masked().Addr().Next() + gw = ip.Next() + addresses = []netip.Prefix{netip.PrefixFrom(ip, addr.Bits())} + dnsAddress = []netip.Addr{gw} family4 = winipcfg.AddressFamily(windows.AF_INET) familyV6 = winipcfg.AddressFamily(windows.AF_INET6) @@ -123,7 +125,7 @@ startOver: // add gateway deduplicatedRoutes = append(deduplicatedRoutes, &winipcfg.RouteData{ Destination: addr.Masked(), - NextHop: addr.Masked().Addr().Next().Next(), + NextHop: gw, Metric: 0, }) @@ -193,12 +195,11 @@ startOver: return fmt.Errorf("unable to set v6 metric and MTU: %w", err) } - dnsAdds := []netip.Addr{netip.MustParseAddr("198.18.0.2")} - err = luid.SetDNS(family4, dnsAdds, nil) + err = luid.SetDNS(family4, dnsAddress, nil) if err == windows.ERROR_NOT_FOUND && retryOnFailure { goto startOver } else if err != nil { - return fmt.Errorf("unable to set DNS %s %s: %w", "198.18.0.2", "nil", err) + return fmt.Errorf("unable to set DNS %s %s: %w", dnsAddress[0].String(), "nil", err) } wintunInterfaceName = dev.Name()