Fixed broadcast ping issues
This commit is contained in:
parent
87c085448d
commit
418f8ec6c7
@ -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();
|
||||
|
@ -1028,17 +1028,16 @@ namespace EduNetworkBuilder
|
||||
//}
|
||||
public bool HasBroadcastAddress(IPAddress dest)
|
||||
{
|
||||
if (dest.BroadcastAddress == dest.GetIP)
|
||||
return true;
|
||||
if (dest.GetIPString == NB.BroadcastIPString)
|
||||
return true;
|
||||
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,50 +1517,60 @@ namespace EduNetworkBuilder
|
||||
if (tPacket.MyType == PacketType.ping_request)
|
||||
{
|
||||
myNet.RegisterTimeOfArrival();
|
||||
nPacket = new Packet(this,tPacket.sourceIP,"",PacketType.ping_answer);
|
||||
nPacket.OriginalDestIP = tPacket.destIP;
|
||||
nPacket.isFresh = true; //So it starts from here
|
||||
nPacket.Tracking = new PacketMessage();
|
||||
myNet.addPacket(nPacket);
|
||||
tPacket.AddMessage(DebugLevel.info, "Success! The ping reached the destination.");
|
||||
tPacket.Tracking.Status = hostname + ":\tPing success: The ping reached the destination." + tPacket.sourceIP.GetIP.ToIpString() + " -> " + tPacket.destIP.GetIP.ToIpString();
|
||||
tPacket.MyStatus = PacketStatus.finished_ok;
|
||||
IPAddress tip = nPacket.sourceIP;
|
||||
if (!HasBroadcastAddress(tPacket.destIP))
|
||||
bool isbroadcast = HasBroadcastAddress(tPacket);
|
||||
if (!isbroadcast || (isbroadcast && HasLocalNic(tPacket.sourceIP)))
|
||||
{
|
||||
nPacket.sourceIP = tPacket.destIP;
|
||||
nPacket.TsourceIP = tPacket.destIP;
|
||||
nPacket = new Packet(this, tPacket.sourceIP, "", PacketType.ping_answer);
|
||||
nPacket.OriginalDestIP = tPacket.destIP;
|
||||
nPacket.isFresh = true; //So it starts from here
|
||||
nPacket.Tracking = new PacketMessage();
|
||||
myNet.addPacket(nPacket);
|
||||
tPacket.AddMessage(DebugLevel.info, "Success! The ping reached the destination.");
|
||||
tPacket.Tracking.Status = hostname + ":\tPing success: The ping reached the destination." + tPacket.sourceIP.GetIP.ToIpString() + " -> " + tPacket.destIP.GetIP.ToIpString();
|
||||
tPacket.MyStatus = PacketStatus.finished_ok;
|
||||
IPAddress tip = nPacket.sourceIP;
|
||||
if (!HasBroadcastAddress(tPacket.destIP))
|
||||
{
|
||||
nPacket.sourceIP = tPacket.destIP;
|
||||
nPacket.TsourceIP = tPacket.destIP;
|
||||
}
|
||||
else
|
||||
{
|
||||
nPacket.sourceIP = new IPAddress(NB.ZeroIPString);
|
||||
nPacket.TsourceIP = new IPAddress(NB.ZeroIPString);
|
||||
}
|
||||
if (tip.GetIP.ToIpString() != NB.ZeroIPString)
|
||||
nPacket.destIP = tip;
|
||||
if (tPacket.isFresh)
|
||||
{
|
||||
//The packet reached itself. At this moment, the packet does not yet have the source information set
|
||||
//We just need to set the dest
|
||||
//
|
||||
nPacket.destIP = new IPAddress(NB.LoopbackIPString);
|
||||
}
|
||||
if (myType == NetworkComponentType.net_hub || myType == NetworkComponentType.net_switch ||
|
||||
myType == NetworkComponentType.wrouter)
|
||||
{
|
||||
//put mac of management interface on packet
|
||||
//dmac is originating mac
|
||||
nPacket.destMAC = tPacket.sourceMAC;
|
||||
nPacket.OutboundDestMAC = tPacket.sourceMAC;
|
||||
nPacket.sourceMAC = HubManagementMAC();
|
||||
}
|
||||
else
|
||||
{
|
||||
nPacket.destMAC = "";
|
||||
nPacket.sourceMAC = "";
|
||||
}
|
||||
nPacket.MyType = PacketType.ping_answer;
|
||||
nPacket.MyStatus = PacketStatus.processing;
|
||||
}
|
||||
else
|
||||
{
|
||||
nPacket.sourceIP = new IPAddress(NB.ZeroIPString);
|
||||
nPacket.TsourceIP = new IPAddress(NB.ZeroIPString);
|
||||
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;
|
||||
}
|
||||
if (tip.GetIP.ToIpString() != NB.ZeroIPString)
|
||||
nPacket.destIP = tip;
|
||||
if (tPacket.isFresh)
|
||||
{
|
||||
//The packet reached itself. At this moment, the packet does not yet have the source information set
|
||||
//We just need to set the dest
|
||||
//
|
||||
nPacket.destIP = new IPAddress(NB.LoopbackIPString);
|
||||
}
|
||||
if (myType == NetworkComponentType.net_hub || myType == NetworkComponentType.net_switch ||
|
||||
myType == NetworkComponentType.wrouter)
|
||||
{
|
||||
//put mac of management interface on packet
|
||||
//dmac is originating mac
|
||||
nPacket.destMAC = tPacket.sourceMAC;
|
||||
nPacket.OutboundDestMAC = tPacket.sourceMAC;
|
||||
nPacket.sourceMAC = HubManagementMAC();
|
||||
}
|
||||
else
|
||||
{
|
||||
nPacket.destMAC = "";
|
||||
nPacket.sourceMAC = "";
|
||||
}
|
||||
nPacket.MyType = PacketType.ping_answer;
|
||||
nPacket.MyStatus = PacketStatus.processing;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user