]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/msg/Messenger.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / msg / Messenger.cc
index 6ab2862dc412a1948977d38da92142df97f38458..efeab3902b56717f0ab5e210968a7e0a0fcdcc6f 100644 (file)
@@ -1,11 +1,11 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 
-#include <random>
 #include <netdb.h>
-#include "include/Spinlock.h"
 
 #include "include/types.h"
+#include "include/random.h"
+
 #include "Messenger.h"
 
 #include "msg/simple/SimpleMessenger.h"
@@ -16,9 +16,8 @@
 
 Messenger *Messenger::create_client_messenger(CephContext *cct, string lname)
 {
-  std::string public_msgr_type = cct->_conf->ms_public_type.empty() ? cct->_conf->get_val<std::string>("ms_type") : cct->_conf->ms_public_type;
-  uint64_t nonce = 0;
-  get_random_bytes((char*)&nonce, sizeof(nonce));
+  std::string public_msgr_type = cct->_conf->ms_public_type.empty() ? cct->_conf.get_val<std::string>("ms_type") : cct->_conf->ms_public_type;
+  auto nonce = ceph::util::generate_random_number<uint64_t>();
   return Messenger::create(cct, public_msgr_type, entity_name_t::CLIENT(),
                           std::move(lname), nonce, 0);
 }
@@ -29,13 +28,7 @@ Messenger *Messenger::create(CephContext *cct, const string &type,
 {
   int r = -1;
   if (type == "random") {
-    static std::random_device seed;
-    static std::default_random_engine random_engine(seed());
-    static Spinlock random_lock;
-
-    std::lock_guard<Spinlock> lock(random_lock);
-    std::uniform_int_distribution<> dis(0, 1);
-    r = dis(random_engine);
+    r = ceph::util::generate_random_number(0, 1);
   }
   if (r == 0 || type == "simple")
     return new SimpleMessenger(cct, name, std::move(lname), nonce);
@@ -50,6 +43,26 @@ Messenger *Messenger::create(CephContext *cct, const string &type,
   return nullptr;
 }
 
+/**
+ * Get the default crc flags for this messenger.
+ * but not yet dispatched.
+ */
+static int get_default_crc_flags(const ConfigProxy&);
+
+Messenger::Messenger(CephContext *cct_, entity_name_t w)
+  : trace_endpoint("0.0.0.0", 0, "Messenger"),
+    my_name(w),
+    default_send_priority(CEPH_MSG_PRIO_DEFAULT),
+    started(false),
+    magic(0),
+    socket_priority(-1),
+    cct(cct_),
+    crcflags(get_default_crc_flags(cct->_conf)),
+    auth_registry(cct)
+{
+  auth_registry.refresh_config();
+}
+
 void Messenger::set_endpoint_addr(const entity_addr_t& a,
                                   const entity_name_t &name)
 {
@@ -71,12 +84,15 @@ void Messenger::set_endpoint_addr(const entity_addr_t& a,
   trace_endpoint.set_port(a.get_port());
 }
 
-/*
+/**
+ * Get the default crc flags for this messenger.
+ * but not yet dispatched.
+ *
  * Pre-calculate desired software CRC settings.  CRC computation may
  * be disabled by default for some transports (e.g., those with strong
  * hardware checksum support).
  */
-int Messenger::get_default_crc_flags(md_config_t * conf)
+int get_default_crc_flags(const ConfigProxy& conf)
 {
   int r = 0;
   if (conf->ms_crc_data)
@@ -85,3 +101,66 @@ int Messenger::get_default_crc_flags(md_config_t * conf)
     r |= MSG_CRC_HEADER;
   return r;
 }
+
+int Messenger::bindv(const entity_addrvec_t& addrs)
+{
+  return bind(addrs.legacy_addr());
+}
+
+bool Messenger::ms_deliver_verify_authorizer(
+  Connection *con,
+  int peer_type,
+  int protocol,
+  bufferlist& authorizer,
+  bufferlist& authorizer_reply,
+  bool& isvalid,
+  CryptoKey& session_key,
+  std::string *connection_secret,
+  std::unique_ptr<AuthAuthorizerChallenge> *challenge)
+{
+  if (authorizer.length() == 0) {
+    for (auto dis : dispatchers) {
+      if (!dis->require_authorizer) {
+       //ldout(cct,10) << __func__ << " tolerating missing authorizer" << dendl;
+       isvalid = true;
+       return true;
+      }
+    }
+  }
+  AuthAuthorizeHandler *ah = auth_registry.get_handler(peer_type, protocol);
+  if (get_mytype() == CEPH_ENTITY_TYPE_MON &&
+      peer_type != CEPH_ENTITY_TYPE_MON) {
+    // the monitor doesn't do authenticators for msgr1.
+    isvalid = true;
+    return true;
+  }
+  if (!ah) {
+    lderr(cct) << __func__ << " no AuthAuthorizeHandler found for protocol "
+              << protocol << dendl;
+    isvalid = false;
+    return false;
+  }
+
+  for (auto dis : dispatchers) {
+    KeyStore *ks = dis->ms_get_auth1_authorizer_keystore();
+    if (ks) {
+      isvalid = ah->verify_authorizer(
+       cct,
+       ks,
+       authorizer,
+       0,
+       &authorizer_reply,
+       &con->peer_name,
+       &con->peer_global_id,
+       &con->peer_caps_info,
+       &session_key,
+       connection_secret,
+       challenge);
+      if (isvalid) {
+       return dis->ms_handle_authentication(con)>=0;
+      }
+      return true;
+    }
+  }
+  return false;
+}