-
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 info loading code
- Loading branch information
Showing
2 changed files
with
27 additions
and
56 deletions.
There are no files selected for viewing
63 changes: 21 additions & 42 deletions
63
src/interfaces/src/plugin/api/interfaces/interface/ipv4/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 |
---|---|---|
@@ -1,68 +1,47 @@ | ||
#include "load.h" | ||
#include "netlink/route/link.h" | ||
#include "plugin/data/interfaces/interface.h" | ||
|
||
|
||
int interfaces_add_address_ipv4(interfaces_interface_ipv4_address_element_t **address, char *ip, char *netmask) | ||
int interfaces_interface_ipv4_load_enabled(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link) | ||
{ | ||
int prefix_length = 0; | ||
int error = 0; | ||
|
||
interfaces_interface_ipv4_address_element_t* new_element = NULL; | ||
// enabled by default | ||
SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_element_set_ipv4_enabled(element, 1), error_out); | ||
|
||
new_element = interfaces_interface_ipv4_address_element_new(); | ||
goto out; | ||
|
||
interfaces_interface_ipv4_address_element_set_ip(&new_element, ip); | ||
SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_address_netmask2prefix(netmask, prefix_length), out); | ||
interfaces_interface_ipv4_address_element_set_subnet(&new_element, netmask, interfaces_interface_ipv4_address_subnet_prefix_length); | ||
interfaces_interface_ipv4_address_add_element(address, new_element); | ||
error_out: | ||
error = -1; | ||
|
||
out: | ||
return error; | ||
} | ||
|
||
int interfaces_add_neighbor_ipv4(interfaces_interface_ipv4_neighbor_element_t** neighbor, char *dst_addr, char *ll_addr) | ||
{ | ||
interfaces_interface_ipv4_neighbor_element_t* new_element = NULL; | ||
|
||
new_element = interfaces_interface_ipv4_neighbor_element_new(); | ||
|
||
interfaces_interface_ipv4_neighbor_element_set_ip(&new_element, dst_addr); | ||
interfaces_interface_ipv4_neighbor_element_set_link_layer_address(&new_element, ll_addr); | ||
interfaces_interface_ipv4_neighbor_add_element(neighbor, new_element); | ||
|
||
return 0; | ||
return error; | ||
} | ||
|
||
unsigned int interfaces_get_ipv4_mtu(struct rtnl_link* link, interfaces_interface_t* interface) | ||
int interfaces_interface_ipv4_load_forwarding(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link) | ||
{ | ||
unsigned int mtu = 0; | ||
|
||
mtu = rtnl_link_get_mtu(link); | ||
int error = 0; | ||
|
||
interface->ipv4.mtu = mtu; | ||
// TODO: implement | ||
|
||
return 0; | ||
return error; | ||
} | ||
|
||
unsigned int interfaces_get_ipv4_enabled(interfaces_interface_t* interface) | ||
int interfaces_interface_ipv4_load_mtu(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link) | ||
{ | ||
const char *ipv4_base = "/proc/sys/net/ipv4/conf"; | ||
|
||
/* TODO: figure out how to enable/disable ipv4 */ | ||
/* since disable_ipv4 doesn't exist in /proc/sys/net/ipv6/conf/interface_name */ | ||
int error = 0; | ||
|
||
} | ||
const unsigned int mtu = rtnl_link_get_mtu(link); | ||
|
||
unsigned int interfaces_get_ipv4_forwarding(interfaces_interface_t* interface) | ||
{ | ||
int error = 0; | ||
int forwarding = 0; | ||
SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_element_set_ipv4_mtu(element, (uint16_t)mtu), error_out); | ||
|
||
const char *ipv4_base = "/proc/sys/net/ipv4/conf"; | ||
|
||
SRPC_SAFE_CALL_ERR(error, read_from_proc_file(ipv4_base, interface->name, "forwarding", &forwarding), out); | ||
goto out; | ||
|
||
interface->ipv4.forwarding = forwarding; | ||
error_out: | ||
error = -1; | ||
|
||
out: | ||
|
||
return error; | ||
} |
20 changes: 6 additions & 14 deletions
20
src/interfaces/src/plugin/api/interfaces/interface/ipv4/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 |
---|---|---|
@@ -1,21 +1,13 @@ | ||
#ifndef INTERFACES_PLUGIN_API_INTERFACES_IPV4_LOAD_H | ||
#define INTERFACES_PLUGIN_API_INTERFACES_IPV4_LOAD_H | ||
#ifndef INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV4_LOAD_H | ||
#define INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV4_LOAD_H | ||
|
||
#include "plugin/context.h" | ||
#include "plugin/data/interfaces/interface.h" | ||
#include "plugin/data/interfaces/interface/linked_list.h" | ||
#include "plugin/types.h" | ||
|
||
int interfaces_add_address_ipv4(interfaces_interface_ipv4_address_element_t **address, char *ip, char *netmask); | ||
|
||
int interfaces_add_neighbor_ipv4(interfaces_interface_ipv4_neighbor_element_t** neighbor, char *dst_addr, char *ll_addr); | ||
|
||
unsigned int interfaces_get_ipv4_mtu(struct rtnl_link* link, interfaces_interface_t* interface); | ||
|
||
unsigned int interfaces_get_ipv4_enabled(interfaces_interface_t* interface); | ||
|
||
unsigned int interfaces_get_ipv4_forwarding(interfaces_interface_t* interface); | ||
|
||
|
||
#endif /* INTERFACES_PLUGIN_API_INTERFACES_IPV4_LOAD_H */ | ||
int interfaces_interface_ipv4_load_enabled(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link); | ||
int interfaces_interface_ipv4_load_forwarding(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link); | ||
int interfaces_interface_ipv4_load_mtu(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link); | ||
|
||
#endif // INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV4_LOAD_H |