From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202504 header.b=JqrYu5Zc; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 63BA35A0271 for ; Tue, 15 Apr 2025 09:16:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202504; t=1744701386; bh=h2a/1okQ8WXOPF75MP64+8OUIJWyeGCurzrU64hilGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JqrYu5ZciWGrJLazkm2z97fL4f+nArB3VbHEbrSGUuMqMBZQY7bp/R+vI9yj98uRM 1G5gEku3Ayw3DTMEjYR8fkfCHdpTb3AmaCBdS+kG3u5BY6h5Jm607Y+xG56DMtr81a lHWodRUB+GoLAmUUDMriiUS/MSUkPBt+8uRTkxTc8zbaYMjYyLwgDKXe6rG94cKkkW 9Wb/OQb4B+hwEUYWIghji8eAWHuz5hIZPkt0yi/VUk3S4H6czaW8rHiFIhiuYbHjDF muVY0UNDNYlKIeUvMa77WF7uYUR9V1L5uBlZzjstNONlsAf7tza3BPGZQGj67albxp AHtkq4OPHei7g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZcFnk5Byvz4xN4; Tue, 15 Apr 2025 17:16:26 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 3/7] udp: Pass socket & flow information direction to error handling functions Date: Tue, 15 Apr 2025 17:16:20 +1000 Message-ID: <20250415071624.2618589-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250415071624.2618589-1-david@gibson.dropbear.id.au> References: <20250415071624.2618589-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: CIWURPKL3RJLEM447VP64TKIWBY3MNTH X-Message-ID-Hash: CIWURPKL3RJLEM447VP64TKIWBY3MNTH 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: Jon Maloy , 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: udp_sock_recverr() and udp_sock_errs() take an epoll reference from which they obtain both the socket fd to receive errors from, and - for flow specific sockets - the flow and side the socket is associated with. We have some upcoming cases where we want to clear errors when we're not directly associated with receiving an epoll event, so it's not natural to have an epoll reference. Therefore, make these functions take the socket and flow from explicit parameters. Signed-off-by: David Gibson --- udp.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/udp.c b/udp.c index 154f99b5..c51ac955 100644 --- a/udp.c +++ b/udp.c @@ -467,14 +467,15 @@ static void udp_send_tap_icmp6(const struct ctx *c, /** * udp_sock_recverr() - Receive and clear an error from a socket * @c: Execution context - * @ref: epoll reference + * @s: Socket to receive errors from + * @sidx: Flow and side of @s, or FLOW_SIDX_NONE if unknown * * Return: 1 if error received and processed, 0 if no more errors in queue, < 0 * if there was an error reading the queue * * #syscalls recvmsg */ -static int udp_sock_recverr(const struct ctx *c, union epoll_ref ref) +static int udp_sock_recverr(const struct ctx *c, int s, flow_sidx_t sidx) { struct errhdr { struct sock_extended_err ee; @@ -484,7 +485,6 @@ static int udp_sock_recverr(const struct ctx *c, union epoll_ref ref) char data[ICMP6_MAX_DLEN]; const struct errhdr *eh; struct cmsghdr *hdr; - int s = ref.fd; struct iovec iov = { .iov_base = data, .iov_len = sizeof(data) @@ -525,12 +525,12 @@ static int udp_sock_recverr(const struct ctx *c, union epoll_ref ref) } eh = (const struct errhdr *)CMSG_DATA(hdr); - if (ref.type == EPOLL_TYPE_UDP) { - flow_sidx_t sidx = flow_sidx_opposite(ref.flowside); - const struct flowside *toside = flowside_at_sidx(sidx); + if (flow_sidx_valid(sidx)) { + flow_sidx_t tosidx = flow_sidx_opposite(sidx); + const struct flowside *toside = flowside_at_sidx(tosidx); size_t dlen = rc; - if (pif_is_socket(pif_at_sidx(sidx))) { + if (pif_is_socket(pif_at_sidx(tosidx))) { /* XXX Is there any way to propagate ICMPs from socket * to socket? */ } else if (hdr->cmsg_level == IPPROTO_IP) { @@ -554,21 +554,21 @@ static int udp_sock_recverr(const struct ctx *c, union epoll_ref ref) /** * udp_sock_errs() - Process errors on a socket * @c: Execution context - * @ref: epoll reference + * @s: Socket to receive errors from + * @sidx: Flow and side of @s, or FLOW_SIDX_NONE if unknown * * Return: Number of errors handled, or < 0 if we have an unrecoverable error */ -static int udp_sock_errs(const struct ctx *c, union epoll_ref ref) +static int udp_sock_errs(const struct ctx *c, int s, flow_sidx_t sidx) { unsigned n_err = 0; socklen_t errlen; - int s = ref.fd; int rc, err; ASSERT(!c->no_udp); /* Empty the error queue */ - while ((rc = udp_sock_recverr(c, ref)) > 0) + while ((rc = udp_sock_recverr(c, s, sidx)) > 0) n_err += rc; if (rc < 0) @@ -777,7 +777,7 @@ void udp_listen_sock_handler(const struct ctx *c, const struct timespec *now) { if (events & EPOLLERR) { - if (udp_sock_errs(c, ref) < 0) { + if (udp_sock_errs(c, ref.fd, FLOW_SIDX_NONE) < 0) { err("UDP: Unrecoverable error on listening socket:" " (%s port %hu)", pif_name(ref.udp.pif), ref.udp.port); /* FIXME: what now? close/re-open socket? */ @@ -804,7 +804,7 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, ASSERT(!c->no_udp && uflow); if (events & EPOLLERR) { - if (udp_sock_errs(c, ref) < 0) { + if (udp_sock_errs(c, ref.fd, ref.flowside) < 0) { flow_err(uflow, "Unrecoverable error on flow socket"); goto fail; } -- 2.49.0