diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-10-14 15:37:07 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-10-14 15:37:07 +0200 |
commit | 633e18bb64769b68f71475f6fd69c568c868c759 (patch) | |
tree | 83e4a90b82d98284cb2337790f8abef5c558b200 | |
parent | bd4936d99b58fcf1c18153e6e0f8ff7bbad9fecb (diff) |
refactor to signal based ipc
-rw-r--r-- | Cargo.lock | 498 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/error.rs | 8 | ||||
-rw-r--r-- | src/main.rs | 105 |
4 files changed, 141 insertions, 474 deletions
@@ -27,12 +27,6 @@ dependencies = [ ] [[package]] -name = "anyhow" -version = "1.0.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" - -[[package]] name = "async-trait" version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -100,12 +94,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] name = "bytes" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -147,13 +135,33 @@ dependencies = [ ] [[package]] -name = "crossbeam-channel" -version = "0.5.8" +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" dependencies = [ + "autocfg", "cfg-if", "crossbeam-utils", + "memoffset", + "scopeguard", ] [[package]] @@ -190,18 +198,6 @@ dependencies = [ ] [[package]] -name = "filetime" -version = "0.2.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "windows-sys 0.48.0", -] - -[[package]] name = "form_urlencoded" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -211,37 +207,12 @@ dependencies = [ ] [[package]] -name = "fsevent-sys" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" -dependencies = [ - "libc", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] name = "futures-channel" version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -251,40 +222,12 @@ 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-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.28", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] name = "futures-task" version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -296,13 +239,8 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", - "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", "slab", @@ -376,26 +314,6 @@ dependencies = [ ] [[package]] -name = "inotify" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" -dependencies = [ - "bitflags 1.3.2", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" -dependencies = [ - "libc", -] - -[[package]] name = "ipconfig" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -403,7 +321,7 @@ checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" dependencies = [ "socket2", "widestring", - "windows-sys 0.48.0", + "windows-sys", "winreg", ] @@ -420,26 +338,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] -name = "kqueue" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" -dependencies = [ - "kqueue-sys", - "libc", -] - -[[package]] -name = "kqueue-sys" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" -dependencies = [ - "bitflags 1.3.2", - "libc", -] - -[[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -517,6 +415,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + +[[package]] name = "minimal-lexical" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -538,86 +445,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", - "log", "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "netlink-packet-core" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72724faf704479d67b388da142b186f916188505e7e0b26719019c525882eda4" -dependencies = [ - "anyhow", - "byteorder", - "netlink-packet-utils", -] - -[[package]] -name = "netlink-packet-route" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6de2fe935f44cbdfcab77dce2150d68eda75be715cd42d4d6f52b0bd4dcc5b1" -dependencies = [ - "anyhow", - "bitflags 1.3.2", - "byteorder", - "libc", - "netlink-packet-core", - "netlink-packet-utils", -] - -[[package]] -name = "netlink-packet-utils" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" -dependencies = [ - "anyhow", - "byteorder", - "paste", - "thiserror", -] - -[[package]] -name = "netlink-proto" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "842c6770fc4bb33dd902f41829c61ef872b8e38de1405aa0b938b27b8fba12c3" -dependencies = [ - "bytes", - "futures", - "log", - "netlink-packet-core", - "netlink-sys", - "thiserror", - "tokio", -] - -[[package]] -name = "netlink-sys" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6471bf08e7ac0135876a9581bf3217ef0333c191c128d34878079f42ee150411" -dependencies = [ - "bytes", - "futures", - "libc", - "log", - "tokio", -] - -[[package]] -name = "nix" -version = "0.26.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "libc", - "static_assertions", + "windows-sys", ] [[package]] @@ -631,39 +460,12 @@ dependencies = [ ] [[package]] -name = "notify" -version = "5.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729f63e1ca555a43fe3efa4f3efdf4801c479da85b432242a7b726f353c88486" -dependencies = [ - "bitflags 1.3.2", - "crossbeam-channel", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "mio", - "walkdir", - "windows-sys 0.45.0", -] - -[[package]] -name = "notify" -version = "6.0.1" +name = "ntapi" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5738a2795d57ea20abec2d6d76c6081186709c0024187cd5977265eda6598b51" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" dependencies = [ - "bitflags 1.3.2", - "crossbeam-channel", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "mio", - "walkdir", - "windows-sys 0.45.0", + "winapi", ] [[package]] @@ -711,16 +513,10 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.1", + "windows-targets", ] [[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - -[[package]] name = "peeking_take_while" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -815,6 +611,26 @@ dependencies = [ ] [[package]] +name = "rayon" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] name = "redox_syscall" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -867,12 +683,12 @@ name = "rsdsl_dslite" version = "0.1.0" dependencies = [ "ipnet", - "notify 6.0.1", "rsdsl_ip_config", - "rsdsl_netlinkd", "rsdsl_netlinkd_sys", "rsdsl_pd_config", "serde_json", + "signal-hook", + "sysinfo", "thiserror", "trust-dns-resolver", ] @@ -886,24 +702,6 @@ dependencies = [ ] [[package]] -name = "rsdsl_netlinkd" -version = "0.6.2" -source = "git+https://github.com/rsdsl/netlinkd.git#861a1f2897f2147c969b1d6222bb86eeb4d55c53" -dependencies = [ - "futures", - "futures-util", - "ipnet", - "netlink-packet-route", - "notify 5.2.0", - "rsdsl_ip_config", - "rsdsl_pd_config", - "rtnetlink", - "serde_json", - "thiserror", - "tokio", -] - -[[package]] name = "rsdsl_netlinkd_sys" version = "0.4.11" source = "git+https://github.com/rsdsl/netlinkd.git#861a1f2897f2147c969b1d6222bb86eeb4d55c53" @@ -922,24 +720,6 @@ dependencies = [ ] [[package]] -name = "rtnetlink" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a552eb82d19f38c3beed3f786bd23aa434ceb9ac43ab44419ca6d67a7e186c0" -dependencies = [ - "futures", - "log", - "netlink-packet-core", - "netlink-packet-route", - "netlink-packet-utils", - "netlink-proto", - "netlink-sys", - "nix", - "thiserror", - "tokio", -] - -[[package]] name = "rustc-demangle" version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -958,15 +738,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1010,6 +781,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] name = "slab" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1031,16 +821,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1063,6 +847,21 @@ dependencies = [ ] [[package]] +name = "sysinfo" +version = "0.29.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a18d114d420ada3a891e6bc8e96a2023402203296a47cdd65083377dad18ba5" +dependencies = [ + "cfg-if", + "core-foundation-sys", + "libc", + "ntapi", + "once_cell", + "rayon", + "winapi", +] + +[[package]] name = "thiserror" version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1110,7 +909,7 @@ dependencies = [ "num_cpus", "pin-project-lite", "socket2", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1223,16 +1022,6 @@ dependencies = [ ] [[package]] -name = "walkdir" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" -dependencies = [ - "same-file", - "winapi-util", -] - -[[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1272,15 +1061,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1288,35 +1068,11 @@ 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.1", -] - -[[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", + "windows-targets", ] [[package]] @@ -1325,95 +1081,53 @@ version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" 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", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[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" @@ -1425,5 +1139,5 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ "cfg-if", - "windows-sys 0.48.0", + "windows-sys", ] @@ -7,11 +7,11 @@ edition = "2021" [dependencies] ipnet = "2.8.0" -notify = "6.0.1" rsdsl_ip_config = { git = "https://github.com/rsdsl/ip_config.git", version = "0.2.2" } -rsdsl_netlinkd = { git = "https://github.com/rsdsl/netlinkd.git", version = "0.6.2" } rsdsl_netlinkd_sys = { git = "https://github.com/rsdsl/netlinkd.git", version = "0.4.11" } rsdsl_pd_config = { git = "https://github.com/rsdsl/pd_config.git", version = "0.1.0" } serde_json = "1.0" +signal-hook = "0.3.17" +sysinfo = "0.29.10" thiserror = "1.0" trust-dns-resolver = "0.22.0" diff --git a/src/error.rs b/src/error.rs index 03145e1..0bbc367 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,20 +4,16 @@ use thiserror::Error; #[derive(Debug, Error)] pub enum Error { - #[error("not enough ipv6 subnets")] - NotEnoughIpv6Subnets, #[error("no address associated with aftr name")] NoDnsRecord, + #[error("not enough ipv6 subnets")] + NotEnoughIpv6Subnets, #[error("io: {0}")] Io(#[from] io::Error), #[error("ipnet prefix len: {0}")] IpnetPrefixLen(#[from] ipnet::PrefixLenError), - #[error("notify: {0}")] - Notify(#[from] notify::Error), - #[error("rsdsl_netlinkd: {0}")] - RsdslNetlinkd(#[from] rsdsl_netlinkd::error::Error), #[error("rsdsl_netlinkd_sys: {0}")] RsdslNetlinkdSys(#[from] rsdsl_netlinkd_sys::Error), #[error("serde_json: {0}")] diff --git a/src/main.rs b/src/main.rs index 2c10c66..ba4fd21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,98 +1,52 @@ +use rsdsl_dslite::{Error, Result}; + use std::fs::File; -use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr}; -use std::path::Path; +use std::net::{Ipv6Addr, SocketAddr}; use std::thread; use std::time::Duration; use ipnet::Ipv6Net; -use notify::event::{CreateKind, ModifyKind}; -use notify::{Event, EventKind, RecursiveMode, Watcher}; -use rsdsl_dslite::{Error, Result}; -use rsdsl_ip_config::DsConfig; -use rsdsl_netlinkd::{addr, link, route}; use rsdsl_netlinkd_sys::IpIp6; use rsdsl_pd_config::PdConfig; +use signal_hook::{consts::SIGUSR1, iterator::Signals}; +use sysinfo::{ProcessExt, Signal, System, SystemExt}; use trust_dns_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts}; use trust_dns_resolver::Resolver; -const ADDR4_AFTR: Ipv4Addr = Ipv4Addr::new(192, 0, 0, 1); -const ADDR4_B4: Ipv4Addr = Ipv4Addr::new(192, 0, 0, 2); - const MAX_ATTEMPTS: usize = 3; +const BACKOFF: u64 = 900; fn main() -> Result<()> { - println!("wait for up ppp0"); - link::wait_up("ppp0".into())?; - - let pd_config = Path::new(rsdsl_pd_config::LOCATION); - - println!("wait for dhcp6"); - while !pd_config.exists() { - thread::sleep(Duration::from_secs(8)); - } + println!("[info] init"); let mut tnl = None; - let do_setup = |tnl: &mut Option<IpIp6>| -> Result<()> { - *tnl = None; - - let mut file = File::open(rsdsl_pd_config::LOCATION)?; - let pdconfig: PdConfig = serde_json::from_reader(&mut file)?; - - if let Some(ref aftr) = pdconfig.aftr { - let local = local_address(&pdconfig)?; - let remote = multitry_resolve6(&pdconfig, aftr)?; - *tnl = Some(IpIp6::new("dslite0", "ppp0", local, remote)?); - - configure_dslite(); - } else { - println!("no aftr"); - } - - Ok(()) - }; - let setup = move |tnl: &mut Option<IpIp6>| match do_setup(tnl) { - Ok(_) => {} - Err(e) => println!("can't create dslite0: {}", e), - }; - - setup(&mut tnl); - - let mut watcher = notify::recommended_watcher(move |res: notify::Result<Event>| match res { - Ok(event) => match event.kind { - EventKind::Create(kind) if kind == CreateKind::File => setup(&mut tnl), - EventKind::Modify(kind) if matches!(kind, ModifyKind::Data(_)) => setup(&mut tnl), - _ => {} - }, - Err(e) => println!("watch error: {:?}", e), - })?; - - watcher.watch(pd_config, RecursiveMode::NonRecursive)?; - - loop { - thread::sleep(Duration::MAX); + let mut signals = Signals::new([SIGUSR1])?; + for _ in signals.forever() { + logic(&mut tnl)?; } -} -fn configure_dslite() { - match configure_dslite0() { - Ok(_) => println!("configure dslite0"), - Err(e) => println!("can't configure dslite0: {}", e), - } + unreachable!() } -fn configure_dslite0() -> Result<()> { - link::up("dslite0".into())?; +fn logic(tnl: &mut Option<IpIp6>) -> Result<()> { + *tnl = None; // Delete old tunnel. - addr::flush("dslite0".into())?; - addr::add("dslite0".into(), ADDR4_B4.into(), 29)?; + let mut file = File::open(rsdsl_pd_config::LOCATION)?; + let pdconfig: PdConfig = serde_json::from_reader(&mut file)?; - let mut file = File::open(rsdsl_ip_config::LOCATION)?; - let dsconfig: DsConfig = serde_json::from_reader(&mut file)?; + if let Some(ref aftr) = pdconfig.aftr { + let local = local_address(&pdconfig)?; + let remote = multitry_resolve6(&pdconfig, aftr)?; + *tnl = Some(IpIp6::new("dslite0", "ppp0", local, remote)?); + + for netlinkd in System::default().processes_by_exact_name("/bin/rsdsl_netlinkd") { + netlinkd.kill_with(Signal::User1); + } - // Check for native connectivity to avoid breaking netlinkd. - if dsconfig.v4.is_none() { - route::add4(Ipv4Addr::UNSPECIFIED, 0, Some(ADDR4_AFTR), "dslite0".into())?; + println!("[info] init ds-lite tunnel {} <=> {}", local, remote); + } else { + println!("[info] no aftr"); } Ok(()) @@ -137,12 +91,15 @@ fn multitry_resolve6(pdconfig: &PdConfig, fqdn: &str) -> Result<Ipv6Addr> { if i >= MAX_ATTEMPTS - 1 { return Err(e); } else { - println!("{}", e) + println!( + "[warn] resolve aftr {}: {} (attempt {}/{})", + fqdn, e, i, MAX_ATTEMPTS + ) } } } - thread::sleep(Duration::from_secs(8)); + thread::sleep(Duration::from_secs(BACKOFF)); } unreachable!() |