mirror of
https://github.com/snltty/linker.git
synced 2025-10-13 04:43:47 +08:00
支持局域网IPV6
This commit is contained in:
@@ -142,7 +142,10 @@ namespace linker.tun
|
|||||||
|
|
||||||
public void SetMtu(int value)
|
public void SetMtu(int value)
|
||||||
{
|
{
|
||||||
CommandHelper.Windows(string.Empty, new string[] { $"netsh interface ipv4 set subinterface {interfaceNumber} mtu={value} store=persistent" });
|
CommandHelper.Windows(string.Empty, new string[] {
|
||||||
|
$"netsh interface ipv4 set subinterface {interfaceNumber} mtu={value} store=persistent" ,
|
||||||
|
$"netsh interface ipv6 set subinterface {interfaceNumber} mtu={value} store=persistent"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
public void SetNat(out string error)
|
public void SetNat(out string error)
|
||||||
{
|
{
|
||||||
@@ -256,7 +259,9 @@ namespace linker.tun
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Marshal.GetLastWin32Error() == 259L)
|
int error = Marshal.GetLastWin32Error();
|
||||||
|
|
||||||
|
if (error == 0 || error == 259L)
|
||||||
{
|
{
|
||||||
WinTun.WaitForSingleObject(waitHandle, 0xFFFFFFFF);
|
WinTun.WaitForSingleObject(waitHandle, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
@@ -95,7 +95,7 @@ namespace linker.tunnel
|
|||||||
}
|
}
|
||||||
|
|
||||||
tunnelAdapter.SetTunnelTransports(transportItems, true);
|
tunnelAdapter.SetTunnelTransports(transportItems, true);
|
||||||
LoggerHelper.Instance.Warning($"load tunnel transport:{string.Join(",", transports.Select(c => c.Name))}");
|
LoggerHelper.Instance.Info($"load tunnel transport:{string.Join(",", transports.Select(c => c.Name))}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -77,13 +77,13 @@ namespace linker.tunnel.transport
|
|||||||
{
|
{
|
||||||
if (QuicListener.IsSupported == false)
|
if (QuicListener.IsSupported == false)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic not supported, need win11+,or linux");
|
LoggerHelper.Instance.Warning($"msquic not supported, need win11+,or linux");
|
||||||
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (tunnelAdapter.Certificate == null)
|
if (tunnelAdapter.Certificate == null)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic need ssl");
|
LoggerHelper.Instance.Warning($"msquic need ssl");
|
||||||
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -137,13 +137,13 @@ namespace linker.tunnel.transport
|
|||||||
{
|
{
|
||||||
if (QuicListener.IsSupported == false)
|
if (QuicListener.IsSupported == false)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic not supported, need win11+,or linux");
|
LoggerHelper.Instance.Warning($"msquic not supported, need win11+,or linux");
|
||||||
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tunnelAdapter.Certificate == null)
|
if (tunnelAdapter.Certificate == null)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic need ssl");
|
LoggerHelper.Instance.Warning($"msquic need ssl");
|
||||||
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -665,12 +665,12 @@ namespace linker.tunnel.transport
|
|||||||
{
|
{
|
||||||
if (QuicListener.IsSupported == false)
|
if (QuicListener.IsSupported == false)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic not supported, need win11+,or linux, or try to restart linker");
|
LoggerHelper.Instance.Warning($"msquic not supported, need win11+,or linux, or try to restart linker");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tunnelAdapter.Certificate == null)
|
if (tunnelAdapter.Certificate == null)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic need ssl");
|
LoggerHelper.Instance.Warning($"msquic need ssl");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -126,7 +126,6 @@ namespace linker.tunnel.transport
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.ToString());
|
|
||||||
socket.SafeClose();
|
socket.SafeClose();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ namespace linker.tunnel.wanport
|
|||||||
public void Init(List<ITunnelWanPortProtocol> tunnelWanPorts)
|
public void Init(List<ITunnelWanPortProtocol> tunnelWanPorts)
|
||||||
{
|
{
|
||||||
this.tunnelWanPorts = tunnelWanPorts;
|
this.tunnelWanPorts = tunnelWanPorts;
|
||||||
LoggerHelper.Instance.Warning($"load tunnel wanport compacts:{string.Join(",", tunnelWanPorts.Select(c => c.Name))}");
|
LoggerHelper.Instance.Info($"load tunnel wanport compacts:{string.Join(",", tunnelWanPorts.Select(c => c.Name))}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TunnelWanPortTypeInfo> GetTypes()
|
public List<TunnelWanPortTypeInfo> GetTypes()
|
||||||
|
@@ -37,7 +37,7 @@ namespace linker.plugins.capi
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LoggerHelper.Instance.Warning($"load client api:{item.Name}");
|
LoggerHelper.Instance.Info($"load client api:{item.Name}");
|
||||||
|
|
||||||
string path = item.Name.Replace("ApiController", "").Replace("ApiController", "");
|
string path = item.Name.Replace("ApiController", "").Replace("ApiController", "");
|
||||||
foreach (MethodInfo method in item.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
|
foreach (MethodInfo method in item.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
|
||||||
|
@@ -170,7 +170,7 @@ namespace linker.plugins.messenger
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LoggerHelper.Instance.Warning($"load messenger:{type.Name}");
|
LoggerHelper.Instance.Info($"load messenger:{type.Name}");
|
||||||
|
|
||||||
foreach (var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
|
foreach (var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
|
||||||
{
|
{
|
||||||
@@ -198,7 +198,7 @@ namespace linker.plugins.messenger
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"{type.Name}->{method.Name}->{mid.Id} 消息id已存在");
|
LoggerHelper.Instance.Warning($"{type.Name}->{method.Name}->{mid.Id} 消息id已存在");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -70,7 +70,7 @@ namespace linker.plugins.relay
|
|||||||
IEnumerable<Type> types = ReflectionHelper.GetInterfaceSchieves(assembs, typeof(ITransport));
|
IEnumerable<Type> types = ReflectionHelper.GetInterfaceSchieves(assembs, typeof(ITransport));
|
||||||
transports = types.Select(c => (ITransport)serviceProvider.GetService(c)).Where(c => c != null).Where(c => string.IsNullOrWhiteSpace(c.Name) == false).ToList();
|
transports = types.Select(c => (ITransport)serviceProvider.GetService(c)).Where(c => c != null).Where(c => string.IsNullOrWhiteSpace(c.Name) == false).ToList();
|
||||||
|
|
||||||
LoggerHelper.Instance.Warning($"load relay transport:{string.Join(",", transports.Select(c => c.Name))}");
|
LoggerHelper.Instance.Info($"load relay transport:{string.Join(",", transports.Select(c => c.Name))}");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取所有中继协议
|
/// 获取所有中继协议
|
||||||
|
@@ -168,7 +168,7 @@ namespace linker.plugins.tunnel
|
|||||||
File.Move("msquic.dll", "msquic.dll.temp", true);
|
File.Move("msquic.dll", "msquic.dll.temp", true);
|
||||||
File.Move("msquic-openssl.dll", "msquic.dll", true);
|
File.Move("msquic-openssl.dll", "msquic.dll", true);
|
||||||
|
|
||||||
Environment.Exit(1);
|
//Environment.Exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@@ -69,8 +69,8 @@ namespace linker.plugins.tunnel
|
|||||||
config.Data.Client.Tunnel.RouteIPs = ips.ToArray();
|
config.Data.Client.Tunnel.RouteIPs = ips.ToArray();
|
||||||
LoggerHelper.Instance.Warning($"route ips:{string.Join(",", ips.Select(c => c.ToString()))}");
|
LoggerHelper.Instance.Warning($"route ips:{string.Join(",", ips.Select(c => c.ToString()))}");
|
||||||
config.Data.Client.Tunnel.LocalIPs = NetworkHelper.GetIPV6().Concat(NetworkHelper.GetIPV4()).ToArray();
|
config.Data.Client.Tunnel.LocalIPs = NetworkHelper.GetIPV6().Concat(NetworkHelper.GetIPV4()).ToArray();
|
||||||
LoggerHelper.Instance.Info($"tunnel local ips :{string.Join(",", config.Data.Client.Tunnel.LocalIPs.Select(c => c.ToString()))}");
|
LoggerHelper.Instance.Warning($"tunnel local ips :{string.Join(",", config.Data.Client.Tunnel.LocalIPs.Select(c => c.ToString()))}");
|
||||||
LoggerHelper.Instance.Info($"tunnel route level:{config.Data.Client.Tunnel.RouteLevel}");
|
LoggerHelper.Instance.Warning($"tunnel route level:{config.Data.Client.Tunnel.RouteLevel}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ namespace linker.plugins.tunnel.excludeip
|
|||||||
IEnumerable<Type> types = ReflectionHelper.GetInterfaceSchieves(assembs, typeof(ITunnelExcludeIP));
|
IEnumerable<Type> types = ReflectionHelper.GetInterfaceSchieves(assembs, typeof(ITunnelExcludeIP));
|
||||||
excludeIPs = types.Select(c => (ITunnelExcludeIP)serviceProvider.GetService(c)).Where(c => c != null).ToList();
|
excludeIPs = types.Select(c => (ITunnelExcludeIP)serviceProvider.GetService(c)).Where(c => c != null).ToList();
|
||||||
|
|
||||||
LoggerHelper.Instance.Warning($"load tunnel excludeips :{string.Join(",", types.Select(c => c.Name))}");
|
LoggerHelper.Instance.Info($"load tunnel excludeips :{string.Join(",", types.Select(c => c.Name))}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ExcludeIPItem> Get()
|
public List<ExcludeIPItem> Get()
|
||||||
|
@@ -78,11 +78,17 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
|
|
||||||
public async Task Callback(LinkerTunDevicPacket packet)
|
public async Task Callback(LinkerTunDevicPacket packet)
|
||||||
{
|
{
|
||||||
//IPV4
|
//IPV4广播组播
|
||||||
if (packet.Version == 4)
|
if (packet.Version == 4 && packet.DistIPAddress.GetIsBroadcastAddress())
|
||||||
{
|
{
|
||||||
// 广播组播
|
if (connections.IsEmpty == false)
|
||||||
if (packet.DistIPAddress.GetIsBroadcastAddress())
|
{
|
||||||
|
await Task.WhenAll(connections.Values.Where(c => c != null && c.Connected).Select(c => c.SendAsync(packet.Packet)));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//IPV6 多播
|
||||||
|
else if (packet.Version == 6 && (packet.DistIPAddress.Span[0] & 0xFF) == 0xFF)
|
||||||
{
|
{
|
||||||
if (connections.IsEmpty == false)
|
if (connections.IsEmpty == false)
|
||||||
{
|
{
|
||||||
@@ -91,7 +97,8 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint ip = BinaryPrimitives.ReadUInt32BigEndian(packet.DistIPAddress.Span);
|
//IPV4+IPV6 单播
|
||||||
|
uint ip = BinaryPrimitives.ReadUInt32BigEndian(packet.DistIPAddress.Span[^4..]);
|
||||||
if (ipConnections.TryGetValue(ip, out ITunnelConnection connection) == false || connection == null || connection.Connected == false)
|
if (ipConnections.TryGetValue(ip, out ITunnelConnection connection) == false || connection == null || connection.Connected == false)
|
||||||
{
|
{
|
||||||
connection = await ConnectTunnel(ip);
|
connection = await ConnectTunnel(ip);
|
||||||
@@ -105,16 +112,6 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
await connection.SendAsync(packet.Packet);
|
await connection.SendAsync(packet.Packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//IPV6 多播
|
|
||||||
else if (packet.Version == 6 && (packet.DistIPAddress.Span[0] & 0xFF) == 0xFF)
|
|
||||||
{
|
|
||||||
if (connections.IsEmpty == false)
|
|
||||||
{
|
|
||||||
await Task.WhenAll(connections.Values.Where(c => c != null && c.Connected).Select(c => c.SendAsync(packet.Packet)));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置IP,等下有连接进来,用IP匹配,才能知道这个连接是要连谁
|
/// 设置IP,等下有连接进来,用IP匹配,才能知道这个连接是要连谁
|
||||||
|
@@ -59,7 +59,7 @@ namespace linker.startup
|
|||||||
|
|
||||||
config.Data.Common.Plugins = startups.Select(c => c.Name).ToArray();
|
config.Data.Common.Plugins = startups.Select(c => c.Name).ToArray();
|
||||||
|
|
||||||
LoggerHelper.Instance.Warning($"load startup : {string.Join(",", startups.Select(c => c.Name))}");
|
LoggerHelper.Instance.Info($"load startup : {string.Join(",", startups.Select(c => c.Name))}");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载插件依赖
|
/// 加载插件依赖
|
||||||
@@ -90,12 +90,12 @@ namespace linker.startup
|
|||||||
{
|
{
|
||||||
if (config.Data.Common.Modes.Contains("client"))
|
if (config.Data.Common.Modes.Contains("client"))
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Warning($"add startup {startup.Name} client");
|
LoggerHelper.Instance.Info($"add startup {startup.Name} client");
|
||||||
startup.AddClient(serviceCollection, config, assemblies);
|
startup.AddClient(serviceCollection, config, assemblies);
|
||||||
}
|
}
|
||||||
if (config.Data.Common.Modes.Contains("server"))
|
if (config.Data.Common.Modes.Contains("server"))
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Warning($"add startup {startup.Name} server");
|
LoggerHelper.Instance.Info($"add startup {startup.Name} server");
|
||||||
startup.AddServer(serviceCollection, config, assemblies);
|
startup.AddServer(serviceCollection, config, assemblies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,12 +113,12 @@ namespace linker.startup
|
|||||||
{
|
{
|
||||||
if (config.Data.Common.Modes.Contains("client"))
|
if (config.Data.Common.Modes.Contains("client"))
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Warning($"use startup {startup.Name} client");
|
LoggerHelper.Instance.Info($"use startup {startup.Name} client");
|
||||||
startup.UseClient(serviceProvider, config, assemblies);
|
startup.UseClient(serviceProvider, config, assemblies);
|
||||||
}
|
}
|
||||||
if (config.Data.Common.Modes.Contains("server"))
|
if (config.Data.Common.Modes.Contains("server"))
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Warning($"use startup {startup.Name} server");
|
LoggerHelper.Instance.Info($"use startup {startup.Name} server");
|
||||||
startup.UseServer(serviceProvider, config, assemblies);
|
startup.UseServer(serviceProvider, config, assemblies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user