EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Functions
iface_mapper.c File Reference

File containing the implementation of the interface mapper utilities. More...

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "allocs.h"
#include "iface_mapper.h"
#include "ifaceu.h"
#include "log.h"
#include "net.h"
#include "os.h"
Include dependency graph for iface_mapper.c:

Functions

int get_if_mapper (hmap_if_conn *const *hmap, in_addr_t subnet, char ifname[static IF_NAMESIZE])
 Get the interface name corresponding to an IP address of the subnet. More...
 
bool put_if_mapper (hmap_if_conn **hmap, in_addr_t subnet, const char *ifname)
 Inserts an interface and subnet IP value into the interface connection mapper. More...
 
void free_if_mapper (hmap_if_conn **hmap)
 Frees the interface connection mapper object. More...
 
int get_vlan_mapper (hmap_vlan_conn *const *hmap, int vlanid, struct vlan_conn *conn)
 Get the vlan connection structure corresponding to a VLAN ID. More...
 
int copy_vlan_mapper (hmap_vlan_conn *const *hmap, hmap_vlan_conn **copy)
 Makes a copy of the VLAn mapper structure. More...
 
bool put_vlan_mapper (hmap_vlan_conn **hmap, const struct vlan_conn *conn)
 Inserts a vlan connection structure and VLAN ID value into the interface connection mapper. More...
 
void free_vlan_mapper (hmap_vlan_conn **hmap)
 Frees the VLAN ID to interface connection mapper object. More...
 
int find_ifinfo (const UT_array *config_ifinfo_array, const char *ip, config_ifinfo_t *ifinfo)
 
int get_brname_from_ip (const UT_array *config_ifinfo_array, const char *ip_addr, char brname[static IF_NAMESIZE])
 Get the bridge name from an IP string. More...
 
int get_ifname_from_ip (const UT_array *config_ifinfo_array, const char *ip_addr, char ifname[static IF_NAMESIZE])
 Get the interface name from an IP string. More...
 
bool create_if_mapper (const UT_array *config_ifinfo_array, hmap_if_conn **hmap)
 Create the subnet to interface mapper. More...
 
int create_vlan_mapper (const UT_array *config_ifinfo_array, hmap_vlan_conn **hmap)
 Create the VLAN ID to interface mapper. More...
 
int init_ifbridge_names (UT_array *config_ifinfo_array, const char *ifname, const char *brname)
 Initialise the interface names. More...
 

Detailed Description

File containing the implementation of the interface mapper utilities.

Author
Alexandru Mereacre
Date
2022

Function Documentation

◆ copy_vlan_mapper()

int copy_vlan_mapper ( hmap_vlan_conn *const *  hmap,
hmap_vlan_conn **  copy 
)

Makes a copy of the VLAn mapper structure.

Parameters
[in]hmapThe VLAN ID to vlan connection mapper object
[in,out]copyThe copied VLAN mapper.
Returns
int 1 if found, 0 not found, -1 on error

◆ create_if_mapper()

bool create_if_mapper ( const UT_array *  config_ifinfo_array,
hmap_if_conn **  hmap 
)

Create the subnet to interface mapper.

Parameters
[in]config_ifinfo_arrayThe connection info array
[in,out]hmapThe subnet to interface mapper
Returns
true on success, false otherwise

◆ create_vlan_mapper()

int create_vlan_mapper ( const UT_array *  config_ifinfo_array,
hmap_vlan_conn **  hmap 
)

Create the VLAN ID to interface mapper.

Parameters
[in]config_ifinfo_arrayThe connection info array
[in,out]hmapThe VLAN ID to interface mapper
Returns
0 on success, -1 otherwise

◆ find_ifinfo()

int find_ifinfo ( const UT_array *  config_ifinfo_array,
const char *  ip,
config_ifinfo_t ifinfo 
)

◆ free_if_mapper()

void free_if_mapper ( hmap_if_conn **  hmap)

Frees the interface connection mapper object.

Parameters
hmapThe interface connection mapper object

◆ free_vlan_mapper()

void free_vlan_mapper ( hmap_vlan_conn **  hmap)

Frees the VLAN ID to interface connection mapper object.

Parameters
hmapThe VLAN ID to interface connection mapper object

◆ get_brname_from_ip()

int get_brname_from_ip ( const UT_array *  config_ifinfo_array,
const char *  ip_addr,
char  brname[static IF_NAMESIZE] 
)

Get the bridge name from an IP string.

Parameters
[in]config_ifinfo_arrayThe list of IP subnets
[in]ip_addrThe input IP address
[out]brnameThe returned bridge name (buffer has to be preallocated to at least the size of config_ifinfo_t::brname).
Returns
0 on success, -1 otherwise

◆ get_if_mapper()

int get_if_mapper ( hmap_if_conn *const *  hmap,
in_addr_t  subnet,
char  ifname[static IF_NAMESIZE] 
)

Get the interface name corresponding to an IP address of the subnet.

Parameters
[in]hmapThe interface connection mapper object
[in]subnetThe IP address of the subnet
[out]ifnameThe buffer to store the returned interface name. Must be at least IF_NAMESIZE large.
Returns
int 1 if found, 0 not found, -1 on error

◆ get_ifname_from_ip()

int get_ifname_from_ip ( const UT_array *  config_ifinfo_array,
const char *  ip,
char  ifname[static IF_NAMESIZE] 
)

Get the interface name from an IP string.

Parameters
[in]config_ifinfo_arrayThe list of IP subnets
[in]ipThe input IP address
[out]ifnameThe returned interface name (buffer has to be preallocated at least the size of config_ifinfo_t::ifname)
Returns
0 on success, -1 otherwise

◆ get_vlan_mapper()

int get_vlan_mapper ( hmap_vlan_conn *const *  hmap,
int  vlanid,
struct vlan_conn conn 
)

Get the vlan connection structure corresponding to a VLAN ID.

Parameters
[in]hmapThe VLAN ID to vlan connection mapper object
[in]vlanidThe VLAN ID
[out]connThe returned VLAN connection structure
Returns
int 1 if found, 0 not found, -1 on error

◆ init_ifbridge_names()

int init_ifbridge_names ( UT_array *  config_ifinfo_array,
const char *  ifname,
const char *  brname 
)

Initialise the interface names.

Parameters
[in,out]config_ifinfo_arrayThe connection info array
[in]ifnameThe interface name prefix
[in]brnameThe bridge name prefix
Returns
0 on success, -1 otherwise

◆ put_if_mapper()

bool put_if_mapper ( hmap_if_conn **  hmap,
in_addr_t  subnet,
const char *  ifname 
)

Inserts an interface and subnet IP value into the interface connection mapper.

Parameters
[in,out]hmapThe interface connection mapper object
[in]subnetThe IP address of the subnet
[in]ifnameThe interface name
Returns
true on success, false otherwise

◆ put_vlan_mapper()

bool put_vlan_mapper ( hmap_vlan_conn **  hmap,
const struct vlan_conn conn 
)

Inserts a vlan connection structure and VLAN ID value into the interface connection mapper.

Parameters
[in,out]hmapThe VLAN ID to interface connection mapper object
[in]connThe VLAN connection structure
Returns
true on success, false otherwise