/usr/include/dnscore/dns-udp.h is in libyadifa-dev 2.1.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | /*------------------------------------------------------------------------------
*
* Copyright (c) 2011-2016, EURid. All rights reserved.
* The YADIFA TM software product is provided under the BSD 3-clause license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of EURid nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*------------------------------------------------------------------------------
*
*/
#ifndef DNS_UDP_H
#define DNS_UDP_H
#include <dnscore/host_address.h>
#include <dnscore/message.h>
#include <dnscore/mutex.h>
#include <dnscore/async.h>
// error codes
#define DNS_UDP_TIMEOUT 0x81000001
#define DNS_UDP_INTERNAL 0x81000002
#define DNS_UDP_CANCEL 0x81000003
//
#define DNS_UDP_TIMEOUT_US 3000000 // 3s
#define DNS_UDP_TIMEOUT_US_MIN 1000000 // 1s
#define DNS_UDP_TIMEOUT_US_MAX 3600000000// 1h
#define DNS_UDP_SEND_RATE 1000000 // 1MB/s
#define DNS_UDP_SEND_RATE_MIN 512 // 512B/s
#define DNS_UDP_SEND_RATE_MAX 100000000 // 100MB/s
#define DNS_UDP_SEND_QUEUE 200000 // 200000 messages
#define DNS_UDP_SEND_QUEUE_MIN 1
#define DNS_UDP_SEND_QUEUE_MAX 0x1000000 // 16.7M messages
#define DNS_UDP_PORT_COUNT 256 // A.K.A workers
#define DNS_UDP_PORT_COUNT_MIN 1
#define DNS_UDP_PORT_COUNT_MAX 4000
#define DNS_UDP_RETRY_COUNT 2 // tries after the first failure
#define DNS_UDP_RETRY_COUNT_MIN 0
#define DNS_UDP_RETRY_COUNT_MAX 16
#define DNS_SIMPLE_MESSAGE_HAS_WAIT_COND 0
#define DNS_SIMPLE_MESSAGE_FLAGS_DNSSEC MESSAGE_EDNS0_DNSSEC
#define DNS_SIMPLE_MESSAGE_STATUS_QUEUED 0x01
#define DNS_SIMPLE_MESSAGE_STATUS_COLLECTED 0x02
#define DNS_SIMPLE_MESSAGE_STATUS_SENT 0x04
#define DNS_SIMPLE_MESSAGE_STATUS_AGGREGATED 0x08
#define DNS_SIMPLE_MESSAGE_STATUS_RECEIVED 0x10
#define DNS_SIMPLE_MESSAGE_STATUS_TIMEDOUT 0x20
#define DNS_SIMPLE_MESSAGE_STATUS_FAILURE 0x40
#define DNS_SIMPLE_MESSAGE_STATUS_INVALID 0x80
struct dns_udp_settings_s
{
u64 timeout;
u32 send_rate;
u32 queue_size;
u32 port_count;
u32 retry_count;
};
typedef struct dns_udp_settings_s dns_udp_settings_s;
// reference count common to all dns_simple_message (aggregation of answer for same query)
struct dns_simple_message_async_node_s
{
struct dns_simple_message_async_node_s *next;
async_message_s *async;
};
typedef struct dns_simple_message_async_node_s dns_simple_message_async_node_s;
/*
* This is basically a DNS query descriptor (retries and all)
*/
struct dns_simple_message_s
{
host_address *name_server;
message_data *answer; // answer, can be shared
dns_simple_message_async_node_s async_node;
volatile s64 queued_time_us;
volatile s64 sent_time_us;
volatile s64 received_time_us;
smp_int rc; // number of references for this message
group_mutex_t mtx;
volatile pthread_t owner;
u32 worker_index;
u16 qtype;
u16 qclass;
u16 flags;
u16 source_port;
u16 dns_id;
u8 retries_left;
u8 status;
bool recurse;
u8 fqdn[MAX_DOMAIN_LENGTH];
};
typedef struct dns_simple_message_s dns_simple_message_s;
/**
* This needs to be called before dns_udp_handler_init() or some settings will not be taken
* into account
*
* @param settings that will be used by the dns_udp handler
*/
void dns_udp_handler_configure(const dns_udp_settings_s *settings);
int dns_udp_handler_init();
int dns_udp_handler_start();
int dns_udp_handler_stop();
int dns_udp_handler_finalize();
/**
* Cancels all pending queries.
* Their handlers will be called with the error message DNS_UDP_CANCEL
* The purpose is cleaning up before shutdown.
*/
void dns_udp_cancel_all_queries();
int dns_udp_send_simple_message(const host_address* name_server, const u8 *fqdn, u16 qtype, u16 qclass, u16 flags, async_done_callback *cb, void* cbargs);
int dns_udp_send_recursive_message(const host_address* name_server, const u8 *fqdn, u16 qtype, u16 qclass, u16 flags, async_done_callback *cb, void* cbargs);
int dns_udp_send_simple_message_sync(const host_address* name_server, const u8 *fqdn, u16 qtype, u16 qclass,u16 flags, dns_simple_message_s **to_release);
int dns_udp_send_recursive_message_sync(const host_address* name_server, const u8 *fqdn, u16 qtype, u16 qclass,u16 flags, dns_simple_message_s **to_release);
bool dns_udp_simple_message_trylock(dns_simple_message_s *simple_message);
void dns_udp_simple_message_lock(dns_simple_message_s *simple_message);
void dns_udp_simple_message_unlock(dns_simple_message_s *simple_message);
void dns_udp_simple_message_retain(dns_simple_message_s *simple_message);
void dns_udp_simple_message_release(dns_simple_message_s *simple_message);
static inline const message_data *dns_udp_simple_message_get_answer(const dns_simple_message_s *simple_message)
{
return simple_message->answer;
}
u32 dns_udp_send_queue_size();
u32 dns_udp_pending_queries_count();
u32 dns_udp_pending_feedback_count();
#endif // DNS_UDP_H
|