summaryrefslogtreecommitdiff
path: root/lib/vty.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2024-12-03 18:49:59 -0500
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-12-04 12:47:35 +0000
commit16bb1dd5b0343f03ae2fd455eeaebdaf89ec9ebc (patch)
tree75d14a22657e5e4d72d232cf99b61b81c069b4e4 /lib/vty.c
parent7aa65cfefcebc512e95e30f68e4aac7e9b36d46c (diff)
lib,vtysh: Use backoff setsockopt option for freebsd
Commit: 9112fb367b1ae0168b4e7a81f41c2ca621979199 Introduced the idea of setting the socket buffer send/receive sizes. BSD's in general have the fun issue of not allowing nearly as large as a size as linux. Since the above commit was developed on linux and not run on bsd it was never tested. Modify the codebase to use the backoff setsockopt that we have in the code base and use the returned values to allow us to notice what was set and respond appropriately. Signed-off-by: Donald Sharp <sharpd@nvidia.com> (cherry picked from commit 959dbe27cde21ab212f6566b30865b2da418b4d2)
Diffstat (limited to 'lib/vty.c')
-rw-r--r--lib/vty.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 256a3bb3f5..1d04e75bf4 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -43,6 +43,7 @@
#include "northbound_cli.h"
#include "printfrr.h"
#include "json.h"
+#include "sockopt.h"
#include <arpa/telnet.h>
#include <termios.h>
@@ -352,7 +353,7 @@ int vty_out(struct vty *vty, const char *format, ...)
* put the data of collective vty->obuf Linked List items on the
* socket and free the vty->obuf data.
*/
- if (vty->vty_buf_size_accumulated >= VTY_MAX_INTERMEDIATE_FLUSH) {
+ if (vty->vty_buf_size_accumulated >= vty->buf_size_intermediate) {
vty->vty_buf_size_accumulated = 0;
vtysh_flush(vty);
}
@@ -2157,15 +2158,15 @@ static void vtysh_accept(struct event *thread)
* Increasing the SEND socket buffer size so that the socket can hold
* before sending it to VTY shell.
*/
- ret = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&sndbufsize,
- sizeof(sndbufsize));
- if (ret < 0) {
+ ret = setsockopt_so_sendbuf(sock, sndbufsize);
+ if (ret <= 0) {
flog_err(EC_LIB_SOCKET,
"Cannot set socket %d send buffer size, %s", sock,
safe_strerror(errno));
close(sock);
return;
}
+
set_cloexec(sock);
#ifdef VTYSH_DEBUG
@@ -2173,6 +2174,13 @@ static void vtysh_accept(struct event *thread)
#endif /* VTYSH_DEBUG */
vty = vty_new();
+
+ vty->buf_size_set = ret;
+ if (vty->buf_size_set < VTY_MAX_INTERMEDIATE_FLUSH)
+ vty->buf_size_intermediate = vty->buf_size_set / 2;
+ else
+ vty->buf_size_intermediate = VTY_MAX_INTERMEDIATE_FLUSH;
+
vty->fd = sock;
vty->wfd = sock;
vty->type = VTY_SHELL_SERV;