OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::GeNL< ReadHandler > Class Template Reference

#include <genl.hpp>

Inheritance diagram for openvpn::GeNL< ReadHandler >:
[legend]
Collaboration diagram for openvpn::GeNL< ReadHandler >:
[legend]

Classes

struct  mcast_handler_args
 

Public Types

typedef RCPtr< GeNLPtr
 
- Public Types inherited from openvpn::RC< thread_unsafe_refcount >
typedef RCPtr< RCPtr
 

Public Member Functions

 GeNL (openvpn_io::io_context &io_context, unsigned int ifindex_arg, ReadHandler read_handler_arg)
 
void new_peer (int peer_id, int fd, struct sockaddr *sa, socklen_t salen, IPv4::Addr vpn4, IPv6::Addr vpn6)
 
void new_key (unsigned int key_slot, const KoRekey::KeyConfig *kc)
 
void swap_keys (int peer_id)
 
void del_key (int peer_id, unsigned int key_slot)
 
void set_peer (int peer_id, unsigned int keepalive_interval, unsigned int keepalive_timeout)
 
void del_peer (int peer_id)
 
void get_peer (int peer_id, bool sync)
 
void stop ()
 
- Public Member Functions inherited from openvpn::RC< thread_unsafe_refcount >
 RC () noexcept=default
 
 RC (const RC &)=delete
 
virtual ~RC ()=default
 
RCoperator= (const RC &)=delete
 
olong use_count () const noexcept
 Delegates call to RCImpl and returns the result.
 

Static Public Member Functions

static bool available ()
 
- Static Public Member Functions inherited from openvpn::RC< thread_unsafe_refcount >
static constexpr bool is_thread_safe ()
 Delegates call to RCImpl and returns the result.
 

Private Types

typedef std::unique_ptr< nl_msg, decltype(&nlmsg_free)> NlMsgPtr
 
typedef std::unique_ptr< nl_sock, decltype(&nl_socket_free)> NlSockPtr
 
typedef std::unique_ptr< nl_cb, decltype(&nl_cb_put)> NlCbPtr
 

Private Member Functions

 OPENVPN_EXCEPTION (netlink_error)
 
int get_mcast_id ()
 
void handle_read (const openvpn_io::error_code &error)
 
void queue_genl_read ()
 
NlMsgPtr create_msg (enum ovpn_nl_commands cmd)
 
void read_netlink_message ()
 
void reset_buffer ()
 
void send_netlink_message (struct nl_msg *msg)
 

Static Private Member Functions

static int mcast_family_handler (struct nl_msg *msg, void *arg)
 
static int message_received (struct nl_msg *msg, void *arg)
 
static int ovpn_nl_cb_error (struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg)
 

Private Attributes

NlSockPtr sock_ptr
 
NlCbPtr cb_ptr
 
struct nl_sock * sock
 
struct nl_cb * cb
 
int ovpn_dco_id
 
unsigned int ifindex
 
ReadHandler read_handler
 
bool halt
 
BufferAllocated buf
 
std::unique_ptr< openvpn_io::posix::stream_descriptor > stream
 

Static Private Attributes

static int nl_status = 0
 

Detailed Description

template<typename ReadHandler>
class openvpn::GeNL< ReadHandler >

Implements asynchronous communication with ovpn-dco kernel module via generic netlink protocol.

Before using this class, caller should create ovpn-dco network device.

Template Parameters
ReadHandlerclass which implements tun_read_handler(BufferAllocated &buf) method.
buf has following layout:
  • first byte - command type ( OVPN_CMD_DEL_PEER or -1 for error)
  • following bytes - command-specific payload

Definition at line 77 of file genl.hpp.

Member Typedef Documentation

◆ NlCbPtr

template<typename ReadHandler >
typedef std::unique_ptr<nl_cb, decltype(&nl_cb_put)> openvpn::GeNL< ReadHandler >::NlCbPtr
private

Definition at line 83 of file genl.hpp.

◆ NlMsgPtr

template<typename ReadHandler >
typedef std::unique_ptr<nl_msg, decltype(&nlmsg_free)> openvpn::GeNL< ReadHandler >::NlMsgPtr
private

Definition at line 81 of file genl.hpp.

◆ NlSockPtr

template<typename ReadHandler >
typedef std::unique_ptr<nl_sock, decltype(&nl_socket_free)> openvpn::GeNL< ReadHandler >::NlSockPtr
private

Definition at line 82 of file genl.hpp.

◆ Ptr

template<typename ReadHandler >
typedef RCPtr<GeNL> openvpn::GeNL< ReadHandler >::Ptr

Definition at line 86 of file genl.hpp.

Constructor & Destructor Documentation

◆ GeNL()

template<typename ReadHandler >
openvpn::GeNL< ReadHandler >::GeNL ( openvpn_io::io_context &  io_context,
unsigned int  ifindex_arg,
ReadHandler  read_handler_arg 
)
inlineexplicit

Construct a new GeNL object

Parameters
io_contextreference to io_context
ifindex_argindex of ovpn-dco network device
read_handler_arginstance of ReadHandler
Exceptions
netlink_errorthrown if error occurs during initialization

Definition at line 112 of file genl.hpp.

Member Function Documentation

◆ available()

template<typename ReadHandler >
static bool openvpn::GeNL< ReadHandler >::available ( )
inlinestatic

Detect ovpn-dco kernel module

Returns
bool value indicating whether the module is loaded

Definition at line 93 of file genl.hpp.

◆ create_msg()

template<typename ReadHandler >
NlMsgPtr openvpn::GeNL< ReadHandler >::create_msg ( enum ovpn_nl_commands  cmd)
inlineprivate

Definition at line 593 of file genl.hpp.

Here is the caller graph for this function:

◆ del_key()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::del_key ( int  peer_id,
unsigned int  key_slot 
)
inline

Remove key from key slot.

Parameters
peer_idthe ID of the peer whose keys has to be deleted
key_slotOVPN_KEY_SLOT_PRIMARY or OVPN_KEY_SLOT_SECONDARY
Exceptions
netlink_errorthrown if error occurs during sending netlink message

Definition at line 306 of file genl.hpp.

◆ del_peer()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::del_peer ( int  peer_id)
inline

Delete an existing peer.

Parameters
peer_idthe ID of the peer to delete
Exceptions
netlink_errorthrown if error occurs during sending netlink message

Definition at line 363 of file genl.hpp.

◆ get_mcast_id()

template<typename ReadHandler >
int openvpn::GeNL< ReadHandler >::get_mcast_id ( )
inlineprivate

Return id of multicast group which ovpn-dco uses to broadcast OVPN_CMD_DEL_PEER message

Returns
int multicast group id

Definition at line 501 of file genl.hpp.

Here is the caller graph for this function:

◆ get_peer()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::get_peer ( int  peer_id,
bool  sync 
)
inline

Retrieve he current status of a peer.

Parameters
peer_idthe ID of the peer to query
syncWhen true the method waits for the reply before returning
Exceptions
netlink_errorthrown if error occurs during sending netlink message

Definition at line 389 of file genl.hpp.

◆ handle_read()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::handle_read ( const openvpn_io::error_code &  error)
inlineprivate

Definition at line 552 of file genl.hpp.

◆ mcast_family_handler()

template<typename ReadHandler >
static int openvpn::GeNL< ReadHandler >::mcast_family_handler ( struct nl_msg *  msg,
void *  arg 
)
inlinestaticprivate

This callback is called by libnl. Here we enumerate netlink multicast groups and find id of the one which name matches ovpn-dco multicast group.

Parameters
msgnetlink message to be processed
argarguments passed by nl_cb_set() call
Returns
int id of ovpn-dco multicast group

Definition at line 458 of file genl.hpp.

Here is the caller graph for this function:

◆ message_received()

template<typename ReadHandler >
static int openvpn::GeNL< ReadHandler >::message_received ( struct nl_msg *  msg,
void *  arg 
)
inlinestaticprivate

This is called inside libnl's nl_recvmsgs() call to process incoming netlink message.

Parameters
msgnetlink message to be processed
argargument passed by nl_cb_set()
Returns
int callback action

Definition at line 634 of file genl.hpp.

Here is the caller graph for this function:

◆ new_key()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::new_key ( unsigned int  key_slot,
const KoRekey::KeyConfig kc 
)
inline

Inject new key into kernel module

Parameters
key_slotOVPN_KEY_SLOT_PRIMARY or OVPN_KEY_SLOT_SECONDARY
kcpointer to KeyConfig struct which contains key data
Exceptions
netlink_errorthrown if error occurs during sending netlink message

Definition at line 220 of file genl.hpp.

◆ new_peer()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::new_peer ( int  peer_id,
int  fd,
struct sockaddr *  sa,
socklen_t  salen,
IPv4::Addr  vpn4,
IPv6::Addr  vpn6 
)
inline

Add peer information to kernel module

Parameters
peer_idPeer ID of the peer being created
fdsocket to be used to communicate with the peer
sasockaddr object representing the remote endpoint
salenlength of sa (either sizeof(sockaddr_in) or sizeof(sockaddr_in6)
vpn4IPv4 address associated with this peer in the tunnel
vpn6IPv6 address associated with this peer in the tunnel
Exceptions
netlink_errorthrown if error occurs during sending netlink message

Definition at line 178 of file genl.hpp.

◆ OPENVPN_EXCEPTION()

template<typename ReadHandler >
openvpn::GeNL< ReadHandler >::OPENVPN_EXCEPTION ( netlink_error  )
private

◆ ovpn_nl_cb_error()

template<typename ReadHandler >
static int openvpn::GeNL< ReadHandler >::ovpn_nl_cb_error ( struct sockaddr_nl *  nla,
struct nlmsgerr *  err,
void *  arg 
)
inlinestaticprivate

This is an error callback called by netlink for error message processing customization.

Parameters
nlanetlink address of the peer (value not needed here)
errnetlink error message being processed
argargument passed by nl_cb_err()
Returns
int callback action

Definition at line 762 of file genl.hpp.

Here is the caller graph for this function:

◆ queue_genl_read()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::queue_genl_read ( )
inlineprivate

Definition at line 584 of file genl.hpp.

Here is the caller graph for this function:

◆ read_netlink_message()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::read_netlink_message ( )
inlineprivate

Definition at line 604 of file genl.hpp.

Here is the caller graph for this function:

◆ reset_buffer()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::reset_buffer ( )
inlineprivate

Definition at line 747 of file genl.hpp.

Here is the caller graph for this function:

◆ send_netlink_message()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::send_netlink_message ( struct nl_msg *  msg)
inlineprivate

Definition at line 797 of file genl.hpp.

Here is the caller graph for this function:

◆ set_peer()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::set_peer ( int  peer_id,
unsigned int  keepalive_interval,
unsigned int  keepalive_timeout 
)
inline

Set peer properties. Currently used for keepalive settings.

Parameters
peer_idID of the peer whose properties have to be modified
keepalive_intervalhow often to send ping packet in absence of traffic
keepalive_timeoutwhen to trigger keepalive_timeout in absence of traffic
Exceptions
netlink_errorthrown if error occurs during sending netlink message

Definition at line 336 of file genl.hpp.

◆ stop()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::stop ( )
inline

Definition at line 419 of file genl.hpp.

◆ swap_keys()

template<typename ReadHandler >
void openvpn::GeNL< ReadHandler >::swap_keys ( int  peer_id)
inline

Swap keys between primary and secondary slots. Called by client as part of rekeying logic to promote and demote keys.

Parameters
peer_idthe ID of the peer whose keys have to be swapped
Exceptions
netlink_errorthrown if error occurs during sending netlink message

Definition at line 280 of file genl.hpp.

Member Data Documentation

◆ buf

template<typename ReadHandler >
BufferAllocated openvpn::GeNL< ReadHandler >::buf
private

Definition at line 819 of file genl.hpp.

◆ cb

template<typename ReadHandler >
struct nl_cb* openvpn::GeNL< ReadHandler >::cb
private

Definition at line 811 of file genl.hpp.

◆ cb_ptr

template<typename ReadHandler >
NlCbPtr openvpn::GeNL< ReadHandler >::cb_ptr
private

Definition at line 808 of file genl.hpp.

◆ halt

template<typename ReadHandler >
bool openvpn::GeNL< ReadHandler >::halt
private

Definition at line 818 of file genl.hpp.

◆ ifindex

template<typename ReadHandler >
unsigned int openvpn::GeNL< ReadHandler >::ifindex
private

Definition at line 814 of file genl.hpp.

◆ nl_status

template<typename ReadHandler >
int openvpn::GeNL< ReadHandler >::nl_status = 0
staticprivate

Definition at line 822 of file genl.hpp.

◆ ovpn_dco_id

template<typename ReadHandler >
int openvpn::GeNL< ReadHandler >::ovpn_dco_id
private

Definition at line 813 of file genl.hpp.

◆ read_handler

template<typename ReadHandler >
ReadHandler openvpn::GeNL< ReadHandler >::read_handler
private

Definition at line 816 of file genl.hpp.

◆ sock

template<typename ReadHandler >
struct nl_sock* openvpn::GeNL< ReadHandler >::sock
private

Definition at line 810 of file genl.hpp.

◆ sock_ptr

template<typename ReadHandler >
NlSockPtr openvpn::GeNL< ReadHandler >::sock_ptr
private

Definition at line 807 of file genl.hpp.

◆ stream

template<typename ReadHandler >
std::unique_ptr<openvpn_io::posix::stream_descriptor> openvpn::GeNL< ReadHandler >::stream
private

Definition at line 821 of file genl.hpp.


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