Skip to content

Commit c2fb936

Browse files
authored
Merge pull request ceph#56640 from NitzanMordhai/wip-nitzan-public-addr-check-subnet-unreachable
common/pick_address: check if address in subnet all public address Reviewed-by: Radoslaw Zarzynski <[email protected]> Reviewed-by: Prashant D <[email protected]>
2 parents b25c182 + 3e2ef5e commit c2fb936

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/common/pick_address.cc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,24 @@ bool is_addr_in_subnet(
644644
{
645645
const auto nets = get_str_list(networks);
646646
ceph_assert(!nets.empty());
647-
const auto &net = nets.front();
648-
struct ifaddrs ifa;
647+
649648
unsigned ipv = CEPH_PICK_ADDRESS_IPV4;
650649
struct sockaddr_in public_addr;
651-
652-
ifa.ifa_next = nullptr;
653-
ifa.ifa_addr = (struct sockaddr*)&public_addr;
654650
public_addr.sin_family = AF_INET;
655-
inet_pton(AF_INET, addr.c_str(), &public_addr.sin_addr);
656651

657-
return matches_with_net(cct, ifa, net, ipv);
652+
if(inet_pton(AF_INET, addr.c_str(), &public_addr.sin_addr) != 1) {
653+
lderr(cct) << "unable to convert chosen address to string: " << addr << dendl;
654+
return false;
655+
}
656+
657+
for (const auto &net : nets) {
658+
struct ifaddrs ifa;
659+
memset(&ifa, 0, sizeof(ifa));
660+
ifa.ifa_next = nullptr;
661+
ifa.ifa_addr = (struct sockaddr*)&public_addr;
662+
if(matches_with_net(cct, ifa, net, ipv)) {
663+
return true;
664+
}
665+
}
666+
return false;
658667
}

0 commit comments

Comments
 (0)