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