Esempio n. 1
0
        public virtual bool OnRouteDefaultRemoveDo()
        {
            List <RouteEntry> routeEntries = RouteList();

            foreach (RouteEntry routeEntry in routeEntries)
            {
                if (routeEntry.Mask.ToString() == "0.0.0.0")
                {
                    m_routeDefaultRemove = routeEntry;

                    routeEntry.Remove();

                    Recovery.Save();
                }
            }

            return(true);
        }
Esempio n. 2
0
		public override List<RouteEntry> RouteList()
		{			
			List<RouteEntry> entryList = new List<RouteEntry>();

			// 'route print' show IP in Interface fields, but 'route add' need the interface ID. We use a map.
			Dictionary<string, string> InterfacesIp2Id = new Dictionary<string, string>();

			ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection objMOC = objMC.GetInstances();

			foreach (ManagementObject objMO in objMOC)
			{				
				if (!((bool)objMO["IPEnabled"]))
					continue;

				string[] ips = Conversions.ToString(objMO["IPAddress"]).Trim().Split(',');
				string id = Conversions.ToString(objMO["InterfaceIndex"]).Trim();

				foreach (string ip in ips)
				{
					InterfacesIp2Id[ip.Trim()] = id;
				}
			}

			// Loopback interface it's not in the enumeration below.
			InterfacesIp2Id["127.0.0.1"] = "1";

			string cmd = "route PRINT";
			string result = ShellCmd(cmd);

			string[] lines = result.Split('\n');
			foreach (string line in lines)
			{
				string[] fields = Utils.StringCleanSpace(line).Split(' ');

				if(fields.Length == 5)
				{
					// Route line.
					RouteEntry e = new RouteEntry();
					e.Address = fields[0];
					e.Mask = fields[1];
					e.Gateway = fields[2];
					e.Interface = fields[3];
					e.Metrics = fields[4];
			 
					if(e.Address.Valid == false)
						continue;
					if(e.Mask.Valid == false)
						continue;

					if (e.Gateway.Value != "On-link")
					{
						if (e.Gateway.Valid == false)
							continue;
					}
					
					if (InterfacesIp2Id.ContainsKey(e.Interface))
					{
						e.Interface = InterfacesIp2Id[e.Interface];
						entryList.Add(e);
					}
					else
					{
						Engine.Instance.LogDebug("Unexpected.");
					}
				}
			}
			
			return entryList;
		}
Esempio n. 3
0
		public override void RouteRemove(RouteEntry r)
		{
			string cmd = "route delete " + r.Address.Value + " mask " + r.Mask.Value + " " + r.Gateway.Value;
			ShellCmd(cmd);
		}
Esempio n. 4
0
		public override void RouteAdd(RouteEntry r)
		{
			string cmd = "";
			cmd += "route add " + r.Address.Value + " mask " + r.Mask.Value + " " + r.Gateway.Value;
			/*
			 * Metric param are ignored or misinterpreted. http://serverfault.com/questions/238695/how-can-i-set-the-metric-of-a-manually-added-route-on-windows
			if(r.Metrics != "")
				cmd += " metric " + r.Metrics;
			*/
			if (r.Interface != "")
				cmd += " if " + r.Interface;
			ShellCmd(cmd);
		}
Esempio n. 5
0
 public virtual void RouteRemove(RouteEntry r)
 {
     NotImplemented();
 }
Esempio n. 6
0
 public virtual void RouteAdd(RouteEntry r)
 {
     NotImplemented();
 }
Esempio n. 7
0
		public override List<RouteEntry> RouteList()
		{	
			List<RouteEntry> entryList = new List<RouteEntry>();

			string result = ShellCmd("route -n -ee");

			string[] lines = result.Split('\n');
			foreach (string line in lines)
			{
				string[] fields = Utils.StringCleanSpace(line).Split(' ');

				if (fields.Length == 11)
				{
					RouteEntry e = new RouteEntry();
					e.Address = fields[0];
					e.Gateway = fields[1];
					e.Mask = fields[2];
					e.Flags = fields[3].ToUpperInvariant();
					e.Metrics = fields[4];
					// Ref, Use ignored
					e.Interface = fields[7];
					e.Mss = fields[8];
					e.Window = fields[9];
					e.Irtt = fields[10];
					
					if (e.Address.Valid == false)
						continue;
					if (e.Gateway.Valid == false)
						continue;
					if (e.Mask.Valid == false)
						continue;

					entryList.Add(e);
				}
			}

			return entryList;
		}
Esempio n. 8
0
		public override void RouteRemove(RouteEntry r)
		{
			string cmd = "route del";

			cmd += " -net " + r.Address.Value;
			cmd += " gw " + r.Gateway.Value;
			cmd += " netmask " + r.Mask.Value;			
			/*
			if(r.Metrics != "")
				cmd += " metric " + r.Metrics;			
			*/
			if(r.Interface != "")
				cmd += " dev " + r.Interface;
			
			ShellCmd(cmd);
		}
Esempio n. 9
0
		public override void RouteAdd(RouteEntry r)
		{
			string cmd = "route add";

			cmd += " -net " + r.Address.Value;
			cmd += " netmask " + r.Mask.Value;
			cmd += " gw " + r.Gateway.Value;
			if(r.Metrics != "")
				cmd += " metric " + r.Metrics;
			if( (r.Mss != "") && (r.Mss != "0") )
				cmd += " mss " + r.Mss;
			if( (r.Window != "") && (r.Window != "0") ) 
				cmd += " window " + r.Window;
			if (r.Irtt != "")
				cmd += " irtt " + r.Irtt;

			if (r.Flags.Contains("!"))
				cmd += " reject";
			if (r.Flags.Contains("M"))
				cmd += " mod";
			if (r.Flags.Contains("D"))
				cmd += " dyn";
			if (r.Flags.Contains("R"))
				cmd += " reinstate";

			if(r.Interface != "")
				cmd += " dev " + r.Interface;

			ShellCmd(cmd);
		}
Esempio n. 10
0
		public override void RouteRemove(RouteEntry r)
		{
			base.RouteRemove (r);
		}
Esempio n. 11
0
		public override void RouteAdd(RouteEntry r)
		{
			base.RouteAdd (r);
		}
Esempio n. 12
0
		public virtual bool OnRouteDefaultRemoveRestore()
		{
			if (m_routeDefaultRemove != null)
			{
				m_routeDefaultRemove.Add();
				m_routeDefaultRemove = null;

				Recovery.Save();
			}

			return true;
		}
Esempio n. 13
0
		public virtual bool OnRouteDefaultRemoveDo()
		{
			List<RouteEntry> routeEntries = RouteList();
			foreach (RouteEntry routeEntry in routeEntries)
			{
				if (routeEntry.Mask.ToString() == "0.0.0.0")
				{
					m_routeDefaultRemove = routeEntry;

					routeEntry.Remove();

					Recovery.Save();
				}
			}

			return true;
		}
Esempio n. 14
0
		/*
		// This is called every time, the OnRecoveryLoad only if Recovery.xml exists
		public virtual void OnRecovery()
		{
		}
		*/

		public virtual void OnRecoveryLoad(XmlElement root)
		{
			XmlElement nodeRouteDefaultRemoved = Utils.XmlGetFirstElementByTagName(root, "RouteDefaultRemoved");
			if (nodeRouteDefaultRemoved != null)
			{
				m_routeDefaultRemove = new RouteEntry();
				m_routeDefaultRemove.ReadXML(nodeRouteDefaultRemoved);				
			}

			OnRouteDefaultRemoveRestore();
			OnDnsSwitchRestore();
			OnIpV6Restore();
		}
Esempio n. 15
0
		public virtual void RouteRemove(RouteEntry r)
		{
			NotImplemented();
		}
Esempio n. 16
0
		public virtual void RouteAdd(RouteEntry r)
		{
			NotImplemented();
		}