2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2001, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: control.c,v 1.7.2.4 2004/04/06 01:38:47 marka Exp $ */
25 #include <isc/event.h>
29 #include <dns/result.h>
31 #include <isccc/alist.h>
33 #include <isccc/result.h>
35 #include <named/control.h>
36 #include <named/log.h>
37 #include <named/server.h>
40 command_compare(const char *text, const char *command) {
41 unsigned int commandlen = strlen(command);
42 if (strncasecmp(text, command, commandlen) == 0 &&
43 (text[commandlen] == '\0' ||
44 text[commandlen] == ' ' ||
45 text[commandlen] == '\t'))
51 * This function is called to process the incoming command
52 * when a control channel message is received.
55 ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) {
60 data = isccc_alist_lookup(message, "_data");
65 return (ISC_R_FAILURE);
68 result = isccc_cc_lookupstring(data, "type", &command);
69 if (result != ISC_R_SUCCESS) {
71 * We have no idea what this is.
76 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
77 NS_LOGMODULE_CONTROL, ISC_LOG_DEBUG(1),
78 "received control channel command '%s'",
82 * Compare the 'command' parameter against all known control commands.
84 if (command_compare(command, NS_COMMAND_RELOAD)) {
85 result = ns_server_reloadcommand(ns_g_server, command);
86 } else if (command_compare(command, NS_COMMAND_RECONFIG)) {
87 result = ns_server_reconfigcommand(ns_g_server, command);
88 } else if (command_compare(command, NS_COMMAND_REFRESH)) {
89 result = ns_server_refreshcommand(ns_g_server, command);
90 } else if (command_compare(command, NS_COMMAND_HALT)) {
91 ns_server_flushonshutdown(ns_g_server, ISC_FALSE);
93 result = ISC_R_SUCCESS;
94 } else if (command_compare(command, NS_COMMAND_STOP)) {
95 ns_server_flushonshutdown(ns_g_server, ISC_TRUE);
97 result = ISC_R_SUCCESS;
98 } else if (command_compare(command, NS_COMMAND_DUMPSTATS)) {
99 result = ns_server_dumpstats(ns_g_server);
100 } else if (command_compare(command, NS_COMMAND_QUERYLOG)) {
101 result = ns_server_togglequerylog(ns_g_server);
102 } else if (command_compare(command, NS_COMMAND_DUMPDB)) {
103 ns_server_dumpdb(ns_g_server);
104 result = ISC_R_SUCCESS;
105 } else if (command_compare(command, NS_COMMAND_TRACE)) {
106 result = ns_server_setdebuglevel(ns_g_server, command);
107 } else if (command_compare(command, NS_COMMAND_NOTRACE)) {
109 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
110 result = ISC_R_SUCCESS;
111 } else if (command_compare(command, NS_COMMAND_FLUSH)) {
112 result = ns_server_flushcache(ns_g_server, command);
113 } else if (command_compare(command, NS_COMMAND_STATUS)) {
114 result = ns_server_status(ns_g_server, text);
115 } else if (command_compare(command, NS_COMMAND_NULL)) {
116 result = ISC_R_SUCCESS;
118 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
119 NS_LOGMODULE_CONTROL, ISC_LOG_WARNING,
120 "unknown control channel command '%s'",
122 result = DNS_R_UNKNOWNCOMMAND;