From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id BE50C5A005E for ; Fri, 9 Dec 2022 06:42:42 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NT0KM3NVxz4xvS; Fri, 9 Dec 2022 16:42:31 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1670564551; bh=W+PM5ahdjQBI/m8Oj0RXcTw3/tTdKXPqgJzA0ip5da0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g3tDXrfRu4KeWNJqtN6zMHNYQLblfitdeUr4NAIAAXiCBxFyITSvCt+I8qlhwNbnx 2cHagyiVpp6kEx19QN/XNqgF7qgwKsrZCH77ggBCOlYHuayiWC8mAIbX8dFwIrd/BL ixvldPdyAecpFz5/ufjyQXVIIJvQfTFspwr3w5GA= From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 10/18] util: Parameterize ethernet header initializer macro Date: Fri, 9 Dec 2022 16:42:20 +1100 Message-Id: <20221209054228.4085990-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221209054228.4085990-1-david@gibson.dropbear.id.au> References: <20221209054228.4085990-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: MG4ET7YSV2RTXOO373KODGRIBBOUOI3I X-Message-ID-Hash: MG4ET7YSV2RTXOO373KODGRIBBOUOI3I X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: We have separate IPv4 and IPv6 versions of a macro to construct an initializer for ethernet headers. However, now that we have htons_constant it's easy to simply paramterize this with the ethernet protocol number. Signed-off-by: David Gibson --- tcp.c | 8 ++++---- udp.c | 4 ++-- util.h | 11 ++--------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/tcp.c b/tcp.c index 79fc733..b30e8e6 100644 --- a/tcp.c +++ b/tcp.c @@ -1059,7 +1059,7 @@ static void tcp_sock4_iov_init(void) for (i = 0; i < ARRAY_SIZE(tcp4_l2_buf); i++) { tcp4_l2_buf[i] = (struct tcp4_l2_buf_t) { - .eh = L2_BUF_ETH_IP4_INIT, + .eh = L2_BUF_ETH_INIT(ETH_P_IP), .iph = L2_BUF_IP4_INIT(IPPROTO_TCP), .th = { .doff = sizeof(struct tcphdr) / 4, .ack = 1 } }; @@ -1067,7 +1067,7 @@ static void tcp_sock4_iov_init(void) for (i = 0; i < ARRAY_SIZE(tcp4_l2_flags_buf); i++) { tcp4_l2_flags_buf[i] = (struct tcp4_l2_flags_buf_t) { - .eh = L2_BUF_ETH_IP4_INIT, + .eh = L2_BUF_ETH_INIT(ETH_P_IP), .iph = L2_BUF_IP4_INIT(IPPROTO_TCP) }; } @@ -1091,7 +1091,7 @@ static void tcp_sock6_iov_init(void) for (i = 0; i < ARRAY_SIZE(tcp6_l2_buf); i++) { tcp6_l2_buf[i] = (struct tcp6_l2_buf_t) { - .eh = L2_BUF_ETH_IP6_INIT, + .eh = L2_BUF_ETH_INIT(ETH_P_IPV6), .ip6h = L2_BUF_IP6_INIT(IPPROTO_TCP), .th = { .doff = sizeof(struct tcphdr) / 4, .ack = 1 } }; @@ -1099,7 +1099,7 @@ static void tcp_sock6_iov_init(void) for (i = 0; i < ARRAY_SIZE(tcp6_l2_flags_buf); i++) { tcp6_l2_flags_buf[i] = (struct tcp6_l2_flags_buf_t) { - .eh = L2_BUF_ETH_IP6_INIT, + .eh = L2_BUF_ETH_INIT(ETH_P_IPV6), .ip6h = L2_BUF_IP6_INIT(IPPROTO_TCP) }; } diff --git a/udp.c b/udp.c index ffedca1..5609836 100644 --- a/udp.c +++ b/udp.c @@ -329,7 +329,7 @@ static void udp_sock4_iov_init(const struct ctx *c) for (i = 0; i < ARRAY_SIZE(udp4_l2_buf); i++) { udp4_l2_buf[i] = (struct udp4_l2_buf_t) { - .eh = L2_BUF_ETH_IP4_INIT, + .eh = L2_BUF_ETH_INIT(ETH_P_IP), .iph = L2_BUF_IP4_INIT(IPPROTO_UDP) }; } @@ -370,7 +370,7 @@ static void udp_sock6_iov_init(const struct ctx *c) for (i = 0; i < ARRAY_SIZE(udp6_l2_buf); i++) { udp6_l2_buf[i] = (struct udp6_l2_buf_t) { - .eh = L2_BUF_ETH_IP6_INIT, + .eh = L2_BUF_ETH_INIT(ETH_P_IPV6), .ip6h = L2_BUF_IP6_INIT(IPPROTO_UDP) }; } diff --git a/util.h b/util.h index b4c139d..b5be7a6 100644 --- a/util.h +++ b/util.h @@ -102,18 +102,11 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags, (void *)(arg)); \ } while (0) -#define L2_BUF_ETH_IP4_INIT \ +#define L2_BUF_ETH_INIT(proto) \ { \ .h_dest = { 0 }, \ .h_source = { 0 }, \ - .h_proto = htons_constant(ETH_P_IP), \ - } - -#define L2_BUF_ETH_IP6_INIT \ - { \ - .h_dest = { 0 }, \ - .h_source = { 0 }, \ - .h_proto = htons_constant(ETH_P_IPV6), \ + .h_proto = htons_constant(proto), \ } #define L2_BUF_IP4_INIT(proto) \ -- 2.38.1