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 E32635A027C for ; Mon, 29 Apr 2024 09:09:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1714374575; bh=/xKUgdO4MkyGcQIZsPqnDmF10pspRMv1vRx1aKBEsH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XU5NYk92OyEmJlsoBf6+cIAzZoGFdr1KlIh5Co/q/PiYEGsOpYcIXebjBamT42jSx S/NsKOHfttvYLtYnItYQ3LUSU4oF0pv38tCW5txR5S7ydBk48FA+sRmtXtGT0z4B4T u3lo4slT8OI1TkAcVUHYyF27A1dXVfpbF36iJdNk7c+xvzXSroZHuvLkQHArVa7vAg /ZtEP2EzwDBZBx4pFn1lqxhR7JlfsjvmnEkBFn08QSIkvTJ7RatWGwBjM/30HG0/o9 ZIdFcg3RG7Y3vSlaNeyo+weohXwrlQyXpFgZGKSurlIpI89Mgb6S5K7K956KsWpRez gw0C0wL8Fe9JA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4VSZFq54g0z4x1N; Mon, 29 Apr 2024 17:09:35 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/7] tap: Split tap specific and L2 (ethernet) headers Date: Mon, 29 Apr 2024 17:09:28 +1000 Message-ID: <20240429070933.1366881-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240429070933.1366881-1-david@gibson.dropbear.id.au> References: <20240429070933.1366881-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: BDYGQHXLWOVWAFH3HGIWNFJNCEJOCAQQ X-Message-ID-Hash: BDYGQHXLWOVWAFH3HGIWNFJNCEJOCAQQ 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: Laurent Vivier , David Gibson X-Mailman-Version: 3.3.8 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: In some places (well, actually only UDP now) we use struct tap_hdr to represent both tap backend specific and L2 ethernet headers. Handling these together seemed like a good idea at the time, but Laurent's changes in the TCP code working towards vhost-user support suggest that treating them separately is more useful, more often. Alter struct tap_hdr to represent only the TAP backend specific headers. Updated related helpers and the UDP code to match. Signed-off-by: David Gibson --- tap.h | 21 +++++++++------------ udp.c | 23 ++++++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/tap.h b/tap.h index 2adc4e2b..dbc23b31 100644 --- a/tap.h +++ b/tap.h @@ -6,30 +6,28 @@ #ifndef TAP_H #define TAP_H +#define ETH_HDR_INIT(proto) { .h_proto = htons_constant(proto) } + /** - * struct tap_hdr - L2 and tap specific headers + * struct tap_hdr - tap backend specific headers * @vnet_len: Frame length (for qemu socket transport) - * @eh: Ethernet header */ struct tap_hdr { uint32_t vnet_len; - struct ethhdr eh; } __attribute__((packed)); -#define TAP_HDR_INIT(proto) { .eh.h_proto = htons_constant(proto) } - static inline size_t tap_hdr_len_(const struct ctx *c) { if (c->mode == MODE_PASST) return sizeof(struct tap_hdr); else - return sizeof(struct ethhdr); + return 0; } /** * tap_frame_base() - Find start of tap frame * @c: Execution context - * @taph: Pointer to L2 and tap specific header buffer + * @taph: Pointer to tap specific header buffer * * Returns: pointer to the start of tap frame - suitable for an * iov_base to be passed to tap_send_frames()) @@ -43,17 +41,16 @@ static inline void *tap_frame_base(const struct ctx *c, struct tap_hdr *taph) * tap_frame_len() - Finalize tap frame and return total length * @c: Execution context * @taph: Tap header to finalize - * @plen: L3 packet length (excludes L2 and tap specific headers) + * @plen: L2 packet length (includes L2, excludes tap specific headers) * - * Returns: length of the tap frame including L2 and tap specific - * headers - suitable for an iov_len to be passed to - * tap_send_frames() + * Returns: length of the tap frame including tap specific headers - suitable + * for an iov_len to be passed to tap_send_frames() */ static inline size_t tap_frame_len(const struct ctx *c, struct tap_hdr *taph, size_t plen) { if (c->mode == MODE_PASST) - taph->vnet_len = htonl(plen + sizeof(taph->eh)); + taph->vnet_len = htonl(plen); return plen + tap_hdr_len_(c); } diff --git a/udp.c b/udp.c index 594ea191..c3e4f6b6 100644 --- a/udp.c +++ b/udp.c @@ -173,7 +173,8 @@ static uint8_t udp_act[IP_VERSIONS][UDP_ACT_TYPE_MAX][DIV_ROUND_UP(NUM_PORTS, 8) /** * udp4_l2_buf_t - Pre-cooked IPv4 packet buffers for tap connections * @s_in: Source socket address, filled in by recvmmsg() - * @taph: Tap-level headers (partially pre-filled) + * @taph: Tap backend specific header + * @eh: Prefilled ethernet header * @iph: Pre-filled IP header (except for tot_len and saddr) * @uh: Headroom for UDP header * @data: Storage for UDP payload @@ -182,6 +183,7 @@ static struct udp4_l2_buf_t { struct sockaddr_in s_in; struct tap_hdr taph; + struct ethhdr eh; struct iphdr iph; struct udphdr uh; uint8_t data[USHRT_MAX - @@ -192,7 +194,8 @@ udp4_l2_buf[UDP_MAX_FRAMES]; /** * udp6_l2_buf_t - Pre-cooked IPv6 packet buffers for tap connections * @s_in6: Source socket address, filled in by recvmmsg() - * @taph: Tap-level headers (partially pre-filled) + * @taph: Tap backend specific header + * @eh: Pre-filled ethernet header * @ip6h: Pre-filled IP header (except for payload_len and addresses) * @uh: Headroom for UDP header * @data: Storage for UDP payload @@ -202,10 +205,11 @@ struct udp6_l2_buf_t { #ifdef __AVX2__ /* Align ip6h to 32-byte boundary. */ uint8_t pad[64 - (sizeof(struct sockaddr_in6) + sizeof(struct ethhdr) + - sizeof(uint32_t))]; + sizeof(struct tap_hdr))]; #endif struct tap_hdr taph; + struct ethhdr eh; struct ipv6hdr ip6h; struct udphdr uh; uint8_t data[USHRT_MAX - @@ -289,8 +293,8 @@ void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s) struct udp4_l2_buf_t *b4 = &udp4_l2_buf[i]; struct udp6_l2_buf_t *b6 = &udp6_l2_buf[i]; - eth_update_mac(&b4->taph.eh, eth_d, eth_s); - eth_update_mac(&b6->taph.eh, eth_d, eth_s); + eth_update_mac(&b4->eh, eth_d, eth_s); + eth_update_mac(&b6->eh, eth_d, eth_s); } } @@ -307,7 +311,7 @@ static void udp_sock4_iov_init_one(const struct ctx *c, size_t i) struct iovec *tiov = &udp4_l2_iov_tap[i]; *buf = (struct udp4_l2_buf_t) { - .taph = TAP_HDR_INIT(ETH_P_IP), + .eh = ETH_HDR_INIT(ETH_P_IP), .iph = L2_BUF_IP4_INIT(IPPROTO_UDP) }; @@ -335,7 +339,7 @@ static void udp_sock6_iov_init_one(const struct ctx *c, size_t i) struct iovec *tiov = &udp6_l2_iov_tap[i]; *buf = (struct udp6_l2_buf_t) { - .taph = TAP_HDR_INIT(ETH_P_IPV6), + .eh = ETH_HDR_INIT(ETH_P_IPV6), .ip6h = L2_BUF_IP6_INIT(IPPROTO_UDP) }; @@ -608,7 +612,7 @@ static size_t udp_update_hdr4(const struct ctx *c, struct udp4_l2_buf_t *b, b->uh.dest = htons(dstport); b->uh.len = htons(datalen + sizeof(b->uh)); - return tap_frame_len(c, &b->taph, ip_len); + return tap_frame_len(c, &b->taph, ip_len + sizeof(b->eh)); } /** @@ -676,7 +680,8 @@ static size_t udp_update_hdr6(const struct ctx *c, struct udp6_l2_buf_t *b, b->uh.len = b->ip6h.payload_len; csum_udp6(&b->uh, src, dst, b->data, datalen); - return tap_frame_len(c, &b->taph, payload_len + sizeof(b->ip6h)); + return tap_frame_len(c, &b->taph, payload_len + sizeof(b->ip6h) + + sizeof(b->eh)); } /** -- 2.44.0