summaryrefslogtreecommitdiff
path: root/usr.sbin/ospf6d/rde.c
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2009-06-06 09:02:47 +0000
committerEric Faurot <eric@cvs.openbsd.org>2009-06-06 09:02:47 +0000
commit43b3ccb7b66fe7ac8ef51712e09e4d04777fb3c0 (patch)
treef7a3ed200a44161068d03ed37714ff75bd226535 /usr.sbin/ospf6d/rde.c
parent13bd723f39459bc3835159e553a7c494c498c93b (diff)
make ospf6ctl/ospf6d imsg-in-a-lib ready too.
ospf6ctl is already broken in tree (not connected to build). ok pyr@
Diffstat (limited to 'usr.sbin/ospf6d/rde.c')
-rw-r--r--usr.sbin/ospf6d/rde.c133
1 files changed, 72 insertions, 61 deletions
diff --git a/usr.sbin/ospf6d/rde.c b/usr.sbin/ospf6d/rde.c
index 5f110a2db0b..d03cfb3ab41 100644
--- a/usr.sbin/ospf6d/rde.c
+++ b/usr.sbin/ospf6d/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.30 2009/05/31 20:29:56 jacekm Exp $ */
+/* $OpenBSD: rde.c,v 1.31 2009/06/06 09:02:46 eric Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -85,8 +85,8 @@ int prefix_compare(struct prefix_node *, struct prefix_node *);
void prefix_tree_add(struct prefix_tree *, struct lsa_link *);
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;
@@ -165,22 +165,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();
@@ -217,10 +219,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");
@@ -231,14 +233,16 @@ int
rde_imsg_compose_ospfe(int type, u_int32_t peerid, pid_t pid, void *data,
u_int16_t datalen)
{
- return (imsg_compose(ibuf_ospfe, type, peerid, pid, 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 = &iev->ibuf;
struct imsg imsg;
struct in_addr aid;
struct ls_req_hdr req_hdr;
@@ -316,8 +320,8 @@ rde_dispatch_imsg(int fd, short event, void *bula)
lsa_snap(nbr, imsg.hdr.peerid);
- imsg_compose(ibuf_ospfe, IMSG_DB_END, imsg.hdr.peerid,
- 0, NULL, 0);
+ imsg_compose_event(iev_ospfe, IMSG_DB_END, imsg.hdr.peerid,
+ 0, -1, NULL, 0);
break;
case IMSG_DD:
nbr = rde_nbr_find(imsg.hdr.peerid);
@@ -343,8 +347,8 @@ rde_dispatch_imsg(int fd, short event, void *bula)
* newer or missing
*/
rde_req_list_add(nbr, &lsa_hdr);
- imsg_compose(ibuf_ospfe, IMSG_DD,
- imsg.hdr.peerid, 0, &lsa_hdr,
+ imsg_compose_event(iev_ospfe, IMSG_DD,
+ imsg.hdr.peerid, 0, -1, &lsa_hdr,
sizeof(lsa_hdr));
}
}
@@ -353,8 +357,8 @@ rde_dispatch_imsg(int fd, short event, void *bula)
"trailing garbage in Database Description "
"packet", imsg.hdr.peerid);
- imsg_compose(ibuf_ospfe, IMSG_DD_END, imsg.hdr.peerid,
- 0, NULL, 0);
+ imsg_compose_event(iev_ospfe, IMSG_DD_END,
+ imsg.hdr.peerid, -1, 0, NULL, 0);
break;
case IMSG_LS_REQ:
nbr = rde_nbr_find(imsg.hdr.peerid);
@@ -370,12 +374,13 @@ rde_dispatch_imsg(int fd, short event, void *bula)
if ((v = lsa_find(nbr->iface,
req_hdr.type, req_hdr.ls_id,
req_hdr.adv_rtr)) == NULL) {
- imsg_compose(ibuf_ospfe, IMSG_LS_BADREQ,
- imsg.hdr.peerid, 0, NULL, 0);
+ imsg_compose_event(iev_ospfe,
+ IMSG_LS_BADREQ,
+ imsg.hdr.peerid, 0, -1, NULL, 0);
continue;
}
- imsg_compose(ibuf_ospfe, IMSG_LS_UPD,
- imsg.hdr.peerid, 0, v->lsa,
+ imsg_compose_event(iev_ospfe, IMSG_LS_UPD,
+ imsg.hdr.peerid, 0, -1, v->lsa,
ntohs(v->lsa->hdr.len));
}
if (l != 0)
@@ -436,14 +441,15 @@ rde_dispatch_imsg(int fd, short event, void *bula)
break;
/* flood and perhaps ack LSA */
- imsg_compose(ibuf_ospfe, IMSG_LS_FLOOD,
- imsg.hdr.peerid, 0, lsa,
+ 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(ibuf_ospfe, IMSG_LS_FLOOD,
- v->peerid, 0, v->lsa,
+ imsg_compose_event(iev_ospfe,
+ IMSG_LS_FLOOD,
+ v->peerid, 0, -1, v->lsa,
ntohs(v->lsa->hdr.len));
/* new LSA was not added so free it */
if (self)
@@ -461,8 +467,9 @@ 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(ibuf_ospfe, IMSG_LS_BADREQ,
- imsg.hdr.peerid, 0, NULL, 0);
+ imsg_compose_event(iev_ospfe,
+ IMSG_LS_BADREQ,
+ imsg.hdr.peerid, 0, -1, NULL, 0);
break;
}
@@ -476,13 +483,13 @@ rde_dispatch_imsg(int fd, short event, void *bula)
break;
/* directly send current LSA, no ack */
- imsg_compose(ibuf_ospfe, IMSG_LS_UPD,
- imsg.hdr.peerid, 0, v->lsa,
+ 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(ibuf_ospfe, IMSG_LS_ACK,
- imsg.hdr.peerid, 0, &lsa->hdr,
+ imsg_compose_event(iev_ospfe, IMSG_LS_ACK,
+ imsg.hdr.peerid, 0, -1, &lsa->hdr,
sizeof(lsa->hdr));
free(lsa);
}
@@ -545,13 +552,13 @@ rde_dispatch_imsg(int fd, short event, void *bula)
imsg.hdr.pid);
}
}
- imsg_compose(ibuf_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid,
- NULL, 0);
+ 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(ibuf_ospfe, IMSG_CTL_AREA,
- 0, imsg.hdr.pid, area, sizeof(*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);
rt_dump(area->id, imsg.hdr.pid, RIB_NET);
@@ -559,15 +566,15 @@ rde_dispatch_imsg(int fd, short event, void *bula)
aid.s_addr = 0;
rt_dump(aid, imsg.hdr.pid, RIB_EXT);
- imsg_compose(ibuf_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid,
- NULL, 0);
+ 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(ibuf_ospfe, IMSG_CTL_END, 0, imsg.hdr.pid,
- NULL, 0);
+ imsg_compose_event(iev_ospfe, IMSG_CTL_END, 0,
+ imsg.hdr.pid, 1, NULL, 0);
break;
case IMSG_IFINFO:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
@@ -598,10 +605,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);
}
}
@@ -615,7 +622,8 @@ rde_dispatch_parent(int fd, short event, void *bula)
struct imsg imsg;
struct kroute kr;
struct rroute rr;
- struct imsgbuf *ibuf = bula;
+ struct imsgev *iev = bula;
+ struct imsgbuf *ibuf = &iev->ibuf;
struct lsa *lsa;
struct vertex *v;
struct rt_node *rn;
@@ -689,8 +697,8 @@ rde_dispatch_parent(int fd, short event, void *bula)
rde_send_change_kroute(rn);
else
/* should not happen */
- imsg_compose(ibuf_main, IMSG_KROUTE_DELETE, 0,
- 0, &kr, sizeof(kr));
+ imsg_compose_event(iev_main, IMSG_KROUTE_DELETE, 0,
+ 0, -1, &kr, sizeof(kr));
break;
case IMSG_IFADD:
if ((niface = malloc(sizeof(struct iface))) == NULL)
@@ -749,10 +757,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);
}
}
@@ -763,12 +771,13 @@ rde_dump_area(struct area *area, int imsg_type, pid_t pid)
struct iface *iface;
/* dump header */
- imsg_compose(ibuf_ospfe, IMSG_CTL_AREA, 0, pid, area, sizeof(*area));
+ imsg_compose_event(iev_ospfe, IMSG_CTL_AREA, 0, pid, -1,
+ area, sizeof(*area));
/* dump link local lsa */
LIST_FOREACH(iface, &area->iface_list, entry) {
- imsg_compose(ibuf_ospfe, IMSG_CTL_IFACE,
- 0, pid, iface, sizeof(*iface));
+ imsg_compose_event(iev_ospfe, IMSG_CTL_IFACE,
+ 0, pid, -1, iface, sizeof(*iface));
lsa_dump(&iface->lsa_tree, imsg_type, pid);
}
@@ -801,7 +810,8 @@ rde_send_change_kroute(struct rt_node *r)
kr.prefixlen = r->prefixlen;
kr.ext_tag = r->ext_tag;
- imsg_compose(ibuf_main, IMSG_KROUTE_CHANGE, 0, 0, &kr, sizeof(kr));
+ imsg_compose_event(iev_main, IMSG_KROUTE_CHANGE, 0, 0, -1,
+ &kr, sizeof(kr));
}
void
@@ -813,7 +823,8 @@ rde_send_delete_kroute(struct rt_node *r)
kr.prefix = r->prefix;
kr.prefixlen = r->prefixlen;
- imsg_compose(ibuf_main, IMSG_KROUTE_DELETE, 0, 0, &kr, sizeof(kr));
+ imsg_compose_event(iev_main, IMSG_KROUTE_DELETE, 0, 0, -1,
+ &kr, sizeof(kr));
}
void