summaryrefslogtreecommitdiff
path: root/networking/ntpd.c
AgeCommit message (Collapse)Author
2023-01-18ntpd: correct comment: 2^-20 is ~1 microsecond (confused with 10^-20)Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-18ntpd: fold d_to_tv() into its only callerDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-17ntpd: correct fixed->float conversions of fractionsDenys Vlasenko
Need to divide by (1<<32), not by (1<<32)-1. Fraction of 0xffffffff is not 1 whole second. function old new delta .rodata 105264 105268 +4 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-17ntpd: make NTP client and server Y2036/2038-readyMiroslav Lichvar
The 32-bit integer part of the NTP timestamp overflows in year 2036, which starts the second NTP era. Modify the timestamp conversion to shift values between 1900-1970 (in the first era) to the second era to enable the client to measure its offset correctly until year 2106 (assuming 64-bit time_t). Also update the conversion from double used when stepping the clock to work with 64-bit time_t after reaching the maximum 32-bit value in 2038 and the server conversion to work correctly in the next NTP era. function old new delta lfp_to_d 51 64 +13 step_time 326 332 +6 .rodata 105260 105264 +4 d_to_lfp 100 86 -14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 23/-14) Total: 9 bytes Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-10*: add NOINLINEs where code noticeably shrinksDenys Vlasenko
function old new delta display 85 1463 +1378 -73 bytes select_and_cluster - 1088 +1088 -139 bytes parse_reply - 979 +979 -109 bytes zbc_num_sqrt - 632 +632 -191 bytes show_bridge_port - 585 +585 -56 bytes sp_256_proj_point_add_8 - 576 +576 -45 bytes encode_then_append_var_plusminus - 554 +554 -118 bytes read_mode_db - 537 +537 -47 bytes fbset_main 1331 747 -584 sp_256_ecc_mulmod_8 1157 536 -621 brctl_main 2189 1548 -641 expand_one_var 2544 1872 -672 zxc_vm_process 6412 5589 -823 send_queries 1813 725 -1088 recv_and_process_peer_pkt 2245 1018 -1227 bb_dump_dump 1531 80 -1451 ------------------------------------------------------------------------------ (add/remove: 7/0 grow/shrink: 1/8 up/down: 6329/-7107) Total: -778 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08help: s/Don't daemonize/Run in foreground/gDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-24libbb.h: inline byteswapsDenys Vlasenko
function old new delta recv_and_process_peer_pkt 2173 2245 +72 machtime_dg 97 114 +17 machtime_stream 29 45 +16 fmt_time_bernstein_25 132 139 +7 aesgcm_GHASH 183 184 +1 dumpleases_main 519 516 -3 __bswap_32 3 - -3 udhcp_run_script 743 739 -4 tls_xread_record 634 630 -4 select_lease_time 56 52 -4 rdate_main 260 256 -4 get_prefix 327 323 -4 udhcp_listen_socket 185 180 -5 sha1_process_block64 361 356 -5 sendping6 81 76 -5 sendping4 107 102 -5 read32 27 22 -5 ll_proto_a2n 112 107 -5 bb_lookup_port 102 97 -5 udhcpc_main 2615 2609 -6 tftpd_main 579 573 -6 str2sockaddr 558 552 -6 GMULT 136 130 -6 sha1_end 73 66 -7 ntpd_main 1361 1354 -7 ntohl 7 - -7 inet_addr_match 93 86 -7 htonl 7 - -7 do_iplink 1259 1252 -7 do_add_or_delete 1138 1131 -7 create_and_bind_or_die 117 110 -7 bind_for_passive_mode 124 117 -7 xconnect_ftpdata 98 90 -8 rpm_getint 118 110 -8 read_leases 304 296 -8 read_config 216 208 -8 udhcp_send_kernel_packet 336 327 -9 udhcp_recv_kernel_packet 143 134 -9 sha256_process_block64 451 442 -9 d6_send_kernel_packet_from_client_data_ifindex 275 266 -9 write_leases 215 205 -10 wget_main 2518 2508 -10 udhcpd_main 1528 1518 -10 tftp_protocol 2019 2009 -10 ftpd_main 2159 2149 -10 des_crypt 1318 1308 -10 send_ACK 138 127 -11 ipaddr_modify 1618 1607 -11 udhcp_str2optset 650 638 -12 init_d6_packet 115 103 -12 xwrite_encrypted 512 499 -13 tls_handshake 2060 2047 -13 pscan_main 607 594 -13 perform_d6_release 240 227 -13 ip_port_str 135 122 -13 handle_incoming_and_exit 2230 2217 -13 INET_setroute 751 737 -14 traceroute_init 1153 1137 -16 nc_main 1055 1039 -16 udhcp_init_header 92 75 -17 volume_id_probe_hfs_hfsplus 512 494 -18 send_offer 455 435 -20 do_lzo_decompress 507 487 -20 add_client_options 229 209 -20 ipcalc_main 554 533 -21 dhcprelay_main 966 943 -23 change_listen_mode 345 321 -24 send_packet 188 162 -26 static.xmalloc_optname_optval 709 681 -28 rpm_gettags 447 419 -28 machtime 28 - -28 catcher 299 270 -29 sfp_to_d 78 48 -30 reread_config_file 917 886 -31 lfp_to_d 84 51 -33 udhcp_recv_raw_packet 594 559 -35 nbdclient_main 1182 1145 -37 d_to_lfp 137 100 -37 lzo_compress 567 529 -38 d6_recv_raw_packet 299 254 -45 d_to_sfp 133 85 -48 d6_send_raw_packet_from_client_data_ifindex 427 379 -48 common_ping_main 1935 1887 -48 udhcp_send_raw_packet 467 416 -51 zcip_main 1219 1160 -59 udhcpc6_main 2636 2568 -68 do_lzo_compress 327 258 -69 send_arp_request 201 129 -72 common_traceroute_main 1699 1621 -78 arpping 523 437 -86 arping_main 1597 1481 -116 print_tunnel 678 550 -128 dnsd_main 1304 1164 -140 parse_args 1370 1169 -201 ------------------------------------------------------------------------------ (add/remove: 0/6 grow/shrink: 5/85 up/down: 113/-2246) Total: -2133 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-26ntpd: code shrink (force not-inlining, stop returning structs)Denys Vlasenko
function old new delta d_to_sfp - 133 +133 lfp_to_d - 84 +84 sfp_to_d - 78 +78 d_to_lfp 141 137 -4 .rodata 103182 103174 -8 recv_and_process_peer_pkt 2380 2173 -207 recv_and_process_client_pkt 706 493 -213 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 0/4 up/down: 295/-432) Total: -137 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-02ntpd: tweak commentsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-02ntpd: decrease INITIAL_SAMPLES from 4 to 3Denys Vlasenko
This reduces initial traffic to NTP servers when a lot of devices boot at once. Log inspection tells me we agressively burst-poll servers about 5 times at startup, even though we usually already update clock after second replies. INITIAL_SAMPLES can probably be even lower, e.g. 2, but let's be conservative when changing this stuff. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21ntpd: log responses to clients at log level 3Denys Vlasenko
function old new delta recv_and_process_client_pkt 670 706 +36 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21ntpd: without INITIAL_FREQ_ESTIMATION code, state variable is not needed tooDenys Vlasenko
function old new delta update_local_clock 917 872 -45 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21ntpd: remove unused USING_INITIAL_FREQ_ESTIMATION codeDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21ntpd: increase loglevel to 3 for "poll:32s sockets:0 interval:64s" messageDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-04Fix ntpd compilcation on the FreeBSDAlex Samorukov
FreeBSD using different constant names, defining them inline Signed-off-by: Alex Samorukov <samm@os2.kiev.ua> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-30libbb: introduce and use xgettimeofday(), do not truncate 64-bit time_t in ↵Denys Vlasenko
shells function old new delta xgettimeofday - 11 +11 get_local_var_value 280 281 +1 svlogd_main 1323 1322 -1 change_epoch 67 66 -1 timestamp_and_log 461 458 -3 hwclock_main 301 298 -3 fmt_time_bernstein_25 135 132 -3 step_time 331 326 -5 script_main 1207 1202 -5 machtime 34 28 -6 curtime 61 54 -7 ts_main 423 415 -8 nmeter_main 761 751 -10 gettime1900d 67 46 -21 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/12 up/down: 12/-73) Total: -61 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-18help text tweaksDenys Vlasenko
function old new delta packed_usage 33570 33502 -68 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16libbb: introduce and use xsettimeofday()Denys Vlasenko
function old new delta xsettimeofday - 25 +25 rdate_main 274 260 -14 step_time 348 331 -17 set_kernel_timezone_and_clock 119 102 -17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 25/-48) Total: -23 bytes text data bss dec hex filename 1020753 559 5052 1026364 fa93c busybox_old 1020708 559 5052 1026319 fa90f busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15ntpd: allow non-root to run it (e.g. with -w option)Denys Vlasenko
This is safe: it's not a setuid applet, the attempt to set time will simply fail if attempted by non-root From openwrt 600-allow-ntpd-non-root.patch function old new delta ntp_init 1049 1005 -44 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29ntpd: fix the case where two replies received at once and first one causes a ↵Denys Vlasenko
step function old new delta recv_and_process_peer_pkt 2476 2486 +10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-13build system: drop PLATFORM_LINUXRon Yorston
PLATFORM_LINUX is a hidden configuration option which is disabled by default and enabled at over a hundred locations for features that are deemed to be Linux specific. The only effect of PLATFORM_LINUX is to control compilation of libbb/match_fstype.c. This file is only needed by mount and umount. Remove all references to PLATFORM_LINUX and compile match_fstype.c if mount or umount is enabled. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-20ntpd: fix refid reported in server mode, closes 13056Denys Vlasenko
function old new delta resolve_peer_hostname 129 196 +67 recv_and_process_peer_pkt 2475 2476 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 68/0) Total: 68 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-30ntpd: decrease MIN_FREQHOLD by 2, increase "penalty" for largish offset x2Denys Vlasenko
> 2018-07-25: > ntpd: increase MIN_FREQHOLD by 3 > This means we'll start correcting frequency ~5 minutes after start, > not ~3.5 ones. > With previous settings I still often see largish ~0.7s initial offsets > only about 1/2 corrected before frequency correction kicks in, > resulting in ~200ppm "correction" which is then slowly undone. Review of real-world results of the above shows that with small initial offsets, freq correction can be allowed to kick in sooner, whereas with large (~0.8s) offsets, we still start freq correction a bit too soon. Let's rebalance this a bit. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25ntpd: abs(tmx.offset) was truncating a "long" typed valueDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25suppress a few "unused function" warningsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02ntpd: add comment about mode6, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02ntpd: commonalize message stringsDenys Vlasenko
function old new delta recv_and_process_peer_pkt 961 973 +12 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 12/0) Total: 12 bytes text data bss dec hex filename 953108 481 7288 960877 ea96d busybox_old 953086 481 7288 960855 ea957 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02libbb: reduce the overhead of single parameter bb_error_msg() callsJames Byrne
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02ntpd: abort if argvs are (unexpectedly) givenDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-30Optionally re-introduce bb_info_msg()James Byrne
Between Busybox 1.24.2 and 1.25.0 the bb_info_msg() function was eliminated and calls to it changed to be bb_error_msg(). The downside of this is that daemons now log all messages to syslog at the LOG_ERR level which makes it hard to filter errors from informational messages. This change optionally re-introduces bb_info_msg(), controlled by a new option FEATURE_SYSLOG_INFO, restores all the calls to bb_info_msg() that were removed (only in applets that set logmode to LOGMODE_SYSLOG or LOGMODE_BOTH), and also changes informational messages in ifplugd and ntpd. The code size change of this is as follows (using 'defconfig' on x86_64 with gcc 7.3.0-27ubuntu1~18.04) function old new delta bb_info_msg - 182 +182 bb_vinfo_msg - 27 +27 static.log7 194 198 +4 log8 190 191 +1 log5 190 191 +1 crondlog 45 - -45 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 3/0 up/down: 215/-45) Total: 170 bytes If you don't care about everything being logged at LOG_ERR level then when FEATURE_SYSLOG_INFO is disabled Busybox actually gets smaller: function old new delta static.log7 194 200 +6 log8 190 193 +3 log5 190 193 +3 syslog_level 1 - -1 bb_verror_msg 583 581 -2 crondlog 45 - -45 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 3/1 up/down: 12/-48) Total: -36 bytes Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-27ntpd: do not create pid file if not backgroundedDenys Vlasenko
function old new delta ntp_init 995 1021 +26 ntpd_main 1267 1257 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 26/-10) Total: 16 bytes Reported by Alfonso Ranieri <alforan@tin.it> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-17do not duplicate CONFIG_PID_FILE_PATH and ".pid" stringsDenys Vlasenko
text data bss dec hex filename 981737 485 7296 989518 f194e busybox_old 981704 485 7296 989485 f192d busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-15ntpd: increase SLEW_THRESHOLD from 0.125 to 0.5Denys Vlasenko
Linux kernel supports it since ~2006 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28config: update size informationDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-25ntpd: do not SEGV on "-p keyno:192.168.1.1", show --help insteadDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-10-30ntpd: default to FEATURE_NTP_AUTH=yDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-10-27ntpd: add support for MD5/SHA1 message authenticationBrandon P. Enochs
Add support for MD5 message authentication as described in RFC 5905. This patch also supports SHA1 authentication. The key file format is the same file format as used by ntpd. The configuration file format follows standard Unix conventions (# comments) with lines consist of the following fields separated by whitespace: <key identifier, [1,65535]> <SHA1|MD5> <an ASCII string of up to 20 characters|an octet string [a-zA-F0-9] of up to 40 characters>. https://www.ietf.org/rfc/rfc5905.txt function old new delta ntp_init 473 987 +514 hash - 125 +125 recv_and_process_peer_pkt 889 961 +72 packed_usage 33066 33130 +64 ntpd_main 1226 1277 +51 find_key_entry - 29 +29 add_peers 195 207 +12 recv_and_process_client_pkt 509 514 +5 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 6/0 up/down: 872/0) Total: 872 bytes Signed-off-by: Brandon P. Enochs <enochs.brandon@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-13ntpd: more verbose message for "root distance too high" caseDenys Vlasenko
Managed to make ntpd on one of my machines to be stuck getting "root distance too high" all the time, but log is not giving me more informatin what exactly is happening... function old new delta select_and_cluster 1045 1095 +50 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-03ntpd: show real, unclamped delays on low-latency networksDenys Vlasenko
On fast network, I've seen "delay:0.002000" shown for all packets, thus completely losing information on what real delays are. The new code is careful to not reject packets with tiny delays if the delay "grows a lot" but is still tiny: 0.000009 is "much larger" than 0.000001 (nine times larger), but is still very good small delay. function old new delta recv_and_process_peer_pkt 863 889 +26 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-25htpd: increase MIN_FREQHOLD by 3Denys Vlasenko
This means we'll start correcting frequency ~5 minutes after start, not ~3.5 ones. With previos settings I still often see largish ~0.7s initial offsets only about 1/2 corrected before frequency correction kicks in, resulting in ~200ppm "correction" which is then slowly undone. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-02ntpd: increase minimum G.FREQHOLD_cnt from 8 to 10Denys Vlasenko
With ~0.9 initiall offsets, using 8 results in a bit too eager frequency correction. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-24ntpd: deprecate IPTOS_LOWDELAY in favor of IPTOS_DSCP_AF21Codarren Velvindron
Update QoS markers. Use DSCP AF21 for interactive traffic. DSCP is defined in RFC2474. Many modern equipment no longer support IPTOS. Signed-off-by: Codarren Velvindron <codarren@hackers.mu> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08libbb.h: always include sys/resource.hDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-11ntpd: choose initial FREQHOLD_cnt dynamicallyDenys Vlasenko
function old new delta update_local_clock 834 858 +24 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-10ntpd: suppress in-kernel frequency correction in first 8 adjtimex callsDenys Vlasenko
In other words: try to correct initially existing clock offset first, before assuming that our clock drifts. function old new delta update_local_clock 826 834 +8 ntp_init 550 557 +7 filter_datapoints 179 173 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 15/-6) Total: 9 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-12-26ntpd: do run the script at leat once in 11 minutesDenys Vlasenko
function old new delta ntpd_main 1197 1226 +29 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-31ntpd: skip over setting next DNS resolution attempt if it is not neededDenys Vlasenko
function old new delta ntpd_main 1177 1197 +20 resolve_peer_hostname 127 129 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-31ntpd: mention in help text that -d can be repeatedDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-31ntpd: improve treatment of DNS resolution failuresDenys Vlasenko
function old new delta ntpd_main 1106 1177 +71 resolve_peer_hostname 122 127 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 76/0) Total: 76 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-28ntpd: perform DNS resolution out of send/receive loop - closes 10466Denys Vlasenko
Bad case: send request to server1good.com; then try to resolve server2bad.com - this fails, and failure takes ~5 secs; then receive server1's response 5 seconds later. We'll never sync up in this case... function old new delta ntpd_main 1079 1106 +27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>