[Netch] Compatible with the latest Redirector

This commit is contained in:
Connection Refused
2021-10-18 18:50:54 +08:00
parent 0d535aa27e
commit cecae73c03
4 changed files with 13 additions and 33 deletions

View File

@@ -53,6 +53,8 @@ namespace Netch.Controllers
// DNS
Dial(NameList.AIO_FILTERDNS, _rdrConfig.DNSHijack.ToString().ToLower());
Dial(NameList.AIO_DNSONLY, "false");
Dial(NameList.AIO_DNSPROX, "true");
if (_rdrConfig.DNSHijack)
{
var dns = new Uri(DnsUtils.AppendScheme(DnsUtils.AppendPort(_rdrConfig.DNSHijackHost), "udp"));
@@ -202,15 +204,13 @@ namespace Netch.Controllers
}
// 注册驱动文件
var result = NFAPI.nf_registerDriver("netfilter2");
if (result == NF_STATUS.NF_STATUS_SUCCESS)
if (Redirector.aio_register("netfilter2"))
{
Log.Information("Install netfilter2 driver finished");
}
else
{
Log.Error("Register netfilter2 failed: {Result}", result);
throw new MessageException($"Register netfilter2 failed\n{result}");
Log.Error("Register netfilter2 failed");
}
}
@@ -237,7 +237,7 @@ namespace Netch.Controllers
if (!File.Exists(SystemDriver))
return true;
NFAPI.nf_unRegisterDriver("netfilter2");
Redirector.aio_unregister("netfilter2");
File.Delete(SystemDriver);
return true;

View File

@@ -1,15 +0,0 @@
using System.Runtime.InteropServices;
namespace Netch.Interops
{
public static class NFAPI
{
private const string nfapinet_bin = "nfapinet.dll";
[DllImport(nfapinet_bin, CallingConvention = CallingConvention.Cdecl)]
public static extern NF_STATUS nf_registerDriver(string driverName);
[DllImport(nfapinet_bin, CallingConvention = CallingConvention.Cdecl)]
public static extern NF_STATUS nf_unRegisterDriver(string driverName);
}
}

View File

@@ -1,11 +0,0 @@
namespace Netch.Interops
{
public enum NF_STATUS : int
{
NF_STATUS_SUCCESS = 0,
NF_STATUS_FAIL = -1,
NF_STATUS_INVALID_ENDPOINT_ID = -2,
NF_STATUS_NOT_INITIALIZED = -3,
NF_STATUS_IO_ERROR = -4
}
}

View File

@@ -18,6 +18,8 @@ namespace Netch.Interops
AIO_ICMPING,
AIO_DNSONLY,
AIO_DNSPROX,
AIO_DNSHOST,
AIO_DNSPORT,
@@ -49,6 +51,12 @@ namespace Netch.Interops
private const string Redirector_bin = "Redirector.bin";
[DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)]
public static extern bool aio_register([MarshalAs(UnmanagedType.LPWStr)] string value);
[DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)]
public static extern bool aio_unregister([MarshalAs(UnmanagedType.LPWStr)] string value);
[DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)]
private static extern bool aio_dial(NameList name, [MarshalAs(UnmanagedType.LPWStr)] string value);
@@ -58,12 +66,10 @@ namespace Netch.Interops
[DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)]
private static extern bool aio_free();
/*
[DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)]
private static extern ulong aio_getUP();
[DllImport(Redirector_bin, CallingConvention = CallingConvention.Cdecl)]
private static extern ulong aio_getDL();
*/
}
}