From 56ac8740b79e291eabe6427d722921533b3a9837 Mon Sep 17 00:00:00 2001 From: diogo464 Date: Sun, 15 Feb 2026 22:05:57 +0000 Subject: updated dependencies --- Cargo.lock | 735 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 12 +- src/key.rs | 3 +- src/lib.rs | 97 +++++--- src/setup.rs | 108 ++++++--- src/view.rs | 59 ++--- 6 files changed, 909 insertions(+), 105 deletions(-) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6203091 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,735 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anyhow" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "futures" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-executor" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "genetlink" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d8935531e8e0919b17043c668cc18bfac1622f2fab73125f4f018124ee330b8" +dependencies = [ + "futures", + "log", + "netlink-packet-core", + "netlink-packet-generic", + "netlink-proto", + "thiserror 1.0.69", + "tokio", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" +dependencies = [ + "serde", +] + +[[package]] +name = "libc" +version = "0.2.182" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "netlink-packet-core" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3463cbb78394cb0141e2c926b93fc2197e473394b761986eca3b9da2c63ae0f4" +dependencies = [ + "paste", +] + +[[package]] +name = "netlink-packet-generic" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f891b2e0054cac5a684a06628f59568f841c93da4e551239da6e518f539e775" +dependencies = [ + "netlink-packet-core", +] + +[[package]] +name = "netlink-packet-route" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ce3636fa715e988114552619582b530481fd5ef176a1e5c1bf024077c2c9445" +dependencies = [ + "bitflags", + "libc", + "log", + "netlink-packet-core", +] + +[[package]] +name = "netlink-packet-wireguard" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037892b0e01ce41f30398a47be2051e712a2cf1eed9cb7e5e6a92b05c423255b" +dependencies = [ + "libc", + "log", + "netlink-packet-core", + "netlink-packet-generic", +] + +[[package]] +name = "netlink-proto" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b65d130ee111430e47eed7896ea43ca693c387f097dd97376bffafbf25812128" +dependencies = [ + "bytes", + "futures", + "log", + "netlink-packet-core", + "netlink-sys", + "thiserror 2.0.18", +] + +[[package]] +name = "netlink-sys" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6c30ed10fa69cc491d491b85cc971f6bdeb8e7367b7cde2ee6cc878d583fae" +dependencies = [ + "bytes", + "futures-util", + "libc", + "log", + "tokio", +] + +[[package]] +name = "nix" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[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 = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rtnetlink" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b960d5d873a75b5be9761b1e73b146f52dddcd27bac75263f40fba686d4d7b5" +dependencies = [ + "futures-channel", + "futures-util", + "log", + "netlink-packet-core", + "netlink-packet-route", + "netlink-proto", + "netlink-sys", + "nix", + "thiserror 1.0.69", + "tokio", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "syn" +version = "2.0.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio" +version = "1.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "unicode-ident" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "wireguard" +version = "0.0.0" +dependencies = [ + "anyhow", + "base64", + "futures", + "genetlink", + "ipnet", + "netlink-packet-core", + "netlink-packet-generic", + "netlink-packet-route", + "netlink-packet-wireguard", + "rand", + "rtnetlink", + "serde", + "tokio", + "tracing", +] + +[[package]] +name = "zerocopy" +version = "0.8.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index b2c8f54..e7ffd1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,14 +9,14 @@ edition = "2021" anyhow = "1.0.79" base64 = "0.21.7" futures = "0.3.30" -genetlink = "0.2.5" +genetlink = "=0.2.6" ipnet = { version = "2.9.0", features = ["serde"] } -netlink-packet-core = "=0.7.0" -netlink-packet-generic = "=0.3.3" -netlink-packet-route = "=0.18.1" -netlink-packet-wireguard = "=0.2.3" +netlink-packet-core = "=0.8.1" +netlink-packet-generic = "=0.4.0" +netlink-packet-route = "=0.28.0" +netlink-packet-wireguard = "=0.3.0" rand = "0.8.5" -rtnetlink = "=0.14.0" +rtnetlink = "=0.20.0" serde = "1.0.195" tokio = { version = "1.35.1", features = ["full"] } tracing = "0.1.40" diff --git a/src/key.rs b/src/key.rs index 19bc127..49f9284 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,7 +1,8 @@ use base64::Engine; -use netlink_packet_wireguard::constants::WG_KEY_LEN; use rand::{rngs::OsRng, RngCore}; +const WG_KEY_LEN: usize = netlink_packet_wireguard::WireguardAttribute::WG_KEY_LEN; + // Code from: https://git.zx2c4.com/wireguard-tools/tree/contrib/embeddable-wg-library/wireguard.c type Fe = [i64; 16]; diff --git a/src/lib.rs b/src/lib.rs index c47d618..8ba36eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,18 +3,18 @@ mod key; mod setup; mod view; -use std::borrow::Cow; +use std::{ + borrow::Cow, + net::{Ipv4Addr, Ipv6Addr}, +}; use futures::{StreamExt, TryStreamExt}; use genetlink::{GenetlinkError, GenetlinkHandle}; use netlink_packet_core::{NetlinkMessage, NetlinkPayload, NLM_F_ACK, NLM_F_DUMP, NLM_F_REQUEST}; use netlink_packet_generic::GenlMessage; -use netlink_packet_route::{ - link::{InfoKind, LinkAttribute, LinkInfo}, - route::RouteScope, -}; -use netlink_packet_wireguard::{nlas::WgDeviceAttrs, Wireguard, WireguardCmd}; -use rtnetlink::Handle; +use netlink_packet_route::{link::LinkAttribute, route::RouteScope}; +use netlink_packet_wireguard::{WireguardAttribute, WireguardCmd, WireguardMessage}; +use rtnetlink::{Handle, LinkMessageBuilder, LinkSetRequest, LinkWireguard, RouteMessageBuilder}; pub use conf::*; pub use key::*; @@ -149,9 +149,9 @@ impl WireGuard { } pub async fn view_device(&mut self, device_name: &str) -> Result { - let genlmsg: GenlMessage = GenlMessage::from_payload(Wireguard { + let genlmsg: GenlMessage = GenlMessage::from_payload(WireguardMessage { cmd: WireguardCmd::GetDevice, - nlas: vec![WgDeviceAttrs::IfName(device_name.to_string())], + attributes: vec![WireguardAttribute::IfName(device_name.to_string())], }); let mut nlmsg = NetlinkMessage::from(genlmsg); nlmsg.header.flags = NLM_F_REQUEST | NLM_F_DUMP; @@ -213,7 +213,7 @@ impl WireGuard { } let message = descriptor.into_wireguard(device_name.to_string()); - let genlmsg: GenlMessage = GenlMessage::from_payload(message); + let genlmsg: GenlMessage = GenlMessage::from_payload(message); let mut nlmsg = NetlinkMessage::from(genlmsg); nlmsg.header.flags = NLM_F_REQUEST | NLM_F_ACK; @@ -225,16 +225,12 @@ impl WireGuard { } async fn link_create(&self, name: &str) -> Result<()> { - let mut msg = self.rt_handle.link().add().replace(); - msg.message_mut() - .attributes - .push(LinkAttribute::LinkInfo(vec![LinkInfo::Kind( - InfoKind::Wireguard, - )])); - msg.message_mut() - .attributes - .push(LinkAttribute::IfName(name.to_string())); - msg.execute().await?; + self.rt_handle + .link() + .add(LinkMessageBuilder::::new(name).build()) + .replace() + .execute() + .await?; Ok(()) } @@ -245,13 +241,31 @@ impl WireGuard { async fn link_up(&self, ifindex: u32) -> Result<()> { tracing::trace!("Bringing up interface {}", ifindex); - self.rt_handle.link().set(ifindex).up().execute().await?; + self.rt_handle + .link() + .set( + LinkMessageBuilder::::default() + .index(ifindex) + .up() + .build(), + ) + .execute() + .await?; Ok(()) } async fn link_down(&self, ifindex: u32) -> Result<()> { tracing::trace!("Bringing down interface {}", ifindex); - self.rt_handle.link().set(ifindex).down().execute().await?; + self.rt_handle + .link() + .set( + LinkMessageBuilder::::default() + .index(ifindex) + .down() + .build(), + ) + .execute() + .await?; Ok(()) } @@ -314,30 +328,37 @@ impl WireGuard { #[allow(unused)] async fn route_add(&self, ifindex: u32, net: ipnet::IpNet) -> Result<()> { tracing::trace!("Adding route {} to {}", net, ifindex); - let request = self - .rt_handle - .route() - .add() - .scope(RouteScope::Link) - .output_interface(ifindex) - .replace(); match net.addr() { std::net::IpAddr::V4(ip) => { - request - .v4() - .destination_prefix(ip, net.prefix_len()) + self.rt_handle + .route() + .add( + RouteMessageBuilder::::default() + .scope(RouteScope::Link) + .output_interface(ifindex) + .destination_prefix(ip, net.prefix_len()) + .build(), + ) + .replace() .execute() - .await + .await?; } std::net::IpAddr::V6(ip) => { - request - .v6() - .destination_prefix(ip, net.prefix_len()) + self.rt_handle + .route() + .add( + RouteMessageBuilder::::default() + .scope(RouteScope::Link) + .output_interface(ifindex) + .destination_prefix(ip, net.prefix_len()) + .build(), + ) + .replace() .execute() - .await + .await?; } - }?; + }; Ok(()) } diff --git a/src/setup.rs b/src/setup.rs index e7d454c..c36772f 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -2,13 +2,46 @@ use std::net::{IpAddr, SocketAddr}; use ipnet::IpNet; use netlink_packet_wireguard::{ - constants::{AF_INET, AF_INET6, WGDEVICE_F_REPLACE_PEERS, WGPEER_F_REPLACE_ALLOWEDIPS}, - nlas::{WgAllowedIp, WgAllowedIpAttrs, WgDeviceAttrs, WgPeer, WgPeerAttrs}, - Wireguard, WireguardCmd, + WireguardAddressFamily, WireguardAllowedIp, WireguardAllowedIpAttr, WireguardAttribute, + WireguardCmd, WireguardMessage, WireguardPeer, WireguardPeerAttribute, }; use super::Key; +#[allow(unused)] +mod constants { + // this is copy pasted from the netlink_packet_wireguard's constants module because for some reason + // they stopped exposing constants in commit 3067a394fc7bc28fadbed5359c44cce95aac0f13 + pub const WGDEVICE_F_REPLACE_PEERS: u32 = 1 << 0; + + pub const WGPEER_F_REMOVE_ME: u32 = 1 << 0; + pub const WGPEER_F_REPLACE_ALLOWEDIPS: u32 = 1 << 1; + pub const WGPEER_F_UPDATE_ONLY: u32 = 1 << 2; + + pub const WGPEER_A_UNSPEC: u16 = 0; + pub const WGPEER_A_PUBLIC_KEY: u16 = 1; + pub const WGPEER_A_PRESHARED_KEY: u16 = 2; + pub const WGPEER_A_FLAGS: u16 = 3; + pub const WGPEER_A_ENDPOINT: u16 = 4; + pub const WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL: u16 = 5; + pub const WGPEER_A_LAST_HANDSHAKE_TIME: u16 = 6; + pub const WGPEER_A_RX_BYTES: u16 = 7; + pub const WGPEER_A_TX_BYTES: u16 = 8; + pub const WGPEER_A_ALLOWEDIPS: u16 = 9; + pub const WGPEER_A_PROTOCOL_VERSION: u16 = 10; + + pub const WGALLOWEDIP_A_UNSPEC: u16 = 0; + pub const WGALLOWEDIP_A_FAMILY: u16 = 1; + pub const WGALLOWEDIP_A_IPADDR: u16 = 2; + pub const WGALLOWEDIP_A_CIDR_MASK: u16 = 3; + + pub const AF_INET6: u16 = 10; + pub const AF_INET: u16 = 2; +} + +#[allow(unused)] +pub(crate) use constants::*; + #[derive(Debug)] pub struct PeerDescriptor { pub(super) public_key: Key, @@ -87,20 +120,25 @@ impl PeerDescriptor { self } - pub(super) fn into_wireguard(self) -> WgPeer { - let mut nlas = Vec::new(); - nlas.push(WgPeerAttrs::PublicKey(self.public_key.into_array())); - nlas.extend( + pub(super) fn into_wireguard(self) -> WireguardPeer { + let mut attributes = Vec::new(); + attributes.push(WireguardPeerAttribute::PublicKey( + self.public_key.into_array(), + )); + attributes.extend( self.preshared_key - .map(|key| WgPeerAttrs::PresharedKey(key.into_array())), + .map(|key| WireguardPeerAttribute::PresharedKey(key.into_array())), ); - nlas.extend(self.endpoint.map(WgPeerAttrs::Endpoint)); - nlas.extend(self.keepalive.map(WgPeerAttrs::PersistentKeepalive)); - nlas.extend(self.allowed_ips.map(|allowed_ips| { - WgPeerAttrs::AllowedIps(allowed_ips.into_iter().map(ipnet_to_wg).collect()) + attributes.extend(self.endpoint.map(WireguardPeerAttribute::Endpoint)); + attributes.extend( + self.keepalive + .map(WireguardPeerAttribute::PersistentKeepalive), + ); + attributes.extend(self.allowed_ips.map(|allowed_ips| { + WireguardPeerAttribute::AllowedIps(allowed_ips.into_iter().map(ipnet_to_wg).collect()) })); - nlas.push(WgPeerAttrs::Flags(WGPEER_F_REPLACE_ALLOWEDIPS)); - WgPeer(nlas) + attributes.push(WireguardPeerAttribute::Flags(WGPEER_F_REPLACE_ALLOWEDIPS)); + WireguardPeer(attributes) } } @@ -174,39 +212,43 @@ impl DeviceDescriptor { self } - pub(super) fn into_wireguard(self, device_name: String) -> Wireguard { - let mut nlas = Vec::new(); - nlas.push(WgDeviceAttrs::IfName(device_name)); - nlas.extend( + pub(super) fn into_wireguard(self, device_name: String) -> WireguardMessage { + let mut attributes = Vec::new(); + attributes.push(WireguardAttribute::IfName(device_name)); + attributes.extend( self.private_key - .map(|key| WgDeviceAttrs::PrivateKey(key.into_array())), + .map(|key| WireguardAttribute::PrivateKey(key.into_array())), ); - nlas.extend(self.listen_port.map(WgDeviceAttrs::ListenPort)); - nlas.extend(self.fwmark.map(WgDeviceAttrs::Fwmark)); - nlas.extend(self.peers.map(|peers| { - WgDeviceAttrs::Peers( + attributes.extend(self.listen_port.map(WireguardAttribute::ListenPort)); + attributes.extend(self.fwmark.map(WireguardAttribute::Fwmark)); + attributes.extend(self.peers.map(|peers| { + WireguardAttribute::Peers( peers .into_iter() .map(PeerDescriptor::into_wireguard) .collect(), ) })); - nlas.push(WgDeviceAttrs::Flags(WGDEVICE_F_REPLACE_PEERS)); + attributes.push(WireguardAttribute::Flags(WGDEVICE_F_REPLACE_PEERS)); - Wireguard { + WireguardMessage { cmd: WireguardCmd::SetDevice, - nlas, + attributes, } } } -fn ipnet_to_wg(net: IpNet) -> WgAllowedIp { - let mut nlas = Vec::default(); - nlas.push(WgAllowedIpAttrs::Cidr(net.prefix_len())); - nlas.push(WgAllowedIpAttrs::IpAddr(net.addr())); +fn ipnet_to_wg(net: IpNet) -> WireguardAllowedIp { + let mut attributes = Vec::default(); + attributes.push(WireguardAllowedIpAttr::Cidr(net.prefix_len())); + attributes.push(WireguardAllowedIpAttr::IpAddr(net.addr())); match net.addr() { - IpAddr::V4(_) => nlas.push(WgAllowedIpAttrs::Family(AF_INET)), - IpAddr::V6(_) => nlas.push(WgAllowedIpAttrs::Family(AF_INET6)), + IpAddr::V4(_) => { + attributes.push(WireguardAllowedIpAttr::Family(WireguardAddressFamily::Ipv4)) + } + IpAddr::V6(_) => { + attributes.push(WireguardAllowedIpAttr::Family(WireguardAddressFamily::Ipv6)) + } } - WgAllowedIp(nlas) + WireguardAllowedIp(attributes) } diff --git a/src/view.rs b/src/view.rs index 2858811..69f718a 100644 --- a/src/view.rs +++ b/src/view.rs @@ -1,9 +1,12 @@ -use std::{net::SocketAddr, time::SystemTime}; +use std::{ + net::SocketAddr, + time::{Duration, SystemTime}, +}; use ipnet::IpNet; use netlink_packet_wireguard::{ - nlas::{WgAllowedIp, WgAllowedIpAttrs, WgDeviceAttrs, WgPeer, WgPeerAttrs}, - Wireguard, + WireguardAllowedIp, WireguardAllowedIpAttr, WireguardAttribute, WireguardMessage, + WireguardPeer, WireguardPeerAttribute, }; use super::{Error, Key, Result}; @@ -31,7 +34,7 @@ pub struct PeerView { pub allowed_ips: Vec, } -pub(super) fn device_view_from_payload(wg: Wireguard) -> Result { +pub(super) fn device_view_from_payload(wg: WireguardMessage) -> Result { let mut if_index = None; let mut if_name = None; let mut private_key = None; @@ -40,15 +43,15 @@ pub(super) fn device_view_from_payload(wg: Wireguard) -> Result { let mut fwmark = None; let mut peers = None; - for nla in wg.nlas { - match nla { - WgDeviceAttrs::IfIndex(v) => if_index = Some(v), - WgDeviceAttrs::IfName(v) => if_name = Some(v), - WgDeviceAttrs::PrivateKey(v) => private_key = Some(Key::from(v)), - WgDeviceAttrs::PublicKey(v) => public_key = Some(Key::from(v)), - WgDeviceAttrs::ListenPort(v) => listen_port = Some(v), - WgDeviceAttrs::Fwmark(v) => fwmark = Some(v), - WgDeviceAttrs::Peers(v) => peers = Some(peers_from_wg_peers(v)?), + for attr in wg.attributes { + match attr { + WireguardAttribute::IfIndex(v) => if_index = Some(v), + WireguardAttribute::IfName(v) => if_name = Some(v), + WireguardAttribute::PrivateKey(v) => private_key = Some(Key::from(v)), + WireguardAttribute::PublicKey(v) => public_key = Some(Key::from(v)), + WireguardAttribute::ListenPort(v) => listen_port = Some(v), + WireguardAttribute::Fwmark(v) => fwmark = Some(v), + WireguardAttribute::Peers(v) => peers = Some(peers_from_wg_peers(v)?), _ => {} } } @@ -64,7 +67,7 @@ pub(super) fn device_view_from_payload(wg: Wireguard) -> Result { }) } -fn peers_from_wg_peers(wg_peers: Vec) -> Result> { +fn peers_from_wg_peers(wg_peers: Vec) -> Result> { let mut peers = Vec::with_capacity(wg_peers.len()); for wg_peer in wg_peers { peers.push(peer_from_wg_peer(wg_peer)?); @@ -72,7 +75,7 @@ fn peers_from_wg_peers(wg_peers: Vec) -> Result> { Ok(peers) } -fn peer_from_wg_peer(wg_peer: WgPeer) -> Result { +fn peer_from_wg_peer(wg_peer: WireguardPeer) -> Result { let mut public_key = None; let mut preshared_key = None; let mut endpoint = None; @@ -84,14 +87,14 @@ fn peer_from_wg_peer(wg_peer: WgPeer) -> Result { for attr in wg_peer.iter() { match attr { - WgPeerAttrs::PublicKey(v) => public_key = Some(Key::from(v)), - WgPeerAttrs::PresharedKey(v) => preshared_key = Some(Key::from(v)), - WgPeerAttrs::Endpoint(v) => endpoint = Some(*v), - WgPeerAttrs::PersistentKeepalive(v) => persistent_keepalive = Some(*v), - WgPeerAttrs::LastHandshake(v) => last_handshake = Some(*v), - WgPeerAttrs::RxBytes(v) => rx_bytes = Some(*v), - WgPeerAttrs::TxBytes(v) => tx_bytes = Some(*v), - WgPeerAttrs::AllowedIps(v) => { + WireguardPeerAttribute::PublicKey(v) => public_key = Some(Key::from(v)), + WireguardPeerAttribute::PresharedKey(v) => preshared_key = Some(Key::from(v)), + WireguardPeerAttribute::Endpoint(v) => endpoint = Some(*v), + WireguardPeerAttribute::PersistentKeepalive(v) => persistent_keepalive = Some(*v), + WireguardPeerAttribute::LastHandshake(v) => last_handshake = Some(*v), + WireguardPeerAttribute::RxBytes(v) => rx_bytes = Some(*v), + WireguardPeerAttribute::TxBytes(v) => tx_bytes = Some(*v), + WireguardPeerAttribute::AllowedIps(v) => { for ip in v { allowed_ips.push(ipnet_from_wg(ip)?); } @@ -105,20 +108,22 @@ fn peer_from_wg_peer(wg_peer: WgPeer) -> Result { preshared_key, endpoint, persistent_keepalive, - last_handshake: last_handshake.ok_or_else(|| Error::message("missing last_handshake"))?, + last_handshake: last_handshake + .map(|ts| SystemTime::now() - Duration::new(ts.seconds as u64, ts.nano_seconds as u32)) + .ok_or_else(|| Error::message("missing last_handshake"))?, rx_bytes: rx_bytes.ok_or_else(|| Error::message("missing rx_bytes"))?, tx_bytes: tx_bytes.ok_or_else(|| Error::message("missing tx_bytes"))?, allowed_ips, }) } -fn ipnet_from_wg(wg: &WgAllowedIp) -> Result { +fn ipnet_from_wg(wg: &WireguardAllowedIp) -> Result { let mut ip = None; let mut prefix = None; for attr in wg.iter() { match attr { - WgAllowedIpAttrs::IpAddr(v) => ip = Some(*v), - WgAllowedIpAttrs::Cidr(v) => prefix = Some(*v), + WireguardAllowedIpAttr::IpAddr(v) => ip = Some(*v), + WireguardAllowedIpAttr::Cidr(v) => prefix = Some(*v), _ => {} } } -- cgit