diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-05-26 13:56:09 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-05-26 13:56:09 +0000 |
commit | 4b9cf3ab192c7e5b1ee8b915d25de6b18cbd1f7e (patch) | |
tree | c8f546660680faabd30571e97e67f49483698059 | |
parent | f11125202098e763efa8b52b0e92bfac7a124175 (diff) |
Rename some imsg bits to make namespace collisions less likely buf to
ibuf, buf_read to ibuf_read, READ_BUF_SIZE to IBUF_READ_SIZE.
ok henning gilles claudio jacekm deraadt
102 files changed, 1395 insertions, 1395 deletions
diff --git a/usr.bin/tmux/imsg-buffer.c b/usr.bin/tmux/imsg-buffer.c index eeadf33af3e..a027e47206b 100644 --- a/usr.bin/tmux/imsg-buffer.c +++ b/usr.bin/tmux/imsg-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg-buffer.c,v 1.2 2009/09/15 18:12:51 jacekm Exp $ */ +/* $OpenBSD: imsg-buffer.c,v 1.3 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.bin/tmux/imsg.c b/usr.bin/tmux/imsg.c index 1a229281a72..923fbd55313 100644 --- a/usr.bin/tmux/imsg.c +++ b/usr.bin/tmux/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.2 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.3 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.bin/tmux/imsg.h b/usr.bin/tmux/imsg.h index e91e9a28f7d..642a12c9145 100644 --- a/usr.bin/tmux/imsg.h +++ b/usr.bin/tmux/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.3 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.4 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index a4e80febba7..ddf0c69d524 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.159 2010/05/03 13:11:41 claudio Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.160 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -168,7 +168,7 @@ main(int argc, char *argv[]) break; case SHOW_FIB: if (!res->addr.aid) { - struct buf *msg; + struct ibuf *msg; sa_family_t af; af = aid2af(res->aid); diff --git a/usr.sbin/bgpd/buffer.c b/usr.sbin/bgpd/buffer.c index 0d8a465b8f9..3d9fdba50a3 100644 --- a/usr.sbin/bgpd/buffer.c +++ b/usr.sbin/bgpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.45 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.46 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/bgpd/imsg.c b/usr.sbin/bgpd/imsg.c index 58fd1e27315..f6315cae39e 100644 --- a/usr.sbin/bgpd/imsg.c +++ b/usr.sbin/bgpd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.49 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.50 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/bgpd/imsg.h b/usr.sbin/bgpd/imsg.h index 9fd3f2f4964..43564710bb2 100644 --- a/usr.sbin/bgpd/imsg.h +++ b/usr.sbin/bgpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.5 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.6 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/bgpd/mrt.c b/usr.sbin/bgpd/mrt.c index 6fee4d2bd0d..95d2403f594 100644 --- a/usr.sbin/bgpd/mrt.c +++ b/usr.sbin/bgpd/mrt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mrt.c,v 1.67 2010/04/22 08:21:18 claudio Exp $ */ +/* $OpenBSD: mrt.c,v 1.68 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -32,20 +32,20 @@ #include "mrt.h" -int mrt_attr_dump(struct buf *, struct rde_aspath *, struct bgpd_addr *); +int mrt_attr_dump(struct ibuf *, struct rde_aspath *, struct bgpd_addr *); int mrt_dump_entry_mp(struct mrt *, struct prefix *, u_int16_t, struct rde_peer*); int mrt_dump_entry(struct mrt *, struct prefix *, u_int16_t, struct rde_peer*); -int mrt_dump_hdr_se(struct buf **, struct peer *, u_int16_t, u_int16_t, +int mrt_dump_hdr_se(struct ibuf **, struct peer *, u_int16_t, u_int16_t, u_int32_t, int); -int mrt_dump_hdr_rde(struct buf **, u_int16_t type, u_int16_t, u_int32_t); +int mrt_dump_hdr_rde(struct ibuf **, u_int16_t type, u_int16_t, u_int32_t); int mrt_open(struct mrt *, time_t); #define DUMP_BYTE(x, b) \ do { \ u_char t = (b); \ - if (buf_add((x), &t, sizeof(t)) == -1) { \ - log_warnx("mrt_dump1: buf_add error"); \ + if (ibuf_add((x), &t, sizeof(t)) == -1) { \ + log_warnx("mrt_dump1: ibuf_add error"); \ goto fail; \ } \ } while (0) @@ -54,8 +54,8 @@ int mrt_open(struct mrt *, time_t); do { \ u_int16_t t; \ t = htons((s)); \ - if (buf_add((x), &t, sizeof(t)) == -1) { \ - log_warnx("mrt_dump2: buf_add error"); \ + if (ibuf_add((x), &t, sizeof(t)) == -1) { \ + log_warnx("mrt_dump2: ibuf_add error"); \ goto fail; \ } \ } while (0) @@ -64,8 +64,8 @@ int mrt_open(struct mrt *, time_t); do { \ u_int32_t t; \ t = htonl((l)); \ - if (buf_add((x), &t, sizeof(t)) == -1) { \ - log_warnx("mrt_dump3: buf_add error"); \ + if (ibuf_add((x), &t, sizeof(t)) == -1) { \ + log_warnx("mrt_dump3: ibuf_add error"); \ goto fail; \ } \ } while (0) @@ -73,8 +73,8 @@ int mrt_open(struct mrt *, time_t); #define DUMP_NLONG(x, l) \ do { \ u_int32_t t = (l); \ - if (buf_add((x), &t, sizeof(t)) == -1) { \ - log_warnx("mrt_dump4: buf_add error"); \ + if (ibuf_add((x), &t, sizeof(t)) == -1) { \ + log_warnx("mrt_dump4: ibuf_add error"); \ goto fail; \ } \ } while (0) @@ -83,7 +83,7 @@ void mrt_dump_bgp_msg(struct mrt *mrt, void *pkg, u_int16_t pkglen, struct peer *peer) { - struct buf *buf; + struct ibuf *buf; int incoming = 0; u_int16_t subtype = BGP4MP_MESSAGE; @@ -98,20 +98,20 @@ mrt_dump_bgp_msg(struct mrt *mrt, void *pkg, u_int16_t pkglen, pkglen, incoming) == -1) return; - if (buf_add(buf, pkg, pkglen) == -1) { + if (ibuf_add(buf, pkg, pkglen) == -1) { log_warnx("mrt_dump_bgp_msg: buf_add error"); - buf_free(buf); + ibuf_free(buf); return; } - buf_close(&mrt->wbuf, buf); + ibuf_close(&mrt->wbuf, buf); } void mrt_dump_state(struct mrt *mrt, u_int16_t old_state, u_int16_t new_state, struct peer *peer) { - struct buf *buf; + struct ibuf *buf; u_int16_t subtype = BGP4MP_STATE_CHANGE; if (peer->capa.neg.as4byte) @@ -124,15 +124,15 @@ 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); - buf_close(&mrt->wbuf, buf); + ibuf_close(&mrt->wbuf, buf); return; fail: - buf_free(buf); + ibuf_free(buf); } int -mrt_attr_dump(struct buf *buf, struct rde_aspath *a, struct bgpd_addr *nexthop) +mrt_attr_dump(struct ibuf *buf, struct rde_aspath *a, struct bgpd_addr *nexthop) { struct attr *oa; u_char *pdata; @@ -197,14 +197,14 @@ int mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, u_int16_t snum, struct rde_peer *peer) { - struct buf *buf, *hbuf = NULL, *h2buf = NULL; + struct ibuf *buf, *hbuf = NULL, *h2buf = NULL; void *bptr; struct bgpd_addr addr, nexthop, *nh; u_int16_t len; u_int8_t p_len; u_int8_t aid; - if ((buf = buf_dynamic(0, MAX_PKTSIZE)) == NULL) { + if ((buf = ibuf_dynamic(0, MAX_PKTSIZE)) == NULL) { log_warn("mrt_dump_entry_mp: buf_dynamic"); return (-1); } @@ -213,9 +213,9 @@ mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, u_int16_t snum, log_warnx("mrt_dump_entry_mp: mrt_attr_dump error"); goto fail; } - len = buf_size(buf); + len = ibuf_size(buf); - if ((h2buf = buf_dynamic(MRT_BGP4MP_IPv4_HEADER_SIZE + + if ((h2buf = ibuf_dynamic(MRT_BGP4MP_IPv4_HEADER_SIZE + MRT_BGP4MP_IPv4_ENTRY_SIZE, MRT_BGP4MP_IPv6_HEADER_SIZE + MRT_BGP4MP_IPv6_ENTRY_SIZE + MRT_BGP4MP_MAX_PREFIXLEN)) == NULL) { log_warn("mrt_dump_entry_mp: buf_dynamic"); @@ -237,9 +237,9 @@ mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, u_int16_t snum, break; case AID_INET6: DUMP_SHORT(h2buf, AFI_IPv6); - if (buf_add(h2buf, &peer->local_v6_addr.v6, + if (ibuf_add(h2buf, &peer->local_v6_addr.v6, sizeof(struct in6_addr)) == -1 || - buf_add(h2buf, &peer->remote_addr.v6, + ibuf_add(h2buf, &peer->remote_addr.v6, sizeof(struct in6_addr)) == -1) { log_warnx("mrt_dump_entry_mp: buf_add error"); goto fail; @@ -273,7 +273,7 @@ mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, u_int16_t snum, DUMP_SHORT(h2buf, AFI_IPv6); /* afi */ DUMP_BYTE(h2buf, SAFI_UNICAST); /* safi */ DUMP_BYTE(h2buf, 16); /* nhlen */ - if (buf_add(h2buf, &nh->v6, sizeof(struct in6_addr)) == -1) { + if (ibuf_add(h2buf, &nh->v6, sizeof(struct in6_addr)) == -1) { log_warnx("mrt_dump_entry_mp: buf_add error"); goto fail; } @@ -284,7 +284,7 @@ mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, u_int16_t snum, } p_len = PREFIX_SIZE(p->prefix->prefixlen); - if ((bptr = buf_reserve(h2buf, p_len)) == NULL) { + if ((bptr = ibuf_reserve(h2buf, p_len)) == NULL) { log_warnx("mrt_dump_entry_mp: buf_reserve error"); goto fail; } @@ -294,24 +294,24 @@ mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, u_int16_t snum, } DUMP_SHORT(h2buf, len); - len += buf_size(h2buf); + len += ibuf_size(h2buf); if (mrt_dump_hdr_rde(&hbuf, MSG_PROTOCOL_BGP4MP, BGP4MP_ENTRY, len) == -1) goto fail; - buf_close(&mrt->wbuf, hbuf); - buf_close(&mrt->wbuf, h2buf); - buf_close(&mrt->wbuf, buf); + ibuf_close(&mrt->wbuf, hbuf); + ibuf_close(&mrt->wbuf, h2buf); + ibuf_close(&mrt->wbuf, buf); return (len + MRT_HEADER_SIZE); fail: if (hbuf) - buf_free(hbuf); + ibuf_free(hbuf); if (h2buf) - buf_free(h2buf); - buf_free(buf); + ibuf_free(h2buf); + ibuf_free(buf); return (-1); } @@ -319,7 +319,7 @@ int mrt_dump_entry(struct mrt *mrt, struct prefix *p, u_int16_t snum, struct rde_peer *peer) { - struct buf *buf, *hbuf; + struct ibuf *buf, *hbuf; struct bgpd_addr addr, *nh; size_t len; @@ -328,7 +328,7 @@ mrt_dump_entry(struct mrt *mrt, struct prefix *p, u_int16_t snum, /* only able to dump IPv4 */ return (0); - if ((buf = buf_dynamic(0, MAX_PKTSIZE)) == NULL) { + if ((buf = ibuf_dynamic(0, MAX_PKTSIZE)) == NULL) { log_warnx("mrt_dump_entry: buf_dynamic"); return (-1); } @@ -341,13 +341,13 @@ mrt_dump_entry(struct mrt *mrt, struct prefix *p, u_int16_t snum, nh = &p->aspath->nexthop->exit_nexthop; if (mrt_attr_dump(buf, p->aspath, nh) == -1) { log_warnx("mrt_dump_entry: mrt_attr_dump error"); - buf_free(buf); + ibuf_free(buf); return (-1); } - len = buf_size(buf); + len = ibuf_size(buf); if (mrt_dump_hdr_rde(&hbuf, MSG_TABLE_DUMP, AFI_IPv4, len) == -1) { - buf_free(buf); + ibuf_free(buf); return (-1); } @@ -364,14 +364,14 @@ mrt_dump_entry(struct mrt *mrt, struct prefix *p, u_int16_t snum, DUMP_SHORT(hbuf, peer->short_as); DUMP_SHORT(hbuf, len); - buf_close(&mrt->wbuf, hbuf); - buf_close(&mrt->wbuf, buf); + ibuf_close(&mrt->wbuf, hbuf); + ibuf_close(&mrt->wbuf, buf); return (len + MRT_HEADER_SIZE); fail: - buf_free(hbuf); - buf_free(buf); + ibuf_free(hbuf); + ibuf_free(buf); return (-1); } @@ -405,12 +405,12 @@ mrt_done(void *ptr) } int -mrt_dump_hdr_se(struct buf ** bp, struct peer *peer, u_int16_t type, +mrt_dump_hdr_se(struct ibuf ** bp, struct peer *peer, u_int16_t type, u_int16_t subtype, u_int32_t len, int swap) { time_t now; - if ((*bp = buf_dynamic(MRT_HEADER_SIZE, MRT_HEADER_SIZE + + if ((*bp = ibuf_dynamic(MRT_HEADER_SIZE, MRT_HEADER_SIZE + MRT_BGP4MP_AS4_IPv6_HEADER_SIZE + len)) == NULL) { log_warnx("mrt_dump_hdr_se: buf_open error"); return (-1); @@ -478,20 +478,20 @@ mrt_dump_hdr_se(struct buf ** bp, struct peer *peer, u_int16_t type, case AF_INET6: DUMP_SHORT(*bp, AFI_IPv6); if (!swap) - if (buf_add(*bp, &((struct sockaddr_in6 *) + if (ibuf_add(*bp, &((struct sockaddr_in6 *) &peer->sa_local)->sin6_addr, sizeof(struct in6_addr)) == -1) { log_warnx("mrt_dump_hdr_se: buf_add error"); goto fail; } - if (buf_add(*bp, + if (ibuf_add(*bp, &((struct sockaddr_in6 *)&peer->sa_remote)->sin6_addr, sizeof(struct in6_addr)) == -1) { log_warnx("mrt_dump_hdr_se: buf_add error"); goto fail; } if (swap) - if (buf_add(*bp, &((struct sockaddr_in6 *) + if (ibuf_add(*bp, &((struct sockaddr_in6 *) &peer->sa_local)->sin6_addr, sizeof(struct in6_addr)) == -1) { log_warnx("mrt_dump_hdr_se: buf_add error"); @@ -503,17 +503,17 @@ mrt_dump_hdr_se(struct buf ** bp, struct peer *peer, u_int16_t type, return (0); fail: - buf_free(*bp); + ibuf_free(*bp); return (-1); } int -mrt_dump_hdr_rde(struct buf **bp, u_int16_t type, u_int16_t subtype, +mrt_dump_hdr_rde(struct ibuf **bp, u_int16_t type, u_int16_t subtype, u_int32_t len) { time_t now; - if ((*bp = buf_dynamic(MRT_HEADER_SIZE, MRT_HEADER_SIZE + + if ((*bp = ibuf_dynamic(MRT_HEADER_SIZE, MRT_HEADER_SIZE + MRT_BGP4MP_AS4_IPv6_HEADER_SIZE + MRT_BGP4MP_IPv6_ENTRY_SIZE)) == NULL) { log_warnx("mrt_dump_hdr_rde: buf_dynamic error"); @@ -539,7 +539,7 @@ mrt_dump_hdr_rde(struct buf **bp, u_int16_t type, u_int16_t subtype, return (0); fail: - buf_free(*bp); + ibuf_free(*bp); return (-1); } @@ -548,7 +548,7 @@ mrt_write(struct mrt *mrt) { int r; - if ((r = buf_write(&mrt->wbuf)) < 0) { + if ((r = ibuf_write(&mrt->wbuf)) < 0) { log_warn("mrt dump aborted, mrt_write"); mrt_clean(mrt); mrt_done(mrt); @@ -558,12 +558,12 @@ mrt_write(struct mrt *mrt) void mrt_clean(struct mrt *mrt) { - struct buf *b; + struct ibuf *b; close(mrt->wbuf.fd); while ((b = TAILQ_FIRST(&mrt->wbuf.bufs))) { TAILQ_REMOVE(&mrt->wbuf.bufs, b, entry); - buf_free(b); + ibuf_free(b); } mrt->wbuf.queued = 0; } diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 4daea46e753..8f78fd7d1b0 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.295 2010/05/19 12:44:14 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.296 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -1876,7 +1876,7 @@ void rde_update_err(struct rde_peer *peer, u_int8_t error, u_int8_t suberr, void *data, u_int16_t size) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf_se, IMSG_UPDATE_ERR, peer->conf.id, 0, size + sizeof(error) + sizeof(suberr))) == NULL) @@ -2048,7 +2048,7 @@ void rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags) { struct ctl_show_rib rib; - struct buf *wbuf; + struct ibuf *wbuf; struct attr *a; void *bp; u_int8_t l; @@ -2108,13 +2108,13 @@ rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags) IMSG_CTL_SHOW_RIB_ATTR, 0, pid, attr_optlen(a))) == NULL) return; - if ((bp = buf_reserve(wbuf, attr_optlen(a))) == NULL) { - buf_free(wbuf); + if ((bp = ibuf_reserve(wbuf, attr_optlen(a))) == NULL) { + ibuf_free(wbuf); return; } if (attr_write(bp, attr_optlen(a), a->flags, a->type, a->data, a->len) == -1) { - buf_free(wbuf); + ibuf_free(wbuf); return; } imsg_close(ibuf_se_ctl, wbuf); diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 687b44d3998..3c0db096f4e 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.136 2010/05/19 12:44:15 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.137 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and @@ -313,7 +313,7 @@ int rde_as4byte(struct rde_peer *); /* rde_attr.c */ int attr_write(void *, u_int16_t, u_int8_t, u_int8_t, void *, u_int16_t); -int attr_writebuf(struct buf *, u_int8_t, u_int8_t, void *, +int attr_writebuf(struct ibuf *, u_int8_t, u_int8_t, void *, u_int16_t); void attr_init(u_int32_t); void attr_shutdown(void); diff --git a/usr.sbin/bgpd/rde_attr.c b/usr.sbin/bgpd/rde_attr.c index e38473ff8d8..f00f82dddcb 100644 --- a/usr.sbin/bgpd/rde_attr.c +++ b/usr.sbin/bgpd/rde_attr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_attr.c,v 1.84 2010/05/17 16:08:20 claudio Exp $ */ +/* $OpenBSD: rde_attr.c,v 1.85 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> @@ -63,7 +63,7 @@ attr_write(void *p, u_int16_t p_len, u_int8_t flags, u_int8_t type, } int -attr_writebuf(struct buf *buf, u_int8_t flags, u_int8_t type, void *data, +attr_writebuf(struct ibuf *buf, u_int8_t flags, u_int8_t type, void *data, u_int16_t data_len) { u_char hdr[4]; @@ -80,9 +80,9 @@ attr_writebuf(struct buf *buf, u_int8_t flags, u_int8_t type, void *data, hdr[0] = flags; hdr[1] = type; - if (buf_add(buf, hdr, flags & ATTR_EXTLEN ? 4 : 3) == -1) + if (ibuf_add(buf, hdr, flags & ATTR_EXTLEN ? 4 : 3) == -1) return (-1); - if (buf_add(buf, data, data_len) == -1) + if (ibuf_add(buf, data, data_len) == -1) return (-1); return (0); } diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index 858896adac2..086cbd1ef4b 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.308 2010/05/03 13:09:38 claudio Exp $ */ +/* $OpenBSD: session.c,v 1.309 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> @@ -65,8 +65,8 @@ void session_accept(int); int session_connect(struct peer *); void session_tcp_established(struct peer *); void session_capa_ann_none(struct peer *); -int session_capa_add(struct buf *, u_int8_t, u_int8_t); -int session_capa_add_mp(struct buf *, u_int8_t); +int session_capa_add(struct ibuf *, u_int8_t, u_int8_t); +int session_capa_add_mp(struct ibuf *, u_int8_t); struct bgp_msg *session_newmsg(enum msg_type, u_int16_t); int session_sendmsg(struct bgp_msg *, struct peer *); void session_open(struct peer *); @@ -626,7 +626,7 @@ bgp_fsm(struct peer *peer, enum session_events event) timer_stop(peer, Timer_IdleHold); /* allocate read buffer */ - peer->rbuf = calloc(1, sizeof(struct buf_read)); + peer->rbuf = calloc(1, sizeof(struct ibuf_read)); if (peer->rbuf == NULL) fatal(NULL); @@ -1227,17 +1227,17 @@ session_capa_ann_none(struct peer *peer) } int -session_capa_add(struct buf *opb, u_int8_t capa_code, u_int8_t capa_len) +session_capa_add(struct ibuf *opb, u_int8_t capa_code, u_int8_t capa_len) { int errs = 0; - errs += buf_add(opb, &capa_code, sizeof(capa_code)); - errs += buf_add(opb, &capa_len, sizeof(capa_len)); + errs += ibuf_add(opb, &capa_code, sizeof(capa_code)); + errs += ibuf_add(opb, &capa_len, sizeof(capa_len)); return (errs); } int -session_capa_add_mp(struct buf *buf, u_int8_t aid) +session_capa_add_mp(struct ibuf *buf, u_int8_t aid) { u_int8_t safi, pad = 0; u_int16_t afi; @@ -1246,9 +1246,9 @@ session_capa_add_mp(struct buf *buf, u_int8_t aid) if (aid2afi(aid, &afi, &safi) == -1) fatalx("session_capa_add_mp: bad afi/safi pair"); afi = htons(afi); - errs += buf_add(buf, &afi, sizeof(afi)); - errs += buf_add(buf, &pad, sizeof(pad)); - errs += buf_add(buf, &safi, sizeof(safi)); + errs += ibuf_add(buf, &afi, sizeof(afi)); + errs += ibuf_add(buf, &pad, sizeof(pad)); + errs += ibuf_add(buf, &safi, sizeof(safi)); return (errs); } @@ -1258,23 +1258,23 @@ session_newmsg(enum msg_type msgtype, u_int16_t len) { struct bgp_msg *msg; struct msg_header hdr; - struct buf *buf; + struct ibuf *buf; int errs = 0; memset(&hdr.marker, 0xff, sizeof(hdr.marker)); hdr.len = htons(len); hdr.type = msgtype; - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); - errs += buf_add(buf, &hdr.marker, sizeof(hdr.marker)); - errs += buf_add(buf, &hdr.len, sizeof(hdr.len)); - errs += buf_add(buf, &hdr.type, sizeof(hdr.type)); + errs += ibuf_add(buf, &hdr.marker, sizeof(hdr.marker)); + errs += ibuf_add(buf, &hdr.len, sizeof(hdr.len)); + errs += ibuf_add(buf, &hdr.type, sizeof(hdr.type)); if (errs > 0 || (msg = calloc(1, sizeof(*msg))) == NULL) { - buf_free(buf); + ibuf_free(buf); return (NULL); } @@ -1300,7 +1300,7 @@ session_sendmsg(struct bgp_msg *msg, struct peer *p) mrt_dump_bgp_msg(mrt, msg->buf->buf, msg->len, p); } - buf_close(&p->wbuf, msg->buf); + ibuf_close(&p->wbuf, msg->buf); free(msg); return (0); } @@ -1309,14 +1309,14 @@ void session_open(struct peer *p) { struct bgp_msg *buf; - struct buf *opb; + struct ibuf *opb; struct msg_open msg; u_int16_t len; u_int8_t i, op_type, optparamlen = 0; u_int errs = 0; - if ((opb = buf_dynamic(0, UCHAR_MAX - sizeof(op_type) - + if ((opb = ibuf_dynamic(0, UCHAR_MAX - sizeof(op_type) - sizeof(optparamlen))) == NULL) { bgp_fsm(p, EVNT_CON_FATAL); return; @@ -1340,7 +1340,7 @@ session_open(struct peer *p) c[0] = 0x80; /* we're always restarting */ c[1] = 0; errs += session_capa_add(opb, CAPA_RESTART, 2); - errs += buf_add(opb, &c, 2); + errs += ibuf_add(opb, &c, 2); } /* 4-bytes AS numbers, draft-ietf-idr-as4bytes-13 */ @@ -1349,16 +1349,16 @@ session_open(struct peer *p) nas = htonl(conf->as); errs += session_capa_add(opb, CAPA_AS4BYTE, sizeof(nas)); - errs += buf_add(opb, &nas, sizeof(nas)); + errs += ibuf_add(opb, &nas, sizeof(nas)); } - if (buf_size(opb)) - optparamlen = buf_size(opb) + sizeof(op_type) + + if (ibuf_size(opb)) + optparamlen = ibuf_size(opb) + sizeof(op_type) + sizeof(optparamlen); len = MSGSIZE_OPEN_MIN + optparamlen; if (errs || (buf = session_newmsg(OPEN, len)) == NULL) { - buf_free(opb); + ibuf_free(opb); bgp_fsm(p, EVNT_CON_FATAL); return; } @@ -1372,24 +1372,24 @@ session_open(struct peer *p) msg.bgpid = conf->bgpid; /* is already in network byte order */ msg.optparamlen = optparamlen; - errs += buf_add(buf->buf, &msg.version, sizeof(msg.version)); - errs += buf_add(buf->buf, &msg.myas, sizeof(msg.myas)); - errs += buf_add(buf->buf, &msg.holdtime, sizeof(msg.holdtime)); - errs += buf_add(buf->buf, &msg.bgpid, sizeof(msg.bgpid)); - errs += buf_add(buf->buf, &msg.optparamlen, sizeof(msg.optparamlen)); + errs += ibuf_add(buf->buf, &msg.version, sizeof(msg.version)); + errs += ibuf_add(buf->buf, &msg.myas, sizeof(msg.myas)); + errs += ibuf_add(buf->buf, &msg.holdtime, sizeof(msg.holdtime)); + errs += ibuf_add(buf->buf, &msg.bgpid, sizeof(msg.bgpid)); + errs += ibuf_add(buf->buf, &msg.optparamlen, sizeof(msg.optparamlen)); if (optparamlen) { op_type = OPT_PARAM_CAPABILITIES; - optparamlen = buf_size(opb); - errs += buf_add(buf->buf, &op_type, sizeof(op_type)); - errs += buf_add(buf->buf, &optparamlen, sizeof(optparamlen)); - errs += buf_add(buf->buf, opb->buf, buf_size(opb)); + optparamlen = ibuf_size(opb); + errs += ibuf_add(buf->buf, &op_type, sizeof(op_type)); + errs += ibuf_add(buf->buf, &optparamlen, sizeof(optparamlen)); + errs += ibuf_add(buf->buf, opb->buf, ibuf_size(opb)); } - buf_free(opb); + ibuf_free(opb); if (errs > 0) { - buf_free(buf->buf); + ibuf_free(buf->buf); free(buf); bgp_fsm(p, EVNT_CON_FATAL); return; @@ -1437,8 +1437,8 @@ session_update(u_int32_t peerid, void *data, size_t datalen) return; } - if (buf_add(buf->buf, data, datalen)) { - buf_free(buf->buf); + if (ibuf_add(buf->buf, data, datalen)) { + ibuf_free(buf->buf); free(buf); bgp_fsm(p, EVNT_CON_FATAL); return; @@ -1469,14 +1469,14 @@ session_notification(struct peer *p, u_int8_t errcode, u_int8_t subcode, return; } - errs += buf_add(buf->buf, &errcode, sizeof(errcode)); - errs += buf_add(buf->buf, &subcode, sizeof(subcode)); + errs += ibuf_add(buf->buf, &errcode, sizeof(errcode)); + errs += ibuf_add(buf->buf, &subcode, sizeof(subcode)); if (datalen > 0) - errs += buf_add(buf->buf, data, datalen); + errs += ibuf_add(buf->buf, data, datalen); if (errs > 0) { - buf_free(buf->buf); + ibuf_free(buf->buf); free(buf); bgp_fsm(p, EVNT_CON_FATAL); return; @@ -1525,12 +1525,12 @@ session_rrefresh(struct peer *p, u_int8_t aid) } afi = htons(afi); - errs += buf_add(buf->buf, &afi, sizeof(afi)); - errs += buf_add(buf->buf, &null8, sizeof(null8)); - errs += buf_add(buf->buf, &safi, sizeof(safi)); + errs += ibuf_add(buf->buf, &afi, sizeof(afi)); + errs += ibuf_add(buf->buf, &null8, sizeof(null8)); + errs += ibuf_add(buf->buf, &safi, sizeof(safi)); if (errs > 0) { - buf_free(buf->buf); + ibuf_free(buf->buf); free(buf); bgp_fsm(p, EVNT_CON_FATAL); return; diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h index 9484cf68cd9..d2ebb003c8f 100644 --- a/usr.sbin/bgpd/session.h +++ b/usr.sbin/bgpd/session.h @@ -1,4 +1,4 @@ -/* $OpenBSD: session.h,v 1.106 2010/05/17 15:49:29 claudio Exp $ */ +/* $OpenBSD: session.h,v 1.107 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -109,7 +109,7 @@ enum capa_codes { }; struct bgp_msg { - struct buf *buf; + struct ibuf *buf; enum msg_type type; u_int16_t len; }; @@ -202,7 +202,7 @@ struct peer { struct sockaddr_storage sa_remote; struct peer_timer_head timers; struct msgbuf wbuf; - struct buf_read *rbuf; + struct ibuf_read *rbuf; struct peer *next; int fd; int lasterr; diff --git a/usr.sbin/dvmrpd/ask_nbrs2.c b/usr.sbin/dvmrpd/ask_nbrs2.c index 2080a0a253b..378ae6f5265 100644 --- a/usr.sbin/dvmrpd/ask_nbrs2.c +++ b/usr.sbin/dvmrpd/ask_nbrs2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ask_nbrs2.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */ +/* $OpenBSD: ask_nbrs2.c,v 1.2 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2006 Esben Norby <norby@openbsd.org> @@ -37,7 +37,7 @@ int send_ask_nbrs2(struct iface *iface, struct in_addr addr, void *data, int len) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; struct dvmrp_hdr *dvmrp_hdr; int ret = 0; @@ -47,7 +47,7 @@ send_ask_nbrs2(struct iface *iface, struct in_addr addr, void *data, int len) if (iface->passive) return (0); - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("send_ask_nbrs2"); /* DVMRP header */ @@ -59,15 +59,15 @@ send_ask_nbrs2(struct iface *iface, struct in_addr addr, void *data, int len) dst.sin_addr.s_addr = addr.s_addr; /* update chksum */ - dvmrp_hdr = buf_seek(buf, 0, sizeof(dvmrp_hdr)); + dvmrp_hdr = ibuf_seek(buf, 0, sizeof(dvmrp_hdr)); dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos); ret = send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_ask_nbrs2"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/dvmrpd/buffer.c b/usr.sbin/dvmrpd/buffer.c index adba24d73d2..c4e5f208ce5 100644 --- a/usr.sbin/dvmrpd/buffer.c +++ b/usr.sbin/dvmrpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.5 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.6 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/dvmrpd/dvmrpe.c b/usr.sbin/dvmrpd/dvmrpe.c index 24aaabaa235..f8217e46e35 100644 --- a/usr.sbin/dvmrpd/dvmrpe.c +++ b/usr.sbin/dvmrpd/dvmrpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dvmrpe.c,v 1.8 2009/09/22 16:38:31 michele Exp $ */ +/* $OpenBSD: dvmrpe.c,v 1.9 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -169,7 +169,7 @@ dvmrpe(struct dvmrpd_conf *xconf, int pipe_parent2dvmrpe[2], TAILQ_INIT(&ctl_conns); control_listen(); - if ((pkt_ptr = calloc(1, READ_BUF_SIZE)) == NULL) + if ((pkt_ptr = calloc(1, IBUF_READ_SIZE)) == NULL) fatal("dvmrpe"); /* start interfaces */ diff --git a/usr.sbin/dvmrpd/dvmrpe.h b/usr.sbin/dvmrpd/dvmrpe.h index d5e95d283ca..7b771522906 100644 --- a/usr.sbin/dvmrpd/dvmrpe.h +++ b/usr.sbin/dvmrpd/dvmrpe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dvmrpe.h,v 1.3 2009/03/14 15:32:55 michele Exp $ */ +/* $OpenBSD: dvmrpe.h,v 1.4 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org> @@ -183,7 +183,7 @@ const char *nbr_action_name(int); struct ctl_nbr *nbr_to_ctl(struct nbr *); /* packet.c */ -int gen_dvmrp_hdr(struct buf *, struct iface *, u_int8_t); +int gen_dvmrp_hdr(struct ibuf *, struct iface *, u_int8_t); int send_packet(struct iface *, void *, size_t, struct sockaddr_in *); void recv_packet(int, short, void *); diff --git a/usr.sbin/dvmrpd/graft.c b/usr.sbin/dvmrpd/graft.c index 1931de3e3dc..7b2eab92c19 100644 --- a/usr.sbin/dvmrpd/graft.c +++ b/usr.sbin/dvmrpd/graft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: graft.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */ +/* $OpenBSD: graft.c,v 1.2 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org> @@ -37,7 +37,7 @@ int send_graft(struct iface *iface, struct in_addr addr, void *data, int len) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; struct dvmrp_hdr *dvmrp_hdr; int ret = 0; @@ -47,7 +47,7 @@ send_graft(struct iface *iface, struct in_addr addr, void *data, int len) if (iface->passive) return (0); - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("send_graft"); /* DVMRP header */ @@ -59,15 +59,15 @@ send_graft(struct iface *iface, struct in_addr addr, void *data, int len) dst.sin_addr.s_addr = addr.s_addr; /* update chksum */ - dvmrp_hdr = buf_seek(buf, 0, sizeof(dvmrp_hdr)); + dvmrp_hdr = ibuf_seek(buf, 0, sizeof(dvmrp_hdr)); dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos); ret = send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_graft"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/dvmrpd/graft_ack.c b/usr.sbin/dvmrpd/graft_ack.c index 682293273da..70154b80cca 100644 --- a/usr.sbin/dvmrpd/graft_ack.c +++ b/usr.sbin/dvmrpd/graft_ack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: graft_ack.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */ +/* $OpenBSD: graft_ack.c,v 1.2 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2006 Esben Norby <norby@openbsd.org> @@ -37,7 +37,7 @@ int send_graft_ack(struct iface *iface, struct in_addr addr, void *data, int len) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; struct dvmrp_hdr *dvmrp_hdr; int ret = 0; @@ -47,7 +47,7 @@ send_graft_ack(struct iface *iface, struct in_addr addr, void *data, int len) if (iface->passive) return (0); - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("send_graft_ack"); /* DVMRP header */ @@ -59,15 +59,15 @@ send_graft_ack(struct iface *iface, struct in_addr addr, void *data, int len) dst.sin_addr.s_addr = addr.s_addr; /* update chksum */ - dvmrp_hdr = buf_seek(buf, 0, sizeof(dvmrp_hdr)); + dvmrp_hdr = ibuf_seek(buf, 0, sizeof(dvmrp_hdr)); dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos); ret = send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_graft_ack"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/dvmrpd/igmp.c b/usr.sbin/dvmrpd/igmp.c index da0f3e3d0b7..b9594ee8400 100644 --- a/usr.sbin/dvmrpd/igmp.c +++ b/usr.sbin/dvmrpd/igmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: igmp.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */ +/* $OpenBSD: igmp.c,v 1.2 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org> @@ -40,7 +40,7 @@ send_igmp_query(struct iface *iface, struct group *group) { struct igmp_hdr igmp_hdr; struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; int ret = 0; log_debug("send_igmp_query: interface %s", iface->name); @@ -48,7 +48,7 @@ send_igmp_query(struct iface *iface, struct group *group) if (iface->passive) return (0); - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("send_igmp_query"); /* IGMP header */ @@ -77,7 +77,7 @@ send_igmp_query(struct iface *iface, struct group *group) /* update chksum */ igmp_hdr.chksum = in_cksum(&igmp_hdr, sizeof(igmp_hdr)); - buf_add(buf, &igmp_hdr, sizeof(igmp_hdr)); + ibuf_add(buf, &igmp_hdr, sizeof(igmp_hdr)); /* set destination address */ dst.sin_family = AF_INET; @@ -85,7 +85,7 @@ send_igmp_query(struct iface *iface, struct group *group) inet_aton(AllSystems, &dst.sin_addr); ret = send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); } diff --git a/usr.sbin/dvmrpd/imsg.c b/usr.sbin/dvmrpd/imsg.c index 53ca8b4385a..5e5f97c40cb 100644 --- a/usr.sbin/dvmrpd/imsg.c +++ b/usr.sbin/dvmrpd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.9 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.10 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/dvmrpd/imsg.h b/usr.sbin/dvmrpd/imsg.h index 9fd3f2f4964..43564710bb2 100644 --- a/usr.sbin/dvmrpd/imsg.h +++ b/usr.sbin/dvmrpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.5 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.6 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/dvmrpd/kmroute.c b/usr.sbin/dvmrpd/kmroute.c index 911319bc995..891f630e27a 100644 --- a/usr.sbin/dvmrpd/kmroute.c +++ b/usr.sbin/dvmrpd/kmroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kmroute.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */ +/* $OpenBSD: kmroute.c,v 1.2 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org> @@ -57,7 +57,7 @@ kmr_init(int fd) mrt_add_vif(conf->mroute_socket, iface); } - if ((mroute_ptr = calloc(1, READ_BUF_SIZE)) == NULL) + if ((mroute_ptr = calloc(1, IBUF_READ_SIZE)) == NULL) fatal("kmr_init"); return (0); @@ -94,7 +94,7 @@ kmr_recv_msg(int fd, short event, void *bula) /* setup buffer */ buf = mroute_ptr; - if ((r = recvfrom(fd, buf, READ_BUF_SIZE, 0, NULL, NULL)) == -1) { + if ((r = recvfrom(fd, buf, IBUF_READ_SIZE, 0, NULL, NULL)) == -1) { if (errno != EAGAIN && errno != EINTR) log_debug("kmr_recv_msg: error receiving packet"); return; diff --git a/usr.sbin/dvmrpd/nbrs2.c b/usr.sbin/dvmrpd/nbrs2.c index 1ea88464dc6..62ed768d7f2 100644 --- a/usr.sbin/dvmrpd/nbrs2.c +++ b/usr.sbin/dvmrpd/nbrs2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nbrs2.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */ +/* $OpenBSD: nbrs2.c,v 1.2 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2006 Esben Norby <norby@openbsd.org> @@ -37,7 +37,7 @@ int send_nbrs2(struct iface *iface, struct in_addr addr, void *data, int len) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; struct dvmrp_hdr *dvmrp_hdr; int ret = 0; @@ -47,7 +47,7 @@ send_nbrs2(struct iface *iface, struct in_addr addr, void *data, int len) if (iface->passive) return (0); - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("send_nbrs2"); /* DVMRP header */ @@ -59,15 +59,15 @@ send_nbrs2(struct iface *iface, struct in_addr addr, void *data, int len) dst.sin_addr.s_addr = addr.s_addr; /* update chksum */ - dvmrp_hdr = buf_seek(buf, 0, sizeof(dvmrp_hdr)); + dvmrp_hdr = ibuf_seek(buf, 0, sizeof(dvmrp_hdr)); dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos); ret = send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_nbrs2"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/dvmrpd/packet.c b/usr.sbin/dvmrpd/packet.c index f81a1614308..022c18f1e02 100644 --- a/usr.sbin/dvmrpd/packet.c +++ b/usr.sbin/dvmrpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */ +/* $OpenBSD: packet.c,v 1.2 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org> @@ -45,7 +45,7 @@ struct iface *find_iface(struct dvmrpd_conf *, struct in_addr); extern struct dvmrpd_conf *deconf; int -gen_dvmrp_hdr(struct buf *buf, struct iface *iface, u_int8_t code) +gen_dvmrp_hdr(struct ibuf *buf, struct iface *iface, u_int8_t code) { struct dvmrp_hdr dvmrp_hdr; @@ -57,7 +57,7 @@ gen_dvmrp_hdr(struct buf *buf, struct iface *iface, u_int8_t code) dvmrp_hdr.minor_version = DVMRP_MINOR_VERSION; dvmrp_hdr.major_version = DVMRP_MAJOR_VERSION; - return (buf_add(buf, &dvmrp_hdr, sizeof(dvmrp_hdr))); + return (ibuf_add(buf, &dvmrp_hdr, sizeof(dvmrp_hdr))); } /* send and receive packets */ @@ -108,7 +108,7 @@ recv_packet(int fd, short event, void *bula) /* setup buffer */ buf = pkt_ptr; - if ((r = recvfrom(fd, buf, READ_BUF_SIZE, 0, NULL, NULL)) == -1) { + if ((r = recvfrom(fd, buf, IBUF_READ_SIZE, 0, NULL, NULL)) == -1) { if (errno != EAGAIN && errno != EINTR) log_debug("recv_packet: error receiving packet"); return; diff --git a/usr.sbin/dvmrpd/probe.c b/usr.sbin/dvmrpd/probe.c index 93e3dccb607..17347df9532 100644 --- a/usr.sbin/dvmrpd/probe.c +++ b/usr.sbin/dvmrpd/probe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: probe.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */ +/* $OpenBSD: probe.c,v 1.2 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org> @@ -39,7 +39,7 @@ int send_probe(struct iface *iface) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; struct dvmrp_hdr *dvmrp_hdr; struct nbr *nbr; int ret = 0; @@ -47,7 +47,7 @@ send_probe(struct iface *iface) if (iface->passive) return (0); - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("send_probe"); /* DVMRP header */ @@ -55,12 +55,12 @@ send_probe(struct iface *iface) goto fail; /* generation ID */ - buf_add(buf, &iface->gen_id, sizeof(iface->gen_id)); + ibuf_add(buf, &iface->gen_id, sizeof(iface->gen_id)); /* generate neighbor list */ LIST_FOREACH(nbr, &iface->nbr_list, entry) { if (nbr->state > NBR_STA_DOWN) - buf_add(buf, &nbr->id, sizeof(nbr->id)); + ibuf_add(buf, &nbr->id, sizeof(nbr->id)); } /* set destination address */ @@ -69,15 +69,15 @@ send_probe(struct iface *iface) inet_aton(AllDVMRPRouters, &dst.sin_addr); /* update chksum */ - dvmrp_hdr = buf_seek(buf, 0, sizeof(dvmrp_hdr)); + dvmrp_hdr = ibuf_seek(buf, 0, sizeof(dvmrp_hdr)); dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos); ret = send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_probe"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/dvmrpd/prune.c b/usr.sbin/dvmrpd/prune.c index 58cf4ac3d1f..0296e113d6f 100644 --- a/usr.sbin/dvmrpd/prune.c +++ b/usr.sbin/dvmrpd/prune.c @@ -1,4 +1,4 @@ -/* $OpenBSD: prune.c,v 1.2 2009/03/14 15:32:55 michele Exp $ */ +/* $OpenBSD: prune.c,v 1.3 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org> @@ -37,7 +37,7 @@ int send_prune(struct nbr *nbr, struct prune *p) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; struct dvmrp_hdr *dvmrp_hdr; struct prune_hdr prune; int ret = 0; @@ -54,7 +54,7 @@ send_prune(struct nbr *nbr, struct prune *p) dst.sin_len = sizeof(struct sockaddr_in); dst.sin_addr = nbr->addr; - if ((buf = buf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) fatal("send_prune"); /* DVMRP header */ @@ -68,19 +68,19 @@ send_prune(struct nbr *nbr, struct prune *p) prune.lifetime = htonl(MAX_PRUNE_LIFETIME); prune.src_netmask = p->netmask.s_addr; - buf_add(buf, &prune, sizeof(prune)); + ibuf_add(buf, &prune, sizeof(prune)); /* update chksum */ - dvmrp_hdr = buf_seek(buf, 0, sizeof(dvmrp_hdr)); + dvmrp_hdr = ibuf_seek(buf, 0, sizeof(dvmrp_hdr)); dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos); ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_prune"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/dvmrpd/report.c b/usr.sbin/dvmrpd/report.c index 140dc3f572f..55137ad3119 100644 --- a/usr.sbin/dvmrpd/report.c +++ b/usr.sbin/dvmrpd/report.c @@ -1,4 +1,4 @@ -/* $OpenBSD: report.c,v 1.7 2007/04/10 09:37:25 michele Exp $ */ +/* $OpenBSD: report.c,v 1.8 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org> @@ -41,7 +41,7 @@ int send_report(struct iface *iface, struct in_addr addr, void *data, int len) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; struct dvmrp_hdr *dvmrp_hdr; int ret = 0; @@ -51,29 +51,29 @@ send_report(struct iface *iface, struct in_addr addr, void *data, int len) if (iface->passive) return (0); - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("send_report"); /* DVMRP header */ if (gen_dvmrp_hdr(buf, iface, DVMRP_CODE_REPORT)) goto fail; - buf_add(buf, data, len); + ibuf_add(buf, data, len); dst.sin_family = AF_INET; dst.sin_len = sizeof(struct sockaddr_in); dst.sin_addr.s_addr = addr.s_addr; /* update chksum */ - dvmrp_hdr = buf_seek(buf, 0, sizeof(dvmrp_hdr)); + dvmrp_hdr = ibuf_seek(buf, 0, sizeof(dvmrp_hdr)); dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos); ret = send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_report"); - buf_free(buf); + ibuf_free(buf); return (-1); } @@ -225,7 +225,7 @@ void rr_list_send(struct rr_head *rr_list, struct iface *xiface, struct nbr *nbr) { struct rr_entry *le, *le2; - struct buf *buf; + struct ibuf *buf; struct iface *iface; struct in_addr addr; u_int32_t netid, netmask; @@ -243,7 +243,7 @@ rr_list_send(struct rr_head *rr_list, struct iface *xiface, struct nbr *nbr) } while (!TAILQ_EMPTY(rr_list)) { - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("rr_list_send"); prefixlen = 0; @@ -255,13 +255,13 @@ rr_list_send(struct rr_head *rr_list, struct iface *xiface, struct nbr *nbr) prefixlen = mask2prefixlen(netmask); netmask = ntohl(netmask) << 8; netmask = htonl(netmask); - buf_add(buf, &netmask, 3); + ibuf_add(buf, &netmask, 3); } netid_len = PREFIX_SIZE(prefixlen); /* netid */ netid = le->re->net.s_addr; - buf_add(buf, &netid, netid_len); + ibuf_add(buf, &netid, netid_len); /* metric */ if (iface->ifindex == le->re->ifindex) @@ -283,13 +283,13 @@ rr_list_send(struct rr_head *rr_list, struct iface *xiface, struct nbr *nbr) metric = metric | LAST_MASK; } - buf_add(buf, &metric, sizeof(metric)); + ibuf_add(buf, &metric, sizeof(metric)); TAILQ_REMOVE(rr_list, le, entry); rr_list_remove(le->re); free(le); } send_report(iface, addr, buf->buf, buf->wpos); - buf_free(buf); + ibuf_free(buf); } } diff --git a/usr.sbin/ldpd/address.c b/usr.sbin/ldpd/address.c index 54d60c0f0d0..e0bf23d0e11 100644 --- a/usr.sbin/ldpd/address.c +++ b/usr.sbin/ldpd/address.c @@ -1,4 +1,4 @@ -/* $OpenBSD: address.c,v 1.4 2010/02/25 17:40:46 claudio Exp $ */ +/* $OpenBSD: address.c,v 1.5 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -39,12 +39,12 @@ extern struct ldpd_conf *leconf; -void gen_address_list_tlv(struct buf *, struct iface *, u_int16_t); +void gen_address_list_tlv(struct ibuf *, struct iface *, u_int16_t); void send_address(struct nbr *nbr, struct iface *iface) { - struct buf *buf; + struct ibuf *buf; struct iface *niface; u_int16_t size, iface_count = 0; @@ -53,7 +53,7 @@ send_address(struct nbr *nbr, struct iface *iface) log_debug("send_address: neighbor ID %s", inet_ntoa(nbr->id)); - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_address"); /* XXX: multiple address on the same iface? */ @@ -141,7 +141,7 @@ recv_address(struct nbr *nbr, char *buf, u_int16_t len) } void -gen_address_list_tlv(struct buf *buf, struct iface *iface, u_int16_t size) +gen_address_list_tlv(struct ibuf *buf, struct iface *iface, u_int16_t size) { struct address_list_tlv alt; struct iface *niface; @@ -155,19 +155,19 @@ gen_address_list_tlv(struct buf *buf, struct iface *iface, u_int16_t size) /* XXX: just ipv4 for now */ alt.family = htons(ADDR_IPV4); - buf_add(buf, &alt, sizeof(alt)); + ibuf_add(buf, &alt, sizeof(alt)); if (iface == NULL) LIST_FOREACH(niface, &leconf->iface_list, entry) - buf_add(buf, &niface->addr, sizeof(niface->addr)); + ibuf_add(buf, &niface->addr, sizeof(niface->addr)); else - buf_add(buf, &iface->addr, sizeof(iface->addr)); + ibuf_add(buf, &iface->addr, sizeof(iface->addr)); } void send_address_withdraw(struct nbr *nbr, struct iface *iface) { - struct buf *buf; + struct ibuf *buf; u_int16_t size; if (nbr->iface->passive) @@ -175,7 +175,7 @@ send_address_withdraw(struct nbr *nbr, struct iface *iface) log_debug("send_address_withdraw: neighbor ID %s", inet_ntoa(nbr->id)); - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_address_withdraw"); /* XXX: multiple address on the same iface? */ diff --git a/usr.sbin/ldpd/buffer.c b/usr.sbin/ldpd/buffer.c index 603a53d60ff..256f37758cc 100644 --- a/usr.sbin/ldpd/buffer.c +++ b/usr.sbin/ldpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.5 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/ldpd/hello.c b/usr.sbin/ldpd/hello.c index 4712a9e782f..d6cb184727e 100644 --- a/usr.sbin/ldpd/hello.c +++ b/usr.sbin/ldpd/hello.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hello.c,v 1.5 2010/05/19 15:28:51 claudio Exp $ */ +/* $OpenBSD: hello.c,v 1.6 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -39,14 +39,14 @@ struct hello_prms_tlv *tlv_decode_hello_prms(char *, u_int16_t); int tlv_decode_opt_hello_prms(char *, u_int16_t, struct in_addr *, u_int32_t *); -int gen_hello_prms_tlv(struct iface *, struct buf *, +int gen_hello_prms_tlv(struct iface *, struct ibuf *, u_int16_t); int send_hello(struct iface *iface) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; u_int16_t size; dst.sin_port = htons(LDP_PORT); @@ -57,7 +57,7 @@ send_hello(struct iface *iface) if (iface->passive) return (0); - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_hello"); size = LDP_HDR_SIZE + sizeof(struct ldp_msg) + @@ -74,7 +74,7 @@ send_hello(struct iface *iface) gen_hello_prms_tlv(iface, buf, size); send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (0); } @@ -151,7 +151,7 @@ recv_hello(struct iface *iface, struct in_addr src, char *buf, u_int16_t len) } int -gen_hello_prms_tlv(struct iface *iface, struct buf *buf, u_int16_t size) +gen_hello_prms_tlv(struct iface *iface, struct ibuf *buf, u_int16_t size) { struct hello_prms_tlv parms; @@ -165,7 +165,7 @@ gen_hello_prms_tlv(struct iface *iface, struct buf *buf, u_int16_t size) parms.holdtime = htons(iface->holdtime); parms.reserved = 0; - return (buf_add(buf, &parms, sizeof(parms))); + return (ibuf_add(buf, &parms, sizeof(parms))); } struct hello_prms_tlv * diff --git a/usr.sbin/ldpd/imsg.c b/usr.sbin/ldpd/imsg.c index c87867354b9..798511b290a 100644 --- a/usr.sbin/ldpd/imsg.c +++ b/usr.sbin/ldpd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.8 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.9 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/ldpd/imsg.h b/usr.sbin/ldpd/imsg.h index 9fd3f2f4964..43564710bb2 100644 --- a/usr.sbin/ldpd/imsg.h +++ b/usr.sbin/ldpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.5 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.6 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/ldpd/init.c b/usr.sbin/ldpd/init.c index b8f1601d9a1..31556a670e2 100644 --- a/usr.sbin/ldpd/init.c +++ b/usr.sbin/ldpd/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.4 2010/02/25 17:40:46 claudio Exp $ */ +/* $OpenBSD: init.c,v 1.5 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -37,12 +37,12 @@ #include "log.h" #include "ldpe.h" -int gen_init_prms_tlv(struct buf *, struct nbr *, u_int16_t); +int gen_init_prms_tlv(struct ibuf *, struct nbr *, u_int16_t); void send_init(struct nbr *nbr) { - struct buf *buf; + struct ibuf *buf; u_int16_t size; if (nbr->iface->passive) @@ -50,7 +50,7 @@ send_init(struct nbr *nbr) log_debug("send_init: neighbor ID %s", inet_ntoa(nbr->id)); - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_init"); size = LDP_HDR_SIZE + sizeof(struct ldp_msg) + SESS_PRMS_SIZE; @@ -105,7 +105,7 @@ recv_init(struct nbr *nbr, char *buf, u_int16_t len) } int -gen_init_prms_tlv(struct buf *buf, struct nbr *nbr, u_int16_t size) +gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr, u_int16_t size) { struct sess_prms_tlv parms; @@ -124,5 +124,5 @@ gen_init_prms_tlv(struct buf *buf, struct nbr *nbr, u_int16_t size) /* XXX: nbr lspace */ parms.lspace_id = 0; - return (buf_add(buf, &parms, SESS_PRMS_SIZE)); + return (ibuf_add(buf, &parms, SESS_PRMS_SIZE)); } diff --git a/usr.sbin/ldpd/keepalive.c b/usr.sbin/ldpd/keepalive.c index ccf3d997668..2e9152a1b4e 100644 --- a/usr.sbin/ldpd/keepalive.c +++ b/usr.sbin/ldpd/keepalive.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keepalive.c,v 1.5 2010/02/25 17:40:46 claudio Exp $ */ +/* $OpenBSD: keepalive.c,v 1.6 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -40,13 +40,13 @@ void send_keepalive(struct nbr *nbr) { - struct buf *buf; + struct ibuf *buf; u_int16_t size; if (nbr->iface->passive) return; - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_keepalive"); size = LDP_HDR_SIZE + sizeof(struct ldp_msg); diff --git a/usr.sbin/ldpd/labelmapping.c b/usr.sbin/ldpd/labelmapping.c index 966fec475dd..21f99f0a06d 100644 --- a/usr.sbin/ldpd/labelmapping.c +++ b/usr.sbin/ldpd/labelmapping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: labelmapping.c,v 1.10 2010/05/25 09:40:10 claudio Exp $ */ +/* $OpenBSD: labelmapping.c,v 1.11 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -37,8 +37,8 @@ #include "log.h" #include "ldpe.h" -void gen_fec_tlv(struct buf *, u_int32_t, u_int8_t); -void gen_label_tlv(struct buf *, u_int32_t); +void gen_fec_tlv(struct ibuf *, u_int32_t, u_int8_t); +void gen_label_tlv(struct ibuf *, u_int32_t); u_int32_t tlv_decode_label(struct label_tlv *); int tlv_decode_fec_elm(char *, u_int16_t, u_int8_t *, u_int32_t *, @@ -48,7 +48,7 @@ int tlv_decode_fec_elm(char *, u_int16_t, u_int8_t *, u_int32_t *, void send_labelmapping(struct nbr *nbr) { - struct buf *buf; + struct ibuf *buf; struct mapping_entry *me; struct ldp_hdr *ldp_hdr; u_int16_t tlv_size, size; @@ -58,7 +58,7 @@ send_labelmapping(struct nbr *nbr) log_debug("send_labelmapping: neighbor ID %s", inet_ntoa(nbr->id)); - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_labelmapping"); /* real size will be set up later */ @@ -78,7 +78,7 @@ send_labelmapping(struct nbr *nbr) /* XXX: should we remove them first? */ nbr_mapping_list_clr(nbr, &nbr->mapping_list); - ldp_hdr = buf_seek(buf, 0, sizeof(struct ldp_hdr)); + ldp_hdr = ibuf_seek(buf, 0, sizeof(struct ldp_hdr)); ldp_hdr->length = htons(size); evbuf_enqueue(&nbr->wbuf, buf); @@ -161,7 +161,7 @@ recv_labelmapping(struct nbr *nbr, char *buf, u_int16_t len) void send_labelrequest(struct nbr *nbr) { - struct buf *buf; + struct ibuf *buf; struct mapping_entry *me; struct ldp_hdr *ldp_hdr; u_int16_t tlv_size, size; @@ -171,7 +171,7 @@ send_labelrequest(struct nbr *nbr) log_debug("send_labelrequest: neighbor ID %s", inet_ntoa(nbr->id)); - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_labelrequest"); /* real size will be set up later */ @@ -190,7 +190,7 @@ send_labelrequest(struct nbr *nbr) /* XXX: should we remove them first? */ nbr_mapping_list_clr(nbr, &nbr->request_list); - ldp_hdr = buf_seek(buf, 0, sizeof(struct ldp_hdr)); + ldp_hdr = ibuf_seek(buf, 0, sizeof(struct ldp_hdr)); ldp_hdr->length = htons(size); evbuf_enqueue(&nbr->wbuf, buf); @@ -260,7 +260,7 @@ recv_labelrequest(struct nbr *nbr, char *buf, u_int16_t len) void send_labelwithdraw(struct nbr *nbr) { - struct buf *buf; + struct ibuf *buf; struct mapping_entry *me; struct ldp_hdr *ldp_hdr; u_int16_t tlv_size, size; @@ -270,7 +270,7 @@ send_labelwithdraw(struct nbr *nbr) log_debug("send_labelwithdraw: neighbor ID %s", inet_ntoa(nbr->id)); - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_labelwithdraw"); /* real size will be set up later */ @@ -297,7 +297,7 @@ send_labelwithdraw(struct nbr *nbr) /* XXX: should we remove them first? */ nbr_mapping_list_clr(nbr, &nbr->withdraw_list); - ldp_hdr = buf_seek(buf, 0, sizeof(struct ldp_hdr)); + ldp_hdr = ibuf_seek(buf, 0, sizeof(struct ldp_hdr)); ldp_hdr->length = htons(size); evbuf_enqueue(&nbr->wbuf, buf); @@ -391,7 +391,7 @@ recv_labelwithdraw(struct nbr *nbr, char *buf, u_int16_t len) void send_labelrelease(struct nbr *nbr) { - struct buf *buf; + struct ibuf *buf; struct mapping_entry *me; struct ldp_hdr *ldp_hdr; u_int16_t tlv_size, size; @@ -401,7 +401,7 @@ send_labelrelease(struct nbr *nbr) log_debug("send_labelrelease: neighbor ID %s", inet_ntoa(nbr->id)); - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_labelrelease"); /* real size will be set up later */ @@ -428,7 +428,7 @@ send_labelrelease(struct nbr *nbr) /* XXX: should we remove them first? */ nbr_mapping_list_clr(nbr, &nbr->release_list); - ldp_hdr = buf_seek(buf, 0, sizeof(struct ldp_hdr)); + ldp_hdr = ibuf_seek(buf, 0, sizeof(struct ldp_hdr)); ldp_hdr->length = htons(size); evbuf_enqueue(&nbr->wbuf, buf); @@ -522,7 +522,7 @@ recv_labelrelease(struct nbr *nbr, char *buf, u_int16_t len) void send_labelabortreq(struct nbr *nbr) { - struct buf *buf; + struct ibuf *buf; u_int16_t size; if (nbr->iface->passive) @@ -530,7 +530,7 @@ send_labelabortreq(struct nbr *nbr) log_debug("send_labelabortreq: neighbor ID %s", inet_ntoa(nbr->id)); - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_labelabortreq"); size = LDP_HDR_SIZE + sizeof(struct ldp_msg); @@ -573,7 +573,7 @@ recv_labelabortreq(struct nbr *nbr, char *buf, u_int16_t len) /* Other TLV related functions */ void -gen_fec_tlv(struct buf *buf, u_int32_t prefix, u_int8_t prefixlen) +gen_fec_tlv(struct ibuf *buf, u_int32_t prefix, u_int8_t prefixlen) { struct fec_tlv ft; u_int8_t type; @@ -585,20 +585,20 @@ gen_fec_tlv(struct buf *buf, u_int32_t prefix, u_int8_t prefixlen) ft.length = htons(sizeof(type) + sizeof(family) + sizeof(prefixlen) + len); - buf_add(buf, &ft, sizeof(ft)); + ibuf_add(buf, &ft, sizeof(ft)); type = FEC_PREFIX; family = htons(FEC_IPV4); - buf_add(buf, &type, sizeof(type)); - buf_add(buf, &family, sizeof(family)); - buf_add(buf, &prefixlen, sizeof(prefixlen)); + ibuf_add(buf, &type, sizeof(type)); + ibuf_add(buf, &family, sizeof(family)); + ibuf_add(buf, &prefixlen, sizeof(prefixlen)); if (len) - buf_add(buf, &prefix, len); + ibuf_add(buf, &prefix, len); } void -gen_label_tlv(struct buf *buf, u_int32_t label) +gen_label_tlv(struct ibuf *buf, u_int32_t label) { struct label_tlv lt; @@ -606,7 +606,7 @@ gen_label_tlv(struct buf *buf, u_int32_t label) lt.length = htons(sizeof(label)); lt.label = htonl(label); - buf_add(buf, <, sizeof(lt)); + ibuf_add(buf, <, sizeof(lt)); } u_int32_t diff --git a/usr.sbin/ldpd/ldpd.c b/usr.sbin/ldpd/ldpd.c index 290822d8ea0..bca79578bb6 100644 --- a/usr.sbin/ldpd/ldpd.c +++ b/usr.sbin/ldpd/ldpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.c,v 1.7 2010/03/03 10:17:05 claudio Exp $ */ +/* $OpenBSD: ldpd.c,v 1.8 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -528,9 +528,9 @@ imsg_compose_event(struct imsgev *iev, u_int16_t type, } void -evbuf_enqueue(struct evbuf *eb, struct buf *buf) +evbuf_enqueue(struct evbuf *eb, struct ibuf *buf) { - buf_close(&eb->wbuf, buf); + ibuf_close(&eb->wbuf, buf); evbuf_event_add(eb); } diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h index 1947219051c..236065e1900 100644 --- a/usr.sbin/ldpd/ldpd.h +++ b/usr.sbin/ldpd/ldpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.h,v 1.20 2010/05/25 13:29:45 claudio Exp $ */ +/* $OpenBSD: ldpd.h,v 1.21 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -422,7 +422,7 @@ void merge_config(struct ldpd_conf *, struct ldpd_conf *); int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t, pid_t, int, void *, u_int16_t); void imsg_event_add(struct imsgev *); -void evbuf_enqueue(struct evbuf *, struct buf *); +void evbuf_enqueue(struct evbuf *, struct ibuf *); void evbuf_event_add(struct evbuf *); void evbuf_init(struct evbuf *, int, void (*)(int, short, void *), void *); void evbuf_clear(struct evbuf *); diff --git a/usr.sbin/ldpd/ldpe.c b/usr.sbin/ldpd/ldpe.c index 6b634834cfb..14a410f38c2 100644 --- a/usr.sbin/ldpd/ldpe.c +++ b/usr.sbin/ldpd/ldpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpe.c,v 1.9 2010/05/19 15:28:51 claudio Exp $ */ +/* $OpenBSD: ldpe.c,v 1.10 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -210,7 +210,7 @@ ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2], TAILQ_INIT(&ctl_conns); control_listen(); - if ((pkt_ptr = calloc(1, READ_BUF_SIZE)) == NULL) + if ((pkt_ptr = calloc(1, IBUF_READ_SIZE)) == NULL) fatal("ldpe"); /* start interfaces */ diff --git a/usr.sbin/ldpd/ldpe.h b/usr.sbin/ldpd/ldpe.h index 88bc5355383..f0fe3d05b3e 100644 --- a/usr.sbin/ldpd/ldpe.h +++ b/usr.sbin/ldpd/ldpe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpe.h,v 1.9 2010/05/19 15:28:51 claudio Exp $ */ +/* $OpenBSD: ldpe.h,v 1.10 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org> @@ -54,7 +54,7 @@ struct nbr { struct in_addr addr; struct in_addr id; - struct buf_read *rbuf; + struct ibuf_read *rbuf; struct iface *iface; time_t uptime; @@ -89,7 +89,7 @@ int recv_keepalive(struct nbr *, char *, u_int16_t); /* notification.c */ void send_notification_nbr(struct nbr *, u_int32_t, u_int32_t, u_int32_t); -struct buf *send_notification(u_int32_t, struct iface *, u_int32_t, +struct ibuf *send_notification(u_int32_t, struct iface *, u_int32_t, u_int32_t); int recv_notification(struct nbr *, char *, u_int16_t); @@ -189,8 +189,8 @@ void nbr_mapping_list_clr(struct nbr *, struct ctl_nbr *nbr_to_ctl(struct nbr *); /* packet.c */ -int gen_ldp_hdr(struct buf *, struct iface *, u_int16_t); -int gen_msg_tlv(struct buf *, u_int32_t, u_int16_t); +int gen_ldp_hdr(struct ibuf *, struct iface *, u_int16_t); +int gen_msg_tlv(struct ibuf *, u_int32_t, u_int16_t); int send_packet(struct iface *, void *, size_t, struct sockaddr_in *); void disc_recv_packet(int, short, void *); void session_accept(int, short, void *); diff --git a/usr.sbin/ldpd/neighbor.c b/usr.sbin/ldpd/neighbor.c index ad445344ac4..db1e1f9dc86 100644 --- a/usr.sbin/ldpd/neighbor.c +++ b/usr.sbin/ldpd/neighbor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: neighbor.c,v 1.14 2010/05/25 09:26:12 claudio Exp $ */ +/* $OpenBSD: neighbor.c,v 1.15 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -229,7 +229,7 @@ nbr_new(u_int32_t nbr_id, u_int16_t lspace, struct iface *iface) if ((nbr = calloc(1, sizeof(*nbr))) == NULL) fatal("nbr_new"); - if ((nbr->rbuf = calloc(1, sizeof(struct buf_read))) == NULL) + if ((nbr->rbuf = calloc(1, sizeof(struct ibuf_read))) == NULL) fatal("nbr_new"); nbr->state = NBR_STA_DOWN; diff --git a/usr.sbin/ldpd/notification.c b/usr.sbin/ldpd/notification.c index 0708a6027a1..52650908a09 100644 --- a/usr.sbin/ldpd/notification.c +++ b/usr.sbin/ldpd/notification.c @@ -1,4 +1,4 @@ -/* $OpenBSD: notification.c,v 1.6 2010/05/14 13:49:09 claudio Exp $ */ +/* $OpenBSD: notification.c,v 1.7 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -37,13 +37,13 @@ #include "log.h" #include "ldpe.h" -int gen_status_tlv(struct buf *, u_int32_t, u_int32_t, u_int32_t); +int gen_status_tlv(struct ibuf *, u_int32_t, u_int32_t, u_int32_t); void send_notification_nbr(struct nbr *nbr, u_int32_t status, u_int32_t msgid, u_int32_t type) { - struct buf *buf; + struct ibuf *buf; if (nbr->iface->passive) return; @@ -52,14 +52,14 @@ send_notification_nbr(struct nbr *nbr, u_int32_t status, u_int32_t msgid, evbuf_enqueue(&nbr->wbuf, buf); } -struct buf * +struct ibuf * send_notification(u_int32_t status, struct iface *iface, u_int32_t msgid, u_int32_t type) { - struct buf *buf; + struct ibuf *buf; u_int16_t size; - if ((buf = buf_open(LDP_MAX_LEN)) == NULL) + if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL) fatal("send_notification"); size = LDP_HDR_SIZE + sizeof(struct ldp_msg) + STATUS_SIZE; @@ -121,7 +121,7 @@ recv_notification(struct nbr *nbr, char *buf, u_int16_t len) } int -gen_status_tlv(struct buf *buf, u_int32_t status, u_int32_t msgid, +gen_status_tlv(struct ibuf *buf, u_int32_t status, u_int32_t msgid, u_int32_t type) { struct status_tlv st; @@ -135,5 +135,5 @@ gen_status_tlv(struct buf *buf, u_int32_t status, u_int32_t msgid, st.msg_id = msgid; st.msg_type = type; - return (buf_add(buf, &st, STATUS_SIZE)); + return (ibuf_add(buf, &st, STATUS_SIZE)); } diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c index df224545a4d..12613b7c454 100644 --- a/usr.sbin/ldpd/packet.c +++ b/usr.sbin/ldpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.11 2010/05/14 13:49:09 claudio Exp $ */ +/* $OpenBSD: packet.c,v 1.12 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -43,12 +43,12 @@ int ldp_hdr_sanity_check(struct ldp_hdr *, u_int16_t, const struct iface *); struct iface *find_iface(struct ldpd_conf *, unsigned int, struct in_addr); struct iface *session_find_iface(struct ldpd_conf *, struct in_addr); -ssize_t session_get_pdu(struct buf_read *, char **); +ssize_t session_get_pdu(struct ibuf_read *, char **); static int msgcnt = 0; int -gen_ldp_hdr(struct buf *buf, struct iface *iface, u_int16_t size) +gen_ldp_hdr(struct ibuf *buf, struct iface *iface, u_int16_t size) { struct ldp_hdr ldp_hdr; @@ -62,11 +62,11 @@ gen_ldp_hdr(struct buf *buf, struct iface *iface, u_int16_t size) ldp_hdr.lsr_id = ldpe_router_id(); ldp_hdr.lspace_id = iface->lspace_id; - return (buf_add(buf, &ldp_hdr, LDP_HDR_SIZE)); + return (ibuf_add(buf, &ldp_hdr, LDP_HDR_SIZE)); } int -gen_msg_tlv(struct buf *buf, u_int32_t type, u_int16_t size) +gen_msg_tlv(struct ibuf *buf, u_int32_t type, u_int16_t size) { struct ldp_msg msg; @@ -78,7 +78,7 @@ gen_msg_tlv(struct buf *buf, u_int32_t type, u_int16_t size) msg.length = htons(size); msg.msgid = htonl(++msgcnt); - return (buf_add(buf, &msg, sizeof(msg))); + return (ibuf_add(buf, &msg, sizeof(msg))); } /* send and receive packets */ @@ -131,7 +131,7 @@ disc_recv_packet(int fd, short event, void *bula) /* setup buffer */ bzero(&msg, sizeof(msg)); iov.iov_base = buf = pkt_ptr; - iov.iov_len = READ_BUF_SIZE; + iov.iov_len = IBUF_READ_SIZE; msg.msg_name = &src; msg.msg_namelen = sizeof(src); msg.msg_iov = &iov; @@ -278,12 +278,12 @@ session_accept(int fd, short event, void *bula) nbr = nbr_find_ip(iface, src.sin_addr.s_addr); if (nbr == NULL) { - struct buf *buf; + struct ibuf *buf; /* If there is no neighbor matching there is no Hello adjacency: try to send notification */ buf = send_notification(S_NO_HELLO, iface, 0, 0); write(newfd, buf->buf, buf->wpos); - buf_free(buf); + ibuf_free(buf); close(newfd); return; } @@ -489,7 +489,7 @@ session_find_iface(struct ldpd_conf *xconf, struct in_addr src) } ssize_t -session_get_pdu(struct buf_read *r, char **b) +session_get_pdu(struct ibuf_read *r, char **b) { struct ldp_hdr l; size_t av, dlen, left; diff --git a/usr.sbin/ntpd/buffer.c b/usr.sbin/ntpd/buffer.c index c8a11378143..cf0cfedb9e0 100644 --- a/usr.sbin/ntpd/buffer.c +++ b/usr.sbin/ntpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.12 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.13 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/ntpd/imsg.c b/usr.sbin/ntpd/imsg.c index 43af5f85478..320e3c392ab 100644 --- a/usr.sbin/ntpd/imsg.c +++ b/usr.sbin/ntpd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.19 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.20 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/ntpd/imsg.h b/usr.sbin/ntpd/imsg.h index 9fd3f2f4964..4e914c08e18 100644 --- a/usr.sbin/ntpd/imsg.h +++ b/usr.sbin/ntpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.5 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.6 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/ntpd/ntp_dns.c b/usr.sbin/ntpd/ntp_dns.c index 13e43e20791..59d22a8b839 100644 --- a/usr.sbin/ntpd/ntp_dns.c +++ b/usr.sbin/ntpd/ntp_dns.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp_dns.c,v 1.2 2009/02/10 16:41:39 stevesk Exp $ */ +/* $OpenBSD: ntp_dns.c,v 1.3 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003-2008 Henning Brauer <henning@openbsd.org> @@ -121,7 +121,7 @@ dns_dispatch_imsg(void) int n, cnt; char *name; struct ntp_addr *h, *hn; - struct buf *buf; + struct ibuf *buf; if ((n = imsg_read(ibuf_dns)) == -1) return (-1); diff --git a/usr.sbin/ntpd/ntpd.c b/usr.sbin/ntpd/ntpd.c index 796c6013d8e..066cbd0a75c 100644 --- a/usr.sbin/ntpd/ntpd.c +++ b/usr.sbin/ntpd/ntpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.c,v 1.66 2009/06/06 18:14:25 pyr Exp $ */ +/* $OpenBSD: ntpd.c,v 1.67 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -266,7 +266,7 @@ dispatch_imsg(struct ntpd_conf *lconf) double d; char *name; struct ntp_addr *h, *hn; - struct buf *buf; + struct ibuf *buf; if ((n = imsg_read(ibuf)) == -1) return (-1); diff --git a/usr.sbin/ospf6d/buffer.c b/usr.sbin/ospf6d/buffer.c index adba24d73d2..cea9406880a 100644 --- a/usr.sbin/ospf6d/buffer.c +++ b/usr.sbin/ospf6d/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.5 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.6 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/ospf6d/database.c b/usr.sbin/ospf6d/database.c index 20c818eb55f..5590cf91eb6 100644 --- a/usr.sbin/ospf6d/database.c +++ b/usr.sbin/ospf6d/database.c @@ -1,4 +1,4 @@ -/* $OpenBSD: database.c,v 1.9 2008/12/28 20:08:31 claudio Exp $ */ +/* $OpenBSD: database.c,v 1.10 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -43,11 +43,11 @@ send_db_description(struct nbr *nbr) struct in6_addr dst; struct db_dscrp_hdr dd_hdr; struct lsa_entry *le, *nle; - struct buf *buf; + struct ibuf *buf; int ret = 0; u_int8_t bits = 0; - if ((buf = buf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) fatal("send_db_description"); /* OSPF header */ @@ -55,7 +55,7 @@ send_db_description(struct nbr *nbr) goto fail; /* reserve space for database description header */ - if (buf_reserve(buf, sizeof(dd_hdr)) == NULL) + if (ibuf_reserve(buf, sizeof(dd_hdr)) == NULL) goto fail; switch (nbr->state) { @@ -94,7 +94,7 @@ send_db_description(struct nbr *nbr) buf->wpos + sizeof(struct lsa_hdr) < buf->max - MD5_DIGEST_LENGTH; le = nle) { nbr->dd_end = nle = TAILQ_NEXT(le, entry); - if (buf_add(buf, le->le_lsa, sizeof(struct lsa_hdr))) + if (ibuf_add(buf, le->le_lsa, sizeof(struct lsa_hdr))) goto fail; } break; @@ -141,7 +141,7 @@ send_db_description(struct nbr *nbr) dd_hdr.bits = bits; dd_hdr.dd_seq_num = htonl(nbr->dd_seq_num); - memcpy(buf_seek(buf, sizeof(struct ospf_hdr), sizeof(dd_hdr)), + memcpy(ibuf_seek(buf, sizeof(struct ospf_hdr), sizeof(dd_hdr)), &dd_hdr, sizeof(dd_hdr)); /* calculate checksum */ @@ -151,11 +151,11 @@ send_db_description(struct nbr *nbr) /* transmit packet */ ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); done: - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_db_description"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/ospf6d/hello.c b/usr.sbin/ospf6d/hello.c index becf70ee21d..0b961719125 100644 --- a/usr.sbin/ospf6d/hello.c +++ b/usr.sbin/ospf6d/hello.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hello.c,v 1.15 2010/02/01 10:22:06 jacekm Exp $ */ +/* $OpenBSD: hello.c,v 1.16 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -41,7 +41,7 @@ send_hello(struct iface *iface) struct in6_addr dst; struct hello_hdr hello; struct nbr *nbr; - struct buf *buf; + struct ibuf *buf; int ret; u_int32_t opts; @@ -62,8 +62,8 @@ send_hello(struct iface *iface) fatalx("send_hello: unknown interface type"); } - /* XXX READ_BUF_SIZE */ - if ((buf = buf_dynamic(PKG_DEF_SIZE, READ_BUF_SIZE)) == NULL) + /* XXX IBUF_READ_SIZE */ + if ((buf = ibuf_dynamic(PKG_DEF_SIZE, IBUF_READ_SIZE)) == NULL) fatal("send_hello"); /* OSPF header */ @@ -91,13 +91,13 @@ send_hello(struct iface *iface) } else hello.bd_rtr = 0; - if (buf_add(buf, &hello, sizeof(hello))) + if (ibuf_add(buf, &hello, sizeof(hello))) goto fail; /* active neighbor(s) */ LIST_FOREACH(nbr, &iface->nbr_list, entry) { if ((nbr->state >= NBR_STA_INIT) && (nbr != iface->self)) - if (buf_add(buf, &nbr->id, sizeof(nbr->id))) + if (ibuf_add(buf, &nbr->id, sizeof(nbr->id))) goto fail; } @@ -107,11 +107,11 @@ send_hello(struct iface *iface) ret = send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_hello"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/ospf6d/imsg.c b/usr.sbin/ospf6d/imsg.c index c87867354b9..7bd1ee09c51 100644 --- a/usr.sbin/ospf6d/imsg.c +++ b/usr.sbin/ospf6d/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.8 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.9 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/ospf6d/imsg.h b/usr.sbin/ospf6d/imsg.h index 9fd3f2f4964..4e914c08e18 100644 --- a/usr.sbin/ospf6d/imsg.h +++ b/usr.sbin/ospf6d/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.5 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.6 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/ospf6d/lsack.c b/usr.sbin/ospf6d/lsack.c index 0561c73ffc2..80dd887e35c 100644 --- a/usr.sbin/ospf6d/lsack.c +++ b/usr.sbin/ospf6d/lsack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsack.c,v 1.4 2007/10/16 13:01:07 norby Exp $ */ +/* $OpenBSD: lsack.c,v 1.5 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005, 2007 Esben Norby <norby@openbsd.org> @@ -37,11 +37,11 @@ void start_ls_ack_tx_timer_now(struct iface *); int send_ls_ack(struct iface *iface, struct in6_addr addr, void *data, size_t len) { - struct buf *buf; + struct ibuf *buf; int ret; - /* XXX READ_BUF_SIZE */ - if ((buf = buf_dynamic(PKG_DEF_SIZE, READ_BUF_SIZE)) == NULL) + /* XXX IBUF_READ_SIZE */ + if ((buf = ibuf_dynamic(PKG_DEF_SIZE, IBUF_READ_SIZE)) == NULL) fatal("send_ls_ack"); /* OSPF header */ @@ -49,7 +49,7 @@ send_ls_ack(struct iface *iface, struct in6_addr addr, void *data, size_t len) goto fail; /* LS ack(s) */ - if (buf_add(buf, data, len)) + if (ibuf_add(buf, data, len)) goto fail; /* calculate checksum */ @@ -58,11 +58,11 @@ send_ls_ack(struct iface *iface, struct in6_addr addr, void *data, size_t len) ret = send_packet(iface, buf->buf, buf->wpos, &addr); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_ls_ack"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/ospf6d/lsreq.c b/usr.sbin/ospf6d/lsreq.c index d460579b09c..97295dac9b9 100644 --- a/usr.sbin/ospf6d/lsreq.c +++ b/usr.sbin/ospf6d/lsreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsreq.c,v 1.4 2009/06/06 09:02:46 eric Exp $ */ +/* $OpenBSD: lsreq.c,v 1.5 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005, 2007 Esben Norby <norby@openbsd.org> @@ -36,10 +36,10 @@ send_ls_req(struct nbr *nbr) struct in6_addr dst; struct ls_req_hdr ls_req_hdr; struct lsa_entry *le, *nle; - struct buf *buf; + struct ibuf *buf; int ret; - if ((buf = buf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) fatal("send_ls_req"); switch (nbr->iface->type) { @@ -69,7 +69,7 @@ send_ls_req(struct nbr *nbr) ls_req_hdr.type = le->le_lsa->type; ls_req_hdr.ls_id = le->le_lsa->ls_id; ls_req_hdr.adv_rtr = le->le_lsa->adv_rtr; - if (buf_add(buf, &ls_req_hdr, sizeof(ls_req_hdr))) + if (ibuf_add(buf, &ls_req_hdr, sizeof(ls_req_hdr))) goto fail; } @@ -79,11 +79,11 @@ send_ls_req(struct nbr *nbr) ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_ls_req"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/ospf6d/lsupdate.c b/usr.sbin/ospf6d/lsupdate.c index c4dbb6b05b6..558b684a2ea 100644 --- a/usr.sbin/ospf6d/lsupdate.c +++ b/usr.sbin/ospf6d/lsupdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsupdate.c,v 1.4 2009/06/06 09:02:46 eric Exp $ */ +/* $OpenBSD: lsupdate.c,v 1.5 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -35,9 +35,9 @@ extern struct ospfd_conf *oeconf; extern struct imsgev *iev_rde; -struct buf *prepare_ls_update(struct iface *); -int add_ls_update(struct buf *, struct iface *, void *, int, u_int16_t); -int send_ls_update(struct buf *, struct iface *, struct in6_addr, u_int32_t); +struct ibuf *prepare_ls_update(struct iface *); +int add_ls_update(struct ibuf *, struct iface *, void *, int, u_int16_t); +int send_ls_update(struct ibuf *, struct iface *, struct in6_addr, u_int32_t); void ls_retrans_list_insert(struct nbr *, struct lsa_entry *); void ls_retrans_list_remove(struct nbr *, struct lsa_entry *); @@ -146,12 +146,12 @@ lsa_flood(struct iface *iface, struct nbr *originator, struct lsa_hdr *lsa_hdr, return (dont_ack == 2); } -struct buf * +struct ibuf * prepare_ls_update(struct iface *iface) { - struct buf *buf; + struct ibuf *buf; - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("prepare_ls_update"); /* OSPF header */ @@ -159,18 +159,18 @@ prepare_ls_update(struct iface *iface) goto fail; /* reserve space for number of lsa field */ - if (buf_reserve(buf, sizeof(u_int32_t)) == NULL) + if (ibuf_reserve(buf, sizeof(u_int32_t)) == NULL) goto fail; return (buf); fail: log_warn("prepare_ls_update"); - buf_free(buf); + ibuf_free(buf); return (NULL); } int -add_ls_update(struct buf *buf, struct iface *iface, void *data, int len, +add_ls_update(struct ibuf *buf, struct iface *iface, void *data, int len, u_int16_t older) { size_t pos; @@ -180,7 +180,7 @@ add_ls_update(struct buf *buf, struct iface *iface, void *data, int len, return (0); pos = buf->wpos; - if (buf_add(buf, data, len)) { + if (ibuf_add(buf, data, len)) { log_warn("add_ls_update"); return (0); } @@ -191,19 +191,19 @@ add_ls_update(struct buf *buf, struct iface *iface, void *data, int len, if ((age += older + iface->transmit_delay) >= MAX_AGE) age = MAX_AGE; age = htons(age); - memcpy(buf_seek(buf, pos, sizeof(age)), &age, sizeof(age)); + memcpy(ibuf_seek(buf, pos, sizeof(age)), &age, sizeof(age)); return (1); } int -send_ls_update(struct buf *buf, struct iface *iface, struct in6_addr addr, +send_ls_update(struct ibuf *buf, struct iface *iface, struct in6_addr addr, u_int32_t nlsa) { int ret; nlsa = htonl(nlsa); - memcpy(buf_seek(buf, sizeof(struct ospf_hdr), sizeof(nlsa)), + memcpy(ibuf_seek(buf, sizeof(struct ospf_hdr), sizeof(nlsa)), &nlsa, sizeof(nlsa)); /* calculate checksum */ if (upd_ospf_hdr(buf, iface)) @@ -211,11 +211,11 @@ send_ls_update(struct buf *buf, struct iface *iface, struct in6_addr addr, ret = send_packet(iface, buf->buf, buf->wpos, &addr); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_ls_update"); - buf_free(buf); + ibuf_free(buf); return (-1); } @@ -416,7 +416,7 @@ ls_retrans_timer(int fd, short event, void *bula) struct in6_addr addr; struct nbr *nbr = bula; struct lsa_entry *le; - struct buf *buf; + struct ibuf *buf; time_t now; int d; u_int32_t nlsa = 0; diff --git a/usr.sbin/ospf6d/ospfe.c b/usr.sbin/ospf6d/ospfe.c index 3daf39e233a..b87de73540c 100644 --- a/usr.sbin/ospf6d/ospfe.c +++ b/usr.sbin/ospf6d/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.28 2009/06/06 09:02:46 eric Exp $ */ +/* $OpenBSD: ospfe.c,v 1.29 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -178,7 +178,7 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2], TAILQ_INIT(&ctl_conns); control_listen(); - if ((pkt_ptr = calloc(1, READ_BUF_SIZE)) == NULL) + if ((pkt_ptr = calloc(1, IBUF_READ_SIZE)) == NULL) fatal("ospfe"); /* start interfaces */ @@ -704,7 +704,7 @@ orig_rtr_lsa_area(struct area *area) struct lsa_rtr lsa_rtr; struct lsa_rtr_link rtr_link; struct iface *iface; - struct buf *buf; + struct ibuf *buf; struct nbr *nbr, *self = NULL; u_int32_t flags; u_int16_t chksum; @@ -712,16 +712,16 @@ orig_rtr_lsa_area(struct area *area) log_debug("orig_rtr_lsa: area %s", inet_ntoa(area->id)); - /* XXX READ_BUF_SIZE */ - if ((buf = buf_dynamic(sizeof(lsa_hdr), READ_BUF_SIZE)) == NULL) + /* XXX IBUF_READ_SIZE */ + if ((buf = ibuf_dynamic(sizeof(lsa_hdr), IBUF_READ_SIZE)) == NULL) fatal("orig_rtr_lsa"); /* reserve space for LSA header and LSA Router header */ - if (buf_reserve(buf, sizeof(lsa_hdr)) == NULL) - fatal("orig_rtr_lsa: buf_reserve failed"); + if (ibuf_reserve(buf, sizeof(lsa_hdr)) == NULL) + fatal("orig_rtr_lsa: ibuf_reserve failed"); - if (buf_reserve(buf, sizeof(lsa_rtr)) == NULL) - fatal("orig_rtr_lsa: buf_reserve failed"); + if (ibuf_reserve(buf, sizeof(lsa_rtr)) == NULL) + fatal("orig_rtr_lsa: ibuf_reserve failed"); /* links */ LIST_FOREACH(iface, &area->iface_list, entry) { @@ -744,7 +744,7 @@ orig_rtr_lsa_area(struct area *area) rtr_link.iface_id = htonl(iface->ifindex); rtr_link.nbr_iface_id = htonl(nbr->iface_id); rtr_link.nbr_rtr_id = nbr->id.s_addr; - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) fatalx("orig_rtr_lsa: buf_add failed"); } continue; @@ -769,7 +769,7 @@ orig_rtr_lsa_area(struct area *area) rtr_link.iface_id = htonl(iface->ifindex); rtr_link.nbr_iface_id = htonl(iface->dr->iface_id); rtr_link.nbr_rtr_id = iface->dr->id.s_addr; - if (buf_add(buf, &rtr_link, + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) fatalx("orig_rtr_lsa: " "buf_add failed"); @@ -795,7 +795,7 @@ orig_rtr_lsa_area(struct area *area) else rtr_link.metric = htons(iface->metric); virtual = 1; - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) fatalx("orig_rtr_lsa: buf_add failed"); log_debug("orig_rtr_lsa: virtual link, " @@ -809,7 +809,7 @@ orig_rtr_lsa_area(struct area *area) rtr_link.data = 0xffffffff; rtr_link.type = LINK_TYPE_STUB_NET; rtr_link.metric = htons(iface->metric); - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) fatalx("orig_rtr_lsa: buf_add failed"); LIST_FOREACH(nbr, &iface->nbr_list, entry) { @@ -829,7 +829,7 @@ orig_rtr_lsa_area(struct area *area) else rtr_link.metric = htons(iface->metric); - if (buf_add(buf, &rtr_link, + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) fatalx("orig_rtr_lsa: " "buf_add failed"); @@ -869,7 +869,7 @@ orig_rtr_lsa_area(struct area *area) LSA_24_SETLO(lsa_rtr.opts, area_ospf_options(area)); LSA_24_SETHI(lsa_rtr.opts, flags); lsa_rtr.opts = htonl(lsa_rtr.opts); - memcpy(buf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_rtr)), + memcpy(ibuf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_rtr)), &lsa_rtr, sizeof(lsa_rtr)); /* LSA header */ @@ -881,10 +881,10 @@ orig_rtr_lsa_area(struct area *area) lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); lsa_hdr.len = htons(buf->wpos); lsa_hdr.ls_chksum = 0; /* updated later */ - memcpy(buf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); + memcpy(ibuf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); chksum = htons(iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET)); - memcpy(buf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), + memcpy(ibuf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), &chksum, sizeof(chksum)); if (self) @@ -894,7 +894,7 @@ orig_rtr_lsa_area(struct area *area) log_warnx("orig_rtr_lsa: empty area %s", inet_ntoa(area->id)); - buf_free(buf); + ibuf_free(buf); } void @@ -902,32 +902,32 @@ orig_net_lsa(struct iface *iface) { struct lsa_hdr lsa_hdr; struct nbr *nbr; - struct buf *buf; + struct ibuf *buf; struct lsa_net lsa_net; int num_rtr = 0; u_int16_t chksum; - /* XXX READ_BUF_SIZE */ - if ((buf = buf_dynamic(sizeof(lsa_hdr), READ_BUF_SIZE)) == NULL) + /* XXX IBUF_READ_SIZE */ + if ((buf = ibuf_dynamic(sizeof(lsa_hdr), IBUF_READ_SIZE)) == NULL) fatal("orig_net_lsa"); /* reserve space for LSA header and options field */ - if (buf_reserve(buf, sizeof(lsa_hdr) + sizeof(lsa_net)) == NULL) - fatal("orig_net_lsa: buf_reserve failed"); + if (ibuf_reserve(buf, sizeof(lsa_hdr) + sizeof(lsa_net)) == NULL) + fatal("orig_net_lsa: ibuf_reserve failed"); lsa_net.opts = 0; /* fully adjacent neighbors + self */ LIST_FOREACH(nbr, &iface->nbr_list, entry) if (nbr->state & NBR_STA_FULL) { - if (buf_add(buf, &nbr->id, sizeof(nbr->id))) - fatal("orig_net_lsa: buf_add failed"); + if (ibuf_add(buf, &nbr->id, sizeof(nbr->id))) + fatal("orig_net_lsa: ibuf_add failed"); lsa_net.opts |= nbr->options; num_rtr++; } if (num_rtr == 1) { /* non transit net therefor no need to generate a net lsa */ - buf_free(buf); + ibuf_free(buf); return; } @@ -944,20 +944,20 @@ orig_net_lsa(struct iface *iface) lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); lsa_hdr.len = htons(buf->wpos); lsa_hdr.ls_chksum = 0; /* updated later */ - memcpy(buf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); + memcpy(ibuf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); lsa_net.opts &= lsa_net.opts & htonl(LSA_24_MASK); - memcpy(buf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_net)), &lsa_net, + memcpy(ibuf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_net)), &lsa_net, sizeof(lsa_net)); chksum = htons(iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET)); - memcpy(buf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), + memcpy(ibuf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), &chksum, sizeof(chksum)); imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0, -1, buf->buf, buf->wpos); - buf_free(buf); + ibuf_free(buf); } void @@ -966,7 +966,7 @@ orig_link_lsa(struct iface *iface) struct lsa_hdr lsa_hdr; struct lsa_link lsa_link; struct lsa_prefix lsa_prefix; - struct buf *buf; + struct ibuf *buf; struct iface_addr *ia; struct in6_addr prefix; unsigned int num_prefix = 0; @@ -992,14 +992,14 @@ orig_link_lsa(struct iface *iface) fatalx("orig_link_lsa: unknown interface type"); } - /* XXX READ_BUF_SIZE */ - if ((buf = buf_dynamic(sizeof(lsa_hdr) + sizeof(lsa_link), - READ_BUF_SIZE)) == NULL) + /* XXX IBUF_READ_SIZE */ + if ((buf = ibuf_dynamic(sizeof(lsa_hdr) + sizeof(lsa_link), + IBUF_READ_SIZE)) == NULL) fatal("orig_link_lsa"); /* reserve space for LSA header and LSA link header */ - if (buf_reserve(buf, sizeof(lsa_hdr) + sizeof(lsa_link)) == NULL) - fatal("orig_link_lsa: buf_reserve failed"); + if (ibuf_reserve(buf, sizeof(lsa_hdr) + sizeof(lsa_link)) == NULL) + fatal("orig_link_lsa: ibuf_reserve failed"); /* link-local address, and all prefixes configured on interface */ TAILQ_FOREACH(ia, &iface->ifa_list, entry) { @@ -1015,11 +1015,11 @@ orig_link_lsa(struct iface *iface) lsa_prefix.metric = 0; inet6applymask(&prefix, &ia->addr, ia->prefixlen); log_debug("orig_link_lsa: prefix %s", log_in6addr(&prefix)); - if (buf_add(buf, &lsa_prefix, sizeof(lsa_prefix))) - fatal("orig_link_lsa: buf_add failed"); - if (buf_add(buf, &prefix.s6_addr[0], + if (ibuf_add(buf, &lsa_prefix, sizeof(lsa_prefix))) + fatal("orig_link_lsa: ibuf_add failed"); + if (ibuf_add(buf, &prefix.s6_addr[0], LSA_PREFIXSIZE(ia->prefixlen))) - fatal("orig_link_lsa: buf_add failed"); + fatal("orig_link_lsa: ibuf_add failed"); num_prefix++; } @@ -1029,7 +1029,7 @@ orig_link_lsa(struct iface *iface) LSA_24_SETLO(lsa_link.opts, options); lsa_link.opts = htonl(lsa_link.opts); lsa_link.numprefix = htonl(num_prefix); - memcpy(buf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_link)), + memcpy(ibuf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_link)), &lsa_link, sizeof(lsa_link)); /* LSA header */ @@ -1041,16 +1041,16 @@ orig_link_lsa(struct iface *iface) lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); lsa_hdr.len = htons(buf->wpos); lsa_hdr.ls_chksum = 0; /* updated later */ - memcpy(buf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); + memcpy(ibuf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); chksum = htons(iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET)); - memcpy(buf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), + memcpy(ibuf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), &chksum, sizeof(chksum)); imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0, -1, buf->buf, buf->wpos); - buf_free(buf); + ibuf_free(buf); } u_int32_t diff --git a/usr.sbin/ospf6d/ospfe.h b/usr.sbin/ospf6d/ospfe.h index ef99a587f57..cce785d2657 100644 --- a/usr.sbin/ospf6d/ospfe.h +++ b/usr.sbin/ospf6d/ospfe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.h,v 1.15 2009/03/29 16:24:38 stsp Exp $ */ +/* $OpenBSD: ospfe.h,v 1.16 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -225,8 +225,8 @@ struct ctl_nbr *nbr_to_ctl(struct nbr *); struct lsa_hdr *lsa_hdr_new(void); /* packet.c */ -int gen_ospf_hdr(struct buf *, struct iface *, u_int8_t); -int upd_ospf_hdr(struct buf *, struct iface *); +int gen_ospf_hdr(struct ibuf *, struct iface *, u_int8_t); +int upd_ospf_hdr(struct ibuf *, struct iface *); int send_packet(struct iface *, void *, size_t, struct in6_addr *); void recv_packet(int, short, void *); diff --git a/usr.sbin/ospf6d/packet.c b/usr.sbin/ospf6d/packet.c index 4bea8456228..ebb5b345254 100644 --- a/usr.sbin/ospf6d/packet.c +++ b/usr.sbin/ospf6d/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.9 2008/03/24 16:11:04 deraadt Exp $ */ +/* $OpenBSD: packet.c,v 1.10 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -44,7 +44,7 @@ struct iface *find_iface(struct ospfd_conf *, unsigned int, struct in6_addr *); int -gen_ospf_hdr(struct buf *buf, struct iface *iface, u_int8_t type) +gen_ospf_hdr(struct ibuf *buf, struct iface *iface, u_int8_t type) { struct ospf_hdr ospf_hdr; @@ -57,15 +57,15 @@ gen_ospf_hdr(struct buf *buf, struct iface *iface, u_int8_t type) ospf_hdr.instance = DEFAULT_INSTANCE_ID; ospf_hdr.zero = 0; /* must be zero */ - return (buf_add(buf, &ospf_hdr, sizeof(ospf_hdr))); + return (ibuf_add(buf, &ospf_hdr, sizeof(ospf_hdr))); } int -upd_ospf_hdr(struct buf *buf, struct iface *iface) +upd_ospf_hdr(struct ibuf *buf, struct iface *iface) { struct ospf_hdr *ospf_hdr; - if ((ospf_hdr = buf_seek(buf, 0, sizeof(ospf_hdr))) == NULL) + if ((ospf_hdr = ibuf_seek(buf, 0, sizeof(ospf_hdr))) == NULL) fatalx("upd_ospf_hdr: buf_seek failed"); /* update length */ diff --git a/usr.sbin/ospfd/auth.c b/usr.sbin/ospfd/auth.c index b9fa536b274..0410a088da4 100644 --- a/usr.sbin/ospfd/auth.c +++ b/usr.sbin/ospfd/auth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth.c,v 1.17 2009/06/06 07:31:26 eric Exp $ */ +/* $OpenBSD: auth.c,v 1.18 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -137,29 +137,29 @@ auth_validate(void *buf, u_int16_t len, struct iface *iface, struct nbr *nbr) } int -auth_gen(struct buf *buf, struct iface *iface) +auth_gen(struct ibuf *buf, struct iface *iface) { MD5_CTX hash; u_int8_t digest[MD5_DIGEST_LENGTH]; struct ospf_hdr *ospf_hdr; struct auth_md *md; - if ((ospf_hdr = buf_seek(buf, 0, sizeof(ospf_hdr))) == NULL) + if ((ospf_hdr = ibuf_seek(buf, 0, sizeof(ospf_hdr))) == NULL) fatalx("auth_gen: buf_seek failed"); /* update length */ - if (buf_size(buf) > USHRT_MAX) + if (ibuf_size(buf) > USHRT_MAX) fatalx("auth_gen: resulting ospf packet too big"); - ospf_hdr->len = htons(buf_size(buf)); + ospf_hdr->len = htons(ibuf_size(buf)); /* clear auth_key field */ bzero(ospf_hdr->auth_key.simple, sizeof(ospf_hdr->auth_key.simple)); switch (iface->auth_type) { case AUTH_NONE: - ospf_hdr->chksum = in_cksum(buf->buf, buf_size(buf)); + ospf_hdr->chksum = in_cksum(buf->buf, ibuf_size(buf)); break; case AUTH_SIMPLE: - ospf_hdr->chksum = in_cksum(buf->buf, buf_size(buf)); + ospf_hdr->chksum = in_cksum(buf->buf, ibuf_size(buf)); strncpy(ospf_hdr->auth_key.simple, iface->auth_key, sizeof(ospf_hdr->auth_key.simple)); @@ -184,11 +184,11 @@ auth_gen(struct buf *buf, struct iface *iface) /* calculate MD5 digest */ MD5Init(&hash); - MD5Update(&hash, buf->buf, buf_size(buf)); + MD5Update(&hash, buf->buf, ibuf_size(buf)); MD5Update(&hash, digest, MD5_DIGEST_LENGTH); MD5Final(digest, &hash); - return (buf_add(buf, digest, MD5_DIGEST_LENGTH)); + return (ibuf_add(buf, digest, MD5_DIGEST_LENGTH)); default: log_debug("auth_gen: unknown auth type, interface %s", iface->name); diff --git a/usr.sbin/ospfd/buffer.c b/usr.sbin/ospfd/buffer.c index 68789a16dbf..2be7a478e2b 100644 --- a/usr.sbin/ospfd/buffer.c +++ b/usr.sbin/ospfd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.17 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.18 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/ospfd/database.c b/usr.sbin/ospfd/database.c index 960c39c9e12..c205ca9e8a0 100644 --- a/usr.sbin/ospfd/database.c +++ b/usr.sbin/ospfd/database.c @@ -1,4 +1,4 @@ -/* $OpenBSD: database.c,v 1.26 2009/01/31 11:44:49 claudio Exp $ */ +/* $OpenBSD: database.c,v 1.27 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -43,11 +43,11 @@ send_db_description(struct nbr *nbr) struct sockaddr_in dst; struct db_dscrp_hdr dd_hdr; struct lsa_entry *le, *nle; - struct buf *buf; + struct ibuf *buf; int ret = 0; u_int8_t bits = 0; - if ((buf = buf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) fatal("send_db_description"); /* OSPF header */ @@ -55,7 +55,7 @@ send_db_description(struct nbr *nbr) goto fail; /* reserve space for database description header */ - if (buf_reserve(buf, sizeof(dd_hdr)) == NULL) + if (ibuf_reserve(buf, sizeof(dd_hdr)) == NULL) goto fail; switch (nbr->state) { @@ -91,10 +91,10 @@ send_db_description(struct nbr *nbr) /* build LSA list, keep space for a possible md5 sum */ for (le = TAILQ_FIRST(&nbr->db_sum_list); le != NULL && - buf_left(buf) >= MD5_DIGEST_LENGTH + sizeof(struct lsa_hdr); + ibuf_left(buf) >= MD5_DIGEST_LENGTH + sizeof(struct lsa_hdr); le = nle) { nbr->dd_end = nle = TAILQ_NEXT(le, entry); - if (buf_add(buf, le->le_lsa, sizeof(struct lsa_hdr))) + if (ibuf_add(buf, le->le_lsa, sizeof(struct lsa_hdr))) goto fail; } break; @@ -142,7 +142,7 @@ send_db_description(struct nbr *nbr) dd_hdr.bits = bits; dd_hdr.dd_seq_num = htonl(nbr->dd_seq_num); - memcpy(buf_seek(buf, sizeof(struct ospf_hdr), sizeof(dd_hdr)), + memcpy(ibuf_seek(buf, sizeof(struct ospf_hdr), sizeof(dd_hdr)), &dd_hdr, sizeof(dd_hdr)); /* update authentication and calculate checksum */ @@ -152,11 +152,11 @@ send_db_description(struct nbr *nbr) /* transmit packet */ ret = send_packet(nbr->iface, buf, &dst); done: - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_db_description"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/ospfd/hello.c b/usr.sbin/ospfd/hello.c index 5bb3201404c..20b16f964f0 100644 --- a/usr.sbin/ospfd/hello.c +++ b/usr.sbin/ospfd/hello.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hello.c,v 1.18 2010/05/13 22:51:56 sthen Exp $ */ +/* $OpenBSD: hello.c,v 1.19 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -41,7 +41,7 @@ send_hello(struct iface *iface) struct sockaddr_in dst; struct hello_hdr hello; struct nbr *nbr; - struct buf *buf; + struct ibuf *buf; int ret; dst.sin_family = AF_INET; @@ -64,8 +64,8 @@ send_hello(struct iface *iface) fatalx("send_hello: unknown interface type"); } - /* XXX READ_BUF_SIZE */ - if ((buf = buf_dynamic(PKG_DEF_SIZE, READ_BUF_SIZE)) == NULL) + /* XXX IBUF_READ_SIZE */ + if ((buf = ibuf_dynamic(PKG_DEF_SIZE, IBUF_READ_SIZE)) == NULL) fatal("send_hello"); /* OSPF header */ @@ -90,13 +90,13 @@ send_hello(struct iface *iface) } else hello.bd_rtr = 0; - if (buf_add(buf, &hello, sizeof(hello))) + if (ibuf_add(buf, &hello, sizeof(hello))) goto fail; /* active neighbor(s) */ LIST_FOREACH(nbr, &iface->nbr_list, entry) { if ((nbr->state >= NBR_STA_INIT) && (nbr != iface->self)) - if (buf_add(buf, &nbr->id, sizeof(nbr->id))) + if (ibuf_add(buf, &nbr->id, sizeof(nbr->id))) goto fail; } @@ -105,11 +105,11 @@ send_hello(struct iface *iface) goto fail; ret = send_packet(iface, buf, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_hello"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/ospfd/imsg.c b/usr.sbin/ospfd/imsg.c index 64d53ce0b0a..ba6685f560f 100644 --- a/usr.sbin/ospfd/imsg.c +++ b/usr.sbin/ospfd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.20 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.21 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/ospfd/imsg.h b/usr.sbin/ospfd/imsg.h index 7a1e5cd041b..90baba107fa 100644 --- a/usr.sbin/ospfd/imsg.h +++ b/usr.sbin/ospfd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.9 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.10 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/ospfd/lsack.c b/usr.sbin/ospfd/lsack.c index 81a118a1f03..2d0236c338b 100644 --- a/usr.sbin/ospfd/lsack.c +++ b/usr.sbin/ospfd/lsack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsack.c,v 1.18 2009/01/31 08:55:00 claudio Exp $ */ +/* $OpenBSD: lsack.c,v 1.19 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -38,11 +38,11 @@ int send_ls_ack(struct iface *iface, struct in_addr addr, void *data, size_t len) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; int ret; - /* XXX READ_BUF_SIZE */ - if ((buf = buf_dynamic(PKG_DEF_SIZE, READ_BUF_SIZE)) == NULL) + /* XXX IBUF_READ_SIZE */ + if ((buf = ibuf_dynamic(PKG_DEF_SIZE, READ_BUF_SIZE)) == NULL) fatal("send_ls_ack"); dst.sin_family = AF_INET; @@ -54,7 +54,7 @@ send_ls_ack(struct iface *iface, struct in_addr addr, void *data, size_t len) goto fail; /* LS ack(s) */ - if (buf_add(buf, data, len)) + if (ibuf_add(buf, data, len)) goto fail; /* update authentication and calculate checksum */ @@ -63,11 +63,11 @@ send_ls_ack(struct iface *iface, struct in_addr addr, void *data, size_t len) ret = send_packet(iface, buf, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_ls_ack"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/ospfd/lsreq.c b/usr.sbin/ospfd/lsreq.c index 646bcfa64b0..840df7b24c3 100644 --- a/usr.sbin/ospfd/lsreq.c +++ b/usr.sbin/ospfd/lsreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsreq.c,v 1.18 2009/06/06 07:31:26 eric Exp $ */ +/* $OpenBSD: lsreq.c,v 1.19 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -36,10 +36,10 @@ send_ls_req(struct nbr *nbr) struct sockaddr_in dst; struct ls_req_hdr ls_req_hdr; struct lsa_entry *le, *nle; - struct buf *buf; + struct ibuf *buf; int ret; - if ((buf = buf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(nbr->iface->mtu - sizeof(struct ip))) == NULL) fatal("send_ls_req"); /* set destination */ @@ -66,13 +66,13 @@ send_ls_req(struct nbr *nbr) /* LSA header(s), keep space for a possible md5 sum */ for (le = TAILQ_FIRST(&nbr->ls_req_list); le != NULL && - buf_left(buf) >= sizeof(struct ls_req_hdr) + MD5_DIGEST_LENGTH; + ibuf_left(buf) >= sizeof(struct ls_req_hdr) + MD5_DIGEST_LENGTH; le = nle) { nbr->ls_req = nle = TAILQ_NEXT(le, entry); ls_req_hdr.type = htonl(le->le_lsa->type); ls_req_hdr.ls_id = le->le_lsa->ls_id; ls_req_hdr.adv_rtr = le->le_lsa->adv_rtr; - if (buf_add(buf, &ls_req_hdr, sizeof(ls_req_hdr))) + if (ibuf_add(buf, &ls_req_hdr, sizeof(ls_req_hdr))) goto fail; } @@ -82,11 +82,11 @@ send_ls_req(struct nbr *nbr) ret = send_packet(nbr->iface, buf, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_ls_req"); - buf_free(buf); + ibuf_free(buf); return (-1); } diff --git a/usr.sbin/ospfd/lsupdate.c b/usr.sbin/ospfd/lsupdate.c index b0cd2c0d280..9b00628f98d 100644 --- a/usr.sbin/ospfd/lsupdate.c +++ b/usr.sbin/ospfd/lsupdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsupdate.c,v 1.38 2009/06/06 07:31:26 eric Exp $ */ +/* $OpenBSD: lsupdate.c,v 1.39 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -35,10 +35,10 @@ extern struct ospfd_conf *oeconf; extern struct imsgev *iev_rde; -struct buf *prepare_ls_update(struct iface *); -int add_ls_update(struct buf *, struct iface *, void *, u_int16_t, +struct ibuf *prepare_ls_update(struct iface *); +int add_ls_update(struct ibuf *, struct iface *, void *, u_int16_t, u_int16_t); -int send_ls_update(struct buf *, struct iface *, struct in_addr, u_int32_t); +int send_ls_update(struct ibuf *, struct iface *, struct in_addr, u_int32_t); void ls_retrans_list_insert(struct nbr *, struct lsa_entry *); void ls_retrans_list_remove(struct nbr *, struct lsa_entry *); @@ -147,12 +147,12 @@ lsa_flood(struct iface *iface, struct nbr *originator, struct lsa_hdr *lsa_hdr, return (dont_ack == 2); } -struct buf * +struct ibuf * prepare_ls_update(struct iface *iface) { - struct buf *buf; + struct ibuf *buf; - if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL) + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL) fatal("prepare_ls_update"); /* OSPF header */ @@ -160,28 +160,28 @@ prepare_ls_update(struct iface *iface) goto fail; /* reserve space for number of lsa field */ - if (buf_reserve(buf, sizeof(u_int32_t)) == NULL) + if (ibuf_reserve(buf, sizeof(u_int32_t)) == NULL) goto fail; return (buf); fail: log_warn("prepare_ls_update"); - buf_free(buf); + ibuf_free(buf); return (NULL); } int -add_ls_update(struct buf *buf, struct iface *iface, void *data, u_int16_t len, +add_ls_update(struct ibuf *buf, struct iface *iface, void *data, u_int16_t len, u_int16_t older) { void *lsage; u_int16_t age; - if (buf_left(buf) < (size_t)len + MD5_DIGEST_LENGTH) + if (ibuf_left(buf) < (size_t)len + MD5_DIGEST_LENGTH) return (0); - lsage = buf_reserve(buf, 0); - if (buf_add(buf, data, len)) { + lsage = ibuf_reserve(buf, 0); + if (ibuf_add(buf, data, len)) { log_warn("add_ls_update"); return (0); } @@ -200,14 +200,14 @@ add_ls_update(struct buf *buf, struct iface *iface, void *data, u_int16_t len, int -send_ls_update(struct buf *buf, struct iface *iface, struct in_addr addr, +send_ls_update(struct ibuf *buf, struct iface *iface, struct in_addr addr, u_int32_t nlsa) { struct sockaddr_in dst; int ret; nlsa = htonl(nlsa); - memcpy(buf_seek(buf, sizeof(struct ospf_hdr), sizeof(nlsa)), + memcpy(ibuf_seek(buf, sizeof(struct ospf_hdr), sizeof(nlsa)), &nlsa, sizeof(nlsa)); /* update authentication and calculate checksum */ if (auth_gen(buf, iface)) @@ -220,11 +220,11 @@ send_ls_update(struct buf *buf, struct iface *iface, struct in_addr addr, ret = send_packet(iface, buf, &dst); - buf_free(buf); + ibuf_free(buf); return (ret); fail: log_warn("send_ls_update"); - buf_free(buf); + ibuf_free(buf); return (-1); } @@ -425,7 +425,7 @@ ls_retrans_timer(int fd, short event, void *bula) struct in_addr addr; struct nbr *nbr = bula; struct lsa_entry *le; - struct buf *buf; + struct ibuf *buf; time_t now; int d; u_int32_t nlsa = 0; diff --git a/usr.sbin/ospfd/ospfe.c b/usr.sbin/ospfd/ospfe.c index 7b2f19d339a..2f4a502c392 100644 --- a/usr.sbin/ospfd/ospfe.c +++ b/usr.sbin/ospfd/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.74 2010/02/16 18:27:11 claudio Exp $ */ +/* $OpenBSD: ospfe.c,v 1.75 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -183,7 +183,7 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2], TAILQ_INIT(&ctl_conns); control_listen(); - if ((pkt_ptr = calloc(1, READ_BUF_SIZE)) == NULL) + if ((pkt_ptr = calloc(1, IBUF_READ_SIZE)) == NULL) fatal("ospfe"); /* start interfaces */ @@ -748,7 +748,7 @@ orig_rtr_lsa(struct area *area) struct lsa_rtr lsa_rtr; struct lsa_rtr_link rtr_link; struct iface *iface; - struct buf *buf; + struct ibuf *buf; struct nbr *nbr, *self = NULL; u_int16_t num_links = 0; u_int16_t chksum; @@ -756,16 +756,16 @@ orig_rtr_lsa(struct area *area) log_debug("orig_rtr_lsa: area %s", inet_ntoa(area->id)); - /* XXX READ_BUF_SIZE */ - if ((buf = buf_dynamic(sizeof(lsa_hdr), READ_BUF_SIZE)) == NULL) + /* XXX IBUF_READ_SIZE */ + if ((buf = ibuf_dynamic(sizeof(lsa_hdr), READ_BUF_SIZE)) == NULL) fatal("orig_rtr_lsa"); /* reserve space for LSA header and LSA Router header */ - if (buf_reserve(buf, sizeof(lsa_hdr)) == NULL) - fatal("orig_rtr_lsa: buf_reserve failed"); + if (ibuf_reserve(buf, sizeof(lsa_hdr)) == NULL) + fatal("orig_rtr_lsa: ibuf_reserve failed"); - if (buf_reserve(buf, sizeof(lsa_rtr)) == NULL) - fatal("orig_rtr_lsa: buf_reserve failed"); + if (ibuf_reserve(buf, sizeof(lsa_rtr)) == NULL) + fatal("orig_rtr_lsa: ibuf_reserve failed"); /* links */ LIST_FOREACH(iface, &area->iface_list, entry) { @@ -780,7 +780,7 @@ orig_rtr_lsa(struct area *area) rtr_link.type = LINK_TYPE_STUB_NET; rtr_link.metric = htons(iface->metric); num_links++; - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) fatalx("orig_rtr_lsa: buf_add failed"); continue; } @@ -804,7 +804,7 @@ orig_rtr_lsa(struct area *area) else rtr_link.metric = htons(iface->metric); num_links++; - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) fatalx("orig_rtr_lsa: buf_add failed"); } if (iface->state & IF_STA_POINTTOPOINT) { @@ -821,7 +821,7 @@ orig_rtr_lsa(struct area *area) rtr_link.type = LINK_TYPE_STUB_NET; rtr_link.metric = htons(iface->metric); num_links++; - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) fatalx("orig_rtr_lsa: buf_add failed"); } continue; @@ -882,8 +882,8 @@ orig_rtr_lsa(struct area *area) else rtr_link.metric = htons(iface->metric); num_links++; - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) - fatalx("orig_rtr_lsa: buf_add failed"); + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) + fatalx("orig_rtr_lsa: ibuf_add failed"); continue; case IF_TYPE_VIRTUALLINK: LIST_FOREACH(nbr, &iface->nbr_list, entry) { @@ -903,8 +903,8 @@ orig_rtr_lsa(struct area *area) rtr_link.metric = htons(iface->metric); num_links++; virtual = 1; - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) - fatalx("orig_rtr_lsa: buf_add failed"); + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) + fatalx("orig_rtr_lsa: ibuf_add failed"); log_debug("orig_rtr_lsa: virtual link, " "interface %s", iface->name); @@ -918,8 +918,8 @@ orig_rtr_lsa(struct area *area) rtr_link.type = LINK_TYPE_STUB_NET; rtr_link.metric = htons(iface->metric); num_links++; - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) - fatalx("orig_rtr_lsa: buf_add failed"); + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) + fatalx("orig_rtr_lsa: ibuf_add failed"); LIST_FOREACH(nbr, &iface->nbr_list, entry) { if (nbr != iface->self && @@ -939,10 +939,10 @@ orig_rtr_lsa(struct area *area) rtr_link.metric = htons(iface->metric); num_links++; - if (buf_add(buf, &rtr_link, + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) fatalx("orig_rtr_lsa: " - "buf_add failed"); + "ibuf_add failed"); } } continue; @@ -958,8 +958,8 @@ orig_rtr_lsa(struct area *area) else rtr_link.metric = htons(iface->metric); num_links++; - if (buf_add(buf, &rtr_link, sizeof(rtr_link))) - fatalx("orig_rtr_lsa: buf_add failed"); + if (ibuf_add(buf, &rtr_link, sizeof(rtr_link))) + fatalx("orig_rtr_lsa: ibuf_add failed"); } /* LSA router header */ @@ -987,7 +987,7 @@ orig_rtr_lsa(struct area *area) lsa_rtr.dummy = 0; lsa_rtr.nlinks = htons(num_links); - memcpy(buf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_rtr)), + memcpy(ibuf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_rtr)), &lsa_rtr, sizeof(lsa_rtr)); /* LSA header */ @@ -997,22 +997,22 @@ orig_rtr_lsa(struct area *area) lsa_hdr.ls_id = oeconf->rtr_id.s_addr; lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr; lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); - lsa_hdr.len = htons(buf_size(buf)); + lsa_hdr.len = htons(ibuf_size(buf)); lsa_hdr.ls_chksum = 0; /* updated later */ - memcpy(buf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); + memcpy(ibuf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); - chksum = htons(iso_cksum(buf->buf, buf_size(buf), LS_CKSUM_OFFSET)); - memcpy(buf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), + chksum = htons(iso_cksum(buf->buf, ibuf_size(buf), LS_CKSUM_OFFSET)); + memcpy(ibuf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), &chksum, sizeof(chksum)); if (self) imsg_compose_event(iev_rde, IMSG_LS_UPD, self->peerid, 0, - -1, buf->buf, buf_size(buf)); + -1, buf->buf, ibuf_size(buf)); else log_warnx("orig_rtr_lsa: empty area %s", inet_ntoa(area->id)); - buf_free(buf); + ibuf_free(buf); } void @@ -1020,33 +1020,33 @@ orig_net_lsa(struct iface *iface) { struct lsa_hdr lsa_hdr; struct nbr *nbr; - struct buf *buf; + struct ibuf *buf; int num_rtr = 0; u_int16_t chksum; - /* XXX READ_BUF_SIZE */ - if ((buf = buf_dynamic(sizeof(lsa_hdr), READ_BUF_SIZE)) == NULL) + /* XXX IBUF_READ_SIZE */ + if ((buf = ibuf_dynamic(sizeof(lsa_hdr), IBUF_READ_SIZE)) == NULL) fatal("orig_net_lsa"); /* reserve space for LSA header and LSA Router header */ - if (buf_reserve(buf, sizeof(lsa_hdr)) == NULL) - fatal("orig_net_lsa: buf_reserve failed"); + if (ibuf_reserve(buf, sizeof(lsa_hdr)) == NULL) + fatal("orig_net_lsa: ibuf_reserve failed"); /* LSA net mask and then all fully adjacent routers */ - if (buf_add(buf, &iface->mask, sizeof(iface->mask))) - fatal("orig_net_lsa: buf_add failed"); + if (ibuf_add(buf, &iface->mask, sizeof(iface->mask))) + fatal("orig_net_lsa: ibuf_add failed"); /* fully adjacent neighbors + self */ LIST_FOREACH(nbr, &iface->nbr_list, entry) if (nbr->state & NBR_STA_FULL) { - if (buf_add(buf, &nbr->id, sizeof(nbr->id))) - fatal("orig_net_lsa: buf_add failed"); + if (ibuf_add(buf, &nbr->id, sizeof(nbr->id))) + fatal("orig_net_lsa: ibuf_add failed"); num_rtr++; } if (num_rtr == 1) { /* non transit net therefore no need to generate a net lsa */ - buf_free(buf); + ibuf_free(buf); return; } @@ -1061,18 +1061,18 @@ orig_net_lsa(struct iface *iface) lsa_hdr.ls_id = iface->addr.s_addr; lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr; lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); - lsa_hdr.len = htons(buf_size(buf)); + lsa_hdr.len = htons(ibuf_size(buf)); lsa_hdr.ls_chksum = 0; /* updated later */ - memcpy(buf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); + memcpy(ibuf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); - chksum = htons(iso_cksum(buf->buf, buf_size(buf), LS_CKSUM_OFFSET)); - memcpy(buf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), + chksum = htons(iso_cksum(buf->buf, ibuf_size(buf), LS_CKSUM_OFFSET)); + memcpy(ibuf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), &chksum, sizeof(chksum)); imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0, - -1, buf->buf, buf_size(buf)); + -1, buf->buf, ibuf_size(buf)); - buf_free(buf); + ibuf_free(buf); } u_int32_t diff --git a/usr.sbin/ospfd/ospfe.h b/usr.sbin/ospfd/ospfe.h index f55de72e176..b6fe009b8ce 100644 --- a/usr.sbin/ospfd/ospfe.h +++ b/usr.sbin/ospfd/ospfe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.h,v 1.41 2009/08/09 23:04:16 claudio Exp $ */ +/* $OpenBSD: ospfe.h,v 1.42 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -97,7 +97,7 @@ struct nbr { /* auth.c */ int auth_validate(void *buf, u_int16_t len, struct iface *, struct nbr *); -int auth_gen(struct buf *, struct iface *); +int auth_gen(struct ibuf *, struct iface *); void md_list_add(struct auth_md_head *, u_int8_t, char *); void md_list_copy(struct auth_md_head *, struct auth_md_head *); void md_list_clr(struct auth_md_head *); @@ -233,8 +233,8 @@ struct ctl_nbr *nbr_to_ctl(struct nbr *); struct lsa_hdr *lsa_hdr_new(void); /* packet.c */ -int gen_ospf_hdr(struct buf *, struct iface *, u_int8_t); -int send_packet(struct iface *, struct buf *, struct sockaddr_in *); +int gen_ospf_hdr(struct ibuf *, struct iface *, u_int8_t); +int send_packet(struct iface *, struct ibuf *, struct sockaddr_in *); void recv_packet(int, short, void *); char *pkt_ptr; /* packet buffer */ diff --git a/usr.sbin/ospfd/packet.c b/usr.sbin/ospfd/packet.c index 5f48fc8b30d..6885a9d3cf2 100644 --- a/usr.sbin/ospfd/packet.c +++ b/usr.sbin/ospfd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.29 2010/02/16 18:04:39 claudio Exp $ */ +/* $OpenBSD: packet.c,v 1.30 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -42,7 +42,7 @@ int ospf_hdr_sanity_check(const struct ip *, struct iface *find_iface(struct ospfd_conf *, unsigned int, struct in_addr); int -gen_ospf_hdr(struct buf *buf, struct iface *iface, u_int8_t type) +gen_ospf_hdr(struct ibuf *buf, struct iface *iface, u_int8_t type) { struct ospf_hdr ospf_hdr; @@ -54,12 +54,12 @@ gen_ospf_hdr(struct buf *buf, struct iface *iface, u_int8_t type) ospf_hdr.area_id = iface->area->id.s_addr; ospf_hdr.auth_type = htons(iface->auth_type); - return (buf_add(buf, &ospf_hdr, sizeof(ospf_hdr))); + return (ibuf_add(buf, &ospf_hdr, sizeof(ospf_hdr))); } /* send and receive packets */ int -send_packet(struct iface *iface, struct buf *buf, struct sockaddr_in *dst) +send_packet(struct iface *iface, struct ibuf *buf, struct sockaddr_in *dst) { struct msghdr msg; struct iovec iov[2]; @@ -70,7 +70,7 @@ send_packet(struct iface *iface, struct buf *buf, struct sockaddr_in *dst) ip_hdr.ip_v = IPVERSION; ip_hdr.ip_hl = sizeof(ip_hdr) >> 2; ip_hdr.ip_tos = IPTOS_PREC_INTERNETCONTROL; - ip_hdr.ip_len = htons(buf_size(buf) + sizeof(ip_hdr)); + ip_hdr.ip_len = htons(ibuf_size(buf) + sizeof(ip_hdr)); ip_hdr.ip_id = 0; /* 0 means kernel set appropriate value */ ip_hdr.ip_off = 0; ip_hdr.ip_ttl = iface->type != IF_TYPE_VIRTUALLINK ? @@ -85,7 +85,7 @@ send_packet(struct iface *iface, struct buf *buf, struct sockaddr_in *dst) iov[0].iov_base = &ip_hdr; iov[0].iov_len = sizeof(ip_hdr); iov[1].iov_base = buf->buf; - iov[1].iov_len = buf_size(buf); + iov[1].iov_len = ibuf_size(buf); msg.msg_name = dst; msg.msg_namelen = sizeof(*dst); msg.msg_iov = iov; diff --git a/usr.sbin/ospfd/rde.c b/usr.sbin/ospfd/rde.c index c42abef4353..bd76d373ce0 100644 --- a/usr.sbin/ospfd/rde.c +++ b/usr.sbin/ospfd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.84 2009/11/11 07:59:10 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.85 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -738,7 +738,7 @@ rde_send_change_kroute(struct rt_node *r) int krcount = 0; struct kroute kr; struct rt_nexthop *rn; - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(&iev_main->ibuf, IMSG_KROUTE_CHANGE, 0, 0, sizeof(kr))) == NULL) { diff --git a/usr.sbin/relayd/buffer.c b/usr.sbin/relayd/buffer.c index 512afa59022..1e6d9d43b7f 100644 --- a/usr.sbin/relayd/buffer.c +++ b/usr.sbin/relayd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.22 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.23 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/relayd/check_tcp.c b/usr.sbin/relayd/check_tcp.c index f88fa8b295b..65c3734b913 100644 --- a/usr.sbin/relayd/check_tcp.c +++ b/usr.sbin/relayd/check_tcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: check_tcp.c,v 1.36 2010/02/18 14:02:16 jsg Exp $ */ +/* $OpenBSD: check_tcp.c,v 1.37 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -176,7 +176,7 @@ tcp_host_up(int s, struct ctl_tcp_event *cte) return; } - if ((cte->buf = buf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL) + if ((cte->buf = ibuf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL) fatalx("tcp_host_up: cannot create dynamic buffer"); event_again(&cte->ev, s, EV_TIMEOUT|EV_READ, tcp_read_buf, &cte->tv_start, &cte->table->conf.timeout, cte); @@ -211,7 +211,7 @@ tcp_send_req(int s, short event, void *arg) len -= bs; } while (len > 0); - if ((cte->buf = buf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL) + if ((cte->buf = ibuf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL) fatalx("tcp_send_req: cannot create dynamic buffer"); event_again(&cte->ev, s, EV_TIMEOUT|EV_READ, tcp_read_buf, &cte->tv_start, &cte->table->conf.timeout, cte); @@ -231,7 +231,7 @@ tcp_read_buf(int s, short event, void *arg) if (event == EV_TIMEOUT) { cte->host->up = HOST_DOWN; - buf_free(cte->buf); + ibuf_free(cte->buf); close(s); hce_notify_done(cte->host, HCE_TCP_READ_TIMEOUT); return; @@ -244,7 +244,7 @@ tcp_read_buf(int s, short event, void *arg) if (errno == EAGAIN || errno == EINTR) goto retry; cte->host->up = HOST_DOWN; - buf_free(cte->buf); + ibuf_free(cte->buf); close(cte->s); hce_notify_done(cte->host, HCE_TCP_READ_FAIL); return; @@ -252,18 +252,18 @@ tcp_read_buf(int s, short event, void *arg) cte->host->up = HOST_DOWN; (void)cte->validate_close(cte); close(cte->s); - buf_free(cte->buf); + ibuf_free(cte->buf); hce_notify_done(cte->host, cte->host->he); return; default: - if (buf_add(cte->buf, rbuf, br) == -1) + if (ibuf_add(cte->buf, rbuf, br) == -1) fatal("tcp_read_buf: buf_add error"); if (cte->validate_read != NULL) { if (cte->validate_read(cte) != 0) goto retry; close(cte->s); - buf_free(cte->buf); + ibuf_free(cte->buf); hce_notify_done(cte->host, cte->host->he); return; } @@ -282,7 +282,7 @@ check_send_expect(struct ctl_tcp_event *cte) /* * ensure string is nul-terminated. */ - b = buf_reserve(cte->buf, 1); + b = ibuf_reserve(cte->buf, 1); if (b == NULL) fatal("out of memory"); *b = '\0'; @@ -314,7 +314,7 @@ check_http_code(struct ctl_tcp_event *cte) /* * ensure string is nul-terminated. */ - b = buf_reserve(cte->buf, 1); + b = ibuf_reserve(cte->buf, 1); if (b == NULL) fatal("out of memory"); *b = '\0'; @@ -366,7 +366,7 @@ check_http_digest(struct ctl_tcp_event *cte) /* * ensure string is nul-terminated. */ - b = buf_reserve(cte->buf, 1); + b = ibuf_reserve(cte->buf, 1); if (b == NULL) fatal("out of memory"); *b = '\0'; diff --git a/usr.sbin/relayd/imsg.c b/usr.sbin/relayd/imsg.c index 4110ffde012..780efebc145 100644 --- a/usr.sbin/relayd/imsg.c +++ b/usr.sbin/relayd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.30 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.31 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/relayd/imsg.h b/usr.sbin/relayd/imsg.h index 983d9205d93..ba4c6863078 100644 --- a/usr.sbin/relayd/imsg.h +++ b/usr.sbin/relayd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.14 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.15 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index 751c35d81e5..a0562187c16 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.120 2010/05/14 11:13:36 reyk Exp $ */ +/* $OpenBSD: relay.c,v 1.121 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org> @@ -928,7 +928,7 @@ relay_resolve(struct ctl_relay_event *cre, struct protonode *proot, struct protonode *pn) { struct rsession *con = (struct rsession *)cre->con; - char buf[READ_BUF_SIZE], *ptr; + char buf[IBUF_READ_SIZE], *ptr; int id; if (pn->mark && (pn->mark != con->se_mark)) @@ -1072,7 +1072,7 @@ relay_handle_http(struct ctl_relay_event *cre, struct protonode *proot, struct protonode *pn, struct protonode *pk, int header) { struct rsession *con = (struct rsession *)cre->con; - char buf[READ_BUF_SIZE], *ptr; + char buf[IBUF_READ_SIZE], *ptr; int ret = PN_DROP, mark = 0; struct protonode *next; @@ -2878,8 +2878,8 @@ relay_ssl_readcb(int fd, short event, void *arg) int ret = 0, ssl_err = 0; short what = EVBUFFER_READ; size_t len; - char rbuf[READ_BUF_SIZE]; - int howmuch = READ_BUF_SIZE; + char rbuf[IBUF_READ_SIZE]; + int howmuch = IBUF_READ_SIZE; if (event == EV_TIMEOUT) { what |= EVBUFFER_TIMEOUT; diff --git a/usr.sbin/relayd/relay_udp.c b/usr.sbin/relayd/relay_udp.c index 9f75de248f9..45af8476daf 100644 --- a/usr.sbin/relayd/relay_udp.c +++ b/usr.sbin/relayd/relay_udp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay_udp.c,v 1.21 2009/08/07 11:21:53 reyk Exp $ */ +/* $OpenBSD: relay_udp.c,v 1.22 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org> @@ -178,7 +178,7 @@ relay_udp_response(int fd, short sig, void *arg) struct protocol *proto = rlay->rl_proto; void *priv = NULL; struct sockaddr_storage ss; - u_int8_t buf[READ_BUF_SIZE]; + u_int8_t buf[IBUF_READ_SIZE]; ssize_t len; socklen_t slen; @@ -216,7 +216,7 @@ relay_udp_server(int fd, short sig, void *arg) socklen_t slen; struct timeval tv; struct sockaddr_storage ss; - u_int8_t buf[READ_BUF_SIZE]; + u_int8_t buf[IBUF_READ_SIZE]; void *priv = NULL; ssize_t len; diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h index 24c86bf865b..21e3833cf05 100644 --- a/usr.sbin/relayd/relayd.h +++ b/usr.sbin/relayd/relayd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.h,v 1.135 2010/05/14 11:13:36 reyk Exp $ */ +/* $OpenBSD: relayd.h,v 1.136 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -116,7 +116,7 @@ struct ctl_icmp_event { struct ctl_tcp_event { int s; char *req; - struct buf *buf; + struct ibuf *buf; struct host *host; struct table *table; struct timeval tv_start; diff --git a/usr.sbin/relayd/ssl.c b/usr.sbin/relayd/ssl.c index 9f4081d551a..6688b2fdec8 100644 --- a/usr.sbin/relayd/ssl.c +++ b/usr.sbin/relayd/ssl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl.c,v 1.15 2009/06/04 13:46:07 reyk Exp $ */ +/* $OpenBSD: ssl.c,v 1.16 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -91,7 +91,7 @@ ssl_read(int s, short event, void *arg) } return; } - if (buf_add(cte->buf, rbuf, ret) == -1) + if (ibuf_add(cte->buf, rbuf, ret) == -1) fatal("ssl_read: buf_add error"); if (cte->validate_read != NULL) { if (cte->validate_read(cte) != 0) @@ -145,7 +145,7 @@ ssl_write(int s, short event, void *arg) return; } } - if ((cte->buf = buf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL) + if ((cte->buf = ibuf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL) fatalx("ssl_write: cannot create dynamic buffer"); event_again(&cte->ev, s, EV_TIMEOUT|EV_READ, ssl_read, @@ -204,7 +204,7 @@ ssl_connect(int s, short event, void *arg) return; } - if ((cte->buf = buf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL) + if ((cte->buf = ibuf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL) fatalx("ssl_connect: cannot create dynamic buffer"); event_again(&cte->ev, cte->s, EV_TIMEOUT|EV_READ, ssl_read, &cte->tv_start, &cte->table->conf.timeout, cte); @@ -224,7 +224,7 @@ ssl_cleanup(struct ctl_tcp_event *cte) SSL_clear(cte->ssl); } if (cte->buf != NULL) - buf_free(cte->buf); + ibuf_free(cte->buf); } void diff --git a/usr.sbin/ripd/auth.c b/usr.sbin/ripd/auth.c index 78f41169ca5..d0917d06e1e 100644 --- a/usr.sbin/ripd/auth.c +++ b/usr.sbin/ripd/auth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth.c,v 1.10 2009/09/26 11:12:50 michele Exp $ */ +/* $OpenBSD: auth.c,v 1.11 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -31,7 +31,7 @@ u_int32_t auth_calc_modulator(struct auth_md *md); struct auth_md *md_list_find(struct auth_md_head *, u_int8_t); -void auth_trailer_header_gen(struct buf *); +void auth_trailer_header_gen(struct ibuf *); u_int32_t auth_get_seq_num(struct auth_md*); u_int32_t @@ -58,13 +58,13 @@ auth_get_seq_num(struct auth_md *md) } void -auth_trailer_header_gen(struct buf *buf) +auth_trailer_header_gen(struct ibuf *buf) { u_int16_t field1 = 0xFFFF; u_int16_t field2 = htons(0x01); - buf_add(buf, &field1, sizeof(field1)); - buf_add(buf, &field2, sizeof(field2)); + ibuf_add(buf, &field1, sizeof(field1)); + ibuf_add(buf, &field2, sizeof(field2)); } /* XXX add the support for key lifetime and rollover */ @@ -184,7 +184,7 @@ auth_validate(u_int8_t **buf, u_int16_t *len, struct iface *iface, } int -auth_gen(struct buf *buf, struct iface *iface) +auth_gen(struct ibuf *buf, struct iface *iface) { struct rip_auth auth_head; struct md5_auth a; @@ -193,11 +193,11 @@ auth_gen(struct buf *buf, struct iface *iface) auth_head.auth_fixed = AUTH; auth_head.auth_type = htons(iface->auth_type); - buf_add(buf, &auth_head, sizeof(auth_head)); + ibuf_add(buf, &auth_head, sizeof(auth_head)); switch (iface->auth_type) { case AUTH_SIMPLE: - buf_add(buf, &iface->auth_key, MAX_SIMPLE_AUTH_LEN); + ibuf_add(buf, &iface->auth_key, MAX_SIMPLE_AUTH_LEN); break; case AUTH_CRYPT: if ((md = md_list_find(&iface->auth_md_list, @@ -211,7 +211,7 @@ auth_gen(struct buf *buf, struct iface *iface) a.auth_seq = htonl(auth_get_seq_num(md)); a.auth_length = MD5_DIGEST_LENGTH + AUTH_TRLR_HDR_LEN; - buf_add(buf, &a, sizeof(a)); + ibuf_add(buf, &a, sizeof(a)); break; default: log_debug("auth_gen: unknown auth type, interface %s", @@ -223,7 +223,7 @@ auth_gen(struct buf *buf, struct iface *iface) } int -auth_add_trailer(struct buf *buf, struct iface *iface) +auth_add_trailer(struct ibuf *buf, struct iface *iface) { MD5_CTX hash; u_int8_t digest[MD5_DIGEST_LENGTH]; @@ -234,7 +234,7 @@ auth_add_trailer(struct buf *buf, struct iface *iface) pos = sizeof(struct rip_hdr) + sizeof(struct rip_auth); /* add offset to header */ - a = buf_seek(buf, pos, sizeof(*a)); + a = ibuf_seek(buf, pos, sizeof(*a)); a->auth_offset = htons(buf->wpos); /* insert plaintext key */ @@ -255,7 +255,7 @@ auth_add_trailer(struct buf *buf, struct iface *iface) MD5Update(&hash, digest, MD5_DIGEST_LENGTH); MD5Final(digest, &hash); - return (buf_add(buf, digest, MD5_DIGEST_LENGTH)); + return (ibuf_add(buf, digest, MD5_DIGEST_LENGTH)); } /* md list */ diff --git a/usr.sbin/ripd/buffer.c b/usr.sbin/ripd/buffer.c index adba24d73d2..cea9406880a 100644 --- a/usr.sbin/ripd/buffer.c +++ b/usr.sbin/ripd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.5 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.6 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/ripd/imsg.c b/usr.sbin/ripd/imsg.c index 53ca8b4385a..f736a7fc429 100644 --- a/usr.sbin/ripd/imsg.c +++ b/usr.sbin/ripd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.9 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.10 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/ripd/imsg.h b/usr.sbin/ripd/imsg.h index 9fd3f2f4964..4e914c08e18 100644 --- a/usr.sbin/ripd/imsg.h +++ b/usr.sbin/ripd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.5 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.6 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/ripd/message.c b/usr.sbin/ripd/message.c index 02060cf3105..acfa3480fd5 100644 --- a/usr.sbin/ripd/message.c +++ b/usr.sbin/ripd/message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: message.c,v 1.10 2008/04/13 00:22:17 djm Exp $ */ +/* $OpenBSD: message.c,v 1.11 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -102,7 +102,7 @@ int send_triggered_update(struct iface *iface, struct rip_route *rr) { struct sockaddr_in dst; - struct buf *buf; + struct ibuf *buf; u_int16_t afi, route_tag; u_int32_t address, netmask, nexthop, metric; @@ -115,7 +115,7 @@ send_triggered_update(struct iface *iface, struct rip_route *rr) if (iface->passive) return (0); - if ((buf = buf_open(iface->mtu - sizeof(struct ip) - + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip) - sizeof(struct udphdr))) == NULL) fatal("send_triggered_update"); @@ -129,15 +129,15 @@ send_triggered_update(struct iface *iface, struct rip_route *rr) nexthop = rr->nexthop.s_addr; metric = htonl(rr->metric); - buf_add(buf, &afi, sizeof(afi)); - buf_add(buf, &route_tag, sizeof(route_tag)); - buf_add(buf, &address, sizeof(address)); - buf_add(buf, &netmask, sizeof(netmask)); - buf_add(buf, &nexthop, sizeof(nexthop)); - buf_add(buf, &metric, sizeof(metric)); + ibuf_add(buf, &afi, sizeof(afi)); + ibuf_add(buf, &route_tag, sizeof(route_tag)); + ibuf_add(buf, &address, sizeof(address)); + ibuf_add(buf, &netmask, sizeof(netmask)); + ibuf_add(buf, &nexthop, sizeof(nexthop)); + ibuf_add(buf, &metric, sizeof(metric)); send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); return (0); } @@ -145,7 +145,7 @@ send_triggered_update(struct iface *iface, struct rip_route *rr) int send_request(struct packet_head *r_list, struct iface *i, struct nbr *nbr) { - struct buf *buf; + struct ibuf *buf; struct iface *iface; struct packet_entry *entry; struct sockaddr_in dst; @@ -175,7 +175,7 @@ send_request(struct packet_head *r_list, struct iface *i, struct nbr *nbr) return (0); while (!TAILQ_EMPTY(r_list)) { - if ((buf = buf_open(iface->mtu - sizeof(struct ip) - + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip) - sizeof(struct udphdr))) == NULL) fatal("send_request"); @@ -198,12 +198,12 @@ send_request(struct packet_head *r_list, struct iface *i, struct nbr *nbr) if (metric == htonl(INFINITY) && single_entry) afi = AF_UNSPEC; - buf_add(buf, &afi, sizeof(afi)); - buf_add(buf, &route_tag, sizeof(route_tag)); - buf_add(buf, &address, sizeof(address)); - buf_add(buf, &netmask, sizeof(netmask)); - buf_add(buf, &nexthop, sizeof(nexthop)); - buf_add(buf, &metric, sizeof(metric)); + ibuf_add(buf, &afi, sizeof(afi)); + ibuf_add(buf, &route_tag, sizeof(route_tag)); + ibuf_add(buf, &address, sizeof(address)); + ibuf_add(buf, &netmask, sizeof(netmask)); + ibuf_add(buf, &nexthop, sizeof(nexthop)); + ibuf_add(buf, &metric, sizeof(metric)); TAILQ_REMOVE(r_list, entry, entry); delete_entry(entry->rr); @@ -211,7 +211,7 @@ send_request(struct packet_head *r_list, struct iface *i, struct nbr *nbr) nentries++; } send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); } return (0); @@ -220,7 +220,7 @@ send_request(struct packet_head *r_list, struct iface *i, struct nbr *nbr) int send_response(struct packet_head *r_list, struct iface *i, struct nbr *nbr) { - struct buf *buf; + struct ibuf *buf; struct iface *iface; struct packet_entry *entry; struct sockaddr_in dst; @@ -249,7 +249,7 @@ send_response(struct packet_head *r_list, struct iface *i, struct nbr *nbr) return (0); while (!TAILQ_EMPTY(r_list)) { - if ((buf = buf_open(iface->mtu - sizeof(struct ip) - + if ((buf = ibuf_open(iface->mtu - sizeof(struct ip) - sizeof(struct udphdr))) == NULL) fatal("send_response"); @@ -261,7 +261,7 @@ send_response(struct packet_head *r_list, struct iface *i, struct nbr *nbr) if (iface->auth_type != AUTH_NONE) { if (auth_gen(buf, iface) == -1) { - buf_free(buf); + ibuf_free(buf); return (-1); } nentries++; @@ -287,12 +287,12 @@ send_response(struct packet_head *r_list, struct iface *i, struct nbr *nbr) (iface->addr.s_addr & iface->mask.s_addr)) nexthop = INADDR_ANY; - buf_add(buf, &afi, sizeof(afi)); - buf_add(buf, &route_tag, sizeof(route_tag)); - buf_add(buf, &address, sizeof(address)); - buf_add(buf, &netmask, sizeof(netmask)); - buf_add(buf, &nexthop, sizeof(nexthop)); - buf_add(buf, &metric, sizeof(metric)); + ibuf_add(buf, &afi, sizeof(afi)); + ibuf_add(buf, &route_tag, sizeof(route_tag)); + ibuf_add(buf, &address, sizeof(address)); + ibuf_add(buf, &netmask, sizeof(netmask)); + ibuf_add(buf, &nexthop, sizeof(nexthop)); + ibuf_add(buf, &metric, sizeof(metric)); free: TAILQ_REMOVE(r_list, entry, entry); delete_entry(entry->rr); @@ -304,7 +304,7 @@ free: auth_add_trailer(buf, iface); send_packet(iface, buf->buf, buf->wpos, &dst); - buf_free(buf); + ibuf_free(buf); } return (0); diff --git a/usr.sbin/ripd/packet.c b/usr.sbin/ripd/packet.c index 7447baee48c..4d7b07a3d1f 100644 --- a/usr.sbin/ripd/packet.c +++ b/usr.sbin/ripd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.10 2008/03/24 16:11:05 deraadt Exp $ */ +/* $OpenBSD: packet.c,v 1.11 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -43,7 +43,7 @@ int rip_hdr_sanity_check(struct rip_hdr *); struct iface *find_iface(struct ripd_conf *, unsigned int, struct in_addr); int -gen_rip_hdr(struct buf *buf, u_int8_t command) +gen_rip_hdr(struct ibuf *buf, u_int8_t command) { struct rip_hdr rip_hdr; @@ -51,7 +51,7 @@ gen_rip_hdr(struct buf *buf, u_int8_t command) rip_hdr.version = RIP_VERSION; rip_hdr.command = command; - return (buf_add(buf, &rip_hdr, sizeof(rip_hdr))); + return (ibuf_add(buf, &rip_hdr, sizeof(rip_hdr))); } /* send and receive packets */ @@ -107,7 +107,7 @@ recv_packet(int fd, short event, void *bula) bzero(&msg, sizeof(msg)); iov.iov_base = buf; - iov.iov_len = READ_BUF_SIZE; + iov.iov_len = IBUF_READ_SIZE; msg.msg_name = &src; msg.msg_namelen = sizeof(src); msg.msg_iov = &iov; diff --git a/usr.sbin/ripd/ripe.c b/usr.sbin/ripd/ripe.c index 2d6f4f584c3..6e0ebac7a2f 100644 --- a/usr.sbin/ripd/ripe.c +++ b/usr.sbin/ripd/ripe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ripe.c,v 1.12 2009/06/06 08:20:55 eric Exp $ */ +/* $OpenBSD: ripe.c,v 1.13 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -184,7 +184,7 @@ ripe(struct ripd_conf *xconf, int pipe_parent2ripe[2], int pipe_ripe2rde[2], TAILQ_INIT(&ctl_conns); control_listen(); - if ((pkt_ptr = calloc(1, READ_BUF_SIZE)) == NULL) + if ((pkt_ptr = calloc(1, IBUF_READ_SIZE)) == NULL) fatal("ripe"); /* start interfaces */ diff --git a/usr.sbin/ripd/ripe.h b/usr.sbin/ripd/ripe.h index 7514d6baad9..8b624fc525f 100644 --- a/usr.sbin/ripd/ripe.h +++ b/usr.sbin/ripd/ripe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ripe.h,v 1.9 2008/12/17 14:19:39 michele Exp $ */ +/* $OpenBSD: ripe.h,v 1.10 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -76,7 +76,7 @@ struct nbr { /* packet.c */ int send_packet(struct iface *, void *, size_t, struct sockaddr_in *); void recv_packet(int, short, void *); -int gen_rip_hdr(struct buf *, u_int8_t); +int gen_rip_hdr(struct ibuf *, u_int8_t); /* interface.c */ void if_init(struct ripd_conf *, struct iface *); @@ -120,8 +120,8 @@ void ripe_demote_iface(struct iface *, int); /* auth.c */ int auth_validate(u_int8_t **, u_int16_t *, struct iface *, struct nbr *, struct nbr_failed *, u_int32_t *); -int auth_gen(struct buf *, struct iface *); -int auth_add_trailer(struct buf *, struct iface *); +int auth_gen(struct ibuf *, struct iface *); +int auth_add_trailer(struct ibuf *, struct iface *); int md_list_add(struct auth_md_head *, u_int8_t, char *); void md_list_copy(struct auth_md_head *, struct auth_md_head *); void md_list_clr(struct auth_md_head *); diff --git a/usr.sbin/smtpd/buffer.c b/usr.sbin/smtpd/buffer.c index 96661c33723..bacec4a2163 100644 --- a/usr.sbin/smtpd/buffer.c +++ b/usr.sbin/smtpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.6 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.7 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/smtpd/client.c b/usr.sbin/smtpd/client.c index 0ea810abd34..538f514e364 100644 --- a/usr.sbin/smtpd/client.c +++ b/usr.sbin/smtpd/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.26 2010/01/02 16:41:19 jacekm Exp $ */ +/* $OpenBSD: client.c,v 1.27 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net> @@ -48,7 +48,7 @@ int client_use_extensions(struct smtp_client *); void client_status(struct smtp_client *, char *, ...); int client_getln(struct smtp_client *, int); void client_putln(struct smtp_client *, char *, ...); -struct buf *client_content_read(FILE *, size_t); +struct ibuf *client_content_read(FILE *, size_t); int client_poll(struct smtp_client *); void client_quit(struct smtp_client *); @@ -58,12 +58,12 @@ int client_socket_write(struct smtp_client *); #ifndef CLIENT_NO_SSL int client_ssl_connect(struct smtp_client *); SSL *ssl_client_init(int, char *, size_t, char *, size_t); -int ssl_buf_read(SSL *, struct buf_read *); +int ssl_buf_read(SSL *, struct ibuf_read *); int ssl_buf_write(SSL *, struct msgbuf *); #endif -char *buf_getln(struct buf_read *); -int buf_read(int, struct buf_read *); +char *buf_getln(struct ibuf_read *); +int buf_read(int, struct ibuf_read *); void log_debug(const char *, ...); /* XXX */ void fatal(const char *); /* XXX */ @@ -265,7 +265,7 @@ client_printf(struct smtp_client *sp, char *fmt, ...) int len; if (sp->head == NULL) - sp->head = buf_dynamic(0, SIZE_T_MAX); + sp->head = ibuf_dynamic(0, SIZE_T_MAX); if (sp->head == NULL) fatal(NULL); @@ -282,11 +282,11 @@ client_printf(struct smtp_client *sp, char *fmt, ...) /* split into lines, deal with dot escaping etc. */ tmp = p; while ((ln = strsep(&tmp, "\n"))) { - if (*ln == '.' && buf_add(sp->head, ".", 1)) + if (*ln == '.' && ibuf_add(sp->head, ".", 1)) fatal(NULL); - if (buf_add(sp->head, ln, strlen(ln))) + if (ibuf_add(sp->head, ln, strlen(ln))) fatal(NULL); - if (buf_add(sp->head, "\r\n", 2)) + if (ibuf_add(sp->head, "\r\n", 2)) fatal(NULL); } @@ -475,7 +475,7 @@ client_write(struct smtp_client *sp) int ret; if (sp->content) { - buf_close(&sp->w, sp->content); + ibuf_close(&sp->w, sp->content); sp->content = client_content_read(sp->body, sp->sndlowat); } else { while (sp->cmdi < sp->cmdw) { @@ -579,9 +579,9 @@ client_close(struct smtp_client *sp) free(sp->auth.cert); free(sp->auth.key); if (sp->head) - buf_free(sp->head); + ibuf_free(sp->head); if (sp->content) - buf_free(sp->content); + ibuf_free(sp->content); msgbuf_clear(&sp->w); while ((cmd = TAILQ_FIRST(&sp->cmdsendq))) { TAILQ_REMOVE(&sp->cmdsendq, cmd, entry); @@ -745,7 +745,7 @@ done: void client_putln(struct smtp_client *sp, char *fmt, ...) { - struct buf *cmd = NULL; + struct ibuf *cmd = NULL; char *p = NULL; int len; va_list ap; @@ -757,13 +757,13 @@ client_putln(struct smtp_client *sp, char *fmt, ...) fprintf(sp->verbose, ">>> %s\n", p); - if ((cmd = buf_open(len + 2)) == NULL) + if ((cmd = ibuf_open(len + 2)) == NULL) fatal(NULL); - if (buf_add(cmd, p, len)) + if (ibuf_add(cmd, p, len)) fatal(NULL); - if (buf_add(cmd, "\r\n", 2)) + if (ibuf_add(cmd, "\r\n", 2)) fatal(NULL); - buf_close(&sp->w, cmd); + ibuf_close(&sp->w, cmd); free(p); } @@ -771,32 +771,32 @@ client_putln(struct smtp_client *sp, char *fmt, ...) /* * Put chunk of message content to output buffer. */ -struct buf * +struct ibuf * client_content_read(FILE *fp, size_t max) { - struct buf *b; + struct ibuf *b; char *ln; size_t len; - if ((b = buf_dynamic(0, SIZE_T_MAX)) == NULL) + if ((b = ibuf_dynamic(0, SIZE_T_MAX)) == NULL) fatal(NULL); - while (buf_size(b) < max) { + while (ibuf_size(b) < max) { if ((ln = fgetln(fp, &len)) == NULL) break; if (ln[len - 1] == '\n') len--; - if (*ln == '.' && buf_add(b, ".", 1)) + if (*ln == '.' && ibuf_add(b, ".", 1)) fatal(NULL); - if (buf_add(b, ln, len)) + if (ibuf_add(b, ln, len)) fatal(NULL); - if (buf_add(b, "\r\n", 2)) + if (ibuf_add(b, "\r\n", 2)) fatal(NULL); } if (ferror(fp)) fatal("client_body: fgetln"); - if (feof(fp) && buf_size(b) == 0) { - buf_free(b); + if (feof(fp) && ibuf_size(b) == 0) { + ibuf_free(b); b = NULL; } @@ -890,7 +890,7 @@ client_socket_write(struct smtp_client *sp) } #endif if (sp->ssl == NULL) { - if (buf_write(&sp->w) < 0) { + if (ibuf_write(&sp->w) < 0) { client_status(sp, "130 buf_write error"); return (CLIENT_DONE); } @@ -903,7 +903,7 @@ client_socket_write(struct smtp_client *sp) * Read a full line from the read buffer. */ char * -buf_getln(struct buf_read *r) +buf_getln(struct ibuf_read *r) { char *buf = r->buf, *line; size_t bufsz = r->wpos, i; @@ -935,7 +935,7 @@ buf_getln(struct buf_read *r) * I/O routine for reading UNIX socket. */ int -buf_read(int fd, struct buf_read *r) +buf_read(int fd, struct ibuf_read *r) { char *buf = r->buf + r->wpos; size_t bufsz = sizeof(r->buf) - r->wpos; diff --git a/usr.sbin/smtpd/client.h b/usr.sbin/smtpd/client.h index 34fa90bed34..1574fbd329e 100644 --- a/usr.sbin/smtpd/client.h +++ b/usr.sbin/smtpd/client.h @@ -1,4 +1,4 @@ -/* $OpenBSD: client.h,v 1.11 2010/01/02 16:41:19 jacekm Exp $ */ +/* $OpenBSD: client.h,v 1.12 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net> @@ -86,15 +86,15 @@ struct smtp_client { void *rcptfail; char *ehlo; char reply[1024]; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; void *ssl; int sndlowat; struct timeval timeout; FILE *verbose; - struct buf *content; /* current chunk of content */ - struct buf *head; /* headers + part of body */ + struct ibuf *content; /* current chunk of content */ + struct ibuf *head; /* headers + part of body */ FILE *body; /* rest of body */ struct client_ext exts[3]; diff --git a/usr.sbin/smtpd/imsg.c b/usr.sbin/smtpd/imsg.c index 1d48703bfcc..97ca2c3c26a 100644 --- a/usr.sbin/smtpd/imsg.c +++ b/usr.sbin/smtpd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.12 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.13 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/smtpd/imsg.h b/usr.sbin/smtpd/imsg.h index c1a279dbdd5..47ccd8d27b8 100644 --- a/usr.sbin/smtpd/imsg.h +++ b/usr.sbin/smtpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.7 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.8 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c index 006a896f5cb..a91e540295c 100644 --- a/usr.sbin/smtpd/mda.c +++ b/usr.sbin/smtpd/mda.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mda.c,v 1.43 2010/04/21 18:54:43 jacekm Exp $ */ +/* $OpenBSD: mda.c,v 1.44 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -341,7 +341,7 @@ void mda_store(struct mda_session *s) { char *p; - struct buf *buf; + struct ibuf *buf; int len; if (s->msg.sender.user[0] && s->msg.sender.domain[0]) @@ -357,11 +357,11 @@ mda_store(struct mda_session *s) fatal("mda_store: asprintf"); session_socket_blockmode(s->w.fd, BM_NONBLOCK); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) fatal(NULL); - if (buf_add(buf, p, len) < 0) + if (ibuf_add(buf, p, len) < 0) fatal(NULL); - buf_close(&s->w, buf); + ibuf_close(&s->w, buf); event_set(&s->ev, s->w.fd, EV_WRITE, mda_store_event, s); event_add(&s->ev, NULL); free(p); @@ -372,11 +372,11 @@ mda_store_event(int fd, short event, void *p) { char tmp[16384]; struct mda_session *s = p; - struct buf *buf; + struct ibuf *buf; size_t len; if (s->w.queued == 0) { - if ((buf = buf_dynamic(0, sizeof tmp)) == NULL) + if ((buf = ibuf_dynamic(0, sizeof tmp)) == NULL) fatal(NULL); len = fread(tmp, 1, sizeof tmp, s->datafp); if (ferror(s->datafp)) @@ -386,12 +386,12 @@ mda_store_event(int fd, short event, void *p) s->w.fd = -1; return; } - if (buf_add(buf, tmp, len) < 0) + if (ibuf_add(buf, tmp, len) < 0) fatal(NULL); - buf_close(&s->w, buf); + ibuf_close(&s->w, buf); } - if (buf_write(&s->w) < 0) { + if (ibuf_write(&s->w) < 0) { close(s->w.fd); s->w.fd = -1; return; diff --git a/usr.sbin/smtpd/ssl.c b/usr.sbin/smtpd/ssl.c index 02a74762688..edd89acf730 100644 --- a/usr.sbin/smtpd/ssl.c +++ b/usr.sbin/smtpd/ssl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl.c,v 1.24 2010/05/19 20:57:10 gilles Exp $ */ +/* $OpenBSD: ssl.c,v 1.25 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -52,7 +52,7 @@ void ssl_connect(int, short, void *); SSL *ssl_client_init(int, char *, size_t, char *, size_t); -int ssl_buf_read(SSL *, struct buf_read *); +int ssl_buf_read(SSL *, struct ibuf_read *); int ssl_buf_write(SSL *, struct msgbuf *); DH *get_dh512(void); @@ -151,8 +151,8 @@ ssl_read(int fd, short event, void *p) int ssl_err; short what; size_t len; - char rbuf[READ_BUF_SIZE]; - int howmuch = READ_BUF_SIZE; + char rbuf[IBUF_READ_SIZE]; + int howmuch = IBUF_READ_SIZE; what = EVBUFFER_READ; ret = ssl_err = 0; @@ -653,7 +653,7 @@ ssl_session_destroy(struct session *s) } int -ssl_buf_read(SSL *s, struct buf_read *r) +ssl_buf_read(SSL *s, struct ibuf_read *r) { char *buf = r->buf + r->wpos; ssize_t bufsz = sizeof(r->buf) - r->wpos; @@ -673,7 +673,7 @@ ssl_buf_read(SSL *s, struct buf_read *r) int ssl_buf_write(SSL *s, struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; int ret; buf = TAILQ_FIRST(&msgbuf->bufs); diff --git a/usr.sbin/snmpd/buffer.c b/usr.sbin/snmpd/buffer.c index 214cc25109d..698827a348f 100644 --- a/usr.sbin/snmpd/buffer.c +++ b/usr.sbin/snmpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.9 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.10 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/snmpd/imsg.c b/usr.sbin/snmpd/imsg.c index 1d48703bfcc..97ca2c3c26a 100644 --- a/usr.sbin/snmpd/imsg.c +++ b/usr.sbin/snmpd/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.12 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.13 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/snmpd/imsg.h b/usr.sbin/snmpd/imsg.h index 9fd3f2f4964..4e914c08e18 100644 --- a/usr.sbin/snmpd/imsg.h +++ b/usr.sbin/snmpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.5 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.6 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/ypldap/buffer.c b/usr.sbin/ypldap/buffer.c index 603a53d60ff..35abba95542 100644 --- a/usr.sbin/ypldap/buffer.c +++ b/usr.sbin/ypldap/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ +/* $OpenBSD: buffer.c,v 1.5 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,16 +28,16 @@ #include "imsg.h" -int buf_realloc(struct buf *, size_t); -void buf_enqueue(struct msgbuf *, struct buf *); -void buf_dequeue(struct msgbuf *, struct buf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct buf * -buf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct buf *buf; + struct ibuf *buf; - if ((buf = calloc(1, sizeof(struct buf))) == NULL) + if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); @@ -49,15 +49,15 @@ buf_open(size_t len) return (buf); } -struct buf * -buf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct buf *buf; + struct ibuf *buf; if (max < len) return (NULL); - if ((buf = buf_open(len)) == NULL) + if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) @@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max) } int -buf_realloc(struct buf *buf, size_t len) +ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; @@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len) } int -buf_add(struct buf *buf, const void *data, size_t len) +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); @@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len) } void * -buf_reserve(struct buf *buf, size_t len) +ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) - if (buf_realloc(buf, len) == -1) + if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; @@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len) } void * -buf_seek(struct buf *buf, size_t pos, size_t len) +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len) } size_t -buf_size(struct buf *buf) +ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t -buf_left(struct buf *buf) +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void -buf_close(struct msgbuf *msgbuf, struct buf *buf) +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { - buf_enqueue(msgbuf, buf); + ibuf_enqueue(msgbuf, buf); } int -buf_write(struct msgbuf *msgbuf) +ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; @@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf) } void -buf_free(struct buf *buf) +ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); @@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf) void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct buf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; @@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n) void msgbuf_clear(struct msgbuf *msgbuf) { - struct buf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - buf_dequeue(msgbuf, buf); + ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf; + struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf) } void -buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void -buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); @@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) close(buf->fd); msgbuf->queued--; - buf_free(buf); + ibuf_free(buf); } diff --git a/usr.sbin/ypldap/imsg.c b/usr.sbin/ypldap/imsg.c index 21d54c0d05e..285e69221c1 100644 --- a/usr.sbin/ypldap/imsg.c +++ b/usr.sbin/ypldap/imsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.c,v 1.10 2010/04/07 18:09:39 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.11 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -135,7 +135,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -154,7 +154,7 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct buf *wbuf; + struct ibuf *wbuf; int i, datalen = 0; for (i = 0; i < iovcnt; i++) @@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct buf * +struct ibuf * imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, pid_t pid, u_int16_t datalen) { - struct buf *wbuf; + struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; @@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, hdr.peerid = peerid; if ((hdr.pid = pid) == 0) hdr.pid = ibuf->pid; - if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { + if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) @@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } int -imsg_add(struct buf *msg, void *data, u_int16_t datalen) +imsg_add(struct ibuf *msg, void *data, u_int16_t datalen) { if (datalen) - if (buf_add(msg, data, datalen) == -1) { - buf_free(msg); + if (ibuf_add(msg, data, datalen) == -1) { + ibuf_free(msg); return (-1); } return (datalen); } void -imsg_close(struct imsgbuf *ibuf, struct buf *msg) +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { struct imsg_hdr *hdr; @@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg) hdr->len = (u_int16_t)msg->wpos; - buf_close(&ibuf->w, msg); + ibuf_close(&ibuf->w, msg); } void diff --git a/usr.sbin/ypldap/imsg.h b/usr.sbin/ypldap/imsg.h index 9fd3f2f4964..4e914c08e18 100644 --- a/usr.sbin/ypldap/imsg.h +++ b/usr.sbin/ypldap/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.5 2010/04/27 21:04:04 nicm Exp $ */ +/* $OpenBSD: imsg.h,v 1.6 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -18,12 +18,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define READ_BUF_SIZE 65535 +#define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 -struct buf { - TAILQ_ENTRY(buf) entry; +struct ibuf { + TAILQ_ENTRY(ibuf) entry; u_char *buf; size_t size; size_t max; @@ -33,13 +33,13 @@ struct buf { }; struct msgbuf { - TAILQ_HEAD(, buf) bufs; + TAILQ_HEAD(, ibuf) bufs; u_int32_t queued; int fd; }; -struct buf_read { - u_char buf[READ_BUF_SIZE]; +struct ibuf_read { + u_char buf[IBUF_READ_SIZE]; u_char *rptr; size_t wpos; }; @@ -51,7 +51,7 @@ struct imsg_fd { struct imsgbuf { TAILQ_HEAD(, imsg_fd) fds; - struct buf_read r; + struct ibuf_read r; struct msgbuf w; int fd; pid_t pid; @@ -75,16 +75,16 @@ struct imsg { /* buffer.c */ -struct buf *buf_open(size_t); -struct buf *buf_dynamic(size_t, size_t); -int buf_add(struct buf *, const void *, size_t); -void *buf_reserve(struct buf *, size_t); -void *buf_seek(struct buf *, size_t, size_t); -size_t buf_size(struct buf *); -size_t buf_left(struct buf *); -void buf_close(struct msgbuf *, struct buf *); -int buf_write(struct msgbuf *); -void buf_free(struct buf *); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); @@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, void *, u_int16_t); int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, const struct iovec *, int); -struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, +struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, u_int16_t); -int imsg_add(struct buf *, void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct buf *); +int imsg_add(struct ibuf *, void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); diff --git a/usr.sbin/ypldap/ypldap_dns.c b/usr.sbin/ypldap/ypldap_dns.c index 4b03e78e9f0..105160de89c 100644 --- a/usr.sbin/ypldap/ypldap_dns.c +++ b/usr.sbin/ypldap/ypldap_dns.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypldap_dns.c,v 1.3 2010/04/01 18:24:04 zinovik Exp $ */ +/* $OpenBSD: ypldap_dns.c,v 1.4 2010/05/26 13:56:08 nicm Exp $ */ /* * Copyright (c) 2003-2008 Henning Brauer <henning@openbsd.org> @@ -128,7 +128,7 @@ dns_dispatch_imsg(int fd, short event, void *p) int n, cnt; char *name; struct ypldap_addr *h, *hn; - struct buf *buf; + struct ibuf *buf; struct env *env = p; struct imsgev *iev = env->sc_iev; struct imsgbuf *ibuf = &iev->ibuf; |