From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cVuIw-0004Nw-4M for mharc-grub-devel@gnu.org; Tue, 24 Jan 2017 01:10:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVuIt-0004Nl-SB for grub-devel@gnu.org; Tue, 24 Jan 2017 01:10:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVuIs-0005Ay-4K for grub-devel@gnu.org; Tue, 24 Jan 2017 01:10:03 -0500 Received: from mail-qt0-x22f.google.com ([2607:f8b0:400d:c0d::22f]:34069) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cVuIr-0005Am-V7 for grub-devel@gnu.org; Tue, 24 Jan 2017 01:10:02 -0500 Received: by mail-qt0-x22f.google.com with SMTP id l7so165873183qtd.1 for ; Mon, 23 Jan 2017 22:10:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=coreos.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=O1aoM1crm7hxmTkY9lDNreAFiqxt7AgffqHveQYHJNs=; b=F04TsyZabi55Za4yB3h6hpbvrsgoT2PbxxE88V0BdaixIa5Zk1kPqRDa9Ry+R5CZNT YyNtRXpXO2KUcDaoQJj5Uq9TMMcoEV7HQu2/xiIiy8TtAarujha9GKDRIJ3h7qF9yY8l eVzsmG7OZ76xKCzLm+zNj0c/3V9H0JWOu4cas= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=O1aoM1crm7hxmTkY9lDNreAFiqxt7AgffqHveQYHJNs=; b=EgIH48mAg5EsDfJq+WwLa+o3eK1BWibdFJJapouTR5sqyuElzsrQIOsq6B1DlT1j1u 0blmwapcLAWMQfanFOZvMnxRCA2UZHn2Gk0NLBUrkdUCQ0qZR55rh5zNn9C1uSrHU4bQ FIOnwBm+02CzGe9UVn6ma86Ke5Gj0ZQ0TJl91x0OeR05x7js/zTinRheOF1w3SMJbpU4 QLC3iLxICPQ7xMXhqnjUt4baHIhvFOVo5Ntwm2rBS3sXTI+cer3TUiqllAkupR9LNOps 8ybVeZq9pEDRQf6XSmtuPVGUGH2Zn1tna74N4NhtvC3I+208kjR0+mBNno1ydQ8EUW5X ntgA== X-Gm-Message-State: AIkVDXLTz38AklJVqVomzb5Lt4dLWDIGmJjhpwLD4nKBOajKQH5zW3NS1FgNTVPbpM/hcSoS7v1/iJ4OP6wdsxay X-Received: by 10.55.159.206 with SMTP id i197mr26078742qke.175.1485238199603; Mon, 23 Jan 2017 22:09:59 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.30.71 with HTTP; Mon, 23 Jan 2017 22:09:58 -0800 (PST) In-Reply-To: <20170124003601.24612-3-mjg59@coreos.com> References: <20170124003601.24612-1-mjg59@coreos.com> <20170124003601.24612-3-mjg59@coreos.com> From: Michael Marineau Date: Mon, 23 Jan 2017 22:09:58 -0800 Message-ID: Subject: Re: [PATCH 2/4] Send a user class identifier in bootp requests and tag it as DHCP discover To: The development of GNU GRUB Cc: Matthew Garrett , Nick Owens Content-Type: text/plain; charset=UTF-8 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::22f 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 06:10:05 -0000 On Mon, Jan 23, 2017 at 4:35 PM, Matthew Garrett wrote: > 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 This list is woefully incomplete and there aren't even allocated values for every platform that grub supports so adding the architecture option will need to be optional. > + > +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); Increasing the allocation without also updating grub_netbuff_reserve and grub_netbuff_push calls doesn't actually influence the amount of space in the packet. grub_netbuff_alloc and grub_netbuff_reserve should be given the total size of the packet: ethernet+ip+udp+bootp while grub_netbuff_push is called for each of those layers. As-is this happens to work because the existing code included 64 bytes of zeros at the end of the bootp packet. The new options use 26 of those bytes. The extra 128 bytes of the reservation is for the lower protocol headers (ethernet+ip+udp). I don't now why the original code included 64 bytes of trailing zeros or allocates 128 for the lower protocols when only 42 will ever be used I don't know, that seems to be the state of the code on initial check-in to git. > 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 > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel