[Netlinx-modules-commit] NetLinx-Modules/TimeSync TimeSyncMod.axi,1.2,1.3 TimeSyncMod.axs,1.3,1.4
Brought to you by:
coffler
|
From: Jeff C. <co...@us...> - 2006-02-16 20:34:59
|
Update of /cvsroot/netlinx-modules/NetLinx-Modules/TimeSync In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11169/TimeSync Modified Files: TimeSyncMod.axi TimeSyncMod.axs Log Message: Fixed problem with TimeSync allowing update to any time at all via NTP. This was a problem because corrupted packets (due to UDP) may cause the NetLinx master to get seriously off kilter. The change is now bounded by 1.5 hours by default; this can be changed if needed via a trivial source code edit. Index: TimeSyncMod.axs =================================================================== RCS file: /cvsroot/netlinx-modules/NetLinx-Modules/TimeSync/TimeSyncMod.axs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TimeSyncMod.axs 16 Sep 2003 16:58:24 -0000 1.3 --- TimeSyncMod.axs 16 Feb 2006 20:34:48 -0000 1.4 *************** *** 45,52 **** (* FILE CREATED ON: 02/05/2001 AT: 08:03:38 *) (***********************************************************) ! (* FILE_LAST_MODIFIED_ON: 04/05/2003 AT: 06:58:30 *) (***********************************************************) (* ORPHAN_FILE_PLATFORM: 1 *) (***********************************************************) (*!!FILE REVISION: Rev 5 *) (* REVISION DATE: 01/26/2003 *) --- 45,67 ---- (* FILE CREATED ON: 02/05/2001 AT: 08:03:38 *) (***********************************************************) ! (* FILE_LAST_MODIFIED_ON: 02/16/2006 AT: 12:28:57 *) (***********************************************************) (* ORPHAN_FILE_PLATFORM: 1 *) (***********************************************************) + (*!!FILE REVISION: Rev 6 *) + (* REVISION DATE: 02/16/2006 *) + (* *) + (* COMMENTS: *) + (* . Time change wasn't validated on NTP broadcast or *) + (* NTP queries, allowing corrupted packets to mess up *) + (* the time. Fixed to validate the time (adjusted if *) + (* time difference <= 1.5 hours). *) + (* . Syncing via time server (RFC868) failed if the *) + (* time was off for a few seconds at midnight. This *) + (* only worked if the dates were equal. Changed this *) + (* to look at seconds change, and allow the change if *) + (* the time <= 1.5 hours apart. *) + (* *) + (***********************************************************) (*!!FILE REVISION: Rev 5 *) (* REVISION DATE: 01/26/2003 *) *************** *** 493,496 **** --- 508,522 ---- } + Define_Function long GregorianToSdnByYear(char mmddyyyy[10]) + { + long myYYYY, myMM, myDD; + + myYYYY = Type_Cast(Date_To_Year(mmddyyyy)); + myMM = Type_Cast(Date_To_Month(mmddyyyy)); + myDD = Type_Cast(Date_To_Day(mmddyyyy)); + + return GregorianToSdn(myYYYY, myMM, myDD); + } + Define_Function SdnToGregorian(long sdn, long yy, long mm, long dd) // Due to compiler issues with TYPE_CAST and SLONG's, this routine *************** *** 621,624 **** --- 647,688 ---- } + Define_Function char Validate_Time_Change(char remoteDate[], remoteTime[]) + { + long curSdn, remoteSdn, baseSdn; + slong curSeconds, remoteSeconds; + long secondsDiff; + char curTime[8]; + + // Figure out the Sdn value for both current and remote dates + + curSdn = GregorianToSdnByYear(LDATE); + curTime = TIME; + + remoteSdn = GregorianToSdnByYear(remoteDate); + + // Normalize by the smaller of curSdn and remoteSdn ... + // The intent here is to figure out the difference in seconds + // + // If the curSdn and remoteSdn aren't even close (2 days), just fail + + baseSdn = min_value(curSdn, remoteSdn); + curSdn = curSdn - baseSdn; + remoteSdn = remoteSdn - baseSdn; + + if (abs_value(curSdn-remoteSdn) > 2) + return FALSE; + + // Determine the number of seconds difference + + curSeconds = Type_Cast(curSdn * 86400) + SecondsSinceMidnight(curTime); + remoteSeconds = Type_Cast(remoteSdn * 86400) + SecondsSinceMidnight(remoteTime); + + // If our time differece is under 1.5 hours, consider this a "good" time + if (abs_value(curSeconds - remoteSeconds) <= 5400) + return TRUE; + + return FALSE; + } + Define_Function Process_Time_Notification(char data[]) { *************** *** 640,644 **** Convert_RFC2030_To_Time(data, rSecSince1900, res.remoteDate, res.remoteTime); if (rSecSince1900 <> 0) ! dateGood = 1; } --- 704,708 ---- Convert_RFC2030_To_Time(data, rSecSince1900, res.remoteDate, res.remoteTime); if (rSecSince1900 <> 0) ! dateGood = Validate_Time_Change(res.remoteDate, res.remoteTime); } *************** *** 650,666 **** Convert_RFC868_To_Time(data, rSecSince1900, res.remoteDate, res.remoteTime); ! ! // Only allow updates if remote time and local time match: ! // a. Same day ! // b. No more than 1.5 hours apart (5400 seconds) ! // This avoids update if remote time is way off base ... ! ! IF (LDATE == res.remoteDate) { ! SLONG timeDiff; ! timeDiff = abs_value(SecondsSinceMidnight(TIME) - SecondsSinceMidnight(res.remoteTime)); ! IF (timeDiff <= 5400) { ! dateGood = 1; ! } ! } } --- 714,718 ---- Convert_RFC868_To_Time(data, rSecSince1900, res.remoteDate, res.remoteTime); ! dateGood = Validate_Time_Change(res.remoteDate, res.remoteTime); } Index: TimeSyncMod.axi =================================================================== RCS file: /cvsroot/netlinx-modules/NetLinx-Modules/TimeSync/TimeSyncMod.axi,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TimeSyncMod.axi 16 Sep 2003 16:58:24 -0000 1.2 --- TimeSyncMod.axi 16 Feb 2006 20:34:48 -0000 1.3 *************** *** 5,9 **** (* FILE CREATED ON: 01/26/2003 AT: 07:00:00 *) (***********************************************************) ! (* FILE_LAST_MODIFIED_ON: 04/05/2003 AT: 06:57:39 *) (***********************************************************) (* ORPHAN_FILE_PLATFORM: 1 *) --- 5,9 ---- (* FILE CREATED ON: 01/26/2003 AT: 07:00:00 *) (***********************************************************) ! (* FILE_LAST_MODIFIED_ON: 02/16/2006 AT: 09:49:14 *) (***********************************************************) (* ORPHAN_FILE_PLATFORM: 1 *) *************** *** 88,95 **** structure _sTimeSync_Feedback { ! char remoteDate[10]; // Date as reported by remote system ! char remoteTime[8]; // Time as reported by remote system ! char diffTime[32]; // Difference from above and NetLinx time ! long diffSeconds; // Above time represented in seconds } --- 88,95 ---- structure _sTimeSync_Feedback { ! char remoteDate[10]; // Date as reported by remote system ! char remoteTime[8]; // Time as reported by remote system ! char diffTime[32]; // Difference from above and NetLinx time ! long diffSeconds; // Above time represented in seconds } |