const struct sockaddr *find_ip_in_subnet_list(
CephContext *cct,
const struct ifaddrs *ifa,
+ unsigned ipv,
const std::string &networks,
const std::string &interfaces)
{
exit(1);
}
+ switch (net.ss_family) {
+ case AF_INET:
+ if (!(ipv & CEPH_PICK_ADDRESS_IPV4)) {
+ continue;
+ }
+ break;
+ case AF_INET6:
+ if (!(ipv & CEPH_PICK_ADDRESS_IPV6)) {
+ continue;
+ }
+ break;
+ }
+
const struct ifaddrs *found = find_ip_in_subnet(
filtered,
(struct sockaddr *) &net, prefix_len);
const string interfaces,
const char *conf_var)
{
- const struct sockaddr *found = find_ip_in_subnet_list(cct, ifa, networks,
- interfaces);
+ const struct sockaddr *found = find_ip_in_subnet_list(
+ cct,
+ ifa,
+ CEPH_PICK_ADDRESS_IPV4|CEPH_PICK_ADDRESS_IPV6,
+ networks,
+ interfaces);
if (!found) {
lderr(cct) << "unable to find any IP address in networks '" << networks
<< "' interfaces '" << interfaces << "'" << dendl;
class CephContext;
-#define CEPH_PICK_ADDRESS_PUBLIC 0x01
-#define CEPH_PICK_ADDRESS_CLUSTER 0x02
+#define CEPH_PICK_ADDRESS_PUBLIC 0x01
+#define CEPH_PICK_ADDRESS_CLUSTER 0x02
+#define CEPH_PICK_ADDRESS_MSGR1 0x04
+#define CEPH_PICK_ADDRESS_MSGR2 0x08
+#define CEPH_PICK_ADDRESS_IPV4 0x10
+#define CEPH_PICK_ADDRESS_IPV6 0x20
+#define CEPH_PICK_ADDRESS_PREFER_IPV4 0x40
+#define CEPH_PICK_ADDRESS_DEFAULT_MON_PORTS 0x80
/*
Pick addresses based on subnets if needed.
const struct sockaddr *find_ip_in_subnet_list(
CephContext *cct,
const struct ifaddrs *ifa,
+ unsigned ipv,
const std::string &networks,
const std::string &interfaces);
TEST(pick_address, find_ip_in_subnet_list)
{
- struct ifaddrs one, two;
+ struct ifaddrs one, two, three;
struct sockaddr_in a_one;
struct sockaddr_in a_two;
+ struct sockaddr_in6 a_three;
const struct sockaddr *result;
one.ifa_next = &two;
one.ifa_addr = (struct sockaddr*)&a_one;
one.ifa_name = eth0;
- two.ifa_next = NULL;
+ two.ifa_next = &three;
two.ifa_addr = (struct sockaddr*)&a_two;
two.ifa_name = eth1;
+ three.ifa_next = NULL;
+ three.ifa_addr = (struct sockaddr*)&a_three;
+ three.ifa_name = eth1;
+
ipv4(&a_one, "10.1.1.2");
ipv4(&a_two, "10.2.1.123");
+ ipv6(&a_three, "2001:1234:5678:90ab::cdef");
// match by network
result = find_ip_in_subnet_list(
g_ceph_context,
&one,
+ CEPH_PICK_ADDRESS_IPV4,
"10.1.0.0/16",
"eth0");
ASSERT_EQ((struct sockaddr*)&a_one, result);
result = find_ip_in_subnet_list(
g_ceph_context,
&one,
+ CEPH_PICK_ADDRESS_IPV4,
"10.2.0.0/16",
"eth1");
ASSERT_EQ((struct sockaddr*)&a_two, result);
result = find_ip_in_subnet_list(
g_ceph_context,
&one,
+ CEPH_PICK_ADDRESS_IPV4,
"10.0.0.0/8",
"eth0");
ASSERT_EQ((struct sockaddr*)&a_one, result);
result = find_ip_in_subnet_list(
g_ceph_context,
&one,
+ CEPH_PICK_ADDRESS_IPV4,
"10.0.0.0/8",
"eth1");
ASSERT_EQ((struct sockaddr*)&a_two, result);
+
+ result = find_ip_in_subnet_list(
+ g_ceph_context,
+ &one,
+ CEPH_PICK_ADDRESS_IPV6,
+ "2001::/16",
+ "eth1");
+ ASSERT_EQ((struct sockaddr*)&a_three, result);
}