]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Accept packets with compatible NTP versions
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 25 May 2011 14:59:40 +0000 (16:59 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 25 May 2011 14:59:40 +0000 (16:59 +0200)
All incoming NTP packets are now required to have version 2, 3 or 4.

acquire.c
ntp_core.c

index ff554ca18eb3f1442df74b88925f72c133974776..742f0f836b976b418a9bf0475ed20091fa9796c3 100644 (file)
--- a/acquire.c
+++ b/acquire.c
 
 #define RETRANSMISSION_TIMEOUT (1.0)
 
+#define NTP_VERSION 3
+#define NTP_MAX_COMPAT_VERSION 4
+#define NTP_MIN_COMPAT_VERSION 2
+
 typedef struct {
   IPAddr ip_addr;               /* Address of the server */
   int sanity;                   /* Flag indicating whether source
@@ -246,7 +250,7 @@ static void
 probe_source(SourceRecord *src)
 {
   NTP_Packet pkt;
-  int version = 3;
+  int version = NTP_VERSION;
   NTP_Mode my_mode = MODE_CLIENT;
   struct timeval cooked;
   union sockaddr_in46 his_addr;
@@ -372,7 +376,7 @@ process_receive(NTP_Packet *msg, SourceRecord *src, struct timeval *now)
   mode = lvm & 0x7;
 
   if ((leap == LEAP_Unsynchronised) ||
-      (version != 3) ||
+      (version  < NTP_MIN_COMPAT_VERSION || version > NTP_MAX_COMPAT_VERSION) ||
       (mode != MODE_SERVER && mode != MODE_PASSIVE)) {
     return;
   }
index 6c8a4eacb5bfa3680598d1296d35cee85cc8f489..eec6d9c3eb770e70ac48ceb1460e11cc10155820 100644 (file)
@@ -192,6 +192,10 @@ struct NCR_Instance_Record {
 /* The NTP protocol version that we support */
 #define NTP_VERSION 3
 
+/* Compatible NTP protocol versions */
+#define NTP_MAX_COMPAT_VERSION 4
+#define NTP_MIN_COMPAT_VERSION 2
+
 /* Maximum allowed dispersion - as defined in RFC1305 (16 seconds) */
 #define NTP_MAX_DISPERSION 16.0
 
@@ -515,7 +519,7 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
   struct timeval our_ref_time;
   double our_root_delay, our_root_dispersion;
 
-  version = 3;
+  version = NTP_VERSION;
 
   LCL_ReadCookedTime(&local_transmit, NULL);
   REF_GetReferenceParams(&local_transmit,
@@ -1329,7 +1333,7 @@ process_known
 
   /* Check version */
   version = (message->lvm >> 3) & 0x7;
-  if (version != NTP_VERSION) {
+  if (version < NTP_MIN_COMPAT_VERSION || version > NTP_MAX_COMPAT_VERSION) {
     /* Ignore packet, but might want to log it */
     return;
   } 
@@ -1521,7 +1525,14 @@ NCR_ProcessNoauthUnknown(NTP_Packet *message, struct timeval *now, double now_er
 
   NTP_Mode his_mode;
   NTP_Mode my_mode;
-  int my_poll;
+  int my_poll, version;
+
+  /* Check version */
+  version = (message->lvm >> 3) & 0x7;
+  if (version < NTP_MIN_COMPAT_VERSION || version > NTP_MAX_COMPAT_VERSION) {
+    /* Ignore packet, but might want to log it */
+    return;
+  }
 
   if (ADF_IsAllowed(access_auth_table, &remote_addr->ip_addr)) {
 
@@ -1589,10 +1600,17 @@ NCR_ProcessAuthUnknown(NTP_Packet *message, struct timeval *now, double now_err,
 
   NTP_Mode his_mode;
   NTP_Mode my_mode;
-  int my_poll;
+  int my_poll, version;
   int valid_key, valid_auth;
   unsigned long key_id;
 
+  /* Check version */
+  version = (message->lvm >> 3) & 0x7;
+  if (version < NTP_MIN_COMPAT_VERSION || version > NTP_MAX_COMPAT_VERSION) {
+    /* Ignore packet, but might want to log it */
+    return;
+  }
+
   if (ADF_IsAllowed(access_auth_table, &remote_addr->ip_addr)) {
 
     his_mode = message->lvm & 0x07;