]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
auth: push con_mode selection into AuthRegistry helper
authorSage Weil <sage@redhat.com>
Mon, 18 Feb 2019 19:34:15 +0000 (13:34 -0600)
committerSage Weil <sage@redhat.com>
Wed, 20 Feb 2019 18:41:55 +0000 (12:41 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/auth/AuthRegistry.cc
src/auth/AuthRegistry.h
src/auth/AuthServer.h
src/msg/async/ProtocolV2.cc

index a7385a833a88e4de6c9de10209d31487fea7e5dc..f7483d56211d2fbc866d15378f813e9630690fbe 100644 (file)
@@ -249,6 +249,24 @@ void AuthRegistry::get_supported_modes(
   }
 }
 
+uint32_t AuthRegistry::pick_mode(
+  int peer_type,
+  uint32_t auth_method,
+  const std::vector<uint32_t>& preferred_modes)
+{
+  std::vector<uint32_t> allowed_modes;
+  get_supported_modes(peer_type, auth_method, &allowed_modes);
+  for (auto mode : preferred_modes) {
+    if (std::find(allowed_modes.begin(), allowed_modes.end(), mode)
+       != allowed_modes.end()) {
+      return mode;
+    }
+  }
+  ldout(cct,1) << "failed to pick con mode from client's " << preferred_modes
+              << " and our " << allowed_modes << dendl;
+  return CEPH_CON_MODE_UNKNOWN;
+}
+
 AuthAuthorizeHandler *AuthRegistry::get_handler(int peer_type, int method)
 {
   std::scoped_lock l{lock};
index 5474355110de9fc7a4ade5b03d46033afdac81d3..ae2cad4fcc3a3928a46abe499af4c12fb4110a6c 100644 (file)
@@ -56,6 +56,10 @@ public:
                           uint32_t auth_method,
                           std::vector<uint32_t> *modes);
 
+  uint32_t pick_mode(int peer_type,
+                    uint32_t auth_method,
+                    const std::vector<uint32_t>& preferred_modes);
+
   AuthAuthorizeHandler *get_handler(int peer_type, int method);
 
   const char** get_tracked_conf_keys() const override;
index 61a2650f192e977b47b465cf94c61b9a3e7b2c48..e3bc8787710e7f3024de30105d366582482aab60 100644 (file)
@@ -33,6 +33,14 @@ public:
     auth_registry.get_supported_modes(peer_type, auth_method, modes);
   }
 
+  /// Get support connection modes for the given peer type and auth method
+  virtual uint32_t pick_con_mode(
+    int peer_type,
+    uint32_t auth_method,
+    const std::vector<uint32_t>& preferred_modes) {
+    return auth_registry.pick_mode(peer_type, auth_method, preferred_modes);
+  }
+
   /// return an AuthAuthorizeHandler for the given peer type and auth method
   AuthAuthorizeHandler *get_auth_authorize_handler(
     int peer_type,
index ce2ef6490b55636fcbc120a330b482af7ad249fc..712686b598b1e805fb1ee793268be53ee56fdc6e 100644 (file)
@@ -2443,22 +2443,10 @@ CtPtr ProtocolV2::handle_auth_request(char *payload, uint32_t length) {
                  << ", payload_len=" << request.auth_payload().length() << ")"
                  << dendl;
   auth_meta->auth_method = request.method();
-
-  // select a connection mode
-  auto& preferred_modes = request.preferred_modes();
-  std::vector<uint32_t> allowed_modes;
-  messenger->auth_server->get_supported_con_modes(
-    connection->get_peer_type(), auth_meta->auth_method, &allowed_modes);
-  for (auto mode : preferred_modes) {
-    if (std::find(allowed_modes.begin(), allowed_modes.end(), mode)
-       != allowed_modes.end()) {
-      auth_meta->con_mode = mode;
-      break;
-    }
-  }
+  auth_meta->con_mode = messenger->auth_server->pick_con_mode(
+    connection->get_peer_type(), auth_meta->auth_method,
+    request.preferred_modes());
   if (auth_meta->con_mode == CEPH_CON_MODE_UNKNOWN) {
-    ldout(cct,1) << "failed to pick con mode from client's " << preferred_modes
-                << " and our " << allowed_modes << dendl;
     return _auth_bad_method(-EOPNOTSUPP);
   }
   return _handle_auth_request(request.auth_payload(), false);