Commit 484d5343 authored by Filip Siroky's avatar Filip Siroky Committed by Filip Široký

zone-status: add freeze information

parent 55bfebe9
......@@ -143,10 +143,10 @@ typedef enum {
ZONE_STATUS_NONE = 0,
ZONE_STATUS_TYPE = 1,
ZONE_STATUS_SERIAL,
ZONE_STATUS_NEXT_EVENT,
ZONE_STATUS_AUTO_DNSSEC,
ZONE_STATUS_TRANSACTION,
ZONE_STATUS_EVENT_TIMERS,
ZONE_STATUS_EVENT_STATUS,
ZONE_STATUS_FREEZE,
} zone_status_param ;
static zone_status_param zone_status_param_check(const char *param)
......@@ -160,18 +160,18 @@ static zone_status_param zone_status_param_check(const char *param)
if (strcmp(param, "serial") == 0) {
return ZONE_STATUS_SERIAL;
}
if (strcmp(param, "next-event") == 0) {
return ZONE_STATUS_NEXT_EVENT;
}
if (strcmp(param, "auto-dnssec") == 0) {
return ZONE_STATUS_AUTO_DNSSEC;
}
if (strcmp(param, "transaction") == 0) {
return ZONE_STATUS_TRANSACTION;
}
if (strcmp(param, "event-timers") == 0) {
return ZONE_STATUS_EVENT_TIMERS;
}
if (strcmp(param, "event-status") == 0) {
return ZONE_STATUS_EVENT_STATUS;
}
if (strcmp(param, "freeze") == 0) {
return ZONE_STATUS_FREEZE;
}
return ZONE_STATUS_INVALID;
}
......@@ -241,75 +241,28 @@ static int zone_status(zone_t *zone, ctl_args_t *args)
type = KNOT_CTL_TYPE_EXTRA;
}
}
// Next event.
if (param == ZONE_STATUS_NEXT_EVENT || param == ZONE_STATUS_NONE) {
data[KNOT_CTL_IDX_TYPE] = "next-event";
zone_event_type_t next_type = ZONE_EVENT_INVALID;
time_t next_time = zone_events_get_next(zone, &next_type);
if (next_type != ZONE_EVENT_INVALID) {
const char *next_name = zone_events_get_name(next_type);
next_time = next_time - time(NULL);
if (next_time < 0) {
ret = snprintf(buff, sizeof(buff), "%s pending",
next_name);
} else {
ret = snprintf(buff, sizeof(buff), "%s in %lldh%lldm%llds",
next_name,
(long long)(next_time / 3600),
(long long)(next_time % 3600) / 60,
(long long)(next_time % 60));
}
if (ret < 0 || ret >= sizeof(buff)) {
return KNOT_ESPACE;
}
data[KNOT_CTL_IDX_DATA] = buff;
} else {
data[KNOT_CTL_IDX_DATA] = "idle";
}
// Zone transaction.
if (param == ZONE_STATUS_TRANSACTION || param == ZONE_STATUS_NONE) {
data[KNOT_CTL_IDX_TYPE] = "transaction";
data[KNOT_CTL_IDX_DATA] = (zone->control_update != NULL) ? "open" : "none";
ret = knot_ctl_send(args->ctl, type, &data);
if (ret != KNOT_EOK) {
return ret;
} else {
type = KNOT_CTL_TYPE_EXTRA;
}
}
// DNSSEC re-signing time.
if (param == ZONE_STATUS_AUTO_DNSSEC || param == ZONE_STATUS_NONE) {
data[KNOT_CTL_IDX_TYPE] = "auto-dnssec";
conf_val_t val = conf_zone_get(conf(), C_DNSSEC_SIGNING, zone->name);
if (conf_bool(&val)) {
struct tm time_gm = { 0 };
time_t refresh_at = zone_events_get_time(zone, ZONE_EVENT_DNSSEC);
gmtime_r(&refresh_at, &time_gm);
size_t written = strftime(buff, sizeof(buff), KNOT_LOG_TIME_FORMAT,
&time_gm);
if (written == 0) {
return KNOT_ESPACE;
}
data[KNOT_CTL_IDX_DATA] = buff;
// frozen
bool frozen = zone->events.frozen;
bool ufrozen = zone->events.ufrozen;
if (param == ZONE_STATUS_FREEZE || param == ZONE_STATUS_NONE) {
data[KNOT_CTL_IDX_TYPE] = "frozen";
if (frozen) {
data[KNOT_CTL_IDX_DATA] = "yes";
} else if (ufrozen) {
data[KNOT_CTL_IDX_DATA] = "frozen by user";
} else {
data[KNOT_CTL_IDX_DATA] = "disabled";
data[KNOT_CTL_IDX_DATA] = "no";
}
ret = knot_ctl_send(args->ctl, type, &data);
if (ret != KNOT_EOK) {
return ret;
} else {
type = KNOT_CTL_TYPE_EXTRA;
}
}
// Zone transaction.
if (param == ZONE_STATUS_TRANSACTION || param == ZONE_STATUS_NONE) {
data[KNOT_CTL_IDX_TYPE] = "transaction";
data[KNOT_CTL_IDX_DATA] = (zone->control_update != NULL) ? "open" : "none";
ret = knot_ctl_send(args->ctl, type, &data);
ret = knot_ctl_send(args->ctl, KNOT_CTL_TYPE_DATA, &data);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -318,28 +271,30 @@ static int zone_status(zone_t *zone, ctl_args_t *args)
if (param == ZONE_STATUS_EVENT_TIMERS || param == ZONE_STATUS_NONE) {
time_t ev_time;
for (zone_event_type_t i = 0; i < ZONE_EVENT_COUNT; i++) {
data[KNOT_CTL_IDX_TYPE] = zone_events_get_name(i);
if (!frozen && (!ufrozen || !ufreeze_applies(i))) {
data[KNOT_CTL_IDX_TYPE] = zone_events_get_name(i);
ev_time = zone_events_get_time(zone, i);
ev_time = ev_time - time(NULL);
if (ev_time < 0) {
ret = snprintf(buff, sizeof(buff), "pending");
} else {
ret = snprintf(buff, sizeof(buff), "in %lldh%lldm%llds",
(long long)(ev_time / 3600),
(long long)(ev_time % 3600) / 60,
(long long)(ev_time % 60));
}
if (ret < 0 || ret >= sizeof(buff)) {
return KNOT_ESPACE;
}
data[KNOT_CTL_IDX_DATA] = buff;
ev_time = zone_events_get_time(zone, i);
ev_time = ev_time - time(NULL);
if (ev_time < 0) {
ret = snprintf(buff, sizeof(buff), "pending");
} else {
ret = snprintf(buff, sizeof(buff), "in %lldh%lldm%llds",
(long long)(ev_time / 3600),
(long long)(ev_time % 3600) / 60,
(long long)(ev_time % 60));
}
if (ret < 0 || ret >= sizeof(buff)) {
return KNOT_ESPACE;
}
data[KNOT_CTL_IDX_DATA] = buff;
ret = knot_ctl_send(args->ctl, !i? KNOT_CTL_TYPE_DATA : KNOT_CTL_TYPE_EXTRA, &data);
if (ret != KNOT_EOK) {
return ret;
ret = knot_ctl_send(args->ctl, KNOT_CTL_TYPE_EXTRA, &data);
if (ret != KNOT_EOK) {
return ret;
}
type = KNOT_CTL_TYPE_EXTRA;
}
type = KNOT_CTL_TYPE_EXTRA;
}
}
......
......@@ -67,7 +67,7 @@ static bool valid_event(zone_event_type_t type)
return (type > ZONE_EVENT_INVALID && type < ZONE_EVENT_COUNT);
}
static bool ufreeze_applies(zone_event_type_t type)
bool ufreeze_applies(zone_event_type_t type)
{
switch (type) {
case ZONE_EVENT_LOAD:
......
......@@ -141,6 +141,13 @@ void zone_events_schedule_user(struct zone *zone, zone_event_type_t type);
*/
void zone_events_freeze(struct zone *zone);
/*!
* \brief ufreeze_applies
* \param type Type of event to be checked
* \return true / false if user freeze applies
*/
bool ufreeze_applies(zone_event_type_t type);
/*!
* \brief Start the events processing.
*
......
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