rtnetlink/link/
bridge_port.rs1use 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 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 pub fn fdb_flush(self) -> Self {
40 self.append_info_data(InfoBridgePort::Flush)
41 }
42
43 pub fn state(self, v: BridgePortState) -> Self {
46 self.append_info_data(InfoBridgePort::State(v))
47 }
48
49 pub fn priority(self, v: u16) -> Self {
52 self.append_info_data(InfoBridgePort::Priority(v))
53 }
54
55 pub fn cost(self, v: u32) -> Self {
58 self.append_info_data(InfoBridgePort::Cost(v))
59 }
60
61 pub fn guard(self, v: bool) -> Self {
64 self.append_info_data(InfoBridgePort::Guard(v))
65 }
66
67 pub fn hairpin(self, v: bool) -> Self {
70 self.append_info_data(InfoBridgePort::HairpinMode(v))
71 }
72
73 pub fn root_block(self, v: bool) -> Self {
76 self.append_info_data(InfoBridgePort::Protect(v))
77 }
78
79 pub fn learning(self, v: bool) -> Self {
82 self.append_info_data(InfoBridgePort::Learning(v))
83 }
84
85 pub fn flood(self, v: bool) -> Self {
88 self.append_info_data(InfoBridgePort::UnicastFlood(v))
89 }
90
91 pub fn proxy_arp(self, v: bool) -> Self {
94 self.append_info_data(InfoBridgePort::ProxyARP(v))
95 }
96
97 pub fn proxy_arp_wifi(self, v: bool) -> Self {
100 self.append_info_data(InfoBridgePort::ProxyARPWifi(v))
101 }
102
103 pub fn mcast_router(self, v: BridgeMulticastRouterType) -> Self {
106 self.append_info_data(InfoBridgePort::MulticastRouter(v))
107 }
108
109 pub fn mcast_fast_leave(self, v: bool) -> Self {
114 self.append_info_data(InfoBridgePort::FastLeave(v))
115 }
116
117 pub fn bcast_flood(self, v: bool) -> Self {
120 self.append_info_data(InfoBridgePort::BroadcastFlood(v))
121 }
122
123 pub fn mcast_flood(self, v: bool) -> Self {
126 self.append_info_data(InfoBridgePort::MulticastFlood(v))
127 }
128
129 pub fn mcast_to_unicast(self, v: bool) -> Self {
132 self.append_info_data(InfoBridgePort::MulticastToUnicast(v))
133 }
134
135 pub fn group_fwd_mask(self, v: u16) -> Self {
138 self.append_info_data(InfoBridgePort::GroupFwdMask(v))
139 }
140
141 pub fn neigh_suppress(self, v: bool) -> Self {
144 self.append_info_data(InfoBridgePort::NeighSupress(v))
145 }
146
147 pub fn neigh_vlan_suppress(self, v: bool) -> Self {
151 self.append_info_data(InfoBridgePort::NeighVlanSupress(v))
152 }
153
154 pub fn vlan_tunnel(self, v: bool) -> Self {
157 self.append_info_data(InfoBridgePort::VlanTunnel(v))
158 }
159
160 pub fn isolated(self, v: bool) -> Self {
163 self.append_info_data(InfoBridgePort::Isolated(v))
164 }
165
166 pub fn locked(self, v: bool) -> Self {
169 self.append_info_data(InfoBridgePort::Locked(v))
170 }
171
172 pub fn mab(self, v: bool) -> Self {
175 self.append_info_data(InfoBridgePort::Mab(v))
176 }
177
178 pub fn backup_port(self, iface_index: u32) -> Self {
183 self.append_info_data(InfoBridgePort::BackupPort(iface_index))
184 }
185
186 pub fn nobackup_port(self) -> Self {
189 self.append_info_data(InfoBridgePort::BackupPort(0))
190 }
191
192 pub fn backup_nhid(self, v: u32) -> Self {
195 self.append_info_data(InfoBridgePort::BackupNextHopId(v))
196 }
197}