From: Dave Hart Date: Wed, 3 May 2023 21:16:16 +0000 (+0000) Subject: [Bug 3814] First poll delay of new or cleared associations miscalculated. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e23233ea02e89d05e40bbe705f399b8174e67a75;p=thirdparty%2Fntp.git [Bug 3814] First poll delay of new or cleared associations miscalculated. Switch NONEMPTY_TRANSLATION_UNIT extern reference from exit() to abs() to avoid warning on VS 2022 due to mismatching declaration as exit() is now noreturn. Minimum supported Visual Studio has been 2005, remove code for earlier. bk: 6452cf209PBAzQTFiZwD6XKLzpAdbQ --- diff --git a/ChangeLog b/ChangeLog index 23c6a6c95..5ce1c0ad7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ --- +* [Bug 3814] First poll delay of new or cleared associations miscalculated. + * [Bug 3802] ntp-keygen -I default identity modulus bits too small for OpenSSL 3. Reported by rmsh1216@163.com * [Bug 3801] gpsdjson refclock gps_open() device name mishandled. diff --git a/include/ntp_types.h b/include/ntp_types.h index 969b325b5..abf5226b8 100644 --- a/include/ntp_types.h +++ b/include/ntp_types.h @@ -258,10 +258,11 @@ aligned_ptr( * Macro to use in otherwise-empty source files to comply with ANSI C * requirement that each translation unit (source file) contain some * declaration. This has commonly been done by declaring an unused - * global variable of type int or char. An extern reference to exit() - * serves the same purpose without bloat. + * global variable of type int or char. An extern reference to abs() + * serves the same purpose without bloat. We once used exit() but + * that can produce warnings on systems that declare exit() noreturn. */ -#define NONEMPTY_TRANSLATION_UNIT extern void exit(int); +#define NONEMPTY_TRANSLATION_UNIT extern int abs(int); /* * On Unix struct sock_timeval is equivalent to struct timeval. diff --git a/libntp/mktime.c b/libntp/mktime.c index 50d2a0810..74ae85431 100644 --- a/libntp/mktime.c +++ b/libntp/mktime.c @@ -60,7 +60,7 @@ */ #include -#include "ntp_machine.h" +#include "ntp_types.h" #if !defined(HAVE_MKTIME) || ( !defined(HAVE_TIMEGM) && defined(WANT_TIMEGM) ) @@ -259,7 +259,7 @@ time2( return t; } #else -int mktime_bs; +NONEMPTY_TRANSLATION_UNIT #endif /* !HAVE_MKTIME || !HAVE_TIMEGM */ #ifndef HAVE_MKTIME diff --git a/libntp/systime.c b/libntp/systime.c index e2f07f71a..76fba7fe1 100644 --- a/libntp/systime.c +++ b/libntp/systime.c @@ -591,6 +591,8 @@ step_systime( return TRUE; } + +#if SIZEOF_TIME_T > 4 static const char * tv_fmt_libbuf( const struct timeval * ptv @@ -612,6 +614,7 @@ tv_fmt_libbuf( (u_int)ptv->tv_usec); return retv; } +#endif /* SIZEOF_TIME_T > 4 */ int /*BOOL*/ diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 7de94c421..18638605a 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -3228,19 +3228,19 @@ peer_clear( /* * During initialization use the association count to spread out - * the polls at one-second intervals. Passive associations' - * first poll is delayed by the "discard minimum" to avoid rate - * limiting. Other post-startup new or cleared associations + * the polls at one-second intervals. Unconfigured associations' + * first poll is delayed by the "discard minimum" plus 1 to avoid + * rate limiting. Other post-startup new or cleared associations * randomize the first poll over the minimum poll interval to * avoid implosion. */ peer->nextdate = peer->update = peer->outdate = current_time; if (initializing) { peer->nextdate += peer_associations; - } else if (MODE_PASSIVE == peer->hmode) { - peer->nextdate += ntp_minpkt; + } else if (!(FLAG_CONFIG & peer->flags)) { + peer->nextdate += ntp_minpkt + 1; } else { - peer->nextdate += ntp_random() % peer->minpoll; + peer->nextdate += ntp_random() % (1 << peer->minpoll); } #ifdef AUTOKEY peer->refresh = current_time + (1 << NTP_REFRESH); diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index 4439b1cdd..6e119da80 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -75,7 +75,7 @@ /* Prevent inclusion of winsock.h in windows.h */ #ifndef _WINSOCKAPI_ -#define _WINSOCKAPI_ +#define _WINSOCKAPI_ #endif #ifndef __RPCASYNC_H__ @@ -213,15 +213,7 @@ typedef int socklen_t; #define SO_EXCLUSIVEADDRUSE ((int)(~SO_REUSEADDR)) #endif -#if defined _MSC_VER && _MSC_VER < 1400 -/* - * Use 32-bit time definitions for versions prior to VS 2005 - * VS 2005 defaults to 64-bit time - */ -# define SIZEOF_TIME_T 4 -#else -# define SIZEOF_TIME_T 8 -#endif +#define SIZEOF_TIME_T 8 /* diff --git a/ports/winnt/ntptrace/ntptrace.dsp b/ports/winnt/ntptrace/ntptrace.dsp deleted file mode 100644 index ed8616a37..000000000 --- a/ports/winnt/ntptrace/ntptrace.dsp +++ /dev/null @@ -1,153 +0,0 @@ -# Microsoft Developer Studio Project File - Name="ntptrace" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=ntptrace - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "ntptrace.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "ntptrace.mak" CFG="ntptrace - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "ntptrace - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "ntptrace - Win32 Debug" (based on "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName ""$/ntp/dev/ports/winnt/ntptrace", AXBAAAAA" -# PROP Scc_LocalPath "." -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "ntptrace - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W4 /GX /O2 /I "\\" /I "$(OPENSSL)\inc32" /I "." /I "..\include" /I "..\..\..\include" /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /D "__STDC__" /D "SYS_WINNT" /D "HAVE_CONFIG_H" /D _WIN32_WINNT=0x400 /YX"windows.h" /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib /nologo /subsystem:console /machine:I386 - -!ELSEIF "$(CFG)" == "ntptrace - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "." /I "..\include" /I "..\..\..\include" /I "$(OPENSSL)\inc32" /D "_DEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /D "__STDC__" /D "SYS_WINNT" /D "HAVE_CONFIG_H" /D _WIN32_WINNT=0x400 /FR /YX"windows.h" /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/Debug/ntptrace.exe" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "ntptrace - Win32 Release" -# Name "ntptrace - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\..\..\ntptrace\ntptrace.c -# End Source File -# Begin Source File - -SOURCE=..\libntp\util_clockstuff.c -# End Source File -# Begin Source File - -SOURCE=.\version.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=..\include\sys\ioctl.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\ntptrace\ntptrace.h -# End Source File -# Begin Source File - -SOURCE=..\include\sys\resource.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# Begin Source File - -SOURCE=..\..\..\configure - -!IF "$(CFG)" == "ntptrace - Win32 Release" - -# Begin Custom Build -ProjDir=. -InputPath=..\..\..\configure - -"$(ProjDir)\version.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - echo Using NT Shell Script to generate version.c - ..\scripts\mkver.bat -P ntptrace - -# End Custom Build - -!ELSEIF "$(CFG)" == "ntptrace - Win32 Debug" - -# Begin Custom Build -ProjDir=. -InputPath=..\..\..\configure - -"$(ProjDir)\version.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - echo Using NT Shell Script to generate version.c - ..\scripts\mkver.bat -P ntptrace - -# End Custom Build - -!ENDIF - -# End Source File -# End Target -# End Project