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