14#ifndef OPENVPN_NETCONF_LINUX_GW_H
15#define OPENVPN_NETCONF_LINUX_GW_H
33 LinuxGW(
const std::string &ip_route_show_txt,
const bool ignore_errors)
35 int best_metric = std::numeric_limits<int>::max();
40 const std::string &line = sl.
line_ref();
52 if (v[0] !=
"default")
66 int m = std::numeric_limits<int>::max();
68 RouteInfo ri = INITIAL;
69 for (
const auto &term : v)
76 else if (term ==
"dev")
78 else if (term ==
"metric")
92 m = parse_number_throw<int>(term,
"bad metric");
99 if (m < best_metric || best_metric == std::numeric_limits<int>::max())
106 catch (
const std::exception &e)
109 OPENVPN_THROW(linux_gw_error,
"error parsing line: " << line <<
" : " << e.what());
118 argv.emplace_back(
"/sbin/ip");
120 argv.emplace_back(
"-6");
121 argv.emplace_back(
"route");
122 argv.emplace_back(
"show");
123 const int status =
system_cmd(argv[0], argv,
nullptr, pipe, 0,
nullptr);
129 const std::string &
dev()
const
164 :
v4(
LinuxGW::ip_route_show(false), ignore_errors),
165 v6(
LinuxGW::ip_route_show(true), ignore_errors)
171 std::string
ret =
"[";
195 throw LinuxGW::linux_gw_error(
"cannot determine gateway interface");
std::string to_string() const
std::string to_string() const
LinuxGW(const std::string &ip_route_show_txt, const bool ignore_errors)
std::string to_string() const
OPENVPN_EXCEPTION(linux_gw_error)
const IP::Addr & addr() const
const std::string & dev() const
static std::string ip_route_show(const bool ipv6)
std::string validate_dev(const std::string &dev)
#define OPENVPN_THROW_EXCEPTION(stuff)
#define OPENVPN_THROW(exc, stuff)
int system_cmd(const std::string &cmd, const Argv &argv, RedirectBase *redir, const Environ *env, const sigset_t *sigmask)
std::string to_string() const
LinuxGW46(const bool ignore_errors)