5 #include <talloc/talloc.h>
9 #include "parser-conf.h"
10 #include "parser-utils.h"
13 #include "user-event.h"
15 struct pxe_parser_info {
16 struct discover_boot_option *opt;
17 const char *default_name;
20 static void pxe_finish(struct conf_context *conf)
22 struct pxe_parser_info *info = conf->parser_info;
24 discover_context_add_boot_option(conf->dc, info->opt);
27 static void pxe_process_pair(struct conf_context *ctx,
28 const char *name, char *value)
30 struct pxe_parser_info *parser_info = ctx->parser_info;
31 struct discover_boot_option *opt = parser_info->opt;
34 /* quirk in the syslinux config format: initrd can be separated
36 if (!name && !strncasecmp(value, "initrd=", strlen("initrd="))) {
38 value += strlen("initrd=");
44 if (streq(name, "DEFAULT")) {
45 parser_info->default_name = talloc_strdup(parser_info, value);
49 if (streq(name, "LABEL")) {
53 opt = discover_boot_option_create(ctx->dc, ctx->dc->device);
55 opt->option->name = talloc_strdup(opt, value);
56 opt->option->id = talloc_asprintf(opt, "%s@%p",
57 ctx->dc->device->device->id, opt);
59 opt->option->is_default = parser_info->default_name &&
60 streq(parser_info->default_name, value);
62 parser_info->opt = opt;
66 /* all other parameters need an option */
70 if (streq(name, "KERNEL")) {
71 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
72 opt->boot_image = create_url_resource(opt, url);
74 } else if (streq(name, "INITRD")) {
75 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
76 opt->initrd = create_url_resource(opt, url);
78 } else if (streq(name, "APPEND")) {
81 opt->option->boot_args = talloc_strdup(opt->option, value);
83 str = strcasestr(value, "INITRD=");
85 str += strlen("INITRD=");
86 end = strchrnul(str, ' ');
89 url = pb_url_join(ctx->dc, ctx->dc->conf_url, str);
90 opt->initrd = create_url_resource(opt, url);
96 static int pxe_parse(struct discover_context *dc)
98 struct pxe_parser_info *parser_info;
99 char **pxe_conf_files, **filename;
100 struct pb_url *conf_url, *url;
101 struct conf_context *conf;
105 /* Expects dhcp event parameters to support network boot */
109 conf = talloc_zero(dc, struct conf_context);
115 conf->get_pair = conf_get_pair_space;
116 conf->process_pair = pxe_process_pair;
117 conf->finish = pxe_finish;
119 parser_info = talloc_zero(conf, struct pxe_parser_info);
120 conf->parser_info = parser_info;
122 conf_url = user_event_parse_conf_url(dc, dc->event);
127 rc = parser_request_url(dc, dc->conf_url, &buf, &len);
131 pxe_conf_files = user_event_parse_conf_filenames(dc, dc->event);
137 for (filename = pxe_conf_files; *filename; filename++) {
138 url = pb_url_join(dc, conf_url, *filename);
142 rc = parser_request_url(dc, url, &buf, &len);
143 if (!rc) /* found one, just break */
149 /* No configuration file found on the boot server */
155 talloc_free(conf_url);
156 talloc_free(pxe_conf_files);
159 /* Call the config file parser with the data read from the file */
160 conf_parse_buf(conf, buf, len);
168 talloc_free(pxe_conf_files);
175 static struct parser pxe_parser = {
180 register_parser(pxe_parser);