netplan_types/netplan/device_types/
bonds.rs

1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4#[cfg(feature = "derive_builder")]
5use derive_builder::Builder;
6
7use crate::CommonPropertiesAllDevices;
8
9#[derive(Default, Debug, Clone, PartialEq, Eq)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11#[cfg_attr(feature = "derive_builder", derive(Builder))]
12#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
13#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
14pub struct BondConfig {
15    /// All devices matching this ID list will be added to the bond.
16    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
17    pub interfaces: Option<Vec<String>>,
18    /// Customization parameters for special bonding options. Time intervals
19    /// may need to be expressed as a number of seconds or milliseconds: the
20    /// default value type is specified below. If necessary, time intervals can
21    /// be qualified using a time suffix (such as “s” for seconds, “ms” for
22    /// milliseconds) to allow for more control over its behavior.
23    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
24    pub parameters: Option<BondParameters>,
25    /// Common properties for all devices
26    #[cfg_attr(feature = "serde", serde(flatten))]
27    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
28    pub common_all: Option<CommonPropertiesAllDevices>,
29}
30
31#[derive(Default, Debug, Clone, PartialEq, Eq)]
32#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
33#[cfg_attr(feature = "derive_builder", derive(Builder))]
34#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
35#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
36pub struct BondParameters {
37    /// Set the bonding mode used for the interfaces. The default is
38    /// balance-rr (round robin). Possible values are balance-rr,
39    /// active-backup, balance-xor, broadcast, 802.3ad,
40    /// balance-tlb, and balance-alb.
41    /// For OpenVSwitch active-backup and the additional modes
42    /// balance-tcp and balance-slb are supported.
43    /// #[serde(skip_serializing_if = "Option
44    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
45    pub mode: Option<BondMode>,
46    /// Set the rate at which LACPDUs are transmitted. This is only useful
47    /// in 802.3ad mode. Possible values are slow (30 seconds, default),
48    /// and fast (every second).
49    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
50    pub lacp_rate: Option<LacpRate>,
51    /// Specifies the interval for MII monitoring (verifying if an interface
52    /// of the bond has carrier). The default is 0; which disables MII
53    /// monitoring. This is equivalent to the MIIMonitorSec= field for the
54    /// networkd backend. If no time suffix is specified, the value will be
55    /// interpreted as milliseconds.
56    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
57    pub mii_monitor_interval: Option<String>,
58    /// The minimum number of links up in a bond to consider the bond
59    /// interface to be up.
60    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
61    pub min_links: Option<u16>,
62    /// Specifies the transmit hash policy for the selection of slaves. This
63    /// is only useful in balance-xor, 802.3ad and balance-tlb modes.
64    /// Possible values are layer2, layer3+4, layer2+3,
65    /// encap2+3, and encap3+4.
66    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
67    pub transmit_hash_policy: Option<TransmitHashPolicy>,
68    /// Set the aggregation selection mode. Possible values are stable,
69    /// bandwidth, and count. This option is only used in 802.3ad
70    /// mode.
71    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
72    pub ad_select: Option<AdSelect>,
73    /// If the bond should drop duplicate frames received on inactive ports,
74    /// set this option to false. If they should be delivered, set this
75    /// option to true. The default value is false, and is the desirable
76    /// behavior in most situations.
77    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
78    #[cfg_attr(feature = "serde", serde(default))]
79    #[cfg_attr(
80        feature = "serde",
81        serde(deserialize_with = "crate::bool::string_or_bool_option")
82    )]
83    pub all_slaves_active: Option<bool>,
84    /// Set the interval value for how frequently ARP link monitoring should
85    /// happen. The default value is 0, which disables ARP monitoring.
86    /// For the networkd backend, this maps to the ARPIntervalSec= property.
87    /// If no time suffix is specified, the value will be interpreted as
88    /// milliseconds.
89    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
90    pub arp_interval: Option<String>,
91    /// IPs of other hosts on the link which should be sent ARP requests in
92    /// order to validate that a slave is up. This option is only used when
93    /// arp-interval is set to a value other than 0. At least one IP
94    /// address must be given for ARP link monitoring to function. Only IPv4
95    /// addresses are supported. You can specify up to 16 IP addresses. The
96    /// default value is an empty list.
97    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
98    pub arp_ip_targets: Option<Vec<String>>,
99    /// Configure how ARP replies are to be validated when using ARP link
100    /// monitoring. Possible values are none, active, backup,
101    /// and all.
102    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
103    pub arp_validate: Option<ArpValidate>,
104    /// Specify whether to use any ARP IP target being up as sufficient for
105    /// a slave to be considered up; or if all the targets must be up. This
106    /// is only used for active-backup mode when arp-validate is
107    /// enabled. Possible values are any and all.
108    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
109    pub arp_all_targets: Option<ArpAllTargets>,
110    /// Specify the delay before enabling a link once the link is physically
111    /// up. The default value is 0. This maps to the UpDelaySec= property
112    /// for the networkd renderer. This option is only valid for the miimon
113    /// link monitor. If no time suffix is specified, the value will be
114    /// interpreted as milliseconds.
115    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
116    pub up_delay: Option<String>,
117    /// Specify the delay before disabling a link once the link has been
118    /// lost. The default value is 0. This maps to the DownDelaySec=
119    /// property for the networkd renderer. This option is only valid for the
120    /// miimon link monitor. If no time suffix is specified, the value will
121    /// be interpreted as milliseconds.
122    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
123    pub down_delay: Option<String>,
124    /// Set whether to set all slaves to the same MAC address when adding
125    /// them to the bond, or how else the system should handle MAC addresses.
126    /// The possible values are none, active, and follow.
127    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
128    pub fail_over_mac_policy: Option<FailOverMacPolicy>,
129    /// Specify how many ARP packets to send after failover. Once a link is
130    /// up on a new slave, a notification is sent and possibly repeated if
131    /// this value is set to a number greater than 1. The default value
132    /// is 1 and valid values are between 1 and 255. This only
133    /// affects active-backup mode.
134    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
135    pub gratuitous_arp: Option<u8>,
136    /// In balance-rr mode, specifies the number of packets to transmit
137    /// on a slave before switching to the next. When this value is set to
138    /// 0, slaves are chosen at random. Allowable values are between
139    /// 0 and 65535. The default value is 1. This setting is
140    /// only used in balance-rr mode.
141    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
142    pub packets_per_slave: Option<u32>,
143    /// Set the reselection policy for the primary slave. On failure of the
144    /// active slave, the system will use this policy to decide how the new
145    /// active slave will be chosen and how recovery will be handled. The
146    /// possible values are always, better, and failure.
147    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
148    pub primary_reselect_policy: Option<PrimaryReselectPolicy>,
149    /// In modes balance-rr, active-backup, balance-tlb and
150    /// balance-alb, a failover can switch IGMP traffic from one
151    /// slave to another.
152    ///
153    /// This parameter specifies how many IGMP membership reports
154    /// are issued on a failover event. Values range from 0 to 255. 0
155    /// disables sending membership reports. Otherwise, the first
156    /// membership report is sent on failover and subsequent reports
157    /// are sent at 200ms intervals.
158    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
159    pub resend_igmp: Option<u8>,
160    /// Specify the interval between sending learning packets to
161    /// each slave. The value range is between 1 and 0x7fffffff.
162    /// The default value is 1. This option only affects balance-tlb
163    /// and balance-alb modes. Using the networkd renderer, this field
164    /// maps to the LearnPacketIntervalSec= property. If no time suffix is
165    /// specified, the value will be interpreted as seconds.
166    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
167    pub learn_packet_interval: Option<String>,
168    /// Specify a device to be used as a primary slave, or preferred device
169    /// to use as a slave for the bond (ie. the preferred device to send
170    /// data through), whenever it is available. This only affects
171    /// active-backup, balance-alb, and balance-tlb modes.
172    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
173    pub primary: Option<String>,
174}
175
176/// Set the bonding mode used for the interfaces. The default is
177/// balance-rr (round robin). Possible values are balance-rr,
178/// active-backup, balance-xor, broadcast, 802.3ad,
179/// balance-tlb, and balance-alb.
180/// For OpenVSwitch active-backup and the additional modes
181/// balance-tcp and balance-slb are supported.
182#[derive(Debug, Clone, PartialEq, Eq)]
183#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
184#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
185pub enum BondMode {
186    #[cfg_attr(feature = "serde", serde(rename = "balance-rr"))]
187    BalanceRr,
188    #[cfg_attr(feature = "serde", serde(rename = "active-backup"))]
189    ActiveBackup,
190    #[cfg_attr(feature = "serde", serde(rename = "balance-xor"))]
191    BalanceXor,
192    #[cfg_attr(feature = "serde", serde(rename = "broadcast"))]
193    Broadcast,
194    /// 802.3ad
195    #[cfg_attr(feature = "serde", serde(rename = "802.3ad"))]
196    EightZeroTwoDotThreeAD,
197    #[cfg_attr(feature = "serde", serde(rename = "balance-tlb"))]
198    BalanceTlb,
199    #[cfg_attr(feature = "serde", serde(rename = "balance-alb"))]
200    BalanceAlb,
201}
202
203/// Set the rate at which LACPDUs are transmitted. This is only useful
204/// in 802.3ad mode. Possible values are slow (30 seconds, default),
205/// and fast (every second).
206#[derive(Debug, Clone, PartialEq, Eq)]
207#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
208#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
209pub enum LacpRate {
210    #[cfg_attr(feature = "serde", serde(rename = "slow"))]
211    Slow,
212    #[cfg_attr(feature = "serde", serde(rename = "fast"))]
213    Fast,
214}
215
216/// Specifies the transmit hash policy for the selection of slaves. This
217/// is only useful in balance-xor, 802.3ad and balance-tlb modes.
218/// Possible values are layer2, layer3+4, layer2+3,
219/// encap2+3, and encap3+4.
220#[derive(Debug, Clone, PartialEq, Eq)]
221#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
222#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
223pub enum TransmitHashPolicy {
224    #[cfg_attr(feature = "serde", serde(rename = "layer2"))]
225    Layer2,
226    #[cfg_attr(feature = "serde", serde(rename = "layer3+4"))]
227    Layer3Plus4,
228    #[cfg_attr(feature = "serde", serde(rename = "layer2+3"))]
229    Layer2Plus3,
230    #[cfg_attr(feature = "serde", serde(rename = "encap2+3"))]
231    Encap2Plus3,
232    #[cfg_attr(feature = "serde", serde(rename = "encap3+4"))]
233    Encap3Plus4,
234}
235
236/// Set the aggregation selection mode. Possible values are stable,
237/// bandwidth, and count. This option is only used in 802.3ad
238/// mode.
239#[derive(Debug, Clone, PartialEq, Eq)]
240#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
241#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
242pub enum AdSelect {
243    #[cfg_attr(feature = "serde", serde(rename = "stable"))]
244    Stable,
245    #[cfg_attr(feature = "serde", serde(rename = "bandwidth"))]
246    Bandwidth,
247    #[cfg_attr(feature = "serde", serde(rename = "count"))]
248    Count,
249}
250
251/// Configure how ARP replies are to be validated when using ARP link
252/// monitoring. Possible values are none, active, backup,
253/// and all.
254#[derive(Debug, Clone, PartialEq, Eq)]
255#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
256#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
257pub enum ArpValidate {
258    #[cfg_attr(feature = "serde", serde(rename = "none"))]
259    None,
260    #[cfg_attr(feature = "serde", serde(rename = "active"))]
261    Active,
262    #[cfg_attr(feature = "serde", serde(rename = "backup"))]
263    Backup,
264    #[cfg_attr(feature = "serde", serde(rename = "all"))]
265    All,
266}
267
268/// Specify whether to use any ARP IP target being up as sufficient for
269/// a slave to be considered up; or if all the targets must be up. This
270/// is only used for active-backup mode when arp-validate is
271/// enabled. Possible values are any and all.
272#[derive(Debug, Clone, PartialEq, Eq)]
273#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
274#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
275pub enum ArpAllTargets {
276    #[cfg_attr(feature = "serde", serde(rename = "any"))]
277    Any,
278    #[cfg_attr(feature = "serde", serde(rename = "all"))]
279    All,
280}
281
282/// Set whether to set all slaves to the same MAC address when adding
283/// them to the bond, or how else the system should handle MAC addresses.
284/// The possible values are none, active, and follow.
285#[derive(Debug, Clone, PartialEq, Eq)]
286#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
287#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
288pub enum FailOverMacPolicy {
289    #[cfg_attr(feature = "serde", serde(rename = "none"))]
290    None,
291    #[cfg_attr(feature = "serde", serde(rename = "activv"))]
292    Active,
293    #[cfg_attr(feature = "serde", serde(rename = "follow"))]
294    Follow,
295}
296
297/// Set the reselection policy for the primary slave. On failure of the
298/// active slave, the system will use this policy to decide how the new
299/// active slave will be chosen and how recovery will be handled. The
300/// possible values are always, better, and failure.
301#[derive(Debug, Clone, PartialEq, Eq)]
302#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
303#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
304pub enum PrimaryReselectPolicy {
305    #[cfg_attr(feature = "serde", serde(rename = "always"))]
306    Always,
307    #[cfg_attr(feature = "serde", serde(rename = "better"))]
308    Better,
309    #[cfg_attr(feature = "serde", serde(rename = "failure"))]
310    Failure,
311}