1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 16:42:56 -08:00

Adjust bgpd to the new msgbuf_write / ibuf_write API

OK tb@
This commit is contained in:
claudio 2024-11-21 13:28:34 +00:00
parent a66ca8dacd
commit bb5614127f
5 changed files with 24 additions and 24 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bgpd.h,v 1.498 2024/10/08 12:28:09 claudio Exp $ */
/* $OpenBSD: bgpd.h,v 1.499 2024/11/21 13:28:34 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -1399,6 +1399,7 @@ struct mrt {
LIST_ENTRY(mrt) entry;
uint32_t peer_id;
uint32_t group_id;
int fd;
enum mrt_type type;
enum mrt_state state;
uint16_t seqnum;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mrt.c,v 1.119 2024/11/21 13:26:49 claudio Exp $ */
/* $OpenBSD: mrt.c,v 1.120 2024/11/21 13:28:34 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@ -1110,7 +1110,7 @@ fail:
void
mrt_write(struct mrt *mrt)
{
if (ibuf_write(&mrt->wbuf) == -1) {
if (ibuf_write(mrt->fd, &mrt->wbuf) == -1) {
log_warn("mrt dump aborted, mrt_write");
mrt_clean(mrt);
mrt_done(mrt);
@ -1120,7 +1120,7 @@ mrt_write(struct mrt *mrt)
void
mrt_clean(struct mrt *mrt)
{
close(mrt->wbuf.fd);
close(mrt->fd);
msgbuf_clear(&mrt->wbuf);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rde.c,v 1.637 2024/11/21 13:18:38 claudio Exp $ */
/* $OpenBSD: rde.c,v 1.638 2024/11/21 13:28:34 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -246,11 +246,11 @@ rde_main(int debug, int verbose)
if (i >= pfd_elms)
fatalx("poll pfd too small");
if (msgbuf_queuelen(&mctx->mrt.wbuf) > 0) {
pfd[i].fd = mctx->mrt.wbuf.fd;
pfd[i].fd = mctx->mrt.fd;
pfd[i].events = POLLOUT;
i++;
} else if (mctx->mrt.state == MRT_STATE_REMOVE) {
close(mctx->mrt.wbuf.fd);
close(mctx->mrt.fd);
LIST_REMOVE(mctx, entry);
free(mctx);
rde_mrt_cnt--;
@ -299,7 +299,7 @@ rde_main(int debug, int verbose)
for (j = PFD_PIPE_COUNT, mctx = LIST_FIRST(&rde_mrts);
j < i && mctx != 0; j++) {
if (pfd[j].fd == mctx->mrt.wbuf.fd &&
if (pfd[j].fd == mctx->mrt.fd &&
pfd[j].revents & POLLOUT)
mrt_write(&mctx->mrt);
mctx = LIST_NEXT(mctx, entry);
@ -345,7 +345,7 @@ rde_main(int debug, int verbose)
while ((mctx = LIST_FIRST(&rde_mrts)) != NULL) {
msgbuf_clear(&mctx->mrt.wbuf);
close(mctx->mrt.wbuf.fd);
close(mctx->mrt.fd);
LIST_REMOVE(mctx, entry);
free(mctx);
}
@ -3214,7 +3214,7 @@ rde_dump_mrt_new(struct mrt *mrt, pid_t pid, int fd)
}
memcpy(&ctx->mrt, mrt, sizeof(struct mrt));
msgbuf_init(&ctx->mrt.wbuf);
ctx->mrt.wbuf.fd = fd;
ctx->mrt.fd = fd;
ctx->mrt.state = MRT_STATE_RUNNING;
rid = rib_find(ctx->mrt.rib);
if (rid == RIB_NOTFOUND) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rtr_proto.c,v 1.43 2024/11/21 13:27:40 claudio Exp $ */
/* $OpenBSD: rtr_proto.c,v 1.44 2024/11/21 13:28:34 claudio Exp $ */
/*
* Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
@ -1272,7 +1272,7 @@ rtr_dispatch_msg(struct pollfd *pfd, struct rtr_session *rs)
return;
}
if (pfd->revents & POLLOUT && msgbuf_queuelen(&rs->w) > 0) {
if (ibuf_write(&rs->w) == -1) {
if (ibuf_write(rs->fd, &rs->w) == -1) {
log_warn("rtr %s: write error", log_rtr(rs));
rtr_fsm(rs, RTR_EVNT_CON_CLOSE);
return;
@ -1468,7 +1468,7 @@ rtr_open(struct rtr_session *rs, int fd)
rs->prev_version = rtr_max_session_version(rs);
}
rs->fd = rs->w.fd = fd;
rs->fd = fd;
rtr_fsm(rs, RTR_EVNT_CON_OPEN);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: session.c,v 1.491 2024/11/21 13:27:40 claudio Exp $ */
/* $OpenBSD: session.c,v 1.492 2024/11/21 13:28:34 claudio Exp $ */
/*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@ -435,7 +435,7 @@ session_main(int debug, int verbose)
LIST_FOREACH(m, &mrthead, entry)
if (msgbuf_queuelen(&m->wbuf) > 0) {
pfd[i].fd = m->wbuf.fd;
pfd[i].fd = m->fd;
pfd[i].events = POLLOUT;
mrt_l[i - idx_peers] = m;
i++;
@ -564,7 +564,7 @@ void
init_peer(struct peer *p)
{
TAILQ_INIT(&p->timers);
p->fd = p->wbuf.fd = -1;
p->fd = -1;
if (p->conf.if_depend[0])
imsg_compose(ibuf_main, IMSG_SESSION_DEPENDON, 0, 0, -1,
@ -865,7 +865,7 @@ session_close_connection(struct peer *peer)
close(peer->fd);
pauseaccept = 0;
}
peer->fd = peer->wbuf.fd = -1;
peer->fd = -1;
}
void
@ -887,7 +887,7 @@ change_state(struct peer *peer, enum session_state state,
*/
if (peer->state >= STATE_OPENSENT &&
msgbuf_queuelen(&peer->wbuf) > 0)
ibuf_write(&peer->wbuf);
ibuf_write(peer->fd, &peer->wbuf);
/*
* we must start the timer for the next EVNT_START
@ -1044,7 +1044,7 @@ open:
close(connfd);
return;
}
p->fd = p->wbuf.fd = connfd;
p->fd = connfd;
if (session_setup_socket(p)) {
close(connfd);
return;
@ -1095,7 +1095,6 @@ session_connect(struct peer *peer)
if (tcp_md5_set(peer->fd, &peer->auth_conf,
&peer->conf.remote_addr) == -1)
log_peer_warn(&peer->conf, "setting md5sig");
peer->wbuf.fd = peer->fd;
/* if local-address is set we need to bind() */
bind_addr = session_localaddr(peer);
@ -1935,7 +1934,7 @@ session_dispatch_msg(struct pollfd *pfd, struct peer *p)
}
if (pfd->revents & POLLOUT && msgbuf_queuelen(&p->wbuf) > 0) {
if (ibuf_write(&p->wbuf) == -1) {
if (ibuf_write(p->fd, &p->wbuf) == -1) {
if (errno == EPIPE)
log_peer_warnx(&p->conf, "Connection closed");
else
@ -3152,7 +3151,7 @@ session_dispatch_imsg(struct imsgbuf *imsgbuf, int idx, u_int *listener_cnt)
break;
}
if ((xmrt.wbuf.fd = imsg_get_fd(&imsg)) == -1) {
if ((xmrt.fd = imsg_get_fd(&imsg)) == -1) {
log_warnx("expected to receive fd for mrt dump "
"but didn't receive any");
break;
@ -3169,9 +3168,9 @@ session_dispatch_imsg(struct imsgbuf *imsgbuf, int idx, u_int *listener_cnt)
LIST_INSERT_HEAD(&mrthead, mrt, entry);
} else {
/* old dump reopened */
close(mrt->wbuf.fd);
close(mrt->fd);
}
mrt->wbuf.fd = xmrt.wbuf.fd;
mrt->fd = xmrt.fd;
break;
case IMSG_MRT_CLOSE:
if (idx != PFD_PIPE_MAIN)