#define REQ_ADDSRC_NTS 0x200
#define REQ_ADDSRC_COPY 0x400
#define REQ_ADDSRC_EF_EXP_MONO_ROOT 0x800
-#define REQ_ADDSRC_EF_EXP_NET_CORRECTION 0x1000
+#define REQ_ADDSRC_EF_NET_CORRECTION 0x1000
#define REQ_ADDSRC_IPV4 0x2000
#define REQ_ADDSRC_IPV6 0x4000
(data.params.burst ? REQ_ADDSRC_BURST : 0) |
(data.params.nts ? REQ_ADDSRC_NTS : 0) |
(data.params.copy ? REQ_ADDSRC_COPY : 0) |
+ (data.params.ext_fields & NTP_EF_FLAG_NET_CORRECTION ?
+ REQ_ADDSRC_EF_NET_CORRECTION : 0) |
(data.params.ext_fields & NTP_EF_FLAG_EXP_MONO_ROOT ?
REQ_ADDSRC_EF_EXP_MONO_ROOT : 0) |
- (data.params.ext_fields & NTP_EF_FLAG_EXP_NET_CORRECTION ?
- REQ_ADDSRC_EF_EXP_NET_CORRECTION : 0) |
(data.family == IPADDR_INET4 ? REQ_ADDSRC_IPV4 : 0) |
(data.family == IPADDR_INET6 ? REQ_ADDSRC_IPV6 : 0) |
convert_addsrc_sel_options(data.params.sel_options));
params.nts = !!(flags & REQ_ADDSRC_NTS);
params.copy = !!(flags & REQ_ADDSRC_COPY);
params.ext_fields = (flags & REQ_ADDSRC_EF_EXP_MONO_ROOT ? NTP_EF_FLAG_EXP_MONO_ROOT : 0) |
- (flags & REQ_ADDSRC_EF_EXP_NET_CORRECTION ?
- NTP_EF_FLAG_EXP_NET_CORRECTION : 0);
+ (flags & REQ_ADDSRC_EF_NET_CORRECTION ? NTP_EF_FLAG_NET_CORRECTION : 0);
params.sel_options = convert_addsrc_select_options(ntohl(rx_message->data.ntp_source.flags));
status = NSR_AddSourceByName(name, family, port, pool, type, ¶ms, NULL);
if (sscanf(line, "%"SCNx32"%n", &ef_type, &n) != 1)
return CPS_InvalidValue;
switch (ef_type) {
+ case NTP_EF_NET_CORRECTION:
+ case 0xF324:
+ src->params.ext_fields |= NTP_EF_FLAG_NET_CORRECTION;
+ break;
case NTP_EF_EXP_MONO_ROOT:
src->params.ext_fields |= NTP_EF_FLAG_EXP_MONO_ROOT;
break;
- case NTP_EF_EXP_NET_CORRECTION:
- src->params.ext_fields |= NTP_EF_FLAG_EXP_NET_CORRECTION;
- break;
default:
return CPS_InvalidValue;
}
+
The following extension fields are supported:
+
+_10A_::::
+The Network Correction extension field enabling the use of the Precision Time
+Protocol (PTP) corrections in NTP-over-PTP messages updated by
+one-step end-to-end transparent clocks (e.g. network switches). It can
+significantly improve the accuracy and stability of the synchronisation. NTP
+over PTP needs to be enabled by the <<ptpport,*ptpport*>> directive and setting
+the *port* option to the PTP port. The corrections are applied only to NTP
+measurements with HW timestamps (enabled by the <<hwtimestamp,*hwtimestamp*>>
+directive).
++
+This field should be enabled only for servers known to be running *chronyd*
+version 4.9 or later, or other implementations supporting the Network
+Correction extension field. *chronyd* versions 4.5-4.8 supported an experimental
+version of this extension field (type _F324_), which is no longer supported,
+but type _F324_ is accepted as an alias for _10A_.
_F323_::::
An experimental extension field to enable several improvements that were
proposed for the next version of the NTP protocol (NTPv5). The field contains
timestamp, which enables a frequency transfer between the server and client to
significantly improve stability of the synchronisation. This field should be
enabled only for servers known to be running *chronyd* version 4.2 or later.
-_F324_::::
-An experimental extension field to enable the use of the Precision Time
-Protocol (PTP) correction field in NTP-over-PTP messages updated by one-step
-end-to-end transparent clocks in network switches and routers to significantly
-improve accuracy and stability of the synchronisation. NTP-over-PTP can be
-enabled by the <<ptpport,*ptpport*>> directive and setting the *port* option to
-the PTP port. The corrections are applied only to NTP measurements with HW
-timestamps (enabled by the <<hwtimestamp,*hwtimestamp*>> directive). This
-field should be enabled only for servers known to be running *chronyd* version
-4.5 or later.
*ipv4*:::
*ipv6*:::
These options force *chronyd* to use only IPv4 or IPv6 addresses respectively
[[ptpport]]*ptpport* _port_::
The *ptpport* directive enables *chronyd* to send and receive NTP messages
-contained in PTP event messages (NTP-over-PTP) to enable hardware timestamping
+contained in PTP event messages (NTP over PTP) to enable hardware timestamping
on NICs that cannot timestamp NTP packets, but can timestamp unicast PTP
packets, and also use corrections provided by PTP one-step end-to-end
transparent clocks in network switches and routers. The port recognized by the
NICs and PTP transparent clocks is 319 (PTP event port). The default value is 0
(disabled).
+
-The NTP-over-PTP support is experimental. The protocol and configuration can
-change in future. It should be used only in local networks.
+Support for NTP over PTP was added in *chronyd* version 4.9.
+Versions 4.2-4.8 supported an experimental version of the transport, which is
+not compatible with the final specification.
+
The PTP port will be open even if *chronyd* is not configured to operate as a
server or client. The directive does not change the default protocol of
-specified NTP sources. Each NTP source that should use NTP-over-PTP needs to
+specified NTP sources. Each NTP source that should use NTP over PTP needs to
be specified with the *port* option set to the PTP port. To actually enable
hardware timestamping on NICs that can timestamp PTP packets only, the
*rxfilter* option of the *hwtimestamp* directive needs to be set to _ptp_. The
-extension field _F324_ needs to be enabled to use the corrections provided by
+extension field _10A_ needs to be enabled to use the corrections provided by
the PTP transparent clocks.
+
An example of client configuration is:
+
----
-server ntp1.example.net minpoll 0 maxpoll 0 xleave port 319 extfield F324
+server ntp1.example.net minpoll 0 maxpoll 0 xleave port 319 extfield 10A
hwtimestamp * rxfilter ptp
ptpport 319
----
Since version 4.5, `chronyd` can apply corrections from PTP one-step end-to-end
transparent clocks (e.g. network switches) to significantly improve accuracy of
synchronisation in local networks. It requires the PTP transport to be enabled
-by the `ptpport` directive, HW timestamping, and the `extfield F324` option.
-For example:
+by the `ptpport` directive, `port` option, HW timestamping, and the `extfield
+F324` option (in versions 4.5-4.8) or `extfield 10A` option (version 4.9 and
+later). For example:
----
-server ntp.local minpoll -4 maxpoll -4 xleave extfield F323 extfield F324 port 319
+server ntp.local minpoll -4 maxpoll -4 xleave extfield F323 extfield 10A port 319
ptpport 319
hwtimestamp eth0 minpoll -4
----
packets than PTP, which is usually the case at least for transmitted packets.
The `ethtool -T` command can be used to verify the timestamping support.
-As an experimental feature added in version 4.2, `chrony` can use PTP as a
-transport for NTP messages (NTP over PTP) to enable hardware timestamping on
-hardware which can timestamp PTP packets only. It can be enabled by the
-`ptpport` directive. Since version 4.5, `chrony` can also apply corrections
-provided by PTP one-step end-to-end transparent clocks to reach the accuracy of
-ordinary PTP clocks. The application of PTP corrections can be enabled by the
-`extfield F324` option.
+As an experimental feature added in version 4.2, and fully supported since
+version 4.9, `chrony` can use PTP as a transport for NTP messages (NTP over
+PTP) to enable hardware timestamping on hardware which can timestamp only PTP
+packets. NTP over PTP can be enabled by the `ptpport` directive and setting the
+`port` option to the PTP port 319. Since version 4.5, `chrony` can also apply
+corrections provided by PTP one-step end-to-end transparent clocks (e.g.
+network switches) to reach the accuracy of ordinary PTP clocks. The application
+of PTP corrections can be enabled by the `extfield F324` option in versions
+before 4.9, or `extfield 10A` in later versions.
=== How can I avoid using wrong PHC refclock?
/* Non-authentication extension fields and corresponding internal flags */
+#define NTP_EF_NET_CORRECTION 0x010A
#define NTP_EF_EXP_MONO_ROOT 0xF323
-#define NTP_EF_EXP_NET_CORRECTION 0xF324
-#define NTP_EF_FLAG_EXP_MONO_ROOT 0x1
-#define NTP_EF_FLAG_EXP_NET_CORRECTION 0x2
+#define NTP_EF_FLAG_NET_CORRECTION 0x1
+#define NTP_EF_FLAG_EXP_MONO_ROOT 0x2
+
+/* Network Correction extension field */
+typedef struct {
+ NTP_int64 correction;
+ uint32_t pad[4];
+} NTP_EFNetCorrection;
/* Pre-NTPv5 experimental extension field */
typedef struct {
#define NTP_EF_EXP_MONO_ROOT_MAGIC 0xF5BEDD9AU
-/* Experimental extension field to provide PTP corrections */
-typedef struct {
- uint32_t magic;
- NTP_int64 correction;
- uint32_t reserved[3];
-} NTP_EFExpNetCorrection;
-
-#define NTP_EF_EXP_NET_CORRECTION_MAGIC 0x07AC2CEBU
-
/* Authentication extension fields */
#define NTP_EF_NTS_UNIQUE_IDENTIFIER 0x0104
assert(offsetof(NTP_Packet, receive_ts) == 32);
assert(offsetof(NTP_Packet, transmit_ts) == 40);
+ assert(sizeof (NTP_EFNetCorrection) == 24);
assert(sizeof (NTP_EFExpMonoRoot) == 24);
- assert(sizeof (NTP_EFExpNetCorrection) == 24);
}
/* ================================================== */
add_ef_net_correction(NTP_Packet *message, NTP_PacketInfo *info,
NTP_Local_Timestamp *local_rx)
{
- NTP_EFExpNetCorrection ef;
+ NTP_EFNetCorrection ef;
if (CNF_GetPtpPort() == 0) {
DEBUG_LOG("ptpport disabled");
}
memset(&ef, 0, sizeof (ef));
- ef.magic = htonl(NTP_EF_EXP_NET_CORRECTION_MAGIC);
if (info->mode != MODE_CLIENT && local_rx->net_correction > local_rx->rx_duration) {
UTI_DoubleToNtp64(local_rx->net_correction, &ef.correction);
}
- if (!NEF_AddField(message, info, NTP_EF_EXP_NET_CORRECTION, &ef, sizeof (ef))) {
+ if (!NEF_AddField(message, info, NTP_EF_NET_CORRECTION, &ef, sizeof (ef))) {
DEBUG_LOG("Could not add EF");
return 0;
}
- info->ext_field_flags |= NTP_EF_FLAG_EXP_NET_CORRECTION;
+ info->ext_field_flags |= NTP_EF_FLAG_NET_CORRECTION;
return 1;
}
return 0;
if (ext_field_flags) {
+ if (ext_field_flags & NTP_EF_FLAG_NET_CORRECTION) {
+ if (!add_ef_net_correction(&message, &info, local_rx))
+ return 0;
+ }
if (ext_field_flags & NTP_EF_FLAG_EXP_MONO_ROOT) {
if (!add_ef_mono_root(&message, &info, smooth_time ? NULL : &local_receive,
our_root_delay, our_root_dispersion))
return 0;
}
- if (ext_field_flags & NTP_EF_FLAG_EXP_NET_CORRECTION) {
- if (!add_ef_net_correction(&message, &info, local_rx))
- return 0;
- }
}
do {
case NTP_EF_NTS_AUTH_AND_EEF:
info->auth.mode = NTP_AUTH_NTS;
break;
+ case NTP_EF_NET_CORRECTION:
+ if (ef_body_length == sizeof (NTP_EFNetCorrection))
+ info->ext_field_flags |= NTP_EF_FLAG_NET_CORRECTION;
+ break;
case NTP_EF_EXP_MONO_ROOT:
if (is_exp_ef(ef_body, ef_body_length, sizeof (NTP_EFExpMonoRoot),
NTP_EF_EXP_MONO_ROOT_MAGIC))
info->ext_field_flags |= NTP_EF_FLAG_EXP_MONO_ROOT;
break;
- case NTP_EF_EXP_NET_CORRECTION:
- if (is_exp_ef(ef_body, ef_body_length, sizeof (NTP_EFExpNetCorrection),
- NTP_EF_EXP_NET_CORRECTION_MAGIC))
- info->ext_field_flags |= NTP_EF_FLAG_EXP_NET_CORRECTION;
- break;
default:
DEBUG_LOG("Unknown extension field type=%x", (unsigned int)ef_type);
}
/* Extension fields */
int parsed, ef_length, ef_type, ef_body_length;
void *ef_body;
+ NTP_EFNetCorrection *ef_net_correction;
NTP_EFExpMonoRoot *ef_mono_root;
- NTP_EFExpNetCorrection *ef_net_correction;
NTP_Local_Timestamp local_receive, local_transmit;
double remote_interval, local_interval, response_time;
break;
switch (ef_type) {
+ case NTP_EF_NET_CORRECTION:
+ if (inst->ext_field_flags & NTP_EF_FLAG_NET_CORRECTION &&
+ ef_body_length == sizeof (*ef_net_correction))
+ ef_net_correction = ef_body;
+ break;
case NTP_EF_EXP_MONO_ROOT:
if (inst->ext_field_flags & NTP_EF_FLAG_EXP_MONO_ROOT &&
is_exp_ef(ef_body, ef_body_length, sizeof (*ef_mono_root),
NTP_EF_EXP_MONO_ROOT_MAGIC))
ef_mono_root = ef_body;
break;
- case NTP_EF_EXP_NET_CORRECTION:
- if (inst->ext_field_flags & NTP_EF_FLAG_EXP_NET_CORRECTION &&
- is_exp_ef(ef_body, ef_body_length, sizeof (*ef_net_correction),
- NTP_EF_EXP_NET_CORRECTION_MAGIC))
- ef_net_correction = ef_body;
- break;
}
}
}
ntohs(msg->header.length) != message->length ||
msg->header.domain != CNF_GetPtpDomain() ||
ntohs(msg->header.flags) != PTP_FLAG_UNICAST ||
- ntohs(msg->tlv_header.type) != PTP_TLV_NTP ||
- ntohs(msg->tlv_header.length) != message->length - PTP_NTP_PREFIX_LENGTH) {
+ (ntohs(msg->tlv_header.type) != PTP_TLV_ORGEXT2 &&
+ ntohs(msg->tlv_header.type) != PTP_TLV_ORGEXT21) ||
+ ntohs(msg->tlv_header.length) != 8 + message->length - PTP_NTP_PREFIX_LENGTH ||
+ memcmp(msg->tlv_header.org_id_subtype, PTP_IANA_TLV_NTP_MSG,
+ sizeof (msg->tlv_header.org_id_subtype)) != 0) {
DEBUG_LOG("Unexpected PTP message");
return 0;
}
{
static uint16_t sequence_id = 0;
- assert(PTP_NTP_PREFIX_LENGTH == 48);
+ assert(PTP_NTP_PREFIX_LENGTH == 56);
if (!is_ptp_socket(sock_fd))
return 1;
ptp_message->header.domain = CNF_GetPtpDomain();
ptp_message->header.flags = htons(PTP_FLAG_UNICAST);
ptp_message->header.sequence_id = htons(sequence_id++);
- ptp_message->tlv_header.type = htons(PTP_TLV_NTP);
- ptp_message->tlv_header.length = htons(message->length);
+ ptp_message->tlv_header.type = htons(PTP_TLV_ORGEXT2);
+ ptp_message->tlv_header.length = htons(8 + message->length);
+ memcpy(ptp_message->tlv_header.org_id_subtype, PTP_IANA_TLV_NTP_MSG,
+ sizeof (ptp_message->tlv_header.org_id_subtype));
memcpy((char *)ptp_message + PTP_NTP_PREFIX_LENGTH, message->data, message->length);
message->data = ptp_message;
#define PTP_TYPE_SYNC 0
#define PTP_TYPE_DELAY_REQ 1
#define PTP_FLAG_UNICAST (1 << (2 + 8))
-#define PTP_TLV_NTP 0x2023
+#define PTP_TLV_ORGEXT2 0x0003
+#define PTP_TLV_ORGEXT21 0x8000
+#define PTP_IANA_TLV_NTP_MSG "\x00\x00\x5E\x00\x00\x01"
typedef struct {
uint8_t type;
typedef struct {
uint16_t type;
uint16_t length;
-} PTP_TlvHeader;
+ uint8_t org_id_subtype[6];
+ uint16_t pad;
+} PTP_TlvNtpHeader;
typedef struct {
PTP_Header header;
uint8_t origin_ts[10];
- PTP_TlvHeader tlv_header;
+ PTP_TlvNtpHeader tlv_header;
NTP_Packet ntp_msg;
} PTP_NtpMessage;
for chronyc_conf in \
"accheck 1.2.3.4" \
"add peer 10.0.0.0 minpoll 2 maxpoll 6" \
- "add server 10.0.0.0 minpoll 6 maxpoll 10 iburst burst key 1 certset 2 maxdelay 1e-3 maxdelayratio 10.0 maxdelaydevratio 10.0 maxdelayquant 0.5 mindelay 1e-4 asymmetry 0.5 offset 1e-5 minsamples 6 maxsamples 6 maxunreach 8 filter 3 offline auto_offline prefer noselect trust require xleave polltarget 20 port 123 presend 7 minstratum 3 version 4 nts ntsport 4460 copy extfield F323 extfield F324 ipv6 ipv4" \
+ "add server 10.0.0.0 minpoll 6 maxpoll 10 iburst burst key 1 certset 2 maxdelay 1e-3 maxdelayratio 10.0 maxdelaydevratio 10.0 maxdelayquant 0.5 mindelay 1e-4 asymmetry 0.5 offset 1e-5 minsamples 6 maxsamples 6 maxunreach 8 filter 3 offline auto_offline prefer noselect trust require xleave polltarget 20 port 123 presend 7 minstratum 3 version 4 nts ntsport 4460 copy extfield 10A extfield F323 ipv6 ipv4" \
"add server node1.net1.clk" \
"allow 1.2.3.4" \
"allow 1.2" \
check_source_selection || test_fail
check_sync || test_fail
-check_file_messages " 2 1 .* 319 319 1 96 " 150 160 \
+check_file_messages " 2 1 .* 319 319 1 104 " 150 160 \
log.packets || test_fail
-check_file_messages " 1 2 .* 319 319 1 96 " 150 160 \
+check_file_messages " 1 2 .* 319 319 1 104 " 150 160 \
log.packets || test_fail
-check_file_messages " 2 3 .* 319 319 1 116 " 150 160 \
+check_file_messages " 2 3 .* 319 319 1 124 " 150 160 \
log.packets || test_fail
-check_file_messages " 3 2 .* 319 319 1 116 " 150 160 \
+check_file_messages " 3 2 .* 319 319 1 124 " 150 160 \
log.packets || test_fail
check_config_h 'HAVE_LINUX_TIMESTAMPING 1' || test_skip
export CLKNETSIM_TIMESTAMPING=2
export CLKNETSIM_LINK_SPEED=100
-client_server_options+=" extfield F324 minpoll 0 maxpoll 0"
-client_peer_options+=" extfield F324 minpoll 0 maxpoll 0 maxdelaydevratio 1e6"
+client_server_options+=" extfield 10A minpoll 0 maxpoll 0"
+client_peer_options+=" extfield 10A minpoll 0 maxpoll 0 maxdelaydevratio 1e6"
server_conf+="
clockprecision 1e-9
hwtimestamp eth0"