]> git.ozlabs.org Git - petitboot/commitdiff
discover/network: Ensure interfaces have device before configuring
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Wed, 21 Dec 2016 04:46:09 +0000 (15:46 +1100)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Thu, 12 Jan 2017 04:37:17 +0000 (15:37 +1100)
Reorganise network_handle_nlmsg() slightly to create interface->dev just
before calling configure_interface() rather than only for brand new
interfaces. This ensures existing interfaces which have had ->dev
removed but receive a new configure event do not access a NULL pointer
during the configuration process.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/network.c

index c3cf30ac973b54f875d56356fc58910190240e0d..6ae44175ab134dd408f52060b20773b7e6884fbf 100644 (file)
@@ -214,13 +214,12 @@ static int network_send_link_query(struct network *network)
        return 0;
 }
 
-static void add_interface(struct network *network,
+static void create_interface_dev(struct network *network,
                struct interface *interface)
 {
        char *uuid = mac_bytes_to_string(interface, interface->hwaddr,
                                                sizeof(interface->hwaddr));
 
-       list_add(&network->interfaces, &interface->list);
        interface->dev = discover_device_create(network->handler, uuid,
                                                interface->name);
        interface->dev->device->type = DEVICE_TYPE_NETWORK;
@@ -563,7 +562,8 @@ 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);
+               list_add(&network->interfaces, &interface->list);
+               create_interface_dev(network, interface);
        }
 
        /* A repeated RTM_NEWLINK can represent an interface name change */
@@ -582,6 +582,9 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg)
                                interface->hwaddr, interface->name,
                                info->ifi_flags & IFF_LOWER_UP);
 
+       if (!interface->dev)
+               create_interface_dev(network, interface);
+
        configure_interface(network, interface,
                        info->ifi_flags & IFF_UP,
                        info->ifi_flags & IFF_LOWER_UP);