diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2025-03-26 14:44:03 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2025-03-26 21:34:26 +0100 |
commit | d924b7dfc40cfaf9ebc64fe052efd8b0c45c6478 (patch) | |
tree | 7dd2831731c67f3e76d3f72b4e8259d1db68b328 | |
parent | 5a977c2f4ee8926673554b2b456e7791962b2ce2 (diff) | |
download | passt-d924b7dfc40cfaf9ebc64fe052efd8b0c45c6478.tar passt-d924b7dfc40cfaf9ebc64fe052efd8b0c45c6478.tar.gz passt-d924b7dfc40cfaf9ebc64fe052efd8b0c45c6478.tar.bz2 passt-d924b7dfc40cfaf9ebc64fe052efd8b0c45c6478.tar.lz passt-d924b7dfc40cfaf9ebc64fe052efd8b0c45c6478.tar.xz passt-d924b7dfc40cfaf9ebc64fe052efd8b0c45c6478.tar.zst passt-d924b7dfc40cfaf9ebc64fe052efd8b0c45c6478.zip |
udp_vu: Factor things out of udp_vu_reply_sock_data() loop
At the start of every cycle of the loop in udp_vu_reply_sock_data() we:
- ASSERT that uflow is not NULL
- Check if the target pif is PIF_TAP
- Initialize the v6 boolean
However, all of these depend only on the flow, which doesn't change across
the loop. This is probably a duplication from udp_vu_listen_sock_data(),
where the flow can be different for each packet. For the reply socket
case, however, factor that logic out of the loop.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r-- | udp_vu.c | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -281,30 +281,28 @@ void udp_vu_reply_sock_data(const struct ctx *c, union epoll_ref ref, { 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 vu_dev *vdev = c->vdev; struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; + uint8_t topif = pif_at_sidx(tosidx); int i; - for (i = 0; i < UDP_MAX_FRAMES; i++) { - uint8_t topif = pif_at_sidx(tosidx); - ssize_t dlen; - int iov_used; - bool v6; - - ASSERT(uflow); + ASSERT(uflow); - if (topif != PIF_TAP) { - uint8_t frompif = pif_at_sidx(ref.flowside); + 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)); - continue; - } + flow_err(uflow, + "No support for forwarding UDP from %s to %s", + pif_name(frompif), pif_name(topif)); + return; + } - v6 = !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); + 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); if (iov_used <= 0) |