From 3882939d1c4a9dd37433f13b1f661616148b86d5 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 18 Jul 2024 17:55:48 +0200 Subject: [PATCH 01/17] Migrate to trust-dns 0.23 for async (WIP) --- Cargo.lock | 850 +++++++++++++++++++++------------------------ Cargo.toml | 17 +- src/dns/code.rs | 2 +- src/dns/handler.rs | 71 ++-- src/dns/listen.rs | 87 ++--- src/dns/record.rs | 24 +- src/dns/zone.rs | 2 +- 7 files changed, 500 insertions(+), 553 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76cea12..d24b51f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,11 +133,11 @@ dependencies = [ "futures-channel", "futures-util", "log", - "mio", + "mio 0.6.23", "mio-uds", "num_cpus", "slab", - "socket2", + "socket2 0.3.19", ] [[package]] @@ -161,7 +161,7 @@ dependencies = [ "actix-server", "actix-service", "log", - "socket2", + "socket2 0.3.19", ] [[package]] @@ -244,7 +244,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "socket2", + "socket2 0.3.19", "time 0.2.27", "tinyvec", "url 2.5.2", @@ -296,30 +296,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "anstream" version = "0.6.14" @@ -356,7 +332,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -366,7 +342,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -380,17 +356,6 @@ dependencies = [ "syn 2.0.71", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi 0.3.9", -] - [[package]] name = "autocfg" version = "1.3.0" @@ -421,21 +386,6 @@ dependencies = [ "serde_urlencoded", ] -[[package]] -name = "backtrace" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f" -dependencies = [ - "backtrace-sys", - "cfg-if 0.1.10", - "dbghelp-sys", - "kernel32-sys", - "libc", - "rustc-demangle", - "winapi 0.2.8", -] - [[package]] name = "backtrace" version = "0.3.73" @@ -451,16 +401,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "backtrace-sys" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "base-x" version = "0.2.11" @@ -561,35 +501,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chrono" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "js-sys", - "num-traits", - "wasm-bindgen", - "windows-targets", -] - -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", -] - [[package]] name = "clap" version = "4.5.9" @@ -608,7 +519,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.11.1", + "strsim", ] [[package]] @@ -654,7 +565,8 @@ version = "1.14.3" dependencies = [ "actix-web", "actix-web-httpauth", - "clap 4.5.9", + "async-trait", + "clap", "farmhash", "flate2", "futures 0.1.31", @@ -672,12 +584,9 @@ dependencies = [ "serde_json", "tar", "tempfile", - "tokio 0.1.22", - "tokio-tcp", - "tokio-udp", + "tokio 1.38.1", "toml 0.8.15", - "trust-dns", - "trust-dns-proto 0.4.3", + "trust-dns-proto 0.23.2", "trust-dns-resolver 0.10.3", "trust-dns-server", "url_serde", @@ -706,12 +615,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" -[[package]] -name = "core-foundation-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -785,33 +688,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] -name = "data-encoding-macro" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1559b6cba622276d6d63706db152618eeb15b89b3e4041446b05876e352e639" -dependencies = [ - "data-encoding", - "data-encoding-macro-internal", -] - -[[package]] -name = "data-encoding-macro-internal" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "332d754c0af53bc87c108fed664d121ecf59207ec4196041f04d6ab9002ad33f" -dependencies = [ - "data-encoding", - "syn 1.0.109", -] - -[[package]] -name = "dbghelp-sys" -version = "0.2.0" +name = "deranged" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "powerfmt", ] [[package]] @@ -842,6 +724,15 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" +[[package]] +name = "drain" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d105028bd2b5dfcb33318fd79a445001ead36004dd8dffef1bdd7e493d8bc1e" +dependencies = [ + "tokio 1.38.1", +] + [[package]] name = "dtoa" version = "0.4.8" @@ -863,12 +754,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - [[package]] name = "enum-as-inner" version = "0.3.4" @@ -882,16 +767,15 @@ dependencies = [ ] [[package]] -name = "env_logger" -version = "0.5.13" +name = "enum-as-inner" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" +checksum = "5ffccbb6966c05b32ef8fbac435df276c4ae4d3dc55a8cd0eb9745e6c12f546a" dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", + "heck", + "proc-macro2", + "quote", + "syn 2.0.71", ] [[package]] @@ -907,16 +791,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", - "windows-sys", -] - -[[package]] -name = "error-chain" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faa976b4fd2e4c2b2f3f486874b19e61944d3de3de8b61c9fcf835d583871bcc" -dependencies = [ - "backtrace 0.2.3", + "windows-sys 0.52.0", ] [[package]] @@ -925,7 +800,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6930e04918388a9a2e41d518c25cf679ccafe26733fb4127dbf21993f2575d46" dependencies = [ - "backtrace 0.3.73", + "backtrace", ] [[package]] @@ -934,7 +809,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" dependencies = [ - "backtrace 0.3.73", + "backtrace", "failure_derive", ] @@ -971,7 +846,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall 0.4.1", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1057,6 +932,17 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.30" @@ -1189,15 +1075,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.9" @@ -1245,38 +1122,6 @@ version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - [[package]] name = "idna" version = "0.1.5" @@ -1299,6 +1144,16 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "0.5.0" @@ -1353,8 +1208,8 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08f7eadeaf4b52700de180d147c4805f199854600b36faa963d91114827b2ffc" dependencies = [ - "error-chain 0.8.1", - "socket2", + "error-chain", + "socket2 0.3.19", "widestring 0.2.2", "winapi 0.3.9", "winreg 0.5.1", @@ -1366,12 +1221,30 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" dependencies = [ - "socket2", + "socket2 0.3.19", "widestring 0.4.3", "winapi 0.3.9", "winreg 0.6.2", ] +[[package]] +name = "ipconfig" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" +dependencies = [ + "socket2 0.5.7", + "widestring 1.1.0", + "windows-sys 0.48.0", + "winreg 0.50.0", +] + +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + [[package]] name = "ipnetwork" version = "0.20.0" @@ -1436,16 +1309,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "libsqlite3-sys" -version = "0.9.1" -source = "git+https://github.com/rusqlite/rusqlite?rev=aa64e2fb33755c696337d443ac4e8af93551ad05#aa64e2fb33755c696337d443ac4e8af93551ad05" -dependencies = [ - "cc", - "pkg-config", - "vcpkg", -] - [[package]] name = "linked-hash-map" version = "0.5.6" @@ -1571,6 +1434,17 @@ dependencies = [ "winapi 0.2.8", ] +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.48.0", +] + [[package]] name = "mio-uds" version = "0.6.8" @@ -1579,7 +1453,7 @@ checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", - "mio", + "mio 0.6.23", ] [[package]] @@ -1606,19 +1480,10 @@ dependencies = [ ] [[package]] -name = "nibble_vec" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d77f3db4bce033f4d04db08079b2ef1c3d02b44e86f25d08886fafa7756ffa" - -[[package]] -name = "num-traits" -version = "0.2.19" +name = "num-conv" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num_cpus" @@ -1626,7 +1491,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.9", + "hermit-abi", "libc", ] @@ -1722,7 +1587,7 @@ dependencies = [ "libc", "redox_syscall 0.5.3", "smallvec 1.13.2", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1796,10 +1661,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "pkg-config" -version = "0.3.30" +name = "powerfmt" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" @@ -1858,29 +1723,6 @@ dependencies = [ "redis", ] -[[package]] -name = "radix_trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3681b28cd95acfb0560ea9441f82d6a4504fa3b15b97bd7b6e952131820e95" -dependencies = [ - "endian-type", - "nibble_vec", -] - -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi 0.3.9", -] - [[package]] name = "rand" version = "0.5.6" @@ -1980,15 +1822,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redis" version = "0.20.2" @@ -2088,28 +1921,32 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.8" +version = "0.16.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" dependencies = [ "cc", - "cfg-if 1.0.0", - "getrandom 0.2.15", "libc", - "spin", - "untrusted", - "windows-sys", + "once_cell", + "spin 0.5.2", + "untrusted 0.7.1", + "web-sys", + "winapi 0.3.9", ] [[package]] -name = "rusqlite" -version = "0.13.0" -source = "git+https://github.com/rusqlite/rusqlite?rev=aa64e2fb33755c696337d443ac4e8af93551ad05#aa64e2fb33755c696337d443ac4e8af93551ad05" +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ - "bitflags 1.3.2", - "libsqlite3-sys", - "lru-cache", - "time 0.1.45", + "cc", + "cfg-if 1.0.0", + "getrandom 0.2.15", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys 0.52.0", ] [[package]] @@ -2146,7 +1983,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -2156,7 +1993,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring", + "ring 0.17.8", "rustls-webpki", "sct", ] @@ -2176,8 +2013,8 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] [[package]] @@ -2207,8 +2044,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] [[package]] @@ -2356,6 +2193,22 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -2420,12 +2273,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.11.1" @@ -2486,25 +2333,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand", "rustix", - "windows-sys", -] - -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", + "windows-sys 0.52.0", ] [[package]] @@ -2536,17 +2365,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", -] - [[package]] name = "time" version = "0.2.27" @@ -2562,6 +2380,25 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + [[package]] name = "time-macros" version = "0.1.1" @@ -2608,7 +2445,7 @@ checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" dependencies = [ "bytes 0.4.12", "futures 0.1.31", - "mio", + "mio 0.6.23", "num_cpus", "tokio-codec", "tokio-current-thread", @@ -2636,7 +2473,7 @@ dependencies = [ "lazy_static", "libc", "memchr", - "mio", + "mio 0.6.23", "mio-uds", "pin-project-lite 0.1.12", "signal-hook-registry", @@ -2644,6 +2481,23 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "tokio" +version = "1.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb2caba9f80616f438e09748d5acda951967e1ea58508ef53d9c6402485a46df" +dependencies = [ + "backtrace", + "bytes 1.6.1", + "libc", + "mio 0.8.11", + "num_cpus", + "pin-project-lite 0.2.14", + "socket2 0.5.7", + "tokio-macros", + "windows-sys 0.48.0", +] + [[package]] name = "tokio-codec" version = "0.1.2" @@ -2697,6 +2551,17 @@ dependencies = [ "log", ] +[[package]] +name = "tokio-macros" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + [[package]] name = "tokio-reactor" version = "0.1.12" @@ -2707,7 +2572,7 @@ dependencies = [ "futures 0.1.31", "lazy_static", "log", - "mio", + "mio 0.6.23", "num_cpus", "parking_lot 0.9.0", "slab", @@ -2735,7 +2600,7 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.31", "iovec", - "mio", + "mio 0.6.23", "tokio-io", "tokio-reactor", ] @@ -2778,7 +2643,7 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.31", "log", - "mio", + "mio 0.6.23", "tokio-codec", "tokio-io", "tokio-reactor", @@ -2795,7 +2660,7 @@ dependencies = [ "iovec", "libc", "log", - "mio", + "mio 0.6.23", "mio-uds", "tokio-codec", "tokio-io", @@ -2818,11 +2683,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.10" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" dependencies = [ "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.19.15", ] [[package]] @@ -2834,7 +2702,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.22.16", ] [[package]] @@ -2846,6 +2714,19 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.2.6", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.5.40", +] + [[package]] name = "toml_edit" version = "0.22.16" @@ -2856,7 +2737,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.13", ] [[package]] @@ -2867,9 +2748,21 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite 0.2.14", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -2889,51 +2782,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "trust-dns" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a97b39064a4786506e855616a0f8869d461a1cb7449c6064a229eaea4e53b45" -dependencies = [ - "chrono", - "data-encoding", - "data-encoding-macro", - "error-chain 0.1.12", - "futures 0.1.31", - "lazy_static", - "log", - "radix_trie", - "rand 0.4.6", - "tokio 0.1.22", - "tokio-tcp", - "trust-dns-proto 0.4.3", -] - -[[package]] -name = "trust-dns-proto" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1525ca4e26f5a09d81b79584f19225e7dba5606ae3a416311c2751c5cea60bb" -dependencies = [ - "byteorder", - "data-encoding", - "error-chain 0.1.12", - "futures 0.1.31", - "idna 0.1.5", - "lazy_static", - "log", - "rand 0.4.6", - "smallvec 0.6.14", - "socket2", - "tokio-executor", - "tokio-io", - "tokio-reactor", - "tokio-tcp", - "tokio-timer", - "tokio-udp", - "url 1.7.2", -] - [[package]] name = "trust-dns-proto" version = "0.6.3" @@ -2948,7 +2796,7 @@ dependencies = [ "log", "rand 0.5.6", "smallvec 0.6.14", - "socket2", + "socket2 0.3.19", "tokio-executor", "tokio-io", "tokio-reactor", @@ -2966,7 +2814,7 @@ checksum = "1cad71a0c0d68ab9941d2fb6e82f8fb2e86d9945b94e1661dd0aaea2b88215a9" dependencies = [ "async-trait", "cfg-if 1.0.0", - "enum-as-inner", + "enum-as-inner 0.3.4", "futures 0.3.30", "idna 0.2.3", "lazy_static", @@ -2978,6 +2826,33 @@ dependencies = [ "url 2.5.2", ] +[[package]] +name = "trust-dns-proto" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3119112651c157f4488931a01e586aa459736e9d6046d3bd9105ffb69352d374" +dependencies = [ + "async-trait", + "cfg-if 1.0.0", + "data-encoding", + "enum-as-inner 0.6.0", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.4.0", + "ipnet", + "once_cell", + "rand 0.8.5", + "ring 0.16.20", + "serde", + "smallvec 1.13.2", + "thiserror", + "tinyvec", + "tokio 1.38.1", + "tracing", + "url 2.5.2", +] + [[package]] name = "trust-dns-resolver" version = "0.10.3" @@ -3016,34 +2891,49 @@ dependencies = [ "trust-dns-proto 0.19.7", ] +[[package]] +name = "trust-dns-resolver" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a3e6c3aff1718b3c73e395d1f35202ba2ffa847c6a62eea0db8fb4cfe30be6" +dependencies = [ + "cfg-if 1.0.0", + "futures-util", + "ipconfig 0.3.2", + "lru-cache", + "once_cell", + "parking_lot 0.12.3", + "rand 0.8.5", + "resolv-conf 0.7.0", + "serde", + "smallvec 1.13.2", + "thiserror", + "tokio 1.38.1", + "tracing", + "trust-dns-proto 0.23.2", +] + [[package]] name = "trust-dns-server" -version = "0.14.0" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1131006e450cab1dfb4617fc7e2088c19d62d144ac6f901dcedb4994e136a0bf" +checksum = "c540f73c2b2ec2f6c54eabd0900e7aafb747a820224b742f556e8faabb461bc7" dependencies = [ - "backtrace 0.3.73", - "chrono", - "clap 2.34.0", - "env_logger", - "error-chain 0.1.12", - "futures 0.1.31", - "lazy_static", - "log", - "rand 0.4.6", - "rusqlite", + "async-trait", + "bytes 1.6.1", + "cfg-if 1.0.0", + "drain", + "enum-as-inner 0.6.0", + "futures-executor", + "futures-util", "serde", - "serde_derive", - "time 0.1.45", - "tokio 0.1.22", - "tokio-executor", - "tokio-reactor", - "tokio-tcp", - "tokio-timer", - "tokio-udp", - "toml 0.4.10", - "trust-dns", - "trust-dns-proto 0.4.3", + "thiserror", + "time 0.3.36", + "tokio 1.38.1", + "toml 0.7.8", + "tracing", + "trust-dns-proto 0.23.2", + "trust-dns-resolver 0.23.2", ] [[package]] @@ -3082,18 +2972,18 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" - [[package]] name = "unicode-xid" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "untrusted" version = "0.9.0" @@ -3120,6 +3010,7 @@ dependencies = [ "form_urlencoded", "idna 0.5.0", "percent-encoding 2.3.1", + "serde", ] [[package]] @@ -3138,18 +3029,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" @@ -3162,12 +3041,6 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -3228,14 +3101,24 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webpki" version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] [[package]] @@ -3256,6 +3139,12 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" +[[package]] +name = "widestring" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" + [[package]] name = "winapi" version = "0.2.8" @@ -3284,15 +3173,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" -dependencies = [ - "windows-sys", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -3300,12 +3180,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows-core" -version = "0.52.0" +name = "windows-sys" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -3314,7 +3194,22 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -3323,28 +3218,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -3357,30 +3270,63 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + [[package]] name = "winnow" version = "0.6.13" @@ -3408,6 +3354,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if 1.0.0", + "windows-sys 0.48.0", +] + [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 8593066..f71768d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,19 +26,21 @@ serde_derive = "1.0" serde_json = "1.0" url_serde = { version = "0.2", default-features = false } regex = "1.10" +async-trait = "0.1" r2d2 = "0.8" r2d2_redis = "0.14" redis = "0.20" actix-web = { version = "3.3", default-features = false } actix-web-httpauth = "0.5" -trust-dns = { version = "0.14", default-features = false } -trust-dns-server = { version = "0.14", default-features = false } -trust-dns-proto = { version = "0.4", default-features = false } +trust-dns-server = { version = "0.23", default-features = false, features = [ + "dnssec-ring", +] } +trust-dns-proto = { version = "0.23", default-features = false, features = [ + "dnssec-ring", +] } trust-dns-resolver = { version = "0.10", default-features = false } futures = "0.1" -tokio = "0.1" -tokio-tcp = "0.1" -tokio-udp = "0.1" +tokio = "1.21" rand = "0.8" farmhash = "1.1" http_req = { version = "0.10", features = [ @@ -49,9 +51,6 @@ tempfile = "3.1" flate2 = "1.0" tar = "0.4" -[patch.crates-io] -rusqlite = { git = "https://github.com/rusqlite/rusqlite", rev = "aa64e2fb33755c696337d443ac4e8af93551ad05" } - [profile.dev] opt-level = 0 debug = true diff --git a/src/dns/code.rs b/src/dns/code.rs index 4b3814d..696f1b7 100644 --- a/src/dns/code.rs +++ b/src/dns/code.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -use trust_dns::op::ResponseCode; +use trust_dns_proto::op::ResponseCode; #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)] pub enum CodeName { diff --git a/src/dns/handler.rs b/src/dns/handler.rs index 20c6c0a..bb2bd74 100644 --- a/src/dns/handler.rs +++ b/src/dns/handler.rs @@ -7,16 +7,18 @@ use rand::seq::SliceRandom; use rand::thread_rng; use std::collections::HashMap; +use std::future::Future; use std::io::Error; use std::net::IpAddr; -use trust_dns::op::{LowerQuery, MessageType, OpCode, ResponseCode}; -use trust_dns::rr::dnssec::SupportedAlgorithms; -use trust_dns::rr::{LowerName, Name, Record, RecordType as TrustRecordType}; use trust_dns_proto::op::header::Header; +use trust_dns_proto::op::{LowerQuery, MessageType, OpCode, ResponseCode}; +use trust_dns_proto::rr::dnssec::SupportedAlgorithms; +use trust_dns_proto::rr::{LowerName, Name, Record, RecordType as TrustRecordType}; use trust_dns_server::authority::{ - AuthLookup, Authority, MessageRequest, MessageResponse, MessageResponseBuilder, + AuthLookup, Authority, LookupOptions, MessageRequest, MessageResponse, MessageResponseBuilder, }; -use trust_dns_server::server::{Request, RequestHandler, ResponseHandler}; +use trust_dns_server::server::{Request, RequestHandler, ResponseHandler, ResponseInfo}; +use trust_dns_server::store::in_memory::InMemoryAuthority; use super::code::CodeName; use super::flatten::DNS_FLATTEN; @@ -30,17 +32,20 @@ use crate::store::store::{StoreAccessOrigin, StoreError, StoreRecord}; use crate::APP_CONF; use crate::APP_STORE; +pub type DNSAuthority = InMemoryAuthority; + pub struct DNSHandler { - authorities: HashMap, + authorities: HashMap, } +#[async_trait::async_trait] impl RequestHandler for DNSHandler { - fn handle_request( + async fn handle_request( &self, request: &Request, response_handle: R, - ) -> Result<(), Error> { - let request_message = &request.message; + ) -> ResponseInfo { + let request_message = **request; trace!("request: {:?}", request_message); @@ -49,12 +54,12 @@ impl RequestHandler for DNSHandler { OpCode::Query => { info!("lookup request with id: {}", request_message.id()); - self.lookup(request.src.ip(), request_message, response_handle) + self.lookup(request.src().ip(), request_message, response_handle) } code @ _ => { error!("unimplemented opcode: {:?}", code); - self.not_impl(request_message, response_handle) + self.not_impl(&request_message, response_handle) } }, MessageType::Response => { @@ -63,7 +68,7 @@ impl RequestHandler for DNSHandler { request_message.id() ); - self.not_impl(request_message, response_handle) + self.not_impl(&request_message, response_handle) } } } @@ -76,14 +81,14 @@ impl DNSHandler { } } - pub fn upsert(&mut self, name: LowerName, authority: Authority) { + pub fn upsert(&mut self, name: LowerName, authority: DNSAuthority) { self.authorities.insert(name, authority); } - fn lookup<'a, R: ResponseHandler>( - &'a self, + fn lookup( + &self, source: IpAddr, - request: &'a MessageRequest<'a>, + request: MessageRequest, response_handle: R, ) -> Result<(), Error> { // Initialize response builder @@ -132,18 +137,19 @@ impl DNSHandler { // Acquire SOA records let supported_algorithms = SupportedAlgorithms::new(); + let lookup_options = LookupOptions::for_dnssec(false, supported_algorithms); - let soa_records = authority.soa_secure(false, supported_algorithms); + let soa_records = authority.soa_secure(lookup_options); let soa_records_vec = soa_records.iter().collect(); // #4. Attempt to resolve from local store - let records_local = authority.search(query, false, supported_algorithms); + let records_local = authority.search(query, lookup_options); if !records_local.is_empty() { let records_local_vec = records_local.iter().collect(); return self.lookup_local( - request, + &request, response, header, query, @@ -169,7 +175,7 @@ impl DNSHandler { let records_remote_vec = records_remote_inner.iter().collect(); Self::serve_response_records( - request, + &request, &mut response, &mut header, &zone_name, @@ -200,7 +206,7 @@ impl DNSHandler { }; Self::stamp_response( - request, + &request, &mut response, &mut header, authority, @@ -218,7 +224,7 @@ impl DNSHandler { debug!("query refused for: {:?} because: {}", query, err); Self::stamp_response( - request, + &request, &mut response, &mut header, authority, @@ -278,7 +284,7 @@ impl DNSHandler { mut response: MessageResponseBuilder<'_, 'a>, mut header: Header, query: &LowerQuery, - authority: &'a Authority, + authority: &'a DNSAuthority, zone_name: Option, soa_records: Vec<&'a Record>, local_records: Vec<&'a Record>, @@ -326,7 +332,7 @@ impl DNSHandler { response_handle.send(response_message) } - fn find_auth_recurse(&self, name: &LowerName) -> Option<&Authority> { + fn find_auth_recurse(&self, name: &LowerName) -> Option<&DNSAuthority> { let authority = self.authorities.get(name); if authority.is_some() { @@ -343,7 +349,7 @@ impl DNSHandler { } fn records_from_store( - authority: &Authority, + authority: &DNSAuthority, zone_name: &Option, source: IpAddr, query: &LowerQuery, @@ -411,7 +417,7 @@ impl DNSHandler { } fn records_from_store_attempt( - authority: &Authority, + authority: &DNSAuthority, source: IpAddr, zone_name: &Option, query_name_client: &LowerName, @@ -726,12 +732,15 @@ impl DNSHandler { // Append final prepared values to response for value in final_values { if let Ok(value_data) = value.to_trust(final_kind) { - records.push(Record::from_rdata( + let mut record = Record::from_rdata( Name::from(query_name_client.to_owned()), record_ttl, - final_type, value_data, - )); + ); + + record.set_record_type(final_type); + + records.push(record); } else { warn!( "could not convert to dns record type: {} with value: {:?}", @@ -757,7 +766,7 @@ impl DNSHandler { header: &'b mut Header, zone_name: &Option, mut records: Vec<&'a Record>, - authority: &'a Authority, + authority: &'a DNSAuthority, soa_records: Vec<&'a Record>, ) { let has_records = !records.is_empty(); @@ -789,7 +798,7 @@ impl DNSHandler { request: &MessageRequest, response: &'b mut MessageResponseBuilder<'_, 'a>, header: &mut Header, - authority: &'a Authority, + authority: &'a DNSAuthority, soa_records: Vec<&'a Record>, code: ResponseCode, zone_name: &Option, diff --git a/src/dns/listen.rs b/src/dns/listen.rs index 77280b5..5f9cce7 100644 --- a/src/dns/listen.rs +++ b/src/dns/listen.rs @@ -4,19 +4,16 @@ // Copyright: 2018, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -use futures::{future, Future}; use std::collections::BTreeMap; -use std::io::{Error, ErrorKind}; use std::time::Duration; -use tokio::runtime::current_thread::Runtime; -use tokio_tcp::TcpListener; -use tokio_udp::UdpSocket; -use trust_dns::rr::rdata::SOA; -use trust_dns::rr::{LowerName, Name, RData, Record, RecordSet, RecordType, RrKey}; -use trust_dns_server::authority::{Authority, ZoneType}; +use tokio::net::{TcpListener, UdpSocket}; +use trust_dns_proto::rr::rdata as TrustRData; +use trust_dns_proto::rr::record_data::RData; +use trust_dns_proto::rr::{LowerName, Name, Record, RecordSet, RecordType, RrKey}; +use trust_dns_server::authority::ZoneType; use trust_dns_server::server::ServerFuture; -use super::handler::DNSHandler; +use super::handler::{DNSAuthority, DNSHandler}; use crate::APP_CONF; lazy_static! { @@ -39,7 +36,8 @@ impl DNSListenBuilder { } impl DNSListen { - pub fn run(&self) { + #[tokio::main] + pub async fn run(&self) { // Run the DNS server let mut handler: DNSHandler = DNSHandler::new(); @@ -50,47 +48,33 @@ impl DNSListen { } } - let mut runtime = Runtime::new().expect("error when creating dns listen runtime"); - let server = ServerFuture::new(handler); - - let server_future: Box + Send> = - Box::new(future::lazy(move || { - // Register sockets & listeners - for inet in &APP_CONF.dns.inets { - let udp_socket = - UdpSocket::bind(inet).expect(&format!("udp bind failed: {}", inet)); - let tcp_listener = - TcpListener::bind(inet).expect(&format!("tcp bind failed: {}", inet)); - - info!("will listen for udp on {:?}", udp_socket); - server.register_socket(udp_socket); - - info!("will listen for tcp on {:?}", tcp_listener); - server - .register_listener( - tcp_listener, - Duration::from_secs(APP_CONF.dns.tcp_timeout), - ) - .expect("could not register tcp listener"); - } - - future::empty() - })); + let mut server = ServerFuture::new(handler); + + // Register sockets & listeners + for inet in &APP_CONF.dns.inets { + let udp_socket = UdpSocket::bind(inet) + .await + .expect(&format!("udp bind failed: {}", inet)); + let tcp_listener = TcpListener::bind(inet) + .await + .expect(&format!("tcp bind failed: {}", inet)); + + info!("will listen for udp on {:?}", udp_socket); + server.register_socket(udp_socket); + + info!("will listen for tcp on {:?}", tcp_listener); + server.register_listener(tcp_listener, Duration::from_secs(APP_CONF.dns.tcp_timeout)); + } // Listen for connections info!("listening for dns connections"); - if let Err(err) = runtime.block_on(server_future.map_err(|_| { - Error::new( - ErrorKind::Interrupted, - "server stopping due to interruption", - ) - })) { + if let Err(err) = server.block_until_done().await { error!("failed to listen on dns: {}", err); } } - fn map_authority(zone_name: &str) -> Result<(Name, Authority), ()> { + fn map_authority(zone_name: &str) -> Result<(Name, DNSAuthority), ()> { if let Ok(name) = Name::parse(zone_name, Some(&Name::new())) { let mut records = BTreeMap::new(); @@ -98,8 +82,7 @@ impl DNSListen { let soa_records = RecordSet::from(Record::from_rdata( name.to_owned(), APP_CONF.dns.record_ttl, - RecordType::SOA, - RData::SOA(SOA::new( + RData::SOA(TrustRData::SOA::new( NAME_SOA_MASTER.to_owned(), NAME_SOA_RESPONSIBLE.to_owned(), SERIAL_DEFAULT, @@ -123,11 +106,10 @@ impl DNSListen { Record::from_rdata( name.to_owned(), APP_CONF.dns.record_ttl, - RecordType::NS, - RData::NS( + RData::NS(TrustRData::NS( Name::parse(nameserver, Some(&Name::new())) .expect("invalid nameserver"), - ), + )), ), SERIAL_DEFAULT, ); @@ -138,10 +120,11 @@ impl DNSListen { ns_records, ); - Ok(( - name.to_owned(), - Authority::new(name, records, ZoneType::Master, false, false), - )) + // Build authority instance + let authority = + DNSAuthority::new(name.clone(), records, ZoneType::Primary, false).or(Err(()))?; + + Ok((name, authority)) } else { Err(()) } diff --git a/src/dns/record.rs b/src/dns/record.rs index 2d2e3fd..ea190ad 100644 --- a/src/dns/record.rs +++ b/src/dns/record.rs @@ -11,11 +11,9 @@ use std::cmp; use std::collections::HashSet; use std::ops::Deref; use std::{fmt, str}; -use trust_dns::rr::rdata::mx::MX; -use trust_dns::rr::rdata::txt::TXT; -use trust_dns::rr::{ - LowerName as TrustLowerName, Name as TrustName, RData as TrustRData, - RecordType as TrustRecordType, +use trust_dns_proto::rr::rdata as TrustRData; +use trust_dns_proto::rr::{ + LowerName as TrustLowerName, Name as TrustName, RData, RecordType as TrustRecordType, }; use crate::geo::country::CountryCode; @@ -186,22 +184,24 @@ impl RecordName { } impl RecordValue { - pub fn to_trust(&self, record_type: &RecordType) -> Result { + pub fn to_trust(&self, record_type: &RecordType) -> Result { match record_type { RecordType::A => { // Parse A into actual IPv4 - self.parse().map(|value| TrustRData::A(value)).or(Err(())) + self.parse() + .map(|value| RData::A(TrustRData::a::A(value))) + .or(Err(())) } RecordType::AAAA => { // Parse AAAA into actual IPv6 self.parse() - .map(|value| TrustRData::AAAA(value)) + .map(|value| RData::AAAA(TrustRData::aaaa::AAAA(value))) .or(Err(())) } RecordType::CNAME => { // Parse CNAME into domain name TrustName::parse(self, Some(&TrustName::new())) - .map(|value| TrustRData::CNAME(value)) + .map(|value| RData::CNAME(TrustRData::name::CNAME(value))) .or(Err(())) } RecordType::MX => { @@ -215,7 +215,7 @@ impl RecordValue { priority_str.parse::(), TrustName::parse(exchange_str, Some(&TrustName::new())), ) { - Ok(TrustRData::MX(MX::new(priority, exchange))) + Ok(RData::MX(TrustRData::mx::MX::new(priority, exchange))) } else { Err(()) } @@ -235,13 +235,13 @@ impl RecordValue { } if !txt_splits.is_empty() { - Ok(TrustRData::TXT(TXT::new(txt_splits))) + Ok(RData::TXT(TrustRData::txt::TXT::new(txt_splits))) } else { Err(()) } } RecordType::PTR => TrustName::parse(self, Some(&TrustName::new())) - .map(|value| TrustRData::PTR(value)) + .map(|value| RData::PTR(TrustRData::PTR(value))) .or(Err(())), } } diff --git a/src/dns/zone.rs b/src/dns/zone.rs index efa5e51..b9132d3 100644 --- a/src/dns/zone.rs +++ b/src/dns/zone.rs @@ -8,7 +8,7 @@ use regex::Regex; use serde::de::{Error as DeserializeError, Unexpected, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::{fmt, str}; -use trust_dns::rr::LowerName as TrustLowerName; +use trust_dns_proto::rr::LowerName as TrustLowerName; use crate::APP_CONF; From dced64ec749602876af53f93bf5a9affd2c925bf Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 18 Jul 2024 18:24:23 +0200 Subject: [PATCH 02/17] Convert handler pipeline to async --- src/dns/handler.rs | 160 ++++++++++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 66 deletions(-) diff --git a/src/dns/handler.rs b/src/dns/handler.rs index bb2bd74..9ba4dc0 100644 --- a/src/dns/handler.rs +++ b/src/dns/handler.rs @@ -9,7 +9,7 @@ use rand::thread_rng; use std::collections::HashMap; use std::future::Future; use std::io::Error; -use std::net::IpAddr; +use std::net::{IpAddr, SocketAddr}; use trust_dns_proto::op::header::Header; use trust_dns_proto::op::{LowerQuery, MessageType, OpCode, ResponseCode}; use trust_dns_proto::rr::dnssec::SupportedAlgorithms; @@ -33,6 +33,7 @@ use crate::APP_CONF; use crate::APP_STORE; pub type DNSAuthority = InMemoryAuthority; +type DNSResponse = Result; pub struct DNSHandler { authorities: HashMap, @@ -43,32 +44,22 @@ impl RequestHandler for DNSHandler { async fn handle_request( &self, request: &Request, - response_handle: R, + responder: R, ) -> ResponseInfo { - let request_message = **request; + let (request_source, request_message) = (request.src(), **request); - trace!("request: {:?}", request_message); + match self + .handle(request_source, request_message, responder) + .await + { + Ok(info) => info, + Err(error) => { + error!("error handling dns request: {}", error); - match request_message.message_type() { - MessageType::Query => match request_message.op_code() { - OpCode::Query => { - info!("lookup request with id: {}", request_message.id()); - - self.lookup(request.src().ip(), request_message, response_handle) - } - code @ _ => { - error!("unimplemented opcode: {:?}", code); - - self.not_impl(&request_message, response_handle) - } - }, - MessageType::Response => { - warn!( - "got a response as a request from id: {}", - request_message.id() - ); + let mut header = Header::new(); - self.not_impl(&request_message, response_handle) + header.set_response_code(ResponseCode::ServFail); + header.into() } } } @@ -85,12 +76,41 @@ impl DNSHandler { self.authorities.insert(name, authority); } - fn lookup( + async fn handle( + &self, + source: SocketAddr, + request: MessageRequest, + responder: R, + ) -> DNSResponse { + trace!("request: {:?} from: {}", request, source.ip()); + + match request.message_type() { + MessageType::Query => match request.op_code() { + OpCode::Query => { + info!("lookup request with id: {}", request.id()); + + self.lookup(source.ip(), request, responder).await + } + code @ _ => { + error!("unimplemented opcode: {:?}", code); + + self.not_impl(&request, responder).await + } + }, + MessageType::Response => { + warn!("got a response as a request from id: {}", request.id()); + + self.not_impl(&request, responder).await + } + } + } + + async fn lookup( &self, source: IpAddr, request: MessageRequest, - response_handle: R, - ) -> Result<(), Error> { + responder: R, + ) -> DNSResponse { // Initialize response builder let mut response: MessageResponseBuilder = MessageResponse::new(Some(request.raw_queries())); @@ -108,7 +128,9 @@ impl DNSHandler { let query_first = queries.first(); if query_first.is_none() == true || queries.len() > 1 { - return self.lookup_invalid_query(request, response, header, response_handle); + return self + .lookup_invalid_query(request, response, header, responder) + .await; } // #2. Acquire base authority (ie. zone) for request @@ -118,7 +140,9 @@ impl DNSHandler { let authority_lookup = self.find_auth_recurse(query.name()); if authority_lookup.is_none() == true { - return self.lookup_no_authority(request, response, header, query, response_handle); + return self + .lookup_no_authority(request, response, header, query, responder) + .await; } // #3. Handle the first query only @@ -148,17 +172,19 @@ impl DNSHandler { if !records_local.is_empty() { let records_local_vec = records_local.iter().collect(); - return self.lookup_local( - &request, - response, - header, - query, - authority, - zone_name, - soa_records_vec, - records_local_vec, - response_handle, - ); + return self + .lookup_local( + &request, + response, + header, + query, + authority, + zone_name, + soa_records_vec, + records_local_vec, + responder, + ) + .await; } // #5. Fallback on resolving from remote store @@ -186,7 +212,7 @@ impl DNSHandler { // Dispatch request from this block, as we cannot escape generated \ // record values lifetimes out of this context. - Self::dispatch(response, header, response_handle) + Self::dispatch(response, header, responder).await } else { // Serve error code debug!("did not find records for query: {:?}", query); @@ -217,7 +243,7 @@ impl DNSHandler { ); // Dispatch empty records response - Self::dispatch(response, header, response_handle) + Self::dispatch(response, header, responder).await } } Err(err) => { @@ -235,18 +261,18 @@ impl DNSHandler { ); // Dispatch error response - Self::dispatch(response, header, response_handle) + Self::dispatch(response, header, responder).await } }; } - fn lookup_invalid_query( + async fn lookup_invalid_query( &self, request: &MessageRequest, response: MessageResponseBuilder, mut header: Header, - response_handle: R, - ) -> Result<(), Error> { + responder: R, + ) -> DNSResponse { warn!( "request has no query, or too many queries for: {}", request.id() @@ -255,17 +281,17 @@ impl DNSHandler { header.set_response_code(ResponseCode::FormErr); // Format error response dispatch - Self::dispatch(response, header, response_handle) + Self::dispatch(response, header, responder).await } - fn lookup_no_authority( + async fn lookup_no_authority( &self, request: &MessageRequest, response: MessageResponseBuilder, mut header: Header, query: &LowerQuery, - response_handle: R, - ) -> Result<(), Error> { + responder: R, + ) -> DNSResponse { debug!( "domain authority not found for query: {:?} on request: {}", query, @@ -275,10 +301,10 @@ impl DNSHandler { header.set_response_code(ResponseCode::Refused); // Authority not found response dispatch - Self::dispatch(response, header, response_handle) + Self::dispatch(response, header, responder).await } - fn lookup_local<'a, R: ResponseHandler>( + async fn lookup_local<'a, R: ResponseHandler>( &self, request: &MessageRequest, mut response: MessageResponseBuilder<'_, 'a>, @@ -288,8 +314,8 @@ impl DNSHandler { zone_name: Option, soa_records: Vec<&'a Record>, local_records: Vec<&'a Record>, - response_handle: R, - ) -> Result<(), Error> { + responder: R, + ) -> Result { debug!("found records for query from local store: {:?}", query); Self::serve_response_records( @@ -304,32 +330,34 @@ impl DNSHandler { // Dispatch request from this block, as we cannot escape generated record \ // values lifetimes out of this context. - Self::dispatch(response, header, response_handle) + Self::dispatch(response, header, responder).await } - fn not_impl( + async fn not_impl( &self, request: &MessageRequest, - response_handle: R, - ) -> Result<(), Error> { - response_handle.send(MessageResponse::new(None).error_msg( - request.id(), - request.op_code(), - ResponseCode::NotImp, - )) + responder: R, + ) -> Result { + responder + .send_response(MessageResponse::new(None).error_msg( + request.id(), + request.op_code(), + ResponseCode::NotImp, + )) + .await } - fn dispatch( + async fn dispatch( response: MessageResponseBuilder, header: Header, - response_handle: R, - ) -> Result<(), Error> { + responder: R, + ) -> Result { // Dispatch final response message let response_message = response.build(header); trace!("query response: {:?}", response_message); - response_handle.send(response_message) + responder.send_response(response_message).await } fn find_auth_recurse(&self, name: &LowerName) -> Option<&DNSAuthority> { From a97628a22512bfd015cceb2d71140fefba661e75 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 18 Jul 2024 20:16:59 +0200 Subject: [PATCH 03/17] Clear useless futures library --- Cargo.lock | 1 - Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d24b51f..969e8a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -569,7 +569,6 @@ dependencies = [ "clap", "farmhash", "flate2", - "futures 0.1.31", "http_req", "lazy_static", "log", diff --git a/Cargo.toml b/Cargo.toml index f71768d..f6bac29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ trust-dns-proto = { version = "0.23", default-features = false, features = [ "dnssec-ring", ] } trust-dns-resolver = { version = "0.10", default-features = false } -futures = "0.1" tokio = "1.21" rand = "0.8" farmhash = "1.1" From fb027999ea444ff3288c6bf4c73f86f5f96f9657 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 18 Jul 2024 20:17:14 +0200 Subject: [PATCH 04/17] Get Constellation to start w/ async server --- src/dns/handler.rs | 291 ++++++++++++++++----------------------------- 1 file changed, 104 insertions(+), 187 deletions(-) diff --git a/src/dns/handler.rs b/src/dns/handler.rs index 9ba4dc0..837d7be 100644 --- a/src/dns/handler.rs +++ b/src/dns/handler.rs @@ -7,15 +7,14 @@ use rand::seq::SliceRandom; use rand::thread_rng; use std::collections::HashMap; -use std::future::Future; use std::io::Error; -use std::net::{IpAddr, SocketAddr}; +use std::net::IpAddr; use trust_dns_proto::op::header::Header; use trust_dns_proto::op::{LowerQuery, MessageType, OpCode, ResponseCode}; use trust_dns_proto::rr::dnssec::SupportedAlgorithms; use trust_dns_proto::rr::{LowerName, Name, Record, RecordType as TrustRecordType}; use trust_dns_server::authority::{ - AuthLookup, Authority, LookupOptions, MessageRequest, MessageResponse, MessageResponseBuilder, + AuthLookup, Authority, LookupOptions, MessageRequest, MessageResponseBuilder, }; use trust_dns_server::server::{Request, RequestHandler, ResponseHandler, ResponseInfo}; use trust_dns_server::store::in_memory::InMemoryAuthority; @@ -46,12 +45,7 @@ impl RequestHandler for DNSHandler { request: &Request, responder: R, ) -> ResponseInfo { - let (request_source, request_message) = (request.src(), **request); - - match self - .handle(request_source, request_message, responder) - .await - { + match self.handle(responder, request).await { Ok(info) => info, Err(error) => { error!("error handling dns request: {}", error); @@ -76,45 +70,31 @@ impl DNSHandler { self.authorities.insert(name, authority); } - async fn handle( - &self, - source: SocketAddr, - request: MessageRequest, - responder: R, - ) -> DNSResponse { - trace!("request: {:?} from: {}", request, source.ip()); + async fn handle(&self, responder: R, request: &Request) -> DNSResponse { + trace!("request: {:?} from: {}", request, request.src().ip()); match request.message_type() { MessageType::Query => match request.op_code() { OpCode::Query => { info!("lookup request with id: {}", request.id()); - self.lookup(source.ip(), request, responder).await + self.lookup(responder, request).await } code @ _ => { error!("unimplemented opcode: {:?}", code); - self.not_impl(&request, responder).await + self.not_impl() } }, MessageType::Response => { warn!("got a response as a request from id: {}", request.id()); - self.not_impl(&request, responder).await + self.not_impl() } } } - async fn lookup( - &self, - source: IpAddr, - request: MessageRequest, - responder: R, - ) -> DNSResponse { - // Initialize response builder - let mut response: MessageResponseBuilder = - MessageResponse::new(Some(request.raw_queries())); - + async fn lookup(&self, responder: R, request: &Request) -> DNSResponse { // Generate response header let mut header: Header = Header::new(); @@ -122,30 +102,19 @@ impl DNSHandler { header.set_op_code(OpCode::Query); header.set_message_type(MessageType::Response); - // #1. Extract queries, and first query - // Notice: check if request has no query, or too many of them? If so, reject straight away. - let queries = request.queries(); - let query_first = queries.first(); - - if query_first.is_none() == true || queries.len() > 1 { - return self - .lookup_invalid_query(request, response, header, responder) - .await; - } - - // #2. Acquire base authority (ie. zone) for request + // #1. Acquire base authority (ie. zone) for request // Notice: if zone cannot be found, then reject straight away. // Notice: since we checked the status of the unwrapped query variable, this is panic-safe. - let query = query_first.unwrap(); + let query = request.query(); let authority_lookup = self.find_auth_recurse(query.name()); if authority_lookup.is_none() == true { return self - .lookup_no_authority(request, response, header, query, responder) + .lookup_no_authority(responder, request, header, query) .await; } - // #3. Handle the first query only + // #2. Handle the first query only // Notice: multiple queries are typically not supported by DNS servers anyway, \ // therefore we would only respond to the first query there. // Notice: since we checked the status of the unwrapped authority variable, this is \ @@ -163,32 +132,35 @@ impl DNSHandler { let supported_algorithms = SupportedAlgorithms::new(); let lookup_options = LookupOptions::for_dnssec(false, supported_algorithms); - let soa_records = authority.soa_secure(lookup_options); - let soa_records_vec = soa_records.iter().collect(); + let soa_records = authority.soa_secure(lookup_options).await; - // #4. Attempt to resolve from local store - let records_local = authority.search(query, lookup_options); + // TODO: fix this + //let soa_records_vec = soa_records.iter().collect(); + let soa_records_vec = vec![]; + + // #3. Attempt to resolve from local store + let records_local = authority + .search(request.request_info(), lookup_options) + .await?; if !records_local.is_empty() { let records_local_vec = records_local.iter().collect(); return self .lookup_local( - &request, - response, + responder, + request, header, query, - authority, zone_name, soa_records_vec, records_local_vec, - responder, ) .await; } - // #5. Fallback on resolving from remote store - return match Self::records_from_store(authority, &zone_name, source, query) { + // #4. Fallback on resolving from remote store + return match Self::records_from_store(authority, &zone_name, request.src().ip(), query) { Ok(records_remote) => { // Serve response data? if let Some(records_remote_inner) = records_remote { @@ -200,97 +172,60 @@ impl DNSHandler { let records_remote_vec = records_remote_inner.iter().collect(); - Self::serve_response_records( - &request, - &mut response, - &mut header, + // Dispatch request from this block, as we cannot escape generated \ + // record values lifetimes out of this context. + Self::dispatch_response_with_records( + responder, + request, + header, &zone_name, records_remote_vec, - &authority, soa_records_vec, - ); - - // Dispatch request from this block, as we cannot escape generated \ - // record values lifetimes out of this context. - Self::dispatch(response, header, responder).await + ) + .await } else { // Serve error code debug!("did not find records for query: {:?}", query); let response_error = match records_local { - AuthLookup::NoName => { + AuthLookup::Empty => { debug!("domain not found for query: {:?}", query); ResponseCode::NXDomain } - AuthLookup::NameExists => { + AuthLookup::SOA { .. } => { debug!("domain found for query: {:?}", query); ResponseCode::NoError } - AuthLookup::Records(..) => panic!("error, should return noerror"), + AuthLookup::Records { .. } | AuthLookup::AXFR { .. } => { + panic!("error, should return noerror") + } }; - Self::stamp_response( - &request, - &mut response, - &mut header, - authority, - soa_records_vec, - response_error, - &zone_name, - false, - ); + Self::stamp_header(request, &mut header, response_error, &zone_name); // Dispatch empty records response - Self::dispatch(response, header, responder).await + Self::dispatch_response(responder, request, header, Some(soa_records_vec)).await } } Err(err) => { debug!("query refused for: {:?} because: {}", query, err); - Self::stamp_response( - &request, - &mut response, - &mut header, - authority, - soa_records_vec, - err, - &zone_name, - false, - ); + Self::stamp_header(request, &mut header, err, &zone_name); // Dispatch error response - Self::dispatch(response, header, responder).await + Self::dispatch_response(responder, request, header, Some(soa_records_vec)).await } }; } - async fn lookup_invalid_query( - &self, - request: &MessageRequest, - response: MessageResponseBuilder, - mut header: Header, - responder: R, - ) -> DNSResponse { - warn!( - "request has no query, or too many queries for: {}", - request.id() - ); - - header.set_response_code(ResponseCode::FormErr); - - // Format error response dispatch - Self::dispatch(response, header, responder).await - } - async fn lookup_no_authority( &self, + responder: R, request: &MessageRequest, - response: MessageResponseBuilder, mut header: Header, query: &LowerQuery, - responder: R, ) -> DNSResponse { debug!( "domain authority not found for query: {:?} on request: {}", @@ -301,65 +236,94 @@ impl DNSHandler { header.set_response_code(ResponseCode::Refused); // Authority not found response dispatch - Self::dispatch(response, header, responder).await + Self::dispatch_response(responder, request, header, None).await } async fn lookup_local<'a, R: ResponseHandler>( &self, + responder: R, request: &MessageRequest, - mut response: MessageResponseBuilder<'_, 'a>, - mut header: Header, + header: Header, query: &LowerQuery, - authority: &'a DNSAuthority, zone_name: Option, soa_records: Vec<&'a Record>, local_records: Vec<&'a Record>, - responder: R, ) -> Result { debug!("found records for query from local store: {:?}", query); - Self::serve_response_records( + Self::dispatch_response_with_records( + responder, request, - &mut response, - &mut header, + header, &zone_name, local_records, - &authority, soa_records, - ); - - // Dispatch request from this block, as we cannot escape generated record \ - // values lifetimes out of this context. - Self::dispatch(response, header, responder).await + ) + .await } - async fn not_impl( - &self, - request: &MessageRequest, - responder: R, - ) -> Result { - responder - .send_response(MessageResponse::new(None).error_msg( - request.id(), - request.op_code(), - ResponseCode::NotImp, - )) - .await + fn not_impl(&self) -> DNSResponse { + let mut header = Header::new(); + + header.set_response_code(ResponseCode::NotImp); + + Ok(header.into()) } - async fn dispatch( - response: MessageResponseBuilder, + async fn dispatch_response( + mut responder: R, + request: &MessageRequest, header: Header, - responder: R, + name_servers: Option>, ) -> Result { // Dispatch final response message - let response_message = response.build(header); + let response_message = MessageResponseBuilder::from_message_request(request).build( + header, + &[], + name_servers.unwrap_or(vec![]), + &[], + &[], + ); trace!("query response: {:?}", response_message); responder.send_response(response_message).await } + async fn dispatch_response_with_records<'a, 'b, R: ResponseHandler>( + mut responder: R, + request: &MessageRequest, + mut header: Header, + zone_name: &Option, + mut records: Vec<&'a Record>, + name_servers: Vec<&'a Record>, + ) -> DNSResponse { + let has_records = !records.is_empty(); + + Self::stamp_header(request, &mut header, ResponseCode::NoError, zone_name); + + // Add records to response? + if has_records == true { + // Randomize records order, as most DNS servers do to balance eg. IP resource usage + if records.len() > 1 { + records.shuffle(&mut thread_rng()); + } + } + + // Dispatch final response message + let response_message = MessageResponseBuilder::from_message_request(request).build( + header, + records, + name_servers, + &[], + &[], + ); + + trace!("query response with records: {:?}", response_message); + + responder.send_response(response_message).await + } + fn find_auth_recurse(&self, name: &LowerName) -> Option<&DNSAuthority> { let authority = self.authorities.get(name); @@ -788,49 +752,11 @@ impl DNSHandler { } } - fn serve_response_records<'a, 'b>( + fn stamp_header<'a, 'b>( request: &MessageRequest, - response: &'b mut MessageResponseBuilder<'_, 'a>, - header: &'b mut Header, - zone_name: &Option, - mut records: Vec<&'a Record>, - authority: &'a DNSAuthority, - soa_records: Vec<&'a Record>, - ) { - let has_records = !records.is_empty(); - - // Stamp response with flags and required response data - Self::stamp_response( - request, - response, - header, - authority, - soa_records, - ResponseCode::NoError, - zone_name, - has_records, - ); - - // Add records to response? - if has_records == true { - // Randomize records order, as most DNS servers do to balance eg. IP resource usage - if records.len() > 1 { - records.shuffle(&mut thread_rng()); - } - - response.answers(records); - } - } - - fn stamp_response<'a, 'b>( - request: &MessageRequest, - response: &'b mut MessageResponseBuilder<'_, 'a>, header: &mut Header, - authority: &'a DNSAuthority, - soa_records: Vec<&'a Record>, code: ResponseCode, zone_name: &Option, - has_records: bool, ) { // Stack answer code to metrics? if let Some(ref zone_name) = zone_name { @@ -849,15 +775,6 @@ impl DNSHandler { if request.recursion_desired() == true { header.set_recursion_desired(true); } - - // Add SOA records? (if response is empty) - if has_records == false { - if soa_records.is_empty() { - warn!("no soa record for authority: {:?}", authority.origin()); - } else { - response.name_servers(soa_records); - } - } } fn check_name_exists( From d22e4ee6fd3b1b977fc4dcaf6575b7c815e92ea3 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 18 Jul 2024 21:29:39 +0200 Subject: [PATCH 05/17] Add TODO --- src/store/store.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/store/store.rs b/src/store/store.rs index 546dd31..9049927 100644 --- a/src/store/store.rs +++ b/src/store/store.rs @@ -88,6 +88,7 @@ pub enum StoreAccessOrigin { Internal, } +// TODO: make this non-blocking (async) impl StoreBuilder { pub fn new() -> Store { let mut pools = Vec::new(); From 3b94c93d6a188088c3c5ded0001ef042307eca6f Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 18 Jul 2024 21:39:36 +0200 Subject: [PATCH 06/17] Working! --- src/dns/handler.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/dns/handler.rs b/src/dns/handler.rs index 837d7be..4daad79 100644 --- a/src/dns/handler.rs +++ b/src/dns/handler.rs @@ -114,11 +114,7 @@ impl DNSHandler { .await; } - // #2. Handle the first query only - // Notice: multiple queries are typically not supported by DNS servers anyway, \ - // therefore we would only respond to the first query there. - // Notice: since we checked the status of the unwrapped authority variable, this is \ - // panic-safe. + // #2. Handle the query let authority = authority_lookup.unwrap(); let zone_name = ZoneName::from_trust(&authority.origin()); @@ -139,9 +135,11 @@ impl DNSHandler { let soa_records_vec = vec![]; // #3. Attempt to resolve from local store + // TODO: it seems that the NS record is not being fetched correctly let records_local = authority .search(request.request_info(), lookup_options) - .await?; + .await + .unwrap_or(AuthLookup::Empty); if !records_local.is_empty() { let records_local_vec = records_local.iter().collect(); From 5b8e136bef395b813a4147f79c0ca9ea61e68483 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 18 Jul 2024 22:12:55 +0200 Subject: [PATCH 07/17] Restore full functionality --- src/dns/handler.rs | 75 +++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/src/dns/handler.rs b/src/dns/handler.rs index 4daad79..34f199c 100644 --- a/src/dns/handler.rs +++ b/src/dns/handler.rs @@ -128,14 +128,14 @@ impl DNSHandler { let supported_algorithms = SupportedAlgorithms::new(); let lookup_options = LookupOptions::for_dnssec(false, supported_algorithms); - let soa_records = authority.soa_secure(lookup_options).await; + let soa_records = authority + .soa_secure(lookup_options) + .await + .unwrap_or(AuthLookup::Empty); - // TODO: fix this - //let soa_records_vec = soa_records.iter().collect(); - let soa_records_vec = vec![]; + let soa_records_vec = soa_records.iter().collect(); // #3. Attempt to resolve from local store - // TODO: it seems that the NS record is not being fetched correctly let records_local = authority .search(request.request_info(), lookup_options) .await @@ -172,7 +172,7 @@ impl DNSHandler { // Dispatch request from this block, as we cannot escape generated \ // record values lifetimes out of this context. - Self::dispatch_response_with_records( + Self::serve_response_records( responder, request, header, @@ -204,7 +204,7 @@ impl DNSHandler { Self::stamp_header(request, &mut header, response_error, &zone_name); // Dispatch empty records response - Self::dispatch_response(responder, request, header, Some(soa_records_vec)).await + Self::dispatch(responder, request, header, None, Some(soa_records_vec)).await } } Err(err) => { @@ -213,7 +213,7 @@ impl DNSHandler { Self::stamp_header(request, &mut header, err, &zone_name); // Dispatch error response - Self::dispatch_response(responder, request, header, Some(soa_records_vec)).await + Self::dispatch(responder, request, header, None, Some(soa_records_vec)).await } }; } @@ -234,7 +234,7 @@ impl DNSHandler { header.set_response_code(ResponseCode::Refused); // Authority not found response dispatch - Self::dispatch_response(responder, request, header, None).await + Self::dispatch(responder, request, header, None, None).await } async fn lookup_local<'a, R: ResponseHandler>( @@ -249,7 +249,7 @@ impl DNSHandler { ) -> Result { debug!("found records for query from local store: {:?}", query); - Self::dispatch_response_with_records( + Self::serve_response_records( responder, request, header, @@ -268,38 +268,16 @@ impl DNSHandler { Ok(header.into()) } - async fn dispatch_response( + async fn dispatch<'a, R: ResponseHandler>( mut responder: R, request: &MessageRequest, header: Header, - name_servers: Option>, + records: Option>, + soa_records: Option>, ) -> Result { - // Dispatch final response message - let response_message = MessageResponseBuilder::from_message_request(request).build( - header, - &[], - name_servers.unwrap_or(vec![]), - &[], - &[], - ); - - trace!("query response: {:?}", response_message); - - responder.send_response(response_message).await - } - - async fn dispatch_response_with_records<'a, 'b, R: ResponseHandler>( - mut responder: R, - request: &MessageRequest, - mut header: Header, - zone_name: &Option, - mut records: Vec<&'a Record>, - name_servers: Vec<&'a Record>, - ) -> DNSResponse { + let mut records = records.unwrap_or(vec![]); let has_records = !records.is_empty(); - Self::stamp_header(request, &mut header, ResponseCode::NoError, zone_name); - // Add records to response? if has_records == true { // Randomize records order, as most DNS servers do to balance eg. IP resource usage @@ -308,20 +286,41 @@ impl DNSHandler { } } + // Acquire response SOA records + // Notice: only append SOA records if this is an empty response + let soa_records = if records.is_empty() { + soa_records + } else { + None + }; + // Dispatch final response message let response_message = MessageResponseBuilder::from_message_request(request).build( header, records, - name_servers, &[], + soa_records.unwrap_or(vec![]), &[], ); - trace!("query response with records: {:?}", response_message); + trace!("query response: {:?}", response_message); responder.send_response(response_message).await } + async fn serve_response_records<'a, 'b, R: ResponseHandler>( + responder: R, + request: &MessageRequest, + mut header: Header, + zone_name: &Option, + records: Vec<&'a Record>, + soa_records: Vec<&'a Record>, + ) -> DNSResponse { + Self::stamp_header(request, &mut header, ResponseCode::NoError, zone_name); + + Self::dispatch(responder, request, header, Some(records), Some(soa_records)).await + } + fn find_auth_recurse(&self, name: &LowerName) -> Option<&DNSAuthority> { let authority = self.authorities.get(name); From a37b6eb0192ec727b74803160228a3e5d926e72c Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 18 Jul 2024 22:16:16 +0200 Subject: [PATCH 08/17] Clear DNSSEC --- Cargo.lock | 118 ++++----------------------------------------- Cargo.toml | 8 +-- src/dns/handler.rs | 12 +---- 3 files changed, 13 insertions(+), 125 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 969e8a2..57cff98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1226,18 +1226,6 @@ dependencies = [ "winreg 0.6.2", ] -[[package]] -name = "ipconfig" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" -dependencies = [ - "socket2 0.5.7", - "widestring 1.1.0", - "windows-sys 0.48.0", - "winreg 0.50.0", -] - [[package]] name = "ipnet" version = "2.9.0" @@ -1271,15 +1259,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" -dependencies = [ - "wasm-bindgen", -] - [[package]] name = "kernel32-sys" version = "0.2.2" @@ -1918,21 +1897,6 @@ dependencies = [ "quick-error", ] -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin 0.5.2", - "untrusted 0.7.1", - "web-sys", - "winapi 0.3.9", -] - [[package]] name = "ring" version = "0.17.8" @@ -1943,8 +1907,8 @@ dependencies = [ "cfg-if 1.0.0", "getrandom 0.2.15", "libc", - "spin 0.9.8", - "untrusted 0.9.0", + "spin", + "untrusted", "windows-sys 0.52.0", ] @@ -1992,7 +1956,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring 0.17.8", + "ring", "rustls-webpki", "sct", ] @@ -2012,8 +1976,8 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -2043,8 +2007,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -2202,12 +2166,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" @@ -2842,8 +2800,6 @@ dependencies = [ "ipnet", "once_cell", "rand 0.8.5", - "ring 0.16.20", - "serde", "smallvec 1.13.2", "thiserror", "tinyvec", @@ -2890,28 +2846,6 @@ dependencies = [ "trust-dns-proto 0.19.7", ] -[[package]] -name = "trust-dns-resolver" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a3e6c3aff1718b3c73e395d1f35202ba2ffa847c6a62eea0db8fb4cfe30be6" -dependencies = [ - "cfg-if 1.0.0", - "futures-util", - "ipconfig 0.3.2", - "lru-cache", - "once_cell", - "parking_lot 0.12.3", - "rand 0.8.5", - "resolv-conf 0.7.0", - "serde", - "smallvec 1.13.2", - "thiserror", - "tokio 1.38.1", - "tracing", - "trust-dns-proto 0.23.2", -] - [[package]] name = "trust-dns-server" version = "0.23.2" @@ -2932,7 +2866,6 @@ dependencies = [ "toml 0.7.8", "tracing", "trust-dns-proto 0.23.2", - "trust-dns-resolver 0.23.2", ] [[package]] @@ -2977,12 +2910,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "untrusted" version = "0.9.0" @@ -3009,7 +2936,6 @@ dependencies = [ "form_urlencoded", "idna 0.5.0", "percent-encoding 2.3.1", - "serde", ] [[package]] @@ -3100,24 +3026,14 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" -[[package]] -name = "web-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "webpki" version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -3138,12 +3054,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" -[[package]] -name = "widestring" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" - [[package]] name = "winapi" version = "0.2.8" @@ -3353,16 +3263,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if 1.0.0", - "windows-sys 0.48.0", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index f6bac29..299b352 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,12 +32,8 @@ r2d2_redis = "0.14" redis = "0.20" actix-web = { version = "3.3", default-features = false } actix-web-httpauth = "0.5" -trust-dns-server = { version = "0.23", default-features = false, features = [ - "dnssec-ring", -] } -trust-dns-proto = { version = "0.23", default-features = false, features = [ - "dnssec-ring", -] } +trust-dns-server = { version = "0.23", default-features = false } +trust-dns-proto = { version = "0.23", default-features = false } trust-dns-resolver = { version = "0.10", default-features = false } tokio = "1.21" rand = "0.8" diff --git a/src/dns/handler.rs b/src/dns/handler.rs index 34f199c..f675295 100644 --- a/src/dns/handler.rs +++ b/src/dns/handler.rs @@ -11,7 +11,6 @@ use std::io::Error; use std::net::IpAddr; use trust_dns_proto::op::header::Header; use trust_dns_proto::op::{LowerQuery, MessageType, OpCode, ResponseCode}; -use trust_dns_proto::rr::dnssec::SupportedAlgorithms; use trust_dns_proto::rr::{LowerName, Name, Record, RecordType as TrustRecordType}; use trust_dns_server::authority::{ AuthLookup, Authority, LookupOptions, MessageRequest, MessageResponseBuilder, @@ -125,19 +124,12 @@ impl DNSHandler { ); // Acquire SOA records - let supported_algorithms = SupportedAlgorithms::new(); - let lookup_options = LookupOptions::for_dnssec(false, supported_algorithms); - - let soa_records = authority - .soa_secure(lookup_options) - .await - .unwrap_or(AuthLookup::Empty); - + let soa_records = authority.soa().await.unwrap_or(AuthLookup::Empty); let soa_records_vec = soa_records.iter().collect(); // #3. Attempt to resolve from local store let records_local = authority - .search(request.request_info(), lookup_options) + .search(request.request_info(), LookupOptions::default()) .await .unwrap_or(AuthLookup::Empty); From 76cc6dea91ac583a69da953b58ea6d4e5114ced8 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Thu, 18 Jul 2024 22:16:21 +0200 Subject: [PATCH 09/17] Add TODO --- src/dns/flatten.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dns/flatten.rs b/src/dns/flatten.rs index b5e065f..588ce50 100644 --- a/src/dns/flatten.rs +++ b/src/dns/flatten.rs @@ -12,7 +12,7 @@ use std::thread; use std::time::{Duration, Instant, SystemTime}; use trust_dns_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts}; use trust_dns_resolver::error::ResolveError; -use trust_dns_resolver::Resolver; +use trust_dns_resolver::Resolver; // TODO: migrate this one to latest version use super::record::{RecordType, RecordValue, RecordValues}; use crate::APP_CONF; From deb9eb99a22bb9c5bda204b46630a46d81810038 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 19 Jul 2024 09:47:20 +0200 Subject: [PATCH 10/17] Bump trust_dns_resolver --- Cargo.lock | 527 +++------------------------------------------ Cargo.toml | 4 +- src/dns/flatten.rs | 50 +++-- 3 files changed, 63 insertions(+), 518 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57cff98..d6e2733 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,7 +116,7 @@ dependencies = [ "copyless", "futures-channel", "futures-util", - "smallvec 1.13.2", + "smallvec", "tokio 0.2.25", ] @@ -452,16 +452,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" -[[package]] -name = "bytes" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" -dependencies = [ - "byteorder", - "iovec", -] - [[package]] name = "bytes" version = "0.5.6" @@ -528,15 +518,6 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "colorchoice" version = "1.0.1" @@ -586,7 +567,7 @@ dependencies = [ "tokio 1.38.1", "toml 0.8.15", "trust-dns-proto 0.23.2", - "trust-dns-resolver 0.10.3", + "trust-dns-resolver 0.23.2", "trust-dns-server", "url_serde", ] @@ -632,54 +613,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "crossbeam-deque" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20ff29ded3204c5106278a81a38f4b482636ed4fa1e6cfbeef193291beb29ed" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" -dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "crossbeam-utils", - "lazy_static", - "maybe-uninit", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-queue" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" -dependencies = [ - "cfg-if 0.1.10", - "crossbeam-utils", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-utils" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" -dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "lazy_static", -] - [[package]] name = "data-encoding" version = "2.6.0" @@ -793,37 +726,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "error-chain" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6930e04918388a9a2e41d518c25cf679ccafe26733fb4127dbf21993f2575d46" -dependencies = [ - "backtrace", -] - -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", - "failure_derive", -] - -[[package]] -name = "failure_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "synstructure", -] - [[package]] name = "farmhash" version = "1.1.5" @@ -873,12 +775,6 @@ dependencies = [ "percent-encoding 2.3.1", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -895,12 +791,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "futures" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" - [[package]] name = "futures" version = "0.3.30" @@ -1201,19 +1091,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ipconfig" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f7eadeaf4b52700de180d147c4805f199854600b36faa963d91114827b2ffc" -dependencies = [ - "error-chain", - "socket2 0.3.19", - "widestring 0.2.2", - "winapi 0.3.9", - "winreg 0.5.1", -] - [[package]] name = "ipconfig" version = "0.2.2" @@ -1221,9 +1098,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" dependencies = [ "socket2 0.3.19", - "widestring 0.4.3", + "widestring", "winapi 0.3.9", - "winreg 0.6.2", + "winreg", ] [[package]] @@ -1299,15 +1176,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "lock_api" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" -dependencies = [ - "scopeguard", -] - [[package]] name = "lock_api" version = "0.4.12" @@ -1357,27 +1225,12 @@ dependencies = [ "serde", ] -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "memoffset" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa" -dependencies = [ - "autocfg", -] - [[package]] name = "mime" version = "0.3.17" @@ -1494,17 +1347,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "parking_lot" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" -dependencies = [ - "lock_api 0.3.4", - "parking_lot_core 0.6.3", - "rustc_version 0.2.3", -] - [[package]] name = "parking_lot" version = "0.11.2" @@ -1512,7 +1354,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", - "lock_api 0.4.12", + "lock_api", "parking_lot_core 0.8.6", ] @@ -1522,25 +1364,10 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ - "lock_api 0.4.12", + "lock_api", "parking_lot_core 0.9.10", ] -[[package]] -name = "parking_lot_core" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66b810a62be75176a80873726630147a5ca780cd33921e0b5709033e66b0a" -dependencies = [ - "cfg-if 0.1.10", - "cloudabi", - "libc", - "redox_syscall 0.1.57", - "rustc_version 0.2.3", - "smallvec 0.6.14", - "winapi 0.3.9", -] - [[package]] name = "parking_lot_core" version = "0.8.6" @@ -1551,7 +1378,7 @@ dependencies = [ "instant", "libc", "redox_syscall 0.2.16", - "smallvec 1.13.2", + "smallvec", "winapi 0.3.9", ] @@ -1564,7 +1391,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall 0.5.3", - "smallvec 1.13.2", + "smallvec", "windows-targets 0.52.6", ] @@ -1701,19 +1528,6 @@ dependencies = [ "redis", ] -[[package]] -name = "rand" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "winapi 0.3.9", -] - [[package]] name = "rand" version = "0.7.3" @@ -1758,21 +1572,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -1815,12 +1614,6 @@ dependencies = [ "url 2.5.2", ] -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - [[package]] name = "redox_syscall" version = "0.2.16" @@ -1877,16 +1670,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" -[[package]] -name = "resolv-conf" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11834e137f3b14e309437a8276714eed3a80d1ef894869e510f2c0c0b98b9f4a" -dependencies = [ - "hostname", - "quick-error", -] - [[package]] name = "resolv-conf" version = "0.7.0" @@ -2130,15 +1913,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "0.6.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" -dependencies = [ - "maybe-uninit", -] - [[package]] name = "smallvec" version = "1.13.2" @@ -2258,18 +2032,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "unicode-xid", -] - [[package]] name = "tar" version = "0.4.41" @@ -2394,30 +2156,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "tokio" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" -dependencies = [ - "bytes 0.4.12", - "futures 0.1.31", - "mio 0.6.23", - "num_cpus", - "tokio-codec", - "tokio-current-thread", - "tokio-executor", - "tokio-fs", - "tokio-io", - "tokio-reactor", - "tokio-sync", - "tokio-tcp", - "tokio-threadpool", - "tokio-timer", - "tokio-udp", - "tokio-uds", -] - [[package]] name = "tokio" version = "0.2.25" @@ -2455,59 +2193,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-codec" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25b2998660ba0e70d18684de5d06b70b70a3a747469af9dea7618cc59e75976b" -dependencies = [ - "bytes 0.4.12", - "futures 0.1.31", - "tokio-io", -] - -[[package]] -name = "tokio-current-thread" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de0e32a83f131e002238d7ccde18211c0a5397f60cbfffcb112868c2e0e20e" -dependencies = [ - "futures 0.1.31", - "tokio-executor", -] - -[[package]] -name = "tokio-executor" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671" -dependencies = [ - "crossbeam-utils", - "futures 0.1.31", -] - -[[package]] -name = "tokio-fs" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "297a1206e0ca6302a0eed35b700d292b275256f596e2f3fea7729d5e629b6ff4" -dependencies = [ - "futures 0.1.31", - "tokio-io", - "tokio-threadpool", -] - -[[package]] -name = "tokio-io" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" -dependencies = [ - "bytes 0.4.12", - "futures 0.1.31", - "log", -] - [[package]] name = "tokio-macros" version = "2.3.0" @@ -2519,111 +2204,6 @@ dependencies = [ "syn 2.0.71", ] -[[package]] -name = "tokio-reactor" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09bc590ec4ba8ba87652da2068d150dcada2cfa2e07faae270a5e0409aa51351" -dependencies = [ - "crossbeam-utils", - "futures 0.1.31", - "lazy_static", - "log", - "mio 0.6.23", - "num_cpus", - "parking_lot 0.9.0", - "slab", - "tokio-executor", - "tokio-io", - "tokio-sync", -] - -[[package]] -name = "tokio-sync" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfe50152bc8164fcc456dab7891fa9bf8beaf01c5ee7e1dd43a397c3cf87dee" -dependencies = [ - "fnv", - "futures 0.1.31", -] - -[[package]] -name = "tokio-tcp" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98df18ed66e3b72e742f185882a9e201892407957e45fbff8da17ae7a7c51f72" -dependencies = [ - "bytes 0.4.12", - "futures 0.1.31", - "iovec", - "mio 0.6.23", - "tokio-io", - "tokio-reactor", -] - -[[package]] -name = "tokio-threadpool" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df720b6581784c118f0eb4310796b12b1d242a7eb95f716a8367855325c25f89" -dependencies = [ - "crossbeam-deque", - "crossbeam-queue", - "crossbeam-utils", - "futures 0.1.31", - "lazy_static", - "log", - "num_cpus", - "slab", - "tokio-executor", -] - -[[package]] -name = "tokio-timer" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93044f2d313c95ff1cb7809ce9a7a05735b012288a888b62d4434fd58c94f296" -dependencies = [ - "crossbeam-utils", - "futures 0.1.31", - "slab", - "tokio-executor", -] - -[[package]] -name = "tokio-udp" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2a0b10e610b39c38b031a2fcab08e4b82f16ece36504988dcbd81dbba650d82" -dependencies = [ - "bytes 0.4.12", - "futures 0.1.31", - "log", - "mio 0.6.23", - "tokio-codec", - "tokio-io", - "tokio-reactor", -] - -[[package]] -name = "tokio-uds" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab57a4ac4111c8c9dbcf70779f6fc8bc35ae4b2454809febac840ad19bd7e4e0" -dependencies = [ - "bytes 0.4.12", - "futures 0.1.31", - "iovec", - "libc", - "log", - "mio 0.6.23", - "mio-uds", - "tokio-codec", - "tokio-io", - "tokio-reactor", -] - [[package]] name = "tokio-util" version = "0.3.1" @@ -2739,30 +2319,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "trust-dns-proto" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09144f0992b0870fa8d2972cc069cbf1e3c0fda64d1f3d45c4d68d0e0b52ad4e" -dependencies = [ - "byteorder", - "failure", - "futures 0.1.31", - "idna 0.1.5", - "lazy_static", - "log", - "rand 0.5.6", - "smallvec 0.6.14", - "socket2 0.3.19", - "tokio-executor", - "tokio-io", - "tokio-reactor", - "tokio-tcp", - "tokio-timer", - "tokio-udp", - "url 1.7.2", -] - [[package]] name = "trust-dns-proto" version = "0.19.7" @@ -2772,12 +2328,12 @@ dependencies = [ "async-trait", "cfg-if 1.0.0", "enum-as-inner 0.3.4", - "futures 0.3.30", + "futures", "idna 0.2.3", "lazy_static", "log", "rand 0.7.3", - "smallvec 1.13.2", + "smallvec", "thiserror", "tokio 0.2.25", "url 2.5.2", @@ -2800,7 +2356,7 @@ dependencies = [ "ipnet", "once_cell", "rand 0.8.5", - "smallvec 1.13.2", + "smallvec", "thiserror", "tinyvec", "tokio 1.38.1", @@ -2810,40 +2366,40 @@ dependencies = [ [[package]] name = "trust-dns-resolver" -version = "0.10.3" +version = "0.19.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9f877f7a1ad821ab350505e1f1b146a4960402991787191d6d8cab2ce2de2c" +checksum = "710f593b371175db53a26d0b38ed2978fafb9e9e8d3868b1acd753ea18df0ceb" dependencies = [ "cfg-if 0.1.10", - "failure", - "futures 0.1.31", - "ipconfig 0.1.9", + "futures", + "ipconfig", "lazy_static", "log", "lru-cache", - "resolv-conf 0.6.3", - "smallvec 0.6.14", - "tokio 0.1.22", - "trust-dns-proto 0.6.3", + "resolv-conf", + "smallvec", + "thiserror", + "tokio 0.2.25", + "trust-dns-proto 0.19.7", ] [[package]] name = "trust-dns-resolver" -version = "0.19.7" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "710f593b371175db53a26d0b38ed2978fafb9e9e8d3868b1acd753ea18df0ceb" +checksum = "10a3e6c3aff1718b3c73e395d1f35202ba2ffa847c6a62eea0db8fb4cfe30be6" dependencies = [ - "cfg-if 0.1.10", - "futures 0.3.30", - "ipconfig 0.2.2", - "lazy_static", - "log", + "cfg-if 1.0.0", + "futures-util", "lru-cache", - "resolv-conf 0.7.0", - "smallvec 1.13.2", + "once_cell", + "parking_lot 0.12.3", + "rand 0.8.5", + "smallvec", "thiserror", - "tokio 0.2.25", - "trust-dns-proto 0.19.7", + "tokio 1.38.1", + "tracing", + "trust-dns-proto 0.23.2", ] [[package]] @@ -2904,12 +2460,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - [[package]] name = "untrusted" version = "0.9.0" @@ -3042,12 +2592,6 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" -[[package]] -name = "widestring" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7157704c2e12e3d2189c507b7482c52820a16dfa4465ba91add92f266667cadb" - [[package]] name = "widestring" version = "0.4.3" @@ -3245,15 +2789,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winreg" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27a759395c1195c4cc5cda607ef6f8f6498f64e78f7900f5de0a127a424704a" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "winreg" version = "0.6.2" diff --git a/Cargo.toml b/Cargo.toml index 299b352..bda2819 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,9 @@ actix-web = { version = "3.3", default-features = false } actix-web-httpauth = "0.5" trust-dns-server = { version = "0.23", default-features = false } trust-dns-proto = { version = "0.23", default-features = false } -trust-dns-resolver = { version = "0.10", default-features = false } +trust-dns-resolver = { version = "0.23", default-features = false, features = [ + "tokio-runtime", +] } tokio = "1.21" rand = "0.8" farmhash = "1.1" diff --git a/src/dns/flatten.rs b/src/dns/flatten.rs index 588ce50..beb7cf2 100644 --- a/src/dns/flatten.rs +++ b/src/dns/flatten.rs @@ -12,7 +12,7 @@ use std::thread; use std::time::{Duration, Instant, SystemTime}; use trust_dns_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts}; use trust_dns_resolver::error::ResolveError; -use trust_dns_resolver::Resolver; // TODO: migrate this one to latest version +use trust_dns_resolver::Resolver; use super::record::{RecordType, RecordValue, RecordValues}; use crate::APP_CONF; @@ -86,8 +86,10 @@ impl DNSFlattenBuilder { for socket_address in socket_addresses { resolver_config.add_name_server(NameServerConfig { socket_addr: socket_address, + bind_addr: None, protocol: Protocol::Udp, tls_dns_name: None, + trust_negative_responses: true, }); } } @@ -194,35 +196,41 @@ impl DNSFlatten { let values: Result, ResolveError> = match registry_key.1 { RecordType::A => self .resolver - .ipv4_lookup(®istry_key.0) + .ipv4_lookup(registry_key.0.to_str()) .map(|values| values.iter().map(|value| value.to_string()).collect()), RecordType::AAAA => self .resolver - .ipv6_lookup(®istry_key.0) + .ipv6_lookup(registry_key.0.to_str()) .map(|values| values.iter().map(|value| value.to_string()).collect()), RecordType::MX => { // Format as `{priority} {exchange}`, eg. `10 inbound.crisp.email` - self.resolver.mx_lookup(®istry_key.0).map(|values| { - values - .iter() - .map(|value| format!("{} {}", value.preference(), value.exchange())) - .collect() - }) + self.resolver + .mx_lookup(registry_key.0.to_str()) + .map(|values| { + values + .iter() + .map(|value| format!("{} {}", value.preference(), value.exchange())) + .collect() + }) } RecordType::TXT => { // Assemble all TXT data segments - self.resolver.txt_lookup(®istry_key.0).map(|values| { - values - .iter() - .map(|value_chunks| { - value_chunks - .txt_data() - .iter() - .map(|value_chunk| std::str::from_utf8(value_chunk).unwrap_or("")) - .collect() - }) - .collect() - }) + self.resolver + .txt_lookup(registry_key.0.to_str()) + .map(|values| { + values + .iter() + .map(|value_chunks| { + value_chunks + .txt_data() + .iter() + .map(|value_chunk| { + std::str::from_utf8(value_chunk).unwrap_or("") + }) + .collect() + }) + .collect() + }) } RecordType::PTR | RecordType::CNAME => Ok(Vec::new()), }; From 4f195b306aedb7f43756913a3175d4501e73d0e7 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 19 Jul 2024 09:51:11 +0200 Subject: [PATCH 11/17] Clear TODO --- src/store/store.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/store/store.rs b/src/store/store.rs index 9049927..546dd31 100644 --- a/src/store/store.rs +++ b/src/store/store.rs @@ -88,7 +88,6 @@ pub enum StoreAccessOrigin { Internal, } -// TODO: make this non-blocking (async) impl StoreBuilder { pub fn new() -> Store { let mut pools = Vec::new(); From 44d159440689ef372a5f6237393872e9c2690368 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 19 Jul 2024 09:58:46 +0200 Subject: [PATCH 12/17] Migrate trust to hickory DNS --- Cargo.lock | 208 ++++++++++++++++++--------------------------- Cargo.toml | 6 +- src/dns/code.rs | 4 +- src/dns/flatten.rs | 6 +- src/dns/handler.rs | 32 +++---- src/dns/listen.rs | 14 +-- src/dns/record.rs | 62 +++++++------- src/dns/zone.rs | 4 +- 8 files changed, 146 insertions(+), 190 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d6e2733..6a2ad67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,7 +15,7 @@ dependencies = [ "log", "pin-project 0.4.30", "tokio 0.2.25", - "tokio-util", + "tokio-util 0.3.1", ] [[package]] @@ -33,8 +33,8 @@ dependencies = [ "futures-util", "http", "log", - "trust-dns-proto 0.19.7", - "trust-dns-resolver 0.19.7", + "trust-dns-proto", + "trust-dns-resolver", ] [[package]] @@ -550,6 +550,9 @@ dependencies = [ "clap", "farmhash", "flate2", + "hickory-proto", + "hickory-resolver", + "hickory-server", "http_req", "lazy_static", "log", @@ -565,10 +568,7 @@ dependencies = [ "tar", "tempfile", "tokio 1.38.1", - "toml 0.8.15", - "trust-dns-proto 0.23.2", - "trust-dns-resolver 0.23.2", - "trust-dns-server", + "toml", "url_serde", ] @@ -656,15 +656,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" -[[package]] -name = "drain" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d105028bd2b5dfcb33318fd79a445001ead36004dd8dffef1bdd7e493d8bc1e" -dependencies = [ - "tokio 1.38.1", -] - [[package]] name = "dtoa" version = "0.4.8" @@ -821,17 +812,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - [[package]] name = "futures-io" version = "0.3.30" @@ -941,7 +921,7 @@ dependencies = [ "indexmap 1.9.3", "slab", "tokio 0.2.25", - "tokio-util", + "tokio-util 0.3.1", "tracing", "tracing-futures", ] @@ -970,6 +950,69 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hickory-proto" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07698b8420e2f0d6447a436ba999ec85d8fbf2a398bbd737b82cac4a2e96e512" +dependencies = [ + "async-trait", + "cfg-if 1.0.0", + "data-encoding", + "enum-as-inner 0.6.0", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.4.0", + "ipnet", + "once_cell", + "rand 0.8.5", + "thiserror", + "tinyvec", + "tokio 1.38.1", + "tracing", + "url 2.5.2", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28757f23aa75c98f254cf0405e6d8c25b831b32921b050a66692427679b1f243" +dependencies = [ + "cfg-if 1.0.0", + "futures-util", + "hickory-proto", + "lru-cache", + "once_cell", + "parking_lot 0.12.3", + "rand 0.8.5", + "smallvec", + "thiserror", + "tokio 1.38.1", + "tracing", +] + +[[package]] +name = "hickory-server" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9be0e43c556b9b3fdb6c7c71a9a32153a2275d02419e3de809e520bfcfe40c37" +dependencies = [ + "async-trait", + "bytes 1.6.1", + "cfg-if 1.0.0", + "enum-as-inner 0.6.0", + "futures-util", + "hickory-proto", + "serde", + "thiserror", + "time 0.3.36", + "tokio 1.38.1", + "tokio-util 0.7.11", + "tracing", +] + [[package]] name = "hostname" version = "0.3.1" @@ -2219,15 +2262,16 @@ dependencies = [ ] [[package]] -name = "toml" -version = "0.7.8" +name = "tokio-util" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit 0.19.15", + "bytes 1.6.1", + "futures-core", + "futures-sink", + "pin-project-lite 0.2.14", + "tokio 1.38.1", ] [[package]] @@ -2239,7 +2283,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.16", + "toml_edit", ] [[package]] @@ -2251,19 +2295,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.2.6", - "serde", - "serde_spanned", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.22.16" @@ -2274,7 +2305,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.13", + "winnow", ] [[package]] @@ -2339,31 +2370,6 @@ dependencies = [ "url 2.5.2", ] -[[package]] -name = "trust-dns-proto" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3119112651c157f4488931a01e586aa459736e9d6046d3bd9105ffb69352d374" -dependencies = [ - "async-trait", - "cfg-if 1.0.0", - "data-encoding", - "enum-as-inner 0.6.0", - "futures-channel", - "futures-io", - "futures-util", - "idna 0.4.0", - "ipnet", - "once_cell", - "rand 0.8.5", - "smallvec", - "thiserror", - "tinyvec", - "tokio 1.38.1", - "tracing", - "url 2.5.2", -] - [[package]] name = "trust-dns-resolver" version = "0.19.7" @@ -2380,48 +2386,7 @@ dependencies = [ "smallvec", "thiserror", "tokio 0.2.25", - "trust-dns-proto 0.19.7", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a3e6c3aff1718b3c73e395d1f35202ba2ffa847c6a62eea0db8fb4cfe30be6" -dependencies = [ - "cfg-if 1.0.0", - "futures-util", - "lru-cache", - "once_cell", - "parking_lot 0.12.3", - "rand 0.8.5", - "smallvec", - "thiserror", - "tokio 1.38.1", - "tracing", - "trust-dns-proto 0.23.2", -] - -[[package]] -name = "trust-dns-server" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c540f73c2b2ec2f6c54eabd0900e7aafb747a820224b742f556e8faabb461bc7" -dependencies = [ - "async-trait", - "bytes 1.6.1", - "cfg-if 1.0.0", - "drain", - "enum-as-inner 0.6.0", - "futures-executor", - "futures-util", - "serde", - "thiserror", - "time 0.3.36", - "tokio 1.38.1", - "toml 0.7.8", - "tracing", - "trust-dns-proto 0.23.2", + "trust-dns-proto", ] [[package]] @@ -2771,15 +2736,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "winnow" -version = "0.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" -dependencies = [ - "memchr", -] - [[package]] name = "winnow" version = "0.6.13" diff --git a/Cargo.toml b/Cargo.toml index bda2819..c943d3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,9 +32,9 @@ r2d2_redis = "0.14" redis = "0.20" actix-web = { version = "3.3", default-features = false } actix-web-httpauth = "0.5" -trust-dns-server = { version = "0.23", default-features = false } -trust-dns-proto = { version = "0.23", default-features = false } -trust-dns-resolver = { version = "0.23", default-features = false, features = [ +hickory-server = { version = "0.24", default-features = false } +hickory-proto = { version = "0.24", default-features = false } +hickory-resolver = { version = "0.24", default-features = false, features = [ "tokio-runtime", ] } tokio = "1.21" diff --git a/src/dns/code.rs b/src/dns/code.rs index 696f1b7..0d69e4b 100644 --- a/src/dns/code.rs +++ b/src/dns/code.rs @@ -4,7 +4,7 @@ // Copyright: 2019, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -use trust_dns_proto::op::ResponseCode; +use hickory_proto::op::ResponseCode; #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)] pub enum CodeName { @@ -22,7 +22,7 @@ pub enum CodeName { } impl CodeName { - pub fn from_trust(response_code: &ResponseCode) -> Option { + pub fn from_hickory(response_code: &ResponseCode) -> Option { match response_code { &ResponseCode::NoError => Some(CodeName::NoError), &ResponseCode::FormErr => Some(CodeName::FormErr), diff --git a/src/dns/flatten.rs b/src/dns/flatten.rs index beb7cf2..04f863b 100644 --- a/src/dns/flatten.rs +++ b/src/dns/flatten.rs @@ -4,15 +4,15 @@ // Copyright: 2020, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) +use hickory_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts}; +use hickory_resolver::error::ResolveError; +use hickory_resolver::Resolver; use std::collections::HashMap; use std::net::ToSocketAddrs; use std::ops::Deref; use std::sync::RwLock; use std::thread; use std::time::{Duration, Instant, SystemTime}; -use trust_dns_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts}; -use trust_dns_resolver::error::ResolveError; -use trust_dns_resolver::Resolver; use super::record::{RecordType, RecordValue, RecordValues}; use crate::APP_CONF; diff --git a/src/dns/handler.rs b/src/dns/handler.rs index f675295..9d1f474 100644 --- a/src/dns/handler.rs +++ b/src/dns/handler.rs @@ -4,19 +4,19 @@ // Copyright: 2018, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) +use hickory_proto::op::header::Header; +use hickory_proto::op::{LowerQuery, MessageType, OpCode, ResponseCode}; +use hickory_proto::rr::{LowerName, Name, Record, RecordType as HickoryRecordType}; +use hickory_server::authority::{ + AuthLookup, Authority, LookupOptions, MessageRequest, MessageResponseBuilder, +}; +use hickory_server::server::{Request, RequestHandler, ResponseHandler, ResponseInfo}; +use hickory_server::store::in_memory::InMemoryAuthority; use rand::seq::SliceRandom; use rand::thread_rng; use std::collections::HashMap; use std::io::Error; use std::net::IpAddr; -use trust_dns_proto::op::header::Header; -use trust_dns_proto::op::{LowerQuery, MessageType, OpCode, ResponseCode}; -use trust_dns_proto::rr::{LowerName, Name, Record, RecordType as TrustRecordType}; -use trust_dns_server::authority::{ - AuthLookup, Authority, LookupOptions, MessageRequest, MessageResponseBuilder, -}; -use trust_dns_server::server::{Request, RequestHandler, ResponseHandler, ResponseInfo}; -use trust_dns_server::store::in_memory::InMemoryAuthority; use super::code::CodeName; use super::flatten::DNS_FLATTEN; @@ -115,7 +115,7 @@ impl DNSHandler { // #2. Handle the query let authority = authority_lookup.unwrap(); - let zone_name = ZoneName::from_trust(&authority.origin()); + let zone_name = ZoneName::from_hickory(&authority.origin()); info!( "request: {} found authority: {}", @@ -336,7 +336,7 @@ impl DNSHandler { query: &LowerQuery, ) -> Result>, ResponseCode> { let (query_name, query_type) = (query.name(), query.query_type()); - let record_type = RecordType::from_trust(&query_type); + let record_type = RecordType::from_hickory(&query_type); // Stack query type to metrics? if let Some(ref zone_name) = zone_name { @@ -403,10 +403,10 @@ impl DNSHandler { zone_name: &Option, query_name_client: &LowerName, query_name_effective: &LowerName, - query_type: &TrustRecordType, + query_type: &HickoryRecordType, record_type: &Option, ) -> Result>, ResponseCode> { - let record_name = RecordName::from_trust(&authority.origin(), query_name_effective); + let record_name = RecordName::from_hickory(&authority.origin(), query_name_effective); debug!( "lookup record in store for query: {} {} on zone: {:?}, record: {:?}, and type: {:?}", @@ -506,14 +506,14 @@ impl DNSHandler { fn parse_from_records( query_name_client: &LowerName, - query_type: &TrustRecordType, + query_type: &HickoryRecordType, record_type: &RecordType, source: IpAddr, zone_name: &ZoneName, record: &StoreRecord, records: &mut Vec, ) { - if let Ok(type_data) = record.kind.to_trust() { + if let Ok(type_data) = record.kind.to_hickory() { // Check if should resolve IP to country? let ip_country = if record.blackhole.is_some() == true || record.regions.is_some() == true { @@ -712,7 +712,7 @@ impl DNSHandler { // Append final prepared values to response for value in final_values { - if let Ok(value_data) = value.to_trust(final_kind) { + if let Ok(value_data) = value.to_hickory(final_kind) { let mut record = Record::from_rdata( Name::from(query_name_client.to_owned()), record_ttl, @@ -749,7 +749,7 @@ impl DNSHandler { ) { // Stack answer code to metrics? if let Some(ref zone_name) = zone_name { - let code_name = CodeName::from_trust(&code); + let code_name = CodeName::from_hickory(&code); METRICS_STORE.stack(zone_name, MetricsValue::AnswerCode(&code_name)); } diff --git a/src/dns/listen.rs b/src/dns/listen.rs index 5f9cce7..f6b31ad 100644 --- a/src/dns/listen.rs +++ b/src/dns/listen.rs @@ -4,14 +4,14 @@ // Copyright: 2018, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) +use hickory_proto::rr::rdata as HickoryRData; +use hickory_proto::rr::record_data::RData; +use hickory_proto::rr::{LowerName, Name, Record, RecordSet, RecordType, RrKey}; +use hickory_server::authority::ZoneType; +use hickory_server::server::ServerFuture; use std::collections::BTreeMap; use std::time::Duration; use tokio::net::{TcpListener, UdpSocket}; -use trust_dns_proto::rr::rdata as TrustRData; -use trust_dns_proto::rr::record_data::RData; -use trust_dns_proto::rr::{LowerName, Name, Record, RecordSet, RecordType, RrKey}; -use trust_dns_server::authority::ZoneType; -use trust_dns_server::server::ServerFuture; use super::handler::{DNSAuthority, DNSHandler}; use crate::APP_CONF; @@ -82,7 +82,7 @@ impl DNSListen { let soa_records = RecordSet::from(Record::from_rdata( name.to_owned(), APP_CONF.dns.record_ttl, - RData::SOA(TrustRData::SOA::new( + RData::SOA(HickoryRData::SOA::new( NAME_SOA_MASTER.to_owned(), NAME_SOA_RESPONSIBLE.to_owned(), SERIAL_DEFAULT, @@ -106,7 +106,7 @@ impl DNSListen { Record::from_rdata( name.to_owned(), APP_CONF.dns.record_ttl, - RData::NS(TrustRData::NS( + RData::NS(HickoryRData::NS( Name::parse(nameserver, Some(&Name::new())) .expect("invalid nameserver"), )), diff --git a/src/dns/record.rs b/src/dns/record.rs index ea190ad..8ec1b84 100644 --- a/src/dns/record.rs +++ b/src/dns/record.rs @@ -4,6 +4,10 @@ // Copyright: 2018, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) +use hickory_proto::rr::rdata as HickoryRData; +use hickory_proto::rr::{ + LowerName as HickoryLowerName, Name as HickoryName, RData, RecordType as HickoryRecordType, +}; use regex::Regex; use serde::de::{Error as DeserializeError, Unexpected, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -11,10 +15,6 @@ use std::cmp; use std::collections::HashSet; use std::ops::Deref; use std::{fmt, str}; -use trust_dns_proto::rr::rdata as TrustRData; -use trust_dns_proto::rr::{ - LowerName as TrustLowerName, Name as TrustName, RData, RecordType as TrustRecordType, -}; use crate::geo::country::CountryCode; @@ -84,14 +84,14 @@ impl RecordType { } } - pub fn from_trust(record_type: &TrustRecordType) -> Option { + pub fn from_hickory(record_type: &HickoryRecordType) -> Option { match record_type { - &TrustRecordType::A => Some(RecordType::A), - &TrustRecordType::AAAA => Some(RecordType::AAAA), - &TrustRecordType::CNAME => Some(RecordType::CNAME), - &TrustRecordType::MX => Some(RecordType::MX), - &TrustRecordType::TXT => Some(RecordType::TXT), - &TrustRecordType::PTR => Some(RecordType::PTR), + &HickoryRecordType::A => Some(RecordType::A), + &HickoryRecordType::AAAA => Some(RecordType::AAAA), + &HickoryRecordType::CNAME => Some(RecordType::CNAME), + &HickoryRecordType::MX => Some(RecordType::MX), + &HickoryRecordType::TXT => Some(RecordType::TXT), + &HickoryRecordType::PTR => Some(RecordType::PTR), _ => None, } } @@ -107,14 +107,14 @@ impl RecordType { } } - pub fn to_trust(&self) -> Result { + pub fn to_hickory(&self) -> Result { match *self { - RecordType::A => Ok(TrustRecordType::A), - RecordType::AAAA => Ok(TrustRecordType::AAAA), - RecordType::CNAME => Ok(TrustRecordType::CNAME), - RecordType::MX => Ok(TrustRecordType::MX), - RecordType::TXT => Ok(TrustRecordType::TXT), - RecordType::PTR => Ok(TrustRecordType::PTR), + RecordType::A => Ok(HickoryRecordType::A), + RecordType::AAAA => Ok(HickoryRecordType::AAAA), + RecordType::CNAME => Ok(HickoryRecordType::CNAME), + RecordType::MX => Ok(HickoryRecordType::MX), + RecordType::TXT => Ok(HickoryRecordType::TXT), + RecordType::PTR => Ok(HickoryRecordType::PTR), } } @@ -139,9 +139,9 @@ impl RecordName { } } - pub fn from_trust( - zone_name: &TrustLowerName, - query_name: &TrustLowerName, + pub fn from_hickory( + zone_name: &HickoryLowerName, + query_name: &HickoryLowerName, ) -> Option { let mut query_string = query_name.to_string().to_lowercase(); let query_len = query_string.len(); @@ -184,24 +184,24 @@ impl RecordName { } impl RecordValue { - pub fn to_trust(&self, record_type: &RecordType) -> Result { + pub fn to_hickory(&self, record_type: &RecordType) -> Result { match record_type { RecordType::A => { // Parse A into actual IPv4 self.parse() - .map(|value| RData::A(TrustRData::a::A(value))) + .map(|value| RData::A(HickoryRData::a::A(value))) .or(Err(())) } RecordType::AAAA => { // Parse AAAA into actual IPv6 self.parse() - .map(|value| RData::AAAA(TrustRData::aaaa::AAAA(value))) + .map(|value| RData::AAAA(HickoryRData::aaaa::AAAA(value))) .or(Err(())) } RecordType::CNAME => { // Parse CNAME into domain name - TrustName::parse(self, Some(&TrustName::new())) - .map(|value| RData::CNAME(TrustRData::name::CNAME(value))) + HickoryName::parse(self, Some(&HickoryName::new())) + .map(|value| RData::CNAME(HickoryRData::name::CNAME(value))) .or(Err(())) } RecordType::MX => { @@ -213,9 +213,9 @@ impl RecordValue { if let (Ok(priority), Ok(exchange)) = ( priority_str.parse::(), - TrustName::parse(exchange_str, Some(&TrustName::new())), + HickoryName::parse(exchange_str, Some(&HickoryName::new())), ) { - Ok(RData::MX(TrustRData::mx::MX::new(priority, exchange))) + Ok(RData::MX(HickoryRData::mx::MX::new(priority, exchange))) } else { Err(()) } @@ -235,13 +235,13 @@ impl RecordValue { } if !txt_splits.is_empty() { - Ok(RData::TXT(TrustRData::txt::TXT::new(txt_splits))) + Ok(RData::TXT(HickoryRData::txt::TXT::new(txt_splits))) } else { Err(()) } } - RecordType::PTR => TrustName::parse(self, Some(&TrustName::new())) - .map(|value| RData::PTR(TrustRData::PTR(value))) + RecordType::PTR => HickoryName::parse(self, Some(&HickoryName::new())) + .map(|value| RData::PTR(HickoryRData::PTR(value))) .or(Err(())), } } diff --git a/src/dns/zone.rs b/src/dns/zone.rs index b9132d3..88b23be 100644 --- a/src/dns/zone.rs +++ b/src/dns/zone.rs @@ -4,11 +4,11 @@ // Copyright: 2018, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) +use hickory_proto::rr::LowerName as HickoryLowerName; use regex::Regex; use serde::de::{Error as DeserializeError, Unexpected, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::{fmt, str}; -use trust_dns_proto::rr::LowerName as TrustLowerName; use crate::APP_CONF; @@ -33,7 +33,7 @@ impl ZoneName { } } - pub fn from_trust(query_name: &TrustLowerName) -> Option { + pub fn from_hickory(query_name: &HickoryLowerName) -> Option { let zone_string = query_name.to_string().to_lowercase(); let mut zone_len = zone_string.len(); From c39f74880fc1ed410acfc3b4ec0cb7fb04db79ff Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 19 Jul 2024 10:34:12 +0200 Subject: [PATCH 13/17] Update geo countries --- src/geo/country.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/geo/country.rs b/src/geo/country.rs index d3657a3..f7223d5 100644 --- a/src/geo/country.rs +++ b/src/geo/country.rs @@ -7,7 +7,7 @@ use super::region::RegionCode; //- Source: https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes/blob/master/all/all.csv -//- Last update: 13 August 2018 +//- Last update: 19 July 2024 #[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)] pub enum CountryCode { @@ -796,7 +796,7 @@ impl CountryCode { CountryCode::BJ => "Benin", CountryCode::BM => "Bermuda", CountryCode::BT => "Bhutan", - CountryCode::BO => "Bolivia (Plurinational State of)", + CountryCode::BO => "Bolivia, Plurinational State of", CountryCode::BQ => "Bonaire, Sint Eustatius and Saba", CountryCode::BA => "Bosnia and Herzegovina", CountryCode::BW => "Botswana", @@ -821,7 +821,7 @@ impl CountryCode { CountryCode::CO => "Colombia", CountryCode::KM => "Comoros", CountryCode::CG => "Congo", - CountryCode::CD => "Congo (Democratic Republic of the)", + CountryCode::CD => "Congo, Democratic Republic of the", CountryCode::CK => "Cook Islands", CountryCode::CR => "Costa Rica", CountryCode::CI => "Côte d'Ivoire", @@ -875,7 +875,7 @@ impl CountryCode { CountryCode::IS => "Iceland", CountryCode::IN => "India", CountryCode::ID => "Indonesia", - CountryCode::IR => "Iran (Islamic Republic of)", + CountryCode::IR => "Iran, Islamic Republic of", CountryCode::IQ => "Iraq", CountryCode::IE => "Ireland", CountryCode::IM => "Isle of Man", @@ -888,8 +888,8 @@ impl CountryCode { CountryCode::KZ => "Kazakhstan", CountryCode::KE => "Kenya", CountryCode::KI => "Kiribati", - CountryCode::KP => "Korea (Democratic People's Republic of)", - CountryCode::KR => "Korea (Republic of)", + CountryCode::KP => "Korea, Democratic People's Republic of", + CountryCode::KR => "Korea, Republic of", CountryCode::KW => "Kuwait", CountryCode::KG => "Kyrgyzstan", CountryCode::LA => "Lao People's Democratic Republic", @@ -902,7 +902,7 @@ impl CountryCode { CountryCode::LT => "Lithuania", CountryCode::LU => "Luxembourg", CountryCode::MO => "Macao", - CountryCode::MK => "Macedonia (the former Yugoslav Republic of)", + CountryCode::MK => "North Macedonia", CountryCode::MG => "Madagascar", CountryCode::MW => "Malawi", CountryCode::MY => "Malaysia", @@ -915,8 +915,8 @@ impl CountryCode { CountryCode::MU => "Mauritius", CountryCode::YT => "Mayotte", CountryCode::MX => "Mexico", - CountryCode::FM => "Micronesia (Federated States of)", - CountryCode::MD => "Moldova (Republic of)", + CountryCode::FM => "Micronesia, Federated States of", + CountryCode::MD => "Moldova, Republic of", CountryCode::MC => "Monaco", CountryCode::MN => "Mongolia", CountryCode::ME => "Montenegro", @@ -927,7 +927,7 @@ impl CountryCode { CountryCode::NA => "Namibia", CountryCode::NR => "Nauru", CountryCode::NP => "Nepal", - CountryCode::NL => "Netherlands", + CountryCode::NL => "Netherlands, Kingdom of the", CountryCode::NC => "New Caledonia", CountryCode::NZ => "New Zealand", CountryCode::NI => "Nicaragua", @@ -997,7 +997,7 @@ impl CountryCode { CountryCode::TO => "Tonga", CountryCode::TT => "Trinidad and Tobago", CountryCode::TN => "Tunisia", - CountryCode::TR => "Turkey", + CountryCode::TR => "Türkiye", CountryCode::TM => "Turkmenistan", CountryCode::TC => "Turks and Caicos Islands", CountryCode::TV => "Tuvalu", @@ -1010,7 +1010,7 @@ impl CountryCode { CountryCode::UY => "Uruguay", CountryCode::UZ => "Uzbekistan", CountryCode::VU => "Vanuatu", - CountryCode::VE => "Venezuela (Bolivarian Republic of)", + CountryCode::VE => "Venezuela, Bolivarian Republic of", CountryCode::VN => "Viet Nam", CountryCode::VG => "Virgin Islands (British)", CountryCode::VI => "Virgin Islands (U.S.)", From 7e1bf7bd69befe5e2a9bb00320adc58a602c9d21 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 19 Jul 2024 10:34:26 +0200 Subject: [PATCH 14/17] Add TODOs wherever blocking code has been found --- src/dns/handler.rs | 25 +++++++++++++++++++------ src/dns/health.rs | 1 + src/dns/listen.rs | 4 +++- src/http/routes.rs | 4 ++++ src/store/cache.rs | 1 + 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/dns/handler.rs b/src/dns/handler.rs index 9d1f474..eb1f4fc 100644 --- a/src/dns/handler.rs +++ b/src/dns/handler.rs @@ -45,7 +45,11 @@ impl RequestHandler for DNSHandler { responder: R, ) -> ResponseInfo { match self.handle(responder, request).await { - Ok(info) => info, + Ok(info) => { + debug!("success handling dns request"); + + info + } Err(error) => { error!("error handling dns request: {}", error); @@ -117,17 +121,17 @@ impl DNSHandler { let authority = authority_lookup.unwrap(); let zone_name = ZoneName::from_hickory(&authority.origin()); + let soa_records = authority.soa().await.unwrap_or(AuthLookup::Empty); + let soa_records_vec = soa_records.iter().collect(); + info!( "request: {} found authority: {}", request.id(), authority.origin() ); - // Acquire SOA records - let soa_records = authority.soa().await.unwrap_or(AuthLookup::Empty); - let soa_records_vec = soa_records.iter().collect(); - // #3. Attempt to resolve from local store + // Notice: this is used to serve local SOA and NS records. let records_local = authority .search(request.request_info(), LookupOptions::default()) .await @@ -149,7 +153,9 @@ impl DNSHandler { .await; } - // #4. Fallback on resolving from remote store + // #4. Resolve from remote store + // Notice: this is used to serve all records set with the HTTP API. + // TODO: this is a blocking code path (records_from_store() must be made async) return match Self::records_from_store(authority, &zone_name, request.src().ip(), query) { Ok(records_remote) => { // Serve response data? @@ -189,6 +195,7 @@ impl DNSHandler { ResponseCode::NoError } AuthLookup::Records { .. } | AuthLookup::AXFR { .. } => { + // This code path is unexpected and should never be reached panic!("error, should return noerror") } }; @@ -344,6 +351,7 @@ impl DNSHandler { } // Attempt with requested domain + // TODO: this is a blocking code path (method must be made async) let mut records = Self::records_from_store_attempt( authority, source, @@ -375,6 +383,7 @@ impl DNSHandler { let wildcard_name_lower = LowerName::new(&wildcard_name); if &wildcard_name_lower != query_name { + // TODO: this is a blocking code path (method must be made async) let records_wildcard = Self::records_from_store_attempt( authority, source, @@ -418,6 +427,7 @@ impl DNSHandler { let mut records = Vec::new(); if let &Some(ref record_type_inner) = record_type { + // TODO: this is a blocking code path (method must be made async) match APP_STORE.get( &zone_name, &record_name, @@ -451,6 +461,7 @@ impl DNSHandler { // Look for a CNAME result? (if no records were acquired) if record_type_inner != &RecordType::CNAME && records.is_empty() { + // TODO: this is a blocking code path (method must be made async) match APP_STORE.get( &zone_name, &record_name, @@ -491,6 +502,7 @@ impl DNSHandler { // No record found, exhaust all record types to check if name exists // Notice: a DNS server must return NOERROR if name exists, else NXDOMAIN + // TODO: this is a blocking code path (method must be made async) if Self::check_name_exists(&zone_name, &record_name, StoreAccessOrigin::External)? == true { @@ -777,6 +789,7 @@ impl DNSHandler { // Notice: instead of performing a simple exist check, we acquire full record data, \ // as this lets us use the local store and therefore prevent non-existing domain \ // attacks on the remote store. + // TODO: this is a blocking code path (method must be made async) match APP_STORE.get(zone_name, record_name, &record_type, origin) { Ok(_) => { // Record exists for name and type; abort there. diff --git a/src/dns/health.rs b/src/dns/health.rs index 75a189b..62acdff 100644 --- a/src/dns/health.rs +++ b/src/dns/health.rs @@ -175,6 +175,7 @@ impl DNSHealthHTTP { record_type ); + // TODO: this is a blocking code path (method must be made async) if let Ok(record) = APP_STORE.get( &domain.zone, &domain.name, diff --git a/src/dns/listen.rs b/src/dns/listen.rs index f6b31ad..f6d32b8 100644 --- a/src/dns/listen.rs +++ b/src/dns/listen.rs @@ -38,7 +38,8 @@ impl DNSListenBuilder { impl DNSListen { #[tokio::main] pub async fn run(&self) { - // Run the DNS server + // Prepare the DNS handler + // Notice: upsert all available authorities from the configuration. let mut handler: DNSHandler = DNSHandler::new(); for (zone_name, _) in &APP_CONF.dns.zone { @@ -48,6 +49,7 @@ impl DNSListen { } } + // Run the DNS server let mut server = ServerFuture::new(handler); // Register sockets & listeners diff --git a/src/http/routes.rs b/src/http/routes.rs index 581bcc4..121c8fd 100644 --- a/src/http/routes.rs +++ b/src/http/routes.rs @@ -44,6 +44,7 @@ async fn head_zone_record( RecordType, )>, ) -> HttpResponse { + // TODO: this is a blocking code path (method must be made async) APP_STORE .get( &zone_name.into_inner(), @@ -63,6 +64,7 @@ async fn get_zone_record( RecordType, )>, ) -> HttpResponse { + // TODO: this is a blocking code path (method must be made async) APP_STORE .get( &zone_name.into_inner(), @@ -95,6 +97,7 @@ async fn put_zone_record( data: web::Json, ) -> HttpResponse { + // TODO: this is a blocking code path (method must be made async) APP_STORE .set( &zone_name.into_inner(), @@ -121,6 +124,7 @@ async fn delete_zone_record( RecordType, )>, ) -> HttpResponse { + // TODO: this is a blocking code path (method must be made async) APP_STORE .remove(&zone_name.into_inner(), &record_name, &record_type) .map(|_| HttpResponse::Ok().finish()) diff --git a/src/store/cache.rs b/src/store/cache.rs index 22e575a..49f0181 100644 --- a/src/store/cache.rs +++ b/src/store/cache.rs @@ -148,6 +148,7 @@ impl StoreCacheFlush { for (store_key, store_accessed_at) in &refresh_register { // Notice: restore 'accessed_at' time, otherwise a never-accessed cache entry \ // would never be expired. + // TODO: this is a blocking code path (method must be made async) APP_STORE .raw_get_remote(store_key, Some(*store_accessed_at)) .ok(); From abf46f058ecbbb17e7150f4d2582999bae8273e7 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 19 Jul 2024 12:01:01 +0200 Subject: [PATCH 15/17] Address issues with GeoIP downloader --- src/geo/updater.rs | 79 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/src/geo/updater.rs b/src/geo/updater.rs index 0d35e3b..e7d3bec 100644 --- a/src/geo/updater.rs +++ b/src/geo/updater.rs @@ -51,7 +51,7 @@ impl GeoUpdater { // Hold on 2 seconds thread::sleep(Duration::from_secs(2)); - match Self::update_database(&update_url) { + match Self::update_database(&update_url, false) { Ok(_) => { info!("ran geo update operation"); @@ -94,39 +94,70 @@ impl GeoUpdater { return false; } - fn update_database(update_url: &str) -> Result<(), Option> { + fn update_database(update_url: &str, redirected: bool) -> Result<(), Option> { debug!("acquiring updated geo database"); match tempfile() { Ok(mut tmp_file) => { match HTTPRequest::get(update_url, &mut tmp_file) { - Ok(_) => { - debug!( - "downloaded updated geo database archive to file: {:?}", - tmp_file - ); - - // Reset file cursor to the beginning (prepare for reading) - tmp_file.seek(SeekFrom::Start(0)).unwrap(); - - // Extract archive - let tar = GzDecoder::new(tmp_file); - - match Archive::new(tar).entries() { - Ok(entries) => { - if Self::extract_archive(entries) == true { - Ok(()) - } else { - error!("no matching mmdb file found in geo database archive"); + Ok(response) => { + let status = response.status_code(); + + if status.is_success() { + debug!( + "downloaded updated geo database archive with status: {} to file: {:?}", + response.status_code(), + tmp_file + ); + + // Reset file cursor to the beginning (prepare for reading) + tmp_file.seek(SeekFrom::Start(0)).unwrap(); + + // Extract archive + let tar = GzDecoder::new(tmp_file); + + match Archive::new(tar).entries() { + Ok(entries) => { + if Self::extract_archive(entries) == true { + Ok(()) + } else { + error!( + "no matching mmdb file found in geo database archive" + ); + + Err(None) + } + } + Err(_) => { + error!("failed to list entries in geo database archive"); Err(None) } } - Err(_) => { - error!("failed to list entries in geo database archive"); - - Err(None) + } else if status.is_redirect() { + // Redirect to target location? + // Important: if not already redirected! + if let Some(location_url) = response.headers().get("Location") { + if !location_url.is_empty() && redirected == false { + info!( + "redirected to download updated geo database archive: {}", + location_url + ); + + return Self::update_database(location_url, true); + } } + + error!("bad redirection to download updated geo database archive"); + + Err(None) + } else { + error!( + "refused to download updated geo database archive (got status: {})", + status + ); + + Err(None) } } Err(err) => { From caf7475d5f29350d36fc07ee66b62503638c320b Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 19 Jul 2024 15:09:06 +0200 Subject: [PATCH 16/17] Simplify r2d2_redis deps tree --- Cargo.lock | 6 ++---- Cargo.toml | 2 -- src/store/store.rs | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a2ad67..ce1b18f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -475,9 +475,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" [[package]] name = "cfg-if" @@ -557,10 +557,8 @@ dependencies = [ "lazy_static", "log", "maxminddb", - "r2d2", "r2d2_redis", "rand 0.8.5", - "redis", "regex", "serde", "serde_derive", diff --git a/Cargo.toml b/Cargo.toml index c943d3a..141ffba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,9 +27,7 @@ serde_json = "1.0" url_serde = { version = "0.2", default-features = false } regex = "1.10" async-trait = "0.1" -r2d2 = "0.8" r2d2_redis = "0.14" -redis = "0.20" actix-web = { version = "3.3", default-features = false } actix-web-httpauth = "0.5" hickory-server = { version = "0.24", default-features = false } diff --git a/src/store/store.rs b/src/store/store.rs index 546dd31..486f928 100644 --- a/src/store/store.rs +++ b/src/store/store.rs @@ -4,9 +4,9 @@ // Copyright: 2018, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -use r2d2::Pool; +use r2d2_redis::r2d2::Pool; +use r2d2_redis::redis::{Commands, ErrorKind}; use r2d2_redis::RedisConnectionManager; -use redis::{Commands, ErrorKind}; use serde_json::{self, Error as SerdeJSONError}; use std::collections::HashSet; use std::sync::RwLock; From 4d326ae7d59503a47513091a2612127adadfe58c Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Sat, 20 Jul 2024 09:05:07 +0200 Subject: [PATCH 17/17] Migrate Redis from r2d2 to bb8 (fully async now!) --- Cargo.lock | 84 +++++++++++++++++++++------------------------ Cargo.toml | 2 +- src/dns/handler.rs | 61 +++++++++++++++++--------------- src/dns/health.rs | 23 +++++++------ src/http/routes.rs | 8 ++--- src/store/cache.rs | 4 +-- src/store/flush.rs | 9 ++--- src/store/macros.rs | 11 +++--- src/store/store.rs | 50 ++++++++++++++------------- 9 files changed, 133 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce1b18f..fb5a42e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -419,6 +419,29 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "bb8" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b10cf871f3ff2ce56432fddc2615ac7acc3aa22ca321f8fea800846fbb32f188" +dependencies = [ + "async-trait", + "futures-util", + "parking_lot 0.12.3", + "tokio 1.38.1", +] + +[[package]] +name = "bb8-redis" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb4f141b33a750b5f667c445bd8588de10b8f2b045cd2aabc040ca746fb53ae" +dependencies = [ + "async-trait", + "bb8", + "redis", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -531,7 +554,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" dependencies = [ "bytes 1.6.1", + "futures-core", "memchr", + "pin-project-lite 0.2.14", + "tokio 1.38.1", + "tokio-util 0.7.11", ] [[package]] @@ -547,6 +574,7 @@ dependencies = [ "actix-web", "actix-web-httpauth", "async-trait", + "bb8-redis", "clap", "farmhash", "flate2", @@ -557,7 +585,6 @@ dependencies = [ "lazy_static", "log", "maxminddb", - "r2d2_redis", "rand 0.8.5", "regex", "serde", @@ -654,12 +681,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" -[[package]] -name = "dtoa" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" - [[package]] name = "either" version = "1.13.0" @@ -1548,27 +1569,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "r2d2" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93" -dependencies = [ - "log", - "parking_lot 0.12.3", - "scheduled-thread-pool", -] - -[[package]] -name = "r2d2_redis" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "182473b876b0b93e353682ec58e207dd1cb4a62278bbe0045fe52b86b74363bb" -dependencies = [ - "r2d2", - "redis", -] - [[package]] name = "rand" version = "0.7.3" @@ -1642,16 +1642,20 @@ dependencies = [ [[package]] name = "redis" -version = "0.20.2" +version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4f0ceb2ec0dd769483ecd283f6615aa83dcd0be556d5294c6e659caefe7cc54" +checksum = "e0d7a6955c7511f60f3ba9e86c6d02b3c3f144f8c24b288d1f4e18074ab8bbec" dependencies = [ "async-trait", + "bytes 1.6.1", "combine", - "dtoa", - "itoa 0.4.8", + "futures-util", + "itoa 1.0.11", "percent-encoding 2.3.1", - "sha1", + "pin-project-lite 0.2.14", + "ryu", + "tokio 1.38.1", + "tokio-util 0.7.11", "url 2.5.2", ] @@ -1810,15 +1814,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "scheduled-thread-pool" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbc66816425a074528352f5789333ecff06ca41b36b0b0efdfbb29edc391a19" -dependencies = [ - "parking_lot 0.12.3", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -2228,6 +2223,7 @@ dependencies = [ "libc", "mio 0.8.11", "num_cpus", + "parking_lot 0.12.3", "pin-project-lite 0.2.14", "socket2 0.5.7", "tokio-macros", @@ -2736,9 +2732,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" +checksum = "374ec40a2d767a3c1b4972d9475ecd557356637be906f2cb3f7fe17a6eb5e22f" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 141ffba..547a486 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ serde_json = "1.0" url_serde = { version = "0.2", default-features = false } regex = "1.10" async-trait = "0.1" -r2d2_redis = "0.14" +bb8-redis = "0.15" actix-web = { version = "3.3", default-features = false } actix-web-httpauth = "0.5" hickory-server = { version = "0.24", default-features = false } diff --git a/src/dns/handler.rs b/src/dns/handler.rs index eb1f4fc..9baa02f 100644 --- a/src/dns/handler.rs +++ b/src/dns/handler.rs @@ -155,8 +155,9 @@ impl DNSHandler { // #4. Resolve from remote store // Notice: this is used to serve all records set with the HTTP API. - // TODO: this is a blocking code path (records_from_store() must be made async) - return match Self::records_from_store(authority, &zone_name, request.src().ip(), query) { + return match Self::records_from_store(authority, &zone_name, request.src().ip(), query) + .await + { Ok(records_remote) => { // Serve response data? if let Some(records_remote_inner) = records_remote { @@ -336,7 +337,7 @@ impl DNSHandler { None } - fn records_from_store( + async fn records_from_store( authority: &DNSAuthority, zone_name: &Option, source: IpAddr, @@ -351,7 +352,6 @@ impl DNSHandler { } // Attempt with requested domain - // TODO: this is a blocking code path (method must be made async) let mut records = Self::records_from_store_attempt( authority, source, @@ -360,7 +360,8 @@ impl DNSHandler { &query_name, &query_type, &record_type, - )?; + ) + .await?; // Check if 'records' is empty let is_records_empty = if let Some(ref records_inner) = records { @@ -383,7 +384,6 @@ impl DNSHandler { let wildcard_name_lower = LowerName::new(&wildcard_name); if &wildcard_name_lower != query_name { - // TODO: this is a blocking code path (method must be made async) let records_wildcard = Self::records_from_store_attempt( authority, source, @@ -392,7 +392,8 @@ impl DNSHandler { &wildcard_name_lower, &query_type, &record_type, - )?; + ) + .await?; // Assign non-none wildcard records? (retain any NOERROR from 'records') if records_wildcard.is_none() == false { @@ -406,7 +407,7 @@ impl DNSHandler { Ok(records) } - fn records_from_store_attempt( + async fn records_from_store_attempt( authority: &DNSAuthority, source: IpAddr, zone_name: &Option, @@ -427,13 +428,15 @@ impl DNSHandler { let mut records = Vec::new(); if let &Some(ref record_type_inner) = record_type { - // TODO: this is a blocking code path (method must be made async) - match APP_STORE.get( - &zone_name, - &record_name, - record_type_inner, - StoreAccessOrigin::External, - ) { + match APP_STORE + .get( + &zone_name, + &record_name, + record_type_inner, + StoreAccessOrigin::External, + ) + .await + { Ok(record) => { debug!( "found record in store for query: {} {}; got: {:?}", @@ -461,13 +464,15 @@ impl DNSHandler { // Look for a CNAME result? (if no records were acquired) if record_type_inner != &RecordType::CNAME && records.is_empty() { - // TODO: this is a blocking code path (method must be made async) - match APP_STORE.get( - &zone_name, - &record_name, - &RecordType::CNAME, - StoreAccessOrigin::External, - ) { + match APP_STORE + .get( + &zone_name, + &record_name, + &RecordType::CNAME, + StoreAccessOrigin::External, + ) + .await + { Ok(record_cname) => { debug!( "found cname hint record in store for query: {} {}; got: {:?}", @@ -502,8 +507,8 @@ impl DNSHandler { // No record found, exhaust all record types to check if name exists // Notice: a DNS server must return NOERROR if name exists, else NXDOMAIN - // TODO: this is a blocking code path (method must be made async) - if Self::check_name_exists(&zone_name, &record_name, StoreAccessOrigin::External)? + if Self::check_name_exists(&zone_name, &record_name, StoreAccessOrigin::External) + .await? == true { // Name exists, return empty records (ie. NOERROR) @@ -778,7 +783,7 @@ impl DNSHandler { } } - fn check_name_exists( + async fn check_name_exists( zone_name: &ZoneName, record_name: &RecordName, origin: StoreAccessOrigin, @@ -789,8 +794,10 @@ impl DNSHandler { // Notice: instead of performing a simple exist check, we acquire full record data, \ // as this lets us use the local store and therefore prevent non-existing domain \ // attacks on the remote store. - // TODO: this is a blocking code path (method must be made async) - match APP_STORE.get(zone_name, record_name, &record_type, origin) { + match APP_STORE + .get(zone_name, record_name, &record_type, origin) + .await + { Ok(_) => { // Record exists for name and type; abort there. return Ok(true); diff --git a/src/dns/health.rs b/src/dns/health.rs index 62acdff..aab4b54 100644 --- a/src/dns/health.rs +++ b/src/dns/health.rs @@ -156,17 +156,18 @@ impl DNSHealth { } impl DNSHealthHTTP { - fn run(notifier: &mut DNSHealthNotify) { + #[tokio::main] + async fn run(notifier: &mut DNSHealthNotify) { debug!("running dns health checks for the http protocol..."); for domain in &APP_CONF.dns.health.http { - Self::check_domain(domain, notifier); + Self::check_domain(domain, notifier).await; } debug!("ran dns health checks for the http protocol"); } - fn check_domain(domain: &ConfigDNSHealthHTTP, notifier: &mut DNSHealthNotify) { + async fn check_domain(domain: &ConfigDNSHealthHTTP, notifier: &mut DNSHealthNotify) { for record_type in HEALTH_CHECK_RECORD_TYPES.iter() { debug!( "checking dns health for target: {} on zone: {} with type: {:?}", @@ -175,13 +176,15 @@ impl DNSHealthHTTP { record_type ); - // TODO: this is a blocking code path (method must be made async) - if let Ok(record) = APP_STORE.get( - &domain.zone, - &domain.name, - record_type, - StoreAccessOrigin::Internal, - ) { + if let Ok(record) = APP_STORE + .get( + &domain.zone, + &domain.name, + record_type, + StoreAccessOrigin::Internal, + ) + .await + { let unique_values = record.list_record_values(); for record_value in unique_values { diff --git a/src/http/routes.rs b/src/http/routes.rs index 121c8fd..7e47304 100644 --- a/src/http/routes.rs +++ b/src/http/routes.rs @@ -44,7 +44,6 @@ async fn head_zone_record( RecordType, )>, ) -> HttpResponse { - // TODO: this is a blocking code path (method must be made async) APP_STORE .get( &zone_name.into_inner(), @@ -52,6 +51,7 @@ async fn head_zone_record( &record_type, StoreAccessOrigin::Internal, ) + .await .map(|_| HttpResponse::Ok().finish()) .unwrap_or(HttpResponse::NotFound().finish()) } @@ -64,7 +64,6 @@ async fn get_zone_record( RecordType, )>, ) -> HttpResponse { - // TODO: this is a blocking code path (method must be made async) APP_STORE .get( &zone_name.into_inner(), @@ -72,6 +71,7 @@ async fn get_zone_record( &record_type, StoreAccessOrigin::Internal, ) + .await .map(|record| { HttpResponse::Ok().json(RecordGetResponse { _type: record.kind, @@ -97,7 +97,6 @@ async fn put_zone_record( data: web::Json, ) -> HttpResponse { - // TODO: this is a blocking code path (method must be made async) APP_STORE .set( &zone_name.into_inner(), @@ -112,6 +111,7 @@ async fn put_zone_record( values: data.values.to_owned(), }, ) + .await .map(|_| HttpResponse::Ok().finish()) .unwrap_or(HttpResponse::ServiceUnavailable().finish()) } @@ -124,9 +124,9 @@ async fn delete_zone_record( RecordType, )>, ) -> HttpResponse { - // TODO: this is a blocking code path (method must be made async) APP_STORE .remove(&zone_name.into_inner(), &record_name, &record_type) + .await .map(|_| HttpResponse::Ok().finish()) .unwrap_or(HttpResponse::ServiceUnavailable().finish()) } diff --git a/src/store/cache.rs b/src/store/cache.rs index 49f0181..d0e45d5 100644 --- a/src/store/cache.rs +++ b/src/store/cache.rs @@ -121,7 +121,7 @@ impl StoreCacheFlush { ); } - pub fn refresh() { + pub async fn refresh() { debug!("flushing to-be-refreshed store cache records"); let mut refresh_register: Vec<(String, SystemTime)> = Vec::new(); @@ -148,9 +148,9 @@ impl StoreCacheFlush { for (store_key, store_accessed_at) in &refresh_register { // Notice: restore 'accessed_at' time, otherwise a never-accessed cache entry \ // would never be expired. - // TODO: this is a blocking code path (method must be made async) APP_STORE .raw_get_remote(store_key, Some(*store_accessed_at)) + .await .ok(); } } diff --git a/src/store/flush.rs b/src/store/flush.rs index 569b417..86ad246 100644 --- a/src/store/flush.rs +++ b/src/store/flush.rs @@ -21,7 +21,8 @@ impl StoreFlushBuilder { } impl StoreFlush { - pub fn run(&self) { + #[tokio::main] + pub async fn run(&self) { info!("store flusher is now active"); loop { @@ -32,7 +33,7 @@ impl StoreFlush { let flush_start = Instant::now(); - Self::perform(); + Self::perform().await; let flush_took = flush_start.elapsed(); @@ -44,13 +45,13 @@ impl StoreFlush { } } - fn perform() { + async fn perform() { // Proceed all perform actions // #1: Flush expired cache StoreCacheFlush::expire(); // #2: Flush to-be-refreshed cache - StoreCacheFlush::refresh(); + StoreCacheFlush::refresh().await; } } diff --git a/src/store/macros.rs b/src/store/macros.rs index 8d3b633..f2c815f 100644 --- a/src/store/macros.rs +++ b/src/store/macros.rs @@ -14,15 +14,18 @@ macro_rules! get_cache_store_client { for (pool, target) in $pools { // Attempt to get the first healthy pool, in order - match pool.try_get() { - Some(mut $client) => { + match pool.get().await { + Ok(mut $client) => { debug!("acquired cache store client at: {}", target); // Healthy pool acquired, return immediately (break the acquire loop) return $code; } - None => { - warn!("could not acquire cache store client from sub-pool"); + Err(err) => { + warn!( + "could not acquire cache store client from sub-pool: {}", + err + ); last_error = $error } diff --git a/src/store/store.rs b/src/store/store.rs index 486f928..a4d8594 100644 --- a/src/store/store.rs +++ b/src/store/store.rs @@ -4,9 +4,9 @@ // Copyright: 2018, Valerian Saliou // License: Mozilla Public License v2.0 (MPL v2.0) -use r2d2_redis::r2d2::Pool; -use r2d2_redis::redis::{Commands, ErrorKind}; -use r2d2_redis::RedisConnectionManager; +use bb8_redis::bb8::Pool; +use bb8_redis::redis::{AsyncCommands, ErrorKind}; +use bb8_redis::RedisConnectionManager; use serde_json::{self, Error as SerdeJSONError}; use std::collections::HashSet; use std::sync::RwLock; @@ -89,7 +89,8 @@ pub enum StoreAccessOrigin { } impl StoreBuilder { - pub fn new() -> Store { + #[tokio::main] + pub async fn new() -> Store { let mut pools = Vec::new(); // Bind to master pool @@ -98,12 +99,13 @@ impl StoreBuilder { &APP_CONF.redis.master.host, APP_CONF.redis.master.port, &APP_CONF.redis.master.password, - ); + ) + .await; // Bind to rescue pools (if any) if let Some(ref rescue_items) = APP_CONF.redis.rescue { for rescue in rescue_items { - Self::pool_bind(&mut pools, &rescue.host, rescue.port, &rescue.password); + Self::pool_bind(&mut pools, &rescue.host, rescue.port, &rescue.password).await; } } @@ -112,21 +114,23 @@ impl StoreBuilder { rate: RwLock::new(StoreLimitsRate::default()), }; - Store { - pools: pools, - limits: limits, - } + Store { pools, limits } } - fn pool_bind(pools: &mut Vec, host: &str, port: u16, password: &Option) { + async fn pool_bind( + pools: &mut Vec, + host: &str, + port: u16, + password: &Option, + ) { // Establish pool connection for this Redis target - match Self::pool_connect(host, port, password) { + match Self::pool_connect(host, port, password).await { Ok(master_pool) => pools.push(master_pool), Err(err) => panic!("store error: {}", err), } } - fn pool_connect( + async fn pool_connect( host: &str, port: u16, password: &Option, @@ -160,7 +164,7 @@ impl StoreBuilder { APP_CONF.redis.connection_timeout_seconds, )); - match builder.build(manager) { + match builder.build(manager).await { Ok(pool) => { info!("connected to redis at: {}", tcp_addr_raw); @@ -175,7 +179,7 @@ impl StoreBuilder { } impl Store { - pub fn get( + pub async fn get( &self, zone_name: &ZoneName, record_name: &RecordName, @@ -206,7 +210,7 @@ impl Store { ); // Read result from remote store - return self.raw_get_remote(&store_key, None); + return self.raw_get_remote(&store_key, None).await; } // #3. Get from store (external origin, ie. DOS-unsafe, thus we need to apply limits) @@ -260,7 +264,7 @@ impl Store { } // Read result from remote store - let result_remote = self.raw_get_remote(&store_key, None); + let result_remote = self.raw_get_remote(&store_key, None).await; // Update time spent in current timespan { @@ -277,7 +281,7 @@ impl Store { result_remote } - pub fn set(&self, zone_name: &ZoneName, record: StoreRecord) -> Result<(), StoreError> { + pub async fn set(&self, zone_name: &ZoneName, record: StoreRecord) -> Result<(), StoreError> { get_cache_store_client!(&self.pools, StoreError::Disconnected, client { let flatten_encoder: Result = match record.flatten { Some(true) => { @@ -335,7 +339,7 @@ impl Store { (KEY_RESCUE, &rescue), (KEY_VALUE, &values), ] - ).or(Err(StoreError::Connector)) + ).await.or(Err(StoreError::Connector)) }, (Err(_), _, _, _, _) | (_, Err(_), _, _, _) | @@ -348,7 +352,7 @@ impl Store { }) } - pub fn remove( + pub async fn remove( &self, zone_name: &ZoneName, record_name: &RecordName, @@ -361,11 +365,11 @@ impl Store { STORE_CACHE.pop(&store_key); // Delete from remote - client.del(store_key).or(Err(StoreError::Connector)) + client.del(store_key).await.or(Err(StoreError::Connector)) }) } - pub fn raw_get_remote( + pub async fn raw_get_remote( &self, store_key: &str, cache_accessed_at: Option, @@ -384,7 +388,7 @@ impl Store { KEY_RESCUE, KEY_VALUE ), - ) { + ).await { Ok(values) => { if let (Some(kind_value), Some(name_value), Ok(value_value)) = ( RecordType::from_str(&values.0),