discover/sysinfo: Set IPv6 addresses
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Wed, 23 May 2018 06:25:25 +0000 (16:25 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 10 Jul 2018 04:42:56 +0000 (14:42 +1000)
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/sysinfo.c
ui/ncurses/nc-sysinfo.c

index 74d1eae573f230a53ea018aab36a713d34686d84..8497959320296b0b2f0e371a24c78d99099188cf 100644 (file)
@@ -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,11 +44,24 @@ 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);
                        return;
                }
index 8252b4529586329fe99da95c06f04dfe50dbf281..756f15dac14c4cf2dcf15f18f260c5371a9a55b4 100644 (file)
@@ -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"));