From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YiJPK-0002Mj-4K for mharc-grub-devel@gnu.org; Wed, 15 Apr 2015 05:14:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiJPH-0002G1-0D for grub-devel@gnu.org; Wed, 15 Apr 2015 05:14:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YiJPF-00048e-Vs for grub-devel@gnu.org; Wed, 15 Apr 2015 05:14:50 -0400 Received: from mail-qk0-x231.google.com ([2607:f8b0:400d:c09::231]:35175) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiJPF-00048U-Qk for grub-devel@gnu.org; Wed, 15 Apr 2015 05:14:49 -0400 Received: by qkhg7 with SMTP id g7so72097211qkh.2 for ; Wed, 15 Apr 2015 02:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=Zb8SQ84gDIOMkGUtKpupeAXmHOBWL9UM3/KwCPJWrMI=; b=KXVBOizUPY8Todf2u/ne+2QNe8sGYw16rip1yWxkKHs0o4WOsrA6c6Wt9BWzpb6AEY mYFz55hpvKTau+uzwBRI7OTuEplAewzlFKP52GGbgcEh7+WFdQixrjWb6JJ57/SFP1m6 ypJr5JchI6yZ4XyXlVG7B+QypJ850DgJP5wTvrsGAfYYU3qQ25MjEIAFURHufLCjf3gU 6Ojx/p+uOIUXU2616r5imifp9IwDZcUGvjILz84lZywpyqcYIKrfNlIWYaXbvkZEorgT 1wqbXG+NC3cDuhLolUhk/G5HxSQZA5wmtAD84mtlLGbjXS6c1/JyD7Yr3eUHnvAoVop/ Ghaw== X-Received: by 10.182.250.134 with SMTP id zc6mr20091295obc.78.1429089266974; Wed, 15 Apr 2015 02:14:26 -0700 (PDT) Received: from localhost.localdomain ([130.57.30.250]) by mx.google.com with ESMTPSA id os15sm2022411oeb.8.2015.04.15.02.14.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Apr 2015 02:14:26 -0700 (PDT) Sender: =?UTF-8?B?5by15paH6I+v?= From: Michael Chang To: grub-devel@gnu.org Subject: [PATCH 3/3] Use UEFI MAC device as default configured by net_bootp6 Date: Wed, 15 Apr 2015 17:05:09 +0800 Message-Id: <1429088709-924-4-git-send-email-mchang@suse.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1429088709-924-1-git-send-email-mchang@suse.com> References: <1429088709-924-1-git-send-email-mchang@suse.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c09::231 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, 15 Apr 2015 09:14:52 -0000 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(+), 0 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c index 477f205..c4963ca 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -1290,6 +1290,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++; } @@ -1299,6 +1303,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 b1837e3..900384f 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -157,6 +157,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) { @@ -223,6 +262,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.7.3.4