コード例 #1
0
ファイル: TcpModule.cs プロジェクト: a1binos/IPTables.Net
        int IIpTablesModuleInternal.Feed(RuleParser 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 = TcpFlagMatch.Parse(parser.GetNextArg(), parser.GetNextArg(2));
                return(2);

            case OptionSyn:
                TcpFlags = not ? TcpFlagMatch.NotSyn : TcpFlagMatch.Syn;
                return(0);

            case OptionTcpOption:
                TcpOption.Set(not, 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
        private HashSet <PortOrRange> ParseListOfPortOrRanges(String csv)
        {
            var ret = new HashSet <PortOrRange>();

            foreach (string a in csv.Split(new[] { ',' }))
            {
                ret.Add(PortOrRange.Parse(a, ':'));
            }
            return(ret);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
0
ファイル: IpSetSet.cs プロジェクト: pvkovalev/IPTables.Net
 public IpSetSet(IpSetType type, string name, int timeout, String family, IpTablesSystem system, IpSetSyncMode syncMode, PortOrRange bitmapRange, List <string> createOptions = null, List <IpSetEntry> entries = null)
 {
     _type          = type;
     _name          = name;
     _timeout       = timeout;
     _family        = family;
     _system        = system;
     _syncMode      = syncMode;
     _createOptions = createOptions == null ? new List <string>() : createOptions.ToList();
     _entries       = entries == null ? new List <IpSetEntry>() : entries.ToList();
     _bitmapRange   = bitmapRange;
 }
コード例 #8
0
ファイル: UdpModule.cs プロジェクト: a1binos/IPTables.Net
        int IIpTablesModuleInternal.Feed(RuleParser 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);
            }

            return(0);
        }
コード例 #9
0
        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);
            }

            return(0);
        }
コード例 #10
0
        public static List <PortOrRange> CompressRanges(List <PortOrRange> ranges)
        {
            List <PortOrRange> ret = new List <PortOrRange>();
            PortOrRange        start = new PortOrRange(0);
            int previous = -1, previousLower = -1;

            foreach (PortOrRange current in ranges.OrderBy((a) => a.LowerPort))
            {
                if (current.LowerPort == (previous + 1))
                {
                    if (start.LowerPort == 0)
                    {
                        start = new PortOrRange((uint)previousLower, current.UpperPort);
                    }
                }
                else
                {
                    if (start.UpperPort != 0)
                    {
                        ret.Add(new PortOrRange(start.LowerPort, (uint)previous));
                        start = new PortOrRange(0);
                    }
                    else if (previous != -1)
                    {
                        ret.Add(new PortOrRange((uint)previousLower, (uint)previous));
                    }
                }
                previous      = (int)current.UpperPort;
                previousLower = (int)current.LowerPort;
            }
            if (start.UpperPort != 0)
            {
                ret.Add(new PortOrRange(start.LowerPort, (uint)previous));
                // ReSharper disable RedundantAssignment
                start = new PortOrRange(0);
                // ReSharper restore RedundantAssignment
            }
            else if (previous != -1)
            {
                ret.Add(new PortOrRange((uint)previousLower, (uint)previous));
            }
            return(ret);
        }
コード例 #11
0
        /// <summary>
        /// Consume arguments
        /// </summary>
        /// <param name="position">Rhe position to parse</param>
        /// <returns>number of arguments consumed</returns>
        public int FeedToSkip(int position, bool first)
        {
            Position = position;
            String option = GetCurrentArg();

            if (first)
            {
                _set.InternalName = option;
                _set.Type         = IpSetTypeHelper.StringToType(GetNextArg());
                return(1);
            }

            switch (option)
            {
            case "timeout":
                _set.Timeout = int.Parse(GetNextArg());
                break;

            case "family":
                _set.Family = GetNextArg();
                break;

            case "hashsize":
                _set.HashSize = int.Parse(GetNextArg());
                break;

            case "maxelem":
                _set.MaxElem = UInt32.Parse(GetNextArg());
                break;

            case "range":
                _set.BitmapRange = PortOrRange.Parse(GetNextArg(), '-');
                break;

            default:
                _set.CreateOptions.Add(GetCurrentArg());
                return(0);
            }

            return(1);
        }