Lines Matching +full:test2 +full:. +full:good

2  * ntp_proto.c - NTP version 4 protocol machinery
5 * (Harlan will be discussing these changes with Dave Mills.)
9 #include <config.h>
12 #include "ntpd.h"
13 #include "ntp_stdlib.h"
14 #include "ntp_unixtime.h"
15 #include "ntp_control.h"
16 #include "ntp_string.h"
17 #include "ntp_leapsec.h"
18 #include "ntp_psl.h"
19 #include "refidsmear.h"
21 #include <stdio.h>
23 #include <libscf.h>
26 #include <unistd.h>
37 x.l_uf = 0; \
38 x.l_ui &= ~((1 << SRVFUZ_SHIFT) - 1U); \
42 * This macro defines the authentication state. If x is 1 authentication
43 * is required; otherwise it is optional.
95 * clock_cluster().
105 * System variables are declared here. Unless specified otherwise, all
106 * times are in seconds.
130 * Rate controls. Leaky buckets are used to throttle the packet
132 * and USNO. There is a counter for each association and another for KoD
133 * packets. The association counter decrements each second, but not
134 * below zero. Each time a packet is sent the counter is incremented by
136 * packets. A packet is delayed as long as the counter is greater than
137 * zero. Note this does not affect the time value computations.
179 * Statistics counters - first the good, then the bad
196 * The default way is "on-receipt". If this was a packet from a
197 * well-behaved source, on-receipt will offer the fastest recovery.
199 * for a bad-guy to DoS us. So look and see what bites you harder
200 * and choose according to your environment.
243 * eventually change xmt_leap below, but never change LEAP_NOTINSYNC. in set_sys_leap()
255 * so make sure we only send "in sync". in set_sys_leap()
257 if (leap_smear.enabled) in set_sys_leap()
348 * not (yet) be a keyid, but in this case FLAG_SKEY is set. in valid_NAK()
350 * if the keyid is 0 and FLAG_SKEY is not set. in valid_NAK()
357 * The ORIGIN must match, or this cannot be a valid NAK, either. in valid_NAK()
378 /* If we ever passed all that checks, we should be safe. Well, in valid_NAK()
379 * as safe as we can ever be with an unauthenticated crypto-nak. in valid_NAK()
396 * The polling state machine. There are two kinds of machines, in transmit()
398 * server modes) and those that do (all other modes). The dance in transmit()
399 * is intricate... in transmit()
405 * send, reset ppoll. in transmit()
412 * minpoll. in transmit()
423 * In manycast mode we start with unity ttl. The ttl is in transmit()
425 * servers have been found or the maximum ttl is reached. When in transmit()
428 * associations turn up. In this case additional better servers in transmit()
429 * are dragged in and preempt the existing ones. Once every in transmit()
433 * every sys_beacon polls. in transmit()
456 * sys_maxclock associations. The hard limit prevents unbounded in transmit()
458 * result in survivor count dipping below sys_minclock often. in transmit()
460 * resulted in 60 associations without the hard limit. A in transmit()
462 * may be appropriate. in transmit()
474 /* [Bug 3851] drop pool servers which can no longer be reached. */ in transmit()
484 * In unicast modes the dance is much more intricate. It is in transmit()
486 * traffic. in transmit()
492 * Update the reachability status. If not heard for in transmit()
494 * filter. in transmit()
503 * Here the peer is unreachable. If it was in transmit()
504 * previously reachable raise a trap. Send a in transmit()
505 * burst if enabled. in transmit()
507 clock_filter(peer, 0., 0., MAXDISPERSE); in transmit()
518 * Here the peer is reachable. Send a burst if in transmit()
519 * enabled and the peer is fit. Reset unreach in transmit()
520 * for persistent and ephemeral associations. in transmit()
522 * clock_select(). in transmit()
534 * Watch for timeout. If ephemeral, toss the rascal; in transmit()
535 * otherwise, bump the poll interval. Note the in transmit()
536 * poll_update() routine will clamp it to maxpoll. in transmit()
539 * demobilize. in transmit()
566 * we declare a successful failure. in transmit()
585 * Do not transmit if in broadcast client mode. in transmit()
669 * Note that there are many places we do not call record_raw_stats(). in receive()
672 * when we've decided to drop a packet. in receive()
676 * Monitor the packet and get restrictions. Note that the packet in receive()
678 * by the service routines. Some restrictions have to be handled in receive()
679 * later in order to generate a kiss-o'-death packet. in receive()
683 * reveals a clogging attack. Likewise the mimimum packet size in receive()
684 * of 2 bytes (for mode 6/7) must be checked first. in receive()
692 restrict_mask = r4a.rflags; in receive()
728 /* If we arrive here, we should have a standard NTP packet. We in receive()
731 * there. in receive()
743 "restrict %s org 0x%x.%08x xmt 0x%x.%08x\n", in receive()
745 stoa(&rbufp->recv_srcadr), r4a.ippeerlimit, hismode, in receive()
748 ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), in receive()
749 ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); in receive()
752 * This is for testing. If restricted drop ten percent of in receive()
753 * surviving packets. in receive()
756 if (ntp_uurandom() < .1) { in receive()
766 ** Validate the packet format. The packet size, packet header, in receive()
767 ** and any extension field lengths are checked. We identify in receive()
769 ** of the hash computation. in receive()
772 ** discarded with no further processing. in receive()
777 * intentionally use an early version. in receive()
791 * Figure out his mode and validate the packet. This has some in receive()
792 * legacy raunch that probably should be removed. In very early in receive()
794 * would interpret as client mode. in receive()
807 * Validate the poll interval in the packet. in receive()
808 * 0 probably indicates a data-minimized packet. in receive()
810 * a value of 0 is not allowed. We check for this below. in receive()
812 * There might be arguments against this check. If you have in receive()
813 * any of these arguments, please let us know. in receive()
815 * At this point, the packet cannot be a mode[67] packet. in receive()
834 * Parse the extension field if present. We figure out whether in receive()
835 * an extension field is present by measuring the MAC size. If in receive()
837 * is present and the packet is not authenticated. If 1, the in receive()
840 * the packet is authenticated with SHA. If 2 or * 4, the packet in receive()
841 * is a runt and discarded forthwith. If greater than 6, an in receive()
843 * field and go around again. in receive()
845 * Note the above description is lame. We should/could also check in receive()
847 * check the two bytes that tell us the EF length. A legacy MAC in receive()
849 * must be <= 64k, meaning the top two bytes will always be zero. in receive()
851 * conforming legacy MAC could ever be misinterpreted as an EF. in receive()
853 * There is more, but this isn't the place to document it. in receive()
890 * Extract calling group name for later. If in receive()
892 * a group name provided to elicit a response. in receive()
922 * If has_mac is < 0 we had a malformed packet. in receive()
933 ** This layer verifies the packet data content. If in receive()
934 ** authentication is required, a MAC must be present. in receive()
935 ** If a MAC is present, it must validate. in receive()
938 ** If authentication fails, we're done. in receive()
942 * If authentication is explicitly required, a MAC must be present. in receive()
951 * Update the MRU list and finger the cloggers. It can be a in receive()
952 * little expensive, so turn it off for production use. in receive()
954 * restrict_mask unless one or both actions are warranted. in receive()
983 * the game to reduce the exposure to a clogging attack. Now we in receive()
985 * authenticate the packet if required. Note that we burn only in receive()
986 * digest cycles, again to reduce exposure. There may be no in receive()
987 * matching association and that's okay. in receive()
989 * More on the autokey mambo. Normally the local interface is in receive()
991 * designated remote address. We assume packets arriving from in receive()
994 * of the interface. However, if the sender is a broadcaster, in receive()
995 * the interface broadcast address is used instead. in receive()
998 * unicast address anyway. Don't ask. in receive()
1022 * using the restrict command. The enable switch if on implies in receive()
1023 * NOPEER for all clients. There are four outcomes: in receive()
1025 * NONE The packet has no MAC. in receive()
1028 * CRYPTO crypto-NAK. The MAC has four octets only. in receive()
1030 * Note: The AUTH(x, y) macro is used to filter outcomes. If x in receive()
1031 * is zero, acceptable outcomes of y are NONE and OK. If x is in receive()
1032 * one, the only acceptable outcome of y is OK. in receive()
1052 DPRINTF(1, ("receive: at %ld %s<-%s mode %d/%s:%s len %d org 0x%x.%08x xmt 0x%x.%08x NOMAC\n", in receive()
1056 ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), in receive()
1057 ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); in receive()
1061 …ceive: at %ld %s<-%s mode %d/%s:%s keyid %08x len %d auth %d org 0x%x.%08x xmt 0x%x.%08x CRYPTONAK… in receive()
1065 ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), in receive()
1066 ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); in receive()
1073 * reply. in receive()
1076 * http://msdn.microsoft.com/en-us/library/cc212930.aspx in receive()
1084 DPRINTF(1, ("receive: at %ld %s<-%s mode %d/%s:%s len %d org %x.%08x xmt %x.%08x SIGND\n", in receive()
1088 ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), in receive()
1089 ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); in receive()
1098 * So there is a MAC here. in receive()
1105 * and install in the key cache. Use the socket in receive()
1106 * broadcast or unicast address as appropriate. in receive()
1111 * More on the autokey dance (AKD). A cookie is in receive()
1112 * constructed from public and private values. in receive()
1114 * (zero). For packets that match no in receive()
1116 * addresses and private value. For server in receive()
1118 * from the server. For symmetric modes, the in receive()
1122 * the EXOR of the peer and host cookies. in receive()
1147 * mobilized. However, if this is from in receive()
1148 * the wildcard interface, game over. in receive()
1171 * values and cookie. In case of an extension in receive()
1173 * purposes is zero. Note the hash is saved for in receive()
1174 * use later in the autokey mambo. in receive()
1192 * Compute the cryptosum. Note a clogging attack may in receive()
1193 * succeed in bloating the key cache. If an autokey, in receive()
1195 * again. If the packet is authentic, it can mobilize an in receive()
1196 * association. Note that there is no key zero. in receive()
1207 …"receive: at %ld %s<-%s mode %d/%s:%s keyid %08x len %d auth %d org 0x%x.%08x xmt 0x%x.%08x MAC\n", in receive()
1211 ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), in receive()
1212 ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); in receive()
1220 * - If we expect a MAC and it's not there, we drop it. in receive()
1221 * - If we expect one keyID and get another, we drop it. in receive()
1222 * - If we have a MAC ahd it hasn't been validated yet, try. in receive()
1223 * - if the provided MAC doesn't validate, we drop it. in receive()
1225 * There might be more to this. in receive()
1233 * - different keyID than what we expect. in receive()
1244 * if has_mac != 0 ... in receive()
1245 * - If it has not yet been validated, do so. in receive()
1247 * - if missing or bad MAC, log and drop. in receive()
1275 ** Verify protocol operations consistent with the on-wire protocol. in receive()
1278 ** packets. The operations are controlled by two timestamps: in receive()
1280 ** and the origin timestamp in the server packet header. The in receive()
1281 ** comparison of these two timestamps is called the loopback test. in receive()
1283 ** response corresponds to the original request. The transmit in receive()
1285 ** packet. Upon failure of either test, the packet is discarded in receive()
1286 ** with no further action. in receive()
1291 * routines and an association table. A packet matching an in receive()
1293 * association. If there are no errors, an ephemeral association in receive()
1297 * symmetric passive association. in receive()
1304 * This is a client mode packet not matching any association. If in receive()
1306 * over the fence. If a manycast client, we have to work a in receive()
1307 * little harder. in receive()
1309 * There are cases here where we do not call record_raw_stats(). in receive()
1315 * send a crypto-NAK. in receive()
1352 * This must be manycast. Do not respond if not in receive()
1353 * configured as a manycast server. in receive()
1363 * Do not respond if not the same group. in receive()
1375 * manycaster has already synchronized to us. in receive()
1395 * global address, to avoid duplicate associations. in receive()
1404 * Respond only if authentication succeeds. Don't do a in receive()
1405 * crypto-NAK, as that would not be useful. in receive()
1431 * manycastclient) or to a unicast address (for pool). The in receive()
1432 * origin timestamp is a good nonce to reliably associate the in receive()
1433 * reply with what was sent. If there is no match, that's in receive()
1435 * just ignore it. in receive()
1440 * association to the new client association. If not, just in receive()
1441 * ignore the packet. in receive()
1444 * the manycast servers send the server packet immediately. If in receive()
1445 * the guy is already here, don't fire up a duplicate. in receive()
1447 * There are cases here where we do not call record_raw_stats(). in receive()
1453 * Do not respond if not the same group. in receive()
1485 * the floor or at or above the ceiling. in receive()
1499 r4a.ippeerlimit, MODE_CLIENT, hisversion, in receive()
1512 * the pool will fill promptly. in receive()
1522 * first sync. in receive()
1527 * This is the first packet received from a broadcast server. If in receive()
1529 * client, mobilize a broadcast client association. We don't in receive()
1530 * kiss any frogs here. in receive()
1532 * There are cases here where we do not call record_raw_stats(). in receive()
1538 * Do not respond if not the same group. in receive()
1562 * the floor or at or above the ceiling. in receive()
1575 * CRYPTO_ASSOC response with association ID. in receive()
1588 * with the same remote address. newpeer() will not in receive()
1590 * if a non-NULL endpoint is supplied. multicastclient in receive()
1592 * endpoints. in receive()
1600 * Determine whether to execute the initial volley. in receive()
1606 * neither is Autokey. in receive()
1616 * Do not execute the volley. Start out in in receive()
1617 * broadcast client mode. in receive()
1620 r4a.ippeerlimit, MODE_BCLIENT, hisversion, in receive()
1637 * propagation delay and run the Autokey protocol. in receive()
1641 * is fixed at this value. in receive()
1644 r4a.ippeerlimit, MODE_CLIENT, hisversion, in receive()
1663 * symmetric active peer. First, deal with broken Windows clients. in receive()
1664 * Then, if NOEPEER is enabled, drop it. If the packet meets our in receive()
1666 * a passive association. in receive()
1667 * Otherwise, kiss the frog. in receive()
1669 * There are cases here where we do not call record_raw_stats(). in receive()
1677 * Do not respond if not the same group. in receive()
1691 * response without mobilizing an association. in receive()
1692 * This is for drat broken Windows clients. See in receive()
1693 * Microsoft KB 875424 for preferred workaround. in receive()
1721 * should just drop it on the floor. For example, in receive()
1723 * will make it this far. This is just in receive()
1725 * flooding. in receive()
1744 * below the floor or at or above the ceiling. Note, in receive()
1746 * us. It would be very strange if he did and then was in receive()
1748 * operating at the top end of the range. It also means in receive()
1750 * MODE_ACTIVE KoDs, which will time out eventually. in receive()
1761 * The message is correctly authenticated and allowed. in receive()
1763 * exceed the ippeerlimit. in receive()
1766 r4a.ippeerlimit, MODE_PASSIVE, hisversion, in receive()
1777 * Process regular packet. Nothing special. in receive()
1779 * There are cases here where we do not call record_raw_stats(). in receive()
1785 * Do not respond if not the same group. in receive()
1832 * packet was received. We limit the check to in receive()
1836 * denial of service condition. in receive()
1849 /* Alert if time from the server is non-monotonic. in receive()
1851 * [Bug 3114] is about Broadcast mode replay DoS. in receive()
1853 * Broadcast mode *assumes* a trusted network. in receive()
1855 * of attacks. in receive()
1861 * - the broadcast server had a backward step. in receive()
1863 * - somebody is trying a replay attack. in receive()
1867 * broadcast packets as we receive them. But in receive()
1869 * delays before believing a backward step. in receive()
1880 tdiff.l_ui = tdiff.l_uf = 0; in receive()
1885 if ( tdiff.l_i < 0 in receive()
1888 …INFO, "receive: broadcast packet from %s contains non-monotonic timestamp: 0x%x.%08x -> 0x%x.%08x", in receive()
1890 peer->bxmt.l_ui, peer->bxmt.l_uf, in receive()
1891 p_xmt.l_ui, p_xmt.l_uf in receive()
1907 * A passive packet matches a passive association. This is in receive()
1908 * usually the result of reconfiguring a client on the fly. As in receive()
1910 * attempt to deny service, just ignore it. in receive()
1913 DPRINTF(2, ("receive: AM_ERR drop.\n")); in receive()
1918 * For everything else there is the bit bucket. in receive()
1921 DPRINTF(2, ("receive: default drop.\n")); in receive()
1930 * symmetric key ID. in receive()
1949 * Next comes a rigorous schedule of timestamp checking. If the in receive()
1951 * interleaved modes or is horribly broken. in receive()
1954 * timestamp. in receive()
1962 peer->bogusorg++; /* for TEST2 or TEST3 */ in receive()
1971 * packet is a replay. This prevents the bad guys from replaying in receive()
1972 * the most recent packet, authenticated or not. in receive()
1984 * is appropriate. Don't do anything else here - we wait to in receive()
1986 * we've validated the MAC that SHOULD be provided. in receive()
1988 * hisstratum cannot be 0 - see assertion above. in receive()
1990 * at least we'll be able to sync with the broadcast server. in receive()
2005 * KoD packets are a mixed-blessing. Forged KoD packets in receive()
2006 * are DoS attacks. There are rare situations where we might in receive()
2007 * get a valid KoD response, though. Since KoD packets are in receive()
2009 * handle the basic KoD checks here. in receive()
2013 * that we have previously sent out. Watch interleave mode. in receive()
2021 "receive: KoD packet from %s has a zero org or rec timestamp. Ignoring.", in receive()
2030 "receive: KoD packet from %s has inconsistent xmt/org/rec timestamps. Ignoring.", in receive()
2039 "receive: flip 0 KoD origin timestamp 0x%x.%08x from %s does not match 0x%x.%08x - ignoring.", in receive()
2040 p_org.l_ui, p_org.l_uf, in receive()
2042 peer->aorg.l_ui, peer->aorg.l_uf); in receive()
2047 …"receive: flip 1 KoD origin timestamp 0x%x.%08x from %s does not match interleave 0x%x.%08x - igno… in receive()
2048 p_org.l_ui, p_org.l_uf, in receive()
2050 peer->borg.l_ui, peer->borg.l_uf); in receive()
2058 * packet or we've already received a response to our query. in receive()
2061 * reply. There is a window of one nanosecond once every in receive()
2062 * 136 years' time where this is possible. We currently in receive()
2064 * is (quietly?) disallowed. in receive()
2066 * Otherwise, check for bogus packet in basic mode. in receive()
2069 * not bogus in symmetric interleaved mode. in receive()
2072 * to be from us, attempting to cause our server to KoD us. in receive()
2074 * We have earlier asserted that hisstratum cannot be 0. in receive()
2075 * If hisstratum is STRATUM_UNSPEC, it means he's not sync'd. in receive()
2115 peer->flash |= TEST2; /* bogus */ in receive()
2124 "receive: %s 0 origin timestamp from %s@%s xmt 0x%x.%08x", in receive()
2126 ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf)); in receive()
2132 /* Should we set TEST2 if we decide to try xleave? */ in receive()
2134 peer->flash |= TEST2; /* bogus */ in receive()
2136 "duplicate or replay: org 0x%x.%08x does not match 0x%x.%08x from %s@%s", in receive()
2137 ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), in receive()
2138 peer->aorg.l_ui, peer->aorg.l_uf, in receive()
2158 * Check for valid nonzero timestamp fields. in receive()
2166 * Check for bogus packet in interleaved symmetric mode. This in receive()
2167 * can happen if a packet is lost, duplicated or crossed. If in receive()
2168 * found, flip and resynchronize. in receive()
2175 peer->flash |= TEST2; /* bogus */ in receive()
2185 * client packet. The server might have just changed keys. Clear in receive()
2186 * the association and restart the protocol. in receive()
2210 * reply to a client packet previously sent. The loopback check in receive()
2212 * possible in past versions. If symmetric modes, return a in receive()
2213 * crypto-NAK. The peer should restart the protocol. in receive()
2252 * client do its stuff. in receive()
2256 * interleaved broadcast, so restart the protocol. in receive()
2257 * - else, this is not an interleaved broadcast packet. in receive()
2287 * update peer->bxmt. in receive()
2294 ** Update the state variables. in receive()
2305 * peer minpoll. If a kiss-o'-death, set the peer minpoll to in receive()
2307 * headroom. Very intricate. in receive()
2311 * Check for any kiss codes. Note this is only used when a server in receive()
2312 * responds to a packet request. in receive()
2354 * then see if the sender's IP is trusted for this keyid. in receive()
2355 * If it is, great - nothing special to do here. in receive()
2356 * Otherwise, we should report and bail. in receive()
2358 * Autokey-authenticated packets are accepted. in receive()
2395 * clean. Get on with real work. in receive()
2406 * More autokey dance. The rules of the cha-cha are as follows: in receive()
2408 * 1. If there is no key or the key is not auto, do nothing. in receive()
2410 * 2. If this packet is in response to the one just previously in receive()
2411 * sent or from a broadcast server, do the extension fields. in receive()
2412 * Otherwise, assume bogosity and bail out. in receive()
2414 * 3. If an extension field contains a verified signature, it is in receive()
2415 * self-authenticated and we sit the dance. in receive()
2417 * 4. If this is a server reply, check only to see that the in receive()
2418 * transmitted key ID matches the received key ID. in receive()
2420 * 5. Check to see that one or more hashes of the current key ID in receive()
2422 * obtained from the broadcaster or symmetric peer. If no in receive()
2423 * match, sit the dance and call for new autokey values. in receive()
2426 * restart the protocol. in receive()
2430 * Decrement remaining autokey hashes. This isn't in receive()
2431 * perfect if a packet is lost, but results in no harm. in receive()
2433 ap = (struct autokey *)peer->recval.ptr; in receive()
2459 * the transmit key ID. in receive()
2467 * has been correctly signed. We don't need a sequence in receive()
2468 * check here, but the sequence continues. in receive()
2474 * Now the fun part. Here, skeyid is the current ID in in receive()
2476 * tkeyid is the hash of skeyid. If the autokey values in receive()
2477 * have not been received, this is an automatic error. in receive()
2478 * If so, check that the tkeyid matches pkeyid. If not, in receive()
2479 * hash tkeyid and try again. If the number of hashes in receive()
2481 * a successful failure and refresh the autokey values. in receive()
2512 * refresh certificates and leapseconds values. in receive()
2524 * The dance is complete and the flash bits have been lit. Toss in receive()
2526 * more flashers. Leave if the packet is not good. in receive()
2534 /* [bug 3592] Update poll. Ideally this should not happen in a in receive()
2535 * receive branch, but too much is going on here... at least we in receive()
2536 * do it only if the packet was good! in receive()
2541 * In interleaved mode update the state variables. Also adjust the in receive()
2542 * transmit phase to avoid crossover. in receive()
2557 * process_packet - Packet Procedure, a la Section 3.4.4 of RFC-1305
2558 * Or almost, at least. If we're in here we have a reasonable
2560 * relationship with this host.
2592 * stratum and root distance are valid. in process_packet()
2601 * If any tests fail at this point, the packet is discarded. in process_packet()
2603 * receive() routine. in process_packet()
2620 * Capture the header values in the client/peer association.. in process_packet()
2638 * First, if either burst mode is armed, enable the burst. in process_packet()
2640 * necessary to avoid exceeding the threshold. in process_packet()
2654 * If the peer was previously unreachable, raise a trap. In any in process_packet()
2655 * case, mark it reachable. in process_packet()
2665 * roundtrip delay and dispersion. The equations are reordered in process_packet()
2666 * from the spec for more efficient use of temporaries. For a in process_packet()
2668 * computed delay during the client/server volley. Note the in process_packet()
2670 * that due to the frequency error since the origin time. in process_packet()
2672 * It is very important to respect the hazards of overflow. The in process_packet()
2675 * in the past to 68 years in the future. To avoid loss of in process_packet()
2677 * arithmetic. However, the offset and delay calculations are in process_packet()
2680 * only half that span. Since the typical first-order in process_packet()
2683 * double arithmetic. This preserves the accuracy while in process_packet()
2684 * retaining the 68-year span. in process_packet()
2687 * symmetric and interleaved broadcast. The timestamps are in process_packet()
2688 * idioscyncratically different. See the onwire briefing/white in process_packet()
2689 * paper at www.eecis.udel.edu/~mills for details. in process_packet()
2706 p_offset = (t21 + t34) / 2.; in process_packet()
2707 if (p_del < 0 || p_del > 1.) { in process_packet()
2709 "t21 %.9f t34 %.9f", t21, t34); in process_packet()
2719 * Interleaved broadcast mode. Use interleaved timestamps. in process_packet()
2731 if (t34 < 0 || t34 > 1.) { in process_packet()
2736 "offset %.9f delay %.9f", in process_packet()
2744 * Basic broadcast - use direct timestamps. in process_packet()
2758 * timestamp. This works for both basic and interleaved in process_packet()
2759 * modes. in process_packet()
2761 * calculation gives reason to suspect clock steps. in process_packet()
2762 * This is assumed for delays > 50ms. in process_packet()
2767 DPRINTF(2, ("broadcast volley: initial delay=%.6f\n", in process_packet()
2782 * Basic mode, otherwise known as the old fashioned way. in process_packet()
2794 p_offset = (t21 + t34) / 2.; in process_packet()
2804 * packet lengths. This is helpful in cases of large asymmetric in process_packet()
2806 * links. in process_packet()
2814 if (ftemp > 1000.) in process_packet()
2823 if (ftemp > 1000.) in process_packet()
2831 * the outbound (d21) and inbound (t34) directions. To do this, in process_packet()
2833 * the roundtrip delay. Then it calculates the correction as a in process_packet()
2834 * fraction of d. in process_packet()
2840 DPRINTF(2, ("packet: t21 %.9lf %d t34 %.9lf %d\n", peer->t21, in process_packet()
2845 .5) * p_del; in process_packet()
2852 * used. In future, we might find conditions where the in process_packet()
2854 * a work in progress. in process_packet()
2858 DPRINTF(2, ("packet: del %.6lf r21 %.1lf r34 %.1lf %.6lf\n", in process_packet()
2865 * That was awesome. Now hand off to the clock filter. in process_packet()
2872 * complete. in process_packet()
2892 * clock_update - Called at system process update intervals.
2906 * Update the system state variables. We do this very carefully, in clock_update()
2907 * as the poll interval might need to be clamped differently. in clock_update()
2925 * E = p.epsilon_r + p.epsilon + p.psi + PHI*(s.t - p.t) + |THETA| in clock_update()
2928 * p.epsilon_r is the PollProc's root dispersion in clock_update()
2929 * p.epsilon is the PollProc's dispersion in clock_update()
2930 * p.psi is the PollProc's jitter in clock_update()
2934 * what they mean. When did peer->update happen? Has anything in clock_update()
2938 * DLM thinks this equation is probably the best of all worse choices. in clock_update()
2967 * Comes now the moment of truth. Crank the clock discipline and in clock_update()
2968 * see what comes out. in clock_update()
2973 * Clock exceeds panic threshold. Life as we know it ends. in clock_update()
2976 msyslog(LOG_ERR, "Clock offset exceeds panic threshold."); in clock_update()
2979 * For Solaris enter the maintenance mode. in clock_update()
2988 * Sleep until SMF kills us. in clock_update()
2990 msyslog(LOG_ERR, "%s placed into maintenance. " in clock_update()
2991 "Set system clock by hand before clearing.", in clock_update()
2997 msyslog(LOG_ERR, "Set system clock by hand."); in clock_update()
3002 * Clock was stepped. Flush all time values of all peers. in clock_update()
3021 * Clock was slewed. Handle the leapsecond stuff. in clock_update()
3027 * leap bits. If crypto, the timer will goose the setup in clock_update()
3028 * process. in clock_update()
3043 * current month. (This only works if no leap second for in clock_update()
3045 * once is mostly harmless.) in clock_update()
3051 leapsec_add_dyn(TRUE, now.l_ui, NULL); in clock_update()
3056 leapsec_add_dyn(FALSE, now.l_ui, NULL); in clock_update()
3062 * Popcorn spike or step threshold exceeded. Pretend it never in clock_update()
3063 * happened. in clock_update()
3085 * This routine figures out when the next poll should be sent. in poll_update()
3086 * That turns out to be wickedly complicated. One problem is in poll_update()
3088 * the poll interval is reduced. We watch out for races here in poll_update()
3089 * between the receive process and the poll process. in poll_update()
3091 * Clamp the poll interval between minpoll and maxpoll. in poll_update()
3098 * the lifetimes in the key list are probably bogus. Purge the in poll_update()
3099 * the key list and regenerate it later. in poll_update()
3109 * and the earliest time (utemp). The earliest time is 2 s in poll_update()
3110 * seconds, but could be more due to rate management. When in poll_update()
3111 * sending in a burst, use the earliest time. When not in a in poll_update()
3113 * unless the next scheduled time has not advanced. This can in poll_update()
3115 * response interval. Otherwise, send at the later of the next in poll_update()
3116 * scheduled time and the earliest time. in poll_update()
3118 * Now we figure out if there is an override. If a burst is in in poll_update()
3120 * slink away. If called from the poll process, delay 1 s for a in poll_update()
3121 * reference clock, otherwise 2 s. in poll_update()
3147 * is pending, delay 2 s, but only if this is a new interval. in poll_update()
3159 * The ordinary case. If a retry, use minpoll; if unreachable, in poll_update()
3162 * understampling is evil. Use the maximum of this value and the in poll_update()
3163 * headway. If the average headway is greater than the headway in poll_update()
3164 * threshold, increase the headway by the minimum interval. in poll_update()
3184 int sub = psi.sub; in poll_update()
3185 int qty = psi.qty; in poll_update()
3186 int msk = psi.msk; in poll_update()
3225 * peer_clear - clear peer filter registers. See Section 3.4.8 of the
3226 * spec.
3241 * Valhalla. Note that autokeys are ephemeral, in that they are in peer_clear()
3242 * tossed immediately upon use. Therefore, the keylist can be in peer_clear()
3243 * purged anytime without needing to preserve random keys. Note in peer_clear()
3245 * purged, too. This makes it much harder to sneak in some in peer_clear()
3246 * unauthenticated data in the clock filter. in peer_clear()
3264 * Clear all values, including the optional crypto values above. in peer_clear()
3278 * If interleave mode, initialize the alternate origin switch. in peer_clear()
3302 * the polls at one-second intervals. Unconfigured associations' in peer_clear()
3304 * rate limiting. Other post-startup new or cleared associations in peer_clear()
3306 * avoid implosion. in peer_clear()
3332 * the filter procedure to find the best sample.
3350 * of arrival. The offset and delay are determined by the on- in clock_filter()
3351 * wire protocol. The dispersion grows from the last outbound in clock_filter()
3354 * error budget. First, shift the new arrival into the shift in clock_filter()
3355 * register discarding the oldest one. in clock_filter()
3367 * time initialize the distance and index lists. Since samples in clock_filter()
3369 * only under exceptional cases will an older sample be used. in clock_filter()
3370 * Therefore, the distance list uses a compound metric. If the in clock_filter()
3372 * distance at that value. If the time since the last update is in clock_filter()
3374 * the sum of the delay and dispersion. in clock_filter()
3396 * If the clock has stabilized, sort the samples by distance. in clock_filter()
3415 * can see it later. Prune the distance list to leave only in clock_filter()
3417 * uncorrelated samples older than the Allan intercept. To in clock_filter()
3420 * least two samples for jitter calculation. in clock_filter()
3432 * Compute the dispersion and jitter. The dispersion is weighted in clock_filter()
3434 * to 1.0. The jitter is the RMS differences relative to the in clock_filter()
3435 * lowest delay sample. in clock_filter()
3451 * quietly tiptoe home leaving only the dispersion. Otherwise, in clock_filter()
3452 * save the offset, delay and jitter. Note the jitter must not in clock_filter()
3453 * be less than the precision. in clock_filter()
3472 * a popcorn spike and ignore it. in clock_filter()
3478 < 2. * ULOGTOD(peer->hpoll)) { in clock_filter()
3479 mprintf_event(PEVNT_POPCORN, peer, "%.9f s", etemp); in clock_filter()
3485 * last one used. In this design the maximum lifetime of any in clock_filter()
3488 * NTP_SHIFT packets. in clock_filter()
3499 * processing. If not synchronized or not in a burst, tickle the in clock_filter()
3500 * clock select algorithm. in clock_filter()
3504 DPRINTF(1, ("clock_filter: n %hu off %.9f del %.9f dsp %.9f jit %.9f\n", in clock_filter()
3520 * infinity.
3556 * enough to handle all associations. in clock_select()
3568 * associations. in clock_select()
3583 * that happen to be lying around. Those with seriously in clock_select()
3584 * defective clocks are immediately booted off the island. Then, in clock_select()
3585 * the falsetickers are culled and put to sea. The truechimers in clock_select()
3587 * unpopular at each round is kicked off. When the population in clock_select()
3589 * bucks and collectively crank the chimes. in clock_select()
3597 * unfit to synchronize. in clock_select()
3606 * has the lowest root distance. This can be used as a last in clock_select()
3607 * resort if all else fails. Once we get an initial sync in clock_select()
3609 * function becomes disabled. in clock_select()
3623 * hashed IPv6 address. To ensure convergence in clock_select()
3626 * metric and be the orphan parent. If this in clock_select()
3628 * orphan mode in timer(). in clock_select()
3652 * instability. Peers at stratum higher than in clock_select()
3654 * parent in ancestry so are excluded. in clock_select()
3655 * See http://bugs.ntp.org/2050 in clock_select()
3662 * The following are special cases. We deal in clock_select()
3663 * with them later. in clock_select()
3685 * idol. in clock_select()
3689 peers[nlist].peer = peer; in clock_select()
3690 peers[nlist].error = peer->jitter; in clock_select()
3691 peers[nlist].synch = f; in clock_select()
3696 * endpoint[] list. in clock_select()
3699 endpoint[nl2].type = -1; /* lower end */ in clock_select()
3700 endpoint[nl2].val = e - f; in clock_select()
3702 endpoint[nl2].type = 1; /* upper end */ in clock_select()
3703 endpoint[nl2].val = e + f; in clock_select()
3708 * offset. in clock_select()
3714 e = endp.val; in clock_select()
3718 if (endp.val < e) { in clock_select()
3719 e = endp.val; in clock_select()
3730 DPRINTF(3, ("select: endpoint %2d %.6f\n", in clock_select()
3731 endpoint[indx[i]].type, endpoint[indx[i]].val)); in clock_select()
3735 * from the falsetickers. The original algorithm was described in clock_select()
3737 * better accuracy. in clock_select()
3741 * then from the high end downwards. The scans stop when the in clock_select()
3743 * the number of falsetickers. If this doesn't happen for a in clock_select()
3745 * falsetickers and try again. If the number of falsetickers in clock_select()
3748 * correct synchronization is not possible. in clock_select()
3751 * number of falsetickers. Upon exit, the truechimers are the in clock_select()
3753 * high. There may be none of them. in clock_select()
3761 * interval containing points from the most sources. in clock_select()
3765 low = endpoint[indx[i]].val; in clock_select()
3766 n -= endpoint[indx[i]].type; in clock_select()
3772 high = endpoint[indx[j]].val; in clock_select()
3773 n += endpoint[indx[j]].type; in clock_select()
3779 * If an interval containing truechimers is found, stop. in clock_select()
3781 * around again. in clock_select()
3788 * Clustering algorithm. Whittle candidate list of falsetickers, in clock_select()
3789 * who leave the island immediately. The TRUE peer is always a in clock_select()
3790 * truechimer. We must leave at least one peer to collect the in clock_select()
3791 * million bucks. in clock_select()
3795 * contained in the interval. For this purpose, a truechimer is in clock_select()
3797 * intersection interval. in clock_select()
3803 peer = peers[i].peer; in clock_select()
3804 h = peers[i].synch; in clock_select()
3814 * algorithm. Use the first one found, but don't in clock_select()
3815 * include any of them in the cluster population. in clock_select()
3833 * driver, local driver or orphan parent in that order. If so, in clock_select()
3834 * nominate the first one found as the only survivor. in clock_select()
3835 * Otherwise, give up and leave the island to the rats. in clock_select()
3838 peers[0].error = 0; in clock_select()
3839 peers[0].synch = sys_mindisp; in clock_select()
3842 peers[0].peer = typeacts; in clock_select()
3845 peers[0].peer = typelocal; in clock_select()
3850 peers[0].peer = typeorphan; in clock_select()
3853 peers[0].peer = typelastresort; in clock_select()
3859 * Mark the candidates at this point as truechimers. in clock_select()
3862 peers[i].peer->new_status = CTL_PST_SEL_SELCAND; in clock_select()
3864 stoa(&peers[i].peer->srcadr), peers[i].synch)); in clock_select()
3869 * by root distance. Continue voting as long as there are more in clock_select()
3872 * jitter. Stop if we are about to discard a TRUE or PREFER in clock_select()
3873 * peer, who of course have the immunity idol. in clock_select()
3881 if (peers[i].error < d) in clock_select()
3882 d = peers[i].error; in clock_select()
3883 peers[i].seljit = 0; in clock_select()
3887 f += DIFF(peers[j].peer->offset, in clock_select()
3888 peers[i].peer->offset); in clock_select()
3889 peers[i].seljit = SQRT(f / (nlist - 1)); in clock_select()
3891 if (peers[i].seljit * peers[i].synch > e) { in clock_select()
3892 g = peers[i].seljit; in clock_select()
3893 e = peers[i].seljit * peers[i].synch; in clock_select()
3900 || ((FLAG_TRUE | FLAG_PREFER) & peers[k].peer->flags)) in clock_select()
3903 DPRINTF(3, ("select: drop %s seljit %.9f jit %.9f\n", in clock_select()
3904 ntoa(&peers[k].peer->srcadr), g, d)); in clock_select()
3906 peers[k].peer->new_status = CTL_PST_SEL_EXCESS; in clock_select()
3914 * peers. Note that unsynchronized peers cannot survive this in clock_select()
3915 * far. Count and mark these survivors. in clock_select()
3917 * While at it, count the number of leap warning bits found. in clock_select()
3918 * This will be used later to vote the system leap warning bit. in clock_select()
3920 * is always won. in clock_select()
3924 * stratum scaled by sys_mindisp (.001 by default). The goal of in clock_select()
3928 * sys_mindisp. in clock_select()
3930 * In contrast, ntpd 4.2.6 and earlier used stratum primarily in clock_select()
3932 * additional root distance per stratum. This heavy bias is no in clock_select()
3934 * more rational metric carrying the cumulative error budget. in clock_select()
3941 peer = peers[i].peer; in clock_select()
3959 speermet = peers[i].seljit * peers[i].synch + in clock_select()
3969 * building dark. Otherwise, do a clockhop dance. Ordinarily, in clock_select()
3970 * use the selected survivor speer. However, if the current in clock_select()
3972 * as long as it doesn't get too old or too ugly. in clock_select()
3977 typesystem = peers[speer].peer; in clock_select()
3985 sys_clockhop *= .5; in clock_select()
3986 DPRINTF(1, ("select: clockhop %d %.9f %.9f\n", in clock_select()
3998 * Mitigation rules of the game. We have the pick of the in clock_select()
3999 * litter in typesystem if any survivors are left. If in clock_select()
4000 * there is a prefer peer, use its offset and jitter. in clock_select()
4001 * Otherwise, use the combined offset and jitter of all kitters. in clock_select()
4014 DPRINTF(1, ("select: combine offset %.9f jitter %.9f\n", in clock_select()
4021 * and jitter. However, if this is the atom driver, use it only in clock_select()
4023 * are required. in clock_select()
4036 DPRINTF(1, ("select: pps offset %.9f jitter %.9f\n", in clock_select()
4043 * system peer. If so and this is an old update, keep the in clock_select()
4044 * current statistics, but do not update the clock. in clock_select()
4059 * stability. in clock_select()
4065 * We have found the alpha male. Wind the clock. in clock_select()
4079 int syspeer /* index of sys.peer */ in clock_combine()
4087 x = 1. / peers[i].synch; in clock_combine()
4089 z += x * peers[i].peer->offset; in clock_combine()
4090 w += x * DIFF(peers[i].peer->offset, in clock_combine()
4091 peers[syspeer].peer->offset); in clock_combine()
4094 sys_jitter = SQRT(w / y + SQUARE(peers[syspeer].seljit)); in clock_combine()
4121 * the alternatives are, and the various pros/cons. in root_distance()
4124 * other worse choices. in root_distance()
4132 * Careful squeak here. The value returned must be greater than in root_distance()
4134 * highly precise reference clocks. Note that the root distance in root_distance()
4136 * selection algorithm. in root_distance()
4145 * peer_xmit - send packet for persistent association.
4160 xpkt.li_vn_mode = PKT_LI_VN_MODE(sys_leap, peer->version, in peer_xmit()
4162 xpkt.stratum = STRATUM_TO_PKT(sys_stratum); in peer_xmit()
4163 xpkt.ppoll = peer->hpoll; in peer_xmit()
4164 xpkt.precision = sys_precision; in peer_xmit()
4165 xpkt.refid = sys_refid; in peer_xmit()
4166 xpkt.rootdelay = HTONS_FP(DTOFP(sys_rootdelay)); in peer_xmit()
4167 xpkt.rootdisp = HTONS_FP(DTOUFP(sys_rootdisp)); in peer_xmit()
4169 HTONL_FP(&sys_reftime, &xpkt.reftime); in peer_xmit()
4170 HTONL_FP(&peer->rec, &xpkt.org); in peer_xmit()
4171 HTONL_FP(&peer->dst, &xpkt.rec); in peer_xmit()
4175 * is authenticated and contains a MAC. If not, the transmitted in peer_xmit()
4176 * packet is not authenticated. in peer_xmit()
4180 * sent. Otherwise, it is not possible to compute a correct MAC in peer_xmit()
4181 * the recipient will accept. Thus, the I/O semantics have to do in peer_xmit()
4182 * a little more work. In particular, the wildcard interface in peer_xmit()
4183 * might not be usable. in peer_xmit()
4198 HTONL_FP(&xmt_tx, &xpkt.xmt); in peer_xmit()
4201 HTONL_FP(&xmt_tx, &xpkt.xmt); in peer_xmit()
4204 &xpkt.org); in peer_xmit()
4207 &xpkt.org); in peer_xmit()
4211 &xpkt.xmt); in peer_xmit()
4214 &xpkt.xmt); in peer_xmit()
4237 DPRINTF(1, ("peer_xmit: at %ld %s->%s mode %d len %zu xmt 0x%x.%08x\n", in peer_xmit()
4240 xmt_tx.l_ui, xmt_tx.l_uf)); in peer_xmit()
4246 * authenticated. If autokey is enabled, fuss with the various in peer_xmit()
4247 * modes; otherwise, symmetric key cryptography is used. in peer_xmit()
4257 * association ID and optional additional data. Optional in peer_xmit()
4259 * the data itself. Request messages are sent from a in peer_xmit()
4262 * path without ever matching an association. Response in peer_xmit()
4264 * a response bit and possibly an error bit set. In this in peer_xmit()
4266 * one command and one or more responses. in peer_xmit()
4269 * a private componet. Request and response messages in peer_xmit()
4271 * private component set to zero. Packets without in peer_xmit()
4273 * the session key is generated. in peer_xmit()
4279 * already done. Then, use the list in inverse in peer_xmit()
4280 * order, discarding keys once used. Keep the in peer_xmit()
4283 * compute propagation delay. in peer_xmit()
4287 * next key is used. This is to allow a client in peer_xmit()
4289 * identifier to verify authenticity. in peer_xmit()
4294 * broken. In that case, purge the keylist and in peer_xmit()
4295 * regenerate it. in peer_xmit()
4313 * required by the broadcast clients. Push them when a in peer_xmit()
4316 * other times. in peer_xmit()
4330 * required. The leapsecond exchange is optional. But, a in peer_xmit()
4333 * might loop until then. If a peer finds a broken in peer_xmit()
4335 * retrieve the autokey values. In any case, if a new in peer_xmit()
4336 * keylist is generated, the autokey values are pushed. in peer_xmit()
4342 * Parameter, certificate and identity. in peer_xmit()
4346 peer->associd, hostval.ptr); in peer_xmit()
4356 * Cookie and autokey. We request the cookie in peer_xmit()
4358 * are synchronized. But, this peer needs the in peer_xmit()
4359 * autokey values when the cookie is zero. Any in peer_xmit()
4361 * autokey values without being asked. If for in peer_xmit()
4364 * used to retrieve the autokey values. in peer_xmit()
4382 * values. in peer_xmit()
4389 peer->associd, hostval.ptr); in peer_xmit()
4397 * cookie and sign exchanges are required. The in peer_xmit()
4398 * leapsecond exchange is optional. If broadcast client in peer_xmit()
4401 * exchange, since the cookie is always zero. If the in peer_xmit()
4404 * values. in peer_xmit()
4409 * Parameter, certificate and identity. in peer_xmit()
4413 peer->associd, hostval.ptr); in peer_xmit()
4423 * Cookie and autokey. These are requests, but in peer_xmit()
4425 * rather than our own. in peer_xmit()
4437 * values. in peer_xmit()
4444 peer->associd, hostval.ptr); in peer_xmit()
4452 * Add a queued extension field if present. This is in peer_xmit()
4454 * in the message. If an error occurs, the error bit is in peer_xmit()
4455 * lit in the response. in peer_xmit()
4469 * Add an extension field created above. All but the in peer_xmit()
4470 * autokey response message are request messages. in peer_xmit()
4480 * Calculate the next session key. Since extension in peer_xmit()
4481 * fields are present, the cookie value is zero. in peer_xmit()
4496 HTONL_FP(&xmt_tx, &xpkt.xmt); in peer_xmit()
4499 HTONL_FP(&xmt_tx, &xpkt.xmt); in peer_xmit()
4501 HTONL_FP(&peer->borg, &xpkt.org); in peer_xmit()
4503 HTONL_FP(&peer->aorg, &xpkt.org); in peer_xmit()
4506 HTONL_FP(&peer->borg, &xpkt.xmt); in peer_xmit()
4508 HTONL_FP(&peer->aorg, &xpkt.xmt); in peer_xmit()
4572 L_ADD(t, &leap_smear.offset); in leap_smear_add_offs()
4585 * fast_xmit - Send packet for nonpersistent association. Note that
4586 * neither the source or destination can be a broadcast address.
4606 * buffer provided. We leave the fields intact as received, but in fast_xmit()
4608 * the system minimum poll (ntp_minpoll). This is for KoD rate in fast_xmit()
4610 * break anything. in fast_xmit()
4616 * a unicast endpoint. in fast_xmit()
4625 " reply to %s mcast.", in fast_xmit()
4635 * kiss code and (???) system root delay. Note we don't reveal in fast_xmit()
4637 * synchronization. in fast_xmit()
4641 xpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC, in fast_xmit()
4643 xpkt.stratum = STRATUM_PKT_UNSPEC; in fast_xmit()
4644 xpkt.ppoll = max(rpkt->ppoll, ntp_minpoll); in fast_xmit()
4645 xpkt.precision = rpkt->precision; in fast_xmit()
4646 memcpy(&xpkt.refid, "RATE", 4); in fast_xmit()
4647 xpkt.rootdelay = rpkt->rootdelay; in fast_xmit()
4648 xpkt.rootdisp = rpkt->rootdisp; in fast_xmit()
4649 xpkt.reftime = rpkt->reftime; in fast_xmit()
4650 xpkt.org = rpkt->xmt; in fast_xmit()
4651 xpkt.rec = rpkt->xmt; in fast_xmit()
4652 xpkt.xmt = rpkt->xmt; in fast_xmit()
4655 * This is a normal packet. Use the system variables. in fast_xmit()
4663 * Make copies of the variables which can be affected by smearing. in fast_xmit()
4674 * reftime isn't later than the transmit/receive times. in fast_xmit()
4676 xpkt.li_vn_mode = PKT_LI_VN_MODE(xmt_leap, in fast_xmit()
4679 xpkt.stratum = STRATUM_TO_PKT(sys_stratum); in fast_xmit()
4680 xpkt.ppoll = max(rpkt->ppoll, ntp_minpoll); in fast_xmit()
4681 xpkt.precision = sys_precision; in fast_xmit()
4682 xpkt.refid = sys_refid; in fast_xmit()
4683 xpkt.rootdelay = HTONS_FP(DTOFP(sys_rootdelay)); in fast_xmit()
4714 xpkt.rootdisp = HTONS_FP(DTOUFP(this_rootdisp)); in fast_xmit()
4721 if (leap_smear.in_progress) { in fast_xmit()
4724 * reftime being later than the transmit time. in fast_xmit()
4730 HTONL_FP(&this_ref_time, &xpkt.reftime); in fast_xmit()
4737 if (leap_smear.in_progress) { in fast_xmit()
4738 xpkt.refid = convertLFPToRefID(leap_smear.offset); in fast_xmit()
4739 DPRINTF(2, ("fast_xmit: leap_smear.in_progress: refid %8x, smear %s\n", in fast_xmit()
4740 ntohl(xpkt.refid), in fast_xmit()
4741 lfptoa(&leap_smear.offset, 8) in fast_xmit()
4750 xpkt.org = rpkt->xmt; in fast_xmit()
4757 if (leap_smear.in_progress) in fast_xmit()
4759 HTONL_FP(&this_recv_time, &xpkt.rec); in fast_xmit()
4761 HTONL_FP(&rbufp->recv_time, &xpkt.rec); in fast_xmit()
4770 if (leap_smear.in_progress) in fast_xmit()
4773 HTONL_FP(&xmt_tx, &xpkt.xmt); in fast_xmit()
4785 * is authenticated and contains a MAC. If not, the transmitted in fast_xmit()
4786 * packet is not authenticated. in fast_xmit()
4801 * must be authenticated. For symmetric key cryptography, use in fast_xmit()
4803 * cryptosum. For autokey cryptography, use the server private in fast_xmit()
4805 * source-destination-key ID combination. in fast_xmit()
4814 * MODE_SERVER. If an extension field is present, there in fast_xmit()
4815 * can be only one and that must be a command. Do what in fast_xmit()
4817 * jerk can decode it. If no extension field is present, in fast_xmit()
4818 * use the cookie to generate the session key. in fast_xmit()
4854 * pool_xmit - resolve hostname or send unicast solicitation for pool.
4889 hints.ai_family = AF(&pool->srcadr); in pool_xmit()
4890 hints.ai_socktype = SOCK_DGRAM; in pool_xmit()
4891 hints.ai_protocol = IPPROTO_UDP; in pool_xmit()
4927 xpkt.li_vn_mode = PKT_LI_VN_MODE(sys_leap, pool->version, in pool_xmit()
4929 xpkt.stratum = STRATUM_TO_PKT(sys_stratum); in pool_xmit()
4930 xpkt.ppoll = pool->hpoll; in pool_xmit()
4931 xpkt.precision = sys_precision; in pool_xmit()
4932 xpkt.refid = sys_refid; in pool_xmit()
4933 xpkt.rootdelay = HTONS_FP(DTOFP(sys_rootdelay)); in pool_xmit()
4934 xpkt.rootdisp = HTONS_FP(DTOUFP(sys_rootdisp)); in pool_xmit()
4936 HTONL_FP(&sys_reftime, &xpkt.reftime); in pool_xmit()
4945 nonce.l_ui = ntp_random(); in pool_xmit()
4946 } while (0 == nonce.l_ui); in pool_xmit()
4948 nonce.l_uf = ntp_random(); in pool_xmit()
4949 } while (0 == nonce.l_uf); in pool_xmit()
4951 HTONL_FP(&nonce, &xpkt.xmt); in pool_xmit()
4954 HTONL_FP(&xmt_tx, &xpkt.xmt); in pool_xmit()
5070 * currently synced to this ntpd.
5071 * Note that until 4.2.8p18 and 4.3.1XX ntpd calculated the IPv6
5072 * refid differently on different-endian systems. It now calculates
5074 * in the past. On big-endian systems, ntpd also calculates a
5076 * as endpt.old_refid and also detects a loop when seeing it. This
5079 * loops with IPv6 refids correctly. Thanks to Hal Murray for
5080 * the byte-swapping idea.
5127 * greater than or equal to the ceiling. in peer_unfit()
5138 * plus the increment due to one host poll interval. in peer_unfit()
5150 * neither a reference clock nor an orphan. in peer_unfit()
5158 * the noselect bit is set. in peer_unfit()
5176 #define MAXLOOPS ((int)(1. / MINSTEP)) /* avoid infinite loop */
5181 * clock. However, if a difference is less than MINSTEP, the clock has
5183 * ignored. We set MINSTEP greater than zero in case something happens
5186 * using an underlying stepping (not interpolated) clock.
5190 * size for lower-precision stepping clocks.
5194 * the underlying clock. With either type of clock, the minimum time
5196 * get_systime() readings always increase and are fuzzed below sys_fuzz.
5203 * is effectively disabled. trunc_os_clock is FALSE to disable in measure_precision()
5204 * get_ostime() simulation of a low-precision system clock. in measure_precision()
5206 set_sys_fuzz(0.); in measure_precision()
5210 msyslog(LOG_INFO, "proto: precision = %.3f usec (%d)", in measure_precision()
5213 msyslog(LOG_NOTICE, "proto: fuzz beneath %.3f usec", in measure_precision()
5224 * between successive clock readings and the time to read the clock.
5283 if (tick > 1.) { in set_sys_tick_precision()
5285 "unsupported tick %.3f > 1s ignored", tick); in set_sys_tick_precision()
5290 "proto: tick %.3f less than measured tick %.3f, ignored", in set_sys_tick_precision()
5296 "proto: truncating system clock to multiples of %.9f", in set_sys_tick_precision()
5302 * Find the nearest power of two. in set_sys_tick_precision()
5323 * Fill in the sys_* stuff. Default is don't listen to in init_proto()
5324 * broadcasting, require authentication. in init_proto()
5373 * enable and disable commands - arguments are Boolean. in proto_config()