resolved-dns-transaction.h revision 7cc6ed7ba6c667caef9a92ba4d59e1ecdc3af8ff
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#pragma once
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich/***
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich This file is part of systemd.
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich Copyright 2014 Lennart Poettering
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich systemd is free software; you can redistribute it and/or modify it
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich under the terms of the GNU Lesser General Public License as published by
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich the Free Software Foundation; either version 2.1 of the License, or
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich (at your option) any later version.
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich systemd is distributed in the hope that it will be useful, but
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich WITHOUT ANY WARRANTY; without even the implied warranty of
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich Lesser General Public License for more details.
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich You should have received a copy of the GNU Lesser General Public License
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich along with systemd; If not, see <http://www.gnu.org/licenses/>.
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich***/
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichtypedef struct DnsTransaction DnsTransaction;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichtypedef enum DnsTransactionState DnsTransactionState;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichtypedef enum DnsTransactionSource DnsTransactionSource;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichenum DnsTransactionState {
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_NULL,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_PENDING,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_VALIDATING,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_RCODE_FAILURE,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_SUCCESS,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_NO_SERVERS,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_TIMEOUT,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_ATTEMPTS_MAX_REACHED,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_INVALID_REPLY,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_ERRNO,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_ABORTED,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_DNSSEC_FAILED,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_NO_TRUST_ANCHOR,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_RR_TYPE_UNSUPPORTED,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_NETWORK_DOWN,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_NOT_FOUND, /* like NXDOMAIN, but when LLMNR/TCP connections fail */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich _DNS_TRANSACTION_STATE_MAX,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich _DNS_TRANSACTION_STATE_INVALID = -1
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich};
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#define DNS_TRANSACTION_IS_LIVE(state) IN_SET((state), DNS_TRANSACTION_NULL, DNS_TRANSACTION_PENDING, DNS_TRANSACTION_VALIDATING)
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichenum DnsTransactionSource {
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_NETWORK,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_CACHE,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_ZONE,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DNS_TRANSACTION_TRUST_ANCHOR,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich _DNS_TRANSACTION_SOURCE_MAX,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich _DNS_TRANSACTION_SOURCE_INVALID = -1
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich};
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#include "resolved-dns-answer.h"
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#include "resolved-dns-packet.h"
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#include "resolved-dns-question.h"
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#include "resolved-dns-scope.h"
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichstruct DnsTransaction {
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsScope *scope;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsResourceKey *key;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich char *key_string;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsTransactionState state;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich uint16_t id;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich bool tried_stream:1;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich bool initial_jitter_scheduled:1;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich bool initial_jitter_elapsed:1;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsPacket *sent, *received;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsAnswer *answer;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich int answer_rcode;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnssecResult answer_dnssec_result;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsTransactionSource answer_source;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich uint32_t answer_nsec_ttl;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich int answer_errno; /* if state is DNS_TRANSACTION_ERRNO */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* Indicates whether the primary answer is authenticated,
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * i.e. whether the RRs from answer which directly match the
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * question are authenticated, or, if there are none, whether
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * the NODATA or NXDOMAIN case is. It says nothing about
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * additional RRs listed in the answer, however they have
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * their own DNS_ANSWER_AUTHORIZED FLAGS. Note that this bit
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * is defined different than the AD bit in DNS packets, as
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * that covers more than just the actual primary answer. */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich bool answer_authenticated;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* Contains DNSKEY, DS, SOA RRs we already verified and need
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * to authenticate this reply */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsAnswer *validated_keys;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich usec_t start_usec;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich usec_t next_attempt_after;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich sd_event_source *timeout_event_source;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich unsigned n_attempts;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* UDP connection logic, if we need it */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich int dns_udp_fd;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich sd_event_source *dns_udp_event_source;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* TCP connection logic, if we need it */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsStream *stream;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* The active server */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsServer *server;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* The features of the DNS server at time of transaction start */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich DnsServerFeatureLevel current_feature_level;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* Query candidates this transaction is referenced by and that
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * shall be notified about this specific transaction
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * completing. */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich Set *notify_query_candidates;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* Zone items this transaction is referenced by and that shall
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * be notified about completion. */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich Set *notify_zone_items;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* Other transactions that this transactions is referenced by
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * and that shall be notified about completion. This is used
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * when transactions want to validate their RRsets, but need
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * another DNSKEY or DS RR to do so. */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich Set *notify_transactions;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich /* The opposite direction: the transactions this transaction
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich * created in order to request DNSKEY or DS RRs. */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich Set *dnssec_transactions;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich unsigned block_gc;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich LIST_FIELDS(DnsTransaction, transactions_by_scope);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich};
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichint dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key);
a220f3583ce0f3e3fc7295325126088382eb45afViktar VauchkevichDnsTransaction* dns_transaction_free(DnsTransaction *t);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichbool dns_transaction_gc(DnsTransaction *t);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichint dns_transaction_go(DnsTransaction *t);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichvoid dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichvoid dns_transaction_complete(DnsTransaction *t, DnsTransactionState state);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichvoid dns_transaction_notify(DnsTransaction *t, DnsTransaction *source);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichint dns_transaction_validate_dnssec(DnsTransaction *t);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichint dns_transaction_request_dnssec_keys(DnsTransaction *t);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichconst char *dns_transaction_key_string(DnsTransaction *t);
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichconst char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
a220f3583ce0f3e3fc7295325126088382eb45afViktar VauchkevichDnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevichconst char* dns_transaction_source_to_string(DnsTransactionSource p) _const_;
a220f3583ce0f3e3fc7295325126088382eb45afViktar VauchkevichDnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich/* LLMNR Jitter interval, see RFC 4795 Section 7 */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich/* mDNS Jitter interval, see RFC 6762 Section 5.2 */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#define MDNS_JITTER_MIN_USEC (20 * USEC_PER_MSEC)
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#define MDNS_JITTER_RANGE_USEC (100 * USEC_PER_MSEC)
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich/* Maximum attempts to send DNS requests, across all DNS servers */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#define DNS_TRANSACTION_ATTEMPTS_MAX 16
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich/* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich#define TRANSACTION_ATTEMPTS_MAX(p) ((p) == DNS_PROTOCOL_LLMNR ? LLMNR_TRANSACTION_ATTEMPTS_MAX : DNS_TRANSACTION_ATTEMPTS_MAX)
a220f3583ce0f3e3fc7295325126088382eb45afViktar Vauchkevich