Commit 5862eb4c authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[1824] Use CMSG_SPACE instead of CMSG_LEN to set msg_controllen.

Both macros should be accepted, but CMSG_LEN appears not to work on
OpenBSD.
parent 12c48d42
......@@ -892,7 +892,15 @@ IfaceMgr::send(const Pkt6Ptr& pkt) {
struct in6_pktinfo *pktinfo = convertPktInfo6(CMSG_DATA(cmsg));
memset(pktinfo, 0, sizeof(struct in6_pktinfo));
pktinfo->ipi6_ifindex = pkt->getIndex();
m.msg_controllen = cmsg->cmsg_len;
// According to RFC3542, section 20.2, the msg_controllen field
// may be set using CMSG_SPACE (which includes padding) or
// using CMSG_LEN. Both forms appear to work fine on Linux, FreeBSD,
// NetBSD, but OpenBSD appears to have a bug, discussed here:
// http://www.archivum.info/mailing.openbsd.bugs/2009-02/00017/
// kernel-6080-msg_controllen-of-IPV6_PKTINFO.html
// which causes sendmsg to return EINVAL if the CMSG_LEN is
// used to set the msg_controllen value.
m.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
pkt->updateTimestamp();
......
......@@ -235,7 +235,7 @@ PktFilterInet::send(const Iface&, uint16_t sockfd,
struct in_pktinfo* pktinfo =(struct in_pktinfo *)CMSG_DATA(cmsg);
memset(pktinfo, 0, sizeof(struct in_pktinfo));
pktinfo->ipi_ifindex = pkt->getIndex();
m.msg_controllen = cmsg->cmsg_len;
m.msg_controllen = CMSG_SPACE(sizeof(struct in_pktinfo));
#endif
pkt->updateTimestamp();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment