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