From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nPUY2-0000pd-ND for mharc-grub-devel@gnu.org; Wed, 02 Mar 2022 14:22:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPUXu-0000mk-FO for grub-devel@gnu.org; Wed, 02 Mar 2022 14:21:59 -0500 Received: from [2607:f8b0:4864:20::f36] (port=33444 helo=mail-qv1-xf36.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nPUXq-0002UT-Pv for grub-devel@gnu.org; Wed, 02 Mar 2022 14:21:57 -0500 Received: by mail-qv1-xf36.google.com with SMTP id f4so1966052qvd.0 for ; Wed, 02 Mar 2022 11:21:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=github.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7SHdCmy7wzZ9aH4LpNzNChnokMRry0fnXz5A0b76c5g=; b=S4iUsS6iLYA42SXDU8MOcblh1VLlfmDI7zokhvNccsy7+wN73KZ6yAaAD1bRF7eUn4 CTeDjZdzEwgV1mIFALbQKRxyKm4IfmL0YL4Wr3b4GRdbpKiifG7SmI+M750q/3Obrrde f5SQN/Ti+xuWcwEDEDScvUVZmfkVGXMTjRasPOceEB2MloSuA1GVw+jXtZzoE9tN6CVA lEAmMkP32msCq4Z08g11SlxDcPRrazPLwkfhKUXwy3OQhrjhGq84hUgHwyOxhTev20hq 3UTpyddCZcZcLH7kL5k9gGvD+px6o/Zr/E1gfurxxMSPnmID9CVjzDHk9s+HwPk/9VDQ IkIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7SHdCmy7wzZ9aH4LpNzNChnokMRry0fnXz5A0b76c5g=; b=TkA/e33J2uLpwlCFgbI/KBtqhgg+3Xht2HyiJuLElkfAne0Oddyh0ITSnV1mOmmiDW jrswOz0fDA6HqA5l0tk3xi8WJyBgjjX0IO3CUln3wy8TvRnPCka23dQ5NhG1yIf7Fz5P eQ60enaN5Rv3t1UmDRRS0ObRmpLj57xm8O54uqwn5RcOg21dWKPsBn94is3/tyIh3/+J T5I+sdk80tA1v1+pnLXxZFFcaU/kmX+JB4IqY2x+pExnpGsFX8Ti3iTj7z7pG5sJQ1ue EEcEDXKnVrnBXM6HPqJSyE5iOhijprfdTO6taB3eg6c8Nvch13HRT7YHf8G3z3MM1Kth Q7Og== X-Gm-Message-State: AOAM533N2xqX9NsIMrBi3OjtC02DK05WIywyH/HaOxpdyw6QHxs2cZP5 25eWo2ekWPOCoc59vRiurj0mxn6jka/4Gn3oA25B5g4GMiRiFOWNRyM5ORAo7AaA3q/PfRk+Hdc 6+opXQzZ8fDNauf1jQ88/jQcGo8ko9LJy4CTwnR7Deh68duXE6nH/aXFfvAkV0Q== X-Google-Smtp-Source: ABdhPJyoZK4P3b1IGDqXnLpw8O6RpTxfUEX1m5ChujYcM+wR/FhhKWyyrUx2B/85738wG6goN1DYdg== X-Received: by 2002:a05:6214:c8f:b0:433:2afd:78e with SMTP id r15-20020a0562140c8f00b004332afd078emr10254453qvr.27.1646248913000; Wed, 02 Mar 2022 11:21:53 -0800 (PST) Received: from a-Virtual-Machine.mshome.net ([136.56.89.57]) by smtp.gmail.com with ESMTPSA id w1-20020a05620a094100b00648e56836ffsm8186181qkw.82.2022.03.02.11.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 11:21:52 -0800 (PST) From: Chad Kimes To: grub-devel@gnu.org Cc: Chad Kimes Subject: [PATCH v2] Fix vlan networking on little-endian systems Date: Wed, 2 Mar 2022 14:21:22 -0500 Message-Id: <20220302192122.263829-1-chkimes@github.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::f36 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::f36; envelope-from=chkimes@github.com; helo=mail-qv1-xf36.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Mar 2022 19:22:03 -0000 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. Signed-off-by: Chad Kimes --- 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..a9906338c 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_compile_time (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_compile_time (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