dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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