nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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