2 #if defined(HAVE_CONFIG_H)
7 #include <talloc/talloc.h>
11 #include "parser-conf.h"
12 #include "parser-utils.h"
15 #include "user-event.h"
17 struct pxe_parser_info {
18 struct discover_boot_option *opt;
19 const char *default_name;
22 static void pxe_finish(struct conf_context *conf)
24 struct pxe_parser_info *info = conf->parser_info;
26 discover_context_add_boot_option(conf->dc, info->opt);
29 static void pxe_process_pair(struct conf_context *ctx,
30 const char *name, char *value)
32 struct pxe_parser_info *parser_info = ctx->parser_info;
33 struct discover_boot_option *opt = parser_info->opt;
36 /* quirk in the syslinux config format: initrd can be separated
38 if (!name && !strncasecmp(value, "initrd=", strlen("initrd="))) {
40 value += strlen("initrd=");
46 if (streq(name, "DEFAULT")) {
47 parser_info->default_name = talloc_strdup(parser_info, value);
51 if (streq(name, "LABEL")) {
55 opt = discover_boot_option_create(ctx->dc, ctx->dc->device);
57 opt->option->name = talloc_strdup(opt, value);
58 opt->option->id = talloc_asprintf(opt, "%s@%p",
59 ctx->dc->device->device->id, opt);
61 opt->option->is_default = parser_info->default_name &&
62 streq(parser_info->default_name, value);
64 parser_info->opt = opt;
68 /* all other parameters need an option */
72 if (streq(name, "KERNEL")) {
73 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
74 opt->boot_image = create_url_resource(opt, url);
76 } else if (streq(name, "INITRD")) {
77 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
78 opt->initrd = create_url_resource(opt, url);
80 } else if (streq(name, "APPEND")) {
83 opt->option->boot_args = talloc_strdup(opt->option, value);
85 str = strcasestr(value, "INITRD=");
87 str += strlen("INITRD=");
88 end = strchrnul(str, ' ');
91 url = pb_url_join(ctx->dc, ctx->dc->conf_url, str);
92 opt->initrd = create_url_resource(opt, url);
98 static int pxe_parse(struct discover_context *dc)
100 struct pxe_parser_info *parser_info;
101 char **pxe_conf_files, **filename;
102 struct pb_url *conf_url, *url;
103 struct conf_context *conf;
108 /* Expects dhcp event parameters to support network boot */
112 conf = talloc_zero(dc, struct conf_context);
118 conf->get_pair = conf_get_pair_space;
119 conf->process_pair = pxe_process_pair;
120 conf->finish = pxe_finish;
122 parser_info = talloc_zero(conf, struct pxe_parser_info);
123 conf->parser_info = parser_info;
125 conf_url = user_event_parse_conf_url(dc, dc->event, &complete_url);
130 /* we have a complete URL; use this and we're done. */
131 dc->conf_url = conf_url;
132 rc = parser_request_url(dc, dc->conf_url, &buf, &len);
136 pxe_conf_files = user_event_parse_conf_filenames(dc, dc->event);
142 for (filename = pxe_conf_files; *filename; filename++) {
143 url = pb_url_join(dc, conf_url, *filename);
147 rc = parser_request_url(dc, url, &buf, &len);
148 if (!rc) /* found one, just break */
154 /* No configuration file found on the boot server */
160 talloc_free(conf_url);
161 talloc_free(pxe_conf_files);
164 /* Call the config file parser with the data read from the file */
165 conf_parse_buf(conf, buf, len);
173 talloc_free(pxe_conf_files);
180 static struct parser pxe_parser = {
185 register_parser(pxe_parser);