dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0058-add-grub_env_set_net_property-function.patch

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