resolved-dns-transaction.h revision 3b31df8301fd7dfb78bf9eaf9227d40c9bf12182
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;
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
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#include "resolved-dns-scope.h"
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#include "resolved-dns-packet.h"
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#include "resolved-dns-question.h"
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#include "resolved-dns-answer.h"
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringstruct DnsTransaction {
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsScope *scope;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsQuestion *question;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsTransactionState state;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering uint16_t id;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
6e0684729420912df019cc64d3f8a3c8290cc5f1Lennart Poettering bool initial_jitter;
6e0684729420912df019cc64d3f8a3c8290cc5f1Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsPacket *sent, *received;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsAnswer *cached;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering int cached_rcode;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen usec_t start_usec;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering sd_event_source *timeout_event_source;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering unsigned n_attempts;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
0eb99d0a6a7d28a16e739b3a0e4900b9e4dc76f9Tom Gundersen int dns_fd;
0eb99d0a6a7d28a16e739b3a0e4900b9e4dc76f9Tom Gundersen sd_event_source *dns_event_source;
d20b1667dbab8bccf69735523a0d5fc645e81b80Tom Gundersen
8300ba218e3cf5049496937be8bce10f22d09bbcTom Gundersen /* the active server */
8300ba218e3cf5049496937be8bce10f22d09bbcTom Gundersen DnsServer *server;
8300ba218e3cf5049496937be8bce10f22d09bbcTom Gundersen
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering /* TCP connection logic, if we need it */
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsStream *stream;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering /* Queries this transaction is referenced by and that shall be
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering * notified about this specific transaction completing. */
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering Set *queries;
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
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringint dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsQuestion *q);
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
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering/* LLMNR Jitter interval, see RFC 4795 Section 7 */
6e0684729420912df019cc64d3f8a3c8290cc5f1Lennart Poettering#define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
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
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#define TRANSACTION_ATTEMPTS_MAX(p) (p == DNS_PROTOCOL_LLMNR ? LLMNR_TRANSACTION_ATTEMPTS_MAX : DNS_TRANSACTION_ATTEMPTS_MAX)