]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonMap: improve ambiguous addr behavior
authorSage Weil <sage@redhat.com>
Fri, 7 Dec 2018 16:23:16 +0000 (10:23 -0600)
committerSage Weil <sage@redhat.com>
Thu, 3 Jan 2019 17:17:31 +0000 (11:17 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/MonMap.cc

index 7fa26a1705f2882607d2347cec488e6d90e0eae1..5ce5a93e41a4f252634cb7fd594203ec4dbbfb9d 100644 (file)
@@ -369,30 +369,40 @@ void MonMap::_add_ambiguous_addr(const string& name,
     }
   } else {
     // no v1: or v2: prefix specified
-    if (addr.get_port() == 0) {
-      // no port; try both msgr2 and legacy
+    if (addr.get_port() == CEPH_MON_PORT_LEGACY) {
+      // legacy port implies legacy addr
+      addr.set_type(entity_addr_t::TYPE_LEGACY);
+      if (!contains(addr)) {
+       add(name + "-legacy", entity_addrvec_t(addr));
+      }
+    } else if (addr.get_port() == CEPH_MON_PORT_IANA) {
+      // iana port implies msgr2 addr
       addr.set_type(entity_addr_t::TYPE_MSGR2);
-      addr.set_port(CEPH_MON_PORT_IANA);
       if (!contains(addr)) {
        add(name, entity_addrvec_t(addr));
       }
-      addr.set_type(entity_addr_t::TYPE_LEGACY);
-      addr.set_port(CEPH_MON_PORT_LEGACY);
+    } else if (addr.get_port() == 0) {
+      // no port; try both msgr2 and legacy ports
+      addr.set_type(entity_addr_t::TYPE_MSGR2);
+      addr.set_port(CEPH_MON_PORT_IANA);
       if (!contains(addr)) {
-       add(name + "-legacy", entity_addrvec_t(addr));
+       add(name, entity_addrvec_t(addr));
       }
-    } else if (addr.get_port() == CEPH_MON_PORT_LEGACY) {
-      // legacy port implies legacy addr
       addr.set_type(entity_addr_t::TYPE_LEGACY);
+      addr.set_port(CEPH_MON_PORT_LEGACY);
       if (!contains(addr)) {
        add(name + "-legacy", entity_addrvec_t(addr));
       }
     } else {
-      // assume msgr2
+      // try both msgr2 and legacy on specified port
       addr.set_type(entity_addr_t::TYPE_MSGR2);
       if (!contains(addr)) {
        add(name, entity_addrvec_t(addr), priority);
       }
+      addr.set_type(entity_addr_t::TYPE_LEGACY);
+      if (!contains(addr)) {
+       add(name + "-legacy", entity_addrvec_t(addr), priority);
+      }
     }
   }
 }
@@ -531,8 +541,11 @@ int MonMap::init_with_config_file(const ConfigProxy& conf,
              << ": error " << res << std::endl;
       continue;
     }
+    // the 'mon addr' field is a legacy field, so assume anything
+    // there on a weird port is a v1 address, and do not handle
+    // addrvecs.
     entity_addr_t addr;
-    if (!addr.parse(val.c_str())) {
+    if (!addr.parse(val.c_str(), nullptr, entity_addr_t::TYPE_LEGACY)) {
       errout << "unable to parse address for mon." << mon_name
              << ": addr='" << val << "'" << std::endl;
       continue;