]> git.ozlabs.org Git - petitboot/commitdiff
discover: extend URL in UI to support auto-discovery
authorNishanth Aravamudan <nacc@linux.vnet.ibm.com>
Wed, 19 Aug 2015 21:05:43 +0000 (14:05 -0700)
committerSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Fri, 18 Dec 2015 02:06:53 +0000 (13:06 +1100)
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@linux.vnet.ibm.com>
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover/device-handler.c
discover/device-handler.h
discover/discover-server.c
discover/network.c
discover/user-event.c

index 3804b34da08fcf781438db1abfaf04205c4cc373..5df070073b4d298c8a49a5488010434b73ff4f32 100644 (file)
@@ -1125,9 +1125,8 @@ static char *device_from_addr(void *ctx, struct pb_url *url)
        return dev;
 }
 
        return dev;
 }
 
-
 void device_handler_process_url(struct device_handler *handler,
 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;
 {
        struct discover_context *ctx;
        struct discover_device *dev;
@@ -1153,11 +1152,25 @@ void device_handler_process_url(struct device_handler *handler,
        event->type = EVENT_TYPE_USER;
        event->action = EVENT_ACTION_CONF;
 
        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) {
 
        pb_url = pb_url_parse(event, event->params->value);
        if (!pb_url || !pb_url->host) {
index d18910a1315d6f7ebf4da9e0b248e83c13fbad80..e5501ec41d6e4911acc39aba2fd9efcc617eb9e8 100644 (file)
@@ -133,7 +133,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,
 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);
 void device_handler_reinit(struct device_handler *handler);
 
 int device_request_write(struct discover_device *dev, bool *release);
index e4f3b67767a0ed08ee1fffda3bc7147b6c137a4b..68065895f4dc52b85ccb04633f87e7201398c950 100644 (file)
@@ -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);
 
        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:
                break;
 
        default:
index f763687f8b53bbb8c57b14f1c0abe63e171e147b..c072eece9627408ac7bbebab2d227d968a8f9fbf 100644 (file)
@@ -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,
        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;
        }
 
        return;
index 8cad1a91a624f5f55cd17d49858edfab3820133c..8926458905ef2b076b965270b31a5adefbb6fa77 100644 (file)
@@ -439,7 +439,7 @@ static int user_event_url(struct user_event *uev, struct event *event)
 
        url = event_get_param(event, "url");
        if (url)
 
        url = event_get_param(event, "url");
        if (url)
-               device_handler_process_url(handler, url);
+               device_handler_process_url(handler, url, NULL, NULL);
 
        return 0;
 }
 
        return 0;
 }