mirror of
https://github.com/snltty/linker.git
synced 2025-10-08 18:40:07 +08:00
sync
This commit is contained in:
@@ -7,8 +7,9 @@ sidebar_position: 1
|
||||
:::tip[说明]
|
||||
|
||||
1. 各个设备的`网卡IP`,不要一样,要同一网段,且不应该使用`1`、`255`
|
||||
2. `局域网IP`,是选填的,可以不填,不懂是啥时,不要填、不要填、不要填
|
||||
3. 虽然支持UDP广播,但是UDP广播不会去主动连接所有设备,所以,你可以先 ping 以下对方,让两端相互连接
|
||||
2. 请使用 `10.0.0.0 - 10.255.255.255`、`172.16.0.0 - 172.31.255.255`、`192.168.0.0 - 192.168.255.255` 范围内的IP
|
||||
3. `局域网IP`,是选填的,可以不填,不懂是啥时,不要填、不要填、不要填
|
||||
4. 虽然支持UDP广播,但是UDP广播不会去主动连接所有设备,所以,你可以先 ping 以下对方,让两端相互连接
|
||||
:::
|
||||
|
||||
|
||||
|
@@ -76,7 +76,7 @@ namespace linker.libs
|
||||
}
|
||||
else
|
||||
{
|
||||
LoggerHelper.Instance.Warning(error);
|
||||
LoggerHelper.Instance.Warning($"file:{fileName},arg:{arg},commands:{string.Join(Environment.NewLine,commands)} -> {error}");
|
||||
}
|
||||
proc.WaitForExit();
|
||||
proc.Close();
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace linker.tun
|
||||
{
|
||||
@@ -55,7 +56,7 @@ namespace linker.tun
|
||||
/// <param name="ips"></param>
|
||||
/// <param name="ip"></param>
|
||||
/// <param name="gateway">是不是网关,是网关,将使用NAT转发,不是网关将添加路由</param>
|
||||
public void AddRoute(LinkerTunDeviceRouteItem[] ips, IPAddress ip,bool gateway);
|
||||
public void AddRoute(LinkerTunDeviceRouteItem[] ips, IPAddress ip, bool gateway);
|
||||
/// <summary>
|
||||
/// 删除路由
|
||||
/// </summary>
|
||||
@@ -114,6 +115,24 @@ namespace linker.tun
|
||||
/// 原始IP包
|
||||
/// </summary>
|
||||
public ReadOnlyMemory<byte> IPPacket;
|
||||
|
||||
public void Unpacket(ReadOnlyMemory<byte> buffer)
|
||||
{
|
||||
Packet = buffer;
|
||||
IPPacket = buffer.Slice(4);
|
||||
Version = (byte)(IPPacket.Span[0] >> 4 & 0b1111);
|
||||
|
||||
if (Version == 4)
|
||||
{
|
||||
SourceIPAddress = IPPacket.Slice(12, 4);
|
||||
DistIPAddress = IPPacket.Slice(16, 4);
|
||||
}
|
||||
else if (Version == 6)
|
||||
{
|
||||
SourceIPAddress = IPPacket.Slice(8, 16);
|
||||
DistIPAddress = IPPacket.Slice(24, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -191,21 +191,8 @@ namespace linker.tun
|
||||
|
||||
|
||||
LinkerTunDevicPacket packet = new LinkerTunDevicPacket();
|
||||
packet.Packet = buffer;
|
||||
packet.IPPacket = buffer.Slice(4);
|
||||
packet.Unpacket(buffer);
|
||||
|
||||
packet.Version = (byte)(packet.IPPacket.Span[0] >> 4 & 0b1111);
|
||||
|
||||
if (packet.Version == 4)
|
||||
{
|
||||
packet.SourceIPAddress = packet.IPPacket.Slice(12, 4);
|
||||
packet.DistIPAddress = packet.IPPacket.Slice(16, 4);
|
||||
}
|
||||
else if (packet.Version == 6)
|
||||
{
|
||||
packet.SourceIPAddress = packet.IPPacket.Slice(8, 16);
|
||||
packet.DistIPAddress = packet.IPPacket.Slice(24, 16);
|
||||
}
|
||||
await linkerTunDeviceCallback.Callback(packet).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@@ -156,6 +156,7 @@ namespace linker.plugins.relay.transport
|
||||
{
|
||||
LoggerHelper.Instance.Error(ex);
|
||||
}
|
||||
callback(null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ using linker.plugins.tuntap.config;
|
||||
using linker.tun;
|
||||
using System.Buffers.Binary;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
|
||||
namespace linker.plugins.tuntap.proxy
|
||||
{
|
||||
@@ -80,7 +81,7 @@ namespace linker.plugins.tuntap.proxy
|
||||
{
|
||||
if (connections.IsEmpty == false)
|
||||
{
|
||||
await Task.WhenAll(connections.Values.Select(c => c.SendAsync(packet.Packet)));
|
||||
await Task.WhenAll(connections.Values.Where(c => c != null && c.Connected).Select(c => c.SendAsync(packet.Packet)));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -97,13 +98,16 @@ namespace linker.plugins.tuntap.proxy
|
||||
{
|
||||
await connection.SendAsync(packet.Packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packet.Version == 6 && (packet.DistIPAddress.Span[0] & 0xFF) == 0xFF)
|
||||
{
|
||||
if (connections.IsEmpty == false)
|
||||
{
|
||||
await Task.WhenAll(connections.Values.Select(c => c.SendAsync(packet.Packet)));
|
||||
await Task.WhenAll(connections.Values.Where(c => c != null && c.Connected).Select(c => c.SendAsync(packet.Packet)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user