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