Commit 5f5e629d authored by Dominik Taborsky's avatar Dominik Taborsky Committed by Daniel Salzman

ctl: new control commands for editing zones

parent ff3548df
......@@ -38,7 +38,7 @@ DNS features:
Server features:
* Adding/removing zones on-the-fly
* Adding/removing/editing zones on-the-fly
* Reconfiguring server instance on-the-fly
* Dynamic configuration
* IPv4 and IPv6 support
......
......@@ -75,7 +75,8 @@ Check if the server is running.
Stop the server if running.
.TP
\fBreload\fP
Reload the server configuration and modified zone files.
Reload the server configuration and modified zone files. All open zone
transactions will be aborted!
.TP
\fBzone\-check\fP [\fIzone\fP\&...]
Test if the server can load the zone. Semantic checks are executed if enabled
......@@ -90,7 +91,8 @@ Show the zone status. (*)
\fBzone\-reload\fP [\fIzone\fP\&...]
Trigger a zone reload from a disk without checking its modification time. For
slave zone, the refresh from a master server is scheduled; for master zone,
the notification of slave servers is scheduled.
the notification of slave servers is scheduled. An open zone transaction
will be aborted!
.TP
\fBzone\-refresh\fP [\fIzone\fP\&...]
Trigger a check for the zone serial on the zone\(aqs master. If the master has a
......@@ -107,6 +109,31 @@ Trigger a zone journal flush into the zone file.
Trigger a DNSSEC re\-sign of the zone. Existing signatures will be dropped.
This command is valid for zones with automatic DNSSEC signing.
.TP
\fBzone\-read\fP \fIzone\fP [\fIowner\fP [\fItype\fP]]
Get zone data that are currently being presented.
.TP
\fBzone\-begin\fP \fIzone\fP\&...
Begin a zone transaction.
.TP
\fBzone\-commit\fP \fIzone\fP\&...
Commit the zone transaction. All changes are applied to the zone.
.TP
\fBzone\-abort\fP \fIzone\fP\&...
Abort the zone transaction. All changes are discarded.
.TP
\fBzone\-diff\fP \fIzone\fP
Get zone changes within the transaction.
.TP
\fBzone\-get\fP \fIzone\fP [\fIowner\fP [\fItype\fP]]
Get zone data within the transaction.
.TP
\fBzone\-set\fP \fIzone\fP \fIowner\fP [\fIttl\fP] \fItype\fP \fIrdata\fP
Add zone record within the transaction. The first record in a rrset
requires a ttl value specified.
.TP
\fBzone\-unset\fP \fIzone\fP \fIowner\fP [\fItype\fP [\fIrdata\fP]]
Remove zone data within the transaction.
.TP
\fBconf\-init\fP
Initialize the configuration database. (*)
.TP
......@@ -150,7 +177,9 @@ Unset the item data in the transaction.
.UNINDENT
.SS Note
.sp
Empty \fIzone\fP parameter means all zones.
Empty or \fB\-\-\fP \fIzone\fP parameter means all zones or all zones with a transaction.
.sp
Use \fB@\fP \fIowner\fP to denote the zone name.
.sp
Type \fIitem\fP parameter in the form of \fIsection\fP[\fB[\fP\fIid\fP\fB]\fP][\fB\&.\fP\fIname\fP].
.sp
......@@ -234,6 +263,17 @@ $ knotc conf\-commit
.fi
.UNINDENT
.UNINDENT
.SS Get the SOA record for each configured zone
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
$ knotc zone\-read \-\- @ SOA
.ft P
.fi
.UNINDENT
.UNINDENT
.SH SEE ALSO
.sp
\fIknotd(8)\fP, \fIknot.conf(5)\fP, \fIeditrc(5)\fP\&.
......
......@@ -52,7 +52,8 @@ Actions
Stop the server if running.
**reload**
Reload the server configuration and modified zone files.
Reload the server configuration and modified zone files. All open zone
transactions will be aborted!
**zone-check** [*zone*...]
Test if the server can load the zone. Semantic checks are executed if enabled
......@@ -67,7 +68,8 @@ Actions
**zone-reload** [*zone*...]
Trigger a zone reload from a disk without checking its modification time. For
slave zone, the refresh from a master server is scheduled; for master zone,
the notification of slave servers is scheduled.
the notification of slave servers is scheduled. An open zone transaction
will be aborted!
**zone-refresh** [*zone*...]
Trigger a check for the zone serial on the zone's master. If the master has a
......@@ -84,6 +86,31 @@ Actions
Trigger a DNSSEC re-sign of the zone. Existing signatures will be dropped.
This command is valid for zones with automatic DNSSEC signing.
**zone-read** *zone* [*owner* [*type*]]
Get zone data that are currently being presented.
**zone-begin** *zone*...
Begin a zone transaction.
**zone-commit** *zone*...
Commit the zone transaction. All changes are applied to the zone.
**zone-abort** *zone*...
Abort the zone transaction. All changes are discarded.
**zone-diff** *zone*
Get zone changes within the transaction.
**zone-get** *zone* [*owner* [*type*]]
Get zone data within the transaction.
**zone-set** *zone* *owner* [*ttl*] *type* *rdata*
Add zone record within the transaction. The first record in a rrset
requires a ttl value specified.
**zone-unset** *zone* *owner* [*type* [*rdata*]]
Remove zone data within the transaction.
**conf-init**
Initialize the configuration database. (*)
......@@ -128,7 +155,9 @@ Actions
Note
....
Empty *zone* parameter means all zones.
Empty or **--** *zone* parameter means all zones or all zones with a transaction.
Use **@** *owner* to denote the zone name.
Type *item* parameter in the form of *section*\ [**[**\ *id*\ **]**\ ][**.**\ *name*].
......@@ -193,6 +222,13 @@ Add example.org zone with a zonefile location
$ knotc conf-set 'zone[example.org].file' '/var/zones/example.org.zone'
$ knotc conf-commit
Get the SOA record for each configured zone
...........................................
::
$ knotc zone-read -- @ SOA
See Also
--------
......
......@@ -180,6 +180,68 @@ actual consumption. Also, for slave servers with incoming transfers
enabled, be aware that the actual memory consumption might be double
or higher during transfers.
.. _Editing zones:
Reading and editing zones
=========================
Knot DNS allows you to read or change zone contents online using server
control interface.
To get contents of all configured zones, or a specific zone contents, or zone
records with a specific owner, or even with a specific record type::
$ knotc zone-read --
$ knotc zone-read example.com
$ knotc zone-read example.com ns1
$ knotc zone-read example.com ns1 NS
.. NOTE::
If the record owner is not a fully qualified domain name, then it is
considered as a relative name to the zone name.
To start a writing transaction on all zones or on specific zones::
$ knotc zone-begin --
$ knotc zone-begin example.com example.net
Now you can list all nodes within the transaction using the ```zone-get```
command, which always returns current data with all changes included. The
command has the same syntax as ```zone-read```.
Within the transaction, you can add a record to a specific zone or to all
zones with an open transaction::
$ knotc zone-add example.com ns1 3600 A 192.168.0.1
$ knotc zone-add -- ns1 3600 A 192.168.0.1
To remove all records with a specific owner, or a specific rrset, or a
specific record data::
$ knotc zone-remove example.com ns1
$ knotc zone-remove example.com ns1 A
$ knotc zone-remove example.com ns1 A 192.168.0.2
To see the difference between the original zone and the current version::
$ knotc zone-diff example.com
Finally, either commit or abort your transaction::
$ knotc zone-commit example.com
$ knotc zone-abort example.com
A full example of setting up a completely new zone from scratch::
$ knotc conf-begin
$ knotc conf-set zone.domain example.com
$ knotc conf-commit
$ knotc zone-begin example.com
$ knotc zone-add example.com @ 7200 SOA ns hostmaster 1 86400 900 691200 3600
$ knotc zone-add example.com ns 3600 A 192.168.0.1
$ knotc zone-add example.com www 3600 A 192.168.0.100
$ knotc zone-commit example.com
.. _Controlling running daemon:
Daemon controls
......
This diff is collapsed.
......@@ -46,6 +46,15 @@ typedef enum {
CTL_ZONE_FLUSH,
CTL_ZONE_SIGN,
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_CONF_LIST,
CTL_CONF_READ,
CTL_CONF_BEGIN,
......
......@@ -120,6 +120,11 @@ int event_load(conf_t *conf, zone_t *zone)
log_zone_info(zone->name, "loaded, serial %u", current_serial);
}
if (zone->control_update != NULL) {
log_zone_warning(zone->name, "control transaction aborted");
zone_control_clear(zone);
}
return KNOT_EOK;
fail:
......
......@@ -22,6 +22,7 @@
#include "knot/common/log.h"
#include "knot/nameserver/process_query.h"
#include "knot/query/requestor.h"
#include "knot/updates/zone-update.h"
#include "knot/zone/contents.h"
#include "knot/zone/serial.h"
#include "knot/zone/zone.h"
......@@ -77,6 +78,17 @@ zone_t* zone_new(const knot_dname_t *name)
return zone;
}
void zone_control_clear(zone_t *zone)
{
if (zone == NULL) {
return;
}
zone_update_clear(zone->control_update);
free(zone->control_update);
zone->control_update = NULL;
}
void zone_free(zone_t **zone_ptr)
{
if (zone_ptr == NULL || *zone_ptr == NULL) {
......@@ -93,6 +105,9 @@ void zone_free(zone_t **zone_ptr)
pthread_mutex_destroy(&zone->ddns_lock);
pthread_mutex_destroy(&zone->journal_lock);
/* Control update. */
zone_control_clear(zone);
/* Free preferred master. */
pthread_mutex_destroy(&zone->preferred_lock);
free(zone->preferred_master);
......
......@@ -36,6 +36,7 @@
#include "libknot/packet/pkt.h"
struct process_query_param;
struct zone_update;
/*!
* \brief Zone flags.
......@@ -72,6 +73,9 @@ typedef struct zone
size_t ddns_queue_size;
list_t ddns_queue;
/*! \brief Control update context. */
struct zone_update *control_update;
/*! \brief Journal access lock. */
pthread_mutex_t journal_lock;
......@@ -103,6 +107,13 @@ zone_t* zone_new(const knot_dname_t *name);
*/
void zone_free(zone_t **zone_ptr);
/*!
* \brief Clears possible control update transaction.
*
* \param zone Zone to be cleared.
*/
void zone_control_clear(zone_t *zone);
/*!
* \note Zone change API below, subject to change.
* \ref #223 New zone API
......
......@@ -157,6 +157,11 @@ static zone_t *create_zone_reload(conf_t *conf, const knot_dname_t *name,
assert(0);
}
if (old_zone->control_update != NULL) {
log_zone_warning(old_zone->name, "control transaction aborted");
zone_control_clear(old_zone);
}
return zone;
}
......
This diff is collapsed.
......@@ -36,7 +36,8 @@ typedef enum {
CMD_FREQ_ITEM = 1 << 3, /*!< Required item argument. */
CMD_FOPT_DATA = 1 << 4, /*!< Optional item data argument. */
CMD_FOPT_ZONE = 1 << 5, /*!< Optional zone name argument. */
CMD_FREQ_TXN = 1 << 6, /*!< Required open confdb transaction. */
CMD_FREQ_ZONE = 1 << 6, /*!< Required zone name argument. */
CMD_FREQ_TXN = 1 << 7, /*!< Required open confdb transaction. */
} cmd_flag_t;
struct cmd_desc;
......
......@@ -325,7 +325,11 @@ static unsigned char complete(EditLine *el, int ch)
}
// Complete the zone name.
if (desc->flags & CMD_FOPT_ZONE) {
if (desc->flags & (CMD_FREQ_ZONE | CMD_FOPT_ZONE)) {
if (token > 1 && !(desc->flags & CMD_FOPT_ZONE)) {
goto complete_exit;
}
if (desc->flags & CMD_FREAD) {
local_zones_lookup(el, argv[token], pos);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment