nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0437-New-variables-net_default_-to-determine-MAC-IP-of-de.patch

f96e0b
From 95329b0fbbbd6c7258c275a27ed904bdae11caad Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Tue, 7 May 2013 12:05:36 +0200
f96e0b
Subject: [PATCH 437/482] 	New variables 'net_default_*' to determine
f96e0b
 MAC/IP of default interface.
f96e0b
f96e0b
---
f96e0b
 ChangeLog             |  4 +++
f96e0b
 grub-core/net/bootp.c |  3 +++
f96e0b
 grub-core/net/net.c   | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++-
f96e0b
 3 files changed, 75 insertions(+), 1 deletion(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 67b4c6f..cbd5d97 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,5 +1,9 @@
f96e0b
 2013-05-07  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
+	New variables 'net_default_*' to determine MAC/IP of default interface.
f96e0b
+
f96e0b
+2013-05-07  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
 	* tests/gettext_strings_test.in: A test to check for strings not
f96e0b
 	marked for translation.
f96e0b
 
f96e0b
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
f96e0b
index 33f860a..c8ef4d6 100644
f96e0b
--- a/grub-core/net/bootp.c
f96e0b
+++ b/grub-core/net/bootp.c
f96e0b
@@ -211,6 +211,9 @@ grub_net_configure_by_dhcp_ack (const char *name,
f96e0b
       grub_print_error ();
f96e0b
     }
f96e0b
 
f96e0b
+  if (is_def)
f96e0b
+    grub_env_set ("net_default_interface", name);
f96e0b
+
f96e0b
   if (device && !*device && bp->server_ip)
f96e0b
     {
f96e0b
       *device = grub_xasprintf ("tftp,%d.%d.%d.%d",
f96e0b
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
f96e0b
index aebbe4b..8ea6906 100644
f96e0b
--- a/grub-core/net/net.c
f96e0b
+++ b/grub-core/net/net.c
f96e0b
@@ -1,6 +1,6 @@
f96e0b
 /*
f96e0b
  *  GRUB  --  GRand Unified Bootloader
f96e0b
- *  Copyright (C) 2010,2011  Free Software Foundation, Inc.
f96e0b
+ *  Copyright (C) 2010,2011,2012,2013  Free Software Foundation, Inc.
f96e0b
  *
f96e0b
  *  GRUB is free software: you can redistribute it and/or modify
f96e0b
  *  it under the terms of the GNU General Public License as published by
f96e0b
@@ -813,6 +813,69 @@ defserver_get_env (struct grub_env_var *var __attribute__ ((unused)),
f96e0b
   return grub_net_default_server ? : "";
f96e0b
 }
f96e0b
 
f96e0b
+static const char *
f96e0b
+defip_get_env (struct grub_env_var *var __attribute__ ((unused)),
f96e0b
+	       const char *val __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  const char *intf = grub_env_get ("net_default_interface");
f96e0b
+  const char *ret = NULL;
f96e0b
+  if (intf)
f96e0b
+    {
f96e0b
+      char *buf = grub_xasprintf ("net_%s_ip", intf);
f96e0b
+      if (buf)
f96e0b
+	ret = grub_env_get (buf);
f96e0b
+      grub_free (buf);
f96e0b
+    }
f96e0b
+  return ret;
f96e0b
+}
f96e0b
+
f96e0b
+static char *
f96e0b
+defip_set_env (struct grub_env_var *var __attribute__ ((unused)),
f96e0b
+	       const char *val)
f96e0b
+{
f96e0b
+  const char *intf = grub_env_get ("net_default_interface");
f96e0b
+  if (intf)
f96e0b
+    {
f96e0b
+      char *buf = grub_xasprintf ("net_%s_ip", intf);
f96e0b
+      if (buf)
f96e0b
+	grub_env_set (buf, val);
f96e0b
+      grub_free (buf);
f96e0b
+    }
f96e0b
+  return NULL;
f96e0b
+}
f96e0b
+
f96e0b
+
f96e0b
+static const char *
f96e0b
+defmac_get_env (struct grub_env_var *var __attribute__ ((unused)),
f96e0b
+	       const char *val __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  const char *intf = grub_env_get ("net_default_interface");
f96e0b
+  const char *ret = NULL;
f96e0b
+  if (intf)
f96e0b
+    {
f96e0b
+      char *buf = grub_xasprintf ("net_%s_mac", intf);
f96e0b
+      if (buf)
f96e0b
+	ret = grub_env_get (buf);
f96e0b
+      grub_free (buf);
f96e0b
+    }
f96e0b
+  return ret;
f96e0b
+}
f96e0b
+
f96e0b
+static char *
f96e0b
+defmac_set_env (struct grub_env_var *var __attribute__ ((unused)),
f96e0b
+	       const char *val)
f96e0b
+{
f96e0b
+  const char *intf = grub_env_get ("net_default_interface");
f96e0b
+  if (intf)
f96e0b
+    {
f96e0b
+      char *buf = grub_xasprintf ("net_%s_mac", intf);
f96e0b
+      if (buf)
f96e0b
+	grub_env_set (buf, val);
f96e0b
+      grub_free (buf);
f96e0b
+    }
f96e0b
+  return NULL;
f96e0b
+}
f96e0b
+
f96e0b
 
f96e0b
 static void
f96e0b
 grub_net_network_level_interface_register (struct grub_net_network_level_interface *inter)
f96e0b
@@ -1560,6 +1623,10 @@ GRUB_MOD_INIT(net)
f96e0b
 			       defserver_set_env);
f96e0b
   grub_register_variable_hook ("pxe_default_server", defserver_get_env,
f96e0b
 			       defserver_set_env);
f96e0b
+  grub_register_variable_hook ("net_default_ip", defip_get_env,
f96e0b
+			       defip_set_env);
f96e0b
+  grub_register_variable_hook ("net_default_mac", defmac_get_env,
f96e0b
+			       defmac_set_env);
f96e0b
 
f96e0b
   cmd_addaddr = grub_register_command ("net_add_addr", grub_cmd_addaddr,
f96e0b
 					/* TRANSLATORS: HWADDRESS stands for
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b