mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
add NKR_VPN_LEGACY_DNS
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"neko/pkg/neko_common"
|
"neko/pkg/neko_common"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@@ -18,7 +19,7 @@ import (
|
|||||||
|
|
||||||
var instance *libcore.V2RayInstance
|
var instance *libcore.V2RayInstance
|
||||||
var getNekorayTunIndex = func() int { return 0 } // Windows only
|
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() {
|
func setupCore() {
|
||||||
// TODO del
|
// TODO del
|
||||||
@@ -28,14 +29,16 @@ func setupCore() {
|
|||||||
// localdns setup
|
// localdns setup
|
||||||
resolver_def := &net.Resolver{PreferGo: false}
|
resolver_def := &net.Resolver{PreferGo: false}
|
||||||
resolver_go := &net.Resolver{PreferGo: true}
|
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
|
resolver_go.Dial = underlyingNetDialer.DialContext
|
||||||
|
logrus.Println("using NKR_VPN_LEGACY_DNS")
|
||||||
}
|
}
|
||||||
localdns.SetLookupFunc(func(network string, host string) (ips []net.IP, err error) {
|
localdns.SetLookupFunc(func(network string, host string) (ips []net.IP, err error) {
|
||||||
// fix old sekai
|
// fix old sekai
|
||||||
defer func() {
|
defer func() {
|
||||||
if len(ips) == 0 {
|
if len(ips) == 0 {
|
||||||
logrus.Println("LookupIP error:", err)
|
logrus.Println("LookupIP error:", network, host, err)
|
||||||
err = dns.ErrEmptyResponse
|
err = dns.ErrEmptyResponse
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -43,7 +46,7 @@ func setupCore() {
|
|||||||
if getNekorayTunIndex() == 0 {
|
if getNekorayTunIndex() == 0 {
|
||||||
return resolver_def.LookupIP(context.Background(), network, host)
|
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)
|
return resolver_go.LookupIP(context.Background(), network, host)
|
||||||
})
|
})
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"libcore/protect"
|
"libcore/protect"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@@ -102,4 +103,12 @@ func is_fwmark_exist(number int) bool {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
protect.FdProtector = &fwmarkProtector{}
|
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
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
namespace NekoRay::sys {
|
namespace NekoRay::sys {
|
||||||
ExternalProcess::ExternalProcess() : QProcess() {
|
ExternalProcess::ExternalProcess() : QProcess() {
|
||||||
// qDebug() << "[Debug] ExternalProcess()" << this << running_ext;
|
// qDebug() << "[Debug] ExternalProcess()" << this << running_ext;
|
||||||
|
this->env = QProcessEnvironment::systemEnvironment().toStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExternalProcess::~ExternalProcess() {
|
ExternalProcess::~ExternalProcess() {
|
||||||
@@ -117,7 +118,6 @@ namespace NekoRay::sys {
|
|||||||
|
|
||||||
void CoreProcess::Start() {
|
void CoreProcess::Start() {
|
||||||
show_stderr = false;
|
show_stderr = false;
|
||||||
env = QStringList();
|
|
||||||
auto v2ray_asset_dir = FindCoreAsset("geoip.dat");
|
auto v2ray_asset_dir = FindCoreAsset("geoip.dat");
|
||||||
if (!v2ray_asset_dir.isEmpty()) {
|
if (!v2ray_asset_dir.isEmpty()) {
|
||||||
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
|
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
|
||||||
|
|||||||
Reference in New Issue
Block a user