From 89a6c39e94166131f14198ee7830555661173495 Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Thu, 28 Feb 2019 11:02:04 +0000 Subject: [PATCH] pick_address: error out in dual stack mode if both addr types cannot be provided When ms_bind_ipv4 and ms_bind_ipv6 options are enabled, if the public_network or cluster_network settings only contain networks of a single type (either IPv4 or IPv6) then pick_addresses function must fail. Fixes: http://tracker.ceph.com/issues/38307 Signed-off-by: Ricardo Dias --- src/common/pick_address.cc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/common/pick_address.cc b/src/common/pick_address.cc index a009a5b18647b..7b284925d51fc 100644 --- a/src/common/pick_address.cc +++ b/src/common/pick_address.cc @@ -339,31 +339,33 @@ int pick_addresses( } if (addr.is_blank_ip() && !networks.empty()) { + int ipv4_r = !(ipv & CEPH_PICK_ADDRESS_IPV4) ? 0 : -1; + int ipv6_r = !(ipv & CEPH_PICK_ADDRESS_IPV6) ? 0 : -1; // first try on preferred numa node (if >= 0), then anywhere. while (true) { // note: pass in ipv to filter the matching addresses - int r = 0; if ((ipv & CEPH_PICK_ADDRESS_IPV4) && (flags & CEPH_PICK_ADDRESS_PREFER_IPV4)) { - r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV4, networks, - interfaces, addrs, preferred_numa_node); + ipv4_r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV4, + networks, interfaces, addrs, + preferred_numa_node); } - if (r >= 0 && - (ipv & CEPH_PICK_ADDRESS_IPV6)) { - r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV6, networks, - interfaces, addrs, preferred_numa_node); + if (ipv & CEPH_PICK_ADDRESS_IPV6) { + ipv6_r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV6, + networks, interfaces, addrs, + preferred_numa_node); } - if (r >= 0 && - (ipv & CEPH_PICK_ADDRESS_IPV4) && + if ((ipv & CEPH_PICK_ADDRESS_IPV4) && !(flags & CEPH_PICK_ADDRESS_PREFER_IPV4)) { - r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV4, networks, - interfaces, addrs, preferred_numa_node); + ipv4_r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV4, + networks, interfaces, addrs, + preferred_numa_node); } - if (r >= 0) { + if (ipv4_r >= 0 && ipv6_r >= 0) { break; } if (preferred_numa_node < 0) { - return r; + return ipv4_r >= 0 && ipv6_r >= 0 ? 0 : -1; } preferred_numa_node = -1; // try any numa node } -- 2.39.5