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.

ntp.h 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef _IPXE_NTP_H
  2. #define _IPXE_NTP_H
  3. /** @file
  4. *
  5. * Network Time Protocol
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/in.h>
  11. #include <ipxe/interface.h>
  12. /** NTP port */
  13. #define NTP_PORT 123
  14. /** An NTP short-format timestamp */
  15. struct ntp_short {
  16. /** Seconds */
  17. uint16_t seconds;
  18. /** Fraction of a second */
  19. uint16_t fraction;
  20. } __attribute__ (( packed ));
  21. /** An NTP timestamp */
  22. struct ntp_timestamp {
  23. /** Seconds */
  24. uint32_t seconds;
  25. /** Fraction of a second */
  26. uint32_t fraction;
  27. } __attribute__ (( packed ));
  28. /** An NTP reference identifier */
  29. union ntp_id {
  30. /** Textual identifier */
  31. char text[4];
  32. /** IPv4 address */
  33. struct in_addr in;
  34. /** Opaque integer */
  35. uint32_t opaque;
  36. };
  37. /** An NTP header */
  38. struct ntp_header {
  39. /** Flags */
  40. uint8_t flags;
  41. /** Stratum */
  42. uint8_t stratum;
  43. /** Polling rate */
  44. int8_t poll;
  45. /** Precision */
  46. int8_t precision;
  47. /** Root delay */
  48. struct ntp_short delay;
  49. /** Root dispersion */
  50. struct ntp_short dispersion;
  51. /** Reference clock identifier */
  52. union ntp_id id;
  53. /** Reference timestamp */
  54. struct ntp_timestamp reference;
  55. /** Originate timestamp */
  56. struct ntp_timestamp originate;
  57. /** Receive timestamp */
  58. struct ntp_timestamp receive;
  59. /** Transmit timestamp */
  60. struct ntp_timestamp transmit;
  61. } __attribute__ (( packed ));
  62. /** Leap second indicator: unknown */
  63. #define NTP_FL_LI_UNKNOWN 0xc0
  64. /** NTP version: 1 */
  65. #define NTP_FL_VN_1 0x20
  66. /** NTP mode: client */
  67. #define NTP_FL_MODE_CLIENT 0x03
  68. /** NTP mode: server */
  69. #define NTP_FL_MODE_SERVER 0x04
  70. /** NTP mode mask */
  71. #define NTP_FL_MODE_MASK 0x07
  72. /** NTP timestamp for start of Unix epoch */
  73. #define NTP_EPOCH 2208988800UL
  74. /** NTP fraction of a second magic value
  75. *
  76. * This is a policy decision.
  77. */
  78. #define NTP_FRACTION_MAGIC 0x69505845UL
  79. /** NTP minimum retransmission timeout
  80. *
  81. * This is a policy decision.
  82. */
  83. #define NTP_MIN_TIMEOUT ( 1 * TICKS_PER_SEC )
  84. /** NTP maximum retransmission timeout
  85. *
  86. * This is a policy decision.
  87. */
  88. #define NTP_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
  89. extern int start_ntp ( struct interface *job, const char *hostname );
  90. #endif /* _IPXE_NTP_H */