31004e6
From af13434ca0de9ef01b5f77fb85d5b3ac6c3d1d91 Mon Sep 17 00:00:00 2001
31004e6
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
31004e6
Date: Tue, 27 Nov 2012 17:18:53 -0200
f74b50e
Subject: [PATCH 456/482] DHCP client ID and UUID options added.
31004e6
31004e6
---
31004e6
 grub-core/net/bootp.c | 52 +++++++++++++++++++++++++++++++++++++++++++--------
31004e6
 include/grub/net.h    |  2 ++
31004e6
 2 files changed, 46 insertions(+), 8 deletions(-)
31004e6
31004e6
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
31004e6
index c8ef4d6..af3cb62 100644
31004e6
--- a/grub-core/net/bootp.c
31004e6
+++ b/grub-core/net/bootp.c
31004e6
@@ -51,6 +51,14 @@ set_env_limn_ro (const char *intername, const char *suffix,
31004e6
   grub_register_variable_hook (varname, 0, grub_env_write_readonly);
31004e6
 }
31004e6
 
31004e6
+static char
31004e6
+hexdigit (grub_uint8_t val)
31004e6
+{
31004e6
+  if (val < 10)
31004e6
+    return val + '0';
31004e6
+  return val + 'a' - 10;
31004e6
+}
31004e6
+
31004e6
 static void
31004e6
 parse_dhcp_vendor (const char *name, void *vend, int limit, int *mask)
31004e6
 {
31004e6
@@ -81,6 +89,9 @@ parse_dhcp_vendor (const char *name, void *vend, int limit, int *mask)
31004e6
 
31004e6
       taglength = *ptr++;
31004e6
 
31004e6
+      grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n",
31004e6
+                   tagtype, tagtype, taglength);
31004e6
+
31004e6
       switch (tagtype)
31004e6
 	{
31004e6
 	case GRUB_NET_BOOTP_NETMASK:
31004e6
@@ -139,6 +150,39 @@ parse_dhcp_vendor (const char *name, void *vend, int limit, int *mask)
31004e6
 	  set_env_limn_ro (name, "extensionspath", (char *) ptr, taglength);
31004e6
 	  break;
31004e6
 
31004e6
+        case GRUB_NET_BOOTP_CLIENT_ID:
31004e6
+	  set_env_limn_ro (name, "clientid", (char *) ptr, taglength);
31004e6
+          break;
31004e6
+
31004e6
+        case GRUB_NET_BOOTP_CLIENT_UUID:
31004e6
+            {
31004e6
+              if (taglength != 17)
31004e6
+                break;
31004e6
+
31004e6
+              /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */
31004e6
+
31004e6
+              ptr += 1;
31004e6
+              taglength -= 1;
31004e6
+
31004e6
+              char *val = grub_malloc (2 * taglength + 4 + 1);
31004e6
+              int i = 0;
31004e6
+              int j = 0;
31004e6
+              for (i = 0; i < taglength; i++)
31004e6
+                {
31004e6
+                  val[2 * i + j] = hexdigit (ptr[i] >> 4);
31004e6
+                  val[2 * i + 1 + j] = hexdigit (ptr[i] & 0xf);
31004e6
+
31004e6
+                  if ((i == 3) || (i == 5) || (i == 7) || (i == 9))
31004e6
+                    {
31004e6
+                      j++;
31004e6
+                      val[2 * i + 1+ j] = '-';
31004e6
+                    }
31004e6
+                }
31004e6
+
31004e6
+              set_env_limn_ro (name, "clientuuid", (char *) val, 2 * taglength + 4);
31004e6
+            }
31004e6
+          break;
31004e6
+
31004e6
 	  /* If you need any other options please contact GRUB
31004e6
 	     development team.  */
31004e6
 	}
31004e6
@@ -302,14 +346,6 @@ grub_net_process_dhcp (struct grub_net_buff *nb,
31004e6
     }
31004e6
 }
31004e6
 
31004e6
-static char
31004e6
-hexdigit (grub_uint8_t val)
31004e6
-{
31004e6
-  if (val < 10)
31004e6
-    return val + '0';
31004e6
-  return val + 'a' - 10;
31004e6
-}
31004e6
-
31004e6
 static grub_err_t
31004e6
 grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)),
31004e6
 		  int argc, char **args)
31004e6
diff --git a/include/grub/net.h b/include/grub/net.h
31004e6
index fe29b16..36ac906 100644
31004e6
--- a/include/grub/net.h
31004e6
+++ b/include/grub/net.h
31004e6
@@ -424,6 +424,8 @@ enum
31004e6
     GRUB_NET_BOOTP_DOMAIN = 0x0f,
31004e6
     GRUB_NET_BOOTP_ROOT_PATH = 0x11,
31004e6
     GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12,
31004e6
+    GRUB_NET_BOOTP_CLIENT_ID = 0x3d,
31004e6
+    GRUB_NET_BOOTP_CLIENT_UUID = 0x61,
31004e6
     GRUB_NET_BOOTP_END = 0xff
31004e6
   };
31004e6
 
31004e6
-- 
31004e6
1.8.2.1
31004e6