From 4582de3ef3dea9b7315212608012c47c825ac81b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 19 Dec 2018 16:38:01 -0600 Subject: [PATCH] msg/async/ProtocolV2: advertise ourselves as a v2 addr when using v2 protocol We may have learned our address from a v1 connection, so myaddrs() is a v1 addr like [v1:1.2.3.4:123/4392]. When we connect to someone using msgr2, we should advertise ourselves as a v2 address, or else we risk confusing everyone because we are a "v1" endpoint using the v2 protocol. Signed-off-by: Sage Weil --- src/msg/async/ProtocolV2.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/msg/async/ProtocolV2.cc b/src/msg/async/ProtocolV2.cc index 66447c13fe1..c3780f50e29 100644 --- a/src/msg/async/ProtocolV2.cc +++ b/src/msg/async/ProtocolV2.cc @@ -1412,8 +1412,17 @@ CtPtr ProtocolV2::handle_server_addrvec_and_identify(char *buffer, int r) { } bufferlist myaddrbl; - ldout(cct, 20) << "encoding myaddrs: " << messenger->get_myaddrs() << dendl; - encode(messenger->get_myaddrs(), myaddrbl, -1ll); + if (messenger->get_myaddrs().front().is_msgr2()) { + ldout(cct, 20) << "encoding myaddrs: " << messenger->get_myaddrs() << dendl; + encode(messenger->get_myaddrs(), myaddrbl, -1ll); + } else { + entity_addr_t a = messenger->get_myaddrs().front(); + a.set_type(entity_addr_t::TYPE_MSGR2); + ldout(cct, 20) << "encoding addr " << a + << " instead of non-v2 myaddrs " << messenger->get_myaddrs() + << dendl; + encode(a, myaddrbl, -1ll); + } bufferlist conbl; encode(myaddrbl, conbl); return WRITE(conbl, handle_my_addrs_write);