diff options
Diffstat (limited to 'src/resolve/resolved-dns-scope.c')
-rw-r--r-- | src/resolve/resolved-dns-scope.c | 74 |
1 files changed, 33 insertions, 41 deletions
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index bf6aac8300..38ea7fea0a 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright 2014 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include <netinet/tcp.h> @@ -65,12 +47,18 @@ int dns_scope_new(Manager *m, DnsScope **ret, Link *l, DnsProtocol protocol, int * not update it from the on, even if the setting * changes. */ - if (l) + if (l) { s->dnssec_mode = link_get_dnssec_mode(l); - else + s->dns_over_tls_mode = link_get_dns_over_tls_mode(l); + } else { s->dnssec_mode = manager_get_dnssec_mode(m); - } else + s->dns_over_tls_mode = manager_get_dns_over_tls_mode(m); + } + + } else { s->dnssec_mode = DNSSEC_NO; + s->dns_over_tls_mode = DNS_OVER_TLS_NO; + } LIST_PREPEND(scopes, m->dns_scopes, s); @@ -234,7 +222,7 @@ static int dns_scope_emit_one(DnsScope *s, int fd, DnsPacket *p) { if (DNS_PACKET_QDCOUNT(p) > 1) return -EOPNOTSUPP; - if (!ratelimit_test(&s->ratelimit)) + if (!ratelimit_below(&s->ratelimit)) return -EBUSY; family = s->family; @@ -259,7 +247,7 @@ static int dns_scope_emit_one(DnsScope *s, int fd, DnsPacket *p) { case DNS_PROTOCOL_MDNS: assert(fd < 0); - if (!ratelimit_test(&s->ratelimit)) + if (!ratelimit_below(&s->ratelimit)) return -EBUSY; family = s->family; @@ -319,13 +307,14 @@ static int dns_scope_socket( int family, const union in_addr_union *address, DnsServer *server, - uint16_t port) { + uint16_t port, + union sockaddr_union *ret_socket_address) { _cleanup_close_ int fd = -1; - union sockaddr_union sa = {}; + union sockaddr_union sa; socklen_t salen; static const int one = 1; - int ret, r, ifindex; + int r, ifindex; assert(s); @@ -405,22 +394,27 @@ static int dns_scope_socket( } } - r = connect(fd, &sa.sa, salen); - if (r < 0 && errno != EINPROGRESS) - return -errno; - - ret = fd; - fd = -1; + if (ret_socket_address) + *ret_socket_address = sa; + else { + r = connect(fd, &sa.sa, salen); + if (r < 0 && errno != EINPROGRESS) + return -errno; + } - return ret; + 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); + return dns_scope_socket(s, SOCK_DGRAM, AF_UNSPEC, NULL, server, port, NULL); } -int dns_scope_socket_tcp(DnsScope *s, int family, const union in_addr_union *address, DnsServer *server, uint16_t port) { - return dns_scope_socket(s, SOCK_STREAM, family, address, server, port); +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) { + /* If ret_socket_address is not NULL, the caller is responisble + * for calling connect() or sendmsg(). This is required by TCP + * Fast Open, to be able to send the initial SYN packet along + * with the first data packet. */ + return dns_scope_socket(s, SOCK_STREAM, family, address, server, port, ret_socket_address); } DnsScopeMatch dns_scope_good_domain(DnsScope *s, int ifindex, uint64_t flags, const char *domain) { @@ -684,8 +678,7 @@ int dns_scope_make_reply_packet( return r; DNS_PACKET_HEADER(p)->arcount = htobe16(dns_answer_size(soa)); - *ret = p; - p = NULL; + *ret = TAKE_PTR(p); return 0; } @@ -776,7 +769,7 @@ void dns_scope_process_query(DnsScope *s, DnsStream *stream, DnsPacket *p) { } else { int fd; - if (!ratelimit_test(&s->ratelimit)) + if (!ratelimit_below(&s->ratelimit)) return; if (p->family == AF_INET) @@ -869,8 +862,7 @@ static int dns_scope_make_conflict_packet( if (r < 0) return r; - *ret = p; - p = NULL; + *ret = TAKE_PTR(p); return 0; } |