mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-06 14:55:06 -05:00
Add IPv6 support
This commit is contained in:
56
ntp_core.c
56
ntp_core.c
@@ -319,7 +319,7 @@ create_instance(NTP_Remote_Address *remote_addr, NTP_Mode mode, SourceParameters
|
||||
result->local_poll = params->minpoll;
|
||||
|
||||
/* Create a source instance for this NTP source */
|
||||
result->source = SRC_CreateNewInstance(remote_addr->ip_addr, SRC_NTP);
|
||||
result->source = SRC_CreateNewInstance(UTI_IPToRefid(&remote_addr->ip_addr), SRC_NTP, &result->remote_addr.ip_addr);
|
||||
|
||||
result->local_rx.tv_sec = 0;
|
||||
result->local_rx.tv_usec = 0;
|
||||
@@ -626,7 +626,7 @@ transmit_timeout(void *arg)
|
||||
|
||||
#ifdef TRACEON
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Transmit timeout for [%s:%d]",
|
||||
UTI_IPToDottedQuad(inst->remote_addr.ip_addr), inst->remote_addr.port);
|
||||
UTI_IPToString(&inst->remote_addr.ip_addr), inst->remote_addr.port);
|
||||
#endif
|
||||
|
||||
/* Check whether we need to 'warm up' the link to the other end by
|
||||
@@ -1043,8 +1043,8 @@ receive_packet(NTP_Packet *message, struct timeval *now, NCR_Instance inst, int
|
||||
message->lvm, message->stratum, message->poll, message->precision);
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Root delay=%08lx (%f), dispersion=%08lx (%f)",
|
||||
message->root_delay, pkt_root_delay, message->root_dispersion, pkt_root_dispersion);
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Ref id=[%s], ref_time=%08lx.%08lx [%s]",
|
||||
UTI_IPToDottedQuad(ntohl(message->reference_id)),
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Ref id=[%lx], ref_time=%08lx.%08lx [%s]",
|
||||
ntohl(message->reference_id),
|
||||
message->reference_ts.hi, message->reference_ts.lo,
|
||||
UTI_TimestampToString(&message->reference_ts));
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Originate=%08lx.%08lx [%s]",
|
||||
@@ -1243,7 +1243,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, NCR_Instance inst, int
|
||||
inst->maxpoll = inst->minpoll;
|
||||
if (inst->minpoll > inst->local_poll)
|
||||
inst->local_poll = inst->minpoll;
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Received KoD RATE from %s, minpoll set to %d", UTI_IPToDottedQuad(inst->remote_addr.ip_addr), inst->minpoll);
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Received KoD RATE from %s, minpoll set to %d", UTI_IPToString(&inst->remote_addr.ip_addr), inst->minpoll);
|
||||
}
|
||||
/* Back off for a while */
|
||||
delay_time += (double) (4 * (1UL << inst->minpoll));
|
||||
@@ -1268,7 +1268,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, NCR_Instance inst, int
|
||||
|
||||
fprintf(logfile, "%s %-15s %1c %2d %1d%1d%1d%1d %1d%1d %1d%1d%1d%1d %2d %2d %2d %10.3e %10.3e %10.3e %10.3e %10.3e\n",
|
||||
UTI_TimeToLogForm(sample_time.tv_sec),
|
||||
UTI_IPToDottedQuad(inst->remote_addr.ip_addr),
|
||||
UTI_IPToString(&inst->remote_addr.ip_addr),
|
||||
sync_stats[pkt_leap],
|
||||
message->stratum,
|
||||
test1, test2, test3, test4,
|
||||
@@ -1357,9 +1357,9 @@ process_known
|
||||
one of the secondaries to flywheel it. The behaviour coded here
|
||||
is required in the secondaries to make this possible. */
|
||||
|
||||
if (ADF_IsAllowed(access_auth_table, inst->remote_addr.ip_addr)) {
|
||||
if (ADF_IsAllowed(access_auth_table, &inst->remote_addr.ip_addr)) {
|
||||
|
||||
CLG_LogNTPClientAccess(inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
CLG_LogNTPClientAccess(&inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
|
||||
if (do_auth) {
|
||||
auth_key_id = ntohl(message->auth_keyid);
|
||||
@@ -1392,7 +1392,7 @@ process_known
|
||||
|
||||
} else {
|
||||
LOG(LOGS_WARN, LOGF_NtpCore, "NTP packet received from unauthorised host %s port %d",
|
||||
UTI_IPToDottedQuad(inst->remote_addr.ip_addr),
|
||||
UTI_IPToString(&inst->remote_addr.ip_addr),
|
||||
inst->remote_addr.port);
|
||||
}
|
||||
|
||||
@@ -1403,7 +1403,7 @@ process_known
|
||||
switch(inst->mode) {
|
||||
case MODE_ACTIVE:
|
||||
/* Ordinary symmetric peering */
|
||||
CLG_LogNTPPeerAccess(inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
CLG_LogNTPPeerAccess(&inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
receive_packet(message, now, inst, do_auth);
|
||||
break;
|
||||
case MODE_PASSIVE:
|
||||
@@ -1413,7 +1413,7 @@ process_known
|
||||
case MODE_CLIENT:
|
||||
/* This is where we have the remote configured as a server and he has
|
||||
us configured as a peer - fair enough. */
|
||||
CLG_LogNTPPeerAccess(inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
CLG_LogNTPPeerAccess(&inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
receive_packet(message, now, inst, do_auth);
|
||||
break;
|
||||
case MODE_SERVER:
|
||||
@@ -1434,7 +1434,7 @@ process_known
|
||||
switch(inst->mode) {
|
||||
case MODE_ACTIVE:
|
||||
/* Slightly bizarre combination, but we can still process it */
|
||||
CLG_LogNTPPeerAccess(inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
CLG_LogNTPPeerAccess(&inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
receive_packet(message, now, inst, do_auth);
|
||||
break;
|
||||
case MODE_PASSIVE:
|
||||
@@ -1462,7 +1462,7 @@ process_known
|
||||
case MODE_ACTIVE:
|
||||
/* This would arise if we have the remote configured as a peer and
|
||||
he does not have us configured */
|
||||
CLG_LogNTPPeerAccess(inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
CLG_LogNTPPeerAccess(&inst->remote_addr.ip_addr, (time_t) now->tv_sec);
|
||||
receive_packet(message, now, inst, do_auth);
|
||||
break;
|
||||
case MODE_PASSIVE:
|
||||
@@ -1524,19 +1524,19 @@ NCR_ProcessNoauthUnknown(NTP_Packet *message, struct timeval *now, NTP_Remote_Ad
|
||||
NTP_Mode my_mode;
|
||||
int my_poll;
|
||||
|
||||
if (ADF_IsAllowed(access_auth_table, remote_addr->ip_addr)) {
|
||||
if (ADF_IsAllowed(access_auth_table, &remote_addr->ip_addr)) {
|
||||
|
||||
his_mode = message->lvm & 0x07;
|
||||
|
||||
if (his_mode == MODE_CLIENT) {
|
||||
/* We are server */
|
||||
my_mode = MODE_SERVER;
|
||||
CLG_LogNTPClientAccess(remote_addr->ip_addr, (time_t) now->tv_sec);
|
||||
CLG_LogNTPClientAccess(&remote_addr->ip_addr, (time_t) now->tv_sec);
|
||||
|
||||
} else if (his_mode == MODE_ACTIVE) {
|
||||
/* We are symmetric passive, even though we don't ever lock to him */
|
||||
my_mode = MODE_PASSIVE;
|
||||
CLG_LogNTPPeerAccess(remote_addr->ip_addr, (time_t) now->tv_sec);
|
||||
CLG_LogNTPPeerAccess(&remote_addr->ip_addr, (time_t) now->tv_sec);
|
||||
|
||||
} else {
|
||||
my_mode = MODE_UNDEFINED;
|
||||
@@ -1560,7 +1560,7 @@ NCR_ProcessNoauthUnknown(NTP_Packet *message, struct timeval *now, NTP_Remote_Ad
|
||||
}
|
||||
} else {
|
||||
LOG(LOGS_WARN, LOGF_NtpCore, "NTP packet received from unauthorised host %s port %d",
|
||||
UTI_IPToDottedQuad(remote_addr->ip_addr),
|
||||
UTI_IPToString(&remote_addr->ip_addr),
|
||||
remote_addr->port);
|
||||
}
|
||||
|
||||
@@ -1594,19 +1594,19 @@ NCR_ProcessAuthUnknown(NTP_Packet *message, struct timeval *now, NTP_Remote_Addr
|
||||
int valid_key, valid_auth;
|
||||
unsigned long key_id;
|
||||
|
||||
if (ADF_IsAllowed(access_auth_table, remote_addr->ip_addr)) {
|
||||
if (ADF_IsAllowed(access_auth_table, &remote_addr->ip_addr)) {
|
||||
|
||||
his_mode = message->lvm & 0x07;
|
||||
|
||||
if (his_mode == MODE_CLIENT) {
|
||||
/* We are server */
|
||||
my_mode = MODE_SERVER;
|
||||
CLG_LogNTPClientAccess(remote_addr->ip_addr, (time_t) now->tv_sec);
|
||||
CLG_LogNTPClientAccess(&remote_addr->ip_addr, (time_t) now->tv_sec);
|
||||
|
||||
} else if (his_mode == MODE_ACTIVE) {
|
||||
/* We are symmetric passive, even though we don't ever lock to him */
|
||||
my_mode = MODE_PASSIVE;
|
||||
CLG_LogNTPPeerAccess(remote_addr->ip_addr, (time_t) now->tv_sec);
|
||||
CLG_LogNTPPeerAccess(&remote_addr->ip_addr, (time_t) now->tv_sec);
|
||||
|
||||
} else {
|
||||
my_mode = MODE_UNDEFINED;
|
||||
@@ -1678,7 +1678,7 @@ NCR_TakeSourceOnline(NCR_Instance inst)
|
||||
case MD_OFFLINE:
|
||||
if (!inst->timer_running) {
|
||||
/* We are not already actively polling it */
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s online", UTI_IPToDottedQuad(inst->remote_addr.ip_addr));
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s online", UTI_IPToString(&inst->remote_addr.ip_addr));
|
||||
inst->local_poll = inst->minpoll;
|
||||
inst->score = (ZONE_WIDTH >> 1);
|
||||
inst->opmode = MD_ONLINE;
|
||||
@@ -1702,7 +1702,7 @@ NCR_TakeSourceOffline(NCR_Instance inst)
|
||||
switch (inst->opmode) {
|
||||
case MD_ONLINE:
|
||||
if (inst->timer_running) {
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s offline", UTI_IPToDottedQuad(inst->remote_addr.ip_addr));
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s offline", UTI_IPToString(&inst->remote_addr.ip_addr));
|
||||
SCH_RemoveTimeout(inst->timeout_id);
|
||||
inst->timer_running = 0;
|
||||
inst->opmode = MD_OFFLINE;
|
||||
@@ -1725,7 +1725,7 @@ void
|
||||
NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll)
|
||||
{
|
||||
inst->minpoll = new_minpoll;
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new minpoll %d", UTI_IPToDottedQuad(inst->remote_addr.ip_addr), new_minpoll);
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new minpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), new_minpoll);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
@@ -1734,7 +1734,7 @@ void
|
||||
NCR_ModifyMaxpoll(NCR_Instance inst, int new_maxpoll)
|
||||
{
|
||||
inst->maxpoll = new_maxpoll;
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new maxpoll %d", UTI_IPToDottedQuad(inst->remote_addr.ip_addr), new_maxpoll);
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new maxpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), new_maxpoll);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
@@ -1744,7 +1744,7 @@ NCR_ModifyMaxdelay(NCR_Instance inst, double new_max_delay)
|
||||
{
|
||||
inst->max_delay = new_max_delay;
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new max delay %f",
|
||||
UTI_IPToDottedQuad(inst->remote_addr.ip_addr), new_max_delay);
|
||||
UTI_IPToString(&inst->remote_addr.ip_addr), new_max_delay);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
@@ -1754,7 +1754,7 @@ NCR_ModifyMaxdelayratio(NCR_Instance inst, double new_max_delay_ratio)
|
||||
{
|
||||
inst->max_delay_ratio = new_max_delay_ratio;
|
||||
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new max delay ratio %f",
|
||||
UTI_IPToDottedQuad(inst->remote_addr.ip_addr), new_max_delay_ratio);
|
||||
UTI_IPToString(&inst->remote_addr.ip_addr), new_max_delay_ratio);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
@@ -1836,7 +1836,7 @@ NCR_ReportSource(NCR_Instance inst, RPT_SourceReport *report, struct timeval *no
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
NCR_AddAccessRestriction(unsigned long ip_addr, int subnet_bits, int allow, int all)
|
||||
NCR_AddAccessRestriction(IPAddr *ip_addr, int subnet_bits, int allow, int all)
|
||||
{
|
||||
ADF_Status status;
|
||||
|
||||
@@ -1866,7 +1866,7 @@ NCR_AddAccessRestriction(unsigned long ip_addr, int subnet_bits, int allow, int
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
NCR_CheckAccessRestriction(unsigned long ip_addr)
|
||||
NCR_CheckAccessRestriction(IPAddr *ip_addr)
|
||||
{
|
||||
return ADF_IsAllowed(access_auth_table, ip_addr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user