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=202502 header.b=JuNpIUQO; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 36D825A0276 for ; Tue, 25 Mar 2025 04:00:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1742871612; bh=3aW/+u7kDu13NvsCXbyrXgysJLIlbA98+w2Bdog9LQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JuNpIUQO9Adr0HgMRZjNyaMTWZmkG2zlH6WzVUoY84f5FJ8ie81EKca3y1FbrHkSI K/qDY+qkLr9eX1xvZGbDoDlTcJ7Uf77j8MHVdctsPQQ9y0JmARw4XYcaNORtsHzYyw UomiWhzGQQL2AOzAKSShtdrwwRnZZsqZePYh7xsKcJi2RGVxcq48WrPLDIpdCevKHN XOzjyPVxVkgudnkM/TtIYqNc5nxMfWDGN9/dCzv6Hfw5DdlrYYdH4y7GFeXoMkiJvf uK31lnCeLkFAGEhrcefz9QOmew3EXWyidGLew82zRavChJPoPDY8TKaNIwuIruKVjd VYkm7yfaqssAw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZMF5m40qlz4xM5; Tue, 25 Mar 2025 14:00:12 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 4/4] udp: Share more logic between vu and non-vu reply socket paths Date: Tue, 25 Mar 2025 14:00:10 +1100 Message-ID: <20250325030010.970144-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250325030010.970144-1-david@gibson.dropbear.id.au> References: <20250325030010.970144-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: GAIM2GYBLZAD43NVZOQ2BKHZIF2SW4XR X-Message-ID-Hash: GAIM2GYBLZAD43NVZOQ2BKHZIF2SW4XR 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: Share some additional miscellaneous logic between the vhost-user and "buf" paths for data on udp reply sockets. The biggest piece is error handling of cases where we can't forward between the two pifs of the flow. We also make common some more simple logic locating the correct flow and its parameters. This adds some lines of code due to extra comment lines, but nonetheless reduces logic duplication. Signed-off-by: David Gibson --- udp.c | 41 ++++++++++++++++++++++++++--------------- udp_vu.c | 26 +++++++++++--------------- udp_vu.h | 3 ++- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/udp.c b/udp.c index 26a91c9c..f417cea1 100644 --- a/udp.c +++ b/udp.c @@ -752,24 +752,25 @@ void udp_listen_sock_handler(const struct ctx *c, /** * udp_buf_reply_sock_data() - Handle new data from flow specific socket * @c: Execution context - * @ref: epoll reference + * @s: Socket to read data from + * @tosidx: Flow & side to forward data from @s to * @now: Current timestamp * + * Return: true on success, false if can't forward from socket to flow's pif + * * #syscalls recvmmsg */ -static void udp_buf_reply_sock_data(const struct ctx *c, union epoll_ref ref, +static bool udp_buf_reply_sock_data(const struct ctx *c, + int s, flow_sidx_t tosidx, const struct timespec *now) { - flow_sidx_t tosidx = flow_sidx_opposite(ref.flowside); const struct flowside *toside = flowside_at_sidx(tosidx); - struct udp_flow *uflow = udp_at_sidx(ref.flowside); + struct udp_flow *uflow = udp_at_sidx(tosidx); uint8_t topif = pif_at_sidx(tosidx); - int n, i, from_s; - - from_s = uflow->s[ref.flowside.sidei]; + int n, i; - if ((n = udp_sock_recv(c, from_s, udp_mh_recv)) <= 0) - return; + if ((n = udp_sock_recv(c, s, udp_mh_recv)) <= 0) + return true; flow_trace(uflow, "Received %d datagrams on reply socket", n); uflow->ts = now->tv_sec; @@ -788,11 +789,10 @@ static void udp_buf_reply_sock_data(const struct ctx *c, union epoll_ref ref, } else if (topif == PIF_TAP) { tap_send_frames(c, &udp_l2_iov[0][0], UDP_NUM_IOVS, n); } else { - uint8_t frompif = pif_at_sidx(ref.flowside); - - flow_err(uflow, "No support for forwarding UDP from %s to %s", - pif_name(frompif), pif_name(topif)); + return false; } + + return true; } /** @@ -819,10 +819,21 @@ void udp_reply_sock_handler(const struct ctx *c, union epoll_ref ref, } if (events & EPOLLIN) { + flow_sidx_t tosidx = flow_sidx_opposite(ref.flowside); + int s = ref.fd; + bool ret; + if (c->mode == MODE_VU) - udp_vu_reply_sock_data(c, ref, now); + ret = udp_vu_reply_sock_data(c, s, tosidx, now); else - udp_buf_reply_sock_data(c, ref, now); + ret = udp_buf_reply_sock_data(c, s, tosidx, now); + + if (!ret) { + flow_err(uflow, + "No support for forwarding UDP from %s to %s", + pif_name(pif_at_sidx(ref.flowside)), + pif_name(pif_at_sidx(tosidx))); + } } } diff --git a/udp_vu.c b/udp_vu.c index 6e1823a9..06bdeae6 100644 --- a/udp_vu.c +++ b/udp_vu.c @@ -273,38 +273,32 @@ void udp_vu_listen_sock_data(const struct ctx *c, union epoll_ref ref, /** * udp_vu_reply_sock_data() - Handle new data from flow specific socket * @c: Execution context - * @ref: epoll reference + * @s: Socket to read data from + * @tosidx: Flow & side to forward data from @s to * @now: Current timestamp + * + * Return: true on success, false if can't forward from socket to flow's pif */ -void udp_vu_reply_sock_data(const struct ctx *c, union epoll_ref ref, +bool udp_vu_reply_sock_data(const struct ctx *c, int s, flow_sidx_t tosidx, const struct timespec *now) { - flow_sidx_t tosidx = flow_sidx_opposite(ref.flowside); const struct flowside *toside = flowside_at_sidx(tosidx); bool v6 = !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); - struct udp_flow *uflow = udp_at_sidx(ref.flowside); - int from_s = uflow->s[ref.flowside.sidei]; + struct udp_flow *uflow = udp_at_sidx(tosidx); struct vu_dev *vdev = c->vdev; struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; - uint8_t topif = pif_at_sidx(tosidx); int i; ASSERT(uflow); - if (topif != PIF_TAP) { - uint8_t frompif = pif_at_sidx(ref.flowside); - - flow_err(uflow, - "No support for forwarding UDP from %s to %s", - pif_name(frompif), pif_name(topif)); - return; - } + if (pif_at_sidx(tosidx) != PIF_TAP) + return false; for (i = 0; i < UDP_MAX_FRAMES; i++) { ssize_t dlen; int iov_used; - iov_used = udp_vu_sock_recv(c, from_s, v6, &dlen); + iov_used = udp_vu_sock_recv(c, s, v6, &dlen); if (iov_used <= 0) break; flow_trace(uflow, "Received 1 datagram on reply socket"); @@ -318,4 +312,6 @@ void udp_vu_reply_sock_data(const struct ctx *c, union epoll_ref ref, } vu_flush(vdev, vq, elem, iov_used); } + + return true; } diff --git a/udp_vu.h b/udp_vu.h index 4f2262d0..2299b51f 100644 --- a/udp_vu.h +++ b/udp_vu.h @@ -8,6 +8,7 @@ void udp_vu_listen_sock_data(const struct ctx *c, union epoll_ref ref, const struct timespec *now); -void udp_vu_reply_sock_data(const struct ctx *c, union epoll_ref ref, +bool udp_vu_reply_sock_data(const struct ctx *c, int s, flow_sidx_t tosidx, const struct timespec *now); + #endif /* UDP_VU_H */ -- 2.49.0