rtnetlink/link/
bridge_port.rs

1// SPDX-License-Identifier: MIT
2
3use crate::{
4    packet_route::link::{
5        BridgeMulticastRouterType, BridgePortState, InfoBridgePort,
6        InfoPortData, InfoPortKind,
7    },
8    LinkMessageBuilder,
9};
10
11#[derive(Debug)]
12pub struct LinkBridgePort;
13
14impl LinkBridgePort {
15    pub fn new(port_index: u32) -> LinkMessageBuilder<Self> {
16        LinkMessageBuilder::<LinkBridgePort>::default()
17            .index(port_index)
18            .set_port_kind(InfoPortKind::Bridge)
19    }
20}
21
22impl LinkMessageBuilder<LinkBridgePort> {
23    /// Append arbitrary [InfoBridgePort]
24    pub fn append_info_data(self, info: InfoBridgePort) -> Self {
25        let mut ret = self;
26
27        if let InfoPortData::BridgePort(infos) = ret
28            .port_data
29            .get_or_insert_with(|| InfoPortData::BridgePort(Vec::new()))
30        {
31            infos.push(info);
32        }
33
34        ret
35    }
36
37    /// This is equivalent to
38    /// `ip link set name NAME type bridge_slave fdb_flush`.
39    pub fn fdb_flush(self) -> Self {
40        self.append_info_data(InfoBridgePort::Flush)
41    }
42
43    /// This is equivalent to
44    /// `ip link set name NAME type bridge_slave state STATE`.
45    pub fn state(self, v: BridgePortState) -> Self {
46        self.append_info_data(InfoBridgePort::State(v))
47    }
48
49    /// This is equivalent to
50    /// `ip link set name NAME type bridge_slave priority PRIO`.
51    pub fn priority(self, v: u16) -> Self {
52        self.append_info_data(InfoBridgePort::Priority(v))
53    }
54
55    /// This is equivalent to
56    /// `ip link set name NAME type bridge_slave cost COST`.
57    pub fn cost(self, v: u32) -> Self {
58        self.append_info_data(InfoBridgePort::Cost(v))
59    }
60
61    /// This is equivalent to
62    /// `ip link set name NAME type bridge_slave guard { on | off }`.
63    pub fn guard(self, v: bool) -> Self {
64        self.append_info_data(InfoBridgePort::Guard(v))
65    }
66
67    /// This is equivalent to
68    /// `ip link set name NAME type bridge_slave hairpin { on | off }`.
69    pub fn hairpin(self, v: bool) -> Self {
70        self.append_info_data(InfoBridgePort::HairpinMode(v))
71    }
72
73    /// This is equivalent to
74    /// `ip link set name NAME type bridge_slave root_block { on | off }`.
75    pub fn root_block(self, v: bool) -> Self {
76        self.append_info_data(InfoBridgePort::Protect(v))
77    }
78
79    /// This is equivalent to
80    /// `ip link set name NAME type bridge_slave learning { on | off }`.
81    pub fn learning(self, v: bool) -> Self {
82        self.append_info_data(InfoBridgePort::Learning(v))
83    }
84
85    /// This is equivalent to
86    /// `ip link set name NAME type bridge_slave flood { on | off }`.
87    pub fn flood(self, v: bool) -> Self {
88        self.append_info_data(InfoBridgePort::UnicastFlood(v))
89    }
90
91    /// This is equivalent to
92    /// `ip link set name NAME type bridge_slave proxy_arp { on | off }`.
93    pub fn proxy_arp(self, v: bool) -> Self {
94        self.append_info_data(InfoBridgePort::ProxyARP(v))
95    }
96
97    /// This is equivalent to
98    /// `ip link set name NAME type bridge_slave proxy_arp_wifi { on | off }`.
99    pub fn proxy_arp_wifi(self, v: bool) -> Self {
100        self.append_info_data(InfoBridgePort::ProxyARPWifi(v))
101    }
102
103    /// This is equivalent to
104    /// `ip link set name NAME type bridge_slave mcast_router MULTICAST_ROUTER`.
105    pub fn mcast_router(self, v: BridgeMulticastRouterType) -> Self {
106        self.append_info_data(InfoBridgePort::MulticastRouter(v))
107    }
108
109    /// This is equivalent to
110    /// `ip link set name NAME type bridge_slave mcast_fast_leave { on | off }`.
111    /// and
112    /// `ip link set name NAME type bridge_slave fastleave { on | off }`.
113    pub fn mcast_fast_leave(self, v: bool) -> Self {
114        self.append_info_data(InfoBridgePort::FastLeave(v))
115    }
116
117    /// This is equivalent to
118    /// `ip link set name NAME type bridge_slave bcast_flood { on | off }`.
119    pub fn bcast_flood(self, v: bool) -> Self {
120        self.append_info_data(InfoBridgePort::BroadcastFlood(v))
121    }
122
123    /// This is equivalent to
124    /// `ip link set name NAME type bridge_slave mcast_flood { on | off }`.
125    pub fn mcast_flood(self, v: bool) -> Self {
126        self.append_info_data(InfoBridgePort::MulticastFlood(v))
127    }
128
129    /// This is equivalent to
130    /// `ip link set name NAME type bridge_slave mcast_to_unicast { on | off }`.
131    pub fn mcast_to_unicast(self, v: bool) -> Self {
132        self.append_info_data(InfoBridgePort::MulticastToUnicast(v))
133    }
134
135    /// This is equivalent to
136    /// `ip link set name NAME type bridge_slave group_fwd_mask MASK`.
137    pub fn group_fwd_mask(self, v: u16) -> Self {
138        self.append_info_data(InfoBridgePort::GroupFwdMask(v))
139    }
140
141    /// This is equivalent to
142    /// `ip link set name NAME type bridge_slave neigh_suppress { on | off }`.
143    pub fn neigh_suppress(self, v: bool) -> Self {
144        self.append_info_data(InfoBridgePort::NeighSupress(v))
145    }
146
147    /// This is equivalent to
148    /// `ip link set name NAME type bridge_slave \
149    ///     neigh_vlan_suppress { on | off }`.
150    pub fn neigh_vlan_suppress(self, v: bool) -> Self {
151        self.append_info_data(InfoBridgePort::NeighVlanSupress(v))
152    }
153
154    /// This is equivalent to
155    /// `ip link set name NAME type bridge_slave vlan_tunnel { on | off }`.
156    pub fn vlan_tunnel(self, v: bool) -> Self {
157        self.append_info_data(InfoBridgePort::VlanTunnel(v))
158    }
159
160    /// This is equivalent to
161    /// `ip link set name NAME type bridge_slave isolated { on | off }`.
162    pub fn isolated(self, v: bool) -> Self {
163        self.append_info_data(InfoBridgePort::Isolated(v))
164    }
165
166    /// This is equivalent to
167    /// `ip link set name NAME type bridge_slave locked { on | off }`.
168    pub fn locked(self, v: bool) -> Self {
169        self.append_info_data(InfoBridgePort::Locked(v))
170    }
171
172    /// This is equivalent to
173    /// `ip link set name NAME type bridge_slave mab { on | off }`.
174    pub fn mab(self, v: bool) -> Self {
175        self.append_info_data(InfoBridgePort::Mab(v))
176    }
177
178    /// This is equivalent to
179    /// `ip link set name NAME type bridge_slave backup_port DEVICE`
180    /// but only accept interface index. Setting to 0 equal to
181    /// `Self::nobackup_port()`.
182    pub fn backup_port(self, iface_index: u32) -> Self {
183        self.append_info_data(InfoBridgePort::BackupPort(iface_index))
184    }
185
186    /// This is equivalent to
187    /// `ip link set name NAME type bridge_slave nobackup_port`
188    pub fn nobackup_port(self) -> Self {
189        self.append_info_data(InfoBridgePort::BackupPort(0))
190    }
191
192    /// This is equivalent to
193    /// `ip link set name NAME type bridge_slave backup_nhid NHID`
194    pub fn backup_nhid(self, v: u32) -> Self {
195        self.append_info_data(InfoBridgePort::BackupNextHopId(v))
196    }
197}