mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 05:57:52 +00:00
1065. [func] Runtime support to select new / old style interface
scanning using ioctls.
This commit is contained in:
parent
2f6d1483f6
commit
31d3464c0c
3
CHANGES
3
CHANGES
@ -1,3 +1,6 @@
|
||||
1065. [func] Runtime support to select new / old style interface
|
||||
scanning using ioctls.
|
||||
|
||||
1064. [bug] Do not shutdown active interfaces if we are unable
|
||||
to scan the list of interfaces. [RT #1921]
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: config.h.in,v 1.48 2001/08/30 04:33:17 marka Exp $ */
|
||||
/* $Id: config.h.in,v 1.49 2001/10/22 04:01:26 marka Exp $ */
|
||||
|
||||
/***
|
||||
*** This file is not to be included by any public header files, because
|
||||
@ -165,6 +165,9 @@ int sigwait(const unsigned int *set, int *sig);
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if you have the <net/if6.h> header file. */
|
||||
#undef NET_IF6_H
|
||||
|
||||
/* Define if you have the nsl library (-lnsl). */
|
||||
#undef HAVE_LIBNSL
|
||||
|
||||
|
26
configure.in
26
configure.in
@ -18,7 +18,7 @@ AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
|
||||
esyscmd([sed "s/^/# /" COPYRIGHT])dnl
|
||||
AC_DIVERT_POP()dnl
|
||||
|
||||
AC_REVISION($Revision: 1.304 $)
|
||||
AC_REVISION($Revision: 1.305 $)
|
||||
|
||||
AC_INIT(lib/dns/name.c)
|
||||
AC_PREREQ(2.13)
|
||||
@ -194,7 +194,7 @@ AC_PROG_CC
|
||||
|
||||
AC_HEADER_STDC
|
||||
|
||||
AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h sys/sockio.h sys/select.h sys/sysctl.h)
|
||||
AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h sys/sockio.h sys/select.h sys/sysctl.h net/if6.h)
|
||||
|
||||
AC_C_CONST
|
||||
AC_C_INLINE
|
||||
@ -1109,6 +1109,28 @@ AC_SUBST(ISC_ISCIPV6_O)
|
||||
AC_SUBST(ISC_IPV6_C)
|
||||
AC_SUBST(LWRES_HAVE_SIN6_SCOPE_ID)
|
||||
|
||||
AC_MSG_CHECKING([for struct if_laddrreq])
|
||||
AC_TRY_LINK([
|
||||
#include <sys/types.h>
|
||||
#include <net/if6.h>
|
||||
],[ struct if_laddrreq a; ],
|
||||
[AC_MSG_RESULT(yes)
|
||||
ISC_PLATFORM_HAVEIF_LADDRREQ="#define ISC_PLATFORM_HAVEIF_LADDRREQ 1"],
|
||||
[AC_MSG_RESULT(no)
|
||||
ISC_PLATFORM_HAVEIF_LADDRREQ="#undef ISC_PLATFORM_HAVEIF_LADDRREQ"])
|
||||
AC_SUBST(ISC_PLATFORM_HAVEIF_LADDRREQ)
|
||||
|
||||
AC_MSG_CHECKING([for struct if_laddrconf])
|
||||
AC_TRY_LINK([
|
||||
#include <sys/types.h>
|
||||
#include <net/if6.h>
|
||||
],[ struct if_laddrconf a; ],
|
||||
[AC_MSG_RESULT(yes)
|
||||
ISC_PLATFORM_HAVEIF_LADDRCONF="#define ISC_PLATFORM_HAVEIF_LADDRCONF 1"],
|
||||
[AC_MSG_RESULT(no)
|
||||
ISC_PLATFORM_HAVEIF_LADDRCONF="#undef ISC_PLATFORM_HAVEIF_LADDRCONF"])
|
||||
AC_SUBST(ISC_PLATFORM_HAVEIF_LADDRCONF)
|
||||
|
||||
#
|
||||
# Check for network functions that are often missing. We do this
|
||||
# after the libtool checking, so we can put the right suffix on
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: platform.h.in,v 1.25 2001/10/03 05:08:30 marka Exp $ */
|
||||
/* $Id: platform.h.in,v 1.26 2001/10/22 04:01:29 marka Exp $ */
|
||||
|
||||
#ifndef ISC_PLATFORM_H
|
||||
#define ISC_PLATFORM_H 1
|
||||
@ -153,6 +153,17 @@
|
||||
*/
|
||||
@ISC_PLATFORM_HAVELIFCONF@
|
||||
|
||||
/*
|
||||
* Define if the system has struct if_laddrconf which is a extended struct
|
||||
* ifconf for IPv6.
|
||||
*/
|
||||
@ISC_PLATFORM_HAVEIF_LADDRCONF@
|
||||
|
||||
/*
|
||||
* Define if the system has struct if_laddrreq.
|
||||
*/
|
||||
@ISC_PLATFORM_HAVEIF_LADDRREQ@
|
||||
|
||||
/*
|
||||
* Used to control how extern data is linked; needed for Win32 platforms.
|
||||
*/
|
||||
|
@ -15,44 +15,36 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: ifiter_ioctl.c,v 1.22 2001/10/03 05:08:32 marka Exp $ */
|
||||
/* $Id: ifiter_ioctl.c,v 1.23 2001/10/22 04:01:31 marka Exp $ */
|
||||
|
||||
/*
|
||||
* Obtain the list of network interfaces using the SIOCGLIFCONF ioctl.
|
||||
* See netintro(4).
|
||||
*/
|
||||
|
||||
#ifndef ISC_PLATFORM_HAVELIFCONF
|
||||
/*
|
||||
* HP uses these differently to Sun.
|
||||
*/
|
||||
#undef SIOCGLIFCONF
|
||||
#undef SIOCGLIFADDR
|
||||
#endif
|
||||
|
||||
#ifndef SIOCGLIFCONF
|
||||
#define SIOCGLIFCONF SIOCGIFCONF
|
||||
#define lifc_len ifc_len
|
||||
#define lifc_buf ifc_buf
|
||||
#define lifc_req ifc_req
|
||||
#define lifconf ifconf
|
||||
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
|
||||
#ifdef ISC_PLATFORM_HAVEIF_LADDRCONF
|
||||
#define lifc_len iflc_len
|
||||
#define lifc_buf iflc_buf
|
||||
#define lifc_req iflc_req
|
||||
#define LIFCONF if_laddrconf
|
||||
#else
|
||||
#define ISC_HAVE_LIFC_FAMILY 1
|
||||
#define ISC_HAVE_LIFC_FLAGS 1
|
||||
#endif
|
||||
#ifndef SIOCGLIFADDR
|
||||
#define SIOCGLIFADDR SIOCGIFADDR
|
||||
#define SIOCGLIFFLAGS SIOCGIFFLAGS
|
||||
#define SIOCGLIFDSTADDR SIOCGIFDSTADDR
|
||||
#define SIOCGLIFNETMASK SIOCGIFNETMASK
|
||||
#define lifr_addr ifr_addr
|
||||
#define lifr_name ifr_name
|
||||
#define lifr_dstaddr ifr_dstaddr
|
||||
#define lifr_flags ifr_flags
|
||||
#define ss_family sa_family
|
||||
#define lifreq ifreq
|
||||
#define LIFCONF lifconf
|
||||
#endif
|
||||
|
||||
#ifdef ISC_PLATFORM_HAVEIF_LADDRREQ
|
||||
#define lifr_addr iflr_addr
|
||||
#define lifr_name iflr_name
|
||||
#define lifr_dstaddr iflr_dstaddr
|
||||
#define lifr_flags iflr_flags
|
||||
#define ss_family sa_family
|
||||
#define LIFREQ if_laddrreq
|
||||
#else
|
||||
#define LIFREQ lifreq
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define IFITER_MAGIC ISC_MAGIC('I', 'F', 'I', 'T')
|
||||
#define VALID_IFITER(t) ISC_MAGIC_VALID(t, IFITER_MAGIC)
|
||||
@ -61,7 +53,11 @@ struct isc_interfaceiter {
|
||||
unsigned int magic; /* Magic number. */
|
||||
isc_mem_t *mctx;
|
||||
int socket;
|
||||
struct lifconf ifc;
|
||||
int mode;
|
||||
struct ifconf ifc;
|
||||
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
|
||||
struct LIFCONF lifc;
|
||||
#endif
|
||||
void *buf; /* Buffer for sysctl data. */
|
||||
unsigned int bufsize; /* Bytes allocated. */
|
||||
unsigned int pos; /* Current offset in
|
||||
@ -78,6 +74,164 @@ struct isc_interfaceiter {
|
||||
#define IFCONF_BUFSIZE_INITIAL 4096
|
||||
#define IFCONF_BUFSIZE_MAX 1048576
|
||||
|
||||
static isc_result_t
|
||||
getbuf4(isc_interfaceiter_t *iter) {
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
|
||||
iter->bufsize = IFCONF_BUFSIZE_INITIAL;
|
||||
|
||||
for (;;) {
|
||||
iter->buf = isc_mem_get(iter->mctx, iter->bufsize);
|
||||
if (iter->buf == NULL)
|
||||
return (ISC_R_NOMEMORY);
|
||||
|
||||
memset(&iter->ifc.ifc_len, 0, sizeof(iter->ifc.ifc_len));
|
||||
iter->ifc.ifc_len = iter->bufsize;
|
||||
iter->ifc.ifc_buf = iter->buf;
|
||||
/*
|
||||
* Ignore the HP/UX warning about "interger overflow during
|
||||
* conversion". It comes from its own macro definition,
|
||||
* and is really hard to shut up.
|
||||
*/
|
||||
if (ioctl(iter->socket, SIOCGIFCONF, (char *)&iter->ifc)
|
||||
== -1) {
|
||||
if (errno != EINVAL) {
|
||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_IFITERIOCTL,
|
||||
ISC_MSG_GETIFCONFIG,
|
||||
"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.
|
||||
*/
|
||||
if (iter->ifc.ifc_len + 2 * sizeof(struct ifreq)
|
||||
< iter->bufsize)
|
||||
break;
|
||||
}
|
||||
if (iter->bufsize >= IFCONF_BUFSIZE_MAX) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_IFITERIOCTL,
|
||||
ISC_MSG_BUFFERMAX,
|
||||
"get interface "
|
||||
"configuration: "
|
||||
"maximum buffer "
|
||||
"size exceeded"));
|
||||
goto unexpected;
|
||||
}
|
||||
isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
|
||||
|
||||
iter->bufsize *= 2;
|
||||
}
|
||||
iter->mode = 4;
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
unexpected:
|
||||
isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
|
||||
iter->buf = NULL;
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
getbuf6(isc_interfaceiter_t *iter) {
|
||||
#if !defined(SIOCGLIFCONF) || !defined(SIOCGLIFADDR)
|
||||
UNUSED(iter);
|
||||
return (ISC_R_NOTIMPLEMENTED);
|
||||
#else
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
|
||||
iter->bufsize = IFCONF_BUFSIZE_INITIAL;
|
||||
|
||||
for (;;) {
|
||||
iter->buf = isc_mem_get(iter->mctx, iter->bufsize);
|
||||
if (iter->buf == NULL)
|
||||
return (ISC_R_NOMEMORY);
|
||||
|
||||
memset(&iter->lifc.lifc_len, 0, sizeof(iter->lifc.lifc_len));
|
||||
#ifdef ISC_HAVE_LIFC_FAMILY
|
||||
iter->lifc.lifc_family = AF_UNSPEC;
|
||||
#endif
|
||||
#ifdef ISC_HAVE_LIFC_FLAGS
|
||||
iter->lifc.lifc_flags = 0;
|
||||
#endif
|
||||
iter->lifc.lifc_len = iter->bufsize;
|
||||
iter->lifc.lifc_buf = iter->buf;
|
||||
/*
|
||||
* Ignore the HP/UX warning about "interger overflow during
|
||||
* conversion". It comes from its own macro definition,
|
||||
* and is really hard to shut up.
|
||||
*/
|
||||
if (ioctl(iter->socket, SIOCGLIFCONF, (char *)&iter->lifc)
|
||||
== -1) {
|
||||
if (errno != EINVAL) {
|
||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_IFITERIOCTL,
|
||||
ISC_MSG_GETIFCONFIG,
|
||||
"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.ifc_len is too near to the end of the
|
||||
* buffer we will grow it just in case and
|
||||
* retry.
|
||||
*/
|
||||
if (iter->lifc.lifc_len + 2 * sizeof(struct LIFREQ)
|
||||
< iter->bufsize)
|
||||
break;
|
||||
}
|
||||
if (iter->bufsize >= IFCONF_BUFSIZE_MAX) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_IFITERIOCTL,
|
||||
ISC_MSG_BUFFERMAX,
|
||||
"get interface "
|
||||
"configuration: "
|
||||
"maximum buffer "
|
||||
"size exceeded"));
|
||||
goto unexpected;
|
||||
}
|
||||
isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
|
||||
|
||||
iter->bufsize *= 2;
|
||||
}
|
||||
|
||||
iter->mode = 6;
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
unexpected:
|
||||
isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
|
||||
iter->buf = NULL;
|
||||
return (ISC_R_UNEXPECTED);
|
||||
#endif
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
|
||||
isc_interfaceiter_t *iter;
|
||||
@ -94,6 +248,7 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
|
||||
|
||||
iter->mctx = mctx;
|
||||
iter->buf = NULL;
|
||||
iter->mode = 0;
|
||||
|
||||
/*
|
||||
* Create an unbound datagram socket to do the SIOCGLIFADDR ioctl on.
|
||||
@ -115,76 +270,14 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
|
||||
* Get the interface configuration, allocating more memory if
|
||||
* necessary.
|
||||
*/
|
||||
iter->bufsize = IFCONF_BUFSIZE_INITIAL;
|
||||
|
||||
for (;;) {
|
||||
iter->buf = isc_mem_get(mctx, iter->bufsize);
|
||||
if (iter->buf == NULL) {
|
||||
result = ISC_R_NOMEMORY;
|
||||
goto alloc_failure;
|
||||
}
|
||||
|
||||
memset(&iter->ifc.lifc_len, 0, sizeof(iter->ifc.lifc_len));
|
||||
#ifdef ISC_HAVE_LIFC_FAMILY
|
||||
iter->ifc.lifc_family = AF_UNSPEC;
|
||||
#endif
|
||||
#ifdef ISC_HAVE_LIFC_FLAGS
|
||||
iter->ifc.lifc_flags = 0;
|
||||
#endif
|
||||
iter->ifc.lifc_len = iter->bufsize;
|
||||
iter->ifc.lifc_buf = iter->buf;
|
||||
/*
|
||||
* Ignore the HP/UX warning about "interger overflow during
|
||||
* conversion". It comes from its own macro definition,
|
||||
* and is really hard to shut up.
|
||||
*/
|
||||
if (ioctl(iter->socket, SIOCGLIFCONF, (char *)&iter->ifc)
|
||||
== -1) {
|
||||
if (errno != EINVAL) {
|
||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_IFITERIOCTL,
|
||||
ISC_MSG_GETIFCONFIG,
|
||||
"get interface "
|
||||
"configuration: %s"),
|
||||
strbuf);
|
||||
result = ISC_R_UNEXPECTED;
|
||||
goto ioctl_failure;
|
||||
}
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
if (iter->ifc.lifc_len + 2 * sizeof(struct lifreq)
|
||||
< iter->bufsize)
|
||||
break;
|
||||
}
|
||||
if (iter->bufsize >= IFCONF_BUFSIZE_MAX) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_IFITERIOCTL,
|
||||
ISC_MSG_BUFFERMAX,
|
||||
"get interface "
|
||||
"configuration: "
|
||||
"maximum buffer "
|
||||
"size exceeded"));
|
||||
result = ISC_R_UNEXPECTED;
|
||||
goto ioctl_failure;
|
||||
}
|
||||
isc_mem_put(mctx, iter->buf, iter->bufsize);
|
||||
|
||||
iter->bufsize *= 2;
|
||||
}
|
||||
result = isc_net_probeipv6();
|
||||
if (result == ISC_R_SUCCESS)
|
||||
result = getbuf6(iter);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
result = getbuf4(iter);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto ioctl_failure;
|
||||
|
||||
/*
|
||||
* A newly created iterator has an undefined position
|
||||
@ -198,9 +291,8 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
ioctl_failure:
|
||||
isc_mem_put(mctx, iter->buf, iter->bufsize);
|
||||
|
||||
alloc_failure:
|
||||
if (iter->buf != NULL)
|
||||
isc_mem_put(mctx, iter->buf, iter->bufsize);
|
||||
(void) close(iter->socket);
|
||||
|
||||
socket_failure:
|
||||
@ -217,22 +309,149 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
|
||||
*/
|
||||
|
||||
static isc_result_t
|
||||
internal_current(isc_interfaceiter_t *iter) {
|
||||
struct lifreq *ifrp;
|
||||
struct lifreq lifreq;
|
||||
internal_current4(isc_interfaceiter_t *iter) {
|
||||
struct ifreq *ifrp;
|
||||
struct ifreq ifreq;
|
||||
int family;
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
|
||||
REQUIRE(VALID_IFITER(iter));
|
||||
REQUIRE (iter->pos < (unsigned int) iter->ifc.lifc_len);
|
||||
REQUIRE (iter->pos < (unsigned int) iter->ifc.ifc_len);
|
||||
|
||||
ifrp = (struct lifreq *)((char *) iter->ifc.lifc_req + iter->pos);
|
||||
ifrp = (struct ifreq *)((char *) iter->ifc.ifc_req + iter->pos);
|
||||
|
||||
memset(&ifreq, 0, sizeof ifreq);
|
||||
memcpy(&ifreq, ifrp, sizeof ifreq);
|
||||
|
||||
family = ifreq.ifr_addr.sa_family;
|
||||
#ifdef ISC_PLATFORM_HAVEIPV6
|
||||
if (family != AF_INET && family != AF_INET6)
|
||||
#else
|
||||
if (family != AF_INET)
|
||||
#endif
|
||||
return (ISC_R_IGNORE);
|
||||
|
||||
memset(&iter->current, 0, sizeof(iter->current));
|
||||
iter->current.af = family;
|
||||
|
||||
INSIST(sizeof(ifreq.ifr_name) <= sizeof(iter->current.name));
|
||||
memset(iter->current.name, 0, sizeof(iter->current.name));
|
||||
memcpy(iter->current.name, ifreq.ifr_name, sizeof(ifreq.ifr_name));
|
||||
|
||||
get_addr(family, &iter->current.address,
|
||||
(struct sockaddr *)&ifreq.ifr_addr);
|
||||
|
||||
/*
|
||||
* Get interface flags.
|
||||
*/
|
||||
|
||||
iter->current.flags = 0;
|
||||
|
||||
/*
|
||||
* Ignore the HP/UX warning about "interger overflow during
|
||||
* conversion. It comes from its own macro definition,
|
||||
* and is really hard to shut up.
|
||||
*/
|
||||
if (ioctl(iter->socket, SIOCGIFFLAGS, (char *) &ifreq) < 0) {
|
||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"%s: getting interface flags: %s",
|
||||
ifreq.ifr_name, strbuf);
|
||||
return (ISC_R_IGNORE);
|
||||
}
|
||||
|
||||
if ((ifreq.ifr_flags & IFF_UP) != 0)
|
||||
iter->current.flags |= INTERFACE_F_UP;
|
||||
|
||||
if ((ifreq.ifr_flags & IFF_POINTOPOINT) != 0)
|
||||
iter->current.flags |= INTERFACE_F_POINTTOPOINT;
|
||||
|
||||
if ((ifreq.ifr_flags & IFF_LOOPBACK) != 0)
|
||||
iter->current.flags |= INTERFACE_F_LOOPBACK;
|
||||
|
||||
/*
|
||||
* If the interface is point-to-point, get the destination address.
|
||||
*/
|
||||
if ((iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) {
|
||||
/*
|
||||
* Ignore the HP/UX warning about "interger overflow during
|
||||
* conversion. It comes from its own macro definition,
|
||||
* and is really hard to shut up.
|
||||
*/
|
||||
if (ioctl(iter->socket, SIOCGIFDSTADDR, (char *)&ifreq)
|
||||
< 0) {
|
||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_IFITERIOCTL,
|
||||
ISC_MSG_GETDESTADDR,
|
||||
"%s: getting "
|
||||
"destination address: %s"),
|
||||
ifreq.ifr_name, strbuf);
|
||||
return (ISC_R_IGNORE);
|
||||
}
|
||||
get_addr(family, &iter->current.dstaddress,
|
||||
(struct sockaddr *)&ifreq.ifr_dstaddr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the network mask.
|
||||
*/
|
||||
memset(&ifreq, 0, sizeof ifreq);
|
||||
memcpy(&ifreq, ifrp, sizeof ifreq);
|
||||
switch (family) {
|
||||
case AF_INET:
|
||||
/*
|
||||
* Ignore the HP/UX warning about "interger overflow during
|
||||
* conversion. It comes from its own macro definition,
|
||||
* and is really hard to shut up.
|
||||
*/
|
||||
if (ioctl(iter->socket, SIOCGIFNETMASK, (char *)&ifreq)
|
||||
< 0) {
|
||||
isc__strerror(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_IFITERIOCTL,
|
||||
ISC_MSG_GETNETMASK,
|
||||
"%s: getting netmask: %s"),
|
||||
ifreq.ifr_name, strbuf);
|
||||
return (ISC_R_IGNORE);
|
||||
}
|
||||
get_addr(family, &iter->current.netmask,
|
||||
(struct sockaddr *)&ifreq.ifr_addr);
|
||||
break;
|
||||
case AF_INET6:
|
||||
break;
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
internal_current6(isc_interfaceiter_t *iter) {
|
||||
#if !defined(SIOCGLIFCONF) || !defined(SIOCGLIFADDR)
|
||||
UNUSED(iter);
|
||||
return (ISC_R_NOTIMPLEMENTED);
|
||||
#else
|
||||
struct LIFREQ *ifrp;
|
||||
struct LIFREQ lifreq;
|
||||
int family;
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
|
||||
REQUIRE(VALID_IFITER(iter));
|
||||
REQUIRE (iter->pos < (unsigned int) iter->lifc.lifc_len);
|
||||
|
||||
ifrp = (struct LIFREQ *)((char *) iter->lifc.lifc_req + iter->pos);
|
||||
|
||||
memset(&lifreq, 0, sizeof lifreq);
|
||||
memcpy(&lifreq, ifrp, sizeof lifreq);
|
||||
|
||||
family = lifreq.lifr_addr.ss_family;
|
||||
#ifdef ISC_PLATFORM_HAVEIPV6
|
||||
if (family != AF_INET && family != AF_INET6)
|
||||
#else
|
||||
if (family != AF_INET)
|
||||
#endif
|
||||
return (ISC_R_IGNORE);
|
||||
|
||||
memset(&iter->current, 0, sizeof(iter->current));
|
||||
@ -344,6 +563,14 @@ internal_current(isc_interfaceiter_t *iter) {
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
#endif
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
internal_current(isc_interfaceiter_t *iter) {
|
||||
if (iter->mode == 6)
|
||||
return (internal_current6(iter));
|
||||
return (internal_current4(iter));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -354,12 +581,37 @@ internal_current(isc_interfaceiter_t *iter) {
|
||||
* interfaces, otherwise ISC_R_SUCCESS.
|
||||
*/
|
||||
static isc_result_t
|
||||
internal_next(isc_interfaceiter_t *iter) {
|
||||
struct lifreq *ifrp;
|
||||
internal_next4(isc_interfaceiter_t *iter) {
|
||||
struct ifreq *ifrp;
|
||||
|
||||
REQUIRE (iter->pos < (unsigned int) iter->ifc.lifc_len);
|
||||
REQUIRE (iter->pos < (unsigned int) iter->ifc.ifc_len);
|
||||
|
||||
ifrp = (struct lifreq *)((char *) iter->ifc.lifc_req + iter->pos);
|
||||
ifrp = (struct ifreq *)((char *) iter->ifc.ifc_req + iter->pos);
|
||||
|
||||
#ifdef ISC_PLATFORM_HAVESALEN
|
||||
if (ifrp->ifr_addr.sa_len > sizeof(struct sockaddr))
|
||||
iter->pos += sizeof(ifrp->ifr_name) + ifrp->ifr_addr.sa_len;
|
||||
else
|
||||
#endif
|
||||
iter->pos += sizeof *ifrp;
|
||||
|
||||
if (iter->pos >= (unsigned int) iter->ifc.ifc_len)
|
||||
return (ISC_R_NOMORE);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
internal_next6(isc_interfaceiter_t *iter) {
|
||||
#if !defined(SIOCGLIFCONF) || !defined(SIOCGLIFADDR)
|
||||
UNUSED(iter);
|
||||
return (ISC_R_NOTIMPLEMENTED);
|
||||
#else
|
||||
struct LIFREQ *ifrp;
|
||||
|
||||
REQUIRE (iter->pos < (unsigned int) iter->lifc.lifc_len);
|
||||
|
||||
ifrp = (struct LIFREQ *)((char *) iter->lifc.lifc_req + iter->pos);
|
||||
|
||||
#ifdef ISC_PLATFORM_HAVESALEN
|
||||
if (ifrp->lifr_addr.sa_len > sizeof(struct sockaddr))
|
||||
@ -368,10 +620,18 @@ internal_next(isc_interfaceiter_t *iter) {
|
||||
#endif
|
||||
iter->pos += sizeof *ifrp;
|
||||
|
||||
if (iter->pos >= (unsigned int) iter->ifc.lifc_len)
|
||||
if (iter->pos >= (unsigned int) iter->lifc.lifc_len)
|
||||
return (ISC_R_NOMORE);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
#endif
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
internal_next(isc_interfaceiter_t *iter) {
|
||||
if (iter->mode == 6)
|
||||
return (internal_next6(iter));
|
||||
return (internal_next4(iter));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: interfaceiter.c,v 1.23 2001/08/31 05:57:53 marka Exp $ */
|
||||
/* $Id: interfaceiter.c,v 1.24 2001/10/22 04:01:32 marka Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -41,7 +41,11 @@
|
||||
#include <isc/interfaceiter.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <net/if.h> /* Must follow <isc/net.h>. */
|
||||
/* Must follow <isc/net.h>. */
|
||||
#ifdef HAVE_NET_IF6_H
|
||||
#include <net/if6.h>
|
||||
#endif
|
||||
#include <net/if.h>
|
||||
|
||||
/* Common utility functions */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user