public void TestCoreFragmentingEquality()
        {
            String           rule   = "-A INPUT ! -f -j test";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule1 = IpTablesRule.Parse(rule, null, chains, 4);
            IpTablesRule irule2 = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.IsTrue(irule2.Compare(irule1));
        }
        public void TestCoreDropingSourceEquality()
        {
            String           rule   = "-A INPUT -s 1.2.3.4 -j DROP";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule1 = IpTablesRule.Parse(rule, null, chains, 4);
            IpTablesRule irule2 = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.IsTrue(irule2.Compare(irule1));
        }
        public void TestDropFragmentedTcpDnsEquality()
        {
            String           rule   = "-A INPUT -p tcp ! -f -j DROP -m tcp --sport 53";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule1 = IpTablesRule.Parse(rule, null, chains, 4);
            IpTablesRule irule2 = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.IsTrue(irule2.Compare(irule1));
        }
        public void TestCoreSportEquality()
        {
            String           rule   = "-A INPUT -p tcp -j DROP -m tcp --sport 1";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule1 = IpTablesRule.Parse(rule, null, chains, 4);
            IpTablesRule irule2 = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.IsTrue(irule2.Compare(irule1));
        }
        public void TestComparisonMultiport()
        {
            String rule = "-A INPUT -p tcp -j RETURN -m multiport --dports 79,22 -m comment --comment TCP";

            IpTablesChainSet chains = new IpTablesChainSet(4);
            IpTablesRule     r1     = IpTablesRule.Parse(rule, null, chains, 4);
            IpTablesRule     r2     = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.IsTrue(r1.Compare(r2));
        }
        public void DnatTest1()
        {
            String           rule   = "-A A+B -p tcp -j DNAT --to-destination 1.2.3.4";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.AreEqual(rule, irule.GetActionCommand());
            Assert.IsTrue(irule.Compare(IpTablesRule.Parse(rule, null, chains, 4)));
        }
        public void TestDropConnectionLimitEquality()
        {
            String           rule   = "-A INPUT -p tcp -j DROP -m connlimit --connlimit-above 10";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule1 = IpTablesRule.Parse(rule, null, chains, 4);
            IpTablesRule irule2 = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.IsTrue(irule2.Compare(irule1));
        }
        public void TestRandomRounding()
        {
            String           rule   = "-A CHAIN -t raw -m statistic --mode random --probability 0.03999999911";
            String           rule2  = "-A CHAIN -t raw -m statistic --mode random --probability 0.03999999957";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule  = IpTablesRule.Parse(rule, null, chains, 4);
            IpTablesRule irule2 = IpTablesRule.Parse(rule2, null, chains, 4);

            Assert.IsTrue(irule.Compare(irule2));
        }
        public void TestDnatRangeSourceAndEquality()
        {
            String           rule   = "-A POSTROUTING -t nat -d 1.1.1.1/24 -j DNAT --to-destination 2.2.2.1-2.2.2.250";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule1 = IpTablesRule.Parse(rule, null, chains, 4);
            IpTablesRule irule2 = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.IsTrue(irule2.Compare(irule1));
            Assert.AreEqual(rule, irule1.GetActionCommand());
            Assert.AreEqual(rule, irule2.GetActionCommand());
        }
        public void TestParse()
        {
            String           rule1  = "-A PREROUTING -t raw -p tcp -j CT --ctevents new,destroy";
            String           rule2  = "-A PREROUTING -t raw -p tcp -j CT --ctevents \"destroy, new\"";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule1 = IpTablesRule.Parse(rule1, null, chains, 4);
            IpTablesRule irule2 = IpTablesRule.Parse(rule2, null, chains, 4);

            irule2.Equals(irule1);
            Assert.IsTrue(irule2.Compare(irule1));
        }
        public void TestRandomRounding3()
        {
            String           rule   = "-A CHAIN -t raw -m statistic --mode random --probability 0.09000000000";
            String           rule2  = "-A CHAIN -t raw -m statistic --mode random --probability 0.08999999985";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule  = IpTablesRule.Parse(rule, null, chains, 4);
            IpTablesRule irule2 = IpTablesRule.Parse(rule2, null, chains, 4);


            Assert.AreEqual(irule.GetActionCommand(), irule2.GetActionCommand());
            Assert.IsTrue(irule.Compare(irule2));
        }
        public void TestDifficultCharacters()
        {
            String           rule   = "-A kY9xlwGhPJW6N1QCHoRg -t mangle -p tcp -d 107.1.107.1 -g x_ComPlex -m comment --comment 'ABC||+sPeC14l=|1' -m tcp --dport 81";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.AreEqual(rule, irule.GetActionCommand());

            IpTablesRule irule2 = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.IsTrue(irule2.Compare(irule));
        }
        public void TestLimitComparison()
        {
            String           rule   = "-A INPUT -m limit --limit 100/second --limit-burst 7";
            IpTablesChainSet chains = new IpTablesChainSet(4);

            IpTablesRule irule = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.AreEqual(rule, irule.GetActionCommand());

            IpTablesRule irule2 = IpTablesRule.Parse(rule, null, chains, 4);

            Assert.IsTrue(irule2.Compare(irule));
        }