2 * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2001-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or 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.20.10.10 2007/09/13 23:46:26 tbox Exp $ */
26 #include <isc/event.h>
28 #include <isc/string.h>
29 #include <isc/timer.h>
32 #include <dns/result.h>
34 #include <isccc/alist.h>
36 #include <isccc/result.h>
38 #include <named/control.h>
39 #include <named/log.h>
41 #include <named/server.h>
43 #include <named/ns_smf_globals.h>
47 command_compare(const char *text
, const char *command
) {
48 unsigned int commandlen
= strlen(command
);
49 if (strncasecmp(text
, command
, commandlen
) == 0 &&
50 (text
[commandlen
] == '\0' ||
51 text
[commandlen
] == ' ' ||
52 text
[commandlen
] == '\t'))
58 * This function is called to process the incoming command
59 * when a control channel message is received.
62 ns_control_docommand(isccc_sexpr_t
*message
, isc_buffer_t
*text
) {
67 ns_smf_want_disable
= 0;
70 data
= isccc_alist_lookup(message
, "_data");
75 return (ISC_R_FAILURE
);
78 result
= isccc_cc_lookupstring(data
, "type", &command
);
79 if (result
!= ISC_R_SUCCESS
) {
81 * We have no idea what this is.
86 isc_log_write(ns_g_lctx
, NS_LOGCATEGORY_GENERAL
,
87 NS_LOGMODULE_CONTROL
, ISC_LOG_DEBUG(1),
88 "received control channel command '%s'",
92 * Compare the 'command' parameter against all known control commands.
94 if (command_compare(command
, NS_COMMAND_RELOAD
)) {
95 result
= ns_server_reloadcommand(ns_g_server
, command
, text
);
96 } else if (command_compare(command
, NS_COMMAND_RECONFIG
)) {
97 result
= ns_server_reconfigcommand(ns_g_server
, command
);
98 } else if (command_compare(command
, NS_COMMAND_REFRESH
)) {
99 result
= ns_server_refreshcommand(ns_g_server
, command
, text
);
100 } else if (command_compare(command
, NS_COMMAND_RETRANSFER
)) {
101 result
= ns_server_retransfercommand(ns_g_server
, command
);
102 } else if (command_compare(command
, NS_COMMAND_HALT
)) {
105 * If we are managed by smf(5), AND in chroot, then
106 * we cannot connect to the smf repository, so just
107 * return with an appropriate message back to rndc.
109 if (ns_smf_got_instance
== 1 && ns_smf_chroot
== 1) {
110 result
= ns_smf_add_message(text
);
114 * If we are managed by smf(5) but not in chroot,
115 * try to disable ourselves the smf way.
117 if (ns_smf_got_instance
== 1 && ns_smf_chroot
== 0)
118 ns_smf_want_disable
= 1;
120 * If ns_smf_got_instance = 0, ns_smf_chroot
121 * is not relevant and we fall through to
122 * isc_app_shutdown below.
125 ns_server_flushonshutdown(ns_g_server
, ISC_FALSE
);
126 ns_os_shutdownmsg(command
, text
);
128 result
= ISC_R_SUCCESS
;
129 } else if (command_compare(command
, NS_COMMAND_STOP
)) {
131 if (ns_smf_got_instance
== 1 && ns_smf_chroot
== 1) {
132 result
= ns_smf_add_message(text
);
135 if (ns_smf_got_instance
== 1 && ns_smf_chroot
== 0)
136 ns_smf_want_disable
= 1;
138 ns_server_flushonshutdown(ns_g_server
, ISC_TRUE
);
139 ns_os_shutdownmsg(command
, text
);
141 result
= ISC_R_SUCCESS
;
142 } else if (command_compare(command
, NS_COMMAND_DUMPSTATS
)) {
143 result
= ns_server_dumpstats(ns_g_server
);
144 } else if (command_compare(command
, NS_COMMAND_QUERYLOG
)) {
145 result
= ns_server_togglequerylog(ns_g_server
);
146 } else if (command_compare(command
, NS_COMMAND_DUMPDB
)) {
147 ns_server_dumpdb(ns_g_server
, command
);
148 result
= ISC_R_SUCCESS
;
149 } else if (command_compare(command
, NS_COMMAND_TRACE
)) {
150 result
= ns_server_setdebuglevel(ns_g_server
, command
);
151 } else if (command_compare(command
, NS_COMMAND_NOTRACE
)) {
153 isc_log_setdebuglevel(ns_g_lctx
, ns_g_debuglevel
);
154 result
= ISC_R_SUCCESS
;
155 } else if (command_compare(command
, NS_COMMAND_FLUSH
)) {
156 result
= ns_server_flushcache(ns_g_server
, command
);
157 } else if (command_compare(command
, NS_COMMAND_FLUSHNAME
)) {
158 result
= ns_server_flushname(ns_g_server
, command
);
159 } else if (command_compare(command
, NS_COMMAND_STATUS
)) {
160 result
= ns_server_status(ns_g_server
, text
);
161 } else if (command_compare(command
, NS_COMMAND_FREEZE
)) {
162 result
= ns_server_freeze(ns_g_server
, ISC_TRUE
, command
);
163 } else if (command_compare(command
, NS_COMMAND_UNFREEZE
) ||
164 command_compare(command
, NS_COMMAND_THAW
)) {
165 result
= ns_server_freeze(ns_g_server
, ISC_FALSE
, command
);
166 } else if (command_compare(command
, NS_COMMAND_RECURSING
)) {
167 result
= ns_server_dumprecursing(ns_g_server
);
168 } else if (command_compare(command
, NS_COMMAND_TIMERPOKE
)) {
169 result
= ISC_R_SUCCESS
;
170 isc_timermgr_poke(ns_g_timermgr
);
171 } else if (command_compare(command
, NS_COMMAND_NULL
)) {
172 result
= ISC_R_SUCCESS
;
173 } else if (command_compare(command
, NS_COMMAND_NOTIFY
)) {
174 result
= ns_server_notifycommand(ns_g_server
, command
, text
);
175 } else if (command_compare(command
, NS_COMMAND_VALIDATION
)) {
176 result
= ns_server_validation(ns_g_server
, command
);
178 isc_log_write(ns_g_lctx
, NS_LOGCATEGORY_GENERAL
,
179 NS_LOGMODULE_CONTROL
, ISC_LOG_WARNING
,
180 "unknown control channel command '%s'",
182 result
= DNS_R_UNKNOWNCOMMAND
;