From patchwork Fri Nov 18 18:11:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrei Borzenkov X-Patchwork-Id: 83015 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp226088qge; Fri, 18 Nov 2016 10:12:34 -0800 (PST) X-Received: by 10.200.53.239 with SMTP id l44mr894435qtb.60.1479492754523; Fri, 18 Nov 2016 10:12:34 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g18si2702547qtb.146.2016.11.18.10.12.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Nov 2016 10:12:34 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from localhost ([::1]:38305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7neM-0006DW-1l for patch@linaro.org; Fri, 18 Nov 2016 13:12:34 -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> 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> 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: , Reply-To: The development of GNU GRUB Cc: nikunj@linux.vnet.ibm.com Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" 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. _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel 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)