From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1c7ndn-0006Da-Dy for mharc-grub-devel@gnu.org; Fri, 18 Nov 2016 13:11:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7ndl-0006DQ-NI for grub-devel@gnu.org; Fri, 18 Nov 2016 13:11:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7ndg-0003S0-PY for grub-devel@gnu.org; Fri, 18 Nov 2016 13:11:57 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35653) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c7ndg-0003R9-0h for grub-devel@gnu.org; Fri, 18 Nov 2016 13:11:52 -0500 Received: by mail-wm0-x244.google.com with SMTP id a20so8698282wme.2 for ; Fri, 18 Nov 2016 10:11:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=hxouzctdVKLUY5qMmszzgoevutuKxgtq/EJtw7lztnQ=; b=f4nG34X9aFVerXw5wAnaW0ZF5W2iPuPLmhODlEOFUCES7bdWzapmRhWAKtdu9jmhYZ qLv3J+9oFHbD42edFG1xzhCRkc4hWB7MfDgcIL8VabvlF0FGacnH9m+t5/l8I1sGUT+8 Wbl4DQ/rP4QwZY4jPRzXtf4Ycc7v0hCPd5sl+2Efzdh90yKLzUHuNsXNpsjLPafdWHB7 lblIAhHOffjyDHE8nIPHNF3YcHU5j+dTR0cXueoy2nEtYZLdkLJhoV6mBRaB+u5H7fMA QN9b421TySeCuPO312MBvXGs0BSLSaMuKcxHrH5nsqf/lw+NEVskH/Kwy/h7utSe2jpP rgBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=hxouzctdVKLUY5qMmszzgoevutuKxgtq/EJtw7lztnQ=; b=d57WsPrjWaXUbf19drZoxv4eVxtcccLZEa+yPPCt5xenezo6QopprUF9D1jUjSt+Xn bl1oZIYZ8c7IPUUWkAruUqQrGg20eXZq95IrSnwwfqSeiJybfofYSNIaCTGN72LRXSIY UkHDIWOe1LSIUABJr2v0cnXTbVyH/N1Kjqu5NMUApBhcLzldeDDTMDIe1NdMMHwk3D4V 9D6muZXj1cz22+Ha1sixYfV4Pb5R6CF9lVjeS338aRLxz77bF0jihwGSRa9zxBaTedw7 L1QDFzXnLnG3KCyvh6oRjhh+H+up+U2y2LFq4PrQ0comij6I0j3NYMjXkkWiCRgafy48 2qOw== X-Gm-Message-State: AKaTC01Vh/FacuP+J5U71lud2eMJ9Yn8URrqwUwsxAAdRVEuOVQKGMi13c+f5UUZP2RM+w== X-Received: by 10.46.71.140 with SMTP id u134mr628216lja.19.1479492708817; Fri, 18 Nov 2016 10:11:48 -0800 (PST) Received: from [192.168.1.44] (ppp109-252-90-55.pppoe.spdop.ru. [109.252.90.55]) by smtp.gmail.com with ESMTPSA id l135sm2532388lfe.10.2016.11.18.10.11.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Nov 2016 10:11:48 -0800 (PST) Subject: Re: [2.02][PATCH] bootp: export server IP as environment variable To: Daniel Kiper , phcoder@gmail.com, grub-devel@gnu.org References: <1458322920-5131-1-git-send-email-arvidjaar@gmail.com> <20161117190234.GA7245@router-fw-old.local.net-space.pl> Cc: nikunj@linux.vnet.ibm.com From: Andrei Borzenkov Message-ID: <8dcbe77f-6075-b4dc-933f-6b7a30be3742@gmail.com> Date: Fri, 18 Nov 2016 21:11:47 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161117190234.GA7245@router-fw-old.local.net-space.pl> Content-Type: multipart/mixed; boundary="------------602790DCA2DAC36541622333" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Nov 2016 18:11:58 -0000 This is a multi-part message in MIME format. --------------602790DCA2DAC36541622333 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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__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 >> 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. --------------602790DCA2DAC36541622333 Content-Type: text/x-patch; name="bootp-server-ip.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="bootp-server-ip.patch" From: Andrei Borzenkov 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__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 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{}_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{}_hostname:: * net_@var{}_ip:: * net_@var{}_mac:: +* net_@var{}_server_ip:: * net_@var{}_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{}_server_ip +@subsection net_@var{}_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) --------------602790DCA2DAC36541622333--