Skip to content

Commit

Permalink
Merge pull request #43 from andreiosg/refactor
Browse files Browse the repository at this point in the history
Interfaces load ipv4/6
  • Loading branch information
zinccyy authored Oct 31, 2022
2 parents 5f9bc18 + 4996e6a commit a20c5f7
Show file tree
Hide file tree
Showing 19 changed files with 677 additions and 59 deletions.
3 changes: 3 additions & 0 deletions src/interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ set(
# API
src/plugin/api/interfaces/check.c
src/plugin/api/interfaces/load.c
src/plugin/api/interfaces/read.c
src/plugin/api/interfaces/store.c
src/plugin/api/interfaces/change.c
src/plugin/api/interfaces/interface/change.c
src/plugin/api/interfaces/interface/ipv6/load.c
src/plugin/api/interfaces/interface/ipv6/change.c
src/plugin/api/interfaces/interface/ipv6/autoconf/change.c
src/plugin/api/interfaces/interface/ipv6/neighbor/change.c
src/plugin/api/interfaces/interface/ipv6/address/change.c
src/plugin/api/interfaces/interface/ipv4/change.c
src/plugin/api/interfaces/interface/ipv4/load.c
src/plugin/api/interfaces/interface/ipv4/neighbor/change.c
src/plugin/api/interfaces/interface/ipv4/address/change.c
src/plugin/api/interfaces/interface/encapsulation/dot1q-vlan/second-tag/change.c
Expand Down
68 changes: 68 additions & 0 deletions src/interfaces/src/plugin/api/interfaces/interface/ipv4/load.c
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 src/interfaces/src/plugin/api/interfaces/interface/ipv4/load.h
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 src/interfaces/src/plugin/api/interfaces/interface/ipv6/load.c
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 src/interfaces/src/plugin/api/interfaces/interface/ipv6/load.h
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 */

Loading

0 comments on commit a20c5f7

Please sign in to comment.