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

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