Blame SOURCES/0252-efinet-UEFI-IPv6-PXE-support.patch

6b3c76
From 25fdb7899c0f66ba4fddd8093df9c66a49dd2870 Mon Sep 17 00:00:00 2001
a85e8e
From: Michael Chang <mchang@suse.com>
a85e8e
Date: Wed, 15 Apr 2015 14:48:30 +0800
6b3c76
Subject: [PATCH 252/261] efinet: UEFI IPv6 PXE support
a85e8e
a85e8e
When grub2 image is booted from UEFI IPv6 PXE, the DHCPv6 Reply packet is
a85e8e
cached in firmware buffer which can be obtained by PXE Base Code protocol. The
a85e8e
network interface can be setup through the parameters in that obtained packet.
a85e8e
a85e8e
Signed-off-by: Michael Chang <mchang@suse.com>
a85e8e
Signed-off-by: Ken Lin <ken.lin@hpe.com>
a85e8e
---
6b3c76
 grub-core/net/drivers/efi/efinet.c | 23 +++++---------
6b3c76
 include/grub/efi/api.h             | 64 ++++++++++++++++++++++++--------------
6b3c76
 2 files changed, 48 insertions(+), 39 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
6b3c76
index b9ed13fca..c00ac2e64 100644
a85e8e
--- a/grub-core/net/drivers/efi/efinet.c
a85e8e
+++ b/grub-core/net/drivers/efi/efinet.c
6b3c76
@@ -404,26 +404,19 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
a85e8e
     pxe_mode = pxe->mode;
a85e8e
     if (pxe_mode->using_ipv6)
a85e8e
       {
a85e8e
-	grub_net_link_level_address_t hwaddr;
a85e8e
-	struct grub_net_network_level_interface *intf;
a85e8e
-
a85e8e
 	grub_dprintf ("efinet", "using ipv6 and dhcpv6\n");
a85e8e
 	grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n",
a85e8e
 		      pxe_mode->dhcp_ack_received ? "yes" : "no",
6b3c76
 		      pxe_mode->dhcp_ack_received ? "" : " cannot continue");
6b3c76
-	if (!pxe_mode->dhcp_ack_received)
6b3c76
-	  continue;
6b3c76
-
a85e8e
-	hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
a85e8e
-	grub_memcpy (hwaddr.mac,
a85e8e
-		     card->efi_net->mode->current_address,
a85e8e
-		     sizeof (hwaddr.mac));
a85e8e
-
a85e8e
-	intf = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr,
a85e8e
-	      (const struct grub_net_dhcpv6_packet *)&pxe_mode->dhcp_ack.dhcpv6,
a85e8e
-	      1, device, path);
a85e8e
-	if (intf && device && path)
a85e8e
+	grub_net_configure_by_dhcpv6_reply (card->name, card, 0,
a85e8e
+					    (struct grub_net_dhcp6_packet *)
a85e8e
+					    &pxe_mode->dhcp_ack,
a85e8e
+					    sizeof (pxe_mode->dhcp_ack),
a85e8e
+					    1, device, path);
a85e8e
+	if (device && path)
a85e8e
 	  grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path);
a85e8e
+	if (grub_errno)
a85e8e
+	  grub_print_error ();
a85e8e
       }
a85e8e
     else
a85e8e
       {
a85e8e
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
6b3c76
index 9422ba9a9..0821e3364 100644
a85e8e
--- a/include/grub/efi/api.h
a85e8e
+++ b/include/grub/efi/api.h
6b3c76
@@ -1446,29 +1446,42 @@ typedef union
a85e8e
   grub_efi_pxe_dhcpv6_packet_t dhcpv6;
a85e8e
 } grub_efi_pxe_packet_t;
a85e8e
 
a85e8e
-#define GRUB_EFI_PXE_MAX_IPCNT 8
a85e8e
-#define GRUB_EFI_PXE_MAX_ARP_ENTRIES 8
a85e8e
-#define GRUB_EFI_PXE_MAX_ROUTE_ENTRIES 8
6b3c76
 
a85e8e
-typedef struct grub_efi_pxe_ip_filter
a85e8e
-{
a85e8e
-  grub_efi_uint8_t filters;
a85e8e
-  grub_efi_uint8_t ip_count;
a85e8e
-  grub_efi_uint8_t reserved;
a85e8e
-  grub_efi_ip_address_t ip_list[GRUB_EFI_PXE_MAX_IPCNT];
a85e8e
+typedef struct {
a85e8e
+  grub_uint8_t addr[4];
a85e8e
+} grub_efi_pxe_ipv4_address_t;
a85e8e
+
a85e8e
+typedef struct {
a85e8e
+  grub_uint8_t addr[16];
a85e8e
+} grub_efi_pxe_ipv6_address_t;
a85e8e
+
a85e8e
+typedef struct {
a85e8e
+  grub_uint8_t addr[32];
a85e8e
+} grub_efi_pxe_mac_address_t;
a85e8e
+
a85e8e
+typedef union {
6b3c76
+    grub_uint32_t addr[4];
6b3c76
+    grub_efi_pxe_ipv4_address_t v4;
6b3c76
+    grub_efi_pxe_ipv6_address_t v6;
a85e8e
+} grub_efi_pxe_ip_address_t;
a85e8e
+
a85e8e
+#define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8
a85e8e
+typedef struct {
6b3c76
+    grub_uint8_t filters;
6b3c76
+    grub_uint8_t ip_cnt;
6b3c76
+    grub_uint16_t reserved;
6b3c76
+    grub_efi_pxe_ip_address_t ip_list[GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT];
6b3c76
 } grub_efi_pxe_ip_filter_t;
6b3c76
 
6b3c76
-typedef struct grub_efi_pxe_arp_entry
6b3c76
-{
6b3c76
-  grub_efi_ip_address_t ip_addr;
6b3c76
-  grub_efi_mac_address_t mac_addr;
a85e8e
+typedef struct {
6b3c76
+    grub_efi_pxe_ip_address_t ip_addr;
6b3c76
+    grub_efi_pxe_mac_address_t mac_addr;
6b3c76
 } grub_efi_pxe_arp_entry_t;
6b3c76
 
6b3c76
-typedef struct grub_efi_pxe_route_entry
6b3c76
-{
6b3c76
-  grub_efi_ip_address_t ip_addr;
6b3c76
-  grub_efi_ip_address_t subnet_mask;
6b3c76
-  grub_efi_ip_address_t gateway_addr;
6b3c76
+typedef struct {
6b3c76
+    grub_efi_pxe_ip_address_t ip_addr;
6b3c76
+    grub_efi_pxe_ip_address_t subnet_mask;
6b3c76
+    grub_efi_pxe_ip_address_t gw_addr;
6b3c76
 } grub_efi_pxe_route_entry_t;
6b3c76
 
6b3c76
 typedef struct grub_efi_pxe_icmp_error
6b3c76
@@ -1482,10 +1495,10 @@ typedef struct grub_efi_pxe_icmp_error
6b3c76
       grub_efi_uint32_t mtu;
6b3c76
       grub_efi_uint32_t pointer;
6b3c76
       struct
6b3c76
-	{
6b3c76
-	  grub_efi_uint16_t identifier;
6b3c76
-	  grub_efi_uint16_t sequence;
6b3c76
-	} echo;
6b3c76
+       {
6b3c76
+         grub_efi_uint16_t identifier;
6b3c76
+         grub_efi_uint16_t sequence;
6b3c76
+       } echo;
6b3c76
     } u;
6b3c76
   grub_efi_uint8_t data[494];
6b3c76
 } grub_efi_pxe_icmp_error_t;
6b3c76
@@ -1496,6 +1509,9 @@ typedef struct grub_efi_pxe_tftp_error
6b3c76
   grub_efi_char8_t error_string[127];
6b3c76
 } grub_efi_pxe_tftp_error_t;
6b3c76
 
a85e8e
+#define GRUB_EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES 8
a85e8e
+#define GRUB_EFI_PXE_BASE_CODE_MAX_ROUTE_ENTRIES 8
a85e8e
+
a85e8e
 typedef struct grub_efi_pxe_mode
a85e8e
 {
a85e8e
   grub_efi_boolean_t started;
6b3c76
@@ -1527,9 +1543,9 @@ typedef struct grub_efi_pxe_mode
a85e8e
   grub_efi_pxe_packet_t pxe_bis_reply;
a85e8e
   grub_efi_pxe_ip_filter_t ip_filter;
a85e8e
   grub_efi_uint32_t arp_cache_entries;
a85e8e
-  grub_efi_pxe_arp_entry_t arp_cache[GRUB_EFI_PXE_MAX_ARP_ENTRIES];
a85e8e
+  grub_efi_pxe_arp_entry_t arp_cache[GRUB_EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES];
a85e8e
   grub_efi_uint32_t route_table_entries;
a85e8e
-  grub_efi_pxe_route_entry_t route_table[GRUB_EFI_PXE_MAX_ROUTE_ENTRIES];
a85e8e
+  grub_efi_pxe_route_entry_t route_table[GRUB_EFI_PXE_BASE_CODE_MAX_ROUTE_ENTRIES];
a85e8e
   grub_efi_pxe_icmp_error_t icmp_error;
a85e8e
   grub_efi_pxe_tftp_error_t tftp_error;
a85e8e
 } grub_efi_pxe_mode_t;
6b3c76
-- 
6b3c76
2.13.5
6b3c76