]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2264] allow IPv6 addresses in HA "url"
authorAndrei Pavel <andrei@isc.org>
Tue, 18 Jan 2022 14:56:58 +0000 (16:56 +0200)
committerRazvan Becheriu <razvan@isc.org>
Wed, 23 Feb 2022 07:11:07 +0000 (09:11 +0200)
src/hooks/dhcp/high_availability/ha_config.cc
src/hooks/dhcp/high_availability/ha_service.cc
src/lib/http/url.h

index 8ced41f4f7bfb000366fcac62d4f81fc6561a96f..e673fddff4a573026a35b610f153638602d92317 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -290,7 +290,7 @@ HAConfig::validate() {
         // The hostname must be an address, not a name.
         IOAddress addr("::");
         try {
-            addr = IOAddress(p->second->getUrl().getHostname());
+            addr = IOAddress(p->second->getUrl().getStrippedHostname());
         } catch (const IOError& ex) {
             isc_throw(HAConfigValidationError, "bad url '"
                       << p->second->getUrl().toText()
index 9a15fa2c35cf72062692a306e943f89caf77755c..4fa55585038fc0de134eda43d99da1da36a690a5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -1319,7 +1319,7 @@ HAService::asyncSendLeaseUpdate(const QueryPtrType& query,
     // Create HTTP/1.1 request including our command.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(config->getUrl().getHostname()));
+         HostHttpHeader(config->getUrl().getStrippedHostname()));
     config->addBasicAuthHttpHeader(request);
     request->setBodyAsJson(command);
     request->finalize();
@@ -1634,7 +1634,7 @@ HAService::asyncSendHeartbeat() {
     // Create HTTP/1.1 request including our command.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(partner_config->getUrl().getHostname()));
+         HostHttpHeader(partner_config->getUrl().getStrippedHostname()));
     partner_config->addBasicAuthHttpHeader(request);
     request->setBodyAsJson(CommandCreator::createHeartbeat(server_type_));
     request->finalize();
@@ -1796,7 +1796,7 @@ HAService::asyncDisableDHCPService(HttpClient& http_client,
     // Create HTTP/1.1 request including our command.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(remote_config->getUrl().getHostname()));
+         HostHttpHeader(remote_config->getUrl().getStrippedHostname()));
 
     remote_config->addBasicAuthHttpHeader(request);
     request->setBodyAsJson(CommandCreator::createDHCPDisable(max_period,
@@ -1875,7 +1875,7 @@ HAService::asyncEnableDHCPService(HttpClient& http_client,
     // Create HTTP/1.1 request including our command.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(remote_config->getUrl().getHostname()));
+         HostHttpHeader(remote_config->getUrl().getStrippedHostname()));
     remote_config->addBasicAuthHttpHeader(request);
     request->setBodyAsJson(CommandCreator::createDHCPEnable(server_type_));
     request->finalize();
@@ -2013,7 +2013,7 @@ HAService::asyncSyncLeasesInternal(http::HttpClient& http_client,
     // Create HTTP/1.1 request including our command.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(partner_config->getUrl().getHostname()));
+         HostHttpHeader(partner_config->getUrl().getStrippedHostname()));
     partner_config->addBasicAuthHttpHeader(request);
     if (server_type_ == HAServerType::DHCPv4) {
         request->setBodyAsJson(CommandCreator::createLease4GetPage(
@@ -2354,7 +2354,7 @@ HAService::asyncSendLeaseUpdatesFromBacklog(HttpClient& http_client,
     // Create HTTP/1.1 request including our command.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(config->getUrl().getHostname()));
+         HostHttpHeader(config->getUrl().getStrippedHostname()));
     config->addBasicAuthHttpHeader(request);
     request->setBodyAsJson(command);
     request->finalize();
@@ -2454,7 +2454,7 @@ HAService::asyncSendHAReset(HttpClient& http_client,
     // Create HTTP/1.1 request including our command.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(config->getUrl().getHostname()));
+         HostHttpHeader(config->getUrl().getStrippedHostname()));
     config->addBasicAuthHttpHeader(request);
     request->setBodyAsJson(command);
     request->finalize();
@@ -2591,7 +2591,7 @@ HAService::processMaintenanceStart() {
     // with the cancel flag set to false.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(remote_config->getUrl().getHostname()));
+         HostHttpHeader(remote_config->getUrl().getStrippedHostname()));
     remote_config->addBasicAuthHttpHeader(request);
     request->setBodyAsJson(CommandCreator::createMaintenanceNotify(false, server_type_));
     request->finalize();
@@ -2715,7 +2715,7 @@ HAService::processMaintenanceCancel() {
     // with the cancel flag set to true.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(remote_config->getUrl().getHostname()));
+         HostHttpHeader(remote_config->getUrl().getStrippedHostname()));
     remote_config->addBasicAuthHttpHeader(request);
     request->setBodyAsJson(CommandCreator::createMaintenanceNotify(true, server_type_));
     request->finalize();
@@ -2806,7 +2806,7 @@ HAService::asyncSyncCompleteNotify(HttpClient& http_client,
     // Create HTTP/1.1 request including our command.
     PostHttpRequestJsonPtr request = boost::make_shared<PostHttpRequestJson>
         (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(),
-         HostHttpHeader(remote_config->getUrl().getHostname()));
+         HostHttpHeader(remote_config->getUrl().getStrippedHostname()));
 
     remote_config->addBasicAuthHttpHeader(request);
     request->setBodyAsJson(CommandCreator::createSyncCompleteNotify(server_type_));
index caaebe9adf5a4bf15bd739fe24ad33b5307dc97f..d6ec9e28b4d2d36fb5a3044d40ede7f69c07cdad 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2022 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -58,15 +58,10 @@ public:
     /// @throw InvalidOperation if URL is invalid.
     Scheme getScheme() const;
 
-    /// @brief Returns hostname.
-    ///
-    /// @throw InvalidOperation if URL is invalid.
-    std::string getHostname() const;
-
     /// @brief Returns hostname stripped from [ ] characters surrounding
     /// IPv6 address.
     ///
-    /// @throw InvalidOperation of URL is invalid.
+    /// @throw InvalidOperation if URL is invalid.
     std::string getStrippedHostname() const;
 
     /// @brief Returns port number.
@@ -94,6 +89,10 @@ public:
     }
 
 private:
+    /// @brief Returns hostname.
+    ///
+    /// @throw InvalidOperation if URL is invalid.
+    std::string getHostname() const;
 
     /// @brief Returns boolean value indicating if the URL is valid.
     void checkValid() const;