EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
iface_mapper.h
Go to the documentation of this file.
1 
11 #ifndef IFACE_MAPPER_H_
12 #define IFACE_MAPPER_H_
13 
14 #include <stdbool.h>
15 #include <netinet/in.h>
16 #include <inttypes.h>
17 #include <net/ethernet.h>
18 #include <net/if.h>
19 #include <pthread.h>
20 
21 #include <utarray.h>
22 #include <uthash.h>
23 #include "allocs.h"
24 #include "net.h"
25 #include "os.h"
26 
27 #define LINK_TYPE_LEN 64
28 
29 enum IF_STATE {
38 };
39 
44 typedef struct {
45  char ifname[IF_NAMESIZE];
46  uint32_t ifindex;
47  enum IF_STATE state;
48  char link_type[LINK_TYPE_LEN];
49  uint8_t ifa_family;
50  char ip_addr[OS_INET_ADDRSTRLEN];
51  char ip_addr6[OS_INET6_ADDRSTRLEN];
52  char peer_addr[OS_INET_ADDRSTRLEN];
53  char brd_addr[OS_INET_ADDRSTRLEN];
55  uint8_t mac_addr[ETHER_ADDR_LEN];
56 } netif_info_t;
57 
62 typedef struct config_ifinfo_t {
63  int vlanid;
64  char ifname[IF_NAMESIZE];
65  char brname[IF_NAMESIZE];
71 
76 typedef struct hashmap_if_conn {
77  in_addr_t key;
78  char value[IF_NAMESIZE];
79  UT_hash_handle hh;
81 
86 struct vlan_conn {
87  int vlanid;
88  char ifname[IF_NAMESIZE];
89  pthread_t capture_pid;
90 };
91 
96 typedef struct hashmap_vlan_conn {
97  int key;
98  struct vlan_conn value;
99  UT_hash_handle hh;
101 
111 int get_if_mapper(hmap_if_conn *const *hmap, in_addr_t subnet,
112  char ifname[static IF_NAMESIZE]);
113 
123 bool put_if_mapper(hmap_if_conn **hmap, in_addr_t subnet, const char *ifname);
124 
130 void free_if_mapper(hmap_if_conn **hmap);
131 
140 int get_vlan_mapper(hmap_vlan_conn *const *hmap, int vlanid,
141  struct vlan_conn *conn);
142 
150 int copy_vlan_mapper(hmap_vlan_conn *const *hmap, hmap_vlan_conn **copy);
151 
160 bool put_vlan_mapper(hmap_vlan_conn **hmap, const struct vlan_conn *conn);
161 
167 void free_vlan_mapper(hmap_vlan_conn **hmap);
168 
178 int get_ifname_from_ip(const UT_array *config_ifinfo_array, const char *ip,
179  char ifname[static IF_NAMESIZE]);
180 
190 int get_brname_from_ip(const UT_array *config_ifinfo_array, const char *ip_addr,
191  char brname[static IF_NAMESIZE]);
192 
200 bool create_if_mapper(const UT_array *config_ifinfo_array, hmap_if_conn **hmap);
201 
209 int create_vlan_mapper(const UT_array *config_ifinfo_array,
210  hmap_vlan_conn **hmap);
211 
220 int init_ifbridge_names(UT_array *config_ifinfo_array, const char *ifname,
221  const char *brname);
222 #endif
File containing the definition of the allocs functionalities.
#define LINK_TYPE_LEN
Definition: iface_mapper.h:27
int copy_vlan_mapper(hmap_vlan_conn *const *hmap, hmap_vlan_conn **copy)
Makes a copy of the VLAn mapper structure.
Definition: iface_mapper.c:120
void free_vlan_mapper(hmap_vlan_conn **hmap)
Frees the VLAN ID to interface connection mapper object.
Definition: iface_mapper.c:171
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.
Definition: iface_mapper.c:29
struct hashmap_if_conn hmap_if_conn
Subnet to interface connection mapper.
IF_STATE
Definition: iface_mapper.h:29
@ IF_STATE_LOWERLAYERDOWN
Definition: iface_mapper.h:33
@ IF_STATE_DOWN
Definition: iface_mapper.h:32
@ IF_STATE_NOTPRESENT
Definition: iface_mapper.h:31
@ IF_STATE_OTHER
Definition: iface_mapper.h:37
@ IF_STATE_TESTING
Definition: iface_mapper.h:34
@ IF_STATE_DORMANT
Definition: iface_mapper.h:35
@ IF_STATE_UNKNOWN
Definition: iface_mapper.h:30
@ IF_STATE_UP
Definition: iface_mapper.h:36
bool create_if_mapper(const UT_array *config_ifinfo_array, hmap_if_conn **hmap)
Create the subnet to interface mapper.
Definition: iface_mapper.c:263
void free_if_mapper(hmap_if_conn **hmap)
Frees the interface connection mapper object.
Definition: iface_mapper.c:90
int init_ifbridge_names(UT_array *config_ifinfo_array, const char *ifname, const char *brname)
Initialise the interface names.
Definition: iface_mapper.c:310
struct hashmap_vlan_conn hmap_vlan_conn
VLAN to interface connection 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.
Definition: iface_mapper.c:54
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.
Definition: iface_mapper.c:99
int create_vlan_mapper(const UT_array *config_ifinfo_array, hmap_vlan_conn **hmap)
Create the VLAN ID to interface mapper.
Definition: iface_mapper.c:288
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.
Definition: iface_mapper.c:205
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.
Definition: iface_mapper.c:133
struct config_ifinfo_t config_ifinfo_t
Interface configuration info structure.
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.
Definition: iface_mapper.c:234
File containing the definition of the network utilities.
#define OS_INET_ADDRSTRLEN
Definition: net.h:25
#define OS_INET6_ADDRSTRLEN
Definition: net.h:26
File containing the definition of the os functionalities.
Interface configuration info structure.
Definition: iface_mapper.h:62
int vlanid
Definition: iface_mapper.h:63
char brd_addr[OS_INET_ADDRSTRLEN]
Definition: iface_mapper.h:67
char ip_addr[OS_INET_ADDRSTRLEN]
Definition: iface_mapper.h:66
char brname[IF_NAMESIZE]
Definition: iface_mapper.h:65
char subnet_mask[OS_INET_ADDRSTRLEN]
Definition: iface_mapper.h:69
char ifname[IF_NAMESIZE]
Definition: iface_mapper.h:64
Subnet to interface connection mapper.
Definition: iface_mapper.h:76
char value[IF_NAMESIZE]
Definition: iface_mapper.h:78
UT_hash_handle hh
Definition: iface_mapper.h:79
in_addr_t key
Definition: iface_mapper.h:77
VLAN to interface connection mapper.
Definition: iface_mapper.h:96
UT_hash_handle hh
Definition: iface_mapper.h:99
struct vlan_conn value
Definition: iface_mapper.h:98
int key
Definition: iface_mapper.h:97
Network interface definition structure.
Definition: iface_mapper.h:44
uint32_t ifindex
Definition: iface_mapper.h:46
uint8_t ifa_family
Definition: iface_mapper.h:49
MAC connection structure.
Definition: iface_mapper.h:86
int vlanid
Definition: iface_mapper.h:87
pthread_t capture_pid
Definition: iface_mapper.h:89
char ifname[IF_NAMESIZE]
Definition: iface_mapper.h:88