Skip to content

Commit

Permalink
add NKR_VPN_LEGACY_DNS
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Feb 3, 2023
1 parent 7a3be29 commit c0b60f9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
11 changes: 7 additions & 4 deletions go/cmd/nekoray_core/core_ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"neko/pkg/neko_common"
"net"
"net/http"
"os"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -18,7 +19,7 @@ import (

var instance *libcore.V2RayInstance
var getNekorayTunIndex = func() int { return 0 } // Windows only
var underlyingNetDialer *net.Dialer // Windows only
var underlyingNetDialer *net.Dialer // NKR_VPN_LEGACY_DNS only

func setupCore() {
// TODO del
Expand All @@ -28,22 +29,24 @@ func setupCore() {
// localdns setup
resolver_def := &net.Resolver{PreferGo: false}
resolver_go := &net.Resolver{PreferGo: true}
if underlyingNetDialer != nil {
if underlyingNetDialer != nil && os.Getenv("NKR_VPN_LEGACY_DNS") == "1" {
resolver_def.Dial = underlyingNetDialer.DialContext
resolver_go.Dial = underlyingNetDialer.DialContext
logrus.Println("using NKR_VPN_LEGACY_DNS")
}
localdns.SetLookupFunc(func(network string, host string) (ips []net.IP, err error) {
// fix old sekai
defer func() {
if len(ips) == 0 {
logrus.Println("LookupIP error:", err)
logrus.Println("LookupIP error:", network, host, err)
err = dns.ErrEmptyResponse
}
}()
// Normal mode use system resolver (go bug)
if getNekorayTunIndex() == 0 {
return resolver_def.LookupIP(context.Background(), network, host)
}
// VPN mode use Go resolver
// Windows VPN mode use Go resolver
return resolver_go.LookupIP(context.Background(), network, host)
})
//
Expand Down
9 changes: 9 additions & 0 deletions go/cmd/nekoray_core/protect_fwmark_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"libcore/protect"
"log"
"net"
"strings"
"syscall"

Expand Down Expand Up @@ -102,4 +103,12 @@ func is_fwmark_exist(number int) bool {

func init() {
protect.FdProtector = &fwmarkProtector{}
underlyingNetDialer = &net.Dialer{
Control: func(network, address string, c syscall.RawConn) error {
c.Control(func(fd uintptr) {
protect.FdProtector.Protect(int32(fd))
})
return nil
},
}
}
2 changes: 1 addition & 1 deletion sys/ExternalProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace NekoRay::sys {
ExternalProcess::ExternalProcess() : QProcess() {
// qDebug() << "[Debug] ExternalProcess()" << this << running_ext;
this->env = QProcessEnvironment::systemEnvironment().toStringList();
}

ExternalProcess::~ExternalProcess() {
Expand Down Expand Up @@ -117,7 +118,6 @@ namespace NekoRay::sys {

void CoreProcess::Start() {
show_stderr = false;
env = QStringList();
auto v2ray_asset_dir = FindCoreAsset("geoip.dat");
if (!v2ray_asset_dir.isEmpty()) {
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
Expand Down

0 comments on commit c0b60f9

Please sign in to comment.