summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2003-12-21 23:26:39 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2003-12-21 23:26:39 +0000
commit6e837807704bcfce6bf07cdce480d9ee5e67cc78 (patch)
treef9997cb4d2630913282bfefc659708db49370222 /usr.sbin
parentc0e61cc2c9076d79030b46b50b9f01aa31e4cd20 (diff)
wrap read & write buffers for imsgs into a struct.
finally gives us read buffers per pipe instead of per process, eleminating a possible race. also gets us a real imsg_init() that does all the boring init work
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpd/bgpd.c57
-rw-r--r--usr.sbin/bgpd/bgpd.h16
-rw-r--r--usr.sbin/bgpd/imsg.c61
-rw-r--r--usr.sbin/bgpd/mrt.c24
-rw-r--r--usr.sbin/bgpd/mrt.h8
-rw-r--r--usr.sbin/bgpd/rde.c46
-rw-r--r--usr.sbin/bgpd/session.c36
7 files changed, 126 insertions, 122 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c
index c316ceedec6..59a748425f0 100644
--- a/usr.sbin/bgpd/bgpd.c
+++ b/usr.sbin/bgpd/bgpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.c,v 1.10 2003/12/21 22:16:53 henning Exp $ */
+/* $OpenBSD: bgpd.c,v 1.11 2003/12/21 23:26:37 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -38,14 +38,14 @@ void sighdlr(int);
void usage(void);
int main(int, char *[]);
int reconfigure(char *, struct bgpd_config *, struct mrt_config *);
-int dispatch_imsg(int, int, struct mrt_config *, struct msgbuf *);
+int dispatch_imsg(struct imsgbuf *, int, struct mrt_config *);
int mrtfd = -1;
volatile sig_atomic_t mrtdump = 0;
volatile sig_atomic_t quit = 0;
volatile sig_atomic_t reconfig = 0;
-struct msgbuf msgbuf_se;
-struct msgbuf msgbuf_rde;
+struct imsgbuf ibuf_se;
+struct imsgbuf ibuf_rde;
void
sighdlr(int sig)
@@ -183,20 +183,17 @@ main(int argc, char *argv[])
close(pipe_s2r[0]);
close(pipe_s2r[1]);
- msgbuf_init(&msgbuf_se);
- msgbuf_se.sock = pipe_m2s[0];
- msgbuf_init(&msgbuf_rde);
- msgbuf_rde.sock = pipe_m2r[0];
- init_imsg_buf();
+ imsg_init(&ibuf_se, pipe_m2s[0]);
+ imsg_init(&ibuf_rde, pipe_m2r[0]);
while (quit == 0) {
- pfd[PFD_PIPE_SESSION].fd = msgbuf_se.sock;
+ pfd[PFD_PIPE_SESSION].fd = ibuf_se.sock;
pfd[PFD_PIPE_SESSION].events = POLLIN;
- if (msgbuf_se.queued)
+ if (ibuf_se.w.queued)
pfd[PFD_PIPE_SESSION].events |= POLLOUT;
- pfd[PFD_PIPE_ROUTE].fd = msgbuf_rde.sock;
+ pfd[PFD_PIPE_ROUTE].fd = ibuf_rde.sock;
pfd[PFD_PIPE_ROUTE].events = POLLIN;
- if (msgbuf_rde.queued)
+ if (ibuf_rde.w.queued)
pfd[PFD_PIPE_ROUTE].events |= POLLOUT;
i = PFD_MRT_START;
LIST_FOREACH(mconf, &mrtconf, list)
@@ -211,23 +208,21 @@ main(int argc, char *argv[])
fatal("poll error", errno);
if (nfds > 0 && (pfd[PFD_PIPE_SESSION].revents & POLLOUT))
- if ((n = msgbuf_write(&msgbuf_se)) == -1)
+ if ((n = msgbuf_write(&ibuf_se.w)) == -1)
fatal("pipe write error", errno);
if (nfds > 0 && (pfd[PFD_PIPE_ROUTE].revents & POLLOUT))
- if ((n = msgbuf_write(&msgbuf_rde)) == -1)
+ if ((n = msgbuf_write(&ibuf_rde.w)) == -1)
fatal("pipe write error", errno);
if (nfds > 0 && pfd[PFD_PIPE_SESSION].revents & POLLIN) {
nfds--;
- dispatch_imsg(pfd[PFD_PIPE_SESSION].fd,
- PFD_PIPE_SESSION, &mrtconf, &msgbuf_rde);
+ dispatch_imsg(&ibuf_se, PFD_PIPE_SESSION, &mrtconf);
}
if (nfds > 0 && pfd[PFD_PIPE_ROUTE].revents & POLLIN) {
nfds--;
- dispatch_imsg(pfd[PFD_PIPE_ROUTE].fd, PFD_PIPE_ROUTE,
- &mrtconf, &msgbuf_rde);
+ dispatch_imsg(&ibuf_rde, PFD_PIPE_ROUTE, &mrtconf);
}
for (j = PFD_MRT_START; j < i && nfds > 0 ; j++) {
@@ -241,15 +236,15 @@ main(int argc, char *argv[])
logit(LOG_CRIT, "rereading config");
reconfigure(conffile, &conf, &mrtconf);
LIST_FOREACH(mconf, &mrtconf, list)
- mrt_state(mconf, IMSG_NONE, &msgbuf_rde);
+ mrt_state(mconf, IMSG_NONE, &ibuf_rde);
reconfig = 0;
}
if (mrtdump == 1) {
- mrt_alrm(&mrtconf, &msgbuf_rde);
+ mrt_alrm(&mrtconf, &ibuf_rde);
mrtdump = 0;
} else if (mrtdump == 2) {
- mrt_usr1(&mrtconf, &msgbuf_rde);
+ mrt_usr1(&mrtconf, &ibuf_rde);
mrtdump = 0;
}
}
@@ -280,18 +275,18 @@ reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_config *mrtc)
conffile);
return (-1);
}
- imsg_compose(&msgbuf_se, IMSG_RECONF_CONF, 0,
+ imsg_compose(&ibuf_se, IMSG_RECONF_CONF, 0,
conf, sizeof(struct bgpd_config));
- imsg_compose(&msgbuf_rde, IMSG_RECONF_CONF, 0,
+ imsg_compose(&ibuf_rde, IMSG_RECONF_CONF, 0,
conf, sizeof(struct bgpd_config));
for (p = conf->peers; p != NULL; p = p->next) {
- imsg_compose(&msgbuf_se, IMSG_RECONF_PEER, p->conf.id,
+ imsg_compose(&ibuf_se, IMSG_RECONF_PEER, p->conf.id,
&p->conf, sizeof(struct peer_config));
- imsg_compose(&msgbuf_rde, IMSG_RECONF_PEER, p->conf.id,
+ imsg_compose(&ibuf_rde, IMSG_RECONF_PEER, p->conf.id,
&p->conf, sizeof(struct peer_config));
}
- imsg_compose(&msgbuf_se, IMSG_RECONF_DONE, 0, NULL, 0);
- imsg_compose(&msgbuf_rde, IMSG_RECONF_DONE, 0, NULL, 0);
+ imsg_compose(&ibuf_se, IMSG_RECONF_DONE, 0, NULL, 0);
+ imsg_compose(&ibuf_rde, IMSG_RECONF_DONE, 0, NULL, 0);
return (0);
}
@@ -300,7 +295,7 @@ reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_config *mrtc)
* XXX currently messages are only buffered for mrt files.
*/
int
-dispatch_imsg(int fd, int idx, struct mrt_config *conf, struct msgbuf *rde)
+dispatch_imsg(struct imsgbuf *ibuf, int idx, struct mrt_config *conf)
{
struct imsg imsg;
struct buf *wbuf;
@@ -308,14 +303,14 @@ dispatch_imsg(int fd, int idx, struct mrt_config *conf, struct msgbuf *rde)
ssize_t len;
int n;
- if (get_imsg(fd, &imsg) > 0) {
+ if (get_imsg(ibuf, &imsg) > 0) {
switch (imsg.hdr.type) {
case IMSG_MRT_MSG:
case IMSG_MRT_END:
LIST_FOREACH(m, conf, list) {
if (m->id != imsg.hdr.peerid)
continue;
- if (mrt_state(m, imsg.hdr.type, rde) == 0)
+ if (mrt_state(m, imsg.hdr.type, ibuf) == 0)
break;
if (m->msgbuf.sock == -1)
break;
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index 29efac291a2..212a0217694 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.9 2003/12/21 22:16:53 henning Exp $ */
+/* $OpenBSD: bgpd.h,v 1.10 2003/12/21 23:26:37 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -179,7 +179,7 @@ struct mrtdump_config {
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
#define MAX_IMSGSIZE 8192
-struct imsg_buf_read {
+struct imsg_readbuf {
u_char buf[MAX_IMSGSIZE];
ssize_t read_len;
u_int32_t peerid;
@@ -189,6 +189,12 @@ struct imsg_buf_read {
u_int8_t seen_hdr;
};
+struct imsgbuf {
+ int sock;
+ struct imsg_readbuf r;
+ struct msgbuf w;
+};
+
enum imsg_type {
IMSG_NONE,
IMSG_RECONF_CONF,
@@ -266,9 +272,9 @@ int parse_config(char *, struct bgpd_config *, struct mrt_config *);
int merge_config(struct bgpd_config *, struct bgpd_config *);
/* imsg.c */
-void init_imsg_buf(void);
-int get_imsg(int, struct imsg *);
-int imsg_compose(struct msgbuf *, int, u_int32_t, void *, u_int16_t);
+void imsg_init(struct imsgbuf *, int);
+int get_imsg(struct imsgbuf *, struct imsg *);
+int imsg_compose(struct imsgbuf *, int, u_int32_t, void *, u_int16_t);
void imsg_free(struct imsg *);
/* rde.c */
diff --git a/usr.sbin/bgpd/imsg.c b/usr.sbin/bgpd/imsg.c
index a6b5ef99f38..bdbf8498858 100644
--- a/usr.sbin/bgpd/imsg.c
+++ b/usr.sbin/bgpd/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.6 2003/12/21 22:16:53 henning Exp $ */
+/* $OpenBSD: imsg.c,v 1.7 2003/12/21 23:26:37 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -25,54 +25,63 @@
#include "bgpd.h"
-static struct imsg_buf_read buf;
+void imsg_init_readbuf(struct imsgbuf *);
void
-init_imsg_buf(void)
+imsg_init_readbuf(struct imsgbuf *ibuf)
{
- bzero(&buf, sizeof(buf));
- buf.wptr = buf.buf;
- buf.pkt_len = IMSG_HEADER_SIZE;
+ bzero(&ibuf->r, sizeof(ibuf->r));
+ ibuf->r.wptr = ibuf->r.buf;
+ ibuf->r.pkt_len = IMSG_HEADER_SIZE;
+}
+
+void
+imsg_init(struct imsgbuf *ibuf, int sock)
+{
+ imsg_init_readbuf(ibuf);
+ msgbuf_init(&ibuf->w);
+ ibuf->sock = sock;
+ ibuf->w.sock = sock;
}
int
-get_imsg(int fd, struct imsg *imsg)
+get_imsg(struct imsgbuf *ibuf, struct imsg *imsg)
{
struct imsg_hdr *hdr;
ssize_t n, read_total = 0, datalen = 0;
u_char *rptr;
do {
- if ((n = read(fd, buf.wptr, buf.pkt_len - buf.read_len)) ==
- -1) {
+ if ((n = read(ibuf->sock, ibuf->r.wptr,
+ ibuf->r.pkt_len - ibuf->r.read_len)) == -1) {
if (errno != EAGAIN && errno != EINTR)
fatal("pipe read error", errno);
return (0);
}
read_total += n;
- buf.wptr += n;
- buf.read_len += n;
- if (buf.read_len == buf.pkt_len) {
- if (!buf.seen_hdr) { /* got header */
- hdr = (struct imsg_hdr *)&buf.buf;
- buf.type = hdr->type;
- buf.pkt_len = hdr->len;
- buf.peerid = hdr->peerid;
+ ibuf->r.wptr += n;
+ ibuf->r.read_len += n;
+ if (ibuf->r.read_len == ibuf->r.pkt_len) {
+ if (!ibuf->r.seen_hdr) { /* got header */
+ hdr = (struct imsg_hdr *)&ibuf->r.buf;
+ ibuf->r.type = hdr->type;
+ ibuf->r.pkt_len = hdr->len;
+ ibuf->r.peerid = hdr->peerid;
if (hdr->len < IMSG_HEADER_SIZE ||
hdr->len > MAX_IMSGSIZE)
fatal("wrong imsg header len", 0);
- buf.seen_hdr = 1;
+ ibuf->r.seen_hdr = 1;
} else { /* we got the full packet */
- imsg->hdr.type = buf.type;
- imsg->hdr.len = buf.pkt_len;
- imsg->hdr.peerid = buf.peerid;
- datalen = buf.pkt_len - IMSG_HEADER_SIZE;
- rptr = buf.buf + IMSG_HEADER_SIZE;
+ imsg->hdr.type = ibuf->r.type;
+ imsg->hdr.len = ibuf->r.pkt_len;
+ imsg->hdr.peerid = ibuf->r.peerid;
+ datalen = ibuf->r.pkt_len - IMSG_HEADER_SIZE;
+ rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
if ((imsg->data = malloc(datalen)) == NULL)
fatal("get_imsg malloc", errno);
memcpy(imsg->data, rptr, datalen);
n = 0; /* give others a chance */
- init_imsg_buf();
+ imsg_init_readbuf(ibuf);
}
}
} while (n > 0);
@@ -84,7 +93,7 @@ get_imsg(int fd, struct imsg *imsg)
}
int
-imsg_compose(struct msgbuf *msgbuf, int type, u_int32_t peerid, void *data,
+imsg_compose(struct imsgbuf *ibuf, int type, u_int32_t peerid, void *data,
u_int16_t datalen)
{
struct buf *wbuf;
@@ -102,7 +111,7 @@ imsg_compose(struct msgbuf *msgbuf, int type, u_int32_t peerid, void *data,
if (datalen)
if (buf_add(wbuf, data, datalen) == -1)
fatal("imsg_compose: buf_add error", 0);
- if ((n = buf_close(msgbuf, wbuf)) == -1)
+ if ((n = buf_close(&ibuf->w, wbuf)) == -1)
fatal("imsg_compose: buf_close error", 0);
return (n);
diff --git a/usr.sbin/bgpd/mrt.c b/usr.sbin/bgpd/mrt.c
index 32aec6ccb2b..ba88e08186f 100644
--- a/usr.sbin/bgpd/mrt.c
+++ b/usr.sbin/bgpd/mrt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mrt.c,v 1.7 2003/12/21 22:16:53 henning Exp $ */
+/* $OpenBSD: mrt.c,v 1.8 2003/12/21 23:26:37 henning Exp $ */
/*
* Copyright (c) 2003 Claudio Jeker <claudio@openbsd.org>
@@ -230,7 +230,7 @@ mrt_open(struct mrtdump_config *conf)
int
mrt_state(struct mrtdump_config *m, enum imsg_type type,
- struct msgbuf *rde /*, struct msgbuf *se */)
+ struct imsgbuf *buf)
{
switch (m->state) {
case MRT_STATE_DONE:
@@ -240,7 +240,7 @@ mrt_state(struct mrtdump_config *m, enum imsg_type type,
switch (type) {
case IMSG_NONE:
if (m->type == MRT_TABLE_DUMP)
- imsg_compose(rde, IMSG_MRT_END, m->id, NULL, 0);
+ imsg_compose(buf, IMSG_MRT_END, m->id, NULL, 0);
return (0);
case IMSG_MRT_END:
/* dump no longer valid */
@@ -256,14 +256,14 @@ mrt_state(struct mrtdump_config *m, enum imsg_type type,
switch (type) {
case IMSG_NONE:
if (m->type == MRT_TABLE_DUMP)
- imsg_compose(rde, IMSG_MRT_END, m->id, NULL, 0);
+ imsg_compose(buf, IMSG_MRT_END, m->id, NULL, 0);
return (0);
case IMSG_MRT_END:
if (m->msgbuf.sock != -1)
close(m->msgbuf.sock);
m->state = MRT_STATE_OPEN;
if (m->type == MRT_TABLE_DUMP)
- imsg_compose(rde, IMSG_MRT_REQ, m->id, NULL, 0);
+ imsg_compose(buf, IMSG_MRT_REQ, m->id, NULL, 0);
return (0);
default:
break;
@@ -273,7 +273,7 @@ mrt_state(struct mrtdump_config *m, enum imsg_type type,
switch (type) {
case IMSG_NONE:
if (m->type == MRT_TABLE_DUMP)
- imsg_compose(rde, IMSG_MRT_REQ, m->id, NULL, 0);
+ imsg_compose(buf, IMSG_MRT_REQ, m->id, NULL, 0);
return (0);
case IMSG_MRT_MSG:
mrt_open(m);
@@ -290,7 +290,7 @@ mrt_state(struct mrtdump_config *m, enum imsg_type type,
}
int
-mrt_usr1(struct mrt_config *conf, struct msgbuf *rde /*, struct msgbuf *se */)
+mrt_usr1(struct mrt_config *conf, struct imsgbuf *buf)
{
struct mrtdump_config *m;
time_t now;
@@ -305,11 +305,11 @@ mrt_usr1(struct mrt_config *conf, struct msgbuf *rde /*, struct msgbuf *se */)
break;
case MRT_STATE_DONE:
m->state = MRT_STATE_OPEN;
- imsg_compose(rde, IMSG_MRT_REQ, m->id, NULL, 0);
+ imsg_compose(buf, IMSG_MRT_REQ, m->id, NULL, 0);
break;
default:
m->state = MRT_STATE_REOPEN;
- imsg_compose(rde, IMSG_MRT_END, m->id, NULL, 0);
+ imsg_compose(buf, IMSG_MRT_END, m->id, NULL, 0);
break;
}
@@ -326,7 +326,7 @@ mrt_usr1(struct mrt_config *conf, struct msgbuf *rde /*, struct msgbuf *se */)
}
int
-mrt_alrm(struct mrt_config *conf, struct msgbuf *rde /*, struct msgbuf *se */)
+mrt_alrm(struct mrt_config *conf, struct imsgbuf *buf)
{
struct mrtdump_config *m;
time_t now;
@@ -344,13 +344,13 @@ mrt_alrm(struct mrt_config *conf, struct msgbuf *rde /*, struct msgbuf *se */)
case MRT_STATE_DONE:
m->state = MRT_STATE_OPEN;
if (m->type == MRT_TABLE_DUMP)
- imsg_compose(rde, IMSG_MRT_REQ, m->id,
+ imsg_compose(buf, IMSG_MRT_REQ, m->id,
NULL, 0);
break;
default:
m->state = MRT_STATE_REOPEN;
if (m->type == MRT_TABLE_DUMP)
- imsg_compose(rde, IMSG_MRT_END, m->id,
+ imsg_compose(buf, IMSG_MRT_END, m->id,
NULL, 0);
break;
}
diff --git a/usr.sbin/bgpd/mrt.h b/usr.sbin/bgpd/mrt.h
index 3abccb8376d..130e3e1153c 100644
--- a/usr.sbin/bgpd/mrt.h
+++ b/usr.sbin/bgpd/mrt.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mrt.h,v 1.3 2003/12/21 22:16:53 henning Exp $ */
+/* $OpenBSD: mrt.h,v 1.4 2003/12/21 23:26:37 henning Exp $ */
/*
* Copyright (c) 2003 Claudio Jeker <cjeker@diehard.n-r-g.com>
@@ -231,8 +231,8 @@ int mrt_dump_bgp_msg(struct mrt *, void *, u_int16_t, int,
struct peer_config *, struct bgpd_config *);
void mrt_clear_seq(void);
void mrt_dump_upcall(struct pt_entry *, void *);
-int mrt_state(struct mrtdump_config *, enum imsg_type, struct msgbuf *);
-int mrt_alrm(struct mrt_config *, struct msgbuf *);
-int mrt_usr1(struct mrt_config *, struct msgbuf *);
+int mrt_state(struct mrtdump_config *, enum imsg_type, struct imsgbuf *);
+int mrt_alrm(struct mrt_config *, struct imsgbuf *);
+int mrt_usr1(struct mrt_config *, struct imsgbuf *);
#endif
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 34d83c3a64c..7fd724881ef 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.16 2003/12/21 22:16:53 henning Exp $ */
+/* $OpenBSD: rde.c,v 1.17 2003/12/21 23:26:38 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -34,7 +34,7 @@
#define PFD_PIPE_SESSION 1
void rde_sighdlr(int);
-void rde_dispatch_imsg(int, int);
+void rde_dispatch_imsg(struct imsgbuf *, int);
int rde_update_dispatch(struct imsg *);
int rde_update_get_prefix(u_char *, u_int16_t, struct in_addr *,
u_int8_t *);
@@ -52,8 +52,8 @@ void peer_down(u_int32_t);
volatile sig_atomic_t rde_quit = 0;
struct bgpd_config *conf, *nconf;
struct rde_peer_head peerlist;
-struct msgbuf msgbuf_se;
-struct msgbuf msgbuf_main;
+struct imsgbuf ibuf_se;
+struct imsgbuf ibuf_main;
void
rde_sighdlr(int sig)
@@ -116,24 +116,21 @@ rde_main(struct bgpd_config *config, int pipe_m2r[2], int pipe_s2r[2])
path_init(pathhashsize);
nexthop_init(nexthophashsize);
pt_init();
- msgbuf_init(&msgbuf_se);
- msgbuf_se.sock = pipe_s2r[1];
- msgbuf_init(&msgbuf_main);
- msgbuf_main.sock = pipe_m2r[1];
- init_imsg_buf();
+ imsg_init(&ibuf_se, pipe_s2r[1]);
+ imsg_init(&ibuf_main, pipe_m2r[1]);
logit(LOG_INFO, "route decision engine ready");
while (rde_quit == 0) {
bzero(&pfd, sizeof(pfd));
- pfd[PFD_PIPE_MAIN].fd = msgbuf_main.sock;
+ pfd[PFD_PIPE_MAIN].fd = ibuf_main.sock;
pfd[PFD_PIPE_MAIN].events = POLLIN;
- if (msgbuf_main.queued > 0)
+ if (ibuf_main.w.queued > 0)
pfd[PFD_PIPE_MAIN].events |= POLLOUT;
- pfd[PFD_PIPE_SESSION].fd = msgbuf_se.sock;
+ pfd[PFD_PIPE_SESSION].fd = ibuf_se.sock;
pfd[PFD_PIPE_SESSION].events = POLLIN;
- if (msgbuf_se.queued > 0)
+ if (ibuf_se.w.queued > 0)
pfd[PFD_PIPE_SESSION].events |= POLLOUT;
if ((nfds = poll(pfd, 2, INFTIM)) == -1)
@@ -141,23 +138,22 @@ rde_main(struct bgpd_config *config, int pipe_m2r[2], int pipe_s2r[2])
fatal("poll error", errno);
if (nfds > 0 && pfd[PFD_PIPE_MAIN].revents & POLLIN)
- rde_dispatch_imsg(pfd[PFD_PIPE_MAIN].fd, PFD_PIPE_MAIN);
+ rde_dispatch_imsg(&ibuf_main, PFD_PIPE_MAIN);
if (nfds > 0 && pfd[PFD_PIPE_SESSION].revents & POLLIN)
- rde_dispatch_imsg(pfd[PFD_PIPE_SESSION].fd,
- PFD_PIPE_SESSION);
+ rde_dispatch_imsg(&ibuf_se, PFD_PIPE_SESSION);
if (nfds > 0 && (pfd[PFD_PIPE_MAIN].revents & POLLOUT) &&
- msgbuf_main.queued) {
+ ibuf_main.w.queued) {
nfds--;
- if ((n = msgbuf_write(&msgbuf_main)) == -1)
+ if ((n = msgbuf_write(&ibuf_main.w)) == -1)
fatal("pipe write error", errno);
}
if (nfds > 0 && (pfd[PFD_PIPE_SESSION].revents & POLLOUT) &&
- msgbuf_se.queued) {
+ ibuf_se.w.queued) {
nfds--;
- if ((n = msgbuf_write(&msgbuf_se)) ==
+ if ((n = msgbuf_write(&ibuf_se.w)) ==
-1)
fatal("pipe write error", errno);
}
@@ -168,7 +164,7 @@ rde_main(struct bgpd_config *config, int pipe_m2r[2], int pipe_s2r[2])
}
void
-rde_dispatch_imsg(int fd, int idx)
+rde_dispatch_imsg(struct imsgbuf *ibuf, int idx)
{
struct imsg imsg;
struct mrt mrtdump;
@@ -176,7 +172,7 @@ rde_dispatch_imsg(int fd, int idx)
struct rde_peer *p, *np;
u_int32_t rid;
- if (get_imsg(fd, &imsg) > 0) {
+ if (get_imsg(ibuf, &imsg) > 0) {
switch (imsg.hdr.type) {
case IMSG_RECONF_CONF:
if (idx != PFD_PIPE_MAIN)
@@ -247,14 +243,14 @@ rde_dispatch_imsg(int fd, int idx)
if (idx != PFD_PIPE_MAIN)
fatal("mrt request not from parent", 0);
mrtdump.id = imsg.hdr.peerid;
- mrtdump.msgbuf = &msgbuf_main;
+ mrtdump.msgbuf = &ibuf_main.w;
pt_dump(mrt_dump_upcall, &mrtdump);
/* FALLTHROUGH */
case IMSG_MRT_END:
if (idx != PFD_PIPE_MAIN)
fatal("mrt request not from parent", 0);
/* ignore end message because a dump is atomic */
- imsg_compose(&msgbuf_main, IMSG_MRT_END,
+ imsg_compose(&ibuf_main, IMSG_MRT_END,
imsg.hdr.peerid, NULL, 0);
break;
default:
@@ -506,7 +502,7 @@ rde_update_err(u_int32_t peerid, enum suberr_update errorcode)
u_int8_t errcode;
errcode = errorcode;
- imsg_compose(&msgbuf_se, IMSG_UPDATE_ERR, peerid,
+ imsg_compose(&ibuf_se, IMSG_UPDATE_ERR, peerid,
&errcode, sizeof(errcode));
}
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c
index 1274cd57518..04b5f259e47 100644
--- a/usr.sbin/bgpd/session.c
+++ b/usr.sbin/bgpd/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.25 2003/12/21 22:16:53 henning Exp $ */
+/* $OpenBSD: session.c,v 1.26 2003/12/21 23:26:38 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -72,7 +72,7 @@ int parse_open(struct peer *);
int parse_update(struct peer *);
int parse_notification(struct peer *);
int parse_keepalive(struct peer *);
-void session_dispatch_imsg(int, int);
+void session_dispatch_imsg(struct imsgbuf *, int);
void session_up(struct peer *);
void session_down(struct peer *);
@@ -81,7 +81,8 @@ struct peer *getpeerbyip(in_addr_t);
struct bgpd_config *conf = NULL, *nconf = NULL;
volatile sig_atomic_t session_quit = 0;
int pending_reconf = 0;
-struct msgbuf msgbuf_rde;
+struct imsgbuf ibuf_rde;
+struct imsgbuf ibuf_main;
void
session_sighdlr(int sig)
@@ -173,20 +174,19 @@ session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2])
close(pipe_m2s[0]);
close(pipe_s2r[1]);
init_conf(conf);
- msgbuf_init(&msgbuf_rde);
- msgbuf_rde.sock = pipe_s2r[0];
- init_imsg_buf();
+ imsg_init(&ibuf_rde, pipe_s2r[0]);
+ imsg_init(&ibuf_main, pipe_m2s[1]);
init_peers();
while (session_quit == 0) {
bzero(&pfd, sizeof(pfd));
pfd[PFD_LISTEN].fd = sock;
pfd[PFD_LISTEN].events = POLLIN;
- pfd[PFD_PIPE_MAIN].fd = pipe_m2s[1];
+ pfd[PFD_PIPE_MAIN].fd = ibuf_main.sock;
pfd[PFD_PIPE_MAIN].events = POLLIN;
- pfd[PFD_PIPE_ROUTE].fd = pipe_s2r[0];
+ pfd[PFD_PIPE_ROUTE].fd = ibuf_rde.sock;
pfd[PFD_PIPE_ROUTE].events = POLLIN;
- if (msgbuf_rde.queued > 0)
+ if (ibuf_rde.w.queued > 0)
pfd[PFD_PIPE_ROUTE].events |= POLLOUT;
nextaction = time(NULL) + 240; /* loop every 240s at least */
@@ -269,18 +269,16 @@ session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2])
if (nfds > 0 && pfd[PFD_PIPE_MAIN].revents & POLLIN) {
nfds--;
- session_dispatch_imsg(pfd[PFD_PIPE_MAIN].fd,
- PFD_PIPE_MAIN);
+ session_dispatch_imsg(&ibuf_main, PFD_PIPE_MAIN);
}
if (nfds > 0 && pfd[PFD_PIPE_ROUTE].revents & POLLOUT)
- if (msgbuf_write(&msgbuf_rde) == -1)
+ if (msgbuf_write(&ibuf_rde.w) == -1)
fatal("pipe write error", 0);
if (nfds > 0 && pfd[PFD_PIPE_ROUTE].revents & POLLIN) {
nfds--;
- session_dispatch_imsg(pfd[PFD_PIPE_ROUTE].fd,
- PFD_PIPE_ROUTE);
+ session_dispatch_imsg(&ibuf_rde, PFD_PIPE_ROUTE);
}
for (j = PFD_PEERS_START; nfds > 0 && j < i; j++) {
@@ -1159,7 +1157,7 @@ parse_update(struct peer *peer)
p += MSGSIZE_HEADER; /* header is already checked */
datalen -= MSGSIZE_HEADER;
- imsg_compose(&msgbuf_rde, IMSG_UPDATE, peer->conf.id, p, datalen);
+ imsg_compose(&ibuf_rde, IMSG_UPDATE, peer->conf.id, p, datalen);
return (0);
}
@@ -1199,14 +1197,14 @@ parse_notification(struct peer *peer)
}
void
-session_dispatch_imsg(int fd, int idx)
+session_dispatch_imsg(struct imsgbuf *ibuf, int idx)
{
struct imsg imsg;
struct peer_config *pconf;
struct peer *p, *next;
enum reconf_action reconf;
- if (get_imsg(fd, &imsg) > 0) {
+ if (get_imsg(ibuf, &imsg) > 0) {
switch (imsg.hdr.type) {
case IMSG_RECONF_CONF:
if (idx != PFD_PIPE_MAIN)
@@ -1309,13 +1307,13 @@ void
session_down(struct peer *peer)
{
if (!session_quit)
- imsg_compose(&msgbuf_rde, IMSG_SESSION_DOWN, peer->conf.id,
+ imsg_compose(&ibuf_rde, IMSG_SESSION_DOWN, peer->conf.id,
NULL, 0);
}
void
session_up(struct peer *peer)
{
- imsg_compose(&msgbuf_rde, IMSG_SESSION_UP, peer->conf.id,
+ imsg_compose(&ibuf_rde, IMSG_SESSION_UP, peer->conf.id,
&peer->remote_bgpid, sizeof(peer->remote_bgpid));
}