OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::TunWin::Nrpt< REG, NETAPI > Class Template Reference

Manage NRPT rules for Windows. More...

#include <nrpt.hpp>

Classes

class  ActionCreate
 
class  ActionDelete
 
struct  ExcludeRuleData
 

Public Member Functions

 OPENVPN_EXCEPTION (nrpt_error)
 

Static Public Member Functions

static void create_rule (const std::string &rule_id, const std::wstring &domains, const std::wstring &servers, bool dnssec)
 Create a NRPT rule in the registry.
 
static void create_exclude_rules (DWORD process_id, const std::vector< std::wstring > &search_domains)
 
static void delete_rules (DWORD process_id)
 Remove our NRPT rules from the registry.
 
static std::string rule_id (DWORD process_id)
 Return a NRPT rule id.
 
static std::string exclude_rule_id (DWORD process_id, std::uint32_t n)
 Return a NRPT exclude rule id.
 

Static Private Member Functions

static std::vector< std::wstring > interface_ipv4_dns_servers (const std::wstring &itf_guid)
 Get IPv4 DNS server addresses of an interface.
 
static std::vector< std::wstring > interface_ipv6_dns_servers (const std::wstring &itf_guid)
 Get IPv6 DNS server addresses of an interface.
 
static std::vector< ExcludeRuleDatacollect_exclude_rule_data (const std::vector< std::wstring > &sd)
 Get all the data necessary for excluding local domains from the tunnel.
 
static REG::Key open_nrpt_base_key ()
 Open the NRPT key to store our rules at.
 
static const char * id_prefix ()
 Return the rule id prefix any rule starts with.
 
static std::string gen_rule_id (DWORD process_id, bool exclude_rule, std::uint32_t n)
 Generate a rule id string.
 

Detailed Description

template<typename REG, typename NETAPI>
class openvpn::TunWin::Nrpt< REG, NETAPI >

Manage NRPT rules for Windows.

Template Parameters
REGRegistry abstraction class to use
NETAPINetwork related Win32 API class to use

Definition at line 58 of file nrpt.hpp.

Member Function Documentation

◆ collect_exclude_rule_data()

template<typename REG , typename NETAPI >
static std::vector< ExcludeRuleData > openvpn::TunWin::Nrpt< REG, NETAPI >::collect_exclude_rule_data ( const std::vector< std::wstring > &  sd)
inlinestaticprivate

Get all the data necessary for excluding local domains from the tunnel.

This data is only necessary if all the domains are to be resolved through the VPN. To not break resolving local DNS names, we add so called exclude rules to the NRPT for as long as the tunnel persists. If a local domain matches one of the pushed search domains, skip it, so that look-ups are performed via VPN.

Parameters
sdsearch domains to compare local domains to
Returns
std::vector<ExcludeRuleData> The data collected to create exclude rules from.

Definition at line 279 of file nrpt.hpp.

Here is the caller graph for this function:

◆ create_exclude_rules()

template<typename REG , typename NETAPI >
static void openvpn::TunWin::Nrpt< REG, NETAPI >::create_exclude_rules ( DWORD  process_id,
const std::vector< std::wstring > &  search_domains 
)
inlinestatic

Set NRPT exclude rules to accompany a catch all rule. This is done so that local resolution of names is not interfered with in case the VPN resolves all names. Exclude rules are only created when no search domain matches to local domain to deal with situations where look-ups should go via VPN, but exclude rules prevent this.

Parameters
process_idthe process id used for the rules
search_domainssearch domains to compare local domains to

Definition at line 136 of file nrpt.hpp.

Here is the caller graph for this function:

◆ create_rule()

template<typename REG , typename NETAPI >
static void openvpn::TunWin::Nrpt< REG, NETAPI >::create_rule ( const std::string &  rule_id,
const std::wstring &  domains,
const std::wstring &  servers,
bool  dnssec 
)
inlinestatic

Create a NRPT rule in the registry.

The exact location of the rule depends on whether there are alredy rules rules defined. If so the rule is stored with them, either in the place where group policy based ones are, or the local one.

Parameters
rule_idthe unique rule id
domainsdomains the rule applies to as wide MULTI_SZ
serverslist of name server addresses, separated by semicolon
dnssecwhether DNSSEC should be enabled for the rule

Definition at line 75 of file nrpt.hpp.

Here is the caller graph for this function:

◆ delete_rules()

template<typename REG , typename NETAPI >
static void openvpn::TunWin::Nrpt< REG, NETAPI >::delete_rules ( DWORD  process_id)
inlinestatic

Remove our NRPT rules from the registry.

Iterate over the rules in the two know subkeys where NRPT rules can be located in the Windows registry and remove those rules, which we identify as ours. This is done by comparing the process id we add to the end of each rule we add. If the process id is zero all NRPT rules are deleted, regardless of the actual pid.

Parameters
process_idthe process id used for the rule deletion

Definition at line 157 of file nrpt.hpp.

Here is the caller graph for this function:

◆ exclude_rule_id()

template<typename REG , typename NETAPI >
static std::string openvpn::TunWin::Nrpt< REG, NETAPI >::exclude_rule_id ( DWORD  process_id,
std::uint32_t  n 
)
inlinestatic

Return a NRPT exclude rule id.

Parameters
process_idthe process id used for the rule
nthe number of this rule
Returns
std::string the rule id string

Definition at line 388 of file nrpt.hpp.

Here is the caller graph for this function:

◆ gen_rule_id()

template<typename REG , typename NETAPI >
static std::string openvpn::TunWin::Nrpt< REG, NETAPI >::gen_rule_id ( DWORD  process_id,
bool  exclude_rule,
std::uint32_t  n 
)
inlinestaticprivate

Generate a rule id string.

Parameters
process_idthe process id used for the rule
exclude_rulewhether the rule is for an exclude rule
nthe number of the exclude rule
Returns
std::string the rule id string

Definition at line 357 of file nrpt.hpp.

Here is the caller graph for this function:

◆ id_prefix()

template<typename REG , typename NETAPI >
static const char * openvpn::TunWin::Nrpt< REG, NETAPI >::id_prefix ( )
inlinestaticprivate

Return the rule id prefix any rule starts with.

Returns
const char* the prefix string

Definition at line 343 of file nrpt.hpp.

Here is the caller graph for this function:

◆ interface_ipv4_dns_servers()

template<typename REG , typename NETAPI >
static std::vector< std::wstring > openvpn::TunWin::Nrpt< REG, NETAPI >::interface_ipv4_dns_servers ( const std::wstring &  itf_guid)
inlinestaticprivate

Get IPv4 DNS server addresses of an interface.

Parameters
itf_guidThe interface GUID string
Returns
std::vector<std::wstring> IPv4 server addresses found

Definition at line 206 of file nrpt.hpp.

Here is the caller graph for this function:

◆ interface_ipv6_dns_servers()

template<typename REG , typename NETAPI >
static std::vector< std::wstring > openvpn::TunWin::Nrpt< REG, NETAPI >::interface_ipv6_dns_servers ( const std::wstring &  itf_guid)
inlinestaticprivate

Get IPv6 DNS server addresses of an interface.

Parameters
itf_guidThe interface GUID string
Returns
std::vector<std::string> IPv6 server addresses found

Definition at line 234 of file nrpt.hpp.

Here is the caller graph for this function:

◆ open_nrpt_base_key()

template<typename REG , typename NETAPI >
static REG::Key openvpn::TunWin::Nrpt< REG, NETAPI >::open_nrpt_base_key ( )
inlinestaticprivate

Open the NRPT key to store our rules at.

There are two places in the registry where NRPT rules can be found, depending on whether group policy rules are used or not. This function tries for the group policy place first and returns the key for the local rules in case it does not exist.

Returns
REG::Key the opened Registry handle

Definition at line 328 of file nrpt.hpp.

Here is the caller graph for this function:

◆ OPENVPN_EXCEPTION()

template<typename REG , typename NETAPI >
openvpn::TunWin::Nrpt< REG, NETAPI >::OPENVPN_EXCEPTION ( nrpt_error  )

◆ rule_id()

template<typename REG , typename NETAPI >
static std::string openvpn::TunWin::Nrpt< REG, NETAPI >::rule_id ( DWORD  process_id)
inlinestatic

Return a NRPT rule id.

Parameters
process_idthe process id used for the rule
Returns
std::string the rule is string

Definition at line 376 of file nrpt.hpp.

Here is the caller graph for this function:

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