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

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