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"
Go to the source code of this file.
|
struct nlctx * | nl_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...
|
|
File containing the definition of the netlink utilities.
- Author
- Alexandru Mereacre
- Date
- 2022
- Copyright
- SPDX-FileCopyrightText: © 2022 NQMCyber Ltd and edgesec contributors SPDX-License-Identifier: LGPL-3.0-or-later
◆ NL_CB_TYPE
#define NL_CB_TYPE NL_CB_DEFAULT |
◆ 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
-
wiphy | Wireless 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
-
context | The nl context interface |
ifname | The interface name |
type | The interface type |
ip_addr | The interface IP4 address |
brd_addr | The interface IP4 broadcast address |
subnet_mask | The 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
-
◆ 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_id | The 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] | buf | Interface 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
-
ifname | Interface 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_name | The interface string name |
type | The 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
-
ifname | The 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
-
context | The nl context |
ifname | The interface name string |
ip_addr | The IP address string |
brd_addr | The broadcast IP address string |
subnet_mask | The 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_name | The interface name string |
state | The interface state value (true - "up", false - "down") |
- Returns
- 0 on success, -1 otherwise