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

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