From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 4B8E25A0082 for ; Wed, 14 Dec 2022 11:35:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671014145; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VSXp09PhtxoeM+S/49JHbN8xy0deDOiGHF9o+nUGBqw=; b=RXvk/HEUp6gyBQuq2s2mVpvcRymbb7m2yS7ovrlml59G4RiVtLIQWTE0jepsWkQUCo8MTu T1xBYqap2qsiL/7mzD202k/FDPU6Afg+6SrYQuM5Ln9TRHh6AqVbupzv2LhjSHphc1J98r kO8biR8kj8frYRa3ZvC6ueCndxrEBMY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-NsbqgDw1MSC1tWDSj9d-rg-1; Wed, 14 Dec 2022 05:35:42 -0500 X-MC-Unique: NsbqgDw1MSC1tWDSj9d-rg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6630880234E; Wed, 14 Dec 2022 10:35:42 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-4.brq.redhat.com [10.40.208.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CDE80C15BA0; Wed, 14 Dec 2022 10:35:41 +0000 (UTC) Date: Wed, 14 Dec 2022 11:35:38 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 6/8] udp: Unify udp_sock_handler_splice() with udp_sock_handler() Message-ID: <20221214113538.5776445e@elisabeth> In-Reply-To: References: <20221205081425.2614425-1-david@gibson.dropbear.id.au> <20221205081425.2614425-7-david@gibson.dropbear.id.au> <20221213234858.474602c1@elisabeth> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 6X2F6VLU5XKCWDDLT5CLO6FK3YUDCUY2 X-Message-ID-Hash: 6X2F6VLU5XKCWDDLT5CLO6FK3YUDCUY2 X-MailFrom: sbrivio@redhat.com 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: passt-dev@passt.top 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: On Wed, 14 Dec 2022 12:19:14 +1100 David Gibson wrote: > On Tue, Dec 13, 2022 at 11:48:58PM +0100, Stefano Brivio wrote: > > On Mon, 5 Dec 2022 19:14:23 +1100 > > David Gibson wrote: > > > > > These two functions now have a very similar structure, and their first > > > part (calling recvmmsg()) is functionally identical. So, merge the two > > > functions into one. > > > > > > Signed-off-by: David Gibson > > > --- > > > udp.c | 86 +++++++++++++++++++---------------------------------------- > > > 1 file changed, 28 insertions(+), 58 deletions(-) > > > > > > diff --git a/udp.c b/udp.c > > > index 7c601cc..6ccfe8c 100644 > > > --- a/udp.c > > > +++ b/udp.c > > > @@ -590,52 +590,6 @@ static void udp_splice_sendfrom(const struct ctx *c, unsigned start, unsigned n, > > > sendmmsg(s, mmh_send + start, n, MSG_NOSIGNAL); > > > } > > > > > > -/** > > > - * udp_sock_handler_splice() - Handler for socket mapped to "spliced" connection > > > - * @c: Execution context > > > - * @ref: epoll reference > > > - * @events: epoll events bitmap > > > - * @now: Current timestamp > > > - */ > > > -static void udp_sock_handler_splice(const struct ctx *c, union epoll_ref ref, > > > - uint32_t events, const struct timespec *now) > > > -{ > > > - in_port_t dst = ref.r.p.udp.udp.port; > > > - int v6 = ref.r.p.udp.udp.v6, n, i, m; > > > - struct mmsghdr *mmh_recv; > > > - > > > - if (!(events & EPOLLIN)) > > > - return; > > > - > > > - if (v6) > > > - mmh_recv = udp6_l2_mh_sock; > > > - else > > > - mmh_recv = udp4_l2_mh_sock; > > > - > > > - n = recvmmsg(ref.r.s, mmh_recv, UDP_MAX_FRAMES, 0, NULL); > > > - > > > - if (n <= 0) > > > - return; > > > - > > > - if (v6) > > > - udp_localname6.sin6_port = htons(dst); > > > - else > > > - udp_localname4.sin_port = htons(dst); > > > - > > > - for (i = 0; i < n; i += m) { > > > - in_port_t src = sa_port(v6, mmh_recv[i].msg_hdr.msg_name); > > > - > > > - for (m = 1; i + m < n; m++) { > > > - void *mname = mmh_recv[i + m].msg_hdr.msg_name; > > > - if (sa_port(v6, mname) != src) > > > - break; > > > - } > > > - > > > - udp_splice_sendfrom(c, i, m, src, dst, v6, ref.r.p.udp.udp.ns, > > > - ref.r.p.udp.udp.orig, now); > > > - } > > > -} > > > - > > > /** > > > * udp_update_hdr4() - Update headers for one IPv4 datagram > > > * @c: Execution context > > > @@ -945,27 +899,43 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, > > > { > > > in_port_t dstport = ref.r.p.udp.udp.port; > > > bool v6 = ref.r.p.udp.udp.v6; > > > - struct mmsghdr *sock_mmh; > > > + struct mmsghdr *mmh_recv; > > > + unsigned int i, m; > > > ssize_t n; > > > > > > - if (events == EPOLLERR) > > > + if (!(events & EPOLLIN)) > > > > Pre-existing, unrelated issue, but this reminds me: we don't handle > > socket errors here, and while udp_timer_one() will drop any sockets we > > created, eventually, it would probably be better to act right away. > > Ok... I'm not sure what, if anything, you would like me to do about > it, however. No no, sorry, nothing, I wanted to share in case you happen to touch this again soon, or if you had thoughts about it. I can fix this separately once you're done with changes for UDP. -- Stefano