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