ntp: use NTP instead of echo for presend
Switch to NTP for presend as the echo service (RFC 862) is rarely enabled. When presend is active, send an NTP client packet to the server/peer and ignore the reply. This also fixes presend with separate client sockets. The destination port can't be changed on connected sockets, so the echo packet was sent to the NTP port instead of the echo port.
This commit is contained in:
parent
ff4abc69c3
commit
cd5105b1db
4 changed files with 18 additions and 32 deletions
|
@ -2836,18 +2836,18 @@ of the machines.
|
|||
|
||||
In order to avoid this problem, the @code{presend} option may be used.
|
||||
It takes a single integer argument, which is the smallest polling
|
||||
interval for which a pair of packets will be exchanged between the
|
||||
client and the server prior to the actual measurement being initiated by
|
||||
the client. For example, with the following option included in a
|
||||
interval for which an extra pair of NTP packets will be exchanged
|
||||
between the client and the server prior to the actual measurement.
|
||||
For example, with the following option included in a
|
||||
@code{server} directive :
|
||||
|
||||
@example
|
||||
presend 9
|
||||
@end example
|
||||
|
||||
when the polling interval is 512 seconds or more, a UDP echo datagram
|
||||
will be sent to the server a short time (currently 4 seconds) before the
|
||||
NTP client mode datagram.
|
||||
when the polling interval is 512 seconds or more, an extra NTP client
|
||||
packet will be sent to the server a short time (currently 4 seconds)
|
||||
before making the actual measurement.
|
||||
|
||||
@item key
|
||||
The NTP protocol supports the inclusion of checksums in the packets, to
|
||||
|
|
18
ntp_core.c
18
ntp_core.c
|
@ -85,8 +85,8 @@ struct NCR_Instance_Record {
|
|||
received packets) */
|
||||
|
||||
int presend_minpoll; /* If the current polling interval is
|
||||
at least this, an echo datagram
|
||||
will be send some time before every
|
||||
at least this, an extra client packet
|
||||
will be send some time before normal
|
||||
transmit. This ensures that both
|
||||
us and the server/peer have an ARP
|
||||
entry for each other ready, which
|
||||
|
@ -191,7 +191,7 @@ struct NCR_Instance_Record {
|
|||
#define IBURST_GOOD_SAMPLES 4
|
||||
#define IBURST_TOTAL_SAMPLES SOURCE_REACH_BITS
|
||||
|
||||
/* Time to wait after sending echo to 'warm up' link */
|
||||
/* Time to wait after sending packet to 'warm up' link */
|
||||
#define WARM_UP_DELAY 4.0
|
||||
|
||||
/* The NTP protocol version that we support */
|
||||
|
@ -820,7 +820,7 @@ transmit_timeout(void *arg)
|
|||
}
|
||||
|
||||
/* Check whether we need to 'warm up' the link to the other end by
|
||||
sending an echo exchange to ensure both ends' ARP caches are
|
||||
sending an NTP exchange to ensure both ends' ARP caches are
|
||||
primed. On loaded systems this might also help ensure that bits
|
||||
of the program are paged in properly before we start. */
|
||||
|
||||
|
@ -828,8 +828,11 @@ transmit_timeout(void *arg)
|
|||
(inst->presend_minpoll <= inst->local_poll) &&
|
||||
!inst->presend_done) {
|
||||
|
||||
/* Send */
|
||||
NIO_SendEcho(&inst->remote_addr, &inst->local_addr);
|
||||
/* Send a client packet, don't store the local tx values
|
||||
as the reply will be ignored */
|
||||
transmit_packet(MODE_CLIENT, inst->local_poll, NTP_VERSION, 0, 0,
|
||||
&inst->remote_orig, &inst->local_rx, NULL, NULL,
|
||||
&inst->remote_addr, &inst->local_addr);
|
||||
|
||||
inst->presend_done = 1;
|
||||
|
||||
|
@ -1483,6 +1486,9 @@ NCR_ProcessKnown
|
|||
break;
|
||||
|
||||
case MODE_SERVER:
|
||||
/* Ignore presend reply */
|
||||
if (inst->presend_done)
|
||||
break;
|
||||
|
||||
switch(inst->mode) {
|
||||
case MODE_ACTIVE:
|
||||
|
|
17
ntp_io.c
17
ntp_io.c
|
@ -687,20 +687,3 @@ NIO_SendAuthenticatedPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr,
|
|||
{
|
||||
send_packet((void *) packet, NTP_NORMAL_PACKET_SIZE + auth_len, remote_addr, local_addr);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
/* We ought to use getservbyname, but I can't really see this changing */
|
||||
#define ECHO_PORT 7
|
||||
|
||||
void
|
||||
NIO_SendEcho(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr)
|
||||
{
|
||||
unsigned long magic_message = 0xbe7ab1e7UL;
|
||||
NTP_Remote_Address addr;
|
||||
|
||||
addr = *remote_addr;
|
||||
addr.port = ECHO_PORT;
|
||||
|
||||
send_packet((void *) &magic_message, sizeof(unsigned long), &addr, local_addr);
|
||||
}
|
||||
|
|
3
ntp_io.h
3
ntp_io.h
|
@ -56,7 +56,4 @@ extern void NIO_SendNormalPacket(NTP_Packet *packet, NTP_Remote_Address *remote_
|
|||
/* Function to transmit an authenticated packet */
|
||||
extern void NIO_SendAuthenticatedPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr, int auth_len);
|
||||
|
||||
/* Function to send a datagram to a remote machine's UDP echo port. */
|
||||
extern void NIO_SendEcho(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr);
|
||||
|
||||
#endif /* GOT_NTP_IO_H */
|
||||
|
|
Loading…
Reference in a new issue