nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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