when setting libunbound's upstream dns, we need to not pass in the square braces of an ipv6 address.
we also net udp handles have ipv6 address for the local ip.
pull/2180/head
Jeff Becker 1 year ago
parent 559fa8aec4
commit fc050b3a09
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D

@ -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 add_braces) 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 add_braces)
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

@ -87,7 +87,7 @@ namespace llarp
ToString() const; ToString() const;
std::string std::string
hostString() const; hostString(bool add_braces = true) const;
inline int inline int
Family() const Family() const

Loading…
Cancel
Save