12#ifndef OPENVPN_SERVER_LISTENLIST_H
13#define OPENVPN_SERVER_LISTENLIST_H
38#ifdef OPENVPN_POLYSOCK_SUPPORTS_ALT_ROUTING
67#ifdef OPENVPN_POLYSOCK_SUPPORTS_ALT_ROUTING
79 if (
ret.proto.is_unix())
88class List :
public std::vector<Item>
96#ifdef VPN_BINDING_PROFILES
97 AllowVPNBindingProfile,
116 const std::string &directive,
123 reserve(opt_list->size());
124 for (
auto i : *opt_list)
129 unsigned int mult = 1;
130 unsigned int local = 0;
152 const std::string title = e.
directive +
" protocol";
163 const std::string title = e.
directive +
" addr";
169 int n_threads_exists = 0;
171 const std::string ntstr = o.
get_optional(4 - local, 16);
173 n_threads_exists = 1;
175 if (n_threads_exists)
177 std::string n_threads = o.
get(4 - local, 16);
181 n_threads = n_threads.substr(0, n_threads.length() - 2);
183 if (!parse_number_validate<unsigned int>(n_threads, 3, 1, 100, &e.
n_threads))
185#ifndef OPENVPN_PLATFORM_WIN
187 OPENVPN_THROW(option_error, e.
directive <<
": local socket only supports one thread per pathname (not " << n_threads <<
')');
195 if (o.
size() >= 5 - local + n_threads_exists)
197 const std::string &ssl_qualifier = o.
get(4 - local + n_threads_exists, 16);
198 if (ssl_qualifier ==
"ssl")
204 else if (ssl_qualifier ==
"!ssl")
206#ifdef OPENVPN_POLYSOCK_SUPPORTS_ALT_ROUTING
207 else if (ssl_qualifier ==
"alt")
208 e.
ssl = Item::AltRouting;
265 OPENVPN_THROW(option_error,
"no " << directive <<
" directives found");
270 unsigned int ret = 0;
271 for (
auto &i : *
this)
279 for (
auto &i : *
this)
281 ret += i.to_string();
289 for (
auto &i : *
this)
290 if (i.proto.is_local())
292 return std::string();
298 for (
const auto &e : *
this)
300 unsigned int offset = 0;
303 if (
ret.size() >= max_size)
304 OPENVPN_THROW(option_error, e.directive <<
": max_size=" << max_size <<
" exceeded");
305 ret.emplace_back(e.port_offset(offset));
306 }
while (++offset < e.n_threads);
314 for (
const auto &e : *
this)
315 ret.emplace_back(e.port_offset(unit));
323#ifdef VPN_BINDING_PROFILES
324 return load_mode == AllowVPNBindingProfile
std::string local_addr() const
List expand_ports_by_n_threads(const size_t max_size) const
unsigned int total_threads() const
std::string to_string() const
List expand_ports_by_unit(const unsigned int unit) const
List(const OptionList &opt, const std::string &directive, const LoadMode load_mode, const unsigned int n_cores)
static bool is_vpn_binding_profile(const LoadMode load_mode, const Item &e)
const IndexList * get_index_ptr(const std::string &name) const
const Option * get_ptr(const std::string &name) const
std::string get_optional(const size_t index, const size_t max_len) const
void touch(bool lightly=false) const
const std::string & get(const size_t index, const size_t max_len) const
static bool is_local_type(const std::string &str)
void mod_addr_version(const IP::Addr::Version ip_version)
static Protocol parse(const std::string &str, const AllowSuffix allow_suffix, const char *title=nullptr)
#define OPENVPN_THROW(exc, stuff)
void validate_port(const std::string &port, const std::string &title, unsigned int *value=nullptr)
unsigned short parse_port(const std::string &port, const std::string &title)
bool is_digit(const char c)
bool ends_with(const STRING &str, const std::string &suffix)
std::string to_string(const T &t)
Convert a value to a string.
std::string printfmt(const std::string &fmt, Args... args)
Item port_offset(const unsigned int offset) const
std::string to_string() const
server addresses push_back({address, port})