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

File containing the implementation of the netlink 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 <linux/netlink.h>
#include <linux/nl80211.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <netlink/attr.h>
#include <netlink/genl/ctrl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/genl.h>
#include <netlink/msg.h>
#include "libnetlink.h"
#include "ll_map.h"
#include "rt_names.h"
#include "utils.h"
#include "linux/if_addr.h"
#include "linux/if_infiniband.h"
#include "allocs.h"
#include "iface_mapper.h"
#include "ifaceu.h"
#include "log.h"
#include "net.h"
#include "nl.h"
#include "os.h"
Include dependency graph for nl.c:

Functions

void free_nlmsg_chain (struct nlmsg_chain *info)
 
int ip_link_list (req_filter_fn_t filter_fn, struct nlmsg_chain *linfo)
 
enum IF_STATE get_operstate (__u8 state)
 
int get_addrinfo (struct nlmsghdr *n, netif_info_t *info)
 
int get_linkinfo (struct nlmsghdr *n, netif_info_t *info)
 
int iplink_parse (int argc, const char *const *argv, struct iplink_req *req, const char **type)
 
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...
 
struct nlctxnl_init_context (void)
 Initialises the nl context. More...
 
void nl_free_context (struct nlctx *context)
 Frees the nl context. 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...
 

Variables

struct rtnl_handle rth = {.fd = -1}
 

Detailed Description

File containing the implementation of the netlink utilities.

Author
Alexandru Mereacre
Date
2022

Function Documentation

◆ free_nlmsg_chain()

void free_nlmsg_chain ( struct nlmsg_chain *  info)

◆ get_addrinfo()

int get_addrinfo ( struct nlmsghdr *  n,
netif_info_t info 
)

◆ get_linkinfo()

int get_linkinfo ( struct nlmsghdr *  n,
netif_info_t info 
)

◆ 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

◆ get_operstate()

enum IF_STATE get_operstate ( __u8  state)

◆ ip_link_list()

int ip_link_list ( req_filter_fn_t  filter_fn,
struct nlmsg_chain *  linfo 
)

◆ iplink_parse()

int iplink_parse ( int  argc,
const char *const *  argv,
struct iplink_req req,
const char **  type 
)

◆ 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

Variable Documentation

◆ rth

struct rtnl_handle rth = {.fd = -1}