SystemD DNS fix:

when dns is port 53 call SetLinKDNS otherwise call SetLinkDNSEx as on older versions of systemd-resolved SetLinkDNSEx is not available.
pull/1741/head
Jeff Becker 3 years ago
parent cf1086e4ac
commit d1246947f7
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -87,46 +87,84 @@ namespace llarp
{ {
// This passing address by bytes and using two separate calls for ipv4/ipv6 is gross, but the // This passing address by bytes and using two separate calls for ipv4/ipv6 is gross, but the
// alternative is to build up a bunch of crap with va_args, which is slightly more gross. // alternative is to build up a bunch of crap with va_args, which is slightly more gross.
const bool isStandardDNSPort = dns.getPort() == 53;
if (dns.isIPv6()) if (dns.isIPv6())
{ {
auto ipv6 = dns.getIPv6(); auto ipv6 = dns.getIPv6();
static_assert(sizeof(ipv6) == 16); static_assert(sizeof(ipv6) == 16);
auto* a = reinterpret_cast<const uint8_t*>(&ipv6); auto* a = reinterpret_cast<const uint8_t*>(&ipv6);
resolved_call( if (isStandardDNSPort)
bus, {
"SetLinkDNSEx", resolved_call(
"ia(iayqs)", bus,
(int32_t)if_ndx, "SetLinkDNS",
(int)1, // number of "iayqs"s we are passing "ia(iay)",
(int32_t)AF_INET6, // network address type (int32_t)if_ndx,
(int)16, // network addr byte size (int)1, // number of "iayqs"s we are passing
// clang-format off (int32_t)AF_INET6, // network address type
a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], (int)16, // network addr byte size
a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], // yuck // clang-format off
// clang-format on a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7],
(uint16_t)dns.getPort(), a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15] // yuck
nullptr // dns server name (for TLS SNI which we don't care about) // clang-format on
); );
}
else
{
resolved_call(
bus,
"SetLinkDNSEx",
"ia(iayqs)",
(int32_t)if_ndx,
(int)1, // number of "iayqs"s we are passing
(int32_t)AF_INET6, // network address type
(int)16, // network addr byte size
// clang-format off
a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7],
a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], // yuck
// clang-format on
(uint16_t)dns.getPort(),
nullptr // dns server name (for TLS SNI which we don't care about)
);
}
} }
else else
{ {
auto ipv4 = dns.getIPv4(); auto ipv4 = dns.getIPv4();
static_assert(sizeof(ipv4) == 4); static_assert(sizeof(ipv4) == 4);
auto* a = reinterpret_cast<const uint8_t*>(&ipv4); auto* a = reinterpret_cast<const uint8_t*>(&ipv4);
resolved_call( if (isStandardDNSPort)
bus, {
"SetLinkDNSEx", resolved_call(
"ia(iayqs)", bus,
(int32_t)if_ndx, "SetLinkDNS",
(int)1, // number of "iayqs"s we are passing "ia(iay)",
(int32_t)AF_INET, // network address type (int32_t)if_ndx,
(int)4, // network addr byte size (int)1, // number of "iayqs"s we are passing
// clang-format off (int32_t)AF_INET, // network address type
a[0], a[1], a[2], a[3], // yuck (int)4, // network addr byte size
// clang-format on // clang-format off
(uint16_t)dns.getPort(), a[0], a[1], a[2], a[3] // yuck
nullptr // dns server name (for TLS SNI which we don't care about) // clang-format on
); );
}
else
{
resolved_call(
bus,
"SetLinkDNSEx",
"ia(iayqs)",
(int32_t)if_ndx,
(int)1, // number of "iayqs"s we are passing
(int32_t)AF_INET, // network address type
(int)4, // network addr byte size
// clang-format off
a[0], a[1], a[2], a[3], // yuck
// clang-format on
(uint16_t)dns.getPort(),
nullptr // dns server name (for TLS SNI which we don't care about)
);
}
} }
if (global) if (global)

Loading…
Cancel
Save