Blame SOURCES/0075-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Michael Chang <mchang@suse.com>
8e15ce
Date: Wed, 10 Jul 2019 23:58:28 +0200
8e15ce
Subject: [PATCH] bootp: Add processing DHCPACK packet from HTTP Boot
8e15ce
8e15ce
The vendor class identifier with the string "HTTPClient" is used to denote the
8e15ce
packet as responding to HTTP boot request. In DHCP4 config, the filename for
8e15ce
HTTP boot is the URL of the boot file while for PXE boot it is the path to the
8e15ce
boot file. As a consequence, the next-server becomes obseleted because the HTTP
8e15ce
URL already contains the server address for the boot file. For DHCP6 config,
8e15ce
there's no difference definition in existing config as dhcp6.bootfile-url can
8e15ce
be used to specify URL for both HTTP and PXE boot file.
8e15ce
8e15ce
This patch adds processing for "HTTPClient" vendor class identifier in DHCPACK
8e15ce
packet by treating it as HTTP format, not as the PXE format.
8e15ce
8e15ce
Signed-off-by: Michael Chang <mchang@suse.com>
8e15ce
Signed-off-by: Ken Lin <ken.lin@hpe.com>
8e15ce
---
8e15ce
 grub-core/net/bootp.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
8e15ce
 include/grub/net.h    |  1 +
8e15ce
 2 files changed, 56 insertions(+)
8e15ce
8e15ce
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
b35c50
index fe93b80f1c..8fb8918ae7 100644
8e15ce
--- a/grub-core/net/bootp.c
8e15ce
+++ b/grub-core/net/bootp.c
8e15ce
@@ -20,6 +20,7 @@
8e15ce
 #include <grub/env.h>
8e15ce
 #include <grub/i18n.h>
8e15ce
 #include <grub/command.h>
8e15ce
+#include <grub/net.h>
8e15ce
 #include <grub/net/ip.h>
8e15ce
 #include <grub/net/netbuff.h>
8e15ce
 #include <grub/net/udp.h>
8e15ce
@@ -500,6 +501,60 @@ grub_net_configure_by_dhcp_ack (const char *name,
8e15ce
   if (opt && opt_len)
8e15ce
     grub_env_set_net_property (name, "rootpath", (const char *) opt, opt_len);
8e15ce
 
8e15ce
+  opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER, &opt_len);
8e15ce
+  if (opt && opt_len)
8e15ce
+    {
8e15ce
+      grub_env_set_net_property (name, "vendor_class_identifier", (const char *) opt, opt_len);
8e15ce
+      if (opt && grub_strcmp (opt, "HTTPClient") == 0)
8e15ce
+        {
8e15ce
+          char *proto, *ip, *pa;
8e15ce
+
8e15ce
+          if (!dissect_url (bp->boot_file, &proto, &ip, &pa))
8e15ce
+            return inter;
8e15ce
+
8e15ce
+          grub_env_set_net_property (name, "boot_file", pa, grub_strlen (pa));
8e15ce
+          if (is_def)
8e15ce
+            {
8e15ce
+              grub_net_default_server = grub_strdup (ip);
8e15ce
+              grub_env_set ("net_default_interface", name);
8e15ce
+             grub_env_export ("net_default_interface");
8e15ce
+            }
8e15ce
+          if (device && !*device)
8e15ce
+            {
8e15ce
+              *device = grub_xasprintf ("%s,%s", proto, ip);
8e15ce
+              grub_print_error ();
8e15ce
+            }
8e15ce
+          if (path)
8e15ce
+            {
8e15ce
+              *path = grub_strdup (pa);
8e15ce
+              grub_print_error ();
8e15ce
+              if (*path)
8e15ce
+                {
8e15ce
+                  char *slash;
8e15ce
+                  slash = grub_strrchr (*path, '/');
8e15ce
+                  if (slash)
8e15ce
+                    *slash = 0;
8e15ce
+                  else
8e15ce
+                    **path = 0;
8e15ce
+                }
8e15ce
+            }
8e15ce
+          grub_net_add_ipv4_local (inter, mask);
8e15ce
+          inter->dhcp_ack = grub_malloc (size);
8e15ce
+          if (inter->dhcp_ack)
8e15ce
+            {
8e15ce
+              grub_memcpy (inter->dhcp_ack, bp, size);
8e15ce
+              inter->dhcp_acklen = size;
8e15ce
+            }
8e15ce
+          else
8e15ce
+            grub_errno = GRUB_ERR_NONE;
8e15ce
+
8e15ce
+          grub_free (proto);
8e15ce
+          grub_free (ip);
8e15ce
+          grub_free (pa);
8e15ce
+          return inter;
8e15ce
+        }
8e15ce
+    }
8e15ce
+
8e15ce
   opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_EXTENSIONS_PATH, &opt_len);
8e15ce
   if (opt && opt_len)
8e15ce
     grub_env_set_net_property (name, "extensionspath", (const char *) opt, opt_len);
8e15ce
diff --git a/include/grub/net.h b/include/grub/net.h
b35c50
index 543251f727..42af7de250 100644
8e15ce
--- a/include/grub/net.h
8e15ce
+++ b/include/grub/net.h
8e15ce
@@ -531,6 +531,7 @@ enum
8e15ce
     GRUB_NET_DHCP_MESSAGE_TYPE = 53,
8e15ce
     GRUB_NET_DHCP_SERVER_IDENTIFIER = 54,
8e15ce
     GRUB_NET_DHCP_PARAMETER_REQUEST_LIST = 55,
8e15ce
+    GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER = 60,
8e15ce
     GRUB_NET_BOOTP_CLIENT_ID = 61,
8e15ce
     GRUB_NET_DHCP_TFTP_SERVER_NAME = 66,
8e15ce
     GRUB_NET_DHCP_BOOTFILE_NAME = 67,