discover: bring network interfaces down in network_shutdown
authorJeremy Kerr <jk@ozlabs.org>
Sat, 1 Jun 2013 09:50:00 +0000 (19:50 +1000)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 24 Jun 2013 05:07:57 +0000 (13:07 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/network.c

index 4a4f93252f5a1f02693222e2ca1d6560d2a0995b..23bf1ee190e13070195d0a3d09cc8c2eda811a11 100644 (file)
@@ -134,26 +134,42 @@ static int network_send_link_query(struct network *network)
        return 0;
 }
 
-static int interface_up(struct network *network, struct interface *interface)
+static int interface_change(struct network *network,
+               struct interface *interface,
+               bool up)
 {
        int rc;
+       const char *statestr = up ? "up" : "down";
        const char *argv[] = {
                pb_system_apps.ip,
                "link",
                "set",
                interface->name,
-               "up",
+               statestr,
                NULL,
        };
 
        rc = pb_run_cmd(argv, 1, network->dry_run);
        if (rc) {
-               pb_log("failed to bring interface %s up\n", interface->name);
+               pb_log("failed to bring interface %s %s\n", interface->name,
+                               statestr);
                return -1;
        }
        return 0;
 }
 
+static int interface_up(struct network *network,
+               struct interface *interface)
+{
+       return interface_change(network, interface, true);
+}
+
+static int interface_down(struct network *network,
+               struct interface *interface)
+{
+       return interface_change(network, interface, false);
+}
+
 static void configure_interface_dhcp(struct network *network,
                struct interface *interface)
 {
@@ -417,9 +433,14 @@ err:
 
 int network_shutdown(struct network *network)
 {
+       struct interface *interface;
+
        if (network->waiter)
                waiter_remove(network->waiter);
 
+       list_for_each_entry(&network->interfaces, interface, list)
+               interface_down(network, interface);
+
        close(network->netlink_sd);
        talloc_free(network);
        return 0;