]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/imsg-buffer.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / imsg-buffer.c
index 4068e31c51c009cd9c021e6c1b0a2ac4af89b616..c2f4052b8f5ea66be9be7b5f3cfdcba19cc570a7 100644 (file)
 
 #include <zebra.h>
 
-#include "openbsd-queue.h"
+#include "queue.h"
 #include "imsg.h"
 
-int ibuf_realloc(struct ibuf *, size_t);
-void ibuf_enqueue(struct msgbuf *, struct ibuf *);
-void ibuf_dequeue(struct msgbuf *, struct ibuf *);
+static int ibuf_realloc(struct ibuf *, size_t);
+static void ibuf_enqueue(struct msgbuf *, struct ibuf *);
+static void ibuf_dequeue(struct msgbuf *, struct ibuf *);
 
 struct ibuf *ibuf_open(size_t len)
 {
@@ -57,9 +57,9 @@ struct ibuf *ibuf_dynamic(size_t len, size_t max)
        return (buf);
 }
 
-int ibuf_realloc(struct ibuf *buf, size_t len)
+static int ibuf_realloc(struct ibuf *buf, size_t len)
 {
-       u_char *b;
+       uint8_t *b;
 
        /* on static buffers max is eq size and so the following fails */
        if (buf->wpos + len > buf->max) {
@@ -132,8 +132,7 @@ int ibuf_write(struct msgbuf *msgbuf)
        ssize_t n;
 
        memset(&iov, 0, sizeof(iov));
-       TAILQ_FOREACH(buf, &msgbuf->bufs, entry)
-       {
+       TAILQ_FOREACH (buf, &msgbuf->bufs, entry) {
                if (i >= IOV_MAX)
                        break;
                iov[i].iov_base = buf->buf + buf->rpos;
@@ -184,6 +183,8 @@ void msgbuf_drain(struct msgbuf *msgbuf, size_t n)
                next = TAILQ_NEXT(buf, entry);
                if (buf->rpos + n >= buf->wpos) {
                        n -= buf->wpos - buf->rpos;
+
+                       TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
                        ibuf_dequeue(msgbuf, buf);
                } else {
                        buf->rpos += n;
@@ -196,7 +197,7 @@ void msgbuf_clear(struct msgbuf *msgbuf)
 {
        struct ibuf *buf;
 
-       while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL)
+       while ((buf = TAILQ_POP_FIRST(&msgbuf->bufs, entry)) != NULL)
                ibuf_dequeue(msgbuf, buf);
 }
 
@@ -216,8 +217,7 @@ int msgbuf_write(struct msgbuf *msgbuf)
        memset(&iov, 0, sizeof(iov));
        memset(&msg, 0, sizeof(msg));
        memset(&cmsgbuf, 0, sizeof(cmsgbuf));
-       TAILQ_FOREACH(buf, &msgbuf->bufs, entry)
-       {
+       TAILQ_FOREACH (buf, &msgbuf->bufs, entry) {
                if (i >= IOV_MAX)
                        break;
                iov[i].iov_base = buf->buf + buf->rpos;
@@ -268,16 +268,15 @@ again:
        return (1);
 }
 
-void ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf)
+static void ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf)
 {
        TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);
        msgbuf->queued++;
 }
 
-void ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf)
+static void ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf)
 {
-       TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
-
+       /* TAILQ_REMOVE done by caller */
        if (buf->fd != -1)
                close(buf->fd);