Esempio n. 1
0
 public void AddRule(NetworkRule networkRule)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 2
0
 public void DisableSourceNetworkAddressTranslation(NetworkRule networkRule)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 3
0
        /// <summary>
        /// Checks (recursively) if a rule matches a given network information
        /// </summary>
        /// <param name="rule">Rule to check</param>
        /// <param name="net">Network information</param>
        /// <param name="res">Detailed result if match</param>
        /// <returns>true if rule matches</returns>
        private bool CheckRuleAgainstNetwork(NetworkRule rule, NetworkInfo net, ref RulesCheckerResult res)
        {
            if (rule is NetworkRulesSet)
            {
                bool thisRes = false;
                foreach (var rule2 in (rule as NetworkRulesSet).Rules)
                {
                    thisRes = CheckRuleAgainstNetwork(rule2, net, ref res);
                    if ((rule as NetworkRulesSet).Op == Operator.And && !thisRes) { thisRes = false; break; }
                    if ((rule as NetworkRulesSet).Op == Operator.Or && thisRes) { thisRes = true; break; }
                    if ((rule as NetworkRulesSet).Op == Operator.Not) { thisRes = !thisRes; break; }
                }

                res = new RulesCheckerResult(thisRes ? Reasons.MATCH : Reasons.NOMATCH, res != null ? res.ReasonString : "complex rule used");
                return thisRes;
            }
            else if (rule is NetworkRuleDNS)
            {
                foreach (string dns in net.DNS)
                {
                    if ((rule as NetworkRuleDNS).DNS == dns)
                    {
                        res = new RulesCheckerResult(Reasons.MATCH, "network DNS matches " + dns);
                        return true;
                    }
                }
            }
            else if (rule is NetworkRuleSubnet)
            {
                foreach (string ip in net.NetworkIP)
                {
                    if ((rule as NetworkRuleSubnet).Subnet == ip)
                    {
                        res = new RulesCheckerResult(Reasons.MATCH, "network subnet matches " + ip);
                        return true;
                    }
                }
            }
            else if (rule is NetworkRuleIfName)
            {
                string regex = (rule as NetworkRuleIfName).InterfaceName;

                if (Regex.IsMatch(net.IfName, regex))
                {
                    res = new RulesCheckerResult(Reasons.MATCH, "interface name matches " + regex);
                    return true;
                }
            }
            else if (rule is NetworkRulePingable)
            {
                string ip = (rule as NetworkRulePingable).IP;

                log.Debug("Pinging " + ip);
                System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
                var reply = ping.Send(ip, 5000);
                log.Info("Ping status: " + reply.Status);
                if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
                {
                    res = new RulesCheckerResult(Reasons.MATCH, "machine " + ip + " is pingable");
                    return true;
                }
            }
            return false;
        }
Esempio n. 4
0
 public void DisableMasquerade(NetworkRule networkRule)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 5
0
 public void DeleteRule(NetworkRule networkRule)
 {
     throw new NotImplementedException();
 }