summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>2014-12-03 15:08:23 +1100
committerJeremy Kerr <jk@ozlabs.org>2014-12-03 12:12:47 +0800
commit9c33c54f7b431074a7d0daddce34140044aaadf6 (patch)
treef726dca93146b8218f4c5711a49b4eb1fe49c12a /test
parentba1633025d93d7b41bda9bd32fa1d2337c7c4365 (diff)
downloadpetitboot-9c33c54f7b431074a7d0daddce34140044aaadf6.zip
petitboot-9c33c54f7b431074a7d0daddce34140044aaadf6.tar.gz
discover/pxe: Format IPAPPEND mac addresses correctly
The SYSAPPEND/IPAPPEND option 2 in PXE configs requires the MAC address of the booting interface to be appended to the boot options. Previously we formatted this as "BOOTIF=01:02:03:04:05:06", but syslinux/pxelinux implementation use this format: "BOOTIF=01-01-02-03-04-05-06", where the leading '01' represents the hardware type. The relevant part of the pxelinux doc is at: http://www.syslinux.org/wiki/index.php/SYSLINUX#SYSAPPEND_bitmask Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'test')
-rw-r--r--test/parser/Makefile.am1
-rw-r--r--test/parser/network.c53
-rw-r--r--test/parser/parser-test.h1
-rw-r--r--test/parser/test-pxe-ipappend.c6
-rw-r--r--test/parser/utils.c5
5 files changed, 63 insertions, 3 deletions
diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am
index dbf400e..1bb45e8 100644
--- a/test/parser/Makefile.am
+++ b/test/parser/Makefile.am
@@ -94,6 +94,7 @@ test_parser_libtest_ro_SOURCES = \
test/parser/main.c \
test/parser/utils.c \
test/parser/handler.c \
+ test/parser/network.c \
test/parser/parser-test.h \
discover/yaboot-parser.c \
discover/kboot-parser.c \
diff --git a/test/parser/network.c b/test/parser/network.c
new file mode 100644
index 0000000..9c57309
--- /dev/null
+++ b/test/parser/network.c
@@ -0,0 +1,53 @@
+#include <string.h>
+#include <types/types.h>
+#include <talloc/talloc.h>
+#include <sys/socket.h>
+#include <linux/if.h>
+#include "network.h"
+
+struct interface {
+ int ifindex;
+ char name[IFNAMSIZ];
+ uint8_t hwaddr[HWADDR_SIZE];
+
+ enum {
+ IFSTATE_NEW,
+ IFSTATE_UP_WAITING_LINK,
+ IFSTATE_CONFIGURED,
+ IFSTATE_IGNORED,
+ } state;
+
+ struct list_item list;
+ struct process *udhcpc_process;
+ struct discover_device *dev;
+};
+
+static struct interface test = {
+ .name = "em1",
+ .hwaddr = {1,2,3,4,5,6},
+};
+
+static struct interface *find_interface_by_name(struct network *network,
+ const char *name)
+{
+ (void)network;
+
+ if (!strcmp(test.name, name))
+ return &test;
+
+ return NULL;
+}
+
+uint8_t *find_mac_by_name(void *ctx, struct network *network,
+ const char *name)
+{
+ struct interface *interface;
+ (void)network;
+
+ interface = find_interface_by_name(network, name);
+ if (!interface)
+ return NULL;
+
+ return talloc_memdup(ctx, &interface->hwaddr,
+ sizeof(uint8_t) * HWADDR_SIZE);
+}
diff --git a/test/parser/parser-test.h b/test/parser/parser-test.h
index c0339b8..21b5b9c 100644
--- a/test/parser/parser-test.h
+++ b/test/parser/parser-test.h
@@ -40,6 +40,7 @@ void test_add_dir(struct parser_test *test, struct discover_device *dev,
void test_set_event_source(struct parser_test *test);
void test_set_event_param(struct event *event, const char *name,
const char *value);
+void test_set_event_device(struct event *event, const char *dev);
#define test_add_file_string(test, dev, filename, str) \
test_add_file_data(test, dev, filename, str, sizeof(str) - 1)
diff --git a/test/parser/test-pxe-ipappend.c b/test/parser/test-pxe-ipappend.c
index 4719b5c..3fec6a7 100644
--- a/test/parser/test-pxe-ipappend.c
+++ b/test/parser/test-pxe-ipappend.c
@@ -1,5 +1,6 @@
#include "parser-test.h"
+#include "network.h"
#if 0 /* PARSER_EMBEDDED_CONFIG */
default linux
@@ -20,8 +21,7 @@ void run_test(struct parser_test *test)
test_set_event_source(test);
test_set_event_param(test->ctx->event, "pxeconffile",
"tftp://host/dir/conf.txt");
- test_set_event_param(test->ctx->event, "mac",
- "01:02:03:04:05:06");
+ test_set_event_device(test->ctx->event, "em1");
test_run_parser(test, "pxe");
@@ -31,5 +31,5 @@ void run_test(struct parser_test *test)
opt = get_boot_option(ctx, 0);
check_name(opt, "linux");
- check_args(opt, "command line BOOTIF=01:02:03:04:05:06");
+ check_args(opt, "command line BOOTIF=01-01-02-03-04-05-06");
}
diff --git a/test/parser/utils.c b/test/parser/utils.c
index 8a6314b..0050d13 100644
--- a/test/parser/utils.c
+++ b/test/parser/utils.c
@@ -207,6 +207,11 @@ void test_set_event_param(struct event *event, const char *name,
event_set_param(event, name, value);
}
+void test_set_event_device(struct event *event, const char *dev)
+{
+ event->device = talloc_strdup(event, dev);
+}
+
int parser_request_file(struct discover_context *ctx,
struct discover_device *dev, const char *filename,
char **buf, int *len)
OpenPOWER on IntegriCloud