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
/*-
* cdns-rs - a simple sync/async DNS query library
* Copyright (C) 2020 Aleksandr Morozov, RELKOM s.r.o
* Copyright (C) 2021-2022 Aleksandr Morozov
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
//! cdns-rs
//!
//! An implementation of client side DNS query library - a resolver, a set of
//! routines that provide access to the Internet Domain Name System (DNS).
//!
//! This library provides both:
//! sync and async crates to query remote DNS servers and local hosts file.
//!
//! This code will be considered stable only when the major part of verion number
//! will reach v 1.x.x
//!
//! # Limitations
//!
//! - This library reads /etc/hosts and partially understands /etc/resolv.conf i.e
//! only 'nameserver' option is parsed at the moment.
//! - This library does not support TCP query at the moment.
//! - The nsswitch.conf is also ignored as this crate at the moment is not pretending
//! to be a glibc/libc replacement.
//! - Does not support DNS-over-TLS at the moment
//! - Does not support DNSSEC at the moment
//! - /etc/resolve.conf is limited to 'nameserver'
//!
//! # Supports
//!
//! Supported GNU/Linux and *BSD (incl OSX, but not guaranteed)
//!
//! # Layout
//!
//! Dirs:
//! - a_sync - contains all async code
//! - sync - contains all sync code
//! Files:
//! */*:
//! - portable.rs - contains the code which requres porting to other OS.
//! This code usually incompatiable with different UNIX-type OSes.
//! - error.rs - an error wrapper and mapper
//! - tokenizer.rs - contains simple tokenizer for parsing config files.
//! - read_only_cell.rs - an implementation of the once written cell for
//! initialization purposes.
//! - cfg_host_parser.rs - a common code for the /etc/host which is used by
//! both sync/async
//! - cfg_resolv_parser.rs - a common code for the /etc/resolv.conf which is
//! used by sync/async
//! - query.rs - a common code of query
//! - query_private.rs - internal items for query construction
//!
//! */sync/*:
//! - caches.rs - contains a cached in memory config files like /etc/hosts.
//! If file was modified, the cache controller attempts to reload file during
//! library call from main program. Sync realization of common file.
//! - cfg_parsers.rs - contains the confgiration files parsers.
//! - common.rs - this file contains all code related to DNS protocol i.e structures,
//! parsing.
//! - network.rs - a code which deals with networking part, i.e msg exchange with DNS
//! server.
//! - mutex.rs - a local implementaion of mutex for dafu usage in multithreading env.
//! Derived from rust's mutex implementation.
//! - poison.rs - a mutex poison detection derived from rust's code.
//! - query.rs - a file which contains main logic
//! - query_polltaps.rs - a pairing of socket with request depending on config
//! - query_private.rs - a sync realization of the common file
//! - request.rs - a pre-defined requests
//! - log.rs - a log facility
//!
//! Features:
//! - feature = "use_async" for asynchronious code (use cdns_rs::a_sync::{...};)
//! - feature = "use_sync" for synchronious code (use cdns_rs::sync::{...};)
//! - feature = "no_error_output" does not output error
//! - feature = "custom_error_output" outputs error to defined output
//! `no_error_output` and `custom_error_output` can not be defined simultaniously.
//!
//! If both `no_error_output` and `custom_error_output` are not defined then the errors
//! are output to stderr.
//!
//! All features can be used simultaniously.
//! # Usage
//!
//! i.e
//! cdns-rs = {version = "0.2", default-features = false, features = ["use_sync", "no_error_output"]}
//!
//! By default, both `use_async`, `use_sync`, `no_error_output` features are enabled.
//!
//! Example:
//! ```Rust
//!
//! extern crate cdns_rs;
//!
//! use cdns_rs::{QType, QDnsQueriesRes, QDnsQuery, QuerySetup, DnsRdata};
//! use cdns_rs::sync::QDns;
//! use cdns_rs::sync::caches::CACHE;
//!
//! fn main() {
//!
//! println!("Hello, world!");
//!
//! let resolvers = CACHE.clone_resolve_list().unwrap();
//!
//! let mut q = QDns::make_empty(resolvers, 1, QuerySetup::default());
//! q.add_request(QType::PTR, "127.0.0.1");
//!
//! let res = q.query().into_inner();
//!
//! if let Some(dq) = res
//! {
//! for d in dq
//! {
//! let resp = d.move_responses();
//!
//! for r in resp
//! {
//! match r.rdata
//! {
//! DnsRdata::PTR{fqdn} =>
//! {
//! println!("{}", fqdn);
//! },
//! _ => {}
//! }
//! }
//! }
//! }
//!
//! ```
extern crate rand;
#[macro_use] extern crate lazy_static;
//extern crate libc;
#[macro_use] extern crate bitflags;
extern crate nix;
//extern crate indexmap;
#[cfg(feature = "use_sync")]
extern crate byteorder;
#[cfg(feature = "use_sync")]
extern crate crossbeam_utils;
#[cfg(feature = "use_sync")]
pub mod sync;
#[cfg(feature = "use_async")]
extern crate async_recursion;
#[cfg(feature = "use_async")]
extern crate tokio;
#[cfg(feature = "use_async")]
extern crate tokio_byteorder;
#[cfg(feature = "use_async")]
extern crate async_trait;
#[cfg(feature = "use_async")]
pub mod a_sync;
pub mod cfg_host_parser;
pub mod cfg_resolv_parser;
mod query_private;
pub mod query;
pub mod common;
mod portable;
#[macro_use] pub mod error;
mod tokenizer;
mod read_only_cell;
pub use lazy_static::*;
pub use error::*;
pub use common::{QType, DnsResponsePayload, DnsRdata, DnsSoa};
pub use query::{QDnsQueriesRes, QDnsQuery, QuerySetup, QDnsQueryRec};