diff options
author | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2007-07-24 16:46:10 +0000 |
---|---|---|
committer | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2007-07-24 16:46:10 +0000 |
commit | 59aefeb61de47e83861ab043b0ad7b5e0322c21d (patch) | |
tree | 7247b77841b722abeb9d89910b0d50bcb3b27629 /usr.sbin | |
parent | af21ec176ff36692bd4733d5b6bf996e5ead9379 (diff) |
make imsg_create use dynamic buffers.
this does not change imsg_compose's behavior but allows the message's
buffer to grow and will avoid sending a ton of small messages when
unrolling lists between two processes.
this is needed for sending multiple routes at once when updating the
fib with multipath routes.
discussed and ok claudio@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ospfd/imsg.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/usr.sbin/ospfd/imsg.c b/usr.sbin/ospfd/imsg.c index dc558c1565a..9bd6cabd33f 100644 --- a/usr.sbin/ospfd/imsg.c +++ b/usr.sbin/ospfd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.8 2007/03/19 10:03:25 henning Exp $ */ +/* $OpenBSD: imsg.c,v 1.9 2007/07/24 16:46:09 pyr Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -122,19 +122,19 @@ imsg_create(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid, struct buf *wbuf; struct imsg_hdr hdr; - if (datalen > MAX_IMSGSIZE - IMSG_HEADER_SIZE) { + datalen += IMSG_HEADER_SIZE; + if (datalen > MAX_IMSGSIZE) { log_warnx("imsg_create: len %u > MAX_IMSGSIZE; " "type %u peerid %lu", datalen + IMSG_HEADER_SIZE, type, peerid); return (NULL); } - hdr.len = (u_int16_t)(datalen + IMSG_HEADER_SIZE); hdr.type = type; hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_open(hdr.len)) == NULL) { + if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { log_warn("imsg_create: buf_open"); return (NULL); } @@ -159,8 +159,11 @@ imsg_add(struct buf *msg, void *data, u_int16_t datalen) int imsg_close(struct imsgbuf *ibuf, struct buf *msg) { - int n; + int n; + struct imsg_hdr *hdr; + hdr = (struct imsg_hdr *)msg->buf; + hdr->len = (u_int16_t)msg->wpos; if ((n = buf_close(&ibuf->w, msg)) < 0) { log_warnx("imsg_close: buf_close error"); buf_free(msg); |