Start working on Firewall Rules

This commit is contained in:
Tim Young 2016-11-04 15:08:47 -05:00
parent c1bce08f77
commit 6d375c9b60
16 changed files with 3454 additions and 12 deletions

View File

@ -101,6 +101,14 @@ namespace EduNetworkBuilder
NetworkCard nic = ndCLonedItem.NicFromName(nic_name);
if (nic != null)
{
if (nic.GetNicType == NicType.management_interface)
interfacesLocked = true;
if (nic.GetNicType == NicType.lo)
interfacesLocked = true;
if (nic.GetNicType == NicType.port)
interfacesLocked = true;
if (nic.GetNicType == NicType.wport)
interfacesLocked = true;
for (int i = 0; i < nic.IFCount; i++)
{
NetworkInterface nif = nic.GetInterface(i);

View File

@ -87,6 +87,10 @@
<Compile Include="DeviceConfig.Designer.cs">
<DependentUpon>DeviceConfig.cs</DependentUpon>
</Compile>
<Compile Include="FirewallEditor.cs" />
<Compile Include="FirewallEditor.Designer.cs">
<DependentUpon>FirewallEditor.cs</DependentUpon>
</Compile>
<Compile Include="IPAddress.cs" />
<Compile Include="IPAddressEntry.cs">
<SubType>Form</SubType>
@ -169,6 +173,9 @@
<EmbeddedResource Include="DeviceConfig.resx">
<DependentUpon>DeviceConfig.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FirewallEditor.resx">
<DependentUpon>FirewallEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="IPAddressEntry.resx">
<DependentUpon>IPAddressEntry.cs</DependentUpon>
</EmbeddedResource>
@ -280,8 +287,10 @@
<None Include="Resources\Level5_WirelessRepeater2.enbx" />
<None Include="Resources\Level5_WirelessRouters.enbx" />
<None Include="Resources\Level6_ForbiddenVLAN.enbx" />
<None Include="Resources\Level6_Intro3_LockedOut.enbx" />
<None Include="Resources\Level6_SorryBoss.enbx" />
<None Include="Resources\Level6_TaggedBetweenSwitches.enbx" />
<None Include="Resources\Level6_TwoAccessPoints.enbx" />
<None Include="Resources\level6_UntaggedAndDHCP.enbx" />
<None Include="Resources\Level6_VLANFrustrations.enbx" />
<None Include="Resources\Level6_VLANRouting.enbx" />

View File

@ -0,0 +1,105 @@
namespace EduNetworkBuilder
{
partial class FirewallEditor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lbRules = new System.Windows.Forms.ListBox();
this.btnNew = new System.Windows.Forms.Button();
this.btnDone = new System.Windows.Forms.Button();
this.btnDel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lbRules
//
this.lbRules.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lbRules.FormattingEnabled = true;
this.lbRules.ItemHeight = 16;
this.lbRules.Location = new System.Drawing.Point(12, 23);
this.lbRules.Name = "lbRules";
this.lbRules.Size = new System.Drawing.Size(276, 228);
this.lbRules.TabIndex = 0;
//
// btnNew
//
this.btnNew.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnNew.Location = new System.Drawing.Point(12, 256);
this.btnNew.Name = "btnNew";
this.btnNew.Size = new System.Drawing.Size(75, 23);
this.btnNew.TabIndex = 1;
this.btnNew.Text = "New";
this.btnNew.UseVisualStyleBackColor = true;
this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
//
// btnDone
//
this.btnDone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnDone.Location = new System.Drawing.Point(213, 256);
this.btnDone.Name = "btnDone";
this.btnDone.Size = new System.Drawing.Size(75, 23);
this.btnDone.TabIndex = 2;
this.btnDone.Text = "Done";
this.btnDone.UseVisualStyleBackColor = true;
this.btnDone.Click += new System.EventHandler(this.btnDone_Click);
//
// btnDel
//
this.btnDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnDel.Location = new System.Drawing.Point(93, 257);
this.btnDel.Name = "btnDel";
this.btnDel.Size = new System.Drawing.Size(75, 23);
this.btnDel.TabIndex = 3;
this.btnDel.Text = "Delete";
this.btnDel.UseVisualStyleBackColor = true;
this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
//
// FirewallEditor
//
this.AcceptButton = this.btnDone;
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(300, 285);
this.Controls.Add(this.btnDel);
this.Controls.Add(this.btnDone);
this.Controls.Add(this.btnNew);
this.Controls.Add(this.lbRules);
this.Name = "FirewallEditor";
this.Text = "FirewallEditor";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListBox lbRules;
private System.Windows.Forms.Button btnNew;
private System.Windows.Forms.Button btnDone;
private System.Windows.Forms.Button btnDel;
}
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EduNetworkBuilder
{
public class FirewallRule
{
public string Source;
public string Destination;
public FirewallRuleType Action;
}
public partial class FirewallEditor : Form
{
public FirewallEditor()
{
InitializeComponent();
UpdateForm();
}
void UpdateForm()
{
if (lbRules.SelectedIndex > 0)
btnDel.Visible = true;
else
btnDel.Visible = false;
}
private void btnNew_Click(object sender, EventArgs e)
{
}
private void btnDel_Click(object sender, EventArgs e)
{
}
private void btnDone_Click(object sender, EventArgs e)
{
}
}
}

View File

@ -55,6 +55,7 @@ namespace EduNetworkBuilder
Network, Packet, NIC, Interface, Router, PacketCorruption, GeneralWireless, WirelessSSID, WirelessKey,
WirelessAP, WirelessRouter, WirelessRepeater, WirelessBridge, VLAN
}
public enum FirewallRuleType { Allow, Drop }
public enum PuzzleNames
{
Level0_IP, Level1_NoGateway, Level0_NeedsLink, Level0_NoSwitch, Level1_BadDHCP, Level1_BadGateway,
@ -71,8 +72,9 @@ namespace EduNetworkBuilder
Level4_InternalSubnetting, Level4_Internalhemorrhage,
Level5_WirelessRouters, Level5_WirelessDevices, Level5_WirelessBridge, Level5_WirelessRepeater, Level5_WirelessRepeater2,
Level5_WirelessAccessPoint, Level5_WirelessCorruption, Level5_Failed, Level5_LostPacket, Level5_HereComesTrouble,
Level6_VLAN_Intro, Level6_VLAN_Intro2, Level6_ForbiddenVLAN, Level6_TaggedBetweenSwitches, Level6_VLANRouting,
Level6_VLANRouting2, level6_UntaggedAndDHCP, Level6_SorryBoss, Level6_VLANFrustrations,
Level6_VLAN_Intro, Level6_VLAN_Intro2, Level6_Intro3_LockedOut, Level6_ForbiddenVLAN, Level6_TaggedBetweenSwitches,
Level6_VLANRouting, Level6_VLANRouting2, level6_UntaggedAndDHCP, Level6_SorryBoss, Level6_VLANFrustrations,
Level6_TwoAccessPoints,
}
public enum DebugPausePoint { none=0, packet_create=1, packet_kill=2,

View File

@ -28,6 +28,7 @@ namespace EduNetworkBuilder
public bool ShowLabelsHere = false;
public bool VLANsEnabled = false;
public bool VLANPacketColors = false;
public bool FirewallEnabled = false;
public LanguageStrings NetMessage;
public LanguageStrings NetTitle;
List<NetworkComponent> NetComponents = new List<NetworkComponent>();
@ -137,6 +138,9 @@ namespace EduNetworkBuilder
case "vlansenabled":
bool.TryParse(Individual.InnerText, out VLANsEnabled);
break;
case "firewallenabled":
bool.TryParse(Individual.InnerText, out FirewallEnabled);
break;
case "vlanpacketcolors":
bool.TryParse(Individual.InnerText, out VLANPacketColors);
if (VLANPacketColors)
@ -288,6 +292,7 @@ namespace EduNetworkBuilder
writer.WriteElementString("uniqueidentifier", UniqueIdentifier.ToString());
writer.WriteElementString("startinghelplevel", StartingHelpLevel.ToString());
writer.WriteElementString("vlansenabled", VLANsEnabled.ToString());
writer.WriteElementString("firewallenabled", FirewallEnabled.ToString());
writer.WriteElementString("VLANPacketColors", VLANPacketColors.ToString());
//Save all the devices
for (int loop = 0; loop < NetComponents.Count; loop++)

View File

@ -966,7 +966,10 @@ namespace EduNetworkBuilder
string newtooltip = "";
if (MouseOver != null)
{
newtooltip = MouseOver.TooltipString();
if (!MouseOver.DeviceIsLockedOutByVLANs())
newtooltip = MouseOver.TooltipString();
else
newtooltip = NB.Translate("NB_LockedOut");
}
if(oldtooltip != newtooltip)
{

View File

@ -33,6 +33,7 @@ namespace EduNetworkBuilder
public bool CanAddNics = false;
public Color BackgroundColor = Color.Empty;
protected Color MorphColor = Color.Empty;
protected List<FirewallRule> FirewallRules = new List<FirewallRule>();
public NetworkDevice(NetworkComponentType what, string tHostname, Point tLocation, NicType firstNic = NicType.eth)
{
@ -1148,6 +1149,13 @@ namespace EduNetworkBuilder
return false;
}
public bool CanBeLockedOut()
{
if (myType == NetworkComponentType.net_switch) return true;
//if (myType == NetworkComponentType.wrouter) return true;
return false;
}
public bool DoesForwarding()
{
if (myType == NetworkComponentType.net_hub)
@ -1165,12 +1173,21 @@ namespace EduNetworkBuilder
return false;
}
public bool DoesFirewall()
{
if (myType == NetworkComponentType.firewall)
return true;
if (myType == NetworkComponentType.wrouter)
return true;
return false;
}
public bool DoesVLANs()
{
if (myType == NetworkComponentType.net_switch)
return true;
if (myType == NetworkComponentType.wrouter)
return true;
//if (myType == NetworkComponentType.wrouter)
// return true;
if (myType == NetworkComponentType.firewall)
return true;
if (myType == NetworkComponentType.router)
@ -1303,7 +1320,7 @@ namespace EduNetworkBuilder
{
bool typesMatch=false;
if (tPacket.sourceIP == null) return ResponseToPacket.reject;
if (tPacket.TsourceIP != null && !tPacket.TsourceIP.IsLocal(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)
{
if(ipc.What == PacketType.dhcp_request)
@ -1650,7 +1667,7 @@ namespace EduNetworkBuilder
//We would be responding to it. We have an odd case for switches.
//Verify that the management IP can talk to the packet
if(myType == NetworkComponentType.net_switch || myType == NetworkComponentType.wrouter)
if(CanBeLockedOut())
{
//only a few devices have management ips
NetworkCard nic = HubManagementCard();
@ -1986,7 +2003,7 @@ namespace EduNetworkBuilder
public bool DeviceIsLockedOutByVLANs()
{
if (myType != NetworkComponentType.net_switch && myType != NetworkComponentType.wrouter)
if (!CanBeLockedOut())
return false; //We can only be locked out of a few things.
NetworkCard nic = HubManagementCard();
if (nic == null) return false; //this should never happen. Eject for now.

View File

@ -51,6 +51,7 @@
this.lblStartingHelp = new System.Windows.Forms.Label();
this.cbVLANs = new System.Windows.Forms.CheckBox();
this.cb_ColoredPackets = new System.Windows.Forms.CheckBox();
this.cbFirewallEnabled = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// btnDone
@ -240,7 +241,7 @@
// cbVLANs
//
this.cbVLANs.AutoSize = true;
this.cbVLANs.Location = new System.Drawing.Point(519, 247);
this.cbVLANs.Location = new System.Drawing.Point(519, 221);
this.cbVLANs.Name = "cbVLANs";
this.cbVLANs.Size = new System.Drawing.Size(129, 21);
this.cbVLANs.TabIndex = 21;
@ -251,19 +252,31 @@
// cb_ColoredPackets
//
this.cb_ColoredPackets.AutoSize = true;
this.cb_ColoredPackets.Location = new System.Drawing.Point(519, 274);
this.cb_ColoredPackets.Location = new System.Drawing.Point(519, 248);
this.cb_ColoredPackets.Name = "cb_ColoredPackets";
this.cb_ColoredPackets.Size = new System.Drawing.Size(173, 21);
this.cb_ColoredPackets.TabIndex = 22;
this.cb_ColoredPackets.Text = "VLAN Colored Packets";
this.cb_ColoredPackets.UseVisualStyleBackColor = true;
//
// cbFirewallEnabled
//
this.cbFirewallEnabled.AutoSize = true;
this.cbFirewallEnabled.Location = new System.Drawing.Point(518, 276);
this.cbFirewallEnabled.Name = "cbFirewallEnabled";
this.cbFirewallEnabled.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.cbFirewallEnabled.Size = new System.Drawing.Size(165, 21);
this.cbFirewallEnabled.TabIndex = 23;
this.cbFirewallEnabled.Text = "Adv. Firewall Enabled";
this.cbFirewallEnabled.UseVisualStyleBackColor = true;
//
// OptionsWindow
//
this.AcceptButton = this.btnDone;
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(836, 307);
this.Controls.Add(this.cbFirewallEnabled);
this.Controls.Add(this.cb_ColoredPackets);
this.Controls.Add(this.cbVLANs);
this.Controls.Add(this.lblStartingHelp);
@ -319,5 +332,6 @@
private System.Windows.Forms.Label lblStartingHelp;
private System.Windows.Forms.CheckBox cbVLANs;
private System.Windows.Forms.CheckBox cb_ColoredPackets;
private System.Windows.Forms.CheckBox cbFirewallEnabled;
}
}

View File

@ -76,6 +76,7 @@ namespace EduNetworkBuilder
tbNetworkTitle.Text = myNet.NetTitle.GetText();
cbDisplayTitles.Checked = myNet.OptionShowLabels;
cbVLANs.Checked = myNet.VLANsEnabled;
cbFirewallEnabled.Checked = myNet.FirewallEnabled;
cb_ColoredPackets.Checked = myNet.VLANPacketColors;
tbNetworkX.Text = myNet.myWidth.ToString();
tbNetworkY.Text = myNet.myHeight.ToString();
@ -115,6 +116,7 @@ namespace EduNetworkBuilder
myNet.OptionShowLabels = cbDisplayTitles.Checked;
myNet.VLANsEnabled = cbVLANs.Checked;
myNet.VLANPacketColors = cb_ColoredPackets.Checked;
myNet.FirewallEnabled = cbFirewallEnabled.Checked;
myNet.ShowLabelsHere = myNet.OptionShowLabels;
int.TryParse(tbNetworkX.Text, out myNet.myWidth);
int.TryParse(tbNetworkY.Text, out myNet.myHeight);

View File

@ -782,6 +782,16 @@ namespace EduNetworkBuilder.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] Level6_Intro3_LockedOut {
get {
object obj = ResourceManager.GetObject("Level6_Intro3_LockedOut", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
@ -802,6 +812,16 @@ namespace EduNetworkBuilder.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] Level6_TwoAccessPoints {
get {
object obj = ResourceManager.GetObject("Level6_TwoAccessPoints", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>

View File

@ -421,4 +421,10 @@
<data name="Level6_VLANFrustrations" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Level6_VLANFrustrations.enbx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="Level6_Intro3_LockedOut" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Level6_Intro3_LockedOut.enbx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="Level6_TwoAccessPoints" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Level6_TwoAccessPoints.enbx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

View File

@ -2,7 +2,7 @@
<EduNetworkBuilder>
<!--This is a network file for EduNetworkBuilder.-->
<Network>
<en_message>Vlans are managed by double-clicking the networking device (the switch, for this puzzle), and clicking on the VLANs button. A VLAN has three states, tagged, untagged, and forbidden. Forbidden means it does not work. To fix this puzzle, change the switch VLAN ports to "untagged" for all of the, and then ping the other PC</en_message>
<en_message>Vlans are managed by double-clicking the networking device (the switch, for this puzzle), and clicking on the VLANs button. A VLAN has three states, tagged, untagged, and forbidden. Forbidden means it does not work. To fix this puzzle, change the switch VLAN ports to "untagged" for all of the ports, and then ping the other PC</en_message>
<en_title>Forbidden VLANs</en_title>
<height>1024</height>
<width>1024</width>
@ -392,7 +392,7 @@
<type>ip</type>
</myip>
<VLAN
ID="1">Forbidden</VLAN>
ID="1">Untagged</VLAN>
</interface>
</nic>
</device>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1609,6 +1609,10 @@
<value>When packets are passing across a VLAN link, color the packets so we can visualize them better.</value>
<comment>OW_OWVLANColoredPacketsTT = When packets are passing across a VLAN link, color the packets so we can visualize them better.</comment>
</data>
<data name="NB_LockedOut" xml:space="preserve">
<value>Locked Out. Cannot determine settings for this device.</value>
<comment>NB_LockedOut = Locked Out. Cannot determine settings for this device.</comment>
</data>
<data name="NB_Reset" xml:space="preserve">
<value>Reset</value>
<comment>NB_Reset = Reset</comment>