diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ospfctl/ospfctl.c | 4 | ||||
-rw-r--r-- | usr.sbin/ospfd/auth.c | 4 | ||||
-rw-r--r-- | usr.sbin/ospfd/buffer.c | 2 | ||||
-rw-r--r-- | usr.sbin/ospfd/control.c | 41 | ||||
-rw-r--r-- | usr.sbin/ospfd/control.h | 4 | ||||
-rw-r--r-- | usr.sbin/ospfd/imsg.c | 9 | ||||
-rw-r--r-- | usr.sbin/ospfd/imsg.h | 9 | ||||
-rw-r--r-- | usr.sbin/ospfd/lsreq.c | 6 | ||||
-rw-r--r-- | usr.sbin/ospfd/lsupdate.c | 6 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.c | 89 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.h | 14 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfe.c | 76 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfe.h | 4 | ||||
-rw-r--r-- | usr.sbin/ospfd/rde.c | 102 |
14 files changed, 198 insertions, 172 deletions
diff --git a/usr.sbin/ospfctl/ospfctl.c b/usr.sbin/ospfctl/ospfctl.c index 9af336ba8b0..99a4ad8fc89 100644 --- a/usr.sbin/ospfctl/ospfctl.c +++ b/usr.sbin/ospfctl/ospfctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfctl.c,v 1.47 2009/06/05 21:19:11 pyr Exp $ */ +/* $OpenBSD: ospfctl.c,v 1.48 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -125,7 +125,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/ospfd/auth.c b/usr.sbin/ospfd/auth.c index f35701d3b40..b9fa536b274 100644 --- a/usr.sbin/ospfd/auth.c +++ b/usr.sbin/ospfd/auth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth.c,v 1.16 2009/06/05 19:33:58 pyr Exp $ */ +/* $OpenBSD: auth.c,v 1.17 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -259,7 +259,7 @@ md_list_find(struct auth_md_head *head, u_int8_t keyid) } int -md_list_send(struct auth_md_head *head, struct imsgbuf *to) +md_list_send(struct auth_md_head *head, struct imsgev *to) { struct auth_md *m; diff --git a/usr.sbin/ospfd/buffer.c b/usr.sbin/ospfd/buffer.c index 66f7887dba9..6d4fef7e749 100644 --- a/usr.sbin/ospfd/buffer.c +++ b/usr.sbin/ospfd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.14 2009/06/05 21:15:47 pyr Exp $ */ +/* $OpenBSD: buffer.c,v 1.15 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> diff --git a/usr.sbin/ospfd/control.c b/usr.sbin/ospfd/control.c index 7619dda9d61..cc3a1c7c8fc 100644 --- a/usr.sbin/ospfd/control.c +++ b/usr.sbin/ospfd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.26 2009/06/05 19:33:58 pyr Exp $ */ +/* $OpenBSD: control.c,v 1.27 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -133,11 +133,12 @@ control_accept(int listenfd, short event, void *bula) 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, &c->ibuf); - 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, &c->iev); + event_add(&c->iev.ev, NULL); TAILQ_INSERT_TAIL(&ctl_conns, c, entry); } @@ -147,7 +148,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 */ @@ -159,7 +160,7 @@ control_connbypid(pid_t pid) { struct ctl_conn *c; - for (c = TAILQ_FIRST(&ctl_conns); c != NULL && c->ibuf.pid != pid; + for (c = TAILQ_FIRST(&ctl_conns); c != NULL && c->iev.ibuf.pid != pid; c = TAILQ_NEXT(c, entry)) ; /* nothing */ @@ -176,11 +177,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); } @@ -199,20 +200,20 @@ control_dispatch_imsg(int fd, short event, void *bula) } 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) == -1) { + if (msgbuf_write(&c->iev.ibuf.w) == -1) { 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; } @@ -226,13 +227,13 @@ control_dispatch_imsg(int fd, short event, void *bula) ospfe_fib_update(imsg.hdr.type); /* FALLTHROUGH */ case IMSG_CTL_RELOAD: - c->ibuf.pid = imsg.hdr.pid; + c->iev.ibuf.pid = imsg.hdr.pid; ospfe_imsg_compose_parent(imsg.hdr.type, 0, NULL, 0); break; case IMSG_CTL_KROUTE: case IMSG_CTL_KROUTE_ADDR: case IMSG_CTL_IFINFO: - c->ibuf.pid = imsg.hdr.pid; + c->iev.ibuf.pid = imsg.hdr.pid; ospfe_imsg_compose_parent(imsg.hdr.type, imsg.hdr.pid, imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE); @@ -242,7 +243,7 @@ control_dispatch_imsg(int fd, short event, void *bula) sizeof(ifidx)) { memcpy(&ifidx, imsg.data, sizeof(ifidx)); ospfe_iface_ctl(c, ifidx); - imsg_compose_event(&c->ibuf, IMSG_CTL_END, 0, + imsg_compose_event(&c->iev, IMSG_CTL_END, 0, 0, -1, NULL, 0); } break; @@ -255,7 +256,7 @@ control_dispatch_imsg(int fd, short event, void *bula) case IMSG_CTL_SHOW_DB_ASBR: case IMSG_CTL_SHOW_RIB: case IMSG_CTL_SHOW_SUM: - c->ibuf.pid = imsg.hdr.pid; + c->iev.ibuf.pid = imsg.hdr.pid; ospfe_imsg_compose_rde(imsg.hdr.type, 0, imsg.hdr.pid, imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE); break; @@ -270,7 +271,7 @@ control_dispatch_imsg(int fd, short event, void *bula) imsg_free(&imsg); } - imsg_event_add(&c->ibuf); + imsg_event_add(&c->iev); } int @@ -281,7 +282,7 @@ control_imsg_relay(struct imsg *imsg) if ((c = control_connbypid(imsg->hdr.pid)) == NULL) return (0); - return (imsg_compose_event(&c->ibuf, imsg->hdr.type, 0, imsg->hdr.pid, + return (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/ospfd/control.h b/usr.sbin/ospfd/control.h index 732005f6dd4..b439e645938 100644 --- a/usr.sbin/ospfd/control.h +++ b/usr.sbin/ospfd/control.h @@ -1,4 +1,4 @@ -/* $OpenBSD: control.h,v 1.3 2009/04/07 14:57:33 reyk Exp $ */ +/* $OpenBSD: control.h,v 1.4 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -35,7 +35,7 @@ enum blockmodes { struct ctl_conn { TAILQ_ENTRY(ctl_conn) entry; - struct imsgbuf ibuf; + struct imsgev iev; }; int control_init(char *); diff --git a/usr.sbin/ospfd/imsg.c b/usr.sbin/ospfd/imsg.c index 3baf6a8c3bb..270a84288db 100644 --- a/usr.sbin/ospfd/imsg.c +++ b/usr.sbin/ospfd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.13 2009/06/06 05:04:12 pyr Exp $ */ +/* $OpenBSD: imsg.c,v 1.14 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -29,15 +29,14 @@ #include "imsg.h" void -imsg_init(struct imsgbuf *ibuf, int fd, void (*handler)(int, short, void *)) +imsg_init(struct imsgbuf *ibuf, int fd) { msgbuf_init(&ibuf->w); bzero(&ibuf->r, sizeof(ibuf->r)); - ibuf->pid = getpid(); - ibuf->handler = handler; - TAILQ_INIT(&ibuf->fds); ibuf->fd = fd; ibuf->w.fd = fd; + ibuf->pid = getpid(); + TAILQ_INIT(&ibuf->fds); } ssize_t diff --git a/usr.sbin/ospfd/imsg.h b/usr.sbin/ospfd/imsg.h index 091d6aeb80d..af43f628ee1 100644 --- a/usr.sbin/ospfd/imsg.h +++ b/usr.sbin/ospfd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.4 2009/06/05 21:15:47 pyr Exp $ */ +/* $OpenBSD: imsg.h,v 1.5 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -19,7 +19,6 @@ */ #include <sys/tree.h> -#include <event.h> #define READ_BUF_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) @@ -56,12 +55,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 +88,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/ospfd/lsreq.c b/usr.sbin/ospfd/lsreq.c index 9acb48c9fde..646bcfa64b0 100644 --- a/usr.sbin/ospfd/lsreq.c +++ b/usr.sbin/ospfd/lsreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsreq.c,v 1.17 2009/06/05 19:33:59 pyr Exp $ */ +/* $OpenBSD: lsreq.c,v 1.18 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -27,7 +27,7 @@ #include "log.h" #include "ospfe.h" -extern struct imsgbuf *ibuf_rde; +extern struct imsgev *iev_rde; /* link state request packet handling */ int @@ -107,7 +107,7 @@ recv_ls_req(struct nbr *nbr, char *buf, u_int16_t len) case NBR_STA_XCHNG: case NBR_STA_LOAD: case NBR_STA_FULL: - imsg_compose_event(ibuf_rde, IMSG_LS_REQ, nbr->peerid, + imsg_compose_event(iev_rde, IMSG_LS_REQ, nbr->peerid, 0, -1, buf, len); break; default: diff --git a/usr.sbin/ospfd/lsupdate.c b/usr.sbin/ospfd/lsupdate.c index 1b8f68e0ba2..b0cd2c0d280 100644 --- a/usr.sbin/ospfd/lsupdate.c +++ b/usr.sbin/ospfd/lsupdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsupdate.c,v 1.37 2009/06/05 19:33:59 pyr Exp $ */ +/* $OpenBSD: lsupdate.c,v 1.38 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -33,7 +33,7 @@ #include "rde.h" extern struct ospfd_conf *oeconf; -extern struct imsgbuf *ibuf_rde; +extern struct imsgev *iev_rde; struct buf *prepare_ls_update(struct iface *); int add_ls_update(struct buf *, struct iface *, void *, u_int16_t, @@ -270,7 +270,7 @@ recv_ls_update(struct nbr *nbr, char *buf, u_int16_t len) "neighbor ID %s", inet_ntoa(nbr->id)); return; } - imsg_compose_event(ibuf_rde, IMSG_LS_UPD, nbr->peerid, 0, + imsg_compose_event(iev_rde, IMSG_LS_UPD, nbr->peerid, 0, -1, buf, ntohs(lsa.len)); buf += ntohs(lsa.len); len -= ntohs(lsa.len); diff --git a/usr.sbin/ospfd/ospfd.c b/usr.sbin/ospfd/ospfd.c index bbbafdbbb17..51ca0fc552d 100644 --- a/usr.sbin/ospfd/ospfd.c +++ b/usr.sbin/ospfd/ospfd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.c,v 1.69 2009/06/05 19:33:59 pyr Exp $ */ +/* $OpenBSD: ospfd.c,v 1.70 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -65,8 +65,8 @@ int pipe_parent2rde[2]; int pipe_ospfe2rde[2]; struct ospfd_conf *ospfd_conf = NULL; -struct imsgbuf *ibuf_ospfe; -struct imsgbuf *ibuf_rde; +struct imsgev *iev_ospfe; +struct imsgev *iev_rde; char *conffile; pid_t ospfe_pid = 0; @@ -270,22 +270,24 @@ main(int argc, char *argv[]) close(pipe_ospfe2rde[0]); close(pipe_ospfe2rde[1]); - if ((ibuf_ospfe = malloc(sizeof(struct imsgbuf))) == NULL || - (ibuf_rde = malloc(sizeof(struct imsgbuf))) == NULL) + if ((iev_ospfe = malloc(sizeof(struct imsgev))) == NULL || + (iev_rde = malloc(sizeof(struct imsgev))) == NULL) fatal(NULL); - imsg_init(ibuf_ospfe, pipe_parent2ospfe[0], main_dispatch_ospfe); - imsg_init(ibuf_rde, pipe_parent2rde[0], main_dispatch_rde); + imsg_init(&iev_ospfe->ibuf, pipe_parent2ospfe[0]); + iev_ospfe->handler = main_dispatch_ospfe; + imsg_init(&iev_rde->ibuf, pipe_parent2rde[0]); + iev_rde->handler = main_dispatch_rde; /* setup event handler */ - ibuf_ospfe->events = EV_READ; - event_set(&ibuf_ospfe->ev, ibuf_ospfe->fd, ibuf_ospfe->events, - ibuf_ospfe->handler, ibuf_ospfe); - event_add(&ibuf_ospfe->ev, NULL); + iev_ospfe->events = EV_READ; + event_set(&iev_ospfe->ev, iev_ospfe->ibuf.fd, iev_ospfe->events, + iev_ospfe->handler, iev_ospfe); + event_add(&iev_ospfe->ev, NULL); - 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); if (kr_init(!(ospfd_conf->flags & OSPFD_FLAG_NO_FIB_UPDATE), ospfd_conf->rdomain) == -1) @@ -325,10 +327,10 @@ ospfd_shutdown(void) fatal("wait"); } while (pid != -1 || (pid == -1 && errno == EINTR)); - msgbuf_clear(&ibuf_ospfe->w); - free(ibuf_ospfe); - msgbuf_clear(&ibuf_rde->w); - free(ibuf_rde); + msgbuf_clear(&iev_ospfe->ibuf.w); + free(iev_ospfe); + msgbuf_clear(&iev_rde->ibuf.w); + free(iev_rde); free(ospfd_conf); log_info("terminating"); @@ -360,12 +362,15 @@ check_child(pid_t pid, const char *pname) void main_dispatch_ospfe(int fd, short event, void *bula) { - struct imsgbuf *ibuf = bula; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; struct imsg imsg; struct demote_msg dmsg; ssize_t n; int shut = 0; + ibuf = &iev->ibuf; + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); @@ -423,10 +428,10 @@ main_dispatch_ospfe(int fd, short event, void *bula) imsg_free(&imsg); } if (!shut) - imsg_event_add(ibuf); + imsg_event_add(iev); else { /* this pipe is dead, so remove the event handler */ - event_del(&ibuf->ev); + event_del(&iev->ev); event_loopexit(NULL); } } @@ -435,11 +440,14 @@ main_dispatch_ospfe(int fd, short event, void *bula) void main_dispatch_rde(int fd, short event, void *bula) { - struct imsgbuf *ibuf = bula; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; struct imsg imsg; ssize_t n; int count, shut = 0; + ibuf = &iev->ibuf; + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); @@ -479,10 +487,10 @@ main_dispatch_rde(int fd, short event, void *bula) imsg_free(&imsg); } if (!shut) - imsg_event_add(ibuf); + imsg_event_add(iev); else { /* this pipe is dead, so remove the event handler */ - event_del(&ibuf->ev); + event_del(&iev->ev); event_loopexit(NULL); } } @@ -490,37 +498,36 @@ main_dispatch_rde(int fd, short event, void *bula) void main_imsg_compose_ospfe(int type, pid_t pid, void *data, u_int16_t datalen) { - imsg_compose_event(ibuf_ospfe, type, 0, pid, -1, data, datalen); + imsg_compose_event(iev_ospfe, type, 0, pid, -1, data, datalen); } void main_imsg_compose_rde(int type, pid_t pid, void *data, u_int16_t datalen) { - imsg_compose_event(ibuf_rde, type, 0, pid, -1, data, datalen); + imsg_compose_event(iev_rde, type, 0, pid, -1, data, datalen); } -/* this needs to be added here so that ospfctl can be used without libevent */ void -imsg_event_add(struct imsgbuf *ibuf) +imsg_event_add(struct imsgev *iev) { - 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, +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); } @@ -629,7 +636,7 @@ ospf_reload(void) return (-1); if (iface->auth_type == AUTH_CRYPT) if (md_list_send(&iface->auth_md_list, - ibuf_ospfe) == -1) + iev_ospfe) == -1) return (-1); } } @@ -646,9 +653,9 @@ ospf_reload(void) int ospf_sendboth(enum imsg_type type, void *buf, u_int16_t len) { - if (imsg_compose_event(ibuf_ospfe, type, 0, 0, -1, buf, len) == -1) + if (imsg_compose_event(iev_ospfe, type, 0, 0, -1, buf, len) == -1) return (-1); - if (imsg_compose_event(ibuf_rde, type, 0, 0, -1, buf, len) == -1) + if (imsg_compose_event(iev_rde, type, 0, 0, -1, buf, len) == -1) return (-1); return (0); } diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index 05690e0a6a1..170700a9b52 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.81 2009/06/05 19:33:59 pyr Exp $ */ +/* $OpenBSD: ospfd.h,v 1.82 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -60,6 +60,14 @@ #define F_BLACKHOLE 0x0080 #define F_REDISTRIBUTED 0x0100 +struct imsgev { + struct imsgbuf ibuf; + void (*handler)(int, short, void *); + struct event ev; + void *data; + short events; +}; + enum imsg_type { IMSG_NONE, IMSG_CTL_RELOAD, @@ -566,8 +574,8 @@ void main_imsg_compose_ospfe(int, pid_t, void *, u_int16_t); void main_imsg_compose_rde(int, pid_t, void *, u_int16_t); int ospf_redistribute(struct kroute *, u_int32_t *); void merge_config(struct ospfd_conf *, struct ospfd_conf *); -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); /* printconf.c */ diff --git a/usr.sbin/ospfd/ospfe.c b/usr.sbin/ospfd/ospfe.c index a4f210d8c0b..0a2f2bb2191 100644 --- a/usr.sbin/ospfd/ospfe.c +++ b/usr.sbin/ospfd/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.68 2009/06/05 19:33:59 pyr Exp $ */ +/* $OpenBSD: ospfe.c,v 1.69 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -49,8 +49,8 @@ void orig_rtr_lsa_all(struct area *); struct iface *find_vlink(struct abr_rtr *); struct ospfd_conf *oeconf = NULL, *nconf; -struct imsgbuf *ibuf_main; -struct imsgbuf *ibuf_rde; +struct imsgev *iev_main; +struct imsgev *iev_rde; int oe_nofib; /* ARGSUSED */ @@ -144,22 +144,24 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[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_ospfe2rde[0], ospfe_dispatch_rde); - imsg_init(ibuf_main, pipe_parent2ospfe[1], ospfe_dispatch_main); + imsg_init(&iev_rde->ibuf, pipe_ospfe2rde[0]); + iev_rde->handler = ospfe_dispatch_rde; + imsg_init(&iev_main->ibuf, pipe_parent2ospfe[1]); + iev_main->handler = ospfe_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(&oeconf->ev, oeconf->ospf_socket, EV_READ|EV_PERSIST, recv_packet, oeconf); @@ -224,12 +226,12 @@ ospfe_shutdown(void) close(oeconf->ospf_socket); /* 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(oeconf); free(pkt_ptr); @@ -241,14 +243,14 @@ ospfe_shutdown(void) int ospfe_imsg_compose_parent(int type, pid_t pid, void *data, u_int16_t datalen) { - return (imsg_compose_event(ibuf_main, type, 0, pid, -1, data, datalen)); + return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen)); } int ospfe_imsg_compose_rde(int type, u_int32_t peerid, pid_t pid, void *data, u_int16_t datalen) { - return (imsg_compose_event(ibuf_rde, type, peerid, pid, -1, data, datalen)); + return (imsg_compose_event(iev_rde, type, peerid, pid, -1, data, datalen)); } /* ARGSUSED */ @@ -258,13 +260,16 @@ ospfe_dispatch_main(int fd, short event, void *bula) static struct area *narea; static struct iface *niface; struct imsg imsg; - struct imsgbuf *ibuf = bula; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; struct area *area = NULL; struct iface *iface = NULL; struct kif *kif; struct auth_md md; int n, link_ok, stub_changed, shut = 0; + ibuf = &iev->ibuf; + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); @@ -381,10 +386,10 @@ ospfe_dispatch_main(int fd, short event, void *bula) imsg_free(&imsg); } if (!shut) - imsg_event_add(ibuf); + imsg_event_add(iev); else { /* this pipe is dead, so remove the event handler */ - event_del(&ibuf->ev); + event_del(&iev->ev); event_loopexit(NULL); } } @@ -394,7 +399,8 @@ void ospfe_dispatch_rde(int fd, short event, void *bula) { struct lsa_hdr lsa_hdr; - struct imsgbuf *ibuf = bula; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; struct nbr *nbr; struct lsa_hdr *lhp; struct lsa_ref *ref; @@ -406,6 +412,8 @@ ospfe_dispatch_rde(int fd, short event, void *bula) int n, noack = 0, shut = 0; u_int16_t l, age; + ibuf = &iev->ibuf; + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); @@ -669,10 +677,10 @@ ospfe_dispatch_rde(int fd, short event, void *bula) imsg_free(&imsg); } if (!shut) - imsg_event_add(ibuf); + imsg_event_add(iev); else { /* this pipe is dead, so remove the event handler */ - event_del(&ibuf->ev); + event_del(&iev->ev); event_loopexit(NULL); } } @@ -954,7 +962,7 @@ orig_rtr_lsa(struct area *area) &chksum, sizeof(chksum)); if (self) - imsg_compose_event(ibuf_rde, IMSG_LS_UPD, self->peerid, 0, + imsg_compose_event(iev_rde, IMSG_LS_UPD, self->peerid, 0, -1, buf->buf, buf_size(buf)); else log_warnx("orig_rtr_lsa: empty area %s", @@ -1017,7 +1025,7 @@ orig_net_lsa(struct iface *iface) memcpy(buf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), &chksum, sizeof(chksum)); - imsg_compose_event(ibuf_rde, IMSG_LS_UPD, iface->self->peerid, 0, + imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0, -1, buf->buf, buf_size(buf)); buf_free(buf); @@ -1053,7 +1061,7 @@ ospfe_iface_ctl(struct ctl_conn *c, unsigned int idx) LIST_FOREACH(iface, &area->iface_list, entry) if (idx == 0 || idx == iface->ifindex) { ictl = if_to_ctl(iface); - imsg_compose_event(&c->ibuf, IMSG_CTL_SHOW_INTERFACE, + imsg_compose_event(&c->iev, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1, ictl, sizeof(struct ctl_iface)); } } @@ -1071,13 +1079,13 @@ ospfe_nbr_ctl(struct ctl_conn *c) LIST_FOREACH(nbr, &iface->nbr_list, entry) { if (iface->self != nbr) { nctl = nbr_to_ctl(nbr); - imsg_compose_event(&c->ibuf, + imsg_compose_event(&c->iev, IMSG_CTL_SHOW_NBR, 0, 0, -1, nctl, sizeof(struct ctl_nbr)); } } - 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 diff --git a/usr.sbin/ospfd/ospfe.h b/usr.sbin/ospfd/ospfe.h index a6534d6541f..d28fba4e2ef 100644 --- a/usr.sbin/ospfd/ospfe.h +++ b/usr.sbin/ospfd/ospfe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.h,v 1.39 2009/01/31 08:55:00 claudio Exp $ */ +/* $OpenBSD: ospfe.h,v 1.40 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -101,7 +101,7 @@ int auth_gen(struct buf *, struct iface *); void md_list_add(struct auth_md_head *, u_int8_t, char *); void md_list_copy(struct auth_md_head *, struct auth_md_head *); void md_list_clr(struct auth_md_head *); -int md_list_send(struct auth_md_head *, struct imsgbuf *); +int md_list_send(struct auth_md_head *, struct imsgev *); /* database.c */ int send_db_description(struct nbr *); diff --git a/usr.sbin/ospfd/rde.c b/usr.sbin/ospfd/rde.c index 85ead90c640..4848b820076 100644 --- a/usr.sbin/ospfd/rde.c +++ b/usr.sbin/ospfd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.80 2009/06/05 19:33:59 pyr Exp $ */ +/* $OpenBSD: rde.c,v 1.81 2009/06/06 07:31:26 eric Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -63,8 +63,8 @@ struct lsa *orig_asext_lsa(struct rroute *, u_int16_t); struct lsa *orig_sum_lsa(struct rt_node *, struct area *, u_int8_t, int); struct ospfd_conf *rdeconf = NULL, *nconf = NULL; -struct imsgbuf *ibuf_ospfe; -struct imsgbuf *ibuf_main; +struct imsgev *iev_ospfe; +struct imsgev *iev_main; struct rde_nbr *nbrself; struct lsa_tree asext_tree; @@ -145,22 +145,24 @@ rde(struct ospfd_conf *xconf, int pipe_parent2rde[2], int pipe_ospfe2rde[2], close(pipe_parent2ospfe[0]); close(pipe_parent2ospfe[1]); - if ((ibuf_ospfe = malloc(sizeof(struct imsgbuf))) == NULL || - (ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL) + if ((iev_ospfe = malloc(sizeof(struct imsgev))) == NULL || + (iev_main = malloc(sizeof(struct imsgev))) == NULL) fatal(NULL); - imsg_init(ibuf_ospfe, pipe_ospfe2rde[1], rde_dispatch_imsg); - imsg_init(ibuf_main, pipe_parent2rde[1], rde_dispatch_parent); + imsg_init(&iev_ospfe->ibuf, pipe_ospfe2rde[1]); + iev_ospfe->handler = rde_dispatch_imsg; + imsg_init(&iev_main->ibuf, pipe_parent2rde[1]); + iev_main->handler = rde_dispatch_parent; /* setup event handler */ - ibuf_ospfe->events = EV_READ; - event_set(&ibuf_ospfe->ev, ibuf_ospfe->fd, ibuf_ospfe->events, - ibuf_ospfe->handler, ibuf_ospfe); - event_add(&ibuf_ospfe->ev, NULL); + iev_ospfe->events = EV_READ; + event_set(&iev_ospfe->ev, iev_ospfe->ibuf.fd, iev_ospfe->events, + iev_ospfe->handler, iev_ospfe); + event_add(&iev_ospfe->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); evtimer_set(&rdeconf->ev, spf_timer, rdeconf); cand_list_init(); @@ -202,10 +204,10 @@ rde_shutdown(void) } rde_nbr_free(); - msgbuf_clear(&ibuf_ospfe->w); - free(ibuf_ospfe); - msgbuf_clear(&ibuf_main->w); - free(ibuf_main); + msgbuf_clear(&iev_ospfe->ibuf.w); + free(iev_ospfe); + msgbuf_clear(&iev_main->ibuf.w); + free(iev_main); free(rdeconf); log_info("route decision engine exiting"); @@ -216,14 +218,15 @@ int rde_imsg_compose_ospfe(int type, u_int32_t peerid, pid_t pid, void *data, u_int16_t datalen) { - return (imsg_compose_event(ibuf_ospfe, type, peerid, pid, -1, data, datalen)); + return (imsg_compose_event(iev_ospfe, type, peerid, pid, -1, data, datalen)); } /* ARGSUSED */ void rde_dispatch_imsg(int fd, short event, void *bula) { - struct imsgbuf *ibuf = bula; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; struct imsg imsg; struct in_addr aid; struct ls_req_hdr req_hdr; @@ -239,6 +242,8 @@ rde_dispatch_imsg(int fd, short event, void *bula) int r, state, self, error, shut = 0; u_int16_t l; + ibuf = &iev->ibuf; + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); @@ -296,7 +301,7 @@ rde_dispatch_imsg(int fd, short event, void *bula) lsa_snap(nbr->area, imsg.hdr.peerid); - imsg_compose_event(ibuf_ospfe, IMSG_DB_END, imsg.hdr.peerid, + imsg_compose_event(iev_ospfe, IMSG_DB_END, imsg.hdr.peerid, 0, -1, NULL, 0); break; case IMSG_DD: @@ -329,7 +334,7 @@ rde_dispatch_imsg(int fd, short event, void *bula) * newer or missing */ rde_req_list_add(nbr, &lsa_hdr); - imsg_compose_event(ibuf_ospfe, IMSG_DD, + imsg_compose_event(iev_ospfe, IMSG_DD, imsg.hdr.peerid, 0, -1, &lsa_hdr, sizeof(lsa_hdr)); } @@ -340,10 +345,10 @@ rde_dispatch_imsg(int fd, short event, void *bula) "packet", imsg.hdr.peerid); if (!error) - imsg_compose_event(ibuf_ospfe, IMSG_DD_END, + imsg_compose_event(iev_ospfe, IMSG_DD_END, imsg.hdr.peerid, 0, -1, NULL, 0); else - imsg_compose_event(ibuf_ospfe, IMSG_DD_BADLSA, + imsg_compose_event(iev_ospfe, IMSG_DD_BADLSA, imsg.hdr.peerid, 0, -1, NULL, 0); break; case IMSG_LS_REQ: @@ -360,11 +365,11 @@ rde_dispatch_imsg(int fd, short event, void *bula) if ((v = lsa_find(nbr->area, ntohl(req_hdr.type), req_hdr.ls_id, req_hdr.adv_rtr)) == NULL) { - imsg_compose_event(ibuf_ospfe, IMSG_LS_BADREQ, + imsg_compose_event(iev_ospfe, IMSG_LS_BADREQ, imsg.hdr.peerid, 0, -1, NULL, 0); continue; } - imsg_compose_event(ibuf_ospfe, IMSG_LS_UPD, + imsg_compose_event(iev_ospfe, IMSG_LS_UPD, imsg.hdr.peerid, 0, -1, v->lsa, ntohs(v->lsa->hdr.len)); } @@ -419,13 +424,13 @@ rde_dispatch_imsg(int fd, short event, void *bula) break; /* flood and perhaps ack LSA */ - imsg_compose_event(ibuf_ospfe, IMSG_LS_FLOOD, + imsg_compose_event(iev_ospfe, IMSG_LS_FLOOD, imsg.hdr.peerid, 0, -1, lsa, ntohs(lsa->hdr.len)); /* reflood self originated LSA */ if (self && v) - imsg_compose_event(ibuf_ospfe, IMSG_LS_FLOOD, + imsg_compose_event(iev_ospfe, IMSG_LS_FLOOD, v->peerid, 0, -1, v->lsa, ntohs(v->lsa->hdr.len)); /* lsa not added so free it */ @@ -444,7 +449,7 @@ rde_dispatch_imsg(int fd, short event, void *bula) * in the table we should reset the session. */ if (rde_req_list_exists(nbr, &lsa->hdr)) { - imsg_compose_event(ibuf_ospfe, IMSG_LS_BADREQ, + imsg_compose_event(iev_ospfe, IMSG_LS_BADREQ, imsg.hdr.peerid, 0, -1, NULL, 0); break; } @@ -459,12 +464,12 @@ rde_dispatch_imsg(int fd, short event, void *bula) break; /* directly send current LSA, no ack */ - imsg_compose_event(ibuf_ospfe, IMSG_LS_UPD, + imsg_compose_event(iev_ospfe, IMSG_LS_UPD, imsg.hdr.peerid, 0, -1, v->lsa, ntohs(v->lsa->hdr.len)); } else { /* LSA equal send direct ack */ - imsg_compose_event(ibuf_ospfe, IMSG_LS_ACK, + imsg_compose_event(iev_ospfe, IMSG_LS_ACK, imsg.hdr.peerid, 0, -1, &lsa->hdr, sizeof(lsa->hdr)); free(lsa); @@ -510,7 +515,7 @@ rde_dispatch_imsg(int fd, short event, void *bula) } if (imsg.hdr.len == IMSG_HEADER_SIZE) { LIST_FOREACH(area, &rdeconf->area_list, entry) { - imsg_compose_event(ibuf_ospfe, IMSG_CTL_AREA, + imsg_compose_event(iev_ospfe, IMSG_CTL_AREA, 0, imsg.hdr.pid, -1, area, sizeof(*area)); lsa_dump(&area->lsa_tree, imsg.hdr.type, @@ -521,7 +526,7 @@ rde_dispatch_imsg(int fd, short event, void *bula) } else { memcpy(&aid, imsg.data, sizeof(aid)); if ((area = area_find(rdeconf, aid)) != NULL) { - imsg_compose_event(ibuf_ospfe, IMSG_CTL_AREA, + imsg_compose_event(iev_ospfe, IMSG_CTL_AREA, 0, imsg.hdr.pid, -1, area, sizeof(*area)); lsa_dump(&area->lsa_tree, imsg.hdr.type, @@ -532,12 +537,12 @@ rde_dispatch_imsg(int fd, short event, void *bula) imsg.hdr.pid); } } - imsg_compose_event(ibuf_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid, + imsg_compose_event(iev_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid, -1, NULL, 0); break; case IMSG_CTL_SHOW_RIB: LIST_FOREACH(area, &rdeconf->area_list, entry) { - imsg_compose_event(ibuf_ospfe, IMSG_CTL_AREA, + imsg_compose_event(iev_ospfe, IMSG_CTL_AREA, 0, imsg.hdr.pid, -1, area, sizeof(*area)); rt_dump(area->id, imsg.hdr.pid, RIB_RTR); @@ -546,14 +551,14 @@ rde_dispatch_imsg(int fd, short event, void *bula) aid.s_addr = 0; rt_dump(aid, imsg.hdr.pid, RIB_EXT); - imsg_compose_event(ibuf_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid, + imsg_compose_event(iev_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid, -1, NULL, 0); break; case IMSG_CTL_SHOW_SUM: rde_send_summary(imsg.hdr.pid); LIST_FOREACH(area, &rdeconf->area_list, entry) rde_send_summary_area(area, imsg.hdr.pid); - imsg_compose_event(ibuf_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid, + imsg_compose_event(iev_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid, -1, NULL, 0); break; default: @@ -564,10 +569,10 @@ rde_dispatch_imsg(int fd, short event, void *bula) imsg_free(&imsg); } if (!shut) - imsg_event_add(ibuf); + imsg_event_add(iev); else { /* this pipe is dead, so remove the event handler */ - event_del(&ibuf->ev); + event_del(&iev->ev); event_loopexit(NULL); } } @@ -580,13 +585,16 @@ rde_dispatch_parent(int fd, short event, void *bula) struct iface *niface; struct imsg imsg; struct rroute rr; - struct imsgbuf *ibuf = bula; + struct imsgev *iev = bula; + struct imsgbuf *ibuf; struct lsa *lsa; struct vertex *v; struct redistribute *nred; ssize_t n; int shut = 0; + ibuf = &iev->ibuf; + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); @@ -693,10 +701,10 @@ rde_dispatch_parent(int fd, short event, void *bula) imsg_free(&imsg); } if (!shut) - imsg_event_add(ibuf); + imsg_event_add(iev); else { /* this pipe is dead, so remove the event handler */ - event_del(&ibuf->ev); + event_del(&iev->ev); event_loopexit(NULL); } } @@ -725,7 +733,7 @@ rde_send_change_kroute(struct rt_node *r) struct rt_nexthop *rn; struct buf *wbuf; - if ((wbuf = imsg_create(ibuf_main, IMSG_KROUTE_CHANGE, 0, 0, + if ((wbuf = imsg_create(&iev_main->ibuf, IMSG_KROUTE_CHANGE, 0, 0, sizeof(kr))) == NULL) { return; } @@ -744,8 +752,8 @@ rde_send_change_kroute(struct rt_node *r) } if (krcount == 0) fatalx("rde_send_change_kroute: no valid nexthop found"); - imsg_close(ibuf_main, wbuf); - imsg_event_add(ibuf_main); + imsg_close(&iev_main->ibuf, wbuf); + imsg_event_add(iev_main); } void @@ -757,7 +765,7 @@ rde_send_delete_kroute(struct rt_node *r) kr.prefix.s_addr = r->prefix.s_addr; kr.prefixlen = r->prefixlen; - imsg_compose_event(ibuf_main, IMSG_KROUTE_DELETE, 0, 0, -1, &kr, sizeof(kr)); + imsg_compose_event(iev_main, IMSG_KROUTE_DELETE, 0, 0, -1, &kr, sizeof(kr)); } void |