]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib,vtysh: Use backoff setsockopt option for freebsd
authorDonald Sharp <sharpd@nvidia.com>
Tue, 3 Dec 2024 23:49:59 +0000 (18:49 -0500)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Wed, 4 Dec 2024 12:47:35 +0000 (12:47 +0000)
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)

lib/vty.c
lib/vty.h
vtysh/vtysh.c

index 256a3bb3f538e3878dd67dcb0c5bf5944f8d7d64..1d04e75bf445bab475d426870ae4a034319d599f 100644 (file)
--- 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;
index e511e8e79ae47108fc0810050a393eedaa144ff9..be54159aa95dd5f293ab849f95b1943d3d6abf05 100644 (file)
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -237,6 +237,9 @@ struct vty {
        bool mgmt_locked_candidate_ds;
        bool mgmt_locked_running_ds;
        uint64_t vty_buf_size_accumulated;
+
+       int buf_size_set;
+       uint64_t buf_size_intermediate;
 };
 
 static inline void vty_push_context(struct vty *vty, int node, uint64_t id)
index 2d80feef6c970696c00b8b6443f604651674c645..92f37f193a964575f10cff058481a2ffb7ebb241 100644 (file)
@@ -39,6 +39,7 @@
 #include "frrstr.h"
 #include "json.h"
 #include "ferr.h"
+#include "sockopt.h"
 
 DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy");
 
@@ -4694,9 +4695,8 @@ static int vtysh_connect(struct vtysh_client *vclient)
         * Increasing the RECEIVE socket buffer size so that the socket can hold
         * after receving from other process.
         */
-       ret = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&rcvbufsize,
-                        sizeof(rcvbufsize));
-       if (ret < 0) {
+       ret = setsockopt_so_recvbuf(sock, rcvbufsize);
+       if (ret <= 0) {
 #ifdef DEBUG
                fprintf(stderr, "Cannot set socket %d rcv buffer size, %s\n",
                        sock, safe_strerror(errno));