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

File containing the definition of the netlink utilities. More...

#include <stdbool.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <netinet/if_ether.h>
#include <utarray.h>
#include "linux/rtnetlink.h"
Include dependency graph for nl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  nlctx
 
struct  nl80211_state
 
struct  netiw_info_t
 Network wireless interface information structure. More...
 
struct  iplink_req
 

Macros

#define NL_CB_TYPE   NL_CB_DEFAULT
 

Functions

struct nlctxnl_init_context (void)
 Initialises the nl context. More...
 
void nl_free_context (struct nlctx *context)
 Frees the nl context. More...
 
UT_array * nl_get_interfaces (int if_id)
 Get the array of struct netif_info_t for each available interface. More...
 
int nl_new_interface (const char *if_name, const char *type)
 Creates a new interface object. More...
 
int nl_set_interface_ip (const struct nlctx *context, const char *ifname, const char *ip_addr, const char *brd_addr, const char *subnet_mask)
 Set the interface IP. More...
 
int nl_set_interface_state (const char *if_name, bool state)
 Set the interface state. More...
 
int nl_create_interface (const struct nlctx *context, 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 nl_reset_interface (const char *ifname)
 Resets the interface. More...
 
int iwace_isvlan (uint32_t wiphy)
 Check if wireless physical interface has VLAN capability. More...
 
UT_array * get_netiw_info (void)
 Get the array of all wireless physical interfaces. More...
 
int nl_is_iw_vlan (const char *ifname)
 Check if interface has the VLAN capability. More...
 
char * nl_get_valid_iw (char buf[static IF_NAMESIZE])
 Returns an exisiting WiFi interface name that supports VLAN. More...
 

Detailed Description

File containing the definition of the netlink utilities.

Author
Alexandru Mereacre
Date
2022

Macro Definition Documentation

◆ NL_CB_TYPE

#define NL_CB_TYPE   NL_CB_DEFAULT

Function Documentation

◆ get_netiw_info()

UT_array* get_netiw_info ( void  )

Get the array of all wireless physical interfaces.

Returns
UT_array* The array of wireless physical interfaces

◆ iwace_isvlan()

int iwace_isvlan ( uint32_t  wiphy)

Check if wireless physical interface has VLAN capability.

Parameters
wiphyWireless physical interface ID
Returns
1 if capability present, 0 otherwise, -1 on error

◆ nl_create_interface()

int nl_create_interface ( const struct nlctx context,
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 nl context interface
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

◆ nl_free_context()

void nl_free_context ( struct nlctx context)

Frees the nl context.

Parameters
contextThe nl context created by nl_init_context()

◆ nl_get_interfaces()

UT_array* nl_get_interfaces ( int  if_id)

Get the array of struct netif_info_t for each available interface.

Parameters
if_idThe intreface id, if 0 return all interfaces
Returns
UT_array* The returned array of struct netif_info_t. You must utarray_free() this array when done.

◆ nl_get_valid_iw()

char* nl_get_valid_iw ( char  buf[static IF_NAMESIZE])

Returns an exisiting WiFi interface name that supports VLAN.

Parameters
[out]bufInterface working buffer of at least IF_NAMESIZE bytes.
Returns
WiFi interface name (pointer to buf param)

◆ nl_init_context()

struct nlctx* nl_init_context ( void  )

Initialises the nl context.

Returns
The nl context, or NULL on error (e.g. memory allocation failure). You must nl_free_context() this object when done with it.

◆ nl_is_iw_vlan()

int nl_is_iw_vlan ( const char *  ifname)

Check if interface has the VLAN capability.

Parameters
ifnameInterface name string
Returns
int 0 if VLAN capable, -1 on error and 1 if not VLAN capable

◆ nl_new_interface()

int nl_new_interface ( const char *  if_name,
const char *  type 
)

Creates a new interface object.

Parameters
if_nameThe interface string name
typeThe interface string type (ex. "bridge")
Returns
0 on success, -1 otherwise

◆ nl_reset_interface()

int nl_reset_interface ( const char *  ifname)

Resets the interface.

Parameters
ifnameThe interface name string
Returns
0 on success, -1 otherwise

◆ nl_set_interface_ip()

int nl_set_interface_ip ( const struct nlctx context,
const char *  ifname,
const char *  ip_addr,
const char *  brd_addr,
const char *  subnet_mask 
)

Set the interface IP.

Parameters
contextThe nl context
ifnameThe interface name string
ip_addrThe IP address string
brd_addrThe broadcast IP address string
subnet_maskThe subnet mask (e.g. 24 for /24)
Returns
0 on success, -1 otherwise

◆ nl_set_interface_state()

int nl_set_interface_state ( const char *  if_name,
bool  state 
)

Set the interface state.

Parameters
if_nameThe interface name string
stateThe interface state value (true - "up", false - "down")
Returns
0 on success, -1 otherwise