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.2.2.11 2004/09/03 03:43:31 marka Exp $ */
25 #include <isc/event.h>
27 #include <isc/timer.h>
30 #include <dns/result.h>
32 #include <isccc/alist.h>
34 #include <isccc/result.h>
36 #include <named/control.h>
37 #include <named/log.h>
39 #include <named/server.h>
42 command_compare(const char *text, const char *command) {
43 unsigned int commandlen = strlen(command);
44 if (strncasecmp(text, command, commandlen) == 0 &&
45 (text[commandlen] == '\0' ||
46 text[commandlen] == ' ' ||
47 text[commandlen] == '\t'))
53 * This function is called to process the incoming command
54 * when a control channel message is received.
57 ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) {
62 data = isccc_alist_lookup(message, "_data");
67 return (ISC_R_FAILURE);
70 result = isccc_cc_lookupstring(data, "type", &command);
71 if (result != ISC_R_SUCCESS) {
73 * We have no idea what this is.
78 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
79 NS_LOGMODULE_CONTROL, ISC_LOG_DEBUG(1),
80 "received control channel command '%s'",
84 * Compare the 'command' parameter against all known control commands.
86 if (command_compare(command, NS_COMMAND_RELOAD)) {
87 result = ns_server_reloadcommand(ns_g_server, command, text);
88 } else if (command_compare(command, NS_COMMAND_RECONFIG)) {
89 result = ns_server_reconfigcommand(ns_g_server, command);
90 } else if (command_compare(command, NS_COMMAND_REFRESH)) {
91 result = ns_server_refreshcommand(ns_g_server, command, text);
92 } else if (command_compare(command, NS_COMMAND_RETRANSFER)) {
93 result = ns_server_retransfercommand(ns_g_server, command);
94 } else if (command_compare(command, NS_COMMAND_HALT)) {
95 ns_server_flushonshutdown(ns_g_server, ISC_FALSE);
96 ns_os_shutdownmsg(command, text);
98 result = ISC_R_SUCCESS;
99 } else if (command_compare(command, NS_COMMAND_STOP)) {
100 ns_server_flushonshutdown(ns_g_server, ISC_TRUE);
101 ns_os_shutdownmsg(command, text);
103 result = ISC_R_SUCCESS;
104 } else if (command_compare(command, NS_COMMAND_DUMPSTATS)) {
105 result = ns_server_dumpstats(ns_g_server);
106 } else if (command_compare(command, NS_COMMAND_QUERYLOG)) {
107 result = ns_server_togglequerylog(ns_g_server);
108 } else if (command_compare(command, NS_COMMAND_DUMPDB)) {
109 ns_server_dumpdb(ns_g_server, command);
110 result = ISC_R_SUCCESS;
111 } else if (command_compare(command, NS_COMMAND_TRACE)) {
112 result = ns_server_setdebuglevel(ns_g_server, command);
113 } else if (command_compare(command, NS_COMMAND_NOTRACE)) {
115 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
116 result = ISC_R_SUCCESS;
117 } else if (command_compare(command, NS_COMMAND_FLUSH)) {
118 result = ns_server_flushcache(ns_g_server, command);
119 } else if (command_compare(command, NS_COMMAND_FLUSHNAME)) {
120 result = ns_server_flushname(ns_g_server, command);
121 } else if (command_compare(command, NS_COMMAND_STATUS)) {
122 result = ns_server_status(ns_g_server, text);
123 } else if (command_compare(command, NS_COMMAND_FREEZE)) {
124 result = ns_server_freeze(ns_g_server, ISC_TRUE, command);
125 } else if (command_compare(command, NS_COMMAND_UNFREEZE) ||
126 command_compare(command, NS_COMMAND_THAW)) {
127 result = ns_server_freeze(ns_g_server, ISC_FALSE, command);
128 } else if (command_compare(command, NS_COMMAND_RECURSING)) {
129 result = ns_server_dumprecursing(ns_g_server);
130 } else if (command_compare(command, NS_COMMAND_NULL)) {
131 result = ISC_R_SUCCESS;
133 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
134 NS_LOGMODULE_CONTROL, ISC_LOG_WARNING,
135 "unknown control channel command '%s'",
137 result = DNS_R_UNKNOWNCOMMAND;