]> git.ozlabs.org Git - petitboot/blobdiff - discover/network.c
discover/network: Manage network->interfaces with {add,remove}_interface
[petitboot] / discover / network.c
index 28e3a29cb2b3621beb3c7ea69c6a06927fc86fe0..eaf6d1b4e3e9d6b4283ac6a534692f8098bd69d1 100644 (file)
@@ -138,6 +138,18 @@ static int network_send_link_query(struct network *network)
        return 0;
 }
 
+static void add_interface(struct network *network,
+               struct interface *interface)
+{
+       list_add(&network->interfaces, &interface->list);
+}
+
+static void remove_interface(struct interface *interface)
+{
+       list_remove(&interface->list);
+       talloc_free(interface);
+}
+
 static int interface_change(struct interface *interface, bool up)
 {
        const char *statestr = up ? "up" : "down";
@@ -325,6 +337,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg)
        struct interface *interface;
        struct ifinfomsg *info;
        struct rtattr *attr;
+       unsigned int mtu;
        uint8_t ifaddr[6];
        char ifname[IFNAMSIZ+1];
        int attrlen, type;
@@ -355,19 +368,22 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg)
                        strncpy(ifname, data, IFNAMSIZ);
                        have_ifname = true;
                        break;
+
+               case IFLA_MTU:
+                       mtu = *(unsigned int *)data;
+                       break;
                }
        }
 
        if (!have_ifaddr || !have_ifname)
                return -1;
 
-       if (type == RTM_DELLINK) {
+       if (type == RTM_DELLINK || mtu == 0) {
                interface = find_interface_by_ifindex(network, info->ifi_index);
                if (!interface)
                        return 0;
                pb_log("network: interface %s removed\n", interface->name);
-               list_remove(&interface->list);
-               talloc_free(interface);
+               remove_interface(interface);
                return 0;
        }
 
@@ -379,6 +395,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg)
                interface->state = IFSTATE_NEW;
                memcpy(interface->hwaddr, ifaddr, sizeof(interface->hwaddr));
                strncpy(interface->name, ifname, sizeof(interface->name) - 1);
+               add_interface(network, interface);
        }
 
        configure_interface(network, interface,