diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-01-31 11:44:50 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-01-31 11:44:50 +0000 |
commit | aab8bd8146ab6ed527a15237258b32eea04587ab (patch) | |
tree | 48d81fe534d0fc5c7f36bd2ebea50d0de2f90692 /usr.sbin/ospfd | |
parent | eb527a8af6bced89a36bf8d8a2c6417207e3bdf0 (diff) |
Implement buf_left() to make some some more buffer handling easier.
buf_left() returns the bytes left in a buffer. This makes the check to
keep MD5_DIGEST_LENGTH bytes unallocated in some messages easier.
From the buf cleanup diff that was OK norby@ and henning@
Diffstat (limited to 'usr.sbin/ospfd')
-rw-r--r-- | usr.sbin/ospfd/buffer.c | 8 | ||||
-rw-r--r-- | usr.sbin/ospfd/database.c | 6 | ||||
-rw-r--r-- | usr.sbin/ospfd/lsreq.c | 6 | ||||
-rw-r--r-- | usr.sbin/ospfd/lsupdate.c | 12 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.h | 3 |
5 files changed, 21 insertions, 14 deletions
diff --git a/usr.sbin/ospfd/buffer.c b/usr.sbin/ospfd/buffer.c index 3d5c69d6623..87890529185 100644 --- a/usr.sbin/ospfd/buffer.c +++ b/usr.sbin/ospfd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.9 2008/10/03 15:20:29 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.10 2009/01/31 11:44:49 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -121,6 +121,12 @@ buf_seek(struct buf *buf, size_t pos, size_t len) return (buf->buf + pos); } +size_t +buf_left(struct buf *buf) +{ + return (buf->max - buf->wpos); +} + int buf_close(struct msgbuf *msgbuf, struct buf *buf) { diff --git a/usr.sbin/ospfd/database.c b/usr.sbin/ospfd/database.c index 27634437968..960c39c9e12 100644 --- a/usr.sbin/ospfd/database.c +++ b/usr.sbin/ospfd/database.c @@ -1,4 +1,4 @@ -/* $OpenBSD: database.c,v 1.25 2009/01/31 08:55:00 claudio Exp $ */ +/* $OpenBSD: database.c,v 1.26 2009/01/31 11:44:49 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -91,8 +91,8 @@ 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->wpos + sizeof(struct lsa_hdr) < buf->max - - MD5_DIGEST_LENGTH; le = nle) { + buf_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))) goto fail; diff --git a/usr.sbin/ospfd/lsreq.c b/usr.sbin/ospfd/lsreq.c index a7cc9358c43..757e1f0ca4f 100644 --- a/usr.sbin/ospfd/lsreq.c +++ b/usr.sbin/ospfd/lsreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsreq.c,v 1.15 2009/01/31 08:55:00 claudio Exp $ */ +/* $OpenBSD: lsreq.c,v 1.16 2009/01/31 11:44:49 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -66,8 +66,8 @@ 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->wpos + sizeof(struct ls_req_hdr) < buf->max - - MD5_DIGEST_LENGTH; le = nle) { + buf_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; diff --git a/usr.sbin/ospfd/lsupdate.c b/usr.sbin/ospfd/lsupdate.c index de564db2da6..ee9a67552b0 100644 --- a/usr.sbin/ospfd/lsupdate.c +++ b/usr.sbin/ospfd/lsupdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsupdate.c,v 1.34 2009/01/31 08:55:00 claudio Exp $ */ +/* $OpenBSD: lsupdate.c,v 1.35 2009/01/31 11:44:49 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -173,13 +173,13 @@ int add_ls_update(struct buf *buf, struct iface *iface, void *data, int len, u_int16_t older) { - size_t pos; - u_int16_t age; + void *lsage; + u_int16_t age; - if (buf->wpos + len >= buf->max - MD5_DIGEST_LENGTH) + if (buf_left(buf) < MD5_DIGEST_LENGTH) return (0); - pos = buf->wpos; + lsage = buf_reserve(buf, 0); if (buf_add(buf, data, len)) { log_warn("add_ls_update"); return (0); @@ -191,7 +191,7 @@ 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(lsage, &age, sizeof(age)); return (1); } diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index 2b63edb9e21..b164d1d674f 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.74 2009/01/07 21:16:36 claudio Exp $ */ +/* $OpenBSD: ospfd.h,v 1.75 2009/01/31 11:44:49 claudio Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -561,6 +561,7 @@ struct buf *buf_dynamic(size_t, size_t); int buf_add(struct buf *, void *, size_t); void *buf_reserve(struct buf *, size_t); void *buf_seek(struct buf *, size_t, size_t); +size_t buf_left(struct buf *); int buf_close(struct msgbuf *, struct buf *); void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); |