All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Automatically configure VLAN from PXE on UEFI
@ 2022-03-21 22:07 Chad Kimes
  2022-03-21 22:07 ` [PATCH v2 1/2] Print VLAN info in EFI device path Chad Kimes
  2022-03-21 22:07 ` [PATCH v2 2/2] Configure VLAN from UEFI device used for PXE Chad Kimes
  0 siblings, 2 replies; 4+ messages in thread
From: Chad Kimes @ 2022-03-21 22:07 UTC (permalink / raw)
  To: grub-devel; +Cc: Chad Kimes

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(-)

-- 
2.25.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] Print VLAN info in EFI device path
  2022-03-21 22:07 [PATCH v2 0/2] Automatically configure VLAN from PXE on UEFI Chad Kimes
@ 2022-03-21 22:07 ` Chad Kimes
  2022-03-21 22:07 ` [PATCH v2 2/2] Configure VLAN from UEFI device used for PXE Chad Kimes
  1 sibling, 0 replies; 4+ messages in thread
From: Chad Kimes @ 2022-03-21 22:07 UTC (permalink / raw)
  To: grub-devel; +Cc: Chad Kimes

Signed-off-by: Chad Kimes <chkimes@github.com>
---
 grub-core/kern/efi/efi.c | 7 +++++++
 include/grub/efi/api.h   | 9 +++++++++
 2 files changed, 16 insertions(+)

diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index 18858c327..d60a0b3e6 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -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",
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
index 6c8d06e15..b8ec19aab 100644
--- a/include/grub/efi/api.h
+++ b/include/grub/efi/api.h
@@ -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.  */
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] Configure VLAN from UEFI device used for PXE
  2022-03-21 22:07 [PATCH v2 0/2] Automatically configure VLAN from PXE on UEFI Chad Kimes
  2022-03-21 22:07 ` [PATCH v2 1/2] Print VLAN info in EFI device path Chad Kimes
@ 2022-03-21 22:07 ` Chad Kimes
  2022-04-14 16:04   ` Daniel Kiper
  1 sibling, 1 reply; 4+ messages in thread
From: Chad Kimes @ 2022-03-21 22:07 UTC (permalink / raw)
  To: grub-devel; +Cc: Chad Kimes

Signed-off-by: Chad Kimes <chkimes@github.com>
---
 grub-core/net/drivers/efi/efinet.c | 38 ++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
index 381c138db..107e1f09e 100644
--- a/grub-core/net/drivers/efi/efinet.c
+++ b/grub-core/net/drivers/efi/efinet.c
@@ -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;
   }
 }
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 2/2] Configure VLAN from UEFI device used for PXE
  2022-03-21 22:07 ` [PATCH v2 2/2] Configure VLAN from UEFI device used for PXE Chad Kimes
@ 2022-04-14 16:04   ` Daniel Kiper
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Kiper @ 2022-04-14 16:04 UTC (permalink / raw)
  To: Chad Kimes; +Cc: grub-devel

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.

> Signed-off-by: Chad Kimes <chkimes@github.com>
> ---
>  grub-core/net/drivers/efi/efinet.c | 38 ++++++++++++++++++++++++++----
>  1 file changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
> index 381c138db..107e1f09e 100644
> --- a/grub-core/net/drivers/efi/efinet.c
> +++ b/grub-core/net/drivers/efi/efinet.c
> @@ -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)

I prefer "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 *) ((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 <daniel.kiper@oracle.com>

Thank you for adding this feature!

Daniel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-14 16:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-21 22:07 [PATCH v2 0/2] Automatically configure VLAN from PXE on UEFI Chad Kimes
2022-03-21 22:07 ` [PATCH v2 1/2] Print VLAN info in EFI device path Chad Kimes
2022-03-21 22:07 ` [PATCH v2 2/2] Configure VLAN from UEFI device used for PXE Chad Kimes
2022-04-14 16:04   ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.