aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2025-04-04 21:15:40 +1100
committerStefano Brivio <sbrivio@redhat.com>2025-04-07 21:43:53 +0200
commitbd6a41ee76bb9a0da2150d76dbabf9a3212d0fca (patch)
treec4dafd75fc6fa935da5d0b5f9d2014519c9dcd1f
parent159beefa36a09fc36cc9669fd536926d84c7c342 (diff)
downloadpasst-bd6a41ee76bb9a0da2150d76dbabf9a3212d0fca.tar
passt-bd6a41ee76bb9a0da2150d76dbabf9a3212d0fca.tar.gz
passt-bd6a41ee76bb9a0da2150d76dbabf9a3212d0fca.tar.bz2
passt-bd6a41ee76bb9a0da2150d76dbabf9a3212d0fca.tar.lz
passt-bd6a41ee76bb9a0da2150d76dbabf9a3212d0fca.tar.xz
passt-bd6a41ee76bb9a0da2150d76dbabf9a3212d0fca.tar.zst
passt-bd6a41ee76bb9a0da2150d76dbabf9a3212d0fca.zip
udp: Rework udp_listen_sock_data() into udp_sock_fwd()
udp_listen_sock_data() forwards datagrams from a "listening" socket until there are no more (for now). We have an upcoming use case where we want to do that for a socket that's not a "listening" socket, and uses a different epoll reference. So, adjust the function to take the pieces it needs from the reference as direct parameters and rename to udp_sock_fwd(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--udp.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/udp.c b/udp.c
index 157697e..20d8f0c 100644
--- a/udp.c
+++ b/udp.c
@@ -716,37 +716,36 @@ static void udp_buf_sock_to_tap(const struct ctx *c, int s, int n,
}
/**
- * udp_listen_sock_data() - Handle new data from listening socket
+ * udp_sock_fwd() - Forward datagrams from a possibly unconnected socket
* @c: Execution context
- * @ref: epoll reference
+ * @s: Socket to forward from
+ * @frompif: Interface to which @s belongs
+ * @port: Our (local) port number of @s
* @now: Current timestamp
*/
-static void udp_listen_sock_data(const struct ctx *c, union epoll_ref ref,
- const struct timespec *now)
+static void udp_sock_fwd(const struct ctx *c, int s, uint8_t frompif,
+ in_port_t port, const struct timespec *now)
{
union sockaddr_inany src;
- while (udp_peek_addr(ref.fd, &src) == 0) {
- flow_sidx_t tosidx = udp_flow_from_sock(c, ref.udp.pif,
- ref.udp.port, &src,
- now);
+ while (udp_peek_addr(s, &src) == 0) {
+ flow_sidx_t tosidx = udp_flow_from_sock(c, frompif, port,
+ &src, now);
uint8_t topif = pif_at_sidx(tosidx);
if (pif_is_socket(topif)) {
- udp_sock_to_sock(c, ref.fd, 1, tosidx);
+ udp_sock_to_sock(c, s, 1, tosidx);
} else if (topif == PIF_TAP) {
if (c->mode == MODE_VU)
- udp_vu_sock_to_tap(c, ref.fd, 1, tosidx);
+ udp_vu_sock_to_tap(c, s, 1, tosidx);
else
- udp_buf_sock_to_tap(c, ref.fd, 1, tosidx);
+ udp_buf_sock_to_tap(c, s, 1, tosidx);
} else if (flow_sidx_valid(tosidx)) {
- flow_sidx_t fromsidx = flow_sidx_opposite(tosidx);
struct udp_flow *uflow = udp_at_sidx(tosidx);
flow_err(uflow,
"No support for forwarding UDP from %s to %s",
- pif_name(pif_at_sidx(fromsidx)),
- pif_name(topif));
+ pif_name(frompif), pif_name(topif));
} else {
debug("Discarding datagram without flow");
}
@@ -774,7 +773,7 @@ void udp_listen_sock_handler(const struct ctx *c,
}
if (events & EPOLLIN)
- udp_listen_sock_data(c, ref, now);
+ udp_sock_fwd(c, ref.fd, ref.udp.pif, ref.udp.port, now);
}
/**