Skip to content
Commits on Source (21)
......@@ -117,7 +117,6 @@ extern int32_t ntp_random (void);
typedef struct __endpt {
struct __endpt *elink; /* endpt list link */
SOCKET fd; /* socket descriptor */
SOCKET bfd; /* for receiving broadcasts */
uint32_t ifnum; /* endpt instance count */
sockaddr_u sin; /* unicast address */
sockaddr_u mask; /* subnet mask */
......@@ -145,13 +144,13 @@ typedef struct __endpt {
#define INT_PPP 0x002 /* Point-to-point interface */
#define INT_LOOPBACK 0x004U /* the loopback interface */
#define INT_BROADCAST 0x008 /* can broadcast out this interface */
#define INT_MULTICAST 0x010 /* can multicast out this interface */
/* #define INT_MULTICAST 0x010 ** can multicast out this interface */
#define INT_BCASTOPEN 0x020U /* broadcast receive socket is open */
#define INT_MCASTOPEN 0x040 /* multicasting enabled */
/* #define INT_MCASTOPEN 0x040 ** multicasting enabled */
#define INT_WILDCARD 0x080 /* wildcard interface - usually skipped */
#define INT_MCASTIF 0x100 /* bound directly to MCAST address */
#define INT_PRIVACY 0x200 /* RFC 4941 IPv6 privacy address */
#define INT_BCASTXMIT 0x400 /* socket setup to allow broadcasts */
/* #define INT_BCASTXMIT 0x400 ** socket setup to allow broadcasts */
/*
* Read-only control knobs for a peer structure.
......@@ -604,7 +603,6 @@ struct mon_data {
int count; /* total packet count */
unsigned short flags; /* restrict flags */
uint8_t vn_mode; /* packet mode & version */
uint8_t cast_flags; /* flags MDF_?CAST */
sockaddr_u rmtadr; /* address of remote host */
};
......@@ -614,7 +612,7 @@ struct mon_data {
*/
#define MDF_UCAST 0x01 /* unicast client */
/* #define MDF_MCAST 0x02 ** multicast server (not used) */
#define MDF_BCAST 0x04 /* broadcast server */
/* #define MDF_BCAST 0x04 ** broadcast server (not used) */
#define MDF_POOL 0x08 /* pool client solicitor */
/* #define MDF_ACAST 0x10 ** manycast client solicitor (not used) */
#define MDF_BCLNT 0x20 /* eph. broadcast/multicast client */
......@@ -622,9 +620,9 @@ struct mon_data {
/*
* In the context of struct peer in ntpd, one cast_flags bit
* represent configured associations which never receive packets, and
* whose reach is always 0: MDF_BCAST
* whose reach is always 0: MDF_BCAST (Historical)
*/
#define MDF_TXONLY_MASK (MDF_BCAST | MDF_POOL)
#define MDF_TXONLY_MASK (MDF_POOL)
/*
* manycastclient-like solicitor association cast_flags bits
*/
......
......@@ -89,11 +89,9 @@ extern endpt * getinterface (sockaddr_u *, uint32_t);
extern endpt * select_peerinterface (struct peer *, sockaddr_u *,
endpt *);
extern endpt * findinterface (sockaddr_u *);
extern void enable_broadcast (endpt *, sockaddr_u *);
extern void interface_update (interface_receiver_t, void *);
extern void io_handler (void);
extern void init_io (void);
extern SOCKET open_socket (sockaddr_u *, bool, bool, endpt *);
extern void io_open_sockets (void);
extern void io_clr_stats (void);
extern void sendpkt (sockaddr_u *, endpt *, void *, int);
......
......@@ -38,7 +38,6 @@ struct recvbuf {
sockaddr_u srcadr; /* where packet came from */
endpt * dstadr; /* address pkt arrived on */
SOCKET fd; /* fd on which it was received */
int cast_flags; /* unicast/broadcast/manycast mode */
l_fp recv_time; /* time of arrival */
void (*receiver)(struct recvbuf *); /* callback */
size_t recv_length; /* number of octets received */
......
......@@ -187,7 +187,6 @@ struct key_tok ntp_keywords[] = {
{ "huffpuff", T_Huffpuff, FOLLBY_TOKEN },
{ "freq", T_Freq, FOLLBY_TOKEN },
/* miscellaneous_command */
{ "port", T_Port, FOLLBY_TOKEN },
{ "interface", T_Interface, FOLLBY_TOKEN },
/* interface_command (ignore and interface already defined) */
{ "nic", T_Nic, FOLLBY_TOKEN },
......
......@@ -110,6 +110,7 @@ unsigned int sys_ifnum; /* next .ifnum to assign */
static int ninterfaces; /* total # of interfaces */
bool disable_dynamic_updates; /* if true, scan interfaces once only */
extern SOCKET open_socket (sockaddr_u *, bool, endpt *);
static bool
netaddr_eqprefix(const isc_netaddr_t *, const isc_netaddr_t *,
......@@ -214,10 +215,6 @@ static bool addr_eqprefix (const sockaddr_u *, const sockaddr_u *,
int);
static int create_sockets (unsigned short);
static void set_reuseaddr (int);
static bool socket_broadcast_enable (endpt *, SOCKET, sockaddr_u *);
#ifdef OS_MISSES_SPECIFIC_ROUTE_UPDATES
static bool socket_broadcast_disable (endpt *, sockaddr_u *);
#endif
typedef struct remaddr remaddr_t;
......@@ -243,7 +240,6 @@ static void add_addr_to_list (sockaddr_u *, endpt *);
static void create_wildcards (unsigned short);
static endpt * findlocalinterface (sockaddr_u *, int, int);
static endpt * findclosestinterface (sockaddr_u *, int);
static endpt * findbcastinter (sockaddr_u *);
#ifdef DEBUG
static const char * action_text (nic_rule_action);
......@@ -424,7 +420,6 @@ interface_dump(const endpt *itf)
{
printf("Dumping interface: %p\n", itf);
printf("fd = %d\n", itf->fd);
printf("bfd = %d\n", itf->bfd);
printf("sin = %s,\n", socktoa(&itf->sin));
sockaddr_dump(&itf->sin);
printf("bcast = %s,\n", socktoa(&itf->bcast));
......@@ -469,12 +464,11 @@ sockaddr_dump(const sockaddr_u *psau)
static void
print_interface(const endpt *iface, const char *pfx, const char *sfx)
{
printf("%sinterface #%u: fd=%d, bfd=%d, name=%s, "
printf("%sinterface #%u: fd=%d, name=%s, "
"flags=0x%x, ifindex=%u, sin=%s",
pfx,
iface->ifnum,
iface->fd,
iface->bfd,
iface->name,
iface->flags,
iface->ifindex,
......@@ -736,7 +730,6 @@ init_interface(
{
ZERO(*ep);
ep->fd = INVALID_SOCKET;
ep->bfd = INVALID_SOCKET;
ep->phase = sys_interphase;
}
......@@ -828,16 +821,6 @@ remove_interface(
ep->fd = INVALID_SOCKET;
}
if (ep->bfd != INVALID_SOCKET) {
msyslog(LOG_INFO,
"IO: stop listening for broadcasts to %s "
"on interface #%u %s",
socktoa(&ep->bcast), ep->ifnum, ep->name);
close_and_delete_fd_from_list(ep->bfd);
ep->bfd = INVALID_SOCKET;
ep->flags &= ~INT_BCASTOPEN;
}
ninterfaces--;
mon_clearinterface(ep);
......@@ -911,7 +894,7 @@ create_wildcards(
wildif->flags = INT_UP | INT_WILDCARD;
wildif->ignore_packets = (ACTION_DROP == action);
wildif->fd = open_socket(&wildif->sin, 0, 1, wildif);
wildif->fd = open_socket(&wildif->sin, true, wildif);
if (wildif->fd != INVALID_SOCKET) {
wildipv6 = wildif;
......@@ -953,7 +936,7 @@ create_wildcards(
wildif->flags = INT_BROADCAST | INT_UP | INT_WILDCARD;
wildif->ignore_packets = (ACTION_DROP == action);
wildif->fd = open_socket(&wildif->sin, 0, 1, wildif);
wildif->fd = open_socket(&wildif->sin, true, wildif);
if (wildif->fd != INVALID_SOCKET) {
wildipv4 = wildif;
......@@ -1270,18 +1253,11 @@ refresh_interface(
{
#ifdef OS_MISSES_SPECIFIC_ROUTE_UPDATES
if (interface->fd != INVALID_SOCKET) {
int bcast = (interface->flags & INT_BCASTXMIT) != 0;
/* as we forcibly close() the socket remove the
broadcast permission indication */
if (bcast)
socket_broadcast_disable(interface, &interface->sin);
close_and_delete_fd_from_list(interface->fd);
/* create new socket picking up a new first hop binding
at connect() time */
interface->fd = open_socket(&interface->sin,
bcast, 0, interface);
interface->fd = open_socket(&interface->sin, false, interface);
/*
* reset TTL indication so TTL is is set again
* next time around
......@@ -1784,18 +1760,12 @@ create_interface(
/*
* create socket
*/
iface->fd = open_socket(&iface->sin, 0, 0, iface);
iface->fd = open_socket(&iface->sin, false, iface);
if (iface->fd != INVALID_SOCKET)
log_listen_address(iface);
if ((INT_BROADCAST & iface->flags)
&& iface->bfd != INVALID_SOCKET)
msyslog(LOG_INFO, "IO: Listening on broadcast address %s#%d",
socktoa((&iface->bcast)), port);
if (INVALID_SOCKET == iface->fd
&& INVALID_SOCKET == iface->bfd) {
if (INVALID_SOCKET == iface->fd) {
msyslog(LOG_ERR, "IO: unable to create socket on %s (%u) for %s#%d",
iface->name,
iface->ifnum,
......@@ -1889,78 +1859,6 @@ set_reuseaddr(
#endif /* ! SO_EXCLUSIVEADDRUSE */
}
/*
* This is just a wrapper around an internal function so we can
* make other changes as necessary later on
*/
void
enable_broadcast(
endpt * iface,
sockaddr_u * baddr
)
{
#ifdef OPEN_BCAST_SOCKET
socket_broadcast_enable(iface, iface->fd, baddr);
#endif
}
#ifdef OPEN_BCAST_SOCKET
/*
* Enable a broadcast address to a given socket
* The socket is in the ep_list all we need to do is enable
* broadcasting. It is not this function's job to select the socket
*/
static bool
socket_broadcast_enable(
endpt * iface,
SOCKET fd,
sockaddr_u * baddr
)
{
int on = 1;
if (IS_IPV4(baddr)) {
/* if this interface can support broadcast, set SO_BROADCAST */
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST,
(char *)&on, sizeof(on)))
msyslog(LOG_ERR,
"IO: setsockopt(SO_BROADCAST) enable failure on address %s: %m",
socktoa(baddr));
else
DPRINT(2, ("Broadcast enabled on socket %d for address %s\n",
fd, socktoa(baddr)));
}
iface->flags |= INT_BCASTXMIT;
return true;
}
#ifdef OS_MISSES_SPECIFIC_ROUTE_UPDATES
/*
* Remove a broadcast address from a given socket
* The socket is in the ep_list all we need to do is disable
* broadcasting. It is not this function's job to select the socket
*/
static bool
socket_broadcast_disable(
endpt * iface,
sockaddr_u * baddr
)
{
int off = 0; /* This seems to be OK as an int */
if (IS_IPV4(baddr) && setsockopt(iface->fd, SOL_SOCKET,
SO_BROADCAST, (char *)&off, sizeof(off)))
msyslog(LOG_ERR,
"IO: setsockopt(SO_BROADCAST) disable failure on address %s: %m",
socktoa(baddr));
iface->flags &= ~INT_BCASTXMIT;
return true;
}
#endif /* OS_MISSES_SPECIFIC_ROUTE_UPDATES */
#endif /* OPEN_BCAST_SOCKET */
/*
* open_socket - open a socket, returning the file descriptor
*/
......@@ -1968,7 +1866,6 @@ socket_broadcast_disable(
SOCKET
open_socket(
sockaddr_u * addr,
bool bcast,
bool turn_off_reuse,
endpt * interf
)
......@@ -2051,8 +1948,6 @@ open_socket(
"IO: setsockopt IP_TOS (%02x) fails on "
"address %s: %m",
(unsigned)qos, socktoa(addr));
if (bcast)
socket_broadcast_enable(interf, fd, addr);
}
/*
......@@ -2234,7 +2129,6 @@ read_refclock_packet(
rb->recv_length = (size_t)buflen;
rb->recv_peer = rp->srcclock;
rb->dstadr = 0;
rb->cast_flags = 0;
rb->fd = fd;
rb->recv_time = ts;
rb->receiver = rp->clock_recv;
......@@ -2369,7 +2263,6 @@ read_network_packet(
* put it on the full list and do bookkeeping.
*/
rb->dstadr = itf;
rb->cast_flags = (uint8_t)(rb->fd == rb->dstadr->bfd ? MDF_BCAST : MDF_UCAST);
rb->fd = fd;
ts = fetch_packetstamp(rb, &msghdr, ts);
rb->recv_time = ts;
......@@ -2441,7 +2334,6 @@ input_handler(
)
{
int buflen;
int doing;
SOCKET fd;
l_fp ts; /* Timestamp at BOselect() gob */
#ifdef ENABLE_DEBUG_TIMING
......@@ -2516,24 +2408,12 @@ input_handler(
* Loop through the interfaces looking for data to read.
*/
for (ep = ep_list; ep != NULL; ep = ep->elink) {
for (doing = 0; doing < 2; doing++) {
if (!doing) {
fd = ep->fd;
} else {
if (!(ep->flags & INT_BCASTOPEN))
break;
fd = ep->bfd;
}
if (fd < 0)
continue;
if (FD_ISSET(fd, fds))
do {
++select_count;
buflen = read_network_packet(
fd, ep, ts);
} while (buflen > 0);
/* Check more interfaces */
}
fd = ep->fd;
if (FD_ISSET(fd, fds))
do {
++select_count;
buflen = read_network_packet(fd, ep, ts);
} while (buflen > 0);
}
#ifdef USE_ROUTING_SOCKET
......@@ -2597,6 +2477,11 @@ select_peerinterface(
endpt *ep;
endpt *wild;
#ifndef REFCLOCK
UNUSED_ARG(peer);
#endif
wild = ANY_INTERFACE_CHOOSE(srcadr);
/*
......@@ -2609,14 +2494,6 @@ select_peerinterface(
*/
if (IS_PEER_REFCLOCK(peer)) {
ep = loopback_interface;
} else if (peer->cast_flags & MDF_BCAST) {
ep = findbcastinter(srcadr);
if (ep != NULL)
DPRINT(4, ("Found *-cast interface %s for address %s\n",
socktoa(&ep->sin), socktoa(srcadr)));
else
DPRINT(4, ("No *-cast local address found for address %s\n",
socktoa(srcadr)));
} else {
ep = dstadr;
if (NULL == ep)
......@@ -2920,88 +2797,6 @@ getinterface(
return iface;
}
/*
* findbcastinter - find broadcast interface corresponding to address
*/
static endpt *
findbcastinter(
sockaddr_u *addr
)
{
endpt * iface;
iface = NULL;
#if defined(SIOCGIFCONF)
DPRINT(4, ("Finding broadcast interface for addr %s in list of addresses\n",
socktoa(addr)));
iface = findlocalinterface(addr, INT_LOOPBACK | INT_WILDCARD,
1);
if (iface != NULL) {
DPRINT(4, ("Easily found bcast-/mcast- interface index #%d %s\n",
iface->ifnum, iface->name));
return iface;
}
/*
* plan B - try to find something reasonable in our lists in
* case kernel lookup doesn't help
*/
for (iface = ep_list; iface != NULL; iface = iface->elink) {
if (iface->flags & INT_WILDCARD)
continue;
/* Don't bother with ignored interfaces */
if (iface->ignore_packets)
continue;
/*
* First look if this is the correct family
*/
if(AF(&iface->sin) != AF(addr))
continue;
/* Skip the loopback addresses */
if (iface->flags & INT_LOOPBACK)
continue;
/*
* We match only those interfaces marked as
* broadcastable and either the explicit broadcast
* address or the network portion of the IP address.
* Sloppy.
*/
if (IS_IPV4(addr)) {
if (SOCK_EQ(&iface->bcast, addr))
break;
if ((NSRCADR(&iface->sin) & NSRCADR(&iface->mask))
== (NSRCADR(addr) & NSRCADR(&iface->mask)))
break;
}
else if (IS_IPV6(addr)) {
if (SOCK_EQ(&iface->bcast, addr))
break;
if (SOCK_EQ(netof6(&iface->sin), netof6(addr)))
break;
}
}
#endif /* SIOCGIFCONF */
if (NULL == iface) {
DPRINT(4, ("No bcast interface found for %s\n",
socktoa(addr)));
iface = ANY_INTERFACE_CHOOSE(addr);
} else {
DPRINT(4, ("Found bcast-/mcast- interface index #%u %s\n",
iface->ifnum, iface->name));
}
return iface;
}
/*
* io_clr_stats - clear I/O module statistics
*/
......
......@@ -464,7 +464,6 @@ ntp_monitor(
memcpy(&mon->rmtadr, &rbufp->recv_srcadr, sizeof(mon->rmtadr));
mon->vn_mode = VN_MODE(version, mode);
mon->lcladr = rbufp->dstadr;
mon->cast_flags = rbufp->cast_flags;
/*
* Drop him into front of the hash table. Also put him on top of
......
......@@ -71,7 +71,7 @@
%token <Integer> T_Disable
%token <Integer> T_Discard
%token <Integer> T_Dispersion
%token <Double> T_Double /* not a token */
%token <Double> T_Double /* Not a token */
%token <Integer> T_Driftfile
%token <Integer> T_Drop
%token <Integer> T_Dscp
......@@ -99,9 +99,9 @@
%token <Integer> T_Initalloc
%token <Integer> T_Initmem
%token <Integer> T_Includefile
%token <Integer> T_Integer /* not a token */
%token <Integer> T_Integer /* Not a token, used as tag */
%token <Integer> T_Interface
%token <Integer> T_Intrange /* not a token */
%token <Integer> T_Intrange /* Not a token, used as tag */
%token <Integer> T_Io
%token <Integer> T_Ipv4
%token <Integer> T_Ipv4_flag
......@@ -168,7 +168,6 @@
%token <Integer> T_Pidfile
%token <Integer> T_Pool
%token <Integer> T_Ppspath
%token <Integer> T_Port
%token <Integer> T_Prefer
%token <Integer> T_Protostats
%token <Integer> T_Rawstats
......@@ -192,7 +191,7 @@
%token <Integer> T_Stepout
%token <Integer> T_Stratum
%token <Integer> T_Subtype
%token <String> T_String /* not a token */
%token <String> T_String /* Not a token */
%token <Integer> T_Sys
%token <Integer> T_Sysstats
%token <Integer> T_Tick
......@@ -202,7 +201,6 @@
%token <Integer> T_Timingstats
%token <Integer> T_Tinker
%token <Integer> T_Tos
%token <Integer> T_Trap
%token <Integer> T_True
%token <Integer> T_Trustedkey
%token <Integer> T_Type
......@@ -213,11 +211,11 @@
%token <Integer> T_Unrestrict
%token <Integer> T_Usestats
%token <Integer> T_Version
%token <Integer> T_WanderThreshold /* Not a token */
%token <Integer> T_WanderThreshold /* Not a token, used as tag */
%token <Integer> T_Week
%token <Integer> T_Wildcard
%token <Integer> T_Year
%token <Integer> T_Flag /* Not a token */
%token <Integer> T_Flag /* Not a token, used as tag */
%token <Integer> T_EOC
/*** NON-TERMINALS ***/
......@@ -501,7 +499,6 @@ unpeer_keyword
/* Other Modes
* (manycastserver)
* ------------------------------------------------
*/
......
......@@ -490,8 +490,8 @@ peer_refresh_interface(
p->cfg.mode, p->cfg.peerkey));
if (niface != NULL) {
DPRINT(4, (
"fd=%d, bfd=%d, name=%.16s, flags=0x%x, ifindex=%u, sin=%s",
niface->fd, niface->bfd, niface->name,
"fd=%d, name=%.16s, flags=0x%x, ifindex=%u, sin=%s",
niface->fd, niface->name,
niface->flags, niface->ifindex,
socktoa(&niface->sin)));
if (niface->flags & INT_BROADCAST)
......@@ -654,12 +654,6 @@ newpeer(
DPRINT(3, ("newpeer(%s): local interface currently not bound\n",
socktoa(srcadr)));
/*
* Broadcast needs the socket enabled for broadcast
*/
if ((MDF_BCAST & cast_flags) && peer->dstadr != NULL)
enable_broadcast(peer->dstadr, srcadr);
/* if a key specified, verify that it will work */
if (0 != peer->cfg.peerkey) {
if (NULL == authlookup(peer->cfg.peerkey, false))
......@@ -674,8 +668,6 @@ newpeer(
peer->hpoll = peer->cfg.minpoll;
if (cast_flags & MDF_POOL)
peer_clear(peer, "POOL", initializing1);
else if (cast_flags & MDF_BCAST)
peer_clear(peer, "BCST", initializing1);
else
peer_clear(peer, "INIT", initializing1);
if (clock_ctl.mode_ntpdate)
......
......@@ -796,18 +796,6 @@ transmit(
*/
hpoll = peer->hpoll;
/*
* In broadcast mode the poll interval is never changed from
* minpoll.
*/
if (peer->cast_flags & MDF_BCAST) {
peer->outdate = current_time;
if (sys_vars.sys_leap != LEAP_NOTINSYNC)
peer_xmit(peer);
poll_update(peer, hpoll);
return;
}
/*
* Pool associations transmit unicast solicitations when there
* are less than a hard limit of 2 * sys_maxclock associations,
......
......@@ -128,9 +128,25 @@ TEST(calendar, parse_to_unixtime) {
}
#endif
// test the NTP to Unix time conversion
TEST(calendar, PeriodicExtend1) {
// Test positive cycle, pivot > value
TEST_ASSERT_EQUAL(1001, ntpcal_periodic_extend(1000, 5, 2));
// Test positive cycle, pivot < value
TEST_ASSERT_EQUAL(6, ntpcal_periodic_extend(5, 1000, 2));
// Test negative cycle, pivot > value
TEST_ASSERT_EQUAL(999, ntpcal_periodic_extend(1000, 5, -2));
// Test negative cycle, pivot < value
TEST_ASSERT_EQUAL(4, ntpcal_periodic_extend(5, 1000, -2));
}
// test the NTP to 64-bit Unix scale time conversion
TEST(calendar, NtpToTime1) {
TEST_ASSERT_EQUAL(2085978538, ntpcal_ntp_to_time(42, 23));
TEST_ASSERT_EQUAL(2085978538, ntpcal_ntp_to_time(42, 23));
}
// test the NTP to 64-bit NTP scale time conversion
TEST(calendar, NtpToNtp1) {
TEST_ASSERT_EQUAL(4294967338, ntpcal_ntp_to_ntp(42, 23));
}
// test the day/sec join & split ops, making sure that 32bit
......@@ -162,6 +178,37 @@ TEST(calendar, DaySplitMerge) {
}
}
TEST(calendar, SplitEraDays1) {
ntpcal_split res;
int32_t isleapyear = 42;
// Test no flag, no-leap, positive
res = ntpcal_split_eradays(4, NULL);
TEST_ASSERT_EQUAL(0, res.hi);
TEST_ASSERT_EQUAL(4, res.lo);
TEST_ASSERT_EQUAL(42, isleapyear);
// Test flag, no-leap, positive
res = ntpcal_split_eradays(4, &isleapyear);
TEST_ASSERT_EQUAL(0, res.hi);
TEST_ASSERT_EQUAL(4, res.lo);
TEST_ASSERT_EQUAL(0, isleapyear);
// Test flag, leap, positive
res = ntpcal_split_eradays(1400, &isleapyear);
TEST_ASSERT_EQUAL(3, res.hi);
TEST_ASSERT_EQUAL(305, res.lo);
TEST_ASSERT_EQUAL(1, isleapyear);
isleapyear = 0;
// Test flag, leap, negative
res = ntpcal_split_eradays(-100, &isleapyear);
TEST_ASSERT_EQUAL(-1, res.hi);
TEST_ASSERT_EQUAL(266, res.lo);
TEST_ASSERT_EQUAL(1, isleapyear);
}
TEST(calendar, SplitYearDays1) {
int32_t eyd;
......@@ -201,6 +248,84 @@ TEST(calendar, RataDie1) {
TEST_ASSERT_TRUE(IsEqualDate(&expected, &actual));
}
TEST(calendar, DaysecToDate1) {
struct calendar cal;
int32_t days;
// Test normal date
days = ntpcal_daysec_to_date(&cal, 100000);
TEST_ASSERT_EQUAL(days, 1);
TEST_ASSERT_EQUAL(cal.hour, 3);
TEST_ASSERT_EQUAL(cal.minute, 46);
TEST_ASSERT_EQUAL(cal.second, 40);
// Test negative date
days = ntpcal_daysec_to_date(&cal, -100000);
TEST_ASSERT_EQUAL(-2, days);
TEST_ASSERT_EQUAL(20, cal.hour);
TEST_ASSERT_EQUAL(13, cal.minute);
TEST_ASSERT_EQUAL(20, cal.second);
}
TEST(calendar, TimeToDate1) {
struct calendar jd = {0, 0, 0, 0, 0, 0, 0, 0};
int res;
res = ntpcal_time_to_date(&jd, 1000000);
TEST_ASSERT_EQUAL(0, res);
TEST_ASSERT_EQUAL(1970, jd.year);
TEST_ASSERT_EQUAL(12, jd.yearday);
TEST_ASSERT_EQUAL(1, jd.month);
TEST_ASSERT_EQUAL(12, jd.monthday);
TEST_ASSERT_EQUAL(13, jd.hour);
TEST_ASSERT_EQUAL(46, jd.minute);
TEST_ASSERT_EQUAL(40, jd.second);
TEST_ASSERT_EQUAL(1, jd.weekday);
}
TEST(calendar, DayJoin1) {
TEST_ASSERT_EQUAL(4323600, ntpcal_dayjoin(50, 3600));
}
TEST(calendar, DaysInYears1) {
// Test positive less than one gregorian cycle of years
TEST_ASSERT_EQUAL(109572, ntpcal_days_in_years(300));
// Test positive one gregorian cycle of years
TEST_ASSERT_EQUAL(146097, ntpcal_days_in_years(400));
// Test positive greater than one gregorian cycle of years
TEST_ASSERT_EQUAL(182621, ntpcal_days_in_years(500));
// Test negative less than one gregorian cycle of years
TEST_ASSERT_EQUAL(-109573, ntpcal_days_in_years(-300));
// Test negative one gregorian cycle of years
TEST_ASSERT_EQUAL(-146097, ntpcal_days_in_years(-400));
// Test negative greater than one gregorian cycle of years
TEST_ASSERT_EQUAL(-182622, ntpcal_days_in_years(-500));
}
TEST(calendar, EdateToEradays1) {
// Test positive, no months
TEST_ASSERT_EQUAL(1827, ntpcal_edate_to_eradays(5, 0, 1));
// Test positive, with months
TEST_ASSERT_EQUAL(1917, ntpcal_edate_to_eradays(5, 3, 1));
// Test negative, no months
TEST_ASSERT_EQUAL(-1828, ntpcal_edate_to_eradays(-5, 0, -1));
// Test negative, with months
TEST_ASSERT_EQUAL(-1920, ntpcal_edate_to_eradays(-5, -3, -1));
}
TEST(calendar, EtimeToSeconds1) {
TEST_ASSERT_EQUAL(18181, ntpcal_etime_to_seconds(5, 3, 1));
}
TEST(calendar, TmToRd1) {
struct tm utm;
utm.tm_year = 10;
utm.tm_mon = 5;
utm.tm_mday = 1;
TEST_ASSERT_EQUAL(697399, ntpcal_tm_to_rd(&utm));
}
// check last day of february for first 10000 years
TEST(calendar, LeapYears1) {
struct calendar dateIn, dateOut;
......@@ -263,6 +388,60 @@ TEST(calendar, RoundTripDate) {
}
}
TEST(calendar, DateToDaysec1) {
struct calendar jd;
jd.hour = 18;
jd.minute = 45;
jd.second = 15;
TEST_ASSERT_EQUAL(67515, ntpcal_date_to_daysec(&jd));
}
TEST(calendar, TmToDaysec1) {
struct tm utm;
utm.tm_hour = 18;
utm.tm_min = 45;
utm.tm_sec = 15;
TEST_ASSERT_EQUAL(67515, ntpcal_tm_to_daysec(&utm));
}
TEST(calendar, DateToTime1) {
struct calendar jd;
jd.year = 2000;
jd.month = 2;
jd.monthday = 4;
jd.hour = 8;
jd.minute = 16;
jd.second = 32;
TEST_ASSERT_EQUAL(949652192, ntpcal_date_to_time(&jd));
}
TEST(calendar, Ntp64ToDate1) {
struct calendar jd;
TEST_ASSERT_EQUAL(0, ntpcal_ntp64_to_date(&jd, 10000000));
TEST_ASSERT_EQUAL(1900, jd.year);
TEST_ASSERT_EQUAL(4, jd.month);
TEST_ASSERT_EQUAL(26, jd.monthday);
TEST_ASSERT_EQUAL(17, jd.hour);
TEST_ASSERT_EQUAL(46, jd.minute);
TEST_ASSERT_EQUAL(40, jd.second);
}
TEST(calendar, NtpToDate1) {
struct calendar jd;
TEST_ASSERT_EQUAL(1, ntpcal_ntp_to_date(&jd, 86400, 1000000));
TEST_ASSERT_EQUAL(2036, jd.year);
TEST_ASSERT_EQUAL(2, jd.month);
TEST_ASSERT_EQUAL(8, jd.monthday);
TEST_ASSERT_EQUAL(6, jd.hour);
TEST_ASSERT_EQUAL(28, jd.minute);
TEST_ASSERT_EQUAL(16, jd.second);
}
TEST_GROUP_RUNNER(calendar) {
RUN_TEST_CASE(calendar, is_leapyear);
......@@ -271,12 +450,27 @@ TEST_GROUP_RUNNER(calendar) {
#ifdef CLOCK_GENERIC
RUN_TEST_CASE(calendar, parse_to_unixtime);
#endif
RUN_TEST_CASE(calendar, PeriodicExtend1);
RUN_TEST_CASE(calendar, NtpToTime1);
RUN_TEST_CASE(calendar, NtpToNtp1);
RUN_TEST_CASE(calendar, DaySplitMerge);
RUN_TEST_CASE(calendar, DaysecToDate1);
RUN_TEST_CASE(calendar, SplitEraDays1);
RUN_TEST_CASE(calendar, SplitYearDays1);
RUN_TEST_CASE(calendar, SplitYearDays2);
RUN_TEST_CASE(calendar, RataDie1);
RUN_TEST_CASE(calendar, TimeToDate1);
RUN_TEST_CASE(calendar, DayJoin1);
RUN_TEST_CASE(calendar, DaysInYears1);
RUN_TEST_CASE(calendar, EdateToEradays1);
RUN_TEST_CASE(calendar, EtimeToSeconds1);
RUN_TEST_CASE(calendar, TmToRd1);
RUN_TEST_CASE(calendar, LeapYears1);
RUN_TEST_CASE(calendar, LeapYears2);
RUN_TEST_CASE(calendar, RoundTripDate);
RUN_TEST_CASE(calendar, DateToDaysec1);
RUN_TEST_CASE(calendar, TmToDaysec1);
RUN_TEST_CASE(calendar, DateToTime1);
RUN_TEST_CASE(calendar, Ntp64ToDate1);
RUN_TEST_CASE(calendar, NtpToDate1);
}
......@@ -19,6 +19,14 @@ TEST_TEAR_DOWN(prettydate) {}
static const uint32_t HALF = 2147483648UL;
TEST(prettydate, Rfc3339Date1) {
TEST_ASSERT_EQUAL_STRING("2036-02-07T06:28:16.000Z", rfc3339date(0));
}
TEST(prettydate, Rfc3339Time1) {
TEST_ASSERT_EQUAL_STRING("2036-02-07T06:28:16.000Z", rfc3339date(0));
}
TEST(prettydate, ConstantDate) {
l_fp t = lfpinit((int32_t)3485080800LL, HALF); // 2010-06-09 14:00:00.5
......@@ -27,4 +35,6 @@ TEST(prettydate, ConstantDate) {
TEST_GROUP_RUNNER(prettydate) {
RUN_TEST_CASE(prettydate, ConstantDate);
RUN_TEST_CASE(prettydate, Rfc3339Date1);
RUN_TEST_CASE(prettydate, Rfc3339Time1);
}
......@@ -596,10 +596,6 @@ int main(int argc, char **argv) {
for header, sizeof in sorted(sizeofs, key=lambda x: x[1:]):
check_sizeof(ctx, header, sizeof)
# These are helpful and don't break Linux or *BSD
ctx.define("OPEN_BCAST_SOCKET", 1,
comment="Whether to open a broadcast socket")
# Check via pkg-config first, then fall back to a direct search
if not ctx.check_cfg(
package='libcrypto', uselib_store='CRYPTO',
......