mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
3896. [bug] Address performance issues with DSCP code on some
platforms. [RT #36534]
This commit is contained in:
parent
bc98d5a4c6
commit
89cf81b462
3
CHANGES
3
CHANGES
@ -1,3 +1,6 @@
|
|||||||
|
3896. [bug] Address performance issues with DSCP code on some
|
||||||
|
platforms. [RT #36534]
|
||||||
|
|
||||||
3895. [func] Add the ability to set the DSCP code point to dig.
|
3895. [func] Add the ability to set the DSCP code point to dig.
|
||||||
[RT #36546]
|
[RT #36546]
|
||||||
|
|
||||||
|
@ -614,7 +614,7 @@ try_dscp_v4(void) {
|
|||||||
int s, dscp = 0, n;
|
int s, dscp = 0, n;
|
||||||
#ifdef IP_RECVTOS
|
#ifdef IP_RECVTOS
|
||||||
int on = 1;
|
int on = 1;
|
||||||
#endif
|
#endif /* IP_RECVTOS */
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
@ -648,23 +648,29 @@ try_dscp_v4(void) {
|
|||||||
on = 1;
|
on = 1;
|
||||||
if (setsockopt(s, IPPROTO_IP, IP_RECVTOS, &on, sizeof(on)) == 0)
|
if (setsockopt(s, IPPROTO_IP, IP_RECVTOS, &on, sizeof(on)) == 0)
|
||||||
dscp_result |= ISC_NET_DSCPRECVV4;
|
dscp_result |= ISC_NET_DSCPRECVV4;
|
||||||
#endif
|
#endif /* IP_RECVTOS */
|
||||||
|
|
||||||
#ifdef ISC_NET_BSD44MSGHDR
|
#ifdef ISC_NET_BSD44MSGHDR
|
||||||
|
|
||||||
#ifndef ISC_CMSG_IP_TOS
|
#ifndef ISC_CMSG_IP_TOS
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#define ISC_CMSG_IP_TOS 0 /* As of 10.8.2. */
|
#define ISC_CMSG_IP_TOS 0 /* As of 10.8.2. */
|
||||||
#else
|
#else /* ! __APPLE__ */
|
||||||
#define ISC_CMSG_IP_TOS 1
|
#define ISC_CMSG_IP_TOS 1
|
||||||
#endif
|
#endif /* ! __APPLE__ */
|
||||||
#endif
|
#endif /* ! ISC_CMSG_IP_TOS */
|
||||||
|
|
||||||
#if ISC_CMSG_IP_TOS
|
#if ISC_CMSG_IP_TOS
|
||||||
if (cmsgsend(s, IPPROTO_IP, IP_TOS, res0))
|
if (cmsgsend(s, IPPROTO_IP, IP_TOS, res0))
|
||||||
dscp_result |= ISC_NET_DSCPPKTV4;
|
dscp_result |= ISC_NET_DSCPPKTV4;
|
||||||
#endif
|
#endif /* ISC_CMSG_IP_TOS */
|
||||||
#endif
|
|
||||||
|
#endif /* ISC_NET_BSD44MSGHDR */
|
||||||
|
|
||||||
freeaddrinfo(res0);
|
freeaddrinfo(res0);
|
||||||
close(s);
|
close(s);
|
||||||
#endif
|
|
||||||
|
#endif /* IP_TOS */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -677,7 +683,7 @@ try_dscp_v6(void) {
|
|||||||
int s, dscp = 0, n;
|
int s, dscp = 0, n;
|
||||||
#if defined(IPV6_RECVTCLASS)
|
#if defined(IPV6_RECVTCLASS)
|
||||||
int on = 1;
|
int on = 1;
|
||||||
#endif
|
#endif /* IPV6_RECVTCLASS */
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = AF_INET6;
|
hints.ai_family = AF_INET6;
|
||||||
@ -709,16 +715,19 @@ try_dscp_v6(void) {
|
|||||||
on = 1;
|
on = 1;
|
||||||
if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVTCLASS, &on, sizeof(on)) == 0)
|
if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVTCLASS, &on, sizeof(on)) == 0)
|
||||||
dscp_result |= ISC_NET_DSCPRECVV6;
|
dscp_result |= ISC_NET_DSCPRECVV6;
|
||||||
#endif
|
#endif /* IPV6_RECVTCLASS */
|
||||||
|
|
||||||
#ifdef ISC_NET_BSD44MSGHDR
|
#ifdef ISC_NET_BSD44MSGHDR
|
||||||
if (cmsgsend(s, IPPROTO_IPV6, IPV6_TCLASS, res0))
|
if (cmsgsend(s, IPPROTO_IPV6, IPV6_TCLASS, res0))
|
||||||
dscp_result |= ISC_NET_DSCPPKTV6;
|
dscp_result |= ISC_NET_DSCPPKTV6;
|
||||||
#endif
|
#endif /* ISC_NET_BSD44MSGHDR */
|
||||||
|
|
||||||
freeaddrinfo(res0);
|
freeaddrinfo(res0);
|
||||||
close(s);
|
close(s);
|
||||||
#endif
|
|
||||||
#endif
|
#endif /* IPV6_TCLASS */
|
||||||
#endif
|
#endif /* WANT_IPV6 */
|
||||||
|
#endif /* ISC_PLATFORM_HAVEIPV6 */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -363,7 +363,8 @@ struct isc__socket {
|
|||||||
connecting : 1, /* connect pending */
|
connecting : 1, /* connect pending */
|
||||||
bound : 1, /* bound to local addr */
|
bound : 1, /* bound to local addr */
|
||||||
dupped : 1,
|
dupped : 1,
|
||||||
active : 1; /* currently active */
|
active : 1, /* currently active */
|
||||||
|
pktdscp : 1; /* per packet dscp */
|
||||||
|
|
||||||
#ifdef ISC_NET_RECVOVERFLOW
|
#ifdef ISC_NET_RECVOVERFLOW
|
||||||
unsigned char overflow; /* used for MSG_TRUNC fake */
|
unsigned char overflow; /* used for MSG_TRUNC fake */
|
||||||
@ -378,7 +379,7 @@ struct isc__socket {
|
|||||||
isc_sockfdwatch_t fdwatchcb;
|
isc_sockfdwatch_t fdwatchcb;
|
||||||
int fdwatchflags;
|
int fdwatchflags;
|
||||||
isc_task_t *fdwatchtask;
|
isc_task_t *fdwatchtask;
|
||||||
int dscp;
|
unsigned int dscp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SOCKET_MANAGER_MAGIC ISC_MAGIC('I', 'O', 'm', 'g')
|
#define SOCKET_MANAGER_MAGIC ISC_MAGIC('I', 'O', 'm', 'g')
|
||||||
@ -1527,11 +1528,12 @@ build_msghdr_send(isc__socket_t *sock, isc_socketevent_t *dev,
|
|||||||
memmove(CMSG_DATA(cmsgp), &use_min_mtu, sizeof(use_min_mtu));
|
memmove(CMSG_DATA(cmsgp), &use_min_mtu, sizeof(use_min_mtu));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (isc_dscp_check_value != -1) {
|
|
||||||
|
if (isc_dscp_check_value > -1) {
|
||||||
if (sock->type == isc_sockettype_udp)
|
if (sock->type == isc_sockettype_udp)
|
||||||
INSIST((int)dev->dscp == isc_dscp_check_value);
|
INSIST((int)dev->dscp == isc_dscp_check_value);
|
||||||
if (sock->type == isc_sockettype_tcp)
|
else if (sock->type == isc_sockettype_tcp)
|
||||||
INSIST(sock->dscp == isc_dscp_check_value);
|
INSIST((int)sock->dscp == isc_dscp_check_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((sock->type == isc_sockettype_udp) &&
|
if ((sock->type == isc_sockettype_udp) &&
|
||||||
@ -1539,10 +1541,10 @@ build_msghdr_send(isc__socket_t *sock, isc_socketevent_t *dev,
|
|||||||
{
|
{
|
||||||
int dscp = (dev->dscp << 2) & 0xff;
|
int dscp = (dev->dscp << 2) & 0xff;
|
||||||
|
|
||||||
|
INSIST(dev->dscp < 0x40 && dev->dscp >= 0);
|
||||||
|
|
||||||
#ifdef IP_TOS
|
#ifdef IP_TOS
|
||||||
if (sock->pf == AF_INET &&
|
if (sock->pf == AF_INET && sock->pktdscp) {
|
||||||
((isc_net_probedscp() & ISC_NET_DSCPPKTV4) != 0))
|
|
||||||
{
|
|
||||||
cmsgp = (struct cmsghdr *)(sock->sendcmsgbuf +
|
cmsgp = (struct cmsghdr *)(sock->sendcmsgbuf +
|
||||||
msg->msg_controllen);
|
msg->msg_controllen);
|
||||||
msg->msg_control = (void *)sock->sendcmsgbuf;
|
msg->msg_control = (void *)sock->sendcmsgbuf;
|
||||||
@ -1553,7 +1555,7 @@ build_msghdr_send(isc__socket_t *sock, isc_socketevent_t *dev,
|
|||||||
cmsgp->cmsg_type = IP_TOS;
|
cmsgp->cmsg_type = IP_TOS;
|
||||||
cmsgp->cmsg_len = cmsg_len(sizeof(char));
|
cmsgp->cmsg_len = cmsg_len(sizeof(char));
|
||||||
*(unsigned char*)CMSG_DATA(cmsgp) = dscp;
|
*(unsigned char*)CMSG_DATA(cmsgp) = dscp;
|
||||||
} else if (sock->pf == AF_INET) {
|
} else if (sock->pf == AF_INET && sock->dscp != dev->dscp) {
|
||||||
if (setsockopt(sock->fd, IPPROTO_IP, IP_TOS,
|
if (setsockopt(sock->fd, IPPROTO_IP, IP_TOS,
|
||||||
(void *)&dscp, sizeof(int)) < 0)
|
(void *)&dscp, sizeof(int)) < 0)
|
||||||
{
|
{
|
||||||
@ -1568,13 +1570,12 @@ build_msghdr_send(isc__socket_t *sock, isc_socketevent_t *dev,
|
|||||||
ISC_MSG_FAILED,
|
ISC_MSG_FAILED,
|
||||||
"failed"),
|
"failed"),
|
||||||
strbuf);
|
strbuf);
|
||||||
}
|
} else
|
||||||
|
sock->dscp = dscp;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)
|
#if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)
|
||||||
if (sock->pf == AF_INET6 &&
|
if (sock->pf == AF_INET6 && sock->pktdscp) {
|
||||||
((isc_net_probedscp() & ISC_NET_DSCPPKTV6) != 0))
|
|
||||||
{
|
|
||||||
cmsgp = (struct cmsghdr *)(sock->sendcmsgbuf +
|
cmsgp = (struct cmsghdr *)(sock->sendcmsgbuf +
|
||||||
msg->msg_controllen);
|
msg->msg_controllen);
|
||||||
msg->msg_control = (void *)sock->sendcmsgbuf;
|
msg->msg_control = (void *)sock->sendcmsgbuf;
|
||||||
@ -1585,7 +1586,7 @@ build_msghdr_send(isc__socket_t *sock, isc_socketevent_t *dev,
|
|||||||
cmsgp->cmsg_type = IPV6_TCLASS;
|
cmsgp->cmsg_type = IPV6_TCLASS;
|
||||||
cmsgp->cmsg_len = cmsg_len(sizeof(dscp));
|
cmsgp->cmsg_len = cmsg_len(sizeof(dscp));
|
||||||
memmove(CMSG_DATA(cmsgp), &dscp, sizeof(dscp));
|
memmove(CMSG_DATA(cmsgp), &dscp, sizeof(dscp));
|
||||||
} else if (sock->pf == AF_INET6) {
|
} else if (sock->pf == AF_INET6 && sock->dscp != dev->dscp) {
|
||||||
if (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_TCLASS,
|
if (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_TCLASS,
|
||||||
(void *)&dscp, sizeof(int)) < 0) {
|
(void *)&dscp, sizeof(int)) < 0) {
|
||||||
char strbuf[ISC_STRERRORSIZE];
|
char strbuf[ISC_STRERRORSIZE];
|
||||||
@ -1599,7 +1600,8 @@ build_msghdr_send(isc__socket_t *sock, isc_socketevent_t *dev,
|
|||||||
ISC_MSG_FAILED,
|
ISC_MSG_FAILED,
|
||||||
"failed"),
|
"failed"),
|
||||||
strbuf);
|
strbuf);
|
||||||
}
|
} else
|
||||||
|
sock->dscp = dscp;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2257,7 +2259,7 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type,
|
|||||||
sock->manager = manager;
|
sock->manager = manager;
|
||||||
sock->type = type;
|
sock->type = type;
|
||||||
sock->fd = -1;
|
sock->fd = -1;
|
||||||
sock->dscp = -1;
|
sock->dscp = 0; /* TOS/TCLASS is zero until set. */
|
||||||
sock->dupped = 0;
|
sock->dupped = 0;
|
||||||
sock->statsindex = NULL;
|
sock->statsindex = NULL;
|
||||||
|
|
||||||
@ -2328,6 +2330,7 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type,
|
|||||||
sock->connected = 0;
|
sock->connected = 0;
|
||||||
sock->connecting = 0;
|
sock->connecting = 0;
|
||||||
sock->bound = 0;
|
sock->bound = 0;
|
||||||
|
sock->pktdscp = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the lock.
|
* Initialize the lock.
|
||||||
@ -2861,6 +2864,8 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type,
|
|||||||
case isc_sockettype_udp:
|
case isc_sockettype_udp:
|
||||||
sock->statsindex =
|
sock->statsindex =
|
||||||
(pf == AF_INET) ? udp4statsindex : udp6statsindex;
|
(pf == AF_INET) ? udp4statsindex : udp6statsindex;
|
||||||
|
#define DCSPPKT(pf) ((pf == AF_INET) ? ISC_NET_DSCPPKTV4 : ISC_NET_DSCPPKTV6)
|
||||||
|
sock->pktdscp = (isc_net_probedscp() & DCSPPKT(pf)) != 0;
|
||||||
break;
|
break;
|
||||||
case isc_sockettype_tcp:
|
case isc_sockettype_tcp:
|
||||||
sock->statsindex =
|
sock->statsindex =
|
||||||
@ -3566,8 +3571,7 @@ internal_accept(isc_task_t *me, isc_event_t *ev) {
|
|||||||
/*
|
/*
|
||||||
* Ensure DSCP settings are inherited across accept.
|
* Ensure DSCP settings are inherited across accept.
|
||||||
*/
|
*/
|
||||||
if (sock->dscp != -1)
|
setdscp(NEWCONNSOCK(dev), sock->dscp);
|
||||||
setdscp(NEWCONNSOCK(dev), sock->dscp);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save away the remote address
|
* Save away the remote address
|
||||||
@ -6148,6 +6152,7 @@ isc__socket_dscp(isc_socket_t *sock0, isc_dscp_t dscp) {
|
|||||||
if (dscp < 0)
|
if (dscp < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* The DSCP value must not be changed once it has been set. */
|
||||||
if (isc_dscp_check_value != -1)
|
if (isc_dscp_check_value != -1)
|
||||||
INSIST(dscp == isc_dscp_check_value);
|
INSIST(dscp == isc_dscp_check_value);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1090,6 +1090,7 @@ allocate_socketevent(isc_mem_t *mctx, isc_socket_t *sock,
|
|||||||
ev->attributes = 0;
|
ev->attributes = 0;
|
||||||
ev->destroy = ev->ev_destroy;
|
ev->destroy = ev->ev_destroy;
|
||||||
ev->ev_destroy = destroy_socketevent;
|
ev->ev_destroy = destroy_socketevent;
|
||||||
|
ev->dscp = 0;
|
||||||
|
|
||||||
return (ev);
|
return (ev);
|
||||||
}
|
}
|
||||||
@ -1470,6 +1471,7 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type,
|
|||||||
|
|
||||||
sock->manager = manager;
|
sock->manager = manager;
|
||||||
sock->type = type;
|
sock->type = type;
|
||||||
|
sock->dscp = 0; /* TOS/TCLASS is zero until set. */
|
||||||
sock->fd = INVALID_SOCKET;
|
sock->fd = INVALID_SOCKET;
|
||||||
|
|
||||||
ISC_LINK_INIT(sock, link);
|
ISC_LINK_INIT(sock, link);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user