diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index cf05a8ea..b5dfa444 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -48,16 +48,24 @@ jobs: env: GITHUB_TOKEN: '${{ secrets.ACTIONS_TOKEN }}' with: - tag_name: v1.2.0.5 - release_name: v1.2.0.5.${{ steps.date.outputs.today }} + tag_name: v1.2.0.6 + release_name: v1.2.0.6.${{ steps.date.outputs.today }} draft: false prerelease: false body: | - 1. UDP端口映射连接(无ssl加密) - 2. UDP打洞,纯净版(无ssl加密) - 3. 如果当前版本小于v1.2.0.4,则windows下需要重新卸载安装服务 - 4. 先更新所有客户端,再更新服务端(先更新服务端会获取不到客户端列表) - 5. 用不上无加密UDP打洞的可以不更新 + 1. 显示虚拟网卡ping值 + 2. 更新服务器,更新服务器,更新服务器 + + #- name: upload win x86 oss + # id: upload-win-x86-oss + # uses: tvrcgo/oss-action@v0.1.1 + # with: + # region: oss-cn-guangzhou + # key-id: '${{ secrets.ALIYUN_OSS_ID }}' + # key-secret: '${{ secrets.ALIYUN_OSS_SECRET }}' + # bucket: snltty + # asset-path: ./public/publish-zip/linker-win-x86.zip + # target-path: /linker/v1.2.0.6/linker-win-x86.zip - name: upload win x86 id: upload-win-x86 diff --git a/linker.doc.web/docs/4、通信功能/3.1.1、点对网.md b/linker.doc.web/docs/4、通信功能/3.1.1、点对网.md index ed43e4ab..6c1ac71c 100644 --- a/linker.doc.web/docs/4、通信功能/3.1.1、点对网.md +++ b/linker.doc.web/docs/4、通信功能/3.1.1、点对网.md @@ -38,8 +38,21 @@ sudo pfctl -f /etc/pf.conf -e :::tip[2、情况2,你的设备无法使用NAT转发时] -1. 你的设备无法使用NAT转发(一般出现在低版本windows下,win10以下),那你只能使用windows的端口转发功能来访问你当前设备局域网下的其它设备 +1. 你的设备无法使用NAT转发(一般出现在低版本windows下,win10以下),那你只能使用端口转发功能来访问你当前设备局域网下的其它设备 2. 按如下配置。当其它设备通过`192.168.54.2:12345` 访问时,将访问到你的局域网的`192.168.1.35:3389` +3. macos下需要你自己在**被访问端**添加端口转发 +``` +//编辑 pf 配置文件 +sudo nano /etc/pf.conf + +//添加转发规则 +rdr pass on en0 inet proto tcp from any to any port 33890 -> 127.0.0.1 port 3389 +rdr pass on en0 inet proto udp from any to any port 33890 -> 127.0.0.1 port 3389 + +//启用并重新加载 pf +sudo pfctl -f /etc/pf.conf +sudo pfctl -e +``` ![Docusaurus Plushie](./img/tun-forward.png) diff --git a/linker.libs/OperatingManager.cs b/linker.libs/OperatingManager.cs new file mode 100644 index 00000000..20c4354b --- /dev/null +++ b/linker.libs/OperatingManager.cs @@ -0,0 +1,35 @@ +using System.Collections.Concurrent; +using System.Reflection.PortableExecutable; +using System.Threading; + +namespace linker.libs +{ + public sealed class OperatingManager + { + private uint operating = 0; + public bool Operating => operating == 1; + + public bool StartOperation() + { + return Interlocked.CompareExchange(ref operating, 1, 0) == 0; + } + public void StopOperation() + { + Interlocked.Exchange(ref operating, 0); + } + } + + public sealed class OperatingMultipleManager + { + private readonly ConcurrentDictionary dicOperating = new ConcurrentDictionary(); + + public bool StartOperation(string key) + { + return dicOperating.TryAdd(key, true); + } + public void StopOperation(string key) + { + dicOperating.TryRemove(key, out _); + } + } +} diff --git a/linker.libs/VersionManager.cs b/linker.libs/VersionManager.cs new file mode 100644 index 00000000..32644fed --- /dev/null +++ b/linker.libs/VersionManager.cs @@ -0,0 +1,21 @@ + +using System.Threading; + +namespace linker.libs +{ + public sealed class VersionManager + { + private ulong version = 0; + + public bool Eq(ulong outsideVersion, out ulong insideVersion) + { + insideVersion = version; + return outsideVersion == version; + } + + public void Add() + { + Interlocked.Increment(ref version); + } + } +} diff --git a/linker.tun/LinkerLinuxTunDevice.cs b/linker.tun/LinkerLinuxTunDevice.cs index 3822c93d..e2438666 100644 --- a/linker.tun/LinkerLinuxTunDevice.cs +++ b/linker.tun/LinkerLinuxTunDevice.cs @@ -1,6 +1,7 @@ using linker.libs; using linker.libs.extends; using Microsoft.Win32.SafeHandles; +using System.Linq; using System.Net; using System.Runtime.InteropServices; @@ -131,7 +132,7 @@ namespace linker.tun try { IPAddress network = NetworkHelper.ToNetworkIp(address, NetworkHelper.MaskValue(prefixLength)); - CommandHelper.Linux(string.Empty, new string[] { + CommandHelper.Linux(string.Empty, new string[] { $"sysctl -w net.ipv4.ip_forward=1", $"iptables -t nat -A POSTROUTING ! -o {Name} -s {network}/{prefixLength} -j MASQUERADE", }); @@ -165,9 +166,33 @@ namespace linker.tun public void AddForward(List forwards) { + string[] commands = forwards.Where(c => c != null && c.Enable).SelectMany(c => + { + return new string[] { + $"sysctl -w net.ipv4.ip_forward=1", + $"iptables -t nat -A PREROUTING -p tcp --dport {c.ListenPort} -j DNAT --to-destination {c.ConnectAddr}:{c.ConnectPort}", + $"iptables -t nat -A POSTROUTING -p tcp --dport {c.ConnectPort} -j MASQUERADE", + $"iptables -t nat -A PREROUTING -p udp --dport {c.ListenPort} -j DNAT --to-destination {c.ConnectAddr}:{c.ConnectPort}", + $"iptables -t nat -A POSTROUTING -p udp --dport {c.ConnectPort} -j MASQUERADE", + }; + + }).ToArray(); + CommandHelper.Windows(string.Empty, commands); } public void RemoveForward(List forwards) { + string[] commands = forwards.Where(c => c != null && c.Enable).SelectMany(c => + { + return new string[] { + $"sysctl -w net.ipv4.ip_forward=1", + $"iptables -t nat -D PREROUTING -p tcp --dport {c.ListenPort} -j DNAT --to-destination {c.ConnectAddr}:{c.ConnectPort}", + $"iptables -t nat -D POSTROUTING -p tcp --dport {c.ConnectPort} -j MASQUERADE", + $"iptables -t nat -D PREROUTING -p udp --dport {c.ListenPort} -j DNAT --to-destination {c.ConnectAddr}:{c.ConnectPort}", + $"iptables -t nat -D POSTROUTING -p udp --dport {c.ConnectPort} -j MASQUERADE" + }; + + }).ToArray(); + CommandHelper.Windows(string.Empty, commands); } @@ -287,7 +312,7 @@ namespace linker.tun { } - + } diff --git a/linker.tunnel/transport/TransportUdp.cs b/linker.tunnel/transport/TransportUdp.cs index 3550c889..88f84424 100644 --- a/linker.tunnel/transport/TransportUdp.cs +++ b/linker.tunnel/transport/TransportUdp.cs @@ -13,7 +13,7 @@ namespace linker.tunnel.transport { public string Name => "udp"; - public string Label => "UDP、非常纯"; + public string Label => "UDP、非常纯,无ssl"; public TunnelProtocolType ProtocolType => TunnelProtocolType.Udp; public TunnelWanPortProtocolType AllowWanPortProtocolType => TunnelWanPortProtocolType.Udp; diff --git a/linker.tunnel/transport/TransportUdpPortMap.cs b/linker.tunnel/transport/TransportUdpPortMap.cs index 109d8c88..b4a366be 100644 --- a/linker.tunnel/transport/TransportUdpPortMap.cs +++ b/linker.tunnel/transport/TransportUdpPortMap.cs @@ -17,7 +17,7 @@ namespace linker.tunnel.transport { public string Name => "UdpPortMap"; - public string Label => "UDP、端口映射"; + public string Label => "UDP、端口映射,无ssl"; public TunnelProtocolType ProtocolType => TunnelProtocolType.Udp; diff --git a/linker.web/src/views/devices/Tuntap.vue b/linker.web/src/views/devices/Tuntap.vue index 8cc98893..865f5571 100644 --- a/linker.web/src/views/devices/Tuntap.vue +++ b/linker.web/src/views/devices/Tuntap.vue @@ -55,6 +55,14 @@ + @@ -65,12 +73,17 @@ import { stopTuntap, runTuntap } from '@/apis/tuntap'; import { ElMessage } from 'element-plus'; import { useTuntap } from './tuntap'; import {Loading} from '@element-plus/icons-vue' +import { injectGlobalData } from '@/provide'; +import { computed } from 'vue'; export default { emits: ['edit','refresh'], components:{Loading}, setup(props, { emit }) { const tuntap = useTuntap(); + const globalData = injectGlobalData(); + + const showDelay = computed(()=>globalData.value.config.Running.Tuntap.ShowDelay); const handleTuntap = (tuntap) => { const fn = tuntap.running ? stopTuntap (tuntap.MachineId) : runTuntap(tuntap.MachineId); tuntap.loading = true; @@ -88,7 +101,7 @@ export default { } return { - tuntap, handleTuntap, handleTuntapIP,handleTuntapRefresh + tuntap,showDelay, handleTuntap, handleTuntapIP,handleTuntapRefresh } } } @@ -119,5 +132,7 @@ export default { -webkit-text-fill-color:hsla(0,0%,100%,0); } } +.delay{position: absolute;right:0;bottom:0;line-height:normal} + \ No newline at end of file diff --git a/linker.web/src/views/devices/TuntapEdit.vue b/linker.web/src/views/devices/TuntapEdit.vue index b5ef64d5..86d64837 100644 --- a/linker.web/src/views/devices/TuntapEdit.vue +++ b/linker.web/src/views/devices/TuntapEdit.vue @@ -3,26 +3,41 @@
- 赐予此设备IP,其它可以通过这个IP访问 + 赐予此设备IP,其它设备可通过此IP访问 - / + + / + + + + + + +
- - + + - - 此设备可以用NAT转发,那填写局域网IP,其它交给NAT(linux、macos、win10+) + + 此设备能使用NAT转发,只需局域网IP,剩下的交给NAT(linux、macos、win10+) - + - - 此设备不能用NAT转发,那可以使用系统端口转发实现类似的效果(仅windows) + + 此设备无法使用NAT转发,或只想使用端口转发 - +