|
|
f731ee |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
f731ee |
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
|
|
|
f731ee |
Date: Tue, 4 Feb 2014 18:41:38 -0200
|
|
|
f731ee |
Subject: [PATCH] add grub_env_set_net_property function
|
|
|
f731ee |
|
|
|
f731ee |
* grub-core/net/bootp.c: Remove set_env_limn_ro.
|
|
|
f731ee |
* grub-core/net/net.c: Add grub_env_set_net_property.
|
|
|
f731ee |
* include/grub/net.h: Likewise.
|
|
|
f731ee |
---
|
|
|
f731ee |
grub-core/net/bootp.c | 63 +++++++++++++--------------------------------------
|
|
|
f731ee |
grub-core/net/net.c | 38 +++++++++++++++++++++++++++++++
|
|
|
f731ee |
include/grub/net.h | 4 ++++
|
|
|
f731ee |
ChangeLog | 8 +++++++
|
|
|
f731ee |
4 files changed, 66 insertions(+), 47 deletions(-)
|
|
|
f731ee |
|
|
|
f731ee |
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
|
|
|
f731ee |
index c14e9de57a4..6310ed447e8 100644
|
|
|
f731ee |
--- a/grub-core/net/bootp.c
|
|
|
f731ee |
+++ b/grub-core/net/bootp.c
|
|
|
f731ee |
@@ -25,41 +25,6 @@
|
|
|
f731ee |
#include <grub/net/udp.h>
|
|
|
f731ee |
#include <grub/datetime.h>
|
|
|
f731ee |
|
|
|
f731ee |
-static char *
|
|
|
f731ee |
-grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)),
|
|
|
f731ee |
- const char *val __attribute__ ((unused)))
|
|
|
f731ee |
-{
|
|
|
f731ee |
- return NULL;
|
|
|
f731ee |
-}
|
|
|
f731ee |
-
|
|
|
f731ee |
-static void
|
|
|
f731ee |
-set_env_limn_ro (const char *intername, const char *suffix,
|
|
|
f731ee |
- const char *value, grub_size_t len)
|
|
|
f731ee |
-{
|
|
|
f731ee |
- char *varname, *varvalue;
|
|
|
f731ee |
- char *ptr;
|
|
|
f731ee |
- varname = grub_xasprintf ("net_%s_%s", intername, suffix);
|
|
|
f731ee |
- if (!varname)
|
|
|
f731ee |
- return;
|
|
|
f731ee |
- for (ptr = varname; *ptr; ptr++)
|
|
|
f731ee |
- if (*ptr == ':')
|
|
|
f731ee |
- *ptr = '_';
|
|
|
f731ee |
- varvalue = grub_malloc (len + 1);
|
|
|
f731ee |
- if (!varvalue)
|
|
|
f731ee |
- {
|
|
|
f731ee |
- grub_free (varname);
|
|
|
f731ee |
- return;
|
|
|
f731ee |
- }
|
|
|
f731ee |
-
|
|
|
f731ee |
- grub_memcpy (varvalue, value, len);
|
|
|
f731ee |
- varvalue[len] = 0;
|
|
|
f731ee |
- grub_env_set (varname, varvalue);
|
|
|
f731ee |
- grub_register_variable_hook (varname, 0, grub_env_write_readonly);
|
|
|
f731ee |
- grub_env_export (varname);
|
|
|
f731ee |
- grub_free (varname);
|
|
|
f731ee |
- grub_free (varvalue);
|
|
|
f731ee |
-}
|
|
|
f731ee |
-
|
|
|
f731ee |
static void
|
|
|
f731ee |
parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
|
|
|
f731ee |
{
|
|
|
f731ee |
@@ -136,20 +101,24 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
|
|
|
f731ee |
}
|
|
|
f731ee |
continue;
|
|
|
f731ee |
case GRUB_NET_BOOTP_HOSTNAME:
|
|
|
f731ee |
- set_env_limn_ro (name, "hostname", (const char *) ptr, taglength);
|
|
|
f731ee |
- break;
|
|
|
f731ee |
+ grub_env_set_net_property (name, "hostname", (const char *) ptr,
|
|
|
f731ee |
+ taglength);
|
|
|
f731ee |
+ break;
|
|
|
f731ee |
|
|
|
f731ee |
case GRUB_NET_BOOTP_DOMAIN:
|
|
|
f731ee |
- set_env_limn_ro (name, "domain", (const char *) ptr, taglength);
|
|
|
f731ee |
- break;
|
|
|
f731ee |
+ grub_env_set_net_property (name, "domain", (const char *) ptr,
|
|
|
f731ee |
+ taglength);
|
|
|
f731ee |
+ break;
|
|
|
f731ee |
|
|
|
f731ee |
case GRUB_NET_BOOTP_ROOT_PATH:
|
|
|
f731ee |
- set_env_limn_ro (name, "rootpath", (const char *) ptr, taglength);
|
|
|
f731ee |
- break;
|
|
|
f731ee |
+ grub_env_set_net_property (name, "rootpath", (const char *) ptr,
|
|
|
f731ee |
+ taglength);
|
|
|
f731ee |
+ break;
|
|
|
f731ee |
|
|
|
f731ee |
case GRUB_NET_BOOTP_EXTENSIONS_PATH:
|
|
|
f731ee |
- set_env_limn_ro (name, "extensionspath", (const char *) ptr, taglength);
|
|
|
f731ee |
- break;
|
|
|
f731ee |
+ grub_env_set_net_property (name, "extensionspath", (const char *) ptr,
|
|
|
f731ee |
+ taglength);
|
|
|
f731ee |
+ break;
|
|
|
f731ee |
|
|
|
f731ee |
/* If you need any other options please contact GRUB
|
|
|
f731ee |
development team. */
|
|
|
f731ee |
@@ -211,8 +180,8 @@ grub_net_configure_by_dhcp_ack (const char *name,
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
if (size > OFFSET_OF (boot_file, bp))
|
|
|
f731ee |
- set_env_limn_ro (name, "boot_file", (char *) bp->boot_file,
|
|
|
f731ee |
- sizeof (bp->boot_file));
|
|
|
f731ee |
+ grub_env_set_net_property (name, "boot_file", bp->boot_file,
|
|
|
f731ee |
+ sizeof (bp->boot_file));
|
|
|
f731ee |
if (is_def)
|
|
|
f731ee |
grub_net_default_server = 0;
|
|
|
f731ee |
if (is_def && !grub_net_default_server && bp->server_ip)
|
|
|
f731ee |
@@ -243,8 +212,8 @@ grub_net_configure_by_dhcp_ack (const char *name,
|
|
|
f731ee |
if (size > OFFSET_OF (server_name, bp)
|
|
|
f731ee |
&& bp->server_name[0])
|
|
|
f731ee |
{
|
|
|
f731ee |
- set_env_limn_ro (name, "dhcp_server_name", (char *) bp->server_name,
|
|
|
f731ee |
- sizeof (bp->server_name));
|
|
|
f731ee |
+ grub_env_set_net_property (name, "dhcp_server_name", bp->server_name,
|
|
|
f731ee |
+ sizeof (bp->server_name));
|
|
|
f731ee |
if (is_def && !grub_net_default_server)
|
|
|
f731ee |
{
|
|
|
f731ee |
grub_net_default_server = grub_strdup (bp->server_name);
|
|
|
f731ee |
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
|
|
|
f731ee |
index 1521d8d2c87..f2e723bd409 100644
|
|
|
f731ee |
--- a/grub-core/net/net.c
|
|
|
f731ee |
+++ b/grub-core/net/net.c
|
|
|
f731ee |
@@ -1480,6 +1480,44 @@ receive_packets (struct grub_net_card *card, int *stop_condition)
|
|
|
f731ee |
grub_print_error ();
|
|
|
f731ee |
}
|
|
|
f731ee |
|
|
|
f731ee |
+static char *
|
|
|
f731ee |
+grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)),
|
|
|
f731ee |
+ const char *val __attribute__ ((unused)))
|
|
|
f731ee |
+{
|
|
|
f731ee |
+ return NULL;
|
|
|
f731ee |
+}
|
|
|
f731ee |
+
|
|
|
f731ee |
+grub_err_t
|
|
|
f731ee |
+grub_env_set_net_property (const char *intername, const char *suffix,
|
|
|
f731ee |
+ const char *value, grub_size_t len)
|
|
|
f731ee |
+{
|
|
|
f731ee |
+ char *varname, *varvalue;
|
|
|
f731ee |
+ char *ptr;
|
|
|
f731ee |
+
|
|
|
f731ee |
+ varname = grub_xasprintf ("net_%s_%s", intername, suffix);
|
|
|
f731ee |
+ if (!varname)
|
|
|
f731ee |
+ return grub_errno;
|
|
|
f731ee |
+ for (ptr = varname; *ptr; ptr++)
|
|
|
f731ee |
+ if (*ptr == ':')
|
|
|
f731ee |
+ *ptr = '_';
|
|
|
f731ee |
+ varvalue = grub_malloc (len + 1);
|
|
|
f731ee |
+ if (!varvalue)
|
|
|
f731ee |
+ {
|
|
|
f731ee |
+ grub_free (varname);
|
|
|
f731ee |
+ return grub_errno;
|
|
|
f731ee |
+ }
|
|
|
f731ee |
+
|
|
|
f731ee |
+ grub_memcpy (varvalue, value, len);
|
|
|
f731ee |
+ varvalue[len] = 0;
|
|
|
f731ee |
+ grub_err_t ret = grub_env_set (varname, varvalue);
|
|
|
f731ee |
+ grub_register_variable_hook (varname, 0, grub_env_write_readonly);
|
|
|
f731ee |
+ grub_env_export (varname);
|
|
|
f731ee |
+ grub_free (varname);
|
|
|
f731ee |
+ grub_free (varvalue);
|
|
|
f731ee |
+
|
|
|
f731ee |
+ return ret;
|
|
|
f731ee |
+}
|
|
|
f731ee |
+
|
|
|
f731ee |
void
|
|
|
f731ee |
grub_net_poll_cards (unsigned time, int *stop_condition)
|
|
|
f731ee |
{
|
|
|
f731ee |
diff --git a/include/grub/net.h b/include/grub/net.h
|
|
|
f731ee |
index 0e0a605c5a6..538baa33eca 100644
|
|
|
f731ee |
--- a/include/grub/net.h
|
|
|
f731ee |
+++ b/include/grub/net.h
|
|
|
f731ee |
@@ -480,6 +480,10 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target,
|
|
|
f731ee |
void
|
|
|
f731ee |
grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str);
|
|
|
f731ee |
|
|
|
f731ee |
+grub_err_t
|
|
|
f731ee |
+grub_env_set_net_property (const char *intername, const char *suffix,
|
|
|
f731ee |
+ const char *value, grub_size_t len);
|
|
|
f731ee |
+
|
|
|
f731ee |
void
|
|
|
f731ee |
grub_net_poll_cards (unsigned time, int *stop_condition);
|
|
|
f731ee |
|
|
|
f731ee |
diff --git a/ChangeLog b/ChangeLog
|
|
|
f731ee |
index f4a472144b1..63f5aa322c3 100644
|
|
|
f731ee |
--- a/ChangeLog
|
|
|
f731ee |
+++ b/ChangeLog
|
|
|
f731ee |
@@ -1,3 +1,11 @@
|
|
|
f731ee |
+2014-02-04 Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
|
|
|
f731ee |
+
|
|
|
f731ee |
+ Add grub_env_set_net_property function.
|
|
|
f731ee |
+
|
|
|
f731ee |
+ * grub-core/net/bootp.c: Remove set_env_limn_ro.
|
|
|
f731ee |
+ * grub-core/net/net.c: Add grub_env_set_net_property.
|
|
|
f731ee |
+ * include/grub/net.h: Likewise.
|
|
|
f731ee |
+
|
|
|
f731ee |
2014-02-03 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f731ee |
|
|
|
f731ee |
* util/grub-mkrescue.c: Build fix for argp.h with older gcc.
|