Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
bgpd: simplify SO_RCVBUF and SO_SNDBUF clamping
To:
tech@openbsd.org
Date:
Thu, 16 May 2024 11:23:40 +0200

Download raw body.

Thread
In bgpd we clamp the TCP bufsize to 64k to limit the amount of buffering
on TCP to a reasonable level. This was done to help the SendHoldTimer.
Now the current code is doing too much since it will scale down below 64k
if setsockopt() fails. Since this is just a voluntary "optimisation" just
ignore possible errors and try only once.

-- 
:wq Claudio

Index: session.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/session.c,v
diff -u -p -r1.474 session.c
--- session.c	24 Apr 2024 10:41:34 -0000	1.474
+++ session.c	15 May 2024 09:01:01 -0000
@@ -1205,13 +1205,8 @@ session_setup_socket(struct peer *p)
 
 	/* limit bufsize. no biggie if it fails */
 	bsize = 65535;
-	while (bsize > 8192 && setsockopt(p->fd, SOL_SOCKET, SO_RCVBUF,
-	    &bsize, sizeof(bsize)) == -1 && errno != EINVAL)
-		bsize /= 2;
-	bsize = 65535;
-	while (bsize > 8192 && setsockopt(p->fd, SOL_SOCKET, SO_SNDBUF,
-	    &bsize, sizeof(bsize)) == -1 && errno != EINVAL)
-		bsize /= 2;
+	setsockopt(p->fd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize));
+	setsockopt(p->fd, SOL_SOCKET, SO_SNDBUF, &bsize, sizeof(bsize));
 
 	return (0);
 }