summaryrefslogtreecommitdiffstats
path: root/discover/parser.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-03-19 14:24:57 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-04-29 14:48:01 +1000
commit19dab336ae13f0476bfbf0db34f1329a802eeb8e (patch)
tree8af60e243d1306a909ec46f46fd9887c6641a8d6 /discover/parser.c
parent5e7c90eddd7ac2e4a3b05a7a5f6e29166edfa161 (diff)
downloadtalos-petitboot-19dab336ae13f0476bfbf0db34f1329a802eeb8e.tar.gz
talos-petitboot-19dab336ae13f0476bfbf0db34f1329a802eeb8e.zip
discover: Add configuration events & DHCP handler
This change adds a new event type, EVENT_ACTION_CONF. These events supply a new configuration URL that petitiboot should download and parse. With this in place, we can receive DHCP configuration events. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/parser.c')
-rw-r--r--discover/parser.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/discover/parser.c b/discover/parser.c
index c04a0af..42ee2e5 100644
--- a/discover/parser.c
+++ b/discover/parser.c
@@ -73,6 +73,28 @@ static char *local_path(struct discover_context *ctx,
return join_paths(ctx, ctx->device->mount_path, filename);
}
+static int download_config(struct discover_context *ctx, char **buf, int *len)
+{
+ unsigned tempfile;
+ const char *file;
+ int rc;
+
+ file = load_url(ctx, ctx->conf_url, &tempfile);
+ if (!file)
+ return -1;
+
+ rc = read_file(ctx, file, buf, len);
+ if (rc)
+ goto out_clean;
+
+ return 0;
+
+out_clean:
+ if (tempfile)
+ unlink(file);
+ return -1;
+}
+
static void iterate_parser_files(struct discover_context *ctx,
const struct parser *parser)
{
@@ -100,11 +122,13 @@ static void iterate_parser_files(struct discover_context *ctx,
void iterate_parsers(struct discover_context *ctx, enum conf_method method)
{
- int i;
+ int rc, i, len;
+ char *buf;
pb_log("trying parsers for %s\n", ctx->device->device->id);
- if (method == CONF_METHOD_LOCAL_FILE) {
+ switch (method) {
+ case CONF_METHOD_LOCAL_FILE:
for (i = 0; i < n_parsers; i++) {
if (parsers[i]->method != CONF_METHOD_LOCAL_FILE)
continue;
@@ -114,6 +138,27 @@ void iterate_parsers(struct discover_context *ctx, enum conf_method method)
iterate_parser_files(ctx, ctx->parser);
}
ctx->parser = NULL;
+ break;
+
+ case CONF_METHOD_DHCP:
+ rc = download_config(ctx, &buf, &len);
+ if (rc)
+ return;
+
+ for (i = 0; i < n_parsers; i++) {
+ if (parsers[i]->method != method)
+ continue;
+
+ pb_log("\ttrying parser '%s'\n", parsers[i]->name);
+ ctx->parser = parsers[i];
+ parsers[i]->parse(ctx, buf, len);
+ }
+
+ break;
+
+ case CONF_METHOD_UNKNOWN:
+ break;
+
}
}
OpenPOWER on IntegriCloud