grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[2.02][PATCH] bootp: export server IP as environment variable


From: Andrei Borzenkov
Subject: [2.02][PATCH] bootp: export server IP as environment variable
Date: Fri, 18 Mar 2016 20:42:00 +0300

Network boot autoconfiguration sets default server to next server IP
(siaddr) from BOOTP/DHCP reply, but manual configuration using net_bootp
exports only server name. Unfortunately semantic of server name is not
clearly defined. BOOTP RFC 951 defines it only for client request, and
DHCP RFC 1541 only mentions it, without any implied usage. It looks like
this field is mostly empty in server replies.

Export next server IP as net_<interface>_server_ip variable. This allows
grub configuration script to set $root/$prefix based on information obtained
by net_bootp.

Reported and tested by: Nikunj A Dadhania <address@hidden>
Cc: address@hidden

---

@Nikunj: cosmetic changes comparing with version you tested - no need to
allocate small buffer dynamically.

@Vladimir: I think this is useful; I will update networking documentation
in followup patch.

 grub-core/net/bootp.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
index a088244..c6fb807 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[sizeof ("xxx.xxx.xxx.xxx")];
 
   addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
   addr.ipv4 = bp->your_ip;
@@ -189,15 +190,22 @@ 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)
+    {
+      grub_snprintf (server_ip, sizeof (server_ip), "%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_env_set_net_property (name, "server_ip", server_ip, sizeof 
(server_ip));
+      grub_print_error ();
+    }
+
   if (is_def)
     grub_net_default_server = 0;
   if (is_def && !grub_net_default_server && bp->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 ();
     }
 
@@ -209,11 +217,7 @@ grub_net_configure_by_dhcp_ack (const char *name,
 
   if (device && !*device && bp->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)
-- 
tg: (76eac44..) u/bootp-server-ip (depends on: master)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]