diff mbox series

[4/4] discover/pxe-parser: Fine grained proxy control

Message ID 20171116034914.7820-4-cyrilbur@gmail.com
State Accepted
Headers show
Series [1/4] configure.ac: Fix unmatched brackets | expand

Commit Message

Cyril Bur Nov. 16, 2017, 3:49 a.m. UTC
Petitboot provides a method for a user to manually specify a
configuration file that should be retrieved. Petitboot also has a
global proxy configuration.

This patch aims to marry the two so that a custom configuration file
can specify that a specific proxy should be used to access one (or all)
of the options within it.

This makes custom configuration files more powerful as they can point
to files behind proxies without the user needing to also specify the
global proxy for that specific custom configuration file to work.

This adds parsing for a `proxy` option which will apply to all boot
items found after.

Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
---
 discover/boot.c           |  5 +++++
 discover/device-handler.h |  1 +
 discover/pxe-parser.c     | 14 +++++++++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)

Comments

Sam Mendoza-Jonas Nov. 21, 2017, 3:27 a.m. UTC | #1
On Thu, 2017-11-16 at 14:49 +1100, Cyril Bur wrote:
> Petitboot provides a method for a user to manually specify a
> configuration file that should be retrieved. Petitboot also has a
> global proxy configuration.
> 
> This patch aims to marry the two so that a custom configuration file
> can specify that a specific proxy should be used to access one (or all)
> of the options within it.
> 
> This makes custom configuration files more powerful as they can point
> to files behind proxies without the user needing to also specify the
> global proxy for that specific custom configuration file to work.
> 
> This adds parsing for a `proxy` option which will apply to all boot
> items found after.
> 
> Signed-off-by: Cyril Bur <cyrilbur@gmail.com>

Thanks for the yak-shaving! Series merged as 3a76e42.

Sam
diff mbox series

Patch

diff --git a/discover/boot.c b/discover/boot.c
index fab4b61..ba4e720 100644
--- a/discover/boot.c
+++ b/discover/boot.c
@@ -579,6 +579,11 @@  struct boot_task *boot(void *ctx, struct discover_boot_option *opt,
 		dtb = opt->dtb->url;
 	}
 
+	if (opt && opt->proxy) {
+		setenv("http_proxy", opt->proxy, 1);
+		setenv("https_proxy", opt->proxy, 1);
+	}
+
 	boot_task = talloc_zero(ctx, struct boot_task);
 	boot_task->dry_run = dry_run;
 	boot_task->status_fn = status_fn;
diff --git a/discover/device-handler.h b/discover/device-handler.h
index a95cc9d..771cd06 100644
--- a/discover/device-handler.h
+++ b/discover/device-handler.h
@@ -45,6 +45,7 @@  struct discover_boot_option {
 	struct discover_device	*device;
 	struct boot_option	*option;
 	struct list_item	list;
+	const char              *proxy;
 
 	struct resource		*boot_image;
 	struct resource		*initrd;
diff --git a/discover/pxe-parser.c b/discover/pxe-parser.c
index aef43b8..7183ecf 100644
--- a/discover/pxe-parser.c
+++ b/discover/pxe-parser.c
@@ -31,13 +31,17 @@  struct pxe_parser_info {
 	char				**pxe_conf_files;
 	struct pb_url			*pxe_base_url;
 	int				current;
+	char	                        *proxy;
 };
 
 static void pxe_finish(struct conf_context *conf)
 {
 	struct pxe_parser_info *info = conf->parser_info;
-	if (info->opt)
+	if (info->opt) {
+		if (info->proxy)
+			info->opt->proxy = talloc_strdup(info->opt, info->proxy);
 		discover_context_add_boot_option(conf->dc, info->opt);
+	}
 }
 
 /* We need a slightly modified version of pb_url_join, to allow for the
@@ -148,6 +152,14 @@  static void pxe_process_pair(struct conf_context *ctx,
 		return;
 	}
 
+	if (streq(name, "PROXY")) {
+		if (parser_info->proxy)
+			talloc_free(parser_info->proxy);
+
+		parser_info->proxy = talloc_strdup(parser_info, value);
+		return;
+	}
+
 	if (streq(name, "LABEL") || streq(name, "PLUGIN")) {
 		if (opt)
 			pxe_finish(ctx);