| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "alloc-util.h" |
| 4 |
#include "dns-answer.h" |
| 5 |
#include "dns-domain.h" |
| 6 |
#include "dns-packet.h" |
| 7 |
#include "dns-question.h" |
| 8 |
#include "dns-rr.h" |
| 9 |
#include "dns-type.h" |
| 10 |
#include "env-util.h" |
| 11 |
#include "hostname-util.h" |
| 12 |
#include "local-addresses.h" |
| 13 |
#include "log.h" |
| 14 |
#include "missing-network.h" |
| 15 |
#include "resolved-def.h" |
| 16 |
#include "resolved-dns-synthesize.h" |
| 17 |
#include "resolved-manager.h" |
| 18 |
#include "socket-util.h" |
| 19 |
|
| 20 |
int dns_synthesize_family(uint64_t flags) { |
| 21 |
|
| 22 |
/* Picks an address family depending on set flags. This is |
| 23 |
* purely for synthesized answers, where the family we return |
| 24 |
* for the reply should match what was requested in the |
| 25 |
* question, even though we are synthesizing the answer |
| 26 |
* here. */ |
| 27 |
|
| 28 |
if (!(flags & SD_RESOLVED_DNS)) { |
| 29 |
if (flags & (SD_RESOLVED_LLMNR_IPV4|SD_RESOLVED_MDNS_IPV4)) |
| 30 |
return AF_INET; |
| 31 |
if (flags & (SD_RESOLVED_LLMNR_IPV6|SD_RESOLVED_MDNS_IPV6)) |
| 32 |
return AF_INET6; |
| 33 |
} |
| 34 |
|
| 35 |
return AF_UNSPEC; |
| 36 |
} |
| 37 |
|
| 38 |
DnsProtocol dns_synthesize_protocol(uint64_t flags) { |
| 39 |
|
| 40 |
/* Similar as dns_synthesize_family() but does this for the |
| 41 |
* protocol. If resolving via DNS was requested, we claim it |
| 42 |
* was DNS. Similar, if nothing specific was |
| 43 |
* requested. However, if only resolving via LLMNR was |
| 44 |
* requested we return that. */ |
| 45 |
|
| 46 |
if (flags & SD_RESOLVED_DNS) |
| 47 |
return DNS_PROTOCOL_DNS; |
| 48 |
if (flags & SD_RESOLVED_LLMNR) |
| 49 |
return DNS_PROTOCOL_LLMNR; |
| 50 |
if (flags & SD_RESOLVED_MDNS) |
| 51 |
return DNS_PROTOCOL_MDNS; |
| 52 |
|
| 53 |
return DNS_PROTOCOL_DNS; |
| 54 |
} |
| 55 |
|
| 56 |
static int synthesize_localhost_rr(Manager *m, const DnsResourceKey *key, DnsAnswer **answer) { |
| 57 |
int r; |
| 58 |
|
| 59 |
assert(m); |
| 60 |
assert(key); |
| 61 |
assert(answer); |
| 62 |
|
| 63 |
r = dns_answer_reserve(answer, 2); |
| 64 |
if (r < 0) |
| 65 |
return r; |
| 66 |
|
| 67 |
if (IN_SET(key->type, DNS_TYPE_A, DNS_TYPE_ANY)) { |
| 68 |
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; |
| 69 |
|
| 70 |
rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, dns_resource_key_name(key)); |
| 71 |
if (!rr) |
| 72 |
return -ENOMEM; |
| 73 |
|
| 74 |
rr->a.in_addr.s_addr = htobe32(INADDR_LOOPBACK); |
| 75 |
|
| 76 |
r = dns_answer_add(*answer, rr, LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED, NULL); |
| 77 |
if (r < 0) |
| 78 |
return r; |
| 79 |
} |
| 80 |
|
| 81 |
if (IN_SET(key->type, DNS_TYPE_AAAA, DNS_TYPE_ANY) && socket_ipv6_is_enabled()) { |
| 82 |
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; |
| 83 |
|
| 84 |
rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_AAAA, dns_resource_key_name(key)); |
| 85 |
if (!rr) |
| 86 |
return -ENOMEM; |
| 87 |
|
| 88 |
rr->aaaa.in6_addr = in6addr_loopback; |
| 89 |
|
| 90 |
r = dns_answer_add(*answer, rr, LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED, NULL); |
| 91 |
if (r < 0) |
| 92 |
return r; |
| 93 |
} |
| 94 |
|
| 95 |
return 0; |
| 96 |
} |
| 97 |
|
| 98 |
static int answer_add_ptr(DnsAnswer **answer, const char *from, const char *to, int ifindex, DnsAnswerFlags flags) { |
| 99 |
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; |
| 100 |
|
| 101 |
assert(answer); |
| 102 |
|
| 103 |
rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_PTR, from); |
| 104 |
if (!rr) |
| 105 |
return -ENOMEM; |
| 106 |
|
| 107 |
rr->ptr.name = strdup(to); |
| 108 |
if (!rr->ptr.name) |
| 109 |
return -ENOMEM; |
| 110 |
|
| 111 |
return dns_answer_add(*answer, rr, ifindex, flags, NULL); |
| 112 |
} |
| 113 |
|
| 114 |
static int synthesize_localhost_ptr(Manager *m, const DnsResourceKey *key, DnsAnswer **answer) { |
| 115 |
int r; |
| 116 |
|
| 117 |
assert(m); |
| 118 |
assert(key); |
| 119 |
assert(answer); |
| 120 |
|
| 121 |
if (IN_SET(key->type, DNS_TYPE_PTR, DNS_TYPE_ANY)) { |
| 122 |
r = dns_answer_reserve(answer, 1); |
| 123 |
if (r < 0) |
| 124 |
return r; |
| 125 |
|
| 126 |
r = answer_add_ptr(answer, dns_resource_key_name(key), "localhost", LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED); |
| 127 |
if (r < 0) |
| 128 |
return r; |
| 129 |
} |
| 130 |
|
| 131 |
return 0; |
| 132 |
} |
| 133 |
|
| 134 |
static int answer_add_addresses_rr( |
| 135 |
DnsAnswer **answer, |
| 136 |
const char *name, |
| 137 |
struct local_address *addresses, |
| 138 |
unsigned n_addresses) { |
| 139 |
|
| 140 |
unsigned j; |
| 141 |
int r; |
| 142 |
|
| 143 |
assert(answer); |
| 144 |
assert(name); |
| 145 |
|
| 146 |
r = dns_answer_reserve(answer, n_addresses); |
| 147 |
if (r < 0) |
| 148 |
return r; |
| 149 |
|
| 150 |
for (j = 0; j < n_addresses; j++) { |
| 151 |
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; |
| 152 |
|
| 153 |
r = dns_resource_record_new_address(&rr, addresses[j].family, &addresses[j].address, name); |
| 154 |
if (r < 0) |
| 155 |
return r; |
| 156 |
|
| 157 |
r = dns_answer_add(*answer, rr, addresses[j].ifindex, DNS_ANSWER_AUTHENTICATED, NULL); |
| 158 |
if (r < 0) |
| 159 |
return r; |
| 160 |
} |
| 161 |
|
| 162 |
return 0; |
| 163 |
} |
| 164 |
|
| 165 |
static int answer_add_addresses_ptr( |
| 166 |
DnsAnswer **answer, |
| 167 |
const char *name, |
| 168 |
struct local_address *addresses, |
| 169 |
unsigned n_addresses, |
| 170 |
int af, const union in_addr_union *match) { |
| 171 |
|
| 172 |
bool added = false; |
| 173 |
unsigned j; |
| 174 |
int r; |
| 175 |
|
| 176 |
assert(answer); |
| 177 |
assert(name); |
| 178 |
|
| 179 |
for (j = 0; j < n_addresses; j++) { |
| 180 |
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; |
| 181 |
|
| 182 |
if (af != AF_UNSPEC) { |
| 183 |
|
| 184 |
if (addresses[j].family != af) |
| 185 |
continue; |
| 186 |
|
| 187 |
if (match && !in_addr_equal(af, match, &addresses[j].address)) |
| 188 |
continue; |
| 189 |
} |
| 190 |
|
| 191 |
r = dns_answer_reserve(answer, 1); |
| 192 |
if (r < 0) |
| 193 |
return r; |
| 194 |
|
| 195 |
r = dns_resource_record_new_reverse(&rr, addresses[j].family, &addresses[j].address, name); |
| 196 |
if (r < 0) |
| 197 |
return r; |
| 198 |
|
| 199 |
r = dns_answer_add(*answer, rr, addresses[j].ifindex, DNS_ANSWER_AUTHENTICATED, NULL); |
| 200 |
if (r < 0) |
| 201 |
return r; |
| 202 |
|
| 203 |
added = true; |
| 204 |
} |
| 205 |
|
| 206 |
return added; |
| 207 |
} |
| 208 |
|
| 209 |
static int synthesize_system_hostname_rr(Manager *m, const DnsResourceKey *key, int ifindex, DnsAnswer **answer) { |
| 210 |
_cleanup_free_ struct local_address *addresses = NULL; |
| 211 |
int n = 0, af; |
| 212 |
|
| 213 |
assert(m); |
| 214 |
assert(key); |
| 215 |
assert(answer); |
| 216 |
|
| 217 |
af = dns_type_to_af(key->type); |
| 218 |
if (af >= 0) { |
| 219 |
n = local_addresses(m->rtnl, ifindex, af, &addresses); |
| 220 |
if (n < 0) |
| 221 |
return n; |
| 222 |
|
| 223 |
if (n == 0) { |
| 224 |
struct local_address buffer[2]; |
| 225 |
|
| 226 |
/* If we have no local addresses then use ::1 and 127.0.0.2 as local ones. */ |
| 227 |
|
| 228 |
if (IN_SET(af, AF_INET, AF_UNSPEC)) |
| 229 |
buffer[n++] = (struct local_address) { |
| 230 |
.family = AF_INET, |
| 231 |
.ifindex = LOOPBACK_IFINDEX, |
| 232 |
.address.in.s_addr = htobe32(INADDR_LOCALADDRESS), |
| 233 |
}; |
| 234 |
|
| 235 |
if (IN_SET(af, AF_INET6, AF_UNSPEC) && socket_ipv6_is_enabled()) |
| 236 |
buffer[n++] = (struct local_address) { |
| 237 |
.family = AF_INET6, |
| 238 |
.ifindex = LOOPBACK_IFINDEX, |
| 239 |
.address.in6 = in6addr_loopback, |
| 240 |
}; |
| 241 |
|
| 242 |
return answer_add_addresses_rr(answer, |
| 243 |
dns_resource_key_name(key), |
| 244 |
buffer, n); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
return answer_add_addresses_rr(answer, dns_resource_key_name(key), addresses, n); |
| 249 |
} |
| 250 |
|
| 251 |
static int synthesize_system_hostname_ptr(Manager *m, int af, const union in_addr_union *address, int ifindex, DnsAnswer **answer) { |
| 252 |
_cleanup_free_ struct local_address *addresses = NULL; |
| 253 |
bool added = false; |
| 254 |
int n, r; |
| 255 |
|
| 256 |
assert(m); |
| 257 |
assert(address); |
| 258 |
assert(answer); |
| 259 |
|
| 260 |
if (af == AF_INET && address->in.s_addr == htobe32(INADDR_LOCALADDRESS)) { |
| 261 |
|
| 262 |
/* Always map the IPv4 address 127.0.0.2 to the local hostname, in addition to "localhost": */ |
| 263 |
|
| 264 |
r = dns_answer_reserve(answer, 4); |
| 265 |
if (r < 0) |
| 266 |
return r; |
| 267 |
|
| 268 |
r = answer_add_ptr(answer, "2.0.0.127.in-addr.arpa", m->full_hostname, LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED); |
| 269 |
if (r < 0) |
| 270 |
return r; |
| 271 |
|
| 272 |
r = answer_add_ptr(answer, "2.0.0.127.in-addr.arpa", m->llmnr_hostname, LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED); |
| 273 |
if (r < 0) |
| 274 |
return r; |
| 275 |
|
| 276 |
r = answer_add_ptr(answer, "2.0.0.127.in-addr.arpa", m->mdns_hostname, LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED); |
| 277 |
if (r < 0) |
| 278 |
return r; |
| 279 |
|
| 280 |
r = answer_add_ptr(answer, "2.0.0.127.in-addr.arpa", "localhost", LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED); |
| 281 |
if (r < 0) |
| 282 |
return r; |
| 283 |
|
| 284 |
return 1; |
| 285 |
} |
| 286 |
|
| 287 |
n = local_addresses(m->rtnl, ifindex, af, &addresses); |
| 288 |
if (n <= 0) |
| 289 |
return n; |
| 290 |
|
| 291 |
r = answer_add_addresses_ptr(answer, m->full_hostname, addresses, n, af, address); |
| 292 |
if (r < 0) |
| 293 |
return r; |
| 294 |
if (r > 0) |
| 295 |
added = true; |
| 296 |
|
| 297 |
r = answer_add_addresses_ptr(answer, m->llmnr_hostname, addresses, n, af, address); |
| 298 |
if (r < 0) |
| 299 |
return r; |
| 300 |
if (r > 0) |
| 301 |
added = true; |
| 302 |
|
| 303 |
r = answer_add_addresses_ptr(answer, m->mdns_hostname, addresses, n, af, address); |
| 304 |
if (r < 0) |
| 305 |
return r; |
| 306 |
if (r > 0) |
| 307 |
added = true; |
| 308 |
|
| 309 |
return added; |
| 310 |
} |
| 311 |
|
| 312 |
static int synthesize_gateway_rr( |
| 313 |
Manager *m, |
| 314 |
const DnsResourceKey *key, |
| 315 |
int ifindex, |
| 316 |
int (*lookup)(sd_netlink *context, int ifindex, int af, struct local_address **ret), /* either local_gateways() or local_outbound() */ |
| 317 |
DnsAnswer **answer) { |
| 318 |
_cleanup_free_ struct local_address *addresses = NULL; |
| 319 |
int n = 0, af, r; |
| 320 |
|
| 321 |
assert(m); |
| 322 |
assert(key); |
| 323 |
assert(lookup); |
| 324 |
assert(answer); |
| 325 |
|
| 326 |
af = dns_type_to_af(key->type); |
| 327 |
if (af >= 0) { |
| 328 |
n = lookup(m->rtnl, ifindex, af, &addresses); |
| 329 |
if (n < 0) /* < 0 means: error */ |
| 330 |
return n; |
| 331 |
|
| 332 |
if (n == 0) { /* == 0 means we have no gateway */ |
| 333 |
/* See if there's a gateway on the other protocol */ |
| 334 |
if (af == AF_INET) |
| 335 |
n = lookup(m->rtnl, ifindex, AF_INET6, NULL); |
| 336 |
else { |
| 337 |
assert(af == AF_INET6); |
| 338 |
n = lookup(m->rtnl, ifindex, AF_INET, NULL); |
| 339 |
} |
| 340 |
if (n <= 0) /* error (if < 0) or really no gateway at all (if == 0) */ |
| 341 |
return n; |
| 342 |
|
| 343 |
/* We have a gateway on the other protocol. Let's return > 0 without adding any RR to |
| 344 |
* the answer, i.e. synthesize NODATA (and not NXDOMAIN!) */ |
| 345 |
return 1; |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
r = answer_add_addresses_rr(answer, dns_resource_key_name(key), addresses, n); |
| 350 |
if (r < 0) |
| 351 |
return r; |
| 352 |
|
| 353 |
return 1; /* > 0 means: we have some gateway */ |
| 354 |
} |
| 355 |
|
| 356 |
static int synthesize_dns_stub_rr( |
| 357 |
Manager *m, |
| 358 |
const DnsResourceKey *key, |
| 359 |
in_addr_t addr, |
| 360 |
DnsAnswer **answer) { |
| 361 |
|
| 362 |
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; |
| 363 |
int r; |
| 364 |
|
| 365 |
assert(m); |
| 366 |
assert(key); |
| 367 |
assert(answer); |
| 368 |
|
| 369 |
if (!IN_SET(key->type, DNS_TYPE_A, DNS_TYPE_ANY)) |
| 370 |
return 1; /* we still consider ourselves the owner of this name */ |
| 371 |
|
| 372 |
r = dns_answer_reserve(answer, 1); |
| 373 |
if (r < 0) |
| 374 |
return r; |
| 375 |
|
| 376 |
rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, dns_resource_key_name(key)); |
| 377 |
if (!rr) |
| 378 |
return -ENOMEM; |
| 379 |
|
| 380 |
rr->a.in_addr.s_addr = htobe32(addr); |
| 381 |
|
| 382 |
r = dns_answer_add(*answer, rr, LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED, NULL); |
| 383 |
if (r < 0) |
| 384 |
return r; |
| 385 |
|
| 386 |
return 1; |
| 387 |
} |
| 388 |
|
| 389 |
static int synthesize_dns_stub_ptr( |
| 390 |
Manager *m, |
| 391 |
int af, |
| 392 |
const union in_addr_union *address, |
| 393 |
DnsAnswer **answer) { |
| 394 |
|
| 395 |
int r; |
| 396 |
|
| 397 |
assert(m); |
| 398 |
assert(address); |
| 399 |
assert(answer); |
| 400 |
|
| 401 |
if (af != AF_INET) |
| 402 |
return 0; |
| 403 |
|
| 404 |
if (address->in.s_addr == htobe32(INADDR_DNS_STUB)) { |
| 405 |
|
| 406 |
r = dns_answer_reserve(answer, 1); |
| 407 |
if (r < 0) |
| 408 |
return r; |
| 409 |
|
| 410 |
r = answer_add_ptr(answer, "53.0.0.127.in-addr.arpa", "_localdnsstub", LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED); |
| 411 |
if (r < 0) |
| 412 |
return r; |
| 413 |
|
| 414 |
return 1; |
| 415 |
} |
| 416 |
|
| 417 |
if (address->in.s_addr == htobe32(INADDR_DNS_PROXY_STUB)) { |
| 418 |
|
| 419 |
r = dns_answer_reserve(answer, 1); |
| 420 |
if (r < 0) |
| 421 |
return r; |
| 422 |
|
| 423 |
r = answer_add_ptr(answer, "54.0.0.127.in-addr.arpa", "_localdnsproxy", LOOPBACK_IFINDEX, DNS_ANSWER_AUTHENTICATED); |
| 424 |
if (r < 0) |
| 425 |
return r; |
| 426 |
|
| 427 |
return 1; |
| 428 |
} |
| 429 |
|
| 430 |
return 0; |
| 431 |
} |
| 432 |
|
| 433 |
static int synthesize_gateway_ptr( |
| 434 |
Manager *m, |
| 435 |
int af, |
| 436 |
const union in_addr_union *address, |
| 437 |
int ifindex, |
| 438 |
DnsAnswer **answer) { |
| 439 |
|
| 440 |
_cleanup_free_ struct local_address *addresses = NULL; |
| 441 |
int n; |
| 442 |
|
| 443 |
assert(m); |
| 444 |
assert(address); |
| 445 |
assert(answer); |
| 446 |
|
| 447 |
n = local_gateways(m->rtnl, ifindex, af, &addresses); |
| 448 |
if (n <= 0) |
| 449 |
return n; |
| 450 |
|
| 451 |
return answer_add_addresses_ptr(answer, "_gateway", addresses, n, af, address); |
| 452 |
} |
| 453 |
|
| 454 |
bool shall_synthesize_own_hostname_rrs(void) { |
| 455 |
static int cached = -1; |
| 456 |
int r; |
| 457 |
|
| 458 |
if (cached >= 0) |
| 459 |
return cached; |
| 460 |
|
| 461 |
r = secure_getenv_bool("SYSTEMD_RESOLVED_SYNTHESIZE_HOSTNAME"); |
| 462 |
if (r < 0 && r != -ENXIO) |
| 463 |
log_debug_errno(r, "Failed to parse $SYSTEMD_RESOLVED_SYNTHESIZE_HOSTNAME: %m"); |
| 464 |
|
| 465 |
return (cached = (r != 0)); |
| 466 |
} |
| 467 |
|
| 468 |
int dns_synthesize_answer( |
| 469 |
Manager *m, |
| 470 |
DnsQuestion *q, |
| 471 |
int ifindex, |
| 472 |
DnsAnswer **ret) { |
| 473 |
|
| 474 |
_cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL; |
| 475 |
DnsResourceKey *key; |
| 476 |
bool found = false, nxdomain = false; |
| 477 |
int r; |
| 478 |
|
| 479 |
assert(m); |
| 480 |
assert(q); |
| 481 |
|
| 482 |
DNS_QUESTION_FOREACH(key, q) { |
| 483 |
union in_addr_union address; |
| 484 |
const char *name; |
| 485 |
int af; |
| 486 |
|
| 487 |
if (!IN_SET(key->class, DNS_CLASS_IN, DNS_CLASS_ANY)) |
| 488 |
continue; |
| 489 |
|
| 490 |
name = dns_resource_key_name(key); |
| 491 |
|
| 492 |
if (dns_name_is_root(name) || dns_name_endswith(name, "resolver.arpa") > 0) { |
| 493 |
/* Do nothing. */ |
| 494 |
|
| 495 |
} else if (dns_name_dont_resolve(name)) { |
| 496 |
/* Synthesize NXDOMAIN for some of the domains in RFC6303 + RFC6761 */ |
| 497 |
nxdomain = true; |
| 498 |
continue; |
| 499 |
|
| 500 |
} else if (is_localhost(name)) { |
| 501 |
|
| 502 |
r = synthesize_localhost_rr(m, key, &answer); |
| 503 |
if (r < 0) |
| 504 |
return log_error_errno(r, "Failed to synthesize localhost RRs: %m"); |
| 505 |
|
| 506 |
} else if (manager_is_own_hostname(m, name)) { |
| 507 |
|
| 508 |
if (!shall_synthesize_own_hostname_rrs()) |
| 509 |
continue; |
| 510 |
|
| 511 |
r = synthesize_system_hostname_rr(m, key, ifindex, &answer); |
| 512 |
if (r < 0) |
| 513 |
return log_error_errno(r, "Failed to synthesize system hostname RRs: %m"); |
| 514 |
|
| 515 |
} else if (is_gateway_hostname(name)) { |
| 516 |
|
| 517 |
r = synthesize_gateway_rr(m, key, ifindex, local_gateways, &answer); |
| 518 |
if (r < 0) |
| 519 |
return log_error_errno(r, "Failed to synthesize gateway RRs: %m"); |
| 520 |
if (r == 0) { /* if we have no gateway return NXDOMAIN */ |
| 521 |
nxdomain = true; |
| 522 |
continue; |
| 523 |
} |
| 524 |
|
| 525 |
} else if (is_outbound_hostname(name)) { |
| 526 |
|
| 527 |
r = synthesize_gateway_rr(m, key, ifindex, local_outbounds, &answer); |
| 528 |
if (r < 0) |
| 529 |
return log_error_errno(r, "Failed to synthesize outbound RRs: %m"); |
| 530 |
if (r == 0) { /* if we have no gateway return NXDOMAIN */ |
| 531 |
nxdomain = true; |
| 532 |
continue; |
| 533 |
} |
| 534 |
|
| 535 |
} else if (is_dns_stub_hostname(name)) { |
| 536 |
|
| 537 |
r = synthesize_dns_stub_rr(m, key, INADDR_DNS_STUB, &answer); |
| 538 |
if (r < 0) |
| 539 |
return log_error_errno(r, "Failed to synthesize local DNS stub RRs: %m"); |
| 540 |
|
| 541 |
} else if (is_dns_proxy_stub_hostname(name)) { |
| 542 |
|
| 543 |
r = synthesize_dns_stub_rr(m, key, INADDR_DNS_PROXY_STUB, &answer); |
| 544 |
if (r < 0) |
| 545 |
return log_error_errno(r, "Failed to synthesize local DNS stub RRs: %m"); |
| 546 |
|
| 547 |
} else if ((dns_name_endswith(name, "127.in-addr.arpa") > 0 && |
| 548 |
dns_name_equal(name, "2.0.0.127.in-addr.arpa") == 0 && |
| 549 |
dns_name_equal(name, "53.0.0.127.in-addr.arpa") == 0 && |
| 550 |
dns_name_equal(name, "54.0.0.127.in-addr.arpa") == 0) || |
| 551 |
dns_name_equal(name, "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa") > 0) { |
| 552 |
|
| 553 |
r = synthesize_localhost_ptr(m, key, &answer); |
| 554 |
if (r < 0) |
| 555 |
return log_error_errno(r, "Failed to synthesize localhost PTR RRs: %m"); |
| 556 |
|
| 557 |
} else if (dns_name_address(name, &af, &address) > 0) { |
| 558 |
int v, w, u; |
| 559 |
|
| 560 |
if (!shall_synthesize_own_hostname_rrs()) |
| 561 |
continue; |
| 562 |
|
| 563 |
v = synthesize_system_hostname_ptr(m, af, &address, ifindex, &answer); |
| 564 |
if (v < 0) |
| 565 |
return log_error_errno(v, "Failed to synthesize system hostname PTR RR: %m"); |
| 566 |
|
| 567 |
w = synthesize_gateway_ptr(m, af, &address, ifindex, &answer); |
| 568 |
if (w < 0) |
| 569 |
return log_error_errno(w, "Failed to synthesize gateway hostname PTR RR: %m"); |
| 570 |
|
| 571 |
u = synthesize_dns_stub_ptr(m, af, &address, &answer); |
| 572 |
if (u < 0) |
| 573 |
return log_error_errno(u, "Failed to synthesize local stub hostname PTR PR: %m"); |
| 574 |
|
| 575 |
if (v == 0 && w == 0 && u == 0) /* This IP address is neither a local one, nor a gateway, nor a stub address */ |
| 576 |
continue; |
| 577 |
|
| 578 |
/* Note that we never synthesize reverse PTR for _outbound, since those are local |
| 579 |
* addresses and thus mapped to the local hostname anyway, hence they already have a |
| 580 |
* mapping. */ |
| 581 |
|
| 582 |
} else |
| 583 |
continue; |
| 584 |
|
| 585 |
found = true; |
| 586 |
} |
| 587 |
|
| 588 |
if (found) { |
| 589 |
|
| 590 |
if (ret) |
| 591 |
*ret = TAKE_PTR(answer); |
| 592 |
|
| 593 |
return 1; |
| 594 |
} else if (nxdomain) |
| 595 |
return -ENXIO; |
| 596 |
|
| 597 |
return 0; |
| 598 |
} |