74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#pragma once
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/***
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2014 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering***/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
3c0cf502796be355431d4a64d738e75f543aa51dLennart Poettering#include "in-addr-util.h"
3c0cf502796be355431d4a64d738e75f543aa51dLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringtypedef struct DnsServer DnsServer;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poetteringtypedef enum DnsServerType {
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering DNS_SERVER_SYSTEM,
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering DNS_SERVER_FALLBACK,
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering DNS_SERVER_LINK,
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering} DnsServerType;
e3309036cda30bdb737ef6e441716b93943677e7Zbigniew Jędrzejewski-Szmek#define _DNS_SERVER_TYPE_MAX (DNS_SERVER_LINK + 1)
e3309036cda30bdb737ef6e441716b93943677e7Zbigniew Jędrzejewski-Szmek
e3309036cda30bdb737ef6e441716b93943677e7Zbigniew Jędrzejewski-Szmekconst char* dns_server_type_to_string(DnsServerType i) _const_;
e3309036cda30bdb737ef6e441716b93943677e7Zbigniew Jędrzejewski-SzmekDnsServerType dns_server_type_from_string(const char *s) _pure_;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersentypedef enum DnsServerFeatureLevel {
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen DNS_SERVER_FEATURE_LEVEL_TCP,
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen DNS_SERVER_FEATURE_LEVEL_UDP,
9c5e12a4314e7192e834e1b855e5e80111e636a6Tom Gundersen DNS_SERVER_FEATURE_LEVEL_EDNS0,
7586f4d172dd9c3ccc3126fc47dca9e49adec132Tom Gundersen DNS_SERVER_FEATURE_LEVEL_DO,
d74fb368b18f0fbd9a4fe6f15691bbea7f3c4a01Tom Gundersen DNS_SERVER_FEATURE_LEVEL_LARGE,
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen _DNS_SERVER_FEATURE_LEVEL_MAX,
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen _DNS_SERVER_FEATURE_LEVEL_INVALID = -1
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen} DnsServerFeatureLevel;
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen#define DNS_SERVER_FEATURE_LEVEL_WORST 0
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen#define DNS_SERVER_FEATURE_LEVEL_BEST (_DNS_SERVER_FEATURE_LEVEL_MAX - 1)
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersenconst char* dns_server_feature_level_to_string(int i) _const_;
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersenint dns_server_feature_level_from_string(const char *s) _pure_;
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering#include "resolved-link.h"
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen#include "resolved-manager.h"
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstruct DnsServer {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Manager *manager;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
91b14d6ff362b938a72db17b095ee9903d07381bTom Gundersen unsigned n_ref;
91b14d6ff362b938a72db17b095ee9903d07381bTom Gundersen
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering DnsServerType type;
3c0cf502796be355431d4a64d738e75f543aa51dLennart Poettering Link *link;
3c0cf502796be355431d4a64d738e75f543aa51dLennart Poettering
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering int family;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering union in_addr_union address;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
6cb08a8930bdaca950b152b1e8b82466ed59511cLennart Poettering char *server_string;
6cb08a8930bdaca950b152b1e8b82466ed59511cLennart Poettering
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen usec_t resend_timeout;
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen usec_t max_rtt;
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen
f4461e5641d53f27d6e76e0607bdaa9c0c58c1f6Lennart Poettering DnsServerFeatureLevel verified_feature_level;
f4461e5641d53f27d6e76e0607bdaa9c0c58c1f6Lennart Poettering DnsServerFeatureLevel possible_feature_level;
de54e62b4bd7856fb897c9a2ee93cc228adb2135Lennart Poettering
d74fb368b18f0fbd9a4fe6f15691bbea7f3c4a01Tom Gundersen size_t received_udp_packet_max;
de54e62b4bd7856fb897c9a2ee93cc228adb2135Lennart Poettering
6bb2c08597c999c429e889cd2403b2fef5f3e1a0Lennart Poettering unsigned n_failed_udp;
6bb2c08597c999c429e889cd2403b2fef5f3e1a0Lennart Poettering unsigned n_failed_tcp;
de54e62b4bd7856fb897c9a2ee93cc228adb2135Lennart Poettering
6bb2c08597c999c429e889cd2403b2fef5f3e1a0Lennart Poettering bool packet_failed:1;
6bb2c08597c999c429e889cd2403b2fef5f3e1a0Lennart Poettering bool packet_truncated:1;
de54e62b4bd7856fb897c9a2ee93cc228adb2135Lennart Poettering bool packet_bad_opt:1;
de54e62b4bd7856fb897c9a2ee93cc228adb2135Lennart Poettering bool packet_rrsig_missing:1;
de54e62b4bd7856fb897c9a2ee93cc228adb2135Lennart Poettering
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen usec_t verified_usec;
be808ea083fa07271116b4519c3c27fd20c5f077Tom Gundersen usec_t features_grace_period_usec;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
1e02e182f1e06fcbe389474175de228103be39cbLennart Poettering /* Whether we already warned about downgrading to non-DNSSEC mode for this server */
1e02e182f1e06fcbe389474175de228103be39cbLennart Poettering bool warned_downgrade:1;
1e02e182f1e06fcbe389474175de228103be39cbLennart Poettering
b652d4a2099d1c167584dcc1d179d47c58dc38a2Lennart Poettering /* Used when GC'ing old DNS servers when configuration changes. */
b652d4a2099d1c167584dcc1d179d47c58dc38a2Lennart Poettering bool marked:1;
b652d4a2099d1c167584dcc1d179d47c58dc38a2Lennart Poettering
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering /* If linked is set, then this server appears in the servers linked list */
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering bool linked:1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIELDS(DnsServer, servers);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint dns_server_new(
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Manager *m,
0b58db658b5c3f586ac3a837427f1f7fec2abb2eLennart Poettering DnsServer **ret,
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering DnsServerType type,
0b58db658b5c3f586ac3a837427f1f7fec2abb2eLennart Poettering Link *link,
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering int family,
3c0cf502796be355431d4a64d738e75f543aa51dLennart Poettering const union in_addr_union *address);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
91b14d6ff362b938a72db17b095ee9903d07381bTom GundersenDnsServer* dns_server_ref(DnsServer *s);
91b14d6ff362b938a72db17b095ee9903d07381bTom GundersenDnsServer* dns_server_unref(DnsServer *s);
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poetteringvoid dns_server_unlink(DnsServer *s);
0b58db658b5c3f586ac3a837427f1f7fec2abb2eLennart Poetteringvoid dns_server_move_back_and_unmark(DnsServer *s);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering
6bb2c08597c999c429e889cd2403b2fef5f3e1a0Lennart Poetteringvoid dns_server_packet_received(DnsServer *s, int protocol, DnsServerFeatureLevel level, usec_t rtt, size_t size);
6bb2c08597c999c429e889cd2403b2fef5f3e1a0Lennart Poetteringvoid dns_server_packet_lost(DnsServer *s, int protocol, DnsServerFeatureLevel level, usec_t usec);
f4461e5641d53f27d6e76e0607bdaa9c0c58c1f6Lennart Poetteringvoid dns_server_packet_failed(DnsServer *s, DnsServerFeatureLevel level);
6bb2c08597c999c429e889cd2403b2fef5f3e1a0Lennart Poetteringvoid dns_server_packet_truncated(DnsServer *s, DnsServerFeatureLevel level);
de54e62b4bd7856fb897c9a2ee93cc228adb2135Lennart Poetteringvoid dns_server_packet_rrsig_missing(DnsServer *s, DnsServerFeatureLevel level);
de54e62b4bd7856fb897c9a2ee93cc228adb2135Lennart Poetteringvoid dns_server_packet_bad_opt(DnsServer *s, DnsServerFeatureLevel level);
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen
f4461e5641d53f27d6e76e0607bdaa9c0c58c1f6Lennart PoetteringDnsServerFeatureLevel dns_server_possible_feature_level(DnsServer *s);
f4461e5641d53f27d6e76e0607bdaa9c0c58c1f6Lennart Poettering
519ef04651b07a547f010d6462603669d7fde4e5Lennart Poetteringint dns_server_adjust_opt(DnsServer *server, DnsPacket *packet, DnsServerFeatureLevel level);
519ef04651b07a547f010d6462603669d7fde4e5Lennart Poettering
6cb08a8930bdaca950b152b1e8b82466ed59511cLennart Poetteringconst char *dns_server_string(DnsServer *server);
6cb08a8930bdaca950b152b1e8b82466ed59511cLennart Poettering
92ec902aad1ade7acbe50efd7b8ef87fbdc63af3Lennart Poetteringbool dns_server_dnssec_supported(DnsServer *server);
92ec902aad1ade7acbe50efd7b8ef87fbdc63af3Lennart Poettering
1e02e182f1e06fcbe389474175de228103be39cbLennart Poetteringvoid dns_server_warn_downgrade(DnsServer *server);
1e02e182f1e06fcbe389474175de228103be39cbLennart Poettering
4b95f1798f22c1bb75295f448188560cb6ec9eceLennart PoetteringDnsServer *dns_server_find(DnsServer *first, int family, const union in_addr_union *in_addr);
4b95f1798f22c1bb75295f448188560cb6ec9eceLennart Poettering
4b95f1798f22c1bb75295f448188560cb6ec9eceLennart Poetteringvoid dns_server_unlink_all(DnsServer *first);
4b95f1798f22c1bb75295f448188560cb6ec9eceLennart Poetteringvoid dns_server_unlink_marked(DnsServer *first);
4b95f1798f22c1bb75295f448188560cb6ec9eceLennart Poetteringvoid dns_server_mark_all(DnsServer *first);
f2f1dbe50fea13abadc9c1e845a29031b90b40f3Lennart Poettering
4b95f1798f22c1bb75295f448188560cb6ec9eceLennart PoetteringDnsServer *manager_get_first_dns_server(Manager *m, DnsServerType t);
636e813dc98ea40c58c6c85bc5e7e3c9f0904ea2Lennart Poettering
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart PoetteringDnsServer *manager_set_dns_server(Manager *m, DnsServer *s);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart PoetteringDnsServer *manager_get_dns_server(Manager *m);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poetteringvoid manager_next_dns_server(Manager *m);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering
8300ba218e3cf5049496937be8bce10f22d09bbcTom GundersenDEFINE_TRIVIAL_CLEANUP_FUNC(DnsServer*, dns_server_unref);
8300ba218e3cf5049496937be8bce10f22d09bbcTom Gundersen
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidtextern const struct hash_ops dns_server_hash_ops;