1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir
// from gtk-girs (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{ffi,Setting,SettingSecretFlags,WireGuardPeer};
#[cfg(feature = "v1_20")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
use crate::{Ternary};
use glib::{prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
use std::{boxed::Box as Box_};
glib::wrapper! {
/// WireGuard Settings
///
/// ## Properties
///
///
/// #### `fwmark`
/// The use of fwmark is optional and is by default off. Setting it to 0
/// disables it. Otherwise, it is a 32-bit fwmark for outgoing packets.
///
/// Note that "ip4-auto-default-route" or "ip6-auto-default-route" enabled,
/// implies to automatically choose a fwmark.
///
/// Readable | Writeable
///
///
/// #### `ip4-auto-default-route`
/// Whether to enable special handling of the IPv4 default route.
/// If enabled, the IPv4 default route from wireguard.peer-routes
/// will be placed to a dedicated routing-table and two policy routing rules
/// will be added. The fwmark number is also used as routing-table for the default-route,
/// and if fwmark is zero, an unused fwmark/table is chosen automatically.
/// This corresponds to what wg-quick does with Table=auto and what WireGuard
/// calls "Improved Rule-based Routing".
///
/// Note that for this automatism to work, you usually don't want to set
/// ipv4.gateway, because that will result in a conflicting default route.
///
/// Leaving this at the default will enable this option automatically
/// if ipv4.never-default is not set and there are any peers that use
/// a default-route as allowed-ips. Since this automatism only makes
/// sense if you also have a peer with an /0 allowed-ips, it is usually
/// not necessary to enable this explicitly. However, you can disable
/// it if you want to configure your own routing and rules.
///
/// Readable | Writeable
///
///
/// #### `ip6-auto-default-route`
/// Like ip4-auto-default-route, but for the IPv6 default route.
///
/// Readable | Writeable
///
///
/// #### `listen-port`
/// The listen-port. If listen-port is not specified, the port will be chosen
/// randomly when the interface comes up.
///
/// Readable | Writeable
///
///
/// #### `mtu`
/// If non-zero, only transmit packets of the specified size or smaller,
/// breaking larger packets up into multiple fragments.
///
/// If zero a default MTU is used. Note that contrary to wg-quick's MTU
/// setting, this does not take into account the current routes at the
/// time of activation.
///
/// Readable | Writeable
///
///
/// #### `peer-routes`
/// Whether to automatically add routes for the AllowedIPs ranges
/// of the peers. If [`true`] (the default), NetworkManager will automatically
/// add routes in the routing tables according to ipv4.route-table and
/// ipv6.route-table. Usually you want this automatism enabled.
/// If [`false`], no such routes are added automatically. In this case, the
/// user may want to configure static routes in ipv4.routes and ipv6.routes,
/// respectively.
///
/// Note that if the peer's AllowedIPs is "0.0.0.0/0" or "::/0" and the profile's
/// ipv4.never-default or ipv6.never-default setting is enabled, the peer route for
/// this peer won't be added automatically.
///
/// Readable | Writeable
///
///
/// #### `private-key`
/// The 256 bit private-key in base64 encoding.
///
/// Readable | Writeable
///
///
/// #### `private-key-flags`
/// Flags indicating how to handle the #NMSettingWirelessSecurity:private-key
/// property.
///
/// Readable | Writeable
/// <details><summary><h4>Setting</h4></summary>
///
///
/// #### `name`
/// The setting's name, which uniquely identifies the setting within the
/// connection. Each setting type has a name unique to that type, for
/// example "ppp" or "802-11-wireless" or "802-3-ethernet".
///
/// Readable
/// </details>
///
/// # Implements
///
/// [`SettingExt`][trait@crate::prelude::SettingExt]
#[doc(alias = "NMSettingWireGuard")]
pub struct SettingWireGuard(Object<ffi::NMSettingWireGuard, ffi::NMSettingWireGuardClass>) @extends Setting;
match fn {
type_ => || ffi::nm_setting_wireguard_get_type(),
}
}
impl SettingWireGuard {
/// Creates a new #NMSettingWireGuard object with default values.
///
/// # Returns
///
/// the new empty #NMSettingWireGuard object
#[doc(alias = "nm_setting_wireguard_new")]
pub fn new() -> SettingWireGuard {
assert_initialized_main_thread!();
unsafe {
Setting::from_glib_full(ffi::nm_setting_wireguard_new()).unsafe_cast()
}
}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`SettingWireGuard`] objects.
///
/// This method returns an instance of [`SettingWireGuardBuilder`](crate::builders::SettingWireGuardBuilder) which can be used to create [`SettingWireGuard`] objects.
pub fn builder() -> SettingWireGuardBuilder {
SettingWireGuardBuilder::new()
}
/// If a peer with the same public-key already exists, that
/// one is replaced by @peer. The new @peer is always appended
/// (or moved to) the end, so in case a peer is replaced, the
/// indexes are shifted and the number of peers stays unchanged.
/// ## `peer`
/// the #NMWireGuardPeer instance to append.
/// This seals @peer and keeps a reference on the
/// instance.
#[doc(alias = "nm_setting_wireguard_append_peer")]
pub fn append_peer(&self, peer: &WireGuardPeer) {
unsafe {
ffi::nm_setting_wireguard_append_peer(self.to_glib_none().0, peer.to_glib_none().0);
}
}
///
/// # Returns
///
/// the number of cleared peers.
#[doc(alias = "nm_setting_wireguard_clear_peers")]
pub fn clear_peers(&self) -> u32 {
unsafe {
ffi::nm_setting_wireguard_clear_peers(self.to_glib_none().0)
}
}
///
/// # Returns
///
/// the set firewall mark.
#[doc(alias = "nm_setting_wireguard_get_fwmark")]
#[doc(alias = "get_fwmark")]
pub fn fwmark(&self) -> u32 {
unsafe {
ffi::nm_setting_wireguard_get_fwmark(self.to_glib_none().0)
}
}
///
/// # Returns
///
/// the "ip4-auto-default-route" property of the setting.
#[cfg(feature = "v1_20")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
#[doc(alias = "nm_setting_wireguard_get_ip4_auto_default_route")]
#[doc(alias = "get_ip4_auto_default_route")]
#[doc(alias = "ip4-auto-default-route")]
pub fn ip4_auto_default_route(&self) -> Ternary {
unsafe {
from_glib(ffi::nm_setting_wireguard_get_ip4_auto_default_route(self.to_glib_none().0))
}
}
///
/// # Returns
///
/// the "ip6-auto-default-route" property of the setting.
#[cfg(feature = "v1_20")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
#[doc(alias = "nm_setting_wireguard_get_ip6_auto_default_route")]
#[doc(alias = "get_ip6_auto_default_route")]
#[doc(alias = "ip6-auto-default-route")]
pub fn ip6_auto_default_route(&self) -> Ternary {
unsafe {
from_glib(ffi::nm_setting_wireguard_get_ip6_auto_default_route(self.to_glib_none().0))
}
}
///
/// # Returns
///
/// the set UDP listen port.
#[doc(alias = "nm_setting_wireguard_get_listen_port")]
#[doc(alias = "get_listen_port")]
#[doc(alias = "listen-port")]
pub fn listen_port(&self) -> u16 {
unsafe {
ffi::nm_setting_wireguard_get_listen_port(self.to_glib_none().0)
}
}
///
/// # Returns
///
/// the MTU of the setting.
#[doc(alias = "nm_setting_wireguard_get_mtu")]
#[doc(alias = "get_mtu")]
pub fn mtu(&self) -> u32 {
unsafe {
ffi::nm_setting_wireguard_get_mtu(self.to_glib_none().0)
}
}
/// ## `idx`
/// the index to lookup.
///
/// # Returns
///
/// the #NMWireGuardPeer entry at
/// index @idx. If the index is out of range, [`None`] is returned.
#[doc(alias = "nm_setting_wireguard_get_peer")]
#[doc(alias = "get_peer")]
pub fn peer(&self, idx: u32) -> WireGuardPeer {
unsafe {
from_glib_none(ffi::nm_setting_wireguard_get_peer(self.to_glib_none().0, idx))
}
}
/// ## `public_key`
/// the public key for looking up the
/// peer.
///
/// # Returns
///
/// the #NMWireGuardPeer instance with a
/// matching public key. If no such peer exists, [`None`] is returned.
///
/// ## `out_idx`
/// optional output argument
/// for the index of the found peer. If no index is found,
/// this is set to the nm_setting_wireguard_get_peers_len().
#[doc(alias = "nm_setting_wireguard_get_peer_by_public_key")]
#[doc(alias = "get_peer_by_public_key")]
pub fn peer_by_public_key(&self, public_key: &str) -> (Option<WireGuardPeer>, u32) {
unsafe {
let mut out_idx = std::mem::MaybeUninit::uninit();
let ret = from_glib_none(ffi::nm_setting_wireguard_get_peer_by_public_key(self.to_glib_none().0, public_key.to_glib_none().0, out_idx.as_mut_ptr()));
(ret, out_idx.assume_init())
}
}
///
/// # Returns
///
/// whether automatically add peer routes.
#[doc(alias = "nm_setting_wireguard_get_peer_routes")]
#[doc(alias = "get_peer_routes")]
#[doc(alias = "peer-routes")]
pub fn is_peer_routes(&self) -> bool {
unsafe {
from_glib(ffi::nm_setting_wireguard_get_peer_routes(self.to_glib_none().0))
}
}
///
/// # Returns
///
/// the number of registered peers.
#[doc(alias = "nm_setting_wireguard_get_peers_len")]
#[doc(alias = "get_peers_len")]
pub fn peers_len(&self) -> u32 {
unsafe {
ffi::nm_setting_wireguard_get_peers_len(self.to_glib_none().0)
}
}
///
/// # Returns
///
/// the set private-key or [`None`].
#[doc(alias = "nm_setting_wireguard_get_private_key")]
#[doc(alias = "get_private_key")]
#[doc(alias = "private-key")]
pub fn private_key(&self) -> glib::GString {
unsafe {
from_glib_none(ffi::nm_setting_wireguard_get_private_key(self.to_glib_none().0))
}
}
///
/// # Returns
///
/// the secret-flags for #NMSettingWireGuard:private-key.
#[doc(alias = "nm_setting_wireguard_get_private_key_flags")]
#[doc(alias = "get_private_key_flags")]
#[doc(alias = "private-key-flags")]
pub fn private_key_flags(&self) -> SettingSecretFlags {
unsafe {
from_glib(ffi::nm_setting_wireguard_get_private_key_flags(self.to_glib_none().0))
}
}
/// ## `idx`
/// the index to remove.
///
/// # Returns
///
/// [`true`] if @idx was in range and a peer
/// was removed. Otherwise, @self is unchanged.
#[doc(alias = "nm_setting_wireguard_remove_peer")]
pub fn remove_peer(&self, idx: u32) -> bool {
unsafe {
from_glib(ffi::nm_setting_wireguard_remove_peer(self.to_glib_none().0, idx))
}
}
/// If @idx is one past the last peer, the behavior is the same
/// as nm_setting_wireguard_append_peer().
/// Otherwise, the peer will be at @idx and replace the peer
/// instance at that index. Note that if a peer with the same
/// public-key exists on another index, then that peer will also
/// be replaced. In that case, the number of peers will shrink
/// by one (because the one at @idx got replace and then one
/// with the same public-key got removed). This also means,
/// that the resulting index afterwards may be one less than
/// @idx (if another peer with a lower index was dropped).
/// ## `peer`
/// the #NMWireGuardPeer instance to set.
/// This seals @peer and keeps a reference on the
/// instance.
/// ## `idx`
/// the index, in the range of 0 to the number of
/// peers (including). That means, if @idx is one past
/// the end of the number of peers, this is the same as
/// nm_setting_wireguard_append_peer(). Otherwise, the
/// peer at this index is replaced.
#[doc(alias = "nm_setting_wireguard_set_peer")]
pub fn set_peer(&self, peer: &WireGuardPeer, idx: u32) {
unsafe {
ffi::nm_setting_wireguard_set_peer(self.to_glib_none().0, peer.to_glib_none().0, idx);
}
}
/// The use of fwmark is optional and is by default off. Setting it to 0
/// disables it. Otherwise, it is a 32-bit fwmark for outgoing packets.
///
/// Note that "ip4-auto-default-route" or "ip6-auto-default-route" enabled,
/// implies to automatically choose a fwmark.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
pub fn set_fwmark(&self, fwmark: u32) {
ObjectExt::set_property(self,"fwmark", fwmark)
}
/// Whether to enable special handling of the IPv4 default route.
/// If enabled, the IPv4 default route from wireguard.peer-routes
/// will be placed to a dedicated routing-table and two policy routing rules
/// will be added. The fwmark number is also used as routing-table for the default-route,
/// and if fwmark is zero, an unused fwmark/table is chosen automatically.
/// This corresponds to what wg-quick does with Table=auto and what WireGuard
/// calls "Improved Rule-based Routing".
///
/// Note that for this automatism to work, you usually don't want to set
/// ipv4.gateway, because that will result in a conflicting default route.
///
/// Leaving this at the default will enable this option automatically
/// if ipv4.never-default is not set and there are any peers that use
/// a default-route as allowed-ips. Since this automatism only makes
/// sense if you also have a peer with an /0 allowed-ips, it is usually
/// not necessary to enable this explicitly. However, you can disable
/// it if you want to configure your own routing and rules.
#[cfg(feature = "v1_20")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
#[doc(alias = "ip4-auto-default-route")]
pub fn set_ip4_auto_default_route(&self, ip4_auto_default_route: Ternary) {
ObjectExt::set_property(self,"ip4-auto-default-route", ip4_auto_default_route)
}
/// Like ip4-auto-default-route, but for the IPv6 default route.
#[cfg(feature = "v1_20")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
#[doc(alias = "ip6-auto-default-route")]
pub fn set_ip6_auto_default_route(&self, ip6_auto_default_route: Ternary) {
ObjectExt::set_property(self,"ip6-auto-default-route", ip6_auto_default_route)
}
/// The listen-port. If listen-port is not specified, the port will be chosen
/// randomly when the interface comes up.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "listen-port")]
pub fn set_listen_port(&self, listen_port: u32) {
ObjectExt::set_property(self,"listen-port", listen_port)
}
/// If non-zero, only transmit packets of the specified size or smaller,
/// breaking larger packets up into multiple fragments.
///
/// If zero a default MTU is used. Note that contrary to wg-quick's MTU
/// setting, this does not take into account the current routes at the
/// time of activation.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
pub fn set_mtu(&self, mtu: u32) {
ObjectExt::set_property(self,"mtu", mtu)
}
/// Whether to automatically add routes for the AllowedIPs ranges
/// of the peers. If [`true`] (the default), NetworkManager will automatically
/// add routes in the routing tables according to ipv4.route-table and
/// ipv6.route-table. Usually you want this automatism enabled.
/// If [`false`], no such routes are added automatically. In this case, the
/// user may want to configure static routes in ipv4.routes and ipv6.routes,
/// respectively.
///
/// Note that if the peer's AllowedIPs is "0.0.0.0/0" or "::/0" and the profile's
/// ipv4.never-default or ipv6.never-default setting is enabled, the peer route for
/// this peer won't be added automatically.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "peer-routes")]
pub fn set_peer_routes(&self, peer_routes: bool) {
ObjectExt::set_property(self,"peer-routes", peer_routes)
}
/// The 256 bit private-key in base64 encoding.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "private-key")]
pub fn set_private_key(&self, private_key: Option<&str>) {
ObjectExt::set_property(self,"private-key", private_key)
}
/// Flags indicating how to handle the #NMSettingWirelessSecurity:private-key
/// property.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "private-key-flags")]
pub fn set_private_key_flags(&self, private_key_flags: SettingSecretFlags) {
ObjectExt::set_property(self,"private-key-flags", private_key_flags)
}
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "fwmark")]
pub fn connect_fwmark_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_fwmark_trampoline<F: Fn(&SettingWireGuard) + 'static>(this: *mut ffi::NMSettingWireGuard, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"notify::fwmark".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_fwmark_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
#[cfg(feature = "v1_20")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
#[doc(alias = "ip4-auto-default-route")]
pub fn connect_ip4_auto_default_route_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_ip4_auto_default_route_trampoline<F: Fn(&SettingWireGuard) + 'static>(this: *mut ffi::NMSettingWireGuard, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"notify::ip4-auto-default-route".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_ip4_auto_default_route_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
#[cfg(feature = "v1_20")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
#[doc(alias = "ip6-auto-default-route")]
pub fn connect_ip6_auto_default_route_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_ip6_auto_default_route_trampoline<F: Fn(&SettingWireGuard) + 'static>(this: *mut ffi::NMSettingWireGuard, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"notify::ip6-auto-default-route".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_ip6_auto_default_route_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "listen-port")]
pub fn connect_listen_port_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_listen_port_trampoline<F: Fn(&SettingWireGuard) + 'static>(this: *mut ffi::NMSettingWireGuard, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"notify::listen-port".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_listen_port_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "mtu")]
pub fn connect_mtu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_mtu_trampoline<F: Fn(&SettingWireGuard) + 'static>(this: *mut ffi::NMSettingWireGuard, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"notify::mtu".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_mtu_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "peer-routes")]
pub fn connect_peer_routes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_peer_routes_trampoline<F: Fn(&SettingWireGuard) + 'static>(this: *mut ffi::NMSettingWireGuard, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"notify::peer-routes".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_peer_routes_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "private-key")]
pub fn connect_private_key_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_private_key_trampoline<F: Fn(&SettingWireGuard) + 'static>(this: *mut ffi::NMSettingWireGuard, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"notify::private-key".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_private_key_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "private-key-flags")]
pub fn connect_private_key_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_private_key_flags_trampoline<F: Fn(&SettingWireGuard) + 'static>(this: *mut ffi::NMSettingWireGuard, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"notify::private-key-flags".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_private_key_flags_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
}
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
impl Default for SettingWireGuard {
fn default() -> Self {
Self::new()
}
}
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`SettingWireGuard`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct SettingWireGuardBuilder {
builder: glib::object::ObjectBuilder<'static, SettingWireGuard>,
}
impl SettingWireGuardBuilder {
fn new() -> Self {
Self { builder: glib::object::Object::builder() }
}
/// The use of fwmark is optional and is by default off. Setting it to 0
/// disables it. Otherwise, it is a 32-bit fwmark for outgoing packets.
///
/// Note that "ip4-auto-default-route" or "ip6-auto-default-route" enabled,
/// implies to automatically choose a fwmark.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
pub fn fwmark(self, fwmark: u32) -> Self {
Self { builder: self.builder.property("fwmark", fwmark), }
}
/// Whether to enable special handling of the IPv4 default route.
/// If enabled, the IPv4 default route from wireguard.peer-routes
/// will be placed to a dedicated routing-table and two policy routing rules
/// will be added. The fwmark number is also used as routing-table for the default-route,
/// and if fwmark is zero, an unused fwmark/table is chosen automatically.
/// This corresponds to what wg-quick does with Table=auto and what WireGuard
/// calls "Improved Rule-based Routing".
///
/// Note that for this automatism to work, you usually don't want to set
/// ipv4.gateway, because that will result in a conflicting default route.
///
/// Leaving this at the default will enable this option automatically
/// if ipv4.never-default is not set and there are any peers that use
/// a default-route as allowed-ips. Since this automatism only makes
/// sense if you also have a peer with an /0 allowed-ips, it is usually
/// not necessary to enable this explicitly. However, you can disable
/// it if you want to configure your own routing and rules.
#[cfg(feature = "v1_20")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
pub fn ip4_auto_default_route(self, ip4_auto_default_route: Ternary) -> Self {
Self { builder: self.builder.property("ip4-auto-default-route", ip4_auto_default_route), }
}
/// Like ip4-auto-default-route, but for the IPv6 default route.
#[cfg(feature = "v1_20")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
pub fn ip6_auto_default_route(self, ip6_auto_default_route: Ternary) -> Self {
Self { builder: self.builder.property("ip6-auto-default-route", ip6_auto_default_route), }
}
/// The listen-port. If listen-port is not specified, the port will be chosen
/// randomly when the interface comes up.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
pub fn listen_port(self, listen_port: u32) -> Self {
Self { builder: self.builder.property("listen-port", listen_port), }
}
/// If non-zero, only transmit packets of the specified size or smaller,
/// breaking larger packets up into multiple fragments.
///
/// If zero a default MTU is used. Note that contrary to wg-quick's MTU
/// setting, this does not take into account the current routes at the
/// time of activation.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
pub fn mtu(self, mtu: u32) -> Self {
Self { builder: self.builder.property("mtu", mtu), }
}
/// Whether to automatically add routes for the AllowedIPs ranges
/// of the peers. If [`true`] (the default), NetworkManager will automatically
/// add routes in the routing tables according to ipv4.route-table and
/// ipv6.route-table. Usually you want this automatism enabled.
/// If [`false`], no such routes are added automatically. In this case, the
/// user may want to configure static routes in ipv4.routes and ipv6.routes,
/// respectively.
///
/// Note that if the peer's AllowedIPs is "0.0.0.0/0" or "::/0" and the profile's
/// ipv4.never-default or ipv6.never-default setting is enabled, the peer route for
/// this peer won't be added automatically.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
pub fn peer_routes(self, peer_routes: bool) -> Self {
Self { builder: self.builder.property("peer-routes", peer_routes), }
}
/// The 256 bit private-key in base64 encoding.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
pub fn private_key(self, private_key: impl Into<glib::GString>) -> Self {
Self { builder: self.builder.property("private-key", private_key.into()), }
}
/// Flags indicating how to handle the #NMSettingWirelessSecurity:private-key
/// property.
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
pub fn private_key_flags(self, private_key_flags: SettingSecretFlags) -> Self {
Self { builder: self.builder.property("private-key-flags", private_key_flags), }
}
// rustdoc-stripper-ignore-next
/// Build the [`SettingWireGuard`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> SettingWireGuard {
assert_initialized_main_thread!();
self.builder.build() }
}