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