resolved-dns-transaction.c revision 8300ba218e3cf5049496937be8bce10f22d09bbc
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering This file is part of systemd.
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering Copyright 2014 Lennart Poettering
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering systemd is free software; you can redistribute it and/or modify it
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering under the terms of the GNU Lesser General Public License as published by
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering (at your option) any later version.
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering systemd is distributed in the hope that it will be useful, but
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering Lesser General Public License for more details.
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering You should have received a copy of the GNU Lesser General Public License
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
6c12b52e19640747e96f89d85422941a23dc6b29Lennart PoetteringDnsTransaction* dns_transaction_free(DnsTransaction *t) {
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering sd_event_source_unref(t->timeout_event_source);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering LIST_REMOVE(transactions_by_scope, t->scope->transactions, t);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering hashmap_remove(t->scope->manager->dns_transactions, UINT_TO_PTR(t->id));
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering while ((q = set_steal_first(t->queries)))
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering while ((i = set_steal_first(t->zone_items)))
6c12b52e19640747e96f89d85422941a23dc6b29Lennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(DnsTransaction*, dns_transaction_free);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringvoid dns_transaction_gc(DnsTransaction *t) {
assert(s);
assert(q);
return -ENOMEM;
while (t->id == 0 ||
t->id = 0;
t->scope = s;
if (ret)
*ret = t;
t = NULL;
assert(t);
DnsZoneItem *z;
assert(t);
assert(p);
pretty);
t->block_gc++;
t->block_gc--;
DnsQuery *q;
DnsZoneItem *z;
Iterator i;
assert(t);
t->block_gc++;
dns_query_ready(q);
t->block_gc--;
DnsTransaction *t;
assert(s);
t = s->transaction;
if (error != 0) {
if (dns_packet_validate_reply(p) <= 0) {
t->block_gc++;
t->block_gc--;
assert(t);
if (t->stream)
if (t->received)
fd = dns_scope_tcp_socket(t->scope, t->received->family, &t->received->sender, t->received->sender_port, NULL);
return -EINVAL;
return -EAFNOSUPPORT;
if (fd < 0)
return fd;
assert(t);
assert(p);
if (DNS_PACKET_LLMNR_T(p)) {
dns_transaction_tentative(t, p);
if (t->received != p) {
if (DNS_PACKET_TC(p)) {
if (DNS_PACKET_TC(p)) {
r = dns_transaction_open_tcp(t);
if (r == -ESRCH) {
r = dns_transaction_go(t);
r = dns_packet_extract(p);
dns_cache_put(&t->scope->cache, p->question, DNS_PACKET_RCODE(p), p->answer, DNS_PACKET_ANCOUNT(p), 0, p->family, &p->sender);
assert(s);
assert(t);
r = dns_transaction_go(t);
unsigned n, added = 0;
assert(t);
if (t->sent)
added++;
if (added <= 0)
return -EDOM;
t->sent = p;
p = NULL;
bool had_stream;
assert(t);
t->n_attempts++;
t->cached_rcode = 0;
t->initial_jitter = true;
r = sd_event_add_time(
&t->timeout_event_source,
t->n_attempts = 0;
r = dns_transaction_make_packet(t);
if (r == -EDOM) {
r = dns_transaction_open_tcp(t);
else if (r == -EMSGSIZE)
r = dns_transaction_open_tcp(t);
if (r == -ESRCH) {
return dns_transaction_go(t);
r = sd_event_add_time(
&t->timeout_event_source,