]> git.ozlabs.org Git - petitboot/commitdiff
discover/pxe: Add pxelinux.cfg/ directory to autodiscovered pxe paths
authorJeremy Kerr <jk@ozlabs.org>
Thu, 27 Feb 2014 02:33:13 +0000 (10:33 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 27 Feb 2014 05:24:23 +0000 (13:24 +0800)
The pxelinux project will perform autodiscovery by looking for files
under the pxelinux.cfg/ prefix (in addition to any pxepathprefix from
DHCP option 210)

This change unifies petitboot's behaviour with pxelinux.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/pxe-parser.c
test/parser/test-pxe-ip-without-conf.c
test/parser/test-pxe-mac-without-conf.c
test/parser/test-pxe-pathprefix-discover-mac.c
test/parser/test-pxe-pathprefix-discover.c

index e245f1b82b10536f6fb549237dc0627fc18fbb91..17ae55e6a3dc0c5665be7e7678a308dddf6ecf0d 100644 (file)
@@ -14,6 +14,8 @@
 #include "paths.h"
 #include "user-event.h"
 
+static const char *pxelinux_prefix = "pxelinux.cfg/";
+
 struct pxe_parser_info {
        struct discover_boot_option *opt;
        const char *default_name;
@@ -97,9 +99,9 @@ static void pxe_process_pair(struct conf_context *ctx,
 
 static int pxe_parse(struct discover_context *dc)
 {
+       struct pb_url *pxe_base_url, *url;
        struct pxe_parser_info *parser_info;
        char **pxe_conf_files, **filename;
-       struct pb_url *conf_url, *url;
        struct conf_context *conf;
        bool complete_url;
        int len, rc;
@@ -122,13 +124,12 @@ static int pxe_parse(struct discover_context *dc)
        parser_info = talloc_zero(conf, struct pxe_parser_info);
        conf->parser_info = parser_info;
 
-       conf_url = user_event_parse_conf_url(dc, dc->event, &complete_url);
-       if (!conf_url)
+       dc->conf_url = user_event_parse_conf_url(dc, dc->event, &complete_url);
+       if (!dc->conf_url)
                goto out_conf;
 
        if (complete_url) {
                /* we have a complete URL; use this and we're done. */
-               dc->conf_url = conf_url;
                rc = parser_request_url(dc, dc->conf_url, &buf, &len);
                if (rc)
                        goto out_conf;
@@ -139,10 +140,14 @@ static int pxe_parse(struct discover_context *dc)
 
                rc = -1;
 
+               pxe_base_url = pb_url_join(dc, dc->conf_url, pxelinux_prefix);
+               if (!pxe_base_url)
+                       goto out_pxe_conf;
+
                for (filename = pxe_conf_files; *filename; filename++) {
-                       url = pb_url_join(dc, conf_url, *filename);
+                       url = pb_url_join(dc, pxe_base_url, *filename);
                        if (!url)
-                               goto out_pxe_conf;
+                               continue;
 
                        rc = parser_request_url(dc, url, &buf, &len);
                        if (!rc) /* found one, just break */
@@ -151,13 +156,12 @@ static int pxe_parse(struct discover_context *dc)
                        talloc_free(url);
                }
 
+               talloc_free(pxe_base_url);
+
                /* No configuration file found on the boot server */
                if (rc)
                        goto out_pxe_conf;
 
-               dc->conf_url = url;
-
-               talloc_free(conf_url);
                talloc_free(pxe_conf_files);
        }
 
index ff3bf9e2ade591b599dc6cf1ad64daa5191fd6e6..e3a612aabce65af2cc6de54ea8d09ffa28335b1d 100644 (file)
@@ -15,7 +15,7 @@ void run_test(struct parser_test *test)
        struct discover_boot_option *opt;
        struct discover_context *ctx;
 
-       test_read_conf_embedded_url(test, "tftp://host/dir/C0A8");
+       test_read_conf_embedded_url(test, "tftp://host/dir/pxelinux.cfg/C0A8");
 
        test_set_event_source(test);
        test_set_event_param(test->ctx->event, "bootfile", "dir/pxe");
index e42e374e38699309ae0b75ab6c3c55151607d11f..f84d63b7c52a959ac6c603d906d1a684742346fb 100644 (file)
@@ -16,7 +16,7 @@ void run_test(struct parser_test *test)
        struct discover_context *ctx;
 
        test_read_conf_embedded_url(test,
-                       "tftp://host/dir/01-12-34-56-78-9a-bc");
+                       "tftp://host/dir/pxelinux.cfg/01-12-34-56-78-9a-bc");
 
        test_set_event_source(test);
        test_set_event_param(test->ctx->event, "bootfile", "dir/pxe");
index 2decb4606bdcddc7b518010a6d92aa7ffa6382f4..1e5fa71e5c8eec377cc375c09931bdfd73cee2a9 100644 (file)
@@ -16,7 +16,8 @@ void run_test(struct parser_test *test)
        struct discover_context *ctx;
 
        test_read_conf_embedded_url(test,
-                       "tftp://host/path/to/01-12-34-56-78-9a-bc");
+                       "tftp://host/path/to/pxelinux.cfg/"
+                               "01-12-34-56-78-9a-bc");
 
        test_set_event_source(test);
        test_set_event_param(test->ctx->event, "mac", "12:34:56:78:9a:bc");
@@ -35,5 +36,6 @@ void run_test(struct parser_test *test)
 
        check_resolved_url_resource(opt->boot_image,
                        "tftp://host/path/to/./kernel");
-       check_resolved_url_resource(opt->initrd, "tftp://host/initrd");
+       check_resolved_url_resource(opt->initrd,
+                       "tftp://host/initrd");
 }
index de2feace6ff1962259ced939e08318f36d9dddef..9cb44c8764b7a954a0c3c6b549408c7f8864cff2 100644 (file)
@@ -15,7 +15,8 @@ void run_test(struct parser_test *test)
        struct discover_boot_option *opt;
        struct discover_context *ctx;
 
-       test_read_conf_embedded_url(test, "tftp://host/path/to/C0A8");
+       test_read_conf_embedded_url(test,
+                       "tftp://host/path/to/pxelinux.cfg/C0A8");
 
        test_set_event_source(test);
        test_set_event_param(test->ctx->event, "ip", "192.168.0.1");
@@ -34,5 +35,6 @@ void run_test(struct parser_test *test)
 
        check_resolved_url_resource(opt->boot_image,
                        "tftp://host/path/to/./kernel");
-       check_resolved_url_resource(opt->initrd, "tftp://host/initrd");
+       check_resolved_url_resource(opt->initrd,
+                       "tftp://host/initrd");
 }