/* RFC 4795, section 2.5 requires the TTL to be set to 1 */
if (sa.sa.sa_family == AF_INET) {
- r = setsockopt_int(fd, IPPROTO_IP, IP_TTL, true);
+ r = setsockopt_int(fd, IPPROTO_IP, IP_TTL, 1);
if (r < 0)
return r;
} else if (sa.sa.sa_family == AF_INET6) {
- r = setsockopt_int(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, true);
+ r = setsockopt_int(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, 1);
if (r < 0)
return r;
}
return TAKE_FD(fd);
}
-int dns_scope_socket_udp(DnsScope *s, DnsServer *server, uint16_t port) {
- return dns_scope_socket(s, SOCK_DGRAM, AF_UNSPEC, NULL, server, port, NULL);
+int dns_scope_socket_udp(DnsScope *s, DnsServer *server) {
+ return dns_scope_socket(s, SOCK_DGRAM, AF_UNSPEC, NULL, server, dns_server_port(server), NULL);
}
int dns_scope_socket_tcp(DnsScope *s, int family, const union in_addr_union *address, DnsServer *server, uint16_t port, union sockaddr_union *ret_socket_address) {
manager_is_own_hostname(s->manager, domain) <= 0)) /* never resolve the local hostname via LLMNR */
return DNS_SCOPE_YES_BASE + 1; /* Return +1, as we consider ourselves authoritative
* for single-label names, i.e. one label. This is
- * particular relevant as it means a "." route on some
+ * particularly relevant as it means a "." route on some
* other scope won't pull all traffic away from
* us. (If people actually want to pull traffic away
* from us they should turn off LLMNR on the
if (s->protocol == DNS_PROTOCOL_DNS) {
- /* On classic DNS, looking up non-address RRs is always
- * fine. (Specifically, we want to permit looking up
- * DNSKEY and DS records on the root and top-level
- * domains.) */
+ /* On classic DNS, looking up non-address RRs is always fine. (Specifically, we want to
+ * permit looking up DNSKEY and DS records on the root and top-level domains.) */
if (!dns_resource_key_is_address(key))
return true;
- /* However, we refuse to look up A and AAAA RRs on the
- * root and single-label domains, under the assumption
- * that those should be resolved via LLMNR or search
- * path only, and should not be leaked onto the
- * internet. */
- return !(dns_name_is_single_label(dns_resource_key_name(key)) ||
- dns_name_is_root(dns_resource_key_name(key)));
+ /* Unless explicitly overridden, we refuse to look up A and AAAA RRs on the root and
+ * single-label domains, under the assumption that those should be resolved via LLMNR or
+ * search path only, and should not be leaked onto the internet. */
+ const char* name = dns_resource_key_name(key);
+
+ if (!s->manager->resolve_unicast_single_label &&
+ dns_name_is_single_label(name))
+ return false;
+
+ return !dns_name_is_root(name);
}
/* On mDNS and LLMNR, send A and AAAA queries only on the
random_bytes(&jitter, sizeof(jitter));
jitter %= LLMNR_JITTER_INTERVAL_USEC;
- r = sd_event_add_time(scope->manager->event,
- &scope->conflict_event_source,
- clock_boottime_or_monotonic(),
- now(clock_boottime_or_monotonic()) + jitter,
- LLMNR_JITTER_INTERVAL_USEC,
- on_conflict_dispatch, scope);
+ r = sd_event_add_time_relative(
+ scope->manager->event,
+ &scope->conflict_event_source,
+ clock_boottime_or_monotonic(),
+ jitter,
+ LLMNR_JITTER_INTERVAL_USEC,
+ on_conflict_dispatch, scope);
if (r < 0)
return log_debug_errno(r, "Failed to add conflict dispatch event: %m");
return s->manager->search_domains;
}
-bool dns_scope_name_needs_search_domain(DnsScope *s, const char *name) {
+bool dns_scope_name_wants_search_domain(DnsScope *s, const char *name) {
assert(s);
if (s->protocol != DNS_PROTOCOL_DNS)
DnsTransaction *t;
DnsZoneItem *z, *i;
unsigned size = 0;
- Iterator iterator;
char *service_type;
int r;
return 0; /* we reach this point only if changing hostname didn't help */
/* Calculate answer's size. */
- HASHMAP_FOREACH(z, scope->zone.by_key, iterator) {
+ HASHMAP_FOREACH(z, scope->zone.by_key) {
if (z->state != DNS_ZONE_ITEM_ESTABLISHED)
continue;
if (!scope->announced &&
dns_resource_key_is_dnssd_ptr(z->rr->key)) {
if (!set_contains(types, dns_resource_key_name(z->rr->key))) {
- r = set_ensure_allocated(&types, &dns_name_hash_ops);
- if (r < 0)
- return log_debug_errno(r, "Failed to allocate set: %m");
-
- r = set_put(types, dns_resource_key_name(z->rr->key));
+ r = set_ensure_put(&types, &dns_name_hash_ops, dns_resource_key_name(z->rr->key));
if (r < 0)
return log_debug_errno(r, "Failed to add item to set: %m");
}
return log_oom();
/* Second iteration, actually add RRs to the answer. */
- HASHMAP_FOREACH(z, scope->zone.by_key, iterator)
+ HASHMAP_FOREACH(z, scope->zone.by_key)
LIST_FOREACH (by_key, i, z) {
DnsAnswerFlags flags;
}
/* Since all the active services are in the zone make them discoverable now. */
- SET_FOREACH(service_type, types, iterator) {
+ SET_FOREACH(service_type, types) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr;
rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_PTR,
/* In section 8.3 of RFC6762: "The Multicast DNS responder MUST send at least two unsolicited
* responses, one second apart." */
if (!scope->announced) {
- usec_t ts;
-
scope->announced = true;
- assert_se(sd_event_now(scope->manager->event, clock_boottime_or_monotonic(), &ts) >= 0);
- ts += MDNS_ANNOUNCE_DELAY;
-
- r = sd_event_add_time(
+ r = sd_event_add_time_relative(
scope->manager->event,
&scope->announce_event_source,
clock_boottime_or_monotonic(),
- ts,
+ MDNS_ANNOUNCE_DELAY,
MDNS_JITTER_RANGE_USEC,
on_announcement_timeout, scope);
if (r < 0)
}
int dns_scope_add_dnssd_services(DnsScope *scope) {
- Iterator i;
DnssdService *service;
DnssdTxtData *txt_data;
int r;
scope->announced = false;
- HASHMAP_FOREACH(service, scope->manager->dnssd_services, i) {
+ HASHMAP_FOREACH(service, scope->manager->dnssd_services) {
service->withdrawn = false;
r = dns_zone_put(&scope->zone, scope, service->ptr_rr, false);
int dns_scope_remove_dnssd_services(DnsScope *scope) {
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
- Iterator i;
DnssdService *service;
DnssdTxtData *txt_data;
int r;
if (r < 0)
return r;
- HASHMAP_FOREACH(service, scope->manager->dnssd_services, i) {
+ HASHMAP_FOREACH(service, scope->manager->dnssd_services) {
dns_zone_remove_rr(&scope->zone, service->ptr_rr);
dns_zone_remove_rr(&scope->zone, service->srv_rr);
LIST_FOREACH(items, txt_data, service->txt_data_items)