From b0d8043a72af22648c058382c46a132264736aaa Mon Sep 17 00:00:00 2001 From: Gu Zhongyan Date: Fri, 26 Jan 2018 16:19:50 +0800 Subject: [PATCH] common/pick_address: wrong prefix_len in pick_iface() 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/pick_address.cc b/src/common/pick_address.cc index a775bb2f66e8a..a115c0021eb3b 100644 --- a/src/common/pick_address.cc +++ b/src/common/pick_address.cc @@ -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); -- 2.39.5