Skip to content

Commit

Permalink
Merge pull request #15124 from fdumontet6WIND/large_fds
Browse files Browse the repository at this point in the history
lib snmp: use snmp's large fd sets for agentx
  • Loading branch information
donaldsharp authored Jan 11, 2024
2 parents 26be39c + 9e06f93 commit 5fbf0cc
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/agentx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -85,22 +86,23 @@ 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)
{
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,
Expand All @@ -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);
Expand All @@ -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 *));
Expand All @@ -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. */
Expand Down

0 comments on commit 5fbf0cc

Please sign in to comment.