[PATCH] ui: add URL for static configurations to load a specified file

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


In certain configurations, e.g. automation, we want to use static
networking but load a particular file, automatically and parse it as a
pxelinux config file. Currently, we support something like this for DHCP
based booting, but not static. Add a URL field to the UI for static
configurations and reuse the logic from device_handler_process_url() to
load the specified file.

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

diff --git a/discover/network.c b/discover/network.c
index 0dad087..f763687 100644
--- a/discover/network.c
+++ b/discover/network.c
@@ -336,7 +336,8 @@ static void configure_interface_dhcp(struct interface *interface)
 	return;
 }
 
-static void configure_interface_static(struct interface *interface,
+static void configure_interface_static(struct network *network,
+		struct interface *interface,
 		const struct interface_config *config)
 {
 	int rc;
@@ -370,6 +371,12 @@ static void configure_interface_static(struct interface *interface,
 				interface->name);
 	}
 
+	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);
+	}
+
 	return;
 }
 
@@ -438,7 +445,7 @@ static void configure_interface(struct network *network,
 		configure_interface_dhcp(interface);
 
 	} else if (config->method == CONFIG_METHOD_STATIC) {
-		configure_interface_static(interface, config);
+		configure_interface_static(network, interface, config);
 	}
 }
 
diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index 2b3b043..f2bdc1b 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -308,7 +308,7 @@ static int parse_one_interface_config(struct config *config,
 	} else if (!strcmp(tok, "static")) {
 		ifconf->method = CONFIG_METHOD_STATIC;
 
-		/* ip/mask, [optional] gateway */
+		/* ip/mask, [optional] gateway, [optional] url */
 		tok = strtok_r(NULL, ",", &saveptr);
 		if (!tok)
 			goto out_err;
@@ -321,6 +321,12 @@ static int parse_one_interface_config(struct config *config,
 				talloc_strdup(ifconf, tok);
 		}
 
+		tok = strtok_r(NULL, ",", &saveptr);
+		if (tok) {
+			ifconf->static_config.url =
+				talloc_strdup(ifconf, tok);
+		}
+
 	} else {
 		pb_log("Unknown network configuration method %s\n", tok);
 		goto out_err;
@@ -568,10 +574,12 @@ static char *iface_config_str(void *ctx, struct interface_config *config)
 		str = talloc_asprintf_append(str, "dhcp");
 
 	} else if (config->method == CONFIG_METHOD_STATIC) {
-		str = talloc_asprintf_append(str, "static,%s%s%s",
+		str = talloc_asprintf_append(str, "static,%s%s%s%s%s",
 				config->static_config.address,
 				config->static_config.gateway ? "," : "",
-				config->static_config.gateway ?: "");
+				config->static_config.gateway ?: "",
+				config->static_config.url ? "," : "",
+				config->static_config.url ?: "");
 	}
 	return str;
 }
diff --git a/discover/platform.c b/discover/platform.c
index 74e2a82..2765cd2 100644
--- a/discover/platform.c
+++ b/discover/platform.c
@@ -56,6 +56,7 @@ static void dump_config(struct config *config)
 			pb_log("   static:\n");
 			pb_log("    ip:  %s\n", ifconf->static_config.address);
 			pb_log("    gw:  %s\n", ifconf->static_config.gateway);
+			pb_log("    url:  %s\n", ifconf->static_config.url);
 
 		}
 	}
diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c
index 69ea35d..63afac4 100644
--- a/lib/pb-protocol/pb-protocol.c
+++ b/lib/pb-protocol/pb-protocol.c
@@ -257,6 +257,7 @@ static int pb_protocol_interface_config_len(struct interface_config *conf)
 	if (conf->method == CONFIG_METHOD_STATIC) {
 		len += 4 + optional_strlen(conf->static_config.address);
 		len += 4 + optional_strlen(conf->static_config.gateway);
+		len += 4 + optional_strlen(conf->static_config.url);
 	}
 
 	return len;
@@ -446,6 +447,8 @@ static int pb_protocol_serialise_config_interface(char *buf,
 				conf->static_config.address);
 		pos += pb_protocol_serialise_string(pos,
 				conf->static_config.gateway);
+		pos += pb_protocol_serialise_string(pos,
+				conf->static_config.url);
 	}
 
 	return pos - buf;
@@ -879,6 +882,9 @@ static int pb_protocol_deserialise_config_interface(const char **buf,
 
 		if (read_string(iface, buf, len, &iface->static_config.gateway))
 			return -1;
+
+		if (read_string(iface, buf, len, &iface->static_config.url))
+			return -1;
 	}
 
 	return 0;
diff --git a/lib/types/types.h b/lib/types/types.h
index e5c7e3e..e76f36c 100644
--- a/lib/types/types.h
+++ b/lib/types/types.h
@@ -113,6 +113,7 @@ struct interface_config {
 		struct {
 			char *address;
 			char *gateway;
+			char *url;
 		} static_config;
 	};
 };
diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c
index 76ede39..6c0cbad 100644
--- a/ui/ncurses/nc-config.c
+++ b/ui/ncurses/nc-config.c
@@ -33,7 +33,7 @@
 #include "nc-config.h"
 #include "nc-widgets.h"
 
-#define N_FIELDS	32
+#define N_FIELDS	35
 
 extern struct help_text config_help_text;
 
@@ -95,6 +95,9 @@ struct config_screen {
 		struct nc_widget_label		*gateway_l;
 		struct nc_widget_textbox	*gateway_f;
 		struct nc_widget_label		*gateway_help_l;
+		struct nc_widget_label		*url_l;
+		struct nc_widget_textbox	*url_f;
+		struct nc_widget_label		*url_help_l;
 		struct nc_widget_label		*dns_l;
 		struct nc_widget_textbox	*dns_f;
 		struct nc_widget_label		*dns_dhcp_help_l;
@@ -284,11 +287,12 @@ static int screen_process_form(struct config_screen *screen)
 	}
 
 	if (net_conf_type == NET_CONF_TYPE_STATIC) {
-		char *ip, *mask, *gateway;
+		char *ip, *mask, *gateway, *url;
 
 		ip = widget_textbox_get_value(screen->widgets.ip_addr_f);
 		mask = widget_textbox_get_value(screen->widgets.ip_mask_f);
 		gateway = widget_textbox_get_value(screen->widgets.gateway_f);
+		url = widget_textbox_get_value(screen->widgets.url_f);
 
 		if (!ip || !*ip || !mask || !*mask) {
 			screen->scr.frame.status =
@@ -302,6 +306,7 @@ static int screen_process_form(struct config_screen *screen)
 		iface->static_config.address = talloc_asprintf(iface, "%s/%s",
 				ip, mask);
 		iface->static_config.gateway = talloc_strdup(iface, gateway);
+		iface->static_config.url = talloc_strdup(iface, url);
 	}
 
 	str = widget_textbox_get_value(screen->widgets.dns_f);
@@ -516,6 +521,19 @@ static void config_screen_layout_widgets(struct config_screen *screen)
 		y++;
 	}
 
+	wl = widget_label_base(screen->widgets.url_l);
+	wf = widget_textbox_base(screen->widgets.url_f);
+	wh = widget_label_base(screen->widgets.url_help_l);
+	widget_set_visible(wl, show);
+	widget_set_visible(wf, show);
+	widget_set_visible(wh, show);
+
+	if (show) {
+		layout_pair(screen, y, screen->widgets.url_l, wf);
+		widget_move(wh, y, help_x);
+		y++;
+	}
+
 	wh = widget_label_base(screen->widgets.dns_help_l);
 	layout_pair(screen, y, screen->widgets.dns_l,
 			widget_textbox_base(screen->widgets.dns_f));
@@ -693,7 +711,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 {
 	struct nc_widgetset *set = screen->widgetset;
 	struct interface_config *ifcfg;
-	char *str, *ip, *mask, *gw;
+	char *str, *ip, *mask, *gw, *url;
 	enum net_conf_type type;
 	unsigned int i;
 
@@ -843,7 +861,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 						i, str, is_default);
 	}
 
-	gw = ip = mask = NULL;
+	url = gw = ip = mask = NULL;
 	if (ifcfg && ifcfg->method == CONFIG_METHOD_STATIC) {
 		char *sep;
 
@@ -856,6 +874,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 			mask = sep + 1;
 		}
 		gw = ifcfg->static_config.gateway;
+		url = ifcfg->static_config.url;
 	}
 
 	screen->widgets.ip_addr_l = widget_new_label(set, 0, 0, _("IP/mask:"));
@@ -878,6 +897,11 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 	widget_textbox_set_fixed_size(screen->widgets.gateway_f);
 	widget_textbox_set_validator_ipv4(screen->widgets.gateway_f);
 
+	screen->widgets.url_l = widget_new_label(set, 0, 0, _("URL:"));
+	screen->widgets.url_f = widget_new_textbox(set, 0, 0, 32, url);
+	screen->widgets.url_help_l =
+		widget_new_label(set, 0, 0, _("(eg. tftp://)"));
+
 	str = talloc_strdup(screen, "");
 	for (i = 0; i < config->network.n_dns_servers; i++) {
 		str = talloc_asprintf_append(str, "%s%s",



More information about the Petitboot mailing list