diff --git a/exec/cfg.c b/exec/cfg.c index ad524af6..dfc18c6e 100644 --- a/exec/cfg.c +++ b/exec/cfg.c @@ -1012,7 +1012,10 @@ static void message_handler_req_lib_cfg_get_node_addrs (void *conn, if (nodeid == 0) nodeid = api->totem_nodeid_get(); - api->totem_ifaces_get(nodeid, node_ifs, INTERFACE_MAX, &status, &num_interfaces); + if (api->totem_ifaces_get(nodeid, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) { + ret = CS_ERR_EXIST; + num_interfaces = 0; + } res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN); res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS; diff --git a/exec/totempg.c b/exec/totempg.c index a40b195b..d030510c 100644 --- a/exec/totempg.c +++ b/exec/totempg.c @@ -1479,6 +1479,9 @@ const char *totempg_ifaces_print (unsigned int nodeid) res = totempg_ifaces_get (nodeid, interfaces, INTERFACE_MAX, NULL, &iface_count); for (i = 0; i < iface_count; i++) { + if (!interfaces[i].family) { + continue; + } snprintf (one_iface, ONE_IFACE_LEN, "r(%d) ip(%s) ", i, totemip_print (&interfaces[i])); diff --git a/exec/totemsrp.c b/exec/totemsrp.c index 78b158d3..2439f466 100644 --- a/exec/totemsrp.c +++ b/exec/totemsrp.c @@ -1037,23 +1037,54 @@ int totemsrp_ifaces_get ( { struct totemsrp_instance *instance = (struct totemsrp_instance *)srp_context; int res = 0; + unsigned int found = 0; int i; + memset(interfaces, 0, sizeof(struct totem_ip_address) * interfaces_size); + + for (i = 0; i < instance->my_memb_entries; i++) { + if (instance->my_memb_list[i].addr[0].nodeid == nodeid) { + found = 1; + break; + } + } + + if (found) { + *iface_count = INTERFACE_MAX; + + if (interfaces_size >= *iface_count) { + memcpy (interfaces, instance->my_memb_list[i].addr, + sizeof (struct totem_ip_address) * *iface_count); + } else { + res = -2; + } + + goto finish; + } + + for (i = 0; i < instance->my_left_memb_entries; i++) { + if (instance->my_left_memb_list[i].addr[0].nodeid == nodeid) { + found = 1; + break; + } + } + + if (found) { + *iface_count = INTERFACE_MAX; + + if (interfaces_size >= *iface_count) { + memcpy (interfaces, instance->my_left_memb_list[i].addr, + sizeof (struct totem_ip_address) * *iface_count); + } else { + res = -2; + } + } else { + res = -1; + } + *iface_count = INTERFACE_MAX; - if (interfaces_size >= *iface_count) { - for (i=0; itotem_config->interfaces[i].configured) { - memcpy (&interfaces[i], &instance->my_id.addr[i], - sizeof (struct totem_ip_address)); - } else { - memset (&interfaces[i], 0, sizeof (struct totem_ip_address)); - } - } - } else { - res = -2; - } - +finish: totemnet_ifaces_get(instance->totemnet_context, status, iface_count); return (res); } diff --git a/lib/cfg.c b/lib/cfg.c index 6b2f8d81..6d5069f6 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -494,12 +494,14 @@ cs_error_t corosync_cfg_get_node_addrs ( struct iovec iov; const char *addr_buf; char response_buf[IPC_RESPONSE_SIZE]; + char zeroes[sizeof(struct sockaddr_storage)]; error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst)); if (error != CS_OK) { return (error); } + memset(zeroes, 0, sizeof(zeroes)); req_lib_cfg_get_node_addrs.header.size = sizeof (req_lib_cfg_get_node_addrs); req_lib_cfg_get_node_addrs.header.id = MESSAGE_REQ_CFG_GET_NODE_ADDRS; @@ -533,14 +535,26 @@ cs_error_t corosync_cfg_get_node_addrs ( if (res_lib_cfg_get_node_addrs->family == AF_INET) { in = (struct sockaddr_in *)addrs[i].address; - in->sin_family = AF_INET; + if (memcmp(addr_buf, zeroes, addrlen) == 0) { + in->sin_family = 0; + } else { + in->sin_family = AF_INET; + } memcpy(&in->sin_addr, addr_buf, sizeof(struct in_addr)); } if (res_lib_cfg_get_node_addrs->family == AF_INET6) { in6 = (struct sockaddr_in6 *)addrs[i].address; - in6->sin6_family = AF_INET6; + + if (memcmp(addr_buf, zeroes, addrlen) == 0) { + in6->sin6_family = 0; + } else { + in6->sin6_family = AF_INET6; + } memcpy(&in6->sin6_addr, addr_buf, sizeof(struct in6_addr)); } + + /* Mark it as unused */ + } *num_addrs = res_lib_cfg_get_node_addrs->num_addrs; errno = error = res_lib_cfg_get_node_addrs->header.error; diff --git a/tools/corosync-cfgtool.c b/tools/corosync-cfgtool.c index a8c092f2..55250893 100644 --- a/tools/corosync-cfgtool.c +++ b/tools/corosync-cfgtool.c @@ -216,10 +216,14 @@ static void showaddrs_do(unsigned int nodeid) struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addrs[i].address; void *saddr; - if (ss->ss_family == AF_INET6) + if (!ss->ss_family) { + continue; + } + if (ss->ss_family == AF_INET6) { saddr = &sin6->sin6_addr; - else + } else { saddr = &sin->sin_addr; + } inet_ntop(ss->ss_family, saddr, buf, sizeof(buf)); if (i != 0) { diff --git a/tools/corosync-cpgtool.c b/tools/corosync-cpgtool.c index 8ab0c3c8..b52a35b1 100644 --- a/tools/corosync-cpgtool.c +++ b/tools/corosync-cpgtool.c @@ -75,10 +75,15 @@ static void fprint_addrs(FILE *f, unsigned int nodeid) struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addrs[i].address; void *saddr; - if (ss->ss_family == AF_INET6) + if (!ss->ss_family) { + continue; + } + + if (ss->ss_family == AF_INET6) { saddr = &sin6->sin6_addr; - else + } else { saddr = &sin->sin_addr; + } inet_ntop(ss->ss_family, saddr, buf, sizeof(buf)); if (i != 0) { diff --git a/tools/corosync-quorumtool.c b/tools/corosync-quorumtool.c index f5eccf12..9d0fae00 100644 --- a/tools/corosync-quorumtool.c +++ b/tools/corosync-quorumtool.c @@ -349,19 +349,23 @@ static const char *node_name(uint32_t nodeid, name_format_t name_format) for (i=start_addr; iss_family) { + continue; + } + if (ss->ss_family == AF_INET6) { addrlen = sizeof(struct sockaddr_in6); } else { addrlen = sizeof(struct sockaddr_in); } + if (i) { + buf[bufptr++] = ','; + buf[bufptr++] = ' '; + } + if (!getnameinfo( (struct sockaddr *)addrs[i].address, addrlen, buf+bufptr, sizeof(buf)-bufptr,