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