From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1agyPf-00051Y-Io for mharc-grub-devel@gnu.org; Fri, 18 Mar 2016 13:42:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agyPc-00050J-Ut for grub-devel@gnu.org; Fri, 18 Mar 2016 13:42:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agyPZ-0004bO-E2 for grub-devel@gnu.org; Fri, 18 Mar 2016 13:42:12 -0400 Received: from mail-lb0-x22f.google.com ([2a00:1450:4010:c04::22f]:33242) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agyPZ-0004bH-5K for grub-devel@gnu.org; Fri, 18 Mar 2016 13:42:09 -0400 Received: by mail-lb0-x22f.google.com with SMTP id oe12so93217298lbc.0 for ; Fri, 18 Mar 2016 10:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=0Y3f8HeKU1a+T1lNpRnNjP4RMzWAJPceudH1BWDqZDo=; b=yVAMWVrmWwzFsb9YhO/A6VMG9DNnUHh+hq0inXytAM8N6MRkFEXpmWYGnDU94Zql6K rWJY9UVKIcRcOOK2uGngA66pPfNyM+Wqj7w0M+3mdpNbCz1DKuENiXCETS79bia3R35r kvLVDr7ExyzrmEl1+A2La409vC594PZHNNjnGhBUd2u1KZfKeus653XE5gVgn5kDmeiy 2rGhgBsy/uKPQLqmjNoo5uhzDRKtxJminNxOkFiVKecMXdl3Ww2bNAaImHkq5uW/YkJ1 tsfr/NxibA/6j9l6xkNsyuBFWVUCaBRsIcDB791tJqYN9emGCLygF6vwaJ7J7lQE1C0x iJgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0Y3f8HeKU1a+T1lNpRnNjP4RMzWAJPceudH1BWDqZDo=; b=S7KR2dpM2m8Enaa5KtV/8zkVEk9AYOFlWz33gHwe02pbyBrE/B7NISeD8lByj2uMSh rufBKvFzQ/FEELU8o9fIWvOue9rUwMsGm2O9cmpsSPANe0qfEzPogYEVty3XAF0cl1yz jwBPIo4caD868KcKJQ2m3pDQi63ERutKiQrB5sMWWzhhK7h2Usp1uCuHWnB5To1xDdfL 16UEUBPicw+JNDyXquBn3sH3EUU4rsBM6tYuzre6WnKY6egYrvvl+ncjn/x0xIyOJLGV Sus3QVTNHyHA3rZAINEKDdZGecugqLnLqq2XcF4w0yrjU4nah+mWc0mxAF/01s/IeBgM vqww== X-Gm-Message-State: AD7BkJJLu+Sht6JYiYIpqezs/zP59H6Y+RAWeEpNZZlpkjfZ16Ayfdm1VLurJMmMQspmxg== X-Received: by 10.112.144.226 with SMTP id sp2mr6374958lbb.70.1458322928204; Fri, 18 Mar 2016 10:42:08 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-76-159.pppoe.spdop.ru. [109.252.76.159]) by smtp.gmail.com with ESMTPSA id 40sm2347607lfp.41.2016.03.18.10.42.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Mar 2016 10:42:07 -0700 (PDT) From: Andrei Borzenkov To: grub-devel@gnu.org Subject: [2.02][PATCH] bootp: export server IP as environment variable Date: Fri, 18 Mar 2016 20:42:00 +0300 Message-Id: <1458322920-5131-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::22f Cc: nikunj@linux.vnet.ibm.com X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Mar 2016 17:42:13 -0000 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. 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)