mirror of
https://github.com/snltty/linker.git
synced 2025-10-09 02:50:12 +08:00
sync
This commit is contained in:
@@ -7,8 +7,9 @@ sidebar_position: 1
|
|||||||
:::tip[说明]
|
:::tip[说明]
|
||||||
|
|
||||||
1. 各个设备的`网卡IP`,不要一样,要同一网段,且不应该使用`1`、`255`
|
1. 各个设备的`网卡IP`,不要一样,要同一网段,且不应该使用`1`、`255`
|
||||||
2. `局域网IP`,是选填的,可以不填,不懂是啥时,不要填、不要填、不要填
|
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. 虽然支持UDP广播,但是UDP广播不会去主动连接所有设备,所以,你可以先 ping 以下对方,让两端相互连接
|
3. `局域网IP`,是选填的,可以不填,不懂是啥时,不要填、不要填、不要填
|
||||||
|
4. 虽然支持UDP广播,但是UDP广播不会去主动连接所有设备,所以,你可以先 ping 以下对方,让两端相互连接
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|
||||||
|
@@ -76,7 +76,7 @@ namespace linker.libs
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Warning(error);
|
LoggerHelper.Instance.Warning($"file:{fileName},arg:{arg},commands:{string.Join(Environment.NewLine,commands)} -> {error}");
|
||||||
}
|
}
|
||||||
proc.WaitForExit();
|
proc.WaitForExit();
|
||||||
proc.Close();
|
proc.Close();
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
namespace linker.tun
|
namespace linker.tun
|
||||||
{
|
{
|
||||||
@@ -114,6 +115,24 @@ namespace linker.tun
|
|||||||
/// 原始IP包
|
/// 原始IP包
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ReadOnlyMemory<byte> IPPacket;
|
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>
|
/// <summary>
|
||||||
|
@@ -191,21 +191,8 @@ namespace linker.tun
|
|||||||
|
|
||||||
|
|
||||||
LinkerTunDevicPacket packet = new LinkerTunDevicPacket();
|
LinkerTunDevicPacket packet = new LinkerTunDevicPacket();
|
||||||
packet.Packet = buffer;
|
packet.Unpacket(buffer);
|
||||||
packet.IPPacket = buffer.Slice(4);
|
|
||||||
|
|
||||||
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);
|
await linkerTunDeviceCallback.Callback(packet).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@@ -156,6 +156,7 @@ namespace linker.plugins.relay.transport
|
|||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error(ex);
|
LoggerHelper.Instance.Error(ex);
|
||||||
}
|
}
|
||||||
|
callback(null);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ using linker.plugins.tuntap.config;
|
|||||||
using linker.tun;
|
using linker.tun;
|
||||||
using System.Buffers.Binary;
|
using System.Buffers.Binary;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace linker.plugins.tuntap.proxy
|
namespace linker.plugins.tuntap.proxy
|
||||||
{
|
{
|
||||||
@@ -80,7 +81,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
{
|
{
|
||||||
if (connections.IsEmpty == false)
|
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
|
else
|
||||||
@@ -97,13 +98,16 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
{
|
{
|
||||||
await connection.SendAsync(packet.Packet);
|
await connection.SendAsync(packet.Packet);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (packet.Version == 6 && (packet.DistIPAddress.Span[0] & 0xFF) == 0xFF)
|
else if (packet.Version == 6 && (packet.DistIPAddress.Span[0] & 0xFF) == 0xFF)
|
||||||
{
|
{
|
||||||
if (connections.IsEmpty == false)
|
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