-
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: reorganize interface info loading code into interf…
…ace load API
- Loading branch information
Showing
4 changed files
with
88 additions
and
48 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
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,66 @@ | ||
#include "load.h" | ||
#include "plugin/data/interfaces/interface.h" | ||
|
||
#include <linux/if.h> | ||
#include <srpc.h> | ||
|
||
int interfaces_interface_load_name(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link) | ||
{ | ||
int error = 0; | ||
|
||
const char* nl_if_name = NULL; | ||
|
||
nl_if_name = rtnl_link_get_name(link); | ||
|
||
// set element values | ||
SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_element_set_name(element, nl_if_name), error_out); | ||
|
||
goto out; | ||
|
||
error_out: | ||
error = -1; | ||
|
||
out: | ||
return error; | ||
} | ||
|
||
int interfaces_interface_load_type(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link) | ||
{ | ||
int error = 0; | ||
|
||
const char* nl_if_type = NULL; | ||
const char* ly_if_type = NULL; | ||
|
||
// 2. 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); | ||
SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_element_set_type(element, ly_if_type), error_out); | ||
|
||
goto out; | ||
|
||
error_out: | ||
error = -1; | ||
|
||
out: | ||
|
||
return error; | ||
} | ||
|
||
int interfaces_interface_load_enabled(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link) | ||
{ | ||
int error = 0; | ||
|
||
uint8_t nl_enabled = (rtnl_link_get_operstate(link) == IF_OPER_UP || rtnl_link_get_operstate(link) == IF_OPER_UNKNOWN); | ||
|
||
SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_element_set_enabled(element, nl_enabled), error_out); | ||
|
||
goto out; | ||
|
||
error_out: | ||
error = -1; | ||
|
||
out: | ||
|
||
return error; | ||
} |
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,13 @@ | ||
#ifndef INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_LOAD_H | ||
#define INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_LOAD_H | ||
|
||
#include "plugin/context.h" | ||
#include "plugin/types.h" | ||
|
||
#include <netlink/route/link.h> | ||
|
||
int interfaces_interface_load_name(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link); | ||
int interfaces_interface_load_type(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link); | ||
int interfaces_interface_load_enabled(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link); | ||
|
||
#endif // INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_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