lcd_time.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * lcd_time.h
  3. */
  4. #ifndef _LCD_TIME_H
  5. #define _LCD_TIME_H
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /*
  10. * undefine to enable time synchronization only on authenticated packets
  11. */
  12. #define LCD_TIME_SYNC_OPT 1
  13. /*
  14. * Macros and definitions.
  15. */
  16. #define ETIMELIST_SIZE 23
  17. typedef struct enginetime_struct {
  18. u_char *engineID;
  19. u_int engineID_len;
  20. u_int engineTime;
  21. u_int engineBoot;
  22. /*
  23. * Time & boots values received from last authenticated
  24. * * message within the previous time window.
  25. */
  26. time_t lastReceivedEngineTime;
  27. /*
  28. * Timestamp made when engineTime/engineBoots was last
  29. * * updated. Measured in seconds.
  30. */
  31. #ifdef LCD_TIME_SYNC_OPT
  32. u_int authenticatedFlag;
  33. #endif
  34. struct enginetime_struct *next;
  35. } enginetime , *Enginetime;
  36. /*
  37. * Macros for streamlined engineID existence checks --
  38. *
  39. * e is char *engineID,
  40. * e_l is u_int engineID_len.
  41. *
  42. *
  43. * ISENGINEKNOWN(e, e_l)
  44. * Returns:
  45. * TRUE If engineID is recoreded in the EngineID List;
  46. * FALSE Otherwise.
  47. *
  48. * ENSURE_ENGINE_RECORD(e, e_l)
  49. * Adds the given engineID to the EngineID List if it does not exist
  50. * already. engineID is added with a <enginetime, engineboots>
  51. * tuple of <0,0>. ALWAYS succeeds -- except in case of a
  52. * fatal internal error.
  53. * Returns:
  54. * SNMPERR_SUCCESS On success;
  55. * SNMPERR_GENERR Otherwise.
  56. *
  57. * MAKENEW_ENGINE_RECORD(e, e_l)
  58. * Returns:
  59. * SNMPERR_SUCCESS If engineID already exists in the EngineID List;
  60. * SNMPERR_GENERR Otherwise -and- invokes ENSURE_ENGINE_RECORD()
  61. * to add an entry to the EngineID List.
  62. *
  63. * XXX Requres the following declaration in modules calling ISENGINEKNOWN():
  64. * static u_int dummy_etime, dummy_eboot;
  65. */
  66. #define ISENGINEKNOWN(e, e_l) \
  67. ( (get_enginetime(e, e_l, \
  68. &dummy_eboot, &dummy_etime, TRUE) == SNMPERR_SUCCESS) \
  69. ? TRUE \
  70. : FALSE )
  71. #define ENSURE_ENGINE_RECORD(e, e_l) \
  72. ( (set_enginetime(e, e_l, 0, 0, FALSE) == SNMPERR_SUCCESS) \
  73. ? SNMPERR_SUCCESS \
  74. : SNMPERR_GENERR )
  75. #define MAKENEW_ENGINE_RECORD(e, e_l) \
  76. ( (ISENGINEKNOWN(e, e_l) == TRUE) \
  77. ? SNMPERR_SUCCESS \
  78. : (ENSURE_ENGINE_RECORD(e, e_l), SNMPERR_GENERR) )
  79. /*
  80. * Prototypes.
  81. */
  82. int get_enginetime(const u_char * engineID, u_int engineID_len,
  83. u_int * engine_boot,
  84. u_int * engine_time,
  85. u_int authenticated);
  86. int get_enginetime_ex(u_char * engineID,
  87. u_int engineID_len,
  88. u_int * engine_boot,
  89. u_int * engine_time,
  90. u_int * last_engine_time,
  91. u_int authenticated);
  92. NETSNMP_IMPORT
  93. int set_enginetime(const u_char * engineID, u_int engineID_len,
  94. u_int engine_boot, u_int engine_time,
  95. u_int authenticated);
  96. Enginetime
  97. search_enginetime_list(const u_char * engineID, u_int engineID_len);
  98. int hash_engineID(const u_char * engineID, u_int engineID_len);
  99. void dump_etimelist_entry(Enginetime e, int count);
  100. void dump_etimelist(void);
  101. void free_etimelist(void);
  102. void free_enginetime(unsigned char *engineID, size_t engineID_len);
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif /* _LCD_TIME_H */