Skip to content

Commit 706232b

Browse files
committed
monitoring BUGFIX advertise YANG 1.1 modules in capabilities
The ietf-netconf-monitoring operational callback used nc_server_get_cpblts_version(ly_ctx, LYS_VERSION_1_0) to build the capabilities list, excluding all YANG 1.1 modules. This was inconsistent with the schemas list in the same response, which already enumerates all modules via ly_ctx_get_module_iter(). Switch to nc_server_get_cpblts(ly_ctx) so that monitoring capabilities match the hello capabilities and schema list. TEST: add test_hello to verify both YANG 1.0 and YANG 1.1 modules appear in the server hello capabilities seen by NETCONF clients. WARNING: it depends on libnetconf2 commits: - session BUGFIX nc_server_get_cpblts() returns no module capabilities - hello FEATURE advertise YANG 1.1 modules in NETCONF capabilities (TBC libnetconf2 >= 4.2.14 or see vj_fixhello branch) Signed-off-by: Vincent Jardin <vjardin@free.fr>
1 parent 7d07da1 commit 706232b

File tree

3 files changed

+103
-2
lines changed

3 files changed

+103
-2
lines changed

src/netconf_monitoring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ np2srv_ncm_oper_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), const cha
291291
/* capabilities */
292292
lyd_new_inner(root, NULL, "capabilities", 0, &cont);
293293

294-
cpblts = nc_server_get_cpblts_version(ly_ctx, LYS_VERSION_1_0);
294+
cpblts = nc_server_get_cpblts(ly_ctx);
295295
if (!cpblts) {
296296
goto error;
297297
}

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ set(TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/np2_test.c" "${CMAKE_CURRENT_SOURCE_DI
4242

4343
# list of all the tests
4444
set(TESTS test_rpc test_edit test_filter test_subscribe_filter test_subscribe_param test_parallel_sessions
45-
test_candidate test_with_defaults test_nacm test_sub_ntf test_sub_ntf_advanced test_sub_ntf_filter test_error test_other_client)
45+
test_candidate test_with_defaults test_nacm test_sub_ntf test_sub_ntf_advanced test_sub_ntf_filter test_error test_other_client test_hello)
4646

4747
if(CMAKE_C_FLAGS MATCHES "-fsanitize=thread")
4848
message(WARNING "Features which use SIGEV_THREAD are known to be broken under TSAN, disabling tests for YANG-push and confirmed commit")

tests/test_hello.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* @file test_hello.c
3+
* @author Vincent Jardin
4+
* @brief test NETCONF hello capability advertisement
5+
*
6+
* @copyright
7+
* Copyright (c) 2026 Free Mobile, Vincent Jardin.
8+
*
9+
* This source code is licensed under BSD 3-Clause License (the "License").
10+
* You may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* https://opensource.org/licenses/BSD-3-Clause
14+
*/
15+
16+
#define _GNU_SOURCE
17+
18+
#include <setjmp.h>
19+
#include <stdarg.h>
20+
#include <stdint.h>
21+
#include <stdlib.h>
22+
#include <string.h>
23+
#include <unistd.h>
24+
25+
#include <cmocka.h>
26+
#include <libyang/libyang.h>
27+
#include <nc_client.h>
28+
29+
#include "np2_test.h"
30+
#include "np2_test_config.h"
31+
32+
static int
33+
local_setup(void **state)
34+
{
35+
char test_name[256];
36+
const char *modules[] = {
37+
NP_TEST_MODULE_DIR "/edit1.yang", /* YANG 1.0 */
38+
NP_TEST_MODULE_DIR "/notif2.yang", /* YANG 1.1 */
39+
NULL
40+
};
41+
int rc;
42+
43+
np2_glob_test_setup_test_name(test_name);
44+
45+
rc = np2_glob_test_setup_env(test_name);
46+
assert_int_equal(rc, 0);
47+
48+
rc = np2_glob_test_setup_server(state, test_name, modules, NULL, 0);
49+
assert_int_equal(rc, 0);
50+
51+
return 0;
52+
}
53+
54+
static int
55+
local_teardown(void **state)
56+
{
57+
const char *modules[] = {"edit1", "notif2", NULL};
58+
59+
if (*state) {
60+
return np2_glob_test_teardown(state, modules);
61+
}
62+
63+
return 0;
64+
}
65+
66+
static void
67+
test_yang10_capability(void **state)
68+
{
69+
struct np2_test *st = *state;
70+
const char *cpblt;
71+
72+
/* YANG 1.0 module edit1 (namespace "urn:ed1") must appear in hello capabilities */
73+
cpblt = nc_session_cpblt(st->nc_sess, "urn:ed1?module=edit1");
74+
assert_non_null(cpblt);
75+
}
76+
77+
static void
78+
test_yang11_capability(void **state)
79+
{
80+
struct np2_test *st = *state;
81+
const char *cpblt;
82+
83+
/* YANG 1.1 module notif2 (namespace "urn:n2") must appear in hello capabilities */
84+
cpblt = nc_session_cpblt(st->nc_sess, "urn:n2?module=notif2");
85+
assert_non_null(cpblt);
86+
}
87+
88+
int
89+
main(int argc, char **argv)
90+
{
91+
const struct CMUnitTest tests[] = {
92+
cmocka_unit_test(test_yang10_capability),
93+
cmocka_unit_test(test_yang11_capability),
94+
};
95+
96+
if (argc > 1) {
97+
parse_arg(argc, argv);
98+
}
99+
100+
return cmocka_run_group_tests(tests, local_setup, local_teardown);
101+
}

0 commit comments

Comments
 (0)