Merge pull request #2180 from majestrate/fix-2179-ipv6-upstream-dns-2023-05-20

libunbound ipv6 upstream dns syntax error
pull/2141/merge
Jason Rhinelander 12 months ago committed by GitHub
commit a17753fddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -177,10 +177,7 @@ namespace llarp::dns
void void
AddUpstreamResolver(const SockAddr& dns) AddUpstreamResolver(const SockAddr& dns)
{ {
std::string str = dns.hostString(); std::string str = fmt::format("{}@{}", dns.hostString(false), dns.getPort());
if (const auto port = dns.getPort(); port != 53)
fmt::format_to(std::back_inserter(str), "@{}", port);
if (auto err = ub_ctx_set_fwd(m_ctx, str.c_str())) if (auto err = ub_ctx_set_fwd(m_ctx, str.c_str()))
{ {

@ -75,8 +75,11 @@ namespace llarp::uv
std::optional<SockAddr> std::optional<SockAddr>
LocalAddr() const override LocalAddr() const override
{ {
auto addr = handle->sock<uvw::IPv4>(); if (auto addr = handle->sock<uvw::IPv4>(); not addr.ip.empty())
return SockAddr{addr.ip, huint16_t{static_cast<uint16_t>(addr.port)}}; return SockAddr{addr.ip, huint16_t{static_cast<uint16_t>(addr.port)}};
if (auto addr = handle->sock<uvw::IPv6>(); not addr.ip.empty())
return SockAddr{addr.ip, huint16_t{static_cast<uint16_t>(addr.port)}};
return std::nullopt;
} }
std::optional<int> std::optional<int>

@ -290,25 +290,21 @@ namespace llarp
} }
std::string std::string
SockAddr::hostString() const SockAddr::hostString(bool ipv6_brackets) const
{ {
std::string str; std::array<char, 128> buf{};
char buf[INET6_ADDRSTRLEN] = {0x0};
if (isIPv4()) if (isIPv4())
{ {
// handle IPv4 mapped addrs // IPv4 mapped addrs
inet_ntop(AF_INET, &m_addr4.sin_addr.s_addr, buf, sizeof(buf)); inet_ntop(AF_INET, &m_addr4.sin_addr.s_addr, buf.data(), buf.size());
str = buf; return buf.data();
} }
else
{ inet_ntop(AF_INET6, &m_addr.sin6_addr.s6_addr, buf.data(), buf.size());
inet_ntop(AF_INET6, &m_addr.sin6_addr.s6_addr, buf, sizeof(buf)); if (not ipv6_brackets)
str.reserve(std::strlen(buf) + 2); return buf.data();
str.append("[");
str.append(buf); return fmt::format("[{}]", buf.data());
str.append("]");
}
return str;
} }
bool bool

@ -86,8 +86,10 @@ namespace llarp
std::string std::string
ToString() const; ToString() const;
/// convert ip address to string; ipv6_brackets - if true or omitted we add [...] around the
/// IPv6 address, otherwise we return it bare.
std::string std::string
hostString() const; hostString(bool ipv6_brackets = true) const;
inline int inline int
Family() const Family() const

Loading…
Cancel
Save