From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id C84225A031A for ; Fri, 05 Jul 2024 12:44:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1720176251; bh=JI7HlEOwsfi+sbcOS5T4VfqjhJOpS4kZAD4gzzwAu+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mKOqre7LKbdaNT37fDjzAKjpdnHYKxA8EivMoF9MgQoa0PXJ1icft074+c7CkoDhE mH2KeneMF2JaZaPFaGwt2kJ4tV/URJavlCeT6PlYmg1PLdHkaykCTzA6gcysbSpJAO /3G9CIS4vms0Woga3FtUozaLTRA8WyoTSB0F6v9lBCx3wrQSfPxz++MTIh7XEIB7Mj 4SlVCWvDwhZDEUGS0bzjCiOPBI4m0smaU3CenO75eH5HQQNnZDmfWZHWmA7PyklpXC xUvcYMWIkytbxeyl3NBe5I5RiZSpGqeUR1G69QAiFV2l8zTtoIG4FLkMELwYdXFma/ QYL6YoQf6k8Ug== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WFqrW70Lyz4x0C; Fri, 5 Jul 2024 20:44:11 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 05/11] udp: Unify udp[46]_mh_splice Date: Fri, 5 Jul 2024 20:44:03 +1000 Message-ID: <20240705104409.3847002-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240705104409.3847002-1-david@gibson.dropbear.id.au> References: <20240705104409.3847002-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: OT3CNZMZUHMMQ7M3PRPWAKHG2FT4QOUJ X-Message-ID-Hash: OT3CNZMZUHMMQ7M3PRPWAKHG2FT4QOUJ 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: We have separate mmsghdr arrays for splicing IPv4 and IPv6 packets, where the only difference is that they point to different sockaddr buffers for the destination address. Unify these by having the common array point at a sockaddr_inany as the address. This does mean slightly more work when we're about to splice, because we need to write the whole socket address, rather than just the port. However it removes 32 mmsghdr structures and we're going to need more flexibility constructing that target address for the flow table. Because future changes might mean that the address isn't always loopback, change the name of the common address from *_localname to udp_splicename. Signed-off-by: David Gibson --- udp.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/udp.c b/udp.c index 43ed6435..2d34f6ac 100644 --- a/udp.c +++ b/udp.c @@ -235,18 +235,10 @@ static struct mmsghdr udp4_mh_recv [UDP_MAX_FRAMES]; static struct mmsghdr udp6_mh_recv [UDP_MAX_FRAMES]; /* IOVs and msghdr arrays for sending "spliced" datagrams to sockets */ -static struct sockaddr_in udp4_splice_to = { - .sin_family = AF_INET, - .sin_addr = IN4ADDR_LOOPBACK_INIT, -}; -static struct sockaddr_in6 udp6_splice_to = { - .sin6_family = AF_INET6, - .sin6_addr = IN6ADDR_LOOPBACK_INIT, -}; +static union sockaddr_inany udp_splice_to; static struct iovec udp_iov_splice [UDP_MAX_FRAMES]; -static struct mmsghdr udp4_mh_splice [UDP_MAX_FRAMES]; -static struct mmsghdr udp6_mh_splice [UDP_MAX_FRAMES]; +static struct mmsghdr udp_mh_splice [UDP_MAX_FRAMES]; /* IOVs for L2 frames */ static struct iovec udp4_l2_iov [UDP_MAX_FRAMES][UDP_NUM_IOVS]; @@ -523,7 +515,7 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n, const struct timespec *now) { in_port_t src = udp_meta[start].splicesrc; - struct mmsghdr *mmh_recv, *mmh_send; + struct mmsghdr *mmh_recv; unsigned int i = start; int s; @@ -532,16 +524,22 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n, if (ref.udp.v6) { mmh_recv = udp6_mh_recv; - mmh_send = udp6_mh_splice; - udp6_splice_to.sin6_port = htons(dst); + udp_splice_to.sa6 = (struct sockaddr_in6) { + .sin6_family = AF_INET6, + .sin6_addr = in6addr_loopback, + .sin6_port = htons(dst), + }; } else { mmh_recv = udp4_mh_recv; - mmh_send = udp4_mh_splice; - udp4_splice_to.sin_port = htons(dst); + udp_splice_to.sa4 = (struct sockaddr_in) { + .sin_family = AF_INET, + .sin_addr = in4addr_loopback, + .sin_port = htons(dst), + }; } do { - mmh_send[i].msg_hdr.msg_iov->iov_len = mmh_recv[i].msg_len; + udp_mh_splice[i].msg_hdr.msg_iov->iov_len = mmh_recv[i].msg_len; if (++i >= n) break; @@ -579,7 +577,7 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n, udp_splice_ns[ref.udp.v6][src].ts = now->tv_sec; } - sendmmsg(s, mmh_send + start, i - start, MSG_NOSIGNAL); + sendmmsg(s, udp_mh_splice + start, i - start, MSG_NOSIGNAL); out: return i - start; } @@ -1094,20 +1092,15 @@ static void udp_splice_iov_init(void) int i; for (i = 0; i < UDP_MAX_FRAMES; i++) { - struct msghdr *mh4 = &udp4_mh_splice[i].msg_hdr; - struct msghdr *mh6 = &udp6_mh_splice[i].msg_hdr; - - mh4->msg_name = &udp4_splice_to; - mh4->msg_namelen = sizeof(udp4_splice_to); + struct msghdr *mh = &udp_mh_splice[i].msg_hdr; - mh6->msg_name = &udp6_splice_to; - mh6->msg_namelen = sizeof(udp6_splice_to); + mh->msg_name = &udp_splice_to; + mh->msg_namelen = sizeof(udp_splice_to); udp_iov_splice[i].iov_base = udp_payload[i].data; - mh4->msg_iov = &udp_iov_splice[i]; - mh6->msg_iov = &udp_iov_splice[i]; - mh4->msg_iovlen = mh6->msg_iovlen = 1; + mh->msg_iov = &udp_iov_splice[i]; + mh->msg_iovlen = 1; } } -- 2.45.2