exit(1);
}
- const struct sockaddr *found = find_ip_in_subnet(ifa, (struct sockaddr *) &net, prefix_len);
+ const struct ifaddrs *found = find_ip_in_subnet(ifa,
+ (struct sockaddr *) &net, prefix_len);
if (found)
- return found;
+ return found->ifa_addr;
}
return NULL;
freeifaddrs(ifa);
}
+
+std::string pick_iface(CephContext *cct, const struct sockaddr_storage &network)
+{
+ struct ifaddrs *ifa;
+ int r = getifaddrs(&ifa);
+ if (r < 0) {
+ string err = cpp_strerror(errno);
+ lderr(cct) << "unable to fetch interfaces and addresses: " << err << dendl;
+ return {};
+ }
+
+ unsigned int prefix_len = 0;
+ const struct ifaddrs *found = find_ip_in_subnet(ifa,
+ (const struct sockaddr *) &network, prefix_len);
+
+ std::string result;
+ if (found) {
+ result = found->ifa_name;
+ }
+
+ freeifaddrs(ifa);
+
+ return result;
+}
+
+
bool have_local_addr(CephContext *cct, const list<entity_addr_t>& ls, entity_addr_t *match)
{
struct ifaddrs *ifa;
*/
void pick_addresses(CephContext *cct, int needs);
+/**
+ * Find a network interface whose address matches the address/netmask
+ * in `network`.
+ */
+std::string pick_iface(CephContext *cct, const struct sockaddr_storage &network);
+
/**
* check for a locally configured address
*
#include "common/ceph_time.h"
#include "common/version.h"
#include "common/io_priority.h"
+#include "common/pick_address.h"
#include "os/ObjectStore.h"
#ifdef HAVE_LIBFUSE
collect_sys_info(pm, cct);
+ std::string front_iface, back_iface;
+ /*
+ pick_iface(cct,
+ CEPH_PICK_ADDRESS_PUBLIC | CEPH_PICK_ADDRESS_CLUSTER,
+ &front_iface, &back_iface);
+ */
+ (*pm)["front_iface"] = pick_iface(cct,
+ client_messenger->get_myaddr().get_sockaddr_storage());
+ (*pm)["back_iface"] = pick_iface(cct,
+ cluster_messenger->get_myaddr().get_sockaddr_storage());
+
dout(10) << __func__ << " " << *pm << dendl;
}