Пример #1
0
 public IpSetSet(IpSetType type, string name, int timeout, IpTablesSystem system, IpSetSyncMode syncMode)
 {
     _type     = type;
     _name     = name;
     _timeout  = timeout;
     _system   = system;
     _syncMode = syncMode;
 }
Пример #2
0
 public IpSetSet(IpSetType type, string name, int timeout, String family, IpTablesSystem system, IpSetSyncMode syncMode)
 {
     _type = type;
     _name = name;
     _timeout = timeout;
     _family = family;
     _system = system;
     _syncMode = syncMode;
 }
Пример #3
0
 public IpSetSet(IpSetType type, string name, int timeout, String family, IpTablesSystem system, IpSetSyncMode syncMode, List <IpSetEntry> entries = null)
 {
     _type     = type;
     _name     = name;
     _timeout  = timeout;
     _family   = family;
     _system   = system;
     _syncMode = syncMode;
     _entries  = entries == null ? new List <IpSetEntry>() : entries.ToList();
 }
Пример #4
0
 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;
 }
Пример #5
0
        /// <summary>
        /// Concert a set type in enum format to a string
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static String TypeToString(IpSetType type)
        {
            switch (type)
            {
                case IpSetType.BitmapPort:
                    return "bitmap:port";
                case IpSetType.HashIp:
                    return "hash:ip";
                case IpSetType.HashIpPort:
                    return "hash:ip,port";
            }

            return null;
        }
Пример #6
0
        /// <summary>
        /// Convert a set type in string format to enum type
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static IpSetType StringToType(String str)
        {
            IpSetType ret   = 0;
            var       parts = str.Split(new char[] { ':' });

            if (parts[0] == "hash")
            {
                ret |= IpSetType.Hash;
            }
            else if (parts[0] == "bitmap")
            {
                ret |= IpSetType.Bitmap;
            }
            else
            {
                throw new IpTablesNetException(String.Format("Unknown set type: {0}", str));
            }

            var types = parts[1].Split(',');

            foreach (var t in types)
            {
                if (t == "ip")
                {
                    if ((ret & IpSetType.Ip) == IpSetType.Ip)
                    {
                        ret |= IpSetType.Ip2;
                    }
                    else
                    {
                        ret |= IpSetType.Ip;
                    }
                }
                else if (t == "port")
                {
                    ret |= IpSetType.Port;
                }
                else if (t == "net")
                {
                    ret |= IpSetType.Net;
                }
                else
                {
                    throw new IpTablesNetException(String.Format("Unknown set type: {0}", str));
                }
            }

            return(ret);
        }
Пример #7
0
        /// <summary>
        /// Concert a set type in enum format to a string
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static String TypeToString(IpSetType type)
        {
            switch (type)
            {
            case IpSetType.BitmapPort:
                return("bitmap:port");

            case IpSetType.HashIp:
                return("hash:ip");

            case IpSetType.HashIpPort:
                return("hash:ip,port");
            }

            return(null);
        }
Пример #8
0
        /// <summary>
        /// Concert a set type in enum format to a string
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static String TypeToString(IpSetType type)
        {
            String mode;

            if ((type & IpSetType.Hash) == IpSetType.Hash)
            {
                mode = "hash:";
            }
            else if ((type & IpSetType.Bitmap) == IpSetType.Bitmap)
            {
                mode = "bitmap:";
            }
            else
            {
                return(null);
            }

            List <String> types = new List <string>();

            if ((type & IpSetType.Ip) == IpSetType.Ip)
            {
                types.Add("ip");
            }
            if ((type & IpSetType.Net) == IpSetType.Net)
            {
                types.Add("net");
            }
            if ((type & IpSetType.Port) == IpSetType.Port)
            {
                types.Add("port");
            }
            if ((type & IpSetType.Ip2) == IpSetType.Ip2)
            {
                types.Add("ip");
            }

            if (types.Count == 0)
            {
                return(null);
            }
            return(mode + string.Join(",", types));
        }