iPXE
ntp.h
Go to the documentation of this file.
00001 #ifndef _IPXE_NTP_H
00002 #define _IPXE_NTP_H
00003 
00004 /** @file
00005  *
00006  * Network Time Protocol
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <ipxe/in.h>
00014 #include <ipxe/interface.h>
00015 
00016 /** NTP port */
00017 #define NTP_PORT 123
00018 
00019 /** An NTP short-format timestamp */
00020 struct ntp_short {
00021         /** Seconds */
00022         uint16_t seconds;
00023         /** Fraction of a second */
00024         uint16_t fraction;
00025 } __attribute__ (( packed ));
00026 
00027 /** An NTP timestamp */
00028 struct ntp_timestamp {
00029         /** Seconds */
00030         uint32_t seconds;
00031         /** Fraction of a second */
00032         uint32_t fraction;
00033 } __attribute__ (( packed ));
00034 
00035 /** An NTP reference identifier */
00036 union ntp_id {
00037         /** Textual identifier */
00038         char text[4];
00039         /** IPv4 address */
00040         struct in_addr in;
00041         /** Opaque integer */
00042         uint32_t opaque;
00043 };
00044 
00045 /** An NTP header */
00046 struct ntp_header {
00047         /** Flags */
00048         uint8_t flags;
00049         /** Stratum */
00050         uint8_t stratum;
00051         /** Polling rate */
00052         int8_t poll;
00053         /** Precision */
00054         int8_t precision;
00055         /** Root delay */
00056         struct ntp_short delay;
00057         /** Root dispersion */
00058         struct ntp_short dispersion;
00059         /** Reference clock identifier */
00060         union ntp_id id;
00061         /** Reference timestamp */
00062         struct ntp_timestamp reference;
00063         /** Originate timestamp */
00064         struct ntp_timestamp originate;
00065         /** Receive timestamp */
00066         struct ntp_timestamp receive;
00067         /** Transmit timestamp */
00068         struct ntp_timestamp transmit;
00069 } __attribute__ (( packed ));
00070 
00071 /** Leap second indicator: unknown */
00072 #define NTP_FL_LI_UNKNOWN 0xc0
00073 
00074 /** NTP version: 1 */
00075 #define NTP_FL_VN_1 0x20
00076 
00077 /** NTP mode: client */
00078 #define NTP_FL_MODE_CLIENT 0x03
00079 
00080 /** NTP mode: server */
00081 #define NTP_FL_MODE_SERVER 0x04
00082 
00083 /** NTP mode mask */
00084 #define NTP_FL_MODE_MASK 0x07
00085 
00086 /** NTP timestamp for start of Unix epoch */
00087 #define NTP_EPOCH 2208988800UL
00088 
00089 /** NTP fraction of a second magic value
00090  *
00091  * This is a policy decision.
00092  */
00093 #define NTP_FRACTION_MAGIC 0x69505845UL
00094 
00095 /** NTP minimum retransmission timeout
00096  *
00097  * This is a policy decision.
00098  */
00099 #define NTP_MIN_TIMEOUT ( 1 * TICKS_PER_SEC )
00100 
00101 /** NTP maximum retransmission timeout
00102  *
00103  * This is a policy decision.
00104  */
00105 #define NTP_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
00106 
00107 extern int start_ntp ( struct interface *job, const char *hostname );
00108 
00109 #endif /* _IPXE_NTP_H */