summaryrefslogtreecommitdiffstats
path: root/src/knot/ctl/commands.h
blob: ab7984e3976b2b4328e878e6ff7ecb299663f6e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*  Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#pragma once

#include "libknot/libknot.h"
#include "knot/server/server.h"

#define CTL_FLAG_FORCE		"F"
#define CTL_FLAG_BLOCKING	"B"

#define CTL_FLAG_DIFF_ADD	"+"
#define CTL_FLAG_DIFF_REM	"-"

#define CTL_FLAG_LIST_SCHEMA	"s"
#define CTL_FLAG_LIST_TXN	"t"
#define CTL_FLAG_LIST_ZONES	"z"

#define CTL_FLAG_STATUS_EMPTY	"e"
#define CTL_FLAG_STATUS_SLAVE	"s"
#define CTL_FLAG_STATUS_MEMBER	"m"

#define CTL_FILTER_FLUSH_OUTDIR		'd'

#define CTL_FILTER_STATUS_ROLE		'r'
#define CTL_FILTER_STATUS_SERIAL	's'
#define CTL_FILTER_STATUS_TRANSACTION	't'
#define CTL_FILTER_STATUS_FREEZE	'f'
#define CTL_FILTER_STATUS_CATALOG	'c'
#define CTL_FILTER_STATUS_EVENTS	'e'

#define CTL_FILTER_PURGE_EXPIRE		'e'
#define CTL_FILTER_PURGE_ZONEFILE	'f'
#define CTL_FILTER_PURGE_JOURNAL	'j'
#define CTL_FILTER_PURGE_TIMERS		't'
#define CTL_FILTER_PURGE_KASPDB		'k'
#define CTL_FILTER_PURGE_CATALOG	'c'
#define CTL_FILTER_PURGE_ORPHAN		'o'

#define CTL_FILTER_BACKUP_OUTDIR	'd'
#define CTL_FILTER_BACKUP_ZONEFILE	'z'
#define CTL_FILTER_BACKUP_NOZONEFILE	'Z'
#define CTL_FILTER_BACKUP_JOURNAL	'j'
#define CTL_FILTER_BACKUP_NOJOURNAL	'J'
#define CTL_FILTER_BACKUP_TIMERS	't'
#define CTL_FILTER_BACKUP_NOTIMERS	'T'
#define CTL_FILTER_BACKUP_KASPDB	'k'
#define CTL_FILTER_BACKUP_NOKASPDB	'K'
#define CTL_FILTER_BACKUP_CATALOG	'c'
#define CTL_FILTER_BACKUP_NOCATALOG	'C'

#define STATUS_EMPTY			"-"

/*! Control commands. */
typedef enum {
	CTL_NONE,

	CTL_STATUS,
	CTL_STOP,
	CTL_RELOAD,
	CTL_STATS,

	CTL_ZONE_STATUS,
	CTL_ZONE_RELOAD,
	CTL_ZONE_REFRESH,
	CTL_ZONE_RETRANSFER,
	CTL_ZONE_NOTIFY,
	CTL_ZONE_FLUSH,
	CTL_ZONE_BACKUP,
	CTL_ZONE_RESTORE,
	CTL_ZONE_SIGN,
	CTL_ZONE_KEYS_LOAD,
	CTL_ZONE_KEY_ROLL,
	CTL_ZONE_KSK_SBM,
	CTL_ZONE_FREEZE,
	CTL_ZONE_THAW,
	CTL_ZONE_XFR_FREEZE,
	CTL_ZONE_XFR_THAW,

	CTL_ZONE_READ,
	CTL_ZONE_BEGIN,
	CTL_ZONE_COMMIT,
	CTL_ZONE_ABORT,
	CTL_ZONE_DIFF,
	CTL_ZONE_GET,
	CTL_ZONE_SET,
	CTL_ZONE_UNSET,
	CTL_ZONE_PURGE,
	CTL_ZONE_STATS,

	CTL_CONF_LIST,
	CTL_CONF_READ,
	CTL_CONF_BEGIN,
	CTL_CONF_COMMIT,
	CTL_CONF_ABORT,
	CTL_CONF_DIFF,
	CTL_CONF_GET,
	CTL_CONF_SET,
	CTL_CONF_UNSET,
} ctl_cmd_t;

/*! Control command parameters. */
typedef struct {
	knot_ctl_t *ctl;
	knot_ctl_type_t type;
	knot_ctl_data_t data;
	server_t *server;
	bool suppress;	// Suppress error reporting in the "all zones" ctl commands.
} ctl_args_t;

/*!
 * Returns a string equivalent of the command.
 *
 * \param[in] cmd  Command.
 *
 * \return Command string or NULL.
 */
const char *ctl_cmd_to_str(ctl_cmd_t cmd);

/*!
 * Returns a command corresponding to the string.
 *
 * \param[in] cmd_str  Command string.
 *
 * \return Command.
 */
ctl_cmd_t ctl_str_to_cmd(const char *cmd_str);

/*!
 * Executes a control command.
 *
 * \param[in] cmd   Control command.
 * \param[in] args  Command arguments.
 *
 * \return Error code, KNOT_EOK if successful.
 */
int ctl_exec(ctl_cmd_t cmd, ctl_args_t *args);

/*!
 * Checks flag presence in flags.
 *
 * \param[in] flags  Flags to check presence in.
 * \param[in] flag   Checked flag.
 *
 * \return True if presented.
 */
bool ctl_has_flag(const char *flags, const char *flag);