traceroute works, at least rudimentarily

This commit is contained in:
Tim Young 2017-03-13 14:04:02 +03:00
parent 1ebf932edb
commit 9e33a6f392
6 changed files with 88 additions and 10 deletions

View File

@ -252,6 +252,7 @@ namespace EduNetworkBuilder
public static UInt32 ParseIp(this string ipAddress) public static UInt32 ParseIp(this string ipAddress)
{ {
if (ipAddress == null) ipAddress = "";
var gw = ipAddress.Split('/'); //Pull off any cdr var gw = ipAddress.Split('/'); //Pull off any cdr
var mySplitVal = gw[0].Split('.'); var mySplitVal = gw[0].Split('.');
if (mySplitVal.Count() != 4) if (mySplitVal.Count() != 4)

View File

@ -1053,6 +1053,15 @@ namespace EduNetworkBuilder
return; //exit early. Rest is done in tick return; //exit early. Rest is done in tick
} }
public void ResetPacketTimeout()
{
//We should only do this when we know we are starting new packets.
//Traceroute does this when resetting
AlreadyChosenTimeout = false; //we do this at the beginning of processing
NumberOfSecondsForTimeout = DefaultTimeout;
NetworkStartTime = DateTime.Now;
}
public void Tick() public void Tick()
{ {
EraseOldPackets(); EraseOldPackets();
@ -1069,7 +1078,7 @@ namespace EduNetworkBuilder
ProcessPacketsOnce(); ProcessPacketsOnce();
if(!ProcessingShouldContinue()) if(!ProcessingShouldContinue())
{ {
//We it has all been taken care of //It has all been taken care of
} }
DrawPackets(); DrawPackets();
//myPBox.Refresh(); //myPBox.Refresh();

View File

@ -823,9 +823,9 @@ namespace EduNetworkBuilder
todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Traceroute")); todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Traceroute"));
if (todo) if (todo)
{ {
//ItemClickedOn.PingFromHere(destination); ItemClickedOn.TracerouteFromHere(destination);
//myNetwork.ProcessPackets(); myNetwork.ProcessPackets();
//UpdateMessages(); UpdateMessages();
} }
} }

View File

@ -1279,11 +1279,10 @@ namespace EduNetworkBuilder
public void TracerouteFromHere(IPAddress Destination) public void TracerouteFromHere(IPAddress Destination)
{ {
//We need to create a packet //We need to create a traceroute packet - start with 1 TTL
Packet TracertPacket = new Packet(this, Destination, NB.Translate("_Traceroute"), PacketType.tracert_request, -1, 1); //We pass it the destination as the payload string, so we have that for all traceroutes.
Packet TracertPacket = new Packet(this, Destination, Destination.GetIPString, PacketType.tracert_request, -1, 1);
Network myNet = NB.GetNetwork(); Network myNet = NB.GetNetwork();
//string dHost = myNet.ReverseDNSLookup(this, Destination);
//myNet.RegisterPingTest(hostname, dHost);
myNet.addPacket(TracertPacket); myNet.addPacket(TracertPacket);
} }
@ -1821,6 +1820,28 @@ namespace EduNetworkBuilder
} }
return; return;
} }
//Tracert_request is processed on the link arrivak
if (tPacket.MyType == PacketType.tracert_reply)
{
//The reply got here. This packet is done
tPacket.AddMessage(DebugLevel.info, NB.Translate("ND_ProcessArrival_TracertReply") + " " + tPacket.sourceIP.GetIPString);
tPacket.Tracking.Status = NB.LeftPad(hostname) + " " + string.Format(NB.Translate("ND_ProcessArrival_TracertReply") + " " + tPacket.sourceIP.GetIPString);
tPacket.MyStatus = PacketStatus.finished_ok;
IPAddress origStart = new IPAddress(tPacket.payloadData);
int ttl = tPacket.OrigTTL + 1;
Console.WriteLine("Tracert: " + tPacket.OrigTTL + " " + tPacket.sourceIP.GetIPString);
Console.WriteLine("Tracert: -- " + tPacket.sourceIP.GetIPString + " " + origStart.GetIPString);
//If we had not landed on the actual dest...
if (tPacket.sourceIP.GetIPString != origStart.GetIPString && ttl < 10)
{
Packet trPacket = new Packet(this, origStart, origStart.GetIPString, PacketType.tracert_request, -1, ttl);
myNet.addPacket(trPacket);
myNet.ResetPacketTimeout();
}
return;
}
if (tPacket.MyType == PacketType.arp_request) if (tPacket.MyType == PacketType.arp_request)
{ {
//The arp request may not be asking for this IP. //The arp request may not be asking for this IP.
@ -2478,6 +2499,38 @@ namespace EduNetworkBuilder
if (!ForwardsPackets()) if (!ForwardsPackets())
{ {
//Traceroute bounce-back
if(tPacket.MyType == PacketType.tracert_request)
{
tPacket.TTL--;
//If it is a router, or this is the destination
if(tPacket.TTL < 1 && (RoutesPackets() || HasMac(tPacket.destMAC)))
{
//The packet reached the end of its ttl. Bounce back.
//this packet ends, another begins.
Network myNet = NB.GetNetwork();
//We create a new packet
Packet nPacket = new Packet(this, tPacket.sourceIP, tPacket.payloadData, PacketType.tracert_reply, tPacket.packetID);
nPacket.OrigTTL = tPacket.OrigTTL;
nPacket.OriginalDestIP = tPacket.destIP;
nPacket.isFresh = true; //So it starts from here
nPacket.Tracking = new PacketMessage();
//The original packet stops here
tPacket.AddMessage(DebugLevel.info, NB.Translate("ND_ProcessArrival_TracerouteArrived") + " " + hostname);
tPacket.Tracking.Status = NB.LeftPad(hostname) + " Traceroute: " + NB.Translate("ND_ProcessArrival_TracerouteArrived") + " "+ hostname;
tPacket.MyStatus = PacketStatus.finished_ok;
Console.WriteLine(" Tracert bounce: " + tPacket.OrigTTL + " " + hostname + " " + tPacket.payloadData);
//Finish setting up the new packet - sending it back
nPacket.sourceIP = new IPAddress(NB.ZeroIPString);
nPacket.TsourceIP = new IPAddress(NB.ZeroIPString);
myNet.addPacket(nPacket);
Console.WriteLine(" Tracert bounce pkt:" + nPacket.OrigTTL + nPacket.payloadData);
}
}
if (tPacket.MyType == PacketType.dhcp_request && !isDHCPServer) if (tPacket.MyType == PacketType.dhcp_request && !isDHCPServer)
{ {
tPacket.AddMessage(DebugLevel.debug, NB.LeftPad(hostname) + " " +string.Format(NB.Translate("ND_DoInFromLnkDeaf"))); tPacket.AddMessage(DebugLevel.debug, NB.LeftPad(hostname) + " " +string.Format(NB.Translate("ND_DoInFromLnkDeaf")));

View File

@ -38,6 +38,7 @@ namespace EduNetworkBuilder
public int packetID; public int packetID;
public int VLANID = NB.UntaggedVLAN; //starts on the management vlan public int VLANID = NB.UntaggedVLAN; //starts on the management vlan
public int TTL = 20; public int TTL = 20;
public int OrigTTL = 20; //The original TTL. We need to know what we started with so we can pass it back on a traceroute
public int TickTTL = 50; public int TickTTL = 50;
public int health = 100; public int health = 100;
public IPAddress sourceIP; public IPAddress sourceIP;
@ -95,6 +96,7 @@ namespace EduNetworkBuilder
{ {
MyType = copyfrom.MyType; MyType = copyfrom.MyType;
TTL = copyfrom.TTL; TTL = copyfrom.TTL;
OrigTTL = copyfrom.OrigTTL;
sourceIP = copyfrom.sourceIP; sourceIP = copyfrom.sourceIP;
TsourceIP = copyfrom.TsourceIP; TsourceIP = copyfrom.TsourceIP;
destIP = copyfrom.destIP; destIP = copyfrom.destIP;
@ -126,6 +128,7 @@ namespace EduNetworkBuilder
packetID = NewPacketID; packetID = NewPacketID;
} }
if (startTTL != -1) this.TTL = startTTL; if (startTTL != -1) this.TTL = startTTL;
OrigTTL = TTL;
WhereAmI = start; WhereAmI = start;
payloadData = payload; payloadData = payload;
MyType = theType; MyType = theType;
@ -170,7 +173,7 @@ namespace EduNetworkBuilder
} }
if (startTTL != -1) this.TTL = startTTL; if (startTTL != -1) this.TTL = startTTL;
OrigTTL = TTL;
if (theType != PacketType.arp_answer && theType != PacketType.arp_request) if (theType != PacketType.arp_answer && theType != PacketType.arp_request)
{ {
@ -228,6 +231,10 @@ namespace EduNetworkBuilder
case PacketType.ping_request: case PacketType.ping_request:
pencolor = Color.Blue; pencolor = Color.Blue;
break; break;
case PacketType.tracert_reply:
case PacketType.tracert_request:
pencolor = Color.LightBlue;
break;
case PacketType.tun_packet: case PacketType.tun_packet:
pencolor = Color.White; pencolor = Color.White;
break; break;

View File

@ -1657,6 +1657,14 @@
<value>Device cannot respond - Packet Failed</value> <value>Device cannot respond - Packet Failed</value>
<comment>ND_DoInputFromLink_PowerOff = Device cannot respond - Packet Failed</comment> <comment>ND_DoInputFromLink_PowerOff = Device cannot respond - Packet Failed</comment>
</data> </data>
<data name="ND_ProcessArrival_TracerouteArrived" xml:space="preserve">
<value>TTL reached.</value>
<comment>ND_ProcessArrival_TracerouteArrived = TTL reached.</comment>
</data>
<data name="ND_ProcessArrival_TracertReply" xml:space="preserve">
<value>Traceroute Destination Reached</value>
<comment>ND_ProcessArrival_TracertReply = Traceroute Destination Reached</comment>
</data>
<data name="_Traceroute" xml:space="preserve"> <data name="_Traceroute" xml:space="preserve">
<value>Traceroute</value> <value>Traceroute</value>
<comment>_Traceroute = Traceroute</comment> <comment>_Traceroute = Traceroute</comment>