From: Matan Breizman Date: Wed, 27 Apr 2022 10:06:13 +0000 (+0000) Subject: mount/conf: Fix IPv6 parsing X-Git-Tag: v18.0.0~975^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5be921f334324c04344d26c024cf4a9ba403fbdd;p=ceph.git mount/conf: Fix IPv6 parsing Fixes: https://tracker.ceph.com/issues/47300 Signed-off-by: Matan Breizman --- diff --git a/src/mount/conf.cc b/src/mount/conf.cc index df95912c1f3b..9a24aa53c3f1 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 0c28e915b7b0..1a78cb326809 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 36aad858b385..6da064c4f86b 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;