net.c revision 2bd63eca275f4292452f6cb79cfb00a1065dd069
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews/*
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Copyright (C) 2004, 2005, 2007-2009, 2011-2015 Internet Systems Consortium, Inc. ("ISC")
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Copyright (C) 1999-2003 Internet Software Consortium.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews *
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * purpose with or without fee is hereby granted, provided that the above
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * copyright notice and this permission notice appear in all copies.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews *
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * PERFORMANCE OF THIS SOFTWARE.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews/* $Id$ */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <config.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <errno.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <unistd.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <isc/log.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <isc/msgs.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <isc/net.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <isc/once.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <isc/strerror.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <isc/string.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#include <isc/util.h>
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews/*%
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence * Definitions about UDP port range specification. This is a total mess of
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * portability variants: some use sysctl (but the sysctl names vary), some use
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews * system-specific interfaces, some have the same interface for IPv4 and IPv6,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * some separate them, etc...
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews/*%
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * The last resort defaults: use all non well known port space
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#ifndef ISC_NET_PORTRANGELOW
ac4e7a61a8dfc490d82b2fa0d24473953f7b4817Mark Andrews#define ISC_NET_PORTRANGELOW 1024
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#endif /* ISC_NET_PORTRANGELOW */
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews#ifndef ISC_NET_PORTRANGEHIGH
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews#define ISC_NET_PORTRANGEHIGH 65535
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews#endif /* ISC_NET_PORTRANGEHIGH */
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrewsconst struct in6_addr isc_net_in6addrany = IN6ADDR_ANY_INIT;
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews#endif
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic isc_once_t once = ISC_ONCE_INIT;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic isc_once_t once_ipv6only = ISC_ONCE_INIT;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic isc_once_t once_ipv6pktinfo = ISC_ONCE_INIT;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic isc_result_t ipv4_result = ISC_R_NOTFOUND;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic isc_result_t ipv6_result = ISC_R_NOTFOUND;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsstatic isc_result_t ipv6only_result = ISC_R_NOTFOUND;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsstatic isc_result_t ipv6pktinfo_result = ISC_R_NOTFOUND;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsvoid InitSockets(void);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic isc_result_t
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewstry_proto(int domain) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews SOCKET s;
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews char strbuf[ISC_STRERRORSIZE];
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews int errval;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews s = socket(domain, SOCK_STREAM, IPPROTO_TCP);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (s == INVALID_SOCKET) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews errval = WSAGetLastError();
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews switch (errval) {
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews case WSAEAFNOSUPPORT:
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews case WSAEPROTONOSUPPORT:
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews case WSAEINVAL:
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews return (ISC_R_NOTFOUND);
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews default:
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews isc__strerror(errval, strbuf, sizeof(strbuf));
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews "socket() %s: %s",
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews isc_msgcat_get(isc_msgcat,
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_MSGSET_GENERAL,
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_MSG_FAILED,
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews "failed"),
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews strbuf);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews return (ISC_R_UNEXPECTED);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews }
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews }
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews closesocket(s);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews return (ISC_R_SUCCESS);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic void
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsinitialize_action(void) {
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews InitSockets();
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ipv4_result = try_proto(PF_INET);
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews#ifdef ISC_PLATFORM_HAVEIPV6
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#ifdef WANT_IPV6
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews ipv6_result = try_proto(PF_INET6);
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#endif
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews#endif
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews#endif
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews}
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsstatic void
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsinitialize(void) {
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsisc_result_t
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsisc_net_probeipv4(void) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews initialize();
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (ipv4_result);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews}
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsisc_result_t
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsisc_net_probeipv6(void) {
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews initialize();
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews return (ipv6_result);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews}
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrewsisc_result_t
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrewsisc_net_probeunix(void) {
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews return (ISC_R_NOTFOUND);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#ifdef ISC_PLATFORM_HAVEIPV6
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#ifdef WANT_IPV6
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsstatic void
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewstry_ipv6only(void) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#ifdef IPV6_V6ONLY
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews SOCKET s;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews int on;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews char strbuf[ISC_STRERRORSIZE];
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#endif
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews isc_result_t result;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews result = isc_net_probeipv6();
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (result != ISC_R_SUCCESS) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ipv6only_result = result;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews }
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews#ifndef IPV6_V6ONLY
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff ipv6only_result = ISC_R_NOTFOUND;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#else
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews /* check for TCP sockets */
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews s = socket(PF_INET6, SOCK_STREAM, 0);
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews if (s == INVALID_SOCKET) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc__strerror(errno, strbuf, sizeof(strbuf));
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews "socket() %s: %s",
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews isc_msgcat_get(isc_msgcat,
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews ISC_MSGSET_GENERAL,
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews ISC_MSG_FAILED,
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews "failed"),
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews strbuf);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ipv6only_result = ISC_R_UNEXPECTED;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews return;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews }
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews on = 1;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)&on,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews sizeof(on)) < 0) {
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews ipv6only_result = ISC_R_NOTFOUND;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews goto close;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews }
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews closesocket(s);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews /* check for UDP sockets */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews s = socket(PF_INET6, SOCK_DGRAM, 0);
440164d3e36353a4b9801fcc05fe66b6cf1fb8ceMark Andrews if (s == INVALID_SOCKET) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews isc__strerror(errno, strbuf, sizeof(strbuf));
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews "socket() %s: %s",
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews isc_msgcat_get(isc_msgcat,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ISC_MSGSET_GENERAL,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ISC_MSG_FAILED,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews "failed"),
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews strbuf);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ipv6only_result = ISC_R_UNEXPECTED;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews }
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews on = 1;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)&on,
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews sizeof(on)) < 0) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ipv6only_result = ISC_R_NOTFOUND;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews goto close;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews }
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ipv6only_result = ISC_R_SUCCESS;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsclose:
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews closesocket(s);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#endif /* IPV6_V6ONLY */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graffstatic void
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsinitialize_ipv6only(void) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews RUNTIME_CHECK(isc_once_do(&once_ipv6only,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews try_ipv6only) == ISC_R_SUCCESS);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff#ifdef __notyet__
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews/*
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * XXXMPA requires win32/socket.c to be updated to support
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * WSASendMsg and WSARecvMsg which are themselves Winsock
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * and compiler version dependent.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsstatic void
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewstry_ipv6pktinfo(void) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews SOCKET s;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews int on;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews char strbuf[ISC_STRERRORSIZE];
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews isc_result_t result;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews int optname;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews result = isc_net_probeipv6();
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews if (result != ISC_R_SUCCESS) {
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ipv6pktinfo_result = result;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews return;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews }
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews /* we only use this for UDP sockets */
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews if (s == INVALID_SOCKET) {
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews isc__strerror(errno, strbuf, sizeof(strbuf));
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews "socket() %s: %s",
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews isc_msgcat_get(isc_msgcat,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ISC_MSGSET_GENERAL,
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ISC_MSG_FAILED,
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews "failed"),
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews strbuf);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews ipv6pktinfo_result = ISC_R_UNEXPECTED;
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrews return;
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews }
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#ifdef IPV6_RECVPKTINFO
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews optname = IPV6_RECVPKTINFO;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#else
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews optname = IPV6_PKTINFO;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#endif
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews on = 1;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews if (setsockopt(s, IPPROTO_IPV6, optname, (const char *) &on,
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews sizeof(on)) < 0) {
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews ipv6pktinfo_result = ISC_R_NOTFOUND;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews goto close;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews }
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews ipv6pktinfo_result = ISC_R_SUCCESS;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsclose:
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews closesocket(s);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews return;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews}
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsstatic void
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsinitialize_ipv6pktinfo(void) {
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews RUNTIME_CHECK(isc_once_do(&once_ipv6pktinfo,
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews try_ipv6pktinfo) == ISC_R_SUCCESS);
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews}
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#endif /* __notyet__ */
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#endif /* WANT_IPV6 */
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#endif /* ISC_PLATFORM_HAVEIPV6 */
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsisc_result_t
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsisc_net_probe_ipv6only(void) {
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#ifdef ISC_PLATFORM_HAVEIPV6
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#ifdef WANT_IPV6
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews initialize_ipv6only();
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#else
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews ipv6only_result = ISC_R_NOTFOUND;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#endif
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews#endif
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews return (ipv6only_result);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrews
4be19dcd14cea678511f1d1b269ab89273e987eeMark Andrewsisc_result_t
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsisc_net_probe_ipv6pktinfo(void) {
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#ifdef __notyet__
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#ifdef ISC_PLATFORM_HAVEIPV6
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews#ifdef WANT_IPV6
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews initialize_ipv6pktinfo();
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#else
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ipv6pktinfo_result = ISC_R_NOTFOUND;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#endif
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#endif
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews#endif /* __notyet__ */
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (ipv6pktinfo_result);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsisc_result_t
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrewsisc_net_getudpportrange(int af, in_port_t *low, in_port_t *high) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews int result = ISC_R_FAILURE;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews REQUIRE(low != NULL && high != NULL);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews UNUSED(af);
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (result != ISC_R_SUCCESS) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews *low = ISC_NET_PORTRANGELOW;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews *high = ISC_NET_PORTRANGEHIGH;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews }
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (ISC_R_SUCCESS); /* we currently never fail in this function */
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews}
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrewsvoid
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsisc_net_disableipv4(void) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews initialize();
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (ipv4_result == ISC_R_SUCCESS)
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews ipv4_result = ISC_R_DISABLED;
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews}
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsvoid
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsisc_net_disableipv6(void) {
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews initialize();
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (ipv6_result == ISC_R_SUCCESS)
34ee961fa2f0f5f2ee3cff40fdb4d7d7b48b7728Mark Andrews ipv6_result = ISC_R_DISABLED;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsvoid
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsisc_net_enableipv4(void) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews initialize();
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews if (ipv4_result == ISC_R_DISABLED)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ipv4_result = ISC_R_SUCCESS;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsvoid
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsisc_net_enableipv6(void) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews initialize();
a5c30de2601a1d130a15a78cf3dc7610a02b2d85Mark Andrews if (ipv6_result == ISC_R_DISABLED)
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews ipv6_result = ISC_R_SUCCESS;
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews}
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsunsigned int
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrewsisc_net_probedscp(void) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews return (0);
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff}
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff