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.129.124]) by passt.top (Postfix) with ESMTP id C333C5A005E for ; Tue, 13 Dec 2022 23:49:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670971742; 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=2JHGiN1cM31Nl6o6pYayymV03F1Q9gX8FaLDk5XJ4ds=; b=WeGbZPTZsKkWJ1QsqLvy9egZpwHfaM78IooNlt4TZGJ2UsQXWqFOgOaKy5K9k9Zi3g+b/b cPLwMhONFA9uk/PMqRfzUHi5PdWk8mPe8ElWvSjMRoo7qJ+RoXJ8Ur6NiBtg7JB28vanvk Diqzw4v8vrXza+EYDIBsxfL7EIJKPgQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-467-RpUCYyJIM0SyVqpZvE_LaA-1; Tue, 13 Dec 2022 17:49:01 -0500 X-MC-Unique: RpUCYyJIM0SyVqpZvE_LaA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1C7381C09B67; Tue, 13 Dec 2022 22:49:01 +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 D68DE2166B26; Tue, 13 Dec 2022 22:49:00 +0000 (UTC) Date: Tue, 13 Dec 2022 23:48:58 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 6/8] udp: Unify udp_sock_handler_splice() with udp_sock_handler() Message-ID: <20221213234858.474602c1@elisabeth> In-Reply-To: <20221205081425.2614425-7-david@gibson.dropbear.id.au> References: <20221205081425.2614425-1-david@gibson.dropbear.id.au> <20221205081425.2614425-7-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 7FWZGNH5NMD5AK3Q632TCUFX6UYFA5DU X-Message-ID-Hash: 7FWZGNH5NMD5AK3Q632TCUFX6UYFA5DU 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 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. Not that I have in mind a valid example of an error on UDP sockets, except perhaps if the interface goes down (but we'll handle that separately). -- Stefano