Skip to content
Snippets Groups Projects
Commit 3315d015 authored by Adam Wujek's avatar Adam Wujek
Browse files

[FEATURE: #295] rootfs/etc/init.d/wr_date: support multiple ntp servers


Also provide the patch to ntpd to ignore wrong ntp servers. Before ntpd
was exiting if wrong ntp server was provided as parameter.

Signed-off-by: default avatarAdam Wujek <dev_public@wujek.eu>
parent 415e7ec4
Branches
No related merge requests found
From bbf5aab21a722b0a9cd427ca18e673cdd73998b4 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Fri, 13 Dec 2024 15:49:13 +0100
Subject: [PATCH] package/busybox: ignore wrong addresses provided to ntpd
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
...etworking-ntpd-Ignore-wrong-adresses.patch | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 package/busybox/0005-networking-ntpd-Ignore-wrong-adresses.patch
diff --git a/package/busybox/0005-networking-ntpd-Ignore-wrong-adresses.patch b/package/busybox/0005-networking-ntpd-Ignore-wrong-adresses.patch
new file mode 100644
index 0000000..7e67974
--- /dev/null
+++ b/package/busybox/0005-networking-ntpd-Ignore-wrong-adresses.patch
@@ -0,0 +1,35 @@
+From 6f342d647aa3e6120cbae62ee6545cd1881f3d9e Mon Sep 17 00:00:00 2001
+From: Adam Wujek <dev_public@wujek.eu>
+Date: Fri, 13 Dec 2024 15:42:11 +0100
+Subject: [PATCH] networking/ntpd: Ignore wrong adresses
+
+By default, if a wrong server address is provided, the ntp exits with an error.
+The new behaviour ignores wrong addresses.
+
+Signed-off-by: Adam Wujek <dev_public@wujek.eu>
+---
+ networking/ntpd.c | 8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+diff --git a/networking/ntpd.c b/networking/ntpd.c
+index 9732c9b..3c6731b 100644
+--- a/networking/ntpd.c
++++ b/networking/ntpd.c
+@@ -766,7 +766,13 @@ add_peers(const char *s)
+ peer_t *p;
+
+ p = xzalloc(sizeof(*p));
+- p->p_lsa = xhost2sockaddr(s, 123);
++ p->p_lsa = host2sockaddr(s, 123);
++ if (!p->p_lsa) {
++ /* Ignore wrong address */
++ bb_error_msg("Exclude address '%s'", s);
++ return;
++ }
++
+ p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa);
+ p->p_fd = -1;
+ p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3);
+--
+2.25.1
+
--
2.25.1
......@@ -52,17 +52,27 @@ ntp_retries()
S=$1
N=$2
server_list=""
OIFS=$IFS
# support comma, semicolon, space as server delimiter
IFS=',; '
for i in $S; do
# assembly list of servers prefixed with -p
server_list="$server_list -p $i"
done
IFS=$OIFS
for i in `seq $N` ; do # Manual retries
eval ntpd -n -q -p $S -d $LOGPIPE
eval ntpd -n -q $server_list -d $LOGPIPE
if [ $? -eq 0 ]; then
success=1
eval echo "NTP success" $LOGPIPE
return 0
else
eval echo "Retry $i/$N : NTP query failed, unable to contact server \($S\)." $LOGPIPE
eval echo "Retry $i/$N : NTP query failed, unable to contact server\(s\) \($S\)." $LOGPIPE
fi
done
eval echo "ERROR: could not reach NTP server '$S' after $N retries" $LOGPIPE
eval echo "ERROR: could not reach NTP server\(s\) '$S' after $N retries" $LOGPIPE
return 1
}
......@@ -77,7 +87,7 @@ ntp_to_hwclk()
fi
#Request NTP server and set time to FPGA is okay
if ntp_retries $S ${ntp_ntries}; then
if ntp_retries "$S" ${ntp_ntries}; then
eval /wr/bin/wr_date -v set host $LOGPIPE
date_set=1
fi
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment