]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
client: add support for source identifiers
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 18 Feb 2020 09:48:10 +0000 (10:48 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 19 Feb 2020 14:03:20 +0000 (15:03 +0100)
Allow the new identifiers to be specified as addresses in commands that
modify or remove NTP sources.

client.c

index e08482949135c3dbb119ec4376f53600c195ba95..185b2cae2decf42340cac81c721e4925254e1d5a 100644 (file)
--- a/client.c
+++ b/client.c
@@ -320,6 +320,9 @@ bits_to_mask(int bits, int family, IPAddr *mask)
       for (; i < 16; i++)
         mask->addr.in6[i] = 0x0;
       break;
+    case IPADDR_ID:
+      mask->family = IPADDR_UNSPEC;
+      break;
     default:
       assert(0);
   }
@@ -327,6 +330,20 @@ bits_to_mask(int bits, int family, IPAddr *mask)
 
 /* ================================================== */
 
+static int
+parse_source_address(char *word, IPAddr *address)
+{
+  if (UTI_StringToIdIP(word, address))
+    return 1;
+
+  if (DNS_Name2IPAddress(word, address, 1) == DNS_Success)
+    return 1;
+
+  return 0;
+}
+
+/* ================================================== */
+
 static int
 read_mask_address(char *line, IPAddr *mask, IPAddr *address)
 {
@@ -353,7 +370,7 @@ read_mask_address(char *line, IPAddr *mask, IPAddr *address)
         }
       }
     } else {
-      if (DNS_Name2IPAddress(p, address, 1) == DNS_Success) {
+      if (parse_source_address(p, address)) {
         bits_to_mask(-1, address->family, mask);
         return 1;
       } else {
@@ -433,7 +450,7 @@ read_address_integer(char *line, IPAddr *address, int *value)
     LOG(LOGS_ERR, "Invalid syntax for address value");
     ok = 0;
   } else {
-    if (DNS_Name2IPAddress(hostname, address, 1) != DNS_Success) {
+    if (!parse_source_address(hostname, address)) {
       LOG(LOGS_ERR, "Could not get address for hostname");
       ok = 0;
     } else {
@@ -461,7 +478,7 @@ read_address_double(char *line, IPAddr *address, double *value)
     LOG(LOGS_ERR, "Invalid syntax for address value");
     ok = 0;
   } else {
-    if (DNS_Name2IPAddress(hostname, address, 1) != DNS_Success) {
+    if (!parse_source_address(hostname, address)) {
       LOG(LOGS_ERR, "Could not get address for hostname");
       ok = 0;
     } else {
@@ -1159,7 +1176,7 @@ process_cmd_delete(CMD_Request *msg, char *line)
     LOG(LOGS_ERR, "Invalid syntax for address");
     ok = 0;
   } else {
-    if (DNS_Name2IPAddress(hostname, &address, 1) != DNS_Success) {
+    if (!parse_source_address(hostname, &address)) {
       LOG(LOGS_ERR, "Could not get address for hostname");
       ok = 0;
     } else {
@@ -2350,7 +2367,7 @@ process_cmd_ntpdata(char *line)
 
   for (i = 0; i < n_sources; i++) {
     if (specified_addr) {
-      if (DNS_Name2IPAddress(line, &remote_addr, 1) != DNS_Success) {
+      if (!parse_source_address(line, &remote_addr)) {
         LOG(LOGS_ERR, "Could not get address for hostname");
         return 0;
       }