EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Data Structures | Macros | Typedefs | Enumerations | Functions
iface_mapper.h File Reference

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

#include <stdbool.h>
#include <netinet/in.h>
#include <inttypes.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <pthread.h>
#include <utarray.h>
#include <uthash.h>
#include "allocs.h"
#include "net.h"
#include "os.h"
Include dependency graph for iface_mapper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  netif_info_t
 Network interface definition structure. More...
 
struct  config_ifinfo_t
 Interface configuration info structure. More...
 
struct  hashmap_if_conn
 Subnet to interface connection mapper. More...
 
struct  vlan_conn
 MAC connection structure. More...
 
struct  hashmap_vlan_conn
 VLAN to interface connection mapper. More...
 

Macros

#define LINK_TYPE_LEN   64
 

Typedefs

typedef struct config_ifinfo_t config_ifinfo_t
 Interface configuration info structure. More...
 
typedef struct hashmap_if_conn hmap_if_conn
 Subnet to interface connection mapper. More...
 
typedef struct hashmap_vlan_conn hmap_vlan_conn
 VLAN to interface connection mapper. More...
 

Enumerations

enum  IF_STATE {
  IF_STATE_UNKNOWN = 0 , IF_STATE_NOTPRESENT , IF_STATE_DOWN , IF_STATE_LOWERLAYERDOWN ,
  IF_STATE_TESTING , IF_STATE_DORMANT , IF_STATE_UP , IF_STATE_OTHER
}
 

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 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. More...
 
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...
 
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 definition of the interface mapper utilities.

Author
Alexandru Mereacre
Date
2022

Macro Definition Documentation

◆ LINK_TYPE_LEN

#define LINK_TYPE_LEN   64

Typedef Documentation

◆ config_ifinfo_t

Interface configuration info structure.

◆ hmap_if_conn

typedef struct hashmap_if_conn hmap_if_conn

Subnet to interface connection mapper.

◆ hmap_vlan_conn

VLAN to interface connection mapper.

Enumeration Type Documentation

◆ IF_STATE

enum IF_STATE
Enumerator
IF_STATE_UNKNOWN 
IF_STATE_NOTPRESENT 
IF_STATE_DOWN 
IF_STATE_LOWERLAYERDOWN 
IF_STATE_TESTING 
IF_STATE_DORMANT 
IF_STATE_UP 
IF_STATE_OTHER 

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

◆ 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