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 1F7585A0278 for ; Thu, 29 Feb 2024 09:42:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709196173; bh=NAJUP29sEQIwRpBJqX8cTqg3dS9kcZ6Uo6uX05IuVbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FloJR3nGZyxvrqwIHadL7G822UoD11mmLFwYfYse0DJpmGoTZSwICMBLgox6Myxx0 WBJXoaSnPR9dwr7bblo3I/iExpJY/Ejnq1Ap19G4POItnTGAbSV6Mx1et5PqlpiqBr 71gEFFsev/s2CZVZO1vhVEjEgKI1WlpcmMYjDHI/tOMv2ynRUT0YNbDJOCof76ZVIo eqZlijtOK12vG4IHZMyKF6FTAacPQnHwEnspEyd/tTq/dTxZ0I+txsjhdeJNOLH5Kl jaHzdnLywBPPqxS792TS3l9adfiPaXJiO/de0gwRz2wfuq1MnyacdyYeGdYr2qj15I RkGMF+I0vB4Yw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Tll991ykKz4wyk; Thu, 29 Feb 2024 19:42:53 +1100 (AEDT) From: David Gibson To: Stefano Brivio , Laurent Vivier , passt-dev@passt.top Subject: [PATCH 2/6] udp: Tweak interface to udp_update_hdr[46] Date: Thu, 29 Feb 2024 19:42:46 +1100 Message-ID: <20240229084250.3202450-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240229084250.3202450-1-david@gibson.dropbear.id.au> References: <20240229084250.3202450-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: GLCTTPMHWO34SYCLRAVBDKKYL4BZILS6 X-Message-ID-Hash: GLCTTPMHWO34SYCLRAVBDKKYL4BZILS6 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.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: These functions take an index to the L2 buffer whose header information to update. They use that for two things: to locate the buffer pointer itself, and to retrieve the length of the received message from the paralllel udp[46]_l2_mh_sock array. The latter is arguably a failure to separate concerns. Change these functions to explicitly take a buffer pointer and payload length as parameters. Signed-off-by: David Gibson --- udp.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/udp.c b/udp.c index 092d343e..e3c51bae 100644 --- a/udp.c +++ b/udp.c @@ -576,28 +576,24 @@ static void udp_splice_sendfrom(const struct ctx *c, unsigned start, unsigned n, /** * udp_update_hdr4() - Update headers for one IPv4 datagram * @c: Execution context - * @n: Index of buffer in udp4_l2_buf pool + * @b: Pointer to udp4_l2_buf to update * @dstport: Destination port number + * @datalen: Length of UDP payload * @now: Current timestamp * * Return: size of tap frame with headers */ -static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport, +static size_t udp_update_hdr4(const struct ctx *c, struct udp4_l2_buf_t *b, + in_port_t dstport, size_t datalen, const struct timespec *now) { - struct udp4_l2_buf_t *b = &udp4_l2_buf[n]; - struct in_addr *src; - in_port_t src_port; - size_t ip_len; - - ip_len = udp4_l2_mh_sock[n].msg_len + sizeof(b->iph) + sizeof(b->uh); + size_t ip_len = datalen + sizeof(b->iph) + sizeof(b->uh); + in_port_t src_port = ntohs(b->s_in.sin_port); + struct in_addr *src = &b->s_in.sin_addr; b->iph.tot_len = htons(ip_len); b->iph.daddr = c->ip4.addr_seen.s_addr; - src = &b->s_in.sin_addr; - src_port = ntohs(b->s_in.sin_port); - if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_match) && IN4_ARE_ADDR_EQUAL(src, &c->ip4.dns_host) && src_port == 53) { b->iph.saddr = c->ip4.dns_match.s_addr; @@ -620,7 +616,7 @@ static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport, udp_update_check4(b); b->uh.source = b->s_in.sin_port; b->uh.dest = htons(dstport); - b->uh.len = htons(udp4_l2_mh_sock[n].msg_len + sizeof(b->uh)); + b->uh.len = htons(datalen + sizeof(b->uh)); return tap_iov_len(c, &b->taph, ip_len); } @@ -628,26 +624,22 @@ static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport, /** * udp_update_hdr6() - Update headers for one IPv6 datagram * @c: Execution context - * @n: Index of buffer in udp6_l2_buf pool + * @b: Pointer to udp6_l2_buf to update * @dstport: Destination port number + * @datalen: Length of UDP payload * @now: Current timestamp * * Return: size of tap frame with headers */ -static size_t udp_update_hdr6(const struct ctx *c, int n, in_port_t dstport, +static size_t udp_update_hdr6(const struct ctx *c, struct udp6_l2_buf_t *b, + in_port_t dstport, size_t datalen, const struct timespec *now) { - struct udp6_l2_buf_t *b = &udp6_l2_buf[n]; - struct in6_addr *src; - in_port_t src_port; - size_t ip_len; - - src = &b->s_in6.sin6_addr; - src_port = ntohs(b->s_in6.sin6_port); - - ip_len = udp6_l2_mh_sock[n].msg_len + sizeof(b->ip6h) + sizeof(b->uh); + size_t ip_len = datalen + sizeof(b->ip6h) + sizeof(b->uh); + in_port_t src_port = ntohs(b->s_in6.sin6_port); + struct in6_addr *src = &b->s_in6.sin6_addr; - b->ip6h.payload_len = htons(udp6_l2_mh_sock[n].msg_len + sizeof(b->uh)); + b->ip6h.payload_len = htons(datalen + sizeof(b->uh)); if (IN6_IS_ADDR_LINKLOCAL(src)) { b->ip6h.daddr = c->ip6.addr_ll_seen; @@ -727,9 +719,11 @@ static void udp_tap_send(const struct ctx *c, size_t buf_len; if (v6) - buf_len = udp_update_hdr6(c, i, dstport, now); + buf_len = udp_update_hdr6(c, &udp6_l2_buf[i], dstport, + udp6_l2_mh_sock[i].msg_len, now); else - buf_len = udp_update_hdr4(c, i, dstport, now); + buf_len = udp_update_hdr4(c, &udp4_l2_buf[i], dstport, + udp4_l2_mh_sock[i].msg_len, now); tap_iov[i].iov_len = buf_len; } -- 2.44.0