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

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