diff options
author | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2009-06-05 23:39:52 +0000 |
---|---|---|
committer | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2009-06-05 23:39:52 +0000 |
commit | eec120ac35f33ddf2b90df426deaa4f48088b71d (patch) | |
tree | 39e95460b2f91d49890ed92bb5cd6dbb11f5eaf3 /usr.sbin/relayd/snmp.c | |
parent | 24d25743651001129029931c6fcb908bc43867fd (diff) |
4 handed diff with eric:
Stop pushing event handling in the imsg framework.
Instead, provide a small glue layer on top of both imsg and libevent.
This finally clearly separates event handling and imsg construction.
Sidetrack bonus: remove the mega-ugly hack of having a dummy imsg_event_add
stub in relayctl.
This will make bgpd (and thus henning) happy. Next up are smtpd and ospfd.
ok eric@
Diffstat (limited to 'usr.sbin/relayd/snmp.c')
-rw-r--r-- | usr.sbin/relayd/snmp.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/usr.sbin/relayd/snmp.c b/usr.sbin/relayd/snmp.c index 983dd1ac10b..d7d82ce86f1 100644 --- a/usr.sbin/relayd/snmp.c +++ b/usr.sbin/relayd/snmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: snmp.c,v 1.4 2009/06/05 00:04:01 pyr Exp $ */ +/* $OpenBSD: snmp.c,v 1.5 2009/06/05 23:39:51 pyr Exp $ */ /* * Copyright (c) 2008 Reyk Floeter <reyk@openbsd.org> @@ -44,19 +44,19 @@ goto done; \ } while (0) -static struct imsgbuf *ibuf_snmp = NULL; -static struct imsgbuf *ibuf_main = NULL; +static struct imsgev *iev_snmp = NULL; +static struct imsgev *iev_main = NULL; static struct relayd *env = NULL; void snmp_sock(int, short, void *); -int snmp_getsock(struct imsgbuf *); +int snmp_getsock(struct imsgev *); int snmp_element(const char *, enum snmp_type, void *, int64_t); void -snmp_init(struct relayd *x_env, struct imsgbuf *ibuf) +snmp_init(struct relayd *x_env, struct imsgev *iev) { env = x_env; - ibuf_main = ibuf; + iev_main = iev; if (event_initialized(&env->sc_snmpev)) event_del(&env->sc_snmpev); @@ -68,17 +68,17 @@ snmp_init(struct relayd *x_env, struct imsgbuf *ibuf) } if ((env->sc_flags & F_TRAP) == 0) { - ibuf_main = NULL; + iev_main = NULL; return; } - snmp_sock(-1, -1, ibuf); + snmp_sock(-1, -1, iev); } int -snmp_sendsock(struct imsgbuf *ibuf) +snmp_sendsock(struct imsgev *iev) { - struct imsgbuf tmpibuf; + struct imsgev tmpiev; struct sockaddr_un sun; int s = -1; @@ -92,45 +92,45 @@ snmp_sendsock(struct imsgbuf *ibuf) goto fail; /* enable restricted snmp socket mode */ - bzero(&tmpibuf, sizeof(tmpibuf)); - imsg_init(&tmpibuf, s, NULL); - imsg_compose_event(&tmpibuf, IMSG_SNMP_LOCK, 0, 0, -1, NULL, 0); + bzero(&tmpiev, sizeof(tmpiev)); + imsg_init(&tmpiev.ibuf, s); + imsg_compose_event(&tmpiev, IMSG_SNMP_LOCK, 0, 0, -1, NULL, 0); - imsg_compose_event(ibuf, IMSG_SNMPSOCK, 0, 0, s, NULL, 0); - imsg_flush(ibuf); /* need to send the socket now */ + imsg_compose_event(iev, IMSG_SNMPSOCK, 0, 0, s, NULL, 0); + imsg_flush(&iev->ibuf); /* need to send the socket now */ close(s); return (0); fail: if (s != -1) close(s); - imsg_compose_event(ibuf, IMSG_NONE, 0, 0, -1, NULL, 0); + imsg_compose_event(iev, IMSG_NONE, 0, 0, -1, NULL, 0); return (-1); } int -snmp_getsock(struct imsgbuf *ibuf) +snmp_getsock(struct imsgev *iev) { struct imsg imsg; int n, s = -1, done = 0; - imsg_compose_event(ibuf, IMSG_SNMPSOCK, 0, 0, -1, NULL, 0); - imsg_flush(ibuf); + imsg_compose_event(iev, IMSG_SNMPSOCK, 0, 0, -1, NULL, 0); + imsg_flush(&iev->ibuf); while (!done) { - if ((n = imsg_read(ibuf)) == -1) + if ((n = imsg_read(&iev->ibuf)) == -1) fatal("snmp_getsock: failed to read imsg"); if (n == 0) fatal("snmp_getsock: pipe closed"); while (!done) { - if ((n = imsg_get(ibuf, &imsg)) == -1) + if ((n = imsg_get(&iev->ibuf, &imsg)) == -1) fatal("snmp_getsock: failed to get imsg"); if (n == 0) break; done = 1; switch (imsg.hdr.type) { case IMSG_SNMPSOCK: - s = imsg_get_fd(ibuf); + s = imsg_get_fd(&iev->ibuf); break; default: break; @@ -141,10 +141,10 @@ snmp_getsock(struct imsgbuf *ibuf) if (s != -1) { log_debug("snmp_getsock: got new snmp socket %d", s); - if (ibuf_snmp == NULL && (ibuf_snmp = (struct imsgbuf *) + if (iev_snmp == NULL && (iev_snmp = (struct imsgev *) calloc(1, sizeof(struct imsgbuf))) == NULL) fatal("snmp_getsock: calloc"); - imsg_init(ibuf_snmp, s, NULL); + imsg_init(&iev_snmp->ibuf, s); } return (s); @@ -165,7 +165,7 @@ snmp_sock(int fd, short event, void *arg) break; } - if ((env->sc_snmp = snmp_getsock(ibuf_main)) == -1) { + if ((env->sc_snmp = snmp_getsock(iev_main)) == -1) { DPRINTF("snmp_sock: failed to open snmp socket"); goto retry; } @@ -234,10 +234,10 @@ snmp_element(const char *oid, enum snmp_type type, void *buf, int64_t val) iov[0].iov_base = &sm; iov[0].iov_len = sizeof(sm); - if (imsg_composev(ibuf_snmp, IMSG_SNMP_ELEMENT, 0, 0, -1, + if (imsg_composev(&iev_snmp->ibuf, IMSG_SNMP_ELEMENT, 0, 0, -1, iov, iovcnt) == -1) return (-1); - imsg_event_add(ibuf_snmp); + imsg_event_add(iev_snmp); return (0); } @@ -249,7 +249,7 @@ snmp_element(const char *oid, enum snmp_type type, void *buf, int64_t val) void snmp_hosttrap(struct table *table, struct host *host) { - if (ibuf_snmp == NULL || env->sc_snmp == -1) + if (iev_snmp == NULL || env->sc_snmp == -1) return; /* @@ -257,7 +257,7 @@ snmp_hosttrap(struct table *table, struct host *host) * XXX The trap format needs some tweaks and other OIDs */ - imsg_compose_event(ibuf_snmp, IMSG_SNMP_TRAP, 0, 0, -1, NULL, 0); + imsg_compose_event(iev_snmp, IMSG_SNMP_TRAP, 0, 0, -1, NULL, 0); SNMP_ELEMENT(".1", SNMP_NULL, NULL, 0); SNMP_ELEMENT(".1.1", SNMP_OCTETSTRING, host->conf.name, 0); @@ -273,5 +273,5 @@ snmp_hosttrap(struct table *table, struct host *host) SNMP_ELEMENT(".1.9", SNMP_INTEGER32, NULL, host->retry_cnt); done: - imsg_compose_event(ibuf_snmp, IMSG_SNMP_END, 0, 0, -1, NULL, 0); + imsg_compose_event(iev_snmp, IMSG_SNMP_END, 0, 0, -1, NULL, 0); } |