mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
eliminated global variable ns_g_rootns; simplified
server startup/cleanup procedure
This commit is contained in:
@@ -52,11 +52,6 @@ EXTERN in_port_t ns_g_port INIT(53);
|
||||
|
||||
EXTERN ns_server_t * ns_g_server INIT(NULL);
|
||||
|
||||
/*
|
||||
* Default root nameserver hints.
|
||||
*/
|
||||
EXTERN dns_db_t * ns_g_rootns INIT(NULL);
|
||||
|
||||
/*
|
||||
* Logging.
|
||||
*/
|
||||
|
@@ -19,9 +19,8 @@
|
||||
#define NS_ROOTNS_H 1
|
||||
|
||||
#include <isc/types.h>
|
||||
#include <dns/db.h>
|
||||
|
||||
isc_result_t ns_rootns_init(void);
|
||||
|
||||
void ns_rootns_destroy(void);
|
||||
isc_result_t ns_rootns_create(isc_mem_t *mctx, dns_db_t **target);
|
||||
|
||||
#endif /* NS_ROOTNS_H */
|
||||
|
@@ -50,6 +50,7 @@ struct ns_server {
|
||||
dns_viewlist_t viewlist;
|
||||
isc_rwlock_t viewlock;
|
||||
ns_interfacemgr_t * interfacemgr;
|
||||
dns_db_t * roothints;
|
||||
};
|
||||
|
||||
#define NS_SERVER_MAGIC 0x53564552 /* SVER */
|
||||
@@ -67,16 +68,6 @@ ns_server_destroy(ns_server_t **serverp);
|
||||
/*
|
||||
* Destroy a server object, freeing its memory.
|
||||
*/
|
||||
|
||||
isc_result_t ns_server_setup(void);
|
||||
/*
|
||||
* Perform global server setup.
|
||||
*/
|
||||
|
||||
void ns_server_cleanup(void);
|
||||
/*
|
||||
* Perform global server cleanup
|
||||
*/
|
||||
|
||||
void
|
||||
ns_server_fatal(isc_logmodule_t *module, isc_boolean_t want_core,
|
||||
|
@@ -239,16 +239,16 @@ setup() {
|
||||
ns_main_earlyfatal("create_managers() failed: %s",
|
||||
isc_result_totext(result));
|
||||
|
||||
result = ns_server_setup();
|
||||
result = ns_server_create(ns_g_mctx, &ns_g_server);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
ns_main_earlyfatal("ns_server_init() failed: %s",
|
||||
ns_main_earlyfatal("ns_server_create() failed: %s",
|
||||
isc_result_totext(result));
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup() {
|
||||
destroy_managers();
|
||||
ns_server_cleanup();
|
||||
ns_server_destroy(&ns_g_server);
|
||||
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
|
||||
ISC_LOG_NOTICE, "exiting");
|
||||
ns_log_shutdown();
|
||||
|
@@ -27,7 +27,6 @@
|
||||
#include <dns/db.h>
|
||||
#include <dns/master.h>
|
||||
|
||||
#include <named/globals.h>
|
||||
#include <named/rootns.h>
|
||||
|
||||
static char root_ns[] =
|
||||
@@ -65,17 +64,18 @@ static char root_ns[] =
|
||||
"G.ROOT-SERVERS.NET. 3600000 IN A 192.112.36.4\n";
|
||||
|
||||
isc_result_t
|
||||
ns_rootns_init(void) {
|
||||
ns_rootns_create(isc_mem_t *mctx, dns_db_t **target) {
|
||||
isc_result_t result, eresult;
|
||||
isc_buffer_t source;
|
||||
size_t len;
|
||||
int soacount, nscount;
|
||||
dns_rdatacallbacks_t callbacks;
|
||||
dns_db_t *db = NULL;
|
||||
|
||||
REQUIRE(target != NULL && *target == NULL);
|
||||
|
||||
REQUIRE(ns_g_rootns == NULL);
|
||||
|
||||
result = dns_db_create(ns_g_mctx, "rbt", dns_rootname, ISC_FALSE,
|
||||
dns_rdataclass_in, 0, NULL, &ns_g_rootns);
|
||||
result = dns_db_create(mctx, "rbt", dns_rootname, ISC_FALSE,
|
||||
dns_rdataclass_in, 0, NULL, &db);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
|
||||
@@ -85,31 +85,26 @@ ns_rootns_init(void) {
|
||||
isc_buffer_init(&source, root_ns, len, ISC_BUFFERTYPE_TEXT);
|
||||
isc_buffer_add(&source, len);
|
||||
|
||||
result = dns_db_beginload(ns_g_rootns, &callbacks.add,
|
||||
result = dns_db_beginload(db, &callbacks.add,
|
||||
&callbacks.add_private);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
result = dns_master_loadbuffer(&source, &ns_g_rootns->origin,
|
||||
&ns_g_rootns->origin,
|
||||
ns_g_rootns->rdclass, ISC_FALSE,
|
||||
result = dns_master_loadbuffer(&source, &db->origin,
|
||||
&db->origin,
|
||||
db->rdclass, ISC_FALSE,
|
||||
&soacount, &nscount, &callbacks,
|
||||
ns_g_rootns->mctx);
|
||||
eresult = dns_db_endload(ns_g_rootns, &callbacks.add_private);
|
||||
db->mctx);
|
||||
eresult = dns_db_endload(db, &callbacks.add_private);
|
||||
if (result == ISC_R_SUCCESS)
|
||||
result = eresult;
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto db_detach;
|
||||
|
||||
*target = db;
|
||||
return (DNS_R_SUCCESS);
|
||||
|
||||
db_detach:
|
||||
dns_db_detach(&ns_g_rootns);
|
||||
dns_db_detach(&db);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
ns_rootns_destroy(void) {
|
||||
REQUIRE(ns_g_rootns != NULL);
|
||||
dns_db_detach(&ns_g_rootns);
|
||||
}
|
||||
|
@@ -139,7 +139,7 @@ create_default_view(dns_c_ctx_t *cctx, isc_mem_t *mctx,
|
||||
* We have default hints for class IN.
|
||||
*/
|
||||
if (rdclass == dns_rdataclass_in)
|
||||
dns_view_sethints(view, ns_g_rootns);
|
||||
dns_view_sethints(view, ns_g_server->roothints);
|
||||
|
||||
*viewp = view;
|
||||
|
||||
@@ -633,6 +633,16 @@ run_server(isc_task_t *task, isc_event_t *event) {
|
||||
|
||||
isc_event_free(&event);
|
||||
|
||||
result = dns_zonemgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
|
||||
ns_g_socketmgr, &ns_g_server->zonemgr);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"ns_zoneemgr_create() failed: %s",
|
||||
isc_result_totext(result));
|
||||
/* XXX cleanup */
|
||||
return;
|
||||
}
|
||||
|
||||
result = ns_clientmgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
|
||||
&server->clientmgr);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
@@ -728,7 +738,11 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
|
||||
ISC_LIST_INIT(server->viewlist);
|
||||
result = isc_rwlock_init(&server->viewlock, 0, 0);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
server->roothints = NULL;
|
||||
|
||||
result = ns_rootns_create(mctx, &server->roothints);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Setup the server task, which is responsible for coordinating
|
||||
* startup and shutdown of the server.
|
||||
@@ -742,11 +756,11 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
|
||||
result = isc_app_onrun(ns_g_mctx, server->task, run_server, server);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup_task;
|
||||
|
||||
|
||||
server->magic = NS_SERVER_MAGIC;
|
||||
*serverp = server;
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
|
||||
cleanup_task:
|
||||
isc_task_detach(&server->task);
|
||||
cleanup:
|
||||
@@ -760,6 +774,9 @@ ns_server_destroy(ns_server_t **serverp) {
|
||||
REQUIRE(NS_SERVER_VALID(server));
|
||||
|
||||
INSIST(ISC_LIST_EMPTY(server->viewlist));
|
||||
|
||||
dns_db_detach(&server->roothints);
|
||||
|
||||
isc_rwlock_destroy(&server->viewlock);
|
||||
|
||||
if (server->queryacl != NULL)
|
||||
@@ -777,43 +794,6 @@ ns_server_destroy(ns_server_t **serverp) {
|
||||
isc_mem_put(server->mctx, server, sizeof(*server));
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up global server state. Don't bother with
|
||||
* cleanup; our caller will cause the program to exit
|
||||
* if we fail.
|
||||
*/
|
||||
isc_result_t
|
||||
ns_server_setup(void) {
|
||||
isc_result_t result;
|
||||
|
||||
/*
|
||||
* Create the server object.
|
||||
*/
|
||||
result = ns_server_create(ns_g_mctx, &ns_g_server);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
/*
|
||||
* Setup default root server hints.
|
||||
*/
|
||||
result = ns_rootns_init();
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
|
||||
result = dns_zonemgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
|
||||
ns_g_socketmgr, &ns_g_server->zonemgr);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
ns_server_cleanup(void)
|
||||
{
|
||||
ns_rootns_destroy();
|
||||
ns_server_destroy(&ns_g_server);
|
||||
}
|
||||
|
||||
void
|
||||
ns_server_fatal(isc_logmodule_t *module, isc_boolean_t want_core,
|
||||
const char *format, ...)
|
||||
|
Reference in New Issue
Block a user