Exemple #1
0
        public void TestListChainsMangle()
        {
            if (IsLinux)
            {
                Assert.AreEqual(0, IptcInterface.RefCount);
                using (IptcInterface iptc = new IptcInterface("mangle", _ipVersion))
                {
                    var chains = iptc.GetChains();
                    Assert.AreNotEqual(0, chains.Count, "Expected atleast one chain");

                    List <String> expectedChains = new List <string>
                    {
                        "PREROUTING",
                        "INPUT",
                        "FORWARD",
                        "OUTPUT",
                        "POSTROUTING"
                    };
                    CollectionAssert.AreEqual(expectedChains, iptc.GetChains(), "first table chain test");

                    //Test repeatable
                    CollectionAssert.AreEqual(expectedChains, iptc.GetChains(), "second table chain test");
                }
                Assert.AreEqual(0, IptcInterface.RefCount);
            }
        }
Exemple #2
0
        public void TestRuleIp()
        {
            if (IsLinux)
            {
                Assert.AreEqual(0, IptcInterface.RefCount);

                String ip;
                int    cidr;
                if (_ipVersion == 4)
                {
                    ip   = IPAddress.Loopback.ToString();
                    cidr = 32;
                }
                else
                {
                    ip   = "::1";
                    cidr = 128;
                }
                var rule = "-A test3 -s " + ip + "/" + cidr + " -p tcp -m tcp --dport 80 -j ACCEPT";

                using (IptcInterface iptc = new IptcInterface("filter", _ipVersion))
                {
                    iptc.ExecuteCommand("ip6tables " + rule);
                    var rules = iptc.GetRules("test3");
                    Assert.AreEqual(2, rules.Count);
                    Assert.AreEqual(rule, iptc.GetRuleString("test3", rules[1]));
                }
                Assert.AreEqual(0, IptcInterface.RefCount);
            }
        }
Exemple #3
0
 public void TestRuleOutputModule()
 {
     if (IsLinux)
     {
         IptcInterface iptc  = new IptcInterface("filter");
         var           rules = iptc.GetRules("test3");
         Assert.AreEqual(1, rules.Count);
         Assert.AreEqual("-A test3 -p tcp -m tcp --dport 80 -j ACCEPT", iptc.GetRuleString("test3", rules[0]));
     }
 }
Exemple #4
0
 public void TestRuleOutputSimple()
 {
     if (IsLinux)
     {
         IptcInterface iptc  = new IptcInterface("filter");
         var           rules = iptc.GetRules("test");
         Assert.AreEqual(1, rules.Count);
         Assert.AreEqual("-A test -j ACCEPT", iptc.GetRuleString("test", rules[0]));
     }
 }
 public void TestRuleOutputModule()
 {
     if (IsLinux)
     {
         IptcInterface iptc = new IptcInterface("filter");
         var rules = iptc.GetRules("test3");
         Assert.AreEqual(1, rules.Count);
         Assert.AreEqual("-A test3 -p tcp -m tcp --dport 80 -j ACCEPT", iptc.GetRuleString("test3", rules[0]));
     }
 }
 public void TestRuleOutputSimple()
 {
     if (IsLinux)
     {
         IptcInterface iptc = new IptcInterface("filter");
         var rules = iptc.GetRules("test");
         Assert.AreEqual(1,rules.Count);
         Assert.AreEqual("-A test -j ACCEPT", iptc.GetRuleString("test",rules[0]));
     }   
 }
Exemple #7
0
        public void TestListChainsSimple()
        {
            if (IsLinux)
            {
                IptcInterface iptc = new IptcInterface("filter");

                var chains = iptc.GetChains();
                Assert.AreNotEqual(0, chains.Count, "Expected atleast one chain");
            }
        }
        private IptcInterface GetInterface(String table)
        {
            if (_interfaces.ContainsKey(table))
            {
                return _interfaces[table];
            }

            var i = new IptcInterface(table, _ipVersion, Log);
            _interfaces.Add(table, i);
            return i;
        }
Exemple #9
0
        private IptcInterface GetInterface(String table)
        {
            if (_interfaces.ContainsKey(table))
            {
                return(_interfaces[table]);
            }

            var i = new IptcInterface(table);

            _interfaces.Add(table, i);
            return(i);
        }
Exemple #10
0
 public string CompileBpf(string dltName, string code, out String error)
 {
     if (IptcInterface.DllExists())
     {
         String ret = IptcInterface.BpfCompile(dltName, code, 2048 + code.Length * 10);
         if (!String.IsNullOrEmpty(ret))
         {
             error = null;
             return(ret);
         }
     }
     return(ExecuteBash(_nfbpf + " " + dltName + " " + ShellHelper.EscapeArguments(code), out error));
 }
Exemple #11
0
 public void TestListChainsSimple()
 {
     if (IsLinux)
     {
         Assert.AreEqual(0, IptcInterface.RefCount);
         using (IptcInterface iptc = new IptcInterface("filter", _ipVersion))
         {
             var chains = iptc.GetChains();
             Assert.AreNotEqual(0, chains.Count, "Expected atleast one chain");
         }
         Assert.AreEqual(0, IptcInterface.RefCount);
     }
 }
Exemple #12
0
        public void TestRuleInput()
        {
            if (IsLinux)
            {
                IptcInterface iptc = new IptcInterface("filter");

                var status = iptc.ExecuteCommand("iptables -A test2 -d 1.1.1.1 -p tcp -m tcp --dport 80 -j ACCEPT");
                Assert.AreEqual(1, status, "Expected OK return value");

                var rules = iptc.GetRules("test2");
                Assert.AreEqual(1, rules.Count);
                Assert.AreEqual("-A test2 -d 1.1.1.1/32 -p tcp -m tcp --dport 80 -j ACCEPT", iptc.GetRuleString("test2", rules[0]));
            }
        }
        public void TestRuleInput()
        {
            if (IsLinux)
            {
                IptcInterface iptc = new IptcInterface("filter");

                var status = iptc.ExecuteCommand("iptables -A test2 -d 1.1.1.1 -p tcp -m tcp --dport 80 -j ACCEPT");
                Assert.AreEqual(1, status, "Expected OK return value");

                var rules = iptc.GetRules("test2");
                Assert.AreEqual(1, rules.Count);
                Assert.AreEqual("-A test2 -d 1.1.1.1/32 -p tcp -m tcp --dport 80 -j ACCEPT", iptc.GetRuleString("test2", rules[0]));
            }
        }
Exemple #14
0
 public void TestRuleOutputSimple()
 {
     if (IsLinux)
     {
         Assert.AreEqual(0, IptcInterface.RefCount);
         using (IptcInterface iptc = new IptcInterface("filter", _ipVersion))
         {
             var rules = iptc.GetRules("test");
             Assert.AreEqual(1, rules.Count);
             Assert.AreEqual("-A test -j ACCEPT", iptc.GetRuleString("test", rules[0]));
         }
         Assert.AreEqual(0, IptcInterface.RefCount);
     }
 }
 public void TestRuleOutputSimple()
 {
     if (IsLinux)
     {
         Assert.AreEqual(0, IptcInterface.RefCount);
         using (IptcInterface iptc = new IptcInterface("filter", _ipVersion))
         {
             var rules = iptc.GetRules("test");
             Assert.AreEqual(1, rules.Count);
             Assert.AreEqual("-A test -j ACCEPT", iptc.GetRuleString("test", rules[0]));
         }
         Assert.AreEqual(0, IptcInterface.RefCount);
     }   
 }
Exemple #16
0
        public void TestRuleInput()
        {
            if (IsLinux)
            {
                Assert.AreEqual(0, IptcInterface.RefCount);
                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");
                    Assert.AreEqual(1, status, "Expected OK return value");

                    var rules = iptc.GetRules("test2");
                    Assert.AreEqual(1, rules.Count);
                    Assert.AreEqual(_ipVersion == 4 ? "-A test2 -d 1.1.1.1/32 -p tcp -m tcp --dport 80 -j ACCEPT" : "-A test2 -d ::1/128 -p tcp -m tcp --dport 80 -j ACCEPT",
                                    iptc.GetRuleString("test2", rules[0]));
                }
                Assert.AreEqual(0, IptcInterface.RefCount);
            }
        }
        public void TestListChainsMangle()
        {
            if (IsLinux)
            {
                Assert.AreEqual(0, IptcInterface.RefCount);
                using (IptcInterface iptc = new IptcInterface("mangle", _ipVersion))
                {

                    var chains = iptc.GetChains();
                    Assert.AreNotEqual(0, chains.Count, "Expected atleast one chain");

                    List<String> expectedChains = new List<string>
                    {
                        "PREROUTING",
                        "INPUT",
                        "FORWARD",
                        "OUTPUT",
                        "POSTROUTING"
                    };
                    CollectionAssert.AreEqual(expectedChains, iptc.GetChains(), "first table chain test");

                    //Test repeatable
                    CollectionAssert.AreEqual(expectedChains, iptc.GetChains(), "second table chain test");
                }
                Assert.AreEqual(0, IptcInterface.RefCount);
            }
        }
        public void TestListChainsSimple()
        {
            if (IsLinux)
            {
                Assert.AreEqual(0, IptcInterface.RefCount);
                using (IptcInterface iptc = new IptcInterface("filter", _ipVersion))
                {

                    var chains = iptc.GetChains();
                    Assert.AreNotEqual(0, chains.Count, "Expected atleast one chain");
                }
                Assert.AreEqual(0, IptcInterface.RefCount);
            }
        }
        public void TestRuleIp()
        {
            if (IsLinux)
            {
                Assert.AreEqual(0, IptcInterface.RefCount);

                String ip;
                int cidr;
                if (_ipVersion == 4)
                {
                    ip = IPAddress.Loopback.ToString();
                    cidr = 32;
                }
                else
                {
                    ip = "::1";
                    cidr = 128;
                }
                var rule = "-A test3 -s " + ip + "/" + cidr + " -p tcp -m tcp --dport 80 -j ACCEPT";

                using (IptcInterface iptc = new IptcInterface("filter", _ipVersion))
                {
                    iptc.ExecuteCommand("ip6tables " + rule);
                    var rules = iptc.GetRules("test3");
                    Assert.AreEqual(2, rules.Count);
                    Assert.AreEqual(rule, iptc.GetRuleString("test3", rules[1]));
                }
                Assert.AreEqual(0, IptcInterface.RefCount);
            }
        }
        public void TestRuleInput()
        {
            if (IsLinux)
            {
                Assert.AreEqual(0, IptcInterface.RefCount);
                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");
                    Assert.AreEqual(1, status, "Expected OK return value");

                    var rules = iptc.GetRules("test2");
                    Assert.AreEqual(1, rules.Count);
                    Assert.AreEqual(_ipVersion == 4 ? "-A test2 -d 1.1.1.1/32 -p tcp -m tcp --dport 80 -j ACCEPT" : "-A test2 -d ::1/128 -p tcp -m tcp --dport 80 -j ACCEPT",
                        iptc.GetRuleString("test2", rules[0]));
                }
                Assert.AreEqual(0, IptcInterface.RefCount);
            }
        }
        public void TestListChainsSimple()
        {
            if (IsLinux)
            {
                IptcInterface iptc = new IptcInterface("filter");

                var chains = iptc.GetChains();
                Assert.AreNotEqual(0, chains.Count, "Expected atleast one chain");
            }
        }