From 2bdab228492bcc71c6ff071b8fe744a2aed6b8a9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 23 May 2018 17:37:00 -0500 Subject: [PATCH] mon/MonClient: make connection check more robust Do no rely on the address comparison; just check the Connection* itself. Signed-off-by: Sage Weil --- src/mon/MonClient.cc | 7 +++---- src/mon/MonClient.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 9cf96f20fe1..b53ee2fe14b 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -271,9 +271,8 @@ bool MonClient::ms_dispatch(Message *m) Mutex::Locker lock(monc_lock); if (_hunting()) { - auto pending_con = pending_cons.find(m->get_source_addr()); - if (pending_con == pending_cons.end() || - pending_con->second.get_con() != m->get_connection()) { + auto p = _find_pending_con(m->get_connection()); + if (p == pending_cons.end()) { // ignore any messages outside hunting sessions ldout(cct, 10) << "discarding stray monitor message " << *m << dendl; m->put(); @@ -541,7 +540,7 @@ void MonClient::handle_auth(MAuthReply *m) } // hunting - auto found = pending_cons.find(m->get_source_addr()); + auto found = _find_pending_con(m->get_connection()); assert(found != pending_cons.end()); int auth_err = found->second.handle_auth(m, entity_name, want_keys, rotating_secrets.get()); diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index 688f13c91ce..dca43693a0f 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -216,6 +216,16 @@ private: void _add_conns(uint64_t global_id); void _send_mon_message(Message *m); + std::map::iterator _find_pending_con( + const ConnectionRef& con) { + for (auto i = pending_cons.begin(); i != pending_cons.end(); ++i) { + if (i->second.get_con() == con) { + return i; + } + } + return pending_cons.end(); + } + public: void set_entity_name(EntityName name) { entity_name = name; } -- 2.39.5