nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

f725e3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f725e3
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
f725e3
Date: Tue, 27 Nov 2012 17:18:53 -0200
f725e3
Subject: [PATCH] DHCP client ID and UUID options added.
f725e3
f725e3
---
f725e3
 grub-core/net/bootp.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++-----
f725e3
 include/grub/net.h    |  2 ++
f725e3
 2 files changed, 81 insertions(+), 8 deletions(-)
f725e3
f725e3
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
f725e3
index 6310ed447e8..88f20568914 100644
f725e3
--- a/grub-core/net/bootp.c
f725e3
+++ b/grub-core/net/bootp.c
f725e3
@@ -25,6 +25,49 @@
f725e3
 #include <grub/net/udp.h>
f725e3
 #include <grub/datetime.h>
f725e3
 
f725e3
+static char *
f725e3
+grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)),
f725e3
+			 const char *val __attribute__ ((unused)))
f725e3
+{
f725e3
+  return NULL;
f725e3
+}
f725e3
+
f725e3
+static void
f725e3
+set_env_limn_ro (const char *intername, const char *suffix,
f725e3
+		 const char *value, grub_size_t len)
f725e3
+{
f725e3
+  char *varname, *varvalue;
f725e3
+  char *ptr;
f725e3
+  varname = grub_xasprintf ("net_%s_%s", intername, suffix);
f725e3
+  if (!varname)
f725e3
+    return;
f725e3
+  for (ptr = varname; *ptr; ptr++)
f725e3
+    if (*ptr == ':')
f725e3
+      *ptr = '_';
f725e3
+  varvalue = grub_malloc (len + 1);
f725e3
+  if (!varvalue)
f725e3
+    {
f725e3
+      grub_free (varname);
f725e3
+      return;
f725e3
+    }
f725e3
+
f725e3
+  grub_memcpy (varvalue, value, len);
f725e3
+  varvalue[len] = 0;
f725e3
+  grub_env_set (varname, varvalue);
f725e3
+  grub_register_variable_hook (varname, 0, grub_env_write_readonly);
f725e3
+  grub_env_export (varname);
f725e3
+  grub_free (varname);
f725e3
+  grub_free (varvalue);
f725e3
+}
f725e3
+
f725e3
+static char
f725e3
+hexdigit (grub_uint8_t val)
f725e3
+{
f725e3
+  if (val < 10)
f725e3
+    return val + '0';
f725e3
+  return val + 'a' - 10;
f725e3
+}
f725e3
+
f725e3
 static void
f725e3
 parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
f725e3
 {
f725e3
@@ -55,6 +98,9 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
f725e3
 
f725e3
       taglength = *ptr++;
f725e3
 
f725e3
+      grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n",
f725e3
+                   tagtype, tagtype, taglength);
f725e3
+
f725e3
       switch (tagtype)
f725e3
 	{
f725e3
 	case GRUB_NET_BOOTP_NETMASK:
f725e3
@@ -120,6 +166,39 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
f725e3
                                      taglength);
f725e3
           break;
f725e3
 
f725e3
+        case GRUB_NET_BOOTP_CLIENT_ID:
f725e3
+	  set_env_limn_ro (name, "clientid", (char *) ptr, taglength);
f725e3
+          break;
f725e3
+
f725e3
+        case GRUB_NET_BOOTP_CLIENT_UUID:
f725e3
+            {
f725e3
+              if (taglength != 17)
f725e3
+                break;
f725e3
+
f725e3
+              /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */
f725e3
+
f725e3
+              ptr += 1;
f725e3
+              taglength -= 1;
f725e3
+
f725e3
+              char *val = grub_malloc (2 * taglength + 4 + 1);
f725e3
+              int i = 0;
f725e3
+              int j = 0;
f725e3
+              for (i = 0; i < taglength; i++)
f725e3
+                {
f725e3
+                  val[2 * i + j] = hexdigit (ptr[i] >> 4);
f725e3
+                  val[2 * i + 1 + j] = hexdigit (ptr[i] & 0xf);
f725e3
+
f725e3
+                  if ((i == 3) || (i == 5) || (i == 7) || (i == 9))
f725e3
+                    {
f725e3
+                      j++;
f725e3
+                      val[2 * i + 1+ j] = '-';
f725e3
+                    }
f725e3
+                }
f725e3
+
f725e3
+              set_env_limn_ro (name, "clientuuid", (char *) val, 2 * taglength + 4);
f725e3
+            }
f725e3
+          break;
f725e3
+
f725e3
 	  /* If you need any other options please contact GRUB
f725e3
 	     development team.  */
f725e3
 	}
f725e3
@@ -288,14 +367,6 @@ grub_net_process_dhcp (struct grub_net_buff *nb,
f725e3
     }
f725e3
 }
f725e3
 
f725e3
-static char
f725e3
-hexdigit (grub_uint8_t val)
f725e3
-{
f725e3
-  if (val < 10)
f725e3
-    return val + '0';
f725e3
-  return val + 'a' - 10;
f725e3
-}
f725e3
-
f725e3
 static grub_err_t
f725e3
 grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)),
f725e3
 		  int argc, char **args)
f725e3
diff --git a/include/grub/net.h b/include/grub/net.h
f725e3
index a799e6b8b69..59e5975b11f 100644
f725e3
--- a/include/grub/net.h
f725e3
+++ b/include/grub/net.h
f725e3
@@ -433,6 +433,8 @@ enum
f725e3
     GRUB_NET_BOOTP_DOMAIN = 0x0f,
f725e3
     GRUB_NET_BOOTP_ROOT_PATH = 0x11,
f725e3
     GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12,
f725e3
+    GRUB_NET_BOOTP_CLIENT_ID = 0x3d,
f725e3
+    GRUB_NET_BOOTP_CLIENT_UUID = 0x61,
f725e3
     GRUB_NET_BOOTP_END = 0xff
f725e3
   };
f725e3