nalika / rpms / grub2

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