コード例 #1
0
        public int Feed(CommandParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionAddSet:
                MatchSet      = new ValueOrNot <String>(parser.GetNextArg(), not);
                MatchSetFlags = parser.GetNextArg(2);
                MatchSetMode  = MatchMode.Add;
                return(2);

            case OptionDelSet:
                MatchSet      = new ValueOrNot <String>(parser.GetNextArg(), not);
                MatchSetFlags = parser.GetNextArg(2);
                MatchSetMode  = MatchMode.Del;
                return(2);

            case OptionMapSet:
                MatchSet      = new ValueOrNot <String>(parser.GetNextArg(), not);
                MatchSetFlags = parser.GetNextArg(2);
                MatchSetMode  = MatchMode.Map;
                return(2);

            case OptionExist:
                Exist = true;
                return(0);

            case OptionTimeout:
                Timeout = int.Parse(parser.GetNextArg());
                return(1);
            }

            return(0);
        }
コード例 #2
0
ファイル: TcpModule.cs プロジェクト: pvkovalev/IPTables.Net
        public int Feed(CommandParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionSourcePortLong:
            case OptionSourcePortShort:
                SourcePort.Set(not, PortOrRange.Parse(parser.GetNextArg(), ':'));
                return(1);

            case OptionDestinationPortLong:
            case OptionDestinationPortShort:
                DestinationPort.Set(not, PortOrRange.Parse(parser.GetNextArg(), ':'));
                return(1);

            case OptionDestinationTcpFlags:
                TcpFlags = new ValueOrNot <TcpFlagMatch>(TcpFlagMatch.Parse(parser.GetNextArg(), parser.GetNextArg(2)), not);
                return(2);

            case OptionSyn:
                TcpFlags = new ValueOrNot <TcpFlagMatch>(TcpFlagMatch.Syn, not);
                return(0);

            case OptionTcpOption:
                TcpOption.Set(not, int.Parse(parser.GetNextArg()));
                return(1);
            }

            return(0);
        }
コード例 #3
0
        public int Feed(RuleParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionNameLong:
                Name = parser.GetNextArg();
                return(1);

            case OptionSetLong:
                Mode = new ValueOrNot <RecentMode>(RecentMode.Set);
                return(0);

            case OptionRsourceLong:
                Rsource = true;
                return(0);

            case OptionRdestLong:
                Rdest = true;
                return(0);

            case OptionRcheckLong:
                Mode = new ValueOrNot <RecentMode>(RecentMode.Rcheck);
                return(0);

            case OptionUpdateLong:
                Mode = new ValueOrNot <RecentMode>(RecentMode.Update);
                return(0);

            case OptionRemoveLong:
                Mode = new ValueOrNot <RecentMode>(RecentMode.Remove);
                return(0);

            case OptionSecondsLong:
                Seconds = int.Parse(parser.GetNextArg());
                return(1);

            case OptionReapLong:
                Reap = true;
                return(0);

            case OptionHitcountLong:
                HitCount = int.Parse(parser.GetNextArg());
                return(1);

            case OptionRttlLong:
                Rttl = true;
                return(0);

            case OptionMaskLong:
                var oldAf = Mask.AddressFamily;
                Mask = IPAddress.Parse(parser.GetNextArg());
                if (Mask.AddressFamily != oldAf)
                {
                    throw new IpTablesNetException("Invalid address family for mask " + parser.GetNextArg() + " should be " + oldAf);
                }
                return(1);
            }

            return(0);
        }
コード例 #4
0
ファイル: CoreModule.cs プロジェクト: justscribe/IPTables.Net
        public int Feed(RuleParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionProtocolLong:
            case OptionProtocolShort:
                Protocol = new ValueOrNot <string>(parser.GetNextArg(), not);
                return(1);

            case OptionSourceLong:
            case OptionSourceShort:
                Source = new ValueOrNot <IpCidr>(IpCidr.Parse(parser.GetNextArg()), IpCidr.Any, not);
                return(1);

            case OptionDestinationLong:
            case OptionDestinationShort:
                Destination = new ValueOrNot <IpCidr>(IpCidr.Parse(parser.GetNextArg()), IpCidr.Any, not);
                return(1);

            case OptionJumpLong:
            case OptionJumpShort:
                Jump = parser.GetNextArg();
                return(1);

            case OptionGotoLong:
            case OptionGotoShort:
                Goto = parser.GetNextArg();
                return(1);

            case OptionInInterfaceLong:
            case OptionInInterfaceShort:
                InInterface = new ValueOrNot <string>(parser.GetNextArg(), not);
                return(1);

            case OptionOutInterfaceLong:
            case OptionOutInterfaceShort:
                OutInterface = new ValueOrNot <string>(parser.GetNextArg(), not);
                return(1);

            case OptionFragmentLong:
            case OptionFragmentShort:
                Fragmented = new ValueOrNot <bool>(true, not);
                return(0);

            case OptionSetCountersLong:
            case OptionSetCountersShort:
                SetCounters =
                    new ValueOrNot <CounterPacketsAndBytes>(
                        new CounterPacketsAndBytes(uint.Parse(parser.GetNextArg(1)),
                                                   uint.Parse(parser.GetNextArg(2))), not);
                return(2);
            }

            return(0);
        }
コード例 #5
0
ファイル: RecentModule.cs プロジェクト: a1binos/IPTables.Net
        int IIpTablesModuleInternal.Feed(RuleParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionNameLong:
                Name = parser.GetNextArg();
                return(1);

            case OptionSetLong:
                Mode = new ValueOrNot <RecentMode>(RecentMode.Set);
                return(0);

            case OptionRsourceLong:
                Rsource = true;
                return(0);

            case OptionRdestLong:
                Rdest = true;
                return(0);

            case OptionRcheckLong:
                Mode = new ValueOrNot <RecentMode>(RecentMode.Rcheck);
                return(0);

            case OptionUpdateLong:
                Mode = new ValueOrNot <RecentMode>(RecentMode.Update);
                return(0);

            case OptionRemoveLong:
                Mode = new ValueOrNot <RecentMode>(RecentMode.Remove);
                return(0);

            case OptionSecondsLong:
                Seconds = int.Parse(parser.GetNextArg());
                return(1);

            case OptionReapLong:
                Reap = true;
                return(0);

            case OptionHitcountLong:
                HitCount = int.Parse(parser.GetNextArg());
                return(1);

            case OptionRttlLong:
                Rttl = true;
                return(0);

            case OptionMaskLong:
                Mask = IPAddress.Parse(parser.GetNextArg());
                return(1);
            }

            return(0);
        }
コード例 #6
0
        public int Feed(CommandParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionLengthLong:
                Length = new ValueOrNot <PortOrRange>(PortOrRange.Parse(parser.GetNextArg(), ':'), not);
                return(1);
            }

            return(0);
        }
コード例 #7
0
        public int Feed(CommandParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionHelperLong:
                Helper = new ValueOrNot <String>(parser.GetNextArg(), not);
                return(1);
            }

            return(0);
        }
コード例 #8
0
        int IIpTablesModuleInternal.Feed(RuleParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionLengthLong:
                Length = new ValueOrNot <PortOrRange>(PortOrRange.Parse(parser.GetNextArg(), ':'), not);
                return(1);
            }

            return(0);
        }
コード例 #9
0
ファイル: HelperModule.cs プロジェクト: a1binos/IPTables.Net
        int IIpTablesModuleInternal.Feed(RuleParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionHelperLong:
                Helper = new ValueOrNot <String>(parser.GetNextArg(), not);
                return(1);
            }

            return(0);
        }
コード例 #10
0
        public int Feed(CommandParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionMatchSet:
                MatchSet      = new ValueOrNot <String>(parser.GetNextArg(), not);
                MatchSetFlags = parser.GetNextArg(2);
                return(2);

            case OptionNoMatch:
                ReturnNoMatch = !not;
                break;

            case OptionUpdateCounters:
                UpdateCounters = !not;
                break;

            case OptionUpdateSubCounters:
                UpdateSubCounters = !not;
                break;

            case OptionPacketsEq:
                PacketsMatch = not ? MatchMode.NotEqual : MatchMode.Equal;
                PacketsValue = int.Parse(parser.GetNextArg());
                return(1);

            case OptionBytesEq:
                BytesMatch = not ? MatchMode.NotEqual : MatchMode.Equal;
                BytesValue = int.Parse(parser.GetNextArg());
                return(1);

            case OptionPacketsLt:
                PacketsMatch = MatchMode.Lt;
                PacketsValue = int.Parse(parser.GetNextArg());
                return(1);

            case OptionBytesLt:
                BytesMatch = MatchMode.Lt;
                BytesValue = int.Parse(parser.GetNextArg());
                return(1);

            case OptionPacketsGt:
                PacketsMatch = MatchMode.Gt;
                PacketsValue = int.Parse(parser.GetNextArg());
                return(1);

            case OptionBytesGt:
                BytesMatch = MatchMode.Gt;
                BytesValue = int.Parse(parser.GetNextArg());
                return(1);
            }

            return(0);
        }
コード例 #11
0
        public int Feed(CommandParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionMss:
                var range = PortOrRange.Parse(parser.GetNextArg(), ':');
                MssRange = new ValueOrNot <PortOrRange>(range, not);
                return(1);
            }

            return(0);
        }
コード例 #12
0
        public int Feed(CommandParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionSrcGroup:
                SrcGroup = new ValueOrNot <UInt32>(FlexibleUInt32.Parse(parser.GetNextArg()), not);
                return(1);

            case OptionDstGroup:
                DstGroup = new ValueOrNot <UInt32>(FlexibleUInt32.Parse(parser.GetNextArg()), not);
                return(1);
            }

            return(0);
        }
コード例 #13
0
        public int Feed(CommandParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionPorts:
                Ports = new ValueOrNot <IEnumerable <PortOrRange> >(ParseListOfPortOrRanges(parser.GetNextArg()), not);
                return(1);

            case OptionDestinationPorts:
            case OptionDestinationPortsLong:
                DestinationPorts = new ValueOrNot <IEnumerable <PortOrRange> >(
                    ParseListOfPortOrRanges(parser.GetNextArg()), not);
                return(1);

            case OptionSourcePorts:
            case OptionSourcePortsLong:
                SourcePorts = new ValueOrNot <IEnumerable <PortOrRange> >(ParseListOfPortOrRanges(parser.GetNextArg()), not);
                return(1);
            }

            return(0);
        }
コード例 #14
0
        int IIpTablesModuleInternal.Feed(RuleParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionAlgorithmLong:
                var alg = parser.GetNextArg();
                if (alg == "bm")
                {
                    Algorithm = Strategy.BoyerMoore;
                }
                else if (alg == "kmp")
                {
                    Algorithm = Strategy.KnuthPrattMorris;
                }
                else
                {
                    throw new IpTablesNetException("Unknown algorithm: " + alg);
                }
                return(1);

            case OptionFromLong:
                From = int.Parse(parser.GetNextArg());
                return(1);

            case OptionToLong:
                To = int.Parse(parser.GetNextArg());
                return(1);

            case OptionStringLong:
                Pattern = new ValueOrNot <string>(parser.GetNextArg(), not);
                return(1);

            case OptionHexStringLong:
                SetHexString(parser.GetNextArg(), not);
                return(1);
            }

            return(0);
        }
コード例 #15
0
        int IIpTablesModuleInternal.Feed(RuleParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionPorts:
                Ports = new ValueOrNot <IEnumerable <PortOrRange> >(ParseListOfPortOrRanges(parser.GetNextArg()), not);
                return(1);

            case OptionDestinationPorts:
            case OptionDestinationPortsLong:
                DestinationPorts = new ValueOrNot <IEnumerable <PortOrRange> >(
                    ParseListOfPortOrRanges(parser.GetNextArg()), not);
                return(1);

            case OptionSourcePorts:
            case OptionSourcePortsLong:
                SourcePorts = new ValueOrNot <IEnumerable <PortOrRange> >(ParseListOfPortOrRanges(parser.GetNextArg()), not);
                return(1);
            }

            return(0);
        }
コード例 #16
0
        public int Feed(CommandParser parser, bool not)
        {
            switch (parser.GetCurrentArg())
            {
            case OptionModeLong:
                Mode = ParseMode(parser.GetNextArg());
                return(1);

            case OptionProbabilityLong:
                Probability = new ValueOrNot <float>(float.Parse(parser.GetNextArg()), not);
                return(1);

            case OptionPacketLong:
                Packet = uint.Parse(parser.GetNextArg());
                return(1);

            case OptionEveryLong:
                Every = new ValueOrNot <uint>(uint.Parse(parser.GetNextArg()), not);
                return(1);
            }

            return(0);
        }
コード例 #17
0
 public void SetHexString(String pattern, bool not = false)
 {
     pattern  = pattern.Replace(" ", "");
     Pattern  = new ValueOrNot <string>(pattern, not);
     Notation = NotationTypes.Hex;
 }