From: Matan Breizman Date: Wed, 27 Apr 2022 10:06:13 +0000 (+0000) Subject: mount/conf: Fix IPv6 parsing X-Git-Tag: v16.2.11~103^2~79^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=766edcc66e43ed1658afd823aaa4d24950f0e0bf;p=ceph.git mount/conf: Fix IPv6 parsing Fixes: https://tracker.ceph.com/issues/47300 Signed-off-by: Matan Breizman (cherry picked from commit 5be921f334324c04344d26c024cf4a9ba403fbdd) --- diff --git a/src/mount/conf.cc b/src/mount/conf.cc index 104969eefbf39..05dc09c04804b 100644 --- a/src/mount/conf.cc +++ b/src/mount/conf.cc @@ -67,9 +67,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 330cfba5bc35a..ba088e84f3204 100644 --- a/src/msg/msg_types.cc +++ b/src/msg/msg_types.cc @@ -380,3 +380,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 77c9fcaab8fda..31d19a946d97a 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -431,6 +431,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;