From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 4/4] pif, util: Move listen(2) call from sock_l4_() to pif_listen()
Date: Tue, 9 Jun 2026 16:30:05 +1000 [thread overview]
Message-ID: <20260609063005.113744-5-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260609063005.113744-1-david@gibson.dropbear.id.au>
It's a bit odd to have the listen(2) call for TCP listening sockets, down
deep in sock_l4_() conditional upon the epoll type passed in. Move it to
pif_listen(), which is at least about listening, although it does still
need to be conditional on TCP.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
pif.c | 14 ++++++++++----
util.c | 7 -------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/pif.c b/pif.c
index ede2f903..f99f33e5 100644
--- a/pif.c
+++ b/pif.c
@@ -123,11 +123,17 @@ int pif_listen(const struct ctx *c, uint8_t proto, uint8_t pif,
ref.listen.pif = pif;
ref.listen.rule = rule;
- ret = epoll_add(c->epollfd, EPOLLIN, ref);
- if (ret < 0) {
- close(ref.fd);
- return ret;
+ if (proto == IPPROTO_TCP && listen(ref.fd, 128) < 0) {
+ ret = -errno;
+ goto fail;
}
+ ret = epoll_add(c->epollfd, EPOLLIN, ref);
+ if (ret < 0)
+ goto fail;
+
return ref.fd;
+fail:
+ close(ref.fd);
+ return ret;
}
diff --git a/util.c b/util.c
index b64c29ed..e22696e3 100644
--- a/util.c
+++ b/util.c
@@ -169,13 +169,6 @@ static int sock_l4_(const struct ctx *c, enum epoll_type type,
}
}
- if (type == EPOLL_TYPE_TCP_LISTEN && listen(fd, 128) < 0) {
- ret = -errno;
- warn("TCP socket listen: %s", strerror_(-ret));
- close(fd);
- return ret;
- }
-
return fd;
}
--
2.54.0
prev parent reply other threads:[~2026-06-09 6:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 6:30 [PATCH 0/4] Assorted minor socket creation cleanups David Gibson
2026-06-09 6:30 ` [PATCH 1/4] flow: Correct misleading signature of flowside_sock_l4() David Gibson
2026-06-09 6:30 ` [PATCH 2/4] Makefile: Remove unused DUAL_STACK_SOCKETS define David Gibson
2026-06-09 6:30 ` [PATCH 3/4] fwd, pif: Remove duplicated logic between tcp_listen() and udp_listen() David Gibson
2026-06-09 6:30 ` David Gibson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260609063005.113744-5-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).