interfacemgr.c revision 15a44745412679c30a6d022733925af70a38b715
/*
* Copyright (C) 1999, 2000 Internet Software Consortium.
*
* 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.
*
* 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.
*/
/* $Id: interfacemgr.c,v 1.47 2000/07/27 09:36:49 tale Exp $ */
#include <config.h>
#include <isc/interfaceiter.h>
#include <dns/dispatch.h>
#include <named/interfacemgr.h>
#define IFMGR_COMMON_LOGARGS \
struct ns_interfacemgr {
unsigned int magic; /* Magic number. */
int references;
unsigned int generation; /* Current generation no. */
};
static void
{
return (ISC_R_NOMEMORY);
if (result != ISC_R_SUCCESS)
goto cleanup_mem;
/*
* The listen-on lists are initially empty.
*/
if (result != ISC_R_SUCCESS)
goto cleanup_mem;
if (result != ISC_R_SUCCESS)
goto cleanup_listenon;
return (ISC_R_SUCCESS);
return (result);
}
static void
}
}
void
source->references++;
}
void
target->references--;
if (target->references == 0)
if (need_destroy)
}
void
/*
* Shut down and detach all interfaces.
* By incrementing the generation count, we make purge_old_interfaces()
* consider all interfaces "old".
*/
mgr->generation++;
}
static isc_result_t
{
return (ISC_R_NOMEMORY);
if (result != ISC_R_SUCCESS)
goto lock_create_failure;
/*
* Create a task.
*/
if (result != ISC_R_SUCCESS) {
"isc_task_create() failed: %s",
goto task_create_failure;
}
/*
* Create a single TCP client object. It will replace itself
* with a new one as soon as it gets a connection, so the actual
* connections will be handled in parallel even though there is
* only one client initially.
*/
ifp->ntcpcurrent = 0;
return (ISC_R_SUCCESS);
return (ISC_R_UNEXPECTED);
}
static isc_result_t
unsigned int attrs;
unsigned int attrmask;
attrs = 0;
else
attrmask = 0;
4096, 1000, 32768, 8219, 8237,
if (result != ISC_R_SUCCESS) {
"UDP dns_dispatch_create(): %s",
goto udp_dispatch_failure;
}
if (result != ISC_R_SUCCESS) {
"UDP ns_clientmgr_createclients(): %s",
goto addtodispatch_failure;
}
return (ISC_R_SUCCESS);
return (result);
}
static isc_result_t
/*
* Open a TCP socket.
*/
if (result != ISC_R_SUCCESS) {
"creating TCP socket: %s",
goto tcp_socket_failure;
}
if (result != ISC_R_SUCCESS) {
"binding TCP socket: %s",
goto tcp_bind_failure;
}
if (result != ISC_R_SUCCESS) {
"listening on TCP socket: %s",
goto tcp_listen_failure;
}
ISC_TRUE);
if (result != ISC_R_SUCCESS) {
"TCP ns_clientmgr_createclients(): %s",
goto accepttcp_failure;
}
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
}
static isc_result_t
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
goto cleanup_interface;
if (result != ISC_R_SUCCESS) {
/*
* XXXRTH We don't currently have a way to easily stop dispatch
* service, so we return currently return ISC_R_SUCCESS (the
* UDP stuff will work even if TCP creation failed). This will
* be fixed later.
*/
}
return (ISC_R_SUCCESS);
return (result);
}
static void
}
}
void
source->references++;
}
void
target->references--;
if (target->references == 0)
if (need_destroy)
}
/*
* Search the interface list for an interface whose address and port
* both match those of 'addr'. Return a pointer to it, or NULL if not found.
*/
static ns_interface_t *
break;
}
return (ifp);
}
/*
* Remove any interfaces whose generation number is not the current one.
*/
static void
char sabuf[256];
"no longer listening on %s", sabuf);
}
}
}
static isc_result_t
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_SUCCESS);
}
static void
if (result != ISC_R_SUCCESS)
return;
if (result != ISC_R_SUCCESS)
goto cleanup_iter;
if (result != ISC_R_SUCCESS)
goto cleanup_iter;
result == ISC_R_SUCCESS;
{
unsigned int prefixlen;
if (result != ISC_R_SUCCESS)
break;
continue;
continue;
&prefixlen);
if (result != ISC_R_SUCCESS)
goto ignore_interface;
/* XXX suppress duplicates */
if (result != ISC_R_SUCCESS)
goto ignore_interface;
if (result != ISC_R_SUCCESS)
goto ignore_interface;
{
int match;
/*
* combination.
*/
/*
* See if the address matches the listen-on statement;
* if not, ignore the interface.
*/
if (match <= 0)
continue;
} else {
char sabuf[256];
"listening on IPv4 interface "
&ifp);
if (result != ISC_R_SUCCESS) {
"creating IPv4 interface %s "
"failed; interface ignored",
}
/* Continue. */
}
}
continue;
"ignoring IPv4 interface %s: %s",
continue;
}
if (result != ISC_R_NOMORE)
"IPv4: interface iteration failed: %s",
}
static isc_boolean_t
if (ISC_LIST_EMPTY(p->elts))
return (ISC_TRUE); /* No listen-on-v6 statements */
return (ISC_FALSE); /* More than one listen-on-v6 stmt */
return (ISC_TRUE); /* listen-on-v6 { } */
return (ISC_FALSE); /* listen-on-v6 { ...; ...; } */
return (ISC_TRUE); /* listen-on-v6 { none; } */
return (ISC_FALSE); /* All others */
}
static isc_boolean_t
if (ISC_LIST_EMPTY(p->elts))
return (ISC_FALSE); /* No listen-on-v6 statements */
return (ISC_FALSE); /* More than one listen-on-v6 stmt */
return (ISC_FALSE);
return (ISC_TRUE); /* listen-on-v6 { any; } */
}
return (ISC_FALSE); /* All others */
}
static void
return;
"bad IPv6 listen-on list: must be 'any' or 'none'");
return;
}
in6a = in6addr_any;
} else {
"listening on IPv6 interfaces, port %u", port);
if (result != ISC_R_SUCCESS) {
"listening on IPv6 interfaces failed");
/* Continue. */
}
}
}
void
if (isc_net_probeipv6() == ISC_R_SUCCESS) {
} else
"no IPv6 interfaces found");
if (isc_net_probeipv4() == ISC_R_SUCCESS)
else
"no IPv4 interfaces found");
/*
* Now go through the interface list and delete anything that
* does not have the current generation number. This is
* how we catch interfaces that go away or change their
* addresses.
*/
"not listening on any interfaces");
/*
* Continue anyway.
*/
}
}
void
}
void
}
{
/*
* Find a UDP dispatcher matching 'address', if it exists.
*/
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
}