15#ifndef OPENVPN_TUN_BUILDER_CAPTURE_H
16#define OPENVPN_TUN_BUILDER_CAPTURE_H
103 Json::Value root(Json::objectValue);
104 root[
"address"] = Json::Value(
address);
105 root[
"ipv6"] = Json::Value(
ipv6);
116 void from_json(
const Json::Value &root,
const std::string &title)
147 std::ostringstream
os;
163 Json::Value root(Json::objectValue);
164 root[
"ipv4"] = Json::Value(
ipv4);
165 root[
"ipv6"] = Json::Value(
ipv6);
166 root[
"flags"] = Json::Value(
flags);
177 void from_json(
const Json::Value &root,
const std::string &title)
214 std::ostringstream
os;
235 Json::Value root(Json::objectValue);
236 root[
"address"] = Json::Value(
address);
238 root[
"metric"] = Json::Value(
metric);
239 root[
"gateway"] = Json::Value(
gateway);
240 root[
"ipv6"] = Json::Value(
ipv6);
241 root[
"net30"] = Json::Value(
net30);
252 void from_json(
const Json::Value &root,
const std::string &title)
277 void validate_(
const std::string &title,
const bool require_canonical)
const
377 Json::Value root(Json::objectValue);
388 void from_json(
const Json::Value &root,
const std::string &title)
441 catch (
const std::exception &e)
455 Json::Value root(Json::objectValue);
456 root[
"url"] = Json::Value(
url);
468 void from_json(
const Json::Value &root,
const std::string &title)
496 std::ostringstream
os;
508 return !
host.empty();
535 Json::Value root(Json::objectValue);
536 root[
"host"] = Json::Value(
host);
537 root[
"port"] = Json::Value(
port);
548 void from_json(
const Json::Value &root,
const std::string &title)
599 Json::Value root(Json::objectValue);
600 root[
"address"] = Json::Value(
address);
611 void from_json(
const Json::Value &root,
const std::string &title)
860 else if (af == AF_INET6)
970 std::ostringstream
os;
974 os <<
"MTU: " <<
mtu <<
'\n';
978 os <<
"Block IPv4: " << (
block_ipv4 ?
"yes" :
"no") <<
'\n';
979 os <<
"Block IPv6: " << (
block_ipv6 ?
"yes" :
"no") <<
'\n';
1013 Json::Value root(Json::objectValue);
1015 root[
"mtu"] = Json::Value(
mtu);
1023 root[
"block_ipv6"] = Json::Value(
block_ipv6);
1051 const std::string title =
"root";
1057 tbc->remote_address.from_json(root[
"remote_address"],
"remote_address");
1059 json::to_int(root,
tbc->tunnel_address_index_ipv4,
"tunnel_address_index_ipv4", title);
1060 json::to_int(root,
tbc->tunnel_address_index_ipv6,
"tunnel_address_index_ipv6", title);
1061 tbc->reroute_gw.from_json(root[
"reroute_gw"],
"reroute_gw");
1064 json::to_int(root,
tbc->route_metric_default,
"route_metric_default", title);
1067 tbc->dns_options.from_json(root[
"dns_options"],
"dns_options");
1070 tbc->proxy_auto_config_url.from_json(root[
"proxy_auto_config_url"],
"proxy_auto_config_url");
1071 tbc->http_proxy.from_json(root[
"http_proxy"],
"http_proxy");
1072 tbc->https_proxy.from_json(root[
"https_proxy"],
"https_proxy");
1114 template <
typename LIST>
1115 static void render_list(std::ostream &
os,
const std::string &title,
const LIST &list)
1117 os << title <<
':' <<
'\n';
1118 for (
auto &e : list)
1120 os <<
" " << e.to_string() <<
'\n';
1132 template <
typename LIST>
1136 for (
auto &e : list)
1154 return index >= 0 &&
static_cast<unsigned int>(index) <=
tunnel_addresses.size();
1175 if (r6 && !r6->
ipv6)
bool is_canonical() const
static Layer from_value(const int value)
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
std::string to_string() const
TunBuilder methods, loosely based on the Android VpnService.Builder abstraction.
Class for handling Proxy Auto-Configuration (PAC) URLs.
void from_json(const Json::Value &root, const std::string &title)
Populates the URL from a JSON object.
bool defined() const
Checks if the URL is defined.
std::string to_string() const
Returns the URL as a string.
void validate(const std::string &title) const
Validates the URL format.
Json::Value to_json() const
Converts the URL to a JSON object.
Class for managing proxy bypass host configurations.
void from_json(const Json::Value &root, const std::string &title)
Deserializes the object from JSON.
void validate(const std::string &title) const
Validates the bypass host value.
std::string to_string() const
Converts the bypass host to a string representation.
bool defined() const
Checks if a bypass host is defined.
Json::Value to_json() const
Serializes the object to JSON.
Host and port configuration for proxy connections.
std::string to_string() const
Converts the host and port to a string representation.
void from_json(const Json::Value &root, const std::string &title)
Populates the object from a JSON representation.
void validate(const std::string &title) const
Validates the host and port.
bool defined() const
Checks if the proxy configuration is defined.
Json::Value to_json() const
Converts the object to a JSON representation.
Represents a remote IP address with IPv4/IPv6 designation.
void validate(const std::string &title) const
Validates the IP address format.
void from_json(const Json::Value &root, const std::string &title)
Deserializes the object from a JSON value.
Json::Value to_json() const
Serializes the object to a JSON value.
bool defined() const
Checks if the address is defined.
std::string to_string() const
Returns a string representation of the remote address.
Class for handling gateway rerouting configuration.
std::string to_string() const
Converts the object to a human-readable string representation.
Json::Value to_json() const
Serializes the object to a JSON value.
void from_json(const Json::Value &root, const std::string &title)
Deserializes the object from a JSON value.
Route address class that may use non-canonical form.
void validate(const std::string &title) const
Validates the route address.
Base class for route-related functionality representing a network route.
static constexpr int net30_prefix_length
void validate_(const std::string &title, const bool require_canonical) const
Protected validation method used by derived classes.
void from_json(const Json::Value &root, const std::string &title)
Deserializes the route from a JSON object.
unsigned char prefix_length
std::string to_string() const
Converts the route to a human-readable string.
Json::Value to_json() const
Serializes the route to a JSON object.
Route class that must use canonical form.
void validate(const std::string &title) const
Validates the route.
Windows Internet Name Service (WINS) server configuration.
void validate(const std::string &title) const
Validates the WINS server address.
std::string to_string() const
Converts the WINS server to a string representation.
Json::Value to_json() const
Serializes the WINS server to a JSON object.
void from_json(const Json::Value &root, const std::string &title)
Deserializes a WINS server from a JSON object.
bool tun_builder_exclude_route(const std::string &address, int prefix_length, int metric, bool ipv6) override
Excludes a route from the tunnel.
RemoteAddress remote_address
bool tun_builder_set_allow_family(int af, bool allow) override
Sets whether to allow a specific address family in the tunnel.
std::vector< RouteAddress > tunnel_addresses
void validate() const
Validates the configuration of the tunnel.
bool tun_builder_add_proxy_bypass(const std::string &bypass_host) override
Adds a host to bypass proxy settings.
bool tun_builder_set_proxy_https(const std::string &host, int port) override
Sets the HTTPS proxy for the tunnel.
bool tun_builder_set_dns_options(const DnsOptions &dns) override
Set DNS options for use with tun builder.
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_set_allow_local_dns(bool allow) override
Sets whether to allow local DNS resolution.
bool tun_builder_set_route_metric_default(int metric) override
Sets the default route metric for VPN routes.
std::vector< Route > add_routes
const RouteAddress * vpn_ip(const IP::Addr::Version v) const
Gets the tunnel address for the specified IP version.
static constexpr int mtu_ipv4_maximum
ProxyAutoConfigURL proxy_auto_config_url
int tunnel_address_index_ipv4
void validate_layer(const std::string &title) const
Validates that the network layer is defined.
bool tun_builder_set_session_name(const std::string &name) override
Sets a descriptive name for the VPN session.
void reset_dns_options()
Resets DNS options to default values.
bool tun_builder_set_remote_address(const std::string &address, bool ipv6) override
Sets the remote address for the TUN interface.
bool tun_builder_set_mtu(int mtu) override
Sets the Maximum Transmission Unit (MTU) for the tunnel.
static TunBuilderCapture::Ptr from_json(const Json::Value &root)
Creates a TunBuilderCapture instance from a JSON representation.
Json::Value to_json() const
Serializes the tunnel configuration to a JSON object.
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.
const RouteAddress * vpn_ipv6() const
Gets the IPv6 tunnel address.
bool tun_builder_set_layer(int layer) override
Sets the tunnel's network layer.
const RouteAddress * vpn_ipv4() const
Gets the IPv4 tunnel address.
bool tun_builder_set_proxy_http(const std::string &host, int port) override
Sets the HTTP proxy for the tunnel.
std::string to_string() const
Converts the tunnel configuration to a human-readable string representation.
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_add_wins_server(const std::string &address) override
Adds a WINS server to the tunnel configuration.
std::vector< Route > exclude_routes
bool tun_builder_reroute_gw(bool ipv4, bool ipv6, unsigned int flags) override
Configures global gateway rerouting through the VPN tunnel.
std::vector< ProxyBypass > proxy_bypass
bool validate_tunnel_index(const int index) const
Checks if a tunnel index is valid.
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.
void validate_tunnel_address_indices(const std::string &title) const
Validates tunnel address indices for both IPv4 and IPv6.
std::vector< WINSServer > wins_servers
static void validate_list(const LIST &list, const std::string &title)
Validates each element in a list.
void reset_tunnel_addresses()
Resets all tunnel addresses.
ProxyHostPort https_proxy
int tunnel_address_index_ipv6
void validate_mtu(const std::string &title) const
Validates that the MTU value is within an acceptable range.
#define OPENVPN_THROW_EXCEPTION(stuff)
void validate_host(const std::string &host, const std::string &title)
void validate_port(const std::string &port, const std::string &title, unsigned int *value=nullptr)
Route route_from_string_prefix(const std::string &addrstr, const unsigned int prefix_len, const TITLE &title, const IP::Addr::Version required_version=IP::Addr::UNSPEC)
void assert_dict(const Json::Value &obj, const TITLE &title)
int get_int(const Json::Value &root, const NAME &name, const TITLE &title)
void to_string(const Json::Value &root, std::string &dest, const NAME &name, const TITLE &title)
void to_uint(const Json::Value &root, unsigned int &dest, const NAME &name, const TITLE &title)
void to_int(const Json::Value &root, int &dest, const NAME &name, const TITLE &title)
void to_uchar(const Json::Value &root, unsigned char &dest, const NAME &name, const TITLE &title)
bool is_dict(const Json::Value &obj, const TITLE &title)
void to_vector(const Json::Value &root, T &vec, const NAME &name, const TITLE &title)
void to_bool(const Json::Value &root, bool &dest, const NAME &name, const TITLE &title)
void from_vector(Json::Value &root, const T &vec, const NAME &name)
std::string to_string(const T &t)
Convert a value to a string.
All DNS options set with the –dns or –dhcp-option directive.
std::map< int, DnsServer > servers
std::string to_string() const
Json::Value to_json() const
const TunBuilderCapture::Ptr tbc(new TunBuilderCapture)