Fixed broadcast ping issues

This commit is contained in:
Tim Young 2015-09-20 08:16:27 -04:00
parent 87c085448d
commit 418f8ec6c7
2 changed files with 70 additions and 47 deletions

View File

@ -226,10 +226,12 @@ namespace EduNetworkBuilder
}
return false;
}
public bool HasBroadcastAddresses(IPAddress dest)
{
if (myNicType == NicType.port) return false;
if (myNicType == NicType.none) return false;
if (myNicType == NicType.lo) return false;
if (dest == null) return false;
foreach (NetworkInterface iface in interfaces)
{
@ -362,6 +364,8 @@ namespace EduNetworkBuilder
if(Tracker != null)
Tracker.AddMessage(DebugLevel.routing, myID.HostName, "Found local interface: ip" + nIF.myIP.GetIP.ToIpString() +
" gw:" + nIF.myIP.GetMask.ToIpString());
if(Tracker != null && theIP != null)
Tracker.AddMessage(DebugLevel.routing, myID.HostName, " IP of local: " + theIP.GetIPString + " " + theIP.GetGateway.ToIpString());
return nIF;
}
}
@ -406,7 +410,7 @@ namespace EduNetworkBuilder
if (tPacket.MyType == PacketType.arp_request && !nf.isLocal(tPacket.destIP))
continue; //only send out arp requests on local networks
nPacket = new Packet(tPacket);//Creates a new packet but sets isfresh=false
if (tPacket.OutboundIP == null || (nf.isLocal(tPacket.OutboundIP) || tPacket.OutboundIP.GetIPString == NB.BroadcastIPString))
if (tPacket.OutboundIP == null || (nf.isLocal(tPacket.OutboundIP) || (tPacket.OutboundIP.GetIPString == NB.BroadcastIPString && tPacket.isFresh)))
{
if ((nf != null && nf.myIP.GetIPString != NB.ZeroIPString) || nPacket.MyType == PacketType.dhcp_request)
{
@ -568,7 +572,7 @@ namespace EduNetworkBuilder
//Need to find the managament interface MAC
nPacket.sourceMAC = WhereFrom.HubManagementMAC();
}
if((nPacket.sourceIP == null || nPacket.sourceIP.GetIPString == NB.ZeroIPString) && !(nPacket.MyType == PacketType.dhcp_request && tPacket.isFresh))
if((nPacket.sourceIP == null || nPacket.sourceIP.GetIPString == NB.ZeroIPString) && nPacket.MyType != PacketType.dhcp_request)
{
//set it to be the ip of management interface
nPacket.sourceIP = WhereFrom.HubManagementIP();

View File

@ -1028,17 +1028,16 @@ namespace EduNetworkBuilder
//}
public bool HasBroadcastAddress(IPAddress dest)
{
if (dest.BroadcastAddress == dest.GetIP)
return true;
if (dest.GetIPString == NB.BroadcastIPString)
foreach(NetworkCard nic in NICs)
{
if (nic.HasBroadcastAddresses(dest))
return true;
}
return false;
}
public bool HasBroadcastAddress(Packet tPacket)
{
if (tPacket.destMAC == NB.BroadcastMACString) return true;
if (tPacket.destIP.GetIPString == NB.BroadcastIPString) return true;
return HasBroadcastAddress(tPacket.destIP);
}
@ -1369,6 +1368,7 @@ namespace EduNetworkBuilder
// if (nic == tPacket.InboundNic) break; //this case is dealt with in nic.SendPacketOutNic
//Pass it to the NIC to send out each nic+interface.
//The nic checks to see if it works and then processes it
if (!tPacket.isFresh && HasBroadcastAddress(tPacket.destIP)) break;
string tMAC = tPacket.destMAC;
string ttMAC = tPacket.OutboundDestMAC;
if (BroadcastMatch && tPacket.MyType != PacketType.dhcp_answer)
@ -1517,6 +1517,9 @@ namespace EduNetworkBuilder
if (tPacket.MyType == PacketType.ping_request)
{
myNet.RegisterTimeOfArrival();
bool isbroadcast = HasBroadcastAddress(tPacket);
if (!isbroadcast || (isbroadcast && HasLocalNic(tPacket.sourceIP)))
{
nPacket = new Packet(this, tPacket.sourceIP, "", PacketType.ping_answer);
nPacket.OriginalDestIP = tPacket.destIP;
nPacket.isFresh = true; //So it starts from here
@ -1561,6 +1564,13 @@ namespace EduNetworkBuilder
}
nPacket.MyType = PacketType.ping_answer;
nPacket.MyStatus = PacketStatus.processing;
}
else
{
tPacket.AddMessage(DebugLevel.info, "The broadcast ping reached a destination that was not on the same network");
tPacket.Tracking.Status = hostname + ":\tThe broadcast ping reached a destination that was not on the same network" + tPacket.sourceIP.GetIP.ToIpString() + " -> " + hostname;
tPacket.MyStatus = PacketStatus.finished_ok;
}
return;
}
if (tPacket.MyType == PacketType.ping_answer)
@ -2571,5 +2581,14 @@ namespace EduNetworkBuilder
}
return false;
}
public bool HasLocalNic(IPAddress dest)
{
foreach(NetworkCard nic in NICs)
{
if (nic.HasLocalInterface(dest)) return true;
}
return false;
}
}
}