]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/pick_address: check if address in subnet all public address 57590/head
authornmordech@redhat.com <nmordech@redhat.com>
Tue, 2 Apr 2024 15:57:41 +0000 (15:57 +0000)
committerNitzan Mordechai <nmordech@redhat.com>
Tue, 21 May 2024 05:21:31 +0000 (05:21 +0000)
When mon trying to check if osd joining within subnet address,
it will check only the first subnet and not the rest of the subnets.
this fix will loop over all the other subnet for checks.

Fixes: https://tracker.ceph.com/issues/65186
Signed-off-by: Nitzan Mordechai <nmordec@redhat.com>
(cherry picked from commit 3e2ef5ec2be7a9662458db63fa1bcac08611d727)

src/common/pick_address.cc

index 2fd076808ac74b2b8737260c4b5c37cd3fa4bf7d..c92f2c4bc0236a112202685a314681fd4a2f4211 100644 (file)
@@ -638,15 +638,24 @@ bool is_addr_in_subnet(
 {
   const auto nets = get_str_list(networks);
   ceph_assert(!nets.empty());
-  const auto &net = nets.front();
-  struct ifaddrs ifa;
+
   unsigned ipv = CEPH_PICK_ADDRESS_IPV4;
   struct sockaddr_in public_addr;
-
-  ifa.ifa_next = nullptr;
-  ifa.ifa_addr = (struct sockaddr*)&public_addr;
   public_addr.sin_family = AF_INET;
-  inet_pton(AF_INET, addr.c_str(), &public_addr.sin_addr);
 
-  return matches_with_net(cct, ifa, net, ipv);
+  if(inet_pton(AF_INET, addr.c_str(), &public_addr.sin_addr) != 1) {
+    lderr(cct) << "unable to convert chosen address to string: " << addr << dendl;
+    return false;
+  }
+
+  for (const auto &net : nets) {
+    struct ifaddrs ifa;
+    memset(&ifa, 0, sizeof(ifa));
+    ifa.ifa_next = nullptr;
+    ifa.ifa_addr = (struct sockaddr*)&public_addr;
+    if(matches_with_net(cct, ifa, net, ipv)) {
+      return true;
+    }
+  }
+  return false;
 }