From a7cc1c6362f72b99147366abb06475bf0ce0200f Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 18 Feb 2025 10:13:59 +0100 Subject: [PATCH] New clixon-restconf@2025-02-01.yang revision: timeout parameter --- CHANGELOG.md | 4 ++- apps/backend/backend_client.c | 1 + apps/restconf/restconf_main_native.c | 30 ++++++++++++------- lib/clixon/clixon_log.h | 2 +- test/test_restconf_notifications.sh | 5 ++-- yang/clixon/Makefile.in | 2 +- ...1.yang => clixon-restconf@2025-02-01.yang} | 23 +++++++++++--- 7 files changed, 47 insertions(+), 20 deletions(-) rename yang/clixon/{clixon-restconf@2022-03-21.yang => clixon-restconf@2025-02-01.yang} (93%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a6964a3..6b6362bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Clixon Changelog -* [7.4.0](#730) Planned: April 2025 +* [7.4.0](#740) Planned: April 2025 * [7.3.0](#730) 30 January 2025 * [7.2.0](#720) 28 October 2024 * [7.1.0](#710) 3 July 2024 @@ -19,6 +19,8 @@ Planned: April 2025 ### Features * Added new `ca_userdef` callback +* New `clixon-restconf@2025-02-01.yang` revision + * Added timeout parameter ## 7.3.0 30 January 2025 diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 058f536c..2927e285 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -1187,6 +1187,7 @@ from_client_create_subscription(clixon_handle h, struct timeval stop; cvec *nsc = NULL; + clixon_debug(CLIXON_DBG_STREAM, ""); /* XXX should use prefix cf edit_config */ if ((nsc = xml_nsctx_init(NULL, EVENT_RFC5277_NAMESPACE)) == NULL) goto done; diff --git a/apps/restconf/restconf_main_native.c b/apps/restconf/restconf_main_native.c index a60b962f..1fb4207c 100644 --- a/apps/restconf/restconf_main_native.c +++ b/apps/restconf/restconf_main_native.c @@ -676,13 +676,13 @@ restconf_clixon_backend(clixon_handle h, clicon_session_id_set(h, id); break; } + /* XXX HARDCODED NAMESPACE NEEDS GENERIC MECHANISM + * It works if one uses "import clixon-restconf" + * But not if one does uses clixon-restdonf in which case the namespace is + * the local (top-level). + */ if ((nsc = xml_nsctx_init(NULL, - /* XXX HARDCODED NAMESPACE NEEDS GENERIC MECHANISM */ -#if 1 - "http://clicon.org/controller" -#else CLIXON_RESTCONF_NS -#endif )) == NULL) goto done; if ((pw = getpwuid(getuid())) == NULL){ @@ -822,15 +822,15 @@ openssl_init_socket(clixon_handle h, * @param[in] h Clixon handle * @param[in] dbg0 Manually set debug flag, if set overrides configuration setting * @param[in] xrestconf XML tree containing restconf config - * @param[in] timeout Terminate notification stream after number of seconds + * @param[in] timeout0 Command-line timeout (overrides if set config timeout) * @retval 0 OK * @retval -1 Error */ -int +static int restconf_openssl_init(clixon_handle h, int dbg0, cxobj *xrestconf, - int timeout) + int timeout0) { int retval = -1; SSL_CTX *ctx; /* SSL context */ @@ -847,12 +847,22 @@ restconf_openssl_init(clixon_handle h, cxobj **vec = NULL; size_t veclen; int i; + int timeout = 0; clixon_debug(CLIXON_DBG_RESTCONF, ""); /* flag used for sanity of certs */ ssl_enable = xpath_first(xrestconf, nsc, "socket[ssl='true']") != NULL; /* Auth type set in config */ auth_type = restconf_auth_type_get(h); + /* Timeout */ + if ((x = xpath_first(xrestconf, nsc, "timeout")) != NULL && + (bstr = xml_body(x)) != NULL){ + timeout = atoi(bstr); + } + /* Command-line overrides */ + if (timeout0 != 0) + timeout = timeout0; + /* Only set debug from config if not set manually */ if (dbg0 == 0 && (x = xpath_first(xrestconf, nsc, "debug")) != NULL && @@ -1311,7 +1321,7 @@ main(int argc, if (clicon_option_add(h, "CLICON_RESTCONF_PRIVILEGES", "none") < 0) goto done; break; - case 'W': /* Run restconf daemon as this user (afetr drop) */ + case 'W': /* Run restconf daemon as this user (after drop) */ if (clicon_option_add(h, "CLICON_RESTCONF_USER", optarg) < 0) goto done; break; @@ -1372,7 +1382,7 @@ main(int argc, retval = 0; goto done; } - /* Create and stroe global openssl handle */ + /* Create and store global openssl handle */ if ((rn = malloc(sizeof *rn)) == NULL){ clixon_err(OE_UNIX, errno, "malloc"); goto done; diff --git a/lib/clixon/clixon_log.h b/lib/clixon/clixon_log.h index e499605f..f326c5f9 100644 --- a/lib/clixon/clixon_log.h +++ b/lib/clixon/clixon_log.h @@ -53,7 +53,7 @@ #define CLIXON_LOG_SYSLOG 0x01 /* print logs on syslog */ #define CLIXON_LOG_STDERR 0x02 /* print logs on stderr */ #define CLIXON_LOG_STDOUT 0x04 /* print logs on stdout */ -#define CLIXON_LOG_FILE 0x08 /* print logs on clixon_log_filename */ +#define CLIXON_LOG_FILE 0x08 /* print logs on clixon_log_file() */ /* What kind of log (only for customizable error/logs) */ enum clixon_log_type{ diff --git a/test/test_restconf_notifications.sh b/test/test_restconf_notifications.sh index 19870c98..c8be194b 100755 --- a/test/test_restconf_notifications.sh +++ b/test/test_restconf_notifications.sh @@ -299,12 +299,11 @@ fi test-pause sleep 5 -# Try parallell -# start background job +# Start curl in background and save PID curl $CURLOPTS -X GET -H "Accept: text/event-stream" -H "Cache-Control: no-cache" -H "Connection: keep-alive" "$RCPROTO://localhost/streams/EXAMPLE" & # > /dev/null & PID=$! -new "Start subscriptions in parallell" +new "Start subscription" ret=$($clixon_util_stream -u $RCPROTO://localhost/streams/EXAMPLE -t 8) expect="data: ${DATE}T[0-9:.]*ZfaultEthernet0major" diff --git a/yang/clixon/Makefile.in b/yang/clixon/Makefile.in index ad588ff7..bc006d92 100644 --- a/yang/clixon/Makefile.in +++ b/yang/clixon/Makefile.in @@ -46,7 +46,7 @@ YANGSPECS = clixon-config@2024-11-01.yang # 7.3 YANGSPECS += clixon-lib@2024-11-01.yang # 7.3 YANGSPECS += clixon-rfc5277@2008-07-01.yang YANGSPECS += clixon-xml-changelog@2019-03-21.yang -YANGSPECS += clixon-restconf@2022-08-01.yang # 5.9 +YANGSPECS += clixon-restconf@2025-02-01.yang # 7.4 YANGSPECS += clixon-autocli@2024-08-01.yang # 7.2 all: diff --git a/yang/clixon/clixon-restconf@2022-03-21.yang b/yang/clixon/clixon-restconf@2025-02-01.yang similarity index 93% rename from yang/clixon/clixon-restconf@2022-03-21.yang rename to yang/clixon/clixon-restconf@2025-02-01.yang index d0be9ca8..6b9a4d3f 100644 --- a/yang/clixon/clixon-restconf@2022-03-21.yang +++ b/yang/clixon/clixon-restconf@2025-02-01.yang @@ -17,7 +17,7 @@ module clixon-restconf { "This YANG module provides a data-model for the Clixon RESTCONF daemon. There is also clixon-config also including some restconf options. The separation is not always logical but there are some reasons for the split: - 1. Some data (ie 'socket') is structurally complex and cannot be expressed as a + 1. Some data (ie 'socket') is structurally complex and cannot be expressed as a simple option 2. clixon-restconf is defined as a macro/grouping and can be included in other YANGs. In particular, it can be used inside a datastore, which @@ -53,6 +53,11 @@ module clixon-restconf { ***** END LICENSE BLOCK *****"; + revision 2025-02-01 { + description + "Added timeout parameter + Released in Clixon 7.4"; + } revision 2022-03-21 { description "Added feature: @@ -185,8 +190,9 @@ module clixon-restconf { } leaf log-destination { description - "Log destination. - If debug is not set, only notice, error and warning will be logged"; + "Log destination. + If debug is not set, only notice, error and warning will be logged + If log-destination is file, the actual file is /var/log/clixon_restconf.log"; type log-destination; default syslog; } @@ -243,6 +249,14 @@ module clixon-restconf { "Path to server CA cert file Note only applies if socket has ssl enabled"; } + leaf timeout { + description + "Timeout of individual sessions. + Useful when debugging long-poll server-sent event streams"; + type uint32; + default 0; + units "seconds"; + } list socket { description "List of server sockets that the restconf daemon listens to. @@ -272,7 +286,8 @@ module clixon-restconf { } container restconf { description - "This presence is strictly not necessary since the enable flag + "If imported, this container appears in top-level configuration. + The presence statement is strictly not necessary since the enable flag in clixon-restconf is the flag bearing the actual semantics. However, removing the presence leads to default config in all clixon installations, even those which do not use backend-started restconf.