All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fb.com>
To: grub-devel@gnu.org, kernel-team@fb.com
Cc: Michael Chang <mchang@suse.com>
Subject: [PATCH 03/14] Use UEFI MAC device as default configured by net_bootp6
Date: Wed, 10 Feb 2016 13:20:57 -0800	[thread overview]
Message-ID: <1455139268-3241273-4-git-send-email-jbacik@fb.com> (raw)
In-Reply-To: <1455139268-3241273-1-git-send-email-jbacik@fb.com>

From: Michael Chang <mchang@suse.com>

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



  parent reply	other threads:[~2016-02-10 22:23 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-10 21:20 [PATCH 00/14] Facebook's netbooting patches Josef Bacik
2016-02-10 21:20 ` [PATCH 01/14] Added net_bootp6 command Josef Bacik
2016-02-10 21:20 ` [PATCH 02/14] UEFI IPv6 PXE support Josef Bacik
2016-02-10 21:20 ` Josef Bacik [this message]
2016-02-10 21:20 ` [PATCH 04/14] tcp: add window scaling and RTTM support Josef Bacik
2016-02-10 21:20 ` [PATCH 05/14] net: don't free uninitialized sockets in dns Josef Bacik
2016-02-13 17:59   ` Andrei Borzenkov
2016-02-16 16:13     ` Josef Bacik
2016-02-10 21:21 ` [PATCH 06/14] net: fix ipv6 routing Josef Bacik
2016-02-25 19:39   ` Andrei Borzenkov
2016-02-10 21:21 ` [PATCH 07/14] efinet: retransmit if our device is busy Josef Bacik
2016-02-10 21:21 ` [PATCH 08/14] efinet: filter multicast traffic based on addresses Josef Bacik
2016-02-10 21:21 ` [PATCH 09/14] efinet: clear the txbuffer before modifying the receive filters Josef Bacik
2016-02-10 21:21 ` [PATCH 10/14] dns: poll card between each dns request Josef Bacik
2016-02-15  6:45   ` Andrei Borzenkov
2016-02-16 16:16     ` Josef Bacik
2016-02-23 22:02     ` Josef Bacik
2016-02-24  3:25       ` Andrei Borzenkov
2016-02-10 21:21 ` [PATCH 11/14] dns: reset data->naddresses for every packet we receive Josef Bacik
2016-02-13 16:05   ` Andrei Borzenkov
2016-02-16 16:18     ` Josef Bacik
2016-02-10 21:21 ` [PATCH 12/14] icmp6: use default interface as the route interface Josef Bacik
2016-02-10 21:21 ` [PATCH 13/14] bootp: don't add multiple interfaces for the same address Josef Bacik
2016-02-10 21:21 ` [PATCH 14/14] net: add interfaces when we open a card Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455139268-3241273-4-git-send-email-jbacik@fb.com \
    --to=jbacik@fb.com \
    --cc=grub-devel@gnu.org \
    --cc=kernel-team@fb.com \
    --cc=mchang@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.