Blame SOURCES/0075-efinet-and-bootp-add-support-for-dhcpv6.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Peter Jones <pjones@redhat.com>
d9d99f
Date: Wed, 8 Jun 2016 21:03:37 -0400
d9d99f
Subject: [PATCH] efinet and bootp: add support for dhcpv6
d9d99f
d9d99f
Signed-off-by: Peter Jones <pjones@redhat.com>
d9d99f
---
d9d99f
 grub-core/net/bootp.c              | 174 +++++++++++++++++++++++++++++++++++++
d9d99f
 grub-core/net/drivers/efi/efinet.c |  53 +++++++++--
d9d99f
 grub-core/net/net.c                |  72 +++++++++++++++
d9d99f
 grub-core/net/tftp.c               |   4 +
d9d99f
 include/grub/efi/api.h             | 129 +++++++++++++++++++++++++--
d9d99f
 include/grub/net.h                 |  60 +++++++++++++
d9d99f
 6 files changed, 478 insertions(+), 14 deletions(-)
d9d99f
d9d99f
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
d9d99f
index f03eeab2fb4..da3e454466b 100644
d9d99f
--- a/grub-core/net/bootp.c
d9d99f
+++ b/grub-core/net/bootp.c
d9d99f
@@ -23,6 +23,7 @@
d9d99f
 #include <grub/net/ip.h>
d9d99f
 #include <grub/net/netbuff.h>
d9d99f
 #include <grub/net/udp.h>
d9d99f
+#include <grub/net/url.h>
d9d99f
 #include <grub/datetime.h>
d9d99f
 
d9d99f
 static char *
d9d99f
@@ -349,6 +350,179 @@ grub_net_configure_by_dhcp_ack (const char *name,
d9d99f
   return inter;
d9d99f
 }
d9d99f
 
d9d99f
+struct grub_net_network_level_interface *
d9d99f
+grub_net_configure_by_dhcpv6_ack (const char *name,
d9d99f
+				  struct grub_net_card *card,
d9d99f
+				  grub_net_interface_flags_t flags
d9d99f
+				    __attribute__((__unused__)),
d9d99f
+				  const grub_net_link_level_address_t *hwaddr,
d9d99f
+				  const struct grub_net_dhcpv6_packet *packet,
d9d99f
+				  int is_def, char **device, char **path)
d9d99f
+{
d9d99f
+  struct grub_net_network_level_interface *inter = NULL;
d9d99f
+  struct grub_net_network_level_address addr;
d9d99f
+  int mask = -1;
d9d99f
+
d9d99f
+  if (!device || !path)
d9d99f
+    return NULL;
d9d99f
+
d9d99f
+  *device = 0;
d9d99f
+  *path = 0;
d9d99f
+
d9d99f
+  grub_dprintf ("net", "mac address is %02x:%02x:%02x:%02x:%02x:%02x\n",
d9d99f
+		hwaddr->mac[0], hwaddr->mac[1], hwaddr->mac[2],
d9d99f
+		hwaddr->mac[3], hwaddr->mac[4], hwaddr->mac[5]);
d9d99f
+
d9d99f
+  if (is_def)
d9d99f
+    grub_net_default_server = 0;
d9d99f
+
d9d99f
+  if (is_def && !grub_net_default_server && packet)
d9d99f
+    {
d9d99f
+      const grub_uint8_t *options = packet->dhcp_options;
d9d99f
+      unsigned int option_max = 1024 - OFFSET_OF (dhcp_options, packet);
d9d99f
+      unsigned int i;
d9d99f
+
d9d99f
+      for (i = 0; i < option_max - sizeof (grub_net_dhcpv6_option_t); )
d9d99f
+	{
d9d99f
+	  grub_uint16_t num, len;
d9d99f
+	  grub_net_dhcpv6_option_t *opt =
d9d99f
+	    (grub_net_dhcpv6_option_t *)(options + i);
d9d99f
+
d9d99f
+	  num = grub_be_to_cpu16(opt->option_num);
d9d99f
+	  len = grub_be_to_cpu16(opt->option_len);
d9d99f
+
d9d99f
+	  grub_dprintf ("net", "got dhcpv6 option %d len %d\n", num, len);
d9d99f
+
d9d99f
+	  if (len == 0)
d9d99f
+	    break;
d9d99f
+
d9d99f
+	  if (len + i > 1024)
d9d99f
+	    break;
d9d99f
+
d9d99f
+	  if (num == GRUB_NET_DHCP6_BOOTFILE_URL)
d9d99f
+	    {
d9d99f
+	      char *scheme, *userinfo, *host, *file;
d9d99f
+	      char *tmp;
d9d99f
+	      int hostlen;
d9d99f
+	      int port;
d9d99f
+	      int rc = extract_url_info ((const char *)opt->option_data,
d9d99f
+					 (grub_size_t)len,
d9d99f
+					 &scheme, &userinfo, &host, &port,
d9d99f
+					 &file;;
d9d99f
+	      if (rc < 0)
d9d99f
+		continue;
d9d99f
+
d9d99f
+	      /* right now this only handles tftp. */
d9d99f
+	      if (grub_strcmp("tftp", scheme))
d9d99f
+		{
d9d99f
+		  grub_free (scheme);
d9d99f
+		  grub_free (userinfo);
d9d99f
+		  grub_free (host);
d9d99f
+		  grub_free (file);
d9d99f
+		  continue;
d9d99f
+		}
d9d99f
+	      grub_free (userinfo);
d9d99f
+
d9d99f
+	      hostlen = grub_strlen (host);
d9d99f
+	      if (hostlen > 2 && host[0] == '[' && host[hostlen-1] == ']')
d9d99f
+		{
d9d99f
+		  tmp = host+1;
d9d99f
+		  host[hostlen-1] = '\0';
d9d99f
+		}
d9d99f
+	      else
d9d99f
+		tmp = host;
d9d99f
+
d9d99f
+	      *device = grub_xasprintf ("%s,%s", scheme, tmp);
d9d99f
+	      grub_free (scheme);
d9d99f
+	      grub_free (host);
d9d99f
+
d9d99f
+	      if (file && *file)
d9d99f
+		{
d9d99f
+		  tmp = grub_strrchr (file, '/');
d9d99f
+		  if (tmp)
d9d99f
+		    *(tmp+1) = '\0';
d9d99f
+		  else
d9d99f
+		    file[0] = '\0';
d9d99f
+		}
d9d99f
+	      else if (!file)
d9d99f
+		file = grub_strdup ("");
d9d99f
+
d9d99f
+	      if (file[0] == '/')
d9d99f
+		{
d9d99f
+		  *path = grub_strdup (file+1);
d9d99f
+		  grub_free (file);
d9d99f
+		}
d9d99f
+	      else
d9d99f
+		*path = file;
d9d99f
+	    }
d9d99f
+	  else if (num == GRUB_NET_DHCP6_IA_NA)
d9d99f
+	    {
d9d99f
+	      const grub_net_dhcpv6_option_t *ia_na_opt;
d9d99f
+	      const grub_net_dhcpv6_opt_ia_na_t *ia_na =
d9d99f
+		(const grub_net_dhcpv6_opt_ia_na_t *)opt;
d9d99f
+	      unsigned int left = len - OFFSET_OF (options, ia_na);
d9d99f
+	      unsigned int j;
d9d99f
+
d9d99f
+	      if ((grub_uint8_t *)ia_na + left >
d9d99f
+		  (grub_uint8_t *)options + option_max)
d9d99f
+		left -= ((grub_uint8_t *)ia_na + left)
d9d99f
+		        - ((grub_uint8_t *)options + option_max);
d9d99f
+
d9d99f
+	      if (len < OFFSET_OF (option_data, opt)
d9d99f
+			+ sizeof (grub_net_dhcpv6_option_t))
d9d99f
+		{
d9d99f
+		  grub_dprintf ("net",
d9d99f
+				"found dhcpv6 ia_na option with no address\n");
d9d99f
+		  continue;
d9d99f
+		}
d9d99f
+
d9d99f
+	      for (j = 0; left > sizeof (grub_net_dhcpv6_option_t); )
d9d99f
+		{
d9d99f
+		  ia_na_opt = (const grub_net_dhcpv6_option_t *)
d9d99f
+			       (ia_na->options + j);
d9d99f
+		  grub_uint16_t ia_na_opt_num, ia_na_opt_len;
d9d99f
+
d9d99f
+		  ia_na_opt_num = grub_be_to_cpu16 (ia_na_opt->option_num);
d9d99f
+		  ia_na_opt_len = grub_be_to_cpu16 (ia_na_opt->option_len);
d9d99f
+		  if (ia_na_opt_len == 0)
d9d99f
+		    break;
d9d99f
+		  if (j + ia_na_opt_len > left)
d9d99f
+		    break;
d9d99f
+		  if (ia_na_opt_num == GRUB_NET_DHCP6_IA_ADDRESS)
d9d99f
+		    {
d9d99f
+		      const grub_net_dhcpv6_opt_ia_address_t *ia_addr;
d9d99f
+
d9d99f
+		      ia_addr = (const grub_net_dhcpv6_opt_ia_address_t *)
d9d99f
+				 ia_na_opt;
d9d99f
+		      addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
d9d99f
+		      grub_memcpy(addr.ipv6, ia_addr->ipv6_address,
d9d99f
+				  sizeof (ia_addr->ipv6_address));
d9d99f
+		      inter = grub_net_add_addr (name, card, &addr, hwaddr, 0);
d9d99f
+		    }
d9d99f
+
d9d99f
+		  j += ia_na_opt_len;
d9d99f
+		  left -= ia_na_opt_len;
d9d99f
+		}
d9d99f
+	    }
d9d99f
+
d9d99f
+	  i += len + 4;
d9d99f
+	}
d9d99f
+
d9d99f
+      grub_print_error ();
d9d99f
+    }
d9d99f
+
d9d99f
+  if (is_def)
d9d99f
+    {
d9d99f
+      grub_env_set ("net_default_interface", name);
d9d99f
+      grub_env_export ("net_default_interface");
d9d99f
+    }
d9d99f
+
d9d99f
+    if (inter)
d9d99f
+      grub_net_add_ipv6_local (inter, mask);
d9d99f
+    return inter;
d9d99f
+}
d9d99f
+
d9d99f
+
d9d99f
 void
d9d99f
 grub_net_process_dhcp (struct grub_net_buff *nb,
d9d99f
 		       struct grub_net_card *card)
d9d99f
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
d9d99f
index 5388f952ba9..a4daaa460bd 100644
d9d99f
--- a/grub-core/net/drivers/efi/efinet.c
d9d99f
+++ b/grub-core/net/drivers/efi/efinet.c
d9d99f
@@ -18,11 +18,15 @@
d9d99f
 
d9d99f
 #include <grub/net/netbuff.h>
d9d99f
 #include <grub/dl.h>
d9d99f
+#include <grub/env.h>
d9d99f
 #include <grub/net.h>
d9d99f
+#include <grub/net/url.h>
d9d99f
 #include <grub/time.h>
d9d99f
 #include <grub/efi/api.h>
d9d99f
 #include <grub/efi/efi.h>
d9d99f
 #include <grub/i18n.h>
d9d99f
+#include <grub/lib/hexdump.h>
d9d99f
+#include <grub/types.h>
d9d99f
 
d9d99f
 GRUB_MOD_LICENSE ("GPLv3+");
d9d99f
 
d9d99f
@@ -329,7 +333,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
d9d99f
 			  char **path)
d9d99f
 {
d9d99f
   struct grub_net_card *card;
d9d99f
-  grub_efi_device_path_t *dp;
d9d99f
+  grub_efi_device_path_t *dp, *ldp = NULL;
d9d99f
 
d9d99f
   dp = grub_efi_get_device_path (hnd);
d9d99f
   if (! dp)
d9d99f
@@ -340,14 +344,18 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
d9d99f
     grub_efi_device_path_t *cdp;
d9d99f
     struct grub_efi_pxe *pxe;
d9d99f
     struct grub_efi_pxe_mode *pxe_mode;
d9d99f
+
d9d99f
     if (card->driver != &efidriver)
d9d99f
       continue;
d9d99f
     cdp = grub_efi_get_device_path (card->efi_handle);
d9d99f
     if (! cdp)
d9d99f
       continue;
d9d99f
+
d9d99f
+    ldp = grub_efi_find_last_device_path (dp);
d9d99f
+
d9d99f
     if (grub_efi_compare_device_paths (dp, cdp) != 0)
d9d99f
       {
d9d99f
-	grub_efi_device_path_t *ldp, *dup_dp, *dup_ldp;
d9d99f
+	grub_efi_device_path_t *dup_dp, *dup_ldp;
d9d99f
 	int match;
d9d99f
 
d9d99f
 	/* EDK2 UEFI PXE driver creates pseudo devices with type IPv4/IPv6
d9d99f
@@ -356,7 +364,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
d9d99f
 	   devices. We skip them when enumerating cards, so here we need to
d9d99f
 	   find matching MAC device.
d9d99f
          */
d9d99f
-	ldp = grub_efi_find_last_device_path (dp);
d9d99f
 	if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE
d9d99f
 	    || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE
d9d99f
 		&& GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE))
d9d99f
@@ -373,16 +380,46 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
d9d99f
 	if (!match)
d9d99f
 	  continue;
d9d99f
       }
d9d99f
+
d9d99f
     pxe = grub_efi_open_protocol (hnd, &pxe_io_guid,
d9d99f
 				  GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
d9d99f
     if (! pxe)
d9d99f
       continue;
d9d99f
+
d9d99f
     pxe_mode = pxe->mode;
d9d99f
-    grub_net_configure_by_dhcp_ack (card->name, card, 0,
d9d99f
-				    (struct grub_net_bootp_packet *)
d9d99f
-				    &pxe_mode->dhcp_ack,
d9d99f
-				    sizeof (pxe_mode->dhcp_ack),
d9d99f
-				    1, device, path);
d9d99f
+    if (pxe_mode->using_ipv6)
d9d99f
+      {
d9d99f
+	grub_net_link_level_address_t hwaddr;
d9d99f
+	struct grub_net_network_level_interface *intf;
d9d99f
+
d9d99f
+	grub_dprintf ("efinet", "using ipv6 and dhcpv6\n");
d9d99f
+	grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n",
d9d99f
+		      pxe_mode->dhcp_ack_received ? "yes" : "no",
d9d99f
+		      pxe_mode->dhcp_ack_received ? "" : " cannot continue");
d9d99f
+	if (!pxe_mode->dhcp_ack_received)
d9d99f
+	  continue;
d9d99f
+
d9d99f
+	hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
d9d99f
+	grub_memcpy (hwaddr.mac,
d9d99f
+		     card->efi_net->mode->current_address,
d9d99f
+		     sizeof (hwaddr.mac));
d9d99f
+
d9d99f
+	intf = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr,
d9d99f
+	      (const struct grub_net_dhcpv6_packet *)&pxe_mode->dhcp_ack.dhcpv6,
d9d99f
+	      1, device, path);
d9d99f
+	if (intf && device && path)
d9d99f
+	  grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path);
d9d99f
+      }
d9d99f
+    else
d9d99f
+      {
d9d99f
+	grub_dprintf ("efinet", "using ipv4 and dhcp\n");
d9d99f
+	grub_net_configure_by_dhcp_ack (card->name, card, 0,
d9d99f
+					(struct grub_net_bootp_packet *)
d9d99f
+					&pxe_mode->dhcp_ack,
d9d99f
+					sizeof (pxe_mode->dhcp_ack),
d9d99f
+					1, device, path);
d9d99f
+	grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path);
d9d99f
+      }
d9d99f
     return;
d9d99f
   }
d9d99f
 }
d9d99f
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
d9d99f
index 16d2ce06d5a..4be228d9576 100644
d9d99f
--- a/grub-core/net/net.c
d9d99f
+++ b/grub-core/net/net.c
d9d99f
@@ -955,6 +955,78 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa
d9d99f
   grub_net_network_level_interfaces = inter;
d9d99f
 }
d9d99f
 
d9d99f
+int
d9d99f
+grub_ipv6_get_masksize (grub_uint16_t be_mask[8])
d9d99f
+{
d9d99f
+  grub_uint8_t *mask;
d9d99f
+  grub_uint16_t mask16[8];
d9d99f
+  int x, y;
d9d99f
+  int ret = 128;
d9d99f
+
d9d99f
+  grub_memcpy (mask16, be_mask, sizeof (mask16));
d9d99f
+  for (x = 0; x < 8; x++)
d9d99f
+    mask16[x] = grub_be_to_cpu16 (mask16[x]);
d9d99f
+
d9d99f
+  mask = (grub_uint8_t *)mask16;
d9d99f
+
d9d99f
+  for (x = 15; x >= 0; x--)
d9d99f
+    {
d9d99f
+      grub_uint8_t octet = mask[x];
d9d99f
+      if (!octet)
d9d99f
+	{
d9d99f
+	  ret -= 8;
d9d99f
+	  continue;
d9d99f
+	}
d9d99f
+      for (y = 0; y < 8; y++)
d9d99f
+	{
d9d99f
+	  if (octet & (1 << y))
d9d99f
+	    break;
d9d99f
+	  else
d9d99f
+	    ret--;
d9d99f
+	}
d9d99f
+      break;
d9d99f
+    }
d9d99f
+
d9d99f
+  return ret;
d9d99f
+}
d9d99f
+
d9d99f
+grub_err_t
d9d99f
+grub_net_add_ipv6_local (struct grub_net_network_level_interface *inter,
d9d99f
+			 int mask)
d9d99f
+{
d9d99f
+  struct grub_net_route *route;
d9d99f
+
d9d99f
+  if (inter->address.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6)
d9d99f
+    return 0;
d9d99f
+
d9d99f
+  if (mask == -1)
d9d99f
+      mask = grub_ipv6_get_masksize ((grub_uint16_t *)inter->address.ipv6);
d9d99f
+
d9d99f
+  if (mask == -1)
d9d99f
+    return 0;
d9d99f
+
d9d99f
+  route = grub_zalloc (sizeof (*route));
d9d99f
+  if (!route)
d9d99f
+    return grub_errno;
d9d99f
+
d9d99f
+  route->name = grub_xasprintf ("%s:local", inter->name);
d9d99f
+  if (!route->name)
d9d99f
+    {
d9d99f
+      grub_free (route);
d9d99f
+      return grub_errno;
d9d99f
+    }
d9d99f
+
d9d99f
+  route->target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
d9d99f
+  grub_memcpy (route->target.ipv6.base, inter->address.ipv6,
d9d99f
+	       sizeof (inter->address.ipv6));
d9d99f
+  route->target.ipv6.masksize = mask;
d9d99f
+  route->is_gateway = 0;
d9d99f
+  route->interface = inter;
d9d99f
+
d9d99f
+  grub_net_route_register (route);
d9d99f
+
d9d99f
+  return 0;
d9d99f
+}
d9d99f
 
d9d99f
 grub_err_t
d9d99f
 grub_net_add_ipv4_local (struct grub_net_network_level_interface *inter,
d9d99f
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
d9d99f
index 7d90bf66e76..1157524fc50 100644
d9d99f
--- a/grub-core/net/tftp.c
d9d99f
+++ b/grub-core/net/tftp.c
d9d99f
@@ -379,19 +379,23 @@ tftp_open (struct grub_file *file, const char *filename)
d9d99f
       return grub_errno;
d9d99f
     }
d9d99f
 
d9d99f
+  grub_dprintf("tftp", "resolving address for %s\n", file->device->net->server);
d9d99f
   err = grub_net_resolve_address (file->device->net->server, &addr);
d9d99f
   if (err)
d9d99f
     {
d9d99f
+      grub_dprintf("tftp", "Address resolution failed: %d\n", err);
d9d99f
       destroy_pq (data);
d9d99f
       grub_free (data);
d9d99f
       return err;
d9d99f
     }
d9d99f
 
d9d99f
+  grub_dprintf("tftp", "opening connection\n");
d9d99f
   data->sock = grub_net_udp_open (addr,
d9d99f
 				  TFTP_SERVER_PORT, tftp_receive,
d9d99f
 				  file);
d9d99f
   if (!data->sock)
d9d99f
     {
d9d99f
+      grub_dprintf("tftp", "connection failed\n");
d9d99f
       destroy_pq (data);
d9d99f
       grub_free (data);
d9d99f
       return grub_errno;
d9d99f
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
d9d99f
index c7c9f0e1db1..28b6adf7648 100644
d9d99f
--- a/include/grub/efi/api.h
d9d99f
+++ b/include/grub/efi/api.h
d9d99f
@@ -572,10 +572,16 @@ typedef void *grub_efi_handle_t;
d9d99f
 typedef void *grub_efi_event_t;
d9d99f
 typedef grub_efi_uint64_t grub_efi_lba_t;
d9d99f
 typedef grub_efi_uintn_t grub_efi_tpl_t;
d9d99f
-typedef grub_uint8_t grub_efi_mac_address_t[32];
d9d99f
-typedef grub_uint8_t grub_efi_ipv4_address_t[4];
d9d99f
-typedef grub_uint16_t grub_efi_ipv6_address_t[8];
d9d99f
-typedef grub_uint8_t grub_efi_ip_address_t[8] __attribute__ ((aligned(4)));
d9d99f
+typedef grub_efi_uint8_t grub_efi_mac_address_t[32];
d9d99f
+typedef grub_efi_uint8_t grub_efi_ipv4_address_t[4];
d9d99f
+typedef grub_efi_uint8_t grub_efi_ipv6_address_t[16];
d9d99f
+typedef union
d9d99f
+{
d9d99f
+  grub_efi_uint32_t addr[4];
d9d99f
+  grub_efi_ipv4_address_t v4;
d9d99f
+  grub_efi_ipv6_address_t v6;
d9d99f
+} grub_efi_ip_address_t __attribute__ ((aligned(4)));
d9d99f
+
d9d99f
 typedef grub_efi_uint64_t grub_efi_physical_address_t;
d9d99f
 typedef grub_efi_uint64_t grub_efi_virtual_address_t;
d9d99f
 
d9d99f
@@ -1450,16 +1456,127 @@ struct grub_efi_simple_text_output_interface
d9d99f
 };
d9d99f
 typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output_interface_t;
d9d99f
 
d9d99f
-typedef grub_uint8_t grub_efi_pxe_packet_t[1472];
d9d99f
+typedef struct grub_efi_pxe_dhcpv4_packet
d9d99f
+{
d9d99f
+  grub_efi_uint8_t bootp_opcode;
d9d99f
+  grub_efi_uint8_t bootp_hwtype;
d9d99f
+  grub_efi_uint8_t bootp_hwaddr_len;
d9d99f
+  grub_efi_uint8_t bootp_gate_hops;
d9d99f
+  grub_efi_uint32_t bootp_ident;
d9d99f
+  grub_efi_uint16_t bootp_seconds;
d9d99f
+  grub_efi_uint16_t bootp_flags;
d9d99f
+  grub_efi_uint8_t bootp_ci_addr[4];
d9d99f
+  grub_efi_uint8_t bootp_yi_addr[4];
d9d99f
+  grub_efi_uint8_t bootp_si_addr[4];
d9d99f
+  grub_efi_uint8_t bootp_gi_addr[4];
d9d99f
+  grub_efi_uint8_t bootp_hw_addr[16];
d9d99f
+  grub_efi_uint8_t bootp_srv_name[64];
d9d99f
+  grub_efi_uint8_t bootp_boot_file[128];
d9d99f
+  grub_efi_uint32_t dhcp_magik;
d9d99f
+  grub_efi_uint8_t dhcp_options[56];
d9d99f
+} grub_efi_pxe_dhcpv4_packet_t;
d9d99f
+
d9d99f
+struct grub_efi_pxe_dhcpv6_packet
d9d99f
+{
d9d99f
+  grub_efi_uint32_t message_type:8;
d9d99f
+  grub_efi_uint32_t transaction_id:24;
d9d99f
+  grub_efi_uint8_t dhcp_options[1024];
d9d99f
+} GRUB_PACKED;
d9d99f
+typedef struct grub_efi_pxe_dhcpv6_packet grub_efi_pxe_dhcpv6_packet_t;
d9d99f
+
d9d99f
+typedef union
d9d99f
+{
d9d99f
+  grub_efi_uint8_t raw[1472];
d9d99f
+  grub_efi_pxe_dhcpv4_packet_t dhcpv4;
d9d99f
+  grub_efi_pxe_dhcpv6_packet_t dhcpv6;
d9d99f
+} grub_efi_pxe_packet_t;
d9d99f
+
d9d99f
+#define GRUB_EFI_PXE_MAX_IPCNT 8
d9d99f
+#define GRUB_EFI_PXE_MAX_ARP_ENTRIES 8
d9d99f
+#define GRUB_EFI_PXE_MAX_ROUTE_ENTRIES 8
d9d99f
+
d9d99f
+typedef struct grub_efi_pxe_ip_filter
d9d99f
+{
d9d99f
+  grub_efi_uint8_t filters;
d9d99f
+  grub_efi_uint8_t ip_count;
d9d99f
+  grub_efi_uint8_t reserved;
d9d99f
+  grub_efi_ip_address_t ip_list[GRUB_EFI_PXE_MAX_IPCNT];
d9d99f
+} grub_efi_pxe_ip_filter_t;
d9d99f
+
d9d99f
+typedef struct grub_efi_pxe_arp_entry
d9d99f
+{
d9d99f
+  grub_efi_ip_address_t ip_addr;
d9d99f
+  grub_efi_mac_address_t mac_addr;
d9d99f
+} grub_efi_pxe_arp_entry_t;
d9d99f
+
d9d99f
+typedef struct grub_efi_pxe_route_entry
d9d99f
+{
d9d99f
+  grub_efi_ip_address_t ip_addr;
d9d99f
+  grub_efi_ip_address_t subnet_mask;
d9d99f
+  grub_efi_ip_address_t gateway_addr;
d9d99f
+} grub_efi_pxe_route_entry_t;
d9d99f
+
d9d99f
+typedef struct grub_efi_pxe_icmp_error
d9d99f
+{
d9d99f
+  grub_efi_uint8_t type;
d9d99f
+  grub_efi_uint8_t code;
d9d99f
+  grub_efi_uint16_t checksum;
d9d99f
+  union
d9d99f
+    {
d9d99f
+      grub_efi_uint32_t reserved;
d9d99f
+      grub_efi_uint32_t mtu;
d9d99f
+      grub_efi_uint32_t pointer;
d9d99f
+      struct
d9d99f
+	{
d9d99f
+	  grub_efi_uint16_t identifier;
d9d99f
+	  grub_efi_uint16_t sequence;
d9d99f
+	} echo;
d9d99f
+    } u;
d9d99f
+  grub_efi_uint8_t data[494];
d9d99f
+} grub_efi_pxe_icmp_error_t;
d9d99f
+
d9d99f
+typedef struct grub_efi_pxe_tftp_error
d9d99f
+{
d9d99f
+  grub_efi_uint8_t error_code;
d9d99f
+  grub_efi_char8_t error_string[127];
d9d99f
+} grub_efi_pxe_tftp_error_t;
d9d99f
 
d9d99f
 typedef struct grub_efi_pxe_mode
d9d99f
 {
d9d99f
-  grub_uint8_t unused[52];
d9d99f
+  grub_efi_boolean_t started;
d9d99f
+  grub_efi_boolean_t ipv6_available;
d9d99f
+  grub_efi_boolean_t ipv6_supported;
d9d99f
+  grub_efi_boolean_t using_ipv6;
d9d99f
+  grub_efi_boolean_t bis_supported;
d9d99f
+  grub_efi_boolean_t bis_detected;
d9d99f
+  grub_efi_boolean_t auto_arp;
d9d99f
+  grub_efi_boolean_t send_guid;
d9d99f
+  grub_efi_boolean_t dhcp_discover_valid;
d9d99f
+  grub_efi_boolean_t dhcp_ack_received;
d9d99f
+  grub_efi_boolean_t proxy_offer_received;
d9d99f
+  grub_efi_boolean_t pxe_discover_valid;
d9d99f
+  grub_efi_boolean_t pxe_reply_received;
d9d99f
+  grub_efi_boolean_t pxe_bis_reply_received;
d9d99f
+  grub_efi_boolean_t icmp_error_received;
d9d99f
+  grub_efi_boolean_t tftp_error_received;
d9d99f
+  grub_efi_boolean_t make_callbacks;
d9d99f
+  grub_efi_uint8_t ttl;
d9d99f
+  grub_efi_uint8_t tos;
d9d99f
+  grub_efi_ip_address_t station_ip;
d9d99f
+  grub_efi_ip_address_t subnet_mask;
d9d99f
   grub_efi_pxe_packet_t dhcp_discover;
d9d99f
   grub_efi_pxe_packet_t dhcp_ack;
d9d99f
   grub_efi_pxe_packet_t proxy_offer;
d9d99f
   grub_efi_pxe_packet_t pxe_discover;
d9d99f
   grub_efi_pxe_packet_t pxe_reply;
d9d99f
+  grub_efi_pxe_packet_t pxe_bis_reply;
d9d99f
+  grub_efi_pxe_ip_filter_t ip_filter;
d9d99f
+  grub_efi_uint32_t arp_cache_entries;
d9d99f
+  grub_efi_pxe_arp_entry_t arp_cache[GRUB_EFI_PXE_MAX_ARP_ENTRIES];
d9d99f
+  grub_efi_uint32_t route_table_entries;
d9d99f
+  grub_efi_pxe_route_entry_t route_table[GRUB_EFI_PXE_MAX_ROUTE_ENTRIES];
d9d99f
+  grub_efi_pxe_icmp_error_t icmp_error;
d9d99f
+  grub_efi_pxe_tftp_error_t tftp_error;
d9d99f
 } grub_efi_pxe_mode_t;
d9d99f
 
d9d99f
 typedef struct grub_efi_pxe
d9d99f
diff --git a/include/grub/net.h b/include/grub/net.h
d9d99f
index 50d62ab0c8c..f8f3ec13acc 100644
d9d99f
--- a/include/grub/net.h
d9d99f
+++ b/include/grub/net.h
d9d99f
@@ -442,6 +442,51 @@ struct grub_net_bootp_packet
d9d99f
   grub_uint8_t vendor[0];
d9d99f
 } GRUB_PACKED;
d9d99f
 
d9d99f
+enum
d9d99f
+  {
d9d99f
+    GRUB_NET_DHCP6_IA_NA = 3,
d9d99f
+    GRUB_NET_DHCP6_IA_ADDRESS = 5,
d9d99f
+    GRUB_NET_DHCP6_BOOTFILE_URL = 59,
d9d99f
+  };
d9d99f
+
d9d99f
+struct grub_net_dhcpv6_option
d9d99f
+{
d9d99f
+  grub_uint16_t option_num;
d9d99f
+  grub_uint16_t option_len;
d9d99f
+  grub_uint8_t option_data[];
d9d99f
+} GRUB_PACKED;
d9d99f
+typedef struct grub_net_dhcpv6_option grub_net_dhcpv6_option_t;
d9d99f
+
d9d99f
+struct grub_net_dhcpv6_opt_ia_na
d9d99f
+{
d9d99f
+  grub_uint16_t option_num;
d9d99f
+  grub_uint16_t option_len;
d9d99f
+  grub_uint32_t iaid;
d9d99f
+  grub_uint32_t t1;
d9d99f
+  grub_uint32_t t2;
d9d99f
+  grub_uint8_t options[];
d9d99f
+} GRUB_PACKED;
d9d99f
+typedef struct grub_net_dhcpv6_opt_ia_na grub_net_dhcpv6_opt_ia_na_t;
d9d99f
+
d9d99f
+struct grub_net_dhcpv6_opt_ia_address
d9d99f
+{
d9d99f
+  grub_uint16_t option_num;
d9d99f
+  grub_uint16_t option_len;
d9d99f
+  grub_uint64_t ipv6_address[2];
d9d99f
+  grub_uint32_t preferred_lifetime;
d9d99f
+  grub_uint32_t valid_lifetime;
d9d99f
+  grub_uint8_t options[];
d9d99f
+} GRUB_PACKED;
d9d99f
+typedef struct grub_net_dhcpv6_opt_ia_address grub_net_dhcpv6_opt_ia_address_t;
d9d99f
+
d9d99f
+struct grub_net_dhcpv6_packet
d9d99f
+{
d9d99f
+  grub_uint32_t message_type:8;
d9d99f
+  grub_uint32_t transaction_id:24;
d9d99f
+  grub_uint8_t dhcp_options[1024];
d9d99f
+} GRUB_PACKED;
d9d99f
+typedef struct grub_net_dhcpv6_packet grub_net_dhcpv6_packet_t;
d9d99f
+
d9d99f
 #define	GRUB_NET_BOOTP_RFC1048_MAGIC_0	0x63
d9d99f
 #define	GRUB_NET_BOOTP_RFC1048_MAGIC_1	0x82
d9d99f
 #define	GRUB_NET_BOOTP_RFC1048_MAGIC_2	0x53
d9d99f
@@ -470,6 +515,21 @@ grub_net_configure_by_dhcp_ack (const char *name,
d9d99f
 				grub_size_t size,
d9d99f
 				int is_def, char **device, char **path);
d9d99f
 
d9d99f
+struct grub_net_network_level_interface *
d9d99f
+grub_net_configure_by_dhcpv6_ack (const char *name,
d9d99f
+				 struct grub_net_card *card,
d9d99f
+				 grub_net_interface_flags_t flags,
d9d99f
+				 const grub_net_link_level_address_t *hwaddr,
d9d99f
+				 const struct grub_net_dhcpv6_packet *packet,
d9d99f
+				 int is_def, char **device, char **path);
d9d99f
+
d9d99f
+int
d9d99f
+grub_ipv6_get_masksize(grub_uint16_t *mask);
d9d99f
+
d9d99f
+grub_err_t
d9d99f
+grub_net_add_ipv6_local (struct grub_net_network_level_interface *inf,
d9d99f
+			 int mask);
d9d99f
+
d9d99f
 grub_err_t
d9d99f
 grub_net_add_ipv4_local (struct grub_net_network_level_interface *inf,
d9d99f
 			 int mask);