rtnetlink/link/
bond_port.rs

1// SPDX-License-Identifier: MIT
2
3use crate::{
4    packet_route::link::{InfoBondPort, InfoPortData, InfoPortKind},
5    LinkMessageBuilder,
6};
7
8#[derive(Debug)]
9pub struct LinkBondPort;
10
11impl LinkBondPort {
12    pub fn new(port_index: u32) -> LinkMessageBuilder<Self> {
13        LinkMessageBuilder::<LinkBondPort>::default()
14            .index(port_index)
15            .set_port_kind(InfoPortKind::Bond)
16    }
17}
18
19impl LinkMessageBuilder<LinkBondPort> {
20    /// Append arbitrary [InfoBondPort]
21    pub fn append_info_data(self, info: InfoBondPort) -> Self {
22        let mut ret = self;
23
24        if let InfoPortData::BondPort(infos) = ret
25            .port_data
26            .get_or_insert_with(|| InfoPortData::BondPort(Vec::new()))
27        {
28            infos.push(info);
29        }
30
31        ret
32    }
33
34    /// Adds the `queue_id` attribute to the bond port
35    /// This is equivalent to
36    /// `ip link set name NAME type bond_slave queue_id QUEUE_ID`.
37    pub fn queue_id(self, queue_id: u16) -> Self {
38        self.append_info_data(InfoBondPort::QueueId(queue_id))
39    }
40
41    /// Adds the `prio` attribute to the bond port
42    /// This is equivalent to `ip link set name NAME type bond_slave prio PRIO`.
43    pub fn prio(self, prio: i32) -> Self {
44        self.append_info_data(InfoBondPort::Prio(prio))
45    }
46}