1999-07-08 02:45:47 +00:00
|
|
|
/*
|
2001-01-09 22:01:04 +00:00
|
|
|
* Copyright (C) 1999-2001 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
1999-07-08 02:45:47 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2000-07-27 09:55:03 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-07-08 02:45:47 +00:00
|
|
|
*/
|
|
|
|
|
2001-01-17 02:11:20 +00:00
|
|
|
/* $Id: net.c,v 1.18 2001/01/17 02:11:20 marka Exp $ */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-07-08 02:45:47 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2000-12-19 01:36:52 +00:00
|
|
|
#include <isc/log.h>
|
2000-12-06 00:30:32 +00:00
|
|
|
#include <isc/msgs.h>
|
1999-07-08 02:45:47 +00:00
|
|
|
#include <isc/net.h>
|
|
|
|
#include <isc/once.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/string.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-07-08 02:45:47 +00:00
|
|
|
|
2000-03-22 22:07:17 +00:00
|
|
|
#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
|
|
|
|
const struct in6_addr isc_net_in6addrany = IN6ADDR_ANY_INIT;
|
|
|
|
#endif
|
|
|
|
|
1999-07-08 02:45:47 +00:00
|
|
|
static isc_once_t once = ISC_ONCE_INIT;
|
|
|
|
static isc_result_t ipv4_result = ISC_R_NOTFOUND;
|
|
|
|
static isc_result_t ipv6_result = ISC_R_NOTFOUND;
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
try_proto(int domain) {
|
|
|
|
int s;
|
2000-12-19 01:36:52 +00:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
1999-07-08 02:45:47 +00:00
|
|
|
|
|
|
|
s = socket(domain, SOCK_STREAM, 0);
|
|
|
|
if (s == -1) {
|
|
|
|
switch (errno) {
|
|
|
|
#ifdef EAFNOSUPPORT
|
|
|
|
case EAFNOSUPPORT:
|
|
|
|
#endif
|
2000-01-04 20:15:53 +00:00
|
|
|
#ifdef EPROTONOSUPPORT
|
|
|
|
case EPROTONOSUPPORT:
|
|
|
|
#endif
|
1999-07-08 02:45:47 +00:00
|
|
|
#ifdef EINVAL
|
|
|
|
case EINVAL:
|
|
|
|
#endif
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
default:
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2000-12-06 00:30:32 +00:00
|
|
|
"socket() %s: %s",
|
|
|
|
isc_msgcat_get(isc_msgcat,
|
|
|
|
ISC_MSGSET_GENERAL,
|
|
|
|
ISC_MSG_FAILED,
|
|
|
|
"failed"),
|
1999-07-08 02:45:47 +00:00
|
|
|
strerror(errno));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-19 01:36:52 +00:00
|
|
|
#ifdef ISC_PLATFORM_HAVEIPV6
|
|
|
|
#ifdef WANT_IPV6
|
|
|
|
#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
|
|
|
|
if (domain == PF_INET6) {
|
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if IPv6 is broken, as is common on Linux.
|
|
|
|
*/
|
2000-12-19 19:29:13 +00:00
|
|
|
len = sizeof(sin6);
|
|
|
|
if (getsockname(s, (struct sockaddr *)&sin6, (void *)&len) < 0) {
|
2000-12-19 01:36:52 +00:00
|
|
|
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
|
|
|
ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
|
|
|
|
"Retrieving the address of an IPv6 "
|
|
|
|
"socket from the kernel failed.");
|
|
|
|
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
|
|
|
ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
|
|
|
|
"IPv6 support is disabled.");
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
} else {
|
|
|
|
if (len == sizeof(struct sockaddr_in6))
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
else {
|
|
|
|
isc_log_write(isc_lctx,
|
|
|
|
ISC_LOGCATEGORY_GENERAL,
|
|
|
|
ISC_LOGMODULE_SOCKET,
|
|
|
|
ISC_LOG_ERROR,
|
|
|
|
"IPv6 structures in kernel and "
|
|
|
|
"user space do not match.");
|
|
|
|
isc_log_write(isc_lctx,
|
|
|
|
ISC_LOGCATEGORY_GENERAL,
|
|
|
|
ISC_LOGMODULE_SOCKET,
|
|
|
|
ISC_LOG_ERROR,
|
|
|
|
"IPv6 support is disabled.");
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close(s);
|
|
|
|
|
|
|
|
return (result);
|
1999-07-08 02:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
initialize_action(void) {
|
|
|
|
ipv4_result = try_proto(PF_INET);
|
1999-10-30 03:53:19 +00:00
|
|
|
#ifdef ISC_PLATFORM_HAVEIPV6
|
2000-09-15 20:52:27 +00:00
|
|
|
#ifdef WANT_IPV6
|
2000-05-06 01:30:32 +00:00
|
|
|
#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
|
1999-07-08 02:45:47 +00:00
|
|
|
ipv6_result = try_proto(PF_INET6);
|
2000-05-06 01:30:32 +00:00
|
|
|
#endif
|
1999-07-08 02:45:47 +00:00
|
|
|
#endif
|
2000-09-15 20:52:27 +00:00
|
|
|
#endif
|
1999-07-08 02:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
initialize(void) {
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
1999-07-19 23:54:09 +00:00
|
|
|
isc_net_probeipv4(void) {
|
1999-07-08 02:45:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the system's kernel supports IPv4.
|
|
|
|
*/
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
return (ipv4_result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
1999-07-19 23:54:09 +00:00
|
|
|
isc_net_probeipv6(void) {
|
1999-07-08 02:45:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the system's kernel supports IPv6.
|
|
|
|
*/
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
return (ipv6_result);
|
|
|
|
}
|