From: Alan T. DeKok Date: Fri, 10 Sep 2021 12:30:06 +0000 (-0400) Subject: just set SO_RCVBUF to a small value X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ccd488e1a782cea4f52ce5966c27a619aa4503d;p=thirdparty%2Ffreeradius-server.git just set SO_RCVBUF to a small value and don't bother reading from the socket. --- diff --git a/src/lib/util/udp_queue.c b/src/lib/util/udp_queue.c index 419398f4d8d..b531332c7f6 100644 --- a/src/lib/util/udp_queue.c +++ b/src/lib/util/udp_queue.c @@ -27,6 +27,7 @@ RCSID("$Id$") #include +#include #include #include @@ -124,9 +125,6 @@ fr_udp_queue_t *fr_udp_queue_alloc(TALLOC_CTX *ctx, fr_udp_queue_config_t const if (config->interface && (fr_socket_bind(fd, &config->ipaddr, &port, config->interface) < 0)) goto error; - /* - * Set sendbuf - */ #ifdef SO_SNDBUF /* * Set SO_SNDBUF size, if configured to do so. @@ -143,6 +141,20 @@ fr_udp_queue_t *fr_udp_queue_alloc(TALLOC_CTX *ctx, fr_udp_queue_config_t const } #endif +#ifdef SO_RCVBUF + /* + * Set SO_RECVBUFF to 4K, so that the kernel will quickly + * drop incoming packets. We don't expect replies, and + * we never check the socket for readability, so this is + * fine. + */ + { + int opt = 4096; + + (void) setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(int)); + } +#endif + uq = talloc_zero(ctx, fr_udp_queue_t); if (!uq) { error: @@ -174,14 +186,6 @@ static void udp_queue_writable(UNUSED fr_event_list_t *el, UNUSED int fd, { fr_udp_queue_t *uq = talloc_get_type_abort(uctx, fr_udp_queue_t); fr_time_t now = fr_time(); - uint8_t buffer[1]; - - /* - * Read and discard any inputs. - */ - while (read(uq->fd, buffer, sizeof(buffer)) > 0) { - /* do nothing */ - } fr_dlist_foreach_safe(&uq->queue, fr_udp_queue_entry_t, entry) { ssize_t rcode; @@ -266,14 +270,6 @@ int fr_udp_queue_write(TALLOC_CTX *ctx, fr_udp_queue_t *uq, uint8_t const *packe if (!uq->blocked) { int retries = 0; ssize_t rcode; - char buffer[1]; - - /* - * Read and discard any inputs. - */ - while (read(uq->fd, buffer, sizeof(buffer)) > 0) { - /* do nothing */ - } retry: rcode = sendto(uq->fd, packet, packet_len, 0, (struct sockaddr *) &sockaddr, socklen);