]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Merge branch 'trac3628'
authorMarcin Siodelski <marcin@isc.org>
Wed, 10 Dec 2014 19:41:19 +0000 (20:41 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 10 Dec 2014 19:41:19 +0000 (20:41 +0100)
Conflicts:
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/cfg_hosts.cc
src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc

1  2 
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/cfg_hosts.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.h
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc

index 886cc2411ed8d7f48f448f1312a21c3ff6fac83c,9933c0377efcd84f811b4513acaedb1b0ed5aa81..062ef8ef5790b799ec1ab2bb6769b9f7787380b8
@@@ -58,14 -75,9 +75,10 @@@ libkea_dhcpsrv_la_SOURCES += csv_lease_
  libkea_dhcpsrv_la_SOURCES += d2_client_cfg.cc d2_client_cfg.h
  libkea_dhcpsrv_la_SOURCES += d2_client_mgr.cc d2_client_mgr.h
  libkea_dhcpsrv_la_SOURCES += daemon.cc daemon.h
- libkea_dhcpsrv_la_SOURCES += dbaccess_parser.cc dbaccess_parser.h
  libkea_dhcpsrv_la_SOURCES += dhcpsrv_log.cc dhcpsrv_log.h
- libkea_dhcpsrv_la_SOURCES += dhcp_config_parser.h
- libkea_dhcpsrv_la_SOURCES += dhcp_parsers.cc dhcp_parsers.h
  libkea_dhcpsrv_la_SOURCES += host.cc host.h
  libkea_dhcpsrv_la_SOURCES += host_container.h
- libkea_dhcpsrv_la_SOURCES += host_reservation_parser.cc host_reservation_parser.h
 +libkea_dhcpsrv_la_SOURCES += host_mgr.cc host_mgr.h
  libkea_dhcpsrv_la_SOURCES += key_from_key.h
  libkea_dhcpsrv_la_SOURCES += lease.cc lease.h
  libkea_dhcpsrv_la_SOURCES += lease_mgr.cc lease_mgr.h
@@@ -88,8 -100,18 +101,19 @@@ libkea_dhcpsrv_la_SOURCES += subnet_id.
  libkea_dhcpsrv_la_SOURCES += subnet_selector.h
  libkea_dhcpsrv_la_SOURCES += triplet.h
  libkea_dhcpsrv_la_SOURCES += utils.h
 +libkea_dhcpsrv_la_SOURCES += writable_host_data_source.h
  
+ # Configuration parsers
+ libkea_dhcpsrv_la_SOURCES += parsers/dhcp_config_parser.h
+ libkea_dhcpsrv_la_SOURCES += parsers/dbaccess_parser.cc
+ libkea_dhcpsrv_la_SOURCES += parsers/dbaccess_parser.h
+ libkea_dhcpsrv_la_SOURCES += parsers/dhcp_parsers.cc
+ libkea_dhcpsrv_la_SOURCES += parsers/dhcp_parsers.h
+ libkea_dhcpsrv_la_SOURCES += parsers/host_reservation_parser.cc
+ libkea_dhcpsrv_la_SOURCES += parsers/host_reservation_parser.h
+ libkea_dhcpsrv_la_SOURCES += parsers/host_reservations_list_parser.h
  nodist_libkea_dhcpsrv_la_SOURCES = dhcpsrv_messages.h dhcpsrv_messages.cc
  
  libkea_dhcpsrv_la_CXXFLAGS = $(AM_CXXFLAGS)
@@@ -119,11 -141,11 +143,11 @@@ libkea_dhcpsrv_la_CXXFLAGS += -Wno-unus
  endif
  
  # The message file should be in the distribution
- EXTRA_DIST = dhcpsrv_messages.mes
+ EXTRA_DIST += dhcpsrv_messages.mes
  
 -# Distribute MySQL schema creation script and backend documentation
 -EXTRA_DIST += dhcpdb_create.mysql dhcpdb_create.pgsql database_backends.dox libdhcpsrv.dox
 -dist_pkgdata_DATA = dhcpdb_create.mysql dhcpdb_create.pgsql
 +# Distribute backend documentation
 +# Database schema creation script moved to src/bin/admin
 +EXTRA_DIST += database_backends.dox libdhcpsrv.dox
  
  install-data-local:
        $(mkinstalldirs) $(DESTDIR)$(dhcp_data_dir)
index f7869509266ef3a3efd6f2bfa754e11c5020f8ee,7b503df74ac378ed6afdd2300176229a984c0b4c..8bb17f3cc3307aefce67e377ef1392dc1d2fbec6
@@@ -165,26 -166,36 +166,43 @@@ CfgHosts::add(const HostPtr& host) 
          isc_throw(BadValue, "specified host object must not be NULL when it"
                    " is added to the configuration");
      }
 -
 +    // At least one subnet ID must be non-zero
 +    if (host->getIPv4SubnetID() == 0 && host->getIPv6SubnetID() == 0) {
 +        isc_throw(BadValue, "must not use both IPv4 and IPv6 subnet ids of"
 +                  " 0 when adding new host reservation");
 +    }
 +    /// @todo This may need further sanity checks.
      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)) {
 +    if ((host->getIPv4SubnetID() > 0) &&
 +        get4(host->getIPv4SubnetID(), hwaddr, duid)) {
          isc_throw(DuplicateHost, "failed to add new host using the HW"
                    " address '" << (hwaddr ? hwaddr->toText(false) : "(null)")
                    << " and DUID '" << (duid ? duid->toText() : "(null)")
                    << "' 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)) {
 +    } else if (host->getIPv6SubnetID() &&
 +               get6(host->getIPv6SubnetID(), duid, hwaddr)) {
          isc_throw(DuplicateHost, "failed to add new host using the HW"
                    " address '" << (hwaddr ? hwaddr->toText(false) : "(null)")
                    << " and DUID '" << (duid ? duid->toText() : "(null)")
index a0999622ef5556eaba4741945109add0b0b6f92d,fc5b8142e9763b7514432f0225cc29100e11b23c..984633f20b03bc5a30c3463181f5272f4e89c36a
@@@ -24,8 -23,8 +23,9 @@@
  #include <dhcpsrv/cfg_option.h>
  #include <dhcpsrv/option_space_container.h>
  #include <dhcpsrv/subnet.h>
+ #include <dhcpsrv/parsers/dhcp_config_parser.h>
  #include <exceptions/exceptions.h>
 +#include <util/optional_value.h>
  
  #include <boost/shared_ptr.hpp>
  
index 59af7395ffb8db449f131adea6d7b622aad62dff,24e80bf1b4c54fd688c9522c6898269b0ece2ee1..a57545791c3cfcc74fe2b4ecb321812ac283ded6
@@@ -68,9 -68,9 +68,10 @@@ libdhcpsrv_unittests_SOURCES += d2_clie
  libdhcpsrv_unittests_SOURCES += d2_udp_unittest.cc
  libdhcpsrv_unittests_SOURCES += daemon_unittest.cc
  libdhcpsrv_unittests_SOURCES += dbaccess_parser_unittest.cc
 +libdhcpsrv_unittests_SOURCES += host_mgr_unittest.cc
  libdhcpsrv_unittests_SOURCES += host_unittest.cc
  libdhcpsrv_unittests_SOURCES += host_reservation_parser_unittest.cc
+ libdhcpsrv_unittests_SOURCES += host_reservations_list_parser_unittest.cc
  libdhcpsrv_unittests_SOURCES += lease_file_io.cc lease_file_io.h
  libdhcpsrv_unittests_SOURCES += lease_unittest.cc
  libdhcpsrv_unittests_SOURCES += lease_mgr_factory_unittest.cc
index 4c566c217d0a522a15eb231d485c4b0c11628a9b,0c158770d0adc694471865e74b0fdfb7236c5f67..04ed40d923aaec5a86f4abfb587d8471c973b9a4
@@@ -358,22 -349,25 +358,25 @@@ TEST_F(CfgHostsTest, duplicatesSubnet6H
      // Add a host.
      ASSERT_NO_THROW(cfg.add(HostPtr(new Host(hwaddrs_[0]->toText(false),
                                               "hw-address",
 -                                             SubnetID(10), SubnetID(1),
 +                                             SubnetID(0), SubnetID(1),
-                                              IOAddress("0.0.0.0")))));
+                                              IOAddress("0.0.0.0"),
+                                              "foo.example.com"))));
  
      // Try to add the host with the same HW address to the same subnet. The fact
      // that the IP address is different here shouldn't really matter.
      EXPECT_THROW(cfg.add(HostPtr(new Host(hwaddrs_[0]->toText(false),
                                            "hw-address",
 -                                          SubnetID(11), SubnetID(1),
 +                                          SubnetID(0), SubnetID(1),
-                                           IOAddress("0.0.0.0")))),
+                                           IOAddress("0.0.0.0"),
+                                           "foo.example.com"))),
                   isc::dhcp::DuplicateHost);
  
      // Now try to add it to a different subnet. It should go through.
      EXPECT_NO_THROW(cfg.add(HostPtr(new Host(hwaddrs_[0]->toText(false),
                                               "hw-address",
 -                                             SubnetID(11), SubnetID(2),
 +                                             SubnetID(0), SubnetID(2),
-                                              IOAddress("0.0.0.0")))));
+                                              IOAddress("0.0.0.0"),
+                                              "foo.example.com"))));
  }
  
  // This test verifies that it is not possible to add the same Host to the
@@@ -383,22 -377,25 +386,25 @@@ TEST_F(CfgHostsTest, duplicatesSubnet6D
      // Add a host.
      ASSERT_NO_THROW(cfg.add(HostPtr(new Host(duids_[0]->toText(),
                                               "duid",
 -                                             SubnetID(10), SubnetID(1),
 +                                             SubnetID(0), SubnetID(1),
-                                              IOAddress("0.0.0.0")))));
+                                              IOAddress("0.0.0.0"),
+                                              "foo.example.com"))));
  
      // Try to add the host with the same DUID to the same subnet. The fact
      // that the IP address is different here shouldn't really matter.
      EXPECT_THROW(cfg.add(HostPtr(new Host(duids_[0]->toText(),
                                            "duid",
 -                                          SubnetID(11), SubnetID(1),
 +                                          SubnetID(0), SubnetID(1),
-                                           IOAddress("0.0.0.0")))),
+                                           IOAddress("0.0.0.0"),
+                                           "foo.example.com"))),
                   isc::dhcp::DuplicateHost);
  
      // Now try to add it to a different subnet. It should go through.
      EXPECT_NO_THROW(cfg.add(HostPtr(new Host(duids_[0]->toText(),
                                               "duid",
 -                                             SubnetID(11), SubnetID(2),
 +                                             SubnetID(0), SubnetID(2),
-                                              IOAddress("0.0.0.0")))));
+                                              IOAddress("0.0.0.0"),
+                                              "foo.example.com"))));
  }