Index | Thread | Search

From:
Theo Buehler <tb@theobuehler.org>
Subject:
Re: bgpd: throttle reads from the peer socket
To:
tech@openbsd.org
Date:
Thu, 10 Sep 2026 21:05:00 +0200

Download raw body.

Thread
On Thu, Sep 10, 2026 at 08:54:50PM +0200, Claudio Jeker wrote:
> Right now the session socket is always ready to read more data. At the
> same time only MSG_PROCESS_LIMIT messages are pulled of the msgbuf read
> queue. As a result the SE may buffer a lot of messages.
> 
> This throttles the POLLIN event by checking that no more than
> MSG_PROCESS_LIMIT are ready. If more are queued the POLLIN is skipped.
> The code will still run session_process_msg on every poll round and so the
> queue len will shrink by MSG_PROCESS_LIMIT.
> 
> This is now possible that the ibuf API includes msgbuf_readlen.

ok tb

> -- 
> :wq Claudio
> 
> Index: session.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/bgpd/session.c,v
> diff -u -p -r1.540 session.c
> --- session.c	24 Jul 2026 05:01:01 -0000	1.540
> +++ session.c	10 Sep 2026 18:45:59 -0000
> @@ -414,7 +414,9 @@ session_main(int debug, int verbose)
>  			}
>  
>  			/* are we waiting for a write? */
> -			events = POLLIN;
> +			events = 0;
> +			if (msgbuf_readlen(p->wbuf) < MSG_PROCESS_LIMIT)
> +				events |= POLLIN;
>  			if (msgbuf_queuelen(p->wbuf) > 0 ||
>  			    p->state == STATE_CONNECT)
>  				events |= POLLOUT;
>