#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;
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));
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));
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) {
* - 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));