]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/pick_address: wrong prefix_len in pick_iface() 20128/head
authorGu Zhongyan <guzhongyan@360.cn>
Fri, 26 Jan 2018 08:19:50 +0000 (16:19 +0800)
committerGu Zhongyan <guzhongyan@360.cn>
Tue, 30 Jan 2018 10:37:34 +0000 (18:37 +0800)
With prefix_len initialized as zero, mask in netmask_ipv4/6()
will always be zero, so find_ip_in_subnet() always return the
first interface.
Set prefix_len to the right value to fetch the right interface.

Signed-off-by: Gu Zhongyan guzhongyan@360.cn
Signed-off-by: yupeng chen chenyupeng-it@360.cn
src/common/pick_address.cc

index a775bb2f66e8a0b72f81088a264174ba29d4e28d..a115c0021eb3ba30c00f9dc87e4102525de46e2b 100644 (file)
@@ -207,7 +207,7 @@ std::string pick_iface(CephContext *cct, const struct sockaddr_storage &network)
     return {};
   }
 
-  unsigned int prefix_len = 0;
+  const unsigned int prefix_len = max(sizeof(in_addr::s_addr), sizeof(in6_addr::s6_addr)) * CHAR_BIT;
   const struct ifaddrs *found = find_ip_in_subnet(ifa,
                                   (const struct sockaddr *) &network, prefix_len);