From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 545CC45B2A; Sun, 13 Oct 2024 10:36:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D610840273; Sun, 13 Oct 2024 10:36:01 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 06CA840151 for ; Sun, 13 Oct 2024 10:36:00 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id C554E207A3 for ; Sun, 13 Oct 2024 10:36:00 +0200 (CEST) Received: from dkrd4.smartsharesys.local ([192.168.4.26]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Sun, 13 Oct 2024 10:36:00 +0200 From: =?UTF-8?q?Morten=20Br=C3=B8rup?= To: dev@dpdk.org Cc: =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH] net: improve vlan header type alignment Date: Sun, 13 Oct 2024 08:35:54 +0000 Message-ID: <20241013083554.97489-1-mb@smartsharesystems.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 13 Oct 2024 08:36:00.0576 (UTC) FILETIME=[EE9F3C00:01DB1D4A] X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Ethernet packets can be VLAN tagged, i.e. an Ethernet header can have a VLAN tag (a.k.a. VLAN header) embedded. Since the Ethernet header is 2 byte aligned, and the VLAN tag is directly related to the Ethernet header, the VLAN tag is also 2 byte aligned, so packing the VLAN tag structure is not necessary. Furthermore, the Ethernet header type is implictly 2 byte aligned, so removed the superfluous explicit 2 byte alignment. Added static_asserts to verify the size and alignment of the various Ethernet types. Signed-off-by: Morten Brørup --- lib/net/rte_ether.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h index 403e84f50b..c9a0b536c3 100644 --- a/lib/net/rte_ether.h +++ b/lib/net/rte_ether.h @@ -11,6 +11,8 @@ * Ethernet Helpers in RTE */ +#include +#include #include #include @@ -75,6 +77,11 @@ struct __rte_aligned(2) rte_ether_addr { uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */ }; +static_assert(sizeof(struct rte_ether_addr) == 6, + "sizeof(struct rte_ether_addr) == 6"); +static_assert(alignof(struct rte_ether_addr) == 2, + "alignof(struct rte_ether_addr) == 2"); + #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */ #define RTE_ETHER_GROUP_ADDR 0x01 /**< Multicast or broadcast Eth. address. */ @@ -290,12 +297,17 @@ rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr); * Ethernet header: Contains the destination address, source address * and frame type. */ -struct __rte_aligned(2) rte_ether_hdr { +struct rte_ether_hdr { struct rte_ether_addr dst_addr; /**< Destination address. */ struct rte_ether_addr src_addr; /**< Source address. */ rte_be16_t ether_type; /**< Frame type. */ }; +static_assert(sizeof(struct rte_ether_hdr) == 14, + "sizeof(struct rte_ether_hdr) == 14"); +static_assert(alignof(struct rte_ether_hdr) == 2, + "alignof(struct rte_ether_hdr) == 2"); + /** * Ethernet VLAN Header. * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type @@ -304,7 +316,12 @@ struct __rte_aligned(2) rte_ether_hdr { struct rte_vlan_hdr { rte_be16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */ rte_be16_t eth_proto; /**< Ethernet type of encapsulated frame. */ -} __rte_packed; +}; + +static_assert(sizeof(struct rte_vlan_hdr) == 4, + "sizeof(struct rte_vlan_hdr) == 4"); +static_assert(alignof(struct rte_vlan_hdr) == 2, + "alignof(struct rte_vlan_hdr) == 2"); -- 2.43.0