]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/imsg.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / imsg.c
index 10650f648af56da8124fc3cd5e43c356b339ae14..935d13772752a2a668fc4d9699793c4addd7845a 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <zebra.h>
 
-#include "openbsd-queue.h"
+#include "queue.h"
 #include "imsg.h"
 
 int imsg_fd_overhead = 0;
@@ -77,7 +77,7 @@ ssize_t imsg_read(struct imsgbuf *ibuf)
                char buf[CMSG_SPACE(sizeof(int) * 1)];
        } cmsgbuf;
        struct iovec iov;
-       ssize_t n = -1;
+       ssize_t n;
        int fd;
        struct imsg_fd *ifd;
 
@@ -110,7 +110,8 @@ again:
                return (-1);
        }
 
-       if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
+       n = recvmsg(ibuf->fd, &msg, 0);
+       if (n == -1) {
                if (errno == EINTR)
                        goto again;
                goto fail;
@@ -193,8 +194,8 @@ ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
        return (datalen + IMSG_HEADER_SIZE);
 }
 
-int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
-                pid_t pid, int fd, const void *data, u_int16_t datalen)
+int imsg_compose(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid,
+                pid_t pid, int fd, const void *data, uint16_t datalen)
 {
        struct ibuf *wbuf;
 
@@ -211,7 +212,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
        return (1);
 }
 
-int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
+int imsg_composev(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid,
                  pid_t pid, int fd, const struct iovec *iov, int iovcnt)
 {
        struct ibuf *wbuf;
@@ -235,12 +236,14 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
 }
 
 /* ARGSUSED */
-struct ibuf *imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
-                        pid_t pid, u_int16_t datalen)
+struct ibuf *imsg_create(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid,
+                        pid_t pid, uint16_t datalen)
 {
        struct ibuf *wbuf;
        struct imsg_hdr hdr;
 
+       memset(&hdr, 0x00, IMSG_HEADER_SIZE);
+
        datalen += IMSG_HEADER_SIZE;
        if (datalen > MAX_IMSGSIZE) {
                errno = ERANGE;
@@ -261,7 +264,7 @@ struct ibuf *imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
        return (wbuf);
 }
 
-int imsg_add(struct ibuf *msg, const void *data, u_int16_t datalen)
+int imsg_add(struct ibuf *msg, const void *data, uint16_t datalen)
 {
        if (datalen)
                if (ibuf_add(msg, data, datalen) == -1) {
@@ -281,7 +284,7 @@ void imsg_close(struct imsgbuf *ibuf, struct ibuf *msg)
        if (msg->fd != -1)
                hdr->flags |= IMSGF_HASFD;
 
-       hdr->len = (u_int16_t)msg->wpos;
+       hdr->len = (uint16_t)msg->wpos;
 
        ibuf_close(&ibuf->w, msg);
 }
@@ -296,11 +299,10 @@ int imsg_get_fd(struct imsgbuf *ibuf)
        int fd;
        struct imsg_fd *ifd;
 
-       if ((ifd = TAILQ_FIRST(&ibuf->fds)) == NULL)
+       if ((ifd = TAILQ_POP_FIRST(&ibuf->fds, entry)) == NULL)
                return (-1);
 
        fd = ifd->fd;
-       TAILQ_REMOVE(&ibuf->fds, ifd, entry);
        free(ifd);
 
        return (fd);