Accept packets with compatible NTP versions

All incoming NTP packets are now required to have version 2, 3 or 4.
This commit is contained in:
Miroslav Lichvar
2011-05-25 16:59:40 +02:00
parent de4d14843f
commit 8cc7ebffa9
2 changed files with 28 additions and 6 deletions

View File

@@ -63,6 +63,10 @@
#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;
}