You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

snfLOGmgr.inline.hpp 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // snfLOGmgr.inline.hpp
  2. //
  3. // (C) Copyright 2006 - 2009 ARM Research Labs, LLC.
  4. // Inline methods for the snfLOGmgr
  5. //// snfScanData ///////////////////////////////////////////////////////////////
  6. inline int snfScanData::IPScanCount() { // Return the number of IPs.
  7. return MyIPCount;
  8. }
  9. inline IPScanRecord& snfScanData::newIPScanRecord() { // Get the next free IP scan record.
  10. if(MaxIPsPerMessage <= MyIPCount) { // Check that we have more records.
  11. throw NoFreeIPScanRecords(); // If we do not then throw!
  12. } // If we do have more records then
  13. IPScanRecord& NewRecord = MyIPScanData[MyIPCount]; // Pick the next available one,
  14. NewRecord.Ordinal = MyIPCount; // set the ordinal value,
  15. ++MyIPCount; // increase our count, and
  16. return NewRecord; // return the one we picked.
  17. }
  18. inline IPScanRecord& snfScanData::IPScanData(int i) { // Return the IP scan record i.
  19. if(MyIPCount <= i || 0 > i) { // First check that i is in bounds.
  20. throw OutOfBounds(); // if it is not then throw!
  21. } // If the record for [i] is available
  22. return MyIPScanData[i]; // return it.
  23. }
  24. inline void snfScanData::drillPastOrdinal(int O) { // Sets Drill Down flag for IP record O.
  25. if(0 <= O && O < MaxIPsPerMessage) { // If O is a useable Received ordinal
  26. DrillDownFlags[O] = true; // then set the Drill Down Flag for O.
  27. }
  28. }
  29. inline bool snfScanData::isDrillDownSource(IPScanRecord& X) { // True if we drill through this source.
  30. if(
  31. (0UL != myCallerForcedSourceIP) || // If the source IP has been forced by
  32. (0UL != myHeaderDirectiveSourceIP) // the caller or by a header directive
  33. ) return false; // then drilldowns are disabled.
  34. // Otherwise check for a drilldown flag.
  35. return DrillDownFlags[X.Ordinal]; // Presuming X is valid, return the flag.
  36. } // If X is not valid we may blow up!
  37. inline IPScanRecord& snfScanData::SourceIPRecord(IPScanRecord& X) { // Sets the source IP record.
  38. SourceIPOrdinal = X.Ordinal; // Here's the ordinal.
  39. SourceIPFoundFlag = true; // Here's the truth flag.
  40. return X; // Return what was set.
  41. }
  42. inline IPScanRecord& snfScanData::SourceIPRecord() { // Gets the source IP record.
  43. return IPScanData(SourceIPOrdinal); // Return the IP record, or throw
  44. } // OutOfBounds.
  45. inline bool snfScanData::FoundSourceIP() { // True if the source IP record was set.
  46. return SourceIPFoundFlag; // Return what the flag says.
  47. }
  48. inline snfIPRange snfScanData::SourceIPRange(snfIPRange R) { // Establish the IP range.
  49. return (SourceIPRangeFlag = R); // set and return the value w/ R.
  50. }
  51. inline snfIPRange snfScanData::SourceIPRange() { // Gets the source IP detection range.
  52. return SourceIPRangeFlag; // Return what the flag says.
  53. }
  54. inline CodeDweller::IP4Address
  55. snfScanData::HeaderDirectiveSourceIP(CodeDweller::IP4Address A) { // set Header directive source IP.
  56. if(0UL == myHeaderDirectiveSourceIP) myHeaderDirectiveSourceIP = A; // If this value is not set, set it.
  57. return myHeaderDirectiveSourceIP; // Return the value.
  58. }
  59. inline CodeDweller::IP4Address snfScanData::HeaderDirectiveSourceIP() { // get Header directive source IP.
  60. return myHeaderDirectiveSourceIP; // Return the current value.
  61. }
  62. inline CodeDweller::IP4Address
  63. snfScanData::CallerForcedSourceIP(CodeDweller::IP4Address A) { // set Caller forced source IP.
  64. if(0UL == myCallerForcedSourceIP) myCallerForcedSourceIP = A; // If this value is not set, set it.
  65. return myCallerForcedSourceIP; // Return the value.
  66. }
  67. inline CodeDweller::IP4Address snfScanData::CallerForcedSourceIP() { // get Caller forced source IP.
  68. return myCallerForcedSourceIP; // Return the current value.
  69. }
  70. //// snfLOGmgr /////////////////////////////////////////////////////////////////
  71. inline void snfLOGmgr::updateActiveUTC(std::string ActiveUTC) { // Update Active Rulebase UTC.
  72. CodeDweller::ScopeMutex Freeze(MyMutex); // Protect the strings.
  73. ActiveRulebaseUTC = ActiveUTC; // Update the active timestamp.
  74. NewerRulebaseIsAvailable = false; // Update availability is now unknown.
  75. }
  76. inline void snfLOGmgr::updateAvailableUTC(std::string& AvailableRulebaseTimestamp) {// Changes update avialability stamp.
  77. CodeDweller::ScopeMutex Freeze(MyMutex); // Protect the strings.
  78. AvailableRulebaseUTC = AvailableRulebaseTimestamp; // Store the new timestamp.
  79. if(0 < AvailableRulebaseUTC.compare(ActiveRulebaseUTC)) { // If the available timestamp is newer
  80. NewerRulebaseIsAvailable = true; // than the active then set the flag.
  81. } else { // If it is not newer then
  82. NewerRulebaseIsAvailable = false; // reset the flag.
  83. }
  84. }
  85. inline std::string snfLOGmgr::ActiveRulebaseTimestamp() { // Get active rulebase timestamp.
  86. CodeDweller::ScopeMutex Freeze(MyMutex); // Protect the string.
  87. return ActiveRulebaseUTC; // Return it.
  88. }
  89. inline std::string snfLOGmgr::AvailableRulebaseTimestamp() { // Get available rulebase timestamp.
  90. CodeDweller::ScopeMutex Freeze(MyMutex); // Protect the strings.
  91. return AvailableRulebaseUTC; // Return the available timestamp.
  92. }
  93. inline bool snfLOGmgr::isUpdateAvailable() { // True if update is available.
  94. return NewerRulebaseIsAvailable; // Return the flag's value.
  95. }
  96. inline int snfLOGmgr::LatestRuleID() { // Query the latest rule id.
  97. return Status.LatestRuleID; // This simple value is atomic
  98. } // so we can read it without the mutex.
  99. inline int snfLOGmgr::RunningTime() { // Get the time we've been alive.
  100. return (int) difftime(Timestamp(), StartupTime);
  101. }