diff --git a/broadcast.c b/broadcast.c deleted file mode 100644 index 30e19f1..0000000 --- a/broadcast.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - chronyd/chronyc - Programs for keeping computer clocks accurate. - - ********************************************************************** - * Copyright (C) Richard P. Curnow 1997-2002 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - ********************************************************************** - - ======================================================================= - - Deal with broadcast server functions. - */ - -#include "config.h" - -#include "sysincl.h" -#include "memory.h" - -#include "addressing.h" -#include "broadcast.h" -#include "sched.h" -#include "ntp.h" -#include "local.h" -#include "reference.h" -#include "util.h" -#include "ntp_io.h" - -typedef struct { - NTP_Remote_Address addr; - NTP_Local_Address local_addr; - int interval; -} Destination; -static Destination *destinations = 0; -static int n_destinations = 0; -static int max_destinations = 0; - -void -BRD_Initialise(void) -{ -} - -/* ================================================== */ - -void -BRD_Finalise(void) -{ -} - -/* ================================================== */ -/* This is a cut-down version of what transmit_packet in ntp_core.c does */ - -static void -timeout_handler(void *arbitrary) -{ - Destination *d = (Destination *) arbitrary; - NTP_Packet message; - /* Parameters read from reference module */ - int leap; - int are_we_synchronised, our_stratum; - NTP_Leap leap_status; - uint32_t our_ref_id, ts_fuzz; - struct timeval our_ref_time; - double our_root_delay, our_root_dispersion; - struct timeval local_transmit; - - LCL_ReadCookedTime(&local_transmit, NULL); - REF_GetReferenceParams(&local_transmit, - &are_we_synchronised, &leap_status, - &our_stratum, - &our_ref_id, &our_ref_time, - &our_root_delay, &our_root_dispersion); - - - if (are_we_synchronised) { - leap = (int) leap_status; - } else { - leap = LEAP_Unsynchronised; - } - - if (our_stratum >= NTP_MAX_STRATUM) - our_stratum = 0; - - message.lvm = NTP_LVM(leap, NTP_VERSION, MODE_BROADCAST); - message.stratum = our_stratum; - message.poll = 6; /* FIXME: what should this be? */ - message.precision = LCL_GetSysPrecisionAsLog(); - - /* If we're sending a client mode packet and we aren't synchronized yet, - we might have to set up artificial values for some of these parameters */ - message.root_delay = UTI_DoubleToInt32(our_root_delay); - message.root_dispersion = UTI_DoubleToInt32(our_root_dispersion); - - message.reference_id = htonl((NTP_int32) our_ref_id); - - /* Now fill in timestamps */ - UTI_TimevalToInt64(&our_ref_time, &message.reference_ts, 0); - message.originate_ts.hi = 0UL; - message.originate_ts.lo = 0UL; - message.receive_ts.hi = 0UL; - message.receive_ts.lo = 0UL; - - ts_fuzz = UTI_GetNTPTsFuzz(message.precision); - LCL_ReadCookedTime(&local_transmit, NULL); - UTI_TimevalToInt64(&local_transmit, &message.transmit_ts, ts_fuzz); - NIO_SendPacket(&message, &d->addr, &d->local_addr, NTP_NORMAL_PACKET_LENGTH); - - /* Requeue timeout. Don't care if interval drifts gradually, so just do it - * at the end. */ - SCH_AddTimeoutInClass((double) d->interval, 1.0, 0.02, - SCH_NtpBroadcastClass, - timeout_handler, (void *) d); - - -} - -/* ================================================== */ - -void -BRD_AddDestination(IPAddr *addr, unsigned short port, int interval) -{ - if (max_destinations == n_destinations) { - /* Expand array */ - max_destinations += 8; - if (destinations) { - destinations = ReallocArray(Destination, max_destinations, destinations); - } else { - destinations = MallocArray(Destination, max_destinations); - } - } - - destinations[n_destinations].addr.ip_addr = *addr; - destinations[n_destinations].addr.port = port; - destinations[n_destinations].local_addr.ip_addr.family = IPADDR_UNSPEC; - destinations[n_destinations].local_addr.sock_fd = - NIO_GetServerSocket(&destinations[n_destinations].addr); - destinations[n_destinations].interval = interval; - - SCH_AddTimeoutInClass((double) interval, 1.0, 0.0, - SCH_NtpBroadcastClass, - timeout_handler, (void *)(destinations + n_destinations)); - - ++n_destinations; - -} - - diff --git a/broadcast.h b/broadcast.h deleted file mode 100644 index 08ba6db..0000000 --- a/broadcast.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - chronyd/chronyc - Programs for keeping computer clocks accurate. - - ********************************************************************** - * Copyright (C) Richard P. Curnow 1997-2002 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - ********************************************************************** - - ======================================================================= - - Deal with broadcast server functions. - */ - -#ifndef GOT_BROADCAST_H -#define GOT_BROADCAST_H - -#include "addressing.h" - -extern void BRD_Initialise(void); -extern void BRD_Finalise(void); -extern void BRD_AddDestination(IPAddr *addr, unsigned short port, int interval); - -#endif /* GOT_BROADCAST_H */ - diff --git a/conf.c b/conf.c index af0d3ba..ec3d9aa 100644 --- a/conf.c +++ b/conf.c @@ -40,7 +40,6 @@ #include "nameserv.h" #include "memory.h" #include "cmdparse.h" -#include "broadcast.h" #include "util.h" /* ================================================== */ @@ -1240,9 +1239,8 @@ CNF_AddBroadcasts(void) { int i; for (i=0; iaddr, &destination->local_addr); + + /* Requeue timeout. We don't care if interval drifts gradually. */ + SCH_AddTimeoutInClass(destination->interval, SAMPLING_SEPARATION, SAMPLING_RANDOMNESS, + SCH_NtpBroadcastClass, broadcast_timeout, arg); +} + +/* ================================================== */ + +void +NCR_AddBroadcastDestination(IPAddr *addr, unsigned short port, int interval) +{ + BroadcastDestination *destination; + + destination = (BroadcastDestination *)ARR_GetNewElement(broadcasts); + + destination->addr.ip_addr = *addr; + destination->addr.port = port; + destination->local_addr.ip_addr.family = IPADDR_UNSPEC; + destination->local_addr.sock_fd = NIO_GetServerSocket(&destination->addr); + destination->interval = interval; + + SCH_AddTimeoutInClass(destination->interval, SAMPLING_SEPARATION, SAMPLING_RANDOMNESS, + SCH_NtpBroadcastClass, broadcast_timeout, + (void *)(long)(ARR_GetSize(broadcasts) - 1)); +} diff --git a/ntp_core.h b/ntp_core.h index 50c2f41..104a704 100644 --- a/ntp_core.h +++ b/ntp_core.h @@ -104,4 +104,6 @@ extern NTP_Remote_Address *NCR_GetRemoteAddress(NCR_Instance instance); extern int NCR_IsSyncPeer(NCR_Instance instance); +extern void NCR_AddBroadcastDestination(IPAddr *addr, unsigned short port, int interval); + #endif /* GOT_NTP_CORE_H */ diff --git a/stubs.c b/stubs.c index a7f9604..aafd6d2 100644 --- a/stubs.c +++ b/stubs.c @@ -27,7 +27,6 @@ #include "config.h" -#include "broadcast.h" #include "clientlog.h" #include "cmdmon.h" #include "keys.h" @@ -89,17 +88,7 @@ MNL_Finalise(void) #ifndef FEAT_NTP void -BRD_Initialise(void) -{ -} - -void -BRD_Finalise(void) -{ -} - -void -BRD_AddDestination(IPAddr *addr, unsigned short port, int interval) +NCR_AddBroadcastDestination(IPAddr *addr, unsigned short port, int interval) { }