diff options
author | Tomek Mrugalski <tomasz@isc.org> | 2017-04-10 18:43:23 +0200 |
---|---|---|
committer | Tomek Mrugalski <tomasz@isc.org> | 2017-04-10 18:43:23 +0200 |
commit | 9147ce9a833ae16878ac92d77d560bea2f3ddae1 (patch) | |
tree | dd5a1456468c23846478a213f9fc0672fe02a29d /src/lib/dhcpsrv/cfg_hosts.cc | |
parent | [5207] Modify HostReservationParser to return parsed host. (diff) | |
download | kea-9147ce9a833ae16878ac92d77d560bea2f3ddae1.tar.xz kea-9147ce9a833ae16878ac92d77d560bea2f3ddae1.zip |
[5207] Improved duplication checks when adding reservations
Diffstat (limited to 'src/lib/dhcpsrv/cfg_hosts.cc')
-rw-r--r-- | src/lib/dhcpsrv/cfg_hosts.cc | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/lib/dhcpsrv/cfg_hosts.cc b/src/lib/dhcpsrv/cfg_hosts.cc index 935be7fbd9..a1f99e0f5c 100644 --- a/src/lib/dhcpsrv/cfg_hosts.cc +++ b/src/lib/dhcpsrv/cfg_hosts.cc @@ -573,7 +573,9 @@ CfgHosts::add(const HostPtr& host) { void CfgHosts::add4(const HostPtr& host) { - /// @todo This may need further sanity checks. + /// @todo: Should we add this host at all if IPv4 subnet-id is 0? + /// Why, if it's IPv6-only host? + HWAddrPtr hwaddr = host->getHWAddress(); DuidPtr duid = host->getDuid(); @@ -633,7 +635,16 @@ CfgHosts::add4(const HostPtr& host) { << ": There's already a reservation for this address"); } - /// @todo This may need further sanity checks. + // Check if the (identifier type, identifier) tuple is already used. + const std::vector<uint8_t>& id = host->getIdentifier(); + if ((host->getIPv4SubnetID() > 0) && !id.empty()) { + if (get4(host->getIPv4SubnetID(), host->getIdentifierType(), &id[0], + id.size())) { + isc_throw(DuplicateHost, "failed to add duplicate host using identifier: " + << Host::getIdentifierAsText(host->getIdentifierType(), + &id[0], id.size())); + } + } // This is a new instance - add it. hosts_.insert(host); @@ -641,13 +652,26 @@ CfgHosts::add4(const HostPtr& host) { void CfgHosts::add6(const HostPtr& host) { - /// @todo This may need further sanity checks. + + /// @todo: Should we add this host at all if IPv6 subnet-id is 0? + /// Why, if it's IPv4-only host? HWAddrPtr hwaddr = host->getHWAddress(); DuidPtr duid = host->getDuid(); // Get all reservations for this host. IPv6ResrvRange reservations = host->getIPv6Reservations(); + // Check if the (identifier type, identifier) tuple is already used. + const std::vector<uint8_t>& id = host->getIdentifier(); + if ((host->getIPv6SubnetID() > 0) && !id.empty()) { + if (get6(host->getIPv4SubnetID(), host->getIdentifierType(), &id[0], + id.size())) { + isc_throw(DuplicateHost, "failed to add duplicate host using identifier: " + << Host::getIdentifierAsText(host->getIdentifierType(), + &id[0], id.size())); + } + } + // Check if there are any IPv6 reservations. if (std::distance(reservations.first, reservations.second) == 0) { // If there aren't, we don't need to add this to hosts6_, which is used |