aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2016-06-13 15:55:49 +0100
committerMichael Brown <mcb30@ipxe.org>2016-06-13 15:55:49 +0100
commitfce6117ad983a9c53087860058769dc65fb09d73 (patch)
tree0d277f84c67acd3055656b4fec326fdf7d342daf /src/include
parente6111c151794c4c15a0988e259666ef5be24ffcc (diff)
downloadipxe-fce6117ad983a9c53087860058769dc65fb09d73.zip
ipxe-fce6117ad983a9c53087860058769dc65fb09d73.tar.gz
ipxe-fce6117ad983a9c53087860058769dc65fb09d73.tar.bz2
[ntp] Add simple NTP client
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/ipxe/errfile.h1
-rw-r--r--src/include/ipxe/ntp.h109
2 files changed, 110 insertions, 0 deletions
diff --git a/src/include/ipxe/errfile.h b/src/include/ipxe/errfile.h
index 4dae35b..cbab452 100644
--- a/src/include/ipxe/errfile.h
+++ b/src/include/ipxe/errfile.h
@@ -265,6 +265,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ERRFILE_peerblk ( ERRFILE_NET | 0x00460000 )
#define ERRFILE_peermux ( ERRFILE_NET | 0x00470000 )
#define ERRFILE_xsigo ( ERRFILE_NET | 0x00480000 )
+#define ERRFILE_ntp ( ERRFILE_NET | 0x00490000 )
#define ERRFILE_image ( ERRFILE_IMAGE | 0x00000000 )
#define ERRFILE_elf ( ERRFILE_IMAGE | 0x00010000 )
diff --git a/src/include/ipxe/ntp.h b/src/include/ipxe/ntp.h
new file mode 100644
index 0000000..f5b3d23
--- /dev/null
+++ b/src/include/ipxe/ntp.h
@@ -0,0 +1,109 @@
+#ifndef _IPXE_NTP_H
+#define _IPXE_NTP_H
+
+/** @file
+ *
+ * Network Time Protocol
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/in.h>
+#include <ipxe/interface.h>
+
+/** NTP port */
+#define NTP_PORT 123
+
+/** An NTP short-format timestamp */
+struct ntp_short {
+ /** Seconds */
+ uint16_t seconds;
+ /** Fraction of a second */
+ uint16_t fraction;
+} __attribute__ (( packed ));
+
+/** An NTP timestamp */
+struct ntp_timestamp {
+ /** Seconds */
+ uint32_t seconds;
+ /** Fraction of a second */
+ uint32_t fraction;
+} __attribute__ (( packed ));
+
+/** An NTP reference identifier */
+union ntp_id {
+ /** Textual identifier */
+ char text[4];
+ /** IPv4 address */
+ struct in_addr in;
+ /** Opaque integer */
+ uint32_t opaque;
+};
+
+/** An NTP header */
+struct ntp_header {
+ /** Flags */
+ uint8_t flags;
+ /** Stratum */
+ uint8_t stratum;
+ /** Polling rate */
+ int8_t poll;
+ /** Precision */
+ int8_t precision;
+ /** Root delay */
+ struct ntp_short delay;
+ /** Root dispersion */
+ struct ntp_short dispersion;
+ /** Reference clock identifier */
+ union ntp_id id;
+ /** Reference timestamp */
+ struct ntp_timestamp reference;
+ /** Originate timestamp */
+ struct ntp_timestamp originate;
+ /** Receive timestamp */
+ struct ntp_timestamp receive;
+ /** Transmit timestamp */
+ struct ntp_timestamp transmit;
+} __attribute__ (( packed ));
+
+/** Leap second indicator: unknown */
+#define NTP_FL_LI_UNKNOWN 0xc0
+
+/** NTP version: 1 */
+#define NTP_FL_VN_1 0x20
+
+/** NTP mode: client */
+#define NTP_FL_MODE_CLIENT 0x03
+
+/** NTP mode: server */
+#define NTP_FL_MODE_SERVER 0x04
+
+/** NTP mode mask */
+#define NTP_FL_MODE_MASK 0x07
+
+/** NTP timestamp for start of Unix epoch */
+#define NTP_EPOCH 2208988800UL
+
+/** NTP fraction of a second magic value
+ *
+ * This is a policy decision.
+ */
+#define NTP_FRACTION_MAGIC 0x69505845UL
+
+/** NTP minimum retransmission timeout
+ *
+ * This is a policy decision.
+ */
+#define NTP_MIN_TIMEOUT ( 1 * TICKS_PER_SEC )
+
+/** NTP maximum retransmission timeout
+ *
+ * This is a policy decision.
+ */
+#define NTP_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
+
+extern int start_ntp ( struct interface *job, const char *hostname );
+
+#endif /* _IPXE_NTP_H */