From 8ce92d0c3f8195bfdbd63148983c0e55e340765d Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Mon, 1 Apr 2019 22:24:31 +0800 Subject: [PATCH] crimson/net: clean auth related interfaces Signed-off-by: Yingxin Cheng --- src/crimson/auth/AuthServer.h | 16 +++++++--------- src/crimson/net/Messenger.h | 8 ++++---- src/crimson/net/ProtocolV2.cc | 28 +++++++++++++--------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/crimson/auth/AuthServer.h b/src/crimson/auth/AuthServer.h index e15d47bb159..ce24bd95336 100644 --- a/src/crimson/auth/AuthServer.h +++ b/src/crimson/auth/AuthServer.h @@ -19,15 +19,13 @@ public: virtual ~AuthServer() {} // Get authentication methods and connection modes for the given peer type - virtual void get_supported_auth_methods( - int peer_type, - std::vector *methods, - std::vector *modes = nullptr) { - // auth_registry.get_supported_methods(peer_type, methods, modes); - *methods = { CEPH_AUTH_NONE }; - if (modes != nullptr) { - *modes = { CEPH_CON_MODE_CRC }; - } + virtual std::pair, std::vector> + get_supported_auth_methods( + int peer_type) { + // std::vector methods; + // std::vector modes; + // auth_registry.get_supported_methods(peer_type, &methods, &modes); + return {{CEPH_AUTH_NONE}, {CEPH_AUTH_NONE}}; } // Get support connection modes for the given peer type and auth method diff --git a/src/crimson/net/Messenger.h b/src/crimson/net/Messenger.h index fd423482e2b..76328f80119 100644 --- a/src/crimson/net/Messenger.h +++ b/src/crimson/net/Messenger.h @@ -37,10 +37,8 @@ class Messenger { entity_addrvec_t my_addrs; uint32_t global_seq = 0; uint32_t crc_flags = 0; - - public: - ceph::auth::AuthClient *auth_client = 0; - ceph::auth::AuthServer *auth_server = 0; + ceph::auth::AuthClient* auth_client = nullptr; + ceph::auth::AuthServer* auth_server = nullptr; public: Messenger(const entity_name_t& name) @@ -97,9 +95,11 @@ class Messenger { crc_flags |= MSG_CRC_HEADER; } + ceph::auth::AuthClient* get_auth_client() const { return auth_client; } void set_auth_client(ceph::auth::AuthClient *ac) { auth_client = ac; } + ceph::auth::AuthServer* get_auth_server() const { return auth_server; } void set_auth_server(ceph::auth::AuthServer *as) { auth_server = as; } diff --git a/src/crimson/net/ProtocolV2.cc b/src/crimson/net/ProtocolV2.cc index 038733f57c7..3d74b9ca9db 100644 --- a/src/crimson/net/ProtocolV2.cc +++ b/src/crimson/net/ProtocolV2.cc @@ -464,8 +464,8 @@ seastar::future<> ProtocolV2::handle_auth_reply() "allowed methods={}, allowed modes={}", conn, bad_method.method(), cpp_strerror(bad_method.result()), bad_method.allowed_methods(), bad_method.allowed_modes()); - ceph_assert(messenger.auth_client); - int r = messenger.auth_client->handle_auth_bad_method( + ceph_assert(messenger.get_auth_client()); + int r = messenger.get_auth_client()->handle_auth_bad_method( conn.shared_from_this(), auth_meta, bad_method.method(), bad_method.result(), bad_method.allowed_methods(), bad_method.allowed_modes()); @@ -483,9 +483,9 @@ seastar::future<> ProtocolV2::handle_auth_reply() auto auth_more = AuthReplyMoreFrame::Decode(rx_segments_data.back()); logger().debug("{} auth reply more len={}", conn, auth_more.auth_payload().length()); - ceph_assert(messenger.auth_client); + ceph_assert(messenger.get_auth_client()); ceph::bufferlist reply; - int r = messenger.auth_client->handle_auth_reply_more( + int r = messenger.get_auth_client()->handle_auth_reply_more( conn.shared_from_this(), auth_meta, auth_more.auth_payload(), &reply); if (r < 0) { logger().error("{} auth_client handle_auth_reply_more returned {}", @@ -502,8 +502,8 @@ seastar::future<> ProtocolV2::handle_auth_reply() .then([this] { // handle_auth_done() logic auto auth_done = AuthDoneFrame::Decode(rx_segments_data.back()); - ceph_assert(messenger.auth_client); - int r = messenger.auth_client->handle_auth_done( + ceph_assert(messenger.get_auth_client()); + int r = messenger.get_auth_client()->handle_auth_done( conn.shared_from_this(), auth_meta, auth_done.global_id(), auth_done.con_mode(), @@ -530,11 +530,11 @@ seastar::future<> ProtocolV2::handle_auth_reply() seastar::future<> ProtocolV2::client_auth(std::vector &allowed_methods) { // send_auth_request() logic - ceph_assert(messenger.auth_client); + ceph_assert(messenger.get_auth_client()); bufferlist bl; vector preferred_modes; - int r = messenger.auth_client->get_auth_request( + int r = messenger.get_auth_client()->get_auth_request( conn.shared_from_this(), auth_meta, &auth_meta->auth_method, &preferred_modes, &bl); if (r < 0) { @@ -810,10 +810,8 @@ seastar::future<> ProtocolV2::_auth_bad_method(int r) { // _auth_bad_method() logic ceph_assert(r < 0); - std::vector allowed_methods; - std::vector allowed_modes; - messenger.auth_server->get_supported_auth_methods( - conn.get_peer_type(), &allowed_methods, &allowed_modes); + auto [allowed_methods, allowed_modes] = + messenger.get_auth_server()->get_supported_auth_methods(conn.get_peer_type()); logger().warn("{} send AuthBadMethod(auth_method={}, r={}, " "allowed_methods={}, allowed_modes={})", conn, auth_meta->auth_method, cpp_strerror(r), @@ -829,9 +827,9 @@ seastar::future<> ProtocolV2::_auth_bad_method(int r) seastar::future<> ProtocolV2::_handle_auth_request(bufferlist& auth_payload, bool more) { // _handle_auth_request() logic - ceph_assert(messenger.auth_server); + ceph_assert(messenger.get_auth_server()); bufferlist reply; - int r = messenger.auth_server->handle_auth_request( + int r = messenger.get_auth_server()->handle_auth_request( conn.shared_from_this(), auth_meta, more, auth_meta->auth_method, auth_payload, &reply); @@ -887,7 +885,7 @@ seastar::future<> ProtocolV2::server_auth() conn, request.method(), request.preferred_modes(), request.auth_payload().length()); auth_meta->auth_method = request.method(); - auth_meta->con_mode = messenger.auth_server->pick_con_mode( + auth_meta->con_mode = messenger.get_auth_server()->pick_con_mode( conn.get_peer_type(), auth_meta->auth_method, request.preferred_modes()); if (auth_meta->con_mode == CEPH_CON_MODE_UNKNOWN) { -- 2.39.5