Update DNSController and TUNController

This commit is contained in:
ChsBuffer
2021-03-27 23:09:33 +08:00
parent 4c4ad72d1d
commit 5b2b6c9f96
2 changed files with 8 additions and 10 deletions

View File

@@ -25,7 +25,6 @@ namespace Netch.Controllers
aiodns_dial((int) NameList.TYPE_LIST, Encoding.UTF8.GetBytes(Path.GetFullPath(Global.Settings.AioDNS.RulePath)));
aiodns_dial((int) NameList.TYPE_CDNS, Encoding.UTF8.GetBytes($"{Global.Settings.AioDNS.ChinaDNS}"));
aiodns_dial((int) NameList.TYPE_ODNS, Encoding.UTF8.GetBytes($"{Global.Settings.AioDNS.OtherDNS}"));
aiodns_dial((int) NameList.TYPE_METH, Encoding.UTF8.GetBytes(Global.Settings.AioDNS.Protocol));
if (!aiodns_init())
throw new Exception("AioDNS start failed");
@@ -42,14 +41,13 @@ namespace Netch.Controllers
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
public static extern void aiodns_free();
private enum NameList
public enum NameList
{
TYPE_REST,
TYPE_ADDR,
TYPE_LIST,
TYPE_CDNS,
TYPE_ODNS,
TYPE_METH
TYPE_ODNS
}
#endregion

View File

@@ -133,11 +133,7 @@ namespace Netch.Controllers
{
var tasks = new[]
{
Task.Run(() =>
{
Free();
// _tunInterop.Unload();
}),
Task.Run(Free),
Task.Run(ClearRouteTable),
Task.Run(DNSController.Stop)
};
@@ -266,7 +262,9 @@ namespace Netch.Controllers
{
case Action.Create:
result = NativeMethods.CreateRoute((int) AddressFamily.InterNetwork, ip, cidr, gateway, index, metric);
ipList.Add(ipNetwork);
if (result && record)
ipList.Add(ipNetwork);
break;
case Action.Delete:
result = NativeMethods.DeleteRoute((int) AddressFamily.InterNetwork, ip, cidr, gateway, index, metric);
@@ -277,7 +275,9 @@ namespace Netch.Controllers
Logging.Debug($"{action}Route(\"{ip}\", {cidr}, \"{gateway}\", {index}, {metric})");
if (!result)
{
Logging.Warning($"Failed to invoke {action}Route(\"{ip}\", {cidr}, \"{gateway}\", {index}, {metric})");
}
return result;
}