tcp, tcp_splice: Issue warnings if unable to refill socket pool

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 <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-02-19 18:56:49 +11:00 committed by Stefano Brivio
parent 554b3aefe7
commit fbe81decbd
3 changed files with 31 additions and 11 deletions

24
tcp.c
View file

@ -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, negative 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));
}
}
/**

View file

@ -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 */

View file

@ -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;
}