summaryrefslogtreecommitdiffstats
path: root/discover/network.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-09-19 22:04:12 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-09-19 22:07:09 +0800
commitb324b03e2b603dafddfaac607e5f98d9cd9c0f04 (patch)
treea891c13e9d4644ff36d0f32b4c46aca8bfa76bd5 /discover/network.c
parent4400b62c78526cf744d2aec3fba86911da936f7a (diff)
downloadtalos-petitboot-b324b03e2b603dafddfaac607e5f98d9cd9c0f04.tar.gz
talos-petitboot-b324b03e2b603dafddfaac607e5f98d9cd9c0f04.zip
discover: register network devices with the device handler
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>
Diffstat (limited to 'discover/network.c')
-rw-r--r--discover/network.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/discover/network.c b/discover/network.c
index eaf6d1b..c853a97 100644
--- a/discover/network.c
+++ b/discover/network.c
@@ -11,6 +11,7 @@
#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>
@@ -19,6 +20,7 @@
#include "file.h"
#include "network.h"
+#include "device-handler.h"
#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 discover_device *dev;
};
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(
@@ -142,10 +146,16 @@ static void add_interface(struct network *network,
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);
}
@@ -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);
- remove_interface(interface);
+ remove_interface(network, interface);
return 0;
}
@@ -481,13 +491,15 @@ static void network_init_dns(struct network *network)
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;
- network = talloc(ctx, struct network);
+ network = talloc(handler, struct network);
list_init(&network->interfaces);
+ network->handler = handler;
network->manual_config = false;
network->dry_run = dry_run;
OpenPOWER on IntegriCloud