Skip to content

Commit ea02096

Browse files
committed
Merge branch 'devel'
2 parents 068ce48 + 2bf3fc1 commit ea02096

23 files changed

+648
-276
lines changed

CMakeLists.txt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ endif()
4343
# Generic version of not only the library. Major version is reserved for really big changes of the project,
4444
# minor version changes with added functionality (new tool, functionality of the tool or library, ...) and
4545
# micro version is changed with a set of small changes or bugfixes anywhere in the project.
46-
set(NP2SRV_VERSION 2.1.16)
46+
set(NP2SRV_VERSION 2.1.23)
4747

4848
# libyang required version
49-
set(LIBYANG_DEP_VERSION 2.0.128)
50-
set(LIBYANG_DEP_SOVERSION 2.14.0)
49+
set(LIBYANG_DEP_VERSION 2.0.178)
50+
set(LIBYANG_DEP_SOVERSION 2.20.2)
5151
set(LIBYANG_DEP_SOVERSION_MAJOR 2)
5252

5353
# libnetconf2 required version
@@ -56,8 +56,8 @@ set(LIBNETCONF2_DEP_SOVERSION 3.1.0)
5656
set(LIBNETCONF2_DEP_SOVERSION_MAJOR 3)
5757

5858
# sysrepo required version
59-
set(SYSREPO_DEP_VERSION 2.1.36)
60-
set(SYSREPO_DEP_SOVERSION 7.3.0)
59+
set(SYSREPO_DEP_VERSION 2.1.53)
60+
set(SYSREPO_DEP_SOVERSION 7.5.0)
6161
set(SYSREPO_DEP_SOVERSION_MAJOR 7)
6262

6363
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=gnu99")
@@ -77,6 +77,7 @@ option(ENABLE_URL "Enable URL capability" ON)
7777
set(THREAD_COUNT 5 CACHE STRING "Number of threads accepting new sessions and handling requests")
7878
set(POLL_IO_TIMEOUT 10 CACHE STRING "Timeout in milliseconds of polling sessions for new data. It is also used for synchronization of low level IO such as sending a reply while a notification is being sent")
7979
set(YANG_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/yang/modules/netopeer2" CACHE STRING "Directory where to copy the YANG modules to")
80+
set(SCRIPT_DIR "${CMAKE_INSTALL_PREFIX}/share/netopeer2" CACHE STRING "Directory where to copy the install scripts to")
8081

8182
# script options
8283
option(INSTALL_MODULES "Install required modules into sysrepo" ON)
@@ -114,10 +115,10 @@ if(NOT NP2SRV_SSH_AUTHORIZED_KEYS_PATTERN MATCHES "^[^%]*%s[^%]*$")
114115
endif()
115116

116117
if(NOT SERVER_DIR)
117-
if("${BUILD_TYPE_UPPER}" STREQUAL "RELEASE")
118-
set(SERVER_DIR "/var/netopeer2")
119-
else()
118+
if("${BUILD_TYPE_UPPER}" STREQUAL "DEBUG")
120119
set(SERVER_DIR "$ENV{HOME}/.netopeer2-server")
120+
else()
121+
set(SERVER_DIR "/var/netopeer2")
121122
endif()
122123
endif()
123124

@@ -331,11 +332,9 @@ configure_file("${PROJECT_SOURCE_DIR}/src/config.h.in" "${PROJECT_BINARY_DIR}/co
331332
configure_file("${PROJECT_SOURCE_DIR}/service/netopeer2-server.service.in" "${PROJECT_BINARY_DIR}/netopeer2-server.service" @ONLY)
332333
include_directories(${PROJECT_BINARY_DIR})
333334

334-
# set script dir
335-
set(SCRIPT_DIR "${PROJECT_SOURCE_DIR}/scripts/")
336-
337-
# install the module files
335+
# install the modules and scripts
338336
install(DIRECTORY "${PROJECT_SOURCE_DIR}/modules/" DESTINATION ${YANG_MODULE_DIR})
337+
install(DIRECTORY "${PROJECT_SOURCE_DIR}/scripts/" DESTINATION ${SCRIPT_DIR} USE_SOURCE_PERMISSIONS)
339338

340339
# install the binary, required modules, and default configuration
341340
install(TARGETS netopeer2-server DESTINATION ${CMAKE_INSTALL_BINDIR})
@@ -409,6 +408,6 @@ add_custom_target(cleancache
409408
)
410409

411410
# uninstall
412-
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake"
413-
COMMAND ${SCRIPT_DIR}/remove.sh
411+
add_custom_target(uninstall ${SCRIPT_DIR}/remove.sh
412+
COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake"
414413
COMMENT "Removing netopeer2 modules from sysrepo...")

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ the `distro` directory.
5656
* [libyang](https://github.com/CESNET/libyang)
5757
* [libnetconf2](https://github.com/CESNET/libnetconf2)
5858
* [sysrepo](https://github.com/sysrepo/sysrepo)
59+
* c_rehash (only for CLI and if TLS is supported, is an OpenSSL Perl script)
5960

6061
### Optional
6162

cli/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include(CheckFunctionExists)
77
project(netopeer2-cli C)
88

99
# set version
10-
set(NP2CLI_VERSION 2.0.64)
10+
set(NP2CLI_VERSION 2.0.65)
1111
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cli_version.h.in" "${PROJECT_BINARY_DIR}/cli_version.h" ESCAPE_QUOTES @ONLY)
1212
include_directories(${PROJECT_BINARY_DIR})
1313

@@ -36,15 +36,21 @@ if(LIBNETCONF2_ENABLED_SSH)
3636
include_directories(${LIBSSH_INCLUDE_DIRS})
3737
endif()
3838

39-
# dependencies - libssl
39+
# dependencies - libssl, c_rehash for hashing CA dir
4040
if(LIBNETCONF2_ENABLED_TLS)
4141
if(NOT OPENSSL_FOUND)
4242
message(FATAL_ERROR "libnetconf2 supports TLS but OpenSSL was not found, CLI compilation failed!")
4343
endif()
4444
target_link_libraries(netopeer2-cli ${OPENSSL_LIBRARIES})
4545
include_directories(${OPENSSL_INCLUDE_DIR})
46+
47+
find_program(C_REHASH c_rehash)
48+
if(NOT C_REHASH)
49+
message(FATAL_ERROR "c_rehash Perl OpenSSL script not found!")
50+
endif()
4651
endif()
4752

53+
# compat checks
4854
check_function_exists(eaccess HAVE_EACCESS)
4955
check_function_exists(mkstemps HAVE_MKSTEMPS)
5056
if(HAVE_MKSTEMPS)

cli/commands.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ extern int done;
7070
LYD_FORMAT output_format = LYD_XML;
7171
uint32_t output_flag;
7272
char *config_editor;
73+
char *ext_data_path;
7374
struct nc_session *session;
7475
volatile int interleave;
7576
int timed;
@@ -462,6 +463,27 @@ cli_send_recv(struct nc_rpc *rpc, FILE *output, NC_WD_MODE wd_mode, int timeout_
462463
return ret;
463464
}
464465

466+
static LY_ERR
467+
cli_ext_data_clb(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free)
468+
{
469+
const char *path = user_data;
470+
struct lyd_node *data;
471+
LY_ERR r;
472+
473+
if (strcmp(ext->def->module->name, "ietf-yang-schema-mount") || strcmp(ext->def->name, "mount-point")) {
474+
return LY_EINVAL;
475+
}
476+
477+
/* parse the data file */
478+
if ((r = lyd_parse_data_path(ext->def->module->ctx, path, 0, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &data))) {
479+
return r;
480+
}
481+
482+
*ext_data = data;
483+
*ext_data_free = 1;
484+
return LY_SUCCESS;
485+
}
486+
465487
static char *
466488
trim_top_elem(char *data, const char *top_elem, const char *top_elem_ns)
467489
{
@@ -1255,6 +1277,12 @@ cmd_userrpc_help(void)
12551277
printf("user-rpc [--help] [--content <file>] [--out <file>] [--rpc-timeout <seconds>]\n");
12561278
}
12571279

1280+
static void
1281+
cmd_extdata_help(void)
1282+
{
1283+
printf("ext-data [--help] [--path <file>]\n");
1284+
}
1285+
12581286
static void
12591287
cmd_timed_help(void)
12601288
{
@@ -1742,6 +1770,10 @@ cmd_connect_listen_ssh(struct arglist *cmd, int is_connect)
17421770
}
17431771
}
17441772

1773+
if (ext_data_path) {
1774+
ly_ctx_set_ext_data_clb((struct ly_ctx *)nc_session_get_ctx(session), cli_ext_data_clb, ext_data_path);
1775+
}
1776+
17451777
return EXIT_SUCCESS;
17461778
}
17471779

@@ -2558,6 +2590,10 @@ cmd_connect_listen_tls(struct arglist *cmd, int is_connect)
25582590
}
25592591
}
25602592

2593+
if (ext_data_path) {
2594+
ly_ctx_set_ext_data_clb((struct ly_ctx *)nc_session_get_ctx(session), cli_ext_data_clb, ext_data_path);
2595+
}
2596+
25612597
ret = EXIT_SUCCESS;
25622598

25632599
error_cleanup:
@@ -2618,6 +2654,10 @@ cmd_connect_listen_unix(struct arglist *cmd, int is_connect)
26182654
goto error_cleanup;
26192655
}
26202656

2657+
if (ext_data_path) {
2658+
ly_ctx_set_ext_data_clb((struct ly_ctx *)nc_session_get_ctx(session), cli_ext_data_clb, ext_data_path);
2659+
}
2660+
26212661
ret = EXIT_SUCCESS;
26222662

26232663
error_cleanup:
@@ -6609,6 +6649,35 @@ cmd_userrpc(const char *arg, char **tmp_config_file)
66096649
return ret;
66106650
}
66116651

6652+
static int
6653+
cmd_extdata(const char *arg, char **UNUSED(tmp_config_file))
6654+
{
6655+
char *cmd, *args = strdupa(arg), *ptr = NULL;
6656+
6657+
cmd = strtok_r(args, " ", &ptr);
6658+
cmd = strtok_r(NULL, " ", &ptr);
6659+
if (cmd == NULL) {
6660+
printf("Current file: ");
6661+
printf("%s\n", ext_data_path);
6662+
} else if ((strcmp(cmd, "--help") == 0) || (strcmp(cmd, "-h") == 0)) {
6663+
cmd_extdata_help();
6664+
} else {
6665+
if (access(cmd, F_OK) == -1) {
6666+
ERROR(__func__, "Unable to access file \"%s\" (%s).", cmd, strerror(errno));
6667+
return EXIT_FAILURE;
6668+
}
6669+
6670+
free(ext_data_path);
6671+
ext_data_path = strdup(cmd);
6672+
}
6673+
6674+
if (session) {
6675+
ly_ctx_set_ext_data_clb((struct ly_ctx *)nc_session_get_ctx(session), cli_ext_data_clb, ext_data_path);
6676+
}
6677+
6678+
return EXIT_SUCCESS;
6679+
}
6680+
66126681
static int
66136682
cmd_timed(const char *arg, char **UNUSED(tmp_config_file))
66146683
{
@@ -6679,6 +6748,7 @@ COMMAND commands[] = {
66796748
"ietf-subscribed-notifications <modify-subscription> operation with ietf-yang-push augments"},
66806749
{"resync-sub", cmd_resyncsub, cmd_resyncsub_help, "ietf-yang-push <resync-subscription> operation"},
66816750
{"user-rpc", cmd_userrpc, cmd_userrpc_help, "Send your own content in an RPC envelope"},
6751+
{"ext-data", cmd_extdata, cmd_extdata_help, "Set path to a data file with libyang ext data"},
66826752
{"timed", cmd_timed, cmd_timed_help, "Time all the commands (that communicate with a server) from issuing an RPC"
66836753
" to getting a reply"},
66846754
/* synonyms for previous commands */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=netopeer2 NETCONF server
3+
#After=
4+
5+
[Service]
6+
Type=notify
7+
ExecStart=/usr/bin/netopeer2-server -d -v2
8+
Restart=always
9+
SystemCallArchitectures=native
10+
KillMode=control-group
11+
12+
[Install]
13+
WantedBy=multi-user.target
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Type Name ID GECOS Home directory Shell
2+
m root sysrepo

0 commit comments

Comments
 (0)