5 #include <talloc/talloc.h>
9 #include "parser-conf.h"
10 #include "parser-utils.h"
13 struct pxe_parser_info {
14 struct discover_boot_option *opt;
15 const char *default_name;
18 static void pxe_finish(struct conf_context *conf)
20 struct pxe_parser_info *info = conf->parser_info;
22 discover_context_add_boot_option(conf->dc, info->opt);
25 static void pxe_process_pair(struct conf_context *ctx,
26 const char *name, char *value)
28 struct pxe_parser_info *parser_info = ctx->parser_info;
29 struct discover_boot_option *opt = parser_info->opt;
32 /* quirk in the syslinux config format: initrd can be separated
34 if (!name && !strncasecmp(value, "initrd=", strlen("initrd="))) {
36 value += strlen("initrd=");
42 if (streq(name, "DEFAULT")) {
43 parser_info->default_name = talloc_strdup(parser_info, value);
47 if (streq(name, "LABEL")) {
51 opt = discover_boot_option_create(ctx->dc, ctx->dc->device);
53 opt->option->name = talloc_strdup(opt, value);
54 opt->option->id = talloc_asprintf(opt, "%s@%p",
55 ctx->dc->device->device->id, opt);
57 opt->option->is_default = parser_info->default_name &&
58 streq(parser_info->default_name, value);
60 parser_info->opt = opt;
64 /* all other parameters need an option */
68 if (streq(name, "KERNEL")) {
69 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
70 opt->boot_image = create_url_resource(opt, url);
72 } else if (streq(name, "INITRD")) {
73 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
74 opt->initrd = create_url_resource(opt, url);
76 } else if (streq(name, "APPEND")) {
79 opt->option->boot_args = talloc_strdup(opt->option, value);
81 str = strcasestr(value, "INITRD=");
83 str += strlen("INITRD=");
84 end = strchrnul(str, ' ');
87 url = pb_url_join(ctx->dc, ctx->dc->conf_url, str);
88 opt->initrd = create_url_resource(opt, url);
94 static int pxe_parse(struct discover_context *dc, char *buf, int len)
96 struct pxe_parser_info *parser_info;
97 struct conf_context *conf;
99 conf = talloc_zero(dc, struct conf_context);
105 conf->get_pair = conf_get_pair_space;
106 conf->process_pair = pxe_process_pair;
107 conf->finish = pxe_finish;
109 parser_info = talloc_zero(conf, struct pxe_parser_info);
110 conf->parser_info = parser_info;
112 conf_parse_buf(conf, buf, len);
118 static struct parser pxe_parser = {
121 .method = CONF_METHOD_DHCP,
124 register_parser(pxe_parser);