summaryrefslogtreecommitdiff
path: root/usr.sbin/dvmrpd/dvmrpe.c
diff options
context:
space:
mode:
authorPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-06 07:52:05 +0000
committerPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-06 07:52:05 +0000
commitc0022c393ab5435ed57bed21adceb48a959e494f (patch)
tree5039b99b8f6812acece6ce748d22df8e49ef758b /usr.sbin/dvmrpd/dvmrpe.c
parentcd9e24e8e0859fe9e77873ee1d58d24c53926189 (diff)
make dvmrpd imsg-in-a-lib ready as well.
``put it in'' claudio@, ok eric@
Diffstat (limited to 'usr.sbin/dvmrpd/dvmrpe.c')
-rw-r--r--usr.sbin/dvmrpd/dvmrpe.c74
1 files changed, 40 insertions, 34 deletions
diff --git a/usr.sbin/dvmrpd/dvmrpe.c b/usr.sbin/dvmrpd/dvmrpe.c
index 00ad87565aa..16bb4fb634f 100644
--- a/usr.sbin/dvmrpd/dvmrpe.c
+++ b/usr.sbin/dvmrpd/dvmrpe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dvmrpe.c,v 1.6 2009/05/31 20:31:35 jacekm Exp $ */
+/* $OpenBSD: dvmrpe.c,v 1.7 2009/06/06 07:52:04 pyr Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -47,8 +47,8 @@ void dvmrpe_shutdown(void);
volatile sig_atomic_t dvmrpe_quit = 0;
struct dvmrpd_conf *deconf = NULL;
-struct imsgbuf *ibuf_main;
-struct imsgbuf *ibuf_rde;
+struct imsgev *iev_main;
+struct imsgev *iev_rde;
struct ctl_conn *ctl_conn;
void
@@ -140,22 +140,25 @@ dvmrpe(struct dvmrpd_conf *xconf, int pipe_parent2dvmrpe[2],
close(pipe_parent2rde[0]);
close(pipe_parent2rde[1]);
- if ((ibuf_rde = malloc(sizeof(struct imsgbuf))) == NULL ||
- (ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL)
+ if ((iev_rde = malloc(sizeof(struct imsgev))) == NULL ||
+ (iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
- imsg_init(ibuf_rde, pipe_dvmrpe2rde[0], dvmrpe_dispatch_rde);
- imsg_init(ibuf_main, pipe_parent2dvmrpe[1], dvmrpe_dispatch_main);
+ imsg_init(&iev_rde->ibuf, pipe_dvmrpe2rde[0]);
+ iev_rde->handler = dvmrpe_dispatch_rde;
+
+ imsg_init(&iev_main->ibuf, pipe_parent2dvmrpe[1]);
+ iev_main->handler = dvmrpe_dispatch_main;
/* setup event handler */
- ibuf_rde->events = EV_READ;
- event_set(&ibuf_rde->ev, ibuf_rde->fd, ibuf_rde->events,
- ibuf_rde->handler, ibuf_rde);
- event_add(&ibuf_rde->ev, NULL);
+ iev_rde->events = EV_READ;
+ event_set(&iev_rde->ev, iev_rde->ibuf.fd, iev_rde->events,
+ iev_rde->handler, iev_rde);
+ event_add(&iev_rde->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);
event_set(&deconf->ev, deconf->dvmrp_socket, EV_READ|EV_PERSIST,
recv_packet, deconf);
@@ -201,12 +204,12 @@ dvmrpe_shutdown(void)
}
/* clean up */
- msgbuf_write(&ibuf_rde->w);
- msgbuf_clear(&ibuf_rde->w);
- free(ibuf_rde);
- msgbuf_write(&ibuf_main->w);
- msgbuf_clear(&ibuf_main->w);
- free(ibuf_main);
+ msgbuf_write(&iev_rde->ibuf.w);
+ msgbuf_clear(&iev_rde->ibuf.w);
+ free(iev_rde);
+ msgbuf_write(&iev_main->ibuf.w);
+ msgbuf_clear(&iev_main->ibuf.w);
+ free(iev_main);
free(pkt_ptr);
log_info("dvmrp engine exiting");
@@ -216,21 +219,23 @@ dvmrpe_shutdown(void)
int
dvmrpe_imsg_compose_parent(int type, pid_t pid, void *data, u_int16_t datalen)
{
- return (imsg_compose(ibuf_main, type, 0, pid, data, datalen));
+ return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen));
}
int
dvmrpe_imsg_compose_rde(int type, u_int32_t peerid, pid_t pid,
void *data, u_int16_t datalen)
{
- return (imsg_compose(ibuf_rde, type, peerid, pid, data, datalen));
+ return (imsg_compose_event(iev_rde, type, peerid, pid,
+ -1, data, datalen));
}
void
dvmrpe_dispatch_main(int fd, short event, void *bula)
{
struct imsg imsg;
- struct imsgbuf *ibuf = bula;
+ struct imsgev *iev = bula;
+ struct imsgbuf *ibuf = &iev->ibuf;
ssize_t n;
if (event & EV_READ) {
@@ -258,13 +263,14 @@ dvmrpe_dispatch_main(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
dvmrpe_dispatch_rde(int fd, short event, void *bula)
{
- struct imsgbuf *ibuf = bula;
+ struct imsgev *iev = bula;
+ struct imsgbuf *ibuf = &iev->ibuf;
struct imsg imsg;
struct nbr *nbr;
struct prune p;
@@ -403,7 +409,7 @@ dvmrpe_dispatch_rde(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
@@ -415,8 +421,8 @@ dvmrpe_iface_ctl(struct ctl_conn *c, unsigned int idx)
LIST_FOREACH(iface, &deconf->iface_list, entry)
if (idx == 0 || idx == iface->ifindex) {
ictl = if_to_ctl(iface);
- imsg_compose(&c->ibuf, IMSG_CTL_SHOW_IFACE,
- 0, 0, ictl, sizeof(struct ctl_iface));
+ imsg_compose_event(&c->iev, IMSG_CTL_SHOW_IFACE,
+ 0, 0, -1, ictl, sizeof(struct ctl_iface));
}
}
@@ -429,8 +435,8 @@ dvmrpe_iface_igmp_ctl(struct ctl_conn *c, unsigned int idx)
LIST_FOREACH(iface, &deconf->iface_list, entry)
if (idx == 0 || idx == iface->ifindex) {
ictl = if_to_ctl(iface);
- imsg_compose(&c->ibuf, IMSG_CTL_SHOW_IFACE,
- 0, 0, ictl, sizeof(struct ctl_iface));
+ imsg_compose_event(&c->iev, IMSG_CTL_SHOW_IFACE,
+ 0, 0, -1, ictl, sizeof(struct ctl_iface));
group_list_dump(iface, c);
}
@@ -446,9 +452,9 @@ dvmrpe_nbr_ctl(struct ctl_conn *c)
LIST_FOREACH(iface, &deconf->iface_list, entry)
LIST_FOREACH(nbr, &iface->nbr_list, entry) {
nctl = nbr_to_ctl(nbr);
- imsg_compose(&c->ibuf, IMSG_CTL_SHOW_NBR, 0, 0, nctl,
- sizeof(struct ctl_nbr));
+ imsg_compose_event(&c->iev, IMSG_CTL_SHOW_NBR,
+ 0, 0, -1, nctl, sizeof(struct ctl_nbr));
}
- imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_END, 0, 0, -1, NULL, 0);
}