From 828387ba8a51700cd65ecee54df2d93719623d8e Mon Sep 17 00:00:00 2001 From: Tim Young Date: Thu, 20 Oct 2016 14:53:23 -0500 Subject: [PATCH] VLAN tests are working --- EduNetworkBuilder/DeviceConfig.cs | 71 +++++++++++++++++++++++++++--- EduNetworkBuilder/NB.cs | 2 +- EduNetworkBuilder/NetTest.cs | 7 +-- EduNetworkBuilder/NetTestEditor.cs | 36 +++++++++++++++ EduNetworkBuilder/Network.cs | 4 +- EduNetworkBuilder/NetworkCard.cs | 20 +++++++++ EduNetworkBuilder/NetworkDevice.cs | 20 ++++++--- EduNetworkBuilder/Packet.cs | 2 + EduNetworkBuilder/VLANConfig.cs | 10 ++++- 9 files changed, 154 insertions(+), 18 deletions(-) diff --git a/EduNetworkBuilder/DeviceConfig.cs b/EduNetworkBuilder/DeviceConfig.cs index 290f3f7..5795cfb 100644 --- a/EduNetworkBuilder/DeviceConfig.cs +++ b/EduNetworkBuilder/DeviceConfig.cs @@ -75,8 +75,55 @@ namespace EduNetworkBuilder if(ClonedItem is NetworkDevice) { NetworkDevice ndCLonedItem = (NetworkDevice)ClonedItem; - - if(ndCLonedItem.CanAddNics) + + + bool nicLocked = false; + bool interfacesLocked = false; + foreach (string nName in ndCLonedItem.NICNames()) + { + NetworkCard nic = ndCLonedItem.NicFromName(nName); + if (theNet.ItemIsLocked(ClonedItem.hostname, nic.NicName(), NetTestType.LockNic) || + theNet.ItemIsLocked(ClonedItem.hostname, "", NetTestType.LockVLANsOnHost)) + { + nicLocked = true; + interfacesLocked = true; + } + } + //if the selected interface is locked + if (lbNics.SelectedIndex != -1 && theNet.ItemIsLocked(ClonedItem.hostname, StripNicName(lbNics.SelectedItem.ToString()), NetTestType.LockNicVLAN)) + { + nicLocked = true; + interfacesLocked = true; + } + if (lbNics.SelectedIndex != -1) + { + string nic_name = StripNicName(lbNics.SelectedItem.ToString()); + NetworkCard nic = ndCLonedItem.NicFromName(nic_name); + if (nic != null) + { + for (int i = 0; i < nic.IFCount; i++) + { + NetworkInterface nif = nic.GetInterface(i); + if (theNet.ItemIsLocked(ClonedItem.hostname, nif.nic_name, NetTestType.LockInterfaceVLAN) || + theNet.ItemIsLocked(ClonedItem.hostname, nif.nic_name, NetTestType.LockVLANsOnHost)) + { + nicLocked = true; + interfacesLocked = true; + } + } + } + } + if (interfacesLocked) + { + btnIfAdd.Visible = false; + btnIfMinus.Visible = false; + } + else + { + btnIfAdd.Visible = true; + btnIfMinus.Visible = true; + } + if (ndCLonedItem.CanAddNics && ! nicLocked) { btnNicPlus.Visible = true; btnNicMinus.Visible = true; @@ -133,6 +180,7 @@ namespace EduNetworkBuilder if (selectedLb >= lbNics.Items.Count) selectedLb = -1; lbNics.SelectedIndex = selectedLb; } + if (lbNics.SelectedIndex >= 0) { btnNicEdit.Enabled = true; @@ -155,8 +203,9 @@ namespace EduNetworkBuilder //Use the index of the nic string selectedNicName = ""; if (lbNics.SelectedItem != null) selectedNicName = lbNics.SelectedItem.ToString(); - selectedNicName = Regex.Replace(selectedNicName, " .*", ""); - selectedNicName = Regex.Replace(selectedNicName, "\\*", ""); + //selectedNicName = Regex.Replace(selectedNicName, " .*", ""); + //selectedNicName = Regex.Replace(selectedNicName, "\\*", ""); + selectedNicName = StripNicName(selectedNicName); lists = ndCLonedItem.NetworkCardInterfaceStrings(selectedNicName); //get the IPAddress string list from the nic selectedLb = lbAddresses.SelectedIndex; @@ -346,6 +395,14 @@ namespace EduNetworkBuilder UpdateForm(); } + private string StripNicName(string NIC) + { + string processed = NIC; + processed = Regex.Replace(processed, " .*", ""); + processed = Regex.Replace(processed, "\\*", ""); + return processed; + } + private void editInterface() { if (ClonedItem.GetType().ToString() == "EduNetworkBuilder.NetworkDevice") @@ -353,9 +410,9 @@ namespace EduNetworkBuilder NetworkDevice ndCLonedItem = (NetworkDevice)ClonedItem; if (lbAddresses.SelectedIndex >= 0 && lbNics.SelectedIndex >= 0) { - string selectedNIC = lbNics.SelectedItem.ToString(); - selectedNIC = Regex.Replace(selectedNIC, " .*", ""); - selectedNIC = Regex.Replace(selectedNIC, "\\*", ""); + string selectedNIC = StripNicName( lbNics.SelectedItem.ToString()); + //selectedNIC = Regex.Replace(selectedNIC, " .*", ""); + //selectedNIC = Regex.Replace(selectedNIC, "\\*", ""); ndCLonedItem.EditNicInterface(selectedNIC, lbAddresses.SelectedIndex); UpdateForm(); diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index 5b6ef20..403e571 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -45,7 +45,7 @@ namespace EduNetworkBuilder SuccessfullyPings, SuccessfullyPingsAgain, SuccessfullyArps, SuccessfullyDHCPs, HelpRequest, ReadContextHelp, FailedPing, DHCPServerEnabled, LockAll, LockIP, LockRoute, LockNic, LockDHCP, LockGateway, - LockVLAN, LockNicVLAN, LockInterfaceVLAN, LockVLANNames, + LockVLANsOnHost, LockNicVLAN, LockInterfaceVLAN, LockVLANNames, } public enum NetTestVerbosity { none, basic, hints, full } public enum LBContents { routes, messages, dhcp, puzzles } diff --git a/EduNetworkBuilder/NetTest.cs b/EduNetworkBuilder/NetTest.cs index ecc523e..4a72d9c 100644 --- a/EduNetworkBuilder/NetTest.cs +++ b/EduNetworkBuilder/NetTest.cs @@ -73,6 +73,7 @@ namespace EduNetworkBuilder case NetTestType.LockInterfaceVLAN: case NetTestType.LockNicVLAN: case NetTestType.LockVLANNames: + case NetTestType.LockVLANsOnHost: TaskWasDone = true; break; } @@ -182,7 +183,7 @@ namespace EduNetworkBuilder case NetTestType.LockVLANNames: toreturn = NB.Translate("NT_TstDiscriptLockVLANNames"); break; - case NetTestType.LockVLAN: + case NetTestType.LockVLANsOnHost: toreturn = NB.Translate("NT_TstDiscriptLockVLAN"); break; case NetTestType.LockNicVLAN: @@ -263,7 +264,7 @@ namespace EduNetworkBuilder case NetTestType.LockVLANNames: toreturn = NB.Translate("NT_TstDiscriptLockVLANNames") + ":"; break; - case NetTestType.LockVLAN: + case NetTestType.LockVLANsOnHost: toreturn = NB.Translate("NT_TstDiscriptLockVLAN") + ":"; break; case NetTestType.LockNicVLAN: @@ -493,7 +494,7 @@ namespace EduNetworkBuilder case NetTestType.LockGateway: case NetTestType.LockInterfaceVLAN: case NetTestType.LockNicVLAN: - case NetTestType.LockVLAN: + case NetTestType.LockVLANsOnHost: case NetTestType.LockVLANNames: return true; //Nothing to solve. We just lock it so it cannot be changed. } diff --git a/EduNetworkBuilder/NetTestEditor.cs b/EduNetworkBuilder/NetTestEditor.cs index 7f02f90..2698a7d 100644 --- a/EduNetworkBuilder/NetTestEditor.cs +++ b/EduNetworkBuilder/NetTestEditor.cs @@ -165,6 +165,37 @@ namespace EduNetworkBuilder { //No items for lockvlannames cbDest.Items.Add(NB.Translate("_All")); + cbSource.Items.Clear(); + cbSource.Items.Add(NB.Translate("_All")); + } + else if (ToEdit.TheTest == NetTestType.LockNicVLAN) + { + sItem = theNet.GetDeviceFromName(ToEdit.sHost); + foreach (string nname in sItem.NICNames()) + { + NetworkCard nic = sItem.NicFromName(nname); + if (!nic.NicCanDoVLANs()) continue; + cbDest.Items.Add(nic.NicName()); + } + } + else if (ToEdit.TheTest == NetTestType.LockVLANsOnHost) + { + //No items for lockvlannames + cbDest.Items.Add(NB.Translate("_All")); + } + else if (ToEdit.TheTest == NetTestType.LockInterfaceVLAN) + { + sItem = theNet.GetDeviceFromName(ToEdit.sHost); + foreach (string nname in sItem.NICNames()) + { + NetworkCard nic = sItem.NicFromName(nname); + if (!nic.NicCanDoVLANs()) continue; + for (int i = 0; i < nic.IFCount; i++) + { + NetworkInterface nif = nic.GetInterface(i); + cbDest.Items.Add(nif.nic_name); + } + } } else { //List all the hosts @@ -242,6 +273,11 @@ namespace EduNetworkBuilder { //This uses a verbosity } + else if(ntt == NetTestType.LockInterfaceVLAN || ntt == NetTestType.LockNicVLAN || + ntt == NetTestType.LockVLANNames || ntt == NetTestType.LockVLANsOnHost) + { + return true; + } else { if (ntt == NetTestType.SuccessfullyPings) return true; diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index d1a63e2..8dff60e 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -740,12 +740,14 @@ namespace EduNetworkBuilder { foreach (NetTest nt in NetTests) { - if(nt.sHost == host) + if(nt.sHost == host || WhatToCheck == NetTestType.LockVLANNames) { if (nt.TheTest == NetTestType.LockAll) return true; if (WhatToCheck == nt.TheTest && WhatToCheck == NetTestType.LockVLANNames) //no dest to check return true; + if (WhatToCheck == nt.TheTest && WhatToCheck == NetTestType.LockVLANsOnHost) //no dest to check + return true; if (WhatToCheck == nt.TheTest && dest == nt.dHost) return true; } diff --git a/EduNetworkBuilder/NetworkCard.cs b/EduNetworkBuilder/NetworkCard.cs index acc73c1..06e23f0 100644 --- a/EduNetworkBuilder/NetworkCard.cs +++ b/EduNetworkBuilder/NetworkCard.cs @@ -431,6 +431,15 @@ namespace EduNetworkBuilder return null; } + + public bool NicCanDoVLANs() + { + if (myNicType == NicType.eth) return true; + if (myNicType == NicType.port) return true; + if (myNicType == NicType.wan) return true; + return false; + } + /*************************************** * * *************************************/ @@ -749,6 +758,17 @@ namespace EduNetworkBuilder } } + public NetworkInterface InterfaceFromVlanTag(Packet tPacket) + { + int ID = tPacket.VLANID; + foreach(NetworkInterface oneIF in interfaces) + { + if (oneIF.GetVLANTag(ID) != VLANTagType.Forbidden) + return oneIF; + } + return null; + } + public IPAddress FirstIP() { List addresses = IPAddressList(); diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index 19400fa..6031f2e 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -1825,7 +1825,7 @@ namespace EduNetworkBuilder dst = RequestDHCPLease(tPacket.sourceMAC, tPacket.InboundInterface.myIP); } //if we the packet came in on a port... - if (tPacket.InboundNic.GetNicType == NicType.wport || tPacket.InboundNic.GetNicType == NicType.port) + if (tPacket.InboundNic != null && (tPacket.InboundNic.GetNicType == NicType.wport || tPacket.InboundNic.GetNicType == NicType.port)) { IPAddress theIP = HubManagementIP(); if (theIP != null) @@ -2300,6 +2300,7 @@ namespace EduNetworkBuilder tPacket.WhereAmI = this; tPacket.MyStatus = PacketStatus.processing; // + tPacket.PacketDump(hostname, DebugPausePoint.packet_in); if(nc == null) { @@ -2317,6 +2318,7 @@ namespace EduNetworkBuilder return; } NetworkInterface nf = nc.LocalInterface(tPacket.sourceIP, tPacket.Tracking); + if(nf == null) { nf = nc.LocalInterface(tPacket.TsourceIP, tPacket.Tracking); @@ -2325,12 +2327,18 @@ namespace EduNetworkBuilder { nf = nc.PrimaryInterface(); } - if (nf == null && tPacket.MyType == PacketType.dhcp_request && isDHCPServer) + + if (nf == null && tPacket.MyType == PacketType.dhcp_request && isDHCPServer ) { + //It is a broadcast. We need to figure out which nic it came in on + // And then, figure out which interface, so we know which IP to dole out + NetworkInterface inif = nc.InterfaceFromVlanTag(tPacket); + tPacket.InboundInterface = inif; + List addresses = nc.IPAddressList(); if (addresses.Count > 0) { - if (tPacket.TsourceIP == null) tPacket.TsourceIP = tPacket.sourceIP; + if (tPacket.TsourceIP == null) tPacket.TsourceIP = tPacket.sourceIP; tPacket.OutboundIP = addresses[0]; tPacket.OutboundNic = nc; tPacket.OutboundMAC = nc.MAC; @@ -2366,11 +2374,13 @@ namespace EduNetworkBuilder tPacket.MyStatus = PacketStatus.finished_failed; return; } + //Now we pass it to the interface - if(nf != null) + if (nf != null) nf.ProcessInboundPacket(tPacket); + //Now we pass it to the nic - if(nc != null) + if (nc != null) nc.ProcessInboundPacket(tPacket); if (hostname != null) Console.WriteLine("Starting on device: " + hostname + " VLANID = " + tPacket.VLANID.ToString()); diff --git a/EduNetworkBuilder/Packet.cs b/EduNetworkBuilder/Packet.cs index 3859fd4..6f7b76e 100644 --- a/EduNetworkBuilder/Packet.cs +++ b/EduNetworkBuilder/Packet.cs @@ -52,6 +52,7 @@ namespace EduNetworkBuilder public IPAddress payloadIP = null; public PacketMessage Tracking = new PacketMessage(); public NetworkComponent WhereAmI = null; + public NetworkLink LastNetworkLink = null; public nb_direction myDirection = nb_direction.none; public int myLinkPercent = 0; //How far along the path are we. 0%, 50%, 100%. For moving a dot along the link line public bool packet_good = true; @@ -350,6 +351,7 @@ namespace EduNetworkBuilder InboundNic = null; InboundInterface = null; WhereAmI = theLink; + LastNetworkLink = theLink; MyStatus = PacketStatus.moving; myLinkPercent = 0; TickTTL = 200; //We keep resetting this as we go. diff --git a/EduNetworkBuilder/VLANConfig.cs b/EduNetworkBuilder/VLANConfig.cs index 20e5b8b..3e4b0ad 100644 --- a/EduNetworkBuilder/VLANConfig.cs +++ b/EduNetworkBuilder/VLANConfig.cs @@ -88,7 +88,8 @@ namespace EduNetworkBuilder dgv_VLANNames.AllowUserToAddRows = true; if (TheDevice != null) { - if (theNet.ItemIsLocked(hostname, "", NetTestType.LockVLANNames)) + if (theNet.ItemIsLocked(hostname, "", NetTestType.LockVLANNames) || + theNet.ItemIsLocked(hostname, "", NetTestType.LockVLANsOnHost)) LockedNames = true; else LockedNames = false; @@ -103,6 +104,7 @@ namespace EduNetworkBuilder VlanBindings.Rows.Clear(); List theNics = TheDevice.NICNames(); + //Fill out the interfaces foreach (string oneNic in theNics) { NetworkCard NIC = TheDevice.NicFromName(oneNic); @@ -115,6 +117,7 @@ namespace EduNetworkBuilder if (NIC.GetNicType == NicType.tun) continue; bool locked = false; + //Lock the interface if it needs to be locked if (TheDevice != null) { if (theNet.ItemIsLocked(hostname, oneNic, NetTestType.LockNic)) locked = true; @@ -122,12 +125,17 @@ namespace EduNetworkBuilder locked = true; if (theNet.ItemIsLocked(hostname, oneNic, NetTestType.LockNicVLAN)) locked = true; + if (theNet.ItemIsLocked(hostname, oneNic, NetTestType.LockVLANsOnHost)) + locked = true; } + bool pastlock = locked; for (int i = 0; i < NIC.IFCount; i++) { + locked = pastlock; NetworkInterface nif = NIC.GetInterface(i); if (TheDevice != null) { + //If the interface itself is locked... if (theNet.ItemIsLocked(hostname, nif.nic_name, NetTestType.LockInterfaceVLAN)) locked = true; }