Просмотр исходного кода

totemsrp: Revert totemsrp_get_ifaces() changes

In my enthusiasm for removing code while integrating knet I
also deleted the correct code for returning IP address for a node,
so that only the IP addres of the local node was ever returned.

This commit restores the the previous code.

Also, because we always return INTERFACE_MAX interfaces now (they don't
have to be contiguous) set ss_family to zero if that interface is not
in use so that downstream apps know and don't display a lot of 0.0.0.0

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
Christine Caulfield 8 лет назад
Родитель
Сommit
1ca72a1154
7 измененных файлов с 86 добавлено и 22 удалено
  1. 4 1
      exec/cfg.c
  2. 3 0
      exec/totempg.c
  3. 41 10
      exec/totemsrp.c
  4. 16 2
      lib/cfg.c
  5. 6 2
      tools/corosync-cfgtool.c
  6. 7 2
      tools/corosync-cpgtool.c
  7. 9 5
      tools/corosync-quorumtool.c

+ 4 - 1
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;

+ 3 - 0
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]));

+ 41 - 10
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;
 
-	*iface_count = INTERFACE_MAX;
+	memset(interfaces, 0, sizeof(struct totem_ip_address) * interfaces_size);
 
-	if (interfaces_size >= *iface_count) {
-		for (i=0; i<INTERFACE_MAX; i++) {
-			if (instance->totem_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));
-			}
+	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 = -2;
+		res = -1;
 	}
 
+	*iface_count = INTERFACE_MAX;
+
+finish:
 	totemnet_ifaces_get(instance->totemnet_context, status, iface_count);
 	return (res);
 }

+ 16 - 2
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;

+ 6 - 2
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) {

+ 7 - 2
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) {

+ 9 - 5
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; i<numaddrs; i++) {
 
-		if (i) {
-			buf[bufptr++] = ',';
-			buf[bufptr++] = ' ';
-		}
-
 		ss = (struct sockaddr_storage *)addrs[i].address;
 
+		if (!ss->ss_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,