Automatically configure VLAN from PXE on UEFI
v2 cover Automatically configure VLAN from PXE on UEFI
This patch series introduces automatic configuration of 802.1Q VLAN identifiers if the interface used for PXE booting on UEFI hardware was configured with a VLAN.
The first patch adds the necessary types for parsing VLAN info from UEFI device paths, and uses that to produce a Vlan(x) device in the grub_efi_print_device_path output.
The second patch handles automatic configuration of VLAN when booting from PXE on UEFI hardware. This patch depends on types introduced in the first patch.
Chad Kimes (2):
Print VLAN info in EFI device path
Configure VLAN from UEFI device used for PXE
grub-core/kern/efi/efi.c | 7 ++++++ grub-core/net/drivers/efi/efinet.c | 38 ++++++++++++++++++++++++++---- include/grub/efi/api.h | 9 +++++++ 3 files changed, 49 insertions(+), 5 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 Print VLAN info in EFI device path
--- grub-core/kern/efi/efi.c | 7 +++++++ include/grub/efi/api.h | 9 +++++++++ 2 files changed, 16 insertions(+)
grub-core/kern/efi/efi.c +7 -0
@@ -832,6 +832,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",
include/grub/efi/api.h +9 -0
@@ -903,6 +903,15 @@ struct grub_efi_sata_device_path }GRUB_PACKED ;typedef struct grub_efi_sata_device_path grub_efi_sata_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. */
Signature · 1 line
2.25.1
PATCH v2 2/2 Configure VLAN from UEFI device used for PXE
In reply to Chad Kimes--- grub-core/net/drivers/efi/efinet.c | 38 ++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-)
grub-core/net/drivers/efi/efinet.c +33 -5
@@ -339,6 +339,10 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, {struct grub_net_card *card;grub_efi_device_path_t *dp; +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)
@@ -387,11 +391,35 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,if (! pxe)continue ; pxe_mode = pxe->mode; -grub_net_configure_by_dhcp_ack (card->name, card,0 , - (struct grub_net_bootp_packet *) - &pxe_mode->dhcp_ack, -sizeof (pxe_mode->dhcp_ack), -1 , device, path); + + 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), +1 , device, path); + +if (inter) + { +/* +* 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 *) ((char *) vlan_dp + vlan_dp_len); + } + }return ; } }
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] Configure VLAN from UEFI device used for PXE
On Mon, Mar 21, 2022 at 06:07:32PM -0400, Chad Kimes via Grub-devel wrote:
I would prefer if you copy some text from the cover letter here.
Quoted 27 lines
Signed-off-by Chad Kimes <[email protected]>--- grub-core/net/drivers/efi/efinet.c | 38 ++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-)grub-core/net/drivers/efi/efinet.c +4
-3@@ -339,6 +339,10 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, {struct grub_net_card *card;grub_efi_device_path_t *dp; +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)@@ -387,11 +391,35 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,if (! pxe)continue ; pxe_mode = pxe->mode; - grub_net_configure_by_dhcp_ack (card->name, card, 0, - (struct grub_net_bootp_packet *) - &pxe_mode->dhcp_ack,
grub-core/net/drivers/efi/efinet.c grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, · line 401
Quoted 10 lines
grub-core/net/drivers/efi/efinet.c +8
-2-sizeof (pxe_mode->dhcp_ack), - 1, device, path); + + 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), +1 , device, path); + +if (inter)
I prefer "if (inter != NULL)".
Quoted 9 lines
grub-core/net/drivers/efi/efinet.c +9
-0+ { +/* +* 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)) + {
grub-core/net/drivers/efi/efinet.c grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, · line 420
Quoted 10 lines
grub-core/net/drivers/efi/efinet.c +10
-0+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 *) ((char *) vlan_dp + vlan_dp_len);
s/char */grub_uint8_t */ even if that translates to almost the same type. Simply I think grub_uint8_t is more natural here.
Anyway, I will fix all these minor issues this time for you.
So, Reviewed-by: Daniel Kiper <[email protected]>
Thank you for adding this feature!
Daniel