mirror of
https://github.com/snltty/linker.git
synced 2025-09-26 21:15:57 +08:00
升级litedb和内网穿透不能删除
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
using linker.libs;
|
||||
using linker.libs.extends;
|
||||
using linker.libs.timer;
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Frozen;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using linker.libs;
|
||||
using linker.libs.extends;
|
||||
using linker.libs.timer;
|
||||
using System.Buffers.Binary;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
@@ -32,46 +31,8 @@ namespace linker.tun
|
||||
|
||||
public LinkerWinTunDevice()
|
||||
{
|
||||
/*
|
||||
winDivert = new WinDivert("inbound and (( ip.SrcAddr == 10.18.18.0/24 and ip.DstAddr == 192.168.56.0/24) or ( ip.SrcAddr == 192.168.56.0/24))", WinDivert.Layer.Network, 0, WinDivert.Flag.Sniff);
|
||||
var packet = new Memory<byte>(new byte[WinDivert.MTUMax]);
|
||||
var abuf = new Memory<WinDivertAddress>(new WinDivertAddress[1]);
|
||||
TimerHelper.Async(() =>
|
||||
{
|
||||
uint recvLen = 0, addrLen = 0;
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
(recvLen, addrLen) = winDivert.RecvEx(packet.Span, abuf.Span);
|
||||
|
||||
var recv = packet[..(int)recvLen];
|
||||
var addr = abuf[..(int)addrLen];
|
||||
foreach (var (i, p) in new WinDivertIndexedPacketParser(recv))
|
||||
{
|
||||
ModifyPacket(p, ref addr.Span[i]);
|
||||
}
|
||||
//_ = winDivert.SendEx(recv.Span, addr.Span);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
winDivert.Dispose();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
NetworkIPv4Addr sourceAddr = IPv4Addr.Parse("10.18.18.23");
|
||||
private unsafe void ModifyPacket(WinDivertParseResult p, ref WinDivertAddress addr)
|
||||
{
|
||||
if (p.IPv4Hdr->SrcAddr == sourceAddr)
|
||||
{
|
||||
Console.WriteLine($"{p.IPv4Hdr->SrcAddr}->{p.IPv4Hdr->DstAddr}");
|
||||
}
|
||||
//WinDivert.CalcChecksums(p.Packet.Span, ref addr, 0);
|
||||
}
|
||||
|
||||
|
||||
public bool Setup(string name, IPAddress address, IPAddress gateway, byte prefixLength, out string error)
|
||||
{
|
||||
@@ -227,7 +188,6 @@ namespace linker.tun
|
||||
{
|
||||
|
||||
error = string.Empty;
|
||||
//return;
|
||||
|
||||
if (address == null || address.Equals(IPAddress.Any)) return;
|
||||
try
|
||||
@@ -349,7 +309,7 @@ namespace linker.tun
|
||||
}
|
||||
|
||||
|
||||
private byte[] buffer = new byte[8 * 1024];
|
||||
private byte[] buffer = new byte[65 * 1024];
|
||||
public unsafe byte[] Read(out int length)
|
||||
{
|
||||
length = 0;
|
||||
@@ -386,24 +346,6 @@ namespace linker.tun
|
||||
public unsafe bool Write(ReadOnlyMemory<byte> buffer)
|
||||
{
|
||||
if (session == 0 || tokenSource.IsCancellationRequested) return false;
|
||||
/*
|
||||
if ((byte)(buffer.Span[0] >> 4 & 0b1111) == 4)
|
||||
{
|
||||
uint distIP = BinaryPrimitives.ReadUInt32BigEndian(buffer.Span.Slice(16, 4));
|
||||
if (distIP != address32)
|
||||
{
|
||||
var addr = new WinDivertAddress
|
||||
{
|
||||
Layer = WinDivert.Layer.Network,
|
||||
Outbound = true,
|
||||
IPv6 = false
|
||||
};
|
||||
winDivert.SendEx(buffer.Span, new ReadOnlySpan<WinDivertAddress>(ref addr));
|
||||
Console.WriteLine($"WinDivert sendto {string.Join(".", buffer.Span.Slice(16, 4).ToArray())}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
IntPtr packet = WinTun.WintunAllocateSendPacket(session, (uint)buffer.Length);
|
||||
if (packet != 0)
|
||||
|
83
src/linker.tun/WinDivertNAT.cs
Normal file
83
src/linker.tun/WinDivertNAT.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static linker.libs.winapis.SECUR32;
|
||||
using static System.Collections.Specialized.BitVector32;
|
||||
|
||||
namespace linker.tun
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用层NAT
|
||||
/// </summary>
|
||||
internal sealed class WinDivertNAT
|
||||
{
|
||||
public WinDivertNAT()
|
||||
{
|
||||
/*
|
||||
winDivert = new WinDivert("inbound and (( ip.SrcAddr == 10.18.18.0/24 and ip.DstAddr == 192.168.56.0/24) or ( ip.SrcAddr == 192.168.56.0/24))", WinDivert.Layer.Network, 0, WinDivert.Flag.Sniff);
|
||||
var packet = new Memory<byte>(new byte[WinDivert.MTUMax]);
|
||||
var abuf = new Memory<WinDivertAddress>(new WinDivertAddress[1]);
|
||||
TimerHelper.Async(() =>
|
||||
{
|
||||
uint recvLen = 0, addrLen = 0;
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
(recvLen, addrLen) = winDivert.RecvEx(packet.Span, abuf.Span);
|
||||
|
||||
var recv = packet[..(int)recvLen];
|
||||
var addr = abuf[..(int)addrLen];
|
||||
foreach (var (i, p) in new WinDivertIndexedPacketParser(recv))
|
||||
{
|
||||
ModifyPacket(p, ref addr.Span[i]);
|
||||
}
|
||||
//_ = winDivert.SendEx(recv.Span, addr.Span);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
winDivert.Dispose();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
// NetworkIPv4Addr sourceAddr = IPv4Addr.Parse("10.18.18.23");
|
||||
private unsafe void ModifyPacket(WinDivertParseResult p, ref WinDivertAddress addr)
|
||||
{
|
||||
/*
|
||||
if (p.IPv4Hdr->SrcAddr == sourceAddr)
|
||||
{
|
||||
Console.WriteLine($"{p.IPv4Hdr->SrcAddr}->{p.IPv4Hdr->DstAddr}");
|
||||
}*/
|
||||
//WinDivert.CalcChecksums(p.Packet.Span, ref addr, 0);
|
||||
}
|
||||
|
||||
private void Inject(ReadOnlyMemory<byte> buffer)
|
||||
{
|
||||
/*
|
||||
if ((byte)(buffer.Span[0] >> 4 & 0b1111) == 4)
|
||||
{
|
||||
uint distIP = BinaryPrimitives.ReadUInt32BigEndian(buffer.Span.Slice(16, 4));
|
||||
if (distIP != address32)
|
||||
{
|
||||
var addr = new WinDivertAddress
|
||||
{
|
||||
Layer = WinDivert.Layer.Network,
|
||||
Outbound = true,
|
||||
IPv6 = false
|
||||
};
|
||||
winDivert.SendEx(buffer.Span, new ReadOnlySpan<WinDivertAddress>(ref addr));
|
||||
Console.WriteLine($"WinDivert sendto {string.Join(".", buffer.Span.Slice(16, 4).ToArray())}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
v1.7.3
|
||||
2025-04-17 11:03:30
|
||||
2025-04-17 11:38:40
|
||||
1. 优化自动分配IP
|
||||
2. 优化网卡,排除不明数据包
|
||||
3. 虚拟网卡点对网IP映射,用于解决网段冲突
|
Reference in New Issue
Block a user