Skip to content

Commit cddf61b

Browse files
committed
session UPDATE support for modules ignored when creating hello
1 parent 23a5fee commit cddf61b

File tree

5 files changed

+94
-7
lines changed

5 files changed

+94
-7
lines changed
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ module libnetconf2-netconf-server {
3131
prefix tlss;
3232
}
3333

34+
revision "2025-01-23" {
35+
description "Added a list of YANG modules skipped in the server <hello> message.";
36+
}
37+
3438
revision "2024-07-09" {
3539
description "Second revision.";
3640
}
@@ -428,11 +432,11 @@ module libnetconf2-netconf-server {
428432
if-feature "ct:certificate-expiration-notification";
429433

430434
description
431-
"Container for the certificate expiration notification intervals.
432-
Its child nodes describe the ability to set the time intervals for the certificate
433-
expiration notifications. These intervals are given in the form of an anchor and a period.
434-
By default, these notifications are generated 3, 2, and 1 month; 2 weeks; 7, 6, 5, 4, 3, 2 and 1 day before a certificate expires.
435-
Additionally, notifications are generated on the day of expiration and every day thereafter.
435+
"Container for the certificate expiration notification intervals. Its child nodes describe the ability to set
436+
the time intervals for the certificate expiration notifications. These intervals are given in the form of an
437+
anchor and a period. By default, these notifications are generated 3, 2, and 1 month; 2 weeks; 7, 6, 5, 4, 3,
438+
2 and 1 day before a certificate expires. Additionally, notifications are generated on the day of expiration
439+
and every day thereafter.
436440
437441
Simplified example of YANG data that describe the default intervals:
438442
@@ -471,5 +475,12 @@ module libnetconf2-netconf-server {
471475
}
472476
}
473477
}
478+
479+
leaf-list ignored-hello-module {
480+
type string;
481+
482+
description
483+
"List of implemented sysrepo YANG modules that will not be reported the NETCONF server in its <hello> messages.";
484+
}
474485
}
475486
}

src/server_config.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4014,13 +4014,20 @@ nc_server_config_parse_netconf_server(const struct lyd_node *node, enum nc_opera
40144014
}
40154015

40164016
int
4017-
nc_server_config_ln2_netconf_server(const struct lyd_node *node, enum nc_operation op)
4017+
nc_server_config_ln2_netconf_server(const struct lyd_node *UNUSED(node), enum nc_operation op)
40184018
{
4019-
(void) node;
4019+
uint32_t i;
40204020

40214021
assert((op == NC_OP_CREATE) || (op == NC_OP_DELETE));
40224022

40234023
if (op == NC_OP_DELETE) {
4024+
/* delete ignored modules */
4025+
for (i = 0; i < server_opts.ignored_mod_count; ++i) {
4026+
free(server_opts.ignored_modules[i]);
4027+
}
4028+
free(server_opts.ignored_modules);
4029+
server_opts.ignored_modules = NULL;
4030+
server_opts.ignored_mod_count = 0;
40244031

40254032
#ifdef NC_ENABLED_SSH_TLS
40264033
/* delete the intervals */
@@ -4163,6 +4170,45 @@ nc_server_config_interval(const struct lyd_node *node, enum nc_operation op)
41634170

41644171
#endif /* NC_ENABLED_SSH_TLS */
41654172

4173+
static int
4174+
nc_server_config_ignored_module(const struct lyd_node *node, enum nc_operation op)
4175+
{
4176+
int ret = 0;
4177+
const char *mod_name;
4178+
uint16_t i;
4179+
4180+
assert(!strcmp(LYD_NAME(node), "ignored-hello-module"));
4181+
4182+
mod_name = lyd_get_value(node);
4183+
4184+
if (op == NC_OP_CREATE) {
4185+
/* add the module */
4186+
ret = nc_server_config_realloc(mod_name, (void **)&server_opts.ignored_modules,
4187+
sizeof *server_opts.ignored_modules, &server_opts.ignored_mod_count);
4188+
} else {
4189+
/* find the module */
4190+
for (i = 0; i < server_opts.ignored_mod_count; ++i) {
4191+
if (!strcmp(server_opts.ignored_modules[i], mod_name)) {
4192+
break;
4193+
}
4194+
}
4195+
assert(i < server_opts.ignored_mod_count);
4196+
4197+
/* remove the module by replacing it with the last */
4198+
free(server_opts.ignored_modules[i]);
4199+
if (i < server_opts.ignored_mod_count - 1) {
4200+
server_opts.ignored_modules[i] = server_opts.ignored_modules[server_opts.ignored_mod_count - 1];
4201+
}
4202+
--server_opts.ignored_mod_count;
4203+
if (!server_opts.ignored_mod_count) {
4204+
free(server_opts.ignored_modules);
4205+
server_opts.ignored_modules = NULL;
4206+
}
4207+
}
4208+
4209+
return ret;
4210+
}
4211+
41664212
static int
41674213
nc_server_config_parse_libnetconf2_netconf_server(const struct lyd_node *node, enum nc_operation op)
41684214
{
@@ -4177,6 +4223,9 @@ nc_server_config_parse_libnetconf2_netconf_server(const struct lyd_node *node, e
41774223
ret = nc_server_config_interval(node, op);
41784224
}
41794225
#endif /* NC_ENABLED_SSH_TLS */
4226+
else if (!strcmp(name, "ignored-hello-module")) {
4227+
ret = nc_server_config_ignored_module(node, op);
4228+
}
41804229

41814230
if (ret) {
41824231
ERR(NULL, "Configuring node \"%s\" failed.", LYD_NAME(node));

src/session.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,11 @@ nc_server_get_cpblts_version(const struct ly_ctx *ctx, LYS_VERSION version)
12051205
/* models */
12061206
u = 0;
12071207
while ((mod = ly_ctx_get_module_iter(ctx, &u))) {
1208+
if (nc_server_is_mod_ignored(mod->name)) {
1209+
/* ignored, not part of the cababilities */
1210+
continue;
1211+
}
1212+
12081213
if (!strcmp(mod->name, "ietf-yang-library")) {
12091214
if (!mod->revision || (strcmp(mod->revision, "2016-06-21") && strcmp(mod->revision, "2019-01-04"))) {
12101215
ERR(NULL, "Unknown \"ietf-yang-library\" revision, only 2016-06-21 and 2019-01-04 are supported.");

src/session_p.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,14 @@ int nc_session_tls_crl_from_cert_ext_fetch(void *leaf_cert, void *cert_store, vo
12381238

12391239
#endif /* NC_ENABLED_SSH_TLS */
12401240

1241+
/**
1242+
* @brief Check whether a module is not ignored by the server.
1243+
*
1244+
* @param[in] mod_name Module name to check.
1245+
* @return Whether the module is ignored.
1246+
*/
1247+
int nc_server_is_mod_ignored(const char *mod_name);
1248+
12411249
/**
12421250
* Functions
12431251
* - io.c

src/session_server.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,3 +4080,17 @@ nc_server_notif_cert_expiration_thread_stop(int wait)
40804080
}
40814081

40824082
#endif /* NC_ENABLED_SSH_TLS */
4083+
4084+
int
4085+
nc_server_is_mod_ignored(const char *mod_name)
4086+
{
4087+
uint16_t i;
4088+
4089+
for (i = 0; i < server_opts.ignored_mod_count; ++i) {
4090+
if (!strcmp(server_opts.ignored_modules[i], mod_name)) {
4091+
return 1;
4092+
}
4093+
}
4094+
4095+
return 0;
4096+
}

0 commit comments

Comments
 (0)