2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

overhaul checkpoint

This commit is contained in:
Bob Halley 1999-07-24 01:16:38 +00:00
parent 7e1f467287
commit 533b047505

View File

@ -45,29 +45,21 @@
#include <dns/dbtable.h> #include <dns/dbtable.h>
#include <dns/message.h> #include <dns/message.h>
#include <sys/types.h> #include <named/types.h>
#include <sys/socket.h> #include <named/globals.h>
#include <named/server.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#if 0
#include "udpclient.h" #include "udpclient.h"
#include "tcpclient.h" #include "tcpclient.h"
#include "interfacemgr.h" #include "interfacemgr.h"
#endif
typedef struct dbinfo {
dns_db_t * db;
ISC_LINK(struct dbinfo) link;
} dbinfo;
isc_mem_t * mctx;
isc_boolean_t want_stats = ISC_FALSE;
static char dbtype[128];
static dns_dbtable_t * dbtable; static dns_dbtable_t * dbtable;
static ISC_LIST(dbinfo) dbs; static ns_dbinfo_t * cache_dbi;
static dbinfo * cache_dbi; static isc_task_t * server_task;
#if 0
static inline isc_boolean_t static inline isc_boolean_t
CHECKRESULT(dns_result_t result, char *msg) CHECKRESULT(dns_result_t result, char *msg)
{ {
@ -102,7 +94,7 @@ resolve_packet(isc_mem_t *mctx, dns_message_t *query, isc_buffer_t *target) {
isc_boolean_t possibly_auth = ISC_FALSE; isc_boolean_t possibly_auth = ISC_FALSE;
message = NULL; message = NULL;
result = dns_message_create(mctx, &message, DNS_MESSAGE_INTENTRENDER); result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message);
CHECKRESULT(result, "dns_message_create failed"); CHECKRESULT(result, "dns_message_create failed");
message->id = query->id; message->id = query->id;
@ -287,7 +279,7 @@ dispatch(isc_mem_t *mctx, isc_region_t *rxr, unsigned int reslen)
isc_buffer_add(&source, rxr->length); isc_buffer_add(&source, rxr->length);
message = NULL; message = NULL;
result = dns_message_create(mctx, &message, DNS_MESSAGE_INTENTPARSE); result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
if (CHECKRESULT(result, "dns_message_create failed")) { if (CHECKRESULT(result, "dns_message_create failed")) {
return (result); return (result);
} }
@ -337,23 +329,18 @@ dispatch(isc_mem_t *mctx, isc_region_t *rxr, unsigned int reslen)
return (DNS_R_SUCCESS); return (DNS_R_SUCCESS);
} }
#endif
static dns_result_t static dns_result_t
load(char *filename, char *origintext, isc_boolean_t cache) { load(ns_dbinfo_t *dbi) {
dns_fixedname_t forigin; dns_fixedname_t forigin;
dns_name_t *origin; dns_name_t *origin;
dns_result_t result; dns_result_t result;
isc_buffer_t source; isc_buffer_t source;
size_t len; size_t len;
dbinfo *dbi;
dbi = isc_mem_get(mctx, sizeof *dbi); len = strlen(dbi->origin);
if (dbi == NULL) isc_buffer_init(&source, dbi->origin, len, ISC_BUFFERTYPE_TEXT);
return (DNS_R_NOMEMORY);
dbi->db = NULL;
len = strlen(origintext);
isc_buffer_init(&source, origintext, len, ISC_BUFFERTYPE_TEXT);
isc_buffer_add(&source, len); isc_buffer_add(&source, len);
dns_fixedname_init(&forigin); dns_fixedname_init(&forigin);
origin = dns_fixedname_name(&forigin); origin = dns_fixedname_name(&forigin);
@ -362,43 +349,58 @@ load(char *filename, char *origintext, isc_boolean_t cache) {
if (result != DNS_R_SUCCESS) if (result != DNS_R_SUCCESS)
return (result); return (result);
result = dns_db_create(mctx, dbtype, origin, cache, dns_rdataclass_in, result = dns_db_create(ns_g_mctx, "rbt", origin, dbi->iscache,
0, NULL, &dbi->db); dns_rdataclass_in, 0, NULL, &dbi->db);
if (result != DNS_R_SUCCESS) { if (result != DNS_R_SUCCESS) {
isc_mem_put(mctx, dbi, sizeof *dbi); isc_mem_put(ns_g_mctx, dbi, sizeof *dbi);
return (result); return (result);
} }
printf("loading %s (%s)\n", filename, origintext); printf("loading %s (%s)\n", dbi->path, dbi->origin);
result = dns_db_load(dbi->db, filename); result = dns_db_load(dbi->db, dbi->path);
if (result != DNS_R_SUCCESS) { if (result != DNS_R_SUCCESS) {
dns_db_detach(&dbi->db); dns_db_detach(&dbi->db);
isc_mem_put(mctx, dbi, sizeof *dbi); isc_mem_put(ns_g_mctx, dbi, sizeof *dbi);
return (result); return (result);
} }
printf("loaded\n"); printf("loaded\n");
if (cache) { if (dbi->iscache) {
INSIST(cache_dbi == NULL); INSIST(cache_dbi == NULL);
dns_dbtable_adddefault(dbtable, dbi->db); dns_dbtable_adddefault(dbtable, dbi->db);
cache_dbi = dbi; cache_dbi = dbi;
} else { } else {
if (dns_dbtable_add(dbtable, dbi->db) != DNS_R_SUCCESS) { if (dns_dbtable_add(dbtable, dbi->db) != DNS_R_SUCCESS) {
dns_db_detach(&dbi->db); dns_db_detach(&dbi->db);
isc_mem_put(mctx, dbi, sizeof *dbi); isc_mem_put(ns_g_mctx, dbi, sizeof *dbi);
return (result); return (result);
} }
} }
ISC_LIST_APPEND(dbs, dbi, link);
return (DNS_R_SUCCESS); return (DNS_R_SUCCESS);
} }
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);
}
static void static void
unload_all(void) { unload_all(void) {
dbinfo *dbi, *dbi_next; ns_dbinfo_t *dbi, *dbi_next;
for (dbi = ISC_LIST_HEAD(dbs); dbi != NULL; dbi = dbi_next) { for (dbi = ISC_LIST_HEAD(ns_g_dbs); dbi != NULL; dbi = dbi_next) {
dbi_next = ISC_LIST_NEXT(dbi, link); dbi_next = ISC_LIST_NEXT(dbi, link);
if (dns_db_iszone(dbi->db)) if (dns_db_iszone(dbi->db))
dns_dbtable_remove(dbtable, dbi->db); dns_dbtable_remove(dbtable, dbi->db);
@ -408,116 +410,77 @@ unload_all(void) {
cache_dbi = NULL; cache_dbi = NULL;
} }
dns_db_detach(&dbi->db); dns_db_detach(&dbi->db);
ISC_LIST_UNLINK(dbs, dbi, link); ISC_LIST_UNLINK(ns_g_dbs, dbi, link);
isc_mem_put(mctx, dbi, sizeof *dbi); isc_mem_put(ns_g_mctx, dbi, sizeof *dbi);
} }
} }
int static void
main(int argc, char *argv[]) load_configuration(void) {
{ isc_result_t result;
isc_taskmgr_t *manager = NULL;
unsigned int workers;
isc_socketmgr_t *socketmgr;
isc_sockaddr_t sockaddr;
unsigned int addrlen;
int ch;
char *origintext;
dns_result_t result;
isc_result_t iresult;
ns_interfacemgr_t *ifmgr = NULL;
RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS); /*
* XXXRTH loading code below is temporary; it
* will be replaced by proper config file processing.
*/
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); result = load_all();
RUNTIME_CHECK(dns_dbtable_create(mctx, dns_rdataclass_in, &dbtable) == if (result != ISC_R_SUCCESS) {
DNS_R_SUCCESS); /* XXXRTH */
strcpy(dbtype, "rbt"); printf("load_all(): %s\n", isc_result_totext(result));
/*+ XXX */
while ((ch = getopt(argc, argv, "c:d:z:s")) != -1) {
switch (ch) {
case 'c':
result = load(optarg, ".", ISC_TRUE);
if (result != DNS_R_SUCCESS)
printf("%s\n", dns_result_totext(result));
break;
case 'd':
strcpy(dbtype, optarg);
break;
case 'z':
origintext = strrchr(optarg, '/');
if (origintext == NULL)
origintext = optarg;
else
origintext++; /* Skip '/'. */
result = load(optarg, origintext, ISC_FALSE);
if (result != DNS_R_SUCCESS)
printf("%s\n", dns_result_totext(result));
break;
case 's':
want_stats = ISC_TRUE;
break;
}
} }
argc -= optind; ns_interfacemgr_scan(ns_g_interfacemgr);
argv += optind; }
if (argc > 1) static void
fprintf(stderr, "ignoring extra command line arguments\n"); run_server(isc_task_t *task, isc_event_t *event) {
/*- XXX */ (void)task;
printf("server running\n");
memset(&sockaddr, 0, sizeof(sockaddr)); load_configuration();
sockaddr.type.sin.sin_port = htons(5544);
addrlen = sizeof(struct sockaddr_in);
workers = 2; isc_event_free(&event);
printf("%d workers\n", workers); }
RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &manager) == static void
ISC_R_SUCCESS); shutdown_server(isc_task_t *task, isc_event_t *event) {
(void)task;
socketmgr = NULL; printf("server shutting down\n");
RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
result = ns_interfacemgr_create(mctx, manager, socketmgr, dispatch, &ifmgr);
RUNTIME_CHECK(result == DNS_R_SUCCESS);
result = ns_interfacemgr_scan(ifmgr);
RUNTIME_CHECK(result == DNS_R_SUCCESS);
if (want_stats)
isc_mem_stats(mctx, stdout);
/*
* Block until shutdown is requested.
*/
iresult = isc_app_run();
if (iresult != ISC_R_SUCCESS)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_run(): %s",
isc_result_totext(iresult));
printf("Destroying network interface manager\n");
ns_interfacemgr_destroy(&ifmgr);
printf("Destroying task manager\n");
isc_taskmgr_destroy(&manager);
printf("Destroying socket manager\n");
isc_socketmgr_destroy(&socketmgr);
printf("Unloading\n");
unload_all(); unload_all();
dns_dbtable_detach(&dbtable); dns_dbtable_detach(&dbtable);
isc_task_detach(&server_task);
if (want_stats) isc_event_free(&event);
isc_mem_stats(mctx, stdout); }
isc_mem_destroy(&mctx);
isc_result_t
isc_app_finish(); ns_server_init(void) {
isc_result_t result;
return (0);
result = dns_dbtable_create(ns_g_mctx, dns_rdataclass_in, &dbtable);
if (result != ISC_R_SUCCESS)
return (result);
result = isc_task_create(ns_g_taskmgr, ns_g_mctx, 0, &server_task);
if (result != ISC_R_SUCCESS)
goto cleanup_dbtable;
result = isc_task_onshutdown(server_task, shutdown_server, NULL);
if (result != ISC_R_SUCCESS)
goto cleanup_task;
result = isc_app_onrun(ns_g_mctx, server_task, run_server, NULL);
if (result != ISC_R_SUCCESS)
goto cleanup_task;
return (ISC_R_SUCCESS);
cleanup_task:
isc_task_detach(&server_task);
cleanup_dbtable:
dns_dbtable_detach(&dbtable);
return (result);
} }