private void BuildMaskedIPtoRuleMap(uint ruleId, IRule rule) { IPRule ipRule = rule as IPRule; if (ipRule != null) { if (!myMaskedIPToRuleMap.ContainsKey(ipRule.Mask)) { myMaskedIPToRuleMap.Add(ipRule.Mask, new Dictionary <uint, HashSet <uint> >()); } Dictionary <uint, HashSet <uint> > ipRuleMap = null; if (myMaskedIPToRuleMap.TryGetValue(ipRule.Mask, out ipRuleMap)) { if (ipRuleMap.ContainsKey(ipRule.MaskedIPAddress)) { HashSet <uint> ruleSet = null; ipRuleMap.TryGetValue(ipRule.MaskedIPAddress, out ruleSet); ruleSet.Add(ruleId); } else { HashSet <uint> ruleSet = new HashSet <uint>(); ruleSet.Add(ruleId); ipRuleMap.Add(ipRule.MaskedIPAddress, ruleSet); } } } }
public static bool CreateIPRule(string line, out IPRule rule) { rule = null; //System.Console.WriteLine(line); string[] fields = line.Split('|'); if (fields.Length != RULE_FIELDS_COUNT) { return(false); } string[] ipAddressWithMask = fields[1].Split('/'); if (ipAddressWithMask.Length != 1 && ipAddressWithMask.Length != 2) { return(false); } UInt16[] ipAddress = IPUtils.ParseIPAddress(ipAddressWithMask[0]); if (ipAddress == null) { return(false); } UInt16 mask = NOMASK; if (ipAddressWithMask.Length == 2 && !UInt16.TryParse(ipAddressWithMask[1], out mask)) { return(false); } bool isAllowed = false; if (!BaseRule.TryParseIsAllowed(fields[2], out isAllowed)) { return(false); } string username = fields[0]; rule = new IPRule(username, ipAddress, mask, isAllowed); return(true); }