Skip to content

Commit

Permalink
interfaces-plugin: add IPv4 info loading code
Browse files Browse the repository at this point in the history
  • Loading branch information
zinccyy committed Oct 31, 2022
1 parent 34a04b5 commit 060b0c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 56 deletions.
63 changes: 21 additions & 42 deletions src/interfaces/src/plugin/api/interfaces/interface/ipv4/load.c
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 src/interfaces/src/plugin/api/interfaces/interface/ipv4/load.h
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

0 comments on commit 060b0c5

Please sign in to comment.