From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 1F77C5A0275 for ; Mon, 19 Feb 2024 08:56:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1708329414; bh=6bQfbhtm8sh25bsApP1p8A/Zyme7CuyuDcw6J0GmAzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kb7UkeF3Mb4NwiBSswcOhg+V9q73OZe+Pel7cjX5m8jo3WNutkumJC5UYPiWZ2DW8 WjzwRdIegUN0pqN8Ty6bzzHjxTI/G4V9uxIuxGHh11J5A/3tNbsxnkKP0iGuIZSUGI e0wbcdoKgR6zzs71mBehruxQwKfcoNXDKwhSwt7V8/diCfHp6Wa+ciiUPXyEzZEH6w 5MWwuASmyHARzbZLoCbiZbC+us7p4z+IiUBLZ39GaUGImJbyInIr+d+sK6nhJfr4p4 vwNloD/+Tn3/d77ry3tABf1mq5QzBlzcDjmhYwIw20sqgE80q6EWhhpg2qNmF8I8Q9 +8rntE+ZzV1cQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TdZck3PtLz4x1k; Mon, 19 Feb 2024 18:56:54 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 4/6] tcp, tcp_splice: Issue warnings if unable to refill socket pool Date: Mon, 19 Feb 2024 18:56:49 +1100 Message-ID: <20240219075651.1360229-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219075651.1360229-1-david@gibson.dropbear.id.au> References: <20240219075651.1360229-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: UMGHDO4EG7PDUFGQZUFZT5AYVBK43EWN X-Message-ID-Hash: UMGHDO4EG7PDUFGQZUFZT5AYVBK43EWN 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: Currently if tcp_sock_refill_pool() is unable to fill all the slots in the pool, it will silently exit. This might lead to a later attempt to get fds from the pool to fail at which point it will be harder to tell what originally went wrong. Instead add warnings if we're unable to refill any of the socket pools when requested. We have tcp_sock_refill_pool() return an error and report it in the callers, because those callers have more context allowing for a more useful message. Signed-off-by: David Gibson --- tcp.c | 24 ++++++++++++++++++------ tcp_conn.h | 2 +- tcp_splice.c | 16 ++++++++++++---- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/tcp.c b/tcp.c index d49210bc..ad56ffc3 100644 --- a/tcp.c +++ b/tcp.c @@ -3007,8 +3007,10 @@ static int tcp_ns_socks_init(void *arg) * @c: Execution context * @pool: Pool of sockets to refill * @af: Address family to use + * + * Return: 0 on success, -ve error code if there was at least one error */ -void tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af) +int tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af) { int i; @@ -3017,8 +3019,10 @@ void tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af) continue; if ((pool[i] = tcp_conn_new_sock(c, af)) < 0) - break; + return pool[i]; } + + return 0; } /** @@ -3027,10 +3031,18 @@ void tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af) */ static void tcp_sock_refill_init(const struct ctx *c) { - if (c->ifi4) - tcp_sock_refill_pool(c, init_sock_pool4, AF_INET); - if (c->ifi6) - tcp_sock_refill_pool(c, init_sock_pool6, AF_INET6); + if (c->ifi4) { + int rc = tcp_sock_refill_pool(c, init_sock_pool4, AF_INET); + if (rc < 0) + warn("TCP: Error refilling IPv4 host socket pool: %s", + strerror(-rc)); + } + if (c->ifi6) { + int rc = tcp_sock_refill_pool(c, init_sock_pool6, AF_INET6); + if (rc < 0) + warn("TCP: Error refilling IPv6 host socket pool: %s", + strerror(-rc)); + } } /** diff --git a/tcp_conn.h b/tcp_conn.h index 20c7cb8b..92d4807a 100644 --- a/tcp_conn.h +++ b/tcp_conn.h @@ -160,7 +160,7 @@ bool tcp_splice_flow_defer(union flow *flow); void tcp_splice_timer(const struct ctx *c, union flow *flow); int tcp_conn_pool_sock(int pool[]); int tcp_conn_new_sock(const struct ctx *c, sa_family_t af); -void tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af); +int tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af); void tcp_splice_refill(const struct ctx *c); #endif /* TCP_CONN_H */ diff --git a/tcp_splice.c b/tcp_splice.c index cc9745e8..ee68029b 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -710,10 +710,18 @@ static int tcp_sock_refill_ns(void *arg) ns_enter(c); - if (c->ifi4) - tcp_sock_refill_pool(c, ns_sock_pool4, AF_INET); - if (c->ifi6) - tcp_sock_refill_pool(c, ns_sock_pool6, AF_INET6); + if (c->ifi4) { + int rc = tcp_sock_refill_pool(c, ns_sock_pool4, AF_INET); + if (rc < 0) + warn("TCP: Error refilling IPv4 ns socket pool: %s", + strerror(-rc)); + } + if (c->ifi6) { + int rc = tcp_sock_refill_pool(c, ns_sock_pool6, AF_INET6); + if (rc < 0) + warn("TCP: Error refilling IPv6 ns socket pool: %s", + strerror(-rc)); + } return 0; } -- 2.43.2