diff options
author | Marcin Siodelski <marcin@isc.org> | 2014-12-09 18:47:50 +0100 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2014-12-09 18:47:50 +0100 |
commit | ad0f44ba43f5f9ea7ada4527659db3ccf345044c (patch) | |
tree | 1fdb09b6ab4098d2cc212ca29b0ab45c35656c94 /src/lib/dhcpsrv/cfg_hosts.cc | |
parent | [3628] Corrected distcheck failure on configuration parser files. (diff) | |
download | kea-ad0f44ba43f5f9ea7ada4527659db3ccf345044c.tar.xz kea-ad0f44ba43f5f9ea7ada4527659db3ccf345044c.zip |
[3628] Addressed review comments.
One of the major changes was to eliminate possibility of defining the dead
reservation: neither hostname nor IP address reserved and covering it with
suitable unit tests.
Diffstat (limited to 'src/lib/dhcpsrv/cfg_hosts.cc')
-rw-r--r-- | src/lib/dhcpsrv/cfg_hosts.cc | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/lib/dhcpsrv/cfg_hosts.cc b/src/lib/dhcpsrv/cfg_hosts.cc index 7e8bcbc405..7b503df74a 100644 --- a/src/lib/dhcpsrv/cfg_hosts.cc +++ b/src/lib/dhcpsrv/cfg_hosts.cc @@ -14,6 +14,7 @@ #include <dhcpsrv/cfg_hosts.h> #include <exceptions/exceptions.h> +#include <ostream> using namespace isc::asiolink; @@ -165,10 +166,26 @@ CfgHosts::add(const HostPtr& host) { isc_throw(BadValue, "specified host object must not be NULL when it" " is added to the configuration"); } - /// @todo This may need further sanity checks. For example, a duplicate - /// should be rejected. + HWAddrPtr hwaddr = host->getHWAddress(); DuidPtr duid = host->getDuid(); + + // There should be at least one resource reserved: hostname, IPv4 + // address, IPv6 address or prefix. + if (host->getHostname().empty() && + (host->getIPv4Reservation() == IOAddress("0.0.0.0")) && + (!host->hasIPv6Reservation())) { + std::ostringstream s; + if (hwaddr) { + s << "for DUID: " << hwaddr->toText(); + } else if (duid) { + s << "for HW address: " << duid->toText(); + } + isc_throw(BadValue, "specified reservation " << s + << " must include at least one resource, i.e. " + "hostname, IPv4 address or IPv6 address/prefix"); + } + // Check for duplicates for the specified IPv4 subnet. if (get4(host->getIPv4SubnetID(), hwaddr, duid)) { isc_throw(DuplicateHost, "failed to add new host using the HW" @@ -177,7 +194,7 @@ CfgHosts::add(const HostPtr& host) { << "' to the IPv4 subnet id '" << host->getIPv4SubnetID() << "' as this host has already been added"); - // Checek for duplicates for the specified IPv6 subnet. + // Check for duplicates for the specified IPv6 subnet. } else if (get6(host->getIPv6SubnetID(), duid, hwaddr)) { isc_throw(DuplicateHost, "failed to add new host using the HW" " address '" << (hwaddr ? hwaddr->toText(false) : "(null)") @@ -186,6 +203,8 @@ CfgHosts::add(const HostPtr& host) { << "' as this host has already been added"); } + /// @todo This may need further sanity checks. + // This is a new instance - add it. hosts_.insert(host); } |