More vlan progress
This commit is contained in:
parent
e4c9a38404
commit
3632432f02
@ -265,9 +265,37 @@ namespace EduNetworkBuilder
|
|||||||
return; //We cannot delete the sole remaining interface
|
return; //We cannot delete the sole remaining interface
|
||||||
interfaces.RemoveAt(index);
|
interfaces.RemoveAt(index);
|
||||||
}
|
}
|
||||||
|
private int NextInterfaceNum()
|
||||||
|
{
|
||||||
|
string NICName = NicName();
|
||||||
|
string testname = "";
|
||||||
|
bool foundone = true;
|
||||||
|
int which = 0;
|
||||||
|
while(foundone)
|
||||||
|
{
|
||||||
|
foundone = false;
|
||||||
|
testname = NICName;
|
||||||
|
if (which != 0)
|
||||||
|
testname = testname + ":" + which.ToString();
|
||||||
|
foreach(NetworkInterface oneif in interfaces)
|
||||||
|
{
|
||||||
|
if(oneif.nic_name == testname)
|
||||||
|
{
|
||||||
|
foundone = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (foundone)
|
||||||
|
which++;
|
||||||
|
}
|
||||||
|
return which;
|
||||||
|
}
|
||||||
public void AddInterface()
|
public void AddInterface()
|
||||||
{
|
{
|
||||||
NetworkInterface iface = new NetworkInterface(NicName(), NB.ZeroIPString, NB.ZeroIPString, myID);
|
string NICName = NicName();
|
||||||
|
int Plus = NextInterfaceNum();
|
||||||
|
if (Plus != 0) NICName += ":"+Plus.ToString();
|
||||||
|
NetworkInterface iface = new NetworkInterface(NICName, NB.ZeroIPString, NB.ZeroIPString, myID);
|
||||||
interfaces.Add(iface);
|
interfaces.Add(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,7 +406,11 @@ namespace EduNetworkBuilder
|
|||||||
/// <returns>null if no interface is local. Otherwise, it returns the one that matches the packet</returns>
|
/// <returns>null if no interface is local. Otherwise, it returns the one that matches the packet</returns>
|
||||||
public NetworkInterface LocalInterface(IPAddress theIP, PacketMessage Tracker)
|
public NetworkInterface LocalInterface(IPAddress theIP, PacketMessage Tracker)
|
||||||
{
|
{
|
||||||
if (myNicType == NicType.port) return null; //ports have no local interfaces
|
if (myNicType == NicType.port)
|
||||||
|
{
|
||||||
|
if (interfaces.Count == 1) return interfaces[0];
|
||||||
|
return null; //ports have no local interfaces
|
||||||
|
}
|
||||||
foreach (NetworkInterface nIF in interfaces)
|
foreach (NetworkInterface nIF in interfaces)
|
||||||
{
|
{
|
||||||
if (nIF.isLocal(theIP))
|
if (nIF.isLocal(theIP))
|
||||||
@ -431,6 +463,9 @@ 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
|
||||||
|
nf.ProcessOutboundPacket(nPacket);
|
||||||
|
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)
|
||||||
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.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)
|
||||||
@ -480,6 +515,10 @@ namespace EduNetworkBuilder
|
|||||||
foreach (NetworkInterface nf in interfaces.ToList())
|
foreach (NetworkInterface nf in interfaces.ToList())
|
||||||
{
|
{
|
||||||
nPacket = new Packet(tPacket);//Creates a new packet but sets isfresh=false
|
nPacket = new Packet(tPacket);//Creates a new packet but sets isfresh=false
|
||||||
|
nf.ProcessOutboundPacket(nPacket);
|
||||||
|
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)
|
||||||
|
|
||||||
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))
|
||||||
{
|
{
|
||||||
if ((nf != null && nf.myIP != null && nf.myIP.GetIPString != NB.ZeroIPString) || nPacket.MyType == PacketType.dhcp_request)
|
if ((nf != null && nf.myIP != null && nf.myIP.GetIPString != NB.ZeroIPString) || nPacket.MyType == PacketType.dhcp_request)
|
||||||
@ -553,17 +592,24 @@ namespace EduNetworkBuilder
|
|||||||
case NicType.wport:
|
case NicType.wport:
|
||||||
if (tPacket.InboundNic == this)
|
if (tPacket.InboundNic == this)
|
||||||
break; //This is the port we came in on. Do not sent it back out this port
|
break; //This is the port we came in on. Do not sent it back out this port
|
||||||
|
foreach (NetworkInterface nf in interfaces.ToList())
|
||||||
|
{
|
||||||
nPacket = new Packet(tPacket);
|
nPacket = new Packet(tPacket);
|
||||||
if((tPacket.InboundNic != null && tPacket.InboundNic.GetNicType == NicType.wan) || tPacket.InboundNic == null || tPacket.destMAC == "")
|
|
||||||
|
nf.ProcessOutboundPacket(nPacket);
|
||||||
|
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)
|
||||||
|
|
||||||
|
if ((tPacket.InboundNic != null && tPacket.InboundNic.GetNicType == NicType.wan) || tPacket.InboundNic == null || tPacket.destMAC == "")
|
||||||
{
|
{
|
||||||
//We need to find destination MAC and set source MAC
|
//We need to find destination MAC and set source MAC
|
||||||
if(nPacket.sourceMAC == null || nPacket.sourceMAC == "" || nPacket.isFresh)
|
if (nPacket.sourceMAC == null || nPacket.sourceMAC == "" || nPacket.isFresh)
|
||||||
nPacket.sourceMAC = MAC;
|
nPacket.sourceMAC = MAC;
|
||||||
//Update the MAC
|
//Update the MAC
|
||||||
string getMAC="";
|
string getMAC = "";
|
||||||
if (tPacket.OutboundIP != null)
|
if (tPacket.OutboundIP != null)
|
||||||
getMAC = WhereFrom.LookupArpFromIP(tPacket.OutboundIP.GetIPString);
|
getMAC = WhereFrom.LookupArpFromIP(tPacket.OutboundIP.GetIPString);
|
||||||
else if(tPacket.destIP != null)
|
else if (tPacket.destIP != null)
|
||||||
getMAC = WhereFrom.LookupArpFromIP(tPacket.destIP.GetIPString);
|
getMAC = WhereFrom.LookupArpFromIP(tPacket.destIP.GetIPString);
|
||||||
if (getMAC != "") nPacket.destMAC = getMAC;
|
if (getMAC != "") nPacket.destMAC = getMAC;
|
||||||
if (nPacket.MyType == PacketType.arp_request)
|
if (nPacket.MyType == PacketType.arp_request)
|
||||||
@ -593,7 +639,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.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();
|
||||||
@ -603,30 +649,23 @@ namespace EduNetworkBuilder
|
|||||||
{
|
{
|
||||||
nPacket.destMAC = WhereFrom.LookupArpFromIP(tPacket.OutboundIP.GetIPString);
|
nPacket.destMAC = WhereFrom.LookupArpFromIP(tPacket.OutboundIP.GetIPString);
|
||||||
}
|
}
|
||||||
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)
|
||||||
WhereFrom.StoreOutgoingPacketInfo(nPacket); //if it originated from here...
|
WhereFrom.StoreOutgoingPacketInfo(nPacket); //if it originated from here...
|
||||||
madeprogress = true;
|
madeprogress = true;
|
||||||
nPacket.PacketDump(myID.HostName, DebugPausePoint.packet_out);
|
nPacket.PacketDump(myID.HostName, DebugPausePoint.packet_out);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return madeprogress;
|
return madeprogress;
|
||||||
}
|
}
|
||||||
|
|
||||||
//********************Process Packet ********
|
|
||||||
public void ProcessOutboundPacket(Packet tPacket)
|
|
||||||
{
|
|
||||||
//We set the MAC addrss to this nic
|
|
||||||
tPacket.sourceMAC = MAC;
|
|
||||||
|
|
||||||
//If the nic has a special function, we need to do that too.
|
|
||||||
// VPN, etc
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ProcessInboundPacket(Packet tPacket)
|
public void ProcessInboundPacket(Packet tPacket)
|
||||||
{
|
{
|
||||||
|
@ -1078,6 +1078,10 @@ namespace EduNetworkBuilder
|
|||||||
return true;
|
return true;
|
||||||
if (myType == NetworkComponentType.wrouter)
|
if (myType == NetworkComponentType.wrouter)
|
||||||
return true;
|
return true;
|
||||||
|
if (myType == NetworkComponentType.firewall)
|
||||||
|
return true;
|
||||||
|
if (myType == NetworkComponentType.router)
|
||||||
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,12 +156,73 @@ namespace EduNetworkBuilder
|
|||||||
/// <param name="tPacket"></param>
|
/// <param name="tPacket"></param>
|
||||||
public void ProcessOutboundPacket(Packet tPacket)
|
public void ProcessOutboundPacket(Packet tPacket)
|
||||||
{
|
{
|
||||||
tPacket.InboundInterface = null; //forget the interface we had come in on now that we are leaving.
|
//tPacket.InboundInterface = null; //forget the interface we had come in on now that we are leaving.
|
||||||
if (tPacket.sourceIP == null || tPacket.sourceIP.GetIP.ToIpString() == NB.ZeroIPString)
|
//if (tPacket.sourceIP == null || tPacket.sourceIP.GetIP.ToIpString() == NB.ZeroIPString)
|
||||||
|
//{
|
||||||
|
// //This happens if we are starting a new packet. We should also do this if we are masquerading.
|
||||||
|
// tPacket.sourceIP = new IPAddress(myIP.GetIP.ToIpString(), "", IPAddressType.ip_only); //We only want the IP address
|
||||||
|
//}
|
||||||
|
//VLAN stuff
|
||||||
|
VLANInfo VI = GetVLANInfo(tPacket.VLANID);
|
||||||
|
VLANTagType What = VI.Tag;
|
||||||
|
Network theNet = NB.GetNetwork();
|
||||||
|
NetworkDevice HD = theNet.GetDeviceFromID(AttachedToHostNic);
|
||||||
|
string hostname = HD.hostname;
|
||||||
|
|
||||||
|
if (What == VLANTagType.Forbidden)
|
||||||
{
|
{
|
||||||
//This happens if we are starting a new packet. We should also do this if we are masquerading.
|
//we drop it silently
|
||||||
tPacket.sourceIP = new IPAddress(myIP.GetIP.ToIpString(), "", IPAddressType.ip_only); //We only want the IP address
|
string errString = string.Format(NB.Translate("NI_VLANOut"), hostname, tPacket.destIP.GetIPString);
|
||||||
|
tPacket.AddMessage(DebugLevel.switching, errString);
|
||||||
|
tPacket.Tracking.Status = errString;
|
||||||
|
tPacket.MyStatus = PacketStatus.finished_ok;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if(What == VLANTagType.Untagged)
|
||||||
|
{
|
||||||
|
//We strip off the tagging
|
||||||
|
tPacket.VLANID = 1; //set to the default vlan
|
||||||
|
}
|
||||||
|
if(What == VLANTagType.Tagged)
|
||||||
|
{
|
||||||
|
//We actually do not do anything. The tag remains intact.
|
||||||
|
tPacket.VLANID = VI.ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private VLANInfo IncomingVLAN(int ID)
|
||||||
|
{
|
||||||
|
//Search through incoming vlan stuff to find the right one
|
||||||
|
//If the packet is tagged with the ID, and the port is tagged, return that
|
||||||
|
//If the packet is untagged, return the one that is untagged
|
||||||
|
VLANInfo newVLANinfo = null;
|
||||||
|
if (ID != 1) //It is tagged
|
||||||
|
{
|
||||||
|
foreach(VLANInfo vi in VLANs)
|
||||||
|
{
|
||||||
|
if (vi.ID == ID) return vi;
|
||||||
|
}
|
||||||
|
//We do not have one set yet. Add a new one
|
||||||
|
newVLANinfo = new VLANInfo(ID, VLANTagType.Forbidden);
|
||||||
|
VLANs.Add(newVLANinfo);
|
||||||
|
return newVLANinfo;
|
||||||
|
}
|
||||||
|
else //the packet is the default vlan (1) so appears untagged.
|
||||||
|
{
|
||||||
|
foreach (VLANInfo vi in VLANs)
|
||||||
|
{
|
||||||
|
if (vi.Tag == VLANTagType.Untagged) return vi;
|
||||||
|
}
|
||||||
|
//We do not have an "untagged" vlan. Return the settings for vlan1
|
||||||
|
foreach (VLANInfo vi in VLANs)
|
||||||
|
{
|
||||||
|
if (vi.ID == 1) return vi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//We should never get here. This is just a fall-through
|
||||||
|
newVLANinfo = new VLANInfo(ID, VLANTagType.Forbidden);
|
||||||
|
VLANs.Add(newVLANinfo);
|
||||||
|
return newVLANinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessInboundPacket(Packet tPacket)
|
public void ProcessInboundPacket(Packet tPacket)
|
||||||
@ -177,6 +238,52 @@ namespace EduNetworkBuilder
|
|||||||
{
|
{
|
||||||
//anything we should do here?
|
//anything we should do here?
|
||||||
//Mainly vlan if we are a vlan.
|
//Mainly vlan if we are a vlan.
|
||||||
|
VLANInfo VI = IncomingVLAN(tPacket.VLANID);
|
||||||
|
VLANTagType What = VI.Tag;
|
||||||
|
Network theNet = NB.GetNetwork();
|
||||||
|
NetworkDevice HD = theNet.GetDeviceFromID(AttachedToHostNic);
|
||||||
|
string hostname = HD.hostname;
|
||||||
|
|
||||||
|
if (What == VLANTagType.Forbidden)
|
||||||
|
{
|
||||||
|
//This vlan packet is deliberately forbidden. Reject it (fail)
|
||||||
|
string errString = string.Format(NB.Translate("NI_VLANInForbidden"), hostname, tPacket.destIP.GetIPString);
|
||||||
|
tPacket.AddMessage(DebugLevel.switching, errString);
|
||||||
|
tPacket.Tracking.Status = errString;
|
||||||
|
tPacket.MyStatus = PacketStatus.finished_ok;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (What == VLANTagType.Untagged)
|
||||||
|
{
|
||||||
|
//If it is 1 (default vlan), this is OK. Otherwise drop.
|
||||||
|
//Untagged means we expect it to be vlan of 1 on the cable side
|
||||||
|
if(tPacket.VLANID != 1)
|
||||||
|
{
|
||||||
|
//Oops. We need to reject the packet
|
||||||
|
string errString = string.Format(NB.Translate("NI_VLANInUntagged"), hostname, tPacket.destIP.GetIPString);
|
||||||
|
tPacket.AddMessage(DebugLevel.switching, errString);
|
||||||
|
tPacket.Tracking.Status = errString;
|
||||||
|
tPacket.MyStatus = PacketStatus.finished_ok;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else //We need to tag the packet with the new VLAN-ID
|
||||||
|
{
|
||||||
|
tPacket.VLANID = VI.ID; //The packet is ow tagged
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (What == VLANTagType.Tagged)
|
||||||
|
{
|
||||||
|
//If the packet is tagged, and the vlan expected tagged, all is good.
|
||||||
|
if(tPacket.VLANID != VI.ID)
|
||||||
|
{
|
||||||
|
//Oops. We need to reject the packet
|
||||||
|
string errString = string.Format(NB.Translate("NI_VLANInMisMatch"), hostname, tPacket.destIP.GetIPString);
|
||||||
|
tPacket.AddMessage(DebugLevel.switching, errString);
|
||||||
|
tPacket.Tracking.Status = errString;
|
||||||
|
tPacket.MyStatus = PacketStatus.finished_ok;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1513,4 +1513,20 @@
|
|||||||
<value>VLANs</value>
|
<value>VLANs</value>
|
||||||
<comment>DeviceConfig bntVLAN = VLANs</comment>
|
<comment>DeviceConfig bntVLAN = VLANs</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NI_VLANInForbidden" xml:space="preserve">
|
||||||
|
<value>Packet forbidden to enter into this port.</value>
|
||||||
|
<comment>NI_VLANInForbidden = Packet forbidden to enter into this port.</comment>
|
||||||
|
</data>
|
||||||
|
<data name="NI_VLANInMisMatch" xml:space="preserve">
|
||||||
|
<value>Packet and port do not match on VLANs. The packet cannot enter this device</value>
|
||||||
|
<comment>NI_VLANInMisMatch</comment>
|
||||||
|
</data>
|
||||||
|
<data name="NI_VLANInUntagged" xml:space="preserve">
|
||||||
|
<value>Packet is expected to be untagged, but it is tagged.</value>
|
||||||
|
<comment>NI_VLANInUntagged = Packet is expected to be untagged, but it is tagged.</comment>
|
||||||
|
</data>
|
||||||
|
<data name="NI_VLANOut" xml:space="preserve">
|
||||||
|
<value>Packed forbidden to go out this port</value>
|
||||||
|
<comment>NI_VLANOut = Packed forbidden to go out this port</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
Loading…
Reference in New Issue
Block a user