From: Daniel Nurmi <nurmi@eucalyptus.com>
Date: Thu, 13 Jun 2024 02:32:09 +0000
Subject: Resolve issue of interfaces not being able to have more than one IP
 address assigned.

Bug-Ubuntu: https://launchpad.net/bugs/717166
Last-Updated: 2017-01-20
---
 common/discover.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/common/discover.c b/common/discover.c
index 0c5ad39..86da10b 100644
--- a/common/discover.c
+++ b/common/discover.c
@@ -615,6 +615,7 @@ discover_interfaces(int state) {
 
 	/* Cycle through the list of interfaces looking for IP addresses. */
 	while (next_iface(&info, &err, &ifaces)) {
+		struct ifaddrs *ifaddr, *ifa;
 
 		/* See if we've seen an interface that matches this one. */
 		for (tmp = interfaces; tmp; tmp = tmp->next) {
@@ -658,9 +659,22 @@ discover_interfaces(int state) {
 			(*dhcp_interface_discovery_hook)(tmp);
 		}
 
-		if ((info.addr.ss_family == AF_INET) &&
-		    (local_family == AF_INET)) {
-			struct sockaddr_in *a = (struct sockaddr_in*)&info.addr;
+		getifaddrs(&ifaddr);
+		for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+
+		    char *s=NULL;
+
+		    s = strchr(ifa->ifa_name, ':');
+		    if (s != NULL) {
+		        *s = '\0';
+		    }
+		    if (strcmp(ifa->ifa_name, info.name))
+		        continue;
+		    if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET
+		        && local_family == AF_INET)
+		    {
+			struct sockaddr_in *a =
+			    (struct sockaddr_in *)ifa->ifa_addr;
 			struct iaddr addr;
 
 			/* We don't want the loopback interface. */
@@ -683,12 +697,14 @@ discover_interfaces(int state) {
 			if (dhcp_interface_setup_hook) {
 				(*dhcp_interface_setup_hook)(tmp, &addr);
 			}
-		}
+		    }
 #ifdef DHCPv6
-		else if ((info.addr.ss_family == AF_INET6) &&
-			 (local_family == AF_INET6)) {
+		    else if (ifa->ifa_addr
+			     && ifa->ifa_addr->sa_family == AF_INET6
+		             && local_family == AF_INET6)
+		    {
 			struct sockaddr_in6 *a =
-					(struct sockaddr_in6*)&info.addr;
+					(struct sockaddr_in6*)ifa->ifa_addr;
 			struct iaddr addr;
 
 			/* We don't want the loopback interface. */
@@ -711,8 +727,9 @@ discover_interfaces(int state) {
 			if (dhcp_interface_setup_hook) {
 				(*dhcp_interface_setup_hook)(tmp, &addr);
 			}
-		}
+		    }
 #endif /* DHCPv6 */
+		}
 	}
 
 	if (err) {
