Skip to content

Commit

Permalink
fix: windows localhost dns
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Nov 9, 2022
1 parent 7a619a8 commit 3e0aac7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
13 changes: 13 additions & 0 deletions go/cmd/nekoray_core/core_ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,28 @@ import (
"time"

v2rayNet "github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/features/dns/localdns"
)

var instance *libcore.V2RayInstance
var getNekorayTunIndex = func() int { return 0 }

func setupCore() {
// TODO del
device.IsNekoray = true
libcore.SetConfig("", false, true)
libcore.InitCore("", "", "", nil, ".", "moe.nekoray.pc:bg", true, 50)
// localdns setup
resolver_def := &net.Resolver{PreferGo: false}
resolver_go := &net.Resolver{PreferGo: true}
localdns.SetLookupFunc(func(network string, host string) ([]net.IP, error) {
// Normal mode use system resolver (go bug)
if getNekorayTunIndex() == 0 {
return resolver_def.LookupIP(context.Background(), network, host)
}
// VPN mode use Go resolver
return resolver_go.LookupIP(context.Background(), network, host)
})
//
neko_common.GetProxyHttpClient = func() *http.Client {
return getProxyHttpClient(instance)
Expand Down
17 changes: 15 additions & 2 deletions go/cmd/nekoray_core/protect_bindinterface_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,24 @@ func init() {
}
return nil
})
//
updateRoutes()
iphlpapi.RegisterNotifyRouteChange2(func(callerContext uintptr, row uintptr, notificationType uint32) uintptr {
updateRoutes()
return 0
}, true)
}, false)
//
getNekorayTunIndex = func() (index int) {
lock.Lock()
defer lock.Unlock()
for _, intf := range interfaces {
if intf.Name == "nekoray-tun" {
index = intf.Index
return
}
}
return
}
}

func updateRoutes() {
Expand Down Expand Up @@ -85,7 +98,7 @@ func getBindInterfaceIndex(address string) uint32 {

var nextInterface int
for i, intf := range interfaces {
if intf.Name == "nekoray-tun" || intf.Name == "wintun" || intf.Name == "TunMax" {
if intf.Name == "nekoray-tun" {
if len(interfaces) > i+1 {
nextInterface = interfaces[i+1].Index
}
Expand Down
1 change: 1 addition & 0 deletions go/cmd/nekoray_core/toolbox_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func ToolBox() {
for _, route := range routes {
log.Println(route)
}
log.Println("TUN:", getNekorayTunIndex())
log.Println("Upstream:", getBindInterfaceIndex("8.8.8.8:8888"))
}
}
Expand Down
2 changes: 1 addition & 1 deletion matsuri_commit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ac454d7b46306ea0c4eaedd95ac7ea54fd1afa73
8b1a40059eee4eb7e3db559185aec224324f322c
1 change: 0 additions & 1 deletion sys/ExternalProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ namespace NekoRay::sys {
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir;
}
env << "GODEBUG=netdns=go";
ExternalProcess::Start();
write((dataStore->core_token + "\n").toUtf8());
}
Expand Down

0 comments on commit 3e0aac7

Please sign in to comment.