15a207
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
15a207
From: Peter Jones <pjones@redhat.com>
15a207
Date: Mon, 30 Jul 2018 16:39:57 -0400
3e07ee
Subject: [PATCH] efi/http: Make root_url reflect the protocol+hostname of our
3e07ee
 boot url.
3e07ee
3e07ee
This lets you write config files that don't know urls.
15a207
15a207
Signed-off-by: Peter Jones <pjones@redhat.com>
15a207
---
15a207
 grub-core/net/efi/http.c | 19 +++++++++++++++++++
15a207
 1 file changed, 19 insertions(+)
15a207
15a207
diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c
15a207
index 3f61fd2fa5b..243acbaa35b 100644
15a207
--- a/grub-core/net/efi/http.c
15a207
+++ b/grub-core/net/efi/http.c
15a207
@@ -4,6 +4,7 @@
15a207
 #include <grub misc.h="">
15a207
 #include <grub net="" efi.h="">
15a207
 #include <grub charset.h="">
15a207
+#include <grub env.h="">
15a207
 
15a207
 static void
15a207
 http_configure (struct grub_efi_net_device *dev, int prefer_ip6)
15a207
@@ -351,6 +352,24 @@ grub_efihttp_open (struct grub_efi_net_device *dev,
15a207
   grub_err_t err;
15a207
   grub_off_t size;
15a207
   char *buf;
15a207
+  char *root_url;
15a207
+  grub_efi_ipv6_address_t address;
15a207
+  const char *rest;
15a207
+
15a207
+  if (grub_efi_string_to_ip6_address (file->device->net->server, &address, &rest) && *rest == 0)
15a207
+    root_url = grub_xasprintf ("%s://[%s]", type ? "https" : "http", file->device->net->server);
15a207
+  else
15a207
+    root_url = grub_xasprintf ("%s://%s", type ? "https" : "http", file->device->net->server);
15a207
+  if (root_url)
15a207
+    {
15a207
+      grub_env_unset ("root_url");
15a207
+      grub_env_set ("root_url", root_url);
15a207
+      grub_free (root_url);
15a207
+    }
15a207
+  else
15a207
+    {
15a207
+      return grub_errno;
15a207
+    }
15a207
 
15a207
   err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 1, 0);
15a207
   if (err != GRUB_ERR_NONE)