From 43f3ce7e2b32e9bfa4d8c4730d83a883bd9dcd2b Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Mon, 31 Oct 2022 20:42:28 +0000 Subject: [PATCH] interfaces-plugin: add IPv4 and IPv6 address and neighbor load API --- src/interfaces/CMakeLists.txt | 4 + .../interfaces/interface/ipv4/address/load.c | 52 +++++++++ .../interfaces/interface/ipv4/address/load.h | 11 ++ .../api/interfaces/interface/ipv4/load.c | 105 ++++++++++++++++++ .../interfaces/interface/ipv4/neighbor/load.c | 58 ++++++++++ .../interfaces/interface/ipv4/neighbor/load.h | 11 ++ .../interfaces/interface/ipv6/address/load.c | 52 +++++++++ .../interfaces/interface/ipv6/address/load.h | 11 ++ .../interfaces/interface/ipv6/neighbor/load.c | 58 ++++++++++ .../interfaces/interface/ipv6/neighbor/load.h | 11 ++ .../src/plugin/api/interfaces/load.c | 3 + .../data/interfaces/interface/ipv4/address.c | 46 +------- .../data/interfaces/interface/ipv4/address.h | 1 - 13 files changed, 377 insertions(+), 46 deletions(-) create mode 100644 src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.c create mode 100644 src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.h create mode 100644 src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.c create mode 100644 src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.h create mode 100644 src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.c create mode 100644 src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.h create mode 100644 src/interfaces/src/plugin/api/interfaces/interface/ipv6/neighbor/load.c create mode 100644 src/interfaces/src/plugin/api/interfaces/interface/ipv6/neighbor/load.h diff --git a/src/interfaces/CMakeLists.txt b/src/interfaces/CMakeLists.txt index 41f1a22b..96f1b6d5 100644 --- a/src/interfaces/CMakeLists.txt +++ b/src/interfaces/CMakeLists.txt @@ -38,11 +38,15 @@ set( src/plugin/api/interfaces/interface/ipv6/change.c src/plugin/api/interfaces/interface/ipv6/autoconf/change.c src/plugin/api/interfaces/interface/ipv6/neighbor/change.c + src/plugin/api/interfaces/interface/ipv6/neighbor/load.c src/plugin/api/interfaces/interface/ipv6/address/change.c + src/plugin/api/interfaces/interface/ipv6/address/load.c src/plugin/api/interfaces/interface/ipv4/change.c src/plugin/api/interfaces/interface/ipv4/load.c src/plugin/api/interfaces/interface/ipv4/neighbor/change.c + src/plugin/api/interfaces/interface/ipv4/neighbor/load.c src/plugin/api/interfaces/interface/ipv4/address/change.c + src/plugin/api/interfaces/interface/ipv4/address/load.c src/plugin/api/interfaces/interface/encapsulation/dot1q-vlan/second-tag/change.c src/plugin/api/interfaces/interface/encapsulation/dot1q-vlan/outer-tag/change.c src/plugin/api/interfaces/interface/dampening/change.c diff --git a/src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.c b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.c new file mode 100644 index 00000000..95985878 --- /dev/null +++ b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.c @@ -0,0 +1,52 @@ +#include "load.h" +#include "netlink/addr.h" +#include "netlink/route/addr.h" +#include "plugin/data/interfaces/interface/ipv4/address.h" + +int interfaces_interface_ipv4_address_load_ip(interfaces_ctx_t* ctx, interfaces_interface_ipv4_address_element_t** element, struct rtnl_addr* addr) +{ + int error = 0; + void* error_ptr = NULL; + char ip_buffer[100] = { 0 }; + + // convert to nl_addr + struct nl_addr* local = rtnl_addr_get_local(addr); + + // parse to string + SRPC_SAFE_CALL_PTR(error_ptr, nl_addr2str(local, ip_buffer, sizeof(ip_buffer)), error_out); + + char* prefix = strchr(ip_buffer, '/'); + if (prefix) { + *prefix = 0; + } + + // set IP + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_address_element_set_ip(element, ip_buffer), error_out); + + goto out; + +error_out: + error = -1; + +out: + + return error; +} + +int interfaces_interface_ipv4_address_load_prefix_length(interfaces_ctx_t* ctx, interfaces_interface_ipv4_address_element_t** element, struct rtnl_addr* addr) +{ + int error = 0; + + const uint8_t prefix = (uint8_t)rtnl_addr_get_prefixlen(addr); + + // set prefix length + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_address_element_set_prefix_length(element, prefix), error_out); + + goto out; + +error_out: + error = -1; + +out: + return error; +} diff --git a/src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.h b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.h new file mode 100644 index 00000000..84288cea --- /dev/null +++ b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.h @@ -0,0 +1,11 @@ +#ifndef INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV4_ADDRESS_LOAD_H +#define INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV4_ADDRESS_LOAD_H + +#include "netlink/route/addr.h" +#include "plugin/context.h" +#include "plugin/types.h" + +int interfaces_interface_ipv4_address_load_ip(interfaces_ctx_t* ctx, interfaces_interface_ipv4_address_element_t** element, struct rtnl_addr* addr); +int interfaces_interface_ipv4_address_load_prefix_length(interfaces_ctx_t* ctx, interfaces_interface_ipv4_address_element_t** element, struct rtnl_addr* addr); + +#endif // INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV4_ADDRESS_LOAD_H diff --git a/src/interfaces/src/plugin/api/interfaces/interface/ipv4/load.c b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/load.c index efbce678..8d1b0ff7 100644 --- a/src/interfaces/src/plugin/api/interfaces/interface/ipv4/load.c +++ b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/load.c @@ -1,7 +1,14 @@ #include "load.h" +#include "netlink/route/addr.h" #include "netlink/route/link.h" +#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/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" int interfaces_interface_ipv4_load_enabled(interfaces_ctx_t* ctx, interfaces_interface_ipv4_t* ipv4, struct rtnl_link* link) { @@ -50,11 +57,109 @@ int interfaces_interface_ipv4_load_mtu(interfaces_ctx_t* ctx, interfaces_interfa int interfaces_interface_ipv4_load_address(interfaces_ctx_t* ctx, interfaces_interface_ipv4_t* ipv4, struct rtnl_link* link) { int error = 0; + interfaces_nl_ctx_t* nl_ctx = &ctx->startup_ctx.nl_ctx; + struct rtnl_addr* addr_iter = NULL; + + // created element + interfaces_interface_ipv4_address_element_t* new_element = NULL; + uint8_t element_added = 0; + + // allocate address list + ipv4->address = interfaces_interface_ipv4_address_new(); + + // allocate cache + SRPC_SAFE_CALL_ERR(error, rtnl_addr_alloc_cache(nl_ctx->socket, &nl_ctx->addr_cache), error_out); + + // get link iterator + SRPC_SAFE_CALL_PTR(addr_iter, (struct rtnl_addr*)nl_cache_get_first(nl_ctx->addr_cache), error_out); + + // iterate links + while (addr_iter) { + // get all addresses from the link and extract info + if (rtnl_addr_get_ifindex(addr_iter) == rtnl_link_get_ifindex(link) && rtnl_addr_get_family(addr_iter) == AF_INET) { + // create new element + new_element = interfaces_interface_ipv4_address_element_new(); + element_added = 0; + + // load IP and prefix + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_address_load_ip(ctx, &new_element, addr_iter), error_out); + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_address_load_prefix_length(ctx, &new_element, addr_iter), error_out); + + // add element to the list + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_address_add_element(&ipv4->address, new_element), error_out); + element_added = 1; + } + + // iterate + SRPC_SAFE_CALL_PTR(addr_iter, (struct rtnl_addr*)nl_cache_get_next((struct nl_object*)addr_iter), error_out); + } + + goto out; + +error_out: + error = -1; + + // if interrupted see if any memory is left over from the allocated element - free the element + if (!element_added) { + interfaces_interface_ipv4_address_element_free(&new_element); + } + +out: + return error; } int interfaces_interface_ipv4_load_neighbor(interfaces_ctx_t* ctx, interfaces_interface_ipv4_t* ipv4, struct rtnl_link* link) { int error = 0; + interfaces_nl_ctx_t* nl_ctx = &ctx->startup_ctx.nl_ctx; + struct rtnl_neigh* neigh_iter = NULL; + + // created element + interfaces_interface_ipv4_neighbor_element_t* new_element = NULL; + uint8_t element_added = 0; + + // allocate address list + ipv4->neighbor = interfaces_interface_ipv4_neighbor_new(); + + // allocate cache + SRPC_SAFE_CALL_ERR(error, rtnl_neigh_alloc_cache(nl_ctx->socket, &nl_ctx->neigh_cache), error_out); + + // get link iterator + SRPC_SAFE_CALL_PTR(neigh_iter, (struct rtnl_neigh*)nl_cache_get_first(nl_ctx->addr_cache), error_out); + + // iterate links + while (neigh_iter) { + // get all neighbors from the link and extract info + if (rtnl_neigh_get_ifindex(neigh_iter) == rtnl_link_get_ifindex(link) && rtnl_neigh_get_family(neigh_iter) == AF_INET) { + // create new element + new_element = interfaces_interface_ipv4_neighbor_element_new(); + element_added = 0; + + // load IP and prefix + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_neighbor_load_ip(ctx, &new_element, neigh_iter), error_out); + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_neighbor_load_link_layer_address(ctx, &new_element, neigh_iter), error_out); + + // add element to the list + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_neighbor_add_element(&ipv4->neighbor, new_element), error_out); + element_added = 1; + } + + // iterate + SRPC_SAFE_CALL_PTR(neigh_iter, (struct rtnl_neigh*)nl_cache_get_next((struct nl_object*)neigh_iter), error_out); + } + + goto out; + +error_out: + error = -1; + + // if interrupted see if any memory is left over from the allocated element - free the element + if (!element_added) { + interfaces_interface_ipv4_neighbor_element_free(&new_element); + } + +out: + return error; } diff --git a/src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.c b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.c new file mode 100644 index 00000000..63540792 --- /dev/null +++ b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.c @@ -0,0 +1,58 @@ +#include "load.h" +#include "netlink/route/neighbour.h" +#include "plugin/data/interfaces/interface/ipv4/neighbor.h" + +int interfaces_interface_ipv4_neighbor_load_ip(interfaces_ctx_t* ctx, interfaces_interface_ipv4_neighbor_element_t** element, struct rtnl_neigh* neigh) +{ + int error = 0; + void* error_ptr = NULL; + char ip_buffer[100] = { 0 }; + + // convert to nl_addr + struct nl_addr* dst = rtnl_neigh_get_dst(neigh); + + // parse to string + SRPC_SAFE_CALL_PTR(error_ptr, nl_addr2str(dst, ip_buffer, sizeof(ip_buffer)), error_out); + + char* prefix = strchr(ip_buffer, '/'); + if (prefix) { + *prefix = 0; + } + + // set IP + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_neighbor_element_set_ip(element, ip_buffer), error_out); + + goto out; + +error_out: + error = -1; + +out: + + return error; +} + +int interfaces_interface_ipv4_neighbor_load_link_layer_address(interfaces_ctx_t* ctx, interfaces_interface_ipv4_neighbor_element_t** element, struct rtnl_neigh* neigh) +{ + int error = 0; + void* error_ptr = NULL; + char lladdr_buffer[100] = { 0 }; + + // convert to nl_addr + struct nl_addr* dst = rtnl_neigh_get_lladdr(neigh); + + // parse to string + SRPC_SAFE_CALL_PTR(error_ptr, nl_addr2str(dst, lladdr_buffer, sizeof(lladdr_buffer)), error_out); + + // set lladdr + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_neighbor_element_set_link_layer_address(element, lladdr_buffer), error_out); + + goto out; + +error_out: + error = -1; + +out: + + return error; +} diff --git a/src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.h b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.h new file mode 100644 index 00000000..74dc942e --- /dev/null +++ b/src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.h @@ -0,0 +1,11 @@ +#ifndef INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV4_NEIGHBOR_LOAD_H +#define INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV4_NEIGHBOR_LOAD_H + +#include "netlink/route/neighbour.h" +#include "plugin/context.h" +#include "plugin/types.h" + +int interfaces_interface_ipv4_neighbor_load_ip(interfaces_ctx_t* ctx, interfaces_interface_ipv4_neighbor_element_t** element, struct rtnl_neigh* neigh); +int interfaces_interface_ipv4_neighbor_load_link_layer_address(interfaces_ctx_t* ctx, interfaces_interface_ipv4_neighbor_element_t** element, struct rtnl_neigh* neigh); + +#endif // INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV4_NEIGHBOR_LOAD_H diff --git a/src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.c b/src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.c new file mode 100644 index 00000000..1dda97ff --- /dev/null +++ b/src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.c @@ -0,0 +1,52 @@ +#include "load.h" +#include "netlink/addr.h" +#include "netlink/route/addr.h" +#include "plugin/data/interfaces/interface/ipv6/address.h" + +int interfaces_interface_ipv6_address_load_ip(interfaces_ctx_t* ctx, interfaces_interface_ipv6_address_element_t** element, struct rtnl_addr* addr) +{ + int error = 0; + void* error_ptr = NULL; + char ip_buffer[100] = { 0 }; + + // convert to nl_addr + struct nl_addr* local = rtnl_addr_get_local(addr); + + // parse to string + SRPC_SAFE_CALL_PTR(error_ptr, nl_addr2str(local, ip_buffer, sizeof(ip_buffer)), error_out); + + char* prefix = strchr(ip_buffer, '/'); + if (prefix) { + *prefix = 0; + } + + // set IP + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv6_address_element_set_ip(element, ip_buffer), error_out); + + goto out; + +error_out: + error = -1; + +out: + + return error; +} + +int interfaces_interface_ipv6_address_load_prefix_length(interfaces_ctx_t* ctx, interfaces_interface_ipv6_address_element_t** element, struct rtnl_addr* addr) +{ + int error = 0; + + const uint8_t prefix = (uint8_t)rtnl_addr_get_prefixlen(addr); + + // set prefix length + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv6_address_element_set_prefix_length(element, prefix), error_out); + + goto out; + +error_out: + error = -1; + +out: + return error; +} diff --git a/src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.h b/src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.h new file mode 100644 index 00000000..140245fe --- /dev/null +++ b/src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.h @@ -0,0 +1,11 @@ +#ifndef INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV6_ADDRESS_LOAD_H +#define INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV6_ADDRESS_LOAD_H + +#include "netlink/route/addr.h" +#include "plugin/context.h" +#include "plugin/types.h" + +int interfaces_interface_ipv6_address_load_ip(interfaces_ctx_t* ctx, interfaces_interface_ipv6_address_element_t** element, struct rtnl_addr* addr); +int interfaces_interface_ipv6_address_load_prefix_length(interfaces_ctx_t* ctx, interfaces_interface_ipv6_address_element_t** element, struct rtnl_addr* addr); + +#endif // INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV6_ADDRESS_LOAD_H diff --git a/src/interfaces/src/plugin/api/interfaces/interface/ipv6/neighbor/load.c b/src/interfaces/src/plugin/api/interfaces/interface/ipv6/neighbor/load.c new file mode 100644 index 00000000..1301f6f8 --- /dev/null +++ b/src/interfaces/src/plugin/api/interfaces/interface/ipv6/neighbor/load.c @@ -0,0 +1,58 @@ +#include "load.h" +#include "netlink/route/neighbour.h" +#include "plugin/data/interfaces/interface/ipv6/neighbor.h" + +int interfaces_interface_ipv6_neighbor_load_ip(interfaces_ctx_t* ctx, interfaces_interface_ipv6_neighbor_element_t** element, struct rtnl_neigh* neigh) +{ + int error = 0; + void* error_ptr = NULL; + char ip_buffer[100] = { 0 }; + + // convert to nl_addr + struct nl_addr* dst = rtnl_neigh_get_dst(neigh); + + // parse to string + SRPC_SAFE_CALL_PTR(error_ptr, nl_addr2str(dst, ip_buffer, sizeof(ip_buffer)), error_out); + + char* prefix = strchr(ip_buffer, '/'); + if (prefix) { + *prefix = 0; + } + + // set IP + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv6_neighbor_element_set_ip(element, ip_buffer), error_out); + + goto out; + +error_out: + error = -1; + +out: + + return error; +} + +int interfaces_interface_ipv6_neighbor_load_link_layer_address(interfaces_ctx_t* ctx, interfaces_interface_ipv6_neighbor_element_t** element, struct rtnl_neigh* neigh) +{ + int error = 0; + void* error_ptr = NULL; + char lladdr_buffer[100] = { 0 }; + + // convert to nl_addr + struct nl_addr* dst = rtnl_neigh_get_lladdr(neigh); + + // parse to string + SRPC_SAFE_CALL_PTR(error_ptr, nl_addr2str(dst, lladdr_buffer, sizeof(lladdr_buffer)), error_out); + + // set lladdr + SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv6_neighbor_element_set_link_layer_address(element, lladdr_buffer), error_out); + + goto out; + +error_out: + error = -1; + +out: + + return error; +} diff --git a/src/interfaces/src/plugin/api/interfaces/interface/ipv6/neighbor/load.h b/src/interfaces/src/plugin/api/interfaces/interface/ipv6/neighbor/load.h new file mode 100644 index 00000000..eb3aaa6b --- /dev/null +++ b/src/interfaces/src/plugin/api/interfaces/interface/ipv6/neighbor/load.h @@ -0,0 +1,11 @@ +#ifndef INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV6_NEIGHBOR_LOAD_H +#define INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV6_NEIGHBOR_LOAD_H + +#include "netlink/route/neighbour.h" +#include "plugin/context.h" +#include "plugin/types.h" + +int interfaces_interface_ipv6_neighbor_load_ip(interfaces_ctx_t* ctx, interfaces_interface_ipv6_neighbor_element_t** element, struct rtnl_neigh* neigh); +int interfaces_interface_ipv6_neighbor_load_link_layer_address(interfaces_ctx_t* ctx, interfaces_interface_ipv6_neighbor_element_t** element, struct rtnl_neigh* neigh); + +#endif // INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV6_NEIGHBOR_LOAD_H diff --git a/src/interfaces/src/plugin/api/interfaces/load.c b/src/interfaces/src/plugin/api/interfaces/load.c index aba97c39..c010ee12 100644 --- a/src/interfaces/src/plugin/api/interfaces/load.c +++ b/src/interfaces/src/plugin/api/interfaces/load.c @@ -80,6 +80,9 @@ int interfaces_load_interface(interfaces_ctx_t* ctx, interfaces_interface_hash_e // load IPv4 address and neighbor lists 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); + + // iterate + SRPC_SAFE_CALL_PTR(link_iter, (struct rtnl_link*)nl_cache_get_next((struct nl_object*)link_iter), error_out); } goto out; diff --git a/src/interfaces/src/plugin/data/interfaces/interface/ipv4/address.c b/src/interfaces/src/plugin/data/interfaces/interface/ipv4/address.c index 39f1b508..ca810c2f 100644 --- a/src/interfaces/src/plugin/data/interfaces/interface/ipv4/address.c +++ b/src/interfaces/src/plugin/data/interfaces/interface/ipv4/address.c @@ -1,13 +1,12 @@ #include "address.h" #include "plugin/types.h" -#include "srpc/common.h" #include "src/utlist.h" +#include "srpc/common.h" #include #include #include #include -#include #include @@ -81,49 +80,6 @@ int interfaces_interface_ipv4_address_element_set_ip(interfaces_interface_ipv4_a return 0; } -/* set (deepcopy) an IPv4 address list */ -int interfaces_interface_ipv4_address_element_set(interfaces_interface_ipv4_address_element_t** src, - interfaces_interface_ipv4_address_element_t **dst) -{ - interfaces_interface_ipv4_address_element_t *src_iter = NULL; - interfaces_interface_ipv4_address_element_t *new_elem = NULL; - - LL_FOREACH(*src, src_iter) { - new_elem = interfaces_interface_ipv4_address_element_new(); - interfaces_interface_ipv4_address_element_set_ip(&new_elem, src_iter->address.ip); - interfaces_interface_ipv4_address_element_set_prefix_length(&new_elem, - src_iter->address.subnet.prefix_length); - - interfaces_interface_ipv4_address_add_element(dst, new_elem); - } - - return 0; -} - -int interfaces_interface_ipv4_address_element_set_subnet(interfaces_interface_ipv4_address_element_t** el, char *netmask, enum interfaces_interface_ipv4_address_subnet subtype) -{ - int error = 0; - int prefix_length = 0; - - switch (subtype) { - case interfaces_interface_ipv4_address_subnet_netmask: - interfaces_interface_ipv4_address_element_set_netmask(el, netmask); - break; - case interfaces_interface_ipv4_address_subnet_prefix_length: - SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_address_netmask2prefix(netmask, prefix_length), out); - interfaces_interface_ipv4_address_element_set_prefix_length(el, prefix_length); - break; - case interfaces_interface_ipv4_address_subnet_none: - break; - default: - error = -1; - } - -out: - - return error; -} - int interfaces_interface_ipv4_address_element_set_prefix_length(interfaces_interface_ipv4_address_element_t** el, uint8_t prefix_length) { (*el)->address.subnet.prefix_length = prefix_length; diff --git a/src/interfaces/src/plugin/data/interfaces/interface/ipv4/address.h b/src/interfaces/src/plugin/data/interfaces/interface/ipv4/address.h index fc80b240..057cd8a0 100644 --- a/src/interfaces/src/plugin/data/interfaces/interface/ipv4/address.h +++ b/src/interfaces/src/plugin/data/interfaces/interface/ipv4/address.h @@ -23,7 +23,6 @@ void interfaces_interface_ipv4_address_element_free(interfaces_interface_ipv4_ad int interfaces_interface_ipv4_address_element_set_ip(interfaces_interface_ipv4_address_element_t** el, const char* ip); int interfaces_interface_ipv4_address_element_set_prefix_length(interfaces_interface_ipv4_address_element_t** el, uint8_t prefix_length); int interfaces_interface_ipv4_address_element_set_netmask(interfaces_interface_ipv4_address_element_t** el, const char* netmask); -int interfaces_interface_ipv4_address_element_set(interfaces_interface_ipv4_address_element_t** src, interfaces_interface_ipv4_address_element_t **dst); /* Helper functions