e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley/*
9a006fe9a05abc03c0e81977802194dab8737206Tinderbox User * Copyright (C) 1999-2005, 2007, 2008, 2012-2017 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley */
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id$ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#include <config.h>
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <sys/types.h>
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#if defined(HAVE_SYS_SYSCTL_H)
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#if defined(HAVE_SYS_PARAM_H)
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#include <sys/param.h>
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#endif
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <sys/sysctl.h>
78576fe0db75332cd956b037d90dad0c7e09b005Tatuya JINMEI 神明達哉#endif
cfb605168d7403d3c967eec1b761519712e11ce3Mark Andrews#include <sys/uio.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#include <errno.h>
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#include <unistd.h>
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews#include <fcntl.h>
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington#include <isc/log.h>
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence#include <isc/msgs.h>
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#include <isc/net.h>
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#include <isc/netdb.h>
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#include <isc/once.h>
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews#include <isc/strerror.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/string.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley#include <isc/util.h>
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifndef ISC_SOCKADDR_LEN_T
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#define ISC_SOCKADDR_LEN_T unsigned int
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#endif
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*%
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Definitions about UDP port range specification. This is a total mess of
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * portability variants: some use sysctl (but the sysctl names vary), some use
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * system-specific interfaces, some have the same interface for IPv4 and IPv6,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * some separate them, etc...
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*%
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * The last resort defaults: use all non well known port space
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#ifndef ISC_NET_PORTRANGELOW
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define ISC_NET_PORTRANGELOW 1024
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#endif /* ISC_NET_PORTRANGELOW */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#ifndef ISC_NET_PORTRANGEHIGH
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define ISC_NET_PORTRANGEHIGH 65535
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#endif /* ISC_NET_PORTRANGEHIGH */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#ifdef HAVE_SYSCTLBYNAME
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*%
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * sysctl variants
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define USE_SYSCTL_PORTRANGE
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V4PORTRANGE_LOW "net.inet.ip.portrange.hifirst"
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V4PORTRANGE_HIGH "net.inet.ip.portrange.hilast"
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V6PORTRANGE_LOW "net.inet.ip.portrange.hifirst"
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V6PORTRANGE_HIGH "net.inet.ip.portrange.hilast"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#endif
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#ifdef __NetBSD__
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define USE_SYSCTL_PORTRANGE
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define SYSCTL_V4PORTRANGE_LOW "net.inet.ip.anonportmin"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define SYSCTL_V4PORTRANGE_HIGH "net.inet.ip.anonportmax"
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V6PORTRANGE_LOW "net.inet6.ip6.anonportmin"
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V6PORTRANGE_HIGH "net.inet6.ip6.anonportmax"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#endif
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#else /* !HAVE_SYSCTLBYNAME */
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#ifdef __OpenBSD__
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define USE_SYSCTL_PORTRANGE
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V4PORTRANGE_LOW { CTL_NET, PF_INET, IPPROTO_IP, \
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt IPCTL_IPPORT_HIFIRSTAUTO }
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V4PORTRANGE_HIGH { CTL_NET, PF_INET, IPPROTO_IP, \
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt IPCTL_IPPORT_HILASTAUTO }
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt/* Same for IPv6 */
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V6PORTRANGE_LOW SYSCTL_V4PORTRANGE_LOW
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#define SYSCTL_V6PORTRANGE_HIGH SYSCTL_V4PORTRANGE_HIGH
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#endif
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#endif /* HAVE_SYSCTLBYNAME */
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt#if defined(ISC_PLATFORM_HAVEIPV6)
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt# if defined(ISC_PLATFORM_NEEDIN6ADDRANY)
435532822dc571a904207d8176e063cc8731eef5Bob Halleyconst struct in6_addr isc_net_in6addrany = IN6ADDR_ANY_INIT;
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt# endif
785d1541b6ec7c6939ec8ebf409db367943bab5fAndreas Gustafsson
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt# if defined(ISC_PLATFORM_NEEDIN6ADDRLOOPBACK)
9d99e3fda11eb8549a2bc7d5af31b7630ed68162Mark Andrewsconst struct in6_addr isc_net_in6addrloop = IN6ADDR_LOOPBACK_INIT;
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt# endif
435532822dc571a904207d8176e063cc8731eef5Bob Halley
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt# if defined(WANT_IPV6)
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrewsstatic isc_once_t once_ipv6only = ISC_ONCE_INIT;
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn# if defined(ISC_PLATFORM_HAVEIN6PKTINFO)
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrewsstatic isc_once_t once_ipv6pktinfo = ISC_ONCE_INIT;
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn# endif
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn# endif /* WANT_IPV6 */
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt#endif /* ISC_PLATFORM_HAVEIPV6 */
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn#ifndef ISC_CMSG_IP_TOS
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn#ifdef __APPLE__
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn#define ISC_CMSG_IP_TOS 0 /* As of 10.8.2. */
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn#else /* ! __APPLE__ */
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn#define ISC_CMSG_IP_TOS 1
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn#endif /* ! __APPLE__ */
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn#endif /* ! ISC_CMSG_IP_TOS */
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Huntstatic isc_once_t once = ISC_ONCE_INIT;
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstatic isc_once_t once_dscp = ISC_ONCE_INIT;
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleystatic isc_result_t ipv4_result = ISC_R_NOTFOUND;
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleystatic isc_result_t ipv6_result = ISC_R_NOTFOUND;
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrewsstatic isc_result_t unix_result = ISC_R_NOTFOUND;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrewsstatic isc_result_t ipv6only_result = ISC_R_NOTFOUND;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrewsstatic isc_result_t ipv6pktinfo_result = ISC_R_NOTFOUND;
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstatic unsigned int dscp_result = 0;
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleystatic isc_result_t
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleytry_proto(int domain) {
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley int s;
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington isc_result_t result = ISC_R_SUCCESS;
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews char strbuf[ISC_STRERRORSIZE];
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley s = socket(domain, SOCK_STREAM, 0);
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley if (s == -1) {
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley switch (errno) {
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#ifdef EAFNOSUPPORT
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley case EAFNOSUPPORT:
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#endif
cb9345c996de9d9c990009f14fc83fbbe9c5e3e6Mark Andrews#ifdef EPFNOSUPPORT
cb9345c996de9d9c990009f14fc83fbbe9c5e3e6Mark Andrews case EPFNOSUPPORT:
cb9345c996de9d9c990009f14fc83fbbe9c5e3e6Mark Andrews#endif
dcf8825fd74f3f83b1882af4793270083b125ee5David Lawrence#ifdef EPROTONOSUPPORT
dcf8825fd74f3f83b1882af4793270083b125ee5David Lawrence case EPROTONOSUPPORT:
dcf8825fd74f3f83b1882af4793270083b125ee5David Lawrence#endif
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#ifdef EINVAL
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley case EINVAL:
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#endif
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley return (ISC_R_NOTFOUND);
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley default:
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews isc__strerror(errno, strbuf, sizeof(strbuf));
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley UNEXPECTED_ERROR(__FILE__, __LINE__,
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence "socket() %s: %s",
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence isc_msgcat_get(isc_msgcat,
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence ISC_MSGSET_GENERAL,
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence ISC_MSG_FAILED,
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence "failed"),
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews strbuf);
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley return (ISC_R_UNEXPECTED);
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley }
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley }
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington#ifdef ISC_PLATFORM_HAVEIPV6
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington#ifdef WANT_IPV6
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington if (domain == PF_INET6) {
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington struct sockaddr_in6 sin6;
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington unsigned int len;
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington /*
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington * Check to see if IPv6 is broken, as is common on Linux.
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington */
70c91849c3a3d808125d690a46af5fd225a4c291Andreas Gustafsson len = sizeof(sin6);
2d67fbd786284ed570031fa82fc9807b0413aa3fBrian Wellington if (getsockname(s, (struct sockaddr *)&sin6, (void *)&len) < 0)
2d67fbd786284ed570031fa82fc9807b0413aa3fBrian Wellington {
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
9efa0d2ae311157ed1cce3c16129579111b1e3b0Andreas Gustafsson "retrieving the address of an IPv6 "
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington "socket from the kernel failed.");
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews "IPv6 is not supported.");
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington result = ISC_R_NOTFOUND;
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington } else {
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington if (len == sizeof(struct sockaddr_in6))
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington result = ISC_R_SUCCESS;
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington else {
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington isc_log_write(isc_lctx,
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington ISC_LOGCATEGORY_GENERAL,
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington ISC_LOGMODULE_SOCKET,
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington ISC_LOG_ERROR,
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington "IPv6 structures in kernel and "
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington "user space do not match.");
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington isc_log_write(isc_lctx,
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington ISC_LOGCATEGORY_GENERAL,
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington ISC_LOGMODULE_SOCKET,
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington ISC_LOG_ERROR,
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews "IPv6 is not supported.");
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington result = ISC_R_NOTFOUND;
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington }
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington }
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington }
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington#endif
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington#endif
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington#endif
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson (void)close(s);
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington
64a84169d7eed05486b10be90afea58f4af146f9Brian Wellington return (result);
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley}
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleystatic void
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleyinitialize_action(void) {
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley ipv4_result = try_proto(PF_INET);
eb2c85b103e3fccebddf59619216ba26af98bcd1Bob Halley#ifdef ISC_PLATFORM_HAVEIPV6
f3f22040a8c4835227e1a3abc54454556d4c47abBrian Wellington#ifdef WANT_IPV6
ece3d6c35693f9e2145434b0bf14e8b752cdeee8Michael Graff#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley ipv6_result = try_proto(PF_INET6);
ece3d6c35693f9e2145434b0bf14e8b752cdeee8Michael Graff#endif
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley#endif
f3f22040a8c4835227e1a3abc54454556d4c47abBrian Wellington#endif
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews#ifdef ISC_PLATFORM_HAVESYSUNH
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews unix_result = try_proto(PF_UNIX);
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews#endif
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley}
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleystatic void
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleyinitialize(void) {
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley}
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleyisc_result_t
2f3cfa8c0212e47f92f6c45459d9ee0ba8aa0045Bob Halleyisc_net_probeipv4(void) {
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley initialize();
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley return (ipv4_result);
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley}
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halleyisc_result_t
2f3cfa8c0212e47f92f6c45459d9ee0ba8aa0045Bob Halleyisc_net_probeipv6(void) {
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley initialize();
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley return (ipv6_result);
e08daafffce8fb74ffca8ecf5772e334299ccf76Bob Halley}
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrewsisc_result_t
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrewsisc_net_probeunix(void) {
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews initialize();
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews return (unix_result);
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews}
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews
602274b30f17281b8af0608016eadd0816d3eca6Mark Andrews#ifdef ISC_PLATFORM_HAVEIPV6
602274b30f17281b8af0608016eadd0816d3eca6Mark Andrews#ifdef WANT_IPV6
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrewsstatic void
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrewstry_ipv6only(void) {
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#ifdef IPV6_V6ONLY
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews int s, on;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews char strbuf[ISC_STRERRORSIZE];
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#endif
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews isc_result_t result;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews result = isc_net_probeipv6();
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews if (result != ISC_R_SUCCESS) {
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ipv6only_result = result;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews return;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews }
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#ifndef IPV6_V6ONLY
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ipv6only_result = ISC_R_NOTFOUND;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews return;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#else
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews /* check for TCP sockets */
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews s = socket(PF_INET6, SOCK_STREAM, 0);
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews if (s == -1) {
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews isc__strerror(errno, strbuf, sizeof(strbuf));
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews "socket() %s: %s",
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews isc_msgcat_get(isc_msgcat,
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ISC_MSGSET_GENERAL,
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ISC_MSG_FAILED,
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews "failed"),
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews strbuf);
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ipv6only_result = ISC_R_UNEXPECTED;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews return;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews }
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews on = 1;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) {
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ipv6only_result = ISC_R_NOTFOUND;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews goto close;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews }
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews close(s);
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews /* check for UDP sockets */
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews s = socket(PF_INET6, SOCK_DGRAM, 0);
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews if (s == -1) {
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews isc__strerror(errno, strbuf, sizeof(strbuf));
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews "socket() %s: %s",
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews isc_msgcat_get(isc_msgcat,
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ISC_MSGSET_GENERAL,
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ISC_MSG_FAILED,
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews "failed"),
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews strbuf);
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ipv6only_result = ISC_R_UNEXPECTED;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews return;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews }
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews on = 1;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) {
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ipv6only_result = ISC_R_NOTFOUND;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews goto close;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews }
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ipv6only_result = ISC_R_SUCCESS;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrewsclose:
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews close(s);
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews return;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews#endif /* IPV6_V6ONLY */
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews}
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrewsstatic void
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrewsinitialize_ipv6only(void) {
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews RUNTIME_CHECK(isc_once_do(&once_ipv6only,
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews try_ipv6only) == ISC_R_SUCCESS);
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews}
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt#endif /* WANT_IPV6 */
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews
4f082b58b17ce39087930d5affc2ada90ef386e6Mark Andrews#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews#ifdef WANT_IPV6
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrewsstatic void
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrewstry_ipv6pktinfo(void) {
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews int s, on;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews char strbuf[ISC_STRERRORSIZE];
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews isc_result_t result;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews int optname;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews result = isc_net_probeipv6();
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews if (result != ISC_R_SUCCESS) {
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews ipv6pktinfo_result = result;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews return;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews }
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews /* we only use this for UDP sockets */
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews if (s == -1) {
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews isc__strerror(errno, strbuf, sizeof(strbuf));
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews "socket() %s: %s",
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews isc_msgcat_get(isc_msgcat,
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews ISC_MSGSET_GENERAL,
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews ISC_MSG_FAILED,
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews "failed"),
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews strbuf);
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews ipv6pktinfo_result = ISC_R_UNEXPECTED;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews return;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews }
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews#ifdef IPV6_RECVPKTINFO
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews optname = IPV6_RECVPKTINFO;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews#else
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews optname = IPV6_PKTINFO;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#endif
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews on = 1;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews if (setsockopt(s, IPPROTO_IPV6, optname, &on, sizeof(on)) < 0) {
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews ipv6pktinfo_result = ISC_R_NOTFOUND;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews goto close;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews }
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews ipv6pktinfo_result = ISC_R_SUCCESS;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrewsclose:
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews close(s);
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews return;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews}
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrewsstatic void
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrewsinitialize_ipv6pktinfo(void) {
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews RUNTIME_CHECK(isc_once_do(&once_ipv6pktinfo,
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews try_ipv6pktinfo) == ISC_R_SUCCESS);
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews}
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews#endif /* WANT_IPV6 */
4f082b58b17ce39087930d5affc2ada90ef386e6Mark Andrews#endif /* ISC_PLATFORM_HAVEIN6PKTINFO */
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt#endif /* ISC_PLATFORM_HAVEIPV6 */
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrewsisc_result_t
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrewsisc_net_probe_ipv6only(void) {
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#ifdef ISC_PLATFORM_HAVEIPV6
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#ifdef WANT_IPV6
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews initialize_ipv6only();
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#else
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews ipv6only_result = ISC_R_NOTFOUND;
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#endif
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews#endif
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews return (ipv6only_result);
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews}
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrewsisc_result_t
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrewsisc_net_probe_ipv6pktinfo(void) {
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews#ifdef ISC_PLATFORM_HAVEIPV6
4f082b58b17ce39087930d5affc2ada90ef386e6Mark Andrews#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews#ifdef WANT_IPV6
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews initialize_ipv6pktinfo();
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews#else
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews ipv6pktinfo_result = ISC_R_NOTFOUND;
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews#endif
4f082b58b17ce39087930d5affc2ada90ef386e6Mark Andrews#endif
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews#endif
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews return (ipv6pktinfo_result);
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews}
cc32d38366fa680fc29f9fb17bd3ebe515835445Mark Andrews
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn#if ISC_CMSG_IP_TOS || \
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn defined(ISC_NET_BSD44MSGHDR) && defined(IPV6_TCLASS) && defined(WANT_IPV6)
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstatic inline ISC_SOCKADDR_LEN_T
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntcmsg_len(ISC_SOCKADDR_LEN_T len) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef CMSG_LEN
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User return (CMSG_LEN(len));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#else
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User ISC_SOCKADDR_LEN_T hdrlen;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User /*
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User * Cast NULL so that any pointer arithmetic performed by CMSG_DATA
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User * is correct.
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User */
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User hdrlen = (ISC_SOCKADDR_LEN_T)CMSG_DATA(((struct cmsghdr *)NULL));
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User return (hdrlen + len);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#endif
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstatic inline ISC_SOCKADDR_LEN_T
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntcmsg_space(ISC_SOCKADDR_LEN_T len) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef CMSG_SPACE
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User return (CMSG_SPACE(len));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#else
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User struct msghdr msg;
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User struct cmsghdr *cmsgp;
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User /*
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User * XXX: The buffer length is an ad-hoc value, but should be enough
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User * in a practical sense.
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User */
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User char dummybuf[sizeof(struct cmsghdr) + 1024];
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User memset(&msg, 0, sizeof(msg));
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User msg.msg_control = dummybuf;
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User msg.msg_controllen = sizeof(dummybuf);
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User cmsgp = (struct cmsghdr *)dummybuf;
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User cmsgp->cmsg_len = cmsg_len(len);
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User cmsgp = CMSG_NXTHDR(&msg, cmsgp);
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User if (cmsgp != NULL)
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User return ((char *)cmsgp - (char *)msg.msg_control);
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User else
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User return (0);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#endif
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef ISC_NET_BSD44MSGHDR
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews/*
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews * Make a fd non-blocking.
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews */
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrewsstatic isc_result_t
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrewsmake_nonblock(int fd) {
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User int ret;
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User int flags;
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User char strbuf[ISC_STRERRORSIZE];
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews#ifdef USE_FIONBIO_IOCTL
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User int on = 1;
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User ret = ioctl(fd, FIONBIO, (char *)&on);
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews#else
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User flags = fcntl(fd, F_GETFL, 0);
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User flags |= PORT_NONBLOCK;
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User ret = fcntl(fd, F_SETFL, flags);
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews#endif
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User if (ret == -1) {
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User isc__strerror(errno, strbuf, sizeof(strbuf));
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User UNEXPECTED_ERROR(__FILE__, __LINE__,
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews#ifdef USE_FIONBIO_IOCTL
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User "ioctl(%d, FIONBIO, &on): %s", fd,
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews#else
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User "fcntl(%d, F_SETFL, %d): %s", fd, flags,
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews#endif
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User strbuf);
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User return (ISC_R_UNEXPECTED);
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User }
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews
0a00c3eb03464988821a0b6817b63ddb3c090890Tinderbox User return (ISC_R_SUCCESS);
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews}
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstatic isc_boolean_t
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntcmsgsend(int s, int level, int type, struct addrinfo *res) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt char strbuf[ISC_STRERRORSIZE];
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt struct sockaddr_storage ss;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ISC_SOCKADDR_LEN_T len = sizeof(ss);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt struct msghdr msg;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt union {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt struct cmsghdr h;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt unsigned char b[256];
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt } control;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt struct cmsghdr *cmsgp;
fd2f4551d9498e1dce8e44a24e5e886ef2aa75cbMark Andrews int dscp = (46 << 2); /* Expedited forwarding. */
b8cf73a3b3e21d61f5a06670551ac22e61bcc4b1Mark Andrews struct iovec iovec;
b8cf73a3b3e21d61f5a06670551ac22e61bcc4b1Mark Andrews char buf[1] = { 0 };
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews isc_result_t result;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (bind(s, res->ai_addr, res->ai_addrlen) < 0) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc__strerror(errno, strbuf, sizeof(strbuf));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(10),
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt "bind: %s", strbuf);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return (ISC_FALSE);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt }
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (getsockname(s, (struct sockaddr *)&ss, &len) < 0) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc__strerror(errno, strbuf, sizeof(strbuf));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(10),
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt "getsockname: %s", strbuf);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return (ISC_FALSE);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt }
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
b8cf73a3b3e21d61f5a06670551ac22e61bcc4b1Mark Andrews iovec.iov_base = buf;
b8cf73a3b3e21d61f5a06670551ac22e61bcc4b1Mark Andrews iovec.iov_len = sizeof(buf);
b8cf73a3b3e21d61f5a06670551ac22e61bcc4b1Mark Andrews
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt memset(&msg, 0, sizeof(msg));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt msg.msg_name = (struct sockaddr *)&ss;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt msg.msg_namelen = len;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt msg.msg_iov = &iovec;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt msg.msg_iovlen = 1;
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User msg.msg_control = (void*)&control;
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews msg.msg_controllen = 0;
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User msg.msg_flags = 0;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt cmsgp = msg.msg_control;
7ade93c3280551115d08d2b3879a1c21d949166aEvan Hunt
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews switch (type) {
7ade93c3280551115d08d2b3879a1c21d949166aEvan Hunt#ifdef IP_TOS
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews case IP_TOS:
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews memset(cmsgp, 0, cmsg_space(sizeof(char)));
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews cmsgp->cmsg_level = level;
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews cmsgp->cmsg_type = type;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt cmsgp->cmsg_len = cmsg_len(sizeof(char));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt *(unsigned char*)CMSG_DATA(cmsgp) = dscp;
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews msg.msg_controllen += cmsg_space(sizeof(char));
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews break;
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews#endif
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews#ifdef IPV6_TCLASS
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews case IPV6_TCLASS:
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews memset(cmsgp, 0, cmsg_space(sizeof(dscp)));
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews cmsgp->cmsg_level = level;
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews cmsgp->cmsg_type = type;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt cmsgp->cmsg_len = cmsg_len(sizeof(dscp));
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(CMSG_DATA(cmsgp), &dscp, sizeof(dscp));
b5edc023a1bb8066d86777dd40fd4555e285de57Mark Andrews msg.msg_controllen += cmsg_space(sizeof(dscp));
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews break;
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews#endif
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews default:
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews INSIST(0);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt }
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (sendmsg(s, &msg, 0) < 0) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt int debug = ISC_LOG_DEBUG(10);
fd2f4551d9498e1dce8e44a24e5e886ef2aa75cbMark Andrews const char *typestr;
fd2f4551d9498e1dce8e44a24e5e886ef2aa75cbMark Andrews const char *msgstr;
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews switch (errno) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef ENOPROTOOPT
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews case ENOPROTOOPT:
b8cf73a3b3e21d61f5a06670551ac22e61bcc4b1Mark Andrews#endif
b8cf73a3b3e21d61f5a06670551ac22e61bcc4b1Mark Andrews#ifdef EOPNOTSUPP
b8cf73a3b3e21d61f5a06670551ac22e61bcc4b1Mark Andrews case EOPNOTSUPP:
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#endif
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews case EINVAL:
f1b29d8428362842c429157b4925e529463eab4cEvan Hunt case EPERM:
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews break;
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews default:
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews debug = ISC_LOG_NOTICE;
368c4556c8a61e1406002a26afa4307adc60545aMark Andrews }
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc__strerror(errno, strbuf, sizeof(strbuf));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (debug != ISC_LOG_NOTICE) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(10),
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt "sendmsg: %s", strbuf);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt } else {
fd2f4551d9498e1dce8e44a24e5e886ef2aa75cbMark Andrews typestr = (type == IP_TOS) ? "IP_TOS" : "IPV6_TCLASS";
fd2f4551d9498e1dce8e44a24e5e886ef2aa75cbMark Andrews msgstr = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
fd2f4551d9498e1dce8e44a24e5e886ef2aa75cbMark Andrews ISC_MSG_FAILED, "failed");
fd2f4551d9498e1dce8e44a24e5e886ef2aa75cbMark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__, "probing "
fd2f4551d9498e1dce8e44a24e5e886ef2aa75cbMark Andrews "sendmsg() with %s=%02x %s: %s",
fd2f4551d9498e1dce8e44a24e5e886ef2aa75cbMark Andrews typestr, dscp, msgstr, strbuf);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt }
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return (ISC_FALSE);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt }
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews /*
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews * Make sure the message actually got sent.
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews */
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews result = make_nonblock(s);
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews RUNTIME_CHECK(result == ISC_R_SUCCESS);
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews iovec.iov_base = buf;
b8cf73a3b3e21d61f5a06670551ac22e61bcc4b1Mark Andrews iovec.iov_len = sizeof(buf);
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews memset(&msg, 0, sizeof(msg));
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews msg.msg_name = (struct sockaddr *)&ss;
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews msg.msg_namelen = sizeof(ss);
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews msg.msg_iov = &iovec;
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews msg.msg_iovlen = 1;
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews msg.msg_control = NULL;
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews msg.msg_controllen = 0;
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews msg.msg_flags = 0;
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews if (recvmsg(s, &msg, 0) < 0)
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews return (ISC_FALSE);
d8c1e4eccf5bf88a3b4f8dc4a24391b5712bb3a3Mark Andrews
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return (ISC_TRUE);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#endif
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn#endif
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstatic void
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunttry_dscp_v4(void) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef IP_TOS
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt char strbuf[ISC_STRERRORSIZE];
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt struct addrinfo hints, *res0;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt int s, dscp = 0, n;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef IP_RECVTOS
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt int on = 1;
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* IP_RECVTOS */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt memset(&hints, 0, sizeof(hints));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt hints.ai_family = AF_INET;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt hints.ai_socktype = SOCK_DGRAM;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt hints.ai_protocol = IPPROTO_UDP;
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews#ifdef AI_NUMERICHOST
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews#else
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews hints.ai_flags = AI_PASSIVE;
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews#endif
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt n = getaddrinfo("127.0.0.1", NULL, &hints, &res0);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (n != 0 || res0 == NULL) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(10),
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt "getaddrinfo(127.0.0.1): %s", gai_strerror(n));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt }
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt s = socket(res0->ai_family, res0->ai_socktype, res0->ai_protocol);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (s == -1) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc__strerror(errno, strbuf, sizeof(strbuf));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(10),
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt "socket: %s", strbuf);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt freeaddrinfo(res0);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt }
7ade93c3280551115d08d2b3879a1c21d949166aEvan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (setsockopt(s, IPPROTO_IP, IP_TOS, &dscp, sizeof(dscp)) == 0)
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt dscp_result |= ISC_NET_DSCPSETV4;
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef IP_RECVTOS
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt on = 1;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (setsockopt(s, IPPROTO_IP, IP_RECVTOS, &on, sizeof(on)) == 0)
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt dscp_result |= ISC_NET_DSCPRECVV4;
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* IP_RECVTOS */
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef ISC_NET_BSD44MSGHDR
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#if ISC_CMSG_IP_TOS
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (cmsgsend(s, IPPROTO_IP, IP_TOS, res0))
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt dscp_result |= ISC_NET_DSCPPKTV4;
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* ISC_CMSG_IP_TOS */
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* ISC_NET_BSD44MSGHDR */
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt freeaddrinfo(res0);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt close(s);
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* IP_TOS */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstatic void
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunttry_dscp_v6(void) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef ISC_PLATFORM_HAVEIPV6
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef WANT_IPV6
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef IPV6_TCLASS
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt char strbuf[ISC_STRERRORSIZE];
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt struct addrinfo hints, *res0;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt int s, dscp = 0, n;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#if defined(IPV6_RECVTCLASS)
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt int on = 1;
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* IPV6_RECVTCLASS */
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt memset(&hints, 0, sizeof(hints));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt hints.ai_family = AF_INET6;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt hints.ai_socktype = SOCK_DGRAM;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt hints.ai_protocol = IPPROTO_UDP;
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews#ifdef AI_NUMERICHOST
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews#else
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews hints.ai_flags = AI_PASSIVE;
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews#endif
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt n = getaddrinfo("::1", NULL, &hints, &res0);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (n != 0 || res0 == NULL) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(10),
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt "getaddrinfo(::1): %s", gai_strerror(n));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt }
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt s = socket(res0->ai_family, res0->ai_socktype, res0->ai_protocol);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (s == -1) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc__strerror(errno, strbuf, sizeof(strbuf));
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(10),
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt "socket: %s", strbuf);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt freeaddrinfo(res0);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt }
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &dscp, sizeof(dscp)) == 0)
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt dscp_result |= ISC_NET_DSCPSETV6;
313b0ea9f258edd8530f4454c69e6ba194280162Tinderbox User
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef IPV6_RECVTCLASS
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt on = 1;
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVTCLASS, &on, sizeof(on)) == 0)
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt dscp_result |= ISC_NET_DSCPRECVV6;
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* IPV6_RECVTCLASS */
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt#ifdef ISC_NET_BSD44MSGHDR
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt if (cmsgsend(s, IPPROTO_IPV6, IPV6_TCLASS, res0))
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt dscp_result |= ISC_NET_DSCPPKTV6;
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* ISC_NET_BSD44MSGHDR */
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt freeaddrinfo(res0);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt close(s);
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* IPV6_TCLASS */
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* WANT_IPV6 */
89cf81b4625c574f60c21e0dce12b150f3c5583cMark Andrews#endif /* ISC_PLATFORM_HAVEIPV6 */
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstatic void
b454c0319685041db3f3e8fd7671e1b364fd20c5Evan Hunttry_dscp(void) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt try_dscp_v4();
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt try_dscp_v6();
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntstatic void
b454c0319685041db3f3e8fd7671e1b364fd20c5Evan Huntinitialize_dscp(void) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt RUNTIME_CHECK(isc_once_do(&once_dscp, try_dscp) == ISC_R_SUCCESS);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntunsigned int
67adc03ef81fb610f8df093b17f55275ee816754Evan Huntisc_net_probedscp(void) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt initialize_dscp();
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt return (dscp_result);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt}
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#if defined(USE_SYSCTL_PORTRANGE)
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#if defined(HAVE_SYSCTLBYNAME)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int port_low, port_high;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 size_t portlen;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 const char *sysctlname_lowport, *sysctlname_hiport;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (af == AF_INET) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 sysctlname_lowport = SYSCTL_V4PORTRANGE_LOW;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 sysctlname_hiport = SYSCTL_V4PORTRANGE_HIGH;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 sysctlname_lowport = SYSCTL_V6PORTRANGE_LOW;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 sysctlname_hiport = SYSCTL_V6PORTRANGE_HIGH;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews portlen = sizeof(port_low);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (sysctlbyname(sysctlname_lowport, &port_low, &portlen,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NULL, 0) < 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_FAILURE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews portlen = sizeof(port_high);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (sysctlbyname(sysctlname_hiport, &port_high, &portlen,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NULL, 0) < 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_FAILURE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if ((port_low & ~0xffff) != 0 || (port_high & ~0xffff) != 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_RANGE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *low = (in_port_t)port_low;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *high = (in_port_t)port_high;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#else /* !HAVE_SYSCTLBYNAME */
64ecc88345766e124e1fb053dbf4e36550471f83Evan Huntstatic isc_result_t
64ecc88345766e124e1fb053dbf4e36550471f83Evan Huntgetudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) {
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt int mib_lo4[4] = SYSCTL_V4PORTRANGE_LOW;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt int mib_hi4[4] = SYSCTL_V4PORTRANGE_HIGH;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt int mib_lo6[4] = SYSCTL_V6PORTRANGE_LOW;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt int mib_hi6[4] = SYSCTL_V6PORTRANGE_HIGH;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt int *mib_lo, *mib_hi, miblen;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt int port_low, port_high;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt size_t portlen;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt if (af == AF_INET) {
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt mib_lo = mib_lo4;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt mib_hi = mib_hi4;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt miblen = sizeof(mib_lo4) / sizeof(mib_lo4[0]);
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt } else {
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt mib_lo = mib_lo6;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt mib_hi = mib_hi6;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt miblen = sizeof(mib_lo6) / sizeof(mib_lo6[0]);
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt }
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews portlen = sizeof(port_low);
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt if (sysctl(mib_lo, miblen, &port_low, &portlen, NULL, 0) < 0) {
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt return (ISC_R_FAILURE);
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt }
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews portlen = sizeof(port_high);
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt if (sysctl(mib_hi, miblen, &port_high, &portlen, NULL, 0) < 0) {
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt return (ISC_R_FAILURE);
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt }
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt if ((port_low & ~0xffff) != 0 || (port_high & ~0xffff) != 0)
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt return (ISC_R_RANGE);
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt *low = (in_port_t) port_low;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt *high = (in_port_t) port_high;
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt return (ISC_R_SUCCESS);
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt}
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#endif /* HAVE_SYSCTLBYNAME */
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#endif /* USE_SYSCTL_PORTRANGE */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int result = ISC_R_FAILURE;
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews#if !defined(USE_SYSCTL_PORTRANGE) && defined(__linux)
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews FILE *fp;
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews#endif
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(low != NULL && high != NULL);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
64ecc88345766e124e1fb053dbf4e36550471f83Evan Hunt#if defined(USE_SYSCTL_PORTRANGE)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = getudpportrange_sysctl(af, low, high);
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews#elif defined(__linux)
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews UNUSED(af);
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews /*
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews * Linux local ports are address family agnostic.
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews */
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews fp = fopen("/proc/sys/net/ipv4/ip_local_port_range", "r");
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews if (fp != NULL) {
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews int n;
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews unsigned int l, h;
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews n = fscanf(fp, "%u %u", &l, &h);
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews if (n == 2 && (l & ~0xffff) == 0 && (h & ~0xffff) == 0) {
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews *low = l;
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews *high = h;
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews result = ISC_R_SUCCESS;
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews }
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews fclose(fp);
e77e44954909dd2e0af1ce724e01f4199ae1e9c0Mark Andrews }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#else
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 UNUSED(af);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#endif
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *low = ISC_NET_PORTRANGELOW;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *high = ISC_NET_PORTRANGEHIGH;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS); /* we currently never fail in this function */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrewsvoid
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrewsisc_net_disableipv4(void) {
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews initialize();
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews if (ipv4_result == ISC_R_SUCCESS)
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews ipv4_result = ISC_R_DISABLED;
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews}
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrewsvoid
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrewsisc_net_disableipv6(void) {
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews initialize();
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews if (ipv6_result == ISC_R_SUCCESS)
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews ipv6_result = ISC_R_DISABLED;
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews}
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrewsvoid
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrewsisc_net_enableipv4(void) {
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews initialize();
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews if (ipv4_result == ISC_R_DISABLED)
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews ipv4_result = ISC_R_SUCCESS;
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews}
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrewsvoid
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrewsisc_net_enableipv6(void) {
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews initialize();
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews if (ipv6_result == ISC_R_DISABLED)
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews ipv6_result = ISC_R_SUCCESS;
0ffaee887ff5674b8c3bb0435ae838f641981706Mark Andrews}