Skip to content

Commit

Permalink
Merge branch 'telekom:refactor' into refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
metamacro authored Oct 13, 2022
2 parents 21b1cfd + 1afc258 commit 62f2ad2
Show file tree
Hide file tree
Showing 24 changed files with 1,269 additions and 52 deletions.
23 changes: 7 additions & 16 deletions src/interfaces/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "plugin.h"
#include "plugin/common.h"

#include <srpc.h>

volatile int exit_application = 0;

static void sigint_handler(__attribute__((unused)) int signum);
Expand All @@ -19,23 +21,11 @@ int main(void)
sr_log_stderr(SR_LL_INF);

/* connect to sysrepo */
error = sr_connect(SR_CONN_DEFAULT, &connection);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_connect error (%d): %s", error, sr_strerror(error));
goto out;
}
SRPC_SAFE_CALL_ERR(error, sr_connect(SR_CONN_DEFAULT, &connection), out);
SRPC_SAFE_CALL_ERR(error, sr_session_start(connection, SR_DS_RUNNING, &session), out);

error = sr_session_start(connection, SR_DS_RUNNING, &session);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_session_start error (%d): %s", error, sr_strerror(error));
goto out;
}

error = sr_plugin_init_cb(session, &private_data);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_plugin_init_cb error");
goto out;
}
/* init plugin */
SRPC_SAFE_CALL_ERR(error, sr_plugin_init_cb(session, &private_data), out);

/* loop until ctrl-c is pressed / SIGINT is received */
signal(SIGINT, sigint_handler);
Expand All @@ -45,6 +35,7 @@ int main(void)
}

out:
/* cleanup plugin */
sr_plugin_cleanup_cb(session, private_data);
sr_disconnect(connection);

Expand Down
9 changes: 9 additions & 0 deletions src/interfaces/src/plugin/api/interfaces/change.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "change.h"
#include "netlink/route/addr.h"
#include "plugin/common.h"
#include "plugin/context.h"

Expand All @@ -25,6 +26,9 @@ int interfaces_change_interface_init(void* priv)
// allocate link cache
SRPC_SAFE_CALL_ERR(error, rtnl_link_alloc_cache(mod_ctx->nl_ctx.socket, AF_UNSPEC, &mod_ctx->nl_ctx.link_cache), error_out);

// allocate address cache
SRPC_SAFE_CALL_ERR(error, rtnl_addr_alloc_cache(mod_ctx->nl_ctx.socket, &mod_ctx->nl_ctx.addr_cache), error_out);

goto out;

error_out:
Expand Down Expand Up @@ -91,6 +95,11 @@ void interfaces_change_interface_free(void* priv)
if (mod_ctx->nl_ctx.link_cache) {
nl_cache_put(mod_ctx->nl_ctx.link_cache);
}

if (mod_ctx->nl_ctx.addr_cache) {
nl_cache_put(mod_ctx->nl_ctx.addr_cache);
}

if (mod_ctx->nl_ctx.socket) {
nl_socket_free(mod_ctx->nl_ctx.socket);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int interfaces_interface_carrier_delay_change_up(void* priv, sr_session_ctx_t* s
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand All @@ -31,7 +31,7 @@ int interfaces_interface_carrier_delay_change_down(void* priv, sr_session_ctx_t*
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ int interfaces_interface_change_enabled(void* priv, sr_session_ctx_t* session, c
// set name
rtnl_link_set_name(request_link, interface_name_buffer);
rtnl_link_set_type(request_link, rtnl_link_get_type(current_link));

// set operstate
rtnl_link_set_flags(request_link, (strcmp(node_value, "true") == 0) ? (unsigned int)rtnl_link_str2flags("up") : (unsigned int)rtnl_link_str2flags("down"));
rtnl_link_unset_flags(request_link, (strcmp(node_value, "true") == 0) ? (unsigned int)rtnl_link_str2flags("down") : (unsigned int)rtnl_link_str2flags("up"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int interfaces_interface_dampening_change_max_suppress_time(void* priv, sr_sessi
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand All @@ -31,7 +31,7 @@ int interfaces_interface_dampening_change_suppress(void* priv, sr_session_ctx_t*
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand All @@ -53,7 +53,7 @@ int interfaces_interface_dampening_change_reuse(void* priv, sr_session_ctx_t* se
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand All @@ -75,7 +75,7 @@ int interfaces_interface_dampening_change_half_life(void* priv, sr_session_ctx_t
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int interfaces_interface_encapsulation_dot1q_vlan_outer_tag_change_vlan_id(void*
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand All @@ -31,7 +31,7 @@ int interfaces_interface_encapsulation_dot1q_vlan_outer_tag_change_tag_type(void
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int interfaces_interface_encapsulation_dot1q_vlan_second_tag_change_vlan_id(void
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand All @@ -31,7 +31,7 @@ int interfaces_interface_encapsulation_dot1q_vlan_second_tag_change_tag_type(voi
const char* node_name = LYD_NAME(change_ctx->node);
const char* node_value = lyd_get_value(change_ctx->node);

SRPLG_LOG_DBG(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);
SRPLG_LOG_INF(PLUGIN_NAME, "Node Name: %s; Previous Value: %s, Value: %s; Operation: %d", node_name, change_ctx->previous_value, node_value, change_ctx->operation);

switch (change_ctx->operation) {
case SR_OP_CREATED:
Expand Down
Loading

0 comments on commit 62f2ad2

Please sign in to comment.