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

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