sysinfo: Add interface link status to sysinfo data
authorJeremy Kerr <jk@ozlabs.org>
Mon, 16 Dec 2013 02:49:29 +0000 (10:49 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 18 Dec 2013 01:52:42 +0000 (09:52 +0800)
This changes adds a 'link' parameter to the interface information sent
in sysinfo messages. The discover network code populates this from the
incoming netlink messages.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/network.c
discover/sysinfo.c
discover/sysinfo.h
lib/pb-protocol/pb-protocol.c
lib/types/types.h

index bc7e186a1921e8531bb2fd37ed026f5e47e5977e..7ddecc03b658a59e88e00bfcf9156114ca7f13c6 100644 (file)
@@ -416,14 +416,15 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg)
                memcpy(interface->hwaddr, ifaddr, sizeof(interface->hwaddr));
                strncpy(interface->name, ifname, sizeof(interface->name) - 1);
                add_interface(network, interface);
-
-               /* tell the sysinfo code about this interface */
-               if (strcmp(interface->name, "lo"))
-                       system_info_register_interface(
-                                       sizeof(interface->hwaddr),
-                                       interface->hwaddr, interface->name);
        }
 
+       /* notify the sysinfo code about changes to this interface */
+       if (strcmp(interface->name, "lo"))
+               system_info_register_interface(
+                               sizeof(interface->hwaddr),
+                               interface->hwaddr, interface->name,
+                               info->ifi_flags & IFF_LOWER_UP);
+
        configure_interface(network, interface,
                        info->ifi_flags & IFF_UP,
                        info->ifi_flags & IFF_LOWER_UP);
index 3c132774e21b3599e0c61e45b6ceaba5ebb847c3..be4543832265a964ceea26124dbcdc1a8d85a2c9 100644 (file)
@@ -18,12 +18,14 @@ const struct system_info *system_info_get(void)
 }
 
 void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
-               const char *name)
+               const char *name, bool link)
 {
        struct interface_info *if_info;
        unsigned int i;
 
        for (i = 0; i < sysinfo->n_interfaces; i++) {
+               bool changed = false;
+
                if_info = sysinfo->interfaces[i];
 
                if (if_info->hwaddr_size != hwaddr_size)
@@ -32,10 +34,22 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
                if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
                        continue;
 
-               /* update the name and we're done */
-               talloc_free(if_info->name);
-               if_info->name = talloc_strdup(if_info, name);
-               discover_server_notify_system_info(server, sysinfo);
+               /* Found an existing interface. Notify clients on any name or
+                * link changes */
+               if (strcmp(if_info->name, name)) {
+                       talloc_free(if_info->name);
+                       if_info->name = talloc_strdup(if_info, name);
+                       changed = true;
+               }
+
+               if (if_info->link != link) {
+                       if_info->link = link;
+                       changed = true;
+               }
+
+               if (changed)
+                       discover_server_notify_system_info(server, sysinfo);
+
                return;
        }
 
@@ -43,6 +57,7 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
        if_info->hwaddr_size = hwaddr_size;
        if_info->hwaddr = talloc_memdup(if_info, hwaddr, hwaddr_size);
        if_info->name = talloc_strdup(if_info, name);
+       if_info->link = link;
 
        sysinfo->n_interfaces++;
        sysinfo->interfaces = talloc_realloc(sysinfo, sysinfo->interfaces,
index d8ba33db9fd12c4faddfb0ea5711ad2cb0867c48..7181c99cd42080cf7edd1a6e327b048e617bae48 100644 (file)
@@ -7,8 +7,8 @@ struct discover_server;
 
 const struct system_info *system_info_get(void);
 
-void system_info_register_interface(unsigned hwaddr_size, uint8_t *hwaddr,
-               const char *name);
+void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
+               const char *name, bool link);
 void system_info_register_blockdev(const char *name, const char *uuid,
                const char *mountpoint);
 
index 091fab722f102e9d9c186e8bec6900146737bcce..5a1cee7a417bc648e883a0c3020f0c42c640430d 100644 (file)
@@ -228,7 +228,8 @@ int pb_protocol_system_info_len(const struct system_info *sysinfo)
        for (i = 0; i < sysinfo->n_interfaces; i++) {
                struct interface_info *if_info = sysinfo->interfaces[i];
                len +=  4 + if_info->hwaddr_size +
-                       4 + optional_strlen(if_info->name);
+                       4 + optional_strlen(if_info->name) +
+                       sizeof(if_info->link);
        }
 
        for (i = 0; i < sysinfo->n_blockdevs; i++) {
@@ -384,6 +385,9 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
                pos += if_info->hwaddr_size;
 
                pos += pb_protocol_serialise_string(pos, if_info->name);
+
+               *(bool *)pos = if_info->link;
+               pos += sizeof(bool);
        }
 
        *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs);
@@ -765,6 +769,9 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
                if (read_string(if_info, &pos, &len, &if_info->name))
                        goto out;
 
+               if_info->link = *(bool *)pos;
+               pos += sizeof(if_info->link);
+
                sysinfo->interfaces[i] = if_info;
        }
 
index d2a2918c7b3fe2cd077219ab6319b87c5d1dde01..3a76cdaa751b6e0230e761c97df46942542efc0a 100644 (file)
@@ -64,6 +64,7 @@ struct interface_info {
        unsigned int    hwaddr_size;
        uint8_t         *hwaddr;
        char            *name;
+       bool            link;
 };
 
 struct blockdev_info {