Skip to content

Commit

Permalink
Merge pull request telekom#18 from telekom/devel
Browse files Browse the repository at this point in the history
Plugin update: use newest SRPC API and improve startup and running DS functionality
  • Loading branch information
zinccyy authored Oct 26, 2022
2 parents 606046a + 19fa1ce commit 812e1ee
Show file tree
Hide file tree
Showing 79 changed files with 535 additions and 712 deletions.
69 changes: 34 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,48 @@ include_directories(
set(
SOURCES

src/system.c
src/ly_tree.c
src/utils/memory.c
src/plugin.c
src/plugin/ly_tree.c

# startup
src/startup/load.c
src/startup/store.c
src/plugin/startup/load.c
src/plugin/startup/store.c

# subs
src/subscription/change.c
src/subscription/operational.c
src/subscription/rpc.c
src/plugin/subscription/change.c
src/plugin/subscription/operational.c
src/plugin/subscription/rpc.c

# data
src/system/data/ip_address.c
src/system/data/dns_resolver/search.c
src/system/data/dns_resolver/search/list.c
src/system/data/dns_resolver/server.c
src/system/data/dns_resolver/server/list.c
src/system/data/ntp/server.c
src/system/data/ntp/server/list.c
src/system/data/authentication/authorized_key.c
src/system/data/authentication/authorized_key/list.c
src/system/data/authentication/local_user.c
src/system/data/authentication/local_user/list.c
src/plugin/data/system/ip_address.c
src/plugin/data/system/dns_resolver/search.c
src/plugin/data/system/dns_resolver/search/list.c
src/plugin/data/system/dns_resolver/server.c
src/plugin/data/system/dns_resolver/server/list.c
src/plugin/data/system/ntp/server.c
src/plugin/data/system/ntp/server/list.c
src/plugin/data/system/authentication/authorized_key.c
src/plugin/data/system/authentication/authorized_key/list.c
src/plugin/data/system/authentication/local_user.c
src/plugin/data/system/authentication/local_user/list.c

# system API
src/system/api/load.c
src/system/api/check.c
src/system/api/store.c
src/system/api/change.c
src/system/api/ntp/load.c
src/system/api/ntp/check.c
src/system/api/ntp/store.c
src/system/api/ntp/change.c
src/system/api/dns_resolver/load.c
src/system/api/dns_resolver/check.c
src/system/api/dns_resolver/store.c
src/system/api/dns_resolver/change.c
src/system/api/authentication/load.c
src/system/api/authentication/check.c
src/system/api/authentication/store.c
src/system/api/authentication/change.c
src/plugin/api/system/load.c
src/plugin/api/system/check.c
src/plugin/api/system/store.c
src/plugin/api/system/change.c
src/plugin/api/system/ntp/load.c
src/plugin/api/system/ntp/check.c
src/plugin/api/system/ntp/store.c
src/plugin/api/system/ntp/change.c
src/plugin/api/system/dns_resolver/load.c
src/plugin/api/system/dns_resolver/check.c
src/plugin/api/system/dns_resolver/store.c
src/plugin/api/system/dns_resolver/change.c
src/plugin/api/system/authentication/load.c
src/plugin/api/system/authentication/check.c
src/plugin/api/system/authentication/store.c
src/plugin/api/system/authentication/change.c
)

# get sysrepo version
Expand Down
36 changes: 20 additions & 16 deletions CompileOptions.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wuninitialized")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wuninitialized")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")

if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=incompatible-pointer-types")
endif ()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-newline-eof")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-gnu-zero-variadic-macro-arguments")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=incompatible-pointer-types")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")

if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-newline-eof")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-gnu-zero-variadic-macro-arguments")
endif()
5 changes: 3 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#include <sysrepo.h>
#include <signal.h>
#include <unistd.h>
#include <system.h>
#include <common.h>

#include "plugin.h"
#include "plugin/common.h"

volatile int exit_application = 0;

Expand Down
61 changes: 25 additions & 36 deletions src/system.c → src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <system.h>
#include <common.h>
#include <context.h>
#include <utils/memory.h>
#include "plugin.h"
#include "plugin/common.h"
#include "plugin/context.h"

// stdlib
#include <stdbool.h>
Expand All @@ -25,16 +24,17 @@
#include <libyang/tree_data.h>

#include "srpc/common.h"
#include "srpc/feature_status.h"
#include "srpc/types.h"

// startup
#include "startup/load.h"
#include "startup/store.h"
#include "plugin/startup/load.h"
#include "plugin/startup/store.h"

// subs
#include "subscription/change.h"
#include "subscription/operational.h"
#include "subscription/rpc.h"
#include "plugin/subscription/change.h"
#include "plugin/subscription/operational.h"
#include "plugin/subscription/rpc.h"

#include <srpc.h>

Expand All @@ -53,7 +53,7 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data)
system_ctx_t *ctx = NULL;

// init context
ctx = xmalloc(sizeof(*ctx));
ctx = malloc(sizeof(*ctx));
*ctx = (system_ctx_t){0};

*private_data = ctx;
Expand Down Expand Up @@ -134,15 +134,22 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data)
// operational getters
srpc_operational_t oper[] = {
{
IETF_SYSTEM_YANG_MODULE,
SYSTEM_STATE_PLATFORM_YANG_PATH "/*",
system_subscription_operational_platform,
},
{
IETF_SYSTEM_YANG_MODULE,
SYSTEM_STATE_CLOCK_YANG_PATH "/*",
system_subscription_operational_clock,
},
};

ctx->ietf_system_features = srpc_feature_status_hash_new();

// load feature status
SRPC_SAFE_CALL_ERR(error, srpc_feature_status_hash_load(&ctx->ietf_system_features, running_session, "ietf-system"), error_out);

// log status of features
const char *features[] = {
"radius",
Expand All @@ -159,11 +166,8 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data)

for (size_t i = 0; i < ARRAY_SIZE(features); i++) {
const char *feature = features[i];
bool enabled = false;

SRPC_SAFE_CALL(srpc_check_feature_status(running_session, "ietf-system", feature, &enabled), error_out);

SRPLG_LOG_INF(PLUGIN_NAME, "ietf-system feature \"%s\" status = %s", feature, enabled ? "enabled" : "disabled");
SRPLG_LOG_INF(PLUGIN_NAME, "ietf-system feature \"%s\" status = %s", feature, srpc_feature_status_hash_check(ctx->ietf_system_features, feature) ? "enabled" : "disabled");
}

connection = sr_session_get_connection(running_session);
Expand All @@ -184,35 +188,24 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data)
if (empty_startup) {
SRPLG_LOG_INF(PLUGIN_NAME, "Startup datastore is empty");
SRPLG_LOG_INF(PLUGIN_NAME, "Loading initial system data");
error = system_startup_load_data(ctx, startup_session);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading initial data into the startup datastore... exiting");
goto error_out;
}

// copy contents of the startup session to the current running session
error = sr_copy_config(running_session, BASE_YANG_MODULE, SR_DS_STARTUP, 0);
// load data only into running DS - do not use startup unless said explicitly
error = system_startup_load_data(ctx, running_session);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error));
SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading initial data into the startup datastore... exiting");
goto error_out;
}
} else {
// make sure the data from startup DS is stored in the system
SRPLG_LOG_INF(PLUGIN_NAME, "Startup datastore contains data");
SRPLG_LOG_INF(PLUGIN_NAME, "Storing startup datastore data in the system");

// check and apply if needed data from startup to the system
error = system_startup_store_data(ctx, startup_session);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "Error applying initial data from startup datastore to the system... exiting");
goto error_out;
}

// copy contents of the startup session to the current running session
error = sr_copy_config(running_session, BASE_YANG_MODULE, SR_DS_STARTUP, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error));
goto error_out;
}
}

// subscribe every module change
Expand Down Expand Up @@ -269,15 +262,11 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data)

void sr_plugin_cleanup_cb(sr_session_ctx_t *running_session, void *private_data)
{
int error = 0;

system_ctx_t *ctx = (system_ctx_t *) private_data;

// save current running configuration into startup for next time when the plugin starts
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error));
if (ctx->ietf_system_features) {
srpc_feature_status_hash_free(&ctx->ietf_system_features);
}

FREE_SAFE(ctx);
free(ctx);
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "change.h"
#include "common.h"
#include "plugin/common.h"
#include "libyang/tree_data.h"
#include "system/api/authentication/store.h"
#include "system/data/authentication/authorized_key.h"
#include "system/data/authentication/authorized_key/list.h"
#include "system/data/authentication/local_user.h"
#include "system/data/authentication/local_user/list.h"
#include "types.h"
#include "plugin/api/system/authentication/store.h"
#include "plugin/data/system/authentication/authorized_key.h"
#include "plugin/data/system/authentication/authorized_key/list.h"
#include "plugin/data/system/authentication/local_user.h"
#include "plugin/data/system/authentication/local_user/list.h"
#include "plugin/types.h"
#include "umgmt/db.h"
#include "umgmt/types.h"
#include "umgmt/user.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef SYSTEM_PLUGIN_API_AUTHENTICATION_CHANGE_H
#define SYSTEM_PLUGIN_API_AUTHENTICATION_CHANGE_H

#include "context.h"
#include "plugin/context.h"

#include <srpc.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
*/
#include "check.h"
#include "load.h"
#include "common.h"
#include "system/data/authentication/local_user/list.h"
#include "system/data/authentication/authorized_key/list.h"
#include "plugin/common.h"
#include "plugin/data/system/authentication/local_user/list.h"
#include "plugin/data/system/authentication/authorized_key/list.h"

#include <sysrepo.h>
#include <utlist.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#ifndef SYSTEM_PLUGIN_API_AUTHENTICATION_CHECK_H
#define SYSTEM_PLUGIN_API_AUTHENTICATION_CHECK_H

#include "context.h"
#include "types.h"
#include "plugin/context.h"
#include "plugin/types.h"
#include <srpc.h>

srpc_check_status_t system_authentication_check_user(system_ctx_t *ctx, system_local_user_element_t *head, system_local_user_element_t **system_head);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/
#include "load.h"
#include "sysrepo.h"
#include "types.h"
#include "common.h"
#include "plugin/types.h"
#include "plugin/common.h"

#include "system/data/authentication/authorized_key/list.h"
#include "system/data/authentication/authorized_key.h"
#include "system/data/authentication/local_user/list.h"
#include "system/data/authentication/local_user.h"
#include "plugin/data/system/authentication/authorized_key/list.h"
#include "plugin/data/system/authentication/authorized_key.h"
#include "plugin/data/system/authentication/local_user/list.h"
#include "plugin/data/system/authentication/local_user.h"
#include "umgmt/user.h"

#include <unistd.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#ifndef SYSTEM_PLUGIN_API_AUTHENTICATION_LOAD_H
#define SYSTEM_PLUGIN_API_AUTHENTICATION_LOAD_H

#include "context.h"
#include "types.h"
#include "plugin/context.h"
#include "plugin/types.h"

int system_authentication_load_user(system_ctx_t *ctx, system_local_user_element_t **head);
int system_authentication_load_user_authorized_key(system_ctx_t *ctx, const char *user, system_authorized_key_element_t **head);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "store.h"
#include "common.h"
#include "plugin/common.h"
#include "umgmt/group.h"

#include <asm-generic/errno-base.h>
Expand Down Expand Up @@ -251,6 +251,10 @@ int system_authentication_store_user(system_ctx_t *ctx, system_local_user_elemen
um_user_free(new_user);
}

if (!group_added && new_group) {
um_group_free(new_group);
}

if (db) {
um_db_free(db);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef SYSTEM_PLUGIN_API_AUTHENTICATION_STORE_H
#define SYSTEM_PLUGIN_API_AUTHENTICATION_STORE_H

#include "context.h"
#include "plugin/context.h"

int system_authentication_store_user(system_ctx_t *ctx, system_local_user_element_t *head);
int system_authentication_store_user_authorized_key(system_ctx_t *ctx, const char *user, system_authorized_key_element_t *head);
Expand Down
File renamed without changes.
Loading

0 comments on commit 812e1ee

Please sign in to comment.