ctx = talloc_zero(handler, struct discover_context);
ctx->device = device;
+ ctx->network = handler->network;
list_init(&ctx->boot_options);
return ctx;
struct discover_device *device;
struct list boot_options;
struct pb_url *conf_url;
+ struct network *network;
void *test_data;
};
return NULL;
}
+uint8_t *find_mac_by_name(void *ctx, struct network *network,
+ const char *name)
+{
+ struct interface *interface;
+
+ interface = find_interface_by_name(network, name);
+ if (!interface)
+ return NULL;
+
+ return talloc_memdup(ctx, &interface->hwaddr,
+ sizeof(uint8_t) * HWADDR_SIZE);
+}
+
static int network_init_netlink(struct network *network)
{
struct sockaddr_nl addr;
void network_unregister_device(struct network *network,
struct discover_device *dev);
+uint8_t *find_mac_by_name(void *ctx, struct network *network,
+ const char *name);
+
#endif /* NETWORK_H */
#include "paths.h"
#include "event.h"
#include "user-event.h"
+#include "network.h"
static const char *pxelinux_prefix = "pxelinux.cfg/";
opt->option->boot_args = talloc_strdup(opt->option, str);
}
+static char *pxe_sysappend_mac(void *ctx, uint8_t *mac)
+{
+ if (!mac)
+ return NULL;
+
+ return talloc_asprintf(ctx,
+ "BOOTIF=01-%02x-%02x-%02x-%02x-%02x-%02x",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+}
+
static void pxe_process_sysappend(struct discover_context *ctx,
struct discover_boot_option *opt,
unsigned long val)
return;
if (val & 0x2) {
- const char *mac = event_get_param(event, "mac");
- if (mac) {
- str = talloc_asprintf(ctx, "BOOTIF=%s", mac);
+ uint8_t *mac = find_mac_by_name(ctx, ctx->network,
+ event->device);
+ str = pxe_sysappend_mac(ctx, mac);
+ if (str) {
pxe_append_string(opt, str);
talloc_free(str);
}
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 \
--- /dev/null
+#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);
+}
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)
#include "parser-test.h"
+#include "network.h"
#if 0 /* PARSER_EMBEDDED_CONFIG */
default linux
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");
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");
}
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)