]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: osd: add a /0 cidr test for 32-bit...
authorGreg Farnum <gfarnum@redhat.com>
Thu, 21 Apr 2022 00:16:22 +0000 (00:16 +0000)
committerGreg Farnum <gfarnum@redhat.com>
Tue, 31 May 2022 23:33:38 +0000 (23:33 +0000)
...and make the OSDMap handle it.

Signed-off-by: Greg Farnum <gfarnum@redhat.com>
(cherry picked from commit c454d0d1d3f6d4ea4962a746cbed20d1aa003f6e)

src/osd/OSDMap.cc
src/test/osd/TestOSDMap.cc

index 1aca8c389f37cd37efc69f38b734ccaa5f1d111c..6e5caf53a1ae008cb12d076b5ae4eaec730cc339 100644 (file)
@@ -1398,7 +1398,11 @@ void OSDMap::range_bits::parse(const entity_addr_t& addr) {
     ipv6 = true;
   } else if (addr.is_ipv4()) {
     bits.ipv4.ip_32_bits = ntohl(addr.in4_addr().sin_addr.s_addr);
-    bits.ipv4.mask = UINT32_MAX << (32-addr.get_nonce());
+    if (addr.get_nonce() > 0) {
+      bits.ipv4.mask = UINT32_MAX << (32-addr.get_nonce());
+    } else {
+      bits.ipv4.mask = 0;
+    }
   } else {
     // uh...
   }
index 9ccbaedd82967075e8672b510bd854b139b7cf7e..dabb1a1c0d7463eeb5ea09061f7c98746aa80f99 100644 (file)
@@ -2229,7 +2229,7 @@ TEST_F(OSDMapTest, blocklisting_ranges) {
   }
 }
 
-TEST_F(OSDMapTest, blocklisting_weirder) {
+TEST_F(OSDMapTest, blocklisting_everything) {
   set_up_map(6); //whatever
   OSDMap::Incremental range_blocklist_inc(osdmap.get_epoch() + 1);
   entity_addr_t baddr;
@@ -2260,6 +2260,38 @@ TEST_F(OSDMapTest, blocklisting_weirder) {
     }
     ASSERT_TRUE(blocklisted);
   }
+
+  OSDMap::Incremental swap_blocklist_inc(osdmap.get_epoch()+1);
+  swap_blocklist_inc.old_range_blocklist.push_back(baddr);
+
+  entity_addr_t caddr;
+  caddr.parse("1.1.1.1/0");
+  caddr.type = entity_addr_t::TYPE_CIDR;
+  swap_blocklist_inc.new_range_blocklist[caddr] = ceph_clock_now();
+  osdmap.apply_incremental(swap_blocklist_inc);
+
+  for (const auto& a: ip_addrs) {
+    entity_addr_t addr;
+    addr.parse(a);
+    addr.set_type(entity_addr_t::TYPE_LEGACY);
+    if (!addr.is_ipv4()) continue;
+    bool blocklisted = osdmap.is_blocklisted(addr, g_ceph_context);
+    if (!blocklisted) {
+      cout << "erroneously not  blocklisted " << addr << std::endl;
+    }
+    ASSERT_TRUE(blocklisted);
+  }
+  for (const auto& a: unblocked_ip_addrs) {
+    entity_addr_t addr;
+    addr.parse(a);
+    addr.set_type(entity_addr_t::TYPE_LEGACY);
+    if (!addr.is_ipv4()) continue;
+    bool blocklisted = osdmap.is_blocklisted(addr, g_ceph_context);
+    if (!blocklisted) {
+      cout << "erroneously not  blocklisted " << addr << std::endl;
+    }
+    ASSERT_TRUE(blocklisted);
+  }
 }
 
 INSTANTIATE_TEST_CASE_P(