Describe your class quickly here.
Add more details here.
        public InterfacePerformanceForm(NetworkInterface nic)
        {
            if (Instance != null)
            {
                Instance.WindowState = FormWindowState.Normal;
                Instance.Activate();
                return;
            }
            Instance = this;
            Global.BusyForms.Enqueue(busyForm);
            InitializeComponent();
            // resize
            Size minimumSize = ClientSize;
            Rectangle screenRectangle = RectangleToScreen(ClientRectangle);
            int titleBarHeight = screenRectangle.Top - Top;
            int borderThickness = screenRectangle.Left - Left;
            Rectangle workingArea = Screen.GetWorkingArea(this);
            Size clientSize = new Size();
            if (minimumSize.Width > workingArea.Width - 2 * borderThickness)
                clientSize.Width = workingArea.Width - 2 * borderThickness;
            else
                clientSize.Width = minimumSize.Width;
            if (minimumSize.Height > workingArea.Height - titleBarHeight - borderThickness)
                clientSize.Height = workingArea.Height - titleBarHeight - borderThickness;
            else
                clientSize.Height = minimumSize.Height;
            AutoScrollMinSize = new System.Drawing.Size(minimumSize.Width, minimumSize.Height);
            ClientSize = new Size(clientSize.Width, clientSize.Height);

            Show();
        }
Exemplo n.º 2
0
        public static long TotalSentdBytes(this WinLib.Network.NetworkInterface networkInterface)
        {
            InterfaceDataUsage interfaceDataUsage = Config.DataUsage.FirstOrDefault(i => i.InterfaceGuid == networkInterface.Guid);

            if (interfaceDataUsage != null)
            {
                return(interfaceDataUsage.PreviousSessionsSentBytes + networkInterface.IPv4BytesSent);
            }
            else
            {
                return(networkInterface.IPv4BytesSent);
            }
        }
        public ConfigureInterfaceForm(Guid guid)
        {
            if (Instance != null)
            {
                // TODO: flash existing config form
                Instance.WindowState = FormWindowState.Normal;
                Instance.Activate();
                return;
            }
            Instance = this;
            Global.BusyForms.Enqueue(busyForm);
            InitializeComponent();
            // load profiles
            LoadProfiles();
            // resize
            Size minimumSize = ClientSize;
            Rectangle screenRectangle = RectangleToScreen(ClientRectangle);
            int titleBarHeight = screenRectangle.Top - Top;
            int borderThickness = screenRectangle.Left - Left;
            Rectangle workingArea = Screen.GetWorkingArea(this);
            Size clientSize = new Size();
            if (minimumSize.Width > workingArea.Width - 2 * borderThickness)
                clientSize.Width = workingArea.Width - 2 * borderThickness;
            else
                clientSize.Width = minimumSize.Width;
            if (minimumSize.Height > workingArea.Height - titleBarHeight - borderThickness)
                clientSize.Height = workingArea.Height - titleBarHeight - borderThickness;
            else
                clientSize.Height = minimumSize.Height;
            AutoScrollMinSize = new System.Drawing.Size(minimumSize.Width, minimumSize.Height);
            ClientSize = new Size(clientSize.Width, clientSize.Height);
            // IPv4
            nic = Global.NetworkInterfaces[guid];
            for (int i = 0; i < nic.IPv4Address.Count; i++)
                dataGridView1.Rows.Add(nic.IPv4Address[i].Address, nic.IPv4Address[i].Subnet);
            for (int i = 0; i < nic.IPv4Gateway.Count; i++)
                dataGridView2.Rows.Add(nic.IPv4Gateway[i].Address, nic.IPv4Gateway[i].GatewayMetric);
            for (int i = 0; i < nic.IPv4DnsServer.Count; i++)
                dataGridView3.Rows.Add(nic.IPv4DnsServer[i]);
            dhcpIPEnabled.Checked = nic.Dhcpv4Enabled > NetworkInterface.Dhcp.Disabled;
            dataGridView1.Enabled = nic.Dhcpv4Enabled == 0;
            dataGridView2.Enabled = nic.Dhcpv4Enabled == 0;
            dhcpDnsEnabled.Checked = nic.Dhcpv4Enabled == NetworkInterface.Dhcp.IPnDns;
            button13.Enabled = nic.Dhcpv4Enabled < NetworkInterface.Dhcp.IPnDns;
            button14.Enabled = nic.Dhcpv4Enabled < NetworkInterface.Dhcp.IPnDns;
            dataGridView3.Enabled = nic.Dhcpv4Enabled < NetworkInterface.Dhcp.IPnDns;
            interfaceMetric.Text = nic.InterfaceMetric.ToString();
            ipv4Mtu.Text = nic.IPv4Mtu;
            new WinLib.Forms.TextBoxMask(interfaceMetric, WinLib.Forms.TextBoxMask.Mask.Numeric);
            new WinLib.Forms.TextBoxMask(ipv4Mtu, WinLib.Forms.TextBoxMask.Mask.Numeric);
            netbiosEnabled.Checked = nic.NetbiosEnabled < NetworkInterface.Netbios.Disabled;
            if (Environment.OSVersion.Version.CompareTo(new Version("6.0")) < 0)
            {
                toolTip.SetToolTip(ipv4Mtu, "This has no effect on versions of Windows older that Windows Vista");
            }
            // IPv6
            for (int i = 0; i < nic.IPv6Address.Global.Count; i++)
                dataGridView4.Rows.Add(nic.IPv6Address.Global[i].Address, nic.IPv6Address.Global[i].Subnet);
            for (int i = 0; i < nic.IPv6Address.Temporary.Count; i++)
                dataGridView4.Rows.Add(nic.IPv6Address.Temporary[i].Address, nic.IPv6Address.Temporary[i].Subnet);
            for (int i = 0; i < nic.IPv6Address.LinkLocal.Count; i++)
                dataGridView4.Rows.Add(nic.IPv6Address.LinkLocal[i].Address, nic.IPv6Address.LinkLocal[i].Subnet);
            for (int i = 0; i < nic.IPv6Address.SiteLocal.Count; i++)
                dataGridView4.Rows.Add(nic.IPv6Address.SiteLocal[i].Address, nic.IPv6Address.SiteLocal[i].Subnet);
            for (int i = 0; i < nic.IPv6Address.UniqueLocal.Count; i++)
                dataGridView4.Rows.Add(nic.IPv6Address.UniqueLocal[i].Address, nic.IPv6Address.UniqueLocal[i].Subnet);
            for (int i = 0; i < nic.IPv6Address.Local.Count; i++)
                dataGridView4.Rows.Add(nic.IPv6Address.Local[i].Address, nic.IPv6Address.Local[i].Subnet);

            for (int i = 0; i < nic.IPv6Gateway.Count; i++)
                dataGridView5.Rows.Add(nic.IPv6Gateway[i].Address, nic.IPv6Gateway[i].GatewayMetric);
            for (int i = 0; i < nic.IPv6DnsServer.Count; i++)
                dataGridView6.Rows.Add(nic.IPv6DnsServer[i]);
            routerDiscoveryEnabled.Checked = nic.IPv6RouterDiscoveryEnabled;
            ipv6Mtu.Text = nic.IPv6Mtu;
            new WinLib.Forms.TextBoxMask(ipv6Mtu, WinLib.Forms.TextBoxMask.Mask.Numeric);
            if (!nic.IPv4Enabled)
                tabControl1.TabPages[0].Enabled = false;
            if (!nic.IPv6Enabled)
                tabControl1.TabPages[1].Enabled = false;
            Text = "Configure " + Global.NetworkInterfaces[guid].Name;
            Show();
        }
Exemplo n.º 4
0
 public static bool Start(IEnumerable<NetworkInterface> requiredNics)
 {
     Global.WriteLog("Load Balancer is starting.", true);
     Status.Update(State.Starting);
     if (requiredNics.Count() == 0)
     {
         Global.WriteLog("Load Balancer can't start without any physical interface.", true);
         Global.ShowTrayTip("Load Balancer", "Can't start whitout any physical interface", System.Windows.Forms.ToolTipIcon.Error);
         Status.Update(State.Failed);
         return false;
     }
     if (!Jobs.Extensions.Dependencies.Check())
     {
         Status.Update(State.Failed);
         return false;
     }
     if (!TapInterface.PutUp())
     {
         Global.WriteLog("Load Balancer failed to connect to " + TapInterface.FriendlyName, true);
         Global.ShowTrayTip("Load Balancer", "Failed to connect to " + TapInterface.FriendlyName, System.Windows.Forms.ToolTipIcon.Error);
         Status.Update(State.Failed);
         return false;
     }
     NetworkInterface tapInterface = new NetworkInterface();
     tapInterface.Guid = TapInterface.Guid;
     tapInterface.Name = TapInterface.FriendlyName;
     if (!Dependencies.RunWinPcapService(requiredNics.Concat(new NetworkInterface[] { tapInterface }), true))
     {
         Global.WriteLog("Load Balancer failed to start because some interfaces were not captured by WinPcap.", true);
         Global.ShowTrayTip("Load Balancer", "Failed to start", System.Windows.Forms.ToolTipIcon.Error);
         TapInterface.PutDown();
         Status.Update(State.Failed);
         return false;
     }
     Interfaces = requiredNics;
     // start LB threads
     LoadingForm splash = LoadingForm.Create("Initializing ...");
     foreach (NetworkInterface nic in Global.NetworkInterfaces.Values)
         if (nic.Guid != TapInterface.Guid &&
             (nic.IPv4Gateway.Count > 0 || nic.IPv6Gateway.Count > 0))
         {
             splash.UpdateStatus("Configuring " + nic.Name + " ...");
             nic.SetInterfaceMetric("4000");
             foreach (NetworkInterface.IPGatewayAddress ip in nic.IPv4Gateway)
                 nic.EditIPv4Gateway(ip.Address, "4000");
             foreach (NetworkInterface.IPGatewayAddress ip in nic.IPv6Gateway)
                 nic.EditIPv6Gateway(ip.Address, "4000");
         }
     splash.UpdateStatus("Initializing " + TapInterface.FriendlyName + " ...");
     physicalWorkers.Clear();
     tapWorker = new TapWorker(TapInterface.Guid, TapInterface.FriendlyName, TapInterface.Mac,
         Global.Config.LoadBalancer.IPv4LocalAddresses.First().Address, Global.Config.LoadBalancer.IPv4GatewayAddresses.First().Address);
     new Thread(new ThreadStart(tapWorker.ReceivePackets)).Start();
     tapWorker.Initialized.Wait(1000);
     foreach (NetworkInterface nic in requiredNics)
     {
         splash.UpdateStatus("Initializing " + nic.Name + " ...");
         physicalWorkers.Add(new PhysicalWorker(nic.Guid, nic.Name, nic.Mac, nic.IPv4Address.First().Address,
             nic.IPv4Address.First().Subnet, nic.DefaultIPv4GatewayMac, nic.DefaultIPv4Gateway));
         new Thread(new ThreadStart(physicalWorkers.Last().ReceivePackets)).Start();
         physicalWorkers.Last().Initialized.Wait(10000);
     }
     int mtu;
     MTU = requiredNics.Min((i) => int.TryParse(i.IPv4Mtu, out mtu) ? mtu : 1500);
     Global.WriteLog("Load Balancer: Negociated MTU = " + MTU);
     MSS = (ushort)(MTU - 40);
     splash.Stop();
     Dependencies.WinPcapInUse.Reset(Dependencies.WinPcapInUse.CurrentCount + 1);
     Global.WriteLog("Load Balancer: started");
     Global.ShowTrayTip("Load Balancer", "Started", System.Windows.Forms.ToolTipIcon.Info);
     Status.Update(State.Running);
     new Thread(new ThreadStart(CheckUp)).Start();
     return true;
 }