dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone
Blob Blame History Raw
From 25fdb7899c0f66ba4fddd8093df9c66a49dd2870 Mon Sep 17 00:00:00 2001
From: Michael Chang <mchang@suse.com>
Date: Wed, 15 Apr 2015 14:48:30 +0800
Subject: [PATCH 252/260] efinet: UEFI IPv6 PXE support

When grub2 image is booted from UEFI IPv6 PXE, the DHCPv6 Reply packet is
cached in firmware buffer which can be obtained by PXE Base Code protocol. The
network interface can be setup through the parameters in that obtained packet.

Signed-off-by: Michael Chang <mchang@suse.com>
Signed-off-by: Ken Lin <ken.lin@hpe.com>
---
 grub-core/net/drivers/efi/efinet.c | 23 +++++---------
 include/grub/efi/api.h             | 64 ++++++++++++++++++++++++--------------
 2 files changed, 48 insertions(+), 39 deletions(-)

diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
index b9ed13fca..c00ac2e64 100644
--- a/grub-core/net/drivers/efi/efinet.c
+++ b/grub-core/net/drivers/efi/efinet.c
@@ -404,26 +404,19 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
     pxe_mode = pxe->mode;
     if (pxe_mode->using_ipv6)
       {
-	grub_net_link_level_address_t hwaddr;
-	struct grub_net_network_level_interface *intf;
-
 	grub_dprintf ("efinet", "using ipv6 and dhcpv6\n");
 	grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n",
 		      pxe_mode->dhcp_ack_received ? "yes" : "no",
 		      pxe_mode->dhcp_ack_received ? "" : " cannot continue");
-	if (!pxe_mode->dhcp_ack_received)
-	  continue;
-
-	hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
-	grub_memcpy (hwaddr.mac,
-		     card->efi_net->mode->current_address,
-		     sizeof (hwaddr.mac));
-
-	intf = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr,
-	      (const struct grub_net_dhcpv6_packet *)&pxe_mode->dhcp_ack.dhcpv6,
-	      1, device, path);
-	if (intf && device && path)
+	grub_net_configure_by_dhcpv6_reply (card->name, card, 0,
+					    (struct grub_net_dhcp6_packet *)
+					    &pxe_mode->dhcp_ack,
+					    sizeof (pxe_mode->dhcp_ack),
+					    1, device, path);
+	if (device && path)
 	  grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path);
+	if (grub_errno)
+	  grub_print_error ();
       }
     else
       {
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
index 9422ba9a9..0821e3364 100644
--- a/include/grub/efi/api.h
+++ b/include/grub/efi/api.h
@@ -1446,29 +1446,42 @@ typedef union
   grub_efi_pxe_dhcpv6_packet_t dhcpv6;
 } grub_efi_pxe_packet_t;
 
-#define GRUB_EFI_PXE_MAX_IPCNT 8
-#define GRUB_EFI_PXE_MAX_ARP_ENTRIES 8
-#define GRUB_EFI_PXE_MAX_ROUTE_ENTRIES 8
 
-typedef struct grub_efi_pxe_ip_filter
-{
-  grub_efi_uint8_t filters;
-  grub_efi_uint8_t ip_count;
-  grub_efi_uint8_t reserved;
-  grub_efi_ip_address_t ip_list[GRUB_EFI_PXE_MAX_IPCNT];
+typedef struct {
+  grub_uint8_t addr[4];
+} grub_efi_pxe_ipv4_address_t;
+
+typedef struct {
+  grub_uint8_t addr[16];
+} grub_efi_pxe_ipv6_address_t;
+
+typedef struct {
+  grub_uint8_t addr[32];
+} grub_efi_pxe_mac_address_t;
+
+typedef union {
+    grub_uint32_t addr[4];
+    grub_efi_pxe_ipv4_address_t v4;
+    grub_efi_pxe_ipv6_address_t v6;
+} grub_efi_pxe_ip_address_t;
+
+#define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8
+typedef struct {
+    grub_uint8_t filters;
+    grub_uint8_t ip_cnt;
+    grub_uint16_t reserved;
+    grub_efi_pxe_ip_address_t ip_list[GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT];
 } grub_efi_pxe_ip_filter_t;
 
-typedef struct grub_efi_pxe_arp_entry
-{
-  grub_efi_ip_address_t ip_addr;
-  grub_efi_mac_address_t mac_addr;
+typedef struct {
+    grub_efi_pxe_ip_address_t ip_addr;
+    grub_efi_pxe_mac_address_t mac_addr;
 } grub_efi_pxe_arp_entry_t;
 
-typedef struct grub_efi_pxe_route_entry
-{
-  grub_efi_ip_address_t ip_addr;
-  grub_efi_ip_address_t subnet_mask;
-  grub_efi_ip_address_t gateway_addr;
+typedef struct {
+    grub_efi_pxe_ip_address_t ip_addr;
+    grub_efi_pxe_ip_address_t subnet_mask;
+    grub_efi_pxe_ip_address_t gw_addr;
 } grub_efi_pxe_route_entry_t;
 
 typedef struct grub_efi_pxe_icmp_error
@@ -1482,10 +1495,10 @@ typedef struct grub_efi_pxe_icmp_error
       grub_efi_uint32_t mtu;
       grub_efi_uint32_t pointer;
       struct
-	{
-	  grub_efi_uint16_t identifier;
-	  grub_efi_uint16_t sequence;
-	} echo;
+       {
+         grub_efi_uint16_t identifier;
+         grub_efi_uint16_t sequence;
+       } echo;
     } u;
   grub_efi_uint8_t data[494];
 } grub_efi_pxe_icmp_error_t;
@@ -1496,6 +1509,9 @@ typedef struct grub_efi_pxe_tftp_error
   grub_efi_char8_t error_string[127];
 } grub_efi_pxe_tftp_error_t;
 
+#define GRUB_EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES 8
+#define GRUB_EFI_PXE_BASE_CODE_MAX_ROUTE_ENTRIES 8
+
 typedef struct grub_efi_pxe_mode
 {
   grub_efi_boolean_t started;
@@ -1527,9 +1543,9 @@ typedef struct grub_efi_pxe_mode
   grub_efi_pxe_packet_t pxe_bis_reply;
   grub_efi_pxe_ip_filter_t ip_filter;
   grub_efi_uint32_t arp_cache_entries;
-  grub_efi_pxe_arp_entry_t arp_cache[GRUB_EFI_PXE_MAX_ARP_ENTRIES];
+  grub_efi_pxe_arp_entry_t arp_cache[GRUB_EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES];
   grub_efi_uint32_t route_table_entries;
-  grub_efi_pxe_route_entry_t route_table[GRUB_EFI_PXE_MAX_ROUTE_ENTRIES];
+  grub_efi_pxe_route_entry_t route_table[GRUB_EFI_PXE_BASE_CODE_MAX_ROUTE_ENTRIES];
   grub_efi_pxe_icmp_error_t icmp_error;
   grub_efi_pxe_tftp_error_t tftp_error;
 } grub_efi_pxe_mode_t;
-- 
2.13.0