This commit is contained in:
snltty
2024-10-17 17:30:30 +08:00
parent c5a12185e7
commit 078d61d5b0
36 changed files with 769 additions and 150 deletions

View File

@@ -138,7 +138,7 @@ namespace linker.tun
error = string.Empty;
try
{
IPAddress network = NetworkHelper.ToNetworkIp(address, NetworkHelper.GetPrefixIP(prefixLength));
IPAddress network = NetworkHelper.NetworkIP2IP(address, NetworkHelper.PrefixLength2Value(prefixLength));
CommandHelper.Linux(string.Empty, new string[] {
$"sysctl -w net.ipv4.ip_forward=1",
@@ -170,7 +170,7 @@ namespace linker.tun
$"iptables -D FORWARD -o {Name} -m state --state ESTABLISHED,RELATED -j ACCEPT"
});
IPAddress network = NetworkHelper.ToNetworkIp(address, NetworkHelper.GetPrefixIP(prefixLength));
IPAddress network = NetworkHelper.NetworkIP2IP(address, NetworkHelper.PrefixLength2Value(prefixLength));
string iptableLineNumbers = CommandHelper.Linux(string.Empty, new string[] { $"iptables -t nat -L --line-numbers | grep {network}/{prefixLength} | cut -d' ' -f1" });
if (string.IsNullOrWhiteSpace(iptableLineNumbers) == false)
{
@@ -223,8 +223,8 @@ namespace linker.tun
{
string[] commands = ips.Select(item =>
{
uint prefixValue = NetworkHelper.GetPrefixIP(item.PrefixLength);
IPAddress network = NetworkHelper.ToNetworkIp(item.Address, prefixValue);
uint prefixValue = NetworkHelper.PrefixLength2Value(item.PrefixLength);
IPAddress network = NetworkHelper.NetworkIP2IP(item.Address, prefixValue);
return $"ip route add {network}/{item.PrefixLength} via {ip} dev {Name} metric 1 ";
}).ToArray();
@@ -237,8 +237,8 @@ namespace linker.tun
{
string[] commands = ip.Select(item =>
{
uint prefixValue = NetworkHelper.GetPrefixIP(item.PrefixLength);
IPAddress network = NetworkHelper.ToNetworkIp(item.Address, prefixValue);
uint prefixValue = NetworkHelper.PrefixLength2Value(item.PrefixLength);
IPAddress network = NetworkHelper.NetworkIP2IP(item.Address, prefixValue);
return $"ip route del {network}/{item.PrefixLength}";
}).ToArray();
CommandHelper.Linux(string.Empty, commands);