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=AHOHXasF; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id B784F5A026E for ; Tue, 16 Jun 2026 03:09:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1781572178; bh=ZRglaZyHYK7yYXPvECbDVA1b/GqYxUKbMcSNaVgan00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AHOHXasF3EVQXOAzveBQz9VxIHCAO86e+OFkYyPxbtPgZqvXf+9oWa+nsReKrzGiL GRf39SAjsLIcWWhKT4xmsviVNUro/HFQnxyWtj/ucZ+AQKAAj7LW9w6yur2/4jbGyf NQXEgUNsGKsSIYiGtecRtjnXRen+/yzDsAgA3ii0MWspLYCM8/Ck7EPScgSOaVsUnk o7pY1BlTozuPjVLXWr0moXjg2+XGXWwURP2kdgjlrZs+6GYL6zSdNiumzqFSs4X0D4 1K+YXRbY4WjkuVIHBUPJq5+B0wEGp6ypX1wOmamN+RRHhGxshojepA0uSluBWZ4lN9 JssgoxvJ4wINA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gfTRQ55bbz4xXt; Tue, 16 Jun 2026 11:09:38 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 4/4] pif, util: Move listen(2) call from sock_l4_() to pif_listen() Date: Tue, 16 Jun 2026 11:09:36 +1000 Message-ID: <20260616010936.1672156-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616010936.1672156-1-david@gibson.dropbear.id.au> References: <20260616010936.1672156-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ZKITONEAQR3I6477M4ZLUYTEEO4FMA4E X-Message-ID-Hash: ZKITONEAQR3I6477M4ZLUYTEEO4FMA4E 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 4cf0f6ed..8ade587c 100644 --- a/pif.c +++ b/pif.c @@ -125,11 +125,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 ed874f1c..0aa4d42d 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