From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cVp66-0002di-EX for mharc-grub-devel@gnu.org; Mon, 23 Jan 2017 19:36:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51757) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVp63-0002cn-CM for grub-devel@gnu.org; Mon, 23 Jan 2017 19:36:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVp62-00010H-6C for grub-devel@gnu.org; Mon, 23 Jan 2017 19:36:27 -0500 Received: from cavan.codon.org.uk ([2a00:1098:0:80:1000:c:0:1]:56361) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cVp61-0000zs-Vy for grub-devel@gnu.org; Mon, 23 Jan 2017 19:36:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codon.org.uk; s=63138784; h=Subject:References:In-Reply-To:Message-Id:Date:Cc:To:From; bh=Oar/5GFmyLNB89nT6bhJ7Elzn/uifcL+x940kUBwI7A=; b=RdSRW10Ud8o36il2H3Bk3It2CZP2wHXCeN6KPKR/WU1tE1pL0wUlOBh4uzYgOaSdAngP+2BW41AcHmOQ/OvQr93s95o2OCqTB6f89wyEXQoYsW181MmTEJOx8nXzaytGpy7jUc0ORq4QjpBOkavHHWViMqu09rzc9W/jXggCH9c=; Received: from [2603:3024:1c06:3af3:3252:cbff:fee6:e579] (helo=xps13-mjg59.libcore.so) by cavan.codon.org.uk with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1cVp5w-0002Sb-9N; Tue, 24 Jan 2017 00:36:22 +0000 From: Matthew Garrett To: grub-devel@gnu.org Cc: Matthew Garrett Date: Mon, 23 Jan 2017 16:35:59 -0800 Message-Id: <20170124003601.24612-3-mjg59@coreos.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170124003601.24612-1-mjg59@coreos.com> References: <20170124003601.24612-1-mjg59@coreos.com> X-SA-Do-Not-Run: Yes X-SA-Exim-Connect-IP: 2603:3024:1c06:3af3:3252:cbff:fee6:e579 X-SA-Exim-Mail-From: mjg59@codon.org.uk Subject: [PATCH 2/4] Send a user class identifier in bootp requests and tag it as DHCP discover X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:54:46 +0000) X-SA-Exim-Scanned: Yes (on cavan.codon.org.uk) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a00:1098:0:80:1000:c:0:1 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: Tue, 24 Jan 2017 00:36:29 -0000 It's helpful to determine that a request was sent by grub in order to permit the server to provide different information at different stages of the boot process. Send GRUB2 as a type 77 DHCP option when sending bootp packets in order to make this possible and tag the request as a DHCP discover to convince servers to pay attention to it. Add the client architecture for good measure. --- grub-core/net/bootp.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c index 9e2fdb7..0da8e24 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -25,6 +25,24 @@ #include #include +#if !defined(GRUB_MACHINE_EFI) && (defined(__i386__) || defined(__x86_64__)) +#define GRUB_NET_BOOTP_ARCH 0x0000 +#elif defined(GRUB_MACHINE_EFI) && defined(__x86_64__) +#define GRUB_NET_BOOTP_ARCH 0x0007 +#elif defined(GRUB_MACHINE_EFI) && defined(__aarch64__) +#define GRUB_NET_BOOTP_ARCH 0x000B +#else +#error "unknown bootp architecture" +#endif + +static grub_uint8_t dhcp_option_header[] = {GRUB_NET_BOOTP_RFC1048_MAGIC_0, + GRUB_NET_BOOTP_RFC1048_MAGIC_1, + GRUB_NET_BOOTP_RFC1048_MAGIC_2, + GRUB_NET_BOOTP_RFC1048_MAGIC_3}; +static grub_uint8_t grub_userclass[] = {0x4D, 0x06, 0x05, 'G', 'R', 'U', 'B', '2'}; +static grub_uint8_t grub_dhcpdiscover[] = {0x35, 0x01, 0x01}; +static grub_uint8_t grub_dhcptime[] = {0x33, 0x04, 0x00, 0x00, 0x0e, 0x10}; + static void parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) { @@ -499,10 +517,14 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), struct udphdr *udph; grub_net_network_level_address_t target; grub_net_link_level_address_t ll_target; + grub_uint8_t *offset; if (!ifaces[j].prev) continue; - nb = grub_netbuff_alloc (sizeof (*pack) + 64 + 128); + nb = grub_netbuff_alloc (sizeof (*pack) + sizeof(dhcp_option_header) + + sizeof(grub_userclass) + + sizeof(grub_dhcpdiscover) + + sizeof(grub_dhcptime) + 64 + 128); if (!nb) { grub_netbuff_free (nb); @@ -536,6 +558,24 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), pack->seconds = grub_cpu_to_be16 (t); grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); + offset = (grub_uint8_t *)&pack->vendor; + grub_memcpy (offset, dhcp_option_header, sizeof(dhcp_option_header)); + offset += sizeof(dhcp_option_header); + grub_memcpy (offset, grub_dhcpdiscover, sizeof(grub_dhcpdiscover)); + offset += sizeof(grub_dhcpdiscover); + grub_memcpy (offset, grub_userclass, sizeof(grub_userclass)); + offset += sizeof(grub_userclass); + grub_memcpy (offset, grub_dhcptime, sizeof(grub_dhcptime)); + + /* insert Client System Architecture (option 93) */ + offset += sizeof(grub_dhcptime); + offset[0] = 93; + offset[1] = 2; + offset[2] = (GRUB_NET_BOOTP_ARCH >> 8); + offset[3] = (GRUB_NET_BOOTP_ARCH & 0xFF); + + /* option terminator */ + offset[4] = 255; grub_netbuff_push (nb, sizeof (*udph)); -- 2.9.3