v0.1
This commit is contained in:
commit
2db0768f2f
|
@ -0,0 +1 @@
|
|||
/target
|
|
@ -0,0 +1,784 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "cidr"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "300bccc729b1ada84523246038aad61fead689ac362bb9d44beea6f6a188c34b"
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb"
|
||||
|
||||
[[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.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8"
|
||||
dependencies = [
|
||||
"matches",
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6"
|
||||
dependencies = [
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipinfo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"cidr",
|
||||
"tokio",
|
||||
"trust-dns-server",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.144"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wasi",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nibble_vec"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "radix_trie"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd"
|
||||
dependencies = [
|
||||
"endian-type",
|
||||
"nibble_vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.162"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71b2f6e1ab5c2b98c05f0f35b236b22e8df7ead6ffbf51d7808da7f8817e7ab6"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.162"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2a0814352fd64b58489904a44ea8d90cb1a91dcb6b4f5ebabc32c8318e93cb6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb"
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3c786bf8134e5a3a166db9b29ab8f48134739014a3eca7bc6bfa95d673b136f"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"bytes",
|
||||
"libc",
|
||||
"mio",
|
||||
"num_cpus",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trust-dns-client"
|
||||
version = "0.22.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c408c32e6a9dbb38037cece35740f2cf23c875d8ca134d33631cec83f74d3fe"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"data-encoding",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"lazy_static",
|
||||
"radix_trie",
|
||||
"rand",
|
||||
"thiserror",
|
||||
"time",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"trust-dns-proto",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trust-dns-proto"
|
||||
version = "0.22.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f7f83d1e4a0e4358ac54c5c3681e5d7da5efc5a7a632c90bb6d6669ddd9bc26"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"cfg-if",
|
||||
"data-encoding",
|
||||
"enum-as-inner",
|
||||
"futures-channel",
|
||||
"futures-io",
|
||||
"futures-util",
|
||||
"idna 0.2.3",
|
||||
"ipnet",
|
||||
"lazy_static",
|
||||
"rand",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"tinyvec",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trust-dns-server"
|
||||
version = "0.22.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1583cf9f8a359c9f16fdf760b79cb2be3f261b98db8027f81959c7a4f6645e2c"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"cfg-if",
|
||||
"enum-as-inner",
|
||||
"futures-executor",
|
||||
"futures-util",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"time",
|
||||
"tokio",
|
||||
"toml",
|
||||
"tracing",
|
||||
"trust-dns-client",
|
||||
"trust-dns-proto",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna 0.3.0",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.45.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
|
||||
dependencies = [
|
||||
"windows-targets 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.42.2",
|
||||
"windows_aarch64_msvc 0.42.2",
|
||||
"windows_i686_gnu 0.42.2",
|
||||
"windows_i686_msvc 0.42.2",
|
||||
"windows_x86_64_gnu 0.42.2",
|
||||
"windows_x86_64_gnullvm 0.42.2",
|
||||
"windows_x86_64_msvc 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.48.0",
|
||||
"windows_aarch64_msvc 0.48.0",
|
||||
"windows_i686_gnu 0.48.0",
|
||||
"windows_i686_msvc 0.48.0",
|
||||
"windows_x86_64_gnu 0.48.0",
|
||||
"windows_x86_64_gnullvm 0.48.0",
|
||||
"windows_x86_64_msvc 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "ipinfo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
cidr = "0.2"
|
||||
anyhow = "1.0"
|
||||
trust-dns-server = "0.22"
|
||||
tokio = { version = "1.28", features = ["macros", "net", "io-util", "rt"] }
|
||||
async-trait = "0.1"
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
# ipinfo
|
||||
|
||||
A tool to provide ipinfo over DNS, similar to [team cymrus IP to
|
||||
ASN mapping](https://www.team-cymru.com/ip-asn-mapping) for dn42.
|
||||
|
||||
With this, ASNs can be provided to MTR for example by setting it as
|
||||
a custom ipinfo server.
|
||||
|
||||
### Configuration
|
||||
|
||||
Configuration is done over enviromental variables. Available options:
|
||||
|
||||
- REGISTRY: path to registry repository (default: `./registry`)
|
||||
- DOMAIN: base domain eg. `ip.catgirls.dn42.` (notice the trailing dot)
|
||||
- BIND: IP to bind to (default: `::`)
|
||||
- PORT: port to bind to (default: `53`)
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
use crate::registry::{Entry, Registry};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use tokio::net::UdpSocket;
|
||||
use trust_dns_server::server::ResponseInfo;
|
||||
use trust_dns_server::{
|
||||
authority::MessageResponseBuilder,
|
||||
proto::{
|
||||
op::{Header, MessageType, OpCode},
|
||||
rr::{rdata::TXT, RData, Record, RecordType},
|
||||
},
|
||||
server::{RequestHandler, ResponseHandler},
|
||||
ServerFuture,
|
||||
};
|
||||
use trust_dns_server::{proto::op::ResponseCode, server::Request};
|
||||
|
||||
pub struct Handler {
|
||||
server: ServerFuture<LookupHandler>,
|
||||
}
|
||||
|
||||
pub struct LookupHandler {
|
||||
registry: Vec<Entry>,
|
||||
domain: String,
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub async fn new(ip: IpAddr, port: u16, registry: Vec<Entry>, domain: String) -> anyhow::Result<Self> {
|
||||
let socket = UdpSocket::bind(SocketAddr::new(ip, port)).await?;
|
||||
let handler = LookupHandler::new(registry, domain);
|
||||
let mut server = ServerFuture::new(handler);
|
||||
server.register_socket(socket);
|
||||
|
||||
Ok(Self { server })
|
||||
}
|
||||
|
||||
pub async fn handle(self) -> anyhow::Result<()> {
|
||||
self.server.block_until_done().await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl LookupHandler {
|
||||
pub fn new(registry: Vec<Entry>, domain: String) -> Self {
|
||||
Self { registry, domain }
|
||||
}
|
||||
|
||||
pub async fn do_txt_lookup<R: ResponseHandler>(
|
||||
&self,
|
||||
request: &Request,
|
||||
mut responder: R,
|
||||
) -> anyhow::Result<ResponseInfo> {
|
||||
let domain = request.query().name().to_string();
|
||||
if let Some(query) = domain.strip_suffix(&self.domain) {
|
||||
println!("{query}");
|
||||
let builder = MessageResponseBuilder::from_message_request(request);
|
||||
let mut header = Header::response_from_request(request.header());
|
||||
header.set_authoritative(true);
|
||||
|
||||
if let Some(asn) = query.strip_prefix("as") {
|
||||
let asn = asn.parse()?;
|
||||
if let Some(entry) = Registry::get_by_asn(&self.registry, asn) {
|
||||
let rdata = RData::TXT(TXT::new(vec![entry]));
|
||||
let records = vec![Record::from_rdata(request.query().name().into(), 0, rdata)];
|
||||
let response = builder.build(header, records.iter(), &[], &[], &[]);
|
||||
Ok(responder.send_response(response).await?)
|
||||
} else {
|
||||
self.do_nxdomain(request, responder).await
|
||||
}
|
||||
} else {
|
||||
let parts: Vec<&str> = query.split('.').rev().collect();
|
||||
let mut addr = String::new();
|
||||
if parts.len() == 4 {
|
||||
for octet in parts {
|
||||
addr.push_str(octet);
|
||||
addr.push('.');
|
||||
}
|
||||
addr = addr.strip_suffix('.').unwrap().to_string();
|
||||
} else {
|
||||
let mut count = 0;
|
||||
let mut octets = 0;
|
||||
for part in parts {
|
||||
addr.push_str(part);
|
||||
count += 1;
|
||||
if count >= 4 {
|
||||
addr.push(':');
|
||||
count = 0;
|
||||
octets += 1;
|
||||
}
|
||||
}
|
||||
for _ in octets..8 {
|
||||
addr.push_str("0:");
|
||||
}
|
||||
addr = addr.strip_suffix(':').unwrap().to_string();
|
||||
}
|
||||
|
||||
let addr = addr.parse()?;
|
||||
if let Some(entry) = match addr {
|
||||
IpAddr::V4(v4) => Registry::get_by_ipv4(&self.registry, v4),
|
||||
IpAddr::V6(v6) => Registry::get_by_ipv6(&self.registry, &v6),
|
||||
} {
|
||||
let rdata = RData::TXT(TXT::new(vec![entry]));
|
||||
let records = vec![Record::from_rdata(request.query().name().into(), 0, rdata)];
|
||||
let response = builder.build(header, records.iter(), &[], &[], &[]);
|
||||
Ok(responder.send_response(response).await?)
|
||||
} else {
|
||||
self.do_nxdomain(request, responder).await
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.do_nxdomain(request, responder).await
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn do_nxdomain<R: ResponseHandler>(
|
||||
&self,
|
||||
request: &Request,
|
||||
mut responder: R,
|
||||
) -> anyhow::Result<ResponseInfo> {
|
||||
let record_type = request.query().query_type();
|
||||
let domain = request.query().name();
|
||||
println!("{domain}: {record_type}");
|
||||
|
||||
let builder = MessageResponseBuilder::from_message_request(request);
|
||||
let mut header = Header::response_from_request(request.header());
|
||||
|
||||
header.set_authoritative(true);
|
||||
header.set_response_code(ResponseCode::NXDomain);
|
||||
|
||||
let response = builder.build_no_records(header);
|
||||
Ok(responder.send_response(response).await?)
|
||||
}
|
||||
|
||||
pub async fn do_lookup<R: ResponseHandler>(
|
||||
&self,
|
||||
request: &Request,
|
||||
responder: R,
|
||||
) -> anyhow::Result<ResponseInfo> {
|
||||
if request.op_code() != OpCode::Query {
|
||||
anyhow::bail!("Invalid OpCode: {}", request.op_code());
|
||||
}
|
||||
|
||||
if request.message_type() != MessageType::Query {
|
||||
anyhow::bail!("Invalid message type: {}", request.message_type());
|
||||
}
|
||||
|
||||
match request.query().query_type() {
|
||||
RecordType::TXT => self.do_txt_lookup(request, responder).await,
|
||||
_ => self.do_nxdomain(request, responder).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestHandler for LookupHandler {
|
||||
async fn handle_request<R: ResponseHandler>(
|
||||
&self,
|
||||
request: &Request,
|
||||
response: R,
|
||||
) -> ResponseInfo {
|
||||
match self.do_lookup(request, response).await {
|
||||
Ok(info) => info,
|
||||
Err(e) => {
|
||||
println!("{e}");
|
||||
let mut header = Header::new();
|
||||
header.set_response_code(trust_dns_server::proto::op::ResponseCode::ServFail);
|
||||
header.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
mod dns;
|
||||
mod registry;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let path = std::env::var("REGISTRY").unwrap_or("registry".to_string());
|
||||
let domain = std::env::var("DOMAIN");
|
||||
let ip = std::env::var("BIND").unwrap_or("::".to_string());
|
||||
let port = std::env::var("PORT").unwrap_or("53".to_string());
|
||||
|
||||
if domain.is_err() {
|
||||
anyhow::bail!("DOMAIN env var is not set");
|
||||
}
|
||||
|
||||
let ip = ip.parse()?;
|
||||
let port = port.parse()?;
|
||||
|
||||
let registry = registry::Registry::new(path);
|
||||
let registry_index = registry.index()?;
|
||||
|
||||
let dns = dns::Handler::new(ip, port, registry_index, domain?).await?;
|
||||
dns.handle().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
use cidr::{Ipv4Inet, Ipv6Inet};
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
static AS_PATH: &str = "data/aut-num";
|
||||
static INETNUM: &str = "data/inetnum";
|
||||
static INET6NUM: &str = "data/inet6num";
|
||||
|
||||
pub struct Registry {
|
||||
path: String,
|
||||
}
|
||||
|
||||
impl Registry {
|
||||
pub fn new(path: String) -> Self {
|
||||
Self { path }
|
||||
}
|
||||
|
||||
pub fn index(self) -> anyhow::Result<Vec<Entry>> {
|
||||
let mut ret = Vec::new();
|
||||
|
||||
let aut_num = std::fs::read_dir(format!("{}/{AS_PATH}", self.path))?;
|
||||
for aut_num in aut_num {
|
||||
let content = std::fs::read_to_string(aut_num?.path())?;
|
||||
let lines = content.lines();
|
||||
|
||||
let mut asn = None;
|
||||
let mut mnt = None;
|
||||
|
||||
for line in lines {
|
||||
if line.starts_with("aut-num:") {
|
||||
let line = line
|
||||
.strip_prefix("aut-num:")
|
||||
.unwrap()
|
||||
.trim()
|
||||
.strip_prefix("AS")
|
||||
.unwrap();
|
||||
|
||||
asn = Some(line.parse()?);
|
||||
} else if line.starts_with("mnt-by:") {
|
||||
let line = line.strip_prefix("mnt-by:").unwrap().trim();
|
||||
mnt = Some(line.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
let entry = Entry {
|
||||
asn: asn.unwrap(),
|
||||
mnt: mnt.unwrap(),
|
||||
ipv4: None,
|
||||
ipv6: None,
|
||||
};
|
||||
|
||||
ret.push(entry);
|
||||
}
|
||||
|
||||
let inetnum = std::fs::read_dir(format!("{}/{INETNUM}", self.path))?;
|
||||
for inetnum in inetnum {
|
||||
let content = std::fs::read_to_string(inetnum?.path())?;
|
||||
let lines = content.lines().rev();
|
||||
|
||||
let mut entry = None;
|
||||
let mut ip = None;
|
||||
|
||||
for line in lines {
|
||||
if line.starts_with("mnt-by:") {
|
||||
let line = line.strip_prefix("mnt-by:").unwrap().trim();
|
||||
entry = Self::get_by_mnt(&mut ret, line);
|
||||
} else if line.starts_with("cidr:") {
|
||||
let line = line.strip_prefix("cidr:").unwrap().trim();
|
||||
ip = Some(line);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ip) = ip {
|
||||
let (ip, len) = ip.split_once('/').unwrap();
|
||||
let ipv4 = Ipv4Inet::new(ip.parse()?, len.parse()?)?;
|
||||
if let Some(entry) = entry {
|
||||
if let Some(vec) = entry.ipv4.as_mut() {
|
||||
vec.push(ipv4);
|
||||
} else {
|
||||
entry.ipv4 = Some(vec![ipv4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let inet6num = std::fs::read_dir(format!("{}/{INET6NUM}", self.path))?;
|
||||
for inet6num in inet6num {
|
||||
let content = std::fs::read_to_string(inet6num?.path())?;
|
||||
let lines = content.lines().rev();
|
||||
|
||||
let mut entry = None;
|
||||
let mut ip = None;
|
||||
|
||||
for line in lines {
|
||||
if line.starts_with("mnt-by:") {
|
||||
let line = line.strip_prefix("mnt-by:").unwrap().trim();
|
||||
entry = Self::get_by_mnt(&mut ret, line);
|
||||
} else if line.starts_with("cidr:") {
|
||||
let line = line.strip_prefix("cidr:").unwrap().trim();
|
||||
ip = Some(line);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ip) = ip {
|
||||
let (ip, len) = ip.split_once('/').unwrap();
|
||||
let ipv6 = Ipv6Inet::new(ip.parse()?, len.parse()?)?;
|
||||
if let Some(entry) = entry {
|
||||
if let Some(vec) = entry.ipv6.as_mut() {
|
||||
vec.push(ipv6);
|
||||
} else {
|
||||
entry.ipv6 = Some(vec![ipv6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
// Mmmm, O(len)
|
||||
pub fn get_by_mnt<'a>(vec: &'a mut Vec<Entry>, mnt: &'a str) -> Option<&'a mut Entry> {
|
||||
let mut ret = None;
|
||||
for entry in vec {
|
||||
if entry.mnt == mnt {
|
||||
ret = Some(entry);
|
||||
}
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn get_by_asn(vec: &Vec<Entry>, asn: u32) -> Option<String> {
|
||||
for entry in vec {
|
||||
if entry.asn == asn {
|
||||
return Some(entry.asn_req(asn));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
// O(len + len)
|
||||
pub fn get_by_ipv4(vec: &Vec<Entry>, addr: Ipv4Addr) -> Option<String> {
|
||||
for entry in vec {
|
||||
if let Some(ipv4) = &entry.ipv4 {
|
||||
for ip in ipv4 {
|
||||
if ip.contains(&addr) {
|
||||
return entry.ipv4_req(*ip, addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_by_ipv6(vec: &Vec<Entry>, addr: &Ipv6Addr) -> Option<String> {
|
||||
for entry in vec {
|
||||
if let Some(ipv6) = &entry.ipv6 {
|
||||
for ip in ipv6 {
|
||||
if ip.contains(addr) {
|
||||
return entry.ipv6_req(*ip, addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Entry {
|
||||
pub asn: u32,
|
||||
pub mnt: String,
|
||||
pub ipv4: Option<Vec<Ipv4Inet>>,
|
||||
pub ipv6: Option<Vec<Ipv6Inet>>,
|
||||
}
|
||||
|
||||
impl Entry {
|
||||
pub fn ipv4_req(&self, ipv4: Ipv4Inet, addr: Ipv4Addr) -> Option<String> {
|
||||
let asn_subnets = self.ipv4.as_ref()?;
|
||||
let mut subnet = None;
|
||||
for prefix in asn_subnets {
|
||||
if prefix.contains(&ipv4.address()) {
|
||||
subnet = Some(prefix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let subnet = subnet?;
|
||||
let mut builder = String::new();
|
||||
builder.push_str(&format!("{} | ", self.asn));
|
||||
builder.push_str(&format!("{} | ", addr.to_string()));
|
||||
builder.push_str(&format!("{} | ", subnet.to_string()));
|
||||
builder.push_str(&format!("{}", self.mnt));
|
||||
|
||||
Some(builder)
|
||||
}
|
||||
|
||||
pub fn ipv6_req(&self, ipv6: Ipv6Inet, addr: &Ipv6Addr) -> Option<String> {
|
||||
let asn_subnets = self.ipv6.as_ref()?;
|
||||
let mut subnet = None;
|
||||
for prefix in asn_subnets {
|
||||
if prefix.contains(&ipv6.address()) {
|
||||
subnet = Some(prefix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let subnet = subnet?;
|
||||
let mut builder = String::new();
|
||||
builder.push_str(&format!("{} | ", self.asn));
|
||||
builder.push_str(&format!("{} | ", addr.to_string()));
|
||||
builder.push_str(&format!("{} | ", subnet.network().to_string()));
|
||||
builder.push_str(&format!("{}", self.mnt));
|
||||
|
||||
Some(builder)
|
||||
}
|
||||
|
||||
pub fn asn_req(&self, asn: u32) -> String {
|
||||
let mut builder = String::new();
|
||||
builder.push_str(&format!("{asn} "));
|
||||
if let Some(ipv4_subnet) = &self.ipv4 {
|
||||
for prefix in ipv4_subnet {
|
||||
builder.push_str(&format!("| {} ", prefix.network().to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ipv6_subnet) = &self.ipv6 {
|
||||
for prefix in ipv6_subnet {
|
||||
builder.push_str(&format!("| {} ", prefix.network().to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
builder.push_str(&format!("| {}", self.mnt));
|
||||
builder
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue