+ /*
+ * value is of the form:
+ * boot_image [--name option_name ] [option args ...]
+ */
+ tmp = strtok_r(value, " ", &saveptr);
+ if (!tmp) {
+ pb_log("%s: malformed kernel statement\n", __func__);
+ break;
+ }
+
+ url = pxe_url_join(ctx->dc, ctx->dc->conf_url, tmp);
+ opt->boot_image = create_url_resource(opt, url);
+
+ tmp = strtok_r(NULL, " ", &saveptr);
+ if (!tmp)
+ continue;
+ if (streq(tmp, "--name")) {
+ tmp = strtok_r(NULL, " ", &saveptr);
+ name = talloc_asprintf(opt, "%s",
+ tmp ?: "malformed ipxe option");
+ args = strtok_r(NULL, " ", &saveptr);
+ } else
+ args = tmp;
+
+ while (args) {
+ pxe_append_string(opt, args);
+ args = strtok_r(NULL, " ", &saveptr);
+ }
+
+ opt->option->name = name ?: talloc_asprintf(opt,
+ "ipxe option (%s)", url->full);
+ continue;
+ }
+
+ if (streq(name, "initrd")) {
+ url = pxe_url_join(ctx->dc, ctx->dc->conf_url, value);
+ opt->initrd = create_url_resource(opt, url);
+ continue;
+ }
+ }
+
+ if (opt->boot_image)
+ discover_context_add_boot_option(ctx->dc, opt);
+ else
+ pb_debug("ipxe file did not contain a valid option\n");
+
+ return true;
+}
+
+/*
+ * Callback for asynchronous loads from pxe_parse()
+ * @param result Result of load_url_async()
+ * @param data Pointer to associated conf_context
+ */
+static void pxe_conf_parse_cb(struct load_url_result *result, void *data)
+{
+ struct conf_context *conf = data;
+ struct device_handler *handler;
+ struct pxe_parser_info *info;
+ char *buf = NULL;
+ int len, rc = 0;
+
+ if (!data)
+ return;
+ if (!result)
+ goto out_clean;
+
+ handler = talloc_parent(conf);
+
+ if (result->status == LOAD_OK)
+ rc = read_file(conf, result->local, &buf, &len);
+ if (result->status != LOAD_OK || rc) {
+ /* This load failed so try the next available filename */
+ info = conf->parser_info;
+ if (!info->pxe_conf_files) {
+ device_handler_status_dev_err(handler,
+ conf->dc->device,
+ _("Failed to download %s"),
+ pb_url_to_string(result->url));
+
+ return;
+ }
+
+ info->current++;
+ pxe_load_next_filename(conf);
+ if (info->pxe_conf_files[info->current] == NULL) {
+ /* Nothing left to try */
+ device_handler_status_dev_err(handler,
+ conf->dc->device,
+ _("PXE autoconfiguration failed"));
+ goto out_clean;
+ }
+ return;
+ }
+
+ /*
+ * Parse the first successfully downloaded file. We only want to parse
+ * the first because otherwise we could parse options from both a
+ * machine-specific config and a 'fallback' default config
+ * We also check if the file is in the limited ipxe format.
+ */
+ if (!ipxe_simple_parser(conf, buf, len))
+ conf_parse_buf(conf, buf, len);
+
+ /* We may be called well after the original caller of iterate_parsers(),
+ * commit any new boot options ourselves */
+ device_handler_discover_context_commit(handler, conf->dc);
+
+ /*
+ * TRANSLATORS: the format specifier in this string is a URL
+ * eg. tftp://192.168.1.1/pxelinux.cfg
+ */
+ device_handler_status_dev_info(handler, conf->dc->device,
+ _("Parsed PXE config from %s"),
+ pb_url_to_string(result->url));
+
+ talloc_free(buf);
+out_clean:
+ if (result && result->cleanup_local)
+ unlink(result->local);
+ talloc_free(conf);
+}
+
+/**
+ * Return a new conf_context and increment the talloc reference count on
+ * the discover_context struct.
+ * @param ctx Parent talloc context
+ * @param orig Original discover_context
+ * @return Pointer to new conf_context
+ */
+static struct conf_context *copy_context(void *ctx, struct discover_context *dc)
+{
+ struct pxe_parser_info *info;
+ struct conf_context *conf;
+
+ conf = talloc_zero(ctx, struct conf_context);