nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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