Commit 1e280bd8 authored by abousselmi's avatar abousselmi

Allow using FQDN along with IPv4 and IPv6

This allows a name resolution attempt before checking IP versions.
GetHostByName is already implemented but never been used. When used
against an IP, it will yield the same IP. Therefore no regression
would be implied by this.

When the name resolution returns multiple IPv4 and IPv6 addresses,
GetHostByName only returns the first element of the list which
potentially is going to be an IPv4. This is not very convenient to
have inside GetIp6, but the user can always specify manually the
IPv6 to be used in the config file.
parent b8c86919
...@@ -146,15 +146,17 @@ std::string GetIp4(const YAML::Node &node, const std::string &name) ...@@ -146,15 +146,17 @@ std::string GetIp4(const YAML::Node &node, const std::string &name)
{ {
std::string s = GetString(node, name); std::string s = GetString(node, name);
s = io::GetHostByName(s);
int version = utils::GetIpVersion(s); int version = utils::GetIpVersion(s);
if (version == 6) if (version == 6)
FieldError(name, "must be a valid IPv4 address or a valid network interface with a IPv4 address"); FieldError(name, "must be a valid IPv4 address, FQDN or a valid network interface with a IPv4 address");
if (version == 4) if (version == 4)
return s; return s;
auto ipFromIf = io::GetIp4OfInterface(s); auto ipFromIf = io::GetIp4OfInterface(s);
if (ipFromIf.empty()) if (ipFromIf.empty())
FieldError(name, "must be a valid IPv4 address or a valid network interface with a IPv4 address"); FieldError(name, "must be a valid IPv4 address, FQDN or a valid network interface with a IPv4 address");
return ipFromIf; return ipFromIf;
} }
...@@ -162,15 +164,17 @@ std::string GetIp6(const YAML::Node &node, const std::string &name) ...@@ -162,15 +164,17 @@ std::string GetIp6(const YAML::Node &node, const std::string &name)
{ {
std::string s = GetString(node, name); std::string s = GetString(node, name);
s = io::GetHostByName(s);
int version = utils::GetIpVersion(s); int version = utils::GetIpVersion(s);
if (version == 4) if (version == 4)
FieldError(name, "must be a valid IPv6 address or a valid network interface with a IPv6 address"); FieldError(name, "must be a valid IPv6 address, FQDN or a valid network interface with a IPv6 address");
if (version == 6) if (version == 6)
return s; return s;
auto ipFromIf = io::GetIp6OfInterface(s); auto ipFromIf = io::GetIp6OfInterface(s);
if (ipFromIf.empty()) if (ipFromIf.empty())
FieldError(name, "must be a valid IPv6 address or a valid network interface with a IPv6 address"); FieldError(name, "must be a valid IPv6 address, FQDN or a valid network interface with a IPv6 address");
return ipFromIf; return ipFromIf;
} }
...@@ -178,6 +182,8 @@ std::string GetIp(const YAML::Node &node, const std::string & name) ...@@ -178,6 +182,8 @@ std::string GetIp(const YAML::Node &node, const std::string & name)
{ {
std::string s = GetString(node, name); std::string s = GetString(node, name);
s = io::GetHostByName(s);
int version = utils::GetIpVersion(s); int version = utils::GetIpVersion(s);
if (version == 6 || version == 4) if (version == 6 || version == 4)
return s; return s;
...@@ -187,7 +193,7 @@ std::string GetIp(const YAML::Node &node, const std::string & name) ...@@ -187,7 +193,7 @@ std::string GetIp(const YAML::Node &node, const std::string & name)
auto ip6FromIf = io::GetIp6OfInterface(s); auto ip6FromIf = io::GetIp6OfInterface(s);
if (!ip6FromIf.empty()) if (!ip6FromIf.empty())
return ip6FromIf; return ip6FromIf;
FieldError(name, "must be a valid IP address or a valid network interface with an IP address"); FieldError(name, "must be a valid IP address, FQDN or a valid network interface with an IP address");
} }
void AssertHasBool(const YAML::Node &node, const std::string &name) void AssertHasBool(const YAML::Node &node, const std::string &name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment