All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix vlan networking on little-endian systems
@ 2022-03-01 16:18 Chad Kimes
  2022-03-02 18:39 ` Daniel Kiper
  0 siblings, 1 reply; 4+ messages in thread
From: Chad Kimes @ 2022-03-01 16:18 UTC (permalink / raw)
  To: grub-devel; +Cc: Chad Kimes

Vlan configuration seems to have never worked on little-endian systems. This is
likely because VLANTAG_IDENTIFIER is not byte-swapped before copying into the
net buffer, nor is vlantag. We can resolve this by using grub_cpu_to_be16 and
its inverse when copying vlan info to/from the net buffer.
---
 grub-core/net/ethernet.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c
index 4d7ceed6f..e49ccc940 100644
--- a/grub-core/net/ethernet.c
+++ b/grub-core/net/ethernet.c
@@ -58,7 +58,7 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
   struct etherhdr *eth;
   grub_err_t err;
   grub_uint8_t etherhdr_size;
-  grub_uint16_t vlantag_id = VLANTAG_IDENTIFIER;
+  grub_uint16_t vlantag_id = grub_cpu_to_be16 (VLANTAG_IDENTIFIER);
 
   etherhdr_size = sizeof (*eth);
   COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE);
@@ -93,8 +93,9 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
                    (char *) nb->data + etherhdr_size - 6, 2);
 
       /* Add the tag in the middle */
+      grub_uint16_t vlan = grub_cpu_to_be16 (inf->vlantag);
       grub_memcpy ((char *) nb->data + etherhdr_size - 6, &vlantag_id, 2);
-      grub_memcpy ((char *) nb->data + etherhdr_size - 4, (char *) &(inf->vlantag), 2);
+      grub_memcpy ((char *) nb->data + etherhdr_size - 4, &vlan, 2);
     }
 
   return inf->card->driver->send (inf->card, nb);
@@ -118,9 +119,9 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb,
   /* 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. */
-  if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == VLANTAG_IDENTIFIER)
+  if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == grub_cpu_to_be16 (VLANTAG_IDENTIFIER))
     {
-      vlantag = grub_get_unaligned16 (nb->data + etherhdr_size);
+      vlantag = grub_be_to_cpu16 (grub_get_unaligned16 (nb->data + etherhdr_size));
       etherhdr_size += 4;
       /* Move eth type to the original position */
       grub_memcpy((char *) nb->data + etherhdr_size - 6,
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] Fix vlan networking on little-endian systems
@ 2022-03-01 14:03 Chad Kimes
  2022-03-01 14:42 ` John Paul Adrian Glaubitz
  0 siblings, 1 reply; 4+ messages in thread
From: Chad Kimes @ 2022-03-01 14:03 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 2218 bytes --]

The interface vlantag appears to have never worked on little-endian
systems. This small initial patch is mostly to get my feet wet in the GRUB
dev process. Once this is accepted, I intend to submit a few more patches
that (a) allow vlan configuration via a command from the net module and (b)
auto-configure vlan from the UEFI device used for PXE booting.


diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c
index 4d7ceed6f..e49ccc940 100644
--- a/grub-core/net/ethernet.c
+++ b/grub-core/net/ethernet.c
@@ -58,7 +58,7 @@ send_ethernet_packet (struct
grub_net_network_level_interface *inf,
   struct etherhdr *eth;
   grub_err_t err;
   grub_uint8_t etherhdr_size;
-  grub_uint16_t vlantag_id = VLANTAG_IDENTIFIER;
+  grub_uint16_t vlantag_id = grub_cpu_to_be16 (VLANTAG_IDENTIFIER);

   etherhdr_size = sizeof (*eth);
   COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE);
@@ -93,8 +93,9 @@ send_ethernet_packet (struct
grub_net_network_level_interface *inf,
                    (char *) nb->data + etherhdr_size - 6, 2);

       /* Add the tag in the middle */
+      grub_uint16_t vlantag = grub_cpu_to_be16 (inf->vlantag);
       grub_memcpy ((char *) nb->data + etherhdr_size - 6, &vlantag_id, 2);
-      grub_memcpy ((char *) nb->data + etherhdr_size - 4, (char *)
&(inf->vlantag), 2);
+      grub_memcpy ((char *) nb->data + etherhdr_size - 4, &vlantag, 2);
     }

   return inf->card->driver->send (inf->card, nb);
@@ -118,9 +119,9 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb,
   /* 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. */
-  if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) ==
VLANTAG_IDENTIFIER)
+  if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) ==
grub_cpu_to_be16 (VLANTAG_IDENTIFIER))
     {
-      vlantag = grub_get_unaligned16 (nb->data + etherhdr_size);
+      vlantag = grub_be_to_cpu16 (grub_get_unaligned16 (nb->data +
etherhdr_size));
       etherhdr_size += 4;
       /* Move eth type to the original position */
       grub_memcpy((char *) nb->data + etherhdr_size - 6,

[-- Attachment #2: Type: text/html, Size: 2521 bytes --]

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

end of thread, other threads:[~2022-03-02 18:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-01 16:18 [PATCH] Fix vlan networking on little-endian systems Chad Kimes
2022-03-02 18:39 ` Daniel Kiper
  -- strict thread matches above, loose matches on Subject: below --
2022-03-01 14:03 Chad Kimes
2022-03-01 14:42 ` John Paul Adrian Glaubitz

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.