From: Andrei Pavel Date: Tue, 18 Jan 2022 14:56:58 +0000 (+0200) Subject: [#2264] allow IPv6 addresses in HA "url" X-Git-Tag: Kea-2.0.2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13db93a035fbbf2fbfb99f622d2dfe4cc466a853;p=thirdparty%2Fkea.git [#2264] allow IPv6 addresses in HA "url" --- diff --git a/src/hooks/dhcp/high_availability/ha_config.cc b/src/hooks/dhcp/high_availability/ha_config.cc index 8ced41f4f7..e673fddff4 100644 --- a/src/hooks/dhcp/high_availability/ha_config.cc +++ b/src/hooks/dhcp/high_availability/ha_config.cc @@ -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() diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 9a15fa2c35..4fa5558503 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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_)); diff --git a/src/lib/http/url.h b/src/lib/http/url.h index caaebe9adf..d6ec9e28b4 100644 --- a/src/lib/http/url.h +++ b/src/lib/http/url.h @@ -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;