resolved-dns-transaction.h revision a9da14e1e97ff774761966c2e1d83b0c6750b367
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#pragma once
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering/***
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering This file is part of systemd.
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering Copyright 2014 Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering systemd is free software; you can redistribute it and/or modify it
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering under the terms of the GNU Lesser General Public License as published by
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering (at your option) any later version.
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering systemd is distributed in the hope that it will be useful, but
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering Lesser General Public License for more details.
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering You should have received a copy of the GNU Lesser General Public License
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering***/
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringtypedef struct DnsTransaction DnsTransaction;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringtypedef enum DnsTransactionState DnsTransactionState;
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poetteringtypedef enum DnsTransactionSource DnsTransactionSource;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringenum DnsTransactionState {
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_NULL,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_PENDING,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_FAILURE,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_SUCCESS,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_NO_SERVERS,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_TIMEOUT,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_ATTEMPTS_MAX_REACHED,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_INVALID_REPLY,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_RESOURCES,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DNS_TRANSACTION_ABORTED,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering _DNS_TRANSACTION_STATE_MAX,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering _DNS_TRANSACTION_STATE_INVALID = -1
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering};
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poetteringenum DnsTransactionSource {
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering DNS_TRANSACTION_NETWORK,
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering DNS_TRANSACTION_CACHE,
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering DNS_TRANSACTION_ZONE,
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering DNS_TRANSACTION_TRUST_ANCHOR,
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering _DNS_TRANSACTION_SOURCE_MAX,
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering _DNS_TRANSACTION_SOURCE_INVALID = -1
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering};
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering
71d35b6b5563817dfbe757ab9e3b9f018b2db491Thomas Hindoe Paaboel Andersen#include "resolved-dns-answer.h"
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#include "resolved-dns-packet.h"
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#include "resolved-dns-question.h"
71d35b6b5563817dfbe757ab9e3b9f018b2db491Thomas Hindoe Paaboel Andersen#include "resolved-dns-scope.h"
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringstruct DnsTransaction {
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsScope *scope;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
f52e61da047d7fc74e83f12dbbf87e0cbcc51c73Lennart Poettering DnsResourceKey *key;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsTransactionState state;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering uint16_t id;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ef7ce6df4d5084bb0cba78e71a2bb932b59045e8Daniel Mack bool initial_jitter_scheduled;
ef7ce6df4d5084bb0cba78e71a2bb932b59045e8Daniel Mack bool initial_jitter_elapsed;
6e0684729420912df019cc64d3f8a3c8290cc5f1Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsPacket *sent, *received;
ae6a4bbf318e197813227e50c245a00de03784a2Lennart Poettering
ae6a4bbf318e197813227e50c245a00de03784a2Lennart Poettering DnsAnswer *answer;
ae6a4bbf318e197813227e50c245a00de03784a2Lennart Poettering int answer_rcode;
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering DnsTransactionSource answer_source;
931851e8e492a4d2715e22dcde50a5e7ccef4b49Lennart Poettering bool answer_authenticated;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen usec_t start_usec;
a9da14e1e97ff774761966c2e1d83b0c6750b367Daniel Mack usec_t next_attempt_after;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering sd_event_source *timeout_event_source;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering unsigned n_attempts;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
4667e00a61c2f60922558bc5e33ac9d3073a482cLennart Poettering int dns_udp_fd;
4667e00a61c2f60922558bc5e33ac9d3073a482cLennart Poettering sd_event_source *dns_udp_event_source;
d20b1667dbab8bccf69735523a0d5fc645e81b80Tom Gundersen
4667e00a61c2f60922558bc5e33ac9d3073a482cLennart Poettering /* The active server */
8300ba218e3cf5049496937be8bce10f22d09bbcTom Gundersen DnsServer *server;
8300ba218e3cf5049496937be8bce10f22d09bbcTom Gundersen
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen /* the features of the DNS server at time of transaction start */
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen DnsServerFeatureLevel current_features;
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering /* TCP connection logic, if we need it */
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsStream *stream;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering /* Query candidates this transaction is referenced by and that
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering * shall be notified about this specific transaction
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering * completing. */
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering Set *query_candidates;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering /* Zone items this transaction is referenced by and that shall
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering * be notified about completion. */
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering Set *zone_items;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering unsigned block_gc;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering LIST_FIELDS(DnsTransaction, transactions_by_scope);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering};
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
f52e61da047d7fc74e83f12dbbf87e0cbcc51c73Lennart Poetteringint dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart PoetteringDnsTransaction* dns_transaction_free(DnsTransaction *t);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringvoid dns_transaction_gc(DnsTransaction *t);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringint dns_transaction_go(DnsTransaction *t);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringvoid dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringvoid dns_transaction_complete(DnsTransaction *t, DnsTransactionState state);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringconst char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart PoetteringDnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poetteringconst char* dns_transaction_source_to_string(DnsTransactionSource p) _const_;
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart PoetteringDnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering/* LLMNR Jitter interval, see RFC 4795 Section 7 */
6e0684729420912df019cc64d3f8a3c8290cc5f1Lennart Poettering#define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ea12bcc78911fd3531955a799dbf6c5ac33bf567Daniel Mack/* mDNS Jitter interval, see RFC 6762 Section 5.2 */
ea12bcc78911fd3531955a799dbf6c5ac33bf567Daniel Mack#define MDNS_JITTER_MIN_USEC (20 * USEC_PER_MSEC)
ea12bcc78911fd3531955a799dbf6c5ac33bf567Daniel Mack#define MDNS_JITTER_RANGE_USEC (100 * USEC_PER_MSEC)
ea12bcc78911fd3531955a799dbf6c5ac33bf567Daniel Mack
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering/* Maximum attempts to send DNS requests, across all DNS servers */
3b31df8301fd7dfb78bf9eaf9227d40c9bf12182Tom Gundersen#define DNS_TRANSACTION_ATTEMPTS_MAX 16
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering/* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering#define TRANSACTION_ATTEMPTS_MAX(p) ((p) == DNS_PROTOCOL_LLMNR ? LLMNR_TRANSACTION_ATTEMPTS_MAX : DNS_TRANSACTION_ATTEMPTS_MAX)