resolved-dns-transaction.h revision 3bbdc31df37a23b5134a115c01d15e7ff870b3cc
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,
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering DNS_TRANSACTION_VALIDATING,
3bbdc31df37a23b5134a115c01d15e7ff870b3ccLennart Poettering DNS_TRANSACTION_RCODE_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,
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering DNS_TRANSACTION_DNSSEC_FAILED,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering _DNS_TRANSACTION_STATE_MAX,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering _DNS_TRANSACTION_STATE_INVALID = -1
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering};
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering#define DNS_TRANSACTION_IS_LIVE(state) IN_SET((state), DNS_TRANSACTION_NULL, DNS_TRANSACTION_PENDING, DNS_TRANSACTION_VALIDATING)
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart 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;
a5784c498598348354543b23b13ee8639a8b9e35Lennart Poettering char *key_string;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsTransactionState state;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering DnssecResult dnssec_result;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering uint16_t id;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
a0c888c78c419cd49c05ee6d226568e6fea0a4f3Lennart Poettering bool initial_jitter_scheduled:1;
a0c888c78c419cd49c05ee6d226568e6fea0a4f3Lennart Poettering bool initial_jitter_elapsed:1;
6e0684729420912df019cc64d3f8a3c8290cc5f1Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsPacket *sent, *received;
ae6a4bbf318e197813227e50c245a00de03784a2Lennart Poettering
ae6a4bbf318e197813227e50c245a00de03784a2Lennart Poettering DnsAnswer *answer;
ae6a4bbf318e197813227e50c245a00de03784a2Lennart Poettering int answer_rcode;
c3bc53e62459d7e566ffffeade41cd82bc6754f5Lennart Poettering DnsTransactionSource answer_source;
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering /* Indicates whether the primary answer is authenticated,
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering * i.e. whether the RRs from answer which directly match the
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering * question are authenticated, or, if there are none, whether
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering * the NODATA or NXDOMAIN case is. It says nothing about
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering * additional RRs listed in the answer, however they have
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering * their own DNS_ANSWER_AUTHORIZED FLAGS. Note that this bit
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering * is defined different than the AD bit in DNS packets, as
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering * that covers more than just the actual primary answer. */
931851e8e492a4d2715e22dcde50a5e7ccef4b49Lennart Poettering bool answer_authenticated;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering /* Contains DNSKEY, DS, SOA RRs we already verified and need
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering * to authenticate this reply */
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering DnsAnswer *validated_keys;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart 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
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering /* 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. */
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering Set *notify_query_candidates;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering /* Zone items this transaction is referenced by and that shall
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering * be notified about completion. */
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering Set *notify_zone_items;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering /* Other transactions that this transactions is referenced by
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering * and that shall be notified about completion. This is used
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering * when transactions want to validate their RRsets, but need
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering * another DNSKEY or DS RR to do so. */
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering Set *notify_transactions;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering /* The opposite direction: the transactions this transaction
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering * created in order to request DNSKEY or DS RRs. */
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering Set *dnssec_transactions;
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
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poetteringvoid dns_transaction_notify(DnsTransaction *t, DnsTransaction *source);
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poetteringint dns_transaction_validate_dnssec(DnsTransaction *t);
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poetteringint dns_transaction_request_dnssec_keys(DnsTransaction *t);
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
a5784c498598348354543b23b13ee8639a8b9e35Lennart Poetteringconst char *dns_transaction_key_string(DnsTransaction *t);
a5784c498598348354543b23b13ee8639a8b9e35Lennart 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)