]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
bootp: export next server IP as environment variable
authorAndrei Borzenkov <arvidjaar@gmail.com>
Tue, 22 Nov 2016 17:42:23 +0000 (20:42 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Tue, 22 Nov 2016 17:43:04 +0000 (20:43 +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>_next_server variable. This allows
grub configuration script to set $root/$prefix based on information obtained
by net_bootp.

Reported and tested by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Cc: nikunj@linux.vnet.ibm.com
v2: change variable name to net_<interface>_next_server as discussed on the list

docs/grub.texi
grub-core/net/bootp.c

index 82f6fa4597c99cd318f4be61b722011d3fe7c026..b9ddb9b8a4464ac1eccd3faab8eda1b9405e9034 100644 (file)
@@ -2446,6 +2446,10 @@ The boot file name provided by DHCP.  Read-only.
 The name of the DHCP server responsible for these boot parameters.
 Read-only.
 
+@item net_@var{<interface>}_next_server
+The IP address of the next (usually, TFTP) server provided by DHCP.
+Read-only.
+
 @item net_default_interface
 Initially set to name of network interface that was used to load grub.
 Read-write, although setting it affects only interpretation of
@@ -3062,6 +3066,7 @@ These variables have special meaning to GRUB.
 * net_@var{<interface>}_hostname::
 * net_@var{<interface>}_ip::
 * net_@var{<interface>}_mac::
+* net_@var{<interface>}_next_server::
 * net_@var{<interface>}_rootpath::
 * net_default_interface::
 * net_default_ip::
@@ -3422,6 +3427,12 @@ The default is the value of @samp{color_normal} (@pxref{color_normal}).
 @xref{Network}.
 
 
+@node net_@var{<interface>}_next_server
+@subsection net_@var{<interface>}_next_server
+
+@xref{Network}.
+
+
 @node net_@var{<interface>}_rootpath
 @subsection net_@var{<interface>}_rootpath
 
index 189551a483ab9413cdca27650b20267268fa724a..9e2fdb795f55e465f085e965739da9d28c3f7928 100644 (file)
@@ -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;
@@ -192,15 +193,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, "next_server", 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 ();
     }
 
@@ -212,11 +220,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)