From 7adf54150f03121de5bfc2868794e47c9a31ae8d Mon Sep 17 00:00:00 2001 From: Mathew Date: Mon, 1 Jan 2024 21:48:57 +1100 Subject: [PATCH] ... --- .github/workflows/main.yml | 5 ++- IPTables.Net.Tests/IptcInterfaceTest.cs | 43 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1dce2eb..34f22dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,7 +56,10 @@ jobs: run: dotnet restore - name: Modprobe IP6 tables - run: sudo modprobe ip6_tables + run: | + sudo modprobe ip6_tables + sudo modprobe ip6table_filter + sudo modprobe ip6table_mangle - name: NUnit Tests run: SKIP_SYSTEM_TESTS=1 dotnet test IPTables.Net.Tests diff --git a/IPTables.Net.Tests/IptcInterfaceTest.cs b/IPTables.Net.Tests/IptcInterfaceTest.cs index 27e7914..6a88585 100644 --- a/IPTables.Net.Tests/IptcInterfaceTest.cs +++ b/IPTables.Net.Tests/IptcInterfaceTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Net; using System.Text; @@ -29,7 +30,7 @@ public IptcInterfaceTest(int ipVersion) _ipVersion = ipVersion; } - private String GetBinary() + private String GetBinaryName() { if (_ipVersion == 4) { @@ -38,6 +39,14 @@ private String GetBinary() return "ip6tables"; } + private String GetBinary() + { + var name = GetBinaryName(); + if(Path.Exists("/sbin/"+name)) return "/sbin/"+name; + if(Path.Exists("/usr/sbin/"+name)) return "/usr/sbin/"+name; + return name; + } + [OneTimeSetUp] public void TestStartup() { @@ -47,14 +56,17 @@ public void TestStartup() { Assert.Ignore(); } - Process.Start("/sbin/" + GetBinary(), "-F test").WaitForExit(); - Process.Start("/sbin/" + GetBinary(), "-N test2").WaitForExit(); - Process.Start("/sbin/" + GetBinary(), "-N test").WaitForExit(); - Process.Start("/sbin/" + GetBinary(), "-A test -j ACCEPT").WaitForExit(); - Process.Start("/sbin/" + GetBinary(), "-N test3").WaitForExit(); - Process.Start("/sbin/" + GetBinary(), "-A test3 -p tcp -m tcp --dport 80 -j ACCEPT").WaitForExit(); + var binary = GetBinary(); + Process.Start(binary, "-F test").WaitForExit(); + + Process.Start(binary, "-N test2").WaitForExit(); + Process.Start(binary, "-N test").WaitForExit(); + Process.Start(binary, "-A test -j ACCEPT").WaitForExit(); + + Process.Start(binary, "-N test3").WaitForExit(); + Process.Start(binary, "-A test3 -p tcp -m tcp --dport 80 -j ACCEPT").WaitForExit(); } } @@ -67,13 +79,14 @@ public void TestDestroy() { Assert.Ignore(); } - Process.Start("/sbin/" + GetBinary(), "-D test -j ACCEPT").WaitForExit(); - Process.Start("/sbin/" + GetBinary(), "-F test").WaitForExit(); - Process.Start("/sbin/"+GetBinary(), "-X test").WaitForExit(); - Process.Start("/sbin/"+GetBinary(), "-F test2").WaitForExit(); - Process.Start("/sbin/"+GetBinary(), "-X test2").WaitForExit(); - Process.Start("/sbin/"+GetBinary(), "-F test3").WaitForExit(); - Process.Start("/sbin/"+GetBinary(), "-X test3").WaitForExit(); + var binary = GetBinary(); + Process.Start(binary, "-D test -j ACCEPT").WaitForExit(); + Process.Start(binary, "-F test").WaitForExit(); + Process.Start(binary, "-X test").WaitForExit(); + Process.Start(binary, "-F test2").WaitForExit(); + Process.Start(binary, "-X test2").WaitForExit(); + Process.Start(binary, "-F test3").WaitForExit(); + Process.Start(binary, " - X test3").WaitForExit(); } } @@ -120,7 +133,7 @@ public void TestRuleInput() using (IptcInterface iptc = new IptcInterface("filter", _ipVersion)) { - var status = iptc.ExecuteCommand(_ipVersion == 4 ? "iptables -A test2 -d 1.1.1.1 -p tcp -m tcp --dport 80 -j ACCEPT" : "iptables -A test2 -d ::1 -p tcp -m tcp --dport 80 -j ACCEPT"); + var status = iptc.ExecuteCommand(_ipVersion == 4 ? "iptables -A test2 -d 1.1.1.1 -p tcp -m tcp --dport 80 -j ACCEPT" : "ip6tables -A test2 -d ::1 -p tcp -m tcp --dport 80 -j ACCEPT"); Assert.AreEqual(1, status, "Expected OK return value"); var rules = iptc.GetRules("test2");