summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-09-16 00:25:13 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-09-16 00:25:13 +0000
commit6494f05de83b84e20b911112563a4b97416c309c (patch)
treeba9e1de91e4d8e40c44f122dd4edb81ea182fc27 /usr.sbin/bgpd
parentffe3bc9bde6f1ba3aceacd6363432d659843c644 (diff)
malloc the imsg buffers instead of having them staticly, suggested by
micskye some time ago
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r--usr.sbin/bgpd/bgpd.c66
-rw-r--r--usr.sbin/bgpd/rde.c77
-rw-r--r--usr.sbin/bgpd/session.c51
3 files changed, 106 insertions, 88 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c
index ae903e6c1fd..5355de60b48 100644
--- a/usr.sbin/bgpd/bgpd.c
+++ b/usr.sbin/bgpd/bgpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.c,v 1.106 2004/09/15 18:30:42 otto Exp $ */
+/* $OpenBSD: bgpd.c,v 1.107 2004/09/16 00:25:12 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -44,13 +44,13 @@ int reconfigure(char *, struct bgpd_config *, struct mrt_head *,
struct peer **, struct filter_head *);
int dispatch_imsg(struct imsgbuf *, int);
-int rfd = -1;
-volatile sig_atomic_t mrtdump = 0;
-volatile sig_atomic_t quit = 0;
-volatile sig_atomic_t reconfig = 0;
-volatile sig_atomic_t sigchld = 0;
-struct imsgbuf ibuf_se;
-struct imsgbuf ibuf_rde;
+int rfd = -1;
+volatile sig_atomic_t mrtdump = 0;
+volatile sig_atomic_t quit = 0;
+volatile sig_atomic_t reconfig = 0;
+volatile sig_atomic_t sigchld = 0;
+struct imsgbuf *ibuf_se;
+struct imsgbuf *ibuf_rde;
void
sighdlr(int sig)
@@ -211,9 +211,12 @@ main(int argc, char *argv[])
close(pipe_s2r[0]);
close(pipe_s2r[1]);
- imsg_init(&ibuf_se, pipe_m2s[0]);
- imsg_init(&ibuf_rde, pipe_m2r[0]);
- mrt_init(&ibuf_rde, &ibuf_se);
+ if ((ibuf_se = malloc(sizeof(struct imsgbuf))) == NULL ||
+ (ibuf_rde = malloc(sizeof(struct imsgbuf))) == NULL)
+ fatal(NULL);
+ imsg_init(ibuf_se, pipe_m2s[0]);
+ imsg_init(ibuf_rde, pipe_m2r[0]);
+ mrt_init(ibuf_rde, ibuf_se);
if ((rfd = kr_init(!(conf.flags & BGPD_FLAG_NO_FIB_UPDATE))) == -1)
quit = 1;
if (pftable_clear_all() != 0)
@@ -238,13 +241,13 @@ main(int argc, char *argv[])
mrt_reconfigure(&mrt_l);
while (quit == 0) {
- pfd[PFD_PIPE_SESSION].fd = ibuf_se.fd;
+ pfd[PFD_PIPE_SESSION].fd = ibuf_se->fd;
pfd[PFD_PIPE_SESSION].events = POLLIN;
- if (ibuf_se.w.queued)
+ if (ibuf_se->w.queued)
pfd[PFD_PIPE_SESSION].events |= POLLOUT;
- pfd[PFD_PIPE_ROUTE].fd = ibuf_rde.fd;
+ pfd[PFD_PIPE_ROUTE].fd = ibuf_rde->fd;
pfd[PFD_PIPE_ROUTE].events = POLLIN;
- if (ibuf_rde.w.queued)
+ if (ibuf_rde->w.queued)
pfd[PFD_PIPE_ROUTE].events |= POLLOUT;
pfd[PFD_SOCK_ROUTE].fd = rfd;
pfd[PFD_SOCK_ROUTE].events = POLLIN;
@@ -260,26 +263,26 @@ main(int argc, char *argv[])
}
if (nfds > 0 && (pfd[PFD_PIPE_SESSION].revents & POLLOUT))
- if (msgbuf_write(&ibuf_se.w) < 0) {
+ if (msgbuf_write(&ibuf_se->w) < 0) {
log_warn("pipe write error (to SE)");
quit = 1;
}
if (nfds > 0 && (pfd[PFD_PIPE_ROUTE].revents & POLLOUT))
- if (msgbuf_write(&ibuf_rde.w) < 0) {
+ if (msgbuf_write(&ibuf_rde->w) < 0) {
log_warn("pipe write error (to RDE)");
quit = 1;
}
if (nfds > 0 && pfd[PFD_PIPE_SESSION].revents & POLLIN) {
nfds--;
- if (dispatch_imsg(&ibuf_se, PFD_PIPE_SESSION) == -1)
+ if (dispatch_imsg(ibuf_se, PFD_PIPE_SESSION) == -1)
quit = 1;
}
if (nfds > 0 && pfd[PFD_PIPE_ROUTE].revents & POLLIN) {
nfds--;
- if (dispatch_imsg(&ibuf_rde, PFD_PIPE_ROUTE) == -1)
+ if (dispatch_imsg(ibuf_rde, PFD_PIPE_ROUTE) == -1)
quit = 1;
}
@@ -338,6 +341,11 @@ main(int argc, char *argv[])
fatal("wait");
} while (pid != -1 || (pid == -1 && errno == EINTR));
+ msgbuf_clear(&ibuf_se->w);
+ free(ibuf_se);
+ msgbuf_clear(&ibuf_rde->w);
+ free(ibuf_rde);
+
log_info("Terminating");
return (0);
}
@@ -380,32 +388,32 @@ reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_head *mrt_l,
prepare_listeners(conf);
- if (imsg_compose(&ibuf_se, IMSG_RECONF_CONF, 0,
+ if (imsg_compose(ibuf_se, IMSG_RECONF_CONF, 0,
conf, sizeof(struct bgpd_config)) == -1)
return (-1);
- if (imsg_compose(&ibuf_rde, IMSG_RECONF_CONF, 0,
+ if (imsg_compose(ibuf_rde, IMSG_RECONF_CONF, 0,
conf, sizeof(struct bgpd_config)) == -1)
return (-1);
for (p = *peer_l; p != NULL; p = p->next)
- if (imsg_compose(&ibuf_se, IMSG_RECONF_PEER, p->conf.id,
+ if (imsg_compose(ibuf_se, IMSG_RECONF_PEER, p->conf.id,
&p->conf, sizeof(struct peer_config)) == -1)
return (-1);
while ((n = TAILQ_FIRST(&net_l)) != NULL) {
- if (imsg_compose(&ibuf_rde, IMSG_NETWORK_ADD, 0,
+ if (imsg_compose(ibuf_rde, IMSG_NETWORK_ADD, 0,
&n->net, sizeof(struct network_config)) == -1)
return (-1);
TAILQ_REMOVE(&net_l, n, entry);
free(n);
}
while ((r = TAILQ_FIRST(rules_l)) != NULL) {
- if (imsg_compose(&ibuf_rde, IMSG_RECONF_FILTER, 0,
+ if (imsg_compose(ibuf_rde, IMSG_RECONF_FILTER, 0,
r, sizeof(struct filter_rule)) == -1)
return (-1);
TAILQ_REMOVE(rules_l, r, entry);
free(r);
}
while ((la = TAILQ_FIRST(conf->listen_addrs)) != NULL) {
- if (imsg_compose_fdpass(&ibuf_se, IMSG_RECONF_LISTENER, la->fd,
+ if (imsg_compose_fdpass(ibuf_se, IMSG_RECONF_LISTENER, la->fd,
la, sizeof(struct listen_addr)) == -1)
return (-1);
TAILQ_REMOVE(conf->listen_addrs, la, entry);
@@ -414,8 +422,8 @@ reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_head *mrt_l,
free(conf->listen_addrs);
conf->listen_addrs = NULL;
- if (imsg_compose(&ibuf_se, IMSG_RECONF_DONE, 0, NULL, 0) == -1 ||
- imsg_compose(&ibuf_rde, IMSG_RECONF_DONE, 0, NULL, 0) == -1)
+ if (imsg_compose(ibuf_se, IMSG_RECONF_DONE, 0, NULL, 0) == -1 ||
+ imsg_compose(ibuf_rde, IMSG_RECONF_DONE, 0, NULL, 0) == -1)
return (-1);
/* mrt changes can be sent out of bound */
@@ -560,7 +568,7 @@ send_nexthop_update(struct kroute_nexthop *msg)
free(gw);
- if (imsg_compose(&ibuf_rde, IMSG_NEXTHOP_UPDATE, 0,
+ if (imsg_compose(ibuf_rde, IMSG_NEXTHOP_UPDATE, 0,
msg, sizeof(struct kroute_nexthop)) == -1)
quit = 1;
}
@@ -568,5 +576,5 @@ send_nexthop_update(struct kroute_nexthop *msg)
void
send_imsg_session(int type, pid_t pid, void *data, u_int16_t datalen)
{
- imsg_compose_pid(&ibuf_se, type, pid, data, datalen);
+ imsg_compose_pid(ibuf_se, type, pid, data, datalen);
}
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 4810f3db3a9..1d19ae83417 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.142 2004/08/12 10:24:16 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.143 2004/09/16 00:25:12 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -90,8 +90,8 @@ struct rde_peer_head peerlist;
struct rde_peer peerself;
struct rde_peer peerdynamic;
struct filter_head *rules_l, *newrules;
-struct imsgbuf ibuf_se;
-struct imsgbuf ibuf_main;
+struct imsgbuf *ibuf_se;
+struct imsgbuf *ibuf_main;
struct mrt *mrt;
void
@@ -161,8 +161,11 @@ rde_main(struct bgpd_config *config, struct peer *peer_l,
close(pipe_m2s[1]);
/* initialize the RIB structures */
- imsg_init(&ibuf_se, pipe_s2r[1]);
- imsg_init(&ibuf_main, pipe_m2r[1]);
+ if ((ibuf_se = malloc(sizeof(struct imsgbuf))) == NULL ||
+ (ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL)
+ fatal(NULL);
+ imsg_init(ibuf_se, pipe_s2r[1]);
+ imsg_init(ibuf_main, pipe_m2r[1]);
/* peer list, mrt list and listener list are not used in the RDE */
while ((p = peer_l) != NULL) {
@@ -195,14 +198,14 @@ rde_main(struct bgpd_config *config, struct peer *peer_l,
while (rde_quit == 0) {
bzero(&pfd, sizeof(pfd));
- pfd[PFD_PIPE_MAIN].fd = ibuf_main.fd;
+ pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd;
pfd[PFD_PIPE_MAIN].events = POLLIN;
- if (ibuf_main.w.queued > 0)
+ if (ibuf_main->w.queued > 0)
pfd[PFD_PIPE_MAIN].events |= POLLOUT;
- pfd[PFD_PIPE_SESSION].fd = ibuf_se.fd;
+ pfd[PFD_PIPE_SESSION].fd = ibuf_se->fd;
pfd[PFD_PIPE_SESSION].events = POLLIN;
- if (ibuf_se.w.queued > 0)
+ if (ibuf_se->w.queued > 0)
pfd[PFD_PIPE_SESSION].events |= POLLOUT;
i = 2;
@@ -217,23 +220,23 @@ rde_main(struct bgpd_config *config, struct peer *peer_l,
fatal("poll error");
if (nfds > 0 && (pfd[PFD_PIPE_MAIN].revents & POLLOUT) &&
- ibuf_main.w.queued)
- if (msgbuf_write(&ibuf_main.w) < 0)
+ ibuf_main->w.queued)
+ if (msgbuf_write(&ibuf_main->w) < 0)
fatal("pipe write error");
if (nfds > 0 && pfd[PFD_PIPE_MAIN].revents & POLLIN) {
nfds--;
- rde_dispatch_imsg_parent(&ibuf_main);
+ rde_dispatch_imsg_parent(ibuf_main);
}
if (nfds > 0 && (pfd[PFD_PIPE_SESSION].revents & POLLOUT) &&
- ibuf_se.w.queued)
- if (msgbuf_write(&ibuf_se.w) < 0)
+ ibuf_se->w.queued)
+ if (msgbuf_write(&ibuf_se->w) < 0)
fatal("pipe write error");
if (nfds > 0 && pfd[PFD_PIPE_SESSION].revents & POLLIN) {
nfds--;
- rde_dispatch_imsg_session(&ibuf_se);
+ rde_dispatch_imsg_session(ibuf_se);
}
if (nfds > 0 && pfd[PFD_MRT_FILE].revents & POLLOUT) {
@@ -249,10 +252,12 @@ rde_main(struct bgpd_config *config, struct peer *peer_l,
rde_shutdown();
- msgbuf_write(&ibuf_se.w);
- msgbuf_clear(&ibuf_se.w);
- msgbuf_write(&ibuf_main.w);
- msgbuf_clear(&ibuf_main.w);
+ msgbuf_write(&ibuf_se->w);
+ msgbuf_clear(&ibuf_se->w);
+ free(ibuf_se);
+ msgbuf_write(&ibuf_main->w);
+ msgbuf_clear(&ibuf_main->w);
+ free(ibuf_main);
log_info("route decision engine exiting");
_exit(0);
@@ -331,7 +336,7 @@ rde_dispatch_imsg_session(struct imsgbuf *ibuf)
}
pid = imsg.hdr.pid;
pt_dump(network_dump_upcall, &pid, AF_UNSPEC);
- imsg_compose_pid(&ibuf_se, IMSG_CTL_END, pid, NULL, 0);
+ imsg_compose_pid(ibuf_se, IMSG_CTL_END, pid, NULL, 0);
break;
case IMSG_CTL_SHOW_RIB:
if (imsg.hdr.len != IMSG_HEADER_SIZE) {
@@ -340,7 +345,7 @@ rde_dispatch_imsg_session(struct imsgbuf *ibuf)
}
pid = imsg.hdr.pid;
pt_dump(rde_dump_upcall, &pid, AF_UNSPEC);
- imsg_compose_pid(&ibuf_se, IMSG_CTL_END, pid, NULL, 0);
+ imsg_compose_pid(ibuf_se, IMSG_CTL_END, pid, NULL, 0);
break;
case IMSG_CTL_SHOW_RIB_AS:
if (imsg.hdr.len - IMSG_HEADER_SIZE !=
@@ -350,7 +355,7 @@ rde_dispatch_imsg_session(struct imsgbuf *ibuf)
}
pid = imsg.hdr.pid;
rde_dump_as(imsg.data, pid);
- imsg_compose_pid(&ibuf_se, IMSG_CTL_END, pid, NULL, 0);
+ imsg_compose_pid(ibuf_se, IMSG_CTL_END, pid, NULL, 0);
break;
case IMSG_CTL_SHOW_RIB_PREFIX:
if (imsg.hdr.len - IMSG_HEADER_SIZE !=
@@ -360,7 +365,7 @@ rde_dispatch_imsg_session(struct imsgbuf *ibuf)
}
pid = imsg.hdr.pid;
rde_dump_prefix(imsg.data, pid);
- imsg_compose_pid(&ibuf_se, IMSG_CTL_END, pid, NULL, 0);
+ imsg_compose_pid(ibuf_se, IMSG_CTL_END, pid, NULL, 0);
break;
case IMSG_CTL_SHOW_NEIGHBOR:
if (imsg.hdr.len - IMSG_HEADER_SIZE !=
@@ -372,11 +377,11 @@ rde_dispatch_imsg_session(struct imsgbuf *ibuf)
peer = peer_get(p.conf.id);
if (peer != NULL)
p.stats.prefix_cnt = peer->prefix_cnt;
- imsg_compose_pid(&ibuf_se, IMSG_CTL_SHOW_NEIGHBOR,
+ imsg_compose_pid(ibuf_se, IMSG_CTL_SHOW_NEIGHBOR,
imsg.hdr.pid, &p, sizeof(struct peer));
break;
case IMSG_CTL_END:
- imsg_compose_pid(&ibuf_se, IMSG_CTL_END, imsg.hdr.pid,
+ imsg_compose_pid(ibuf_se, IMSG_CTL_END, imsg.hdr.pid,
NULL, 0);
break;
default:
@@ -1311,14 +1316,14 @@ rde_update_err(struct rde_peer *peer, u_int8_t error, u_int8_t suberr,
{
struct buf *wbuf;
- if ((wbuf = imsg_create(&ibuf_se, IMSG_UPDATE_ERR, peer->conf.id,
+ if ((wbuf = imsg_create(ibuf_se, IMSG_UPDATE_ERR, peer->conf.id,
size + sizeof(error) + sizeof(suberr))) == NULL)
fatal("imsg_create error");
if (imsg_add(wbuf, &error, sizeof(error)) == -1 ||
imsg_add(wbuf, &suberr, sizeof(suberr)) == -1 ||
imsg_add(wbuf, data, size) == -1)
fatal("imsg_add error");
- if (imsg_close(&ibuf_se, wbuf) == -1)
+ if (imsg_close(ibuf_se, wbuf) == -1)
fatal("imsg_close error");
peer->state = PEER_ERR;
}
@@ -1433,14 +1438,14 @@ rde_dump_rib_as(struct prefix *p, pid_t pid)
rib.flags |= F_RIB_ELIGIBLE;
rib.aspath_len = aspath_length(p->aspath->aspath);
- if ((wbuf = imsg_create_pid(&ibuf_se, IMSG_CTL_SHOW_RIB, pid,
+ if ((wbuf = imsg_create_pid(ibuf_se, IMSG_CTL_SHOW_RIB, pid,
sizeof(rib) + rib.aspath_len)) == NULL)
return;
if (imsg_add(wbuf, &rib, sizeof(rib)) == -1 ||
imsg_add(wbuf, aspath_dump(p->aspath->aspath),
rib.aspath_len) == -1)
return;
- if (imsg_close(&ibuf_se, wbuf) == -1)
+ if (imsg_close(ibuf_se, wbuf) == -1)
return;
}
@@ -1462,7 +1467,7 @@ rde_dump_rib_prefix(struct prefix *p, pid_t pid)
if (p->aspath->nexthop == NULL ||
p->aspath->nexthop->state == NEXTHOP_REACH)
prefix.flags |= F_RIB_ELIGIBLE;
- if (imsg_compose_pid(&ibuf_se, IMSG_CTL_SHOW_RIB_PREFIX, pid,
+ if (imsg_compose_pid(ibuf_se, IMSG_CTL_SHOW_RIB_PREFIX, pid,
&prefix, sizeof(prefix)) == -1)
log_warnx("rde_dump_as: imsg_compose error");
}
@@ -1587,7 +1592,7 @@ rde_send_kroute(struct prefix *new, struct prefix *old)
if (p->aspath->flags & F_NEXTHOP_BLACKHOLE)
kr.flags |= F_BLACKHOLE;
- if (imsg_compose(&ibuf_main, type, 0, &kr, sizeof(kr)) == -1)
+ if (imsg_compose(ibuf_main, type, 0, &kr, sizeof(kr)) == -1)
fatal("imsg_compose error");
}
@@ -1608,7 +1613,7 @@ rde_send_pftable(const char *table, struct bgpd_addr *addr,
memcpy(&pfm.addr, addr, sizeof(pfm.addr));
pfm.len = len;
- if (imsg_compose(&ibuf_main,
+ if (imsg_compose(ibuf_main,
del ? IMSG_PFTABLE_REMOVE : IMSG_PFTABLE_ADD,
0, &pfm, sizeof(pfm)) == -1)
fatal("imsg_compose error");
@@ -1617,7 +1622,7 @@ rde_send_pftable(const char *table, struct bgpd_addr *addr,
void
rde_send_pftable_commit(void)
{
- if (imsg_compose(&ibuf_main, IMSG_PFTABLE_COMMIT, 0, NULL, 0) == -1)
+ if (imsg_compose(ibuf_main, IMSG_PFTABLE_COMMIT, 0, NULL, 0) == -1)
fatal("imsg_compose error");
}
@@ -1637,7 +1642,7 @@ rde_send_nexthop(struct bgpd_addr *next, int valid)
size = sizeof(struct bgpd_addr);
- if (imsg_compose(&ibuf_main, type, 0, next,
+ if (imsg_compose(ibuf_main, type, 0, next,
sizeof(struct bgpd_addr)) == -1)
fatal("imsg_compose error");
}
@@ -1704,7 +1709,7 @@ rde_update_queue_runner(void)
continue;
/* finally send message to SE */
- if (imsg_compose(&ibuf_se, IMSG_UPDATE, peer->conf.id,
+ if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id,
queue_buf, wpos) == -1)
fatal("imsg_compose error");
sent++;
@@ -1980,7 +1985,7 @@ network_dump_upcall(struct pt_entry *pt, void *ptr)
k.prefixlen = p->prefix->prefixlen;
if (p->peer == &peerself)
k.flags = F_KERNEL;
- if (imsg_compose_pid(&ibuf_se, IMSG_CTL_SHOW_NETWORK, pid,
+ if (imsg_compose_pid(ibuf_se, IMSG_CTL_SHOW_NETWORK, pid,
&k, sizeof(k)) == -1)
log_warnx("network_dump_upcall: "
"imsg_compose error");
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c
index abf7dbb4710..30f4a4237d8 100644
--- a/usr.sbin/bgpd/session.c
+++ b/usr.sbin/bgpd/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.189 2004/09/09 21:53:57 henning Exp $ */
+/* $OpenBSD: session.c,v 1.190 2004/09/16 00:25:12 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -92,8 +92,8 @@ volatile sig_atomic_t session_quit = 0;
int pending_reconf = 0;
int csock = -1;
u_int peer_cnt;
-struct imsgbuf ibuf_rde;
-struct imsgbuf ibuf_main;
+struct imsgbuf *ibuf_rde;
+struct imsgbuf *ibuf_main;
struct mrt_head mrthead;
@@ -228,8 +228,11 @@ session_main(struct bgpd_config *config, struct peer *cpeers,
close(pipe_m2r[0]);
close(pipe_m2r[1]);
init_conf(conf);
- imsg_init(&ibuf_rde, pipe_s2r[0]);
- imsg_init(&ibuf_main, pipe_m2s[1]);
+ if ((ibuf_rde = malloc(sizeof(struct imsgbuf))) == NULL ||
+ (ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL)
+ fatal(NULL);
+ imsg_init(ibuf_rde, pipe_s2r[0]);
+ imsg_init(ibuf_main, pipe_m2s[1]);
TAILQ_INIT(&ctl_conns);
csock = control_listen();
LIST_INIT(&mrthead);
@@ -339,13 +342,13 @@ session_main(struct bgpd_config *config, struct peer *cpeers,
}
bzero(pfd, sizeof(struct pollfd) * pfd_elms);
- pfd[PFD_PIPE_MAIN].fd = ibuf_main.fd;
+ pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd;
pfd[PFD_PIPE_MAIN].events = POLLIN;
- if (ibuf_main.w.queued > 0)
+ if (ibuf_main->w.queued > 0)
pfd[PFD_PIPE_MAIN].events |= POLLOUT;
- pfd[PFD_PIPE_ROUTE].fd = ibuf_rde.fd;
+ pfd[PFD_PIPE_ROUTE].fd = ibuf_rde->fd;
pfd[PFD_PIPE_ROUTE].events = POLLIN;
- if (ibuf_rde.w.queued > 0)
+ if (ibuf_rde->w.queued > 0)
pfd[PFD_PIPE_ROUTE].events |= POLLOUT;
pfd[PFD_SOCK_CTL].fd = csock;
pfd[PFD_SOCK_CTL].events = POLLIN;
@@ -439,22 +442,22 @@ session_main(struct bgpd_config *config, struct peer *cpeers,
fatal("poll error");
if (nfds > 0 && pfd[PFD_PIPE_MAIN].revents & POLLOUT)
- if (msgbuf_write(&ibuf_main.w) < 0)
+ if (msgbuf_write(&ibuf_main->w) < 0)
fatal("pipe write error");
if (nfds > 0 && pfd[PFD_PIPE_MAIN].revents & POLLIN) {
nfds--;
- session_dispatch_imsg(&ibuf_main, PFD_PIPE_MAIN,
+ session_dispatch_imsg(ibuf_main, PFD_PIPE_MAIN,
&listener_cnt);
}
if (nfds > 0 && pfd[PFD_PIPE_ROUTE].revents & POLLOUT)
- if (msgbuf_write(&ibuf_rde.w) < 0)
+ if (msgbuf_write(&ibuf_rde->w) < 0)
fatal("pipe write error");
if (nfds > 0 && pfd[PFD_PIPE_ROUTE].revents & POLLIN) {
nfds--;
- session_dispatch_imsg(&ibuf_rde, PFD_PIPE_ROUTE,
+ session_dispatch_imsg(ibuf_rde, PFD_PIPE_ROUTE,
&listener_cnt);
}
@@ -506,10 +509,12 @@ session_main(struct bgpd_config *config, struct peer *cpeers,
free(mrt_l);
free(pfd);
- msgbuf_write(&ibuf_rde.w);
- msgbuf_clear(&ibuf_rde.w);
- msgbuf_write(&ibuf_main.w);
- msgbuf_clear(&ibuf_main.w);
+ 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);
control_shutdown();
log_info("session engine exiting");
@@ -1802,7 +1807,7 @@ parse_update(struct peer *peer)
p += MSGSIZE_HEADER; /* header is already checked */
datalen -= MSGSIZE_HEADER;
- if (imsg_compose(&ibuf_rde, IMSG_UPDATE, peer->conf.id, p,
+ if (imsg_compose(ibuf_rde, IMSG_UPDATE, peer->conf.id, p,
datalen) == -1)
return (-1);
@@ -1829,7 +1834,7 @@ parse_refresh(struct peer *peer)
/* afi/safi unchecked - unrecognized values will be ignored anyway */
- if (imsg_compose(&ibuf_rde, IMSG_REFRESH, peer->conf.id, &r,
+ if (imsg_compose(ibuf_rde, IMSG_REFRESH, peer->conf.id, &r,
sizeof(r)) == -1)
return (-1);
@@ -2437,7 +2442,7 @@ void
session_down(struct peer *peer)
{
peer->stats.last_updown = time(NULL);
- if (imsg_compose(&ibuf_rde, IMSG_SESSION_DOWN, peer->conf.id,
+ if (imsg_compose(ibuf_rde, IMSG_SESSION_DOWN, peer->conf.id,
NULL, 0) == -1)
fatalx("imsg_compose error");
}
@@ -2476,7 +2481,7 @@ session_up(struct peer *peer)
memcpy(&sup.conf, &peer->conf, sizeof(sup.conf));
peer->stats.last_updown = time(NULL);
- if (imsg_compose(&ibuf_rde, IMSG_SESSION_UP, peer->conf.id,
+ if (imsg_compose(ibuf_rde, IMSG_SESSION_UP, peer->conf.id,
&sup, sizeof(sup)) == -1)
fatalx("imsg_compose error");
}
@@ -2484,13 +2489,13 @@ session_up(struct peer *peer)
int
imsg_compose_parent(int type, pid_t pid, void *data, u_int16_t datalen)
{
- return (imsg_compose_pid(&ibuf_main, type, pid, data, datalen));
+ return (imsg_compose_pid(ibuf_main, type, pid, data, datalen));
}
int
imsg_compose_rde(int type, pid_t pid, void *data, u_int16_t datalen)
{
- return (imsg_compose_pid(&ibuf_rde, type, pid, data, datalen));
+ return (imsg_compose_pid(ibuf_rde, type, pid, data, datalen));
}
static struct sockaddr *