nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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