2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 18:19:42 +00:00
bind/bin/named/server.c

229 lines
5.2 KiB
C
Raw Normal View History

/*
1999-03-06 03:55:54 +00:00
* Copyright (C) 1999 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.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <isc/assertions.h>
#include <isc/error.h>
#include <isc/mem.h>
#include <isc/task.h>
#include <isc/thread.h>
#include <isc/result.h>
#include <isc/socket.h>
#include <isc/timer.h>
1999-05-27 01:51:31 +00:00
#include <isc/app.h>
#include <dns/types.h>
#include <dns/result.h>
#include <dns/name.h>
1999-05-03 19:56:23 +00:00
#include <dns/fixedname.h>
#include <dns/rdata.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
1999-05-03 19:56:23 +00:00
#include <dns/rdatasetiter.h>
#include <dns/compress.h>
1999-01-31 12:31:31 +00:00
#include <dns/db.h>
1999-05-03 19:56:23 +00:00
#include <dns/dbtable.h>
#include <dns/message.h>
1999-07-24 01:16:38 +00:00
#include <named/types.h>
#include <named/globals.h>
#include <named/server.h>
1999-07-24 01:16:38 +00:00
#if 0
#include "udpclient.h"
1999-01-28 05:52:20 +00:00
#include "tcpclient.h"
#include "interfacemgr.h"
1999-07-24 01:16:38 +00:00
#endif
1999-07-24 01:16:38 +00:00
static ns_dbinfo_t * cache_dbi;
static isc_task_t * server_task;
1999-01-31 12:31:31 +00:00
1999-05-03 19:56:23 +00:00
static dns_result_t
1999-07-24 01:16:38 +00:00
load(ns_dbinfo_t *dbi) {
1999-05-03 19:56:23 +00:00
dns_fixedname_t forigin;
dns_name_t *origin;
dns_result_t result;
isc_buffer_t source;
size_t len;
1999-07-24 01:16:38 +00:00
len = strlen(dbi->origin);
isc_buffer_init(&source, dbi->origin, len, ISC_BUFFERTYPE_TEXT);
1999-05-03 19:56:23 +00:00
isc_buffer_add(&source, len);
dns_fixedname_init(&forigin);
origin = dns_fixedname_name(&forigin);
result = dns_name_fromtext(origin, &source, dns_rootname, ISC_FALSE,
NULL);
if (result != DNS_R_SUCCESS)
return (result);
1999-07-24 01:16:38 +00:00
result = dns_db_create(ns_g_mctx, "rbt", origin, dbi->iscache,
dns_rdataclass_in, 0, NULL, &dbi->db);
1999-08-05 01:51:32 +00:00
if (result != DNS_R_SUCCESS)
1999-05-03 19:56:23 +00:00
return (result);
1999-07-24 01:16:38 +00:00
printf("loading %s (%s)\n", dbi->path, dbi->origin);
result = dns_db_load(dbi->db, dbi->path);
1999-05-03 19:56:23 +00:00
if (result != DNS_R_SUCCESS) {
dns_db_detach(&dbi->db);
return (result);
}
printf("loaded\n");
1999-07-24 01:16:38 +00:00
if (dbi->iscache) {
1999-05-03 19:56:23 +00:00
INSIST(cache_dbi == NULL);
1999-07-28 02:20:36 +00:00
dns_dbtable_adddefault(ns_g_dbtable, dbi->db);
1999-05-03 19:56:23 +00:00
cache_dbi = dbi;
} else {
1999-07-28 02:20:36 +00:00
if (dns_dbtable_add(ns_g_dbtable, dbi->db) != DNS_R_SUCCESS) {
1999-05-03 19:56:23 +00:00
dns_db_detach(&dbi->db);
1999-07-24 01:16:38 +00:00
isc_mem_put(ns_g_mctx, dbi, sizeof *dbi);
1999-05-03 19:56:23 +00:00
return (result);
}
}
return (DNS_R_SUCCESS);
}
1999-07-24 01:16:38 +00:00
static isc_result_t
load_all(void) {
isc_result_t result = ISC_R_SUCCESS;
ns_dbinfo_t *dbi;
for (dbi = ISC_LIST_HEAD(ns_g_dbs);
dbi != NULL;
dbi = ISC_LIST_NEXT(dbi, link)) {
result = load(dbi);
if (result != ISC_R_SUCCESS)
break;
}
return (result);
}
1999-05-03 19:56:23 +00:00
static void
unload_all(void) {
1999-07-24 01:16:38 +00:00
ns_dbinfo_t *dbi, *dbi_next;
1999-05-03 19:56:23 +00:00
1999-07-24 01:16:38 +00:00
for (dbi = ISC_LIST_HEAD(ns_g_dbs); dbi != NULL; dbi = dbi_next) {
1999-05-03 19:56:23 +00:00
dbi_next = ISC_LIST_NEXT(dbi, link);
1999-08-05 01:51:32 +00:00
if (dbi->db != NULL) {
if (dns_db_iszone(dbi->db))
dns_dbtable_remove(ns_g_dbtable, dbi->db);
else {
INSIST(dbi == cache_dbi);
dns_dbtable_removedefault(ns_g_dbtable);
cache_dbi = NULL;
}
dns_db_detach(&dbi->db);
1999-05-03 19:56:23 +00:00
}
1999-07-24 01:16:38 +00:00
ISC_LIST_UNLINK(ns_g_dbs, dbi, link);
isc_mem_put(ns_g_mctx, dbi, sizeof *dbi);
1999-05-03 19:56:23 +00:00
}
}
1999-07-24 01:16:38 +00:00
static void
load_configuration(void) {
isc_result_t result;
1999-01-31 12:31:31 +00:00
1999-07-24 01:16:38 +00:00
/*
* XXXRTH loading code below is temporary; it
* will be replaced by proper config file processing.
*/
1999-01-31 12:31:31 +00:00
1999-07-24 01:16:38 +00:00
result = load_all();
if (result != ISC_R_SUCCESS) {
/* XXXRTH */
printf("load_all(): %s\n", isc_result_totext(result));
}
1999-07-24 01:16:38 +00:00
ns_interfacemgr_scan(ns_g_interfacemgr);
}
1999-07-24 01:16:38 +00:00
static void
run_server(isc_task_t *task, isc_event_t *event) {
1999-07-24 01:16:38 +00:00
(void)task;
printf("server running\n");
1999-07-24 01:16:38 +00:00
load_configuration();
1999-07-24 01:16:38 +00:00
isc_event_free(&event);
}
1999-01-28 05:52:20 +00:00
1999-07-24 01:16:38 +00:00
static void
shutdown_server(isc_task_t *task, isc_event_t *event) {
(void)task;
printf("server shutting down\n");
unload_all();
1999-07-28 02:20:36 +00:00
dns_dbtable_detach(&ns_g_dbtable);
1999-07-24 01:16:38 +00:00
isc_task_detach(&server_task);
isc_event_free(&event);
}
1999-07-24 01:16:38 +00:00
isc_result_t
ns_server_init(void) {
isc_result_t result;
1999-08-05 01:51:32 +00:00
#if 0
dns_view_t *view = NULL;
#endif
1999-07-28 02:20:36 +00:00
result = dns_dbtable_create(ns_g_mctx, dns_rdataclass_in,
&ns_g_dbtable);
1999-07-24 01:16:38 +00:00
if (result != ISC_R_SUCCESS)
return (result);
1999-08-05 01:51:32 +00:00
#if 0
result = dns_view_create(ns_g_viewmgr, dns_rdataclass_in, "default/IN",
ns_g_dbtable, NULL, &view);
if (result != ISC_R_SUCCESS)
goto cleanup_dbtable;
#endif
1999-05-03 19:56:23 +00:00
1999-07-24 01:16:38 +00:00
result = isc_task_create(ns_g_taskmgr, ns_g_mctx, 0, &server_task);
if (result != ISC_R_SUCCESS)
1999-08-05 01:51:32 +00:00
goto cleanup_view;
1999-07-24 01:16:38 +00:00
result = isc_task_onshutdown(server_task, shutdown_server, NULL);
if (result != ISC_R_SUCCESS)
goto cleanup_task;
1999-05-27 01:51:31 +00:00
1999-07-24 01:16:38 +00:00
result = isc_app_onrun(ns_g_mctx, server_task, run_server, NULL);
if (result != ISC_R_SUCCESS)
goto cleanup_task;
1999-07-24 01:16:38 +00:00
return (ISC_R_SUCCESS);
1999-07-24 01:16:38 +00:00
cleanup_task:
isc_task_detach(&server_task);
1999-08-05 01:51:32 +00:00
cleanup_view:
#if 0
dns_view_detach(&view);
1999-07-24 01:16:38 +00:00
cleanup_dbtable:
1999-08-05 01:51:32 +00:00
#endif
1999-07-28 02:20:36 +00:00
dns_dbtable_detach(&ns_g_dbtable);
1999-05-27 01:51:31 +00:00
1999-07-24 01:16:38 +00:00
return (result);
}