summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/relayctl/relayctl.c11
-rw-r--r--usr.sbin/relayd/check_script.c6
-rw-r--r--usr.sbin/relayd/control.c81
-rw-r--r--usr.sbin/relayd/hce.c54
-rw-r--r--usr.sbin/relayd/imsg.c5
-rw-r--r--usr.sbin/relayd/imsg.h8
-rw-r--r--usr.sbin/relayd/pfe.c141
-rw-r--r--usr.sbin/relayd/relay.c61
-rw-r--r--usr.sbin/relayd/relay_udp.c6
-rw-r--r--usr.sbin/relayd/relayd.c138
-rw-r--r--usr.sbin/relayd/relayd.h22
-rw-r--r--usr.sbin/relayd/snmp.c60
12 files changed, 310 insertions, 283 deletions
diff --git a/usr.sbin/relayctl/relayctl.c b/usr.sbin/relayctl/relayctl.c
index 5c5ee09cb58..94aca767f97 100644
--- a/usr.sbin/relayctl/relayctl.c
+++ b/usr.sbin/relayctl/relayctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayctl.c,v 1.36 2008/12/31 15:22:27 sobrado Exp $ */
+/* $OpenBSD: relayctl.c,v 1.37 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -93,13 +93,6 @@ usage(void)
exit(1);
}
-/* dummy function so that relayctl does not need libevent */
-void
-imsg_event_add(struct imsgbuf *i)
-{
- /* nothing */
-}
-
int
main(int argc, char *argv[])
{
@@ -134,7 +127,7 @@ main(int argc, char *argv[])
if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL)
err(1, NULL);
- imsg_init(ibuf, ctl_sock, NULL);
+ imsg_init(ibuf, ctl_sock);
done = 0;
/* process user request */
diff --git a/usr.sbin/relayd/check_script.c b/usr.sbin/relayd/check_script.c
index ce8956ba62c..80f587b70be 100644
--- a/usr.sbin/relayd/check_script.c
+++ b/usr.sbin/relayd/check_script.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_script.c,v 1.9 2009/06/05 00:04:01 pyr Exp $ */
+/* $OpenBSD: check_script.c,v 1.10 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -39,7 +39,7 @@
void script_sig_alarm(int);
-extern struct imsgbuf *ibuf_main;
+extern struct imsgev *iev_main;
pid_t child = -1;
void
@@ -51,7 +51,7 @@ check_script(struct host *host)
host->flags &= ~(F_CHECK_SENT|F_CHECK_DONE);
scr.host = host->conf.id;
- imsg_compose_event(ibuf_main, IMSG_SCRIPT, 0, 0, -1, &scr, sizeof(scr));
+ imsg_compose_event(iev_main, IMSG_SCRIPT, 0, 0, -1, &scr, sizeof(scr));
}
void
diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c
index ba6963eebf7..899135ecf0d 100644
--- a/usr.sbin/relayd/control.c
+++ b/usr.sbin/relayd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.31 2009/06/05 00:20:50 pyr Exp $ */
+/* $OpenBSD: control.c,v 1.32 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -43,8 +43,8 @@ struct ctl_connlist ctl_conns;
struct ctl_conn *control_connbyfd(int);
void control_close(int);
-struct imsgbuf *ibuf_main = NULL;
-struct imsgbuf *ibuf_hce = NULL;
+struct imsgev *iev_main = NULL;
+struct imsgev *iev_hce = NULL;
int
control_init(void)
@@ -97,12 +97,12 @@ control_init(void)
}
int
-control_listen(struct relayd *env, struct imsgbuf *i_main,
- struct imsgbuf *i_hce)
+control_listen(struct relayd *env, struct imsgev *i_main,
+ struct imsgev *i_hce)
{
- ibuf_main = i_main;
- ibuf_hce = i_hce;
+ iev_main = i_main;
+ iev_hce = i_hce;
if (listen(control_state.fd, CONTROL_BACKLOG) == -1) {
log_warn("control_listen: listen");
@@ -148,11 +148,12 @@ control_accept(int listenfd, short event, void *arg)
return;
}
- imsg_init(&c->ibuf, connfd, control_dispatch_imsg);
- c->ibuf.events = EV_READ;
- event_set(&c->ibuf.ev, c->ibuf.fd, c->ibuf.events,
- c->ibuf.handler, env);
- event_add(&c->ibuf.ev, NULL);
+ imsg_init(&c->iev.ibuf, connfd);
+ c->iev.handler = control_dispatch_imsg;
+ c->iev.events = EV_READ;
+ event_set(&c->iev.ev, c->iev.ibuf.fd, c->iev.events,
+ c->iev.handler, env);
+ event_add(&c->iev.ev, NULL);
TAILQ_INSERT_TAIL(&ctl_conns, c, entry);
}
@@ -162,7 +163,7 @@ control_connbyfd(int fd)
{
struct ctl_conn *c;
- for (c = TAILQ_FIRST(&ctl_conns); c != NULL && c->ibuf.fd != fd;
+ for (c = TAILQ_FIRST(&ctl_conns); c != NULL && c->iev.ibuf.fd != fd;
c = TAILQ_NEXT(c, entry))
; /* nothing */
@@ -179,11 +180,11 @@ control_close(int fd)
return;
}
- msgbuf_clear(&c->ibuf.w);
+ msgbuf_clear(&c->iev.ibuf.w);
TAILQ_REMOVE(&ctl_conns, c, entry);
- event_del(&c->ibuf.ev);
- close(c->ibuf.fd);
+ event_del(&c->iev.ev);
+ close(c->iev.ibuf.fd);
free(c);
}
@@ -203,21 +204,21 @@ control_dispatch_imsg(int fd, short event, void *arg)
}
if (event & EV_READ) {
- if ((n = imsg_read(&c->ibuf)) == -1 || n == 0) {
+ if ((n = imsg_read(&c->iev.ibuf)) == -1 || n == 0) {
control_close(fd);
return;
}
}
if (event & EV_WRITE) {
- if (msgbuf_write(&c->ibuf.w) < 0) {
+ if (msgbuf_write(&c->iev.ibuf.w) < 0) {
control_close(fd);
return;
}
}
for (;;) {
- if ((n = imsg_get(&c->ibuf, &imsg)) == -1) {
+ if ((n = imsg_get(&c->iev.ibuf, &imsg)) == -1) {
control_close(fd);
return;
}
@@ -237,12 +238,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
if (disable_rdr(c, &id))
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL,
0, 0, -1, NULL, 0);
else {
memcpy(imsg.data, &id, sizeof(id));
control_imsg_forward(&imsg);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK,
+ imsg_compose_event(&c->iev, IMSG_CTL_OK,
0, 0, -1, NULL, 0);
}
break;
@@ -251,12 +252,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
if (enable_rdr(c, &id))
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL,
0, 0, -1, NULL, 0);
else {
memcpy(imsg.data, &id, sizeof(id));
control_imsg_forward(&imsg);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK,
+ imsg_compose_event(&c->iev, IMSG_CTL_OK,
0, 0, -1, NULL, 0);
}
break;
@@ -265,12 +266,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
if (disable_table(c, &id))
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL,
0, 0, -1, NULL, 0);
else {
memcpy(imsg.data, &id, sizeof(id));
control_imsg_forward(&imsg);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK,
+ imsg_compose_event(&c->iev, IMSG_CTL_OK,
0, 0, -1, NULL, 0);
}
break;
@@ -279,12 +280,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
if (enable_table(c, &id))
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL,
0, 0, -1, NULL, 0);
else {
memcpy(imsg.data, &id, sizeof(id));
control_imsg_forward(&imsg);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK,
+ imsg_compose_event(&c->iev, IMSG_CTL_OK,
0, 0, -1, NULL, 0);
}
break;
@@ -293,12 +294,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
if (disable_host(c, &id, NULL))
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL,
0, 0, -1, NULL, 0);
else {
memcpy(imsg.data, &id, sizeof(id));
control_imsg_forward(&imsg);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK,
+ imsg_compose_event(&c->iev, IMSG_CTL_OK,
0, 0, -1, NULL, 0);
}
break;
@@ -307,32 +308,32 @@ control_dispatch_imsg(int fd, short event, void *arg)
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
if (enable_host(c, &id, NULL))
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL,
0, 0, -1, NULL, 0);
else {
memcpy(imsg.data, &id, sizeof(id));
control_imsg_forward(&imsg);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK,
+ imsg_compose_event(&c->iev, IMSG_CTL_OK,
0, 0, -1, NULL, 0);
}
break;
case IMSG_CTL_SHUTDOWN:
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL,
0, 0, -1, NULL, 0);
break;
case IMSG_CTL_POLL:
- imsg_compose_event(ibuf_hce, IMSG_CTL_POLL,
+ imsg_compose_event(iev_hce, IMSG_CTL_POLL,
0, 0,-1, NULL, 0);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK,
+ imsg_compose_event(&c->iev, IMSG_CTL_OK,
0, 0, -1, NULL, 0);
break;
case IMSG_CTL_RELOAD:
if (env->sc_prefork_relay > 0) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL,
0, 0, -1, NULL, 0);
break;
}
- imsg_compose_event(ibuf_main, IMSG_CTL_RELOAD,
+ imsg_compose_event(iev_main, IMSG_CTL_RELOAD,
0, 0, -1, NULL, 0);
/*
* we unconditionnaly return a CTL_OK imsg because
@@ -342,14 +343,14 @@ control_dispatch_imsg(int fd, short event, void *arg)
* that the reload command has been set,
* it doesn't say wether the command succeeded or not.
*/
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK,
+ imsg_compose_event(&c->iev, IMSG_CTL_OK,
0, 0, -1, NULL, 0);
break;
case IMSG_CTL_NOTIFY:
if (c->flags & CTL_CONN_NOTIFY) {
log_debug("control_dispatch_imsg: "
"client requested notify more than once");
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL,
0, 0, -1, NULL, 0);
break;
}
@@ -363,7 +364,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
imsg_free(&imsg);
}
- imsg_event_add(&c->ibuf);
+ imsg_event_add(&c->iev);
}
void
@@ -373,7 +374,7 @@ control_imsg_forward(struct imsg *imsg)
TAILQ_FOREACH(c, &ctl_conns, entry)
if (c->flags & CTL_CONN_NOTIFY)
- imsg_compose_event(&c->ibuf, imsg->hdr.type,
+ imsg_compose_event(&c->iev, imsg->hdr.type,
0, imsg->hdr.pid, -1, imsg->data,
imsg->hdr.len - IMSG_HEADER_SIZE);
}
diff --git a/usr.sbin/relayd/hce.c b/usr.sbin/relayd/hce.c
index 7f45ecf4e56..f33417f44b1 100644
--- a/usr.sbin/relayd/hce.c
+++ b/usr.sbin/relayd/hce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hce.c,v 1.52 2009/06/05 00:20:50 pyr Exp $ */
+/* $OpenBSD: hce.c,v 1.53 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -50,8 +50,8 @@ void hce_setup_events(void);
void hce_disable_events(void);
static struct relayd *env = NULL;
-struct imsgbuf *ibuf_pfe;
-struct imsgbuf *ibuf_main;
+struct imsgev *iev_pfe;
+struct imsgev *iev_main;
int running = 0;
void
@@ -117,21 +117,23 @@ hce(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
event_init();
- if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
+ if ((iev_pfe = calloc(1, sizeof(struct imsgev))) == NULL ||
+ (iev_main = calloc(1, sizeof(struct imsgev))) == NULL)
fatal("hce");
- imsg_init(ibuf_pfe, pipe_pfe2hce[0], hce_dispatch_imsg);
- imsg_init(ibuf_main, pipe_parent2hce[1], hce_dispatch_parent);
+ imsg_init(&iev_pfe->ibuf, pipe_pfe2hce[0]);
+ iev_pfe->handler = hce_dispatch_imsg;
+ imsg_init(&iev_main->ibuf, pipe_parent2hce[1]);
+ iev_main->handler = hce_dispatch_parent;
- ibuf_pfe->events = EV_READ;
- event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
- ibuf_pfe->handler, ibuf_pfe);
- event_add(&ibuf_pfe->ev, NULL);
+ iev_pfe->events = EV_READ;
+ event_set(&iev_pfe->ev, iev_pfe->ibuf.fd, iev_pfe->events,
+ iev_pfe->handler, iev_pfe);
+ event_add(&iev_pfe->ev, NULL);
- ibuf_main->events = EV_READ;
- event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
- ibuf_main->handler, ibuf_main);
- event_add(&ibuf_main->ev, NULL);
+ iev_main->events = EV_READ;
+ event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
+ iev_main->handler, iev_main);
+ event_add(&iev_main->ev, NULL);
signal_set(&ev_sigint, SIGINT, hce_sig_handler, NULL);
signal_set(&ev_sigterm, SIGTERM, hce_sig_handler, NULL);
@@ -165,7 +167,7 @@ hce_setup_events(void)
struct timeval tv;
struct table *table;
- snmp_init(env, ibuf_main);
+ snmp_init(env, iev_main);
if (!TAILQ_EMPTY(env->sc_tables)) {
evtimer_set(&env->sc_ev, hce_launch_checks, env);
@@ -217,7 +219,7 @@ hce_launch_checks(int fd, short event, void *arg)
/*
* notify pfe checks are done and schedule next check
*/
- imsg_compose_event(ibuf_pfe, IMSG_SYNC, 0, 0, -1, NULL, 0);
+ imsg_compose_event(iev_pfe, IMSG_SYNC, 0, 0, -1, NULL, 0);
TAILQ_FOREACH(table, env->sc_tables, entry) {
TAILQ_FOREACH(host, &table->hosts, entry) {
if ((host->flags & F_CHECK_DONE) == 0)
@@ -307,7 +309,7 @@ hce_notify_done(struct host *host, enum host_error he)
if (msg)
log_debug("hce_notify_done: %s (%s)", host->conf.name, msg);
- imsg_compose_event(ibuf_pfe, IMSG_HOST_STATUS,
+ imsg_compose_event(iev_pfe, IMSG_HOST_STATUS,
0, 0, -1, &st, sizeof(st));
if (host->up != host->last_up)
logopt = RELAYD_OPT_LOGUPDATE;
@@ -359,6 +361,7 @@ hce_shutdown(void)
void
hce_dispatch_imsg(int fd, short event, void *ptr)
{
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
@@ -366,14 +369,15 @@ hce_dispatch_imsg(int fd, short event, void *ptr)
struct host *host;
struct table *table;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("hce_dispatch_imsg: imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -438,12 +442,13 @@ hce_dispatch_imsg(int fd, short event, void *ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
hce_dispatch_parent(int fd, short event, void * ptr)
{
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
struct ctl_script scr;
@@ -452,14 +457,15 @@ hce_dispatch_parent(int fd, short event, void * ptr)
static struct table *table = NULL;
struct host *host, *parent;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("hce_dispatch_parent: imsg_read error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -535,5 +541,5 @@ hce_dispatch_parent(int fd, short event, void * ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
diff --git a/usr.sbin/relayd/imsg.c b/usr.sbin/relayd/imsg.c
index 8cfc017cab0..b91d123e266 100644
--- a/usr.sbin/relayd/imsg.c
+++ b/usr.sbin/relayd/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.22 2009/06/05 00:04:01 pyr Exp $ */
+/* $OpenBSD: imsg.c,v 1.23 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -29,13 +29,12 @@
#include "imsg.h"
void
-imsg_init(struct imsgbuf *ibuf, int fd, void (*handler)(int, short, void *))
+imsg_init(struct imsgbuf *ibuf, int fd)
{
if (!ibuf->pid) {
msgbuf_init(&ibuf->w);
bzero(&ibuf->r, sizeof(ibuf->r));
ibuf->pid = getpid();
- ibuf->handler = handler;
TAILQ_INIT(&ibuf->fds);
}
ibuf->fd = fd;
diff --git a/usr.sbin/relayd/imsg.h b/usr.sbin/relayd/imsg.h
index bf15876b94f..2454221e56d 100644
--- a/usr.sbin/relayd/imsg.h
+++ b/usr.sbin/relayd/imsg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.h,v 1.8 2009/06/05 21:15:47 pyr Exp $ */
+/* $OpenBSD: imsg.h,v 1.9 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -56,12 +56,8 @@ struct imsgbuf {
TAILQ_HEAD(, imsg_fd) fds;
struct buf_read r;
struct msgbuf w;
- struct event ev;
- void (*handler)(int, short, void *);
int fd;
pid_t pid;
- void *data;
- short events;
};
struct imsg_hdr {
@@ -93,7 +89,7 @@ void msgbuf_clear(struct msgbuf *);
int msgbuf_write(struct msgbuf *);
/* imsg.c */
-void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
+void imsg_init(struct imsgbuf *, int);
ssize_t imsg_read(struct imsgbuf *);
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
int imsg_compose(struct imsgbuf *, u_int16_t, u_int32_t, pid_t,
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 92dd86ab4af..c9bdef4bbfb 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.59 2009/06/05 00:20:50 pyr Exp $ */
+/* $OpenBSD: pfe.c,v 1.60 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -47,9 +47,9 @@ void pfe_statistics(int, short, void *);
static struct relayd *env = NULL;
-struct imsgbuf *ibuf_main;
-struct imsgbuf *ibuf_hce;
-struct imsgbuf *ibuf_relay;
+struct imsgev *iev_main;
+struct imsgev *iev_hce;
+struct imsgev *iev_relay;
void
pfe_sig_handler(int sig, short event, void *arg)
@@ -136,28 +136,31 @@ pfe(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
close(pipe_pfe2relay[i][0]);
}
- size = sizeof(struct imsgbuf);
- if ((ibuf_hce = calloc(1, size)) == NULL ||
- (ibuf_relay = calloc(env->sc_prefork_relay, size)) == NULL ||
- (ibuf_main = calloc(1, size)) == NULL)
+ size = sizeof(struct imsgev);
+ if ((iev_hce = calloc(1, size)) == NULL ||
+ (iev_relay = calloc(env->sc_prefork_relay, size)) == NULL ||
+ (iev_main = calloc(1, size)) == NULL)
fatal("pfe");
- imsg_init(ibuf_hce, pipe_pfe2hce[1], pfe_dispatch_imsg);
- imsg_init(ibuf_main, pipe_parent2pfe[1], pfe_dispatch_parent);
- for (i = 0; i < env->sc_prefork_relay; i++)
- imsg_init(&ibuf_relay[i], pipe_pfe2relay[i][1],
- pfe_dispatch_relay);
+ imsg_init(&iev_hce->ibuf, pipe_pfe2hce[1]);
+ iev_hce->handler = pfe_dispatch_imsg;
+ imsg_init(&iev_main->ibuf, pipe_parent2pfe[1]);
+ iev_main->handler = pfe_dispatch_parent;
+ for (i = 0; i < env->sc_prefork_relay; i++) {
+ imsg_init(&iev_relay[i].ibuf, pipe_pfe2relay[i][1]);
+ iev_relay[i].handler = pfe_dispatch_relay;
+ }
- ibuf_main->events = EV_READ;
- event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
- ibuf_main->handler, ibuf_main);
- event_add(&ibuf_main->ev, NULL);
+ iev_main->events = EV_READ;
+ event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
+ iev_main->handler, iev_main);
+ event_add(&iev_main->ev, NULL);
pfe_setup_events();
TAILQ_INIT(&ctl_conns);
- if (control_listen(env, ibuf_main, ibuf_hce) == -1)
+ if (control_listen(env, iev_main, iev_hce) == -1)
fatalx("pfe: control socket listen failed");
/* Initial sync */
@@ -181,21 +184,21 @@ void
pfe_setup_events(void)
{
int i;
- struct imsgbuf *ibuf;
+ struct imsgev *iev;
struct timeval tv;
- ibuf_hce->events = EV_READ;
- event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
- ibuf_hce->handler, ibuf_hce);
- event_add(&ibuf_hce->ev, NULL);
+ iev_hce->events = EV_READ;
+ event_set(&iev_hce->ev, iev_hce->ibuf.fd, iev_hce->events,
+ iev_hce->handler, iev_hce);
+ event_add(&iev_hce->ev, NULL);
for (i = 0; i < env->sc_prefork_relay; i++) {
- ibuf = &ibuf_relay[i];
+ iev = &iev_relay[i];
- ibuf->events = EV_READ;
- event_set(&ibuf->ev, ibuf->fd, ibuf->events,
- ibuf->handler, ibuf);
- event_add(&ibuf->ev, NULL);
+ iev->events = EV_READ;
+ event_set(&iev->ev, iev->ibuf.fd, iev->events,
+ iev->handler, iev);
+ event_add(&iev->ev, NULL);
}
/* Schedule statistics timer */
@@ -209,10 +212,10 @@ pfe_disable_events(void)
{
int i;
- event_del(&ibuf_hce->ev);
+ event_del(&iev_hce->ev);
for (i = 0; i < env->sc_prefork_relay; i++)
- event_del(&ibuf_relay[i].ev);
+ event_del(&iev_relay[i].ev);
event_del(&env->sc_statev);
}
@@ -220,6 +223,7 @@ pfe_disable_events(void)
void
pfe_dispatch_imsg(int fd, short event, void *ptr)
{
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
@@ -228,14 +232,15 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
struct table *table;
struct ctl_status st;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("pfe_dispatch_imsg: imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -280,7 +285,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
/* Forward to relay engine(s) */
for (n = 0; n < env->sc_prefork_relay; n++)
- imsg_compose_event(&ibuf_relay[n],
+ imsg_compose_event(&iev_relay[n],
IMSG_HOST_STATUS, 0, 0, -1, &st,
sizeof(st));
@@ -319,12 +324,13 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
pfe_dispatch_parent(int fd, short event, void * ptr)
{
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
@@ -334,14 +340,15 @@ pfe_dispatch_parent(int fd, short event, void * ptr)
struct host *host, *parent;
struct address *virt;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -442,12 +449,13 @@ pfe_dispatch_parent(int fd, short event, void * ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
pfe_dispatch_relay(int fd, short event, void * ptr)
{
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
@@ -455,14 +463,15 @@ pfe_dispatch_relay(int fd, short event, void * ptr)
struct ctl_stats crs;
struct relay *rlay;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -489,7 +498,7 @@ pfe_dispatch_relay(int fd, short event, void * ptr)
"invalid relay proc");
if (natlook(env, &cnl) != 0)
cnl.in = -1;
- imsg_compose_event(&ibuf_relay[cnl.proc], IMSG_NATLOOK,
+ imsg_compose_event(&iev_relay[cnl.proc], IMSG_NATLOOK,
0, 0, -1, &cnl, sizeof(cnl));
break;
case IMSG_STATISTICS:
@@ -512,7 +521,7 @@ pfe_dispatch_relay(int fd, short event, void * ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
@@ -525,28 +534,28 @@ show(struct ctl_conn *c)
if (env->sc_rdrs == NULL)
goto relays;
TAILQ_FOREACH(rdr, env->sc_rdrs, entry) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_RDR, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_RDR, 0, 0, -1,
rdr, sizeof(*rdr));
if (rdr->conf.flags & F_DISABLE)
continue;
- imsg_compose_event(&c->ibuf, IMSG_CTL_RDR_STATS, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_RDR_STATS, 0, 0, -1,
&rdr->stats, sizeof(rdr->stats));
- imsg_compose_event(&c->ibuf, IMSG_CTL_TABLE, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_TABLE, 0, 0, -1,
rdr->table, sizeof(*rdr->table));
if (!(rdr->table->conf.flags & F_DISABLE))
TAILQ_FOREACH(host, &rdr->table->hosts, entry)
- imsg_compose_event(&c->ibuf, IMSG_CTL_HOST,
+ imsg_compose_event(&c->iev, IMSG_CTL_HOST,
0, 0, -1, host, sizeof(*host));
if (rdr->backup->conf.id == EMPTY_TABLE)
continue;
- imsg_compose_event(&c->ibuf, IMSG_CTL_TABLE, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_TABLE, 0, 0, -1,
rdr->backup, sizeof(*rdr->backup));
if (!(rdr->backup->conf.flags & F_DISABLE))
TAILQ_FOREACH(host, &rdr->backup->hosts, entry)
- imsg_compose_event(&c->ibuf, IMSG_CTL_HOST,
+ imsg_compose_event(&c->iev, IMSG_CTL_HOST,
0, 0, -1, host, sizeof(*host));
}
relays:
@@ -554,22 +563,22 @@ relays:
goto end;
TAILQ_FOREACH(rlay, env->sc_relays, rl_entry) {
rlay->rl_stats[env->sc_prefork_relay].id = EMPTY_ID;
- imsg_compose_event(&c->ibuf, IMSG_CTL_RELAY, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_RELAY, 0, 0, -1,
rlay, sizeof(*rlay));
- imsg_compose_event(&c->ibuf, IMSG_CTL_RELAY_STATS, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_RELAY_STATS, 0, 0, -1,
&rlay->rl_stats, sizeof(rlay->rl_stats));
if (rlay->rl_dsttable == NULL)
continue;
- imsg_compose_event(&c->ibuf, IMSG_CTL_TABLE, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_TABLE, 0, 0, -1,
rlay->rl_dsttable, sizeof(*rlay->rl_dsttable));
if (!(rlay->rl_dsttable->conf.flags & F_DISABLE))
TAILQ_FOREACH(host, &rlay->rl_dsttable->hosts, entry)
- imsg_compose_event(&c->ibuf, IMSG_CTL_HOST,
+ imsg_compose_event(&c->iev, IMSG_CTL_HOST,
0, 0, -1, host, sizeof(*host));
}
end:
- imsg_compose_event(&c->ibuf, IMSG_CTL_END, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_END, 0, 0, -1, NULL, 0);
}
void
@@ -582,10 +591,10 @@ show_sessions(struct ctl_conn *c)
/*
* Request all the running sessions from the process
*/
- imsg_compose_event(&ibuf_relay[proc],
+ imsg_compose_event(&iev_relay[proc],
IMSG_CTL_SESSION, 0, 0, -1, NULL, 0);
- while (ibuf_relay[proc].w.queued)
- if (msgbuf_write(&ibuf_relay[proc].w) < 0)
+ while (iev_relay[proc].ibuf.w.queued)
+ if (msgbuf_write(&iev_relay[proc].ibuf.w) < 0)
fatalx("write error");
/*
@@ -595,18 +604,18 @@ show_sessions(struct ctl_conn *c)
done = 0;
while (!done) {
do {
- if ((n = imsg_read(&ibuf_relay[proc])) == -1)
+ if ((n = imsg_read(&iev_relay[proc].ibuf)) == -1)
fatalx("imsg_read error");
} while (n == -2); /* handle non-blocking I/O */
while (!done) {
- if ((n = imsg_get(&ibuf_relay[proc],
+ if ((n = imsg_get(&iev_relay[proc].ibuf,
&imsg)) == -1)
fatalx("imsg_get error");
if (n == 0)
break;
switch (imsg.hdr.type) {
case IMSG_CTL_SESSION:
- imsg_compose_event(&c->ibuf,
+ imsg_compose_event(&c->iev,
IMSG_CTL_SESSION, proc, 0, -1,
imsg.data, sizeof(struct session));
break;
@@ -622,7 +631,7 @@ show_sessions(struct ctl_conn *c)
}
}
- imsg_compose_event(&c->ibuf, IMSG_CTL_END, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_END, 0, 0, -1, NULL, 0);
}
int
@@ -709,7 +718,7 @@ disable_table(struct ctl_conn *c, struct ctl_id *id)
table->up = 0;
TAILQ_FOREACH(host, &table->hosts, entry)
host->up = HOST_UNKNOWN;
- imsg_compose_event(ibuf_hce, IMSG_TABLE_DISABLE, 0, 0, -1,
+ imsg_compose_event(iev_hce, IMSG_TABLE_DISABLE, 0, 0, -1,
&table->conf.id, sizeof(table->conf.id));
log_debug("disable_table: disabled table %d", table->conf.id);
pfe_sync();
@@ -741,7 +750,7 @@ enable_table(struct ctl_conn *c, struct ctl_id *id)
table->up = 0;
TAILQ_FOREACH(host, &table->hosts, entry)
host->up = HOST_UNKNOWN;
- imsg_compose_event(ibuf_hce, IMSG_TABLE_ENABLE, 0, 0, -1,
+ imsg_compose_event(iev_hce, IMSG_TABLE_ENABLE, 0, 0, -1,
&table->conf.id, sizeof(table->conf.id));
log_debug("enable_table: enabled table %d", table->conf.id);
pfe_sync();
@@ -782,11 +791,11 @@ disable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host)
host->check_cnt = 0;
host->up_cnt = 0;
- imsg_compose_event(ibuf_hce, IMSG_HOST_DISABLE, 0, 0, -1,
+ imsg_compose_event(iev_hce, IMSG_HOST_DISABLE, 0, 0, -1,
&host->conf.id, sizeof(host->conf.id));
/* Forward to relay engine(s) */
for (n = 0; n < env->sc_prefork_relay; n++)
- imsg_compose_event(&ibuf_relay[n],
+ imsg_compose_event(&iev_relay[n],
IMSG_HOST_DISABLE, 0, 0, -1,
&host->conf.id, sizeof(host->conf.id));
log_debug("disable_host: disabled host %d", host->conf.id);
@@ -824,11 +833,11 @@ enable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host)
host->flags &= ~(F_DEL);
host->flags &= ~(F_ADD);
- imsg_compose_event(ibuf_hce, IMSG_HOST_ENABLE, 0, 0, -1,
+ imsg_compose_event(iev_hce, IMSG_HOST_ENABLE, 0, 0, -1,
&host->conf.id, sizeof (host->conf.id));
/* Forward to relay engine(s) */
for (n = 0; n < env->sc_prefork_relay; n++)
- imsg_compose_event(&ibuf_relay[n],
+ imsg_compose_event(&iev_relay[n],
IMSG_HOST_ENABLE, 0, 0, -1,
&host->conf.id, sizeof(host->conf.id));
log_debug("enable_host: enabled host %d", host->conf.id);
@@ -931,7 +940,7 @@ pfe_sync(void)
demote.level, table->conf.name, table->conf.demote_group);
(void)strlcpy(demote.group, table->conf.demote_group,
sizeof(demote.group));
- imsg_compose_event(ibuf_main, IMSG_DEMOTE, 0, 0, -1,
+ imsg_compose_event(iev_main, IMSG_DEMOTE, 0, 0, -1,
&demote, sizeof(demote));
}
}
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c
index 12366c63a52..98f049fcbe4 100644
--- a/usr.sbin/relayd/relay.c
+++ b/usr.sbin/relayd/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.114 2009/06/05 00:20:50 pyr Exp $ */
+/* $OpenBSD: relay.c,v 1.115 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -133,8 +133,8 @@ volatile sig_atomic_t relay_sessions;
objid_t relay_conid;
static struct relayd *env = NULL;
-struct imsgbuf *ibuf_pfe;
-struct imsgbuf *ibuf_main;
+struct imsgev *iev_pfe;
+struct imsgev *iev_main;
int proc_id;
void
@@ -234,22 +234,23 @@ relay(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
close(pipe_parent2relay[proc_id][1]);
close(pipe_pfe2relay[proc_id][1]);
- if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
+ if ((iev_pfe = calloc(1, sizeof(struct imsgev))) == NULL ||
+ (iev_main = calloc(1, sizeof(struct imsgev))) == NULL)
fatal("relay");
- imsg_init(ibuf_main, pipe_parent2relay[proc_id][0],
- relay_dispatch_parent);
- imsg_init(ibuf_pfe, pipe_pfe2relay[proc_id][0], relay_dispatch_pfe);
+ imsg_init(&iev_pfe->ibuf, pipe_pfe2relay[proc_id][0]);
+ imsg_init(&iev_main->ibuf, pipe_parent2relay[proc_id][0]);
+ iev_pfe->handler = relay_dispatch_pfe;
+ iev_main->handler = relay_dispatch_parent;
- ibuf_pfe->events = EV_READ;
- event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
- ibuf_pfe->handler, ibuf_pfe);
- event_add(&ibuf_pfe->ev, NULL);
+ iev_pfe->events = EV_READ;
+ event_set(&iev_pfe->ev, iev_pfe->ibuf.fd, iev_pfe->events,
+ iev_pfe->handler, iev_pfe);
+ event_add(&iev_pfe->ev, NULL);
- ibuf_main->events = EV_READ;
- event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
- ibuf_main->handler, ibuf_main);
- event_add(&ibuf_main->ev, NULL);
+ iev_main->events = EV_READ;
+ event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
+ iev_main->handler, iev_main);
+ event_add(&iev_main->ev, NULL);
relay_launch();
@@ -556,7 +557,7 @@ relay_statistics(int fd, short events, void *arg)
crs.id = rlay->rl_conf.id;
crs.proc = proc_id;
- imsg_compose_event(ibuf_pfe, IMSG_STATISTICS, 0, 0, -1,
+ imsg_compose_event(iev_pfe, IMSG_STATISTICS, 0, 0, -1,
&crs, sizeof(crs));
for (con = SPLAY_ROOT(&rlay->rl_sessions);
@@ -2042,7 +2043,7 @@ relay_accept(int fd, short sig, void *arg)
return;
}
- imsg_compose_event(ibuf_pfe, IMSG_NATLOOK, 0, 0, -1, cnl,
+ imsg_compose_event(iev_pfe, IMSG_NATLOOK, 0, 0, -1, cnl,
sizeof(*cnl));
/* Schedule timeout */
@@ -2220,7 +2221,7 @@ relay_bindanyreq(struct session *con, in_port_t port, int proto)
bnd.bnd_port = port;
bnd.bnd_proto = proto;
bcopy(&con->se_in.ss, &bnd.bnd_ss, sizeof(bnd.bnd_ss));
- imsg_compose_event(ibuf_main, IMSG_BINDANY,
+ imsg_compose_event(iev_main, IMSG_BINDANY,
0, 0, -1, &bnd, sizeof(bnd));
/* Schedule timeout */
@@ -2379,7 +2380,7 @@ relay_close(struct session *con, const char *msg)
if (con->se_cnl != NULL) {
#if 0
- imsg_compose_event(ibuf_pfe, IMSG_KILLSTATES, 0, 0, -1,
+ imsg_compose_event(iev_pfe, IMSG_KILLSTATES, 0, 0, -1,
cnl, sizeof(*cnl));
#endif
free(con->se_cnl);
@@ -2392,6 +2393,7 @@ relay_close(struct session *con, const char *msg)
void
relay_dispatch_pfe(int fd, short event, void *ptr)
{
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
@@ -2404,14 +2406,15 @@ relay_dispatch_pfe(int fd, short event, void *ptr)
struct ctl_status st;
objid_t id;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("relay_dispatch_pfe: imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -2499,10 +2502,10 @@ relay_dispatch_pfe(int fd, short event, void *ptr)
TAILQ_FOREACH(rlay, env->sc_relays, rl_entry)
SPLAY_FOREACH(con, session_tree,
&rlay->rl_sessions)
- imsg_compose_event(ibuf,
+ imsg_compose_event(iev,
IMSG_CTL_SESSION,
0, 0, -1, con, sizeof(*con));
- imsg_compose_event(ibuf, IMSG_CTL_END,
+ imsg_compose_event(iev, IMSG_CTL_END,
0, 0, -1, NULL, 0);
break;
default:
@@ -2512,27 +2515,29 @@ relay_dispatch_pfe(int fd, short event, void *ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
relay_dispatch_parent(int fd, short event, void * ptr)
{
struct session *con;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
struct timeval tv;
objid_t id;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("relay_dispatch_parent: imsg_read error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -2573,7 +2578,7 @@ relay_dispatch_parent(int fd, short event, void * ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
SSL_CTX *
diff --git a/usr.sbin/relayd/relay_udp.c b/usr.sbin/relayd/relay_udp.c
index f323807268b..d5ff36f74d3 100644
--- a/usr.sbin/relayd/relay_udp.c
+++ b/usr.sbin/relayd/relay_udp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay_udp.c,v 1.19 2009/06/05 00:04:01 pyr Exp $ */
+/* $OpenBSD: relay_udp.c,v 1.20 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -50,7 +50,7 @@
extern volatile sig_atomic_t relay_sessions;
extern objid_t relay_conid;
extern int proc_id;
-extern struct imsgbuf *ibuf_pfe;
+extern struct imsgev *iev_pfe;
extern int debug;
struct relayd *env = NULL;
@@ -321,7 +321,7 @@ relay_udp_server(int fd, short sig, void *arg)
cnl->proto = IPPROTO_UDP;
bcopy(&con->se_in.ss, &cnl->src, sizeof(cnl->src));
bcopy(&rlay->rl_conf.ss, &cnl->dst, sizeof(cnl->dst));
- imsg_compose_event(ibuf_pfe, IMSG_NATLOOK, 0, 0, -1, cnl,
+ imsg_compose_event(iev_pfe, IMSG_NATLOOK, 0, 0, -1, cnl,
sizeof(*cnl));
/* Schedule timeout */
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index c1b49370c4d..eb33e59fe53 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.c,v 1.88 2009/06/05 00:20:50 pyr Exp $ */
+/* $OpenBSD: relayd.c,v 1.89 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -66,9 +66,9 @@ int pipe_pfe2relay[RELAY_MAXPROC][2];
struct relayd *relayd_env;
-struct imsgbuf *ibuf_pfe;
-struct imsgbuf *ibuf_hce;
-struct imsgbuf *ibuf_relay;
+struct imsgev *iev_pfe;
+struct imsgev *iev_hce;
+struct imsgev *iev_relay;
pid_t pfe_pid = 0;
pid_t hce_pid = 0;
@@ -132,7 +132,7 @@ main(int argc, char *argv[])
struct event ev_sigterm;
struct event ev_sigchld;
struct event ev_sighup;
- struct imsgbuf *ibuf;
+ struct imsgev *iev;
opts = 0;
debug = 0;
@@ -257,36 +257,40 @@ main(int argc, char *argv[])
close(pipe_parent2relay[c][0]);
}
- if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_hce = calloc(1, sizeof(struct imsgbuf))) == NULL)
+ if ((iev_pfe = calloc(1, sizeof(struct imsgev))) == NULL ||
+ (iev_hce = calloc(1, sizeof(struct imsgev))) == NULL)
fatal(NULL);
if (env->sc_prefork_relay > 0) {
- if ((ibuf_relay = calloc(env->sc_prefork_relay,
- sizeof(struct imsgbuf))) == NULL)
+ if ((iev_relay = calloc(env->sc_prefork_relay,
+ sizeof(struct imsgev))) == NULL)
fatal(NULL);
}
- imsg_init(ibuf_pfe, pipe_parent2pfe[0], main_dispatch_pfe);
- imsg_init(ibuf_hce, pipe_parent2hce[0], main_dispatch_hce);
+ imsg_init(&iev_pfe->ibuf, pipe_parent2pfe[0]);
+ imsg_init(&iev_hce->ibuf, pipe_parent2hce[0]);
+ iev_pfe->handler = main_dispatch_pfe;
+ iev_hce->handler = main_dispatch_hce;
+
for (c = 0; c < env->sc_prefork_relay; c++) {
- ibuf = &ibuf_relay[c];
- imsg_init(ibuf, pipe_parent2relay[c][1], main_dispatch_relay);
- ibuf->events = EV_READ;
- event_set(&ibuf->ev, ibuf->fd, ibuf->events,
- ibuf->handler, ibuf);
- event_add(&ibuf->ev, NULL);
+ iev = &iev_relay[c];
+ imsg_init(&iev->ibuf, pipe_parent2relay[c][1]);
+ iev->handler = main_dispatch_relay;
+ iev->events = EV_READ;
+ event_set(&iev->ev, iev->ibuf.fd, iev->events,
+ iev->handler, iev);
+ event_add(&iev->ev, NULL);
}
- ibuf_pfe->events = EV_READ;
- event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
- ibuf_pfe->handler, ibuf_pfe);
- event_add(&ibuf_pfe->ev, NULL);
+ iev_pfe->events = EV_READ;
+ event_set(&iev_pfe->ev, iev_pfe->ibuf.fd, iev_pfe->events,
+ iev_pfe->handler, iev_pfe);
+ event_add(&iev_pfe->ev, NULL);
- ibuf_hce->events = EV_READ;
- event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
- ibuf_hce->handler, ibuf_hce);
- event_add(&ibuf_hce->ev, NULL);
+ iev_hce->events = EV_READ;
+ event_set(&iev_hce->ev, iev_hce->ibuf.fd, iev_hce->events,
+ iev_hce->handler, iev_hce);
+ event_add(&iev_hce->ev, NULL);
if (env->sc_flags & F_DEMOTE)
carp_demote_reset(env->sc_demote_group, 0);
@@ -347,12 +351,12 @@ send_all(struct relayd *env, enum imsg_type type, void *buf, u_int16_t len)
{
int i;
- if (imsg_compose_event(ibuf_pfe, type, 0, 0, -1, buf, len) == -1)
+ if (imsg_compose_event(iev_pfe, type, 0, 0, -1, buf, len) == -1)
return (-1);
- if (imsg_compose_event(ibuf_hce, type, 0, 0, -1, buf, len) == -1)
+ if (imsg_compose_event(iev_hce, type, 0, 0, -1, buf, len) == -1)
return (-1);
for (i = 0; i < env->sc_prefork_relay; i++) {
- if (imsg_compose_event(&ibuf_relay[i], type, 0, 0, -1, buf, len)
+ if (imsg_compose_event(&iev_relay[i], type, 0, 0, -1, buf, len)
== -1)
return (-1);
}
@@ -422,41 +426,41 @@ reconfigure(void)
/*
* first reconfigure pfe
*/
- imsg_compose_event(ibuf_pfe, IMSG_RECONF, 0, 0, -1, env, sizeof(*env));
+ imsg_compose_event(iev_pfe, IMSG_RECONF, 0, 0, -1, env, sizeof(*env));
TAILQ_FOREACH(table, env->sc_tables, entry) {
- imsg_compose_event(ibuf_pfe, IMSG_RECONF_TABLE, 0, 0, -1,
+ imsg_compose_event(iev_pfe, IMSG_RECONF_TABLE, 0, 0, -1,
&table->conf, sizeof(table->conf));
TAILQ_FOREACH(host, &table->hosts, entry) {
- imsg_compose_event(ibuf_pfe, IMSG_RECONF_HOST, 0, 0, -1,
+ imsg_compose_event(iev_pfe, IMSG_RECONF_HOST, 0, 0, -1,
&host->conf, sizeof(host->conf));
}
}
TAILQ_FOREACH(rdr, env->sc_rdrs, entry) {
- imsg_compose_event(ibuf_pfe, IMSG_RECONF_RDR, 0, 0, -1,
+ imsg_compose_event(iev_pfe, IMSG_RECONF_RDR, 0, 0, -1,
&rdr->conf, sizeof(rdr->conf));
TAILQ_FOREACH(virt, &rdr->virts, entry)
- imsg_compose_event(ibuf_pfe, IMSG_RECONF_VIRT, 0, 0, -1,
+ imsg_compose_event(iev_pfe, IMSG_RECONF_VIRT, 0, 0, -1,
virt, sizeof(*virt));
}
- imsg_compose_event(ibuf_pfe, IMSG_RECONF_END, 0, 0, -1, NULL, 0);
+ imsg_compose_event(iev_pfe, IMSG_RECONF_END, 0, 0, -1, NULL, 0);
/*
* then reconfigure hce
*/
- imsg_compose_event(ibuf_hce, IMSG_RECONF, 0, 0, -1, env, sizeof(*env));
+ imsg_compose_event(iev_hce, IMSG_RECONF, 0, 0, -1, env, sizeof(*env));
TAILQ_FOREACH(table, env->sc_tables, entry) {
- imsg_compose_event(ibuf_hce, IMSG_RECONF_TABLE, 0, 0, -1,
+ imsg_compose_event(iev_hce, IMSG_RECONF_TABLE, 0, 0, -1,
&table->conf, sizeof(table->conf));
if (table->sendbuf != NULL)
- imsg_compose_event(ibuf_hce, IMSG_RECONF_SENDBUF,
+ imsg_compose_event(iev_hce, IMSG_RECONF_SENDBUF,
0, 0, -1, table->sendbuf,
strlen(table->sendbuf) + 1);
TAILQ_FOREACH(host, &table->hosts, entry) {
- imsg_compose_event(ibuf_hce, IMSG_RECONF_HOST, 0, 0, -1,
+ imsg_compose_event(iev_hce, IMSG_RECONF_HOST, 0, 0, -1,
&host->conf, sizeof(host->conf));
}
}
- imsg_compose_event(ibuf_hce, IMSG_RECONF_END, 0, 0, -1, NULL, 0);
+ imsg_compose_event(iev_hce, IMSG_RECONF_END, 0, 0, -1, NULL, 0);
}
void
@@ -571,50 +575,52 @@ purge_table(struct tablelist *head, struct table *table)
}
void
-imsg_event_add(struct imsgbuf *ibuf)
+imsg_event_add(struct imsgev *iev)
{
- if (ibuf->handler == NULL) {
- imsg_flush(ibuf);
+ if (iev->handler == NULL) {
+ imsg_flush(&iev->ibuf);
return;
}
- ibuf->events = EV_READ;
- if (ibuf->w.queued)
- ibuf->events |= EV_WRITE;
+ iev->events = EV_READ;
+ if (iev->ibuf.w.queued)
+ iev->events |= EV_WRITE;
- event_del(&ibuf->ev);
- event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf);
- event_add(&ibuf->ev, NULL);
+ event_del(&iev->ev);
+ event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev);
+ event_add(&iev->ev, NULL);
}
int
-imsg_compose_event(struct imsgbuf *ibuf, u_int16_t type, u_int32_t peerid,
- pid_t pid, int fd, void *data, u_int16_t datalen)
+imsg_compose_event(struct imsgev *iev, u_int16_t type,
+ u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen)
{
int ret;
- if ((ret = imsg_compose(ibuf, type, peerid,
+ if ((ret = imsg_compose(&iev->ibuf, type, peerid,
pid, fd, data, datalen)) != -1)
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
return (ret);
}
void
main_dispatch_pfe(int fd, short event, void *ptr)
{
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
struct ctl_demote demote;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -653,12 +659,13 @@ main_dispatch_pfe(int fd, short event, void *ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
main_dispatch_hce(int fd, short event, void * ptr)
{
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
@@ -666,14 +673,15 @@ main_dispatch_hce(int fd, short event, void * ptr)
struct relayd *env;
env = relayd_env;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -698,11 +706,11 @@ main_dispatch_hce(int fd, short event, void * ptr)
"invalid size of script request");
bcopy(imsg.data, &scr, sizeof(scr));
scr.retval = script_exec(env, &scr);
- imsg_compose_event(ibuf_hce, IMSG_SCRIPT,
+ imsg_compose_event(iev_hce, IMSG_SCRIPT,
0, 0, -1, &scr, sizeof(scr));
break;
case IMSG_SNMPSOCK:
- (void)snmp_sendsock(ibuf);
+ (void)snmp_sendsock(iev);
break;
default:
log_debug("main_dispatch_hce: unexpected imsg %d",
@@ -711,27 +719,29 @@ main_dispatch_hce(int fd, short event, void * ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
main_dispatch_relay(int fd, short event, void * ptr)
{
struct relayd *env = relayd_env;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
struct ctl_bindany bnd;
int s;
- ibuf = ptr;
+ iev = ptr;
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -766,7 +776,7 @@ main_dispatch_relay(int fd, short event, void * ptr)
/* NOTREACHED */
}
s = bindany(&bnd);
- imsg_compose_event(&ibuf_relay[bnd.bnd_proc],
+ imsg_compose_event(&iev_relay[bnd.bnd_proc],
IMSG_BINDANY,
0, 0, s, &bnd.bnd_id, sizeof(bnd.bnd_id));
break;
@@ -777,7 +787,7 @@ main_dispatch_relay(int fd, short event, void * ptr)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
struct host *
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 5e2ee27b327..8de34988acd 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.124 2009/06/05 00:04:01 pyr Exp $ */
+/* $OpenBSD: relayd.h,v 1.125 2009/06/05 23:39:51 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -635,11 +635,19 @@ enum blockmodes {
BM_NONBLOCK
};
+struct imsgev {
+ struct imsgbuf ibuf;
+ void (*handler)(int, short, void *);
+ struct event ev;
+ void *data;
+ short events;
+};
+
struct ctl_conn {
TAILQ_ENTRY(ctl_conn) entry;
u_int8_t flags;
#define CTL_CONN_NOTIFY 0x01
- struct imsgbuf ibuf;
+ struct imsgev iev;
};
TAILQ_HEAD(ctl_connlist, ctl_conn);
@@ -701,7 +709,7 @@ enum imsg_type {
/* control.c */
int control_init(void);
-int control_listen(struct relayd *, struct imsgbuf *, struct imsgbuf *);
+int control_listen(struct relayd *, struct imsgev *, struct imsgev *);
void control_accept(int, short, void *);
void control_dispatch_imsg(int, short, void *);
void control_imsg_forward(struct imsg *);
@@ -830,8 +838,8 @@ int protonode_load(enum direction, struct protocol *,
struct protonode *, const char *);
int map6to4(struct sockaddr_storage *);
int map4to6(struct sockaddr_storage *, struct sockaddr_storage *);
-void imsg_event_add(struct imsgbuf *);
-int imsg_compose_event(struct imsgbuf *, u_int16_t, u_int32_t,
+void imsg_event_add(struct imsgev *);
+int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t,
pid_t, int, void *, u_int16_t);
/* carp.c */
@@ -848,8 +856,8 @@ void pn_unref(u_int16_t);
void pn_ref(u_int16_t);
/* snmp.c */
-void snmp_init(struct relayd *, struct imsgbuf *);
-int snmp_sendsock(struct imsgbuf *);
+void snmp_init(struct relayd *, struct imsgev *);
+int snmp_sendsock(struct imsgev *);
void snmp_hosttrap(struct table *, struct host *);
/* shuffle.c */
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);
}