#define RCVBUFSIZE (32*1024)
#endif /* TUNE_LARGE */
+/*%
+ * Instead of calculating the cmsgbuf lengths every time we take
+ * a rule of thumb approach - sizes are taken from x86_64 linux,
+ * multiplied by 2, everything should fit. Those sizes are not
+ * large enough to cause any concern.
+ */
+#if defined(USE_CMSG) && defined(ISC_PLATFORM_HAVEIN6PKTINFO)
+#define CMSG_SP_IN6PKT 40
+#else
+#define CMSG_SP_IN6PKT 0
+#endif
+
+#if defined(USE_CMSG) && defined(SO_TIMESTAMP)
+#define CMSG_SP_TIMESTAMP 32
+#else
+#define CMSG_SP_TIMESTAMP 0
+#endif
+
+#if defined(USE_CMSG) && (defined(IPV6_TCLASS) || defined(IP_TOS))
+#define CMSG_SP_TCTOS 24
+#else
+#define CMSG_SP_TCTOS 0
+#endif
+
+#define CMSG_SP_INT 24
+
+#define RECVCMSGBUFLEN (2*(CMSG_SP_IN6PKT + CMSG_SP_TIMESTAMP + CMSG_SP_TCTOS)+1)
+#define SENDCMSGBUFLEN (2*(CMSG_SP_IN6PKT + CMSG_SP_INT + CMSG_SP_TCTOS)+1)
+
/*%
* The number of times a send operation is repeated if the result is EINTR.
*/
unsigned char overflow; /* used for MSG_TRUNC fake */
#endif
- ISC_SOCKADDR_LEN_T recvcmsgbuflen;
- ISC_SOCKADDR_LEN_T sendcmsgbuflen;
-
void *fdwatcharg;
isc_sockfdwatch_t fdwatchcb;
int fdwatchflags;
memset(msg, 0, sizeof(*msg));
- if (sock->sendcmsgbuflen != 0U) {
- memset(cmsgbuf, 0, sock->sendcmsgbuflen);
- }
-
if (!sock->connected) {
msg->msg_name = (void *)&dev->address.type.sa;
msg->msg_namelen = dev->address.length;
msg->msg_control = (void *)cmsgbuf;
msg->msg_controllen = cmsg_space(sizeof(struct in6_pktinfo));
- INSIST(msg->msg_controllen <= sock->sendcmsgbuflen);
+ INSIST(msg->msg_controllen <= SENDCMSGBUFLEN);
cmsgp = (struct cmsghdr *)cmsgbuf;
cmsgp->cmsg_level = IPPROTO_IPV6;
cmsgp = (struct cmsghdr *)(cmsgbuf +
msg->msg_controllen);
+
+ msg->msg_control = (void *)cmsgbuf;
msg->msg_controllen += cmsg_space(sizeof(use_min_mtu));
- INSIST(msg->msg_controllen <= sock->sendcmsgbuflen);
+ INSIST(msg->msg_controllen <= SENDCMSGBUFLEN);
cmsgp->cmsg_level = IPPROTO_IPV6;
cmsgp->cmsg_type = IPV6_USE_MIN_MTU;
msg->msg_controllen);
msg->msg_control = (void *)cmsgbuf;
msg->msg_controllen += cmsg_space(sizeof(dscp));
- INSIST(msg->msg_controllen <= sock->sendcmsgbuflen);
+ INSIST(msg->msg_controllen <= SENDCMSGBUFLEN);
cmsgp->cmsg_level = IPPROTO_IP;
cmsgp->cmsg_type = IP_TOS;
msg->msg_controllen);
msg->msg_control = (void *)cmsgbuf;
msg->msg_controllen += cmsg_space(sizeof(dscp));
- INSIST(msg->msg_controllen <= sock->sendcmsgbuflen);
+ INSIST(msg->msg_controllen <= SENDCMSGBUFLEN);
cmsgp->cmsg_level = IPPROTO_IPV6;
cmsgp->cmsg_type = IPV6_TCLASS;
}
#endif
if (msg->msg_controllen != 0 &&
- msg->msg_controllen < sock->sendcmsgbuflen)
+ msg->msg_controllen < SENDCMSGBUFLEN)
{
memset(cmsgbuf + msg->msg_controllen, 0,
- sock->sendcmsgbuflen - msg->msg_controllen);
+ SENDCMSGBUFLEN - msg->msg_controllen);
}
}
#endif
#ifdef ISC_NET_BSD44MSGHDR
#if defined(USE_CMSG)
msg->msg_control = cmsgbuf;
- msg->msg_controllen = sock->recvcmsgbuflen;
+ msg->msg_controllen = RECVCMSGBUFLEN;
#else
msg->msg_control = NULL;
msg->msg_controllen = 0;
isc_buffer_t *buffer;
int recv_errno;
char strbuf[ISC_STRERRORSIZE];
- char cmsgbuf[sock->recvcmsgbuflen];
+ char cmsgbuf[RECVCMSGBUFLEN] = {0};
build_msghdr_recv(sock, cmsgbuf, dev, &msghdr, iov, &read_count);
int attempts = 0;
int send_errno;
char strbuf[ISC_STRERRORSIZE];
- char cmsgbuf[sock->sendcmsgbuflen];
+ char cmsgbuf[SENDCMSGBUFLEN] = {0};
build_msghdr_send(sock, cmsgbuf, dev, &msghdr, iov, &write_count);
{
isc__socket_t *sock;
isc_result_t result;
- ISC_SOCKADDR_LEN_T cmsgbuflen;
sock = isc_mem_get(manager->mctx, sizeof(*sock));
ISC_LINK_INIT(sock, link);
- /*
- * Set up cmsg buffer lengths.
- */
- cmsgbuflen = 0;
-#if defined(USE_CMSG) && defined(ISC_PLATFORM_HAVEIN6PKTINFO)
- cmsgbuflen += cmsg_space(sizeof(struct in6_pktinfo));
-#endif
-#if defined(USE_CMSG) && defined(SO_TIMESTAMP)
- cmsgbuflen += cmsg_space(sizeof(struct timeval));
-#endif
-#if defined(USE_CMSG) && (defined(IPV6_TCLASS) || defined(IP_TOS))
- cmsgbuflen += cmsg_space(sizeof(int));
-#endif
- sock->recvcmsgbuflen = cmsgbuflen;
-
- cmsgbuflen = 0;
-#if defined(USE_CMSG) && defined(ISC_PLATFORM_HAVEIN6PKTINFO)
- cmsgbuflen += cmsg_space(sizeof(struct in6_pktinfo));
-#if defined(IPV6_USE_MIN_MTU)
- /*
- * Provide space for working around FreeBSD's broken IPV6_USE_MIN_MTU
- * support.
- */
- cmsgbuflen += cmsg_space(sizeof(int));
-#endif
-#endif
-#if defined(USE_CMSG) && (defined(IP_TOS) || defined(IPV6_TCLASS))
- cmsgbuflen += cmsg_space(sizeof(int));
-#endif
- sock->sendcmsgbuflen = cmsgbuflen;
memset(sock->name, 0, sizeof(sock->name));
sock->tag = NULL;
#endif /* SO_TIMESTAMP */
#if defined(ISC_PLATFORM_HAVEIPV6)
- if (sock->pf == AF_INET6 && sock->recvcmsgbuflen == 0U) {
- /*
- * Warn explicitly because this anomaly can be hidden
- * in usual operation (and unexpectedly appear later).
- */
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "No buffer available to receive "
- "IPv6 destination");
- }
#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
#ifdef IPV6_RECVPKTINFO
/* RFC 3542 */