From 5be921f334324c04344d26c024cf4a9ba403fbdd Mon Sep 17 00:00:00 2001 From: Matan Breizman Date: Wed, 27 Apr 2022 10:06:13 +0000 Subject: [PATCH] mount/conf: Fix IPv6 parsing Fixes: https://tracker.ceph.com/issues/47300 Signed-off-by: Matan Breizman --- src/mount/conf.cc | 4 +--- src/msg/msg_types.cc | 13 +++++++++++++ src/msg/msg_types.h | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mount/conf.cc b/src/mount/conf.cc index df95912c1f3..9a24aa53c3f 100644 --- a/src/mount/conf.cc +++ b/src/mount/conf.cc @@ -71,9 +71,7 @@ extern "C" void mount_ceph_get_config_info(const char *config_file, } std::string addr; - addr += eaddr.ip_only_to_str(); - addr += ":"; - addr += std::to_string(eaddr.get_port()); + addr += eaddr.ip_n_port_to_str(); /* If this will overrun cci_mons, stop here */ if (monaddrs.length() + 1 + addr.length() + 1 > sizeof(cci->cci_mons)) break; diff --git a/src/msg/msg_types.cc b/src/msg/msg_types.cc index 0c28e915b7b..1a78cb32680 100644 --- a/src/msg/msg_types.cc +++ b/src/msg/msg_types.cc @@ -410,3 +410,16 @@ std::string entity_addr_t::ip_only_to_str() const } return host_ip ? host_ip : ""; } + +std::string entity_addr_t::ip_n_port_to_str() const +{ + std::string addr; + addr += ip_only_to_str(); + if (is_ipv6()) { + addr = '[' + addr + ']'; + } + addr += ':'; + addr += std::to_string(get_port()); + return addr; +} + diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index 36aad858b38..6da064c4f86 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -420,6 +420,7 @@ struct entity_addr_t { } std::string ip_only_to_str() const; + std::string ip_n_port_to_str() const; std::string get_legacy_str() const { std::ostringstream ss; -- 2.39.5