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 <sage@redhat.com>
This commit is contained in:
Sage Weil 2018-12-19 16:38:01 -06:00
parent 69408b57e0
commit 4582de3ef3

View File

@ -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);