Add UEFI VLAN patches

This commit is contained in:
Simone Caronni 2023-08-10 11:21:32 +02:00
parent dc5c4e3f52
commit bb3942d42f
6 changed files with 364 additions and 5 deletions

View file

@ -0,0 +1,81 @@
From 2fd539ed1c41b7a771a78fb2a7ef8c89b4231b4b Mon Sep 17 00:00:00 2001
From: Chad Kimes <chkimes@github.com>
Date: Mon, 21 Mar 2022 17:29:15 -0400
Subject: [PATCH 333/336] net/net: Add vlan information to net_ls_addr output
Example output:
grub> net_ls_addr
efinet1 00:11:22:33:44:55 192.0.2.100 vlan100
Signed-off-by: Chad Kimes <chkimes@github.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
grub-core/net/net.c | 19 ++++++++++++++++++-
include/grub/net.h | 6 ++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
index 1001c611d..f37f34cb8 100644
--- a/grub-core/net/net.c
+++ b/grub-core/net/net.c
@@ -795,6 +795,20 @@ grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str)
}
}
+void
+grub_net_vlan_to_str (grub_uint16_t vlantag, char *str)
+{
+ str[0] = 0;
+
+ /* 12 bits are used to identify the vlan in 802.1Q. */
+ vlantag = vlantag & 0x0fff;
+
+ if (vlantag == 0)
+ return;
+
+ grub_snprintf (str, GRUB_NET_MAX_STR_VLAN_LEN, "vlan%u", vlantag);
+}
+
int
grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a,
const grub_net_link_level_address_t *b)
@@ -1340,9 +1354,12 @@ grub_cmd_listaddrs (struct grub_command *cmd __attribute__ ((unused)),
{
char bufh[GRUB_NET_MAX_STR_HWADDR_LEN];
char bufn[GRUB_NET_MAX_STR_ADDR_LEN];
+ char bufv[GRUB_NET_MAX_STR_VLAN_LEN];
+
grub_net_hwaddr_to_str (&inf->hwaddress, bufh);
grub_net_addr_to_str (&inf->address, bufn);
- grub_printf ("%s %s %s\n", inf->name, bufh, bufn);
+ grub_net_vlan_to_str (inf->vlantag, bufv);
+ grub_printf ("%s %s %s %s\n", inf->name, bufh, bufn, bufv);
}
return GRUB_ERR_NONE;
}
diff --git a/include/grub/net.h b/include/grub/net.h
index 9e4898cc6..d771afa47 100644
--- a/include/grub/net.h
+++ b/include/grub/net.h
@@ -599,12 +599,18 @@ grub_net_addr_cmp (const grub_net_network_level_address_t *a,
"XX:XX:XX:XX:XX:XX:XX:XX:"\
"XX:XX:XX:XX:XX:XX:XX:XX"))
+/* Max VLAN id = 4094 */
+#define GRUB_NET_MAX_STR_VLAN_LEN (sizeof ("vlanXXXX"))
+
void
grub_net_addr_to_str (const grub_net_network_level_address_t *target,
char *buf);
void
grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str);
+void
+grub_net_vlan_to_str (grub_uint16_t vlantag, char *str);
+
grub_err_t
grub_env_set_net_property (const char *intername, const char *suffix,
const char *value, grub_size_t len);
--
2.41.0

View file

@ -0,0 +1,134 @@
From 4ba50e6a7f9723d8ccca4b7e92184377c65df454 Mon Sep 17 00:00:00 2001
From: Chad Kimes <chkimes@github.com>
Date: Mon, 21 Mar 2022 17:29:16 -0400
Subject: [PATCH 334/336] net/net: Add net_set_vlan command
Previously there was no way to set the 802.1Q VLAN identifier, despite
support for vlantag in the net module. The only location vlantag was
being populated was from PXE boot and only for Open Firmware hardware.
This commit allows users to manually configure VLAN information for any
interface.
Example usage:
grub> net_ls_addr
efinet1 00:11:22:33:44:55 192.0.2.100
grub> net_set_vlan efinet1 100
grub> net_ls_addr
efinet1 00:11:22:33:44:55 192.0.2.100 vlan100
grub> net_set_vlan efinet1 0
efinet1 00:11:22:33:44:55 192.0.2.100
Signed-off-by: Chad Kimes <chkimes@github.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
docs/grub.texi | 20 ++++++++++++++++++++
grub-core/net/net.c | 41 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/docs/grub.texi b/docs/grub.texi
index 825278a7f..7786ed7eb 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -5597,6 +5597,7 @@ This command is only available on AArch64 systems.
* net_ls_dns:: List DNS servers
* net_ls_routes:: List routing entries
* net_nslookup:: Perform a DNS lookup
+* net_set_vlan:: Set vlan id on an interface
@end menu
@@ -5789,6 +5790,25 @@ is given, use default list of servers.
@end deffn
+@node net_set_vlan
+@subsection net_set_vlan
+
+@deffn Command net_set_vlan @var{interface} @var{vlanid}
+Set the 802.1Q VLAN identifier on @var{interface} to @var{vlanid}. For example,
+to set the VLAN identifier on interface @samp{efinet1} to @samp{100}:
+
+@example
+net_set_vlan efinet1 100
+@end example
+
+The VLAN identifier can be removed by setting it to @samp{0}:
+
+@example
+net_set_vlan efinet1 0
+@end example
+@end deffn
+
+
@node Internationalisation
@chapter Internationalisation
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
index f37f34cb8..0336c343a 100644
--- a/grub-core/net/net.c
+++ b/grub-core/net/net.c
@@ -1266,6 +1266,42 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)),
}
}
+static grub_err_t
+grub_cmd_setvlan (struct grub_command *cmd __attribute__ ((unused)),
+ int argc, char **args)
+{
+ const char *vlan_string, *vlan_string_end;
+ unsigned long vlantag;
+ struct grub_net_network_level_interface *inter;
+
+ if (argc != 2)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
+
+ vlan_string = args[1];
+ vlantag = grub_strtoul (vlan_string, &vlan_string_end, 10);
+
+ if (*vlan_string == '\0' || *vlan_string_end != '\0')
+ return grub_error (GRUB_ERR_BAD_NUMBER,
+ N_("non-numeric or invalid number `%s'"), vlan_string);
+
+ if (vlantag > 4094)
+ return grub_error (GRUB_ERR_OUT_OF_RANGE,
+ N_("vlan id `%s' not in the valid range of 0-4094"),
+ vlan_string);
+
+ FOR_NET_NETWORK_LEVEL_INTERFACES (inter)
+ {
+ if (grub_strcmp (inter->name, args[0]) != 0)
+ continue;
+
+ inter->vlantag = vlantag;
+ return GRUB_ERR_NONE;
+ }
+
+ return grub_error (GRUB_ERR_BAD_ARGUMENT,
+ N_("network interface not found"));
+}
+
static void
print_net_address (const grub_net_network_level_netaddress_t *target)
{
@@ -2057,7 +2093,7 @@ grub_net_search_config_file (char *config)
static struct grub_preboot *fini_hnd;
static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute;
-static grub_command_t cmd_lsroutes, cmd_lscards;
+static grub_command_t cmd_setvlan, cmd_lsroutes, cmd_lscards;
static grub_command_t cmd_lsaddr, cmd_slaac;
#ifdef GRUB_MACHINE_EFI
@@ -2136,6 +2172,9 @@ GRUB_MOD_INIT(net)
cmd_delroute = grub_register_command ("net_del_route", grub_cmd_delroute,
N_("SHORTNAME"),
N_("Delete a network route."));
+ cmd_setvlan = grub_register_command ("net_set_vlan", grub_cmd_setvlan,
+ N_("SHORTNAME VLANID"),
+ N_("Set an interface's vlan id."));
cmd_lsroutes = grub_register_command ("net_ls_routes", grub_cmd_listroutes,
"", N_("list network routes"));
cmd_lscards = grub_register_command ("net_ls_cards", grub_cmd_listcards,
--
2.41.0

View file

@ -0,0 +1,61 @@
From 769786ed748fe4582f3ee2b51233afab16c8be18 Mon Sep 17 00:00:00 2001
From: Chad Kimes <chkimes@github.com>
Date: Mon, 21 Mar 2022 18:07:31 -0400
Subject: [PATCH 335/336] kern/efi/efi: Print VLAN info in EFI device path
Signed-off-by: Chad Kimes <chkimes@github.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
grub-core/kern/efi/efi.c | 7 +++++++
include/grub/efi/api.h | 10 ++++++++++
2 files changed, 17 insertions(+)
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index 4ac2b2754..b9a69d44f 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -872,6 +872,13 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp)
sata->lun);
}
break;
+ case GRUB_EFI_VLAN_DEVICE_PATH_SUBTYPE:
+ {
+ grub_efi_vlan_device_path_t *vlan;
+ vlan = (grub_efi_vlan_device_path_t *) dp;
+ grub_printf ("/Vlan(%u)", vlan->vlan_id);
+ }
+ break;
case GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE:
dump_vendor_path ("Messaging",
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
index 464842ba3..b03f7fae3 100644
--- a/include/grub/efi/api.h
+++ b/include/grub/efi/api.h
@@ -963,6 +963,7 @@ struct grub_efi_uri_device_path
typedef struct grub_efi_uri_device_path grub_efi_uri_device_path_t;
#define GRUB_EFI_DNS_DEVICE_PATH_SUBTYPE 31
+
struct grub_efi_dns_device_path
{
grub_efi_device_path_t header;
@@ -971,6 +972,15 @@ struct grub_efi_dns_device_path
} GRUB_PACKED;
typedef struct grub_efi_dns_device_path grub_efi_dns_device_path_t;
+#define GRUB_EFI_VLAN_DEVICE_PATH_SUBTYPE 20
+
+struct grub_efi_vlan_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint16_t vlan_id;
+} GRUB_PACKED;
+typedef struct grub_efi_vlan_device_path grub_efi_vlan_device_path_t;
+
#define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10
/* Media Device Path. */
--
2.41.0

View file

@ -0,0 +1,71 @@
From 19e65d172c8abe5d0dc9f49cbffa0a85f1a9ed79 Mon Sep 17 00:00:00 2001
From: Chad Kimes <chkimes@github.com>
Date: Mon, 21 Mar 2022 18:07:32 -0400
Subject: [PATCH 336/336] net/drivers/efi/efinet: Configure VLAN from UEFI
device used for PXE
This patch handles automatic configuration of VLAN when booting from PXE
on UEFI hardware.
Signed-off-by: Chad Kimes <chkimes@github.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
grub-core/net/drivers/efi/efinet.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
index 1a24f38a2..8b039a69a 100644
--- a/grub-core/net/drivers/efi/efinet.c
+++ b/grub-core/net/drivers/efi/efinet.c
@@ -734,6 +734,10 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
{
struct grub_net_card *card;
grub_efi_device_path_t *dp, *ldp = NULL;
+ struct grub_net_network_level_interface *inter;
+ grub_efi_device_path_t *vlan_dp;
+ grub_efi_uint16_t vlan_dp_len;
+ grub_efi_vlan_device_path_t *vlan;
dp = grub_efi_get_device_path (hnd);
if (! dp)
@@ -871,7 +875,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
}
}
- grub_net_configure_by_dhcp_ack (card->name, card, 0,
+ inter = grub_net_configure_by_dhcp_ack (card->name, card, 0,
(struct grub_net_bootp_packet *)
&pxe_mode->dhcp_ack,
sizeof (pxe_mode->dhcp_ack),
@@ -882,6 +886,28 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
if (nb)
grub_netbuff_free (nb);
+ if (inter != NULL)
+ {
+ /*
+ * Search the device path for any VLAN subtype and use it
+ * to configure the interface.
+ */
+ vlan_dp = dp;
+
+ while (!GRUB_EFI_END_ENTIRE_DEVICE_PATH (vlan_dp))
+ {
+ if (GRUB_EFI_DEVICE_PATH_TYPE (vlan_dp) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE &&
+ GRUB_EFI_DEVICE_PATH_SUBTYPE (vlan_dp) == GRUB_EFI_VLAN_DEVICE_PATH_SUBTYPE)
+ {
+ vlan = (grub_efi_vlan_device_path_t *) vlan_dp;
+ inter->vlantag = vlan->vlan_id;
+ break;
+ }
+
+ vlan_dp_len = GRUB_EFI_DEVICE_PATH_LENGTH (vlan_dp);
+ vlan_dp = (grub_efi_device_path_t *) ((grub_efi_uint8_t *) vlan_dp + vlan_dp_len);
+ }
+ }
return;
}
}
--
2.41.0

View file

@ -330,3 +330,7 @@ Patch0329: 0329-grub_dl_set_mem_attrs-fix-format-string.patch
Patch0330: 0330-grub_dl_set_mem_attrs-add-self-check-for-the-tramp-G.patch
Patch0331: 0331-grub_dl_load_segments-page-align-the-tramp-GOT-areas.patch
Patch0332: 0332-emu-Add-switch-root-to-grub-emu.patch
Patch0333: 0333-net-net-Add-vlan-information-to-net_ls_addr-output.patch
Patch0334: 0334-net-net-Add-net_set_vlan-command.patch
Patch0335: 0335-kern-efi-efi-Print-VLAN-info-in-EFI-device-path.patch
Patch0336: 0336-net-drivers-efi-efinet-Configure-VLAN-from-UEFI-devi.patch

View file

@ -17,7 +17,7 @@
Name: grub2
Epoch: 1
Version: 2.06
Release: 95%{?dist}
Release: 96%{?dist}
Summary: Bootloader with support for Linux, Multiboot and more
License: GPLv3+
URL: http://www.gnu.org/software/grub/
@ -110,7 +110,7 @@ subpackages.
%package tools
Summary: Support tools for GRUB.
Requires: grub2-common = %{epoch}:%{version}-%{release}
Requires: gettext-runtime os-prober file
Requires: gettext os-prober file
Requires(pre): dracut
Requires(pre): grep
Requires(pre): sed
@ -122,7 +122,7 @@ This subpackage provides tools for support of all platforms.
%ifarch x86_64
%package tools-efi
Summary: Support tools for GRUB.
Requires: gettext-runtime os-prober file
Requires: gettext os-prober file
Requires: grub2-common = %{epoch}:%{version}-%{release}
%description tools-efi
@ -132,7 +132,7 @@ This subpackage provides tools for support of EFI platforms.
%package tools-minimal
Summary: Support tools for GRUB.
Requires: gettext-runtime
Requires: gettext
Requires: grub2-common = %{epoch}:%{version}-%{release}
Obsoletes: grub2-tools < %{evr}
@ -142,7 +142,7 @@ This subpackage provides tools for support of all platforms.
%package tools-extra
Summary: Support tools for GRUB.
Requires: gettext-runtime os-prober file
Requires: gettext os-prober file
Requires: grub2-tools-minimal = %{epoch}:%{version}-%{release}
Requires: grub2-common = %{epoch}:%{version}-%{release}
Requires: mtools
@ -544,6 +544,14 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg
%endif
%changelog
* Thu Aug 10 2023 Simone Caronni <negativo17@gmail.com> - 1:2.06-96
- Add UEFI VLAN patches:
https://git.savannah.gnu.org/cgit/grub.git/commit/?id=98c299e540ec2942c2734c3e56cf586302d3eef0
https://git.savannah.gnu.org/cgit/grub.git/commit/?id=954c48b9c833d64b74ced1f27701af2ea5c6f55a
https://git.savannah.gnu.org/cgit/grub.git/commit/?id=c143056a34b4ccc255a6ad4e96a5aa989d304760
https://git.savannah.gnu.org/cgit/grub.git/commit/?id=9322a7740f7ca48d0b23a231af1c7807d9f7b5dd
- Require gettext and not gettext-runtime so it installs on el9.
* Wed Apr 12 2023 Robbie Harwood <rharwood@redhat.com> - 2.06-95
- Add switch-root support to grub-emu