Fixed broadcast ping issues
This commit is contained in:
parent
87c085448d
commit
418f8ec6c7
@ -226,10 +226,12 @@ namespace EduNetworkBuilder
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasBroadcastAddresses(IPAddress dest)
|
public bool HasBroadcastAddresses(IPAddress dest)
|
||||||
{
|
{
|
||||||
if (myNicType == NicType.port) return false;
|
if (myNicType == NicType.port) return false;
|
||||||
if (myNicType == NicType.none) return false;
|
if (myNicType == NicType.none) return false;
|
||||||
|
if (myNicType == NicType.lo) return false;
|
||||||
if (dest == null) return false;
|
if (dest == null) return false;
|
||||||
foreach (NetworkInterface iface in interfaces)
|
foreach (NetworkInterface iface in interfaces)
|
||||||
{
|
{
|
||||||
@ -362,6 +364,8 @@ namespace EduNetworkBuilder
|
|||||||
if(Tracker != null)
|
if(Tracker != null)
|
||||||
Tracker.AddMessage(DebugLevel.routing, myID.HostName, "Found local interface: ip" + nIF.myIP.GetIP.ToIpString() +
|
Tracker.AddMessage(DebugLevel.routing, myID.HostName, "Found local interface: ip" + nIF.myIP.GetIP.ToIpString() +
|
||||||
" gw:" + nIF.myIP.GetMask.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;
|
return nIF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -406,7 +410,7 @@ namespace EduNetworkBuilder
|
|||||||
if (tPacket.MyType == PacketType.arp_request && !nf.isLocal(tPacket.destIP))
|
if (tPacket.MyType == PacketType.arp_request && !nf.isLocal(tPacket.destIP))
|
||||||
continue; //only send out arp requests on local networks
|
continue; //only send out arp requests on local networks
|
||||||
nPacket = new Packet(tPacket);//Creates a new packet but sets isfresh=false
|
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)
|
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
|
//Need to find the managament interface MAC
|
||||||
nPacket.sourceMAC = WhereFrom.HubManagementMAC();
|
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
|
//set it to be the ip of management interface
|
||||||
nPacket.sourceIP = WhereFrom.HubManagementIP();
|
nPacket.sourceIP = WhereFrom.HubManagementIP();
|
||||||
|
@ -1028,17 +1028,16 @@ namespace EduNetworkBuilder
|
|||||||
//}
|
//}
|
||||||
public bool HasBroadcastAddress(IPAddress dest)
|
public bool HasBroadcastAddress(IPAddress dest)
|
||||||
{
|
{
|
||||||
if (dest.BroadcastAddress == dest.GetIP)
|
foreach(NetworkCard nic in NICs)
|
||||||
return true;
|
{
|
||||||
if (dest.GetIPString == NB.BroadcastIPString)
|
if (nic.HasBroadcastAddresses(dest))
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasBroadcastAddress(Packet tPacket)
|
public bool HasBroadcastAddress(Packet tPacket)
|
||||||
{
|
{
|
||||||
if (tPacket.destMAC == NB.BroadcastMACString) return true;
|
|
||||||
if (tPacket.destIP.GetIPString == NB.BroadcastIPString) return true;
|
|
||||||
return HasBroadcastAddress(tPacket.destIP);
|
return HasBroadcastAddress(tPacket.destIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1369,6 +1368,7 @@ namespace EduNetworkBuilder
|
|||||||
// if (nic == tPacket.InboundNic) break; //this case is dealt with in nic.SendPacketOutNic
|
// if (nic == tPacket.InboundNic) break; //this case is dealt with in nic.SendPacketOutNic
|
||||||
//Pass it to the NIC to send out each nic+interface.
|
//Pass it to the NIC to send out each nic+interface.
|
||||||
//The nic checks to see if it works and then processes it
|
//The nic checks to see if it works and then processes it
|
||||||
|
if (!tPacket.isFresh && HasBroadcastAddress(tPacket.destIP)) break;
|
||||||
string tMAC = tPacket.destMAC;
|
string tMAC = tPacket.destMAC;
|
||||||
string ttMAC = tPacket.OutboundDestMAC;
|
string ttMAC = tPacket.OutboundDestMAC;
|
||||||
if (BroadcastMatch && tPacket.MyType != PacketType.dhcp_answer)
|
if (BroadcastMatch && tPacket.MyType != PacketType.dhcp_answer)
|
||||||
@ -1517,50 +1517,60 @@ namespace EduNetworkBuilder
|
|||||||
if (tPacket.MyType == PacketType.ping_request)
|
if (tPacket.MyType == PacketType.ping_request)
|
||||||
{
|
{
|
||||||
myNet.RegisterTimeOfArrival();
|
myNet.RegisterTimeOfArrival();
|
||||||
nPacket = new Packet(this,tPacket.sourceIP,"",PacketType.ping_answer);
|
bool isbroadcast = HasBroadcastAddress(tPacket);
|
||||||
nPacket.OriginalDestIP = tPacket.destIP;
|
if (!isbroadcast || (isbroadcast && HasLocalNic(tPacket.sourceIP)))
|
||||||
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 = new Packet(this, tPacket.sourceIP, "", PacketType.ping_answer);
|
||||||
nPacket.TsourceIP = tPacket.destIP;
|
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
|
else
|
||||||
{
|
{
|
||||||
nPacket.sourceIP = new IPAddress(NB.ZeroIPString);
|
tPacket.AddMessage(DebugLevel.info, "The broadcast ping reached a destination that was not on the same network");
|
||||||
nPacket.TsourceIP = new IPAddress(NB.ZeroIPString);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (tPacket.MyType == PacketType.ping_answer)
|
if (tPacket.MyType == PacketType.ping_answer)
|
||||||
@ -2571,5 +2581,14 @@ namespace EduNetworkBuilder
|
|||||||
}
|
}
|
||||||
return false;
|
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