2018-07-12 14:56:34 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-07-10 19:08:14 +00:00
|
|
|
From: Andrzej Kacprowski <andrzej.kacprowski@intel.com>
|
2019-08-15 06:01:31 +00:00
|
|
|
Date: Wed, 10 Jul 2019 15:22:29 +0200
|
2018-07-10 19:08:14 +00:00
|
|
|
Subject: [PATCH] Add support for non-Ethernet network cards
|
|
|
|
|
|
|
|
This patch replaces fixed 6-byte link layer address with
|
|
|
|
up to 32-byte variable sized address.
|
|
|
|
This allows supporting Infiniband and Omni-Path fabric
|
|
|
|
which use 20-byte address, but other network card types
|
|
|
|
can also take advantage of this change.
|
|
|
|
The network card driver is responsible for replacing L2
|
|
|
|
header provided by grub2 if needed.
|
|
|
|
This approach is compatible with UEFI network stack which
|
|
|
|
also allows up to 32-byte variable size link address.
|
|
|
|
|
|
|
|
The BOOTP/DHCP packet format is limited to 16 byte client
|
|
|
|
hardware address, if link address is more that 16-bytes
|
|
|
|
then chaddr field in BOOTP it will be set to 0 as per rfc4390.
|
|
|
|
|
|
|
|
Resolves: rhbz#1370642
|
|
|
|
|
|
|
|
Signed-off-by: Andrzej Kacprowski <andrzej.kacprowski@intel.com>
|
2019-07-16 09:23:51 +00:00
|
|
|
[msalter: Fix max string calculation in grub_net_hwaddr_to_str]
|
|
|
|
Signed-off-by: Mark Salter <msalter@redhat.com>
|
2018-07-10 19:08:14 +00:00
|
|
|
---
|
2024-08-01 23:56:47 +00:00
|
|
|
grub-core/net/arp.c | 156 ++++++++++++++++++++++-----------
|
2019-08-15 06:01:31 +00:00
|
|
|
grub-core/net/bootp.c | 15 ++--
|
2018-07-10 19:08:14 +00:00
|
|
|
grub-core/net/drivers/efi/efinet.c | 8 +-
|
|
|
|
grub-core/net/drivers/emu/emunet.c | 1 +
|
|
|
|
grub-core/net/drivers/i386/pc/pxe.c | 13 +--
|
|
|
|
grub-core/net/drivers/ieee1275/ofnet.c | 2 +
|
|
|
|
grub-core/net/drivers/uboot/ubootnet.c | 1 +
|
2024-08-01 23:56:47 +00:00
|
|
|
grub-core/net/ethernet.c | 89 +++++++++----------
|
2018-07-10 19:08:14 +00:00
|
|
|
grub-core/net/icmp6.c | 15 ++--
|
|
|
|
grub-core/net/ip.c | 4 +-
|
2019-07-16 09:23:51 +00:00
|
|
|
grub-core/net/net.c | 50 ++++++-----
|
2018-07-10 19:08:14 +00:00
|
|
|
include/grub/net.h | 19 ++--
|
2024-08-01 23:56:47 +00:00
|
|
|
12 files changed, 220 insertions(+), 153 deletions(-)
|
2018-07-10 19:08:14 +00:00
|
|
|
|
|
|
|
diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 1d367436cfc..8bf0a06e193 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/arp.c
|
|
|
|
+++ b/grub-core/net/arp.c
|
|
|
|
@@ -31,22 +31,12 @@ enum
|
|
|
|
ARP_REPLY = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
-enum
|
|
|
|
- {
|
|
|
|
- /* IANA ARP constant to define hardware type as ethernet. */
|
|
|
|
- GRUB_NET_ARPHRD_ETHERNET = 1
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-struct arppkt {
|
|
|
|
+struct arphdr {
|
|
|
|
grub_uint16_t hrd;
|
|
|
|
grub_uint16_t pro;
|
|
|
|
grub_uint8_t hln;
|
|
|
|
grub_uint8_t pln;
|
|
|
|
grub_uint16_t op;
|
|
|
|
- grub_uint8_t sender_mac[6];
|
|
|
|
- grub_uint32_t sender_ip;
|
|
|
|
- grub_uint8_t recv_mac[6];
|
|
|
|
- grub_uint32_t recv_ip;
|
|
|
|
} GRUB_PACKED;
|
|
|
|
|
|
|
|
static int have_pending;
|
|
|
|
@@ -57,12 +47,16 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf,
|
|
|
|
const grub_net_network_level_address_t *proto_addr)
|
|
|
|
{
|
|
|
|
struct grub_net_buff nb;
|
|
|
|
- struct arppkt *arp_packet;
|
|
|
|
+ struct arphdr *arp_header;
|
|
|
|
grub_net_link_level_address_t target_mac_addr;
|
|
|
|
grub_err_t err;
|
|
|
|
int i;
|
|
|
|
grub_uint8_t *nbd;
|
|
|
|
grub_uint8_t arp_data[128];
|
|
|
|
+ grub_uint8_t hln;
|
|
|
|
+ grub_uint8_t pln;
|
|
|
|
+ grub_uint8_t arp_packet_len;
|
|
|
|
+ grub_uint8_t *tmp_ptr;
|
|
|
|
|
|
|
|
if (proto_addr->type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4)
|
|
|
|
return grub_error (GRUB_ERR_BUG, "unsupported address family");
|
|
|
|
@@ -73,23 +67,39 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf,
|
|
|
|
grub_netbuff_clear (&nb);
|
|
|
|
grub_netbuff_reserve (&nb, 128);
|
|
|
|
|
|
|
|
- err = grub_netbuff_push (&nb, sizeof (*arp_packet));
|
|
|
|
+ hln = inf->card->default_address.len;
|
|
|
|
+ pln = sizeof (proto_addr->ipv4);
|
|
|
|
+ arp_packet_len = sizeof (*arp_header) + 2 * (hln + pln);
|
|
|
|
+
|
|
|
|
+ err = grub_netbuff_push (&nb, arp_packet_len);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
- arp_packet = (struct arppkt *) nb.data;
|
|
|
|
- arp_packet->hrd = grub_cpu_to_be16_compile_time (GRUB_NET_ARPHRD_ETHERNET);
|
|
|
|
- arp_packet->hln = 6;
|
|
|
|
- arp_packet->pro = grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP);
|
|
|
|
- arp_packet->pln = 4;
|
|
|
|
- arp_packet->op = grub_cpu_to_be16_compile_time (ARP_REQUEST);
|
|
|
|
- /* Sender hardware address. */
|
|
|
|
- grub_memcpy (arp_packet->sender_mac, &inf->hwaddress.mac, 6);
|
|
|
|
- arp_packet->sender_ip = inf->address.ipv4;
|
|
|
|
- grub_memset (arp_packet->recv_mac, 0, 6);
|
|
|
|
- arp_packet->recv_ip = proto_addr->ipv4;
|
|
|
|
- /* Target protocol address */
|
|
|
|
- grub_memset (&target_mac_addr.mac, 0xff, 6);
|
|
|
|
+ arp_header = (struct arphdr *) nb.data;
|
|
|
|
+ arp_header->hrd = grub_cpu_to_be16 (inf->card->default_address.type);
|
|
|
|
+ arp_header->hln = hln;
|
|
|
|
+ arp_header->pro = grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP);
|
|
|
|
+ arp_header->pln = pln;
|
|
|
|
+ arp_header->op = grub_cpu_to_be16_compile_time (ARP_REQUEST);
|
|
|
|
+ tmp_ptr = nb.data + sizeof (*arp_header);
|
|
|
|
+
|
|
|
|
+ /* The source hardware address. */
|
|
|
|
+ grub_memcpy (tmp_ptr, inf->hwaddress.mac, hln);
|
|
|
|
+ tmp_ptr += hln;
|
|
|
|
+
|
|
|
|
+ /* The source protocol address. */
|
|
|
|
+ grub_memcpy (tmp_ptr, &inf->address.ipv4, pln);
|
|
|
|
+ tmp_ptr += pln;
|
|
|
|
+
|
|
|
|
+ /* The target hardware address. */
|
|
|
|
+ grub_memset (tmp_ptr, 0, hln);
|
|
|
|
+ tmp_ptr += hln;
|
|
|
|
+
|
|
|
|
+ /* The target protocol address */
|
|
|
|
+ grub_memcpy (tmp_ptr, &proto_addr->ipv4, pln);
|
|
|
|
+ tmp_ptr += pln;
|
|
|
|
+
|
|
|
|
+ grub_memset (&target_mac_addr.mac, 0xff, hln);
|
|
|
|
|
|
|
|
nbd = nb.data;
|
|
|
|
send_ethernet_packet (inf, &nb, target_mac_addr, GRUB_NET_ETHERTYPE_ARP);
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -114,30 +124,56 @@ grub_err_t
|
2018-07-10 19:08:14 +00:00
|
|
|
grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card,
|
|
|
|
grub_uint16_t *vlantag)
|
|
|
|
{
|
|
|
|
- struct arppkt *arp_packet = (struct arppkt *) nb->data;
|
|
|
|
+ struct arphdr *arp_header = (struct arphdr *) nb->data;
|
|
|
|
grub_net_network_level_address_t sender_addr, target_addr;
|
|
|
|
grub_net_link_level_address_t sender_mac_addr;
|
|
|
|
struct grub_net_network_level_interface *inf;
|
|
|
|
+ grub_uint16_t hw_type;
|
|
|
|
+ grub_uint8_t hln;
|
|
|
|
+ grub_uint8_t pln;
|
|
|
|
+ grub_uint8_t arp_packet_len;
|
|
|
|
+ grub_uint8_t *tmp_ptr;
|
|
|
|
|
|
|
|
- if (arp_packet->pro != grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP)
|
|
|
|
- || arp_packet->pln != 4 || arp_packet->hln != 6
|
|
|
|
- || nb->tail - nb->data < (int) sizeof (*arp_packet))
|
|
|
|
+ hw_type = card->default_address.type;
|
|
|
|
+ hln = card->default_address.len;
|
|
|
|
+ pln = sizeof(sender_addr.ipv4);
|
|
|
|
+ arp_packet_len = sizeof (*arp_header) + 2 * (pln + hln);
|
|
|
|
+
|
|
|
|
+ if (arp_header->pro != grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP)
|
|
|
|
+ || arp_header->hrd != grub_cpu_to_be16 (hw_type)
|
|
|
|
+ || arp_header->hln != hln || arp_header->pln != pln
|
|
|
|
+ || nb->tail - nb->data < (int) arp_packet_len) {
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ tmp_ptr = nb->data + sizeof (*arp_header);
|
|
|
|
+
|
|
|
|
+ /* The source hardware address. */
|
|
|
|
+ sender_mac_addr.type = hw_type;
|
|
|
|
+ sender_mac_addr.len = hln;
|
|
|
|
+ grub_memcpy (sender_mac_addr.mac, tmp_ptr, hln);
|
|
|
|
+ tmp_ptr += hln;
|
|
|
|
+
|
|
|
|
+ /* The source protocol address. */
|
|
|
|
sender_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
|
2024-08-01 23:56:47 +00:00
|
|
|
- target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
|
|
|
|
- sender_addr.ipv4 = arp_packet->sender_ip;
|
|
|
|
- target_addr.ipv4 = arp_packet->recv_ip;
|
|
|
|
sender_addr.option = 0;
|
|
|
|
target_addr.option = 0;
|
|
|
|
- if (arp_packet->sender_ip == pending_req)
|
|
|
|
- have_pending = 1;
|
|
|
|
|
|
|
|
- sender_mac_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
- grub_memcpy (sender_mac_addr.mac, arp_packet->sender_mac,
|
|
|
|
- sizeof (sender_mac_addr.mac));
|
|
|
|
+ grub_memcpy(&target_addr.ipv4, tmp_ptr, pln);
|
2018-07-10 19:08:14 +00:00
|
|
|
+ tmp_ptr += pln;
|
|
|
|
+
|
2024-08-01 23:56:47 +00:00
|
|
|
grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1);
|
|
|
|
|
2018-07-10 19:08:14 +00:00
|
|
|
+ /* The target hardware address. */
|
|
|
|
+ tmp_ptr += hln;
|
|
|
|
+
|
|
|
|
+ /* The target protocol address. */
|
2024-08-01 23:56:47 +00:00
|
|
|
+ target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
|
2018-07-10 19:08:14 +00:00
|
|
|
+ grub_memcpy(&target_addr.ipv4, tmp_ptr, pln);
|
|
|
|
+
|
|
|
|
+ if (sender_addr.ipv4 == pending_req)
|
2024-08-01 23:56:47 +00:00
|
|
|
+ have_pending = 1;
|
|
|
|
+
|
2018-07-10 19:08:14 +00:00
|
|
|
FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
|
|
|
|
{
|
|
|
|
/* Verify vlantag id */
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -150,11 +186,11 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card,
|
2018-07-10 19:08:14 +00:00
|
|
|
|
|
|
|
/* Am I the protocol address target? */
|
|
|
|
if (grub_net_addr_cmp (&inf->address, &target_addr) == 0
|
|
|
|
- && arp_packet->op == grub_cpu_to_be16_compile_time (ARP_REQUEST))
|
|
|
|
+ && arp_header->op == grub_cpu_to_be16_compile_time (ARP_REQUEST))
|
|
|
|
{
|
|
|
|
grub_net_link_level_address_t target;
|
|
|
|
struct grub_net_buff nb_reply;
|
|
|
|
- struct arppkt *arp_reply;
|
|
|
|
+ struct arphdr *arp_reply;
|
|
|
|
grub_uint8_t arp_data[128];
|
|
|
|
grub_err_t err;
|
|
|
|
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -163,25 +199,39 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card,
|
2018-07-10 19:08:14 +00:00
|
|
|
grub_netbuff_clear (&nb_reply);
|
|
|
|
grub_netbuff_reserve (&nb_reply, 128);
|
|
|
|
|
|
|
|
- err = grub_netbuff_push (&nb_reply, sizeof (*arp_packet));
|
|
|
|
+ err = grub_netbuff_push (&nb_reply, arp_packet_len);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
- arp_reply = (struct arppkt *) nb_reply.data;
|
|
|
|
+ arp_reply = (struct arphdr *) nb_reply.data;
|
|
|
|
|
|
|
|
- arp_reply->hrd = grub_cpu_to_be16_compile_time (GRUB_NET_ARPHRD_ETHERNET);
|
|
|
|
+ arp_reply->hrd = grub_cpu_to_be16 (hw_type);
|
|
|
|
arp_reply->pro = grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP);
|
|
|
|
- arp_reply->pln = 4;
|
|
|
|
- arp_reply->hln = 6;
|
|
|
|
+ arp_reply->pln = pln;
|
|
|
|
+ arp_reply->hln = hln;
|
|
|
|
arp_reply->op = grub_cpu_to_be16_compile_time (ARP_REPLY);
|
|
|
|
- arp_reply->sender_ip = arp_packet->recv_ip;
|
|
|
|
- arp_reply->recv_ip = arp_packet->sender_ip;
|
|
|
|
- arp_reply->hln = 6;
|
|
|
|
-
|
|
|
|
- target.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
- grub_memcpy (target.mac, arp_packet->sender_mac, 6);
|
|
|
|
- grub_memcpy (arp_reply->sender_mac, inf->hwaddress.mac, 6);
|
|
|
|
- grub_memcpy (arp_reply->recv_mac, arp_packet->sender_mac, 6);
|
|
|
|
+
|
|
|
|
+ tmp_ptr = nb_reply.data + sizeof (*arp_reply);
|
|
|
|
+
|
|
|
|
+ /* The source hardware address. */
|
|
|
|
+ grub_memcpy (tmp_ptr, inf->hwaddress.mac, hln);
|
|
|
|
+ tmp_ptr += hln;
|
|
|
|
+
|
|
|
|
+ /* The source protocol address. */
|
|
|
|
+ grub_memcpy (tmp_ptr, &target_addr.ipv4, pln);
|
|
|
|
+ tmp_ptr += pln;
|
|
|
|
+
|
|
|
|
+ /* The target hardware address. */
|
|
|
|
+ grub_memcpy (tmp_ptr, sender_mac_addr.mac, hln);
|
|
|
|
+ tmp_ptr += hln;
|
|
|
|
+
|
|
|
|
+ /* The target protocol address */
|
|
|
|
+ grub_memcpy (tmp_ptr, &sender_addr.ipv4, pln);
|
|
|
|
+ tmp_ptr += pln;
|
|
|
|
+
|
|
|
|
+ target.type = hw_type;
|
|
|
|
+ target.len = hln;
|
|
|
|
+ grub_memcpy (target.mac, sender_mac_addr.mac, hln);
|
|
|
|
|
|
|
|
/* Change operation to REPLY and send packet */
|
|
|
|
send_ethernet_packet (inf, &nb_reply, target, GRUB_NET_ETHERTYPE_ARP);
|
|
|
|
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index e0aec25233d..76e4c11a46f 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/bootp.c
|
|
|
|
+++ b/grub-core/net/bootp.c
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -325,7 +325,6 @@ grub_net_configure_by_dhcp_ack (const char *name,
|
2018-07-10 19:08:14 +00:00
|
|
|
int is_def, char **device, char **path)
|
|
|
|
{
|
|
|
|
grub_net_network_level_address_t addr;
|
|
|
|
- grub_net_link_level_address_t hwaddr;
|
|
|
|
struct grub_net_network_level_interface *inter;
|
|
|
|
int mask = -1;
|
|
|
|
char server_ip[sizeof ("xxx.xxx.xxx.xxx")];
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -343,12 +342,8 @@ grub_net_configure_by_dhcp_ack (const char *name,
|
2018-07-10 19:08:14 +00:00
|
|
|
if (path)
|
|
|
|
*path = 0;
|
|
|
|
|
|
|
|
- grub_memcpy (hwaddr.mac, bp->mac_addr,
|
|
|
|
- bp->hw_len < sizeof (hwaddr.mac) ? bp->hw_len
|
|
|
|
- : sizeof (hwaddr.mac));
|
|
|
|
- hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
-
|
|
|
|
- inter = grub_net_add_addr (name, card, &addr, &hwaddr, flags);
|
|
|
|
+ grub_dprintf("dhcp", "configuring dhcp for %s\n", name);
|
|
|
|
+ inter = grub_net_add_addr (name, card, &addr, &card->default_address, flags);
|
|
|
|
if (!inter)
|
|
|
|
return 0;
|
|
|
|
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -660,7 +655,9 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface)
|
2019-08-15 06:01:31 +00:00
|
|
|
grub_memset (pack, 0, sizeof (*pack));
|
|
|
|
pack->opcode = 1;
|
|
|
|
pack->hw_type = 1;
|
|
|
|
- pack->hw_len = 6;
|
|
|
|
+ pack->hw_len = iface->hwaddress.len > 16 ? 0
|
|
|
|
+ : iface->hwaddress.len;
|
|
|
|
+
|
|
|
|
err = grub_get_datetime (&date);
|
|
|
|
if (err || !grub_datetime2unixtime (&date, &t))
|
|
|
|
{
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -673,7 +670,7 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface)
|
2019-08-15 06:01:31 +00:00
|
|
|
else
|
|
|
|
pack->ident = iface->xid;
|
2018-07-10 19:08:14 +00:00
|
|
|
|
2019-08-15 06:01:31 +00:00
|
|
|
- grub_memcpy (&pack->mac_addr, &iface->hwaddress.mac, 6);
|
|
|
|
+ grub_memcpy (&pack->mac_addr, &iface->hwaddress.mac, pack->hw_len);
|
2018-07-10 19:08:14 +00:00
|
|
|
|
2024-08-01 23:56:47 +00:00
|
|
|
err = grub_netbuff_push (nb, sizeof (*udph));
|
|
|
|
if (err)
|
2018-07-10 19:08:14 +00:00
|
|
|
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 3e2432fb61c..7deb0a32efd 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/drivers/efi/efinet.c
|
|
|
|
+++ b/grub-core/net/drivers/efi/efinet.c
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -288,6 +288,9 @@ grub_efinet_findcards (void)
|
2018-07-10 19:08:14 +00:00
|
|
|
/* This should not happen... Why? */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
+ if (net->mode->hwaddr_size > GRUB_NET_MAX_LINK_ADDRESS_SIZE)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
if (net->mode->state == GRUB_EFI_NETWORK_STOPPED
|
2024-08-01 23:56:47 +00:00
|
|
|
&& net->start (net) != GRUB_EFI_SUCCESS)
|
2018-07-10 19:08:14 +00:00
|
|
|
continue;
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -332,10 +335,11 @@ grub_efinet_findcards (void)
|
|
|
|
* such as LoadFile2 for initrd loading.
|
|
|
|
*/
|
|
|
|
card->flags = GRUB_NET_CARD_NO_CLOSE_ON_FINI_HW;
|
2018-07-10 19:08:14 +00:00
|
|
|
- card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
+ card->default_address.type = net->mode->if_type;
|
|
|
|
+ card->default_address.len = net->mode->hwaddr_size;
|
|
|
|
grub_memcpy (card->default_address.mac,
|
|
|
|
net->mode->current_address,
|
|
|
|
- sizeof (card->default_address.mac));
|
|
|
|
+ net->mode->hwaddr_size);
|
|
|
|
card->efi_net = net;
|
|
|
|
card->efi_handle = *handle;
|
|
|
|
|
|
|
|
diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 5f311d40f49..7461d13bbc2 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/drivers/emu/emunet.c
|
|
|
|
+++ b/grub-core/net/drivers/emu/emunet.c
|
|
|
|
@@ -46,6 +46,7 @@ static struct grub_net_card emucard =
|
|
|
|
.mtu = 1500,
|
|
|
|
.default_address = {
|
|
|
|
.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET,
|
|
|
|
+ . len = 6,
|
|
|
|
{.mac = {0, 1, 2, 3, 4, 5}}
|
|
|
|
},
|
|
|
|
.flags = 0
|
|
|
|
diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index db17186ee7d..816d1d0eeda 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/drivers/i386/pc/pxe.c
|
|
|
|
+++ b/grub-core/net/drivers/i386/pc/pxe.c
|
|
|
|
@@ -386,20 +386,21 @@ GRUB_MOD_INIT(pxe)
|
|
|
|
grub_memset (ui, 0, sizeof (*ui));
|
|
|
|
grub_pxe_call (GRUB_PXENV_UNDI_GET_INFORMATION, ui, pxe_rm_entry);
|
|
|
|
|
|
|
|
+ grub_pxe_card.default_address.len = 6;
|
|
|
|
grub_memcpy (grub_pxe_card.default_address.mac, ui->current_addr,
|
|
|
|
- sizeof (grub_pxe_card.default_address.mac));
|
|
|
|
- for (i = 0; i < sizeof (grub_pxe_card.default_address.mac); i++)
|
|
|
|
+ grub_pxe_card.default_address.len);
|
|
|
|
+ for (i = 0; i < grub_pxe_card.default_address.len; i++)
|
|
|
|
if (grub_pxe_card.default_address.mac[i] != 0)
|
|
|
|
break;
|
|
|
|
- if (i != sizeof (grub_pxe_card.default_address.mac))
|
|
|
|
+ if (i != grub_pxe_card.default_address.len)
|
|
|
|
{
|
|
|
|
- for (i = 0; i < sizeof (grub_pxe_card.default_address.mac); i++)
|
|
|
|
+ for (i = 0; i < grub_pxe_card.default_address.len; i++)
|
|
|
|
if (grub_pxe_card.default_address.mac[i] != 0xff)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
- if (i == sizeof (grub_pxe_card.default_address.mac))
|
|
|
|
+ if (i == grub_pxe_card.default_address.len)
|
|
|
|
grub_memcpy (grub_pxe_card.default_address.mac, ui->permanent_addr,
|
|
|
|
- sizeof (grub_pxe_card.default_address.mac));
|
|
|
|
+ grub_pxe_card.default_address.len);
|
|
|
|
grub_pxe_card.mtu = ui->mtu;
|
|
|
|
|
|
|
|
grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 78f03df8e21..c56461ff1ae 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/drivers/ieee1275/ofnet.c
|
|
|
|
+++ b/grub-core/net/drivers/ieee1275/ofnet.c
|
|
|
|
@@ -160,6 +160,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath,
|
|
|
|
grub_uint16_t vlantag = 0;
|
|
|
|
|
|
|
|
hw_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
+ hw_addr.len = 6;
|
|
|
|
|
|
|
|
args = bootpath + grub_strlen (devpath) + 1;
|
|
|
|
do
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -491,6 +492,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias)
|
2018-07-10 19:08:14 +00:00
|
|
|
grub_memcpy (&lla.mac, pprop, 6);
|
|
|
|
|
|
|
|
lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
+ lla.len = 6;
|
|
|
|
card->default_address = lla;
|
|
|
|
|
|
|
|
card->txbufsize = ALIGN_UP (card->mtu, 64) + 256;
|
|
|
|
diff --git a/grub-core/net/drivers/uboot/ubootnet.c b/grub-core/net/drivers/uboot/ubootnet.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index b9d5a0cd494..9f3354a1b74 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/drivers/uboot/ubootnet.c
|
|
|
|
+++ b/grub-core/net/drivers/uboot/ubootnet.c
|
|
|
|
@@ -131,6 +131,7 @@ GRUB_MOD_INIT (ubootnet)
|
|
|
|
|
|
|
|
grub_memcpy (&(card->default_address.mac), &devinfo->di_net.hwaddr, 6);
|
|
|
|
card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
+ card->default_address.len = 6;
|
|
|
|
|
|
|
|
card->txbufsize = ALIGN_UP (card->mtu, 64) + 256;
|
|
|
|
card->txbuf = grub_zalloc (card->txbufsize);
|
|
|
|
diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 707bbb12cb2..1441a1bacff 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/ethernet.c
|
|
|
|
+++ b/grub-core/net/ethernet.c
|
|
|
|
@@ -29,13 +29,6 @@
|
|
|
|
|
|
|
|
#define LLCADDRMASK 0x7f
|
|
|
|
|
|
|
|
-struct etherhdr
|
|
|
|
-{
|
|
|
|
- grub_uint8_t dst[6];
|
|
|
|
- grub_uint8_t src[6];
|
|
|
|
- grub_uint16_t type;
|
|
|
|
-} GRUB_PACKED;
|
|
|
|
-
|
|
|
|
struct llchdr
|
|
|
|
{
|
|
|
|
grub_uint8_t dsap;
|
|
|
|
@@ -55,13 +48,15 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
|
|
|
|
grub_net_link_level_address_t target_addr,
|
|
|
|
grub_net_ethertype_t ethertype)
|
|
|
|
{
|
|
|
|
- struct etherhdr *eth;
|
|
|
|
+ grub_uint8_t *eth;
|
|
|
|
grub_err_t err;
|
|
|
|
- grub_uint8_t etherhdr_size;
|
2024-08-01 23:56:47 +00:00
|
|
|
- grub_uint16_t vlantag_id = grub_cpu_to_be16_compile_time (VLANTAG_IDENTIFIER);
|
2018-07-10 19:08:14 +00:00
|
|
|
+ grub_uint32_t vlantag = 0;
|
|
|
|
+ grub_uint8_t hw_addr_len = inf->card->default_address.len;
|
|
|
|
+ grub_uint8_t etherhdr_size = 2 * hw_addr_len + 2;
|
|
|
|
|
|
|
|
- etherhdr_size = sizeof (*eth);
|
|
|
|
- COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE);
|
|
|
|
+ /* Source and destination link addresses + ethertype + vlan tag */
|
|
|
|
+ COMPILE_TIME_ASSERT ((GRUB_NET_MAX_LINK_ADDRESS_SIZE * 2 + 2 + 4) <
|
|
|
|
+ GRUB_NET_MAX_LINK_HEADER_SIZE);
|
|
|
|
|
|
|
|
/* Increase ethernet header in case of vlantag */
|
|
|
|
if (inf->vlantag != 0)
|
|
|
|
@@ -70,11 +65,22 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
|
|
|
|
err = grub_netbuff_push (nb, etherhdr_size);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
- eth = (struct etherhdr *) nb->data;
|
|
|
|
- grub_memcpy (eth->dst, target_addr.mac, 6);
|
|
|
|
- grub_memcpy (eth->src, inf->hwaddress.mac, 6);
|
|
|
|
+ eth = nb->data;
|
|
|
|
+ grub_memcpy (eth, target_addr.mac, hw_addr_len);
|
|
|
|
+ eth += hw_addr_len;
|
|
|
|
+ grub_memcpy (eth, inf->hwaddress.mac, hw_addr_len);
|
|
|
|
+ eth += hw_addr_len;
|
|
|
|
+
|
|
|
|
+ /* Check if a vlan-tag is present. */
|
|
|
|
+ if (vlantag != 0)
|
|
|
|
+ {
|
|
|
|
+ *((grub_uint32_t *)eth) = grub_cpu_to_be32 (vlantag);
|
|
|
|
+ eth += sizeof (vlantag);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Write ethertype */
|
|
|
|
+ *((grub_uint16_t*) eth) = grub_cpu_to_be16 (ethertype);
|
|
|
|
|
|
|
|
- eth->type = grub_cpu_to_be16 (ethertype);
|
|
|
|
if (!inf->card->opened)
|
|
|
|
{
|
|
|
|
err = GRUB_ERR_NONE;
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -85,19 +91,6 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
|
2018-07-10 19:08:14 +00:00
|
|
|
inf->card->opened = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- /* Check and add a vlan-tag if needed. */
|
|
|
|
- if (inf->vlantag != 0)
|
|
|
|
- {
|
|
|
|
- /* Move eth type to the right */
|
|
|
|
- grub_memcpy ((char *) nb->data + etherhdr_size - 2,
|
|
|
|
- (char *) nb->data + etherhdr_size - 6, 2);
|
|
|
|
-
|
|
|
|
- /* Add the tag in the middle */
|
2024-08-01 23:56:47 +00:00
|
|
|
- grub_uint16_t vlan = grub_cpu_to_be16 (inf->vlantag);
|
2018-07-10 19:08:14 +00:00
|
|
|
- grub_memcpy ((char *) nb->data + etherhdr_size - 6, &vlantag_id, 2);
|
2024-08-01 23:56:47 +00:00
|
|
|
- grub_memcpy ((char *) nb->data + etherhdr_size - 4, &vlan, 2);
|
2018-07-10 19:08:14 +00:00
|
|
|
- }
|
|
|
|
-
|
|
|
|
return inf->card->driver->send (inf->card, nb);
|
|
|
|
}
|
|
|
|
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -105,31 +98,40 @@ grub_err_t
|
2018-07-10 19:08:14 +00:00
|
|
|
grub_net_recv_ethernet_packet (struct grub_net_buff *nb,
|
|
|
|
struct grub_net_card *card)
|
|
|
|
{
|
|
|
|
- struct etherhdr *eth;
|
|
|
|
+ grub_uint8_t *eth;
|
|
|
|
struct llchdr *llch;
|
|
|
|
struct snaphdr *snaph;
|
|
|
|
grub_net_ethertype_t type;
|
|
|
|
grub_net_link_level_address_t hwaddress;
|
|
|
|
grub_net_link_level_address_t src_hwaddress;
|
|
|
|
grub_err_t err;
|
|
|
|
- grub_uint8_t etherhdr_size = sizeof (*eth);
|
|
|
|
+ grub_uint8_t hw_addr_len = card->default_address.len;
|
|
|
|
+ grub_uint8_t etherhdr_size = 2 * hw_addr_len + 2;
|
|
|
|
grub_uint16_t vlantag = 0;
|
|
|
|
|
|
|
|
+ eth = nb->data;
|
|
|
|
|
|
|
|
- /* Check if a vlan-tag is present. If so, the ethernet header is 4 bytes */
|
|
|
|
- /* longer than the original one. The vlantag id is extracted and the header */
|
|
|
|
- /* is reseted to the original size. */
|
2024-08-01 23:56:47 +00:00
|
|
|
- if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == grub_cpu_to_be16_compile_time (VLANTAG_IDENTIFIER))
|
2018-07-10 19:08:14 +00:00
|
|
|
+ hwaddress.type = card->default_address.type;
|
|
|
|
+ hwaddress.len = hw_addr_len;
|
|
|
|
+ grub_memcpy (hwaddress.mac, eth, hw_addr_len);
|
|
|
|
+ eth += hw_addr_len;
|
|
|
|
+
|
|
|
|
+ src_hwaddress.type = card->default_address.type;
|
|
|
|
+ src_hwaddress.len = hw_addr_len;
|
|
|
|
+ grub_memcpy (src_hwaddress.mac, eth, hw_addr_len);
|
|
|
|
+ eth += hw_addr_len;
|
|
|
|
+
|
|
|
|
+ type = grub_be_to_cpu16 (*(grub_uint16_t*)(eth));
|
|
|
|
+ if (type == VLANTAG_IDENTIFIER)
|
|
|
|
{
|
2024-08-01 23:56:47 +00:00
|
|
|
- vlantag = grub_be_to_cpu16 (grub_get_unaligned16 (nb->data + etherhdr_size));
|
2018-07-10 19:08:14 +00:00
|
|
|
+ /* Skip vlan tag */
|
|
|
|
+ eth += 2;
|
|
|
|
+ vlantag = grub_be_to_cpu16 (*(grub_uint16_t*)(eth));
|
|
|
|
etherhdr_size += 4;
|
|
|
|
- /* Move eth type to the original position */
|
|
|
|
- grub_memcpy((char *) nb->data + etherhdr_size - 6,
|
|
|
|
- (char *) nb->data + etherhdr_size - 2, 2);
|
|
|
|
+ eth += 2;
|
|
|
|
+ type = grub_be_to_cpu16 (*(grub_uint16_t*)(eth));
|
|
|
|
}
|
|
|
|
|
|
|
|
- eth = (struct etherhdr *) nb->data;
|
|
|
|
- type = grub_be_to_cpu16 (eth->type);
|
|
|
|
err = grub_netbuff_pull (nb, etherhdr_size);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -149,11 +151,6 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb,
|
2018-07-10 19:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- hwaddress.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
- grub_memcpy (hwaddress.mac, eth->dst, sizeof (hwaddress.mac));
|
|
|
|
- src_hwaddress.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
- grub_memcpy (src_hwaddress.mac, eth->src, sizeof (src_hwaddress.mac));
|
|
|
|
-
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
/* ARP packet. */
|
|
|
|
diff --git a/grub-core/net/icmp6.c b/grub-core/net/icmp6.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 9a8c4511285..5924fd53aca 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/icmp6.c
|
|
|
|
+++ b/grub-core/net/icmp6.c
|
|
|
|
@@ -231,8 +231,9 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb,
|
|
|
|
&& ohdr->len == 1)
|
|
|
|
{
|
|
|
|
grub_net_link_level_address_t ll_address;
|
|
|
|
- ll_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
- grub_memcpy (ll_address.mac, ohdr + 1, sizeof (ll_address.mac));
|
|
|
|
+ ll_address.type = card->default_address.type;
|
|
|
|
+ ll_address.len = card->default_address.len;
|
|
|
|
+ grub_memcpy (ll_address.mac, ohdr + 1, ll_address.len);
|
|
|
|
grub_net_link_layer_add_address (card, source, &ll_address, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -335,8 +336,9 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb,
|
|
|
|
&& ohdr->len == 1)
|
|
|
|
{
|
|
|
|
grub_net_link_level_address_t ll_address;
|
|
|
|
- ll_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
- grub_memcpy (ll_address.mac, ohdr + 1, sizeof (ll_address.mac));
|
|
|
|
+ ll_address.type = card->default_address.type;
|
|
|
|
+ ll_address.len = card->default_address.len;
|
|
|
|
+ grub_memcpy (ll_address.mac, ohdr + 1, ll_address.len);
|
|
|
|
grub_net_link_layer_add_address (card, source, &ll_address, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -384,8 +386,9 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb,
|
|
|
|
&& ohdr->len == 1)
|
|
|
|
{
|
|
|
|
grub_net_link_level_address_t ll_address;
|
|
|
|
- ll_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
- grub_memcpy (ll_address.mac, ohdr + 1, sizeof (ll_address.mac));
|
|
|
|
+ ll_address.type = card->default_address.type;
|
|
|
|
+ ll_address.len = card->default_address.len;
|
|
|
|
+ grub_memcpy (ll_address.mac, ohdr + 1, ll_address.len);
|
|
|
|
grub_net_link_layer_add_address (card, source, &ll_address, 0);
|
|
|
|
}
|
|
|
|
if (ohdr->type == OPTION_PREFIX && ohdr->len == 4)
|
|
|
|
diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index f967618e53f..3c475762cc0 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/ip.c
|
|
|
|
+++ b/grub-core/net/ip.c
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -316,8 +316,8 @@ handle_dgram (struct grub_net_buff *nb,
|
2019-08-15 06:01:31 +00:00
|
|
|
if (inf->card == card
|
2018-07-10 19:08:14 +00:00
|
|
|
&& inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV
|
|
|
|
&& inf->hwaddress.type == GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET
|
|
|
|
- && grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr,
|
|
|
|
- sizeof (inf->hwaddress.mac)) == 0)
|
|
|
|
+ && (grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr,
|
|
|
|
+ bootp->hw_len) == 0 || bootp->hw_len == 0))
|
|
|
|
{
|
2019-08-15 06:01:31 +00:00
|
|
|
grub_net_process_dhcp (nb, inf);
|
2018-07-10 19:08:14 +00:00
|
|
|
grub_netbuff_free (nb);
|
|
|
|
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 20c55257647..fa6b6537142 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/grub-core/net/net.c
|
|
|
|
+++ b/grub-core/net/net.c
|
2021-03-12 21:54:28 +00:00
|
|
|
@@ -133,8 +133,9 @@ grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf,
|
2018-07-10 19:08:14 +00:00
|
|
|
<< 48)
|
|
|
|
&& proto_addr->ipv6[1] == (grub_be_to_cpu64_compile_time (1))))
|
|
|
|
{
|
|
|
|
- hw_addr->type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
- grub_memset (hw_addr->mac, -1, 6);
|
|
|
|
+ hw_addr->type = inf->card->default_address.type;
|
|
|
|
+ hw_addr->len = inf->card->default_address.len;
|
|
|
|
+ grub_memset (hw_addr->mac, -1, hw_addr->len);
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2021-03-12 21:54:28 +00:00
|
|
|
@@ -142,6 +143,7 @@ grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf,
|
2018-07-10 19:08:14 +00:00
|
|
|
&& ((grub_be_to_cpu64 (proto_addr->ipv6[0]) >> 56) == 0xff))
|
|
|
|
{
|
|
|
|
hw_addr->type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
|
|
|
+ hw_addr->len = inf->card->default_address.len;
|
|
|
|
hw_addr->mac[0] = 0x33;
|
|
|
|
hw_addr->mac[1] = 0x33;
|
|
|
|
hw_addr->mac[2] = ((grub_be_to_cpu64 (proto_addr->ipv6[1]) >> 24) & 0xff);
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -772,23 +774,23 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf)
|
2018-07-10 19:08:14 +00:00
|
|
|
void
|
|
|
|
grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str)
|
|
|
|
{
|
|
|
|
- str[0] = 0;
|
|
|
|
- switch (addr->type)
|
|
|
|
+ char *ptr;
|
|
|
|
+ unsigned i;
|
2019-07-16 09:23:51 +00:00
|
|
|
+ int maxstr;
|
2018-07-10 19:08:14 +00:00
|
|
|
+
|
|
|
|
+ if (addr->len > GRUB_NET_MAX_LINK_ADDRESS_SIZE)
|
|
|
|
{
|
|
|
|
- case GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET:
|
|
|
|
- {
|
|
|
|
- char *ptr;
|
|
|
|
- unsigned i;
|
|
|
|
- for (ptr = str, i = 0; i < ARRAY_SIZE (addr->mac); i++)
|
|
|
|
- {
|
|
|
|
- grub_snprintf (ptr, GRUB_NET_MAX_STR_HWADDR_LEN - (ptr - str),
|
|
|
|
- "%02x:", addr->mac[i] & 0xff);
|
|
|
|
- ptr += (sizeof ("XX:") - 1);
|
|
|
|
- }
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
+ str[0] = 0;
|
|
|
|
+ grub_printf (_("Unsupported hw address type %d len %d\n"),
|
|
|
|
+ addr->type, addr->len);
|
|
|
|
+ return;
|
|
|
|
+ }
|
2019-07-16 09:23:51 +00:00
|
|
|
+ maxstr = addr->len * grub_strlen ("XX:");
|
2018-07-10 19:08:14 +00:00
|
|
|
+ for (ptr = str, i = 0; i < addr->len; i++)
|
|
|
|
+ {
|
2019-07-16 09:23:51 +00:00
|
|
|
+ ptr += grub_snprintf (ptr, maxstr - (ptr - str),
|
2018-07-10 19:08:14 +00:00
|
|
|
+ "%02x:", addr->mac[i] & 0xff);
|
|
|
|
}
|
|
|
|
- grub_printf (_("Unsupported hw address type %d\n"), addr->type);
|
|
|
|
}
|
|
|
|
|
2024-08-01 23:56:47 +00:00
|
|
|
void
|
|
|
|
@@ -813,13 +815,17 @@ grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a,
|
2018-07-10 19:08:14 +00:00
|
|
|
return -1;
|
|
|
|
if (a->type > b->type)
|
|
|
|
return +1;
|
|
|
|
- switch (a->type)
|
|
|
|
+ if (a->len < b->len)
|
|
|
|
+ return -1;
|
|
|
|
+ if (a->len > b->len)
|
|
|
|
+ return +1;
|
|
|
|
+ if (a->len > GRUB_NET_MAX_LINK_ADDRESS_SIZE)
|
|
|
|
{
|
|
|
|
- case GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET:
|
|
|
|
- return grub_memcmp (a->mac, b->mac, sizeof (a->mac));
|
|
|
|
+ grub_printf (_("Unsupported hw address type %d len %d\n"),
|
|
|
|
+ a->type, a->len);
|
|
|
|
+ return + 1;
|
|
|
|
}
|
|
|
|
- grub_printf (_("Unsupported hw address type %d\n"), a->type);
|
|
|
|
- return 1;
|
|
|
|
+ return grub_memcmp (a->mac, b->mac, a->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
diff --git a/include/grub/net.h b/include/grub/net.h
|
2024-08-01 23:56:47 +00:00
|
|
|
index ff901b96e22..1d76fd9a1f5 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/include/grub/net.h
|
|
|
|
+++ b/include/grub/net.h
|
|
|
|
@@ -29,7 +29,8 @@
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
- GRUB_NET_MAX_LINK_HEADER_SIZE = 64,
|
|
|
|
+ GRUB_NET_MAX_LINK_HEADER_SIZE = 96,
|
|
|
|
+ GRUB_NET_MAX_LINK_ADDRESS_SIZE = 32,
|
|
|
|
GRUB_NET_UDP_HEADER_SIZE = 8,
|
|
|
|
GRUB_NET_TCP_HEADER_SIZE = 20,
|
|
|
|
GRUB_NET_OUR_IPV4_HEADER_SIZE = 20,
|
|
|
|
@@ -42,15 +43,17 @@ enum
|
|
|
|
|
2024-08-01 23:56:47 +00:00
|
|
|
typedef enum grub_link_level_protocol_id
|
2018-07-10 19:08:14 +00:00
|
|
|
{
|
|
|
|
- GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET
|
|
|
|
+ /* IANA ARP constant to define hardware type. */
|
|
|
|
+ GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET = 1,
|
|
|
|
} grub_link_level_protocol_id_t;
|
|
|
|
|
|
|
|
typedef struct grub_net_link_level_address
|
|
|
|
{
|
|
|
|
grub_link_level_protocol_id_t type;
|
|
|
|
+ grub_uint8_t len;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
- grub_uint8_t mac[6];
|
|
|
|
+ grub_uint8_t mac[GRUB_NET_MAX_LINK_ADDRESS_SIZE];
|
|
|
|
};
|
|
|
|
} grub_net_link_level_address_t;
|
|
|
|
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -588,11 +591,13 @@ grub_net_addr_cmp (const grub_net_network_level_address_t *a,
|
2018-07-10 19:08:14 +00:00
|
|
|
#define GRUB_NET_MAX_STR_ADDR_LEN sizeof ("XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX")
|
|
|
|
|
|
|
|
/*
|
|
|
|
- Currently suppoerted adresses:
|
|
|
|
- ethernet: XX:XX:XX:XX:XX:XX
|
|
|
|
+ Up to 32 byte hardware address supported, see GRUB_NET_MAX_LINK_ADDRESS_SIZE
|
|
|
|
*/
|
|
|
|
-
|
|
|
|
-#define GRUB_NET_MAX_STR_HWADDR_LEN (sizeof ("XX:XX:XX:XX:XX:XX"))
|
|
|
|
+#define GRUB_NET_MAX_STR_HWADDR_LEN (sizeof (\
|
|
|
|
+ "XX:XX:XX:XX:XX:XX:XX:XX:"\
|
|
|
|
+ "XX:XX:XX:XX:XX:XX:XX:XX:"\
|
|
|
|
+ "XX:XX:XX:XX:XX:XX:XX:XX:"\
|
|
|
|
+ "XX:XX:XX:XX:XX:XX:XX:XX"))
|
|
|
|
|
2024-08-01 23:56:47 +00:00
|
|
|
/* Max VLAN id = 4094 */
|
|
|
|
#define GRUB_NET_MAX_STR_VLAN_LEN (sizeof ("vlanXXXX"))
|