summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd/session.c
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/session.c
parentffe3bc9bde6f1ba3aceacd6363432d659843c644 (diff)
malloc the imsg buffers instead of having them staticly, suggested by
micskye some time ago
Diffstat (limited to 'usr.sbin/bgpd/session.c')
-rw-r--r--usr.sbin/bgpd/session.c51
1 files changed, 28 insertions, 23 deletions
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 *