config UPDATE add hello/idle timeouts leaves
diff --git a/doc/libnetconf.doc b/doc/libnetconf.doc
index 20be760..c4d7353 100644
--- a/doc/libnetconf.doc
+++ b/doc/libnetconf.doc
@@ -289,8 +289,6 @@
* determined by the context used when accepting new NETCONF sessions. Few capabilities that
* cannot be learnt from the context are set with separate functions
* ::nc_server_set_capab_withdefaults() and generally ::nc_server_set_capability().
- * Timeout for receiving the _hello_ message on a new session can be set
- * by ::nc_server_set_hello_timeout().
*
* Context does not only determine server modules, but its overall
* functionality as well. For every RPC the server should support,
@@ -310,7 +308,6 @@
*
* - ::nc_server_set_capab_withdefaults()
* - ::nc_server_set_capability()
- * - ::nc_server_set_hello_timeout()
*
* Server Configuration
* ===
@@ -701,8 +698,8 @@
* You can adjust active and inactive read timeout using `cmake` variables.
* For details look into `README.md`.
*
- * API Functions
- * -------------
+ * Configurable timeouts
+ * ---------------------
*
* Once a new connection is established including transport protocol negotiations,
* _hello_ message is exchanged. You can set how long will the server wait for
@@ -712,19 +709,10 @@
* To free up some resources, it is possible to adjust the maximum idle period
* of a session before it is disconnected. In _Call Home_, for both a persistent
* and periodic connection can this idle timeout be specified separately for each
- * client using corresponding functions. Unlike other timeouts, the idle timeout
- * can only be set via applying configuration data.
- *
- * Lastly, SSH user authentication timeout can be also modified. It is the time
+ * client. Lastly, SSH user authentication timeout can be also modified. It is the time
* a client has to successfully authenticate after connecting before it is disconnected.
*
- * Functions List
- * --------------
- *
- * Available in __nc_server.h__.
- *
- * - ::nc_server_set_hello_timeout()
- * - ::nc_server_get_hello_timeout()
+ * These timeouts can be toggled by applying corresponding configuration data.
*/
/**
diff --git a/modules/libnetconf2-netconf-server@2023-09-07.yang b/modules/libnetconf2-netconf-server@2023-09-07.yang
index 2f9d26f..9708c54 100644
--- a/modules/libnetconf2-netconf-server@2023-09-07.yang
+++ b/modules/libnetconf2-netconf-server@2023-09-07.yang
@@ -240,6 +240,24 @@
https://cvsweb.openbsd.org/src/usr.bin/ssh/PROTOCOL?annotate=HEAD";
}
+ augment "/ncs:netconf-server" {
+ leaf hello-timeout {
+ type uint16;
+ default 60;
+ description
+ "Represents the maximum number of seconds the server will wait for receiving a hello message.";
+ }
+ }
+
+ augment "/ncs:netconf-server" {
+ leaf idle-timeout {
+ type uint16;
+ default 0;
+ description
+ "Represents the maximum number of seconds a NETCONF session may remain idle. The value of 0 represents indefinitely.";
+ }
+ }
+
augment "/ncs:netconf-server/ncs:listen/ncs:endpoint/ncs:transport/ncs:ssh/ncs:ssh/ncs:ssh-server-parameters/ncs:client-authentication" {
leaf auth-attempts {
type uint16;
diff --git a/src/server_config.c b/src/server_config.c
index 328367b..63bf0c1 100644
--- a/src/server_config.c
+++ b/src/server_config.c
@@ -1157,20 +1157,29 @@
/* default leaf */
static int
+nc_server_config_hello_timeout(const struct lyd_node *node, NC_OPERATION op)
+{
+ assert(!strcmp(LYD_NAME(node), "hello-timeout"));
+
+ if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
+ server_opts.hello_timeout = strtoul(lyd_get_value(node), NULL, 10);
+ } else {
+ /* default value */
+ server_opts.hello_timeout = 60;
+ }
+
+ return 0;
+}
+
+/* default leaf */
+static int
nc_server_config_idle_timeout(const struct lyd_node *node, NC_OPERATION op)
{
struct nc_ch_client *ch_client;
assert(!strcmp(LYD_NAME(node), "idle-timeout"));
- if (is_listen(node)) {
- if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
- server_opts.idle_timeout = strtoul(lyd_get_value(node), NULL, 10);
- } else {
- /* default value */
- server_opts.idle_timeout = 180;
- }
- } else {
+ if (is_ch(node)) {
/* call-home idle timeout */
if (nc_server_config_get_ch_client_with_lock(node, &ch_client)) {
/* to avoid unlock on fail */
@@ -1184,6 +1193,14 @@
}
nc_ch_client_unlock(ch_client);
+ } else {
+ /* whole server idle timeout */
+ if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
+ server_opts.idle_timeout = strtoul(lyd_get_value(node), NULL, 10);
+ } else {
+ /* default value */
+ server_opts.idle_timeout = 0;
+ }
}
return 0;
@@ -4207,8 +4224,8 @@
ret = nc_server_config_listen(node, op);
} else if (!strcmp(name, "call-home")) {
ret = nc_server_config_ch(node, op);
- } else if (!strcmp(name, "idle-timeout")) {
- ret = nc_server_config_idle_timeout(node, op);
+ } else if (!strcmp(name, "hello-timeout")) {
+ ret = nc_server_config_hello_timeout(node, op);
} else if (!strcmp(name, "endpoint")) {
ret = nc_server_config_endpoint(node, op);
} else if (!strcmp(name, "unix-socket")) {
@@ -4309,6 +4326,8 @@
ret = nc_server_config_period(node, op);
} else if (!strcmp(name, "anchor-time")) {
ret = nc_server_config_anchor_time(node, op);
+ } else if (!strcmp(name, "idle-timeout")) {
+ ret = nc_server_config_idle_timeout(node, op);
} else if (!strcmp(name, "reconnect-strategy")) {
ret = nc_server_config_reconnect_strategy(node, op);
} else if (!strcmp(name, "start-with")) {
diff --git a/src/session_server.c b/src/session_server.c
index 7e37cb0..be53450 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -959,24 +959,6 @@
server_opts.content_id_data_free = free_user_data;
}
-API void
-nc_server_set_hello_timeout(uint16_t hello_timeout)
-{
- server_opts.hello_timeout = hello_timeout;
-}
-
-API uint16_t
-nc_server_get_hello_timeout(void)
-{
- return server_opts.hello_timeout;
-}
-
-API uint16_t
-nc_server_get_idle_timeout(void)
-{
- return server_opts.idle_timeout;
-}
-
API NC_MSG_TYPE
nc_accept_inout(int fdin, int fdout, const char *username, const struct ly_ctx *ctx, struct nc_session **session)
{
diff --git a/src/session_server.h b/src/session_server.h
index 660bada..d9486f0 100644
--- a/src/session_server.h
+++ b/src/session_server.h
@@ -200,20 +200,6 @@
void (*free_user_data)(void *user_data));
/**
- * @brief Set server timeout for receiving a hello message.
- *
- * @param[in] hello_timeout Hello message timeout. 0 for infinite waiting.
- */
-void nc_server_set_hello_timeout(uint16_t hello_timeout);
-
-/**
- * @brief get server timeout for receiving a hello message.
- *
- * @return Hello message timeout, 0 is infinite.
- */
-uint16_t nc_server_get_hello_timeout(void);
-
-/**
* @brief Get all the server capabilities including all the schemas.
*
* A few capabilities (with-defaults, interleave) depend on the current