| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sparse-endian.h" |
| 5 |
#include "timesyncd-forward.h" |
| 6 |
|
| 7 |
/* NTP protocol, packet header */ |
| 8 |
#define NTP_LEAP_PLUSSEC 1 |
| 9 |
#define NTP_LEAP_MINUSSEC 2 |
| 10 |
#define NTP_LEAP_NOTINSYNC 3 |
| 11 |
#define NTP_MODE_CLIENT 3 |
| 12 |
#define NTP_MODE_SERVER 4 |
| 13 |
#define NTP_FIELD_LEAP(f) (((f) >> 6) & 3) |
| 14 |
#define NTP_FIELD_VERSION(f) (((f) >> 3) & 7) |
| 15 |
#define NTP_FIELD_MODE(f) ((f) & 7) |
| 16 |
#define NTP_FIELD(l, v, m) (((l) << 6) | ((v) << 3) | (m)) |
| 17 |
|
| 18 |
/* |
| 19 |
* "NTP timestamps are represented as a 64-bit unsigned fixed-point number, |
| 20 |
* in seconds relative to 0h on 1 January 1900." |
| 21 |
*/ |
| 22 |
#define OFFSET_1900_1970 UINT64_C(2208988800) |
| 23 |
|
| 24 |
struct ntp_ts { |
| 25 |
be32_t sec; |
| 26 |
be32_t frac; |
| 27 |
} _packed_; |
| 28 |
|
| 29 |
struct ntp_ts_short { |
| 30 |
be16_t sec; |
| 31 |
be16_t frac; |
| 32 |
} _packed_; |
| 33 |
|
| 34 |
struct ntp_msg { |
| 35 |
uint8_t field; |
| 36 |
uint8_t stratum; |
| 37 |
int8_t poll; |
| 38 |
int8_t precision; |
| 39 |
struct ntp_ts_short root_delay; |
| 40 |
struct ntp_ts_short root_dispersion; |
| 41 |
char refid[4]; |
| 42 |
struct ntp_ts reference_time; |
| 43 |
struct ntp_ts origin_time; |
| 44 |
struct ntp_ts recv_time; |
| 45 |
struct ntp_ts trans_time; |
| 46 |
} _packed_; |