OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::TunNetlink::SITNL Class Reference

#include <sitnl.hpp>

Classes

struct  iface_addr_res_t
 
struct  route_res_t
 
struct  sitnl_addr_req
 
struct  sitnl_link_req
 
struct  sitnl_route_req
 

Static Public Member Functions

static int net_route_best_gw (const IP::Route6 &route, IPv6::Addr &best_gw6, std::string &best_iface, const std::string &iface_to_ignore="")
 
static int net_route_best_gw (const IP::Route4 &route, IPv4::Addr &best_gw4, std::string &best_iface, const std::string &iface_to_ignore="")
 
static IP::Route net_iface_addr (const std::string &iface, const int family)
 Get interface address/netmask.
 
static int net_iface_new (const std::string &iface, const std::string &type)
 Add new interface (similar to ip link add)
 
static int net_iface_del (const std::string &iface)
 
static int net_iface_up (std::string &iface, bool up)
 
static int net_iface_mtu_set (std::string &iface, uint32_t mtu)
 
static int net_addr_add (const std::string &iface, const IPv4::Addr &addr, const unsigned char prefixlen, const IPv4::Addr &broadcast)
 
static int net_addr_add (const std::string &iface, const IPv6::Addr &addr, const unsigned char prefixlen)
 
static int net_addr_del (const std::string &iface, const IPv4::Addr &addr, const unsigned char prefixlen)
 
static int net_addr_del (const std::string &iface, const IPv6::Addr &addr, const unsigned char prefixlen)
 
static int net_addr_ptp_add (const std::string &iface, const IPv4::Addr &local, const IPv4::Addr &remote)
 
static int net_addr_ptp_del (const std::string &iface, const IPv4::Addr &local, const IPv4::Addr &remote)
 
static int net_route_add (const IP::Route4 &route, const IPv4::Addr &gw, const std::string &iface, const uint32_t table, const int metric)
 
static int net_route_add (const IP::Route6 &route, const IPv6::Addr &gw, const std::string &iface, const uint32_t table, const int metric)
 
static int net_route_del (const IP::Route4 &route, const IPv4::Addr &gw, const std::string &iface, const uint32_t table, const int metric)
 
static int net_route_del (const IP::Route6 &route, const IPv6::Addr &gw, const std::string &iface, const uint32_t table, const int metric)
 

Private Types

typedef int(* sitnl_parse_reply_cb) (struct nlmsghdr *msg, void *arg)
 

Static Private Member Functions

static int sitnl_addattr (struct nlmsghdr *n, int maxlen, uint16_t type, const void *data, uint16_t alen)
 
static int sitnl_socket (void)
 
static int sitnl_bind (int fd, uint32_t groups)
 
static int sitnl_send (struct nlmsghdr *payload, pid_t peer, unsigned int groups, sitnl_parse_reply_cb cb, void *arg_cb)
 
static int sitnl_route_save (struct nlmsghdr *n, void *arg)
 
static int sitnl_route_best_gw (const std::string &iface_to_ignore, const IP::Route &route, IP::Addr &best_gw, std::string &best_iface)
 
static int sitnl_iface_addr_save (struct nlmsghdr *n, void *arg)
 
static int sitnl_iface_addr (const int ifindex, const int family, IP::Route &route)
 
static int sitnl_addr_set (const unsigned short cmd, const unsigned short flags, const std::string &iface, const IP::Addr &local, const IP::Addr &remote, unsigned char prefixlen, const IP::Addr &broadcast)
 
static int sitnl_addr_ptp_add (const std::string &iface, const IP::Addr &local, const IP::Addr &remote)
 
static int sitnl_addr_ptp_del (const std::string &iface, const IP::Addr &local)
 
static int sitnl_route_set (const unsigned short cmd, const unsigned short flags, const std::string &iface, const IP::Route &route, const IP::Addr &gw, const enum rt_class_t table, const int metric, const enum rt_scope_t scope, const unsigned char protocol, const unsigned char type)
 
static int sitnl_addr_add (const std::string &iface, const IP::Addr &addr, unsigned char prefixlen, const IP::Addr &broadcast)
 
static int sitnl_addr_del (const std::string &iface, const IP::Addr &addr, unsigned char prefixlen)
 
static int sitnl_route_add (const IP::Route &route, const IP::Addr &gw, const std::string &iface, const uint32_t table, const int metric)
 
static int sitnl_route_del (const IP::Route &route, const IP::Addr &gw, const std::string &iface, const uint32_t table, const int metric)
 

Detailed Description

Definition at line 56 of file sitnl.hpp.

Member Typedef Documentation

◆ sitnl_parse_reply_cb

typedef int(* openvpn::TunNetlink::SITNL::sitnl_parse_reply_cb) (struct nlmsghdr *msg, void *arg)
private

Definition at line 89 of file sitnl.hpp.

Member Function Documentation

◆ net_addr_add() [1/2]

static int openvpn::TunNetlink::SITNL::net_addr_add ( const std::string &  iface,
const IPv4::Addr addr,
const unsigned char  prefixlen,
const IPv4::Addr broadcast 
)
inlinestatic

Definition at line 1215 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_addr_add() [2/2]

static int openvpn::TunNetlink::SITNL::net_addr_add ( const std::string &  iface,
const IPv6::Addr addr,
const unsigned char  prefixlen 
)
inlinestatic

Definition at line 1231 of file sitnl.hpp.

◆ net_addr_del() [1/2]

static int openvpn::TunNetlink::SITNL::net_addr_del ( const std::string &  iface,
const IPv4::Addr addr,
const unsigned char  prefixlen 
)
inlinestatic

Definition at line 1245 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_addr_del() [2/2]

static int openvpn::TunNetlink::SITNL::net_addr_del ( const std::string &  iface,
const IPv6::Addr addr,
const unsigned char  prefixlen 
)
inlinestatic

Definition at line 1258 of file sitnl.hpp.

◆ net_addr_ptp_add()

static int openvpn::TunNetlink::SITNL::net_addr_ptp_add ( const std::string &  iface,
const IPv4::Addr local,
const IPv4::Addr remote 
)
inlinestatic

Definition at line 1271 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_addr_ptp_del()

static int openvpn::TunNetlink::SITNL::net_addr_ptp_del ( const std::string &  iface,
const IPv4::Addr local,
const IPv4::Addr remote 
)
inlinestatic

Definition at line 1285 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_iface_addr()

static IP::Route openvpn::TunNetlink::SITNL::net_iface_addr ( const std::string &  iface,
const int  family 
)
inlinestatic

Get interface address/netmask.

Parameters
ifaceinterface to probe
familyaddress family
Returns
interface primary address/subnet or undefined route if error

Definition at line 1047 of file sitnl.hpp.

◆ net_iface_del()

static int openvpn::TunNetlink::SITNL::net_iface_del ( const std::string &  iface)
inlinestatic

Definition at line 1108 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_iface_mtu_set()

static int openvpn::TunNetlink::SITNL::net_iface_mtu_set ( std::string &  iface,
uint32_t  mtu 
)
inlinestatic

Definition at line 1181 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_iface_new()

static int openvpn::TunNetlink::SITNL::net_iface_new ( const std::string &  iface,
const std::string &  type 
)
inlinestatic

Add new interface (similar to ip link add)

Parameters
ifaceinterface name
typeinterface link type (for example "ovpn-dco")
Returns
int 0 on success, negative error code on error

Definition at line 1069 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_iface_up()

static int openvpn::TunNetlink::SITNL::net_iface_up ( std::string &  iface,
bool  up 
)
inlinestatic

Definition at line 1140 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_route_add() [1/2]

static int openvpn::TunNetlink::SITNL::net_route_add ( const IP::Route4 route,
const IPv4::Addr gw,
const std::string &  iface,
const uint32_t  table,
const int  metric 
)
inlinestatic

Definition at line 1297 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_route_add() [2/2]

static int openvpn::TunNetlink::SITNL::net_route_add ( const IP::Route6 route,
const IPv6::Addr gw,
const std::string &  iface,
const uint32_t  table,
const int  metric 
)
inlinestatic

Definition at line 1317 of file sitnl.hpp.

◆ net_route_best_gw() [1/2]

static int openvpn::TunNetlink::SITNL::net_route_best_gw ( const IP::Route4 route,
IPv4::Addr best_gw4,
std::string &  best_iface,
const std::string &  iface_to_ignore = "" 
)
inlinestatic

Definition at line 1018 of file sitnl.hpp.

◆ net_route_best_gw() [2/2]

static int openvpn::TunNetlink::SITNL::net_route_best_gw ( const IP::Route6 route,
IPv6::Addr best_gw6,
std::string &  best_iface,
const std::string &  iface_to_ignore = "" 
)
inlinestatic

Definition at line 996 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_route_del() [1/2]

static int openvpn::TunNetlink::SITNL::net_route_del ( const IP::Route4 route,
const IPv4::Addr gw,
const std::string &  iface,
const uint32_t  table,
const int  metric 
)
inlinestatic

Definition at line 1337 of file sitnl.hpp.

Here is the caller graph for this function:

◆ net_route_del() [2/2]

static int openvpn::TunNetlink::SITNL::net_route_del ( const IP::Route6 route,
const IPv6::Addr gw,
const std::string &  iface,
const uint32_t  table,
const int  metric 
)
inlinestatic

Definition at line 1354 of file sitnl.hpp.

◆ sitnl_addattr()

static int openvpn::TunNetlink::SITNL::sitnl_addattr ( struct nlmsghdr *  n,
int  maxlen,
uint16_t  type,
const void *  data,
uint16_t  alen 
)
inlinestaticprivate

Helper function used to easily add attributes to a rtnl message

Definition at line 95 of file sitnl.hpp.

◆ sitnl_addr_add()

static int openvpn::TunNetlink::SITNL::sitnl_addr_add ( const std::string &  iface,
const IP::Addr addr,
unsigned char  prefixlen,
const IP::Addr broadcast 
)
inlinestaticprivate

Definition at line 930 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_addr_del()

static int openvpn::TunNetlink::SITNL::sitnl_addr_del ( const std::string &  iface,
const IP::Addr addr,
unsigned char  prefixlen 
)
inlinestaticprivate

Definition at line 945 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_addr_ptp_add()

static int openvpn::TunNetlink::SITNL::sitnl_addr_ptp_add ( const std::string &  iface,
const IP::Addr local,
const IP::Addr remote 
)
inlinestaticprivate

Definition at line 820 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_addr_ptp_del()

static int openvpn::TunNetlink::SITNL::sitnl_addr_ptp_del ( const std::string &  iface,
const IP::Addr local 
)
inlinestaticprivate

Definition at line 834 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_addr_set()

static int openvpn::TunNetlink::SITNL::sitnl_addr_set ( const unsigned short  cmd,
const unsigned short  flags,
const std::string &  iface,
const IP::Addr local,
const IP::Addr remote,
unsigned char  prefixlen,
const IP::Addr broadcast 
)
inlinestaticprivate

Definition at line 736 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_bind()

static int openvpn::TunNetlink::SITNL::sitnl_bind ( int  fd,
uint32_t  groups 
)
inlinestaticprivate

Bind socket to Netlink subsystem

Definition at line 162 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_iface_addr()

static int openvpn::TunNetlink::SITNL::sitnl_iface_addr ( const int  ifindex,
const int  family,
IP::Route route 
)
inlinestaticprivate

Return interface primary address/netmask given interface index.

Parameters
ifindexinterface to probe
familyaddress family
[out]routeaddress/netmask of interface
Returns
success if 0, error if < 0

Definition at line 700 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_iface_addr_save()

static int openvpn::TunNetlink::SITNL::sitnl_iface_addr_save ( struct nlmsghdr *  n,
void *  arg 
)
inlinestaticprivate

Definition at line 637 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_route_add()

static int openvpn::TunNetlink::SITNL::sitnl_route_add ( const IP::Route route,
const IP::Addr gw,
const std::string &  iface,
const uint32_t  table,
const int  metric 
)
inlinestaticprivate

Definition at line 957 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_route_best_gw()

static int openvpn::TunNetlink::SITNL::sitnl_route_best_gw ( const std::string &  iface_to_ignore,
const IP::Route route,
IP::Addr best_gw,
std::string &  best_iface 
)
inlinestaticprivate

Searches for best gateway for a given route

Parameters
iface_to_ignorethis allows to exclude certain interface from discovered gateways. Used when we want to exclude VPN interface when there is active VPN connection with redirected default gateway
routeroute for which we search gw
[out]best_gwfound gw
[out]best_ifacenetwork interface on which gw was found
Returns

Definition at line 569 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_route_del()

static int openvpn::TunNetlink::SITNL::sitnl_route_del ( const IP::Route route,
const IP::Addr gw,
const std::string &  iface,
const uint32_t  table,
const int  metric 
)
inlinestaticprivate

Definition at line 976 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_route_save()

static int openvpn::TunNetlink::SITNL::sitnl_route_save ( struct nlmsghdr *  n,
void *  arg 
)
inlinestaticprivate

Definition at line 422 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_route_set()

static int openvpn::TunNetlink::SITNL::sitnl_route_set ( const unsigned short  cmd,
const unsigned short  flags,
const std::string &  iface,
const IP::Route route,
const IP::Addr gw,
const enum rt_class_t  table,
const int  metric,
const enum rt_scope_t  scope,
const unsigned char  protocol,
const unsigned char  type 
)
inlinestaticprivate

Definition at line 846 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_send()

static int openvpn::TunNetlink::SITNL::sitnl_send ( struct nlmsghdr *  payload,
pid_t  peer,
unsigned int  groups,
sitnl_parse_reply_cb  cb,
void *  arg_cb 
)
inlinestaticprivate

Send Netlink message and run callback on reply (if specified)

If cb is not set, will request an ack message with NLM_F_ACK. Will return the value of error attribute of the ack message unless any other error occured during send or receive. Only NLMSG_ERROR and NLMSG_DONE messages are expected and handled without a callback function.

If any other messages will be returned, a callback should be used. The callback will called on every message header except NLMSG_DONE (which ends the processing immediately). NLMSG_ERROR message is treated special in that if the callback returns a negative result on a NLMSG_ERROR message, the processing ends and that result is returned immediately. Otherwise, the function returns the return value of the callback called on the last message before NLMSG_DONE.

Parameters
payloadnlmsghdr to embed into a nlmsg and send
peernladdr.nl_pid to use, can be 0
groupsnladdr.nl_groups to use, can be 0
cbcallback to call on returned nlmsghdrs, can be NULL
arg_cbdata argument for cb, can be NULL
Returns
If any error occurs, negative errno. If cb is set, return value of last cb call, if not then value of error attribute in NLMSG_ERROR.

Definition at line 222 of file sitnl.hpp.

Here is the caller graph for this function:

◆ sitnl_socket()

static int openvpn::TunNetlink::SITNL::sitnl_socket ( void  )
inlinestaticprivate

Open RTNL socket

Definition at line 128 of file sitnl.hpp.

Here is the caller graph for this function:

The documentation for this class was generated from the following file: