[PATCH 2/2] discover: extend URL in UI to support auto-discovery

Nishanth Aravamudan nacc at linux.vnet.ibm.com
Thu Aug 20 07:05:50 AEST 2015


The URL field currently only supports loading a particular file for
static network configurations. But it makes sense in certain static
network configurations to 'auto-discover' a file like petitboot does
with DHCP -- based off the MAC address and IP. Extend
device_handler_process_url to take those as parameters, and toggle off
the URL ending in a '/' to indicate whether to 'auto-discover' or
directly load the specified URL.

Signed-off-by: Nishanth Aravamudan <nacc at linux.vnet.ibm.com>

diff --git a/discover/device-handler.c b/discover/device-handler.c
index 64095f1..c844cc4 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -1005,9 +1005,8 @@ static char *device_from_addr(void *ctx, struct pb_url *url)
 	return dev;
 }
 
-
 void device_handler_process_url(struct device_handler *handler,
-		const char *url)
+		const char *url, const char *mac, const char *ip)
 {
 	struct discover_context *ctx;
 	struct discover_device *dev;
@@ -1033,11 +1032,25 @@ void device_handler_process_url(struct device_handler *handler,
 	event->type = EVENT_TYPE_USER;
 	event->action = EVENT_ACTION_CONF;
 
-	event->params = talloc_array(event, struct param, 1);
-	param = &event->params[0];
-	param->name = talloc_strdup(event, "pxeconffile");
-	param->value = talloc_strdup(event, url);
-	event->n_params = 1;
+	if (url[strlen(url) - 1] == '/') {
+		event->params = talloc_array(event, struct param, 3);
+		param = &event->params[0];
+		param->name = talloc_strdup(event, "pxepathprefix");
+		param->value = talloc_strdup(event, url);
+		param = &event->params[1];
+		param->name = talloc_strdup(event, "mac");
+		param->value = talloc_strdup(event, mac);
+		param = &event->params[2];
+		param->name = talloc_strdup(event, "ip");
+		param->value = talloc_strdup(event, ip);
+		event->n_params = 3;
+	} else {
+		event->params = talloc_array(event, struct param, 1);
+		param = &event->params[0];
+		param->name = talloc_strdup(event, "pxeconffile");
+		param->value = talloc_strdup(event, url);
+		event->n_params = 1;
+	}
 
 	pb_url = pb_url_parse(event, event->params->value);
 	if (!pb_url || !pb_url->host) {
diff --git a/discover/device-handler.h b/discover/device-handler.h
index b592c46..fd3d14b 100644
--- a/discover/device-handler.h
+++ b/discover/device-handler.h
@@ -119,7 +119,7 @@ void device_handler_cancel_default(struct device_handler *handler);
 void device_handler_update_config(struct device_handler *handler,
 		struct config *config);
 void device_handler_process_url(struct device_handler *handler,
-		const char *url);
+		const char *url, const char *mac, const char *ip);
 void device_handler_reinit(struct device_handler *handler);
 
 int device_request_write(struct discover_device *dev, bool *release);
diff --git a/discover/discover-server.c b/discover/discover-server.c
index e4f3b67..6806589 100644
--- a/discover/discover-server.c
+++ b/discover/discover-server.c
@@ -266,7 +266,8 @@ static int discover_server_process_message(void *arg)
 	case PB_PROTOCOL_ACTION_ADD_URL:
 		url = pb_protocol_deserialise_string((void *) client, message);
 
-		device_handler_process_url(client->server->device_handler, url);
+		device_handler_process_url(client->server->device_handler,
+				url, NULL, NULL);
 		break;
 
 	default:
diff --git a/discover/network.c b/discover/network.c
index f763687..c072eec 100644
--- a/discover/network.c
+++ b/discover/network.c
@@ -374,7 +374,11 @@ static void configure_interface_static(struct network *network,
 	if (config->static_config.url) {
 		pb_log("config URL %s\n", config->static_config.url);
 		device_handler_process_url(network->handler,
-				config->static_config.url);
+				config->static_config.url,
+				mac_bytes_to_string(interface->dev,
+						interface->hwaddr,
+						sizeof(interface->hwaddr)),
+				config->static_config.address);
 	}
 
 	return;
diff --git a/discover/user-event.c b/discover/user-event.c
index 69defa3..6a68abf 100644
--- a/discover/user-event.c
+++ b/discover/user-event.c
@@ -439,7 +439,7 @@ static int user_event_url(struct user_event *uev, struct event *event)
 
 	url = event_get_param(event, "url");
 	if (url)
-		device_handler_process_url(handler, url);
+		device_handler_process_url(handler, url, NULL, NULL);
 
 	return 0;
 }



More information about the Petitboot mailing list