Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aTdAR-0003ka-Ml for mharc-grub-devel@gnu.org; Wed, 10 Feb 2016 17:23:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTdAO-0003jM-Oq for grub-devel@gnu.org; Wed, 10 Feb 2016 17:23:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTdAK-0004nt-NO for grub-devel@gnu.org; Wed, 10 Feb 2016 17:23:20 -0500 Received: from 66-220-144-178.intmgw.facebook.com ([66.220.144.178]:47615 helo=mx-out.facebook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTdAK-0004nn-HC for grub-devel@gnu.org; Wed, 10 Feb 2016 17:23:16 -0500 Received: from facebook.com (2401:db00:2040:5012:face:0:9:0) by mx-out.facebook.com (10.103.99.99) with ESMTP id 0c9d821cd03c11e5ab680002c9dfb610-786e3270 for ; Wed, 10 Feb 2016 13:20:03 -0800 Received: by devbig041.ash4.facebook.com (Postfix, from userid 8730) id 61B7D45406E2; Wed, 10 Feb 2016 13:21:10 -0800 (PST) From: Josef Bacik To: grub-devel@gnu.org, kernel-team@fb.com Subject: [PATCH 03/14] Use UEFI MAC device as default configured by net_bootp6 Date: Wed, 10 Feb 2016 13:20:57 -0800 Message-Id: <1455139268-3241273-4-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1455139268-3241273-1-git-send-email-jbacik@fb.com> References: <1455139268-3241273-1-git-send-email-jbacik@fb.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 66.220.144.178 Cc: Michael Chang 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: Wed, 10 Feb 2016 22:23:22 -0000 From: Michael Chang The grub_efinet_findcards will register cards by checking if it can support EFI Simple Netowork Protocol which create more than one device to a physical NIC device. If without specifying any device to be configured by net_bootp6, it should pick up one from them but not all. In my case three firmware device are listed. IPv4, IPv6 and MAC device. Both IPv4 and IPv6 are derived from MAC device for providing PXE Base Code Protocol. I think we should use MAC device instead of those two to avoid collision, because net_bootp6 command does not depend on PXE Base Code but only Simple Network Protocol to work --- grub-core/net/bootp.c | 8 ++++++++ grub-core/net/drivers/efi/efinet.c | 40 ++++++++++++++++++++++++++++++++++++++ include/grub/net.h | 1 + 3 files changed, 49 insertions(+) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c index 25ab70c..37d1cfa 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -1297,6 +1297,10 @@ grub_cmd_bootp6 (struct grub_command *cmd __attribute__ ((unused)), { if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) continue; +#ifdef GRUB_MACHINE_EFI + else if (!card->is_efi_mac_device (card)) + continue; +#endif ncards++; } @@ -1306,6 +1310,10 @@ grub_cmd_bootp6 (struct grub_command *cmd __attribute__ ((unused)), if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) continue; +#ifdef GRUB_MACHINE_EFI + else if (!card->is_efi_mac_device (card)) + continue; +#endif ifaces = grub_net_ipv6_get_link_local (card, &card->default_address); if (!ifaces) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c index 2b9a0e7..692d5ad 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -229,6 +229,45 @@ grub_efinet_get_device_handle (struct grub_net_card *card) return card->efi_handle; } +static int +grub_efinet_is_mac_device (struct grub_net_card *card) +{ + grub_efi_handle_t efi_handle; + grub_efi_device_path_t *dp; + grub_efi_device_path_t *next, *p; + grub_efi_uint8_t type; + grub_efi_uint8_t subtype; + + efi_handle = grub_efinet_get_device_handle (card); + + if (!efi_handle) + return 0; + + dp = grub_efi_get_device_path (efi_handle); + + if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) + return 0; + + for (p = (grub_efi_device_path_t *) dp, next = GRUB_EFI_NEXT_DEVICE_PATH (p); + ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (next); + p = next, next = GRUB_EFI_NEXT_DEVICE_PATH (next)) + ; + + if (p) + { + type = GRUB_EFI_DEVICE_PATH_TYPE (p); + subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (p); + + if (type == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE + && subtype == GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE) + { + return 1; + } + } + + return 0; +} + static void grub_efinet_findcards (void) { @@ -318,6 +357,7 @@ grub_efinet_findcards (void) sizeof (card->default_address.mac)); card->efi_net = net; card->efi_handle = *handle; + card->is_efi_mac_device = grub_efinet_is_mac_device; grub_net_card_register (card); } diff --git a/include/grub/net.h b/include/grub/net.h index 71dc243..4571b72 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -140,6 +140,7 @@ struct grub_net_card struct grub_efi_simple_network *efi_net; grub_efi_handle_t efi_handle; grub_size_t last_pkt_size; + int (*is_efi_mac_device) (struct grub_net_card* card); }; #endif void *data; -- 1.8.1