From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nP5DK-0004KF-G7 for mharc-grub-devel@gnu.org; Tue, 01 Mar 2022 11:19:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nP5DI-0004Jq-KW for grub-devel@gnu.org; Tue, 01 Mar 2022 11:19:00 -0500 Received: from [2607:f8b0:4864:20::f30] (port=35343 helo=mail-qv1-xf30.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nP5DG-0001Ot-IF for grub-devel@gnu.org; Tue, 01 Mar 2022 11:18:59 -0500 Received: by mail-qv1-xf30.google.com with SMTP id 8so17036236qvf.2 for ; Tue, 01 Mar 2022 08:18:58 -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=ZagsP2iPdkVBtH2NHpLrNN27GxWg1OV89l8lxfy1p+k=; b=Tj3CERnGkGMMbdPQpYG37NawkTNZiTFFnC/dUIstBhaOtMRjRrmTf4Xq461wWD6szL vbQ7yFGC6y6vn6IR6HZiOvz3kjKXCgdttY4G4p3LQOb1X3zfg1fecyk7eaiHQ0klOY7Z k/M+hgkcpCjugMnZPYJuMKaTxhpB48q8QtqChfP+mUG5nAuA1pyxfXIvJAt4yqB0twy+ dbvXGMuJf1O1LtfgVBe6B/9/2VLSRp8uQTXUydDlJfdSHCovL+0oFbQ48df5fCOghUoX gN8rYwWkCKzYXZC3S8N4DPq98/Pf/+sYcgXYDXbbWLC4jVjo0czgpO++OUkXvNjU/sSA t9uw== 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=ZagsP2iPdkVBtH2NHpLrNN27GxWg1OV89l8lxfy1p+k=; b=vVI4NdYu4CLvtdTf+XLGlvClxSP2rjko+yj6v3fwzf1EaqB1+GjXpjTZBGj/kzC+Ir gxUWvk6YZPE4nKh8+OHDB3TgWQAn6gTLzCOeYiNhEsSkIDumxUkKWsnmGG3gpha3XAFs Tkk1u1pMkcj7ac2FWun8PPo9cWK1ShcG7BEV8v9hlJBWSgAMgG/CI+ftLE/uFqXne1A0 ofFlpg93Wi1918C2xfgYJ3c5XS2ff55MxJQB73s06uv1igqEdIr1uDSkqCX1nwLrA4DK vmXO7IbcqeE4ciE7nNF3z+7aKG9hKjbr2SEEQRT1rArvPhV/N/fHaZhSeQV/3pdKwIoI ZQjQ== X-Gm-Message-State: AOAM530bCr1g3d74kmbjaTcZYi3LDtYmVewBRSs/Op73NcqVTQF5nHda QOznx1fSiaZHsREoInCLxqvDrpnemKgUyFvYoHBIDV85IM2JFjDqp3XaJOQeTP9Sg9P5ihTn6js xILVv+l92mo8jR1CM9mywJiZ4Ilf1tfFCEViMaTimpBpjtSRhYgDKclm1ynBTVA== X-Google-Smtp-Source: ABdhPJzoXkTf76P1m4uDFQ+CJuvCS/lrr5iuQ2TzTC6bF3XigTbpfwygm4FiNBLctBj0P0mGC3/1IA== X-Received: by 2002:a0c:80c5:0:b0:42c:3efa:2ed with SMTP id 63-20020a0c80c5000000b0042c3efa02edmr17776681qvb.106.1646151537323; Tue, 01 Mar 2022 08:18:57 -0800 (PST) Received: from a-Virtual-Machine.mshome.net ([136.56.89.57]) by smtp.gmail.com with ESMTPSA id f15-20020ac86ecf000000b002d58a639121sm8760464qtv.97.2022.03.01.08.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Mar 2022 08:18:56 -0800 (PST) From: Chad Kimes To: grub-devel@gnu.org Cc: Chad Kimes Subject: [PATCH] Fix vlan networking on little-endian systems Date: Tue, 1 Mar 2022 11:18:52 -0500 Message-Id: <20220301161852.248546-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::f30 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::f30; envelope-from=chkimes@github.com; helo=mail-qv1-xf30.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: Tue, 01 Mar 2022 16:19:00 -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. --- 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