Merge pull request #15124 from fdumontet6WIND/large_fds

lib snmp: use snmp's large fd sets for agentx
This commit is contained in:
Donald Sharp 2024-01-10 20:24:26 -05:00 committed by GitHub
commit 5fbf0cc00d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/snmp_vars.h>
#include <net-snmp/library/large_fd_set.h>
#include "command.h"
#include "smux.h"
@ -43,7 +44,7 @@ static void agentx_timeout(struct event *t)
static void agentx_read(struct event *t)
{
fd_set fds;
netsnmp_large_fd_set lfds;
int flags, new_flags = 0;
int nonblock = false;
struct listnode *ln = EVENT_ARG(t);
@ -68,9 +69,9 @@ static void agentx_read(struct event *t)
flog_err(EC_LIB_SYSTEM_CALL, "Failed to set snmp fd non blocking: %s(%d)",
strerror(errno), errno);
FD_ZERO(&fds);
FD_SET(EVENT_FD(t), &fds);
snmp_read(&fds);
netsnmp_large_fd_set_init(&lfds, FD_SETSIZE);
netsnmp_large_fd_setfd(t->u.fd, &lfds);
snmp_read2(&lfds);
/* Reset the flag */
if (!nonblock) {
@ -85,6 +86,7 @@ static void agentx_read(struct event *t)
netsnmp_check_outstanding_agent_requests();
agentx_events_update();
netsnmp_large_fd_set_cleanup(&lfds);
}
static void agentx_events_update(void)
@ -92,15 +94,15 @@ static void agentx_events_update(void)
int maxfd = 0;
int block = 1;
struct timeval timeout = {.tv_sec = 0, .tv_usec = 0};
fd_set fds;
netsnmp_large_fd_set lfds;
struct listnode *ln;
struct event **thr;
int fd, thr_fd;
event_cancel(&timeout_thr);
FD_ZERO(&fds);
snmp_select_info(&maxfd, &fds, &timeout, &block);
netsnmp_large_fd_set_init(&lfds, FD_SETSIZE);
snmp_select_info2(&maxfd, &lfds, &timeout, &block);
if (!block) {
event_add_timer_tv(agentx_tm, agentx_timeout, NULL, &timeout,
@ -118,7 +120,7 @@ static void agentx_events_update(void)
/* caught up */
if (thr_fd == fd) {
struct listnode *nextln = listnextnode(ln);
if (!FD_ISSET(fd, &fds)) {
if (!netsnmp_large_fd_is_set(fd, &lfds)) {
event_cancel(thr);
XFREE(MTYPE_TMP, thr);
list_delete_node(events, ln);
@ -128,7 +130,7 @@ static void agentx_events_update(void)
thr_fd = thr ? EVENT_FD(*thr) : -1;
}
/* need listener, but haven't hit one where it would be */
else if (FD_ISSET(fd, &fds)) {
else if (netsnmp_large_fd_is_set(fd, &lfds)) {
struct listnode *newln;
thr = XCALLOC(MTYPE_TMP, sizeof(struct event *));
@ -147,6 +149,7 @@ static void agentx_events_update(void)
list_delete_node(events, ln);
ln = nextln;
}
netsnmp_large_fd_set_cleanup(&lfds);
}
/* AgentX node. */