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

File containing the implementation of the network interface 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 <sys/socket.h>
#include <ifaddrs.h>
#include <netdb.h>
#include "allocs.h"
#include "iface.h"
#include "iface_mapper.h"
#include "ifaceu.h"
#include "log.h"
#include "net.h"
#include "os.h"
Include dependency graph for iface.c:

Macros

#define _GNU_SOURCE   /* To get defns of NI_MAXSERV and NI_MAXHOST */
 

Functions

void iface_free_context (struct iface_context *ctx)
 Initialises the interface context. More...
 
struct iface_contextiface_init_context (void *params)
 Initialises the interface context. More...
 
UT_array * iface_get (const char *ifname)
 Get the array of struct netif_info_t for each available interface. More...
 
UT_array * iface_get_ip4 (const struct iface_context *ctx, const char *brname, const char *ifname)
 Get the IP4 addresses for a given interface. More...
 
char * iface_get_vlan (char if_buf[static IF_NAMESIZE])
 Returns an exisiting WiFi interface name that supports VLAN. More...
 
int reset_interface (const struct iface_context *ctx, const char *ifname)
 Resets an interface. More...
 
int iface_create (const struct iface_context *ctx, const char *brname, const char *ifname, const char *type, const char *ip_addr, const char *brd_addr, const char *subnet_mask)
 Creates and interface and assigns an IP. More...
 
int iface_set_ip4 (const struct iface_context *ctx, const char *brname, const char *ifname, const char *ip_addr, const char *brd_addr, const char *subnet_mask)
 Sets the IP4 for a given interface. More...
 
int iface_commit (const struct iface_context *ctx)
 Commits the interface changes. More...
 

Detailed Description

File containing the implementation of the network interface utilities.

Author
Alexandru Mereacre
Date
2020

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   /* To get defns of NI_MAXSERV and NI_MAXHOST */

Function Documentation

◆ iface_commit()

int iface_commit ( const struct iface_context context)

Commits the interface changes.

Parameters
contextThe interface context
Returns
int 0 on success, -1 on failure

◆ iface_create()

int iface_create ( const struct iface_context context,
const char *  brname,
const char *  ifname,
const char *  type,
const char *  ip_addr,
const char *  brd_addr,
const char *  subnet_mask 
)

Creates and interface and assigns an IP.

Parameters
contextThe interface context
brnameThe bridge name
ifnameThe interface name
typeThe interface type
ip_addrThe interface IP4 address
brd_addrThe interface IP4 broadcast address
subnet_maskThe interface IP4 subnet mask
Returns
int 0 on success, -1 on failure

◆ iface_free_context()

void iface_free_context ( struct iface_context context)

Initialises the interface context.

Parameters
contextThe interface context

◆ iface_get()

UT_array* iface_get ( const char *  ifname)

Get the array of struct netif_info_t for each available interface.

Parameters
[in]ifnameThe interface name, if NULL return all interfaces
Returns
UT_array* The returned array of struct netif_info_t. Must be freed with utarray_free() when done.

◆ iface_get_ip4()

UT_array* iface_get_ip4 ( const struct iface_context context,
const char *  brname,
const char *  ifname 
)

Get the IP4 addresses for a given interface.

Parameters
contextThe interface context
[in]brnameThe bridge name
[in]ifnameThe interface name
Returns
UT_array* The returned array of IP4 strings. Must be freed with utarray_free() when done.

◆ iface_get_vlan()

char* iface_get_vlan ( char  if_buf[static IF_NAMESIZE])

Returns an exisiting WiFi interface name that supports VLAN.

Parameters
[out]if_bufInterface working buffer of at least size IF_NAMESIZE.
Returns
WiFi interface name (pointer to if_buf param), or NULL on error.

◆ iface_init_context()

struct iface_context* iface_init_context ( void *  params)

Initialises the interface context.

Parameters
paramsThe parameters for interface context
Returns
The interface context. Must be freed by iface_free_context().

◆ iface_set_ip4()

int iface_set_ip4 ( const struct iface_context context,
const char *  brname,
const char *  ifname,
const char *  ip_addr,
const char *  brd_addr,
const char *  subnet_mask 
)

Sets the IP4 for a given interface.

Parameters
contextThe interface context
brnameThe bridge name
ifnameThe interface name
ip_addrThe interface IP4 address
brd_addrThe interface IP4 broadcast address
subnet_maskThe interface IP4 subnet mask
Returns
int 0 on success, -1 on failure

◆ reset_interface()

int reset_interface ( const struct iface_context context,
const char *  ifname 
)

Resets an interface.

Parameters
contextThe interface context
ifnameThe interface name
Returns
int 0 on success, -1 on failure