resolved-dns-query.h revision 934e9b10b4f4bfb48e21883670c7f45b6911fa9b
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen#pragma once
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen/***
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen This file is part of systemd.
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen Copyright 2014 Lennart Poettering
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen systemd is free software; you can redistribute it and/or modify it
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen under the terms of the GNU Lesser General Public License as published by
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen the Free Software Foundation; either version 2.1 of the License, or
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen (at your option) any later version.
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen systemd is distributed in the hope that it will be useful, but
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen WITHOUT ANY WARRANTY; without even the implied warranty of
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen Lesser General Public License for more details.
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen You should have received a copy of the GNU Lesser General Public License
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen***/
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen#include <inttypes.h>
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen#include "sd-bus.h"
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen#include "util.h"
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen#include "set.h"
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersentypedef struct DnsQuery DnsQuery;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersentypedef struct DnsQueryTransaction DnsQueryTransaction;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen#include "resolved.h"
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen#include "resolved-dns-scope.h"
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen#include "resolved-dns-rr.h"
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen#include "resolved-dns-packet.h"
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering#include "resolved-dns-question.h"
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering#include "resolved-dns-answer.h"
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersentypedef enum DnsQueryState {
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_NULL,
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_PENDING,
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_FAILURE,
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_SUCCESS,
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_NO_SERVERS,
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_TIMEOUT,
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_ATTEMPTS_MAX,
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_INVALID_REPLY,
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_RESOURCES,
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DNS_QUERY_ABORTED,
d5d8429a12c4b1ef0dcd226c0904f00f4fa4898aLennart Poettering} DnsQueryState;
d5d8429a12c4b1ef0dcd226c0904f00f4fa4898aLennart Poettering
d5d8429a12c4b1ef0dcd226c0904f00f4fa4898aLennart Poetteringstruct DnsQueryTransaction {
d5d8429a12c4b1ef0dcd226c0904f00f4fa4898aLennart Poettering DnsScope *scope;
d5d8429a12c4b1ef0dcd226c0904f00f4fa4898aLennart Poettering
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DnsQuestion *question;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DnsQueryState state;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen uint16_t id;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DnsPacket *sent, *received;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen DnsAnswer *cached;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen int cached_rcode;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen sd_event_source *timeout_event_source;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen unsigned n_attempts;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek /* TCP connection logic */
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek int tcp_fd;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen sd_event_source *tcp_event_source;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen size_t tcp_written, tcp_read;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen be16_t tcp_read_size;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen /* Queries this transaction is referenced by and that shall by
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen * notified about this specific transaction completing. */
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen Set *queries;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen unsigned block_gc;
260ad50f5b4a9795032e3119c64f838a2d03370dThomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen LIST_FIELDS(DnsQueryTransaction, transactions_by_scope);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen};
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersenstruct DnsQuery {
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen Manager *manager;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek DnsQuestion *question;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek DnsQueryState state;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek unsigned n_cname_redirects;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek sd_event_source *timeout_event_source;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek /* Discovered data */
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek DnsAnswer *answer;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek int answer_ifindex;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek int answer_rcode;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek /* Bus client information */
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek sd_bus_message *request;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek int request_family;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek const char *request_hostname;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek union in_addr_union request_address;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek /* Completion callback */
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek void (*complete)(DnsQuery* q);
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek unsigned block_ready;
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek
8fba1c8d4e3d05d2af2848b6570bdc09e725d06eZbigniew Jędrzejewski-Szmek Set *transactions;
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen LIST_FIELDS(DnsQuery, queries);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen};
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel AndersenDnsQueryTransaction* dns_query_transaction_free(DnsQueryTransaction *t);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersenvoid dns_query_transaction_complete(DnsQueryTransaction *t, DnsQueryState state);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersenvoid dns_query_transaction_process_reply(DnsQueryTransaction *t, DnsPacket *p);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersenint dns_query_new(Manager *m, DnsQuery **q, DnsQuestion *question);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel AndersenDnsQuery *dns_query_free(DnsQuery *q);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersenint dns_query_go(DnsQuery *q);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersenvoid dns_query_ready(DnsQuery *q);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersenint dns_query_cname_redirect(DnsQuery *q, const char *name);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel AndersenDEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free);
95ed3294c632f5606327149f10cef1eb34422862Thomas Hindoe Paaboel Andersen