cmdmon: add refresh command

This command can be used to resolve the names of configured sources to
IP addresses again.
This commit is contained in:
Gautier PHILIPPON 2015-09-29 16:08:43 +02:00 committed by Miroslav Lichvar
parent 440c159217
commit 3eb43f4619
6 changed files with 49 additions and 1 deletions

View file

@ -90,7 +90,8 @@
#define REQ_MODIFY_MAKESTEP 50
#define REQ_SMOOTHING 51
#define REQ_SMOOTHTIME 52
#define N_REQUEST_TYPES 53
#define REQ_REFRESH 53
#define N_REQUEST_TYPES 54
/* Special utoken value used to log on with first exchange being the
password. (This time value has long since gone by) */

View file

@ -2293,6 +2293,14 @@ process_cmd_reselect(CMD_Request *msg, char *line)
/* ================================================== */
static void
process_cmd_refresh(CMD_Request *msg, char *line)
{
msg->command = htons(REQ_REFRESH);
}
/* ================================================== */
static int
process_cmd_waitsync(char *line)
{
@ -2520,6 +2528,8 @@ process_line(char *line)
do_normal_submit = 0;
quit = 1;
ret = 1;
} else if (!strcmp(command, "refresh")) {
process_cmd_refresh(&tx_message, line);
} else if (!strcmp(command, "rekey")) {
process_cmd_rekey(&tx_message, line);
} else if (!strcmp(command, "reselect")) {

View file

@ -129,6 +129,7 @@ static const char permissions[] = {
PERMIT_AUTH, /* MODIFY_MAKESTEP */
PERMIT_OPEN, /* SMOOTHING */
PERMIT_AUTH, /* SMOOTHTIME */
PERMIT_AUTH, /* REFRESH */
};
/* ================================================== */
@ -1140,6 +1141,14 @@ handle_reselect(CMD_Request *rx_message, CMD_Reply *tx_message)
SRC_ReselectSource();
}
/* ================================================== */
static void
handle_refresh(CMD_Request *rx_message, CMD_Reply *tx_message)
{
NSR_RefreshAddresses();
}
/* ================================================== */
/* Read a packet and process it */
@ -1534,6 +1543,10 @@ read_from_cmd_socket(void *anything)
handle_modify_polltarget(&rx_message, &tx_message);
break;
case REQ_REFRESH:
handle_refresh(&rx_message, &tx_message);
break;
default:
assert(0);
break;

View file

@ -703,6 +703,23 @@ NSR_HandleBadSource(IPAddr *address)
/* ================================================== */
void
NSR_RefreshAddresses(void)
{
SourceRecord *record;
unsigned int i;
for (i = 0; i < ARR_GetSize(records); i++) {
record = get_record(i);
if (!record->remote_addr || !record->name)
continue;
resolve_source_replacement(record);
}
}
/* ================================================== */
static void remove_tentative_pool_sources(int pool)
{
SourceRecord *record;

View file

@ -80,6 +80,9 @@ extern void NSR_RemoveAllSources(void);
/* Procedure to try to find a replacement for a bad source */
extern void NSR_HandleBadSource(IPAddr *address);
/* Procedure to resolve all names again */
extern void NSR_RefreshAddresses(void);
/* This routine is called by ntp_io when a new packet arrives off the network */
extern void NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr, int length);

View file

@ -150,6 +150,8 @@ command_unpadded_length(CMD_Request *r)
return offsetof(CMD_Request, data.null.EOR);
case REQ_SMOOTHTIME:
return offsetof(CMD_Request, data.smoothtime.EOR);
case REQ_REFRESH:
return offsetof(CMD_Request, data.null.EOR);
default:
/* If we fall through the switch, it most likely means we've forgotten to implement a new case */
assert(0);
@ -304,6 +306,8 @@ PKL_CommandPaddingLength(CMD_Request *r)
return PADDING_LENGTH(data.null.EOR, data.smoothing.EOR);
case REQ_SMOOTHTIME:
return PADDING_LENGTH(data.smoothtime.EOR, data.null.EOR);
case REQ_REFRESH:
return PADDING_LENGTH(data.null.EOR, data.null.EOR);
default:
/* If we fall through the switch, it most likely means we've forgotten to implement a new case */
assert(0);