diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/snmpd/parse.y | 3 | ||||
-rw-r--r-- | usr.sbin/snmpd/snmpd.h | 15 | ||||
-rw-r--r-- | usr.sbin/snmpd/snmpe.c | 52 | ||||
-rw-r--r-- | usr.sbin/snmpd/traphandler.c | 24 |
4 files changed, 38 insertions, 56 deletions
diff --git a/usr.sbin/snmpd/parse.y b/usr.sbin/snmpd/parse.y index 9d0c613eb55..5a7af838155 100644 --- a/usr.sbin/snmpd/parse.y +++ b/usr.sbin/snmpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.58 2020/06/30 17:11:49 martijn Exp $ */ +/* $OpenBSD: parse.y,v 1.59 2020/08/23 07:39:57 martijn Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -997,7 +997,6 @@ parse_config(const char *filename, u_int flags) conf->sc_flags = flags; conf->sc_confpath = filename; TAILQ_INIT(&conf->sc_addresses); - TAILQ_INIT(&conf->sc_sockets); strlcpy(conf->sc_rdcommunity, "public", SNMPD_MAXCOMMUNITYLEN); strlcpy(conf->sc_rwcommunity, "private", SNMPD_MAXCOMMUNITYLEN); strlcpy(conf->sc_trcommunity, "public", SNMPD_MAXCOMMUNITYLEN); diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h index e9feea29ab9..1782f0fc9af 100644 --- a/usr.sbin/snmpd/snmpd.h +++ b/usr.sbin/snmpd/snmpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpd.h,v 1.88 2020/08/08 13:39:57 martijn Exp $ */ +/* $OpenBSD: snmpd.h,v 1.89 2020/08/23 07:39:57 martijn Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -482,6 +482,9 @@ struct address { struct sockaddr_storage ss; in_port_t port; int ipproto; + int fd; + struct event ev; + struct event evt; TAILQ_ENTRY(address) entry; @@ -492,15 +495,6 @@ struct address { }; TAILQ_HEAD(addresslist, address); -struct listen_sock { - int s_fd; - int s_ipproto; - struct event s_ev; - struct event s_evt; - TAILQ_ENTRY(listen_sock) entry; -}; -TAILQ_HEAD(socklist, listen_sock); - enum usmauth { AUTH_NONE = 0, AUTH_MD5, /* HMAC-MD5-96, RFC3414 */ @@ -545,7 +539,6 @@ struct snmpd { const char *sc_confpath; struct addresslist sc_addresses; - struct socklist sc_sockets; struct timeval sc_starttime; u_int32_t sc_engine_boots; diff --git a/usr.sbin/snmpd/snmpe.c b/usr.sbin/snmpd/snmpe.c index 8ddaaece946..817928aac66 100644 --- a/usr.sbin/snmpd/snmpe.c +++ b/usr.sbin/snmpd/snmpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpe.c,v 1.64 2020/08/17 15:48:28 martijn Exp $ */ +/* $OpenBSD: snmpe.c,v 1.65 2020/08/23 07:39:57 martijn Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -68,7 +68,6 @@ snmpe(struct privsep *ps, struct privsep_proc *p) { struct snmpd *env = ps->ps_env; struct address *h; - struct listen_sock *so; #ifdef DEBUG char buf[BUFSIZ]; struct oid *oid; @@ -82,14 +81,9 @@ snmpe(struct privsep *ps, struct privsep_proc *p) #endif /* bind SNMP UDP/TCP sockets */ - TAILQ_FOREACH(h, &env->sc_addresses, entry) { - if ((so = calloc(1, sizeof(*so))) == NULL) - fatal("snmpe: %s", __func__); - if ((so->s_fd = snmpe_bind(h)) == -1) + TAILQ_FOREACH(h, &env->sc_addresses, entry) + if ((h->fd = snmpe_bind(h)) == -1) fatal("snmpe: failed to bind SNMP socket"); - so->s_ipproto = h->ipproto; - TAILQ_INSERT_TAIL(&env->sc_sockets, so, entry); - } proc_run(ps, p, procs, nitems(procs), snmpe_init, NULL); } @@ -99,7 +93,7 @@ void snmpe_init(struct privsep *ps, struct privsep_proc *p, void *arg) { struct snmpd *env = ps->ps_env; - struct listen_sock *so; + struct address *h; kr_init(); trap_init(); @@ -107,17 +101,17 @@ snmpe_init(struct privsep *ps, struct privsep_proc *p, void *arg) usm_generate_keys(); /* listen for incoming SNMP UDP/TCP messages */ - TAILQ_FOREACH(so, &env->sc_sockets, entry) { - if (so->s_ipproto == IPPROTO_TCP) { - if (listen(so->s_fd, 5) < 0) + TAILQ_FOREACH(h, &env->sc_addresses, entry) { + if (h->ipproto == IPPROTO_TCP) { + if (listen(h->fd, 5) < 0) fatalx("snmpe: failed to listen on socket"); - event_set(&so->s_ev, so->s_fd, EV_READ, snmpe_acceptcb, so); - evtimer_set(&so->s_evt, snmpe_acceptcb, so); + event_set(&h->ev, h->fd, EV_READ, snmpe_acceptcb, h); + evtimer_set(&h->evt, snmpe_acceptcb, h); } else { - event_set(&so->s_ev, so->s_fd, EV_READ|EV_PERSIST, + event_set(&h->ev, h->fd, EV_READ|EV_PERSIST, snmpe_recvmsg, env); } - event_add(&so->s_ev, NULL); + event_add(&h->ev, NULL); } /* no filesystem visibility */ @@ -130,13 +124,13 @@ snmpe_init(struct privsep *ps, struct privsep_proc *p, void *arg) void snmpe_shutdown(void) { - struct listen_sock *so; + struct address *h; - TAILQ_FOREACH(so, &snmpd_env->sc_sockets, entry) { - event_del(&so->s_ev); - if (so->s_ipproto == IPPROTO_TCP) - event_del(&so->s_evt); - close(so->s_fd); + TAILQ_FOREACH(h, &snmpd_env->sc_addresses, entry) { + event_del(&h->ev); + if (h->ipproto == IPPROTO_TCP) + event_del(&h->evt); + close(h->fd); } kr_shutdown(); } @@ -509,13 +503,13 @@ snmpe_parsevarbinds(struct snmp_message *msg) void snmpe_acceptcb(int fd, short type, void *arg) { - struct listen_sock *so = arg; - struct sockaddr_storage ss; - socklen_t len = sizeof(ss); + struct address *h = arg; + struct sockaddr_storage ss; + socklen_t len = sizeof(ss); struct snmp_message *msg; int afd; - event_add(&so->s_ev, NULL); + event_add(&h->ev, NULL); if ((type & EV_TIMEOUT)) return; @@ -525,8 +519,8 @@ snmpe_acceptcb(int fd, short type, void *arg) if (errno == ENFILE || errno == EMFILE) { struct timeval evtpause = { 1, 0 }; - event_del(&so->s_ev); - evtimer_add(&so->s_evt, &evtpause); + event_del(&h->ev); + evtimer_add(&h->evt, &evtpause); } else if (errno != EAGAIN && errno != EINTR) log_debug("%s: accept4", __func__); return; diff --git a/usr.sbin/snmpd/traphandler.c b/usr.sbin/snmpd/traphandler.c index bf8218c1202..7738203f7a6 100644 --- a/usr.sbin/snmpd/traphandler.c +++ b/usr.sbin/snmpd/traphandler.c @@ -1,4 +1,4 @@ -/* $OpenBSD: traphandler.c,v 1.16 2020/03/11 06:53:42 martijn Exp $ */ +/* $OpenBSD: traphandler.c,v 1.17 2020/08/23 07:39:57 martijn Exp $ */ /* * Copyright (c) 2014 Bret Stephen Lambert <blambert@openbsd.org> @@ -74,17 +74,13 @@ traphandler(struct privsep *ps, struct privsep_proc *p) { struct snmpd *env = ps->ps_env; struct address *h; - struct listen_sock *so; if (env->sc_traphandler) { TAILQ_FOREACH(h, &env->sc_addresses, entry) { if (h->ipproto != IPPROTO_UDP) continue; - if ((so = calloc(1, sizeof(*so))) == NULL) - fatal("%s", __func__); - if ((so->s_fd = traphandler_bind(h)) == -1) + if ((h->fd = traphandler_bind(h)) == -1) fatal("could not create trap listener socket"); - TAILQ_INSERT_TAIL(&env->sc_sockets, so, entry); } } @@ -95,7 +91,7 @@ void traphandler_init(struct privsep *ps, struct privsep_proc *p, void *arg) { struct snmpd *env = ps->ps_env; - struct listen_sock *so; + struct address *h; if (pledge("stdio id proc recvfd exec", NULL) == -1) fatal("pledge"); @@ -104,10 +100,10 @@ traphandler_init(struct privsep *ps, struct privsep_proc *p, void *arg) return; /* listen for SNMP trap messages */ - TAILQ_FOREACH(so, &env->sc_sockets, entry) { - event_set(&so->s_ev, so->s_fd, EV_READ|EV_PERSIST, + TAILQ_FOREACH(h, &env->sc_addresses, entry) { + event_set(&h->ev, h->fd, EV_READ|EV_PERSIST, traphandler_recvmsg, ps); - event_add(&so->s_ev, NULL); + event_add(&h->ev, NULL); } } @@ -141,11 +137,11 @@ traphandler_bind(struct address *addr) void traphandler_shutdown(void) { - struct listen_sock *so; + struct address *h; - TAILQ_FOREACH(so, &snmpd_env->sc_sockets, entry) { - event_del(&so->s_ev); - close(so->s_fd); + TAILQ_FOREACH(h, &snmpd_env->sc_addresses, entry) { + event_del(&h->ev); + close(h->fd); } } |