[PATCH v2 2/9] discover/sysinfo: Set IPv6 addresses

Samuel Mendoza-Jonas sam at mendozajonas.com
Thu May 24 14:47:35 AEST 2018


Signed-off-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
---
 discover/sysinfo.c      | 23 +++++++++++++++++++----
 ui/ncurses/nc-sysinfo.c |  3 +++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/discover/sysinfo.c b/discover/sysinfo.c
index 74d1eae..b7286f1 100644
--- a/discover/sysinfo.c
+++ b/discover/sysinfo.c
@@ -4,6 +4,7 @@
 #include <talloc/talloc.h>
 #include <process/process.h>
 #include <log/log.h>
+#include <url/url.h>
 
 #include "discover-server.h"
 #include "platform.h"
@@ -32,7 +33,7 @@ void system_info_set_interface_address(unsigned int hwaddr_size,
 {
 	struct interface_info *if_info;
 	unsigned int i;
-	char mac[20];
+	char mac[20], **if_addr, *new_addr, *subnet;
 
 	for (i = 0; i < sysinfo->n_interfaces; i++) {
 		if_info = sysinfo->interfaces[i];
@@ -43,12 +44,26 @@ void system_info_set_interface_address(unsigned int hwaddr_size,
 		if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
 			continue;
 
+		/*
+		 * Don't include the subnet from a static config, and check if
+		 * we're updating the IPv4 or IPv6 address.
+		 * */
+		if ((subnet = strchr(address, '/')))
+			new_addr = talloc_strndup(if_info, address, subnet - address);
+		else
+			new_addr = talloc_strdup(if_info, address);
+		if (addr_scheme(new_addr) == AF_INET)
+			if_addr = &if_info->address;
+		else
+			if_addr = &if_info->address_v6;
+
 		/* Found an existing interface. Notify clients if a new address
 		 * is set */
-		if (!if_info->address || strcmp(if_info->address, address)) {
-			talloc_free(if_info->address);
-			if_info->address = talloc_strdup(if_info, address);
+		if (!*if_addr || strcmp(*if_addr, address)) {
+			talloc_free(*if_addr);
+			*if_addr = new_addr;
 			discover_server_notify_system_info(server, sysinfo);
+			pb_log("ADDR: %s on %s\n", *if_addr, if_info->name);
 			return;
 		}
 	}
diff --git a/ui/ncurses/nc-sysinfo.c b/ui/ncurses/nc-sysinfo.c
index 8252b45..756f15d 100644
--- a/ui/ncurses/nc-sysinfo.c
+++ b/ui/ncurses/nc-sysinfo.c
@@ -131,6 +131,9 @@ static void sysinfo_screen_populate(struct sysinfo_screen *screen,
 		line("%s:", info->name);
 		line(_(" MAC:        %s"), macbuf);
 		line(_(" IP Address: %s"), info->address ?: _("none"));
+		if (info->address_v6)
+			line(_(" IPv6 Address: %s"),
+					info->address_v6 ?: _("none"));
 		/* TRANSLATORS: these "up" / "down" strings refer to the
 		 * link status for a network connection. */
 		line(_(" link:       %s"), info->link ? _("up") : _("down"));
-- 
2.17.0



More information about the Petitboot mailing list