nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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