OpenVPN 3 Core Library
Loading...
Searching...
No Matches
capture.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12// An artificial TunBuilder object, used to log the tun builder settings,
13// but doesn't actually configure anything.
14
15#ifndef OPENVPN_TUN_BUILDER_CAPTURE_H
16#define OPENVPN_TUN_BUILDER_CAPTURE_H
17
18#include <string>
19#include <sstream>
20#include <vector>
21
23#include <openvpn/common/rc.hpp>
31#include <openvpn/addr/ip.hpp>
34#include <openvpn/tun/layer.hpp>
35
36#ifdef HAVE_JSON
38#endif
39
40namespace openvpn {
41class TunBuilderCapture : public TunBuilderBase, public RC<thread_unsafe_refcount>
42{
43 public:
45
46 // builder data classes
47
55 {
56 public:
57 std::string address;
58 bool ipv6 = false;
59
66 std::string to_string() const
67 {
68 std::string ret = address;
69 if (ipv6)
70 ret += " [IPv6]";
71 return ret;
72 }
73
79 bool defined() const
80 {
81 return !address.empty();
82 }
83
90 void validate(const std::string &title) const
91 {
93 }
94
95#ifdef HAVE_JSON
101 Json::Value to_json() const
102 {
103 Json::Value root(Json::objectValue);
104 root["address"] = Json::Value(address);
105 root["ipv6"] = Json::Value(ipv6);
106 return root;
107 }
108
116 void from_json(const Json::Value &root, const std::string &title)
117 {
118 if (!json::is_dict(root, title))
119 return;
120 json::to_string(root, address, "address", title);
121 json::to_bool(root, ipv6, "ipv6", title);
122 }
123#endif
124 };
125
133 {
134 public:
135 bool ipv4 = false;
136 bool ipv6 = false;
137 unsigned int flags = 0;
138
145 std::string to_string() const
146 {
147 std::ostringstream os;
148 const RedirectGatewayFlags rgf(flags);
149 os << "IPv4=" << ipv4 << " IPv6=" << ipv6 << " flags=" << rgf.to_string();
150 return os.str();
151 }
152
153
154#ifdef HAVE_JSON
161 Json::Value to_json() const
162 {
163 Json::Value root(Json::objectValue);
164 root["ipv4"] = Json::Value(ipv4);
165 root["ipv6"] = Json::Value(ipv6);
166 root["flags"] = Json::Value(flags);
167 return root;
168 }
169
177 void from_json(const Json::Value &root, const std::string &title)
178 {
179 json::assert_dict(root, title);
180 json::to_bool(root, ipv4, "ipv4", title);
181 json::to_bool(root, ipv6, "ipv6", title);
182 json::to_uint(root, flags, "flags", title);
183 }
184#endif
185 };
186
197 {
198 public:
199 std::string address;
200 unsigned char prefix_length = 0;
201 int metric = -1; // optional
202 std::string gateway; // optional
203 bool ipv6 = false;
204 bool net30 = false;
205
212 std::string to_string() const
213 {
214 std::ostringstream os;
215 os << address << '/' << static_cast<uint16_t>(prefix_length);
216 if (!gateway.empty())
217 os << " -> " << gateway;
218 if (metric >= 0)
219 os << " [METRIC=" << metric << ']';
220 if (ipv6)
221 os << " [IPv6]";
222 if (net30)
223 os << " [net30]";
224 return os.str();
225 }
226
227#ifdef HAVE_JSON
233 Json::Value to_json() const
234 {
235 Json::Value root(Json::objectValue);
236 root["address"] = Json::Value(address);
237 root["prefix_length"] = Json::Value(prefix_length);
238 root["metric"] = Json::Value(metric);
239 root["gateway"] = Json::Value(gateway);
240 root["ipv6"] = Json::Value(ipv6);
241 root["net30"] = Json::Value(net30);
242 return root;
243 }
244
252 void from_json(const Json::Value &root, const std::string &title)
253 {
254 json::assert_dict(root, title);
255 json::to_string(root, address, "address", title);
256 json::to_uchar(root, prefix_length, "prefix_length", title);
257 json::to_int(root, metric, "metric", title);
258 json::to_string(root, gateway, "gateway", title);
259 json::to_bool(root, ipv6, "ipv6", title);
260 json::to_bool(root, net30, "net30", title);
261 }
262#endif
263
264 protected:
265 static constexpr int net30_prefix_length = 30;
266
277 void validate_(const std::string &title, const bool require_canonical) const
278 {
281 if (require_canonical && !route.is_canonical())
282 OPENVPN_THROW_EXCEPTION(title << " : not a canonical route: " << route);
283 if (!gateway.empty())
284 IP::Addr(gateway, title + ".gateway", ver);
285 if (net30 && route.prefix_len != net30_prefix_length)
286 OPENVPN_THROW_EXCEPTION(title << " : not a net30 route: " << route);
287 }
288 };
289
294 class RouteAddress : public RouteBase // may be non-canonical
295 {
296 public:
302 void validate(const std::string &title) const
303 {
304 validate_(title, false);
305 }
306 };
307
312 class Route : public RouteBase // must be canonical
313 {
314 public:
320 void validate(const std::string &title) const
321 {
322 validate_(title, true);
323 }
324 };
325
332 {
333 public:
334 std::string bypass_host;
335
340 std::string to_string() const
341 {
342 return bypass_host;
343 }
344
351 bool defined() const
352 {
353 return !bypass_host.empty();
354 }
355
363 void validate(const std::string &title) const
364 {
365 if (defined())
367 }
368
369#ifdef HAVE_JSON
375 Json::Value to_json() const
376 {
377 Json::Value root(Json::objectValue);
378 root["bypass_host"] = Json::Value(bypass_host);
379 return root;
380 }
381
388 void from_json(const Json::Value &root, const std::string &title)
389 {
390 json::assert_dict(root, title);
391 json::to_string(root, bypass_host, "bypass_host", title);
392 }
393#endif
394 };
395
403 {
404 public:
405 std::string url;
406
411 std::string to_string() const
412 {
413 return url;
414 }
415
421 bool defined() const
422 {
423 return !url.empty();
424 }
425
434 void validate(const std::string &title) const
435 {
436 try
437 {
438 if (defined())
439 (URL::Parse(url));
440 }
441 catch (const std::exception &e)
442 {
443 OPENVPN_THROW_EXCEPTION(title << " : error parsing ProxyAutoConfigURL: " << e.what());
444 }
445 }
446
447#ifdef HAVE_JSON
453 Json::Value to_json() const
454 {
455 Json::Value root(Json::objectValue);
456 root["url"] = Json::Value(url);
457 return root;
458 }
459
468 void from_json(const Json::Value &root, const std::string &title)
469 {
470 if (!json::is_dict(root, title))
471 return;
472 json::to_string(root, url, "url", title);
473 }
474#endif
475 };
476
484 {
485 public:
486 std::string host;
487 int port = 0;
488
494 std::string to_string() const
495 {
496 std::ostringstream os;
497 os << host << ' ' << port;
498 return os.str();
499 }
500
506 bool defined() const
507 {
508 return !host.empty();
509 }
510
518 void validate(const std::string &title) const
519 {
520 if (defined())
521 {
524 }
525 }
526
527#ifdef HAVE_JSON
533 Json::Value to_json() const
534 {
535 Json::Value root(Json::objectValue);
536 root["host"] = Json::Value(host);
537 root["port"] = Json::Value(port);
538 return root;
539 }
540
548 void from_json(const Json::Value &root, const std::string &title)
549 {
550 if (!json::is_dict(root, title))
551 return;
552 json::to_string(root, host, "host", title);
553 json::to_int(root, port, "port", title);
554 }
555#endif
556 };
557
565 {
566 public:
567 std::string address;
568
573 std::string to_string() const
574 {
575 std::string ret = address;
576 return ret;
577 }
578
585 void validate(const std::string &title) const
586 {
588 }
589
590#ifdef HAVE_JSON
597 Json::Value to_json() const
598 {
599 Json::Value root(Json::objectValue);
600 root["address"] = Json::Value(address);
601 return root;
602 }
603
611 void from_json(const Json::Value &root, const std::string &title)
612 {
613 json::assert_dict(root, title);
614 json::to_string(root, address, "address", title);
615 }
616#endif
617 };
618
626 bool tun_builder_set_remote_address(const std::string &address, bool ipv6) override
627 {
630 return true;
631 }
632
644 bool tun_builder_add_address(const std::string &address, int prefix_length, const std::string &gateway, bool ipv6, bool net30) override
645 {
646 RouteAddress r;
647 r.address = address;
648 r.prefix_length = static_cast<unsigned char>(prefix_length);
649 r.gateway = gateway;
650 r.ipv6 = ipv6;
651 r.net30 = net30;
652 if (ipv6)
653 tunnel_address_index_ipv6 = static_cast<int>(tunnel_addresses.size());
654 else
655 tunnel_address_index_ipv4 = static_cast<int>(tunnel_addresses.size());
656 tunnel_addresses.push_back(std::move(r));
657 return true;
658 }
659
669 bool tun_builder_reroute_gw(bool ipv4, bool ipv6, unsigned int flags) override
670 {
674 return true;
675 }
676
685 {
687 return true;
688 }
689
699 bool tun_builder_add_route(const std::string &address, int prefix_length, int metric, bool ipv6) override
700 {
701 Route r;
702 r.address = address;
703 r.prefix_length = static_cast<unsigned char>(prefix_length);
705 r.ipv6 = ipv6;
706 add_routes.push_back(std::move(r));
707 return true;
708 }
709
720 bool tun_builder_exclude_route(const std::string &address, int prefix_length, int metric, bool ipv6) override
721 {
722 Route r;
723 r.address = address;
724 r.prefix_length = static_cast<unsigned char>(prefix_length);
725 r.metric = metric;
726 r.ipv6 = ipv6;
727 exclude_routes.push_back(std::move(r));
728 return true;
729 }
730
737 bool tun_builder_set_dns_options(const DnsOptions &dns) override
738 {
739 dns_options = dns;
740 return true;
741 }
742
749 bool tun_builder_set_layer(int layer) override
750 {
751 this->layer = Layer::from_value(layer);
752 return true;
753 }
754
761 bool tun_builder_set_mtu(int mtu) override
762 {
763 this->mtu = mtu;
764 return true;
765 }
766
773 bool tun_builder_set_session_name(const std::string &name) override
774 {
775 session_name = name;
776 return true;
777 }
778
786 bool tun_builder_add_proxy_bypass(const std::string &bypass_host) override
787 {
788 ProxyBypass b;
790 proxy_bypass.push_back(std::move(b));
791 return true;
792 }
793
801 bool tun_builder_set_proxy_auto_config_url(const std::string &url) override
802 {
804 return true;
805 }
806
814 bool tun_builder_set_proxy_http(const std::string &host, int port) override
815 {
818 return true;
819 }
820
828 bool tun_builder_set_proxy_https(const std::string &host, int port) override
829 {
832 return true;
833 }
834
841 bool tun_builder_add_wins_server(const std::string &address) override
842 {
843 WINSServer wins;
844 wins.address = address;
845 wins_servers.push_back(std::move(wins));
846 return true;
847 }
848
856 bool tun_builder_set_allow_family(int af, bool allow) override
857 {
858 if (af == AF_INET)
859 block_ipv4 = !allow;
860 else if (af == AF_INET6)
861 block_ipv6 = !allow;
862 return true;
863 }
864
871 bool tun_builder_set_allow_local_dns(bool allow) override
872 {
873 block_outside_dns = !allow;
874 return true;
875 }
876
887
893 {
894 dns_options = {};
895 }
896
902 const RouteAddress *vpn_ipv4() const
903 {
906 return nullptr;
907 }
908
914 const RouteAddress *vpn_ipv6() const
915 {
918 return nullptr;
919 }
920
928 {
929 switch (v)
930 {
931 case IP::Addr::V4:
932 return vpn_ipv4();
933 case IP::Addr::V6:
934 return vpn_ipv6();
935 default:
936 return nullptr;
937 }
938 }
939
946 void validate() const
947 {
948 validate_layer("root");
949 validate_mtu("root");
950 remote_address.validate("remote_address");
951 validate_list(tunnel_addresses, "tunnel_addresses");
953 validate_list(add_routes, "add_routes");
954 validate_list(exclude_routes, "exclude_routes");
955 validate_list(proxy_bypass, "proxy_bypass");
956 proxy_auto_config_url.validate("proxy_auto_config_url");
957 http_proxy.validate("http_proxy");
958 https_proxy.validate("https_proxy");
959 }
960
968 std::string to_string() const
969 {
970 std::ostringstream os;
971 os << "Session Name: " << session_name << '\n';
972 os << "Layer: " << layer.str() << '\n';
973 if (mtu)
974 os << "MTU: " << mtu << '\n';
975 os << "Remote Address: " << remote_address.to_string() << '\n';
976 render_list(os, "Tunnel Addresses", tunnel_addresses);
977 os << "Reroute Gateway: " << reroute_gw.to_string() << '\n';
978 os << "Block IPv4: " << (block_ipv4 ? "yes" : "no") << '\n';
979 os << "Block IPv6: " << (block_ipv6 ? "yes" : "no") << '\n';
980 os << "Block local DNS: " << (block_outside_dns ? "yes" : "no") << '\n';
981 if (route_metric_default >= 0)
982 os << "Route Metric Default: " << route_metric_default << '\n';
983 render_list(os, "Add Routes", add_routes);
984 render_list(os, "Exclude Routes", exclude_routes);
985 if (!dns_options.servers.empty())
986 {
987 os << dns_options.to_string() << '\n';
988 }
989 if (!proxy_bypass.empty())
990 render_list(os, "Proxy Bypass", proxy_bypass);
992 os << "Proxy Auto Config URL: " << proxy_auto_config_url.to_string() << '\n';
993 if (http_proxy.defined())
994 os << "HTTP Proxy: " << http_proxy.to_string() << '\n';
995 if (https_proxy.defined())
996 os << "HTTPS Proxy: " << https_proxy.to_string() << '\n';
997 if (!wins_servers.empty())
998 render_list(os, "WINS Servers", wins_servers);
999 return os.str();
1000 }
1001
1002#ifdef HAVE_JSON
1003
1011 Json::Value to_json() const
1012 {
1013 Json::Value root(Json::objectValue);
1014 root["session_name"] = Json::Value(session_name);
1015 root["mtu"] = Json::Value(mtu);
1016 root["layer"] = Json::Value(layer.value());
1017 if (remote_address.defined())
1018 root["remote_address"] = remote_address.to_json();
1019 json::from_vector(root, tunnel_addresses, "tunnel_addresses");
1020 root["tunnel_address_index_ipv4"] = Json::Value(tunnel_address_index_ipv4);
1021 root["tunnel_address_index_ipv6"] = Json::Value(tunnel_address_index_ipv6);
1022 root["reroute_gw"] = reroute_gw.to_json();
1023 root["block_ipv6"] = Json::Value(block_ipv6);
1024 root["block_outside_dns"] = Json::Value(block_outside_dns);
1025 root["route_metric_default"] = Json::Value(route_metric_default);
1026 json::from_vector(root, add_routes, "add_routes");
1027 json::from_vector(root, exclude_routes, "exclude_routes");
1028 root["dns_options"] = dns_options.to_json();
1029 json::from_vector(root, wins_servers, "wins_servers");
1030 json::from_vector(root, proxy_bypass, "proxy_bypass");
1032 root["proxy_auto_config_url"] = proxy_auto_config_url.to_json();
1033 if (http_proxy.defined())
1034 root["http_proxy"] = http_proxy.to_json();
1035 if (https_proxy.defined())
1036 root["https_proxy"] = https_proxy.to_json();
1037 return root;
1038 }
1039
1049 static TunBuilderCapture::Ptr from_json(const Json::Value &root)
1050 {
1051 const std::string title = "root";
1053 json::assert_dict(root, title);
1054 json::to_string(root, tbc->session_name, "session_name", title);
1055 tbc->layer = Layer::from_value(json::get_int(root, "layer", title));
1056 json::to_int(root, tbc->mtu, "mtu", title);
1057 tbc->remote_address.from_json(root["remote_address"], "remote_address");
1058 json::to_vector(root, tbc->tunnel_addresses, "tunnel_addresses", title);
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");
1062 json::to_bool(root, tbc->block_ipv6, "block_ipv6", title);
1063 json::to_bool(root, tbc->block_outside_dns, "block_outside_dns", title);
1064 json::to_int(root, tbc->route_metric_default, "route_metric_default", title);
1065 json::to_vector(root, tbc->add_routes, "add_routes", title);
1066 json::to_vector(root, tbc->exclude_routes, "exclude_routes", title);
1067 tbc->dns_options.from_json(root["dns_options"], "dns_options");
1068 json::to_vector(root, tbc->wins_servers, "wins_servers", title);
1069 json::to_vector(root, tbc->proxy_bypass, "proxy_bypass", title);
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");
1073 return tbc;
1074 }
1075
1076#endif // HAVE_JSON
1077
1078 // builder data
1079 std::string session_name;
1080 int mtu = 0;
1082 RemoteAddress remote_address; // real address of server
1083 std::vector<RouteAddress> tunnel_addresses; // local tunnel addresses
1084 int tunnel_address_index_ipv4 = -1; // index into tunnel_addresses for IPv4 entry (or -1 if undef)
1085 int tunnel_address_index_ipv6 = -1; // index into tunnel_addresses for IPv6 entry (or -1 if undef)
1086 RerouteGW reroute_gw; // redirect-gateway info
1087 bool block_ipv4 = false; // block IPv4 traffic while VPN is active
1088 bool block_ipv6 = false; // block IPv6 traffic while VPN is active
1089 bool block_outside_dns = false; // block traffic to port 53 locally while VPN is active
1090 int route_metric_default = -1; // route-metric directive
1091 std::vector<Route> add_routes; // routes that should be added to tunnel
1092 std::vector<Route> exclude_routes; // routes that should be excluded from tunnel
1093 DnsOptions dns_options; // VPN DNS related settings from --dns option
1094
1095 std::vector<ProxyBypass> proxy_bypass; // hosts that should bypass proxy
1099
1100 std::vector<WINSServer> wins_servers; // Windows WINS servers
1101
1102 static constexpr int mtu_ipv4_maximum = 65'535;
1103
1104 private:
1114 template <typename LIST>
1115 static void render_list(std::ostream &os, const std::string &title, const LIST &list)
1116 {
1117 os << title << ':' << '\n';
1118 for (auto &e : list)
1119 {
1120 os << " " << e.to_string() << '\n';
1121 }
1122 }
1123
1132 template <typename LIST>
1133 static void validate_list(const LIST &list, const std::string &title)
1134 {
1135 int i = 0;
1136 for (auto &e : list)
1137 {
1138 e.validate(title + '[' + openvpn::to_string(i) + ']');
1139 ++i;
1140 }
1141 }
1142
1150 bool validate_tunnel_index(const int index) const
1151 {
1152 if (index == -1)
1153 return true;
1154 return index >= 0 && static_cast<unsigned int>(index) <= tunnel_addresses.size();
1155 }
1156
1165 void validate_tunnel_address_indices(const std::string &title) const
1166 {
1168 OPENVPN_THROW_EXCEPTION(title << ".tunnel_address_index_ipv4 : IPv4 tunnel address index out of range: " << tunnel_address_index_ipv4);
1170 OPENVPN_THROW_EXCEPTION(title << ".tunnel_address_index_ipv6 : IPv6 tunnel address index out of range: " << tunnel_address_index_ipv6);
1171 const RouteAddress *r4 = vpn_ipv4();
1172 if (r4 && r4->ipv6)
1173 OPENVPN_THROW_EXCEPTION(title << ".tunnel_address_index_ipv4 : IPv4 tunnel address index points to wrong address type: " << r4->to_string());
1174 const RouteAddress *r6 = vpn_ipv6();
1175 if (r6 && !r6->ipv6)
1176 OPENVPN_THROW_EXCEPTION(title << ".tunnel_address_index_ipv6 : IPv6 tunnel address index points to wrong address type: " << r6->to_string());
1177 }
1178
1186 void validate_mtu(const std::string &title) const
1187 {
1188 if (mtu < 0 || mtu > mtu_ipv4_maximum)
1189 OPENVPN_THROW_EXCEPTION(title << ".mtu : MTU out of range: " << mtu);
1190 }
1191
1199 void validate_layer(const std::string &title) const
1200 {
1201 if (!layer.defined())
1202 OPENVPN_THROW_EXCEPTION(title << ": layer undefined");
1203 }
1204};
1205} // namespace openvpn
1206
1207#endif
bool is_canonical() const
Definition route.hpp:169
unsigned int prefix_len
Definition route.hpp:38
static Layer from_value(const int value)
Definition layer.hpp:103
int value() const
Definition layer.hpp:76
const char * str() const
Definition layer.hpp:61
bool defined() const
Definition layer.hpp:43
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
Definition rc.hpp:912
std::string to_string() const
Definition rgopt.hpp:82
TunBuilder methods, loosely based on the Android VpnService.Builder abstraction.
Definition base.hpp:42
Class for handling Proxy Auto-Configuration (PAC) URLs.
Definition capture.hpp:403
void from_json(const Json::Value &root, const std::string &title)
Populates the URL from a JSON object.
Definition capture.hpp:468
bool defined() const
Checks if the URL is defined.
Definition capture.hpp:421
std::string to_string() const
Returns the URL as a string.
Definition capture.hpp:411
void validate(const std::string &title) const
Validates the URL format.
Definition capture.hpp:434
Json::Value to_json() const
Converts the URL to a JSON object.
Definition capture.hpp:453
Class for managing proxy bypass host configurations.
Definition capture.hpp:332
void from_json(const Json::Value &root, const std::string &title)
Deserializes the object from JSON.
Definition capture.hpp:388
void validate(const std::string &title) const
Validates the bypass host value.
Definition capture.hpp:363
std::string to_string() const
Converts the bypass host to a string representation.
Definition capture.hpp:340
bool defined() const
Checks if a bypass host is defined.
Definition capture.hpp:351
Json::Value to_json() const
Serializes the object to JSON.
Definition capture.hpp:375
Host and port configuration for proxy connections.
Definition capture.hpp:484
std::string to_string() const
Converts the host and port to a string representation.
Definition capture.hpp:494
void from_json(const Json::Value &root, const std::string &title)
Populates the object from a JSON representation.
Definition capture.hpp:548
void validate(const std::string &title) const
Validates the host and port.
Definition capture.hpp:518
bool defined() const
Checks if the proxy configuration is defined.
Definition capture.hpp:506
Json::Value to_json() const
Converts the object to a JSON representation.
Definition capture.hpp:533
Represents a remote IP address with IPv4/IPv6 designation.
Definition capture.hpp:55
void validate(const std::string &title) const
Validates the IP address format.
Definition capture.hpp:90
void from_json(const Json::Value &root, const std::string &title)
Deserializes the object from a JSON value.
Definition capture.hpp:116
Json::Value to_json() const
Serializes the object to a JSON value.
Definition capture.hpp:101
bool defined() const
Checks if the address is defined.
Definition capture.hpp:79
std::string to_string() const
Returns a string representation of the remote address.
Definition capture.hpp:66
Class for handling gateway rerouting configuration.
Definition capture.hpp:133
std::string to_string() const
Converts the object to a human-readable string representation.
Definition capture.hpp:145
Json::Value to_json() const
Serializes the object to a JSON value.
Definition capture.hpp:161
void from_json(const Json::Value &root, const std::string &title)
Deserializes the object from a JSON value.
Definition capture.hpp:177
Route address class that may use non-canonical form.
Definition capture.hpp:295
void validate(const std::string &title) const
Validates the route address.
Definition capture.hpp:302
Base class for route-related functionality representing a network route.
Definition capture.hpp:197
static constexpr int net30_prefix_length
Definition capture.hpp:265
void validate_(const std::string &title, const bool require_canonical) const
Protected validation method used by derived classes.
Definition capture.hpp:277
void from_json(const Json::Value &root, const std::string &title)
Deserializes the route from a JSON object.
Definition capture.hpp:252
std::string to_string() const
Converts the route to a human-readable string.
Definition capture.hpp:212
Json::Value to_json() const
Serializes the route to a JSON object.
Definition capture.hpp:233
Route class that must use canonical form.
Definition capture.hpp:313
void validate(const std::string &title) const
Validates the route.
Definition capture.hpp:320
Windows Internet Name Service (WINS) server configuration.
Definition capture.hpp:565
void validate(const std::string &title) const
Validates the WINS server address.
Definition capture.hpp:585
std::string to_string() const
Converts the WINS server to a string representation.
Definition capture.hpp:573
Json::Value to_json() const
Serializes the WINS server to a JSON object.
Definition capture.hpp:597
void from_json(const Json::Value &root, const std::string &title)
Deserializes a WINS server from a JSON object.
Definition capture.hpp:611
bool tun_builder_exclude_route(const std::string &address, int prefix_length, int metric, bool ipv6) override
Excludes a route from the tunnel.
Definition capture.hpp:720
RemoteAddress remote_address
Definition capture.hpp:1082
bool tun_builder_set_allow_family(int af, bool allow) override
Sets whether to allow a specific address family in the tunnel.
Definition capture.hpp:856
std::vector< RouteAddress > tunnel_addresses
Definition capture.hpp:1083
void validate() const
Validates the configuration of the tunnel.
Definition capture.hpp:946
bool tun_builder_add_proxy_bypass(const std::string &bypass_host) override
Adds a host to bypass proxy settings.
Definition capture.hpp:786
bool tun_builder_set_proxy_https(const std::string &host, int port) override
Sets the HTTPS proxy for the tunnel.
Definition capture.hpp:828
bool tun_builder_set_dns_options(const DnsOptions &dns) override
Set DNS options for use with tun builder.
Definition capture.hpp:737
bool tun_builder_add_route(const std::string &address, int prefix_length, int metric, bool ipv6) override
Adds a route to the tunnel.
Definition capture.hpp:699
bool tun_builder_set_allow_local_dns(bool allow) override
Sets whether to allow local DNS resolution.
Definition capture.hpp:871
bool tun_builder_set_route_metric_default(int metric) override
Sets the default route metric for VPN routes.
Definition capture.hpp:684
std::vector< Route > add_routes
Definition capture.hpp:1091
const RouteAddress * vpn_ip(const IP::Addr::Version v) const
Gets the tunnel address for the specified IP version.
Definition capture.hpp:927
static constexpr int mtu_ipv4_maximum
Definition capture.hpp:1102
ProxyAutoConfigURL proxy_auto_config_url
Definition capture.hpp:1096
void validate_layer(const std::string &title) const
Validates that the network layer is defined.
Definition capture.hpp:1199
bool tun_builder_set_session_name(const std::string &name) override
Sets a descriptive name for the VPN session.
Definition capture.hpp:773
void reset_dns_options()
Resets DNS options to default values.
Definition capture.hpp:892
bool tun_builder_set_remote_address(const std::string &address, bool ipv6) override
Sets the remote address for the TUN interface.
Definition capture.hpp:626
bool tun_builder_set_mtu(int mtu) override
Sets the Maximum Transmission Unit (MTU) for the tunnel.
Definition capture.hpp:761
static TunBuilderCapture::Ptr from_json(const Json::Value &root)
Creates a TunBuilderCapture instance from a JSON representation.
Definition capture.hpp:1049
Json::Value to_json() const
Serializes the tunnel configuration to a JSON object.
Definition capture.hpp:1011
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.
Definition capture.hpp:644
const RouteAddress * vpn_ipv6() const
Gets the IPv6 tunnel address.
Definition capture.hpp:914
bool tun_builder_set_layer(int layer) override
Sets the tunnel's network layer.
Definition capture.hpp:749
const RouteAddress * vpn_ipv4() const
Gets the IPv4 tunnel address.
Definition capture.hpp:902
bool tun_builder_set_proxy_http(const std::string &host, int port) override
Sets the HTTP proxy for the tunnel.
Definition capture.hpp:814
std::string to_string() const
Converts the tunnel configuration to a human-readable string representation.
Definition capture.hpp:968
bool tun_builder_set_proxy_auto_config_url(const std::string &url) override
Sets the URL for a proxy auto-configuration (PAC) file.
Definition capture.hpp:801
bool tun_builder_add_wins_server(const std::string &address) override
Adds a WINS server to the tunnel configuration.
Definition capture.hpp:841
std::vector< Route > exclude_routes
Definition capture.hpp:1092
bool tun_builder_reroute_gw(bool ipv4, bool ipv6, unsigned int flags) override
Configures global gateway rerouting through the VPN tunnel.
Definition capture.hpp:669
std::vector< ProxyBypass > proxy_bypass
Definition capture.hpp:1095
bool validate_tunnel_index(const int index) const
Checks if a tunnel index is valid.
Definition capture.hpp:1150
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.
Definition capture.hpp:1115
void validate_tunnel_address_indices(const std::string &title) const
Validates tunnel address indices for both IPv4 and IPv6.
Definition capture.hpp:1165
std::vector< WINSServer > wins_servers
Definition capture.hpp:1100
static void validate_list(const LIST &list, const std::string &title)
Validates each element in a list.
Definition capture.hpp:1133
void reset_tunnel_addresses()
Resets all tunnel addresses.
Definition capture.hpp:881
void validate_mtu(const std::string &title) const
Validates that the MTU value is within an acceptable range.
Definition capture.hpp:1186
#define OPENVPN_THROW_EXCEPTION(stuff)
void validate_host(const std::string &host, const std::string &title)
Definition hostport.hpp:93
void validate_port(const std::string &port, const std::string &title, unsigned int *value=nullptr)
Definition hostport.hpp:34
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)
Definition route.hpp:376
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.
Definition to_string.hpp:45
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 auto metric
reroute_gw flags
proxy_host_port port
const TunBuilderCapture::Ptr tbc(new TunBuilderCapture)
proxy_autoconfig_url url
remote_address ipv6
proxy_bypass bypass_host
proxy_host_port host
remote_address address
reroute_gw ipv4
std::string ret
std::ostringstream os