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