nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

23d2ea
From dfbcd97b4207c2684fdf3cfe4292e0c96c65eed2 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
23d2ea
Subject: [PATCH 058/198] 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
 ChangeLog             |  8 +++++++
39700a
 grub-core/net/bootp.c | 63 +++++++++++++--------------------------------------
39700a
 grub-core/net/net.c   | 38 +++++++++++++++++++++++++++++++
39700a
 include/grub/net.h    |  4 ++++
39700a
 4 files changed, 66 insertions(+), 47 deletions(-)
39700a
39700a
diff --git a/ChangeLog b/ChangeLog
39700a
index f4a4721..63f5aa3 100644
39700a
--- a/ChangeLog
39700a
+++ b/ChangeLog
39700a
@@ -1,3 +1,11 @@
39700a
+2014-02-04  Paulo Flabiano Smorigo  <pfsmorigo@br.ibm.com>
39700a
+
39700a
+	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
 2014-02-03  Vladimir Serbinenko  <phcoder@gmail.com>
39700a
 
39700a
 	* util/grub-mkrescue.c: Build fix for argp.h with older gcc.
39700a
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
39700a
index c14e9de..6310ed4 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
39700a
index 1521d8d..f2e723b 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
39700a
index 0e0a605..538baa3 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
 
39700a
-- 
23d2ea
2.7.4
39700a