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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -256,7 +259,9 @@ namespace linker.tun
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Marshal.GetLastWin32Error() == 259L)
|
||||
int error = Marshal.GetLastWin32Error();
|
||||
|
||||
if (error == 0 || error == 259L)
|
||||
{
|
||||
WinTun.WaitForSingleObject(waitHandle, 0xFFFFFFFF);
|
||||
}
|
||||
|
@@ -95,7 +95,7 @@ namespace linker.tunnel
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
return null;
|
||||
}
|
||||
if (tunnelAdapter.Certificate == null)
|
||||
{
|
||||
LoggerHelper.Instance.Error($"msquic need ssl");
|
||||
LoggerHelper.Instance.Warning($"msquic need ssl");
|
||||
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||
return null;
|
||||
}
|
||||
@@ -137,13 +137,13 @@ namespace linker.tunnel.transport
|
||||
{
|
||||
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);
|
||||
return;
|
||||
}
|
||||
if (tunnelAdapter.Certificate == null)
|
||||
{
|
||||
LoggerHelper.Instance.Error($"msquic need ssl");
|
||||
LoggerHelper.Instance.Warning($"msquic need ssl");
|
||||
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
@@ -665,12 +665,12 @@ namespace linker.tunnel.transport
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (tunnelAdapter.Certificate == null)
|
||||
{
|
||||
LoggerHelper.Instance.Error($"msquic need ssl");
|
||||
LoggerHelper.Instance.Warning($"msquic need ssl");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -126,7 +126,6 @@ namespace linker.tunnel.transport
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
socket.SafeClose();
|
||||
break;
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ namespace linker.tunnel.wanport
|
||||
public void Init(List<ITunnelWanPortProtocol> 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()
|
||||
|
@@ -37,7 +37,7 @@ namespace linker.plugins.capi
|
||||
{
|
||||
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", "");
|
||||
foreach (MethodInfo method in item.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
|
||||
|
@@ -170,7 +170,7 @@ namespace linker.plugins.messenger
|
||||
{
|
||||
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))
|
||||
{
|
||||
@@ -198,7 +198,7 @@ namespace linker.plugins.messenger
|
||||
}
|
||||
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));
|
||||
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>
|
||||
/// 获取所有中继协议
|
||||
|
@@ -168,7 +168,7 @@ namespace linker.plugins.tunnel
|
||||
File.Move("msquic.dll", "msquic.dll.temp", true);
|
||||
File.Move("msquic-openssl.dll", "msquic.dll", true);
|
||||
|
||||
Environment.Exit(1);
|
||||
//Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
|
@@ -69,8 +69,8 @@ namespace linker.plugins.tunnel
|
||||
config.Data.Client.Tunnel.RouteIPs = ips.ToArray();
|
||||
LoggerHelper.Instance.Warning($"route ips:{string.Join(",", ips.Select(c => c.ToString()))}");
|
||||
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.Info($"tunnel route level:{config.Data.Client.Tunnel.RouteLevel}");
|
||||
LoggerHelper.Instance.Warning($"tunnel local ips :{string.Join(",", config.Data.Client.Tunnel.LocalIPs.Select(c => c.ToString()))}");
|
||||
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));
|
||||
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()
|
||||
|
@@ -78,32 +78,14 @@ namespace linker.plugins.tuntap.proxy
|
||||
|
||||
public async Task Callback(LinkerTunDevicPacket packet)
|
||||
{
|
||||
//IPV4
|
||||
if (packet.Version == 4)
|
||||
//IPV4广播组播
|
||||
if (packet.Version == 4 && packet.DistIPAddress.GetIsBroadcastAddress())
|
||||
{
|
||||
// 广播组播
|
||||
if (packet.DistIPAddress.GetIsBroadcastAddress())
|
||||
if (connections.IsEmpty == false)
|
||||
{
|
||||
if (connections.IsEmpty == false)
|
||||
{
|
||||
await Task.WhenAll(connections.Values.Where(c => c != null && c.Connected).Select(c => c.SendAsync(packet.Packet)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
uint ip = BinaryPrimitives.ReadUInt32BigEndian(packet.DistIPAddress.Span);
|
||||
if (ipConnections.TryGetValue(ip, out ITunnelConnection connection) == false || connection == null || connection.Connected == false)
|
||||
{
|
||||
connection = await ConnectTunnel(ip);
|
||||
if (connection != null)
|
||||
{
|
||||
ipConnections.AddOrUpdate(ip, connection, (a, b) => connection);
|
||||
}
|
||||
}
|
||||
if (connection != null)
|
||||
{
|
||||
await connection.SendAsync(packet.Packet);
|
||||
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)
|
||||
@@ -114,6 +96,21 @@ namespace linker.plugins.tuntap.proxy
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//IPV4+IPV6 单播
|
||||
uint ip = BinaryPrimitives.ReadUInt32BigEndian(packet.DistIPAddress.Span[^4..]);
|
||||
if (ipConnections.TryGetValue(ip, out ITunnelConnection connection) == false || connection == null || connection.Connected == false)
|
||||
{
|
||||
connection = await ConnectTunnel(ip);
|
||||
if (connection != null)
|
||||
{
|
||||
ipConnections.AddOrUpdate(ip, connection, (a, b) => connection);
|
||||
}
|
||||
}
|
||||
if (connection != null)
|
||||
{
|
||||
await connection.SendAsync(packet.Packet);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -59,7 +59,7 @@ namespace linker.startup
|
||||
|
||||
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>
|
||||
/// 加载插件依赖
|
||||
@@ -90,12 +90,12 @@ namespace linker.startup
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -113,12 +113,12 @@ namespace linker.startup
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user