diff --git a/linker.tun/ILinkerTunDevice.cs b/linker.tun/ILinkerTunDevice.cs
index edcce03e..1cf12735 100644
--- a/linker.tun/ILinkerTunDevice.cs
+++ b/linker.tun/ILinkerTunDevice.cs
@@ -2,50 +2,144 @@
namespace linker.tun
{
+ ///
+ /// 设备接口
+ ///
public interface ILinkerTunDevice
{
+ ///
+ /// 设备名
+ ///
public string Name { get; }
+ ///
+ /// 是否正在运行
+ ///
public bool Running { get; }
+ ///
+ /// 启动
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public bool SetUp(IPAddress address, IPAddress gateway, byte prefixLength, out string error);
+ ///
+ /// 关闭
+ ///
public void Shutdown();
+ ///
+ /// 设置MTU
+ ///
+ ///
public void SetMtu(int value);
+ ///
+ /// 设置NAT转发
+ ///
public void SetNat();
+ ///
+ /// 移除NAT转发
+ ///
public void RemoveNat();
+ ///
+ /// 添加路由
+ ///
+ ///
+ ///
public void AddRoute(LinkerTunDeviceRouteItem[] ips, IPAddress ip);
+ ///
+ /// 删除路由
+ ///
+ ///
public void DelRoute(LinkerTunDeviceRouteItem[] ip);
+ ///
+ /// 读取数据包
+ ///
+ ///
public ReadOnlyMemory Read();
+ ///
+ /// 写入数据包
+ ///
+ ///
+ ///
public bool Write(ReadOnlyMemory buffer);
}
-
+ ///
+ /// 网卡读取数据回调
+ ///
public interface ILinkerTunDeviceCallback
{
+ ///
+ /// 回调
+ ///
+ ///
+ ///
public Task Callback(LinkerTunDevicPacket packet);
}
+ ///
+ /// 数据包
+ ///
public struct LinkerTunDevicPacket
{
+ ///
+ /// 协议版本,4或者6
+ ///
public byte Version;
+ ///
+ /// 源IP
+ ///
public ReadOnlyMemory SourceIPAddress;
+ ///
+ /// 目标IP
+ ///
public ReadOnlyMemory DistIPAddress;
+ ///
+ /// 带4字节头的包
+ ///
public ReadOnlyMemory Packet;
+ ///
+ /// 原始IP包
+ ///
public ReadOnlyMemory IPPacket;
}
+ ///
+ /// 添加路由项
+ ///
public sealed class LinkerTunDeviceRouteItem
{
+ ///
+ /// IP
+ ///
public IPAddress Address { get; set; }
- public byte Mask { get; set; }
+ ///
+ /// 掩码
+ ///
+ public byte PrefixLength { get; set; }
}
+ ///
+ /// 设备状态
+ ///
public enum LinkerTunDeviceStatus
{
+ ///
+ /// 无
+ ///
Normal = 0,
- Starting = 1,
+ ///
+ /// 正在操作
+ ///
+ Operating = 1,
+ ///
+ /// 运行中
+ ///
Running = 2
}
}
diff --git a/linker.tun/LinkerLinuxTunDevice.cs b/linker.tun/LinkerLinuxTunDevice.cs
index c3c999a0..05f8f430 100644
--- a/linker.tun/LinkerLinuxTunDevice.cs
+++ b/linker.tun/LinkerLinuxTunDevice.cs
@@ -150,10 +150,10 @@ namespace linker.tun
{
string[] commands = ips.Select(item =>
{
- uint maskValue = NetworkHelper.MaskValue(item.Mask);
+ uint maskValue = NetworkHelper.MaskValue(item.PrefixLength);
IPAddress _ip = NetworkHelper.ToNetworkIp(item.Address, maskValue);
- return $"ip route add {_ip}/{item.Mask} via {ip} dev {Name} metric 1 ";
+ return $"ip route add {_ip}/{item.PrefixLength} via {ip} dev {Name} metric 1 ";
}).ToArray();
if (commands.Length > 0)
{
@@ -164,9 +164,9 @@ namespace linker.tun
{
string[] commands = ip.Select(item =>
{
- uint maskValue = NetworkHelper.MaskValue(item.Mask);
+ uint maskValue = NetworkHelper.MaskValue(item.PrefixLength);
IPAddress _ip = NetworkHelper.ToNetworkIp(item.Address, maskValue);
- return $"ip route del {_ip}/{item.Mask}";
+ return $"ip route del {_ip}/{item.PrefixLength}";
}).ToArray();
CommandHelper.Linux(string.Empty, commands);
}
diff --git a/linker.tun/LinkerOsxTunDevice.cs b/linker.tun/LinkerOsxTunDevice.cs
index 9676cfd3..984b880b 100644
--- a/linker.tun/LinkerOsxTunDevice.cs
+++ b/linker.tun/LinkerOsxTunDevice.cs
@@ -60,8 +60,8 @@ namespace linker.tun
{
string[] commands = ips.Select(item =>
{
- IPAddress _ip = NetworkHelper.ToNetworkIp(item.Address, item.Mask);
- return $"route add -net {_ip}/{item.Mask} {ip}";
+ IPAddress _ip = NetworkHelper.ToNetworkIp(item.Address, item.PrefixLength);
+ return $"route add -net {_ip}/{item.PrefixLength} {ip}";
}).ToArray();
if (commands.Length > 0)
{
@@ -72,8 +72,8 @@ namespace linker.tun
{
string[] commands = ip.Select(item =>
{
- IPAddress _ip = NetworkHelper.ToNetworkIp(item.Address, item.Mask);
- return $"route delete -net {_ip}/{item.Mask}";
+ IPAddress _ip = NetworkHelper.ToNetworkIp(item.Address, item.PrefixLength);
+ return $"route delete -net {_ip}/{item.PrefixLength}";
}).ToArray();
if (commands.Length > 0)
{
diff --git a/linker.tun/LinkerTunDeviceAdapter.cs b/linker.tun/LinkerTunDeviceAdapter.cs
index f7404157..95ab0def 100644
--- a/linker.tun/LinkerTunDeviceAdapter.cs
+++ b/linker.tun/LinkerTunDeviceAdapter.cs
@@ -23,7 +23,7 @@ namespace linker.tun
if (linkerTunDevice == null) return LinkerTunDeviceStatus.Normal;
return operating == 1
- ? LinkerTunDeviceStatus.Starting
+ ? LinkerTunDeviceStatus.Operating
: linkerTunDevice.Running
? LinkerTunDeviceStatus.Running
: LinkerTunDeviceStatus.Normal;
diff --git a/linker.tun/LinkerWinTunDevice.cs b/linker.tun/LinkerWinTunDevice.cs
index 04fb0ad4..084ac607 100644
--- a/linker.tun/LinkerWinTunDevice.cs
+++ b/linker.tun/LinkerWinTunDevice.cs
@@ -125,7 +125,7 @@ namespace linker.tun
{
string[] commands = ips.Select(item =>
{
- uint maskValue = NetworkHelper.MaskValue(item.Mask);
+ uint maskValue = NetworkHelper.MaskValue(item.PrefixLength);
IPAddress mask = NetworkHelper.GetMaskIp(maskValue);
IPAddress _ip = NetworkHelper.ToNetworkIp(item.Address, maskValue);
@@ -141,7 +141,7 @@ namespace linker.tun
{
string[] commands = ip.Select(item =>
{
- uint maskValue = NetworkHelper.MaskValue(item.Mask);
+ uint maskValue = NetworkHelper.MaskValue(item.PrefixLength);
IPAddress mask = NetworkHelper.GetMaskIp(maskValue);
IPAddress _ip = NetworkHelper.ToNetworkIp(item.Address, maskValue);
return $"route delete {_ip}";
diff --git a/linker.web/src/components/install/Index.vue b/linker.web/src/components/install/Index.vue
index cf8e0f20..9769aa19 100644
--- a/linker.web/src/components/install/Index.vue
+++ b/linker.web/src/components/install/Index.vue
@@ -73,7 +73,6 @@ export default {
currentDom.value.handleValidate().then((json)=>{
step.value.json = Object.assign(step.value.json,json.json);
step.value.form = Object.assign(step.value.form,json.form);
- console.log(step.value);
step.value.step ++;
}).catch(()=>{
});
diff --git a/linker.web/src/views/devices/TuntapEdit.vue b/linker.web/src/views/devices/TuntapEdit.vue
index 0e5bb3da..8d2deed9 100644
--- a/linker.web/src/views/devices/TuntapEdit.vue
+++ b/linker.web/src/views/devices/TuntapEdit.vue
@@ -51,7 +51,6 @@ export default {
const globalData = injectGlobalData();
const tuntap = useTuntap();
- console.log(tuntap);
const ruleFormRef = ref(null);
const state = reactive({
show: true,
diff --git a/linker/plugins/tuntap/TuntapTransfer.cs b/linker/plugins/tuntap/TuntapTransfer.cs
index 20878829..4ca8a8f8 100644
--- a/linker/plugins/tuntap/TuntapTransfer.cs
+++ b/linker/plugins/tuntap/TuntapTransfer.cs
@@ -280,7 +280,7 @@ namespace linker.plugins.tuntap
{
List ipsList = ParseIPs(tuntapInfos.Values.ToList());
TuntapVeaLanIPAddress[] ips = ipsList.SelectMany(c => c.IPS).ToArray();
- linkerTunDeviceAdapter.DelRoute(ipsList.SelectMany(c => c.IPS).Select(c => new LinkerTunDeviceRouteItem { Address = c.OriginIPAddress, Mask = c.MaskLength }).ToArray());
+ linkerTunDeviceAdapter.DelRoute(ipsList.SelectMany(c => c.IPS).Select(c => new LinkerTunDeviceRouteItem { Address = c.OriginIPAddress, PrefixLength = c.MaskLength }).ToArray());
}
///
/// 添加路由
@@ -289,7 +289,7 @@ namespace linker.plugins.tuntap
{
List ipsList = ParseIPs(tuntapInfos.Values.ToList());
TuntapVeaLanIPAddress[] ips = ipsList.SelectMany(c => c.IPS).ToArray();
- linkerTunDeviceAdapter.AddRoute(ipsList.SelectMany(c => c.IPS).Select(c => new LinkerTunDeviceRouteItem { Address = c.OriginIPAddress, Mask = c.MaskLength }).ToArray(), runningConfig.Data.Tuntap.IP);
+ linkerTunDeviceAdapter.AddRoute(ipsList.SelectMany(c => c.IPS).Select(c => new LinkerTunDeviceRouteItem { Address = c.OriginIPAddress, PrefixLength = c.MaskLength }).ToArray(), runningConfig.Data.Tuntap.IP);
tuntapProxy.SetIPs(ipsList);
foreach (var item in tuntapInfos.Values)