1#![doc = "Link configuration over rtnetlink."]
2#![allow(clippy::all)]
3#![allow(unused_imports)]
4#![allow(unused_assignments)]
5#![allow(non_snake_case)]
6#![allow(unused_variables)]
7#![allow(irrefutable_let_patterns)]
8#![allow(unreachable_code)]
9#![allow(unreachable_patterns)]
10use crate::builtin::{PushBuiltinBitfield32, PushBuiltinNfgenmsg, PushDummy, PushNlmsghdr};
11use crate::{
12 consts,
13 traits::{NetlinkRequest, Protocol},
14 utils::*,
15};
16pub const PROTONAME: &CStr = c"rt-link";
17pub const PROTONUM: u16 = 0u16;
18#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
19#[derive(Debug, Clone, Copy)]
20pub enum IfinfoFlags {
21 Up = 1 << 0,
22 Broadcast = 1 << 1,
23 Debug = 1 << 2,
24 Loopback = 1 << 3,
25 PointToPoint = 1 << 4,
26 NoTrailers = 1 << 5,
27 Running = 1 << 6,
28 NoArp = 1 << 7,
29 Promisc = 1 << 8,
30 AllMulti = 1 << 9,
31 Master = 1 << 10,
32 Slave = 1 << 11,
33 Multicast = 1 << 12,
34 Portsel = 1 << 13,
35 AutoMedia = 1 << 14,
36 Dynamic = 1 << 15,
37 LowerUp = 1 << 16,
38 Dormant = 1 << 17,
39 Echo = 1 << 18,
40}
41impl IfinfoFlags {
42 pub fn from_value(value: u64) -> Option<Self> {
43 Some(match value {
44 n if n == 1 << 0 => Self::Up,
45 n if n == 1 << 1 => Self::Broadcast,
46 n if n == 1 << 2 => Self::Debug,
47 n if n == 1 << 3 => Self::Loopback,
48 n if n == 1 << 4 => Self::PointToPoint,
49 n if n == 1 << 5 => Self::NoTrailers,
50 n if n == 1 << 6 => Self::Running,
51 n if n == 1 << 7 => Self::NoArp,
52 n if n == 1 << 8 => Self::Promisc,
53 n if n == 1 << 9 => Self::AllMulti,
54 n if n == 1 << 10 => Self::Master,
55 n if n == 1 << 11 => Self::Slave,
56 n if n == 1 << 12 => Self::Multicast,
57 n if n == 1 << 13 => Self::Portsel,
58 n if n == 1 << 14 => Self::AutoMedia,
59 n if n == 1 << 15 => Self::Dynamic,
60 n if n == 1 << 16 => Self::LowerUp,
61 n if n == 1 << 17 => Self::Dormant,
62 n if n == 1 << 18 => Self::Echo,
63 _ => return None,
64 })
65 }
66}
67#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
68#[derive(Debug, Clone, Copy)]
69pub enum VlanProtocols {
70 _8021q = 33024,
71 _8021ad = 34984,
72}
73impl VlanProtocols {
74 pub fn from_value(value: u64) -> Option<Self> {
75 Some(match value {
76 33024 => Self::_8021q,
77 34984 => Self::_8021ad,
78 _ => return None,
79 })
80 }
81}
82#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
83#[derive(Debug, Clone, Copy)]
84pub enum Ipv4Devconf {
85 Forwarding = 0,
86 McForwarding = 1,
87 ProxyArp = 2,
88 AcceptRedirects = 3,
89 SecureRedirects = 4,
90 SendRedirects = 5,
91 SharedMedia = 6,
92 RpFilter = 7,
93 AcceptSourceRoute = 8,
94 BootpRelay = 9,
95 LogMartians = 10,
96 Tag = 11,
97 Arpfilter = 12,
98 MediumId = 13,
99 Noxfrm = 14,
100 Nopolicy = 15,
101 ForceIgmpVersion = 16,
102 ArpAnnounce = 17,
103 ArpIgnore = 18,
104 PromoteSecondaries = 19,
105 ArpAccept = 20,
106 ArpNotify = 21,
107 AcceptLocal = 22,
108 SrcVmark = 23,
109 ProxyArpPvlan = 24,
110 RouteLocalnet = 25,
111 Igmpv2UnsolicitedReportInterval = 26,
112 Igmpv3UnsolicitedReportInterval = 27,
113 IgnoreRoutesWithLinkdown = 28,
114 DropUnicastInL2Multicast = 29,
115 DropGratuitousArp = 30,
116 BcForwarding = 31,
117 ArpEvictNocarrier = 32,
118}
119impl Ipv4Devconf {
120 pub fn from_value(value: u64) -> Option<Self> {
121 Some(match value {
122 0 => Self::Forwarding,
123 1 => Self::McForwarding,
124 2 => Self::ProxyArp,
125 3 => Self::AcceptRedirects,
126 4 => Self::SecureRedirects,
127 5 => Self::SendRedirects,
128 6 => Self::SharedMedia,
129 7 => Self::RpFilter,
130 8 => Self::AcceptSourceRoute,
131 9 => Self::BootpRelay,
132 10 => Self::LogMartians,
133 11 => Self::Tag,
134 12 => Self::Arpfilter,
135 13 => Self::MediumId,
136 14 => Self::Noxfrm,
137 15 => Self::Nopolicy,
138 16 => Self::ForceIgmpVersion,
139 17 => Self::ArpAnnounce,
140 18 => Self::ArpIgnore,
141 19 => Self::PromoteSecondaries,
142 20 => Self::ArpAccept,
143 21 => Self::ArpNotify,
144 22 => Self::AcceptLocal,
145 23 => Self::SrcVmark,
146 24 => Self::ProxyArpPvlan,
147 25 => Self::RouteLocalnet,
148 26 => Self::Igmpv2UnsolicitedReportInterval,
149 27 => Self::Igmpv3UnsolicitedReportInterval,
150 28 => Self::IgnoreRoutesWithLinkdown,
151 29 => Self::DropUnicastInL2Multicast,
152 30 => Self::DropGratuitousArp,
153 31 => Self::BcForwarding,
154 32 => Self::ArpEvictNocarrier,
155 _ => return None,
156 })
157 }
158}
159#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
160#[derive(Debug, Clone, Copy)]
161pub enum Ipv6Devconf {
162 Forwarding = 0,
163 Hoplimit = 1,
164 Mtu6 = 2,
165 AcceptRa = 3,
166 AcceptRedirects = 4,
167 Autoconf = 5,
168 DadTransmits = 6,
169 RtrSolicits = 7,
170 RtrSolicitInterval = 8,
171 RtrSolicitDelay = 9,
172 UseTempaddr = 10,
173 TempValidLft = 11,
174 TempPreferedLft = 12,
175 RegenMaxRetry = 13,
176 MaxDesyncFactor = 14,
177 MaxAddresses = 15,
178 ForceMldVersion = 16,
179 AcceptRaDefrtr = 17,
180 AcceptRaPinfo = 18,
181 AcceptRaRtrPref = 19,
182 RtrProbeInterval = 20,
183 AcceptRaRtInfoMaxPlen = 21,
184 ProxyNdp = 22,
185 OptimisticDad = 23,
186 AcceptSourceRoute = 24,
187 McForwarding = 25,
188 DisableIpv6 = 26,
189 AcceptDad = 27,
190 ForceTllao = 28,
191 NdiscNotify = 29,
192 Mldv1UnsolicitedReportInterval = 30,
193 Mldv2UnsolicitedReportInterval = 31,
194 SuppressFragNdisc = 32,
195 AcceptRaFromLocal = 33,
196 UseOptimistic = 34,
197 AcceptRaMtu = 35,
198 StableSecret = 36,
199 UseOifAddrsOnly = 37,
200 AcceptRaMinHopLimit = 38,
201 IgnoreRoutesWithLinkdown = 39,
202 DropUnicastInL2Multicast = 40,
203 DropUnsolicitedNa = 41,
204 KeepAddrOnDown = 42,
205 RtrSolicitMaxInterval = 43,
206 Seg6Enabled = 44,
207 Seg6RequireHmac = 45,
208 EnhancedDad = 46,
209 AddrGenMode = 47,
210 DisablePolicy = 48,
211 AcceptRaRtInfoMinPlen = 49,
212 NdiscTclass = 50,
213 RplSegEnabled = 51,
214 RaDefrtrMetric = 52,
215 Ioam6Enabled = 53,
216 Ioam6Id = 54,
217 Ioam6IdWide = 55,
218 NdiscEvictNocarrier = 56,
219 AcceptUntrackedNa = 57,
220}
221impl Ipv6Devconf {
222 pub fn from_value(value: u64) -> Option<Self> {
223 Some(match value {
224 0 => Self::Forwarding,
225 1 => Self::Hoplimit,
226 2 => Self::Mtu6,
227 3 => Self::AcceptRa,
228 4 => Self::AcceptRedirects,
229 5 => Self::Autoconf,
230 6 => Self::DadTransmits,
231 7 => Self::RtrSolicits,
232 8 => Self::RtrSolicitInterval,
233 9 => Self::RtrSolicitDelay,
234 10 => Self::UseTempaddr,
235 11 => Self::TempValidLft,
236 12 => Self::TempPreferedLft,
237 13 => Self::RegenMaxRetry,
238 14 => Self::MaxDesyncFactor,
239 15 => Self::MaxAddresses,
240 16 => Self::ForceMldVersion,
241 17 => Self::AcceptRaDefrtr,
242 18 => Self::AcceptRaPinfo,
243 19 => Self::AcceptRaRtrPref,
244 20 => Self::RtrProbeInterval,
245 21 => Self::AcceptRaRtInfoMaxPlen,
246 22 => Self::ProxyNdp,
247 23 => Self::OptimisticDad,
248 24 => Self::AcceptSourceRoute,
249 25 => Self::McForwarding,
250 26 => Self::DisableIpv6,
251 27 => Self::AcceptDad,
252 28 => Self::ForceTllao,
253 29 => Self::NdiscNotify,
254 30 => Self::Mldv1UnsolicitedReportInterval,
255 31 => Self::Mldv2UnsolicitedReportInterval,
256 32 => Self::SuppressFragNdisc,
257 33 => Self::AcceptRaFromLocal,
258 34 => Self::UseOptimistic,
259 35 => Self::AcceptRaMtu,
260 36 => Self::StableSecret,
261 37 => Self::UseOifAddrsOnly,
262 38 => Self::AcceptRaMinHopLimit,
263 39 => Self::IgnoreRoutesWithLinkdown,
264 40 => Self::DropUnicastInL2Multicast,
265 41 => Self::DropUnsolicitedNa,
266 42 => Self::KeepAddrOnDown,
267 43 => Self::RtrSolicitMaxInterval,
268 44 => Self::Seg6Enabled,
269 45 => Self::Seg6RequireHmac,
270 46 => Self::EnhancedDad,
271 47 => Self::AddrGenMode,
272 48 => Self::DisablePolicy,
273 49 => Self::AcceptRaRtInfoMinPlen,
274 50 => Self::NdiscTclass,
275 51 => Self::RplSegEnabled,
276 52 => Self::RaDefrtrMetric,
277 53 => Self::Ioam6Enabled,
278 54 => Self::Ioam6Id,
279 55 => Self::Ioam6IdWide,
280 56 => Self::NdiscEvictNocarrier,
281 57 => Self::AcceptUntrackedNa,
282 _ => return None,
283 })
284 }
285}
286#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
287#[derive(Debug, Clone, Copy)]
288pub enum IflaIcmp6Stats {
289 Num = 0,
290 Inmsgs = 1,
291 Inerrors = 2,
292 Outmsgs = 3,
293 Outerrors = 4,
294 Csumerrors = 5,
295 Ratelimithost = 6,
296}
297impl IflaIcmp6Stats {
298 pub fn from_value(value: u64) -> Option<Self> {
299 Some(match value {
300 0 => Self::Num,
301 1 => Self::Inmsgs,
302 2 => Self::Inerrors,
303 3 => Self::Outmsgs,
304 4 => Self::Outerrors,
305 5 => Self::Csumerrors,
306 6 => Self::Ratelimithost,
307 _ => return None,
308 })
309 }
310}
311#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
312#[derive(Debug, Clone, Copy)]
313pub enum IflaInet6Stats {
314 Num = 0,
315 Inpkts = 1,
316 Inoctets = 2,
317 Indelivers = 3,
318 Outforwdatagrams = 4,
319 Outpkts = 5,
320 Outoctets = 6,
321 Inhdrerrors = 7,
322 Intoobigerrors = 8,
323 Innoroutes = 9,
324 Inaddrerrors = 10,
325 Inunknownprotos = 11,
326 Intruncatedpkts = 12,
327 Indiscards = 13,
328 Outdiscards = 14,
329 Outnoroutes = 15,
330 Reasmtimeout = 16,
331 Reasmreqds = 17,
332 Reasmoks = 18,
333 Reasmfails = 19,
334 Fragoks = 20,
335 Fragfails = 21,
336 Fragcreates = 22,
337 Inmcastpkts = 23,
338 Outmcastpkts = 24,
339 Inbcastpkts = 25,
340 Outbcastpkts = 26,
341 Inmcastoctets = 27,
342 Outmcastoctets = 28,
343 Inbcastoctets = 29,
344 Outbcastoctets = 30,
345 Csumerrors = 31,
346 Noectpkts = 32,
347 Ect1Pkts = 33,
348 Ect0Pkts = 34,
349 Cepkts = 35,
350 ReasmOverlaps = 36,
351}
352impl IflaInet6Stats {
353 pub fn from_value(value: u64) -> Option<Self> {
354 Some(match value {
355 0 => Self::Num,
356 1 => Self::Inpkts,
357 2 => Self::Inoctets,
358 3 => Self::Indelivers,
359 4 => Self::Outforwdatagrams,
360 5 => Self::Outpkts,
361 6 => Self::Outoctets,
362 7 => Self::Inhdrerrors,
363 8 => Self::Intoobigerrors,
364 9 => Self::Innoroutes,
365 10 => Self::Inaddrerrors,
366 11 => Self::Inunknownprotos,
367 12 => Self::Intruncatedpkts,
368 13 => Self::Indiscards,
369 14 => Self::Outdiscards,
370 15 => Self::Outnoroutes,
371 16 => Self::Reasmtimeout,
372 17 => Self::Reasmreqds,
373 18 => Self::Reasmoks,
374 19 => Self::Reasmfails,
375 20 => Self::Fragoks,
376 21 => Self::Fragfails,
377 22 => Self::Fragcreates,
378 23 => Self::Inmcastpkts,
379 24 => Self::Outmcastpkts,
380 25 => Self::Inbcastpkts,
381 26 => Self::Outbcastpkts,
382 27 => Self::Inmcastoctets,
383 28 => Self::Outmcastoctets,
384 29 => Self::Inbcastoctets,
385 30 => Self::Outbcastoctets,
386 31 => Self::Csumerrors,
387 32 => Self::Noectpkts,
388 33 => Self::Ect1Pkts,
389 34 => Self::Ect0Pkts,
390 35 => Self::Cepkts,
391 36 => Self::ReasmOverlaps,
392 _ => return None,
393 })
394 }
395}
396#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
397#[derive(Debug, Clone, Copy)]
398pub enum VlanFlags {
399 ReorderHdr = 1 << 0,
400 Gvrp = 1 << 1,
401 LooseBinding = 1 << 2,
402 Mvrp = 1 << 3,
403 BridgeBinding = 1 << 4,
404}
405impl VlanFlags {
406 pub fn from_value(value: u64) -> Option<Self> {
407 Some(match value {
408 n if n == 1 << 0 => Self::ReorderHdr,
409 n if n == 1 << 1 => Self::Gvrp,
410 n if n == 1 << 2 => Self::LooseBinding,
411 n if n == 1 << 3 => Self::Mvrp,
412 n if n == 1 << 4 => Self::BridgeBinding,
413 _ => return None,
414 })
415 }
416}
417#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
418#[derive(Debug, Clone, Copy)]
419pub enum IflaVfLinkStateEnum {
420 Auto = 0,
421 Enable = 1,
422 Disable = 2,
423}
424impl IflaVfLinkStateEnum {
425 pub fn from_value(value: u64) -> Option<Self> {
426 Some(match value {
427 0 => Self::Auto,
428 1 => Self::Enable,
429 2 => Self::Disable,
430 _ => return None,
431 })
432 }
433}
434#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
435#[derive(Debug, Clone, Copy)]
436pub enum RtextFilter {
437 Vf = 1 << 0,
438 Brvlan = 1 << 1,
439 BrvlanCompressed = 1 << 2,
440 SkipStats = 1 << 3,
441 Mrp = 1 << 4,
442 CfmConfig = 1 << 5,
443 CfmStatus = 1 << 6,
444 Mst = 1 << 7,
445}
446impl RtextFilter {
447 pub fn from_value(value: u64) -> Option<Self> {
448 Some(match value {
449 n if n == 1 << 0 => Self::Vf,
450 n if n == 1 << 1 => Self::Brvlan,
451 n if n == 1 << 2 => Self::BrvlanCompressed,
452 n if n == 1 << 3 => Self::SkipStats,
453 n if n == 1 << 4 => Self::Mrp,
454 n if n == 1 << 5 => Self::CfmConfig,
455 n if n == 1 << 6 => Self::CfmStatus,
456 n if n == 1 << 7 => Self::Mst,
457 _ => return None,
458 })
459 }
460}
461#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
462#[derive(Debug, Clone, Copy)]
463pub enum NetkitPolicy {
464 Forward = 0,
465 Blackhole = 2,
466}
467impl NetkitPolicy {
468 pub fn from_value(value: u64) -> Option<Self> {
469 Some(match value {
470 0 => Self::Forward,
471 2 => Self::Blackhole,
472 _ => return None,
473 })
474 }
475}
476#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
477#[derive(Debug, Clone, Copy)]
478pub enum NetkitMode {
479 L2 = 0,
480 L3 = 1,
481}
482impl NetkitMode {
483 pub fn from_value(value: u64) -> Option<Self> {
484 Some(match value {
485 0 => Self::L2,
486 1 => Self::L3,
487 _ => return None,
488 })
489 }
490}
491#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
492#[derive(Debug, Clone, Copy)]
493pub enum NetkitScrub {
494 None = 0,
495 Default = 1,
496}
497impl NetkitScrub {
498 pub fn from_value(value: u64) -> Option<Self> {
499 Some(match value {
500 0 => Self::None,
501 1 => Self::Default,
502 _ => return None,
503 })
504 }
505}
506#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
507#[derive(Debug, Clone, Copy)]
508pub enum OvpnMode {
509 P2p = 0,
510 Mp = 1,
511}
512impl OvpnMode {
513 pub fn from_value(value: u64) -> Option<Self> {
514 Some(match value {
515 0 => Self::P2p,
516 1 => Self::Mp,
517 _ => return None,
518 })
519 }
520}
521#[derive(Clone)]
522pub enum LinkAttrs<'a> {
523 Address(&'a [u8]),
524 Broadcast(&'a [u8]),
525 Ifname(&'a CStr),
526 Mtu(u32),
527 Link(u32),
528 Qdisc(&'a CStr),
529 Stats(PushRtnlLinkStats),
530 Cost(&'a CStr),
531 Priority(&'a CStr),
532 Master(u32),
533 Wireless(&'a CStr),
534 Protinfo(&'a CStr),
535 Txqlen(u32),
536 Map(PushRtnlLinkIfmap),
537 Weight(u32),
538 Operstate(u8),
539 Linkmode(u8),
540 Linkinfo(IterableLinkinfoAttrs<'a>),
541 NetNsPid(u32),
542 Ifalias(&'a CStr),
543 NumVf(u32),
544 VfinfoList(IterableVfinfoListAttrs<'a>),
545 Stats64(PushRtnlLinkStats64),
546 VfPorts(IterableVfPortsAttrs<'a>),
547 PortSelf(IterablePortSelfAttrs<'a>),
548 AfSpec(IterableAfSpecAttrs<'a>),
549 Group(u32),
550 NetNsFd(u32),
551 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
552 ExtMask(u32),
553 Promiscuity(u32),
554 NumTxQueues(u32),
555 NumRxQueues(u32),
556 Carrier(u8),
557 PhysPortId(&'a [u8]),
558 CarrierChanges(u32),
559 PhysSwitchId(&'a [u8]),
560 LinkNetnsid(i32),
561 PhysPortName(&'a CStr),
562 ProtoDown(u8),
563 GsoMaxSegs(u32),
564 GsoMaxSize(u32),
565 Pad(&'a [u8]),
566 Xdp(IterableXdpAttrs<'a>),
567 Event(u32),
568 NewNetnsid(i32),
569 TargetNetnsid(i32),
570 CarrierUpCount(u32),
571 CarrierDownCount(u32),
572 NewIfindex(i32),
573 MinMtu(u32),
574 MaxMtu(u32),
575 PropList(IterablePropListLinkAttrs<'a>),
576 AltIfname(&'a CStr),
577 PermAddress(&'a [u8]),
578 ProtoDownReason(&'a CStr),
579 ParentDevName(&'a CStr),
580 ParentDevBusName(&'a CStr),
581 GroMaxSize(u32),
582 TsoMaxSize(u32),
583 TsoMaxSegs(u32),
584 Allmulti(u32),
585 DevlinkPort(&'a [u8]),
586 GsoIpv4MaxSize(u32),
587 GroIpv4MaxSize(u32),
588 DpllPin(IterableLinkDpllPinAttrs<'a>),
589 #[doc = "EDT offload horizon supported by the device (in nsec)."]
590 MaxPacingOffloadHorizon(u32),
591 NetnsImmutable(u8),
592}
593impl<'a> IterableLinkAttrs<'a> {
594 pub fn get_address(&self) -> Result<&'a [u8], ErrorContext> {
595 let mut iter = self.clone();
596 iter.pos = 0;
597 for attr in iter {
598 if let LinkAttrs::Address(val) = attr? {
599 return Ok(val);
600 }
601 }
602 Err(ErrorContext::new_missing(
603 "LinkAttrs",
604 "Address",
605 self.orig_loc,
606 self.buf.as_ptr() as usize,
607 ))
608 }
609 pub fn get_broadcast(&self) -> Result<&'a [u8], ErrorContext> {
610 let mut iter = self.clone();
611 iter.pos = 0;
612 for attr in iter {
613 if let LinkAttrs::Broadcast(val) = attr? {
614 return Ok(val);
615 }
616 }
617 Err(ErrorContext::new_missing(
618 "LinkAttrs",
619 "Broadcast",
620 self.orig_loc,
621 self.buf.as_ptr() as usize,
622 ))
623 }
624 pub fn get_ifname(&self) -> Result<&'a CStr, ErrorContext> {
625 let mut iter = self.clone();
626 iter.pos = 0;
627 for attr in iter {
628 if let LinkAttrs::Ifname(val) = attr? {
629 return Ok(val);
630 }
631 }
632 Err(ErrorContext::new_missing(
633 "LinkAttrs",
634 "Ifname",
635 self.orig_loc,
636 self.buf.as_ptr() as usize,
637 ))
638 }
639 pub fn get_mtu(&self) -> Result<u32, ErrorContext> {
640 let mut iter = self.clone();
641 iter.pos = 0;
642 for attr in iter {
643 if let LinkAttrs::Mtu(val) = attr? {
644 return Ok(val);
645 }
646 }
647 Err(ErrorContext::new_missing(
648 "LinkAttrs",
649 "Mtu",
650 self.orig_loc,
651 self.buf.as_ptr() as usize,
652 ))
653 }
654 pub fn get_link(&self) -> Result<u32, ErrorContext> {
655 let mut iter = self.clone();
656 iter.pos = 0;
657 for attr in iter {
658 if let LinkAttrs::Link(val) = attr? {
659 return Ok(val);
660 }
661 }
662 Err(ErrorContext::new_missing(
663 "LinkAttrs",
664 "Link",
665 self.orig_loc,
666 self.buf.as_ptr() as usize,
667 ))
668 }
669 pub fn get_qdisc(&self) -> Result<&'a CStr, ErrorContext> {
670 let mut iter = self.clone();
671 iter.pos = 0;
672 for attr in iter {
673 if let LinkAttrs::Qdisc(val) = attr? {
674 return Ok(val);
675 }
676 }
677 Err(ErrorContext::new_missing(
678 "LinkAttrs",
679 "Qdisc",
680 self.orig_loc,
681 self.buf.as_ptr() as usize,
682 ))
683 }
684 pub fn get_stats(&self) -> Result<PushRtnlLinkStats, ErrorContext> {
685 let mut iter = self.clone();
686 iter.pos = 0;
687 for attr in iter {
688 if let LinkAttrs::Stats(val) = attr? {
689 return Ok(val);
690 }
691 }
692 Err(ErrorContext::new_missing(
693 "LinkAttrs",
694 "Stats",
695 self.orig_loc,
696 self.buf.as_ptr() as usize,
697 ))
698 }
699 pub fn get_cost(&self) -> Result<&'a CStr, ErrorContext> {
700 let mut iter = self.clone();
701 iter.pos = 0;
702 for attr in iter {
703 if let LinkAttrs::Cost(val) = attr? {
704 return Ok(val);
705 }
706 }
707 Err(ErrorContext::new_missing(
708 "LinkAttrs",
709 "Cost",
710 self.orig_loc,
711 self.buf.as_ptr() as usize,
712 ))
713 }
714 pub fn get_priority(&self) -> Result<&'a CStr, ErrorContext> {
715 let mut iter = self.clone();
716 iter.pos = 0;
717 for attr in iter {
718 if let LinkAttrs::Priority(val) = attr? {
719 return Ok(val);
720 }
721 }
722 Err(ErrorContext::new_missing(
723 "LinkAttrs",
724 "Priority",
725 self.orig_loc,
726 self.buf.as_ptr() as usize,
727 ))
728 }
729 pub fn get_master(&self) -> Result<u32, ErrorContext> {
730 let mut iter = self.clone();
731 iter.pos = 0;
732 for attr in iter {
733 if let LinkAttrs::Master(val) = attr? {
734 return Ok(val);
735 }
736 }
737 Err(ErrorContext::new_missing(
738 "LinkAttrs",
739 "Master",
740 self.orig_loc,
741 self.buf.as_ptr() as usize,
742 ))
743 }
744 pub fn get_wireless(&self) -> Result<&'a CStr, ErrorContext> {
745 let mut iter = self.clone();
746 iter.pos = 0;
747 for attr in iter {
748 if let LinkAttrs::Wireless(val) = attr? {
749 return Ok(val);
750 }
751 }
752 Err(ErrorContext::new_missing(
753 "LinkAttrs",
754 "Wireless",
755 self.orig_loc,
756 self.buf.as_ptr() as usize,
757 ))
758 }
759 pub fn get_protinfo(&self) -> Result<&'a CStr, ErrorContext> {
760 let mut iter = self.clone();
761 iter.pos = 0;
762 for attr in iter {
763 if let LinkAttrs::Protinfo(val) = attr? {
764 return Ok(val);
765 }
766 }
767 Err(ErrorContext::new_missing(
768 "LinkAttrs",
769 "Protinfo",
770 self.orig_loc,
771 self.buf.as_ptr() as usize,
772 ))
773 }
774 pub fn get_txqlen(&self) -> Result<u32, ErrorContext> {
775 let mut iter = self.clone();
776 iter.pos = 0;
777 for attr in iter {
778 if let LinkAttrs::Txqlen(val) = attr? {
779 return Ok(val);
780 }
781 }
782 Err(ErrorContext::new_missing(
783 "LinkAttrs",
784 "Txqlen",
785 self.orig_loc,
786 self.buf.as_ptr() as usize,
787 ))
788 }
789 pub fn get_map(&self) -> Result<PushRtnlLinkIfmap, ErrorContext> {
790 let mut iter = self.clone();
791 iter.pos = 0;
792 for attr in iter {
793 if let LinkAttrs::Map(val) = attr? {
794 return Ok(val);
795 }
796 }
797 Err(ErrorContext::new_missing(
798 "LinkAttrs",
799 "Map",
800 self.orig_loc,
801 self.buf.as_ptr() as usize,
802 ))
803 }
804 pub fn get_weight(&self) -> Result<u32, ErrorContext> {
805 let mut iter = self.clone();
806 iter.pos = 0;
807 for attr in iter {
808 if let LinkAttrs::Weight(val) = attr? {
809 return Ok(val);
810 }
811 }
812 Err(ErrorContext::new_missing(
813 "LinkAttrs",
814 "Weight",
815 self.orig_loc,
816 self.buf.as_ptr() as usize,
817 ))
818 }
819 pub fn get_operstate(&self) -> Result<u8, ErrorContext> {
820 let mut iter = self.clone();
821 iter.pos = 0;
822 for attr in iter {
823 if let LinkAttrs::Operstate(val) = attr? {
824 return Ok(val);
825 }
826 }
827 Err(ErrorContext::new_missing(
828 "LinkAttrs",
829 "Operstate",
830 self.orig_loc,
831 self.buf.as_ptr() as usize,
832 ))
833 }
834 pub fn get_linkmode(&self) -> Result<u8, ErrorContext> {
835 let mut iter = self.clone();
836 iter.pos = 0;
837 for attr in iter {
838 if let LinkAttrs::Linkmode(val) = attr? {
839 return Ok(val);
840 }
841 }
842 Err(ErrorContext::new_missing(
843 "LinkAttrs",
844 "Linkmode",
845 self.orig_loc,
846 self.buf.as_ptr() as usize,
847 ))
848 }
849 pub fn get_linkinfo(&self) -> Result<IterableLinkinfoAttrs<'a>, ErrorContext> {
850 let mut iter = self.clone();
851 iter.pos = 0;
852 for attr in iter {
853 if let LinkAttrs::Linkinfo(val) = attr? {
854 return Ok(val);
855 }
856 }
857 Err(ErrorContext::new_missing(
858 "LinkAttrs",
859 "Linkinfo",
860 self.orig_loc,
861 self.buf.as_ptr() as usize,
862 ))
863 }
864 pub fn get_net_ns_pid(&self) -> Result<u32, ErrorContext> {
865 let mut iter = self.clone();
866 iter.pos = 0;
867 for attr in iter {
868 if let LinkAttrs::NetNsPid(val) = attr? {
869 return Ok(val);
870 }
871 }
872 Err(ErrorContext::new_missing(
873 "LinkAttrs",
874 "NetNsPid",
875 self.orig_loc,
876 self.buf.as_ptr() as usize,
877 ))
878 }
879 pub fn get_ifalias(&self) -> Result<&'a CStr, ErrorContext> {
880 let mut iter = self.clone();
881 iter.pos = 0;
882 for attr in iter {
883 if let LinkAttrs::Ifalias(val) = attr? {
884 return Ok(val);
885 }
886 }
887 Err(ErrorContext::new_missing(
888 "LinkAttrs",
889 "Ifalias",
890 self.orig_loc,
891 self.buf.as_ptr() as usize,
892 ))
893 }
894 pub fn get_num_vf(&self) -> Result<u32, ErrorContext> {
895 let mut iter = self.clone();
896 iter.pos = 0;
897 for attr in iter {
898 if let LinkAttrs::NumVf(val) = attr? {
899 return Ok(val);
900 }
901 }
902 Err(ErrorContext::new_missing(
903 "LinkAttrs",
904 "NumVf",
905 self.orig_loc,
906 self.buf.as_ptr() as usize,
907 ))
908 }
909 pub fn get_vfinfo_list(&self) -> Result<IterableVfinfoListAttrs<'a>, ErrorContext> {
910 let mut iter = self.clone();
911 iter.pos = 0;
912 for attr in iter {
913 if let LinkAttrs::VfinfoList(val) = attr? {
914 return Ok(val);
915 }
916 }
917 Err(ErrorContext::new_missing(
918 "LinkAttrs",
919 "VfinfoList",
920 self.orig_loc,
921 self.buf.as_ptr() as usize,
922 ))
923 }
924 pub fn get_stats64(&self) -> Result<PushRtnlLinkStats64, ErrorContext> {
925 let mut iter = self.clone();
926 iter.pos = 0;
927 for attr in iter {
928 if let LinkAttrs::Stats64(val) = attr? {
929 return Ok(val);
930 }
931 }
932 Err(ErrorContext::new_missing(
933 "LinkAttrs",
934 "Stats64",
935 self.orig_loc,
936 self.buf.as_ptr() as usize,
937 ))
938 }
939 pub fn get_vf_ports(&self) -> Result<IterableVfPortsAttrs<'a>, ErrorContext> {
940 let mut iter = self.clone();
941 iter.pos = 0;
942 for attr in iter {
943 if let LinkAttrs::VfPorts(val) = attr? {
944 return Ok(val);
945 }
946 }
947 Err(ErrorContext::new_missing(
948 "LinkAttrs",
949 "VfPorts",
950 self.orig_loc,
951 self.buf.as_ptr() as usize,
952 ))
953 }
954 pub fn get_port_self(&self) -> Result<IterablePortSelfAttrs<'a>, ErrorContext> {
955 let mut iter = self.clone();
956 iter.pos = 0;
957 for attr in iter {
958 if let LinkAttrs::PortSelf(val) = attr? {
959 return Ok(val);
960 }
961 }
962 Err(ErrorContext::new_missing(
963 "LinkAttrs",
964 "PortSelf",
965 self.orig_loc,
966 self.buf.as_ptr() as usize,
967 ))
968 }
969 pub fn get_af_spec(&self) -> Result<IterableAfSpecAttrs<'a>, ErrorContext> {
970 let mut iter = self.clone();
971 iter.pos = 0;
972 for attr in iter {
973 if let LinkAttrs::AfSpec(val) = attr? {
974 return Ok(val);
975 }
976 }
977 Err(ErrorContext::new_missing(
978 "LinkAttrs",
979 "AfSpec",
980 self.orig_loc,
981 self.buf.as_ptr() as usize,
982 ))
983 }
984 pub fn get_group(&self) -> Result<u32, ErrorContext> {
985 let mut iter = self.clone();
986 iter.pos = 0;
987 for attr in iter {
988 if let LinkAttrs::Group(val) = attr? {
989 return Ok(val);
990 }
991 }
992 Err(ErrorContext::new_missing(
993 "LinkAttrs",
994 "Group",
995 self.orig_loc,
996 self.buf.as_ptr() as usize,
997 ))
998 }
999 pub fn get_net_ns_fd(&self) -> Result<u32, ErrorContext> {
1000 let mut iter = self.clone();
1001 iter.pos = 0;
1002 for attr in iter {
1003 if let LinkAttrs::NetNsFd(val) = attr? {
1004 return Ok(val);
1005 }
1006 }
1007 Err(ErrorContext::new_missing(
1008 "LinkAttrs",
1009 "NetNsFd",
1010 self.orig_loc,
1011 self.buf.as_ptr() as usize,
1012 ))
1013 }
1014 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
1015 pub fn get_ext_mask(&self) -> Result<u32, ErrorContext> {
1016 let mut iter = self.clone();
1017 iter.pos = 0;
1018 for attr in iter {
1019 if let LinkAttrs::ExtMask(val) = attr? {
1020 return Ok(val);
1021 }
1022 }
1023 Err(ErrorContext::new_missing(
1024 "LinkAttrs",
1025 "ExtMask",
1026 self.orig_loc,
1027 self.buf.as_ptr() as usize,
1028 ))
1029 }
1030 pub fn get_promiscuity(&self) -> Result<u32, ErrorContext> {
1031 let mut iter = self.clone();
1032 iter.pos = 0;
1033 for attr in iter {
1034 if let LinkAttrs::Promiscuity(val) = attr? {
1035 return Ok(val);
1036 }
1037 }
1038 Err(ErrorContext::new_missing(
1039 "LinkAttrs",
1040 "Promiscuity",
1041 self.orig_loc,
1042 self.buf.as_ptr() as usize,
1043 ))
1044 }
1045 pub fn get_num_tx_queues(&self) -> Result<u32, ErrorContext> {
1046 let mut iter = self.clone();
1047 iter.pos = 0;
1048 for attr in iter {
1049 if let LinkAttrs::NumTxQueues(val) = attr? {
1050 return Ok(val);
1051 }
1052 }
1053 Err(ErrorContext::new_missing(
1054 "LinkAttrs",
1055 "NumTxQueues",
1056 self.orig_loc,
1057 self.buf.as_ptr() as usize,
1058 ))
1059 }
1060 pub fn get_num_rx_queues(&self) -> Result<u32, ErrorContext> {
1061 let mut iter = self.clone();
1062 iter.pos = 0;
1063 for attr in iter {
1064 if let LinkAttrs::NumRxQueues(val) = attr? {
1065 return Ok(val);
1066 }
1067 }
1068 Err(ErrorContext::new_missing(
1069 "LinkAttrs",
1070 "NumRxQueues",
1071 self.orig_loc,
1072 self.buf.as_ptr() as usize,
1073 ))
1074 }
1075 pub fn get_carrier(&self) -> Result<u8, ErrorContext> {
1076 let mut iter = self.clone();
1077 iter.pos = 0;
1078 for attr in iter {
1079 if let LinkAttrs::Carrier(val) = attr? {
1080 return Ok(val);
1081 }
1082 }
1083 Err(ErrorContext::new_missing(
1084 "LinkAttrs",
1085 "Carrier",
1086 self.orig_loc,
1087 self.buf.as_ptr() as usize,
1088 ))
1089 }
1090 pub fn get_phys_port_id(&self) -> Result<&'a [u8], ErrorContext> {
1091 let mut iter = self.clone();
1092 iter.pos = 0;
1093 for attr in iter {
1094 if let LinkAttrs::PhysPortId(val) = attr? {
1095 return Ok(val);
1096 }
1097 }
1098 Err(ErrorContext::new_missing(
1099 "LinkAttrs",
1100 "PhysPortId",
1101 self.orig_loc,
1102 self.buf.as_ptr() as usize,
1103 ))
1104 }
1105 pub fn get_carrier_changes(&self) -> Result<u32, ErrorContext> {
1106 let mut iter = self.clone();
1107 iter.pos = 0;
1108 for attr in iter {
1109 if let LinkAttrs::CarrierChanges(val) = attr? {
1110 return Ok(val);
1111 }
1112 }
1113 Err(ErrorContext::new_missing(
1114 "LinkAttrs",
1115 "CarrierChanges",
1116 self.orig_loc,
1117 self.buf.as_ptr() as usize,
1118 ))
1119 }
1120 pub fn get_phys_switch_id(&self) -> Result<&'a [u8], ErrorContext> {
1121 let mut iter = self.clone();
1122 iter.pos = 0;
1123 for attr in iter {
1124 if let LinkAttrs::PhysSwitchId(val) = attr? {
1125 return Ok(val);
1126 }
1127 }
1128 Err(ErrorContext::new_missing(
1129 "LinkAttrs",
1130 "PhysSwitchId",
1131 self.orig_loc,
1132 self.buf.as_ptr() as usize,
1133 ))
1134 }
1135 pub fn get_link_netnsid(&self) -> Result<i32, ErrorContext> {
1136 let mut iter = self.clone();
1137 iter.pos = 0;
1138 for attr in iter {
1139 if let LinkAttrs::LinkNetnsid(val) = attr? {
1140 return Ok(val);
1141 }
1142 }
1143 Err(ErrorContext::new_missing(
1144 "LinkAttrs",
1145 "LinkNetnsid",
1146 self.orig_loc,
1147 self.buf.as_ptr() as usize,
1148 ))
1149 }
1150 pub fn get_phys_port_name(&self) -> Result<&'a CStr, ErrorContext> {
1151 let mut iter = self.clone();
1152 iter.pos = 0;
1153 for attr in iter {
1154 if let LinkAttrs::PhysPortName(val) = attr? {
1155 return Ok(val);
1156 }
1157 }
1158 Err(ErrorContext::new_missing(
1159 "LinkAttrs",
1160 "PhysPortName",
1161 self.orig_loc,
1162 self.buf.as_ptr() as usize,
1163 ))
1164 }
1165 pub fn get_proto_down(&self) -> Result<u8, ErrorContext> {
1166 let mut iter = self.clone();
1167 iter.pos = 0;
1168 for attr in iter {
1169 if let LinkAttrs::ProtoDown(val) = attr? {
1170 return Ok(val);
1171 }
1172 }
1173 Err(ErrorContext::new_missing(
1174 "LinkAttrs",
1175 "ProtoDown",
1176 self.orig_loc,
1177 self.buf.as_ptr() as usize,
1178 ))
1179 }
1180 pub fn get_gso_max_segs(&self) -> Result<u32, ErrorContext> {
1181 let mut iter = self.clone();
1182 iter.pos = 0;
1183 for attr in iter {
1184 if let LinkAttrs::GsoMaxSegs(val) = attr? {
1185 return Ok(val);
1186 }
1187 }
1188 Err(ErrorContext::new_missing(
1189 "LinkAttrs",
1190 "GsoMaxSegs",
1191 self.orig_loc,
1192 self.buf.as_ptr() as usize,
1193 ))
1194 }
1195 pub fn get_gso_max_size(&self) -> Result<u32, ErrorContext> {
1196 let mut iter = self.clone();
1197 iter.pos = 0;
1198 for attr in iter {
1199 if let LinkAttrs::GsoMaxSize(val) = attr? {
1200 return Ok(val);
1201 }
1202 }
1203 Err(ErrorContext::new_missing(
1204 "LinkAttrs",
1205 "GsoMaxSize",
1206 self.orig_loc,
1207 self.buf.as_ptr() as usize,
1208 ))
1209 }
1210 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
1211 let mut iter = self.clone();
1212 iter.pos = 0;
1213 for attr in iter {
1214 if let LinkAttrs::Pad(val) = attr? {
1215 return Ok(val);
1216 }
1217 }
1218 Err(ErrorContext::new_missing(
1219 "LinkAttrs",
1220 "Pad",
1221 self.orig_loc,
1222 self.buf.as_ptr() as usize,
1223 ))
1224 }
1225 pub fn get_xdp(&self) -> Result<IterableXdpAttrs<'a>, ErrorContext> {
1226 let mut iter = self.clone();
1227 iter.pos = 0;
1228 for attr in iter {
1229 if let LinkAttrs::Xdp(val) = attr? {
1230 return Ok(val);
1231 }
1232 }
1233 Err(ErrorContext::new_missing(
1234 "LinkAttrs",
1235 "Xdp",
1236 self.orig_loc,
1237 self.buf.as_ptr() as usize,
1238 ))
1239 }
1240 pub fn get_event(&self) -> Result<u32, ErrorContext> {
1241 let mut iter = self.clone();
1242 iter.pos = 0;
1243 for attr in iter {
1244 if let LinkAttrs::Event(val) = attr? {
1245 return Ok(val);
1246 }
1247 }
1248 Err(ErrorContext::new_missing(
1249 "LinkAttrs",
1250 "Event",
1251 self.orig_loc,
1252 self.buf.as_ptr() as usize,
1253 ))
1254 }
1255 pub fn get_new_netnsid(&self) -> Result<i32, ErrorContext> {
1256 let mut iter = self.clone();
1257 iter.pos = 0;
1258 for attr in iter {
1259 if let LinkAttrs::NewNetnsid(val) = attr? {
1260 return Ok(val);
1261 }
1262 }
1263 Err(ErrorContext::new_missing(
1264 "LinkAttrs",
1265 "NewNetnsid",
1266 self.orig_loc,
1267 self.buf.as_ptr() as usize,
1268 ))
1269 }
1270 pub fn get_target_netnsid(&self) -> Result<i32, ErrorContext> {
1271 let mut iter = self.clone();
1272 iter.pos = 0;
1273 for attr in iter {
1274 if let LinkAttrs::TargetNetnsid(val) = attr? {
1275 return Ok(val);
1276 }
1277 }
1278 Err(ErrorContext::new_missing(
1279 "LinkAttrs",
1280 "TargetNetnsid",
1281 self.orig_loc,
1282 self.buf.as_ptr() as usize,
1283 ))
1284 }
1285 pub fn get_carrier_up_count(&self) -> Result<u32, ErrorContext> {
1286 let mut iter = self.clone();
1287 iter.pos = 0;
1288 for attr in iter {
1289 if let LinkAttrs::CarrierUpCount(val) = attr? {
1290 return Ok(val);
1291 }
1292 }
1293 Err(ErrorContext::new_missing(
1294 "LinkAttrs",
1295 "CarrierUpCount",
1296 self.orig_loc,
1297 self.buf.as_ptr() as usize,
1298 ))
1299 }
1300 pub fn get_carrier_down_count(&self) -> Result<u32, ErrorContext> {
1301 let mut iter = self.clone();
1302 iter.pos = 0;
1303 for attr in iter {
1304 if let LinkAttrs::CarrierDownCount(val) = attr? {
1305 return Ok(val);
1306 }
1307 }
1308 Err(ErrorContext::new_missing(
1309 "LinkAttrs",
1310 "CarrierDownCount",
1311 self.orig_loc,
1312 self.buf.as_ptr() as usize,
1313 ))
1314 }
1315 pub fn get_new_ifindex(&self) -> Result<i32, ErrorContext> {
1316 let mut iter = self.clone();
1317 iter.pos = 0;
1318 for attr in iter {
1319 if let LinkAttrs::NewIfindex(val) = attr? {
1320 return Ok(val);
1321 }
1322 }
1323 Err(ErrorContext::new_missing(
1324 "LinkAttrs",
1325 "NewIfindex",
1326 self.orig_loc,
1327 self.buf.as_ptr() as usize,
1328 ))
1329 }
1330 pub fn get_min_mtu(&self) -> Result<u32, ErrorContext> {
1331 let mut iter = self.clone();
1332 iter.pos = 0;
1333 for attr in iter {
1334 if let LinkAttrs::MinMtu(val) = attr? {
1335 return Ok(val);
1336 }
1337 }
1338 Err(ErrorContext::new_missing(
1339 "LinkAttrs",
1340 "MinMtu",
1341 self.orig_loc,
1342 self.buf.as_ptr() as usize,
1343 ))
1344 }
1345 pub fn get_max_mtu(&self) -> Result<u32, ErrorContext> {
1346 let mut iter = self.clone();
1347 iter.pos = 0;
1348 for attr in iter {
1349 if let LinkAttrs::MaxMtu(val) = attr? {
1350 return Ok(val);
1351 }
1352 }
1353 Err(ErrorContext::new_missing(
1354 "LinkAttrs",
1355 "MaxMtu",
1356 self.orig_loc,
1357 self.buf.as_ptr() as usize,
1358 ))
1359 }
1360 pub fn get_prop_list(&self) -> Result<IterablePropListLinkAttrs<'a>, ErrorContext> {
1361 let mut iter = self.clone();
1362 iter.pos = 0;
1363 for attr in iter {
1364 if let LinkAttrs::PropList(val) = attr? {
1365 return Ok(val);
1366 }
1367 }
1368 Err(ErrorContext::new_missing(
1369 "LinkAttrs",
1370 "PropList",
1371 self.orig_loc,
1372 self.buf.as_ptr() as usize,
1373 ))
1374 }
1375 pub fn get_alt_ifname(&self) -> Result<&'a CStr, ErrorContext> {
1376 let mut iter = self.clone();
1377 iter.pos = 0;
1378 for attr in iter {
1379 if let LinkAttrs::AltIfname(val) = attr? {
1380 return Ok(val);
1381 }
1382 }
1383 Err(ErrorContext::new_missing(
1384 "LinkAttrs",
1385 "AltIfname",
1386 self.orig_loc,
1387 self.buf.as_ptr() as usize,
1388 ))
1389 }
1390 pub fn get_perm_address(&self) -> Result<&'a [u8], ErrorContext> {
1391 let mut iter = self.clone();
1392 iter.pos = 0;
1393 for attr in iter {
1394 if let LinkAttrs::PermAddress(val) = attr? {
1395 return Ok(val);
1396 }
1397 }
1398 Err(ErrorContext::new_missing(
1399 "LinkAttrs",
1400 "PermAddress",
1401 self.orig_loc,
1402 self.buf.as_ptr() as usize,
1403 ))
1404 }
1405 pub fn get_proto_down_reason(&self) -> Result<&'a CStr, ErrorContext> {
1406 let mut iter = self.clone();
1407 iter.pos = 0;
1408 for attr in iter {
1409 if let LinkAttrs::ProtoDownReason(val) = attr? {
1410 return Ok(val);
1411 }
1412 }
1413 Err(ErrorContext::new_missing(
1414 "LinkAttrs",
1415 "ProtoDownReason",
1416 self.orig_loc,
1417 self.buf.as_ptr() as usize,
1418 ))
1419 }
1420 pub fn get_parent_dev_name(&self) -> Result<&'a CStr, ErrorContext> {
1421 let mut iter = self.clone();
1422 iter.pos = 0;
1423 for attr in iter {
1424 if let LinkAttrs::ParentDevName(val) = attr? {
1425 return Ok(val);
1426 }
1427 }
1428 Err(ErrorContext::new_missing(
1429 "LinkAttrs",
1430 "ParentDevName",
1431 self.orig_loc,
1432 self.buf.as_ptr() as usize,
1433 ))
1434 }
1435 pub fn get_parent_dev_bus_name(&self) -> Result<&'a CStr, ErrorContext> {
1436 let mut iter = self.clone();
1437 iter.pos = 0;
1438 for attr in iter {
1439 if let LinkAttrs::ParentDevBusName(val) = attr? {
1440 return Ok(val);
1441 }
1442 }
1443 Err(ErrorContext::new_missing(
1444 "LinkAttrs",
1445 "ParentDevBusName",
1446 self.orig_loc,
1447 self.buf.as_ptr() as usize,
1448 ))
1449 }
1450 pub fn get_gro_max_size(&self) -> Result<u32, ErrorContext> {
1451 let mut iter = self.clone();
1452 iter.pos = 0;
1453 for attr in iter {
1454 if let LinkAttrs::GroMaxSize(val) = attr? {
1455 return Ok(val);
1456 }
1457 }
1458 Err(ErrorContext::new_missing(
1459 "LinkAttrs",
1460 "GroMaxSize",
1461 self.orig_loc,
1462 self.buf.as_ptr() as usize,
1463 ))
1464 }
1465 pub fn get_tso_max_size(&self) -> Result<u32, ErrorContext> {
1466 let mut iter = self.clone();
1467 iter.pos = 0;
1468 for attr in iter {
1469 if let LinkAttrs::TsoMaxSize(val) = attr? {
1470 return Ok(val);
1471 }
1472 }
1473 Err(ErrorContext::new_missing(
1474 "LinkAttrs",
1475 "TsoMaxSize",
1476 self.orig_loc,
1477 self.buf.as_ptr() as usize,
1478 ))
1479 }
1480 pub fn get_tso_max_segs(&self) -> Result<u32, ErrorContext> {
1481 let mut iter = self.clone();
1482 iter.pos = 0;
1483 for attr in iter {
1484 if let LinkAttrs::TsoMaxSegs(val) = attr? {
1485 return Ok(val);
1486 }
1487 }
1488 Err(ErrorContext::new_missing(
1489 "LinkAttrs",
1490 "TsoMaxSegs",
1491 self.orig_loc,
1492 self.buf.as_ptr() as usize,
1493 ))
1494 }
1495 pub fn get_allmulti(&self) -> Result<u32, ErrorContext> {
1496 let mut iter = self.clone();
1497 iter.pos = 0;
1498 for attr in iter {
1499 if let LinkAttrs::Allmulti(val) = attr? {
1500 return Ok(val);
1501 }
1502 }
1503 Err(ErrorContext::new_missing(
1504 "LinkAttrs",
1505 "Allmulti",
1506 self.orig_loc,
1507 self.buf.as_ptr() as usize,
1508 ))
1509 }
1510 pub fn get_devlink_port(&self) -> Result<&'a [u8], ErrorContext> {
1511 let mut iter = self.clone();
1512 iter.pos = 0;
1513 for attr in iter {
1514 if let LinkAttrs::DevlinkPort(val) = attr? {
1515 return Ok(val);
1516 }
1517 }
1518 Err(ErrorContext::new_missing(
1519 "LinkAttrs",
1520 "DevlinkPort",
1521 self.orig_loc,
1522 self.buf.as_ptr() as usize,
1523 ))
1524 }
1525 pub fn get_gso_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
1526 let mut iter = self.clone();
1527 iter.pos = 0;
1528 for attr in iter {
1529 if let LinkAttrs::GsoIpv4MaxSize(val) = attr? {
1530 return Ok(val);
1531 }
1532 }
1533 Err(ErrorContext::new_missing(
1534 "LinkAttrs",
1535 "GsoIpv4MaxSize",
1536 self.orig_loc,
1537 self.buf.as_ptr() as usize,
1538 ))
1539 }
1540 pub fn get_gro_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
1541 let mut iter = self.clone();
1542 iter.pos = 0;
1543 for attr in iter {
1544 if let LinkAttrs::GroIpv4MaxSize(val) = attr? {
1545 return Ok(val);
1546 }
1547 }
1548 Err(ErrorContext::new_missing(
1549 "LinkAttrs",
1550 "GroIpv4MaxSize",
1551 self.orig_loc,
1552 self.buf.as_ptr() as usize,
1553 ))
1554 }
1555 pub fn get_dpll_pin(&self) -> Result<IterableLinkDpllPinAttrs<'a>, ErrorContext> {
1556 let mut iter = self.clone();
1557 iter.pos = 0;
1558 for attr in iter {
1559 if let LinkAttrs::DpllPin(val) = attr? {
1560 return Ok(val);
1561 }
1562 }
1563 Err(ErrorContext::new_missing(
1564 "LinkAttrs",
1565 "DpllPin",
1566 self.orig_loc,
1567 self.buf.as_ptr() as usize,
1568 ))
1569 }
1570 #[doc = "EDT offload horizon supported by the device (in nsec)."]
1571 pub fn get_max_pacing_offload_horizon(&self) -> Result<u32, ErrorContext> {
1572 let mut iter = self.clone();
1573 iter.pos = 0;
1574 for attr in iter {
1575 if let LinkAttrs::MaxPacingOffloadHorizon(val) = attr? {
1576 return Ok(val);
1577 }
1578 }
1579 Err(ErrorContext::new_missing(
1580 "LinkAttrs",
1581 "MaxPacingOffloadHorizon",
1582 self.orig_loc,
1583 self.buf.as_ptr() as usize,
1584 ))
1585 }
1586 pub fn get_netns_immutable(&self) -> Result<u8, ErrorContext> {
1587 let mut iter = self.clone();
1588 iter.pos = 0;
1589 for attr in iter {
1590 if let LinkAttrs::NetnsImmutable(val) = attr? {
1591 return Ok(val);
1592 }
1593 }
1594 Err(ErrorContext::new_missing(
1595 "LinkAttrs",
1596 "NetnsImmutable",
1597 self.orig_loc,
1598 self.buf.as_ptr() as usize,
1599 ))
1600 }
1601}
1602impl LinkAttrs<'_> {
1603 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkAttrs<'a> {
1604 IterableLinkAttrs::with_loc(buf, buf.as_ptr() as usize)
1605 }
1606 fn attr_from_type(r#type: u16) -> Option<&'static str> {
1607 let res = match r#type {
1608 1u16 => "Address",
1609 2u16 => "Broadcast",
1610 3u16 => "Ifname",
1611 4u16 => "Mtu",
1612 5u16 => "Link",
1613 6u16 => "Qdisc",
1614 7u16 => "Stats",
1615 8u16 => "Cost",
1616 9u16 => "Priority",
1617 10u16 => "Master",
1618 11u16 => "Wireless",
1619 12u16 => "Protinfo",
1620 13u16 => "Txqlen",
1621 14u16 => "Map",
1622 15u16 => "Weight",
1623 16u16 => "Operstate",
1624 17u16 => "Linkmode",
1625 18u16 => "Linkinfo",
1626 19u16 => "NetNsPid",
1627 20u16 => "Ifalias",
1628 21u16 => "NumVf",
1629 22u16 => "VfinfoList",
1630 23u16 => "Stats64",
1631 24u16 => "VfPorts",
1632 25u16 => "PortSelf",
1633 26u16 => "AfSpec",
1634 27u16 => "Group",
1635 28u16 => "NetNsFd",
1636 29u16 => "ExtMask",
1637 30u16 => "Promiscuity",
1638 31u16 => "NumTxQueues",
1639 32u16 => "NumRxQueues",
1640 33u16 => "Carrier",
1641 34u16 => "PhysPortId",
1642 35u16 => "CarrierChanges",
1643 36u16 => "PhysSwitchId",
1644 37u16 => "LinkNetnsid",
1645 38u16 => "PhysPortName",
1646 39u16 => "ProtoDown",
1647 40u16 => "GsoMaxSegs",
1648 41u16 => "GsoMaxSize",
1649 42u16 => "Pad",
1650 43u16 => "Xdp",
1651 44u16 => "Event",
1652 45u16 => "NewNetnsid",
1653 46u16 => "TargetNetnsid",
1654 47u16 => "CarrierUpCount",
1655 48u16 => "CarrierDownCount",
1656 49u16 => "NewIfindex",
1657 50u16 => "MinMtu",
1658 51u16 => "MaxMtu",
1659 52u16 => "PropList",
1660 53u16 => "AltIfname",
1661 54u16 => "PermAddress",
1662 55u16 => "ProtoDownReason",
1663 56u16 => "ParentDevName",
1664 57u16 => "ParentDevBusName",
1665 58u16 => "GroMaxSize",
1666 59u16 => "TsoMaxSize",
1667 60u16 => "TsoMaxSegs",
1668 61u16 => "Allmulti",
1669 62u16 => "DevlinkPort",
1670 63u16 => "GsoIpv4MaxSize",
1671 64u16 => "GroIpv4MaxSize",
1672 65u16 => "DpllPin",
1673 66u16 => "MaxPacingOffloadHorizon",
1674 67u16 => "NetnsImmutable",
1675 _ => return None,
1676 };
1677 Some(res)
1678 }
1679}
1680#[derive(Clone, Copy, Default)]
1681pub struct IterableLinkAttrs<'a> {
1682 buf: &'a [u8],
1683 pos: usize,
1684 orig_loc: usize,
1685}
1686impl<'a> IterableLinkAttrs<'a> {
1687 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1688 Self {
1689 buf,
1690 pos: 0,
1691 orig_loc,
1692 }
1693 }
1694 pub fn get_buf(&self) -> &'a [u8] {
1695 self.buf
1696 }
1697}
1698impl<'a> Iterator for IterableLinkAttrs<'a> {
1699 type Item = Result<LinkAttrs<'a>, ErrorContext>;
1700 fn next(&mut self) -> Option<Self::Item> {
1701 if self.buf.len() == self.pos {
1702 return None;
1703 }
1704 let pos = self.pos;
1705 let mut r#type = None;
1706 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
1707 r#type = Some(header.r#type);
1708 let res = match header.r#type {
1709 1u16 => LinkAttrs::Address({
1710 let res = Some(next);
1711 let Some(val) = res else { break };
1712 val
1713 }),
1714 2u16 => LinkAttrs::Broadcast({
1715 let res = Some(next);
1716 let Some(val) = res else { break };
1717 val
1718 }),
1719 3u16 => LinkAttrs::Ifname({
1720 let res = CStr::from_bytes_with_nul(next).ok();
1721 let Some(val) = res else { break };
1722 val
1723 }),
1724 4u16 => LinkAttrs::Mtu({
1725 let res = parse_u32(next);
1726 let Some(val) = res else { break };
1727 val
1728 }),
1729 5u16 => LinkAttrs::Link({
1730 let res = parse_u32(next);
1731 let Some(val) = res else { break };
1732 val
1733 }),
1734 6u16 => LinkAttrs::Qdisc({
1735 let res = CStr::from_bytes_with_nul(next).ok();
1736 let Some(val) = res else { break };
1737 val
1738 }),
1739 7u16 => LinkAttrs::Stats({
1740 let res = PushRtnlLinkStats::new_from_slice(next);
1741 let Some(val) = res else { break };
1742 val
1743 }),
1744 8u16 => LinkAttrs::Cost({
1745 let res = CStr::from_bytes_with_nul(next).ok();
1746 let Some(val) = res else { break };
1747 val
1748 }),
1749 9u16 => LinkAttrs::Priority({
1750 let res = CStr::from_bytes_with_nul(next).ok();
1751 let Some(val) = res else { break };
1752 val
1753 }),
1754 10u16 => LinkAttrs::Master({
1755 let res = parse_u32(next);
1756 let Some(val) = res else { break };
1757 val
1758 }),
1759 11u16 => LinkAttrs::Wireless({
1760 let res = CStr::from_bytes_with_nul(next).ok();
1761 let Some(val) = res else { break };
1762 val
1763 }),
1764 12u16 => LinkAttrs::Protinfo({
1765 let res = CStr::from_bytes_with_nul(next).ok();
1766 let Some(val) = res else { break };
1767 val
1768 }),
1769 13u16 => LinkAttrs::Txqlen({
1770 let res = parse_u32(next);
1771 let Some(val) = res else { break };
1772 val
1773 }),
1774 14u16 => LinkAttrs::Map({
1775 let res = PushRtnlLinkIfmap::new_from_slice(next);
1776 let Some(val) = res else { break };
1777 val
1778 }),
1779 15u16 => LinkAttrs::Weight({
1780 let res = parse_u32(next);
1781 let Some(val) = res else { break };
1782 val
1783 }),
1784 16u16 => LinkAttrs::Operstate({
1785 let res = parse_u8(next);
1786 let Some(val) = res else { break };
1787 val
1788 }),
1789 17u16 => LinkAttrs::Linkmode({
1790 let res = parse_u8(next);
1791 let Some(val) = res else { break };
1792 val
1793 }),
1794 18u16 => LinkAttrs::Linkinfo({
1795 let res = Some(IterableLinkinfoAttrs::with_loc(next, self.orig_loc));
1796 let Some(val) = res else { break };
1797 val
1798 }),
1799 19u16 => LinkAttrs::NetNsPid({
1800 let res = parse_u32(next);
1801 let Some(val) = res else { break };
1802 val
1803 }),
1804 20u16 => LinkAttrs::Ifalias({
1805 let res = CStr::from_bytes_with_nul(next).ok();
1806 let Some(val) = res else { break };
1807 val
1808 }),
1809 21u16 => LinkAttrs::NumVf({
1810 let res = parse_u32(next);
1811 let Some(val) = res else { break };
1812 val
1813 }),
1814 22u16 => LinkAttrs::VfinfoList({
1815 let res = Some(IterableVfinfoListAttrs::with_loc(next, self.orig_loc));
1816 let Some(val) = res else { break };
1817 val
1818 }),
1819 23u16 => LinkAttrs::Stats64({
1820 let res = PushRtnlLinkStats64::new_from_slice(next);
1821 let Some(val) = res else { break };
1822 val
1823 }),
1824 24u16 => LinkAttrs::VfPorts({
1825 let res = Some(IterableVfPortsAttrs::with_loc(next, self.orig_loc));
1826 let Some(val) = res else { break };
1827 val
1828 }),
1829 25u16 => LinkAttrs::PortSelf({
1830 let res = Some(IterablePortSelfAttrs::with_loc(next, self.orig_loc));
1831 let Some(val) = res else { break };
1832 val
1833 }),
1834 26u16 => LinkAttrs::AfSpec({
1835 let res = Some(IterableAfSpecAttrs::with_loc(next, self.orig_loc));
1836 let Some(val) = res else { break };
1837 val
1838 }),
1839 27u16 => LinkAttrs::Group({
1840 let res = parse_u32(next);
1841 let Some(val) = res else { break };
1842 val
1843 }),
1844 28u16 => LinkAttrs::NetNsFd({
1845 let res = parse_u32(next);
1846 let Some(val) = res else { break };
1847 val
1848 }),
1849 29u16 => LinkAttrs::ExtMask({
1850 let res = parse_u32(next);
1851 let Some(val) = res else { break };
1852 val
1853 }),
1854 30u16 => LinkAttrs::Promiscuity({
1855 let res = parse_u32(next);
1856 let Some(val) = res else { break };
1857 val
1858 }),
1859 31u16 => LinkAttrs::NumTxQueues({
1860 let res = parse_u32(next);
1861 let Some(val) = res else { break };
1862 val
1863 }),
1864 32u16 => LinkAttrs::NumRxQueues({
1865 let res = parse_u32(next);
1866 let Some(val) = res else { break };
1867 val
1868 }),
1869 33u16 => LinkAttrs::Carrier({
1870 let res = parse_u8(next);
1871 let Some(val) = res else { break };
1872 val
1873 }),
1874 34u16 => LinkAttrs::PhysPortId({
1875 let res = Some(next);
1876 let Some(val) = res else { break };
1877 val
1878 }),
1879 35u16 => LinkAttrs::CarrierChanges({
1880 let res = parse_u32(next);
1881 let Some(val) = res else { break };
1882 val
1883 }),
1884 36u16 => LinkAttrs::PhysSwitchId({
1885 let res = Some(next);
1886 let Some(val) = res else { break };
1887 val
1888 }),
1889 37u16 => LinkAttrs::LinkNetnsid({
1890 let res = parse_i32(next);
1891 let Some(val) = res else { break };
1892 val
1893 }),
1894 38u16 => LinkAttrs::PhysPortName({
1895 let res = CStr::from_bytes_with_nul(next).ok();
1896 let Some(val) = res else { break };
1897 val
1898 }),
1899 39u16 => LinkAttrs::ProtoDown({
1900 let res = parse_u8(next);
1901 let Some(val) = res else { break };
1902 val
1903 }),
1904 40u16 => LinkAttrs::GsoMaxSegs({
1905 let res = parse_u32(next);
1906 let Some(val) = res else { break };
1907 val
1908 }),
1909 41u16 => LinkAttrs::GsoMaxSize({
1910 let res = parse_u32(next);
1911 let Some(val) = res else { break };
1912 val
1913 }),
1914 42u16 => LinkAttrs::Pad({
1915 let res = Some(next);
1916 let Some(val) = res else { break };
1917 val
1918 }),
1919 43u16 => LinkAttrs::Xdp({
1920 let res = Some(IterableXdpAttrs::with_loc(next, self.orig_loc));
1921 let Some(val) = res else { break };
1922 val
1923 }),
1924 44u16 => LinkAttrs::Event({
1925 let res = parse_u32(next);
1926 let Some(val) = res else { break };
1927 val
1928 }),
1929 45u16 => LinkAttrs::NewNetnsid({
1930 let res = parse_i32(next);
1931 let Some(val) = res else { break };
1932 val
1933 }),
1934 46u16 => LinkAttrs::TargetNetnsid({
1935 let res = parse_i32(next);
1936 let Some(val) = res else { break };
1937 val
1938 }),
1939 47u16 => LinkAttrs::CarrierUpCount({
1940 let res = parse_u32(next);
1941 let Some(val) = res else { break };
1942 val
1943 }),
1944 48u16 => LinkAttrs::CarrierDownCount({
1945 let res = parse_u32(next);
1946 let Some(val) = res else { break };
1947 val
1948 }),
1949 49u16 => LinkAttrs::NewIfindex({
1950 let res = parse_i32(next);
1951 let Some(val) = res else { break };
1952 val
1953 }),
1954 50u16 => LinkAttrs::MinMtu({
1955 let res = parse_u32(next);
1956 let Some(val) = res else { break };
1957 val
1958 }),
1959 51u16 => LinkAttrs::MaxMtu({
1960 let res = parse_u32(next);
1961 let Some(val) = res else { break };
1962 val
1963 }),
1964 52u16 => LinkAttrs::PropList({
1965 let res = Some(IterablePropListLinkAttrs::with_loc(next, self.orig_loc));
1966 let Some(val) = res else { break };
1967 val
1968 }),
1969 53u16 => LinkAttrs::AltIfname({
1970 let res = CStr::from_bytes_with_nul(next).ok();
1971 let Some(val) = res else { break };
1972 val
1973 }),
1974 54u16 => LinkAttrs::PermAddress({
1975 let res = Some(next);
1976 let Some(val) = res else { break };
1977 val
1978 }),
1979 55u16 => LinkAttrs::ProtoDownReason({
1980 let res = CStr::from_bytes_with_nul(next).ok();
1981 let Some(val) = res else { break };
1982 val
1983 }),
1984 56u16 => LinkAttrs::ParentDevName({
1985 let res = CStr::from_bytes_with_nul(next).ok();
1986 let Some(val) = res else { break };
1987 val
1988 }),
1989 57u16 => LinkAttrs::ParentDevBusName({
1990 let res = CStr::from_bytes_with_nul(next).ok();
1991 let Some(val) = res else { break };
1992 val
1993 }),
1994 58u16 => LinkAttrs::GroMaxSize({
1995 let res = parse_u32(next);
1996 let Some(val) = res else { break };
1997 val
1998 }),
1999 59u16 => LinkAttrs::TsoMaxSize({
2000 let res = parse_u32(next);
2001 let Some(val) = res else { break };
2002 val
2003 }),
2004 60u16 => LinkAttrs::TsoMaxSegs({
2005 let res = parse_u32(next);
2006 let Some(val) = res else { break };
2007 val
2008 }),
2009 61u16 => LinkAttrs::Allmulti({
2010 let res = parse_u32(next);
2011 let Some(val) = res else { break };
2012 val
2013 }),
2014 62u16 => LinkAttrs::DevlinkPort({
2015 let res = Some(next);
2016 let Some(val) = res else { break };
2017 val
2018 }),
2019 63u16 => LinkAttrs::GsoIpv4MaxSize({
2020 let res = parse_u32(next);
2021 let Some(val) = res else { break };
2022 val
2023 }),
2024 64u16 => LinkAttrs::GroIpv4MaxSize({
2025 let res = parse_u32(next);
2026 let Some(val) = res else { break };
2027 val
2028 }),
2029 65u16 => LinkAttrs::DpllPin({
2030 let res = Some(IterableLinkDpllPinAttrs::with_loc(next, self.orig_loc));
2031 let Some(val) = res else { break };
2032 val
2033 }),
2034 66u16 => LinkAttrs::MaxPacingOffloadHorizon({
2035 let res = parse_u32(next);
2036 let Some(val) = res else { break };
2037 val
2038 }),
2039 67u16 => LinkAttrs::NetnsImmutable({
2040 let res = parse_u8(next);
2041 let Some(val) = res else { break };
2042 val
2043 }),
2044 n => {
2045 if cfg!(any(test, feature = "deny-unknown-attrs")) {
2046 break;
2047 } else {
2048 continue;
2049 }
2050 }
2051 };
2052 return Some(Ok(res));
2053 }
2054 Some(Err(ErrorContext::new(
2055 "LinkAttrs",
2056 r#type.and_then(|t| LinkAttrs::attr_from_type(t)),
2057 self.orig_loc,
2058 self.buf.as_ptr().wrapping_add(pos) as usize,
2059 )))
2060 }
2061}
2062impl<'a> std::fmt::Debug for IterableLinkAttrs<'_> {
2063 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2064 let mut fmt = f.debug_struct("LinkAttrs");
2065 for attr in self.clone() {
2066 let attr = match attr {
2067 Ok(a) => a,
2068 Err(err) => {
2069 fmt.finish()?;
2070 f.write_str("Err(")?;
2071 err.fmt(f)?;
2072 return f.write_str(")");
2073 }
2074 };
2075 match attr {
2076 LinkAttrs::Address(val) => fmt.field("Address", &val),
2077 LinkAttrs::Broadcast(val) => fmt.field("Broadcast", &val),
2078 LinkAttrs::Ifname(val) => fmt.field("Ifname", &val),
2079 LinkAttrs::Mtu(val) => fmt.field("Mtu", &val),
2080 LinkAttrs::Link(val) => fmt.field("Link", &val),
2081 LinkAttrs::Qdisc(val) => fmt.field("Qdisc", &val),
2082 LinkAttrs::Stats(val) => fmt.field("Stats", &val),
2083 LinkAttrs::Cost(val) => fmt.field("Cost", &val),
2084 LinkAttrs::Priority(val) => fmt.field("Priority", &val),
2085 LinkAttrs::Master(val) => fmt.field("Master", &val),
2086 LinkAttrs::Wireless(val) => fmt.field("Wireless", &val),
2087 LinkAttrs::Protinfo(val) => fmt.field("Protinfo", &val),
2088 LinkAttrs::Txqlen(val) => fmt.field("Txqlen", &val),
2089 LinkAttrs::Map(val) => fmt.field("Map", &val),
2090 LinkAttrs::Weight(val) => fmt.field("Weight", &val),
2091 LinkAttrs::Operstate(val) => fmt.field("Operstate", &val),
2092 LinkAttrs::Linkmode(val) => fmt.field("Linkmode", &val),
2093 LinkAttrs::Linkinfo(val) => fmt.field("Linkinfo", &val),
2094 LinkAttrs::NetNsPid(val) => fmt.field("NetNsPid", &val),
2095 LinkAttrs::Ifalias(val) => fmt.field("Ifalias", &val),
2096 LinkAttrs::NumVf(val) => fmt.field("NumVf", &val),
2097 LinkAttrs::VfinfoList(val) => fmt.field("VfinfoList", &val),
2098 LinkAttrs::Stats64(val) => fmt.field("Stats64", &val),
2099 LinkAttrs::VfPorts(val) => fmt.field("VfPorts", &val),
2100 LinkAttrs::PortSelf(val) => fmt.field("PortSelf", &val),
2101 LinkAttrs::AfSpec(val) => fmt.field("AfSpec", &val),
2102 LinkAttrs::Group(val) => fmt.field("Group", &val),
2103 LinkAttrs::NetNsFd(val) => fmt.field("NetNsFd", &val),
2104 LinkAttrs::ExtMask(val) => {
2105 fmt.field("ExtMask", &FormatFlags(val.into(), RtextFilter::from_value))
2106 }
2107 LinkAttrs::Promiscuity(val) => fmt.field("Promiscuity", &val),
2108 LinkAttrs::NumTxQueues(val) => fmt.field("NumTxQueues", &val),
2109 LinkAttrs::NumRxQueues(val) => fmt.field("NumRxQueues", &val),
2110 LinkAttrs::Carrier(val) => fmt.field("Carrier", &val),
2111 LinkAttrs::PhysPortId(val) => fmt.field("PhysPortId", &val),
2112 LinkAttrs::CarrierChanges(val) => fmt.field("CarrierChanges", &val),
2113 LinkAttrs::PhysSwitchId(val) => fmt.field("PhysSwitchId", &val),
2114 LinkAttrs::LinkNetnsid(val) => fmt.field("LinkNetnsid", &val),
2115 LinkAttrs::PhysPortName(val) => fmt.field("PhysPortName", &val),
2116 LinkAttrs::ProtoDown(val) => fmt.field("ProtoDown", &val),
2117 LinkAttrs::GsoMaxSegs(val) => fmt.field("GsoMaxSegs", &val),
2118 LinkAttrs::GsoMaxSize(val) => fmt.field("GsoMaxSize", &val),
2119 LinkAttrs::Pad(val) => fmt.field("Pad", &val),
2120 LinkAttrs::Xdp(val) => fmt.field("Xdp", &val),
2121 LinkAttrs::Event(val) => fmt.field("Event", &val),
2122 LinkAttrs::NewNetnsid(val) => fmt.field("NewNetnsid", &val),
2123 LinkAttrs::TargetNetnsid(val) => fmt.field("TargetNetnsid", &val),
2124 LinkAttrs::CarrierUpCount(val) => fmt.field("CarrierUpCount", &val),
2125 LinkAttrs::CarrierDownCount(val) => fmt.field("CarrierDownCount", &val),
2126 LinkAttrs::NewIfindex(val) => fmt.field("NewIfindex", &val),
2127 LinkAttrs::MinMtu(val) => fmt.field("MinMtu", &val),
2128 LinkAttrs::MaxMtu(val) => fmt.field("MaxMtu", &val),
2129 LinkAttrs::PropList(val) => fmt.field("PropList", &val),
2130 LinkAttrs::AltIfname(val) => fmt.field("AltIfname", &val),
2131 LinkAttrs::PermAddress(val) => fmt.field("PermAddress", &val),
2132 LinkAttrs::ProtoDownReason(val) => fmt.field("ProtoDownReason", &val),
2133 LinkAttrs::ParentDevName(val) => fmt.field("ParentDevName", &val),
2134 LinkAttrs::ParentDevBusName(val) => fmt.field("ParentDevBusName", &val),
2135 LinkAttrs::GroMaxSize(val) => fmt.field("GroMaxSize", &val),
2136 LinkAttrs::TsoMaxSize(val) => fmt.field("TsoMaxSize", &val),
2137 LinkAttrs::TsoMaxSegs(val) => fmt.field("TsoMaxSegs", &val),
2138 LinkAttrs::Allmulti(val) => fmt.field("Allmulti", &val),
2139 LinkAttrs::DevlinkPort(val) => fmt.field("DevlinkPort", &val),
2140 LinkAttrs::GsoIpv4MaxSize(val) => fmt.field("GsoIpv4MaxSize", &val),
2141 LinkAttrs::GroIpv4MaxSize(val) => fmt.field("GroIpv4MaxSize", &val),
2142 LinkAttrs::DpllPin(val) => fmt.field("DpllPin", &val),
2143 LinkAttrs::MaxPacingOffloadHorizon(val) => {
2144 fmt.field("MaxPacingOffloadHorizon", &val)
2145 }
2146 LinkAttrs::NetnsImmutable(val) => fmt.field("NetnsImmutable", &val),
2147 };
2148 }
2149 fmt.finish()
2150 }
2151}
2152impl IterableLinkAttrs<'_> {
2153 pub fn lookup_attr(
2154 &self,
2155 offset: usize,
2156 missing_type: Option<u16>,
2157 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2158 let mut stack = Vec::new();
2159 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2160 if cur == offset {
2161 stack.push(("LinkAttrs", offset));
2162 return (
2163 stack,
2164 missing_type.and_then(|t| LinkAttrs::attr_from_type(t)),
2165 );
2166 }
2167 if cur > offset || cur + self.buf.len() < offset {
2168 return (stack, None);
2169 }
2170 let mut attrs = self.clone();
2171 let mut last_off = cur + attrs.pos;
2172 let mut missing = None;
2173 while let Some(attr) = attrs.next() {
2174 let Ok(attr) = attr else { break };
2175 match attr {
2176 LinkAttrs::Address(val) => {
2177 if last_off == offset {
2178 stack.push(("Address", last_off));
2179 break;
2180 }
2181 }
2182 LinkAttrs::Broadcast(val) => {
2183 if last_off == offset {
2184 stack.push(("Broadcast", last_off));
2185 break;
2186 }
2187 }
2188 LinkAttrs::Ifname(val) => {
2189 if last_off == offset {
2190 stack.push(("Ifname", last_off));
2191 break;
2192 }
2193 }
2194 LinkAttrs::Mtu(val) => {
2195 if last_off == offset {
2196 stack.push(("Mtu", last_off));
2197 break;
2198 }
2199 }
2200 LinkAttrs::Link(val) => {
2201 if last_off == offset {
2202 stack.push(("Link", last_off));
2203 break;
2204 }
2205 }
2206 LinkAttrs::Qdisc(val) => {
2207 if last_off == offset {
2208 stack.push(("Qdisc", last_off));
2209 break;
2210 }
2211 }
2212 LinkAttrs::Stats(val) => {
2213 if last_off == offset {
2214 stack.push(("Stats", last_off));
2215 break;
2216 }
2217 }
2218 LinkAttrs::Cost(val) => {
2219 if last_off == offset {
2220 stack.push(("Cost", last_off));
2221 break;
2222 }
2223 }
2224 LinkAttrs::Priority(val) => {
2225 if last_off == offset {
2226 stack.push(("Priority", last_off));
2227 break;
2228 }
2229 }
2230 LinkAttrs::Master(val) => {
2231 if last_off == offset {
2232 stack.push(("Master", last_off));
2233 break;
2234 }
2235 }
2236 LinkAttrs::Wireless(val) => {
2237 if last_off == offset {
2238 stack.push(("Wireless", last_off));
2239 break;
2240 }
2241 }
2242 LinkAttrs::Protinfo(val) => {
2243 if last_off == offset {
2244 stack.push(("Protinfo", last_off));
2245 break;
2246 }
2247 }
2248 LinkAttrs::Txqlen(val) => {
2249 if last_off == offset {
2250 stack.push(("Txqlen", last_off));
2251 break;
2252 }
2253 }
2254 LinkAttrs::Map(val) => {
2255 if last_off == offset {
2256 stack.push(("Map", last_off));
2257 break;
2258 }
2259 }
2260 LinkAttrs::Weight(val) => {
2261 if last_off == offset {
2262 stack.push(("Weight", last_off));
2263 break;
2264 }
2265 }
2266 LinkAttrs::Operstate(val) => {
2267 if last_off == offset {
2268 stack.push(("Operstate", last_off));
2269 break;
2270 }
2271 }
2272 LinkAttrs::Linkmode(val) => {
2273 if last_off == offset {
2274 stack.push(("Linkmode", last_off));
2275 break;
2276 }
2277 }
2278 LinkAttrs::Linkinfo(val) => {
2279 (stack, missing) = val.lookup_attr(offset, missing_type);
2280 if !stack.is_empty() {
2281 break;
2282 }
2283 }
2284 LinkAttrs::NetNsPid(val) => {
2285 if last_off == offset {
2286 stack.push(("NetNsPid", last_off));
2287 break;
2288 }
2289 }
2290 LinkAttrs::Ifalias(val) => {
2291 if last_off == offset {
2292 stack.push(("Ifalias", last_off));
2293 break;
2294 }
2295 }
2296 LinkAttrs::NumVf(val) => {
2297 if last_off == offset {
2298 stack.push(("NumVf", last_off));
2299 break;
2300 }
2301 }
2302 LinkAttrs::VfinfoList(val) => {
2303 (stack, missing) = val.lookup_attr(offset, missing_type);
2304 if !stack.is_empty() {
2305 break;
2306 }
2307 }
2308 LinkAttrs::Stats64(val) => {
2309 if last_off == offset {
2310 stack.push(("Stats64", last_off));
2311 break;
2312 }
2313 }
2314 LinkAttrs::VfPorts(val) => {
2315 (stack, missing) = val.lookup_attr(offset, missing_type);
2316 if !stack.is_empty() {
2317 break;
2318 }
2319 }
2320 LinkAttrs::PortSelf(val) => {
2321 (stack, missing) = val.lookup_attr(offset, missing_type);
2322 if !stack.is_empty() {
2323 break;
2324 }
2325 }
2326 LinkAttrs::AfSpec(val) => {
2327 (stack, missing) = val.lookup_attr(offset, missing_type);
2328 if !stack.is_empty() {
2329 break;
2330 }
2331 }
2332 LinkAttrs::Group(val) => {
2333 if last_off == offset {
2334 stack.push(("Group", last_off));
2335 break;
2336 }
2337 }
2338 LinkAttrs::NetNsFd(val) => {
2339 if last_off == offset {
2340 stack.push(("NetNsFd", last_off));
2341 break;
2342 }
2343 }
2344 LinkAttrs::ExtMask(val) => {
2345 if last_off == offset {
2346 stack.push(("ExtMask", last_off));
2347 break;
2348 }
2349 }
2350 LinkAttrs::Promiscuity(val) => {
2351 if last_off == offset {
2352 stack.push(("Promiscuity", last_off));
2353 break;
2354 }
2355 }
2356 LinkAttrs::NumTxQueues(val) => {
2357 if last_off == offset {
2358 stack.push(("NumTxQueues", last_off));
2359 break;
2360 }
2361 }
2362 LinkAttrs::NumRxQueues(val) => {
2363 if last_off == offset {
2364 stack.push(("NumRxQueues", last_off));
2365 break;
2366 }
2367 }
2368 LinkAttrs::Carrier(val) => {
2369 if last_off == offset {
2370 stack.push(("Carrier", last_off));
2371 break;
2372 }
2373 }
2374 LinkAttrs::PhysPortId(val) => {
2375 if last_off == offset {
2376 stack.push(("PhysPortId", last_off));
2377 break;
2378 }
2379 }
2380 LinkAttrs::CarrierChanges(val) => {
2381 if last_off == offset {
2382 stack.push(("CarrierChanges", last_off));
2383 break;
2384 }
2385 }
2386 LinkAttrs::PhysSwitchId(val) => {
2387 if last_off == offset {
2388 stack.push(("PhysSwitchId", last_off));
2389 break;
2390 }
2391 }
2392 LinkAttrs::LinkNetnsid(val) => {
2393 if last_off == offset {
2394 stack.push(("LinkNetnsid", last_off));
2395 break;
2396 }
2397 }
2398 LinkAttrs::PhysPortName(val) => {
2399 if last_off == offset {
2400 stack.push(("PhysPortName", last_off));
2401 break;
2402 }
2403 }
2404 LinkAttrs::ProtoDown(val) => {
2405 if last_off == offset {
2406 stack.push(("ProtoDown", last_off));
2407 break;
2408 }
2409 }
2410 LinkAttrs::GsoMaxSegs(val) => {
2411 if last_off == offset {
2412 stack.push(("GsoMaxSegs", last_off));
2413 break;
2414 }
2415 }
2416 LinkAttrs::GsoMaxSize(val) => {
2417 if last_off == offset {
2418 stack.push(("GsoMaxSize", last_off));
2419 break;
2420 }
2421 }
2422 LinkAttrs::Pad(val) => {
2423 if last_off == offset {
2424 stack.push(("Pad", last_off));
2425 break;
2426 }
2427 }
2428 LinkAttrs::Xdp(val) => {
2429 (stack, missing) = val.lookup_attr(offset, missing_type);
2430 if !stack.is_empty() {
2431 break;
2432 }
2433 }
2434 LinkAttrs::Event(val) => {
2435 if last_off == offset {
2436 stack.push(("Event", last_off));
2437 break;
2438 }
2439 }
2440 LinkAttrs::NewNetnsid(val) => {
2441 if last_off == offset {
2442 stack.push(("NewNetnsid", last_off));
2443 break;
2444 }
2445 }
2446 LinkAttrs::TargetNetnsid(val) => {
2447 if last_off == offset {
2448 stack.push(("TargetNetnsid", last_off));
2449 break;
2450 }
2451 }
2452 LinkAttrs::CarrierUpCount(val) => {
2453 if last_off == offset {
2454 stack.push(("CarrierUpCount", last_off));
2455 break;
2456 }
2457 }
2458 LinkAttrs::CarrierDownCount(val) => {
2459 if last_off == offset {
2460 stack.push(("CarrierDownCount", last_off));
2461 break;
2462 }
2463 }
2464 LinkAttrs::NewIfindex(val) => {
2465 if last_off == offset {
2466 stack.push(("NewIfindex", last_off));
2467 break;
2468 }
2469 }
2470 LinkAttrs::MinMtu(val) => {
2471 if last_off == offset {
2472 stack.push(("MinMtu", last_off));
2473 break;
2474 }
2475 }
2476 LinkAttrs::MaxMtu(val) => {
2477 if last_off == offset {
2478 stack.push(("MaxMtu", last_off));
2479 break;
2480 }
2481 }
2482 LinkAttrs::PropList(val) => {
2483 (stack, missing) = val.lookup_attr(offset, missing_type);
2484 if !stack.is_empty() {
2485 break;
2486 }
2487 }
2488 LinkAttrs::AltIfname(val) => {
2489 if last_off == offset {
2490 stack.push(("AltIfname", last_off));
2491 break;
2492 }
2493 }
2494 LinkAttrs::PermAddress(val) => {
2495 if last_off == offset {
2496 stack.push(("PermAddress", last_off));
2497 break;
2498 }
2499 }
2500 LinkAttrs::ProtoDownReason(val) => {
2501 if last_off == offset {
2502 stack.push(("ProtoDownReason", last_off));
2503 break;
2504 }
2505 }
2506 LinkAttrs::ParentDevName(val) => {
2507 if last_off == offset {
2508 stack.push(("ParentDevName", last_off));
2509 break;
2510 }
2511 }
2512 LinkAttrs::ParentDevBusName(val) => {
2513 if last_off == offset {
2514 stack.push(("ParentDevBusName", last_off));
2515 break;
2516 }
2517 }
2518 LinkAttrs::GroMaxSize(val) => {
2519 if last_off == offset {
2520 stack.push(("GroMaxSize", last_off));
2521 break;
2522 }
2523 }
2524 LinkAttrs::TsoMaxSize(val) => {
2525 if last_off == offset {
2526 stack.push(("TsoMaxSize", last_off));
2527 break;
2528 }
2529 }
2530 LinkAttrs::TsoMaxSegs(val) => {
2531 if last_off == offset {
2532 stack.push(("TsoMaxSegs", last_off));
2533 break;
2534 }
2535 }
2536 LinkAttrs::Allmulti(val) => {
2537 if last_off == offset {
2538 stack.push(("Allmulti", last_off));
2539 break;
2540 }
2541 }
2542 LinkAttrs::DevlinkPort(val) => {
2543 if last_off == offset {
2544 stack.push(("DevlinkPort", last_off));
2545 break;
2546 }
2547 }
2548 LinkAttrs::GsoIpv4MaxSize(val) => {
2549 if last_off == offset {
2550 stack.push(("GsoIpv4MaxSize", last_off));
2551 break;
2552 }
2553 }
2554 LinkAttrs::GroIpv4MaxSize(val) => {
2555 if last_off == offset {
2556 stack.push(("GroIpv4MaxSize", last_off));
2557 break;
2558 }
2559 }
2560 LinkAttrs::DpllPin(val) => {
2561 (stack, missing) = val.lookup_attr(offset, missing_type);
2562 if !stack.is_empty() {
2563 break;
2564 }
2565 }
2566 LinkAttrs::MaxPacingOffloadHorizon(val) => {
2567 if last_off == offset {
2568 stack.push(("MaxPacingOffloadHorizon", last_off));
2569 break;
2570 }
2571 }
2572 LinkAttrs::NetnsImmutable(val) => {
2573 if last_off == offset {
2574 stack.push(("NetnsImmutable", last_off));
2575 break;
2576 }
2577 }
2578 _ => {}
2579 };
2580 last_off = cur + attrs.pos;
2581 }
2582 if !stack.is_empty() {
2583 stack.push(("LinkAttrs", cur));
2584 }
2585 (stack, missing)
2586 }
2587}
2588#[derive(Clone)]
2589pub enum PropListLinkAttrs<'a> {
2590 #[doc = "Attribute may repeat multiple times (treat it as array)"]
2591 AltIfname(&'a CStr),
2592}
2593impl<'a> IterablePropListLinkAttrs<'a> {
2594 #[doc = "Attribute may repeat multiple times (treat it as array)"]
2595 pub fn get_alt_ifname(&self) -> MultiAttrIterable<Self, PropListLinkAttrs<'a>, &'a CStr> {
2596 MultiAttrIterable::new(self.clone(), |variant| {
2597 if let PropListLinkAttrs::AltIfname(val) = variant {
2598 Some(val)
2599 } else {
2600 None
2601 }
2602 })
2603 }
2604}
2605impl PropListLinkAttrs<'_> {
2606 pub fn new<'a>(buf: &'a [u8]) -> IterablePropListLinkAttrs<'a> {
2607 IterablePropListLinkAttrs::with_loc(buf, buf.as_ptr() as usize)
2608 }
2609 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2610 LinkAttrs::attr_from_type(r#type)
2611 }
2612}
2613#[derive(Clone, Copy, Default)]
2614pub struct IterablePropListLinkAttrs<'a> {
2615 buf: &'a [u8],
2616 pos: usize,
2617 orig_loc: usize,
2618}
2619impl<'a> IterablePropListLinkAttrs<'a> {
2620 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2621 Self {
2622 buf,
2623 pos: 0,
2624 orig_loc,
2625 }
2626 }
2627 pub fn get_buf(&self) -> &'a [u8] {
2628 self.buf
2629 }
2630}
2631impl<'a> Iterator for IterablePropListLinkAttrs<'a> {
2632 type Item = Result<PropListLinkAttrs<'a>, ErrorContext>;
2633 fn next(&mut self) -> Option<Self::Item> {
2634 if self.buf.len() == self.pos {
2635 return None;
2636 }
2637 let pos = self.pos;
2638 let mut r#type = None;
2639 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
2640 r#type = Some(header.r#type);
2641 let res = match header.r#type {
2642 53u16 => PropListLinkAttrs::AltIfname({
2643 let res = CStr::from_bytes_with_nul(next).ok();
2644 let Some(val) = res else { break };
2645 val
2646 }),
2647 n => {
2648 if cfg!(any(test, feature = "deny-unknown-attrs")) {
2649 break;
2650 } else {
2651 continue;
2652 }
2653 }
2654 };
2655 return Some(Ok(res));
2656 }
2657 Some(Err(ErrorContext::new(
2658 "PropListLinkAttrs",
2659 r#type.and_then(|t| PropListLinkAttrs::attr_from_type(t)),
2660 self.orig_loc,
2661 self.buf.as_ptr().wrapping_add(pos) as usize,
2662 )))
2663 }
2664}
2665impl<'a> std::fmt::Debug for IterablePropListLinkAttrs<'_> {
2666 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2667 let mut fmt = f.debug_struct("PropListLinkAttrs");
2668 for attr in self.clone() {
2669 let attr = match attr {
2670 Ok(a) => a,
2671 Err(err) => {
2672 fmt.finish()?;
2673 f.write_str("Err(")?;
2674 err.fmt(f)?;
2675 return f.write_str(")");
2676 }
2677 };
2678 match attr {
2679 PropListLinkAttrs::AltIfname(val) => fmt.field("AltIfname", &val),
2680 };
2681 }
2682 fmt.finish()
2683 }
2684}
2685impl IterablePropListLinkAttrs<'_> {
2686 pub fn lookup_attr(
2687 &self,
2688 offset: usize,
2689 missing_type: Option<u16>,
2690 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2691 let mut stack = Vec::new();
2692 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2693 if cur == offset {
2694 stack.push(("PropListLinkAttrs", offset));
2695 return (
2696 stack,
2697 missing_type.and_then(|t| PropListLinkAttrs::attr_from_type(t)),
2698 );
2699 }
2700 if cur > offset || cur + self.buf.len() < offset {
2701 return (stack, None);
2702 }
2703 let mut attrs = self.clone();
2704 let mut last_off = cur + attrs.pos;
2705 while let Some(attr) = attrs.next() {
2706 let Ok(attr) = attr else { break };
2707 match attr {
2708 PropListLinkAttrs::AltIfname(val) => {
2709 if last_off == offset {
2710 stack.push(("AltIfname", last_off));
2711 break;
2712 }
2713 }
2714 _ => {}
2715 };
2716 last_off = cur + attrs.pos;
2717 }
2718 if !stack.is_empty() {
2719 stack.push(("PropListLinkAttrs", cur));
2720 }
2721 (stack, None)
2722 }
2723}
2724#[derive(Clone)]
2725pub enum AfSpecAttrs<'a> {
2726 Inet(IterableIflaAttrs<'a>),
2727 Inet6(IterableIfla6Attrs<'a>),
2728 Mctp(IterableMctpAttrs<'a>),
2729}
2730impl<'a> IterableAfSpecAttrs<'a> {
2731 pub fn get_inet(&self) -> Result<IterableIflaAttrs<'a>, ErrorContext> {
2732 let mut iter = self.clone();
2733 iter.pos = 0;
2734 for attr in iter {
2735 if let AfSpecAttrs::Inet(val) = attr? {
2736 return Ok(val);
2737 }
2738 }
2739 Err(ErrorContext::new_missing(
2740 "AfSpecAttrs",
2741 "Inet",
2742 self.orig_loc,
2743 self.buf.as_ptr() as usize,
2744 ))
2745 }
2746 pub fn get_inet6(&self) -> Result<IterableIfla6Attrs<'a>, ErrorContext> {
2747 let mut iter = self.clone();
2748 iter.pos = 0;
2749 for attr in iter {
2750 if let AfSpecAttrs::Inet6(val) = attr? {
2751 return Ok(val);
2752 }
2753 }
2754 Err(ErrorContext::new_missing(
2755 "AfSpecAttrs",
2756 "Inet6",
2757 self.orig_loc,
2758 self.buf.as_ptr() as usize,
2759 ))
2760 }
2761 pub fn get_mctp(&self) -> Result<IterableMctpAttrs<'a>, ErrorContext> {
2762 let mut iter = self.clone();
2763 iter.pos = 0;
2764 for attr in iter {
2765 if let AfSpecAttrs::Mctp(val) = attr? {
2766 return Ok(val);
2767 }
2768 }
2769 Err(ErrorContext::new_missing(
2770 "AfSpecAttrs",
2771 "Mctp",
2772 self.orig_loc,
2773 self.buf.as_ptr() as usize,
2774 ))
2775 }
2776}
2777impl AfSpecAttrs<'_> {
2778 pub fn new<'a>(buf: &'a [u8]) -> IterableAfSpecAttrs<'a> {
2779 IterableAfSpecAttrs::with_loc(buf, buf.as_ptr() as usize)
2780 }
2781 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2782 let res = match r#type {
2783 2u16 => "Inet",
2784 10u16 => "Inet6",
2785 45u16 => "Mctp",
2786 _ => return None,
2787 };
2788 Some(res)
2789 }
2790}
2791#[derive(Clone, Copy, Default)]
2792pub struct IterableAfSpecAttrs<'a> {
2793 buf: &'a [u8],
2794 pos: usize,
2795 orig_loc: usize,
2796}
2797impl<'a> IterableAfSpecAttrs<'a> {
2798 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2799 Self {
2800 buf,
2801 pos: 0,
2802 orig_loc,
2803 }
2804 }
2805 pub fn get_buf(&self) -> &'a [u8] {
2806 self.buf
2807 }
2808}
2809impl<'a> Iterator for IterableAfSpecAttrs<'a> {
2810 type Item = Result<AfSpecAttrs<'a>, ErrorContext>;
2811 fn next(&mut self) -> Option<Self::Item> {
2812 if self.buf.len() == self.pos {
2813 return None;
2814 }
2815 let pos = self.pos;
2816 let mut r#type = None;
2817 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
2818 r#type = Some(header.r#type);
2819 let res = match header.r#type {
2820 2u16 => AfSpecAttrs::Inet({
2821 let res = Some(IterableIflaAttrs::with_loc(next, self.orig_loc));
2822 let Some(val) = res else { break };
2823 val
2824 }),
2825 10u16 => AfSpecAttrs::Inet6({
2826 let res = Some(IterableIfla6Attrs::with_loc(next, self.orig_loc));
2827 let Some(val) = res else { break };
2828 val
2829 }),
2830 45u16 => AfSpecAttrs::Mctp({
2831 let res = Some(IterableMctpAttrs::with_loc(next, self.orig_loc));
2832 let Some(val) = res else { break };
2833 val
2834 }),
2835 n => {
2836 if cfg!(any(test, feature = "deny-unknown-attrs")) {
2837 break;
2838 } else {
2839 continue;
2840 }
2841 }
2842 };
2843 return Some(Ok(res));
2844 }
2845 Some(Err(ErrorContext::new(
2846 "AfSpecAttrs",
2847 r#type.and_then(|t| AfSpecAttrs::attr_from_type(t)),
2848 self.orig_loc,
2849 self.buf.as_ptr().wrapping_add(pos) as usize,
2850 )))
2851 }
2852}
2853impl<'a> std::fmt::Debug for IterableAfSpecAttrs<'_> {
2854 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2855 let mut fmt = f.debug_struct("AfSpecAttrs");
2856 for attr in self.clone() {
2857 let attr = match attr {
2858 Ok(a) => a,
2859 Err(err) => {
2860 fmt.finish()?;
2861 f.write_str("Err(")?;
2862 err.fmt(f)?;
2863 return f.write_str(")");
2864 }
2865 };
2866 match attr {
2867 AfSpecAttrs::Inet(val) => fmt.field("Inet", &val),
2868 AfSpecAttrs::Inet6(val) => fmt.field("Inet6", &val),
2869 AfSpecAttrs::Mctp(val) => fmt.field("Mctp", &val),
2870 };
2871 }
2872 fmt.finish()
2873 }
2874}
2875impl IterableAfSpecAttrs<'_> {
2876 pub fn lookup_attr(
2877 &self,
2878 offset: usize,
2879 missing_type: Option<u16>,
2880 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2881 let mut stack = Vec::new();
2882 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2883 if cur == offset {
2884 stack.push(("AfSpecAttrs", offset));
2885 return (
2886 stack,
2887 missing_type.and_then(|t| AfSpecAttrs::attr_from_type(t)),
2888 );
2889 }
2890 if cur > offset || cur + self.buf.len() < offset {
2891 return (stack, None);
2892 }
2893 let mut attrs = self.clone();
2894 let mut last_off = cur + attrs.pos;
2895 let mut missing = None;
2896 while let Some(attr) = attrs.next() {
2897 let Ok(attr) = attr else { break };
2898 match attr {
2899 AfSpecAttrs::Inet(val) => {
2900 (stack, missing) = val.lookup_attr(offset, missing_type);
2901 if !stack.is_empty() {
2902 break;
2903 }
2904 }
2905 AfSpecAttrs::Inet6(val) => {
2906 (stack, missing) = val.lookup_attr(offset, missing_type);
2907 if !stack.is_empty() {
2908 break;
2909 }
2910 }
2911 AfSpecAttrs::Mctp(val) => {
2912 (stack, missing) = val.lookup_attr(offset, missing_type);
2913 if !stack.is_empty() {
2914 break;
2915 }
2916 }
2917 _ => {}
2918 };
2919 last_off = cur + attrs.pos;
2920 }
2921 if !stack.is_empty() {
2922 stack.push(("AfSpecAttrs", cur));
2923 }
2924 (stack, missing)
2925 }
2926}
2927#[derive(Clone)]
2928pub enum VfinfoListAttrs<'a> {
2929 #[doc = "Attribute may repeat multiple times (treat it as array)"]
2930 Info(IterableVfinfoAttrs<'a>),
2931}
2932impl<'a> IterableVfinfoListAttrs<'a> {
2933 #[doc = "Attribute may repeat multiple times (treat it as array)"]
2934 pub fn get_info(
2935 &self,
2936 ) -> MultiAttrIterable<Self, VfinfoListAttrs<'a>, IterableVfinfoAttrs<'a>> {
2937 MultiAttrIterable::new(self.clone(), |variant| {
2938 if let VfinfoListAttrs::Info(val) = variant {
2939 Some(val)
2940 } else {
2941 None
2942 }
2943 })
2944 }
2945}
2946impl VfinfoListAttrs<'_> {
2947 pub fn new<'a>(buf: &'a [u8]) -> IterableVfinfoListAttrs<'a> {
2948 IterableVfinfoListAttrs::with_loc(buf, buf.as_ptr() as usize)
2949 }
2950 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2951 let res = match r#type {
2952 1u16 => "Info",
2953 _ => return None,
2954 };
2955 Some(res)
2956 }
2957}
2958#[derive(Clone, Copy, Default)]
2959pub struct IterableVfinfoListAttrs<'a> {
2960 buf: &'a [u8],
2961 pos: usize,
2962 orig_loc: usize,
2963}
2964impl<'a> IterableVfinfoListAttrs<'a> {
2965 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2966 Self {
2967 buf,
2968 pos: 0,
2969 orig_loc,
2970 }
2971 }
2972 pub fn get_buf(&self) -> &'a [u8] {
2973 self.buf
2974 }
2975}
2976impl<'a> Iterator for IterableVfinfoListAttrs<'a> {
2977 type Item = Result<VfinfoListAttrs<'a>, ErrorContext>;
2978 fn next(&mut self) -> Option<Self::Item> {
2979 if self.buf.len() == self.pos {
2980 return None;
2981 }
2982 let pos = self.pos;
2983 let mut r#type = None;
2984 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
2985 r#type = Some(header.r#type);
2986 let res = match header.r#type {
2987 1u16 => VfinfoListAttrs::Info({
2988 let res = Some(IterableVfinfoAttrs::with_loc(next, self.orig_loc));
2989 let Some(val) = res else { break };
2990 val
2991 }),
2992 n => {
2993 if cfg!(any(test, feature = "deny-unknown-attrs")) {
2994 break;
2995 } else {
2996 continue;
2997 }
2998 }
2999 };
3000 return Some(Ok(res));
3001 }
3002 Some(Err(ErrorContext::new(
3003 "VfinfoListAttrs",
3004 r#type.and_then(|t| VfinfoListAttrs::attr_from_type(t)),
3005 self.orig_loc,
3006 self.buf.as_ptr().wrapping_add(pos) as usize,
3007 )))
3008 }
3009}
3010impl<'a> std::fmt::Debug for IterableVfinfoListAttrs<'_> {
3011 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3012 let mut fmt = f.debug_struct("VfinfoListAttrs");
3013 for attr in self.clone() {
3014 let attr = match attr {
3015 Ok(a) => a,
3016 Err(err) => {
3017 fmt.finish()?;
3018 f.write_str("Err(")?;
3019 err.fmt(f)?;
3020 return f.write_str(")");
3021 }
3022 };
3023 match attr {
3024 VfinfoListAttrs::Info(val) => fmt.field("Info", &val),
3025 };
3026 }
3027 fmt.finish()
3028 }
3029}
3030impl IterableVfinfoListAttrs<'_> {
3031 pub fn lookup_attr(
3032 &self,
3033 offset: usize,
3034 missing_type: Option<u16>,
3035 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3036 let mut stack = Vec::new();
3037 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3038 if cur == offset {
3039 stack.push(("VfinfoListAttrs", offset));
3040 return (
3041 stack,
3042 missing_type.and_then(|t| VfinfoListAttrs::attr_from_type(t)),
3043 );
3044 }
3045 if cur > offset || cur + self.buf.len() < offset {
3046 return (stack, None);
3047 }
3048 let mut attrs = self.clone();
3049 let mut last_off = cur + attrs.pos;
3050 let mut missing = None;
3051 while let Some(attr) = attrs.next() {
3052 let Ok(attr) = attr else { break };
3053 match attr {
3054 VfinfoListAttrs::Info(val) => {
3055 (stack, missing) = val.lookup_attr(offset, missing_type);
3056 if !stack.is_empty() {
3057 break;
3058 }
3059 }
3060 _ => {}
3061 };
3062 last_off = cur + attrs.pos;
3063 }
3064 if !stack.is_empty() {
3065 stack.push(("VfinfoListAttrs", cur));
3066 }
3067 (stack, missing)
3068 }
3069}
3070#[derive(Clone)]
3071pub enum VfinfoAttrs<'a> {
3072 Mac(PushIflaVfMac),
3073 Vlan(PushIflaVfVlan),
3074 TxRate(PushIflaVfTxRate),
3075 Spoofchk(PushIflaVfSpoofchk),
3076 LinkState(PushIflaVfLinkState),
3077 Rate(PushIflaVfRate),
3078 RssQueryEn(PushIflaVfRssQueryEn),
3079 Stats(IterableVfStatsAttrs<'a>),
3080 Trust(PushIflaVfTrust),
3081 IbNodeGuid(PushIflaVfGuid),
3082 IbPortGuid(PushIflaVfGuid),
3083 VlanList(IterableVfVlanAttrs<'a>),
3084 Broadcast(&'a [u8]),
3085}
3086impl<'a> IterableVfinfoAttrs<'a> {
3087 pub fn get_mac(&self) -> Result<PushIflaVfMac, ErrorContext> {
3088 let mut iter = self.clone();
3089 iter.pos = 0;
3090 for attr in iter {
3091 if let VfinfoAttrs::Mac(val) = attr? {
3092 return Ok(val);
3093 }
3094 }
3095 Err(ErrorContext::new_missing(
3096 "VfinfoAttrs",
3097 "Mac",
3098 self.orig_loc,
3099 self.buf.as_ptr() as usize,
3100 ))
3101 }
3102 pub fn get_vlan(&self) -> Result<PushIflaVfVlan, ErrorContext> {
3103 let mut iter = self.clone();
3104 iter.pos = 0;
3105 for attr in iter {
3106 if let VfinfoAttrs::Vlan(val) = attr? {
3107 return Ok(val);
3108 }
3109 }
3110 Err(ErrorContext::new_missing(
3111 "VfinfoAttrs",
3112 "Vlan",
3113 self.orig_loc,
3114 self.buf.as_ptr() as usize,
3115 ))
3116 }
3117 pub fn get_tx_rate(&self) -> Result<PushIflaVfTxRate, ErrorContext> {
3118 let mut iter = self.clone();
3119 iter.pos = 0;
3120 for attr in iter {
3121 if let VfinfoAttrs::TxRate(val) = attr? {
3122 return Ok(val);
3123 }
3124 }
3125 Err(ErrorContext::new_missing(
3126 "VfinfoAttrs",
3127 "TxRate",
3128 self.orig_loc,
3129 self.buf.as_ptr() as usize,
3130 ))
3131 }
3132 pub fn get_spoofchk(&self) -> Result<PushIflaVfSpoofchk, ErrorContext> {
3133 let mut iter = self.clone();
3134 iter.pos = 0;
3135 for attr in iter {
3136 if let VfinfoAttrs::Spoofchk(val) = attr? {
3137 return Ok(val);
3138 }
3139 }
3140 Err(ErrorContext::new_missing(
3141 "VfinfoAttrs",
3142 "Spoofchk",
3143 self.orig_loc,
3144 self.buf.as_ptr() as usize,
3145 ))
3146 }
3147 pub fn get_link_state(&self) -> Result<PushIflaVfLinkState, ErrorContext> {
3148 let mut iter = self.clone();
3149 iter.pos = 0;
3150 for attr in iter {
3151 if let VfinfoAttrs::LinkState(val) = attr? {
3152 return Ok(val);
3153 }
3154 }
3155 Err(ErrorContext::new_missing(
3156 "VfinfoAttrs",
3157 "LinkState",
3158 self.orig_loc,
3159 self.buf.as_ptr() as usize,
3160 ))
3161 }
3162 pub fn get_rate(&self) -> Result<PushIflaVfRate, ErrorContext> {
3163 let mut iter = self.clone();
3164 iter.pos = 0;
3165 for attr in iter {
3166 if let VfinfoAttrs::Rate(val) = attr? {
3167 return Ok(val);
3168 }
3169 }
3170 Err(ErrorContext::new_missing(
3171 "VfinfoAttrs",
3172 "Rate",
3173 self.orig_loc,
3174 self.buf.as_ptr() as usize,
3175 ))
3176 }
3177 pub fn get_rss_query_en(&self) -> Result<PushIflaVfRssQueryEn, ErrorContext> {
3178 let mut iter = self.clone();
3179 iter.pos = 0;
3180 for attr in iter {
3181 if let VfinfoAttrs::RssQueryEn(val) = attr? {
3182 return Ok(val);
3183 }
3184 }
3185 Err(ErrorContext::new_missing(
3186 "VfinfoAttrs",
3187 "RssQueryEn",
3188 self.orig_loc,
3189 self.buf.as_ptr() as usize,
3190 ))
3191 }
3192 pub fn get_stats(&self) -> Result<IterableVfStatsAttrs<'a>, ErrorContext> {
3193 let mut iter = self.clone();
3194 iter.pos = 0;
3195 for attr in iter {
3196 if let VfinfoAttrs::Stats(val) = attr? {
3197 return Ok(val);
3198 }
3199 }
3200 Err(ErrorContext::new_missing(
3201 "VfinfoAttrs",
3202 "Stats",
3203 self.orig_loc,
3204 self.buf.as_ptr() as usize,
3205 ))
3206 }
3207 pub fn get_trust(&self) -> Result<PushIflaVfTrust, ErrorContext> {
3208 let mut iter = self.clone();
3209 iter.pos = 0;
3210 for attr in iter {
3211 if let VfinfoAttrs::Trust(val) = attr? {
3212 return Ok(val);
3213 }
3214 }
3215 Err(ErrorContext::new_missing(
3216 "VfinfoAttrs",
3217 "Trust",
3218 self.orig_loc,
3219 self.buf.as_ptr() as usize,
3220 ))
3221 }
3222 pub fn get_ib_node_guid(&self) -> Result<PushIflaVfGuid, ErrorContext> {
3223 let mut iter = self.clone();
3224 iter.pos = 0;
3225 for attr in iter {
3226 if let VfinfoAttrs::IbNodeGuid(val) = attr? {
3227 return Ok(val);
3228 }
3229 }
3230 Err(ErrorContext::new_missing(
3231 "VfinfoAttrs",
3232 "IbNodeGuid",
3233 self.orig_loc,
3234 self.buf.as_ptr() as usize,
3235 ))
3236 }
3237 pub fn get_ib_port_guid(&self) -> Result<PushIflaVfGuid, ErrorContext> {
3238 let mut iter = self.clone();
3239 iter.pos = 0;
3240 for attr in iter {
3241 if let VfinfoAttrs::IbPortGuid(val) = attr? {
3242 return Ok(val);
3243 }
3244 }
3245 Err(ErrorContext::new_missing(
3246 "VfinfoAttrs",
3247 "IbPortGuid",
3248 self.orig_loc,
3249 self.buf.as_ptr() as usize,
3250 ))
3251 }
3252 pub fn get_vlan_list(&self) -> Result<IterableVfVlanAttrs<'a>, ErrorContext> {
3253 let mut iter = self.clone();
3254 iter.pos = 0;
3255 for attr in iter {
3256 if let VfinfoAttrs::VlanList(val) = attr? {
3257 return Ok(val);
3258 }
3259 }
3260 Err(ErrorContext::new_missing(
3261 "VfinfoAttrs",
3262 "VlanList",
3263 self.orig_loc,
3264 self.buf.as_ptr() as usize,
3265 ))
3266 }
3267 pub fn get_broadcast(&self) -> Result<&'a [u8], ErrorContext> {
3268 let mut iter = self.clone();
3269 iter.pos = 0;
3270 for attr in iter {
3271 if let VfinfoAttrs::Broadcast(val) = attr? {
3272 return Ok(val);
3273 }
3274 }
3275 Err(ErrorContext::new_missing(
3276 "VfinfoAttrs",
3277 "Broadcast",
3278 self.orig_loc,
3279 self.buf.as_ptr() as usize,
3280 ))
3281 }
3282}
3283impl VfinfoAttrs<'_> {
3284 pub fn new<'a>(buf: &'a [u8]) -> IterableVfinfoAttrs<'a> {
3285 IterableVfinfoAttrs::with_loc(buf, buf.as_ptr() as usize)
3286 }
3287 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3288 let res = match r#type {
3289 1u16 => "Mac",
3290 2u16 => "Vlan",
3291 3u16 => "TxRate",
3292 4u16 => "Spoofchk",
3293 5u16 => "LinkState",
3294 6u16 => "Rate",
3295 7u16 => "RssQueryEn",
3296 8u16 => "Stats",
3297 9u16 => "Trust",
3298 10u16 => "IbNodeGuid",
3299 11u16 => "IbPortGuid",
3300 12u16 => "VlanList",
3301 13u16 => "Broadcast",
3302 _ => return None,
3303 };
3304 Some(res)
3305 }
3306}
3307#[derive(Clone, Copy, Default)]
3308pub struct IterableVfinfoAttrs<'a> {
3309 buf: &'a [u8],
3310 pos: usize,
3311 orig_loc: usize,
3312}
3313impl<'a> IterableVfinfoAttrs<'a> {
3314 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3315 Self {
3316 buf,
3317 pos: 0,
3318 orig_loc,
3319 }
3320 }
3321 pub fn get_buf(&self) -> &'a [u8] {
3322 self.buf
3323 }
3324}
3325impl<'a> Iterator for IterableVfinfoAttrs<'a> {
3326 type Item = Result<VfinfoAttrs<'a>, ErrorContext>;
3327 fn next(&mut self) -> Option<Self::Item> {
3328 if self.buf.len() == self.pos {
3329 return None;
3330 }
3331 let pos = self.pos;
3332 let mut r#type = None;
3333 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
3334 r#type = Some(header.r#type);
3335 let res = match header.r#type {
3336 1u16 => VfinfoAttrs::Mac({
3337 let res = PushIflaVfMac::new_from_slice(next);
3338 let Some(val) = res else { break };
3339 val
3340 }),
3341 2u16 => VfinfoAttrs::Vlan({
3342 let res = PushIflaVfVlan::new_from_slice(next);
3343 let Some(val) = res else { break };
3344 val
3345 }),
3346 3u16 => VfinfoAttrs::TxRate({
3347 let res = PushIflaVfTxRate::new_from_slice(next);
3348 let Some(val) = res else { break };
3349 val
3350 }),
3351 4u16 => VfinfoAttrs::Spoofchk({
3352 let res = PushIflaVfSpoofchk::new_from_slice(next);
3353 let Some(val) = res else { break };
3354 val
3355 }),
3356 5u16 => VfinfoAttrs::LinkState({
3357 let res = PushIflaVfLinkState::new_from_slice(next);
3358 let Some(val) = res else { break };
3359 val
3360 }),
3361 6u16 => VfinfoAttrs::Rate({
3362 let res = PushIflaVfRate::new_from_slice(next);
3363 let Some(val) = res else { break };
3364 val
3365 }),
3366 7u16 => VfinfoAttrs::RssQueryEn({
3367 let res = PushIflaVfRssQueryEn::new_from_slice(next);
3368 let Some(val) = res else { break };
3369 val
3370 }),
3371 8u16 => VfinfoAttrs::Stats({
3372 let res = Some(IterableVfStatsAttrs::with_loc(next, self.orig_loc));
3373 let Some(val) = res else { break };
3374 val
3375 }),
3376 9u16 => VfinfoAttrs::Trust({
3377 let res = PushIflaVfTrust::new_from_slice(next);
3378 let Some(val) = res else { break };
3379 val
3380 }),
3381 10u16 => VfinfoAttrs::IbNodeGuid({
3382 let res = PushIflaVfGuid::new_from_slice(next);
3383 let Some(val) = res else { break };
3384 val
3385 }),
3386 11u16 => VfinfoAttrs::IbPortGuid({
3387 let res = PushIflaVfGuid::new_from_slice(next);
3388 let Some(val) = res else { break };
3389 val
3390 }),
3391 12u16 => VfinfoAttrs::VlanList({
3392 let res = Some(IterableVfVlanAttrs::with_loc(next, self.orig_loc));
3393 let Some(val) = res else { break };
3394 val
3395 }),
3396 13u16 => VfinfoAttrs::Broadcast({
3397 let res = Some(next);
3398 let Some(val) = res else { break };
3399 val
3400 }),
3401 n => {
3402 if cfg!(any(test, feature = "deny-unknown-attrs")) {
3403 break;
3404 } else {
3405 continue;
3406 }
3407 }
3408 };
3409 return Some(Ok(res));
3410 }
3411 Some(Err(ErrorContext::new(
3412 "VfinfoAttrs",
3413 r#type.and_then(|t| VfinfoAttrs::attr_from_type(t)),
3414 self.orig_loc,
3415 self.buf.as_ptr().wrapping_add(pos) as usize,
3416 )))
3417 }
3418}
3419impl<'a> std::fmt::Debug for IterableVfinfoAttrs<'_> {
3420 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3421 let mut fmt = f.debug_struct("VfinfoAttrs");
3422 for attr in self.clone() {
3423 let attr = match attr {
3424 Ok(a) => a,
3425 Err(err) => {
3426 fmt.finish()?;
3427 f.write_str("Err(")?;
3428 err.fmt(f)?;
3429 return f.write_str(")");
3430 }
3431 };
3432 match attr {
3433 VfinfoAttrs::Mac(val) => fmt.field("Mac", &val),
3434 VfinfoAttrs::Vlan(val) => fmt.field("Vlan", &val),
3435 VfinfoAttrs::TxRate(val) => fmt.field("TxRate", &val),
3436 VfinfoAttrs::Spoofchk(val) => fmt.field("Spoofchk", &val),
3437 VfinfoAttrs::LinkState(val) => fmt.field("LinkState", &val),
3438 VfinfoAttrs::Rate(val) => fmt.field("Rate", &val),
3439 VfinfoAttrs::RssQueryEn(val) => fmt.field("RssQueryEn", &val),
3440 VfinfoAttrs::Stats(val) => fmt.field("Stats", &val),
3441 VfinfoAttrs::Trust(val) => fmt.field("Trust", &val),
3442 VfinfoAttrs::IbNodeGuid(val) => fmt.field("IbNodeGuid", &val),
3443 VfinfoAttrs::IbPortGuid(val) => fmt.field("IbPortGuid", &val),
3444 VfinfoAttrs::VlanList(val) => fmt.field("VlanList", &val),
3445 VfinfoAttrs::Broadcast(val) => fmt.field("Broadcast", &val),
3446 };
3447 }
3448 fmt.finish()
3449 }
3450}
3451impl IterableVfinfoAttrs<'_> {
3452 pub fn lookup_attr(
3453 &self,
3454 offset: usize,
3455 missing_type: Option<u16>,
3456 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3457 let mut stack = Vec::new();
3458 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3459 if cur == offset {
3460 stack.push(("VfinfoAttrs", offset));
3461 return (
3462 stack,
3463 missing_type.and_then(|t| VfinfoAttrs::attr_from_type(t)),
3464 );
3465 }
3466 if cur > offset || cur + self.buf.len() < offset {
3467 return (stack, None);
3468 }
3469 let mut attrs = self.clone();
3470 let mut last_off = cur + attrs.pos;
3471 let mut missing = None;
3472 while let Some(attr) = attrs.next() {
3473 let Ok(attr) = attr else { break };
3474 match attr {
3475 VfinfoAttrs::Mac(val) => {
3476 if last_off == offset {
3477 stack.push(("Mac", last_off));
3478 break;
3479 }
3480 }
3481 VfinfoAttrs::Vlan(val) => {
3482 if last_off == offset {
3483 stack.push(("Vlan", last_off));
3484 break;
3485 }
3486 }
3487 VfinfoAttrs::TxRate(val) => {
3488 if last_off == offset {
3489 stack.push(("TxRate", last_off));
3490 break;
3491 }
3492 }
3493 VfinfoAttrs::Spoofchk(val) => {
3494 if last_off == offset {
3495 stack.push(("Spoofchk", last_off));
3496 break;
3497 }
3498 }
3499 VfinfoAttrs::LinkState(val) => {
3500 if last_off == offset {
3501 stack.push(("LinkState", last_off));
3502 break;
3503 }
3504 }
3505 VfinfoAttrs::Rate(val) => {
3506 if last_off == offset {
3507 stack.push(("Rate", last_off));
3508 break;
3509 }
3510 }
3511 VfinfoAttrs::RssQueryEn(val) => {
3512 if last_off == offset {
3513 stack.push(("RssQueryEn", last_off));
3514 break;
3515 }
3516 }
3517 VfinfoAttrs::Stats(val) => {
3518 (stack, missing) = val.lookup_attr(offset, missing_type);
3519 if !stack.is_empty() {
3520 break;
3521 }
3522 }
3523 VfinfoAttrs::Trust(val) => {
3524 if last_off == offset {
3525 stack.push(("Trust", last_off));
3526 break;
3527 }
3528 }
3529 VfinfoAttrs::IbNodeGuid(val) => {
3530 if last_off == offset {
3531 stack.push(("IbNodeGuid", last_off));
3532 break;
3533 }
3534 }
3535 VfinfoAttrs::IbPortGuid(val) => {
3536 if last_off == offset {
3537 stack.push(("IbPortGuid", last_off));
3538 break;
3539 }
3540 }
3541 VfinfoAttrs::VlanList(val) => {
3542 (stack, missing) = val.lookup_attr(offset, missing_type);
3543 if !stack.is_empty() {
3544 break;
3545 }
3546 }
3547 VfinfoAttrs::Broadcast(val) => {
3548 if last_off == offset {
3549 stack.push(("Broadcast", last_off));
3550 break;
3551 }
3552 }
3553 _ => {}
3554 };
3555 last_off = cur + attrs.pos;
3556 }
3557 if !stack.is_empty() {
3558 stack.push(("VfinfoAttrs", cur));
3559 }
3560 (stack, missing)
3561 }
3562}
3563#[derive(Clone)]
3564pub enum VfStatsAttrs<'a> {
3565 RxPackets(u64),
3566 TxPackets(u64),
3567 RxBytes(u64),
3568 TxBytes(u64),
3569 Broadcast(u64),
3570 Multicast(u64),
3571 Pad(&'a [u8]),
3572 RxDropped(u64),
3573 TxDropped(u64),
3574}
3575impl<'a> IterableVfStatsAttrs<'a> {
3576 pub fn get_rx_packets(&self) -> Result<u64, ErrorContext> {
3577 let mut iter = self.clone();
3578 iter.pos = 0;
3579 for attr in iter {
3580 if let VfStatsAttrs::RxPackets(val) = attr? {
3581 return Ok(val);
3582 }
3583 }
3584 Err(ErrorContext::new_missing(
3585 "VfStatsAttrs",
3586 "RxPackets",
3587 self.orig_loc,
3588 self.buf.as_ptr() as usize,
3589 ))
3590 }
3591 pub fn get_tx_packets(&self) -> Result<u64, ErrorContext> {
3592 let mut iter = self.clone();
3593 iter.pos = 0;
3594 for attr in iter {
3595 if let VfStatsAttrs::TxPackets(val) = attr? {
3596 return Ok(val);
3597 }
3598 }
3599 Err(ErrorContext::new_missing(
3600 "VfStatsAttrs",
3601 "TxPackets",
3602 self.orig_loc,
3603 self.buf.as_ptr() as usize,
3604 ))
3605 }
3606 pub fn get_rx_bytes(&self) -> Result<u64, ErrorContext> {
3607 let mut iter = self.clone();
3608 iter.pos = 0;
3609 for attr in iter {
3610 if let VfStatsAttrs::RxBytes(val) = attr? {
3611 return Ok(val);
3612 }
3613 }
3614 Err(ErrorContext::new_missing(
3615 "VfStatsAttrs",
3616 "RxBytes",
3617 self.orig_loc,
3618 self.buf.as_ptr() as usize,
3619 ))
3620 }
3621 pub fn get_tx_bytes(&self) -> Result<u64, ErrorContext> {
3622 let mut iter = self.clone();
3623 iter.pos = 0;
3624 for attr in iter {
3625 if let VfStatsAttrs::TxBytes(val) = attr? {
3626 return Ok(val);
3627 }
3628 }
3629 Err(ErrorContext::new_missing(
3630 "VfStatsAttrs",
3631 "TxBytes",
3632 self.orig_loc,
3633 self.buf.as_ptr() as usize,
3634 ))
3635 }
3636 pub fn get_broadcast(&self) -> Result<u64, ErrorContext> {
3637 let mut iter = self.clone();
3638 iter.pos = 0;
3639 for attr in iter {
3640 if let VfStatsAttrs::Broadcast(val) = attr? {
3641 return Ok(val);
3642 }
3643 }
3644 Err(ErrorContext::new_missing(
3645 "VfStatsAttrs",
3646 "Broadcast",
3647 self.orig_loc,
3648 self.buf.as_ptr() as usize,
3649 ))
3650 }
3651 pub fn get_multicast(&self) -> Result<u64, ErrorContext> {
3652 let mut iter = self.clone();
3653 iter.pos = 0;
3654 for attr in iter {
3655 if let VfStatsAttrs::Multicast(val) = attr? {
3656 return Ok(val);
3657 }
3658 }
3659 Err(ErrorContext::new_missing(
3660 "VfStatsAttrs",
3661 "Multicast",
3662 self.orig_loc,
3663 self.buf.as_ptr() as usize,
3664 ))
3665 }
3666 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
3667 let mut iter = self.clone();
3668 iter.pos = 0;
3669 for attr in iter {
3670 if let VfStatsAttrs::Pad(val) = attr? {
3671 return Ok(val);
3672 }
3673 }
3674 Err(ErrorContext::new_missing(
3675 "VfStatsAttrs",
3676 "Pad",
3677 self.orig_loc,
3678 self.buf.as_ptr() as usize,
3679 ))
3680 }
3681 pub fn get_rx_dropped(&self) -> Result<u64, ErrorContext> {
3682 let mut iter = self.clone();
3683 iter.pos = 0;
3684 for attr in iter {
3685 if let VfStatsAttrs::RxDropped(val) = attr? {
3686 return Ok(val);
3687 }
3688 }
3689 Err(ErrorContext::new_missing(
3690 "VfStatsAttrs",
3691 "RxDropped",
3692 self.orig_loc,
3693 self.buf.as_ptr() as usize,
3694 ))
3695 }
3696 pub fn get_tx_dropped(&self) -> Result<u64, ErrorContext> {
3697 let mut iter = self.clone();
3698 iter.pos = 0;
3699 for attr in iter {
3700 if let VfStatsAttrs::TxDropped(val) = attr? {
3701 return Ok(val);
3702 }
3703 }
3704 Err(ErrorContext::new_missing(
3705 "VfStatsAttrs",
3706 "TxDropped",
3707 self.orig_loc,
3708 self.buf.as_ptr() as usize,
3709 ))
3710 }
3711}
3712impl VfStatsAttrs<'_> {
3713 pub fn new<'a>(buf: &'a [u8]) -> IterableVfStatsAttrs<'a> {
3714 IterableVfStatsAttrs::with_loc(buf, buf.as_ptr() as usize)
3715 }
3716 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3717 let res = match r#type {
3718 0u16 => "RxPackets",
3719 1u16 => "TxPackets",
3720 2u16 => "RxBytes",
3721 3u16 => "TxBytes",
3722 4u16 => "Broadcast",
3723 5u16 => "Multicast",
3724 6u16 => "Pad",
3725 7u16 => "RxDropped",
3726 8u16 => "TxDropped",
3727 _ => return None,
3728 };
3729 Some(res)
3730 }
3731}
3732#[derive(Clone, Copy, Default)]
3733pub struct IterableVfStatsAttrs<'a> {
3734 buf: &'a [u8],
3735 pos: usize,
3736 orig_loc: usize,
3737}
3738impl<'a> IterableVfStatsAttrs<'a> {
3739 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3740 Self {
3741 buf,
3742 pos: 0,
3743 orig_loc,
3744 }
3745 }
3746 pub fn get_buf(&self) -> &'a [u8] {
3747 self.buf
3748 }
3749}
3750impl<'a> Iterator for IterableVfStatsAttrs<'a> {
3751 type Item = Result<VfStatsAttrs<'a>, ErrorContext>;
3752 fn next(&mut self) -> Option<Self::Item> {
3753 if self.buf.len() == self.pos {
3754 return None;
3755 }
3756 let pos = self.pos;
3757 let mut r#type = None;
3758 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
3759 r#type = Some(header.r#type);
3760 let res = match header.r#type {
3761 0u16 => VfStatsAttrs::RxPackets({
3762 let res = parse_u64(next);
3763 let Some(val) = res else { break };
3764 val
3765 }),
3766 1u16 => VfStatsAttrs::TxPackets({
3767 let res = parse_u64(next);
3768 let Some(val) = res else { break };
3769 val
3770 }),
3771 2u16 => VfStatsAttrs::RxBytes({
3772 let res = parse_u64(next);
3773 let Some(val) = res else { break };
3774 val
3775 }),
3776 3u16 => VfStatsAttrs::TxBytes({
3777 let res = parse_u64(next);
3778 let Some(val) = res else { break };
3779 val
3780 }),
3781 4u16 => VfStatsAttrs::Broadcast({
3782 let res = parse_u64(next);
3783 let Some(val) = res else { break };
3784 val
3785 }),
3786 5u16 => VfStatsAttrs::Multicast({
3787 let res = parse_u64(next);
3788 let Some(val) = res else { break };
3789 val
3790 }),
3791 6u16 => VfStatsAttrs::Pad({
3792 let res = Some(next);
3793 let Some(val) = res else { break };
3794 val
3795 }),
3796 7u16 => VfStatsAttrs::RxDropped({
3797 let res = parse_u64(next);
3798 let Some(val) = res else { break };
3799 val
3800 }),
3801 8u16 => VfStatsAttrs::TxDropped({
3802 let res = parse_u64(next);
3803 let Some(val) = res else { break };
3804 val
3805 }),
3806 n => {
3807 if cfg!(any(test, feature = "deny-unknown-attrs")) {
3808 break;
3809 } else {
3810 continue;
3811 }
3812 }
3813 };
3814 return Some(Ok(res));
3815 }
3816 Some(Err(ErrorContext::new(
3817 "VfStatsAttrs",
3818 r#type.and_then(|t| VfStatsAttrs::attr_from_type(t)),
3819 self.orig_loc,
3820 self.buf.as_ptr().wrapping_add(pos) as usize,
3821 )))
3822 }
3823}
3824impl<'a> std::fmt::Debug for IterableVfStatsAttrs<'_> {
3825 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3826 let mut fmt = f.debug_struct("VfStatsAttrs");
3827 for attr in self.clone() {
3828 let attr = match attr {
3829 Ok(a) => a,
3830 Err(err) => {
3831 fmt.finish()?;
3832 f.write_str("Err(")?;
3833 err.fmt(f)?;
3834 return f.write_str(")");
3835 }
3836 };
3837 match attr {
3838 VfStatsAttrs::RxPackets(val) => fmt.field("RxPackets", &val),
3839 VfStatsAttrs::TxPackets(val) => fmt.field("TxPackets", &val),
3840 VfStatsAttrs::RxBytes(val) => fmt.field("RxBytes", &val),
3841 VfStatsAttrs::TxBytes(val) => fmt.field("TxBytes", &val),
3842 VfStatsAttrs::Broadcast(val) => fmt.field("Broadcast", &val),
3843 VfStatsAttrs::Multicast(val) => fmt.field("Multicast", &val),
3844 VfStatsAttrs::Pad(val) => fmt.field("Pad", &val),
3845 VfStatsAttrs::RxDropped(val) => fmt.field("RxDropped", &val),
3846 VfStatsAttrs::TxDropped(val) => fmt.field("TxDropped", &val),
3847 };
3848 }
3849 fmt.finish()
3850 }
3851}
3852impl IterableVfStatsAttrs<'_> {
3853 pub fn lookup_attr(
3854 &self,
3855 offset: usize,
3856 missing_type: Option<u16>,
3857 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3858 let mut stack = Vec::new();
3859 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3860 if cur == offset {
3861 stack.push(("VfStatsAttrs", offset));
3862 return (
3863 stack,
3864 missing_type.and_then(|t| VfStatsAttrs::attr_from_type(t)),
3865 );
3866 }
3867 if cur > offset || cur + self.buf.len() < offset {
3868 return (stack, None);
3869 }
3870 let mut attrs = self.clone();
3871 let mut last_off = cur + attrs.pos;
3872 while let Some(attr) = attrs.next() {
3873 let Ok(attr) = attr else { break };
3874 match attr {
3875 VfStatsAttrs::RxPackets(val) => {
3876 if last_off == offset {
3877 stack.push(("RxPackets", last_off));
3878 break;
3879 }
3880 }
3881 VfStatsAttrs::TxPackets(val) => {
3882 if last_off == offset {
3883 stack.push(("TxPackets", last_off));
3884 break;
3885 }
3886 }
3887 VfStatsAttrs::RxBytes(val) => {
3888 if last_off == offset {
3889 stack.push(("RxBytes", last_off));
3890 break;
3891 }
3892 }
3893 VfStatsAttrs::TxBytes(val) => {
3894 if last_off == offset {
3895 stack.push(("TxBytes", last_off));
3896 break;
3897 }
3898 }
3899 VfStatsAttrs::Broadcast(val) => {
3900 if last_off == offset {
3901 stack.push(("Broadcast", last_off));
3902 break;
3903 }
3904 }
3905 VfStatsAttrs::Multicast(val) => {
3906 if last_off == offset {
3907 stack.push(("Multicast", last_off));
3908 break;
3909 }
3910 }
3911 VfStatsAttrs::Pad(val) => {
3912 if last_off == offset {
3913 stack.push(("Pad", last_off));
3914 break;
3915 }
3916 }
3917 VfStatsAttrs::RxDropped(val) => {
3918 if last_off == offset {
3919 stack.push(("RxDropped", last_off));
3920 break;
3921 }
3922 }
3923 VfStatsAttrs::TxDropped(val) => {
3924 if last_off == offset {
3925 stack.push(("TxDropped", last_off));
3926 break;
3927 }
3928 }
3929 _ => {}
3930 };
3931 last_off = cur + attrs.pos;
3932 }
3933 if !stack.is_empty() {
3934 stack.push(("VfStatsAttrs", cur));
3935 }
3936 (stack, None)
3937 }
3938}
3939#[derive(Clone)]
3940pub enum VfVlanAttrs {
3941 #[doc = "Attribute may repeat multiple times (treat it as array)"]
3942 Info(PushIflaVfVlanInfo),
3943}
3944impl<'a> IterableVfVlanAttrs<'a> {
3945 #[doc = "Attribute may repeat multiple times (treat it as array)"]
3946 pub fn get_info(&self) -> MultiAttrIterable<Self, VfVlanAttrs, PushIflaVfVlanInfo> {
3947 MultiAttrIterable::new(self.clone(), |variant| {
3948 if let VfVlanAttrs::Info(val) = variant {
3949 Some(val)
3950 } else {
3951 None
3952 }
3953 })
3954 }
3955}
3956impl VfVlanAttrs {
3957 pub fn new<'a>(buf: &'a [u8]) -> IterableVfVlanAttrs<'a> {
3958 IterableVfVlanAttrs::with_loc(buf, buf.as_ptr() as usize)
3959 }
3960 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3961 let res = match r#type {
3962 1u16 => "Info",
3963 _ => return None,
3964 };
3965 Some(res)
3966 }
3967}
3968#[derive(Clone, Copy, Default)]
3969pub struct IterableVfVlanAttrs<'a> {
3970 buf: &'a [u8],
3971 pos: usize,
3972 orig_loc: usize,
3973}
3974impl<'a> IterableVfVlanAttrs<'a> {
3975 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3976 Self {
3977 buf,
3978 pos: 0,
3979 orig_loc,
3980 }
3981 }
3982 pub fn get_buf(&self) -> &'a [u8] {
3983 self.buf
3984 }
3985}
3986impl<'a> Iterator for IterableVfVlanAttrs<'a> {
3987 type Item = Result<VfVlanAttrs, ErrorContext>;
3988 fn next(&mut self) -> Option<Self::Item> {
3989 if self.buf.len() == self.pos {
3990 return None;
3991 }
3992 let pos = self.pos;
3993 let mut r#type = None;
3994 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
3995 r#type = Some(header.r#type);
3996 let res = match header.r#type {
3997 1u16 => VfVlanAttrs::Info({
3998 let res = PushIflaVfVlanInfo::new_from_slice(next);
3999 let Some(val) = res else { break };
4000 val
4001 }),
4002 n => {
4003 if cfg!(any(test, feature = "deny-unknown-attrs")) {
4004 break;
4005 } else {
4006 continue;
4007 }
4008 }
4009 };
4010 return Some(Ok(res));
4011 }
4012 Some(Err(ErrorContext::new(
4013 "VfVlanAttrs",
4014 r#type.and_then(|t| VfVlanAttrs::attr_from_type(t)),
4015 self.orig_loc,
4016 self.buf.as_ptr().wrapping_add(pos) as usize,
4017 )))
4018 }
4019}
4020impl std::fmt::Debug for IterableVfVlanAttrs<'_> {
4021 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4022 let mut fmt = f.debug_struct("VfVlanAttrs");
4023 for attr in self.clone() {
4024 let attr = match attr {
4025 Ok(a) => a,
4026 Err(err) => {
4027 fmt.finish()?;
4028 f.write_str("Err(")?;
4029 err.fmt(f)?;
4030 return f.write_str(")");
4031 }
4032 };
4033 match attr {
4034 VfVlanAttrs::Info(val) => fmt.field("Info", &val),
4035 };
4036 }
4037 fmt.finish()
4038 }
4039}
4040impl IterableVfVlanAttrs<'_> {
4041 pub fn lookup_attr(
4042 &self,
4043 offset: usize,
4044 missing_type: Option<u16>,
4045 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
4046 let mut stack = Vec::new();
4047 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
4048 if cur == offset {
4049 stack.push(("VfVlanAttrs", offset));
4050 return (
4051 stack,
4052 missing_type.and_then(|t| VfVlanAttrs::attr_from_type(t)),
4053 );
4054 }
4055 if cur > offset || cur + self.buf.len() < offset {
4056 return (stack, None);
4057 }
4058 let mut attrs = self.clone();
4059 let mut last_off = cur + attrs.pos;
4060 while let Some(attr) = attrs.next() {
4061 let Ok(attr) = attr else { break };
4062 match attr {
4063 VfVlanAttrs::Info(val) => {
4064 if last_off == offset {
4065 stack.push(("Info", last_off));
4066 break;
4067 }
4068 }
4069 _ => {}
4070 };
4071 last_off = cur + attrs.pos;
4072 }
4073 if !stack.is_empty() {
4074 stack.push(("VfVlanAttrs", cur));
4075 }
4076 (stack, None)
4077 }
4078}
4079#[derive(Clone)]
4080pub enum VfPortsAttrs {}
4081impl<'a> IterableVfPortsAttrs<'a> {}
4082impl VfPortsAttrs {
4083 pub fn new<'a>(buf: &'a [u8]) -> IterableVfPortsAttrs<'a> {
4084 IterableVfPortsAttrs::with_loc(buf, buf.as_ptr() as usize)
4085 }
4086 fn attr_from_type(r#type: u16) -> Option<&'static str> {
4087 None
4088 }
4089}
4090#[derive(Clone, Copy, Default)]
4091pub struct IterableVfPortsAttrs<'a> {
4092 buf: &'a [u8],
4093 pos: usize,
4094 orig_loc: usize,
4095}
4096impl<'a> IterableVfPortsAttrs<'a> {
4097 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
4098 Self {
4099 buf,
4100 pos: 0,
4101 orig_loc,
4102 }
4103 }
4104 pub fn get_buf(&self) -> &'a [u8] {
4105 self.buf
4106 }
4107}
4108impl<'a> Iterator for IterableVfPortsAttrs<'a> {
4109 type Item = Result<VfPortsAttrs, ErrorContext>;
4110 fn next(&mut self) -> Option<Self::Item> {
4111 if self.buf.len() == self.pos {
4112 return None;
4113 }
4114 let pos = self.pos;
4115 let mut r#type = None;
4116 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
4117 r#type = Some(header.r#type);
4118 let res = match header.r#type {
4119 n => {
4120 if cfg!(any(test, feature = "deny-unknown-attrs")) {
4121 break;
4122 } else {
4123 continue;
4124 }
4125 }
4126 };
4127 return Some(Ok(res));
4128 }
4129 Some(Err(ErrorContext::new(
4130 "VfPortsAttrs",
4131 r#type.and_then(|t| VfPortsAttrs::attr_from_type(t)),
4132 self.orig_loc,
4133 self.buf.as_ptr().wrapping_add(pos) as usize,
4134 )))
4135 }
4136}
4137impl std::fmt::Debug for IterableVfPortsAttrs<'_> {
4138 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4139 let mut fmt = f.debug_struct("VfPortsAttrs");
4140 for attr in self.clone() {
4141 let attr = match attr {
4142 Ok(a) => a,
4143 Err(err) => {
4144 fmt.finish()?;
4145 f.write_str("Err(")?;
4146 err.fmt(f)?;
4147 return f.write_str(")");
4148 }
4149 };
4150 match attr {};
4151 }
4152 fmt.finish()
4153 }
4154}
4155impl IterableVfPortsAttrs<'_> {
4156 pub fn lookup_attr(
4157 &self,
4158 offset: usize,
4159 missing_type: Option<u16>,
4160 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
4161 let mut stack = Vec::new();
4162 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
4163 if cur == offset {
4164 stack.push(("VfPortsAttrs", offset));
4165 return (
4166 stack,
4167 missing_type.and_then(|t| VfPortsAttrs::attr_from_type(t)),
4168 );
4169 }
4170 (stack, None)
4171 }
4172}
4173#[derive(Clone)]
4174pub enum PortSelfAttrs {}
4175impl<'a> IterablePortSelfAttrs<'a> {}
4176impl PortSelfAttrs {
4177 pub fn new<'a>(buf: &'a [u8]) -> IterablePortSelfAttrs<'a> {
4178 IterablePortSelfAttrs::with_loc(buf, buf.as_ptr() as usize)
4179 }
4180 fn attr_from_type(r#type: u16) -> Option<&'static str> {
4181 None
4182 }
4183}
4184#[derive(Clone, Copy, Default)]
4185pub struct IterablePortSelfAttrs<'a> {
4186 buf: &'a [u8],
4187 pos: usize,
4188 orig_loc: usize,
4189}
4190impl<'a> IterablePortSelfAttrs<'a> {
4191 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
4192 Self {
4193 buf,
4194 pos: 0,
4195 orig_loc,
4196 }
4197 }
4198 pub fn get_buf(&self) -> &'a [u8] {
4199 self.buf
4200 }
4201}
4202impl<'a> Iterator for IterablePortSelfAttrs<'a> {
4203 type Item = Result<PortSelfAttrs, ErrorContext>;
4204 fn next(&mut self) -> Option<Self::Item> {
4205 if self.buf.len() == self.pos {
4206 return None;
4207 }
4208 let pos = self.pos;
4209 let mut r#type = None;
4210 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
4211 r#type = Some(header.r#type);
4212 let res = match header.r#type {
4213 n => {
4214 if cfg!(any(test, feature = "deny-unknown-attrs")) {
4215 break;
4216 } else {
4217 continue;
4218 }
4219 }
4220 };
4221 return Some(Ok(res));
4222 }
4223 Some(Err(ErrorContext::new(
4224 "PortSelfAttrs",
4225 r#type.and_then(|t| PortSelfAttrs::attr_from_type(t)),
4226 self.orig_loc,
4227 self.buf.as_ptr().wrapping_add(pos) as usize,
4228 )))
4229 }
4230}
4231impl std::fmt::Debug for IterablePortSelfAttrs<'_> {
4232 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4233 let mut fmt = f.debug_struct("PortSelfAttrs");
4234 for attr in self.clone() {
4235 let attr = match attr {
4236 Ok(a) => a,
4237 Err(err) => {
4238 fmt.finish()?;
4239 f.write_str("Err(")?;
4240 err.fmt(f)?;
4241 return f.write_str(")");
4242 }
4243 };
4244 match attr {};
4245 }
4246 fmt.finish()
4247 }
4248}
4249impl IterablePortSelfAttrs<'_> {
4250 pub fn lookup_attr(
4251 &self,
4252 offset: usize,
4253 missing_type: Option<u16>,
4254 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
4255 let mut stack = Vec::new();
4256 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
4257 if cur == offset {
4258 stack.push(("PortSelfAttrs", offset));
4259 return (
4260 stack,
4261 missing_type.and_then(|t| PortSelfAttrs::attr_from_type(t)),
4262 );
4263 }
4264 (stack, None)
4265 }
4266}
4267#[derive(Clone)]
4268pub enum LinkinfoAttrs<'a> {
4269 Kind(&'a CStr),
4270 Data(LinkinfoDataMsg<'a>),
4271 Xstats(&'a [u8]),
4272 SlaveKind(&'a CStr),
4273 SlaveData(LinkinfoMemberDataMsg<'a>),
4274}
4275impl<'a> IterableLinkinfoAttrs<'a> {
4276 pub fn get_kind(&self) -> Result<&'a CStr, ErrorContext> {
4277 let mut iter = self.clone();
4278 iter.pos = 0;
4279 for attr in iter {
4280 if let LinkinfoAttrs::Kind(val) = attr? {
4281 return Ok(val);
4282 }
4283 }
4284 Err(ErrorContext::new_missing(
4285 "LinkinfoAttrs",
4286 "Kind",
4287 self.orig_loc,
4288 self.buf.as_ptr() as usize,
4289 ))
4290 }
4291 pub fn get_data(&self) -> Result<LinkinfoDataMsg<'a>, ErrorContext> {
4292 let mut iter = self.clone();
4293 iter.pos = 0;
4294 for attr in iter {
4295 if let LinkinfoAttrs::Data(val) = attr? {
4296 return Ok(val);
4297 }
4298 }
4299 Err(ErrorContext::new_missing(
4300 "LinkinfoAttrs",
4301 "Data",
4302 self.orig_loc,
4303 self.buf.as_ptr() as usize,
4304 ))
4305 }
4306 pub fn get_xstats(&self) -> Result<&'a [u8], ErrorContext> {
4307 let mut iter = self.clone();
4308 iter.pos = 0;
4309 for attr in iter {
4310 if let LinkinfoAttrs::Xstats(val) = attr? {
4311 return Ok(val);
4312 }
4313 }
4314 Err(ErrorContext::new_missing(
4315 "LinkinfoAttrs",
4316 "Xstats",
4317 self.orig_loc,
4318 self.buf.as_ptr() as usize,
4319 ))
4320 }
4321 pub fn get_slave_kind(&self) -> Result<&'a CStr, ErrorContext> {
4322 let mut iter = self.clone();
4323 iter.pos = 0;
4324 for attr in iter {
4325 if let LinkinfoAttrs::SlaveKind(val) = attr? {
4326 return Ok(val);
4327 }
4328 }
4329 Err(ErrorContext::new_missing(
4330 "LinkinfoAttrs",
4331 "SlaveKind",
4332 self.orig_loc,
4333 self.buf.as_ptr() as usize,
4334 ))
4335 }
4336 pub fn get_slave_data(&self) -> Result<LinkinfoMemberDataMsg<'a>, ErrorContext> {
4337 let mut iter = self.clone();
4338 iter.pos = 0;
4339 for attr in iter {
4340 if let LinkinfoAttrs::SlaveData(val) = attr? {
4341 return Ok(val);
4342 }
4343 }
4344 Err(ErrorContext::new_missing(
4345 "LinkinfoAttrs",
4346 "SlaveData",
4347 self.orig_loc,
4348 self.buf.as_ptr() as usize,
4349 ))
4350 }
4351}
4352#[derive(Debug, Clone)]
4353pub enum LinkinfoDataMsg<'a> {
4354 Bond(IterableLinkinfoBondAttrs<'a>),
4355 Bridge(IterableLinkinfoBridgeAttrs<'a>),
4356 Erspan(IterableLinkinfoGreAttrs<'a>),
4357 Gre(IterableLinkinfoGreAttrs<'a>),
4358 Gretap(IterableLinkinfoGreAttrs<'a>),
4359 Ip6gre(IterableLinkinfoGre6Attrs<'a>),
4360 Geneve(IterableLinkinfoGeneveAttrs<'a>),
4361 Ipip(IterableLinkinfoIptunAttrs<'a>),
4362 Ip6tnl(IterableLinkinfoIp6tnlAttrs<'a>),
4363 Sit(IterableLinkinfoIptunAttrs<'a>),
4364 Tun(IterableLinkinfoTunAttrs<'a>),
4365 Vlan(IterableLinkinfoVlanAttrs<'a>),
4366 Vrf(IterableLinkinfoVrfAttrs<'a>),
4367 Vti(IterableLinkinfoVtiAttrs<'a>),
4368 Vti6(IterableLinkinfoVti6Attrs<'a>),
4369 Netkit(IterableLinkinfoNetkitAttrs<'a>),
4370 Ovpn(IterableLinkinfoOvpnAttrs<'a>),
4371}
4372impl<'a> LinkinfoDataMsg<'a> {
4373 fn select_with_loc(selector: &'a CStr, buf: &'a [u8], loc: usize) -> Option<Self> {
4374 match selector.to_bytes() {
4375 b"bond" => Some(LinkinfoDataMsg::Bond(IterableLinkinfoBondAttrs::with_loc(
4376 buf, loc,
4377 ))),
4378 b"bridge" => Some(LinkinfoDataMsg::Bridge(
4379 IterableLinkinfoBridgeAttrs::with_loc(buf, loc),
4380 )),
4381 b"erspan" => Some(LinkinfoDataMsg::Erspan(IterableLinkinfoGreAttrs::with_loc(
4382 buf, loc,
4383 ))),
4384 b"gre" => Some(LinkinfoDataMsg::Gre(IterableLinkinfoGreAttrs::with_loc(
4385 buf, loc,
4386 ))),
4387 b"gretap" => Some(LinkinfoDataMsg::Gretap(IterableLinkinfoGreAttrs::with_loc(
4388 buf, loc,
4389 ))),
4390 b"ip6gre" => Some(LinkinfoDataMsg::Ip6gre(
4391 IterableLinkinfoGre6Attrs::with_loc(buf, loc),
4392 )),
4393 b"geneve" => Some(LinkinfoDataMsg::Geneve(
4394 IterableLinkinfoGeneveAttrs::with_loc(buf, loc),
4395 )),
4396 b"ipip" => Some(LinkinfoDataMsg::Ipip(IterableLinkinfoIptunAttrs::with_loc(
4397 buf, loc,
4398 ))),
4399 b"ip6tnl" => Some(LinkinfoDataMsg::Ip6tnl(
4400 IterableLinkinfoIp6tnlAttrs::with_loc(buf, loc),
4401 )),
4402 b"sit" => Some(LinkinfoDataMsg::Sit(IterableLinkinfoIptunAttrs::with_loc(
4403 buf, loc,
4404 ))),
4405 b"tun" => Some(LinkinfoDataMsg::Tun(IterableLinkinfoTunAttrs::with_loc(
4406 buf, loc,
4407 ))),
4408 b"vlan" => Some(LinkinfoDataMsg::Vlan(IterableLinkinfoVlanAttrs::with_loc(
4409 buf, loc,
4410 ))),
4411 b"vrf" => Some(LinkinfoDataMsg::Vrf(IterableLinkinfoVrfAttrs::with_loc(
4412 buf, loc,
4413 ))),
4414 b"vti" => Some(LinkinfoDataMsg::Vti(IterableLinkinfoVtiAttrs::with_loc(
4415 buf, loc,
4416 ))),
4417 b"vti6" => Some(LinkinfoDataMsg::Vti6(IterableLinkinfoVti6Attrs::with_loc(
4418 buf, loc,
4419 ))),
4420 b"netkit" => Some(LinkinfoDataMsg::Netkit(
4421 IterableLinkinfoNetkitAttrs::with_loc(buf, loc),
4422 )),
4423 b"ovpn" => Some(LinkinfoDataMsg::Ovpn(IterableLinkinfoOvpnAttrs::with_loc(
4424 buf, loc,
4425 ))),
4426 _ => None,
4427 }
4428 }
4429}
4430#[derive(Debug, Clone)]
4431pub enum LinkinfoMemberDataMsg<'a> {
4432 Bridge(IterableLinkinfoBrportAttrs<'a>),
4433 Bond(IterableBondSlaveAttrs<'a>),
4434}
4435impl<'a> LinkinfoMemberDataMsg<'a> {
4436 fn select_with_loc(selector: &'a CStr, buf: &'a [u8], loc: usize) -> Option<Self> {
4437 match selector.to_bytes() {
4438 b"bridge" => Some(LinkinfoMemberDataMsg::Bridge(
4439 IterableLinkinfoBrportAttrs::with_loc(buf, loc),
4440 )),
4441 b"bond" => Some(LinkinfoMemberDataMsg::Bond(
4442 IterableBondSlaveAttrs::with_loc(buf, loc),
4443 )),
4444 _ => None,
4445 }
4446 }
4447}
4448impl LinkinfoAttrs<'_> {
4449 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoAttrs<'a> {
4450 IterableLinkinfoAttrs::with_loc(buf, buf.as_ptr() as usize)
4451 }
4452 fn attr_from_type(r#type: u16) -> Option<&'static str> {
4453 let res = match r#type {
4454 1u16 => "Kind",
4455 2u16 => "Data",
4456 3u16 => "Xstats",
4457 4u16 => "SlaveKind",
4458 5u16 => "SlaveData",
4459 _ => return None,
4460 };
4461 Some(res)
4462 }
4463}
4464#[derive(Clone, Copy, Default)]
4465pub struct IterableLinkinfoAttrs<'a> {
4466 buf: &'a [u8],
4467 pos: usize,
4468 orig_loc: usize,
4469}
4470impl<'a> IterableLinkinfoAttrs<'a> {
4471 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
4472 Self {
4473 buf,
4474 pos: 0,
4475 orig_loc,
4476 }
4477 }
4478 pub fn get_buf(&self) -> &'a [u8] {
4479 self.buf
4480 }
4481}
4482impl<'a> Iterator for IterableLinkinfoAttrs<'a> {
4483 type Item = Result<LinkinfoAttrs<'a>, ErrorContext>;
4484 fn next(&mut self) -> Option<Self::Item> {
4485 if self.buf.len() == self.pos {
4486 return None;
4487 }
4488 let pos = self.pos;
4489 let mut r#type = None;
4490 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
4491 r#type = Some(header.r#type);
4492 let res = match header.r#type {
4493 1u16 => LinkinfoAttrs::Kind({
4494 let res = CStr::from_bytes_with_nul(next).ok();
4495 let Some(val) = res else { break };
4496 val
4497 }),
4498 2u16 => LinkinfoAttrs::Data({
4499 let res = {
4500 let Ok(selector) = self.get_kind() else { break };
4501 LinkinfoDataMsg::select_with_loc(selector, next, self.orig_loc)
4502 };
4503 let Some(val) = res else { break };
4504 val
4505 }),
4506 3u16 => LinkinfoAttrs::Xstats({
4507 let res = Some(next);
4508 let Some(val) = res else { break };
4509 val
4510 }),
4511 4u16 => LinkinfoAttrs::SlaveKind({
4512 let res = CStr::from_bytes_with_nul(next).ok();
4513 let Some(val) = res else { break };
4514 val
4515 }),
4516 5u16 => LinkinfoAttrs::SlaveData({
4517 let res = {
4518 let Ok(selector) = self.get_slave_kind() else {
4519 break;
4520 };
4521 LinkinfoMemberDataMsg::select_with_loc(selector, next, self.orig_loc)
4522 };
4523 let Some(val) = res else { break };
4524 val
4525 }),
4526 n => {
4527 if cfg!(any(test, feature = "deny-unknown-attrs")) {
4528 break;
4529 } else {
4530 continue;
4531 }
4532 }
4533 };
4534 return Some(Ok(res));
4535 }
4536 Some(Err(ErrorContext::new(
4537 "LinkinfoAttrs",
4538 r#type.and_then(|t| LinkinfoAttrs::attr_from_type(t)),
4539 self.orig_loc,
4540 self.buf.as_ptr().wrapping_add(pos) as usize,
4541 )))
4542 }
4543}
4544impl<'a> std::fmt::Debug for IterableLinkinfoAttrs<'_> {
4545 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4546 let mut fmt = f.debug_struct("LinkinfoAttrs");
4547 for attr in self.clone() {
4548 let attr = match attr {
4549 Ok(a) => a,
4550 Err(err) => {
4551 fmt.finish()?;
4552 f.write_str("Err(")?;
4553 err.fmt(f)?;
4554 return f.write_str(")");
4555 }
4556 };
4557 match attr {
4558 LinkinfoAttrs::Kind(val) => fmt.field("Kind", &val),
4559 LinkinfoAttrs::Data(val) => fmt.field("Data", &val),
4560 LinkinfoAttrs::Xstats(val) => fmt.field("Xstats", &val),
4561 LinkinfoAttrs::SlaveKind(val) => fmt.field("SlaveKind", &val),
4562 LinkinfoAttrs::SlaveData(val) => fmt.field("SlaveData", &val),
4563 };
4564 }
4565 fmt.finish()
4566 }
4567}
4568impl IterableLinkinfoAttrs<'_> {
4569 pub fn lookup_attr(
4570 &self,
4571 offset: usize,
4572 missing_type: Option<u16>,
4573 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
4574 let mut stack = Vec::new();
4575 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
4576 if cur == offset {
4577 stack.push(("LinkinfoAttrs", offset));
4578 return (
4579 stack,
4580 missing_type.and_then(|t| LinkinfoAttrs::attr_from_type(t)),
4581 );
4582 }
4583 if cur > offset || cur + self.buf.len() < offset {
4584 return (stack, None);
4585 }
4586 let mut attrs = self.clone();
4587 let mut last_off = cur + attrs.pos;
4588 while let Some(attr) = attrs.next() {
4589 let Ok(attr) = attr else { break };
4590 match attr {
4591 LinkinfoAttrs::Kind(val) => {
4592 if last_off == offset {
4593 stack.push(("Kind", last_off));
4594 break;
4595 }
4596 }
4597 LinkinfoAttrs::Data(val) => {
4598 if last_off == offset {
4599 stack.push(("Data", last_off));
4600 break;
4601 }
4602 }
4603 LinkinfoAttrs::Xstats(val) => {
4604 if last_off == offset {
4605 stack.push(("Xstats", last_off));
4606 break;
4607 }
4608 }
4609 LinkinfoAttrs::SlaveKind(val) => {
4610 if last_off == offset {
4611 stack.push(("SlaveKind", last_off));
4612 break;
4613 }
4614 }
4615 LinkinfoAttrs::SlaveData(val) => {
4616 if last_off == offset {
4617 stack.push(("SlaveData", last_off));
4618 break;
4619 }
4620 }
4621 _ => {}
4622 };
4623 last_off = cur + attrs.pos;
4624 }
4625 if !stack.is_empty() {
4626 stack.push(("LinkinfoAttrs", cur));
4627 }
4628 (stack, None)
4629 }
4630}
4631#[derive(Clone)]
4632pub enum LinkinfoBondAttrs<'a> {
4633 Mode(u8),
4634 ActiveSlave(u32),
4635 Miimon(u32),
4636 Updelay(u32),
4637 Downdelay(u32),
4638 UseCarrier(u8),
4639 ArpInterval(u32),
4640 ArpIpTarget(IterableArrayIpv4Addr<'a>),
4641 ArpValidate(u32),
4642 ArpAllTargets(u32),
4643 Primary(u32),
4644 PrimaryReselect(u8),
4645 FailOverMac(u8),
4646 XmitHashPolicy(u8),
4647 ResendIgmp(u32),
4648 NumPeerNotif(u8),
4649 AllSlavesActive(u8),
4650 MinLinks(u32),
4651 LpInterval(u32),
4652 PacketsPerSlave(u32),
4653 AdLacpRate(u8),
4654 AdSelect(u8),
4655 AdInfo(IterableBondAdInfoAttrs<'a>),
4656 AdActorSysPrio(u16),
4657 AdUserPortKey(u16),
4658 AdActorSystem(&'a [u8]),
4659 TlbDynamicLb(u8),
4660 PeerNotifDelay(u32),
4661 AdLacpActive(u8),
4662 MissedMax(u8),
4663 NsIp6Target(IterableArrayBinary<'a>),
4664 CoupledControl(u8),
4665}
4666impl<'a> IterableLinkinfoBondAttrs<'a> {
4667 pub fn get_mode(&self) -> Result<u8, ErrorContext> {
4668 let mut iter = self.clone();
4669 iter.pos = 0;
4670 for attr in iter {
4671 if let LinkinfoBondAttrs::Mode(val) = attr? {
4672 return Ok(val);
4673 }
4674 }
4675 Err(ErrorContext::new_missing(
4676 "LinkinfoBondAttrs",
4677 "Mode",
4678 self.orig_loc,
4679 self.buf.as_ptr() as usize,
4680 ))
4681 }
4682 pub fn get_active_slave(&self) -> Result<u32, ErrorContext> {
4683 let mut iter = self.clone();
4684 iter.pos = 0;
4685 for attr in iter {
4686 if let LinkinfoBondAttrs::ActiveSlave(val) = attr? {
4687 return Ok(val);
4688 }
4689 }
4690 Err(ErrorContext::new_missing(
4691 "LinkinfoBondAttrs",
4692 "ActiveSlave",
4693 self.orig_loc,
4694 self.buf.as_ptr() as usize,
4695 ))
4696 }
4697 pub fn get_miimon(&self) -> Result<u32, ErrorContext> {
4698 let mut iter = self.clone();
4699 iter.pos = 0;
4700 for attr in iter {
4701 if let LinkinfoBondAttrs::Miimon(val) = attr? {
4702 return Ok(val);
4703 }
4704 }
4705 Err(ErrorContext::new_missing(
4706 "LinkinfoBondAttrs",
4707 "Miimon",
4708 self.orig_loc,
4709 self.buf.as_ptr() as usize,
4710 ))
4711 }
4712 pub fn get_updelay(&self) -> Result<u32, ErrorContext> {
4713 let mut iter = self.clone();
4714 iter.pos = 0;
4715 for attr in iter {
4716 if let LinkinfoBondAttrs::Updelay(val) = attr? {
4717 return Ok(val);
4718 }
4719 }
4720 Err(ErrorContext::new_missing(
4721 "LinkinfoBondAttrs",
4722 "Updelay",
4723 self.orig_loc,
4724 self.buf.as_ptr() as usize,
4725 ))
4726 }
4727 pub fn get_downdelay(&self) -> Result<u32, ErrorContext> {
4728 let mut iter = self.clone();
4729 iter.pos = 0;
4730 for attr in iter {
4731 if let LinkinfoBondAttrs::Downdelay(val) = attr? {
4732 return Ok(val);
4733 }
4734 }
4735 Err(ErrorContext::new_missing(
4736 "LinkinfoBondAttrs",
4737 "Downdelay",
4738 self.orig_loc,
4739 self.buf.as_ptr() as usize,
4740 ))
4741 }
4742 pub fn get_use_carrier(&self) -> Result<u8, ErrorContext> {
4743 let mut iter = self.clone();
4744 iter.pos = 0;
4745 for attr in iter {
4746 if let LinkinfoBondAttrs::UseCarrier(val) = attr? {
4747 return Ok(val);
4748 }
4749 }
4750 Err(ErrorContext::new_missing(
4751 "LinkinfoBondAttrs",
4752 "UseCarrier",
4753 self.orig_loc,
4754 self.buf.as_ptr() as usize,
4755 ))
4756 }
4757 pub fn get_arp_interval(&self) -> Result<u32, ErrorContext> {
4758 let mut iter = self.clone();
4759 iter.pos = 0;
4760 for attr in iter {
4761 if let LinkinfoBondAttrs::ArpInterval(val) = attr? {
4762 return Ok(val);
4763 }
4764 }
4765 Err(ErrorContext::new_missing(
4766 "LinkinfoBondAttrs",
4767 "ArpInterval",
4768 self.orig_loc,
4769 self.buf.as_ptr() as usize,
4770 ))
4771 }
4772 pub fn get_arp_ip_target(
4773 &self,
4774 ) -> Result<ArrayIterable<IterableArrayIpv4Addr<'a>, std::net::Ipv4Addr>, ErrorContext> {
4775 for attr in self.clone() {
4776 if let LinkinfoBondAttrs::ArpIpTarget(val) = attr? {
4777 return Ok(ArrayIterable::new(val));
4778 }
4779 }
4780 Err(ErrorContext::new_missing(
4781 "LinkinfoBondAttrs",
4782 "ArpIpTarget",
4783 self.orig_loc,
4784 self.buf.as_ptr() as usize,
4785 ))
4786 }
4787 pub fn get_arp_validate(&self) -> Result<u32, ErrorContext> {
4788 let mut iter = self.clone();
4789 iter.pos = 0;
4790 for attr in iter {
4791 if let LinkinfoBondAttrs::ArpValidate(val) = attr? {
4792 return Ok(val);
4793 }
4794 }
4795 Err(ErrorContext::new_missing(
4796 "LinkinfoBondAttrs",
4797 "ArpValidate",
4798 self.orig_loc,
4799 self.buf.as_ptr() as usize,
4800 ))
4801 }
4802 pub fn get_arp_all_targets(&self) -> Result<u32, ErrorContext> {
4803 let mut iter = self.clone();
4804 iter.pos = 0;
4805 for attr in iter {
4806 if let LinkinfoBondAttrs::ArpAllTargets(val) = attr? {
4807 return Ok(val);
4808 }
4809 }
4810 Err(ErrorContext::new_missing(
4811 "LinkinfoBondAttrs",
4812 "ArpAllTargets",
4813 self.orig_loc,
4814 self.buf.as_ptr() as usize,
4815 ))
4816 }
4817 pub fn get_primary(&self) -> Result<u32, ErrorContext> {
4818 let mut iter = self.clone();
4819 iter.pos = 0;
4820 for attr in iter {
4821 if let LinkinfoBondAttrs::Primary(val) = attr? {
4822 return Ok(val);
4823 }
4824 }
4825 Err(ErrorContext::new_missing(
4826 "LinkinfoBondAttrs",
4827 "Primary",
4828 self.orig_loc,
4829 self.buf.as_ptr() as usize,
4830 ))
4831 }
4832 pub fn get_primary_reselect(&self) -> Result<u8, ErrorContext> {
4833 let mut iter = self.clone();
4834 iter.pos = 0;
4835 for attr in iter {
4836 if let LinkinfoBondAttrs::PrimaryReselect(val) = attr? {
4837 return Ok(val);
4838 }
4839 }
4840 Err(ErrorContext::new_missing(
4841 "LinkinfoBondAttrs",
4842 "PrimaryReselect",
4843 self.orig_loc,
4844 self.buf.as_ptr() as usize,
4845 ))
4846 }
4847 pub fn get_fail_over_mac(&self) -> Result<u8, ErrorContext> {
4848 let mut iter = self.clone();
4849 iter.pos = 0;
4850 for attr in iter {
4851 if let LinkinfoBondAttrs::FailOverMac(val) = attr? {
4852 return Ok(val);
4853 }
4854 }
4855 Err(ErrorContext::new_missing(
4856 "LinkinfoBondAttrs",
4857 "FailOverMac",
4858 self.orig_loc,
4859 self.buf.as_ptr() as usize,
4860 ))
4861 }
4862 pub fn get_xmit_hash_policy(&self) -> Result<u8, ErrorContext> {
4863 let mut iter = self.clone();
4864 iter.pos = 0;
4865 for attr in iter {
4866 if let LinkinfoBondAttrs::XmitHashPolicy(val) = attr? {
4867 return Ok(val);
4868 }
4869 }
4870 Err(ErrorContext::new_missing(
4871 "LinkinfoBondAttrs",
4872 "XmitHashPolicy",
4873 self.orig_loc,
4874 self.buf.as_ptr() as usize,
4875 ))
4876 }
4877 pub fn get_resend_igmp(&self) -> Result<u32, ErrorContext> {
4878 let mut iter = self.clone();
4879 iter.pos = 0;
4880 for attr in iter {
4881 if let LinkinfoBondAttrs::ResendIgmp(val) = attr? {
4882 return Ok(val);
4883 }
4884 }
4885 Err(ErrorContext::new_missing(
4886 "LinkinfoBondAttrs",
4887 "ResendIgmp",
4888 self.orig_loc,
4889 self.buf.as_ptr() as usize,
4890 ))
4891 }
4892 pub fn get_num_peer_notif(&self) -> Result<u8, ErrorContext> {
4893 let mut iter = self.clone();
4894 iter.pos = 0;
4895 for attr in iter {
4896 if let LinkinfoBondAttrs::NumPeerNotif(val) = attr? {
4897 return Ok(val);
4898 }
4899 }
4900 Err(ErrorContext::new_missing(
4901 "LinkinfoBondAttrs",
4902 "NumPeerNotif",
4903 self.orig_loc,
4904 self.buf.as_ptr() as usize,
4905 ))
4906 }
4907 pub fn get_all_slaves_active(&self) -> Result<u8, ErrorContext> {
4908 let mut iter = self.clone();
4909 iter.pos = 0;
4910 for attr in iter {
4911 if let LinkinfoBondAttrs::AllSlavesActive(val) = attr? {
4912 return Ok(val);
4913 }
4914 }
4915 Err(ErrorContext::new_missing(
4916 "LinkinfoBondAttrs",
4917 "AllSlavesActive",
4918 self.orig_loc,
4919 self.buf.as_ptr() as usize,
4920 ))
4921 }
4922 pub fn get_min_links(&self) -> Result<u32, ErrorContext> {
4923 let mut iter = self.clone();
4924 iter.pos = 0;
4925 for attr in iter {
4926 if let LinkinfoBondAttrs::MinLinks(val) = attr? {
4927 return Ok(val);
4928 }
4929 }
4930 Err(ErrorContext::new_missing(
4931 "LinkinfoBondAttrs",
4932 "MinLinks",
4933 self.orig_loc,
4934 self.buf.as_ptr() as usize,
4935 ))
4936 }
4937 pub fn get_lp_interval(&self) -> Result<u32, ErrorContext> {
4938 let mut iter = self.clone();
4939 iter.pos = 0;
4940 for attr in iter {
4941 if let LinkinfoBondAttrs::LpInterval(val) = attr? {
4942 return Ok(val);
4943 }
4944 }
4945 Err(ErrorContext::new_missing(
4946 "LinkinfoBondAttrs",
4947 "LpInterval",
4948 self.orig_loc,
4949 self.buf.as_ptr() as usize,
4950 ))
4951 }
4952 pub fn get_packets_per_slave(&self) -> Result<u32, ErrorContext> {
4953 let mut iter = self.clone();
4954 iter.pos = 0;
4955 for attr in iter {
4956 if let LinkinfoBondAttrs::PacketsPerSlave(val) = attr? {
4957 return Ok(val);
4958 }
4959 }
4960 Err(ErrorContext::new_missing(
4961 "LinkinfoBondAttrs",
4962 "PacketsPerSlave",
4963 self.orig_loc,
4964 self.buf.as_ptr() as usize,
4965 ))
4966 }
4967 pub fn get_ad_lacp_rate(&self) -> Result<u8, ErrorContext> {
4968 let mut iter = self.clone();
4969 iter.pos = 0;
4970 for attr in iter {
4971 if let LinkinfoBondAttrs::AdLacpRate(val) = attr? {
4972 return Ok(val);
4973 }
4974 }
4975 Err(ErrorContext::new_missing(
4976 "LinkinfoBondAttrs",
4977 "AdLacpRate",
4978 self.orig_loc,
4979 self.buf.as_ptr() as usize,
4980 ))
4981 }
4982 pub fn get_ad_select(&self) -> Result<u8, ErrorContext> {
4983 let mut iter = self.clone();
4984 iter.pos = 0;
4985 for attr in iter {
4986 if let LinkinfoBondAttrs::AdSelect(val) = attr? {
4987 return Ok(val);
4988 }
4989 }
4990 Err(ErrorContext::new_missing(
4991 "LinkinfoBondAttrs",
4992 "AdSelect",
4993 self.orig_loc,
4994 self.buf.as_ptr() as usize,
4995 ))
4996 }
4997 pub fn get_ad_info(&self) -> Result<IterableBondAdInfoAttrs<'a>, ErrorContext> {
4998 let mut iter = self.clone();
4999 iter.pos = 0;
5000 for attr in iter {
5001 if let LinkinfoBondAttrs::AdInfo(val) = attr? {
5002 return Ok(val);
5003 }
5004 }
5005 Err(ErrorContext::new_missing(
5006 "LinkinfoBondAttrs",
5007 "AdInfo",
5008 self.orig_loc,
5009 self.buf.as_ptr() as usize,
5010 ))
5011 }
5012 pub fn get_ad_actor_sys_prio(&self) -> Result<u16, ErrorContext> {
5013 let mut iter = self.clone();
5014 iter.pos = 0;
5015 for attr in iter {
5016 if let LinkinfoBondAttrs::AdActorSysPrio(val) = attr? {
5017 return Ok(val);
5018 }
5019 }
5020 Err(ErrorContext::new_missing(
5021 "LinkinfoBondAttrs",
5022 "AdActorSysPrio",
5023 self.orig_loc,
5024 self.buf.as_ptr() as usize,
5025 ))
5026 }
5027 pub fn get_ad_user_port_key(&self) -> Result<u16, ErrorContext> {
5028 let mut iter = self.clone();
5029 iter.pos = 0;
5030 for attr in iter {
5031 if let LinkinfoBondAttrs::AdUserPortKey(val) = attr? {
5032 return Ok(val);
5033 }
5034 }
5035 Err(ErrorContext::new_missing(
5036 "LinkinfoBondAttrs",
5037 "AdUserPortKey",
5038 self.orig_loc,
5039 self.buf.as_ptr() as usize,
5040 ))
5041 }
5042 pub fn get_ad_actor_system(&self) -> Result<&'a [u8], ErrorContext> {
5043 let mut iter = self.clone();
5044 iter.pos = 0;
5045 for attr in iter {
5046 if let LinkinfoBondAttrs::AdActorSystem(val) = attr? {
5047 return Ok(val);
5048 }
5049 }
5050 Err(ErrorContext::new_missing(
5051 "LinkinfoBondAttrs",
5052 "AdActorSystem",
5053 self.orig_loc,
5054 self.buf.as_ptr() as usize,
5055 ))
5056 }
5057 pub fn get_tlb_dynamic_lb(&self) -> Result<u8, ErrorContext> {
5058 let mut iter = self.clone();
5059 iter.pos = 0;
5060 for attr in iter {
5061 if let LinkinfoBondAttrs::TlbDynamicLb(val) = attr? {
5062 return Ok(val);
5063 }
5064 }
5065 Err(ErrorContext::new_missing(
5066 "LinkinfoBondAttrs",
5067 "TlbDynamicLb",
5068 self.orig_loc,
5069 self.buf.as_ptr() as usize,
5070 ))
5071 }
5072 pub fn get_peer_notif_delay(&self) -> Result<u32, ErrorContext> {
5073 let mut iter = self.clone();
5074 iter.pos = 0;
5075 for attr in iter {
5076 if let LinkinfoBondAttrs::PeerNotifDelay(val) = attr? {
5077 return Ok(val);
5078 }
5079 }
5080 Err(ErrorContext::new_missing(
5081 "LinkinfoBondAttrs",
5082 "PeerNotifDelay",
5083 self.orig_loc,
5084 self.buf.as_ptr() as usize,
5085 ))
5086 }
5087 pub fn get_ad_lacp_active(&self) -> Result<u8, ErrorContext> {
5088 let mut iter = self.clone();
5089 iter.pos = 0;
5090 for attr in iter {
5091 if let LinkinfoBondAttrs::AdLacpActive(val) = attr? {
5092 return Ok(val);
5093 }
5094 }
5095 Err(ErrorContext::new_missing(
5096 "LinkinfoBondAttrs",
5097 "AdLacpActive",
5098 self.orig_loc,
5099 self.buf.as_ptr() as usize,
5100 ))
5101 }
5102 pub fn get_missed_max(&self) -> Result<u8, ErrorContext> {
5103 let mut iter = self.clone();
5104 iter.pos = 0;
5105 for attr in iter {
5106 if let LinkinfoBondAttrs::MissedMax(val) = attr? {
5107 return Ok(val);
5108 }
5109 }
5110 Err(ErrorContext::new_missing(
5111 "LinkinfoBondAttrs",
5112 "MissedMax",
5113 self.orig_loc,
5114 self.buf.as_ptr() as usize,
5115 ))
5116 }
5117 pub fn get_ns_ip6_target(
5118 &self,
5119 ) -> Result<ArrayIterable<IterableArrayBinary<'a>, &'a [u8]>, ErrorContext> {
5120 for attr in self.clone() {
5121 if let LinkinfoBondAttrs::NsIp6Target(val) = attr? {
5122 return Ok(ArrayIterable::new(val));
5123 }
5124 }
5125 Err(ErrorContext::new_missing(
5126 "LinkinfoBondAttrs",
5127 "NsIp6Target",
5128 self.orig_loc,
5129 self.buf.as_ptr() as usize,
5130 ))
5131 }
5132 pub fn get_coupled_control(&self) -> Result<u8, ErrorContext> {
5133 let mut iter = self.clone();
5134 iter.pos = 0;
5135 for attr in iter {
5136 if let LinkinfoBondAttrs::CoupledControl(val) = attr? {
5137 return Ok(val);
5138 }
5139 }
5140 Err(ErrorContext::new_missing(
5141 "LinkinfoBondAttrs",
5142 "CoupledControl",
5143 self.orig_loc,
5144 self.buf.as_ptr() as usize,
5145 ))
5146 }
5147}
5148#[derive(Clone, Copy, Default)]
5149pub struct IterableArrayIpv4Addr<'a> {
5150 buf: &'a [u8],
5151 pos: usize,
5152 orig_loc: usize,
5153}
5154impl<'a> IterableArrayIpv4Addr<'a> {
5155 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5156 Self {
5157 buf,
5158 pos: 0,
5159 orig_loc,
5160 }
5161 }
5162 pub fn get_buf(&self) -> &'a [u8] {
5163 self.buf
5164 }
5165}
5166impl<'a> Iterator for IterableArrayIpv4Addr<'a> {
5167 type Item = Result<std::net::Ipv4Addr, ErrorContext>;
5168 fn next(&mut self) -> Option<Self::Item> {
5169 if self.buf.len() == self.pos {
5170 return None;
5171 }
5172 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
5173 {
5174 let Some(res) = parse_be_u32(next).map(Ipv4Addr::from_bits) else {
5175 break;
5176 };
5177 return Some(Ok(res));
5178 }
5179 }
5180 Some(Err(ErrorContext::new(
5181 "Ipv4Addr",
5182 None,
5183 self.orig_loc,
5184 self.buf.as_ptr().wrapping_add(self.pos) as usize,
5185 )))
5186 }
5187}
5188#[derive(Clone, Copy, Default)]
5189pub struct IterableArrayBinary<'a> {
5190 buf: &'a [u8],
5191 pos: usize,
5192 orig_loc: usize,
5193}
5194impl<'a> IterableArrayBinary<'a> {
5195 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5196 Self {
5197 buf,
5198 pos: 0,
5199 orig_loc,
5200 }
5201 }
5202 pub fn get_buf(&self) -> &'a [u8] {
5203 self.buf
5204 }
5205}
5206impl<'a> Iterator for IterableArrayBinary<'a> {
5207 type Item = Result<&'a [u8], ErrorContext>;
5208 fn next(&mut self) -> Option<Self::Item> {
5209 if self.buf.len() == self.pos {
5210 return None;
5211 }
5212 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
5213 {
5214 let Some(res) = Some(next) else { break };
5215 return Some(Ok(res));
5216 }
5217 }
5218 Some(Err(ErrorContext::new(
5219 "Binary",
5220 None,
5221 self.orig_loc,
5222 self.buf.as_ptr().wrapping_add(self.pos) as usize,
5223 )))
5224 }
5225}
5226impl LinkinfoBondAttrs<'_> {
5227 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoBondAttrs<'a> {
5228 IterableLinkinfoBondAttrs::with_loc(buf, buf.as_ptr() as usize)
5229 }
5230 fn attr_from_type(r#type: u16) -> Option<&'static str> {
5231 let res = match r#type {
5232 1u16 => "Mode",
5233 2u16 => "ActiveSlave",
5234 3u16 => "Miimon",
5235 4u16 => "Updelay",
5236 5u16 => "Downdelay",
5237 6u16 => "UseCarrier",
5238 7u16 => "ArpInterval",
5239 8u16 => "ArpIpTarget",
5240 9u16 => "ArpValidate",
5241 10u16 => "ArpAllTargets",
5242 11u16 => "Primary",
5243 12u16 => "PrimaryReselect",
5244 13u16 => "FailOverMac",
5245 14u16 => "XmitHashPolicy",
5246 15u16 => "ResendIgmp",
5247 16u16 => "NumPeerNotif",
5248 17u16 => "AllSlavesActive",
5249 18u16 => "MinLinks",
5250 19u16 => "LpInterval",
5251 20u16 => "PacketsPerSlave",
5252 21u16 => "AdLacpRate",
5253 22u16 => "AdSelect",
5254 23u16 => "AdInfo",
5255 24u16 => "AdActorSysPrio",
5256 25u16 => "AdUserPortKey",
5257 26u16 => "AdActorSystem",
5258 27u16 => "TlbDynamicLb",
5259 28u16 => "PeerNotifDelay",
5260 29u16 => "AdLacpActive",
5261 30u16 => "MissedMax",
5262 31u16 => "NsIp6Target",
5263 32u16 => "CoupledControl",
5264 _ => return None,
5265 };
5266 Some(res)
5267 }
5268}
5269#[derive(Clone, Copy, Default)]
5270pub struct IterableLinkinfoBondAttrs<'a> {
5271 buf: &'a [u8],
5272 pos: usize,
5273 orig_loc: usize,
5274}
5275impl<'a> IterableLinkinfoBondAttrs<'a> {
5276 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5277 Self {
5278 buf,
5279 pos: 0,
5280 orig_loc,
5281 }
5282 }
5283 pub fn get_buf(&self) -> &'a [u8] {
5284 self.buf
5285 }
5286}
5287impl<'a> Iterator for IterableLinkinfoBondAttrs<'a> {
5288 type Item = Result<LinkinfoBondAttrs<'a>, ErrorContext>;
5289 fn next(&mut self) -> Option<Self::Item> {
5290 if self.buf.len() == self.pos {
5291 return None;
5292 }
5293 let pos = self.pos;
5294 let mut r#type = None;
5295 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
5296 r#type = Some(header.r#type);
5297 let res = match header.r#type {
5298 1u16 => LinkinfoBondAttrs::Mode({
5299 let res = parse_u8(next);
5300 let Some(val) = res else { break };
5301 val
5302 }),
5303 2u16 => LinkinfoBondAttrs::ActiveSlave({
5304 let res = parse_u32(next);
5305 let Some(val) = res else { break };
5306 val
5307 }),
5308 3u16 => LinkinfoBondAttrs::Miimon({
5309 let res = parse_u32(next);
5310 let Some(val) = res else { break };
5311 val
5312 }),
5313 4u16 => LinkinfoBondAttrs::Updelay({
5314 let res = parse_u32(next);
5315 let Some(val) = res else { break };
5316 val
5317 }),
5318 5u16 => LinkinfoBondAttrs::Downdelay({
5319 let res = parse_u32(next);
5320 let Some(val) = res else { break };
5321 val
5322 }),
5323 6u16 => LinkinfoBondAttrs::UseCarrier({
5324 let res = parse_u8(next);
5325 let Some(val) = res else { break };
5326 val
5327 }),
5328 7u16 => LinkinfoBondAttrs::ArpInterval({
5329 let res = parse_u32(next);
5330 let Some(val) = res else { break };
5331 val
5332 }),
5333 8u16 => LinkinfoBondAttrs::ArpIpTarget({
5334 let res = Some(IterableArrayIpv4Addr::with_loc(next, self.orig_loc));
5335 let Some(val) = res else { break };
5336 val
5337 }),
5338 9u16 => LinkinfoBondAttrs::ArpValidate({
5339 let res = parse_u32(next);
5340 let Some(val) = res else { break };
5341 val
5342 }),
5343 10u16 => LinkinfoBondAttrs::ArpAllTargets({
5344 let res = parse_u32(next);
5345 let Some(val) = res else { break };
5346 val
5347 }),
5348 11u16 => LinkinfoBondAttrs::Primary({
5349 let res = parse_u32(next);
5350 let Some(val) = res else { break };
5351 val
5352 }),
5353 12u16 => LinkinfoBondAttrs::PrimaryReselect({
5354 let res = parse_u8(next);
5355 let Some(val) = res else { break };
5356 val
5357 }),
5358 13u16 => LinkinfoBondAttrs::FailOverMac({
5359 let res = parse_u8(next);
5360 let Some(val) = res else { break };
5361 val
5362 }),
5363 14u16 => LinkinfoBondAttrs::XmitHashPolicy({
5364 let res = parse_u8(next);
5365 let Some(val) = res else { break };
5366 val
5367 }),
5368 15u16 => LinkinfoBondAttrs::ResendIgmp({
5369 let res = parse_u32(next);
5370 let Some(val) = res else { break };
5371 val
5372 }),
5373 16u16 => LinkinfoBondAttrs::NumPeerNotif({
5374 let res = parse_u8(next);
5375 let Some(val) = res else { break };
5376 val
5377 }),
5378 17u16 => LinkinfoBondAttrs::AllSlavesActive({
5379 let res = parse_u8(next);
5380 let Some(val) = res else { break };
5381 val
5382 }),
5383 18u16 => LinkinfoBondAttrs::MinLinks({
5384 let res = parse_u32(next);
5385 let Some(val) = res else { break };
5386 val
5387 }),
5388 19u16 => LinkinfoBondAttrs::LpInterval({
5389 let res = parse_u32(next);
5390 let Some(val) = res else { break };
5391 val
5392 }),
5393 20u16 => LinkinfoBondAttrs::PacketsPerSlave({
5394 let res = parse_u32(next);
5395 let Some(val) = res else { break };
5396 val
5397 }),
5398 21u16 => LinkinfoBondAttrs::AdLacpRate({
5399 let res = parse_u8(next);
5400 let Some(val) = res else { break };
5401 val
5402 }),
5403 22u16 => LinkinfoBondAttrs::AdSelect({
5404 let res = parse_u8(next);
5405 let Some(val) = res else { break };
5406 val
5407 }),
5408 23u16 => LinkinfoBondAttrs::AdInfo({
5409 let res = Some(IterableBondAdInfoAttrs::with_loc(next, self.orig_loc));
5410 let Some(val) = res else { break };
5411 val
5412 }),
5413 24u16 => LinkinfoBondAttrs::AdActorSysPrio({
5414 let res = parse_u16(next);
5415 let Some(val) = res else { break };
5416 val
5417 }),
5418 25u16 => LinkinfoBondAttrs::AdUserPortKey({
5419 let res = parse_u16(next);
5420 let Some(val) = res else { break };
5421 val
5422 }),
5423 26u16 => LinkinfoBondAttrs::AdActorSystem({
5424 let res = Some(next);
5425 let Some(val) = res else { break };
5426 val
5427 }),
5428 27u16 => LinkinfoBondAttrs::TlbDynamicLb({
5429 let res = parse_u8(next);
5430 let Some(val) = res else { break };
5431 val
5432 }),
5433 28u16 => LinkinfoBondAttrs::PeerNotifDelay({
5434 let res = parse_u32(next);
5435 let Some(val) = res else { break };
5436 val
5437 }),
5438 29u16 => LinkinfoBondAttrs::AdLacpActive({
5439 let res = parse_u8(next);
5440 let Some(val) = res else { break };
5441 val
5442 }),
5443 30u16 => LinkinfoBondAttrs::MissedMax({
5444 let res = parse_u8(next);
5445 let Some(val) = res else { break };
5446 val
5447 }),
5448 31u16 => LinkinfoBondAttrs::NsIp6Target({
5449 let res = Some(IterableArrayBinary::with_loc(next, self.orig_loc));
5450 let Some(val) = res else { break };
5451 val
5452 }),
5453 32u16 => LinkinfoBondAttrs::CoupledControl({
5454 let res = parse_u8(next);
5455 let Some(val) = res else { break };
5456 val
5457 }),
5458 n => {
5459 if cfg!(any(test, feature = "deny-unknown-attrs")) {
5460 break;
5461 } else {
5462 continue;
5463 }
5464 }
5465 };
5466 return Some(Ok(res));
5467 }
5468 Some(Err(ErrorContext::new(
5469 "LinkinfoBondAttrs",
5470 r#type.and_then(|t| LinkinfoBondAttrs::attr_from_type(t)),
5471 self.orig_loc,
5472 self.buf.as_ptr().wrapping_add(pos) as usize,
5473 )))
5474 }
5475}
5476impl std::fmt::Debug for IterableArrayIpv4Addr<'_> {
5477 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5478 fmt.debug_list()
5479 .entries(self.clone().map(FlattenErrorContext))
5480 .finish()
5481 }
5482}
5483impl std::fmt::Debug for IterableArrayBinary<'_> {
5484 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5485 fmt.debug_list()
5486 .entries(self.clone().map(FlattenErrorContext))
5487 .finish()
5488 }
5489}
5490impl<'a> std::fmt::Debug for IterableLinkinfoBondAttrs<'_> {
5491 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5492 let mut fmt = f.debug_struct("LinkinfoBondAttrs");
5493 for attr in self.clone() {
5494 let attr = match attr {
5495 Ok(a) => a,
5496 Err(err) => {
5497 fmt.finish()?;
5498 f.write_str("Err(")?;
5499 err.fmt(f)?;
5500 return f.write_str(")");
5501 }
5502 };
5503 match attr {
5504 LinkinfoBondAttrs::Mode(val) => fmt.field("Mode", &val),
5505 LinkinfoBondAttrs::ActiveSlave(val) => fmt.field("ActiveSlave", &val),
5506 LinkinfoBondAttrs::Miimon(val) => fmt.field("Miimon", &val),
5507 LinkinfoBondAttrs::Updelay(val) => fmt.field("Updelay", &val),
5508 LinkinfoBondAttrs::Downdelay(val) => fmt.field("Downdelay", &val),
5509 LinkinfoBondAttrs::UseCarrier(val) => fmt.field("UseCarrier", &val),
5510 LinkinfoBondAttrs::ArpInterval(val) => fmt.field("ArpInterval", &val),
5511 LinkinfoBondAttrs::ArpIpTarget(val) => fmt.field("ArpIpTarget", &val),
5512 LinkinfoBondAttrs::ArpValidate(val) => fmt.field("ArpValidate", &val),
5513 LinkinfoBondAttrs::ArpAllTargets(val) => fmt.field("ArpAllTargets", &val),
5514 LinkinfoBondAttrs::Primary(val) => fmt.field("Primary", &val),
5515 LinkinfoBondAttrs::PrimaryReselect(val) => fmt.field("PrimaryReselect", &val),
5516 LinkinfoBondAttrs::FailOverMac(val) => fmt.field("FailOverMac", &val),
5517 LinkinfoBondAttrs::XmitHashPolicy(val) => fmt.field("XmitHashPolicy", &val),
5518 LinkinfoBondAttrs::ResendIgmp(val) => fmt.field("ResendIgmp", &val),
5519 LinkinfoBondAttrs::NumPeerNotif(val) => fmt.field("NumPeerNotif", &val),
5520 LinkinfoBondAttrs::AllSlavesActive(val) => fmt.field("AllSlavesActive", &val),
5521 LinkinfoBondAttrs::MinLinks(val) => fmt.field("MinLinks", &val),
5522 LinkinfoBondAttrs::LpInterval(val) => fmt.field("LpInterval", &val),
5523 LinkinfoBondAttrs::PacketsPerSlave(val) => fmt.field("PacketsPerSlave", &val),
5524 LinkinfoBondAttrs::AdLacpRate(val) => fmt.field("AdLacpRate", &val),
5525 LinkinfoBondAttrs::AdSelect(val) => fmt.field("AdSelect", &val),
5526 LinkinfoBondAttrs::AdInfo(val) => fmt.field("AdInfo", &val),
5527 LinkinfoBondAttrs::AdActorSysPrio(val) => fmt.field("AdActorSysPrio", &val),
5528 LinkinfoBondAttrs::AdUserPortKey(val) => fmt.field("AdUserPortKey", &val),
5529 LinkinfoBondAttrs::AdActorSystem(val) => fmt.field("AdActorSystem", &val),
5530 LinkinfoBondAttrs::TlbDynamicLb(val) => fmt.field("TlbDynamicLb", &val),
5531 LinkinfoBondAttrs::PeerNotifDelay(val) => fmt.field("PeerNotifDelay", &val),
5532 LinkinfoBondAttrs::AdLacpActive(val) => fmt.field("AdLacpActive", &val),
5533 LinkinfoBondAttrs::MissedMax(val) => fmt.field("MissedMax", &val),
5534 LinkinfoBondAttrs::NsIp6Target(val) => fmt.field("NsIp6Target", &val),
5535 LinkinfoBondAttrs::CoupledControl(val) => fmt.field("CoupledControl", &val),
5536 };
5537 }
5538 fmt.finish()
5539 }
5540}
5541impl IterableLinkinfoBondAttrs<'_> {
5542 pub fn lookup_attr(
5543 &self,
5544 offset: usize,
5545 missing_type: Option<u16>,
5546 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5547 let mut stack = Vec::new();
5548 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
5549 if cur == offset {
5550 stack.push(("LinkinfoBondAttrs", offset));
5551 return (
5552 stack,
5553 missing_type.and_then(|t| LinkinfoBondAttrs::attr_from_type(t)),
5554 );
5555 }
5556 if cur > offset || cur + self.buf.len() < offset {
5557 return (stack, None);
5558 }
5559 let mut attrs = self.clone();
5560 let mut last_off = cur + attrs.pos;
5561 let mut missing = None;
5562 while let Some(attr) = attrs.next() {
5563 let Ok(attr) = attr else { break };
5564 match attr {
5565 LinkinfoBondAttrs::Mode(val) => {
5566 if last_off == offset {
5567 stack.push(("Mode", last_off));
5568 break;
5569 }
5570 }
5571 LinkinfoBondAttrs::ActiveSlave(val) => {
5572 if last_off == offset {
5573 stack.push(("ActiveSlave", last_off));
5574 break;
5575 }
5576 }
5577 LinkinfoBondAttrs::Miimon(val) => {
5578 if last_off == offset {
5579 stack.push(("Miimon", last_off));
5580 break;
5581 }
5582 }
5583 LinkinfoBondAttrs::Updelay(val) => {
5584 if last_off == offset {
5585 stack.push(("Updelay", last_off));
5586 break;
5587 }
5588 }
5589 LinkinfoBondAttrs::Downdelay(val) => {
5590 if last_off == offset {
5591 stack.push(("Downdelay", last_off));
5592 break;
5593 }
5594 }
5595 LinkinfoBondAttrs::UseCarrier(val) => {
5596 if last_off == offset {
5597 stack.push(("UseCarrier", last_off));
5598 break;
5599 }
5600 }
5601 LinkinfoBondAttrs::ArpInterval(val) => {
5602 if last_off == offset {
5603 stack.push(("ArpInterval", last_off));
5604 break;
5605 }
5606 }
5607 LinkinfoBondAttrs::ArpIpTarget(val) => {
5608 if last_off == offset {
5609 stack.push(("ArpIpTarget", last_off));
5610 break;
5611 }
5612 }
5613 LinkinfoBondAttrs::ArpValidate(val) => {
5614 if last_off == offset {
5615 stack.push(("ArpValidate", last_off));
5616 break;
5617 }
5618 }
5619 LinkinfoBondAttrs::ArpAllTargets(val) => {
5620 if last_off == offset {
5621 stack.push(("ArpAllTargets", last_off));
5622 break;
5623 }
5624 }
5625 LinkinfoBondAttrs::Primary(val) => {
5626 if last_off == offset {
5627 stack.push(("Primary", last_off));
5628 break;
5629 }
5630 }
5631 LinkinfoBondAttrs::PrimaryReselect(val) => {
5632 if last_off == offset {
5633 stack.push(("PrimaryReselect", last_off));
5634 break;
5635 }
5636 }
5637 LinkinfoBondAttrs::FailOverMac(val) => {
5638 if last_off == offset {
5639 stack.push(("FailOverMac", last_off));
5640 break;
5641 }
5642 }
5643 LinkinfoBondAttrs::XmitHashPolicy(val) => {
5644 if last_off == offset {
5645 stack.push(("XmitHashPolicy", last_off));
5646 break;
5647 }
5648 }
5649 LinkinfoBondAttrs::ResendIgmp(val) => {
5650 if last_off == offset {
5651 stack.push(("ResendIgmp", last_off));
5652 break;
5653 }
5654 }
5655 LinkinfoBondAttrs::NumPeerNotif(val) => {
5656 if last_off == offset {
5657 stack.push(("NumPeerNotif", last_off));
5658 break;
5659 }
5660 }
5661 LinkinfoBondAttrs::AllSlavesActive(val) => {
5662 if last_off == offset {
5663 stack.push(("AllSlavesActive", last_off));
5664 break;
5665 }
5666 }
5667 LinkinfoBondAttrs::MinLinks(val) => {
5668 if last_off == offset {
5669 stack.push(("MinLinks", last_off));
5670 break;
5671 }
5672 }
5673 LinkinfoBondAttrs::LpInterval(val) => {
5674 if last_off == offset {
5675 stack.push(("LpInterval", last_off));
5676 break;
5677 }
5678 }
5679 LinkinfoBondAttrs::PacketsPerSlave(val) => {
5680 if last_off == offset {
5681 stack.push(("PacketsPerSlave", last_off));
5682 break;
5683 }
5684 }
5685 LinkinfoBondAttrs::AdLacpRate(val) => {
5686 if last_off == offset {
5687 stack.push(("AdLacpRate", last_off));
5688 break;
5689 }
5690 }
5691 LinkinfoBondAttrs::AdSelect(val) => {
5692 if last_off == offset {
5693 stack.push(("AdSelect", last_off));
5694 break;
5695 }
5696 }
5697 LinkinfoBondAttrs::AdInfo(val) => {
5698 (stack, missing) = val.lookup_attr(offset, missing_type);
5699 if !stack.is_empty() {
5700 break;
5701 }
5702 }
5703 LinkinfoBondAttrs::AdActorSysPrio(val) => {
5704 if last_off == offset {
5705 stack.push(("AdActorSysPrio", last_off));
5706 break;
5707 }
5708 }
5709 LinkinfoBondAttrs::AdUserPortKey(val) => {
5710 if last_off == offset {
5711 stack.push(("AdUserPortKey", last_off));
5712 break;
5713 }
5714 }
5715 LinkinfoBondAttrs::AdActorSystem(val) => {
5716 if last_off == offset {
5717 stack.push(("AdActorSystem", last_off));
5718 break;
5719 }
5720 }
5721 LinkinfoBondAttrs::TlbDynamicLb(val) => {
5722 if last_off == offset {
5723 stack.push(("TlbDynamicLb", last_off));
5724 break;
5725 }
5726 }
5727 LinkinfoBondAttrs::PeerNotifDelay(val) => {
5728 if last_off == offset {
5729 stack.push(("PeerNotifDelay", last_off));
5730 break;
5731 }
5732 }
5733 LinkinfoBondAttrs::AdLacpActive(val) => {
5734 if last_off == offset {
5735 stack.push(("AdLacpActive", last_off));
5736 break;
5737 }
5738 }
5739 LinkinfoBondAttrs::MissedMax(val) => {
5740 if last_off == offset {
5741 stack.push(("MissedMax", last_off));
5742 break;
5743 }
5744 }
5745 LinkinfoBondAttrs::NsIp6Target(val) => {
5746 if last_off == offset {
5747 stack.push(("NsIp6Target", last_off));
5748 break;
5749 }
5750 }
5751 LinkinfoBondAttrs::CoupledControl(val) => {
5752 if last_off == offset {
5753 stack.push(("CoupledControl", last_off));
5754 break;
5755 }
5756 }
5757 _ => {}
5758 };
5759 last_off = cur + attrs.pos;
5760 }
5761 if !stack.is_empty() {
5762 stack.push(("LinkinfoBondAttrs", cur));
5763 }
5764 (stack, missing)
5765 }
5766}
5767#[derive(Clone)]
5768pub enum BondAdInfoAttrs<'a> {
5769 Aggregator(u16),
5770 NumPorts(u16),
5771 ActorKey(u16),
5772 PartnerKey(u16),
5773 PartnerMac(&'a [u8]),
5774}
5775impl<'a> IterableBondAdInfoAttrs<'a> {
5776 pub fn get_aggregator(&self) -> Result<u16, ErrorContext> {
5777 let mut iter = self.clone();
5778 iter.pos = 0;
5779 for attr in iter {
5780 if let BondAdInfoAttrs::Aggregator(val) = attr? {
5781 return Ok(val);
5782 }
5783 }
5784 Err(ErrorContext::new_missing(
5785 "BondAdInfoAttrs",
5786 "Aggregator",
5787 self.orig_loc,
5788 self.buf.as_ptr() as usize,
5789 ))
5790 }
5791 pub fn get_num_ports(&self) -> Result<u16, ErrorContext> {
5792 let mut iter = self.clone();
5793 iter.pos = 0;
5794 for attr in iter {
5795 if let BondAdInfoAttrs::NumPorts(val) = attr? {
5796 return Ok(val);
5797 }
5798 }
5799 Err(ErrorContext::new_missing(
5800 "BondAdInfoAttrs",
5801 "NumPorts",
5802 self.orig_loc,
5803 self.buf.as_ptr() as usize,
5804 ))
5805 }
5806 pub fn get_actor_key(&self) -> Result<u16, ErrorContext> {
5807 let mut iter = self.clone();
5808 iter.pos = 0;
5809 for attr in iter {
5810 if let BondAdInfoAttrs::ActorKey(val) = attr? {
5811 return Ok(val);
5812 }
5813 }
5814 Err(ErrorContext::new_missing(
5815 "BondAdInfoAttrs",
5816 "ActorKey",
5817 self.orig_loc,
5818 self.buf.as_ptr() as usize,
5819 ))
5820 }
5821 pub fn get_partner_key(&self) -> Result<u16, ErrorContext> {
5822 let mut iter = self.clone();
5823 iter.pos = 0;
5824 for attr in iter {
5825 if let BondAdInfoAttrs::PartnerKey(val) = attr? {
5826 return Ok(val);
5827 }
5828 }
5829 Err(ErrorContext::new_missing(
5830 "BondAdInfoAttrs",
5831 "PartnerKey",
5832 self.orig_loc,
5833 self.buf.as_ptr() as usize,
5834 ))
5835 }
5836 pub fn get_partner_mac(&self) -> Result<&'a [u8], ErrorContext> {
5837 let mut iter = self.clone();
5838 iter.pos = 0;
5839 for attr in iter {
5840 if let BondAdInfoAttrs::PartnerMac(val) = attr? {
5841 return Ok(val);
5842 }
5843 }
5844 Err(ErrorContext::new_missing(
5845 "BondAdInfoAttrs",
5846 "PartnerMac",
5847 self.orig_loc,
5848 self.buf.as_ptr() as usize,
5849 ))
5850 }
5851}
5852impl BondAdInfoAttrs<'_> {
5853 pub fn new<'a>(buf: &'a [u8]) -> IterableBondAdInfoAttrs<'a> {
5854 IterableBondAdInfoAttrs::with_loc(buf, buf.as_ptr() as usize)
5855 }
5856 fn attr_from_type(r#type: u16) -> Option<&'static str> {
5857 let res = match r#type {
5858 1u16 => "Aggregator",
5859 2u16 => "NumPorts",
5860 3u16 => "ActorKey",
5861 4u16 => "PartnerKey",
5862 5u16 => "PartnerMac",
5863 _ => return None,
5864 };
5865 Some(res)
5866 }
5867}
5868#[derive(Clone, Copy, Default)]
5869pub struct IterableBondAdInfoAttrs<'a> {
5870 buf: &'a [u8],
5871 pos: usize,
5872 orig_loc: usize,
5873}
5874impl<'a> IterableBondAdInfoAttrs<'a> {
5875 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5876 Self {
5877 buf,
5878 pos: 0,
5879 orig_loc,
5880 }
5881 }
5882 pub fn get_buf(&self) -> &'a [u8] {
5883 self.buf
5884 }
5885}
5886impl<'a> Iterator for IterableBondAdInfoAttrs<'a> {
5887 type Item = Result<BondAdInfoAttrs<'a>, ErrorContext>;
5888 fn next(&mut self) -> Option<Self::Item> {
5889 if self.buf.len() == self.pos {
5890 return None;
5891 }
5892 let pos = self.pos;
5893 let mut r#type = None;
5894 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
5895 r#type = Some(header.r#type);
5896 let res = match header.r#type {
5897 1u16 => BondAdInfoAttrs::Aggregator({
5898 let res = parse_u16(next);
5899 let Some(val) = res else { break };
5900 val
5901 }),
5902 2u16 => BondAdInfoAttrs::NumPorts({
5903 let res = parse_u16(next);
5904 let Some(val) = res else { break };
5905 val
5906 }),
5907 3u16 => BondAdInfoAttrs::ActorKey({
5908 let res = parse_u16(next);
5909 let Some(val) = res else { break };
5910 val
5911 }),
5912 4u16 => BondAdInfoAttrs::PartnerKey({
5913 let res = parse_u16(next);
5914 let Some(val) = res else { break };
5915 val
5916 }),
5917 5u16 => BondAdInfoAttrs::PartnerMac({
5918 let res = Some(next);
5919 let Some(val) = res else { break };
5920 val
5921 }),
5922 n => {
5923 if cfg!(any(test, feature = "deny-unknown-attrs")) {
5924 break;
5925 } else {
5926 continue;
5927 }
5928 }
5929 };
5930 return Some(Ok(res));
5931 }
5932 Some(Err(ErrorContext::new(
5933 "BondAdInfoAttrs",
5934 r#type.and_then(|t| BondAdInfoAttrs::attr_from_type(t)),
5935 self.orig_loc,
5936 self.buf.as_ptr().wrapping_add(pos) as usize,
5937 )))
5938 }
5939}
5940impl<'a> std::fmt::Debug for IterableBondAdInfoAttrs<'_> {
5941 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5942 let mut fmt = f.debug_struct("BondAdInfoAttrs");
5943 for attr in self.clone() {
5944 let attr = match attr {
5945 Ok(a) => a,
5946 Err(err) => {
5947 fmt.finish()?;
5948 f.write_str("Err(")?;
5949 err.fmt(f)?;
5950 return f.write_str(")");
5951 }
5952 };
5953 match attr {
5954 BondAdInfoAttrs::Aggregator(val) => fmt.field("Aggregator", &val),
5955 BondAdInfoAttrs::NumPorts(val) => fmt.field("NumPorts", &val),
5956 BondAdInfoAttrs::ActorKey(val) => fmt.field("ActorKey", &val),
5957 BondAdInfoAttrs::PartnerKey(val) => fmt.field("PartnerKey", &val),
5958 BondAdInfoAttrs::PartnerMac(val) => fmt.field("PartnerMac", &val),
5959 };
5960 }
5961 fmt.finish()
5962 }
5963}
5964impl IterableBondAdInfoAttrs<'_> {
5965 pub fn lookup_attr(
5966 &self,
5967 offset: usize,
5968 missing_type: Option<u16>,
5969 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5970 let mut stack = Vec::new();
5971 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
5972 if cur == offset {
5973 stack.push(("BondAdInfoAttrs", offset));
5974 return (
5975 stack,
5976 missing_type.and_then(|t| BondAdInfoAttrs::attr_from_type(t)),
5977 );
5978 }
5979 if cur > offset || cur + self.buf.len() < offset {
5980 return (stack, None);
5981 }
5982 let mut attrs = self.clone();
5983 let mut last_off = cur + attrs.pos;
5984 while let Some(attr) = attrs.next() {
5985 let Ok(attr) = attr else { break };
5986 match attr {
5987 BondAdInfoAttrs::Aggregator(val) => {
5988 if last_off == offset {
5989 stack.push(("Aggregator", last_off));
5990 break;
5991 }
5992 }
5993 BondAdInfoAttrs::NumPorts(val) => {
5994 if last_off == offset {
5995 stack.push(("NumPorts", last_off));
5996 break;
5997 }
5998 }
5999 BondAdInfoAttrs::ActorKey(val) => {
6000 if last_off == offset {
6001 stack.push(("ActorKey", last_off));
6002 break;
6003 }
6004 }
6005 BondAdInfoAttrs::PartnerKey(val) => {
6006 if last_off == offset {
6007 stack.push(("PartnerKey", last_off));
6008 break;
6009 }
6010 }
6011 BondAdInfoAttrs::PartnerMac(val) => {
6012 if last_off == offset {
6013 stack.push(("PartnerMac", last_off));
6014 break;
6015 }
6016 }
6017 _ => {}
6018 };
6019 last_off = cur + attrs.pos;
6020 }
6021 if !stack.is_empty() {
6022 stack.push(("BondAdInfoAttrs", cur));
6023 }
6024 (stack, None)
6025 }
6026}
6027#[derive(Clone)]
6028pub enum BondSlaveAttrs<'a> {
6029 State(u8),
6030 MiiStatus(u8),
6031 LinkFailureCount(u32),
6032 PermHwaddr(&'a [u8]),
6033 QueueId(u16),
6034 AdAggregatorId(u16),
6035 AdActorOperPortState(u8),
6036 AdPartnerOperPortState(u16),
6037 Prio(u32),
6038}
6039impl<'a> IterableBondSlaveAttrs<'a> {
6040 pub fn get_state(&self) -> Result<u8, ErrorContext> {
6041 let mut iter = self.clone();
6042 iter.pos = 0;
6043 for attr in iter {
6044 if let BondSlaveAttrs::State(val) = attr? {
6045 return Ok(val);
6046 }
6047 }
6048 Err(ErrorContext::new_missing(
6049 "BondSlaveAttrs",
6050 "State",
6051 self.orig_loc,
6052 self.buf.as_ptr() as usize,
6053 ))
6054 }
6055 pub fn get_mii_status(&self) -> Result<u8, ErrorContext> {
6056 let mut iter = self.clone();
6057 iter.pos = 0;
6058 for attr in iter {
6059 if let BondSlaveAttrs::MiiStatus(val) = attr? {
6060 return Ok(val);
6061 }
6062 }
6063 Err(ErrorContext::new_missing(
6064 "BondSlaveAttrs",
6065 "MiiStatus",
6066 self.orig_loc,
6067 self.buf.as_ptr() as usize,
6068 ))
6069 }
6070 pub fn get_link_failure_count(&self) -> Result<u32, ErrorContext> {
6071 let mut iter = self.clone();
6072 iter.pos = 0;
6073 for attr in iter {
6074 if let BondSlaveAttrs::LinkFailureCount(val) = attr? {
6075 return Ok(val);
6076 }
6077 }
6078 Err(ErrorContext::new_missing(
6079 "BondSlaveAttrs",
6080 "LinkFailureCount",
6081 self.orig_loc,
6082 self.buf.as_ptr() as usize,
6083 ))
6084 }
6085 pub fn get_perm_hwaddr(&self) -> Result<&'a [u8], ErrorContext> {
6086 let mut iter = self.clone();
6087 iter.pos = 0;
6088 for attr in iter {
6089 if let BondSlaveAttrs::PermHwaddr(val) = attr? {
6090 return Ok(val);
6091 }
6092 }
6093 Err(ErrorContext::new_missing(
6094 "BondSlaveAttrs",
6095 "PermHwaddr",
6096 self.orig_loc,
6097 self.buf.as_ptr() as usize,
6098 ))
6099 }
6100 pub fn get_queue_id(&self) -> Result<u16, ErrorContext> {
6101 let mut iter = self.clone();
6102 iter.pos = 0;
6103 for attr in iter {
6104 if let BondSlaveAttrs::QueueId(val) = attr? {
6105 return Ok(val);
6106 }
6107 }
6108 Err(ErrorContext::new_missing(
6109 "BondSlaveAttrs",
6110 "QueueId",
6111 self.orig_loc,
6112 self.buf.as_ptr() as usize,
6113 ))
6114 }
6115 pub fn get_ad_aggregator_id(&self) -> Result<u16, ErrorContext> {
6116 let mut iter = self.clone();
6117 iter.pos = 0;
6118 for attr in iter {
6119 if let BondSlaveAttrs::AdAggregatorId(val) = attr? {
6120 return Ok(val);
6121 }
6122 }
6123 Err(ErrorContext::new_missing(
6124 "BondSlaveAttrs",
6125 "AdAggregatorId",
6126 self.orig_loc,
6127 self.buf.as_ptr() as usize,
6128 ))
6129 }
6130 pub fn get_ad_actor_oper_port_state(&self) -> Result<u8, ErrorContext> {
6131 let mut iter = self.clone();
6132 iter.pos = 0;
6133 for attr in iter {
6134 if let BondSlaveAttrs::AdActorOperPortState(val) = attr? {
6135 return Ok(val);
6136 }
6137 }
6138 Err(ErrorContext::new_missing(
6139 "BondSlaveAttrs",
6140 "AdActorOperPortState",
6141 self.orig_loc,
6142 self.buf.as_ptr() as usize,
6143 ))
6144 }
6145 pub fn get_ad_partner_oper_port_state(&self) -> Result<u16, ErrorContext> {
6146 let mut iter = self.clone();
6147 iter.pos = 0;
6148 for attr in iter {
6149 if let BondSlaveAttrs::AdPartnerOperPortState(val) = attr? {
6150 return Ok(val);
6151 }
6152 }
6153 Err(ErrorContext::new_missing(
6154 "BondSlaveAttrs",
6155 "AdPartnerOperPortState",
6156 self.orig_loc,
6157 self.buf.as_ptr() as usize,
6158 ))
6159 }
6160 pub fn get_prio(&self) -> Result<u32, ErrorContext> {
6161 let mut iter = self.clone();
6162 iter.pos = 0;
6163 for attr in iter {
6164 if let BondSlaveAttrs::Prio(val) = attr? {
6165 return Ok(val);
6166 }
6167 }
6168 Err(ErrorContext::new_missing(
6169 "BondSlaveAttrs",
6170 "Prio",
6171 self.orig_loc,
6172 self.buf.as_ptr() as usize,
6173 ))
6174 }
6175}
6176impl BondSlaveAttrs<'_> {
6177 pub fn new<'a>(buf: &'a [u8]) -> IterableBondSlaveAttrs<'a> {
6178 IterableBondSlaveAttrs::with_loc(buf, buf.as_ptr() as usize)
6179 }
6180 fn attr_from_type(r#type: u16) -> Option<&'static str> {
6181 let res = match r#type {
6182 1u16 => "State",
6183 2u16 => "MiiStatus",
6184 3u16 => "LinkFailureCount",
6185 4u16 => "PermHwaddr",
6186 5u16 => "QueueId",
6187 6u16 => "AdAggregatorId",
6188 7u16 => "AdActorOperPortState",
6189 8u16 => "AdPartnerOperPortState",
6190 9u16 => "Prio",
6191 _ => return None,
6192 };
6193 Some(res)
6194 }
6195}
6196#[derive(Clone, Copy, Default)]
6197pub struct IterableBondSlaveAttrs<'a> {
6198 buf: &'a [u8],
6199 pos: usize,
6200 orig_loc: usize,
6201}
6202impl<'a> IterableBondSlaveAttrs<'a> {
6203 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
6204 Self {
6205 buf,
6206 pos: 0,
6207 orig_loc,
6208 }
6209 }
6210 pub fn get_buf(&self) -> &'a [u8] {
6211 self.buf
6212 }
6213}
6214impl<'a> Iterator for IterableBondSlaveAttrs<'a> {
6215 type Item = Result<BondSlaveAttrs<'a>, ErrorContext>;
6216 fn next(&mut self) -> Option<Self::Item> {
6217 if self.buf.len() == self.pos {
6218 return None;
6219 }
6220 let pos = self.pos;
6221 let mut r#type = None;
6222 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
6223 r#type = Some(header.r#type);
6224 let res = match header.r#type {
6225 1u16 => BondSlaveAttrs::State({
6226 let res = parse_u8(next);
6227 let Some(val) = res else { break };
6228 val
6229 }),
6230 2u16 => BondSlaveAttrs::MiiStatus({
6231 let res = parse_u8(next);
6232 let Some(val) = res else { break };
6233 val
6234 }),
6235 3u16 => BondSlaveAttrs::LinkFailureCount({
6236 let res = parse_u32(next);
6237 let Some(val) = res else { break };
6238 val
6239 }),
6240 4u16 => BondSlaveAttrs::PermHwaddr({
6241 let res = Some(next);
6242 let Some(val) = res else { break };
6243 val
6244 }),
6245 5u16 => BondSlaveAttrs::QueueId({
6246 let res = parse_u16(next);
6247 let Some(val) = res else { break };
6248 val
6249 }),
6250 6u16 => BondSlaveAttrs::AdAggregatorId({
6251 let res = parse_u16(next);
6252 let Some(val) = res else { break };
6253 val
6254 }),
6255 7u16 => BondSlaveAttrs::AdActorOperPortState({
6256 let res = parse_u8(next);
6257 let Some(val) = res else { break };
6258 val
6259 }),
6260 8u16 => BondSlaveAttrs::AdPartnerOperPortState({
6261 let res = parse_u16(next);
6262 let Some(val) = res else { break };
6263 val
6264 }),
6265 9u16 => BondSlaveAttrs::Prio({
6266 let res = parse_u32(next);
6267 let Some(val) = res else { break };
6268 val
6269 }),
6270 n => {
6271 if cfg!(any(test, feature = "deny-unknown-attrs")) {
6272 break;
6273 } else {
6274 continue;
6275 }
6276 }
6277 };
6278 return Some(Ok(res));
6279 }
6280 Some(Err(ErrorContext::new(
6281 "BondSlaveAttrs",
6282 r#type.and_then(|t| BondSlaveAttrs::attr_from_type(t)),
6283 self.orig_loc,
6284 self.buf.as_ptr().wrapping_add(pos) as usize,
6285 )))
6286 }
6287}
6288impl<'a> std::fmt::Debug for IterableBondSlaveAttrs<'_> {
6289 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6290 let mut fmt = f.debug_struct("BondSlaveAttrs");
6291 for attr in self.clone() {
6292 let attr = match attr {
6293 Ok(a) => a,
6294 Err(err) => {
6295 fmt.finish()?;
6296 f.write_str("Err(")?;
6297 err.fmt(f)?;
6298 return f.write_str(")");
6299 }
6300 };
6301 match attr {
6302 BondSlaveAttrs::State(val) => fmt.field("State", &val),
6303 BondSlaveAttrs::MiiStatus(val) => fmt.field("MiiStatus", &val),
6304 BondSlaveAttrs::LinkFailureCount(val) => fmt.field("LinkFailureCount", &val),
6305 BondSlaveAttrs::PermHwaddr(val) => fmt.field("PermHwaddr", &val),
6306 BondSlaveAttrs::QueueId(val) => fmt.field("QueueId", &val),
6307 BondSlaveAttrs::AdAggregatorId(val) => fmt.field("AdAggregatorId", &val),
6308 BondSlaveAttrs::AdActorOperPortState(val) => {
6309 fmt.field("AdActorOperPortState", &val)
6310 }
6311 BondSlaveAttrs::AdPartnerOperPortState(val) => {
6312 fmt.field("AdPartnerOperPortState", &val)
6313 }
6314 BondSlaveAttrs::Prio(val) => fmt.field("Prio", &val),
6315 };
6316 }
6317 fmt.finish()
6318 }
6319}
6320impl IterableBondSlaveAttrs<'_> {
6321 pub fn lookup_attr(
6322 &self,
6323 offset: usize,
6324 missing_type: Option<u16>,
6325 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
6326 let mut stack = Vec::new();
6327 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
6328 if cur == offset {
6329 stack.push(("BondSlaveAttrs", offset));
6330 return (
6331 stack,
6332 missing_type.and_then(|t| BondSlaveAttrs::attr_from_type(t)),
6333 );
6334 }
6335 if cur > offset || cur + self.buf.len() < offset {
6336 return (stack, None);
6337 }
6338 let mut attrs = self.clone();
6339 let mut last_off = cur + attrs.pos;
6340 while let Some(attr) = attrs.next() {
6341 let Ok(attr) = attr else { break };
6342 match attr {
6343 BondSlaveAttrs::State(val) => {
6344 if last_off == offset {
6345 stack.push(("State", last_off));
6346 break;
6347 }
6348 }
6349 BondSlaveAttrs::MiiStatus(val) => {
6350 if last_off == offset {
6351 stack.push(("MiiStatus", last_off));
6352 break;
6353 }
6354 }
6355 BondSlaveAttrs::LinkFailureCount(val) => {
6356 if last_off == offset {
6357 stack.push(("LinkFailureCount", last_off));
6358 break;
6359 }
6360 }
6361 BondSlaveAttrs::PermHwaddr(val) => {
6362 if last_off == offset {
6363 stack.push(("PermHwaddr", last_off));
6364 break;
6365 }
6366 }
6367 BondSlaveAttrs::QueueId(val) => {
6368 if last_off == offset {
6369 stack.push(("QueueId", last_off));
6370 break;
6371 }
6372 }
6373 BondSlaveAttrs::AdAggregatorId(val) => {
6374 if last_off == offset {
6375 stack.push(("AdAggregatorId", last_off));
6376 break;
6377 }
6378 }
6379 BondSlaveAttrs::AdActorOperPortState(val) => {
6380 if last_off == offset {
6381 stack.push(("AdActorOperPortState", last_off));
6382 break;
6383 }
6384 }
6385 BondSlaveAttrs::AdPartnerOperPortState(val) => {
6386 if last_off == offset {
6387 stack.push(("AdPartnerOperPortState", last_off));
6388 break;
6389 }
6390 }
6391 BondSlaveAttrs::Prio(val) => {
6392 if last_off == offset {
6393 stack.push(("Prio", last_off));
6394 break;
6395 }
6396 }
6397 _ => {}
6398 };
6399 last_off = cur + attrs.pos;
6400 }
6401 if !stack.is_empty() {
6402 stack.push(("BondSlaveAttrs", cur));
6403 }
6404 (stack, None)
6405 }
6406}
6407#[derive(Clone)]
6408pub enum LinkinfoBridgeAttrs<'a> {
6409 ForwardDelay(u32),
6410 HelloTime(u32),
6411 MaxAge(u32),
6412 AgeingTime(u32),
6413 StpState(u32),
6414 Priority(u16),
6415 VlanFiltering(u8),
6416 VlanProtocol(u16),
6417 GroupFwdMask(u16),
6418 RootId(PushIflaBridgeId),
6419 BridgeId(PushIflaBridgeId),
6420 RootPort(u16),
6421 RootPathCost(u32),
6422 TopologyChange(u8),
6423 TopologyChangeDetected(u8),
6424 HelloTimer(u64),
6425 TcnTimer(u64),
6426 TopologyChangeTimer(u64),
6427 GcTimer(u64),
6428 GroupAddr(&'a [u8]),
6429 FdbFlush(&'a [u8]),
6430 McastRouter(u8),
6431 McastSnooping(u8),
6432 McastQueryUseIfaddr(u8),
6433 McastQuerier(u8),
6434 McastHashElasticity(u32),
6435 McastHashMax(u32),
6436 McastLastMemberCnt(u32),
6437 McastStartupQueryCnt(u32),
6438 McastLastMemberIntvl(u64),
6439 McastMembershipIntvl(u64),
6440 McastQuerierIntvl(u64),
6441 McastQueryIntvl(u64),
6442 McastQueryResponseIntvl(u64),
6443 McastStartupQueryIntvl(u64),
6444 NfCallIptables(u8),
6445 NfCallIp6tables(u8),
6446 NfCallArptables(u8),
6447 VlanDefaultPvid(u16),
6448 Pad(&'a [u8]),
6449 VlanStatsEnabled(u8),
6450 McastStatsEnabled(u8),
6451 McastIgmpVersion(u8),
6452 McastMldVersion(u8),
6453 VlanStatsPerPort(u8),
6454 MultiBoolopt(PushBrBooloptMulti),
6455 McastQuerierState(&'a [u8]),
6456 FdbNLearned(u32),
6457 FdbMaxLearned(u32),
6458}
6459impl<'a> IterableLinkinfoBridgeAttrs<'a> {
6460 pub fn get_forward_delay(&self) -> Result<u32, ErrorContext> {
6461 let mut iter = self.clone();
6462 iter.pos = 0;
6463 for attr in iter {
6464 if let LinkinfoBridgeAttrs::ForwardDelay(val) = attr? {
6465 return Ok(val);
6466 }
6467 }
6468 Err(ErrorContext::new_missing(
6469 "LinkinfoBridgeAttrs",
6470 "ForwardDelay",
6471 self.orig_loc,
6472 self.buf.as_ptr() as usize,
6473 ))
6474 }
6475 pub fn get_hello_time(&self) -> Result<u32, ErrorContext> {
6476 let mut iter = self.clone();
6477 iter.pos = 0;
6478 for attr in iter {
6479 if let LinkinfoBridgeAttrs::HelloTime(val) = attr? {
6480 return Ok(val);
6481 }
6482 }
6483 Err(ErrorContext::new_missing(
6484 "LinkinfoBridgeAttrs",
6485 "HelloTime",
6486 self.orig_loc,
6487 self.buf.as_ptr() as usize,
6488 ))
6489 }
6490 pub fn get_max_age(&self) -> Result<u32, ErrorContext> {
6491 let mut iter = self.clone();
6492 iter.pos = 0;
6493 for attr in iter {
6494 if let LinkinfoBridgeAttrs::MaxAge(val) = attr? {
6495 return Ok(val);
6496 }
6497 }
6498 Err(ErrorContext::new_missing(
6499 "LinkinfoBridgeAttrs",
6500 "MaxAge",
6501 self.orig_loc,
6502 self.buf.as_ptr() as usize,
6503 ))
6504 }
6505 pub fn get_ageing_time(&self) -> Result<u32, ErrorContext> {
6506 let mut iter = self.clone();
6507 iter.pos = 0;
6508 for attr in iter {
6509 if let LinkinfoBridgeAttrs::AgeingTime(val) = attr? {
6510 return Ok(val);
6511 }
6512 }
6513 Err(ErrorContext::new_missing(
6514 "LinkinfoBridgeAttrs",
6515 "AgeingTime",
6516 self.orig_loc,
6517 self.buf.as_ptr() as usize,
6518 ))
6519 }
6520 pub fn get_stp_state(&self) -> Result<u32, ErrorContext> {
6521 let mut iter = self.clone();
6522 iter.pos = 0;
6523 for attr in iter {
6524 if let LinkinfoBridgeAttrs::StpState(val) = attr? {
6525 return Ok(val);
6526 }
6527 }
6528 Err(ErrorContext::new_missing(
6529 "LinkinfoBridgeAttrs",
6530 "StpState",
6531 self.orig_loc,
6532 self.buf.as_ptr() as usize,
6533 ))
6534 }
6535 pub fn get_priority(&self) -> Result<u16, ErrorContext> {
6536 let mut iter = self.clone();
6537 iter.pos = 0;
6538 for attr in iter {
6539 if let LinkinfoBridgeAttrs::Priority(val) = attr? {
6540 return Ok(val);
6541 }
6542 }
6543 Err(ErrorContext::new_missing(
6544 "LinkinfoBridgeAttrs",
6545 "Priority",
6546 self.orig_loc,
6547 self.buf.as_ptr() as usize,
6548 ))
6549 }
6550 pub fn get_vlan_filtering(&self) -> Result<u8, ErrorContext> {
6551 let mut iter = self.clone();
6552 iter.pos = 0;
6553 for attr in iter {
6554 if let LinkinfoBridgeAttrs::VlanFiltering(val) = attr? {
6555 return Ok(val);
6556 }
6557 }
6558 Err(ErrorContext::new_missing(
6559 "LinkinfoBridgeAttrs",
6560 "VlanFiltering",
6561 self.orig_loc,
6562 self.buf.as_ptr() as usize,
6563 ))
6564 }
6565 pub fn get_vlan_protocol(&self) -> Result<u16, ErrorContext> {
6566 let mut iter = self.clone();
6567 iter.pos = 0;
6568 for attr in iter {
6569 if let LinkinfoBridgeAttrs::VlanProtocol(val) = attr? {
6570 return Ok(val);
6571 }
6572 }
6573 Err(ErrorContext::new_missing(
6574 "LinkinfoBridgeAttrs",
6575 "VlanProtocol",
6576 self.orig_loc,
6577 self.buf.as_ptr() as usize,
6578 ))
6579 }
6580 pub fn get_group_fwd_mask(&self) -> Result<u16, ErrorContext> {
6581 let mut iter = self.clone();
6582 iter.pos = 0;
6583 for attr in iter {
6584 if let LinkinfoBridgeAttrs::GroupFwdMask(val) = attr? {
6585 return Ok(val);
6586 }
6587 }
6588 Err(ErrorContext::new_missing(
6589 "LinkinfoBridgeAttrs",
6590 "GroupFwdMask",
6591 self.orig_loc,
6592 self.buf.as_ptr() as usize,
6593 ))
6594 }
6595 pub fn get_root_id(&self) -> Result<PushIflaBridgeId, ErrorContext> {
6596 let mut iter = self.clone();
6597 iter.pos = 0;
6598 for attr in iter {
6599 if let LinkinfoBridgeAttrs::RootId(val) = attr? {
6600 return Ok(val);
6601 }
6602 }
6603 Err(ErrorContext::new_missing(
6604 "LinkinfoBridgeAttrs",
6605 "RootId",
6606 self.orig_loc,
6607 self.buf.as_ptr() as usize,
6608 ))
6609 }
6610 pub fn get_bridge_id(&self) -> Result<PushIflaBridgeId, ErrorContext> {
6611 let mut iter = self.clone();
6612 iter.pos = 0;
6613 for attr in iter {
6614 if let LinkinfoBridgeAttrs::BridgeId(val) = attr? {
6615 return Ok(val);
6616 }
6617 }
6618 Err(ErrorContext::new_missing(
6619 "LinkinfoBridgeAttrs",
6620 "BridgeId",
6621 self.orig_loc,
6622 self.buf.as_ptr() as usize,
6623 ))
6624 }
6625 pub fn get_root_port(&self) -> Result<u16, ErrorContext> {
6626 let mut iter = self.clone();
6627 iter.pos = 0;
6628 for attr in iter {
6629 if let LinkinfoBridgeAttrs::RootPort(val) = attr? {
6630 return Ok(val);
6631 }
6632 }
6633 Err(ErrorContext::new_missing(
6634 "LinkinfoBridgeAttrs",
6635 "RootPort",
6636 self.orig_loc,
6637 self.buf.as_ptr() as usize,
6638 ))
6639 }
6640 pub fn get_root_path_cost(&self) -> Result<u32, ErrorContext> {
6641 let mut iter = self.clone();
6642 iter.pos = 0;
6643 for attr in iter {
6644 if let LinkinfoBridgeAttrs::RootPathCost(val) = attr? {
6645 return Ok(val);
6646 }
6647 }
6648 Err(ErrorContext::new_missing(
6649 "LinkinfoBridgeAttrs",
6650 "RootPathCost",
6651 self.orig_loc,
6652 self.buf.as_ptr() as usize,
6653 ))
6654 }
6655 pub fn get_topology_change(&self) -> Result<u8, ErrorContext> {
6656 let mut iter = self.clone();
6657 iter.pos = 0;
6658 for attr in iter {
6659 if let LinkinfoBridgeAttrs::TopologyChange(val) = attr? {
6660 return Ok(val);
6661 }
6662 }
6663 Err(ErrorContext::new_missing(
6664 "LinkinfoBridgeAttrs",
6665 "TopologyChange",
6666 self.orig_loc,
6667 self.buf.as_ptr() as usize,
6668 ))
6669 }
6670 pub fn get_topology_change_detected(&self) -> Result<u8, ErrorContext> {
6671 let mut iter = self.clone();
6672 iter.pos = 0;
6673 for attr in iter {
6674 if let LinkinfoBridgeAttrs::TopologyChangeDetected(val) = attr? {
6675 return Ok(val);
6676 }
6677 }
6678 Err(ErrorContext::new_missing(
6679 "LinkinfoBridgeAttrs",
6680 "TopologyChangeDetected",
6681 self.orig_loc,
6682 self.buf.as_ptr() as usize,
6683 ))
6684 }
6685 pub fn get_hello_timer(&self) -> Result<u64, ErrorContext> {
6686 let mut iter = self.clone();
6687 iter.pos = 0;
6688 for attr in iter {
6689 if let LinkinfoBridgeAttrs::HelloTimer(val) = attr? {
6690 return Ok(val);
6691 }
6692 }
6693 Err(ErrorContext::new_missing(
6694 "LinkinfoBridgeAttrs",
6695 "HelloTimer",
6696 self.orig_loc,
6697 self.buf.as_ptr() as usize,
6698 ))
6699 }
6700 pub fn get_tcn_timer(&self) -> Result<u64, ErrorContext> {
6701 let mut iter = self.clone();
6702 iter.pos = 0;
6703 for attr in iter {
6704 if let LinkinfoBridgeAttrs::TcnTimer(val) = attr? {
6705 return Ok(val);
6706 }
6707 }
6708 Err(ErrorContext::new_missing(
6709 "LinkinfoBridgeAttrs",
6710 "TcnTimer",
6711 self.orig_loc,
6712 self.buf.as_ptr() as usize,
6713 ))
6714 }
6715 pub fn get_topology_change_timer(&self) -> Result<u64, ErrorContext> {
6716 let mut iter = self.clone();
6717 iter.pos = 0;
6718 for attr in iter {
6719 if let LinkinfoBridgeAttrs::TopologyChangeTimer(val) = attr? {
6720 return Ok(val);
6721 }
6722 }
6723 Err(ErrorContext::new_missing(
6724 "LinkinfoBridgeAttrs",
6725 "TopologyChangeTimer",
6726 self.orig_loc,
6727 self.buf.as_ptr() as usize,
6728 ))
6729 }
6730 pub fn get_gc_timer(&self) -> Result<u64, ErrorContext> {
6731 let mut iter = self.clone();
6732 iter.pos = 0;
6733 for attr in iter {
6734 if let LinkinfoBridgeAttrs::GcTimer(val) = attr? {
6735 return Ok(val);
6736 }
6737 }
6738 Err(ErrorContext::new_missing(
6739 "LinkinfoBridgeAttrs",
6740 "GcTimer",
6741 self.orig_loc,
6742 self.buf.as_ptr() as usize,
6743 ))
6744 }
6745 pub fn get_group_addr(&self) -> Result<&'a [u8], ErrorContext> {
6746 let mut iter = self.clone();
6747 iter.pos = 0;
6748 for attr in iter {
6749 if let LinkinfoBridgeAttrs::GroupAddr(val) = attr? {
6750 return Ok(val);
6751 }
6752 }
6753 Err(ErrorContext::new_missing(
6754 "LinkinfoBridgeAttrs",
6755 "GroupAddr",
6756 self.orig_loc,
6757 self.buf.as_ptr() as usize,
6758 ))
6759 }
6760 pub fn get_fdb_flush(&self) -> Result<&'a [u8], ErrorContext> {
6761 let mut iter = self.clone();
6762 iter.pos = 0;
6763 for attr in iter {
6764 if let LinkinfoBridgeAttrs::FdbFlush(val) = attr? {
6765 return Ok(val);
6766 }
6767 }
6768 Err(ErrorContext::new_missing(
6769 "LinkinfoBridgeAttrs",
6770 "FdbFlush",
6771 self.orig_loc,
6772 self.buf.as_ptr() as usize,
6773 ))
6774 }
6775 pub fn get_mcast_router(&self) -> Result<u8, ErrorContext> {
6776 let mut iter = self.clone();
6777 iter.pos = 0;
6778 for attr in iter {
6779 if let LinkinfoBridgeAttrs::McastRouter(val) = attr? {
6780 return Ok(val);
6781 }
6782 }
6783 Err(ErrorContext::new_missing(
6784 "LinkinfoBridgeAttrs",
6785 "McastRouter",
6786 self.orig_loc,
6787 self.buf.as_ptr() as usize,
6788 ))
6789 }
6790 pub fn get_mcast_snooping(&self) -> Result<u8, ErrorContext> {
6791 let mut iter = self.clone();
6792 iter.pos = 0;
6793 for attr in iter {
6794 if let LinkinfoBridgeAttrs::McastSnooping(val) = attr? {
6795 return Ok(val);
6796 }
6797 }
6798 Err(ErrorContext::new_missing(
6799 "LinkinfoBridgeAttrs",
6800 "McastSnooping",
6801 self.orig_loc,
6802 self.buf.as_ptr() as usize,
6803 ))
6804 }
6805 pub fn get_mcast_query_use_ifaddr(&self) -> Result<u8, ErrorContext> {
6806 let mut iter = self.clone();
6807 iter.pos = 0;
6808 for attr in iter {
6809 if let LinkinfoBridgeAttrs::McastQueryUseIfaddr(val) = attr? {
6810 return Ok(val);
6811 }
6812 }
6813 Err(ErrorContext::new_missing(
6814 "LinkinfoBridgeAttrs",
6815 "McastQueryUseIfaddr",
6816 self.orig_loc,
6817 self.buf.as_ptr() as usize,
6818 ))
6819 }
6820 pub fn get_mcast_querier(&self) -> Result<u8, ErrorContext> {
6821 let mut iter = self.clone();
6822 iter.pos = 0;
6823 for attr in iter {
6824 if let LinkinfoBridgeAttrs::McastQuerier(val) = attr? {
6825 return Ok(val);
6826 }
6827 }
6828 Err(ErrorContext::new_missing(
6829 "LinkinfoBridgeAttrs",
6830 "McastQuerier",
6831 self.orig_loc,
6832 self.buf.as_ptr() as usize,
6833 ))
6834 }
6835 pub fn get_mcast_hash_elasticity(&self) -> Result<u32, ErrorContext> {
6836 let mut iter = self.clone();
6837 iter.pos = 0;
6838 for attr in iter {
6839 if let LinkinfoBridgeAttrs::McastHashElasticity(val) = attr? {
6840 return Ok(val);
6841 }
6842 }
6843 Err(ErrorContext::new_missing(
6844 "LinkinfoBridgeAttrs",
6845 "McastHashElasticity",
6846 self.orig_loc,
6847 self.buf.as_ptr() as usize,
6848 ))
6849 }
6850 pub fn get_mcast_hash_max(&self) -> Result<u32, ErrorContext> {
6851 let mut iter = self.clone();
6852 iter.pos = 0;
6853 for attr in iter {
6854 if let LinkinfoBridgeAttrs::McastHashMax(val) = attr? {
6855 return Ok(val);
6856 }
6857 }
6858 Err(ErrorContext::new_missing(
6859 "LinkinfoBridgeAttrs",
6860 "McastHashMax",
6861 self.orig_loc,
6862 self.buf.as_ptr() as usize,
6863 ))
6864 }
6865 pub fn get_mcast_last_member_cnt(&self) -> Result<u32, ErrorContext> {
6866 let mut iter = self.clone();
6867 iter.pos = 0;
6868 for attr in iter {
6869 if let LinkinfoBridgeAttrs::McastLastMemberCnt(val) = attr? {
6870 return Ok(val);
6871 }
6872 }
6873 Err(ErrorContext::new_missing(
6874 "LinkinfoBridgeAttrs",
6875 "McastLastMemberCnt",
6876 self.orig_loc,
6877 self.buf.as_ptr() as usize,
6878 ))
6879 }
6880 pub fn get_mcast_startup_query_cnt(&self) -> Result<u32, ErrorContext> {
6881 let mut iter = self.clone();
6882 iter.pos = 0;
6883 for attr in iter {
6884 if let LinkinfoBridgeAttrs::McastStartupQueryCnt(val) = attr? {
6885 return Ok(val);
6886 }
6887 }
6888 Err(ErrorContext::new_missing(
6889 "LinkinfoBridgeAttrs",
6890 "McastStartupQueryCnt",
6891 self.orig_loc,
6892 self.buf.as_ptr() as usize,
6893 ))
6894 }
6895 pub fn get_mcast_last_member_intvl(&self) -> Result<u64, ErrorContext> {
6896 let mut iter = self.clone();
6897 iter.pos = 0;
6898 for attr in iter {
6899 if let LinkinfoBridgeAttrs::McastLastMemberIntvl(val) = attr? {
6900 return Ok(val);
6901 }
6902 }
6903 Err(ErrorContext::new_missing(
6904 "LinkinfoBridgeAttrs",
6905 "McastLastMemberIntvl",
6906 self.orig_loc,
6907 self.buf.as_ptr() as usize,
6908 ))
6909 }
6910 pub fn get_mcast_membership_intvl(&self) -> Result<u64, ErrorContext> {
6911 let mut iter = self.clone();
6912 iter.pos = 0;
6913 for attr in iter {
6914 if let LinkinfoBridgeAttrs::McastMembershipIntvl(val) = attr? {
6915 return Ok(val);
6916 }
6917 }
6918 Err(ErrorContext::new_missing(
6919 "LinkinfoBridgeAttrs",
6920 "McastMembershipIntvl",
6921 self.orig_loc,
6922 self.buf.as_ptr() as usize,
6923 ))
6924 }
6925 pub fn get_mcast_querier_intvl(&self) -> Result<u64, ErrorContext> {
6926 let mut iter = self.clone();
6927 iter.pos = 0;
6928 for attr in iter {
6929 if let LinkinfoBridgeAttrs::McastQuerierIntvl(val) = attr? {
6930 return Ok(val);
6931 }
6932 }
6933 Err(ErrorContext::new_missing(
6934 "LinkinfoBridgeAttrs",
6935 "McastQuerierIntvl",
6936 self.orig_loc,
6937 self.buf.as_ptr() as usize,
6938 ))
6939 }
6940 pub fn get_mcast_query_intvl(&self) -> Result<u64, ErrorContext> {
6941 let mut iter = self.clone();
6942 iter.pos = 0;
6943 for attr in iter {
6944 if let LinkinfoBridgeAttrs::McastQueryIntvl(val) = attr? {
6945 return Ok(val);
6946 }
6947 }
6948 Err(ErrorContext::new_missing(
6949 "LinkinfoBridgeAttrs",
6950 "McastQueryIntvl",
6951 self.orig_loc,
6952 self.buf.as_ptr() as usize,
6953 ))
6954 }
6955 pub fn get_mcast_query_response_intvl(&self) -> Result<u64, ErrorContext> {
6956 let mut iter = self.clone();
6957 iter.pos = 0;
6958 for attr in iter {
6959 if let LinkinfoBridgeAttrs::McastQueryResponseIntvl(val) = attr? {
6960 return Ok(val);
6961 }
6962 }
6963 Err(ErrorContext::new_missing(
6964 "LinkinfoBridgeAttrs",
6965 "McastQueryResponseIntvl",
6966 self.orig_loc,
6967 self.buf.as_ptr() as usize,
6968 ))
6969 }
6970 pub fn get_mcast_startup_query_intvl(&self) -> Result<u64, ErrorContext> {
6971 let mut iter = self.clone();
6972 iter.pos = 0;
6973 for attr in iter {
6974 if let LinkinfoBridgeAttrs::McastStartupQueryIntvl(val) = attr? {
6975 return Ok(val);
6976 }
6977 }
6978 Err(ErrorContext::new_missing(
6979 "LinkinfoBridgeAttrs",
6980 "McastStartupQueryIntvl",
6981 self.orig_loc,
6982 self.buf.as_ptr() as usize,
6983 ))
6984 }
6985 pub fn get_nf_call_iptables(&self) -> Result<u8, ErrorContext> {
6986 let mut iter = self.clone();
6987 iter.pos = 0;
6988 for attr in iter {
6989 if let LinkinfoBridgeAttrs::NfCallIptables(val) = attr? {
6990 return Ok(val);
6991 }
6992 }
6993 Err(ErrorContext::new_missing(
6994 "LinkinfoBridgeAttrs",
6995 "NfCallIptables",
6996 self.orig_loc,
6997 self.buf.as_ptr() as usize,
6998 ))
6999 }
7000 pub fn get_nf_call_ip6tables(&self) -> Result<u8, ErrorContext> {
7001 let mut iter = self.clone();
7002 iter.pos = 0;
7003 for attr in iter {
7004 if let LinkinfoBridgeAttrs::NfCallIp6tables(val) = attr? {
7005 return Ok(val);
7006 }
7007 }
7008 Err(ErrorContext::new_missing(
7009 "LinkinfoBridgeAttrs",
7010 "NfCallIp6tables",
7011 self.orig_loc,
7012 self.buf.as_ptr() as usize,
7013 ))
7014 }
7015 pub fn get_nf_call_arptables(&self) -> Result<u8, ErrorContext> {
7016 let mut iter = self.clone();
7017 iter.pos = 0;
7018 for attr in iter {
7019 if let LinkinfoBridgeAttrs::NfCallArptables(val) = attr? {
7020 return Ok(val);
7021 }
7022 }
7023 Err(ErrorContext::new_missing(
7024 "LinkinfoBridgeAttrs",
7025 "NfCallArptables",
7026 self.orig_loc,
7027 self.buf.as_ptr() as usize,
7028 ))
7029 }
7030 pub fn get_vlan_default_pvid(&self) -> Result<u16, ErrorContext> {
7031 let mut iter = self.clone();
7032 iter.pos = 0;
7033 for attr in iter {
7034 if let LinkinfoBridgeAttrs::VlanDefaultPvid(val) = attr? {
7035 return Ok(val);
7036 }
7037 }
7038 Err(ErrorContext::new_missing(
7039 "LinkinfoBridgeAttrs",
7040 "VlanDefaultPvid",
7041 self.orig_loc,
7042 self.buf.as_ptr() as usize,
7043 ))
7044 }
7045 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
7046 let mut iter = self.clone();
7047 iter.pos = 0;
7048 for attr in iter {
7049 if let LinkinfoBridgeAttrs::Pad(val) = attr? {
7050 return Ok(val);
7051 }
7052 }
7053 Err(ErrorContext::new_missing(
7054 "LinkinfoBridgeAttrs",
7055 "Pad",
7056 self.orig_loc,
7057 self.buf.as_ptr() as usize,
7058 ))
7059 }
7060 pub fn get_vlan_stats_enabled(&self) -> Result<u8, ErrorContext> {
7061 let mut iter = self.clone();
7062 iter.pos = 0;
7063 for attr in iter {
7064 if let LinkinfoBridgeAttrs::VlanStatsEnabled(val) = attr? {
7065 return Ok(val);
7066 }
7067 }
7068 Err(ErrorContext::new_missing(
7069 "LinkinfoBridgeAttrs",
7070 "VlanStatsEnabled",
7071 self.orig_loc,
7072 self.buf.as_ptr() as usize,
7073 ))
7074 }
7075 pub fn get_mcast_stats_enabled(&self) -> Result<u8, ErrorContext> {
7076 let mut iter = self.clone();
7077 iter.pos = 0;
7078 for attr in iter {
7079 if let LinkinfoBridgeAttrs::McastStatsEnabled(val) = attr? {
7080 return Ok(val);
7081 }
7082 }
7083 Err(ErrorContext::new_missing(
7084 "LinkinfoBridgeAttrs",
7085 "McastStatsEnabled",
7086 self.orig_loc,
7087 self.buf.as_ptr() as usize,
7088 ))
7089 }
7090 pub fn get_mcast_igmp_version(&self) -> Result<u8, ErrorContext> {
7091 let mut iter = self.clone();
7092 iter.pos = 0;
7093 for attr in iter {
7094 if let LinkinfoBridgeAttrs::McastIgmpVersion(val) = attr? {
7095 return Ok(val);
7096 }
7097 }
7098 Err(ErrorContext::new_missing(
7099 "LinkinfoBridgeAttrs",
7100 "McastIgmpVersion",
7101 self.orig_loc,
7102 self.buf.as_ptr() as usize,
7103 ))
7104 }
7105 pub fn get_mcast_mld_version(&self) -> Result<u8, ErrorContext> {
7106 let mut iter = self.clone();
7107 iter.pos = 0;
7108 for attr in iter {
7109 if let LinkinfoBridgeAttrs::McastMldVersion(val) = attr? {
7110 return Ok(val);
7111 }
7112 }
7113 Err(ErrorContext::new_missing(
7114 "LinkinfoBridgeAttrs",
7115 "McastMldVersion",
7116 self.orig_loc,
7117 self.buf.as_ptr() as usize,
7118 ))
7119 }
7120 pub fn get_vlan_stats_per_port(&self) -> Result<u8, ErrorContext> {
7121 let mut iter = self.clone();
7122 iter.pos = 0;
7123 for attr in iter {
7124 if let LinkinfoBridgeAttrs::VlanStatsPerPort(val) = attr? {
7125 return Ok(val);
7126 }
7127 }
7128 Err(ErrorContext::new_missing(
7129 "LinkinfoBridgeAttrs",
7130 "VlanStatsPerPort",
7131 self.orig_loc,
7132 self.buf.as_ptr() as usize,
7133 ))
7134 }
7135 pub fn get_multi_boolopt(&self) -> Result<PushBrBooloptMulti, ErrorContext> {
7136 let mut iter = self.clone();
7137 iter.pos = 0;
7138 for attr in iter {
7139 if let LinkinfoBridgeAttrs::MultiBoolopt(val) = attr? {
7140 return Ok(val);
7141 }
7142 }
7143 Err(ErrorContext::new_missing(
7144 "LinkinfoBridgeAttrs",
7145 "MultiBoolopt",
7146 self.orig_loc,
7147 self.buf.as_ptr() as usize,
7148 ))
7149 }
7150 pub fn get_mcast_querier_state(&self) -> Result<&'a [u8], ErrorContext> {
7151 let mut iter = self.clone();
7152 iter.pos = 0;
7153 for attr in iter {
7154 if let LinkinfoBridgeAttrs::McastQuerierState(val) = attr? {
7155 return Ok(val);
7156 }
7157 }
7158 Err(ErrorContext::new_missing(
7159 "LinkinfoBridgeAttrs",
7160 "McastQuerierState",
7161 self.orig_loc,
7162 self.buf.as_ptr() as usize,
7163 ))
7164 }
7165 pub fn get_fdb_n_learned(&self) -> Result<u32, ErrorContext> {
7166 let mut iter = self.clone();
7167 iter.pos = 0;
7168 for attr in iter {
7169 if let LinkinfoBridgeAttrs::FdbNLearned(val) = attr? {
7170 return Ok(val);
7171 }
7172 }
7173 Err(ErrorContext::new_missing(
7174 "LinkinfoBridgeAttrs",
7175 "FdbNLearned",
7176 self.orig_loc,
7177 self.buf.as_ptr() as usize,
7178 ))
7179 }
7180 pub fn get_fdb_max_learned(&self) -> Result<u32, ErrorContext> {
7181 let mut iter = self.clone();
7182 iter.pos = 0;
7183 for attr in iter {
7184 if let LinkinfoBridgeAttrs::FdbMaxLearned(val) = attr? {
7185 return Ok(val);
7186 }
7187 }
7188 Err(ErrorContext::new_missing(
7189 "LinkinfoBridgeAttrs",
7190 "FdbMaxLearned",
7191 self.orig_loc,
7192 self.buf.as_ptr() as usize,
7193 ))
7194 }
7195}
7196impl LinkinfoBridgeAttrs<'_> {
7197 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoBridgeAttrs<'a> {
7198 IterableLinkinfoBridgeAttrs::with_loc(buf, buf.as_ptr() as usize)
7199 }
7200 fn attr_from_type(r#type: u16) -> Option<&'static str> {
7201 let res = match r#type {
7202 1u16 => "ForwardDelay",
7203 2u16 => "HelloTime",
7204 3u16 => "MaxAge",
7205 4u16 => "AgeingTime",
7206 5u16 => "StpState",
7207 6u16 => "Priority",
7208 7u16 => "VlanFiltering",
7209 8u16 => "VlanProtocol",
7210 9u16 => "GroupFwdMask",
7211 10u16 => "RootId",
7212 11u16 => "BridgeId",
7213 12u16 => "RootPort",
7214 13u16 => "RootPathCost",
7215 14u16 => "TopologyChange",
7216 15u16 => "TopologyChangeDetected",
7217 16u16 => "HelloTimer",
7218 17u16 => "TcnTimer",
7219 18u16 => "TopologyChangeTimer",
7220 19u16 => "GcTimer",
7221 20u16 => "GroupAddr",
7222 21u16 => "FdbFlush",
7223 22u16 => "McastRouter",
7224 23u16 => "McastSnooping",
7225 24u16 => "McastQueryUseIfaddr",
7226 25u16 => "McastQuerier",
7227 26u16 => "McastHashElasticity",
7228 27u16 => "McastHashMax",
7229 28u16 => "McastLastMemberCnt",
7230 29u16 => "McastStartupQueryCnt",
7231 30u16 => "McastLastMemberIntvl",
7232 31u16 => "McastMembershipIntvl",
7233 32u16 => "McastQuerierIntvl",
7234 33u16 => "McastQueryIntvl",
7235 34u16 => "McastQueryResponseIntvl",
7236 35u16 => "McastStartupQueryIntvl",
7237 36u16 => "NfCallIptables",
7238 37u16 => "NfCallIp6tables",
7239 38u16 => "NfCallArptables",
7240 39u16 => "VlanDefaultPvid",
7241 40u16 => "Pad",
7242 41u16 => "VlanStatsEnabled",
7243 42u16 => "McastStatsEnabled",
7244 43u16 => "McastIgmpVersion",
7245 44u16 => "McastMldVersion",
7246 45u16 => "VlanStatsPerPort",
7247 46u16 => "MultiBoolopt",
7248 47u16 => "McastQuerierState",
7249 48u16 => "FdbNLearned",
7250 49u16 => "FdbMaxLearned",
7251 _ => return None,
7252 };
7253 Some(res)
7254 }
7255}
7256#[derive(Clone, Copy, Default)]
7257pub struct IterableLinkinfoBridgeAttrs<'a> {
7258 buf: &'a [u8],
7259 pos: usize,
7260 orig_loc: usize,
7261}
7262impl<'a> IterableLinkinfoBridgeAttrs<'a> {
7263 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
7264 Self {
7265 buf,
7266 pos: 0,
7267 orig_loc,
7268 }
7269 }
7270 pub fn get_buf(&self) -> &'a [u8] {
7271 self.buf
7272 }
7273}
7274impl<'a> Iterator for IterableLinkinfoBridgeAttrs<'a> {
7275 type Item = Result<LinkinfoBridgeAttrs<'a>, ErrorContext>;
7276 fn next(&mut self) -> Option<Self::Item> {
7277 if self.buf.len() == self.pos {
7278 return None;
7279 }
7280 let pos = self.pos;
7281 let mut r#type = None;
7282 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
7283 r#type = Some(header.r#type);
7284 let res = match header.r#type {
7285 1u16 => LinkinfoBridgeAttrs::ForwardDelay({
7286 let res = parse_u32(next);
7287 let Some(val) = res else { break };
7288 val
7289 }),
7290 2u16 => LinkinfoBridgeAttrs::HelloTime({
7291 let res = parse_u32(next);
7292 let Some(val) = res else { break };
7293 val
7294 }),
7295 3u16 => LinkinfoBridgeAttrs::MaxAge({
7296 let res = parse_u32(next);
7297 let Some(val) = res else { break };
7298 val
7299 }),
7300 4u16 => LinkinfoBridgeAttrs::AgeingTime({
7301 let res = parse_u32(next);
7302 let Some(val) = res else { break };
7303 val
7304 }),
7305 5u16 => LinkinfoBridgeAttrs::StpState({
7306 let res = parse_u32(next);
7307 let Some(val) = res else { break };
7308 val
7309 }),
7310 6u16 => LinkinfoBridgeAttrs::Priority({
7311 let res = parse_u16(next);
7312 let Some(val) = res else { break };
7313 val
7314 }),
7315 7u16 => LinkinfoBridgeAttrs::VlanFiltering({
7316 let res = parse_u8(next);
7317 let Some(val) = res else { break };
7318 val
7319 }),
7320 8u16 => LinkinfoBridgeAttrs::VlanProtocol({
7321 let res = parse_u16(next);
7322 let Some(val) = res else { break };
7323 val
7324 }),
7325 9u16 => LinkinfoBridgeAttrs::GroupFwdMask({
7326 let res = parse_u16(next);
7327 let Some(val) = res else { break };
7328 val
7329 }),
7330 10u16 => LinkinfoBridgeAttrs::RootId({
7331 let res = PushIflaBridgeId::new_from_slice(next);
7332 let Some(val) = res else { break };
7333 val
7334 }),
7335 11u16 => LinkinfoBridgeAttrs::BridgeId({
7336 let res = PushIflaBridgeId::new_from_slice(next);
7337 let Some(val) = res else { break };
7338 val
7339 }),
7340 12u16 => LinkinfoBridgeAttrs::RootPort({
7341 let res = parse_u16(next);
7342 let Some(val) = res else { break };
7343 val
7344 }),
7345 13u16 => LinkinfoBridgeAttrs::RootPathCost({
7346 let res = parse_u32(next);
7347 let Some(val) = res else { break };
7348 val
7349 }),
7350 14u16 => LinkinfoBridgeAttrs::TopologyChange({
7351 let res = parse_u8(next);
7352 let Some(val) = res else { break };
7353 val
7354 }),
7355 15u16 => LinkinfoBridgeAttrs::TopologyChangeDetected({
7356 let res = parse_u8(next);
7357 let Some(val) = res else { break };
7358 val
7359 }),
7360 16u16 => LinkinfoBridgeAttrs::HelloTimer({
7361 let res = parse_u64(next);
7362 let Some(val) = res else { break };
7363 val
7364 }),
7365 17u16 => LinkinfoBridgeAttrs::TcnTimer({
7366 let res = parse_u64(next);
7367 let Some(val) = res else { break };
7368 val
7369 }),
7370 18u16 => LinkinfoBridgeAttrs::TopologyChangeTimer({
7371 let res = parse_u64(next);
7372 let Some(val) = res else { break };
7373 val
7374 }),
7375 19u16 => LinkinfoBridgeAttrs::GcTimer({
7376 let res = parse_u64(next);
7377 let Some(val) = res else { break };
7378 val
7379 }),
7380 20u16 => LinkinfoBridgeAttrs::GroupAddr({
7381 let res = Some(next);
7382 let Some(val) = res else { break };
7383 val
7384 }),
7385 21u16 => LinkinfoBridgeAttrs::FdbFlush({
7386 let res = Some(next);
7387 let Some(val) = res else { break };
7388 val
7389 }),
7390 22u16 => LinkinfoBridgeAttrs::McastRouter({
7391 let res = parse_u8(next);
7392 let Some(val) = res else { break };
7393 val
7394 }),
7395 23u16 => LinkinfoBridgeAttrs::McastSnooping({
7396 let res = parse_u8(next);
7397 let Some(val) = res else { break };
7398 val
7399 }),
7400 24u16 => LinkinfoBridgeAttrs::McastQueryUseIfaddr({
7401 let res = parse_u8(next);
7402 let Some(val) = res else { break };
7403 val
7404 }),
7405 25u16 => LinkinfoBridgeAttrs::McastQuerier({
7406 let res = parse_u8(next);
7407 let Some(val) = res else { break };
7408 val
7409 }),
7410 26u16 => LinkinfoBridgeAttrs::McastHashElasticity({
7411 let res = parse_u32(next);
7412 let Some(val) = res else { break };
7413 val
7414 }),
7415 27u16 => LinkinfoBridgeAttrs::McastHashMax({
7416 let res = parse_u32(next);
7417 let Some(val) = res else { break };
7418 val
7419 }),
7420 28u16 => LinkinfoBridgeAttrs::McastLastMemberCnt({
7421 let res = parse_u32(next);
7422 let Some(val) = res else { break };
7423 val
7424 }),
7425 29u16 => LinkinfoBridgeAttrs::McastStartupQueryCnt({
7426 let res = parse_u32(next);
7427 let Some(val) = res else { break };
7428 val
7429 }),
7430 30u16 => LinkinfoBridgeAttrs::McastLastMemberIntvl({
7431 let res = parse_u64(next);
7432 let Some(val) = res else { break };
7433 val
7434 }),
7435 31u16 => LinkinfoBridgeAttrs::McastMembershipIntvl({
7436 let res = parse_u64(next);
7437 let Some(val) = res else { break };
7438 val
7439 }),
7440 32u16 => LinkinfoBridgeAttrs::McastQuerierIntvl({
7441 let res = parse_u64(next);
7442 let Some(val) = res else { break };
7443 val
7444 }),
7445 33u16 => LinkinfoBridgeAttrs::McastQueryIntvl({
7446 let res = parse_u64(next);
7447 let Some(val) = res else { break };
7448 val
7449 }),
7450 34u16 => LinkinfoBridgeAttrs::McastQueryResponseIntvl({
7451 let res = parse_u64(next);
7452 let Some(val) = res else { break };
7453 val
7454 }),
7455 35u16 => LinkinfoBridgeAttrs::McastStartupQueryIntvl({
7456 let res = parse_u64(next);
7457 let Some(val) = res else { break };
7458 val
7459 }),
7460 36u16 => LinkinfoBridgeAttrs::NfCallIptables({
7461 let res = parse_u8(next);
7462 let Some(val) = res else { break };
7463 val
7464 }),
7465 37u16 => LinkinfoBridgeAttrs::NfCallIp6tables({
7466 let res = parse_u8(next);
7467 let Some(val) = res else { break };
7468 val
7469 }),
7470 38u16 => LinkinfoBridgeAttrs::NfCallArptables({
7471 let res = parse_u8(next);
7472 let Some(val) = res else { break };
7473 val
7474 }),
7475 39u16 => LinkinfoBridgeAttrs::VlanDefaultPvid({
7476 let res = parse_u16(next);
7477 let Some(val) = res else { break };
7478 val
7479 }),
7480 40u16 => LinkinfoBridgeAttrs::Pad({
7481 let res = Some(next);
7482 let Some(val) = res else { break };
7483 val
7484 }),
7485 41u16 => LinkinfoBridgeAttrs::VlanStatsEnabled({
7486 let res = parse_u8(next);
7487 let Some(val) = res else { break };
7488 val
7489 }),
7490 42u16 => LinkinfoBridgeAttrs::McastStatsEnabled({
7491 let res = parse_u8(next);
7492 let Some(val) = res else { break };
7493 val
7494 }),
7495 43u16 => LinkinfoBridgeAttrs::McastIgmpVersion({
7496 let res = parse_u8(next);
7497 let Some(val) = res else { break };
7498 val
7499 }),
7500 44u16 => LinkinfoBridgeAttrs::McastMldVersion({
7501 let res = parse_u8(next);
7502 let Some(val) = res else { break };
7503 val
7504 }),
7505 45u16 => LinkinfoBridgeAttrs::VlanStatsPerPort({
7506 let res = parse_u8(next);
7507 let Some(val) = res else { break };
7508 val
7509 }),
7510 46u16 => LinkinfoBridgeAttrs::MultiBoolopt({
7511 let res = PushBrBooloptMulti::new_from_slice(next);
7512 let Some(val) = res else { break };
7513 val
7514 }),
7515 47u16 => LinkinfoBridgeAttrs::McastQuerierState({
7516 let res = Some(next);
7517 let Some(val) = res else { break };
7518 val
7519 }),
7520 48u16 => LinkinfoBridgeAttrs::FdbNLearned({
7521 let res = parse_u32(next);
7522 let Some(val) = res else { break };
7523 val
7524 }),
7525 49u16 => LinkinfoBridgeAttrs::FdbMaxLearned({
7526 let res = parse_u32(next);
7527 let Some(val) = res else { break };
7528 val
7529 }),
7530 n => {
7531 if cfg!(any(test, feature = "deny-unknown-attrs")) {
7532 break;
7533 } else {
7534 continue;
7535 }
7536 }
7537 };
7538 return Some(Ok(res));
7539 }
7540 Some(Err(ErrorContext::new(
7541 "LinkinfoBridgeAttrs",
7542 r#type.and_then(|t| LinkinfoBridgeAttrs::attr_from_type(t)),
7543 self.orig_loc,
7544 self.buf.as_ptr().wrapping_add(pos) as usize,
7545 )))
7546 }
7547}
7548impl<'a> std::fmt::Debug for IterableLinkinfoBridgeAttrs<'_> {
7549 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7550 let mut fmt = f.debug_struct("LinkinfoBridgeAttrs");
7551 for attr in self.clone() {
7552 let attr = match attr {
7553 Ok(a) => a,
7554 Err(err) => {
7555 fmt.finish()?;
7556 f.write_str("Err(")?;
7557 err.fmt(f)?;
7558 return f.write_str(")");
7559 }
7560 };
7561 match attr {
7562 LinkinfoBridgeAttrs::ForwardDelay(val) => fmt.field("ForwardDelay", &val),
7563 LinkinfoBridgeAttrs::HelloTime(val) => fmt.field("HelloTime", &val),
7564 LinkinfoBridgeAttrs::MaxAge(val) => fmt.field("MaxAge", &val),
7565 LinkinfoBridgeAttrs::AgeingTime(val) => fmt.field("AgeingTime", &val),
7566 LinkinfoBridgeAttrs::StpState(val) => fmt.field("StpState", &val),
7567 LinkinfoBridgeAttrs::Priority(val) => fmt.field("Priority", &val),
7568 LinkinfoBridgeAttrs::VlanFiltering(val) => fmt.field("VlanFiltering", &val),
7569 LinkinfoBridgeAttrs::VlanProtocol(val) => fmt.field("VlanProtocol", &val),
7570 LinkinfoBridgeAttrs::GroupFwdMask(val) => fmt.field("GroupFwdMask", &val),
7571 LinkinfoBridgeAttrs::RootId(val) => fmt.field("RootId", &val),
7572 LinkinfoBridgeAttrs::BridgeId(val) => fmt.field("BridgeId", &val),
7573 LinkinfoBridgeAttrs::RootPort(val) => fmt.field("RootPort", &val),
7574 LinkinfoBridgeAttrs::RootPathCost(val) => fmt.field("RootPathCost", &val),
7575 LinkinfoBridgeAttrs::TopologyChange(val) => fmt.field("TopologyChange", &val),
7576 LinkinfoBridgeAttrs::TopologyChangeDetected(val) => {
7577 fmt.field("TopologyChangeDetected", &val)
7578 }
7579 LinkinfoBridgeAttrs::HelloTimer(val) => fmt.field("HelloTimer", &val),
7580 LinkinfoBridgeAttrs::TcnTimer(val) => fmt.field("TcnTimer", &val),
7581 LinkinfoBridgeAttrs::TopologyChangeTimer(val) => {
7582 fmt.field("TopologyChangeTimer", &val)
7583 }
7584 LinkinfoBridgeAttrs::GcTimer(val) => fmt.field("GcTimer", &val),
7585 LinkinfoBridgeAttrs::GroupAddr(val) => fmt.field("GroupAddr", &val),
7586 LinkinfoBridgeAttrs::FdbFlush(val) => fmt.field("FdbFlush", &val),
7587 LinkinfoBridgeAttrs::McastRouter(val) => fmt.field("McastRouter", &val),
7588 LinkinfoBridgeAttrs::McastSnooping(val) => fmt.field("McastSnooping", &val),
7589 LinkinfoBridgeAttrs::McastQueryUseIfaddr(val) => {
7590 fmt.field("McastQueryUseIfaddr", &val)
7591 }
7592 LinkinfoBridgeAttrs::McastQuerier(val) => fmt.field("McastQuerier", &val),
7593 LinkinfoBridgeAttrs::McastHashElasticity(val) => {
7594 fmt.field("McastHashElasticity", &val)
7595 }
7596 LinkinfoBridgeAttrs::McastHashMax(val) => fmt.field("McastHashMax", &val),
7597 LinkinfoBridgeAttrs::McastLastMemberCnt(val) => {
7598 fmt.field("McastLastMemberCnt", &val)
7599 }
7600 LinkinfoBridgeAttrs::McastStartupQueryCnt(val) => {
7601 fmt.field("McastStartupQueryCnt", &val)
7602 }
7603 LinkinfoBridgeAttrs::McastLastMemberIntvl(val) => {
7604 fmt.field("McastLastMemberIntvl", &val)
7605 }
7606 LinkinfoBridgeAttrs::McastMembershipIntvl(val) => {
7607 fmt.field("McastMembershipIntvl", &val)
7608 }
7609 LinkinfoBridgeAttrs::McastQuerierIntvl(val) => fmt.field("McastQuerierIntvl", &val),
7610 LinkinfoBridgeAttrs::McastQueryIntvl(val) => fmt.field("McastQueryIntvl", &val),
7611 LinkinfoBridgeAttrs::McastQueryResponseIntvl(val) => {
7612 fmt.field("McastQueryResponseIntvl", &val)
7613 }
7614 LinkinfoBridgeAttrs::McastStartupQueryIntvl(val) => {
7615 fmt.field("McastStartupQueryIntvl", &val)
7616 }
7617 LinkinfoBridgeAttrs::NfCallIptables(val) => fmt.field("NfCallIptables", &val),
7618 LinkinfoBridgeAttrs::NfCallIp6tables(val) => fmt.field("NfCallIp6tables", &val),
7619 LinkinfoBridgeAttrs::NfCallArptables(val) => fmt.field("NfCallArptables", &val),
7620 LinkinfoBridgeAttrs::VlanDefaultPvid(val) => fmt.field("VlanDefaultPvid", &val),
7621 LinkinfoBridgeAttrs::Pad(val) => fmt.field("Pad", &val),
7622 LinkinfoBridgeAttrs::VlanStatsEnabled(val) => fmt.field("VlanStatsEnabled", &val),
7623 LinkinfoBridgeAttrs::McastStatsEnabled(val) => fmt.field("McastStatsEnabled", &val),
7624 LinkinfoBridgeAttrs::McastIgmpVersion(val) => fmt.field("McastIgmpVersion", &val),
7625 LinkinfoBridgeAttrs::McastMldVersion(val) => fmt.field("McastMldVersion", &val),
7626 LinkinfoBridgeAttrs::VlanStatsPerPort(val) => fmt.field("VlanStatsPerPort", &val),
7627 LinkinfoBridgeAttrs::MultiBoolopt(val) => fmt.field("MultiBoolopt", &val),
7628 LinkinfoBridgeAttrs::McastQuerierState(val) => fmt.field("McastQuerierState", &val),
7629 LinkinfoBridgeAttrs::FdbNLearned(val) => fmt.field("FdbNLearned", &val),
7630 LinkinfoBridgeAttrs::FdbMaxLearned(val) => fmt.field("FdbMaxLearned", &val),
7631 };
7632 }
7633 fmt.finish()
7634 }
7635}
7636impl IterableLinkinfoBridgeAttrs<'_> {
7637 pub fn lookup_attr(
7638 &self,
7639 offset: usize,
7640 missing_type: Option<u16>,
7641 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
7642 let mut stack = Vec::new();
7643 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
7644 if cur == offset {
7645 stack.push(("LinkinfoBridgeAttrs", offset));
7646 return (
7647 stack,
7648 missing_type.and_then(|t| LinkinfoBridgeAttrs::attr_from_type(t)),
7649 );
7650 }
7651 if cur > offset || cur + self.buf.len() < offset {
7652 return (stack, None);
7653 }
7654 let mut attrs = self.clone();
7655 let mut last_off = cur + attrs.pos;
7656 while let Some(attr) = attrs.next() {
7657 let Ok(attr) = attr else { break };
7658 match attr {
7659 LinkinfoBridgeAttrs::ForwardDelay(val) => {
7660 if last_off == offset {
7661 stack.push(("ForwardDelay", last_off));
7662 break;
7663 }
7664 }
7665 LinkinfoBridgeAttrs::HelloTime(val) => {
7666 if last_off == offset {
7667 stack.push(("HelloTime", last_off));
7668 break;
7669 }
7670 }
7671 LinkinfoBridgeAttrs::MaxAge(val) => {
7672 if last_off == offset {
7673 stack.push(("MaxAge", last_off));
7674 break;
7675 }
7676 }
7677 LinkinfoBridgeAttrs::AgeingTime(val) => {
7678 if last_off == offset {
7679 stack.push(("AgeingTime", last_off));
7680 break;
7681 }
7682 }
7683 LinkinfoBridgeAttrs::StpState(val) => {
7684 if last_off == offset {
7685 stack.push(("StpState", last_off));
7686 break;
7687 }
7688 }
7689 LinkinfoBridgeAttrs::Priority(val) => {
7690 if last_off == offset {
7691 stack.push(("Priority", last_off));
7692 break;
7693 }
7694 }
7695 LinkinfoBridgeAttrs::VlanFiltering(val) => {
7696 if last_off == offset {
7697 stack.push(("VlanFiltering", last_off));
7698 break;
7699 }
7700 }
7701 LinkinfoBridgeAttrs::VlanProtocol(val) => {
7702 if last_off == offset {
7703 stack.push(("VlanProtocol", last_off));
7704 break;
7705 }
7706 }
7707 LinkinfoBridgeAttrs::GroupFwdMask(val) => {
7708 if last_off == offset {
7709 stack.push(("GroupFwdMask", last_off));
7710 break;
7711 }
7712 }
7713 LinkinfoBridgeAttrs::RootId(val) => {
7714 if last_off == offset {
7715 stack.push(("RootId", last_off));
7716 break;
7717 }
7718 }
7719 LinkinfoBridgeAttrs::BridgeId(val) => {
7720 if last_off == offset {
7721 stack.push(("BridgeId", last_off));
7722 break;
7723 }
7724 }
7725 LinkinfoBridgeAttrs::RootPort(val) => {
7726 if last_off == offset {
7727 stack.push(("RootPort", last_off));
7728 break;
7729 }
7730 }
7731 LinkinfoBridgeAttrs::RootPathCost(val) => {
7732 if last_off == offset {
7733 stack.push(("RootPathCost", last_off));
7734 break;
7735 }
7736 }
7737 LinkinfoBridgeAttrs::TopologyChange(val) => {
7738 if last_off == offset {
7739 stack.push(("TopologyChange", last_off));
7740 break;
7741 }
7742 }
7743 LinkinfoBridgeAttrs::TopologyChangeDetected(val) => {
7744 if last_off == offset {
7745 stack.push(("TopologyChangeDetected", last_off));
7746 break;
7747 }
7748 }
7749 LinkinfoBridgeAttrs::HelloTimer(val) => {
7750 if last_off == offset {
7751 stack.push(("HelloTimer", last_off));
7752 break;
7753 }
7754 }
7755 LinkinfoBridgeAttrs::TcnTimer(val) => {
7756 if last_off == offset {
7757 stack.push(("TcnTimer", last_off));
7758 break;
7759 }
7760 }
7761 LinkinfoBridgeAttrs::TopologyChangeTimer(val) => {
7762 if last_off == offset {
7763 stack.push(("TopologyChangeTimer", last_off));
7764 break;
7765 }
7766 }
7767 LinkinfoBridgeAttrs::GcTimer(val) => {
7768 if last_off == offset {
7769 stack.push(("GcTimer", last_off));
7770 break;
7771 }
7772 }
7773 LinkinfoBridgeAttrs::GroupAddr(val) => {
7774 if last_off == offset {
7775 stack.push(("GroupAddr", last_off));
7776 break;
7777 }
7778 }
7779 LinkinfoBridgeAttrs::FdbFlush(val) => {
7780 if last_off == offset {
7781 stack.push(("FdbFlush", last_off));
7782 break;
7783 }
7784 }
7785 LinkinfoBridgeAttrs::McastRouter(val) => {
7786 if last_off == offset {
7787 stack.push(("McastRouter", last_off));
7788 break;
7789 }
7790 }
7791 LinkinfoBridgeAttrs::McastSnooping(val) => {
7792 if last_off == offset {
7793 stack.push(("McastSnooping", last_off));
7794 break;
7795 }
7796 }
7797 LinkinfoBridgeAttrs::McastQueryUseIfaddr(val) => {
7798 if last_off == offset {
7799 stack.push(("McastQueryUseIfaddr", last_off));
7800 break;
7801 }
7802 }
7803 LinkinfoBridgeAttrs::McastQuerier(val) => {
7804 if last_off == offset {
7805 stack.push(("McastQuerier", last_off));
7806 break;
7807 }
7808 }
7809 LinkinfoBridgeAttrs::McastHashElasticity(val) => {
7810 if last_off == offset {
7811 stack.push(("McastHashElasticity", last_off));
7812 break;
7813 }
7814 }
7815 LinkinfoBridgeAttrs::McastHashMax(val) => {
7816 if last_off == offset {
7817 stack.push(("McastHashMax", last_off));
7818 break;
7819 }
7820 }
7821 LinkinfoBridgeAttrs::McastLastMemberCnt(val) => {
7822 if last_off == offset {
7823 stack.push(("McastLastMemberCnt", last_off));
7824 break;
7825 }
7826 }
7827 LinkinfoBridgeAttrs::McastStartupQueryCnt(val) => {
7828 if last_off == offset {
7829 stack.push(("McastStartupQueryCnt", last_off));
7830 break;
7831 }
7832 }
7833 LinkinfoBridgeAttrs::McastLastMemberIntvl(val) => {
7834 if last_off == offset {
7835 stack.push(("McastLastMemberIntvl", last_off));
7836 break;
7837 }
7838 }
7839 LinkinfoBridgeAttrs::McastMembershipIntvl(val) => {
7840 if last_off == offset {
7841 stack.push(("McastMembershipIntvl", last_off));
7842 break;
7843 }
7844 }
7845 LinkinfoBridgeAttrs::McastQuerierIntvl(val) => {
7846 if last_off == offset {
7847 stack.push(("McastQuerierIntvl", last_off));
7848 break;
7849 }
7850 }
7851 LinkinfoBridgeAttrs::McastQueryIntvl(val) => {
7852 if last_off == offset {
7853 stack.push(("McastQueryIntvl", last_off));
7854 break;
7855 }
7856 }
7857 LinkinfoBridgeAttrs::McastQueryResponseIntvl(val) => {
7858 if last_off == offset {
7859 stack.push(("McastQueryResponseIntvl", last_off));
7860 break;
7861 }
7862 }
7863 LinkinfoBridgeAttrs::McastStartupQueryIntvl(val) => {
7864 if last_off == offset {
7865 stack.push(("McastStartupQueryIntvl", last_off));
7866 break;
7867 }
7868 }
7869 LinkinfoBridgeAttrs::NfCallIptables(val) => {
7870 if last_off == offset {
7871 stack.push(("NfCallIptables", last_off));
7872 break;
7873 }
7874 }
7875 LinkinfoBridgeAttrs::NfCallIp6tables(val) => {
7876 if last_off == offset {
7877 stack.push(("NfCallIp6tables", last_off));
7878 break;
7879 }
7880 }
7881 LinkinfoBridgeAttrs::NfCallArptables(val) => {
7882 if last_off == offset {
7883 stack.push(("NfCallArptables", last_off));
7884 break;
7885 }
7886 }
7887 LinkinfoBridgeAttrs::VlanDefaultPvid(val) => {
7888 if last_off == offset {
7889 stack.push(("VlanDefaultPvid", last_off));
7890 break;
7891 }
7892 }
7893 LinkinfoBridgeAttrs::Pad(val) => {
7894 if last_off == offset {
7895 stack.push(("Pad", last_off));
7896 break;
7897 }
7898 }
7899 LinkinfoBridgeAttrs::VlanStatsEnabled(val) => {
7900 if last_off == offset {
7901 stack.push(("VlanStatsEnabled", last_off));
7902 break;
7903 }
7904 }
7905 LinkinfoBridgeAttrs::McastStatsEnabled(val) => {
7906 if last_off == offset {
7907 stack.push(("McastStatsEnabled", last_off));
7908 break;
7909 }
7910 }
7911 LinkinfoBridgeAttrs::McastIgmpVersion(val) => {
7912 if last_off == offset {
7913 stack.push(("McastIgmpVersion", last_off));
7914 break;
7915 }
7916 }
7917 LinkinfoBridgeAttrs::McastMldVersion(val) => {
7918 if last_off == offset {
7919 stack.push(("McastMldVersion", last_off));
7920 break;
7921 }
7922 }
7923 LinkinfoBridgeAttrs::VlanStatsPerPort(val) => {
7924 if last_off == offset {
7925 stack.push(("VlanStatsPerPort", last_off));
7926 break;
7927 }
7928 }
7929 LinkinfoBridgeAttrs::MultiBoolopt(val) => {
7930 if last_off == offset {
7931 stack.push(("MultiBoolopt", last_off));
7932 break;
7933 }
7934 }
7935 LinkinfoBridgeAttrs::McastQuerierState(val) => {
7936 if last_off == offset {
7937 stack.push(("McastQuerierState", last_off));
7938 break;
7939 }
7940 }
7941 LinkinfoBridgeAttrs::FdbNLearned(val) => {
7942 if last_off == offset {
7943 stack.push(("FdbNLearned", last_off));
7944 break;
7945 }
7946 }
7947 LinkinfoBridgeAttrs::FdbMaxLearned(val) => {
7948 if last_off == offset {
7949 stack.push(("FdbMaxLearned", last_off));
7950 break;
7951 }
7952 }
7953 _ => {}
7954 };
7955 last_off = cur + attrs.pos;
7956 }
7957 if !stack.is_empty() {
7958 stack.push(("LinkinfoBridgeAttrs", cur));
7959 }
7960 (stack, None)
7961 }
7962}
7963#[derive(Clone)]
7964pub enum LinkinfoBrportAttrs<'a> {
7965 State(u8),
7966 Priority(u16),
7967 Cost(u32),
7968 Mode(()),
7969 Guard(()),
7970 Protect(()),
7971 FastLeave(()),
7972 Learning(()),
7973 UnicastFlood(()),
7974 Proxyarp(()),
7975 LearningSync(()),
7976 ProxyarpWifi(()),
7977 RootId(PushIflaBridgeId),
7978 BridgeId(PushIflaBridgeId),
7979 DesignatedPort(u16),
7980 DesignatedCost(u16),
7981 Id(u16),
7982 No(u16),
7983 TopologyChangeAck(u8),
7984 ConfigPending(u8),
7985 MessageAgeTimer(u64),
7986 ForwardDelayTimer(u64),
7987 HoldTimer(u64),
7988 Flush(()),
7989 MulticastRouter(u8),
7990 Pad(&'a [u8]),
7991 McastFlood(()),
7992 McastToUcast(()),
7993 VlanTunnel(()),
7994 BcastFlood(()),
7995 GroupFwdMask(u16),
7996 NeighSuppress(()),
7997 Isolated(()),
7998 BackupPort(u32),
7999 MrpRingOpen(()),
8000 MrpInOpen(()),
8001 McastEhtHostsLimit(u32),
8002 McastEhtHostsCnt(u32),
8003 Locked(()),
8004 Mab(()),
8005 McastNGroups(u32),
8006 McastMaxGroups(u32),
8007 NeighVlanSuppress(()),
8008 BackupNhid(u32),
8009}
8010impl<'a> IterableLinkinfoBrportAttrs<'a> {
8011 pub fn get_state(&self) -> Result<u8, ErrorContext> {
8012 let mut iter = self.clone();
8013 iter.pos = 0;
8014 for attr in iter {
8015 if let LinkinfoBrportAttrs::State(val) = attr? {
8016 return Ok(val);
8017 }
8018 }
8019 Err(ErrorContext::new_missing(
8020 "LinkinfoBrportAttrs",
8021 "State",
8022 self.orig_loc,
8023 self.buf.as_ptr() as usize,
8024 ))
8025 }
8026 pub fn get_priority(&self) -> Result<u16, ErrorContext> {
8027 let mut iter = self.clone();
8028 iter.pos = 0;
8029 for attr in iter {
8030 if let LinkinfoBrportAttrs::Priority(val) = attr? {
8031 return Ok(val);
8032 }
8033 }
8034 Err(ErrorContext::new_missing(
8035 "LinkinfoBrportAttrs",
8036 "Priority",
8037 self.orig_loc,
8038 self.buf.as_ptr() as usize,
8039 ))
8040 }
8041 pub fn get_cost(&self) -> Result<u32, ErrorContext> {
8042 let mut iter = self.clone();
8043 iter.pos = 0;
8044 for attr in iter {
8045 if let LinkinfoBrportAttrs::Cost(val) = attr? {
8046 return Ok(val);
8047 }
8048 }
8049 Err(ErrorContext::new_missing(
8050 "LinkinfoBrportAttrs",
8051 "Cost",
8052 self.orig_loc,
8053 self.buf.as_ptr() as usize,
8054 ))
8055 }
8056 pub fn get_mode(&self) -> Result<(), ErrorContext> {
8057 let mut iter = self.clone();
8058 iter.pos = 0;
8059 for attr in iter {
8060 if let LinkinfoBrportAttrs::Mode(val) = attr? {
8061 return Ok(val);
8062 }
8063 }
8064 Err(ErrorContext::new_missing(
8065 "LinkinfoBrportAttrs",
8066 "Mode",
8067 self.orig_loc,
8068 self.buf.as_ptr() as usize,
8069 ))
8070 }
8071 pub fn get_guard(&self) -> Result<(), ErrorContext> {
8072 let mut iter = self.clone();
8073 iter.pos = 0;
8074 for attr in iter {
8075 if let LinkinfoBrportAttrs::Guard(val) = attr? {
8076 return Ok(val);
8077 }
8078 }
8079 Err(ErrorContext::new_missing(
8080 "LinkinfoBrportAttrs",
8081 "Guard",
8082 self.orig_loc,
8083 self.buf.as_ptr() as usize,
8084 ))
8085 }
8086 pub fn get_protect(&self) -> Result<(), ErrorContext> {
8087 let mut iter = self.clone();
8088 iter.pos = 0;
8089 for attr in iter {
8090 if let LinkinfoBrportAttrs::Protect(val) = attr? {
8091 return Ok(val);
8092 }
8093 }
8094 Err(ErrorContext::new_missing(
8095 "LinkinfoBrportAttrs",
8096 "Protect",
8097 self.orig_loc,
8098 self.buf.as_ptr() as usize,
8099 ))
8100 }
8101 pub fn get_fast_leave(&self) -> Result<(), ErrorContext> {
8102 let mut iter = self.clone();
8103 iter.pos = 0;
8104 for attr in iter {
8105 if let LinkinfoBrportAttrs::FastLeave(val) = attr? {
8106 return Ok(val);
8107 }
8108 }
8109 Err(ErrorContext::new_missing(
8110 "LinkinfoBrportAttrs",
8111 "FastLeave",
8112 self.orig_loc,
8113 self.buf.as_ptr() as usize,
8114 ))
8115 }
8116 pub fn get_learning(&self) -> Result<(), ErrorContext> {
8117 let mut iter = self.clone();
8118 iter.pos = 0;
8119 for attr in iter {
8120 if let LinkinfoBrportAttrs::Learning(val) = attr? {
8121 return Ok(val);
8122 }
8123 }
8124 Err(ErrorContext::new_missing(
8125 "LinkinfoBrportAttrs",
8126 "Learning",
8127 self.orig_loc,
8128 self.buf.as_ptr() as usize,
8129 ))
8130 }
8131 pub fn get_unicast_flood(&self) -> Result<(), ErrorContext> {
8132 let mut iter = self.clone();
8133 iter.pos = 0;
8134 for attr in iter {
8135 if let LinkinfoBrportAttrs::UnicastFlood(val) = attr? {
8136 return Ok(val);
8137 }
8138 }
8139 Err(ErrorContext::new_missing(
8140 "LinkinfoBrportAttrs",
8141 "UnicastFlood",
8142 self.orig_loc,
8143 self.buf.as_ptr() as usize,
8144 ))
8145 }
8146 pub fn get_proxyarp(&self) -> Result<(), ErrorContext> {
8147 let mut iter = self.clone();
8148 iter.pos = 0;
8149 for attr in iter {
8150 if let LinkinfoBrportAttrs::Proxyarp(val) = attr? {
8151 return Ok(val);
8152 }
8153 }
8154 Err(ErrorContext::new_missing(
8155 "LinkinfoBrportAttrs",
8156 "Proxyarp",
8157 self.orig_loc,
8158 self.buf.as_ptr() as usize,
8159 ))
8160 }
8161 pub fn get_learning_sync(&self) -> Result<(), ErrorContext> {
8162 let mut iter = self.clone();
8163 iter.pos = 0;
8164 for attr in iter {
8165 if let LinkinfoBrportAttrs::LearningSync(val) = attr? {
8166 return Ok(val);
8167 }
8168 }
8169 Err(ErrorContext::new_missing(
8170 "LinkinfoBrportAttrs",
8171 "LearningSync",
8172 self.orig_loc,
8173 self.buf.as_ptr() as usize,
8174 ))
8175 }
8176 pub fn get_proxyarp_wifi(&self) -> Result<(), ErrorContext> {
8177 let mut iter = self.clone();
8178 iter.pos = 0;
8179 for attr in iter {
8180 if let LinkinfoBrportAttrs::ProxyarpWifi(val) = attr? {
8181 return Ok(val);
8182 }
8183 }
8184 Err(ErrorContext::new_missing(
8185 "LinkinfoBrportAttrs",
8186 "ProxyarpWifi",
8187 self.orig_loc,
8188 self.buf.as_ptr() as usize,
8189 ))
8190 }
8191 pub fn get_root_id(&self) -> Result<PushIflaBridgeId, ErrorContext> {
8192 let mut iter = self.clone();
8193 iter.pos = 0;
8194 for attr in iter {
8195 if let LinkinfoBrportAttrs::RootId(val) = attr? {
8196 return Ok(val);
8197 }
8198 }
8199 Err(ErrorContext::new_missing(
8200 "LinkinfoBrportAttrs",
8201 "RootId",
8202 self.orig_loc,
8203 self.buf.as_ptr() as usize,
8204 ))
8205 }
8206 pub fn get_bridge_id(&self) -> Result<PushIflaBridgeId, ErrorContext> {
8207 let mut iter = self.clone();
8208 iter.pos = 0;
8209 for attr in iter {
8210 if let LinkinfoBrportAttrs::BridgeId(val) = attr? {
8211 return Ok(val);
8212 }
8213 }
8214 Err(ErrorContext::new_missing(
8215 "LinkinfoBrportAttrs",
8216 "BridgeId",
8217 self.orig_loc,
8218 self.buf.as_ptr() as usize,
8219 ))
8220 }
8221 pub fn get_designated_port(&self) -> Result<u16, ErrorContext> {
8222 let mut iter = self.clone();
8223 iter.pos = 0;
8224 for attr in iter {
8225 if let LinkinfoBrportAttrs::DesignatedPort(val) = attr? {
8226 return Ok(val);
8227 }
8228 }
8229 Err(ErrorContext::new_missing(
8230 "LinkinfoBrportAttrs",
8231 "DesignatedPort",
8232 self.orig_loc,
8233 self.buf.as_ptr() as usize,
8234 ))
8235 }
8236 pub fn get_designated_cost(&self) -> Result<u16, ErrorContext> {
8237 let mut iter = self.clone();
8238 iter.pos = 0;
8239 for attr in iter {
8240 if let LinkinfoBrportAttrs::DesignatedCost(val) = attr? {
8241 return Ok(val);
8242 }
8243 }
8244 Err(ErrorContext::new_missing(
8245 "LinkinfoBrportAttrs",
8246 "DesignatedCost",
8247 self.orig_loc,
8248 self.buf.as_ptr() as usize,
8249 ))
8250 }
8251 pub fn get_id(&self) -> Result<u16, ErrorContext> {
8252 let mut iter = self.clone();
8253 iter.pos = 0;
8254 for attr in iter {
8255 if let LinkinfoBrportAttrs::Id(val) = attr? {
8256 return Ok(val);
8257 }
8258 }
8259 Err(ErrorContext::new_missing(
8260 "LinkinfoBrportAttrs",
8261 "Id",
8262 self.orig_loc,
8263 self.buf.as_ptr() as usize,
8264 ))
8265 }
8266 pub fn get_no(&self) -> Result<u16, ErrorContext> {
8267 let mut iter = self.clone();
8268 iter.pos = 0;
8269 for attr in iter {
8270 if let LinkinfoBrportAttrs::No(val) = attr? {
8271 return Ok(val);
8272 }
8273 }
8274 Err(ErrorContext::new_missing(
8275 "LinkinfoBrportAttrs",
8276 "No",
8277 self.orig_loc,
8278 self.buf.as_ptr() as usize,
8279 ))
8280 }
8281 pub fn get_topology_change_ack(&self) -> Result<u8, ErrorContext> {
8282 let mut iter = self.clone();
8283 iter.pos = 0;
8284 for attr in iter {
8285 if let LinkinfoBrportAttrs::TopologyChangeAck(val) = attr? {
8286 return Ok(val);
8287 }
8288 }
8289 Err(ErrorContext::new_missing(
8290 "LinkinfoBrportAttrs",
8291 "TopologyChangeAck",
8292 self.orig_loc,
8293 self.buf.as_ptr() as usize,
8294 ))
8295 }
8296 pub fn get_config_pending(&self) -> Result<u8, ErrorContext> {
8297 let mut iter = self.clone();
8298 iter.pos = 0;
8299 for attr in iter {
8300 if let LinkinfoBrportAttrs::ConfigPending(val) = attr? {
8301 return Ok(val);
8302 }
8303 }
8304 Err(ErrorContext::new_missing(
8305 "LinkinfoBrportAttrs",
8306 "ConfigPending",
8307 self.orig_loc,
8308 self.buf.as_ptr() as usize,
8309 ))
8310 }
8311 pub fn get_message_age_timer(&self) -> Result<u64, ErrorContext> {
8312 let mut iter = self.clone();
8313 iter.pos = 0;
8314 for attr in iter {
8315 if let LinkinfoBrportAttrs::MessageAgeTimer(val) = attr? {
8316 return Ok(val);
8317 }
8318 }
8319 Err(ErrorContext::new_missing(
8320 "LinkinfoBrportAttrs",
8321 "MessageAgeTimer",
8322 self.orig_loc,
8323 self.buf.as_ptr() as usize,
8324 ))
8325 }
8326 pub fn get_forward_delay_timer(&self) -> Result<u64, ErrorContext> {
8327 let mut iter = self.clone();
8328 iter.pos = 0;
8329 for attr in iter {
8330 if let LinkinfoBrportAttrs::ForwardDelayTimer(val) = attr? {
8331 return Ok(val);
8332 }
8333 }
8334 Err(ErrorContext::new_missing(
8335 "LinkinfoBrportAttrs",
8336 "ForwardDelayTimer",
8337 self.orig_loc,
8338 self.buf.as_ptr() as usize,
8339 ))
8340 }
8341 pub fn get_hold_timer(&self) -> Result<u64, ErrorContext> {
8342 let mut iter = self.clone();
8343 iter.pos = 0;
8344 for attr in iter {
8345 if let LinkinfoBrportAttrs::HoldTimer(val) = attr? {
8346 return Ok(val);
8347 }
8348 }
8349 Err(ErrorContext::new_missing(
8350 "LinkinfoBrportAttrs",
8351 "HoldTimer",
8352 self.orig_loc,
8353 self.buf.as_ptr() as usize,
8354 ))
8355 }
8356 pub fn get_flush(&self) -> Result<(), ErrorContext> {
8357 let mut iter = self.clone();
8358 iter.pos = 0;
8359 for attr in iter {
8360 if let LinkinfoBrportAttrs::Flush(val) = attr? {
8361 return Ok(val);
8362 }
8363 }
8364 Err(ErrorContext::new_missing(
8365 "LinkinfoBrportAttrs",
8366 "Flush",
8367 self.orig_loc,
8368 self.buf.as_ptr() as usize,
8369 ))
8370 }
8371 pub fn get_multicast_router(&self) -> Result<u8, ErrorContext> {
8372 let mut iter = self.clone();
8373 iter.pos = 0;
8374 for attr in iter {
8375 if let LinkinfoBrportAttrs::MulticastRouter(val) = attr? {
8376 return Ok(val);
8377 }
8378 }
8379 Err(ErrorContext::new_missing(
8380 "LinkinfoBrportAttrs",
8381 "MulticastRouter",
8382 self.orig_loc,
8383 self.buf.as_ptr() as usize,
8384 ))
8385 }
8386 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
8387 let mut iter = self.clone();
8388 iter.pos = 0;
8389 for attr in iter {
8390 if let LinkinfoBrportAttrs::Pad(val) = attr? {
8391 return Ok(val);
8392 }
8393 }
8394 Err(ErrorContext::new_missing(
8395 "LinkinfoBrportAttrs",
8396 "Pad",
8397 self.orig_loc,
8398 self.buf.as_ptr() as usize,
8399 ))
8400 }
8401 pub fn get_mcast_flood(&self) -> Result<(), ErrorContext> {
8402 let mut iter = self.clone();
8403 iter.pos = 0;
8404 for attr in iter {
8405 if let LinkinfoBrportAttrs::McastFlood(val) = attr? {
8406 return Ok(val);
8407 }
8408 }
8409 Err(ErrorContext::new_missing(
8410 "LinkinfoBrportAttrs",
8411 "McastFlood",
8412 self.orig_loc,
8413 self.buf.as_ptr() as usize,
8414 ))
8415 }
8416 pub fn get_mcast_to_ucast(&self) -> Result<(), ErrorContext> {
8417 let mut iter = self.clone();
8418 iter.pos = 0;
8419 for attr in iter {
8420 if let LinkinfoBrportAttrs::McastToUcast(val) = attr? {
8421 return Ok(val);
8422 }
8423 }
8424 Err(ErrorContext::new_missing(
8425 "LinkinfoBrportAttrs",
8426 "McastToUcast",
8427 self.orig_loc,
8428 self.buf.as_ptr() as usize,
8429 ))
8430 }
8431 pub fn get_vlan_tunnel(&self) -> Result<(), ErrorContext> {
8432 let mut iter = self.clone();
8433 iter.pos = 0;
8434 for attr in iter {
8435 if let LinkinfoBrportAttrs::VlanTunnel(val) = attr? {
8436 return Ok(val);
8437 }
8438 }
8439 Err(ErrorContext::new_missing(
8440 "LinkinfoBrportAttrs",
8441 "VlanTunnel",
8442 self.orig_loc,
8443 self.buf.as_ptr() as usize,
8444 ))
8445 }
8446 pub fn get_bcast_flood(&self) -> Result<(), ErrorContext> {
8447 let mut iter = self.clone();
8448 iter.pos = 0;
8449 for attr in iter {
8450 if let LinkinfoBrportAttrs::BcastFlood(val) = attr? {
8451 return Ok(val);
8452 }
8453 }
8454 Err(ErrorContext::new_missing(
8455 "LinkinfoBrportAttrs",
8456 "BcastFlood",
8457 self.orig_loc,
8458 self.buf.as_ptr() as usize,
8459 ))
8460 }
8461 pub fn get_group_fwd_mask(&self) -> Result<u16, ErrorContext> {
8462 let mut iter = self.clone();
8463 iter.pos = 0;
8464 for attr in iter {
8465 if let LinkinfoBrportAttrs::GroupFwdMask(val) = attr? {
8466 return Ok(val);
8467 }
8468 }
8469 Err(ErrorContext::new_missing(
8470 "LinkinfoBrportAttrs",
8471 "GroupFwdMask",
8472 self.orig_loc,
8473 self.buf.as_ptr() as usize,
8474 ))
8475 }
8476 pub fn get_neigh_suppress(&self) -> Result<(), ErrorContext> {
8477 let mut iter = self.clone();
8478 iter.pos = 0;
8479 for attr in iter {
8480 if let LinkinfoBrportAttrs::NeighSuppress(val) = attr? {
8481 return Ok(val);
8482 }
8483 }
8484 Err(ErrorContext::new_missing(
8485 "LinkinfoBrportAttrs",
8486 "NeighSuppress",
8487 self.orig_loc,
8488 self.buf.as_ptr() as usize,
8489 ))
8490 }
8491 pub fn get_isolated(&self) -> Result<(), ErrorContext> {
8492 let mut iter = self.clone();
8493 iter.pos = 0;
8494 for attr in iter {
8495 if let LinkinfoBrportAttrs::Isolated(val) = attr? {
8496 return Ok(val);
8497 }
8498 }
8499 Err(ErrorContext::new_missing(
8500 "LinkinfoBrportAttrs",
8501 "Isolated",
8502 self.orig_loc,
8503 self.buf.as_ptr() as usize,
8504 ))
8505 }
8506 pub fn get_backup_port(&self) -> Result<u32, ErrorContext> {
8507 let mut iter = self.clone();
8508 iter.pos = 0;
8509 for attr in iter {
8510 if let LinkinfoBrportAttrs::BackupPort(val) = attr? {
8511 return Ok(val);
8512 }
8513 }
8514 Err(ErrorContext::new_missing(
8515 "LinkinfoBrportAttrs",
8516 "BackupPort",
8517 self.orig_loc,
8518 self.buf.as_ptr() as usize,
8519 ))
8520 }
8521 pub fn get_mrp_ring_open(&self) -> Result<(), ErrorContext> {
8522 let mut iter = self.clone();
8523 iter.pos = 0;
8524 for attr in iter {
8525 if let LinkinfoBrportAttrs::MrpRingOpen(val) = attr? {
8526 return Ok(val);
8527 }
8528 }
8529 Err(ErrorContext::new_missing(
8530 "LinkinfoBrportAttrs",
8531 "MrpRingOpen",
8532 self.orig_loc,
8533 self.buf.as_ptr() as usize,
8534 ))
8535 }
8536 pub fn get_mrp_in_open(&self) -> Result<(), ErrorContext> {
8537 let mut iter = self.clone();
8538 iter.pos = 0;
8539 for attr in iter {
8540 if let LinkinfoBrportAttrs::MrpInOpen(val) = attr? {
8541 return Ok(val);
8542 }
8543 }
8544 Err(ErrorContext::new_missing(
8545 "LinkinfoBrportAttrs",
8546 "MrpInOpen",
8547 self.orig_loc,
8548 self.buf.as_ptr() as usize,
8549 ))
8550 }
8551 pub fn get_mcast_eht_hosts_limit(&self) -> Result<u32, ErrorContext> {
8552 let mut iter = self.clone();
8553 iter.pos = 0;
8554 for attr in iter {
8555 if let LinkinfoBrportAttrs::McastEhtHostsLimit(val) = attr? {
8556 return Ok(val);
8557 }
8558 }
8559 Err(ErrorContext::new_missing(
8560 "LinkinfoBrportAttrs",
8561 "McastEhtHostsLimit",
8562 self.orig_loc,
8563 self.buf.as_ptr() as usize,
8564 ))
8565 }
8566 pub fn get_mcast_eht_hosts_cnt(&self) -> Result<u32, ErrorContext> {
8567 let mut iter = self.clone();
8568 iter.pos = 0;
8569 for attr in iter {
8570 if let LinkinfoBrportAttrs::McastEhtHostsCnt(val) = attr? {
8571 return Ok(val);
8572 }
8573 }
8574 Err(ErrorContext::new_missing(
8575 "LinkinfoBrportAttrs",
8576 "McastEhtHostsCnt",
8577 self.orig_loc,
8578 self.buf.as_ptr() as usize,
8579 ))
8580 }
8581 pub fn get_locked(&self) -> Result<(), ErrorContext> {
8582 let mut iter = self.clone();
8583 iter.pos = 0;
8584 for attr in iter {
8585 if let LinkinfoBrportAttrs::Locked(val) = attr? {
8586 return Ok(val);
8587 }
8588 }
8589 Err(ErrorContext::new_missing(
8590 "LinkinfoBrportAttrs",
8591 "Locked",
8592 self.orig_loc,
8593 self.buf.as_ptr() as usize,
8594 ))
8595 }
8596 pub fn get_mab(&self) -> Result<(), ErrorContext> {
8597 let mut iter = self.clone();
8598 iter.pos = 0;
8599 for attr in iter {
8600 if let LinkinfoBrportAttrs::Mab(val) = attr? {
8601 return Ok(val);
8602 }
8603 }
8604 Err(ErrorContext::new_missing(
8605 "LinkinfoBrportAttrs",
8606 "Mab",
8607 self.orig_loc,
8608 self.buf.as_ptr() as usize,
8609 ))
8610 }
8611 pub fn get_mcast_n_groups(&self) -> Result<u32, ErrorContext> {
8612 let mut iter = self.clone();
8613 iter.pos = 0;
8614 for attr in iter {
8615 if let LinkinfoBrportAttrs::McastNGroups(val) = attr? {
8616 return Ok(val);
8617 }
8618 }
8619 Err(ErrorContext::new_missing(
8620 "LinkinfoBrportAttrs",
8621 "McastNGroups",
8622 self.orig_loc,
8623 self.buf.as_ptr() as usize,
8624 ))
8625 }
8626 pub fn get_mcast_max_groups(&self) -> Result<u32, ErrorContext> {
8627 let mut iter = self.clone();
8628 iter.pos = 0;
8629 for attr in iter {
8630 if let LinkinfoBrportAttrs::McastMaxGroups(val) = attr? {
8631 return Ok(val);
8632 }
8633 }
8634 Err(ErrorContext::new_missing(
8635 "LinkinfoBrportAttrs",
8636 "McastMaxGroups",
8637 self.orig_loc,
8638 self.buf.as_ptr() as usize,
8639 ))
8640 }
8641 pub fn get_neigh_vlan_suppress(&self) -> Result<(), ErrorContext> {
8642 let mut iter = self.clone();
8643 iter.pos = 0;
8644 for attr in iter {
8645 if let LinkinfoBrportAttrs::NeighVlanSuppress(val) = attr? {
8646 return Ok(val);
8647 }
8648 }
8649 Err(ErrorContext::new_missing(
8650 "LinkinfoBrportAttrs",
8651 "NeighVlanSuppress",
8652 self.orig_loc,
8653 self.buf.as_ptr() as usize,
8654 ))
8655 }
8656 pub fn get_backup_nhid(&self) -> Result<u32, ErrorContext> {
8657 let mut iter = self.clone();
8658 iter.pos = 0;
8659 for attr in iter {
8660 if let LinkinfoBrportAttrs::BackupNhid(val) = attr? {
8661 return Ok(val);
8662 }
8663 }
8664 Err(ErrorContext::new_missing(
8665 "LinkinfoBrportAttrs",
8666 "BackupNhid",
8667 self.orig_loc,
8668 self.buf.as_ptr() as usize,
8669 ))
8670 }
8671}
8672impl LinkinfoBrportAttrs<'_> {
8673 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoBrportAttrs<'a> {
8674 IterableLinkinfoBrportAttrs::with_loc(buf, buf.as_ptr() as usize)
8675 }
8676 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8677 let res = match r#type {
8678 1u16 => "State",
8679 2u16 => "Priority",
8680 3u16 => "Cost",
8681 4u16 => "Mode",
8682 5u16 => "Guard",
8683 6u16 => "Protect",
8684 7u16 => "FastLeave",
8685 8u16 => "Learning",
8686 9u16 => "UnicastFlood",
8687 10u16 => "Proxyarp",
8688 11u16 => "LearningSync",
8689 12u16 => "ProxyarpWifi",
8690 13u16 => "RootId",
8691 14u16 => "BridgeId",
8692 15u16 => "DesignatedPort",
8693 16u16 => "DesignatedCost",
8694 17u16 => "Id",
8695 18u16 => "No",
8696 19u16 => "TopologyChangeAck",
8697 20u16 => "ConfigPending",
8698 21u16 => "MessageAgeTimer",
8699 22u16 => "ForwardDelayTimer",
8700 23u16 => "HoldTimer",
8701 24u16 => "Flush",
8702 25u16 => "MulticastRouter",
8703 26u16 => "Pad",
8704 27u16 => "McastFlood",
8705 28u16 => "McastToUcast",
8706 29u16 => "VlanTunnel",
8707 30u16 => "BcastFlood",
8708 31u16 => "GroupFwdMask",
8709 32u16 => "NeighSuppress",
8710 33u16 => "Isolated",
8711 34u16 => "BackupPort",
8712 35u16 => "MrpRingOpen",
8713 36u16 => "MrpInOpen",
8714 37u16 => "McastEhtHostsLimit",
8715 38u16 => "McastEhtHostsCnt",
8716 39u16 => "Locked",
8717 40u16 => "Mab",
8718 41u16 => "McastNGroups",
8719 42u16 => "McastMaxGroups",
8720 43u16 => "NeighVlanSuppress",
8721 44u16 => "BackupNhid",
8722 _ => return None,
8723 };
8724 Some(res)
8725 }
8726}
8727#[derive(Clone, Copy, Default)]
8728pub struct IterableLinkinfoBrportAttrs<'a> {
8729 buf: &'a [u8],
8730 pos: usize,
8731 orig_loc: usize,
8732}
8733impl<'a> IterableLinkinfoBrportAttrs<'a> {
8734 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
8735 Self {
8736 buf,
8737 pos: 0,
8738 orig_loc,
8739 }
8740 }
8741 pub fn get_buf(&self) -> &'a [u8] {
8742 self.buf
8743 }
8744}
8745impl<'a> Iterator for IterableLinkinfoBrportAttrs<'a> {
8746 type Item = Result<LinkinfoBrportAttrs<'a>, ErrorContext>;
8747 fn next(&mut self) -> Option<Self::Item> {
8748 if self.buf.len() == self.pos {
8749 return None;
8750 }
8751 let pos = self.pos;
8752 let mut r#type = None;
8753 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
8754 r#type = Some(header.r#type);
8755 let res = match header.r#type {
8756 1u16 => LinkinfoBrportAttrs::State({
8757 let res = parse_u8(next);
8758 let Some(val) = res else { break };
8759 val
8760 }),
8761 2u16 => LinkinfoBrportAttrs::Priority({
8762 let res = parse_u16(next);
8763 let Some(val) = res else { break };
8764 val
8765 }),
8766 3u16 => LinkinfoBrportAttrs::Cost({
8767 let res = parse_u32(next);
8768 let Some(val) = res else { break };
8769 val
8770 }),
8771 4u16 => LinkinfoBrportAttrs::Mode(()),
8772 5u16 => LinkinfoBrportAttrs::Guard(()),
8773 6u16 => LinkinfoBrportAttrs::Protect(()),
8774 7u16 => LinkinfoBrportAttrs::FastLeave(()),
8775 8u16 => LinkinfoBrportAttrs::Learning(()),
8776 9u16 => LinkinfoBrportAttrs::UnicastFlood(()),
8777 10u16 => LinkinfoBrportAttrs::Proxyarp(()),
8778 11u16 => LinkinfoBrportAttrs::LearningSync(()),
8779 12u16 => LinkinfoBrportAttrs::ProxyarpWifi(()),
8780 13u16 => LinkinfoBrportAttrs::RootId({
8781 let res = PushIflaBridgeId::new_from_slice(next);
8782 let Some(val) = res else { break };
8783 val
8784 }),
8785 14u16 => LinkinfoBrportAttrs::BridgeId({
8786 let res = PushIflaBridgeId::new_from_slice(next);
8787 let Some(val) = res else { break };
8788 val
8789 }),
8790 15u16 => LinkinfoBrportAttrs::DesignatedPort({
8791 let res = parse_u16(next);
8792 let Some(val) = res else { break };
8793 val
8794 }),
8795 16u16 => LinkinfoBrportAttrs::DesignatedCost({
8796 let res = parse_u16(next);
8797 let Some(val) = res else { break };
8798 val
8799 }),
8800 17u16 => LinkinfoBrportAttrs::Id({
8801 let res = parse_u16(next);
8802 let Some(val) = res else { break };
8803 val
8804 }),
8805 18u16 => LinkinfoBrportAttrs::No({
8806 let res = parse_u16(next);
8807 let Some(val) = res else { break };
8808 val
8809 }),
8810 19u16 => LinkinfoBrportAttrs::TopologyChangeAck({
8811 let res = parse_u8(next);
8812 let Some(val) = res else { break };
8813 val
8814 }),
8815 20u16 => LinkinfoBrportAttrs::ConfigPending({
8816 let res = parse_u8(next);
8817 let Some(val) = res else { break };
8818 val
8819 }),
8820 21u16 => LinkinfoBrportAttrs::MessageAgeTimer({
8821 let res = parse_u64(next);
8822 let Some(val) = res else { break };
8823 val
8824 }),
8825 22u16 => LinkinfoBrportAttrs::ForwardDelayTimer({
8826 let res = parse_u64(next);
8827 let Some(val) = res else { break };
8828 val
8829 }),
8830 23u16 => LinkinfoBrportAttrs::HoldTimer({
8831 let res = parse_u64(next);
8832 let Some(val) = res else { break };
8833 val
8834 }),
8835 24u16 => LinkinfoBrportAttrs::Flush(()),
8836 25u16 => LinkinfoBrportAttrs::MulticastRouter({
8837 let res = parse_u8(next);
8838 let Some(val) = res else { break };
8839 val
8840 }),
8841 26u16 => LinkinfoBrportAttrs::Pad({
8842 let res = Some(next);
8843 let Some(val) = res else { break };
8844 val
8845 }),
8846 27u16 => LinkinfoBrportAttrs::McastFlood(()),
8847 28u16 => LinkinfoBrportAttrs::McastToUcast(()),
8848 29u16 => LinkinfoBrportAttrs::VlanTunnel(()),
8849 30u16 => LinkinfoBrportAttrs::BcastFlood(()),
8850 31u16 => LinkinfoBrportAttrs::GroupFwdMask({
8851 let res = parse_u16(next);
8852 let Some(val) = res else { break };
8853 val
8854 }),
8855 32u16 => LinkinfoBrportAttrs::NeighSuppress(()),
8856 33u16 => LinkinfoBrportAttrs::Isolated(()),
8857 34u16 => LinkinfoBrportAttrs::BackupPort({
8858 let res = parse_u32(next);
8859 let Some(val) = res else { break };
8860 val
8861 }),
8862 35u16 => LinkinfoBrportAttrs::MrpRingOpen(()),
8863 36u16 => LinkinfoBrportAttrs::MrpInOpen(()),
8864 37u16 => LinkinfoBrportAttrs::McastEhtHostsLimit({
8865 let res = parse_u32(next);
8866 let Some(val) = res else { break };
8867 val
8868 }),
8869 38u16 => LinkinfoBrportAttrs::McastEhtHostsCnt({
8870 let res = parse_u32(next);
8871 let Some(val) = res else { break };
8872 val
8873 }),
8874 39u16 => LinkinfoBrportAttrs::Locked(()),
8875 40u16 => LinkinfoBrportAttrs::Mab(()),
8876 41u16 => LinkinfoBrportAttrs::McastNGroups({
8877 let res = parse_u32(next);
8878 let Some(val) = res else { break };
8879 val
8880 }),
8881 42u16 => LinkinfoBrportAttrs::McastMaxGroups({
8882 let res = parse_u32(next);
8883 let Some(val) = res else { break };
8884 val
8885 }),
8886 43u16 => LinkinfoBrportAttrs::NeighVlanSuppress(()),
8887 44u16 => LinkinfoBrportAttrs::BackupNhid({
8888 let res = parse_u32(next);
8889 let Some(val) = res else { break };
8890 val
8891 }),
8892 n => {
8893 if cfg!(any(test, feature = "deny-unknown-attrs")) {
8894 break;
8895 } else {
8896 continue;
8897 }
8898 }
8899 };
8900 return Some(Ok(res));
8901 }
8902 Some(Err(ErrorContext::new(
8903 "LinkinfoBrportAttrs",
8904 r#type.and_then(|t| LinkinfoBrportAttrs::attr_from_type(t)),
8905 self.orig_loc,
8906 self.buf.as_ptr().wrapping_add(pos) as usize,
8907 )))
8908 }
8909}
8910impl<'a> std::fmt::Debug for IterableLinkinfoBrportAttrs<'_> {
8911 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8912 let mut fmt = f.debug_struct("LinkinfoBrportAttrs");
8913 for attr in self.clone() {
8914 let attr = match attr {
8915 Ok(a) => a,
8916 Err(err) => {
8917 fmt.finish()?;
8918 f.write_str("Err(")?;
8919 err.fmt(f)?;
8920 return f.write_str(")");
8921 }
8922 };
8923 match attr {
8924 LinkinfoBrportAttrs::State(val) => fmt.field("State", &val),
8925 LinkinfoBrportAttrs::Priority(val) => fmt.field("Priority", &val),
8926 LinkinfoBrportAttrs::Cost(val) => fmt.field("Cost", &val),
8927 LinkinfoBrportAttrs::Mode(val) => fmt.field("Mode", &val),
8928 LinkinfoBrportAttrs::Guard(val) => fmt.field("Guard", &val),
8929 LinkinfoBrportAttrs::Protect(val) => fmt.field("Protect", &val),
8930 LinkinfoBrportAttrs::FastLeave(val) => fmt.field("FastLeave", &val),
8931 LinkinfoBrportAttrs::Learning(val) => fmt.field("Learning", &val),
8932 LinkinfoBrportAttrs::UnicastFlood(val) => fmt.field("UnicastFlood", &val),
8933 LinkinfoBrportAttrs::Proxyarp(val) => fmt.field("Proxyarp", &val),
8934 LinkinfoBrportAttrs::LearningSync(val) => fmt.field("LearningSync", &val),
8935 LinkinfoBrportAttrs::ProxyarpWifi(val) => fmt.field("ProxyarpWifi", &val),
8936 LinkinfoBrportAttrs::RootId(val) => fmt.field("RootId", &val),
8937 LinkinfoBrportAttrs::BridgeId(val) => fmt.field("BridgeId", &val),
8938 LinkinfoBrportAttrs::DesignatedPort(val) => fmt.field("DesignatedPort", &val),
8939 LinkinfoBrportAttrs::DesignatedCost(val) => fmt.field("DesignatedCost", &val),
8940 LinkinfoBrportAttrs::Id(val) => fmt.field("Id", &val),
8941 LinkinfoBrportAttrs::No(val) => fmt.field("No", &val),
8942 LinkinfoBrportAttrs::TopologyChangeAck(val) => fmt.field("TopologyChangeAck", &val),
8943 LinkinfoBrportAttrs::ConfigPending(val) => fmt.field("ConfigPending", &val),
8944 LinkinfoBrportAttrs::MessageAgeTimer(val) => fmt.field("MessageAgeTimer", &val),
8945 LinkinfoBrportAttrs::ForwardDelayTimer(val) => fmt.field("ForwardDelayTimer", &val),
8946 LinkinfoBrportAttrs::HoldTimer(val) => fmt.field("HoldTimer", &val),
8947 LinkinfoBrportAttrs::Flush(val) => fmt.field("Flush", &val),
8948 LinkinfoBrportAttrs::MulticastRouter(val) => fmt.field("MulticastRouter", &val),
8949 LinkinfoBrportAttrs::Pad(val) => fmt.field("Pad", &val),
8950 LinkinfoBrportAttrs::McastFlood(val) => fmt.field("McastFlood", &val),
8951 LinkinfoBrportAttrs::McastToUcast(val) => fmt.field("McastToUcast", &val),
8952 LinkinfoBrportAttrs::VlanTunnel(val) => fmt.field("VlanTunnel", &val),
8953 LinkinfoBrportAttrs::BcastFlood(val) => fmt.field("BcastFlood", &val),
8954 LinkinfoBrportAttrs::GroupFwdMask(val) => fmt.field("GroupFwdMask", &val),
8955 LinkinfoBrportAttrs::NeighSuppress(val) => fmt.field("NeighSuppress", &val),
8956 LinkinfoBrportAttrs::Isolated(val) => fmt.field("Isolated", &val),
8957 LinkinfoBrportAttrs::BackupPort(val) => fmt.field("BackupPort", &val),
8958 LinkinfoBrportAttrs::MrpRingOpen(val) => fmt.field("MrpRingOpen", &val),
8959 LinkinfoBrportAttrs::MrpInOpen(val) => fmt.field("MrpInOpen", &val),
8960 LinkinfoBrportAttrs::McastEhtHostsLimit(val) => {
8961 fmt.field("McastEhtHostsLimit", &val)
8962 }
8963 LinkinfoBrportAttrs::McastEhtHostsCnt(val) => fmt.field("McastEhtHostsCnt", &val),
8964 LinkinfoBrportAttrs::Locked(val) => fmt.field("Locked", &val),
8965 LinkinfoBrportAttrs::Mab(val) => fmt.field("Mab", &val),
8966 LinkinfoBrportAttrs::McastNGroups(val) => fmt.field("McastNGroups", &val),
8967 LinkinfoBrportAttrs::McastMaxGroups(val) => fmt.field("McastMaxGroups", &val),
8968 LinkinfoBrportAttrs::NeighVlanSuppress(val) => fmt.field("NeighVlanSuppress", &val),
8969 LinkinfoBrportAttrs::BackupNhid(val) => fmt.field("BackupNhid", &val),
8970 };
8971 }
8972 fmt.finish()
8973 }
8974}
8975impl IterableLinkinfoBrportAttrs<'_> {
8976 pub fn lookup_attr(
8977 &self,
8978 offset: usize,
8979 missing_type: Option<u16>,
8980 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
8981 let mut stack = Vec::new();
8982 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
8983 if cur == offset {
8984 stack.push(("LinkinfoBrportAttrs", offset));
8985 return (
8986 stack,
8987 missing_type.and_then(|t| LinkinfoBrportAttrs::attr_from_type(t)),
8988 );
8989 }
8990 if cur > offset || cur + self.buf.len() < offset {
8991 return (stack, None);
8992 }
8993 let mut attrs = self.clone();
8994 let mut last_off = cur + attrs.pos;
8995 while let Some(attr) = attrs.next() {
8996 let Ok(attr) = attr else { break };
8997 match attr {
8998 LinkinfoBrportAttrs::State(val) => {
8999 if last_off == offset {
9000 stack.push(("State", last_off));
9001 break;
9002 }
9003 }
9004 LinkinfoBrportAttrs::Priority(val) => {
9005 if last_off == offset {
9006 stack.push(("Priority", last_off));
9007 break;
9008 }
9009 }
9010 LinkinfoBrportAttrs::Cost(val) => {
9011 if last_off == offset {
9012 stack.push(("Cost", last_off));
9013 break;
9014 }
9015 }
9016 LinkinfoBrportAttrs::Mode(val) => {
9017 if last_off == offset {
9018 stack.push(("Mode", last_off));
9019 break;
9020 }
9021 }
9022 LinkinfoBrportAttrs::Guard(val) => {
9023 if last_off == offset {
9024 stack.push(("Guard", last_off));
9025 break;
9026 }
9027 }
9028 LinkinfoBrportAttrs::Protect(val) => {
9029 if last_off == offset {
9030 stack.push(("Protect", last_off));
9031 break;
9032 }
9033 }
9034 LinkinfoBrportAttrs::FastLeave(val) => {
9035 if last_off == offset {
9036 stack.push(("FastLeave", last_off));
9037 break;
9038 }
9039 }
9040 LinkinfoBrportAttrs::Learning(val) => {
9041 if last_off == offset {
9042 stack.push(("Learning", last_off));
9043 break;
9044 }
9045 }
9046 LinkinfoBrportAttrs::UnicastFlood(val) => {
9047 if last_off == offset {
9048 stack.push(("UnicastFlood", last_off));
9049 break;
9050 }
9051 }
9052 LinkinfoBrportAttrs::Proxyarp(val) => {
9053 if last_off == offset {
9054 stack.push(("Proxyarp", last_off));
9055 break;
9056 }
9057 }
9058 LinkinfoBrportAttrs::LearningSync(val) => {
9059 if last_off == offset {
9060 stack.push(("LearningSync", last_off));
9061 break;
9062 }
9063 }
9064 LinkinfoBrportAttrs::ProxyarpWifi(val) => {
9065 if last_off == offset {
9066 stack.push(("ProxyarpWifi", last_off));
9067 break;
9068 }
9069 }
9070 LinkinfoBrportAttrs::RootId(val) => {
9071 if last_off == offset {
9072 stack.push(("RootId", last_off));
9073 break;
9074 }
9075 }
9076 LinkinfoBrportAttrs::BridgeId(val) => {
9077 if last_off == offset {
9078 stack.push(("BridgeId", last_off));
9079 break;
9080 }
9081 }
9082 LinkinfoBrportAttrs::DesignatedPort(val) => {
9083 if last_off == offset {
9084 stack.push(("DesignatedPort", last_off));
9085 break;
9086 }
9087 }
9088 LinkinfoBrportAttrs::DesignatedCost(val) => {
9089 if last_off == offset {
9090 stack.push(("DesignatedCost", last_off));
9091 break;
9092 }
9093 }
9094 LinkinfoBrportAttrs::Id(val) => {
9095 if last_off == offset {
9096 stack.push(("Id", last_off));
9097 break;
9098 }
9099 }
9100 LinkinfoBrportAttrs::No(val) => {
9101 if last_off == offset {
9102 stack.push(("No", last_off));
9103 break;
9104 }
9105 }
9106 LinkinfoBrportAttrs::TopologyChangeAck(val) => {
9107 if last_off == offset {
9108 stack.push(("TopologyChangeAck", last_off));
9109 break;
9110 }
9111 }
9112 LinkinfoBrportAttrs::ConfigPending(val) => {
9113 if last_off == offset {
9114 stack.push(("ConfigPending", last_off));
9115 break;
9116 }
9117 }
9118 LinkinfoBrportAttrs::MessageAgeTimer(val) => {
9119 if last_off == offset {
9120 stack.push(("MessageAgeTimer", last_off));
9121 break;
9122 }
9123 }
9124 LinkinfoBrportAttrs::ForwardDelayTimer(val) => {
9125 if last_off == offset {
9126 stack.push(("ForwardDelayTimer", last_off));
9127 break;
9128 }
9129 }
9130 LinkinfoBrportAttrs::HoldTimer(val) => {
9131 if last_off == offset {
9132 stack.push(("HoldTimer", last_off));
9133 break;
9134 }
9135 }
9136 LinkinfoBrportAttrs::Flush(val) => {
9137 if last_off == offset {
9138 stack.push(("Flush", last_off));
9139 break;
9140 }
9141 }
9142 LinkinfoBrportAttrs::MulticastRouter(val) => {
9143 if last_off == offset {
9144 stack.push(("MulticastRouter", last_off));
9145 break;
9146 }
9147 }
9148 LinkinfoBrportAttrs::Pad(val) => {
9149 if last_off == offset {
9150 stack.push(("Pad", last_off));
9151 break;
9152 }
9153 }
9154 LinkinfoBrportAttrs::McastFlood(val) => {
9155 if last_off == offset {
9156 stack.push(("McastFlood", last_off));
9157 break;
9158 }
9159 }
9160 LinkinfoBrportAttrs::McastToUcast(val) => {
9161 if last_off == offset {
9162 stack.push(("McastToUcast", last_off));
9163 break;
9164 }
9165 }
9166 LinkinfoBrportAttrs::VlanTunnel(val) => {
9167 if last_off == offset {
9168 stack.push(("VlanTunnel", last_off));
9169 break;
9170 }
9171 }
9172 LinkinfoBrportAttrs::BcastFlood(val) => {
9173 if last_off == offset {
9174 stack.push(("BcastFlood", last_off));
9175 break;
9176 }
9177 }
9178 LinkinfoBrportAttrs::GroupFwdMask(val) => {
9179 if last_off == offset {
9180 stack.push(("GroupFwdMask", last_off));
9181 break;
9182 }
9183 }
9184 LinkinfoBrportAttrs::NeighSuppress(val) => {
9185 if last_off == offset {
9186 stack.push(("NeighSuppress", last_off));
9187 break;
9188 }
9189 }
9190 LinkinfoBrportAttrs::Isolated(val) => {
9191 if last_off == offset {
9192 stack.push(("Isolated", last_off));
9193 break;
9194 }
9195 }
9196 LinkinfoBrportAttrs::BackupPort(val) => {
9197 if last_off == offset {
9198 stack.push(("BackupPort", last_off));
9199 break;
9200 }
9201 }
9202 LinkinfoBrportAttrs::MrpRingOpen(val) => {
9203 if last_off == offset {
9204 stack.push(("MrpRingOpen", last_off));
9205 break;
9206 }
9207 }
9208 LinkinfoBrportAttrs::MrpInOpen(val) => {
9209 if last_off == offset {
9210 stack.push(("MrpInOpen", last_off));
9211 break;
9212 }
9213 }
9214 LinkinfoBrportAttrs::McastEhtHostsLimit(val) => {
9215 if last_off == offset {
9216 stack.push(("McastEhtHostsLimit", last_off));
9217 break;
9218 }
9219 }
9220 LinkinfoBrportAttrs::McastEhtHostsCnt(val) => {
9221 if last_off == offset {
9222 stack.push(("McastEhtHostsCnt", last_off));
9223 break;
9224 }
9225 }
9226 LinkinfoBrportAttrs::Locked(val) => {
9227 if last_off == offset {
9228 stack.push(("Locked", last_off));
9229 break;
9230 }
9231 }
9232 LinkinfoBrportAttrs::Mab(val) => {
9233 if last_off == offset {
9234 stack.push(("Mab", last_off));
9235 break;
9236 }
9237 }
9238 LinkinfoBrportAttrs::McastNGroups(val) => {
9239 if last_off == offset {
9240 stack.push(("McastNGroups", last_off));
9241 break;
9242 }
9243 }
9244 LinkinfoBrportAttrs::McastMaxGroups(val) => {
9245 if last_off == offset {
9246 stack.push(("McastMaxGroups", last_off));
9247 break;
9248 }
9249 }
9250 LinkinfoBrportAttrs::NeighVlanSuppress(val) => {
9251 if last_off == offset {
9252 stack.push(("NeighVlanSuppress", last_off));
9253 break;
9254 }
9255 }
9256 LinkinfoBrportAttrs::BackupNhid(val) => {
9257 if last_off == offset {
9258 stack.push(("BackupNhid", last_off));
9259 break;
9260 }
9261 }
9262 _ => {}
9263 };
9264 last_off = cur + attrs.pos;
9265 }
9266 if !stack.is_empty() {
9267 stack.push(("LinkinfoBrportAttrs", cur));
9268 }
9269 (stack, None)
9270 }
9271}
9272#[derive(Clone)]
9273pub enum LinkinfoGreAttrs<'a> {
9274 Link(u32),
9275 Iflags(u16),
9276 Oflags(u16),
9277 Ikey(u32),
9278 Okey(u32),
9279 Local(&'a [u8]),
9280 Remote(&'a [u8]),
9281 Ttl(u8),
9282 Tos(u8),
9283 Pmtudisc(u8),
9284 EncapLimit(u8),
9285 Flowinfo(u32),
9286 Flags(u32),
9287 EncapType(u16),
9288 EncapFlags(u16),
9289 EncapSport(u16),
9290 EncapDport(u16),
9291 CollectMetadata(()),
9292 IgnoreDf(u8),
9293 Fwmark(u32),
9294 ErspanIndex(u32),
9295 ErspanVer(u8),
9296 ErspanDir(u8),
9297 ErspanHwid(u16),
9298}
9299impl<'a> IterableLinkinfoGreAttrs<'a> {
9300 pub fn get_link(&self) -> Result<u32, ErrorContext> {
9301 let mut iter = self.clone();
9302 iter.pos = 0;
9303 for attr in iter {
9304 if let LinkinfoGreAttrs::Link(val) = attr? {
9305 return Ok(val);
9306 }
9307 }
9308 Err(ErrorContext::new_missing(
9309 "LinkinfoGreAttrs",
9310 "Link",
9311 self.orig_loc,
9312 self.buf.as_ptr() as usize,
9313 ))
9314 }
9315 pub fn get_iflags(&self) -> Result<u16, ErrorContext> {
9316 let mut iter = self.clone();
9317 iter.pos = 0;
9318 for attr in iter {
9319 if let LinkinfoGreAttrs::Iflags(val) = attr? {
9320 return Ok(val);
9321 }
9322 }
9323 Err(ErrorContext::new_missing(
9324 "LinkinfoGreAttrs",
9325 "Iflags",
9326 self.orig_loc,
9327 self.buf.as_ptr() as usize,
9328 ))
9329 }
9330 pub fn get_oflags(&self) -> Result<u16, ErrorContext> {
9331 let mut iter = self.clone();
9332 iter.pos = 0;
9333 for attr in iter {
9334 if let LinkinfoGreAttrs::Oflags(val) = attr? {
9335 return Ok(val);
9336 }
9337 }
9338 Err(ErrorContext::new_missing(
9339 "LinkinfoGreAttrs",
9340 "Oflags",
9341 self.orig_loc,
9342 self.buf.as_ptr() as usize,
9343 ))
9344 }
9345 pub fn get_ikey(&self) -> Result<u32, ErrorContext> {
9346 let mut iter = self.clone();
9347 iter.pos = 0;
9348 for attr in iter {
9349 if let LinkinfoGreAttrs::Ikey(val) = attr? {
9350 return Ok(val);
9351 }
9352 }
9353 Err(ErrorContext::new_missing(
9354 "LinkinfoGreAttrs",
9355 "Ikey",
9356 self.orig_loc,
9357 self.buf.as_ptr() as usize,
9358 ))
9359 }
9360 pub fn get_okey(&self) -> Result<u32, ErrorContext> {
9361 let mut iter = self.clone();
9362 iter.pos = 0;
9363 for attr in iter {
9364 if let LinkinfoGreAttrs::Okey(val) = attr? {
9365 return Ok(val);
9366 }
9367 }
9368 Err(ErrorContext::new_missing(
9369 "LinkinfoGreAttrs",
9370 "Okey",
9371 self.orig_loc,
9372 self.buf.as_ptr() as usize,
9373 ))
9374 }
9375 pub fn get_local(&self) -> Result<&'a [u8], ErrorContext> {
9376 let mut iter = self.clone();
9377 iter.pos = 0;
9378 for attr in iter {
9379 if let LinkinfoGreAttrs::Local(val) = attr? {
9380 return Ok(val);
9381 }
9382 }
9383 Err(ErrorContext::new_missing(
9384 "LinkinfoGreAttrs",
9385 "Local",
9386 self.orig_loc,
9387 self.buf.as_ptr() as usize,
9388 ))
9389 }
9390 pub fn get_remote(&self) -> Result<&'a [u8], ErrorContext> {
9391 let mut iter = self.clone();
9392 iter.pos = 0;
9393 for attr in iter {
9394 if let LinkinfoGreAttrs::Remote(val) = attr? {
9395 return Ok(val);
9396 }
9397 }
9398 Err(ErrorContext::new_missing(
9399 "LinkinfoGreAttrs",
9400 "Remote",
9401 self.orig_loc,
9402 self.buf.as_ptr() as usize,
9403 ))
9404 }
9405 pub fn get_ttl(&self) -> Result<u8, ErrorContext> {
9406 let mut iter = self.clone();
9407 iter.pos = 0;
9408 for attr in iter {
9409 if let LinkinfoGreAttrs::Ttl(val) = attr? {
9410 return Ok(val);
9411 }
9412 }
9413 Err(ErrorContext::new_missing(
9414 "LinkinfoGreAttrs",
9415 "Ttl",
9416 self.orig_loc,
9417 self.buf.as_ptr() as usize,
9418 ))
9419 }
9420 pub fn get_tos(&self) -> Result<u8, ErrorContext> {
9421 let mut iter = self.clone();
9422 iter.pos = 0;
9423 for attr in iter {
9424 if let LinkinfoGreAttrs::Tos(val) = attr? {
9425 return Ok(val);
9426 }
9427 }
9428 Err(ErrorContext::new_missing(
9429 "LinkinfoGreAttrs",
9430 "Tos",
9431 self.orig_loc,
9432 self.buf.as_ptr() as usize,
9433 ))
9434 }
9435 pub fn get_pmtudisc(&self) -> Result<u8, ErrorContext> {
9436 let mut iter = self.clone();
9437 iter.pos = 0;
9438 for attr in iter {
9439 if let LinkinfoGreAttrs::Pmtudisc(val) = attr? {
9440 return Ok(val);
9441 }
9442 }
9443 Err(ErrorContext::new_missing(
9444 "LinkinfoGreAttrs",
9445 "Pmtudisc",
9446 self.orig_loc,
9447 self.buf.as_ptr() as usize,
9448 ))
9449 }
9450 pub fn get_encap_limit(&self) -> Result<u8, ErrorContext> {
9451 let mut iter = self.clone();
9452 iter.pos = 0;
9453 for attr in iter {
9454 if let LinkinfoGreAttrs::EncapLimit(val) = attr? {
9455 return Ok(val);
9456 }
9457 }
9458 Err(ErrorContext::new_missing(
9459 "LinkinfoGreAttrs",
9460 "EncapLimit",
9461 self.orig_loc,
9462 self.buf.as_ptr() as usize,
9463 ))
9464 }
9465 pub fn get_flowinfo(&self) -> Result<u32, ErrorContext> {
9466 let mut iter = self.clone();
9467 iter.pos = 0;
9468 for attr in iter {
9469 if let LinkinfoGreAttrs::Flowinfo(val) = attr? {
9470 return Ok(val);
9471 }
9472 }
9473 Err(ErrorContext::new_missing(
9474 "LinkinfoGreAttrs",
9475 "Flowinfo",
9476 self.orig_loc,
9477 self.buf.as_ptr() as usize,
9478 ))
9479 }
9480 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
9481 let mut iter = self.clone();
9482 iter.pos = 0;
9483 for attr in iter {
9484 if let LinkinfoGreAttrs::Flags(val) = attr? {
9485 return Ok(val);
9486 }
9487 }
9488 Err(ErrorContext::new_missing(
9489 "LinkinfoGreAttrs",
9490 "Flags",
9491 self.orig_loc,
9492 self.buf.as_ptr() as usize,
9493 ))
9494 }
9495 pub fn get_encap_type(&self) -> Result<u16, ErrorContext> {
9496 let mut iter = self.clone();
9497 iter.pos = 0;
9498 for attr in iter {
9499 if let LinkinfoGreAttrs::EncapType(val) = attr? {
9500 return Ok(val);
9501 }
9502 }
9503 Err(ErrorContext::new_missing(
9504 "LinkinfoGreAttrs",
9505 "EncapType",
9506 self.orig_loc,
9507 self.buf.as_ptr() as usize,
9508 ))
9509 }
9510 pub fn get_encap_flags(&self) -> Result<u16, ErrorContext> {
9511 let mut iter = self.clone();
9512 iter.pos = 0;
9513 for attr in iter {
9514 if let LinkinfoGreAttrs::EncapFlags(val) = attr? {
9515 return Ok(val);
9516 }
9517 }
9518 Err(ErrorContext::new_missing(
9519 "LinkinfoGreAttrs",
9520 "EncapFlags",
9521 self.orig_loc,
9522 self.buf.as_ptr() as usize,
9523 ))
9524 }
9525 pub fn get_encap_sport(&self) -> Result<u16, ErrorContext> {
9526 let mut iter = self.clone();
9527 iter.pos = 0;
9528 for attr in iter {
9529 if let LinkinfoGreAttrs::EncapSport(val) = attr? {
9530 return Ok(val);
9531 }
9532 }
9533 Err(ErrorContext::new_missing(
9534 "LinkinfoGreAttrs",
9535 "EncapSport",
9536 self.orig_loc,
9537 self.buf.as_ptr() as usize,
9538 ))
9539 }
9540 pub fn get_encap_dport(&self) -> Result<u16, ErrorContext> {
9541 let mut iter = self.clone();
9542 iter.pos = 0;
9543 for attr in iter {
9544 if let LinkinfoGreAttrs::EncapDport(val) = attr? {
9545 return Ok(val);
9546 }
9547 }
9548 Err(ErrorContext::new_missing(
9549 "LinkinfoGreAttrs",
9550 "EncapDport",
9551 self.orig_loc,
9552 self.buf.as_ptr() as usize,
9553 ))
9554 }
9555 pub fn get_collect_metadata(&self) -> Result<(), ErrorContext> {
9556 let mut iter = self.clone();
9557 iter.pos = 0;
9558 for attr in iter {
9559 if let LinkinfoGreAttrs::CollectMetadata(val) = attr? {
9560 return Ok(val);
9561 }
9562 }
9563 Err(ErrorContext::new_missing(
9564 "LinkinfoGreAttrs",
9565 "CollectMetadata",
9566 self.orig_loc,
9567 self.buf.as_ptr() as usize,
9568 ))
9569 }
9570 pub fn get_ignore_df(&self) -> Result<u8, ErrorContext> {
9571 let mut iter = self.clone();
9572 iter.pos = 0;
9573 for attr in iter {
9574 if let LinkinfoGreAttrs::IgnoreDf(val) = attr? {
9575 return Ok(val);
9576 }
9577 }
9578 Err(ErrorContext::new_missing(
9579 "LinkinfoGreAttrs",
9580 "IgnoreDf",
9581 self.orig_loc,
9582 self.buf.as_ptr() as usize,
9583 ))
9584 }
9585 pub fn get_fwmark(&self) -> Result<u32, ErrorContext> {
9586 let mut iter = self.clone();
9587 iter.pos = 0;
9588 for attr in iter {
9589 if let LinkinfoGreAttrs::Fwmark(val) = attr? {
9590 return Ok(val);
9591 }
9592 }
9593 Err(ErrorContext::new_missing(
9594 "LinkinfoGreAttrs",
9595 "Fwmark",
9596 self.orig_loc,
9597 self.buf.as_ptr() as usize,
9598 ))
9599 }
9600 pub fn get_erspan_index(&self) -> Result<u32, ErrorContext> {
9601 let mut iter = self.clone();
9602 iter.pos = 0;
9603 for attr in iter {
9604 if let LinkinfoGreAttrs::ErspanIndex(val) = attr? {
9605 return Ok(val);
9606 }
9607 }
9608 Err(ErrorContext::new_missing(
9609 "LinkinfoGreAttrs",
9610 "ErspanIndex",
9611 self.orig_loc,
9612 self.buf.as_ptr() as usize,
9613 ))
9614 }
9615 pub fn get_erspan_ver(&self) -> Result<u8, ErrorContext> {
9616 let mut iter = self.clone();
9617 iter.pos = 0;
9618 for attr in iter {
9619 if let LinkinfoGreAttrs::ErspanVer(val) = attr? {
9620 return Ok(val);
9621 }
9622 }
9623 Err(ErrorContext::new_missing(
9624 "LinkinfoGreAttrs",
9625 "ErspanVer",
9626 self.orig_loc,
9627 self.buf.as_ptr() as usize,
9628 ))
9629 }
9630 pub fn get_erspan_dir(&self) -> Result<u8, ErrorContext> {
9631 let mut iter = self.clone();
9632 iter.pos = 0;
9633 for attr in iter {
9634 if let LinkinfoGreAttrs::ErspanDir(val) = attr? {
9635 return Ok(val);
9636 }
9637 }
9638 Err(ErrorContext::new_missing(
9639 "LinkinfoGreAttrs",
9640 "ErspanDir",
9641 self.orig_loc,
9642 self.buf.as_ptr() as usize,
9643 ))
9644 }
9645 pub fn get_erspan_hwid(&self) -> Result<u16, ErrorContext> {
9646 let mut iter = self.clone();
9647 iter.pos = 0;
9648 for attr in iter {
9649 if let LinkinfoGreAttrs::ErspanHwid(val) = attr? {
9650 return Ok(val);
9651 }
9652 }
9653 Err(ErrorContext::new_missing(
9654 "LinkinfoGreAttrs",
9655 "ErspanHwid",
9656 self.orig_loc,
9657 self.buf.as_ptr() as usize,
9658 ))
9659 }
9660}
9661impl LinkinfoGreAttrs<'_> {
9662 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoGreAttrs<'a> {
9663 IterableLinkinfoGreAttrs::with_loc(buf, buf.as_ptr() as usize)
9664 }
9665 fn attr_from_type(r#type: u16) -> Option<&'static str> {
9666 let res = match r#type {
9667 1u16 => "Link",
9668 2u16 => "Iflags",
9669 3u16 => "Oflags",
9670 4u16 => "Ikey",
9671 5u16 => "Okey",
9672 6u16 => "Local",
9673 7u16 => "Remote",
9674 8u16 => "Ttl",
9675 9u16 => "Tos",
9676 10u16 => "Pmtudisc",
9677 11u16 => "EncapLimit",
9678 12u16 => "Flowinfo",
9679 13u16 => "Flags",
9680 14u16 => "EncapType",
9681 15u16 => "EncapFlags",
9682 16u16 => "EncapSport",
9683 17u16 => "EncapDport",
9684 18u16 => "CollectMetadata",
9685 19u16 => "IgnoreDf",
9686 20u16 => "Fwmark",
9687 21u16 => "ErspanIndex",
9688 22u16 => "ErspanVer",
9689 23u16 => "ErspanDir",
9690 24u16 => "ErspanHwid",
9691 _ => return None,
9692 };
9693 Some(res)
9694 }
9695}
9696#[derive(Clone, Copy, Default)]
9697pub struct IterableLinkinfoGreAttrs<'a> {
9698 buf: &'a [u8],
9699 pos: usize,
9700 orig_loc: usize,
9701}
9702impl<'a> IterableLinkinfoGreAttrs<'a> {
9703 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
9704 Self {
9705 buf,
9706 pos: 0,
9707 orig_loc,
9708 }
9709 }
9710 pub fn get_buf(&self) -> &'a [u8] {
9711 self.buf
9712 }
9713}
9714impl<'a> Iterator for IterableLinkinfoGreAttrs<'a> {
9715 type Item = Result<LinkinfoGreAttrs<'a>, ErrorContext>;
9716 fn next(&mut self) -> Option<Self::Item> {
9717 if self.buf.len() == self.pos {
9718 return None;
9719 }
9720 let pos = self.pos;
9721 let mut r#type = None;
9722 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
9723 r#type = Some(header.r#type);
9724 let res = match header.r#type {
9725 1u16 => LinkinfoGreAttrs::Link({
9726 let res = parse_u32(next);
9727 let Some(val) = res else { break };
9728 val
9729 }),
9730 2u16 => LinkinfoGreAttrs::Iflags({
9731 let res = parse_be_u16(next);
9732 let Some(val) = res else { break };
9733 val
9734 }),
9735 3u16 => LinkinfoGreAttrs::Oflags({
9736 let res = parse_be_u16(next);
9737 let Some(val) = res else { break };
9738 val
9739 }),
9740 4u16 => LinkinfoGreAttrs::Ikey({
9741 let res = parse_be_u32(next);
9742 let Some(val) = res else { break };
9743 val
9744 }),
9745 5u16 => LinkinfoGreAttrs::Okey({
9746 let res = parse_be_u32(next);
9747 let Some(val) = res else { break };
9748 val
9749 }),
9750 6u16 => LinkinfoGreAttrs::Local({
9751 let res = Some(next);
9752 let Some(val) = res else { break };
9753 val
9754 }),
9755 7u16 => LinkinfoGreAttrs::Remote({
9756 let res = Some(next);
9757 let Some(val) = res else { break };
9758 val
9759 }),
9760 8u16 => LinkinfoGreAttrs::Ttl({
9761 let res = parse_u8(next);
9762 let Some(val) = res else { break };
9763 val
9764 }),
9765 9u16 => LinkinfoGreAttrs::Tos({
9766 let res = parse_u8(next);
9767 let Some(val) = res else { break };
9768 val
9769 }),
9770 10u16 => LinkinfoGreAttrs::Pmtudisc({
9771 let res = parse_u8(next);
9772 let Some(val) = res else { break };
9773 val
9774 }),
9775 11u16 => LinkinfoGreAttrs::EncapLimit({
9776 let res = parse_u8(next);
9777 let Some(val) = res else { break };
9778 val
9779 }),
9780 12u16 => LinkinfoGreAttrs::Flowinfo({
9781 let res = parse_be_u32(next);
9782 let Some(val) = res else { break };
9783 val
9784 }),
9785 13u16 => LinkinfoGreAttrs::Flags({
9786 let res = parse_u32(next);
9787 let Some(val) = res else { break };
9788 val
9789 }),
9790 14u16 => LinkinfoGreAttrs::EncapType({
9791 let res = parse_u16(next);
9792 let Some(val) = res else { break };
9793 val
9794 }),
9795 15u16 => LinkinfoGreAttrs::EncapFlags({
9796 let res = parse_u16(next);
9797 let Some(val) = res else { break };
9798 val
9799 }),
9800 16u16 => LinkinfoGreAttrs::EncapSport({
9801 let res = parse_be_u16(next);
9802 let Some(val) = res else { break };
9803 val
9804 }),
9805 17u16 => LinkinfoGreAttrs::EncapDport({
9806 let res = parse_be_u16(next);
9807 let Some(val) = res else { break };
9808 val
9809 }),
9810 18u16 => LinkinfoGreAttrs::CollectMetadata(()),
9811 19u16 => LinkinfoGreAttrs::IgnoreDf({
9812 let res = parse_u8(next);
9813 let Some(val) = res else { break };
9814 val
9815 }),
9816 20u16 => LinkinfoGreAttrs::Fwmark({
9817 let res = parse_u32(next);
9818 let Some(val) = res else { break };
9819 val
9820 }),
9821 21u16 => LinkinfoGreAttrs::ErspanIndex({
9822 let res = parse_u32(next);
9823 let Some(val) = res else { break };
9824 val
9825 }),
9826 22u16 => LinkinfoGreAttrs::ErspanVer({
9827 let res = parse_u8(next);
9828 let Some(val) = res else { break };
9829 val
9830 }),
9831 23u16 => LinkinfoGreAttrs::ErspanDir({
9832 let res = parse_u8(next);
9833 let Some(val) = res else { break };
9834 val
9835 }),
9836 24u16 => LinkinfoGreAttrs::ErspanHwid({
9837 let res = parse_u16(next);
9838 let Some(val) = res else { break };
9839 val
9840 }),
9841 n => {
9842 if cfg!(any(test, feature = "deny-unknown-attrs")) {
9843 break;
9844 } else {
9845 continue;
9846 }
9847 }
9848 };
9849 return Some(Ok(res));
9850 }
9851 Some(Err(ErrorContext::new(
9852 "LinkinfoGreAttrs",
9853 r#type.and_then(|t| LinkinfoGreAttrs::attr_from_type(t)),
9854 self.orig_loc,
9855 self.buf.as_ptr().wrapping_add(pos) as usize,
9856 )))
9857 }
9858}
9859impl<'a> std::fmt::Debug for IterableLinkinfoGreAttrs<'_> {
9860 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9861 let mut fmt = f.debug_struct("LinkinfoGreAttrs");
9862 for attr in self.clone() {
9863 let attr = match attr {
9864 Ok(a) => a,
9865 Err(err) => {
9866 fmt.finish()?;
9867 f.write_str("Err(")?;
9868 err.fmt(f)?;
9869 return f.write_str(")");
9870 }
9871 };
9872 match attr {
9873 LinkinfoGreAttrs::Link(val) => fmt.field("Link", &val),
9874 LinkinfoGreAttrs::Iflags(val) => fmt.field("Iflags", &val),
9875 LinkinfoGreAttrs::Oflags(val) => fmt.field("Oflags", &val),
9876 LinkinfoGreAttrs::Ikey(val) => fmt.field("Ikey", &val),
9877 LinkinfoGreAttrs::Okey(val) => fmt.field("Okey", &val),
9878 LinkinfoGreAttrs::Local(val) => fmt.field("Local", &val),
9879 LinkinfoGreAttrs::Remote(val) => fmt.field("Remote", &val),
9880 LinkinfoGreAttrs::Ttl(val) => fmt.field("Ttl", &val),
9881 LinkinfoGreAttrs::Tos(val) => fmt.field("Tos", &val),
9882 LinkinfoGreAttrs::Pmtudisc(val) => fmt.field("Pmtudisc", &val),
9883 LinkinfoGreAttrs::EncapLimit(val) => fmt.field("EncapLimit", &val),
9884 LinkinfoGreAttrs::Flowinfo(val) => fmt.field("Flowinfo", &val),
9885 LinkinfoGreAttrs::Flags(val) => fmt.field("Flags", &val),
9886 LinkinfoGreAttrs::EncapType(val) => fmt.field("EncapType", &val),
9887 LinkinfoGreAttrs::EncapFlags(val) => fmt.field("EncapFlags", &val),
9888 LinkinfoGreAttrs::EncapSport(val) => fmt.field("EncapSport", &val),
9889 LinkinfoGreAttrs::EncapDport(val) => fmt.field("EncapDport", &val),
9890 LinkinfoGreAttrs::CollectMetadata(val) => fmt.field("CollectMetadata", &val),
9891 LinkinfoGreAttrs::IgnoreDf(val) => fmt.field("IgnoreDf", &val),
9892 LinkinfoGreAttrs::Fwmark(val) => fmt.field("Fwmark", &val),
9893 LinkinfoGreAttrs::ErspanIndex(val) => fmt.field("ErspanIndex", &val),
9894 LinkinfoGreAttrs::ErspanVer(val) => fmt.field("ErspanVer", &val),
9895 LinkinfoGreAttrs::ErspanDir(val) => fmt.field("ErspanDir", &val),
9896 LinkinfoGreAttrs::ErspanHwid(val) => fmt.field("ErspanHwid", &val),
9897 };
9898 }
9899 fmt.finish()
9900 }
9901}
9902impl IterableLinkinfoGreAttrs<'_> {
9903 pub fn lookup_attr(
9904 &self,
9905 offset: usize,
9906 missing_type: Option<u16>,
9907 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9908 let mut stack = Vec::new();
9909 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9910 if cur == offset {
9911 stack.push(("LinkinfoGreAttrs", offset));
9912 return (
9913 stack,
9914 missing_type.and_then(|t| LinkinfoGreAttrs::attr_from_type(t)),
9915 );
9916 }
9917 if cur > offset || cur + self.buf.len() < offset {
9918 return (stack, None);
9919 }
9920 let mut attrs = self.clone();
9921 let mut last_off = cur + attrs.pos;
9922 while let Some(attr) = attrs.next() {
9923 let Ok(attr) = attr else { break };
9924 match attr {
9925 LinkinfoGreAttrs::Link(val) => {
9926 if last_off == offset {
9927 stack.push(("Link", last_off));
9928 break;
9929 }
9930 }
9931 LinkinfoGreAttrs::Iflags(val) => {
9932 if last_off == offset {
9933 stack.push(("Iflags", last_off));
9934 break;
9935 }
9936 }
9937 LinkinfoGreAttrs::Oflags(val) => {
9938 if last_off == offset {
9939 stack.push(("Oflags", last_off));
9940 break;
9941 }
9942 }
9943 LinkinfoGreAttrs::Ikey(val) => {
9944 if last_off == offset {
9945 stack.push(("Ikey", last_off));
9946 break;
9947 }
9948 }
9949 LinkinfoGreAttrs::Okey(val) => {
9950 if last_off == offset {
9951 stack.push(("Okey", last_off));
9952 break;
9953 }
9954 }
9955 LinkinfoGreAttrs::Local(val) => {
9956 if last_off == offset {
9957 stack.push(("Local", last_off));
9958 break;
9959 }
9960 }
9961 LinkinfoGreAttrs::Remote(val) => {
9962 if last_off == offset {
9963 stack.push(("Remote", last_off));
9964 break;
9965 }
9966 }
9967 LinkinfoGreAttrs::Ttl(val) => {
9968 if last_off == offset {
9969 stack.push(("Ttl", last_off));
9970 break;
9971 }
9972 }
9973 LinkinfoGreAttrs::Tos(val) => {
9974 if last_off == offset {
9975 stack.push(("Tos", last_off));
9976 break;
9977 }
9978 }
9979 LinkinfoGreAttrs::Pmtudisc(val) => {
9980 if last_off == offset {
9981 stack.push(("Pmtudisc", last_off));
9982 break;
9983 }
9984 }
9985 LinkinfoGreAttrs::EncapLimit(val) => {
9986 if last_off == offset {
9987 stack.push(("EncapLimit", last_off));
9988 break;
9989 }
9990 }
9991 LinkinfoGreAttrs::Flowinfo(val) => {
9992 if last_off == offset {
9993 stack.push(("Flowinfo", last_off));
9994 break;
9995 }
9996 }
9997 LinkinfoGreAttrs::Flags(val) => {
9998 if last_off == offset {
9999 stack.push(("Flags", last_off));
10000 break;
10001 }
10002 }
10003 LinkinfoGreAttrs::EncapType(val) => {
10004 if last_off == offset {
10005 stack.push(("EncapType", last_off));
10006 break;
10007 }
10008 }
10009 LinkinfoGreAttrs::EncapFlags(val) => {
10010 if last_off == offset {
10011 stack.push(("EncapFlags", last_off));
10012 break;
10013 }
10014 }
10015 LinkinfoGreAttrs::EncapSport(val) => {
10016 if last_off == offset {
10017 stack.push(("EncapSport", last_off));
10018 break;
10019 }
10020 }
10021 LinkinfoGreAttrs::EncapDport(val) => {
10022 if last_off == offset {
10023 stack.push(("EncapDport", last_off));
10024 break;
10025 }
10026 }
10027 LinkinfoGreAttrs::CollectMetadata(val) => {
10028 if last_off == offset {
10029 stack.push(("CollectMetadata", last_off));
10030 break;
10031 }
10032 }
10033 LinkinfoGreAttrs::IgnoreDf(val) => {
10034 if last_off == offset {
10035 stack.push(("IgnoreDf", last_off));
10036 break;
10037 }
10038 }
10039 LinkinfoGreAttrs::Fwmark(val) => {
10040 if last_off == offset {
10041 stack.push(("Fwmark", last_off));
10042 break;
10043 }
10044 }
10045 LinkinfoGreAttrs::ErspanIndex(val) => {
10046 if last_off == offset {
10047 stack.push(("ErspanIndex", last_off));
10048 break;
10049 }
10050 }
10051 LinkinfoGreAttrs::ErspanVer(val) => {
10052 if last_off == offset {
10053 stack.push(("ErspanVer", last_off));
10054 break;
10055 }
10056 }
10057 LinkinfoGreAttrs::ErspanDir(val) => {
10058 if last_off == offset {
10059 stack.push(("ErspanDir", last_off));
10060 break;
10061 }
10062 }
10063 LinkinfoGreAttrs::ErspanHwid(val) => {
10064 if last_off == offset {
10065 stack.push(("ErspanHwid", last_off));
10066 break;
10067 }
10068 }
10069 _ => {}
10070 };
10071 last_off = cur + attrs.pos;
10072 }
10073 if !stack.is_empty() {
10074 stack.push(("LinkinfoGreAttrs", cur));
10075 }
10076 (stack, None)
10077 }
10078}
10079#[derive(Clone)]
10080pub enum LinkinfoGre6Attrs<'a> {
10081 Link(u32),
10082 Iflags(u16),
10083 Oflags(u16),
10084 Ikey(u32),
10085 Okey(u32),
10086 Local(&'a [u8]),
10087 Remote(&'a [u8]),
10088 Ttl(u8),
10089 EncapLimit(u8),
10090 Flowinfo(u32),
10091 Flags(u32),
10092 EncapType(u16),
10093 EncapFlags(u16),
10094 EncapSport(u16),
10095 EncapDport(u16),
10096 CollectMetadata(()),
10097 Fwmark(u32),
10098 ErspanIndex(u32),
10099 ErspanVer(u8),
10100 ErspanDir(u8),
10101 ErspanHwid(u16),
10102}
10103impl<'a> IterableLinkinfoGre6Attrs<'a> {
10104 pub fn get_link(&self) -> Result<u32, ErrorContext> {
10105 let mut iter = self.clone();
10106 iter.pos = 0;
10107 for attr in iter {
10108 if let LinkinfoGre6Attrs::Link(val) = attr? {
10109 return Ok(val);
10110 }
10111 }
10112 Err(ErrorContext::new_missing(
10113 "LinkinfoGre6Attrs",
10114 "Link",
10115 self.orig_loc,
10116 self.buf.as_ptr() as usize,
10117 ))
10118 }
10119 pub fn get_iflags(&self) -> Result<u16, ErrorContext> {
10120 let mut iter = self.clone();
10121 iter.pos = 0;
10122 for attr in iter {
10123 if let LinkinfoGre6Attrs::Iflags(val) = attr? {
10124 return Ok(val);
10125 }
10126 }
10127 Err(ErrorContext::new_missing(
10128 "LinkinfoGre6Attrs",
10129 "Iflags",
10130 self.orig_loc,
10131 self.buf.as_ptr() as usize,
10132 ))
10133 }
10134 pub fn get_oflags(&self) -> Result<u16, ErrorContext> {
10135 let mut iter = self.clone();
10136 iter.pos = 0;
10137 for attr in iter {
10138 if let LinkinfoGre6Attrs::Oflags(val) = attr? {
10139 return Ok(val);
10140 }
10141 }
10142 Err(ErrorContext::new_missing(
10143 "LinkinfoGre6Attrs",
10144 "Oflags",
10145 self.orig_loc,
10146 self.buf.as_ptr() as usize,
10147 ))
10148 }
10149 pub fn get_ikey(&self) -> Result<u32, ErrorContext> {
10150 let mut iter = self.clone();
10151 iter.pos = 0;
10152 for attr in iter {
10153 if let LinkinfoGre6Attrs::Ikey(val) = attr? {
10154 return Ok(val);
10155 }
10156 }
10157 Err(ErrorContext::new_missing(
10158 "LinkinfoGre6Attrs",
10159 "Ikey",
10160 self.orig_loc,
10161 self.buf.as_ptr() as usize,
10162 ))
10163 }
10164 pub fn get_okey(&self) -> Result<u32, ErrorContext> {
10165 let mut iter = self.clone();
10166 iter.pos = 0;
10167 for attr in iter {
10168 if let LinkinfoGre6Attrs::Okey(val) = attr? {
10169 return Ok(val);
10170 }
10171 }
10172 Err(ErrorContext::new_missing(
10173 "LinkinfoGre6Attrs",
10174 "Okey",
10175 self.orig_loc,
10176 self.buf.as_ptr() as usize,
10177 ))
10178 }
10179 pub fn get_local(&self) -> Result<&'a [u8], ErrorContext> {
10180 let mut iter = self.clone();
10181 iter.pos = 0;
10182 for attr in iter {
10183 if let LinkinfoGre6Attrs::Local(val) = attr? {
10184 return Ok(val);
10185 }
10186 }
10187 Err(ErrorContext::new_missing(
10188 "LinkinfoGre6Attrs",
10189 "Local",
10190 self.orig_loc,
10191 self.buf.as_ptr() as usize,
10192 ))
10193 }
10194 pub fn get_remote(&self) -> Result<&'a [u8], ErrorContext> {
10195 let mut iter = self.clone();
10196 iter.pos = 0;
10197 for attr in iter {
10198 if let LinkinfoGre6Attrs::Remote(val) = attr? {
10199 return Ok(val);
10200 }
10201 }
10202 Err(ErrorContext::new_missing(
10203 "LinkinfoGre6Attrs",
10204 "Remote",
10205 self.orig_loc,
10206 self.buf.as_ptr() as usize,
10207 ))
10208 }
10209 pub fn get_ttl(&self) -> Result<u8, ErrorContext> {
10210 let mut iter = self.clone();
10211 iter.pos = 0;
10212 for attr in iter {
10213 if let LinkinfoGre6Attrs::Ttl(val) = attr? {
10214 return Ok(val);
10215 }
10216 }
10217 Err(ErrorContext::new_missing(
10218 "LinkinfoGre6Attrs",
10219 "Ttl",
10220 self.orig_loc,
10221 self.buf.as_ptr() as usize,
10222 ))
10223 }
10224 pub fn get_encap_limit(&self) -> Result<u8, ErrorContext> {
10225 let mut iter = self.clone();
10226 iter.pos = 0;
10227 for attr in iter {
10228 if let LinkinfoGre6Attrs::EncapLimit(val) = attr? {
10229 return Ok(val);
10230 }
10231 }
10232 Err(ErrorContext::new_missing(
10233 "LinkinfoGre6Attrs",
10234 "EncapLimit",
10235 self.orig_loc,
10236 self.buf.as_ptr() as usize,
10237 ))
10238 }
10239 pub fn get_flowinfo(&self) -> Result<u32, ErrorContext> {
10240 let mut iter = self.clone();
10241 iter.pos = 0;
10242 for attr in iter {
10243 if let LinkinfoGre6Attrs::Flowinfo(val) = attr? {
10244 return Ok(val);
10245 }
10246 }
10247 Err(ErrorContext::new_missing(
10248 "LinkinfoGre6Attrs",
10249 "Flowinfo",
10250 self.orig_loc,
10251 self.buf.as_ptr() as usize,
10252 ))
10253 }
10254 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
10255 let mut iter = self.clone();
10256 iter.pos = 0;
10257 for attr in iter {
10258 if let LinkinfoGre6Attrs::Flags(val) = attr? {
10259 return Ok(val);
10260 }
10261 }
10262 Err(ErrorContext::new_missing(
10263 "LinkinfoGre6Attrs",
10264 "Flags",
10265 self.orig_loc,
10266 self.buf.as_ptr() as usize,
10267 ))
10268 }
10269 pub fn get_encap_type(&self) -> Result<u16, ErrorContext> {
10270 let mut iter = self.clone();
10271 iter.pos = 0;
10272 for attr in iter {
10273 if let LinkinfoGre6Attrs::EncapType(val) = attr? {
10274 return Ok(val);
10275 }
10276 }
10277 Err(ErrorContext::new_missing(
10278 "LinkinfoGre6Attrs",
10279 "EncapType",
10280 self.orig_loc,
10281 self.buf.as_ptr() as usize,
10282 ))
10283 }
10284 pub fn get_encap_flags(&self) -> Result<u16, ErrorContext> {
10285 let mut iter = self.clone();
10286 iter.pos = 0;
10287 for attr in iter {
10288 if let LinkinfoGre6Attrs::EncapFlags(val) = attr? {
10289 return Ok(val);
10290 }
10291 }
10292 Err(ErrorContext::new_missing(
10293 "LinkinfoGre6Attrs",
10294 "EncapFlags",
10295 self.orig_loc,
10296 self.buf.as_ptr() as usize,
10297 ))
10298 }
10299 pub fn get_encap_sport(&self) -> Result<u16, ErrorContext> {
10300 let mut iter = self.clone();
10301 iter.pos = 0;
10302 for attr in iter {
10303 if let LinkinfoGre6Attrs::EncapSport(val) = attr? {
10304 return Ok(val);
10305 }
10306 }
10307 Err(ErrorContext::new_missing(
10308 "LinkinfoGre6Attrs",
10309 "EncapSport",
10310 self.orig_loc,
10311 self.buf.as_ptr() as usize,
10312 ))
10313 }
10314 pub fn get_encap_dport(&self) -> Result<u16, ErrorContext> {
10315 let mut iter = self.clone();
10316 iter.pos = 0;
10317 for attr in iter {
10318 if let LinkinfoGre6Attrs::EncapDport(val) = attr? {
10319 return Ok(val);
10320 }
10321 }
10322 Err(ErrorContext::new_missing(
10323 "LinkinfoGre6Attrs",
10324 "EncapDport",
10325 self.orig_loc,
10326 self.buf.as_ptr() as usize,
10327 ))
10328 }
10329 pub fn get_collect_metadata(&self) -> Result<(), ErrorContext> {
10330 let mut iter = self.clone();
10331 iter.pos = 0;
10332 for attr in iter {
10333 if let LinkinfoGre6Attrs::CollectMetadata(val) = attr? {
10334 return Ok(val);
10335 }
10336 }
10337 Err(ErrorContext::new_missing(
10338 "LinkinfoGre6Attrs",
10339 "CollectMetadata",
10340 self.orig_loc,
10341 self.buf.as_ptr() as usize,
10342 ))
10343 }
10344 pub fn get_fwmark(&self) -> Result<u32, ErrorContext> {
10345 let mut iter = self.clone();
10346 iter.pos = 0;
10347 for attr in iter {
10348 if let LinkinfoGre6Attrs::Fwmark(val) = attr? {
10349 return Ok(val);
10350 }
10351 }
10352 Err(ErrorContext::new_missing(
10353 "LinkinfoGre6Attrs",
10354 "Fwmark",
10355 self.orig_loc,
10356 self.buf.as_ptr() as usize,
10357 ))
10358 }
10359 pub fn get_erspan_index(&self) -> Result<u32, ErrorContext> {
10360 let mut iter = self.clone();
10361 iter.pos = 0;
10362 for attr in iter {
10363 if let LinkinfoGre6Attrs::ErspanIndex(val) = attr? {
10364 return Ok(val);
10365 }
10366 }
10367 Err(ErrorContext::new_missing(
10368 "LinkinfoGre6Attrs",
10369 "ErspanIndex",
10370 self.orig_loc,
10371 self.buf.as_ptr() as usize,
10372 ))
10373 }
10374 pub fn get_erspan_ver(&self) -> Result<u8, ErrorContext> {
10375 let mut iter = self.clone();
10376 iter.pos = 0;
10377 for attr in iter {
10378 if let LinkinfoGre6Attrs::ErspanVer(val) = attr? {
10379 return Ok(val);
10380 }
10381 }
10382 Err(ErrorContext::new_missing(
10383 "LinkinfoGre6Attrs",
10384 "ErspanVer",
10385 self.orig_loc,
10386 self.buf.as_ptr() as usize,
10387 ))
10388 }
10389 pub fn get_erspan_dir(&self) -> Result<u8, ErrorContext> {
10390 let mut iter = self.clone();
10391 iter.pos = 0;
10392 for attr in iter {
10393 if let LinkinfoGre6Attrs::ErspanDir(val) = attr? {
10394 return Ok(val);
10395 }
10396 }
10397 Err(ErrorContext::new_missing(
10398 "LinkinfoGre6Attrs",
10399 "ErspanDir",
10400 self.orig_loc,
10401 self.buf.as_ptr() as usize,
10402 ))
10403 }
10404 pub fn get_erspan_hwid(&self) -> Result<u16, ErrorContext> {
10405 let mut iter = self.clone();
10406 iter.pos = 0;
10407 for attr in iter {
10408 if let LinkinfoGre6Attrs::ErspanHwid(val) = attr? {
10409 return Ok(val);
10410 }
10411 }
10412 Err(ErrorContext::new_missing(
10413 "LinkinfoGre6Attrs",
10414 "ErspanHwid",
10415 self.orig_loc,
10416 self.buf.as_ptr() as usize,
10417 ))
10418 }
10419}
10420impl LinkinfoGre6Attrs<'_> {
10421 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoGre6Attrs<'a> {
10422 IterableLinkinfoGre6Attrs::with_loc(buf, buf.as_ptr() as usize)
10423 }
10424 fn attr_from_type(r#type: u16) -> Option<&'static str> {
10425 LinkinfoGreAttrs::attr_from_type(r#type)
10426 }
10427}
10428#[derive(Clone, Copy, Default)]
10429pub struct IterableLinkinfoGre6Attrs<'a> {
10430 buf: &'a [u8],
10431 pos: usize,
10432 orig_loc: usize,
10433}
10434impl<'a> IterableLinkinfoGre6Attrs<'a> {
10435 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
10436 Self {
10437 buf,
10438 pos: 0,
10439 orig_loc,
10440 }
10441 }
10442 pub fn get_buf(&self) -> &'a [u8] {
10443 self.buf
10444 }
10445}
10446impl<'a> Iterator for IterableLinkinfoGre6Attrs<'a> {
10447 type Item = Result<LinkinfoGre6Attrs<'a>, ErrorContext>;
10448 fn next(&mut self) -> Option<Self::Item> {
10449 if self.buf.len() == self.pos {
10450 return None;
10451 }
10452 let pos = self.pos;
10453 let mut r#type = None;
10454 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
10455 r#type = Some(header.r#type);
10456 let res = match header.r#type {
10457 1u16 => LinkinfoGre6Attrs::Link({
10458 let res = parse_u32(next);
10459 let Some(val) = res else { break };
10460 val
10461 }),
10462 2u16 => LinkinfoGre6Attrs::Iflags({
10463 let res = parse_be_u16(next);
10464 let Some(val) = res else { break };
10465 val
10466 }),
10467 3u16 => LinkinfoGre6Attrs::Oflags({
10468 let res = parse_be_u16(next);
10469 let Some(val) = res else { break };
10470 val
10471 }),
10472 4u16 => LinkinfoGre6Attrs::Ikey({
10473 let res = parse_be_u32(next);
10474 let Some(val) = res else { break };
10475 val
10476 }),
10477 5u16 => LinkinfoGre6Attrs::Okey({
10478 let res = parse_be_u32(next);
10479 let Some(val) = res else { break };
10480 val
10481 }),
10482 6u16 => LinkinfoGre6Attrs::Local({
10483 let res = Some(next);
10484 let Some(val) = res else { break };
10485 val
10486 }),
10487 7u16 => LinkinfoGre6Attrs::Remote({
10488 let res = Some(next);
10489 let Some(val) = res else { break };
10490 val
10491 }),
10492 8u16 => LinkinfoGre6Attrs::Ttl({
10493 let res = parse_u8(next);
10494 let Some(val) = res else { break };
10495 val
10496 }),
10497 11u16 => LinkinfoGre6Attrs::EncapLimit({
10498 let res = parse_u8(next);
10499 let Some(val) = res else { break };
10500 val
10501 }),
10502 12u16 => LinkinfoGre6Attrs::Flowinfo({
10503 let res = parse_be_u32(next);
10504 let Some(val) = res else { break };
10505 val
10506 }),
10507 13u16 => LinkinfoGre6Attrs::Flags({
10508 let res = parse_u32(next);
10509 let Some(val) = res else { break };
10510 val
10511 }),
10512 14u16 => LinkinfoGre6Attrs::EncapType({
10513 let res = parse_u16(next);
10514 let Some(val) = res else { break };
10515 val
10516 }),
10517 15u16 => LinkinfoGre6Attrs::EncapFlags({
10518 let res = parse_u16(next);
10519 let Some(val) = res else { break };
10520 val
10521 }),
10522 16u16 => LinkinfoGre6Attrs::EncapSport({
10523 let res = parse_be_u16(next);
10524 let Some(val) = res else { break };
10525 val
10526 }),
10527 17u16 => LinkinfoGre6Attrs::EncapDport({
10528 let res = parse_be_u16(next);
10529 let Some(val) = res else { break };
10530 val
10531 }),
10532 18u16 => LinkinfoGre6Attrs::CollectMetadata(()),
10533 20u16 => LinkinfoGre6Attrs::Fwmark({
10534 let res = parse_u32(next);
10535 let Some(val) = res else { break };
10536 val
10537 }),
10538 21u16 => LinkinfoGre6Attrs::ErspanIndex({
10539 let res = parse_u32(next);
10540 let Some(val) = res else { break };
10541 val
10542 }),
10543 22u16 => LinkinfoGre6Attrs::ErspanVer({
10544 let res = parse_u8(next);
10545 let Some(val) = res else { break };
10546 val
10547 }),
10548 23u16 => LinkinfoGre6Attrs::ErspanDir({
10549 let res = parse_u8(next);
10550 let Some(val) = res else { break };
10551 val
10552 }),
10553 24u16 => LinkinfoGre6Attrs::ErspanHwid({
10554 let res = parse_u16(next);
10555 let Some(val) = res else { break };
10556 val
10557 }),
10558 n => {
10559 if cfg!(any(test, feature = "deny-unknown-attrs")) {
10560 break;
10561 } else {
10562 continue;
10563 }
10564 }
10565 };
10566 return Some(Ok(res));
10567 }
10568 Some(Err(ErrorContext::new(
10569 "LinkinfoGre6Attrs",
10570 r#type.and_then(|t| LinkinfoGre6Attrs::attr_from_type(t)),
10571 self.orig_loc,
10572 self.buf.as_ptr().wrapping_add(pos) as usize,
10573 )))
10574 }
10575}
10576impl<'a> std::fmt::Debug for IterableLinkinfoGre6Attrs<'_> {
10577 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10578 let mut fmt = f.debug_struct("LinkinfoGre6Attrs");
10579 for attr in self.clone() {
10580 let attr = match attr {
10581 Ok(a) => a,
10582 Err(err) => {
10583 fmt.finish()?;
10584 f.write_str("Err(")?;
10585 err.fmt(f)?;
10586 return f.write_str(")");
10587 }
10588 };
10589 match attr {
10590 LinkinfoGre6Attrs::Link(val) => fmt.field("Link", &val),
10591 LinkinfoGre6Attrs::Iflags(val) => fmt.field("Iflags", &val),
10592 LinkinfoGre6Attrs::Oflags(val) => fmt.field("Oflags", &val),
10593 LinkinfoGre6Attrs::Ikey(val) => fmt.field("Ikey", &val),
10594 LinkinfoGre6Attrs::Okey(val) => fmt.field("Okey", &val),
10595 LinkinfoGre6Attrs::Local(val) => fmt.field("Local", &val),
10596 LinkinfoGre6Attrs::Remote(val) => fmt.field("Remote", &val),
10597 LinkinfoGre6Attrs::Ttl(val) => fmt.field("Ttl", &val),
10598 LinkinfoGre6Attrs::EncapLimit(val) => fmt.field("EncapLimit", &val),
10599 LinkinfoGre6Attrs::Flowinfo(val) => fmt.field("Flowinfo", &val),
10600 LinkinfoGre6Attrs::Flags(val) => fmt.field("Flags", &val),
10601 LinkinfoGre6Attrs::EncapType(val) => fmt.field("EncapType", &val),
10602 LinkinfoGre6Attrs::EncapFlags(val) => fmt.field("EncapFlags", &val),
10603 LinkinfoGre6Attrs::EncapSport(val) => fmt.field("EncapSport", &val),
10604 LinkinfoGre6Attrs::EncapDport(val) => fmt.field("EncapDport", &val),
10605 LinkinfoGre6Attrs::CollectMetadata(val) => fmt.field("CollectMetadata", &val),
10606 LinkinfoGre6Attrs::Fwmark(val) => fmt.field("Fwmark", &val),
10607 LinkinfoGre6Attrs::ErspanIndex(val) => fmt.field("ErspanIndex", &val),
10608 LinkinfoGre6Attrs::ErspanVer(val) => fmt.field("ErspanVer", &val),
10609 LinkinfoGre6Attrs::ErspanDir(val) => fmt.field("ErspanDir", &val),
10610 LinkinfoGre6Attrs::ErspanHwid(val) => fmt.field("ErspanHwid", &val),
10611 };
10612 }
10613 fmt.finish()
10614 }
10615}
10616impl IterableLinkinfoGre6Attrs<'_> {
10617 pub fn lookup_attr(
10618 &self,
10619 offset: usize,
10620 missing_type: Option<u16>,
10621 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
10622 let mut stack = Vec::new();
10623 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
10624 if cur == offset {
10625 stack.push(("LinkinfoGre6Attrs", offset));
10626 return (
10627 stack,
10628 missing_type.and_then(|t| LinkinfoGre6Attrs::attr_from_type(t)),
10629 );
10630 }
10631 if cur > offset || cur + self.buf.len() < offset {
10632 return (stack, None);
10633 }
10634 let mut attrs = self.clone();
10635 let mut last_off = cur + attrs.pos;
10636 while let Some(attr) = attrs.next() {
10637 let Ok(attr) = attr else { break };
10638 match attr {
10639 LinkinfoGre6Attrs::Link(val) => {
10640 if last_off == offset {
10641 stack.push(("Link", last_off));
10642 break;
10643 }
10644 }
10645 LinkinfoGre6Attrs::Iflags(val) => {
10646 if last_off == offset {
10647 stack.push(("Iflags", last_off));
10648 break;
10649 }
10650 }
10651 LinkinfoGre6Attrs::Oflags(val) => {
10652 if last_off == offset {
10653 stack.push(("Oflags", last_off));
10654 break;
10655 }
10656 }
10657 LinkinfoGre6Attrs::Ikey(val) => {
10658 if last_off == offset {
10659 stack.push(("Ikey", last_off));
10660 break;
10661 }
10662 }
10663 LinkinfoGre6Attrs::Okey(val) => {
10664 if last_off == offset {
10665 stack.push(("Okey", last_off));
10666 break;
10667 }
10668 }
10669 LinkinfoGre6Attrs::Local(val) => {
10670 if last_off == offset {
10671 stack.push(("Local", last_off));
10672 break;
10673 }
10674 }
10675 LinkinfoGre6Attrs::Remote(val) => {
10676 if last_off == offset {
10677 stack.push(("Remote", last_off));
10678 break;
10679 }
10680 }
10681 LinkinfoGre6Attrs::Ttl(val) => {
10682 if last_off == offset {
10683 stack.push(("Ttl", last_off));
10684 break;
10685 }
10686 }
10687 LinkinfoGre6Attrs::EncapLimit(val) => {
10688 if last_off == offset {
10689 stack.push(("EncapLimit", last_off));
10690 break;
10691 }
10692 }
10693 LinkinfoGre6Attrs::Flowinfo(val) => {
10694 if last_off == offset {
10695 stack.push(("Flowinfo", last_off));
10696 break;
10697 }
10698 }
10699 LinkinfoGre6Attrs::Flags(val) => {
10700 if last_off == offset {
10701 stack.push(("Flags", last_off));
10702 break;
10703 }
10704 }
10705 LinkinfoGre6Attrs::EncapType(val) => {
10706 if last_off == offset {
10707 stack.push(("EncapType", last_off));
10708 break;
10709 }
10710 }
10711 LinkinfoGre6Attrs::EncapFlags(val) => {
10712 if last_off == offset {
10713 stack.push(("EncapFlags", last_off));
10714 break;
10715 }
10716 }
10717 LinkinfoGre6Attrs::EncapSport(val) => {
10718 if last_off == offset {
10719 stack.push(("EncapSport", last_off));
10720 break;
10721 }
10722 }
10723 LinkinfoGre6Attrs::EncapDport(val) => {
10724 if last_off == offset {
10725 stack.push(("EncapDport", last_off));
10726 break;
10727 }
10728 }
10729 LinkinfoGre6Attrs::CollectMetadata(val) => {
10730 if last_off == offset {
10731 stack.push(("CollectMetadata", last_off));
10732 break;
10733 }
10734 }
10735 LinkinfoGre6Attrs::Fwmark(val) => {
10736 if last_off == offset {
10737 stack.push(("Fwmark", last_off));
10738 break;
10739 }
10740 }
10741 LinkinfoGre6Attrs::ErspanIndex(val) => {
10742 if last_off == offset {
10743 stack.push(("ErspanIndex", last_off));
10744 break;
10745 }
10746 }
10747 LinkinfoGre6Attrs::ErspanVer(val) => {
10748 if last_off == offset {
10749 stack.push(("ErspanVer", last_off));
10750 break;
10751 }
10752 }
10753 LinkinfoGre6Attrs::ErspanDir(val) => {
10754 if last_off == offset {
10755 stack.push(("ErspanDir", last_off));
10756 break;
10757 }
10758 }
10759 LinkinfoGre6Attrs::ErspanHwid(val) => {
10760 if last_off == offset {
10761 stack.push(("ErspanHwid", last_off));
10762 break;
10763 }
10764 }
10765 _ => {}
10766 };
10767 last_off = cur + attrs.pos;
10768 }
10769 if !stack.is_empty() {
10770 stack.push(("LinkinfoGre6Attrs", cur));
10771 }
10772 (stack, None)
10773 }
10774}
10775#[derive(Clone)]
10776pub enum LinkinfoVtiAttrs<'a> {
10777 Link(u32),
10778 Ikey(u32),
10779 Okey(u32),
10780 Local(&'a [u8]),
10781 Remote(&'a [u8]),
10782 Fwmark(u32),
10783}
10784impl<'a> IterableLinkinfoVtiAttrs<'a> {
10785 pub fn get_link(&self) -> Result<u32, ErrorContext> {
10786 let mut iter = self.clone();
10787 iter.pos = 0;
10788 for attr in iter {
10789 if let LinkinfoVtiAttrs::Link(val) = attr? {
10790 return Ok(val);
10791 }
10792 }
10793 Err(ErrorContext::new_missing(
10794 "LinkinfoVtiAttrs",
10795 "Link",
10796 self.orig_loc,
10797 self.buf.as_ptr() as usize,
10798 ))
10799 }
10800 pub fn get_ikey(&self) -> Result<u32, ErrorContext> {
10801 let mut iter = self.clone();
10802 iter.pos = 0;
10803 for attr in iter {
10804 if let LinkinfoVtiAttrs::Ikey(val) = attr? {
10805 return Ok(val);
10806 }
10807 }
10808 Err(ErrorContext::new_missing(
10809 "LinkinfoVtiAttrs",
10810 "Ikey",
10811 self.orig_loc,
10812 self.buf.as_ptr() as usize,
10813 ))
10814 }
10815 pub fn get_okey(&self) -> Result<u32, ErrorContext> {
10816 let mut iter = self.clone();
10817 iter.pos = 0;
10818 for attr in iter {
10819 if let LinkinfoVtiAttrs::Okey(val) = attr? {
10820 return Ok(val);
10821 }
10822 }
10823 Err(ErrorContext::new_missing(
10824 "LinkinfoVtiAttrs",
10825 "Okey",
10826 self.orig_loc,
10827 self.buf.as_ptr() as usize,
10828 ))
10829 }
10830 pub fn get_local(&self) -> Result<&'a [u8], ErrorContext> {
10831 let mut iter = self.clone();
10832 iter.pos = 0;
10833 for attr in iter {
10834 if let LinkinfoVtiAttrs::Local(val) = attr? {
10835 return Ok(val);
10836 }
10837 }
10838 Err(ErrorContext::new_missing(
10839 "LinkinfoVtiAttrs",
10840 "Local",
10841 self.orig_loc,
10842 self.buf.as_ptr() as usize,
10843 ))
10844 }
10845 pub fn get_remote(&self) -> Result<&'a [u8], ErrorContext> {
10846 let mut iter = self.clone();
10847 iter.pos = 0;
10848 for attr in iter {
10849 if let LinkinfoVtiAttrs::Remote(val) = attr? {
10850 return Ok(val);
10851 }
10852 }
10853 Err(ErrorContext::new_missing(
10854 "LinkinfoVtiAttrs",
10855 "Remote",
10856 self.orig_loc,
10857 self.buf.as_ptr() as usize,
10858 ))
10859 }
10860 pub fn get_fwmark(&self) -> Result<u32, ErrorContext> {
10861 let mut iter = self.clone();
10862 iter.pos = 0;
10863 for attr in iter {
10864 if let LinkinfoVtiAttrs::Fwmark(val) = attr? {
10865 return Ok(val);
10866 }
10867 }
10868 Err(ErrorContext::new_missing(
10869 "LinkinfoVtiAttrs",
10870 "Fwmark",
10871 self.orig_loc,
10872 self.buf.as_ptr() as usize,
10873 ))
10874 }
10875}
10876impl LinkinfoVtiAttrs<'_> {
10877 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoVtiAttrs<'a> {
10878 IterableLinkinfoVtiAttrs::with_loc(buf, buf.as_ptr() as usize)
10879 }
10880 fn attr_from_type(r#type: u16) -> Option<&'static str> {
10881 let res = match r#type {
10882 1u16 => "Link",
10883 2u16 => "Ikey",
10884 3u16 => "Okey",
10885 4u16 => "Local",
10886 5u16 => "Remote",
10887 6u16 => "Fwmark",
10888 _ => return None,
10889 };
10890 Some(res)
10891 }
10892}
10893#[derive(Clone, Copy, Default)]
10894pub struct IterableLinkinfoVtiAttrs<'a> {
10895 buf: &'a [u8],
10896 pos: usize,
10897 orig_loc: usize,
10898}
10899impl<'a> IterableLinkinfoVtiAttrs<'a> {
10900 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
10901 Self {
10902 buf,
10903 pos: 0,
10904 orig_loc,
10905 }
10906 }
10907 pub fn get_buf(&self) -> &'a [u8] {
10908 self.buf
10909 }
10910}
10911impl<'a> Iterator for IterableLinkinfoVtiAttrs<'a> {
10912 type Item = Result<LinkinfoVtiAttrs<'a>, ErrorContext>;
10913 fn next(&mut self) -> Option<Self::Item> {
10914 if self.buf.len() == self.pos {
10915 return None;
10916 }
10917 let pos = self.pos;
10918 let mut r#type = None;
10919 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
10920 r#type = Some(header.r#type);
10921 let res = match header.r#type {
10922 1u16 => LinkinfoVtiAttrs::Link({
10923 let res = parse_u32(next);
10924 let Some(val) = res else { break };
10925 val
10926 }),
10927 2u16 => LinkinfoVtiAttrs::Ikey({
10928 let res = parse_be_u32(next);
10929 let Some(val) = res else { break };
10930 val
10931 }),
10932 3u16 => LinkinfoVtiAttrs::Okey({
10933 let res = parse_be_u32(next);
10934 let Some(val) = res else { break };
10935 val
10936 }),
10937 4u16 => LinkinfoVtiAttrs::Local({
10938 let res = Some(next);
10939 let Some(val) = res else { break };
10940 val
10941 }),
10942 5u16 => LinkinfoVtiAttrs::Remote({
10943 let res = Some(next);
10944 let Some(val) = res else { break };
10945 val
10946 }),
10947 6u16 => LinkinfoVtiAttrs::Fwmark({
10948 let res = parse_u32(next);
10949 let Some(val) = res else { break };
10950 val
10951 }),
10952 n => {
10953 if cfg!(any(test, feature = "deny-unknown-attrs")) {
10954 break;
10955 } else {
10956 continue;
10957 }
10958 }
10959 };
10960 return Some(Ok(res));
10961 }
10962 Some(Err(ErrorContext::new(
10963 "LinkinfoVtiAttrs",
10964 r#type.and_then(|t| LinkinfoVtiAttrs::attr_from_type(t)),
10965 self.orig_loc,
10966 self.buf.as_ptr().wrapping_add(pos) as usize,
10967 )))
10968 }
10969}
10970impl<'a> std::fmt::Debug for IterableLinkinfoVtiAttrs<'_> {
10971 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10972 let mut fmt = f.debug_struct("LinkinfoVtiAttrs");
10973 for attr in self.clone() {
10974 let attr = match attr {
10975 Ok(a) => a,
10976 Err(err) => {
10977 fmt.finish()?;
10978 f.write_str("Err(")?;
10979 err.fmt(f)?;
10980 return f.write_str(")");
10981 }
10982 };
10983 match attr {
10984 LinkinfoVtiAttrs::Link(val) => fmt.field("Link", &val),
10985 LinkinfoVtiAttrs::Ikey(val) => fmt.field("Ikey", &val),
10986 LinkinfoVtiAttrs::Okey(val) => fmt.field("Okey", &val),
10987 LinkinfoVtiAttrs::Local(val) => fmt.field("Local", &val),
10988 LinkinfoVtiAttrs::Remote(val) => fmt.field("Remote", &val),
10989 LinkinfoVtiAttrs::Fwmark(val) => fmt.field("Fwmark", &val),
10990 };
10991 }
10992 fmt.finish()
10993 }
10994}
10995impl IterableLinkinfoVtiAttrs<'_> {
10996 pub fn lookup_attr(
10997 &self,
10998 offset: usize,
10999 missing_type: Option<u16>,
11000 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11001 let mut stack = Vec::new();
11002 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11003 if cur == offset {
11004 stack.push(("LinkinfoVtiAttrs", offset));
11005 return (
11006 stack,
11007 missing_type.and_then(|t| LinkinfoVtiAttrs::attr_from_type(t)),
11008 );
11009 }
11010 if cur > offset || cur + self.buf.len() < offset {
11011 return (stack, None);
11012 }
11013 let mut attrs = self.clone();
11014 let mut last_off = cur + attrs.pos;
11015 while let Some(attr) = attrs.next() {
11016 let Ok(attr) = attr else { break };
11017 match attr {
11018 LinkinfoVtiAttrs::Link(val) => {
11019 if last_off == offset {
11020 stack.push(("Link", last_off));
11021 break;
11022 }
11023 }
11024 LinkinfoVtiAttrs::Ikey(val) => {
11025 if last_off == offset {
11026 stack.push(("Ikey", last_off));
11027 break;
11028 }
11029 }
11030 LinkinfoVtiAttrs::Okey(val) => {
11031 if last_off == offset {
11032 stack.push(("Okey", last_off));
11033 break;
11034 }
11035 }
11036 LinkinfoVtiAttrs::Local(val) => {
11037 if last_off == offset {
11038 stack.push(("Local", last_off));
11039 break;
11040 }
11041 }
11042 LinkinfoVtiAttrs::Remote(val) => {
11043 if last_off == offset {
11044 stack.push(("Remote", last_off));
11045 break;
11046 }
11047 }
11048 LinkinfoVtiAttrs::Fwmark(val) => {
11049 if last_off == offset {
11050 stack.push(("Fwmark", last_off));
11051 break;
11052 }
11053 }
11054 _ => {}
11055 };
11056 last_off = cur + attrs.pos;
11057 }
11058 if !stack.is_empty() {
11059 stack.push(("LinkinfoVtiAttrs", cur));
11060 }
11061 (stack, None)
11062 }
11063}
11064#[derive(Clone)]
11065pub enum LinkinfoVti6Attrs<'a> {
11066 Link(u32),
11067 Ikey(u32),
11068 Okey(u32),
11069 Local(&'a [u8]),
11070 Remote(&'a [u8]),
11071 Fwmark(u32),
11072}
11073impl<'a> IterableLinkinfoVti6Attrs<'a> {
11074 pub fn get_link(&self) -> Result<u32, ErrorContext> {
11075 let mut iter = self.clone();
11076 iter.pos = 0;
11077 for attr in iter {
11078 if let LinkinfoVti6Attrs::Link(val) = attr? {
11079 return Ok(val);
11080 }
11081 }
11082 Err(ErrorContext::new_missing(
11083 "LinkinfoVti6Attrs",
11084 "Link",
11085 self.orig_loc,
11086 self.buf.as_ptr() as usize,
11087 ))
11088 }
11089 pub fn get_ikey(&self) -> Result<u32, ErrorContext> {
11090 let mut iter = self.clone();
11091 iter.pos = 0;
11092 for attr in iter {
11093 if let LinkinfoVti6Attrs::Ikey(val) = attr? {
11094 return Ok(val);
11095 }
11096 }
11097 Err(ErrorContext::new_missing(
11098 "LinkinfoVti6Attrs",
11099 "Ikey",
11100 self.orig_loc,
11101 self.buf.as_ptr() as usize,
11102 ))
11103 }
11104 pub fn get_okey(&self) -> Result<u32, ErrorContext> {
11105 let mut iter = self.clone();
11106 iter.pos = 0;
11107 for attr in iter {
11108 if let LinkinfoVti6Attrs::Okey(val) = attr? {
11109 return Ok(val);
11110 }
11111 }
11112 Err(ErrorContext::new_missing(
11113 "LinkinfoVti6Attrs",
11114 "Okey",
11115 self.orig_loc,
11116 self.buf.as_ptr() as usize,
11117 ))
11118 }
11119 pub fn get_local(&self) -> Result<&'a [u8], ErrorContext> {
11120 let mut iter = self.clone();
11121 iter.pos = 0;
11122 for attr in iter {
11123 if let LinkinfoVti6Attrs::Local(val) = attr? {
11124 return Ok(val);
11125 }
11126 }
11127 Err(ErrorContext::new_missing(
11128 "LinkinfoVti6Attrs",
11129 "Local",
11130 self.orig_loc,
11131 self.buf.as_ptr() as usize,
11132 ))
11133 }
11134 pub fn get_remote(&self) -> Result<&'a [u8], ErrorContext> {
11135 let mut iter = self.clone();
11136 iter.pos = 0;
11137 for attr in iter {
11138 if let LinkinfoVti6Attrs::Remote(val) = attr? {
11139 return Ok(val);
11140 }
11141 }
11142 Err(ErrorContext::new_missing(
11143 "LinkinfoVti6Attrs",
11144 "Remote",
11145 self.orig_loc,
11146 self.buf.as_ptr() as usize,
11147 ))
11148 }
11149 pub fn get_fwmark(&self) -> Result<u32, ErrorContext> {
11150 let mut iter = self.clone();
11151 iter.pos = 0;
11152 for attr in iter {
11153 if let LinkinfoVti6Attrs::Fwmark(val) = attr? {
11154 return Ok(val);
11155 }
11156 }
11157 Err(ErrorContext::new_missing(
11158 "LinkinfoVti6Attrs",
11159 "Fwmark",
11160 self.orig_loc,
11161 self.buf.as_ptr() as usize,
11162 ))
11163 }
11164}
11165impl LinkinfoVti6Attrs<'_> {
11166 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoVti6Attrs<'a> {
11167 IterableLinkinfoVti6Attrs::with_loc(buf, buf.as_ptr() as usize)
11168 }
11169 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11170 LinkinfoVtiAttrs::attr_from_type(r#type)
11171 }
11172}
11173#[derive(Clone, Copy, Default)]
11174pub struct IterableLinkinfoVti6Attrs<'a> {
11175 buf: &'a [u8],
11176 pos: usize,
11177 orig_loc: usize,
11178}
11179impl<'a> IterableLinkinfoVti6Attrs<'a> {
11180 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11181 Self {
11182 buf,
11183 pos: 0,
11184 orig_loc,
11185 }
11186 }
11187 pub fn get_buf(&self) -> &'a [u8] {
11188 self.buf
11189 }
11190}
11191impl<'a> Iterator for IterableLinkinfoVti6Attrs<'a> {
11192 type Item = Result<LinkinfoVti6Attrs<'a>, ErrorContext>;
11193 fn next(&mut self) -> Option<Self::Item> {
11194 if self.buf.len() == self.pos {
11195 return None;
11196 }
11197 let pos = self.pos;
11198 let mut r#type = None;
11199 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
11200 r#type = Some(header.r#type);
11201 let res = match header.r#type {
11202 1u16 => LinkinfoVti6Attrs::Link({
11203 let res = parse_u32(next);
11204 let Some(val) = res else { break };
11205 val
11206 }),
11207 2u16 => LinkinfoVti6Attrs::Ikey({
11208 let res = parse_be_u32(next);
11209 let Some(val) = res else { break };
11210 val
11211 }),
11212 3u16 => LinkinfoVti6Attrs::Okey({
11213 let res = parse_be_u32(next);
11214 let Some(val) = res else { break };
11215 val
11216 }),
11217 4u16 => LinkinfoVti6Attrs::Local({
11218 let res = Some(next);
11219 let Some(val) = res else { break };
11220 val
11221 }),
11222 5u16 => LinkinfoVti6Attrs::Remote({
11223 let res = Some(next);
11224 let Some(val) = res else { break };
11225 val
11226 }),
11227 6u16 => LinkinfoVti6Attrs::Fwmark({
11228 let res = parse_u32(next);
11229 let Some(val) = res else { break };
11230 val
11231 }),
11232 n => {
11233 if cfg!(any(test, feature = "deny-unknown-attrs")) {
11234 break;
11235 } else {
11236 continue;
11237 }
11238 }
11239 };
11240 return Some(Ok(res));
11241 }
11242 Some(Err(ErrorContext::new(
11243 "LinkinfoVti6Attrs",
11244 r#type.and_then(|t| LinkinfoVti6Attrs::attr_from_type(t)),
11245 self.orig_loc,
11246 self.buf.as_ptr().wrapping_add(pos) as usize,
11247 )))
11248 }
11249}
11250impl<'a> std::fmt::Debug for IterableLinkinfoVti6Attrs<'_> {
11251 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11252 let mut fmt = f.debug_struct("LinkinfoVti6Attrs");
11253 for attr in self.clone() {
11254 let attr = match attr {
11255 Ok(a) => a,
11256 Err(err) => {
11257 fmt.finish()?;
11258 f.write_str("Err(")?;
11259 err.fmt(f)?;
11260 return f.write_str(")");
11261 }
11262 };
11263 match attr {
11264 LinkinfoVti6Attrs::Link(val) => fmt.field("Link", &val),
11265 LinkinfoVti6Attrs::Ikey(val) => fmt.field("Ikey", &val),
11266 LinkinfoVti6Attrs::Okey(val) => fmt.field("Okey", &val),
11267 LinkinfoVti6Attrs::Local(val) => fmt.field("Local", &val),
11268 LinkinfoVti6Attrs::Remote(val) => fmt.field("Remote", &val),
11269 LinkinfoVti6Attrs::Fwmark(val) => fmt.field("Fwmark", &val),
11270 };
11271 }
11272 fmt.finish()
11273 }
11274}
11275impl IterableLinkinfoVti6Attrs<'_> {
11276 pub fn lookup_attr(
11277 &self,
11278 offset: usize,
11279 missing_type: Option<u16>,
11280 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11281 let mut stack = Vec::new();
11282 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11283 if cur == offset {
11284 stack.push(("LinkinfoVti6Attrs", offset));
11285 return (
11286 stack,
11287 missing_type.and_then(|t| LinkinfoVti6Attrs::attr_from_type(t)),
11288 );
11289 }
11290 if cur > offset || cur + self.buf.len() < offset {
11291 return (stack, None);
11292 }
11293 let mut attrs = self.clone();
11294 let mut last_off = cur + attrs.pos;
11295 while let Some(attr) = attrs.next() {
11296 let Ok(attr) = attr else { break };
11297 match attr {
11298 LinkinfoVti6Attrs::Link(val) => {
11299 if last_off == offset {
11300 stack.push(("Link", last_off));
11301 break;
11302 }
11303 }
11304 LinkinfoVti6Attrs::Ikey(val) => {
11305 if last_off == offset {
11306 stack.push(("Ikey", last_off));
11307 break;
11308 }
11309 }
11310 LinkinfoVti6Attrs::Okey(val) => {
11311 if last_off == offset {
11312 stack.push(("Okey", last_off));
11313 break;
11314 }
11315 }
11316 LinkinfoVti6Attrs::Local(val) => {
11317 if last_off == offset {
11318 stack.push(("Local", last_off));
11319 break;
11320 }
11321 }
11322 LinkinfoVti6Attrs::Remote(val) => {
11323 if last_off == offset {
11324 stack.push(("Remote", last_off));
11325 break;
11326 }
11327 }
11328 LinkinfoVti6Attrs::Fwmark(val) => {
11329 if last_off == offset {
11330 stack.push(("Fwmark", last_off));
11331 break;
11332 }
11333 }
11334 _ => {}
11335 };
11336 last_off = cur + attrs.pos;
11337 }
11338 if !stack.is_empty() {
11339 stack.push(("LinkinfoVti6Attrs", cur));
11340 }
11341 (stack, None)
11342 }
11343}
11344#[derive(Clone)]
11345pub enum LinkinfoGeneveAttrs<'a> {
11346 Id(u32),
11347 Remote(&'a [u8]),
11348 Ttl(u8),
11349 Tos(u8),
11350 Port(u16),
11351 CollectMetadata(()),
11352 Remote6(&'a [u8]),
11353 UdpCsum(u8),
11354 UdpZeroCsum6Tx(u8),
11355 UdpZeroCsum6Rx(u8),
11356 Label(u32),
11357 TtlInherit(u8),
11358 Df(u8),
11359 InnerProtoInherit(()),
11360 PortRange(PushIflaGenevePortRange),
11361}
11362impl<'a> IterableLinkinfoGeneveAttrs<'a> {
11363 pub fn get_id(&self) -> Result<u32, ErrorContext> {
11364 let mut iter = self.clone();
11365 iter.pos = 0;
11366 for attr in iter {
11367 if let LinkinfoGeneveAttrs::Id(val) = attr? {
11368 return Ok(val);
11369 }
11370 }
11371 Err(ErrorContext::new_missing(
11372 "LinkinfoGeneveAttrs",
11373 "Id",
11374 self.orig_loc,
11375 self.buf.as_ptr() as usize,
11376 ))
11377 }
11378 pub fn get_remote(&self) -> Result<&'a [u8], ErrorContext> {
11379 let mut iter = self.clone();
11380 iter.pos = 0;
11381 for attr in iter {
11382 if let LinkinfoGeneveAttrs::Remote(val) = attr? {
11383 return Ok(val);
11384 }
11385 }
11386 Err(ErrorContext::new_missing(
11387 "LinkinfoGeneveAttrs",
11388 "Remote",
11389 self.orig_loc,
11390 self.buf.as_ptr() as usize,
11391 ))
11392 }
11393 pub fn get_ttl(&self) -> Result<u8, ErrorContext> {
11394 let mut iter = self.clone();
11395 iter.pos = 0;
11396 for attr in iter {
11397 if let LinkinfoGeneveAttrs::Ttl(val) = attr? {
11398 return Ok(val);
11399 }
11400 }
11401 Err(ErrorContext::new_missing(
11402 "LinkinfoGeneveAttrs",
11403 "Ttl",
11404 self.orig_loc,
11405 self.buf.as_ptr() as usize,
11406 ))
11407 }
11408 pub fn get_tos(&self) -> Result<u8, ErrorContext> {
11409 let mut iter = self.clone();
11410 iter.pos = 0;
11411 for attr in iter {
11412 if let LinkinfoGeneveAttrs::Tos(val) = attr? {
11413 return Ok(val);
11414 }
11415 }
11416 Err(ErrorContext::new_missing(
11417 "LinkinfoGeneveAttrs",
11418 "Tos",
11419 self.orig_loc,
11420 self.buf.as_ptr() as usize,
11421 ))
11422 }
11423 pub fn get_port(&self) -> Result<u16, ErrorContext> {
11424 let mut iter = self.clone();
11425 iter.pos = 0;
11426 for attr in iter {
11427 if let LinkinfoGeneveAttrs::Port(val) = attr? {
11428 return Ok(val);
11429 }
11430 }
11431 Err(ErrorContext::new_missing(
11432 "LinkinfoGeneveAttrs",
11433 "Port",
11434 self.orig_loc,
11435 self.buf.as_ptr() as usize,
11436 ))
11437 }
11438 pub fn get_collect_metadata(&self) -> Result<(), ErrorContext> {
11439 let mut iter = self.clone();
11440 iter.pos = 0;
11441 for attr in iter {
11442 if let LinkinfoGeneveAttrs::CollectMetadata(val) = attr? {
11443 return Ok(val);
11444 }
11445 }
11446 Err(ErrorContext::new_missing(
11447 "LinkinfoGeneveAttrs",
11448 "CollectMetadata",
11449 self.orig_loc,
11450 self.buf.as_ptr() as usize,
11451 ))
11452 }
11453 pub fn get_remote6(&self) -> Result<&'a [u8], ErrorContext> {
11454 let mut iter = self.clone();
11455 iter.pos = 0;
11456 for attr in iter {
11457 if let LinkinfoGeneveAttrs::Remote6(val) = attr? {
11458 return Ok(val);
11459 }
11460 }
11461 Err(ErrorContext::new_missing(
11462 "LinkinfoGeneveAttrs",
11463 "Remote6",
11464 self.orig_loc,
11465 self.buf.as_ptr() as usize,
11466 ))
11467 }
11468 pub fn get_udp_csum(&self) -> Result<u8, ErrorContext> {
11469 let mut iter = self.clone();
11470 iter.pos = 0;
11471 for attr in iter {
11472 if let LinkinfoGeneveAttrs::UdpCsum(val) = attr? {
11473 return Ok(val);
11474 }
11475 }
11476 Err(ErrorContext::new_missing(
11477 "LinkinfoGeneveAttrs",
11478 "UdpCsum",
11479 self.orig_loc,
11480 self.buf.as_ptr() as usize,
11481 ))
11482 }
11483 pub fn get_udp_zero_csum6_tx(&self) -> Result<u8, ErrorContext> {
11484 let mut iter = self.clone();
11485 iter.pos = 0;
11486 for attr in iter {
11487 if let LinkinfoGeneveAttrs::UdpZeroCsum6Tx(val) = attr? {
11488 return Ok(val);
11489 }
11490 }
11491 Err(ErrorContext::new_missing(
11492 "LinkinfoGeneveAttrs",
11493 "UdpZeroCsum6Tx",
11494 self.orig_loc,
11495 self.buf.as_ptr() as usize,
11496 ))
11497 }
11498 pub fn get_udp_zero_csum6_rx(&self) -> Result<u8, ErrorContext> {
11499 let mut iter = self.clone();
11500 iter.pos = 0;
11501 for attr in iter {
11502 if let LinkinfoGeneveAttrs::UdpZeroCsum6Rx(val) = attr? {
11503 return Ok(val);
11504 }
11505 }
11506 Err(ErrorContext::new_missing(
11507 "LinkinfoGeneveAttrs",
11508 "UdpZeroCsum6Rx",
11509 self.orig_loc,
11510 self.buf.as_ptr() as usize,
11511 ))
11512 }
11513 pub fn get_label(&self) -> Result<u32, ErrorContext> {
11514 let mut iter = self.clone();
11515 iter.pos = 0;
11516 for attr in iter {
11517 if let LinkinfoGeneveAttrs::Label(val) = attr? {
11518 return Ok(val);
11519 }
11520 }
11521 Err(ErrorContext::new_missing(
11522 "LinkinfoGeneveAttrs",
11523 "Label",
11524 self.orig_loc,
11525 self.buf.as_ptr() as usize,
11526 ))
11527 }
11528 pub fn get_ttl_inherit(&self) -> Result<u8, ErrorContext> {
11529 let mut iter = self.clone();
11530 iter.pos = 0;
11531 for attr in iter {
11532 if let LinkinfoGeneveAttrs::TtlInherit(val) = attr? {
11533 return Ok(val);
11534 }
11535 }
11536 Err(ErrorContext::new_missing(
11537 "LinkinfoGeneveAttrs",
11538 "TtlInherit",
11539 self.orig_loc,
11540 self.buf.as_ptr() as usize,
11541 ))
11542 }
11543 pub fn get_df(&self) -> Result<u8, ErrorContext> {
11544 let mut iter = self.clone();
11545 iter.pos = 0;
11546 for attr in iter {
11547 if let LinkinfoGeneveAttrs::Df(val) = attr? {
11548 return Ok(val);
11549 }
11550 }
11551 Err(ErrorContext::new_missing(
11552 "LinkinfoGeneveAttrs",
11553 "Df",
11554 self.orig_loc,
11555 self.buf.as_ptr() as usize,
11556 ))
11557 }
11558 pub fn get_inner_proto_inherit(&self) -> Result<(), ErrorContext> {
11559 let mut iter = self.clone();
11560 iter.pos = 0;
11561 for attr in iter {
11562 if let LinkinfoGeneveAttrs::InnerProtoInherit(val) = attr? {
11563 return Ok(val);
11564 }
11565 }
11566 Err(ErrorContext::new_missing(
11567 "LinkinfoGeneveAttrs",
11568 "InnerProtoInherit",
11569 self.orig_loc,
11570 self.buf.as_ptr() as usize,
11571 ))
11572 }
11573 pub fn get_port_range(&self) -> Result<PushIflaGenevePortRange, ErrorContext> {
11574 let mut iter = self.clone();
11575 iter.pos = 0;
11576 for attr in iter {
11577 if let LinkinfoGeneveAttrs::PortRange(val) = attr? {
11578 return Ok(val);
11579 }
11580 }
11581 Err(ErrorContext::new_missing(
11582 "LinkinfoGeneveAttrs",
11583 "PortRange",
11584 self.orig_loc,
11585 self.buf.as_ptr() as usize,
11586 ))
11587 }
11588}
11589impl LinkinfoGeneveAttrs<'_> {
11590 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoGeneveAttrs<'a> {
11591 IterableLinkinfoGeneveAttrs::with_loc(buf, buf.as_ptr() as usize)
11592 }
11593 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11594 let res = match r#type {
11595 1u16 => "Id",
11596 2u16 => "Remote",
11597 3u16 => "Ttl",
11598 4u16 => "Tos",
11599 5u16 => "Port",
11600 6u16 => "CollectMetadata",
11601 7u16 => "Remote6",
11602 8u16 => "UdpCsum",
11603 9u16 => "UdpZeroCsum6Tx",
11604 10u16 => "UdpZeroCsum6Rx",
11605 11u16 => "Label",
11606 12u16 => "TtlInherit",
11607 13u16 => "Df",
11608 14u16 => "InnerProtoInherit",
11609 15u16 => "PortRange",
11610 _ => return None,
11611 };
11612 Some(res)
11613 }
11614}
11615#[derive(Clone, Copy, Default)]
11616pub struct IterableLinkinfoGeneveAttrs<'a> {
11617 buf: &'a [u8],
11618 pos: usize,
11619 orig_loc: usize,
11620}
11621impl<'a> IterableLinkinfoGeneveAttrs<'a> {
11622 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11623 Self {
11624 buf,
11625 pos: 0,
11626 orig_loc,
11627 }
11628 }
11629 pub fn get_buf(&self) -> &'a [u8] {
11630 self.buf
11631 }
11632}
11633impl<'a> Iterator for IterableLinkinfoGeneveAttrs<'a> {
11634 type Item = Result<LinkinfoGeneveAttrs<'a>, ErrorContext>;
11635 fn next(&mut self) -> Option<Self::Item> {
11636 if self.buf.len() == self.pos {
11637 return None;
11638 }
11639 let pos = self.pos;
11640 let mut r#type = None;
11641 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
11642 r#type = Some(header.r#type);
11643 let res = match header.r#type {
11644 1u16 => LinkinfoGeneveAttrs::Id({
11645 let res = parse_u32(next);
11646 let Some(val) = res else { break };
11647 val
11648 }),
11649 2u16 => LinkinfoGeneveAttrs::Remote({
11650 let res = Some(next);
11651 let Some(val) = res else { break };
11652 val
11653 }),
11654 3u16 => LinkinfoGeneveAttrs::Ttl({
11655 let res = parse_u8(next);
11656 let Some(val) = res else { break };
11657 val
11658 }),
11659 4u16 => LinkinfoGeneveAttrs::Tos({
11660 let res = parse_u8(next);
11661 let Some(val) = res else { break };
11662 val
11663 }),
11664 5u16 => LinkinfoGeneveAttrs::Port({
11665 let res = parse_be_u16(next);
11666 let Some(val) = res else { break };
11667 val
11668 }),
11669 6u16 => LinkinfoGeneveAttrs::CollectMetadata(()),
11670 7u16 => LinkinfoGeneveAttrs::Remote6({
11671 let res = Some(next);
11672 let Some(val) = res else { break };
11673 val
11674 }),
11675 8u16 => LinkinfoGeneveAttrs::UdpCsum({
11676 let res = parse_u8(next);
11677 let Some(val) = res else { break };
11678 val
11679 }),
11680 9u16 => LinkinfoGeneveAttrs::UdpZeroCsum6Tx({
11681 let res = parse_u8(next);
11682 let Some(val) = res else { break };
11683 val
11684 }),
11685 10u16 => LinkinfoGeneveAttrs::UdpZeroCsum6Rx({
11686 let res = parse_u8(next);
11687 let Some(val) = res else { break };
11688 val
11689 }),
11690 11u16 => LinkinfoGeneveAttrs::Label({
11691 let res = parse_be_u32(next);
11692 let Some(val) = res else { break };
11693 val
11694 }),
11695 12u16 => LinkinfoGeneveAttrs::TtlInherit({
11696 let res = parse_u8(next);
11697 let Some(val) = res else { break };
11698 val
11699 }),
11700 13u16 => LinkinfoGeneveAttrs::Df({
11701 let res = parse_u8(next);
11702 let Some(val) = res else { break };
11703 val
11704 }),
11705 14u16 => LinkinfoGeneveAttrs::InnerProtoInherit(()),
11706 15u16 => LinkinfoGeneveAttrs::PortRange({
11707 let res = PushIflaGenevePortRange::new_from_slice(next);
11708 let Some(val) = res else { break };
11709 val
11710 }),
11711 n => {
11712 if cfg!(any(test, feature = "deny-unknown-attrs")) {
11713 break;
11714 } else {
11715 continue;
11716 }
11717 }
11718 };
11719 return Some(Ok(res));
11720 }
11721 Some(Err(ErrorContext::new(
11722 "LinkinfoGeneveAttrs",
11723 r#type.and_then(|t| LinkinfoGeneveAttrs::attr_from_type(t)),
11724 self.orig_loc,
11725 self.buf.as_ptr().wrapping_add(pos) as usize,
11726 )))
11727 }
11728}
11729impl<'a> std::fmt::Debug for IterableLinkinfoGeneveAttrs<'_> {
11730 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11731 let mut fmt = f.debug_struct("LinkinfoGeneveAttrs");
11732 for attr in self.clone() {
11733 let attr = match attr {
11734 Ok(a) => a,
11735 Err(err) => {
11736 fmt.finish()?;
11737 f.write_str("Err(")?;
11738 err.fmt(f)?;
11739 return f.write_str(")");
11740 }
11741 };
11742 match attr {
11743 LinkinfoGeneveAttrs::Id(val) => fmt.field("Id", &val),
11744 LinkinfoGeneveAttrs::Remote(val) => fmt.field("Remote", &val),
11745 LinkinfoGeneveAttrs::Ttl(val) => fmt.field("Ttl", &val),
11746 LinkinfoGeneveAttrs::Tos(val) => fmt.field("Tos", &val),
11747 LinkinfoGeneveAttrs::Port(val) => fmt.field("Port", &val),
11748 LinkinfoGeneveAttrs::CollectMetadata(val) => fmt.field("CollectMetadata", &val),
11749 LinkinfoGeneveAttrs::Remote6(val) => fmt.field("Remote6", &val),
11750 LinkinfoGeneveAttrs::UdpCsum(val) => fmt.field("UdpCsum", &val),
11751 LinkinfoGeneveAttrs::UdpZeroCsum6Tx(val) => fmt.field("UdpZeroCsum6Tx", &val),
11752 LinkinfoGeneveAttrs::UdpZeroCsum6Rx(val) => fmt.field("UdpZeroCsum6Rx", &val),
11753 LinkinfoGeneveAttrs::Label(val) => fmt.field("Label", &val),
11754 LinkinfoGeneveAttrs::TtlInherit(val) => fmt.field("TtlInherit", &val),
11755 LinkinfoGeneveAttrs::Df(val) => fmt.field("Df", &val),
11756 LinkinfoGeneveAttrs::InnerProtoInherit(val) => fmt.field("InnerProtoInherit", &val),
11757 LinkinfoGeneveAttrs::PortRange(val) => fmt.field("PortRange", &val),
11758 };
11759 }
11760 fmt.finish()
11761 }
11762}
11763impl IterableLinkinfoGeneveAttrs<'_> {
11764 pub fn lookup_attr(
11765 &self,
11766 offset: usize,
11767 missing_type: Option<u16>,
11768 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11769 let mut stack = Vec::new();
11770 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11771 if cur == offset {
11772 stack.push(("LinkinfoGeneveAttrs", offset));
11773 return (
11774 stack,
11775 missing_type.and_then(|t| LinkinfoGeneveAttrs::attr_from_type(t)),
11776 );
11777 }
11778 if cur > offset || cur + self.buf.len() < offset {
11779 return (stack, None);
11780 }
11781 let mut attrs = self.clone();
11782 let mut last_off = cur + attrs.pos;
11783 while let Some(attr) = attrs.next() {
11784 let Ok(attr) = attr else { break };
11785 match attr {
11786 LinkinfoGeneveAttrs::Id(val) => {
11787 if last_off == offset {
11788 stack.push(("Id", last_off));
11789 break;
11790 }
11791 }
11792 LinkinfoGeneveAttrs::Remote(val) => {
11793 if last_off == offset {
11794 stack.push(("Remote", last_off));
11795 break;
11796 }
11797 }
11798 LinkinfoGeneveAttrs::Ttl(val) => {
11799 if last_off == offset {
11800 stack.push(("Ttl", last_off));
11801 break;
11802 }
11803 }
11804 LinkinfoGeneveAttrs::Tos(val) => {
11805 if last_off == offset {
11806 stack.push(("Tos", last_off));
11807 break;
11808 }
11809 }
11810 LinkinfoGeneveAttrs::Port(val) => {
11811 if last_off == offset {
11812 stack.push(("Port", last_off));
11813 break;
11814 }
11815 }
11816 LinkinfoGeneveAttrs::CollectMetadata(val) => {
11817 if last_off == offset {
11818 stack.push(("CollectMetadata", last_off));
11819 break;
11820 }
11821 }
11822 LinkinfoGeneveAttrs::Remote6(val) => {
11823 if last_off == offset {
11824 stack.push(("Remote6", last_off));
11825 break;
11826 }
11827 }
11828 LinkinfoGeneveAttrs::UdpCsum(val) => {
11829 if last_off == offset {
11830 stack.push(("UdpCsum", last_off));
11831 break;
11832 }
11833 }
11834 LinkinfoGeneveAttrs::UdpZeroCsum6Tx(val) => {
11835 if last_off == offset {
11836 stack.push(("UdpZeroCsum6Tx", last_off));
11837 break;
11838 }
11839 }
11840 LinkinfoGeneveAttrs::UdpZeroCsum6Rx(val) => {
11841 if last_off == offset {
11842 stack.push(("UdpZeroCsum6Rx", last_off));
11843 break;
11844 }
11845 }
11846 LinkinfoGeneveAttrs::Label(val) => {
11847 if last_off == offset {
11848 stack.push(("Label", last_off));
11849 break;
11850 }
11851 }
11852 LinkinfoGeneveAttrs::TtlInherit(val) => {
11853 if last_off == offset {
11854 stack.push(("TtlInherit", last_off));
11855 break;
11856 }
11857 }
11858 LinkinfoGeneveAttrs::Df(val) => {
11859 if last_off == offset {
11860 stack.push(("Df", last_off));
11861 break;
11862 }
11863 }
11864 LinkinfoGeneveAttrs::InnerProtoInherit(val) => {
11865 if last_off == offset {
11866 stack.push(("InnerProtoInherit", last_off));
11867 break;
11868 }
11869 }
11870 LinkinfoGeneveAttrs::PortRange(val) => {
11871 if last_off == offset {
11872 stack.push(("PortRange", last_off));
11873 break;
11874 }
11875 }
11876 _ => {}
11877 };
11878 last_off = cur + attrs.pos;
11879 }
11880 if !stack.is_empty() {
11881 stack.push(("LinkinfoGeneveAttrs", cur));
11882 }
11883 (stack, None)
11884 }
11885}
11886#[derive(Clone)]
11887pub enum LinkinfoIptunAttrs<'a> {
11888 Link(u32),
11889 Local(&'a [u8]),
11890 Remote(&'a [u8]),
11891 Ttl(u8),
11892 Tos(u8),
11893 EncapLimit(u8),
11894 Flowinfo(u32),
11895 Flags(u16),
11896 Proto(u8),
11897 Pmtudisc(u8),
11898 _6rdPrefix(&'a [u8]),
11899 _6rdRelayPrefix(&'a [u8]),
11900 _6rdPrefixlen(u16),
11901 _6rdRelayPrefixlen(u16),
11902 EncapType(u16),
11903 EncapFlags(u16),
11904 EncapSport(u16),
11905 EncapDport(u16),
11906 CollectMetadata(()),
11907 Fwmark(u32),
11908}
11909impl<'a> IterableLinkinfoIptunAttrs<'a> {
11910 pub fn get_link(&self) -> Result<u32, ErrorContext> {
11911 let mut iter = self.clone();
11912 iter.pos = 0;
11913 for attr in iter {
11914 if let LinkinfoIptunAttrs::Link(val) = attr? {
11915 return Ok(val);
11916 }
11917 }
11918 Err(ErrorContext::new_missing(
11919 "LinkinfoIptunAttrs",
11920 "Link",
11921 self.orig_loc,
11922 self.buf.as_ptr() as usize,
11923 ))
11924 }
11925 pub fn get_local(&self) -> Result<&'a [u8], ErrorContext> {
11926 let mut iter = self.clone();
11927 iter.pos = 0;
11928 for attr in iter {
11929 if let LinkinfoIptunAttrs::Local(val) = attr? {
11930 return Ok(val);
11931 }
11932 }
11933 Err(ErrorContext::new_missing(
11934 "LinkinfoIptunAttrs",
11935 "Local",
11936 self.orig_loc,
11937 self.buf.as_ptr() as usize,
11938 ))
11939 }
11940 pub fn get_remote(&self) -> Result<&'a [u8], ErrorContext> {
11941 let mut iter = self.clone();
11942 iter.pos = 0;
11943 for attr in iter {
11944 if let LinkinfoIptunAttrs::Remote(val) = attr? {
11945 return Ok(val);
11946 }
11947 }
11948 Err(ErrorContext::new_missing(
11949 "LinkinfoIptunAttrs",
11950 "Remote",
11951 self.orig_loc,
11952 self.buf.as_ptr() as usize,
11953 ))
11954 }
11955 pub fn get_ttl(&self) -> Result<u8, ErrorContext> {
11956 let mut iter = self.clone();
11957 iter.pos = 0;
11958 for attr in iter {
11959 if let LinkinfoIptunAttrs::Ttl(val) = attr? {
11960 return Ok(val);
11961 }
11962 }
11963 Err(ErrorContext::new_missing(
11964 "LinkinfoIptunAttrs",
11965 "Ttl",
11966 self.orig_loc,
11967 self.buf.as_ptr() as usize,
11968 ))
11969 }
11970 pub fn get_tos(&self) -> Result<u8, ErrorContext> {
11971 let mut iter = self.clone();
11972 iter.pos = 0;
11973 for attr in iter {
11974 if let LinkinfoIptunAttrs::Tos(val) = attr? {
11975 return Ok(val);
11976 }
11977 }
11978 Err(ErrorContext::new_missing(
11979 "LinkinfoIptunAttrs",
11980 "Tos",
11981 self.orig_loc,
11982 self.buf.as_ptr() as usize,
11983 ))
11984 }
11985 pub fn get_encap_limit(&self) -> Result<u8, ErrorContext> {
11986 let mut iter = self.clone();
11987 iter.pos = 0;
11988 for attr in iter {
11989 if let LinkinfoIptunAttrs::EncapLimit(val) = attr? {
11990 return Ok(val);
11991 }
11992 }
11993 Err(ErrorContext::new_missing(
11994 "LinkinfoIptunAttrs",
11995 "EncapLimit",
11996 self.orig_loc,
11997 self.buf.as_ptr() as usize,
11998 ))
11999 }
12000 pub fn get_flowinfo(&self) -> Result<u32, ErrorContext> {
12001 let mut iter = self.clone();
12002 iter.pos = 0;
12003 for attr in iter {
12004 if let LinkinfoIptunAttrs::Flowinfo(val) = attr? {
12005 return Ok(val);
12006 }
12007 }
12008 Err(ErrorContext::new_missing(
12009 "LinkinfoIptunAttrs",
12010 "Flowinfo",
12011 self.orig_loc,
12012 self.buf.as_ptr() as usize,
12013 ))
12014 }
12015 pub fn get_flags(&self) -> Result<u16, ErrorContext> {
12016 let mut iter = self.clone();
12017 iter.pos = 0;
12018 for attr in iter {
12019 if let LinkinfoIptunAttrs::Flags(val) = attr? {
12020 return Ok(val);
12021 }
12022 }
12023 Err(ErrorContext::new_missing(
12024 "LinkinfoIptunAttrs",
12025 "Flags",
12026 self.orig_loc,
12027 self.buf.as_ptr() as usize,
12028 ))
12029 }
12030 pub fn get_proto(&self) -> Result<u8, ErrorContext> {
12031 let mut iter = self.clone();
12032 iter.pos = 0;
12033 for attr in iter {
12034 if let LinkinfoIptunAttrs::Proto(val) = attr? {
12035 return Ok(val);
12036 }
12037 }
12038 Err(ErrorContext::new_missing(
12039 "LinkinfoIptunAttrs",
12040 "Proto",
12041 self.orig_loc,
12042 self.buf.as_ptr() as usize,
12043 ))
12044 }
12045 pub fn get_pmtudisc(&self) -> Result<u8, ErrorContext> {
12046 let mut iter = self.clone();
12047 iter.pos = 0;
12048 for attr in iter {
12049 if let LinkinfoIptunAttrs::Pmtudisc(val) = attr? {
12050 return Ok(val);
12051 }
12052 }
12053 Err(ErrorContext::new_missing(
12054 "LinkinfoIptunAttrs",
12055 "Pmtudisc",
12056 self.orig_loc,
12057 self.buf.as_ptr() as usize,
12058 ))
12059 }
12060 pub fn get_6rd_prefix(&self) -> Result<&'a [u8], ErrorContext> {
12061 let mut iter = self.clone();
12062 iter.pos = 0;
12063 for attr in iter {
12064 if let LinkinfoIptunAttrs::_6rdPrefix(val) = attr? {
12065 return Ok(val);
12066 }
12067 }
12068 Err(ErrorContext::new_missing(
12069 "LinkinfoIptunAttrs",
12070 "6rdPrefix",
12071 self.orig_loc,
12072 self.buf.as_ptr() as usize,
12073 ))
12074 }
12075 pub fn get_6rd_relay_prefix(&self) -> Result<&'a [u8], ErrorContext> {
12076 let mut iter = self.clone();
12077 iter.pos = 0;
12078 for attr in iter {
12079 if let LinkinfoIptunAttrs::_6rdRelayPrefix(val) = attr? {
12080 return Ok(val);
12081 }
12082 }
12083 Err(ErrorContext::new_missing(
12084 "LinkinfoIptunAttrs",
12085 "6rdRelayPrefix",
12086 self.orig_loc,
12087 self.buf.as_ptr() as usize,
12088 ))
12089 }
12090 pub fn get_6rd_prefixlen(&self) -> Result<u16, ErrorContext> {
12091 let mut iter = self.clone();
12092 iter.pos = 0;
12093 for attr in iter {
12094 if let LinkinfoIptunAttrs::_6rdPrefixlen(val) = attr? {
12095 return Ok(val);
12096 }
12097 }
12098 Err(ErrorContext::new_missing(
12099 "LinkinfoIptunAttrs",
12100 "6rdPrefixlen",
12101 self.orig_loc,
12102 self.buf.as_ptr() as usize,
12103 ))
12104 }
12105 pub fn get_6rd_relay_prefixlen(&self) -> Result<u16, ErrorContext> {
12106 let mut iter = self.clone();
12107 iter.pos = 0;
12108 for attr in iter {
12109 if let LinkinfoIptunAttrs::_6rdRelayPrefixlen(val) = attr? {
12110 return Ok(val);
12111 }
12112 }
12113 Err(ErrorContext::new_missing(
12114 "LinkinfoIptunAttrs",
12115 "6rdRelayPrefixlen",
12116 self.orig_loc,
12117 self.buf.as_ptr() as usize,
12118 ))
12119 }
12120 pub fn get_encap_type(&self) -> Result<u16, ErrorContext> {
12121 let mut iter = self.clone();
12122 iter.pos = 0;
12123 for attr in iter {
12124 if let LinkinfoIptunAttrs::EncapType(val) = attr? {
12125 return Ok(val);
12126 }
12127 }
12128 Err(ErrorContext::new_missing(
12129 "LinkinfoIptunAttrs",
12130 "EncapType",
12131 self.orig_loc,
12132 self.buf.as_ptr() as usize,
12133 ))
12134 }
12135 pub fn get_encap_flags(&self) -> Result<u16, ErrorContext> {
12136 let mut iter = self.clone();
12137 iter.pos = 0;
12138 for attr in iter {
12139 if let LinkinfoIptunAttrs::EncapFlags(val) = attr? {
12140 return Ok(val);
12141 }
12142 }
12143 Err(ErrorContext::new_missing(
12144 "LinkinfoIptunAttrs",
12145 "EncapFlags",
12146 self.orig_loc,
12147 self.buf.as_ptr() as usize,
12148 ))
12149 }
12150 pub fn get_encap_sport(&self) -> Result<u16, ErrorContext> {
12151 let mut iter = self.clone();
12152 iter.pos = 0;
12153 for attr in iter {
12154 if let LinkinfoIptunAttrs::EncapSport(val) = attr? {
12155 return Ok(val);
12156 }
12157 }
12158 Err(ErrorContext::new_missing(
12159 "LinkinfoIptunAttrs",
12160 "EncapSport",
12161 self.orig_loc,
12162 self.buf.as_ptr() as usize,
12163 ))
12164 }
12165 pub fn get_encap_dport(&self) -> Result<u16, ErrorContext> {
12166 let mut iter = self.clone();
12167 iter.pos = 0;
12168 for attr in iter {
12169 if let LinkinfoIptunAttrs::EncapDport(val) = attr? {
12170 return Ok(val);
12171 }
12172 }
12173 Err(ErrorContext::new_missing(
12174 "LinkinfoIptunAttrs",
12175 "EncapDport",
12176 self.orig_loc,
12177 self.buf.as_ptr() as usize,
12178 ))
12179 }
12180 pub fn get_collect_metadata(&self) -> Result<(), ErrorContext> {
12181 let mut iter = self.clone();
12182 iter.pos = 0;
12183 for attr in iter {
12184 if let LinkinfoIptunAttrs::CollectMetadata(val) = attr? {
12185 return Ok(val);
12186 }
12187 }
12188 Err(ErrorContext::new_missing(
12189 "LinkinfoIptunAttrs",
12190 "CollectMetadata",
12191 self.orig_loc,
12192 self.buf.as_ptr() as usize,
12193 ))
12194 }
12195 pub fn get_fwmark(&self) -> Result<u32, ErrorContext> {
12196 let mut iter = self.clone();
12197 iter.pos = 0;
12198 for attr in iter {
12199 if let LinkinfoIptunAttrs::Fwmark(val) = attr? {
12200 return Ok(val);
12201 }
12202 }
12203 Err(ErrorContext::new_missing(
12204 "LinkinfoIptunAttrs",
12205 "Fwmark",
12206 self.orig_loc,
12207 self.buf.as_ptr() as usize,
12208 ))
12209 }
12210}
12211impl LinkinfoIptunAttrs<'_> {
12212 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoIptunAttrs<'a> {
12213 IterableLinkinfoIptunAttrs::with_loc(buf, buf.as_ptr() as usize)
12214 }
12215 fn attr_from_type(r#type: u16) -> Option<&'static str> {
12216 let res = match r#type {
12217 1u16 => "Link",
12218 2u16 => "Local",
12219 3u16 => "Remote",
12220 4u16 => "Ttl",
12221 5u16 => "Tos",
12222 6u16 => "EncapLimit",
12223 7u16 => "Flowinfo",
12224 8u16 => "Flags",
12225 9u16 => "Proto",
12226 10u16 => "Pmtudisc",
12227 11u16 => "6rdPrefix",
12228 12u16 => "6rdRelayPrefix",
12229 13u16 => "6rdPrefixlen",
12230 14u16 => "6rdRelayPrefixlen",
12231 15u16 => "EncapType",
12232 16u16 => "EncapFlags",
12233 17u16 => "EncapSport",
12234 18u16 => "EncapDport",
12235 19u16 => "CollectMetadata",
12236 20u16 => "Fwmark",
12237 _ => return None,
12238 };
12239 Some(res)
12240 }
12241}
12242#[derive(Clone, Copy, Default)]
12243pub struct IterableLinkinfoIptunAttrs<'a> {
12244 buf: &'a [u8],
12245 pos: usize,
12246 orig_loc: usize,
12247}
12248impl<'a> IterableLinkinfoIptunAttrs<'a> {
12249 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
12250 Self {
12251 buf,
12252 pos: 0,
12253 orig_loc,
12254 }
12255 }
12256 pub fn get_buf(&self) -> &'a [u8] {
12257 self.buf
12258 }
12259}
12260impl<'a> Iterator for IterableLinkinfoIptunAttrs<'a> {
12261 type Item = Result<LinkinfoIptunAttrs<'a>, ErrorContext>;
12262 fn next(&mut self) -> Option<Self::Item> {
12263 if self.buf.len() == self.pos {
12264 return None;
12265 }
12266 let pos = self.pos;
12267 let mut r#type = None;
12268 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
12269 r#type = Some(header.r#type);
12270 let res = match header.r#type {
12271 1u16 => LinkinfoIptunAttrs::Link({
12272 let res = parse_u32(next);
12273 let Some(val) = res else { break };
12274 val
12275 }),
12276 2u16 => LinkinfoIptunAttrs::Local({
12277 let res = Some(next);
12278 let Some(val) = res else { break };
12279 val
12280 }),
12281 3u16 => LinkinfoIptunAttrs::Remote({
12282 let res = Some(next);
12283 let Some(val) = res else { break };
12284 val
12285 }),
12286 4u16 => LinkinfoIptunAttrs::Ttl({
12287 let res = parse_u8(next);
12288 let Some(val) = res else { break };
12289 val
12290 }),
12291 5u16 => LinkinfoIptunAttrs::Tos({
12292 let res = parse_u8(next);
12293 let Some(val) = res else { break };
12294 val
12295 }),
12296 6u16 => LinkinfoIptunAttrs::EncapLimit({
12297 let res = parse_u8(next);
12298 let Some(val) = res else { break };
12299 val
12300 }),
12301 7u16 => LinkinfoIptunAttrs::Flowinfo({
12302 let res = parse_be_u32(next);
12303 let Some(val) = res else { break };
12304 val
12305 }),
12306 8u16 => LinkinfoIptunAttrs::Flags({
12307 let res = parse_be_u16(next);
12308 let Some(val) = res else { break };
12309 val
12310 }),
12311 9u16 => LinkinfoIptunAttrs::Proto({
12312 let res = parse_u8(next);
12313 let Some(val) = res else { break };
12314 val
12315 }),
12316 10u16 => LinkinfoIptunAttrs::Pmtudisc({
12317 let res = parse_u8(next);
12318 let Some(val) = res else { break };
12319 val
12320 }),
12321 11u16 => LinkinfoIptunAttrs::_6rdPrefix({
12322 let res = Some(next);
12323 let Some(val) = res else { break };
12324 val
12325 }),
12326 12u16 => LinkinfoIptunAttrs::_6rdRelayPrefix({
12327 let res = Some(next);
12328 let Some(val) = res else { break };
12329 val
12330 }),
12331 13u16 => LinkinfoIptunAttrs::_6rdPrefixlen({
12332 let res = parse_u16(next);
12333 let Some(val) = res else { break };
12334 val
12335 }),
12336 14u16 => LinkinfoIptunAttrs::_6rdRelayPrefixlen({
12337 let res = parse_u16(next);
12338 let Some(val) = res else { break };
12339 val
12340 }),
12341 15u16 => LinkinfoIptunAttrs::EncapType({
12342 let res = parse_u16(next);
12343 let Some(val) = res else { break };
12344 val
12345 }),
12346 16u16 => LinkinfoIptunAttrs::EncapFlags({
12347 let res = parse_u16(next);
12348 let Some(val) = res else { break };
12349 val
12350 }),
12351 17u16 => LinkinfoIptunAttrs::EncapSport({
12352 let res = parse_be_u16(next);
12353 let Some(val) = res else { break };
12354 val
12355 }),
12356 18u16 => LinkinfoIptunAttrs::EncapDport({
12357 let res = parse_be_u16(next);
12358 let Some(val) = res else { break };
12359 val
12360 }),
12361 19u16 => LinkinfoIptunAttrs::CollectMetadata(()),
12362 20u16 => LinkinfoIptunAttrs::Fwmark({
12363 let res = parse_u32(next);
12364 let Some(val) = res else { break };
12365 val
12366 }),
12367 n => {
12368 if cfg!(any(test, feature = "deny-unknown-attrs")) {
12369 break;
12370 } else {
12371 continue;
12372 }
12373 }
12374 };
12375 return Some(Ok(res));
12376 }
12377 Some(Err(ErrorContext::new(
12378 "LinkinfoIptunAttrs",
12379 r#type.and_then(|t| LinkinfoIptunAttrs::attr_from_type(t)),
12380 self.orig_loc,
12381 self.buf.as_ptr().wrapping_add(pos) as usize,
12382 )))
12383 }
12384}
12385impl<'a> std::fmt::Debug for IterableLinkinfoIptunAttrs<'_> {
12386 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12387 let mut fmt = f.debug_struct("LinkinfoIptunAttrs");
12388 for attr in self.clone() {
12389 let attr = match attr {
12390 Ok(a) => a,
12391 Err(err) => {
12392 fmt.finish()?;
12393 f.write_str("Err(")?;
12394 err.fmt(f)?;
12395 return f.write_str(")");
12396 }
12397 };
12398 match attr {
12399 LinkinfoIptunAttrs::Link(val) => fmt.field("Link", &val),
12400 LinkinfoIptunAttrs::Local(val) => fmt.field("Local", &val),
12401 LinkinfoIptunAttrs::Remote(val) => fmt.field("Remote", &val),
12402 LinkinfoIptunAttrs::Ttl(val) => fmt.field("Ttl", &val),
12403 LinkinfoIptunAttrs::Tos(val) => fmt.field("Tos", &val),
12404 LinkinfoIptunAttrs::EncapLimit(val) => fmt.field("EncapLimit", &val),
12405 LinkinfoIptunAttrs::Flowinfo(val) => fmt.field("Flowinfo", &val),
12406 LinkinfoIptunAttrs::Flags(val) => fmt.field("Flags", &val),
12407 LinkinfoIptunAttrs::Proto(val) => fmt.field("Proto", &val),
12408 LinkinfoIptunAttrs::Pmtudisc(val) => fmt.field("Pmtudisc", &val),
12409 LinkinfoIptunAttrs::_6rdPrefix(val) => fmt.field("_6rdPrefix", &val),
12410 LinkinfoIptunAttrs::_6rdRelayPrefix(val) => fmt.field("_6rdRelayPrefix", &val),
12411 LinkinfoIptunAttrs::_6rdPrefixlen(val) => fmt.field("_6rdPrefixlen", &val),
12412 LinkinfoIptunAttrs::_6rdRelayPrefixlen(val) => {
12413 fmt.field("_6rdRelayPrefixlen", &val)
12414 }
12415 LinkinfoIptunAttrs::EncapType(val) => fmt.field("EncapType", &val),
12416 LinkinfoIptunAttrs::EncapFlags(val) => fmt.field("EncapFlags", &val),
12417 LinkinfoIptunAttrs::EncapSport(val) => fmt.field("EncapSport", &val),
12418 LinkinfoIptunAttrs::EncapDport(val) => fmt.field("EncapDport", &val),
12419 LinkinfoIptunAttrs::CollectMetadata(val) => fmt.field("CollectMetadata", &val),
12420 LinkinfoIptunAttrs::Fwmark(val) => fmt.field("Fwmark", &val),
12421 };
12422 }
12423 fmt.finish()
12424 }
12425}
12426impl IterableLinkinfoIptunAttrs<'_> {
12427 pub fn lookup_attr(
12428 &self,
12429 offset: usize,
12430 missing_type: Option<u16>,
12431 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
12432 let mut stack = Vec::new();
12433 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
12434 if cur == offset {
12435 stack.push(("LinkinfoIptunAttrs", offset));
12436 return (
12437 stack,
12438 missing_type.and_then(|t| LinkinfoIptunAttrs::attr_from_type(t)),
12439 );
12440 }
12441 if cur > offset || cur + self.buf.len() < offset {
12442 return (stack, None);
12443 }
12444 let mut attrs = self.clone();
12445 let mut last_off = cur + attrs.pos;
12446 while let Some(attr) = attrs.next() {
12447 let Ok(attr) = attr else { break };
12448 match attr {
12449 LinkinfoIptunAttrs::Link(val) => {
12450 if last_off == offset {
12451 stack.push(("Link", last_off));
12452 break;
12453 }
12454 }
12455 LinkinfoIptunAttrs::Local(val) => {
12456 if last_off == offset {
12457 stack.push(("Local", last_off));
12458 break;
12459 }
12460 }
12461 LinkinfoIptunAttrs::Remote(val) => {
12462 if last_off == offset {
12463 stack.push(("Remote", last_off));
12464 break;
12465 }
12466 }
12467 LinkinfoIptunAttrs::Ttl(val) => {
12468 if last_off == offset {
12469 stack.push(("Ttl", last_off));
12470 break;
12471 }
12472 }
12473 LinkinfoIptunAttrs::Tos(val) => {
12474 if last_off == offset {
12475 stack.push(("Tos", last_off));
12476 break;
12477 }
12478 }
12479 LinkinfoIptunAttrs::EncapLimit(val) => {
12480 if last_off == offset {
12481 stack.push(("EncapLimit", last_off));
12482 break;
12483 }
12484 }
12485 LinkinfoIptunAttrs::Flowinfo(val) => {
12486 if last_off == offset {
12487 stack.push(("Flowinfo", last_off));
12488 break;
12489 }
12490 }
12491 LinkinfoIptunAttrs::Flags(val) => {
12492 if last_off == offset {
12493 stack.push(("Flags", last_off));
12494 break;
12495 }
12496 }
12497 LinkinfoIptunAttrs::Proto(val) => {
12498 if last_off == offset {
12499 stack.push(("Proto", last_off));
12500 break;
12501 }
12502 }
12503 LinkinfoIptunAttrs::Pmtudisc(val) => {
12504 if last_off == offset {
12505 stack.push(("Pmtudisc", last_off));
12506 break;
12507 }
12508 }
12509 LinkinfoIptunAttrs::_6rdPrefix(val) => {
12510 if last_off == offset {
12511 stack.push(("6rdPrefix", last_off));
12512 break;
12513 }
12514 }
12515 LinkinfoIptunAttrs::_6rdRelayPrefix(val) => {
12516 if last_off == offset {
12517 stack.push(("6rdRelayPrefix", last_off));
12518 break;
12519 }
12520 }
12521 LinkinfoIptunAttrs::_6rdPrefixlen(val) => {
12522 if last_off == offset {
12523 stack.push(("6rdPrefixlen", last_off));
12524 break;
12525 }
12526 }
12527 LinkinfoIptunAttrs::_6rdRelayPrefixlen(val) => {
12528 if last_off == offset {
12529 stack.push(("6rdRelayPrefixlen", last_off));
12530 break;
12531 }
12532 }
12533 LinkinfoIptunAttrs::EncapType(val) => {
12534 if last_off == offset {
12535 stack.push(("EncapType", last_off));
12536 break;
12537 }
12538 }
12539 LinkinfoIptunAttrs::EncapFlags(val) => {
12540 if last_off == offset {
12541 stack.push(("EncapFlags", last_off));
12542 break;
12543 }
12544 }
12545 LinkinfoIptunAttrs::EncapSport(val) => {
12546 if last_off == offset {
12547 stack.push(("EncapSport", last_off));
12548 break;
12549 }
12550 }
12551 LinkinfoIptunAttrs::EncapDport(val) => {
12552 if last_off == offset {
12553 stack.push(("EncapDport", last_off));
12554 break;
12555 }
12556 }
12557 LinkinfoIptunAttrs::CollectMetadata(val) => {
12558 if last_off == offset {
12559 stack.push(("CollectMetadata", last_off));
12560 break;
12561 }
12562 }
12563 LinkinfoIptunAttrs::Fwmark(val) => {
12564 if last_off == offset {
12565 stack.push(("Fwmark", last_off));
12566 break;
12567 }
12568 }
12569 _ => {}
12570 };
12571 last_off = cur + attrs.pos;
12572 }
12573 if !stack.is_empty() {
12574 stack.push(("LinkinfoIptunAttrs", cur));
12575 }
12576 (stack, None)
12577 }
12578}
12579#[derive(Clone)]
12580pub enum LinkinfoIp6tnlAttrs<'a> {
12581 Link(u32),
12582 Local(&'a [u8]),
12583 Remote(&'a [u8]),
12584 Ttl(u8),
12585 EncapLimit(u8),
12586 Flowinfo(u32),
12587 Flags(u32),
12588 Proto(u8),
12589 EncapType(u16),
12590 EncapFlags(u16),
12591 EncapSport(u16),
12592 EncapDport(u16),
12593 CollectMetadata(()),
12594 Fwmark(u32),
12595}
12596impl<'a> IterableLinkinfoIp6tnlAttrs<'a> {
12597 pub fn get_link(&self) -> Result<u32, ErrorContext> {
12598 let mut iter = self.clone();
12599 iter.pos = 0;
12600 for attr in iter {
12601 if let LinkinfoIp6tnlAttrs::Link(val) = attr? {
12602 return Ok(val);
12603 }
12604 }
12605 Err(ErrorContext::new_missing(
12606 "LinkinfoIp6tnlAttrs",
12607 "Link",
12608 self.orig_loc,
12609 self.buf.as_ptr() as usize,
12610 ))
12611 }
12612 pub fn get_local(&self) -> Result<&'a [u8], ErrorContext> {
12613 let mut iter = self.clone();
12614 iter.pos = 0;
12615 for attr in iter {
12616 if let LinkinfoIp6tnlAttrs::Local(val) = attr? {
12617 return Ok(val);
12618 }
12619 }
12620 Err(ErrorContext::new_missing(
12621 "LinkinfoIp6tnlAttrs",
12622 "Local",
12623 self.orig_loc,
12624 self.buf.as_ptr() as usize,
12625 ))
12626 }
12627 pub fn get_remote(&self) -> Result<&'a [u8], ErrorContext> {
12628 let mut iter = self.clone();
12629 iter.pos = 0;
12630 for attr in iter {
12631 if let LinkinfoIp6tnlAttrs::Remote(val) = attr? {
12632 return Ok(val);
12633 }
12634 }
12635 Err(ErrorContext::new_missing(
12636 "LinkinfoIp6tnlAttrs",
12637 "Remote",
12638 self.orig_loc,
12639 self.buf.as_ptr() as usize,
12640 ))
12641 }
12642 pub fn get_ttl(&self) -> Result<u8, ErrorContext> {
12643 let mut iter = self.clone();
12644 iter.pos = 0;
12645 for attr in iter {
12646 if let LinkinfoIp6tnlAttrs::Ttl(val) = attr? {
12647 return Ok(val);
12648 }
12649 }
12650 Err(ErrorContext::new_missing(
12651 "LinkinfoIp6tnlAttrs",
12652 "Ttl",
12653 self.orig_loc,
12654 self.buf.as_ptr() as usize,
12655 ))
12656 }
12657 pub fn get_encap_limit(&self) -> Result<u8, ErrorContext> {
12658 let mut iter = self.clone();
12659 iter.pos = 0;
12660 for attr in iter {
12661 if let LinkinfoIp6tnlAttrs::EncapLimit(val) = attr? {
12662 return Ok(val);
12663 }
12664 }
12665 Err(ErrorContext::new_missing(
12666 "LinkinfoIp6tnlAttrs",
12667 "EncapLimit",
12668 self.orig_loc,
12669 self.buf.as_ptr() as usize,
12670 ))
12671 }
12672 pub fn get_flowinfo(&self) -> Result<u32, ErrorContext> {
12673 let mut iter = self.clone();
12674 iter.pos = 0;
12675 for attr in iter {
12676 if let LinkinfoIp6tnlAttrs::Flowinfo(val) = attr? {
12677 return Ok(val);
12678 }
12679 }
12680 Err(ErrorContext::new_missing(
12681 "LinkinfoIp6tnlAttrs",
12682 "Flowinfo",
12683 self.orig_loc,
12684 self.buf.as_ptr() as usize,
12685 ))
12686 }
12687 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
12688 let mut iter = self.clone();
12689 iter.pos = 0;
12690 for attr in iter {
12691 if let LinkinfoIp6tnlAttrs::Flags(val) = attr? {
12692 return Ok(val);
12693 }
12694 }
12695 Err(ErrorContext::new_missing(
12696 "LinkinfoIp6tnlAttrs",
12697 "Flags",
12698 self.orig_loc,
12699 self.buf.as_ptr() as usize,
12700 ))
12701 }
12702 pub fn get_proto(&self) -> Result<u8, ErrorContext> {
12703 let mut iter = self.clone();
12704 iter.pos = 0;
12705 for attr in iter {
12706 if let LinkinfoIp6tnlAttrs::Proto(val) = attr? {
12707 return Ok(val);
12708 }
12709 }
12710 Err(ErrorContext::new_missing(
12711 "LinkinfoIp6tnlAttrs",
12712 "Proto",
12713 self.orig_loc,
12714 self.buf.as_ptr() as usize,
12715 ))
12716 }
12717 pub fn get_encap_type(&self) -> Result<u16, ErrorContext> {
12718 let mut iter = self.clone();
12719 iter.pos = 0;
12720 for attr in iter {
12721 if let LinkinfoIp6tnlAttrs::EncapType(val) = attr? {
12722 return Ok(val);
12723 }
12724 }
12725 Err(ErrorContext::new_missing(
12726 "LinkinfoIp6tnlAttrs",
12727 "EncapType",
12728 self.orig_loc,
12729 self.buf.as_ptr() as usize,
12730 ))
12731 }
12732 pub fn get_encap_flags(&self) -> Result<u16, ErrorContext> {
12733 let mut iter = self.clone();
12734 iter.pos = 0;
12735 for attr in iter {
12736 if let LinkinfoIp6tnlAttrs::EncapFlags(val) = attr? {
12737 return Ok(val);
12738 }
12739 }
12740 Err(ErrorContext::new_missing(
12741 "LinkinfoIp6tnlAttrs",
12742 "EncapFlags",
12743 self.orig_loc,
12744 self.buf.as_ptr() as usize,
12745 ))
12746 }
12747 pub fn get_encap_sport(&self) -> Result<u16, ErrorContext> {
12748 let mut iter = self.clone();
12749 iter.pos = 0;
12750 for attr in iter {
12751 if let LinkinfoIp6tnlAttrs::EncapSport(val) = attr? {
12752 return Ok(val);
12753 }
12754 }
12755 Err(ErrorContext::new_missing(
12756 "LinkinfoIp6tnlAttrs",
12757 "EncapSport",
12758 self.orig_loc,
12759 self.buf.as_ptr() as usize,
12760 ))
12761 }
12762 pub fn get_encap_dport(&self) -> Result<u16, ErrorContext> {
12763 let mut iter = self.clone();
12764 iter.pos = 0;
12765 for attr in iter {
12766 if let LinkinfoIp6tnlAttrs::EncapDport(val) = attr? {
12767 return Ok(val);
12768 }
12769 }
12770 Err(ErrorContext::new_missing(
12771 "LinkinfoIp6tnlAttrs",
12772 "EncapDport",
12773 self.orig_loc,
12774 self.buf.as_ptr() as usize,
12775 ))
12776 }
12777 pub fn get_collect_metadata(&self) -> Result<(), ErrorContext> {
12778 let mut iter = self.clone();
12779 iter.pos = 0;
12780 for attr in iter {
12781 if let LinkinfoIp6tnlAttrs::CollectMetadata(val) = attr? {
12782 return Ok(val);
12783 }
12784 }
12785 Err(ErrorContext::new_missing(
12786 "LinkinfoIp6tnlAttrs",
12787 "CollectMetadata",
12788 self.orig_loc,
12789 self.buf.as_ptr() as usize,
12790 ))
12791 }
12792 pub fn get_fwmark(&self) -> Result<u32, ErrorContext> {
12793 let mut iter = self.clone();
12794 iter.pos = 0;
12795 for attr in iter {
12796 if let LinkinfoIp6tnlAttrs::Fwmark(val) = attr? {
12797 return Ok(val);
12798 }
12799 }
12800 Err(ErrorContext::new_missing(
12801 "LinkinfoIp6tnlAttrs",
12802 "Fwmark",
12803 self.orig_loc,
12804 self.buf.as_ptr() as usize,
12805 ))
12806 }
12807}
12808impl LinkinfoIp6tnlAttrs<'_> {
12809 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoIp6tnlAttrs<'a> {
12810 IterableLinkinfoIp6tnlAttrs::with_loc(buf, buf.as_ptr() as usize)
12811 }
12812 fn attr_from_type(r#type: u16) -> Option<&'static str> {
12813 LinkinfoIptunAttrs::attr_from_type(r#type)
12814 }
12815}
12816#[derive(Clone, Copy, Default)]
12817pub struct IterableLinkinfoIp6tnlAttrs<'a> {
12818 buf: &'a [u8],
12819 pos: usize,
12820 orig_loc: usize,
12821}
12822impl<'a> IterableLinkinfoIp6tnlAttrs<'a> {
12823 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
12824 Self {
12825 buf,
12826 pos: 0,
12827 orig_loc,
12828 }
12829 }
12830 pub fn get_buf(&self) -> &'a [u8] {
12831 self.buf
12832 }
12833}
12834impl<'a> Iterator for IterableLinkinfoIp6tnlAttrs<'a> {
12835 type Item = Result<LinkinfoIp6tnlAttrs<'a>, ErrorContext>;
12836 fn next(&mut self) -> Option<Self::Item> {
12837 if self.buf.len() == self.pos {
12838 return None;
12839 }
12840 let pos = self.pos;
12841 let mut r#type = None;
12842 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
12843 r#type = Some(header.r#type);
12844 let res = match header.r#type {
12845 1u16 => LinkinfoIp6tnlAttrs::Link({
12846 let res = parse_u32(next);
12847 let Some(val) = res else { break };
12848 val
12849 }),
12850 2u16 => LinkinfoIp6tnlAttrs::Local({
12851 let res = Some(next);
12852 let Some(val) = res else { break };
12853 val
12854 }),
12855 3u16 => LinkinfoIp6tnlAttrs::Remote({
12856 let res = Some(next);
12857 let Some(val) = res else { break };
12858 val
12859 }),
12860 4u16 => LinkinfoIp6tnlAttrs::Ttl({
12861 let res = parse_u8(next);
12862 let Some(val) = res else { break };
12863 val
12864 }),
12865 6u16 => LinkinfoIp6tnlAttrs::EncapLimit({
12866 let res = parse_u8(next);
12867 let Some(val) = res else { break };
12868 val
12869 }),
12870 7u16 => LinkinfoIp6tnlAttrs::Flowinfo({
12871 let res = parse_be_u32(next);
12872 let Some(val) = res else { break };
12873 val
12874 }),
12875 8u16 => LinkinfoIp6tnlAttrs::Flags({
12876 let res = parse_be_u32(next);
12877 let Some(val) = res else { break };
12878 val
12879 }),
12880 9u16 => LinkinfoIp6tnlAttrs::Proto({
12881 let res = parse_u8(next);
12882 let Some(val) = res else { break };
12883 val
12884 }),
12885 15u16 => LinkinfoIp6tnlAttrs::EncapType({
12886 let res = parse_u16(next);
12887 let Some(val) = res else { break };
12888 val
12889 }),
12890 16u16 => LinkinfoIp6tnlAttrs::EncapFlags({
12891 let res = parse_u16(next);
12892 let Some(val) = res else { break };
12893 val
12894 }),
12895 17u16 => LinkinfoIp6tnlAttrs::EncapSport({
12896 let res = parse_be_u16(next);
12897 let Some(val) = res else { break };
12898 val
12899 }),
12900 18u16 => LinkinfoIp6tnlAttrs::EncapDport({
12901 let res = parse_be_u16(next);
12902 let Some(val) = res else { break };
12903 val
12904 }),
12905 19u16 => LinkinfoIp6tnlAttrs::CollectMetadata(()),
12906 20u16 => LinkinfoIp6tnlAttrs::Fwmark({
12907 let res = parse_u32(next);
12908 let Some(val) = res else { break };
12909 val
12910 }),
12911 n => {
12912 if cfg!(any(test, feature = "deny-unknown-attrs")) {
12913 break;
12914 } else {
12915 continue;
12916 }
12917 }
12918 };
12919 return Some(Ok(res));
12920 }
12921 Some(Err(ErrorContext::new(
12922 "LinkinfoIp6tnlAttrs",
12923 r#type.and_then(|t| LinkinfoIp6tnlAttrs::attr_from_type(t)),
12924 self.orig_loc,
12925 self.buf.as_ptr().wrapping_add(pos) as usize,
12926 )))
12927 }
12928}
12929impl<'a> std::fmt::Debug for IterableLinkinfoIp6tnlAttrs<'_> {
12930 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12931 let mut fmt = f.debug_struct("LinkinfoIp6tnlAttrs");
12932 for attr in self.clone() {
12933 let attr = match attr {
12934 Ok(a) => a,
12935 Err(err) => {
12936 fmt.finish()?;
12937 f.write_str("Err(")?;
12938 err.fmt(f)?;
12939 return f.write_str(")");
12940 }
12941 };
12942 match attr {
12943 LinkinfoIp6tnlAttrs::Link(val) => fmt.field("Link", &val),
12944 LinkinfoIp6tnlAttrs::Local(val) => fmt.field("Local", &val),
12945 LinkinfoIp6tnlAttrs::Remote(val) => fmt.field("Remote", &val),
12946 LinkinfoIp6tnlAttrs::Ttl(val) => fmt.field("Ttl", &val),
12947 LinkinfoIp6tnlAttrs::EncapLimit(val) => fmt.field("EncapLimit", &val),
12948 LinkinfoIp6tnlAttrs::Flowinfo(val) => fmt.field("Flowinfo", &val),
12949 LinkinfoIp6tnlAttrs::Flags(val) => fmt.field("Flags", &val),
12950 LinkinfoIp6tnlAttrs::Proto(val) => fmt.field("Proto", &val),
12951 LinkinfoIp6tnlAttrs::EncapType(val) => fmt.field("EncapType", &val),
12952 LinkinfoIp6tnlAttrs::EncapFlags(val) => fmt.field("EncapFlags", &val),
12953 LinkinfoIp6tnlAttrs::EncapSport(val) => fmt.field("EncapSport", &val),
12954 LinkinfoIp6tnlAttrs::EncapDport(val) => fmt.field("EncapDport", &val),
12955 LinkinfoIp6tnlAttrs::CollectMetadata(val) => fmt.field("CollectMetadata", &val),
12956 LinkinfoIp6tnlAttrs::Fwmark(val) => fmt.field("Fwmark", &val),
12957 };
12958 }
12959 fmt.finish()
12960 }
12961}
12962impl IterableLinkinfoIp6tnlAttrs<'_> {
12963 pub fn lookup_attr(
12964 &self,
12965 offset: usize,
12966 missing_type: Option<u16>,
12967 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
12968 let mut stack = Vec::new();
12969 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
12970 if cur == offset {
12971 stack.push(("LinkinfoIp6tnlAttrs", offset));
12972 return (
12973 stack,
12974 missing_type.and_then(|t| LinkinfoIp6tnlAttrs::attr_from_type(t)),
12975 );
12976 }
12977 if cur > offset || cur + self.buf.len() < offset {
12978 return (stack, None);
12979 }
12980 let mut attrs = self.clone();
12981 let mut last_off = cur + attrs.pos;
12982 while let Some(attr) = attrs.next() {
12983 let Ok(attr) = attr else { break };
12984 match attr {
12985 LinkinfoIp6tnlAttrs::Link(val) => {
12986 if last_off == offset {
12987 stack.push(("Link", last_off));
12988 break;
12989 }
12990 }
12991 LinkinfoIp6tnlAttrs::Local(val) => {
12992 if last_off == offset {
12993 stack.push(("Local", last_off));
12994 break;
12995 }
12996 }
12997 LinkinfoIp6tnlAttrs::Remote(val) => {
12998 if last_off == offset {
12999 stack.push(("Remote", last_off));
13000 break;
13001 }
13002 }
13003 LinkinfoIp6tnlAttrs::Ttl(val) => {
13004 if last_off == offset {
13005 stack.push(("Ttl", last_off));
13006 break;
13007 }
13008 }
13009 LinkinfoIp6tnlAttrs::EncapLimit(val) => {
13010 if last_off == offset {
13011 stack.push(("EncapLimit", last_off));
13012 break;
13013 }
13014 }
13015 LinkinfoIp6tnlAttrs::Flowinfo(val) => {
13016 if last_off == offset {
13017 stack.push(("Flowinfo", last_off));
13018 break;
13019 }
13020 }
13021 LinkinfoIp6tnlAttrs::Flags(val) => {
13022 if last_off == offset {
13023 stack.push(("Flags", last_off));
13024 break;
13025 }
13026 }
13027 LinkinfoIp6tnlAttrs::Proto(val) => {
13028 if last_off == offset {
13029 stack.push(("Proto", last_off));
13030 break;
13031 }
13032 }
13033 LinkinfoIp6tnlAttrs::EncapType(val) => {
13034 if last_off == offset {
13035 stack.push(("EncapType", last_off));
13036 break;
13037 }
13038 }
13039 LinkinfoIp6tnlAttrs::EncapFlags(val) => {
13040 if last_off == offset {
13041 stack.push(("EncapFlags", last_off));
13042 break;
13043 }
13044 }
13045 LinkinfoIp6tnlAttrs::EncapSport(val) => {
13046 if last_off == offset {
13047 stack.push(("EncapSport", last_off));
13048 break;
13049 }
13050 }
13051 LinkinfoIp6tnlAttrs::EncapDport(val) => {
13052 if last_off == offset {
13053 stack.push(("EncapDport", last_off));
13054 break;
13055 }
13056 }
13057 LinkinfoIp6tnlAttrs::CollectMetadata(val) => {
13058 if last_off == offset {
13059 stack.push(("CollectMetadata", last_off));
13060 break;
13061 }
13062 }
13063 LinkinfoIp6tnlAttrs::Fwmark(val) => {
13064 if last_off == offset {
13065 stack.push(("Fwmark", last_off));
13066 break;
13067 }
13068 }
13069 _ => {}
13070 };
13071 last_off = cur + attrs.pos;
13072 }
13073 if !stack.is_empty() {
13074 stack.push(("LinkinfoIp6tnlAttrs", cur));
13075 }
13076 (stack, None)
13077 }
13078}
13079#[derive(Clone)]
13080pub enum LinkinfoTunAttrs {
13081 Owner(u32),
13082 Group(u32),
13083 Type(u8),
13084 Pi(u8),
13085 VnetHdr(u8),
13086 Persist(u8),
13087 MultiQueue(u8),
13088 NumQueues(u32),
13089 NumDisabledQueues(u32),
13090}
13091impl<'a> IterableLinkinfoTunAttrs<'a> {
13092 pub fn get_owner(&self) -> Result<u32, ErrorContext> {
13093 let mut iter = self.clone();
13094 iter.pos = 0;
13095 for attr in iter {
13096 if let LinkinfoTunAttrs::Owner(val) = attr? {
13097 return Ok(val);
13098 }
13099 }
13100 Err(ErrorContext::new_missing(
13101 "LinkinfoTunAttrs",
13102 "Owner",
13103 self.orig_loc,
13104 self.buf.as_ptr() as usize,
13105 ))
13106 }
13107 pub fn get_group(&self) -> Result<u32, ErrorContext> {
13108 let mut iter = self.clone();
13109 iter.pos = 0;
13110 for attr in iter {
13111 if let LinkinfoTunAttrs::Group(val) = attr? {
13112 return Ok(val);
13113 }
13114 }
13115 Err(ErrorContext::new_missing(
13116 "LinkinfoTunAttrs",
13117 "Group",
13118 self.orig_loc,
13119 self.buf.as_ptr() as usize,
13120 ))
13121 }
13122 pub fn get_type(&self) -> Result<u8, ErrorContext> {
13123 let mut iter = self.clone();
13124 iter.pos = 0;
13125 for attr in iter {
13126 if let LinkinfoTunAttrs::Type(val) = attr? {
13127 return Ok(val);
13128 }
13129 }
13130 Err(ErrorContext::new_missing(
13131 "LinkinfoTunAttrs",
13132 "Type",
13133 self.orig_loc,
13134 self.buf.as_ptr() as usize,
13135 ))
13136 }
13137 pub fn get_pi(&self) -> Result<u8, ErrorContext> {
13138 let mut iter = self.clone();
13139 iter.pos = 0;
13140 for attr in iter {
13141 if let LinkinfoTunAttrs::Pi(val) = attr? {
13142 return Ok(val);
13143 }
13144 }
13145 Err(ErrorContext::new_missing(
13146 "LinkinfoTunAttrs",
13147 "Pi",
13148 self.orig_loc,
13149 self.buf.as_ptr() as usize,
13150 ))
13151 }
13152 pub fn get_vnet_hdr(&self) -> Result<u8, ErrorContext> {
13153 let mut iter = self.clone();
13154 iter.pos = 0;
13155 for attr in iter {
13156 if let LinkinfoTunAttrs::VnetHdr(val) = attr? {
13157 return Ok(val);
13158 }
13159 }
13160 Err(ErrorContext::new_missing(
13161 "LinkinfoTunAttrs",
13162 "VnetHdr",
13163 self.orig_loc,
13164 self.buf.as_ptr() as usize,
13165 ))
13166 }
13167 pub fn get_persist(&self) -> Result<u8, ErrorContext> {
13168 let mut iter = self.clone();
13169 iter.pos = 0;
13170 for attr in iter {
13171 if let LinkinfoTunAttrs::Persist(val) = attr? {
13172 return Ok(val);
13173 }
13174 }
13175 Err(ErrorContext::new_missing(
13176 "LinkinfoTunAttrs",
13177 "Persist",
13178 self.orig_loc,
13179 self.buf.as_ptr() as usize,
13180 ))
13181 }
13182 pub fn get_multi_queue(&self) -> Result<u8, ErrorContext> {
13183 let mut iter = self.clone();
13184 iter.pos = 0;
13185 for attr in iter {
13186 if let LinkinfoTunAttrs::MultiQueue(val) = attr? {
13187 return Ok(val);
13188 }
13189 }
13190 Err(ErrorContext::new_missing(
13191 "LinkinfoTunAttrs",
13192 "MultiQueue",
13193 self.orig_loc,
13194 self.buf.as_ptr() as usize,
13195 ))
13196 }
13197 pub fn get_num_queues(&self) -> Result<u32, ErrorContext> {
13198 let mut iter = self.clone();
13199 iter.pos = 0;
13200 for attr in iter {
13201 if let LinkinfoTunAttrs::NumQueues(val) = attr? {
13202 return Ok(val);
13203 }
13204 }
13205 Err(ErrorContext::new_missing(
13206 "LinkinfoTunAttrs",
13207 "NumQueues",
13208 self.orig_loc,
13209 self.buf.as_ptr() as usize,
13210 ))
13211 }
13212 pub fn get_num_disabled_queues(&self) -> Result<u32, ErrorContext> {
13213 let mut iter = self.clone();
13214 iter.pos = 0;
13215 for attr in iter {
13216 if let LinkinfoTunAttrs::NumDisabledQueues(val) = attr? {
13217 return Ok(val);
13218 }
13219 }
13220 Err(ErrorContext::new_missing(
13221 "LinkinfoTunAttrs",
13222 "NumDisabledQueues",
13223 self.orig_loc,
13224 self.buf.as_ptr() as usize,
13225 ))
13226 }
13227}
13228impl LinkinfoTunAttrs {
13229 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoTunAttrs<'a> {
13230 IterableLinkinfoTunAttrs::with_loc(buf, buf.as_ptr() as usize)
13231 }
13232 fn attr_from_type(r#type: u16) -> Option<&'static str> {
13233 let res = match r#type {
13234 1u16 => "Owner",
13235 2u16 => "Group",
13236 3u16 => "Type",
13237 4u16 => "Pi",
13238 5u16 => "VnetHdr",
13239 6u16 => "Persist",
13240 7u16 => "MultiQueue",
13241 8u16 => "NumQueues",
13242 9u16 => "NumDisabledQueues",
13243 _ => return None,
13244 };
13245 Some(res)
13246 }
13247}
13248#[derive(Clone, Copy, Default)]
13249pub struct IterableLinkinfoTunAttrs<'a> {
13250 buf: &'a [u8],
13251 pos: usize,
13252 orig_loc: usize,
13253}
13254impl<'a> IterableLinkinfoTunAttrs<'a> {
13255 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
13256 Self {
13257 buf,
13258 pos: 0,
13259 orig_loc,
13260 }
13261 }
13262 pub fn get_buf(&self) -> &'a [u8] {
13263 self.buf
13264 }
13265}
13266impl<'a> Iterator for IterableLinkinfoTunAttrs<'a> {
13267 type Item = Result<LinkinfoTunAttrs, ErrorContext>;
13268 fn next(&mut self) -> Option<Self::Item> {
13269 if self.buf.len() == self.pos {
13270 return None;
13271 }
13272 let pos = self.pos;
13273 let mut r#type = None;
13274 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
13275 r#type = Some(header.r#type);
13276 let res = match header.r#type {
13277 1u16 => LinkinfoTunAttrs::Owner({
13278 let res = parse_u32(next);
13279 let Some(val) = res else { break };
13280 val
13281 }),
13282 2u16 => LinkinfoTunAttrs::Group({
13283 let res = parse_u32(next);
13284 let Some(val) = res else { break };
13285 val
13286 }),
13287 3u16 => LinkinfoTunAttrs::Type({
13288 let res = parse_u8(next);
13289 let Some(val) = res else { break };
13290 val
13291 }),
13292 4u16 => LinkinfoTunAttrs::Pi({
13293 let res = parse_u8(next);
13294 let Some(val) = res else { break };
13295 val
13296 }),
13297 5u16 => LinkinfoTunAttrs::VnetHdr({
13298 let res = parse_u8(next);
13299 let Some(val) = res else { break };
13300 val
13301 }),
13302 6u16 => LinkinfoTunAttrs::Persist({
13303 let res = parse_u8(next);
13304 let Some(val) = res else { break };
13305 val
13306 }),
13307 7u16 => LinkinfoTunAttrs::MultiQueue({
13308 let res = parse_u8(next);
13309 let Some(val) = res else { break };
13310 val
13311 }),
13312 8u16 => LinkinfoTunAttrs::NumQueues({
13313 let res = parse_u32(next);
13314 let Some(val) = res else { break };
13315 val
13316 }),
13317 9u16 => LinkinfoTunAttrs::NumDisabledQueues({
13318 let res = parse_u32(next);
13319 let Some(val) = res else { break };
13320 val
13321 }),
13322 n => {
13323 if cfg!(any(test, feature = "deny-unknown-attrs")) {
13324 break;
13325 } else {
13326 continue;
13327 }
13328 }
13329 };
13330 return Some(Ok(res));
13331 }
13332 Some(Err(ErrorContext::new(
13333 "LinkinfoTunAttrs",
13334 r#type.and_then(|t| LinkinfoTunAttrs::attr_from_type(t)),
13335 self.orig_loc,
13336 self.buf.as_ptr().wrapping_add(pos) as usize,
13337 )))
13338 }
13339}
13340impl std::fmt::Debug for IterableLinkinfoTunAttrs<'_> {
13341 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13342 let mut fmt = f.debug_struct("LinkinfoTunAttrs");
13343 for attr in self.clone() {
13344 let attr = match attr {
13345 Ok(a) => a,
13346 Err(err) => {
13347 fmt.finish()?;
13348 f.write_str("Err(")?;
13349 err.fmt(f)?;
13350 return f.write_str(")");
13351 }
13352 };
13353 match attr {
13354 LinkinfoTunAttrs::Owner(val) => fmt.field("Owner", &val),
13355 LinkinfoTunAttrs::Group(val) => fmt.field("Group", &val),
13356 LinkinfoTunAttrs::Type(val) => fmt.field("Type", &val),
13357 LinkinfoTunAttrs::Pi(val) => fmt.field("Pi", &val),
13358 LinkinfoTunAttrs::VnetHdr(val) => fmt.field("VnetHdr", &val),
13359 LinkinfoTunAttrs::Persist(val) => fmt.field("Persist", &val),
13360 LinkinfoTunAttrs::MultiQueue(val) => fmt.field("MultiQueue", &val),
13361 LinkinfoTunAttrs::NumQueues(val) => fmt.field("NumQueues", &val),
13362 LinkinfoTunAttrs::NumDisabledQueues(val) => fmt.field("NumDisabledQueues", &val),
13363 };
13364 }
13365 fmt.finish()
13366 }
13367}
13368impl IterableLinkinfoTunAttrs<'_> {
13369 pub fn lookup_attr(
13370 &self,
13371 offset: usize,
13372 missing_type: Option<u16>,
13373 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
13374 let mut stack = Vec::new();
13375 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
13376 if cur == offset {
13377 stack.push(("LinkinfoTunAttrs", offset));
13378 return (
13379 stack,
13380 missing_type.and_then(|t| LinkinfoTunAttrs::attr_from_type(t)),
13381 );
13382 }
13383 if cur > offset || cur + self.buf.len() < offset {
13384 return (stack, None);
13385 }
13386 let mut attrs = self.clone();
13387 let mut last_off = cur + attrs.pos;
13388 while let Some(attr) = attrs.next() {
13389 let Ok(attr) = attr else { break };
13390 match attr {
13391 LinkinfoTunAttrs::Owner(val) => {
13392 if last_off == offset {
13393 stack.push(("Owner", last_off));
13394 break;
13395 }
13396 }
13397 LinkinfoTunAttrs::Group(val) => {
13398 if last_off == offset {
13399 stack.push(("Group", last_off));
13400 break;
13401 }
13402 }
13403 LinkinfoTunAttrs::Type(val) => {
13404 if last_off == offset {
13405 stack.push(("Type", last_off));
13406 break;
13407 }
13408 }
13409 LinkinfoTunAttrs::Pi(val) => {
13410 if last_off == offset {
13411 stack.push(("Pi", last_off));
13412 break;
13413 }
13414 }
13415 LinkinfoTunAttrs::VnetHdr(val) => {
13416 if last_off == offset {
13417 stack.push(("VnetHdr", last_off));
13418 break;
13419 }
13420 }
13421 LinkinfoTunAttrs::Persist(val) => {
13422 if last_off == offset {
13423 stack.push(("Persist", last_off));
13424 break;
13425 }
13426 }
13427 LinkinfoTunAttrs::MultiQueue(val) => {
13428 if last_off == offset {
13429 stack.push(("MultiQueue", last_off));
13430 break;
13431 }
13432 }
13433 LinkinfoTunAttrs::NumQueues(val) => {
13434 if last_off == offset {
13435 stack.push(("NumQueues", last_off));
13436 break;
13437 }
13438 }
13439 LinkinfoTunAttrs::NumDisabledQueues(val) => {
13440 if last_off == offset {
13441 stack.push(("NumDisabledQueues", last_off));
13442 break;
13443 }
13444 }
13445 _ => {}
13446 };
13447 last_off = cur + attrs.pos;
13448 }
13449 if !stack.is_empty() {
13450 stack.push(("LinkinfoTunAttrs", cur));
13451 }
13452 (stack, None)
13453 }
13454}
13455#[derive(Clone)]
13456pub enum LinkinfoVlanAttrs<'a> {
13457 Id(u16),
13458 Flags(PushIflaVlanFlags),
13459 EgressQos(IterableIflaVlanQos<'a>),
13460 IngressQos(IterableIflaVlanQos<'a>),
13461 #[doc = "Associated type: \"VlanProtocols\" (enum)"]
13462 Protocol(u16),
13463}
13464impl<'a> IterableLinkinfoVlanAttrs<'a> {
13465 pub fn get_id(&self) -> Result<u16, ErrorContext> {
13466 let mut iter = self.clone();
13467 iter.pos = 0;
13468 for attr in iter {
13469 if let LinkinfoVlanAttrs::Id(val) = attr? {
13470 return Ok(val);
13471 }
13472 }
13473 Err(ErrorContext::new_missing(
13474 "LinkinfoVlanAttrs",
13475 "Id",
13476 self.orig_loc,
13477 self.buf.as_ptr() as usize,
13478 ))
13479 }
13480 pub fn get_flags(&self) -> Result<PushIflaVlanFlags, ErrorContext> {
13481 let mut iter = self.clone();
13482 iter.pos = 0;
13483 for attr in iter {
13484 if let LinkinfoVlanAttrs::Flags(val) = attr? {
13485 return Ok(val);
13486 }
13487 }
13488 Err(ErrorContext::new_missing(
13489 "LinkinfoVlanAttrs",
13490 "Flags",
13491 self.orig_loc,
13492 self.buf.as_ptr() as usize,
13493 ))
13494 }
13495 pub fn get_egress_qos(&self) -> Result<IterableIflaVlanQos<'a>, ErrorContext> {
13496 let mut iter = self.clone();
13497 iter.pos = 0;
13498 for attr in iter {
13499 if let LinkinfoVlanAttrs::EgressQos(val) = attr? {
13500 return Ok(val);
13501 }
13502 }
13503 Err(ErrorContext::new_missing(
13504 "LinkinfoVlanAttrs",
13505 "EgressQos",
13506 self.orig_loc,
13507 self.buf.as_ptr() as usize,
13508 ))
13509 }
13510 pub fn get_ingress_qos(&self) -> Result<IterableIflaVlanQos<'a>, ErrorContext> {
13511 let mut iter = self.clone();
13512 iter.pos = 0;
13513 for attr in iter {
13514 if let LinkinfoVlanAttrs::IngressQos(val) = attr? {
13515 return Ok(val);
13516 }
13517 }
13518 Err(ErrorContext::new_missing(
13519 "LinkinfoVlanAttrs",
13520 "IngressQos",
13521 self.orig_loc,
13522 self.buf.as_ptr() as usize,
13523 ))
13524 }
13525 #[doc = "Associated type: \"VlanProtocols\" (enum)"]
13526 pub fn get_protocol(&self) -> Result<u16, ErrorContext> {
13527 let mut iter = self.clone();
13528 iter.pos = 0;
13529 for attr in iter {
13530 if let LinkinfoVlanAttrs::Protocol(val) = attr? {
13531 return Ok(val);
13532 }
13533 }
13534 Err(ErrorContext::new_missing(
13535 "LinkinfoVlanAttrs",
13536 "Protocol",
13537 self.orig_loc,
13538 self.buf.as_ptr() as usize,
13539 ))
13540 }
13541}
13542impl LinkinfoVlanAttrs<'_> {
13543 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoVlanAttrs<'a> {
13544 IterableLinkinfoVlanAttrs::with_loc(buf, buf.as_ptr() as usize)
13545 }
13546 fn attr_from_type(r#type: u16) -> Option<&'static str> {
13547 let res = match r#type {
13548 1u16 => "Id",
13549 2u16 => "Flags",
13550 3u16 => "EgressQos",
13551 4u16 => "IngressQos",
13552 5u16 => "Protocol",
13553 _ => return None,
13554 };
13555 Some(res)
13556 }
13557}
13558#[derive(Clone, Copy, Default)]
13559pub struct IterableLinkinfoVlanAttrs<'a> {
13560 buf: &'a [u8],
13561 pos: usize,
13562 orig_loc: usize,
13563}
13564impl<'a> IterableLinkinfoVlanAttrs<'a> {
13565 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
13566 Self {
13567 buf,
13568 pos: 0,
13569 orig_loc,
13570 }
13571 }
13572 pub fn get_buf(&self) -> &'a [u8] {
13573 self.buf
13574 }
13575}
13576impl<'a> Iterator for IterableLinkinfoVlanAttrs<'a> {
13577 type Item = Result<LinkinfoVlanAttrs<'a>, ErrorContext>;
13578 fn next(&mut self) -> Option<Self::Item> {
13579 if self.buf.len() == self.pos {
13580 return None;
13581 }
13582 let pos = self.pos;
13583 let mut r#type = None;
13584 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
13585 r#type = Some(header.r#type);
13586 let res = match header.r#type {
13587 1u16 => LinkinfoVlanAttrs::Id({
13588 let res = parse_u16(next);
13589 let Some(val) = res else { break };
13590 val
13591 }),
13592 2u16 => LinkinfoVlanAttrs::Flags({
13593 let res = PushIflaVlanFlags::new_from_slice(next);
13594 let Some(val) = res else { break };
13595 val
13596 }),
13597 3u16 => LinkinfoVlanAttrs::EgressQos({
13598 let res = Some(IterableIflaVlanQos::with_loc(next, self.orig_loc));
13599 let Some(val) = res else { break };
13600 val
13601 }),
13602 4u16 => LinkinfoVlanAttrs::IngressQos({
13603 let res = Some(IterableIflaVlanQos::with_loc(next, self.orig_loc));
13604 let Some(val) = res else { break };
13605 val
13606 }),
13607 5u16 => LinkinfoVlanAttrs::Protocol({
13608 let res = parse_be_u16(next);
13609 let Some(val) = res else { break };
13610 val
13611 }),
13612 n => {
13613 if cfg!(any(test, feature = "deny-unknown-attrs")) {
13614 break;
13615 } else {
13616 continue;
13617 }
13618 }
13619 };
13620 return Some(Ok(res));
13621 }
13622 Some(Err(ErrorContext::new(
13623 "LinkinfoVlanAttrs",
13624 r#type.and_then(|t| LinkinfoVlanAttrs::attr_from_type(t)),
13625 self.orig_loc,
13626 self.buf.as_ptr().wrapping_add(pos) as usize,
13627 )))
13628 }
13629}
13630impl<'a> std::fmt::Debug for IterableLinkinfoVlanAttrs<'_> {
13631 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13632 let mut fmt = f.debug_struct("LinkinfoVlanAttrs");
13633 for attr in self.clone() {
13634 let attr = match attr {
13635 Ok(a) => a,
13636 Err(err) => {
13637 fmt.finish()?;
13638 f.write_str("Err(")?;
13639 err.fmt(f)?;
13640 return f.write_str(")");
13641 }
13642 };
13643 match attr {
13644 LinkinfoVlanAttrs::Id(val) => fmt.field("Id", &val),
13645 LinkinfoVlanAttrs::Flags(val) => fmt.field("Flags", &val),
13646 LinkinfoVlanAttrs::EgressQos(val) => fmt.field("EgressQos", &val),
13647 LinkinfoVlanAttrs::IngressQos(val) => fmt.field("IngressQos", &val),
13648 LinkinfoVlanAttrs::Protocol(val) => fmt.field(
13649 "Protocol",
13650 &FormatEnum(val.into(), VlanProtocols::from_value),
13651 ),
13652 };
13653 }
13654 fmt.finish()
13655 }
13656}
13657impl IterableLinkinfoVlanAttrs<'_> {
13658 pub fn lookup_attr(
13659 &self,
13660 offset: usize,
13661 missing_type: Option<u16>,
13662 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
13663 let mut stack = Vec::new();
13664 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
13665 if cur == offset {
13666 stack.push(("LinkinfoVlanAttrs", offset));
13667 return (
13668 stack,
13669 missing_type.and_then(|t| LinkinfoVlanAttrs::attr_from_type(t)),
13670 );
13671 }
13672 if cur > offset || cur + self.buf.len() < offset {
13673 return (stack, None);
13674 }
13675 let mut attrs = self.clone();
13676 let mut last_off = cur + attrs.pos;
13677 let mut missing = None;
13678 while let Some(attr) = attrs.next() {
13679 let Ok(attr) = attr else { break };
13680 match attr {
13681 LinkinfoVlanAttrs::Id(val) => {
13682 if last_off == offset {
13683 stack.push(("Id", last_off));
13684 break;
13685 }
13686 }
13687 LinkinfoVlanAttrs::Flags(val) => {
13688 if last_off == offset {
13689 stack.push(("Flags", last_off));
13690 break;
13691 }
13692 }
13693 LinkinfoVlanAttrs::EgressQos(val) => {
13694 (stack, missing) = val.lookup_attr(offset, missing_type);
13695 if !stack.is_empty() {
13696 break;
13697 }
13698 }
13699 LinkinfoVlanAttrs::IngressQos(val) => {
13700 (stack, missing) = val.lookup_attr(offset, missing_type);
13701 if !stack.is_empty() {
13702 break;
13703 }
13704 }
13705 LinkinfoVlanAttrs::Protocol(val) => {
13706 if last_off == offset {
13707 stack.push(("Protocol", last_off));
13708 break;
13709 }
13710 }
13711 _ => {}
13712 };
13713 last_off = cur + attrs.pos;
13714 }
13715 if !stack.is_empty() {
13716 stack.push(("LinkinfoVlanAttrs", cur));
13717 }
13718 (stack, missing)
13719 }
13720}
13721#[derive(Clone)]
13722pub enum IflaVlanQos {
13723 #[doc = "Attribute may repeat multiple times (treat it as array)"]
13724 Mapping(PushIflaVlanQosMapping),
13725}
13726impl<'a> IterableIflaVlanQos<'a> {
13727 #[doc = "Attribute may repeat multiple times (treat it as array)"]
13728 pub fn get_mapping(&self) -> MultiAttrIterable<Self, IflaVlanQos, PushIflaVlanQosMapping> {
13729 MultiAttrIterable::new(self.clone(), |variant| {
13730 if let IflaVlanQos::Mapping(val) = variant {
13731 Some(val)
13732 } else {
13733 None
13734 }
13735 })
13736 }
13737}
13738impl IflaVlanQos {
13739 pub fn new<'a>(buf: &'a [u8]) -> IterableIflaVlanQos<'a> {
13740 IterableIflaVlanQos::with_loc(buf, buf.as_ptr() as usize)
13741 }
13742 fn attr_from_type(r#type: u16) -> Option<&'static str> {
13743 let res = match r#type {
13744 1u16 => "Mapping",
13745 _ => return None,
13746 };
13747 Some(res)
13748 }
13749}
13750#[derive(Clone, Copy, Default)]
13751pub struct IterableIflaVlanQos<'a> {
13752 buf: &'a [u8],
13753 pos: usize,
13754 orig_loc: usize,
13755}
13756impl<'a> IterableIflaVlanQos<'a> {
13757 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
13758 Self {
13759 buf,
13760 pos: 0,
13761 orig_loc,
13762 }
13763 }
13764 pub fn get_buf(&self) -> &'a [u8] {
13765 self.buf
13766 }
13767}
13768impl<'a> Iterator for IterableIflaVlanQos<'a> {
13769 type Item = Result<IflaVlanQos, ErrorContext>;
13770 fn next(&mut self) -> Option<Self::Item> {
13771 if self.buf.len() == self.pos {
13772 return None;
13773 }
13774 let pos = self.pos;
13775 let mut r#type = None;
13776 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
13777 r#type = Some(header.r#type);
13778 let res = match header.r#type {
13779 1u16 => IflaVlanQos::Mapping({
13780 let res = PushIflaVlanQosMapping::new_from_slice(next);
13781 let Some(val) = res else { break };
13782 val
13783 }),
13784 n => {
13785 if cfg!(any(test, feature = "deny-unknown-attrs")) {
13786 break;
13787 } else {
13788 continue;
13789 }
13790 }
13791 };
13792 return Some(Ok(res));
13793 }
13794 Some(Err(ErrorContext::new(
13795 "IflaVlanQos",
13796 r#type.and_then(|t| IflaVlanQos::attr_from_type(t)),
13797 self.orig_loc,
13798 self.buf.as_ptr().wrapping_add(pos) as usize,
13799 )))
13800 }
13801}
13802impl std::fmt::Debug for IterableIflaVlanQos<'_> {
13803 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13804 let mut fmt = f.debug_struct("IflaVlanQos");
13805 for attr in self.clone() {
13806 let attr = match attr {
13807 Ok(a) => a,
13808 Err(err) => {
13809 fmt.finish()?;
13810 f.write_str("Err(")?;
13811 err.fmt(f)?;
13812 return f.write_str(")");
13813 }
13814 };
13815 match attr {
13816 IflaVlanQos::Mapping(val) => fmt.field("Mapping", &val),
13817 };
13818 }
13819 fmt.finish()
13820 }
13821}
13822impl IterableIflaVlanQos<'_> {
13823 pub fn lookup_attr(
13824 &self,
13825 offset: usize,
13826 missing_type: Option<u16>,
13827 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
13828 let mut stack = Vec::new();
13829 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
13830 if cur == offset {
13831 stack.push(("IflaVlanQos", offset));
13832 return (
13833 stack,
13834 missing_type.and_then(|t| IflaVlanQos::attr_from_type(t)),
13835 );
13836 }
13837 if cur > offset || cur + self.buf.len() < offset {
13838 return (stack, None);
13839 }
13840 let mut attrs = self.clone();
13841 let mut last_off = cur + attrs.pos;
13842 while let Some(attr) = attrs.next() {
13843 let Ok(attr) = attr else { break };
13844 match attr {
13845 IflaVlanQos::Mapping(val) => {
13846 if last_off == offset {
13847 stack.push(("Mapping", last_off));
13848 break;
13849 }
13850 }
13851 _ => {}
13852 };
13853 last_off = cur + attrs.pos;
13854 }
13855 if !stack.is_empty() {
13856 stack.push(("IflaVlanQos", cur));
13857 }
13858 (stack, None)
13859 }
13860}
13861#[derive(Clone)]
13862pub enum LinkinfoVrfAttrs {
13863 Table(u32),
13864}
13865impl<'a> IterableLinkinfoVrfAttrs<'a> {
13866 pub fn get_table(&self) -> Result<u32, ErrorContext> {
13867 let mut iter = self.clone();
13868 iter.pos = 0;
13869 for attr in iter {
13870 if let LinkinfoVrfAttrs::Table(val) = attr? {
13871 return Ok(val);
13872 }
13873 }
13874 Err(ErrorContext::new_missing(
13875 "LinkinfoVrfAttrs",
13876 "Table",
13877 self.orig_loc,
13878 self.buf.as_ptr() as usize,
13879 ))
13880 }
13881}
13882impl LinkinfoVrfAttrs {
13883 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoVrfAttrs<'a> {
13884 IterableLinkinfoVrfAttrs::with_loc(buf, buf.as_ptr() as usize)
13885 }
13886 fn attr_from_type(r#type: u16) -> Option<&'static str> {
13887 let res = match r#type {
13888 1u16 => "Table",
13889 _ => return None,
13890 };
13891 Some(res)
13892 }
13893}
13894#[derive(Clone, Copy, Default)]
13895pub struct IterableLinkinfoVrfAttrs<'a> {
13896 buf: &'a [u8],
13897 pos: usize,
13898 orig_loc: usize,
13899}
13900impl<'a> IterableLinkinfoVrfAttrs<'a> {
13901 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
13902 Self {
13903 buf,
13904 pos: 0,
13905 orig_loc,
13906 }
13907 }
13908 pub fn get_buf(&self) -> &'a [u8] {
13909 self.buf
13910 }
13911}
13912impl<'a> Iterator for IterableLinkinfoVrfAttrs<'a> {
13913 type Item = Result<LinkinfoVrfAttrs, ErrorContext>;
13914 fn next(&mut self) -> Option<Self::Item> {
13915 if self.buf.len() == self.pos {
13916 return None;
13917 }
13918 let pos = self.pos;
13919 let mut r#type = None;
13920 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
13921 r#type = Some(header.r#type);
13922 let res = match header.r#type {
13923 1u16 => LinkinfoVrfAttrs::Table({
13924 let res = parse_u32(next);
13925 let Some(val) = res else { break };
13926 val
13927 }),
13928 n => {
13929 if cfg!(any(test, feature = "deny-unknown-attrs")) {
13930 break;
13931 } else {
13932 continue;
13933 }
13934 }
13935 };
13936 return Some(Ok(res));
13937 }
13938 Some(Err(ErrorContext::new(
13939 "LinkinfoVrfAttrs",
13940 r#type.and_then(|t| LinkinfoVrfAttrs::attr_from_type(t)),
13941 self.orig_loc,
13942 self.buf.as_ptr().wrapping_add(pos) as usize,
13943 )))
13944 }
13945}
13946impl std::fmt::Debug for IterableLinkinfoVrfAttrs<'_> {
13947 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13948 let mut fmt = f.debug_struct("LinkinfoVrfAttrs");
13949 for attr in self.clone() {
13950 let attr = match attr {
13951 Ok(a) => a,
13952 Err(err) => {
13953 fmt.finish()?;
13954 f.write_str("Err(")?;
13955 err.fmt(f)?;
13956 return f.write_str(")");
13957 }
13958 };
13959 match attr {
13960 LinkinfoVrfAttrs::Table(val) => fmt.field("Table", &val),
13961 };
13962 }
13963 fmt.finish()
13964 }
13965}
13966impl IterableLinkinfoVrfAttrs<'_> {
13967 pub fn lookup_attr(
13968 &self,
13969 offset: usize,
13970 missing_type: Option<u16>,
13971 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
13972 let mut stack = Vec::new();
13973 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
13974 if cur == offset {
13975 stack.push(("LinkinfoVrfAttrs", offset));
13976 return (
13977 stack,
13978 missing_type.and_then(|t| LinkinfoVrfAttrs::attr_from_type(t)),
13979 );
13980 }
13981 if cur > offset || cur + self.buf.len() < offset {
13982 return (stack, None);
13983 }
13984 let mut attrs = self.clone();
13985 let mut last_off = cur + attrs.pos;
13986 while let Some(attr) = attrs.next() {
13987 let Ok(attr) = attr else { break };
13988 match attr {
13989 LinkinfoVrfAttrs::Table(val) => {
13990 if last_off == offset {
13991 stack.push(("Table", last_off));
13992 break;
13993 }
13994 }
13995 _ => {}
13996 };
13997 last_off = cur + attrs.pos;
13998 }
13999 if !stack.is_empty() {
14000 stack.push(("LinkinfoVrfAttrs", cur));
14001 }
14002 (stack, None)
14003 }
14004}
14005#[derive(Clone)]
14006pub enum XdpAttrs {
14007 Fd(i32),
14008 Attached(u8),
14009 Flags(u32),
14010 ProgId(u32),
14011 DrvProgId(u32),
14012 SkbProgId(u32),
14013 HwProgId(u32),
14014 ExpectedFd(i32),
14015}
14016impl<'a> IterableXdpAttrs<'a> {
14017 pub fn get_fd(&self) -> Result<i32, ErrorContext> {
14018 let mut iter = self.clone();
14019 iter.pos = 0;
14020 for attr in iter {
14021 if let XdpAttrs::Fd(val) = attr? {
14022 return Ok(val);
14023 }
14024 }
14025 Err(ErrorContext::new_missing(
14026 "XdpAttrs",
14027 "Fd",
14028 self.orig_loc,
14029 self.buf.as_ptr() as usize,
14030 ))
14031 }
14032 pub fn get_attached(&self) -> Result<u8, ErrorContext> {
14033 let mut iter = self.clone();
14034 iter.pos = 0;
14035 for attr in iter {
14036 if let XdpAttrs::Attached(val) = attr? {
14037 return Ok(val);
14038 }
14039 }
14040 Err(ErrorContext::new_missing(
14041 "XdpAttrs",
14042 "Attached",
14043 self.orig_loc,
14044 self.buf.as_ptr() as usize,
14045 ))
14046 }
14047 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
14048 let mut iter = self.clone();
14049 iter.pos = 0;
14050 for attr in iter {
14051 if let XdpAttrs::Flags(val) = attr? {
14052 return Ok(val);
14053 }
14054 }
14055 Err(ErrorContext::new_missing(
14056 "XdpAttrs",
14057 "Flags",
14058 self.orig_loc,
14059 self.buf.as_ptr() as usize,
14060 ))
14061 }
14062 pub fn get_prog_id(&self) -> Result<u32, ErrorContext> {
14063 let mut iter = self.clone();
14064 iter.pos = 0;
14065 for attr in iter {
14066 if let XdpAttrs::ProgId(val) = attr? {
14067 return Ok(val);
14068 }
14069 }
14070 Err(ErrorContext::new_missing(
14071 "XdpAttrs",
14072 "ProgId",
14073 self.orig_loc,
14074 self.buf.as_ptr() as usize,
14075 ))
14076 }
14077 pub fn get_drv_prog_id(&self) -> Result<u32, ErrorContext> {
14078 let mut iter = self.clone();
14079 iter.pos = 0;
14080 for attr in iter {
14081 if let XdpAttrs::DrvProgId(val) = attr? {
14082 return Ok(val);
14083 }
14084 }
14085 Err(ErrorContext::new_missing(
14086 "XdpAttrs",
14087 "DrvProgId",
14088 self.orig_loc,
14089 self.buf.as_ptr() as usize,
14090 ))
14091 }
14092 pub fn get_skb_prog_id(&self) -> Result<u32, ErrorContext> {
14093 let mut iter = self.clone();
14094 iter.pos = 0;
14095 for attr in iter {
14096 if let XdpAttrs::SkbProgId(val) = attr? {
14097 return Ok(val);
14098 }
14099 }
14100 Err(ErrorContext::new_missing(
14101 "XdpAttrs",
14102 "SkbProgId",
14103 self.orig_loc,
14104 self.buf.as_ptr() as usize,
14105 ))
14106 }
14107 pub fn get_hw_prog_id(&self) -> Result<u32, ErrorContext> {
14108 let mut iter = self.clone();
14109 iter.pos = 0;
14110 for attr in iter {
14111 if let XdpAttrs::HwProgId(val) = attr? {
14112 return Ok(val);
14113 }
14114 }
14115 Err(ErrorContext::new_missing(
14116 "XdpAttrs",
14117 "HwProgId",
14118 self.orig_loc,
14119 self.buf.as_ptr() as usize,
14120 ))
14121 }
14122 pub fn get_expected_fd(&self) -> Result<i32, ErrorContext> {
14123 let mut iter = self.clone();
14124 iter.pos = 0;
14125 for attr in iter {
14126 if let XdpAttrs::ExpectedFd(val) = attr? {
14127 return Ok(val);
14128 }
14129 }
14130 Err(ErrorContext::new_missing(
14131 "XdpAttrs",
14132 "ExpectedFd",
14133 self.orig_loc,
14134 self.buf.as_ptr() as usize,
14135 ))
14136 }
14137}
14138impl XdpAttrs {
14139 pub fn new<'a>(buf: &'a [u8]) -> IterableXdpAttrs<'a> {
14140 IterableXdpAttrs::with_loc(buf, buf.as_ptr() as usize)
14141 }
14142 fn attr_from_type(r#type: u16) -> Option<&'static str> {
14143 let res = match r#type {
14144 1u16 => "Fd",
14145 2u16 => "Attached",
14146 3u16 => "Flags",
14147 4u16 => "ProgId",
14148 5u16 => "DrvProgId",
14149 6u16 => "SkbProgId",
14150 7u16 => "HwProgId",
14151 8u16 => "ExpectedFd",
14152 _ => return None,
14153 };
14154 Some(res)
14155 }
14156}
14157#[derive(Clone, Copy, Default)]
14158pub struct IterableXdpAttrs<'a> {
14159 buf: &'a [u8],
14160 pos: usize,
14161 orig_loc: usize,
14162}
14163impl<'a> IterableXdpAttrs<'a> {
14164 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
14165 Self {
14166 buf,
14167 pos: 0,
14168 orig_loc,
14169 }
14170 }
14171 pub fn get_buf(&self) -> &'a [u8] {
14172 self.buf
14173 }
14174}
14175impl<'a> Iterator for IterableXdpAttrs<'a> {
14176 type Item = Result<XdpAttrs, ErrorContext>;
14177 fn next(&mut self) -> Option<Self::Item> {
14178 if self.buf.len() == self.pos {
14179 return None;
14180 }
14181 let pos = self.pos;
14182 let mut r#type = None;
14183 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
14184 r#type = Some(header.r#type);
14185 let res = match header.r#type {
14186 1u16 => XdpAttrs::Fd({
14187 let res = parse_i32(next);
14188 let Some(val) = res else { break };
14189 val
14190 }),
14191 2u16 => XdpAttrs::Attached({
14192 let res = parse_u8(next);
14193 let Some(val) = res else { break };
14194 val
14195 }),
14196 3u16 => XdpAttrs::Flags({
14197 let res = parse_u32(next);
14198 let Some(val) = res else { break };
14199 val
14200 }),
14201 4u16 => XdpAttrs::ProgId({
14202 let res = parse_u32(next);
14203 let Some(val) = res else { break };
14204 val
14205 }),
14206 5u16 => XdpAttrs::DrvProgId({
14207 let res = parse_u32(next);
14208 let Some(val) = res else { break };
14209 val
14210 }),
14211 6u16 => XdpAttrs::SkbProgId({
14212 let res = parse_u32(next);
14213 let Some(val) = res else { break };
14214 val
14215 }),
14216 7u16 => XdpAttrs::HwProgId({
14217 let res = parse_u32(next);
14218 let Some(val) = res else { break };
14219 val
14220 }),
14221 8u16 => XdpAttrs::ExpectedFd({
14222 let res = parse_i32(next);
14223 let Some(val) = res else { break };
14224 val
14225 }),
14226 n => {
14227 if cfg!(any(test, feature = "deny-unknown-attrs")) {
14228 break;
14229 } else {
14230 continue;
14231 }
14232 }
14233 };
14234 return Some(Ok(res));
14235 }
14236 Some(Err(ErrorContext::new(
14237 "XdpAttrs",
14238 r#type.and_then(|t| XdpAttrs::attr_from_type(t)),
14239 self.orig_loc,
14240 self.buf.as_ptr().wrapping_add(pos) as usize,
14241 )))
14242 }
14243}
14244impl std::fmt::Debug for IterableXdpAttrs<'_> {
14245 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14246 let mut fmt = f.debug_struct("XdpAttrs");
14247 for attr in self.clone() {
14248 let attr = match attr {
14249 Ok(a) => a,
14250 Err(err) => {
14251 fmt.finish()?;
14252 f.write_str("Err(")?;
14253 err.fmt(f)?;
14254 return f.write_str(")");
14255 }
14256 };
14257 match attr {
14258 XdpAttrs::Fd(val) => fmt.field("Fd", &val),
14259 XdpAttrs::Attached(val) => fmt.field("Attached", &val),
14260 XdpAttrs::Flags(val) => fmt.field("Flags", &val),
14261 XdpAttrs::ProgId(val) => fmt.field("ProgId", &val),
14262 XdpAttrs::DrvProgId(val) => fmt.field("DrvProgId", &val),
14263 XdpAttrs::SkbProgId(val) => fmt.field("SkbProgId", &val),
14264 XdpAttrs::HwProgId(val) => fmt.field("HwProgId", &val),
14265 XdpAttrs::ExpectedFd(val) => fmt.field("ExpectedFd", &val),
14266 };
14267 }
14268 fmt.finish()
14269 }
14270}
14271impl IterableXdpAttrs<'_> {
14272 pub fn lookup_attr(
14273 &self,
14274 offset: usize,
14275 missing_type: Option<u16>,
14276 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
14277 let mut stack = Vec::new();
14278 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
14279 if cur == offset {
14280 stack.push(("XdpAttrs", offset));
14281 return (
14282 stack,
14283 missing_type.and_then(|t| XdpAttrs::attr_from_type(t)),
14284 );
14285 }
14286 if cur > offset || cur + self.buf.len() < offset {
14287 return (stack, None);
14288 }
14289 let mut attrs = self.clone();
14290 let mut last_off = cur + attrs.pos;
14291 while let Some(attr) = attrs.next() {
14292 let Ok(attr) = attr else { break };
14293 match attr {
14294 XdpAttrs::Fd(val) => {
14295 if last_off == offset {
14296 stack.push(("Fd", last_off));
14297 break;
14298 }
14299 }
14300 XdpAttrs::Attached(val) => {
14301 if last_off == offset {
14302 stack.push(("Attached", last_off));
14303 break;
14304 }
14305 }
14306 XdpAttrs::Flags(val) => {
14307 if last_off == offset {
14308 stack.push(("Flags", last_off));
14309 break;
14310 }
14311 }
14312 XdpAttrs::ProgId(val) => {
14313 if last_off == offset {
14314 stack.push(("ProgId", last_off));
14315 break;
14316 }
14317 }
14318 XdpAttrs::DrvProgId(val) => {
14319 if last_off == offset {
14320 stack.push(("DrvProgId", last_off));
14321 break;
14322 }
14323 }
14324 XdpAttrs::SkbProgId(val) => {
14325 if last_off == offset {
14326 stack.push(("SkbProgId", last_off));
14327 break;
14328 }
14329 }
14330 XdpAttrs::HwProgId(val) => {
14331 if last_off == offset {
14332 stack.push(("HwProgId", last_off));
14333 break;
14334 }
14335 }
14336 XdpAttrs::ExpectedFd(val) => {
14337 if last_off == offset {
14338 stack.push(("ExpectedFd", last_off));
14339 break;
14340 }
14341 }
14342 _ => {}
14343 };
14344 last_off = cur + attrs.pos;
14345 }
14346 if !stack.is_empty() {
14347 stack.push(("XdpAttrs", cur));
14348 }
14349 (stack, None)
14350 }
14351}
14352#[derive(Clone)]
14353pub enum IflaAttrs<'a> {
14354 #[doc = "u32 indexed by ipv4-devconf - 1 on output, on input it's a nest"]
14355 Conf(&'a [u8]),
14356}
14357impl<'a> IterableIflaAttrs<'a> {
14358 #[doc = "u32 indexed by ipv4-devconf - 1 on output, on input it's a nest"]
14359 pub fn get_conf(&self) -> Result<&'a [u8], ErrorContext> {
14360 let mut iter = self.clone();
14361 iter.pos = 0;
14362 for attr in iter {
14363 if let IflaAttrs::Conf(val) = attr? {
14364 return Ok(val);
14365 }
14366 }
14367 Err(ErrorContext::new_missing(
14368 "IflaAttrs",
14369 "Conf",
14370 self.orig_loc,
14371 self.buf.as_ptr() as usize,
14372 ))
14373 }
14374}
14375impl IflaAttrs<'_> {
14376 pub fn new<'a>(buf: &'a [u8]) -> IterableIflaAttrs<'a> {
14377 IterableIflaAttrs::with_loc(buf, buf.as_ptr() as usize)
14378 }
14379 fn attr_from_type(r#type: u16) -> Option<&'static str> {
14380 let res = match r#type {
14381 1u16 => "Conf",
14382 _ => return None,
14383 };
14384 Some(res)
14385 }
14386}
14387#[derive(Clone, Copy, Default)]
14388pub struct IterableIflaAttrs<'a> {
14389 buf: &'a [u8],
14390 pos: usize,
14391 orig_loc: usize,
14392}
14393impl<'a> IterableIflaAttrs<'a> {
14394 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
14395 Self {
14396 buf,
14397 pos: 0,
14398 orig_loc,
14399 }
14400 }
14401 pub fn get_buf(&self) -> &'a [u8] {
14402 self.buf
14403 }
14404}
14405impl<'a> Iterator for IterableIflaAttrs<'a> {
14406 type Item = Result<IflaAttrs<'a>, ErrorContext>;
14407 fn next(&mut self) -> Option<Self::Item> {
14408 if self.buf.len() == self.pos {
14409 return None;
14410 }
14411 let pos = self.pos;
14412 let mut r#type = None;
14413 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
14414 r#type = Some(header.r#type);
14415 let res = match header.r#type {
14416 1u16 => IflaAttrs::Conf({
14417 let res = Some(next);
14418 let Some(val) = res else { break };
14419 val
14420 }),
14421 n => {
14422 if cfg!(any(test, feature = "deny-unknown-attrs")) {
14423 break;
14424 } else {
14425 continue;
14426 }
14427 }
14428 };
14429 return Some(Ok(res));
14430 }
14431 Some(Err(ErrorContext::new(
14432 "IflaAttrs",
14433 r#type.and_then(|t| IflaAttrs::attr_from_type(t)),
14434 self.orig_loc,
14435 self.buf.as_ptr().wrapping_add(pos) as usize,
14436 )))
14437 }
14438}
14439impl<'a> std::fmt::Debug for IterableIflaAttrs<'_> {
14440 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14441 let mut fmt = f.debug_struct("IflaAttrs");
14442 for attr in self.clone() {
14443 let attr = match attr {
14444 Ok(a) => a,
14445 Err(err) => {
14446 fmt.finish()?;
14447 f.write_str("Err(")?;
14448 err.fmt(f)?;
14449 return f.write_str(")");
14450 }
14451 };
14452 match attr {
14453 IflaAttrs::Conf(val) => fmt.field("Conf", &val),
14454 };
14455 }
14456 fmt.finish()
14457 }
14458}
14459impl IterableIflaAttrs<'_> {
14460 pub fn lookup_attr(
14461 &self,
14462 offset: usize,
14463 missing_type: Option<u16>,
14464 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
14465 let mut stack = Vec::new();
14466 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
14467 if cur == offset {
14468 stack.push(("IflaAttrs", offset));
14469 return (
14470 stack,
14471 missing_type.and_then(|t| IflaAttrs::attr_from_type(t)),
14472 );
14473 }
14474 if cur > offset || cur + self.buf.len() < offset {
14475 return (stack, None);
14476 }
14477 let mut attrs = self.clone();
14478 let mut last_off = cur + attrs.pos;
14479 while let Some(attr) = attrs.next() {
14480 let Ok(attr) = attr else { break };
14481 match attr {
14482 IflaAttrs::Conf(val) => {
14483 if last_off == offset {
14484 stack.push(("Conf", last_off));
14485 break;
14486 }
14487 }
14488 _ => {}
14489 };
14490 last_off = cur + attrs.pos;
14491 }
14492 if !stack.is_empty() {
14493 stack.push(("IflaAttrs", cur));
14494 }
14495 (stack, None)
14496 }
14497}
14498#[derive(Clone)]
14499pub enum Ifla6Attrs<'a> {
14500 Flags(u32),
14501 #[doc = "u32 indexed by ipv6-devconf - 1 on output, on input it's a nest"]
14502 Conf(&'a [u8]),
14503 Stats(&'a [u8]),
14504 Mcast(&'a [u8]),
14505 Cacheinfo(PushIflaCacheinfo),
14506 Icmp6stats(&'a [u8]),
14507 Token(&'a [u8]),
14508 AddrGenMode(u8),
14509 RaMtu(u32),
14510}
14511impl<'a> IterableIfla6Attrs<'a> {
14512 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
14513 let mut iter = self.clone();
14514 iter.pos = 0;
14515 for attr in iter {
14516 if let Ifla6Attrs::Flags(val) = attr? {
14517 return Ok(val);
14518 }
14519 }
14520 Err(ErrorContext::new_missing(
14521 "Ifla6Attrs",
14522 "Flags",
14523 self.orig_loc,
14524 self.buf.as_ptr() as usize,
14525 ))
14526 }
14527 #[doc = "u32 indexed by ipv6-devconf - 1 on output, on input it's a nest"]
14528 pub fn get_conf(&self) -> Result<&'a [u8], ErrorContext> {
14529 let mut iter = self.clone();
14530 iter.pos = 0;
14531 for attr in iter {
14532 if let Ifla6Attrs::Conf(val) = attr? {
14533 return Ok(val);
14534 }
14535 }
14536 Err(ErrorContext::new_missing(
14537 "Ifla6Attrs",
14538 "Conf",
14539 self.orig_loc,
14540 self.buf.as_ptr() as usize,
14541 ))
14542 }
14543 pub fn get_stats(&self) -> Result<&'a [u8], ErrorContext> {
14544 let mut iter = self.clone();
14545 iter.pos = 0;
14546 for attr in iter {
14547 if let Ifla6Attrs::Stats(val) = attr? {
14548 return Ok(val);
14549 }
14550 }
14551 Err(ErrorContext::new_missing(
14552 "Ifla6Attrs",
14553 "Stats",
14554 self.orig_loc,
14555 self.buf.as_ptr() as usize,
14556 ))
14557 }
14558 pub fn get_mcast(&self) -> Result<&'a [u8], ErrorContext> {
14559 let mut iter = self.clone();
14560 iter.pos = 0;
14561 for attr in iter {
14562 if let Ifla6Attrs::Mcast(val) = attr? {
14563 return Ok(val);
14564 }
14565 }
14566 Err(ErrorContext::new_missing(
14567 "Ifla6Attrs",
14568 "Mcast",
14569 self.orig_loc,
14570 self.buf.as_ptr() as usize,
14571 ))
14572 }
14573 pub fn get_cacheinfo(&self) -> Result<PushIflaCacheinfo, ErrorContext> {
14574 let mut iter = self.clone();
14575 iter.pos = 0;
14576 for attr in iter {
14577 if let Ifla6Attrs::Cacheinfo(val) = attr? {
14578 return Ok(val);
14579 }
14580 }
14581 Err(ErrorContext::new_missing(
14582 "Ifla6Attrs",
14583 "Cacheinfo",
14584 self.orig_loc,
14585 self.buf.as_ptr() as usize,
14586 ))
14587 }
14588 pub fn get_icmp6stats(&self) -> Result<&'a [u8], ErrorContext> {
14589 let mut iter = self.clone();
14590 iter.pos = 0;
14591 for attr in iter {
14592 if let Ifla6Attrs::Icmp6stats(val) = attr? {
14593 return Ok(val);
14594 }
14595 }
14596 Err(ErrorContext::new_missing(
14597 "Ifla6Attrs",
14598 "Icmp6stats",
14599 self.orig_loc,
14600 self.buf.as_ptr() as usize,
14601 ))
14602 }
14603 pub fn get_token(&self) -> Result<&'a [u8], ErrorContext> {
14604 let mut iter = self.clone();
14605 iter.pos = 0;
14606 for attr in iter {
14607 if let Ifla6Attrs::Token(val) = attr? {
14608 return Ok(val);
14609 }
14610 }
14611 Err(ErrorContext::new_missing(
14612 "Ifla6Attrs",
14613 "Token",
14614 self.orig_loc,
14615 self.buf.as_ptr() as usize,
14616 ))
14617 }
14618 pub fn get_addr_gen_mode(&self) -> Result<u8, ErrorContext> {
14619 let mut iter = self.clone();
14620 iter.pos = 0;
14621 for attr in iter {
14622 if let Ifla6Attrs::AddrGenMode(val) = attr? {
14623 return Ok(val);
14624 }
14625 }
14626 Err(ErrorContext::new_missing(
14627 "Ifla6Attrs",
14628 "AddrGenMode",
14629 self.orig_loc,
14630 self.buf.as_ptr() as usize,
14631 ))
14632 }
14633 pub fn get_ra_mtu(&self) -> Result<u32, ErrorContext> {
14634 let mut iter = self.clone();
14635 iter.pos = 0;
14636 for attr in iter {
14637 if let Ifla6Attrs::RaMtu(val) = attr? {
14638 return Ok(val);
14639 }
14640 }
14641 Err(ErrorContext::new_missing(
14642 "Ifla6Attrs",
14643 "RaMtu",
14644 self.orig_loc,
14645 self.buf.as_ptr() as usize,
14646 ))
14647 }
14648}
14649impl Ifla6Attrs<'_> {
14650 pub fn new<'a>(buf: &'a [u8]) -> IterableIfla6Attrs<'a> {
14651 IterableIfla6Attrs::with_loc(buf, buf.as_ptr() as usize)
14652 }
14653 fn attr_from_type(r#type: u16) -> Option<&'static str> {
14654 let res = match r#type {
14655 1u16 => "Flags",
14656 2u16 => "Conf",
14657 3u16 => "Stats",
14658 4u16 => "Mcast",
14659 5u16 => "Cacheinfo",
14660 6u16 => "Icmp6stats",
14661 7u16 => "Token",
14662 8u16 => "AddrGenMode",
14663 9u16 => "RaMtu",
14664 _ => return None,
14665 };
14666 Some(res)
14667 }
14668}
14669#[derive(Clone, Copy, Default)]
14670pub struct IterableIfla6Attrs<'a> {
14671 buf: &'a [u8],
14672 pos: usize,
14673 orig_loc: usize,
14674}
14675impl<'a> IterableIfla6Attrs<'a> {
14676 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
14677 Self {
14678 buf,
14679 pos: 0,
14680 orig_loc,
14681 }
14682 }
14683 pub fn get_buf(&self) -> &'a [u8] {
14684 self.buf
14685 }
14686}
14687impl<'a> Iterator for IterableIfla6Attrs<'a> {
14688 type Item = Result<Ifla6Attrs<'a>, ErrorContext>;
14689 fn next(&mut self) -> Option<Self::Item> {
14690 if self.buf.len() == self.pos {
14691 return None;
14692 }
14693 let pos = self.pos;
14694 let mut r#type = None;
14695 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
14696 r#type = Some(header.r#type);
14697 let res = match header.r#type {
14698 1u16 => Ifla6Attrs::Flags({
14699 let res = parse_u32(next);
14700 let Some(val) = res else { break };
14701 val
14702 }),
14703 2u16 => Ifla6Attrs::Conf({
14704 let res = Some(next);
14705 let Some(val) = res else { break };
14706 val
14707 }),
14708 3u16 => Ifla6Attrs::Stats({
14709 let res = Some(next);
14710 let Some(val) = res else { break };
14711 val
14712 }),
14713 4u16 => Ifla6Attrs::Mcast({
14714 let res = Some(next);
14715 let Some(val) = res else { break };
14716 val
14717 }),
14718 5u16 => Ifla6Attrs::Cacheinfo({
14719 let res = PushIflaCacheinfo::new_from_slice(next);
14720 let Some(val) = res else { break };
14721 val
14722 }),
14723 6u16 => Ifla6Attrs::Icmp6stats({
14724 let res = Some(next);
14725 let Some(val) = res else { break };
14726 val
14727 }),
14728 7u16 => Ifla6Attrs::Token({
14729 let res = Some(next);
14730 let Some(val) = res else { break };
14731 val
14732 }),
14733 8u16 => Ifla6Attrs::AddrGenMode({
14734 let res = parse_u8(next);
14735 let Some(val) = res else { break };
14736 val
14737 }),
14738 9u16 => Ifla6Attrs::RaMtu({
14739 let res = parse_u32(next);
14740 let Some(val) = res else { break };
14741 val
14742 }),
14743 n => {
14744 if cfg!(any(test, feature = "deny-unknown-attrs")) {
14745 break;
14746 } else {
14747 continue;
14748 }
14749 }
14750 };
14751 return Some(Ok(res));
14752 }
14753 Some(Err(ErrorContext::new(
14754 "Ifla6Attrs",
14755 r#type.and_then(|t| Ifla6Attrs::attr_from_type(t)),
14756 self.orig_loc,
14757 self.buf.as_ptr().wrapping_add(pos) as usize,
14758 )))
14759 }
14760}
14761impl<'a> std::fmt::Debug for IterableIfla6Attrs<'_> {
14762 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14763 let mut fmt = f.debug_struct("Ifla6Attrs");
14764 for attr in self.clone() {
14765 let attr = match attr {
14766 Ok(a) => a,
14767 Err(err) => {
14768 fmt.finish()?;
14769 f.write_str("Err(")?;
14770 err.fmt(f)?;
14771 return f.write_str(")");
14772 }
14773 };
14774 match attr {
14775 Ifla6Attrs::Flags(val) => fmt.field("Flags", &val),
14776 Ifla6Attrs::Conf(val) => fmt.field("Conf", &val),
14777 Ifla6Attrs::Stats(val) => fmt.field("Stats", &val),
14778 Ifla6Attrs::Mcast(val) => fmt.field("Mcast", &val),
14779 Ifla6Attrs::Cacheinfo(val) => fmt.field("Cacheinfo", &val),
14780 Ifla6Attrs::Icmp6stats(val) => fmt.field("Icmp6stats", &val),
14781 Ifla6Attrs::Token(val) => fmt.field("Token", &val),
14782 Ifla6Attrs::AddrGenMode(val) => fmt.field("AddrGenMode", &val),
14783 Ifla6Attrs::RaMtu(val) => fmt.field("RaMtu", &val),
14784 };
14785 }
14786 fmt.finish()
14787 }
14788}
14789impl IterableIfla6Attrs<'_> {
14790 pub fn lookup_attr(
14791 &self,
14792 offset: usize,
14793 missing_type: Option<u16>,
14794 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
14795 let mut stack = Vec::new();
14796 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
14797 if cur == offset {
14798 stack.push(("Ifla6Attrs", offset));
14799 return (
14800 stack,
14801 missing_type.and_then(|t| Ifla6Attrs::attr_from_type(t)),
14802 );
14803 }
14804 if cur > offset || cur + self.buf.len() < offset {
14805 return (stack, None);
14806 }
14807 let mut attrs = self.clone();
14808 let mut last_off = cur + attrs.pos;
14809 while let Some(attr) = attrs.next() {
14810 let Ok(attr) = attr else { break };
14811 match attr {
14812 Ifla6Attrs::Flags(val) => {
14813 if last_off == offset {
14814 stack.push(("Flags", last_off));
14815 break;
14816 }
14817 }
14818 Ifla6Attrs::Conf(val) => {
14819 if last_off == offset {
14820 stack.push(("Conf", last_off));
14821 break;
14822 }
14823 }
14824 Ifla6Attrs::Stats(val) => {
14825 if last_off == offset {
14826 stack.push(("Stats", last_off));
14827 break;
14828 }
14829 }
14830 Ifla6Attrs::Mcast(val) => {
14831 if last_off == offset {
14832 stack.push(("Mcast", last_off));
14833 break;
14834 }
14835 }
14836 Ifla6Attrs::Cacheinfo(val) => {
14837 if last_off == offset {
14838 stack.push(("Cacheinfo", last_off));
14839 break;
14840 }
14841 }
14842 Ifla6Attrs::Icmp6stats(val) => {
14843 if last_off == offset {
14844 stack.push(("Icmp6stats", last_off));
14845 break;
14846 }
14847 }
14848 Ifla6Attrs::Token(val) => {
14849 if last_off == offset {
14850 stack.push(("Token", last_off));
14851 break;
14852 }
14853 }
14854 Ifla6Attrs::AddrGenMode(val) => {
14855 if last_off == offset {
14856 stack.push(("AddrGenMode", last_off));
14857 break;
14858 }
14859 }
14860 Ifla6Attrs::RaMtu(val) => {
14861 if last_off == offset {
14862 stack.push(("RaMtu", last_off));
14863 break;
14864 }
14865 }
14866 _ => {}
14867 };
14868 last_off = cur + attrs.pos;
14869 }
14870 if !stack.is_empty() {
14871 stack.push(("Ifla6Attrs", cur));
14872 }
14873 (stack, None)
14874 }
14875}
14876#[derive(Clone)]
14877pub enum MctpAttrs {
14878 Net(u32),
14879 PhysBinding(u8),
14880}
14881impl<'a> IterableMctpAttrs<'a> {
14882 pub fn get_net(&self) -> Result<u32, ErrorContext> {
14883 let mut iter = self.clone();
14884 iter.pos = 0;
14885 for attr in iter {
14886 if let MctpAttrs::Net(val) = attr? {
14887 return Ok(val);
14888 }
14889 }
14890 Err(ErrorContext::new_missing(
14891 "MctpAttrs",
14892 "Net",
14893 self.orig_loc,
14894 self.buf.as_ptr() as usize,
14895 ))
14896 }
14897 pub fn get_phys_binding(&self) -> Result<u8, ErrorContext> {
14898 let mut iter = self.clone();
14899 iter.pos = 0;
14900 for attr in iter {
14901 if let MctpAttrs::PhysBinding(val) = attr? {
14902 return Ok(val);
14903 }
14904 }
14905 Err(ErrorContext::new_missing(
14906 "MctpAttrs",
14907 "PhysBinding",
14908 self.orig_loc,
14909 self.buf.as_ptr() as usize,
14910 ))
14911 }
14912}
14913impl MctpAttrs {
14914 pub fn new<'a>(buf: &'a [u8]) -> IterableMctpAttrs<'a> {
14915 IterableMctpAttrs::with_loc(buf, buf.as_ptr() as usize)
14916 }
14917 fn attr_from_type(r#type: u16) -> Option<&'static str> {
14918 let res = match r#type {
14919 1u16 => "Net",
14920 2u16 => "PhysBinding",
14921 _ => return None,
14922 };
14923 Some(res)
14924 }
14925}
14926#[derive(Clone, Copy, Default)]
14927pub struct IterableMctpAttrs<'a> {
14928 buf: &'a [u8],
14929 pos: usize,
14930 orig_loc: usize,
14931}
14932impl<'a> IterableMctpAttrs<'a> {
14933 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
14934 Self {
14935 buf,
14936 pos: 0,
14937 orig_loc,
14938 }
14939 }
14940 pub fn get_buf(&self) -> &'a [u8] {
14941 self.buf
14942 }
14943}
14944impl<'a> Iterator for IterableMctpAttrs<'a> {
14945 type Item = Result<MctpAttrs, ErrorContext>;
14946 fn next(&mut self) -> Option<Self::Item> {
14947 if self.buf.len() == self.pos {
14948 return None;
14949 }
14950 let pos = self.pos;
14951 let mut r#type = None;
14952 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
14953 r#type = Some(header.r#type);
14954 let res = match header.r#type {
14955 1u16 => MctpAttrs::Net({
14956 let res = parse_u32(next);
14957 let Some(val) = res else { break };
14958 val
14959 }),
14960 2u16 => MctpAttrs::PhysBinding({
14961 let res = parse_u8(next);
14962 let Some(val) = res else { break };
14963 val
14964 }),
14965 n => {
14966 if cfg!(any(test, feature = "deny-unknown-attrs")) {
14967 break;
14968 } else {
14969 continue;
14970 }
14971 }
14972 };
14973 return Some(Ok(res));
14974 }
14975 Some(Err(ErrorContext::new(
14976 "MctpAttrs",
14977 r#type.and_then(|t| MctpAttrs::attr_from_type(t)),
14978 self.orig_loc,
14979 self.buf.as_ptr().wrapping_add(pos) as usize,
14980 )))
14981 }
14982}
14983impl std::fmt::Debug for IterableMctpAttrs<'_> {
14984 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14985 let mut fmt = f.debug_struct("MctpAttrs");
14986 for attr in self.clone() {
14987 let attr = match attr {
14988 Ok(a) => a,
14989 Err(err) => {
14990 fmt.finish()?;
14991 f.write_str("Err(")?;
14992 err.fmt(f)?;
14993 return f.write_str(")");
14994 }
14995 };
14996 match attr {
14997 MctpAttrs::Net(val) => fmt.field("Net", &val),
14998 MctpAttrs::PhysBinding(val) => fmt.field("PhysBinding", &val),
14999 };
15000 }
15001 fmt.finish()
15002 }
15003}
15004impl IterableMctpAttrs<'_> {
15005 pub fn lookup_attr(
15006 &self,
15007 offset: usize,
15008 missing_type: Option<u16>,
15009 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15010 let mut stack = Vec::new();
15011 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15012 if cur == offset {
15013 stack.push(("MctpAttrs", offset));
15014 return (
15015 stack,
15016 missing_type.and_then(|t| MctpAttrs::attr_from_type(t)),
15017 );
15018 }
15019 if cur > offset || cur + self.buf.len() < offset {
15020 return (stack, None);
15021 }
15022 let mut attrs = self.clone();
15023 let mut last_off = cur + attrs.pos;
15024 while let Some(attr) = attrs.next() {
15025 let Ok(attr) = attr else { break };
15026 match attr {
15027 MctpAttrs::Net(val) => {
15028 if last_off == offset {
15029 stack.push(("Net", last_off));
15030 break;
15031 }
15032 }
15033 MctpAttrs::PhysBinding(val) => {
15034 if last_off == offset {
15035 stack.push(("PhysBinding", last_off));
15036 break;
15037 }
15038 }
15039 _ => {}
15040 };
15041 last_off = cur + attrs.pos;
15042 }
15043 if !stack.is_empty() {
15044 stack.push(("MctpAttrs", cur));
15045 }
15046 (stack, None)
15047 }
15048}
15049#[derive(Clone)]
15050pub enum StatsAttrs<'a> {
15051 Link64(PushRtnlLinkStats64),
15052 LinkXstats(&'a [u8]),
15053 LinkXstatsSlave(&'a [u8]),
15054 LinkOffloadXstats(IterableLinkOffloadXstats<'a>),
15055 AfSpec(&'a [u8]),
15056}
15057impl<'a> IterableStatsAttrs<'a> {
15058 pub fn get_link_64(&self) -> Result<PushRtnlLinkStats64, ErrorContext> {
15059 let mut iter = self.clone();
15060 iter.pos = 0;
15061 for attr in iter {
15062 if let StatsAttrs::Link64(val) = attr? {
15063 return Ok(val);
15064 }
15065 }
15066 Err(ErrorContext::new_missing(
15067 "StatsAttrs",
15068 "Link64",
15069 self.orig_loc,
15070 self.buf.as_ptr() as usize,
15071 ))
15072 }
15073 pub fn get_link_xstats(&self) -> Result<&'a [u8], ErrorContext> {
15074 let mut iter = self.clone();
15075 iter.pos = 0;
15076 for attr in iter {
15077 if let StatsAttrs::LinkXstats(val) = attr? {
15078 return Ok(val);
15079 }
15080 }
15081 Err(ErrorContext::new_missing(
15082 "StatsAttrs",
15083 "LinkXstats",
15084 self.orig_loc,
15085 self.buf.as_ptr() as usize,
15086 ))
15087 }
15088 pub fn get_link_xstats_slave(&self) -> Result<&'a [u8], ErrorContext> {
15089 let mut iter = self.clone();
15090 iter.pos = 0;
15091 for attr in iter {
15092 if let StatsAttrs::LinkXstatsSlave(val) = attr? {
15093 return Ok(val);
15094 }
15095 }
15096 Err(ErrorContext::new_missing(
15097 "StatsAttrs",
15098 "LinkXstatsSlave",
15099 self.orig_loc,
15100 self.buf.as_ptr() as usize,
15101 ))
15102 }
15103 pub fn get_link_offload_xstats(&self) -> Result<IterableLinkOffloadXstats<'a>, ErrorContext> {
15104 let mut iter = self.clone();
15105 iter.pos = 0;
15106 for attr in iter {
15107 if let StatsAttrs::LinkOffloadXstats(val) = attr? {
15108 return Ok(val);
15109 }
15110 }
15111 Err(ErrorContext::new_missing(
15112 "StatsAttrs",
15113 "LinkOffloadXstats",
15114 self.orig_loc,
15115 self.buf.as_ptr() as usize,
15116 ))
15117 }
15118 pub fn get_af_spec(&self) -> Result<&'a [u8], ErrorContext> {
15119 let mut iter = self.clone();
15120 iter.pos = 0;
15121 for attr in iter {
15122 if let StatsAttrs::AfSpec(val) = attr? {
15123 return Ok(val);
15124 }
15125 }
15126 Err(ErrorContext::new_missing(
15127 "StatsAttrs",
15128 "AfSpec",
15129 self.orig_loc,
15130 self.buf.as_ptr() as usize,
15131 ))
15132 }
15133}
15134impl StatsAttrs<'_> {
15135 pub fn new<'a>(buf: &'a [u8]) -> IterableStatsAttrs<'a> {
15136 IterableStatsAttrs::with_loc(buf, buf.as_ptr() as usize)
15137 }
15138 fn attr_from_type(r#type: u16) -> Option<&'static str> {
15139 let res = match r#type {
15140 1u16 => "Link64",
15141 2u16 => "LinkXstats",
15142 3u16 => "LinkXstatsSlave",
15143 4u16 => "LinkOffloadXstats",
15144 5u16 => "AfSpec",
15145 _ => return None,
15146 };
15147 Some(res)
15148 }
15149}
15150#[derive(Clone, Copy, Default)]
15151pub struct IterableStatsAttrs<'a> {
15152 buf: &'a [u8],
15153 pos: usize,
15154 orig_loc: usize,
15155}
15156impl<'a> IterableStatsAttrs<'a> {
15157 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15158 Self {
15159 buf,
15160 pos: 0,
15161 orig_loc,
15162 }
15163 }
15164 pub fn get_buf(&self) -> &'a [u8] {
15165 self.buf
15166 }
15167}
15168impl<'a> Iterator for IterableStatsAttrs<'a> {
15169 type Item = Result<StatsAttrs<'a>, ErrorContext>;
15170 fn next(&mut self) -> Option<Self::Item> {
15171 if self.buf.len() == self.pos {
15172 return None;
15173 }
15174 let pos = self.pos;
15175 let mut r#type = None;
15176 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
15177 r#type = Some(header.r#type);
15178 let res = match header.r#type {
15179 1u16 => StatsAttrs::Link64({
15180 let res = PushRtnlLinkStats64::new_from_slice(next);
15181 let Some(val) = res else { break };
15182 val
15183 }),
15184 2u16 => StatsAttrs::LinkXstats({
15185 let res = Some(next);
15186 let Some(val) = res else { break };
15187 val
15188 }),
15189 3u16 => StatsAttrs::LinkXstatsSlave({
15190 let res = Some(next);
15191 let Some(val) = res else { break };
15192 val
15193 }),
15194 4u16 => StatsAttrs::LinkOffloadXstats({
15195 let res = Some(IterableLinkOffloadXstats::with_loc(next, self.orig_loc));
15196 let Some(val) = res else { break };
15197 val
15198 }),
15199 5u16 => StatsAttrs::AfSpec({
15200 let res = Some(next);
15201 let Some(val) = res else { break };
15202 val
15203 }),
15204 n => {
15205 if cfg!(any(test, feature = "deny-unknown-attrs")) {
15206 break;
15207 } else {
15208 continue;
15209 }
15210 }
15211 };
15212 return Some(Ok(res));
15213 }
15214 Some(Err(ErrorContext::new(
15215 "StatsAttrs",
15216 r#type.and_then(|t| StatsAttrs::attr_from_type(t)),
15217 self.orig_loc,
15218 self.buf.as_ptr().wrapping_add(pos) as usize,
15219 )))
15220 }
15221}
15222impl<'a> std::fmt::Debug for IterableStatsAttrs<'_> {
15223 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15224 let mut fmt = f.debug_struct("StatsAttrs");
15225 for attr in self.clone() {
15226 let attr = match attr {
15227 Ok(a) => a,
15228 Err(err) => {
15229 fmt.finish()?;
15230 f.write_str("Err(")?;
15231 err.fmt(f)?;
15232 return f.write_str(")");
15233 }
15234 };
15235 match attr {
15236 StatsAttrs::Link64(val) => fmt.field("Link64", &val),
15237 StatsAttrs::LinkXstats(val) => fmt.field("LinkXstats", &val),
15238 StatsAttrs::LinkXstatsSlave(val) => fmt.field("LinkXstatsSlave", &val),
15239 StatsAttrs::LinkOffloadXstats(val) => fmt.field("LinkOffloadXstats", &val),
15240 StatsAttrs::AfSpec(val) => fmt.field("AfSpec", &val),
15241 };
15242 }
15243 fmt.finish()
15244 }
15245}
15246impl IterableStatsAttrs<'_> {
15247 pub fn lookup_attr(
15248 &self,
15249 offset: usize,
15250 missing_type: Option<u16>,
15251 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15252 let mut stack = Vec::new();
15253 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15254 if cur == offset {
15255 stack.push(("StatsAttrs", offset));
15256 return (
15257 stack,
15258 missing_type.and_then(|t| StatsAttrs::attr_from_type(t)),
15259 );
15260 }
15261 if cur > offset || cur + self.buf.len() < offset {
15262 return (stack, None);
15263 }
15264 let mut attrs = self.clone();
15265 let mut last_off = cur + attrs.pos;
15266 let mut missing = None;
15267 while let Some(attr) = attrs.next() {
15268 let Ok(attr) = attr else { break };
15269 match attr {
15270 StatsAttrs::Link64(val) => {
15271 if last_off == offset {
15272 stack.push(("Link64", last_off));
15273 break;
15274 }
15275 }
15276 StatsAttrs::LinkXstats(val) => {
15277 if last_off == offset {
15278 stack.push(("LinkXstats", last_off));
15279 break;
15280 }
15281 }
15282 StatsAttrs::LinkXstatsSlave(val) => {
15283 if last_off == offset {
15284 stack.push(("LinkXstatsSlave", last_off));
15285 break;
15286 }
15287 }
15288 StatsAttrs::LinkOffloadXstats(val) => {
15289 (stack, missing) = val.lookup_attr(offset, missing_type);
15290 if !stack.is_empty() {
15291 break;
15292 }
15293 }
15294 StatsAttrs::AfSpec(val) => {
15295 if last_off == offset {
15296 stack.push(("AfSpec", last_off));
15297 break;
15298 }
15299 }
15300 _ => {}
15301 };
15302 last_off = cur + attrs.pos;
15303 }
15304 if !stack.is_empty() {
15305 stack.push(("StatsAttrs", cur));
15306 }
15307 (stack, missing)
15308 }
15309}
15310#[derive(Clone)]
15311pub enum LinkOffloadXstats<'a> {
15312 CpuHit(&'a [u8]),
15313 HwSInfo(IterableArrayHwSInfoOne<'a>),
15314 L3Stats(&'a [u8]),
15315}
15316impl<'a> IterableLinkOffloadXstats<'a> {
15317 pub fn get_cpu_hit(&self) -> Result<&'a [u8], ErrorContext> {
15318 let mut iter = self.clone();
15319 iter.pos = 0;
15320 for attr in iter {
15321 if let LinkOffloadXstats::CpuHit(val) = attr? {
15322 return Ok(val);
15323 }
15324 }
15325 Err(ErrorContext::new_missing(
15326 "LinkOffloadXstats",
15327 "CpuHit",
15328 self.orig_loc,
15329 self.buf.as_ptr() as usize,
15330 ))
15331 }
15332 pub fn get_hw_s_info(
15333 &self,
15334 ) -> Result<ArrayIterable<IterableArrayHwSInfoOne<'a>, IterableHwSInfoOne<'a>>, ErrorContext>
15335 {
15336 for attr in self.clone() {
15337 if let LinkOffloadXstats::HwSInfo(val) = attr? {
15338 return Ok(ArrayIterable::new(val));
15339 }
15340 }
15341 Err(ErrorContext::new_missing(
15342 "LinkOffloadXstats",
15343 "HwSInfo",
15344 self.orig_loc,
15345 self.buf.as_ptr() as usize,
15346 ))
15347 }
15348 pub fn get_l3_stats(&self) -> Result<&'a [u8], ErrorContext> {
15349 let mut iter = self.clone();
15350 iter.pos = 0;
15351 for attr in iter {
15352 if let LinkOffloadXstats::L3Stats(val) = attr? {
15353 return Ok(val);
15354 }
15355 }
15356 Err(ErrorContext::new_missing(
15357 "LinkOffloadXstats",
15358 "L3Stats",
15359 self.orig_loc,
15360 self.buf.as_ptr() as usize,
15361 ))
15362 }
15363}
15364impl HwSInfoOne {
15365 pub fn new_array(buf: &[u8]) -> IterableArrayHwSInfoOne<'_> {
15366 IterableArrayHwSInfoOne::with_loc(buf, buf.as_ptr() as usize)
15367 }
15368}
15369#[derive(Clone, Copy, Default)]
15370pub struct IterableArrayHwSInfoOne<'a> {
15371 buf: &'a [u8],
15372 pos: usize,
15373 orig_loc: usize,
15374}
15375impl<'a> IterableArrayHwSInfoOne<'a> {
15376 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15377 Self {
15378 buf,
15379 pos: 0,
15380 orig_loc,
15381 }
15382 }
15383 pub fn get_buf(&self) -> &'a [u8] {
15384 self.buf
15385 }
15386}
15387impl<'a> Iterator for IterableArrayHwSInfoOne<'a> {
15388 type Item = Result<IterableHwSInfoOne<'a>, ErrorContext>;
15389 fn next(&mut self) -> Option<Self::Item> {
15390 if self.buf.len() == self.pos {
15391 return None;
15392 }
15393 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
15394 {
15395 return Some(Ok(IterableHwSInfoOne::with_loc(next, self.orig_loc)));
15396 }
15397 }
15398 Some(Err(ErrorContext::new(
15399 "HwSInfoOne",
15400 None,
15401 self.orig_loc,
15402 self.buf.as_ptr().wrapping_add(self.pos) as usize,
15403 )))
15404 }
15405}
15406impl LinkOffloadXstats<'_> {
15407 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkOffloadXstats<'a> {
15408 IterableLinkOffloadXstats::with_loc(buf, buf.as_ptr() as usize)
15409 }
15410 fn attr_from_type(r#type: u16) -> Option<&'static str> {
15411 let res = match r#type {
15412 1u16 => "CpuHit",
15413 2u16 => "HwSInfo",
15414 3u16 => "L3Stats",
15415 _ => return None,
15416 };
15417 Some(res)
15418 }
15419}
15420#[derive(Clone, Copy, Default)]
15421pub struct IterableLinkOffloadXstats<'a> {
15422 buf: &'a [u8],
15423 pos: usize,
15424 orig_loc: usize,
15425}
15426impl<'a> IterableLinkOffloadXstats<'a> {
15427 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15428 Self {
15429 buf,
15430 pos: 0,
15431 orig_loc,
15432 }
15433 }
15434 pub fn get_buf(&self) -> &'a [u8] {
15435 self.buf
15436 }
15437}
15438impl<'a> Iterator for IterableLinkOffloadXstats<'a> {
15439 type Item = Result<LinkOffloadXstats<'a>, ErrorContext>;
15440 fn next(&mut self) -> Option<Self::Item> {
15441 if self.buf.len() == self.pos {
15442 return None;
15443 }
15444 let pos = self.pos;
15445 let mut r#type = None;
15446 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
15447 r#type = Some(header.r#type);
15448 let res = match header.r#type {
15449 1u16 => LinkOffloadXstats::CpuHit({
15450 let res = Some(next);
15451 let Some(val) = res else { break };
15452 val
15453 }),
15454 2u16 => LinkOffloadXstats::HwSInfo({
15455 let res = Some(IterableArrayHwSInfoOne::with_loc(next, self.orig_loc));
15456 let Some(val) = res else { break };
15457 val
15458 }),
15459 3u16 => LinkOffloadXstats::L3Stats({
15460 let res = Some(next);
15461 let Some(val) = res else { break };
15462 val
15463 }),
15464 n => {
15465 if cfg!(any(test, feature = "deny-unknown-attrs")) {
15466 break;
15467 } else {
15468 continue;
15469 }
15470 }
15471 };
15472 return Some(Ok(res));
15473 }
15474 Some(Err(ErrorContext::new(
15475 "LinkOffloadXstats",
15476 r#type.and_then(|t| LinkOffloadXstats::attr_from_type(t)),
15477 self.orig_loc,
15478 self.buf.as_ptr().wrapping_add(pos) as usize,
15479 )))
15480 }
15481}
15482impl std::fmt::Debug for IterableArrayHwSInfoOne<'_> {
15483 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15484 fmt.debug_list()
15485 .entries(self.clone().map(FlattenErrorContext))
15486 .finish()
15487 }
15488}
15489impl<'a> std::fmt::Debug for IterableLinkOffloadXstats<'_> {
15490 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15491 let mut fmt = f.debug_struct("LinkOffloadXstats");
15492 for attr in self.clone() {
15493 let attr = match attr {
15494 Ok(a) => a,
15495 Err(err) => {
15496 fmt.finish()?;
15497 f.write_str("Err(")?;
15498 err.fmt(f)?;
15499 return f.write_str(")");
15500 }
15501 };
15502 match attr {
15503 LinkOffloadXstats::CpuHit(val) => fmt.field("CpuHit", &val),
15504 LinkOffloadXstats::HwSInfo(val) => fmt.field("HwSInfo", &val),
15505 LinkOffloadXstats::L3Stats(val) => fmt.field("L3Stats", &val),
15506 };
15507 }
15508 fmt.finish()
15509 }
15510}
15511impl IterableLinkOffloadXstats<'_> {
15512 pub fn lookup_attr(
15513 &self,
15514 offset: usize,
15515 missing_type: Option<u16>,
15516 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15517 let mut stack = Vec::new();
15518 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15519 if cur == offset {
15520 stack.push(("LinkOffloadXstats", offset));
15521 return (
15522 stack,
15523 missing_type.and_then(|t| LinkOffloadXstats::attr_from_type(t)),
15524 );
15525 }
15526 if cur > offset || cur + self.buf.len() < offset {
15527 return (stack, None);
15528 }
15529 let mut attrs = self.clone();
15530 let mut last_off = cur + attrs.pos;
15531 let mut missing = None;
15532 while let Some(attr) = attrs.next() {
15533 let Ok(attr) = attr else { break };
15534 match attr {
15535 LinkOffloadXstats::CpuHit(val) => {
15536 if last_off == offset {
15537 stack.push(("CpuHit", last_off));
15538 break;
15539 }
15540 }
15541 LinkOffloadXstats::HwSInfo(val) => {
15542 for entry in val {
15543 let Ok(attr) = entry else { break };
15544 (stack, missing) = attr.lookup_attr(offset, missing_type);
15545 if !stack.is_empty() {
15546 break;
15547 }
15548 }
15549 if !stack.is_empty() {
15550 stack.push(("HwSInfo", last_off));
15551 break;
15552 }
15553 }
15554 LinkOffloadXstats::L3Stats(val) => {
15555 if last_off == offset {
15556 stack.push(("L3Stats", last_off));
15557 break;
15558 }
15559 }
15560 _ => {}
15561 };
15562 last_off = cur + attrs.pos;
15563 }
15564 if !stack.is_empty() {
15565 stack.push(("LinkOffloadXstats", cur));
15566 }
15567 (stack, missing)
15568 }
15569}
15570#[derive(Clone)]
15571pub enum HwSInfoOne {
15572 Request(u8),
15573 Used(u8),
15574}
15575impl<'a> IterableHwSInfoOne<'a> {
15576 pub fn get_request(&self) -> Result<u8, ErrorContext> {
15577 let mut iter = self.clone();
15578 iter.pos = 0;
15579 for attr in iter {
15580 if let HwSInfoOne::Request(val) = attr? {
15581 return Ok(val);
15582 }
15583 }
15584 Err(ErrorContext::new_missing(
15585 "HwSInfoOne",
15586 "Request",
15587 self.orig_loc,
15588 self.buf.as_ptr() as usize,
15589 ))
15590 }
15591 pub fn get_used(&self) -> Result<u8, ErrorContext> {
15592 let mut iter = self.clone();
15593 iter.pos = 0;
15594 for attr in iter {
15595 if let HwSInfoOne::Used(val) = attr? {
15596 return Ok(val);
15597 }
15598 }
15599 Err(ErrorContext::new_missing(
15600 "HwSInfoOne",
15601 "Used",
15602 self.orig_loc,
15603 self.buf.as_ptr() as usize,
15604 ))
15605 }
15606}
15607impl HwSInfoOne {
15608 pub fn new<'a>(buf: &'a [u8]) -> IterableHwSInfoOne<'a> {
15609 IterableHwSInfoOne::with_loc(buf, buf.as_ptr() as usize)
15610 }
15611 fn attr_from_type(r#type: u16) -> Option<&'static str> {
15612 let res = match r#type {
15613 1u16 => "Request",
15614 2u16 => "Used",
15615 _ => return None,
15616 };
15617 Some(res)
15618 }
15619}
15620#[derive(Clone, Copy, Default)]
15621pub struct IterableHwSInfoOne<'a> {
15622 buf: &'a [u8],
15623 pos: usize,
15624 orig_loc: usize,
15625}
15626impl<'a> IterableHwSInfoOne<'a> {
15627 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15628 Self {
15629 buf,
15630 pos: 0,
15631 orig_loc,
15632 }
15633 }
15634 pub fn get_buf(&self) -> &'a [u8] {
15635 self.buf
15636 }
15637}
15638impl<'a> Iterator for IterableHwSInfoOne<'a> {
15639 type Item = Result<HwSInfoOne, ErrorContext>;
15640 fn next(&mut self) -> Option<Self::Item> {
15641 if self.buf.len() == self.pos {
15642 return None;
15643 }
15644 let pos = self.pos;
15645 let mut r#type = None;
15646 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
15647 r#type = Some(header.r#type);
15648 let res = match header.r#type {
15649 1u16 => HwSInfoOne::Request({
15650 let res = parse_u8(next);
15651 let Some(val) = res else { break };
15652 val
15653 }),
15654 2u16 => HwSInfoOne::Used({
15655 let res = parse_u8(next);
15656 let Some(val) = res else { break };
15657 val
15658 }),
15659 n => {
15660 if cfg!(any(test, feature = "deny-unknown-attrs")) {
15661 break;
15662 } else {
15663 continue;
15664 }
15665 }
15666 };
15667 return Some(Ok(res));
15668 }
15669 Some(Err(ErrorContext::new(
15670 "HwSInfoOne",
15671 r#type.and_then(|t| HwSInfoOne::attr_from_type(t)),
15672 self.orig_loc,
15673 self.buf.as_ptr().wrapping_add(pos) as usize,
15674 )))
15675 }
15676}
15677impl std::fmt::Debug for IterableHwSInfoOne<'_> {
15678 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15679 let mut fmt = f.debug_struct("HwSInfoOne");
15680 for attr in self.clone() {
15681 let attr = match attr {
15682 Ok(a) => a,
15683 Err(err) => {
15684 fmt.finish()?;
15685 f.write_str("Err(")?;
15686 err.fmt(f)?;
15687 return f.write_str(")");
15688 }
15689 };
15690 match attr {
15691 HwSInfoOne::Request(val) => fmt.field("Request", &val),
15692 HwSInfoOne::Used(val) => fmt.field("Used", &val),
15693 };
15694 }
15695 fmt.finish()
15696 }
15697}
15698impl IterableHwSInfoOne<'_> {
15699 pub fn lookup_attr(
15700 &self,
15701 offset: usize,
15702 missing_type: Option<u16>,
15703 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15704 let mut stack = Vec::new();
15705 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15706 if cur == offset {
15707 stack.push(("HwSInfoOne", offset));
15708 return (
15709 stack,
15710 missing_type.and_then(|t| HwSInfoOne::attr_from_type(t)),
15711 );
15712 }
15713 if cur > offset || cur + self.buf.len() < offset {
15714 return (stack, None);
15715 }
15716 let mut attrs = self.clone();
15717 let mut last_off = cur + attrs.pos;
15718 while let Some(attr) = attrs.next() {
15719 let Ok(attr) = attr else { break };
15720 match attr {
15721 HwSInfoOne::Request(val) => {
15722 if last_off == offset {
15723 stack.push(("Request", last_off));
15724 break;
15725 }
15726 }
15727 HwSInfoOne::Used(val) => {
15728 if last_off == offset {
15729 stack.push(("Used", last_off));
15730 break;
15731 }
15732 }
15733 _ => {}
15734 };
15735 last_off = cur + attrs.pos;
15736 }
15737 if !stack.is_empty() {
15738 stack.push(("HwSInfoOne", cur));
15739 }
15740 (stack, None)
15741 }
15742}
15743#[derive(Clone)]
15744pub enum LinkDpllPinAttrs {
15745 Id(u32),
15746}
15747impl<'a> IterableLinkDpllPinAttrs<'a> {
15748 pub fn get_id(&self) -> Result<u32, ErrorContext> {
15749 let mut iter = self.clone();
15750 iter.pos = 0;
15751 for attr in iter {
15752 if let LinkDpllPinAttrs::Id(val) = attr? {
15753 return Ok(val);
15754 }
15755 }
15756 Err(ErrorContext::new_missing(
15757 "LinkDpllPinAttrs",
15758 "Id",
15759 self.orig_loc,
15760 self.buf.as_ptr() as usize,
15761 ))
15762 }
15763}
15764impl LinkDpllPinAttrs {
15765 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkDpllPinAttrs<'a> {
15766 IterableLinkDpllPinAttrs::with_loc(buf, buf.as_ptr() as usize)
15767 }
15768 fn attr_from_type(r#type: u16) -> Option<&'static str> {
15769 let res = match r#type {
15770 1u16 => "Id",
15771 _ => return None,
15772 };
15773 Some(res)
15774 }
15775}
15776#[derive(Clone, Copy, Default)]
15777pub struct IterableLinkDpllPinAttrs<'a> {
15778 buf: &'a [u8],
15779 pos: usize,
15780 orig_loc: usize,
15781}
15782impl<'a> IterableLinkDpllPinAttrs<'a> {
15783 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15784 Self {
15785 buf,
15786 pos: 0,
15787 orig_loc,
15788 }
15789 }
15790 pub fn get_buf(&self) -> &'a [u8] {
15791 self.buf
15792 }
15793}
15794impl<'a> Iterator for IterableLinkDpllPinAttrs<'a> {
15795 type Item = Result<LinkDpllPinAttrs, ErrorContext>;
15796 fn next(&mut self) -> Option<Self::Item> {
15797 if self.buf.len() == self.pos {
15798 return None;
15799 }
15800 let pos = self.pos;
15801 let mut r#type = None;
15802 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
15803 r#type = Some(header.r#type);
15804 let res = match header.r#type {
15805 1u16 => LinkDpllPinAttrs::Id({
15806 let res = parse_u32(next);
15807 let Some(val) = res else { break };
15808 val
15809 }),
15810 n => {
15811 if cfg!(any(test, feature = "deny-unknown-attrs")) {
15812 break;
15813 } else {
15814 continue;
15815 }
15816 }
15817 };
15818 return Some(Ok(res));
15819 }
15820 Some(Err(ErrorContext::new(
15821 "LinkDpllPinAttrs",
15822 r#type.and_then(|t| LinkDpllPinAttrs::attr_from_type(t)),
15823 self.orig_loc,
15824 self.buf.as_ptr().wrapping_add(pos) as usize,
15825 )))
15826 }
15827}
15828impl std::fmt::Debug for IterableLinkDpllPinAttrs<'_> {
15829 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15830 let mut fmt = f.debug_struct("LinkDpllPinAttrs");
15831 for attr in self.clone() {
15832 let attr = match attr {
15833 Ok(a) => a,
15834 Err(err) => {
15835 fmt.finish()?;
15836 f.write_str("Err(")?;
15837 err.fmt(f)?;
15838 return f.write_str(")");
15839 }
15840 };
15841 match attr {
15842 LinkDpllPinAttrs::Id(val) => fmt.field("Id", &val),
15843 };
15844 }
15845 fmt.finish()
15846 }
15847}
15848impl IterableLinkDpllPinAttrs<'_> {
15849 pub fn lookup_attr(
15850 &self,
15851 offset: usize,
15852 missing_type: Option<u16>,
15853 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15854 let mut stack = Vec::new();
15855 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15856 if cur == offset {
15857 stack.push(("LinkDpllPinAttrs", offset));
15858 return (
15859 stack,
15860 missing_type.and_then(|t| LinkDpllPinAttrs::attr_from_type(t)),
15861 );
15862 }
15863 if cur > offset || cur + self.buf.len() < offset {
15864 return (stack, None);
15865 }
15866 let mut attrs = self.clone();
15867 let mut last_off = cur + attrs.pos;
15868 while let Some(attr) = attrs.next() {
15869 let Ok(attr) = attr else { break };
15870 match attr {
15871 LinkDpllPinAttrs::Id(val) => {
15872 if last_off == offset {
15873 stack.push(("Id", last_off));
15874 break;
15875 }
15876 }
15877 _ => {}
15878 };
15879 last_off = cur + attrs.pos;
15880 }
15881 if !stack.is_empty() {
15882 stack.push(("LinkDpllPinAttrs", cur));
15883 }
15884 (stack, None)
15885 }
15886}
15887#[derive(Clone)]
15888pub enum LinkinfoNetkitAttrs<'a> {
15889 PeerInfo(&'a [u8]),
15890 Primary(u8),
15891 #[doc = "Associated type: \"NetkitPolicy\" (enum)"]
15892 Policy(u32),
15893 #[doc = "Associated type: \"NetkitPolicy\" (enum)"]
15894 PeerPolicy(u32),
15895 #[doc = "Associated type: \"NetkitMode\" (enum)"]
15896 Mode(u32),
15897 #[doc = "Associated type: \"NetkitScrub\" (enum)"]
15898 Scrub(u32),
15899 #[doc = "Associated type: \"NetkitScrub\" (enum)"]
15900 PeerScrub(u32),
15901 Headroom(u16),
15902 Tailroom(u16),
15903}
15904impl<'a> IterableLinkinfoNetkitAttrs<'a> {
15905 pub fn get_peer_info(&self) -> Result<&'a [u8], ErrorContext> {
15906 let mut iter = self.clone();
15907 iter.pos = 0;
15908 for attr in iter {
15909 if let LinkinfoNetkitAttrs::PeerInfo(val) = attr? {
15910 return Ok(val);
15911 }
15912 }
15913 Err(ErrorContext::new_missing(
15914 "LinkinfoNetkitAttrs",
15915 "PeerInfo",
15916 self.orig_loc,
15917 self.buf.as_ptr() as usize,
15918 ))
15919 }
15920 pub fn get_primary(&self) -> Result<u8, ErrorContext> {
15921 let mut iter = self.clone();
15922 iter.pos = 0;
15923 for attr in iter {
15924 if let LinkinfoNetkitAttrs::Primary(val) = attr? {
15925 return Ok(val);
15926 }
15927 }
15928 Err(ErrorContext::new_missing(
15929 "LinkinfoNetkitAttrs",
15930 "Primary",
15931 self.orig_loc,
15932 self.buf.as_ptr() as usize,
15933 ))
15934 }
15935 #[doc = "Associated type: \"NetkitPolicy\" (enum)"]
15936 pub fn get_policy(&self) -> Result<u32, ErrorContext> {
15937 let mut iter = self.clone();
15938 iter.pos = 0;
15939 for attr in iter {
15940 if let LinkinfoNetkitAttrs::Policy(val) = attr? {
15941 return Ok(val);
15942 }
15943 }
15944 Err(ErrorContext::new_missing(
15945 "LinkinfoNetkitAttrs",
15946 "Policy",
15947 self.orig_loc,
15948 self.buf.as_ptr() as usize,
15949 ))
15950 }
15951 #[doc = "Associated type: \"NetkitPolicy\" (enum)"]
15952 pub fn get_peer_policy(&self) -> Result<u32, ErrorContext> {
15953 let mut iter = self.clone();
15954 iter.pos = 0;
15955 for attr in iter {
15956 if let LinkinfoNetkitAttrs::PeerPolicy(val) = attr? {
15957 return Ok(val);
15958 }
15959 }
15960 Err(ErrorContext::new_missing(
15961 "LinkinfoNetkitAttrs",
15962 "PeerPolicy",
15963 self.orig_loc,
15964 self.buf.as_ptr() as usize,
15965 ))
15966 }
15967 #[doc = "Associated type: \"NetkitMode\" (enum)"]
15968 pub fn get_mode(&self) -> Result<u32, ErrorContext> {
15969 let mut iter = self.clone();
15970 iter.pos = 0;
15971 for attr in iter {
15972 if let LinkinfoNetkitAttrs::Mode(val) = attr? {
15973 return Ok(val);
15974 }
15975 }
15976 Err(ErrorContext::new_missing(
15977 "LinkinfoNetkitAttrs",
15978 "Mode",
15979 self.orig_loc,
15980 self.buf.as_ptr() as usize,
15981 ))
15982 }
15983 #[doc = "Associated type: \"NetkitScrub\" (enum)"]
15984 pub fn get_scrub(&self) -> Result<u32, ErrorContext> {
15985 let mut iter = self.clone();
15986 iter.pos = 0;
15987 for attr in iter {
15988 if let LinkinfoNetkitAttrs::Scrub(val) = attr? {
15989 return Ok(val);
15990 }
15991 }
15992 Err(ErrorContext::new_missing(
15993 "LinkinfoNetkitAttrs",
15994 "Scrub",
15995 self.orig_loc,
15996 self.buf.as_ptr() as usize,
15997 ))
15998 }
15999 #[doc = "Associated type: \"NetkitScrub\" (enum)"]
16000 pub fn get_peer_scrub(&self) -> Result<u32, ErrorContext> {
16001 let mut iter = self.clone();
16002 iter.pos = 0;
16003 for attr in iter {
16004 if let LinkinfoNetkitAttrs::PeerScrub(val) = attr? {
16005 return Ok(val);
16006 }
16007 }
16008 Err(ErrorContext::new_missing(
16009 "LinkinfoNetkitAttrs",
16010 "PeerScrub",
16011 self.orig_loc,
16012 self.buf.as_ptr() as usize,
16013 ))
16014 }
16015 pub fn get_headroom(&self) -> Result<u16, ErrorContext> {
16016 let mut iter = self.clone();
16017 iter.pos = 0;
16018 for attr in iter {
16019 if let LinkinfoNetkitAttrs::Headroom(val) = attr? {
16020 return Ok(val);
16021 }
16022 }
16023 Err(ErrorContext::new_missing(
16024 "LinkinfoNetkitAttrs",
16025 "Headroom",
16026 self.orig_loc,
16027 self.buf.as_ptr() as usize,
16028 ))
16029 }
16030 pub fn get_tailroom(&self) -> Result<u16, ErrorContext> {
16031 let mut iter = self.clone();
16032 iter.pos = 0;
16033 for attr in iter {
16034 if let LinkinfoNetkitAttrs::Tailroom(val) = attr? {
16035 return Ok(val);
16036 }
16037 }
16038 Err(ErrorContext::new_missing(
16039 "LinkinfoNetkitAttrs",
16040 "Tailroom",
16041 self.orig_loc,
16042 self.buf.as_ptr() as usize,
16043 ))
16044 }
16045}
16046impl LinkinfoNetkitAttrs<'_> {
16047 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoNetkitAttrs<'a> {
16048 IterableLinkinfoNetkitAttrs::with_loc(buf, buf.as_ptr() as usize)
16049 }
16050 fn attr_from_type(r#type: u16) -> Option<&'static str> {
16051 let res = match r#type {
16052 1u16 => "PeerInfo",
16053 2u16 => "Primary",
16054 3u16 => "Policy",
16055 4u16 => "PeerPolicy",
16056 5u16 => "Mode",
16057 6u16 => "Scrub",
16058 7u16 => "PeerScrub",
16059 8u16 => "Headroom",
16060 9u16 => "Tailroom",
16061 _ => return None,
16062 };
16063 Some(res)
16064 }
16065}
16066#[derive(Clone, Copy, Default)]
16067pub struct IterableLinkinfoNetkitAttrs<'a> {
16068 buf: &'a [u8],
16069 pos: usize,
16070 orig_loc: usize,
16071}
16072impl<'a> IterableLinkinfoNetkitAttrs<'a> {
16073 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
16074 Self {
16075 buf,
16076 pos: 0,
16077 orig_loc,
16078 }
16079 }
16080 pub fn get_buf(&self) -> &'a [u8] {
16081 self.buf
16082 }
16083}
16084impl<'a> Iterator for IterableLinkinfoNetkitAttrs<'a> {
16085 type Item = Result<LinkinfoNetkitAttrs<'a>, ErrorContext>;
16086 fn next(&mut self) -> Option<Self::Item> {
16087 if self.buf.len() == self.pos {
16088 return None;
16089 }
16090 let pos = self.pos;
16091 let mut r#type = None;
16092 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
16093 r#type = Some(header.r#type);
16094 let res = match header.r#type {
16095 1u16 => LinkinfoNetkitAttrs::PeerInfo({
16096 let res = Some(next);
16097 let Some(val) = res else { break };
16098 val
16099 }),
16100 2u16 => LinkinfoNetkitAttrs::Primary({
16101 let res = parse_u8(next);
16102 let Some(val) = res else { break };
16103 val
16104 }),
16105 3u16 => LinkinfoNetkitAttrs::Policy({
16106 let res = parse_u32(next);
16107 let Some(val) = res else { break };
16108 val
16109 }),
16110 4u16 => LinkinfoNetkitAttrs::PeerPolicy({
16111 let res = parse_u32(next);
16112 let Some(val) = res else { break };
16113 val
16114 }),
16115 5u16 => LinkinfoNetkitAttrs::Mode({
16116 let res = parse_u32(next);
16117 let Some(val) = res else { break };
16118 val
16119 }),
16120 6u16 => LinkinfoNetkitAttrs::Scrub({
16121 let res = parse_u32(next);
16122 let Some(val) = res else { break };
16123 val
16124 }),
16125 7u16 => LinkinfoNetkitAttrs::PeerScrub({
16126 let res = parse_u32(next);
16127 let Some(val) = res else { break };
16128 val
16129 }),
16130 8u16 => LinkinfoNetkitAttrs::Headroom({
16131 let res = parse_u16(next);
16132 let Some(val) = res else { break };
16133 val
16134 }),
16135 9u16 => LinkinfoNetkitAttrs::Tailroom({
16136 let res = parse_u16(next);
16137 let Some(val) = res else { break };
16138 val
16139 }),
16140 n => {
16141 if cfg!(any(test, feature = "deny-unknown-attrs")) {
16142 break;
16143 } else {
16144 continue;
16145 }
16146 }
16147 };
16148 return Some(Ok(res));
16149 }
16150 Some(Err(ErrorContext::new(
16151 "LinkinfoNetkitAttrs",
16152 r#type.and_then(|t| LinkinfoNetkitAttrs::attr_from_type(t)),
16153 self.orig_loc,
16154 self.buf.as_ptr().wrapping_add(pos) as usize,
16155 )))
16156 }
16157}
16158impl<'a> std::fmt::Debug for IterableLinkinfoNetkitAttrs<'_> {
16159 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16160 let mut fmt = f.debug_struct("LinkinfoNetkitAttrs");
16161 for attr in self.clone() {
16162 let attr = match attr {
16163 Ok(a) => a,
16164 Err(err) => {
16165 fmt.finish()?;
16166 f.write_str("Err(")?;
16167 err.fmt(f)?;
16168 return f.write_str(")");
16169 }
16170 };
16171 match attr {
16172 LinkinfoNetkitAttrs::PeerInfo(val) => fmt.field("PeerInfo", &val),
16173 LinkinfoNetkitAttrs::Primary(val) => fmt.field("Primary", &val),
16174 LinkinfoNetkitAttrs::Policy(val) => {
16175 fmt.field("Policy", &FormatEnum(val.into(), NetkitPolicy::from_value))
16176 }
16177 LinkinfoNetkitAttrs::PeerPolicy(val) => fmt.field(
16178 "PeerPolicy",
16179 &FormatEnum(val.into(), NetkitPolicy::from_value),
16180 ),
16181 LinkinfoNetkitAttrs::Mode(val) => {
16182 fmt.field("Mode", &FormatEnum(val.into(), NetkitMode::from_value))
16183 }
16184 LinkinfoNetkitAttrs::Scrub(val) => {
16185 fmt.field("Scrub", &FormatEnum(val.into(), NetkitScrub::from_value))
16186 }
16187 LinkinfoNetkitAttrs::PeerScrub(val) => fmt.field(
16188 "PeerScrub",
16189 &FormatEnum(val.into(), NetkitScrub::from_value),
16190 ),
16191 LinkinfoNetkitAttrs::Headroom(val) => fmt.field("Headroom", &val),
16192 LinkinfoNetkitAttrs::Tailroom(val) => fmt.field("Tailroom", &val),
16193 };
16194 }
16195 fmt.finish()
16196 }
16197}
16198impl IterableLinkinfoNetkitAttrs<'_> {
16199 pub fn lookup_attr(
16200 &self,
16201 offset: usize,
16202 missing_type: Option<u16>,
16203 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16204 let mut stack = Vec::new();
16205 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
16206 if cur == offset {
16207 stack.push(("LinkinfoNetkitAttrs", offset));
16208 return (
16209 stack,
16210 missing_type.and_then(|t| LinkinfoNetkitAttrs::attr_from_type(t)),
16211 );
16212 }
16213 if cur > offset || cur + self.buf.len() < offset {
16214 return (stack, None);
16215 }
16216 let mut attrs = self.clone();
16217 let mut last_off = cur + attrs.pos;
16218 while let Some(attr) = attrs.next() {
16219 let Ok(attr) = attr else { break };
16220 match attr {
16221 LinkinfoNetkitAttrs::PeerInfo(val) => {
16222 if last_off == offset {
16223 stack.push(("PeerInfo", last_off));
16224 break;
16225 }
16226 }
16227 LinkinfoNetkitAttrs::Primary(val) => {
16228 if last_off == offset {
16229 stack.push(("Primary", last_off));
16230 break;
16231 }
16232 }
16233 LinkinfoNetkitAttrs::Policy(val) => {
16234 if last_off == offset {
16235 stack.push(("Policy", last_off));
16236 break;
16237 }
16238 }
16239 LinkinfoNetkitAttrs::PeerPolicy(val) => {
16240 if last_off == offset {
16241 stack.push(("PeerPolicy", last_off));
16242 break;
16243 }
16244 }
16245 LinkinfoNetkitAttrs::Mode(val) => {
16246 if last_off == offset {
16247 stack.push(("Mode", last_off));
16248 break;
16249 }
16250 }
16251 LinkinfoNetkitAttrs::Scrub(val) => {
16252 if last_off == offset {
16253 stack.push(("Scrub", last_off));
16254 break;
16255 }
16256 }
16257 LinkinfoNetkitAttrs::PeerScrub(val) => {
16258 if last_off == offset {
16259 stack.push(("PeerScrub", last_off));
16260 break;
16261 }
16262 }
16263 LinkinfoNetkitAttrs::Headroom(val) => {
16264 if last_off == offset {
16265 stack.push(("Headroom", last_off));
16266 break;
16267 }
16268 }
16269 LinkinfoNetkitAttrs::Tailroom(val) => {
16270 if last_off == offset {
16271 stack.push(("Tailroom", last_off));
16272 break;
16273 }
16274 }
16275 _ => {}
16276 };
16277 last_off = cur + attrs.pos;
16278 }
16279 if !stack.is_empty() {
16280 stack.push(("LinkinfoNetkitAttrs", cur));
16281 }
16282 (stack, None)
16283 }
16284}
16285#[derive(Clone)]
16286pub enum LinkinfoOvpnAttrs {
16287 #[doc = "Associated type: \"OvpnMode\" (enum)"]
16288 Mode(u8),
16289}
16290impl<'a> IterableLinkinfoOvpnAttrs<'a> {
16291 #[doc = "Associated type: \"OvpnMode\" (enum)"]
16292 pub fn get_mode(&self) -> Result<u8, ErrorContext> {
16293 let mut iter = self.clone();
16294 iter.pos = 0;
16295 for attr in iter {
16296 if let LinkinfoOvpnAttrs::Mode(val) = attr? {
16297 return Ok(val);
16298 }
16299 }
16300 Err(ErrorContext::new_missing(
16301 "LinkinfoOvpnAttrs",
16302 "Mode",
16303 self.orig_loc,
16304 self.buf.as_ptr() as usize,
16305 ))
16306 }
16307}
16308impl LinkinfoOvpnAttrs {
16309 pub fn new<'a>(buf: &'a [u8]) -> IterableLinkinfoOvpnAttrs<'a> {
16310 IterableLinkinfoOvpnAttrs::with_loc(buf, buf.as_ptr() as usize)
16311 }
16312 fn attr_from_type(r#type: u16) -> Option<&'static str> {
16313 let res = match r#type {
16314 1u16 => "Mode",
16315 _ => return None,
16316 };
16317 Some(res)
16318 }
16319}
16320#[derive(Clone, Copy, Default)]
16321pub struct IterableLinkinfoOvpnAttrs<'a> {
16322 buf: &'a [u8],
16323 pos: usize,
16324 orig_loc: usize,
16325}
16326impl<'a> IterableLinkinfoOvpnAttrs<'a> {
16327 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
16328 Self {
16329 buf,
16330 pos: 0,
16331 orig_loc,
16332 }
16333 }
16334 pub fn get_buf(&self) -> &'a [u8] {
16335 self.buf
16336 }
16337}
16338impl<'a> Iterator for IterableLinkinfoOvpnAttrs<'a> {
16339 type Item = Result<LinkinfoOvpnAttrs, ErrorContext>;
16340 fn next(&mut self) -> Option<Self::Item> {
16341 if self.buf.len() == self.pos {
16342 return None;
16343 }
16344 let pos = self.pos;
16345 let mut r#type = None;
16346 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
16347 r#type = Some(header.r#type);
16348 let res = match header.r#type {
16349 1u16 => LinkinfoOvpnAttrs::Mode({
16350 let res = parse_u8(next);
16351 let Some(val) = res else { break };
16352 val
16353 }),
16354 n => {
16355 if cfg!(any(test, feature = "deny-unknown-attrs")) {
16356 break;
16357 } else {
16358 continue;
16359 }
16360 }
16361 };
16362 return Some(Ok(res));
16363 }
16364 Some(Err(ErrorContext::new(
16365 "LinkinfoOvpnAttrs",
16366 r#type.and_then(|t| LinkinfoOvpnAttrs::attr_from_type(t)),
16367 self.orig_loc,
16368 self.buf.as_ptr().wrapping_add(pos) as usize,
16369 )))
16370 }
16371}
16372impl std::fmt::Debug for IterableLinkinfoOvpnAttrs<'_> {
16373 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16374 let mut fmt = f.debug_struct("LinkinfoOvpnAttrs");
16375 for attr in self.clone() {
16376 let attr = match attr {
16377 Ok(a) => a,
16378 Err(err) => {
16379 fmt.finish()?;
16380 f.write_str("Err(")?;
16381 err.fmt(f)?;
16382 return f.write_str(")");
16383 }
16384 };
16385 match attr {
16386 LinkinfoOvpnAttrs::Mode(val) => {
16387 fmt.field("Mode", &FormatEnum(val.into(), OvpnMode::from_value))
16388 }
16389 };
16390 }
16391 fmt.finish()
16392 }
16393}
16394impl IterableLinkinfoOvpnAttrs<'_> {
16395 pub fn lookup_attr(
16396 &self,
16397 offset: usize,
16398 missing_type: Option<u16>,
16399 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16400 let mut stack = Vec::new();
16401 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
16402 if cur == offset {
16403 stack.push(("LinkinfoOvpnAttrs", offset));
16404 return (
16405 stack,
16406 missing_type.and_then(|t| LinkinfoOvpnAttrs::attr_from_type(t)),
16407 );
16408 }
16409 if cur > offset || cur + self.buf.len() < offset {
16410 return (stack, None);
16411 }
16412 let mut attrs = self.clone();
16413 let mut last_off = cur + attrs.pos;
16414 while let Some(attr) = attrs.next() {
16415 let Ok(attr) = attr else { break };
16416 match attr {
16417 LinkinfoOvpnAttrs::Mode(val) => {
16418 if last_off == offset {
16419 stack.push(("Mode", last_off));
16420 break;
16421 }
16422 }
16423 _ => {}
16424 };
16425 last_off = cur + attrs.pos;
16426 }
16427 if !stack.is_empty() {
16428 stack.push(("LinkinfoOvpnAttrs", cur));
16429 }
16430 (stack, None)
16431 }
16432}
16433pub struct PushLinkAttrs<Prev: Rec> {
16434 pub(crate) prev: Option<Prev>,
16435 pub(crate) header_offset: Option<usize>,
16436}
16437impl<Prev: Rec> Rec for PushLinkAttrs<Prev> {
16438 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
16439 self.prev.as_mut().unwrap().as_rec_mut()
16440 }
16441}
16442impl<Prev: Rec> PushLinkAttrs<Prev> {
16443 pub fn new(prev: Prev) -> Self {
16444 Self {
16445 prev: Some(prev),
16446 header_offset: None,
16447 }
16448 }
16449 pub fn end_nested(mut self) -> Prev {
16450 let mut prev = self.prev.take().unwrap();
16451 if let Some(header_offset) = &self.header_offset {
16452 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16453 }
16454 prev
16455 }
16456 pub fn push_address(mut self, value: &[u8]) -> Self {
16457 push_header(self.as_rec_mut(), 1u16, value.len() as u16);
16458 self.as_rec_mut().extend(value);
16459 self
16460 }
16461 pub fn push_broadcast(mut self, value: &[u8]) -> Self {
16462 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
16463 self.as_rec_mut().extend(value);
16464 self
16465 }
16466 pub fn push_ifname(mut self, value: &CStr) -> Self {
16467 push_header(
16468 self.as_rec_mut(),
16469 3u16,
16470 value.to_bytes_with_nul().len() as u16,
16471 );
16472 self.as_rec_mut().extend(value.to_bytes_with_nul());
16473 self
16474 }
16475 pub fn push_ifname_bytes(mut self, value: &[u8]) -> Self {
16476 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
16477 self.as_rec_mut().extend(value);
16478 self.as_rec_mut().push(0);
16479 self
16480 }
16481 pub fn push_mtu(mut self, value: u32) -> Self {
16482 push_header(self.as_rec_mut(), 4u16, 4 as u16);
16483 self.as_rec_mut().extend(value.to_ne_bytes());
16484 self
16485 }
16486 pub fn push_link(mut self, value: u32) -> Self {
16487 push_header(self.as_rec_mut(), 5u16, 4 as u16);
16488 self.as_rec_mut().extend(value.to_ne_bytes());
16489 self
16490 }
16491 pub fn push_qdisc(mut self, value: &CStr) -> Self {
16492 push_header(
16493 self.as_rec_mut(),
16494 6u16,
16495 value.to_bytes_with_nul().len() as u16,
16496 );
16497 self.as_rec_mut().extend(value.to_bytes_with_nul());
16498 self
16499 }
16500 pub fn push_qdisc_bytes(mut self, value: &[u8]) -> Self {
16501 push_header(self.as_rec_mut(), 6u16, (value.len() + 1) as u16);
16502 self.as_rec_mut().extend(value);
16503 self.as_rec_mut().push(0);
16504 self
16505 }
16506 pub fn push_stats(mut self, value: PushRtnlLinkStats) -> Self {
16507 push_header(self.as_rec_mut(), 7u16, value.as_slice().len() as u16);
16508 self.as_rec_mut().extend(value.as_slice());
16509 self
16510 }
16511 pub fn push_cost(mut self, value: &CStr) -> Self {
16512 push_header(
16513 self.as_rec_mut(),
16514 8u16,
16515 value.to_bytes_with_nul().len() as u16,
16516 );
16517 self.as_rec_mut().extend(value.to_bytes_with_nul());
16518 self
16519 }
16520 pub fn push_cost_bytes(mut self, value: &[u8]) -> Self {
16521 push_header(self.as_rec_mut(), 8u16, (value.len() + 1) as u16);
16522 self.as_rec_mut().extend(value);
16523 self.as_rec_mut().push(0);
16524 self
16525 }
16526 pub fn push_priority(mut self, value: &CStr) -> Self {
16527 push_header(
16528 self.as_rec_mut(),
16529 9u16,
16530 value.to_bytes_with_nul().len() as u16,
16531 );
16532 self.as_rec_mut().extend(value.to_bytes_with_nul());
16533 self
16534 }
16535 pub fn push_priority_bytes(mut self, value: &[u8]) -> Self {
16536 push_header(self.as_rec_mut(), 9u16, (value.len() + 1) as u16);
16537 self.as_rec_mut().extend(value);
16538 self.as_rec_mut().push(0);
16539 self
16540 }
16541 pub fn push_master(mut self, value: u32) -> Self {
16542 push_header(self.as_rec_mut(), 10u16, 4 as u16);
16543 self.as_rec_mut().extend(value.to_ne_bytes());
16544 self
16545 }
16546 pub fn push_wireless(mut self, value: &CStr) -> Self {
16547 push_header(
16548 self.as_rec_mut(),
16549 11u16,
16550 value.to_bytes_with_nul().len() as u16,
16551 );
16552 self.as_rec_mut().extend(value.to_bytes_with_nul());
16553 self
16554 }
16555 pub fn push_wireless_bytes(mut self, value: &[u8]) -> Self {
16556 push_header(self.as_rec_mut(), 11u16, (value.len() + 1) as u16);
16557 self.as_rec_mut().extend(value);
16558 self.as_rec_mut().push(0);
16559 self
16560 }
16561 pub fn push_protinfo(mut self, value: &CStr) -> Self {
16562 push_header(
16563 self.as_rec_mut(),
16564 12u16,
16565 value.to_bytes_with_nul().len() as u16,
16566 );
16567 self.as_rec_mut().extend(value.to_bytes_with_nul());
16568 self
16569 }
16570 pub fn push_protinfo_bytes(mut self, value: &[u8]) -> Self {
16571 push_header(self.as_rec_mut(), 12u16, (value.len() + 1) as u16);
16572 self.as_rec_mut().extend(value);
16573 self.as_rec_mut().push(0);
16574 self
16575 }
16576 pub fn push_txqlen(mut self, value: u32) -> Self {
16577 push_header(self.as_rec_mut(), 13u16, 4 as u16);
16578 self.as_rec_mut().extend(value.to_ne_bytes());
16579 self
16580 }
16581 pub fn push_map(mut self, value: PushRtnlLinkIfmap) -> Self {
16582 push_header(self.as_rec_mut(), 14u16, value.as_slice().len() as u16);
16583 self.as_rec_mut().extend(value.as_slice());
16584 self
16585 }
16586 pub fn push_weight(mut self, value: u32) -> Self {
16587 push_header(self.as_rec_mut(), 15u16, 4 as u16);
16588 self.as_rec_mut().extend(value.to_ne_bytes());
16589 self
16590 }
16591 pub fn push_operstate(mut self, value: u8) -> Self {
16592 push_header(self.as_rec_mut(), 16u16, 1 as u16);
16593 self.as_rec_mut().extend(value.to_ne_bytes());
16594 self
16595 }
16596 pub fn push_linkmode(mut self, value: u8) -> Self {
16597 push_header(self.as_rec_mut(), 17u16, 1 as u16);
16598 self.as_rec_mut().extend(value.to_ne_bytes());
16599 self
16600 }
16601 pub fn nested_linkinfo(mut self) -> PushLinkinfoAttrs<Self> {
16602 let header_offset = push_nested_header(self.as_rec_mut(), 18u16);
16603 PushLinkinfoAttrs {
16604 prev: Some(self),
16605 header_offset: Some(header_offset),
16606 }
16607 }
16608 pub fn push_net_ns_pid(mut self, value: u32) -> Self {
16609 push_header(self.as_rec_mut(), 19u16, 4 as u16);
16610 self.as_rec_mut().extend(value.to_ne_bytes());
16611 self
16612 }
16613 pub fn push_ifalias(mut self, value: &CStr) -> Self {
16614 push_header(
16615 self.as_rec_mut(),
16616 20u16,
16617 value.to_bytes_with_nul().len() as u16,
16618 );
16619 self.as_rec_mut().extend(value.to_bytes_with_nul());
16620 self
16621 }
16622 pub fn push_ifalias_bytes(mut self, value: &[u8]) -> Self {
16623 push_header(self.as_rec_mut(), 20u16, (value.len() + 1) as u16);
16624 self.as_rec_mut().extend(value);
16625 self.as_rec_mut().push(0);
16626 self
16627 }
16628 pub fn push_num_vf(mut self, value: u32) -> Self {
16629 push_header(self.as_rec_mut(), 21u16, 4 as u16);
16630 self.as_rec_mut().extend(value.to_ne_bytes());
16631 self
16632 }
16633 pub fn nested_vfinfo_list(mut self) -> PushVfinfoListAttrs<Self> {
16634 let header_offset = push_nested_header(self.as_rec_mut(), 22u16);
16635 PushVfinfoListAttrs {
16636 prev: Some(self),
16637 header_offset: Some(header_offset),
16638 }
16639 }
16640 pub fn push_stats64(mut self, value: PushRtnlLinkStats64) -> Self {
16641 push_header(self.as_rec_mut(), 23u16, value.as_slice().len() as u16);
16642 self.as_rec_mut().extend(value.as_slice());
16643 self
16644 }
16645 pub fn nested_vf_ports(mut self) -> PushVfPortsAttrs<Self> {
16646 let header_offset = push_nested_header(self.as_rec_mut(), 24u16);
16647 PushVfPortsAttrs {
16648 prev: Some(self),
16649 header_offset: Some(header_offset),
16650 }
16651 }
16652 pub fn nested_port_self(mut self) -> PushPortSelfAttrs<Self> {
16653 let header_offset = push_nested_header(self.as_rec_mut(), 25u16);
16654 PushPortSelfAttrs {
16655 prev: Some(self),
16656 header_offset: Some(header_offset),
16657 }
16658 }
16659 pub fn nested_af_spec(mut self) -> PushAfSpecAttrs<Self> {
16660 let header_offset = push_nested_header(self.as_rec_mut(), 26u16);
16661 PushAfSpecAttrs {
16662 prev: Some(self),
16663 header_offset: Some(header_offset),
16664 }
16665 }
16666 pub fn push_group(mut self, value: u32) -> Self {
16667 push_header(self.as_rec_mut(), 27u16, 4 as u16);
16668 self.as_rec_mut().extend(value.to_ne_bytes());
16669 self
16670 }
16671 pub fn push_net_ns_fd(mut self, value: u32) -> Self {
16672 push_header(self.as_rec_mut(), 28u16, 4 as u16);
16673 self.as_rec_mut().extend(value.to_ne_bytes());
16674 self
16675 }
16676 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
16677 pub fn push_ext_mask(mut self, value: u32) -> Self {
16678 push_header(self.as_rec_mut(), 29u16, 4 as u16);
16679 self.as_rec_mut().extend(value.to_ne_bytes());
16680 self
16681 }
16682 pub fn push_promiscuity(mut self, value: u32) -> Self {
16683 push_header(self.as_rec_mut(), 30u16, 4 as u16);
16684 self.as_rec_mut().extend(value.to_ne_bytes());
16685 self
16686 }
16687 pub fn push_num_tx_queues(mut self, value: u32) -> Self {
16688 push_header(self.as_rec_mut(), 31u16, 4 as u16);
16689 self.as_rec_mut().extend(value.to_ne_bytes());
16690 self
16691 }
16692 pub fn push_num_rx_queues(mut self, value: u32) -> Self {
16693 push_header(self.as_rec_mut(), 32u16, 4 as u16);
16694 self.as_rec_mut().extend(value.to_ne_bytes());
16695 self
16696 }
16697 pub fn push_carrier(mut self, value: u8) -> Self {
16698 push_header(self.as_rec_mut(), 33u16, 1 as u16);
16699 self.as_rec_mut().extend(value.to_ne_bytes());
16700 self
16701 }
16702 pub fn push_phys_port_id(mut self, value: &[u8]) -> Self {
16703 push_header(self.as_rec_mut(), 34u16, value.len() as u16);
16704 self.as_rec_mut().extend(value);
16705 self
16706 }
16707 pub fn push_carrier_changes(mut self, value: u32) -> Self {
16708 push_header(self.as_rec_mut(), 35u16, 4 as u16);
16709 self.as_rec_mut().extend(value.to_ne_bytes());
16710 self
16711 }
16712 pub fn push_phys_switch_id(mut self, value: &[u8]) -> Self {
16713 push_header(self.as_rec_mut(), 36u16, value.len() as u16);
16714 self.as_rec_mut().extend(value);
16715 self
16716 }
16717 pub fn push_link_netnsid(mut self, value: i32) -> Self {
16718 push_header(self.as_rec_mut(), 37u16, 4 as u16);
16719 self.as_rec_mut().extend(value.to_ne_bytes());
16720 self
16721 }
16722 pub fn push_phys_port_name(mut self, value: &CStr) -> Self {
16723 push_header(
16724 self.as_rec_mut(),
16725 38u16,
16726 value.to_bytes_with_nul().len() as u16,
16727 );
16728 self.as_rec_mut().extend(value.to_bytes_with_nul());
16729 self
16730 }
16731 pub fn push_phys_port_name_bytes(mut self, value: &[u8]) -> Self {
16732 push_header(self.as_rec_mut(), 38u16, (value.len() + 1) as u16);
16733 self.as_rec_mut().extend(value);
16734 self.as_rec_mut().push(0);
16735 self
16736 }
16737 pub fn push_proto_down(mut self, value: u8) -> Self {
16738 push_header(self.as_rec_mut(), 39u16, 1 as u16);
16739 self.as_rec_mut().extend(value.to_ne_bytes());
16740 self
16741 }
16742 pub fn push_gso_max_segs(mut self, value: u32) -> Self {
16743 push_header(self.as_rec_mut(), 40u16, 4 as u16);
16744 self.as_rec_mut().extend(value.to_ne_bytes());
16745 self
16746 }
16747 pub fn push_gso_max_size(mut self, value: u32) -> Self {
16748 push_header(self.as_rec_mut(), 41u16, 4 as u16);
16749 self.as_rec_mut().extend(value.to_ne_bytes());
16750 self
16751 }
16752 pub fn push_pad(mut self, value: &[u8]) -> Self {
16753 push_header(self.as_rec_mut(), 42u16, value.len() as u16);
16754 self.as_rec_mut().extend(value);
16755 self
16756 }
16757 pub fn nested_xdp(mut self) -> PushXdpAttrs<Self> {
16758 let header_offset = push_nested_header(self.as_rec_mut(), 43u16);
16759 PushXdpAttrs {
16760 prev: Some(self),
16761 header_offset: Some(header_offset),
16762 }
16763 }
16764 pub fn push_event(mut self, value: u32) -> Self {
16765 push_header(self.as_rec_mut(), 44u16, 4 as u16);
16766 self.as_rec_mut().extend(value.to_ne_bytes());
16767 self
16768 }
16769 pub fn push_new_netnsid(mut self, value: i32) -> Self {
16770 push_header(self.as_rec_mut(), 45u16, 4 as u16);
16771 self.as_rec_mut().extend(value.to_ne_bytes());
16772 self
16773 }
16774 pub fn push_target_netnsid(mut self, value: i32) -> Self {
16775 push_header(self.as_rec_mut(), 46u16, 4 as u16);
16776 self.as_rec_mut().extend(value.to_ne_bytes());
16777 self
16778 }
16779 pub fn push_carrier_up_count(mut self, value: u32) -> Self {
16780 push_header(self.as_rec_mut(), 47u16, 4 as u16);
16781 self.as_rec_mut().extend(value.to_ne_bytes());
16782 self
16783 }
16784 pub fn push_carrier_down_count(mut self, value: u32) -> Self {
16785 push_header(self.as_rec_mut(), 48u16, 4 as u16);
16786 self.as_rec_mut().extend(value.to_ne_bytes());
16787 self
16788 }
16789 pub fn push_new_ifindex(mut self, value: i32) -> Self {
16790 push_header(self.as_rec_mut(), 49u16, 4 as u16);
16791 self.as_rec_mut().extend(value.to_ne_bytes());
16792 self
16793 }
16794 pub fn push_min_mtu(mut self, value: u32) -> Self {
16795 push_header(self.as_rec_mut(), 50u16, 4 as u16);
16796 self.as_rec_mut().extend(value.to_ne_bytes());
16797 self
16798 }
16799 pub fn push_max_mtu(mut self, value: u32) -> Self {
16800 push_header(self.as_rec_mut(), 51u16, 4 as u16);
16801 self.as_rec_mut().extend(value.to_ne_bytes());
16802 self
16803 }
16804 pub fn nested_prop_list(mut self) -> PushPropListLinkAttrs<Self> {
16805 let header_offset = push_nested_header(self.as_rec_mut(), 52u16);
16806 PushPropListLinkAttrs {
16807 prev: Some(self),
16808 header_offset: Some(header_offset),
16809 }
16810 }
16811 pub fn push_alt_ifname(mut self, value: &CStr) -> Self {
16812 push_header(
16813 self.as_rec_mut(),
16814 53u16,
16815 value.to_bytes_with_nul().len() as u16,
16816 );
16817 self.as_rec_mut().extend(value.to_bytes_with_nul());
16818 self
16819 }
16820 pub fn push_alt_ifname_bytes(mut self, value: &[u8]) -> Self {
16821 push_header(self.as_rec_mut(), 53u16, (value.len() + 1) as u16);
16822 self.as_rec_mut().extend(value);
16823 self.as_rec_mut().push(0);
16824 self
16825 }
16826 pub fn push_perm_address(mut self, value: &[u8]) -> Self {
16827 push_header(self.as_rec_mut(), 54u16, value.len() as u16);
16828 self.as_rec_mut().extend(value);
16829 self
16830 }
16831 pub fn push_proto_down_reason(mut self, value: &CStr) -> Self {
16832 push_header(
16833 self.as_rec_mut(),
16834 55u16,
16835 value.to_bytes_with_nul().len() as u16,
16836 );
16837 self.as_rec_mut().extend(value.to_bytes_with_nul());
16838 self
16839 }
16840 pub fn push_proto_down_reason_bytes(mut self, value: &[u8]) -> Self {
16841 push_header(self.as_rec_mut(), 55u16, (value.len() + 1) as u16);
16842 self.as_rec_mut().extend(value);
16843 self.as_rec_mut().push(0);
16844 self
16845 }
16846 pub fn push_parent_dev_name(mut self, value: &CStr) -> Self {
16847 push_header(
16848 self.as_rec_mut(),
16849 56u16,
16850 value.to_bytes_with_nul().len() as u16,
16851 );
16852 self.as_rec_mut().extend(value.to_bytes_with_nul());
16853 self
16854 }
16855 pub fn push_parent_dev_name_bytes(mut self, value: &[u8]) -> Self {
16856 push_header(self.as_rec_mut(), 56u16, (value.len() + 1) as u16);
16857 self.as_rec_mut().extend(value);
16858 self.as_rec_mut().push(0);
16859 self
16860 }
16861 pub fn push_parent_dev_bus_name(mut self, value: &CStr) -> Self {
16862 push_header(
16863 self.as_rec_mut(),
16864 57u16,
16865 value.to_bytes_with_nul().len() as u16,
16866 );
16867 self.as_rec_mut().extend(value.to_bytes_with_nul());
16868 self
16869 }
16870 pub fn push_parent_dev_bus_name_bytes(mut self, value: &[u8]) -> Self {
16871 push_header(self.as_rec_mut(), 57u16, (value.len() + 1) as u16);
16872 self.as_rec_mut().extend(value);
16873 self.as_rec_mut().push(0);
16874 self
16875 }
16876 pub fn push_gro_max_size(mut self, value: u32) -> Self {
16877 push_header(self.as_rec_mut(), 58u16, 4 as u16);
16878 self.as_rec_mut().extend(value.to_ne_bytes());
16879 self
16880 }
16881 pub fn push_tso_max_size(mut self, value: u32) -> Self {
16882 push_header(self.as_rec_mut(), 59u16, 4 as u16);
16883 self.as_rec_mut().extend(value.to_ne_bytes());
16884 self
16885 }
16886 pub fn push_tso_max_segs(mut self, value: u32) -> Self {
16887 push_header(self.as_rec_mut(), 60u16, 4 as u16);
16888 self.as_rec_mut().extend(value.to_ne_bytes());
16889 self
16890 }
16891 pub fn push_allmulti(mut self, value: u32) -> Self {
16892 push_header(self.as_rec_mut(), 61u16, 4 as u16);
16893 self.as_rec_mut().extend(value.to_ne_bytes());
16894 self
16895 }
16896 pub fn push_devlink_port(mut self, value: &[u8]) -> Self {
16897 push_header(self.as_rec_mut(), 62u16, value.len() as u16);
16898 self.as_rec_mut().extend(value);
16899 self
16900 }
16901 pub fn push_gso_ipv4_max_size(mut self, value: u32) -> Self {
16902 push_header(self.as_rec_mut(), 63u16, 4 as u16);
16903 self.as_rec_mut().extend(value.to_ne_bytes());
16904 self
16905 }
16906 pub fn push_gro_ipv4_max_size(mut self, value: u32) -> Self {
16907 push_header(self.as_rec_mut(), 64u16, 4 as u16);
16908 self.as_rec_mut().extend(value.to_ne_bytes());
16909 self
16910 }
16911 pub fn nested_dpll_pin(mut self) -> PushLinkDpllPinAttrs<Self> {
16912 let header_offset = push_nested_header(self.as_rec_mut(), 65u16);
16913 PushLinkDpllPinAttrs {
16914 prev: Some(self),
16915 header_offset: Some(header_offset),
16916 }
16917 }
16918 #[doc = "EDT offload horizon supported by the device (in nsec)."]
16919 pub fn push_max_pacing_offload_horizon(mut self, value: u32) -> Self {
16920 push_header(self.as_rec_mut(), 66u16, 4 as u16);
16921 self.as_rec_mut().extend(value.to_ne_bytes());
16922 self
16923 }
16924 pub fn push_netns_immutable(mut self, value: u8) -> Self {
16925 push_header(self.as_rec_mut(), 67u16, 1 as u16);
16926 self.as_rec_mut().extend(value.to_ne_bytes());
16927 self
16928 }
16929}
16930impl<Prev: Rec> Drop for PushLinkAttrs<Prev> {
16931 fn drop(&mut self) {
16932 if let Some(prev) = &mut self.prev {
16933 if let Some(header_offset) = &self.header_offset {
16934 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16935 }
16936 }
16937 }
16938}
16939pub struct PushPropListLinkAttrs<Prev: Rec> {
16940 pub(crate) prev: Option<Prev>,
16941 pub(crate) header_offset: Option<usize>,
16942}
16943impl<Prev: Rec> Rec for PushPropListLinkAttrs<Prev> {
16944 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
16945 self.prev.as_mut().unwrap().as_rec_mut()
16946 }
16947}
16948impl<Prev: Rec> PushPropListLinkAttrs<Prev> {
16949 pub fn new(prev: Prev) -> Self {
16950 Self {
16951 prev: Some(prev),
16952 header_offset: None,
16953 }
16954 }
16955 pub fn end_nested(mut self) -> Prev {
16956 let mut prev = self.prev.take().unwrap();
16957 if let Some(header_offset) = &self.header_offset {
16958 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16959 }
16960 prev
16961 }
16962 #[doc = "Attribute may repeat multiple times (treat it as array)"]
16963 pub fn push_alt_ifname(mut self, value: &CStr) -> Self {
16964 push_header(
16965 self.as_rec_mut(),
16966 53u16,
16967 value.to_bytes_with_nul().len() as u16,
16968 );
16969 self.as_rec_mut().extend(value.to_bytes_with_nul());
16970 self
16971 }
16972 #[doc = "Attribute may repeat multiple times (treat it as array)"]
16973 pub fn push_alt_ifname_bytes(mut self, value: &[u8]) -> Self {
16974 push_header(self.as_rec_mut(), 53u16, (value.len() + 1) as u16);
16975 self.as_rec_mut().extend(value);
16976 self.as_rec_mut().push(0);
16977 self
16978 }
16979}
16980impl<Prev: Rec> Drop for PushPropListLinkAttrs<Prev> {
16981 fn drop(&mut self) {
16982 if let Some(prev) = &mut self.prev {
16983 if let Some(header_offset) = &self.header_offset {
16984 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16985 }
16986 }
16987 }
16988}
16989pub struct PushAfSpecAttrs<Prev: Rec> {
16990 pub(crate) prev: Option<Prev>,
16991 pub(crate) header_offset: Option<usize>,
16992}
16993impl<Prev: Rec> Rec for PushAfSpecAttrs<Prev> {
16994 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
16995 self.prev.as_mut().unwrap().as_rec_mut()
16996 }
16997}
16998impl<Prev: Rec> PushAfSpecAttrs<Prev> {
16999 pub fn new(prev: Prev) -> Self {
17000 Self {
17001 prev: Some(prev),
17002 header_offset: None,
17003 }
17004 }
17005 pub fn end_nested(mut self) -> Prev {
17006 let mut prev = self.prev.take().unwrap();
17007 if let Some(header_offset) = &self.header_offset {
17008 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17009 }
17010 prev
17011 }
17012 pub fn nested_inet(mut self) -> PushIflaAttrs<Self> {
17013 let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17014 PushIflaAttrs {
17015 prev: Some(self),
17016 header_offset: Some(header_offset),
17017 }
17018 }
17019 pub fn nested_inet6(mut self) -> PushIfla6Attrs<Self> {
17020 let header_offset = push_nested_header(self.as_rec_mut(), 10u16);
17021 PushIfla6Attrs {
17022 prev: Some(self),
17023 header_offset: Some(header_offset),
17024 }
17025 }
17026 pub fn nested_mctp(mut self) -> PushMctpAttrs<Self> {
17027 let header_offset = push_nested_header(self.as_rec_mut(), 45u16);
17028 PushMctpAttrs {
17029 prev: Some(self),
17030 header_offset: Some(header_offset),
17031 }
17032 }
17033}
17034impl<Prev: Rec> Drop for PushAfSpecAttrs<Prev> {
17035 fn drop(&mut self) {
17036 if let Some(prev) = &mut self.prev {
17037 if let Some(header_offset) = &self.header_offset {
17038 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17039 }
17040 }
17041 }
17042}
17043pub struct PushVfinfoListAttrs<Prev: Rec> {
17044 pub(crate) prev: Option<Prev>,
17045 pub(crate) header_offset: Option<usize>,
17046}
17047impl<Prev: Rec> Rec for PushVfinfoListAttrs<Prev> {
17048 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17049 self.prev.as_mut().unwrap().as_rec_mut()
17050 }
17051}
17052impl<Prev: Rec> PushVfinfoListAttrs<Prev> {
17053 pub fn new(prev: Prev) -> Self {
17054 Self {
17055 prev: Some(prev),
17056 header_offset: None,
17057 }
17058 }
17059 pub fn end_nested(mut self) -> Prev {
17060 let mut prev = self.prev.take().unwrap();
17061 if let Some(header_offset) = &self.header_offset {
17062 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17063 }
17064 prev
17065 }
17066 #[doc = "Attribute may repeat multiple times (treat it as array)"]
17067 pub fn nested_info(mut self) -> PushVfinfoAttrs<Self> {
17068 let header_offset = push_nested_header(self.as_rec_mut(), 1u16);
17069 PushVfinfoAttrs {
17070 prev: Some(self),
17071 header_offset: Some(header_offset),
17072 }
17073 }
17074}
17075impl<Prev: Rec> Drop for PushVfinfoListAttrs<Prev> {
17076 fn drop(&mut self) {
17077 if let Some(prev) = &mut self.prev {
17078 if let Some(header_offset) = &self.header_offset {
17079 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17080 }
17081 }
17082 }
17083}
17084pub struct PushVfinfoAttrs<Prev: Rec> {
17085 pub(crate) prev: Option<Prev>,
17086 pub(crate) header_offset: Option<usize>,
17087}
17088impl<Prev: Rec> Rec for PushVfinfoAttrs<Prev> {
17089 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17090 self.prev.as_mut().unwrap().as_rec_mut()
17091 }
17092}
17093impl<Prev: Rec> PushVfinfoAttrs<Prev> {
17094 pub fn new(prev: Prev) -> Self {
17095 Self {
17096 prev: Some(prev),
17097 header_offset: None,
17098 }
17099 }
17100 pub fn end_nested(mut self) -> Prev {
17101 let mut prev = self.prev.take().unwrap();
17102 if let Some(header_offset) = &self.header_offset {
17103 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17104 }
17105 prev
17106 }
17107 pub fn push_mac(mut self, value: PushIflaVfMac) -> Self {
17108 push_header(self.as_rec_mut(), 1u16, value.as_slice().len() as u16);
17109 self.as_rec_mut().extend(value.as_slice());
17110 self
17111 }
17112 pub fn push_vlan(mut self, value: PushIflaVfVlan) -> Self {
17113 push_header(self.as_rec_mut(), 2u16, value.as_slice().len() as u16);
17114 self.as_rec_mut().extend(value.as_slice());
17115 self
17116 }
17117 pub fn push_tx_rate(mut self, value: PushIflaVfTxRate) -> Self {
17118 push_header(self.as_rec_mut(), 3u16, value.as_slice().len() as u16);
17119 self.as_rec_mut().extend(value.as_slice());
17120 self
17121 }
17122 pub fn push_spoofchk(mut self, value: PushIflaVfSpoofchk) -> Self {
17123 push_header(self.as_rec_mut(), 4u16, value.as_slice().len() as u16);
17124 self.as_rec_mut().extend(value.as_slice());
17125 self
17126 }
17127 pub fn push_link_state(mut self, value: PushIflaVfLinkState) -> Self {
17128 push_header(self.as_rec_mut(), 5u16, value.as_slice().len() as u16);
17129 self.as_rec_mut().extend(value.as_slice());
17130 self
17131 }
17132 pub fn push_rate(mut self, value: PushIflaVfRate) -> Self {
17133 push_header(self.as_rec_mut(), 6u16, value.as_slice().len() as u16);
17134 self.as_rec_mut().extend(value.as_slice());
17135 self
17136 }
17137 pub fn push_rss_query_en(mut self, value: PushIflaVfRssQueryEn) -> Self {
17138 push_header(self.as_rec_mut(), 7u16, value.as_slice().len() as u16);
17139 self.as_rec_mut().extend(value.as_slice());
17140 self
17141 }
17142 pub fn nested_stats(mut self) -> PushVfStatsAttrs<Self> {
17143 let header_offset = push_nested_header(self.as_rec_mut(), 8u16);
17144 PushVfStatsAttrs {
17145 prev: Some(self),
17146 header_offset: Some(header_offset),
17147 }
17148 }
17149 pub fn push_trust(mut self, value: PushIflaVfTrust) -> Self {
17150 push_header(self.as_rec_mut(), 9u16, value.as_slice().len() as u16);
17151 self.as_rec_mut().extend(value.as_slice());
17152 self
17153 }
17154 pub fn push_ib_node_guid(mut self, value: PushIflaVfGuid) -> Self {
17155 push_header(self.as_rec_mut(), 10u16, value.as_slice().len() as u16);
17156 self.as_rec_mut().extend(value.as_slice());
17157 self
17158 }
17159 pub fn push_ib_port_guid(mut self, value: PushIflaVfGuid) -> Self {
17160 push_header(self.as_rec_mut(), 11u16, value.as_slice().len() as u16);
17161 self.as_rec_mut().extend(value.as_slice());
17162 self
17163 }
17164 pub fn nested_vlan_list(mut self) -> PushVfVlanAttrs<Self> {
17165 let header_offset = push_nested_header(self.as_rec_mut(), 12u16);
17166 PushVfVlanAttrs {
17167 prev: Some(self),
17168 header_offset: Some(header_offset),
17169 }
17170 }
17171 pub fn push_broadcast(mut self, value: &[u8]) -> Self {
17172 push_header(self.as_rec_mut(), 13u16, value.len() as u16);
17173 self.as_rec_mut().extend(value);
17174 self
17175 }
17176}
17177impl<Prev: Rec> Drop for PushVfinfoAttrs<Prev> {
17178 fn drop(&mut self) {
17179 if let Some(prev) = &mut self.prev {
17180 if let Some(header_offset) = &self.header_offset {
17181 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17182 }
17183 }
17184 }
17185}
17186pub struct PushVfStatsAttrs<Prev: Rec> {
17187 pub(crate) prev: Option<Prev>,
17188 pub(crate) header_offset: Option<usize>,
17189}
17190impl<Prev: Rec> Rec for PushVfStatsAttrs<Prev> {
17191 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17192 self.prev.as_mut().unwrap().as_rec_mut()
17193 }
17194}
17195impl<Prev: Rec> PushVfStatsAttrs<Prev> {
17196 pub fn new(prev: Prev) -> Self {
17197 Self {
17198 prev: Some(prev),
17199 header_offset: None,
17200 }
17201 }
17202 pub fn end_nested(mut self) -> Prev {
17203 let mut prev = self.prev.take().unwrap();
17204 if let Some(header_offset) = &self.header_offset {
17205 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17206 }
17207 prev
17208 }
17209 pub fn push_rx_packets(mut self, value: u64) -> Self {
17210 push_header(self.as_rec_mut(), 0u16, 8 as u16);
17211 self.as_rec_mut().extend(value.to_ne_bytes());
17212 self
17213 }
17214 pub fn push_tx_packets(mut self, value: u64) -> Self {
17215 push_header(self.as_rec_mut(), 1u16, 8 as u16);
17216 self.as_rec_mut().extend(value.to_ne_bytes());
17217 self
17218 }
17219 pub fn push_rx_bytes(mut self, value: u64) -> Self {
17220 push_header(self.as_rec_mut(), 2u16, 8 as u16);
17221 self.as_rec_mut().extend(value.to_ne_bytes());
17222 self
17223 }
17224 pub fn push_tx_bytes(mut self, value: u64) -> Self {
17225 push_header(self.as_rec_mut(), 3u16, 8 as u16);
17226 self.as_rec_mut().extend(value.to_ne_bytes());
17227 self
17228 }
17229 pub fn push_broadcast(mut self, value: u64) -> Self {
17230 push_header(self.as_rec_mut(), 4u16, 8 as u16);
17231 self.as_rec_mut().extend(value.to_ne_bytes());
17232 self
17233 }
17234 pub fn push_multicast(mut self, value: u64) -> Self {
17235 push_header(self.as_rec_mut(), 5u16, 8 as u16);
17236 self.as_rec_mut().extend(value.to_ne_bytes());
17237 self
17238 }
17239 pub fn push_pad(mut self, value: &[u8]) -> Self {
17240 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
17241 self.as_rec_mut().extend(value);
17242 self
17243 }
17244 pub fn push_rx_dropped(mut self, value: u64) -> Self {
17245 push_header(self.as_rec_mut(), 7u16, 8 as u16);
17246 self.as_rec_mut().extend(value.to_ne_bytes());
17247 self
17248 }
17249 pub fn push_tx_dropped(mut self, value: u64) -> Self {
17250 push_header(self.as_rec_mut(), 8u16, 8 as u16);
17251 self.as_rec_mut().extend(value.to_ne_bytes());
17252 self
17253 }
17254}
17255impl<Prev: Rec> Drop for PushVfStatsAttrs<Prev> {
17256 fn drop(&mut self) {
17257 if let Some(prev) = &mut self.prev {
17258 if let Some(header_offset) = &self.header_offset {
17259 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17260 }
17261 }
17262 }
17263}
17264pub struct PushVfVlanAttrs<Prev: Rec> {
17265 pub(crate) prev: Option<Prev>,
17266 pub(crate) header_offset: Option<usize>,
17267}
17268impl<Prev: Rec> Rec for PushVfVlanAttrs<Prev> {
17269 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17270 self.prev.as_mut().unwrap().as_rec_mut()
17271 }
17272}
17273impl<Prev: Rec> PushVfVlanAttrs<Prev> {
17274 pub fn new(prev: Prev) -> Self {
17275 Self {
17276 prev: Some(prev),
17277 header_offset: None,
17278 }
17279 }
17280 pub fn end_nested(mut self) -> Prev {
17281 let mut prev = self.prev.take().unwrap();
17282 if let Some(header_offset) = &self.header_offset {
17283 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17284 }
17285 prev
17286 }
17287 #[doc = "Attribute may repeat multiple times (treat it as array)"]
17288 pub fn push_info(mut self, value: PushIflaVfVlanInfo) -> Self {
17289 push_header(self.as_rec_mut(), 1u16, value.as_slice().len() as u16);
17290 self.as_rec_mut().extend(value.as_slice());
17291 self
17292 }
17293}
17294impl<Prev: Rec> Drop for PushVfVlanAttrs<Prev> {
17295 fn drop(&mut self) {
17296 if let Some(prev) = &mut self.prev {
17297 if let Some(header_offset) = &self.header_offset {
17298 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17299 }
17300 }
17301 }
17302}
17303pub struct PushVfPortsAttrs<Prev: Rec> {
17304 pub(crate) prev: Option<Prev>,
17305 pub(crate) header_offset: Option<usize>,
17306}
17307impl<Prev: Rec> Rec for PushVfPortsAttrs<Prev> {
17308 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17309 self.prev.as_mut().unwrap().as_rec_mut()
17310 }
17311}
17312impl<Prev: Rec> PushVfPortsAttrs<Prev> {
17313 pub fn new(prev: Prev) -> Self {
17314 Self {
17315 prev: Some(prev),
17316 header_offset: None,
17317 }
17318 }
17319 pub fn end_nested(mut self) -> Prev {
17320 let mut prev = self.prev.take().unwrap();
17321 if let Some(header_offset) = &self.header_offset {
17322 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17323 }
17324 prev
17325 }
17326}
17327impl<Prev: Rec> Drop for PushVfPortsAttrs<Prev> {
17328 fn drop(&mut self) {
17329 if let Some(prev) = &mut self.prev {
17330 if let Some(header_offset) = &self.header_offset {
17331 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17332 }
17333 }
17334 }
17335}
17336pub struct PushPortSelfAttrs<Prev: Rec> {
17337 pub(crate) prev: Option<Prev>,
17338 pub(crate) header_offset: Option<usize>,
17339}
17340impl<Prev: Rec> Rec for PushPortSelfAttrs<Prev> {
17341 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17342 self.prev.as_mut().unwrap().as_rec_mut()
17343 }
17344}
17345impl<Prev: Rec> PushPortSelfAttrs<Prev> {
17346 pub fn new(prev: Prev) -> Self {
17347 Self {
17348 prev: Some(prev),
17349 header_offset: None,
17350 }
17351 }
17352 pub fn end_nested(mut self) -> Prev {
17353 let mut prev = self.prev.take().unwrap();
17354 if let Some(header_offset) = &self.header_offset {
17355 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17356 }
17357 prev
17358 }
17359}
17360impl<Prev: Rec> Drop for PushPortSelfAttrs<Prev> {
17361 fn drop(&mut self) {
17362 if let Some(prev) = &mut self.prev {
17363 if let Some(header_offset) = &self.header_offset {
17364 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17365 }
17366 }
17367 }
17368}
17369pub struct PushLinkinfoAttrs<Prev: Rec> {
17370 pub(crate) prev: Option<Prev>,
17371 pub(crate) header_offset: Option<usize>,
17372}
17373impl<Prev: Rec> Rec for PushLinkinfoAttrs<Prev> {
17374 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17375 self.prev.as_mut().unwrap().as_rec_mut()
17376 }
17377}
17378impl<Prev: Rec> PushLinkinfoAttrs<Prev> {
17379 pub fn new(prev: Prev) -> Self {
17380 Self {
17381 prev: Some(prev),
17382 header_offset: None,
17383 }
17384 }
17385 pub fn end_nested(mut self) -> Prev {
17386 let mut prev = self.prev.take().unwrap();
17387 if let Some(header_offset) = &self.header_offset {
17388 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17389 }
17390 prev
17391 }
17392 pub fn push_kind(mut self, value: &CStr) -> Self {
17393 push_header(
17394 self.as_rec_mut(),
17395 1u16,
17396 value.to_bytes_with_nul().len() as u16,
17397 );
17398 self.as_rec_mut().extend(value.to_bytes_with_nul());
17399 self
17400 }
17401 pub fn push_kind_bytes(mut self, value: &[u8]) -> Self {
17402 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
17403 self.as_rec_mut().extend(value);
17404 self.as_rec_mut().push(0);
17405 self
17406 }
17407 #[doc = "Selector attribute is inserted automatically."]
17408 #[doc = "At most one sub-message attribute is expected per attribute set."]
17409 pub fn nested_data_bond(mut self) -> PushLinkinfoBondAttrs<PushDummy<Prev>> {
17410 self = self.push_kind(c"bond");
17411 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17412 let dummy = PushDummy {
17413 prev: self.prev.take(),
17414 header_offset: self.header_offset.take(),
17415 };
17416 PushLinkinfoBondAttrs {
17417 prev: Some(dummy),
17418 header_offset: Some(new_header_offset),
17419 }
17420 }
17421 #[doc = "Selector attribute is inserted automatically."]
17422 #[doc = "At most one sub-message attribute is expected per attribute set."]
17423 pub fn nested_data_bridge(mut self) -> PushLinkinfoBridgeAttrs<PushDummy<Prev>> {
17424 self = self.push_kind(c"bridge");
17425 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17426 let dummy = PushDummy {
17427 prev: self.prev.take(),
17428 header_offset: self.header_offset.take(),
17429 };
17430 PushLinkinfoBridgeAttrs {
17431 prev: Some(dummy),
17432 header_offset: Some(new_header_offset),
17433 }
17434 }
17435 #[doc = "Selector attribute is inserted automatically."]
17436 #[doc = "At most one sub-message attribute is expected per attribute set."]
17437 pub fn nested_data_erspan(mut self) -> PushLinkinfoGreAttrs<PushDummy<Prev>> {
17438 self = self.push_kind(c"erspan");
17439 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17440 let dummy = PushDummy {
17441 prev: self.prev.take(),
17442 header_offset: self.header_offset.take(),
17443 };
17444 PushLinkinfoGreAttrs {
17445 prev: Some(dummy),
17446 header_offset: Some(new_header_offset),
17447 }
17448 }
17449 #[doc = "Selector attribute is inserted automatically."]
17450 #[doc = "At most one sub-message attribute is expected per attribute set."]
17451 pub fn nested_data_gre(mut self) -> PushLinkinfoGreAttrs<PushDummy<Prev>> {
17452 self = self.push_kind(c"gre");
17453 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17454 let dummy = PushDummy {
17455 prev: self.prev.take(),
17456 header_offset: self.header_offset.take(),
17457 };
17458 PushLinkinfoGreAttrs {
17459 prev: Some(dummy),
17460 header_offset: Some(new_header_offset),
17461 }
17462 }
17463 #[doc = "Selector attribute is inserted automatically."]
17464 #[doc = "At most one sub-message attribute is expected per attribute set."]
17465 pub fn nested_data_gretap(mut self) -> PushLinkinfoGreAttrs<PushDummy<Prev>> {
17466 self = self.push_kind(c"gretap");
17467 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17468 let dummy = PushDummy {
17469 prev: self.prev.take(),
17470 header_offset: self.header_offset.take(),
17471 };
17472 PushLinkinfoGreAttrs {
17473 prev: Some(dummy),
17474 header_offset: Some(new_header_offset),
17475 }
17476 }
17477 #[doc = "Selector attribute is inserted automatically."]
17478 #[doc = "At most one sub-message attribute is expected per attribute set."]
17479 pub fn nested_data_ip6gre(mut self) -> PushLinkinfoGre6Attrs<PushDummy<Prev>> {
17480 self = self.push_kind(c"ip6gre");
17481 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17482 let dummy = PushDummy {
17483 prev: self.prev.take(),
17484 header_offset: self.header_offset.take(),
17485 };
17486 PushLinkinfoGre6Attrs {
17487 prev: Some(dummy),
17488 header_offset: Some(new_header_offset),
17489 }
17490 }
17491 #[doc = "Selector attribute is inserted automatically."]
17492 #[doc = "At most one sub-message attribute is expected per attribute set."]
17493 pub fn nested_data_geneve(mut self) -> PushLinkinfoGeneveAttrs<PushDummy<Prev>> {
17494 self = self.push_kind(c"geneve");
17495 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17496 let dummy = PushDummy {
17497 prev: self.prev.take(),
17498 header_offset: self.header_offset.take(),
17499 };
17500 PushLinkinfoGeneveAttrs {
17501 prev: Some(dummy),
17502 header_offset: Some(new_header_offset),
17503 }
17504 }
17505 #[doc = "Selector attribute is inserted automatically."]
17506 #[doc = "At most one sub-message attribute is expected per attribute set."]
17507 pub fn nested_data_ipip(mut self) -> PushLinkinfoIptunAttrs<PushDummy<Prev>> {
17508 self = self.push_kind(c"ipip");
17509 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17510 let dummy = PushDummy {
17511 prev: self.prev.take(),
17512 header_offset: self.header_offset.take(),
17513 };
17514 PushLinkinfoIptunAttrs {
17515 prev: Some(dummy),
17516 header_offset: Some(new_header_offset),
17517 }
17518 }
17519 #[doc = "Selector attribute is inserted automatically."]
17520 #[doc = "At most one sub-message attribute is expected per attribute set."]
17521 pub fn nested_data_ip6tnl(mut self) -> PushLinkinfoIp6tnlAttrs<PushDummy<Prev>> {
17522 self = self.push_kind(c"ip6tnl");
17523 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17524 let dummy = PushDummy {
17525 prev: self.prev.take(),
17526 header_offset: self.header_offset.take(),
17527 };
17528 PushLinkinfoIp6tnlAttrs {
17529 prev: Some(dummy),
17530 header_offset: Some(new_header_offset),
17531 }
17532 }
17533 #[doc = "Selector attribute is inserted automatically."]
17534 #[doc = "At most one sub-message attribute is expected per attribute set."]
17535 pub fn nested_data_sit(mut self) -> PushLinkinfoIptunAttrs<PushDummy<Prev>> {
17536 self = self.push_kind(c"sit");
17537 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17538 let dummy = PushDummy {
17539 prev: self.prev.take(),
17540 header_offset: self.header_offset.take(),
17541 };
17542 PushLinkinfoIptunAttrs {
17543 prev: Some(dummy),
17544 header_offset: Some(new_header_offset),
17545 }
17546 }
17547 #[doc = "Selector attribute is inserted automatically."]
17548 #[doc = "At most one sub-message attribute is expected per attribute set."]
17549 pub fn nested_data_tun(mut self) -> PushLinkinfoTunAttrs<PushDummy<Prev>> {
17550 self = self.push_kind(c"tun");
17551 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17552 let dummy = PushDummy {
17553 prev: self.prev.take(),
17554 header_offset: self.header_offset.take(),
17555 };
17556 PushLinkinfoTunAttrs {
17557 prev: Some(dummy),
17558 header_offset: Some(new_header_offset),
17559 }
17560 }
17561 #[doc = "Selector attribute is inserted automatically."]
17562 #[doc = "At most one sub-message attribute is expected per attribute set."]
17563 pub fn nested_data_vlan(mut self) -> PushLinkinfoVlanAttrs<PushDummy<Prev>> {
17564 self = self.push_kind(c"vlan");
17565 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17566 let dummy = PushDummy {
17567 prev: self.prev.take(),
17568 header_offset: self.header_offset.take(),
17569 };
17570 PushLinkinfoVlanAttrs {
17571 prev: Some(dummy),
17572 header_offset: Some(new_header_offset),
17573 }
17574 }
17575 #[doc = "Selector attribute is inserted automatically."]
17576 #[doc = "At most one sub-message attribute is expected per attribute set."]
17577 pub fn nested_data_vrf(mut self) -> PushLinkinfoVrfAttrs<PushDummy<Prev>> {
17578 self = self.push_kind(c"vrf");
17579 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17580 let dummy = PushDummy {
17581 prev: self.prev.take(),
17582 header_offset: self.header_offset.take(),
17583 };
17584 PushLinkinfoVrfAttrs {
17585 prev: Some(dummy),
17586 header_offset: Some(new_header_offset),
17587 }
17588 }
17589 #[doc = "Selector attribute is inserted automatically."]
17590 #[doc = "At most one sub-message attribute is expected per attribute set."]
17591 pub fn nested_data_vti(mut self) -> PushLinkinfoVtiAttrs<PushDummy<Prev>> {
17592 self = self.push_kind(c"vti");
17593 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17594 let dummy = PushDummy {
17595 prev: self.prev.take(),
17596 header_offset: self.header_offset.take(),
17597 };
17598 PushLinkinfoVtiAttrs {
17599 prev: Some(dummy),
17600 header_offset: Some(new_header_offset),
17601 }
17602 }
17603 #[doc = "Selector attribute is inserted automatically."]
17604 #[doc = "At most one sub-message attribute is expected per attribute set."]
17605 pub fn nested_data_vti6(mut self) -> PushLinkinfoVti6Attrs<PushDummy<Prev>> {
17606 self = self.push_kind(c"vti6");
17607 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17608 let dummy = PushDummy {
17609 prev: self.prev.take(),
17610 header_offset: self.header_offset.take(),
17611 };
17612 PushLinkinfoVti6Attrs {
17613 prev: Some(dummy),
17614 header_offset: Some(new_header_offset),
17615 }
17616 }
17617 #[doc = "Selector attribute is inserted automatically."]
17618 #[doc = "At most one sub-message attribute is expected per attribute set."]
17619 pub fn nested_data_netkit(mut self) -> PushLinkinfoNetkitAttrs<PushDummy<Prev>> {
17620 self = self.push_kind(c"netkit");
17621 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17622 let dummy = PushDummy {
17623 prev: self.prev.take(),
17624 header_offset: self.header_offset.take(),
17625 };
17626 PushLinkinfoNetkitAttrs {
17627 prev: Some(dummy),
17628 header_offset: Some(new_header_offset),
17629 }
17630 }
17631 #[doc = "Selector attribute is inserted automatically."]
17632 #[doc = "At most one sub-message attribute is expected per attribute set."]
17633 pub fn nested_data_ovpn(mut self) -> PushLinkinfoOvpnAttrs<PushDummy<Prev>> {
17634 self = self.push_kind(c"ovpn");
17635 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
17636 let dummy = PushDummy {
17637 prev: self.prev.take(),
17638 header_offset: self.header_offset.take(),
17639 };
17640 PushLinkinfoOvpnAttrs {
17641 prev: Some(dummy),
17642 header_offset: Some(new_header_offset),
17643 }
17644 }
17645 pub fn push_xstats(mut self, value: &[u8]) -> Self {
17646 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
17647 self.as_rec_mut().extend(value);
17648 self
17649 }
17650 pub fn push_slave_kind(mut self, value: &CStr) -> Self {
17651 push_header(
17652 self.as_rec_mut(),
17653 4u16,
17654 value.to_bytes_with_nul().len() as u16,
17655 );
17656 self.as_rec_mut().extend(value.to_bytes_with_nul());
17657 self
17658 }
17659 pub fn push_slave_kind_bytes(mut self, value: &[u8]) -> Self {
17660 push_header(self.as_rec_mut(), 4u16, (value.len() + 1) as u16);
17661 self.as_rec_mut().extend(value);
17662 self.as_rec_mut().push(0);
17663 self
17664 }
17665 #[doc = "Selector attribute is inserted automatically."]
17666 #[doc = "At most one sub-message attribute is expected per attribute set."]
17667 pub fn nested_slave_data_bridge(mut self) -> PushLinkinfoBrportAttrs<PushDummy<Prev>> {
17668 self = self.push_slave_kind(c"bridge");
17669 let new_header_offset = push_nested_header(self.as_rec_mut(), 5u16);
17670 let dummy = PushDummy {
17671 prev: self.prev.take(),
17672 header_offset: self.header_offset.take(),
17673 };
17674 PushLinkinfoBrportAttrs {
17675 prev: Some(dummy),
17676 header_offset: Some(new_header_offset),
17677 }
17678 }
17679 #[doc = "Selector attribute is inserted automatically."]
17680 #[doc = "At most one sub-message attribute is expected per attribute set."]
17681 pub fn nested_slave_data_bond(mut self) -> PushBondSlaveAttrs<PushDummy<Prev>> {
17682 self = self.push_slave_kind(c"bond");
17683 let new_header_offset = push_nested_header(self.as_rec_mut(), 5u16);
17684 let dummy = PushDummy {
17685 prev: self.prev.take(),
17686 header_offset: self.header_offset.take(),
17687 };
17688 PushBondSlaveAttrs {
17689 prev: Some(dummy),
17690 header_offset: Some(new_header_offset),
17691 }
17692 }
17693}
17694impl<Prev: Rec> Drop for PushLinkinfoAttrs<Prev> {
17695 fn drop(&mut self) {
17696 if let Some(prev) = &mut self.prev {
17697 if let Some(header_offset) = &self.header_offset {
17698 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17699 }
17700 }
17701 }
17702}
17703pub struct PushLinkinfoBondAttrs<Prev: Rec> {
17704 pub(crate) prev: Option<Prev>,
17705 pub(crate) header_offset: Option<usize>,
17706}
17707impl<Prev: Rec> Rec for PushLinkinfoBondAttrs<Prev> {
17708 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17709 self.prev.as_mut().unwrap().as_rec_mut()
17710 }
17711}
17712pub struct PushArrayU32<Prev: Rec> {
17713 pub(crate) prev: Option<Prev>,
17714 pub(crate) header_offset: Option<usize>,
17715 pub(crate) counter: u16,
17716}
17717impl<Prev: Rec> Rec for PushArrayU32<Prev> {
17718 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17719 self.prev.as_mut().unwrap().as_rec_mut()
17720 }
17721}
17722impl<Prev: Rec> PushArrayU32<Prev> {
17723 pub fn new(prev: Prev) -> Self {
17724 Self {
17725 prev: Some(prev),
17726 header_offset: None,
17727 counter: 0,
17728 }
17729 }
17730 pub fn end_array(mut self) -> Prev {
17731 let mut prev = self.prev.take().unwrap();
17732 if let Some(header_offset) = &self.header_offset {
17733 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17734 }
17735 prev
17736 }
17737 pub fn entry(mut self, value: std::net::Ipv4Addr) -> Self {
17738 let index = self.counter;
17739 self.counter += 1;
17740 push_header(self.as_rec_mut(), index, 4 as u16);
17741 self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
17742 self
17743 }
17744}
17745impl<Prev: Rec> Drop for PushArrayU32<Prev> {
17746 fn drop(&mut self) {
17747 if let Some(prev) = &mut self.prev {
17748 if let Some(header_offset) = &self.header_offset {
17749 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17750 }
17751 }
17752 }
17753}
17754pub struct PushArrayBinary<Prev: Rec> {
17755 pub(crate) prev: Option<Prev>,
17756 pub(crate) header_offset: Option<usize>,
17757 pub(crate) counter: u16,
17758}
17759impl<Prev: Rec> Rec for PushArrayBinary<Prev> {
17760 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17761 self.prev.as_mut().unwrap().as_rec_mut()
17762 }
17763}
17764impl<Prev: Rec> PushArrayBinary<Prev> {
17765 pub fn new(prev: Prev) -> Self {
17766 Self {
17767 prev: Some(prev),
17768 header_offset: None,
17769 counter: 0,
17770 }
17771 }
17772 pub fn end_array(mut self) -> Prev {
17773 let mut prev = self.prev.take().unwrap();
17774 if let Some(header_offset) = &self.header_offset {
17775 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17776 }
17777 prev
17778 }
17779 pub fn entry(mut self, value: &[u8]) -> Self {
17780 let index = self.counter;
17781 self.counter += 1;
17782 push_header(self.as_rec_mut(), index, value.len() as u16);
17783 self.as_rec_mut().extend(value);
17784 self
17785 }
17786}
17787impl<Prev: Rec> Drop for PushArrayBinary<Prev> {
17788 fn drop(&mut self) {
17789 if let Some(prev) = &mut self.prev {
17790 if let Some(header_offset) = &self.header_offset {
17791 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17792 }
17793 }
17794 }
17795}
17796impl<Prev: Rec> PushLinkinfoBondAttrs<Prev> {
17797 pub fn new(prev: Prev) -> Self {
17798 Self {
17799 prev: Some(prev),
17800 header_offset: None,
17801 }
17802 }
17803 pub fn end_nested(mut self) -> Prev {
17804 let mut prev = self.prev.take().unwrap();
17805 if let Some(header_offset) = &self.header_offset {
17806 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17807 }
17808 prev
17809 }
17810 pub fn push_mode(mut self, value: u8) -> Self {
17811 push_header(self.as_rec_mut(), 1u16, 1 as u16);
17812 self.as_rec_mut().extend(value.to_ne_bytes());
17813 self
17814 }
17815 pub fn push_active_slave(mut self, value: u32) -> Self {
17816 push_header(self.as_rec_mut(), 2u16, 4 as u16);
17817 self.as_rec_mut().extend(value.to_ne_bytes());
17818 self
17819 }
17820 pub fn push_miimon(mut self, value: u32) -> Self {
17821 push_header(self.as_rec_mut(), 3u16, 4 as u16);
17822 self.as_rec_mut().extend(value.to_ne_bytes());
17823 self
17824 }
17825 pub fn push_updelay(mut self, value: u32) -> Self {
17826 push_header(self.as_rec_mut(), 4u16, 4 as u16);
17827 self.as_rec_mut().extend(value.to_ne_bytes());
17828 self
17829 }
17830 pub fn push_downdelay(mut self, value: u32) -> Self {
17831 push_header(self.as_rec_mut(), 5u16, 4 as u16);
17832 self.as_rec_mut().extend(value.to_ne_bytes());
17833 self
17834 }
17835 pub fn push_use_carrier(mut self, value: u8) -> Self {
17836 push_header(self.as_rec_mut(), 6u16, 1 as u16);
17837 self.as_rec_mut().extend(value.to_ne_bytes());
17838 self
17839 }
17840 pub fn push_arp_interval(mut self, value: u32) -> Self {
17841 push_header(self.as_rec_mut(), 7u16, 4 as u16);
17842 self.as_rec_mut().extend(value.to_ne_bytes());
17843 self
17844 }
17845 pub fn array_arp_ip_target(mut self) -> PushArrayU32<Self> {
17846 let header_offset = push_nested_header(self.as_rec_mut(), 8u16);
17847 PushArrayU32 {
17848 prev: Some(self),
17849 header_offset: Some(header_offset),
17850 counter: 0,
17851 }
17852 }
17853 pub fn push_arp_validate(mut self, value: u32) -> Self {
17854 push_header(self.as_rec_mut(), 9u16, 4 as u16);
17855 self.as_rec_mut().extend(value.to_ne_bytes());
17856 self
17857 }
17858 pub fn push_arp_all_targets(mut self, value: u32) -> Self {
17859 push_header(self.as_rec_mut(), 10u16, 4 as u16);
17860 self.as_rec_mut().extend(value.to_ne_bytes());
17861 self
17862 }
17863 pub fn push_primary(mut self, value: u32) -> Self {
17864 push_header(self.as_rec_mut(), 11u16, 4 as u16);
17865 self.as_rec_mut().extend(value.to_ne_bytes());
17866 self
17867 }
17868 pub fn push_primary_reselect(mut self, value: u8) -> Self {
17869 push_header(self.as_rec_mut(), 12u16, 1 as u16);
17870 self.as_rec_mut().extend(value.to_ne_bytes());
17871 self
17872 }
17873 pub fn push_fail_over_mac(mut self, value: u8) -> Self {
17874 push_header(self.as_rec_mut(), 13u16, 1 as u16);
17875 self.as_rec_mut().extend(value.to_ne_bytes());
17876 self
17877 }
17878 pub fn push_xmit_hash_policy(mut self, value: u8) -> Self {
17879 push_header(self.as_rec_mut(), 14u16, 1 as u16);
17880 self.as_rec_mut().extend(value.to_ne_bytes());
17881 self
17882 }
17883 pub fn push_resend_igmp(mut self, value: u32) -> Self {
17884 push_header(self.as_rec_mut(), 15u16, 4 as u16);
17885 self.as_rec_mut().extend(value.to_ne_bytes());
17886 self
17887 }
17888 pub fn push_num_peer_notif(mut self, value: u8) -> Self {
17889 push_header(self.as_rec_mut(), 16u16, 1 as u16);
17890 self.as_rec_mut().extend(value.to_ne_bytes());
17891 self
17892 }
17893 pub fn push_all_slaves_active(mut self, value: u8) -> Self {
17894 push_header(self.as_rec_mut(), 17u16, 1 as u16);
17895 self.as_rec_mut().extend(value.to_ne_bytes());
17896 self
17897 }
17898 pub fn push_min_links(mut self, value: u32) -> Self {
17899 push_header(self.as_rec_mut(), 18u16, 4 as u16);
17900 self.as_rec_mut().extend(value.to_ne_bytes());
17901 self
17902 }
17903 pub fn push_lp_interval(mut self, value: u32) -> Self {
17904 push_header(self.as_rec_mut(), 19u16, 4 as u16);
17905 self.as_rec_mut().extend(value.to_ne_bytes());
17906 self
17907 }
17908 pub fn push_packets_per_slave(mut self, value: u32) -> Self {
17909 push_header(self.as_rec_mut(), 20u16, 4 as u16);
17910 self.as_rec_mut().extend(value.to_ne_bytes());
17911 self
17912 }
17913 pub fn push_ad_lacp_rate(mut self, value: u8) -> Self {
17914 push_header(self.as_rec_mut(), 21u16, 1 as u16);
17915 self.as_rec_mut().extend(value.to_ne_bytes());
17916 self
17917 }
17918 pub fn push_ad_select(mut self, value: u8) -> Self {
17919 push_header(self.as_rec_mut(), 22u16, 1 as u16);
17920 self.as_rec_mut().extend(value.to_ne_bytes());
17921 self
17922 }
17923 pub fn nested_ad_info(mut self) -> PushBondAdInfoAttrs<Self> {
17924 let header_offset = push_nested_header(self.as_rec_mut(), 23u16);
17925 PushBondAdInfoAttrs {
17926 prev: Some(self),
17927 header_offset: Some(header_offset),
17928 }
17929 }
17930 pub fn push_ad_actor_sys_prio(mut self, value: u16) -> Self {
17931 push_header(self.as_rec_mut(), 24u16, 2 as u16);
17932 self.as_rec_mut().extend(value.to_ne_bytes());
17933 self
17934 }
17935 pub fn push_ad_user_port_key(mut self, value: u16) -> Self {
17936 push_header(self.as_rec_mut(), 25u16, 2 as u16);
17937 self.as_rec_mut().extend(value.to_ne_bytes());
17938 self
17939 }
17940 pub fn push_ad_actor_system(mut self, value: &[u8]) -> Self {
17941 push_header(self.as_rec_mut(), 26u16, value.len() as u16);
17942 self.as_rec_mut().extend(value);
17943 self
17944 }
17945 pub fn push_tlb_dynamic_lb(mut self, value: u8) -> Self {
17946 push_header(self.as_rec_mut(), 27u16, 1 as u16);
17947 self.as_rec_mut().extend(value.to_ne_bytes());
17948 self
17949 }
17950 pub fn push_peer_notif_delay(mut self, value: u32) -> Self {
17951 push_header(self.as_rec_mut(), 28u16, 4 as u16);
17952 self.as_rec_mut().extend(value.to_ne_bytes());
17953 self
17954 }
17955 pub fn push_ad_lacp_active(mut self, value: u8) -> Self {
17956 push_header(self.as_rec_mut(), 29u16, 1 as u16);
17957 self.as_rec_mut().extend(value.to_ne_bytes());
17958 self
17959 }
17960 pub fn push_missed_max(mut self, value: u8) -> Self {
17961 push_header(self.as_rec_mut(), 30u16, 1 as u16);
17962 self.as_rec_mut().extend(value.to_ne_bytes());
17963 self
17964 }
17965 pub fn array_ns_ip6_target(mut self) -> PushArrayBinary<Self> {
17966 let header_offset = push_nested_header(self.as_rec_mut(), 31u16);
17967 PushArrayBinary {
17968 prev: Some(self),
17969 header_offset: Some(header_offset),
17970 counter: 0,
17971 }
17972 }
17973 pub fn push_coupled_control(mut self, value: u8) -> Self {
17974 push_header(self.as_rec_mut(), 32u16, 1 as u16);
17975 self.as_rec_mut().extend(value.to_ne_bytes());
17976 self
17977 }
17978}
17979impl<Prev: Rec> Drop for PushLinkinfoBondAttrs<Prev> {
17980 fn drop(&mut self) {
17981 if let Some(prev) = &mut self.prev {
17982 if let Some(header_offset) = &self.header_offset {
17983 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17984 }
17985 }
17986 }
17987}
17988pub struct PushBondAdInfoAttrs<Prev: Rec> {
17989 pub(crate) prev: Option<Prev>,
17990 pub(crate) header_offset: Option<usize>,
17991}
17992impl<Prev: Rec> Rec for PushBondAdInfoAttrs<Prev> {
17993 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17994 self.prev.as_mut().unwrap().as_rec_mut()
17995 }
17996}
17997impl<Prev: Rec> PushBondAdInfoAttrs<Prev> {
17998 pub fn new(prev: Prev) -> Self {
17999 Self {
18000 prev: Some(prev),
18001 header_offset: None,
18002 }
18003 }
18004 pub fn end_nested(mut self) -> Prev {
18005 let mut prev = self.prev.take().unwrap();
18006 if let Some(header_offset) = &self.header_offset {
18007 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18008 }
18009 prev
18010 }
18011 pub fn push_aggregator(mut self, value: u16) -> Self {
18012 push_header(self.as_rec_mut(), 1u16, 2 as u16);
18013 self.as_rec_mut().extend(value.to_ne_bytes());
18014 self
18015 }
18016 pub fn push_num_ports(mut self, value: u16) -> Self {
18017 push_header(self.as_rec_mut(), 2u16, 2 as u16);
18018 self.as_rec_mut().extend(value.to_ne_bytes());
18019 self
18020 }
18021 pub fn push_actor_key(mut self, value: u16) -> Self {
18022 push_header(self.as_rec_mut(), 3u16, 2 as u16);
18023 self.as_rec_mut().extend(value.to_ne_bytes());
18024 self
18025 }
18026 pub fn push_partner_key(mut self, value: u16) -> Self {
18027 push_header(self.as_rec_mut(), 4u16, 2 as u16);
18028 self.as_rec_mut().extend(value.to_ne_bytes());
18029 self
18030 }
18031 pub fn push_partner_mac(mut self, value: &[u8]) -> Self {
18032 push_header(self.as_rec_mut(), 5u16, value.len() as u16);
18033 self.as_rec_mut().extend(value);
18034 self
18035 }
18036}
18037impl<Prev: Rec> Drop for PushBondAdInfoAttrs<Prev> {
18038 fn drop(&mut self) {
18039 if let Some(prev) = &mut self.prev {
18040 if let Some(header_offset) = &self.header_offset {
18041 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18042 }
18043 }
18044 }
18045}
18046pub struct PushBondSlaveAttrs<Prev: Rec> {
18047 pub(crate) prev: Option<Prev>,
18048 pub(crate) header_offset: Option<usize>,
18049}
18050impl<Prev: Rec> Rec for PushBondSlaveAttrs<Prev> {
18051 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18052 self.prev.as_mut().unwrap().as_rec_mut()
18053 }
18054}
18055impl<Prev: Rec> PushBondSlaveAttrs<Prev> {
18056 pub fn new(prev: Prev) -> Self {
18057 Self {
18058 prev: Some(prev),
18059 header_offset: None,
18060 }
18061 }
18062 pub fn end_nested(mut self) -> Prev {
18063 let mut prev = self.prev.take().unwrap();
18064 if let Some(header_offset) = &self.header_offset {
18065 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18066 }
18067 prev
18068 }
18069 pub fn push_state(mut self, value: u8) -> Self {
18070 push_header(self.as_rec_mut(), 1u16, 1 as u16);
18071 self.as_rec_mut().extend(value.to_ne_bytes());
18072 self
18073 }
18074 pub fn push_mii_status(mut self, value: u8) -> Self {
18075 push_header(self.as_rec_mut(), 2u16, 1 as u16);
18076 self.as_rec_mut().extend(value.to_ne_bytes());
18077 self
18078 }
18079 pub fn push_link_failure_count(mut self, value: u32) -> Self {
18080 push_header(self.as_rec_mut(), 3u16, 4 as u16);
18081 self.as_rec_mut().extend(value.to_ne_bytes());
18082 self
18083 }
18084 pub fn push_perm_hwaddr(mut self, value: &[u8]) -> Self {
18085 push_header(self.as_rec_mut(), 4u16, value.len() as u16);
18086 self.as_rec_mut().extend(value);
18087 self
18088 }
18089 pub fn push_queue_id(mut self, value: u16) -> Self {
18090 push_header(self.as_rec_mut(), 5u16, 2 as u16);
18091 self.as_rec_mut().extend(value.to_ne_bytes());
18092 self
18093 }
18094 pub fn push_ad_aggregator_id(mut self, value: u16) -> Self {
18095 push_header(self.as_rec_mut(), 6u16, 2 as u16);
18096 self.as_rec_mut().extend(value.to_ne_bytes());
18097 self
18098 }
18099 pub fn push_ad_actor_oper_port_state(mut self, value: u8) -> Self {
18100 push_header(self.as_rec_mut(), 7u16, 1 as u16);
18101 self.as_rec_mut().extend(value.to_ne_bytes());
18102 self
18103 }
18104 pub fn push_ad_partner_oper_port_state(mut self, value: u16) -> Self {
18105 push_header(self.as_rec_mut(), 8u16, 2 as u16);
18106 self.as_rec_mut().extend(value.to_ne_bytes());
18107 self
18108 }
18109 pub fn push_prio(mut self, value: u32) -> Self {
18110 push_header(self.as_rec_mut(), 9u16, 4 as u16);
18111 self.as_rec_mut().extend(value.to_ne_bytes());
18112 self
18113 }
18114}
18115impl<Prev: Rec> Drop for PushBondSlaveAttrs<Prev> {
18116 fn drop(&mut self) {
18117 if let Some(prev) = &mut self.prev {
18118 if let Some(header_offset) = &self.header_offset {
18119 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18120 }
18121 }
18122 }
18123}
18124pub struct PushLinkinfoBridgeAttrs<Prev: Rec> {
18125 pub(crate) prev: Option<Prev>,
18126 pub(crate) header_offset: Option<usize>,
18127}
18128impl<Prev: Rec> Rec for PushLinkinfoBridgeAttrs<Prev> {
18129 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18130 self.prev.as_mut().unwrap().as_rec_mut()
18131 }
18132}
18133impl<Prev: Rec> PushLinkinfoBridgeAttrs<Prev> {
18134 pub fn new(prev: Prev) -> Self {
18135 Self {
18136 prev: Some(prev),
18137 header_offset: None,
18138 }
18139 }
18140 pub fn end_nested(mut self) -> Prev {
18141 let mut prev = self.prev.take().unwrap();
18142 if let Some(header_offset) = &self.header_offset {
18143 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18144 }
18145 prev
18146 }
18147 pub fn push_forward_delay(mut self, value: u32) -> Self {
18148 push_header(self.as_rec_mut(), 1u16, 4 as u16);
18149 self.as_rec_mut().extend(value.to_ne_bytes());
18150 self
18151 }
18152 pub fn push_hello_time(mut self, value: u32) -> Self {
18153 push_header(self.as_rec_mut(), 2u16, 4 as u16);
18154 self.as_rec_mut().extend(value.to_ne_bytes());
18155 self
18156 }
18157 pub fn push_max_age(mut self, value: u32) -> Self {
18158 push_header(self.as_rec_mut(), 3u16, 4 as u16);
18159 self.as_rec_mut().extend(value.to_ne_bytes());
18160 self
18161 }
18162 pub fn push_ageing_time(mut self, value: u32) -> Self {
18163 push_header(self.as_rec_mut(), 4u16, 4 as u16);
18164 self.as_rec_mut().extend(value.to_ne_bytes());
18165 self
18166 }
18167 pub fn push_stp_state(mut self, value: u32) -> Self {
18168 push_header(self.as_rec_mut(), 5u16, 4 as u16);
18169 self.as_rec_mut().extend(value.to_ne_bytes());
18170 self
18171 }
18172 pub fn push_priority(mut self, value: u16) -> Self {
18173 push_header(self.as_rec_mut(), 6u16, 2 as u16);
18174 self.as_rec_mut().extend(value.to_ne_bytes());
18175 self
18176 }
18177 pub fn push_vlan_filtering(mut self, value: u8) -> Self {
18178 push_header(self.as_rec_mut(), 7u16, 1 as u16);
18179 self.as_rec_mut().extend(value.to_ne_bytes());
18180 self
18181 }
18182 pub fn push_vlan_protocol(mut self, value: u16) -> Self {
18183 push_header(self.as_rec_mut(), 8u16, 2 as u16);
18184 self.as_rec_mut().extend(value.to_ne_bytes());
18185 self
18186 }
18187 pub fn push_group_fwd_mask(mut self, value: u16) -> Self {
18188 push_header(self.as_rec_mut(), 9u16, 2 as u16);
18189 self.as_rec_mut().extend(value.to_ne_bytes());
18190 self
18191 }
18192 pub fn push_root_id(mut self, value: PushIflaBridgeId) -> Self {
18193 push_header(self.as_rec_mut(), 10u16, value.as_slice().len() as u16);
18194 self.as_rec_mut().extend(value.as_slice());
18195 self
18196 }
18197 pub fn push_bridge_id(mut self, value: PushIflaBridgeId) -> Self {
18198 push_header(self.as_rec_mut(), 11u16, value.as_slice().len() as u16);
18199 self.as_rec_mut().extend(value.as_slice());
18200 self
18201 }
18202 pub fn push_root_port(mut self, value: u16) -> Self {
18203 push_header(self.as_rec_mut(), 12u16, 2 as u16);
18204 self.as_rec_mut().extend(value.to_ne_bytes());
18205 self
18206 }
18207 pub fn push_root_path_cost(mut self, value: u32) -> Self {
18208 push_header(self.as_rec_mut(), 13u16, 4 as u16);
18209 self.as_rec_mut().extend(value.to_ne_bytes());
18210 self
18211 }
18212 pub fn push_topology_change(mut self, value: u8) -> Self {
18213 push_header(self.as_rec_mut(), 14u16, 1 as u16);
18214 self.as_rec_mut().extend(value.to_ne_bytes());
18215 self
18216 }
18217 pub fn push_topology_change_detected(mut self, value: u8) -> Self {
18218 push_header(self.as_rec_mut(), 15u16, 1 as u16);
18219 self.as_rec_mut().extend(value.to_ne_bytes());
18220 self
18221 }
18222 pub fn push_hello_timer(mut self, value: u64) -> Self {
18223 push_header(self.as_rec_mut(), 16u16, 8 as u16);
18224 self.as_rec_mut().extend(value.to_ne_bytes());
18225 self
18226 }
18227 pub fn push_tcn_timer(mut self, value: u64) -> Self {
18228 push_header(self.as_rec_mut(), 17u16, 8 as u16);
18229 self.as_rec_mut().extend(value.to_ne_bytes());
18230 self
18231 }
18232 pub fn push_topology_change_timer(mut self, value: u64) -> Self {
18233 push_header(self.as_rec_mut(), 18u16, 8 as u16);
18234 self.as_rec_mut().extend(value.to_ne_bytes());
18235 self
18236 }
18237 pub fn push_gc_timer(mut self, value: u64) -> Self {
18238 push_header(self.as_rec_mut(), 19u16, 8 as u16);
18239 self.as_rec_mut().extend(value.to_ne_bytes());
18240 self
18241 }
18242 pub fn push_group_addr(mut self, value: &[u8]) -> Self {
18243 push_header(self.as_rec_mut(), 20u16, value.len() as u16);
18244 self.as_rec_mut().extend(value);
18245 self
18246 }
18247 pub fn push_fdb_flush(mut self, value: &[u8]) -> Self {
18248 push_header(self.as_rec_mut(), 21u16, value.len() as u16);
18249 self.as_rec_mut().extend(value);
18250 self
18251 }
18252 pub fn push_mcast_router(mut self, value: u8) -> Self {
18253 push_header(self.as_rec_mut(), 22u16, 1 as u16);
18254 self.as_rec_mut().extend(value.to_ne_bytes());
18255 self
18256 }
18257 pub fn push_mcast_snooping(mut self, value: u8) -> Self {
18258 push_header(self.as_rec_mut(), 23u16, 1 as u16);
18259 self.as_rec_mut().extend(value.to_ne_bytes());
18260 self
18261 }
18262 pub fn push_mcast_query_use_ifaddr(mut self, value: u8) -> Self {
18263 push_header(self.as_rec_mut(), 24u16, 1 as u16);
18264 self.as_rec_mut().extend(value.to_ne_bytes());
18265 self
18266 }
18267 pub fn push_mcast_querier(mut self, value: u8) -> Self {
18268 push_header(self.as_rec_mut(), 25u16, 1 as u16);
18269 self.as_rec_mut().extend(value.to_ne_bytes());
18270 self
18271 }
18272 pub fn push_mcast_hash_elasticity(mut self, value: u32) -> Self {
18273 push_header(self.as_rec_mut(), 26u16, 4 as u16);
18274 self.as_rec_mut().extend(value.to_ne_bytes());
18275 self
18276 }
18277 pub fn push_mcast_hash_max(mut self, value: u32) -> Self {
18278 push_header(self.as_rec_mut(), 27u16, 4 as u16);
18279 self.as_rec_mut().extend(value.to_ne_bytes());
18280 self
18281 }
18282 pub fn push_mcast_last_member_cnt(mut self, value: u32) -> Self {
18283 push_header(self.as_rec_mut(), 28u16, 4 as u16);
18284 self.as_rec_mut().extend(value.to_ne_bytes());
18285 self
18286 }
18287 pub fn push_mcast_startup_query_cnt(mut self, value: u32) -> Self {
18288 push_header(self.as_rec_mut(), 29u16, 4 as u16);
18289 self.as_rec_mut().extend(value.to_ne_bytes());
18290 self
18291 }
18292 pub fn push_mcast_last_member_intvl(mut self, value: u64) -> Self {
18293 push_header(self.as_rec_mut(), 30u16, 8 as u16);
18294 self.as_rec_mut().extend(value.to_ne_bytes());
18295 self
18296 }
18297 pub fn push_mcast_membership_intvl(mut self, value: u64) -> Self {
18298 push_header(self.as_rec_mut(), 31u16, 8 as u16);
18299 self.as_rec_mut().extend(value.to_ne_bytes());
18300 self
18301 }
18302 pub fn push_mcast_querier_intvl(mut self, value: u64) -> Self {
18303 push_header(self.as_rec_mut(), 32u16, 8 as u16);
18304 self.as_rec_mut().extend(value.to_ne_bytes());
18305 self
18306 }
18307 pub fn push_mcast_query_intvl(mut self, value: u64) -> Self {
18308 push_header(self.as_rec_mut(), 33u16, 8 as u16);
18309 self.as_rec_mut().extend(value.to_ne_bytes());
18310 self
18311 }
18312 pub fn push_mcast_query_response_intvl(mut self, value: u64) -> Self {
18313 push_header(self.as_rec_mut(), 34u16, 8 as u16);
18314 self.as_rec_mut().extend(value.to_ne_bytes());
18315 self
18316 }
18317 pub fn push_mcast_startup_query_intvl(mut self, value: u64) -> Self {
18318 push_header(self.as_rec_mut(), 35u16, 8 as u16);
18319 self.as_rec_mut().extend(value.to_ne_bytes());
18320 self
18321 }
18322 pub fn push_nf_call_iptables(mut self, value: u8) -> Self {
18323 push_header(self.as_rec_mut(), 36u16, 1 as u16);
18324 self.as_rec_mut().extend(value.to_ne_bytes());
18325 self
18326 }
18327 pub fn push_nf_call_ip6tables(mut self, value: u8) -> Self {
18328 push_header(self.as_rec_mut(), 37u16, 1 as u16);
18329 self.as_rec_mut().extend(value.to_ne_bytes());
18330 self
18331 }
18332 pub fn push_nf_call_arptables(mut self, value: u8) -> Self {
18333 push_header(self.as_rec_mut(), 38u16, 1 as u16);
18334 self.as_rec_mut().extend(value.to_ne_bytes());
18335 self
18336 }
18337 pub fn push_vlan_default_pvid(mut self, value: u16) -> Self {
18338 push_header(self.as_rec_mut(), 39u16, 2 as u16);
18339 self.as_rec_mut().extend(value.to_ne_bytes());
18340 self
18341 }
18342 pub fn push_pad(mut self, value: &[u8]) -> Self {
18343 push_header(self.as_rec_mut(), 40u16, value.len() as u16);
18344 self.as_rec_mut().extend(value);
18345 self
18346 }
18347 pub fn push_vlan_stats_enabled(mut self, value: u8) -> Self {
18348 push_header(self.as_rec_mut(), 41u16, 1 as u16);
18349 self.as_rec_mut().extend(value.to_ne_bytes());
18350 self
18351 }
18352 pub fn push_mcast_stats_enabled(mut self, value: u8) -> Self {
18353 push_header(self.as_rec_mut(), 42u16, 1 as u16);
18354 self.as_rec_mut().extend(value.to_ne_bytes());
18355 self
18356 }
18357 pub fn push_mcast_igmp_version(mut self, value: u8) -> Self {
18358 push_header(self.as_rec_mut(), 43u16, 1 as u16);
18359 self.as_rec_mut().extend(value.to_ne_bytes());
18360 self
18361 }
18362 pub fn push_mcast_mld_version(mut self, value: u8) -> Self {
18363 push_header(self.as_rec_mut(), 44u16, 1 as u16);
18364 self.as_rec_mut().extend(value.to_ne_bytes());
18365 self
18366 }
18367 pub fn push_vlan_stats_per_port(mut self, value: u8) -> Self {
18368 push_header(self.as_rec_mut(), 45u16, 1 as u16);
18369 self.as_rec_mut().extend(value.to_ne_bytes());
18370 self
18371 }
18372 pub fn push_multi_boolopt(mut self, value: PushBrBooloptMulti) -> Self {
18373 push_header(self.as_rec_mut(), 46u16, value.as_slice().len() as u16);
18374 self.as_rec_mut().extend(value.as_slice());
18375 self
18376 }
18377 pub fn push_mcast_querier_state(mut self, value: &[u8]) -> Self {
18378 push_header(self.as_rec_mut(), 47u16, value.len() as u16);
18379 self.as_rec_mut().extend(value);
18380 self
18381 }
18382 pub fn push_fdb_n_learned(mut self, value: u32) -> Self {
18383 push_header(self.as_rec_mut(), 48u16, 4 as u16);
18384 self.as_rec_mut().extend(value.to_ne_bytes());
18385 self
18386 }
18387 pub fn push_fdb_max_learned(mut self, value: u32) -> Self {
18388 push_header(self.as_rec_mut(), 49u16, 4 as u16);
18389 self.as_rec_mut().extend(value.to_ne_bytes());
18390 self
18391 }
18392}
18393impl<Prev: Rec> Drop for PushLinkinfoBridgeAttrs<Prev> {
18394 fn drop(&mut self) {
18395 if let Some(prev) = &mut self.prev {
18396 if let Some(header_offset) = &self.header_offset {
18397 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18398 }
18399 }
18400 }
18401}
18402pub struct PushLinkinfoBrportAttrs<Prev: Rec> {
18403 pub(crate) prev: Option<Prev>,
18404 pub(crate) header_offset: Option<usize>,
18405}
18406impl<Prev: Rec> Rec for PushLinkinfoBrportAttrs<Prev> {
18407 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18408 self.prev.as_mut().unwrap().as_rec_mut()
18409 }
18410}
18411impl<Prev: Rec> PushLinkinfoBrportAttrs<Prev> {
18412 pub fn new(prev: Prev) -> Self {
18413 Self {
18414 prev: Some(prev),
18415 header_offset: None,
18416 }
18417 }
18418 pub fn end_nested(mut self) -> Prev {
18419 let mut prev = self.prev.take().unwrap();
18420 if let Some(header_offset) = &self.header_offset {
18421 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18422 }
18423 prev
18424 }
18425 pub fn push_state(mut self, value: u8) -> Self {
18426 push_header(self.as_rec_mut(), 1u16, 1 as u16);
18427 self.as_rec_mut().extend(value.to_ne_bytes());
18428 self
18429 }
18430 pub fn push_priority(mut self, value: u16) -> Self {
18431 push_header(self.as_rec_mut(), 2u16, 2 as u16);
18432 self.as_rec_mut().extend(value.to_ne_bytes());
18433 self
18434 }
18435 pub fn push_cost(mut self, value: u32) -> Self {
18436 push_header(self.as_rec_mut(), 3u16, 4 as u16);
18437 self.as_rec_mut().extend(value.to_ne_bytes());
18438 self
18439 }
18440 pub fn push_mode(mut self, value: ()) -> Self {
18441 push_header(self.as_rec_mut(), 4u16, 0 as u16);
18442 self
18443 }
18444 pub fn push_guard(mut self, value: ()) -> Self {
18445 push_header(self.as_rec_mut(), 5u16, 0 as u16);
18446 self
18447 }
18448 pub fn push_protect(mut self, value: ()) -> Self {
18449 push_header(self.as_rec_mut(), 6u16, 0 as u16);
18450 self
18451 }
18452 pub fn push_fast_leave(mut self, value: ()) -> Self {
18453 push_header(self.as_rec_mut(), 7u16, 0 as u16);
18454 self
18455 }
18456 pub fn push_learning(mut self, value: ()) -> Self {
18457 push_header(self.as_rec_mut(), 8u16, 0 as u16);
18458 self
18459 }
18460 pub fn push_unicast_flood(mut self, value: ()) -> Self {
18461 push_header(self.as_rec_mut(), 9u16, 0 as u16);
18462 self
18463 }
18464 pub fn push_proxyarp(mut self, value: ()) -> Self {
18465 push_header(self.as_rec_mut(), 10u16, 0 as u16);
18466 self
18467 }
18468 pub fn push_learning_sync(mut self, value: ()) -> Self {
18469 push_header(self.as_rec_mut(), 11u16, 0 as u16);
18470 self
18471 }
18472 pub fn push_proxyarp_wifi(mut self, value: ()) -> Self {
18473 push_header(self.as_rec_mut(), 12u16, 0 as u16);
18474 self
18475 }
18476 pub fn push_root_id(mut self, value: PushIflaBridgeId) -> Self {
18477 push_header(self.as_rec_mut(), 13u16, value.as_slice().len() as u16);
18478 self.as_rec_mut().extend(value.as_slice());
18479 self
18480 }
18481 pub fn push_bridge_id(mut self, value: PushIflaBridgeId) -> Self {
18482 push_header(self.as_rec_mut(), 14u16, value.as_slice().len() as u16);
18483 self.as_rec_mut().extend(value.as_slice());
18484 self
18485 }
18486 pub fn push_designated_port(mut self, value: u16) -> Self {
18487 push_header(self.as_rec_mut(), 15u16, 2 as u16);
18488 self.as_rec_mut().extend(value.to_ne_bytes());
18489 self
18490 }
18491 pub fn push_designated_cost(mut self, value: u16) -> Self {
18492 push_header(self.as_rec_mut(), 16u16, 2 as u16);
18493 self.as_rec_mut().extend(value.to_ne_bytes());
18494 self
18495 }
18496 pub fn push_id(mut self, value: u16) -> Self {
18497 push_header(self.as_rec_mut(), 17u16, 2 as u16);
18498 self.as_rec_mut().extend(value.to_ne_bytes());
18499 self
18500 }
18501 pub fn push_no(mut self, value: u16) -> Self {
18502 push_header(self.as_rec_mut(), 18u16, 2 as u16);
18503 self.as_rec_mut().extend(value.to_ne_bytes());
18504 self
18505 }
18506 pub fn push_topology_change_ack(mut self, value: u8) -> Self {
18507 push_header(self.as_rec_mut(), 19u16, 1 as u16);
18508 self.as_rec_mut().extend(value.to_ne_bytes());
18509 self
18510 }
18511 pub fn push_config_pending(mut self, value: u8) -> Self {
18512 push_header(self.as_rec_mut(), 20u16, 1 as u16);
18513 self.as_rec_mut().extend(value.to_ne_bytes());
18514 self
18515 }
18516 pub fn push_message_age_timer(mut self, value: u64) -> Self {
18517 push_header(self.as_rec_mut(), 21u16, 8 as u16);
18518 self.as_rec_mut().extend(value.to_ne_bytes());
18519 self
18520 }
18521 pub fn push_forward_delay_timer(mut self, value: u64) -> Self {
18522 push_header(self.as_rec_mut(), 22u16, 8 as u16);
18523 self.as_rec_mut().extend(value.to_ne_bytes());
18524 self
18525 }
18526 pub fn push_hold_timer(mut self, value: u64) -> Self {
18527 push_header(self.as_rec_mut(), 23u16, 8 as u16);
18528 self.as_rec_mut().extend(value.to_ne_bytes());
18529 self
18530 }
18531 pub fn push_flush(mut self, value: ()) -> Self {
18532 push_header(self.as_rec_mut(), 24u16, 0 as u16);
18533 self
18534 }
18535 pub fn push_multicast_router(mut self, value: u8) -> Self {
18536 push_header(self.as_rec_mut(), 25u16, 1 as u16);
18537 self.as_rec_mut().extend(value.to_ne_bytes());
18538 self
18539 }
18540 pub fn push_pad(mut self, value: &[u8]) -> Self {
18541 push_header(self.as_rec_mut(), 26u16, value.len() as u16);
18542 self.as_rec_mut().extend(value);
18543 self
18544 }
18545 pub fn push_mcast_flood(mut self, value: ()) -> Self {
18546 push_header(self.as_rec_mut(), 27u16, 0 as u16);
18547 self
18548 }
18549 pub fn push_mcast_to_ucast(mut self, value: ()) -> Self {
18550 push_header(self.as_rec_mut(), 28u16, 0 as u16);
18551 self
18552 }
18553 pub fn push_vlan_tunnel(mut self, value: ()) -> Self {
18554 push_header(self.as_rec_mut(), 29u16, 0 as u16);
18555 self
18556 }
18557 pub fn push_bcast_flood(mut self, value: ()) -> Self {
18558 push_header(self.as_rec_mut(), 30u16, 0 as u16);
18559 self
18560 }
18561 pub fn push_group_fwd_mask(mut self, value: u16) -> Self {
18562 push_header(self.as_rec_mut(), 31u16, 2 as u16);
18563 self.as_rec_mut().extend(value.to_ne_bytes());
18564 self
18565 }
18566 pub fn push_neigh_suppress(mut self, value: ()) -> Self {
18567 push_header(self.as_rec_mut(), 32u16, 0 as u16);
18568 self
18569 }
18570 pub fn push_isolated(mut self, value: ()) -> Self {
18571 push_header(self.as_rec_mut(), 33u16, 0 as u16);
18572 self
18573 }
18574 pub fn push_backup_port(mut self, value: u32) -> Self {
18575 push_header(self.as_rec_mut(), 34u16, 4 as u16);
18576 self.as_rec_mut().extend(value.to_ne_bytes());
18577 self
18578 }
18579 pub fn push_mrp_ring_open(mut self, value: ()) -> Self {
18580 push_header(self.as_rec_mut(), 35u16, 0 as u16);
18581 self
18582 }
18583 pub fn push_mrp_in_open(mut self, value: ()) -> Self {
18584 push_header(self.as_rec_mut(), 36u16, 0 as u16);
18585 self
18586 }
18587 pub fn push_mcast_eht_hosts_limit(mut self, value: u32) -> Self {
18588 push_header(self.as_rec_mut(), 37u16, 4 as u16);
18589 self.as_rec_mut().extend(value.to_ne_bytes());
18590 self
18591 }
18592 pub fn push_mcast_eht_hosts_cnt(mut self, value: u32) -> Self {
18593 push_header(self.as_rec_mut(), 38u16, 4 as u16);
18594 self.as_rec_mut().extend(value.to_ne_bytes());
18595 self
18596 }
18597 pub fn push_locked(mut self, value: ()) -> Self {
18598 push_header(self.as_rec_mut(), 39u16, 0 as u16);
18599 self
18600 }
18601 pub fn push_mab(mut self, value: ()) -> Self {
18602 push_header(self.as_rec_mut(), 40u16, 0 as u16);
18603 self
18604 }
18605 pub fn push_mcast_n_groups(mut self, value: u32) -> Self {
18606 push_header(self.as_rec_mut(), 41u16, 4 as u16);
18607 self.as_rec_mut().extend(value.to_ne_bytes());
18608 self
18609 }
18610 pub fn push_mcast_max_groups(mut self, value: u32) -> Self {
18611 push_header(self.as_rec_mut(), 42u16, 4 as u16);
18612 self.as_rec_mut().extend(value.to_ne_bytes());
18613 self
18614 }
18615 pub fn push_neigh_vlan_suppress(mut self, value: ()) -> Self {
18616 push_header(self.as_rec_mut(), 43u16, 0 as u16);
18617 self
18618 }
18619 pub fn push_backup_nhid(mut self, value: u32) -> Self {
18620 push_header(self.as_rec_mut(), 44u16, 4 as u16);
18621 self.as_rec_mut().extend(value.to_ne_bytes());
18622 self
18623 }
18624}
18625impl<Prev: Rec> Drop for PushLinkinfoBrportAttrs<Prev> {
18626 fn drop(&mut self) {
18627 if let Some(prev) = &mut self.prev {
18628 if let Some(header_offset) = &self.header_offset {
18629 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18630 }
18631 }
18632 }
18633}
18634pub struct PushLinkinfoGreAttrs<Prev: Rec> {
18635 pub(crate) prev: Option<Prev>,
18636 pub(crate) header_offset: Option<usize>,
18637}
18638impl<Prev: Rec> Rec for PushLinkinfoGreAttrs<Prev> {
18639 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18640 self.prev.as_mut().unwrap().as_rec_mut()
18641 }
18642}
18643impl<Prev: Rec> PushLinkinfoGreAttrs<Prev> {
18644 pub fn new(prev: Prev) -> Self {
18645 Self {
18646 prev: Some(prev),
18647 header_offset: None,
18648 }
18649 }
18650 pub fn end_nested(mut self) -> Prev {
18651 let mut prev = self.prev.take().unwrap();
18652 if let Some(header_offset) = &self.header_offset {
18653 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18654 }
18655 prev
18656 }
18657 pub fn push_link(mut self, value: u32) -> Self {
18658 push_header(self.as_rec_mut(), 1u16, 4 as u16);
18659 self.as_rec_mut().extend(value.to_ne_bytes());
18660 self
18661 }
18662 pub fn push_iflags(mut self, value: u16) -> Self {
18663 push_header(self.as_rec_mut(), 2u16, 2 as u16);
18664 self.as_rec_mut().extend(value.to_be_bytes());
18665 self
18666 }
18667 pub fn push_oflags(mut self, value: u16) -> Self {
18668 push_header(self.as_rec_mut(), 3u16, 2 as u16);
18669 self.as_rec_mut().extend(value.to_be_bytes());
18670 self
18671 }
18672 pub fn push_ikey(mut self, value: u32) -> Self {
18673 push_header(self.as_rec_mut(), 4u16, 4 as u16);
18674 self.as_rec_mut().extend(value.to_be_bytes());
18675 self
18676 }
18677 pub fn push_okey(mut self, value: u32) -> Self {
18678 push_header(self.as_rec_mut(), 5u16, 4 as u16);
18679 self.as_rec_mut().extend(value.to_be_bytes());
18680 self
18681 }
18682 pub fn push_local(mut self, value: &[u8]) -> Self {
18683 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
18684 self.as_rec_mut().extend(value);
18685 self
18686 }
18687 pub fn push_remote(mut self, value: &[u8]) -> Self {
18688 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
18689 self.as_rec_mut().extend(value);
18690 self
18691 }
18692 pub fn push_ttl(mut self, value: u8) -> Self {
18693 push_header(self.as_rec_mut(), 8u16, 1 as u16);
18694 self.as_rec_mut().extend(value.to_ne_bytes());
18695 self
18696 }
18697 pub fn push_tos(mut self, value: u8) -> Self {
18698 push_header(self.as_rec_mut(), 9u16, 1 as u16);
18699 self.as_rec_mut().extend(value.to_ne_bytes());
18700 self
18701 }
18702 pub fn push_pmtudisc(mut self, value: u8) -> Self {
18703 push_header(self.as_rec_mut(), 10u16, 1 as u16);
18704 self.as_rec_mut().extend(value.to_ne_bytes());
18705 self
18706 }
18707 pub fn push_encap_limit(mut self, value: u8) -> Self {
18708 push_header(self.as_rec_mut(), 11u16, 1 as u16);
18709 self.as_rec_mut().extend(value.to_ne_bytes());
18710 self
18711 }
18712 pub fn push_flowinfo(mut self, value: u32) -> Self {
18713 push_header(self.as_rec_mut(), 12u16, 4 as u16);
18714 self.as_rec_mut().extend(value.to_be_bytes());
18715 self
18716 }
18717 pub fn push_flags(mut self, value: u32) -> Self {
18718 push_header(self.as_rec_mut(), 13u16, 4 as u16);
18719 self.as_rec_mut().extend(value.to_ne_bytes());
18720 self
18721 }
18722 pub fn push_encap_type(mut self, value: u16) -> Self {
18723 push_header(self.as_rec_mut(), 14u16, 2 as u16);
18724 self.as_rec_mut().extend(value.to_ne_bytes());
18725 self
18726 }
18727 pub fn push_encap_flags(mut self, value: u16) -> Self {
18728 push_header(self.as_rec_mut(), 15u16, 2 as u16);
18729 self.as_rec_mut().extend(value.to_ne_bytes());
18730 self
18731 }
18732 pub fn push_encap_sport(mut self, value: u16) -> Self {
18733 push_header(self.as_rec_mut(), 16u16, 2 as u16);
18734 self.as_rec_mut().extend(value.to_be_bytes());
18735 self
18736 }
18737 pub fn push_encap_dport(mut self, value: u16) -> Self {
18738 push_header(self.as_rec_mut(), 17u16, 2 as u16);
18739 self.as_rec_mut().extend(value.to_be_bytes());
18740 self
18741 }
18742 pub fn push_collect_metadata(mut self, value: ()) -> Self {
18743 push_header(self.as_rec_mut(), 18u16, 0 as u16);
18744 self
18745 }
18746 pub fn push_ignore_df(mut self, value: u8) -> Self {
18747 push_header(self.as_rec_mut(), 19u16, 1 as u16);
18748 self.as_rec_mut().extend(value.to_ne_bytes());
18749 self
18750 }
18751 pub fn push_fwmark(mut self, value: u32) -> Self {
18752 push_header(self.as_rec_mut(), 20u16, 4 as u16);
18753 self.as_rec_mut().extend(value.to_ne_bytes());
18754 self
18755 }
18756 pub fn push_erspan_index(mut self, value: u32) -> Self {
18757 push_header(self.as_rec_mut(), 21u16, 4 as u16);
18758 self.as_rec_mut().extend(value.to_ne_bytes());
18759 self
18760 }
18761 pub fn push_erspan_ver(mut self, value: u8) -> Self {
18762 push_header(self.as_rec_mut(), 22u16, 1 as u16);
18763 self.as_rec_mut().extend(value.to_ne_bytes());
18764 self
18765 }
18766 pub fn push_erspan_dir(mut self, value: u8) -> Self {
18767 push_header(self.as_rec_mut(), 23u16, 1 as u16);
18768 self.as_rec_mut().extend(value.to_ne_bytes());
18769 self
18770 }
18771 pub fn push_erspan_hwid(mut self, value: u16) -> Self {
18772 push_header(self.as_rec_mut(), 24u16, 2 as u16);
18773 self.as_rec_mut().extend(value.to_ne_bytes());
18774 self
18775 }
18776}
18777impl<Prev: Rec> Drop for PushLinkinfoGreAttrs<Prev> {
18778 fn drop(&mut self) {
18779 if let Some(prev) = &mut self.prev {
18780 if let Some(header_offset) = &self.header_offset {
18781 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18782 }
18783 }
18784 }
18785}
18786pub struct PushLinkinfoGre6Attrs<Prev: Rec> {
18787 pub(crate) prev: Option<Prev>,
18788 pub(crate) header_offset: Option<usize>,
18789}
18790impl<Prev: Rec> Rec for PushLinkinfoGre6Attrs<Prev> {
18791 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18792 self.prev.as_mut().unwrap().as_rec_mut()
18793 }
18794}
18795impl<Prev: Rec> PushLinkinfoGre6Attrs<Prev> {
18796 pub fn new(prev: Prev) -> Self {
18797 Self {
18798 prev: Some(prev),
18799 header_offset: None,
18800 }
18801 }
18802 pub fn end_nested(mut self) -> Prev {
18803 let mut prev = self.prev.take().unwrap();
18804 if let Some(header_offset) = &self.header_offset {
18805 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18806 }
18807 prev
18808 }
18809 pub fn push_link(mut self, value: u32) -> Self {
18810 push_header(self.as_rec_mut(), 1u16, 4 as u16);
18811 self.as_rec_mut().extend(value.to_ne_bytes());
18812 self
18813 }
18814 pub fn push_iflags(mut self, value: u16) -> Self {
18815 push_header(self.as_rec_mut(), 2u16, 2 as u16);
18816 self.as_rec_mut().extend(value.to_be_bytes());
18817 self
18818 }
18819 pub fn push_oflags(mut self, value: u16) -> Self {
18820 push_header(self.as_rec_mut(), 3u16, 2 as u16);
18821 self.as_rec_mut().extend(value.to_be_bytes());
18822 self
18823 }
18824 pub fn push_ikey(mut self, value: u32) -> Self {
18825 push_header(self.as_rec_mut(), 4u16, 4 as u16);
18826 self.as_rec_mut().extend(value.to_be_bytes());
18827 self
18828 }
18829 pub fn push_okey(mut self, value: u32) -> Self {
18830 push_header(self.as_rec_mut(), 5u16, 4 as u16);
18831 self.as_rec_mut().extend(value.to_be_bytes());
18832 self
18833 }
18834 pub fn push_local(mut self, value: &[u8]) -> Self {
18835 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
18836 self.as_rec_mut().extend(value);
18837 self
18838 }
18839 pub fn push_remote(mut self, value: &[u8]) -> Self {
18840 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
18841 self.as_rec_mut().extend(value);
18842 self
18843 }
18844 pub fn push_ttl(mut self, value: u8) -> Self {
18845 push_header(self.as_rec_mut(), 8u16, 1 as u16);
18846 self.as_rec_mut().extend(value.to_ne_bytes());
18847 self
18848 }
18849 pub fn push_encap_limit(mut self, value: u8) -> Self {
18850 push_header(self.as_rec_mut(), 11u16, 1 as u16);
18851 self.as_rec_mut().extend(value.to_ne_bytes());
18852 self
18853 }
18854 pub fn push_flowinfo(mut self, value: u32) -> Self {
18855 push_header(self.as_rec_mut(), 12u16, 4 as u16);
18856 self.as_rec_mut().extend(value.to_be_bytes());
18857 self
18858 }
18859 pub fn push_flags(mut self, value: u32) -> Self {
18860 push_header(self.as_rec_mut(), 13u16, 4 as u16);
18861 self.as_rec_mut().extend(value.to_ne_bytes());
18862 self
18863 }
18864 pub fn push_encap_type(mut self, value: u16) -> Self {
18865 push_header(self.as_rec_mut(), 14u16, 2 as u16);
18866 self.as_rec_mut().extend(value.to_ne_bytes());
18867 self
18868 }
18869 pub fn push_encap_flags(mut self, value: u16) -> Self {
18870 push_header(self.as_rec_mut(), 15u16, 2 as u16);
18871 self.as_rec_mut().extend(value.to_ne_bytes());
18872 self
18873 }
18874 pub fn push_encap_sport(mut self, value: u16) -> Self {
18875 push_header(self.as_rec_mut(), 16u16, 2 as u16);
18876 self.as_rec_mut().extend(value.to_be_bytes());
18877 self
18878 }
18879 pub fn push_encap_dport(mut self, value: u16) -> Self {
18880 push_header(self.as_rec_mut(), 17u16, 2 as u16);
18881 self.as_rec_mut().extend(value.to_be_bytes());
18882 self
18883 }
18884 pub fn push_collect_metadata(mut self, value: ()) -> Self {
18885 push_header(self.as_rec_mut(), 18u16, 0 as u16);
18886 self
18887 }
18888 pub fn push_fwmark(mut self, value: u32) -> Self {
18889 push_header(self.as_rec_mut(), 20u16, 4 as u16);
18890 self.as_rec_mut().extend(value.to_ne_bytes());
18891 self
18892 }
18893 pub fn push_erspan_index(mut self, value: u32) -> Self {
18894 push_header(self.as_rec_mut(), 21u16, 4 as u16);
18895 self.as_rec_mut().extend(value.to_ne_bytes());
18896 self
18897 }
18898 pub fn push_erspan_ver(mut self, value: u8) -> Self {
18899 push_header(self.as_rec_mut(), 22u16, 1 as u16);
18900 self.as_rec_mut().extend(value.to_ne_bytes());
18901 self
18902 }
18903 pub fn push_erspan_dir(mut self, value: u8) -> Self {
18904 push_header(self.as_rec_mut(), 23u16, 1 as u16);
18905 self.as_rec_mut().extend(value.to_ne_bytes());
18906 self
18907 }
18908 pub fn push_erspan_hwid(mut self, value: u16) -> Self {
18909 push_header(self.as_rec_mut(), 24u16, 2 as u16);
18910 self.as_rec_mut().extend(value.to_ne_bytes());
18911 self
18912 }
18913}
18914impl<Prev: Rec> Drop for PushLinkinfoGre6Attrs<Prev> {
18915 fn drop(&mut self) {
18916 if let Some(prev) = &mut self.prev {
18917 if let Some(header_offset) = &self.header_offset {
18918 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18919 }
18920 }
18921 }
18922}
18923pub struct PushLinkinfoVtiAttrs<Prev: Rec> {
18924 pub(crate) prev: Option<Prev>,
18925 pub(crate) header_offset: Option<usize>,
18926}
18927impl<Prev: Rec> Rec for PushLinkinfoVtiAttrs<Prev> {
18928 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18929 self.prev.as_mut().unwrap().as_rec_mut()
18930 }
18931}
18932impl<Prev: Rec> PushLinkinfoVtiAttrs<Prev> {
18933 pub fn new(prev: Prev) -> Self {
18934 Self {
18935 prev: Some(prev),
18936 header_offset: None,
18937 }
18938 }
18939 pub fn end_nested(mut self) -> Prev {
18940 let mut prev = self.prev.take().unwrap();
18941 if let Some(header_offset) = &self.header_offset {
18942 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18943 }
18944 prev
18945 }
18946 pub fn push_link(mut self, value: u32) -> Self {
18947 push_header(self.as_rec_mut(), 1u16, 4 as u16);
18948 self.as_rec_mut().extend(value.to_ne_bytes());
18949 self
18950 }
18951 pub fn push_ikey(mut self, value: u32) -> Self {
18952 push_header(self.as_rec_mut(), 2u16, 4 as u16);
18953 self.as_rec_mut().extend(value.to_be_bytes());
18954 self
18955 }
18956 pub fn push_okey(mut self, value: u32) -> Self {
18957 push_header(self.as_rec_mut(), 3u16, 4 as u16);
18958 self.as_rec_mut().extend(value.to_be_bytes());
18959 self
18960 }
18961 pub fn push_local(mut self, value: &[u8]) -> Self {
18962 push_header(self.as_rec_mut(), 4u16, value.len() as u16);
18963 self.as_rec_mut().extend(value);
18964 self
18965 }
18966 pub fn push_remote(mut self, value: &[u8]) -> Self {
18967 push_header(self.as_rec_mut(), 5u16, value.len() as u16);
18968 self.as_rec_mut().extend(value);
18969 self
18970 }
18971 pub fn push_fwmark(mut self, value: u32) -> Self {
18972 push_header(self.as_rec_mut(), 6u16, 4 as u16);
18973 self.as_rec_mut().extend(value.to_ne_bytes());
18974 self
18975 }
18976}
18977impl<Prev: Rec> Drop for PushLinkinfoVtiAttrs<Prev> {
18978 fn drop(&mut self) {
18979 if let Some(prev) = &mut self.prev {
18980 if let Some(header_offset) = &self.header_offset {
18981 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18982 }
18983 }
18984 }
18985}
18986pub struct PushLinkinfoVti6Attrs<Prev: Rec> {
18987 pub(crate) prev: Option<Prev>,
18988 pub(crate) header_offset: Option<usize>,
18989}
18990impl<Prev: Rec> Rec for PushLinkinfoVti6Attrs<Prev> {
18991 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18992 self.prev.as_mut().unwrap().as_rec_mut()
18993 }
18994}
18995impl<Prev: Rec> PushLinkinfoVti6Attrs<Prev> {
18996 pub fn new(prev: Prev) -> Self {
18997 Self {
18998 prev: Some(prev),
18999 header_offset: None,
19000 }
19001 }
19002 pub fn end_nested(mut self) -> Prev {
19003 let mut prev = self.prev.take().unwrap();
19004 if let Some(header_offset) = &self.header_offset {
19005 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19006 }
19007 prev
19008 }
19009 pub fn push_link(mut self, value: u32) -> Self {
19010 push_header(self.as_rec_mut(), 1u16, 4 as u16);
19011 self.as_rec_mut().extend(value.to_ne_bytes());
19012 self
19013 }
19014 pub fn push_ikey(mut self, value: u32) -> Self {
19015 push_header(self.as_rec_mut(), 2u16, 4 as u16);
19016 self.as_rec_mut().extend(value.to_be_bytes());
19017 self
19018 }
19019 pub fn push_okey(mut self, value: u32) -> Self {
19020 push_header(self.as_rec_mut(), 3u16, 4 as u16);
19021 self.as_rec_mut().extend(value.to_be_bytes());
19022 self
19023 }
19024 pub fn push_local(mut self, value: &[u8]) -> Self {
19025 push_header(self.as_rec_mut(), 4u16, value.len() as u16);
19026 self.as_rec_mut().extend(value);
19027 self
19028 }
19029 pub fn push_remote(mut self, value: &[u8]) -> Self {
19030 push_header(self.as_rec_mut(), 5u16, value.len() as u16);
19031 self.as_rec_mut().extend(value);
19032 self
19033 }
19034 pub fn push_fwmark(mut self, value: u32) -> Self {
19035 push_header(self.as_rec_mut(), 6u16, 4 as u16);
19036 self.as_rec_mut().extend(value.to_ne_bytes());
19037 self
19038 }
19039}
19040impl<Prev: Rec> Drop for PushLinkinfoVti6Attrs<Prev> {
19041 fn drop(&mut self) {
19042 if let Some(prev) = &mut self.prev {
19043 if let Some(header_offset) = &self.header_offset {
19044 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19045 }
19046 }
19047 }
19048}
19049pub struct PushLinkinfoGeneveAttrs<Prev: Rec> {
19050 pub(crate) prev: Option<Prev>,
19051 pub(crate) header_offset: Option<usize>,
19052}
19053impl<Prev: Rec> Rec for PushLinkinfoGeneveAttrs<Prev> {
19054 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19055 self.prev.as_mut().unwrap().as_rec_mut()
19056 }
19057}
19058impl<Prev: Rec> PushLinkinfoGeneveAttrs<Prev> {
19059 pub fn new(prev: Prev) -> Self {
19060 Self {
19061 prev: Some(prev),
19062 header_offset: None,
19063 }
19064 }
19065 pub fn end_nested(mut self) -> Prev {
19066 let mut prev = self.prev.take().unwrap();
19067 if let Some(header_offset) = &self.header_offset {
19068 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19069 }
19070 prev
19071 }
19072 pub fn push_id(mut self, value: u32) -> Self {
19073 push_header(self.as_rec_mut(), 1u16, 4 as u16);
19074 self.as_rec_mut().extend(value.to_ne_bytes());
19075 self
19076 }
19077 pub fn push_remote(mut self, value: &[u8]) -> Self {
19078 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
19079 self.as_rec_mut().extend(value);
19080 self
19081 }
19082 pub fn push_ttl(mut self, value: u8) -> Self {
19083 push_header(self.as_rec_mut(), 3u16, 1 as u16);
19084 self.as_rec_mut().extend(value.to_ne_bytes());
19085 self
19086 }
19087 pub fn push_tos(mut self, value: u8) -> Self {
19088 push_header(self.as_rec_mut(), 4u16, 1 as u16);
19089 self.as_rec_mut().extend(value.to_ne_bytes());
19090 self
19091 }
19092 pub fn push_port(mut self, value: u16) -> Self {
19093 push_header(self.as_rec_mut(), 5u16, 2 as u16);
19094 self.as_rec_mut().extend(value.to_be_bytes());
19095 self
19096 }
19097 pub fn push_collect_metadata(mut self, value: ()) -> Self {
19098 push_header(self.as_rec_mut(), 6u16, 0 as u16);
19099 self
19100 }
19101 pub fn push_remote6(mut self, value: &[u8]) -> Self {
19102 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
19103 self.as_rec_mut().extend(value);
19104 self
19105 }
19106 pub fn push_udp_csum(mut self, value: u8) -> Self {
19107 push_header(self.as_rec_mut(), 8u16, 1 as u16);
19108 self.as_rec_mut().extend(value.to_ne_bytes());
19109 self
19110 }
19111 pub fn push_udp_zero_csum6_tx(mut self, value: u8) -> Self {
19112 push_header(self.as_rec_mut(), 9u16, 1 as u16);
19113 self.as_rec_mut().extend(value.to_ne_bytes());
19114 self
19115 }
19116 pub fn push_udp_zero_csum6_rx(mut self, value: u8) -> Self {
19117 push_header(self.as_rec_mut(), 10u16, 1 as u16);
19118 self.as_rec_mut().extend(value.to_ne_bytes());
19119 self
19120 }
19121 pub fn push_label(mut self, value: u32) -> Self {
19122 push_header(self.as_rec_mut(), 11u16, 4 as u16);
19123 self.as_rec_mut().extend(value.to_be_bytes());
19124 self
19125 }
19126 pub fn push_ttl_inherit(mut self, value: u8) -> Self {
19127 push_header(self.as_rec_mut(), 12u16, 1 as u16);
19128 self.as_rec_mut().extend(value.to_ne_bytes());
19129 self
19130 }
19131 pub fn push_df(mut self, value: u8) -> Self {
19132 push_header(self.as_rec_mut(), 13u16, 1 as u16);
19133 self.as_rec_mut().extend(value.to_ne_bytes());
19134 self
19135 }
19136 pub fn push_inner_proto_inherit(mut self, value: ()) -> Self {
19137 push_header(self.as_rec_mut(), 14u16, 0 as u16);
19138 self
19139 }
19140 pub fn push_port_range(mut self, value: PushIflaGenevePortRange) -> Self {
19141 push_header(self.as_rec_mut(), 15u16, value.as_slice().len() as u16);
19142 self.as_rec_mut().extend(value.as_slice());
19143 self
19144 }
19145}
19146impl<Prev: Rec> Drop for PushLinkinfoGeneveAttrs<Prev> {
19147 fn drop(&mut self) {
19148 if let Some(prev) = &mut self.prev {
19149 if let Some(header_offset) = &self.header_offset {
19150 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19151 }
19152 }
19153 }
19154}
19155pub struct PushLinkinfoIptunAttrs<Prev: Rec> {
19156 pub(crate) prev: Option<Prev>,
19157 pub(crate) header_offset: Option<usize>,
19158}
19159impl<Prev: Rec> Rec for PushLinkinfoIptunAttrs<Prev> {
19160 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19161 self.prev.as_mut().unwrap().as_rec_mut()
19162 }
19163}
19164impl<Prev: Rec> PushLinkinfoIptunAttrs<Prev> {
19165 pub fn new(prev: Prev) -> Self {
19166 Self {
19167 prev: Some(prev),
19168 header_offset: None,
19169 }
19170 }
19171 pub fn end_nested(mut self) -> Prev {
19172 let mut prev = self.prev.take().unwrap();
19173 if let Some(header_offset) = &self.header_offset {
19174 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19175 }
19176 prev
19177 }
19178 pub fn push_link(mut self, value: u32) -> Self {
19179 push_header(self.as_rec_mut(), 1u16, 4 as u16);
19180 self.as_rec_mut().extend(value.to_ne_bytes());
19181 self
19182 }
19183 pub fn push_local(mut self, value: &[u8]) -> Self {
19184 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
19185 self.as_rec_mut().extend(value);
19186 self
19187 }
19188 pub fn push_remote(mut self, value: &[u8]) -> Self {
19189 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
19190 self.as_rec_mut().extend(value);
19191 self
19192 }
19193 pub fn push_ttl(mut self, value: u8) -> Self {
19194 push_header(self.as_rec_mut(), 4u16, 1 as u16);
19195 self.as_rec_mut().extend(value.to_ne_bytes());
19196 self
19197 }
19198 pub fn push_tos(mut self, value: u8) -> Self {
19199 push_header(self.as_rec_mut(), 5u16, 1 as u16);
19200 self.as_rec_mut().extend(value.to_ne_bytes());
19201 self
19202 }
19203 pub fn push_encap_limit(mut self, value: u8) -> Self {
19204 push_header(self.as_rec_mut(), 6u16, 1 as u16);
19205 self.as_rec_mut().extend(value.to_ne_bytes());
19206 self
19207 }
19208 pub fn push_flowinfo(mut self, value: u32) -> Self {
19209 push_header(self.as_rec_mut(), 7u16, 4 as u16);
19210 self.as_rec_mut().extend(value.to_be_bytes());
19211 self
19212 }
19213 pub fn push_flags(mut self, value: u16) -> Self {
19214 push_header(self.as_rec_mut(), 8u16, 2 as u16);
19215 self.as_rec_mut().extend(value.to_be_bytes());
19216 self
19217 }
19218 pub fn push_proto(mut self, value: u8) -> Self {
19219 push_header(self.as_rec_mut(), 9u16, 1 as u16);
19220 self.as_rec_mut().extend(value.to_ne_bytes());
19221 self
19222 }
19223 pub fn push_pmtudisc(mut self, value: u8) -> Self {
19224 push_header(self.as_rec_mut(), 10u16, 1 as u16);
19225 self.as_rec_mut().extend(value.to_ne_bytes());
19226 self
19227 }
19228 pub fn push_6rd_prefix(mut self, value: &[u8]) -> Self {
19229 push_header(self.as_rec_mut(), 11u16, value.len() as u16);
19230 self.as_rec_mut().extend(value);
19231 self
19232 }
19233 pub fn push_6rd_relay_prefix(mut self, value: &[u8]) -> Self {
19234 push_header(self.as_rec_mut(), 12u16, value.len() as u16);
19235 self.as_rec_mut().extend(value);
19236 self
19237 }
19238 pub fn push_6rd_prefixlen(mut self, value: u16) -> Self {
19239 push_header(self.as_rec_mut(), 13u16, 2 as u16);
19240 self.as_rec_mut().extend(value.to_ne_bytes());
19241 self
19242 }
19243 pub fn push_6rd_relay_prefixlen(mut self, value: u16) -> Self {
19244 push_header(self.as_rec_mut(), 14u16, 2 as u16);
19245 self.as_rec_mut().extend(value.to_ne_bytes());
19246 self
19247 }
19248 pub fn push_encap_type(mut self, value: u16) -> Self {
19249 push_header(self.as_rec_mut(), 15u16, 2 as u16);
19250 self.as_rec_mut().extend(value.to_ne_bytes());
19251 self
19252 }
19253 pub fn push_encap_flags(mut self, value: u16) -> Self {
19254 push_header(self.as_rec_mut(), 16u16, 2 as u16);
19255 self.as_rec_mut().extend(value.to_ne_bytes());
19256 self
19257 }
19258 pub fn push_encap_sport(mut self, value: u16) -> Self {
19259 push_header(self.as_rec_mut(), 17u16, 2 as u16);
19260 self.as_rec_mut().extend(value.to_be_bytes());
19261 self
19262 }
19263 pub fn push_encap_dport(mut self, value: u16) -> Self {
19264 push_header(self.as_rec_mut(), 18u16, 2 as u16);
19265 self.as_rec_mut().extend(value.to_be_bytes());
19266 self
19267 }
19268 pub fn push_collect_metadata(mut self, value: ()) -> Self {
19269 push_header(self.as_rec_mut(), 19u16, 0 as u16);
19270 self
19271 }
19272 pub fn push_fwmark(mut self, value: u32) -> Self {
19273 push_header(self.as_rec_mut(), 20u16, 4 as u16);
19274 self.as_rec_mut().extend(value.to_ne_bytes());
19275 self
19276 }
19277}
19278impl<Prev: Rec> Drop for PushLinkinfoIptunAttrs<Prev> {
19279 fn drop(&mut self) {
19280 if let Some(prev) = &mut self.prev {
19281 if let Some(header_offset) = &self.header_offset {
19282 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19283 }
19284 }
19285 }
19286}
19287pub struct PushLinkinfoIp6tnlAttrs<Prev: Rec> {
19288 pub(crate) prev: Option<Prev>,
19289 pub(crate) header_offset: Option<usize>,
19290}
19291impl<Prev: Rec> Rec for PushLinkinfoIp6tnlAttrs<Prev> {
19292 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19293 self.prev.as_mut().unwrap().as_rec_mut()
19294 }
19295}
19296impl<Prev: Rec> PushLinkinfoIp6tnlAttrs<Prev> {
19297 pub fn new(prev: Prev) -> Self {
19298 Self {
19299 prev: Some(prev),
19300 header_offset: None,
19301 }
19302 }
19303 pub fn end_nested(mut self) -> Prev {
19304 let mut prev = self.prev.take().unwrap();
19305 if let Some(header_offset) = &self.header_offset {
19306 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19307 }
19308 prev
19309 }
19310 pub fn push_link(mut self, value: u32) -> Self {
19311 push_header(self.as_rec_mut(), 1u16, 4 as u16);
19312 self.as_rec_mut().extend(value.to_ne_bytes());
19313 self
19314 }
19315 pub fn push_local(mut self, value: &[u8]) -> Self {
19316 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
19317 self.as_rec_mut().extend(value);
19318 self
19319 }
19320 pub fn push_remote(mut self, value: &[u8]) -> Self {
19321 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
19322 self.as_rec_mut().extend(value);
19323 self
19324 }
19325 pub fn push_ttl(mut self, value: u8) -> Self {
19326 push_header(self.as_rec_mut(), 4u16, 1 as u16);
19327 self.as_rec_mut().extend(value.to_ne_bytes());
19328 self
19329 }
19330 pub fn push_encap_limit(mut self, value: u8) -> Self {
19331 push_header(self.as_rec_mut(), 6u16, 1 as u16);
19332 self.as_rec_mut().extend(value.to_ne_bytes());
19333 self
19334 }
19335 pub fn push_flowinfo(mut self, value: u32) -> Self {
19336 push_header(self.as_rec_mut(), 7u16, 4 as u16);
19337 self.as_rec_mut().extend(value.to_be_bytes());
19338 self
19339 }
19340 pub fn push_flags(mut self, value: u32) -> Self {
19341 push_header(self.as_rec_mut(), 8u16, 4 as u16);
19342 self.as_rec_mut().extend(value.to_be_bytes());
19343 self
19344 }
19345 pub fn push_proto(mut self, value: u8) -> Self {
19346 push_header(self.as_rec_mut(), 9u16, 1 as u16);
19347 self.as_rec_mut().extend(value.to_ne_bytes());
19348 self
19349 }
19350 pub fn push_encap_type(mut self, value: u16) -> Self {
19351 push_header(self.as_rec_mut(), 15u16, 2 as u16);
19352 self.as_rec_mut().extend(value.to_ne_bytes());
19353 self
19354 }
19355 pub fn push_encap_flags(mut self, value: u16) -> Self {
19356 push_header(self.as_rec_mut(), 16u16, 2 as u16);
19357 self.as_rec_mut().extend(value.to_ne_bytes());
19358 self
19359 }
19360 pub fn push_encap_sport(mut self, value: u16) -> Self {
19361 push_header(self.as_rec_mut(), 17u16, 2 as u16);
19362 self.as_rec_mut().extend(value.to_be_bytes());
19363 self
19364 }
19365 pub fn push_encap_dport(mut self, value: u16) -> Self {
19366 push_header(self.as_rec_mut(), 18u16, 2 as u16);
19367 self.as_rec_mut().extend(value.to_be_bytes());
19368 self
19369 }
19370 pub fn push_collect_metadata(mut self, value: ()) -> Self {
19371 push_header(self.as_rec_mut(), 19u16, 0 as u16);
19372 self
19373 }
19374 pub fn push_fwmark(mut self, value: u32) -> Self {
19375 push_header(self.as_rec_mut(), 20u16, 4 as u16);
19376 self.as_rec_mut().extend(value.to_ne_bytes());
19377 self
19378 }
19379}
19380impl<Prev: Rec> Drop for PushLinkinfoIp6tnlAttrs<Prev> {
19381 fn drop(&mut self) {
19382 if let Some(prev) = &mut self.prev {
19383 if let Some(header_offset) = &self.header_offset {
19384 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19385 }
19386 }
19387 }
19388}
19389pub struct PushLinkinfoTunAttrs<Prev: Rec> {
19390 pub(crate) prev: Option<Prev>,
19391 pub(crate) header_offset: Option<usize>,
19392}
19393impl<Prev: Rec> Rec for PushLinkinfoTunAttrs<Prev> {
19394 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19395 self.prev.as_mut().unwrap().as_rec_mut()
19396 }
19397}
19398impl<Prev: Rec> PushLinkinfoTunAttrs<Prev> {
19399 pub fn new(prev: Prev) -> Self {
19400 Self {
19401 prev: Some(prev),
19402 header_offset: None,
19403 }
19404 }
19405 pub fn end_nested(mut self) -> Prev {
19406 let mut prev = self.prev.take().unwrap();
19407 if let Some(header_offset) = &self.header_offset {
19408 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19409 }
19410 prev
19411 }
19412 pub fn push_owner(mut self, value: u32) -> Self {
19413 push_header(self.as_rec_mut(), 1u16, 4 as u16);
19414 self.as_rec_mut().extend(value.to_ne_bytes());
19415 self
19416 }
19417 pub fn push_group(mut self, value: u32) -> Self {
19418 push_header(self.as_rec_mut(), 2u16, 4 as u16);
19419 self.as_rec_mut().extend(value.to_ne_bytes());
19420 self
19421 }
19422 pub fn push_type(mut self, value: u8) -> Self {
19423 push_header(self.as_rec_mut(), 3u16, 1 as u16);
19424 self.as_rec_mut().extend(value.to_ne_bytes());
19425 self
19426 }
19427 pub fn push_pi(mut self, value: u8) -> Self {
19428 push_header(self.as_rec_mut(), 4u16, 1 as u16);
19429 self.as_rec_mut().extend(value.to_ne_bytes());
19430 self
19431 }
19432 pub fn push_vnet_hdr(mut self, value: u8) -> Self {
19433 push_header(self.as_rec_mut(), 5u16, 1 as u16);
19434 self.as_rec_mut().extend(value.to_ne_bytes());
19435 self
19436 }
19437 pub fn push_persist(mut self, value: u8) -> Self {
19438 push_header(self.as_rec_mut(), 6u16, 1 as u16);
19439 self.as_rec_mut().extend(value.to_ne_bytes());
19440 self
19441 }
19442 pub fn push_multi_queue(mut self, value: u8) -> Self {
19443 push_header(self.as_rec_mut(), 7u16, 1 as u16);
19444 self.as_rec_mut().extend(value.to_ne_bytes());
19445 self
19446 }
19447 pub fn push_num_queues(mut self, value: u32) -> Self {
19448 push_header(self.as_rec_mut(), 8u16, 4 as u16);
19449 self.as_rec_mut().extend(value.to_ne_bytes());
19450 self
19451 }
19452 pub fn push_num_disabled_queues(mut self, value: u32) -> Self {
19453 push_header(self.as_rec_mut(), 9u16, 4 as u16);
19454 self.as_rec_mut().extend(value.to_ne_bytes());
19455 self
19456 }
19457}
19458impl<Prev: Rec> Drop for PushLinkinfoTunAttrs<Prev> {
19459 fn drop(&mut self) {
19460 if let Some(prev) = &mut self.prev {
19461 if let Some(header_offset) = &self.header_offset {
19462 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19463 }
19464 }
19465 }
19466}
19467pub struct PushLinkinfoVlanAttrs<Prev: Rec> {
19468 pub(crate) prev: Option<Prev>,
19469 pub(crate) header_offset: Option<usize>,
19470}
19471impl<Prev: Rec> Rec for PushLinkinfoVlanAttrs<Prev> {
19472 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19473 self.prev.as_mut().unwrap().as_rec_mut()
19474 }
19475}
19476impl<Prev: Rec> PushLinkinfoVlanAttrs<Prev> {
19477 pub fn new(prev: Prev) -> Self {
19478 Self {
19479 prev: Some(prev),
19480 header_offset: None,
19481 }
19482 }
19483 pub fn end_nested(mut self) -> Prev {
19484 let mut prev = self.prev.take().unwrap();
19485 if let Some(header_offset) = &self.header_offset {
19486 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19487 }
19488 prev
19489 }
19490 pub fn push_id(mut self, value: u16) -> Self {
19491 push_header(self.as_rec_mut(), 1u16, 2 as u16);
19492 self.as_rec_mut().extend(value.to_ne_bytes());
19493 self
19494 }
19495 pub fn push_flags(mut self, value: PushIflaVlanFlags) -> Self {
19496 push_header(self.as_rec_mut(), 2u16, value.as_slice().len() as u16);
19497 self.as_rec_mut().extend(value.as_slice());
19498 self
19499 }
19500 pub fn nested_egress_qos(mut self) -> PushIflaVlanQos<Self> {
19501 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
19502 PushIflaVlanQos {
19503 prev: Some(self),
19504 header_offset: Some(header_offset),
19505 }
19506 }
19507 pub fn nested_ingress_qos(mut self) -> PushIflaVlanQos<Self> {
19508 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
19509 PushIflaVlanQos {
19510 prev: Some(self),
19511 header_offset: Some(header_offset),
19512 }
19513 }
19514 #[doc = "Associated type: \"VlanProtocols\" (enum)"]
19515 pub fn push_protocol(mut self, value: u16) -> Self {
19516 push_header(self.as_rec_mut(), 5u16, 2 as u16);
19517 self.as_rec_mut().extend(value.to_be_bytes());
19518 self
19519 }
19520}
19521impl<Prev: Rec> Drop for PushLinkinfoVlanAttrs<Prev> {
19522 fn drop(&mut self) {
19523 if let Some(prev) = &mut self.prev {
19524 if let Some(header_offset) = &self.header_offset {
19525 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19526 }
19527 }
19528 }
19529}
19530pub struct PushIflaVlanQos<Prev: Rec> {
19531 pub(crate) prev: Option<Prev>,
19532 pub(crate) header_offset: Option<usize>,
19533}
19534impl<Prev: Rec> Rec for PushIflaVlanQos<Prev> {
19535 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19536 self.prev.as_mut().unwrap().as_rec_mut()
19537 }
19538}
19539impl<Prev: Rec> PushIflaVlanQos<Prev> {
19540 pub fn new(prev: Prev) -> Self {
19541 Self {
19542 prev: Some(prev),
19543 header_offset: None,
19544 }
19545 }
19546 pub fn end_nested(mut self) -> Prev {
19547 let mut prev = self.prev.take().unwrap();
19548 if let Some(header_offset) = &self.header_offset {
19549 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19550 }
19551 prev
19552 }
19553 #[doc = "Attribute may repeat multiple times (treat it as array)"]
19554 pub fn push_mapping(mut self, value: PushIflaVlanQosMapping) -> Self {
19555 push_header(self.as_rec_mut(), 1u16, value.as_slice().len() as u16);
19556 self.as_rec_mut().extend(value.as_slice());
19557 self
19558 }
19559}
19560impl<Prev: Rec> Drop for PushIflaVlanQos<Prev> {
19561 fn drop(&mut self) {
19562 if let Some(prev) = &mut self.prev {
19563 if let Some(header_offset) = &self.header_offset {
19564 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19565 }
19566 }
19567 }
19568}
19569pub struct PushLinkinfoVrfAttrs<Prev: Rec> {
19570 pub(crate) prev: Option<Prev>,
19571 pub(crate) header_offset: Option<usize>,
19572}
19573impl<Prev: Rec> Rec for PushLinkinfoVrfAttrs<Prev> {
19574 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19575 self.prev.as_mut().unwrap().as_rec_mut()
19576 }
19577}
19578impl<Prev: Rec> PushLinkinfoVrfAttrs<Prev> {
19579 pub fn new(prev: Prev) -> Self {
19580 Self {
19581 prev: Some(prev),
19582 header_offset: None,
19583 }
19584 }
19585 pub fn end_nested(mut self) -> Prev {
19586 let mut prev = self.prev.take().unwrap();
19587 if let Some(header_offset) = &self.header_offset {
19588 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19589 }
19590 prev
19591 }
19592 pub fn push_table(mut self, value: u32) -> Self {
19593 push_header(self.as_rec_mut(), 1u16, 4 as u16);
19594 self.as_rec_mut().extend(value.to_ne_bytes());
19595 self
19596 }
19597}
19598impl<Prev: Rec> Drop for PushLinkinfoVrfAttrs<Prev> {
19599 fn drop(&mut self) {
19600 if let Some(prev) = &mut self.prev {
19601 if let Some(header_offset) = &self.header_offset {
19602 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19603 }
19604 }
19605 }
19606}
19607pub struct PushXdpAttrs<Prev: Rec> {
19608 pub(crate) prev: Option<Prev>,
19609 pub(crate) header_offset: Option<usize>,
19610}
19611impl<Prev: Rec> Rec for PushXdpAttrs<Prev> {
19612 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19613 self.prev.as_mut().unwrap().as_rec_mut()
19614 }
19615}
19616impl<Prev: Rec> PushXdpAttrs<Prev> {
19617 pub fn new(prev: Prev) -> Self {
19618 Self {
19619 prev: Some(prev),
19620 header_offset: None,
19621 }
19622 }
19623 pub fn end_nested(mut self) -> Prev {
19624 let mut prev = self.prev.take().unwrap();
19625 if let Some(header_offset) = &self.header_offset {
19626 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19627 }
19628 prev
19629 }
19630 pub fn push_fd(mut self, value: i32) -> Self {
19631 push_header(self.as_rec_mut(), 1u16, 4 as u16);
19632 self.as_rec_mut().extend(value.to_ne_bytes());
19633 self
19634 }
19635 pub fn push_attached(mut self, value: u8) -> Self {
19636 push_header(self.as_rec_mut(), 2u16, 1 as u16);
19637 self.as_rec_mut().extend(value.to_ne_bytes());
19638 self
19639 }
19640 pub fn push_flags(mut self, value: u32) -> Self {
19641 push_header(self.as_rec_mut(), 3u16, 4 as u16);
19642 self.as_rec_mut().extend(value.to_ne_bytes());
19643 self
19644 }
19645 pub fn push_prog_id(mut self, value: u32) -> Self {
19646 push_header(self.as_rec_mut(), 4u16, 4 as u16);
19647 self.as_rec_mut().extend(value.to_ne_bytes());
19648 self
19649 }
19650 pub fn push_drv_prog_id(mut self, value: u32) -> Self {
19651 push_header(self.as_rec_mut(), 5u16, 4 as u16);
19652 self.as_rec_mut().extend(value.to_ne_bytes());
19653 self
19654 }
19655 pub fn push_skb_prog_id(mut self, value: u32) -> Self {
19656 push_header(self.as_rec_mut(), 6u16, 4 as u16);
19657 self.as_rec_mut().extend(value.to_ne_bytes());
19658 self
19659 }
19660 pub fn push_hw_prog_id(mut self, value: u32) -> Self {
19661 push_header(self.as_rec_mut(), 7u16, 4 as u16);
19662 self.as_rec_mut().extend(value.to_ne_bytes());
19663 self
19664 }
19665 pub fn push_expected_fd(mut self, value: i32) -> Self {
19666 push_header(self.as_rec_mut(), 8u16, 4 as u16);
19667 self.as_rec_mut().extend(value.to_ne_bytes());
19668 self
19669 }
19670}
19671impl<Prev: Rec> Drop for PushXdpAttrs<Prev> {
19672 fn drop(&mut self) {
19673 if let Some(prev) = &mut self.prev {
19674 if let Some(header_offset) = &self.header_offset {
19675 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19676 }
19677 }
19678 }
19679}
19680pub struct PushIflaAttrs<Prev: Rec> {
19681 pub(crate) prev: Option<Prev>,
19682 pub(crate) header_offset: Option<usize>,
19683}
19684impl<Prev: Rec> Rec for PushIflaAttrs<Prev> {
19685 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19686 self.prev.as_mut().unwrap().as_rec_mut()
19687 }
19688}
19689impl<Prev: Rec> PushIflaAttrs<Prev> {
19690 pub fn new(prev: Prev) -> Self {
19691 Self {
19692 prev: Some(prev),
19693 header_offset: None,
19694 }
19695 }
19696 pub fn end_nested(mut self) -> Prev {
19697 let mut prev = self.prev.take().unwrap();
19698 if let Some(header_offset) = &self.header_offset {
19699 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19700 }
19701 prev
19702 }
19703 #[doc = "u32 indexed by ipv4-devconf - 1 on output, on input it's a nest"]
19704 pub fn push_conf(mut self, value: &[u8]) -> Self {
19705 push_header(self.as_rec_mut(), 1u16, value.len() as u16);
19706 self.as_rec_mut().extend(value);
19707 self
19708 }
19709}
19710impl<Prev: Rec> Drop for PushIflaAttrs<Prev> {
19711 fn drop(&mut self) {
19712 if let Some(prev) = &mut self.prev {
19713 if let Some(header_offset) = &self.header_offset {
19714 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19715 }
19716 }
19717 }
19718}
19719pub struct PushIfla6Attrs<Prev: Rec> {
19720 pub(crate) prev: Option<Prev>,
19721 pub(crate) header_offset: Option<usize>,
19722}
19723impl<Prev: Rec> Rec for PushIfla6Attrs<Prev> {
19724 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19725 self.prev.as_mut().unwrap().as_rec_mut()
19726 }
19727}
19728impl<Prev: Rec> PushIfla6Attrs<Prev> {
19729 pub fn new(prev: Prev) -> Self {
19730 Self {
19731 prev: Some(prev),
19732 header_offset: None,
19733 }
19734 }
19735 pub fn end_nested(mut self) -> Prev {
19736 let mut prev = self.prev.take().unwrap();
19737 if let Some(header_offset) = &self.header_offset {
19738 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19739 }
19740 prev
19741 }
19742 pub fn push_flags(mut self, value: u32) -> Self {
19743 push_header(self.as_rec_mut(), 1u16, 4 as u16);
19744 self.as_rec_mut().extend(value.to_ne_bytes());
19745 self
19746 }
19747 #[doc = "u32 indexed by ipv6-devconf - 1 on output, on input it's a nest"]
19748 pub fn push_conf(mut self, value: &[u8]) -> Self {
19749 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
19750 self.as_rec_mut().extend(value);
19751 self
19752 }
19753 pub fn push_stats(mut self, value: &[u8]) -> Self {
19754 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
19755 self.as_rec_mut().extend(value);
19756 self
19757 }
19758 pub fn push_mcast(mut self, value: &[u8]) -> Self {
19759 push_header(self.as_rec_mut(), 4u16, value.len() as u16);
19760 self.as_rec_mut().extend(value);
19761 self
19762 }
19763 pub fn push_cacheinfo(mut self, value: PushIflaCacheinfo) -> Self {
19764 push_header(self.as_rec_mut(), 5u16, value.as_slice().len() as u16);
19765 self.as_rec_mut().extend(value.as_slice());
19766 self
19767 }
19768 pub fn push_icmp6stats(mut self, value: &[u8]) -> Self {
19769 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
19770 self.as_rec_mut().extend(value);
19771 self
19772 }
19773 pub fn push_token(mut self, value: &[u8]) -> Self {
19774 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
19775 self.as_rec_mut().extend(value);
19776 self
19777 }
19778 pub fn push_addr_gen_mode(mut self, value: u8) -> Self {
19779 push_header(self.as_rec_mut(), 8u16, 1 as u16);
19780 self.as_rec_mut().extend(value.to_ne_bytes());
19781 self
19782 }
19783 pub fn push_ra_mtu(mut self, value: u32) -> Self {
19784 push_header(self.as_rec_mut(), 9u16, 4 as u16);
19785 self.as_rec_mut().extend(value.to_ne_bytes());
19786 self
19787 }
19788}
19789impl<Prev: Rec> Drop for PushIfla6Attrs<Prev> {
19790 fn drop(&mut self) {
19791 if let Some(prev) = &mut self.prev {
19792 if let Some(header_offset) = &self.header_offset {
19793 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19794 }
19795 }
19796 }
19797}
19798pub struct PushMctpAttrs<Prev: Rec> {
19799 pub(crate) prev: Option<Prev>,
19800 pub(crate) header_offset: Option<usize>,
19801}
19802impl<Prev: Rec> Rec for PushMctpAttrs<Prev> {
19803 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19804 self.prev.as_mut().unwrap().as_rec_mut()
19805 }
19806}
19807impl<Prev: Rec> PushMctpAttrs<Prev> {
19808 pub fn new(prev: Prev) -> Self {
19809 Self {
19810 prev: Some(prev),
19811 header_offset: None,
19812 }
19813 }
19814 pub fn end_nested(mut self) -> Prev {
19815 let mut prev = self.prev.take().unwrap();
19816 if let Some(header_offset) = &self.header_offset {
19817 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19818 }
19819 prev
19820 }
19821 pub fn push_net(mut self, value: u32) -> Self {
19822 push_header(self.as_rec_mut(), 1u16, 4 as u16);
19823 self.as_rec_mut().extend(value.to_ne_bytes());
19824 self
19825 }
19826 pub fn push_phys_binding(mut self, value: u8) -> Self {
19827 push_header(self.as_rec_mut(), 2u16, 1 as u16);
19828 self.as_rec_mut().extend(value.to_ne_bytes());
19829 self
19830 }
19831}
19832impl<Prev: Rec> Drop for PushMctpAttrs<Prev> {
19833 fn drop(&mut self) {
19834 if let Some(prev) = &mut self.prev {
19835 if let Some(header_offset) = &self.header_offset {
19836 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19837 }
19838 }
19839 }
19840}
19841pub struct PushStatsAttrs<Prev: Rec> {
19842 pub(crate) prev: Option<Prev>,
19843 pub(crate) header_offset: Option<usize>,
19844}
19845impl<Prev: Rec> Rec for PushStatsAttrs<Prev> {
19846 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19847 self.prev.as_mut().unwrap().as_rec_mut()
19848 }
19849}
19850impl<Prev: Rec> PushStatsAttrs<Prev> {
19851 pub fn new(prev: Prev) -> Self {
19852 Self {
19853 prev: Some(prev),
19854 header_offset: None,
19855 }
19856 }
19857 pub fn end_nested(mut self) -> Prev {
19858 let mut prev = self.prev.take().unwrap();
19859 if let Some(header_offset) = &self.header_offset {
19860 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19861 }
19862 prev
19863 }
19864 pub fn push_link_64(mut self, value: PushRtnlLinkStats64) -> Self {
19865 push_header(self.as_rec_mut(), 1u16, value.as_slice().len() as u16);
19866 self.as_rec_mut().extend(value.as_slice());
19867 self
19868 }
19869 pub fn push_link_xstats(mut self, value: &[u8]) -> Self {
19870 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
19871 self.as_rec_mut().extend(value);
19872 self
19873 }
19874 pub fn push_link_xstats_slave(mut self, value: &[u8]) -> Self {
19875 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
19876 self.as_rec_mut().extend(value);
19877 self
19878 }
19879 pub fn nested_link_offload_xstats(mut self) -> PushLinkOffloadXstats<Self> {
19880 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
19881 PushLinkOffloadXstats {
19882 prev: Some(self),
19883 header_offset: Some(header_offset),
19884 }
19885 }
19886 pub fn push_af_spec(mut self, value: &[u8]) -> Self {
19887 push_header(self.as_rec_mut(), 5u16, value.len() as u16);
19888 self.as_rec_mut().extend(value);
19889 self
19890 }
19891}
19892impl<Prev: Rec> Drop for PushStatsAttrs<Prev> {
19893 fn drop(&mut self) {
19894 if let Some(prev) = &mut self.prev {
19895 if let Some(header_offset) = &self.header_offset {
19896 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19897 }
19898 }
19899 }
19900}
19901pub struct PushLinkOffloadXstats<Prev: Rec> {
19902 pub(crate) prev: Option<Prev>,
19903 pub(crate) header_offset: Option<usize>,
19904}
19905impl<Prev: Rec> Rec for PushLinkOffloadXstats<Prev> {
19906 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19907 self.prev.as_mut().unwrap().as_rec_mut()
19908 }
19909}
19910pub struct PushArrayHwSInfoOne<Prev: Rec> {
19911 pub(crate) prev: Option<Prev>,
19912 pub(crate) header_offset: Option<usize>,
19913 pub(crate) counter: u16,
19914}
19915impl<Prev: Rec> Rec for PushArrayHwSInfoOne<Prev> {
19916 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19917 self.prev.as_mut().unwrap().as_rec_mut()
19918 }
19919}
19920impl<Prev: Rec> PushArrayHwSInfoOne<Prev> {
19921 pub fn new(prev: Prev) -> Self {
19922 Self {
19923 prev: Some(prev),
19924 header_offset: None,
19925 counter: 0,
19926 }
19927 }
19928 pub fn end_array(mut self) -> Prev {
19929 let mut prev = self.prev.take().unwrap();
19930 if let Some(header_offset) = &self.header_offset {
19931 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19932 }
19933 prev
19934 }
19935 pub fn entry_nested(mut self) -> PushHwSInfoOne<Self> {
19936 let index = self.counter;
19937 self.counter += 1;
19938 let header_offset = push_nested_header(self.as_rec_mut(), index);
19939 PushHwSInfoOne {
19940 prev: Some(self),
19941 header_offset: Some(header_offset),
19942 }
19943 }
19944}
19945impl<Prev: Rec> Drop for PushArrayHwSInfoOne<Prev> {
19946 fn drop(&mut self) {
19947 if let Some(prev) = &mut self.prev {
19948 if let Some(header_offset) = &self.header_offset {
19949 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19950 }
19951 }
19952 }
19953}
19954impl<Prev: Rec> PushLinkOffloadXstats<Prev> {
19955 pub fn new(prev: Prev) -> Self {
19956 Self {
19957 prev: Some(prev),
19958 header_offset: None,
19959 }
19960 }
19961 pub fn end_nested(mut self) -> Prev {
19962 let mut prev = self.prev.take().unwrap();
19963 if let Some(header_offset) = &self.header_offset {
19964 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19965 }
19966 prev
19967 }
19968 pub fn push_cpu_hit(mut self, value: &[u8]) -> Self {
19969 push_header(self.as_rec_mut(), 1u16, value.len() as u16);
19970 self.as_rec_mut().extend(value);
19971 self
19972 }
19973 pub fn array_hw_s_info(mut self) -> PushArrayHwSInfoOne<Self> {
19974 let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
19975 PushArrayHwSInfoOne {
19976 prev: Some(self),
19977 header_offset: Some(header_offset),
19978 counter: 0,
19979 }
19980 }
19981 pub fn push_l3_stats(mut self, value: &[u8]) -> Self {
19982 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
19983 self.as_rec_mut().extend(value);
19984 self
19985 }
19986}
19987impl<Prev: Rec> Drop for PushLinkOffloadXstats<Prev> {
19988 fn drop(&mut self) {
19989 if let Some(prev) = &mut self.prev {
19990 if let Some(header_offset) = &self.header_offset {
19991 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19992 }
19993 }
19994 }
19995}
19996pub struct PushHwSInfoOne<Prev: Rec> {
19997 pub(crate) prev: Option<Prev>,
19998 pub(crate) header_offset: Option<usize>,
19999}
20000impl<Prev: Rec> Rec for PushHwSInfoOne<Prev> {
20001 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
20002 self.prev.as_mut().unwrap().as_rec_mut()
20003 }
20004}
20005impl<Prev: Rec> PushHwSInfoOne<Prev> {
20006 pub fn new(prev: Prev) -> Self {
20007 Self {
20008 prev: Some(prev),
20009 header_offset: None,
20010 }
20011 }
20012 pub fn end_nested(mut self) -> Prev {
20013 let mut prev = self.prev.take().unwrap();
20014 if let Some(header_offset) = &self.header_offset {
20015 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20016 }
20017 prev
20018 }
20019 pub fn push_request(mut self, value: u8) -> Self {
20020 push_header(self.as_rec_mut(), 1u16, 1 as u16);
20021 self.as_rec_mut().extend(value.to_ne_bytes());
20022 self
20023 }
20024 pub fn push_used(mut self, value: u8) -> Self {
20025 push_header(self.as_rec_mut(), 2u16, 1 as u16);
20026 self.as_rec_mut().extend(value.to_ne_bytes());
20027 self
20028 }
20029}
20030impl<Prev: Rec> Drop for PushHwSInfoOne<Prev> {
20031 fn drop(&mut self) {
20032 if let Some(prev) = &mut self.prev {
20033 if let Some(header_offset) = &self.header_offset {
20034 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20035 }
20036 }
20037 }
20038}
20039pub struct PushLinkDpllPinAttrs<Prev: Rec> {
20040 pub(crate) prev: Option<Prev>,
20041 pub(crate) header_offset: Option<usize>,
20042}
20043impl<Prev: Rec> Rec for PushLinkDpllPinAttrs<Prev> {
20044 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
20045 self.prev.as_mut().unwrap().as_rec_mut()
20046 }
20047}
20048impl<Prev: Rec> PushLinkDpllPinAttrs<Prev> {
20049 pub fn new(prev: Prev) -> Self {
20050 Self {
20051 prev: Some(prev),
20052 header_offset: None,
20053 }
20054 }
20055 pub fn end_nested(mut self) -> Prev {
20056 let mut prev = self.prev.take().unwrap();
20057 if let Some(header_offset) = &self.header_offset {
20058 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20059 }
20060 prev
20061 }
20062 pub fn push_id(mut self, value: u32) -> Self {
20063 push_header(self.as_rec_mut(), 1u16, 4 as u16);
20064 self.as_rec_mut().extend(value.to_ne_bytes());
20065 self
20066 }
20067}
20068impl<Prev: Rec> Drop for PushLinkDpllPinAttrs<Prev> {
20069 fn drop(&mut self) {
20070 if let Some(prev) = &mut self.prev {
20071 if let Some(header_offset) = &self.header_offset {
20072 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20073 }
20074 }
20075 }
20076}
20077pub struct PushLinkinfoNetkitAttrs<Prev: Rec> {
20078 pub(crate) prev: Option<Prev>,
20079 pub(crate) header_offset: Option<usize>,
20080}
20081impl<Prev: Rec> Rec for PushLinkinfoNetkitAttrs<Prev> {
20082 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
20083 self.prev.as_mut().unwrap().as_rec_mut()
20084 }
20085}
20086impl<Prev: Rec> PushLinkinfoNetkitAttrs<Prev> {
20087 pub fn new(prev: Prev) -> Self {
20088 Self {
20089 prev: Some(prev),
20090 header_offset: None,
20091 }
20092 }
20093 pub fn end_nested(mut self) -> Prev {
20094 let mut prev = self.prev.take().unwrap();
20095 if let Some(header_offset) = &self.header_offset {
20096 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20097 }
20098 prev
20099 }
20100 pub fn push_peer_info(mut self, value: &[u8]) -> Self {
20101 push_header(self.as_rec_mut(), 1u16, value.len() as u16);
20102 self.as_rec_mut().extend(value);
20103 self
20104 }
20105 pub fn push_primary(mut self, value: u8) -> Self {
20106 push_header(self.as_rec_mut(), 2u16, 1 as u16);
20107 self.as_rec_mut().extend(value.to_ne_bytes());
20108 self
20109 }
20110 #[doc = "Associated type: \"NetkitPolicy\" (enum)"]
20111 pub fn push_policy(mut self, value: u32) -> Self {
20112 push_header(self.as_rec_mut(), 3u16, 4 as u16);
20113 self.as_rec_mut().extend(value.to_ne_bytes());
20114 self
20115 }
20116 #[doc = "Associated type: \"NetkitPolicy\" (enum)"]
20117 pub fn push_peer_policy(mut self, value: u32) -> Self {
20118 push_header(self.as_rec_mut(), 4u16, 4 as u16);
20119 self.as_rec_mut().extend(value.to_ne_bytes());
20120 self
20121 }
20122 #[doc = "Associated type: \"NetkitMode\" (enum)"]
20123 pub fn push_mode(mut self, value: u32) -> Self {
20124 push_header(self.as_rec_mut(), 5u16, 4 as u16);
20125 self.as_rec_mut().extend(value.to_ne_bytes());
20126 self
20127 }
20128 #[doc = "Associated type: \"NetkitScrub\" (enum)"]
20129 pub fn push_scrub(mut self, value: u32) -> Self {
20130 push_header(self.as_rec_mut(), 6u16, 4 as u16);
20131 self.as_rec_mut().extend(value.to_ne_bytes());
20132 self
20133 }
20134 #[doc = "Associated type: \"NetkitScrub\" (enum)"]
20135 pub fn push_peer_scrub(mut self, value: u32) -> Self {
20136 push_header(self.as_rec_mut(), 7u16, 4 as u16);
20137 self.as_rec_mut().extend(value.to_ne_bytes());
20138 self
20139 }
20140 pub fn push_headroom(mut self, value: u16) -> Self {
20141 push_header(self.as_rec_mut(), 8u16, 2 as u16);
20142 self.as_rec_mut().extend(value.to_ne_bytes());
20143 self
20144 }
20145 pub fn push_tailroom(mut self, value: u16) -> Self {
20146 push_header(self.as_rec_mut(), 9u16, 2 as u16);
20147 self.as_rec_mut().extend(value.to_ne_bytes());
20148 self
20149 }
20150}
20151impl<Prev: Rec> Drop for PushLinkinfoNetkitAttrs<Prev> {
20152 fn drop(&mut self) {
20153 if let Some(prev) = &mut self.prev {
20154 if let Some(header_offset) = &self.header_offset {
20155 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20156 }
20157 }
20158 }
20159}
20160pub struct PushLinkinfoOvpnAttrs<Prev: Rec> {
20161 pub(crate) prev: Option<Prev>,
20162 pub(crate) header_offset: Option<usize>,
20163}
20164impl<Prev: Rec> Rec for PushLinkinfoOvpnAttrs<Prev> {
20165 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
20166 self.prev.as_mut().unwrap().as_rec_mut()
20167 }
20168}
20169impl<Prev: Rec> PushLinkinfoOvpnAttrs<Prev> {
20170 pub fn new(prev: Prev) -> Self {
20171 Self {
20172 prev: Some(prev),
20173 header_offset: None,
20174 }
20175 }
20176 pub fn end_nested(mut self) -> Prev {
20177 let mut prev = self.prev.take().unwrap();
20178 if let Some(header_offset) = &self.header_offset {
20179 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20180 }
20181 prev
20182 }
20183 #[doc = "Associated type: \"OvpnMode\" (enum)"]
20184 pub fn push_mode(mut self, value: u8) -> Self {
20185 push_header(self.as_rec_mut(), 1u16, 1 as u16);
20186 self.as_rec_mut().extend(value.to_ne_bytes());
20187 self
20188 }
20189}
20190impl<Prev: Rec> Drop for PushLinkinfoOvpnAttrs<Prev> {
20191 fn drop(&mut self) {
20192 if let Some(prev) = &mut self.prev {
20193 if let Some(header_offset) = &self.header_offset {
20194 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20195 }
20196 }
20197 }
20198}
20199#[derive(Clone)]
20200pub struct PushRtgenmsg {
20201 pub(crate) buf: [u8; 1usize],
20202}
20203#[doc = "Create zero-initialized struct"]
20204impl Default for PushRtgenmsg {
20205 fn default() -> Self {
20206 Self { buf: [0u8; 1usize] }
20207 }
20208}
20209impl PushRtgenmsg {
20210 #[doc = "Create zero-initialized struct"]
20211 pub fn new() -> Self {
20212 Default::default()
20213 }
20214 #[doc = "Copy from contents from other slice"]
20215 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
20216 if other.len() != Self::len() {
20217 return None;
20218 }
20219 let mut buf = [0u8; Self::len()];
20220 buf.clone_from_slice(other);
20221 Some(Self { buf })
20222 }
20223 pub fn as_slice(&self) -> &[u8] {
20224 &self.buf
20225 }
20226 pub fn as_mut_slice(&mut self) -> &mut [u8] {
20227 &mut self.buf
20228 }
20229 pub const fn len() -> usize {
20230 1usize
20231 }
20232 pub fn family(&self) -> u8 {
20233 parse_u8(&self.buf[0usize..1usize]).unwrap()
20234 }
20235 pub fn set_family(&mut self, value: u8) {
20236 self.buf[0usize..1usize].copy_from_slice(&value.to_ne_bytes())
20237 }
20238}
20239impl std::fmt::Debug for PushRtgenmsg {
20240 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20241 fmt.debug_struct("Rtgenmsg")
20242 .field("family", &self.family())
20243 .finish()
20244 }
20245}
20246#[derive(Clone)]
20247pub struct PushIfinfomsg {
20248 pub(crate) buf: [u8; 16usize],
20249}
20250#[doc = "Create zero-initialized struct"]
20251impl Default for PushIfinfomsg {
20252 fn default() -> Self {
20253 Self {
20254 buf: [0u8; 16usize],
20255 }
20256 }
20257}
20258impl PushIfinfomsg {
20259 #[doc = "Create zero-initialized struct"]
20260 pub fn new() -> Self {
20261 Default::default()
20262 }
20263 #[doc = "Copy from contents from other slice"]
20264 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
20265 if other.len() != Self::len() {
20266 return None;
20267 }
20268 let mut buf = [0u8; Self::len()];
20269 buf.clone_from_slice(other);
20270 Some(Self { buf })
20271 }
20272 pub fn as_slice(&self) -> &[u8] {
20273 &self.buf
20274 }
20275 pub fn as_mut_slice(&mut self) -> &mut [u8] {
20276 &mut self.buf
20277 }
20278 pub const fn len() -> usize {
20279 16usize
20280 }
20281 pub fn ifi_family(&self) -> u8 {
20282 parse_u8(&self.buf[0usize..1usize]).unwrap()
20283 }
20284 pub fn set_ifi_family(&mut self, value: u8) {
20285 self.buf[0usize..1usize].copy_from_slice(&value.to_ne_bytes())
20286 }
20287 pub fn ifi_type(&self) -> u16 {
20288 parse_u16(&self.buf[2usize..4usize]).unwrap()
20289 }
20290 pub fn set_ifi_type(&mut self, value: u16) {
20291 self.buf[2usize..4usize].copy_from_slice(&value.to_ne_bytes())
20292 }
20293 pub fn ifi_index(&self) -> i32 {
20294 parse_i32(&self.buf[4usize..8usize]).unwrap()
20295 }
20296 pub fn set_ifi_index(&mut self, value: i32) {
20297 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
20298 }
20299 #[doc = "Associated type: \"IfinfoFlags\" (1 bit per enumeration)"]
20300 pub fn ifi_flags(&self) -> u32 {
20301 parse_u32(&self.buf[8usize..12usize]).unwrap()
20302 }
20303 #[doc = "Associated type: \"IfinfoFlags\" (1 bit per enumeration)"]
20304 pub fn set_ifi_flags(&mut self, value: u32) {
20305 self.buf[8usize..12usize].copy_from_slice(&value.to_ne_bytes())
20306 }
20307 pub fn ifi_change(&self) -> u32 {
20308 parse_u32(&self.buf[12usize..16usize]).unwrap()
20309 }
20310 pub fn set_ifi_change(&mut self, value: u32) {
20311 self.buf[12usize..16usize].copy_from_slice(&value.to_ne_bytes())
20312 }
20313}
20314impl std::fmt::Debug for PushIfinfomsg {
20315 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20316 fmt.debug_struct("Ifinfomsg")
20317 .field("ifi_family", &self.ifi_family())
20318 .field("ifi_type", &self.ifi_type())
20319 .field("ifi_index", &self.ifi_index())
20320 .field("ifi_flags", &self.ifi_flags())
20321 .field("ifi_change", &self.ifi_change())
20322 .finish()
20323 }
20324}
20325#[derive(Clone)]
20326pub struct PushIflaBridgeId {
20327 pub(crate) buf: [u8; 2usize],
20328}
20329#[doc = "Create zero-initialized struct"]
20330impl Default for PushIflaBridgeId {
20331 fn default() -> Self {
20332 Self { buf: [0u8; 2usize] }
20333 }
20334}
20335impl PushIflaBridgeId {
20336 #[doc = "Create zero-initialized struct"]
20337 pub fn new() -> Self {
20338 Default::default()
20339 }
20340 #[doc = "Copy from contents from other slice"]
20341 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
20342 if other.len() != Self::len() {
20343 return None;
20344 }
20345 let mut buf = [0u8; Self::len()];
20346 buf.clone_from_slice(other);
20347 Some(Self { buf })
20348 }
20349 pub fn as_slice(&self) -> &[u8] {
20350 &self.buf
20351 }
20352 pub fn as_mut_slice(&mut self) -> &mut [u8] {
20353 &mut self.buf
20354 }
20355 pub const fn len() -> usize {
20356 2usize
20357 }
20358 pub fn prio(&self) -> u16 {
20359 parse_u16(&self.buf[0usize..2usize]).unwrap()
20360 }
20361 pub fn set_prio(&mut self, value: u16) {
20362 self.buf[0usize..2usize].copy_from_slice(&value.to_ne_bytes())
20363 }
20364 pub fn addr(&self) -> [u8; 6usize] {
20365 self.buf[2usize..8usize].try_into().unwrap()
20366 }
20367 pub fn set_addr(&mut self, value: [u8; 6usize]) {
20368 self.buf[2usize..8usize].copy_from_slice(&value)
20369 }
20370}
20371impl std::fmt::Debug for PushIflaBridgeId {
20372 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20373 fmt.debug_struct("IflaBridgeId")
20374 .field("prio", &self.prio())
20375 .field("addr", &self.addr())
20376 .finish()
20377 }
20378}
20379#[derive(Clone)]
20380pub struct PushIflaCacheinfo {
20381 pub(crate) buf: [u8; 16usize],
20382}
20383#[doc = "Create zero-initialized struct"]
20384impl Default for PushIflaCacheinfo {
20385 fn default() -> Self {
20386 Self {
20387 buf: [0u8; 16usize],
20388 }
20389 }
20390}
20391impl PushIflaCacheinfo {
20392 #[doc = "Create zero-initialized struct"]
20393 pub fn new() -> Self {
20394 Default::default()
20395 }
20396 #[doc = "Copy from contents from other slice"]
20397 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
20398 if other.len() != Self::len() {
20399 return None;
20400 }
20401 let mut buf = [0u8; Self::len()];
20402 buf.clone_from_slice(other);
20403 Some(Self { buf })
20404 }
20405 pub fn as_slice(&self) -> &[u8] {
20406 &self.buf
20407 }
20408 pub fn as_mut_slice(&mut self) -> &mut [u8] {
20409 &mut self.buf
20410 }
20411 pub const fn len() -> usize {
20412 16usize
20413 }
20414 pub fn max_reasm_len(&self) -> u32 {
20415 parse_u32(&self.buf[0usize..4usize]).unwrap()
20416 }
20417 pub fn set_max_reasm_len(&mut self, value: u32) {
20418 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
20419 }
20420 pub fn tstamp(&self) -> u32 {
20421 parse_u32(&self.buf[4usize..8usize]).unwrap()
20422 }
20423 pub fn set_tstamp(&mut self, value: u32) {
20424 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
20425 }
20426 pub fn reachable_time(&self) -> i32 {
20427 parse_i32(&self.buf[8usize..12usize]).unwrap()
20428 }
20429 pub fn set_reachable_time(&mut self, value: i32) {
20430 self.buf[8usize..12usize].copy_from_slice(&value.to_ne_bytes())
20431 }
20432 pub fn retrans_time(&self) -> u32 {
20433 parse_u32(&self.buf[12usize..16usize]).unwrap()
20434 }
20435 pub fn set_retrans_time(&mut self, value: u32) {
20436 self.buf[12usize..16usize].copy_from_slice(&value.to_ne_bytes())
20437 }
20438}
20439impl std::fmt::Debug for PushIflaCacheinfo {
20440 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20441 fmt.debug_struct("IflaCacheinfo")
20442 .field("max_reasm_len", &self.max_reasm_len())
20443 .field("tstamp", &self.tstamp())
20444 .field("reachable_time", &self.reachable_time())
20445 .field("retrans_time", &self.retrans_time())
20446 .finish()
20447 }
20448}
20449#[derive(Clone)]
20450pub struct PushRtnlLinkStats {
20451 pub(crate) buf: [u8; 96usize],
20452}
20453#[doc = "Create zero-initialized struct"]
20454impl Default for PushRtnlLinkStats {
20455 fn default() -> Self {
20456 Self {
20457 buf: [0u8; 96usize],
20458 }
20459 }
20460}
20461impl PushRtnlLinkStats {
20462 #[doc = "Create zero-initialized struct"]
20463 pub fn new() -> Self {
20464 Default::default()
20465 }
20466 #[doc = "Copy from contents from other slice"]
20467 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
20468 if other.len() != Self::len() {
20469 return None;
20470 }
20471 let mut buf = [0u8; Self::len()];
20472 buf.clone_from_slice(other);
20473 Some(Self { buf })
20474 }
20475 pub fn as_slice(&self) -> &[u8] {
20476 &self.buf
20477 }
20478 pub fn as_mut_slice(&mut self) -> &mut [u8] {
20479 &mut self.buf
20480 }
20481 pub const fn len() -> usize {
20482 96usize
20483 }
20484 pub fn rx_packets(&self) -> u32 {
20485 parse_u32(&self.buf[0usize..4usize]).unwrap()
20486 }
20487 pub fn set_rx_packets(&mut self, value: u32) {
20488 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
20489 }
20490 pub fn tx_packets(&self) -> u32 {
20491 parse_u32(&self.buf[4usize..8usize]).unwrap()
20492 }
20493 pub fn set_tx_packets(&mut self, value: u32) {
20494 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
20495 }
20496 pub fn rx_bytes(&self) -> u32 {
20497 parse_u32(&self.buf[8usize..12usize]).unwrap()
20498 }
20499 pub fn set_rx_bytes(&mut self, value: u32) {
20500 self.buf[8usize..12usize].copy_from_slice(&value.to_ne_bytes())
20501 }
20502 pub fn tx_bytes(&self) -> u32 {
20503 parse_u32(&self.buf[12usize..16usize]).unwrap()
20504 }
20505 pub fn set_tx_bytes(&mut self, value: u32) {
20506 self.buf[12usize..16usize].copy_from_slice(&value.to_ne_bytes())
20507 }
20508 pub fn rx_errors(&self) -> u32 {
20509 parse_u32(&self.buf[16usize..20usize]).unwrap()
20510 }
20511 pub fn set_rx_errors(&mut self, value: u32) {
20512 self.buf[16usize..20usize].copy_from_slice(&value.to_ne_bytes())
20513 }
20514 pub fn tx_errors(&self) -> u32 {
20515 parse_u32(&self.buf[20usize..24usize]).unwrap()
20516 }
20517 pub fn set_tx_errors(&mut self, value: u32) {
20518 self.buf[20usize..24usize].copy_from_slice(&value.to_ne_bytes())
20519 }
20520 pub fn rx_dropped(&self) -> u32 {
20521 parse_u32(&self.buf[24usize..28usize]).unwrap()
20522 }
20523 pub fn set_rx_dropped(&mut self, value: u32) {
20524 self.buf[24usize..28usize].copy_from_slice(&value.to_ne_bytes())
20525 }
20526 pub fn tx_dropped(&self) -> u32 {
20527 parse_u32(&self.buf[28usize..32usize]).unwrap()
20528 }
20529 pub fn set_tx_dropped(&mut self, value: u32) {
20530 self.buf[28usize..32usize].copy_from_slice(&value.to_ne_bytes())
20531 }
20532 pub fn multicast(&self) -> u32 {
20533 parse_u32(&self.buf[32usize..36usize]).unwrap()
20534 }
20535 pub fn set_multicast(&mut self, value: u32) {
20536 self.buf[32usize..36usize].copy_from_slice(&value.to_ne_bytes())
20537 }
20538 pub fn collisions(&self) -> u32 {
20539 parse_u32(&self.buf[36usize..40usize]).unwrap()
20540 }
20541 pub fn set_collisions(&mut self, value: u32) {
20542 self.buf[36usize..40usize].copy_from_slice(&value.to_ne_bytes())
20543 }
20544 pub fn rx_length_errors(&self) -> u32 {
20545 parse_u32(&self.buf[40usize..44usize]).unwrap()
20546 }
20547 pub fn set_rx_length_errors(&mut self, value: u32) {
20548 self.buf[40usize..44usize].copy_from_slice(&value.to_ne_bytes())
20549 }
20550 pub fn rx_over_errors(&self) -> u32 {
20551 parse_u32(&self.buf[44usize..48usize]).unwrap()
20552 }
20553 pub fn set_rx_over_errors(&mut self, value: u32) {
20554 self.buf[44usize..48usize].copy_from_slice(&value.to_ne_bytes())
20555 }
20556 pub fn rx_crc_errors(&self) -> u32 {
20557 parse_u32(&self.buf[48usize..52usize]).unwrap()
20558 }
20559 pub fn set_rx_crc_errors(&mut self, value: u32) {
20560 self.buf[48usize..52usize].copy_from_slice(&value.to_ne_bytes())
20561 }
20562 pub fn rx_frame_errors(&self) -> u32 {
20563 parse_u32(&self.buf[52usize..56usize]).unwrap()
20564 }
20565 pub fn set_rx_frame_errors(&mut self, value: u32) {
20566 self.buf[52usize..56usize].copy_from_slice(&value.to_ne_bytes())
20567 }
20568 pub fn rx_fifo_errors(&self) -> u32 {
20569 parse_u32(&self.buf[56usize..60usize]).unwrap()
20570 }
20571 pub fn set_rx_fifo_errors(&mut self, value: u32) {
20572 self.buf[56usize..60usize].copy_from_slice(&value.to_ne_bytes())
20573 }
20574 pub fn rx_missed_errors(&self) -> u32 {
20575 parse_u32(&self.buf[60usize..64usize]).unwrap()
20576 }
20577 pub fn set_rx_missed_errors(&mut self, value: u32) {
20578 self.buf[60usize..64usize].copy_from_slice(&value.to_ne_bytes())
20579 }
20580 pub fn tx_aborted_errors(&self) -> u32 {
20581 parse_u32(&self.buf[64usize..68usize]).unwrap()
20582 }
20583 pub fn set_tx_aborted_errors(&mut self, value: u32) {
20584 self.buf[64usize..68usize].copy_from_slice(&value.to_ne_bytes())
20585 }
20586 pub fn tx_carrier_errors(&self) -> u32 {
20587 parse_u32(&self.buf[68usize..72usize]).unwrap()
20588 }
20589 pub fn set_tx_carrier_errors(&mut self, value: u32) {
20590 self.buf[68usize..72usize].copy_from_slice(&value.to_ne_bytes())
20591 }
20592 pub fn tx_fifo_errors(&self) -> u32 {
20593 parse_u32(&self.buf[72usize..76usize]).unwrap()
20594 }
20595 pub fn set_tx_fifo_errors(&mut self, value: u32) {
20596 self.buf[72usize..76usize].copy_from_slice(&value.to_ne_bytes())
20597 }
20598 pub fn tx_heartbeat_errors(&self) -> u32 {
20599 parse_u32(&self.buf[76usize..80usize]).unwrap()
20600 }
20601 pub fn set_tx_heartbeat_errors(&mut self, value: u32) {
20602 self.buf[76usize..80usize].copy_from_slice(&value.to_ne_bytes())
20603 }
20604 pub fn tx_window_errors(&self) -> u32 {
20605 parse_u32(&self.buf[80usize..84usize]).unwrap()
20606 }
20607 pub fn set_tx_window_errors(&mut self, value: u32) {
20608 self.buf[80usize..84usize].copy_from_slice(&value.to_ne_bytes())
20609 }
20610 pub fn rx_compressed(&self) -> u32 {
20611 parse_u32(&self.buf[84usize..88usize]).unwrap()
20612 }
20613 pub fn set_rx_compressed(&mut self, value: u32) {
20614 self.buf[84usize..88usize].copy_from_slice(&value.to_ne_bytes())
20615 }
20616 pub fn tx_compressed(&self) -> u32 {
20617 parse_u32(&self.buf[88usize..92usize]).unwrap()
20618 }
20619 pub fn set_tx_compressed(&mut self, value: u32) {
20620 self.buf[88usize..92usize].copy_from_slice(&value.to_ne_bytes())
20621 }
20622 pub fn rx_nohandler(&self) -> u32 {
20623 parse_u32(&self.buf[92usize..96usize]).unwrap()
20624 }
20625 pub fn set_rx_nohandler(&mut self, value: u32) {
20626 self.buf[92usize..96usize].copy_from_slice(&value.to_ne_bytes())
20627 }
20628}
20629impl std::fmt::Debug for PushRtnlLinkStats {
20630 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20631 fmt.debug_struct("RtnlLinkStats")
20632 .field("rx_packets", &self.rx_packets())
20633 .field("tx_packets", &self.tx_packets())
20634 .field("rx_bytes", &self.rx_bytes())
20635 .field("tx_bytes", &self.tx_bytes())
20636 .field("rx_errors", &self.rx_errors())
20637 .field("tx_errors", &self.tx_errors())
20638 .field("rx_dropped", &self.rx_dropped())
20639 .field("tx_dropped", &self.tx_dropped())
20640 .field("multicast", &self.multicast())
20641 .field("collisions", &self.collisions())
20642 .field("rx_length_errors", &self.rx_length_errors())
20643 .field("rx_over_errors", &self.rx_over_errors())
20644 .field("rx_crc_errors", &self.rx_crc_errors())
20645 .field("rx_frame_errors", &self.rx_frame_errors())
20646 .field("rx_fifo_errors", &self.rx_fifo_errors())
20647 .field("rx_missed_errors", &self.rx_missed_errors())
20648 .field("tx_aborted_errors", &self.tx_aborted_errors())
20649 .field("tx_carrier_errors", &self.tx_carrier_errors())
20650 .field("tx_fifo_errors", &self.tx_fifo_errors())
20651 .field("tx_heartbeat_errors", &self.tx_heartbeat_errors())
20652 .field("tx_window_errors", &self.tx_window_errors())
20653 .field("rx_compressed", &self.rx_compressed())
20654 .field("tx_compressed", &self.tx_compressed())
20655 .field("rx_nohandler", &self.rx_nohandler())
20656 .finish()
20657 }
20658}
20659#[derive(Clone)]
20660pub struct PushRtnlLinkStats64 {
20661 pub(crate) buf: [u8; 200usize],
20662}
20663#[doc = "Create zero-initialized struct"]
20664impl Default for PushRtnlLinkStats64 {
20665 fn default() -> Self {
20666 Self {
20667 buf: [0u8; 200usize],
20668 }
20669 }
20670}
20671impl PushRtnlLinkStats64 {
20672 #[doc = "Create zero-initialized struct"]
20673 pub fn new() -> Self {
20674 Default::default()
20675 }
20676 #[doc = "Copy from contents from other slice"]
20677 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
20678 if other.len() != Self::len() {
20679 return None;
20680 }
20681 let mut buf = [0u8; Self::len()];
20682 buf.clone_from_slice(other);
20683 Some(Self { buf })
20684 }
20685 pub fn as_slice(&self) -> &[u8] {
20686 &self.buf
20687 }
20688 pub fn as_mut_slice(&mut self) -> &mut [u8] {
20689 &mut self.buf
20690 }
20691 pub const fn len() -> usize {
20692 200usize
20693 }
20694 pub fn rx_packets(&self) -> u64 {
20695 parse_u64(&self.buf[0usize..8usize]).unwrap()
20696 }
20697 pub fn set_rx_packets(&mut self, value: u64) {
20698 self.buf[0usize..8usize].copy_from_slice(&value.to_ne_bytes())
20699 }
20700 pub fn tx_packets(&self) -> u64 {
20701 parse_u64(&self.buf[8usize..16usize]).unwrap()
20702 }
20703 pub fn set_tx_packets(&mut self, value: u64) {
20704 self.buf[8usize..16usize].copy_from_slice(&value.to_ne_bytes())
20705 }
20706 pub fn rx_bytes(&self) -> u64 {
20707 parse_u64(&self.buf[16usize..24usize]).unwrap()
20708 }
20709 pub fn set_rx_bytes(&mut self, value: u64) {
20710 self.buf[16usize..24usize].copy_from_slice(&value.to_ne_bytes())
20711 }
20712 pub fn tx_bytes(&self) -> u64 {
20713 parse_u64(&self.buf[24usize..32usize]).unwrap()
20714 }
20715 pub fn set_tx_bytes(&mut self, value: u64) {
20716 self.buf[24usize..32usize].copy_from_slice(&value.to_ne_bytes())
20717 }
20718 pub fn rx_errors(&self) -> u64 {
20719 parse_u64(&self.buf[32usize..40usize]).unwrap()
20720 }
20721 pub fn set_rx_errors(&mut self, value: u64) {
20722 self.buf[32usize..40usize].copy_from_slice(&value.to_ne_bytes())
20723 }
20724 pub fn tx_errors(&self) -> u64 {
20725 parse_u64(&self.buf[40usize..48usize]).unwrap()
20726 }
20727 pub fn set_tx_errors(&mut self, value: u64) {
20728 self.buf[40usize..48usize].copy_from_slice(&value.to_ne_bytes())
20729 }
20730 pub fn rx_dropped(&self) -> u64 {
20731 parse_u64(&self.buf[48usize..56usize]).unwrap()
20732 }
20733 pub fn set_rx_dropped(&mut self, value: u64) {
20734 self.buf[48usize..56usize].copy_from_slice(&value.to_ne_bytes())
20735 }
20736 pub fn tx_dropped(&self) -> u64 {
20737 parse_u64(&self.buf[56usize..64usize]).unwrap()
20738 }
20739 pub fn set_tx_dropped(&mut self, value: u64) {
20740 self.buf[56usize..64usize].copy_from_slice(&value.to_ne_bytes())
20741 }
20742 pub fn multicast(&self) -> u64 {
20743 parse_u64(&self.buf[64usize..72usize]).unwrap()
20744 }
20745 pub fn set_multicast(&mut self, value: u64) {
20746 self.buf[64usize..72usize].copy_from_slice(&value.to_ne_bytes())
20747 }
20748 pub fn collisions(&self) -> u64 {
20749 parse_u64(&self.buf[72usize..80usize]).unwrap()
20750 }
20751 pub fn set_collisions(&mut self, value: u64) {
20752 self.buf[72usize..80usize].copy_from_slice(&value.to_ne_bytes())
20753 }
20754 pub fn rx_length_errors(&self) -> u64 {
20755 parse_u64(&self.buf[80usize..88usize]).unwrap()
20756 }
20757 pub fn set_rx_length_errors(&mut self, value: u64) {
20758 self.buf[80usize..88usize].copy_from_slice(&value.to_ne_bytes())
20759 }
20760 pub fn rx_over_errors(&self) -> u64 {
20761 parse_u64(&self.buf[88usize..96usize]).unwrap()
20762 }
20763 pub fn set_rx_over_errors(&mut self, value: u64) {
20764 self.buf[88usize..96usize].copy_from_slice(&value.to_ne_bytes())
20765 }
20766 pub fn rx_crc_errors(&self) -> u64 {
20767 parse_u64(&self.buf[96usize..104usize]).unwrap()
20768 }
20769 pub fn set_rx_crc_errors(&mut self, value: u64) {
20770 self.buf[96usize..104usize].copy_from_slice(&value.to_ne_bytes())
20771 }
20772 pub fn rx_frame_errors(&self) -> u64 {
20773 parse_u64(&self.buf[104usize..112usize]).unwrap()
20774 }
20775 pub fn set_rx_frame_errors(&mut self, value: u64) {
20776 self.buf[104usize..112usize].copy_from_slice(&value.to_ne_bytes())
20777 }
20778 pub fn rx_fifo_errors(&self) -> u64 {
20779 parse_u64(&self.buf[112usize..120usize]).unwrap()
20780 }
20781 pub fn set_rx_fifo_errors(&mut self, value: u64) {
20782 self.buf[112usize..120usize].copy_from_slice(&value.to_ne_bytes())
20783 }
20784 pub fn rx_missed_errors(&self) -> u64 {
20785 parse_u64(&self.buf[120usize..128usize]).unwrap()
20786 }
20787 pub fn set_rx_missed_errors(&mut self, value: u64) {
20788 self.buf[120usize..128usize].copy_from_slice(&value.to_ne_bytes())
20789 }
20790 pub fn tx_aborted_errors(&self) -> u64 {
20791 parse_u64(&self.buf[128usize..136usize]).unwrap()
20792 }
20793 pub fn set_tx_aborted_errors(&mut self, value: u64) {
20794 self.buf[128usize..136usize].copy_from_slice(&value.to_ne_bytes())
20795 }
20796 pub fn tx_carrier_errors(&self) -> u64 {
20797 parse_u64(&self.buf[136usize..144usize]).unwrap()
20798 }
20799 pub fn set_tx_carrier_errors(&mut self, value: u64) {
20800 self.buf[136usize..144usize].copy_from_slice(&value.to_ne_bytes())
20801 }
20802 pub fn tx_fifo_errors(&self) -> u64 {
20803 parse_u64(&self.buf[144usize..152usize]).unwrap()
20804 }
20805 pub fn set_tx_fifo_errors(&mut self, value: u64) {
20806 self.buf[144usize..152usize].copy_from_slice(&value.to_ne_bytes())
20807 }
20808 pub fn tx_heartbeat_errors(&self) -> u64 {
20809 parse_u64(&self.buf[152usize..160usize]).unwrap()
20810 }
20811 pub fn set_tx_heartbeat_errors(&mut self, value: u64) {
20812 self.buf[152usize..160usize].copy_from_slice(&value.to_ne_bytes())
20813 }
20814 pub fn tx_window_errors(&self) -> u64 {
20815 parse_u64(&self.buf[160usize..168usize]).unwrap()
20816 }
20817 pub fn set_tx_window_errors(&mut self, value: u64) {
20818 self.buf[160usize..168usize].copy_from_slice(&value.to_ne_bytes())
20819 }
20820 pub fn rx_compressed(&self) -> u64 {
20821 parse_u64(&self.buf[168usize..176usize]).unwrap()
20822 }
20823 pub fn set_rx_compressed(&mut self, value: u64) {
20824 self.buf[168usize..176usize].copy_from_slice(&value.to_ne_bytes())
20825 }
20826 pub fn tx_compressed(&self) -> u64 {
20827 parse_u64(&self.buf[176usize..184usize]).unwrap()
20828 }
20829 pub fn set_tx_compressed(&mut self, value: u64) {
20830 self.buf[176usize..184usize].copy_from_slice(&value.to_ne_bytes())
20831 }
20832 pub fn rx_nohandler(&self) -> u64 {
20833 parse_u64(&self.buf[184usize..192usize]).unwrap()
20834 }
20835 pub fn set_rx_nohandler(&mut self, value: u64) {
20836 self.buf[184usize..192usize].copy_from_slice(&value.to_ne_bytes())
20837 }
20838 pub fn rx_otherhost_dropped(&self) -> u64 {
20839 parse_u64(&self.buf[192usize..200usize]).unwrap()
20840 }
20841 pub fn set_rx_otherhost_dropped(&mut self, value: u64) {
20842 self.buf[192usize..200usize].copy_from_slice(&value.to_ne_bytes())
20843 }
20844}
20845impl std::fmt::Debug for PushRtnlLinkStats64 {
20846 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20847 fmt.debug_struct("RtnlLinkStats64")
20848 .field("rx_packets", &self.rx_packets())
20849 .field("tx_packets", &self.tx_packets())
20850 .field("rx_bytes", &self.rx_bytes())
20851 .field("tx_bytes", &self.tx_bytes())
20852 .field("rx_errors", &self.rx_errors())
20853 .field("tx_errors", &self.tx_errors())
20854 .field("rx_dropped", &self.rx_dropped())
20855 .field("tx_dropped", &self.tx_dropped())
20856 .field("multicast", &self.multicast())
20857 .field("collisions", &self.collisions())
20858 .field("rx_length_errors", &self.rx_length_errors())
20859 .field("rx_over_errors", &self.rx_over_errors())
20860 .field("rx_crc_errors", &self.rx_crc_errors())
20861 .field("rx_frame_errors", &self.rx_frame_errors())
20862 .field("rx_fifo_errors", &self.rx_fifo_errors())
20863 .field("rx_missed_errors", &self.rx_missed_errors())
20864 .field("tx_aborted_errors", &self.tx_aborted_errors())
20865 .field("tx_carrier_errors", &self.tx_carrier_errors())
20866 .field("tx_fifo_errors", &self.tx_fifo_errors())
20867 .field("tx_heartbeat_errors", &self.tx_heartbeat_errors())
20868 .field("tx_window_errors", &self.tx_window_errors())
20869 .field("rx_compressed", &self.rx_compressed())
20870 .field("tx_compressed", &self.tx_compressed())
20871 .field("rx_nohandler", &self.rx_nohandler())
20872 .field("rx_otherhost_dropped", &self.rx_otherhost_dropped())
20873 .finish()
20874 }
20875}
20876#[derive(Clone)]
20877pub struct PushRtnlLinkIfmap {
20878 pub(crate) buf: [u8; 32usize],
20879}
20880#[doc = "Create zero-initialized struct"]
20881impl Default for PushRtnlLinkIfmap {
20882 fn default() -> Self {
20883 Self {
20884 buf: [0u8; 32usize],
20885 }
20886 }
20887}
20888impl PushRtnlLinkIfmap {
20889 #[doc = "Create zero-initialized struct"]
20890 pub fn new() -> Self {
20891 Default::default()
20892 }
20893 #[doc = "Copy from contents from other slice"]
20894 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
20895 if other.len() != Self::len() {
20896 return None;
20897 }
20898 let mut buf = [0u8; Self::len()];
20899 buf.clone_from_slice(other);
20900 Some(Self { buf })
20901 }
20902 pub fn as_slice(&self) -> &[u8] {
20903 &self.buf
20904 }
20905 pub fn as_mut_slice(&mut self) -> &mut [u8] {
20906 &mut self.buf
20907 }
20908 pub const fn len() -> usize {
20909 32usize
20910 }
20911 pub fn mem_start(&self) -> u64 {
20912 parse_u64(&self.buf[0usize..8usize]).unwrap()
20913 }
20914 pub fn set_mem_start(&mut self, value: u64) {
20915 self.buf[0usize..8usize].copy_from_slice(&value.to_ne_bytes())
20916 }
20917 pub fn mem_end(&self) -> u64 {
20918 parse_u64(&self.buf[8usize..16usize]).unwrap()
20919 }
20920 pub fn set_mem_end(&mut self, value: u64) {
20921 self.buf[8usize..16usize].copy_from_slice(&value.to_ne_bytes())
20922 }
20923 pub fn base_addr(&self) -> u64 {
20924 parse_u64(&self.buf[16usize..24usize]).unwrap()
20925 }
20926 pub fn set_base_addr(&mut self, value: u64) {
20927 self.buf[16usize..24usize].copy_from_slice(&value.to_ne_bytes())
20928 }
20929 pub fn irq(&self) -> u16 {
20930 parse_u16(&self.buf[24usize..26usize]).unwrap()
20931 }
20932 pub fn set_irq(&mut self, value: u16) {
20933 self.buf[24usize..26usize].copy_from_slice(&value.to_ne_bytes())
20934 }
20935 pub fn dma(&self) -> u8 {
20936 parse_u8(&self.buf[26usize..27usize]).unwrap()
20937 }
20938 pub fn set_dma(&mut self, value: u8) {
20939 self.buf[26usize..27usize].copy_from_slice(&value.to_ne_bytes())
20940 }
20941 pub fn port(&self) -> u8 {
20942 parse_u8(&self.buf[27usize..28usize]).unwrap()
20943 }
20944 pub fn set_port(&mut self, value: u8) {
20945 self.buf[27usize..28usize].copy_from_slice(&value.to_ne_bytes())
20946 }
20947}
20948impl std::fmt::Debug for PushRtnlLinkIfmap {
20949 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20950 fmt.debug_struct("RtnlLinkIfmap")
20951 .field("mem_start", &self.mem_start())
20952 .field("mem_end", &self.mem_end())
20953 .field("base_addr", &self.base_addr())
20954 .field("irq", &self.irq())
20955 .field("dma", &self.dma())
20956 .field("port", &self.port())
20957 .finish()
20958 }
20959}
20960#[derive(Clone)]
20961pub struct PushBrBooloptMulti {
20962 pub(crate) buf: [u8; 8usize],
20963}
20964#[doc = "Create zero-initialized struct"]
20965impl Default for PushBrBooloptMulti {
20966 fn default() -> Self {
20967 Self { buf: [0u8; 8usize] }
20968 }
20969}
20970impl PushBrBooloptMulti {
20971 #[doc = "Create zero-initialized struct"]
20972 pub fn new() -> Self {
20973 Default::default()
20974 }
20975 #[doc = "Copy from contents from other slice"]
20976 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
20977 if other.len() != Self::len() {
20978 return None;
20979 }
20980 let mut buf = [0u8; Self::len()];
20981 buf.clone_from_slice(other);
20982 Some(Self { buf })
20983 }
20984 pub fn as_slice(&self) -> &[u8] {
20985 &self.buf
20986 }
20987 pub fn as_mut_slice(&mut self) -> &mut [u8] {
20988 &mut self.buf
20989 }
20990 pub const fn len() -> usize {
20991 8usize
20992 }
20993 pub fn optval(&self) -> u32 {
20994 parse_u32(&self.buf[0usize..4usize]).unwrap()
20995 }
20996 pub fn set_optval(&mut self, value: u32) {
20997 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
20998 }
20999 pub fn optmask(&self) -> u32 {
21000 parse_u32(&self.buf[4usize..8usize]).unwrap()
21001 }
21002 pub fn set_optmask(&mut self, value: u32) {
21003 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21004 }
21005}
21006impl std::fmt::Debug for PushBrBooloptMulti {
21007 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21008 fmt.debug_struct("BrBooloptMulti")
21009 .field("optval", &self.optval())
21010 .field("optmask", &self.optmask())
21011 .finish()
21012 }
21013}
21014#[derive(Clone)]
21015pub struct PushIfStatsMsg {
21016 pub(crate) buf: [u8; 12usize],
21017}
21018#[doc = "Create zero-initialized struct"]
21019impl Default for PushIfStatsMsg {
21020 fn default() -> Self {
21021 Self {
21022 buf: [0u8; 12usize],
21023 }
21024 }
21025}
21026impl PushIfStatsMsg {
21027 #[doc = "Create zero-initialized struct"]
21028 pub fn new() -> Self {
21029 Default::default()
21030 }
21031 #[doc = "Copy from contents from other slice"]
21032 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21033 if other.len() != Self::len() {
21034 return None;
21035 }
21036 let mut buf = [0u8; Self::len()];
21037 buf.clone_from_slice(other);
21038 Some(Self { buf })
21039 }
21040 pub fn as_slice(&self) -> &[u8] {
21041 &self.buf
21042 }
21043 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21044 &mut self.buf
21045 }
21046 pub const fn len() -> usize {
21047 12usize
21048 }
21049 pub fn family(&self) -> u8 {
21050 parse_u8(&self.buf[0usize..1usize]).unwrap()
21051 }
21052 pub fn set_family(&mut self, value: u8) {
21053 self.buf[0usize..1usize].copy_from_slice(&value.to_ne_bytes())
21054 }
21055 pub fn ifindex(&self) -> u32 {
21056 parse_u32(&self.buf[4usize..8usize]).unwrap()
21057 }
21058 pub fn set_ifindex(&mut self, value: u32) {
21059 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21060 }
21061 pub fn filter_mask(&self) -> u32 {
21062 parse_u32(&self.buf[8usize..12usize]).unwrap()
21063 }
21064 pub fn set_filter_mask(&mut self, value: u32) {
21065 self.buf[8usize..12usize].copy_from_slice(&value.to_ne_bytes())
21066 }
21067}
21068impl std::fmt::Debug for PushIfStatsMsg {
21069 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21070 fmt.debug_struct("IfStatsMsg")
21071 .field("family", &self.family())
21072 .field("ifindex", &self.ifindex())
21073 .field("filter_mask", &self.filter_mask())
21074 .finish()
21075 }
21076}
21077#[derive(Clone)]
21078pub struct PushIflaVlanFlags {
21079 pub(crate) buf: [u8; 8usize],
21080}
21081#[doc = "Create zero-initialized struct"]
21082impl Default for PushIflaVlanFlags {
21083 fn default() -> Self {
21084 Self { buf: [0u8; 8usize] }
21085 }
21086}
21087impl PushIflaVlanFlags {
21088 #[doc = "Create zero-initialized struct"]
21089 pub fn new() -> Self {
21090 Default::default()
21091 }
21092 #[doc = "Copy from contents from other slice"]
21093 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21094 if other.len() != Self::len() {
21095 return None;
21096 }
21097 let mut buf = [0u8; Self::len()];
21098 buf.clone_from_slice(other);
21099 Some(Self { buf })
21100 }
21101 pub fn as_slice(&self) -> &[u8] {
21102 &self.buf
21103 }
21104 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21105 &mut self.buf
21106 }
21107 pub const fn len() -> usize {
21108 8usize
21109 }
21110 #[doc = "Associated type: \"VlanFlags\" (1 bit per enumeration)"]
21111 pub fn flags(&self) -> u32 {
21112 parse_u32(&self.buf[0usize..4usize]).unwrap()
21113 }
21114 #[doc = "Associated type: \"VlanFlags\" (1 bit per enumeration)"]
21115 pub fn set_flags(&mut self, value: u32) {
21116 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21117 }
21118 pub fn mask(&self) -> u32 {
21119 parse_u32(&self.buf[4usize..8usize]).unwrap()
21120 }
21121 pub fn set_mask(&mut self, value: u32) {
21122 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21123 }
21124}
21125impl std::fmt::Debug for PushIflaVlanFlags {
21126 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21127 fmt.debug_struct("IflaVlanFlags")
21128 .field("flags", &self.flags())
21129 .field("mask", &self.mask())
21130 .finish()
21131 }
21132}
21133#[derive(Clone)]
21134pub struct PushIflaVlanQosMapping {
21135 pub(crate) buf: [u8; 8usize],
21136}
21137#[doc = "Create zero-initialized struct"]
21138impl Default for PushIflaVlanQosMapping {
21139 fn default() -> Self {
21140 Self { buf: [0u8; 8usize] }
21141 }
21142}
21143impl PushIflaVlanQosMapping {
21144 #[doc = "Create zero-initialized struct"]
21145 pub fn new() -> Self {
21146 Default::default()
21147 }
21148 #[doc = "Copy from contents from other slice"]
21149 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21150 if other.len() != Self::len() {
21151 return None;
21152 }
21153 let mut buf = [0u8; Self::len()];
21154 buf.clone_from_slice(other);
21155 Some(Self { buf })
21156 }
21157 pub fn as_slice(&self) -> &[u8] {
21158 &self.buf
21159 }
21160 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21161 &mut self.buf
21162 }
21163 pub const fn len() -> usize {
21164 8usize
21165 }
21166 pub fn from(&self) -> u32 {
21167 parse_u32(&self.buf[0usize..4usize]).unwrap()
21168 }
21169 pub fn set_from(&mut self, value: u32) {
21170 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21171 }
21172 pub fn to(&self) -> u32 {
21173 parse_u32(&self.buf[4usize..8usize]).unwrap()
21174 }
21175 pub fn set_to(&mut self, value: u32) {
21176 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21177 }
21178}
21179impl std::fmt::Debug for PushIflaVlanQosMapping {
21180 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21181 fmt.debug_struct("IflaVlanQosMapping")
21182 .field("from", &self.from())
21183 .field("to", &self.to())
21184 .finish()
21185 }
21186}
21187#[derive(Clone)]
21188pub struct PushIflaGenevePortRange {
21189 pub(crate) buf: [u8; 4usize],
21190}
21191#[doc = "Create zero-initialized struct"]
21192impl Default for PushIflaGenevePortRange {
21193 fn default() -> Self {
21194 Self { buf: [0u8; 4usize] }
21195 }
21196}
21197impl PushIflaGenevePortRange {
21198 #[doc = "Create zero-initialized struct"]
21199 pub fn new() -> Self {
21200 Default::default()
21201 }
21202 #[doc = "Copy from contents from other slice"]
21203 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21204 if other.len() != Self::len() {
21205 return None;
21206 }
21207 let mut buf = [0u8; Self::len()];
21208 buf.clone_from_slice(other);
21209 Some(Self { buf })
21210 }
21211 pub fn as_slice(&self) -> &[u8] {
21212 &self.buf
21213 }
21214 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21215 &mut self.buf
21216 }
21217 pub const fn len() -> usize {
21218 4usize
21219 }
21220 pub fn low(&self) -> u16 {
21221 parse_be_u16(&self.buf[0usize..2usize]).unwrap()
21222 }
21223 pub fn set_low(&mut self, value: u16) {
21224 self.buf[0usize..2usize].copy_from_slice(&value.to_be_bytes())
21225 }
21226 pub fn high(&self) -> u16 {
21227 parse_be_u16(&self.buf[2usize..4usize]).unwrap()
21228 }
21229 pub fn set_high(&mut self, value: u16) {
21230 self.buf[2usize..4usize].copy_from_slice(&value.to_be_bytes())
21231 }
21232}
21233impl std::fmt::Debug for PushIflaGenevePortRange {
21234 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21235 fmt.debug_struct("IflaGenevePortRange")
21236 .field("low", &self.low())
21237 .field("high", &self.high())
21238 .finish()
21239 }
21240}
21241#[derive(Clone)]
21242pub struct PushIflaVfMac {
21243 pub(crate) buf: [u8; 4usize],
21244}
21245#[doc = "Create zero-initialized struct"]
21246impl Default for PushIflaVfMac {
21247 fn default() -> Self {
21248 Self { buf: [0u8; 4usize] }
21249 }
21250}
21251impl PushIflaVfMac {
21252 #[doc = "Create zero-initialized struct"]
21253 pub fn new() -> Self {
21254 Default::default()
21255 }
21256 #[doc = "Copy from contents from other slice"]
21257 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21258 if other.len() != Self::len() {
21259 return None;
21260 }
21261 let mut buf = [0u8; Self::len()];
21262 buf.clone_from_slice(other);
21263 Some(Self { buf })
21264 }
21265 pub fn as_slice(&self) -> &[u8] {
21266 &self.buf
21267 }
21268 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21269 &mut self.buf
21270 }
21271 pub const fn len() -> usize {
21272 4usize
21273 }
21274 pub fn vf(&self) -> u32 {
21275 parse_u32(&self.buf[0usize..4usize]).unwrap()
21276 }
21277 pub fn set_vf(&mut self, value: u32) {
21278 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21279 }
21280 pub fn mac(&self) -> [u8; 32usize] {
21281 self.buf[4usize..36usize].try_into().unwrap()
21282 }
21283 pub fn set_mac(&mut self, value: [u8; 32usize]) {
21284 self.buf[4usize..36usize].copy_from_slice(&value)
21285 }
21286}
21287impl std::fmt::Debug for PushIflaVfMac {
21288 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21289 fmt.debug_struct("IflaVfMac")
21290 .field("vf", &self.vf())
21291 .field("mac", &self.mac())
21292 .finish()
21293 }
21294}
21295#[derive(Clone)]
21296pub struct PushIflaVfVlan {
21297 pub(crate) buf: [u8; 12usize],
21298}
21299#[doc = "Create zero-initialized struct"]
21300impl Default for PushIflaVfVlan {
21301 fn default() -> Self {
21302 Self {
21303 buf: [0u8; 12usize],
21304 }
21305 }
21306}
21307impl PushIflaVfVlan {
21308 #[doc = "Create zero-initialized struct"]
21309 pub fn new() -> Self {
21310 Default::default()
21311 }
21312 #[doc = "Copy from contents from other slice"]
21313 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21314 if other.len() != Self::len() {
21315 return None;
21316 }
21317 let mut buf = [0u8; Self::len()];
21318 buf.clone_from_slice(other);
21319 Some(Self { buf })
21320 }
21321 pub fn as_slice(&self) -> &[u8] {
21322 &self.buf
21323 }
21324 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21325 &mut self.buf
21326 }
21327 pub const fn len() -> usize {
21328 12usize
21329 }
21330 pub fn vf(&self) -> u32 {
21331 parse_u32(&self.buf[0usize..4usize]).unwrap()
21332 }
21333 pub fn set_vf(&mut self, value: u32) {
21334 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21335 }
21336 pub fn vlan(&self) -> u32 {
21337 parse_u32(&self.buf[4usize..8usize]).unwrap()
21338 }
21339 pub fn set_vlan(&mut self, value: u32) {
21340 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21341 }
21342 pub fn qos(&self) -> u32 {
21343 parse_u32(&self.buf[8usize..12usize]).unwrap()
21344 }
21345 pub fn set_qos(&mut self, value: u32) {
21346 self.buf[8usize..12usize].copy_from_slice(&value.to_ne_bytes())
21347 }
21348}
21349impl std::fmt::Debug for PushIflaVfVlan {
21350 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21351 fmt.debug_struct("IflaVfVlan")
21352 .field("vf", &self.vf())
21353 .field("vlan", &self.vlan())
21354 .field("qos", &self.qos())
21355 .finish()
21356 }
21357}
21358#[derive(Clone)]
21359pub struct PushIflaVfTxRate {
21360 pub(crate) buf: [u8; 8usize],
21361}
21362#[doc = "Create zero-initialized struct"]
21363impl Default for PushIflaVfTxRate {
21364 fn default() -> Self {
21365 Self { buf: [0u8; 8usize] }
21366 }
21367}
21368impl PushIflaVfTxRate {
21369 #[doc = "Create zero-initialized struct"]
21370 pub fn new() -> Self {
21371 Default::default()
21372 }
21373 #[doc = "Copy from contents from other slice"]
21374 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21375 if other.len() != Self::len() {
21376 return None;
21377 }
21378 let mut buf = [0u8; Self::len()];
21379 buf.clone_from_slice(other);
21380 Some(Self { buf })
21381 }
21382 pub fn as_slice(&self) -> &[u8] {
21383 &self.buf
21384 }
21385 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21386 &mut self.buf
21387 }
21388 pub const fn len() -> usize {
21389 8usize
21390 }
21391 pub fn vf(&self) -> u32 {
21392 parse_u32(&self.buf[0usize..4usize]).unwrap()
21393 }
21394 pub fn set_vf(&mut self, value: u32) {
21395 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21396 }
21397 pub fn rate(&self) -> u32 {
21398 parse_u32(&self.buf[4usize..8usize]).unwrap()
21399 }
21400 pub fn set_rate(&mut self, value: u32) {
21401 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21402 }
21403}
21404impl std::fmt::Debug for PushIflaVfTxRate {
21405 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21406 fmt.debug_struct("IflaVfTxRate")
21407 .field("vf", &self.vf())
21408 .field("rate", &self.rate())
21409 .finish()
21410 }
21411}
21412#[derive(Clone)]
21413pub struct PushIflaVfSpoofchk {
21414 pub(crate) buf: [u8; 8usize],
21415}
21416#[doc = "Create zero-initialized struct"]
21417impl Default for PushIflaVfSpoofchk {
21418 fn default() -> Self {
21419 Self { buf: [0u8; 8usize] }
21420 }
21421}
21422impl PushIflaVfSpoofchk {
21423 #[doc = "Create zero-initialized struct"]
21424 pub fn new() -> Self {
21425 Default::default()
21426 }
21427 #[doc = "Copy from contents from other slice"]
21428 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21429 if other.len() != Self::len() {
21430 return None;
21431 }
21432 let mut buf = [0u8; Self::len()];
21433 buf.clone_from_slice(other);
21434 Some(Self { buf })
21435 }
21436 pub fn as_slice(&self) -> &[u8] {
21437 &self.buf
21438 }
21439 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21440 &mut self.buf
21441 }
21442 pub const fn len() -> usize {
21443 8usize
21444 }
21445 pub fn vf(&self) -> u32 {
21446 parse_u32(&self.buf[0usize..4usize]).unwrap()
21447 }
21448 pub fn set_vf(&mut self, value: u32) {
21449 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21450 }
21451 pub fn setting(&self) -> u32 {
21452 parse_u32(&self.buf[4usize..8usize]).unwrap()
21453 }
21454 pub fn set_setting(&mut self, value: u32) {
21455 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21456 }
21457}
21458impl std::fmt::Debug for PushIflaVfSpoofchk {
21459 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21460 fmt.debug_struct("IflaVfSpoofchk")
21461 .field("vf", &self.vf())
21462 .field("setting", &self.setting())
21463 .finish()
21464 }
21465}
21466#[derive(Clone)]
21467pub struct PushIflaVfLinkState {
21468 pub(crate) buf: [u8; 8usize],
21469}
21470#[doc = "Create zero-initialized struct"]
21471impl Default for PushIflaVfLinkState {
21472 fn default() -> Self {
21473 Self { buf: [0u8; 8usize] }
21474 }
21475}
21476impl PushIflaVfLinkState {
21477 #[doc = "Create zero-initialized struct"]
21478 pub fn new() -> Self {
21479 Default::default()
21480 }
21481 #[doc = "Copy from contents from other slice"]
21482 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21483 if other.len() != Self::len() {
21484 return None;
21485 }
21486 let mut buf = [0u8; Self::len()];
21487 buf.clone_from_slice(other);
21488 Some(Self { buf })
21489 }
21490 pub fn as_slice(&self) -> &[u8] {
21491 &self.buf
21492 }
21493 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21494 &mut self.buf
21495 }
21496 pub const fn len() -> usize {
21497 8usize
21498 }
21499 pub fn vf(&self) -> u32 {
21500 parse_u32(&self.buf[0usize..4usize]).unwrap()
21501 }
21502 pub fn set_vf(&mut self, value: u32) {
21503 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21504 }
21505 #[doc = "Associated type: \"IflaVfLinkStateEnum\" (enum)"]
21506 pub fn link_state(&self) -> u32 {
21507 parse_u32(&self.buf[4usize..8usize]).unwrap()
21508 }
21509 #[doc = "Associated type: \"IflaVfLinkStateEnum\" (enum)"]
21510 pub fn set_link_state(&mut self, value: u32) {
21511 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21512 }
21513}
21514impl std::fmt::Debug for PushIflaVfLinkState {
21515 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21516 fmt.debug_struct("IflaVfLinkState")
21517 .field("vf", &self.vf())
21518 .field("link_state", &self.link_state())
21519 .finish()
21520 }
21521}
21522#[derive(Clone)]
21523pub struct PushIflaVfRate {
21524 pub(crate) buf: [u8; 12usize],
21525}
21526#[doc = "Create zero-initialized struct"]
21527impl Default for PushIflaVfRate {
21528 fn default() -> Self {
21529 Self {
21530 buf: [0u8; 12usize],
21531 }
21532 }
21533}
21534impl PushIflaVfRate {
21535 #[doc = "Create zero-initialized struct"]
21536 pub fn new() -> Self {
21537 Default::default()
21538 }
21539 #[doc = "Copy from contents from other slice"]
21540 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21541 if other.len() != Self::len() {
21542 return None;
21543 }
21544 let mut buf = [0u8; Self::len()];
21545 buf.clone_from_slice(other);
21546 Some(Self { buf })
21547 }
21548 pub fn as_slice(&self) -> &[u8] {
21549 &self.buf
21550 }
21551 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21552 &mut self.buf
21553 }
21554 pub const fn len() -> usize {
21555 12usize
21556 }
21557 pub fn vf(&self) -> u32 {
21558 parse_u32(&self.buf[0usize..4usize]).unwrap()
21559 }
21560 pub fn set_vf(&mut self, value: u32) {
21561 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21562 }
21563 pub fn min_tx_rate(&self) -> u32 {
21564 parse_u32(&self.buf[4usize..8usize]).unwrap()
21565 }
21566 pub fn set_min_tx_rate(&mut self, value: u32) {
21567 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21568 }
21569 pub fn max_tx_rate(&self) -> u32 {
21570 parse_u32(&self.buf[8usize..12usize]).unwrap()
21571 }
21572 pub fn set_max_tx_rate(&mut self, value: u32) {
21573 self.buf[8usize..12usize].copy_from_slice(&value.to_ne_bytes())
21574 }
21575}
21576impl std::fmt::Debug for PushIflaVfRate {
21577 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21578 fmt.debug_struct("IflaVfRate")
21579 .field("vf", &self.vf())
21580 .field("min_tx_rate", &self.min_tx_rate())
21581 .field("max_tx_rate", &self.max_tx_rate())
21582 .finish()
21583 }
21584}
21585#[derive(Clone)]
21586pub struct PushIflaVfRssQueryEn {
21587 pub(crate) buf: [u8; 8usize],
21588}
21589#[doc = "Create zero-initialized struct"]
21590impl Default for PushIflaVfRssQueryEn {
21591 fn default() -> Self {
21592 Self { buf: [0u8; 8usize] }
21593 }
21594}
21595impl PushIflaVfRssQueryEn {
21596 #[doc = "Create zero-initialized struct"]
21597 pub fn new() -> Self {
21598 Default::default()
21599 }
21600 #[doc = "Copy from contents from other slice"]
21601 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21602 if other.len() != Self::len() {
21603 return None;
21604 }
21605 let mut buf = [0u8; Self::len()];
21606 buf.clone_from_slice(other);
21607 Some(Self { buf })
21608 }
21609 pub fn as_slice(&self) -> &[u8] {
21610 &self.buf
21611 }
21612 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21613 &mut self.buf
21614 }
21615 pub const fn len() -> usize {
21616 8usize
21617 }
21618 pub fn vf(&self) -> u32 {
21619 parse_u32(&self.buf[0usize..4usize]).unwrap()
21620 }
21621 pub fn set_vf(&mut self, value: u32) {
21622 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21623 }
21624 pub fn setting(&self) -> u32 {
21625 parse_u32(&self.buf[4usize..8usize]).unwrap()
21626 }
21627 pub fn set_setting(&mut self, value: u32) {
21628 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21629 }
21630}
21631impl std::fmt::Debug for PushIflaVfRssQueryEn {
21632 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21633 fmt.debug_struct("IflaVfRssQueryEn")
21634 .field("vf", &self.vf())
21635 .field("setting", &self.setting())
21636 .finish()
21637 }
21638}
21639#[derive(Clone)]
21640pub struct PushIflaVfTrust {
21641 pub(crate) buf: [u8; 8usize],
21642}
21643#[doc = "Create zero-initialized struct"]
21644impl Default for PushIflaVfTrust {
21645 fn default() -> Self {
21646 Self { buf: [0u8; 8usize] }
21647 }
21648}
21649impl PushIflaVfTrust {
21650 #[doc = "Create zero-initialized struct"]
21651 pub fn new() -> Self {
21652 Default::default()
21653 }
21654 #[doc = "Copy from contents from other slice"]
21655 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21656 if other.len() != Self::len() {
21657 return None;
21658 }
21659 let mut buf = [0u8; Self::len()];
21660 buf.clone_from_slice(other);
21661 Some(Self { buf })
21662 }
21663 pub fn as_slice(&self) -> &[u8] {
21664 &self.buf
21665 }
21666 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21667 &mut self.buf
21668 }
21669 pub const fn len() -> usize {
21670 8usize
21671 }
21672 pub fn vf(&self) -> u32 {
21673 parse_u32(&self.buf[0usize..4usize]).unwrap()
21674 }
21675 pub fn set_vf(&mut self, value: u32) {
21676 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21677 }
21678 pub fn setting(&self) -> u32 {
21679 parse_u32(&self.buf[4usize..8usize]).unwrap()
21680 }
21681 pub fn set_setting(&mut self, value: u32) {
21682 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21683 }
21684}
21685impl std::fmt::Debug for PushIflaVfTrust {
21686 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21687 fmt.debug_struct("IflaVfTrust")
21688 .field("vf", &self.vf())
21689 .field("setting", &self.setting())
21690 .finish()
21691 }
21692}
21693#[derive(Clone)]
21694pub struct PushIflaVfGuid {
21695 pub(crate) buf: [u8; 16usize],
21696}
21697#[doc = "Create zero-initialized struct"]
21698impl Default for PushIflaVfGuid {
21699 fn default() -> Self {
21700 Self {
21701 buf: [0u8; 16usize],
21702 }
21703 }
21704}
21705impl PushIflaVfGuid {
21706 #[doc = "Create zero-initialized struct"]
21707 pub fn new() -> Self {
21708 Default::default()
21709 }
21710 #[doc = "Copy from contents from other slice"]
21711 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21712 if other.len() != Self::len() {
21713 return None;
21714 }
21715 let mut buf = [0u8; Self::len()];
21716 buf.clone_from_slice(other);
21717 Some(Self { buf })
21718 }
21719 pub fn as_slice(&self) -> &[u8] {
21720 &self.buf
21721 }
21722 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21723 &mut self.buf
21724 }
21725 pub const fn len() -> usize {
21726 16usize
21727 }
21728 pub fn vf(&self) -> u32 {
21729 parse_u32(&self.buf[0usize..4usize]).unwrap()
21730 }
21731 pub fn set_vf(&mut self, value: u32) {
21732 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21733 }
21734 pub fn guid(&self) -> u64 {
21735 parse_u64(&self.buf[8usize..16usize]).unwrap()
21736 }
21737 pub fn set_guid(&mut self, value: u64) {
21738 self.buf[8usize..16usize].copy_from_slice(&value.to_ne_bytes())
21739 }
21740}
21741impl std::fmt::Debug for PushIflaVfGuid {
21742 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21743 fmt.debug_struct("IflaVfGuid")
21744 .field("vf", &self.vf())
21745 .field("guid", &self.guid())
21746 .finish()
21747 }
21748}
21749#[derive(Clone)]
21750pub struct PushIflaVfVlanInfo {
21751 pub(crate) buf: [u8; 16usize],
21752}
21753#[doc = "Create zero-initialized struct"]
21754impl Default for PushIflaVfVlanInfo {
21755 fn default() -> Self {
21756 Self {
21757 buf: [0u8; 16usize],
21758 }
21759 }
21760}
21761impl PushIflaVfVlanInfo {
21762 #[doc = "Create zero-initialized struct"]
21763 pub fn new() -> Self {
21764 Default::default()
21765 }
21766 #[doc = "Copy from contents from other slice"]
21767 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
21768 if other.len() != Self::len() {
21769 return None;
21770 }
21771 let mut buf = [0u8; Self::len()];
21772 buf.clone_from_slice(other);
21773 Some(Self { buf })
21774 }
21775 pub fn as_slice(&self) -> &[u8] {
21776 &self.buf
21777 }
21778 pub fn as_mut_slice(&mut self) -> &mut [u8] {
21779 &mut self.buf
21780 }
21781 pub const fn len() -> usize {
21782 16usize
21783 }
21784 pub fn vf(&self) -> u32 {
21785 parse_u32(&self.buf[0usize..4usize]).unwrap()
21786 }
21787 pub fn set_vf(&mut self, value: u32) {
21788 self.buf[0usize..4usize].copy_from_slice(&value.to_ne_bytes())
21789 }
21790 pub fn vlan(&self) -> u32 {
21791 parse_u32(&self.buf[4usize..8usize]).unwrap()
21792 }
21793 pub fn set_vlan(&mut self, value: u32) {
21794 self.buf[4usize..8usize].copy_from_slice(&value.to_ne_bytes())
21795 }
21796 pub fn qos(&self) -> u32 {
21797 parse_u32(&self.buf[8usize..12usize]).unwrap()
21798 }
21799 pub fn set_qos(&mut self, value: u32) {
21800 self.buf[8usize..12usize].copy_from_slice(&value.to_ne_bytes())
21801 }
21802 pub fn vlan_proto(&self) -> u32 {
21803 parse_u32(&self.buf[12usize..16usize]).unwrap()
21804 }
21805 pub fn set_vlan_proto(&mut self, value: u32) {
21806 self.buf[12usize..16usize].copy_from_slice(&value.to_ne_bytes())
21807 }
21808}
21809impl std::fmt::Debug for PushIflaVfVlanInfo {
21810 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21811 fmt.debug_struct("IflaVfVlanInfo")
21812 .field("vf", &self.vf())
21813 .field("vlan", &self.vlan())
21814 .field("qos", &self.qos())
21815 .field("vlan_proto", &self.vlan_proto())
21816 .finish()
21817 }
21818}
21819#[doc = "Create a new link."]
21820pub struct PushOpNewlinkDoRequest<Prev: Rec> {
21821 pub(crate) prev: Option<Prev>,
21822 pub(crate) header_offset: Option<usize>,
21823}
21824impl<Prev: Rec> Rec for PushOpNewlinkDoRequest<Prev> {
21825 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
21826 self.prev.as_mut().unwrap().as_rec_mut()
21827 }
21828}
21829impl<Prev: Rec> PushOpNewlinkDoRequest<Prev> {
21830 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
21831 Self::write_header(&mut prev, header);
21832 Self::new_without_header(prev)
21833 }
21834 fn new_without_header(prev: Prev) -> Self {
21835 Self {
21836 prev: Some(prev),
21837 header_offset: None,
21838 }
21839 }
21840 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
21841 prev.as_rec_mut().extend(header.as_slice());
21842 }
21843 pub fn end_nested(mut self) -> Prev {
21844 let mut prev = self.prev.take().unwrap();
21845 if let Some(header_offset) = &self.header_offset {
21846 finalize_nested_header(prev.as_rec_mut(), *header_offset);
21847 }
21848 prev
21849 }
21850 pub fn push_address(mut self, value: &[u8]) -> Self {
21851 push_header(self.as_rec_mut(), 1u16, value.len() as u16);
21852 self.as_rec_mut().extend(value);
21853 self
21854 }
21855 pub fn push_broadcast(mut self, value: &[u8]) -> Self {
21856 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
21857 self.as_rec_mut().extend(value);
21858 self
21859 }
21860 pub fn push_ifname(mut self, value: &CStr) -> Self {
21861 push_header(
21862 self.as_rec_mut(),
21863 3u16,
21864 value.to_bytes_with_nul().len() as u16,
21865 );
21866 self.as_rec_mut().extend(value.to_bytes_with_nul());
21867 self
21868 }
21869 pub fn push_ifname_bytes(mut self, value: &[u8]) -> Self {
21870 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
21871 self.as_rec_mut().extend(value);
21872 self.as_rec_mut().push(0);
21873 self
21874 }
21875 pub fn push_mtu(mut self, value: u32) -> Self {
21876 push_header(self.as_rec_mut(), 4u16, 4 as u16);
21877 self.as_rec_mut().extend(value.to_ne_bytes());
21878 self
21879 }
21880 pub fn push_txqlen(mut self, value: u32) -> Self {
21881 push_header(self.as_rec_mut(), 13u16, 4 as u16);
21882 self.as_rec_mut().extend(value.to_ne_bytes());
21883 self
21884 }
21885 pub fn push_operstate(mut self, value: u8) -> Self {
21886 push_header(self.as_rec_mut(), 16u16, 1 as u16);
21887 self.as_rec_mut().extend(value.to_ne_bytes());
21888 self
21889 }
21890 pub fn push_linkmode(mut self, value: u8) -> Self {
21891 push_header(self.as_rec_mut(), 17u16, 1 as u16);
21892 self.as_rec_mut().extend(value.to_ne_bytes());
21893 self
21894 }
21895 pub fn nested_linkinfo(mut self) -> PushLinkinfoAttrs<Self> {
21896 let header_offset = push_nested_header(self.as_rec_mut(), 18u16);
21897 PushLinkinfoAttrs {
21898 prev: Some(self),
21899 header_offset: Some(header_offset),
21900 }
21901 }
21902 pub fn push_net_ns_pid(mut self, value: u32) -> Self {
21903 push_header(self.as_rec_mut(), 19u16, 4 as u16);
21904 self.as_rec_mut().extend(value.to_ne_bytes());
21905 self
21906 }
21907 pub fn nested_af_spec(mut self) -> PushAfSpecAttrs<Self> {
21908 let header_offset = push_nested_header(self.as_rec_mut(), 26u16);
21909 PushAfSpecAttrs {
21910 prev: Some(self),
21911 header_offset: Some(header_offset),
21912 }
21913 }
21914 pub fn push_group(mut self, value: u32) -> Self {
21915 push_header(self.as_rec_mut(), 27u16, 4 as u16);
21916 self.as_rec_mut().extend(value.to_ne_bytes());
21917 self
21918 }
21919 pub fn push_net_ns_fd(mut self, value: u32) -> Self {
21920 push_header(self.as_rec_mut(), 28u16, 4 as u16);
21921 self.as_rec_mut().extend(value.to_ne_bytes());
21922 self
21923 }
21924 pub fn push_num_tx_queues(mut self, value: u32) -> Self {
21925 push_header(self.as_rec_mut(), 31u16, 4 as u16);
21926 self.as_rec_mut().extend(value.to_ne_bytes());
21927 self
21928 }
21929 pub fn push_num_rx_queues(mut self, value: u32) -> Self {
21930 push_header(self.as_rec_mut(), 32u16, 4 as u16);
21931 self.as_rec_mut().extend(value.to_ne_bytes());
21932 self
21933 }
21934 pub fn push_link_netnsid(mut self, value: i32) -> Self {
21935 push_header(self.as_rec_mut(), 37u16, 4 as u16);
21936 self.as_rec_mut().extend(value.to_ne_bytes());
21937 self
21938 }
21939 pub fn push_gso_max_segs(mut self, value: u32) -> Self {
21940 push_header(self.as_rec_mut(), 40u16, 4 as u16);
21941 self.as_rec_mut().extend(value.to_ne_bytes());
21942 self
21943 }
21944 pub fn push_gso_max_size(mut self, value: u32) -> Self {
21945 push_header(self.as_rec_mut(), 41u16, 4 as u16);
21946 self.as_rec_mut().extend(value.to_ne_bytes());
21947 self
21948 }
21949 pub fn push_target_netnsid(mut self, value: i32) -> Self {
21950 push_header(self.as_rec_mut(), 46u16, 4 as u16);
21951 self.as_rec_mut().extend(value.to_ne_bytes());
21952 self
21953 }
21954 pub fn push_gro_max_size(mut self, value: u32) -> Self {
21955 push_header(self.as_rec_mut(), 58u16, 4 as u16);
21956 self.as_rec_mut().extend(value.to_ne_bytes());
21957 self
21958 }
21959 pub fn push_gso_ipv4_max_size(mut self, value: u32) -> Self {
21960 push_header(self.as_rec_mut(), 63u16, 4 as u16);
21961 self.as_rec_mut().extend(value.to_ne_bytes());
21962 self
21963 }
21964 pub fn push_gro_ipv4_max_size(mut self, value: u32) -> Self {
21965 push_header(self.as_rec_mut(), 64u16, 4 as u16);
21966 self.as_rec_mut().extend(value.to_ne_bytes());
21967 self
21968 }
21969}
21970impl<Prev: Rec> Drop for PushOpNewlinkDoRequest<Prev> {
21971 fn drop(&mut self) {
21972 if let Some(prev) = &mut self.prev {
21973 if let Some(header_offset) = &self.header_offset {
21974 finalize_nested_header(prev.as_rec_mut(), *header_offset);
21975 }
21976 }
21977 }
21978}
21979#[doc = "Create a new link."]
21980#[derive(Clone)]
21981pub enum OpNewlinkDoRequest<'a> {
21982 Address(&'a [u8]),
21983 Broadcast(&'a [u8]),
21984 Ifname(&'a CStr),
21985 Mtu(u32),
21986 Txqlen(u32),
21987 Operstate(u8),
21988 Linkmode(u8),
21989 Linkinfo(IterableLinkinfoAttrs<'a>),
21990 NetNsPid(u32),
21991 AfSpec(IterableAfSpecAttrs<'a>),
21992 Group(u32),
21993 NetNsFd(u32),
21994 NumTxQueues(u32),
21995 NumRxQueues(u32),
21996 LinkNetnsid(i32),
21997 GsoMaxSegs(u32),
21998 GsoMaxSize(u32),
21999 TargetNetnsid(i32),
22000 GroMaxSize(u32),
22001 GsoIpv4MaxSize(u32),
22002 GroIpv4MaxSize(u32),
22003}
22004impl<'a> IterableOpNewlinkDoRequest<'a> {
22005 pub fn get_address(&self) -> Result<&'a [u8], ErrorContext> {
22006 let mut iter = self.clone();
22007 iter.pos = 0;
22008 for attr in iter {
22009 if let OpNewlinkDoRequest::Address(val) = attr? {
22010 return Ok(val);
22011 }
22012 }
22013 Err(ErrorContext::new_missing(
22014 "OpNewlinkDoRequest",
22015 "Address",
22016 self.orig_loc,
22017 self.buf.as_ptr() as usize,
22018 ))
22019 }
22020 pub fn get_broadcast(&self) -> Result<&'a [u8], ErrorContext> {
22021 let mut iter = self.clone();
22022 iter.pos = 0;
22023 for attr in iter {
22024 if let OpNewlinkDoRequest::Broadcast(val) = attr? {
22025 return Ok(val);
22026 }
22027 }
22028 Err(ErrorContext::new_missing(
22029 "OpNewlinkDoRequest",
22030 "Broadcast",
22031 self.orig_loc,
22032 self.buf.as_ptr() as usize,
22033 ))
22034 }
22035 pub fn get_ifname(&self) -> Result<&'a CStr, ErrorContext> {
22036 let mut iter = self.clone();
22037 iter.pos = 0;
22038 for attr in iter {
22039 if let OpNewlinkDoRequest::Ifname(val) = attr? {
22040 return Ok(val);
22041 }
22042 }
22043 Err(ErrorContext::new_missing(
22044 "OpNewlinkDoRequest",
22045 "Ifname",
22046 self.orig_loc,
22047 self.buf.as_ptr() as usize,
22048 ))
22049 }
22050 pub fn get_mtu(&self) -> Result<u32, ErrorContext> {
22051 let mut iter = self.clone();
22052 iter.pos = 0;
22053 for attr in iter {
22054 if let OpNewlinkDoRequest::Mtu(val) = attr? {
22055 return Ok(val);
22056 }
22057 }
22058 Err(ErrorContext::new_missing(
22059 "OpNewlinkDoRequest",
22060 "Mtu",
22061 self.orig_loc,
22062 self.buf.as_ptr() as usize,
22063 ))
22064 }
22065 pub fn get_txqlen(&self) -> Result<u32, ErrorContext> {
22066 let mut iter = self.clone();
22067 iter.pos = 0;
22068 for attr in iter {
22069 if let OpNewlinkDoRequest::Txqlen(val) = attr? {
22070 return Ok(val);
22071 }
22072 }
22073 Err(ErrorContext::new_missing(
22074 "OpNewlinkDoRequest",
22075 "Txqlen",
22076 self.orig_loc,
22077 self.buf.as_ptr() as usize,
22078 ))
22079 }
22080 pub fn get_operstate(&self) -> Result<u8, ErrorContext> {
22081 let mut iter = self.clone();
22082 iter.pos = 0;
22083 for attr in iter {
22084 if let OpNewlinkDoRequest::Operstate(val) = attr? {
22085 return Ok(val);
22086 }
22087 }
22088 Err(ErrorContext::new_missing(
22089 "OpNewlinkDoRequest",
22090 "Operstate",
22091 self.orig_loc,
22092 self.buf.as_ptr() as usize,
22093 ))
22094 }
22095 pub fn get_linkmode(&self) -> Result<u8, ErrorContext> {
22096 let mut iter = self.clone();
22097 iter.pos = 0;
22098 for attr in iter {
22099 if let OpNewlinkDoRequest::Linkmode(val) = attr? {
22100 return Ok(val);
22101 }
22102 }
22103 Err(ErrorContext::new_missing(
22104 "OpNewlinkDoRequest",
22105 "Linkmode",
22106 self.orig_loc,
22107 self.buf.as_ptr() as usize,
22108 ))
22109 }
22110 pub fn get_linkinfo(&self) -> Result<IterableLinkinfoAttrs<'a>, ErrorContext> {
22111 let mut iter = self.clone();
22112 iter.pos = 0;
22113 for attr in iter {
22114 if let OpNewlinkDoRequest::Linkinfo(val) = attr? {
22115 return Ok(val);
22116 }
22117 }
22118 Err(ErrorContext::new_missing(
22119 "OpNewlinkDoRequest",
22120 "Linkinfo",
22121 self.orig_loc,
22122 self.buf.as_ptr() as usize,
22123 ))
22124 }
22125 pub fn get_net_ns_pid(&self) -> Result<u32, ErrorContext> {
22126 let mut iter = self.clone();
22127 iter.pos = 0;
22128 for attr in iter {
22129 if let OpNewlinkDoRequest::NetNsPid(val) = attr? {
22130 return Ok(val);
22131 }
22132 }
22133 Err(ErrorContext::new_missing(
22134 "OpNewlinkDoRequest",
22135 "NetNsPid",
22136 self.orig_loc,
22137 self.buf.as_ptr() as usize,
22138 ))
22139 }
22140 pub fn get_af_spec(&self) -> Result<IterableAfSpecAttrs<'a>, ErrorContext> {
22141 let mut iter = self.clone();
22142 iter.pos = 0;
22143 for attr in iter {
22144 if let OpNewlinkDoRequest::AfSpec(val) = attr? {
22145 return Ok(val);
22146 }
22147 }
22148 Err(ErrorContext::new_missing(
22149 "OpNewlinkDoRequest",
22150 "AfSpec",
22151 self.orig_loc,
22152 self.buf.as_ptr() as usize,
22153 ))
22154 }
22155 pub fn get_group(&self) -> Result<u32, ErrorContext> {
22156 let mut iter = self.clone();
22157 iter.pos = 0;
22158 for attr in iter {
22159 if let OpNewlinkDoRequest::Group(val) = attr? {
22160 return Ok(val);
22161 }
22162 }
22163 Err(ErrorContext::new_missing(
22164 "OpNewlinkDoRequest",
22165 "Group",
22166 self.orig_loc,
22167 self.buf.as_ptr() as usize,
22168 ))
22169 }
22170 pub fn get_net_ns_fd(&self) -> Result<u32, ErrorContext> {
22171 let mut iter = self.clone();
22172 iter.pos = 0;
22173 for attr in iter {
22174 if let OpNewlinkDoRequest::NetNsFd(val) = attr? {
22175 return Ok(val);
22176 }
22177 }
22178 Err(ErrorContext::new_missing(
22179 "OpNewlinkDoRequest",
22180 "NetNsFd",
22181 self.orig_loc,
22182 self.buf.as_ptr() as usize,
22183 ))
22184 }
22185 pub fn get_num_tx_queues(&self) -> Result<u32, ErrorContext> {
22186 let mut iter = self.clone();
22187 iter.pos = 0;
22188 for attr in iter {
22189 if let OpNewlinkDoRequest::NumTxQueues(val) = attr? {
22190 return Ok(val);
22191 }
22192 }
22193 Err(ErrorContext::new_missing(
22194 "OpNewlinkDoRequest",
22195 "NumTxQueues",
22196 self.orig_loc,
22197 self.buf.as_ptr() as usize,
22198 ))
22199 }
22200 pub fn get_num_rx_queues(&self) -> Result<u32, ErrorContext> {
22201 let mut iter = self.clone();
22202 iter.pos = 0;
22203 for attr in iter {
22204 if let OpNewlinkDoRequest::NumRxQueues(val) = attr? {
22205 return Ok(val);
22206 }
22207 }
22208 Err(ErrorContext::new_missing(
22209 "OpNewlinkDoRequest",
22210 "NumRxQueues",
22211 self.orig_loc,
22212 self.buf.as_ptr() as usize,
22213 ))
22214 }
22215 pub fn get_link_netnsid(&self) -> Result<i32, ErrorContext> {
22216 let mut iter = self.clone();
22217 iter.pos = 0;
22218 for attr in iter {
22219 if let OpNewlinkDoRequest::LinkNetnsid(val) = attr? {
22220 return Ok(val);
22221 }
22222 }
22223 Err(ErrorContext::new_missing(
22224 "OpNewlinkDoRequest",
22225 "LinkNetnsid",
22226 self.orig_loc,
22227 self.buf.as_ptr() as usize,
22228 ))
22229 }
22230 pub fn get_gso_max_segs(&self) -> Result<u32, ErrorContext> {
22231 let mut iter = self.clone();
22232 iter.pos = 0;
22233 for attr in iter {
22234 if let OpNewlinkDoRequest::GsoMaxSegs(val) = attr? {
22235 return Ok(val);
22236 }
22237 }
22238 Err(ErrorContext::new_missing(
22239 "OpNewlinkDoRequest",
22240 "GsoMaxSegs",
22241 self.orig_loc,
22242 self.buf.as_ptr() as usize,
22243 ))
22244 }
22245 pub fn get_gso_max_size(&self) -> Result<u32, ErrorContext> {
22246 let mut iter = self.clone();
22247 iter.pos = 0;
22248 for attr in iter {
22249 if let OpNewlinkDoRequest::GsoMaxSize(val) = attr? {
22250 return Ok(val);
22251 }
22252 }
22253 Err(ErrorContext::new_missing(
22254 "OpNewlinkDoRequest",
22255 "GsoMaxSize",
22256 self.orig_loc,
22257 self.buf.as_ptr() as usize,
22258 ))
22259 }
22260 pub fn get_target_netnsid(&self) -> Result<i32, ErrorContext> {
22261 let mut iter = self.clone();
22262 iter.pos = 0;
22263 for attr in iter {
22264 if let OpNewlinkDoRequest::TargetNetnsid(val) = attr? {
22265 return Ok(val);
22266 }
22267 }
22268 Err(ErrorContext::new_missing(
22269 "OpNewlinkDoRequest",
22270 "TargetNetnsid",
22271 self.orig_loc,
22272 self.buf.as_ptr() as usize,
22273 ))
22274 }
22275 pub fn get_gro_max_size(&self) -> Result<u32, ErrorContext> {
22276 let mut iter = self.clone();
22277 iter.pos = 0;
22278 for attr in iter {
22279 if let OpNewlinkDoRequest::GroMaxSize(val) = attr? {
22280 return Ok(val);
22281 }
22282 }
22283 Err(ErrorContext::new_missing(
22284 "OpNewlinkDoRequest",
22285 "GroMaxSize",
22286 self.orig_loc,
22287 self.buf.as_ptr() as usize,
22288 ))
22289 }
22290 pub fn get_gso_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
22291 let mut iter = self.clone();
22292 iter.pos = 0;
22293 for attr in iter {
22294 if let OpNewlinkDoRequest::GsoIpv4MaxSize(val) = attr? {
22295 return Ok(val);
22296 }
22297 }
22298 Err(ErrorContext::new_missing(
22299 "OpNewlinkDoRequest",
22300 "GsoIpv4MaxSize",
22301 self.orig_loc,
22302 self.buf.as_ptr() as usize,
22303 ))
22304 }
22305 pub fn get_gro_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
22306 let mut iter = self.clone();
22307 iter.pos = 0;
22308 for attr in iter {
22309 if let OpNewlinkDoRequest::GroIpv4MaxSize(val) = attr? {
22310 return Ok(val);
22311 }
22312 }
22313 Err(ErrorContext::new_missing(
22314 "OpNewlinkDoRequest",
22315 "GroIpv4MaxSize",
22316 self.orig_loc,
22317 self.buf.as_ptr() as usize,
22318 ))
22319 }
22320}
22321impl OpNewlinkDoRequest<'_> {
22322 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpNewlinkDoRequest<'a>) {
22323 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
22324 (
22325 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
22326 IterableOpNewlinkDoRequest::with_loc(attrs, buf.as_ptr() as usize),
22327 )
22328 }
22329 fn attr_from_type(r#type: u16) -> Option<&'static str> {
22330 LinkAttrs::attr_from_type(r#type)
22331 }
22332}
22333#[derive(Clone, Copy, Default)]
22334pub struct IterableOpNewlinkDoRequest<'a> {
22335 buf: &'a [u8],
22336 pos: usize,
22337 orig_loc: usize,
22338}
22339impl<'a> IterableOpNewlinkDoRequest<'a> {
22340 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22341 Self {
22342 buf,
22343 pos: 0,
22344 orig_loc,
22345 }
22346 }
22347 pub fn get_buf(&self) -> &'a [u8] {
22348 self.buf
22349 }
22350}
22351impl<'a> Iterator for IterableOpNewlinkDoRequest<'a> {
22352 type Item = Result<OpNewlinkDoRequest<'a>, ErrorContext>;
22353 fn next(&mut self) -> Option<Self::Item> {
22354 if self.buf.len() == self.pos {
22355 return None;
22356 }
22357 let pos = self.pos;
22358 let mut r#type = None;
22359 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
22360 r#type = Some(header.r#type);
22361 let res = match header.r#type {
22362 1u16 => OpNewlinkDoRequest::Address({
22363 let res = Some(next);
22364 let Some(val) = res else { break };
22365 val
22366 }),
22367 2u16 => OpNewlinkDoRequest::Broadcast({
22368 let res = Some(next);
22369 let Some(val) = res else { break };
22370 val
22371 }),
22372 3u16 => OpNewlinkDoRequest::Ifname({
22373 let res = CStr::from_bytes_with_nul(next).ok();
22374 let Some(val) = res else { break };
22375 val
22376 }),
22377 4u16 => OpNewlinkDoRequest::Mtu({
22378 let res = parse_u32(next);
22379 let Some(val) = res else { break };
22380 val
22381 }),
22382 13u16 => OpNewlinkDoRequest::Txqlen({
22383 let res = parse_u32(next);
22384 let Some(val) = res else { break };
22385 val
22386 }),
22387 16u16 => OpNewlinkDoRequest::Operstate({
22388 let res = parse_u8(next);
22389 let Some(val) = res else { break };
22390 val
22391 }),
22392 17u16 => OpNewlinkDoRequest::Linkmode({
22393 let res = parse_u8(next);
22394 let Some(val) = res else { break };
22395 val
22396 }),
22397 18u16 => OpNewlinkDoRequest::Linkinfo({
22398 let res = Some(IterableLinkinfoAttrs::with_loc(next, self.orig_loc));
22399 let Some(val) = res else { break };
22400 val
22401 }),
22402 19u16 => OpNewlinkDoRequest::NetNsPid({
22403 let res = parse_u32(next);
22404 let Some(val) = res else { break };
22405 val
22406 }),
22407 26u16 => OpNewlinkDoRequest::AfSpec({
22408 let res = Some(IterableAfSpecAttrs::with_loc(next, self.orig_loc));
22409 let Some(val) = res else { break };
22410 val
22411 }),
22412 27u16 => OpNewlinkDoRequest::Group({
22413 let res = parse_u32(next);
22414 let Some(val) = res else { break };
22415 val
22416 }),
22417 28u16 => OpNewlinkDoRequest::NetNsFd({
22418 let res = parse_u32(next);
22419 let Some(val) = res else { break };
22420 val
22421 }),
22422 31u16 => OpNewlinkDoRequest::NumTxQueues({
22423 let res = parse_u32(next);
22424 let Some(val) = res else { break };
22425 val
22426 }),
22427 32u16 => OpNewlinkDoRequest::NumRxQueues({
22428 let res = parse_u32(next);
22429 let Some(val) = res else { break };
22430 val
22431 }),
22432 37u16 => OpNewlinkDoRequest::LinkNetnsid({
22433 let res = parse_i32(next);
22434 let Some(val) = res else { break };
22435 val
22436 }),
22437 40u16 => OpNewlinkDoRequest::GsoMaxSegs({
22438 let res = parse_u32(next);
22439 let Some(val) = res else { break };
22440 val
22441 }),
22442 41u16 => OpNewlinkDoRequest::GsoMaxSize({
22443 let res = parse_u32(next);
22444 let Some(val) = res else { break };
22445 val
22446 }),
22447 46u16 => OpNewlinkDoRequest::TargetNetnsid({
22448 let res = parse_i32(next);
22449 let Some(val) = res else { break };
22450 val
22451 }),
22452 58u16 => OpNewlinkDoRequest::GroMaxSize({
22453 let res = parse_u32(next);
22454 let Some(val) = res else { break };
22455 val
22456 }),
22457 63u16 => OpNewlinkDoRequest::GsoIpv4MaxSize({
22458 let res = parse_u32(next);
22459 let Some(val) = res else { break };
22460 val
22461 }),
22462 64u16 => OpNewlinkDoRequest::GroIpv4MaxSize({
22463 let res = parse_u32(next);
22464 let Some(val) = res else { break };
22465 val
22466 }),
22467 n => {
22468 if cfg!(any(test, feature = "deny-unknown-attrs")) {
22469 break;
22470 } else {
22471 continue;
22472 }
22473 }
22474 };
22475 return Some(Ok(res));
22476 }
22477 Some(Err(ErrorContext::new(
22478 "OpNewlinkDoRequest",
22479 r#type.and_then(|t| OpNewlinkDoRequest::attr_from_type(t)),
22480 self.orig_loc,
22481 self.buf.as_ptr().wrapping_add(pos) as usize,
22482 )))
22483 }
22484}
22485impl<'a> std::fmt::Debug for IterableOpNewlinkDoRequest<'_> {
22486 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22487 let mut fmt = f.debug_struct("OpNewlinkDoRequest");
22488 for attr in self.clone() {
22489 let attr = match attr {
22490 Ok(a) => a,
22491 Err(err) => {
22492 fmt.finish()?;
22493 f.write_str("Err(")?;
22494 err.fmt(f)?;
22495 return f.write_str(")");
22496 }
22497 };
22498 match attr {
22499 OpNewlinkDoRequest::Address(val) => fmt.field("Address", &val),
22500 OpNewlinkDoRequest::Broadcast(val) => fmt.field("Broadcast", &val),
22501 OpNewlinkDoRequest::Ifname(val) => fmt.field("Ifname", &val),
22502 OpNewlinkDoRequest::Mtu(val) => fmt.field("Mtu", &val),
22503 OpNewlinkDoRequest::Txqlen(val) => fmt.field("Txqlen", &val),
22504 OpNewlinkDoRequest::Operstate(val) => fmt.field("Operstate", &val),
22505 OpNewlinkDoRequest::Linkmode(val) => fmt.field("Linkmode", &val),
22506 OpNewlinkDoRequest::Linkinfo(val) => fmt.field("Linkinfo", &val),
22507 OpNewlinkDoRequest::NetNsPid(val) => fmt.field("NetNsPid", &val),
22508 OpNewlinkDoRequest::AfSpec(val) => fmt.field("AfSpec", &val),
22509 OpNewlinkDoRequest::Group(val) => fmt.field("Group", &val),
22510 OpNewlinkDoRequest::NetNsFd(val) => fmt.field("NetNsFd", &val),
22511 OpNewlinkDoRequest::NumTxQueues(val) => fmt.field("NumTxQueues", &val),
22512 OpNewlinkDoRequest::NumRxQueues(val) => fmt.field("NumRxQueues", &val),
22513 OpNewlinkDoRequest::LinkNetnsid(val) => fmt.field("LinkNetnsid", &val),
22514 OpNewlinkDoRequest::GsoMaxSegs(val) => fmt.field("GsoMaxSegs", &val),
22515 OpNewlinkDoRequest::GsoMaxSize(val) => fmt.field("GsoMaxSize", &val),
22516 OpNewlinkDoRequest::TargetNetnsid(val) => fmt.field("TargetNetnsid", &val),
22517 OpNewlinkDoRequest::GroMaxSize(val) => fmt.field("GroMaxSize", &val),
22518 OpNewlinkDoRequest::GsoIpv4MaxSize(val) => fmt.field("GsoIpv4MaxSize", &val),
22519 OpNewlinkDoRequest::GroIpv4MaxSize(val) => fmt.field("GroIpv4MaxSize", &val),
22520 };
22521 }
22522 fmt.finish()
22523 }
22524}
22525impl IterableOpNewlinkDoRequest<'_> {
22526 pub fn lookup_attr(
22527 &self,
22528 offset: usize,
22529 missing_type: Option<u16>,
22530 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22531 let mut stack = Vec::new();
22532 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
22533 if cur == offset + PushIfinfomsg::len() {
22534 stack.push(("OpNewlinkDoRequest", offset));
22535 return (
22536 stack,
22537 missing_type.and_then(|t| OpNewlinkDoRequest::attr_from_type(t)),
22538 );
22539 }
22540 if cur > offset || cur + self.buf.len() < offset {
22541 return (stack, None);
22542 }
22543 let mut attrs = self.clone();
22544 let mut last_off = cur + attrs.pos;
22545 let mut missing = None;
22546 while let Some(attr) = attrs.next() {
22547 let Ok(attr) = attr else { break };
22548 match attr {
22549 OpNewlinkDoRequest::Address(val) => {
22550 if last_off == offset {
22551 stack.push(("Address", last_off));
22552 break;
22553 }
22554 }
22555 OpNewlinkDoRequest::Broadcast(val) => {
22556 if last_off == offset {
22557 stack.push(("Broadcast", last_off));
22558 break;
22559 }
22560 }
22561 OpNewlinkDoRequest::Ifname(val) => {
22562 if last_off == offset {
22563 stack.push(("Ifname", last_off));
22564 break;
22565 }
22566 }
22567 OpNewlinkDoRequest::Mtu(val) => {
22568 if last_off == offset {
22569 stack.push(("Mtu", last_off));
22570 break;
22571 }
22572 }
22573 OpNewlinkDoRequest::Txqlen(val) => {
22574 if last_off == offset {
22575 stack.push(("Txqlen", last_off));
22576 break;
22577 }
22578 }
22579 OpNewlinkDoRequest::Operstate(val) => {
22580 if last_off == offset {
22581 stack.push(("Operstate", last_off));
22582 break;
22583 }
22584 }
22585 OpNewlinkDoRequest::Linkmode(val) => {
22586 if last_off == offset {
22587 stack.push(("Linkmode", last_off));
22588 break;
22589 }
22590 }
22591 OpNewlinkDoRequest::Linkinfo(val) => {
22592 (stack, missing) = val.lookup_attr(offset, missing_type);
22593 if !stack.is_empty() {
22594 break;
22595 }
22596 }
22597 OpNewlinkDoRequest::NetNsPid(val) => {
22598 if last_off == offset {
22599 stack.push(("NetNsPid", last_off));
22600 break;
22601 }
22602 }
22603 OpNewlinkDoRequest::AfSpec(val) => {
22604 (stack, missing) = val.lookup_attr(offset, missing_type);
22605 if !stack.is_empty() {
22606 break;
22607 }
22608 }
22609 OpNewlinkDoRequest::Group(val) => {
22610 if last_off == offset {
22611 stack.push(("Group", last_off));
22612 break;
22613 }
22614 }
22615 OpNewlinkDoRequest::NetNsFd(val) => {
22616 if last_off == offset {
22617 stack.push(("NetNsFd", last_off));
22618 break;
22619 }
22620 }
22621 OpNewlinkDoRequest::NumTxQueues(val) => {
22622 if last_off == offset {
22623 stack.push(("NumTxQueues", last_off));
22624 break;
22625 }
22626 }
22627 OpNewlinkDoRequest::NumRxQueues(val) => {
22628 if last_off == offset {
22629 stack.push(("NumRxQueues", last_off));
22630 break;
22631 }
22632 }
22633 OpNewlinkDoRequest::LinkNetnsid(val) => {
22634 if last_off == offset {
22635 stack.push(("LinkNetnsid", last_off));
22636 break;
22637 }
22638 }
22639 OpNewlinkDoRequest::GsoMaxSegs(val) => {
22640 if last_off == offset {
22641 stack.push(("GsoMaxSegs", last_off));
22642 break;
22643 }
22644 }
22645 OpNewlinkDoRequest::GsoMaxSize(val) => {
22646 if last_off == offset {
22647 stack.push(("GsoMaxSize", last_off));
22648 break;
22649 }
22650 }
22651 OpNewlinkDoRequest::TargetNetnsid(val) => {
22652 if last_off == offset {
22653 stack.push(("TargetNetnsid", last_off));
22654 break;
22655 }
22656 }
22657 OpNewlinkDoRequest::GroMaxSize(val) => {
22658 if last_off == offset {
22659 stack.push(("GroMaxSize", last_off));
22660 break;
22661 }
22662 }
22663 OpNewlinkDoRequest::GsoIpv4MaxSize(val) => {
22664 if last_off == offset {
22665 stack.push(("GsoIpv4MaxSize", last_off));
22666 break;
22667 }
22668 }
22669 OpNewlinkDoRequest::GroIpv4MaxSize(val) => {
22670 if last_off == offset {
22671 stack.push(("GroIpv4MaxSize", last_off));
22672 break;
22673 }
22674 }
22675 _ => {}
22676 };
22677 last_off = cur + attrs.pos;
22678 }
22679 if !stack.is_empty() {
22680 stack.push(("OpNewlinkDoRequest", cur));
22681 }
22682 (stack, missing)
22683 }
22684}
22685#[doc = "Create a new link."]
22686pub struct PushOpNewlinkDoReply<Prev: Rec> {
22687 pub(crate) prev: Option<Prev>,
22688 pub(crate) header_offset: Option<usize>,
22689}
22690impl<Prev: Rec> Rec for PushOpNewlinkDoReply<Prev> {
22691 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
22692 self.prev.as_mut().unwrap().as_rec_mut()
22693 }
22694}
22695impl<Prev: Rec> PushOpNewlinkDoReply<Prev> {
22696 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
22697 Self::write_header(&mut prev, header);
22698 Self::new_without_header(prev)
22699 }
22700 fn new_without_header(prev: Prev) -> Self {
22701 Self {
22702 prev: Some(prev),
22703 header_offset: None,
22704 }
22705 }
22706 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
22707 prev.as_rec_mut().extend(header.as_slice());
22708 }
22709 pub fn end_nested(mut self) -> Prev {
22710 let mut prev = self.prev.take().unwrap();
22711 if let Some(header_offset) = &self.header_offset {
22712 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22713 }
22714 prev
22715 }
22716}
22717impl<Prev: Rec> Drop for PushOpNewlinkDoReply<Prev> {
22718 fn drop(&mut self) {
22719 if let Some(prev) = &mut self.prev {
22720 if let Some(header_offset) = &self.header_offset {
22721 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22722 }
22723 }
22724 }
22725}
22726#[doc = "Create a new link."]
22727#[derive(Clone)]
22728pub enum OpNewlinkDoReply {}
22729impl<'a> IterableOpNewlinkDoReply<'a> {}
22730impl OpNewlinkDoReply {
22731 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpNewlinkDoReply<'a>) {
22732 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
22733 (
22734 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
22735 IterableOpNewlinkDoReply::with_loc(attrs, buf.as_ptr() as usize),
22736 )
22737 }
22738 fn attr_from_type(r#type: u16) -> Option<&'static str> {
22739 LinkAttrs::attr_from_type(r#type)
22740 }
22741}
22742#[derive(Clone, Copy, Default)]
22743pub struct IterableOpNewlinkDoReply<'a> {
22744 buf: &'a [u8],
22745 pos: usize,
22746 orig_loc: usize,
22747}
22748impl<'a> IterableOpNewlinkDoReply<'a> {
22749 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22750 Self {
22751 buf,
22752 pos: 0,
22753 orig_loc,
22754 }
22755 }
22756 pub fn get_buf(&self) -> &'a [u8] {
22757 self.buf
22758 }
22759}
22760impl<'a> Iterator for IterableOpNewlinkDoReply<'a> {
22761 type Item = Result<OpNewlinkDoReply, ErrorContext>;
22762 fn next(&mut self) -> Option<Self::Item> {
22763 if self.buf.len() == self.pos {
22764 return None;
22765 }
22766 let pos = self.pos;
22767 let mut r#type = None;
22768 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
22769 r#type = Some(header.r#type);
22770 let res = match header.r#type {
22771 n => {
22772 if cfg!(any(test, feature = "deny-unknown-attrs")) {
22773 break;
22774 } else {
22775 continue;
22776 }
22777 }
22778 };
22779 return Some(Ok(res));
22780 }
22781 Some(Err(ErrorContext::new(
22782 "OpNewlinkDoReply",
22783 r#type.and_then(|t| OpNewlinkDoReply::attr_from_type(t)),
22784 self.orig_loc,
22785 self.buf.as_ptr().wrapping_add(pos) as usize,
22786 )))
22787 }
22788}
22789impl std::fmt::Debug for IterableOpNewlinkDoReply<'_> {
22790 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22791 let mut fmt = f.debug_struct("OpNewlinkDoReply");
22792 for attr in self.clone() {
22793 let attr = match attr {
22794 Ok(a) => a,
22795 Err(err) => {
22796 fmt.finish()?;
22797 f.write_str("Err(")?;
22798 err.fmt(f)?;
22799 return f.write_str(")");
22800 }
22801 };
22802 match attr {};
22803 }
22804 fmt.finish()
22805 }
22806}
22807impl IterableOpNewlinkDoReply<'_> {
22808 pub fn lookup_attr(
22809 &self,
22810 offset: usize,
22811 missing_type: Option<u16>,
22812 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22813 let mut stack = Vec::new();
22814 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
22815 if cur == offset + PushIfinfomsg::len() {
22816 stack.push(("OpNewlinkDoReply", offset));
22817 return (
22818 stack,
22819 missing_type.and_then(|t| OpNewlinkDoReply::attr_from_type(t)),
22820 );
22821 }
22822 (stack, None)
22823 }
22824}
22825#[derive(Debug)]
22826pub struct RequestOpNewlinkDoRequest<'r> {
22827 request: Request<'r>,
22828}
22829impl<'r> RequestOpNewlinkDoRequest<'r> {
22830 pub fn new(mut request: Request<'r>, header: &PushIfinfomsg) -> Self {
22831 PushOpNewlinkDoRequest::write_header(&mut request.buf_mut(), header);
22832 Self { request: request }
22833 }
22834 pub fn encode(&mut self) -> PushOpNewlinkDoRequest<&mut Vec<u8>> {
22835 PushOpNewlinkDoRequest::new_without_header(self.request.buf_mut())
22836 }
22837 pub fn into_encoder(self) -> PushOpNewlinkDoRequest<RequestBuf<'r>> {
22838 PushOpNewlinkDoRequest::new_without_header(self.request.buf)
22839 }
22840}
22841impl NetlinkRequest for RequestOpNewlinkDoRequest<'_> {
22842 type ReplyType<'buf> = (PushIfinfomsg, IterableOpNewlinkDoReply<'buf>);
22843 fn protocol(&self) -> Protocol {
22844 Protocol::Raw {
22845 protonum: 0u16,
22846 request_type: 16u16,
22847 }
22848 }
22849 fn flags(&self) -> u16 {
22850 self.request.flags
22851 }
22852 fn payload(&self) -> &[u8] {
22853 self.request.buf()
22854 }
22855 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
22856 OpNewlinkDoReply::new(buf)
22857 }
22858 fn lookup(
22859 buf: &[u8],
22860 offset: usize,
22861 missing_type: Option<u16>,
22862 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22863 OpNewlinkDoRequest::new(buf)
22864 .1
22865 .lookup_attr(offset, missing_type)
22866 }
22867}
22868#[doc = "Delete an existing link."]
22869pub struct PushOpDellinkDoRequest<Prev: Rec> {
22870 pub(crate) prev: Option<Prev>,
22871 pub(crate) header_offset: Option<usize>,
22872}
22873impl<Prev: Rec> Rec for PushOpDellinkDoRequest<Prev> {
22874 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
22875 self.prev.as_mut().unwrap().as_rec_mut()
22876 }
22877}
22878impl<Prev: Rec> PushOpDellinkDoRequest<Prev> {
22879 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
22880 Self::write_header(&mut prev, header);
22881 Self::new_without_header(prev)
22882 }
22883 fn new_without_header(prev: Prev) -> Self {
22884 Self {
22885 prev: Some(prev),
22886 header_offset: None,
22887 }
22888 }
22889 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
22890 prev.as_rec_mut().extend(header.as_slice());
22891 }
22892 pub fn end_nested(mut self) -> Prev {
22893 let mut prev = self.prev.take().unwrap();
22894 if let Some(header_offset) = &self.header_offset {
22895 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22896 }
22897 prev
22898 }
22899 pub fn push_ifname(mut self, value: &CStr) -> Self {
22900 push_header(
22901 self.as_rec_mut(),
22902 3u16,
22903 value.to_bytes_with_nul().len() as u16,
22904 );
22905 self.as_rec_mut().extend(value.to_bytes_with_nul());
22906 self
22907 }
22908 pub fn push_ifname_bytes(mut self, value: &[u8]) -> Self {
22909 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
22910 self.as_rec_mut().extend(value);
22911 self.as_rec_mut().push(0);
22912 self
22913 }
22914}
22915impl<Prev: Rec> Drop for PushOpDellinkDoRequest<Prev> {
22916 fn drop(&mut self) {
22917 if let Some(prev) = &mut self.prev {
22918 if let Some(header_offset) = &self.header_offset {
22919 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22920 }
22921 }
22922 }
22923}
22924#[doc = "Delete an existing link."]
22925#[derive(Clone)]
22926pub enum OpDellinkDoRequest<'a> {
22927 Ifname(&'a CStr),
22928}
22929impl<'a> IterableOpDellinkDoRequest<'a> {
22930 pub fn get_ifname(&self) -> Result<&'a CStr, ErrorContext> {
22931 let mut iter = self.clone();
22932 iter.pos = 0;
22933 for attr in iter {
22934 if let OpDellinkDoRequest::Ifname(val) = attr? {
22935 return Ok(val);
22936 }
22937 }
22938 Err(ErrorContext::new_missing(
22939 "OpDellinkDoRequest",
22940 "Ifname",
22941 self.orig_loc,
22942 self.buf.as_ptr() as usize,
22943 ))
22944 }
22945}
22946impl OpDellinkDoRequest<'_> {
22947 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpDellinkDoRequest<'a>) {
22948 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
22949 (
22950 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
22951 IterableOpDellinkDoRequest::with_loc(attrs, buf.as_ptr() as usize),
22952 )
22953 }
22954 fn attr_from_type(r#type: u16) -> Option<&'static str> {
22955 LinkAttrs::attr_from_type(r#type)
22956 }
22957}
22958#[derive(Clone, Copy, Default)]
22959pub struct IterableOpDellinkDoRequest<'a> {
22960 buf: &'a [u8],
22961 pos: usize,
22962 orig_loc: usize,
22963}
22964impl<'a> IterableOpDellinkDoRequest<'a> {
22965 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22966 Self {
22967 buf,
22968 pos: 0,
22969 orig_loc,
22970 }
22971 }
22972 pub fn get_buf(&self) -> &'a [u8] {
22973 self.buf
22974 }
22975}
22976impl<'a> Iterator for IterableOpDellinkDoRequest<'a> {
22977 type Item = Result<OpDellinkDoRequest<'a>, ErrorContext>;
22978 fn next(&mut self) -> Option<Self::Item> {
22979 if self.buf.len() == self.pos {
22980 return None;
22981 }
22982 let pos = self.pos;
22983 let mut r#type = None;
22984 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
22985 r#type = Some(header.r#type);
22986 let res = match header.r#type {
22987 3u16 => OpDellinkDoRequest::Ifname({
22988 let res = CStr::from_bytes_with_nul(next).ok();
22989 let Some(val) = res else { break };
22990 val
22991 }),
22992 n => {
22993 if cfg!(any(test, feature = "deny-unknown-attrs")) {
22994 break;
22995 } else {
22996 continue;
22997 }
22998 }
22999 };
23000 return Some(Ok(res));
23001 }
23002 Some(Err(ErrorContext::new(
23003 "OpDellinkDoRequest",
23004 r#type.and_then(|t| OpDellinkDoRequest::attr_from_type(t)),
23005 self.orig_loc,
23006 self.buf.as_ptr().wrapping_add(pos) as usize,
23007 )))
23008 }
23009}
23010impl<'a> std::fmt::Debug for IterableOpDellinkDoRequest<'_> {
23011 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23012 let mut fmt = f.debug_struct("OpDellinkDoRequest");
23013 for attr in self.clone() {
23014 let attr = match attr {
23015 Ok(a) => a,
23016 Err(err) => {
23017 fmt.finish()?;
23018 f.write_str("Err(")?;
23019 err.fmt(f)?;
23020 return f.write_str(")");
23021 }
23022 };
23023 match attr {
23024 OpDellinkDoRequest::Ifname(val) => fmt.field("Ifname", &val),
23025 };
23026 }
23027 fmt.finish()
23028 }
23029}
23030impl IterableOpDellinkDoRequest<'_> {
23031 pub fn lookup_attr(
23032 &self,
23033 offset: usize,
23034 missing_type: Option<u16>,
23035 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23036 let mut stack = Vec::new();
23037 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23038 if cur == offset + PushIfinfomsg::len() {
23039 stack.push(("OpDellinkDoRequest", offset));
23040 return (
23041 stack,
23042 missing_type.and_then(|t| OpDellinkDoRequest::attr_from_type(t)),
23043 );
23044 }
23045 if cur > offset || cur + self.buf.len() < offset {
23046 return (stack, None);
23047 }
23048 let mut attrs = self.clone();
23049 let mut last_off = cur + attrs.pos;
23050 while let Some(attr) = attrs.next() {
23051 let Ok(attr) = attr else { break };
23052 match attr {
23053 OpDellinkDoRequest::Ifname(val) => {
23054 if last_off == offset {
23055 stack.push(("Ifname", last_off));
23056 break;
23057 }
23058 }
23059 _ => {}
23060 };
23061 last_off = cur + attrs.pos;
23062 }
23063 if !stack.is_empty() {
23064 stack.push(("OpDellinkDoRequest", cur));
23065 }
23066 (stack, None)
23067 }
23068}
23069#[doc = "Delete an existing link."]
23070pub struct PushOpDellinkDoReply<Prev: Rec> {
23071 pub(crate) prev: Option<Prev>,
23072 pub(crate) header_offset: Option<usize>,
23073}
23074impl<Prev: Rec> Rec for PushOpDellinkDoReply<Prev> {
23075 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
23076 self.prev.as_mut().unwrap().as_rec_mut()
23077 }
23078}
23079impl<Prev: Rec> PushOpDellinkDoReply<Prev> {
23080 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
23081 Self::write_header(&mut prev, header);
23082 Self::new_without_header(prev)
23083 }
23084 fn new_without_header(prev: Prev) -> Self {
23085 Self {
23086 prev: Some(prev),
23087 header_offset: None,
23088 }
23089 }
23090 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
23091 prev.as_rec_mut().extend(header.as_slice());
23092 }
23093 pub fn end_nested(mut self) -> Prev {
23094 let mut prev = self.prev.take().unwrap();
23095 if let Some(header_offset) = &self.header_offset {
23096 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23097 }
23098 prev
23099 }
23100}
23101impl<Prev: Rec> Drop for PushOpDellinkDoReply<Prev> {
23102 fn drop(&mut self) {
23103 if let Some(prev) = &mut self.prev {
23104 if let Some(header_offset) = &self.header_offset {
23105 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23106 }
23107 }
23108 }
23109}
23110#[doc = "Delete an existing link."]
23111#[derive(Clone)]
23112pub enum OpDellinkDoReply {}
23113impl<'a> IterableOpDellinkDoReply<'a> {}
23114impl OpDellinkDoReply {
23115 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpDellinkDoReply<'a>) {
23116 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
23117 (
23118 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
23119 IterableOpDellinkDoReply::with_loc(attrs, buf.as_ptr() as usize),
23120 )
23121 }
23122 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23123 LinkAttrs::attr_from_type(r#type)
23124 }
23125}
23126#[derive(Clone, Copy, Default)]
23127pub struct IterableOpDellinkDoReply<'a> {
23128 buf: &'a [u8],
23129 pos: usize,
23130 orig_loc: usize,
23131}
23132impl<'a> IterableOpDellinkDoReply<'a> {
23133 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
23134 Self {
23135 buf,
23136 pos: 0,
23137 orig_loc,
23138 }
23139 }
23140 pub fn get_buf(&self) -> &'a [u8] {
23141 self.buf
23142 }
23143}
23144impl<'a> Iterator for IterableOpDellinkDoReply<'a> {
23145 type Item = Result<OpDellinkDoReply, ErrorContext>;
23146 fn next(&mut self) -> Option<Self::Item> {
23147 if self.buf.len() == self.pos {
23148 return None;
23149 }
23150 let pos = self.pos;
23151 let mut r#type = None;
23152 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
23153 r#type = Some(header.r#type);
23154 let res = match header.r#type {
23155 n => {
23156 if cfg!(any(test, feature = "deny-unknown-attrs")) {
23157 break;
23158 } else {
23159 continue;
23160 }
23161 }
23162 };
23163 return Some(Ok(res));
23164 }
23165 Some(Err(ErrorContext::new(
23166 "OpDellinkDoReply",
23167 r#type.and_then(|t| OpDellinkDoReply::attr_from_type(t)),
23168 self.orig_loc,
23169 self.buf.as_ptr().wrapping_add(pos) as usize,
23170 )))
23171 }
23172}
23173impl std::fmt::Debug for IterableOpDellinkDoReply<'_> {
23174 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23175 let mut fmt = f.debug_struct("OpDellinkDoReply");
23176 for attr in self.clone() {
23177 let attr = match attr {
23178 Ok(a) => a,
23179 Err(err) => {
23180 fmt.finish()?;
23181 f.write_str("Err(")?;
23182 err.fmt(f)?;
23183 return f.write_str(")");
23184 }
23185 };
23186 match attr {};
23187 }
23188 fmt.finish()
23189 }
23190}
23191impl IterableOpDellinkDoReply<'_> {
23192 pub fn lookup_attr(
23193 &self,
23194 offset: usize,
23195 missing_type: Option<u16>,
23196 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23197 let mut stack = Vec::new();
23198 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23199 if cur == offset + PushIfinfomsg::len() {
23200 stack.push(("OpDellinkDoReply", offset));
23201 return (
23202 stack,
23203 missing_type.and_then(|t| OpDellinkDoReply::attr_from_type(t)),
23204 );
23205 }
23206 (stack, None)
23207 }
23208}
23209#[derive(Debug)]
23210pub struct RequestOpDellinkDoRequest<'r> {
23211 request: Request<'r>,
23212}
23213impl<'r> RequestOpDellinkDoRequest<'r> {
23214 pub fn new(mut request: Request<'r>, header: &PushIfinfomsg) -> Self {
23215 PushOpDellinkDoRequest::write_header(&mut request.buf_mut(), header);
23216 Self { request: request }
23217 }
23218 pub fn encode(&mut self) -> PushOpDellinkDoRequest<&mut Vec<u8>> {
23219 PushOpDellinkDoRequest::new_without_header(self.request.buf_mut())
23220 }
23221 pub fn into_encoder(self) -> PushOpDellinkDoRequest<RequestBuf<'r>> {
23222 PushOpDellinkDoRequest::new_without_header(self.request.buf)
23223 }
23224}
23225impl NetlinkRequest for RequestOpDellinkDoRequest<'_> {
23226 type ReplyType<'buf> = (PushIfinfomsg, IterableOpDellinkDoReply<'buf>);
23227 fn protocol(&self) -> Protocol {
23228 Protocol::Raw {
23229 protonum: 0u16,
23230 request_type: 17u16,
23231 }
23232 }
23233 fn flags(&self) -> u16 {
23234 self.request.flags
23235 }
23236 fn payload(&self) -> &[u8] {
23237 self.request.buf()
23238 }
23239 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
23240 OpDellinkDoReply::new(buf)
23241 }
23242 fn lookup(
23243 buf: &[u8],
23244 offset: usize,
23245 missing_type: Option<u16>,
23246 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23247 OpDellinkDoRequest::new(buf)
23248 .1
23249 .lookup_attr(offset, missing_type)
23250 }
23251}
23252#[doc = "Get / dump information about a link."]
23253pub struct PushOpGetlinkDumpRequest<Prev: Rec> {
23254 pub(crate) prev: Option<Prev>,
23255 pub(crate) header_offset: Option<usize>,
23256}
23257impl<Prev: Rec> Rec for PushOpGetlinkDumpRequest<Prev> {
23258 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
23259 self.prev.as_mut().unwrap().as_rec_mut()
23260 }
23261}
23262impl<Prev: Rec> PushOpGetlinkDumpRequest<Prev> {
23263 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
23264 Self::write_header(&mut prev, header);
23265 Self::new_without_header(prev)
23266 }
23267 fn new_without_header(prev: Prev) -> Self {
23268 Self {
23269 prev: Some(prev),
23270 header_offset: None,
23271 }
23272 }
23273 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
23274 prev.as_rec_mut().extend(header.as_slice());
23275 }
23276 pub fn end_nested(mut self) -> Prev {
23277 let mut prev = self.prev.take().unwrap();
23278 if let Some(header_offset) = &self.header_offset {
23279 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23280 }
23281 prev
23282 }
23283 pub fn push_master(mut self, value: u32) -> Self {
23284 push_header(self.as_rec_mut(), 10u16, 4 as u16);
23285 self.as_rec_mut().extend(value.to_ne_bytes());
23286 self
23287 }
23288 pub fn nested_linkinfo(mut self) -> PushLinkinfoAttrs<Self> {
23289 let header_offset = push_nested_header(self.as_rec_mut(), 18u16);
23290 PushLinkinfoAttrs {
23291 prev: Some(self),
23292 header_offset: Some(header_offset),
23293 }
23294 }
23295 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
23296 pub fn push_ext_mask(mut self, value: u32) -> Self {
23297 push_header(self.as_rec_mut(), 29u16, 4 as u16);
23298 self.as_rec_mut().extend(value.to_ne_bytes());
23299 self
23300 }
23301 pub fn push_target_netnsid(mut self, value: i32) -> Self {
23302 push_header(self.as_rec_mut(), 46u16, 4 as u16);
23303 self.as_rec_mut().extend(value.to_ne_bytes());
23304 self
23305 }
23306}
23307impl<Prev: Rec> Drop for PushOpGetlinkDumpRequest<Prev> {
23308 fn drop(&mut self) {
23309 if let Some(prev) = &mut self.prev {
23310 if let Some(header_offset) = &self.header_offset {
23311 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23312 }
23313 }
23314 }
23315}
23316#[doc = "Get / dump information about a link."]
23317#[derive(Clone)]
23318pub enum OpGetlinkDumpRequest<'a> {
23319 Master(u32),
23320 Linkinfo(IterableLinkinfoAttrs<'a>),
23321 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
23322 ExtMask(u32),
23323 TargetNetnsid(i32),
23324}
23325impl<'a> IterableOpGetlinkDumpRequest<'a> {
23326 pub fn get_master(&self) -> Result<u32, ErrorContext> {
23327 let mut iter = self.clone();
23328 iter.pos = 0;
23329 for attr in iter {
23330 if let OpGetlinkDumpRequest::Master(val) = attr? {
23331 return Ok(val);
23332 }
23333 }
23334 Err(ErrorContext::new_missing(
23335 "OpGetlinkDumpRequest",
23336 "Master",
23337 self.orig_loc,
23338 self.buf.as_ptr() as usize,
23339 ))
23340 }
23341 pub fn get_linkinfo(&self) -> Result<IterableLinkinfoAttrs<'a>, ErrorContext> {
23342 let mut iter = self.clone();
23343 iter.pos = 0;
23344 for attr in iter {
23345 if let OpGetlinkDumpRequest::Linkinfo(val) = attr? {
23346 return Ok(val);
23347 }
23348 }
23349 Err(ErrorContext::new_missing(
23350 "OpGetlinkDumpRequest",
23351 "Linkinfo",
23352 self.orig_loc,
23353 self.buf.as_ptr() as usize,
23354 ))
23355 }
23356 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
23357 pub fn get_ext_mask(&self) -> Result<u32, ErrorContext> {
23358 let mut iter = self.clone();
23359 iter.pos = 0;
23360 for attr in iter {
23361 if let OpGetlinkDumpRequest::ExtMask(val) = attr? {
23362 return Ok(val);
23363 }
23364 }
23365 Err(ErrorContext::new_missing(
23366 "OpGetlinkDumpRequest",
23367 "ExtMask",
23368 self.orig_loc,
23369 self.buf.as_ptr() as usize,
23370 ))
23371 }
23372 pub fn get_target_netnsid(&self) -> Result<i32, ErrorContext> {
23373 let mut iter = self.clone();
23374 iter.pos = 0;
23375 for attr in iter {
23376 if let OpGetlinkDumpRequest::TargetNetnsid(val) = attr? {
23377 return Ok(val);
23378 }
23379 }
23380 Err(ErrorContext::new_missing(
23381 "OpGetlinkDumpRequest",
23382 "TargetNetnsid",
23383 self.orig_loc,
23384 self.buf.as_ptr() as usize,
23385 ))
23386 }
23387}
23388impl OpGetlinkDumpRequest<'_> {
23389 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpGetlinkDumpRequest<'a>) {
23390 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
23391 (
23392 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
23393 IterableOpGetlinkDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
23394 )
23395 }
23396 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23397 LinkAttrs::attr_from_type(r#type)
23398 }
23399}
23400#[derive(Clone, Copy, Default)]
23401pub struct IterableOpGetlinkDumpRequest<'a> {
23402 buf: &'a [u8],
23403 pos: usize,
23404 orig_loc: usize,
23405}
23406impl<'a> IterableOpGetlinkDumpRequest<'a> {
23407 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
23408 Self {
23409 buf,
23410 pos: 0,
23411 orig_loc,
23412 }
23413 }
23414 pub fn get_buf(&self) -> &'a [u8] {
23415 self.buf
23416 }
23417}
23418impl<'a> Iterator for IterableOpGetlinkDumpRequest<'a> {
23419 type Item = Result<OpGetlinkDumpRequest<'a>, ErrorContext>;
23420 fn next(&mut self) -> Option<Self::Item> {
23421 if self.buf.len() == self.pos {
23422 return None;
23423 }
23424 let pos = self.pos;
23425 let mut r#type = None;
23426 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
23427 r#type = Some(header.r#type);
23428 let res = match header.r#type {
23429 10u16 => OpGetlinkDumpRequest::Master({
23430 let res = parse_u32(next);
23431 let Some(val) = res else { break };
23432 val
23433 }),
23434 18u16 => OpGetlinkDumpRequest::Linkinfo({
23435 let res = Some(IterableLinkinfoAttrs::with_loc(next, self.orig_loc));
23436 let Some(val) = res else { break };
23437 val
23438 }),
23439 29u16 => OpGetlinkDumpRequest::ExtMask({
23440 let res = parse_u32(next);
23441 let Some(val) = res else { break };
23442 val
23443 }),
23444 46u16 => OpGetlinkDumpRequest::TargetNetnsid({
23445 let res = parse_i32(next);
23446 let Some(val) = res else { break };
23447 val
23448 }),
23449 n => {
23450 if cfg!(any(test, feature = "deny-unknown-attrs")) {
23451 break;
23452 } else {
23453 continue;
23454 }
23455 }
23456 };
23457 return Some(Ok(res));
23458 }
23459 Some(Err(ErrorContext::new(
23460 "OpGetlinkDumpRequest",
23461 r#type.and_then(|t| OpGetlinkDumpRequest::attr_from_type(t)),
23462 self.orig_loc,
23463 self.buf.as_ptr().wrapping_add(pos) as usize,
23464 )))
23465 }
23466}
23467impl<'a> std::fmt::Debug for IterableOpGetlinkDumpRequest<'_> {
23468 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23469 let mut fmt = f.debug_struct("OpGetlinkDumpRequest");
23470 for attr in self.clone() {
23471 let attr = match attr {
23472 Ok(a) => a,
23473 Err(err) => {
23474 fmt.finish()?;
23475 f.write_str("Err(")?;
23476 err.fmt(f)?;
23477 return f.write_str(")");
23478 }
23479 };
23480 match attr {
23481 OpGetlinkDumpRequest::Master(val) => fmt.field("Master", &val),
23482 OpGetlinkDumpRequest::Linkinfo(val) => fmt.field("Linkinfo", &val),
23483 OpGetlinkDumpRequest::ExtMask(val) => {
23484 fmt.field("ExtMask", &FormatFlags(val.into(), RtextFilter::from_value))
23485 }
23486 OpGetlinkDumpRequest::TargetNetnsid(val) => fmt.field("TargetNetnsid", &val),
23487 };
23488 }
23489 fmt.finish()
23490 }
23491}
23492impl IterableOpGetlinkDumpRequest<'_> {
23493 pub fn lookup_attr(
23494 &self,
23495 offset: usize,
23496 missing_type: Option<u16>,
23497 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23498 let mut stack = Vec::new();
23499 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23500 if cur == offset + PushIfinfomsg::len() {
23501 stack.push(("OpGetlinkDumpRequest", offset));
23502 return (
23503 stack,
23504 missing_type.and_then(|t| OpGetlinkDumpRequest::attr_from_type(t)),
23505 );
23506 }
23507 if cur > offset || cur + self.buf.len() < offset {
23508 return (stack, None);
23509 }
23510 let mut attrs = self.clone();
23511 let mut last_off = cur + attrs.pos;
23512 let mut missing = None;
23513 while let Some(attr) = attrs.next() {
23514 let Ok(attr) = attr else { break };
23515 match attr {
23516 OpGetlinkDumpRequest::Master(val) => {
23517 if last_off == offset {
23518 stack.push(("Master", last_off));
23519 break;
23520 }
23521 }
23522 OpGetlinkDumpRequest::Linkinfo(val) => {
23523 (stack, missing) = val.lookup_attr(offset, missing_type);
23524 if !stack.is_empty() {
23525 break;
23526 }
23527 }
23528 OpGetlinkDumpRequest::ExtMask(val) => {
23529 if last_off == offset {
23530 stack.push(("ExtMask", last_off));
23531 break;
23532 }
23533 }
23534 OpGetlinkDumpRequest::TargetNetnsid(val) => {
23535 if last_off == offset {
23536 stack.push(("TargetNetnsid", last_off));
23537 break;
23538 }
23539 }
23540 _ => {}
23541 };
23542 last_off = cur + attrs.pos;
23543 }
23544 if !stack.is_empty() {
23545 stack.push(("OpGetlinkDumpRequest", cur));
23546 }
23547 (stack, missing)
23548 }
23549}
23550#[doc = "Get / dump information about a link."]
23551pub struct PushOpGetlinkDumpReply<Prev: Rec> {
23552 pub(crate) prev: Option<Prev>,
23553 pub(crate) header_offset: Option<usize>,
23554}
23555impl<Prev: Rec> Rec for PushOpGetlinkDumpReply<Prev> {
23556 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
23557 self.prev.as_mut().unwrap().as_rec_mut()
23558 }
23559}
23560impl<Prev: Rec> PushOpGetlinkDumpReply<Prev> {
23561 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
23562 Self::write_header(&mut prev, header);
23563 Self::new_without_header(prev)
23564 }
23565 fn new_without_header(prev: Prev) -> Self {
23566 Self {
23567 prev: Some(prev),
23568 header_offset: None,
23569 }
23570 }
23571 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
23572 prev.as_rec_mut().extend(header.as_slice());
23573 }
23574 pub fn end_nested(mut self) -> Prev {
23575 let mut prev = self.prev.take().unwrap();
23576 if let Some(header_offset) = &self.header_offset {
23577 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23578 }
23579 prev
23580 }
23581 pub fn push_address(mut self, value: &[u8]) -> Self {
23582 push_header(self.as_rec_mut(), 1u16, value.len() as u16);
23583 self.as_rec_mut().extend(value);
23584 self
23585 }
23586 pub fn push_broadcast(mut self, value: &[u8]) -> Self {
23587 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
23588 self.as_rec_mut().extend(value);
23589 self
23590 }
23591 pub fn push_ifname(mut self, value: &CStr) -> Self {
23592 push_header(
23593 self.as_rec_mut(),
23594 3u16,
23595 value.to_bytes_with_nul().len() as u16,
23596 );
23597 self.as_rec_mut().extend(value.to_bytes_with_nul());
23598 self
23599 }
23600 pub fn push_ifname_bytes(mut self, value: &[u8]) -> Self {
23601 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
23602 self.as_rec_mut().extend(value);
23603 self.as_rec_mut().push(0);
23604 self
23605 }
23606 pub fn push_mtu(mut self, value: u32) -> Self {
23607 push_header(self.as_rec_mut(), 4u16, 4 as u16);
23608 self.as_rec_mut().extend(value.to_ne_bytes());
23609 self
23610 }
23611 pub fn push_link(mut self, value: u32) -> Self {
23612 push_header(self.as_rec_mut(), 5u16, 4 as u16);
23613 self.as_rec_mut().extend(value.to_ne_bytes());
23614 self
23615 }
23616 pub fn push_qdisc(mut self, value: &CStr) -> Self {
23617 push_header(
23618 self.as_rec_mut(),
23619 6u16,
23620 value.to_bytes_with_nul().len() as u16,
23621 );
23622 self.as_rec_mut().extend(value.to_bytes_with_nul());
23623 self
23624 }
23625 pub fn push_qdisc_bytes(mut self, value: &[u8]) -> Self {
23626 push_header(self.as_rec_mut(), 6u16, (value.len() + 1) as u16);
23627 self.as_rec_mut().extend(value);
23628 self.as_rec_mut().push(0);
23629 self
23630 }
23631 pub fn push_stats(mut self, value: PushRtnlLinkStats) -> Self {
23632 push_header(self.as_rec_mut(), 7u16, value.as_slice().len() as u16);
23633 self.as_rec_mut().extend(value.as_slice());
23634 self
23635 }
23636 pub fn push_cost(mut self, value: &CStr) -> Self {
23637 push_header(
23638 self.as_rec_mut(),
23639 8u16,
23640 value.to_bytes_with_nul().len() as u16,
23641 );
23642 self.as_rec_mut().extend(value.to_bytes_with_nul());
23643 self
23644 }
23645 pub fn push_cost_bytes(mut self, value: &[u8]) -> Self {
23646 push_header(self.as_rec_mut(), 8u16, (value.len() + 1) as u16);
23647 self.as_rec_mut().extend(value);
23648 self.as_rec_mut().push(0);
23649 self
23650 }
23651 pub fn push_priority(mut self, value: &CStr) -> Self {
23652 push_header(
23653 self.as_rec_mut(),
23654 9u16,
23655 value.to_bytes_with_nul().len() as u16,
23656 );
23657 self.as_rec_mut().extend(value.to_bytes_with_nul());
23658 self
23659 }
23660 pub fn push_priority_bytes(mut self, value: &[u8]) -> Self {
23661 push_header(self.as_rec_mut(), 9u16, (value.len() + 1) as u16);
23662 self.as_rec_mut().extend(value);
23663 self.as_rec_mut().push(0);
23664 self
23665 }
23666 pub fn push_master(mut self, value: u32) -> Self {
23667 push_header(self.as_rec_mut(), 10u16, 4 as u16);
23668 self.as_rec_mut().extend(value.to_ne_bytes());
23669 self
23670 }
23671 pub fn push_wireless(mut self, value: &CStr) -> Self {
23672 push_header(
23673 self.as_rec_mut(),
23674 11u16,
23675 value.to_bytes_with_nul().len() as u16,
23676 );
23677 self.as_rec_mut().extend(value.to_bytes_with_nul());
23678 self
23679 }
23680 pub fn push_wireless_bytes(mut self, value: &[u8]) -> Self {
23681 push_header(self.as_rec_mut(), 11u16, (value.len() + 1) as u16);
23682 self.as_rec_mut().extend(value);
23683 self.as_rec_mut().push(0);
23684 self
23685 }
23686 pub fn push_protinfo(mut self, value: &CStr) -> Self {
23687 push_header(
23688 self.as_rec_mut(),
23689 12u16,
23690 value.to_bytes_with_nul().len() as u16,
23691 );
23692 self.as_rec_mut().extend(value.to_bytes_with_nul());
23693 self
23694 }
23695 pub fn push_protinfo_bytes(mut self, value: &[u8]) -> Self {
23696 push_header(self.as_rec_mut(), 12u16, (value.len() + 1) as u16);
23697 self.as_rec_mut().extend(value);
23698 self.as_rec_mut().push(0);
23699 self
23700 }
23701 pub fn push_txqlen(mut self, value: u32) -> Self {
23702 push_header(self.as_rec_mut(), 13u16, 4 as u16);
23703 self.as_rec_mut().extend(value.to_ne_bytes());
23704 self
23705 }
23706 pub fn push_map(mut self, value: PushRtnlLinkIfmap) -> Self {
23707 push_header(self.as_rec_mut(), 14u16, value.as_slice().len() as u16);
23708 self.as_rec_mut().extend(value.as_slice());
23709 self
23710 }
23711 pub fn push_weight(mut self, value: u32) -> Self {
23712 push_header(self.as_rec_mut(), 15u16, 4 as u16);
23713 self.as_rec_mut().extend(value.to_ne_bytes());
23714 self
23715 }
23716 pub fn push_operstate(mut self, value: u8) -> Self {
23717 push_header(self.as_rec_mut(), 16u16, 1 as u16);
23718 self.as_rec_mut().extend(value.to_ne_bytes());
23719 self
23720 }
23721 pub fn push_linkmode(mut self, value: u8) -> Self {
23722 push_header(self.as_rec_mut(), 17u16, 1 as u16);
23723 self.as_rec_mut().extend(value.to_ne_bytes());
23724 self
23725 }
23726 pub fn nested_linkinfo(mut self) -> PushLinkinfoAttrs<Self> {
23727 let header_offset = push_nested_header(self.as_rec_mut(), 18u16);
23728 PushLinkinfoAttrs {
23729 prev: Some(self),
23730 header_offset: Some(header_offset),
23731 }
23732 }
23733 pub fn push_net_ns_pid(mut self, value: u32) -> Self {
23734 push_header(self.as_rec_mut(), 19u16, 4 as u16);
23735 self.as_rec_mut().extend(value.to_ne_bytes());
23736 self
23737 }
23738 pub fn push_ifalias(mut self, value: &CStr) -> Self {
23739 push_header(
23740 self.as_rec_mut(),
23741 20u16,
23742 value.to_bytes_with_nul().len() as u16,
23743 );
23744 self.as_rec_mut().extend(value.to_bytes_with_nul());
23745 self
23746 }
23747 pub fn push_ifalias_bytes(mut self, value: &[u8]) -> Self {
23748 push_header(self.as_rec_mut(), 20u16, (value.len() + 1) as u16);
23749 self.as_rec_mut().extend(value);
23750 self.as_rec_mut().push(0);
23751 self
23752 }
23753 pub fn push_num_vf(mut self, value: u32) -> Self {
23754 push_header(self.as_rec_mut(), 21u16, 4 as u16);
23755 self.as_rec_mut().extend(value.to_ne_bytes());
23756 self
23757 }
23758 pub fn nested_vfinfo_list(mut self) -> PushVfinfoListAttrs<Self> {
23759 let header_offset = push_nested_header(self.as_rec_mut(), 22u16);
23760 PushVfinfoListAttrs {
23761 prev: Some(self),
23762 header_offset: Some(header_offset),
23763 }
23764 }
23765 pub fn push_stats64(mut self, value: PushRtnlLinkStats64) -> Self {
23766 push_header(self.as_rec_mut(), 23u16, value.as_slice().len() as u16);
23767 self.as_rec_mut().extend(value.as_slice());
23768 self
23769 }
23770 pub fn nested_vf_ports(mut self) -> PushVfPortsAttrs<Self> {
23771 let header_offset = push_nested_header(self.as_rec_mut(), 24u16);
23772 PushVfPortsAttrs {
23773 prev: Some(self),
23774 header_offset: Some(header_offset),
23775 }
23776 }
23777 pub fn nested_port_self(mut self) -> PushPortSelfAttrs<Self> {
23778 let header_offset = push_nested_header(self.as_rec_mut(), 25u16);
23779 PushPortSelfAttrs {
23780 prev: Some(self),
23781 header_offset: Some(header_offset),
23782 }
23783 }
23784 pub fn nested_af_spec(mut self) -> PushAfSpecAttrs<Self> {
23785 let header_offset = push_nested_header(self.as_rec_mut(), 26u16);
23786 PushAfSpecAttrs {
23787 prev: Some(self),
23788 header_offset: Some(header_offset),
23789 }
23790 }
23791 pub fn push_group(mut self, value: u32) -> Self {
23792 push_header(self.as_rec_mut(), 27u16, 4 as u16);
23793 self.as_rec_mut().extend(value.to_ne_bytes());
23794 self
23795 }
23796 pub fn push_net_ns_fd(mut self, value: u32) -> Self {
23797 push_header(self.as_rec_mut(), 28u16, 4 as u16);
23798 self.as_rec_mut().extend(value.to_ne_bytes());
23799 self
23800 }
23801 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
23802 pub fn push_ext_mask(mut self, value: u32) -> Self {
23803 push_header(self.as_rec_mut(), 29u16, 4 as u16);
23804 self.as_rec_mut().extend(value.to_ne_bytes());
23805 self
23806 }
23807 pub fn push_promiscuity(mut self, value: u32) -> Self {
23808 push_header(self.as_rec_mut(), 30u16, 4 as u16);
23809 self.as_rec_mut().extend(value.to_ne_bytes());
23810 self
23811 }
23812 pub fn push_num_tx_queues(mut self, value: u32) -> Self {
23813 push_header(self.as_rec_mut(), 31u16, 4 as u16);
23814 self.as_rec_mut().extend(value.to_ne_bytes());
23815 self
23816 }
23817 pub fn push_num_rx_queues(mut self, value: u32) -> Self {
23818 push_header(self.as_rec_mut(), 32u16, 4 as u16);
23819 self.as_rec_mut().extend(value.to_ne_bytes());
23820 self
23821 }
23822 pub fn push_carrier(mut self, value: u8) -> Self {
23823 push_header(self.as_rec_mut(), 33u16, 1 as u16);
23824 self.as_rec_mut().extend(value.to_ne_bytes());
23825 self
23826 }
23827 pub fn push_phys_port_id(mut self, value: &[u8]) -> Self {
23828 push_header(self.as_rec_mut(), 34u16, value.len() as u16);
23829 self.as_rec_mut().extend(value);
23830 self
23831 }
23832 pub fn push_carrier_changes(mut self, value: u32) -> Self {
23833 push_header(self.as_rec_mut(), 35u16, 4 as u16);
23834 self.as_rec_mut().extend(value.to_ne_bytes());
23835 self
23836 }
23837 pub fn push_phys_switch_id(mut self, value: &[u8]) -> Self {
23838 push_header(self.as_rec_mut(), 36u16, value.len() as u16);
23839 self.as_rec_mut().extend(value);
23840 self
23841 }
23842 pub fn push_link_netnsid(mut self, value: i32) -> Self {
23843 push_header(self.as_rec_mut(), 37u16, 4 as u16);
23844 self.as_rec_mut().extend(value.to_ne_bytes());
23845 self
23846 }
23847 pub fn push_phys_port_name(mut self, value: &CStr) -> Self {
23848 push_header(
23849 self.as_rec_mut(),
23850 38u16,
23851 value.to_bytes_with_nul().len() as u16,
23852 );
23853 self.as_rec_mut().extend(value.to_bytes_with_nul());
23854 self
23855 }
23856 pub fn push_phys_port_name_bytes(mut self, value: &[u8]) -> Self {
23857 push_header(self.as_rec_mut(), 38u16, (value.len() + 1) as u16);
23858 self.as_rec_mut().extend(value);
23859 self.as_rec_mut().push(0);
23860 self
23861 }
23862 pub fn push_proto_down(mut self, value: u8) -> Self {
23863 push_header(self.as_rec_mut(), 39u16, 1 as u16);
23864 self.as_rec_mut().extend(value.to_ne_bytes());
23865 self
23866 }
23867 pub fn push_gso_max_segs(mut self, value: u32) -> Self {
23868 push_header(self.as_rec_mut(), 40u16, 4 as u16);
23869 self.as_rec_mut().extend(value.to_ne_bytes());
23870 self
23871 }
23872 pub fn push_gso_max_size(mut self, value: u32) -> Self {
23873 push_header(self.as_rec_mut(), 41u16, 4 as u16);
23874 self.as_rec_mut().extend(value.to_ne_bytes());
23875 self
23876 }
23877 pub fn push_pad(mut self, value: &[u8]) -> Self {
23878 push_header(self.as_rec_mut(), 42u16, value.len() as u16);
23879 self.as_rec_mut().extend(value);
23880 self
23881 }
23882 pub fn nested_xdp(mut self) -> PushXdpAttrs<Self> {
23883 let header_offset = push_nested_header(self.as_rec_mut(), 43u16);
23884 PushXdpAttrs {
23885 prev: Some(self),
23886 header_offset: Some(header_offset),
23887 }
23888 }
23889 pub fn push_event(mut self, value: u32) -> Self {
23890 push_header(self.as_rec_mut(), 44u16, 4 as u16);
23891 self.as_rec_mut().extend(value.to_ne_bytes());
23892 self
23893 }
23894 pub fn push_new_netnsid(mut self, value: i32) -> Self {
23895 push_header(self.as_rec_mut(), 45u16, 4 as u16);
23896 self.as_rec_mut().extend(value.to_ne_bytes());
23897 self
23898 }
23899 pub fn push_target_netnsid(mut self, value: i32) -> Self {
23900 push_header(self.as_rec_mut(), 46u16, 4 as u16);
23901 self.as_rec_mut().extend(value.to_ne_bytes());
23902 self
23903 }
23904 pub fn push_carrier_up_count(mut self, value: u32) -> Self {
23905 push_header(self.as_rec_mut(), 47u16, 4 as u16);
23906 self.as_rec_mut().extend(value.to_ne_bytes());
23907 self
23908 }
23909 pub fn push_carrier_down_count(mut self, value: u32) -> Self {
23910 push_header(self.as_rec_mut(), 48u16, 4 as u16);
23911 self.as_rec_mut().extend(value.to_ne_bytes());
23912 self
23913 }
23914 pub fn push_new_ifindex(mut self, value: i32) -> Self {
23915 push_header(self.as_rec_mut(), 49u16, 4 as u16);
23916 self.as_rec_mut().extend(value.to_ne_bytes());
23917 self
23918 }
23919 pub fn push_min_mtu(mut self, value: u32) -> Self {
23920 push_header(self.as_rec_mut(), 50u16, 4 as u16);
23921 self.as_rec_mut().extend(value.to_ne_bytes());
23922 self
23923 }
23924 pub fn push_max_mtu(mut self, value: u32) -> Self {
23925 push_header(self.as_rec_mut(), 51u16, 4 as u16);
23926 self.as_rec_mut().extend(value.to_ne_bytes());
23927 self
23928 }
23929 pub fn nested_prop_list(mut self) -> PushPropListLinkAttrs<Self> {
23930 let header_offset = push_nested_header(self.as_rec_mut(), 52u16);
23931 PushPropListLinkAttrs {
23932 prev: Some(self),
23933 header_offset: Some(header_offset),
23934 }
23935 }
23936 pub fn push_perm_address(mut self, value: &[u8]) -> Self {
23937 push_header(self.as_rec_mut(), 54u16, value.len() as u16);
23938 self.as_rec_mut().extend(value);
23939 self
23940 }
23941 pub fn push_proto_down_reason(mut self, value: &CStr) -> Self {
23942 push_header(
23943 self.as_rec_mut(),
23944 55u16,
23945 value.to_bytes_with_nul().len() as u16,
23946 );
23947 self.as_rec_mut().extend(value.to_bytes_with_nul());
23948 self
23949 }
23950 pub fn push_proto_down_reason_bytes(mut self, value: &[u8]) -> Self {
23951 push_header(self.as_rec_mut(), 55u16, (value.len() + 1) as u16);
23952 self.as_rec_mut().extend(value);
23953 self.as_rec_mut().push(0);
23954 self
23955 }
23956 pub fn push_parent_dev_name(mut self, value: &CStr) -> Self {
23957 push_header(
23958 self.as_rec_mut(),
23959 56u16,
23960 value.to_bytes_with_nul().len() as u16,
23961 );
23962 self.as_rec_mut().extend(value.to_bytes_with_nul());
23963 self
23964 }
23965 pub fn push_parent_dev_name_bytes(mut self, value: &[u8]) -> Self {
23966 push_header(self.as_rec_mut(), 56u16, (value.len() + 1) as u16);
23967 self.as_rec_mut().extend(value);
23968 self.as_rec_mut().push(0);
23969 self
23970 }
23971 pub fn push_parent_dev_bus_name(mut self, value: &CStr) -> Self {
23972 push_header(
23973 self.as_rec_mut(),
23974 57u16,
23975 value.to_bytes_with_nul().len() as u16,
23976 );
23977 self.as_rec_mut().extend(value.to_bytes_with_nul());
23978 self
23979 }
23980 pub fn push_parent_dev_bus_name_bytes(mut self, value: &[u8]) -> Self {
23981 push_header(self.as_rec_mut(), 57u16, (value.len() + 1) as u16);
23982 self.as_rec_mut().extend(value);
23983 self.as_rec_mut().push(0);
23984 self
23985 }
23986 pub fn push_gro_max_size(mut self, value: u32) -> Self {
23987 push_header(self.as_rec_mut(), 58u16, 4 as u16);
23988 self.as_rec_mut().extend(value.to_ne_bytes());
23989 self
23990 }
23991 pub fn push_tso_max_size(mut self, value: u32) -> Self {
23992 push_header(self.as_rec_mut(), 59u16, 4 as u16);
23993 self.as_rec_mut().extend(value.to_ne_bytes());
23994 self
23995 }
23996 pub fn push_tso_max_segs(mut self, value: u32) -> Self {
23997 push_header(self.as_rec_mut(), 60u16, 4 as u16);
23998 self.as_rec_mut().extend(value.to_ne_bytes());
23999 self
24000 }
24001 pub fn push_allmulti(mut self, value: u32) -> Self {
24002 push_header(self.as_rec_mut(), 61u16, 4 as u16);
24003 self.as_rec_mut().extend(value.to_ne_bytes());
24004 self
24005 }
24006 pub fn push_devlink_port(mut self, value: &[u8]) -> Self {
24007 push_header(self.as_rec_mut(), 62u16, value.len() as u16);
24008 self.as_rec_mut().extend(value);
24009 self
24010 }
24011 pub fn push_gso_ipv4_max_size(mut self, value: u32) -> Self {
24012 push_header(self.as_rec_mut(), 63u16, 4 as u16);
24013 self.as_rec_mut().extend(value.to_ne_bytes());
24014 self
24015 }
24016 pub fn push_gro_ipv4_max_size(mut self, value: u32) -> Self {
24017 push_header(self.as_rec_mut(), 64u16, 4 as u16);
24018 self.as_rec_mut().extend(value.to_ne_bytes());
24019 self
24020 }
24021 pub fn nested_dpll_pin(mut self) -> PushLinkDpllPinAttrs<Self> {
24022 let header_offset = push_nested_header(self.as_rec_mut(), 65u16);
24023 PushLinkDpllPinAttrs {
24024 prev: Some(self),
24025 header_offset: Some(header_offset),
24026 }
24027 }
24028 #[doc = "EDT offload horizon supported by the device (in nsec)."]
24029 pub fn push_max_pacing_offload_horizon(mut self, value: u32) -> Self {
24030 push_header(self.as_rec_mut(), 66u16, 4 as u16);
24031 self.as_rec_mut().extend(value.to_ne_bytes());
24032 self
24033 }
24034 pub fn push_netns_immutable(mut self, value: u8) -> Self {
24035 push_header(self.as_rec_mut(), 67u16, 1 as u16);
24036 self.as_rec_mut().extend(value.to_ne_bytes());
24037 self
24038 }
24039}
24040impl<Prev: Rec> Drop for PushOpGetlinkDumpReply<Prev> {
24041 fn drop(&mut self) {
24042 if let Some(prev) = &mut self.prev {
24043 if let Some(header_offset) = &self.header_offset {
24044 finalize_nested_header(prev.as_rec_mut(), *header_offset);
24045 }
24046 }
24047 }
24048}
24049#[doc = "Get / dump information about a link."]
24050#[derive(Clone)]
24051pub enum OpGetlinkDumpReply<'a> {
24052 Address(&'a [u8]),
24053 Broadcast(&'a [u8]),
24054 Ifname(&'a CStr),
24055 Mtu(u32),
24056 Link(u32),
24057 Qdisc(&'a CStr),
24058 Stats(PushRtnlLinkStats),
24059 Cost(&'a CStr),
24060 Priority(&'a CStr),
24061 Master(u32),
24062 Wireless(&'a CStr),
24063 Protinfo(&'a CStr),
24064 Txqlen(u32),
24065 Map(PushRtnlLinkIfmap),
24066 Weight(u32),
24067 Operstate(u8),
24068 Linkmode(u8),
24069 Linkinfo(IterableLinkinfoAttrs<'a>),
24070 NetNsPid(u32),
24071 Ifalias(&'a CStr),
24072 NumVf(u32),
24073 VfinfoList(IterableVfinfoListAttrs<'a>),
24074 Stats64(PushRtnlLinkStats64),
24075 VfPorts(IterableVfPortsAttrs<'a>),
24076 PortSelf(IterablePortSelfAttrs<'a>),
24077 AfSpec(IterableAfSpecAttrs<'a>),
24078 Group(u32),
24079 NetNsFd(u32),
24080 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
24081 ExtMask(u32),
24082 Promiscuity(u32),
24083 NumTxQueues(u32),
24084 NumRxQueues(u32),
24085 Carrier(u8),
24086 PhysPortId(&'a [u8]),
24087 CarrierChanges(u32),
24088 PhysSwitchId(&'a [u8]),
24089 LinkNetnsid(i32),
24090 PhysPortName(&'a CStr),
24091 ProtoDown(u8),
24092 GsoMaxSegs(u32),
24093 GsoMaxSize(u32),
24094 Pad(&'a [u8]),
24095 Xdp(IterableXdpAttrs<'a>),
24096 Event(u32),
24097 NewNetnsid(i32),
24098 TargetNetnsid(i32),
24099 CarrierUpCount(u32),
24100 CarrierDownCount(u32),
24101 NewIfindex(i32),
24102 MinMtu(u32),
24103 MaxMtu(u32),
24104 PropList(IterablePropListLinkAttrs<'a>),
24105 PermAddress(&'a [u8]),
24106 ProtoDownReason(&'a CStr),
24107 ParentDevName(&'a CStr),
24108 ParentDevBusName(&'a CStr),
24109 GroMaxSize(u32),
24110 TsoMaxSize(u32),
24111 TsoMaxSegs(u32),
24112 Allmulti(u32),
24113 DevlinkPort(&'a [u8]),
24114 GsoIpv4MaxSize(u32),
24115 GroIpv4MaxSize(u32),
24116 DpllPin(IterableLinkDpllPinAttrs<'a>),
24117 #[doc = "EDT offload horizon supported by the device (in nsec)."]
24118 MaxPacingOffloadHorizon(u32),
24119 NetnsImmutable(u8),
24120}
24121impl<'a> IterableOpGetlinkDumpReply<'a> {
24122 pub fn get_address(&self) -> Result<&'a [u8], ErrorContext> {
24123 let mut iter = self.clone();
24124 iter.pos = 0;
24125 for attr in iter {
24126 if let OpGetlinkDumpReply::Address(val) = attr? {
24127 return Ok(val);
24128 }
24129 }
24130 Err(ErrorContext::new_missing(
24131 "OpGetlinkDumpReply",
24132 "Address",
24133 self.orig_loc,
24134 self.buf.as_ptr() as usize,
24135 ))
24136 }
24137 pub fn get_broadcast(&self) -> Result<&'a [u8], ErrorContext> {
24138 let mut iter = self.clone();
24139 iter.pos = 0;
24140 for attr in iter {
24141 if let OpGetlinkDumpReply::Broadcast(val) = attr? {
24142 return Ok(val);
24143 }
24144 }
24145 Err(ErrorContext::new_missing(
24146 "OpGetlinkDumpReply",
24147 "Broadcast",
24148 self.orig_loc,
24149 self.buf.as_ptr() as usize,
24150 ))
24151 }
24152 pub fn get_ifname(&self) -> Result<&'a CStr, ErrorContext> {
24153 let mut iter = self.clone();
24154 iter.pos = 0;
24155 for attr in iter {
24156 if let OpGetlinkDumpReply::Ifname(val) = attr? {
24157 return Ok(val);
24158 }
24159 }
24160 Err(ErrorContext::new_missing(
24161 "OpGetlinkDumpReply",
24162 "Ifname",
24163 self.orig_loc,
24164 self.buf.as_ptr() as usize,
24165 ))
24166 }
24167 pub fn get_mtu(&self) -> Result<u32, ErrorContext> {
24168 let mut iter = self.clone();
24169 iter.pos = 0;
24170 for attr in iter {
24171 if let OpGetlinkDumpReply::Mtu(val) = attr? {
24172 return Ok(val);
24173 }
24174 }
24175 Err(ErrorContext::new_missing(
24176 "OpGetlinkDumpReply",
24177 "Mtu",
24178 self.orig_loc,
24179 self.buf.as_ptr() as usize,
24180 ))
24181 }
24182 pub fn get_link(&self) -> Result<u32, ErrorContext> {
24183 let mut iter = self.clone();
24184 iter.pos = 0;
24185 for attr in iter {
24186 if let OpGetlinkDumpReply::Link(val) = attr? {
24187 return Ok(val);
24188 }
24189 }
24190 Err(ErrorContext::new_missing(
24191 "OpGetlinkDumpReply",
24192 "Link",
24193 self.orig_loc,
24194 self.buf.as_ptr() as usize,
24195 ))
24196 }
24197 pub fn get_qdisc(&self) -> Result<&'a CStr, ErrorContext> {
24198 let mut iter = self.clone();
24199 iter.pos = 0;
24200 for attr in iter {
24201 if let OpGetlinkDumpReply::Qdisc(val) = attr? {
24202 return Ok(val);
24203 }
24204 }
24205 Err(ErrorContext::new_missing(
24206 "OpGetlinkDumpReply",
24207 "Qdisc",
24208 self.orig_loc,
24209 self.buf.as_ptr() as usize,
24210 ))
24211 }
24212 pub fn get_stats(&self) -> Result<PushRtnlLinkStats, ErrorContext> {
24213 let mut iter = self.clone();
24214 iter.pos = 0;
24215 for attr in iter {
24216 if let OpGetlinkDumpReply::Stats(val) = attr? {
24217 return Ok(val);
24218 }
24219 }
24220 Err(ErrorContext::new_missing(
24221 "OpGetlinkDumpReply",
24222 "Stats",
24223 self.orig_loc,
24224 self.buf.as_ptr() as usize,
24225 ))
24226 }
24227 pub fn get_cost(&self) -> Result<&'a CStr, ErrorContext> {
24228 let mut iter = self.clone();
24229 iter.pos = 0;
24230 for attr in iter {
24231 if let OpGetlinkDumpReply::Cost(val) = attr? {
24232 return Ok(val);
24233 }
24234 }
24235 Err(ErrorContext::new_missing(
24236 "OpGetlinkDumpReply",
24237 "Cost",
24238 self.orig_loc,
24239 self.buf.as_ptr() as usize,
24240 ))
24241 }
24242 pub fn get_priority(&self) -> Result<&'a CStr, ErrorContext> {
24243 let mut iter = self.clone();
24244 iter.pos = 0;
24245 for attr in iter {
24246 if let OpGetlinkDumpReply::Priority(val) = attr? {
24247 return Ok(val);
24248 }
24249 }
24250 Err(ErrorContext::new_missing(
24251 "OpGetlinkDumpReply",
24252 "Priority",
24253 self.orig_loc,
24254 self.buf.as_ptr() as usize,
24255 ))
24256 }
24257 pub fn get_master(&self) -> Result<u32, ErrorContext> {
24258 let mut iter = self.clone();
24259 iter.pos = 0;
24260 for attr in iter {
24261 if let OpGetlinkDumpReply::Master(val) = attr? {
24262 return Ok(val);
24263 }
24264 }
24265 Err(ErrorContext::new_missing(
24266 "OpGetlinkDumpReply",
24267 "Master",
24268 self.orig_loc,
24269 self.buf.as_ptr() as usize,
24270 ))
24271 }
24272 pub fn get_wireless(&self) -> Result<&'a CStr, ErrorContext> {
24273 let mut iter = self.clone();
24274 iter.pos = 0;
24275 for attr in iter {
24276 if let OpGetlinkDumpReply::Wireless(val) = attr? {
24277 return Ok(val);
24278 }
24279 }
24280 Err(ErrorContext::new_missing(
24281 "OpGetlinkDumpReply",
24282 "Wireless",
24283 self.orig_loc,
24284 self.buf.as_ptr() as usize,
24285 ))
24286 }
24287 pub fn get_protinfo(&self) -> Result<&'a CStr, ErrorContext> {
24288 let mut iter = self.clone();
24289 iter.pos = 0;
24290 for attr in iter {
24291 if let OpGetlinkDumpReply::Protinfo(val) = attr? {
24292 return Ok(val);
24293 }
24294 }
24295 Err(ErrorContext::new_missing(
24296 "OpGetlinkDumpReply",
24297 "Protinfo",
24298 self.orig_loc,
24299 self.buf.as_ptr() as usize,
24300 ))
24301 }
24302 pub fn get_txqlen(&self) -> Result<u32, ErrorContext> {
24303 let mut iter = self.clone();
24304 iter.pos = 0;
24305 for attr in iter {
24306 if let OpGetlinkDumpReply::Txqlen(val) = attr? {
24307 return Ok(val);
24308 }
24309 }
24310 Err(ErrorContext::new_missing(
24311 "OpGetlinkDumpReply",
24312 "Txqlen",
24313 self.orig_loc,
24314 self.buf.as_ptr() as usize,
24315 ))
24316 }
24317 pub fn get_map(&self) -> Result<PushRtnlLinkIfmap, ErrorContext> {
24318 let mut iter = self.clone();
24319 iter.pos = 0;
24320 for attr in iter {
24321 if let OpGetlinkDumpReply::Map(val) = attr? {
24322 return Ok(val);
24323 }
24324 }
24325 Err(ErrorContext::new_missing(
24326 "OpGetlinkDumpReply",
24327 "Map",
24328 self.orig_loc,
24329 self.buf.as_ptr() as usize,
24330 ))
24331 }
24332 pub fn get_weight(&self) -> Result<u32, ErrorContext> {
24333 let mut iter = self.clone();
24334 iter.pos = 0;
24335 for attr in iter {
24336 if let OpGetlinkDumpReply::Weight(val) = attr? {
24337 return Ok(val);
24338 }
24339 }
24340 Err(ErrorContext::new_missing(
24341 "OpGetlinkDumpReply",
24342 "Weight",
24343 self.orig_loc,
24344 self.buf.as_ptr() as usize,
24345 ))
24346 }
24347 pub fn get_operstate(&self) -> Result<u8, ErrorContext> {
24348 let mut iter = self.clone();
24349 iter.pos = 0;
24350 for attr in iter {
24351 if let OpGetlinkDumpReply::Operstate(val) = attr? {
24352 return Ok(val);
24353 }
24354 }
24355 Err(ErrorContext::new_missing(
24356 "OpGetlinkDumpReply",
24357 "Operstate",
24358 self.orig_loc,
24359 self.buf.as_ptr() as usize,
24360 ))
24361 }
24362 pub fn get_linkmode(&self) -> Result<u8, ErrorContext> {
24363 let mut iter = self.clone();
24364 iter.pos = 0;
24365 for attr in iter {
24366 if let OpGetlinkDumpReply::Linkmode(val) = attr? {
24367 return Ok(val);
24368 }
24369 }
24370 Err(ErrorContext::new_missing(
24371 "OpGetlinkDumpReply",
24372 "Linkmode",
24373 self.orig_loc,
24374 self.buf.as_ptr() as usize,
24375 ))
24376 }
24377 pub fn get_linkinfo(&self) -> Result<IterableLinkinfoAttrs<'a>, ErrorContext> {
24378 let mut iter = self.clone();
24379 iter.pos = 0;
24380 for attr in iter {
24381 if let OpGetlinkDumpReply::Linkinfo(val) = attr? {
24382 return Ok(val);
24383 }
24384 }
24385 Err(ErrorContext::new_missing(
24386 "OpGetlinkDumpReply",
24387 "Linkinfo",
24388 self.orig_loc,
24389 self.buf.as_ptr() as usize,
24390 ))
24391 }
24392 pub fn get_net_ns_pid(&self) -> Result<u32, ErrorContext> {
24393 let mut iter = self.clone();
24394 iter.pos = 0;
24395 for attr in iter {
24396 if let OpGetlinkDumpReply::NetNsPid(val) = attr? {
24397 return Ok(val);
24398 }
24399 }
24400 Err(ErrorContext::new_missing(
24401 "OpGetlinkDumpReply",
24402 "NetNsPid",
24403 self.orig_loc,
24404 self.buf.as_ptr() as usize,
24405 ))
24406 }
24407 pub fn get_ifalias(&self) -> Result<&'a CStr, ErrorContext> {
24408 let mut iter = self.clone();
24409 iter.pos = 0;
24410 for attr in iter {
24411 if let OpGetlinkDumpReply::Ifalias(val) = attr? {
24412 return Ok(val);
24413 }
24414 }
24415 Err(ErrorContext::new_missing(
24416 "OpGetlinkDumpReply",
24417 "Ifalias",
24418 self.orig_loc,
24419 self.buf.as_ptr() as usize,
24420 ))
24421 }
24422 pub fn get_num_vf(&self) -> Result<u32, ErrorContext> {
24423 let mut iter = self.clone();
24424 iter.pos = 0;
24425 for attr in iter {
24426 if let OpGetlinkDumpReply::NumVf(val) = attr? {
24427 return Ok(val);
24428 }
24429 }
24430 Err(ErrorContext::new_missing(
24431 "OpGetlinkDumpReply",
24432 "NumVf",
24433 self.orig_loc,
24434 self.buf.as_ptr() as usize,
24435 ))
24436 }
24437 pub fn get_vfinfo_list(&self) -> Result<IterableVfinfoListAttrs<'a>, ErrorContext> {
24438 let mut iter = self.clone();
24439 iter.pos = 0;
24440 for attr in iter {
24441 if let OpGetlinkDumpReply::VfinfoList(val) = attr? {
24442 return Ok(val);
24443 }
24444 }
24445 Err(ErrorContext::new_missing(
24446 "OpGetlinkDumpReply",
24447 "VfinfoList",
24448 self.orig_loc,
24449 self.buf.as_ptr() as usize,
24450 ))
24451 }
24452 pub fn get_stats64(&self) -> Result<PushRtnlLinkStats64, ErrorContext> {
24453 let mut iter = self.clone();
24454 iter.pos = 0;
24455 for attr in iter {
24456 if let OpGetlinkDumpReply::Stats64(val) = attr? {
24457 return Ok(val);
24458 }
24459 }
24460 Err(ErrorContext::new_missing(
24461 "OpGetlinkDumpReply",
24462 "Stats64",
24463 self.orig_loc,
24464 self.buf.as_ptr() as usize,
24465 ))
24466 }
24467 pub fn get_vf_ports(&self) -> Result<IterableVfPortsAttrs<'a>, ErrorContext> {
24468 let mut iter = self.clone();
24469 iter.pos = 0;
24470 for attr in iter {
24471 if let OpGetlinkDumpReply::VfPorts(val) = attr? {
24472 return Ok(val);
24473 }
24474 }
24475 Err(ErrorContext::new_missing(
24476 "OpGetlinkDumpReply",
24477 "VfPorts",
24478 self.orig_loc,
24479 self.buf.as_ptr() as usize,
24480 ))
24481 }
24482 pub fn get_port_self(&self) -> Result<IterablePortSelfAttrs<'a>, ErrorContext> {
24483 let mut iter = self.clone();
24484 iter.pos = 0;
24485 for attr in iter {
24486 if let OpGetlinkDumpReply::PortSelf(val) = attr? {
24487 return Ok(val);
24488 }
24489 }
24490 Err(ErrorContext::new_missing(
24491 "OpGetlinkDumpReply",
24492 "PortSelf",
24493 self.orig_loc,
24494 self.buf.as_ptr() as usize,
24495 ))
24496 }
24497 pub fn get_af_spec(&self) -> Result<IterableAfSpecAttrs<'a>, ErrorContext> {
24498 let mut iter = self.clone();
24499 iter.pos = 0;
24500 for attr in iter {
24501 if let OpGetlinkDumpReply::AfSpec(val) = attr? {
24502 return Ok(val);
24503 }
24504 }
24505 Err(ErrorContext::new_missing(
24506 "OpGetlinkDumpReply",
24507 "AfSpec",
24508 self.orig_loc,
24509 self.buf.as_ptr() as usize,
24510 ))
24511 }
24512 pub fn get_group(&self) -> Result<u32, ErrorContext> {
24513 let mut iter = self.clone();
24514 iter.pos = 0;
24515 for attr in iter {
24516 if let OpGetlinkDumpReply::Group(val) = attr? {
24517 return Ok(val);
24518 }
24519 }
24520 Err(ErrorContext::new_missing(
24521 "OpGetlinkDumpReply",
24522 "Group",
24523 self.orig_loc,
24524 self.buf.as_ptr() as usize,
24525 ))
24526 }
24527 pub fn get_net_ns_fd(&self) -> Result<u32, ErrorContext> {
24528 let mut iter = self.clone();
24529 iter.pos = 0;
24530 for attr in iter {
24531 if let OpGetlinkDumpReply::NetNsFd(val) = attr? {
24532 return Ok(val);
24533 }
24534 }
24535 Err(ErrorContext::new_missing(
24536 "OpGetlinkDumpReply",
24537 "NetNsFd",
24538 self.orig_loc,
24539 self.buf.as_ptr() as usize,
24540 ))
24541 }
24542 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
24543 pub fn get_ext_mask(&self) -> Result<u32, ErrorContext> {
24544 let mut iter = self.clone();
24545 iter.pos = 0;
24546 for attr in iter {
24547 if let OpGetlinkDumpReply::ExtMask(val) = attr? {
24548 return Ok(val);
24549 }
24550 }
24551 Err(ErrorContext::new_missing(
24552 "OpGetlinkDumpReply",
24553 "ExtMask",
24554 self.orig_loc,
24555 self.buf.as_ptr() as usize,
24556 ))
24557 }
24558 pub fn get_promiscuity(&self) -> Result<u32, ErrorContext> {
24559 let mut iter = self.clone();
24560 iter.pos = 0;
24561 for attr in iter {
24562 if let OpGetlinkDumpReply::Promiscuity(val) = attr? {
24563 return Ok(val);
24564 }
24565 }
24566 Err(ErrorContext::new_missing(
24567 "OpGetlinkDumpReply",
24568 "Promiscuity",
24569 self.orig_loc,
24570 self.buf.as_ptr() as usize,
24571 ))
24572 }
24573 pub fn get_num_tx_queues(&self) -> Result<u32, ErrorContext> {
24574 let mut iter = self.clone();
24575 iter.pos = 0;
24576 for attr in iter {
24577 if let OpGetlinkDumpReply::NumTxQueues(val) = attr? {
24578 return Ok(val);
24579 }
24580 }
24581 Err(ErrorContext::new_missing(
24582 "OpGetlinkDumpReply",
24583 "NumTxQueues",
24584 self.orig_loc,
24585 self.buf.as_ptr() as usize,
24586 ))
24587 }
24588 pub fn get_num_rx_queues(&self) -> Result<u32, ErrorContext> {
24589 let mut iter = self.clone();
24590 iter.pos = 0;
24591 for attr in iter {
24592 if let OpGetlinkDumpReply::NumRxQueues(val) = attr? {
24593 return Ok(val);
24594 }
24595 }
24596 Err(ErrorContext::new_missing(
24597 "OpGetlinkDumpReply",
24598 "NumRxQueues",
24599 self.orig_loc,
24600 self.buf.as_ptr() as usize,
24601 ))
24602 }
24603 pub fn get_carrier(&self) -> Result<u8, ErrorContext> {
24604 let mut iter = self.clone();
24605 iter.pos = 0;
24606 for attr in iter {
24607 if let OpGetlinkDumpReply::Carrier(val) = attr? {
24608 return Ok(val);
24609 }
24610 }
24611 Err(ErrorContext::new_missing(
24612 "OpGetlinkDumpReply",
24613 "Carrier",
24614 self.orig_loc,
24615 self.buf.as_ptr() as usize,
24616 ))
24617 }
24618 pub fn get_phys_port_id(&self) -> Result<&'a [u8], ErrorContext> {
24619 let mut iter = self.clone();
24620 iter.pos = 0;
24621 for attr in iter {
24622 if let OpGetlinkDumpReply::PhysPortId(val) = attr? {
24623 return Ok(val);
24624 }
24625 }
24626 Err(ErrorContext::new_missing(
24627 "OpGetlinkDumpReply",
24628 "PhysPortId",
24629 self.orig_loc,
24630 self.buf.as_ptr() as usize,
24631 ))
24632 }
24633 pub fn get_carrier_changes(&self) -> Result<u32, ErrorContext> {
24634 let mut iter = self.clone();
24635 iter.pos = 0;
24636 for attr in iter {
24637 if let OpGetlinkDumpReply::CarrierChanges(val) = attr? {
24638 return Ok(val);
24639 }
24640 }
24641 Err(ErrorContext::new_missing(
24642 "OpGetlinkDumpReply",
24643 "CarrierChanges",
24644 self.orig_loc,
24645 self.buf.as_ptr() as usize,
24646 ))
24647 }
24648 pub fn get_phys_switch_id(&self) -> Result<&'a [u8], ErrorContext> {
24649 let mut iter = self.clone();
24650 iter.pos = 0;
24651 for attr in iter {
24652 if let OpGetlinkDumpReply::PhysSwitchId(val) = attr? {
24653 return Ok(val);
24654 }
24655 }
24656 Err(ErrorContext::new_missing(
24657 "OpGetlinkDumpReply",
24658 "PhysSwitchId",
24659 self.orig_loc,
24660 self.buf.as_ptr() as usize,
24661 ))
24662 }
24663 pub fn get_link_netnsid(&self) -> Result<i32, ErrorContext> {
24664 let mut iter = self.clone();
24665 iter.pos = 0;
24666 for attr in iter {
24667 if let OpGetlinkDumpReply::LinkNetnsid(val) = attr? {
24668 return Ok(val);
24669 }
24670 }
24671 Err(ErrorContext::new_missing(
24672 "OpGetlinkDumpReply",
24673 "LinkNetnsid",
24674 self.orig_loc,
24675 self.buf.as_ptr() as usize,
24676 ))
24677 }
24678 pub fn get_phys_port_name(&self) -> Result<&'a CStr, ErrorContext> {
24679 let mut iter = self.clone();
24680 iter.pos = 0;
24681 for attr in iter {
24682 if let OpGetlinkDumpReply::PhysPortName(val) = attr? {
24683 return Ok(val);
24684 }
24685 }
24686 Err(ErrorContext::new_missing(
24687 "OpGetlinkDumpReply",
24688 "PhysPortName",
24689 self.orig_loc,
24690 self.buf.as_ptr() as usize,
24691 ))
24692 }
24693 pub fn get_proto_down(&self) -> Result<u8, ErrorContext> {
24694 let mut iter = self.clone();
24695 iter.pos = 0;
24696 for attr in iter {
24697 if let OpGetlinkDumpReply::ProtoDown(val) = attr? {
24698 return Ok(val);
24699 }
24700 }
24701 Err(ErrorContext::new_missing(
24702 "OpGetlinkDumpReply",
24703 "ProtoDown",
24704 self.orig_loc,
24705 self.buf.as_ptr() as usize,
24706 ))
24707 }
24708 pub fn get_gso_max_segs(&self) -> Result<u32, ErrorContext> {
24709 let mut iter = self.clone();
24710 iter.pos = 0;
24711 for attr in iter {
24712 if let OpGetlinkDumpReply::GsoMaxSegs(val) = attr? {
24713 return Ok(val);
24714 }
24715 }
24716 Err(ErrorContext::new_missing(
24717 "OpGetlinkDumpReply",
24718 "GsoMaxSegs",
24719 self.orig_loc,
24720 self.buf.as_ptr() as usize,
24721 ))
24722 }
24723 pub fn get_gso_max_size(&self) -> Result<u32, ErrorContext> {
24724 let mut iter = self.clone();
24725 iter.pos = 0;
24726 for attr in iter {
24727 if let OpGetlinkDumpReply::GsoMaxSize(val) = attr? {
24728 return Ok(val);
24729 }
24730 }
24731 Err(ErrorContext::new_missing(
24732 "OpGetlinkDumpReply",
24733 "GsoMaxSize",
24734 self.orig_loc,
24735 self.buf.as_ptr() as usize,
24736 ))
24737 }
24738 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
24739 let mut iter = self.clone();
24740 iter.pos = 0;
24741 for attr in iter {
24742 if let OpGetlinkDumpReply::Pad(val) = attr? {
24743 return Ok(val);
24744 }
24745 }
24746 Err(ErrorContext::new_missing(
24747 "OpGetlinkDumpReply",
24748 "Pad",
24749 self.orig_loc,
24750 self.buf.as_ptr() as usize,
24751 ))
24752 }
24753 pub fn get_xdp(&self) -> Result<IterableXdpAttrs<'a>, ErrorContext> {
24754 let mut iter = self.clone();
24755 iter.pos = 0;
24756 for attr in iter {
24757 if let OpGetlinkDumpReply::Xdp(val) = attr? {
24758 return Ok(val);
24759 }
24760 }
24761 Err(ErrorContext::new_missing(
24762 "OpGetlinkDumpReply",
24763 "Xdp",
24764 self.orig_loc,
24765 self.buf.as_ptr() as usize,
24766 ))
24767 }
24768 pub fn get_event(&self) -> Result<u32, ErrorContext> {
24769 let mut iter = self.clone();
24770 iter.pos = 0;
24771 for attr in iter {
24772 if let OpGetlinkDumpReply::Event(val) = attr? {
24773 return Ok(val);
24774 }
24775 }
24776 Err(ErrorContext::new_missing(
24777 "OpGetlinkDumpReply",
24778 "Event",
24779 self.orig_loc,
24780 self.buf.as_ptr() as usize,
24781 ))
24782 }
24783 pub fn get_new_netnsid(&self) -> Result<i32, ErrorContext> {
24784 let mut iter = self.clone();
24785 iter.pos = 0;
24786 for attr in iter {
24787 if let OpGetlinkDumpReply::NewNetnsid(val) = attr? {
24788 return Ok(val);
24789 }
24790 }
24791 Err(ErrorContext::new_missing(
24792 "OpGetlinkDumpReply",
24793 "NewNetnsid",
24794 self.orig_loc,
24795 self.buf.as_ptr() as usize,
24796 ))
24797 }
24798 pub fn get_target_netnsid(&self) -> Result<i32, ErrorContext> {
24799 let mut iter = self.clone();
24800 iter.pos = 0;
24801 for attr in iter {
24802 if let OpGetlinkDumpReply::TargetNetnsid(val) = attr? {
24803 return Ok(val);
24804 }
24805 }
24806 Err(ErrorContext::new_missing(
24807 "OpGetlinkDumpReply",
24808 "TargetNetnsid",
24809 self.orig_loc,
24810 self.buf.as_ptr() as usize,
24811 ))
24812 }
24813 pub fn get_carrier_up_count(&self) -> Result<u32, ErrorContext> {
24814 let mut iter = self.clone();
24815 iter.pos = 0;
24816 for attr in iter {
24817 if let OpGetlinkDumpReply::CarrierUpCount(val) = attr? {
24818 return Ok(val);
24819 }
24820 }
24821 Err(ErrorContext::new_missing(
24822 "OpGetlinkDumpReply",
24823 "CarrierUpCount",
24824 self.orig_loc,
24825 self.buf.as_ptr() as usize,
24826 ))
24827 }
24828 pub fn get_carrier_down_count(&self) -> Result<u32, ErrorContext> {
24829 let mut iter = self.clone();
24830 iter.pos = 0;
24831 for attr in iter {
24832 if let OpGetlinkDumpReply::CarrierDownCount(val) = attr? {
24833 return Ok(val);
24834 }
24835 }
24836 Err(ErrorContext::new_missing(
24837 "OpGetlinkDumpReply",
24838 "CarrierDownCount",
24839 self.orig_loc,
24840 self.buf.as_ptr() as usize,
24841 ))
24842 }
24843 pub fn get_new_ifindex(&self) -> Result<i32, ErrorContext> {
24844 let mut iter = self.clone();
24845 iter.pos = 0;
24846 for attr in iter {
24847 if let OpGetlinkDumpReply::NewIfindex(val) = attr? {
24848 return Ok(val);
24849 }
24850 }
24851 Err(ErrorContext::new_missing(
24852 "OpGetlinkDumpReply",
24853 "NewIfindex",
24854 self.orig_loc,
24855 self.buf.as_ptr() as usize,
24856 ))
24857 }
24858 pub fn get_min_mtu(&self) -> Result<u32, ErrorContext> {
24859 let mut iter = self.clone();
24860 iter.pos = 0;
24861 for attr in iter {
24862 if let OpGetlinkDumpReply::MinMtu(val) = attr? {
24863 return Ok(val);
24864 }
24865 }
24866 Err(ErrorContext::new_missing(
24867 "OpGetlinkDumpReply",
24868 "MinMtu",
24869 self.orig_loc,
24870 self.buf.as_ptr() as usize,
24871 ))
24872 }
24873 pub fn get_max_mtu(&self) -> Result<u32, ErrorContext> {
24874 let mut iter = self.clone();
24875 iter.pos = 0;
24876 for attr in iter {
24877 if let OpGetlinkDumpReply::MaxMtu(val) = attr? {
24878 return Ok(val);
24879 }
24880 }
24881 Err(ErrorContext::new_missing(
24882 "OpGetlinkDumpReply",
24883 "MaxMtu",
24884 self.orig_loc,
24885 self.buf.as_ptr() as usize,
24886 ))
24887 }
24888 pub fn get_prop_list(&self) -> Result<IterablePropListLinkAttrs<'a>, ErrorContext> {
24889 let mut iter = self.clone();
24890 iter.pos = 0;
24891 for attr in iter {
24892 if let OpGetlinkDumpReply::PropList(val) = attr? {
24893 return Ok(val);
24894 }
24895 }
24896 Err(ErrorContext::new_missing(
24897 "OpGetlinkDumpReply",
24898 "PropList",
24899 self.orig_loc,
24900 self.buf.as_ptr() as usize,
24901 ))
24902 }
24903 pub fn get_perm_address(&self) -> Result<&'a [u8], ErrorContext> {
24904 let mut iter = self.clone();
24905 iter.pos = 0;
24906 for attr in iter {
24907 if let OpGetlinkDumpReply::PermAddress(val) = attr? {
24908 return Ok(val);
24909 }
24910 }
24911 Err(ErrorContext::new_missing(
24912 "OpGetlinkDumpReply",
24913 "PermAddress",
24914 self.orig_loc,
24915 self.buf.as_ptr() as usize,
24916 ))
24917 }
24918 pub fn get_proto_down_reason(&self) -> Result<&'a CStr, ErrorContext> {
24919 let mut iter = self.clone();
24920 iter.pos = 0;
24921 for attr in iter {
24922 if let OpGetlinkDumpReply::ProtoDownReason(val) = attr? {
24923 return Ok(val);
24924 }
24925 }
24926 Err(ErrorContext::new_missing(
24927 "OpGetlinkDumpReply",
24928 "ProtoDownReason",
24929 self.orig_loc,
24930 self.buf.as_ptr() as usize,
24931 ))
24932 }
24933 pub fn get_parent_dev_name(&self) -> Result<&'a CStr, ErrorContext> {
24934 let mut iter = self.clone();
24935 iter.pos = 0;
24936 for attr in iter {
24937 if let OpGetlinkDumpReply::ParentDevName(val) = attr? {
24938 return Ok(val);
24939 }
24940 }
24941 Err(ErrorContext::new_missing(
24942 "OpGetlinkDumpReply",
24943 "ParentDevName",
24944 self.orig_loc,
24945 self.buf.as_ptr() as usize,
24946 ))
24947 }
24948 pub fn get_parent_dev_bus_name(&self) -> Result<&'a CStr, ErrorContext> {
24949 let mut iter = self.clone();
24950 iter.pos = 0;
24951 for attr in iter {
24952 if let OpGetlinkDumpReply::ParentDevBusName(val) = attr? {
24953 return Ok(val);
24954 }
24955 }
24956 Err(ErrorContext::new_missing(
24957 "OpGetlinkDumpReply",
24958 "ParentDevBusName",
24959 self.orig_loc,
24960 self.buf.as_ptr() as usize,
24961 ))
24962 }
24963 pub fn get_gro_max_size(&self) -> Result<u32, ErrorContext> {
24964 let mut iter = self.clone();
24965 iter.pos = 0;
24966 for attr in iter {
24967 if let OpGetlinkDumpReply::GroMaxSize(val) = attr? {
24968 return Ok(val);
24969 }
24970 }
24971 Err(ErrorContext::new_missing(
24972 "OpGetlinkDumpReply",
24973 "GroMaxSize",
24974 self.orig_loc,
24975 self.buf.as_ptr() as usize,
24976 ))
24977 }
24978 pub fn get_tso_max_size(&self) -> Result<u32, ErrorContext> {
24979 let mut iter = self.clone();
24980 iter.pos = 0;
24981 for attr in iter {
24982 if let OpGetlinkDumpReply::TsoMaxSize(val) = attr? {
24983 return Ok(val);
24984 }
24985 }
24986 Err(ErrorContext::new_missing(
24987 "OpGetlinkDumpReply",
24988 "TsoMaxSize",
24989 self.orig_loc,
24990 self.buf.as_ptr() as usize,
24991 ))
24992 }
24993 pub fn get_tso_max_segs(&self) -> Result<u32, ErrorContext> {
24994 let mut iter = self.clone();
24995 iter.pos = 0;
24996 for attr in iter {
24997 if let OpGetlinkDumpReply::TsoMaxSegs(val) = attr? {
24998 return Ok(val);
24999 }
25000 }
25001 Err(ErrorContext::new_missing(
25002 "OpGetlinkDumpReply",
25003 "TsoMaxSegs",
25004 self.orig_loc,
25005 self.buf.as_ptr() as usize,
25006 ))
25007 }
25008 pub fn get_allmulti(&self) -> Result<u32, ErrorContext> {
25009 let mut iter = self.clone();
25010 iter.pos = 0;
25011 for attr in iter {
25012 if let OpGetlinkDumpReply::Allmulti(val) = attr? {
25013 return Ok(val);
25014 }
25015 }
25016 Err(ErrorContext::new_missing(
25017 "OpGetlinkDumpReply",
25018 "Allmulti",
25019 self.orig_loc,
25020 self.buf.as_ptr() as usize,
25021 ))
25022 }
25023 pub fn get_devlink_port(&self) -> Result<&'a [u8], ErrorContext> {
25024 let mut iter = self.clone();
25025 iter.pos = 0;
25026 for attr in iter {
25027 if let OpGetlinkDumpReply::DevlinkPort(val) = attr? {
25028 return Ok(val);
25029 }
25030 }
25031 Err(ErrorContext::new_missing(
25032 "OpGetlinkDumpReply",
25033 "DevlinkPort",
25034 self.orig_loc,
25035 self.buf.as_ptr() as usize,
25036 ))
25037 }
25038 pub fn get_gso_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
25039 let mut iter = self.clone();
25040 iter.pos = 0;
25041 for attr in iter {
25042 if let OpGetlinkDumpReply::GsoIpv4MaxSize(val) = attr? {
25043 return Ok(val);
25044 }
25045 }
25046 Err(ErrorContext::new_missing(
25047 "OpGetlinkDumpReply",
25048 "GsoIpv4MaxSize",
25049 self.orig_loc,
25050 self.buf.as_ptr() as usize,
25051 ))
25052 }
25053 pub fn get_gro_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
25054 let mut iter = self.clone();
25055 iter.pos = 0;
25056 for attr in iter {
25057 if let OpGetlinkDumpReply::GroIpv4MaxSize(val) = attr? {
25058 return Ok(val);
25059 }
25060 }
25061 Err(ErrorContext::new_missing(
25062 "OpGetlinkDumpReply",
25063 "GroIpv4MaxSize",
25064 self.orig_loc,
25065 self.buf.as_ptr() as usize,
25066 ))
25067 }
25068 pub fn get_dpll_pin(&self) -> Result<IterableLinkDpllPinAttrs<'a>, ErrorContext> {
25069 let mut iter = self.clone();
25070 iter.pos = 0;
25071 for attr in iter {
25072 if let OpGetlinkDumpReply::DpllPin(val) = attr? {
25073 return Ok(val);
25074 }
25075 }
25076 Err(ErrorContext::new_missing(
25077 "OpGetlinkDumpReply",
25078 "DpllPin",
25079 self.orig_loc,
25080 self.buf.as_ptr() as usize,
25081 ))
25082 }
25083 #[doc = "EDT offload horizon supported by the device (in nsec)."]
25084 pub fn get_max_pacing_offload_horizon(&self) -> Result<u32, ErrorContext> {
25085 let mut iter = self.clone();
25086 iter.pos = 0;
25087 for attr in iter {
25088 if let OpGetlinkDumpReply::MaxPacingOffloadHorizon(val) = attr? {
25089 return Ok(val);
25090 }
25091 }
25092 Err(ErrorContext::new_missing(
25093 "OpGetlinkDumpReply",
25094 "MaxPacingOffloadHorizon",
25095 self.orig_loc,
25096 self.buf.as_ptr() as usize,
25097 ))
25098 }
25099 pub fn get_netns_immutable(&self) -> Result<u8, ErrorContext> {
25100 let mut iter = self.clone();
25101 iter.pos = 0;
25102 for attr in iter {
25103 if let OpGetlinkDumpReply::NetnsImmutable(val) = attr? {
25104 return Ok(val);
25105 }
25106 }
25107 Err(ErrorContext::new_missing(
25108 "OpGetlinkDumpReply",
25109 "NetnsImmutable",
25110 self.orig_loc,
25111 self.buf.as_ptr() as usize,
25112 ))
25113 }
25114}
25115impl OpGetlinkDumpReply<'_> {
25116 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpGetlinkDumpReply<'a>) {
25117 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
25118 (
25119 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
25120 IterableOpGetlinkDumpReply::with_loc(attrs, buf.as_ptr() as usize),
25121 )
25122 }
25123 fn attr_from_type(r#type: u16) -> Option<&'static str> {
25124 LinkAttrs::attr_from_type(r#type)
25125 }
25126}
25127#[derive(Clone, Copy, Default)]
25128pub struct IterableOpGetlinkDumpReply<'a> {
25129 buf: &'a [u8],
25130 pos: usize,
25131 orig_loc: usize,
25132}
25133impl<'a> IterableOpGetlinkDumpReply<'a> {
25134 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
25135 Self {
25136 buf,
25137 pos: 0,
25138 orig_loc,
25139 }
25140 }
25141 pub fn get_buf(&self) -> &'a [u8] {
25142 self.buf
25143 }
25144}
25145impl<'a> Iterator for IterableOpGetlinkDumpReply<'a> {
25146 type Item = Result<OpGetlinkDumpReply<'a>, ErrorContext>;
25147 fn next(&mut self) -> Option<Self::Item> {
25148 if self.buf.len() == self.pos {
25149 return None;
25150 }
25151 let pos = self.pos;
25152 let mut r#type = None;
25153 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
25154 r#type = Some(header.r#type);
25155 let res = match header.r#type {
25156 1u16 => OpGetlinkDumpReply::Address({
25157 let res = Some(next);
25158 let Some(val) = res else { break };
25159 val
25160 }),
25161 2u16 => OpGetlinkDumpReply::Broadcast({
25162 let res = Some(next);
25163 let Some(val) = res else { break };
25164 val
25165 }),
25166 3u16 => OpGetlinkDumpReply::Ifname({
25167 let res = CStr::from_bytes_with_nul(next).ok();
25168 let Some(val) = res else { break };
25169 val
25170 }),
25171 4u16 => OpGetlinkDumpReply::Mtu({
25172 let res = parse_u32(next);
25173 let Some(val) = res else { break };
25174 val
25175 }),
25176 5u16 => OpGetlinkDumpReply::Link({
25177 let res = parse_u32(next);
25178 let Some(val) = res else { break };
25179 val
25180 }),
25181 6u16 => OpGetlinkDumpReply::Qdisc({
25182 let res = CStr::from_bytes_with_nul(next).ok();
25183 let Some(val) = res else { break };
25184 val
25185 }),
25186 7u16 => OpGetlinkDumpReply::Stats({
25187 let res = PushRtnlLinkStats::new_from_slice(next);
25188 let Some(val) = res else { break };
25189 val
25190 }),
25191 8u16 => OpGetlinkDumpReply::Cost({
25192 let res = CStr::from_bytes_with_nul(next).ok();
25193 let Some(val) = res else { break };
25194 val
25195 }),
25196 9u16 => OpGetlinkDumpReply::Priority({
25197 let res = CStr::from_bytes_with_nul(next).ok();
25198 let Some(val) = res else { break };
25199 val
25200 }),
25201 10u16 => OpGetlinkDumpReply::Master({
25202 let res = parse_u32(next);
25203 let Some(val) = res else { break };
25204 val
25205 }),
25206 11u16 => OpGetlinkDumpReply::Wireless({
25207 let res = CStr::from_bytes_with_nul(next).ok();
25208 let Some(val) = res else { break };
25209 val
25210 }),
25211 12u16 => OpGetlinkDumpReply::Protinfo({
25212 let res = CStr::from_bytes_with_nul(next).ok();
25213 let Some(val) = res else { break };
25214 val
25215 }),
25216 13u16 => OpGetlinkDumpReply::Txqlen({
25217 let res = parse_u32(next);
25218 let Some(val) = res else { break };
25219 val
25220 }),
25221 14u16 => OpGetlinkDumpReply::Map({
25222 let res = PushRtnlLinkIfmap::new_from_slice(next);
25223 let Some(val) = res else { break };
25224 val
25225 }),
25226 15u16 => OpGetlinkDumpReply::Weight({
25227 let res = parse_u32(next);
25228 let Some(val) = res else { break };
25229 val
25230 }),
25231 16u16 => OpGetlinkDumpReply::Operstate({
25232 let res = parse_u8(next);
25233 let Some(val) = res else { break };
25234 val
25235 }),
25236 17u16 => OpGetlinkDumpReply::Linkmode({
25237 let res = parse_u8(next);
25238 let Some(val) = res else { break };
25239 val
25240 }),
25241 18u16 => OpGetlinkDumpReply::Linkinfo({
25242 let res = Some(IterableLinkinfoAttrs::with_loc(next, self.orig_loc));
25243 let Some(val) = res else { break };
25244 val
25245 }),
25246 19u16 => OpGetlinkDumpReply::NetNsPid({
25247 let res = parse_u32(next);
25248 let Some(val) = res else { break };
25249 val
25250 }),
25251 20u16 => OpGetlinkDumpReply::Ifalias({
25252 let res = CStr::from_bytes_with_nul(next).ok();
25253 let Some(val) = res else { break };
25254 val
25255 }),
25256 21u16 => OpGetlinkDumpReply::NumVf({
25257 let res = parse_u32(next);
25258 let Some(val) = res else { break };
25259 val
25260 }),
25261 22u16 => OpGetlinkDumpReply::VfinfoList({
25262 let res = Some(IterableVfinfoListAttrs::with_loc(next, self.orig_loc));
25263 let Some(val) = res else { break };
25264 val
25265 }),
25266 23u16 => OpGetlinkDumpReply::Stats64({
25267 let res = PushRtnlLinkStats64::new_from_slice(next);
25268 let Some(val) = res else { break };
25269 val
25270 }),
25271 24u16 => OpGetlinkDumpReply::VfPorts({
25272 let res = Some(IterableVfPortsAttrs::with_loc(next, self.orig_loc));
25273 let Some(val) = res else { break };
25274 val
25275 }),
25276 25u16 => OpGetlinkDumpReply::PortSelf({
25277 let res = Some(IterablePortSelfAttrs::with_loc(next, self.orig_loc));
25278 let Some(val) = res else { break };
25279 val
25280 }),
25281 26u16 => OpGetlinkDumpReply::AfSpec({
25282 let res = Some(IterableAfSpecAttrs::with_loc(next, self.orig_loc));
25283 let Some(val) = res else { break };
25284 val
25285 }),
25286 27u16 => OpGetlinkDumpReply::Group({
25287 let res = parse_u32(next);
25288 let Some(val) = res else { break };
25289 val
25290 }),
25291 28u16 => OpGetlinkDumpReply::NetNsFd({
25292 let res = parse_u32(next);
25293 let Some(val) = res else { break };
25294 val
25295 }),
25296 29u16 => OpGetlinkDumpReply::ExtMask({
25297 let res = parse_u32(next);
25298 let Some(val) = res else { break };
25299 val
25300 }),
25301 30u16 => OpGetlinkDumpReply::Promiscuity({
25302 let res = parse_u32(next);
25303 let Some(val) = res else { break };
25304 val
25305 }),
25306 31u16 => OpGetlinkDumpReply::NumTxQueues({
25307 let res = parse_u32(next);
25308 let Some(val) = res else { break };
25309 val
25310 }),
25311 32u16 => OpGetlinkDumpReply::NumRxQueues({
25312 let res = parse_u32(next);
25313 let Some(val) = res else { break };
25314 val
25315 }),
25316 33u16 => OpGetlinkDumpReply::Carrier({
25317 let res = parse_u8(next);
25318 let Some(val) = res else { break };
25319 val
25320 }),
25321 34u16 => OpGetlinkDumpReply::PhysPortId({
25322 let res = Some(next);
25323 let Some(val) = res else { break };
25324 val
25325 }),
25326 35u16 => OpGetlinkDumpReply::CarrierChanges({
25327 let res = parse_u32(next);
25328 let Some(val) = res else { break };
25329 val
25330 }),
25331 36u16 => OpGetlinkDumpReply::PhysSwitchId({
25332 let res = Some(next);
25333 let Some(val) = res else { break };
25334 val
25335 }),
25336 37u16 => OpGetlinkDumpReply::LinkNetnsid({
25337 let res = parse_i32(next);
25338 let Some(val) = res else { break };
25339 val
25340 }),
25341 38u16 => OpGetlinkDumpReply::PhysPortName({
25342 let res = CStr::from_bytes_with_nul(next).ok();
25343 let Some(val) = res else { break };
25344 val
25345 }),
25346 39u16 => OpGetlinkDumpReply::ProtoDown({
25347 let res = parse_u8(next);
25348 let Some(val) = res else { break };
25349 val
25350 }),
25351 40u16 => OpGetlinkDumpReply::GsoMaxSegs({
25352 let res = parse_u32(next);
25353 let Some(val) = res else { break };
25354 val
25355 }),
25356 41u16 => OpGetlinkDumpReply::GsoMaxSize({
25357 let res = parse_u32(next);
25358 let Some(val) = res else { break };
25359 val
25360 }),
25361 42u16 => OpGetlinkDumpReply::Pad({
25362 let res = Some(next);
25363 let Some(val) = res else { break };
25364 val
25365 }),
25366 43u16 => OpGetlinkDumpReply::Xdp({
25367 let res = Some(IterableXdpAttrs::with_loc(next, self.orig_loc));
25368 let Some(val) = res else { break };
25369 val
25370 }),
25371 44u16 => OpGetlinkDumpReply::Event({
25372 let res = parse_u32(next);
25373 let Some(val) = res else { break };
25374 val
25375 }),
25376 45u16 => OpGetlinkDumpReply::NewNetnsid({
25377 let res = parse_i32(next);
25378 let Some(val) = res else { break };
25379 val
25380 }),
25381 46u16 => OpGetlinkDumpReply::TargetNetnsid({
25382 let res = parse_i32(next);
25383 let Some(val) = res else { break };
25384 val
25385 }),
25386 47u16 => OpGetlinkDumpReply::CarrierUpCount({
25387 let res = parse_u32(next);
25388 let Some(val) = res else { break };
25389 val
25390 }),
25391 48u16 => OpGetlinkDumpReply::CarrierDownCount({
25392 let res = parse_u32(next);
25393 let Some(val) = res else { break };
25394 val
25395 }),
25396 49u16 => OpGetlinkDumpReply::NewIfindex({
25397 let res = parse_i32(next);
25398 let Some(val) = res else { break };
25399 val
25400 }),
25401 50u16 => OpGetlinkDumpReply::MinMtu({
25402 let res = parse_u32(next);
25403 let Some(val) = res else { break };
25404 val
25405 }),
25406 51u16 => OpGetlinkDumpReply::MaxMtu({
25407 let res = parse_u32(next);
25408 let Some(val) = res else { break };
25409 val
25410 }),
25411 52u16 => OpGetlinkDumpReply::PropList({
25412 let res = Some(IterablePropListLinkAttrs::with_loc(next, self.orig_loc));
25413 let Some(val) = res else { break };
25414 val
25415 }),
25416 54u16 => OpGetlinkDumpReply::PermAddress({
25417 let res = Some(next);
25418 let Some(val) = res else { break };
25419 val
25420 }),
25421 55u16 => OpGetlinkDumpReply::ProtoDownReason({
25422 let res = CStr::from_bytes_with_nul(next).ok();
25423 let Some(val) = res else { break };
25424 val
25425 }),
25426 56u16 => OpGetlinkDumpReply::ParentDevName({
25427 let res = CStr::from_bytes_with_nul(next).ok();
25428 let Some(val) = res else { break };
25429 val
25430 }),
25431 57u16 => OpGetlinkDumpReply::ParentDevBusName({
25432 let res = CStr::from_bytes_with_nul(next).ok();
25433 let Some(val) = res else { break };
25434 val
25435 }),
25436 58u16 => OpGetlinkDumpReply::GroMaxSize({
25437 let res = parse_u32(next);
25438 let Some(val) = res else { break };
25439 val
25440 }),
25441 59u16 => OpGetlinkDumpReply::TsoMaxSize({
25442 let res = parse_u32(next);
25443 let Some(val) = res else { break };
25444 val
25445 }),
25446 60u16 => OpGetlinkDumpReply::TsoMaxSegs({
25447 let res = parse_u32(next);
25448 let Some(val) = res else { break };
25449 val
25450 }),
25451 61u16 => OpGetlinkDumpReply::Allmulti({
25452 let res = parse_u32(next);
25453 let Some(val) = res else { break };
25454 val
25455 }),
25456 62u16 => OpGetlinkDumpReply::DevlinkPort({
25457 let res = Some(next);
25458 let Some(val) = res else { break };
25459 val
25460 }),
25461 63u16 => OpGetlinkDumpReply::GsoIpv4MaxSize({
25462 let res = parse_u32(next);
25463 let Some(val) = res else { break };
25464 val
25465 }),
25466 64u16 => OpGetlinkDumpReply::GroIpv4MaxSize({
25467 let res = parse_u32(next);
25468 let Some(val) = res else { break };
25469 val
25470 }),
25471 65u16 => OpGetlinkDumpReply::DpllPin({
25472 let res = Some(IterableLinkDpllPinAttrs::with_loc(next, self.orig_loc));
25473 let Some(val) = res else { break };
25474 val
25475 }),
25476 66u16 => OpGetlinkDumpReply::MaxPacingOffloadHorizon({
25477 let res = parse_u32(next);
25478 let Some(val) = res else { break };
25479 val
25480 }),
25481 67u16 => OpGetlinkDumpReply::NetnsImmutable({
25482 let res = parse_u8(next);
25483 let Some(val) = res else { break };
25484 val
25485 }),
25486 n => {
25487 if cfg!(any(test, feature = "deny-unknown-attrs")) {
25488 break;
25489 } else {
25490 continue;
25491 }
25492 }
25493 };
25494 return Some(Ok(res));
25495 }
25496 Some(Err(ErrorContext::new(
25497 "OpGetlinkDumpReply",
25498 r#type.and_then(|t| OpGetlinkDumpReply::attr_from_type(t)),
25499 self.orig_loc,
25500 self.buf.as_ptr().wrapping_add(pos) as usize,
25501 )))
25502 }
25503}
25504impl<'a> std::fmt::Debug for IterableOpGetlinkDumpReply<'_> {
25505 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25506 let mut fmt = f.debug_struct("OpGetlinkDumpReply");
25507 for attr in self.clone() {
25508 let attr = match attr {
25509 Ok(a) => a,
25510 Err(err) => {
25511 fmt.finish()?;
25512 f.write_str("Err(")?;
25513 err.fmt(f)?;
25514 return f.write_str(")");
25515 }
25516 };
25517 match attr {
25518 OpGetlinkDumpReply::Address(val) => fmt.field("Address", &val),
25519 OpGetlinkDumpReply::Broadcast(val) => fmt.field("Broadcast", &val),
25520 OpGetlinkDumpReply::Ifname(val) => fmt.field("Ifname", &val),
25521 OpGetlinkDumpReply::Mtu(val) => fmt.field("Mtu", &val),
25522 OpGetlinkDumpReply::Link(val) => fmt.field("Link", &val),
25523 OpGetlinkDumpReply::Qdisc(val) => fmt.field("Qdisc", &val),
25524 OpGetlinkDumpReply::Stats(val) => fmt.field("Stats", &val),
25525 OpGetlinkDumpReply::Cost(val) => fmt.field("Cost", &val),
25526 OpGetlinkDumpReply::Priority(val) => fmt.field("Priority", &val),
25527 OpGetlinkDumpReply::Master(val) => fmt.field("Master", &val),
25528 OpGetlinkDumpReply::Wireless(val) => fmt.field("Wireless", &val),
25529 OpGetlinkDumpReply::Protinfo(val) => fmt.field("Protinfo", &val),
25530 OpGetlinkDumpReply::Txqlen(val) => fmt.field("Txqlen", &val),
25531 OpGetlinkDumpReply::Map(val) => fmt.field("Map", &val),
25532 OpGetlinkDumpReply::Weight(val) => fmt.field("Weight", &val),
25533 OpGetlinkDumpReply::Operstate(val) => fmt.field("Operstate", &val),
25534 OpGetlinkDumpReply::Linkmode(val) => fmt.field("Linkmode", &val),
25535 OpGetlinkDumpReply::Linkinfo(val) => fmt.field("Linkinfo", &val),
25536 OpGetlinkDumpReply::NetNsPid(val) => fmt.field("NetNsPid", &val),
25537 OpGetlinkDumpReply::Ifalias(val) => fmt.field("Ifalias", &val),
25538 OpGetlinkDumpReply::NumVf(val) => fmt.field("NumVf", &val),
25539 OpGetlinkDumpReply::VfinfoList(val) => fmt.field("VfinfoList", &val),
25540 OpGetlinkDumpReply::Stats64(val) => fmt.field("Stats64", &val),
25541 OpGetlinkDumpReply::VfPorts(val) => fmt.field("VfPorts", &val),
25542 OpGetlinkDumpReply::PortSelf(val) => fmt.field("PortSelf", &val),
25543 OpGetlinkDumpReply::AfSpec(val) => fmt.field("AfSpec", &val),
25544 OpGetlinkDumpReply::Group(val) => fmt.field("Group", &val),
25545 OpGetlinkDumpReply::NetNsFd(val) => fmt.field("NetNsFd", &val),
25546 OpGetlinkDumpReply::ExtMask(val) => {
25547 fmt.field("ExtMask", &FormatFlags(val.into(), RtextFilter::from_value))
25548 }
25549 OpGetlinkDumpReply::Promiscuity(val) => fmt.field("Promiscuity", &val),
25550 OpGetlinkDumpReply::NumTxQueues(val) => fmt.field("NumTxQueues", &val),
25551 OpGetlinkDumpReply::NumRxQueues(val) => fmt.field("NumRxQueues", &val),
25552 OpGetlinkDumpReply::Carrier(val) => fmt.field("Carrier", &val),
25553 OpGetlinkDumpReply::PhysPortId(val) => fmt.field("PhysPortId", &val),
25554 OpGetlinkDumpReply::CarrierChanges(val) => fmt.field("CarrierChanges", &val),
25555 OpGetlinkDumpReply::PhysSwitchId(val) => fmt.field("PhysSwitchId", &val),
25556 OpGetlinkDumpReply::LinkNetnsid(val) => fmt.field("LinkNetnsid", &val),
25557 OpGetlinkDumpReply::PhysPortName(val) => fmt.field("PhysPortName", &val),
25558 OpGetlinkDumpReply::ProtoDown(val) => fmt.field("ProtoDown", &val),
25559 OpGetlinkDumpReply::GsoMaxSegs(val) => fmt.field("GsoMaxSegs", &val),
25560 OpGetlinkDumpReply::GsoMaxSize(val) => fmt.field("GsoMaxSize", &val),
25561 OpGetlinkDumpReply::Pad(val) => fmt.field("Pad", &val),
25562 OpGetlinkDumpReply::Xdp(val) => fmt.field("Xdp", &val),
25563 OpGetlinkDumpReply::Event(val) => fmt.field("Event", &val),
25564 OpGetlinkDumpReply::NewNetnsid(val) => fmt.field("NewNetnsid", &val),
25565 OpGetlinkDumpReply::TargetNetnsid(val) => fmt.field("TargetNetnsid", &val),
25566 OpGetlinkDumpReply::CarrierUpCount(val) => fmt.field("CarrierUpCount", &val),
25567 OpGetlinkDumpReply::CarrierDownCount(val) => fmt.field("CarrierDownCount", &val),
25568 OpGetlinkDumpReply::NewIfindex(val) => fmt.field("NewIfindex", &val),
25569 OpGetlinkDumpReply::MinMtu(val) => fmt.field("MinMtu", &val),
25570 OpGetlinkDumpReply::MaxMtu(val) => fmt.field("MaxMtu", &val),
25571 OpGetlinkDumpReply::PropList(val) => fmt.field("PropList", &val),
25572 OpGetlinkDumpReply::PermAddress(val) => fmt.field("PermAddress", &val),
25573 OpGetlinkDumpReply::ProtoDownReason(val) => fmt.field("ProtoDownReason", &val),
25574 OpGetlinkDumpReply::ParentDevName(val) => fmt.field("ParentDevName", &val),
25575 OpGetlinkDumpReply::ParentDevBusName(val) => fmt.field("ParentDevBusName", &val),
25576 OpGetlinkDumpReply::GroMaxSize(val) => fmt.field("GroMaxSize", &val),
25577 OpGetlinkDumpReply::TsoMaxSize(val) => fmt.field("TsoMaxSize", &val),
25578 OpGetlinkDumpReply::TsoMaxSegs(val) => fmt.field("TsoMaxSegs", &val),
25579 OpGetlinkDumpReply::Allmulti(val) => fmt.field("Allmulti", &val),
25580 OpGetlinkDumpReply::DevlinkPort(val) => fmt.field("DevlinkPort", &val),
25581 OpGetlinkDumpReply::GsoIpv4MaxSize(val) => fmt.field("GsoIpv4MaxSize", &val),
25582 OpGetlinkDumpReply::GroIpv4MaxSize(val) => fmt.field("GroIpv4MaxSize", &val),
25583 OpGetlinkDumpReply::DpllPin(val) => fmt.field("DpllPin", &val),
25584 OpGetlinkDumpReply::MaxPacingOffloadHorizon(val) => {
25585 fmt.field("MaxPacingOffloadHorizon", &val)
25586 }
25587 OpGetlinkDumpReply::NetnsImmutable(val) => fmt.field("NetnsImmutable", &val),
25588 };
25589 }
25590 fmt.finish()
25591 }
25592}
25593impl IterableOpGetlinkDumpReply<'_> {
25594 pub fn lookup_attr(
25595 &self,
25596 offset: usize,
25597 missing_type: Option<u16>,
25598 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
25599 let mut stack = Vec::new();
25600 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
25601 if cur == offset + PushIfinfomsg::len() {
25602 stack.push(("OpGetlinkDumpReply", offset));
25603 return (
25604 stack,
25605 missing_type.and_then(|t| OpGetlinkDumpReply::attr_from_type(t)),
25606 );
25607 }
25608 if cur > offset || cur + self.buf.len() < offset {
25609 return (stack, None);
25610 }
25611 let mut attrs = self.clone();
25612 let mut last_off = cur + attrs.pos;
25613 let mut missing = None;
25614 while let Some(attr) = attrs.next() {
25615 let Ok(attr) = attr else { break };
25616 match attr {
25617 OpGetlinkDumpReply::Address(val) => {
25618 if last_off == offset {
25619 stack.push(("Address", last_off));
25620 break;
25621 }
25622 }
25623 OpGetlinkDumpReply::Broadcast(val) => {
25624 if last_off == offset {
25625 stack.push(("Broadcast", last_off));
25626 break;
25627 }
25628 }
25629 OpGetlinkDumpReply::Ifname(val) => {
25630 if last_off == offset {
25631 stack.push(("Ifname", last_off));
25632 break;
25633 }
25634 }
25635 OpGetlinkDumpReply::Mtu(val) => {
25636 if last_off == offset {
25637 stack.push(("Mtu", last_off));
25638 break;
25639 }
25640 }
25641 OpGetlinkDumpReply::Link(val) => {
25642 if last_off == offset {
25643 stack.push(("Link", last_off));
25644 break;
25645 }
25646 }
25647 OpGetlinkDumpReply::Qdisc(val) => {
25648 if last_off == offset {
25649 stack.push(("Qdisc", last_off));
25650 break;
25651 }
25652 }
25653 OpGetlinkDumpReply::Stats(val) => {
25654 if last_off == offset {
25655 stack.push(("Stats", last_off));
25656 break;
25657 }
25658 }
25659 OpGetlinkDumpReply::Cost(val) => {
25660 if last_off == offset {
25661 stack.push(("Cost", last_off));
25662 break;
25663 }
25664 }
25665 OpGetlinkDumpReply::Priority(val) => {
25666 if last_off == offset {
25667 stack.push(("Priority", last_off));
25668 break;
25669 }
25670 }
25671 OpGetlinkDumpReply::Master(val) => {
25672 if last_off == offset {
25673 stack.push(("Master", last_off));
25674 break;
25675 }
25676 }
25677 OpGetlinkDumpReply::Wireless(val) => {
25678 if last_off == offset {
25679 stack.push(("Wireless", last_off));
25680 break;
25681 }
25682 }
25683 OpGetlinkDumpReply::Protinfo(val) => {
25684 if last_off == offset {
25685 stack.push(("Protinfo", last_off));
25686 break;
25687 }
25688 }
25689 OpGetlinkDumpReply::Txqlen(val) => {
25690 if last_off == offset {
25691 stack.push(("Txqlen", last_off));
25692 break;
25693 }
25694 }
25695 OpGetlinkDumpReply::Map(val) => {
25696 if last_off == offset {
25697 stack.push(("Map", last_off));
25698 break;
25699 }
25700 }
25701 OpGetlinkDumpReply::Weight(val) => {
25702 if last_off == offset {
25703 stack.push(("Weight", last_off));
25704 break;
25705 }
25706 }
25707 OpGetlinkDumpReply::Operstate(val) => {
25708 if last_off == offset {
25709 stack.push(("Operstate", last_off));
25710 break;
25711 }
25712 }
25713 OpGetlinkDumpReply::Linkmode(val) => {
25714 if last_off == offset {
25715 stack.push(("Linkmode", last_off));
25716 break;
25717 }
25718 }
25719 OpGetlinkDumpReply::Linkinfo(val) => {
25720 (stack, missing) = val.lookup_attr(offset, missing_type);
25721 if !stack.is_empty() {
25722 break;
25723 }
25724 }
25725 OpGetlinkDumpReply::NetNsPid(val) => {
25726 if last_off == offset {
25727 stack.push(("NetNsPid", last_off));
25728 break;
25729 }
25730 }
25731 OpGetlinkDumpReply::Ifalias(val) => {
25732 if last_off == offset {
25733 stack.push(("Ifalias", last_off));
25734 break;
25735 }
25736 }
25737 OpGetlinkDumpReply::NumVf(val) => {
25738 if last_off == offset {
25739 stack.push(("NumVf", last_off));
25740 break;
25741 }
25742 }
25743 OpGetlinkDumpReply::VfinfoList(val) => {
25744 (stack, missing) = val.lookup_attr(offset, missing_type);
25745 if !stack.is_empty() {
25746 break;
25747 }
25748 }
25749 OpGetlinkDumpReply::Stats64(val) => {
25750 if last_off == offset {
25751 stack.push(("Stats64", last_off));
25752 break;
25753 }
25754 }
25755 OpGetlinkDumpReply::VfPorts(val) => {
25756 (stack, missing) = val.lookup_attr(offset, missing_type);
25757 if !stack.is_empty() {
25758 break;
25759 }
25760 }
25761 OpGetlinkDumpReply::PortSelf(val) => {
25762 (stack, missing) = val.lookup_attr(offset, missing_type);
25763 if !stack.is_empty() {
25764 break;
25765 }
25766 }
25767 OpGetlinkDumpReply::AfSpec(val) => {
25768 (stack, missing) = val.lookup_attr(offset, missing_type);
25769 if !stack.is_empty() {
25770 break;
25771 }
25772 }
25773 OpGetlinkDumpReply::Group(val) => {
25774 if last_off == offset {
25775 stack.push(("Group", last_off));
25776 break;
25777 }
25778 }
25779 OpGetlinkDumpReply::NetNsFd(val) => {
25780 if last_off == offset {
25781 stack.push(("NetNsFd", last_off));
25782 break;
25783 }
25784 }
25785 OpGetlinkDumpReply::ExtMask(val) => {
25786 if last_off == offset {
25787 stack.push(("ExtMask", last_off));
25788 break;
25789 }
25790 }
25791 OpGetlinkDumpReply::Promiscuity(val) => {
25792 if last_off == offset {
25793 stack.push(("Promiscuity", last_off));
25794 break;
25795 }
25796 }
25797 OpGetlinkDumpReply::NumTxQueues(val) => {
25798 if last_off == offset {
25799 stack.push(("NumTxQueues", last_off));
25800 break;
25801 }
25802 }
25803 OpGetlinkDumpReply::NumRxQueues(val) => {
25804 if last_off == offset {
25805 stack.push(("NumRxQueues", last_off));
25806 break;
25807 }
25808 }
25809 OpGetlinkDumpReply::Carrier(val) => {
25810 if last_off == offset {
25811 stack.push(("Carrier", last_off));
25812 break;
25813 }
25814 }
25815 OpGetlinkDumpReply::PhysPortId(val) => {
25816 if last_off == offset {
25817 stack.push(("PhysPortId", last_off));
25818 break;
25819 }
25820 }
25821 OpGetlinkDumpReply::CarrierChanges(val) => {
25822 if last_off == offset {
25823 stack.push(("CarrierChanges", last_off));
25824 break;
25825 }
25826 }
25827 OpGetlinkDumpReply::PhysSwitchId(val) => {
25828 if last_off == offset {
25829 stack.push(("PhysSwitchId", last_off));
25830 break;
25831 }
25832 }
25833 OpGetlinkDumpReply::LinkNetnsid(val) => {
25834 if last_off == offset {
25835 stack.push(("LinkNetnsid", last_off));
25836 break;
25837 }
25838 }
25839 OpGetlinkDumpReply::PhysPortName(val) => {
25840 if last_off == offset {
25841 stack.push(("PhysPortName", last_off));
25842 break;
25843 }
25844 }
25845 OpGetlinkDumpReply::ProtoDown(val) => {
25846 if last_off == offset {
25847 stack.push(("ProtoDown", last_off));
25848 break;
25849 }
25850 }
25851 OpGetlinkDumpReply::GsoMaxSegs(val) => {
25852 if last_off == offset {
25853 stack.push(("GsoMaxSegs", last_off));
25854 break;
25855 }
25856 }
25857 OpGetlinkDumpReply::GsoMaxSize(val) => {
25858 if last_off == offset {
25859 stack.push(("GsoMaxSize", last_off));
25860 break;
25861 }
25862 }
25863 OpGetlinkDumpReply::Pad(val) => {
25864 if last_off == offset {
25865 stack.push(("Pad", last_off));
25866 break;
25867 }
25868 }
25869 OpGetlinkDumpReply::Xdp(val) => {
25870 (stack, missing) = val.lookup_attr(offset, missing_type);
25871 if !stack.is_empty() {
25872 break;
25873 }
25874 }
25875 OpGetlinkDumpReply::Event(val) => {
25876 if last_off == offset {
25877 stack.push(("Event", last_off));
25878 break;
25879 }
25880 }
25881 OpGetlinkDumpReply::NewNetnsid(val) => {
25882 if last_off == offset {
25883 stack.push(("NewNetnsid", last_off));
25884 break;
25885 }
25886 }
25887 OpGetlinkDumpReply::TargetNetnsid(val) => {
25888 if last_off == offset {
25889 stack.push(("TargetNetnsid", last_off));
25890 break;
25891 }
25892 }
25893 OpGetlinkDumpReply::CarrierUpCount(val) => {
25894 if last_off == offset {
25895 stack.push(("CarrierUpCount", last_off));
25896 break;
25897 }
25898 }
25899 OpGetlinkDumpReply::CarrierDownCount(val) => {
25900 if last_off == offset {
25901 stack.push(("CarrierDownCount", last_off));
25902 break;
25903 }
25904 }
25905 OpGetlinkDumpReply::NewIfindex(val) => {
25906 if last_off == offset {
25907 stack.push(("NewIfindex", last_off));
25908 break;
25909 }
25910 }
25911 OpGetlinkDumpReply::MinMtu(val) => {
25912 if last_off == offset {
25913 stack.push(("MinMtu", last_off));
25914 break;
25915 }
25916 }
25917 OpGetlinkDumpReply::MaxMtu(val) => {
25918 if last_off == offset {
25919 stack.push(("MaxMtu", last_off));
25920 break;
25921 }
25922 }
25923 OpGetlinkDumpReply::PropList(val) => {
25924 (stack, missing) = val.lookup_attr(offset, missing_type);
25925 if !stack.is_empty() {
25926 break;
25927 }
25928 }
25929 OpGetlinkDumpReply::PermAddress(val) => {
25930 if last_off == offset {
25931 stack.push(("PermAddress", last_off));
25932 break;
25933 }
25934 }
25935 OpGetlinkDumpReply::ProtoDownReason(val) => {
25936 if last_off == offset {
25937 stack.push(("ProtoDownReason", last_off));
25938 break;
25939 }
25940 }
25941 OpGetlinkDumpReply::ParentDevName(val) => {
25942 if last_off == offset {
25943 stack.push(("ParentDevName", last_off));
25944 break;
25945 }
25946 }
25947 OpGetlinkDumpReply::ParentDevBusName(val) => {
25948 if last_off == offset {
25949 stack.push(("ParentDevBusName", last_off));
25950 break;
25951 }
25952 }
25953 OpGetlinkDumpReply::GroMaxSize(val) => {
25954 if last_off == offset {
25955 stack.push(("GroMaxSize", last_off));
25956 break;
25957 }
25958 }
25959 OpGetlinkDumpReply::TsoMaxSize(val) => {
25960 if last_off == offset {
25961 stack.push(("TsoMaxSize", last_off));
25962 break;
25963 }
25964 }
25965 OpGetlinkDumpReply::TsoMaxSegs(val) => {
25966 if last_off == offset {
25967 stack.push(("TsoMaxSegs", last_off));
25968 break;
25969 }
25970 }
25971 OpGetlinkDumpReply::Allmulti(val) => {
25972 if last_off == offset {
25973 stack.push(("Allmulti", last_off));
25974 break;
25975 }
25976 }
25977 OpGetlinkDumpReply::DevlinkPort(val) => {
25978 if last_off == offset {
25979 stack.push(("DevlinkPort", last_off));
25980 break;
25981 }
25982 }
25983 OpGetlinkDumpReply::GsoIpv4MaxSize(val) => {
25984 if last_off == offset {
25985 stack.push(("GsoIpv4MaxSize", last_off));
25986 break;
25987 }
25988 }
25989 OpGetlinkDumpReply::GroIpv4MaxSize(val) => {
25990 if last_off == offset {
25991 stack.push(("GroIpv4MaxSize", last_off));
25992 break;
25993 }
25994 }
25995 OpGetlinkDumpReply::DpllPin(val) => {
25996 (stack, missing) = val.lookup_attr(offset, missing_type);
25997 if !stack.is_empty() {
25998 break;
25999 }
26000 }
26001 OpGetlinkDumpReply::MaxPacingOffloadHorizon(val) => {
26002 if last_off == offset {
26003 stack.push(("MaxPacingOffloadHorizon", last_off));
26004 break;
26005 }
26006 }
26007 OpGetlinkDumpReply::NetnsImmutable(val) => {
26008 if last_off == offset {
26009 stack.push(("NetnsImmutable", last_off));
26010 break;
26011 }
26012 }
26013 _ => {}
26014 };
26015 last_off = cur + attrs.pos;
26016 }
26017 if !stack.is_empty() {
26018 stack.push(("OpGetlinkDumpReply", cur));
26019 }
26020 (stack, missing)
26021 }
26022}
26023#[derive(Debug)]
26024pub struct RequestOpGetlinkDumpRequest<'r> {
26025 request: Request<'r>,
26026}
26027impl<'r> RequestOpGetlinkDumpRequest<'r> {
26028 pub fn new(mut request: Request<'r>, header: &PushIfinfomsg) -> Self {
26029 PushOpGetlinkDumpRequest::write_header(&mut request.buf_mut(), header);
26030 Self {
26031 request: request.set_dump(),
26032 }
26033 }
26034 pub fn encode(&mut self) -> PushOpGetlinkDumpRequest<&mut Vec<u8>> {
26035 PushOpGetlinkDumpRequest::new_without_header(self.request.buf_mut())
26036 }
26037 pub fn into_encoder(self) -> PushOpGetlinkDumpRequest<RequestBuf<'r>> {
26038 PushOpGetlinkDumpRequest::new_without_header(self.request.buf)
26039 }
26040}
26041impl NetlinkRequest for RequestOpGetlinkDumpRequest<'_> {
26042 type ReplyType<'buf> = (PushIfinfomsg, IterableOpGetlinkDumpReply<'buf>);
26043 fn protocol(&self) -> Protocol {
26044 Protocol::Raw {
26045 protonum: 0u16,
26046 request_type: 18u16,
26047 }
26048 }
26049 fn flags(&self) -> u16 {
26050 self.request.flags
26051 }
26052 fn payload(&self) -> &[u8] {
26053 self.request.buf()
26054 }
26055 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
26056 OpGetlinkDumpReply::new(buf)
26057 }
26058 fn lookup(
26059 buf: &[u8],
26060 offset: usize,
26061 missing_type: Option<u16>,
26062 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
26063 OpGetlinkDumpRequest::new(buf)
26064 .1
26065 .lookup_attr(offset, missing_type)
26066 }
26067}
26068#[doc = "Get / dump information about a link."]
26069pub struct PushOpGetlinkDoRequest<Prev: Rec> {
26070 pub(crate) prev: Option<Prev>,
26071 pub(crate) header_offset: Option<usize>,
26072}
26073impl<Prev: Rec> Rec for PushOpGetlinkDoRequest<Prev> {
26074 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
26075 self.prev.as_mut().unwrap().as_rec_mut()
26076 }
26077}
26078impl<Prev: Rec> PushOpGetlinkDoRequest<Prev> {
26079 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
26080 Self::write_header(&mut prev, header);
26081 Self::new_without_header(prev)
26082 }
26083 fn new_without_header(prev: Prev) -> Self {
26084 Self {
26085 prev: Some(prev),
26086 header_offset: None,
26087 }
26088 }
26089 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
26090 prev.as_rec_mut().extend(header.as_slice());
26091 }
26092 pub fn end_nested(mut self) -> Prev {
26093 let mut prev = self.prev.take().unwrap();
26094 if let Some(header_offset) = &self.header_offset {
26095 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26096 }
26097 prev
26098 }
26099 pub fn push_ifname(mut self, value: &CStr) -> Self {
26100 push_header(
26101 self.as_rec_mut(),
26102 3u16,
26103 value.to_bytes_with_nul().len() as u16,
26104 );
26105 self.as_rec_mut().extend(value.to_bytes_with_nul());
26106 self
26107 }
26108 pub fn push_ifname_bytes(mut self, value: &[u8]) -> Self {
26109 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
26110 self.as_rec_mut().extend(value);
26111 self.as_rec_mut().push(0);
26112 self
26113 }
26114 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
26115 pub fn push_ext_mask(mut self, value: u32) -> Self {
26116 push_header(self.as_rec_mut(), 29u16, 4 as u16);
26117 self.as_rec_mut().extend(value.to_ne_bytes());
26118 self
26119 }
26120 pub fn push_target_netnsid(mut self, value: i32) -> Self {
26121 push_header(self.as_rec_mut(), 46u16, 4 as u16);
26122 self.as_rec_mut().extend(value.to_ne_bytes());
26123 self
26124 }
26125 pub fn push_alt_ifname(mut self, value: &CStr) -> Self {
26126 push_header(
26127 self.as_rec_mut(),
26128 53u16,
26129 value.to_bytes_with_nul().len() as u16,
26130 );
26131 self.as_rec_mut().extend(value.to_bytes_with_nul());
26132 self
26133 }
26134 pub fn push_alt_ifname_bytes(mut self, value: &[u8]) -> Self {
26135 push_header(self.as_rec_mut(), 53u16, (value.len() + 1) as u16);
26136 self.as_rec_mut().extend(value);
26137 self.as_rec_mut().push(0);
26138 self
26139 }
26140}
26141impl<Prev: Rec> Drop for PushOpGetlinkDoRequest<Prev> {
26142 fn drop(&mut self) {
26143 if let Some(prev) = &mut self.prev {
26144 if let Some(header_offset) = &self.header_offset {
26145 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26146 }
26147 }
26148 }
26149}
26150#[doc = "Get / dump information about a link."]
26151#[derive(Clone)]
26152pub enum OpGetlinkDoRequest<'a> {
26153 Ifname(&'a CStr),
26154 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
26155 ExtMask(u32),
26156 TargetNetnsid(i32),
26157 AltIfname(&'a CStr),
26158}
26159impl<'a> IterableOpGetlinkDoRequest<'a> {
26160 pub fn get_ifname(&self) -> Result<&'a CStr, ErrorContext> {
26161 let mut iter = self.clone();
26162 iter.pos = 0;
26163 for attr in iter {
26164 if let OpGetlinkDoRequest::Ifname(val) = attr? {
26165 return Ok(val);
26166 }
26167 }
26168 Err(ErrorContext::new_missing(
26169 "OpGetlinkDoRequest",
26170 "Ifname",
26171 self.orig_loc,
26172 self.buf.as_ptr() as usize,
26173 ))
26174 }
26175 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
26176 pub fn get_ext_mask(&self) -> Result<u32, ErrorContext> {
26177 let mut iter = self.clone();
26178 iter.pos = 0;
26179 for attr in iter {
26180 if let OpGetlinkDoRequest::ExtMask(val) = attr? {
26181 return Ok(val);
26182 }
26183 }
26184 Err(ErrorContext::new_missing(
26185 "OpGetlinkDoRequest",
26186 "ExtMask",
26187 self.orig_loc,
26188 self.buf.as_ptr() as usize,
26189 ))
26190 }
26191 pub fn get_target_netnsid(&self) -> Result<i32, ErrorContext> {
26192 let mut iter = self.clone();
26193 iter.pos = 0;
26194 for attr in iter {
26195 if let OpGetlinkDoRequest::TargetNetnsid(val) = attr? {
26196 return Ok(val);
26197 }
26198 }
26199 Err(ErrorContext::new_missing(
26200 "OpGetlinkDoRequest",
26201 "TargetNetnsid",
26202 self.orig_loc,
26203 self.buf.as_ptr() as usize,
26204 ))
26205 }
26206 pub fn get_alt_ifname(&self) -> Result<&'a CStr, ErrorContext> {
26207 let mut iter = self.clone();
26208 iter.pos = 0;
26209 for attr in iter {
26210 if let OpGetlinkDoRequest::AltIfname(val) = attr? {
26211 return Ok(val);
26212 }
26213 }
26214 Err(ErrorContext::new_missing(
26215 "OpGetlinkDoRequest",
26216 "AltIfname",
26217 self.orig_loc,
26218 self.buf.as_ptr() as usize,
26219 ))
26220 }
26221}
26222impl OpGetlinkDoRequest<'_> {
26223 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpGetlinkDoRequest<'a>) {
26224 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
26225 (
26226 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
26227 IterableOpGetlinkDoRequest::with_loc(attrs, buf.as_ptr() as usize),
26228 )
26229 }
26230 fn attr_from_type(r#type: u16) -> Option<&'static str> {
26231 LinkAttrs::attr_from_type(r#type)
26232 }
26233}
26234#[derive(Clone, Copy, Default)]
26235pub struct IterableOpGetlinkDoRequest<'a> {
26236 buf: &'a [u8],
26237 pos: usize,
26238 orig_loc: usize,
26239}
26240impl<'a> IterableOpGetlinkDoRequest<'a> {
26241 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
26242 Self {
26243 buf,
26244 pos: 0,
26245 orig_loc,
26246 }
26247 }
26248 pub fn get_buf(&self) -> &'a [u8] {
26249 self.buf
26250 }
26251}
26252impl<'a> Iterator for IterableOpGetlinkDoRequest<'a> {
26253 type Item = Result<OpGetlinkDoRequest<'a>, ErrorContext>;
26254 fn next(&mut self) -> Option<Self::Item> {
26255 if self.buf.len() == self.pos {
26256 return None;
26257 }
26258 let pos = self.pos;
26259 let mut r#type = None;
26260 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
26261 r#type = Some(header.r#type);
26262 let res = match header.r#type {
26263 3u16 => OpGetlinkDoRequest::Ifname({
26264 let res = CStr::from_bytes_with_nul(next).ok();
26265 let Some(val) = res else { break };
26266 val
26267 }),
26268 29u16 => OpGetlinkDoRequest::ExtMask({
26269 let res = parse_u32(next);
26270 let Some(val) = res else { break };
26271 val
26272 }),
26273 46u16 => OpGetlinkDoRequest::TargetNetnsid({
26274 let res = parse_i32(next);
26275 let Some(val) = res else { break };
26276 val
26277 }),
26278 53u16 => OpGetlinkDoRequest::AltIfname({
26279 let res = CStr::from_bytes_with_nul(next).ok();
26280 let Some(val) = res else { break };
26281 val
26282 }),
26283 n => {
26284 if cfg!(any(test, feature = "deny-unknown-attrs")) {
26285 break;
26286 } else {
26287 continue;
26288 }
26289 }
26290 };
26291 return Some(Ok(res));
26292 }
26293 Some(Err(ErrorContext::new(
26294 "OpGetlinkDoRequest",
26295 r#type.and_then(|t| OpGetlinkDoRequest::attr_from_type(t)),
26296 self.orig_loc,
26297 self.buf.as_ptr().wrapping_add(pos) as usize,
26298 )))
26299 }
26300}
26301impl<'a> std::fmt::Debug for IterableOpGetlinkDoRequest<'_> {
26302 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26303 let mut fmt = f.debug_struct("OpGetlinkDoRequest");
26304 for attr in self.clone() {
26305 let attr = match attr {
26306 Ok(a) => a,
26307 Err(err) => {
26308 fmt.finish()?;
26309 f.write_str("Err(")?;
26310 err.fmt(f)?;
26311 return f.write_str(")");
26312 }
26313 };
26314 match attr {
26315 OpGetlinkDoRequest::Ifname(val) => fmt.field("Ifname", &val),
26316 OpGetlinkDoRequest::ExtMask(val) => {
26317 fmt.field("ExtMask", &FormatFlags(val.into(), RtextFilter::from_value))
26318 }
26319 OpGetlinkDoRequest::TargetNetnsid(val) => fmt.field("TargetNetnsid", &val),
26320 OpGetlinkDoRequest::AltIfname(val) => fmt.field("AltIfname", &val),
26321 };
26322 }
26323 fmt.finish()
26324 }
26325}
26326impl IterableOpGetlinkDoRequest<'_> {
26327 pub fn lookup_attr(
26328 &self,
26329 offset: usize,
26330 missing_type: Option<u16>,
26331 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
26332 let mut stack = Vec::new();
26333 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
26334 if cur == offset + PushIfinfomsg::len() {
26335 stack.push(("OpGetlinkDoRequest", offset));
26336 return (
26337 stack,
26338 missing_type.and_then(|t| OpGetlinkDoRequest::attr_from_type(t)),
26339 );
26340 }
26341 if cur > offset || cur + self.buf.len() < offset {
26342 return (stack, None);
26343 }
26344 let mut attrs = self.clone();
26345 let mut last_off = cur + attrs.pos;
26346 while let Some(attr) = attrs.next() {
26347 let Ok(attr) = attr else { break };
26348 match attr {
26349 OpGetlinkDoRequest::Ifname(val) => {
26350 if last_off == offset {
26351 stack.push(("Ifname", last_off));
26352 break;
26353 }
26354 }
26355 OpGetlinkDoRequest::ExtMask(val) => {
26356 if last_off == offset {
26357 stack.push(("ExtMask", last_off));
26358 break;
26359 }
26360 }
26361 OpGetlinkDoRequest::TargetNetnsid(val) => {
26362 if last_off == offset {
26363 stack.push(("TargetNetnsid", last_off));
26364 break;
26365 }
26366 }
26367 OpGetlinkDoRequest::AltIfname(val) => {
26368 if last_off == offset {
26369 stack.push(("AltIfname", last_off));
26370 break;
26371 }
26372 }
26373 _ => {}
26374 };
26375 last_off = cur + attrs.pos;
26376 }
26377 if !stack.is_empty() {
26378 stack.push(("OpGetlinkDoRequest", cur));
26379 }
26380 (stack, None)
26381 }
26382}
26383#[doc = "Get / dump information about a link."]
26384pub struct PushOpGetlinkDoReply<Prev: Rec> {
26385 pub(crate) prev: Option<Prev>,
26386 pub(crate) header_offset: Option<usize>,
26387}
26388impl<Prev: Rec> Rec for PushOpGetlinkDoReply<Prev> {
26389 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
26390 self.prev.as_mut().unwrap().as_rec_mut()
26391 }
26392}
26393impl<Prev: Rec> PushOpGetlinkDoReply<Prev> {
26394 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
26395 Self::write_header(&mut prev, header);
26396 Self::new_without_header(prev)
26397 }
26398 fn new_without_header(prev: Prev) -> Self {
26399 Self {
26400 prev: Some(prev),
26401 header_offset: None,
26402 }
26403 }
26404 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
26405 prev.as_rec_mut().extend(header.as_slice());
26406 }
26407 pub fn end_nested(mut self) -> Prev {
26408 let mut prev = self.prev.take().unwrap();
26409 if let Some(header_offset) = &self.header_offset {
26410 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26411 }
26412 prev
26413 }
26414 pub fn push_address(mut self, value: &[u8]) -> Self {
26415 push_header(self.as_rec_mut(), 1u16, value.len() as u16);
26416 self.as_rec_mut().extend(value);
26417 self
26418 }
26419 pub fn push_broadcast(mut self, value: &[u8]) -> Self {
26420 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
26421 self.as_rec_mut().extend(value);
26422 self
26423 }
26424 pub fn push_ifname(mut self, value: &CStr) -> Self {
26425 push_header(
26426 self.as_rec_mut(),
26427 3u16,
26428 value.to_bytes_with_nul().len() as u16,
26429 );
26430 self.as_rec_mut().extend(value.to_bytes_with_nul());
26431 self
26432 }
26433 pub fn push_ifname_bytes(mut self, value: &[u8]) -> Self {
26434 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
26435 self.as_rec_mut().extend(value);
26436 self.as_rec_mut().push(0);
26437 self
26438 }
26439 pub fn push_mtu(mut self, value: u32) -> Self {
26440 push_header(self.as_rec_mut(), 4u16, 4 as u16);
26441 self.as_rec_mut().extend(value.to_ne_bytes());
26442 self
26443 }
26444 pub fn push_link(mut self, value: u32) -> Self {
26445 push_header(self.as_rec_mut(), 5u16, 4 as u16);
26446 self.as_rec_mut().extend(value.to_ne_bytes());
26447 self
26448 }
26449 pub fn push_qdisc(mut self, value: &CStr) -> Self {
26450 push_header(
26451 self.as_rec_mut(),
26452 6u16,
26453 value.to_bytes_with_nul().len() as u16,
26454 );
26455 self.as_rec_mut().extend(value.to_bytes_with_nul());
26456 self
26457 }
26458 pub fn push_qdisc_bytes(mut self, value: &[u8]) -> Self {
26459 push_header(self.as_rec_mut(), 6u16, (value.len() + 1) as u16);
26460 self.as_rec_mut().extend(value);
26461 self.as_rec_mut().push(0);
26462 self
26463 }
26464 pub fn push_stats(mut self, value: PushRtnlLinkStats) -> Self {
26465 push_header(self.as_rec_mut(), 7u16, value.as_slice().len() as u16);
26466 self.as_rec_mut().extend(value.as_slice());
26467 self
26468 }
26469 pub fn push_cost(mut self, value: &CStr) -> Self {
26470 push_header(
26471 self.as_rec_mut(),
26472 8u16,
26473 value.to_bytes_with_nul().len() as u16,
26474 );
26475 self.as_rec_mut().extend(value.to_bytes_with_nul());
26476 self
26477 }
26478 pub fn push_cost_bytes(mut self, value: &[u8]) -> Self {
26479 push_header(self.as_rec_mut(), 8u16, (value.len() + 1) as u16);
26480 self.as_rec_mut().extend(value);
26481 self.as_rec_mut().push(0);
26482 self
26483 }
26484 pub fn push_priority(mut self, value: &CStr) -> Self {
26485 push_header(
26486 self.as_rec_mut(),
26487 9u16,
26488 value.to_bytes_with_nul().len() as u16,
26489 );
26490 self.as_rec_mut().extend(value.to_bytes_with_nul());
26491 self
26492 }
26493 pub fn push_priority_bytes(mut self, value: &[u8]) -> Self {
26494 push_header(self.as_rec_mut(), 9u16, (value.len() + 1) as u16);
26495 self.as_rec_mut().extend(value);
26496 self.as_rec_mut().push(0);
26497 self
26498 }
26499 pub fn push_master(mut self, value: u32) -> Self {
26500 push_header(self.as_rec_mut(), 10u16, 4 as u16);
26501 self.as_rec_mut().extend(value.to_ne_bytes());
26502 self
26503 }
26504 pub fn push_wireless(mut self, value: &CStr) -> Self {
26505 push_header(
26506 self.as_rec_mut(),
26507 11u16,
26508 value.to_bytes_with_nul().len() as u16,
26509 );
26510 self.as_rec_mut().extend(value.to_bytes_with_nul());
26511 self
26512 }
26513 pub fn push_wireless_bytes(mut self, value: &[u8]) -> Self {
26514 push_header(self.as_rec_mut(), 11u16, (value.len() + 1) as u16);
26515 self.as_rec_mut().extend(value);
26516 self.as_rec_mut().push(0);
26517 self
26518 }
26519 pub fn push_protinfo(mut self, value: &CStr) -> Self {
26520 push_header(
26521 self.as_rec_mut(),
26522 12u16,
26523 value.to_bytes_with_nul().len() as u16,
26524 );
26525 self.as_rec_mut().extend(value.to_bytes_with_nul());
26526 self
26527 }
26528 pub fn push_protinfo_bytes(mut self, value: &[u8]) -> Self {
26529 push_header(self.as_rec_mut(), 12u16, (value.len() + 1) as u16);
26530 self.as_rec_mut().extend(value);
26531 self.as_rec_mut().push(0);
26532 self
26533 }
26534 pub fn push_txqlen(mut self, value: u32) -> Self {
26535 push_header(self.as_rec_mut(), 13u16, 4 as u16);
26536 self.as_rec_mut().extend(value.to_ne_bytes());
26537 self
26538 }
26539 pub fn push_map(mut self, value: PushRtnlLinkIfmap) -> Self {
26540 push_header(self.as_rec_mut(), 14u16, value.as_slice().len() as u16);
26541 self.as_rec_mut().extend(value.as_slice());
26542 self
26543 }
26544 pub fn push_weight(mut self, value: u32) -> Self {
26545 push_header(self.as_rec_mut(), 15u16, 4 as u16);
26546 self.as_rec_mut().extend(value.to_ne_bytes());
26547 self
26548 }
26549 pub fn push_operstate(mut self, value: u8) -> Self {
26550 push_header(self.as_rec_mut(), 16u16, 1 as u16);
26551 self.as_rec_mut().extend(value.to_ne_bytes());
26552 self
26553 }
26554 pub fn push_linkmode(mut self, value: u8) -> Self {
26555 push_header(self.as_rec_mut(), 17u16, 1 as u16);
26556 self.as_rec_mut().extend(value.to_ne_bytes());
26557 self
26558 }
26559 pub fn nested_linkinfo(mut self) -> PushLinkinfoAttrs<Self> {
26560 let header_offset = push_nested_header(self.as_rec_mut(), 18u16);
26561 PushLinkinfoAttrs {
26562 prev: Some(self),
26563 header_offset: Some(header_offset),
26564 }
26565 }
26566 pub fn push_net_ns_pid(mut self, value: u32) -> Self {
26567 push_header(self.as_rec_mut(), 19u16, 4 as u16);
26568 self.as_rec_mut().extend(value.to_ne_bytes());
26569 self
26570 }
26571 pub fn push_ifalias(mut self, value: &CStr) -> Self {
26572 push_header(
26573 self.as_rec_mut(),
26574 20u16,
26575 value.to_bytes_with_nul().len() as u16,
26576 );
26577 self.as_rec_mut().extend(value.to_bytes_with_nul());
26578 self
26579 }
26580 pub fn push_ifalias_bytes(mut self, value: &[u8]) -> Self {
26581 push_header(self.as_rec_mut(), 20u16, (value.len() + 1) as u16);
26582 self.as_rec_mut().extend(value);
26583 self.as_rec_mut().push(0);
26584 self
26585 }
26586 pub fn push_num_vf(mut self, value: u32) -> Self {
26587 push_header(self.as_rec_mut(), 21u16, 4 as u16);
26588 self.as_rec_mut().extend(value.to_ne_bytes());
26589 self
26590 }
26591 pub fn nested_vfinfo_list(mut self) -> PushVfinfoListAttrs<Self> {
26592 let header_offset = push_nested_header(self.as_rec_mut(), 22u16);
26593 PushVfinfoListAttrs {
26594 prev: Some(self),
26595 header_offset: Some(header_offset),
26596 }
26597 }
26598 pub fn push_stats64(mut self, value: PushRtnlLinkStats64) -> Self {
26599 push_header(self.as_rec_mut(), 23u16, value.as_slice().len() as u16);
26600 self.as_rec_mut().extend(value.as_slice());
26601 self
26602 }
26603 pub fn nested_vf_ports(mut self) -> PushVfPortsAttrs<Self> {
26604 let header_offset = push_nested_header(self.as_rec_mut(), 24u16);
26605 PushVfPortsAttrs {
26606 prev: Some(self),
26607 header_offset: Some(header_offset),
26608 }
26609 }
26610 pub fn nested_port_self(mut self) -> PushPortSelfAttrs<Self> {
26611 let header_offset = push_nested_header(self.as_rec_mut(), 25u16);
26612 PushPortSelfAttrs {
26613 prev: Some(self),
26614 header_offset: Some(header_offset),
26615 }
26616 }
26617 pub fn nested_af_spec(mut self) -> PushAfSpecAttrs<Self> {
26618 let header_offset = push_nested_header(self.as_rec_mut(), 26u16);
26619 PushAfSpecAttrs {
26620 prev: Some(self),
26621 header_offset: Some(header_offset),
26622 }
26623 }
26624 pub fn push_group(mut self, value: u32) -> Self {
26625 push_header(self.as_rec_mut(), 27u16, 4 as u16);
26626 self.as_rec_mut().extend(value.to_ne_bytes());
26627 self
26628 }
26629 pub fn push_net_ns_fd(mut self, value: u32) -> Self {
26630 push_header(self.as_rec_mut(), 28u16, 4 as u16);
26631 self.as_rec_mut().extend(value.to_ne_bytes());
26632 self
26633 }
26634 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
26635 pub fn push_ext_mask(mut self, value: u32) -> Self {
26636 push_header(self.as_rec_mut(), 29u16, 4 as u16);
26637 self.as_rec_mut().extend(value.to_ne_bytes());
26638 self
26639 }
26640 pub fn push_promiscuity(mut self, value: u32) -> Self {
26641 push_header(self.as_rec_mut(), 30u16, 4 as u16);
26642 self.as_rec_mut().extend(value.to_ne_bytes());
26643 self
26644 }
26645 pub fn push_num_tx_queues(mut self, value: u32) -> Self {
26646 push_header(self.as_rec_mut(), 31u16, 4 as u16);
26647 self.as_rec_mut().extend(value.to_ne_bytes());
26648 self
26649 }
26650 pub fn push_num_rx_queues(mut self, value: u32) -> Self {
26651 push_header(self.as_rec_mut(), 32u16, 4 as u16);
26652 self.as_rec_mut().extend(value.to_ne_bytes());
26653 self
26654 }
26655 pub fn push_carrier(mut self, value: u8) -> Self {
26656 push_header(self.as_rec_mut(), 33u16, 1 as u16);
26657 self.as_rec_mut().extend(value.to_ne_bytes());
26658 self
26659 }
26660 pub fn push_phys_port_id(mut self, value: &[u8]) -> Self {
26661 push_header(self.as_rec_mut(), 34u16, value.len() as u16);
26662 self.as_rec_mut().extend(value);
26663 self
26664 }
26665 pub fn push_carrier_changes(mut self, value: u32) -> Self {
26666 push_header(self.as_rec_mut(), 35u16, 4 as u16);
26667 self.as_rec_mut().extend(value.to_ne_bytes());
26668 self
26669 }
26670 pub fn push_phys_switch_id(mut self, value: &[u8]) -> Self {
26671 push_header(self.as_rec_mut(), 36u16, value.len() as u16);
26672 self.as_rec_mut().extend(value);
26673 self
26674 }
26675 pub fn push_link_netnsid(mut self, value: i32) -> Self {
26676 push_header(self.as_rec_mut(), 37u16, 4 as u16);
26677 self.as_rec_mut().extend(value.to_ne_bytes());
26678 self
26679 }
26680 pub fn push_phys_port_name(mut self, value: &CStr) -> Self {
26681 push_header(
26682 self.as_rec_mut(),
26683 38u16,
26684 value.to_bytes_with_nul().len() as u16,
26685 );
26686 self.as_rec_mut().extend(value.to_bytes_with_nul());
26687 self
26688 }
26689 pub fn push_phys_port_name_bytes(mut self, value: &[u8]) -> Self {
26690 push_header(self.as_rec_mut(), 38u16, (value.len() + 1) as u16);
26691 self.as_rec_mut().extend(value);
26692 self.as_rec_mut().push(0);
26693 self
26694 }
26695 pub fn push_proto_down(mut self, value: u8) -> Self {
26696 push_header(self.as_rec_mut(), 39u16, 1 as u16);
26697 self.as_rec_mut().extend(value.to_ne_bytes());
26698 self
26699 }
26700 pub fn push_gso_max_segs(mut self, value: u32) -> Self {
26701 push_header(self.as_rec_mut(), 40u16, 4 as u16);
26702 self.as_rec_mut().extend(value.to_ne_bytes());
26703 self
26704 }
26705 pub fn push_gso_max_size(mut self, value: u32) -> Self {
26706 push_header(self.as_rec_mut(), 41u16, 4 as u16);
26707 self.as_rec_mut().extend(value.to_ne_bytes());
26708 self
26709 }
26710 pub fn push_pad(mut self, value: &[u8]) -> Self {
26711 push_header(self.as_rec_mut(), 42u16, value.len() as u16);
26712 self.as_rec_mut().extend(value);
26713 self
26714 }
26715 pub fn nested_xdp(mut self) -> PushXdpAttrs<Self> {
26716 let header_offset = push_nested_header(self.as_rec_mut(), 43u16);
26717 PushXdpAttrs {
26718 prev: Some(self),
26719 header_offset: Some(header_offset),
26720 }
26721 }
26722 pub fn push_event(mut self, value: u32) -> Self {
26723 push_header(self.as_rec_mut(), 44u16, 4 as u16);
26724 self.as_rec_mut().extend(value.to_ne_bytes());
26725 self
26726 }
26727 pub fn push_new_netnsid(mut self, value: i32) -> Self {
26728 push_header(self.as_rec_mut(), 45u16, 4 as u16);
26729 self.as_rec_mut().extend(value.to_ne_bytes());
26730 self
26731 }
26732 pub fn push_target_netnsid(mut self, value: i32) -> Self {
26733 push_header(self.as_rec_mut(), 46u16, 4 as u16);
26734 self.as_rec_mut().extend(value.to_ne_bytes());
26735 self
26736 }
26737 pub fn push_carrier_up_count(mut self, value: u32) -> Self {
26738 push_header(self.as_rec_mut(), 47u16, 4 as u16);
26739 self.as_rec_mut().extend(value.to_ne_bytes());
26740 self
26741 }
26742 pub fn push_carrier_down_count(mut self, value: u32) -> Self {
26743 push_header(self.as_rec_mut(), 48u16, 4 as u16);
26744 self.as_rec_mut().extend(value.to_ne_bytes());
26745 self
26746 }
26747 pub fn push_new_ifindex(mut self, value: i32) -> Self {
26748 push_header(self.as_rec_mut(), 49u16, 4 as u16);
26749 self.as_rec_mut().extend(value.to_ne_bytes());
26750 self
26751 }
26752 pub fn push_min_mtu(mut self, value: u32) -> Self {
26753 push_header(self.as_rec_mut(), 50u16, 4 as u16);
26754 self.as_rec_mut().extend(value.to_ne_bytes());
26755 self
26756 }
26757 pub fn push_max_mtu(mut self, value: u32) -> Self {
26758 push_header(self.as_rec_mut(), 51u16, 4 as u16);
26759 self.as_rec_mut().extend(value.to_ne_bytes());
26760 self
26761 }
26762 pub fn nested_prop_list(mut self) -> PushPropListLinkAttrs<Self> {
26763 let header_offset = push_nested_header(self.as_rec_mut(), 52u16);
26764 PushPropListLinkAttrs {
26765 prev: Some(self),
26766 header_offset: Some(header_offset),
26767 }
26768 }
26769 pub fn push_perm_address(mut self, value: &[u8]) -> Self {
26770 push_header(self.as_rec_mut(), 54u16, value.len() as u16);
26771 self.as_rec_mut().extend(value);
26772 self
26773 }
26774 pub fn push_proto_down_reason(mut self, value: &CStr) -> Self {
26775 push_header(
26776 self.as_rec_mut(),
26777 55u16,
26778 value.to_bytes_with_nul().len() as u16,
26779 );
26780 self.as_rec_mut().extend(value.to_bytes_with_nul());
26781 self
26782 }
26783 pub fn push_proto_down_reason_bytes(mut self, value: &[u8]) -> Self {
26784 push_header(self.as_rec_mut(), 55u16, (value.len() + 1) as u16);
26785 self.as_rec_mut().extend(value);
26786 self.as_rec_mut().push(0);
26787 self
26788 }
26789 pub fn push_parent_dev_name(mut self, value: &CStr) -> Self {
26790 push_header(
26791 self.as_rec_mut(),
26792 56u16,
26793 value.to_bytes_with_nul().len() as u16,
26794 );
26795 self.as_rec_mut().extend(value.to_bytes_with_nul());
26796 self
26797 }
26798 pub fn push_parent_dev_name_bytes(mut self, value: &[u8]) -> Self {
26799 push_header(self.as_rec_mut(), 56u16, (value.len() + 1) as u16);
26800 self.as_rec_mut().extend(value);
26801 self.as_rec_mut().push(0);
26802 self
26803 }
26804 pub fn push_parent_dev_bus_name(mut self, value: &CStr) -> Self {
26805 push_header(
26806 self.as_rec_mut(),
26807 57u16,
26808 value.to_bytes_with_nul().len() as u16,
26809 );
26810 self.as_rec_mut().extend(value.to_bytes_with_nul());
26811 self
26812 }
26813 pub fn push_parent_dev_bus_name_bytes(mut self, value: &[u8]) -> Self {
26814 push_header(self.as_rec_mut(), 57u16, (value.len() + 1) as u16);
26815 self.as_rec_mut().extend(value);
26816 self.as_rec_mut().push(0);
26817 self
26818 }
26819 pub fn push_gro_max_size(mut self, value: u32) -> Self {
26820 push_header(self.as_rec_mut(), 58u16, 4 as u16);
26821 self.as_rec_mut().extend(value.to_ne_bytes());
26822 self
26823 }
26824 pub fn push_tso_max_size(mut self, value: u32) -> Self {
26825 push_header(self.as_rec_mut(), 59u16, 4 as u16);
26826 self.as_rec_mut().extend(value.to_ne_bytes());
26827 self
26828 }
26829 pub fn push_tso_max_segs(mut self, value: u32) -> Self {
26830 push_header(self.as_rec_mut(), 60u16, 4 as u16);
26831 self.as_rec_mut().extend(value.to_ne_bytes());
26832 self
26833 }
26834 pub fn push_allmulti(mut self, value: u32) -> Self {
26835 push_header(self.as_rec_mut(), 61u16, 4 as u16);
26836 self.as_rec_mut().extend(value.to_ne_bytes());
26837 self
26838 }
26839 pub fn push_devlink_port(mut self, value: &[u8]) -> Self {
26840 push_header(self.as_rec_mut(), 62u16, value.len() as u16);
26841 self.as_rec_mut().extend(value);
26842 self
26843 }
26844 pub fn push_gso_ipv4_max_size(mut self, value: u32) -> Self {
26845 push_header(self.as_rec_mut(), 63u16, 4 as u16);
26846 self.as_rec_mut().extend(value.to_ne_bytes());
26847 self
26848 }
26849 pub fn push_gro_ipv4_max_size(mut self, value: u32) -> Self {
26850 push_header(self.as_rec_mut(), 64u16, 4 as u16);
26851 self.as_rec_mut().extend(value.to_ne_bytes());
26852 self
26853 }
26854 pub fn nested_dpll_pin(mut self) -> PushLinkDpllPinAttrs<Self> {
26855 let header_offset = push_nested_header(self.as_rec_mut(), 65u16);
26856 PushLinkDpllPinAttrs {
26857 prev: Some(self),
26858 header_offset: Some(header_offset),
26859 }
26860 }
26861 #[doc = "EDT offload horizon supported by the device (in nsec)."]
26862 pub fn push_max_pacing_offload_horizon(mut self, value: u32) -> Self {
26863 push_header(self.as_rec_mut(), 66u16, 4 as u16);
26864 self.as_rec_mut().extend(value.to_ne_bytes());
26865 self
26866 }
26867 pub fn push_netns_immutable(mut self, value: u8) -> Self {
26868 push_header(self.as_rec_mut(), 67u16, 1 as u16);
26869 self.as_rec_mut().extend(value.to_ne_bytes());
26870 self
26871 }
26872}
26873impl<Prev: Rec> Drop for PushOpGetlinkDoReply<Prev> {
26874 fn drop(&mut self) {
26875 if let Some(prev) = &mut self.prev {
26876 if let Some(header_offset) = &self.header_offset {
26877 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26878 }
26879 }
26880 }
26881}
26882#[doc = "Get / dump information about a link."]
26883#[derive(Clone)]
26884pub enum OpGetlinkDoReply<'a> {
26885 Address(&'a [u8]),
26886 Broadcast(&'a [u8]),
26887 Ifname(&'a CStr),
26888 Mtu(u32),
26889 Link(u32),
26890 Qdisc(&'a CStr),
26891 Stats(PushRtnlLinkStats),
26892 Cost(&'a CStr),
26893 Priority(&'a CStr),
26894 Master(u32),
26895 Wireless(&'a CStr),
26896 Protinfo(&'a CStr),
26897 Txqlen(u32),
26898 Map(PushRtnlLinkIfmap),
26899 Weight(u32),
26900 Operstate(u8),
26901 Linkmode(u8),
26902 Linkinfo(IterableLinkinfoAttrs<'a>),
26903 NetNsPid(u32),
26904 Ifalias(&'a CStr),
26905 NumVf(u32),
26906 VfinfoList(IterableVfinfoListAttrs<'a>),
26907 Stats64(PushRtnlLinkStats64),
26908 VfPorts(IterableVfPortsAttrs<'a>),
26909 PortSelf(IterablePortSelfAttrs<'a>),
26910 AfSpec(IterableAfSpecAttrs<'a>),
26911 Group(u32),
26912 NetNsFd(u32),
26913 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
26914 ExtMask(u32),
26915 Promiscuity(u32),
26916 NumTxQueues(u32),
26917 NumRxQueues(u32),
26918 Carrier(u8),
26919 PhysPortId(&'a [u8]),
26920 CarrierChanges(u32),
26921 PhysSwitchId(&'a [u8]),
26922 LinkNetnsid(i32),
26923 PhysPortName(&'a CStr),
26924 ProtoDown(u8),
26925 GsoMaxSegs(u32),
26926 GsoMaxSize(u32),
26927 Pad(&'a [u8]),
26928 Xdp(IterableXdpAttrs<'a>),
26929 Event(u32),
26930 NewNetnsid(i32),
26931 TargetNetnsid(i32),
26932 CarrierUpCount(u32),
26933 CarrierDownCount(u32),
26934 NewIfindex(i32),
26935 MinMtu(u32),
26936 MaxMtu(u32),
26937 PropList(IterablePropListLinkAttrs<'a>),
26938 PermAddress(&'a [u8]),
26939 ProtoDownReason(&'a CStr),
26940 ParentDevName(&'a CStr),
26941 ParentDevBusName(&'a CStr),
26942 GroMaxSize(u32),
26943 TsoMaxSize(u32),
26944 TsoMaxSegs(u32),
26945 Allmulti(u32),
26946 DevlinkPort(&'a [u8]),
26947 GsoIpv4MaxSize(u32),
26948 GroIpv4MaxSize(u32),
26949 DpllPin(IterableLinkDpllPinAttrs<'a>),
26950 #[doc = "EDT offload horizon supported by the device (in nsec)."]
26951 MaxPacingOffloadHorizon(u32),
26952 NetnsImmutable(u8),
26953}
26954impl<'a> IterableOpGetlinkDoReply<'a> {
26955 pub fn get_address(&self) -> Result<&'a [u8], ErrorContext> {
26956 let mut iter = self.clone();
26957 iter.pos = 0;
26958 for attr in iter {
26959 if let OpGetlinkDoReply::Address(val) = attr? {
26960 return Ok(val);
26961 }
26962 }
26963 Err(ErrorContext::new_missing(
26964 "OpGetlinkDoReply",
26965 "Address",
26966 self.orig_loc,
26967 self.buf.as_ptr() as usize,
26968 ))
26969 }
26970 pub fn get_broadcast(&self) -> Result<&'a [u8], ErrorContext> {
26971 let mut iter = self.clone();
26972 iter.pos = 0;
26973 for attr in iter {
26974 if let OpGetlinkDoReply::Broadcast(val) = attr? {
26975 return Ok(val);
26976 }
26977 }
26978 Err(ErrorContext::new_missing(
26979 "OpGetlinkDoReply",
26980 "Broadcast",
26981 self.orig_loc,
26982 self.buf.as_ptr() as usize,
26983 ))
26984 }
26985 pub fn get_ifname(&self) -> Result<&'a CStr, ErrorContext> {
26986 let mut iter = self.clone();
26987 iter.pos = 0;
26988 for attr in iter {
26989 if let OpGetlinkDoReply::Ifname(val) = attr? {
26990 return Ok(val);
26991 }
26992 }
26993 Err(ErrorContext::new_missing(
26994 "OpGetlinkDoReply",
26995 "Ifname",
26996 self.orig_loc,
26997 self.buf.as_ptr() as usize,
26998 ))
26999 }
27000 pub fn get_mtu(&self) -> Result<u32, ErrorContext> {
27001 let mut iter = self.clone();
27002 iter.pos = 0;
27003 for attr in iter {
27004 if let OpGetlinkDoReply::Mtu(val) = attr? {
27005 return Ok(val);
27006 }
27007 }
27008 Err(ErrorContext::new_missing(
27009 "OpGetlinkDoReply",
27010 "Mtu",
27011 self.orig_loc,
27012 self.buf.as_ptr() as usize,
27013 ))
27014 }
27015 pub fn get_link(&self) -> Result<u32, ErrorContext> {
27016 let mut iter = self.clone();
27017 iter.pos = 0;
27018 for attr in iter {
27019 if let OpGetlinkDoReply::Link(val) = attr? {
27020 return Ok(val);
27021 }
27022 }
27023 Err(ErrorContext::new_missing(
27024 "OpGetlinkDoReply",
27025 "Link",
27026 self.orig_loc,
27027 self.buf.as_ptr() as usize,
27028 ))
27029 }
27030 pub fn get_qdisc(&self) -> Result<&'a CStr, ErrorContext> {
27031 let mut iter = self.clone();
27032 iter.pos = 0;
27033 for attr in iter {
27034 if let OpGetlinkDoReply::Qdisc(val) = attr? {
27035 return Ok(val);
27036 }
27037 }
27038 Err(ErrorContext::new_missing(
27039 "OpGetlinkDoReply",
27040 "Qdisc",
27041 self.orig_loc,
27042 self.buf.as_ptr() as usize,
27043 ))
27044 }
27045 pub fn get_stats(&self) -> Result<PushRtnlLinkStats, ErrorContext> {
27046 let mut iter = self.clone();
27047 iter.pos = 0;
27048 for attr in iter {
27049 if let OpGetlinkDoReply::Stats(val) = attr? {
27050 return Ok(val);
27051 }
27052 }
27053 Err(ErrorContext::new_missing(
27054 "OpGetlinkDoReply",
27055 "Stats",
27056 self.orig_loc,
27057 self.buf.as_ptr() as usize,
27058 ))
27059 }
27060 pub fn get_cost(&self) -> Result<&'a CStr, ErrorContext> {
27061 let mut iter = self.clone();
27062 iter.pos = 0;
27063 for attr in iter {
27064 if let OpGetlinkDoReply::Cost(val) = attr? {
27065 return Ok(val);
27066 }
27067 }
27068 Err(ErrorContext::new_missing(
27069 "OpGetlinkDoReply",
27070 "Cost",
27071 self.orig_loc,
27072 self.buf.as_ptr() as usize,
27073 ))
27074 }
27075 pub fn get_priority(&self) -> Result<&'a CStr, ErrorContext> {
27076 let mut iter = self.clone();
27077 iter.pos = 0;
27078 for attr in iter {
27079 if let OpGetlinkDoReply::Priority(val) = attr? {
27080 return Ok(val);
27081 }
27082 }
27083 Err(ErrorContext::new_missing(
27084 "OpGetlinkDoReply",
27085 "Priority",
27086 self.orig_loc,
27087 self.buf.as_ptr() as usize,
27088 ))
27089 }
27090 pub fn get_master(&self) -> Result<u32, ErrorContext> {
27091 let mut iter = self.clone();
27092 iter.pos = 0;
27093 for attr in iter {
27094 if let OpGetlinkDoReply::Master(val) = attr? {
27095 return Ok(val);
27096 }
27097 }
27098 Err(ErrorContext::new_missing(
27099 "OpGetlinkDoReply",
27100 "Master",
27101 self.orig_loc,
27102 self.buf.as_ptr() as usize,
27103 ))
27104 }
27105 pub fn get_wireless(&self) -> Result<&'a CStr, ErrorContext> {
27106 let mut iter = self.clone();
27107 iter.pos = 0;
27108 for attr in iter {
27109 if let OpGetlinkDoReply::Wireless(val) = attr? {
27110 return Ok(val);
27111 }
27112 }
27113 Err(ErrorContext::new_missing(
27114 "OpGetlinkDoReply",
27115 "Wireless",
27116 self.orig_loc,
27117 self.buf.as_ptr() as usize,
27118 ))
27119 }
27120 pub fn get_protinfo(&self) -> Result<&'a CStr, ErrorContext> {
27121 let mut iter = self.clone();
27122 iter.pos = 0;
27123 for attr in iter {
27124 if let OpGetlinkDoReply::Protinfo(val) = attr? {
27125 return Ok(val);
27126 }
27127 }
27128 Err(ErrorContext::new_missing(
27129 "OpGetlinkDoReply",
27130 "Protinfo",
27131 self.orig_loc,
27132 self.buf.as_ptr() as usize,
27133 ))
27134 }
27135 pub fn get_txqlen(&self) -> Result<u32, ErrorContext> {
27136 let mut iter = self.clone();
27137 iter.pos = 0;
27138 for attr in iter {
27139 if let OpGetlinkDoReply::Txqlen(val) = attr? {
27140 return Ok(val);
27141 }
27142 }
27143 Err(ErrorContext::new_missing(
27144 "OpGetlinkDoReply",
27145 "Txqlen",
27146 self.orig_loc,
27147 self.buf.as_ptr() as usize,
27148 ))
27149 }
27150 pub fn get_map(&self) -> Result<PushRtnlLinkIfmap, ErrorContext> {
27151 let mut iter = self.clone();
27152 iter.pos = 0;
27153 for attr in iter {
27154 if let OpGetlinkDoReply::Map(val) = attr? {
27155 return Ok(val);
27156 }
27157 }
27158 Err(ErrorContext::new_missing(
27159 "OpGetlinkDoReply",
27160 "Map",
27161 self.orig_loc,
27162 self.buf.as_ptr() as usize,
27163 ))
27164 }
27165 pub fn get_weight(&self) -> Result<u32, ErrorContext> {
27166 let mut iter = self.clone();
27167 iter.pos = 0;
27168 for attr in iter {
27169 if let OpGetlinkDoReply::Weight(val) = attr? {
27170 return Ok(val);
27171 }
27172 }
27173 Err(ErrorContext::new_missing(
27174 "OpGetlinkDoReply",
27175 "Weight",
27176 self.orig_loc,
27177 self.buf.as_ptr() as usize,
27178 ))
27179 }
27180 pub fn get_operstate(&self) -> Result<u8, ErrorContext> {
27181 let mut iter = self.clone();
27182 iter.pos = 0;
27183 for attr in iter {
27184 if let OpGetlinkDoReply::Operstate(val) = attr? {
27185 return Ok(val);
27186 }
27187 }
27188 Err(ErrorContext::new_missing(
27189 "OpGetlinkDoReply",
27190 "Operstate",
27191 self.orig_loc,
27192 self.buf.as_ptr() as usize,
27193 ))
27194 }
27195 pub fn get_linkmode(&self) -> Result<u8, ErrorContext> {
27196 let mut iter = self.clone();
27197 iter.pos = 0;
27198 for attr in iter {
27199 if let OpGetlinkDoReply::Linkmode(val) = attr? {
27200 return Ok(val);
27201 }
27202 }
27203 Err(ErrorContext::new_missing(
27204 "OpGetlinkDoReply",
27205 "Linkmode",
27206 self.orig_loc,
27207 self.buf.as_ptr() as usize,
27208 ))
27209 }
27210 pub fn get_linkinfo(&self) -> Result<IterableLinkinfoAttrs<'a>, ErrorContext> {
27211 let mut iter = self.clone();
27212 iter.pos = 0;
27213 for attr in iter {
27214 if let OpGetlinkDoReply::Linkinfo(val) = attr? {
27215 return Ok(val);
27216 }
27217 }
27218 Err(ErrorContext::new_missing(
27219 "OpGetlinkDoReply",
27220 "Linkinfo",
27221 self.orig_loc,
27222 self.buf.as_ptr() as usize,
27223 ))
27224 }
27225 pub fn get_net_ns_pid(&self) -> Result<u32, ErrorContext> {
27226 let mut iter = self.clone();
27227 iter.pos = 0;
27228 for attr in iter {
27229 if let OpGetlinkDoReply::NetNsPid(val) = attr? {
27230 return Ok(val);
27231 }
27232 }
27233 Err(ErrorContext::new_missing(
27234 "OpGetlinkDoReply",
27235 "NetNsPid",
27236 self.orig_loc,
27237 self.buf.as_ptr() as usize,
27238 ))
27239 }
27240 pub fn get_ifalias(&self) -> Result<&'a CStr, ErrorContext> {
27241 let mut iter = self.clone();
27242 iter.pos = 0;
27243 for attr in iter {
27244 if let OpGetlinkDoReply::Ifalias(val) = attr? {
27245 return Ok(val);
27246 }
27247 }
27248 Err(ErrorContext::new_missing(
27249 "OpGetlinkDoReply",
27250 "Ifalias",
27251 self.orig_loc,
27252 self.buf.as_ptr() as usize,
27253 ))
27254 }
27255 pub fn get_num_vf(&self) -> Result<u32, ErrorContext> {
27256 let mut iter = self.clone();
27257 iter.pos = 0;
27258 for attr in iter {
27259 if let OpGetlinkDoReply::NumVf(val) = attr? {
27260 return Ok(val);
27261 }
27262 }
27263 Err(ErrorContext::new_missing(
27264 "OpGetlinkDoReply",
27265 "NumVf",
27266 self.orig_loc,
27267 self.buf.as_ptr() as usize,
27268 ))
27269 }
27270 pub fn get_vfinfo_list(&self) -> Result<IterableVfinfoListAttrs<'a>, ErrorContext> {
27271 let mut iter = self.clone();
27272 iter.pos = 0;
27273 for attr in iter {
27274 if let OpGetlinkDoReply::VfinfoList(val) = attr? {
27275 return Ok(val);
27276 }
27277 }
27278 Err(ErrorContext::new_missing(
27279 "OpGetlinkDoReply",
27280 "VfinfoList",
27281 self.orig_loc,
27282 self.buf.as_ptr() as usize,
27283 ))
27284 }
27285 pub fn get_stats64(&self) -> Result<PushRtnlLinkStats64, ErrorContext> {
27286 let mut iter = self.clone();
27287 iter.pos = 0;
27288 for attr in iter {
27289 if let OpGetlinkDoReply::Stats64(val) = attr? {
27290 return Ok(val);
27291 }
27292 }
27293 Err(ErrorContext::new_missing(
27294 "OpGetlinkDoReply",
27295 "Stats64",
27296 self.orig_loc,
27297 self.buf.as_ptr() as usize,
27298 ))
27299 }
27300 pub fn get_vf_ports(&self) -> Result<IterableVfPortsAttrs<'a>, ErrorContext> {
27301 let mut iter = self.clone();
27302 iter.pos = 0;
27303 for attr in iter {
27304 if let OpGetlinkDoReply::VfPorts(val) = attr? {
27305 return Ok(val);
27306 }
27307 }
27308 Err(ErrorContext::new_missing(
27309 "OpGetlinkDoReply",
27310 "VfPorts",
27311 self.orig_loc,
27312 self.buf.as_ptr() as usize,
27313 ))
27314 }
27315 pub fn get_port_self(&self) -> Result<IterablePortSelfAttrs<'a>, ErrorContext> {
27316 let mut iter = self.clone();
27317 iter.pos = 0;
27318 for attr in iter {
27319 if let OpGetlinkDoReply::PortSelf(val) = attr? {
27320 return Ok(val);
27321 }
27322 }
27323 Err(ErrorContext::new_missing(
27324 "OpGetlinkDoReply",
27325 "PortSelf",
27326 self.orig_loc,
27327 self.buf.as_ptr() as usize,
27328 ))
27329 }
27330 pub fn get_af_spec(&self) -> Result<IterableAfSpecAttrs<'a>, ErrorContext> {
27331 let mut iter = self.clone();
27332 iter.pos = 0;
27333 for attr in iter {
27334 if let OpGetlinkDoReply::AfSpec(val) = attr? {
27335 return Ok(val);
27336 }
27337 }
27338 Err(ErrorContext::new_missing(
27339 "OpGetlinkDoReply",
27340 "AfSpec",
27341 self.orig_loc,
27342 self.buf.as_ptr() as usize,
27343 ))
27344 }
27345 pub fn get_group(&self) -> Result<u32, ErrorContext> {
27346 let mut iter = self.clone();
27347 iter.pos = 0;
27348 for attr in iter {
27349 if let OpGetlinkDoReply::Group(val) = attr? {
27350 return Ok(val);
27351 }
27352 }
27353 Err(ErrorContext::new_missing(
27354 "OpGetlinkDoReply",
27355 "Group",
27356 self.orig_loc,
27357 self.buf.as_ptr() as usize,
27358 ))
27359 }
27360 pub fn get_net_ns_fd(&self) -> Result<u32, ErrorContext> {
27361 let mut iter = self.clone();
27362 iter.pos = 0;
27363 for attr in iter {
27364 if let OpGetlinkDoReply::NetNsFd(val) = attr? {
27365 return Ok(val);
27366 }
27367 }
27368 Err(ErrorContext::new_missing(
27369 "OpGetlinkDoReply",
27370 "NetNsFd",
27371 self.orig_loc,
27372 self.buf.as_ptr() as usize,
27373 ))
27374 }
27375 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
27376 pub fn get_ext_mask(&self) -> Result<u32, ErrorContext> {
27377 let mut iter = self.clone();
27378 iter.pos = 0;
27379 for attr in iter {
27380 if let OpGetlinkDoReply::ExtMask(val) = attr? {
27381 return Ok(val);
27382 }
27383 }
27384 Err(ErrorContext::new_missing(
27385 "OpGetlinkDoReply",
27386 "ExtMask",
27387 self.orig_loc,
27388 self.buf.as_ptr() as usize,
27389 ))
27390 }
27391 pub fn get_promiscuity(&self) -> Result<u32, ErrorContext> {
27392 let mut iter = self.clone();
27393 iter.pos = 0;
27394 for attr in iter {
27395 if let OpGetlinkDoReply::Promiscuity(val) = attr? {
27396 return Ok(val);
27397 }
27398 }
27399 Err(ErrorContext::new_missing(
27400 "OpGetlinkDoReply",
27401 "Promiscuity",
27402 self.orig_loc,
27403 self.buf.as_ptr() as usize,
27404 ))
27405 }
27406 pub fn get_num_tx_queues(&self) -> Result<u32, ErrorContext> {
27407 let mut iter = self.clone();
27408 iter.pos = 0;
27409 for attr in iter {
27410 if let OpGetlinkDoReply::NumTxQueues(val) = attr? {
27411 return Ok(val);
27412 }
27413 }
27414 Err(ErrorContext::new_missing(
27415 "OpGetlinkDoReply",
27416 "NumTxQueues",
27417 self.orig_loc,
27418 self.buf.as_ptr() as usize,
27419 ))
27420 }
27421 pub fn get_num_rx_queues(&self) -> Result<u32, ErrorContext> {
27422 let mut iter = self.clone();
27423 iter.pos = 0;
27424 for attr in iter {
27425 if let OpGetlinkDoReply::NumRxQueues(val) = attr? {
27426 return Ok(val);
27427 }
27428 }
27429 Err(ErrorContext::new_missing(
27430 "OpGetlinkDoReply",
27431 "NumRxQueues",
27432 self.orig_loc,
27433 self.buf.as_ptr() as usize,
27434 ))
27435 }
27436 pub fn get_carrier(&self) -> Result<u8, ErrorContext> {
27437 let mut iter = self.clone();
27438 iter.pos = 0;
27439 for attr in iter {
27440 if let OpGetlinkDoReply::Carrier(val) = attr? {
27441 return Ok(val);
27442 }
27443 }
27444 Err(ErrorContext::new_missing(
27445 "OpGetlinkDoReply",
27446 "Carrier",
27447 self.orig_loc,
27448 self.buf.as_ptr() as usize,
27449 ))
27450 }
27451 pub fn get_phys_port_id(&self) -> Result<&'a [u8], ErrorContext> {
27452 let mut iter = self.clone();
27453 iter.pos = 0;
27454 for attr in iter {
27455 if let OpGetlinkDoReply::PhysPortId(val) = attr? {
27456 return Ok(val);
27457 }
27458 }
27459 Err(ErrorContext::new_missing(
27460 "OpGetlinkDoReply",
27461 "PhysPortId",
27462 self.orig_loc,
27463 self.buf.as_ptr() as usize,
27464 ))
27465 }
27466 pub fn get_carrier_changes(&self) -> Result<u32, ErrorContext> {
27467 let mut iter = self.clone();
27468 iter.pos = 0;
27469 for attr in iter {
27470 if let OpGetlinkDoReply::CarrierChanges(val) = attr? {
27471 return Ok(val);
27472 }
27473 }
27474 Err(ErrorContext::new_missing(
27475 "OpGetlinkDoReply",
27476 "CarrierChanges",
27477 self.orig_loc,
27478 self.buf.as_ptr() as usize,
27479 ))
27480 }
27481 pub fn get_phys_switch_id(&self) -> Result<&'a [u8], ErrorContext> {
27482 let mut iter = self.clone();
27483 iter.pos = 0;
27484 for attr in iter {
27485 if let OpGetlinkDoReply::PhysSwitchId(val) = attr? {
27486 return Ok(val);
27487 }
27488 }
27489 Err(ErrorContext::new_missing(
27490 "OpGetlinkDoReply",
27491 "PhysSwitchId",
27492 self.orig_loc,
27493 self.buf.as_ptr() as usize,
27494 ))
27495 }
27496 pub fn get_link_netnsid(&self) -> Result<i32, ErrorContext> {
27497 let mut iter = self.clone();
27498 iter.pos = 0;
27499 for attr in iter {
27500 if let OpGetlinkDoReply::LinkNetnsid(val) = attr? {
27501 return Ok(val);
27502 }
27503 }
27504 Err(ErrorContext::new_missing(
27505 "OpGetlinkDoReply",
27506 "LinkNetnsid",
27507 self.orig_loc,
27508 self.buf.as_ptr() as usize,
27509 ))
27510 }
27511 pub fn get_phys_port_name(&self) -> Result<&'a CStr, ErrorContext> {
27512 let mut iter = self.clone();
27513 iter.pos = 0;
27514 for attr in iter {
27515 if let OpGetlinkDoReply::PhysPortName(val) = attr? {
27516 return Ok(val);
27517 }
27518 }
27519 Err(ErrorContext::new_missing(
27520 "OpGetlinkDoReply",
27521 "PhysPortName",
27522 self.orig_loc,
27523 self.buf.as_ptr() as usize,
27524 ))
27525 }
27526 pub fn get_proto_down(&self) -> Result<u8, ErrorContext> {
27527 let mut iter = self.clone();
27528 iter.pos = 0;
27529 for attr in iter {
27530 if let OpGetlinkDoReply::ProtoDown(val) = attr? {
27531 return Ok(val);
27532 }
27533 }
27534 Err(ErrorContext::new_missing(
27535 "OpGetlinkDoReply",
27536 "ProtoDown",
27537 self.orig_loc,
27538 self.buf.as_ptr() as usize,
27539 ))
27540 }
27541 pub fn get_gso_max_segs(&self) -> Result<u32, ErrorContext> {
27542 let mut iter = self.clone();
27543 iter.pos = 0;
27544 for attr in iter {
27545 if let OpGetlinkDoReply::GsoMaxSegs(val) = attr? {
27546 return Ok(val);
27547 }
27548 }
27549 Err(ErrorContext::new_missing(
27550 "OpGetlinkDoReply",
27551 "GsoMaxSegs",
27552 self.orig_loc,
27553 self.buf.as_ptr() as usize,
27554 ))
27555 }
27556 pub fn get_gso_max_size(&self) -> Result<u32, ErrorContext> {
27557 let mut iter = self.clone();
27558 iter.pos = 0;
27559 for attr in iter {
27560 if let OpGetlinkDoReply::GsoMaxSize(val) = attr? {
27561 return Ok(val);
27562 }
27563 }
27564 Err(ErrorContext::new_missing(
27565 "OpGetlinkDoReply",
27566 "GsoMaxSize",
27567 self.orig_loc,
27568 self.buf.as_ptr() as usize,
27569 ))
27570 }
27571 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
27572 let mut iter = self.clone();
27573 iter.pos = 0;
27574 for attr in iter {
27575 if let OpGetlinkDoReply::Pad(val) = attr? {
27576 return Ok(val);
27577 }
27578 }
27579 Err(ErrorContext::new_missing(
27580 "OpGetlinkDoReply",
27581 "Pad",
27582 self.orig_loc,
27583 self.buf.as_ptr() as usize,
27584 ))
27585 }
27586 pub fn get_xdp(&self) -> Result<IterableXdpAttrs<'a>, ErrorContext> {
27587 let mut iter = self.clone();
27588 iter.pos = 0;
27589 for attr in iter {
27590 if let OpGetlinkDoReply::Xdp(val) = attr? {
27591 return Ok(val);
27592 }
27593 }
27594 Err(ErrorContext::new_missing(
27595 "OpGetlinkDoReply",
27596 "Xdp",
27597 self.orig_loc,
27598 self.buf.as_ptr() as usize,
27599 ))
27600 }
27601 pub fn get_event(&self) -> Result<u32, ErrorContext> {
27602 let mut iter = self.clone();
27603 iter.pos = 0;
27604 for attr in iter {
27605 if let OpGetlinkDoReply::Event(val) = attr? {
27606 return Ok(val);
27607 }
27608 }
27609 Err(ErrorContext::new_missing(
27610 "OpGetlinkDoReply",
27611 "Event",
27612 self.orig_loc,
27613 self.buf.as_ptr() as usize,
27614 ))
27615 }
27616 pub fn get_new_netnsid(&self) -> Result<i32, ErrorContext> {
27617 let mut iter = self.clone();
27618 iter.pos = 0;
27619 for attr in iter {
27620 if let OpGetlinkDoReply::NewNetnsid(val) = attr? {
27621 return Ok(val);
27622 }
27623 }
27624 Err(ErrorContext::new_missing(
27625 "OpGetlinkDoReply",
27626 "NewNetnsid",
27627 self.orig_loc,
27628 self.buf.as_ptr() as usize,
27629 ))
27630 }
27631 pub fn get_target_netnsid(&self) -> Result<i32, ErrorContext> {
27632 let mut iter = self.clone();
27633 iter.pos = 0;
27634 for attr in iter {
27635 if let OpGetlinkDoReply::TargetNetnsid(val) = attr? {
27636 return Ok(val);
27637 }
27638 }
27639 Err(ErrorContext::new_missing(
27640 "OpGetlinkDoReply",
27641 "TargetNetnsid",
27642 self.orig_loc,
27643 self.buf.as_ptr() as usize,
27644 ))
27645 }
27646 pub fn get_carrier_up_count(&self) -> Result<u32, ErrorContext> {
27647 let mut iter = self.clone();
27648 iter.pos = 0;
27649 for attr in iter {
27650 if let OpGetlinkDoReply::CarrierUpCount(val) = attr? {
27651 return Ok(val);
27652 }
27653 }
27654 Err(ErrorContext::new_missing(
27655 "OpGetlinkDoReply",
27656 "CarrierUpCount",
27657 self.orig_loc,
27658 self.buf.as_ptr() as usize,
27659 ))
27660 }
27661 pub fn get_carrier_down_count(&self) -> Result<u32, ErrorContext> {
27662 let mut iter = self.clone();
27663 iter.pos = 0;
27664 for attr in iter {
27665 if let OpGetlinkDoReply::CarrierDownCount(val) = attr? {
27666 return Ok(val);
27667 }
27668 }
27669 Err(ErrorContext::new_missing(
27670 "OpGetlinkDoReply",
27671 "CarrierDownCount",
27672 self.orig_loc,
27673 self.buf.as_ptr() as usize,
27674 ))
27675 }
27676 pub fn get_new_ifindex(&self) -> Result<i32, ErrorContext> {
27677 let mut iter = self.clone();
27678 iter.pos = 0;
27679 for attr in iter {
27680 if let OpGetlinkDoReply::NewIfindex(val) = attr? {
27681 return Ok(val);
27682 }
27683 }
27684 Err(ErrorContext::new_missing(
27685 "OpGetlinkDoReply",
27686 "NewIfindex",
27687 self.orig_loc,
27688 self.buf.as_ptr() as usize,
27689 ))
27690 }
27691 pub fn get_min_mtu(&self) -> Result<u32, ErrorContext> {
27692 let mut iter = self.clone();
27693 iter.pos = 0;
27694 for attr in iter {
27695 if let OpGetlinkDoReply::MinMtu(val) = attr? {
27696 return Ok(val);
27697 }
27698 }
27699 Err(ErrorContext::new_missing(
27700 "OpGetlinkDoReply",
27701 "MinMtu",
27702 self.orig_loc,
27703 self.buf.as_ptr() as usize,
27704 ))
27705 }
27706 pub fn get_max_mtu(&self) -> Result<u32, ErrorContext> {
27707 let mut iter = self.clone();
27708 iter.pos = 0;
27709 for attr in iter {
27710 if let OpGetlinkDoReply::MaxMtu(val) = attr? {
27711 return Ok(val);
27712 }
27713 }
27714 Err(ErrorContext::new_missing(
27715 "OpGetlinkDoReply",
27716 "MaxMtu",
27717 self.orig_loc,
27718 self.buf.as_ptr() as usize,
27719 ))
27720 }
27721 pub fn get_prop_list(&self) -> Result<IterablePropListLinkAttrs<'a>, ErrorContext> {
27722 let mut iter = self.clone();
27723 iter.pos = 0;
27724 for attr in iter {
27725 if let OpGetlinkDoReply::PropList(val) = attr? {
27726 return Ok(val);
27727 }
27728 }
27729 Err(ErrorContext::new_missing(
27730 "OpGetlinkDoReply",
27731 "PropList",
27732 self.orig_loc,
27733 self.buf.as_ptr() as usize,
27734 ))
27735 }
27736 pub fn get_perm_address(&self) -> Result<&'a [u8], ErrorContext> {
27737 let mut iter = self.clone();
27738 iter.pos = 0;
27739 for attr in iter {
27740 if let OpGetlinkDoReply::PermAddress(val) = attr? {
27741 return Ok(val);
27742 }
27743 }
27744 Err(ErrorContext::new_missing(
27745 "OpGetlinkDoReply",
27746 "PermAddress",
27747 self.orig_loc,
27748 self.buf.as_ptr() as usize,
27749 ))
27750 }
27751 pub fn get_proto_down_reason(&self) -> Result<&'a CStr, ErrorContext> {
27752 let mut iter = self.clone();
27753 iter.pos = 0;
27754 for attr in iter {
27755 if let OpGetlinkDoReply::ProtoDownReason(val) = attr? {
27756 return Ok(val);
27757 }
27758 }
27759 Err(ErrorContext::new_missing(
27760 "OpGetlinkDoReply",
27761 "ProtoDownReason",
27762 self.orig_loc,
27763 self.buf.as_ptr() as usize,
27764 ))
27765 }
27766 pub fn get_parent_dev_name(&self) -> Result<&'a CStr, ErrorContext> {
27767 let mut iter = self.clone();
27768 iter.pos = 0;
27769 for attr in iter {
27770 if let OpGetlinkDoReply::ParentDevName(val) = attr? {
27771 return Ok(val);
27772 }
27773 }
27774 Err(ErrorContext::new_missing(
27775 "OpGetlinkDoReply",
27776 "ParentDevName",
27777 self.orig_loc,
27778 self.buf.as_ptr() as usize,
27779 ))
27780 }
27781 pub fn get_parent_dev_bus_name(&self) -> Result<&'a CStr, ErrorContext> {
27782 let mut iter = self.clone();
27783 iter.pos = 0;
27784 for attr in iter {
27785 if let OpGetlinkDoReply::ParentDevBusName(val) = attr? {
27786 return Ok(val);
27787 }
27788 }
27789 Err(ErrorContext::new_missing(
27790 "OpGetlinkDoReply",
27791 "ParentDevBusName",
27792 self.orig_loc,
27793 self.buf.as_ptr() as usize,
27794 ))
27795 }
27796 pub fn get_gro_max_size(&self) -> Result<u32, ErrorContext> {
27797 let mut iter = self.clone();
27798 iter.pos = 0;
27799 for attr in iter {
27800 if let OpGetlinkDoReply::GroMaxSize(val) = attr? {
27801 return Ok(val);
27802 }
27803 }
27804 Err(ErrorContext::new_missing(
27805 "OpGetlinkDoReply",
27806 "GroMaxSize",
27807 self.orig_loc,
27808 self.buf.as_ptr() as usize,
27809 ))
27810 }
27811 pub fn get_tso_max_size(&self) -> Result<u32, ErrorContext> {
27812 let mut iter = self.clone();
27813 iter.pos = 0;
27814 for attr in iter {
27815 if let OpGetlinkDoReply::TsoMaxSize(val) = attr? {
27816 return Ok(val);
27817 }
27818 }
27819 Err(ErrorContext::new_missing(
27820 "OpGetlinkDoReply",
27821 "TsoMaxSize",
27822 self.orig_loc,
27823 self.buf.as_ptr() as usize,
27824 ))
27825 }
27826 pub fn get_tso_max_segs(&self) -> Result<u32, ErrorContext> {
27827 let mut iter = self.clone();
27828 iter.pos = 0;
27829 for attr in iter {
27830 if let OpGetlinkDoReply::TsoMaxSegs(val) = attr? {
27831 return Ok(val);
27832 }
27833 }
27834 Err(ErrorContext::new_missing(
27835 "OpGetlinkDoReply",
27836 "TsoMaxSegs",
27837 self.orig_loc,
27838 self.buf.as_ptr() as usize,
27839 ))
27840 }
27841 pub fn get_allmulti(&self) -> Result<u32, ErrorContext> {
27842 let mut iter = self.clone();
27843 iter.pos = 0;
27844 for attr in iter {
27845 if let OpGetlinkDoReply::Allmulti(val) = attr? {
27846 return Ok(val);
27847 }
27848 }
27849 Err(ErrorContext::new_missing(
27850 "OpGetlinkDoReply",
27851 "Allmulti",
27852 self.orig_loc,
27853 self.buf.as_ptr() as usize,
27854 ))
27855 }
27856 pub fn get_devlink_port(&self) -> Result<&'a [u8], ErrorContext> {
27857 let mut iter = self.clone();
27858 iter.pos = 0;
27859 for attr in iter {
27860 if let OpGetlinkDoReply::DevlinkPort(val) = attr? {
27861 return Ok(val);
27862 }
27863 }
27864 Err(ErrorContext::new_missing(
27865 "OpGetlinkDoReply",
27866 "DevlinkPort",
27867 self.orig_loc,
27868 self.buf.as_ptr() as usize,
27869 ))
27870 }
27871 pub fn get_gso_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
27872 let mut iter = self.clone();
27873 iter.pos = 0;
27874 for attr in iter {
27875 if let OpGetlinkDoReply::GsoIpv4MaxSize(val) = attr? {
27876 return Ok(val);
27877 }
27878 }
27879 Err(ErrorContext::new_missing(
27880 "OpGetlinkDoReply",
27881 "GsoIpv4MaxSize",
27882 self.orig_loc,
27883 self.buf.as_ptr() as usize,
27884 ))
27885 }
27886 pub fn get_gro_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
27887 let mut iter = self.clone();
27888 iter.pos = 0;
27889 for attr in iter {
27890 if let OpGetlinkDoReply::GroIpv4MaxSize(val) = attr? {
27891 return Ok(val);
27892 }
27893 }
27894 Err(ErrorContext::new_missing(
27895 "OpGetlinkDoReply",
27896 "GroIpv4MaxSize",
27897 self.orig_loc,
27898 self.buf.as_ptr() as usize,
27899 ))
27900 }
27901 pub fn get_dpll_pin(&self) -> Result<IterableLinkDpllPinAttrs<'a>, ErrorContext> {
27902 let mut iter = self.clone();
27903 iter.pos = 0;
27904 for attr in iter {
27905 if let OpGetlinkDoReply::DpllPin(val) = attr? {
27906 return Ok(val);
27907 }
27908 }
27909 Err(ErrorContext::new_missing(
27910 "OpGetlinkDoReply",
27911 "DpllPin",
27912 self.orig_loc,
27913 self.buf.as_ptr() as usize,
27914 ))
27915 }
27916 #[doc = "EDT offload horizon supported by the device (in nsec)."]
27917 pub fn get_max_pacing_offload_horizon(&self) -> Result<u32, ErrorContext> {
27918 let mut iter = self.clone();
27919 iter.pos = 0;
27920 for attr in iter {
27921 if let OpGetlinkDoReply::MaxPacingOffloadHorizon(val) = attr? {
27922 return Ok(val);
27923 }
27924 }
27925 Err(ErrorContext::new_missing(
27926 "OpGetlinkDoReply",
27927 "MaxPacingOffloadHorizon",
27928 self.orig_loc,
27929 self.buf.as_ptr() as usize,
27930 ))
27931 }
27932 pub fn get_netns_immutable(&self) -> Result<u8, ErrorContext> {
27933 let mut iter = self.clone();
27934 iter.pos = 0;
27935 for attr in iter {
27936 if let OpGetlinkDoReply::NetnsImmutable(val) = attr? {
27937 return Ok(val);
27938 }
27939 }
27940 Err(ErrorContext::new_missing(
27941 "OpGetlinkDoReply",
27942 "NetnsImmutable",
27943 self.orig_loc,
27944 self.buf.as_ptr() as usize,
27945 ))
27946 }
27947}
27948impl OpGetlinkDoReply<'_> {
27949 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpGetlinkDoReply<'a>) {
27950 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
27951 (
27952 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
27953 IterableOpGetlinkDoReply::with_loc(attrs, buf.as_ptr() as usize),
27954 )
27955 }
27956 fn attr_from_type(r#type: u16) -> Option<&'static str> {
27957 LinkAttrs::attr_from_type(r#type)
27958 }
27959}
27960#[derive(Clone, Copy, Default)]
27961pub struct IterableOpGetlinkDoReply<'a> {
27962 buf: &'a [u8],
27963 pos: usize,
27964 orig_loc: usize,
27965}
27966impl<'a> IterableOpGetlinkDoReply<'a> {
27967 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
27968 Self {
27969 buf,
27970 pos: 0,
27971 orig_loc,
27972 }
27973 }
27974 pub fn get_buf(&self) -> &'a [u8] {
27975 self.buf
27976 }
27977}
27978impl<'a> Iterator for IterableOpGetlinkDoReply<'a> {
27979 type Item = Result<OpGetlinkDoReply<'a>, ErrorContext>;
27980 fn next(&mut self) -> Option<Self::Item> {
27981 if self.buf.len() == self.pos {
27982 return None;
27983 }
27984 let pos = self.pos;
27985 let mut r#type = None;
27986 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
27987 r#type = Some(header.r#type);
27988 let res = match header.r#type {
27989 1u16 => OpGetlinkDoReply::Address({
27990 let res = Some(next);
27991 let Some(val) = res else { break };
27992 val
27993 }),
27994 2u16 => OpGetlinkDoReply::Broadcast({
27995 let res = Some(next);
27996 let Some(val) = res else { break };
27997 val
27998 }),
27999 3u16 => OpGetlinkDoReply::Ifname({
28000 let res = CStr::from_bytes_with_nul(next).ok();
28001 let Some(val) = res else { break };
28002 val
28003 }),
28004 4u16 => OpGetlinkDoReply::Mtu({
28005 let res = parse_u32(next);
28006 let Some(val) = res else { break };
28007 val
28008 }),
28009 5u16 => OpGetlinkDoReply::Link({
28010 let res = parse_u32(next);
28011 let Some(val) = res else { break };
28012 val
28013 }),
28014 6u16 => OpGetlinkDoReply::Qdisc({
28015 let res = CStr::from_bytes_with_nul(next).ok();
28016 let Some(val) = res else { break };
28017 val
28018 }),
28019 7u16 => OpGetlinkDoReply::Stats({
28020 let res = PushRtnlLinkStats::new_from_slice(next);
28021 let Some(val) = res else { break };
28022 val
28023 }),
28024 8u16 => OpGetlinkDoReply::Cost({
28025 let res = CStr::from_bytes_with_nul(next).ok();
28026 let Some(val) = res else { break };
28027 val
28028 }),
28029 9u16 => OpGetlinkDoReply::Priority({
28030 let res = CStr::from_bytes_with_nul(next).ok();
28031 let Some(val) = res else { break };
28032 val
28033 }),
28034 10u16 => OpGetlinkDoReply::Master({
28035 let res = parse_u32(next);
28036 let Some(val) = res else { break };
28037 val
28038 }),
28039 11u16 => OpGetlinkDoReply::Wireless({
28040 let res = CStr::from_bytes_with_nul(next).ok();
28041 let Some(val) = res else { break };
28042 val
28043 }),
28044 12u16 => OpGetlinkDoReply::Protinfo({
28045 let res = CStr::from_bytes_with_nul(next).ok();
28046 let Some(val) = res else { break };
28047 val
28048 }),
28049 13u16 => OpGetlinkDoReply::Txqlen({
28050 let res = parse_u32(next);
28051 let Some(val) = res else { break };
28052 val
28053 }),
28054 14u16 => OpGetlinkDoReply::Map({
28055 let res = PushRtnlLinkIfmap::new_from_slice(next);
28056 let Some(val) = res else { break };
28057 val
28058 }),
28059 15u16 => OpGetlinkDoReply::Weight({
28060 let res = parse_u32(next);
28061 let Some(val) = res else { break };
28062 val
28063 }),
28064 16u16 => OpGetlinkDoReply::Operstate({
28065 let res = parse_u8(next);
28066 let Some(val) = res else { break };
28067 val
28068 }),
28069 17u16 => OpGetlinkDoReply::Linkmode({
28070 let res = parse_u8(next);
28071 let Some(val) = res else { break };
28072 val
28073 }),
28074 18u16 => OpGetlinkDoReply::Linkinfo({
28075 let res = Some(IterableLinkinfoAttrs::with_loc(next, self.orig_loc));
28076 let Some(val) = res else { break };
28077 val
28078 }),
28079 19u16 => OpGetlinkDoReply::NetNsPid({
28080 let res = parse_u32(next);
28081 let Some(val) = res else { break };
28082 val
28083 }),
28084 20u16 => OpGetlinkDoReply::Ifalias({
28085 let res = CStr::from_bytes_with_nul(next).ok();
28086 let Some(val) = res else { break };
28087 val
28088 }),
28089 21u16 => OpGetlinkDoReply::NumVf({
28090 let res = parse_u32(next);
28091 let Some(val) = res else { break };
28092 val
28093 }),
28094 22u16 => OpGetlinkDoReply::VfinfoList({
28095 let res = Some(IterableVfinfoListAttrs::with_loc(next, self.orig_loc));
28096 let Some(val) = res else { break };
28097 val
28098 }),
28099 23u16 => OpGetlinkDoReply::Stats64({
28100 let res = PushRtnlLinkStats64::new_from_slice(next);
28101 let Some(val) = res else { break };
28102 val
28103 }),
28104 24u16 => OpGetlinkDoReply::VfPorts({
28105 let res = Some(IterableVfPortsAttrs::with_loc(next, self.orig_loc));
28106 let Some(val) = res else { break };
28107 val
28108 }),
28109 25u16 => OpGetlinkDoReply::PortSelf({
28110 let res = Some(IterablePortSelfAttrs::with_loc(next, self.orig_loc));
28111 let Some(val) = res else { break };
28112 val
28113 }),
28114 26u16 => OpGetlinkDoReply::AfSpec({
28115 let res = Some(IterableAfSpecAttrs::with_loc(next, self.orig_loc));
28116 let Some(val) = res else { break };
28117 val
28118 }),
28119 27u16 => OpGetlinkDoReply::Group({
28120 let res = parse_u32(next);
28121 let Some(val) = res else { break };
28122 val
28123 }),
28124 28u16 => OpGetlinkDoReply::NetNsFd({
28125 let res = parse_u32(next);
28126 let Some(val) = res else { break };
28127 val
28128 }),
28129 29u16 => OpGetlinkDoReply::ExtMask({
28130 let res = parse_u32(next);
28131 let Some(val) = res else { break };
28132 val
28133 }),
28134 30u16 => OpGetlinkDoReply::Promiscuity({
28135 let res = parse_u32(next);
28136 let Some(val) = res else { break };
28137 val
28138 }),
28139 31u16 => OpGetlinkDoReply::NumTxQueues({
28140 let res = parse_u32(next);
28141 let Some(val) = res else { break };
28142 val
28143 }),
28144 32u16 => OpGetlinkDoReply::NumRxQueues({
28145 let res = parse_u32(next);
28146 let Some(val) = res else { break };
28147 val
28148 }),
28149 33u16 => OpGetlinkDoReply::Carrier({
28150 let res = parse_u8(next);
28151 let Some(val) = res else { break };
28152 val
28153 }),
28154 34u16 => OpGetlinkDoReply::PhysPortId({
28155 let res = Some(next);
28156 let Some(val) = res else { break };
28157 val
28158 }),
28159 35u16 => OpGetlinkDoReply::CarrierChanges({
28160 let res = parse_u32(next);
28161 let Some(val) = res else { break };
28162 val
28163 }),
28164 36u16 => OpGetlinkDoReply::PhysSwitchId({
28165 let res = Some(next);
28166 let Some(val) = res else { break };
28167 val
28168 }),
28169 37u16 => OpGetlinkDoReply::LinkNetnsid({
28170 let res = parse_i32(next);
28171 let Some(val) = res else { break };
28172 val
28173 }),
28174 38u16 => OpGetlinkDoReply::PhysPortName({
28175 let res = CStr::from_bytes_with_nul(next).ok();
28176 let Some(val) = res else { break };
28177 val
28178 }),
28179 39u16 => OpGetlinkDoReply::ProtoDown({
28180 let res = parse_u8(next);
28181 let Some(val) = res else { break };
28182 val
28183 }),
28184 40u16 => OpGetlinkDoReply::GsoMaxSegs({
28185 let res = parse_u32(next);
28186 let Some(val) = res else { break };
28187 val
28188 }),
28189 41u16 => OpGetlinkDoReply::GsoMaxSize({
28190 let res = parse_u32(next);
28191 let Some(val) = res else { break };
28192 val
28193 }),
28194 42u16 => OpGetlinkDoReply::Pad({
28195 let res = Some(next);
28196 let Some(val) = res else { break };
28197 val
28198 }),
28199 43u16 => OpGetlinkDoReply::Xdp({
28200 let res = Some(IterableXdpAttrs::with_loc(next, self.orig_loc));
28201 let Some(val) = res else { break };
28202 val
28203 }),
28204 44u16 => OpGetlinkDoReply::Event({
28205 let res = parse_u32(next);
28206 let Some(val) = res else { break };
28207 val
28208 }),
28209 45u16 => OpGetlinkDoReply::NewNetnsid({
28210 let res = parse_i32(next);
28211 let Some(val) = res else { break };
28212 val
28213 }),
28214 46u16 => OpGetlinkDoReply::TargetNetnsid({
28215 let res = parse_i32(next);
28216 let Some(val) = res else { break };
28217 val
28218 }),
28219 47u16 => OpGetlinkDoReply::CarrierUpCount({
28220 let res = parse_u32(next);
28221 let Some(val) = res else { break };
28222 val
28223 }),
28224 48u16 => OpGetlinkDoReply::CarrierDownCount({
28225 let res = parse_u32(next);
28226 let Some(val) = res else { break };
28227 val
28228 }),
28229 49u16 => OpGetlinkDoReply::NewIfindex({
28230 let res = parse_i32(next);
28231 let Some(val) = res else { break };
28232 val
28233 }),
28234 50u16 => OpGetlinkDoReply::MinMtu({
28235 let res = parse_u32(next);
28236 let Some(val) = res else { break };
28237 val
28238 }),
28239 51u16 => OpGetlinkDoReply::MaxMtu({
28240 let res = parse_u32(next);
28241 let Some(val) = res else { break };
28242 val
28243 }),
28244 52u16 => OpGetlinkDoReply::PropList({
28245 let res = Some(IterablePropListLinkAttrs::with_loc(next, self.orig_loc));
28246 let Some(val) = res else { break };
28247 val
28248 }),
28249 54u16 => OpGetlinkDoReply::PermAddress({
28250 let res = Some(next);
28251 let Some(val) = res else { break };
28252 val
28253 }),
28254 55u16 => OpGetlinkDoReply::ProtoDownReason({
28255 let res = CStr::from_bytes_with_nul(next).ok();
28256 let Some(val) = res else { break };
28257 val
28258 }),
28259 56u16 => OpGetlinkDoReply::ParentDevName({
28260 let res = CStr::from_bytes_with_nul(next).ok();
28261 let Some(val) = res else { break };
28262 val
28263 }),
28264 57u16 => OpGetlinkDoReply::ParentDevBusName({
28265 let res = CStr::from_bytes_with_nul(next).ok();
28266 let Some(val) = res else { break };
28267 val
28268 }),
28269 58u16 => OpGetlinkDoReply::GroMaxSize({
28270 let res = parse_u32(next);
28271 let Some(val) = res else { break };
28272 val
28273 }),
28274 59u16 => OpGetlinkDoReply::TsoMaxSize({
28275 let res = parse_u32(next);
28276 let Some(val) = res else { break };
28277 val
28278 }),
28279 60u16 => OpGetlinkDoReply::TsoMaxSegs({
28280 let res = parse_u32(next);
28281 let Some(val) = res else { break };
28282 val
28283 }),
28284 61u16 => OpGetlinkDoReply::Allmulti({
28285 let res = parse_u32(next);
28286 let Some(val) = res else { break };
28287 val
28288 }),
28289 62u16 => OpGetlinkDoReply::DevlinkPort({
28290 let res = Some(next);
28291 let Some(val) = res else { break };
28292 val
28293 }),
28294 63u16 => OpGetlinkDoReply::GsoIpv4MaxSize({
28295 let res = parse_u32(next);
28296 let Some(val) = res else { break };
28297 val
28298 }),
28299 64u16 => OpGetlinkDoReply::GroIpv4MaxSize({
28300 let res = parse_u32(next);
28301 let Some(val) = res else { break };
28302 val
28303 }),
28304 65u16 => OpGetlinkDoReply::DpllPin({
28305 let res = Some(IterableLinkDpllPinAttrs::with_loc(next, self.orig_loc));
28306 let Some(val) = res else { break };
28307 val
28308 }),
28309 66u16 => OpGetlinkDoReply::MaxPacingOffloadHorizon({
28310 let res = parse_u32(next);
28311 let Some(val) = res else { break };
28312 val
28313 }),
28314 67u16 => OpGetlinkDoReply::NetnsImmutable({
28315 let res = parse_u8(next);
28316 let Some(val) = res else { break };
28317 val
28318 }),
28319 n => {
28320 if cfg!(any(test, feature = "deny-unknown-attrs")) {
28321 break;
28322 } else {
28323 continue;
28324 }
28325 }
28326 };
28327 return Some(Ok(res));
28328 }
28329 Some(Err(ErrorContext::new(
28330 "OpGetlinkDoReply",
28331 r#type.and_then(|t| OpGetlinkDoReply::attr_from_type(t)),
28332 self.orig_loc,
28333 self.buf.as_ptr().wrapping_add(pos) as usize,
28334 )))
28335 }
28336}
28337impl<'a> std::fmt::Debug for IterableOpGetlinkDoReply<'_> {
28338 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28339 let mut fmt = f.debug_struct("OpGetlinkDoReply");
28340 for attr in self.clone() {
28341 let attr = match attr {
28342 Ok(a) => a,
28343 Err(err) => {
28344 fmt.finish()?;
28345 f.write_str("Err(")?;
28346 err.fmt(f)?;
28347 return f.write_str(")");
28348 }
28349 };
28350 match attr {
28351 OpGetlinkDoReply::Address(val) => fmt.field("Address", &val),
28352 OpGetlinkDoReply::Broadcast(val) => fmt.field("Broadcast", &val),
28353 OpGetlinkDoReply::Ifname(val) => fmt.field("Ifname", &val),
28354 OpGetlinkDoReply::Mtu(val) => fmt.field("Mtu", &val),
28355 OpGetlinkDoReply::Link(val) => fmt.field("Link", &val),
28356 OpGetlinkDoReply::Qdisc(val) => fmt.field("Qdisc", &val),
28357 OpGetlinkDoReply::Stats(val) => fmt.field("Stats", &val),
28358 OpGetlinkDoReply::Cost(val) => fmt.field("Cost", &val),
28359 OpGetlinkDoReply::Priority(val) => fmt.field("Priority", &val),
28360 OpGetlinkDoReply::Master(val) => fmt.field("Master", &val),
28361 OpGetlinkDoReply::Wireless(val) => fmt.field("Wireless", &val),
28362 OpGetlinkDoReply::Protinfo(val) => fmt.field("Protinfo", &val),
28363 OpGetlinkDoReply::Txqlen(val) => fmt.field("Txqlen", &val),
28364 OpGetlinkDoReply::Map(val) => fmt.field("Map", &val),
28365 OpGetlinkDoReply::Weight(val) => fmt.field("Weight", &val),
28366 OpGetlinkDoReply::Operstate(val) => fmt.field("Operstate", &val),
28367 OpGetlinkDoReply::Linkmode(val) => fmt.field("Linkmode", &val),
28368 OpGetlinkDoReply::Linkinfo(val) => fmt.field("Linkinfo", &val),
28369 OpGetlinkDoReply::NetNsPid(val) => fmt.field("NetNsPid", &val),
28370 OpGetlinkDoReply::Ifalias(val) => fmt.field("Ifalias", &val),
28371 OpGetlinkDoReply::NumVf(val) => fmt.field("NumVf", &val),
28372 OpGetlinkDoReply::VfinfoList(val) => fmt.field("VfinfoList", &val),
28373 OpGetlinkDoReply::Stats64(val) => fmt.field("Stats64", &val),
28374 OpGetlinkDoReply::VfPorts(val) => fmt.field("VfPorts", &val),
28375 OpGetlinkDoReply::PortSelf(val) => fmt.field("PortSelf", &val),
28376 OpGetlinkDoReply::AfSpec(val) => fmt.field("AfSpec", &val),
28377 OpGetlinkDoReply::Group(val) => fmt.field("Group", &val),
28378 OpGetlinkDoReply::NetNsFd(val) => fmt.field("NetNsFd", &val),
28379 OpGetlinkDoReply::ExtMask(val) => {
28380 fmt.field("ExtMask", &FormatFlags(val.into(), RtextFilter::from_value))
28381 }
28382 OpGetlinkDoReply::Promiscuity(val) => fmt.field("Promiscuity", &val),
28383 OpGetlinkDoReply::NumTxQueues(val) => fmt.field("NumTxQueues", &val),
28384 OpGetlinkDoReply::NumRxQueues(val) => fmt.field("NumRxQueues", &val),
28385 OpGetlinkDoReply::Carrier(val) => fmt.field("Carrier", &val),
28386 OpGetlinkDoReply::PhysPortId(val) => fmt.field("PhysPortId", &val),
28387 OpGetlinkDoReply::CarrierChanges(val) => fmt.field("CarrierChanges", &val),
28388 OpGetlinkDoReply::PhysSwitchId(val) => fmt.field("PhysSwitchId", &val),
28389 OpGetlinkDoReply::LinkNetnsid(val) => fmt.field("LinkNetnsid", &val),
28390 OpGetlinkDoReply::PhysPortName(val) => fmt.field("PhysPortName", &val),
28391 OpGetlinkDoReply::ProtoDown(val) => fmt.field("ProtoDown", &val),
28392 OpGetlinkDoReply::GsoMaxSegs(val) => fmt.field("GsoMaxSegs", &val),
28393 OpGetlinkDoReply::GsoMaxSize(val) => fmt.field("GsoMaxSize", &val),
28394 OpGetlinkDoReply::Pad(val) => fmt.field("Pad", &val),
28395 OpGetlinkDoReply::Xdp(val) => fmt.field("Xdp", &val),
28396 OpGetlinkDoReply::Event(val) => fmt.field("Event", &val),
28397 OpGetlinkDoReply::NewNetnsid(val) => fmt.field("NewNetnsid", &val),
28398 OpGetlinkDoReply::TargetNetnsid(val) => fmt.field("TargetNetnsid", &val),
28399 OpGetlinkDoReply::CarrierUpCount(val) => fmt.field("CarrierUpCount", &val),
28400 OpGetlinkDoReply::CarrierDownCount(val) => fmt.field("CarrierDownCount", &val),
28401 OpGetlinkDoReply::NewIfindex(val) => fmt.field("NewIfindex", &val),
28402 OpGetlinkDoReply::MinMtu(val) => fmt.field("MinMtu", &val),
28403 OpGetlinkDoReply::MaxMtu(val) => fmt.field("MaxMtu", &val),
28404 OpGetlinkDoReply::PropList(val) => fmt.field("PropList", &val),
28405 OpGetlinkDoReply::PermAddress(val) => fmt.field("PermAddress", &val),
28406 OpGetlinkDoReply::ProtoDownReason(val) => fmt.field("ProtoDownReason", &val),
28407 OpGetlinkDoReply::ParentDevName(val) => fmt.field("ParentDevName", &val),
28408 OpGetlinkDoReply::ParentDevBusName(val) => fmt.field("ParentDevBusName", &val),
28409 OpGetlinkDoReply::GroMaxSize(val) => fmt.field("GroMaxSize", &val),
28410 OpGetlinkDoReply::TsoMaxSize(val) => fmt.field("TsoMaxSize", &val),
28411 OpGetlinkDoReply::TsoMaxSegs(val) => fmt.field("TsoMaxSegs", &val),
28412 OpGetlinkDoReply::Allmulti(val) => fmt.field("Allmulti", &val),
28413 OpGetlinkDoReply::DevlinkPort(val) => fmt.field("DevlinkPort", &val),
28414 OpGetlinkDoReply::GsoIpv4MaxSize(val) => fmt.field("GsoIpv4MaxSize", &val),
28415 OpGetlinkDoReply::GroIpv4MaxSize(val) => fmt.field("GroIpv4MaxSize", &val),
28416 OpGetlinkDoReply::DpllPin(val) => fmt.field("DpllPin", &val),
28417 OpGetlinkDoReply::MaxPacingOffloadHorizon(val) => {
28418 fmt.field("MaxPacingOffloadHorizon", &val)
28419 }
28420 OpGetlinkDoReply::NetnsImmutable(val) => fmt.field("NetnsImmutable", &val),
28421 };
28422 }
28423 fmt.finish()
28424 }
28425}
28426impl IterableOpGetlinkDoReply<'_> {
28427 pub fn lookup_attr(
28428 &self,
28429 offset: usize,
28430 missing_type: Option<u16>,
28431 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28432 let mut stack = Vec::new();
28433 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
28434 if cur == offset + PushIfinfomsg::len() {
28435 stack.push(("OpGetlinkDoReply", offset));
28436 return (
28437 stack,
28438 missing_type.and_then(|t| OpGetlinkDoReply::attr_from_type(t)),
28439 );
28440 }
28441 if cur > offset || cur + self.buf.len() < offset {
28442 return (stack, None);
28443 }
28444 let mut attrs = self.clone();
28445 let mut last_off = cur + attrs.pos;
28446 let mut missing = None;
28447 while let Some(attr) = attrs.next() {
28448 let Ok(attr) = attr else { break };
28449 match attr {
28450 OpGetlinkDoReply::Address(val) => {
28451 if last_off == offset {
28452 stack.push(("Address", last_off));
28453 break;
28454 }
28455 }
28456 OpGetlinkDoReply::Broadcast(val) => {
28457 if last_off == offset {
28458 stack.push(("Broadcast", last_off));
28459 break;
28460 }
28461 }
28462 OpGetlinkDoReply::Ifname(val) => {
28463 if last_off == offset {
28464 stack.push(("Ifname", last_off));
28465 break;
28466 }
28467 }
28468 OpGetlinkDoReply::Mtu(val) => {
28469 if last_off == offset {
28470 stack.push(("Mtu", last_off));
28471 break;
28472 }
28473 }
28474 OpGetlinkDoReply::Link(val) => {
28475 if last_off == offset {
28476 stack.push(("Link", last_off));
28477 break;
28478 }
28479 }
28480 OpGetlinkDoReply::Qdisc(val) => {
28481 if last_off == offset {
28482 stack.push(("Qdisc", last_off));
28483 break;
28484 }
28485 }
28486 OpGetlinkDoReply::Stats(val) => {
28487 if last_off == offset {
28488 stack.push(("Stats", last_off));
28489 break;
28490 }
28491 }
28492 OpGetlinkDoReply::Cost(val) => {
28493 if last_off == offset {
28494 stack.push(("Cost", last_off));
28495 break;
28496 }
28497 }
28498 OpGetlinkDoReply::Priority(val) => {
28499 if last_off == offset {
28500 stack.push(("Priority", last_off));
28501 break;
28502 }
28503 }
28504 OpGetlinkDoReply::Master(val) => {
28505 if last_off == offset {
28506 stack.push(("Master", last_off));
28507 break;
28508 }
28509 }
28510 OpGetlinkDoReply::Wireless(val) => {
28511 if last_off == offset {
28512 stack.push(("Wireless", last_off));
28513 break;
28514 }
28515 }
28516 OpGetlinkDoReply::Protinfo(val) => {
28517 if last_off == offset {
28518 stack.push(("Protinfo", last_off));
28519 break;
28520 }
28521 }
28522 OpGetlinkDoReply::Txqlen(val) => {
28523 if last_off == offset {
28524 stack.push(("Txqlen", last_off));
28525 break;
28526 }
28527 }
28528 OpGetlinkDoReply::Map(val) => {
28529 if last_off == offset {
28530 stack.push(("Map", last_off));
28531 break;
28532 }
28533 }
28534 OpGetlinkDoReply::Weight(val) => {
28535 if last_off == offset {
28536 stack.push(("Weight", last_off));
28537 break;
28538 }
28539 }
28540 OpGetlinkDoReply::Operstate(val) => {
28541 if last_off == offset {
28542 stack.push(("Operstate", last_off));
28543 break;
28544 }
28545 }
28546 OpGetlinkDoReply::Linkmode(val) => {
28547 if last_off == offset {
28548 stack.push(("Linkmode", last_off));
28549 break;
28550 }
28551 }
28552 OpGetlinkDoReply::Linkinfo(val) => {
28553 (stack, missing) = val.lookup_attr(offset, missing_type);
28554 if !stack.is_empty() {
28555 break;
28556 }
28557 }
28558 OpGetlinkDoReply::NetNsPid(val) => {
28559 if last_off == offset {
28560 stack.push(("NetNsPid", last_off));
28561 break;
28562 }
28563 }
28564 OpGetlinkDoReply::Ifalias(val) => {
28565 if last_off == offset {
28566 stack.push(("Ifalias", last_off));
28567 break;
28568 }
28569 }
28570 OpGetlinkDoReply::NumVf(val) => {
28571 if last_off == offset {
28572 stack.push(("NumVf", last_off));
28573 break;
28574 }
28575 }
28576 OpGetlinkDoReply::VfinfoList(val) => {
28577 (stack, missing) = val.lookup_attr(offset, missing_type);
28578 if !stack.is_empty() {
28579 break;
28580 }
28581 }
28582 OpGetlinkDoReply::Stats64(val) => {
28583 if last_off == offset {
28584 stack.push(("Stats64", last_off));
28585 break;
28586 }
28587 }
28588 OpGetlinkDoReply::VfPorts(val) => {
28589 (stack, missing) = val.lookup_attr(offset, missing_type);
28590 if !stack.is_empty() {
28591 break;
28592 }
28593 }
28594 OpGetlinkDoReply::PortSelf(val) => {
28595 (stack, missing) = val.lookup_attr(offset, missing_type);
28596 if !stack.is_empty() {
28597 break;
28598 }
28599 }
28600 OpGetlinkDoReply::AfSpec(val) => {
28601 (stack, missing) = val.lookup_attr(offset, missing_type);
28602 if !stack.is_empty() {
28603 break;
28604 }
28605 }
28606 OpGetlinkDoReply::Group(val) => {
28607 if last_off == offset {
28608 stack.push(("Group", last_off));
28609 break;
28610 }
28611 }
28612 OpGetlinkDoReply::NetNsFd(val) => {
28613 if last_off == offset {
28614 stack.push(("NetNsFd", last_off));
28615 break;
28616 }
28617 }
28618 OpGetlinkDoReply::ExtMask(val) => {
28619 if last_off == offset {
28620 stack.push(("ExtMask", last_off));
28621 break;
28622 }
28623 }
28624 OpGetlinkDoReply::Promiscuity(val) => {
28625 if last_off == offset {
28626 stack.push(("Promiscuity", last_off));
28627 break;
28628 }
28629 }
28630 OpGetlinkDoReply::NumTxQueues(val) => {
28631 if last_off == offset {
28632 stack.push(("NumTxQueues", last_off));
28633 break;
28634 }
28635 }
28636 OpGetlinkDoReply::NumRxQueues(val) => {
28637 if last_off == offset {
28638 stack.push(("NumRxQueues", last_off));
28639 break;
28640 }
28641 }
28642 OpGetlinkDoReply::Carrier(val) => {
28643 if last_off == offset {
28644 stack.push(("Carrier", last_off));
28645 break;
28646 }
28647 }
28648 OpGetlinkDoReply::PhysPortId(val) => {
28649 if last_off == offset {
28650 stack.push(("PhysPortId", last_off));
28651 break;
28652 }
28653 }
28654 OpGetlinkDoReply::CarrierChanges(val) => {
28655 if last_off == offset {
28656 stack.push(("CarrierChanges", last_off));
28657 break;
28658 }
28659 }
28660 OpGetlinkDoReply::PhysSwitchId(val) => {
28661 if last_off == offset {
28662 stack.push(("PhysSwitchId", last_off));
28663 break;
28664 }
28665 }
28666 OpGetlinkDoReply::LinkNetnsid(val) => {
28667 if last_off == offset {
28668 stack.push(("LinkNetnsid", last_off));
28669 break;
28670 }
28671 }
28672 OpGetlinkDoReply::PhysPortName(val) => {
28673 if last_off == offset {
28674 stack.push(("PhysPortName", last_off));
28675 break;
28676 }
28677 }
28678 OpGetlinkDoReply::ProtoDown(val) => {
28679 if last_off == offset {
28680 stack.push(("ProtoDown", last_off));
28681 break;
28682 }
28683 }
28684 OpGetlinkDoReply::GsoMaxSegs(val) => {
28685 if last_off == offset {
28686 stack.push(("GsoMaxSegs", last_off));
28687 break;
28688 }
28689 }
28690 OpGetlinkDoReply::GsoMaxSize(val) => {
28691 if last_off == offset {
28692 stack.push(("GsoMaxSize", last_off));
28693 break;
28694 }
28695 }
28696 OpGetlinkDoReply::Pad(val) => {
28697 if last_off == offset {
28698 stack.push(("Pad", last_off));
28699 break;
28700 }
28701 }
28702 OpGetlinkDoReply::Xdp(val) => {
28703 (stack, missing) = val.lookup_attr(offset, missing_type);
28704 if !stack.is_empty() {
28705 break;
28706 }
28707 }
28708 OpGetlinkDoReply::Event(val) => {
28709 if last_off == offset {
28710 stack.push(("Event", last_off));
28711 break;
28712 }
28713 }
28714 OpGetlinkDoReply::NewNetnsid(val) => {
28715 if last_off == offset {
28716 stack.push(("NewNetnsid", last_off));
28717 break;
28718 }
28719 }
28720 OpGetlinkDoReply::TargetNetnsid(val) => {
28721 if last_off == offset {
28722 stack.push(("TargetNetnsid", last_off));
28723 break;
28724 }
28725 }
28726 OpGetlinkDoReply::CarrierUpCount(val) => {
28727 if last_off == offset {
28728 stack.push(("CarrierUpCount", last_off));
28729 break;
28730 }
28731 }
28732 OpGetlinkDoReply::CarrierDownCount(val) => {
28733 if last_off == offset {
28734 stack.push(("CarrierDownCount", last_off));
28735 break;
28736 }
28737 }
28738 OpGetlinkDoReply::NewIfindex(val) => {
28739 if last_off == offset {
28740 stack.push(("NewIfindex", last_off));
28741 break;
28742 }
28743 }
28744 OpGetlinkDoReply::MinMtu(val) => {
28745 if last_off == offset {
28746 stack.push(("MinMtu", last_off));
28747 break;
28748 }
28749 }
28750 OpGetlinkDoReply::MaxMtu(val) => {
28751 if last_off == offset {
28752 stack.push(("MaxMtu", last_off));
28753 break;
28754 }
28755 }
28756 OpGetlinkDoReply::PropList(val) => {
28757 (stack, missing) = val.lookup_attr(offset, missing_type);
28758 if !stack.is_empty() {
28759 break;
28760 }
28761 }
28762 OpGetlinkDoReply::PermAddress(val) => {
28763 if last_off == offset {
28764 stack.push(("PermAddress", last_off));
28765 break;
28766 }
28767 }
28768 OpGetlinkDoReply::ProtoDownReason(val) => {
28769 if last_off == offset {
28770 stack.push(("ProtoDownReason", last_off));
28771 break;
28772 }
28773 }
28774 OpGetlinkDoReply::ParentDevName(val) => {
28775 if last_off == offset {
28776 stack.push(("ParentDevName", last_off));
28777 break;
28778 }
28779 }
28780 OpGetlinkDoReply::ParentDevBusName(val) => {
28781 if last_off == offset {
28782 stack.push(("ParentDevBusName", last_off));
28783 break;
28784 }
28785 }
28786 OpGetlinkDoReply::GroMaxSize(val) => {
28787 if last_off == offset {
28788 stack.push(("GroMaxSize", last_off));
28789 break;
28790 }
28791 }
28792 OpGetlinkDoReply::TsoMaxSize(val) => {
28793 if last_off == offset {
28794 stack.push(("TsoMaxSize", last_off));
28795 break;
28796 }
28797 }
28798 OpGetlinkDoReply::TsoMaxSegs(val) => {
28799 if last_off == offset {
28800 stack.push(("TsoMaxSegs", last_off));
28801 break;
28802 }
28803 }
28804 OpGetlinkDoReply::Allmulti(val) => {
28805 if last_off == offset {
28806 stack.push(("Allmulti", last_off));
28807 break;
28808 }
28809 }
28810 OpGetlinkDoReply::DevlinkPort(val) => {
28811 if last_off == offset {
28812 stack.push(("DevlinkPort", last_off));
28813 break;
28814 }
28815 }
28816 OpGetlinkDoReply::GsoIpv4MaxSize(val) => {
28817 if last_off == offset {
28818 stack.push(("GsoIpv4MaxSize", last_off));
28819 break;
28820 }
28821 }
28822 OpGetlinkDoReply::GroIpv4MaxSize(val) => {
28823 if last_off == offset {
28824 stack.push(("GroIpv4MaxSize", last_off));
28825 break;
28826 }
28827 }
28828 OpGetlinkDoReply::DpllPin(val) => {
28829 (stack, missing) = val.lookup_attr(offset, missing_type);
28830 if !stack.is_empty() {
28831 break;
28832 }
28833 }
28834 OpGetlinkDoReply::MaxPacingOffloadHorizon(val) => {
28835 if last_off == offset {
28836 stack.push(("MaxPacingOffloadHorizon", last_off));
28837 break;
28838 }
28839 }
28840 OpGetlinkDoReply::NetnsImmutable(val) => {
28841 if last_off == offset {
28842 stack.push(("NetnsImmutable", last_off));
28843 break;
28844 }
28845 }
28846 _ => {}
28847 };
28848 last_off = cur + attrs.pos;
28849 }
28850 if !stack.is_empty() {
28851 stack.push(("OpGetlinkDoReply", cur));
28852 }
28853 (stack, missing)
28854 }
28855}
28856#[derive(Debug)]
28857pub struct RequestOpGetlinkDoRequest<'r> {
28858 request: Request<'r>,
28859}
28860impl<'r> RequestOpGetlinkDoRequest<'r> {
28861 pub fn new(mut request: Request<'r>, header: &PushIfinfomsg) -> Self {
28862 PushOpGetlinkDoRequest::write_header(&mut request.buf_mut(), header);
28863 Self { request: request }
28864 }
28865 pub fn encode(&mut self) -> PushOpGetlinkDoRequest<&mut Vec<u8>> {
28866 PushOpGetlinkDoRequest::new_without_header(self.request.buf_mut())
28867 }
28868 pub fn into_encoder(self) -> PushOpGetlinkDoRequest<RequestBuf<'r>> {
28869 PushOpGetlinkDoRequest::new_without_header(self.request.buf)
28870 }
28871}
28872impl NetlinkRequest for RequestOpGetlinkDoRequest<'_> {
28873 type ReplyType<'buf> = (PushIfinfomsg, IterableOpGetlinkDoReply<'buf>);
28874 fn protocol(&self) -> Protocol {
28875 Protocol::Raw {
28876 protonum: 0u16,
28877 request_type: 18u16,
28878 }
28879 }
28880 fn flags(&self) -> u16 {
28881 self.request.flags
28882 }
28883 fn payload(&self) -> &[u8] {
28884 self.request.buf()
28885 }
28886 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
28887 OpGetlinkDoReply::new(buf)
28888 }
28889 fn lookup(
28890 buf: &[u8],
28891 offset: usize,
28892 missing_type: Option<u16>,
28893 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28894 OpGetlinkDoRequest::new(buf)
28895 .1
28896 .lookup_attr(offset, missing_type)
28897 }
28898}
28899#[doc = "Set information about a link."]
28900pub struct PushOpSetlinkDoRequest<Prev: Rec> {
28901 pub(crate) prev: Option<Prev>,
28902 pub(crate) header_offset: Option<usize>,
28903}
28904impl<Prev: Rec> Rec for PushOpSetlinkDoRequest<Prev> {
28905 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
28906 self.prev.as_mut().unwrap().as_rec_mut()
28907 }
28908}
28909impl<Prev: Rec> PushOpSetlinkDoRequest<Prev> {
28910 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
28911 Self::write_header(&mut prev, header);
28912 Self::new_without_header(prev)
28913 }
28914 fn new_without_header(prev: Prev) -> Self {
28915 Self {
28916 prev: Some(prev),
28917 header_offset: None,
28918 }
28919 }
28920 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
28921 prev.as_rec_mut().extend(header.as_slice());
28922 }
28923 pub fn end_nested(mut self) -> Prev {
28924 let mut prev = self.prev.take().unwrap();
28925 if let Some(header_offset) = &self.header_offset {
28926 finalize_nested_header(prev.as_rec_mut(), *header_offset);
28927 }
28928 prev
28929 }
28930 pub fn push_address(mut self, value: &[u8]) -> Self {
28931 push_header(self.as_rec_mut(), 1u16, value.len() as u16);
28932 self.as_rec_mut().extend(value);
28933 self
28934 }
28935 pub fn push_broadcast(mut self, value: &[u8]) -> Self {
28936 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
28937 self.as_rec_mut().extend(value);
28938 self
28939 }
28940 pub fn push_ifname(mut self, value: &CStr) -> Self {
28941 push_header(
28942 self.as_rec_mut(),
28943 3u16,
28944 value.to_bytes_with_nul().len() as u16,
28945 );
28946 self.as_rec_mut().extend(value.to_bytes_with_nul());
28947 self
28948 }
28949 pub fn push_ifname_bytes(mut self, value: &[u8]) -> Self {
28950 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
28951 self.as_rec_mut().extend(value);
28952 self.as_rec_mut().push(0);
28953 self
28954 }
28955 pub fn push_mtu(mut self, value: u32) -> Self {
28956 push_header(self.as_rec_mut(), 4u16, 4 as u16);
28957 self.as_rec_mut().extend(value.to_ne_bytes());
28958 self
28959 }
28960 pub fn push_link(mut self, value: u32) -> Self {
28961 push_header(self.as_rec_mut(), 5u16, 4 as u16);
28962 self.as_rec_mut().extend(value.to_ne_bytes());
28963 self
28964 }
28965 pub fn push_qdisc(mut self, value: &CStr) -> Self {
28966 push_header(
28967 self.as_rec_mut(),
28968 6u16,
28969 value.to_bytes_with_nul().len() as u16,
28970 );
28971 self.as_rec_mut().extend(value.to_bytes_with_nul());
28972 self
28973 }
28974 pub fn push_qdisc_bytes(mut self, value: &[u8]) -> Self {
28975 push_header(self.as_rec_mut(), 6u16, (value.len() + 1) as u16);
28976 self.as_rec_mut().extend(value);
28977 self.as_rec_mut().push(0);
28978 self
28979 }
28980 pub fn push_stats(mut self, value: PushRtnlLinkStats) -> Self {
28981 push_header(self.as_rec_mut(), 7u16, value.as_slice().len() as u16);
28982 self.as_rec_mut().extend(value.as_slice());
28983 self
28984 }
28985 pub fn push_cost(mut self, value: &CStr) -> Self {
28986 push_header(
28987 self.as_rec_mut(),
28988 8u16,
28989 value.to_bytes_with_nul().len() as u16,
28990 );
28991 self.as_rec_mut().extend(value.to_bytes_with_nul());
28992 self
28993 }
28994 pub fn push_cost_bytes(mut self, value: &[u8]) -> Self {
28995 push_header(self.as_rec_mut(), 8u16, (value.len() + 1) as u16);
28996 self.as_rec_mut().extend(value);
28997 self.as_rec_mut().push(0);
28998 self
28999 }
29000 pub fn push_priority(mut self, value: &CStr) -> Self {
29001 push_header(
29002 self.as_rec_mut(),
29003 9u16,
29004 value.to_bytes_with_nul().len() as u16,
29005 );
29006 self.as_rec_mut().extend(value.to_bytes_with_nul());
29007 self
29008 }
29009 pub fn push_priority_bytes(mut self, value: &[u8]) -> Self {
29010 push_header(self.as_rec_mut(), 9u16, (value.len() + 1) as u16);
29011 self.as_rec_mut().extend(value);
29012 self.as_rec_mut().push(0);
29013 self
29014 }
29015 pub fn push_master(mut self, value: u32) -> Self {
29016 push_header(self.as_rec_mut(), 10u16, 4 as u16);
29017 self.as_rec_mut().extend(value.to_ne_bytes());
29018 self
29019 }
29020 pub fn push_wireless(mut self, value: &CStr) -> Self {
29021 push_header(
29022 self.as_rec_mut(),
29023 11u16,
29024 value.to_bytes_with_nul().len() as u16,
29025 );
29026 self.as_rec_mut().extend(value.to_bytes_with_nul());
29027 self
29028 }
29029 pub fn push_wireless_bytes(mut self, value: &[u8]) -> Self {
29030 push_header(self.as_rec_mut(), 11u16, (value.len() + 1) as u16);
29031 self.as_rec_mut().extend(value);
29032 self.as_rec_mut().push(0);
29033 self
29034 }
29035 pub fn push_protinfo(mut self, value: &CStr) -> Self {
29036 push_header(
29037 self.as_rec_mut(),
29038 12u16,
29039 value.to_bytes_with_nul().len() as u16,
29040 );
29041 self.as_rec_mut().extend(value.to_bytes_with_nul());
29042 self
29043 }
29044 pub fn push_protinfo_bytes(mut self, value: &[u8]) -> Self {
29045 push_header(self.as_rec_mut(), 12u16, (value.len() + 1) as u16);
29046 self.as_rec_mut().extend(value);
29047 self.as_rec_mut().push(0);
29048 self
29049 }
29050 pub fn push_txqlen(mut self, value: u32) -> Self {
29051 push_header(self.as_rec_mut(), 13u16, 4 as u16);
29052 self.as_rec_mut().extend(value.to_ne_bytes());
29053 self
29054 }
29055 pub fn push_map(mut self, value: PushRtnlLinkIfmap) -> Self {
29056 push_header(self.as_rec_mut(), 14u16, value.as_slice().len() as u16);
29057 self.as_rec_mut().extend(value.as_slice());
29058 self
29059 }
29060 pub fn push_weight(mut self, value: u32) -> Self {
29061 push_header(self.as_rec_mut(), 15u16, 4 as u16);
29062 self.as_rec_mut().extend(value.to_ne_bytes());
29063 self
29064 }
29065 pub fn push_operstate(mut self, value: u8) -> Self {
29066 push_header(self.as_rec_mut(), 16u16, 1 as u16);
29067 self.as_rec_mut().extend(value.to_ne_bytes());
29068 self
29069 }
29070 pub fn push_linkmode(mut self, value: u8) -> Self {
29071 push_header(self.as_rec_mut(), 17u16, 1 as u16);
29072 self.as_rec_mut().extend(value.to_ne_bytes());
29073 self
29074 }
29075 pub fn nested_linkinfo(mut self) -> PushLinkinfoAttrs<Self> {
29076 let header_offset = push_nested_header(self.as_rec_mut(), 18u16);
29077 PushLinkinfoAttrs {
29078 prev: Some(self),
29079 header_offset: Some(header_offset),
29080 }
29081 }
29082 pub fn push_net_ns_pid(mut self, value: u32) -> Self {
29083 push_header(self.as_rec_mut(), 19u16, 4 as u16);
29084 self.as_rec_mut().extend(value.to_ne_bytes());
29085 self
29086 }
29087 pub fn push_ifalias(mut self, value: &CStr) -> Self {
29088 push_header(
29089 self.as_rec_mut(),
29090 20u16,
29091 value.to_bytes_with_nul().len() as u16,
29092 );
29093 self.as_rec_mut().extend(value.to_bytes_with_nul());
29094 self
29095 }
29096 pub fn push_ifalias_bytes(mut self, value: &[u8]) -> Self {
29097 push_header(self.as_rec_mut(), 20u16, (value.len() + 1) as u16);
29098 self.as_rec_mut().extend(value);
29099 self.as_rec_mut().push(0);
29100 self
29101 }
29102 pub fn push_num_vf(mut self, value: u32) -> Self {
29103 push_header(self.as_rec_mut(), 21u16, 4 as u16);
29104 self.as_rec_mut().extend(value.to_ne_bytes());
29105 self
29106 }
29107 pub fn nested_vfinfo_list(mut self) -> PushVfinfoListAttrs<Self> {
29108 let header_offset = push_nested_header(self.as_rec_mut(), 22u16);
29109 PushVfinfoListAttrs {
29110 prev: Some(self),
29111 header_offset: Some(header_offset),
29112 }
29113 }
29114 pub fn push_stats64(mut self, value: PushRtnlLinkStats64) -> Self {
29115 push_header(self.as_rec_mut(), 23u16, value.as_slice().len() as u16);
29116 self.as_rec_mut().extend(value.as_slice());
29117 self
29118 }
29119 pub fn nested_vf_ports(mut self) -> PushVfPortsAttrs<Self> {
29120 let header_offset = push_nested_header(self.as_rec_mut(), 24u16);
29121 PushVfPortsAttrs {
29122 prev: Some(self),
29123 header_offset: Some(header_offset),
29124 }
29125 }
29126 pub fn nested_port_self(mut self) -> PushPortSelfAttrs<Self> {
29127 let header_offset = push_nested_header(self.as_rec_mut(), 25u16);
29128 PushPortSelfAttrs {
29129 prev: Some(self),
29130 header_offset: Some(header_offset),
29131 }
29132 }
29133 pub fn nested_af_spec(mut self) -> PushAfSpecAttrs<Self> {
29134 let header_offset = push_nested_header(self.as_rec_mut(), 26u16);
29135 PushAfSpecAttrs {
29136 prev: Some(self),
29137 header_offset: Some(header_offset),
29138 }
29139 }
29140 pub fn push_group(mut self, value: u32) -> Self {
29141 push_header(self.as_rec_mut(), 27u16, 4 as u16);
29142 self.as_rec_mut().extend(value.to_ne_bytes());
29143 self
29144 }
29145 pub fn push_net_ns_fd(mut self, value: u32) -> Self {
29146 push_header(self.as_rec_mut(), 28u16, 4 as u16);
29147 self.as_rec_mut().extend(value.to_ne_bytes());
29148 self
29149 }
29150 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
29151 pub fn push_ext_mask(mut self, value: u32) -> Self {
29152 push_header(self.as_rec_mut(), 29u16, 4 as u16);
29153 self.as_rec_mut().extend(value.to_ne_bytes());
29154 self
29155 }
29156 pub fn push_promiscuity(mut self, value: u32) -> Self {
29157 push_header(self.as_rec_mut(), 30u16, 4 as u16);
29158 self.as_rec_mut().extend(value.to_ne_bytes());
29159 self
29160 }
29161 pub fn push_num_tx_queues(mut self, value: u32) -> Self {
29162 push_header(self.as_rec_mut(), 31u16, 4 as u16);
29163 self.as_rec_mut().extend(value.to_ne_bytes());
29164 self
29165 }
29166 pub fn push_num_rx_queues(mut self, value: u32) -> Self {
29167 push_header(self.as_rec_mut(), 32u16, 4 as u16);
29168 self.as_rec_mut().extend(value.to_ne_bytes());
29169 self
29170 }
29171 pub fn push_carrier(mut self, value: u8) -> Self {
29172 push_header(self.as_rec_mut(), 33u16, 1 as u16);
29173 self.as_rec_mut().extend(value.to_ne_bytes());
29174 self
29175 }
29176 pub fn push_phys_port_id(mut self, value: &[u8]) -> Self {
29177 push_header(self.as_rec_mut(), 34u16, value.len() as u16);
29178 self.as_rec_mut().extend(value);
29179 self
29180 }
29181 pub fn push_carrier_changes(mut self, value: u32) -> Self {
29182 push_header(self.as_rec_mut(), 35u16, 4 as u16);
29183 self.as_rec_mut().extend(value.to_ne_bytes());
29184 self
29185 }
29186 pub fn push_phys_switch_id(mut self, value: &[u8]) -> Self {
29187 push_header(self.as_rec_mut(), 36u16, value.len() as u16);
29188 self.as_rec_mut().extend(value);
29189 self
29190 }
29191 pub fn push_link_netnsid(mut self, value: i32) -> Self {
29192 push_header(self.as_rec_mut(), 37u16, 4 as u16);
29193 self.as_rec_mut().extend(value.to_ne_bytes());
29194 self
29195 }
29196 pub fn push_phys_port_name(mut self, value: &CStr) -> Self {
29197 push_header(
29198 self.as_rec_mut(),
29199 38u16,
29200 value.to_bytes_with_nul().len() as u16,
29201 );
29202 self.as_rec_mut().extend(value.to_bytes_with_nul());
29203 self
29204 }
29205 pub fn push_phys_port_name_bytes(mut self, value: &[u8]) -> Self {
29206 push_header(self.as_rec_mut(), 38u16, (value.len() + 1) as u16);
29207 self.as_rec_mut().extend(value);
29208 self.as_rec_mut().push(0);
29209 self
29210 }
29211 pub fn push_proto_down(mut self, value: u8) -> Self {
29212 push_header(self.as_rec_mut(), 39u16, 1 as u16);
29213 self.as_rec_mut().extend(value.to_ne_bytes());
29214 self
29215 }
29216 pub fn push_gso_max_segs(mut self, value: u32) -> Self {
29217 push_header(self.as_rec_mut(), 40u16, 4 as u16);
29218 self.as_rec_mut().extend(value.to_ne_bytes());
29219 self
29220 }
29221 pub fn push_gso_max_size(mut self, value: u32) -> Self {
29222 push_header(self.as_rec_mut(), 41u16, 4 as u16);
29223 self.as_rec_mut().extend(value.to_ne_bytes());
29224 self
29225 }
29226 pub fn push_pad(mut self, value: &[u8]) -> Self {
29227 push_header(self.as_rec_mut(), 42u16, value.len() as u16);
29228 self.as_rec_mut().extend(value);
29229 self
29230 }
29231 pub fn nested_xdp(mut self) -> PushXdpAttrs<Self> {
29232 let header_offset = push_nested_header(self.as_rec_mut(), 43u16);
29233 PushXdpAttrs {
29234 prev: Some(self),
29235 header_offset: Some(header_offset),
29236 }
29237 }
29238 pub fn push_event(mut self, value: u32) -> Self {
29239 push_header(self.as_rec_mut(), 44u16, 4 as u16);
29240 self.as_rec_mut().extend(value.to_ne_bytes());
29241 self
29242 }
29243 pub fn push_new_netnsid(mut self, value: i32) -> Self {
29244 push_header(self.as_rec_mut(), 45u16, 4 as u16);
29245 self.as_rec_mut().extend(value.to_ne_bytes());
29246 self
29247 }
29248 pub fn push_target_netnsid(mut self, value: i32) -> Self {
29249 push_header(self.as_rec_mut(), 46u16, 4 as u16);
29250 self.as_rec_mut().extend(value.to_ne_bytes());
29251 self
29252 }
29253 pub fn push_carrier_up_count(mut self, value: u32) -> Self {
29254 push_header(self.as_rec_mut(), 47u16, 4 as u16);
29255 self.as_rec_mut().extend(value.to_ne_bytes());
29256 self
29257 }
29258 pub fn push_carrier_down_count(mut self, value: u32) -> Self {
29259 push_header(self.as_rec_mut(), 48u16, 4 as u16);
29260 self.as_rec_mut().extend(value.to_ne_bytes());
29261 self
29262 }
29263 pub fn push_new_ifindex(mut self, value: i32) -> Self {
29264 push_header(self.as_rec_mut(), 49u16, 4 as u16);
29265 self.as_rec_mut().extend(value.to_ne_bytes());
29266 self
29267 }
29268 pub fn push_min_mtu(mut self, value: u32) -> Self {
29269 push_header(self.as_rec_mut(), 50u16, 4 as u16);
29270 self.as_rec_mut().extend(value.to_ne_bytes());
29271 self
29272 }
29273 pub fn push_max_mtu(mut self, value: u32) -> Self {
29274 push_header(self.as_rec_mut(), 51u16, 4 as u16);
29275 self.as_rec_mut().extend(value.to_ne_bytes());
29276 self
29277 }
29278 pub fn nested_prop_list(mut self) -> PushPropListLinkAttrs<Self> {
29279 let header_offset = push_nested_header(self.as_rec_mut(), 52u16);
29280 PushPropListLinkAttrs {
29281 prev: Some(self),
29282 header_offset: Some(header_offset),
29283 }
29284 }
29285 pub fn push_perm_address(mut self, value: &[u8]) -> Self {
29286 push_header(self.as_rec_mut(), 54u16, value.len() as u16);
29287 self.as_rec_mut().extend(value);
29288 self
29289 }
29290 pub fn push_proto_down_reason(mut self, value: &CStr) -> Self {
29291 push_header(
29292 self.as_rec_mut(),
29293 55u16,
29294 value.to_bytes_with_nul().len() as u16,
29295 );
29296 self.as_rec_mut().extend(value.to_bytes_with_nul());
29297 self
29298 }
29299 pub fn push_proto_down_reason_bytes(mut self, value: &[u8]) -> Self {
29300 push_header(self.as_rec_mut(), 55u16, (value.len() + 1) as u16);
29301 self.as_rec_mut().extend(value);
29302 self.as_rec_mut().push(0);
29303 self
29304 }
29305 pub fn push_parent_dev_name(mut self, value: &CStr) -> Self {
29306 push_header(
29307 self.as_rec_mut(),
29308 56u16,
29309 value.to_bytes_with_nul().len() as u16,
29310 );
29311 self.as_rec_mut().extend(value.to_bytes_with_nul());
29312 self
29313 }
29314 pub fn push_parent_dev_name_bytes(mut self, value: &[u8]) -> Self {
29315 push_header(self.as_rec_mut(), 56u16, (value.len() + 1) as u16);
29316 self.as_rec_mut().extend(value);
29317 self.as_rec_mut().push(0);
29318 self
29319 }
29320 pub fn push_parent_dev_bus_name(mut self, value: &CStr) -> Self {
29321 push_header(
29322 self.as_rec_mut(),
29323 57u16,
29324 value.to_bytes_with_nul().len() as u16,
29325 );
29326 self.as_rec_mut().extend(value.to_bytes_with_nul());
29327 self
29328 }
29329 pub fn push_parent_dev_bus_name_bytes(mut self, value: &[u8]) -> Self {
29330 push_header(self.as_rec_mut(), 57u16, (value.len() + 1) as u16);
29331 self.as_rec_mut().extend(value);
29332 self.as_rec_mut().push(0);
29333 self
29334 }
29335 pub fn push_gro_max_size(mut self, value: u32) -> Self {
29336 push_header(self.as_rec_mut(), 58u16, 4 as u16);
29337 self.as_rec_mut().extend(value.to_ne_bytes());
29338 self
29339 }
29340 pub fn push_tso_max_size(mut self, value: u32) -> Self {
29341 push_header(self.as_rec_mut(), 59u16, 4 as u16);
29342 self.as_rec_mut().extend(value.to_ne_bytes());
29343 self
29344 }
29345 pub fn push_tso_max_segs(mut self, value: u32) -> Self {
29346 push_header(self.as_rec_mut(), 60u16, 4 as u16);
29347 self.as_rec_mut().extend(value.to_ne_bytes());
29348 self
29349 }
29350 pub fn push_allmulti(mut self, value: u32) -> Self {
29351 push_header(self.as_rec_mut(), 61u16, 4 as u16);
29352 self.as_rec_mut().extend(value.to_ne_bytes());
29353 self
29354 }
29355 pub fn push_devlink_port(mut self, value: &[u8]) -> Self {
29356 push_header(self.as_rec_mut(), 62u16, value.len() as u16);
29357 self.as_rec_mut().extend(value);
29358 self
29359 }
29360 pub fn push_gso_ipv4_max_size(mut self, value: u32) -> Self {
29361 push_header(self.as_rec_mut(), 63u16, 4 as u16);
29362 self.as_rec_mut().extend(value.to_ne_bytes());
29363 self
29364 }
29365 pub fn push_gro_ipv4_max_size(mut self, value: u32) -> Self {
29366 push_header(self.as_rec_mut(), 64u16, 4 as u16);
29367 self.as_rec_mut().extend(value.to_ne_bytes());
29368 self
29369 }
29370 pub fn nested_dpll_pin(mut self) -> PushLinkDpllPinAttrs<Self> {
29371 let header_offset = push_nested_header(self.as_rec_mut(), 65u16);
29372 PushLinkDpllPinAttrs {
29373 prev: Some(self),
29374 header_offset: Some(header_offset),
29375 }
29376 }
29377 #[doc = "EDT offload horizon supported by the device (in nsec)."]
29378 pub fn push_max_pacing_offload_horizon(mut self, value: u32) -> Self {
29379 push_header(self.as_rec_mut(), 66u16, 4 as u16);
29380 self.as_rec_mut().extend(value.to_ne_bytes());
29381 self
29382 }
29383 pub fn push_netns_immutable(mut self, value: u8) -> Self {
29384 push_header(self.as_rec_mut(), 67u16, 1 as u16);
29385 self.as_rec_mut().extend(value.to_ne_bytes());
29386 self
29387 }
29388}
29389impl<Prev: Rec> Drop for PushOpSetlinkDoRequest<Prev> {
29390 fn drop(&mut self) {
29391 if let Some(prev) = &mut self.prev {
29392 if let Some(header_offset) = &self.header_offset {
29393 finalize_nested_header(prev.as_rec_mut(), *header_offset);
29394 }
29395 }
29396 }
29397}
29398#[doc = "Set information about a link."]
29399#[derive(Clone)]
29400pub enum OpSetlinkDoRequest<'a> {
29401 Address(&'a [u8]),
29402 Broadcast(&'a [u8]),
29403 Ifname(&'a CStr),
29404 Mtu(u32),
29405 Link(u32),
29406 Qdisc(&'a CStr),
29407 Stats(PushRtnlLinkStats),
29408 Cost(&'a CStr),
29409 Priority(&'a CStr),
29410 Master(u32),
29411 Wireless(&'a CStr),
29412 Protinfo(&'a CStr),
29413 Txqlen(u32),
29414 Map(PushRtnlLinkIfmap),
29415 Weight(u32),
29416 Operstate(u8),
29417 Linkmode(u8),
29418 Linkinfo(IterableLinkinfoAttrs<'a>),
29419 NetNsPid(u32),
29420 Ifalias(&'a CStr),
29421 NumVf(u32),
29422 VfinfoList(IterableVfinfoListAttrs<'a>),
29423 Stats64(PushRtnlLinkStats64),
29424 VfPorts(IterableVfPortsAttrs<'a>),
29425 PortSelf(IterablePortSelfAttrs<'a>),
29426 AfSpec(IterableAfSpecAttrs<'a>),
29427 Group(u32),
29428 NetNsFd(u32),
29429 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
29430 ExtMask(u32),
29431 Promiscuity(u32),
29432 NumTxQueues(u32),
29433 NumRxQueues(u32),
29434 Carrier(u8),
29435 PhysPortId(&'a [u8]),
29436 CarrierChanges(u32),
29437 PhysSwitchId(&'a [u8]),
29438 LinkNetnsid(i32),
29439 PhysPortName(&'a CStr),
29440 ProtoDown(u8),
29441 GsoMaxSegs(u32),
29442 GsoMaxSize(u32),
29443 Pad(&'a [u8]),
29444 Xdp(IterableXdpAttrs<'a>),
29445 Event(u32),
29446 NewNetnsid(i32),
29447 TargetNetnsid(i32),
29448 CarrierUpCount(u32),
29449 CarrierDownCount(u32),
29450 NewIfindex(i32),
29451 MinMtu(u32),
29452 MaxMtu(u32),
29453 PropList(IterablePropListLinkAttrs<'a>),
29454 PermAddress(&'a [u8]),
29455 ProtoDownReason(&'a CStr),
29456 ParentDevName(&'a CStr),
29457 ParentDevBusName(&'a CStr),
29458 GroMaxSize(u32),
29459 TsoMaxSize(u32),
29460 TsoMaxSegs(u32),
29461 Allmulti(u32),
29462 DevlinkPort(&'a [u8]),
29463 GsoIpv4MaxSize(u32),
29464 GroIpv4MaxSize(u32),
29465 DpllPin(IterableLinkDpllPinAttrs<'a>),
29466 #[doc = "EDT offload horizon supported by the device (in nsec)."]
29467 MaxPacingOffloadHorizon(u32),
29468 NetnsImmutable(u8),
29469}
29470impl<'a> IterableOpSetlinkDoRequest<'a> {
29471 pub fn get_address(&self) -> Result<&'a [u8], ErrorContext> {
29472 let mut iter = self.clone();
29473 iter.pos = 0;
29474 for attr in iter {
29475 if let OpSetlinkDoRequest::Address(val) = attr? {
29476 return Ok(val);
29477 }
29478 }
29479 Err(ErrorContext::new_missing(
29480 "OpSetlinkDoRequest",
29481 "Address",
29482 self.orig_loc,
29483 self.buf.as_ptr() as usize,
29484 ))
29485 }
29486 pub fn get_broadcast(&self) -> Result<&'a [u8], ErrorContext> {
29487 let mut iter = self.clone();
29488 iter.pos = 0;
29489 for attr in iter {
29490 if let OpSetlinkDoRequest::Broadcast(val) = attr? {
29491 return Ok(val);
29492 }
29493 }
29494 Err(ErrorContext::new_missing(
29495 "OpSetlinkDoRequest",
29496 "Broadcast",
29497 self.orig_loc,
29498 self.buf.as_ptr() as usize,
29499 ))
29500 }
29501 pub fn get_ifname(&self) -> Result<&'a CStr, ErrorContext> {
29502 let mut iter = self.clone();
29503 iter.pos = 0;
29504 for attr in iter {
29505 if let OpSetlinkDoRequest::Ifname(val) = attr? {
29506 return Ok(val);
29507 }
29508 }
29509 Err(ErrorContext::new_missing(
29510 "OpSetlinkDoRequest",
29511 "Ifname",
29512 self.orig_loc,
29513 self.buf.as_ptr() as usize,
29514 ))
29515 }
29516 pub fn get_mtu(&self) -> Result<u32, ErrorContext> {
29517 let mut iter = self.clone();
29518 iter.pos = 0;
29519 for attr in iter {
29520 if let OpSetlinkDoRequest::Mtu(val) = attr? {
29521 return Ok(val);
29522 }
29523 }
29524 Err(ErrorContext::new_missing(
29525 "OpSetlinkDoRequest",
29526 "Mtu",
29527 self.orig_loc,
29528 self.buf.as_ptr() as usize,
29529 ))
29530 }
29531 pub fn get_link(&self) -> Result<u32, ErrorContext> {
29532 let mut iter = self.clone();
29533 iter.pos = 0;
29534 for attr in iter {
29535 if let OpSetlinkDoRequest::Link(val) = attr? {
29536 return Ok(val);
29537 }
29538 }
29539 Err(ErrorContext::new_missing(
29540 "OpSetlinkDoRequest",
29541 "Link",
29542 self.orig_loc,
29543 self.buf.as_ptr() as usize,
29544 ))
29545 }
29546 pub fn get_qdisc(&self) -> Result<&'a CStr, ErrorContext> {
29547 let mut iter = self.clone();
29548 iter.pos = 0;
29549 for attr in iter {
29550 if let OpSetlinkDoRequest::Qdisc(val) = attr? {
29551 return Ok(val);
29552 }
29553 }
29554 Err(ErrorContext::new_missing(
29555 "OpSetlinkDoRequest",
29556 "Qdisc",
29557 self.orig_loc,
29558 self.buf.as_ptr() as usize,
29559 ))
29560 }
29561 pub fn get_stats(&self) -> Result<PushRtnlLinkStats, ErrorContext> {
29562 let mut iter = self.clone();
29563 iter.pos = 0;
29564 for attr in iter {
29565 if let OpSetlinkDoRequest::Stats(val) = attr? {
29566 return Ok(val);
29567 }
29568 }
29569 Err(ErrorContext::new_missing(
29570 "OpSetlinkDoRequest",
29571 "Stats",
29572 self.orig_loc,
29573 self.buf.as_ptr() as usize,
29574 ))
29575 }
29576 pub fn get_cost(&self) -> Result<&'a CStr, ErrorContext> {
29577 let mut iter = self.clone();
29578 iter.pos = 0;
29579 for attr in iter {
29580 if let OpSetlinkDoRequest::Cost(val) = attr? {
29581 return Ok(val);
29582 }
29583 }
29584 Err(ErrorContext::new_missing(
29585 "OpSetlinkDoRequest",
29586 "Cost",
29587 self.orig_loc,
29588 self.buf.as_ptr() as usize,
29589 ))
29590 }
29591 pub fn get_priority(&self) -> Result<&'a CStr, ErrorContext> {
29592 let mut iter = self.clone();
29593 iter.pos = 0;
29594 for attr in iter {
29595 if let OpSetlinkDoRequest::Priority(val) = attr? {
29596 return Ok(val);
29597 }
29598 }
29599 Err(ErrorContext::new_missing(
29600 "OpSetlinkDoRequest",
29601 "Priority",
29602 self.orig_loc,
29603 self.buf.as_ptr() as usize,
29604 ))
29605 }
29606 pub fn get_master(&self) -> Result<u32, ErrorContext> {
29607 let mut iter = self.clone();
29608 iter.pos = 0;
29609 for attr in iter {
29610 if let OpSetlinkDoRequest::Master(val) = attr? {
29611 return Ok(val);
29612 }
29613 }
29614 Err(ErrorContext::new_missing(
29615 "OpSetlinkDoRequest",
29616 "Master",
29617 self.orig_loc,
29618 self.buf.as_ptr() as usize,
29619 ))
29620 }
29621 pub fn get_wireless(&self) -> Result<&'a CStr, ErrorContext> {
29622 let mut iter = self.clone();
29623 iter.pos = 0;
29624 for attr in iter {
29625 if let OpSetlinkDoRequest::Wireless(val) = attr? {
29626 return Ok(val);
29627 }
29628 }
29629 Err(ErrorContext::new_missing(
29630 "OpSetlinkDoRequest",
29631 "Wireless",
29632 self.orig_loc,
29633 self.buf.as_ptr() as usize,
29634 ))
29635 }
29636 pub fn get_protinfo(&self) -> Result<&'a CStr, ErrorContext> {
29637 let mut iter = self.clone();
29638 iter.pos = 0;
29639 for attr in iter {
29640 if let OpSetlinkDoRequest::Protinfo(val) = attr? {
29641 return Ok(val);
29642 }
29643 }
29644 Err(ErrorContext::new_missing(
29645 "OpSetlinkDoRequest",
29646 "Protinfo",
29647 self.orig_loc,
29648 self.buf.as_ptr() as usize,
29649 ))
29650 }
29651 pub fn get_txqlen(&self) -> Result<u32, ErrorContext> {
29652 let mut iter = self.clone();
29653 iter.pos = 0;
29654 for attr in iter {
29655 if let OpSetlinkDoRequest::Txqlen(val) = attr? {
29656 return Ok(val);
29657 }
29658 }
29659 Err(ErrorContext::new_missing(
29660 "OpSetlinkDoRequest",
29661 "Txqlen",
29662 self.orig_loc,
29663 self.buf.as_ptr() as usize,
29664 ))
29665 }
29666 pub fn get_map(&self) -> Result<PushRtnlLinkIfmap, ErrorContext> {
29667 let mut iter = self.clone();
29668 iter.pos = 0;
29669 for attr in iter {
29670 if let OpSetlinkDoRequest::Map(val) = attr? {
29671 return Ok(val);
29672 }
29673 }
29674 Err(ErrorContext::new_missing(
29675 "OpSetlinkDoRequest",
29676 "Map",
29677 self.orig_loc,
29678 self.buf.as_ptr() as usize,
29679 ))
29680 }
29681 pub fn get_weight(&self) -> Result<u32, ErrorContext> {
29682 let mut iter = self.clone();
29683 iter.pos = 0;
29684 for attr in iter {
29685 if let OpSetlinkDoRequest::Weight(val) = attr? {
29686 return Ok(val);
29687 }
29688 }
29689 Err(ErrorContext::new_missing(
29690 "OpSetlinkDoRequest",
29691 "Weight",
29692 self.orig_loc,
29693 self.buf.as_ptr() as usize,
29694 ))
29695 }
29696 pub fn get_operstate(&self) -> Result<u8, ErrorContext> {
29697 let mut iter = self.clone();
29698 iter.pos = 0;
29699 for attr in iter {
29700 if let OpSetlinkDoRequest::Operstate(val) = attr? {
29701 return Ok(val);
29702 }
29703 }
29704 Err(ErrorContext::new_missing(
29705 "OpSetlinkDoRequest",
29706 "Operstate",
29707 self.orig_loc,
29708 self.buf.as_ptr() as usize,
29709 ))
29710 }
29711 pub fn get_linkmode(&self) -> Result<u8, ErrorContext> {
29712 let mut iter = self.clone();
29713 iter.pos = 0;
29714 for attr in iter {
29715 if let OpSetlinkDoRequest::Linkmode(val) = attr? {
29716 return Ok(val);
29717 }
29718 }
29719 Err(ErrorContext::new_missing(
29720 "OpSetlinkDoRequest",
29721 "Linkmode",
29722 self.orig_loc,
29723 self.buf.as_ptr() as usize,
29724 ))
29725 }
29726 pub fn get_linkinfo(&self) -> Result<IterableLinkinfoAttrs<'a>, ErrorContext> {
29727 let mut iter = self.clone();
29728 iter.pos = 0;
29729 for attr in iter {
29730 if let OpSetlinkDoRequest::Linkinfo(val) = attr? {
29731 return Ok(val);
29732 }
29733 }
29734 Err(ErrorContext::new_missing(
29735 "OpSetlinkDoRequest",
29736 "Linkinfo",
29737 self.orig_loc,
29738 self.buf.as_ptr() as usize,
29739 ))
29740 }
29741 pub fn get_net_ns_pid(&self) -> Result<u32, ErrorContext> {
29742 let mut iter = self.clone();
29743 iter.pos = 0;
29744 for attr in iter {
29745 if let OpSetlinkDoRequest::NetNsPid(val) = attr? {
29746 return Ok(val);
29747 }
29748 }
29749 Err(ErrorContext::new_missing(
29750 "OpSetlinkDoRequest",
29751 "NetNsPid",
29752 self.orig_loc,
29753 self.buf.as_ptr() as usize,
29754 ))
29755 }
29756 pub fn get_ifalias(&self) -> Result<&'a CStr, ErrorContext> {
29757 let mut iter = self.clone();
29758 iter.pos = 0;
29759 for attr in iter {
29760 if let OpSetlinkDoRequest::Ifalias(val) = attr? {
29761 return Ok(val);
29762 }
29763 }
29764 Err(ErrorContext::new_missing(
29765 "OpSetlinkDoRequest",
29766 "Ifalias",
29767 self.orig_loc,
29768 self.buf.as_ptr() as usize,
29769 ))
29770 }
29771 pub fn get_num_vf(&self) -> Result<u32, ErrorContext> {
29772 let mut iter = self.clone();
29773 iter.pos = 0;
29774 for attr in iter {
29775 if let OpSetlinkDoRequest::NumVf(val) = attr? {
29776 return Ok(val);
29777 }
29778 }
29779 Err(ErrorContext::new_missing(
29780 "OpSetlinkDoRequest",
29781 "NumVf",
29782 self.orig_loc,
29783 self.buf.as_ptr() as usize,
29784 ))
29785 }
29786 pub fn get_vfinfo_list(&self) -> Result<IterableVfinfoListAttrs<'a>, ErrorContext> {
29787 let mut iter = self.clone();
29788 iter.pos = 0;
29789 for attr in iter {
29790 if let OpSetlinkDoRequest::VfinfoList(val) = attr? {
29791 return Ok(val);
29792 }
29793 }
29794 Err(ErrorContext::new_missing(
29795 "OpSetlinkDoRequest",
29796 "VfinfoList",
29797 self.orig_loc,
29798 self.buf.as_ptr() as usize,
29799 ))
29800 }
29801 pub fn get_stats64(&self) -> Result<PushRtnlLinkStats64, ErrorContext> {
29802 let mut iter = self.clone();
29803 iter.pos = 0;
29804 for attr in iter {
29805 if let OpSetlinkDoRequest::Stats64(val) = attr? {
29806 return Ok(val);
29807 }
29808 }
29809 Err(ErrorContext::new_missing(
29810 "OpSetlinkDoRequest",
29811 "Stats64",
29812 self.orig_loc,
29813 self.buf.as_ptr() as usize,
29814 ))
29815 }
29816 pub fn get_vf_ports(&self) -> Result<IterableVfPortsAttrs<'a>, ErrorContext> {
29817 let mut iter = self.clone();
29818 iter.pos = 0;
29819 for attr in iter {
29820 if let OpSetlinkDoRequest::VfPorts(val) = attr? {
29821 return Ok(val);
29822 }
29823 }
29824 Err(ErrorContext::new_missing(
29825 "OpSetlinkDoRequest",
29826 "VfPorts",
29827 self.orig_loc,
29828 self.buf.as_ptr() as usize,
29829 ))
29830 }
29831 pub fn get_port_self(&self) -> Result<IterablePortSelfAttrs<'a>, ErrorContext> {
29832 let mut iter = self.clone();
29833 iter.pos = 0;
29834 for attr in iter {
29835 if let OpSetlinkDoRequest::PortSelf(val) = attr? {
29836 return Ok(val);
29837 }
29838 }
29839 Err(ErrorContext::new_missing(
29840 "OpSetlinkDoRequest",
29841 "PortSelf",
29842 self.orig_loc,
29843 self.buf.as_ptr() as usize,
29844 ))
29845 }
29846 pub fn get_af_spec(&self) -> Result<IterableAfSpecAttrs<'a>, ErrorContext> {
29847 let mut iter = self.clone();
29848 iter.pos = 0;
29849 for attr in iter {
29850 if let OpSetlinkDoRequest::AfSpec(val) = attr? {
29851 return Ok(val);
29852 }
29853 }
29854 Err(ErrorContext::new_missing(
29855 "OpSetlinkDoRequest",
29856 "AfSpec",
29857 self.orig_loc,
29858 self.buf.as_ptr() as usize,
29859 ))
29860 }
29861 pub fn get_group(&self) -> Result<u32, ErrorContext> {
29862 let mut iter = self.clone();
29863 iter.pos = 0;
29864 for attr in iter {
29865 if let OpSetlinkDoRequest::Group(val) = attr? {
29866 return Ok(val);
29867 }
29868 }
29869 Err(ErrorContext::new_missing(
29870 "OpSetlinkDoRequest",
29871 "Group",
29872 self.orig_loc,
29873 self.buf.as_ptr() as usize,
29874 ))
29875 }
29876 pub fn get_net_ns_fd(&self) -> Result<u32, ErrorContext> {
29877 let mut iter = self.clone();
29878 iter.pos = 0;
29879 for attr in iter {
29880 if let OpSetlinkDoRequest::NetNsFd(val) = attr? {
29881 return Ok(val);
29882 }
29883 }
29884 Err(ErrorContext::new_missing(
29885 "OpSetlinkDoRequest",
29886 "NetNsFd",
29887 self.orig_loc,
29888 self.buf.as_ptr() as usize,
29889 ))
29890 }
29891 #[doc = "Associated type: \"RtextFilter\" (1 bit per enumeration)"]
29892 pub fn get_ext_mask(&self) -> Result<u32, ErrorContext> {
29893 let mut iter = self.clone();
29894 iter.pos = 0;
29895 for attr in iter {
29896 if let OpSetlinkDoRequest::ExtMask(val) = attr? {
29897 return Ok(val);
29898 }
29899 }
29900 Err(ErrorContext::new_missing(
29901 "OpSetlinkDoRequest",
29902 "ExtMask",
29903 self.orig_loc,
29904 self.buf.as_ptr() as usize,
29905 ))
29906 }
29907 pub fn get_promiscuity(&self) -> Result<u32, ErrorContext> {
29908 let mut iter = self.clone();
29909 iter.pos = 0;
29910 for attr in iter {
29911 if let OpSetlinkDoRequest::Promiscuity(val) = attr? {
29912 return Ok(val);
29913 }
29914 }
29915 Err(ErrorContext::new_missing(
29916 "OpSetlinkDoRequest",
29917 "Promiscuity",
29918 self.orig_loc,
29919 self.buf.as_ptr() as usize,
29920 ))
29921 }
29922 pub fn get_num_tx_queues(&self) -> Result<u32, ErrorContext> {
29923 let mut iter = self.clone();
29924 iter.pos = 0;
29925 for attr in iter {
29926 if let OpSetlinkDoRequest::NumTxQueues(val) = attr? {
29927 return Ok(val);
29928 }
29929 }
29930 Err(ErrorContext::new_missing(
29931 "OpSetlinkDoRequest",
29932 "NumTxQueues",
29933 self.orig_loc,
29934 self.buf.as_ptr() as usize,
29935 ))
29936 }
29937 pub fn get_num_rx_queues(&self) -> Result<u32, ErrorContext> {
29938 let mut iter = self.clone();
29939 iter.pos = 0;
29940 for attr in iter {
29941 if let OpSetlinkDoRequest::NumRxQueues(val) = attr? {
29942 return Ok(val);
29943 }
29944 }
29945 Err(ErrorContext::new_missing(
29946 "OpSetlinkDoRequest",
29947 "NumRxQueues",
29948 self.orig_loc,
29949 self.buf.as_ptr() as usize,
29950 ))
29951 }
29952 pub fn get_carrier(&self) -> Result<u8, ErrorContext> {
29953 let mut iter = self.clone();
29954 iter.pos = 0;
29955 for attr in iter {
29956 if let OpSetlinkDoRequest::Carrier(val) = attr? {
29957 return Ok(val);
29958 }
29959 }
29960 Err(ErrorContext::new_missing(
29961 "OpSetlinkDoRequest",
29962 "Carrier",
29963 self.orig_loc,
29964 self.buf.as_ptr() as usize,
29965 ))
29966 }
29967 pub fn get_phys_port_id(&self) -> Result<&'a [u8], ErrorContext> {
29968 let mut iter = self.clone();
29969 iter.pos = 0;
29970 for attr in iter {
29971 if let OpSetlinkDoRequest::PhysPortId(val) = attr? {
29972 return Ok(val);
29973 }
29974 }
29975 Err(ErrorContext::new_missing(
29976 "OpSetlinkDoRequest",
29977 "PhysPortId",
29978 self.orig_loc,
29979 self.buf.as_ptr() as usize,
29980 ))
29981 }
29982 pub fn get_carrier_changes(&self) -> Result<u32, ErrorContext> {
29983 let mut iter = self.clone();
29984 iter.pos = 0;
29985 for attr in iter {
29986 if let OpSetlinkDoRequest::CarrierChanges(val) = attr? {
29987 return Ok(val);
29988 }
29989 }
29990 Err(ErrorContext::new_missing(
29991 "OpSetlinkDoRequest",
29992 "CarrierChanges",
29993 self.orig_loc,
29994 self.buf.as_ptr() as usize,
29995 ))
29996 }
29997 pub fn get_phys_switch_id(&self) -> Result<&'a [u8], ErrorContext> {
29998 let mut iter = self.clone();
29999 iter.pos = 0;
30000 for attr in iter {
30001 if let OpSetlinkDoRequest::PhysSwitchId(val) = attr? {
30002 return Ok(val);
30003 }
30004 }
30005 Err(ErrorContext::new_missing(
30006 "OpSetlinkDoRequest",
30007 "PhysSwitchId",
30008 self.orig_loc,
30009 self.buf.as_ptr() as usize,
30010 ))
30011 }
30012 pub fn get_link_netnsid(&self) -> Result<i32, ErrorContext> {
30013 let mut iter = self.clone();
30014 iter.pos = 0;
30015 for attr in iter {
30016 if let OpSetlinkDoRequest::LinkNetnsid(val) = attr? {
30017 return Ok(val);
30018 }
30019 }
30020 Err(ErrorContext::new_missing(
30021 "OpSetlinkDoRequest",
30022 "LinkNetnsid",
30023 self.orig_loc,
30024 self.buf.as_ptr() as usize,
30025 ))
30026 }
30027 pub fn get_phys_port_name(&self) -> Result<&'a CStr, ErrorContext> {
30028 let mut iter = self.clone();
30029 iter.pos = 0;
30030 for attr in iter {
30031 if let OpSetlinkDoRequest::PhysPortName(val) = attr? {
30032 return Ok(val);
30033 }
30034 }
30035 Err(ErrorContext::new_missing(
30036 "OpSetlinkDoRequest",
30037 "PhysPortName",
30038 self.orig_loc,
30039 self.buf.as_ptr() as usize,
30040 ))
30041 }
30042 pub fn get_proto_down(&self) -> Result<u8, ErrorContext> {
30043 let mut iter = self.clone();
30044 iter.pos = 0;
30045 for attr in iter {
30046 if let OpSetlinkDoRequest::ProtoDown(val) = attr? {
30047 return Ok(val);
30048 }
30049 }
30050 Err(ErrorContext::new_missing(
30051 "OpSetlinkDoRequest",
30052 "ProtoDown",
30053 self.orig_loc,
30054 self.buf.as_ptr() as usize,
30055 ))
30056 }
30057 pub fn get_gso_max_segs(&self) -> Result<u32, ErrorContext> {
30058 let mut iter = self.clone();
30059 iter.pos = 0;
30060 for attr in iter {
30061 if let OpSetlinkDoRequest::GsoMaxSegs(val) = attr? {
30062 return Ok(val);
30063 }
30064 }
30065 Err(ErrorContext::new_missing(
30066 "OpSetlinkDoRequest",
30067 "GsoMaxSegs",
30068 self.orig_loc,
30069 self.buf.as_ptr() as usize,
30070 ))
30071 }
30072 pub fn get_gso_max_size(&self) -> Result<u32, ErrorContext> {
30073 let mut iter = self.clone();
30074 iter.pos = 0;
30075 for attr in iter {
30076 if let OpSetlinkDoRequest::GsoMaxSize(val) = attr? {
30077 return Ok(val);
30078 }
30079 }
30080 Err(ErrorContext::new_missing(
30081 "OpSetlinkDoRequest",
30082 "GsoMaxSize",
30083 self.orig_loc,
30084 self.buf.as_ptr() as usize,
30085 ))
30086 }
30087 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
30088 let mut iter = self.clone();
30089 iter.pos = 0;
30090 for attr in iter {
30091 if let OpSetlinkDoRequest::Pad(val) = attr? {
30092 return Ok(val);
30093 }
30094 }
30095 Err(ErrorContext::new_missing(
30096 "OpSetlinkDoRequest",
30097 "Pad",
30098 self.orig_loc,
30099 self.buf.as_ptr() as usize,
30100 ))
30101 }
30102 pub fn get_xdp(&self) -> Result<IterableXdpAttrs<'a>, ErrorContext> {
30103 let mut iter = self.clone();
30104 iter.pos = 0;
30105 for attr in iter {
30106 if let OpSetlinkDoRequest::Xdp(val) = attr? {
30107 return Ok(val);
30108 }
30109 }
30110 Err(ErrorContext::new_missing(
30111 "OpSetlinkDoRequest",
30112 "Xdp",
30113 self.orig_loc,
30114 self.buf.as_ptr() as usize,
30115 ))
30116 }
30117 pub fn get_event(&self) -> Result<u32, ErrorContext> {
30118 let mut iter = self.clone();
30119 iter.pos = 0;
30120 for attr in iter {
30121 if let OpSetlinkDoRequest::Event(val) = attr? {
30122 return Ok(val);
30123 }
30124 }
30125 Err(ErrorContext::new_missing(
30126 "OpSetlinkDoRequest",
30127 "Event",
30128 self.orig_loc,
30129 self.buf.as_ptr() as usize,
30130 ))
30131 }
30132 pub fn get_new_netnsid(&self) -> Result<i32, ErrorContext> {
30133 let mut iter = self.clone();
30134 iter.pos = 0;
30135 for attr in iter {
30136 if let OpSetlinkDoRequest::NewNetnsid(val) = attr? {
30137 return Ok(val);
30138 }
30139 }
30140 Err(ErrorContext::new_missing(
30141 "OpSetlinkDoRequest",
30142 "NewNetnsid",
30143 self.orig_loc,
30144 self.buf.as_ptr() as usize,
30145 ))
30146 }
30147 pub fn get_target_netnsid(&self) -> Result<i32, ErrorContext> {
30148 let mut iter = self.clone();
30149 iter.pos = 0;
30150 for attr in iter {
30151 if let OpSetlinkDoRequest::TargetNetnsid(val) = attr? {
30152 return Ok(val);
30153 }
30154 }
30155 Err(ErrorContext::new_missing(
30156 "OpSetlinkDoRequest",
30157 "TargetNetnsid",
30158 self.orig_loc,
30159 self.buf.as_ptr() as usize,
30160 ))
30161 }
30162 pub fn get_carrier_up_count(&self) -> Result<u32, ErrorContext> {
30163 let mut iter = self.clone();
30164 iter.pos = 0;
30165 for attr in iter {
30166 if let OpSetlinkDoRequest::CarrierUpCount(val) = attr? {
30167 return Ok(val);
30168 }
30169 }
30170 Err(ErrorContext::new_missing(
30171 "OpSetlinkDoRequest",
30172 "CarrierUpCount",
30173 self.orig_loc,
30174 self.buf.as_ptr() as usize,
30175 ))
30176 }
30177 pub fn get_carrier_down_count(&self) -> Result<u32, ErrorContext> {
30178 let mut iter = self.clone();
30179 iter.pos = 0;
30180 for attr in iter {
30181 if let OpSetlinkDoRequest::CarrierDownCount(val) = attr? {
30182 return Ok(val);
30183 }
30184 }
30185 Err(ErrorContext::new_missing(
30186 "OpSetlinkDoRequest",
30187 "CarrierDownCount",
30188 self.orig_loc,
30189 self.buf.as_ptr() as usize,
30190 ))
30191 }
30192 pub fn get_new_ifindex(&self) -> Result<i32, ErrorContext> {
30193 let mut iter = self.clone();
30194 iter.pos = 0;
30195 for attr in iter {
30196 if let OpSetlinkDoRequest::NewIfindex(val) = attr? {
30197 return Ok(val);
30198 }
30199 }
30200 Err(ErrorContext::new_missing(
30201 "OpSetlinkDoRequest",
30202 "NewIfindex",
30203 self.orig_loc,
30204 self.buf.as_ptr() as usize,
30205 ))
30206 }
30207 pub fn get_min_mtu(&self) -> Result<u32, ErrorContext> {
30208 let mut iter = self.clone();
30209 iter.pos = 0;
30210 for attr in iter {
30211 if let OpSetlinkDoRequest::MinMtu(val) = attr? {
30212 return Ok(val);
30213 }
30214 }
30215 Err(ErrorContext::new_missing(
30216 "OpSetlinkDoRequest",
30217 "MinMtu",
30218 self.orig_loc,
30219 self.buf.as_ptr() as usize,
30220 ))
30221 }
30222 pub fn get_max_mtu(&self) -> Result<u32, ErrorContext> {
30223 let mut iter = self.clone();
30224 iter.pos = 0;
30225 for attr in iter {
30226 if let OpSetlinkDoRequest::MaxMtu(val) = attr? {
30227 return Ok(val);
30228 }
30229 }
30230 Err(ErrorContext::new_missing(
30231 "OpSetlinkDoRequest",
30232 "MaxMtu",
30233 self.orig_loc,
30234 self.buf.as_ptr() as usize,
30235 ))
30236 }
30237 pub fn get_prop_list(&self) -> Result<IterablePropListLinkAttrs<'a>, ErrorContext> {
30238 let mut iter = self.clone();
30239 iter.pos = 0;
30240 for attr in iter {
30241 if let OpSetlinkDoRequest::PropList(val) = attr? {
30242 return Ok(val);
30243 }
30244 }
30245 Err(ErrorContext::new_missing(
30246 "OpSetlinkDoRequest",
30247 "PropList",
30248 self.orig_loc,
30249 self.buf.as_ptr() as usize,
30250 ))
30251 }
30252 pub fn get_perm_address(&self) -> Result<&'a [u8], ErrorContext> {
30253 let mut iter = self.clone();
30254 iter.pos = 0;
30255 for attr in iter {
30256 if let OpSetlinkDoRequest::PermAddress(val) = attr? {
30257 return Ok(val);
30258 }
30259 }
30260 Err(ErrorContext::new_missing(
30261 "OpSetlinkDoRequest",
30262 "PermAddress",
30263 self.orig_loc,
30264 self.buf.as_ptr() as usize,
30265 ))
30266 }
30267 pub fn get_proto_down_reason(&self) -> Result<&'a CStr, ErrorContext> {
30268 let mut iter = self.clone();
30269 iter.pos = 0;
30270 for attr in iter {
30271 if let OpSetlinkDoRequest::ProtoDownReason(val) = attr? {
30272 return Ok(val);
30273 }
30274 }
30275 Err(ErrorContext::new_missing(
30276 "OpSetlinkDoRequest",
30277 "ProtoDownReason",
30278 self.orig_loc,
30279 self.buf.as_ptr() as usize,
30280 ))
30281 }
30282 pub fn get_parent_dev_name(&self) -> Result<&'a CStr, ErrorContext> {
30283 let mut iter = self.clone();
30284 iter.pos = 0;
30285 for attr in iter {
30286 if let OpSetlinkDoRequest::ParentDevName(val) = attr? {
30287 return Ok(val);
30288 }
30289 }
30290 Err(ErrorContext::new_missing(
30291 "OpSetlinkDoRequest",
30292 "ParentDevName",
30293 self.orig_loc,
30294 self.buf.as_ptr() as usize,
30295 ))
30296 }
30297 pub fn get_parent_dev_bus_name(&self) -> Result<&'a CStr, ErrorContext> {
30298 let mut iter = self.clone();
30299 iter.pos = 0;
30300 for attr in iter {
30301 if let OpSetlinkDoRequest::ParentDevBusName(val) = attr? {
30302 return Ok(val);
30303 }
30304 }
30305 Err(ErrorContext::new_missing(
30306 "OpSetlinkDoRequest",
30307 "ParentDevBusName",
30308 self.orig_loc,
30309 self.buf.as_ptr() as usize,
30310 ))
30311 }
30312 pub fn get_gro_max_size(&self) -> Result<u32, ErrorContext> {
30313 let mut iter = self.clone();
30314 iter.pos = 0;
30315 for attr in iter {
30316 if let OpSetlinkDoRequest::GroMaxSize(val) = attr? {
30317 return Ok(val);
30318 }
30319 }
30320 Err(ErrorContext::new_missing(
30321 "OpSetlinkDoRequest",
30322 "GroMaxSize",
30323 self.orig_loc,
30324 self.buf.as_ptr() as usize,
30325 ))
30326 }
30327 pub fn get_tso_max_size(&self) -> Result<u32, ErrorContext> {
30328 let mut iter = self.clone();
30329 iter.pos = 0;
30330 for attr in iter {
30331 if let OpSetlinkDoRequest::TsoMaxSize(val) = attr? {
30332 return Ok(val);
30333 }
30334 }
30335 Err(ErrorContext::new_missing(
30336 "OpSetlinkDoRequest",
30337 "TsoMaxSize",
30338 self.orig_loc,
30339 self.buf.as_ptr() as usize,
30340 ))
30341 }
30342 pub fn get_tso_max_segs(&self) -> Result<u32, ErrorContext> {
30343 let mut iter = self.clone();
30344 iter.pos = 0;
30345 for attr in iter {
30346 if let OpSetlinkDoRequest::TsoMaxSegs(val) = attr? {
30347 return Ok(val);
30348 }
30349 }
30350 Err(ErrorContext::new_missing(
30351 "OpSetlinkDoRequest",
30352 "TsoMaxSegs",
30353 self.orig_loc,
30354 self.buf.as_ptr() as usize,
30355 ))
30356 }
30357 pub fn get_allmulti(&self) -> Result<u32, ErrorContext> {
30358 let mut iter = self.clone();
30359 iter.pos = 0;
30360 for attr in iter {
30361 if let OpSetlinkDoRequest::Allmulti(val) = attr? {
30362 return Ok(val);
30363 }
30364 }
30365 Err(ErrorContext::new_missing(
30366 "OpSetlinkDoRequest",
30367 "Allmulti",
30368 self.orig_loc,
30369 self.buf.as_ptr() as usize,
30370 ))
30371 }
30372 pub fn get_devlink_port(&self) -> Result<&'a [u8], ErrorContext> {
30373 let mut iter = self.clone();
30374 iter.pos = 0;
30375 for attr in iter {
30376 if let OpSetlinkDoRequest::DevlinkPort(val) = attr? {
30377 return Ok(val);
30378 }
30379 }
30380 Err(ErrorContext::new_missing(
30381 "OpSetlinkDoRequest",
30382 "DevlinkPort",
30383 self.orig_loc,
30384 self.buf.as_ptr() as usize,
30385 ))
30386 }
30387 pub fn get_gso_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
30388 let mut iter = self.clone();
30389 iter.pos = 0;
30390 for attr in iter {
30391 if let OpSetlinkDoRequest::GsoIpv4MaxSize(val) = attr? {
30392 return Ok(val);
30393 }
30394 }
30395 Err(ErrorContext::new_missing(
30396 "OpSetlinkDoRequest",
30397 "GsoIpv4MaxSize",
30398 self.orig_loc,
30399 self.buf.as_ptr() as usize,
30400 ))
30401 }
30402 pub fn get_gro_ipv4_max_size(&self) -> Result<u32, ErrorContext> {
30403 let mut iter = self.clone();
30404 iter.pos = 0;
30405 for attr in iter {
30406 if let OpSetlinkDoRequest::GroIpv4MaxSize(val) = attr? {
30407 return Ok(val);
30408 }
30409 }
30410 Err(ErrorContext::new_missing(
30411 "OpSetlinkDoRequest",
30412 "GroIpv4MaxSize",
30413 self.orig_loc,
30414 self.buf.as_ptr() as usize,
30415 ))
30416 }
30417 pub fn get_dpll_pin(&self) -> Result<IterableLinkDpllPinAttrs<'a>, ErrorContext> {
30418 let mut iter = self.clone();
30419 iter.pos = 0;
30420 for attr in iter {
30421 if let OpSetlinkDoRequest::DpllPin(val) = attr? {
30422 return Ok(val);
30423 }
30424 }
30425 Err(ErrorContext::new_missing(
30426 "OpSetlinkDoRequest",
30427 "DpllPin",
30428 self.orig_loc,
30429 self.buf.as_ptr() as usize,
30430 ))
30431 }
30432 #[doc = "EDT offload horizon supported by the device (in nsec)."]
30433 pub fn get_max_pacing_offload_horizon(&self) -> Result<u32, ErrorContext> {
30434 let mut iter = self.clone();
30435 iter.pos = 0;
30436 for attr in iter {
30437 if let OpSetlinkDoRequest::MaxPacingOffloadHorizon(val) = attr? {
30438 return Ok(val);
30439 }
30440 }
30441 Err(ErrorContext::new_missing(
30442 "OpSetlinkDoRequest",
30443 "MaxPacingOffloadHorizon",
30444 self.orig_loc,
30445 self.buf.as_ptr() as usize,
30446 ))
30447 }
30448 pub fn get_netns_immutable(&self) -> Result<u8, ErrorContext> {
30449 let mut iter = self.clone();
30450 iter.pos = 0;
30451 for attr in iter {
30452 if let OpSetlinkDoRequest::NetnsImmutable(val) = attr? {
30453 return Ok(val);
30454 }
30455 }
30456 Err(ErrorContext::new_missing(
30457 "OpSetlinkDoRequest",
30458 "NetnsImmutable",
30459 self.orig_loc,
30460 self.buf.as_ptr() as usize,
30461 ))
30462 }
30463}
30464impl OpSetlinkDoRequest<'_> {
30465 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpSetlinkDoRequest<'a>) {
30466 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
30467 (
30468 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
30469 IterableOpSetlinkDoRequest::with_loc(attrs, buf.as_ptr() as usize),
30470 )
30471 }
30472 fn attr_from_type(r#type: u16) -> Option<&'static str> {
30473 LinkAttrs::attr_from_type(r#type)
30474 }
30475}
30476#[derive(Clone, Copy, Default)]
30477pub struct IterableOpSetlinkDoRequest<'a> {
30478 buf: &'a [u8],
30479 pos: usize,
30480 orig_loc: usize,
30481}
30482impl<'a> IterableOpSetlinkDoRequest<'a> {
30483 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
30484 Self {
30485 buf,
30486 pos: 0,
30487 orig_loc,
30488 }
30489 }
30490 pub fn get_buf(&self) -> &'a [u8] {
30491 self.buf
30492 }
30493}
30494impl<'a> Iterator for IterableOpSetlinkDoRequest<'a> {
30495 type Item = Result<OpSetlinkDoRequest<'a>, ErrorContext>;
30496 fn next(&mut self) -> Option<Self::Item> {
30497 if self.buf.len() == self.pos {
30498 return None;
30499 }
30500 let pos = self.pos;
30501 let mut r#type = None;
30502 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
30503 r#type = Some(header.r#type);
30504 let res = match header.r#type {
30505 1u16 => OpSetlinkDoRequest::Address({
30506 let res = Some(next);
30507 let Some(val) = res else { break };
30508 val
30509 }),
30510 2u16 => OpSetlinkDoRequest::Broadcast({
30511 let res = Some(next);
30512 let Some(val) = res else { break };
30513 val
30514 }),
30515 3u16 => OpSetlinkDoRequest::Ifname({
30516 let res = CStr::from_bytes_with_nul(next).ok();
30517 let Some(val) = res else { break };
30518 val
30519 }),
30520 4u16 => OpSetlinkDoRequest::Mtu({
30521 let res = parse_u32(next);
30522 let Some(val) = res else { break };
30523 val
30524 }),
30525 5u16 => OpSetlinkDoRequest::Link({
30526 let res = parse_u32(next);
30527 let Some(val) = res else { break };
30528 val
30529 }),
30530 6u16 => OpSetlinkDoRequest::Qdisc({
30531 let res = CStr::from_bytes_with_nul(next).ok();
30532 let Some(val) = res else { break };
30533 val
30534 }),
30535 7u16 => OpSetlinkDoRequest::Stats({
30536 let res = PushRtnlLinkStats::new_from_slice(next);
30537 let Some(val) = res else { break };
30538 val
30539 }),
30540 8u16 => OpSetlinkDoRequest::Cost({
30541 let res = CStr::from_bytes_with_nul(next).ok();
30542 let Some(val) = res else { break };
30543 val
30544 }),
30545 9u16 => OpSetlinkDoRequest::Priority({
30546 let res = CStr::from_bytes_with_nul(next).ok();
30547 let Some(val) = res else { break };
30548 val
30549 }),
30550 10u16 => OpSetlinkDoRequest::Master({
30551 let res = parse_u32(next);
30552 let Some(val) = res else { break };
30553 val
30554 }),
30555 11u16 => OpSetlinkDoRequest::Wireless({
30556 let res = CStr::from_bytes_with_nul(next).ok();
30557 let Some(val) = res else { break };
30558 val
30559 }),
30560 12u16 => OpSetlinkDoRequest::Protinfo({
30561 let res = CStr::from_bytes_with_nul(next).ok();
30562 let Some(val) = res else { break };
30563 val
30564 }),
30565 13u16 => OpSetlinkDoRequest::Txqlen({
30566 let res = parse_u32(next);
30567 let Some(val) = res else { break };
30568 val
30569 }),
30570 14u16 => OpSetlinkDoRequest::Map({
30571 let res = PushRtnlLinkIfmap::new_from_slice(next);
30572 let Some(val) = res else { break };
30573 val
30574 }),
30575 15u16 => OpSetlinkDoRequest::Weight({
30576 let res = parse_u32(next);
30577 let Some(val) = res else { break };
30578 val
30579 }),
30580 16u16 => OpSetlinkDoRequest::Operstate({
30581 let res = parse_u8(next);
30582 let Some(val) = res else { break };
30583 val
30584 }),
30585 17u16 => OpSetlinkDoRequest::Linkmode({
30586 let res = parse_u8(next);
30587 let Some(val) = res else { break };
30588 val
30589 }),
30590 18u16 => OpSetlinkDoRequest::Linkinfo({
30591 let res = Some(IterableLinkinfoAttrs::with_loc(next, self.orig_loc));
30592 let Some(val) = res else { break };
30593 val
30594 }),
30595 19u16 => OpSetlinkDoRequest::NetNsPid({
30596 let res = parse_u32(next);
30597 let Some(val) = res else { break };
30598 val
30599 }),
30600 20u16 => OpSetlinkDoRequest::Ifalias({
30601 let res = CStr::from_bytes_with_nul(next).ok();
30602 let Some(val) = res else { break };
30603 val
30604 }),
30605 21u16 => OpSetlinkDoRequest::NumVf({
30606 let res = parse_u32(next);
30607 let Some(val) = res else { break };
30608 val
30609 }),
30610 22u16 => OpSetlinkDoRequest::VfinfoList({
30611 let res = Some(IterableVfinfoListAttrs::with_loc(next, self.orig_loc));
30612 let Some(val) = res else { break };
30613 val
30614 }),
30615 23u16 => OpSetlinkDoRequest::Stats64({
30616 let res = PushRtnlLinkStats64::new_from_slice(next);
30617 let Some(val) = res else { break };
30618 val
30619 }),
30620 24u16 => OpSetlinkDoRequest::VfPorts({
30621 let res = Some(IterableVfPortsAttrs::with_loc(next, self.orig_loc));
30622 let Some(val) = res else { break };
30623 val
30624 }),
30625 25u16 => OpSetlinkDoRequest::PortSelf({
30626 let res = Some(IterablePortSelfAttrs::with_loc(next, self.orig_loc));
30627 let Some(val) = res else { break };
30628 val
30629 }),
30630 26u16 => OpSetlinkDoRequest::AfSpec({
30631 let res = Some(IterableAfSpecAttrs::with_loc(next, self.orig_loc));
30632 let Some(val) = res else { break };
30633 val
30634 }),
30635 27u16 => OpSetlinkDoRequest::Group({
30636 let res = parse_u32(next);
30637 let Some(val) = res else { break };
30638 val
30639 }),
30640 28u16 => OpSetlinkDoRequest::NetNsFd({
30641 let res = parse_u32(next);
30642 let Some(val) = res else { break };
30643 val
30644 }),
30645 29u16 => OpSetlinkDoRequest::ExtMask({
30646 let res = parse_u32(next);
30647 let Some(val) = res else { break };
30648 val
30649 }),
30650 30u16 => OpSetlinkDoRequest::Promiscuity({
30651 let res = parse_u32(next);
30652 let Some(val) = res else { break };
30653 val
30654 }),
30655 31u16 => OpSetlinkDoRequest::NumTxQueues({
30656 let res = parse_u32(next);
30657 let Some(val) = res else { break };
30658 val
30659 }),
30660 32u16 => OpSetlinkDoRequest::NumRxQueues({
30661 let res = parse_u32(next);
30662 let Some(val) = res else { break };
30663 val
30664 }),
30665 33u16 => OpSetlinkDoRequest::Carrier({
30666 let res = parse_u8(next);
30667 let Some(val) = res else { break };
30668 val
30669 }),
30670 34u16 => OpSetlinkDoRequest::PhysPortId({
30671 let res = Some(next);
30672 let Some(val) = res else { break };
30673 val
30674 }),
30675 35u16 => OpSetlinkDoRequest::CarrierChanges({
30676 let res = parse_u32(next);
30677 let Some(val) = res else { break };
30678 val
30679 }),
30680 36u16 => OpSetlinkDoRequest::PhysSwitchId({
30681 let res = Some(next);
30682 let Some(val) = res else { break };
30683 val
30684 }),
30685 37u16 => OpSetlinkDoRequest::LinkNetnsid({
30686 let res = parse_i32(next);
30687 let Some(val) = res else { break };
30688 val
30689 }),
30690 38u16 => OpSetlinkDoRequest::PhysPortName({
30691 let res = CStr::from_bytes_with_nul(next).ok();
30692 let Some(val) = res else { break };
30693 val
30694 }),
30695 39u16 => OpSetlinkDoRequest::ProtoDown({
30696 let res = parse_u8(next);
30697 let Some(val) = res else { break };
30698 val
30699 }),
30700 40u16 => OpSetlinkDoRequest::GsoMaxSegs({
30701 let res = parse_u32(next);
30702 let Some(val) = res else { break };
30703 val
30704 }),
30705 41u16 => OpSetlinkDoRequest::GsoMaxSize({
30706 let res = parse_u32(next);
30707 let Some(val) = res else { break };
30708 val
30709 }),
30710 42u16 => OpSetlinkDoRequest::Pad({
30711 let res = Some(next);
30712 let Some(val) = res else { break };
30713 val
30714 }),
30715 43u16 => OpSetlinkDoRequest::Xdp({
30716 let res = Some(IterableXdpAttrs::with_loc(next, self.orig_loc));
30717 let Some(val) = res else { break };
30718 val
30719 }),
30720 44u16 => OpSetlinkDoRequest::Event({
30721 let res = parse_u32(next);
30722 let Some(val) = res else { break };
30723 val
30724 }),
30725 45u16 => OpSetlinkDoRequest::NewNetnsid({
30726 let res = parse_i32(next);
30727 let Some(val) = res else { break };
30728 val
30729 }),
30730 46u16 => OpSetlinkDoRequest::TargetNetnsid({
30731 let res = parse_i32(next);
30732 let Some(val) = res else { break };
30733 val
30734 }),
30735 47u16 => OpSetlinkDoRequest::CarrierUpCount({
30736 let res = parse_u32(next);
30737 let Some(val) = res else { break };
30738 val
30739 }),
30740 48u16 => OpSetlinkDoRequest::CarrierDownCount({
30741 let res = parse_u32(next);
30742 let Some(val) = res else { break };
30743 val
30744 }),
30745 49u16 => OpSetlinkDoRequest::NewIfindex({
30746 let res = parse_i32(next);
30747 let Some(val) = res else { break };
30748 val
30749 }),
30750 50u16 => OpSetlinkDoRequest::MinMtu({
30751 let res = parse_u32(next);
30752 let Some(val) = res else { break };
30753 val
30754 }),
30755 51u16 => OpSetlinkDoRequest::MaxMtu({
30756 let res = parse_u32(next);
30757 let Some(val) = res else { break };
30758 val
30759 }),
30760 52u16 => OpSetlinkDoRequest::PropList({
30761 let res = Some(IterablePropListLinkAttrs::with_loc(next, self.orig_loc));
30762 let Some(val) = res else { break };
30763 val
30764 }),
30765 54u16 => OpSetlinkDoRequest::PermAddress({
30766 let res = Some(next);
30767 let Some(val) = res else { break };
30768 val
30769 }),
30770 55u16 => OpSetlinkDoRequest::ProtoDownReason({
30771 let res = CStr::from_bytes_with_nul(next).ok();
30772 let Some(val) = res else { break };
30773 val
30774 }),
30775 56u16 => OpSetlinkDoRequest::ParentDevName({
30776 let res = CStr::from_bytes_with_nul(next).ok();
30777 let Some(val) = res else { break };
30778 val
30779 }),
30780 57u16 => OpSetlinkDoRequest::ParentDevBusName({
30781 let res = CStr::from_bytes_with_nul(next).ok();
30782 let Some(val) = res else { break };
30783 val
30784 }),
30785 58u16 => OpSetlinkDoRequest::GroMaxSize({
30786 let res = parse_u32(next);
30787 let Some(val) = res else { break };
30788 val
30789 }),
30790 59u16 => OpSetlinkDoRequest::TsoMaxSize({
30791 let res = parse_u32(next);
30792 let Some(val) = res else { break };
30793 val
30794 }),
30795 60u16 => OpSetlinkDoRequest::TsoMaxSegs({
30796 let res = parse_u32(next);
30797 let Some(val) = res else { break };
30798 val
30799 }),
30800 61u16 => OpSetlinkDoRequest::Allmulti({
30801 let res = parse_u32(next);
30802 let Some(val) = res else { break };
30803 val
30804 }),
30805 62u16 => OpSetlinkDoRequest::DevlinkPort({
30806 let res = Some(next);
30807 let Some(val) = res else { break };
30808 val
30809 }),
30810 63u16 => OpSetlinkDoRequest::GsoIpv4MaxSize({
30811 let res = parse_u32(next);
30812 let Some(val) = res else { break };
30813 val
30814 }),
30815 64u16 => OpSetlinkDoRequest::GroIpv4MaxSize({
30816 let res = parse_u32(next);
30817 let Some(val) = res else { break };
30818 val
30819 }),
30820 65u16 => OpSetlinkDoRequest::DpllPin({
30821 let res = Some(IterableLinkDpllPinAttrs::with_loc(next, self.orig_loc));
30822 let Some(val) = res else { break };
30823 val
30824 }),
30825 66u16 => OpSetlinkDoRequest::MaxPacingOffloadHorizon({
30826 let res = parse_u32(next);
30827 let Some(val) = res else { break };
30828 val
30829 }),
30830 67u16 => OpSetlinkDoRequest::NetnsImmutable({
30831 let res = parse_u8(next);
30832 let Some(val) = res else { break };
30833 val
30834 }),
30835 n => {
30836 if cfg!(any(test, feature = "deny-unknown-attrs")) {
30837 break;
30838 } else {
30839 continue;
30840 }
30841 }
30842 };
30843 return Some(Ok(res));
30844 }
30845 Some(Err(ErrorContext::new(
30846 "OpSetlinkDoRequest",
30847 r#type.and_then(|t| OpSetlinkDoRequest::attr_from_type(t)),
30848 self.orig_loc,
30849 self.buf.as_ptr().wrapping_add(pos) as usize,
30850 )))
30851 }
30852}
30853impl<'a> std::fmt::Debug for IterableOpSetlinkDoRequest<'_> {
30854 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30855 let mut fmt = f.debug_struct("OpSetlinkDoRequest");
30856 for attr in self.clone() {
30857 let attr = match attr {
30858 Ok(a) => a,
30859 Err(err) => {
30860 fmt.finish()?;
30861 f.write_str("Err(")?;
30862 err.fmt(f)?;
30863 return f.write_str(")");
30864 }
30865 };
30866 match attr {
30867 OpSetlinkDoRequest::Address(val) => fmt.field("Address", &val),
30868 OpSetlinkDoRequest::Broadcast(val) => fmt.field("Broadcast", &val),
30869 OpSetlinkDoRequest::Ifname(val) => fmt.field("Ifname", &val),
30870 OpSetlinkDoRequest::Mtu(val) => fmt.field("Mtu", &val),
30871 OpSetlinkDoRequest::Link(val) => fmt.field("Link", &val),
30872 OpSetlinkDoRequest::Qdisc(val) => fmt.field("Qdisc", &val),
30873 OpSetlinkDoRequest::Stats(val) => fmt.field("Stats", &val),
30874 OpSetlinkDoRequest::Cost(val) => fmt.field("Cost", &val),
30875 OpSetlinkDoRequest::Priority(val) => fmt.field("Priority", &val),
30876 OpSetlinkDoRequest::Master(val) => fmt.field("Master", &val),
30877 OpSetlinkDoRequest::Wireless(val) => fmt.field("Wireless", &val),
30878 OpSetlinkDoRequest::Protinfo(val) => fmt.field("Protinfo", &val),
30879 OpSetlinkDoRequest::Txqlen(val) => fmt.field("Txqlen", &val),
30880 OpSetlinkDoRequest::Map(val) => fmt.field("Map", &val),
30881 OpSetlinkDoRequest::Weight(val) => fmt.field("Weight", &val),
30882 OpSetlinkDoRequest::Operstate(val) => fmt.field("Operstate", &val),
30883 OpSetlinkDoRequest::Linkmode(val) => fmt.field("Linkmode", &val),
30884 OpSetlinkDoRequest::Linkinfo(val) => fmt.field("Linkinfo", &val),
30885 OpSetlinkDoRequest::NetNsPid(val) => fmt.field("NetNsPid", &val),
30886 OpSetlinkDoRequest::Ifalias(val) => fmt.field("Ifalias", &val),
30887 OpSetlinkDoRequest::NumVf(val) => fmt.field("NumVf", &val),
30888 OpSetlinkDoRequest::VfinfoList(val) => fmt.field("VfinfoList", &val),
30889 OpSetlinkDoRequest::Stats64(val) => fmt.field("Stats64", &val),
30890 OpSetlinkDoRequest::VfPorts(val) => fmt.field("VfPorts", &val),
30891 OpSetlinkDoRequest::PortSelf(val) => fmt.field("PortSelf", &val),
30892 OpSetlinkDoRequest::AfSpec(val) => fmt.field("AfSpec", &val),
30893 OpSetlinkDoRequest::Group(val) => fmt.field("Group", &val),
30894 OpSetlinkDoRequest::NetNsFd(val) => fmt.field("NetNsFd", &val),
30895 OpSetlinkDoRequest::ExtMask(val) => {
30896 fmt.field("ExtMask", &FormatFlags(val.into(), RtextFilter::from_value))
30897 }
30898 OpSetlinkDoRequest::Promiscuity(val) => fmt.field("Promiscuity", &val),
30899 OpSetlinkDoRequest::NumTxQueues(val) => fmt.field("NumTxQueues", &val),
30900 OpSetlinkDoRequest::NumRxQueues(val) => fmt.field("NumRxQueues", &val),
30901 OpSetlinkDoRequest::Carrier(val) => fmt.field("Carrier", &val),
30902 OpSetlinkDoRequest::PhysPortId(val) => fmt.field("PhysPortId", &val),
30903 OpSetlinkDoRequest::CarrierChanges(val) => fmt.field("CarrierChanges", &val),
30904 OpSetlinkDoRequest::PhysSwitchId(val) => fmt.field("PhysSwitchId", &val),
30905 OpSetlinkDoRequest::LinkNetnsid(val) => fmt.field("LinkNetnsid", &val),
30906 OpSetlinkDoRequest::PhysPortName(val) => fmt.field("PhysPortName", &val),
30907 OpSetlinkDoRequest::ProtoDown(val) => fmt.field("ProtoDown", &val),
30908 OpSetlinkDoRequest::GsoMaxSegs(val) => fmt.field("GsoMaxSegs", &val),
30909 OpSetlinkDoRequest::GsoMaxSize(val) => fmt.field("GsoMaxSize", &val),
30910 OpSetlinkDoRequest::Pad(val) => fmt.field("Pad", &val),
30911 OpSetlinkDoRequest::Xdp(val) => fmt.field("Xdp", &val),
30912 OpSetlinkDoRequest::Event(val) => fmt.field("Event", &val),
30913 OpSetlinkDoRequest::NewNetnsid(val) => fmt.field("NewNetnsid", &val),
30914 OpSetlinkDoRequest::TargetNetnsid(val) => fmt.field("TargetNetnsid", &val),
30915 OpSetlinkDoRequest::CarrierUpCount(val) => fmt.field("CarrierUpCount", &val),
30916 OpSetlinkDoRequest::CarrierDownCount(val) => fmt.field("CarrierDownCount", &val),
30917 OpSetlinkDoRequest::NewIfindex(val) => fmt.field("NewIfindex", &val),
30918 OpSetlinkDoRequest::MinMtu(val) => fmt.field("MinMtu", &val),
30919 OpSetlinkDoRequest::MaxMtu(val) => fmt.field("MaxMtu", &val),
30920 OpSetlinkDoRequest::PropList(val) => fmt.field("PropList", &val),
30921 OpSetlinkDoRequest::PermAddress(val) => fmt.field("PermAddress", &val),
30922 OpSetlinkDoRequest::ProtoDownReason(val) => fmt.field("ProtoDownReason", &val),
30923 OpSetlinkDoRequest::ParentDevName(val) => fmt.field("ParentDevName", &val),
30924 OpSetlinkDoRequest::ParentDevBusName(val) => fmt.field("ParentDevBusName", &val),
30925 OpSetlinkDoRequest::GroMaxSize(val) => fmt.field("GroMaxSize", &val),
30926 OpSetlinkDoRequest::TsoMaxSize(val) => fmt.field("TsoMaxSize", &val),
30927 OpSetlinkDoRequest::TsoMaxSegs(val) => fmt.field("TsoMaxSegs", &val),
30928 OpSetlinkDoRequest::Allmulti(val) => fmt.field("Allmulti", &val),
30929 OpSetlinkDoRequest::DevlinkPort(val) => fmt.field("DevlinkPort", &val),
30930 OpSetlinkDoRequest::GsoIpv4MaxSize(val) => fmt.field("GsoIpv4MaxSize", &val),
30931 OpSetlinkDoRequest::GroIpv4MaxSize(val) => fmt.field("GroIpv4MaxSize", &val),
30932 OpSetlinkDoRequest::DpllPin(val) => fmt.field("DpllPin", &val),
30933 OpSetlinkDoRequest::MaxPacingOffloadHorizon(val) => {
30934 fmt.field("MaxPacingOffloadHorizon", &val)
30935 }
30936 OpSetlinkDoRequest::NetnsImmutable(val) => fmt.field("NetnsImmutable", &val),
30937 };
30938 }
30939 fmt.finish()
30940 }
30941}
30942impl IterableOpSetlinkDoRequest<'_> {
30943 pub fn lookup_attr(
30944 &self,
30945 offset: usize,
30946 missing_type: Option<u16>,
30947 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
30948 let mut stack = Vec::new();
30949 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
30950 if cur == offset + PushIfinfomsg::len() {
30951 stack.push(("OpSetlinkDoRequest", offset));
30952 return (
30953 stack,
30954 missing_type.and_then(|t| OpSetlinkDoRequest::attr_from_type(t)),
30955 );
30956 }
30957 if cur > offset || cur + self.buf.len() < offset {
30958 return (stack, None);
30959 }
30960 let mut attrs = self.clone();
30961 let mut last_off = cur + attrs.pos;
30962 let mut missing = None;
30963 while let Some(attr) = attrs.next() {
30964 let Ok(attr) = attr else { break };
30965 match attr {
30966 OpSetlinkDoRequest::Address(val) => {
30967 if last_off == offset {
30968 stack.push(("Address", last_off));
30969 break;
30970 }
30971 }
30972 OpSetlinkDoRequest::Broadcast(val) => {
30973 if last_off == offset {
30974 stack.push(("Broadcast", last_off));
30975 break;
30976 }
30977 }
30978 OpSetlinkDoRequest::Ifname(val) => {
30979 if last_off == offset {
30980 stack.push(("Ifname", last_off));
30981 break;
30982 }
30983 }
30984 OpSetlinkDoRequest::Mtu(val) => {
30985 if last_off == offset {
30986 stack.push(("Mtu", last_off));
30987 break;
30988 }
30989 }
30990 OpSetlinkDoRequest::Link(val) => {
30991 if last_off == offset {
30992 stack.push(("Link", last_off));
30993 break;
30994 }
30995 }
30996 OpSetlinkDoRequest::Qdisc(val) => {
30997 if last_off == offset {
30998 stack.push(("Qdisc", last_off));
30999 break;
31000 }
31001 }
31002 OpSetlinkDoRequest::Stats(val) => {
31003 if last_off == offset {
31004 stack.push(("Stats", last_off));
31005 break;
31006 }
31007 }
31008 OpSetlinkDoRequest::Cost(val) => {
31009 if last_off == offset {
31010 stack.push(("Cost", last_off));
31011 break;
31012 }
31013 }
31014 OpSetlinkDoRequest::Priority(val) => {
31015 if last_off == offset {
31016 stack.push(("Priority", last_off));
31017 break;
31018 }
31019 }
31020 OpSetlinkDoRequest::Master(val) => {
31021 if last_off == offset {
31022 stack.push(("Master", last_off));
31023 break;
31024 }
31025 }
31026 OpSetlinkDoRequest::Wireless(val) => {
31027 if last_off == offset {
31028 stack.push(("Wireless", last_off));
31029 break;
31030 }
31031 }
31032 OpSetlinkDoRequest::Protinfo(val) => {
31033 if last_off == offset {
31034 stack.push(("Protinfo", last_off));
31035 break;
31036 }
31037 }
31038 OpSetlinkDoRequest::Txqlen(val) => {
31039 if last_off == offset {
31040 stack.push(("Txqlen", last_off));
31041 break;
31042 }
31043 }
31044 OpSetlinkDoRequest::Map(val) => {
31045 if last_off == offset {
31046 stack.push(("Map", last_off));
31047 break;
31048 }
31049 }
31050 OpSetlinkDoRequest::Weight(val) => {
31051 if last_off == offset {
31052 stack.push(("Weight", last_off));
31053 break;
31054 }
31055 }
31056 OpSetlinkDoRequest::Operstate(val) => {
31057 if last_off == offset {
31058 stack.push(("Operstate", last_off));
31059 break;
31060 }
31061 }
31062 OpSetlinkDoRequest::Linkmode(val) => {
31063 if last_off == offset {
31064 stack.push(("Linkmode", last_off));
31065 break;
31066 }
31067 }
31068 OpSetlinkDoRequest::Linkinfo(val) => {
31069 (stack, missing) = val.lookup_attr(offset, missing_type);
31070 if !stack.is_empty() {
31071 break;
31072 }
31073 }
31074 OpSetlinkDoRequest::NetNsPid(val) => {
31075 if last_off == offset {
31076 stack.push(("NetNsPid", last_off));
31077 break;
31078 }
31079 }
31080 OpSetlinkDoRequest::Ifalias(val) => {
31081 if last_off == offset {
31082 stack.push(("Ifalias", last_off));
31083 break;
31084 }
31085 }
31086 OpSetlinkDoRequest::NumVf(val) => {
31087 if last_off == offset {
31088 stack.push(("NumVf", last_off));
31089 break;
31090 }
31091 }
31092 OpSetlinkDoRequest::VfinfoList(val) => {
31093 (stack, missing) = val.lookup_attr(offset, missing_type);
31094 if !stack.is_empty() {
31095 break;
31096 }
31097 }
31098 OpSetlinkDoRequest::Stats64(val) => {
31099 if last_off == offset {
31100 stack.push(("Stats64", last_off));
31101 break;
31102 }
31103 }
31104 OpSetlinkDoRequest::VfPorts(val) => {
31105 (stack, missing) = val.lookup_attr(offset, missing_type);
31106 if !stack.is_empty() {
31107 break;
31108 }
31109 }
31110 OpSetlinkDoRequest::PortSelf(val) => {
31111 (stack, missing) = val.lookup_attr(offset, missing_type);
31112 if !stack.is_empty() {
31113 break;
31114 }
31115 }
31116 OpSetlinkDoRequest::AfSpec(val) => {
31117 (stack, missing) = val.lookup_attr(offset, missing_type);
31118 if !stack.is_empty() {
31119 break;
31120 }
31121 }
31122 OpSetlinkDoRequest::Group(val) => {
31123 if last_off == offset {
31124 stack.push(("Group", last_off));
31125 break;
31126 }
31127 }
31128 OpSetlinkDoRequest::NetNsFd(val) => {
31129 if last_off == offset {
31130 stack.push(("NetNsFd", last_off));
31131 break;
31132 }
31133 }
31134 OpSetlinkDoRequest::ExtMask(val) => {
31135 if last_off == offset {
31136 stack.push(("ExtMask", last_off));
31137 break;
31138 }
31139 }
31140 OpSetlinkDoRequest::Promiscuity(val) => {
31141 if last_off == offset {
31142 stack.push(("Promiscuity", last_off));
31143 break;
31144 }
31145 }
31146 OpSetlinkDoRequest::NumTxQueues(val) => {
31147 if last_off == offset {
31148 stack.push(("NumTxQueues", last_off));
31149 break;
31150 }
31151 }
31152 OpSetlinkDoRequest::NumRxQueues(val) => {
31153 if last_off == offset {
31154 stack.push(("NumRxQueues", last_off));
31155 break;
31156 }
31157 }
31158 OpSetlinkDoRequest::Carrier(val) => {
31159 if last_off == offset {
31160 stack.push(("Carrier", last_off));
31161 break;
31162 }
31163 }
31164 OpSetlinkDoRequest::PhysPortId(val) => {
31165 if last_off == offset {
31166 stack.push(("PhysPortId", last_off));
31167 break;
31168 }
31169 }
31170 OpSetlinkDoRequest::CarrierChanges(val) => {
31171 if last_off == offset {
31172 stack.push(("CarrierChanges", last_off));
31173 break;
31174 }
31175 }
31176 OpSetlinkDoRequest::PhysSwitchId(val) => {
31177 if last_off == offset {
31178 stack.push(("PhysSwitchId", last_off));
31179 break;
31180 }
31181 }
31182 OpSetlinkDoRequest::LinkNetnsid(val) => {
31183 if last_off == offset {
31184 stack.push(("LinkNetnsid", last_off));
31185 break;
31186 }
31187 }
31188 OpSetlinkDoRequest::PhysPortName(val) => {
31189 if last_off == offset {
31190 stack.push(("PhysPortName", last_off));
31191 break;
31192 }
31193 }
31194 OpSetlinkDoRequest::ProtoDown(val) => {
31195 if last_off == offset {
31196 stack.push(("ProtoDown", last_off));
31197 break;
31198 }
31199 }
31200 OpSetlinkDoRequest::GsoMaxSegs(val) => {
31201 if last_off == offset {
31202 stack.push(("GsoMaxSegs", last_off));
31203 break;
31204 }
31205 }
31206 OpSetlinkDoRequest::GsoMaxSize(val) => {
31207 if last_off == offset {
31208 stack.push(("GsoMaxSize", last_off));
31209 break;
31210 }
31211 }
31212 OpSetlinkDoRequest::Pad(val) => {
31213 if last_off == offset {
31214 stack.push(("Pad", last_off));
31215 break;
31216 }
31217 }
31218 OpSetlinkDoRequest::Xdp(val) => {
31219 (stack, missing) = val.lookup_attr(offset, missing_type);
31220 if !stack.is_empty() {
31221 break;
31222 }
31223 }
31224 OpSetlinkDoRequest::Event(val) => {
31225 if last_off == offset {
31226 stack.push(("Event", last_off));
31227 break;
31228 }
31229 }
31230 OpSetlinkDoRequest::NewNetnsid(val) => {
31231 if last_off == offset {
31232 stack.push(("NewNetnsid", last_off));
31233 break;
31234 }
31235 }
31236 OpSetlinkDoRequest::TargetNetnsid(val) => {
31237 if last_off == offset {
31238 stack.push(("TargetNetnsid", last_off));
31239 break;
31240 }
31241 }
31242 OpSetlinkDoRequest::CarrierUpCount(val) => {
31243 if last_off == offset {
31244 stack.push(("CarrierUpCount", last_off));
31245 break;
31246 }
31247 }
31248 OpSetlinkDoRequest::CarrierDownCount(val) => {
31249 if last_off == offset {
31250 stack.push(("CarrierDownCount", last_off));
31251 break;
31252 }
31253 }
31254 OpSetlinkDoRequest::NewIfindex(val) => {
31255 if last_off == offset {
31256 stack.push(("NewIfindex", last_off));
31257 break;
31258 }
31259 }
31260 OpSetlinkDoRequest::MinMtu(val) => {
31261 if last_off == offset {
31262 stack.push(("MinMtu", last_off));
31263 break;
31264 }
31265 }
31266 OpSetlinkDoRequest::MaxMtu(val) => {
31267 if last_off == offset {
31268 stack.push(("MaxMtu", last_off));
31269 break;
31270 }
31271 }
31272 OpSetlinkDoRequest::PropList(val) => {
31273 (stack, missing) = val.lookup_attr(offset, missing_type);
31274 if !stack.is_empty() {
31275 break;
31276 }
31277 }
31278 OpSetlinkDoRequest::PermAddress(val) => {
31279 if last_off == offset {
31280 stack.push(("PermAddress", last_off));
31281 break;
31282 }
31283 }
31284 OpSetlinkDoRequest::ProtoDownReason(val) => {
31285 if last_off == offset {
31286 stack.push(("ProtoDownReason", last_off));
31287 break;
31288 }
31289 }
31290 OpSetlinkDoRequest::ParentDevName(val) => {
31291 if last_off == offset {
31292 stack.push(("ParentDevName", last_off));
31293 break;
31294 }
31295 }
31296 OpSetlinkDoRequest::ParentDevBusName(val) => {
31297 if last_off == offset {
31298 stack.push(("ParentDevBusName", last_off));
31299 break;
31300 }
31301 }
31302 OpSetlinkDoRequest::GroMaxSize(val) => {
31303 if last_off == offset {
31304 stack.push(("GroMaxSize", last_off));
31305 break;
31306 }
31307 }
31308 OpSetlinkDoRequest::TsoMaxSize(val) => {
31309 if last_off == offset {
31310 stack.push(("TsoMaxSize", last_off));
31311 break;
31312 }
31313 }
31314 OpSetlinkDoRequest::TsoMaxSegs(val) => {
31315 if last_off == offset {
31316 stack.push(("TsoMaxSegs", last_off));
31317 break;
31318 }
31319 }
31320 OpSetlinkDoRequest::Allmulti(val) => {
31321 if last_off == offset {
31322 stack.push(("Allmulti", last_off));
31323 break;
31324 }
31325 }
31326 OpSetlinkDoRequest::DevlinkPort(val) => {
31327 if last_off == offset {
31328 stack.push(("DevlinkPort", last_off));
31329 break;
31330 }
31331 }
31332 OpSetlinkDoRequest::GsoIpv4MaxSize(val) => {
31333 if last_off == offset {
31334 stack.push(("GsoIpv4MaxSize", last_off));
31335 break;
31336 }
31337 }
31338 OpSetlinkDoRequest::GroIpv4MaxSize(val) => {
31339 if last_off == offset {
31340 stack.push(("GroIpv4MaxSize", last_off));
31341 break;
31342 }
31343 }
31344 OpSetlinkDoRequest::DpllPin(val) => {
31345 (stack, missing) = val.lookup_attr(offset, missing_type);
31346 if !stack.is_empty() {
31347 break;
31348 }
31349 }
31350 OpSetlinkDoRequest::MaxPacingOffloadHorizon(val) => {
31351 if last_off == offset {
31352 stack.push(("MaxPacingOffloadHorizon", last_off));
31353 break;
31354 }
31355 }
31356 OpSetlinkDoRequest::NetnsImmutable(val) => {
31357 if last_off == offset {
31358 stack.push(("NetnsImmutable", last_off));
31359 break;
31360 }
31361 }
31362 _ => {}
31363 };
31364 last_off = cur + attrs.pos;
31365 }
31366 if !stack.is_empty() {
31367 stack.push(("OpSetlinkDoRequest", cur));
31368 }
31369 (stack, missing)
31370 }
31371}
31372#[doc = "Set information about a link."]
31373pub struct PushOpSetlinkDoReply<Prev: Rec> {
31374 pub(crate) prev: Option<Prev>,
31375 pub(crate) header_offset: Option<usize>,
31376}
31377impl<Prev: Rec> Rec for PushOpSetlinkDoReply<Prev> {
31378 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
31379 self.prev.as_mut().unwrap().as_rec_mut()
31380 }
31381}
31382impl<Prev: Rec> PushOpSetlinkDoReply<Prev> {
31383 pub fn new(mut prev: Prev, header: &PushIfinfomsg) -> Self {
31384 Self::write_header(&mut prev, header);
31385 Self::new_without_header(prev)
31386 }
31387 fn new_without_header(prev: Prev) -> Self {
31388 Self {
31389 prev: Some(prev),
31390 header_offset: None,
31391 }
31392 }
31393 fn write_header(prev: &mut Prev, header: &PushIfinfomsg) {
31394 prev.as_rec_mut().extend(header.as_slice());
31395 }
31396 pub fn end_nested(mut self) -> Prev {
31397 let mut prev = self.prev.take().unwrap();
31398 if let Some(header_offset) = &self.header_offset {
31399 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31400 }
31401 prev
31402 }
31403}
31404impl<Prev: Rec> Drop for PushOpSetlinkDoReply<Prev> {
31405 fn drop(&mut self) {
31406 if let Some(prev) = &mut self.prev {
31407 if let Some(header_offset) = &self.header_offset {
31408 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31409 }
31410 }
31411 }
31412}
31413#[doc = "Set information about a link."]
31414#[derive(Clone)]
31415pub enum OpSetlinkDoReply {}
31416impl<'a> IterableOpSetlinkDoReply<'a> {}
31417impl OpSetlinkDoReply {
31418 pub fn new<'a>(buf: &'a [u8]) -> (PushIfinfomsg, IterableOpSetlinkDoReply<'a>) {
31419 let (header, attrs) = buf.split_at(buf.len().min(PushIfinfomsg::len()));
31420 (
31421 PushIfinfomsg::new_from_slice(header).unwrap_or_default(),
31422 IterableOpSetlinkDoReply::with_loc(attrs, buf.as_ptr() as usize),
31423 )
31424 }
31425 fn attr_from_type(r#type: u16) -> Option<&'static str> {
31426 LinkAttrs::attr_from_type(r#type)
31427 }
31428}
31429#[derive(Clone, Copy, Default)]
31430pub struct IterableOpSetlinkDoReply<'a> {
31431 buf: &'a [u8],
31432 pos: usize,
31433 orig_loc: usize,
31434}
31435impl<'a> IterableOpSetlinkDoReply<'a> {
31436 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
31437 Self {
31438 buf,
31439 pos: 0,
31440 orig_loc,
31441 }
31442 }
31443 pub fn get_buf(&self) -> &'a [u8] {
31444 self.buf
31445 }
31446}
31447impl<'a> Iterator for IterableOpSetlinkDoReply<'a> {
31448 type Item = Result<OpSetlinkDoReply, ErrorContext>;
31449 fn next(&mut self) -> Option<Self::Item> {
31450 if self.buf.len() == self.pos {
31451 return None;
31452 }
31453 let pos = self.pos;
31454 let mut r#type = None;
31455 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
31456 r#type = Some(header.r#type);
31457 let res = match header.r#type {
31458 n => {
31459 if cfg!(any(test, feature = "deny-unknown-attrs")) {
31460 break;
31461 } else {
31462 continue;
31463 }
31464 }
31465 };
31466 return Some(Ok(res));
31467 }
31468 Some(Err(ErrorContext::new(
31469 "OpSetlinkDoReply",
31470 r#type.and_then(|t| OpSetlinkDoReply::attr_from_type(t)),
31471 self.orig_loc,
31472 self.buf.as_ptr().wrapping_add(pos) as usize,
31473 )))
31474 }
31475}
31476impl std::fmt::Debug for IterableOpSetlinkDoReply<'_> {
31477 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31478 let mut fmt = f.debug_struct("OpSetlinkDoReply");
31479 for attr in self.clone() {
31480 let attr = match attr {
31481 Ok(a) => a,
31482 Err(err) => {
31483 fmt.finish()?;
31484 f.write_str("Err(")?;
31485 err.fmt(f)?;
31486 return f.write_str(")");
31487 }
31488 };
31489 match attr {};
31490 }
31491 fmt.finish()
31492 }
31493}
31494impl IterableOpSetlinkDoReply<'_> {
31495 pub fn lookup_attr(
31496 &self,
31497 offset: usize,
31498 missing_type: Option<u16>,
31499 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31500 let mut stack = Vec::new();
31501 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
31502 if cur == offset + PushIfinfomsg::len() {
31503 stack.push(("OpSetlinkDoReply", offset));
31504 return (
31505 stack,
31506 missing_type.and_then(|t| OpSetlinkDoReply::attr_from_type(t)),
31507 );
31508 }
31509 (stack, None)
31510 }
31511}
31512#[derive(Debug)]
31513pub struct RequestOpSetlinkDoRequest<'r> {
31514 request: Request<'r>,
31515}
31516impl<'r> RequestOpSetlinkDoRequest<'r> {
31517 pub fn new(mut request: Request<'r>, header: &PushIfinfomsg) -> Self {
31518 PushOpSetlinkDoRequest::write_header(&mut request.buf_mut(), header);
31519 Self { request: request }
31520 }
31521 pub fn encode(&mut self) -> PushOpSetlinkDoRequest<&mut Vec<u8>> {
31522 PushOpSetlinkDoRequest::new_without_header(self.request.buf_mut())
31523 }
31524 pub fn into_encoder(self) -> PushOpSetlinkDoRequest<RequestBuf<'r>> {
31525 PushOpSetlinkDoRequest::new_without_header(self.request.buf)
31526 }
31527}
31528impl NetlinkRequest for RequestOpSetlinkDoRequest<'_> {
31529 type ReplyType<'buf> = (PushIfinfomsg, IterableOpSetlinkDoReply<'buf>);
31530 fn protocol(&self) -> Protocol {
31531 Protocol::Raw {
31532 protonum: 0u16,
31533 request_type: 19u16,
31534 }
31535 }
31536 fn flags(&self) -> u16 {
31537 self.request.flags
31538 }
31539 fn payload(&self) -> &[u8] {
31540 self.request.buf()
31541 }
31542 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
31543 OpSetlinkDoReply::new(buf)
31544 }
31545 fn lookup(
31546 buf: &[u8],
31547 offset: usize,
31548 missing_type: Option<u16>,
31549 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31550 OpSetlinkDoRequest::new(buf)
31551 .1
31552 .lookup_attr(offset, missing_type)
31553 }
31554}
31555#[doc = "Get / dump link stats."]
31556pub struct PushOpGetstatsDumpRequest<Prev: Rec> {
31557 pub(crate) prev: Option<Prev>,
31558 pub(crate) header_offset: Option<usize>,
31559}
31560impl<Prev: Rec> Rec for PushOpGetstatsDumpRequest<Prev> {
31561 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
31562 self.prev.as_mut().unwrap().as_rec_mut()
31563 }
31564}
31565impl<Prev: Rec> PushOpGetstatsDumpRequest<Prev> {
31566 pub fn new(mut prev: Prev, header: &PushIfStatsMsg) -> Self {
31567 Self::write_header(&mut prev, header);
31568 Self::new_without_header(prev)
31569 }
31570 fn new_without_header(prev: Prev) -> Self {
31571 Self {
31572 prev: Some(prev),
31573 header_offset: None,
31574 }
31575 }
31576 fn write_header(prev: &mut Prev, header: &PushIfStatsMsg) {
31577 prev.as_rec_mut().extend(header.as_slice());
31578 }
31579 pub fn end_nested(mut self) -> Prev {
31580 let mut prev = self.prev.take().unwrap();
31581 if let Some(header_offset) = &self.header_offset {
31582 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31583 }
31584 prev
31585 }
31586}
31587impl<Prev: Rec> Drop for PushOpGetstatsDumpRequest<Prev> {
31588 fn drop(&mut self) {
31589 if let Some(prev) = &mut self.prev {
31590 if let Some(header_offset) = &self.header_offset {
31591 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31592 }
31593 }
31594 }
31595}
31596#[doc = "Get / dump link stats."]
31597#[derive(Clone)]
31598pub enum OpGetstatsDumpRequest {}
31599impl<'a> IterableOpGetstatsDumpRequest<'a> {}
31600impl OpGetstatsDumpRequest {
31601 pub fn new<'a>(buf: &'a [u8]) -> (PushIfStatsMsg, IterableOpGetstatsDumpRequest<'a>) {
31602 let (header, attrs) = buf.split_at(buf.len().min(PushIfStatsMsg::len()));
31603 (
31604 PushIfStatsMsg::new_from_slice(header).unwrap_or_default(),
31605 IterableOpGetstatsDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
31606 )
31607 }
31608 fn attr_from_type(r#type: u16) -> Option<&'static str> {
31609 StatsAttrs::attr_from_type(r#type)
31610 }
31611}
31612#[derive(Clone, Copy, Default)]
31613pub struct IterableOpGetstatsDumpRequest<'a> {
31614 buf: &'a [u8],
31615 pos: usize,
31616 orig_loc: usize,
31617}
31618impl<'a> IterableOpGetstatsDumpRequest<'a> {
31619 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
31620 Self {
31621 buf,
31622 pos: 0,
31623 orig_loc,
31624 }
31625 }
31626 pub fn get_buf(&self) -> &'a [u8] {
31627 self.buf
31628 }
31629}
31630impl<'a> Iterator for IterableOpGetstatsDumpRequest<'a> {
31631 type Item = Result<OpGetstatsDumpRequest, ErrorContext>;
31632 fn next(&mut self) -> Option<Self::Item> {
31633 if self.buf.len() == self.pos {
31634 return None;
31635 }
31636 let pos = self.pos;
31637 let mut r#type = None;
31638 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
31639 r#type = Some(header.r#type);
31640 let res = match header.r#type {
31641 n => {
31642 if cfg!(any(test, feature = "deny-unknown-attrs")) {
31643 break;
31644 } else {
31645 continue;
31646 }
31647 }
31648 };
31649 return Some(Ok(res));
31650 }
31651 Some(Err(ErrorContext::new(
31652 "OpGetstatsDumpRequest",
31653 r#type.and_then(|t| OpGetstatsDumpRequest::attr_from_type(t)),
31654 self.orig_loc,
31655 self.buf.as_ptr().wrapping_add(pos) as usize,
31656 )))
31657 }
31658}
31659impl std::fmt::Debug for IterableOpGetstatsDumpRequest<'_> {
31660 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31661 let mut fmt = f.debug_struct("OpGetstatsDumpRequest");
31662 for attr in self.clone() {
31663 let attr = match attr {
31664 Ok(a) => a,
31665 Err(err) => {
31666 fmt.finish()?;
31667 f.write_str("Err(")?;
31668 err.fmt(f)?;
31669 return f.write_str(")");
31670 }
31671 };
31672 match attr {};
31673 }
31674 fmt.finish()
31675 }
31676}
31677impl IterableOpGetstatsDumpRequest<'_> {
31678 pub fn lookup_attr(
31679 &self,
31680 offset: usize,
31681 missing_type: Option<u16>,
31682 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31683 let mut stack = Vec::new();
31684 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
31685 if cur == offset + PushIfStatsMsg::len() {
31686 stack.push(("OpGetstatsDumpRequest", offset));
31687 return (
31688 stack,
31689 missing_type.and_then(|t| OpGetstatsDumpRequest::attr_from_type(t)),
31690 );
31691 }
31692 (stack, None)
31693 }
31694}
31695#[doc = "Get / dump link stats."]
31696pub struct PushOpGetstatsDumpReply<Prev: Rec> {
31697 pub(crate) prev: Option<Prev>,
31698 pub(crate) header_offset: Option<usize>,
31699}
31700impl<Prev: Rec> Rec for PushOpGetstatsDumpReply<Prev> {
31701 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
31702 self.prev.as_mut().unwrap().as_rec_mut()
31703 }
31704}
31705impl<Prev: Rec> PushOpGetstatsDumpReply<Prev> {
31706 pub fn new(mut prev: Prev, header: &PushIfStatsMsg) -> Self {
31707 Self::write_header(&mut prev, header);
31708 Self::new_without_header(prev)
31709 }
31710 fn new_without_header(prev: Prev) -> Self {
31711 Self {
31712 prev: Some(prev),
31713 header_offset: None,
31714 }
31715 }
31716 fn write_header(prev: &mut Prev, header: &PushIfStatsMsg) {
31717 prev.as_rec_mut().extend(header.as_slice());
31718 }
31719 pub fn end_nested(mut self) -> Prev {
31720 let mut prev = self.prev.take().unwrap();
31721 if let Some(header_offset) = &self.header_offset {
31722 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31723 }
31724 prev
31725 }
31726 pub fn push_link_64(mut self, value: PushRtnlLinkStats64) -> Self {
31727 push_header(self.as_rec_mut(), 1u16, value.as_slice().len() as u16);
31728 self.as_rec_mut().extend(value.as_slice());
31729 self
31730 }
31731 pub fn push_link_xstats(mut self, value: &[u8]) -> Self {
31732 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
31733 self.as_rec_mut().extend(value);
31734 self
31735 }
31736 pub fn push_link_xstats_slave(mut self, value: &[u8]) -> Self {
31737 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
31738 self.as_rec_mut().extend(value);
31739 self
31740 }
31741 pub fn nested_link_offload_xstats(mut self) -> PushLinkOffloadXstats<Self> {
31742 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
31743 PushLinkOffloadXstats {
31744 prev: Some(self),
31745 header_offset: Some(header_offset),
31746 }
31747 }
31748 pub fn push_af_spec(mut self, value: &[u8]) -> Self {
31749 push_header(self.as_rec_mut(), 5u16, value.len() as u16);
31750 self.as_rec_mut().extend(value);
31751 self
31752 }
31753}
31754impl<Prev: Rec> Drop for PushOpGetstatsDumpReply<Prev> {
31755 fn drop(&mut self) {
31756 if let Some(prev) = &mut self.prev {
31757 if let Some(header_offset) = &self.header_offset {
31758 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31759 }
31760 }
31761 }
31762}
31763#[doc = "Get / dump link stats."]
31764#[derive(Clone)]
31765pub enum OpGetstatsDumpReply<'a> {
31766 Link64(PushRtnlLinkStats64),
31767 LinkXstats(&'a [u8]),
31768 LinkXstatsSlave(&'a [u8]),
31769 LinkOffloadXstats(IterableLinkOffloadXstats<'a>),
31770 AfSpec(&'a [u8]),
31771}
31772impl<'a> IterableOpGetstatsDumpReply<'a> {
31773 pub fn get_link_64(&self) -> Result<PushRtnlLinkStats64, ErrorContext> {
31774 let mut iter = self.clone();
31775 iter.pos = 0;
31776 for attr in iter {
31777 if let OpGetstatsDumpReply::Link64(val) = attr? {
31778 return Ok(val);
31779 }
31780 }
31781 Err(ErrorContext::new_missing(
31782 "OpGetstatsDumpReply",
31783 "Link64",
31784 self.orig_loc,
31785 self.buf.as_ptr() as usize,
31786 ))
31787 }
31788 pub fn get_link_xstats(&self) -> Result<&'a [u8], ErrorContext> {
31789 let mut iter = self.clone();
31790 iter.pos = 0;
31791 for attr in iter {
31792 if let OpGetstatsDumpReply::LinkXstats(val) = attr? {
31793 return Ok(val);
31794 }
31795 }
31796 Err(ErrorContext::new_missing(
31797 "OpGetstatsDumpReply",
31798 "LinkXstats",
31799 self.orig_loc,
31800 self.buf.as_ptr() as usize,
31801 ))
31802 }
31803 pub fn get_link_xstats_slave(&self) -> Result<&'a [u8], ErrorContext> {
31804 let mut iter = self.clone();
31805 iter.pos = 0;
31806 for attr in iter {
31807 if let OpGetstatsDumpReply::LinkXstatsSlave(val) = attr? {
31808 return Ok(val);
31809 }
31810 }
31811 Err(ErrorContext::new_missing(
31812 "OpGetstatsDumpReply",
31813 "LinkXstatsSlave",
31814 self.orig_loc,
31815 self.buf.as_ptr() as usize,
31816 ))
31817 }
31818 pub fn get_link_offload_xstats(&self) -> Result<IterableLinkOffloadXstats<'a>, ErrorContext> {
31819 let mut iter = self.clone();
31820 iter.pos = 0;
31821 for attr in iter {
31822 if let OpGetstatsDumpReply::LinkOffloadXstats(val) = attr? {
31823 return Ok(val);
31824 }
31825 }
31826 Err(ErrorContext::new_missing(
31827 "OpGetstatsDumpReply",
31828 "LinkOffloadXstats",
31829 self.orig_loc,
31830 self.buf.as_ptr() as usize,
31831 ))
31832 }
31833 pub fn get_af_spec(&self) -> Result<&'a [u8], ErrorContext> {
31834 let mut iter = self.clone();
31835 iter.pos = 0;
31836 for attr in iter {
31837 if let OpGetstatsDumpReply::AfSpec(val) = attr? {
31838 return Ok(val);
31839 }
31840 }
31841 Err(ErrorContext::new_missing(
31842 "OpGetstatsDumpReply",
31843 "AfSpec",
31844 self.orig_loc,
31845 self.buf.as_ptr() as usize,
31846 ))
31847 }
31848}
31849impl OpGetstatsDumpReply<'_> {
31850 pub fn new<'a>(buf: &'a [u8]) -> (PushIfStatsMsg, IterableOpGetstatsDumpReply<'a>) {
31851 let (header, attrs) = buf.split_at(buf.len().min(PushIfStatsMsg::len()));
31852 (
31853 PushIfStatsMsg::new_from_slice(header).unwrap_or_default(),
31854 IterableOpGetstatsDumpReply::with_loc(attrs, buf.as_ptr() as usize),
31855 )
31856 }
31857 fn attr_from_type(r#type: u16) -> Option<&'static str> {
31858 StatsAttrs::attr_from_type(r#type)
31859 }
31860}
31861#[derive(Clone, Copy, Default)]
31862pub struct IterableOpGetstatsDumpReply<'a> {
31863 buf: &'a [u8],
31864 pos: usize,
31865 orig_loc: usize,
31866}
31867impl<'a> IterableOpGetstatsDumpReply<'a> {
31868 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
31869 Self {
31870 buf,
31871 pos: 0,
31872 orig_loc,
31873 }
31874 }
31875 pub fn get_buf(&self) -> &'a [u8] {
31876 self.buf
31877 }
31878}
31879impl<'a> Iterator for IterableOpGetstatsDumpReply<'a> {
31880 type Item = Result<OpGetstatsDumpReply<'a>, ErrorContext>;
31881 fn next(&mut self) -> Option<Self::Item> {
31882 if self.buf.len() == self.pos {
31883 return None;
31884 }
31885 let pos = self.pos;
31886 let mut r#type = None;
31887 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
31888 r#type = Some(header.r#type);
31889 let res = match header.r#type {
31890 1u16 => OpGetstatsDumpReply::Link64({
31891 let res = PushRtnlLinkStats64::new_from_slice(next);
31892 let Some(val) = res else { break };
31893 val
31894 }),
31895 2u16 => OpGetstatsDumpReply::LinkXstats({
31896 let res = Some(next);
31897 let Some(val) = res else { break };
31898 val
31899 }),
31900 3u16 => OpGetstatsDumpReply::LinkXstatsSlave({
31901 let res = Some(next);
31902 let Some(val) = res else { break };
31903 val
31904 }),
31905 4u16 => OpGetstatsDumpReply::LinkOffloadXstats({
31906 let res = Some(IterableLinkOffloadXstats::with_loc(next, self.orig_loc));
31907 let Some(val) = res else { break };
31908 val
31909 }),
31910 5u16 => OpGetstatsDumpReply::AfSpec({
31911 let res = Some(next);
31912 let Some(val) = res else { break };
31913 val
31914 }),
31915 n => {
31916 if cfg!(any(test, feature = "deny-unknown-attrs")) {
31917 break;
31918 } else {
31919 continue;
31920 }
31921 }
31922 };
31923 return Some(Ok(res));
31924 }
31925 Some(Err(ErrorContext::new(
31926 "OpGetstatsDumpReply",
31927 r#type.and_then(|t| OpGetstatsDumpReply::attr_from_type(t)),
31928 self.orig_loc,
31929 self.buf.as_ptr().wrapping_add(pos) as usize,
31930 )))
31931 }
31932}
31933impl<'a> std::fmt::Debug for IterableOpGetstatsDumpReply<'_> {
31934 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31935 let mut fmt = f.debug_struct("OpGetstatsDumpReply");
31936 for attr in self.clone() {
31937 let attr = match attr {
31938 Ok(a) => a,
31939 Err(err) => {
31940 fmt.finish()?;
31941 f.write_str("Err(")?;
31942 err.fmt(f)?;
31943 return f.write_str(")");
31944 }
31945 };
31946 match attr {
31947 OpGetstatsDumpReply::Link64(val) => fmt.field("Link64", &val),
31948 OpGetstatsDumpReply::LinkXstats(val) => fmt.field("LinkXstats", &val),
31949 OpGetstatsDumpReply::LinkXstatsSlave(val) => fmt.field("LinkXstatsSlave", &val),
31950 OpGetstatsDumpReply::LinkOffloadXstats(val) => fmt.field("LinkOffloadXstats", &val),
31951 OpGetstatsDumpReply::AfSpec(val) => fmt.field("AfSpec", &val),
31952 };
31953 }
31954 fmt.finish()
31955 }
31956}
31957impl IterableOpGetstatsDumpReply<'_> {
31958 pub fn lookup_attr(
31959 &self,
31960 offset: usize,
31961 missing_type: Option<u16>,
31962 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31963 let mut stack = Vec::new();
31964 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
31965 if cur == offset + PushIfStatsMsg::len() {
31966 stack.push(("OpGetstatsDumpReply", offset));
31967 return (
31968 stack,
31969 missing_type.and_then(|t| OpGetstatsDumpReply::attr_from_type(t)),
31970 );
31971 }
31972 if cur > offset || cur + self.buf.len() < offset {
31973 return (stack, None);
31974 }
31975 let mut attrs = self.clone();
31976 let mut last_off = cur + attrs.pos;
31977 let mut missing = None;
31978 while let Some(attr) = attrs.next() {
31979 let Ok(attr) = attr else { break };
31980 match attr {
31981 OpGetstatsDumpReply::Link64(val) => {
31982 if last_off == offset {
31983 stack.push(("Link64", last_off));
31984 break;
31985 }
31986 }
31987 OpGetstatsDumpReply::LinkXstats(val) => {
31988 if last_off == offset {
31989 stack.push(("LinkXstats", last_off));
31990 break;
31991 }
31992 }
31993 OpGetstatsDumpReply::LinkXstatsSlave(val) => {
31994 if last_off == offset {
31995 stack.push(("LinkXstatsSlave", last_off));
31996 break;
31997 }
31998 }
31999 OpGetstatsDumpReply::LinkOffloadXstats(val) => {
32000 (stack, missing) = val.lookup_attr(offset, missing_type);
32001 if !stack.is_empty() {
32002 break;
32003 }
32004 }
32005 OpGetstatsDumpReply::AfSpec(val) => {
32006 if last_off == offset {
32007 stack.push(("AfSpec", last_off));
32008 break;
32009 }
32010 }
32011 _ => {}
32012 };
32013 last_off = cur + attrs.pos;
32014 }
32015 if !stack.is_empty() {
32016 stack.push(("OpGetstatsDumpReply", cur));
32017 }
32018 (stack, missing)
32019 }
32020}
32021#[derive(Debug)]
32022pub struct RequestOpGetstatsDumpRequest<'r> {
32023 request: Request<'r>,
32024}
32025impl<'r> RequestOpGetstatsDumpRequest<'r> {
32026 pub fn new(mut request: Request<'r>, header: &PushIfStatsMsg) -> Self {
32027 PushOpGetstatsDumpRequest::write_header(&mut request.buf_mut(), header);
32028 Self {
32029 request: request.set_dump(),
32030 }
32031 }
32032 pub fn encode(&mut self) -> PushOpGetstatsDumpRequest<&mut Vec<u8>> {
32033 PushOpGetstatsDumpRequest::new_without_header(self.request.buf_mut())
32034 }
32035 pub fn into_encoder(self) -> PushOpGetstatsDumpRequest<RequestBuf<'r>> {
32036 PushOpGetstatsDumpRequest::new_without_header(self.request.buf)
32037 }
32038}
32039impl NetlinkRequest for RequestOpGetstatsDumpRequest<'_> {
32040 type ReplyType<'buf> = (PushIfStatsMsg, IterableOpGetstatsDumpReply<'buf>);
32041 fn protocol(&self) -> Protocol {
32042 Protocol::Raw {
32043 protonum: 0u16,
32044 request_type: 94u16,
32045 }
32046 }
32047 fn flags(&self) -> u16 {
32048 self.request.flags
32049 }
32050 fn payload(&self) -> &[u8] {
32051 self.request.buf()
32052 }
32053 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
32054 OpGetstatsDumpReply::new(buf)
32055 }
32056 fn lookup(
32057 buf: &[u8],
32058 offset: usize,
32059 missing_type: Option<u16>,
32060 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32061 OpGetstatsDumpRequest::new(buf)
32062 .1
32063 .lookup_attr(offset, missing_type)
32064 }
32065}
32066#[doc = "Get / dump link stats."]
32067pub struct PushOpGetstatsDoRequest<Prev: Rec> {
32068 pub(crate) prev: Option<Prev>,
32069 pub(crate) header_offset: Option<usize>,
32070}
32071impl<Prev: Rec> Rec for PushOpGetstatsDoRequest<Prev> {
32072 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
32073 self.prev.as_mut().unwrap().as_rec_mut()
32074 }
32075}
32076impl<Prev: Rec> PushOpGetstatsDoRequest<Prev> {
32077 pub fn new(mut prev: Prev, header: &PushIfStatsMsg) -> Self {
32078 Self::write_header(&mut prev, header);
32079 Self::new_without_header(prev)
32080 }
32081 fn new_without_header(prev: Prev) -> Self {
32082 Self {
32083 prev: Some(prev),
32084 header_offset: None,
32085 }
32086 }
32087 fn write_header(prev: &mut Prev, header: &PushIfStatsMsg) {
32088 prev.as_rec_mut().extend(header.as_slice());
32089 }
32090 pub fn end_nested(mut self) -> Prev {
32091 let mut prev = self.prev.take().unwrap();
32092 if let Some(header_offset) = &self.header_offset {
32093 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32094 }
32095 prev
32096 }
32097}
32098impl<Prev: Rec> Drop for PushOpGetstatsDoRequest<Prev> {
32099 fn drop(&mut self) {
32100 if let Some(prev) = &mut self.prev {
32101 if let Some(header_offset) = &self.header_offset {
32102 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32103 }
32104 }
32105 }
32106}
32107#[doc = "Get / dump link stats."]
32108#[derive(Clone)]
32109pub enum OpGetstatsDoRequest {}
32110impl<'a> IterableOpGetstatsDoRequest<'a> {}
32111impl OpGetstatsDoRequest {
32112 pub fn new<'a>(buf: &'a [u8]) -> (PushIfStatsMsg, IterableOpGetstatsDoRequest<'a>) {
32113 let (header, attrs) = buf.split_at(buf.len().min(PushIfStatsMsg::len()));
32114 (
32115 PushIfStatsMsg::new_from_slice(header).unwrap_or_default(),
32116 IterableOpGetstatsDoRequest::with_loc(attrs, buf.as_ptr() as usize),
32117 )
32118 }
32119 fn attr_from_type(r#type: u16) -> Option<&'static str> {
32120 StatsAttrs::attr_from_type(r#type)
32121 }
32122}
32123#[derive(Clone, Copy, Default)]
32124pub struct IterableOpGetstatsDoRequest<'a> {
32125 buf: &'a [u8],
32126 pos: usize,
32127 orig_loc: usize,
32128}
32129impl<'a> IterableOpGetstatsDoRequest<'a> {
32130 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
32131 Self {
32132 buf,
32133 pos: 0,
32134 orig_loc,
32135 }
32136 }
32137 pub fn get_buf(&self) -> &'a [u8] {
32138 self.buf
32139 }
32140}
32141impl<'a> Iterator for IterableOpGetstatsDoRequest<'a> {
32142 type Item = Result<OpGetstatsDoRequest, ErrorContext>;
32143 fn next(&mut self) -> Option<Self::Item> {
32144 if self.buf.len() == self.pos {
32145 return None;
32146 }
32147 let pos = self.pos;
32148 let mut r#type = None;
32149 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
32150 r#type = Some(header.r#type);
32151 let res = match header.r#type {
32152 n => {
32153 if cfg!(any(test, feature = "deny-unknown-attrs")) {
32154 break;
32155 } else {
32156 continue;
32157 }
32158 }
32159 };
32160 return Some(Ok(res));
32161 }
32162 Some(Err(ErrorContext::new(
32163 "OpGetstatsDoRequest",
32164 r#type.and_then(|t| OpGetstatsDoRequest::attr_from_type(t)),
32165 self.orig_loc,
32166 self.buf.as_ptr().wrapping_add(pos) as usize,
32167 )))
32168 }
32169}
32170impl std::fmt::Debug for IterableOpGetstatsDoRequest<'_> {
32171 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32172 let mut fmt = f.debug_struct("OpGetstatsDoRequest");
32173 for attr in self.clone() {
32174 let attr = match attr {
32175 Ok(a) => a,
32176 Err(err) => {
32177 fmt.finish()?;
32178 f.write_str("Err(")?;
32179 err.fmt(f)?;
32180 return f.write_str(")");
32181 }
32182 };
32183 match attr {};
32184 }
32185 fmt.finish()
32186 }
32187}
32188impl IterableOpGetstatsDoRequest<'_> {
32189 pub fn lookup_attr(
32190 &self,
32191 offset: usize,
32192 missing_type: Option<u16>,
32193 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32194 let mut stack = Vec::new();
32195 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
32196 if cur == offset + PushIfStatsMsg::len() {
32197 stack.push(("OpGetstatsDoRequest", offset));
32198 return (
32199 stack,
32200 missing_type.and_then(|t| OpGetstatsDoRequest::attr_from_type(t)),
32201 );
32202 }
32203 (stack, None)
32204 }
32205}
32206#[doc = "Get / dump link stats."]
32207pub struct PushOpGetstatsDoReply<Prev: Rec> {
32208 pub(crate) prev: Option<Prev>,
32209 pub(crate) header_offset: Option<usize>,
32210}
32211impl<Prev: Rec> Rec for PushOpGetstatsDoReply<Prev> {
32212 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
32213 self.prev.as_mut().unwrap().as_rec_mut()
32214 }
32215}
32216impl<Prev: Rec> PushOpGetstatsDoReply<Prev> {
32217 pub fn new(mut prev: Prev, header: &PushIfStatsMsg) -> Self {
32218 Self::write_header(&mut prev, header);
32219 Self::new_without_header(prev)
32220 }
32221 fn new_without_header(prev: Prev) -> Self {
32222 Self {
32223 prev: Some(prev),
32224 header_offset: None,
32225 }
32226 }
32227 fn write_header(prev: &mut Prev, header: &PushIfStatsMsg) {
32228 prev.as_rec_mut().extend(header.as_slice());
32229 }
32230 pub fn end_nested(mut self) -> Prev {
32231 let mut prev = self.prev.take().unwrap();
32232 if let Some(header_offset) = &self.header_offset {
32233 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32234 }
32235 prev
32236 }
32237 pub fn push_link_64(mut self, value: PushRtnlLinkStats64) -> Self {
32238 push_header(self.as_rec_mut(), 1u16, value.as_slice().len() as u16);
32239 self.as_rec_mut().extend(value.as_slice());
32240 self
32241 }
32242 pub fn push_link_xstats(mut self, value: &[u8]) -> Self {
32243 push_header(self.as_rec_mut(), 2u16, value.len() as u16);
32244 self.as_rec_mut().extend(value);
32245 self
32246 }
32247 pub fn push_link_xstats_slave(mut self, value: &[u8]) -> Self {
32248 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
32249 self.as_rec_mut().extend(value);
32250 self
32251 }
32252 pub fn nested_link_offload_xstats(mut self) -> PushLinkOffloadXstats<Self> {
32253 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
32254 PushLinkOffloadXstats {
32255 prev: Some(self),
32256 header_offset: Some(header_offset),
32257 }
32258 }
32259 pub fn push_af_spec(mut self, value: &[u8]) -> Self {
32260 push_header(self.as_rec_mut(), 5u16, value.len() as u16);
32261 self.as_rec_mut().extend(value);
32262 self
32263 }
32264}
32265impl<Prev: Rec> Drop for PushOpGetstatsDoReply<Prev> {
32266 fn drop(&mut self) {
32267 if let Some(prev) = &mut self.prev {
32268 if let Some(header_offset) = &self.header_offset {
32269 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32270 }
32271 }
32272 }
32273}
32274#[doc = "Get / dump link stats."]
32275#[derive(Clone)]
32276pub enum OpGetstatsDoReply<'a> {
32277 Link64(PushRtnlLinkStats64),
32278 LinkXstats(&'a [u8]),
32279 LinkXstatsSlave(&'a [u8]),
32280 LinkOffloadXstats(IterableLinkOffloadXstats<'a>),
32281 AfSpec(&'a [u8]),
32282}
32283impl<'a> IterableOpGetstatsDoReply<'a> {
32284 pub fn get_link_64(&self) -> Result<PushRtnlLinkStats64, ErrorContext> {
32285 let mut iter = self.clone();
32286 iter.pos = 0;
32287 for attr in iter {
32288 if let OpGetstatsDoReply::Link64(val) = attr? {
32289 return Ok(val);
32290 }
32291 }
32292 Err(ErrorContext::new_missing(
32293 "OpGetstatsDoReply",
32294 "Link64",
32295 self.orig_loc,
32296 self.buf.as_ptr() as usize,
32297 ))
32298 }
32299 pub fn get_link_xstats(&self) -> Result<&'a [u8], ErrorContext> {
32300 let mut iter = self.clone();
32301 iter.pos = 0;
32302 for attr in iter {
32303 if let OpGetstatsDoReply::LinkXstats(val) = attr? {
32304 return Ok(val);
32305 }
32306 }
32307 Err(ErrorContext::new_missing(
32308 "OpGetstatsDoReply",
32309 "LinkXstats",
32310 self.orig_loc,
32311 self.buf.as_ptr() as usize,
32312 ))
32313 }
32314 pub fn get_link_xstats_slave(&self) -> Result<&'a [u8], ErrorContext> {
32315 let mut iter = self.clone();
32316 iter.pos = 0;
32317 for attr in iter {
32318 if let OpGetstatsDoReply::LinkXstatsSlave(val) = attr? {
32319 return Ok(val);
32320 }
32321 }
32322 Err(ErrorContext::new_missing(
32323 "OpGetstatsDoReply",
32324 "LinkXstatsSlave",
32325 self.orig_loc,
32326 self.buf.as_ptr() as usize,
32327 ))
32328 }
32329 pub fn get_link_offload_xstats(&self) -> Result<IterableLinkOffloadXstats<'a>, ErrorContext> {
32330 let mut iter = self.clone();
32331 iter.pos = 0;
32332 for attr in iter {
32333 if let OpGetstatsDoReply::LinkOffloadXstats(val) = attr? {
32334 return Ok(val);
32335 }
32336 }
32337 Err(ErrorContext::new_missing(
32338 "OpGetstatsDoReply",
32339 "LinkOffloadXstats",
32340 self.orig_loc,
32341 self.buf.as_ptr() as usize,
32342 ))
32343 }
32344 pub fn get_af_spec(&self) -> Result<&'a [u8], ErrorContext> {
32345 let mut iter = self.clone();
32346 iter.pos = 0;
32347 for attr in iter {
32348 if let OpGetstatsDoReply::AfSpec(val) = attr? {
32349 return Ok(val);
32350 }
32351 }
32352 Err(ErrorContext::new_missing(
32353 "OpGetstatsDoReply",
32354 "AfSpec",
32355 self.orig_loc,
32356 self.buf.as_ptr() as usize,
32357 ))
32358 }
32359}
32360impl OpGetstatsDoReply<'_> {
32361 pub fn new<'a>(buf: &'a [u8]) -> (PushIfStatsMsg, IterableOpGetstatsDoReply<'a>) {
32362 let (header, attrs) = buf.split_at(buf.len().min(PushIfStatsMsg::len()));
32363 (
32364 PushIfStatsMsg::new_from_slice(header).unwrap_or_default(),
32365 IterableOpGetstatsDoReply::with_loc(attrs, buf.as_ptr() as usize),
32366 )
32367 }
32368 fn attr_from_type(r#type: u16) -> Option<&'static str> {
32369 StatsAttrs::attr_from_type(r#type)
32370 }
32371}
32372#[derive(Clone, Copy, Default)]
32373pub struct IterableOpGetstatsDoReply<'a> {
32374 buf: &'a [u8],
32375 pos: usize,
32376 orig_loc: usize,
32377}
32378impl<'a> IterableOpGetstatsDoReply<'a> {
32379 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
32380 Self {
32381 buf,
32382 pos: 0,
32383 orig_loc,
32384 }
32385 }
32386 pub fn get_buf(&self) -> &'a [u8] {
32387 self.buf
32388 }
32389}
32390impl<'a> Iterator for IterableOpGetstatsDoReply<'a> {
32391 type Item = Result<OpGetstatsDoReply<'a>, ErrorContext>;
32392 fn next(&mut self) -> Option<Self::Item> {
32393 if self.buf.len() == self.pos {
32394 return None;
32395 }
32396 let pos = self.pos;
32397 let mut r#type = None;
32398 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
32399 r#type = Some(header.r#type);
32400 let res = match header.r#type {
32401 1u16 => OpGetstatsDoReply::Link64({
32402 let res = PushRtnlLinkStats64::new_from_slice(next);
32403 let Some(val) = res else { break };
32404 val
32405 }),
32406 2u16 => OpGetstatsDoReply::LinkXstats({
32407 let res = Some(next);
32408 let Some(val) = res else { break };
32409 val
32410 }),
32411 3u16 => OpGetstatsDoReply::LinkXstatsSlave({
32412 let res = Some(next);
32413 let Some(val) = res else { break };
32414 val
32415 }),
32416 4u16 => OpGetstatsDoReply::LinkOffloadXstats({
32417 let res = Some(IterableLinkOffloadXstats::with_loc(next, self.orig_loc));
32418 let Some(val) = res else { break };
32419 val
32420 }),
32421 5u16 => OpGetstatsDoReply::AfSpec({
32422 let res = Some(next);
32423 let Some(val) = res else { break };
32424 val
32425 }),
32426 n => {
32427 if cfg!(any(test, feature = "deny-unknown-attrs")) {
32428 break;
32429 } else {
32430 continue;
32431 }
32432 }
32433 };
32434 return Some(Ok(res));
32435 }
32436 Some(Err(ErrorContext::new(
32437 "OpGetstatsDoReply",
32438 r#type.and_then(|t| OpGetstatsDoReply::attr_from_type(t)),
32439 self.orig_loc,
32440 self.buf.as_ptr().wrapping_add(pos) as usize,
32441 )))
32442 }
32443}
32444impl<'a> std::fmt::Debug for IterableOpGetstatsDoReply<'_> {
32445 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32446 let mut fmt = f.debug_struct("OpGetstatsDoReply");
32447 for attr in self.clone() {
32448 let attr = match attr {
32449 Ok(a) => a,
32450 Err(err) => {
32451 fmt.finish()?;
32452 f.write_str("Err(")?;
32453 err.fmt(f)?;
32454 return f.write_str(")");
32455 }
32456 };
32457 match attr {
32458 OpGetstatsDoReply::Link64(val) => fmt.field("Link64", &val),
32459 OpGetstatsDoReply::LinkXstats(val) => fmt.field("LinkXstats", &val),
32460 OpGetstatsDoReply::LinkXstatsSlave(val) => fmt.field("LinkXstatsSlave", &val),
32461 OpGetstatsDoReply::LinkOffloadXstats(val) => fmt.field("LinkOffloadXstats", &val),
32462 OpGetstatsDoReply::AfSpec(val) => fmt.field("AfSpec", &val),
32463 };
32464 }
32465 fmt.finish()
32466 }
32467}
32468impl IterableOpGetstatsDoReply<'_> {
32469 pub fn lookup_attr(
32470 &self,
32471 offset: usize,
32472 missing_type: Option<u16>,
32473 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32474 let mut stack = Vec::new();
32475 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
32476 if cur == offset + PushIfStatsMsg::len() {
32477 stack.push(("OpGetstatsDoReply", offset));
32478 return (
32479 stack,
32480 missing_type.and_then(|t| OpGetstatsDoReply::attr_from_type(t)),
32481 );
32482 }
32483 if cur > offset || cur + self.buf.len() < offset {
32484 return (stack, None);
32485 }
32486 let mut attrs = self.clone();
32487 let mut last_off = cur + attrs.pos;
32488 let mut missing = None;
32489 while let Some(attr) = attrs.next() {
32490 let Ok(attr) = attr else { break };
32491 match attr {
32492 OpGetstatsDoReply::Link64(val) => {
32493 if last_off == offset {
32494 stack.push(("Link64", last_off));
32495 break;
32496 }
32497 }
32498 OpGetstatsDoReply::LinkXstats(val) => {
32499 if last_off == offset {
32500 stack.push(("LinkXstats", last_off));
32501 break;
32502 }
32503 }
32504 OpGetstatsDoReply::LinkXstatsSlave(val) => {
32505 if last_off == offset {
32506 stack.push(("LinkXstatsSlave", last_off));
32507 break;
32508 }
32509 }
32510 OpGetstatsDoReply::LinkOffloadXstats(val) => {
32511 (stack, missing) = val.lookup_attr(offset, missing_type);
32512 if !stack.is_empty() {
32513 break;
32514 }
32515 }
32516 OpGetstatsDoReply::AfSpec(val) => {
32517 if last_off == offset {
32518 stack.push(("AfSpec", last_off));
32519 break;
32520 }
32521 }
32522 _ => {}
32523 };
32524 last_off = cur + attrs.pos;
32525 }
32526 if !stack.is_empty() {
32527 stack.push(("OpGetstatsDoReply", cur));
32528 }
32529 (stack, missing)
32530 }
32531}
32532#[derive(Debug)]
32533pub struct RequestOpGetstatsDoRequest<'r> {
32534 request: Request<'r>,
32535}
32536impl<'r> RequestOpGetstatsDoRequest<'r> {
32537 pub fn new(mut request: Request<'r>, header: &PushIfStatsMsg) -> Self {
32538 PushOpGetstatsDoRequest::write_header(&mut request.buf_mut(), header);
32539 Self { request: request }
32540 }
32541 pub fn encode(&mut self) -> PushOpGetstatsDoRequest<&mut Vec<u8>> {
32542 PushOpGetstatsDoRequest::new_without_header(self.request.buf_mut())
32543 }
32544 pub fn into_encoder(self) -> PushOpGetstatsDoRequest<RequestBuf<'r>> {
32545 PushOpGetstatsDoRequest::new_without_header(self.request.buf)
32546 }
32547}
32548impl NetlinkRequest for RequestOpGetstatsDoRequest<'_> {
32549 type ReplyType<'buf> = (PushIfStatsMsg, IterableOpGetstatsDoReply<'buf>);
32550 fn protocol(&self) -> Protocol {
32551 Protocol::Raw {
32552 protonum: 0u16,
32553 request_type: 94u16,
32554 }
32555 }
32556 fn flags(&self) -> u16 {
32557 self.request.flags
32558 }
32559 fn payload(&self) -> &[u8] {
32560 self.request.buf()
32561 }
32562 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
32563 OpGetstatsDoReply::new(buf)
32564 }
32565 fn lookup(
32566 buf: &[u8],
32567 offset: usize,
32568 missing_type: Option<u16>,
32569 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32570 OpGetstatsDoRequest::new(buf)
32571 .1
32572 .lookup_attr(offset, missing_type)
32573 }
32574}
32575#[derive(Debug)]
32576pub struct ChainedFinal<'a> {
32577 inner: Chained<'a>,
32578}
32579#[derive(Debug)]
32580pub struct Chained<'a> {
32581 buf: RequestBuf<'a>,
32582 first_seq: u32,
32583 lookups: Vec<(&'static str, LookupFn)>,
32584 last_header_offset: usize,
32585 last_kind: Option<RequestInfo>,
32586}
32587impl<'a> ChainedFinal<'a> {
32588 pub fn into_chained(self) -> Chained<'a> {
32589 self.inner
32590 }
32591 pub fn buf(&self) -> &Vec<u8> {
32592 self.inner.buf()
32593 }
32594 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
32595 self.inner.buf_mut()
32596 }
32597 fn get_index(&self, seq: u32) -> Option<u32> {
32598 let min = self.inner.first_seq;
32599 let max = min.wrapping_add(self.inner.lookups.len() as u32);
32600 return if min <= max {
32601 (min..max).contains(&seq).then(|| seq - min)
32602 } else if min <= seq {
32603 Some(seq - min)
32604 } else if seq < max {
32605 Some(u32::MAX - min + seq)
32606 } else {
32607 None
32608 };
32609 }
32610}
32611impl crate::traits::NetlinkChained for ChainedFinal<'_> {
32612 fn protonum(&self) -> u16 {
32613 PROTONUM
32614 }
32615 fn payload(&self) -> &[u8] {
32616 self.buf()
32617 }
32618 fn chain_len(&self) -> usize {
32619 self.inner.lookups.len()
32620 }
32621 fn get_index(&self, seq: u32) -> Option<usize> {
32622 self.get_index(seq).map(|n| n as usize)
32623 }
32624 fn name(&self, index: usize) -> &'static str {
32625 self.inner.lookups[index].0
32626 }
32627 fn lookup(&self, index: usize) -> LookupFn {
32628 self.inner.lookups[index].1
32629 }
32630}
32631impl Chained<'static> {
32632 pub fn new(first_seq: u32) -> Self {
32633 Self::new_from_buf(Vec::new(), first_seq)
32634 }
32635 pub fn new_from_buf(buf: Vec<u8>, first_seq: u32) -> Self {
32636 Self {
32637 buf: RequestBuf::Own(buf),
32638 first_seq,
32639 lookups: Vec::new(),
32640 last_header_offset: 0,
32641 last_kind: None,
32642 }
32643 }
32644 pub fn into_buf(self) -> Vec<u8> {
32645 match self.buf {
32646 RequestBuf::Own(buf) => buf,
32647 _ => unreachable!(),
32648 }
32649 }
32650}
32651impl<'a> Chained<'a> {
32652 pub fn new_with_buf(buf: &'a mut Vec<u8>, first_seq: u32) -> Self {
32653 Self {
32654 buf: RequestBuf::Ref(buf),
32655 first_seq,
32656 lookups: Vec::new(),
32657 last_header_offset: 0,
32658 last_kind: None,
32659 }
32660 }
32661 pub fn finalize(mut self) -> ChainedFinal<'a> {
32662 self.update_header();
32663 ChainedFinal { inner: self }
32664 }
32665 pub fn request(&mut self) -> Request<'_> {
32666 self.update_header();
32667 self.last_header_offset = self.buf().len();
32668 self.buf_mut()
32669 .extend_from_slice(PushNlmsghdr::new().as_slice());
32670 let mut request = Request::new_extend(self.buf.buf_mut());
32671 self.last_kind = None;
32672 request.writeback = Some(&mut self.last_kind);
32673 request
32674 }
32675 pub fn buf(&self) -> &Vec<u8> {
32676 self.buf.buf()
32677 }
32678 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
32679 self.buf.buf_mut()
32680 }
32681 fn update_header(&mut self) {
32682 let Some(RequestInfo {
32683 protocol,
32684 flags,
32685 name,
32686 lookup,
32687 }) = self.last_kind
32688 else {
32689 if !self.buf().is_empty() {
32690 assert_eq!(
32691 self.last_header_offset + PushNlmsghdr::len(),
32692 self.buf().len()
32693 );
32694 self.buf.buf_mut().truncate(self.last_header_offset);
32695 }
32696 return;
32697 };
32698 let header_offset = self.last_header_offset;
32699 let request_type = match protocol {
32700 Protocol::Raw { request_type, .. } => request_type,
32701 Protocol::Generic(_) => unreachable!(),
32702 };
32703 let index = self.lookups.len();
32704 let seq = self.first_seq.wrapping_add(index as u32);
32705 self.lookups.push((name, lookup));
32706 let buf = self.buf_mut();
32707 align(buf);
32708 let mut header = PushNlmsghdr::new();
32709 header.set_len((buf.len() - header_offset) as u32);
32710 header.set_type(request_type);
32711 header.set_flags(flags | consts::NLM_F_REQUEST as u16 | consts::NLM_F_ACK as u16);
32712 header.set_seq(seq);
32713 buf[header_offset..(header_offset + 16)].clone_from_slice(header.as_slice());
32714 }
32715}
32716use crate::traits::LookupFn;
32717use crate::utils::RequestBuf;
32718#[derive(Debug)]
32719pub struct Request<'buf> {
32720 buf: RequestBuf<'buf>,
32721 flags: u16,
32722 writeback: Option<&'buf mut Option<RequestInfo>>,
32723}
32724#[allow(unused)]
32725#[derive(Debug, Clone)]
32726pub struct RequestInfo {
32727 protocol: Protocol,
32728 flags: u16,
32729 name: &'static str,
32730 lookup: LookupFn,
32731}
32732impl Request<'static> {
32733 pub fn new() -> Self {
32734 Self::new_from_buf(Vec::new())
32735 }
32736 pub fn new_from_buf(buf: Vec<u8>) -> Self {
32737 Self {
32738 flags: 0,
32739 buf: RequestBuf::Own(buf),
32740 writeback: None,
32741 }
32742 }
32743 pub fn into_buf(self) -> Vec<u8> {
32744 match self.buf {
32745 RequestBuf::Own(buf) => buf,
32746 _ => unreachable!(),
32747 }
32748 }
32749}
32750impl<'buf> Request<'buf> {
32751 pub fn new_with_buf(buf: &'buf mut Vec<u8>) -> Self {
32752 buf.clear();
32753 Self::new_extend(buf)
32754 }
32755 pub fn new_extend(buf: &'buf mut Vec<u8>) -> Self {
32756 Self {
32757 flags: 0,
32758 buf: RequestBuf::Ref(buf),
32759 writeback: None,
32760 }
32761 }
32762 fn do_writeback(&mut self, protocol: Protocol, name: &'static str, lookup: LookupFn) {
32763 let Some(writeback) = &mut self.writeback else {
32764 return;
32765 };
32766 **writeback = Some(RequestInfo {
32767 protocol,
32768 flags: self.flags,
32769 name,
32770 lookup,
32771 })
32772 }
32773 pub fn buf(&self) -> &Vec<u8> {
32774 self.buf.buf()
32775 }
32776 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
32777 self.buf.buf_mut()
32778 }
32779 #[doc = "Set `NLM_F_CREATE` flag"]
32780 pub fn set_create(mut self) -> Self {
32781 self.flags |= consts::NLM_F_CREATE as u16;
32782 self
32783 }
32784 #[doc = "Set `NLM_F_EXCL` flag"]
32785 pub fn set_excl(mut self) -> Self {
32786 self.flags |= consts::NLM_F_EXCL as u16;
32787 self
32788 }
32789 #[doc = "Set `NLM_F_REPLACE` flag"]
32790 pub fn set_replace(mut self) -> Self {
32791 self.flags |= consts::NLM_F_REPLACE as u16;
32792 self
32793 }
32794 #[doc = "Set `NLM_F_CREATE` and `NLM_F_REPLACE` flag"]
32795 pub fn set_change(self) -> Self {
32796 self.set_create().set_replace()
32797 }
32798 #[doc = "Set `NLM_F_APPEND` flag"]
32799 pub fn set_append(mut self) -> Self {
32800 self.flags |= consts::NLM_F_APPEND as u16;
32801 self
32802 }
32803 #[doc = "Set `NLM_F_DUMP` flag"]
32804 fn set_dump(mut self) -> Self {
32805 self.flags |= consts::NLM_F_DUMP as u16;
32806 self
32807 }
32808 pub fn op_newlink_do_request(self, header: &PushIfinfomsg) -> RequestOpNewlinkDoRequest<'buf> {
32809 let mut res = RequestOpNewlinkDoRequest::new(self, header);
32810 res.request.do_writeback(
32811 res.protocol(),
32812 "op-newlink-do-request",
32813 RequestOpNewlinkDoRequest::lookup,
32814 );
32815 res
32816 }
32817 pub fn op_dellink_do_request(self, header: &PushIfinfomsg) -> RequestOpDellinkDoRequest<'buf> {
32818 let mut res = RequestOpDellinkDoRequest::new(self, header);
32819 res.request.do_writeback(
32820 res.protocol(),
32821 "op-dellink-do-request",
32822 RequestOpDellinkDoRequest::lookup,
32823 );
32824 res
32825 }
32826 pub fn op_getlink_dump_request(
32827 self,
32828 header: &PushIfinfomsg,
32829 ) -> RequestOpGetlinkDumpRequest<'buf> {
32830 let mut res = RequestOpGetlinkDumpRequest::new(self, header);
32831 res.request.do_writeback(
32832 res.protocol(),
32833 "op-getlink-dump-request",
32834 RequestOpGetlinkDumpRequest::lookup,
32835 );
32836 res
32837 }
32838 pub fn op_getlink_do_request(self, header: &PushIfinfomsg) -> RequestOpGetlinkDoRequest<'buf> {
32839 let mut res = RequestOpGetlinkDoRequest::new(self, header);
32840 res.request.do_writeback(
32841 res.protocol(),
32842 "op-getlink-do-request",
32843 RequestOpGetlinkDoRequest::lookup,
32844 );
32845 res
32846 }
32847 pub fn op_setlink_do_request(self, header: &PushIfinfomsg) -> RequestOpSetlinkDoRequest<'buf> {
32848 let mut res = RequestOpSetlinkDoRequest::new(self, header);
32849 res.request.do_writeback(
32850 res.protocol(),
32851 "op-setlink-do-request",
32852 RequestOpSetlinkDoRequest::lookup,
32853 );
32854 res
32855 }
32856 pub fn op_getstats_dump_request(
32857 self,
32858 header: &PushIfStatsMsg,
32859 ) -> RequestOpGetstatsDumpRequest<'buf> {
32860 let mut res = RequestOpGetstatsDumpRequest::new(self, header);
32861 res.request.do_writeback(
32862 res.protocol(),
32863 "op-getstats-dump-request",
32864 RequestOpGetstatsDumpRequest::lookup,
32865 );
32866 res
32867 }
32868 pub fn op_getstats_do_request(
32869 self,
32870 header: &PushIfStatsMsg,
32871 ) -> RequestOpGetstatsDoRequest<'buf> {
32872 let mut res = RequestOpGetstatsDoRequest::new(self, header);
32873 res.request.do_writeback(
32874 res.protocol(),
32875 "op-getstats-do-request",
32876 RequestOpGetstatsDoRequest::lookup,
32877 );
32878 res
32879 }
32880}