aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-02-14 10:48:21 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-02-14 17:25:08 +0100
commit912d37cd5b8c507d17f38758d50ff3ba0401a99c (patch)
tree0d836b5e5c9934b66d7c110f10d6ef4b4211119c /tcp.c
parentc8993476d53302b73c8cdac1c975525315f5a2db (diff)
downloadpasst-912d37cd5b8c507d17f38758d50ff3ba0401a99c.tar
passt-912d37cd5b8c507d17f38758d50ff3ba0401a99c.tar.gz
passt-912d37cd5b8c507d17f38758d50ff3ba0401a99c.tar.bz2
passt-912d37cd5b8c507d17f38758d50ff3ba0401a99c.tar.lz
passt-912d37cd5b8c507d17f38758d50ff3ba0401a99c.tar.xz
passt-912d37cd5b8c507d17f38758d50ff3ba0401a99c.tar.zst
passt-912d37cd5b8c507d17f38758d50ff3ba0401a99c.zip
tcp: Move socket pool declarations around
tcp_splice.c has some explicit extern declarations to access the socket pools. This is pretty dangerous - if we changed the type of these variables in tcp.c, we'd have tcp.c and tcp_splice.c using the same memory in different ways with no compiler error. So, move the extern declarations to tcp_conn.h so they're visible to both tcp.c and tcp_splice.c, but not the rest of pasta. In fact the pools for the guest namespace are necessarily only used by tcp_splice.c - we have no sockets on the guest side if we're not splicing. So move those declarations and the functions that deal exclusively with them to tcp_splice.c Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c41
1 files changed, 4 insertions, 37 deletions
diff --git a/tcp.c b/tcp.c
index 1d1b4ee..2f40d62 100644
--- a/tcp.c
+++ b/tcp.c
@@ -369,8 +369,6 @@ struct tcp6_l2_head { /* For MSS6 macro: keep in sync with tcp6_l2_buf_t */
#define FIN_TIMEOUT 60
#define ACT_TIMEOUT 7200
-#define TCP_SOCK_POOL_TSH 16 /* Refill in ns if > x used */
-
#define LOW_RTT_TABLE_SIZE 8
#define LOW_RTT_THRESHOLD 10 /* us */
@@ -594,11 +592,9 @@ static inline struct tcp_tap_conn *conn_at_idx(int index)
/* Table for lookup from remote address, local port, remote port */
static struct tcp_tap_conn *tc_hash[TCP_HASH_TABLE_SIZE];
-/* Pools for pre-opened sockets */
+/* Pools for pre-opened sockets (in init) */
int init_sock_pool4 [TCP_SOCK_POOL_SIZE];
int init_sock_pool6 [TCP_SOCK_POOL_SIZE];
-int ns_sock_pool4 [TCP_SOCK_POOL_SIZE];
-int ns_sock_pool6 [TCP_SOCK_POOL_SIZE];
/**
* tcp_conn_epoll_events() - epoll events mask for given connection state
@@ -3015,7 +3011,7 @@ static int tcp_ns_socks_init(void *arg)
* @pool: Pool of sockets to refill
* @af: Address family to use
*/
-static void tcp_sock_refill_pool(const struct ctx *c, int pool[], int af)
+void tcp_sock_refill_pool(const struct ctx *c, int pool[], int af)
{
int i;
@@ -3050,26 +3046,6 @@ static void tcp_sock_refill_init(const struct ctx *c)
}
/**
- * tcp_sock_refill_ns() - Refill pools of pre-opened sockets in namespace
- * @arg: Execution context cast to void *
- *
- * Return: 0
- */
-static int tcp_sock_refill_ns(void *arg)
-{
- const struct ctx *c = (const struct ctx *)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);
-
- return 0;
-}
-
-/**
* tcp_init() - Get initial sequence, hash secret, initialise per-socket data
* @c: Execution context
*
@@ -3117,8 +3093,6 @@ int tcp_init(struct ctx *c)
memset(init_sock_pool4, 0xff, sizeof(init_sock_pool4));
memset(init_sock_pool6, 0xff, sizeof(init_sock_pool6));
- memset(ns_sock_pool4, 0xff, sizeof(ns_sock_pool4));
- memset(ns_sock_pool6, 0xff, sizeof(ns_sock_pool6));
memset(tcp_sock_init_ext, 0xff, sizeof(tcp_sock_init_ext));
memset(tcp_sock_ns, 0xff, sizeof(tcp_sock_ns));
@@ -3128,8 +3102,6 @@ int tcp_init(struct ctx *c)
tcp_splice_init(c);
NS_CALL(tcp_ns_socks_init, c);
-
- NS_CALL(tcp_sock_refill_ns, c);
}
return 0;
@@ -3282,11 +3254,6 @@ void tcp_timer(struct ctx *c, const struct timespec *ts)
}
tcp_sock_refill_init(c);
- if (c->mode == MODE_PASTA) {
- if ((c->ifi4 && ns_sock_pool4[TCP_SOCK_POOL_TSH] < 0) ||
- (c->ifi6 && ns_sock_pool6[TCP_SOCK_POOL_TSH] < 0))
- NS_CALL(tcp_sock_refill_ns, c);
-
- tcp_splice_pipe_refill(c);
- }
+ if (c->mode == MODE_PASTA)
+ tcp_splice_refill(c);
}