diff options
| author | David Gibson <david@gibson.dropbear.id.au> | 2026-01-08 13:14:50 +1100 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-01-10 20:54:13 +0100 |
| commit | 9ea9dde5b5f64562d5fb0385dfee967a8cfec0f3 (patch) | |
| tree | 613dd84c13e75282e808e738fe7f26dcba2345b4 | |
| parent | 3b55ba88ead03263e4139eb85493d6f59789d80a (diff) | |
| download | passt-9ea9dde5b5f64562d5fb0385dfee967a8cfec0f3.tar passt-9ea9dde5b5f64562d5fb0385dfee967a8cfec0f3.tar.gz passt-9ea9dde5b5f64562d5fb0385dfee967a8cfec0f3.tar.bz2 passt-9ea9dde5b5f64562d5fb0385dfee967a8cfec0f3.tar.lz passt-9ea9dde5b5f64562d5fb0385dfee967a8cfec0f3.tar.xz passt-9ea9dde5b5f64562d5fb0385dfee967a8cfec0f3.tar.zst passt-9ea9dde5b5f64562d5fb0385dfee967a8cfec0f3.zip | |
fwd, tcp, udp: Consolidate epoll refs for listening sockets
The epoll references we use for TCP listening sockets and UDP "listening"
sockets have identical information. Combine them into a single structure.
Note that, despite the name, epoll_ref.udp was only ever used for
"listening" sockets, not flow sockets.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | epoll_ctl.h | 6 | ||||
| -rw-r--r-- | fwd.h | 13 | ||||
| -rw-r--r-- | tcp.c | 8 | ||||
| -rw-r--r-- | tcp.h | 14 | ||||
| -rw-r--r-- | udp.c | 6 | ||||
| -rw-r--r-- | udp.h | 15 |
6 files changed, 22 insertions, 40 deletions
diff --git a/epoll_ctl.h b/epoll_ctl.h index 02b081e..3f802e7 100644 --- a/epoll_ctl.h +++ b/epoll_ctl.h @@ -21,8 +21,7 @@ * @fd: File descriptor number (implies < 2^24 total descriptors) * @flow: Index of the flow this fd is linked to * @flowside: Index and side of a flow this fd is linked to - * @tcp_listen: TCP-specific reference part for listening sockets - * @udp: UDP-specific reference part + * @listen: Information for listening sockets * @data: Data handled by protocol handlers * @nsdir_fd: netns dirfd for fallback timer checking if namespace is gone * @queue: vhost-user queue index for this fd @@ -35,8 +34,7 @@ union epoll_ref { union { uint32_t flow; flow_sidx_t flowside; - union tcp_listen_epoll_ref tcp_listen; - union udp_listen_epoll_ref udp; + union fwd_listen_ref listen; uint32_t data; int nsdir_fd; int queue; @@ -16,6 +16,19 @@ struct flowside; void fwd_probe_ephemeral(void); bool fwd_port_is_ephemeral(in_port_t port); +/** + * union fwd_listen_ref - information about a single listening socket + * @port: Bound port number of the socket + * @pif: pif in which the socket is listening + */ +union fwd_listen_ref { + struct { + in_port_t port; + uint8_t pif; + }; + uint32_t u32; +}; + enum fwd_ports_mode { FWD_UNSET = 0, FWD_SPEC = 1, @@ -2485,8 +2485,8 @@ void tcp_listen_handler(const struct ctx *c, union epoll_ref ref, * address, record that as our address, as implemented for vhost-user * mode only, below. */ - ini = flow_initiate_sa(flow, ref.tcp_listen.pif, &sa, - NULL, ref.tcp_listen.port); + ini = flow_initiate_sa(flow, ref.listen.pif, &sa, + NULL, ref.listen.port); if (getsockname(s, &sa.sa, &sl) || inany_from_sockaddr(&ini->oaddr, &ini->oport, &sa) < 0) @@ -2685,7 +2685,7 @@ void tcp_sock_handler(const struct ctx *c, union epoll_ref ref, int tcp_listen(const struct ctx *c, uint8_t pif, const union inany_addr *addr, const char *ifname, in_port_t port) { - union tcp_listen_epoll_ref tref = { + union fwd_listen_ref ref = { .port = port, .pif = pif, }; @@ -2722,7 +2722,7 @@ int tcp_listen(const struct ctx *c, uint8_t pif, } s = pif_sock_l4(c, EPOLL_TYPE_TCP_LISTEN, pif, addr, ifname, - port, tref.u32); + port, ref.u32); if (fwd->mode == FWD_AUTO) { if (!addr || inany_v4(addr)) @@ -31,20 +31,6 @@ void tcp_update_l2_buf(const unsigned char *eth_d); extern bool peek_offset_cap; /** - * union tcp_listen_epoll_ref - epoll reference portion for TCP listening - * @port: Bound port number of the socket - * @pif: pif in which the socket is listening - * @u32: Opaque u32 value of reference - */ -union tcp_listen_epoll_ref { - struct { - in_port_t port; - uint8_t pif; - }; - uint32_t u32; -}; - -/** * struct tcp_ctx - Execution context for TCP routines * @port_to_tap: Ports bound host-side, packets to tap or spliced * @fwd_in: Port forwarding configuration for inbound packets @@ -928,7 +928,7 @@ void udp_listen_sock_handler(const struct ctx *c, const struct timespec *now) { if (events & (EPOLLERR | EPOLLIN)) - udp_sock_fwd(c, ref.fd, ref.udp.pif, ref.udp.port, now); + udp_sock_fwd(c, ref.fd, ref.listen.pif, ref.listen.port, now); } /** @@ -1141,7 +1141,7 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, int udp_listen(const struct ctx *c, uint8_t pif, const union inany_addr *addr, const char *ifname, in_port_t port) { - union udp_listen_epoll_ref uref = { + union fwd_listen_ref ref = { .pif = pif, .port = port, }; @@ -1175,7 +1175,7 @@ int udp_listen(const struct ctx *c, uint8_t pif, } s = pif_sock_l4(c, EPOLL_TYPE_UDP_LISTEN, pif, - addr, ifname, port, uref.u32); + addr, ifname, port, ref.u32); if (!addr || inany_v4(addr)) socks[V4][port] = s < 0 ? -1 : s; @@ -23,21 +23,6 @@ void udp_port_rebind_all(struct ctx *c); void udp_update_l2_buf(const unsigned char *eth_d); /** - * union udp_listen_epoll_ref - epoll reference for "listening" UDP sockets - * @port: Source port for connected sockets, bound port otherwise - * @pif: pif for this socket - * @u32: Opaque u32 value of reference - */ -union udp_listen_epoll_ref { - struct { - in_port_t port; - uint8_t pif; - }; - uint32_t u32; -}; - - -/** * struct udp_ctx - Execution context for UDP * @fwd_in: Port forwarding configuration for inbound packets * @fwd_out: Port forwarding configuration for outbound packets |
