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

Add a 'family' parameter to totemip_parse so it can be told to look for
either IPv4 or IPv6 addresses, or both.

As we get the (unambiguous) multicast address first, we can make sure we always
look for the right type of node address afterwards.


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1150 fd59a12c-fef9-0310-b244-a6a79926bd2f

Patrick Caulfield 19 лет назад
Родитель
Сommit
7eb9ed2c45
3 измененных файлов с 15 добавлено и 11 удалено
  1. 3 2
      exec/totemconfig.c
  2. 11 8
      exec/totemip.c
  3. 1 1
      exec/totemip.h

+ 3 - 2
exec/totemconfig.c

@@ -228,7 +228,7 @@ extern int totem_config_read (
 		 * Get interface multicast address
 		 */
 		if (!objdb_get_string (objdb, object_interface_handle, "mcastaddr", &str)) {
-			res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str);
+			res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str, 0);
 		}
 
 		/*
@@ -243,7 +243,8 @@ extern int totem_config_read (
 		 */
 		if (!objdb_get_string (objdb, object_interface_handle, "bindnetaddr", &str)) {
 
-			res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str);
+			res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str,
+					     totem_config->interfaces[ringnumber].mcast_addr.family);
 		}
 		totem_config->interface_count++;
 	}

+ 11 - 8
exec/totemip.c

@@ -80,7 +80,7 @@ void totemip_nosigpipe(int s)
 	int on = 1;
 	setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on));
 }
-#endif 
+#endif
 
 /* Compare two addresses */
 int totemip_equal(struct totem_ip_address *addr1, struct totem_ip_address *addr2)
@@ -238,8 +238,10 @@ int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr,
 	return ret;
 }
 
-/* Converts an address string string into a totem_ip_address */
-int totemip_parse(struct totem_ip_address *totemip, char *addr)
+/* Converts an address string string into a totem_ip_address.
+   family can be AF_INET, AF_INET6 or 0 ("for "don't care")
+*/
+int totemip_parse(struct totem_ip_address *totemip, char *addr, int family)
 {
 	struct addrinfo *ainfo;
 	struct addrinfo ahints;
@@ -250,6 +252,7 @@ int totemip_parse(struct totem_ip_address *totemip, char *addr)
 	memset(&ahints, 0, sizeof(ahints));
 	ahints.ai_socktype = SOCK_DGRAM;
 	ahints.ai_protocol = IPPROTO_UDP;
+	ahints.ai_family   = family;
 
 	/* Lookup the nodename address */
 	ret = getaddrinfo(addr, NULL, &ahints, &ainfo);
@@ -301,7 +304,7 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
 {
 #define NEXT_IFR(a)	((struct ifreq *)((u_char *)&(a)->ifr_addr +\
 	((a)->ifr_addr.sa_len ? (a)->ifr_addr.sa_len : sizeof((a)->ifr_addr))))
-	
+
 	struct sockaddr_in *intf_addr_mask;
 	struct sockaddr_storage bindnet_ss, intf_addr_ss;
 	struct sockaddr_in *intf_addr_sin = (struct sockaddr_in *)&intf_addr_ss;
@@ -341,7 +344,7 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
 	 * Find interface address to bind to
 	 */
 	lifr = (struct ifreq *)ifc.ifc_buf + (ifc.ifc_len / sizeof(*lifr));
-	
+
 	for (ifr = ifc.ifc_req; ifr < lifr; ifr = NEXT_IFR(ifr)) {
 		strcpy(ifrb.ifr_name, ifr->ifr_name);
 
@@ -349,7 +352,7 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
 		 */
 		if (ioctl(id_fd, SIOCGIFADDR, &ifrb) < 0)
 			continue;
-			
+
 		memcpy(&intf_addr_ss, &ifrb.ifr_addr, sizeof(intf_addr_ss));
 		if (intf_addr_sin->sin_family == AF_INET) {
 			/* Retrieve mask
@@ -362,7 +365,7 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
 			if ( bindnet_sin->sin_family == AF_INET &&
 				 (intf_addr_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr) ==
 			     (bindnet_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr)) {
-	
+
 				totemip_copy(boundto, bindnet);
 				memcpy(boundto->addr, &intf_addr_sin->sin_addr, sizeof(intf_addr_sin->sin_addr));
 
@@ -390,7 +393,7 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
 	}
 	free (ifc.ifc_buf);
 	close (id_fd);
-	
+
 	return (res);
 }
 #elif defined(OPENAIS_LINUX)

+ 1 - 1
exec/totemip.h

@@ -70,7 +70,7 @@ extern const char *totemip_print(struct totem_ip_address *addr);
 extern int totemip_sockaddr_to_totemip_convert(struct sockaddr_storage *saddr, struct totem_ip_address *ip_addr);
 extern int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr,
 					       uint16_t port, struct sockaddr_storage *saddr, int *addrlen);
-extern int totemip_parse(struct totem_ip_address *totemip, char *addr);
+extern int totemip_parse(struct totem_ip_address *totemip, char *addr, int family);
 extern int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num);
 
 /* These two simulate a zero in_addr by clearing the family field */