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