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