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