main.c revision 15a44745412679c30a6d022733925af70a38b715
/*
* Copyright (C) 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: main.c,v 1.44 2000/07/27 09:36:41 tale Exp $ */
/*
* Main program for the Lightweight Resolver Daemon.
*
* To paraphrase the old saying about X11, "It's not a lightweight deamon
* for resolvers, it's a deamon for lightweight resolvers".
*/
#include <config.h>
#include <stdlib.h>
#include <dns/dispatch.h>
#include <dns/resolver.h>
#include "client.h"
/*
* The goal number of clients we can handle will be NTASKS * NRECVS.
*/
/*
* Array of client managers. Each of these will have a task associated
* with it.
*/
unsigned int ntasks; /* number of tasks actually created */
static isc_logmodule_t logmodules[] = {
{ "main", 0 },
{ NULL, 0 }
};
#define LWRES_LOGMODULE_MAIN (&logmodules[0])
static isc_logcategory_t logcategories[] = {
{ "network", 0 },
{ NULL, 0 }
};
#define LWRES_LOGCATEGORY_NETWORK (&logcategories[0])
static isc_result_t
unsigned int attrs;
/*
* View.
*/
if (result != ISC_R_SUCCESS)
goto out;
/*
* Cache.
*/
if (result != ISC_R_SUCCESS)
goto out;
/*
* Resolver.
*
* XXXMLG hardwired number of tasks.
*/
if (isc_net_probeipv4() == ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
goto out;
}
if (isc_net_probeipv6() == ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
goto out;
}
timermgr, 0, dispatchmgr,
if (result != ISC_R_SUCCESS)
goto out;
if (result != ISC_R_SUCCESS)
goto out;
/*
* If we have forwarders, set them here.
*/
}
}
return (ISC_R_SUCCESS);
out:
return (result);
}
/*
* Wrappers around our memory management stuff, for the lwres functions.
*/
static void *
}
static void
}
static void
int lwresult;
int i;
if (lwresult != LWRES_R_SUCCESS)
return;
if (lwresult != LWRES_R_SUCCESS)
goto out;
#if 1
#endif
/*
* Run through the list of nameservers, and set them to be our
* forwarders.
*/
case AF_INET:
break;
case AF_INET6:
break;
default:
break;
}
}
out:
}
int
unsigned int i, j;
result = isc_app_start();
/*
* Set up logging.
*/
/*
* Set the initial debug level.
*/
/*
* Create a task manager.
*/
/*
* Create a socket manager.
*/
/*
* Create a timer manager.
*/
/*
* Create a dispatch manager.
*/
dispatchmgr = NULL;
/*
* Read resolv.conf to get our forwarders.
*/
/*
* Initialize the DNS bits. Start by loading our built-in
* root hints.
*/
/*
* We'll need a socket. It will be a UDP socket, and bound to
* 127.0.0.1 port LWRES_UDP_PORT.
*/
&sock);
if (result != ISC_R_SUCCESS) {
"binding lwres protocol socket to port %d: %s",
exit(1);
}
/*
* Create one task for each client manager.
*/
for (i = 0 ; i < NTASKS ; i++) {
if (result != ISC_R_SUCCESS)
break;
0, LWRD_SHUTDOWN,
if (result != ISC_R_SUCCESS) {
break;
}
}
INSIST(i > 0);
ntasks = i; /* remember how many we managed to create */
/*
* Now, run through each client manager and populate it with
* client structures. Do this by creating one receive for each
* task, in a loop, so each task has a chance of getting at least
* one client structure.
*/
for (i = 0 ; i < NRECVS ; i++) {
break;
for (j = 0 ; j < ntasks ; j++)
}
INSIST(i > 0);
/*
* Issue one read request for each task we have.
*/
for (j = 0 ; j < ntasks ; j++) {
}
/*
* Wait for ^c or kill.
*/
isc_app_run();
/*
* Send a shutdown event to every task.
*/
for (j = 0 ; j < ntasks ; j++) {
}
/*
* Kill off the view.
*/
/*
* Wait for the tasks to all die.
*/
/*
* Wait for everything to die off by waiting for the sockets
* to be detached.
*/
/*
* Free up memory allocated. This is somewhat magical. We allocated
* the client_t's in blocks, but the first task always has the
* first pointer. Just loop here, freeing them.
*/
}
/*
* Now, kill off the client manager structures.
*/
/*
* Kill the memory system.
*/
return (0);
}