diff options
author | Gleb Smirnoff <glebius@FreeBSD.org> | 2025-01-13 18:08:58 +0000 |
---|---|---|
committer | Gleb Smirnoff <glebius@FreeBSD.org> | 2025-01-13 18:11:46 +0000 |
commit | 59498e099cc055da7afca8266087b7668be6d7cb (patch) | |
tree | e914327903d0d74005605112567ca5078467a195 | |
parent | 4155be454c46bc1ab725aca5c6969b064b74be38 (diff) |
sockets: virtualize kern.ipc.numopensockets
To avoid breaking POLA on the host machine it reports the same value as
before. In a VNET jail it now reports number of sockets in this jail.
PR: 219655
Differential Revision: https://reviews.freebsd.org/D48315
-rw-r--r-- | sys/kern/uipc_socket.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 7a76b561389a..426316ac6ce8 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -275,9 +275,23 @@ SYSCTL_PROC(_kern_ipc, KIPC_SOMAXCONN, somaxconn, sizeof(u_int), sysctl_somaxconn, "IU", "Maximum listen socket pending connection accept queue size (compat)"); -static int numopensockets; -SYSCTL_INT(_kern_ipc, OID_AUTO, numopensockets, CTLFLAG_RD, - &numopensockets, 0, "Number of open sockets"); +static u_int numopensockets; +static int +sysctl_numopensockets(SYSCTL_HANDLER_ARGS) +{ + u_int val; + +#ifdef VIMAGE + if(!IS_DEFAULT_VNET(curvnet)) + val = curvnet->vnet_sockcnt; + else +#endif + val = numopensockets; + return (sysctl_handle_int(oidp, &val, 0, req)); +} +SYSCTL_PROC(_kern_ipc, OID_AUTO, numopensockets, + CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_VNET, 0, sizeof(u_int), + sysctl_numopensockets, "IU", "Number of open sockets"); /* * so_global_mtx protects so_gencnt, numopensockets, and the per-socket |