summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock735
-rw-r--r--Cargo.toml12
-rw-r--r--src/key.rs3
-rw-r--r--src/lib.rs97
-rw-r--r--src/setup.rs108
-rw-r--r--src/view.rs59
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.
3version = 4
4
5[[package]]
6name = "anyhow"
7version = "1.0.101"
8source = "registry+https://github.com/rust-lang/crates.io-index"
9checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea"
10
11[[package]]
12name = "base64"
13version = "0.21.7"
14source = "registry+https://github.com/rust-lang/crates.io-index"
15checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
16
17[[package]]
18name = "bitflags"
19version = "2.11.0"
20source = "registry+https://github.com/rust-lang/crates.io-index"
21checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
22
23[[package]]
24name = "bytes"
25version = "1.11.1"
26source = "registry+https://github.com/rust-lang/crates.io-index"
27checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
28
29[[package]]
30name = "cfg-if"
31version = "1.0.4"
32source = "registry+https://github.com/rust-lang/crates.io-index"
33checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
34
35[[package]]
36name = "cfg_aliases"
37version = "0.2.1"
38source = "registry+https://github.com/rust-lang/crates.io-index"
39checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
40
41[[package]]
42name = "errno"
43version = "0.3.14"
44source = "registry+https://github.com/rust-lang/crates.io-index"
45checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
46dependencies = [
47 "libc",
48 "windows-sys 0.61.2",
49]
50
51[[package]]
52name = "futures"
53version = "0.3.32"
54source = "registry+https://github.com/rust-lang/crates.io-index"
55checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"
56dependencies = [
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]]
67name = "futures-channel"
68version = "0.3.32"
69source = "registry+https://github.com/rust-lang/crates.io-index"
70checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
71dependencies = [
72 "futures-core",
73 "futures-sink",
74]
75
76[[package]]
77name = "futures-core"
78version = "0.3.32"
79source = "registry+https://github.com/rust-lang/crates.io-index"
80checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
81
82[[package]]
83name = "futures-executor"
84version = "0.3.32"
85source = "registry+https://github.com/rust-lang/crates.io-index"
86checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d"
87dependencies = [
88 "futures-core",
89 "futures-task",
90 "futures-util",
91]
92
93[[package]]
94name = "futures-io"
95version = "0.3.32"
96source = "registry+https://github.com/rust-lang/crates.io-index"
97checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
98
99[[package]]
100name = "futures-macro"
101version = "0.3.32"
102source = "registry+https://github.com/rust-lang/crates.io-index"
103checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
104dependencies = [
105 "proc-macro2",
106 "quote",
107 "syn",
108]
109
110[[package]]
111name = "futures-sink"
112version = "0.3.32"
113source = "registry+https://github.com/rust-lang/crates.io-index"
114checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"
115
116[[package]]
117name = "futures-task"
118version = "0.3.32"
119source = "registry+https://github.com/rust-lang/crates.io-index"
120checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
121
122[[package]]
123name = "futures-util"
124version = "0.3.32"
125source = "registry+https://github.com/rust-lang/crates.io-index"
126checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
127dependencies = [
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]]
140name = "genetlink"
141version = "0.2.6"
142source = "registry+https://github.com/rust-lang/crates.io-index"
143checksum = "4d8935531e8e0919b17043c668cc18bfac1622f2fab73125f4f018124ee330b8"
144dependencies = [
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]]
155name = "getrandom"
156version = "0.2.17"
157source = "registry+https://github.com/rust-lang/crates.io-index"
158checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
159dependencies = [
160 "cfg-if",
161 "libc",
162 "wasi",
163]
164
165[[package]]
166name = "ipnet"
167version = "2.11.0"
168source = "registry+https://github.com/rust-lang/crates.io-index"
169checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
170dependencies = [
171 "serde",
172]
173
174[[package]]
175name = "libc"
176version = "0.2.182"
177source = "registry+https://github.com/rust-lang/crates.io-index"
178checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
179
180[[package]]
181name = "lock_api"
182version = "0.4.14"
183source = "registry+https://github.com/rust-lang/crates.io-index"
184checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
185dependencies = [
186 "scopeguard",
187]
188
189[[package]]
190name = "log"
191version = "0.4.29"
192source = "registry+https://github.com/rust-lang/crates.io-index"
193checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
194
195[[package]]
196name = "memchr"
197version = "2.8.0"
198source = "registry+https://github.com/rust-lang/crates.io-index"
199checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
200
201[[package]]
202name = "mio"
203version = "1.1.1"
204source = "registry+https://github.com/rust-lang/crates.io-index"
205checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc"
206dependencies = [
207 "libc",
208 "wasi",
209 "windows-sys 0.61.2",
210]
211
212[[package]]
213name = "netlink-packet-core"
214version = "0.8.1"
215source = "registry+https://github.com/rust-lang/crates.io-index"
216checksum = "3463cbb78394cb0141e2c926b93fc2197e473394b761986eca3b9da2c63ae0f4"
217dependencies = [
218 "paste",
219]
220
221[[package]]
222name = "netlink-packet-generic"
223version = "0.4.0"
224source = "registry+https://github.com/rust-lang/crates.io-index"
225checksum = "2f891b2e0054cac5a684a06628f59568f841c93da4e551239da6e518f539e775"
226dependencies = [
227 "netlink-packet-core",
228]
229
230[[package]]
231name = "netlink-packet-route"
232version = "0.28.0"
233source = "registry+https://github.com/rust-lang/crates.io-index"
234checksum = "4ce3636fa715e988114552619582b530481fd5ef176a1e5c1bf024077c2c9445"
235dependencies = [
236 "bitflags",
237 "libc",
238 "log",
239 "netlink-packet-core",
240]
241
242[[package]]
243name = "netlink-packet-wireguard"
244version = "0.3.0"
245source = "registry+https://github.com/rust-lang/crates.io-index"
246checksum = "037892b0e01ce41f30398a47be2051e712a2cf1eed9cb7e5e6a92b05c423255b"
247dependencies = [
248 "libc",
249 "log",
250 "netlink-packet-core",
251 "netlink-packet-generic",
252]
253
254[[package]]
255name = "netlink-proto"
256version = "0.12.0"
257source = "registry+https://github.com/rust-lang/crates.io-index"
258checksum = "b65d130ee111430e47eed7896ea43ca693c387f097dd97376bffafbf25812128"
259dependencies = [
260 "bytes",
261 "futures",
262 "log",
263 "netlink-packet-core",
264 "netlink-sys",
265 "thiserror 2.0.18",
266]
267
268[[package]]
269name = "netlink-sys"
270version = "0.8.8"
271source = "registry+https://github.com/rust-lang/crates.io-index"
272checksum = "cd6c30ed10fa69cc491d491b85cc971f6bdeb8e7367b7cde2ee6cc878d583fae"
273dependencies = [
274 "bytes",
275 "futures-util",
276 "libc",
277 "log",
278 "tokio",
279]
280
281[[package]]
282name = "nix"
283version = "0.30.1"
284source = "registry+https://github.com/rust-lang/crates.io-index"
285checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
286dependencies = [
287 "bitflags",
288 "cfg-if",
289 "cfg_aliases",
290 "libc",
291]
292
293[[package]]
294name = "once_cell"
295version = "1.21.3"
296source = "registry+https://github.com/rust-lang/crates.io-index"
297checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
298
299[[package]]
300name = "parking_lot"
301version = "0.12.5"
302source = "registry+https://github.com/rust-lang/crates.io-index"
303checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
304dependencies = [
305 "lock_api",
306 "parking_lot_core",
307]
308
309[[package]]
310name = "parking_lot_core"
311version = "0.9.12"
312source = "registry+https://github.com/rust-lang/crates.io-index"
313checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
314dependencies = [
315 "cfg-if",
316 "libc",
317 "redox_syscall",
318 "smallvec",
319 "windows-link",
320]
321
322[[package]]
323name = "paste"
324version = "1.0.15"
325source = "registry+https://github.com/rust-lang/crates.io-index"
326checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
327
328[[package]]
329name = "pin-project-lite"
330version = "0.2.16"
331source = "registry+https://github.com/rust-lang/crates.io-index"
332checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
333
334[[package]]
335name = "ppv-lite86"
336version = "0.2.21"
337source = "registry+https://github.com/rust-lang/crates.io-index"
338checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
339dependencies = [
340 "zerocopy",
341]
342
343[[package]]
344name = "proc-macro2"
345version = "1.0.106"
346source = "registry+https://github.com/rust-lang/crates.io-index"
347checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
348dependencies = [
349 "unicode-ident",
350]
351
352[[package]]
353name = "quote"
354version = "1.0.44"
355source = "registry+https://github.com/rust-lang/crates.io-index"
356checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
357dependencies = [
358 "proc-macro2",
359]
360
361[[package]]
362name = "rand"
363version = "0.8.5"
364source = "registry+https://github.com/rust-lang/crates.io-index"
365checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
366dependencies = [
367 "libc",
368 "rand_chacha",
369 "rand_core",
370]
371
372[[package]]
373name = "rand_chacha"
374version = "0.3.1"
375source = "registry+https://github.com/rust-lang/crates.io-index"
376checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
377dependencies = [
378 "ppv-lite86",
379 "rand_core",
380]
381
382[[package]]
383name = "rand_core"
384version = "0.6.4"
385source = "registry+https://github.com/rust-lang/crates.io-index"
386checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
387dependencies = [
388 "getrandom",
389]
390
391[[package]]
392name = "redox_syscall"
393version = "0.5.18"
394source = "registry+https://github.com/rust-lang/crates.io-index"
395checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
396dependencies = [
397 "bitflags",
398]
399
400[[package]]
401name = "rtnetlink"
402version = "0.20.0"
403source = "registry+https://github.com/rust-lang/crates.io-index"
404checksum = "4b960d5d873a75b5be9761b1e73b146f52dddcd27bac75263f40fba686d4d7b5"
405dependencies = [
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]]
419name = "scopeguard"
420version = "1.2.0"
421source = "registry+https://github.com/rust-lang/crates.io-index"
422checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
423
424[[package]]
425name = "serde"
426version = "1.0.228"
427source = "registry+https://github.com/rust-lang/crates.io-index"
428checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
429dependencies = [
430 "serde_core",
431 "serde_derive",
432]
433
434[[package]]
435name = "serde_core"
436version = "1.0.228"
437source = "registry+https://github.com/rust-lang/crates.io-index"
438checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
439dependencies = [
440 "serde_derive",
441]
442
443[[package]]
444name = "serde_derive"
445version = "1.0.228"
446source = "registry+https://github.com/rust-lang/crates.io-index"
447checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
448dependencies = [
449 "proc-macro2",
450 "quote",
451 "syn",
452]
453
454[[package]]
455name = "signal-hook-registry"
456version = "1.4.8"
457source = "registry+https://github.com/rust-lang/crates.io-index"
458checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
459dependencies = [
460 "errno",
461 "libc",
462]
463
464[[package]]
465name = "slab"
466version = "0.4.12"
467source = "registry+https://github.com/rust-lang/crates.io-index"
468checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
469
470[[package]]
471name = "smallvec"
472version = "1.15.1"
473source = "registry+https://github.com/rust-lang/crates.io-index"
474checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
475
476[[package]]
477name = "socket2"
478version = "0.6.2"
479source = "registry+https://github.com/rust-lang/crates.io-index"
480checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0"
481dependencies = [
482 "libc",
483 "windows-sys 0.60.2",
484]
485
486[[package]]
487name = "syn"
488version = "2.0.116"
489source = "registry+https://github.com/rust-lang/crates.io-index"
490checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb"
491dependencies = [
492 "proc-macro2",
493 "quote",
494 "unicode-ident",
495]
496
497[[package]]
498name = "thiserror"
499version = "1.0.69"
500source = "registry+https://github.com/rust-lang/crates.io-index"
501checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
502dependencies = [
503 "thiserror-impl 1.0.69",
504]
505
506[[package]]
507name = "thiserror"
508version = "2.0.18"
509source = "registry+https://github.com/rust-lang/crates.io-index"
510checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
511dependencies = [
512 "thiserror-impl 2.0.18",
513]
514
515[[package]]
516name = "thiserror-impl"
517version = "1.0.69"
518source = "registry+https://github.com/rust-lang/crates.io-index"
519checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
520dependencies = [
521 "proc-macro2",
522 "quote",
523 "syn",
524]
525
526[[package]]
527name = "thiserror-impl"
528version = "2.0.18"
529source = "registry+https://github.com/rust-lang/crates.io-index"
530checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
531dependencies = [
532 "proc-macro2",
533 "quote",
534 "syn",
535]
536
537[[package]]
538name = "tokio"
539version = "1.49.0"
540source = "registry+https://github.com/rust-lang/crates.io-index"
541checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"
542dependencies = [
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]]
555name = "tokio-macros"
556version = "2.6.0"
557source = "registry+https://github.com/rust-lang/crates.io-index"
558checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
559dependencies = [
560 "proc-macro2",
561 "quote",
562 "syn",
563]
564
565[[package]]
566name = "tracing"
567version = "0.1.44"
568source = "registry+https://github.com/rust-lang/crates.io-index"
569checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
570dependencies = [
571 "pin-project-lite",
572 "tracing-attributes",
573 "tracing-core",
574]
575
576[[package]]
577name = "tracing-attributes"
578version = "0.1.31"
579source = "registry+https://github.com/rust-lang/crates.io-index"
580checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
581dependencies = [
582 "proc-macro2",
583 "quote",
584 "syn",
585]
586
587[[package]]
588name = "tracing-core"
589version = "0.1.36"
590source = "registry+https://github.com/rust-lang/crates.io-index"
591checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
592dependencies = [
593 "once_cell",
594]
595
596[[package]]
597name = "unicode-ident"
598version = "1.0.23"
599source = "registry+https://github.com/rust-lang/crates.io-index"
600checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"
601
602[[package]]
603name = "wasi"
604version = "0.11.1+wasi-snapshot-preview1"
605source = "registry+https://github.com/rust-lang/crates.io-index"
606checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
607
608[[package]]
609name = "windows-link"
610version = "0.2.1"
611source = "registry+https://github.com/rust-lang/crates.io-index"
612checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
613
614[[package]]
615name = "windows-sys"
616version = "0.60.2"
617source = "registry+https://github.com/rust-lang/crates.io-index"
618checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
619dependencies = [
620 "windows-targets",
621]
622
623[[package]]
624name = "windows-sys"
625version = "0.61.2"
626source = "registry+https://github.com/rust-lang/crates.io-index"
627checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
628dependencies = [
629 "windows-link",
630]
631
632[[package]]
633name = "windows-targets"
634version = "0.53.5"
635source = "registry+https://github.com/rust-lang/crates.io-index"
636checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
637dependencies = [
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]]
650name = "windows_aarch64_gnullvm"
651version = "0.53.1"
652source = "registry+https://github.com/rust-lang/crates.io-index"
653checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
654
655[[package]]
656name = "windows_aarch64_msvc"
657version = "0.53.1"
658source = "registry+https://github.com/rust-lang/crates.io-index"
659checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
660
661[[package]]
662name = "windows_i686_gnu"
663version = "0.53.1"
664source = "registry+https://github.com/rust-lang/crates.io-index"
665checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
666
667[[package]]
668name = "windows_i686_gnullvm"
669version = "0.53.1"
670source = "registry+https://github.com/rust-lang/crates.io-index"
671checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
672
673[[package]]
674name = "windows_i686_msvc"
675version = "0.53.1"
676source = "registry+https://github.com/rust-lang/crates.io-index"
677checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
678
679[[package]]
680name = "windows_x86_64_gnu"
681version = "0.53.1"
682source = "registry+https://github.com/rust-lang/crates.io-index"
683checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
684
685[[package]]
686name = "windows_x86_64_gnullvm"
687version = "0.53.1"
688source = "registry+https://github.com/rust-lang/crates.io-index"
689checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
690
691[[package]]
692name = "windows_x86_64_msvc"
693version = "0.53.1"
694source = "registry+https://github.com/rust-lang/crates.io-index"
695checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
696
697[[package]]
698name = "wireguard"
699version = "0.0.0"
700dependencies = [
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]]
718name = "zerocopy"
719version = "0.8.39"
720source = "registry+https://github.com/rust-lang/crates.io-index"
721checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a"
722dependencies = [
723 "zerocopy-derive",
724]
725
726[[package]]
727name = "zerocopy-derive"
728version = "0.8.39"
729source = "registry+https://github.com/rust-lang/crates.io-index"
730checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517"
731dependencies = [
732 "proc-macro2",
733 "quote",
734 "syn",
735]
diff --git a/Cargo.toml b/Cargo.toml
index b2c8f54..e7ffd1b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,14 +9,14 @@ edition = "2021"
9anyhow = "1.0.79" 9anyhow = "1.0.79"
10base64 = "0.21.7" 10base64 = "0.21.7"
11futures = "0.3.30" 11futures = "0.3.30"
12genetlink = "0.2.5" 12genetlink = "=0.2.6"
13ipnet = { version = "2.9.0", features = ["serde"] } 13ipnet = { version = "2.9.0", features = ["serde"] }
14netlink-packet-core = "=0.7.0" 14netlink-packet-core = "=0.8.1"
15netlink-packet-generic = "=0.3.3" 15netlink-packet-generic = "=0.4.0"
16netlink-packet-route = "=0.18.1" 16netlink-packet-route = "=0.28.0"
17netlink-packet-wireguard = "=0.2.3" 17netlink-packet-wireguard = "=0.3.0"
18rand = "0.8.5" 18rand = "0.8.5"
19rtnetlink = "=0.14.0" 19rtnetlink = "=0.20.0"
20serde = "1.0.195" 20serde = "1.0.195"
21tokio = { version = "1.35.1", features = ["full"] } 21tokio = { version = "1.35.1", features = ["full"] }
22tracing = "0.1.40" 22tracing = "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 @@
1use base64::Engine; 1use base64::Engine;
2use netlink_packet_wireguard::constants::WG_KEY_LEN;
3use rand::{rngs::OsRng, RngCore}; 2use rand::{rngs::OsRng, RngCore};
4 3
4const 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
7type Fe = [i64; 16]; 8type 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;
3mod setup; 3mod setup;
4mod view; 4mod view;
5 5
6use std::borrow::Cow; 6use std::{
7 borrow::Cow,
8 net::{Ipv4Addr, Ipv6Addr},
9};
7 10
8use futures::{StreamExt, TryStreamExt}; 11use futures::{StreamExt, TryStreamExt};
9use genetlink::{GenetlinkError, GenetlinkHandle}; 12use genetlink::{GenetlinkError, GenetlinkHandle};
10use netlink_packet_core::{NetlinkMessage, NetlinkPayload, NLM_F_ACK, NLM_F_DUMP, NLM_F_REQUEST}; 13use netlink_packet_core::{NetlinkMessage, NetlinkPayload, NLM_F_ACK, NLM_F_DUMP, NLM_F_REQUEST};
11use netlink_packet_generic::GenlMessage; 14use netlink_packet_generic::GenlMessage;
12use netlink_packet_route::{ 15use netlink_packet_route::{link::LinkAttribute, route::RouteScope};
13 link::{InfoKind, LinkAttribute, LinkInfo}, 16use netlink_packet_wireguard::{WireguardAttribute, WireguardCmd, WireguardMessage};
14 route::RouteScope, 17use rtnetlink::{Handle, LinkMessageBuilder, LinkSetRequest, LinkWireguard, RouteMessageBuilder};
15};
16use netlink_packet_wireguard::{nlas::WgDeviceAttrs, Wireguard, WireguardCmd};
17use rtnetlink::Handle;
18 18
19pub use conf::*; 19pub use conf::*;
20pub use key::*; 20pub 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
3use ipnet::IpNet; 3use ipnet::IpNet;
4use netlink_packet_wireguard::{ 4use 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
10use super::Key; 9use super::Key;
11 10
11#[allow(unused)]
12mod 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)]
43pub(crate) use constants::*;
44
12#[derive(Debug)] 45#[derive(Debug)]
13pub struct PeerDescriptor { 46pub 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
203fn ipnet_to_wg(net: IpNet) -> WgAllowedIp { 241fn 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 @@
1use std::{net::SocketAddr, time::SystemTime}; 1use std::{
2 net::SocketAddr,
3 time::{Duration, SystemTime},
4};
2 5
3use ipnet::IpNet; 6use ipnet::IpNet;
4use netlink_packet_wireguard::{ 7use netlink_packet_wireguard::{
5 nlas::{WgAllowedIp, WgAllowedIpAttrs, WgDeviceAttrs, WgPeer, WgPeerAttrs}, 8 WireguardAllowedIp, WireguardAllowedIpAttr, WireguardAttribute, WireguardMessage,
6 Wireguard, 9 WireguardPeer, WireguardPeerAttribute,
7}; 10};
8 11
9use super::{Error, Key, Result}; 12use 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
34pub(super) fn device_view_from_payload(wg: Wireguard) -> Result<DeviceView> { 37pub(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
67fn peers_from_wg_peers(wg_peers: Vec<WgPeer>) -> Result<Vec<PeerView>> { 70fn 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
75fn peer_from_wg_peer(wg_peer: WgPeer) -> Result<PeerView> { 78fn 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
115fn ipnet_from_wg(wg: &WgAllowedIp) -> Result<IpNet> { 120fn 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 }