From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cKLcq-0000o9-JI for mharc-grub-devel@gnu.org; Fri, 23 Dec 2016 03:54:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cKLci-0000i0-8X for grub-devel@gnu.org; Fri, 23 Dec 2016 03:54:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cKLcf-0005W0-3s for grub-devel@gnu.org; Fri, 23 Dec 2016 03:54:44 -0500 Received: from g2t2353.austin.hpe.com ([15.233.44.26]:1596) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cKLce-0005Vm-U8 for grub-devel@gnu.org; Fri, 23 Dec 2016 03:54:41 -0500 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2353.austin.hpe.com (Postfix) with ESMTP id A406255; Fri, 23 Dec 2016 08:54:39 +0000 (UTC) Received: from hpe.com (hpe.asiapacific.hpqcorp.net [16.159.110.186]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id 2E7B53A; Fri, 23 Dec 2016 08:54:38 +0000 (UTC) From: Keng-Yu Lin To: grub-devel@gnu.org Cc: mchang@suse.com, ken.lin@hpe.com, ljk@hpe.com, michael.ruan@hpe.com, clayc@hpe.com, kengyu@hpe.com Subject: [PATCH 7/9] bootp: Add processing DHCPACK packet from HTTP Boot Date: Fri, 23 Dec 2016 16:54:10 +0800 Message-Id: <1482483252-8710-8-git-send-email-kengyu@hpe.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482483252-8710-1-git-send-email-kengyu@hpe.com> References: <1482483252-8710-1-git-send-email-kengyu@hpe.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 15.233.44.26 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, 23 Dec 2016 08:54:48 -0000 From: Michael Chang The vendor class identifier with the string "HTTPClient" is used to denote the packet as responding to HTTP boot request. In DHCP4 config, the filename for HTTP boot is the URL of the boot file while for PXE boot it is the path to the boot file. As a consequence, the next-server becomes obseleted because the HTTP URL already contains the server address for the boot file. For DHCP6 config, there's no difference definition in existing config as dhcp6.bootfile-url can be used to specify URL for both HTTP and PXE boot file. This patch adds processing for "HTTPClient" vendor class identifier in DHCPACK packet by treating it as HTTP format, not as the PXE format. Signed-off-by: Michael Chang Signed-off-by: Ken Lin --- grub-core/net/bootp.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++-- include/grub/net.h | 1 + 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c index 172528e..de9239c 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -207,6 +207,11 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) taglength); break; + case GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER: + grub_env_set_net_property (name, "vendor_class_identifier", (const char *) ptr, + taglength); + break; + case GRUB_NET_BOOTP_EXTENSIONS_PATH: grub_env_set_net_property (name, "extensionspath", (const char *) ptr, taglength); @@ -282,6 +287,66 @@ grub_net_configure_by_dhcp_ack (const char *name, } #endif + if (size > OFFSET_OF (vendor, bp)) + { + char *cidvar; + const char *cid; + + parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp), &mask); + cidvar = grub_xasprintf ("net_%s_%s", name, "vendor_class_identifier"); + cid = grub_env_get (cidvar); + grub_free (cidvar); + + if (cid && grub_strcmp (cid, "HTTPClient") == 0) + { + char *proto, *ip, *pa; + + if (!dissect_url (bp->boot_file, &proto, &ip, &pa)) + return inter; + + grub_env_set_net_property (name, "boot_file", pa, grub_strlen (pa)); + if (is_def) + { + grub_net_default_server = grub_strdup (ip); + grub_env_set ("net_default_interface", name); + grub_env_export ("net_default_interface"); + } + if (device && !*device) + { + *device = grub_xasprintf ("%s,%s", proto, ip); + grub_print_error (); + } + if (path) + { + *path = grub_strdup (pa); + grub_print_error (); + if (*path) + { + char *slash; + slash = grub_strrchr (*path, '/'); + if (slash) + *slash = 0; + else + **path = 0; + } + } + grub_net_add_ipv4_local (inter, mask); + inter->dhcp_ack = grub_malloc (size); + if (inter->dhcp_ack) + { + grub_memcpy (inter->dhcp_ack, bp, size); + inter->dhcp_acklen = size; + } + else + grub_errno = GRUB_ERR_NONE; + + grub_free (proto); + grub_free (ip); + grub_free (pa); + return inter; + } + } + if (size > OFFSET_OF (boot_file, bp)) grub_env_set_net_property (name, "boot_file", bp->boot_file, sizeof (bp->boot_file)); @@ -346,8 +411,6 @@ grub_net_configure_by_dhcp_ack (const char *name, **path = 0; } } - if (size > OFFSET_OF (vendor, bp)) - parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp), &mask); grub_net_add_ipv4_local (inter, mask); inter->dhcp_ack = grub_malloc (size); diff --git a/include/grub/net.h b/include/grub/net.h index 6133da5..67c801e 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -518,6 +518,7 @@ enum GRUB_NET_BOOTP_DOMAIN = 0x0f, GRUB_NET_BOOTP_ROOT_PATH = 0x11, GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12, + GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER = 0x3C, GRUB_NET_BOOTP_END = 0xff }; -- 2.7.4