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 static const char *pxelinux_prefix = "pxelinux.cfg/";
19 struct pxe_parser_info {
20 struct discover_boot_option *opt;
21 const char *default_name;
24 static void pxe_finish(struct conf_context *conf)
26 struct pxe_parser_info *info = conf->parser_info;
28 discover_context_add_boot_option(conf->dc, info->opt);
31 static void pxe_process_pair(struct conf_context *ctx,
32 const char *name, char *value)
34 struct pxe_parser_info *parser_info = ctx->parser_info;
35 struct discover_boot_option *opt = parser_info->opt;
38 /* quirk in the syslinux config format: initrd can be separated
40 if (!name && !strncasecmp(value, "initrd=", strlen("initrd="))) {
42 value += strlen("initrd=");
48 if (streq(name, "DEFAULT")) {
49 parser_info->default_name = talloc_strdup(parser_info, value);
53 if (streq(name, "LABEL")) {
57 opt = discover_boot_option_create(ctx->dc, ctx->dc->device);
59 opt->option->name = talloc_strdup(opt, value);
60 opt->option->id = talloc_asprintf(opt, "%s@%p",
61 ctx->dc->device->device->id, opt);
63 opt->option->is_default = parser_info->default_name &&
64 streq(parser_info->default_name, value);
66 parser_info->opt = opt;
70 /* all other parameters need an option */
74 if (streq(name, "KERNEL")) {
75 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
76 opt->boot_image = create_url_resource(opt, url);
78 } else if (streq(name, "INITRD")) {
79 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
80 opt->initrd = create_url_resource(opt, url);
82 } else if (streq(name, "APPEND")) {
85 opt->option->boot_args = talloc_strdup(opt->option, value);
87 str = strcasestr(value, "INITRD=");
89 str += strlen("INITRD=");
90 end = strchrnul(str, ' ');
93 url = pb_url_join(ctx->dc, ctx->dc->conf_url, str);
94 opt->initrd = create_url_resource(opt, url);
100 static int pxe_parse(struct discover_context *dc)
102 struct pb_url *pxe_base_url, *url;
103 struct pxe_parser_info *parser_info;
104 char **pxe_conf_files, **filename;
105 struct conf_context *conf;
110 /* Expects dhcp event parameters to support network boot */
114 conf = talloc_zero(dc, struct conf_context);
120 conf->get_pair = conf_get_pair_space;
121 conf->process_pair = pxe_process_pair;
122 conf->finish = pxe_finish;
124 parser_info = talloc_zero(conf, struct pxe_parser_info);
125 conf->parser_info = parser_info;
127 dc->conf_url = user_event_parse_conf_url(dc, dc->event, &complete_url);
132 /* we have a complete URL; use this and we're done. */
133 rc = parser_request_url(dc, dc->conf_url, &buf, &len);
137 pxe_conf_files = user_event_parse_conf_filenames(dc, dc->event);
143 pxe_base_url = pb_url_join(dc, dc->conf_url, pxelinux_prefix);
147 for (filename = pxe_conf_files; *filename; filename++) {
148 url = pb_url_join(dc, pxe_base_url, *filename);
152 rc = parser_request_url(dc, url, &buf, &len);
153 if (!rc) /* found one, just break */
159 talloc_free(pxe_base_url);
161 /* No configuration file found on the boot server */
165 talloc_free(pxe_conf_files);
168 /* Call the config file parser with the data read from the file */
169 conf_parse_buf(conf, buf, len);
177 talloc_free(pxe_conf_files);
184 static struct parser pxe_parser = {
189 register_parser(pxe_parser);