Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new libnetconf2 API #1492

Merged
merged 23 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- devel

env:
DEFAULT_PACKAGES: libcmocka-dev zlib1g-dev libssh-dev libssl-dev libpam0g-dev
DEFAULT_PACKAGES: libcmocka-dev zlib1g-dev libssh-dev libssl-dev libpam0g-dev libcurl4-openssl-dev

jobs:
git-branch:
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
dep-build-type: "Debug",
cc: "gcc",
options: "",
packages: "libcurl4-openssl-dev valgrind",
packages: "valgrind",
snaps: "",
make-prepend: "",
make-target: ""
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ "devel" ]

env:
DEFAULT_PACKAGES: libcmocka-dev zlib1g-dev libssh-dev libssl-dev libpam0g-dev
DEFAULT_PACKAGES: libcmocka-dev zlib1g-dev libssh-dev libssl-dev libpam0g-dev libcurl4-openssl-dev

jobs:
git-branch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/devel-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- devel

env:
DEFAULT_PACKAGES: libcmocka-dev zlib1g-dev libssh-dev libssl-dev libpam0g-dev
DEFAULT_PACKAGES: libcmocka-dev zlib1g-dev libssh-dev libssl-dev libpam0g-dev libcurl4-openssl-dev
COVERITY_PROJECT: CESNET%2FNetopeer2

jobs:
Expand Down
82 changes: 42 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.5)

project(netopeer2 C)
set(NETOPEER2_DESC "NETCONF tools suite including a server and command-line client")
Expand Down Expand Up @@ -46,17 +46,17 @@ endif()
# Generic version of not only the library. Major version is reserved for really big changes of the project,
# minor version changes with added functionality (new tool, functionality of the tool or library, ...) and
# micro version is changed with a set of small changes or bugfixes anywhere in the project.
set(NP2SRV_VERSION 2.1.72)
set(NP2SRV_VERSION 2.2.0)

# libyang required version
set(LIBYANG_DEP_VERSION 2.1.87)
set(LIBYANG_DEP_SOVERSION 2.37.1)
set(LIBYANG_DEP_SOVERSION_MAJOR 2)

# libnetconf2 required version
set(LIBNETCONF2_DEP_VERSION 2.1.27)
set(LIBNETCONF2_DEP_SOVERSION 3.5.3)
set(LIBNETCONF2_DEP_SOVERSION_MAJOR 3)
set(LIBNETCONF2_DEP_VERSION 3.0.0)
set(LIBNETCONF2_DEP_SOVERSION 4.0.0)
set(LIBNETCONF2_DEP_SOVERSION_MAJOR 4)

# sysrepo required version
set(SYSREPO_DEP_VERSION 2.2.111)
Expand Down Expand Up @@ -155,27 +155,37 @@ set(FORMAT_SRC
# checks
#

find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
# lnc2 support for np2srv thread count
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=LNC2_MAX_THREAD_COUNT" "libnetconf2" OUTPUT_VARIABLE LNC2_THREAD_COUNT)
if(LNC2_THREAD_COUNT)
string(STRIP ${LNC2_THREAD_COUNT} LNC2_THREAD_COUNT)
if(LNC2_THREAD_COUNT LESS THREAD_COUNT)
message(FATAL_ERROR "libnetconf2 was compiled with support up to ${LNC2_THREAD_COUNT} threads, server is configured with ${THREAD_COUNT}.")
else()
message(STATUS "libnetconf2 was compiled with support of up to ${LNC2_THREAD_COUNT} threads")
endif()
# PKGCONFIG {

find_package(PkgConfig REQUIRED)

# find libnetconf2 pkg
pkg_check_modules(PKG_LN2 REQUIRED libnetconf2)

# libnetconf2 thread count check
pkg_get_variable(LN2_THREAD_COUNT libnetconf2 "LN2_MAX_THREAD_COUNT")
if(LN2_THREAD_COUNT)
if(LN2_THREAD_COUNT LESS THREAD_COUNT)
message(FATAL_ERROR "libnetconf2 was compiled with support up to ${LN2_THREAD_COUNT} threads, server is configured with ${THREAD_COUNT}.")
else()
message(STATUS "Unable to learn libnetconf2 thread support, check skipped")
message(STATUS "libnetconf2 was compiled with support of up to ${LN2_THREAD_COUNT} threads")
endif()

# sysrepo group
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=SR_GROUP" "sysrepo" OUTPUT_VARIABLE SR_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
message(STATUS "pkg-config not found, so it was not possible to check if libnetconf2 supports ${THREAD_COUNT} threads")
message(STATUS "Unable to learn libnetconf2 thread support, check skipped")
endif()

# get libnetconf2 module directory, use it later when installing modules
pkg_get_variable(LN2_YANG_MODULE_DIR libnetconf2 "LN2_SCHEMAS_DIR")
if(NOT LN2_YANG_MODULE_DIR)
message(FATAL_ERROR "Unable to learn libnetconf2 module search directory.")
endif()

# find sysrepo pkg and get sysrepo group
pkg_check_modules(PKG_SR REQUIRED sysrepo)
pkg_get_variable(SR_GROUP sysrepo "SR_GROUP")

# } PKGCONFIG

if(ENABLE_VALGRIND_TESTS)
find_program(VALGRIND_FOUND valgrind)
if(NOT VALGRIND_FOUND)
Expand Down Expand Up @@ -229,21 +239,6 @@ include_directories(${LIBNETCONF2_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBNETCONF2_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBNETCONF2_LIBRARIES})

# at least some remote transport is enabled
if(LIBNETCONF2_ENABLED_SSH OR LIBNETCONF2_ENABLED_TLS)
list(APPEND SERVER_SRC src/netconf_server.c)
endif()

# SSH is enabled
if(LIBNETCONF2_ENABLED_SSH)
list(APPEND SERVER_SRC src/netconf_server_ssh.c)
endif()

# TLS is enabled
if(LIBNETCONF2_ENABLED_TLS)
list(APPEND SERVER_SRC src/netconf_server_tls.c)
endif()

# link compat
use_compat()

Expand All @@ -265,7 +260,7 @@ endif()
target_link_libraries(netopeer2-server ${LIBNETCONF2_LIBRARIES})

# libssh (was already found, if exists)
if(LIBSSH_FOUND AND LIBNETCONF2_ENABLED_SSH)
if(LIBSSH_FOUND AND LIBNETCONF2_ENABLED_SSH_TLS)
target_link_libraries(netopeer2-server ${LIBSSH_LIBRARIES})
include_directories(${LIBSSH_INCLUDE_DIRS})
endif()
Expand Down Expand Up @@ -361,6 +356,8 @@ if(INSTALL_MODULES)
set(ENV{NP2_MODULE_PERMS} \"${MODULES_PERMS}\")
set(ENV{NP2_MODULE_OWNER} \"${MODULES_OWNER}\")
set(ENV{NP2_MODULE_GROUP} \"${MODULES_GROUP}\")
set(ENV{NP2_SCRIPTS_DIR} \"${SCRIPT_DIR}\")
set(ENV{LN2_MODULE_DIR} \"${LN2_YANG_MODULE_DIR}\")
set(ENV{SYSREPOCTL_EXECUTABLE} \"${SYSREPOCTL_EXECUTABLE}\")
set(ENV{SYSREPOCFG_EXECUTABLE} \"${SYSREPOCFG_EXECUTABLE}\")
execute_process(COMMAND \"\$ENV{DESTDIR}${SCRIPT_DIR}/setup.sh\" RESULT_VARIABLE SETUP_RES)
Expand All @@ -371,11 +368,13 @@ if(INSTALL_MODULES)
else()
message(WARNING "Server will refuse to start if the modules are not installed!")
endif()

if(GENERATE_HOSTKEY)
install(CODE "
message(STATUS \"Generating a new RSA host key \\\"genkey\\\" if not already added...\")
set(ENV{SYSREPOCTL_EXECUTABLE} \"${SYSREPOCTL_EXECUTABLE}\")
set(ENV{SYSREPOCFG_EXECUTABLE} \"${SYSREPOCFG_EXECUTABLE}\")
set(ENV{NP2_SCRIPTS_DIR} \"${SCRIPT_DIR}\")
execute_process(COMMAND \"\$ENV{DESTDIR}${SCRIPT_DIR}/merge_hostkey.sh\" RESULT_VARIABLE MERGE_HOSTKEY_RES)
if(NOT MERGE_HOSTKEY_RES EQUAL \"0\")
message(FATAL_ERROR \" scripts/merge_hostkey.sh failed: \${MERGE_HOSTKEY_RES}\")
Expand All @@ -387,6 +386,7 @@ if(MERGE_LISTEN_CONFIG)
message(STATUS \"Merging default server listen configuration if there is none...\")
set(ENV{SYSREPOCTL_EXECUTABLE} \"${SYSREPOCTL_EXECUTABLE}\")
set(ENV{SYSREPOCFG_EXECUTABLE} \"${SYSREPOCFG_EXECUTABLE}\")
set(ENV{NP2_SCRIPTS_DIR} \"${SCRIPT_DIR}\")
execute_process(COMMAND \"\$ENV{DESTDIR}${SCRIPT_DIR}/merge_config.sh\" RESULT_VARIABLE MERGE_CONFIG_RES)
if(NOT MERGE_CONFIG_RES EQUAL \"0\")
message(FATAL_ERROR \" scripts/merge_config.sh failed: \${MERGE_CONFIG_RES}\")
Expand Down Expand Up @@ -420,6 +420,8 @@ add_custom_target(cleancache
)

# uninstall
add_custom_target(uninstall ${SCRIPT_DIR}/remove.sh
COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake"
COMMENT "Removing netopeer2 modules from sysrepo...")
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -E env "NP2_SCRIPTS_DIR=${SCRIPT_DIR}" ${SCRIPT_DIR}/remove.sh
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_MODULE_PATH}/uninstall.cmake
COMMENT "Removing netopeer2 modules from sysrepo..."
)
6 changes: 2 additions & 4 deletions CMakeModules/FindLibNETCONF2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# LIBNETCONF2_INCLUDE_DIRS - the LibNETCONF2 include directory
# LIBNETCONF2_LIBRARIES - Link these to use LibNETCONF2
# LIBNETCONF2_VERSION - SO version of the found libNETCONF2 library
# LIBNETCONF2_ENABLED_SSH - LibNETCONF2 was compiled with SSH support
# LIBNETCONF2_ENABLED_TLS - LibNETCONF2 was compiled with TLS support
# LIBNETCONF2_ENABLED_SSH_TLS - LibNETCONF2 was compiled with SSH and TLS support
#
# Author Michal Vasko <mvasko@cesnet.cz>
# Copyright (c) 2021 CESNET, z.s.p.o.
Expand Down Expand Up @@ -93,8 +92,7 @@ else()

# check the configured options and make them available through cmake
list(INSERT CMAKE_REQUIRED_INCLUDES 0 "${LIBNETCONF2_INCLUDE_DIR}")
check_symbol_exists("NC_ENABLED_SSH" "nc_client.h" LIBNETCONF2_ENABLED_SSH)
check_symbol_exists("NC_ENABLED_TLS" "nc_client.h" LIBNETCONF2_ENABLED_TLS)
check_symbol_exists("NC_ENABLED_SSH_TLS" "nc_client.h" LIBNETCONF2_ENABLED_SSH_TLS)
list(REMOVE_AT CMAKE_REQUIRED_INCLUDES 0)
endif()

9 changes: 4 additions & 5 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ target_link_libraries(netopeer2-cli ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(netopeer2-cli ${LIBYANG_LIBRARIES})
target_link_libraries(netopeer2-cli ${LIBNETCONF2_LIBRARIES})

# dependencies - libssh
if(LIBNETCONF2_ENABLED_SSH)
# dependencies
if(LIBNETCONF2_ENABLED_SSH_TLS)
# - libssh
if(NOT LIBSSH_FOUND)
message(FATAL_ERROR "libnetconf2 supports SSH but libssh was not found, CLI compilation failed!")
endif()
target_link_libraries(netopeer2-cli ${LIBSSH_LIBRARIES})
include_directories(${LIBSSH_INCLUDE_DIRS})
endif()

# dependencies - libssl (and openssl)
if(LIBNETCONF2_ENABLED_TLS)
# - openssl
if(NOT OPENSSL_FOUND)
message(FATAL_ERROR "libnetconf2 supports TLS but OpenSSL was not found, CLI compilation failed!")
endif()
Expand Down
Loading
Loading