Преглед изворни кода

Make ifaces_get work with dynamic no_rings

Commit which added number of addresses to srp_address structure didn't
count with totemsrp_ifaces_get where whole structure was copied instead
of addresses only. This is now fixed.

Also to make API totempg forward compatible, size of interfaces array
must be passed to ifaces_get like functions to prevent memory overwrite.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Jan Friesse пре 14 година
родитељ
комит
e925f42165
8 измењених фајлова са 37 додато и 6 уклоњено
  1. 2 1
      exec/cfg.c
  2. 2 0
      exec/totemmrp.c
  3. 1 0
      exec/totemmrp.h
  4. 5 1
      exec/totempg.c
  5. 24 4
      exec/totemsrp.c
  6. 1 0
      exec/totemsrp.h
  7. 1 0
      include/corosync/coroapi.h
  8. 1 0
      include/corosync/totem/totempg.h

+ 2 - 1
exec/cfg.c

@@ -553,6 +553,7 @@ static void message_handler_req_lib_cfg_ringstatusget (
 	api->totem_ifaces_get (
 		api->totem_nodeid_get(),
 		interfaces,
+		INTERFACE_MAX,
 		&status,
 		&iface_count);
 
@@ -801,7 +802,7 @@ 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, &status, &num_interfaces);
+	api->totem_ifaces_get(nodeid, node_ifs, INTERFACE_MAX, &status, &num_interfaces);
 
 	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;

+ 2 - 0
exec/totemmrp.c

@@ -196,6 +196,7 @@ void totemmrp_event_signal (enum totem_event_type type, int value)
 int totemmrp_ifaces_get (
 	unsigned int nodeid,
 	struct totem_ip_address *interfaces,
+	unsigned int interfaces_size,
 	char ***status,
 	unsigned int *iface_count)
 {
@@ -205,6 +206,7 @@ int totemmrp_ifaces_get (
 		totemsrp_context,
 		nodeid,
 		interfaces,
+		interfaces_size,
 		status,
 		iface_count);
 

+ 1 - 0
exec/totemmrp.h

@@ -106,6 +106,7 @@ extern void totemmrp_event_signal (enum totem_event_type type, int value);
 extern int totemmrp_ifaces_get (
 	unsigned int nodeid,
 	struct totem_ip_address *interfaces,
+	unsigned int interfaces_size,
 	char ***status,
 	unsigned int *iface_count);
 

+ 5 - 1
exec/totempg.c

@@ -1359,6 +1359,7 @@ int totempg_groups_send_ok_groups (
 int totempg_ifaces_get (
 	unsigned int nodeid,
 	struct totem_ip_address *interfaces,
+	unsigned int interfaces_size,
 	char ***status,
 	unsigned int *iface_count)
 {
@@ -1367,6 +1368,7 @@ int totempg_ifaces_get (
 	res = totemmrp_ifaces_get (
 		nodeid,
 		interfaces,
+		interfaces_size,
 		status,
 		iface_count);
 
@@ -1415,11 +1417,13 @@ const char *totempg_ifaces_print (unsigned int nodeid)
 
 	iface_string[0] = '\0';
 
-	res = totempg_ifaces_get (nodeid, interfaces, &status, &iface_count);
+	res = totempg_ifaces_get (nodeid, interfaces, INTERFACE_MAX, &status, &iface_count);
 	if (res == -1) {
 		return ("no interface found for nodeid");
 	}
 
+	res = totempg_ifaces_get (nodeid, interfaces, INTERFACE_MAX, &status, &iface_count);
+
 	for (i = 0; i < iface_count; i++) {
 		sprintf (one_iface, "r(%d) ip(%s) ",
 			i, totemip_print (&interfaces[i]));

+ 24 - 4
exec/totemsrp.c

@@ -987,10 +987,19 @@ void totemsrp_finalize (
 	free (instance);
 }
 
+/*
+ * Return configured interfaces. interfaces is array of totem_ip addresses allocated by caller,
+ * with interaces_size number of items. iface_count is final number of interfaces filled by this
+ * function.
+ *
+ * Function returns 0 on success, otherwise if interfaces array is not big enough, -2 is returned,
+ * and if interface was not found, -1 is returned.
+ */
 int totemsrp_ifaces_get (
 	void *srp_context,
 	unsigned int nodeid,
 	struct totem_ip_address *interfaces,
+	unsigned int interfaces_size,
 	char ***status,
 	unsigned int *iface_count)
 {
@@ -1007,9 +1016,15 @@ int totemsrp_ifaces_get (
 	}
 
 	if (found) {
-		memcpy (interfaces, &instance->my_memb_list[i],
-			sizeof (struct srp_addr));
 		*iface_count = instance->totem_config->interface_count;
+
+		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;
 	}
 
@@ -1021,9 +1036,14 @@ int totemsrp_ifaces_get (
 	}
 
 	if (found) {
-		memcpy (interfaces, &instance->my_left_memb_list[i],
-			sizeof (struct srp_addr));
 		*iface_count = instance->totem_config->interface_count;
+
+		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;
 	}

+ 1 - 0
exec/totemsrp.h

@@ -103,6 +103,7 @@ extern int totemsrp_ifaces_get (
 	void *srp_context,
 	unsigned int nodeid,
 	struct totem_ip_address *interfaces,
+	unsigned int interfaces_size,
 	char ***status,
 	unsigned int *iface_count);
 

+ 1 - 0
include/corosync/coroapi.h

@@ -234,6 +234,7 @@ struct corosync_api_v1 {
 	int (*totem_ifaces_get) (
 		unsigned int nodeid,
 		struct totem_ip_address *interfaces,
+		unsigned int interfaces_size,
 		char ***status,
 		unsigned int *iface_count);
 

+ 1 - 0
include/corosync/totem/totempg.h

@@ -140,6 +140,7 @@ extern int totempg_groups_send_ok_groups (
 extern int totempg_ifaces_get (
 	unsigned int nodeid,
         struct totem_ip_address *interfaces,
+        unsigned int interfaces_size,
 	char ***status,
         unsigned int *iface_count);