/*
* Copyright (C) 2004-2009, 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2003 Internet Software Consortium.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/* $Id$ */
/*! \file
* \brief
* Obtain the list of network interfaces using the SIOCGLIFCONF ioctl.
* See netintro(4).
*/
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
#else
#endif
#ifdef ISC_PLATFORM_HAVEIF_LADDRREQ
#else
#endif
#endif
struct isc_interfaceiter {
int mode;
int socket;
SIOCGIFCONF data */
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
int socket6;
SIOCGLIFCONF data */
#endif
#ifdef HAVE_TRUCLUSTER
#endif
#ifdef __linux
#endif
};
#ifdef HAVE_TRUCLUSTER
#endif
/*%
* Size of buffer for SIOCGLIFCONF, in bytes. We assume no sane system
* will have more than a megabyte of interface configuration data.
*/
#ifdef __linux
#ifndef IF_NAMESIZE
# ifdef IFNAMSIZ
# else
# endif
#endif
#endif
static isc_result_t
for (;;) {
return (ISC_R_NOMEMORY);
/*
* conversion". It comes from its own macro definition,
* and is really hard to shut up.
*/
== -1) {
"get interface "
"configuration: %s"),
strbuf);
goto unexpected;
}
/*
* EINVAL. Retry with a bigger buffer.
*/
} else {
/*
* The ioctl succeeded.
* Some OS's just return what will fit rather
* than set EINVAL if the buffer is too small
* to fit all the interfaces in. If
* ifc.lifc_len is too near to the end of the
* buffer we will grow it just in case and
* retry.
*/
break;
}
"get interface "
"configuration: "
"maximum buffer "
"size exceeded"));
goto unexpected;
}
}
return (ISC_R_SUCCESS);
return (ISC_R_UNEXPECTED);
}
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
static isc_result_t
for (;;) {
return (ISC_R_NOMEMORY);
#ifdef ISC_HAVE_LIFC_FAMILY
#endif
#ifdef ISC_HAVE_LIFC_FLAGS
#endif
/*
* conversion". It comes from its own macro definition,
* and is really hard to shut up.
*/
== -1) {
#ifdef __hpux
/*
* IPv6 interface scanning is not available on all
* kernels w/ IPv6 sockets.
*/
ISC_LOG_DEBUG(1),
"get interface "
"configuration: %s"),
strbuf);
goto cleanup;
}
#endif
"get interface "
"configuration: %s"),
strbuf);
goto cleanup;
}
/*
* EINVAL. Retry with a bigger buffer.
*/
} else {
/*
* The ioctl succeeded.
* Some OS's just return what will fit rather
* than set EINVAL if the buffer is too small
* to fit all the interfaces in. If
* ifc.ifc_len is too near to the end of the
* buffer we will grow it just in case and
* retry.
*/
break;
}
"get interface "
"configuration: "
"maximum buffer "
"size exceeded"));
goto cleanup;
}
}
return (ISC_R_SUCCESS);
return (result);
}
#endif
return (ISC_R_NOMEMORY);
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
#endif
/*
* Get the interface configuration, allocating more memory if
* necessary.
*/
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
result = isc_net_probeipv6();
if (result == ISC_R_SUCCESS) {
/*
* Create an unbound datagram socket to do the SIOCGLIFCONF
* SIOCGLIFCONF to get IPv6 addresses.
*/
"making interface "
"scan socket: %s"),
strbuf);
goto socket6_failure;
}
goto ioctl6_failure;
}
#endif
"making interface "
"scan socket: %s"),
strbuf);
goto socket_failure;
}
if (result != ISC_R_SUCCESS)
goto ioctl_failure;
/*
* A newly created iterator has an undefined position
* until isc_interfaceiter_first() is called.
*/
#ifdef HAVE_TRUCLUSTER
#endif
#ifdef __linux
#endif
return (ISC_R_SUCCESS);
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
#endif
return (result);
}
#ifdef HAVE_TRUCLUSTER
static void
}
static isc_result_t
return (ISC_R_IGNORE);
return (ISC_R_SUCCESS);
}
#endif
/*
* Get information about the current interface to iter->current.
* If successful, return ISC_R_SUCCESS.
* If the interface has an unsupported address family, or if
* some operation on it fails, return ISC_R_IGNORE to make
* the higher-level iterator code ignore it.
*/
static isc_result_t
int family;
#if !defined(ISC_PLATFORM_HAVEIF_LADDRREQ) && defined(SIOCGLIFADDR)
#else
#endif
#ifdef __linux
return (linux_if_inet6_current(iter));
#else
return (ISC_R_NOMORE);
#endif
}
#if defined(ISC_PLATFORM_HAVEIPV6)
#else
#endif
return (ISC_R_IGNORE);
/*
* If the interface does not have a address ignore it.
*/
switch (family) {
case AF_INET:
return (ISC_R_IGNORE);
break;
case AF_INET6:
sizeof(in6addr_any)) == 0)
return (ISC_R_IGNORE);
break;
}
/*
* Get interface flags.
*/
/*
* conversion. It comes from its own macro definition,
* and is really hard to shut up.
*/
"%s: getting interface flags: %s",
return (ISC_R_IGNORE);
}
#ifdef IFF_POINTOPOINT
#endif
goto inet;
#if !defined(ISC_PLATFORM_HAVEIF_LADDRREQ) && defined(SIOCGLIFADDR)
"%s: getting interface address: %s",
return (ISC_R_IGNORE);
}
#else
"prefix length for %s is unknown "
"(assume 128)"), sabuf);
prefixlen = 128;
#endif
/*
* Netmask already zeroed.
*/
for (i = 0; i < 16; i++) {
if (prefixlen > 8) {
bits = 0;
prefixlen -= 8;
} else {
prefixlen = 0;
}
}
return (ISC_R_SUCCESS);
inet:
return (ISC_R_IGNORE);
#ifdef IFF_POINTOPOINT
/*
* If the interface is point-to-point, get the destination address.
*/
/*
* conversion. It comes from its own macro definition,
* and is really hard to shut up.
*/
< 0) {
"%s: getting "
"destination address: %s"),
return (ISC_R_IGNORE);
}
}
#endif
/*
* Get the network mask.
*/
/*
* conversion. It comes from its own macro definition,
* and is really hard to shut up.
*/
"%s: getting netmask: %s"),
return (ISC_R_IGNORE);
}
return (ISC_R_SUCCESS);
}
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
static isc_result_t
int family;
int fd;
#ifdef ISC_PLATFORM_HAVEIPV6
#else
#endif
return (ISC_R_IGNORE);
/*
* If the interface does not have a address ignore it.
*/
switch (family) {
case AF_INET:
return (ISC_R_IGNORE);
break;
case AF_INET6:
sizeof(in6addr_any)) == 0)
return (ISC_R_IGNORE);
break;
}
/*
* Get interface flags.
*/
else
/*
* conversion. It comes from its own macro definition,
* and is really hard to shut up.
*/
"%s: getting interface flags: %s",
return (ISC_R_IGNORE);
}
#ifdef IFF_POINTOPOINT
#endif
#ifdef IFF_POINTOPOINT
/*
* If the interface is point-to-point, get the destination address.
*/
/*
* conversion. It comes from its own macro definition,
* and is really hard to shut up.
*/
< 0) {
"%s: getting "
"destination address: %s"),
return (ISC_R_IGNORE);
}
}
#endif
/*
* Get the network mask. Netmask already zeroed.
*/
#ifdef lifr_addrlen
/*
* Special case: if the system provides lifr_addrlen member, the
* netmask of an IPv6 address can be derived from the length, since
* an IPv6 address always has a contiguous mask.
*/
int i, bits;
(~0 << bits) & 0xff;
}
return (ISC_R_SUCCESS);
}
#endif
/*
* conversion. It comes from its own macro definition,
* and is really hard to shut up.
*/
"%s: getting netmask: %s"),
return (ISC_R_IGNORE);
}
return (ISC_R_SUCCESS);
}
#endif
static isc_result_t
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
}
#endif
#ifdef HAVE_TRUCLUSTER
return(internal_current_clusteralias(iter));
#endif
return (internal_current4(iter));
}
/*
* Step the iterator to the next interface. Unlike
* isc_interfaceiter_next(), this may leave the iterator
* positioned on an interface that will ultimately
* be ignored. Return ISC_R_NOMORE if there are no more
* interfaces, otherwise ISC_R_SUCCESS.
*/
static isc_result_t
#ifdef ISC_PLATFORM_HAVESALEN
#endif
#ifdef ISC_PLATFORM_HAVESALEN
else
#endif
} else {
#ifdef __linux
return (linux_if_inet6_next(iter));
#else
return (ISC_R_NOMORE);
#endif
}
return (ISC_R_SUCCESS);
}
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
static isc_result_t
#ifdef ISC_PLATFORM_HAVESALEN
#endif
#ifdef ISC_PLATFORM_HAVESALEN
else
#endif
return (ISC_R_NOMORE);
return (ISC_R_SUCCESS);
}
#endif
static isc_result_t
#ifdef HAVE_TRUCLUSTER
int clua_result;
#endif
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
return (ISC_R_SUCCESS);
}
}
#endif
#ifdef HAVE_TRUCLUSTER
&iter->clua_context);
if (clua_result != CLUA_SUCCESS)
return (ISC_R_SUCCESS);
}
#endif
return (internal_next4(iter));
}
static void
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
}
#endif
#ifdef __linux
#endif
}
static
#ifdef HAVE_TRUCLUSTER
int clua_result;
#endif
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
#endif
#ifdef HAVE_TRUCLUSTER
iter->clua_context = 0;
&iter->clua_context);
#endif
#ifdef __linux
#endif
}