aboutgitcodebugslistschat
path: root/util.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-04-30 14:52:18 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-04-30 14:52:18 +0200
commite07f539ae0aa3ad623c4e8afcaca26906fd1eb17 (patch)
tree869fc954471b65f6659ca87d9068fd9143e87674 /util.c
parent605af213c5e0fa047f6d8caef5bcef61a0987c8d (diff)
downloadpasst-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.gz
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.bz2
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.lz
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.xz
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.zst
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.zip
udp, passt: Introduce socket packet buffer, avoid getsockname() for UDP
This is in preparation for scatter-gather IO on the UDP receive path: save a getsockname() syscall by setting a flag if we get the numbering of all bound sockets in a strict sequence (expected, in practice) and repurpose the tap buffer to be also a socket receive buffer, passing it down to protocol handlers. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.c')
-rw-r--r--util.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/util.c b/util.c
index c48f2f6..9ccd9f6 100644
--- a/util.c
+++ b/util.c
@@ -189,11 +189,6 @@ int sock_l4(struct ctx *c, int af, uint16_t proto, uint16_t port)
return -1;
}
- CHECK_SET_MIN_MAX_PROTO_FD(proto, IPPROTO_ICMP, icmp, fd);
- CHECK_SET_MIN_MAX_PROTO_FD(proto, IPPROTO_ICMPV6, icmp, fd);
- CHECK_SET_MIN_MAX_PROTO_FD(proto, IPPROTO_TCP, tcp, fd);
- CHECK_SET_MIN_MAX_PROTO_FD(proto, IPPROTO_UDP, udp, fd);
-
if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6)
goto epoll_add;
@@ -207,16 +202,29 @@ int sock_l4(struct ctx *c, int af, uint16_t proto, uint16_t port)
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one));
}
+ CHECK_SET_MIN_MAX_PROTO_FD(proto, IPPROTO_ICMP, icmp, fd);
+ CHECK_SET_MIN_MAX_PROTO_FD(proto, IPPROTO_ICMPV6, icmp, fd);
+ CHECK_SET_MIN_MAX_PROTO_FD(proto, IPPROTO_TCP, tcp, fd);
+ CHECK_SET_MIN_MAX_PROTO_FD(proto, IPPROTO_UDP, udp, fd);
+
if (proto == IPPROTO_UDP && PORT_IS_EPHEMERAL(port))
goto epoll_add;
if (bind(fd, sa, sl) < 0) {
/* We'll fail to bind to low ports if we don't have enough
* capabilities, and we'll fail to bind on already bound ports,
- * this is fine.
+ * this is fine. If this isn't the socket with the lowest number
+ * for a given protocol, leave it open, to avoid unnecessary
+ * holes in the numbering.
*/
- close(fd);
- return 0;
+ if ((proto == IPPROTO_TCP && fd == c->tcp.fd_min) ||
+ (proto == IPPROTO_UDP && fd == c->udp.fd_min) ||
+ ((proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) &&
+ fd == c->icmp.fd_min)) {
+ close(fd);
+ return 0;
+ }
+ return fd;
}
if (proto == IPPROTO_TCP && listen(fd, 128) < 0) {