/// <summary> /// Returns the configuration that matches the given network /// </summary> /// <param name="configurations"></param> public NetworkConfiguration FindMatchingConfiguration(IList <NetworkInfo> networks, out RulesChecker.RulesCheckerResult result, out NetworkInfo matchingNetwork) { int countMatches = 0; NetworkConfiguration matchingConfiguration = null; result = null; matchingNetwork = null; // Check each configuration foreach (NetworkConfiguration configuration in m_configurations) { using (log4net.ThreadContext.Stacks["NDC"].Push(String.Format("config {0}", configuration.Name))) { log.InfoFormat("Checking config {0}", configuration.Name); // Check each network foreach (NetworkInfo net in networks) { log.InfoFormat("Checking network: {0} (IP: {1}, DNS: {2})", net.IfName, string.Join(",", net.NetworkIP), string.Join(",", net.DNS)); RulesChecker rc = new RulesChecker(configuration.NetworkRulesSet); RulesChecker.RulesCheckerResult tempResult = rc.CheckRulesAgainstNetwork(net); if (tempResult.Match) { log.InfoFormat("Match #{1}: config {0}", configuration.Name, countMatches + 1); if (countMatches == 0) { result = tempResult; matchingConfiguration = configuration; matchingNetwork = net; } countMatches++; } } } } return(matchingConfiguration); }
/// <summary> /// Returns the configuration that matches the given network /// </summary> /// <param name="configurations"></param> public NetworkConfiguration FindMatchingConfiguration(IList<NetworkInfo> networks, out RulesChecker.RulesCheckerResult result, out NetworkInfo matchingNetwork) { int countMatches = 0; NetworkConfiguration matchingConfiguration = null; result = null; matchingNetwork = null; // Check each configuration foreach (NetworkConfiguration configuration in m_configurations) { using (log4net.ThreadContext.Stacks["NDC"].Push(String.Format("config {0}", configuration.Name))) { log.InfoFormat("Checking config {0}", configuration.Name); // Check each network foreach (NetworkInfo net in networks) { log.InfoFormat("Checking network: {0} (IP: {1}, DNS: {2})", net.IfName, string.Join(",", net.NetworkIP), string.Join(",", net.DNS)); RulesChecker rc = new RulesChecker(configuration.NetworkRulesSet); RulesChecker.RulesCheckerResult tempResult = rc.CheckRulesAgainstNetwork(net); if (tempResult.Match) { log.InfoFormat("Match #{1}: config {0}", configuration.Name, countMatches + 1); if (countMatches == 0) { result = tempResult; matchingConfiguration = configuration; matchingNetwork = net; } countMatches++; } } } } return matchingConfiguration; }