]> git.ozlabs.org Git - petitboot/commitdiff
discover: register network devices with the device handler
authorJeremy Kerr <jk@ozlabs.org>
Thu, 19 Sep 2013 14:04:12 +0000 (22:04 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 19 Sep 2013 14:07:09 +0000 (22:07 +0800)
We'd like to correlate incoming network boot options with a device, so
register the interface with the device hander.

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

index eaf6d1b4e3e9d6b4283ac6a534692f8098bd69d1..c853a97b0cf21d8350f702d3c83dac780a79c3b5 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <log/log.h>
 #include <list/list.h>
 
 #include <log/log.h>
 #include <list/list.h>
+#include <types/types.h>
 #include <talloc/talloc.h>
 #include <waiter/waiter.h>
 #include <pb-config/pb-config.h>
 #include <talloc/talloc.h>
 #include <waiter/waiter.h>
 #include <pb-config/pb-config.h>
@@ -19,6 +20,7 @@
 
 #include "file.h"
 #include "network.h"
 
 #include "file.h"
 #include "network.h"
+#include "device-handler.h"
 
 #define HWADDR_SIZE    6
 #define PIDFILE_BASE   (LOCAL_STATE_DIR "/petitboot/")
 
 #define HWADDR_SIZE    6
 #define PIDFILE_BASE   (LOCAL_STATE_DIR "/petitboot/")
@@ -47,14 +49,16 @@ struct interface {
 
        struct list_item list;
        struct process *udhcpc_process;
 
        struct list_item list;
        struct process *udhcpc_process;
+       struct discover_device *dev;
 };
 
 struct network {
 };
 
 struct network {
-       struct list     interfaces;
-       struct waiter   *waiter;
-       int             netlink_sd;
-       bool            manual_config;
-       bool            dry_run;
+       struct list             interfaces;
+       struct device_handler   *handler;
+       struct waiter           *waiter;
+       int                     netlink_sd;
+       bool                    manual_config;
+       bool                    dry_run;
 };
 
 static const struct interface_config *find_config_by_hwaddr(
 };
 
 static const struct interface_config *find_config_by_hwaddr(
@@ -142,10 +146,16 @@ static void add_interface(struct network *network,
                struct interface *interface)
 {
        list_add(&network->interfaces, &interface->list);
                struct interface *interface)
 {
        list_add(&network->interfaces, &interface->list);
+       interface->dev = discover_device_create(network->handler,
+                                       interface->name);
+       interface->dev->device->type = DEVICE_TYPE_NETWORK;
+       device_handler_add_device(network->handler, interface->dev);
 }
 
 }
 
-static void remove_interface(struct interface *interface)
+static void remove_interface(struct network *network,
+               struct interface *interface)
 {
 {
+       device_handler_remove(network->handler, interface->dev);
        list_remove(&interface->list);
        talloc_free(interface);
 }
        list_remove(&interface->list);
        talloc_free(interface);
 }
@@ -383,7 +393,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg)
                if (!interface)
                        return 0;
                pb_log("network: interface %s removed\n", interface->name);
                if (!interface)
                        return 0;
                pb_log("network: interface %s removed\n", interface->name);
-               remove_interface(interface);
+               remove_interface(network, interface);
                return 0;
        }
 
                return 0;
        }
 
@@ -481,13 +491,15 @@ static void network_init_dns(struct network *network)
        talloc_free(buf);
 }
 
        talloc_free(buf);
 }
 
-struct network *network_init(void *ctx, struct waitset *waitset, bool dry_run)
+struct network *network_init(struct device_handler *handler,
+               struct waitset *waitset, bool dry_run)
 {
        struct network *network;
        int rc;
 
 {
        struct network *network;
        int rc;
 
-       network = talloc(ctx, struct network);
+       network = talloc(handler, struct network);
        list_init(&network->interfaces);
        list_init(&network->interfaces);
+       network->handler = handler;
        network->manual_config = false;
        network->dry_run = dry_run;
 
        network->manual_config = false;
        network->dry_run = dry_run;
 
index c90af40eb170b8ae0fbe03c363f7c98613fb4e49..912174f4392badc0e03bd44ffdc65a9571ad97ea 100644 (file)
@@ -2,9 +2,11 @@
 #define NETWORK_H
 
 struct network;
 #define NETWORK_H
 
 struct network;
+struct device_handler;
 struct waitset;
 
 struct waitset;
 
-struct network *network_init(void *ctx, struct waitset *waitset, bool dry_run);
+struct network *network_init(struct device_handler *handler,
+               struct waitset *waitset, bool dry_run);
 int network_shutdown(struct network *network);
 
 #endif /* NETWORK_H */
 int network_shutdown(struct network *network);
 
 #endif /* NETWORK_H */
index 26df9b3ff3f6062f9bdc85c85ae1dde068cc8e92..6def0900bc73cddf56397c67641825899e8abde1 100644 (file)
@@ -173,20 +173,21 @@ int main(int argc, char *argv[])
 
        config_init(NULL);
 
 
        config_init(NULL);
 
-       network = network_init(server, waitset, opts.dry_run == opt_yes);
-       if (!network)
-               return EXIT_FAILURE;
-
        handler = device_handler_init(server, waitset, opts.dry_run == opt_yes);
        if (!handler)
                return EXIT_FAILURE;
 
        discover_server_set_device_source(server, handler);
 
        handler = device_handler_init(server, waitset, opts.dry_run == opt_yes);
        if (!handler)
                return EXIT_FAILURE;
 
        discover_server_set_device_source(server, handler);
 
+       /* init our device sources: udev, network and user events */
        udev = udev_init(waitset, handler);
        if (!udev)
                return EXIT_FAILURE;
 
        udev = udev_init(waitset, handler);
        if (!udev)
                return EXIT_FAILURE;
 
+       network = network_init(handler, waitset, opts.dry_run == opt_yes);
+       if (!network)
+               return EXIT_FAILURE;
+
        uev = user_event_init(waitset, handler);
        if (!uev)
                return EXIT_FAILURE;
        uev = user_event_init(waitset, handler);
        if (!uev)
                return EXIT_FAILURE;