diff --git a/src/interfaces/src/plugin/data/interfaces/interface.c b/src/interfaces/src/plugin/data/interfaces/interface.c index 8689497e..5e64ce4f 100644 --- a/src/interfaces/src/plugin/data/interfaces/interface.c +++ b/src/interfaces/src/plugin/data/interfaces/interface.c @@ -86,6 +86,8 @@ void interfaces_interface_hash_print_debug(const interfaces_interface_hash_eleme const interfaces_interface_hash_element_t *iter = NULL, *tmp = NULL; interfaces_interface_ipv4_address_element_t* v4addr_iter = NULL; interfaces_interface_ipv6_address_element_t* v6addr_iter = NULL; + interfaces_interface_ipv4_neighbor_element_t* v4neigh_iter = NULL; + interfaces_interface_ipv6_neighbor_element_t* v6neigh_iter = NULL; HASH_ITER(hh, if_hash, iter, tmp) { @@ -97,20 +99,25 @@ void interfaces_interface_hash_print_debug(const interfaces_interface_hash_eleme SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv4:Enabled = %d", iter->interface.ipv4.enabled); SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv4:Forwarding = %d", iter->interface.ipv4.forwarding); SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv4:MTU = %hu", iter->interface.ipv4.mtu); - SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv4:Address List:"); LL_FOREACH(iter->interface.ipv4.address, v4addr_iter) { - SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv4:Address %s:", v4addr_iter->address.ip); - SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv4:Address IP = %s", v4addr_iter->address.ip); - SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv4:Address Prefix Length = %d", v4addr_iter->address.subnet.prefix_length); + SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv4:Address = %s/%d", v4addr_iter->address.ip, v4addr_iter->address.subnet.prefix_length); + } + + LL_FOREACH(iter->interface.ipv4.neighbor, v4neigh_iter) + { + SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv4:Neighbor = %s : %s", v4neigh_iter->neighbor.ip, v4neigh_iter->neighbor.link_layer_address); } LL_FOREACH(iter->interface.ipv6.address, v6addr_iter) { - SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv6:Address %s:", v6addr_iter->address.ip); - SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv6:Address IP = %s", v6addr_iter->address.ip); - SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv6:Address Prefix Length = %d", v6addr_iter->address.prefix_length); + SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv6:Address = %s/%d", v6addr_iter->address.ip, v6addr_iter->address.prefix_length); + } + + LL_FOREACH(iter->interface.ipv6.neighbor, v6neigh_iter) + { + SRPLG_LOG_INF(PLUGIN_NAME, "\t IPv6:Neighbor = %s : %s", v6neigh_iter->neighbor.ip, v6neigh_iter->neighbor.link_layer_address); } } } @@ -308,6 +315,13 @@ int interfaces_interface_hash_from_ly(interfaces_interface_hash_element_t** if_h return error; } +int interfaces_interface_hash_to_ly(interfaces_interface_hash_element_t* if_hash, struct lyd_node** interfaces_container_node) +{ + int error = 0; + + return error; +} + int interfaces_interface_hash_add_element(interfaces_interface_hash_element_t** hash, interfaces_interface_hash_element_t* new_element) { interfaces_interface_hash_element_t* found_element = NULL; diff --git a/src/interfaces/src/plugin/data/interfaces/interface.h b/src/interfaces/src/plugin/data/interfaces/interface.h index 2c62cff7..09df7f55 100644 --- a/src/interfaces/src/plugin/data/interfaces/interface.h +++ b/src/interfaces/src/plugin/data/interfaces/interface.h @@ -11,6 +11,7 @@ interfaces_interface_hash_element_t* interfaces_interface_hash_new(void); void interfaces_interface_hash_print_debug(const interfaces_interface_hash_element_t* if_hash); int interfaces_interface_hash_from_ly(interfaces_interface_hash_element_t** if_hash, const struct lyd_node* interface_list_node); +int interfaces_interface_hash_to_ly(interfaces_interface_hash_element_t* if_hash, struct lyd_node** interfaces_container_node); int interfaces_interface_hash_add_element(interfaces_interface_hash_element_t** hash, interfaces_interface_hash_element_t* new_element); interfaces_interface_hash_element_t* interfaces_interface_hash_get_element(interfaces_interface_hash_element_t** hash, const char* name); void interfaces_interface_hash_free(interfaces_interface_hash_element_t** hash); diff --git a/src/interfaces/src/plugin/startup/load.c b/src/interfaces/src/plugin/startup/load.c index b571a19b..c30065f8 100644 --- a/src/interfaces/src/plugin/startup/load.c +++ b/src/interfaces/src/plugin/startup/load.c @@ -84,58 +84,23 @@ 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_hash_element_t* interface_hash = NULL; - interfaces_interface_ipv4_address_element_t* v4_addr_iter = NULL; - interfaces_interface_ipv6_address_element_t* v6_addr_iter = NULL; + // load interfaces data + SRPC_SAFE_CALL_ERR(error, interfaces_load_interface(ctx, &interface_hash), error_out); - interfaces_interface_ipv4_neighbor_element_t* v4_neigh_iter = NULL; - interfaces_interface_ipv6_neighbor_element_t* v6_neigh_iter = NULL; + // print debug info for now + // interfaces_interface_hash_print_debug(interface_hash); - 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); - } - } + // convert to libyang + SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_to_ly(interface_hash, &parent_node), error_out); goto out; error_out: error = -1; out: - interfaces_interface_hash_free(&interface_head); + interfaces_interface_hash_free(&interface_hash); return error; }