OpenVPN 3 Core Library
|
#include <capture.hpp>
Classes | |
class | ProxyAutoConfigURL |
Class for handling Proxy Auto-Configuration (PAC) URLs. More... | |
class | ProxyBypass |
Class for managing proxy bypass host configurations. More... | |
class | ProxyHostPort |
Host and port configuration for proxy connections. More... | |
class | RemoteAddress |
Represents a remote IP address with IPv4/IPv6 designation. More... | |
class | RerouteGW |
Class for handling gateway rerouting configuration. More... | |
class | Route |
Route class that must use canonical form. More... | |
class | RouteAddress |
Route address class that may use non-canonical form. More... | |
class | RouteBase |
Base class for route-related functionality representing a network route. More... | |
class | WINSServer |
Windows Internet Name Service (WINS) server configuration. More... | |
Public Types | |
using | Ptr = RCPtr< TunBuilderCapture > |
![]() | |
typedef RCPtr< RC > | Ptr |
Public Member Functions | |
bool | tun_builder_set_remote_address (const std::string &address, bool ipv6) override |
Sets the remote address for the TUN interface. | |
bool | tun_builder_add_address (const std::string &address, int prefix_length, const std::string &gateway, bool ipv6, bool net30) override |
Adds a local address to the TUN interface. | |
bool | tun_builder_reroute_gw (bool ipv4, bool ipv6, unsigned int flags) override |
Configures global gateway rerouting through the VPN tunnel. | |
bool | tun_builder_set_route_metric_default (int metric) override |
Sets the default route metric for VPN routes. | |
bool | tun_builder_add_route (const std::string &address, int prefix_length, int metric, bool ipv6) override |
Adds a route to the tunnel. | |
bool | tun_builder_exclude_route (const std::string &address, int prefix_length, int metric, bool ipv6) override |
Excludes a route from the tunnel. | |
bool | tun_builder_set_dns_options (const DnsOptions &dns) override |
Set DNS options for use with tun builder. | |
bool | tun_builder_set_layer (int layer) override |
Sets the tunnel's network layer. | |
bool | tun_builder_set_mtu (int mtu) override |
Sets the Maximum Transmission Unit (MTU) for the tunnel. | |
bool | tun_builder_set_session_name (const std::string &name) override |
Sets a descriptive name for the VPN session. | |
bool | tun_builder_add_proxy_bypass (const std::string &bypass_host) override |
Adds a host to bypass proxy settings. | |
bool | tun_builder_set_proxy_auto_config_url (const std::string &url) override |
Sets the URL for a proxy auto-configuration (PAC) file. | |
bool | tun_builder_set_proxy_http (const std::string &host, int port) override |
Sets the HTTP proxy for the tunnel. | |
bool | tun_builder_set_proxy_https (const std::string &host, int port) override |
Sets the HTTPS proxy for the tunnel. | |
bool | tun_builder_add_wins_server (const std::string &address) override |
Adds a WINS server to the tunnel configuration. | |
bool | tun_builder_set_allow_family (int af, bool allow) override |
Sets whether to allow a specific address family in the tunnel. | |
bool | tun_builder_set_allow_local_dns (bool allow) override |
Sets whether to allow local DNS resolution. | |
void | reset_tunnel_addresses () |
Resets all tunnel addresses. | |
void | reset_dns_options () |
Resets DNS options to default values. | |
const RouteAddress * | vpn_ipv4 () const |
Gets the IPv4 tunnel address. | |
const RouteAddress * | vpn_ipv6 () const |
Gets the IPv6 tunnel address. | |
const RouteAddress * | vpn_ip (const IP::Addr::Version v) const |
Gets the tunnel address for the specified IP version. | |
void | validate () const |
Validates the configuration of the tunnel. | |
std::string | to_string () const |
Converts the tunnel configuration to a human-readable string representation. | |
Json::Value | to_json () const |
Serializes the tunnel configuration to a JSON object. | |
![]() | |
virtual bool | tun_builder_new () |
Callback to construct a new TunBuilder. This function should be called first. | |
virtual int | tun_builder_establish () |
Callback to establish the VPN tunnel. | |
virtual bool | tun_builder_persist () |
Determines if the TUN interface can be persisted. | |
virtual std::vector< std::string > | tun_builder_get_local_networks (bool ipv6) |
Retrieves a list of local networks to exclude from the VPN network. | |
virtual void | tun_builder_establish_lite () |
Indicates a reconnection with persisted TUN state. | |
virtual void | tun_builder_teardown (bool disconnect) |
Indicates that tunnel is being torn down. | |
virtual | ~TunBuilderBase ()=default |
Virtual destructor for the TunBuilderBase class. | |
![]() | |
RC () noexcept=default | |
RC (const RC &)=delete | |
virtual | ~RC ()=default |
RC & | operator= (const RC &)=delete |
olong | use_count () const noexcept |
Delegates call to RCImpl and returns the result. | |
Static Public Member Functions | |
static TunBuilderCapture::Ptr | from_json (const Json::Value &root) |
Creates a TunBuilderCapture instance from a JSON representation. | |
![]() | |
static constexpr bool | is_thread_safe () |
Delegates call to RCImpl and returns the result. | |
Public Attributes | |
std::string | session_name |
int | mtu = 0 |
Layer | layer {Layer::OSI_LAYER_3} |
RemoteAddress | remote_address |
std::vector< RouteAddress > | tunnel_addresses |
int | tunnel_address_index_ipv4 = -1 |
int | tunnel_address_index_ipv6 = -1 |
RerouteGW | reroute_gw |
bool | block_ipv4 = false |
bool | block_ipv6 = false |
bool | block_outside_dns = false |
int | route_metric_default = -1 |
std::vector< Route > | add_routes |
std::vector< Route > | exclude_routes |
DnsOptions | dns_options |
std::vector< ProxyBypass > | proxy_bypass |
ProxyAutoConfigURL | proxy_auto_config_url |
ProxyHostPort | http_proxy |
ProxyHostPort | https_proxy |
std::vector< WINSServer > | wins_servers |
Static Public Attributes | |
static constexpr int | mtu_ipv4_maximum = 65'535 |
Private Member Functions | |
bool | validate_tunnel_index (const int index) const |
Checks if a tunnel index is valid. | |
void | validate_tunnel_address_indices (const std::string &title) const |
Validates tunnel address indices for both IPv4 and IPv6. | |
void | validate_mtu (const std::string &title) const |
Validates that the MTU value is within an acceptable range. | |
void | validate_layer (const std::string &title) const |
Validates that the network layer is defined. | |
Static Private Member Functions | |
template<typename LIST > | |
static void | render_list (std::ostream &os, const std::string &title, const LIST &list) |
Renders a list of elements to an output stream with a title. | |
template<typename LIST > | |
static void | validate_list (const LIST &list, const std::string &title) |
Validates each element in a list. | |
Definition at line 41 of file capture.hpp.
Definition at line 44 of file capture.hpp.
|
inlinestatic |
Creates a TunBuilderCapture instance from a JSON representation.
Parses a JSON object to reconstruct a complete tunnel configuration, validating required fields and populating all configuration parameters. Uses helper methods from the json namespace to ensure proper type conversion and validation.
root | The JSON object containing the tunnel configuration. |
Definition at line 1049 of file capture.hpp.
|
inlinestaticprivate |
Renders a list of elements to an output stream with a title.
Outputs the title followed by each element in the list on a new line with indentation. Each element is rendered using its to_string() method.
os | The output stream to write to. |
title | The title to display before the list. |
list | The list of elements to render. |
LIST | The list type which must contain elements with a to_string() method. |
Definition at line 1115 of file capture.hpp.
|
inline |
Resets DNS options to default values.
Clears all DNS configuration options.
Definition at line 892 of file capture.hpp.
|
inline |
Resets all tunnel addresses.
Clears the list of tunnel addresses and resets IPv4 and IPv6 address indices to invalid values.
Definition at line 881 of file capture.hpp.
|
inline |
Serializes the tunnel configuration to a JSON object.
Converts all tunnel parameters into a JSON representation, including session details, network configuration, routing options, and proxy settings. Optional settings are only included in the JSON if they are defined.
Json::Value
object containing the serialized tunnel configuration. Definition at line 1011 of file capture.hpp.
|
inline |
Converts the tunnel configuration to a human-readable string representation.
Creates a formatted multi-line string containing all configured tunnel parameters including session name, layer, MTU, addresses, routing options, DNS settings, and proxy configurations. Only displays optional settings if they are defined.
Definition at line 968 of file capture.hpp.
|
inlineoverridevirtual |
Adds a local address to the TUN interface.
Configures a local IP address for the virtual network interface with specified prefix length and gateway. Maintains separate indices for IPv4 and IPv6 addresses.
address | The local IP address to assign to the TUN interface. |
prefix_length | The subnet prefix length (e.g., 24 for a /24 subnet). |
gateway | The gateway address for this network. |
ipv6 | If true , indicates this is an IPv6 address; if false , it's an IPv4 address. |
net30 | If true , indicates this is a net30 topology (point-to-point with 4 addresses). |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 644 of file capture.hpp.
|
inlineoverridevirtual |
Adds a host to bypass proxy settings.
Configures a host that should connect directly, bypassing any proxy settings when the VPN is active.
bypass_host | The hostname or address that should bypass the proxy. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 786 of file capture.hpp.
|
inlineoverridevirtual |
Adds a route to the tunnel.
Configures a new route to be added to the routing table when the tunnel is established.
address | The destination network address. |
prefix_length | The subnet prefix length (netmask). |
metric | The route metric/priority value. If negative, a default metric will be used. |
ipv6 | Whether this is an IPv6 true or IPv4 false route. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 699 of file capture.hpp.
|
inlineoverridevirtual |
Adds a WINS server to the tunnel configuration.
Creates a new WINS server entry with the provided address and adds it to the list of WINS servers.
address | The IP address of the WINS server. |
true
to indicate successful addition. Reimplemented from openvpn::TunBuilderBase.
Definition at line 841 of file capture.hpp.
|
inlineoverridevirtual |
Excludes a route from the tunnel.
Configures a route to be excluded from the tunnel routing, allowing traffic to that destination to bypass the VPN tunnel.
address | The destination network address to exclude. |
prefix_length | The subnet prefix length (netmask). |
metric | The route metric/priority value. |
ipv6 | Whether this is an IPv6 (true ) or IPv4 (false ) route. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 720 of file capture.hpp.
|
inlineoverridevirtual |
Configures global gateway rerouting through the VPN tunnel.
Sets up redirection of default traffic routes through the VPN tunnel for IPv4 and/or IPv6 traffic according to the specified flags.
ipv4 | If true , reroute IPv4 default gateway. |
ipv6 | If true , reroute IPv6 default gateway. |
flags | Special routing flags that modify the routing behavior. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 669 of file capture.hpp.
|
inlineoverridevirtual |
Sets whether to allow a specific address family in the tunnel.
Controls whether IPv4 or IPv6 traffic is allowed or blocked in the tunnel.
af | The address family to configure (AF_INET for IPv4 or AF_INET6 for IPv6). |
allow | Whether to allow true or block false the specified address family. |
true
to indicate successful configuration. Reimplemented from openvpn::TunBuilderBase.
Definition at line 856 of file capture.hpp.
|
inlineoverridevirtual |
Sets whether to allow local DNS resolution.
Controls whether DNS requests can be resolved locally or must go through the VPN.
allow | Whether to allow true or block false local DNS resolution. |
true
to indicate successful configuration. Reimplemented from openvpn::TunBuilderBase.
Definition at line 871 of file capture.hpp.
|
inlineoverridevirtual |
Set DNS options for use with tun builder.
Calling this invalidates any DNS related --dhcp-options
previously added.
dns | The --dns options to be set. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 737 of file capture.hpp.
|
inlineoverridevirtual |
Sets the tunnel's network layer.
Configures which OSI layer the tunnel will operate at (typically layer 2 or 3).
layer | The network layer value to set. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 749 of file capture.hpp.
|
inlineoverridevirtual |
Sets the Maximum Transmission Unit (MTU) for the tunnel.
Configures the maximum packet size that can be transmitted through the tunnel.
mtu | The MTU value in bytes. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 761 of file capture.hpp.
|
inlineoverridevirtual |
Sets the URL for a proxy auto-configuration (PAC) file.
Configures the VPN to use a PAC file at the specified URL for determining proxy settings.
url | The URL where the PAC file is located. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 801 of file capture.hpp.
|
inlineoverridevirtual |
Sets the HTTP proxy for the tunnel.
Configures the HTTP proxy with the specified host and port.
host | The hostname or IP address of the HTTP proxy server. |
port | The port number of the HTTP proxy server. |
true
to indicate successful configuration. Reimplemented from openvpn::TunBuilderBase.
Definition at line 814 of file capture.hpp.
|
inlineoverridevirtual |
Sets the HTTPS proxy for the tunnel.
Configures the HTTPS proxy with the specified host and port.
host | The hostname or IP address of the HTTPS proxy server. |
port | The port number of the HTTPS proxy server. |
true
to indicate successful configuration. Reimplemented from openvpn::TunBuilderBase.
Definition at line 828 of file capture.hpp.
|
inlineoverridevirtual |
Sets the remote address for the TUN interface.
Stores the remote endpoint address for the VPN tunnel connection.
address | The remote address string to set. |
ipv6 | If true , indicates this is an IPv6 address; if false , it's an IPv4 address. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 626 of file capture.hpp.
|
inlineoverridevirtual |
Sets the default route metric for VPN routes.
Configures the priority of routes added by the VPN, where lower metric values indicate higher priority routes.
metric | The metric value to assign to routes. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 684 of file capture.hpp.
|
inlineoverridevirtual |
Sets a descriptive name for the VPN session.
This name may be displayed in network connection UIs or logs.
name | The session name to set. |
true
to indicate successful operation. Reimplemented from openvpn::TunBuilderBase.
Definition at line 773 of file capture.hpp.
|
inline |
Validates the configuration of the tunnel.
Performs validation on all components of the tunnel configuration, including layer settings, MTU, addresses, routes, and proxy settings. Each component's validate method is called with an appropriate context string.
Definition at line 946 of file capture.hpp.
|
inlineprivate |
Validates that the network layer is defined.
Checks that the layer property has been properly initialized. Throws an exception if the layer is undefined.
title | The title to use in exception messages. |
Exception | if the layer is undefined. |
Definition at line 1199 of file capture.hpp.
|
inlinestaticprivate |
Validates each element in a list.
Iterates through each element in the list and calls its validate() method with a title argument that includes the element's index.
list | The list of elements to validate. |
title | The base title to use for validation messages. |
LIST | The list type which must contain elements with a validate() method. |
Definition at line 1133 of file capture.hpp.
|
inlineprivate |
Validates that the MTU value is within an acceptable range.
Checks that the MTU is not negative and does not exceed mtu_ipv4_maximum. Throws an exception if validation fails.
title | The title to use in exception messages. |
Exception | if the MTU is out of range. |
Definition at line 1186 of file capture.hpp.
|
inlineprivate |
Validates tunnel address indices for both IPv4 and IPv6.
Checks that both tunnel_address_index_ipv4 and tunnel_address_index_ipv6 are valid, and that they point to the correct address types (IPv4 and IPv6 respectively). Throws an exception if any validation fails.
title | The title to use in exception messages. |
Exception | if any validation fails, with a descriptive error message. |
Definition at line 1165 of file capture.hpp.
|
inlineprivate |
Checks if a tunnel index is valid.
An index is considered valid if it's -1 (special value) or if it's within the range of available tunnel addresses (0 to tunnel_addresses.size()
).
index | The tunnel index to validate. |
true
if the index is valid, false
otherwise. Definition at line 1150 of file capture.hpp.
|
inline |
Gets the tunnel address for the specified IP version.
Returns a pointer to the RouteAddress structure for the specified IP version.
v | The IP address version (V4 or V6). |
nullptr
if not configured. Definition at line 927 of file capture.hpp.
|
inline |
Gets the IPv4 tunnel address.
Returns a pointer to the RouteAddress structure for the IPv4 tunnel if configured.
nullptr
if not configured. Definition at line 902 of file capture.hpp.
|
inline |
Gets the IPv6 tunnel address.
Returns a pointer to the RouteAddress structure for the IPv6 tunnel if configured.
nullptr
if not configured. Definition at line 914 of file capture.hpp.
std::vector<Route> openvpn::TunBuilderCapture::add_routes |
Definition at line 1091 of file capture.hpp.
bool openvpn::TunBuilderCapture::block_ipv4 = false |
Definition at line 1087 of file capture.hpp.
bool openvpn::TunBuilderCapture::block_ipv6 = false |
Definition at line 1088 of file capture.hpp.
bool openvpn::TunBuilderCapture::block_outside_dns = false |
Definition at line 1089 of file capture.hpp.
DnsOptions openvpn::TunBuilderCapture::dns_options |
Definition at line 1093 of file capture.hpp.
std::vector<Route> openvpn::TunBuilderCapture::exclude_routes |
Definition at line 1092 of file capture.hpp.
ProxyHostPort openvpn::TunBuilderCapture::http_proxy |
Definition at line 1097 of file capture.hpp.
ProxyHostPort openvpn::TunBuilderCapture::https_proxy |
Definition at line 1098 of file capture.hpp.
Layer openvpn::TunBuilderCapture::layer {Layer::OSI_LAYER_3} |
Definition at line 1081 of file capture.hpp.
int openvpn::TunBuilderCapture::mtu = 0 |
Definition at line 1080 of file capture.hpp.
|
staticconstexpr |
Definition at line 1102 of file capture.hpp.
ProxyAutoConfigURL openvpn::TunBuilderCapture::proxy_auto_config_url |
Definition at line 1096 of file capture.hpp.
std::vector<ProxyBypass> openvpn::TunBuilderCapture::proxy_bypass |
Definition at line 1095 of file capture.hpp.
RemoteAddress openvpn::TunBuilderCapture::remote_address |
Definition at line 1082 of file capture.hpp.
RerouteGW openvpn::TunBuilderCapture::reroute_gw |
Definition at line 1086 of file capture.hpp.
int openvpn::TunBuilderCapture::route_metric_default = -1 |
Definition at line 1090 of file capture.hpp.
std::string openvpn::TunBuilderCapture::session_name |
Definition at line 1079 of file capture.hpp.
int openvpn::TunBuilderCapture::tunnel_address_index_ipv4 = -1 |
Definition at line 1084 of file capture.hpp.
int openvpn::TunBuilderCapture::tunnel_address_index_ipv6 = -1 |
Definition at line 1085 of file capture.hpp.
std::vector<RouteAddress> openvpn::TunBuilderCapture::tunnel_addresses |
Definition at line 1083 of file capture.hpp.
std::vector<WINSServer> openvpn::TunBuilderCapture::wins_servers |
Definition at line 1100 of file capture.hpp.