2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

Add helper function to enable DF (don't fragment) flag on UDP sockets

This commits add isc__nm_socket_dontfrag() helper functions.
This commit is contained in:
Ondřej Surý
2020-10-05 10:51:40 +02:00
committed by Ondřej Surý
parent 5daaca7146
commit d685bbc822
3 changed files with 56 additions and 0 deletions

View File

@@ -850,3 +850,9 @@ isc__nm_socket_incoming_cpu(uv_os_fd_t fd);
/*%<
* Set the SO_INCOMING_CPU socket option on the fd if available
*/
isc_result_t
isc__nm_socket_dontfrag(uv_os_fd_t fd, sa_family_t sa_family);
/*%<
* Set the SO_IP_DONTFRAG (or equivalent) socket option of the fd if available
*/

View File

@@ -1687,6 +1687,54 @@ isc__nm_socket_incoming_cpu(uv_os_fd_t fd) {
return (ISC_R_NOTIMPLEMENTED);
}
isc_result_t
isc__nm_socket_dontfrag(uv_os_fd_t fd, sa_family_t sa_family) {
/*
* Set the Don't Fragment flag on IP packets
*/
if (sa_family == AF_INET6) {
#if defined(IPV6_DONTFRAG)
if (setsockopt_on(fd, IPPROTO_IPV6, IPV6_DONTFRAG) == -1) {
return (ISC_R_FAILURE);
} else {
return (ISC_R_SUCCESS);
}
#elif defined(IPV6_MTU_DISCOVER)
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
&(int){ IP_PMTUDISC_DO }, sizeof(int)) == -1)
{
return (ISC_R_FAILURE);
} else {
return (ISC_R_SUCCESS);
}
#else
UNUSED(fd);
#endif
} else if (sa_family == AF_INET) {
#if defined(IP_DONTFRAG)
if (setsockopt_on(fd, IPPROTO_IP, IP_DONTFRAG) == -1) {
return (ISC_R_FAILURE);
} else {
return (ISC_R_SUCCESS);
}
#elif defined(IP_MTU_DISCOVER)
if (setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER,
&(int){ IP_PMTUDISC_DO }, sizeof(int)) == -1)
{
return (ISC_R_FAILURE);
} else {
return (ISC_R_SUCCESS);
}
#else
UNUSED(fd);
#endif
} else {
return (ISC_R_FAMILYNOSUPPORT);
}
return (ISC_R_NOTIMPLEMENTED);
}
#ifdef NETMGR_TRACE
/*
* Dump all active sockets in netmgr. We output to stderr

View File

@@ -56,6 +56,8 @@ typedef uint32_t socklen_t;
#undef MSG_TRUNC
typedef uint16_t sa_family_t;
/*
* Set up a macro for importing and exporting from the DLL
*/