Fixed bug with network loop puzzle. That caused issues with tSourceIP. Needed to set tSourceIP when forwarding / routing, and coming out of a VPN

This commit is contained in:
Tim Young 2016-12-10 16:47:14 -08:00
parent 2094f7fac4
commit 52c7ab63e2
9 changed files with 69 additions and 27 deletions

View File

@ -185,7 +185,7 @@
this.lbArpTable.ItemHeight = 17; this.lbArpTable.ItemHeight = 17;
this.lbArpTable.Location = new System.Drawing.Point(15, 269); this.lbArpTable.Location = new System.Drawing.Point(15, 269);
this.lbArpTable.Name = "lbArpTable"; this.lbArpTable.Name = "lbArpTable";
this.lbArpTable.Size = new System.Drawing.Size(326, 89); this.lbArpTable.Size = new System.Drawing.Size(349, 89);
this.lbArpTable.TabIndex = 13; this.lbArpTable.TabIndex = 13;
// //
// btnGateway // btnGateway

View File

@ -211,10 +211,10 @@ namespace EduNetworkBuilder
} }
lbArpTable.Items.Clear(); lbArpTable.Items.Clear();
lbArpTable.Items.Add("Arp Table MAC\tIPAddress"); lbArpTable.Items.Add("Arp Table MAC\tIPAddress\tIF");
foreach(ArpEntry ae in ndCLonedItem.GetArps()) foreach(ArpEntry ae in ndCLonedItem.GetArps())
{ {
lbArpTable.Items.Add(ae.MACAddress + "\t" + ae.IPAddr); lbArpTable.Items.Add(ae.MACAddress + "\t" + ae.IPAddr + "\t" + ae.NicOnWhichItIsFound.NicName);
} }
//The IP Addresses for the given nic //The IP Addresses for the given nic

View File

@ -57,10 +57,10 @@
<ApplicationIcon>Resources\NBIco.ico</ApplicationIcon> <ApplicationIcon>Resources\NBIco.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ManifestCertificateThumbprint>FC016CC0B0D70B0A6ABDABD9CDB267055A8FCCA3</ManifestCertificateThumbprint> <ManifestCertificateThumbprint>B9F30C1A5500E918477D84AE79FD91D601D3860E</ManifestCertificateThumbprint>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ManifestKeyFile>EduNetworkBuilder_1_TemporaryKey.pfx</ManifestKeyFile> <ManifestKeyFile>EduNetworkBuilder_2_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<GenerateManifests>true</GenerateManifests> <GenerateManifests>true</GenerateManifests>
@ -214,6 +214,7 @@
<DependentUpon>VLANConfig.cs</DependentUpon> <DependentUpon>VLANConfig.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<None Include="EduNetworkBuilder_1_TemporaryKey.pfx" /> <None Include="EduNetworkBuilder_1_TemporaryKey.pfx" />
<None Include="EduNetworkBuilder_2_TemporaryKey.pfx" />
<None Include="EduNetworkBuilder_TemporaryKey.pfx" /> <None Include="EduNetworkBuilder_TemporaryKey.pfx" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>

View File

@ -294,6 +294,7 @@ namespace EduNetworkBuilder
public static int WirelessMaxSuccessfulLink = 100; //Packets will drop after this distance public static int WirelessMaxSuccessfulLink = 100; //Packets will drop after this distance
public static int WirelessReconnectDistance = 70; //Try to find a closer AP if we are this far out. public static int WirelessReconnectDistance = 70; //Try to find a closer AP if we are this far out.
public static int UntaggedVLAN = -1; //If the packet is not tagged. public static int UntaggedVLAN = -1; //If the packet is not tagged.
public static int MaxPacketsBeforeOptimizing = 50;
/// <summary> /// <summary>
/// Find the global random number generator. /// Find the global random number generator.

View File

@ -941,8 +941,29 @@ namespace EduNetworkBuilder
public void addPacket(Packet toadd) public void addPacket(Packet toadd)
{ {
if(toadd != null && !myPackets.Contains(toadd)) if (toadd != null && !myPackets.Contains(toadd))
myPackets.Add(toadd); {
if (myPackets.Count > NB.MaxPacketsBeforeOptimizing)
{
bool foundit = false;
foreach(Packet pkt in myPackets)
{
if(pkt.MyType == toadd.MyType && pkt.WhereAmI == toadd.WhereAmI &&
(pkt.sourceIP != null && pkt.sourceIP.Equals(toadd.sourceIP)) &&
(pkt.destIP != null && pkt.destIP.Equals(toadd.destIP)))
{
foundit = true;
break;
}
}
if (!foundit)
myPackets.Add(toadd);
}
else
{
myPackets.Add(toadd);
}
}
} }
public int CountPackets(PacketType WhatType) public int CountPackets(PacketType WhatType)

View File

@ -464,8 +464,8 @@ namespace EduNetworkBuilder
case NicType.eth: case NicType.eth:
case NicType.wlan: case NicType.wlan:
//see if it the packet dest is local to this nic //see if it the packet dest is local to this nic
if (tPacket.MyType == PacketType.dhcp_answer) //if (tPacket.MyType == PacketType.dhcp_answer)
Console.WriteLine("DHCP Answer"); // Console.WriteLine("DHCP Answer");
foreach (NetworkInterface nf in interfaces.ToList()) foreach (NetworkInterface nf in interfaces.ToList())
{ {
if (tPacket.InboundNic != null && tPacket.InboundNic == this && if (tPacket.InboundNic != null && tPacket.InboundNic == this &&
@ -477,6 +477,8 @@ namespace EduNetworkBuilder
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
nPacket.OutboundIF = nf; nPacket.OutboundIF = nf;
if(nf != null)
nPacket.TsourceIP = nf.myIP;
nPacket.InboundInterface = tPacket.InboundInterface; nPacket.InboundInterface = tPacket.InboundInterface;
nf.ProcessOutboundPacket(nPacket); nf.ProcessOutboundPacket(nPacket);
if (nPacket.MyStatus == PacketStatus.finished || nPacket.MyStatus == PacketStatus.finished_failed || nPacket.MyStatus == PacketStatus.finished_ok) if (nPacket.MyStatus == PacketStatus.finished || nPacket.MyStatus == PacketStatus.finished_failed || nPacket.MyStatus == PacketStatus.finished_ok)
@ -532,6 +534,8 @@ namespace EduNetworkBuilder
nPacket = new Packet(tPacket);//Creates a new packet but sets isfresh=false nPacket = new Packet(tPacket);//Creates a new packet but sets isfresh=false
nPacket.OutboundIF = nf; nPacket.OutboundIF = nf;
nPacket.InboundInterface = tPacket.InboundInterface; nPacket.InboundInterface = tPacket.InboundInterface;
if (nf != null)
nPacket.TsourceIP = nf.myIP;
nf.ProcessOutboundPacket(nPacket); nf.ProcessOutboundPacket(nPacket);
if (nPacket.MyStatus == PacketStatus.finished || nPacket.MyStatus == PacketStatus.finished_failed || nPacket.MyStatus == PacketStatus.finished_ok) if (nPacket.MyStatus == PacketStatus.finished || nPacket.MyStatus == PacketStatus.finished_failed || nPacket.MyStatus == PacketStatus.finished_ok)
@ -595,6 +599,8 @@ namespace EduNetworkBuilder
tPacket.MyStatus = PacketStatus.encapsulated; tPacket.MyStatus = PacketStatus.encapsulated;
tPacket.TsourceIP = nf.myIP; tPacket.TsourceIP = nf.myIP;
tPacket.destMAC = WhereFrom.LookupArpFromIP(tPacket.OutboundIP.GetIPString); tPacket.destMAC = WhereFrom.LookupArpFromIP(tPacket.OutboundIP.GetIPString);
if (nf != null)
tPacket.TsourceIP = nf.myIP;
//We need to make a new, tunnel packet //We need to make a new, tunnel packet
if (myNicType == NicType.tun) if (myNicType == NicType.tun)
@ -672,7 +678,8 @@ namespace EduNetworkBuilder
if (nPacket.TsourceIP == null) if (nPacket.TsourceIP == null)
nPacket.TsourceIP = WhereFrom.HubManagementIP(); nPacket.TsourceIP = WhereFrom.HubManagementIP();
nl = myNet.GetLinkFromID(ConnectedLink); nl = myNet.GetLinkFromID(ConnectedLink);
if (nl == null) break; if (nl == null)
break;
nPacket.StartOnLink(nl, WhereFrom); //This sends the packet down the link. nPacket.StartOnLink(nl, WhereFrom); //This sends the packet down the link.
myNet.addPacket(nPacket); myNet.addPacket(nPacket);
if (tPacket.isFresh) if (tPacket.isFresh)

View File

@ -1348,13 +1348,6 @@ namespace EduNetworkBuilder
if (tPacket.TsourceIP != null && !tPacket.TsourceIP.IsLocal(tPacket.destIP) && !HasBroadcastAddress(tPacket.destIP)) return ResponseToPacket.none; if (tPacket.TsourceIP != null && !tPacket.TsourceIP.IsLocal(tPacket.destIP) && !HasBroadcastAddress(tPacket.destIP)) return ResponseToPacket.none;
foreach(IPConnectionEntry ipc in IPConnections) foreach(IPConnectionEntry ipc in IPConnections)
{ {
if(ipc.What == PacketType.dhcp_request)
{
//Console.WriteLine(NB.LeftPad(hostname) + ": packet=" + tPacket.MyType.ToString());
//Console.WriteLine(" " + NB.LeftPad(hostname) + ": d:" + ipc.destIP.GetIPString + " s:" + tPacket.sourceIP.GetIPString);
//if (HasBroadcastAddress(ipc.destIP))
// Console.WriteLine(" Broadcast");
}
if (ipc.destIP.GetIP == tPacket.sourceIP.GetIP || HasBroadcastAddress(ipc.destIP)) if (ipc.destIP.GetIP == tPacket.sourceIP.GetIP || HasBroadcastAddress(ipc.destIP))
{ {
if (ipc.What == PacketType.arp_request && tPacket.MyType == PacketType.arp_answer) if (ipc.What == PacketType.arp_request && tPacket.MyType == PacketType.arp_answer)
@ -1444,15 +1437,16 @@ namespace EduNetworkBuilder
bool MacAddressMatch = HasMac(tPacket.destMAC); bool MacAddressMatch = HasMac(tPacket.destMAC);
//It is an exact match if it is coming from a local source. //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 HasIp = HasIPAddress(tPacket.destIP);
bool ExactMatch = HasIp && (tPacket.TsourceIP == null || tPacket.TsourceIP.IsLocal(tPacket.destIP));
bool LocalMatch = LocalMatches(tPacket); bool LocalMatch = LocalMatches(tPacket);
bool BroadcastMatch = HasBroadcastAddress(tPacket.destIP); bool BroadcastMatch = HasBroadcastAddress(tPacket.destIP);
bool NeedsRouting = MacAddressMatch && (!ExactMatch && !BroadcastMatch); bool NeedsRouting = MacAddressMatch && (!ExactMatch && !BroadcastMatch);
if(ExactMatch || BroadcastMatch || LocalMatch) if(ExactMatch || BroadcastMatch || LocalMatch)
{ {
//Change this. Need a new ProcessArrival //Change this. Need a new ProcessArrival
if(tPacket.MyType != PacketType.dhcp_answer) //If it is a match, it should be handled elsewhere if (tPacket.MyType != PacketType.dhcp_answer) //If it is a match, it should be handled elsewhere
ProcessArrival(tPacket); ProcessArrival(tPacket);
if (ExactMatch && tPacket.isFinshed()) if (ExactMatch && tPacket.isFinshed())
return; return;
@ -1483,15 +1477,18 @@ namespace EduNetworkBuilder
{ {
//It is a local packet. Let it go out the interface it needs to go out //It is a local packet. Let it go out the interface it needs to go out
tPacket.OutboundIP = tPacket.destIP; tPacket.OutboundIP = tPacket.destIP;
tPacket.TsourceIP = null;
} }
else if(tPacket.destIP.GetIPString != NB.BroadcastIPString) else if(tPacket.destIP.GetIPString != NB.BroadcastIPString)
{ {
//it needs to go to a gateway. Set the next destination is the GW //it needs to go to a gateway. Set the next destination is the GW
tPacket.OutboundIP = dest; tPacket.OutboundIP = dest;
tPacket.TsourceIP = null;
} }
else else
{ {
tPacket.OutboundIP = tPacket.destIP; tPacket.OutboundIP = tPacket.destIP;
tPacket.TsourceIP = null;
} }
} }
@ -1508,6 +1505,7 @@ namespace EduNetworkBuilder
if (arp.MACAddress == tPacket.destMAC) if (arp.MACAddress == tPacket.destMAC)
{ {
dNic = NicFromID(arp.NicOnWhichItIsFound); dNic = NicFromID(arp.NicOnWhichItIsFound);
break;
} }
//if (arp.MACAddress == tPacket.sourceMAC) //if (arp.MACAddress == tPacket.sourceMAC)
//{ //{
@ -1529,7 +1527,7 @@ namespace EduNetworkBuilder
// Resume processing at the nic level, not the device level when the arp comes back // Resume processing at the nic level, not the device level when the arp comes back
int count = 0; int count = 0;
bool PacketSentOutWAN = false; bool PacketSentOutWAN = false;
foreach(NetworkCard nic in NICs) foreach (NetworkCard nic in NICs)
{ {
NicType NT = nic.GetNicType; NicType NT = nic.GetNicType;
//bridges and waps are basically switches //bridges and waps are basically switches
@ -1579,7 +1577,9 @@ namespace EduNetworkBuilder
case NicType.port: case NicType.port:
case NicType.wport: case NicType.wport:
if (PacketSentOutWAN) if (PacketSentOutWAN)
{
continue; //do not send packets out of ports if they have been sent out a WAN nic continue; //do not send packets out of ports if they have been sent out a WAN nic
}
NetworkCard tdNic = dNic; NetworkCard tdNic = dNic;
if (myType == NetworkComponentType.wrouter) if (myType == NetworkComponentType.wrouter)
{ {
@ -1660,6 +1660,7 @@ namespace EduNetworkBuilder
tPacket.MyStatus = PacketStatus.finished_ok; //It stops here tPacket.MyStatus = PacketStatus.finished_ok; //It stops here
nPacket = tPacket.payloadPacket; nPacket = tPacket.payloadPacket;
NetworkCard nc = LocalNic(nPacket.TsourceIP, true); NetworkCard nc = LocalNic(nPacket.TsourceIP, true);
nPacket.TsourceIP = null;
if (nc != null) if (nc != null)
{ {
if (nPacket != null) if (nPacket != null)
@ -2471,6 +2472,7 @@ namespace EduNetworkBuilder
return; return;
} }
} }
if (!ForwardsPackets()) if (!ForwardsPackets())
{ {
if (tPacket.MyType == PacketType.dhcp_request && !isDHCPServer) if (tPacket.MyType == PacketType.dhcp_request && !isDHCPServer)
@ -2872,8 +2874,10 @@ namespace EduNetworkBuilder
{ {
if(fwr.Source == inIF && fwr.Destination == outIF) if(fwr.Source == inIF && fwr.Destination == outIF)
{ {
if (fwr.Action == FirewallRuleType.Allow) return true; if (fwr.Action == FirewallRuleType.Allow)
if (fwr.Action == FirewallRuleType.Drop) return false; return true;
if (fwr.Action == FirewallRuleType.Drop)
return false;
} }
} }
return true; return true;

View File

@ -203,6 +203,13 @@ namespace EduNetworkBuilder
NetworkDevice HD = theNet.GetDeviceFromID(AttachedToHostNic); NetworkDevice HD = theNet.GetDeviceFromID(AttachedToHostNic);
if (HD == null) return; //Oops! Something went wrong. if (HD == null) return; //Oops! Something went wrong.
string hostname = HD.hostname; string hostname = HD.hostname;
//added to fix the issue with vpns and pings - 11-09-2016
//Only do this on non-ports?
NetworkCard nic = HD.NicFromID(AttachedToHostNic);
if(nic != null && nic.GetNicType != NicType.port && nic.GetNicType != NicType.wport)
tPacket.TsourceIP = myIP;
if(tPacket.TsourceIP == null || tPacket.TsourceIP.GetIPString == NB.ZeroIPString)
tPacket.TsourceIP = myIP;
if (What == VLANTagType.Forbidden) if (What == VLANTagType.Forbidden)
{ {
@ -224,8 +231,6 @@ namespace EduNetworkBuilder
//We actually do not do anything. The tag remains intact. //We actually do not do anything. The tag remains intact.
tPacket.VLANID = VI.ID; tPacket.VLANID = VI.ID;
} }
//added to fix the issue with vpns and pings - 11-09-2016
tPacket.TsourceIP = myIP;
} }
private VLANInfo IncomingVLAN(int ID) private VLANInfo IncomingVLAN(int ID)
@ -324,6 +329,9 @@ namespace EduNetworkBuilder
if (tPacket.destIP != null && myIP.IsLocal(tPacket.destIP)) isgood = true; if (tPacket.destIP != null && myIP.IsLocal(tPacket.destIP)) isgood = true;
if (myIP.NetworkAddress == myIP.GetIP) isgood = true; if (myIP.NetworkAddress == myIP.GetIP) isgood = true;
Network MyNet = NB.GetNetwork();
NetworkDevice ND = MyNet.GetDeviceFromID(AttachedToHostNic);
tPacket.InboundInterface = this; tPacket.InboundInterface = this;
if(isgood) if(isgood)

View File

@ -42,7 +42,7 @@ namespace EduNetworkBuilder
public int health = 100; public int health = 100;
public IPAddress sourceIP; public IPAddress sourceIP;
public IPAddress OriginalDestIP; public IPAddress OriginalDestIP;
public IPAddress TsourceIP; public IPAddress TsourceIP; //This is the local link source ip. It should go along with the local MAC address
public IPAddress destIP; public IPAddress destIP;
public string sourceMAC; public string sourceMAC;
public string destMAC; public string destMAC;