diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpd/mrt.c | 41 | ||||
-rw-r--r-- | usr.sbin/bgpd/mrt.h | 10 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.c | 21 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.c | 16 |
4 files changed, 39 insertions, 49 deletions
diff --git a/usr.sbin/bgpd/mrt.c b/usr.sbin/bgpd/mrt.c index afa50950eca..3b685ab18c5 100644 --- a/usr.sbin/bgpd/mrt.c +++ b/usr.sbin/bgpd/mrt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mrt.c,v 1.54 2009/02/19 21:34:40 claudio Exp $ */ +/* $OpenBSD: mrt.c,v 1.55 2009/03/13 05:43:50 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -171,8 +171,7 @@ mrt_dump_bgp_msg(struct mrt *mrt, void *pkg, u_int16_t pkglen, return (-1); } - TAILQ_INSERT_TAIL(&mrt->bufs, buf, entry); - mrt->queued++; + buf_close(&mrt->wbuf, buf); return (len + MRT_HEADER_SIZE); } @@ -235,8 +234,7 @@ mrt_dump_state(struct mrt *mrt, u_int16_t old_state, u_int16_t new_state, DUMP_SHORT(buf, old_state); DUMP_SHORT(buf, new_state); - TAILQ_INSERT_TAIL(&mrt->bufs, buf, entry); - mrt->queued++; + buf_close(&mrt->wbuf, buf); return (len + MRT_HEADER_SIZE); } @@ -452,8 +450,7 @@ mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, u_int16_t snum, return (-1); } - TAILQ_INSERT_TAIL(&mrt->bufs, buf, entry); - mrt->queued++; + buf_close(&mrt->wbuf, buf); return (len + MRT_HEADER_SIZE); } @@ -513,8 +510,7 @@ mrt_dump_entry(struct mrt *mrt, struct prefix *p, u_int16_t snum, return (-1); } - TAILQ_INSERT_TAIL(&mrt->bufs, buf, entry); - mrt->queued++; + buf_close(&mrt->wbuf, buf); return (len + MRT_HEADER_SIZE); } @@ -573,10 +569,10 @@ mrt_write(struct mrt *mrt) struct buf *b; int r = 0; - while ((b = TAILQ_FIRST(&mrt->bufs)) && - (r = buf_write(mrt->fd, b)) == 1) { - TAILQ_REMOVE(&mrt->bufs, b, entry); - mrt->queued--; + while ((b = TAILQ_FIRST(&mrt->wbuf.bufs)) && + (r = buf_write(mrt->wbuf.fd, b)) == 1) { + TAILQ_REMOVE(&mrt->wbuf.bufs, b, entry); + mrt->wbuf.queued--; buf_free(b); } if (r <= -1) { @@ -592,12 +588,12 @@ mrt_clean(struct mrt *mrt) { struct buf *b; - close(mrt->fd); - while ((b = TAILQ_FIRST(&mrt->bufs))) { - TAILQ_REMOVE(&mrt->bufs, b, entry); + close(mrt->wbuf.fd); + while ((b = TAILQ_FIRST(&mrt->wbuf.bufs))) { + TAILQ_REMOVE(&mrt->wbuf.bufs, b, entry); buf_free(b); } - mrt->queued = 0; + mrt->wbuf.queued = 0; } static struct imsgbuf *mrt_imsgbuf[2]; @@ -613,18 +609,17 @@ int mrt_open(struct mrt *mrt, time_t now) { enum imsg_type type; - int i; + int i, fd; if (strftime(MRT2MC(mrt)->file, sizeof(MRT2MC(mrt)->file), MRT2MC(mrt)->name, localtime(&now)) == 0) { log_warnx("mrt_open: strftime conversion failed"); - mrt->fd = -1; return (-1); } - mrt->fd = open(MRT2MC(mrt)->file, + fd = open(MRT2MC(mrt)->file, O_WRONLY|O_NONBLOCK|O_CREAT|O_TRUNC, 0644); - if (mrt->fd == -1) { + if (fd == -1) { log_warn("mrt_open %s", MRT2MC(mrt)->file); return (1); } @@ -636,7 +631,7 @@ mrt_open(struct mrt *mrt, time_t now) i = mrt->type == MRT_TABLE_DUMP ? 0 : 1; - if (imsg_compose(mrt_imsgbuf[i], type, 0, 0, mrt->fd, + if (imsg_compose(mrt_imsgbuf[i], type, 0, 0, fd, mrt, sizeof(struct mrt)) == -1) log_warn("mrt_open"); @@ -739,7 +734,6 @@ mrt_mergeconfig(struct mrt_head *xconf, struct mrt_head *nconf) if ((xm = calloc(1, sizeof(struct mrt_config))) == NULL) fatal("mrt_mergeconfig"); memcpy(xm, m, sizeof(struct mrt_config)); - xm->fd = -1; MRT2MC(xm)->state = MRT_STATE_OPEN; LIST_INSERT_HEAD(xconf, xm, entry); } else { @@ -767,4 +761,3 @@ mrt_mergeconfig(struct mrt_head *xconf, struct mrt_head *nconf) return (0); } - diff --git a/usr.sbin/bgpd/mrt.h b/usr.sbin/bgpd/mrt.h index b175b7f251b..5414be3edc8 100644 --- a/usr.sbin/bgpd/mrt.h +++ b/usr.sbin/bgpd/mrt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mrt.h,v 1.16 2007/05/30 04:28:27 msf Exp $ */ +/* $OpenBSD: mrt.h,v 1.17 2009/03/13 05:43:51 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -255,13 +255,11 @@ enum mrt_state { }; struct mrt { - enum mrt_type type; + struct msgbuf wbuf; + LIST_ENTRY(mrt) entry; u_int32_t peer_id; u_int32_t group_id; - u_int32_t queued; - int fd; - TAILQ_HEAD(, buf) bufs; - LIST_ENTRY(mrt) entry; + enum mrt_type type; }; struct mrt_config { diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 377917db28d..9cfe88e7b58 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.236 2009/03/13 04:19:43 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.237 2009/03/13 05:43:51 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -263,8 +263,8 @@ rde_main(struct bgpd_config *config, struct peer *peer_l, timeout = 0; i = 3; - if (mrt && mrt->queued) { - pfd[PFD_MRT_FILE].fd = mrt->fd; + if (mrt && mrt->wbuf.queued) { + pfd[PFD_MRT_FILE].fd = mrt->wbuf.fd; pfd[PFD_MRT_FILE].events = POLLOUT; i++; } @@ -303,8 +303,8 @@ rde_main(struct bgpd_config *config, struct peer *peer_l, if (mrt_write(mrt) == -1) { free(mrt); mrt = NULL; - } else if (mrt->queued == 0) - close(mrt->fd); + } else if (mrt->wbuf.queued == 0) + close(mrt->wbuf.fd); } rde_update_queue_runner(); @@ -694,15 +694,14 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf) if (xmrt == NULL) fatal("rde_dispatch_imsg_parent"); memcpy(xmrt, imsg.data, sizeof(struct mrt)); - TAILQ_INIT(&xmrt->bufs); + TAILQ_INIT(&xmrt->wbuf.bufs); - if ((xmrt->fd = imsg_get_fd(ibuf)) == -1) + if ((xmrt->wbuf.fd = imsg_get_fd(ibuf)) == -1) log_warnx("expected to receive fd for mrt dump " "but didn't receive any"); - - if (xmrt->type == MRT_TABLE_DUMP) { + else if (xmrt->type == MRT_TABLE_DUMP) { /* do not dump if another is still running */ - if (mrt == NULL || mrt->queued == 0) { + if (mrt == NULL || mrt->wbuf.queued == 0) { free(mrt); mrt = xmrt; mrt_clear_seq(); @@ -711,7 +710,7 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf) break; } } - close(xmrt->fd); + close(xmrt->wbuf.fd); free(xmrt); break; case IMSG_MRT_CLOSE: diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index f3a4d9b8e55..ee91f094b8e 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.285 2009/03/13 04:40:55 claudio Exp $ */ +/* $OpenBSD: session.c,v 1.286 2009/03/13 05:43:51 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> @@ -341,7 +341,7 @@ session_main(struct bgpd_config *config, struct peer *cpeers, mrt_cnt = 0; LIST_FOREACH(m, &mrthead, entry) - if (m->queued) + if (m->wbuf.queued) mrt_cnt++; if (mrt_cnt > mrt_l_elms) { @@ -469,8 +469,8 @@ session_main(struct bgpd_config *config, struct peer *cpeers, idx_peers = i; LIST_FOREACH(m, &mrthead, entry) - if (m->queued) { - pfd[i].fd = m->fd; + if (m->wbuf.queued) { + pfd[i].fd = m->wbuf.fd; pfd[i].events = POLLOUT; mrt_l[i - idx_peers] = m; i++; @@ -2423,7 +2423,7 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt) } memcpy(&xmrt, imsg.data, sizeof(struct mrt)); - if ((xmrt.fd = imsg_get_fd(ibuf)) == -1) + if ((xmrt.wbuf.fd = imsg_get_fd(ibuf)) == -1) log_warnx("expected to receive fd for mrt dump " "but didn't receive any"); @@ -2434,12 +2434,12 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt) if (mrt == NULL) fatal("session_dispatch_imsg"); memcpy(mrt, &xmrt, sizeof(struct mrt)); - TAILQ_INIT(&mrt->bufs); + TAILQ_INIT(&mrt->wbuf.bufs); LIST_INSERT_HEAD(&mrthead, mrt, entry); } else { /* old dump reopened */ - close(mrt->fd); - mrt->fd = xmrt.fd; + close(mrt->wbuf.fd); + mrt->wbuf.fd = xmrt.wbuf.fd; } break; case IMSG_MRT_CLOSE: |