nm_rs/auto/setting_sriov.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
6#[cfg(feature = "v1_54")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v1_54")))]
8use crate::SriovPreserveOnDown;
9use crate::{Setting, SriovVF, Ternary, ffi};
10#[cfg(feature = "v1_46")]
11#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
12use crate::{SriovEswitchEncapMode, SriovEswitchInlineMode, SriovEswitchMode};
13use glib::{
14 prelude::*,
15 signal::{SignalHandlerId, connect_raw},
16 translate::*,
17};
18use std::boxed::Box as Box_;
19
20glib::wrapper! {
21 /// SR-IOV settings
22 ///
23 /// ## Properties
24 ///
25 ///
26 /// #### `autoprobe-drivers`
27 /// Whether to autoprobe virtual functions by a compatible driver.
28 ///
29 /// If set to [`Ternary::True`][crate::Ternary::True], the kernel will try to bind VFs to
30 /// a compatible driver and if this succeeds a new network
31 /// interface will be instantiated for each VF.
32 ///
33 /// If set to [`Ternary::False`][crate::Ternary::False], VFs will not be claimed and no
34 /// network interfaces will be created for them.
35 ///
36 /// When set to [`Ternary::Default`][crate::Ternary::Default], the global default is used; in
37 /// case the global default is unspecified it is assumed to be
38 /// [`Ternary::True`][crate::Ternary::True].
39 ///
40 /// Readable | Writeable
41 ///
42 ///
43 /// #### `eswitch-encap-mode`
44 /// Select the eswitch encapsulation support.
45 ///
46 /// Currently it's only supported for PCI PF devices, and only if the eswitch device
47 /// is managed from the same PCI address than the PF.
48 ///
49 /// If set to [`SriovEswitchEncapMode::Preserve`][crate::SriovEswitchEncapMode::Preserve] (default) the eswitch encap-mode
50 /// won't be modified by NetworkManager.
51 ///
52 /// Readable | Writeable
53 ///
54 ///
55 /// #### `eswitch-inline-mode`
56 /// Select the eswitch inline-mode of the device. Some HWs need the VF driver to put
57 /// part of the packet headers on the TX descriptor so the e-switch can do proper
58 /// matching and steering.
59 ///
60 /// Currently it's only supported for PCI PF devices, and only if the eswitch device
61 /// is managed from the same PCI address than the PF.
62 ///
63 /// If set to [`SriovEswitchInlineMode::Preserve`][crate::SriovEswitchInlineMode::Preserve] (default) the eswitch inline-mode
64 /// won't be modified by NetworkManager.
65 ///
66 /// Readable | Writeable
67 ///
68 ///
69 /// #### `eswitch-mode`
70 /// Select the eswitch mode of the device. Currently it's only supported for
71 /// PCI PF devices, and only if the eswitch device is managed from the same
72 /// PCI address than the PF.
73 ///
74 /// If set to [`SriovEswitchMode::Preserve`][crate::SriovEswitchMode::Preserve] (default) the eswitch mode won't be
75 /// modified by NetworkManager.
76 ///
77 /// Readable | Writeable
78 ///
79 ///
80 /// #### `preserve-on-down`
81 /// This controls whether NetworkManager preserves the SR-IOV parameters set on
82 /// the device when the connection is deactivated, or whether it resets them to
83 /// their default value. The SR-IOV parameters are those specified in this setting
84 /// (the "sriov" setting), like the number of VFs to create, the eswitch
85 /// configuration, etc.
86 ///
87 /// If set to [`SriovPreserveOnDown::No`][crate::SriovPreserveOnDown::No], NetworkManager resets the SR-IOV
88 /// parameters when the connection is deactivated. When set to
89 /// [`SriovPreserveOnDown::Yes`][crate::SriovPreserveOnDown::Yes], NetworkManager preserves those parameters
90 /// on the device. If the value is [`SriovPreserveOnDown::Default`][crate::SriovPreserveOnDown::Default], NetworkManager
91 /// looks up a global default value in the configuration; in case no such value is
92 /// defined, it uses [`SriovPreserveOnDown::No`][crate::SriovPreserveOnDown::No] as fallback.
93 ///
94 /// Readable | Writeable
95 ///
96 ///
97 /// #### `total-vfs`
98 /// The total number of virtual functions to create.
99 ///
100 /// Note that when the sriov setting is present NetworkManager
101 /// enforces the number of virtual functions on the interface
102 /// (also when it is zero) during activation and resets it
103 /// upon deactivation. To prevent any changes to SR-IOV
104 /// parameters don't add a sriov setting to the connection.
105 ///
106 /// Readable | Writeable
107 ///
108 ///
109 /// #### `vfs`
110 /// Array of virtual function descriptors.
111 ///
112 /// Each VF descriptor is a dictionary mapping attribute names
113 /// to GVariant values. The 'index' entry is mandatory for
114 /// each VF.
115 ///
116 /// When represented as string a VF is in the form:
117 ///
118 /// "INDEX [ATTR=VALUE[ ATTR=VALUE]...]".
119 ///
120 /// for example:
121 ///
122 /// "2 mac=00:11:22:33:44:55 spoof-check=true".
123 ///
124 /// Multiple VFs can be specified using a comma as separator.
125 /// Currently, the following attributes are supported: mac,
126 /// spoof-check, trust, min-tx-rate, max-tx-rate, vlans.
127 ///
128 /// The "vlans" attribute is represented as a semicolon-separated
129 /// list of VLAN descriptors, where each descriptor has the form
130 ///
131 /// "ID[.PRIORITY[.PROTO]]".
132 ///
133 /// PROTO can be either 'q' for 802.1Q (the default) or 'ad' for
134 /// 802.1ad.
135 ///
136 /// Readable | Writeable
137 /// <details><summary><h4>Setting</h4></summary>
138 ///
139 ///
140 /// #### `name`
141 /// The setting's name, which uniquely identifies the setting within the
142 /// connection. Each setting type has a name unique to that type, for
143 /// example "ppp" or "802-11-wireless" or "802-3-ethernet".
144 ///
145 /// Readable
146 /// </details>
147 ///
148 /// # Implements
149 ///
150 /// [`SettingExt`][trait@crate::prelude::SettingExt]
151 #[doc(alias = "NMSettingSriov")]
152 pub struct SettingSriov(Object<ffi::NMSettingSriov, ffi::NMSettingSriovClass>) @extends Setting;
153
154 match fn {
155 type_ => || ffi::nm_setting_sriov_get_type(),
156 }
157}
158
159impl SettingSriov {
160 /// Creates a new #NMSettingSriov object with default values.
161 ///
162 /// # Returns
163 ///
164 /// the new empty #NMSettingSriov object
165 #[doc(alias = "nm_setting_sriov_new")]
166 pub fn new() -> SettingSriov {
167 assert_initialized_main_thread!();
168 unsafe { Setting::from_glib_full(ffi::nm_setting_sriov_new()).unsafe_cast() }
169 }
170
171 // rustdoc-stripper-ignore-next
172 /// Creates a new builder-pattern struct instance to construct [`SettingSriov`] objects.
173 ///
174 /// This method returns an instance of [`SettingSriovBuilder`](crate::builders::SettingSriovBuilder) which can be used to create [`SettingSriov`] objects.
175 pub fn builder() -> SettingSriovBuilder {
176 SettingSriovBuilder::new()
177 }
178
179 /// Appends a new VF and associated information to the setting. The
180 /// given VF is duplicated internally and is not changed by this function.
181 /// ## `vf`
182 /// the VF to add
183 #[doc(alias = "nm_setting_sriov_add_vf")]
184 pub fn add_vf(&self, vf: &SriovVF) {
185 unsafe {
186 ffi::nm_setting_sriov_add_vf(self.to_glib_none().0, vf.to_glib_none().0);
187 }
188 }
189
190 /// Removes all configured VFs.
191 #[doc(alias = "nm_setting_sriov_clear_vfs")]
192 pub fn clear_vfs(&self) {
193 unsafe {
194 ffi::nm_setting_sriov_clear_vfs(self.to_glib_none().0);
195 }
196 }
197
198 /// Returns the value contained in the #NMSettingSriov:autoprobe-drivers
199 /// property.
200 ///
201 /// # Returns
202 ///
203 /// the autoprobe-drivers property value
204 #[doc(alias = "nm_setting_sriov_get_autoprobe_drivers")]
205 #[doc(alias = "get_autoprobe_drivers")]
206 #[doc(alias = "autoprobe-drivers")]
207 pub fn autoprobe_drivers(&self) -> Ternary {
208 unsafe {
209 from_glib(ffi::nm_setting_sriov_get_autoprobe_drivers(
210 self.to_glib_none().0,
211 ))
212 }
213 }
214
215 ///
216 /// # Returns
217 ///
218 /// the value contained in the #NMSettingSriov:eswitch-encap-mode property.
219 #[cfg(feature = "v1_46")]
220 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
221 #[doc(alias = "nm_setting_sriov_get_eswitch_encap_mode")]
222 #[doc(alias = "get_eswitch_encap_mode")]
223 #[doc(alias = "eswitch-encap-mode")]
224 pub fn eswitch_encap_mode(&self) -> SriovEswitchEncapMode {
225 unsafe {
226 from_glib(ffi::nm_setting_sriov_get_eswitch_encap_mode(
227 self.to_glib_none().0,
228 ))
229 }
230 }
231
232 ///
233 /// # Returns
234 ///
235 /// the value contained in the #NMSettingSriov:eswitch-inline-mode property.
236 #[cfg(feature = "v1_46")]
237 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
238 #[doc(alias = "nm_setting_sriov_get_eswitch_inline_mode")]
239 #[doc(alias = "get_eswitch_inline_mode")]
240 #[doc(alias = "eswitch-inline-mode")]
241 pub fn eswitch_inline_mode(&self) -> SriovEswitchInlineMode {
242 unsafe {
243 from_glib(ffi::nm_setting_sriov_get_eswitch_inline_mode(
244 self.to_glib_none().0,
245 ))
246 }
247 }
248
249 ///
250 /// # Returns
251 ///
252 /// the value contained in the #NMSettingSriov:eswitch-mode property.
253 #[cfg(feature = "v1_46")]
254 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
255 #[doc(alias = "nm_setting_sriov_get_eswitch_mode")]
256 #[doc(alias = "get_eswitch_mode")]
257 #[doc(alias = "eswitch-mode")]
258 pub fn eswitch_mode(&self) -> SriovEswitchMode {
259 unsafe {
260 from_glib(ffi::nm_setting_sriov_get_eswitch_mode(
261 self.to_glib_none().0,
262 ))
263 }
264 }
265
266 ///
267 /// # Returns
268 ///
269 /// the number of configured VFs
270 #[doc(alias = "nm_setting_sriov_get_num_vfs")]
271 #[doc(alias = "get_num_vfs")]
272 pub fn num_vfs(&self) -> u32 {
273 unsafe { ffi::nm_setting_sriov_get_num_vfs(self.to_glib_none().0) }
274 }
275
276 ///
277 /// # Returns
278 ///
279 /// the value contained in the #NMSettingSriov:preserve-on-down property.
280 #[cfg(feature = "v1_54")]
281 #[cfg_attr(docsrs, doc(cfg(feature = "v1_54")))]
282 #[doc(alias = "nm_setting_sriov_get_preserve_on_down")]
283 #[doc(alias = "get_preserve_on_down")]
284 #[doc(alias = "preserve-on-down")]
285 pub fn preserve_on_down(&self) -> SriovPreserveOnDown {
286 unsafe {
287 from_glib(ffi::nm_setting_sriov_get_preserve_on_down(
288 self.to_glib_none().0,
289 ))
290 }
291 }
292
293 /// Returns the value contained in the #NMSettingSriov:total-vfs
294 /// property.
295 ///
296 /// # Returns
297 ///
298 /// the total number of SR-IOV virtual functions to create
299 #[doc(alias = "nm_setting_sriov_get_total_vfs")]
300 #[doc(alias = "get_total_vfs")]
301 #[doc(alias = "total-vfs")]
302 pub fn total_vfs(&self) -> u32 {
303 unsafe { ffi::nm_setting_sriov_get_total_vfs(self.to_glib_none().0) }
304 }
305
306 /// ## `idx`
307 /// index number of the VF to return
308 ///
309 /// # Returns
310 ///
311 /// the VF at index @idx
312 #[doc(alias = "nm_setting_sriov_get_vf")]
313 #[doc(alias = "get_vf")]
314 pub fn vf(&self, idx: u32) -> SriovVF {
315 unsafe { from_glib_none(ffi::nm_setting_sriov_get_vf(self.to_glib_none().0, idx)) }
316 }
317
318 /// Removes the VF at index @idx.
319 /// ## `idx`
320 /// index number of the VF
321 #[doc(alias = "nm_setting_sriov_remove_vf")]
322 pub fn remove_vf(&self, idx: u32) {
323 unsafe {
324 ffi::nm_setting_sriov_remove_vf(self.to_glib_none().0, idx);
325 }
326 }
327
328 /// Removes the VF with VF index @index.
329 /// ## `index`
330 /// the VF index of the VF to remove
331 ///
332 /// # Returns
333 ///
334 /// [`true`] if the VF was found and removed; [`false`] if it was not
335 #[doc(alias = "nm_setting_sriov_remove_vf_by_index")]
336 pub fn remove_vf_by_index(&self, index: u32) -> bool {
337 unsafe {
338 from_glib(ffi::nm_setting_sriov_remove_vf_by_index(
339 self.to_glib_none().0,
340 index,
341 ))
342 }
343 }
344
345 /// Whether to autoprobe virtual functions by a compatible driver.
346 ///
347 /// If set to [`Ternary::True`][crate::Ternary::True], the kernel will try to bind VFs to
348 /// a compatible driver and if this succeeds a new network
349 /// interface will be instantiated for each VF.
350 ///
351 /// If set to [`Ternary::False`][crate::Ternary::False], VFs will not be claimed and no
352 /// network interfaces will be created for them.
353 ///
354 /// When set to [`Ternary::Default`][crate::Ternary::Default], the global default is used; in
355 /// case the global default is unspecified it is assumed to be
356 /// [`Ternary::True`][crate::Ternary::True].
357 #[cfg(feature = "v1_14")]
358 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
359 #[doc(alias = "autoprobe-drivers")]
360 pub fn set_autoprobe_drivers(&self, autoprobe_drivers: Ternary) {
361 ObjectExt::set_property(self, "autoprobe-drivers", autoprobe_drivers)
362 }
363
364 /// Select the eswitch encapsulation support.
365 ///
366 /// Currently it's only supported for PCI PF devices, and only if the eswitch device
367 /// is managed from the same PCI address than the PF.
368 ///
369 /// If set to [`SriovEswitchEncapMode::Preserve`][crate::SriovEswitchEncapMode::Preserve] (default) the eswitch encap-mode
370 /// won't be modified by NetworkManager.
371 #[cfg(feature = "v1_46")]
372 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
373 #[doc(alias = "eswitch-encap-mode")]
374 pub fn set_eswitch_encap_mode(&self, eswitch_encap_mode: i32) {
375 ObjectExt::set_property(self, "eswitch-encap-mode", eswitch_encap_mode)
376 }
377
378 /// Select the eswitch inline-mode of the device. Some HWs need the VF driver to put
379 /// part of the packet headers on the TX descriptor so the e-switch can do proper
380 /// matching and steering.
381 ///
382 /// Currently it's only supported for PCI PF devices, and only if the eswitch device
383 /// is managed from the same PCI address than the PF.
384 ///
385 /// If set to [`SriovEswitchInlineMode::Preserve`][crate::SriovEswitchInlineMode::Preserve] (default) the eswitch inline-mode
386 /// won't be modified by NetworkManager.
387 #[cfg(feature = "v1_46")]
388 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
389 #[doc(alias = "eswitch-inline-mode")]
390 pub fn set_eswitch_inline_mode(&self, eswitch_inline_mode: i32) {
391 ObjectExt::set_property(self, "eswitch-inline-mode", eswitch_inline_mode)
392 }
393
394 /// Select the eswitch mode of the device. Currently it's only supported for
395 /// PCI PF devices, and only if the eswitch device is managed from the same
396 /// PCI address than the PF.
397 ///
398 /// If set to [`SriovEswitchMode::Preserve`][crate::SriovEswitchMode::Preserve] (default) the eswitch mode won't be
399 /// modified by NetworkManager.
400 #[cfg(feature = "v1_46")]
401 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
402 #[doc(alias = "eswitch-mode")]
403 pub fn set_eswitch_mode(&self, eswitch_mode: i32) {
404 ObjectExt::set_property(self, "eswitch-mode", eswitch_mode)
405 }
406
407 /// This controls whether NetworkManager preserves the SR-IOV parameters set on
408 /// the device when the connection is deactivated, or whether it resets them to
409 /// their default value. The SR-IOV parameters are those specified in this setting
410 /// (the "sriov" setting), like the number of VFs to create, the eswitch
411 /// configuration, etc.
412 ///
413 /// If set to [`SriovPreserveOnDown::No`][crate::SriovPreserveOnDown::No], NetworkManager resets the SR-IOV
414 /// parameters when the connection is deactivated. When set to
415 /// [`SriovPreserveOnDown::Yes`][crate::SriovPreserveOnDown::Yes], NetworkManager preserves those parameters
416 /// on the device. If the value is [`SriovPreserveOnDown::Default`][crate::SriovPreserveOnDown::Default], NetworkManager
417 /// looks up a global default value in the configuration; in case no such value is
418 /// defined, it uses [`SriovPreserveOnDown::No`][crate::SriovPreserveOnDown::No] as fallback.
419 #[cfg(feature = "v1_54")]
420 #[cfg_attr(docsrs, doc(cfg(feature = "v1_54")))]
421 #[doc(alias = "preserve-on-down")]
422 pub fn set_preserve_on_down(&self, preserve_on_down: i32) {
423 ObjectExt::set_property(self, "preserve-on-down", preserve_on_down)
424 }
425
426 /// The total number of virtual functions to create.
427 ///
428 /// Note that when the sriov setting is present NetworkManager
429 /// enforces the number of virtual functions on the interface
430 /// (also when it is zero) during activation and resets it
431 /// upon deactivation. To prevent any changes to SR-IOV
432 /// parameters don't add a sriov setting to the connection.
433 #[cfg(feature = "v1_14")]
434 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
435 #[doc(alias = "total-vfs")]
436 pub fn set_total_vfs(&self, total_vfs: u32) {
437 ObjectExt::set_property(self, "total-vfs", total_vfs)
438 }
439
440 /// Array of virtual function descriptors.
441 ///
442 /// Each VF descriptor is a dictionary mapping attribute names
443 /// to GVariant values. The 'index' entry is mandatory for
444 /// each VF.
445 ///
446 /// When represented as string a VF is in the form:
447 ///
448 /// "INDEX [ATTR=VALUE[ ATTR=VALUE]...]".
449 ///
450 /// for example:
451 ///
452 /// "2 mac=00:11:22:33:44:55 spoof-check=true".
453 ///
454 /// Multiple VFs can be specified using a comma as separator.
455 /// Currently, the following attributes are supported: mac,
456 /// spoof-check, trust, min-tx-rate, max-tx-rate, vlans.
457 ///
458 /// The "vlans" attribute is represented as a semicolon-separated
459 /// list of VLAN descriptors, where each descriptor has the form
460 ///
461 /// "ID[.PRIORITY[.PROTO]]".
462 ///
463 /// PROTO can be either 'q' for 802.1Q (the default) or 'ad' for
464 /// 802.1ad.
465 #[cfg(feature = "v1_14")]
466 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
467 pub fn vfs(&self) -> Vec<SriovVF> {
468 let vals = ObjectExt::property::<glib::ValueArray>(self, "vfs");
469 vals.iter()
470 .map(|value| unsafe {
471 use glib::value::FromValue;
472
473 SriovVF::from_value(value)
474 })
475 .collect()
476 }
477
478 /// Array of virtual function descriptors.
479 ///
480 /// Each VF descriptor is a dictionary mapping attribute names
481 /// to GVariant values. The 'index' entry is mandatory for
482 /// each VF.
483 ///
484 /// When represented as string a VF is in the form:
485 ///
486 /// "INDEX [ATTR=VALUE[ ATTR=VALUE]...]".
487 ///
488 /// for example:
489 ///
490 /// "2 mac=00:11:22:33:44:55 spoof-check=true".
491 ///
492 /// Multiple VFs can be specified using a comma as separator.
493 /// Currently, the following attributes are supported: mac,
494 /// spoof-check, trust, min-tx-rate, max-tx-rate, vlans.
495 ///
496 /// The "vlans" attribute is represented as a semicolon-separated
497 /// list of VLAN descriptors, where each descriptor has the form
498 ///
499 /// "ID[.PRIORITY[.PROTO]]".
500 ///
501 /// PROTO can be either 'q' for 802.1Q (the default) or 'ad' for
502 /// 802.1ad.
503 #[cfg(feature = "v1_14")]
504 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
505 pub fn set_vfs(&self, vfs: &[&SriovVF]) {
506 ObjectExt::set_property(
507 self,
508 "vfs",
509 vfs.iter()
510 .map(|sriov_vf| sriov_vf.to_value())
511 .collect::<glib::ValueArray>(),
512 )
513 }
514
515 #[cfg(feature = "v1_14")]
516 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
517 #[doc(alias = "autoprobe-drivers")]
518 pub fn connect_autoprobe_drivers_notify<F: Fn(&Self) + 'static>(
519 &self,
520 f: F,
521 ) -> SignalHandlerId {
522 unsafe extern "C" fn notify_autoprobe_drivers_trampoline<F: Fn(&SettingSriov) + 'static>(
523 this: *mut ffi::NMSettingSriov,
524 _param_spec: glib::ffi::gpointer,
525 f: glib::ffi::gpointer,
526 ) {
527 let f: &F = &*(f as *const F);
528 f(&from_glib_borrow(this))
529 }
530 unsafe {
531 let f: Box_<F> = Box_::new(f);
532 connect_raw(
533 self.as_ptr() as *mut _,
534 c"notify::autoprobe-drivers".as_ptr() as *const _,
535 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
536 notify_autoprobe_drivers_trampoline::<F> as *const (),
537 )),
538 Box_::into_raw(f),
539 )
540 }
541 }
542
543 #[cfg(feature = "v1_46")]
544 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
545 #[doc(alias = "eswitch-encap-mode")]
546 pub fn connect_eswitch_encap_mode_notify<F: Fn(&Self) + 'static>(
547 &self,
548 f: F,
549 ) -> SignalHandlerId {
550 unsafe extern "C" fn notify_eswitch_encap_mode_trampoline<
551 F: Fn(&SettingSriov) + 'static,
552 >(
553 this: *mut ffi::NMSettingSriov,
554 _param_spec: glib::ffi::gpointer,
555 f: glib::ffi::gpointer,
556 ) {
557 let f: &F = &*(f as *const F);
558 f(&from_glib_borrow(this))
559 }
560 unsafe {
561 let f: Box_<F> = Box_::new(f);
562 connect_raw(
563 self.as_ptr() as *mut _,
564 c"notify::eswitch-encap-mode".as_ptr() as *const _,
565 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
566 notify_eswitch_encap_mode_trampoline::<F> as *const (),
567 )),
568 Box_::into_raw(f),
569 )
570 }
571 }
572
573 #[cfg(feature = "v1_46")]
574 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
575 #[doc(alias = "eswitch-inline-mode")]
576 pub fn connect_eswitch_inline_mode_notify<F: Fn(&Self) + 'static>(
577 &self,
578 f: F,
579 ) -> SignalHandlerId {
580 unsafe extern "C" fn notify_eswitch_inline_mode_trampoline<
581 F: Fn(&SettingSriov) + 'static,
582 >(
583 this: *mut ffi::NMSettingSriov,
584 _param_spec: glib::ffi::gpointer,
585 f: glib::ffi::gpointer,
586 ) {
587 let f: &F = &*(f as *const F);
588 f(&from_glib_borrow(this))
589 }
590 unsafe {
591 let f: Box_<F> = Box_::new(f);
592 connect_raw(
593 self.as_ptr() as *mut _,
594 c"notify::eswitch-inline-mode".as_ptr() as *const _,
595 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
596 notify_eswitch_inline_mode_trampoline::<F> as *const (),
597 )),
598 Box_::into_raw(f),
599 )
600 }
601 }
602
603 #[cfg(feature = "v1_46")]
604 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
605 #[doc(alias = "eswitch-mode")]
606 pub fn connect_eswitch_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
607 unsafe extern "C" fn notify_eswitch_mode_trampoline<F: Fn(&SettingSriov) + 'static>(
608 this: *mut ffi::NMSettingSriov,
609 _param_spec: glib::ffi::gpointer,
610 f: glib::ffi::gpointer,
611 ) {
612 let f: &F = &*(f as *const F);
613 f(&from_glib_borrow(this))
614 }
615 unsafe {
616 let f: Box_<F> = Box_::new(f);
617 connect_raw(
618 self.as_ptr() as *mut _,
619 c"notify::eswitch-mode".as_ptr() as *const _,
620 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
621 notify_eswitch_mode_trampoline::<F> as *const (),
622 )),
623 Box_::into_raw(f),
624 )
625 }
626 }
627
628 #[cfg(feature = "v1_54")]
629 #[cfg_attr(docsrs, doc(cfg(feature = "v1_54")))]
630 #[doc(alias = "preserve-on-down")]
631 pub fn connect_preserve_on_down_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
632 unsafe extern "C" fn notify_preserve_on_down_trampoline<F: Fn(&SettingSriov) + 'static>(
633 this: *mut ffi::NMSettingSriov,
634 _param_spec: glib::ffi::gpointer,
635 f: glib::ffi::gpointer,
636 ) {
637 let f: &F = &*(f as *const F);
638 f(&from_glib_borrow(this))
639 }
640 unsafe {
641 let f: Box_<F> = Box_::new(f);
642 connect_raw(
643 self.as_ptr() as *mut _,
644 c"notify::preserve-on-down".as_ptr() as *const _,
645 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
646 notify_preserve_on_down_trampoline::<F> as *const (),
647 )),
648 Box_::into_raw(f),
649 )
650 }
651 }
652
653 #[cfg(feature = "v1_14")]
654 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
655 #[doc(alias = "total-vfs")]
656 pub fn connect_total_vfs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
657 unsafe extern "C" fn notify_total_vfs_trampoline<F: Fn(&SettingSriov) + 'static>(
658 this: *mut ffi::NMSettingSriov,
659 _param_spec: glib::ffi::gpointer,
660 f: glib::ffi::gpointer,
661 ) {
662 let f: &F = &*(f as *const F);
663 f(&from_glib_borrow(this))
664 }
665 unsafe {
666 let f: Box_<F> = Box_::new(f);
667 connect_raw(
668 self.as_ptr() as *mut _,
669 c"notify::total-vfs".as_ptr() as *const _,
670 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
671 notify_total_vfs_trampoline::<F> as *const (),
672 )),
673 Box_::into_raw(f),
674 )
675 }
676 }
677
678 #[cfg(feature = "v1_14")]
679 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
680 #[doc(alias = "vfs")]
681 pub fn connect_vfs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
682 unsafe extern "C" fn notify_vfs_trampoline<F: Fn(&SettingSriov) + 'static>(
683 this: *mut ffi::NMSettingSriov,
684 _param_spec: glib::ffi::gpointer,
685 f: glib::ffi::gpointer,
686 ) {
687 let f: &F = &*(f as *const F);
688 f(&from_glib_borrow(this))
689 }
690 unsafe {
691 let f: Box_<F> = Box_::new(f);
692 connect_raw(
693 self.as_ptr() as *mut _,
694 c"notify::vfs".as_ptr() as *const _,
695 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
696 notify_vfs_trampoline::<F> as *const (),
697 )),
698 Box_::into_raw(f),
699 )
700 }
701 }
702}
703
704#[cfg(feature = "v1_14")]
705#[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
706impl Default for SettingSriov {
707 fn default() -> Self {
708 Self::new()
709 }
710}
711
712// rustdoc-stripper-ignore-next
713/// A [builder-pattern] type to construct [`SettingSriov`] objects.
714///
715/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
716#[must_use = "The builder must be built to be used"]
717pub struct SettingSriovBuilder {
718 builder: glib::object::ObjectBuilder<'static, SettingSriov>,
719}
720
721impl SettingSriovBuilder {
722 fn new() -> Self {
723 Self {
724 builder: glib::object::Object::builder(),
725 }
726 }
727
728 /// Whether to autoprobe virtual functions by a compatible driver.
729 ///
730 /// If set to [`Ternary::True`][crate::Ternary::True], the kernel will try to bind VFs to
731 /// a compatible driver and if this succeeds a new network
732 /// interface will be instantiated for each VF.
733 ///
734 /// If set to [`Ternary::False`][crate::Ternary::False], VFs will not be claimed and no
735 /// network interfaces will be created for them.
736 ///
737 /// When set to [`Ternary::Default`][crate::Ternary::Default], the global default is used; in
738 /// case the global default is unspecified it is assumed to be
739 /// [`Ternary::True`][crate::Ternary::True].
740 #[cfg(feature = "v1_14")]
741 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
742 pub fn autoprobe_drivers(self, autoprobe_drivers: Ternary) -> Self {
743 Self {
744 builder: self
745 .builder
746 .property("autoprobe-drivers", autoprobe_drivers),
747 }
748 }
749
750 /// Select the eswitch encapsulation support.
751 ///
752 /// Currently it's only supported for PCI PF devices, and only if the eswitch device
753 /// is managed from the same PCI address than the PF.
754 ///
755 /// If set to [`SriovEswitchEncapMode::Preserve`][crate::SriovEswitchEncapMode::Preserve] (default) the eswitch encap-mode
756 /// won't be modified by NetworkManager.
757 #[cfg(feature = "v1_46")]
758 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
759 pub fn eswitch_encap_mode(self, eswitch_encap_mode: i32) -> Self {
760 Self {
761 builder: self
762 .builder
763 .property("eswitch-encap-mode", eswitch_encap_mode),
764 }
765 }
766
767 /// Select the eswitch inline-mode of the device. Some HWs need the VF driver to put
768 /// part of the packet headers on the TX descriptor so the e-switch can do proper
769 /// matching and steering.
770 ///
771 /// Currently it's only supported for PCI PF devices, and only if the eswitch device
772 /// is managed from the same PCI address than the PF.
773 ///
774 /// If set to [`SriovEswitchInlineMode::Preserve`][crate::SriovEswitchInlineMode::Preserve] (default) the eswitch inline-mode
775 /// won't be modified by NetworkManager.
776 #[cfg(feature = "v1_46")]
777 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
778 pub fn eswitch_inline_mode(self, eswitch_inline_mode: i32) -> Self {
779 Self {
780 builder: self
781 .builder
782 .property("eswitch-inline-mode", eswitch_inline_mode),
783 }
784 }
785
786 /// Select the eswitch mode of the device. Currently it's only supported for
787 /// PCI PF devices, and only if the eswitch device is managed from the same
788 /// PCI address than the PF.
789 ///
790 /// If set to [`SriovEswitchMode::Preserve`][crate::SriovEswitchMode::Preserve] (default) the eswitch mode won't be
791 /// modified by NetworkManager.
792 #[cfg(feature = "v1_46")]
793 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
794 pub fn eswitch_mode(self, eswitch_mode: i32) -> Self {
795 Self {
796 builder: self.builder.property("eswitch-mode", eswitch_mode),
797 }
798 }
799
800 /// This controls whether NetworkManager preserves the SR-IOV parameters set on
801 /// the device when the connection is deactivated, or whether it resets them to
802 /// their default value. The SR-IOV parameters are those specified in this setting
803 /// (the "sriov" setting), like the number of VFs to create, the eswitch
804 /// configuration, etc.
805 ///
806 /// If set to [`SriovPreserveOnDown::No`][crate::SriovPreserveOnDown::No], NetworkManager resets the SR-IOV
807 /// parameters when the connection is deactivated. When set to
808 /// [`SriovPreserveOnDown::Yes`][crate::SriovPreserveOnDown::Yes], NetworkManager preserves those parameters
809 /// on the device. If the value is [`SriovPreserveOnDown::Default`][crate::SriovPreserveOnDown::Default], NetworkManager
810 /// looks up a global default value in the configuration; in case no such value is
811 /// defined, it uses [`SriovPreserveOnDown::No`][crate::SriovPreserveOnDown::No] as fallback.
812 #[cfg(feature = "v1_54")]
813 #[cfg_attr(docsrs, doc(cfg(feature = "v1_54")))]
814 pub fn preserve_on_down(self, preserve_on_down: i32) -> Self {
815 Self {
816 builder: self.builder.property("preserve-on-down", preserve_on_down),
817 }
818 }
819
820 /// The total number of virtual functions to create.
821 ///
822 /// Note that when the sriov setting is present NetworkManager
823 /// enforces the number of virtual functions on the interface
824 /// (also when it is zero) during activation and resets it
825 /// upon deactivation. To prevent any changes to SR-IOV
826 /// parameters don't add a sriov setting to the connection.
827 #[cfg(feature = "v1_14")]
828 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
829 pub fn total_vfs(self, total_vfs: u32) -> Self {
830 Self {
831 builder: self.builder.property("total-vfs", total_vfs),
832 }
833 }
834
835 /// Array of virtual function descriptors.
836 ///
837 /// Each VF descriptor is a dictionary mapping attribute names
838 /// to GVariant values. The 'index' entry is mandatory for
839 /// each VF.
840 ///
841 /// When represented as string a VF is in the form:
842 ///
843 /// "INDEX [ATTR=VALUE[ ATTR=VALUE]...]".
844 ///
845 /// for example:
846 ///
847 /// "2 mac=00:11:22:33:44:55 spoof-check=true".
848 ///
849 /// Multiple VFs can be specified using a comma as separator.
850 /// Currently, the following attributes are supported: mac,
851 /// spoof-check, trust, min-tx-rate, max-tx-rate, vlans.
852 ///
853 /// The "vlans" attribute is represented as a semicolon-separated
854 /// list of VLAN descriptors, where each descriptor has the form
855 ///
856 /// "ID[.PRIORITY[.PROTO]]".
857 ///
858 /// PROTO can be either 'q' for 802.1Q (the default) or 'ad' for
859 /// 802.1ad.
860 #[cfg(feature = "v1_14")]
861 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
862 pub fn vfs(self, vfs: &[&SriovVF]) -> Self {
863 Self {
864 builder: self.builder.property(
865 "vfs",
866 vfs.iter()
867 .map(|sriov_vf| sriov_vf.to_value())
868 .collect::<glib::ValueArray>(),
869 ),
870 }
871 }
872
873 // rustdoc-stripper-ignore-next
874 /// Build the [`SettingSriov`].
875 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
876 pub fn build(self) -> SettingSriov {
877 assert_initialized_main_thread!();
878 self.builder.build()
879 }
880}