From 8b54d92b1eef9a74f2037a9654e5f68211fde128 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Sun, 9 Aug 2015 20:27:07 -0600 Subject: [PATCH] Get DHCP server on wRouter to work. --- EduNetworkBuilder/NetworkDevice.cs | 27 ++++++++++++++++++++++++--- EduNetworkBuilder/Packet.cs | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index 825b41a..10f64e3 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -199,6 +199,14 @@ namespace EduNetworkBuilder CanAddNics = false; setNicsCanUseDHCP(true); } + if (myType == NetworkComponentType.wrouter) + { + CanServeDHCP = true; + CanUseDHCP = true; + MustUseDHCP = false; + CanAddNics = false; + setNicsCanUseDHCP(true); + } } private void setNicsCanUseDHCP(bool CanUse) @@ -1014,6 +1022,7 @@ namespace EduNetworkBuilder public ResponseToPacket HowToRespondToPacket(Packet tPacket) { bool typesMatch=false; + if (tPacket.sourceIP == null) return ResponseToPacket.reject; foreach(IPConnectionEntry ipc in IPConnections) { if(ipc.destIP.GetIP == tPacket.sourceIP.GetIP || HasBroadcastAddress(ipc.destIP)) @@ -1472,7 +1481,13 @@ namespace EduNetworkBuilder nPacket.MyStatus = PacketStatus.processing; tPacket.AddMessage(DebugLevel.info, "Success! The DHCP request reached a DHCP Server."); - tPacket.Tracking.Status = hostname + ":\tDHCP Request found Server: " + nPacket.sourceIP.GetIPString; + string IP = ""; + if (nPacket.sourceIP != null) IP = nPacket.sourceIP.GetIPString; + if(IP == "" && nPacket.WhereAmI != null) { + IPAddress tIP = HubManagementIP(); + if (tIP != null) IP = tIP.GetIPString; + } + tPacket.Tracking.Status = hostname + ":\tDHCP Request found Server: " + IP; tPacket.MyStatus = PacketStatus.finished_ok; return; } @@ -1499,7 +1514,10 @@ namespace EduNetworkBuilder else { tPacket.AddMessage(DebugLevel.info, "ERROR! A packet returned to a machine that we were not expecting it from."); - tPacket.Tracking.Status = hostname + ":\tDHCP Request failed: Arrived at a machine that was not expecting it and was rejected." + tPacket.sourceIP.GetIP.ToIpString() + " -> " + tPacket.destIP.GetIP.ToIpString(); + string sIP = "?.?.?.?"; + if (tPacket.sourceIP != null) + sIP = tPacket.sourceIP.GetIP.ToIpString(); + tPacket.Tracking.Status = hostname + ":\tDHCP Request failed: Arrived at a machine that was not expecting it and was rejected." + sIP + " -> " + tPacket.destIP.GetIP.ToIpString(); tPacket.MyStatus = PacketStatus.finished_failed; } return; @@ -2183,7 +2201,8 @@ namespace EduNetworkBuilder } public IPAddress DHCPRangeMatchingInterface(IPAddress InterfaceIP) - { + { + if (InterfaceIP == null) return null; foreach (IPAddress ip in DHCPRanges) { if (ip.GetIP.ToIpString() != "127.0.0.1" && InterfaceIP.IsLocal(ip)) @@ -2254,6 +2273,8 @@ namespace EduNetworkBuilder /// an IPAddress IP/Mask/GW public IPAddress RequestDHCPLease(string MAC, IPAddress NIC_IP) { + if (NIC_IP == null) + NIC_IP = HubManagementIP(); IPAddress tAddress = LookupDHCPLease(MAC, NIC_IP); if (tAddress != null) return tAddress; diff --git a/EduNetworkBuilder/Packet.cs b/EduNetworkBuilder/Packet.cs index a329674..b30f70d 100644 --- a/EduNetworkBuilder/Packet.cs +++ b/EduNetworkBuilder/Packet.cs @@ -316,6 +316,7 @@ namespace EduNetworkBuilder public void StartOnLink(NetworkLink theLink, NetworkDevice start_device) { + if (theLink == null) return; WhereAmI = theLink; MyStatus = PacketStatus.moving; myLinkPercent = 0;