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,
114 const std::string &directive,
121 reserve(opt_list->size());
122 for (
auto i : *opt_list)
127 unsigned int mult = 1;
128 unsigned int local = 0;
150 const std::string title = e.
directive +
" protocol";
161 const std::string title = e.
directive +
" addr";
167 int n_threads_exists = 0;
169 const std::string ntstr = o.
get_optional(4 - local, 16);
171 n_threads_exists = 1;
173 if (n_threads_exists)
175 std::string n_threads = o.
get(4 - local, 16);
176 if (n_threads.ends_with(
"*N"))
179 n_threads = n_threads.substr(0, n_threads.length() - 2);
181 if (!parse_number_validate<unsigned int>(n_threads, 3, 1, 100, &e.
n_threads))
183#ifndef OPENVPN_PLATFORM_WIN
185 OPENVPN_THROW(option_error, e.
directive <<
": local socket only supports one thread per pathname (not " << n_threads <<
')');
193 if (o.
size() >= 5 - local + n_threads_exists)
195 const std::string &ssl_qualifier = o.
get(4 - local + n_threads_exists, 16);
196 if (ssl_qualifier ==
"ssl")
202 else if (ssl_qualifier ==
"!ssl")
204#ifdef OPENVPN_POLYSOCK_SUPPORTS_ALT_ROUTING
205 else if (ssl_qualifier ==
"alt")
206 e.
ssl = Item::AltRouting;
263 OPENVPN_THROW(option_error,
"no " << directive <<
" directives found");
268 unsigned int ret = 0;
269 for (
auto &i : *
this)
277 for (
auto &i : *
this)
279 ret += i.to_string();
287 for (
auto &i : *
this)
288 if (i.proto.is_local())
290 return std::string();
296 for (
const auto &e : *
this)
298 unsigned int offset = 0;
301 if (
ret.size() >= max_size)
302 OPENVPN_THROW(option_error, e.directive <<
": max_size=" << max_size <<
" exceeded");
303 ret.emplace_back(e.port_offset(offset));
304 }
while (++offset < e.n_threads);
312 for (
const auto &e : *
this)
313 ret.emplace_back(e.port_offset(unit));
321#ifdef VPN_BINDING_PROFILES
322 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)
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)