diff options
-rw-r--r-- | usr.sbin/bgpd/bgpd.c | 12 | ||||
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 3 | ||||
-rw-r--r-- | usr.sbin/bgpd/imsg.c | 25 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.c | 14 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.c | 14 |
5 files changed, 49 insertions, 19 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index fb2cbd6ea79..370d8948948 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.47 2003/12/30 22:42:31 henning Exp $ */ +/* $OpenBSD: bgpd.c,v 1.48 2004/01/01 23:09:08 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -340,10 +340,16 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct mrt_config *conf) int n; in_addr_t ina; - if ((n = imsg_get(ibuf, &imsg)) == -1) + if (imsg_read(ibuf) == -1) return (-1); - if (n > 0) { + for (;;) { + if ((n = imsg_get(ibuf, &imsg)) == -1) + return (-1); + + if (n == 0) + break; + switch (imsg.hdr.type) { case IMSG_MRT_MSG: case IMSG_MRT_END: diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 0c3a48dada9..8e766659d9e 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.44 2003/12/28 14:34:30 henning Exp $ */ +/* $OpenBSD: bgpd.h,v 1.45 2004/01/01 23:09:08 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -294,6 +294,7 @@ int merge_config(struct bgpd_config *, struct bgpd_config *); /* imsg.c */ void imsg_init(struct imsgbuf *, int); +int imsg_read(struct imsgbuf *); int imsg_get(struct imsgbuf *, struct imsg *); int imsg_compose(struct imsgbuf *, int, u_int32_t, void *, u_int16_t); void imsg_free(struct imsg *); diff --git a/usr.sbin/bgpd/imsg.c b/usr.sbin/bgpd/imsg.c index ed80e399c45..5201c8fc353 100644 --- a/usr.sbin/bgpd/imsg.c +++ b/usr.sbin/bgpd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.14 2003/12/30 22:42:31 henning Exp $ */ +/* $OpenBSD: imsg.c,v 1.15 2004/01/01 23:09:09 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -35,10 +35,9 @@ imsg_init(struct imsgbuf *ibuf, int sock) } int -imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) +imsg_read(struct imsgbuf *ibuf) { - ssize_t n, datalen = 0; - size_t av, left; + ssize_t n; if ((n = read(ibuf->sock, ibuf->r.buf + ibuf->r.wpos, sizeof(ibuf->r.buf) - ibuf->r.wpos)) == -1) { @@ -52,10 +51,22 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) logit(LOG_CRIT, "imsg_get: pipe close"); return (-1); } - av = ibuf->r.wpos + n; + + ibuf->r.wpos += n; + + return (0); +} + +int +imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) +{ + ssize_t datalen = 0; + size_t av, left; + + av = ibuf->r.wpos; if (IMSG_HEADER_SIZE > av) - return (-1); + return (0); memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr)); if (imsg->hdr.len < IMSG_HEADER_SIZE || @@ -64,7 +75,7 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) return (-1); } if (imsg->hdr.len > av) - return (-1); + return (0); datalen = imsg->hdr.len - IMSG_HEADER_SIZE; ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE; if ((imsg->data = malloc(datalen)) == NULL) { diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index e8b1248f1db..236589583be 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.39 2003/12/27 00:53:51 henning Exp $ */ +/* $OpenBSD: rde.c,v 1.40 2004/01/01 23:09:09 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -176,10 +176,16 @@ rde_dispatch_imsg(struct imsgbuf *ibuf, int idx) u_int32_t rid; int n; - if ((n = imsg_get(ibuf, &imsg)) == -1) - fatal("imsg_get error"); + if (imsg_read(ibuf) == -1) + fatal("rde_dispatch_imsg: imsg_read error"); + + for (;;) { + if ((n = imsg_get(ibuf, &imsg)) == -1) + fatal("rde_dispatch_imsg: imsg_read error"); + + if (n == 0) + break; - if (n > 0) { switch (imsg.hdr.type) { case IMSG_RECONF_CONF: if (idx != PFD_PIPE_MAIN) diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index 7b49c972403..1bc5f7b08a8 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.52 2003/12/30 21:05:09 henning Exp $ */ +/* $OpenBSD: session.c,v 1.53 2004/01/01 23:09:09 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -1250,10 +1250,16 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx) enum reconf_action reconf; int n; - if ((n = imsg_get(ibuf, &imsg)) == -1) - fatal("imsg_get error"); + if (imsg_read(ibuf) == -1) + fatal("session_dispatch_imsg: imsg_read error"); + + for (;;) { + if ((n = imsg_get(ibuf, &imsg)) == -1) + fatal("session_dispatch_imsg: imsg_get error"); + + if (n == 0) + break; - if (n > 0) { switch (imsg.hdr.type) { case IMSG_RECONF_CONF: if (idx != PFD_PIPE_MAIN) |