-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interfaces-plugin: add IPv4 and IPv6 address and neighbor load API
- Loading branch information
Showing
13 changed files
with
377 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/interfaces/src/plugin/api/interfaces/interface/ipv4/address/load.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/interfaces/src/plugin/api/interfaces/interface/ipv4/neighbor/load.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
52 changes: 52 additions & 0 deletions
52
src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/interfaces/src/plugin/api/interfaces/interface/ipv6/address/load.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.