12#ifndef OPENVPN_SERVER_VPNSERVNETBLOCK_H
13#define OPENVPN_SERVER_VPNSERVNETBLOCK_H
39 throw vpn_serv_netblock(
"not canonical");
41 throw vpn_serv_netblock(
"need at least 4 addresses in netblock");
53 throw vpn_serv_netblock(
"override_server_gw: server gateway address is not contained by netblock");
144 const std::string &opt_name,
145 const bool ipv4_optional,
146 const unsigned int n_threads)
149 if (!ipv4_optional || opt.
exists(opt_name))
152 const IP::Addr gw(o.
get(1, 64), opt_name +
" gateway");
153 const IP::Addr nm(o.
get(2, 64), opt_name +
" netmask");
156 throw vpn_serv_netblock(opt_name +
" address is not IPv4");
160 throw vpn_serv_netblock(opt_name +
" local gateway must be first usable address of subnet");
168 IP::Route rt(o->
get(1, 64), opt_name +
"-ipv6 network");
170 throw vpn_serv_netblock(opt_name +
"-ipv6 network is not IPv6");
172 throw vpn_serv_netblock(opt_name +
"-ipv6 network is not canonical");
183 for (
unsigned int i = 0; i < n_threads; ++i)
185 if (!rp.
next(crange))
186 throw vpn_serv_netblock(opt_name +
" : unexpected ServerNetblock4 partition fail");
198 for (
unsigned int i = 0; i < n_threads; ++i)
200 if (!rp.
next(crange))
201 throw vpn_serv_netblock(opt_name +
" : unexpected ServerNetblock6 partition fail");
202 thr[i].range6_ = crange;
234 std::ostringstream
os;
238 for (
size_t i = 0; i <
thr.size(); ++i)
241 os <<
'[' << i <<
']';
253 std::vector<PerThread>
thr;
std::string to_string() const
static Addr netmask_from_prefix_len(Version v, const unsigned int prefix_len)
unsigned int prefix_len() const
divide a range of IP addresses into smaller, equal-sized partitions
bool next(RangeType< ADDR > &r)
Retrieves the next partition in the range.
designed to represent and manage a range of IP addresses.
bool defined() const
Check if the range is defined (non-empty).
std::string to_string() const
Convert the range to a string representation.
IP::Addr::Version version() const
unsigned int host_bits() const
bool is_canonical() const
const Option & get(const std::string &name) const
const Option * get_ptr(const std::string &name) const
bool exists(const std::string &name) const
const std::string & get(const size_t index, const size_t max_len) const
const IP::Range & range4() const
bool range6_defined() const
const IP::Range & range6() const
std::vector< PerThread > thr
bool netblock_contains(const IP::Addr &a) const
OPENVPN_EXCEPTION(vpn_serv_netblock)
const ClientNetblock & netblock6() const
VPNServerNetblock(const OptionList &opt, const std::string &opt_name, const bool ipv4_optional, const unsigned int n_threads)
const PerThread & per_thread(const size_t index) const
std::string to_string() const
const ClientNetblock & netblock4() const
RangeType< IP::Addr > Range
RouteType< IP::Addr > Route
std::string to_string() const
ClientNetblock(const IP::Route &route)
std::string to_string() const
Netblock(const IP::Route &route)
bool contains(const IP::Addr &a) const
void override_server_gw(const IP::Addr &gw)