]> git.proxmox.com Git - mirror_frr.git/commitdiff
bfdd: fix alpine build
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 14 Aug 2018 18:10:25 +0000 (15:10 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 14 Aug 2018 20:52:14 +0000 (17:52 -0300)
Move `recvmsg` parameter option initialization to function, initialize
the parameter struct with zeroes and access field by name.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
bfdd/bfd_packet.c

index 19cb8547ab3368a936018fa40d52a749bcc10a47..8d74c5c234b45ceba19131746ef426d344b6cd13 100644 (file)
@@ -78,18 +78,6 @@ struct vxlan_hdr {
 #define UDP_CTRL_PKT_LEN (UDP_HDR_LEN + BFD_PKT_LEN)
 
 static uint8_t msgbuf[BFD_PKT_LEN];
-static struct iovec msgiov = {&(msgbuf[0]), sizeof(msgbuf)};
-static uint8_t cmsgbuf[255];
-
-static struct sockaddr_in msgaddr;
-static struct msghdr msghdr = {(void *)&msgaddr, sizeof(msgaddr), &msgiov, 1,
-                              (void *)&cmsgbuf, sizeof(cmsgbuf), 0};
-
-static uint8_t cmsgbuf6[255];
-
-static struct sockaddr_in6 msgaddr6;
-static struct msghdr msghdr6 = {(void *)&msgaddr6, sizeof(msgaddr6), &msgiov, 1,
-                               (void *)&cmsgbuf6, sizeof(cmsgbuf6), 0};
 
 static int ttlval = BFD_TTL_VAL;
 static int tosval = BFD_TOS_VAL;
@@ -713,7 +701,24 @@ static ssize_t bfd_recv_ipv4(int sd, bool is_mhop, char *port, size_t portlen,
        struct cmsghdr *cm;
        int ifindex;
        ssize_t mlen;
-
+       struct sockaddr_in msgaddr;
+       struct msghdr msghdr;
+       struct iovec iov[1];
+       uint8_t cmsgbuf[255];
+
+       /* Prepare the recvmsg params. */
+       iov[0].iov_base = msgbuf;
+       iov[0].iov_len = sizeof(msgbuf);
+
+       memset(&msghdr, 0, sizeof(msghdr));
+       msghdr.msg_name = &msgaddr;
+       msghdr.msg_namelen = sizeof(msgaddr);
+       msghdr.msg_iov = iov;
+       msghdr.msg_iovlen = 1;
+       msghdr.msg_control = cmsgbuf;
+       msghdr.msg_controllen = sizeof(cmsgbuf);
+
+       /* Sanitize input/output. */
        memset(port, 0, portlen);
        memset(vrfname, 0, vrfnamelen);
        memset(local, 0, sizeof(*local));
@@ -821,7 +826,24 @@ ssize_t bfd_recv_ipv6(int sd, bool is_mhop, char *port, size_t portlen,
        struct in6_pktinfo *pi6 = NULL;
        int ifindex = 0;
        ssize_t mlen;
-
+       struct sockaddr_in6 msgaddr6;
+       struct msghdr msghdr6;
+       struct iovec iov[1];
+       uint8_t cmsgbuf6[255];
+
+       /* Prepare the recvmsg params. */
+       iov[0].iov_base = msgbuf;
+       iov[0].iov_len = sizeof(msgbuf);
+
+       memset(&msghdr6, 0, sizeof(msghdr6));
+       msghdr6.msg_name = &msgaddr6;
+       msghdr6.msg_namelen = sizeof(msgaddr6);
+       msghdr6.msg_iov = iov;
+       msghdr6.msg_iovlen = 1;
+       msghdr6.msg_control = cmsgbuf6;
+       msghdr6.msg_controllen = sizeof(cmsgbuf6);
+
+       /* Sanitize input/output. */
        memset(port, 0, portlen);
        memset(vrfname, 0, vrfnamelen);
        memset(local, 0, sizeof(*local));
@@ -851,7 +873,7 @@ ssize_t bfd_recv_ipv6(int sd, bool is_mhop, char *port, size_t portlen,
                                log_debug(
                                        "ipv6-recv: invalid TTL from %s (expected %d, got %d flags %d)",
                                        satostr(peer), ttlval, BFD_TTL_VAL,
-                                       msghdr.msg_flags);
+                                       msghdr6.msg_flags);
                                return -1;
                        }
                } else if (cm->cmsg_type == IPV6_PKTINFO) {
@@ -999,7 +1021,7 @@ int bfd_recv_cb(struct thread *t)
         * - Short packets;
         * - Invalid discriminator;
         */
-       cp = (struct bfd_pkt *)(msghdr.msg_iov->iov_base);
+       cp = (struct bfd_pkt *)(msgbuf);
        if (BFD_GETVER(cp->diag) != BFD_VERSION) {
                cp_debug(is_mhop, &peer, &local, port, vrfname,
                         "bad version %d", BFD_GETVER(cp->diag));