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