Network Card using NB_IPAddress functions. We can change these functions to work with ipv6 later. Move our comparisons to these funcs.

This commit is contained in:
Tim Young 2020-12-08 15:22:24 -07:00
parent f34b9a405e
commit 49151e7c55
2 changed files with 15 additions and 14 deletions

View File

@ -341,7 +341,8 @@ namespace EduNetworkBuilder
public bool IsBroadcast() public bool IsBroadcast()
{ {
uint BA = BroadcastAddress; uint BA = BroadcastAddress;
if (_ip == BA) return true; if (_ip == BA) return true; //the actual broadcast for the network
if (GetIPString == NB.BroadcastIPString) return true; //The special broadcast 255.255.255.255
return false; return false;
} }

View File

@ -45,7 +45,7 @@ namespace EduNetworkBuilder
myID = new HostNicID(HostID, UniqueIdentifier, hostname, _nic_name); myID = new HostNicID(HostID, UniqueIdentifier, hostname, _nic_name);
NetworkInterface nInterface = new NetworkInterface(NicName(), NB.ZeroIPString, NB.ZeroIPString, myID); NetworkInterface nInterface = new NetworkInterface(NicName(), NB.ZeroIPString, NB.ZeroIPString, myID);
if(theType == NicType.lo) if(theType == NicType.lo)
nInterface = new NetworkInterface(NicName(), "127.0.0.1", "255.0.0.0", myID); nInterface = new NetworkInterface(NicName(), NB.LoopbackIPString, "255.0.0.0", myID);
interfaces.Add(nInterface); interfaces.Add(nInterface);
ApplyNicRules(); ApplyNicRules();
SetIPForDHCP(); SetIPForDHCP();
@ -313,7 +313,7 @@ namespace EduNetworkBuilder
if (iface.myIP.BroadcastAddress == 0) continue; //a netmask of 0.0.0.0 causes grief if (iface.myIP.BroadcastAddress == 0) continue; //a netmask of 0.0.0.0 causes grief
if (iface.myIP.BroadcastAddress == dest.GetIP) if (iface.myIP.BroadcastAddress == dest.GetIP)
return true;//If they are pinging the broadcast IP return true;//If they are pinging the broadcast IP
if (iface.myIP.GetIPString == NB.BroadcastIPString) if (iface.myIP.IsBroadcast())
return true; return true;
} }
return false; return false;
@ -435,7 +435,7 @@ namespace EduNetworkBuilder
if (UsesDHCP && CanUseDHCP) if (UsesDHCP && CanUseDHCP)
{ {
bool doIt = true; bool doIt = true;
if (interfaces.Count > 0 && interfaces[0].myIP.GetIPString == NB.ZeroIPString) if (interfaces.Count > 0 && interfaces[0].myIP.IsZeroString())
{ {
doIt = true; doIt = true;
} }
@ -568,15 +568,15 @@ namespace EduNetworkBuilder
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)
continue; //If the packet cannot be sent out (VLAN stuff) continue; //If the packet cannot be sent out (VLAN stuff)
if (tPacket.OutboundIP == null || (nf.isLocal(tPacket.OutboundIP) || (tPacket.OutboundIP.GetIPString == NB.BroadcastIPString && tPacket.isFresh))) if (tPacket.OutboundIP == null || (nf.isLocal(tPacket.OutboundIP) || (tPacket.OutboundIP.IsBroadcast() && tPacket.isFresh)))
{ {
if ((nf != null && nf.myIP.GetIPString != NB.ZeroIPString) || nPacket.MyType == PacketType.dhcp_request) if ((nf != null && !nf.myIP.IsZeroString()) || nPacket.MyType == PacketType.dhcp_request)
{ {
//this means we have a local interface to send it out of //this means we have a local interface to send it out of
//if(nPacket.sourceMAC == null || nPacket.sourceMAC == "" || nPacket.isFresh) //if(nPacket.sourceMAC == null || nPacket.sourceMAC == "" || nPacket.isFresh)
nPacket.sourceMAC = MAC; nPacket.sourceMAC = MAC;
//If the source IP is empty then it is a new packet. We set the source to be us //If the source IP is empty then it is a new packet. We set the source to be us
if (nPacket.sourceIP == null || nPacket.sourceIP.GetIPString == NB.ZeroIPString) if (nPacket.sourceIP == null || nPacket.sourceIP.IsZeroString())
nPacket.sourceIP = nf.myIP; nPacket.sourceIP = nf.myIP;
nPacket.TsourceIP = nf.myIP; nPacket.TsourceIP = nf.myIP;
if (nPacket.destMAC == null || nPacket.destMAC == "") if (nPacket.destMAC == null || nPacket.destMAC == "")
@ -627,14 +627,14 @@ namespace EduNetworkBuilder
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)
continue; //If the packet cannot be sent out (VLAN stuff) continue; //If the packet cannot be sent out (VLAN stuff)
if (tPacket.OutboundIP != null && (nf.isLocal(tPacket.OutboundIP) || tPacket.OutboundIP.GetIPString == NB.BroadcastIPString)) if (tPacket.OutboundIP != null && (nf.isLocal(tPacket.OutboundIP) || tPacket.OutboundIP.IsBroadcast()))
{ {
if ((nf != null && nf.myIP != null && nf.myIP.GetIPString != NB.ZeroIPString) || nPacket.MyType == PacketType.dhcp_request) if ((nf != null && nf.myIP != null && !nf.myIP.IsZeroString()) || nPacket.MyType == PacketType.dhcp_request)
{ {
//this means we have a local interface to send it out of //this means we have a local interface to send it out of
nPacket.sourceMAC = MAC; nPacket.sourceMAC = MAC;
//If the source IP is empty then it originated from here. We set the source to be us //If the source IP is empty then it originated from here. We set the source to be us
if (nPacket.sourceIP == null || nPacket.sourceIP.GetIPString == NB.ZeroIPString) if (nPacket.sourceIP == null || nPacket.sourceIP.IsZeroString())
{ {
nPacket.sourceIP = nf.myIP; nPacket.sourceIP = nf.myIP;
WhereFrom.StoreOutgoingPacketInfo(nPacket); //the packet is not masqueraded, just accepted WhereFrom.StoreOutgoingPacketInfo(nPacket); //the packet is not masqueraded, just accepted
@ -701,10 +701,10 @@ namespace EduNetworkBuilder
} }
} }
} }
if (nf != null && nf.myIP != null && nf.myIP.GetIPString != NB.ZeroIPString) if (nf != null && nf.myIP != null && !nf.myIP.IsZeroString())
{ {
//If the source IP is empty then it originated from here. We set the source to be us //If the source IP is empty then it originated from here. We set the source to be us
if (tPacket.sourceIP == null || tPacket.sourceIP.GetIPString == NB.ZeroIPString) if (tPacket.sourceIP == null || tPacket.sourceIP.IsZeroString())
{ {
tPacket.sourceIP = nf.myIP; tPacket.sourceIP = nf.myIP;
WhereFrom.StoreOutgoingPacketInfo(tPacket); //the packet is not yet tunneled WhereFrom.StoreOutgoingPacketInfo(tPacket); //the packet is not yet tunneled
@ -785,7 +785,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) if ((nPacket.sourceIP == null || nPacket.sourceIP.IsZeroString()) && 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();
@ -800,7 +800,7 @@ namespace EduNetworkBuilder
nl = myNet.GetLinkFromID(ConnectedLink); nl = myNet.GetLinkFromID(ConnectedLink);
if (nl == null) if (nl == null)
break; break;
if ((nPacket.sourceIP == null || nPacket.sourceIP.GetIPString == NB.ZeroIPString) && tPacket.MyType != PacketType.dhcp_request) return false; //We still have no IP. Do not send the packet out. if ((nPacket.sourceIP == null || nPacket.sourceIP.IsZeroString()) && tPacket.MyType != PacketType.dhcp_request) return false; //We still have no IP. Do not send the packet out.
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)