Don't lose DHCP range when NIC address changes
When a server or firewall changes the IP address of a network card, any DHCP ranges associated with that old number were zeroed out. Invalidating the range COULD be a nice feature in case the new IP address falls within the DHCP range - thus preventing conflicting IP addresses. So just to be nice I did allow the range to invalidate in that situation. However, in real life it wouldn't be so nice, and so perhaps it would actually be better to keep the existing rules intact even if it would cause a problem. Scenario: Level 2 Firewall Test -change firewall eth0 to 192.168.1.10 and eth1 to 192.168.2.20 -click OK -edit firewall again and look at the DHCP rules -notice that 192.168.1 has all zeros. -same thing with 192.168.2 -after the fix, the 192.168.2 rules are retained since 2.20 doesn't conflict with the range, but 1.10 does conflict, so that rule was invalidated.
This commit is contained in:
parent
cecd14a901
commit
4a72518ccc
@ -80,6 +80,11 @@ namespace EduNetworkBuilder
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIP(UInt32 newIP)
|
||||
{
|
||||
_ip = newIP;
|
||||
}
|
||||
|
||||
public bool Equals(NB_IPAddress CompareWith)
|
||||
{
|
||||
if (_ip != CompareWith._ip) return false;
|
||||
|
@ -1806,6 +1806,24 @@ namespace EduNetworkBuilder
|
||||
RouteTable.AddRange(ndCopyFrom.RouteTable);
|
||||
DHCPRanges.Clear();
|
||||
DHCPRanges.AddRange(ndCopyFrom.DHCPRanges);
|
||||
//if the IP address has changed, also update the corresponding address in DHCP rules
|
||||
foreach (NB_IPAddress dhcpIP in DHCPRanges)
|
||||
{
|
||||
foreach (NetworkCard nic in NICs)
|
||||
{
|
||||
NetworkInterface matchingIF = nic.LocalInterface(dhcpIP, null);
|
||||
if (matchingIF != null && !matchingIF.myIP.Equals(dhcpIP.GetIP) && !matchingIF.myIP.Equals(0))
|
||||
{
|
||||
//only validate the entry if the new address doesn't conflict with the DHCP range.
|
||||
UInt32 nStartingDHCP = dhcpIP.GetMask;
|
||||
UInt32 nEndingDHCP = dhcpIP.GetGateway;
|
||||
if (matchingIF.myIP.GetIP < nStartingDHCP || matchingIF.myIP.GetIP > nEndingDHCP)
|
||||
{
|
||||
dhcpIP.SetIP(matchingIF.myIP.GetIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DHCPLeases.Clear();
|
||||
DHCPLeases.AddRange(ndCopyFrom.DHCPLeases);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user