From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=SbskN8Hd; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id BC5515A026D for ; Tue, 09 Jun 2026 08:30:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1780986609; bh=TVoMOq3bFaibPjx77H4XPoMYzburXceZmxkAfoVnqFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SbskN8HdNMG13m8dg6EO5y9Bnhz9OPaotScpytHxUST/a6J+emiASxCk7B/XSB6PO arro0BAy0/s2LYfA1fp27rfOJbYnEo3EHnVhw6NMyFOD4GWU9YfQFGAKdgZc6P6Evb P72ScuxAQNMUdVso/Tey3E6V1nF/oqWB/U19OUlwWplnXhkYgLgDyy9GopGxBYmzCy 4NB8owNxXLEuNrQ9i4n8aWWSqeqSW5qDxUyC6dg/WwNCBPFjBcCdlhV/EnCD3BVnDi AvntNhJh4ck4Tf1VvJhs4lRosatQ74HVe1xT2iM6rxdJ/LqlXIK2nHP4+9Nez3dabS uSeTLS/ZLRidA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gZJtT0pz5z4wTL; Tue, 09 Jun 2026 16:30:09 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top 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 Message-ID: <20260609063005.113744-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260609063005.113744-1-david@gibson.dropbear.id.au> References: <20260609063005.113744-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: DAAWMUMSRZ7JYZ4XOFQBS3IOUZDBOOSK X-Message-ID-Hash: DAAWMUMSRZ7JYZ4XOFQBS3IOUZDBOOSK X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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