grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: Daniel Kiper <dkiper@net-space.pl>,
	phcoder@gmail.com, grub-devel@gnu.org
Cc: nikunj@linux.vnet.ibm.com
Subject: Re: [2.02][PATCH] bootp: export server IP as environment variable
Date: Fri, 18 Nov 2016 21:11:47 +0300	[thread overview]
Message-ID: <8dcbe77f-6075-b4dc-933f-6b7a30be3742@gmail.com> (raw)
In-Reply-To: <20161117190234.GA7245@router-fw-old.local.net-space.pl>

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

17.11.2016 22:02, Daniel Kiper пишет:
> On Fri, Mar 18, 2016 at 08:42:00PM +0300, Andrei Borzenkov wrote:
>> 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 <nikunj@linux.vnet.ibm.com>
>> Cc: nikunj@linux.vnet.ibm.com
>>
>> ---
>>
>> @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.
> 
> Vladimir, Andrei, could you take care of it?
> 
> Daniel
> 

I added documentation (not worth separate patch); if there are no
objections I commit.



[-- Attachment #2: bootp-server-ip.patch --]
[-- Type: text/x-patch, Size: 4162 bytes --]

From: Andrei Borzenkov <arvidjaar@gmail.com>
Subject: [2.02][PATCH] bootp: export server IP as environment variable

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 <nikunj@linux.vnet.ibm.com>
Cc: nikunj@linux.vnet.ibm.com

---
 docs/grub.texi        | 11 +++++++++++
 grub-core/net/bootp.c | 24 ++++++++++++++----------
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/docs/grub.texi b/docs/grub.texi
index 82f6fa4..bb03875 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -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>}_server_ip
+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>}_server_ip::
 * net_@var{<interface>}_rootpath::
 * net_default_interface::
 * net_default_ip::
@@ -3428,6 +3433,12 @@ The default is the value of @samp{color_normal} (@pxref{color_normal}).
 @xref{Network}.
 
 
+@node net_@var{<interface>}_server_ip
+@subsection net_@var{<interface>}_server_ip
+
+@xref{Network}.
+
+
 @node net_default_interface
 @subsection net_default_interface
 
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
index 189551a..6503840 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;
@@ -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, "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 ();
     }
 
@@ -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)
-- 
tg: (0d663b5..) u/bootp-server-ip (depends on: master)

  reply	other threads:[~2016-11-18 18:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-18 17:42 [2.02][PATCH] bootp: export server IP as environment variable Andrei Borzenkov
2016-11-17 19:02 ` Daniel Kiper
2016-11-18 18:11   ` Andrei Borzenkov [this message]
2016-11-21 13:09     ` Daniel Kiper
2016-11-21 19:52       ` Andrei Borzenkov
2016-11-21 22:02         ` Daniel Kiper
2016-11-22 17:21           ` Andrei Borzenkov
2016-11-22 18:19             ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8dcbe77f-6075-b4dc-933f-6b7a30be3742@gmail.com \
    --to=arvidjaar@gmail.com \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    --cc=nikunj@linux.vnet.ibm.com \
    --cc=phcoder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).