-
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.
Merge pull request #43 from andreiosg/refactor
Interfaces load ipv4/6
- Loading branch information
Showing
19 changed files
with
677 additions
and
59 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
68 changes: 68 additions & 0 deletions
68
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "load.h" | ||
|
||
|
||
int interfaces_add_address_ipv4(interfaces_interface_ipv4_address_element_t **address, char *ip, char *netmask) | ||
{ | ||
int prefix_length = 0; | ||
int error = 0; | ||
|
||
interfaces_interface_ipv4_address_element_t* new_element = NULL; | ||
|
||
new_element = interfaces_interface_ipv4_address_element_new(); | ||
|
||
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); | ||
|
||
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; | ||
} | ||
|
||
unsigned int interfaces_get_ipv4_mtu(struct rtnl_link* link, interfaces_interface_t* interface) | ||
{ | ||
unsigned int mtu = 0; | ||
|
||
mtu = rtnl_link_get_mtu(link); | ||
|
||
interface->ipv4.mtu = mtu; | ||
|
||
return 0; | ||
} | ||
|
||
unsigned int interfaces_get_ipv4_enabled(interfaces_interface_t* interface) | ||
{ | ||
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 */ | ||
|
||
} | ||
|
||
unsigned int interfaces_get_ipv4_forwarding(interfaces_interface_t* interface) | ||
{ | ||
int error = 0; | ||
int forwarding = 0; | ||
|
||
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); | ||
|
||
interface->ipv4.forwarding = forwarding; | ||
|
||
out: | ||
return error; | ||
} |
21 changes: 21 additions & 0 deletions
21
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef INTERFACES_PLUGIN_API_INTERFACES_IPV4_LOAD_H | ||
#define INTERFACES_PLUGIN_API_INTERFACES_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 */ | ||
|
75 changes: 75 additions & 0 deletions
75
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "load.h" | ||
|
||
int interfaces_add_address_ipv6(interfaces_interface_ipv6_address_element_t **address, char *ip, char *netmask) | ||
{ | ||
int error = 0; | ||
uint8_t prefix_length = 0; | ||
|
||
interfaces_interface_ipv6_address_element_t* new_element = NULL; | ||
|
||
new_element = interfaces_interface_ipv6_address_element_new(); | ||
|
||
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); | ||
|
||
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; | ||
|
||
} | ||
|
||
unsigned int interfaces_get_ipv6_enabled(interfaces_interface_t* interface) | ||
{ | ||
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); | ||
|
||
interface->ipv6.enabled = enabled; | ||
|
||
out: | ||
return error; | ||
} | ||
|
||
unsigned int interfaces_get_ipv6_forwarding(interfaces_interface_t* interface) | ||
{ | ||
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); | ||
|
||
interface->ipv6.forwarding = forwarding; | ||
|
||
out: | ||
return error; | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef INTERFACES_PLUGIN_API_INTERFACES_IPV6_LOAD_H | ||
#define INTERFACES_PLUGIN_API_INTERFACES_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 */ | ||
|
Oops, something went wrong.