From 05c197c457bb3e1135ebb634eaad45c5816472a3 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 26 Feb 2025 17:50:53 +0100 Subject: [PATCH 1/7] patches/avahi: improve log message in chroot communication The following log message does not stem from an error in setting up the chroot, but from the internal communication with the chroot. This patch adds the crucial missing file name in the log message. avahi-daemon[3590]: chroot.c: open() failed: No such file or directory So that when the user sees this message, e.g., with "/etc/resolv.conf" as the arg. to open(), they can be certain; "ah, no a biggie, we have not created that file yet!" Issue #896 Signed-off-by: Joachim Wiberg --- ...-dispatcher-to-process-event-before-.patch | 2 +- ...ahi-daemon-allow-adjusting-log-level.patch | 2 +- ...rove-error-reporting-in-chroot-commu.patch | 60 +++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 patches/avahi/0003-avahi-daemon-improve-error-reporting-in-chroot-commu.patch diff --git a/patches/avahi/0001-On-SIGTERM-allow-dispatcher-to-process-event-before-.patch b/patches/avahi/0001-On-SIGTERM-allow-dispatcher-to-process-event-before-.patch index d9abc24c..6a3441fc 100644 --- a/patches/avahi/0001-On-SIGTERM-allow-dispatcher-to-process-event-before-.patch +++ b/patches/avahi/0001-On-SIGTERM-allow-dispatcher-to-process-event-before-.patch @@ -1,7 +1,7 @@ From 74ec0f8335f811e4f5becc8bbea4a52af4d3e749 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 17 Sep 2024 04:08:12 +0200 -Subject: [PATCH 1/2] On SIGTERM, allow dispatcher to process event before +Subject: [PATCH 1/3] On SIGTERM, allow dispatcher to process event before exiting Organization: Addiva Elektronik diff --git a/patches/avahi/0002-avahi-daemon-allow-adjusting-log-level.patch b/patches/avahi/0002-avahi-daemon-allow-adjusting-log-level.patch index 40be33cd..0b73ec1e 100644 --- a/patches/avahi/0002-avahi-daemon-allow-adjusting-log-level.patch +++ b/patches/avahi/0002-avahi-daemon-allow-adjusting-log-level.patch @@ -1,7 +1,7 @@ From bceb724d328f156efa4ad18f26f1760504bd093d Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 27 Nov 2024 08:44:57 +0100 -Subject: [PATCH 2/2] avahi-daemon: allow adjusting log level +Subject: [PATCH 2/3] avahi-daemon: allow adjusting log level Organization: Addiva Elektronik Signed-off-by: Joachim Wiberg diff --git a/patches/avahi/0003-avahi-daemon-improve-error-reporting-in-chroot-commu.patch b/patches/avahi/0003-avahi-daemon-improve-error-reporting-in-chroot-commu.patch new file mode 100644 index 00000000..5de92a72 --- /dev/null +++ b/patches/avahi/0003-avahi-daemon-improve-error-reporting-in-chroot-commu.patch @@ -0,0 +1,60 @@ +From 50ddfbefe5ac4d87040cb177e7cf432d4da04e97 Mon Sep 17 00:00:00 2001 +From: Joachim Wiberg +Date: Wed, 26 Feb 2025 17:42:08 +0100 +Subject: [PATCH 3/3] avahi-daemon: improve error reporting in chroot + communication +Organization: Addiva Elektronik + +Improve logging of error in chroot communication by including the +filename in the log message. Instead of this: + + avahi-daemon[3590]: chroot.c: open() failed: No such file or directory + +log this: + + avahi-daemon[3590]: chroot.c: open(/etc/resolv.conf) failed: No such file or directory + +Which on a system with resolvconf would make the sysadmin a lot calmer, +since the file had not yet been created at boot. + +Signed-off-by: Joachim Wiberg +--- + avahi-daemon/chroot.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/avahi-daemon/chroot.c b/avahi-daemon/chroot.c +index ccd56be..fbaad69 100644 +--- a/avahi-daemon/chroot.c ++++ b/avahi-daemon/chroot.c +@@ -237,12 +237,13 @@ static int helper_main(int fd) { + case AVAHI_CHROOT_GET_RECORD_BROWSER_INTROSPECT: + #endif + case AVAHI_CHROOT_GET_RESOLV_CONF: { ++ const char *fn = get_file_name_table[(int) command]; + int payload; + +- if ((payload = open(get_file_name_table[(int) command], O_RDONLY)) < 0) { ++ if ((payload = open(fn, O_RDONLY)) < 0) { + uint8_t c = AVAHI_CHROOT_FAILURE; + +- avahi_log_error(__FILE__": open() failed: %s", strerror(errno)); ++ avahi_log_error(__FILE__": open(%s) failed: %s", fn, strerror(errno)); + + if (write(fd, &c, sizeof(c)) != sizeof(c)) { + avahi_log_error(__FILE__": write() failed: %s\n", strerror(errno)); +@@ -262,9 +263,11 @@ static int helper_main(int fd) { + + case AVAHI_CHROOT_UNLINK_SOCKET: + case AVAHI_CHROOT_UNLINK_PID: { ++ const char *fn = unlink_file_name_table[(int) command]; + uint8_t c = AVAHI_CHROOT_SUCCESS; + +- unlink(unlink_file_name_table[(int) command]); ++ if (unlink(fn) && errno != ENOENT) ++ avahi_log_error(__FILE__": unlink(%s) failed: %s", fn, strerror(errno)); + + if (write(fd, &c, sizeof(c)) != sizeof(c)) { + avahi_log_error(__FILE__": write() failed: %s\n", strerror(errno)); +-- +2.43.0 + From 3e07c9a96013c12c0e6dc55928d9f77ab5f27b24 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 28 Feb 2025 11:42:40 +0100 Subject: [PATCH 2/7] Fix missing /etc/resolv.conf when starting with failure-config Turns out the root cause for the odd log message in #896 was that the system did not properly call `resolvconf -u` when starting in failure mode. This patch simplifies the code by moving all `resolvconf -u` calls to the same Finit task. Ensuring it is first launched when confd has successfully consumed any configuration at boot, and then every time a static DNS server is added. (The udhcpc client script already call `resolvconf -u` when dynamic DNS servers are learned.) Fixes #896 Signed-off-by: Joachim Wiberg --- package/confd/confd.conf | 5 ----- package/confd/confd.mk | 6 ++++-- package/confd/resolvconf.conf | 3 +++ src/confd/src/core.c | 5 ++++- src/confd/src/ietf-system.c | 7 ++----- 5 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 package/confd/resolvconf.conf diff --git a/package/confd/confd.conf b/package/confd/confd.conf index c8dcf4eb..91bc58ec 100644 --- a/package/confd/confd.conf +++ b/package/confd/confd.conf @@ -29,8 +29,3 @@ run name:error :2 log:console norestart \ service name:netopeer notify:none log env:/etc/default/confd \ [12345] netopeer2-server -F -t $CONFD_TIMEOUT -v 1 \ -- NETCONF server - -# Create initial /etc/resolv.conf after successful bootstrap -task name:resolv :conf norestart \ - if: \ - [S] resolvconf -u -- Update DNS configuration diff --git a/package/confd/confd.mk b/package/confd/confd.mk index 4d9fe8a5..4309ee2d 100644 --- a/package/confd/confd.mk +++ b/package/confd/confd.mk @@ -26,8 +26,10 @@ CONFD_CONF_OPTS += --disable-containers endif define CONFD_INSTALL_EXTRA - cp $(CONFD_PKGDIR)/confd.conf $(FINIT_D)/available/ - ln -sf ../available/confd.conf $(FINIT_D)/enabled/confd.conf + for fn in confd.conf resolvconf.conf; do \ + cp $(CONFD_PKGDIR)/$$fn $(FINIT_D)/available/; \ + ln -sf ../available/$$fn $(FINIT_D)/enabled/$$fn; \ + done cp $(CONFD_PKGDIR)/tmpfiles.conf $(TARGET_DIR)/etc/tmpfiles.d/confd.conf mkdir -p $(TARGET_DIR)/etc/avahi/services cp $(CONFD_PKGDIR)/avahi.service $(TARGET_DIR)/etc/avahi/services/netconf.service diff --git a/package/confd/resolvconf.conf b/package/confd/resolvconf.conf new file mode 100644 index 00000000..e08a1acc --- /dev/null +++ b/package/confd/resolvconf.conf @@ -0,0 +1,3 @@ +# Create initial /etc/resolv.conf after successful bootstrap, regardless +# of startup-config or failure-config. Condition set by confd. +task [S12345] resolvconf -u -- Update DNS configuration diff --git a/src/confd/src/core.c b/src/confd/src/core.c index f8e6bc2e..ba987f4b 100644 --- a/src/confd/src/core.c +++ b/src/confd/src/core.c @@ -76,8 +76,11 @@ int core_post_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *modul } /* skip reload in bootstrap, implicit reload in runlevel change */ - if (systemf("runlevel >/dev/null 2>&1")) + if (systemf("runlevel >/dev/null 2>&1")) { + /* trigger any tasks waiting for confd to have applied *-config */ + system("initctl -nbq cond set bootstrap"); return SR_ERR_OK; + } if (systemf("initctl -b reload")) return SR_ERR_SYS; diff --git a/src/confd/src/ietf-system.c b/src/confd/src/ietf-system.c index 5f2bb746..0532797e 100644 --- a/src/confd/src/ietf-system.c +++ b/src/confd/src/ietf-system.c @@ -540,11 +540,8 @@ static int change_dns(sr_session_ctx_t *session, uint32_t sub_id, const char *mo (void)rename(RESOLV_NEXT, RESOLV_CONF); } - /* in bootstrap, another resolvconf will soon take your call */ - if (systemf("initctl -bq cond get hook/sys/up")) - return 0; + systemf("initctl -bq touch resolvconf"); - systemf("resolvconf -u"); return SR_ERR_OK; default: @@ -1761,7 +1758,7 @@ static int change_hostname(sr_session_ctx_t *session, uint32_t sub_id, const cha /* Inform any running lldpd and avahi of the change ... */ systemf("initctl -bq status lldpd && lldpcli configure system hostname %s", hostnm); systemf("initctl -bq status mdns && avahi-set-host-name %s", hostnm); - systemf("initctl -nbq touch netbrowse"); + systemf("initctl -bq touch netbrowse"); err: if (fmt) free(fmt); From 62a4b48679ebeb6e5ea83fe19f4a7eb90245e3f7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 28 Feb 2025 11:50:43 +0100 Subject: [PATCH 3/7] patches/openresolv: drop unused patches Signed-off-by: Joachim Wiberg --- patches/openresolv/3.12.0/finit-support.patch | 12 ------------ .../openresolv/foo-3.12.0/finit-support.patch | 16 ---------------- 2 files changed, 28 deletions(-) delete mode 100644 patches/openresolv/3.12.0/finit-support.patch delete mode 100644 patches/openresolv/foo-3.12.0/finit-support.patch diff --git a/patches/openresolv/3.12.0/finit-support.patch b/patches/openresolv/3.12.0/finit-support.patch deleted file mode 100644 index 6b9be23e..00000000 --- a/patches/openresolv/3.12.0/finit-support.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff -ru openresolv-3.12.0.orig/resolvconf.in openresolv-3.12.0/resolvconf.in ---- openresolv-3.12.0.orig/resolvconf.in 2020-12-27 19:05:10.000000000 +0100 -+++ openresolv-3.12.0/resolvconf.in 2023-03-27 00:19:03.365164029 +0200 -@@ -315,6 +315,8 @@ - then - /usr/bin/systemctl restart $1.service - fi' -+ elif [ -x /sbin/initctl ]; then -+ RESTARTCMD="/sbin/initctl -bnq restart \$1" - elif [ -x /sbin/rc-service ] && - { [ -s /libexec/rc/init.d/softlevel ] || - [ -s /run/openrc/softlevel ]; } diff --git a/patches/openresolv/foo-3.12.0/finit-support.patch b/patches/openresolv/foo-3.12.0/finit-support.patch deleted file mode 100644 index 1e1588df..00000000 --- a/patches/openresolv/foo-3.12.0/finit-support.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff -ru openresolv-3.12.0.orig/resolvconf.in openresolv-3.12.0/resolvconf.in ---- openresolv-3.12.0.orig/resolvconf.in 2020-12-27 19:05:10.000000000 +0100 -+++ openresolv-3.12.0/resolvconf.in 2023-03-27 00:19:03.365164029 +0200 -@@ -315,6 +315,12 @@ - then - /usr/bin/systemctl restart $1.service - fi' -+ elif [ -x /sbin/initctl ]; then -+ # Finit -+ RESTARTCMD=' -+ if /sbin/initctl -bq status $1; then -+ /sbin/initctl -bnq restart $1 -+ fi' - elif [ -x /sbin/rc-service ] && - { [ -s /libexec/rc/init.d/softlevel ] || - [ -s /run/openrc/softlevel ]; } From 172d7607bb890b62bbbca7d6bc14ce48b32cbdf8 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 28 Feb 2025 11:51:44 +0100 Subject: [PATCH 4/7] statd: add missing .pid file, used for readiness signaling Signed-off-by: Joachim Wiberg --- src/statd/statd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/statd/statd.c b/src/statd/statd.c index 1fa66e41..11e3aaec 100644 --- a/src/statd/statd.c +++ b/src/statd/statd.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -409,6 +410,9 @@ int main(int argc, char *argv[]) sigusr1_watcher.data = &statd; ev_signal_start(statd.ev_loop, &sigusr1_watcher); + /* Signal readiness to Finit */ + pidfile(NULL); + INFO("Status daemon entering main event loop"); ev_run(statd.ev_loop, 0); From 581d1742e5a359e277a5af4065b1bd883c6c4a2e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 28 Feb 2025 12:19:48 +0100 Subject: [PATCH 5/7] package/finit: bump to v4.10-rc2 ChangeLog: https://github.com/troglobit/finit/releases/tag/4.10-rc2 Signed-off-by: Joachim Wiberg --- package/finit/finit.hash | 2 +- package/finit/finit.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package/finit/finit.hash b/package/finit/finit.hash index 813e0ad1..be07d5ef 100644 --- a/package/finit/finit.hash +++ b/package/finit/finit.hash @@ -1,5 +1,5 @@ # From https://github.com/troglobit/finit/releases/ -sha256 ead37606012ced935c66dcfd88786d533d08964b00adb7899ea156ae29b7896a finit-4.10-rc1.tar.gz +sha256 40c8db203cb59381973146f7157bde6886f05de06f18f1bd567c70ee780cbe3f finit-4.10-rc2.tar.gz # Locally calculated sha256 2fd62c0fe6ea6d1861669f4c87bda83a0b5ceca64f4baa4d16dd078fbd218c14 LICENSE diff --git a/package/finit/finit.mk b/package/finit/finit.mk index eec7fede..37dbdb95 100644 --- a/package/finit/finit.mk +++ b/package/finit/finit.mk @@ -4,7 +4,7 @@ # ################################################################################ -FINIT_VERSION = 4.10-rc1 +FINIT_VERSION = 4.10-rc2 FINIT_SITE = https://github.com/troglobit/finit/releases/download/$(FINIT_VERSION) FINIT_LICENSE = MIT FINIT_LICENSE_FILES = LICENSE From 90d2ae3868dc0370b3edcc401fc2f45a5b6648e8 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 28 Feb 2025 13:49:38 +0100 Subject: [PATCH 6/7] doc: update restconf section with some more examples Signed-off-by: Joachim Wiberg --- doc/scripting.md | 59 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/doc/scripting.md b/doc/scripting.md index a2258bc3..f7da8e9e 100644 --- a/doc/scripting.md +++ b/doc/scripting.md @@ -853,14 +853,18 @@ models for details. ### Factory Reset ``` -~$ curl -kX POST -H "Content-Type: application/yang-data+json" https://example.local/restconf/operations/ietf-factory-default:factory-reset -u admin:admin +~$ curl -kX POST -u admin:admin \ + -H "Content-Type: application/yang-data+json" \ + https://example.local/restconf/operations/ietf-factory-default:factory-reset curl: (56) OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0 ``` ### System Reboot ``` -~$ curl -kX POST -H "Content-Type: application/yang-data+json" https://example.local/restconf/operations/ietf-system:system-restart -u admin:admin +~$ curl -kX POST -u admin:admin \ + -H "Content-Type: application/yang-data+json" \ + https://example.local/restconf/operations/ietf-system:system-restart ``` ### Set Date and Time @@ -868,7 +872,11 @@ curl: (56) OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while r Here's an example of an RPC that takes input/argument: ``` -~$ curl -kX POST -H "Content-Type: application/yang-data+json" https://example.local/restconf/operations/ietf-system:set-current-datetime -u admin:admin -d '{"ietf-system:input": {"current-datetime": "2024-04-17T13:48:02-01:00"}}' +~$ curl -kX POST -u admin:admin \ + -H "Content-Type: application/yang-data+json" \ + -d '{"ietf-system:input": {"current-datetime": "2024-04-17T13:48:02-01:00"}}' \ + https://example.local/restconf/operations/ietf-system:set-current-datetime + ``` You can verify that the changes took by a remote SSH command: @@ -879,6 +887,51 @@ Wed Apr 17 14:48:12 UTC 2024 ~$ ``` +### Read Hostname + +Example of fetching JSON configuration data to stdout: + +``` +~$ curl -kX GET -u admin:admin \ + -H 'Accept: application/yang-data+json' \ + https://example.local/restconf/data/ietf-system:system/hostname +{ + "ietf-system:system": { + "hostname": "foo" + } +} +``` + +### Set Hostname + +Example of inline JSON data: + +``` +~$ curl -kX PATCH -u admin:admin \ + -H 'Content-Type: application/yang-data+json' \ + -d '{"ietf-system:system":{"hostname":"bar"}}' \ + https://example.local/restconf/data/ietf-system:system +``` + +### Copy Running to Startup + +No copy command available yet to copy between datastores, and the +Rousette back-end also does not support "write-through" to the +startup datastore. + +To save running-config to startup-config, use the following example to +fetch running to a local file and then update startup with it: + +``` +~$ curl -kX GET -u admin:admin -o running-config.json \ + -H 'Accept: application/yang-data+json' \ + https://example.local/restconf/ds/ietf-datastores:running + +~$ curl -kX PUT -u admin:admin -d @running-config.json \ + -H 'Content-Type: application/yang-data+json' \ + https://example.local/restconf/ds/ietf-datastores:startup +``` + ## Miscellaneous From 3867abe4dabf7b08577ff44eb33b64e0c13612d4 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 28 Feb 2025 16:14:09 +0100 Subject: [PATCH 7/7] doc: update ChangeLog [skip ci] Signed-off-by: Joachim Wiberg --- doc/ChangeLog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index c1012e80..cca12dfa 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -4,7 +4,7 @@ Change Log All notable changes to the project are documented in this file. -[v25.02.0][UNRELASED] - +[v25.02.0][] - 2025-03-03 ------------------------- ### Changes @@ -18,8 +18,11 @@ All notable changes to the project are documented in this file. setting. Note, route advertisements are always accepted. Issue #785 - Drop automatic default route (interface route) for IPv4 autoconf, not necessary and causes more confusion than good. Issue #923 + - Update scripting with new RESTCONF examples ### Fixes + - Fix #896: `/etc/resolv.conf` not properly generated when system runs + in fail secure mode (failing to load `startup-config`) - Fix #902: containers "linger" in the system (state 'exited') after having removed them from the configuration - Fix #930: container configuration changes does not apply at runtime