diff --git a/EduNetworkBuilder/IPAddress.cs b/EduNetworkBuilder/IPAddress.cs index 42e0d81..b2ed9f0 100644 --- a/EduNetworkBuilder/IPAddress.cs +++ b/EduNetworkBuilder/IPAddress.cs @@ -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; diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index c9eb29a..d5ffeea 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -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);