diff options
| author | diogo464 <[email protected]> | 2026-02-15 22:05:57 +0000 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2026-02-15 22:05:57 +0000 |
| commit | 56ac8740b79e291eabe6427d722921533b3a9837 (patch) | |
| tree | c244662e382263efec95d6ac445cfc9f987e4758 | |
| parent | 75ccbd675c22fb3275c5763518c3b97819db4c53 (diff) | |
updated dependencies
| -rw-r--r-- | Cargo.lock | 735 | ||||
| -rw-r--r-- | Cargo.toml | 12 | ||||
| -rw-r--r-- | src/key.rs | 3 | ||||
| -rw-r--r-- | src/lib.rs | 97 | ||||
| -rw-r--r-- | src/setup.rs | 108 | ||||
| -rw-r--r-- | src/view.rs | 59 |
6 files changed, 909 insertions, 105 deletions
diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6203091 --- /dev/null +++ b/Cargo.lock | |||
| @@ -0,0 +1,735 @@ | |||
| 1 | # This file is automatically @generated by Cargo. | ||
| 2 | # It is not intended for manual editing. | ||
| 3 | version = 4 | ||
| 4 | |||
| 5 | [[package]] | ||
| 6 | name = "anyhow" | ||
| 7 | version = "1.0.101" | ||
| 8 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 9 | checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" | ||
| 10 | |||
| 11 | [[package]] | ||
| 12 | name = "base64" | ||
| 13 | version = "0.21.7" | ||
| 14 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 15 | checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" | ||
| 16 | |||
| 17 | [[package]] | ||
| 18 | name = "bitflags" | ||
| 19 | version = "2.11.0" | ||
| 20 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 21 | checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" | ||
| 22 | |||
| 23 | [[package]] | ||
| 24 | name = "bytes" | ||
| 25 | version = "1.11.1" | ||
| 26 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 27 | checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" | ||
| 28 | |||
| 29 | [[package]] | ||
| 30 | name = "cfg-if" | ||
| 31 | version = "1.0.4" | ||
| 32 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 33 | checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" | ||
| 34 | |||
| 35 | [[package]] | ||
| 36 | name = "cfg_aliases" | ||
| 37 | version = "0.2.1" | ||
| 38 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 39 | checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" | ||
| 40 | |||
| 41 | [[package]] | ||
| 42 | name = "errno" | ||
| 43 | version = "0.3.14" | ||
| 44 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 45 | checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" | ||
| 46 | dependencies = [ | ||
| 47 | "libc", | ||
| 48 | "windows-sys 0.61.2", | ||
| 49 | ] | ||
| 50 | |||
| 51 | [[package]] | ||
| 52 | name = "futures" | ||
| 53 | version = "0.3.32" | ||
| 54 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 55 | checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" | ||
| 56 | dependencies = [ | ||
| 57 | "futures-channel", | ||
| 58 | "futures-core", | ||
| 59 | "futures-executor", | ||
| 60 | "futures-io", | ||
| 61 | "futures-sink", | ||
| 62 | "futures-task", | ||
| 63 | "futures-util", | ||
| 64 | ] | ||
| 65 | |||
| 66 | [[package]] | ||
| 67 | name = "futures-channel" | ||
| 68 | version = "0.3.32" | ||
| 69 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 70 | checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" | ||
| 71 | dependencies = [ | ||
| 72 | "futures-core", | ||
| 73 | "futures-sink", | ||
| 74 | ] | ||
| 75 | |||
| 76 | [[package]] | ||
| 77 | name = "futures-core" | ||
| 78 | version = "0.3.32" | ||
| 79 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 80 | checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" | ||
| 81 | |||
| 82 | [[package]] | ||
| 83 | name = "futures-executor" | ||
| 84 | version = "0.3.32" | ||
| 85 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 86 | checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" | ||
| 87 | dependencies = [ | ||
| 88 | "futures-core", | ||
| 89 | "futures-task", | ||
| 90 | "futures-util", | ||
| 91 | ] | ||
| 92 | |||
| 93 | [[package]] | ||
| 94 | name = "futures-io" | ||
| 95 | version = "0.3.32" | ||
| 96 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 97 | checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" | ||
| 98 | |||
| 99 | [[package]] | ||
| 100 | name = "futures-macro" | ||
| 101 | version = "0.3.32" | ||
| 102 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 103 | checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" | ||
| 104 | dependencies = [ | ||
| 105 | "proc-macro2", | ||
| 106 | "quote", | ||
| 107 | "syn", | ||
| 108 | ] | ||
| 109 | |||
| 110 | [[package]] | ||
| 111 | name = "futures-sink" | ||
| 112 | version = "0.3.32" | ||
| 113 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 114 | checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" | ||
| 115 | |||
| 116 | [[package]] | ||
| 117 | name = "futures-task" | ||
| 118 | version = "0.3.32" | ||
| 119 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 120 | checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" | ||
| 121 | |||
| 122 | [[package]] | ||
| 123 | name = "futures-util" | ||
| 124 | version = "0.3.32" | ||
| 125 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 126 | checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" | ||
| 127 | dependencies = [ | ||
| 128 | "futures-channel", | ||
| 129 | "futures-core", | ||
| 130 | "futures-io", | ||
| 131 | "futures-macro", | ||
| 132 | "futures-sink", | ||
| 133 | "futures-task", | ||
| 134 | "memchr", | ||
| 135 | "pin-project-lite", | ||
| 136 | "slab", | ||
| 137 | ] | ||
| 138 | |||
| 139 | [[package]] | ||
| 140 | name = "genetlink" | ||
| 141 | version = "0.2.6" | ||
| 142 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 143 | checksum = "4d8935531e8e0919b17043c668cc18bfac1622f2fab73125f4f018124ee330b8" | ||
| 144 | dependencies = [ | ||
| 145 | "futures", | ||
| 146 | "log", | ||
| 147 | "netlink-packet-core", | ||
| 148 | "netlink-packet-generic", | ||
| 149 | "netlink-proto", | ||
| 150 | "thiserror 1.0.69", | ||
| 151 | "tokio", | ||
| 152 | ] | ||
| 153 | |||
| 154 | [[package]] | ||
| 155 | name = "getrandom" | ||
| 156 | version = "0.2.17" | ||
| 157 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 158 | checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" | ||
| 159 | dependencies = [ | ||
| 160 | "cfg-if", | ||
| 161 | "libc", | ||
| 162 | "wasi", | ||
| 163 | ] | ||
| 164 | |||
| 165 | [[package]] | ||
| 166 | name = "ipnet" | ||
| 167 | version = "2.11.0" | ||
| 168 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 169 | checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" | ||
| 170 | dependencies = [ | ||
| 171 | "serde", | ||
| 172 | ] | ||
| 173 | |||
| 174 | [[package]] | ||
| 175 | name = "libc" | ||
| 176 | version = "0.2.182" | ||
| 177 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 178 | checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" | ||
| 179 | |||
| 180 | [[package]] | ||
| 181 | name = "lock_api" | ||
| 182 | version = "0.4.14" | ||
| 183 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 184 | checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" | ||
| 185 | dependencies = [ | ||
| 186 | "scopeguard", | ||
| 187 | ] | ||
| 188 | |||
| 189 | [[package]] | ||
| 190 | name = "log" | ||
| 191 | version = "0.4.29" | ||
| 192 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 193 | checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" | ||
| 194 | |||
| 195 | [[package]] | ||
| 196 | name = "memchr" | ||
| 197 | version = "2.8.0" | ||
| 198 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 199 | checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" | ||
| 200 | |||
| 201 | [[package]] | ||
| 202 | name = "mio" | ||
| 203 | version = "1.1.1" | ||
| 204 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 205 | checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" | ||
| 206 | dependencies = [ | ||
| 207 | "libc", | ||
| 208 | "wasi", | ||
| 209 | "windows-sys 0.61.2", | ||
| 210 | ] | ||
| 211 | |||
| 212 | [[package]] | ||
| 213 | name = "netlink-packet-core" | ||
| 214 | version = "0.8.1" | ||
| 215 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 216 | checksum = "3463cbb78394cb0141e2c926b93fc2197e473394b761986eca3b9da2c63ae0f4" | ||
| 217 | dependencies = [ | ||
| 218 | "paste", | ||
| 219 | ] | ||
| 220 | |||
| 221 | [[package]] | ||
| 222 | name = "netlink-packet-generic" | ||
| 223 | version = "0.4.0" | ||
| 224 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 225 | checksum = "2f891b2e0054cac5a684a06628f59568f841c93da4e551239da6e518f539e775" | ||
| 226 | dependencies = [ | ||
| 227 | "netlink-packet-core", | ||
| 228 | ] | ||
| 229 | |||
| 230 | [[package]] | ||
| 231 | name = "netlink-packet-route" | ||
| 232 | version = "0.28.0" | ||
| 233 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 234 | checksum = "4ce3636fa715e988114552619582b530481fd5ef176a1e5c1bf024077c2c9445" | ||
| 235 | dependencies = [ | ||
| 236 | "bitflags", | ||
| 237 | "libc", | ||
| 238 | "log", | ||
| 239 | "netlink-packet-core", | ||
| 240 | ] | ||
| 241 | |||
| 242 | [[package]] | ||
| 243 | name = "netlink-packet-wireguard" | ||
| 244 | version = "0.3.0" | ||
| 245 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 246 | checksum = "037892b0e01ce41f30398a47be2051e712a2cf1eed9cb7e5e6a92b05c423255b" | ||
| 247 | dependencies = [ | ||
| 248 | "libc", | ||
| 249 | "log", | ||
| 250 | "netlink-packet-core", | ||
| 251 | "netlink-packet-generic", | ||
| 252 | ] | ||
| 253 | |||
| 254 | [[package]] | ||
| 255 | name = "netlink-proto" | ||
| 256 | version = "0.12.0" | ||
| 257 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 258 | checksum = "b65d130ee111430e47eed7896ea43ca693c387f097dd97376bffafbf25812128" | ||
| 259 | dependencies = [ | ||
| 260 | "bytes", | ||
| 261 | "futures", | ||
| 262 | "log", | ||
| 263 | "netlink-packet-core", | ||
| 264 | "netlink-sys", | ||
| 265 | "thiserror 2.0.18", | ||
| 266 | ] | ||
| 267 | |||
| 268 | [[package]] | ||
| 269 | name = "netlink-sys" | ||
| 270 | version = "0.8.8" | ||
| 271 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 272 | checksum = "cd6c30ed10fa69cc491d491b85cc971f6bdeb8e7367b7cde2ee6cc878d583fae" | ||
| 273 | dependencies = [ | ||
| 274 | "bytes", | ||
| 275 | "futures-util", | ||
| 276 | "libc", | ||
| 277 | "log", | ||
| 278 | "tokio", | ||
| 279 | ] | ||
| 280 | |||
| 281 | [[package]] | ||
| 282 | name = "nix" | ||
| 283 | version = "0.30.1" | ||
| 284 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 285 | checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" | ||
| 286 | dependencies = [ | ||
| 287 | "bitflags", | ||
| 288 | "cfg-if", | ||
| 289 | "cfg_aliases", | ||
| 290 | "libc", | ||
| 291 | ] | ||
| 292 | |||
| 293 | [[package]] | ||
| 294 | name = "once_cell" | ||
| 295 | version = "1.21.3" | ||
| 296 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 297 | checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" | ||
| 298 | |||
| 299 | [[package]] | ||
| 300 | name = "parking_lot" | ||
| 301 | version = "0.12.5" | ||
| 302 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 303 | checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" | ||
| 304 | dependencies = [ | ||
| 305 | "lock_api", | ||
| 306 | "parking_lot_core", | ||
| 307 | ] | ||
| 308 | |||
| 309 | [[package]] | ||
| 310 | name = "parking_lot_core" | ||
| 311 | version = "0.9.12" | ||
| 312 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 313 | checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" | ||
| 314 | dependencies = [ | ||
| 315 | "cfg-if", | ||
| 316 | "libc", | ||
| 317 | "redox_syscall", | ||
| 318 | "smallvec", | ||
| 319 | "windows-link", | ||
| 320 | ] | ||
| 321 | |||
| 322 | [[package]] | ||
| 323 | name = "paste" | ||
| 324 | version = "1.0.15" | ||
| 325 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 326 | checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" | ||
| 327 | |||
| 328 | [[package]] | ||
| 329 | name = "pin-project-lite" | ||
| 330 | version = "0.2.16" | ||
| 331 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 332 | checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" | ||
| 333 | |||
| 334 | [[package]] | ||
| 335 | name = "ppv-lite86" | ||
| 336 | version = "0.2.21" | ||
| 337 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 338 | checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" | ||
| 339 | dependencies = [ | ||
| 340 | "zerocopy", | ||
| 341 | ] | ||
| 342 | |||
| 343 | [[package]] | ||
| 344 | name = "proc-macro2" | ||
| 345 | version = "1.0.106" | ||
| 346 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 347 | checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" | ||
| 348 | dependencies = [ | ||
| 349 | "unicode-ident", | ||
| 350 | ] | ||
| 351 | |||
| 352 | [[package]] | ||
| 353 | name = "quote" | ||
| 354 | version = "1.0.44" | ||
| 355 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 356 | checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" | ||
| 357 | dependencies = [ | ||
| 358 | "proc-macro2", | ||
| 359 | ] | ||
| 360 | |||
| 361 | [[package]] | ||
| 362 | name = "rand" | ||
| 363 | version = "0.8.5" | ||
| 364 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 365 | checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" | ||
| 366 | dependencies = [ | ||
| 367 | "libc", | ||
| 368 | "rand_chacha", | ||
| 369 | "rand_core", | ||
| 370 | ] | ||
| 371 | |||
| 372 | [[package]] | ||
| 373 | name = "rand_chacha" | ||
| 374 | version = "0.3.1" | ||
| 375 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 376 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" | ||
| 377 | dependencies = [ | ||
| 378 | "ppv-lite86", | ||
| 379 | "rand_core", | ||
| 380 | ] | ||
| 381 | |||
| 382 | [[package]] | ||
| 383 | name = "rand_core" | ||
| 384 | version = "0.6.4" | ||
| 385 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 386 | checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" | ||
| 387 | dependencies = [ | ||
| 388 | "getrandom", | ||
| 389 | ] | ||
| 390 | |||
| 391 | [[package]] | ||
| 392 | name = "redox_syscall" | ||
| 393 | version = "0.5.18" | ||
| 394 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 395 | checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" | ||
| 396 | dependencies = [ | ||
| 397 | "bitflags", | ||
| 398 | ] | ||
| 399 | |||
| 400 | [[package]] | ||
| 401 | name = "rtnetlink" | ||
| 402 | version = "0.20.0" | ||
| 403 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 404 | checksum = "4b960d5d873a75b5be9761b1e73b146f52dddcd27bac75263f40fba686d4d7b5" | ||
| 405 | dependencies = [ | ||
| 406 | "futures-channel", | ||
| 407 | "futures-util", | ||
| 408 | "log", | ||
| 409 | "netlink-packet-core", | ||
| 410 | "netlink-packet-route", | ||
| 411 | "netlink-proto", | ||
| 412 | "netlink-sys", | ||
| 413 | "nix", | ||
| 414 | "thiserror 1.0.69", | ||
| 415 | "tokio", | ||
| 416 | ] | ||
| 417 | |||
| 418 | [[package]] | ||
| 419 | name = "scopeguard" | ||
| 420 | version = "1.2.0" | ||
| 421 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 422 | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" | ||
| 423 | |||
| 424 | [[package]] | ||
| 425 | name = "serde" | ||
| 426 | version = "1.0.228" | ||
| 427 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 428 | checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" | ||
| 429 | dependencies = [ | ||
| 430 | "serde_core", | ||
| 431 | "serde_derive", | ||
| 432 | ] | ||
| 433 | |||
| 434 | [[package]] | ||
| 435 | name = "serde_core" | ||
| 436 | version = "1.0.228" | ||
| 437 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 438 | checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" | ||
| 439 | dependencies = [ | ||
| 440 | "serde_derive", | ||
| 441 | ] | ||
| 442 | |||
| 443 | [[package]] | ||
| 444 | name = "serde_derive" | ||
| 445 | version = "1.0.228" | ||
| 446 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 447 | checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" | ||
| 448 | dependencies = [ | ||
| 449 | "proc-macro2", | ||
| 450 | "quote", | ||
| 451 | "syn", | ||
| 452 | ] | ||
| 453 | |||
| 454 | [[package]] | ||
| 455 | name = "signal-hook-registry" | ||
| 456 | version = "1.4.8" | ||
| 457 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 458 | checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" | ||
| 459 | dependencies = [ | ||
| 460 | "errno", | ||
| 461 | "libc", | ||
| 462 | ] | ||
| 463 | |||
| 464 | [[package]] | ||
| 465 | name = "slab" | ||
| 466 | version = "0.4.12" | ||
| 467 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 468 | checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" | ||
| 469 | |||
| 470 | [[package]] | ||
| 471 | name = "smallvec" | ||
| 472 | version = "1.15.1" | ||
| 473 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 474 | checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" | ||
| 475 | |||
| 476 | [[package]] | ||
| 477 | name = "socket2" | ||
| 478 | version = "0.6.2" | ||
| 479 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 480 | checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" | ||
| 481 | dependencies = [ | ||
| 482 | "libc", | ||
| 483 | "windows-sys 0.60.2", | ||
| 484 | ] | ||
| 485 | |||
| 486 | [[package]] | ||
| 487 | name = "syn" | ||
| 488 | version = "2.0.116" | ||
| 489 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 490 | checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb" | ||
| 491 | dependencies = [ | ||
| 492 | "proc-macro2", | ||
| 493 | "quote", | ||
| 494 | "unicode-ident", | ||
| 495 | ] | ||
| 496 | |||
| 497 | [[package]] | ||
| 498 | name = "thiserror" | ||
| 499 | version = "1.0.69" | ||
| 500 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 501 | checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" | ||
| 502 | dependencies = [ | ||
| 503 | "thiserror-impl 1.0.69", | ||
| 504 | ] | ||
| 505 | |||
| 506 | [[package]] | ||
| 507 | name = "thiserror" | ||
| 508 | version = "2.0.18" | ||
| 509 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 510 | checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" | ||
| 511 | dependencies = [ | ||
| 512 | "thiserror-impl 2.0.18", | ||
| 513 | ] | ||
| 514 | |||
| 515 | [[package]] | ||
| 516 | name = "thiserror-impl" | ||
| 517 | version = "1.0.69" | ||
| 518 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 519 | checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" | ||
| 520 | dependencies = [ | ||
| 521 | "proc-macro2", | ||
| 522 | "quote", | ||
| 523 | "syn", | ||
| 524 | ] | ||
| 525 | |||
| 526 | [[package]] | ||
| 527 | name = "thiserror-impl" | ||
| 528 | version = "2.0.18" | ||
| 529 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 530 | checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" | ||
| 531 | dependencies = [ | ||
| 532 | "proc-macro2", | ||
| 533 | "quote", | ||
| 534 | "syn", | ||
| 535 | ] | ||
| 536 | |||
| 537 | [[package]] | ||
| 538 | name = "tokio" | ||
| 539 | version = "1.49.0" | ||
| 540 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 541 | checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" | ||
| 542 | dependencies = [ | ||
| 543 | "bytes", | ||
| 544 | "libc", | ||
| 545 | "mio", | ||
| 546 | "parking_lot", | ||
| 547 | "pin-project-lite", | ||
| 548 | "signal-hook-registry", | ||
| 549 | "socket2", | ||
| 550 | "tokio-macros", | ||
| 551 | "windows-sys 0.61.2", | ||
| 552 | ] | ||
| 553 | |||
| 554 | [[package]] | ||
| 555 | name = "tokio-macros" | ||
| 556 | version = "2.6.0" | ||
| 557 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 558 | checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" | ||
| 559 | dependencies = [ | ||
| 560 | "proc-macro2", | ||
| 561 | "quote", | ||
| 562 | "syn", | ||
| 563 | ] | ||
| 564 | |||
| 565 | [[package]] | ||
| 566 | name = "tracing" | ||
| 567 | version = "0.1.44" | ||
| 568 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 569 | checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" | ||
| 570 | dependencies = [ | ||
| 571 | "pin-project-lite", | ||
| 572 | "tracing-attributes", | ||
| 573 | "tracing-core", | ||
| 574 | ] | ||
| 575 | |||
| 576 | [[package]] | ||
| 577 | name = "tracing-attributes" | ||
| 578 | version = "0.1.31" | ||
| 579 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 580 | checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" | ||
| 581 | dependencies = [ | ||
| 582 | "proc-macro2", | ||
| 583 | "quote", | ||
| 584 | "syn", | ||
| 585 | ] | ||
| 586 | |||
| 587 | [[package]] | ||
| 588 | name = "tracing-core" | ||
| 589 | version = "0.1.36" | ||
| 590 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 591 | checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" | ||
| 592 | dependencies = [ | ||
| 593 | "once_cell", | ||
| 594 | ] | ||
| 595 | |||
| 596 | [[package]] | ||
| 597 | name = "unicode-ident" | ||
| 598 | version = "1.0.23" | ||
| 599 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 600 | checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e" | ||
| 601 | |||
| 602 | [[package]] | ||
| 603 | name = "wasi" | ||
| 604 | version = "0.11.1+wasi-snapshot-preview1" | ||
| 605 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 606 | checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" | ||
| 607 | |||
| 608 | [[package]] | ||
| 609 | name = "windows-link" | ||
| 610 | version = "0.2.1" | ||
| 611 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 612 | checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" | ||
| 613 | |||
| 614 | [[package]] | ||
| 615 | name = "windows-sys" | ||
| 616 | version = "0.60.2" | ||
| 617 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 618 | checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" | ||
| 619 | dependencies = [ | ||
| 620 | "windows-targets", | ||
| 621 | ] | ||
| 622 | |||
| 623 | [[package]] | ||
| 624 | name = "windows-sys" | ||
| 625 | version = "0.61.2" | ||
| 626 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 627 | checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" | ||
| 628 | dependencies = [ | ||
| 629 | "windows-link", | ||
| 630 | ] | ||
| 631 | |||
| 632 | [[package]] | ||
| 633 | name = "windows-targets" | ||
| 634 | version = "0.53.5" | ||
| 635 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 636 | checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" | ||
| 637 | dependencies = [ | ||
| 638 | "windows-link", | ||
| 639 | "windows_aarch64_gnullvm", | ||
| 640 | "windows_aarch64_msvc", | ||
| 641 | "windows_i686_gnu", | ||
| 642 | "windows_i686_gnullvm", | ||
| 643 | "windows_i686_msvc", | ||
| 644 | "windows_x86_64_gnu", | ||
| 645 | "windows_x86_64_gnullvm", | ||
| 646 | "windows_x86_64_msvc", | ||
| 647 | ] | ||
| 648 | |||
| 649 | [[package]] | ||
| 650 | name = "windows_aarch64_gnullvm" | ||
| 651 | version = "0.53.1" | ||
| 652 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 653 | checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" | ||
| 654 | |||
| 655 | [[package]] | ||
| 656 | name = "windows_aarch64_msvc" | ||
| 657 | version = "0.53.1" | ||
| 658 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 659 | checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" | ||
| 660 | |||
| 661 | [[package]] | ||
| 662 | name = "windows_i686_gnu" | ||
| 663 | version = "0.53.1" | ||
| 664 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 665 | checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" | ||
| 666 | |||
| 667 | [[package]] | ||
| 668 | name = "windows_i686_gnullvm" | ||
| 669 | version = "0.53.1" | ||
| 670 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 671 | checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" | ||
| 672 | |||
| 673 | [[package]] | ||
| 674 | name = "windows_i686_msvc" | ||
| 675 | version = "0.53.1" | ||
| 676 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 677 | checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" | ||
| 678 | |||
| 679 | [[package]] | ||
| 680 | name = "windows_x86_64_gnu" | ||
| 681 | version = "0.53.1" | ||
| 682 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 683 | checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" | ||
| 684 | |||
| 685 | [[package]] | ||
| 686 | name = "windows_x86_64_gnullvm" | ||
| 687 | version = "0.53.1" | ||
| 688 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 689 | checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" | ||
| 690 | |||
| 691 | [[package]] | ||
| 692 | name = "windows_x86_64_msvc" | ||
| 693 | version = "0.53.1" | ||
| 694 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 695 | checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" | ||
| 696 | |||
| 697 | [[package]] | ||
| 698 | name = "wireguard" | ||
| 699 | version = "0.0.0" | ||
| 700 | dependencies = [ | ||
| 701 | "anyhow", | ||
| 702 | "base64", | ||
| 703 | "futures", | ||
| 704 | "genetlink", | ||
| 705 | "ipnet", | ||
| 706 | "netlink-packet-core", | ||
| 707 | "netlink-packet-generic", | ||
| 708 | "netlink-packet-route", | ||
| 709 | "netlink-packet-wireguard", | ||
| 710 | "rand", | ||
| 711 | "rtnetlink", | ||
| 712 | "serde", | ||
| 713 | "tokio", | ||
| 714 | "tracing", | ||
| 715 | ] | ||
| 716 | |||
| 717 | [[package]] | ||
| 718 | name = "zerocopy" | ||
| 719 | version = "0.8.39" | ||
| 720 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 721 | checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" | ||
| 722 | dependencies = [ | ||
| 723 | "zerocopy-derive", | ||
| 724 | ] | ||
| 725 | |||
| 726 | [[package]] | ||
| 727 | name = "zerocopy-derive" | ||
| 728 | version = "0.8.39" | ||
| 729 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 730 | checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" | ||
| 731 | dependencies = [ | ||
| 732 | "proc-macro2", | ||
| 733 | "quote", | ||
| 734 | "syn", | ||
| 735 | ] | ||
| @@ -9,14 +9,14 @@ edition = "2021" | |||
| 9 | anyhow = "1.0.79" | 9 | anyhow = "1.0.79" |
| 10 | base64 = "0.21.7" | 10 | base64 = "0.21.7" |
| 11 | futures = "0.3.30" | 11 | futures = "0.3.30" |
| 12 | genetlink = "0.2.5" | 12 | genetlink = "=0.2.6" |
| 13 | ipnet = { version = "2.9.0", features = ["serde"] } | 13 | ipnet = { version = "2.9.0", features = ["serde"] } |
| 14 | netlink-packet-core = "=0.7.0" | 14 | netlink-packet-core = "=0.8.1" |
| 15 | netlink-packet-generic = "=0.3.3" | 15 | netlink-packet-generic = "=0.4.0" |
| 16 | netlink-packet-route = "=0.18.1" | 16 | netlink-packet-route = "=0.28.0" |
| 17 | netlink-packet-wireguard = "=0.2.3" | 17 | netlink-packet-wireguard = "=0.3.0" |
| 18 | rand = "0.8.5" | 18 | rand = "0.8.5" |
| 19 | rtnetlink = "=0.14.0" | 19 | rtnetlink = "=0.20.0" |
| 20 | serde = "1.0.195" | 20 | serde = "1.0.195" |
| 21 | tokio = { version = "1.35.1", features = ["full"] } | 21 | tokio = { version = "1.35.1", features = ["full"] } |
| 22 | tracing = "0.1.40" | 22 | tracing = "0.1.40" |
| @@ -1,7 +1,8 @@ | |||
| 1 | use base64::Engine; | 1 | use base64::Engine; |
| 2 | use netlink_packet_wireguard::constants::WG_KEY_LEN; | ||
| 3 | use rand::{rngs::OsRng, RngCore}; | 2 | use rand::{rngs::OsRng, RngCore}; |
| 4 | 3 | ||
| 4 | const WG_KEY_LEN: usize = netlink_packet_wireguard::WireguardAttribute::WG_KEY_LEN; | ||
| 5 | |||
| 5 | // Code from: https://git.zx2c4.com/wireguard-tools/tree/contrib/embeddable-wg-library/wireguard.c | 6 | // Code from: https://git.zx2c4.com/wireguard-tools/tree/contrib/embeddable-wg-library/wireguard.c |
| 6 | 7 | ||
| 7 | type Fe = [i64; 16]; | 8 | type Fe = [i64; 16]; |
| @@ -3,18 +3,18 @@ mod key; | |||
| 3 | mod setup; | 3 | mod setup; |
| 4 | mod view; | 4 | mod view; |
| 5 | 5 | ||
| 6 | use std::borrow::Cow; | 6 | use std::{ |
| 7 | borrow::Cow, | ||
| 8 | net::{Ipv4Addr, Ipv6Addr}, | ||
| 9 | }; | ||
| 7 | 10 | ||
| 8 | use futures::{StreamExt, TryStreamExt}; | 11 | use futures::{StreamExt, TryStreamExt}; |
| 9 | use genetlink::{GenetlinkError, GenetlinkHandle}; | 12 | use genetlink::{GenetlinkError, GenetlinkHandle}; |
| 10 | use netlink_packet_core::{NetlinkMessage, NetlinkPayload, NLM_F_ACK, NLM_F_DUMP, NLM_F_REQUEST}; | 13 | use netlink_packet_core::{NetlinkMessage, NetlinkPayload, NLM_F_ACK, NLM_F_DUMP, NLM_F_REQUEST}; |
| 11 | use netlink_packet_generic::GenlMessage; | 14 | use netlink_packet_generic::GenlMessage; |
| 12 | use netlink_packet_route::{ | 15 | use netlink_packet_route::{link::LinkAttribute, route::RouteScope}; |
| 13 | link::{InfoKind, LinkAttribute, LinkInfo}, | 16 | use netlink_packet_wireguard::{WireguardAttribute, WireguardCmd, WireguardMessage}; |
| 14 | route::RouteScope, | 17 | use rtnetlink::{Handle, LinkMessageBuilder, LinkSetRequest, LinkWireguard, RouteMessageBuilder}; |
| 15 | }; | ||
| 16 | use netlink_packet_wireguard::{nlas::WgDeviceAttrs, Wireguard, WireguardCmd}; | ||
| 17 | use rtnetlink::Handle; | ||
| 18 | 18 | ||
| 19 | pub use conf::*; | 19 | pub use conf::*; |
| 20 | pub use key::*; | 20 | pub use key::*; |
| @@ -149,9 +149,9 @@ impl WireGuard { | |||
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | pub async fn view_device(&mut self, device_name: &str) -> Result<DeviceView> { | 151 | pub async fn view_device(&mut self, device_name: &str) -> Result<DeviceView> { |
| 152 | let genlmsg: GenlMessage<Wireguard> = GenlMessage::from_payload(Wireguard { | 152 | let genlmsg: GenlMessage<WireguardMessage> = GenlMessage::from_payload(WireguardMessage { |
| 153 | cmd: WireguardCmd::GetDevice, | 153 | cmd: WireguardCmd::GetDevice, |
| 154 | nlas: vec![WgDeviceAttrs::IfName(device_name.to_string())], | 154 | attributes: vec![WireguardAttribute::IfName(device_name.to_string())], |
| 155 | }); | 155 | }); |
| 156 | let mut nlmsg = NetlinkMessage::from(genlmsg); | 156 | let mut nlmsg = NetlinkMessage::from(genlmsg); |
| 157 | nlmsg.header.flags = NLM_F_REQUEST | NLM_F_DUMP; | 157 | nlmsg.header.flags = NLM_F_REQUEST | NLM_F_DUMP; |
| @@ -213,7 +213,7 @@ impl WireGuard { | |||
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | let message = descriptor.into_wireguard(device_name.to_string()); | 215 | let message = descriptor.into_wireguard(device_name.to_string()); |
| 216 | let genlmsg: GenlMessage<Wireguard> = GenlMessage::from_payload(message); | 216 | let genlmsg: GenlMessage<WireguardMessage> = GenlMessage::from_payload(message); |
| 217 | let mut nlmsg = NetlinkMessage::from(genlmsg); | 217 | let mut nlmsg = NetlinkMessage::from(genlmsg); |
| 218 | nlmsg.header.flags = NLM_F_REQUEST | NLM_F_ACK; | 218 | nlmsg.header.flags = NLM_F_REQUEST | NLM_F_ACK; |
| 219 | 219 | ||
| @@ -225,16 +225,12 @@ impl WireGuard { | |||
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | async fn link_create(&self, name: &str) -> Result<()> { | 227 | async fn link_create(&self, name: &str) -> Result<()> { |
| 228 | let mut msg = self.rt_handle.link().add().replace(); | 228 | self.rt_handle |
| 229 | msg.message_mut() | 229 | .link() |
| 230 | .attributes | 230 | .add(LinkMessageBuilder::<LinkWireguard>::new(name).build()) |
| 231 | .push(LinkAttribute::LinkInfo(vec![LinkInfo::Kind( | 231 | .replace() |
| 232 | InfoKind::Wireguard, | 232 | .execute() |
| 233 | )])); | 233 | .await?; |
| 234 | msg.message_mut() | ||
| 235 | .attributes | ||
| 236 | .push(LinkAttribute::IfName(name.to_string())); | ||
| 237 | msg.execute().await?; | ||
| 238 | Ok(()) | 234 | Ok(()) |
| 239 | } | 235 | } |
| 240 | 236 | ||
| @@ -245,13 +241,31 @@ impl WireGuard { | |||
| 245 | 241 | ||
| 246 | async fn link_up(&self, ifindex: u32) -> Result<()> { | 242 | async fn link_up(&self, ifindex: u32) -> Result<()> { |
| 247 | tracing::trace!("Bringing up interface {}", ifindex); | 243 | tracing::trace!("Bringing up interface {}", ifindex); |
| 248 | self.rt_handle.link().set(ifindex).up().execute().await?; | 244 | self.rt_handle |
| 245 | .link() | ||
| 246 | .set( | ||
| 247 | LinkMessageBuilder::<LinkSetRequest>::default() | ||
| 248 | .index(ifindex) | ||
| 249 | .up() | ||
| 250 | .build(), | ||
| 251 | ) | ||
| 252 | .execute() | ||
| 253 | .await?; | ||
| 249 | Ok(()) | 254 | Ok(()) |
| 250 | } | 255 | } |
| 251 | 256 | ||
| 252 | async fn link_down(&self, ifindex: u32) -> Result<()> { | 257 | async fn link_down(&self, ifindex: u32) -> Result<()> { |
| 253 | tracing::trace!("Bringing down interface {}", ifindex); | 258 | tracing::trace!("Bringing down interface {}", ifindex); |
| 254 | self.rt_handle.link().set(ifindex).down().execute().await?; | 259 | self.rt_handle |
| 260 | .link() | ||
| 261 | .set( | ||
| 262 | LinkMessageBuilder::<LinkSetRequest>::default() | ||
| 263 | .index(ifindex) | ||
| 264 | .down() | ||
| 265 | .build(), | ||
| 266 | ) | ||
| 267 | .execute() | ||
| 268 | .await?; | ||
| 255 | Ok(()) | 269 | Ok(()) |
| 256 | } | 270 | } |
| 257 | 271 | ||
| @@ -314,30 +328,37 @@ impl WireGuard { | |||
| 314 | #[allow(unused)] | 328 | #[allow(unused)] |
| 315 | async fn route_add(&self, ifindex: u32, net: ipnet::IpNet) -> Result<()> { | 329 | async fn route_add(&self, ifindex: u32, net: ipnet::IpNet) -> Result<()> { |
| 316 | tracing::trace!("Adding route {} to {}", net, ifindex); | 330 | tracing::trace!("Adding route {} to {}", net, ifindex); |
| 317 | let request = self | ||
| 318 | .rt_handle | ||
| 319 | .route() | ||
| 320 | .add() | ||
| 321 | .scope(RouteScope::Link) | ||
| 322 | .output_interface(ifindex) | ||
| 323 | .replace(); | ||
| 324 | 331 | ||
| 325 | match net.addr() { | 332 | match net.addr() { |
| 326 | std::net::IpAddr::V4(ip) => { | 333 | std::net::IpAddr::V4(ip) => { |
| 327 | request | 334 | self.rt_handle |
| 328 | .v4() | 335 | .route() |
| 329 | .destination_prefix(ip, net.prefix_len()) | 336 | .add( |
| 337 | RouteMessageBuilder::<Ipv4Addr>::default() | ||
| 338 | .scope(RouteScope::Link) | ||
| 339 | .output_interface(ifindex) | ||
| 340 | .destination_prefix(ip, net.prefix_len()) | ||
| 341 | .build(), | ||
| 342 | ) | ||
| 343 | .replace() | ||
| 330 | .execute() | 344 | .execute() |
| 331 | .await | 345 | .await?; |
| 332 | } | 346 | } |
| 333 | std::net::IpAddr::V6(ip) => { | 347 | std::net::IpAddr::V6(ip) => { |
| 334 | request | 348 | self.rt_handle |
| 335 | .v6() | 349 | .route() |
| 336 | .destination_prefix(ip, net.prefix_len()) | 350 | .add( |
| 351 | RouteMessageBuilder::<Ipv6Addr>::default() | ||
| 352 | .scope(RouteScope::Link) | ||
| 353 | .output_interface(ifindex) | ||
| 354 | .destination_prefix(ip, net.prefix_len()) | ||
| 355 | .build(), | ||
| 356 | ) | ||
| 357 | .replace() | ||
| 337 | .execute() | 358 | .execute() |
| 338 | .await | 359 | .await?; |
| 339 | } | 360 | } |
| 340 | }?; | 361 | }; |
| 341 | 362 | ||
| 342 | Ok(()) | 363 | Ok(()) |
| 343 | } | 364 | } |
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}; | |||
| 2 | 2 | ||
| 3 | use ipnet::IpNet; | 3 | use ipnet::IpNet; |
| 4 | use netlink_packet_wireguard::{ | 4 | use netlink_packet_wireguard::{ |
| 5 | constants::{AF_INET, AF_INET6, WGDEVICE_F_REPLACE_PEERS, WGPEER_F_REPLACE_ALLOWEDIPS}, | 5 | WireguardAddressFamily, WireguardAllowedIp, WireguardAllowedIpAttr, WireguardAttribute, |
| 6 | nlas::{WgAllowedIp, WgAllowedIpAttrs, WgDeviceAttrs, WgPeer, WgPeerAttrs}, | 6 | WireguardCmd, WireguardMessage, WireguardPeer, WireguardPeerAttribute, |
| 7 | Wireguard, WireguardCmd, | ||
| 8 | }; | 7 | }; |
| 9 | 8 | ||
| 10 | use super::Key; | 9 | use super::Key; |
| 11 | 10 | ||
| 11 | #[allow(unused)] | ||
| 12 | mod constants { | ||
| 13 | // this is copy pasted from the netlink_packet_wireguard's constants module because for some reason | ||
| 14 | // they stopped exposing constants in commit 3067a394fc7bc28fadbed5359c44cce95aac0f13 | ||
| 15 | pub const WGDEVICE_F_REPLACE_PEERS: u32 = 1 << 0; | ||
| 16 | |||
| 17 | pub const WGPEER_F_REMOVE_ME: u32 = 1 << 0; | ||
| 18 | pub const WGPEER_F_REPLACE_ALLOWEDIPS: u32 = 1 << 1; | ||
| 19 | pub const WGPEER_F_UPDATE_ONLY: u32 = 1 << 2; | ||
| 20 | |||
| 21 | pub const WGPEER_A_UNSPEC: u16 = 0; | ||
| 22 | pub const WGPEER_A_PUBLIC_KEY: u16 = 1; | ||
| 23 | pub const WGPEER_A_PRESHARED_KEY: u16 = 2; | ||
| 24 | pub const WGPEER_A_FLAGS: u16 = 3; | ||
| 25 | pub const WGPEER_A_ENDPOINT: u16 = 4; | ||
| 26 | pub const WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL: u16 = 5; | ||
| 27 | pub const WGPEER_A_LAST_HANDSHAKE_TIME: u16 = 6; | ||
| 28 | pub const WGPEER_A_RX_BYTES: u16 = 7; | ||
| 29 | pub const WGPEER_A_TX_BYTES: u16 = 8; | ||
| 30 | pub const WGPEER_A_ALLOWEDIPS: u16 = 9; | ||
| 31 | pub const WGPEER_A_PROTOCOL_VERSION: u16 = 10; | ||
| 32 | |||
| 33 | pub const WGALLOWEDIP_A_UNSPEC: u16 = 0; | ||
| 34 | pub const WGALLOWEDIP_A_FAMILY: u16 = 1; | ||
| 35 | pub const WGALLOWEDIP_A_IPADDR: u16 = 2; | ||
| 36 | pub const WGALLOWEDIP_A_CIDR_MASK: u16 = 3; | ||
| 37 | |||
| 38 | pub const AF_INET6: u16 = 10; | ||
| 39 | pub const AF_INET: u16 = 2; | ||
| 40 | } | ||
| 41 | |||
| 42 | #[allow(unused)] | ||
| 43 | pub(crate) use constants::*; | ||
| 44 | |||
| 12 | #[derive(Debug)] | 45 | #[derive(Debug)] |
| 13 | pub struct PeerDescriptor { | 46 | pub struct PeerDescriptor { |
| 14 | pub(super) public_key: Key, | 47 | pub(super) public_key: Key, |
| @@ -87,20 +120,25 @@ impl PeerDescriptor { | |||
| 87 | self | 120 | self |
| 88 | } | 121 | } |
| 89 | 122 | ||
| 90 | pub(super) fn into_wireguard(self) -> WgPeer { | 123 | pub(super) fn into_wireguard(self) -> WireguardPeer { |
| 91 | let mut nlas = Vec::new(); | 124 | let mut attributes = Vec::new(); |
| 92 | nlas.push(WgPeerAttrs::PublicKey(self.public_key.into_array())); | 125 | attributes.push(WireguardPeerAttribute::PublicKey( |
| 93 | nlas.extend( | 126 | self.public_key.into_array(), |
| 127 | )); | ||
| 128 | attributes.extend( | ||
| 94 | self.preshared_key | 129 | self.preshared_key |
| 95 | .map(|key| WgPeerAttrs::PresharedKey(key.into_array())), | 130 | .map(|key| WireguardPeerAttribute::PresharedKey(key.into_array())), |
| 96 | ); | 131 | ); |
| 97 | nlas.extend(self.endpoint.map(WgPeerAttrs::Endpoint)); | 132 | attributes.extend(self.endpoint.map(WireguardPeerAttribute::Endpoint)); |
| 98 | nlas.extend(self.keepalive.map(WgPeerAttrs::PersistentKeepalive)); | 133 | attributes.extend( |
| 99 | nlas.extend(self.allowed_ips.map(|allowed_ips| { | 134 | self.keepalive |
| 100 | WgPeerAttrs::AllowedIps(allowed_ips.into_iter().map(ipnet_to_wg).collect()) | 135 | .map(WireguardPeerAttribute::PersistentKeepalive), |
| 136 | ); | ||
| 137 | attributes.extend(self.allowed_ips.map(|allowed_ips| { | ||
| 138 | WireguardPeerAttribute::AllowedIps(allowed_ips.into_iter().map(ipnet_to_wg).collect()) | ||
| 101 | })); | 139 | })); |
| 102 | nlas.push(WgPeerAttrs::Flags(WGPEER_F_REPLACE_ALLOWEDIPS)); | 140 | attributes.push(WireguardPeerAttribute::Flags(WGPEER_F_REPLACE_ALLOWEDIPS)); |
| 103 | WgPeer(nlas) | 141 | WireguardPeer(attributes) |
| 104 | } | 142 | } |
| 105 | } | 143 | } |
| 106 | 144 | ||
| @@ -174,39 +212,43 @@ impl DeviceDescriptor { | |||
| 174 | self | 212 | self |
| 175 | } | 213 | } |
| 176 | 214 | ||
| 177 | pub(super) fn into_wireguard(self, device_name: String) -> Wireguard { | 215 | pub(super) fn into_wireguard(self, device_name: String) -> WireguardMessage { |
| 178 | let mut nlas = Vec::new(); | 216 | let mut attributes = Vec::new(); |
| 179 | nlas.push(WgDeviceAttrs::IfName(device_name)); | 217 | attributes.push(WireguardAttribute::IfName(device_name)); |
| 180 | nlas.extend( | 218 | attributes.extend( |
| 181 | self.private_key | 219 | self.private_key |
| 182 | .map(|key| WgDeviceAttrs::PrivateKey(key.into_array())), | 220 | .map(|key| WireguardAttribute::PrivateKey(key.into_array())), |
| 183 | ); | 221 | ); |
| 184 | nlas.extend(self.listen_port.map(WgDeviceAttrs::ListenPort)); | 222 | attributes.extend(self.listen_port.map(WireguardAttribute::ListenPort)); |
| 185 | nlas.extend(self.fwmark.map(WgDeviceAttrs::Fwmark)); | 223 | attributes.extend(self.fwmark.map(WireguardAttribute::Fwmark)); |
| 186 | nlas.extend(self.peers.map(|peers| { | 224 | attributes.extend(self.peers.map(|peers| { |
| 187 | WgDeviceAttrs::Peers( | 225 | WireguardAttribute::Peers( |
| 188 | peers | 226 | peers |
| 189 | .into_iter() | 227 | .into_iter() |
| 190 | .map(PeerDescriptor::into_wireguard) | 228 | .map(PeerDescriptor::into_wireguard) |
| 191 | .collect(), | 229 | .collect(), |
| 192 | ) | 230 | ) |
| 193 | })); | 231 | })); |
| 194 | nlas.push(WgDeviceAttrs::Flags(WGDEVICE_F_REPLACE_PEERS)); | 232 | attributes.push(WireguardAttribute::Flags(WGDEVICE_F_REPLACE_PEERS)); |
| 195 | 233 | ||
| 196 | Wireguard { | 234 | WireguardMessage { |
| 197 | cmd: WireguardCmd::SetDevice, | 235 | cmd: WireguardCmd::SetDevice, |
| 198 | nlas, | 236 | attributes, |
| 199 | } | 237 | } |
| 200 | } | 238 | } |
| 201 | } | 239 | } |
| 202 | 240 | ||
| 203 | fn ipnet_to_wg(net: IpNet) -> WgAllowedIp { | 241 | fn ipnet_to_wg(net: IpNet) -> WireguardAllowedIp { |
| 204 | let mut nlas = Vec::default(); | 242 | let mut attributes = Vec::default(); |
| 205 | nlas.push(WgAllowedIpAttrs::Cidr(net.prefix_len())); | 243 | attributes.push(WireguardAllowedIpAttr::Cidr(net.prefix_len())); |
| 206 | nlas.push(WgAllowedIpAttrs::IpAddr(net.addr())); | 244 | attributes.push(WireguardAllowedIpAttr::IpAddr(net.addr())); |
| 207 | match net.addr() { | 245 | match net.addr() { |
| 208 | IpAddr::V4(_) => nlas.push(WgAllowedIpAttrs::Family(AF_INET)), | 246 | IpAddr::V4(_) => { |
| 209 | IpAddr::V6(_) => nlas.push(WgAllowedIpAttrs::Family(AF_INET6)), | 247 | attributes.push(WireguardAllowedIpAttr::Family(WireguardAddressFamily::Ipv4)) |
| 248 | } | ||
| 249 | IpAddr::V6(_) => { | ||
| 250 | attributes.push(WireguardAllowedIpAttr::Family(WireguardAddressFamily::Ipv6)) | ||
| 251 | } | ||
| 210 | } | 252 | } |
| 211 | WgAllowedIp(nlas) | 253 | WireguardAllowedIp(attributes) |
| 212 | } | 254 | } |
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 @@ | |||
| 1 | use std::{net::SocketAddr, time::SystemTime}; | 1 | use std::{ |
| 2 | net::SocketAddr, | ||
| 3 | time::{Duration, SystemTime}, | ||
| 4 | }; | ||
| 2 | 5 | ||
| 3 | use ipnet::IpNet; | 6 | use ipnet::IpNet; |
| 4 | use netlink_packet_wireguard::{ | 7 | use netlink_packet_wireguard::{ |
| 5 | nlas::{WgAllowedIp, WgAllowedIpAttrs, WgDeviceAttrs, WgPeer, WgPeerAttrs}, | 8 | WireguardAllowedIp, WireguardAllowedIpAttr, WireguardAttribute, WireguardMessage, |
| 6 | Wireguard, | 9 | WireguardPeer, WireguardPeerAttribute, |
| 7 | }; | 10 | }; |
| 8 | 11 | ||
| 9 | use super::{Error, Key, Result}; | 12 | use super::{Error, Key, Result}; |
| @@ -31,7 +34,7 @@ pub struct PeerView { | |||
| 31 | pub allowed_ips: Vec<IpNet>, | 34 | pub allowed_ips: Vec<IpNet>, |
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | pub(super) fn device_view_from_payload(wg: Wireguard) -> Result<DeviceView> { | 37 | pub(super) fn device_view_from_payload(wg: WireguardMessage) -> Result<DeviceView> { |
| 35 | let mut if_index = None; | 38 | let mut if_index = None; |
| 36 | let mut if_name = None; | 39 | let mut if_name = None; |
| 37 | let mut private_key = None; | 40 | let mut private_key = None; |
| @@ -40,15 +43,15 @@ pub(super) fn device_view_from_payload(wg: Wireguard) -> Result<DeviceView> { | |||
| 40 | let mut fwmark = None; | 43 | let mut fwmark = None; |
| 41 | let mut peers = None; | 44 | let mut peers = None; |
| 42 | 45 | ||
| 43 | for nla in wg.nlas { | 46 | for attr in wg.attributes { |
| 44 | match nla { | 47 | match attr { |
| 45 | WgDeviceAttrs::IfIndex(v) => if_index = Some(v), | 48 | WireguardAttribute::IfIndex(v) => if_index = Some(v), |
| 46 | WgDeviceAttrs::IfName(v) => if_name = Some(v), | 49 | WireguardAttribute::IfName(v) => if_name = Some(v), |
| 47 | WgDeviceAttrs::PrivateKey(v) => private_key = Some(Key::from(v)), | 50 | WireguardAttribute::PrivateKey(v) => private_key = Some(Key::from(v)), |
| 48 | WgDeviceAttrs::PublicKey(v) => public_key = Some(Key::from(v)), | 51 | WireguardAttribute::PublicKey(v) => public_key = Some(Key::from(v)), |
| 49 | WgDeviceAttrs::ListenPort(v) => listen_port = Some(v), | 52 | WireguardAttribute::ListenPort(v) => listen_port = Some(v), |
| 50 | WgDeviceAttrs::Fwmark(v) => fwmark = Some(v), | 53 | WireguardAttribute::Fwmark(v) => fwmark = Some(v), |
| 51 | WgDeviceAttrs::Peers(v) => peers = Some(peers_from_wg_peers(v)?), | 54 | WireguardAttribute::Peers(v) => peers = Some(peers_from_wg_peers(v)?), |
| 52 | _ => {} | 55 | _ => {} |
| 53 | } | 56 | } |
| 54 | } | 57 | } |
| @@ -64,7 +67,7 @@ pub(super) fn device_view_from_payload(wg: Wireguard) -> Result<DeviceView> { | |||
| 64 | }) | 67 | }) |
| 65 | } | 68 | } |
| 66 | 69 | ||
| 67 | fn peers_from_wg_peers(wg_peers: Vec<WgPeer>) -> Result<Vec<PeerView>> { | 70 | fn peers_from_wg_peers(wg_peers: Vec<WireguardPeer>) -> Result<Vec<PeerView>> { |
| 68 | let mut peers = Vec::with_capacity(wg_peers.len()); | 71 | let mut peers = Vec::with_capacity(wg_peers.len()); |
| 69 | for wg_peer in wg_peers { | 72 | for wg_peer in wg_peers { |
| 70 | peers.push(peer_from_wg_peer(wg_peer)?); | 73 | peers.push(peer_from_wg_peer(wg_peer)?); |
| @@ -72,7 +75,7 @@ fn peers_from_wg_peers(wg_peers: Vec<WgPeer>) -> Result<Vec<PeerView>> { | |||
| 72 | Ok(peers) | 75 | Ok(peers) |
| 73 | } | 76 | } |
| 74 | 77 | ||
| 75 | fn peer_from_wg_peer(wg_peer: WgPeer) -> Result<PeerView> { | 78 | fn peer_from_wg_peer(wg_peer: WireguardPeer) -> Result<PeerView> { |
| 76 | let mut public_key = None; | 79 | let mut public_key = None; |
| 77 | let mut preshared_key = None; | 80 | let mut preshared_key = None; |
| 78 | let mut endpoint = None; | 81 | let mut endpoint = None; |
| @@ -84,14 +87,14 @@ fn peer_from_wg_peer(wg_peer: WgPeer) -> Result<PeerView> { | |||
| 84 | 87 | ||
| 85 | for attr in wg_peer.iter() { | 88 | for attr in wg_peer.iter() { |
| 86 | match attr { | 89 | match attr { |
| 87 | WgPeerAttrs::PublicKey(v) => public_key = Some(Key::from(v)), | 90 | WireguardPeerAttribute::PublicKey(v) => public_key = Some(Key::from(v)), |
| 88 | WgPeerAttrs::PresharedKey(v) => preshared_key = Some(Key::from(v)), | 91 | WireguardPeerAttribute::PresharedKey(v) => preshared_key = Some(Key::from(v)), |
| 89 | WgPeerAttrs::Endpoint(v) => endpoint = Some(*v), | 92 | WireguardPeerAttribute::Endpoint(v) => endpoint = Some(*v), |
| 90 | WgPeerAttrs::PersistentKeepalive(v) => persistent_keepalive = Some(*v), | 93 | WireguardPeerAttribute::PersistentKeepalive(v) => persistent_keepalive = Some(*v), |
| 91 | WgPeerAttrs::LastHandshake(v) => last_handshake = Some(*v), | 94 | WireguardPeerAttribute::LastHandshake(v) => last_handshake = Some(*v), |
| 92 | WgPeerAttrs::RxBytes(v) => rx_bytes = Some(*v), | 95 | WireguardPeerAttribute::RxBytes(v) => rx_bytes = Some(*v), |
| 93 | WgPeerAttrs::TxBytes(v) => tx_bytes = Some(*v), | 96 | WireguardPeerAttribute::TxBytes(v) => tx_bytes = Some(*v), |
| 94 | WgPeerAttrs::AllowedIps(v) => { | 97 | WireguardPeerAttribute::AllowedIps(v) => { |
| 95 | for ip in v { | 98 | for ip in v { |
| 96 | allowed_ips.push(ipnet_from_wg(ip)?); | 99 | allowed_ips.push(ipnet_from_wg(ip)?); |
| 97 | } | 100 | } |
| @@ -105,20 +108,22 @@ fn peer_from_wg_peer(wg_peer: WgPeer) -> Result<PeerView> { | |||
| 105 | preshared_key, | 108 | preshared_key, |
| 106 | endpoint, | 109 | endpoint, |
| 107 | persistent_keepalive, | 110 | persistent_keepalive, |
| 108 | last_handshake: last_handshake.ok_or_else(|| Error::message("missing last_handshake"))?, | 111 | last_handshake: last_handshake |
| 112 | .map(|ts| SystemTime::now() - Duration::new(ts.seconds as u64, ts.nano_seconds as u32)) | ||
| 113 | .ok_or_else(|| Error::message("missing last_handshake"))?, | ||
| 109 | rx_bytes: rx_bytes.ok_or_else(|| Error::message("missing rx_bytes"))?, | 114 | rx_bytes: rx_bytes.ok_or_else(|| Error::message("missing rx_bytes"))?, |
| 110 | tx_bytes: tx_bytes.ok_or_else(|| Error::message("missing tx_bytes"))?, | 115 | tx_bytes: tx_bytes.ok_or_else(|| Error::message("missing tx_bytes"))?, |
| 111 | allowed_ips, | 116 | allowed_ips, |
| 112 | }) | 117 | }) |
| 113 | } | 118 | } |
| 114 | 119 | ||
| 115 | fn ipnet_from_wg(wg: &WgAllowedIp) -> Result<IpNet> { | 120 | fn ipnet_from_wg(wg: &WireguardAllowedIp) -> Result<IpNet> { |
| 116 | let mut ip = None; | 121 | let mut ip = None; |
| 117 | let mut prefix = None; | 122 | let mut prefix = None; |
| 118 | for attr in wg.iter() { | 123 | for attr in wg.iter() { |
| 119 | match attr { | 124 | match attr { |
| 120 | WgAllowedIpAttrs::IpAddr(v) => ip = Some(*v), | 125 | WireguardAllowedIpAttr::IpAddr(v) => ip = Some(*v), |
| 121 | WgAllowedIpAttrs::Cidr(v) => prefix = Some(*v), | 126 | WireguardAllowedIpAttr::Cidr(v) => prefix = Some(*v), |
| 122 | _ => {} | 127 | _ => {} |
| 123 | } | 128 | } |
| 124 | } | 129 | } |
