17.03.2016 11:45, Nikunj A Dadhania пишет:
> Andrei Borzenkov <arvidj...@gmail.com> writes:
> 
>> On Thu, Mar 17, 2016 at 11:04 AM, Nikunj A Dadhania
>> <nik...@linux.vnet.ibm.com> wrote:
>>> net_default_interface=ofnet_net:dhcp
>>> net_default_ip=(null)
>>> net_default_mac=(null)
>>> net_default_server=10.0.2.2
>>> net_ofnet_net_dhcp_boot_file=ubuntu-installer/ppc64el/powerpc-ieee1275/core.elf
>>> net_ofnet_net_dhcp_ip=10.0.2.15
>>> net_ofnet_net_dhcp_mac=52:54:00:12:34:56
>>
>>
>> OK, we probably need to export not only name, but also IP to match
>> default case. Could you attach bootp reply packet?
> 
> Attached the pcap file, it has the request as well as the ack.
> 
>> I wonder if anyone ever seen or used net_if_dhcp_server_name variable;
>> because net_boot sets interface name to card:dhcp, this actually
>> becomes net_card_dhcp_dhcp_server_name. Someone would sure have
>> noticed it.
> 

Please test attached patch. It sets net_<card>_dhcp_server_ip variable.

We probably need to offer programmatic way to iterate through all cards
in CLI. But as long as you have single card with known name it should be
OK.
From: Andrei Borzenkov <arvidj...@gmail.com>
Subject: [PATCH] bootp: export server IP as environment variable



---
 grub-core/net/bootp.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
index a088244..c70cc09 100644
--- a/grub-core/net/bootp.c
+++ b/grub-core/net/bootp.c
@@ -142,6 +142,7 @@ grub_net_configure_by_dhcp_ack (const char *name,
   grub_net_link_level_address_t hwaddr;
   struct grub_net_network_level_interface *inter;
   int mask = -1;
+  char *server_ip = 0;
 
   addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
   addr.ipv4 = bp->your_ip;
@@ -189,15 +190,27 @@ grub_net_configure_by_dhcp_ack (const char *name,
   if (size > OFFSET_OF (boot_file, bp))
     grub_env_set_net_property (name, "boot_file", bp->boot_file,
                                sizeof (bp->boot_file));
+  if (bp->server_ip)
+    {
+      server_ip = grub_xasprintf ("%d.%d.%d.%d",
+				  ((grub_uint8_t *) &bp->server_ip)[0],
+				  ((grub_uint8_t *) &bp->server_ip)[1],
+				  ((grub_uint8_t *) &bp->server_ip)[2],
+				  ((grub_uint8_t *) &bp->server_ip)[3]);
+      grub_print_error ();
+    }
+
+  if (server_ip)
+    {
+      grub_env_set_net_property (name, "server_ip", server_ip, grub_strlen (server_ip));
+      grub_print_error ();
+    }
+
   if (is_def)
     grub_net_default_server = 0;
-  if (is_def && !grub_net_default_server && bp->server_ip)
+  if (is_def && !grub_net_default_server && server_ip)
     {
-      grub_net_default_server = grub_xasprintf ("%d.%d.%d.%d",
-						((grub_uint8_t *) &bp->server_ip)[0],
-						((grub_uint8_t *) &bp->server_ip)[1],
-						((grub_uint8_t *) &bp->server_ip)[2],
-						((grub_uint8_t *) &bp->server_ip)[3]);
+      grub_net_default_server = grub_strdup (server_ip);
       grub_print_error ();
     }
 
@@ -207,13 +220,9 @@ grub_net_configure_by_dhcp_ack (const char *name,
       grub_env_export ("net_default_interface");
     }
 
-  if (device && !*device && bp->server_ip)
+  if (device && !*device && server_ip)
     {
-      *device = grub_xasprintf ("tftp,%d.%d.%d.%d",
-				((grub_uint8_t *) &bp->server_ip)[0],
-				((grub_uint8_t *) &bp->server_ip)[1],
-				((grub_uint8_t *) &bp->server_ip)[2],
-				((grub_uint8_t *) &bp->server_ip)[3]);
+      *device = grub_xasprintf ("tftp,%s", server_ip);
       grub_print_error ();
     }
   if (size > OFFSET_OF (server_name, bp)
@@ -260,6 +269,7 @@ grub_net_configure_by_dhcp_ack (const char *name,
   else
     grub_errno = GRUB_ERR_NONE;
 
+  grub_free (server_ip);
   return inter;
 }
 
-- 
tg: (76eac44..) u/bootp-server-ip (depends on: master)
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to