-
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: refactor IPv4 and IPv6 data code
- Loading branch information
Showing
11 changed files
with
107 additions
and
146 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
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
69 changes: 21 additions & 48 deletions
69
src/interfaces/src/plugin/api/interfaces/interface/ipv6/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,75 +1,48 @@ | ||
#include "load.h" | ||
#include "netlink/route/link.h" | ||
#include "plugin/data/interfaces/interface.h" | ||
#include "plugin/data/interfaces/interface/ipv6.h" | ||
|
||
int interfaces_add_address_ipv6(interfaces_interface_ipv6_address_element_t **address, char *ip, char *netmask) | ||
int interfaces_interface_ipv6_load_enabled(interfaces_ctx_t* ctx, interfaces_interface_ipv6_t* ipv6, struct rtnl_link* link) | ||
{ | ||
int error = 0; | ||
uint8_t prefix_length = 0; | ||
|
||
interfaces_interface_ipv6_address_element_t* new_element = NULL; | ||
// enabled by default | ||
SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_element_ipv6_set_enabled(ipv6, 1), error_out); | ||
|
||
new_element = interfaces_interface_ipv6_address_element_new(); | ||
goto out; | ||
|
||
interfaces_interface_ipv6_address_element_set_ip(&new_element, ip); | ||
SRPC_SAFE_CALL_ERR(error, interfaces_interface_ipv4_address_netmask2prefix(netmask, prefix_length), out); | ||
interfaces_interface_ipv6_address_element_set_prefix_length(&new_element, prefix_length); | ||
interfaces_interface_ipv6_address_add_element(address, new_element); | ||
error_out: | ||
error = -1; | ||
|
||
out: | ||
return error; | ||
} | ||
|
||
int interfaces_add_neighbor_ipv6(interfaces_interface_ipv6_neighbor_element_t** neighbor, char *dst_addr, char *ll_addr) | ||
{ | ||
interfaces_interface_ipv6_neighbor_element_t* new_element = NULL; | ||
|
||
new_element = interfaces_interface_ipv6_neighbor_element_new(); | ||
|
||
interfaces_interface_ipv6_neighbor_element_set_ip(&new_element, dst_addr); | ||
interfaces_interface_ipv6_neighbor_element_set_link_layer_address(&new_element, ll_addr); | ||
interfaces_interface_ipv6_neighbor_add_element(neighbor, new_element); | ||
|
||
return 0; | ||
} | ||
|
||
unsigned int interfaces_get_ipv6_mtu(struct rtnl_link* link, interfaces_interface_t* interface) | ||
{ | ||
unsigned int mtu = 0; | ||
|
||
mtu = rtnl_link_get_mtu(link); | ||
|
||
interface->ipv6.mtu = mtu; | ||
|
||
return 0; | ||
|
||
return error; | ||
} | ||
|
||
unsigned int interfaces_get_ipv6_enabled(interfaces_interface_t* interface) | ||
int interfaces_interface_ipv6_load_forwarding(interfaces_ctx_t* ctx, interfaces_interface_ipv6_t* ipv6, struct rtnl_link* link) | ||
{ | ||
int error = 0; | ||
int enabled = 0; | ||
|
||
const char *ipv6_base = "/proc/sys/net/ipv6/conf"; | ||
|
||
SRPC_SAFE_CALL_ERR(error, read_from_proc_file(ipv6_base, interface->name, "disable_ipv6", &enabled), out); | ||
// TODO: implement | ||
|
||
interface->ipv6.enabled = enabled; | ||
|
||
out: | ||
return error; | ||
} | ||
|
||
unsigned int interfaces_get_ipv6_forwarding(interfaces_interface_t* interface) | ||
int interfaces_interface_ipv6_load_mtu(interfaces_ctx_t* ctx, interfaces_interface_ipv6_t* ipv6, struct rtnl_link* link) | ||
{ | ||
int error = 0; | ||
int forwarding = 0; | ||
|
||
const char *ipv6_base = "/proc/sys/net/ipv6/conf"; | ||
|
||
SRPC_SAFE_CALL_ERR(error, read_from_proc_file(ipv6_base, interface->name, "forwarding", &forwarding), out); | ||
const unsigned int mtu = rtnl_link_get_mtu(link); | ||
|
||
interface->ipv6.forwarding = forwarding; | ||
SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_element_ipv6_set_mtu(ipv6, (uint16_t)mtu), error_out); | ||
|
||
goto out; | ||
|
||
error_out: | ||
error = -1; | ||
|
||
out: | ||
|
||
return error; | ||
} | ||
|
19 changes: 6 additions & 13 deletions
19
src/interfaces/src/plugin/api/interfaces/interface/ipv6/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,20 +1,13 @@ | ||
#ifndef INTERFACES_PLUGIN_API_INTERFACES_IPV6_LOAD_H | ||
#define INTERFACES_PLUGIN_API_INTERFACES_IPV6_LOAD_H | ||
#ifndef INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV6_LOAD_H | ||
#define INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV6_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_ipv6(interfaces_interface_ipv6_address_element_t **address, char *ip, char *netmask); | ||
|
||
int interfaces_add_neighbor_ipv6(interfaces_interface_ipv6_neighbor_element_t** neighbor, char *dst_addr, char *ll_addr); | ||
|
||
unsigned int interfaces_get_ipv6_mtu(struct rtnl_link* link, interfaces_interface_t* interface); | ||
|
||
unsigned int interfaces_get_ipv6_enabled(interfaces_interface_t* interface); | ||
|
||
unsigned int interfaces_get_ipv6_forwarding(interfaces_interface_t* interface); | ||
|
||
#endif /* INTERFACES_PLUGIN_API_INTERFACES_IPV6_LOAD_H */ | ||
int interfaces_interface_ipv6_load_enabled(interfaces_ctx_t* ctx, interfaces_interface_ipv6_t* ipv6, struct rtnl_link* link); | ||
int interfaces_interface_ipv6_load_forwarding(interfaces_ctx_t* ctx, interfaces_interface_ipv6_t* ipv6, struct rtnl_link* link); | ||
int interfaces_interface_ipv6_load_mtu(interfaces_ctx_t* ctx, interfaces_interface_ipv6_t* ipv6, struct rtnl_link* link); | ||
|
||
#endif // INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_IPV6_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
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
22 changes: 22 additions & 0 deletions
22
src/interfaces/src/plugin/data/interfaces/interface/ipv4.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,22 @@ | ||
#include "ipv4.h" | ||
|
||
int interfaces_interface_hash_element_ipv4_set_enabled(interfaces_interface_ipv4_t* ipv4, uint8_t enabled) | ||
{ | ||
ipv4->enabled = enabled; | ||
|
||
return 0; | ||
} | ||
|
||
int interfaces_interface_hash_element_ipv4_set_forwarding(interfaces_interface_ipv4_t* ipv4, uint8_t forwarding) | ||
{ | ||
ipv4->forwarding = forwarding; | ||
|
||
return 0; | ||
} | ||
|
||
int interfaces_interface_hash_element_ipv4_set_mtu(interfaces_interface_ipv4_t* ipv4, uint16_t mtu) | ||
{ | ||
ipv4->mtu = mtu; | ||
|
||
return 0; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/interfaces/src/plugin/data/interfaces/interface/ipv4.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,10 @@ | ||
#ifndef INTERFACES_PLUGIN_DATA_INTERFACES_INTERFACE_IPV4_H | ||
#define INTERFACES_PLUGIN_DATA_INTERFACES_INTERFACE_IPV4_H | ||
|
||
#include "plugin/types.h" | ||
|
||
int interfaces_interface_hash_element_ipv4_set_enabled(interfaces_interface_ipv4_t* ipv4, uint8_t enabled); | ||
int interfaces_interface_hash_element_ipv4_set_forwarding(interfaces_interface_ipv4_t* ipv4, uint8_t forwarding); | ||
int interfaces_interface_hash_element_ipv4_set_mtu(interfaces_interface_ipv4_t* ipv4, uint16_t mtu); | ||
|
||
#endif // INTERFACES_PLUGIN_DATA_INTERFACES_INTERFACE_IPV4_H |
22 changes: 22 additions & 0 deletions
22
src/interfaces/src/plugin/data/interfaces/interface/ipv6.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,22 @@ | ||
#include "ipv6.h" | ||
|
||
int interfaces_interface_hash_element_ipv6_set_enabled(interfaces_interface_ipv6_t* ipv6, uint8_t enabled) | ||
{ | ||
ipv6->enabled = enabled; | ||
|
||
return 0; | ||
} | ||
|
||
int interfaces_interface_hash_element_ipv6_set_forwarding(interfaces_interface_ipv6_t* ipv6, uint8_t forwarding) | ||
{ | ||
ipv6->forwarding = forwarding; | ||
|
||
return 0; | ||
} | ||
|
||
int interfaces_interface_hash_element_ipv6_set_mtu(interfaces_interface_ipv6_t* ipv6, uint16_t mtu) | ||
{ | ||
ipv6->mtu = mtu; | ||
|
||
return 0; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/interfaces/src/plugin/data/interfaces/interface/ipv6.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,10 @@ | ||
#ifndef INTERFACES_PLUGIN_DATA_INTERFACES_INTERFACE_IPV6_H | ||
#define INTERFACES_PLUGIN_DATA_INTERFACES_INTERFACE_IPV6_H | ||
|
||
#include "plugin/types.h" | ||
|
||
int interfaces_interface_hash_element_ipv6_set_enabled(interfaces_interface_ipv6_t* ipv6, uint8_t enabled); | ||
int interfaces_interface_hash_element_ipv6_set_forwarding(interfaces_interface_ipv6_t* ipv6, uint8_t forwarding); | ||
int interfaces_interface_hash_element_ipv6_set_mtu(interfaces_interface_ipv6_t* ipv6, uint16_t mtu); | ||
|
||
#endif // INTERFACES_PLUGIN_DATA_INTERFACES_INTERFACE_IPV6_H |