dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0011-DHCP-client-ID-and-UUID-options-added.patch

606ea6
From 1c9b8bec85cd2600da2f8a16ed08820300c02bee Mon Sep 17 00:00:00 2001
606ea6
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
606ea6
Date: Tue, 27 Nov 2012 17:18:53 -0200
606ea6
Subject: [PATCH 11/34] DHCP client ID and UUID options added.
606ea6
606ea6
---
606ea6
 grub-core/net/bootp.c | 52 +++++++++++++++++++++++++++++++++++++++++++--------
606ea6
 include/grub/net.h    |  2 ++
606ea6
 2 files changed, 46 insertions(+), 8 deletions(-)
606ea6
606ea6
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
606ea6
index c14e9de..656bb71 100644
606ea6
--- a/grub-core/net/bootp.c
606ea6
+++ b/grub-core/net/bootp.c
606ea6
@@ -60,6 +60,14 @@ set_env_limn_ro (const char *intername, const char *suffix,
606ea6
   grub_free (varvalue);
606ea6
 }
606ea6
 
606ea6
+static char
606ea6
+hexdigit (grub_uint8_t val)
606ea6
+{
606ea6
+  if (val < 10)
606ea6
+    return val + '0';
606ea6
+  return val + 'a' - 10;
606ea6
+}
606ea6
+
606ea6
 static void
606ea6
 parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
606ea6
 {
606ea6
@@ -90,6 +98,9 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
606ea6
 
606ea6
       taglength = *ptr++;
606ea6
 
606ea6
+      grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n",
606ea6
+                   tagtype, tagtype, taglength);
606ea6
+
606ea6
       switch (tagtype)
606ea6
 	{
606ea6
 	case GRUB_NET_BOOTP_NETMASK:
606ea6
@@ -151,6 +162,39 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
606ea6
 	  set_env_limn_ro (name, "extensionspath", (const char *) ptr, taglength);
606ea6
 	  break;
606ea6
 
606ea6
+        case GRUB_NET_BOOTP_CLIENT_ID:
606ea6
+	  set_env_limn_ro (name, "clientid", (char *) ptr, taglength);
606ea6
+          break;
606ea6
+
606ea6
+        case GRUB_NET_BOOTP_CLIENT_UUID:
606ea6
+            {
606ea6
+              if (taglength != 17)
606ea6
+                break;
606ea6
+
606ea6
+              /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */
606ea6
+
606ea6
+              ptr += 1;
606ea6
+              taglength -= 1;
606ea6
+
606ea6
+              char *val = grub_malloc (2 * taglength + 4 + 1);
606ea6
+              int i = 0;
606ea6
+              int j = 0;
606ea6
+              for (i = 0; i < taglength; i++)
606ea6
+                {
606ea6
+                  val[2 * i + j] = hexdigit (ptr[i] >> 4);
606ea6
+                  val[2 * i + 1 + j] = hexdigit (ptr[i] & 0xf);
606ea6
+
606ea6
+                  if ((i == 3) || (i == 5) || (i == 7) || (i == 9))
606ea6
+                    {
606ea6
+                      j++;
606ea6
+                      val[2 * i + 1+ j] = '-';
606ea6
+                    }
606ea6
+                }
606ea6
+
606ea6
+              set_env_limn_ro (name, "clientuuid", (char *) val, 2 * taglength + 4);
606ea6
+            }
606ea6
+          break;
606ea6
+
606ea6
 	  /* If you need any other options please contact GRUB
606ea6
 	     development team.  */
606ea6
 	}
606ea6
@@ -319,14 +363,6 @@ grub_net_process_dhcp (struct grub_net_buff *nb,
606ea6
     }
606ea6
 }
606ea6
 
606ea6
-static char
606ea6
-hexdigit (grub_uint8_t val)
606ea6
-{
606ea6
-  if (val < 10)
606ea6
-    return val + '0';
606ea6
-  return val + 'a' - 10;
606ea6
-}
606ea6
-
606ea6
 static grub_err_t
606ea6
 grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)),
606ea6
 		  int argc, char **args)
606ea6
diff --git a/include/grub/net.h b/include/grub/net.h
606ea6
index c8ce8db..ea4978d 100644
606ea6
--- a/include/grub/net.h
606ea6
+++ b/include/grub/net.h
606ea6
@@ -433,6 +433,8 @@ enum
606ea6
     GRUB_NET_BOOTP_DOMAIN = 0x0f,
606ea6
     GRUB_NET_BOOTP_ROOT_PATH = 0x11,
606ea6
     GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12,
606ea6
+    GRUB_NET_BOOTP_CLIENT_ID = 0x3d,
606ea6
+    GRUB_NET_BOOTP_CLIENT_UUID = 0x61,
606ea6
     GRUB_NET_BOOTP_END = 0xff
606ea6
   };
606ea6
 
606ea6
-- 
606ea6
1.8.4.2
606ea6