diff --git a/nhrpd/zbuf.c b/nhrpd/zbuf.c index e191a90f2d..9cc2b56245 100644 --- a/nhrpd/zbuf.c +++ b/nhrpd/zbuf.c @@ -164,35 +164,33 @@ void *zbuf_may_pull_until(struct zbuf *zb, const char *sep, struct zbuf *msg) void zbufq_init(struct zbuf_queue *zbq) { *zbq = (struct zbuf_queue){ - .queue_head = LIST_INITIALIZER(zbq->queue_head), + .queue_head = INIT_DLIST(zbq->queue_head), }; } void zbufq_reset(struct zbuf_queue *zbq) { - struct zbuf *buf, *bufn; + struct zbuf *buf; - list_for_each_entry_safe(buf, bufn, &zbq->queue_head, queue_list) - { - list_del(&buf->queue_list); + frr_each_safe (zbuf_queue, &zbq->queue_head, buf) { + zbuf_queue_del(&zbq->queue_head, buf); zbuf_free(buf); } } void zbufq_queue(struct zbuf_queue *zbq, struct zbuf *zb) { - list_add_tail(&zb->queue_list, &zbq->queue_head); + zbuf_queue_add_tail(&zbq->queue_head, zb); } int zbufq_write(struct zbuf_queue *zbq, int fd) { struct iovec iov[16]; - struct zbuf *zb, *zbn; + struct zbuf *zb; ssize_t r; size_t iovcnt = 0; - list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list) - { + frr_each_safe (zbuf_queue, &zbq->queue_head, zb) { iov[iovcnt++] = (struct iovec){ .iov_base = zb->head, .iov_len = zbuf_used(zb), }; @@ -204,15 +202,14 @@ int zbufq_write(struct zbuf_queue *zbq, int fd) if (r < 0) return r; - list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list) - { + frr_each_safe (zbuf_queue, &zbq->queue_head, zb) { if (r < (ssize_t)zbuf_used(zb)) { zb->head += r; return 1; } r -= zbuf_used(zb); - list_del(&zb->queue_list); + zbuf_queue_del(&zbq->queue_head, zb); zbuf_free(zb); } diff --git a/nhrpd/zbuf.h b/nhrpd/zbuf.h index 2741860bfd..d036b10460 100644 --- a/nhrpd/zbuf.h +++ b/nhrpd/zbuf.h @@ -15,18 +15,22 @@ #include #include -#include "list.h" +#include "typesafe.h" + +PREDECL_DLIST(zbuf_queue); struct zbuf { - struct list_head queue_list; + struct zbuf_queue_item queue_entry; unsigned allocated : 1; unsigned error : 1; uint8_t *buf, *end; uint8_t *head, *tail; }; +DECLARE_DLIST(zbuf_queue, struct zbuf, queue_entry); + struct zbuf_queue { - struct list_head queue_head; + struct zbuf_queue_head queue_head; }; struct zbuf *zbuf_alloc(size_t size);