Skip to content

Commit

Permalink
interfaces-plugin: fix load issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zinccyy committed Oct 31, 2022
1 parent 290bde5 commit 6ce174b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include "netlink/route/neighbour.h"
#include "plugin/api/interfaces/interface/ipv4/address/load.h"
#include "plugin/api/interfaces/interface/ipv4/neighbor/load.h"
#include "plugin/common.h"
#include "plugin/context.h"
#include "plugin/data/interfaces/interface.h"
#include "plugin/data/interfaces/interface/ipv4.h"
#include "plugin/data/interfaces/interface/ipv4/address.h"
#include "plugin/types.h"
#include "sysrepo.h"

int interfaces_interface_ipv4_load_enabled(interfaces_ctx_t* ctx, interfaces_interface_ipv4_t* ipv4, struct rtnl_link* link)
{
Expand Down Expand Up @@ -91,7 +93,7 @@ int interfaces_interface_ipv4_load_address(interfaces_ctx_t* ctx, interfaces_int
}

// iterate
SRPC_SAFE_CALL_PTR(addr_iter, (struct rtnl_addr*)nl_cache_get_next((struct nl_object*)addr_iter), error_out);
addr_iter = (struct rtnl_addr*)nl_cache_get_next((struct nl_object*)addr_iter);
}

goto out;
Expand Down Expand Up @@ -146,7 +148,7 @@ int interfaces_interface_ipv4_load_neighbor(interfaces_ctx_t* ctx, interfaces_in
}

// iterate
SRPC_SAFE_CALL_PTR(neigh_iter, (struct rtnl_neigh*)nl_cache_get_next((struct nl_object*)neigh_iter), error_out);
neigh_iter = (struct rtnl_neigh*)nl_cache_get_next((struct nl_object*)neigh_iter);
}

goto out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int interfaces_interface_ipv6_load_address(interfaces_ctx_t* ctx, interfaces_int
}

// iterate
SRPC_SAFE_CALL_PTR(addr_iter, (struct rtnl_addr*)nl_cache_get_next((struct nl_object*)addr_iter), error_out);
addr_iter = (struct rtnl_addr*)nl_cache_get_next((struct nl_object*)addr_iter);
}

goto out;
Expand Down Expand Up @@ -141,7 +141,7 @@ int interfaces_interface_ipv6_load_neighbor(interfaces_ctx_t* ctx, interfaces_in
}

// iterate
SRPC_SAFE_CALL_PTR(neigh_iter, (struct rtnl_neigh*)nl_cache_get_next((struct nl_object*)neigh_iter), error_out);
neigh_iter = (struct rtnl_neigh*)nl_cache_get_next((struct nl_object*)neigh_iter);
}

goto out;
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/src/plugin/api/interfaces/interface/load.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "load.h"
#include "plugin/common.h"
#include "plugin/data/interfaces/interface.h"
#include "sysrepo.h"

#include <linux/if.h>
#include <srpc.h>
Expand Down Expand Up @@ -31,7 +33,7 @@ int interfaces_interface_load_type(interfaces_ctx_t* ctx, interfaces_interface_h
const char* nl_if_type = NULL;
const char* ly_if_type = NULL;

// 2. interface type - nl version -> convert to libyang version
// interface type - nl version -> convert to libyang version
nl_if_type = rtnl_link_get_type(link);

SRPC_SAFE_CALL_ERR(error, interfaces_interface_type_nl2ly(nl_if_type, &ly_if_type), error_out);
Expand Down
17 changes: 16 additions & 1 deletion src/interfaces/src/plugin/api/interfaces/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ int interfaces_load_interface(interfaces_ctx_t* ctx, interfaces_interface_hash_e

// temp data
interfaces_interface_hash_element_t* new_element = NULL;
uint8_t element_added = 0;

struct rtnl_link* link_iter = NULL;

// init hash
Expand All @@ -61,6 +63,7 @@ int interfaces_load_interface(interfaces_ctx_t* ctx, interfaces_interface_hash_e
while (link_iter) {
// allocate new element
SRPC_SAFE_CALL_PTR(new_element, interfaces_interface_hash_element_new(), error_out);
element_added = 0;

// load interface data
SRPC_SAFE_CALL_ERR(error, interfaces_interface_load_name(ctx, &new_element, link_iter), error_out);
Expand All @@ -81,15 +84,27 @@ int interfaces_load_interface(interfaces_ctx_t* ctx, interfaces_interface_hash_e
SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_load_address(ctx, &new_element->interface.ipv4, link_iter), error_out);
SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_load_neighbor(ctx, &new_element->interface.ipv4, link_iter), error_out);

// load IPv6 address and neighbor lists
SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv6_load_address(ctx, &new_element->interface.ipv6, link_iter), error_out);
SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv6_load_neighbor(ctx, &new_element->interface.ipv6, link_iter), error_out);

// add element to the hash
SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_add_element(if_hash, new_element), error_out);
element_added = 1;

// iterate
SRPC_SAFE_CALL_PTR(link_iter, (struct rtnl_link*)nl_cache_get_next((struct nl_object*)link_iter), error_out);
link_iter = (struct rtnl_link*)nl_cache_get_next((struct nl_object*)link_iter);
}

goto out;

error_out:
error = -1;

if (!element_added) {
interfaces_interface_hash_element_free(&new_element);
}

out:
// dealloc nl_ctx data

Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/src/plugin/data/interfaces/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ int interfaces_interface_type_nl2ly(const char* nl_type, const char** ly_type)
int error = 0;

if (nl_type == NULL) {
return -1;
// fix for now - investigate more - lo interface has type == NULL
*ly_type = "iana-if-type:softwareLoopback";
return 0;
}

if (strcmp(nl_type, "veth") == 0) {
Expand Down
49 changes: 48 additions & 1 deletion src/interfaces/src/plugin/startup/load.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include "load.h"
#include "plugin/common.h"
#include "plugin/data/interfaces/interface.h"
#include "plugin/ly_tree.h"

#include "plugin/api/interfaces/load.h"
#include "plugin/types.h"
#include "src/uthash.h"
#include "src/utlist.h"
#include "srpc/common.h"

#include <libyang/libyang.h>
Expand Down Expand Up @@ -81,14 +85,57 @@ static int interfaces_startup_load_interface(void* priv, sr_session_ctx_t* sessi
int error = 0;
interfaces_ctx_t* ctx = (interfaces_ctx_t*)priv;
interfaces_interface_hash_element_t* interface_head = NULL;
// interfaces_interface_hash_element_t *iter = NULL, *tmp = NULL;

// interfaces_interface_ipv4_address_element_t* v4_addr_iter = NULL;
// interfaces_interface_ipv6_address_element_t* v6_addr_iter = NULL;

// interfaces_interface_ipv4_neighbor_element_t* v4_neigh_iter = NULL;
// interfaces_interface_ipv6_neighbor_element_t* v6_neigh_iter = NULL;

SRPC_SAFE_CALL_ERR(error, interfaces_load_interface(ctx, &interface_head), error_out);

// HASH_ITER(hh, interface_head, iter, tmp)
// {
// SRPLG_LOG_INF(PLUGIN_NAME, "Name: %s", iter->interface.name);
// SRPLG_LOG_INF(PLUGIN_NAME, "Type: %s", iter->interface.type);
// SRPLG_LOG_INF(PLUGIN_NAME, "Enabled: %d", iter->interface.enabled);

// // v4
// SRPLG_LOG_INF(PLUGIN_NAME, "v4 MTU: %d", iter->interface.ipv4.mtu);
// SRPLG_LOG_INF(PLUGIN_NAME, "v4 Enabled: %d", iter->interface.ipv4.enabled);
// SRPLG_LOG_INF(PLUGIN_NAME, "v4 Forwarding: %d", iter->interface.ipv4.forwarding);

// LL_FOREACH(iter->interface.ipv4.address, v4_addr_iter)
// {
// SRPLG_LOG_INF(PLUGIN_NAME, "v4 Address : %s/%d", v4_addr_iter->address.ip, v4_addr_iter->address.subnet.prefix_length);
// }
// LL_FOREACH(iter->interface.ipv4.neighbor, v4_neigh_iter)
// {
// SRPLG_LOG_INF(PLUGIN_NAME, "v4 Neighbor : %s : %s", v4_neigh_iter->neighbor.ip, v4_neigh_iter->neighbor.link_layer_address);
// }

// // v6
// SRPLG_LOG_INF(PLUGIN_NAME, "v6 MTU: %d", iter->interface.ipv6.mtu);
// SRPLG_LOG_INF(PLUGIN_NAME, "v6 Enabled: %d", iter->interface.ipv6.enabled);
// SRPLG_LOG_INF(PLUGIN_NAME, "v6 Forwarding: %d", iter->interface.ipv6.forwarding);

// LL_FOREACH(iter->interface.ipv6.address, v6_addr_iter)
// {
// SRPLG_LOG_INF(PLUGIN_NAME, "v6 Address : %s/%d", v6_addr_iter->address.ip, v6_addr_iter->address.prefix_length);
// }
// LL_FOREACH(iter->interface.ipv6.neighbor, v6_neigh_iter)
// {
// SRPLG_LOG_INF(PLUGIN_NAME, "v6 Neighbor : %s : %s", v6_neigh_iter->neighbor.ip, v6_neigh_iter->neighbor.link_layer_address);
// }
// }

goto out;

error_out:
error = -1;
out:
interfaces_interface_hash_free(&interface_head);

return error;
}

0 comments on commit 6ce174b

Please sign in to comment.