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