[chrony-dev] Feature chrony + patch |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
Hi,
I have exchanged some e-mails with Miroslav Lichvar about a feature I needed to refresh the ip adresses of sources.
I use a VPN and the DNS resolution is not the same if the VPN is up or down. The public ip resolution is still reachable when the VPN is up and that is why I wanted a way to refresh the source IP.
I've patched myself chrony to add the a command refresh to the client which redo the DNS resolution for all the sources. I have sent it to Miroslav Lichvar who reviewed it and recommended me to send here for wider review.
I am at your disposal for any improvements you could see.
Best regards
Gautier PHILIPPON
diff --git a/candm.h b/candm.h
index f3bea3a..8510aec 100644
--- a/candm.h
+++ b/candm.h
@@ -91,7 +91,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) */
diff --git a/client.c b/client.c
index abe01aa..9395e91 100644
--- a/client.c
+++ b/client.c
@@ -2319,6 +2319,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)
{
@@ -2579,6 +2587,8 @@ process_line(char *line, int *quit)
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")) {
diff --git a/cmdmon.c b/cmdmon.c
index 5d5c559..0e4b671 100644
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -165,6 +165,7 @@ static const char permissions[] = {
PERMIT_AUTH, /* MODIFY_MAKESTEP */
PERMIT_OPEN, /* SMOOTHING */
PERMIT_AUTH, /* SMOOTHTIME */
+ PERMIT_AUTH, /* REFRESH */
};
/* ================================================== */
@@ -1137,6 +1138,14 @@ handle_add_source(NTP_Source_Type type, CMD_Request *rx_message, CMD_Reply *tx_m
/* ================================================== */
static void
+handle_refresh(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+ NSR_IPRefreshAdresses();
+}
+
+/* ================================================== */
+
+static void
handle_del_source(CMD_Request *rx_message, CMD_Reply *tx_message)
{
NTP_Remote_Address rem_addr;
@@ -1869,6 +1878,10 @@ read_from_cmd_socket(void *anything)
handle_manual(&rx_message, &tx_message);
break;
+ case REQ_REFRESH:
+ handle_refresh(&rx_message, &tx_message);
+ break;
+
case REQ_N_SOURCES:
handle_n_sources(&rx_message, &tx_message);
break;
diff --git a/ntp_sources.c b/ntp_sources.c
index 9c56255..56b2526 100644
--- a/ntp_sources.c
+++ b/ntp_sources.c
@@ -114,6 +114,7 @@ static ARR_Instance pools;
static void resolve_sources(void *arg);
static void rehash_records(void);
static void clean_source_record(SourceRecord *record);
+void NSR_IPRefreshAdresses(void);
static void
slew_sources(struct timeval *raw,
@@ -661,7 +662,6 @@ resolve_source_replacement(SourceRecord *record)
us->replace_source = *record->remote_addr;
append_unresolved_source(us);
- NSR_ResolveSources();
}
/* ================================================== */
@@ -699,6 +699,26 @@ NSR_HandleBadSource(IPAddr *address)
last_replacement = now;
resolve_source_replacement(record);
+ NSR_ResolveSources();
+}
+
+/* ================================================== */
+
+void
+NSR_IPRefreshAdresses(void)
+{
+ SourceRecord *record;
+ unsigned int i;
+
+ for (i = 0; i < ARR_GetSize(records); i++) {
+ record = get_record(i);
+ if (record == NULL || record->name == NULL || record->remote_addr == NULL)
+ continue;
+
+ resolve_source_replacement(record);
+ }
+
+ NSR_ResolveSources();
}
/* ================================================== */
@@ -1079,6 +1099,5 @@ NSR_GetActivityReport(RPT_ActivityReport *report)
}
}
-
/* ================================================== */
diff --git a/ntp_sources.h b/ntp_sources.h
index 828a446..bc2d3dc 100644
--- a/ntp_sources.h
+++ b/ntp_sources.h
@@ -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 refresh the IP with a DNS resolution of the source records */
+extern void NSR_IPRefreshAdresses(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);
diff --git a/pktlength.c b/pktlength.c
index be773c2..e123ef4 100644
--- a/pktlength.c
+++ b/pktlength.c
@@ -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);