OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::TunBuilderCapture::RouteBase Class Reference

Base class for route-related functionality representing a network route. More...

#include <capture.hpp>

Inheritance diagram for openvpn::TunBuilderCapture::RouteBase:
[legend]

Public Member Functions

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.
 
void from_json (const Json::Value &root, const std::string &title)
 Deserializes the route from a JSON object.
 

Public Attributes

std::string address
 
unsigned char prefix_length = 0
 
int metric = -1
 
std::string gateway
 
bool ipv6 = false
 
bool net30 = false
 

Protected Member Functions

void validate_ (const std::string &title, const bool require_canonical) const
 Protected validation method used by derived classes.
 

Static Protected Attributes

static constexpr int net30_prefix_length = 30
 

Detailed Description

Base class for route-related functionality representing a network route.

This class serves as a base for route classes, providing common validation functionality. It encapsulates the components of a network route, including address, prefix length, gateway, and various options. It provides methods for string representation, JSON serialization/deserialization, and validation. The class handles both IPv4 and IPv6 routes, with special support for net30 routes commonly used in certain VPN configurations.

Definition at line 196 of file capture.hpp.

Member Function Documentation

◆ from_json()

void openvpn::TunBuilderCapture::RouteBase::from_json ( const Json::Value &  root,
const std::string &  title 
)
inline

Deserializes the route from a JSON object.

Populates the route properties from a JSON object. Throws exceptions if required fields are missing or have invalid types.

Parameters
rootThe JSON object to parse.
titleA string identifier used in error messages.

Definition at line 252 of file capture.hpp.

◆ to_json()

Json::Value openvpn::TunBuilderCapture::RouteBase::to_json ( ) const
inline

Serializes the route to a JSON object.

Creates a JSON object with keys for each route property.

Returns
A JSON object representing the route.

Definition at line 233 of file capture.hpp.

◆ to_string()

std::string openvpn::TunBuilderCapture::RouteBase::to_string ( ) const
inline

Converts the route to a human-readable string.

Formats the route in CIDR notation (address/prefix_length), including gateway, metric, IPv6 flag, and net30 flag if applicable.

Returns
A string representation of the route.

Definition at line 212 of file capture.hpp.

Here is the caller graph for this function:

◆ validate_()

void openvpn::TunBuilderCapture::RouteBase::validate_ ( const std::string &  title,
const bool  require_canonical 
) const
inlineprotected

Protected validation method used by derived classes.

Performs validation with different requirements based on the canonical flag. Checks if the route is valid and properly formatted. Validates address format, prefix length, gateway format if specified, and net30 compliance if required.

Parameters
titleA string identifier used in error messages.
require_canonicalIf true, verifies the route is in canonical form.
Exceptions
Exceptionif validation fails.

Definition at line 277 of file capture.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ address

std::string openvpn::TunBuilderCapture::RouteBase::address

Definition at line 199 of file capture.hpp.

◆ gateway

std::string openvpn::TunBuilderCapture::RouteBase::gateway

Definition at line 202 of file capture.hpp.

◆ ipv6

bool openvpn::TunBuilderCapture::RouteBase::ipv6 = false

Definition at line 203 of file capture.hpp.

◆ metric

int openvpn::TunBuilderCapture::RouteBase::metric = -1

Definition at line 201 of file capture.hpp.

◆ net30

bool openvpn::TunBuilderCapture::RouteBase::net30 = false

Definition at line 204 of file capture.hpp.

◆ net30_prefix_length

constexpr int openvpn::TunBuilderCapture::RouteBase::net30_prefix_length = 30
staticconstexprprotected

Definition at line 265 of file capture.hpp.

◆ prefix_length

unsigned char openvpn::TunBuilderCapture::RouteBase::prefix_length = 0

Definition at line 200 of file capture.hpp.


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