diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index 0d9eba9..09edc8e 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -1390,6 +1390,28 @@ namespace EduNetworkBuilder return false; } + public bool LocalMatches(Packet tPacket) + { + //return false; + //the tSourceIP is local to something on the device + //The dest IP exists on the device. + //If we have multiple IPs, the tdest is one, and the actual dest is another + bool MatchesSource = false; + bool MatchesDest = false; + foreach(NetworkCard nic in NICs) + { + //If no IPs are defined, is it 0.0.0.0/0.0.0.0 which is local to everything + if (nic.GetNicType == NicType.port) continue; + if (nic.GetNicType == NicType.wport) continue; + if (nic.HasLocalInterface(tPacket.TsourceIP)) + MatchesSource = true; + if (nic.HasIPAddresses(tPacket.destIP)) + MatchesDest = true; + } + if (MatchesDest && MatchesSource) return true; + return false; + } + public override void ProcessPacket(Packet tPacket) { //Psuedo code for processing a packet @@ -1409,10 +1431,11 @@ namespace EduNetworkBuilder bool MacAddressMatch = HasMac(tPacket.destMAC); //It is an exact match if it is coming from a local source. bool ExactMatch = HasIPAddress(tPacket.destIP) && (tPacket.TsourceIP == null || tPacket.TsourceIP.IsLocal(tPacket.destIP)); + bool LocalMatch = LocalMatches(tPacket); bool BroadcastMatch = HasBroadcastAddress(tPacket.destIP); bool NeedsRouting = MacAddressMatch && (!ExactMatch && !BroadcastMatch); - if(ExactMatch || BroadcastMatch) + if(ExactMatch || BroadcastMatch || LocalMatch) { //Change this. Need a new ProcessArrival if(tPacket.MyType != PacketType.dhcp_answer) //If it is a match, it should be handled elsewhere