OpenVPN 3 Core Library
Loading...
Searching...
No Matches
addrspacesplit.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// Invert a route list. Used to support excluded routes on platforms that
13// don't support them natively.
14
15#pragma once
16
19
20namespace openvpn::IP {
22{
23 public:
24 OPENVPN_EXCEPTION(address_space_splitter);
25
27
28 // NOTE: when passing AddressSpaceSplitter to this constructor, make sure
29 // to static_cast it to RouteList& so as to avoid matching the
30 // default copy constructor.
31 explicit AddressSpaceSplitter(const RouteList &in)
33 {
34 }
35
37 {
39 if (vermask & Addr::V4_MASK)
41 if (vermask & Addr::V6_MASK)
43 }
44
45 private:
46 enum class Type
47 {
48 EQUAL,
50 LEAF,
51 };
62 void descend(const RouteList &in, const Route &route)
63 {
64 switch (find(in, route))
65 {
66 case Type::SUBROUTE:
67 {
68 Route r1, r2;
69 if (route.split(r1, r2))
70 {
71 descend(in, r1);
72 descend(in, r2);
73 }
74 else
75 push_back(route);
76 break;
77 }
78 case Type::EQUAL:
79 case Type::LEAF:
80 push_back(route);
81 break;
82 }
83 }
84
85 static Type find(const RouteList &in, const Route &route)
86 {
87 Type type = Type::LEAF;
88 for (const auto &r : in)
89 {
90 if (route == r)
91 type = Type::EQUAL;
92 else if (route.contains(r))
93 return Type::SUBROUTE;
94 }
95 return type;
96 }
97};
98} // namespace openvpn::IP
unsigned int VersionMask
Definition ip.hpp:53
static Addr from_zero(const Version v)
Definition ip.hpp:450
OPENVPN_EXCEPTION(address_space_splitter)
AddressSpaceSplitter(const RouteList &in, const Addr::VersionMask vermask)
AddressSpaceSplitter(const RouteList &in)
static Type find(const RouteList &in, const Route &route)
void descend(const RouteList &in, const Route &route)
bool split(RouteType &r1, RouteType &r2) const
Definition route.hpp:221
bool contains(const ADDR &a) const
Definition route.hpp:208
RouteType< IP::Addr > Route
Definition route.hpp:357
IP::Addr::VersionMask version_mask() const
Definition route.hpp:333
void verify_canonical() const
Definition route.hpp:341
server addresses push_back({address, port})