1#![doc = "Netlink raw family for tc qdisc, chain, class and filter configuration\nover rtnetlink.\n"]
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)]
10#[cfg(test)]
11mod tests;
12use crate::builtin::{BuiltinBitfield32, BuiltinNfgenmsg, Nlmsghdr, PushDummy};
13use crate::{
14 consts,
15 traits::{NetlinkRequest, Protocol},
16 utils::*,
17};
18pub const PROTONAME: &str = "tc";
19pub const PROTONAME_CSTR: &CStr = c"tc";
20pub const PROTONUM: u16 = 0u16;
21#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
22#[derive(Debug, Clone, Copy)]
23pub enum ClsFlags {
24 SkipHw = 1 << 0,
25 SkipSw = 1 << 1,
26 InHw = 1 << 2,
27 NotInNw = 1 << 3,
28 Verbose = 1 << 4,
29}
30impl ClsFlags {
31 pub fn from_value(value: u64) -> Option<Self> {
32 Some(match value {
33 n if n == 1 << 0 => Self::SkipHw,
34 n if n == 1 << 1 => Self::SkipSw,
35 n if n == 1 << 2 => Self::InHw,
36 n if n == 1 << 3 => Self::NotInNw,
37 n if n == 1 << 4 => Self::Verbose,
38 _ => return None,
39 })
40 }
41}
42#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
43#[derive(Debug, Clone, Copy)]
44pub enum FlowerKeyCtrlFlags {
45 Frag = 1 << 0,
46 Firstfrag = 1 << 1,
47 Tuncsum = 1 << 2,
48 Tundf = 1 << 3,
49 Tunoam = 1 << 4,
50 Tuncrit = 1 << 5,
51}
52impl FlowerKeyCtrlFlags {
53 pub fn from_value(value: u64) -> Option<Self> {
54 Some(match value {
55 n if n == 1 << 0 => Self::Frag,
56 n if n == 1 << 1 => Self::Firstfrag,
57 n if n == 1 << 2 => Self::Tuncsum,
58 n if n == 1 << 3 => Self::Tundf,
59 n if n == 1 << 4 => Self::Tunoam,
60 n if n == 1 << 5 => Self::Tuncrit,
61 _ => return None,
62 })
63 }
64}
65#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
66#[derive(Debug, Clone, Copy)]
67pub enum Dualpi2DropOverload {
68 Overflow = 0,
69 Drop = 1,
70}
71impl Dualpi2DropOverload {
72 pub fn from_value(value: u64) -> Option<Self> {
73 Some(match value {
74 0 => Self::Overflow,
75 1 => Self::Drop,
76 _ => return None,
77 })
78 }
79}
80#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
81#[derive(Debug, Clone, Copy)]
82pub enum Dualpi2DropEarly {
83 DropDequeue = 0,
84 DropEnqueue = 1,
85}
86impl Dualpi2DropEarly {
87 pub fn from_value(value: u64) -> Option<Self> {
88 Some(match value {
89 0 => Self::DropDequeue,
90 1 => Self::DropEnqueue,
91 _ => return None,
92 })
93 }
94}
95#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
96#[derive(Debug, Clone, Copy)]
97pub enum Dualpi2EcnMask {
98 L4sEct = 1,
99 ClaEct = 2,
100 AnyEct = 3,
101}
102impl Dualpi2EcnMask {
103 pub fn from_value(value: u64) -> Option<Self> {
104 Some(match value {
105 1 => Self::L4sEct,
106 2 => Self::ClaEct,
107 3 => Self::AnyEct,
108 _ => return None,
109 })
110 }
111}
112#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
113#[derive(Debug, Clone, Copy)]
114pub enum Dualpi2SplitGso {
115 NoSplitGso = 0,
116 SplitGso = 1,
117}
118impl Dualpi2SplitGso {
119 pub fn from_value(value: u64) -> Option<Self> {
120 Some(match value {
121 0 => Self::NoSplitGso,
122 1 => Self::SplitGso,
123 _ => return None,
124 })
125 }
126}
127#[repr(C, packed(4))]
128pub struct Tcmsg {
129 pub family: u8,
130 pub _pad: [u8; 3usize],
131 pub ifindex: i32,
132 pub handle: u32,
133 pub parent: u32,
134 pub info: u32,
135}
136impl Clone for Tcmsg {
137 fn clone(&self) -> Self {
138 Self::new_from_array(*self.as_array())
139 }
140}
141#[doc = "Create zero-initialized struct"]
142impl Default for Tcmsg {
143 fn default() -> Self {
144 Self::new()
145 }
146}
147impl Tcmsg {
148 #[doc = "Create zero-initialized struct"]
149 pub fn new() -> Self {
150 Self::new_from_array([0u8; Self::len()])
151 }
152 #[doc = "Copy from contents from slice"]
153 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
154 if other.len() != Self::len() {
155 return None;
156 }
157 let mut buf = [0u8; Self::len()];
158 buf.clone_from_slice(other);
159 Some(Self::new_from_array(buf))
160 }
161 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
162 pub fn new_from_zeroed(other: &[u8]) -> Self {
163 let mut buf = [0u8; Self::len()];
164 let len = buf.len().min(other.len());
165 buf[..len].clone_from_slice(&other[..len]);
166 Self::new_from_array(buf)
167 }
168 pub fn new_from_array(buf: [u8; 20usize]) -> Self {
169 unsafe { std::mem::transmute(buf) }
170 }
171 pub fn as_slice(&self) -> &[u8] {
172 unsafe {
173 let ptr: *const u8 = std::mem::transmute(self as *const Self);
174 std::slice::from_raw_parts(ptr, Self::len())
175 }
176 }
177 pub fn from_slice(buf: &[u8]) -> &Self {
178 assert!(buf.len() >= Self::len());
179 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
180 unsafe { std::mem::transmute(buf.as_ptr()) }
181 }
182 pub fn as_array(&self) -> &[u8; 20usize] {
183 unsafe { std::mem::transmute(self) }
184 }
185 pub fn from_array(buf: &[u8; 20usize]) -> &Self {
186 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
187 unsafe { std::mem::transmute(buf) }
188 }
189 pub fn into_array(self) -> [u8; 20usize] {
190 unsafe { std::mem::transmute(self) }
191 }
192 pub const fn len() -> usize {
193 const _: () = assert!(std::mem::size_of::<Tcmsg>() == 20usize);
194 20usize
195 }
196}
197impl std::fmt::Debug for Tcmsg {
198 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
199 fmt.debug_struct("Tcmsg")
200 .field("family", &self.family)
201 .field("ifindex", &self.ifindex)
202 .field("handle", &self.handle)
203 .field("parent", &self.parent)
204 .field("info", &self.info)
205 .finish()
206 }
207}
208#[repr(C, packed(4))]
209pub struct TcStats {
210 #[doc = "Number of enqueued bytes\n"]
211 pub bytes: u64,
212 #[doc = "Number of enqueued packets\n"]
213 pub packets: u32,
214 #[doc = "Packets dropped because of lack of resources\n"]
215 pub drops: u32,
216 #[doc = "Number of throttle events when this flow goes out of allocated bandwidth\n"]
217 pub overlimits: u32,
218 #[doc = "Current flow byte rate\n"]
219 pub bps: u32,
220 #[doc = "Current flow packet rate\n"]
221 pub pps: u32,
222 pub qlen: u32,
223 pub backlog: u32,
224 pub _pad_36: [u8; 4usize],
225}
226impl Clone for TcStats {
227 fn clone(&self) -> Self {
228 Self::new_from_array(*self.as_array())
229 }
230}
231#[doc = "Create zero-initialized struct"]
232impl Default for TcStats {
233 fn default() -> Self {
234 Self::new()
235 }
236}
237impl TcStats {
238 #[doc = "Create zero-initialized struct"]
239 pub fn new() -> Self {
240 Self::new_from_array([0u8; Self::len()])
241 }
242 #[doc = "Copy from contents from slice"]
243 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
244 if other.len() != Self::len() {
245 return None;
246 }
247 let mut buf = [0u8; Self::len()];
248 buf.clone_from_slice(other);
249 Some(Self::new_from_array(buf))
250 }
251 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
252 pub fn new_from_zeroed(other: &[u8]) -> Self {
253 let mut buf = [0u8; Self::len()];
254 let len = buf.len().min(other.len());
255 buf[..len].clone_from_slice(&other[..len]);
256 Self::new_from_array(buf)
257 }
258 pub fn new_from_array(buf: [u8; 40usize]) -> Self {
259 unsafe { std::mem::transmute(buf) }
260 }
261 pub fn as_slice(&self) -> &[u8] {
262 unsafe {
263 let ptr: *const u8 = std::mem::transmute(self as *const Self);
264 std::slice::from_raw_parts(ptr, Self::len())
265 }
266 }
267 pub fn from_slice(buf: &[u8]) -> &Self {
268 assert!(buf.len() >= Self::len());
269 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
270 unsafe { std::mem::transmute(buf.as_ptr()) }
271 }
272 pub fn as_array(&self) -> &[u8; 40usize] {
273 unsafe { std::mem::transmute(self) }
274 }
275 pub fn from_array(buf: &[u8; 40usize]) -> &Self {
276 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
277 unsafe { std::mem::transmute(buf) }
278 }
279 pub fn into_array(self) -> [u8; 40usize] {
280 unsafe { std::mem::transmute(self) }
281 }
282 pub const fn len() -> usize {
283 const _: () = assert!(std::mem::size_of::<TcStats>() == 40usize);
284 40usize
285 }
286}
287impl std::fmt::Debug for TcStats {
288 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
289 fmt.debug_struct("TcStats")
290 .field("bytes", &{ self.bytes })
291 .field("packets", &self.packets)
292 .field("drops", &self.drops)
293 .field("overlimits", &self.overlimits)
294 .field("bps", &self.bps)
295 .field("pps", &self.pps)
296 .field("qlen", &self.qlen)
297 .field("backlog", &self.backlog)
298 .finish()
299 }
300}
301#[repr(C, packed(4))]
302pub struct TcCbsQopt {
303 pub offload: u8,
304 pub _pad: [u8; 3usize],
305 pub hicredit: i32,
306 pub locredit: i32,
307 pub idleslope: i32,
308 pub sendslope: i32,
309}
310impl Clone for TcCbsQopt {
311 fn clone(&self) -> Self {
312 Self::new_from_array(*self.as_array())
313 }
314}
315#[doc = "Create zero-initialized struct"]
316impl Default for TcCbsQopt {
317 fn default() -> Self {
318 Self::new()
319 }
320}
321impl TcCbsQopt {
322 #[doc = "Create zero-initialized struct"]
323 pub fn new() -> Self {
324 Self::new_from_array([0u8; Self::len()])
325 }
326 #[doc = "Copy from contents from slice"]
327 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
328 if other.len() != Self::len() {
329 return None;
330 }
331 let mut buf = [0u8; Self::len()];
332 buf.clone_from_slice(other);
333 Some(Self::new_from_array(buf))
334 }
335 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
336 pub fn new_from_zeroed(other: &[u8]) -> Self {
337 let mut buf = [0u8; Self::len()];
338 let len = buf.len().min(other.len());
339 buf[..len].clone_from_slice(&other[..len]);
340 Self::new_from_array(buf)
341 }
342 pub fn new_from_array(buf: [u8; 20usize]) -> Self {
343 unsafe { std::mem::transmute(buf) }
344 }
345 pub fn as_slice(&self) -> &[u8] {
346 unsafe {
347 let ptr: *const u8 = std::mem::transmute(self as *const Self);
348 std::slice::from_raw_parts(ptr, Self::len())
349 }
350 }
351 pub fn from_slice(buf: &[u8]) -> &Self {
352 assert!(buf.len() >= Self::len());
353 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
354 unsafe { std::mem::transmute(buf.as_ptr()) }
355 }
356 pub fn as_array(&self) -> &[u8; 20usize] {
357 unsafe { std::mem::transmute(self) }
358 }
359 pub fn from_array(buf: &[u8; 20usize]) -> &Self {
360 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
361 unsafe { std::mem::transmute(buf) }
362 }
363 pub fn into_array(self) -> [u8; 20usize] {
364 unsafe { std::mem::transmute(self) }
365 }
366 pub const fn len() -> usize {
367 const _: () = assert!(std::mem::size_of::<TcCbsQopt>() == 20usize);
368 20usize
369 }
370}
371impl std::fmt::Debug for TcCbsQopt {
372 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
373 fmt.debug_struct("TcCbsQopt")
374 .field("offload", &self.offload)
375 .field("hicredit", &self.hicredit)
376 .field("locredit", &self.locredit)
377 .field("idleslope", &self.idleslope)
378 .field("sendslope", &self.sendslope)
379 .finish()
380 }
381}
382#[derive(Debug)]
383#[repr(C, packed(4))]
384pub struct TcEtfQopt {
385 pub delta: i32,
386 pub clockid: i32,
387 pub flags: i32,
388}
389impl Clone for TcEtfQopt {
390 fn clone(&self) -> Self {
391 Self::new_from_array(*self.as_array())
392 }
393}
394#[doc = "Create zero-initialized struct"]
395impl Default for TcEtfQopt {
396 fn default() -> Self {
397 Self::new()
398 }
399}
400impl TcEtfQopt {
401 #[doc = "Create zero-initialized struct"]
402 pub fn new() -> Self {
403 Self::new_from_array([0u8; Self::len()])
404 }
405 #[doc = "Copy from contents from slice"]
406 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
407 if other.len() != Self::len() {
408 return None;
409 }
410 let mut buf = [0u8; Self::len()];
411 buf.clone_from_slice(other);
412 Some(Self::new_from_array(buf))
413 }
414 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
415 pub fn new_from_zeroed(other: &[u8]) -> Self {
416 let mut buf = [0u8; Self::len()];
417 let len = buf.len().min(other.len());
418 buf[..len].clone_from_slice(&other[..len]);
419 Self::new_from_array(buf)
420 }
421 pub fn new_from_array(buf: [u8; 12usize]) -> Self {
422 unsafe { std::mem::transmute(buf) }
423 }
424 pub fn as_slice(&self) -> &[u8] {
425 unsafe {
426 let ptr: *const u8 = std::mem::transmute(self as *const Self);
427 std::slice::from_raw_parts(ptr, Self::len())
428 }
429 }
430 pub fn from_slice(buf: &[u8]) -> &Self {
431 assert!(buf.len() >= Self::len());
432 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
433 unsafe { std::mem::transmute(buf.as_ptr()) }
434 }
435 pub fn as_array(&self) -> &[u8; 12usize] {
436 unsafe { std::mem::transmute(self) }
437 }
438 pub fn from_array(buf: &[u8; 12usize]) -> &Self {
439 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
440 unsafe { std::mem::transmute(buf) }
441 }
442 pub fn into_array(self) -> [u8; 12usize] {
443 unsafe { std::mem::transmute(self) }
444 }
445 pub const fn len() -> usize {
446 const _: () = assert!(std::mem::size_of::<TcEtfQopt>() == 12usize);
447 12usize
448 }
449}
450#[derive(Debug)]
451#[repr(C, packed(4))]
452pub struct TcFifoQopt {
453 #[doc = "Queue length; bytes for bfifo, packets for pfifo\n"]
454 pub limit: u32,
455}
456impl Clone for TcFifoQopt {
457 fn clone(&self) -> Self {
458 Self::new_from_array(*self.as_array())
459 }
460}
461#[doc = "Create zero-initialized struct"]
462impl Default for TcFifoQopt {
463 fn default() -> Self {
464 Self::new()
465 }
466}
467impl TcFifoQopt {
468 #[doc = "Create zero-initialized struct"]
469 pub fn new() -> Self {
470 Self::new_from_array([0u8; Self::len()])
471 }
472 #[doc = "Copy from contents from slice"]
473 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
474 if other.len() != Self::len() {
475 return None;
476 }
477 let mut buf = [0u8; Self::len()];
478 buf.clone_from_slice(other);
479 Some(Self::new_from_array(buf))
480 }
481 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
482 pub fn new_from_zeroed(other: &[u8]) -> Self {
483 let mut buf = [0u8; Self::len()];
484 let len = buf.len().min(other.len());
485 buf[..len].clone_from_slice(&other[..len]);
486 Self::new_from_array(buf)
487 }
488 pub fn new_from_array(buf: [u8; 4usize]) -> Self {
489 unsafe { std::mem::transmute(buf) }
490 }
491 pub fn as_slice(&self) -> &[u8] {
492 unsafe {
493 let ptr: *const u8 = std::mem::transmute(self as *const Self);
494 std::slice::from_raw_parts(ptr, Self::len())
495 }
496 }
497 pub fn from_slice(buf: &[u8]) -> &Self {
498 assert!(buf.len() >= Self::len());
499 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
500 unsafe { std::mem::transmute(buf.as_ptr()) }
501 }
502 pub fn as_array(&self) -> &[u8; 4usize] {
503 unsafe { std::mem::transmute(self) }
504 }
505 pub fn from_array(buf: &[u8; 4usize]) -> &Self {
506 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
507 unsafe { std::mem::transmute(buf) }
508 }
509 pub fn into_array(self) -> [u8; 4usize] {
510 unsafe { std::mem::transmute(self) }
511 }
512 pub const fn len() -> usize {
513 const _: () = assert!(std::mem::size_of::<TcFifoQopt>() == 4usize);
514 4usize
515 }
516}
517#[repr(C, packed(4))]
518pub struct TcHtbOpt {
519 pub rate: TcRatespec,
520 pub ceil: TcRatespec,
521 pub buffer: u32,
522 pub cbuffer: u32,
523 pub quantum: u32,
524 pub level: u32,
525 pub prio: u32,
526}
527impl Clone for TcHtbOpt {
528 fn clone(&self) -> Self {
529 Self::new_from_array(*self.as_array())
530 }
531}
532#[doc = "Create zero-initialized struct"]
533impl Default for TcHtbOpt {
534 fn default() -> Self {
535 Self::new()
536 }
537}
538impl TcHtbOpt {
539 #[doc = "Create zero-initialized struct"]
540 pub fn new() -> Self {
541 Self::new_from_array([0u8; Self::len()])
542 }
543 #[doc = "Copy from contents from slice"]
544 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
545 if other.len() != Self::len() {
546 return None;
547 }
548 let mut buf = [0u8; Self::len()];
549 buf.clone_from_slice(other);
550 Some(Self::new_from_array(buf))
551 }
552 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
553 pub fn new_from_zeroed(other: &[u8]) -> Self {
554 let mut buf = [0u8; Self::len()];
555 let len = buf.len().min(other.len());
556 buf[..len].clone_from_slice(&other[..len]);
557 Self::new_from_array(buf)
558 }
559 pub fn new_from_array(buf: [u8; 44usize]) -> Self {
560 unsafe { std::mem::transmute(buf) }
561 }
562 pub fn as_slice(&self) -> &[u8] {
563 unsafe {
564 let ptr: *const u8 = std::mem::transmute(self as *const Self);
565 std::slice::from_raw_parts(ptr, Self::len())
566 }
567 }
568 pub fn from_slice(buf: &[u8]) -> &Self {
569 assert!(buf.len() >= Self::len());
570 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
571 unsafe { std::mem::transmute(buf.as_ptr()) }
572 }
573 pub fn as_array(&self) -> &[u8; 44usize] {
574 unsafe { std::mem::transmute(self) }
575 }
576 pub fn from_array(buf: &[u8; 44usize]) -> &Self {
577 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
578 unsafe { std::mem::transmute(buf) }
579 }
580 pub fn into_array(self) -> [u8; 44usize] {
581 unsafe { std::mem::transmute(self) }
582 }
583 pub const fn len() -> usize {
584 const _: () = assert!(std::mem::size_of::<TcHtbOpt>() == 44usize);
585 44usize
586 }
587}
588impl std::fmt::Debug for TcHtbOpt {
589 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
590 fmt.debug_struct("TcHtbOpt")
591 .field("rate", &self.rate)
592 .field("ceil", &self.ceil)
593 .field("buffer", &self.buffer)
594 .field("cbuffer", &self.cbuffer)
595 .field("quantum", &self.quantum)
596 .field("level", &self.level)
597 .field("prio", &self.prio)
598 .finish()
599 }
600}
601#[derive(Debug)]
602#[repr(C, packed(4))]
603pub struct TcHtbGlob {
604 pub version: u32,
605 #[doc = "bps-\\>quantum divisor\n"]
606 pub rate2quantum: u32,
607 #[doc = "Default class number\n"]
608 pub defcls: u32,
609 #[doc = "Debug flags\n"]
610 pub debug: u32,
611 #[doc = "Count of non shaped packets\n"]
612 pub direct_pkts: u32,
613}
614impl Clone for TcHtbGlob {
615 fn clone(&self) -> Self {
616 Self::new_from_array(*self.as_array())
617 }
618}
619#[doc = "Create zero-initialized struct"]
620impl Default for TcHtbGlob {
621 fn default() -> Self {
622 Self::new()
623 }
624}
625impl TcHtbGlob {
626 #[doc = "Create zero-initialized struct"]
627 pub fn new() -> Self {
628 Self::new_from_array([0u8; Self::len()])
629 }
630 #[doc = "Copy from contents from slice"]
631 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
632 if other.len() != Self::len() {
633 return None;
634 }
635 let mut buf = [0u8; Self::len()];
636 buf.clone_from_slice(other);
637 Some(Self::new_from_array(buf))
638 }
639 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
640 pub fn new_from_zeroed(other: &[u8]) -> Self {
641 let mut buf = [0u8; Self::len()];
642 let len = buf.len().min(other.len());
643 buf[..len].clone_from_slice(&other[..len]);
644 Self::new_from_array(buf)
645 }
646 pub fn new_from_array(buf: [u8; 20usize]) -> Self {
647 unsafe { std::mem::transmute(buf) }
648 }
649 pub fn as_slice(&self) -> &[u8] {
650 unsafe {
651 let ptr: *const u8 = std::mem::transmute(self as *const Self);
652 std::slice::from_raw_parts(ptr, Self::len())
653 }
654 }
655 pub fn from_slice(buf: &[u8]) -> &Self {
656 assert!(buf.len() >= Self::len());
657 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
658 unsafe { std::mem::transmute(buf.as_ptr()) }
659 }
660 pub fn as_array(&self) -> &[u8; 20usize] {
661 unsafe { std::mem::transmute(self) }
662 }
663 pub fn from_array(buf: &[u8; 20usize]) -> &Self {
664 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
665 unsafe { std::mem::transmute(buf) }
666 }
667 pub fn into_array(self) -> [u8; 20usize] {
668 unsafe { std::mem::transmute(self) }
669 }
670 pub const fn len() -> usize {
671 const _: () = assert!(std::mem::size_of::<TcHtbGlob>() == 20usize);
672 20usize
673 }
674}
675#[derive(Debug)]
676#[repr(C, packed(4))]
677pub struct TcGredQopt {
678 #[doc = "HARD maximal queue length in bytes\n"]
679 pub limit: u32,
680 #[doc = "Min average length threshold in bytes\n"]
681 pub qth_min: u32,
682 #[doc = "Max average length threshold in bytes\n"]
683 pub qth_max: u32,
684 #[doc = "Up to 2\\^32 DPs\n"]
685 pub DP: u32,
686 pub backlog: u32,
687 pub qave: u32,
688 pub forced: u32,
689 pub early: u32,
690 pub other: u32,
691 pub pdrop: u32,
692 #[doc = "log(W)\n"]
693 pub Wlog: u8,
694 #[doc = "log(P_max / (qth-max - qth-min))\n"]
695 pub Plog: u8,
696 #[doc = "cell size for idle damping\n"]
697 pub Scell_log: u8,
698 #[doc = "Priority of this VQ\n"]
699 pub prio: u8,
700 pub packets: u32,
701 pub bytesin: u32,
702}
703impl Clone for TcGredQopt {
704 fn clone(&self) -> Self {
705 Self::new_from_array(*self.as_array())
706 }
707}
708#[doc = "Create zero-initialized struct"]
709impl Default for TcGredQopt {
710 fn default() -> Self {
711 Self::new()
712 }
713}
714impl TcGredQopt {
715 #[doc = "Create zero-initialized struct"]
716 pub fn new() -> Self {
717 Self::new_from_array([0u8; Self::len()])
718 }
719 #[doc = "Copy from contents from slice"]
720 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
721 if other.len() != Self::len() {
722 return None;
723 }
724 let mut buf = [0u8; Self::len()];
725 buf.clone_from_slice(other);
726 Some(Self::new_from_array(buf))
727 }
728 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
729 pub fn new_from_zeroed(other: &[u8]) -> Self {
730 let mut buf = [0u8; Self::len()];
731 let len = buf.len().min(other.len());
732 buf[..len].clone_from_slice(&other[..len]);
733 Self::new_from_array(buf)
734 }
735 pub fn new_from_array(buf: [u8; 52usize]) -> Self {
736 unsafe { std::mem::transmute(buf) }
737 }
738 pub fn as_slice(&self) -> &[u8] {
739 unsafe {
740 let ptr: *const u8 = std::mem::transmute(self as *const Self);
741 std::slice::from_raw_parts(ptr, Self::len())
742 }
743 }
744 pub fn from_slice(buf: &[u8]) -> &Self {
745 assert!(buf.len() >= Self::len());
746 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
747 unsafe { std::mem::transmute(buf.as_ptr()) }
748 }
749 pub fn as_array(&self) -> &[u8; 52usize] {
750 unsafe { std::mem::transmute(self) }
751 }
752 pub fn from_array(buf: &[u8; 52usize]) -> &Self {
753 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
754 unsafe { std::mem::transmute(buf) }
755 }
756 pub fn into_array(self) -> [u8; 52usize] {
757 unsafe { std::mem::transmute(self) }
758 }
759 pub const fn len() -> usize {
760 const _: () = assert!(std::mem::size_of::<TcGredQopt>() == 52usize);
761 52usize
762 }
763}
764#[repr(C, packed(4))]
765pub struct TcGredSopt {
766 pub DPs: u32,
767 pub def_DP: u32,
768 pub grio: u8,
769 pub flags: u8,
770 pub _pad: [u8; 2usize],
771}
772impl Clone for TcGredSopt {
773 fn clone(&self) -> Self {
774 Self::new_from_array(*self.as_array())
775 }
776}
777#[doc = "Create zero-initialized struct"]
778impl Default for TcGredSopt {
779 fn default() -> Self {
780 Self::new()
781 }
782}
783impl TcGredSopt {
784 #[doc = "Create zero-initialized struct"]
785 pub fn new() -> Self {
786 Self::new_from_array([0u8; Self::len()])
787 }
788 #[doc = "Copy from contents from slice"]
789 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
790 if other.len() != Self::len() {
791 return None;
792 }
793 let mut buf = [0u8; Self::len()];
794 buf.clone_from_slice(other);
795 Some(Self::new_from_array(buf))
796 }
797 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
798 pub fn new_from_zeroed(other: &[u8]) -> Self {
799 let mut buf = [0u8; Self::len()];
800 let len = buf.len().min(other.len());
801 buf[..len].clone_from_slice(&other[..len]);
802 Self::new_from_array(buf)
803 }
804 pub fn new_from_array(buf: [u8; 12usize]) -> Self {
805 unsafe { std::mem::transmute(buf) }
806 }
807 pub fn as_slice(&self) -> &[u8] {
808 unsafe {
809 let ptr: *const u8 = std::mem::transmute(self as *const Self);
810 std::slice::from_raw_parts(ptr, Self::len())
811 }
812 }
813 pub fn from_slice(buf: &[u8]) -> &Self {
814 assert!(buf.len() >= Self::len());
815 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
816 unsafe { std::mem::transmute(buf.as_ptr()) }
817 }
818 pub fn as_array(&self) -> &[u8; 12usize] {
819 unsafe { std::mem::transmute(self) }
820 }
821 pub fn from_array(buf: &[u8; 12usize]) -> &Self {
822 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
823 unsafe { std::mem::transmute(buf) }
824 }
825 pub fn into_array(self) -> [u8; 12usize] {
826 unsafe { std::mem::transmute(self) }
827 }
828 pub const fn len() -> usize {
829 const _: () = assert!(std::mem::size_of::<TcGredSopt>() == 12usize);
830 12usize
831 }
832}
833impl std::fmt::Debug for TcGredSopt {
834 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
835 fmt.debug_struct("TcGredSopt")
836 .field("DPs", &self.DPs)
837 .field("def_DP", &self.def_DP)
838 .field("grio", &self.grio)
839 .field("flags", &self.flags)
840 .finish()
841 }
842}
843#[derive(Debug)]
844#[repr(C, packed(4))]
845pub struct TcHfscQopt {
846 pub defcls: u16,
847}
848impl Clone for TcHfscQopt {
849 fn clone(&self) -> Self {
850 Self::new_from_array(*self.as_array())
851 }
852}
853#[doc = "Create zero-initialized struct"]
854impl Default for TcHfscQopt {
855 fn default() -> Self {
856 Self::new()
857 }
858}
859impl TcHfscQopt {
860 #[doc = "Create zero-initialized struct"]
861 pub fn new() -> Self {
862 Self::new_from_array([0u8; Self::len()])
863 }
864 #[doc = "Copy from contents from slice"]
865 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
866 if other.len() != Self::len() {
867 return None;
868 }
869 let mut buf = [0u8; Self::len()];
870 buf.clone_from_slice(other);
871 Some(Self::new_from_array(buf))
872 }
873 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
874 pub fn new_from_zeroed(other: &[u8]) -> Self {
875 let mut buf = [0u8; Self::len()];
876 let len = buf.len().min(other.len());
877 buf[..len].clone_from_slice(&other[..len]);
878 Self::new_from_array(buf)
879 }
880 pub fn new_from_array(buf: [u8; 2usize]) -> Self {
881 unsafe { std::mem::transmute(buf) }
882 }
883 pub fn as_slice(&self) -> &[u8] {
884 unsafe {
885 let ptr: *const u8 = std::mem::transmute(self as *const Self);
886 std::slice::from_raw_parts(ptr, Self::len())
887 }
888 }
889 pub fn from_slice(buf: &[u8]) -> &Self {
890 assert!(buf.len() >= Self::len());
891 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
892 unsafe { std::mem::transmute(buf.as_ptr()) }
893 }
894 pub fn as_array(&self) -> &[u8; 2usize] {
895 unsafe { std::mem::transmute(self) }
896 }
897 pub fn from_array(buf: &[u8; 2usize]) -> &Self {
898 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
899 unsafe { std::mem::transmute(buf) }
900 }
901 pub fn into_array(self) -> [u8; 2usize] {
902 unsafe { std::mem::transmute(self) }
903 }
904 pub const fn len() -> usize {
905 const _: () = assert!(std::mem::size_of::<TcHfscQopt>() == 2usize);
906 2usize
907 }
908}
909#[derive(Debug)]
910#[repr(C, packed(4))]
911pub struct TcMqprioQopt {
912 pub num_tc: u8,
913 pub prio_tc_map: [u8; 16usize],
914 pub hw: u8,
915 pub count: [u8; 32usize],
916 pub offset: [u8; 32usize],
917}
918impl Clone for TcMqprioQopt {
919 fn clone(&self) -> Self {
920 Self::new_from_array(*self.as_array())
921 }
922}
923#[doc = "Create zero-initialized struct"]
924impl Default for TcMqprioQopt {
925 fn default() -> Self {
926 Self::new()
927 }
928}
929impl TcMqprioQopt {
930 #[doc = "Create zero-initialized struct"]
931 pub fn new() -> Self {
932 Self::new_from_array([0u8; Self::len()])
933 }
934 #[doc = "Copy from contents from slice"]
935 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
936 if other.len() != Self::len() {
937 return None;
938 }
939 let mut buf = [0u8; Self::len()];
940 buf.clone_from_slice(other);
941 Some(Self::new_from_array(buf))
942 }
943 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
944 pub fn new_from_zeroed(other: &[u8]) -> Self {
945 let mut buf = [0u8; Self::len()];
946 let len = buf.len().min(other.len());
947 buf[..len].clone_from_slice(&other[..len]);
948 Self::new_from_array(buf)
949 }
950 pub fn new_from_array(buf: [u8; 82usize]) -> Self {
951 unsafe { std::mem::transmute(buf) }
952 }
953 pub fn as_slice(&self) -> &[u8] {
954 unsafe {
955 let ptr: *const u8 = std::mem::transmute(self as *const Self);
956 std::slice::from_raw_parts(ptr, Self::len())
957 }
958 }
959 pub fn from_slice(buf: &[u8]) -> &Self {
960 assert!(buf.len() >= Self::len());
961 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
962 unsafe { std::mem::transmute(buf.as_ptr()) }
963 }
964 pub fn as_array(&self) -> &[u8; 82usize] {
965 unsafe { std::mem::transmute(self) }
966 }
967 pub fn from_array(buf: &[u8; 82usize]) -> &Self {
968 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
969 unsafe { std::mem::transmute(buf) }
970 }
971 pub fn into_array(self) -> [u8; 82usize] {
972 unsafe { std::mem::transmute(self) }
973 }
974 pub const fn len() -> usize {
975 const _: () = assert!(std::mem::size_of::<TcMqprioQopt>() == 82usize);
976 82usize
977 }
978}
979#[derive(Debug)]
980#[repr(C, packed(4))]
981pub struct TcMultiqQopt {
982 #[doc = "Number of bands\n"]
983 pub bands: u16,
984 #[doc = "Maximum number of queues\n"]
985 pub max_bands: u16,
986}
987impl Clone for TcMultiqQopt {
988 fn clone(&self) -> Self {
989 Self::new_from_array(*self.as_array())
990 }
991}
992#[doc = "Create zero-initialized struct"]
993impl Default for TcMultiqQopt {
994 fn default() -> Self {
995 Self::new()
996 }
997}
998impl TcMultiqQopt {
999 #[doc = "Create zero-initialized struct"]
1000 pub fn new() -> Self {
1001 Self::new_from_array([0u8; Self::len()])
1002 }
1003 #[doc = "Copy from contents from slice"]
1004 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1005 if other.len() != Self::len() {
1006 return None;
1007 }
1008 let mut buf = [0u8; Self::len()];
1009 buf.clone_from_slice(other);
1010 Some(Self::new_from_array(buf))
1011 }
1012 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1013 pub fn new_from_zeroed(other: &[u8]) -> Self {
1014 let mut buf = [0u8; Self::len()];
1015 let len = buf.len().min(other.len());
1016 buf[..len].clone_from_slice(&other[..len]);
1017 Self::new_from_array(buf)
1018 }
1019 pub fn new_from_array(buf: [u8; 4usize]) -> Self {
1020 unsafe { std::mem::transmute(buf) }
1021 }
1022 pub fn as_slice(&self) -> &[u8] {
1023 unsafe {
1024 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1025 std::slice::from_raw_parts(ptr, Self::len())
1026 }
1027 }
1028 pub fn from_slice(buf: &[u8]) -> &Self {
1029 assert!(buf.len() >= Self::len());
1030 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1031 unsafe { std::mem::transmute(buf.as_ptr()) }
1032 }
1033 pub fn as_array(&self) -> &[u8; 4usize] {
1034 unsafe { std::mem::transmute(self) }
1035 }
1036 pub fn from_array(buf: &[u8; 4usize]) -> &Self {
1037 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1038 unsafe { std::mem::transmute(buf) }
1039 }
1040 pub fn into_array(self) -> [u8; 4usize] {
1041 unsafe { std::mem::transmute(self) }
1042 }
1043 pub const fn len() -> usize {
1044 const _: () = assert!(std::mem::size_of::<TcMultiqQopt>() == 4usize);
1045 4usize
1046 }
1047}
1048#[derive(Debug)]
1049#[repr(C, packed(4))]
1050pub struct TcNetemQopt {
1051 #[doc = "Added delay in microseconds\n"]
1052 pub latency: u32,
1053 #[doc = "Fifo limit in packets\n"]
1054 pub limit: u32,
1055 #[doc = "Random packet loss (0=none, \\~0=100%)\n"]
1056 pub loss: u32,
1057 #[doc = "Re-ordering gap (0 for none)\n"]
1058 pub gap: u32,
1059 #[doc = "Random packet duplication (0=none, \\~0=100%)\n"]
1060 pub duplicate: u32,
1061 #[doc = "Random jitter latency in microseconds\n"]
1062 pub jitter: u32,
1063}
1064impl Clone for TcNetemQopt {
1065 fn clone(&self) -> Self {
1066 Self::new_from_array(*self.as_array())
1067 }
1068}
1069#[doc = "Create zero-initialized struct"]
1070impl Default for TcNetemQopt {
1071 fn default() -> Self {
1072 Self::new()
1073 }
1074}
1075impl TcNetemQopt {
1076 #[doc = "Create zero-initialized struct"]
1077 pub fn new() -> Self {
1078 Self::new_from_array([0u8; Self::len()])
1079 }
1080 #[doc = "Copy from contents from slice"]
1081 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1082 if other.len() != Self::len() {
1083 return None;
1084 }
1085 let mut buf = [0u8; Self::len()];
1086 buf.clone_from_slice(other);
1087 Some(Self::new_from_array(buf))
1088 }
1089 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1090 pub fn new_from_zeroed(other: &[u8]) -> Self {
1091 let mut buf = [0u8; Self::len()];
1092 let len = buf.len().min(other.len());
1093 buf[..len].clone_from_slice(&other[..len]);
1094 Self::new_from_array(buf)
1095 }
1096 pub fn new_from_array(buf: [u8; 24usize]) -> Self {
1097 unsafe { std::mem::transmute(buf) }
1098 }
1099 pub fn as_slice(&self) -> &[u8] {
1100 unsafe {
1101 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1102 std::slice::from_raw_parts(ptr, Self::len())
1103 }
1104 }
1105 pub fn from_slice(buf: &[u8]) -> &Self {
1106 assert!(buf.len() >= Self::len());
1107 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1108 unsafe { std::mem::transmute(buf.as_ptr()) }
1109 }
1110 pub fn as_array(&self) -> &[u8; 24usize] {
1111 unsafe { std::mem::transmute(self) }
1112 }
1113 pub fn from_array(buf: &[u8; 24usize]) -> &Self {
1114 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1115 unsafe { std::mem::transmute(buf) }
1116 }
1117 pub fn into_array(self) -> [u8; 24usize] {
1118 unsafe { std::mem::transmute(self) }
1119 }
1120 pub const fn len() -> usize {
1121 const _: () = assert!(std::mem::size_of::<TcNetemQopt>() == 24usize);
1122 24usize
1123 }
1124}
1125#[derive(Debug)]
1126#[doc = "State transition probabilities for 4 state model\n"]
1127#[repr(C, packed(4))]
1128pub struct TcNetemGimodel {
1129 pub p13: u32,
1130 pub p31: u32,
1131 pub p32: u32,
1132 pub p14: u32,
1133 pub p23: u32,
1134}
1135impl Clone for TcNetemGimodel {
1136 fn clone(&self) -> Self {
1137 Self::new_from_array(*self.as_array())
1138 }
1139}
1140#[doc = "Create zero-initialized struct"]
1141impl Default for TcNetemGimodel {
1142 fn default() -> Self {
1143 Self::new()
1144 }
1145}
1146impl TcNetemGimodel {
1147 #[doc = "Create zero-initialized struct"]
1148 pub fn new() -> Self {
1149 Self::new_from_array([0u8; Self::len()])
1150 }
1151 #[doc = "Copy from contents from slice"]
1152 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1153 if other.len() != Self::len() {
1154 return None;
1155 }
1156 let mut buf = [0u8; Self::len()];
1157 buf.clone_from_slice(other);
1158 Some(Self::new_from_array(buf))
1159 }
1160 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1161 pub fn new_from_zeroed(other: &[u8]) -> Self {
1162 let mut buf = [0u8; Self::len()];
1163 let len = buf.len().min(other.len());
1164 buf[..len].clone_from_slice(&other[..len]);
1165 Self::new_from_array(buf)
1166 }
1167 pub fn new_from_array(buf: [u8; 20usize]) -> Self {
1168 unsafe { std::mem::transmute(buf) }
1169 }
1170 pub fn as_slice(&self) -> &[u8] {
1171 unsafe {
1172 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1173 std::slice::from_raw_parts(ptr, Self::len())
1174 }
1175 }
1176 pub fn from_slice(buf: &[u8]) -> &Self {
1177 assert!(buf.len() >= Self::len());
1178 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1179 unsafe { std::mem::transmute(buf.as_ptr()) }
1180 }
1181 pub fn as_array(&self) -> &[u8; 20usize] {
1182 unsafe { std::mem::transmute(self) }
1183 }
1184 pub fn from_array(buf: &[u8; 20usize]) -> &Self {
1185 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1186 unsafe { std::mem::transmute(buf) }
1187 }
1188 pub fn into_array(self) -> [u8; 20usize] {
1189 unsafe { std::mem::transmute(self) }
1190 }
1191 pub const fn len() -> usize {
1192 const _: () = assert!(std::mem::size_of::<TcNetemGimodel>() == 20usize);
1193 20usize
1194 }
1195}
1196#[derive(Debug)]
1197#[doc = "Gilbert-Elliot models\n"]
1198#[repr(C, packed(4))]
1199pub struct TcNetemGemodel {
1200 pub p: u32,
1201 pub r: u32,
1202 pub h: u32,
1203 pub k1: u32,
1204}
1205impl Clone for TcNetemGemodel {
1206 fn clone(&self) -> Self {
1207 Self::new_from_array(*self.as_array())
1208 }
1209}
1210#[doc = "Create zero-initialized struct"]
1211impl Default for TcNetemGemodel {
1212 fn default() -> Self {
1213 Self::new()
1214 }
1215}
1216impl TcNetemGemodel {
1217 #[doc = "Create zero-initialized struct"]
1218 pub fn new() -> Self {
1219 Self::new_from_array([0u8; Self::len()])
1220 }
1221 #[doc = "Copy from contents from slice"]
1222 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1223 if other.len() != Self::len() {
1224 return None;
1225 }
1226 let mut buf = [0u8; Self::len()];
1227 buf.clone_from_slice(other);
1228 Some(Self::new_from_array(buf))
1229 }
1230 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1231 pub fn new_from_zeroed(other: &[u8]) -> Self {
1232 let mut buf = [0u8; Self::len()];
1233 let len = buf.len().min(other.len());
1234 buf[..len].clone_from_slice(&other[..len]);
1235 Self::new_from_array(buf)
1236 }
1237 pub fn new_from_array(buf: [u8; 16usize]) -> Self {
1238 unsafe { std::mem::transmute(buf) }
1239 }
1240 pub fn as_slice(&self) -> &[u8] {
1241 unsafe {
1242 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1243 std::slice::from_raw_parts(ptr, Self::len())
1244 }
1245 }
1246 pub fn from_slice(buf: &[u8]) -> &Self {
1247 assert!(buf.len() >= Self::len());
1248 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1249 unsafe { std::mem::transmute(buf.as_ptr()) }
1250 }
1251 pub fn as_array(&self) -> &[u8; 16usize] {
1252 unsafe { std::mem::transmute(self) }
1253 }
1254 pub fn from_array(buf: &[u8; 16usize]) -> &Self {
1255 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1256 unsafe { std::mem::transmute(buf) }
1257 }
1258 pub fn into_array(self) -> [u8; 16usize] {
1259 unsafe { std::mem::transmute(self) }
1260 }
1261 pub const fn len() -> usize {
1262 const _: () = assert!(std::mem::size_of::<TcNetemGemodel>() == 16usize);
1263 16usize
1264 }
1265}
1266#[derive(Debug)]
1267#[repr(C, packed(4))]
1268pub struct TcNetemCorr {
1269 #[doc = "Delay correlation\n"]
1270 pub delay_corr: u32,
1271 #[doc = "Packet loss correlation\n"]
1272 pub loss_corr: u32,
1273 #[doc = "Duplicate correlation\n"]
1274 pub dup_corr: u32,
1275}
1276impl Clone for TcNetemCorr {
1277 fn clone(&self) -> Self {
1278 Self::new_from_array(*self.as_array())
1279 }
1280}
1281#[doc = "Create zero-initialized struct"]
1282impl Default for TcNetemCorr {
1283 fn default() -> Self {
1284 Self::new()
1285 }
1286}
1287impl TcNetemCorr {
1288 #[doc = "Create zero-initialized struct"]
1289 pub fn new() -> Self {
1290 Self::new_from_array([0u8; Self::len()])
1291 }
1292 #[doc = "Copy from contents from slice"]
1293 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1294 if other.len() != Self::len() {
1295 return None;
1296 }
1297 let mut buf = [0u8; Self::len()];
1298 buf.clone_from_slice(other);
1299 Some(Self::new_from_array(buf))
1300 }
1301 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1302 pub fn new_from_zeroed(other: &[u8]) -> Self {
1303 let mut buf = [0u8; Self::len()];
1304 let len = buf.len().min(other.len());
1305 buf[..len].clone_from_slice(&other[..len]);
1306 Self::new_from_array(buf)
1307 }
1308 pub fn new_from_array(buf: [u8; 12usize]) -> Self {
1309 unsafe { std::mem::transmute(buf) }
1310 }
1311 pub fn as_slice(&self) -> &[u8] {
1312 unsafe {
1313 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1314 std::slice::from_raw_parts(ptr, Self::len())
1315 }
1316 }
1317 pub fn from_slice(buf: &[u8]) -> &Self {
1318 assert!(buf.len() >= Self::len());
1319 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1320 unsafe { std::mem::transmute(buf.as_ptr()) }
1321 }
1322 pub fn as_array(&self) -> &[u8; 12usize] {
1323 unsafe { std::mem::transmute(self) }
1324 }
1325 pub fn from_array(buf: &[u8; 12usize]) -> &Self {
1326 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1327 unsafe { std::mem::transmute(buf) }
1328 }
1329 pub fn into_array(self) -> [u8; 12usize] {
1330 unsafe { std::mem::transmute(self) }
1331 }
1332 pub const fn len() -> usize {
1333 const _: () = assert!(std::mem::size_of::<TcNetemCorr>() == 12usize);
1334 12usize
1335 }
1336}
1337#[derive(Debug)]
1338#[repr(C, packed(4))]
1339pub struct TcNetemReorder {
1340 pub probability: u32,
1341 pub correlation: u32,
1342}
1343impl Clone for TcNetemReorder {
1344 fn clone(&self) -> Self {
1345 Self::new_from_array(*self.as_array())
1346 }
1347}
1348#[doc = "Create zero-initialized struct"]
1349impl Default for TcNetemReorder {
1350 fn default() -> Self {
1351 Self::new()
1352 }
1353}
1354impl TcNetemReorder {
1355 #[doc = "Create zero-initialized struct"]
1356 pub fn new() -> Self {
1357 Self::new_from_array([0u8; Self::len()])
1358 }
1359 #[doc = "Copy from contents from slice"]
1360 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1361 if other.len() != Self::len() {
1362 return None;
1363 }
1364 let mut buf = [0u8; Self::len()];
1365 buf.clone_from_slice(other);
1366 Some(Self::new_from_array(buf))
1367 }
1368 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1369 pub fn new_from_zeroed(other: &[u8]) -> Self {
1370 let mut buf = [0u8; Self::len()];
1371 let len = buf.len().min(other.len());
1372 buf[..len].clone_from_slice(&other[..len]);
1373 Self::new_from_array(buf)
1374 }
1375 pub fn new_from_array(buf: [u8; 8usize]) -> Self {
1376 unsafe { std::mem::transmute(buf) }
1377 }
1378 pub fn as_slice(&self) -> &[u8] {
1379 unsafe {
1380 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1381 std::slice::from_raw_parts(ptr, Self::len())
1382 }
1383 }
1384 pub fn from_slice(buf: &[u8]) -> &Self {
1385 assert!(buf.len() >= Self::len());
1386 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1387 unsafe { std::mem::transmute(buf.as_ptr()) }
1388 }
1389 pub fn as_array(&self) -> &[u8; 8usize] {
1390 unsafe { std::mem::transmute(self) }
1391 }
1392 pub fn from_array(buf: &[u8; 8usize]) -> &Self {
1393 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1394 unsafe { std::mem::transmute(buf) }
1395 }
1396 pub fn into_array(self) -> [u8; 8usize] {
1397 unsafe { std::mem::transmute(self) }
1398 }
1399 pub const fn len() -> usize {
1400 const _: () = assert!(std::mem::size_of::<TcNetemReorder>() == 8usize);
1401 8usize
1402 }
1403}
1404#[derive(Debug)]
1405#[repr(C, packed(4))]
1406pub struct TcNetemCorrupt {
1407 pub probability: u32,
1408 pub correlation: u32,
1409}
1410impl Clone for TcNetemCorrupt {
1411 fn clone(&self) -> Self {
1412 Self::new_from_array(*self.as_array())
1413 }
1414}
1415#[doc = "Create zero-initialized struct"]
1416impl Default for TcNetemCorrupt {
1417 fn default() -> Self {
1418 Self::new()
1419 }
1420}
1421impl TcNetemCorrupt {
1422 #[doc = "Create zero-initialized struct"]
1423 pub fn new() -> Self {
1424 Self::new_from_array([0u8; Self::len()])
1425 }
1426 #[doc = "Copy from contents from slice"]
1427 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1428 if other.len() != Self::len() {
1429 return None;
1430 }
1431 let mut buf = [0u8; Self::len()];
1432 buf.clone_from_slice(other);
1433 Some(Self::new_from_array(buf))
1434 }
1435 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1436 pub fn new_from_zeroed(other: &[u8]) -> Self {
1437 let mut buf = [0u8; Self::len()];
1438 let len = buf.len().min(other.len());
1439 buf[..len].clone_from_slice(&other[..len]);
1440 Self::new_from_array(buf)
1441 }
1442 pub fn new_from_array(buf: [u8; 8usize]) -> Self {
1443 unsafe { std::mem::transmute(buf) }
1444 }
1445 pub fn as_slice(&self) -> &[u8] {
1446 unsafe {
1447 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1448 std::slice::from_raw_parts(ptr, Self::len())
1449 }
1450 }
1451 pub fn from_slice(buf: &[u8]) -> &Self {
1452 assert!(buf.len() >= Self::len());
1453 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1454 unsafe { std::mem::transmute(buf.as_ptr()) }
1455 }
1456 pub fn as_array(&self) -> &[u8; 8usize] {
1457 unsafe { std::mem::transmute(self) }
1458 }
1459 pub fn from_array(buf: &[u8; 8usize]) -> &Self {
1460 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1461 unsafe { std::mem::transmute(buf) }
1462 }
1463 pub fn into_array(self) -> [u8; 8usize] {
1464 unsafe { std::mem::transmute(self) }
1465 }
1466 pub const fn len() -> usize {
1467 const _: () = assert!(std::mem::size_of::<TcNetemCorrupt>() == 8usize);
1468 8usize
1469 }
1470}
1471#[derive(Debug)]
1472#[repr(C, packed(4))]
1473pub struct TcNetemRate {
1474 pub rate: u32,
1475 pub packet_overhead: i32,
1476 pub cell_size: u32,
1477 pub cell_overhead: i32,
1478}
1479impl Clone for TcNetemRate {
1480 fn clone(&self) -> Self {
1481 Self::new_from_array(*self.as_array())
1482 }
1483}
1484#[doc = "Create zero-initialized struct"]
1485impl Default for TcNetemRate {
1486 fn default() -> Self {
1487 Self::new()
1488 }
1489}
1490impl TcNetemRate {
1491 #[doc = "Create zero-initialized struct"]
1492 pub fn new() -> Self {
1493 Self::new_from_array([0u8; Self::len()])
1494 }
1495 #[doc = "Copy from contents from slice"]
1496 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1497 if other.len() != Self::len() {
1498 return None;
1499 }
1500 let mut buf = [0u8; Self::len()];
1501 buf.clone_from_slice(other);
1502 Some(Self::new_from_array(buf))
1503 }
1504 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1505 pub fn new_from_zeroed(other: &[u8]) -> Self {
1506 let mut buf = [0u8; Self::len()];
1507 let len = buf.len().min(other.len());
1508 buf[..len].clone_from_slice(&other[..len]);
1509 Self::new_from_array(buf)
1510 }
1511 pub fn new_from_array(buf: [u8; 16usize]) -> Self {
1512 unsafe { std::mem::transmute(buf) }
1513 }
1514 pub fn as_slice(&self) -> &[u8] {
1515 unsafe {
1516 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1517 std::slice::from_raw_parts(ptr, Self::len())
1518 }
1519 }
1520 pub fn from_slice(buf: &[u8]) -> &Self {
1521 assert!(buf.len() >= Self::len());
1522 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1523 unsafe { std::mem::transmute(buf.as_ptr()) }
1524 }
1525 pub fn as_array(&self) -> &[u8; 16usize] {
1526 unsafe { std::mem::transmute(self) }
1527 }
1528 pub fn from_array(buf: &[u8; 16usize]) -> &Self {
1529 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1530 unsafe { std::mem::transmute(buf) }
1531 }
1532 pub fn into_array(self) -> [u8; 16usize] {
1533 unsafe { std::mem::transmute(self) }
1534 }
1535 pub const fn len() -> usize {
1536 const _: () = assert!(std::mem::size_of::<TcNetemRate>() == 16usize);
1537 16usize
1538 }
1539}
1540#[repr(C, packed(4))]
1541pub struct TcNetemSlot {
1542 pub min_delay: i64,
1543 pub max_delay: i64,
1544 pub max_packets: i32,
1545 pub max_bytes: i32,
1546 pub dist_delay: i64,
1547 pub dist_jitter: i64,
1548}
1549impl Clone for TcNetemSlot {
1550 fn clone(&self) -> Self {
1551 Self::new_from_array(*self.as_array())
1552 }
1553}
1554#[doc = "Create zero-initialized struct"]
1555impl Default for TcNetemSlot {
1556 fn default() -> Self {
1557 Self::new()
1558 }
1559}
1560impl TcNetemSlot {
1561 #[doc = "Create zero-initialized struct"]
1562 pub fn new() -> Self {
1563 Self::new_from_array([0u8; Self::len()])
1564 }
1565 #[doc = "Copy from contents from slice"]
1566 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1567 if other.len() != Self::len() {
1568 return None;
1569 }
1570 let mut buf = [0u8; Self::len()];
1571 buf.clone_from_slice(other);
1572 Some(Self::new_from_array(buf))
1573 }
1574 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1575 pub fn new_from_zeroed(other: &[u8]) -> Self {
1576 let mut buf = [0u8; Self::len()];
1577 let len = buf.len().min(other.len());
1578 buf[..len].clone_from_slice(&other[..len]);
1579 Self::new_from_array(buf)
1580 }
1581 pub fn new_from_array(buf: [u8; 40usize]) -> Self {
1582 unsafe { std::mem::transmute(buf) }
1583 }
1584 pub fn as_slice(&self) -> &[u8] {
1585 unsafe {
1586 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1587 std::slice::from_raw_parts(ptr, Self::len())
1588 }
1589 }
1590 pub fn from_slice(buf: &[u8]) -> &Self {
1591 assert!(buf.len() >= Self::len());
1592 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1593 unsafe { std::mem::transmute(buf.as_ptr()) }
1594 }
1595 pub fn as_array(&self) -> &[u8; 40usize] {
1596 unsafe { std::mem::transmute(self) }
1597 }
1598 pub fn from_array(buf: &[u8; 40usize]) -> &Self {
1599 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1600 unsafe { std::mem::transmute(buf) }
1601 }
1602 pub fn into_array(self) -> [u8; 40usize] {
1603 unsafe { std::mem::transmute(self) }
1604 }
1605 pub const fn len() -> usize {
1606 const _: () = assert!(std::mem::size_of::<TcNetemSlot>() == 40usize);
1607 40usize
1608 }
1609}
1610impl std::fmt::Debug for TcNetemSlot {
1611 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1612 fmt.debug_struct("TcNetemSlot")
1613 .field("min_delay", &{ self.min_delay })
1614 .field("max_delay", &{ self.max_delay })
1615 .field("max_packets", &self.max_packets)
1616 .field("max_bytes", &self.max_bytes)
1617 .field("dist_delay", &{ self.dist_delay })
1618 .field("dist_jitter", &{ self.dist_jitter })
1619 .finish()
1620 }
1621}
1622#[derive(Debug)]
1623#[repr(C, packed(4))]
1624pub struct TcPlugQopt {
1625 pub action: i32,
1626 pub limit: u32,
1627}
1628impl Clone for TcPlugQopt {
1629 fn clone(&self) -> Self {
1630 Self::new_from_array(*self.as_array())
1631 }
1632}
1633#[doc = "Create zero-initialized struct"]
1634impl Default for TcPlugQopt {
1635 fn default() -> Self {
1636 Self::new()
1637 }
1638}
1639impl TcPlugQopt {
1640 #[doc = "Create zero-initialized struct"]
1641 pub fn new() -> Self {
1642 Self::new_from_array([0u8; Self::len()])
1643 }
1644 #[doc = "Copy from contents from slice"]
1645 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1646 if other.len() != Self::len() {
1647 return None;
1648 }
1649 let mut buf = [0u8; Self::len()];
1650 buf.clone_from_slice(other);
1651 Some(Self::new_from_array(buf))
1652 }
1653 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1654 pub fn new_from_zeroed(other: &[u8]) -> Self {
1655 let mut buf = [0u8; Self::len()];
1656 let len = buf.len().min(other.len());
1657 buf[..len].clone_from_slice(&other[..len]);
1658 Self::new_from_array(buf)
1659 }
1660 pub fn new_from_array(buf: [u8; 8usize]) -> Self {
1661 unsafe { std::mem::transmute(buf) }
1662 }
1663 pub fn as_slice(&self) -> &[u8] {
1664 unsafe {
1665 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1666 std::slice::from_raw_parts(ptr, Self::len())
1667 }
1668 }
1669 pub fn from_slice(buf: &[u8]) -> &Self {
1670 assert!(buf.len() >= Self::len());
1671 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1672 unsafe { std::mem::transmute(buf.as_ptr()) }
1673 }
1674 pub fn as_array(&self) -> &[u8; 8usize] {
1675 unsafe { std::mem::transmute(self) }
1676 }
1677 pub fn from_array(buf: &[u8; 8usize]) -> &Self {
1678 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1679 unsafe { std::mem::transmute(buf) }
1680 }
1681 pub fn into_array(self) -> [u8; 8usize] {
1682 unsafe { std::mem::transmute(self) }
1683 }
1684 pub const fn len() -> usize {
1685 const _: () = assert!(std::mem::size_of::<TcPlugQopt>() == 8usize);
1686 8usize
1687 }
1688}
1689#[derive(Debug)]
1690#[repr(C, packed(4))]
1691pub struct TcPrioQopt {
1692 #[doc = "Number of bands\n"]
1693 pub bands: u32,
1694 #[doc = "Map of logical priority -\\> PRIO band\n"]
1695 pub priomap: [u8; 16usize],
1696}
1697impl Clone for TcPrioQopt {
1698 fn clone(&self) -> Self {
1699 Self::new_from_array(*self.as_array())
1700 }
1701}
1702#[doc = "Create zero-initialized struct"]
1703impl Default for TcPrioQopt {
1704 fn default() -> Self {
1705 Self::new()
1706 }
1707}
1708impl TcPrioQopt {
1709 #[doc = "Create zero-initialized struct"]
1710 pub fn new() -> Self {
1711 Self::new_from_array([0u8; Self::len()])
1712 }
1713 #[doc = "Copy from contents from slice"]
1714 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1715 if other.len() != Self::len() {
1716 return None;
1717 }
1718 let mut buf = [0u8; Self::len()];
1719 buf.clone_from_slice(other);
1720 Some(Self::new_from_array(buf))
1721 }
1722 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1723 pub fn new_from_zeroed(other: &[u8]) -> Self {
1724 let mut buf = [0u8; Self::len()];
1725 let len = buf.len().min(other.len());
1726 buf[..len].clone_from_slice(&other[..len]);
1727 Self::new_from_array(buf)
1728 }
1729 pub fn new_from_array(buf: [u8; 20usize]) -> Self {
1730 unsafe { std::mem::transmute(buf) }
1731 }
1732 pub fn as_slice(&self) -> &[u8] {
1733 unsafe {
1734 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1735 std::slice::from_raw_parts(ptr, Self::len())
1736 }
1737 }
1738 pub fn from_slice(buf: &[u8]) -> &Self {
1739 assert!(buf.len() >= Self::len());
1740 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1741 unsafe { std::mem::transmute(buf.as_ptr()) }
1742 }
1743 pub fn as_array(&self) -> &[u8; 20usize] {
1744 unsafe { std::mem::transmute(self) }
1745 }
1746 pub fn from_array(buf: &[u8; 20usize]) -> &Self {
1747 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1748 unsafe { std::mem::transmute(buf) }
1749 }
1750 pub fn into_array(self) -> [u8; 20usize] {
1751 unsafe { std::mem::transmute(self) }
1752 }
1753 pub const fn len() -> usize {
1754 const _: () = assert!(std::mem::size_of::<TcPrioQopt>() == 20usize);
1755 20usize
1756 }
1757}
1758#[derive(Debug)]
1759#[repr(C, packed(4))]
1760pub struct TcRedQopt {
1761 #[doc = "Hard queue length in packets\n"]
1762 pub limit: u32,
1763 #[doc = "Min average threshold in packets\n"]
1764 pub qth_min: u32,
1765 #[doc = "Max average threshold in packets\n"]
1766 pub qth_max: u32,
1767 #[doc = "log(W)\n"]
1768 pub Wlog: u8,
1769 #[doc = "log(P_max / (qth-max - qth-min))\n"]
1770 pub Plog: u8,
1771 #[doc = "Cell size for idle damping\n"]
1772 pub Scell_log: u8,
1773 pub flags: u8,
1774}
1775impl Clone for TcRedQopt {
1776 fn clone(&self) -> Self {
1777 Self::new_from_array(*self.as_array())
1778 }
1779}
1780#[doc = "Create zero-initialized struct"]
1781impl Default for TcRedQopt {
1782 fn default() -> Self {
1783 Self::new()
1784 }
1785}
1786impl TcRedQopt {
1787 #[doc = "Create zero-initialized struct"]
1788 pub fn new() -> Self {
1789 Self::new_from_array([0u8; Self::len()])
1790 }
1791 #[doc = "Copy from contents from slice"]
1792 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1793 if other.len() != Self::len() {
1794 return None;
1795 }
1796 let mut buf = [0u8; Self::len()];
1797 buf.clone_from_slice(other);
1798 Some(Self::new_from_array(buf))
1799 }
1800 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1801 pub fn new_from_zeroed(other: &[u8]) -> Self {
1802 let mut buf = [0u8; Self::len()];
1803 let len = buf.len().min(other.len());
1804 buf[..len].clone_from_slice(&other[..len]);
1805 Self::new_from_array(buf)
1806 }
1807 pub fn new_from_array(buf: [u8; 16usize]) -> Self {
1808 unsafe { std::mem::transmute(buf) }
1809 }
1810 pub fn as_slice(&self) -> &[u8] {
1811 unsafe {
1812 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1813 std::slice::from_raw_parts(ptr, Self::len())
1814 }
1815 }
1816 pub fn from_slice(buf: &[u8]) -> &Self {
1817 assert!(buf.len() >= Self::len());
1818 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1819 unsafe { std::mem::transmute(buf.as_ptr()) }
1820 }
1821 pub fn as_array(&self) -> &[u8; 16usize] {
1822 unsafe { std::mem::transmute(self) }
1823 }
1824 pub fn from_array(buf: &[u8; 16usize]) -> &Self {
1825 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1826 unsafe { std::mem::transmute(buf) }
1827 }
1828 pub fn into_array(self) -> [u8; 16usize] {
1829 unsafe { std::mem::transmute(self) }
1830 }
1831 pub const fn len() -> usize {
1832 const _: () = assert!(std::mem::size_of::<TcRedQopt>() == 16usize);
1833 16usize
1834 }
1835}
1836#[derive(Debug)]
1837#[repr(C, packed(4))]
1838pub struct TcSfbQopt {
1839 pub rehash_interval: u32,
1840 pub warmup_time: u32,
1841 pub max: u32,
1842 pub bin_size: u32,
1843 pub increment: u32,
1844 pub decrement: u32,
1845 pub limit: u32,
1846 pub penalty_rate: u32,
1847 pub penalty_burst: u32,
1848}
1849impl Clone for TcSfbQopt {
1850 fn clone(&self) -> Self {
1851 Self::new_from_array(*self.as_array())
1852 }
1853}
1854#[doc = "Create zero-initialized struct"]
1855impl Default for TcSfbQopt {
1856 fn default() -> Self {
1857 Self::new()
1858 }
1859}
1860impl TcSfbQopt {
1861 #[doc = "Create zero-initialized struct"]
1862 pub fn new() -> Self {
1863 Self::new_from_array([0u8; Self::len()])
1864 }
1865 #[doc = "Copy from contents from slice"]
1866 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1867 if other.len() != Self::len() {
1868 return None;
1869 }
1870 let mut buf = [0u8; Self::len()];
1871 buf.clone_from_slice(other);
1872 Some(Self::new_from_array(buf))
1873 }
1874 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1875 pub fn new_from_zeroed(other: &[u8]) -> Self {
1876 let mut buf = [0u8; Self::len()];
1877 let len = buf.len().min(other.len());
1878 buf[..len].clone_from_slice(&other[..len]);
1879 Self::new_from_array(buf)
1880 }
1881 pub fn new_from_array(buf: [u8; 36usize]) -> Self {
1882 unsafe { std::mem::transmute(buf) }
1883 }
1884 pub fn as_slice(&self) -> &[u8] {
1885 unsafe {
1886 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1887 std::slice::from_raw_parts(ptr, Self::len())
1888 }
1889 }
1890 pub fn from_slice(buf: &[u8]) -> &Self {
1891 assert!(buf.len() >= Self::len());
1892 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1893 unsafe { std::mem::transmute(buf.as_ptr()) }
1894 }
1895 pub fn as_array(&self) -> &[u8; 36usize] {
1896 unsafe { std::mem::transmute(self) }
1897 }
1898 pub fn from_array(buf: &[u8; 36usize]) -> &Self {
1899 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1900 unsafe { std::mem::transmute(buf) }
1901 }
1902 pub fn into_array(self) -> [u8; 36usize] {
1903 unsafe { std::mem::transmute(self) }
1904 }
1905 pub const fn len() -> usize {
1906 const _: () = assert!(std::mem::size_of::<TcSfbQopt>() == 36usize);
1907 36usize
1908 }
1909}
1910#[derive(Debug)]
1911#[repr(C, packed(4))]
1912pub struct TcSfqQopt {
1913 #[doc = "Bytes per round allocated to flow\n"]
1914 pub quantum: u32,
1915 #[doc = "Period of hash perturbation\n"]
1916 pub perturb_period: i32,
1917 #[doc = "Maximal packets in queue\n"]
1918 pub limit: u32,
1919 #[doc = "Hash divisor\n"]
1920 pub divisor: u32,
1921 #[doc = "Maximal number of flows\n"]
1922 pub flows: u32,
1923}
1924impl Clone for TcSfqQopt {
1925 fn clone(&self) -> Self {
1926 Self::new_from_array(*self.as_array())
1927 }
1928}
1929#[doc = "Create zero-initialized struct"]
1930impl Default for TcSfqQopt {
1931 fn default() -> Self {
1932 Self::new()
1933 }
1934}
1935impl TcSfqQopt {
1936 #[doc = "Create zero-initialized struct"]
1937 pub fn new() -> Self {
1938 Self::new_from_array([0u8; Self::len()])
1939 }
1940 #[doc = "Copy from contents from slice"]
1941 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
1942 if other.len() != Self::len() {
1943 return None;
1944 }
1945 let mut buf = [0u8; Self::len()];
1946 buf.clone_from_slice(other);
1947 Some(Self::new_from_array(buf))
1948 }
1949 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
1950 pub fn new_from_zeroed(other: &[u8]) -> Self {
1951 let mut buf = [0u8; Self::len()];
1952 let len = buf.len().min(other.len());
1953 buf[..len].clone_from_slice(&other[..len]);
1954 Self::new_from_array(buf)
1955 }
1956 pub fn new_from_array(buf: [u8; 20usize]) -> Self {
1957 unsafe { std::mem::transmute(buf) }
1958 }
1959 pub fn as_slice(&self) -> &[u8] {
1960 unsafe {
1961 let ptr: *const u8 = std::mem::transmute(self as *const Self);
1962 std::slice::from_raw_parts(ptr, Self::len())
1963 }
1964 }
1965 pub fn from_slice(buf: &[u8]) -> &Self {
1966 assert!(buf.len() >= Self::len());
1967 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1968 unsafe { std::mem::transmute(buf.as_ptr()) }
1969 }
1970 pub fn as_array(&self) -> &[u8; 20usize] {
1971 unsafe { std::mem::transmute(self) }
1972 }
1973 pub fn from_array(buf: &[u8; 20usize]) -> &Self {
1974 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
1975 unsafe { std::mem::transmute(buf) }
1976 }
1977 pub fn into_array(self) -> [u8; 20usize] {
1978 unsafe { std::mem::transmute(self) }
1979 }
1980 pub const fn len() -> usize {
1981 const _: () = assert!(std::mem::size_of::<TcSfqQopt>() == 20usize);
1982 20usize
1983 }
1984}
1985#[derive(Debug)]
1986#[repr(C, packed(4))]
1987pub struct TcSfqredStats {
1988 #[doc = "Early drops, below max threshold\n"]
1989 pub prob_drop: u32,
1990 #[doc = "Early drops, after max threshold\n"]
1991 pub forced_drop: u32,
1992 #[doc = "Marked packets, below max threshold\n"]
1993 pub prob_mark: u32,
1994 #[doc = "Marked packets, after max threshold\n"]
1995 pub forced_mark: u32,
1996 #[doc = "Marked packets, below max threshold\n"]
1997 pub prob_mark_head: u32,
1998 #[doc = "Marked packets, after max threshold\n"]
1999 pub forced_mark_head: u32,
2000}
2001impl Clone for TcSfqredStats {
2002 fn clone(&self) -> Self {
2003 Self::new_from_array(*self.as_array())
2004 }
2005}
2006#[doc = "Create zero-initialized struct"]
2007impl Default for TcSfqredStats {
2008 fn default() -> Self {
2009 Self::new()
2010 }
2011}
2012impl TcSfqredStats {
2013 #[doc = "Create zero-initialized struct"]
2014 pub fn new() -> Self {
2015 Self::new_from_array([0u8; Self::len()])
2016 }
2017 #[doc = "Copy from contents from slice"]
2018 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2019 if other.len() != Self::len() {
2020 return None;
2021 }
2022 let mut buf = [0u8; Self::len()];
2023 buf.clone_from_slice(other);
2024 Some(Self::new_from_array(buf))
2025 }
2026 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2027 pub fn new_from_zeroed(other: &[u8]) -> Self {
2028 let mut buf = [0u8; Self::len()];
2029 let len = buf.len().min(other.len());
2030 buf[..len].clone_from_slice(&other[..len]);
2031 Self::new_from_array(buf)
2032 }
2033 pub fn new_from_array(buf: [u8; 24usize]) -> Self {
2034 unsafe { std::mem::transmute(buf) }
2035 }
2036 pub fn as_slice(&self) -> &[u8] {
2037 unsafe {
2038 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2039 std::slice::from_raw_parts(ptr, Self::len())
2040 }
2041 }
2042 pub fn from_slice(buf: &[u8]) -> &Self {
2043 assert!(buf.len() >= Self::len());
2044 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2045 unsafe { std::mem::transmute(buf.as_ptr()) }
2046 }
2047 pub fn as_array(&self) -> &[u8; 24usize] {
2048 unsafe { std::mem::transmute(self) }
2049 }
2050 pub fn from_array(buf: &[u8; 24usize]) -> &Self {
2051 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2052 unsafe { std::mem::transmute(buf) }
2053 }
2054 pub fn into_array(self) -> [u8; 24usize] {
2055 unsafe { std::mem::transmute(self) }
2056 }
2057 pub const fn len() -> usize {
2058 const _: () = assert!(std::mem::size_of::<TcSfqredStats>() == 24usize);
2059 24usize
2060 }
2061}
2062#[repr(C, packed(4))]
2063pub struct TcSfqQoptV1 {
2064 pub v0: TcSfqQopt,
2065 #[doc = "Maximum number of packets per flow\n"]
2066 pub depth: u32,
2067 pub headdrop: u32,
2068 #[doc = "HARD maximal flow queue length in bytes\n"]
2069 pub limit: u32,
2070 #[doc = "Min average length threshold in bytes\n"]
2071 pub qth_min: u32,
2072 #[doc = "Max average length threshold in bytes\n"]
2073 pub qth_max: u32,
2074 #[doc = "log(W)\n"]
2075 pub Wlog: u8,
2076 #[doc = "log(P_max / (qth-max - qth-min))\n"]
2077 pub Plog: u8,
2078 #[doc = "Cell size for idle damping\n"]
2079 pub Scell_log: u8,
2080 pub flags: u8,
2081 #[doc = "probability, high resolution\n"]
2082 pub max_P: u32,
2083 pub stats: TcSfqredStats,
2084}
2085impl Clone for TcSfqQoptV1 {
2086 fn clone(&self) -> Self {
2087 Self::new_from_array(*self.as_array())
2088 }
2089}
2090#[doc = "Create zero-initialized struct"]
2091impl Default for TcSfqQoptV1 {
2092 fn default() -> Self {
2093 Self::new()
2094 }
2095}
2096impl TcSfqQoptV1 {
2097 #[doc = "Create zero-initialized struct"]
2098 pub fn new() -> Self {
2099 Self::new_from_array([0u8; Self::len()])
2100 }
2101 #[doc = "Copy from contents from slice"]
2102 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2103 if other.len() != Self::len() {
2104 return None;
2105 }
2106 let mut buf = [0u8; Self::len()];
2107 buf.clone_from_slice(other);
2108 Some(Self::new_from_array(buf))
2109 }
2110 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2111 pub fn new_from_zeroed(other: &[u8]) -> Self {
2112 let mut buf = [0u8; Self::len()];
2113 let len = buf.len().min(other.len());
2114 buf[..len].clone_from_slice(&other[..len]);
2115 Self::new_from_array(buf)
2116 }
2117 pub fn new_from_array(buf: [u8; 72usize]) -> Self {
2118 unsafe { std::mem::transmute(buf) }
2119 }
2120 pub fn as_slice(&self) -> &[u8] {
2121 unsafe {
2122 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2123 std::slice::from_raw_parts(ptr, Self::len())
2124 }
2125 }
2126 pub fn from_slice(buf: &[u8]) -> &Self {
2127 assert!(buf.len() >= Self::len());
2128 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2129 unsafe { std::mem::transmute(buf.as_ptr()) }
2130 }
2131 pub fn as_array(&self) -> &[u8; 72usize] {
2132 unsafe { std::mem::transmute(self) }
2133 }
2134 pub fn from_array(buf: &[u8; 72usize]) -> &Self {
2135 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2136 unsafe { std::mem::transmute(buf) }
2137 }
2138 pub fn into_array(self) -> [u8; 72usize] {
2139 unsafe { std::mem::transmute(self) }
2140 }
2141 pub const fn len() -> usize {
2142 const _: () = assert!(std::mem::size_of::<TcSfqQoptV1>() == 72usize);
2143 72usize
2144 }
2145}
2146impl std::fmt::Debug for TcSfqQoptV1 {
2147 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2148 fmt.debug_struct("TcSfqQoptV1")
2149 .field("v0", &self.v0)
2150 .field("depth", &self.depth)
2151 .field("headdrop", &self.headdrop)
2152 .field("limit", &self.limit)
2153 .field("qth_min", &self.qth_min)
2154 .field("qth_max", &self.qth_max)
2155 .field("Wlog", &self.Wlog)
2156 .field("Plog", &self.Plog)
2157 .field("Scell_log", &self.Scell_log)
2158 .field("flags", &self.flags)
2159 .field("max_P", &self.max_P)
2160 .field("stats", &self.stats)
2161 .finish()
2162 }
2163}
2164#[repr(C, packed(4))]
2165pub struct TcRatespec {
2166 pub cell_log: u8,
2167 pub linklayer: u8,
2168 pub overhead: u8,
2169 pub cell_align: u8,
2170 pub mpu: u8,
2171 pub _pad_5: [u8; 3usize],
2172 pub rate: u32,
2173}
2174impl Clone for TcRatespec {
2175 fn clone(&self) -> Self {
2176 Self::new_from_array(*self.as_array())
2177 }
2178}
2179#[doc = "Create zero-initialized struct"]
2180impl Default for TcRatespec {
2181 fn default() -> Self {
2182 Self::new()
2183 }
2184}
2185impl TcRatespec {
2186 #[doc = "Create zero-initialized struct"]
2187 pub fn new() -> Self {
2188 Self::new_from_array([0u8; Self::len()])
2189 }
2190 #[doc = "Copy from contents from slice"]
2191 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2192 if other.len() != Self::len() {
2193 return None;
2194 }
2195 let mut buf = [0u8; Self::len()];
2196 buf.clone_from_slice(other);
2197 Some(Self::new_from_array(buf))
2198 }
2199 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2200 pub fn new_from_zeroed(other: &[u8]) -> Self {
2201 let mut buf = [0u8; Self::len()];
2202 let len = buf.len().min(other.len());
2203 buf[..len].clone_from_slice(&other[..len]);
2204 Self::new_from_array(buf)
2205 }
2206 pub fn new_from_array(buf: [u8; 12usize]) -> Self {
2207 unsafe { std::mem::transmute(buf) }
2208 }
2209 pub fn as_slice(&self) -> &[u8] {
2210 unsafe {
2211 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2212 std::slice::from_raw_parts(ptr, Self::len())
2213 }
2214 }
2215 pub fn from_slice(buf: &[u8]) -> &Self {
2216 assert!(buf.len() >= Self::len());
2217 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2218 unsafe { std::mem::transmute(buf.as_ptr()) }
2219 }
2220 pub fn as_array(&self) -> &[u8; 12usize] {
2221 unsafe { std::mem::transmute(self) }
2222 }
2223 pub fn from_array(buf: &[u8; 12usize]) -> &Self {
2224 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2225 unsafe { std::mem::transmute(buf) }
2226 }
2227 pub fn into_array(self) -> [u8; 12usize] {
2228 unsafe { std::mem::transmute(self) }
2229 }
2230 pub const fn len() -> usize {
2231 const _: () = assert!(std::mem::size_of::<TcRatespec>() == 12usize);
2232 12usize
2233 }
2234}
2235impl std::fmt::Debug for TcRatespec {
2236 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2237 fmt.debug_struct("TcRatespec")
2238 .field("cell_log", &self.cell_log)
2239 .field("linklayer", &self.linklayer)
2240 .field("overhead", &self.overhead)
2241 .field("cell_align", &self.cell_align)
2242 .field("mpu", &self.mpu)
2243 .field("rate", &self.rate)
2244 .finish()
2245 }
2246}
2247#[repr(C, packed(4))]
2248pub struct TcTbfQopt {
2249 pub rate: TcRatespec,
2250 pub peakrate: TcRatespec,
2251 pub limit: u32,
2252 pub buffer: u32,
2253 pub mtu: u32,
2254}
2255impl Clone for TcTbfQopt {
2256 fn clone(&self) -> Self {
2257 Self::new_from_array(*self.as_array())
2258 }
2259}
2260#[doc = "Create zero-initialized struct"]
2261impl Default for TcTbfQopt {
2262 fn default() -> Self {
2263 Self::new()
2264 }
2265}
2266impl TcTbfQopt {
2267 #[doc = "Create zero-initialized struct"]
2268 pub fn new() -> Self {
2269 Self::new_from_array([0u8; Self::len()])
2270 }
2271 #[doc = "Copy from contents from slice"]
2272 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2273 if other.len() != Self::len() {
2274 return None;
2275 }
2276 let mut buf = [0u8; Self::len()];
2277 buf.clone_from_slice(other);
2278 Some(Self::new_from_array(buf))
2279 }
2280 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2281 pub fn new_from_zeroed(other: &[u8]) -> Self {
2282 let mut buf = [0u8; Self::len()];
2283 let len = buf.len().min(other.len());
2284 buf[..len].clone_from_slice(&other[..len]);
2285 Self::new_from_array(buf)
2286 }
2287 pub fn new_from_array(buf: [u8; 36usize]) -> Self {
2288 unsafe { std::mem::transmute(buf) }
2289 }
2290 pub fn as_slice(&self) -> &[u8] {
2291 unsafe {
2292 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2293 std::slice::from_raw_parts(ptr, Self::len())
2294 }
2295 }
2296 pub fn from_slice(buf: &[u8]) -> &Self {
2297 assert!(buf.len() >= Self::len());
2298 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2299 unsafe { std::mem::transmute(buf.as_ptr()) }
2300 }
2301 pub fn as_array(&self) -> &[u8; 36usize] {
2302 unsafe { std::mem::transmute(self) }
2303 }
2304 pub fn from_array(buf: &[u8; 36usize]) -> &Self {
2305 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2306 unsafe { std::mem::transmute(buf) }
2307 }
2308 pub fn into_array(self) -> [u8; 36usize] {
2309 unsafe { std::mem::transmute(self) }
2310 }
2311 pub const fn len() -> usize {
2312 const _: () = assert!(std::mem::size_of::<TcTbfQopt>() == 36usize);
2313 36usize
2314 }
2315}
2316impl std::fmt::Debug for TcTbfQopt {
2317 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2318 fmt.debug_struct("TcTbfQopt")
2319 .field("rate", &self.rate)
2320 .field("peakrate", &self.peakrate)
2321 .field("limit", &self.limit)
2322 .field("buffer", &self.buffer)
2323 .field("mtu", &self.mtu)
2324 .finish()
2325 }
2326}
2327#[derive(Debug)]
2328#[repr(C, packed(4))]
2329pub struct TcSizespec {
2330 pub cell_log: u8,
2331 pub size_log: u8,
2332 pub cell_align: i16,
2333 pub overhead: i32,
2334 pub linklayer: u32,
2335 pub mpu: u32,
2336 pub mtu: u32,
2337 pub tsize: u32,
2338}
2339impl Clone for TcSizespec {
2340 fn clone(&self) -> Self {
2341 Self::new_from_array(*self.as_array())
2342 }
2343}
2344#[doc = "Create zero-initialized struct"]
2345impl Default for TcSizespec {
2346 fn default() -> Self {
2347 Self::new()
2348 }
2349}
2350impl TcSizespec {
2351 #[doc = "Create zero-initialized struct"]
2352 pub fn new() -> Self {
2353 Self::new_from_array([0u8; Self::len()])
2354 }
2355 #[doc = "Copy from contents from slice"]
2356 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2357 if other.len() != Self::len() {
2358 return None;
2359 }
2360 let mut buf = [0u8; Self::len()];
2361 buf.clone_from_slice(other);
2362 Some(Self::new_from_array(buf))
2363 }
2364 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2365 pub fn new_from_zeroed(other: &[u8]) -> Self {
2366 let mut buf = [0u8; Self::len()];
2367 let len = buf.len().min(other.len());
2368 buf[..len].clone_from_slice(&other[..len]);
2369 Self::new_from_array(buf)
2370 }
2371 pub fn new_from_array(buf: [u8; 24usize]) -> Self {
2372 unsafe { std::mem::transmute(buf) }
2373 }
2374 pub fn as_slice(&self) -> &[u8] {
2375 unsafe {
2376 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2377 std::slice::from_raw_parts(ptr, Self::len())
2378 }
2379 }
2380 pub fn from_slice(buf: &[u8]) -> &Self {
2381 assert!(buf.len() >= Self::len());
2382 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2383 unsafe { std::mem::transmute(buf.as_ptr()) }
2384 }
2385 pub fn as_array(&self) -> &[u8; 24usize] {
2386 unsafe { std::mem::transmute(self) }
2387 }
2388 pub fn from_array(buf: &[u8; 24usize]) -> &Self {
2389 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2390 unsafe { std::mem::transmute(buf) }
2391 }
2392 pub fn into_array(self) -> [u8; 24usize] {
2393 unsafe { std::mem::transmute(self) }
2394 }
2395 pub const fn len() -> usize {
2396 const _: () = assert!(std::mem::size_of::<TcSizespec>() == 24usize);
2397 24usize
2398 }
2399}
2400#[derive(Debug)]
2401#[repr(C, packed(4))]
2402pub struct GnetEstimator {
2403 #[doc = "Sampling period\n"]
2404 pub interval: i8,
2405 #[doc = "The log() of measurement window weight\n"]
2406 pub ewma_log: u8,
2407}
2408impl Clone for GnetEstimator {
2409 fn clone(&self) -> Self {
2410 Self::new_from_array(*self.as_array())
2411 }
2412}
2413#[doc = "Create zero-initialized struct"]
2414impl Default for GnetEstimator {
2415 fn default() -> Self {
2416 Self::new()
2417 }
2418}
2419impl GnetEstimator {
2420 #[doc = "Create zero-initialized struct"]
2421 pub fn new() -> Self {
2422 Self::new_from_array([0u8; Self::len()])
2423 }
2424 #[doc = "Copy from contents from slice"]
2425 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2426 if other.len() != Self::len() {
2427 return None;
2428 }
2429 let mut buf = [0u8; Self::len()];
2430 buf.clone_from_slice(other);
2431 Some(Self::new_from_array(buf))
2432 }
2433 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2434 pub fn new_from_zeroed(other: &[u8]) -> Self {
2435 let mut buf = [0u8; Self::len()];
2436 let len = buf.len().min(other.len());
2437 buf[..len].clone_from_slice(&other[..len]);
2438 Self::new_from_array(buf)
2439 }
2440 pub fn new_from_array(buf: [u8; 2usize]) -> Self {
2441 unsafe { std::mem::transmute(buf) }
2442 }
2443 pub fn as_slice(&self) -> &[u8] {
2444 unsafe {
2445 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2446 std::slice::from_raw_parts(ptr, Self::len())
2447 }
2448 }
2449 pub fn from_slice(buf: &[u8]) -> &Self {
2450 assert!(buf.len() >= Self::len());
2451 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2452 unsafe { std::mem::transmute(buf.as_ptr()) }
2453 }
2454 pub fn as_array(&self) -> &[u8; 2usize] {
2455 unsafe { std::mem::transmute(self) }
2456 }
2457 pub fn from_array(buf: &[u8; 2usize]) -> &Self {
2458 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2459 unsafe { std::mem::transmute(buf) }
2460 }
2461 pub fn into_array(self) -> [u8; 2usize] {
2462 unsafe { std::mem::transmute(self) }
2463 }
2464 pub const fn len() -> usize {
2465 const _: () = assert!(std::mem::size_of::<GnetEstimator>() == 2usize);
2466 2usize
2467 }
2468}
2469#[derive(Debug)]
2470#[repr(C, packed(4))]
2471pub struct TcChokeXstats {
2472 #[doc = "Early drops\n"]
2473 pub early: u32,
2474 #[doc = "Drops due to queue limits\n"]
2475 pub pdrop: u32,
2476 #[doc = "Drops due to drop() calls\n"]
2477 pub other: u32,
2478 #[doc = "Marked packets\n"]
2479 pub marked: u32,
2480 #[doc = "Drops due to flow match\n"]
2481 pub matched: u32,
2482}
2483impl Clone for TcChokeXstats {
2484 fn clone(&self) -> Self {
2485 Self::new_from_array(*self.as_array())
2486 }
2487}
2488#[doc = "Create zero-initialized struct"]
2489impl Default for TcChokeXstats {
2490 fn default() -> Self {
2491 Self::new()
2492 }
2493}
2494impl TcChokeXstats {
2495 #[doc = "Create zero-initialized struct"]
2496 pub fn new() -> Self {
2497 Self::new_from_array([0u8; Self::len()])
2498 }
2499 #[doc = "Copy from contents from slice"]
2500 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2501 if other.len() != Self::len() {
2502 return None;
2503 }
2504 let mut buf = [0u8; Self::len()];
2505 buf.clone_from_slice(other);
2506 Some(Self::new_from_array(buf))
2507 }
2508 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2509 pub fn new_from_zeroed(other: &[u8]) -> Self {
2510 let mut buf = [0u8; Self::len()];
2511 let len = buf.len().min(other.len());
2512 buf[..len].clone_from_slice(&other[..len]);
2513 Self::new_from_array(buf)
2514 }
2515 pub fn new_from_array(buf: [u8; 20usize]) -> Self {
2516 unsafe { std::mem::transmute(buf) }
2517 }
2518 pub fn as_slice(&self) -> &[u8] {
2519 unsafe {
2520 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2521 std::slice::from_raw_parts(ptr, Self::len())
2522 }
2523 }
2524 pub fn from_slice(buf: &[u8]) -> &Self {
2525 assert!(buf.len() >= Self::len());
2526 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2527 unsafe { std::mem::transmute(buf.as_ptr()) }
2528 }
2529 pub fn as_array(&self) -> &[u8; 20usize] {
2530 unsafe { std::mem::transmute(self) }
2531 }
2532 pub fn from_array(buf: &[u8; 20usize]) -> &Self {
2533 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2534 unsafe { std::mem::transmute(buf) }
2535 }
2536 pub fn into_array(self) -> [u8; 20usize] {
2537 unsafe { std::mem::transmute(self) }
2538 }
2539 pub const fn len() -> usize {
2540 const _: () = assert!(std::mem::size_of::<TcChokeXstats>() == 20usize);
2541 20usize
2542 }
2543}
2544#[derive(Debug)]
2545#[repr(C, packed(4))]
2546pub struct TcCodelXstats {
2547 #[doc = "Largest packet we\\'ve seen so far\n"]
2548 pub maxpacket: u32,
2549 #[doc = "How many drops we\\'ve done since the last time we entered dropping state\n"]
2550 pub count: u32,
2551 #[doc = "Count at entry to dropping state\n"]
2552 pub lastcount: u32,
2553 #[doc = "in-queue delay seen by most recently dequeued packet\n"]
2554 pub ldelay: u32,
2555 #[doc = "Time to drop next packet\n"]
2556 pub drop_next: i32,
2557 #[doc = "Number of times max qdisc packet limit was hit\n"]
2558 pub drop_overlimit: u32,
2559 #[doc = "Number of packets we\\'ve ECN marked instead of dropped\n"]
2560 pub ecn_mark: u32,
2561 #[doc = "Are we in a dropping state?\n"]
2562 pub dropping: u32,
2563 #[doc = "Number of CE marked packets because of ce-threshold\n"]
2564 pub ce_mark: u32,
2565}
2566impl Clone for TcCodelXstats {
2567 fn clone(&self) -> Self {
2568 Self::new_from_array(*self.as_array())
2569 }
2570}
2571#[doc = "Create zero-initialized struct"]
2572impl Default for TcCodelXstats {
2573 fn default() -> Self {
2574 Self::new()
2575 }
2576}
2577impl TcCodelXstats {
2578 #[doc = "Create zero-initialized struct"]
2579 pub fn new() -> Self {
2580 Self::new_from_array([0u8; Self::len()])
2581 }
2582 #[doc = "Copy from contents from slice"]
2583 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2584 if other.len() != Self::len() {
2585 return None;
2586 }
2587 let mut buf = [0u8; Self::len()];
2588 buf.clone_from_slice(other);
2589 Some(Self::new_from_array(buf))
2590 }
2591 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2592 pub fn new_from_zeroed(other: &[u8]) -> Self {
2593 let mut buf = [0u8; Self::len()];
2594 let len = buf.len().min(other.len());
2595 buf[..len].clone_from_slice(&other[..len]);
2596 Self::new_from_array(buf)
2597 }
2598 pub fn new_from_array(buf: [u8; 36usize]) -> Self {
2599 unsafe { std::mem::transmute(buf) }
2600 }
2601 pub fn as_slice(&self) -> &[u8] {
2602 unsafe {
2603 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2604 std::slice::from_raw_parts(ptr, Self::len())
2605 }
2606 }
2607 pub fn from_slice(buf: &[u8]) -> &Self {
2608 assert!(buf.len() >= Self::len());
2609 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2610 unsafe { std::mem::transmute(buf.as_ptr()) }
2611 }
2612 pub fn as_array(&self) -> &[u8; 36usize] {
2613 unsafe { std::mem::transmute(self) }
2614 }
2615 pub fn from_array(buf: &[u8; 36usize]) -> &Self {
2616 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2617 unsafe { std::mem::transmute(buf) }
2618 }
2619 pub fn into_array(self) -> [u8; 36usize] {
2620 unsafe { std::mem::transmute(self) }
2621 }
2622 pub const fn len() -> usize {
2623 const _: () = assert!(std::mem::size_of::<TcCodelXstats>() == 36usize);
2624 36usize
2625 }
2626}
2627#[derive(Debug)]
2628#[repr(C, packed(4))]
2629pub struct TcFqCodelXstats {
2630 pub r#type: u32,
2631 #[doc = "Largest packet we\\'ve seen so far\n"]
2632 pub maxpacket: u32,
2633 #[doc = "Number of times max qdisc packet limit was hit\n"]
2634 pub drop_overlimit: u32,
2635 #[doc = "Number of packets we ECN marked instead of being dropped\n"]
2636 pub ecn_mark: u32,
2637 #[doc = "Number of times packets created a new flow\n"]
2638 pub new_flow_count: u32,
2639 #[doc = "Count of flows in new list\n"]
2640 pub new_flows_len: u32,
2641 #[doc = "Count of flows in old list\n"]
2642 pub old_flows_len: u32,
2643 #[doc = "Packets above ce-threshold\n"]
2644 pub ce_mark: u32,
2645 #[doc = "Memory usage in bytes\n"]
2646 pub memory_usage: u32,
2647 pub drop_overmemory: u32,
2648}
2649impl Clone for TcFqCodelXstats {
2650 fn clone(&self) -> Self {
2651 Self::new_from_array(*self.as_array())
2652 }
2653}
2654#[doc = "Create zero-initialized struct"]
2655impl Default for TcFqCodelXstats {
2656 fn default() -> Self {
2657 Self::new()
2658 }
2659}
2660impl TcFqCodelXstats {
2661 #[doc = "Create zero-initialized struct"]
2662 pub fn new() -> Self {
2663 Self::new_from_array([0u8; Self::len()])
2664 }
2665 #[doc = "Copy from contents from slice"]
2666 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2667 if other.len() != Self::len() {
2668 return None;
2669 }
2670 let mut buf = [0u8; Self::len()];
2671 buf.clone_from_slice(other);
2672 Some(Self::new_from_array(buf))
2673 }
2674 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2675 pub fn new_from_zeroed(other: &[u8]) -> Self {
2676 let mut buf = [0u8; Self::len()];
2677 let len = buf.len().min(other.len());
2678 buf[..len].clone_from_slice(&other[..len]);
2679 Self::new_from_array(buf)
2680 }
2681 pub fn new_from_array(buf: [u8; 40usize]) -> Self {
2682 unsafe { std::mem::transmute(buf) }
2683 }
2684 pub fn as_slice(&self) -> &[u8] {
2685 unsafe {
2686 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2687 std::slice::from_raw_parts(ptr, Self::len())
2688 }
2689 }
2690 pub fn from_slice(buf: &[u8]) -> &Self {
2691 assert!(buf.len() >= Self::len());
2692 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2693 unsafe { std::mem::transmute(buf.as_ptr()) }
2694 }
2695 pub fn as_array(&self) -> &[u8; 40usize] {
2696 unsafe { std::mem::transmute(self) }
2697 }
2698 pub fn from_array(buf: &[u8; 40usize]) -> &Self {
2699 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2700 unsafe { std::mem::transmute(buf) }
2701 }
2702 pub fn into_array(self) -> [u8; 40usize] {
2703 unsafe { std::mem::transmute(self) }
2704 }
2705 pub const fn len() -> usize {
2706 const _: () = assert!(std::mem::size_of::<TcFqCodelXstats>() == 40usize);
2707 40usize
2708 }
2709}
2710#[derive(Debug)]
2711#[repr(C, packed(4))]
2712pub struct TcDualpi2Xstats {
2713 #[doc = "Current base PI probability\n"]
2714 pub prob: u32,
2715 #[doc = "Current C-queue delay in microseconds\n"]
2716 pub delay_c: u32,
2717 #[doc = "Current L-queue delay in microseconds\n"]
2718 pub delay_l: u32,
2719 #[doc = "Number of packets enqueued in the C-queue\n"]
2720 pub pkts_in_c: u32,
2721 #[doc = "Number of packets enqueued in the L-queue\n"]
2722 pub pkts_in_l: u32,
2723 #[doc = "Maximum number of packets seen by the DualPI2\n"]
2724 pub maxq: u32,
2725 #[doc = "All packets marked with ECN\n"]
2726 pub ecn_mark: u32,
2727 #[doc = "Only packets marked with ECN due to L-queue step AQM\n"]
2728 pub step_mark: u32,
2729 #[doc = "Current credit value for WRR\n"]
2730 pub credit: i32,
2731 #[doc = "Memory used in bytes by the DualPI2\n"]
2732 pub memory_used: u32,
2733 #[doc = "Maximum memory used in bytes by the DualPI2\n"]
2734 pub max_memory_used: u32,
2735 #[doc = "Memory limit in bytes\n"]
2736 pub memory_limit: u32,
2737}
2738impl Clone for TcDualpi2Xstats {
2739 fn clone(&self) -> Self {
2740 Self::new_from_array(*self.as_array())
2741 }
2742}
2743#[doc = "Create zero-initialized struct"]
2744impl Default for TcDualpi2Xstats {
2745 fn default() -> Self {
2746 Self::new()
2747 }
2748}
2749impl TcDualpi2Xstats {
2750 #[doc = "Create zero-initialized struct"]
2751 pub fn new() -> Self {
2752 Self::new_from_array([0u8; Self::len()])
2753 }
2754 #[doc = "Copy from contents from slice"]
2755 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2756 if other.len() != Self::len() {
2757 return None;
2758 }
2759 let mut buf = [0u8; Self::len()];
2760 buf.clone_from_slice(other);
2761 Some(Self::new_from_array(buf))
2762 }
2763 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2764 pub fn new_from_zeroed(other: &[u8]) -> Self {
2765 let mut buf = [0u8; Self::len()];
2766 let len = buf.len().min(other.len());
2767 buf[..len].clone_from_slice(&other[..len]);
2768 Self::new_from_array(buf)
2769 }
2770 pub fn new_from_array(buf: [u8; 48usize]) -> Self {
2771 unsafe { std::mem::transmute(buf) }
2772 }
2773 pub fn as_slice(&self) -> &[u8] {
2774 unsafe {
2775 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2776 std::slice::from_raw_parts(ptr, Self::len())
2777 }
2778 }
2779 pub fn from_slice(buf: &[u8]) -> &Self {
2780 assert!(buf.len() >= Self::len());
2781 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2782 unsafe { std::mem::transmute(buf.as_ptr()) }
2783 }
2784 pub fn as_array(&self) -> &[u8; 48usize] {
2785 unsafe { std::mem::transmute(self) }
2786 }
2787 pub fn from_array(buf: &[u8; 48usize]) -> &Self {
2788 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2789 unsafe { std::mem::transmute(buf) }
2790 }
2791 pub fn into_array(self) -> [u8; 48usize] {
2792 unsafe { std::mem::transmute(self) }
2793 }
2794 pub const fn len() -> usize {
2795 const _: () = assert!(std::mem::size_of::<TcDualpi2Xstats>() == 48usize);
2796 48usize
2797 }
2798}
2799#[derive(Debug)]
2800#[repr(C, packed(4))]
2801pub struct TcFqPieXstats {
2802 #[doc = "Total number of packets enqueued\n"]
2803 pub packets_in: u32,
2804 #[doc = "Packets dropped due to fq_pie_action\n"]
2805 pub dropped: u32,
2806 #[doc = "Dropped due to lack of space in queue\n"]
2807 pub overlimit: u32,
2808 #[doc = "Dropped due to lack of memory in queue\n"]
2809 pub overmemory: u32,
2810 #[doc = "Packets marked with ECN\n"]
2811 pub ecn_mark: u32,
2812 #[doc = "Count of new flows created by packets\n"]
2813 pub new_flow_count: u32,
2814 #[doc = "Count of flows in new list\n"]
2815 pub new_flows_len: u32,
2816 #[doc = "Count of flows in old list\n"]
2817 pub old_flows_len: u32,
2818 #[doc = "Total memory across all queues\n"]
2819 pub memory_usage: u32,
2820}
2821impl Clone for TcFqPieXstats {
2822 fn clone(&self) -> Self {
2823 Self::new_from_array(*self.as_array())
2824 }
2825}
2826#[doc = "Create zero-initialized struct"]
2827impl Default for TcFqPieXstats {
2828 fn default() -> Self {
2829 Self::new()
2830 }
2831}
2832impl TcFqPieXstats {
2833 #[doc = "Create zero-initialized struct"]
2834 pub fn new() -> Self {
2835 Self::new_from_array([0u8; Self::len()])
2836 }
2837 #[doc = "Copy from contents from slice"]
2838 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2839 if other.len() != Self::len() {
2840 return None;
2841 }
2842 let mut buf = [0u8; Self::len()];
2843 buf.clone_from_slice(other);
2844 Some(Self::new_from_array(buf))
2845 }
2846 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2847 pub fn new_from_zeroed(other: &[u8]) -> Self {
2848 let mut buf = [0u8; Self::len()];
2849 let len = buf.len().min(other.len());
2850 buf[..len].clone_from_slice(&other[..len]);
2851 Self::new_from_array(buf)
2852 }
2853 pub fn new_from_array(buf: [u8; 36usize]) -> Self {
2854 unsafe { std::mem::transmute(buf) }
2855 }
2856 pub fn as_slice(&self) -> &[u8] {
2857 unsafe {
2858 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2859 std::slice::from_raw_parts(ptr, Self::len())
2860 }
2861 }
2862 pub fn from_slice(buf: &[u8]) -> &Self {
2863 assert!(buf.len() >= Self::len());
2864 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2865 unsafe { std::mem::transmute(buf.as_ptr()) }
2866 }
2867 pub fn as_array(&self) -> &[u8; 36usize] {
2868 unsafe { std::mem::transmute(self) }
2869 }
2870 pub fn from_array(buf: &[u8; 36usize]) -> &Self {
2871 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2872 unsafe { std::mem::transmute(buf) }
2873 }
2874 pub fn into_array(self) -> [u8; 36usize] {
2875 unsafe { std::mem::transmute(self) }
2876 }
2877 pub const fn len() -> usize {
2878 const _: () = assert!(std::mem::size_of::<TcFqPieXstats>() == 36usize);
2879 36usize
2880 }
2881}
2882#[repr(C, packed(4))]
2883pub struct TcFqQdStats {
2884 pub gc_flows: u64,
2885 #[doc = "obsolete\n"]
2886 pub highprio_packets: u64,
2887 #[doc = "obsolete\n"]
2888 pub tcp_retrans: u64,
2889 pub throttled: u64,
2890 pub flows_plimit: u64,
2891 pub pkts_too_long: u64,
2892 pub allocation_errors: u64,
2893 pub time_next_delayed_flow: i64,
2894 pub flows: u32,
2895 pub inactive_flows: u32,
2896 pub throttled_flows: u32,
2897 pub unthrottle_latency_ns: u32,
2898 #[doc = "Packets above ce-threshold\n"]
2899 pub ce_mark: u64,
2900 pub horizon_drops: u64,
2901 pub horizon_caps: u64,
2902 pub fastpath_packets: u64,
2903 pub band_drops: [u8; 24usize],
2904 pub band_pkt_count: [u8; 12usize],
2905 pub _pad: [u8; 4usize],
2906}
2907impl Clone for TcFqQdStats {
2908 fn clone(&self) -> Self {
2909 Self::new_from_array(*self.as_array())
2910 }
2911}
2912#[doc = "Create zero-initialized struct"]
2913impl Default for TcFqQdStats {
2914 fn default() -> Self {
2915 Self::new()
2916 }
2917}
2918impl TcFqQdStats {
2919 #[doc = "Create zero-initialized struct"]
2920 pub fn new() -> Self {
2921 Self::new_from_array([0u8; Self::len()])
2922 }
2923 #[doc = "Copy from contents from slice"]
2924 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
2925 if other.len() != Self::len() {
2926 return None;
2927 }
2928 let mut buf = [0u8; Self::len()];
2929 buf.clone_from_slice(other);
2930 Some(Self::new_from_array(buf))
2931 }
2932 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
2933 pub fn new_from_zeroed(other: &[u8]) -> Self {
2934 let mut buf = [0u8; Self::len()];
2935 let len = buf.len().min(other.len());
2936 buf[..len].clone_from_slice(&other[..len]);
2937 Self::new_from_array(buf)
2938 }
2939 pub fn new_from_array(buf: [u8; 152usize]) -> Self {
2940 unsafe { std::mem::transmute(buf) }
2941 }
2942 pub fn as_slice(&self) -> &[u8] {
2943 unsafe {
2944 let ptr: *const u8 = std::mem::transmute(self as *const Self);
2945 std::slice::from_raw_parts(ptr, Self::len())
2946 }
2947 }
2948 pub fn from_slice(buf: &[u8]) -> &Self {
2949 assert!(buf.len() >= Self::len());
2950 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2951 unsafe { std::mem::transmute(buf.as_ptr()) }
2952 }
2953 pub fn as_array(&self) -> &[u8; 152usize] {
2954 unsafe { std::mem::transmute(self) }
2955 }
2956 pub fn from_array(buf: &[u8; 152usize]) -> &Self {
2957 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
2958 unsafe { std::mem::transmute(buf) }
2959 }
2960 pub fn into_array(self) -> [u8; 152usize] {
2961 unsafe { std::mem::transmute(self) }
2962 }
2963 pub const fn len() -> usize {
2964 const _: () = assert!(std::mem::size_of::<TcFqQdStats>() == 152usize);
2965 152usize
2966 }
2967}
2968impl std::fmt::Debug for TcFqQdStats {
2969 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2970 fmt.debug_struct("TcFqQdStats")
2971 .field("gc_flows", &{ self.gc_flows })
2972 .field("highprio_packets", &{ self.highprio_packets })
2973 .field("tcp_retrans", &{ self.tcp_retrans })
2974 .field("throttled", &{ self.throttled })
2975 .field("flows_plimit", &{ self.flows_plimit })
2976 .field("pkts_too_long", &{ self.pkts_too_long })
2977 .field("allocation_errors", &{ self.allocation_errors })
2978 .field("time_next_delayed_flow", &{ self.time_next_delayed_flow })
2979 .field("flows", &self.flows)
2980 .field("inactive_flows", &self.inactive_flows)
2981 .field("throttled_flows", &self.throttled_flows)
2982 .field("unthrottle_latency_ns", &self.unthrottle_latency_ns)
2983 .field("ce_mark", &{ self.ce_mark })
2984 .field("horizon_drops", &{ self.horizon_drops })
2985 .field("horizon_caps", &{ self.horizon_caps })
2986 .field("fastpath_packets", &{ self.fastpath_packets })
2987 .field("band_drops", &self.band_drops)
2988 .field("band_pkt_count", &self.band_pkt_count)
2989 .finish()
2990 }
2991}
2992#[derive(Debug)]
2993#[repr(C, packed(4))]
2994pub struct TcHhfXstats {
2995 #[doc = "Number of times max qdisc packet limit was hit\n"]
2996 pub drop_overlimit: u32,
2997 #[doc = "Number of times max heavy-hitters was hit\n"]
2998 pub hh_overlimit: u32,
2999 #[doc = "Number of captured heavy-hitters so far\n"]
3000 pub hh_tot_count: u32,
3001 #[doc = "Number of current heavy-hitters\n"]
3002 pub hh_cur_count: u32,
3003}
3004impl Clone for TcHhfXstats {
3005 fn clone(&self) -> Self {
3006 Self::new_from_array(*self.as_array())
3007 }
3008}
3009#[doc = "Create zero-initialized struct"]
3010impl Default for TcHhfXstats {
3011 fn default() -> Self {
3012 Self::new()
3013 }
3014}
3015impl TcHhfXstats {
3016 #[doc = "Create zero-initialized struct"]
3017 pub fn new() -> Self {
3018 Self::new_from_array([0u8; Self::len()])
3019 }
3020 #[doc = "Copy from contents from slice"]
3021 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3022 if other.len() != Self::len() {
3023 return None;
3024 }
3025 let mut buf = [0u8; Self::len()];
3026 buf.clone_from_slice(other);
3027 Some(Self::new_from_array(buf))
3028 }
3029 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3030 pub fn new_from_zeroed(other: &[u8]) -> Self {
3031 let mut buf = [0u8; Self::len()];
3032 let len = buf.len().min(other.len());
3033 buf[..len].clone_from_slice(&other[..len]);
3034 Self::new_from_array(buf)
3035 }
3036 pub fn new_from_array(buf: [u8; 16usize]) -> Self {
3037 unsafe { std::mem::transmute(buf) }
3038 }
3039 pub fn as_slice(&self) -> &[u8] {
3040 unsafe {
3041 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3042 std::slice::from_raw_parts(ptr, Self::len())
3043 }
3044 }
3045 pub fn from_slice(buf: &[u8]) -> &Self {
3046 assert!(buf.len() >= Self::len());
3047 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3048 unsafe { std::mem::transmute(buf.as_ptr()) }
3049 }
3050 pub fn as_array(&self) -> &[u8; 16usize] {
3051 unsafe { std::mem::transmute(self) }
3052 }
3053 pub fn from_array(buf: &[u8; 16usize]) -> &Self {
3054 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3055 unsafe { std::mem::transmute(buf) }
3056 }
3057 pub fn into_array(self) -> [u8; 16usize] {
3058 unsafe { std::mem::transmute(self) }
3059 }
3060 pub const fn len() -> usize {
3061 const _: () = assert!(std::mem::size_of::<TcHhfXstats>() == 16usize);
3062 16usize
3063 }
3064}
3065#[repr(C, packed(4))]
3066pub struct TcPieXstats {
3067 #[doc = "Current probability\n"]
3068 pub prob: u64,
3069 #[doc = "Current delay in ms\n"]
3070 pub delay: u32,
3071 #[doc = "Current average dq rate in bits/pie-time\n"]
3072 pub avg_dq_rate: u32,
3073 #[doc = "Is avg-dq-rate being calculated?\n"]
3074 pub dq_rate_estimating: u32,
3075 #[doc = "Total number of packets enqueued\n"]
3076 pub packets_in: u32,
3077 #[doc = "Packets dropped due to pie action\n"]
3078 pub dropped: u32,
3079 #[doc = "Dropped due to lack of space in queue\n"]
3080 pub overlimit: u32,
3081 #[doc = "Maximum queue size\n"]
3082 pub maxq: u32,
3083 #[doc = "Packets marked with ECN\n"]
3084 pub ecn_mark: u32,
3085}
3086impl Clone for TcPieXstats {
3087 fn clone(&self) -> Self {
3088 Self::new_from_array(*self.as_array())
3089 }
3090}
3091#[doc = "Create zero-initialized struct"]
3092impl Default for TcPieXstats {
3093 fn default() -> Self {
3094 Self::new()
3095 }
3096}
3097impl TcPieXstats {
3098 #[doc = "Create zero-initialized struct"]
3099 pub fn new() -> Self {
3100 Self::new_from_array([0u8; Self::len()])
3101 }
3102 #[doc = "Copy from contents from slice"]
3103 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3104 if other.len() != Self::len() {
3105 return None;
3106 }
3107 let mut buf = [0u8; Self::len()];
3108 buf.clone_from_slice(other);
3109 Some(Self::new_from_array(buf))
3110 }
3111 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3112 pub fn new_from_zeroed(other: &[u8]) -> Self {
3113 let mut buf = [0u8; Self::len()];
3114 let len = buf.len().min(other.len());
3115 buf[..len].clone_from_slice(&other[..len]);
3116 Self::new_from_array(buf)
3117 }
3118 pub fn new_from_array(buf: [u8; 40usize]) -> Self {
3119 unsafe { std::mem::transmute(buf) }
3120 }
3121 pub fn as_slice(&self) -> &[u8] {
3122 unsafe {
3123 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3124 std::slice::from_raw_parts(ptr, Self::len())
3125 }
3126 }
3127 pub fn from_slice(buf: &[u8]) -> &Self {
3128 assert!(buf.len() >= Self::len());
3129 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3130 unsafe { std::mem::transmute(buf.as_ptr()) }
3131 }
3132 pub fn as_array(&self) -> &[u8; 40usize] {
3133 unsafe { std::mem::transmute(self) }
3134 }
3135 pub fn from_array(buf: &[u8; 40usize]) -> &Self {
3136 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3137 unsafe { std::mem::transmute(buf) }
3138 }
3139 pub fn into_array(self) -> [u8; 40usize] {
3140 unsafe { std::mem::transmute(self) }
3141 }
3142 pub const fn len() -> usize {
3143 const _: () = assert!(std::mem::size_of::<TcPieXstats>() == 40usize);
3144 40usize
3145 }
3146}
3147impl std::fmt::Debug for TcPieXstats {
3148 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3149 fmt.debug_struct("TcPieXstats")
3150 .field("prob", &{ self.prob })
3151 .field("delay", &self.delay)
3152 .field("avg_dq_rate", &self.avg_dq_rate)
3153 .field("dq_rate_estimating", &self.dq_rate_estimating)
3154 .field("packets_in", &self.packets_in)
3155 .field("dropped", &self.dropped)
3156 .field("overlimit", &self.overlimit)
3157 .field("maxq", &self.maxq)
3158 .field("ecn_mark", &self.ecn_mark)
3159 .finish()
3160 }
3161}
3162#[derive(Debug)]
3163#[repr(C, packed(4))]
3164pub struct TcRedXstats {
3165 #[doc = "Early drops\n"]
3166 pub early: u32,
3167 #[doc = "Drops due to queue limits\n"]
3168 pub pdrop: u32,
3169 #[doc = "Drops due to drop() calls\n"]
3170 pub other: u32,
3171 #[doc = "Marked packets\n"]
3172 pub marked: u32,
3173}
3174impl Clone for TcRedXstats {
3175 fn clone(&self) -> Self {
3176 Self::new_from_array(*self.as_array())
3177 }
3178}
3179#[doc = "Create zero-initialized struct"]
3180impl Default for TcRedXstats {
3181 fn default() -> Self {
3182 Self::new()
3183 }
3184}
3185impl TcRedXstats {
3186 #[doc = "Create zero-initialized struct"]
3187 pub fn new() -> Self {
3188 Self::new_from_array([0u8; Self::len()])
3189 }
3190 #[doc = "Copy from contents from slice"]
3191 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3192 if other.len() != Self::len() {
3193 return None;
3194 }
3195 let mut buf = [0u8; Self::len()];
3196 buf.clone_from_slice(other);
3197 Some(Self::new_from_array(buf))
3198 }
3199 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3200 pub fn new_from_zeroed(other: &[u8]) -> Self {
3201 let mut buf = [0u8; Self::len()];
3202 let len = buf.len().min(other.len());
3203 buf[..len].clone_from_slice(&other[..len]);
3204 Self::new_from_array(buf)
3205 }
3206 pub fn new_from_array(buf: [u8; 16usize]) -> Self {
3207 unsafe { std::mem::transmute(buf) }
3208 }
3209 pub fn as_slice(&self) -> &[u8] {
3210 unsafe {
3211 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3212 std::slice::from_raw_parts(ptr, Self::len())
3213 }
3214 }
3215 pub fn from_slice(buf: &[u8]) -> &Self {
3216 assert!(buf.len() >= Self::len());
3217 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3218 unsafe { std::mem::transmute(buf.as_ptr()) }
3219 }
3220 pub fn as_array(&self) -> &[u8; 16usize] {
3221 unsafe { std::mem::transmute(self) }
3222 }
3223 pub fn from_array(buf: &[u8; 16usize]) -> &Self {
3224 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3225 unsafe { std::mem::transmute(buf) }
3226 }
3227 pub fn into_array(self) -> [u8; 16usize] {
3228 unsafe { std::mem::transmute(self) }
3229 }
3230 pub const fn len() -> usize {
3231 const _: () = assert!(std::mem::size_of::<TcRedXstats>() == 16usize);
3232 16usize
3233 }
3234}
3235#[derive(Debug)]
3236#[repr(C, packed(4))]
3237pub struct TcSfbXstats {
3238 pub earlydrop: u32,
3239 pub penaltydrop: u32,
3240 pub bucketdrop: u32,
3241 pub queuedrop: u32,
3242 #[doc = "drops in child qdisc\n"]
3243 pub childdrop: u32,
3244 pub marked: u32,
3245 pub maxqlen: u32,
3246 pub maxprob: u32,
3247 pub avgprob: u32,
3248}
3249impl Clone for TcSfbXstats {
3250 fn clone(&self) -> Self {
3251 Self::new_from_array(*self.as_array())
3252 }
3253}
3254#[doc = "Create zero-initialized struct"]
3255impl Default for TcSfbXstats {
3256 fn default() -> Self {
3257 Self::new()
3258 }
3259}
3260impl TcSfbXstats {
3261 #[doc = "Create zero-initialized struct"]
3262 pub fn new() -> Self {
3263 Self::new_from_array([0u8; Self::len()])
3264 }
3265 #[doc = "Copy from contents from slice"]
3266 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3267 if other.len() != Self::len() {
3268 return None;
3269 }
3270 let mut buf = [0u8; Self::len()];
3271 buf.clone_from_slice(other);
3272 Some(Self::new_from_array(buf))
3273 }
3274 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3275 pub fn new_from_zeroed(other: &[u8]) -> Self {
3276 let mut buf = [0u8; Self::len()];
3277 let len = buf.len().min(other.len());
3278 buf[..len].clone_from_slice(&other[..len]);
3279 Self::new_from_array(buf)
3280 }
3281 pub fn new_from_array(buf: [u8; 36usize]) -> Self {
3282 unsafe { std::mem::transmute(buf) }
3283 }
3284 pub fn as_slice(&self) -> &[u8] {
3285 unsafe {
3286 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3287 std::slice::from_raw_parts(ptr, Self::len())
3288 }
3289 }
3290 pub fn from_slice(buf: &[u8]) -> &Self {
3291 assert!(buf.len() >= Self::len());
3292 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3293 unsafe { std::mem::transmute(buf.as_ptr()) }
3294 }
3295 pub fn as_array(&self) -> &[u8; 36usize] {
3296 unsafe { std::mem::transmute(self) }
3297 }
3298 pub fn from_array(buf: &[u8; 36usize]) -> &Self {
3299 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3300 unsafe { std::mem::transmute(buf) }
3301 }
3302 pub fn into_array(self) -> [u8; 36usize] {
3303 unsafe { std::mem::transmute(self) }
3304 }
3305 pub const fn len() -> usize {
3306 const _: () = assert!(std::mem::size_of::<TcSfbXstats>() == 36usize);
3307 36usize
3308 }
3309}
3310#[derive(Debug)]
3311#[repr(C, packed(4))]
3312pub struct TcSfqXstats {
3313 pub allot: i32,
3314}
3315impl Clone for TcSfqXstats {
3316 fn clone(&self) -> Self {
3317 Self::new_from_array(*self.as_array())
3318 }
3319}
3320#[doc = "Create zero-initialized struct"]
3321impl Default for TcSfqXstats {
3322 fn default() -> Self {
3323 Self::new()
3324 }
3325}
3326impl TcSfqXstats {
3327 #[doc = "Create zero-initialized struct"]
3328 pub fn new() -> Self {
3329 Self::new_from_array([0u8; Self::len()])
3330 }
3331 #[doc = "Copy from contents from slice"]
3332 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3333 if other.len() != Self::len() {
3334 return None;
3335 }
3336 let mut buf = [0u8; Self::len()];
3337 buf.clone_from_slice(other);
3338 Some(Self::new_from_array(buf))
3339 }
3340 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3341 pub fn new_from_zeroed(other: &[u8]) -> Self {
3342 let mut buf = [0u8; Self::len()];
3343 let len = buf.len().min(other.len());
3344 buf[..len].clone_from_slice(&other[..len]);
3345 Self::new_from_array(buf)
3346 }
3347 pub fn new_from_array(buf: [u8; 4usize]) -> Self {
3348 unsafe { std::mem::transmute(buf) }
3349 }
3350 pub fn as_slice(&self) -> &[u8] {
3351 unsafe {
3352 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3353 std::slice::from_raw_parts(ptr, Self::len())
3354 }
3355 }
3356 pub fn from_slice(buf: &[u8]) -> &Self {
3357 assert!(buf.len() >= Self::len());
3358 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3359 unsafe { std::mem::transmute(buf.as_ptr()) }
3360 }
3361 pub fn as_array(&self) -> &[u8; 4usize] {
3362 unsafe { std::mem::transmute(self) }
3363 }
3364 pub fn from_array(buf: &[u8; 4usize]) -> &Self {
3365 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3366 unsafe { std::mem::transmute(buf) }
3367 }
3368 pub fn into_array(self) -> [u8; 4usize] {
3369 unsafe { std::mem::transmute(self) }
3370 }
3371 pub const fn len() -> usize {
3372 const _: () = assert!(std::mem::size_of::<TcSfqXstats>() == 4usize);
3373 4usize
3374 }
3375}
3376#[repr(C, packed(4))]
3377pub struct GnetStatsBasic {
3378 pub bytes: u64,
3379 pub packets: u32,
3380 pub _pad_12: [u8; 4usize],
3381}
3382impl Clone for GnetStatsBasic {
3383 fn clone(&self) -> Self {
3384 Self::new_from_array(*self.as_array())
3385 }
3386}
3387#[doc = "Create zero-initialized struct"]
3388impl Default for GnetStatsBasic {
3389 fn default() -> Self {
3390 Self::new()
3391 }
3392}
3393impl GnetStatsBasic {
3394 #[doc = "Create zero-initialized struct"]
3395 pub fn new() -> Self {
3396 Self::new_from_array([0u8; Self::len()])
3397 }
3398 #[doc = "Copy from contents from slice"]
3399 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3400 if other.len() != Self::len() {
3401 return None;
3402 }
3403 let mut buf = [0u8; Self::len()];
3404 buf.clone_from_slice(other);
3405 Some(Self::new_from_array(buf))
3406 }
3407 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3408 pub fn new_from_zeroed(other: &[u8]) -> Self {
3409 let mut buf = [0u8; Self::len()];
3410 let len = buf.len().min(other.len());
3411 buf[..len].clone_from_slice(&other[..len]);
3412 Self::new_from_array(buf)
3413 }
3414 pub fn new_from_array(buf: [u8; 16usize]) -> Self {
3415 unsafe { std::mem::transmute(buf) }
3416 }
3417 pub fn as_slice(&self) -> &[u8] {
3418 unsafe {
3419 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3420 std::slice::from_raw_parts(ptr, Self::len())
3421 }
3422 }
3423 pub fn from_slice(buf: &[u8]) -> &Self {
3424 assert!(buf.len() >= Self::len());
3425 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3426 unsafe { std::mem::transmute(buf.as_ptr()) }
3427 }
3428 pub fn as_array(&self) -> &[u8; 16usize] {
3429 unsafe { std::mem::transmute(self) }
3430 }
3431 pub fn from_array(buf: &[u8; 16usize]) -> &Self {
3432 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3433 unsafe { std::mem::transmute(buf) }
3434 }
3435 pub fn into_array(self) -> [u8; 16usize] {
3436 unsafe { std::mem::transmute(self) }
3437 }
3438 pub const fn len() -> usize {
3439 const _: () = assert!(std::mem::size_of::<GnetStatsBasic>() == 16usize);
3440 16usize
3441 }
3442}
3443impl std::fmt::Debug for GnetStatsBasic {
3444 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3445 fmt.debug_struct("GnetStatsBasic")
3446 .field("bytes", &{ self.bytes })
3447 .field("packets", &self.packets)
3448 .finish()
3449 }
3450}
3451#[derive(Debug)]
3452#[repr(C, packed(4))]
3453pub struct GnetStatsRateEst {
3454 pub bps: u32,
3455 pub pps: u32,
3456}
3457impl Clone for GnetStatsRateEst {
3458 fn clone(&self) -> Self {
3459 Self::new_from_array(*self.as_array())
3460 }
3461}
3462#[doc = "Create zero-initialized struct"]
3463impl Default for GnetStatsRateEst {
3464 fn default() -> Self {
3465 Self::new()
3466 }
3467}
3468impl GnetStatsRateEst {
3469 #[doc = "Create zero-initialized struct"]
3470 pub fn new() -> Self {
3471 Self::new_from_array([0u8; Self::len()])
3472 }
3473 #[doc = "Copy from contents from slice"]
3474 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3475 if other.len() != Self::len() {
3476 return None;
3477 }
3478 let mut buf = [0u8; Self::len()];
3479 buf.clone_from_slice(other);
3480 Some(Self::new_from_array(buf))
3481 }
3482 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3483 pub fn new_from_zeroed(other: &[u8]) -> Self {
3484 let mut buf = [0u8; Self::len()];
3485 let len = buf.len().min(other.len());
3486 buf[..len].clone_from_slice(&other[..len]);
3487 Self::new_from_array(buf)
3488 }
3489 pub fn new_from_array(buf: [u8; 8usize]) -> Self {
3490 unsafe { std::mem::transmute(buf) }
3491 }
3492 pub fn as_slice(&self) -> &[u8] {
3493 unsafe {
3494 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3495 std::slice::from_raw_parts(ptr, Self::len())
3496 }
3497 }
3498 pub fn from_slice(buf: &[u8]) -> &Self {
3499 assert!(buf.len() >= Self::len());
3500 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3501 unsafe { std::mem::transmute(buf.as_ptr()) }
3502 }
3503 pub fn as_array(&self) -> &[u8; 8usize] {
3504 unsafe { std::mem::transmute(self) }
3505 }
3506 pub fn from_array(buf: &[u8; 8usize]) -> &Self {
3507 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3508 unsafe { std::mem::transmute(buf) }
3509 }
3510 pub fn into_array(self) -> [u8; 8usize] {
3511 unsafe { std::mem::transmute(self) }
3512 }
3513 pub const fn len() -> usize {
3514 const _: () = assert!(std::mem::size_of::<GnetStatsRateEst>() == 8usize);
3515 8usize
3516 }
3517}
3518#[repr(C, packed(4))]
3519pub struct GnetStatsRateEst64 {
3520 pub bps: u64,
3521 pub pps: u64,
3522}
3523impl Clone for GnetStatsRateEst64 {
3524 fn clone(&self) -> Self {
3525 Self::new_from_array(*self.as_array())
3526 }
3527}
3528#[doc = "Create zero-initialized struct"]
3529impl Default for GnetStatsRateEst64 {
3530 fn default() -> Self {
3531 Self::new()
3532 }
3533}
3534impl GnetStatsRateEst64 {
3535 #[doc = "Create zero-initialized struct"]
3536 pub fn new() -> Self {
3537 Self::new_from_array([0u8; Self::len()])
3538 }
3539 #[doc = "Copy from contents from slice"]
3540 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3541 if other.len() != Self::len() {
3542 return None;
3543 }
3544 let mut buf = [0u8; Self::len()];
3545 buf.clone_from_slice(other);
3546 Some(Self::new_from_array(buf))
3547 }
3548 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3549 pub fn new_from_zeroed(other: &[u8]) -> Self {
3550 let mut buf = [0u8; Self::len()];
3551 let len = buf.len().min(other.len());
3552 buf[..len].clone_from_slice(&other[..len]);
3553 Self::new_from_array(buf)
3554 }
3555 pub fn new_from_array(buf: [u8; 16usize]) -> Self {
3556 unsafe { std::mem::transmute(buf) }
3557 }
3558 pub fn as_slice(&self) -> &[u8] {
3559 unsafe {
3560 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3561 std::slice::from_raw_parts(ptr, Self::len())
3562 }
3563 }
3564 pub fn from_slice(buf: &[u8]) -> &Self {
3565 assert!(buf.len() >= Self::len());
3566 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3567 unsafe { std::mem::transmute(buf.as_ptr()) }
3568 }
3569 pub fn as_array(&self) -> &[u8; 16usize] {
3570 unsafe { std::mem::transmute(self) }
3571 }
3572 pub fn from_array(buf: &[u8; 16usize]) -> &Self {
3573 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3574 unsafe { std::mem::transmute(buf) }
3575 }
3576 pub fn into_array(self) -> [u8; 16usize] {
3577 unsafe { std::mem::transmute(self) }
3578 }
3579 pub const fn len() -> usize {
3580 const _: () = assert!(std::mem::size_of::<GnetStatsRateEst64>() == 16usize);
3581 16usize
3582 }
3583}
3584impl std::fmt::Debug for GnetStatsRateEst64 {
3585 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3586 fmt.debug_struct("GnetStatsRateEst64")
3587 .field("bps", &{ self.bps })
3588 .field("pps", &{ self.pps })
3589 .finish()
3590 }
3591}
3592#[derive(Debug)]
3593#[repr(C, packed(4))]
3594pub struct GnetStatsQueue {
3595 pub qlen: u32,
3596 pub backlog: u32,
3597 pub drops: u32,
3598 pub requeues: u32,
3599 pub overlimits: u32,
3600}
3601impl Clone for GnetStatsQueue {
3602 fn clone(&self) -> Self {
3603 Self::new_from_array(*self.as_array())
3604 }
3605}
3606#[doc = "Create zero-initialized struct"]
3607impl Default for GnetStatsQueue {
3608 fn default() -> Self {
3609 Self::new()
3610 }
3611}
3612impl GnetStatsQueue {
3613 #[doc = "Create zero-initialized struct"]
3614 pub fn new() -> Self {
3615 Self::new_from_array([0u8; Self::len()])
3616 }
3617 #[doc = "Copy from contents from slice"]
3618 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3619 if other.len() != Self::len() {
3620 return None;
3621 }
3622 let mut buf = [0u8; Self::len()];
3623 buf.clone_from_slice(other);
3624 Some(Self::new_from_array(buf))
3625 }
3626 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3627 pub fn new_from_zeroed(other: &[u8]) -> Self {
3628 let mut buf = [0u8; Self::len()];
3629 let len = buf.len().min(other.len());
3630 buf[..len].clone_from_slice(&other[..len]);
3631 Self::new_from_array(buf)
3632 }
3633 pub fn new_from_array(buf: [u8; 20usize]) -> Self {
3634 unsafe { std::mem::transmute(buf) }
3635 }
3636 pub fn as_slice(&self) -> &[u8] {
3637 unsafe {
3638 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3639 std::slice::from_raw_parts(ptr, Self::len())
3640 }
3641 }
3642 pub fn from_slice(buf: &[u8]) -> &Self {
3643 assert!(buf.len() >= Self::len());
3644 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3645 unsafe { std::mem::transmute(buf.as_ptr()) }
3646 }
3647 pub fn as_array(&self) -> &[u8; 20usize] {
3648 unsafe { std::mem::transmute(self) }
3649 }
3650 pub fn from_array(buf: &[u8; 20usize]) -> &Self {
3651 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3652 unsafe { std::mem::transmute(buf) }
3653 }
3654 pub fn into_array(self) -> [u8; 20usize] {
3655 unsafe { std::mem::transmute(self) }
3656 }
3657 pub const fn len() -> usize {
3658 const _: () = assert!(std::mem::size_of::<GnetStatsQueue>() == 20usize);
3659 20usize
3660 }
3661}
3662#[repr(C, packed(4))]
3663pub struct TcU32Key {
3664 pub _mask_be: u32,
3665 pub _val_be: u32,
3666 pub off: i32,
3667 pub offmask: i32,
3668}
3669impl Clone for TcU32Key {
3670 fn clone(&self) -> Self {
3671 Self::new_from_array(*self.as_array())
3672 }
3673}
3674#[doc = "Create zero-initialized struct"]
3675impl Default for TcU32Key {
3676 fn default() -> Self {
3677 Self::new()
3678 }
3679}
3680impl TcU32Key {
3681 #[doc = "Create zero-initialized struct"]
3682 pub fn new() -> Self {
3683 Self::new_from_array([0u8; Self::len()])
3684 }
3685 #[doc = "Copy from contents from slice"]
3686 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3687 if other.len() != Self::len() {
3688 return None;
3689 }
3690 let mut buf = [0u8; Self::len()];
3691 buf.clone_from_slice(other);
3692 Some(Self::new_from_array(buf))
3693 }
3694 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3695 pub fn new_from_zeroed(other: &[u8]) -> Self {
3696 let mut buf = [0u8; Self::len()];
3697 let len = buf.len().min(other.len());
3698 buf[..len].clone_from_slice(&other[..len]);
3699 Self::new_from_array(buf)
3700 }
3701 pub fn new_from_array(buf: [u8; 16usize]) -> Self {
3702 unsafe { std::mem::transmute(buf) }
3703 }
3704 pub fn as_slice(&self) -> &[u8] {
3705 unsafe {
3706 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3707 std::slice::from_raw_parts(ptr, Self::len())
3708 }
3709 }
3710 pub fn from_slice(buf: &[u8]) -> &Self {
3711 assert!(buf.len() >= Self::len());
3712 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3713 unsafe { std::mem::transmute(buf.as_ptr()) }
3714 }
3715 pub fn as_array(&self) -> &[u8; 16usize] {
3716 unsafe { std::mem::transmute(self) }
3717 }
3718 pub fn from_array(buf: &[u8; 16usize]) -> &Self {
3719 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3720 unsafe { std::mem::transmute(buf) }
3721 }
3722 pub fn into_array(self) -> [u8; 16usize] {
3723 unsafe { std::mem::transmute(self) }
3724 }
3725 pub const fn len() -> usize {
3726 const _: () = assert!(std::mem::size_of::<TcU32Key>() == 16usize);
3727 16usize
3728 }
3729 pub fn mask(&self) -> u32 {
3730 u32::from_be(self._mask_be)
3731 }
3732 pub fn set_mask(&mut self, value: u32) {
3733 self._mask_be = value.to_be();
3734 }
3735 pub fn val(&self) -> u32 {
3736 u32::from_be(self._val_be)
3737 }
3738 pub fn set_val(&mut self, value: u32) {
3739 self._val_be = value.to_be();
3740 }
3741}
3742impl std::fmt::Debug for TcU32Key {
3743 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3744 fmt.debug_struct("TcU32Key")
3745 .field("mask", &self.mask())
3746 .field("val", &self.val())
3747 .field("off", &self.off)
3748 .field("offmask", &self.offmask)
3749 .finish()
3750 }
3751}
3752#[derive(Debug)]
3753#[repr(C, packed(4))]
3754pub struct TcU32Mark {
3755 pub val: u32,
3756 pub mask: u32,
3757 pub success: u32,
3758}
3759impl Clone for TcU32Mark {
3760 fn clone(&self) -> Self {
3761 Self::new_from_array(*self.as_array())
3762 }
3763}
3764#[doc = "Create zero-initialized struct"]
3765impl Default for TcU32Mark {
3766 fn default() -> Self {
3767 Self::new()
3768 }
3769}
3770impl TcU32Mark {
3771 #[doc = "Create zero-initialized struct"]
3772 pub fn new() -> Self {
3773 Self::new_from_array([0u8; Self::len()])
3774 }
3775 #[doc = "Copy from contents from slice"]
3776 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3777 if other.len() != Self::len() {
3778 return None;
3779 }
3780 let mut buf = [0u8; Self::len()];
3781 buf.clone_from_slice(other);
3782 Some(Self::new_from_array(buf))
3783 }
3784 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3785 pub fn new_from_zeroed(other: &[u8]) -> Self {
3786 let mut buf = [0u8; Self::len()];
3787 let len = buf.len().min(other.len());
3788 buf[..len].clone_from_slice(&other[..len]);
3789 Self::new_from_array(buf)
3790 }
3791 pub fn new_from_array(buf: [u8; 12usize]) -> Self {
3792 unsafe { std::mem::transmute(buf) }
3793 }
3794 pub fn as_slice(&self) -> &[u8] {
3795 unsafe {
3796 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3797 std::slice::from_raw_parts(ptr, Self::len())
3798 }
3799 }
3800 pub fn from_slice(buf: &[u8]) -> &Self {
3801 assert!(buf.len() >= Self::len());
3802 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3803 unsafe { std::mem::transmute(buf.as_ptr()) }
3804 }
3805 pub fn as_array(&self) -> &[u8; 12usize] {
3806 unsafe { std::mem::transmute(self) }
3807 }
3808 pub fn from_array(buf: &[u8; 12usize]) -> &Self {
3809 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3810 unsafe { std::mem::transmute(buf) }
3811 }
3812 pub fn into_array(self) -> [u8; 12usize] {
3813 unsafe { std::mem::transmute(self) }
3814 }
3815 pub const fn len() -> usize {
3816 const _: () = assert!(std::mem::size_of::<TcU32Mark>() == 12usize);
3817 12usize
3818 }
3819}
3820#[repr(C, packed(4))]
3821pub struct TcU32Sel {
3822 pub flags: u8,
3823 pub offshift: u8,
3824 pub nkeys: u8,
3825 pub _pad_3: [u8; 1usize],
3826 pub _offmask_be: u16,
3827 pub off: u16,
3828 pub offoff: i16,
3829 pub hoff: i16,
3830 pub _hmask_be: u32,
3831 pub keys: TcU32Key,
3832}
3833impl Clone for TcU32Sel {
3834 fn clone(&self) -> Self {
3835 Self::new_from_array(*self.as_array())
3836 }
3837}
3838#[doc = "Create zero-initialized struct"]
3839impl Default for TcU32Sel {
3840 fn default() -> Self {
3841 Self::new()
3842 }
3843}
3844impl TcU32Sel {
3845 #[doc = "Create zero-initialized struct"]
3846 pub fn new() -> Self {
3847 Self::new_from_array([0u8; Self::len()])
3848 }
3849 #[doc = "Copy from contents from slice"]
3850 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3851 if other.len() != Self::len() {
3852 return None;
3853 }
3854 let mut buf = [0u8; Self::len()];
3855 buf.clone_from_slice(other);
3856 Some(Self::new_from_array(buf))
3857 }
3858 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3859 pub fn new_from_zeroed(other: &[u8]) -> Self {
3860 let mut buf = [0u8; Self::len()];
3861 let len = buf.len().min(other.len());
3862 buf[..len].clone_from_slice(&other[..len]);
3863 Self::new_from_array(buf)
3864 }
3865 pub fn new_from_array(buf: [u8; 32usize]) -> Self {
3866 unsafe { std::mem::transmute(buf) }
3867 }
3868 pub fn as_slice(&self) -> &[u8] {
3869 unsafe {
3870 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3871 std::slice::from_raw_parts(ptr, Self::len())
3872 }
3873 }
3874 pub fn from_slice(buf: &[u8]) -> &Self {
3875 assert!(buf.len() >= Self::len());
3876 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3877 unsafe { std::mem::transmute(buf.as_ptr()) }
3878 }
3879 pub fn as_array(&self) -> &[u8; 32usize] {
3880 unsafe { std::mem::transmute(self) }
3881 }
3882 pub fn from_array(buf: &[u8; 32usize]) -> &Self {
3883 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3884 unsafe { std::mem::transmute(buf) }
3885 }
3886 pub fn into_array(self) -> [u8; 32usize] {
3887 unsafe { std::mem::transmute(self) }
3888 }
3889 pub const fn len() -> usize {
3890 const _: () = assert!(std::mem::size_of::<TcU32Sel>() == 32usize);
3891 32usize
3892 }
3893 pub fn offmask(&self) -> u16 {
3894 u16::from_be(self._offmask_be)
3895 }
3896 pub fn set_offmask(&mut self, value: u16) {
3897 self._offmask_be = value.to_be();
3898 }
3899 pub fn hmask(&self) -> u32 {
3900 u32::from_be(self._hmask_be)
3901 }
3902 pub fn set_hmask(&mut self, value: u32) {
3903 self._hmask_be = value.to_be();
3904 }
3905}
3906impl std::fmt::Debug for TcU32Sel {
3907 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3908 fmt.debug_struct("TcU32Sel")
3909 .field("flags", &self.flags)
3910 .field("offshift", &self.offshift)
3911 .field("nkeys", &self.nkeys)
3912 .field("offmask", &self.offmask())
3913 .field("off", &self.off)
3914 .field("offoff", &self.offoff)
3915 .field("hoff", &self.hoff)
3916 .field("hmask", &self.hmask())
3917 .field("keys", &self.keys)
3918 .finish()
3919 }
3920}
3921#[repr(C, packed(4))]
3922pub struct TcU32Pcnt {
3923 pub rcnt: u64,
3924 pub rhit: u64,
3925 pub kcnts: u64,
3926}
3927impl Clone for TcU32Pcnt {
3928 fn clone(&self) -> Self {
3929 Self::new_from_array(*self.as_array())
3930 }
3931}
3932#[doc = "Create zero-initialized struct"]
3933impl Default for TcU32Pcnt {
3934 fn default() -> Self {
3935 Self::new()
3936 }
3937}
3938impl TcU32Pcnt {
3939 #[doc = "Create zero-initialized struct"]
3940 pub fn new() -> Self {
3941 Self::new_from_array([0u8; Self::len()])
3942 }
3943 #[doc = "Copy from contents from slice"]
3944 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
3945 if other.len() != Self::len() {
3946 return None;
3947 }
3948 let mut buf = [0u8; Self::len()];
3949 buf.clone_from_slice(other);
3950 Some(Self::new_from_array(buf))
3951 }
3952 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
3953 pub fn new_from_zeroed(other: &[u8]) -> Self {
3954 let mut buf = [0u8; Self::len()];
3955 let len = buf.len().min(other.len());
3956 buf[..len].clone_from_slice(&other[..len]);
3957 Self::new_from_array(buf)
3958 }
3959 pub fn new_from_array(buf: [u8; 24usize]) -> Self {
3960 unsafe { std::mem::transmute(buf) }
3961 }
3962 pub fn as_slice(&self) -> &[u8] {
3963 unsafe {
3964 let ptr: *const u8 = std::mem::transmute(self as *const Self);
3965 std::slice::from_raw_parts(ptr, Self::len())
3966 }
3967 }
3968 pub fn from_slice(buf: &[u8]) -> &Self {
3969 assert!(buf.len() >= Self::len());
3970 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3971 unsafe { std::mem::transmute(buf.as_ptr()) }
3972 }
3973 pub fn as_array(&self) -> &[u8; 24usize] {
3974 unsafe { std::mem::transmute(self) }
3975 }
3976 pub fn from_array(buf: &[u8; 24usize]) -> &Self {
3977 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
3978 unsafe { std::mem::transmute(buf) }
3979 }
3980 pub fn into_array(self) -> [u8; 24usize] {
3981 unsafe { std::mem::transmute(self) }
3982 }
3983 pub const fn len() -> usize {
3984 const _: () = assert!(std::mem::size_of::<TcU32Pcnt>() == 24usize);
3985 24usize
3986 }
3987}
3988impl std::fmt::Debug for TcU32Pcnt {
3989 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3990 fmt.debug_struct("TcU32Pcnt")
3991 .field("rcnt", &{ self.rcnt })
3992 .field("rhit", &{ self.rhit })
3993 .field("kcnts", &{ self.kcnts })
3994 .finish()
3995 }
3996}
3997#[repr(C, packed(4))]
3998pub struct TcfT {
3999 pub install: u64,
4000 pub lastuse: u64,
4001 pub expires: u64,
4002 pub firstuse: u64,
4003}
4004impl Clone for TcfT {
4005 fn clone(&self) -> Self {
4006 Self::new_from_array(*self.as_array())
4007 }
4008}
4009#[doc = "Create zero-initialized struct"]
4010impl Default for TcfT {
4011 fn default() -> Self {
4012 Self::new()
4013 }
4014}
4015impl TcfT {
4016 #[doc = "Create zero-initialized struct"]
4017 pub fn new() -> Self {
4018 Self::new_from_array([0u8; Self::len()])
4019 }
4020 #[doc = "Copy from contents from slice"]
4021 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4022 if other.len() != Self::len() {
4023 return None;
4024 }
4025 let mut buf = [0u8; Self::len()];
4026 buf.clone_from_slice(other);
4027 Some(Self::new_from_array(buf))
4028 }
4029 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4030 pub fn new_from_zeroed(other: &[u8]) -> Self {
4031 let mut buf = [0u8; Self::len()];
4032 let len = buf.len().min(other.len());
4033 buf[..len].clone_from_slice(&other[..len]);
4034 Self::new_from_array(buf)
4035 }
4036 pub fn new_from_array(buf: [u8; 32usize]) -> Self {
4037 unsafe { std::mem::transmute(buf) }
4038 }
4039 pub fn as_slice(&self) -> &[u8] {
4040 unsafe {
4041 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4042 std::slice::from_raw_parts(ptr, Self::len())
4043 }
4044 }
4045 pub fn from_slice(buf: &[u8]) -> &Self {
4046 assert!(buf.len() >= Self::len());
4047 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4048 unsafe { std::mem::transmute(buf.as_ptr()) }
4049 }
4050 pub fn as_array(&self) -> &[u8; 32usize] {
4051 unsafe { std::mem::transmute(self) }
4052 }
4053 pub fn from_array(buf: &[u8; 32usize]) -> &Self {
4054 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4055 unsafe { std::mem::transmute(buf) }
4056 }
4057 pub fn into_array(self) -> [u8; 32usize] {
4058 unsafe { std::mem::transmute(self) }
4059 }
4060 pub const fn len() -> usize {
4061 const _: () = assert!(std::mem::size_of::<TcfT>() == 32usize);
4062 32usize
4063 }
4064}
4065impl std::fmt::Debug for TcfT {
4066 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4067 fmt.debug_struct("TcfT")
4068 .field("install", &{ self.install })
4069 .field("lastuse", &{ self.lastuse })
4070 .field("expires", &{ self.expires })
4071 .field("firstuse", &{ self.firstuse })
4072 .finish()
4073 }
4074}
4075#[derive(Debug)]
4076#[repr(C, packed(4))]
4077pub struct TcGact {
4078 pub index: u32,
4079 pub capab: u32,
4080 pub action: i32,
4081 pub refcnt: i32,
4082 pub bindcnt: i32,
4083}
4084impl Clone for TcGact {
4085 fn clone(&self) -> Self {
4086 Self::new_from_array(*self.as_array())
4087 }
4088}
4089#[doc = "Create zero-initialized struct"]
4090impl Default for TcGact {
4091 fn default() -> Self {
4092 Self::new()
4093 }
4094}
4095impl TcGact {
4096 #[doc = "Create zero-initialized struct"]
4097 pub fn new() -> Self {
4098 Self::new_from_array([0u8; Self::len()])
4099 }
4100 #[doc = "Copy from contents from slice"]
4101 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4102 if other.len() != Self::len() {
4103 return None;
4104 }
4105 let mut buf = [0u8; Self::len()];
4106 buf.clone_from_slice(other);
4107 Some(Self::new_from_array(buf))
4108 }
4109 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4110 pub fn new_from_zeroed(other: &[u8]) -> Self {
4111 let mut buf = [0u8; Self::len()];
4112 let len = buf.len().min(other.len());
4113 buf[..len].clone_from_slice(&other[..len]);
4114 Self::new_from_array(buf)
4115 }
4116 pub fn new_from_array(buf: [u8; 20usize]) -> Self {
4117 unsafe { std::mem::transmute(buf) }
4118 }
4119 pub fn as_slice(&self) -> &[u8] {
4120 unsafe {
4121 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4122 std::slice::from_raw_parts(ptr, Self::len())
4123 }
4124 }
4125 pub fn from_slice(buf: &[u8]) -> &Self {
4126 assert!(buf.len() >= Self::len());
4127 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4128 unsafe { std::mem::transmute(buf.as_ptr()) }
4129 }
4130 pub fn as_array(&self) -> &[u8; 20usize] {
4131 unsafe { std::mem::transmute(self) }
4132 }
4133 pub fn from_array(buf: &[u8; 20usize]) -> &Self {
4134 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4135 unsafe { std::mem::transmute(buf) }
4136 }
4137 pub fn into_array(self) -> [u8; 20usize] {
4138 unsafe { std::mem::transmute(self) }
4139 }
4140 pub const fn len() -> usize {
4141 const _: () = assert!(std::mem::size_of::<TcGact>() == 20usize);
4142 20usize
4143 }
4144}
4145#[derive(Debug)]
4146#[repr(C, packed(4))]
4147pub struct TcGactP {
4148 pub ptype: u16,
4149 pub pval: u16,
4150 pub paction: i32,
4151}
4152impl Clone for TcGactP {
4153 fn clone(&self) -> Self {
4154 Self::new_from_array(*self.as_array())
4155 }
4156}
4157#[doc = "Create zero-initialized struct"]
4158impl Default for TcGactP {
4159 fn default() -> Self {
4160 Self::new()
4161 }
4162}
4163impl TcGactP {
4164 #[doc = "Create zero-initialized struct"]
4165 pub fn new() -> Self {
4166 Self::new_from_array([0u8; Self::len()])
4167 }
4168 #[doc = "Copy from contents from slice"]
4169 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4170 if other.len() != Self::len() {
4171 return None;
4172 }
4173 let mut buf = [0u8; Self::len()];
4174 buf.clone_from_slice(other);
4175 Some(Self::new_from_array(buf))
4176 }
4177 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4178 pub fn new_from_zeroed(other: &[u8]) -> Self {
4179 let mut buf = [0u8; Self::len()];
4180 let len = buf.len().min(other.len());
4181 buf[..len].clone_from_slice(&other[..len]);
4182 Self::new_from_array(buf)
4183 }
4184 pub fn new_from_array(buf: [u8; 8usize]) -> Self {
4185 unsafe { std::mem::transmute(buf) }
4186 }
4187 pub fn as_slice(&self) -> &[u8] {
4188 unsafe {
4189 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4190 std::slice::from_raw_parts(ptr, Self::len())
4191 }
4192 }
4193 pub fn from_slice(buf: &[u8]) -> &Self {
4194 assert!(buf.len() >= Self::len());
4195 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4196 unsafe { std::mem::transmute(buf.as_ptr()) }
4197 }
4198 pub fn as_array(&self) -> &[u8; 8usize] {
4199 unsafe { std::mem::transmute(self) }
4200 }
4201 pub fn from_array(buf: &[u8; 8usize]) -> &Self {
4202 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4203 unsafe { std::mem::transmute(buf) }
4204 }
4205 pub fn into_array(self) -> [u8; 8usize] {
4206 unsafe { std::mem::transmute(self) }
4207 }
4208 pub const fn len() -> usize {
4209 const _: () = assert!(std::mem::size_of::<TcGactP>() == 8usize);
4210 8usize
4211 }
4212}
4213#[derive(Debug)]
4214#[repr(C, packed(4))]
4215pub struct TcfEmatchTreeHdr {
4216 pub nmatches: u16,
4217 pub progid: u16,
4218}
4219impl Clone for TcfEmatchTreeHdr {
4220 fn clone(&self) -> Self {
4221 Self::new_from_array(*self.as_array())
4222 }
4223}
4224#[doc = "Create zero-initialized struct"]
4225impl Default for TcfEmatchTreeHdr {
4226 fn default() -> Self {
4227 Self::new()
4228 }
4229}
4230impl TcfEmatchTreeHdr {
4231 #[doc = "Create zero-initialized struct"]
4232 pub fn new() -> Self {
4233 Self::new_from_array([0u8; Self::len()])
4234 }
4235 #[doc = "Copy from contents from slice"]
4236 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4237 if other.len() != Self::len() {
4238 return None;
4239 }
4240 let mut buf = [0u8; Self::len()];
4241 buf.clone_from_slice(other);
4242 Some(Self::new_from_array(buf))
4243 }
4244 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4245 pub fn new_from_zeroed(other: &[u8]) -> Self {
4246 let mut buf = [0u8; Self::len()];
4247 let len = buf.len().min(other.len());
4248 buf[..len].clone_from_slice(&other[..len]);
4249 Self::new_from_array(buf)
4250 }
4251 pub fn new_from_array(buf: [u8; 4usize]) -> Self {
4252 unsafe { std::mem::transmute(buf) }
4253 }
4254 pub fn as_slice(&self) -> &[u8] {
4255 unsafe {
4256 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4257 std::slice::from_raw_parts(ptr, Self::len())
4258 }
4259 }
4260 pub fn from_slice(buf: &[u8]) -> &Self {
4261 assert!(buf.len() >= Self::len());
4262 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4263 unsafe { std::mem::transmute(buf.as_ptr()) }
4264 }
4265 pub fn as_array(&self) -> &[u8; 4usize] {
4266 unsafe { std::mem::transmute(self) }
4267 }
4268 pub fn from_array(buf: &[u8; 4usize]) -> &Self {
4269 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4270 unsafe { std::mem::transmute(buf) }
4271 }
4272 pub fn into_array(self) -> [u8; 4usize] {
4273 unsafe { std::mem::transmute(self) }
4274 }
4275 pub const fn len() -> usize {
4276 const _: () = assert!(std::mem::size_of::<TcfEmatchTreeHdr>() == 4usize);
4277 4usize
4278 }
4279}
4280#[repr(C, packed(4))]
4281pub struct TcBasicPcnt {
4282 pub rcnt: u64,
4283 pub rhit: u64,
4284}
4285impl Clone for TcBasicPcnt {
4286 fn clone(&self) -> Self {
4287 Self::new_from_array(*self.as_array())
4288 }
4289}
4290#[doc = "Create zero-initialized struct"]
4291impl Default for TcBasicPcnt {
4292 fn default() -> Self {
4293 Self::new()
4294 }
4295}
4296impl TcBasicPcnt {
4297 #[doc = "Create zero-initialized struct"]
4298 pub fn new() -> Self {
4299 Self::new_from_array([0u8; Self::len()])
4300 }
4301 #[doc = "Copy from contents from slice"]
4302 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4303 if other.len() != Self::len() {
4304 return None;
4305 }
4306 let mut buf = [0u8; Self::len()];
4307 buf.clone_from_slice(other);
4308 Some(Self::new_from_array(buf))
4309 }
4310 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4311 pub fn new_from_zeroed(other: &[u8]) -> Self {
4312 let mut buf = [0u8; Self::len()];
4313 let len = buf.len().min(other.len());
4314 buf[..len].clone_from_slice(&other[..len]);
4315 Self::new_from_array(buf)
4316 }
4317 pub fn new_from_array(buf: [u8; 16usize]) -> Self {
4318 unsafe { std::mem::transmute(buf) }
4319 }
4320 pub fn as_slice(&self) -> &[u8] {
4321 unsafe {
4322 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4323 std::slice::from_raw_parts(ptr, Self::len())
4324 }
4325 }
4326 pub fn from_slice(buf: &[u8]) -> &Self {
4327 assert!(buf.len() >= Self::len());
4328 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4329 unsafe { std::mem::transmute(buf.as_ptr()) }
4330 }
4331 pub fn as_array(&self) -> &[u8; 16usize] {
4332 unsafe { std::mem::transmute(self) }
4333 }
4334 pub fn from_array(buf: &[u8; 16usize]) -> &Self {
4335 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4336 unsafe { std::mem::transmute(buf) }
4337 }
4338 pub fn into_array(self) -> [u8; 16usize] {
4339 unsafe { std::mem::transmute(self) }
4340 }
4341 pub const fn len() -> usize {
4342 const _: () = assert!(std::mem::size_of::<TcBasicPcnt>() == 16usize);
4343 16usize
4344 }
4345}
4346impl std::fmt::Debug for TcBasicPcnt {
4347 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4348 fmt.debug_struct("TcBasicPcnt")
4349 .field("rcnt", &{ self.rcnt })
4350 .field("rhit", &{ self.rhit })
4351 .finish()
4352 }
4353}
4354#[repr(C, packed(4))]
4355pub struct TcMatchallPcnt {
4356 pub rhit: u64,
4357}
4358impl Clone for TcMatchallPcnt {
4359 fn clone(&self) -> Self {
4360 Self::new_from_array(*self.as_array())
4361 }
4362}
4363#[doc = "Create zero-initialized struct"]
4364impl Default for TcMatchallPcnt {
4365 fn default() -> Self {
4366 Self::new()
4367 }
4368}
4369impl TcMatchallPcnt {
4370 #[doc = "Create zero-initialized struct"]
4371 pub fn new() -> Self {
4372 Self::new_from_array([0u8; Self::len()])
4373 }
4374 #[doc = "Copy from contents from slice"]
4375 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4376 if other.len() != Self::len() {
4377 return None;
4378 }
4379 let mut buf = [0u8; Self::len()];
4380 buf.clone_from_slice(other);
4381 Some(Self::new_from_array(buf))
4382 }
4383 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4384 pub fn new_from_zeroed(other: &[u8]) -> Self {
4385 let mut buf = [0u8; Self::len()];
4386 let len = buf.len().min(other.len());
4387 buf[..len].clone_from_slice(&other[..len]);
4388 Self::new_from_array(buf)
4389 }
4390 pub fn new_from_array(buf: [u8; 8usize]) -> Self {
4391 unsafe { std::mem::transmute(buf) }
4392 }
4393 pub fn as_slice(&self) -> &[u8] {
4394 unsafe {
4395 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4396 std::slice::from_raw_parts(ptr, Self::len())
4397 }
4398 }
4399 pub fn from_slice(buf: &[u8]) -> &Self {
4400 assert!(buf.len() >= Self::len());
4401 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4402 unsafe { std::mem::transmute(buf.as_ptr()) }
4403 }
4404 pub fn as_array(&self) -> &[u8; 8usize] {
4405 unsafe { std::mem::transmute(self) }
4406 }
4407 pub fn from_array(buf: &[u8; 8usize]) -> &Self {
4408 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4409 unsafe { std::mem::transmute(buf) }
4410 }
4411 pub fn into_array(self) -> [u8; 8usize] {
4412 unsafe { std::mem::transmute(self) }
4413 }
4414 pub const fn len() -> usize {
4415 const _: () = assert!(std::mem::size_of::<TcMatchallPcnt>() == 8usize);
4416 8usize
4417 }
4418}
4419impl std::fmt::Debug for TcMatchallPcnt {
4420 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4421 fmt.debug_struct("TcMatchallPcnt")
4422 .field("rhit", &{ self.rhit })
4423 .finish()
4424 }
4425}
4426#[derive(Debug)]
4427#[repr(C, packed(4))]
4428pub struct TcMpls {
4429 pub index: u32,
4430 pub capab: u32,
4431 pub action: i32,
4432 pub refcnt: i32,
4433 pub bindcnt: i32,
4434 pub m_action: i32,
4435}
4436impl Clone for TcMpls {
4437 fn clone(&self) -> Self {
4438 Self::new_from_array(*self.as_array())
4439 }
4440}
4441#[doc = "Create zero-initialized struct"]
4442impl Default for TcMpls {
4443 fn default() -> Self {
4444 Self::new()
4445 }
4446}
4447impl TcMpls {
4448 #[doc = "Create zero-initialized struct"]
4449 pub fn new() -> Self {
4450 Self::new_from_array([0u8; Self::len()])
4451 }
4452 #[doc = "Copy from contents from slice"]
4453 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4454 if other.len() != Self::len() {
4455 return None;
4456 }
4457 let mut buf = [0u8; Self::len()];
4458 buf.clone_from_slice(other);
4459 Some(Self::new_from_array(buf))
4460 }
4461 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4462 pub fn new_from_zeroed(other: &[u8]) -> Self {
4463 let mut buf = [0u8; Self::len()];
4464 let len = buf.len().min(other.len());
4465 buf[..len].clone_from_slice(&other[..len]);
4466 Self::new_from_array(buf)
4467 }
4468 pub fn new_from_array(buf: [u8; 24usize]) -> Self {
4469 unsafe { std::mem::transmute(buf) }
4470 }
4471 pub fn as_slice(&self) -> &[u8] {
4472 unsafe {
4473 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4474 std::slice::from_raw_parts(ptr, Self::len())
4475 }
4476 }
4477 pub fn from_slice(buf: &[u8]) -> &Self {
4478 assert!(buf.len() >= Self::len());
4479 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4480 unsafe { std::mem::transmute(buf.as_ptr()) }
4481 }
4482 pub fn as_array(&self) -> &[u8; 24usize] {
4483 unsafe { std::mem::transmute(self) }
4484 }
4485 pub fn from_array(buf: &[u8; 24usize]) -> &Self {
4486 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4487 unsafe { std::mem::transmute(buf) }
4488 }
4489 pub fn into_array(self) -> [u8; 24usize] {
4490 unsafe { std::mem::transmute(self) }
4491 }
4492 pub const fn len() -> usize {
4493 const _: () = assert!(std::mem::size_of::<TcMpls>() == 24usize);
4494 24usize
4495 }
4496}
4497#[repr(C, packed(4))]
4498pub struct TcPolice {
4499 pub index: u32,
4500 pub action: i32,
4501 pub limit: u32,
4502 pub burst: u32,
4503 pub mtu: u32,
4504 pub rate: TcRatespec,
4505 pub peakrate: TcRatespec,
4506 pub refcnt: i32,
4507 pub bindcnt: i32,
4508 pub capab: u32,
4509}
4510impl Clone for TcPolice {
4511 fn clone(&self) -> Self {
4512 Self::new_from_array(*self.as_array())
4513 }
4514}
4515#[doc = "Create zero-initialized struct"]
4516impl Default for TcPolice {
4517 fn default() -> Self {
4518 Self::new()
4519 }
4520}
4521impl TcPolice {
4522 #[doc = "Create zero-initialized struct"]
4523 pub fn new() -> Self {
4524 Self::new_from_array([0u8; Self::len()])
4525 }
4526 #[doc = "Copy from contents from slice"]
4527 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4528 if other.len() != Self::len() {
4529 return None;
4530 }
4531 let mut buf = [0u8; Self::len()];
4532 buf.clone_from_slice(other);
4533 Some(Self::new_from_array(buf))
4534 }
4535 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4536 pub fn new_from_zeroed(other: &[u8]) -> Self {
4537 let mut buf = [0u8; Self::len()];
4538 let len = buf.len().min(other.len());
4539 buf[..len].clone_from_slice(&other[..len]);
4540 Self::new_from_array(buf)
4541 }
4542 pub fn new_from_array(buf: [u8; 56usize]) -> Self {
4543 unsafe { std::mem::transmute(buf) }
4544 }
4545 pub fn as_slice(&self) -> &[u8] {
4546 unsafe {
4547 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4548 std::slice::from_raw_parts(ptr, Self::len())
4549 }
4550 }
4551 pub fn from_slice(buf: &[u8]) -> &Self {
4552 assert!(buf.len() >= Self::len());
4553 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4554 unsafe { std::mem::transmute(buf.as_ptr()) }
4555 }
4556 pub fn as_array(&self) -> &[u8; 56usize] {
4557 unsafe { std::mem::transmute(self) }
4558 }
4559 pub fn from_array(buf: &[u8; 56usize]) -> &Self {
4560 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4561 unsafe { std::mem::transmute(buf) }
4562 }
4563 pub fn into_array(self) -> [u8; 56usize] {
4564 unsafe { std::mem::transmute(self) }
4565 }
4566 pub const fn len() -> usize {
4567 const _: () = assert!(std::mem::size_of::<TcPolice>() == 56usize);
4568 56usize
4569 }
4570}
4571impl std::fmt::Debug for TcPolice {
4572 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4573 fmt.debug_struct("TcPolice")
4574 .field("index", &self.index)
4575 .field("action", &self.action)
4576 .field("limit", &self.limit)
4577 .field("burst", &self.burst)
4578 .field("mtu", &self.mtu)
4579 .field("rate", &self.rate)
4580 .field("peakrate", &self.peakrate)
4581 .field("refcnt", &self.refcnt)
4582 .field("bindcnt", &self.bindcnt)
4583 .field("capab", &self.capab)
4584 .finish()
4585 }
4586}
4587#[repr(C, packed(4))]
4588pub struct TcPeditSel {
4589 pub index: u32,
4590 pub capab: u32,
4591 pub action: i32,
4592 pub refcnt: i32,
4593 pub bindcnt: i32,
4594 pub nkeys: u8,
4595 pub flags: u8,
4596 pub _pad_22: [u8; 2usize],
4597 pub keys: TcPeditKey,
4598}
4599impl Clone for TcPeditSel {
4600 fn clone(&self) -> Self {
4601 Self::new_from_array(*self.as_array())
4602 }
4603}
4604#[doc = "Create zero-initialized struct"]
4605impl Default for TcPeditSel {
4606 fn default() -> Self {
4607 Self::new()
4608 }
4609}
4610impl TcPeditSel {
4611 #[doc = "Create zero-initialized struct"]
4612 pub fn new() -> Self {
4613 Self::new_from_array([0u8; Self::len()])
4614 }
4615 #[doc = "Copy from contents from slice"]
4616 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4617 if other.len() != Self::len() {
4618 return None;
4619 }
4620 let mut buf = [0u8; Self::len()];
4621 buf.clone_from_slice(other);
4622 Some(Self::new_from_array(buf))
4623 }
4624 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4625 pub fn new_from_zeroed(other: &[u8]) -> Self {
4626 let mut buf = [0u8; Self::len()];
4627 let len = buf.len().min(other.len());
4628 buf[..len].clone_from_slice(&other[..len]);
4629 Self::new_from_array(buf)
4630 }
4631 pub fn new_from_array(buf: [u8; 48usize]) -> Self {
4632 unsafe { std::mem::transmute(buf) }
4633 }
4634 pub fn as_slice(&self) -> &[u8] {
4635 unsafe {
4636 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4637 std::slice::from_raw_parts(ptr, Self::len())
4638 }
4639 }
4640 pub fn from_slice(buf: &[u8]) -> &Self {
4641 assert!(buf.len() >= Self::len());
4642 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4643 unsafe { std::mem::transmute(buf.as_ptr()) }
4644 }
4645 pub fn as_array(&self) -> &[u8; 48usize] {
4646 unsafe { std::mem::transmute(self) }
4647 }
4648 pub fn from_array(buf: &[u8; 48usize]) -> &Self {
4649 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4650 unsafe { std::mem::transmute(buf) }
4651 }
4652 pub fn into_array(self) -> [u8; 48usize] {
4653 unsafe { std::mem::transmute(self) }
4654 }
4655 pub const fn len() -> usize {
4656 const _: () = assert!(std::mem::size_of::<TcPeditSel>() == 48usize);
4657 48usize
4658 }
4659}
4660impl std::fmt::Debug for TcPeditSel {
4661 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4662 fmt.debug_struct("TcPeditSel")
4663 .field("index", &self.index)
4664 .field("capab", &self.capab)
4665 .field("action", &self.action)
4666 .field("refcnt", &self.refcnt)
4667 .field("bindcnt", &self.bindcnt)
4668 .field("nkeys", &self.nkeys)
4669 .field("flags", &self.flags)
4670 .field("keys", &self.keys)
4671 .finish()
4672 }
4673}
4674#[derive(Debug)]
4675#[repr(C, packed(4))]
4676pub struct TcPeditKey {
4677 pub mask: u32,
4678 pub val: u32,
4679 pub off: u32,
4680 pub at: u32,
4681 pub offmask: u32,
4682 pub shift: u32,
4683}
4684impl Clone for TcPeditKey {
4685 fn clone(&self) -> Self {
4686 Self::new_from_array(*self.as_array())
4687 }
4688}
4689#[doc = "Create zero-initialized struct"]
4690impl Default for TcPeditKey {
4691 fn default() -> Self {
4692 Self::new()
4693 }
4694}
4695impl TcPeditKey {
4696 #[doc = "Create zero-initialized struct"]
4697 pub fn new() -> Self {
4698 Self::new_from_array([0u8; Self::len()])
4699 }
4700 #[doc = "Copy from contents from slice"]
4701 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4702 if other.len() != Self::len() {
4703 return None;
4704 }
4705 let mut buf = [0u8; Self::len()];
4706 buf.clone_from_slice(other);
4707 Some(Self::new_from_array(buf))
4708 }
4709 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4710 pub fn new_from_zeroed(other: &[u8]) -> Self {
4711 let mut buf = [0u8; Self::len()];
4712 let len = buf.len().min(other.len());
4713 buf[..len].clone_from_slice(&other[..len]);
4714 Self::new_from_array(buf)
4715 }
4716 pub fn new_from_array(buf: [u8; 24usize]) -> Self {
4717 unsafe { std::mem::transmute(buf) }
4718 }
4719 pub fn as_slice(&self) -> &[u8] {
4720 unsafe {
4721 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4722 std::slice::from_raw_parts(ptr, Self::len())
4723 }
4724 }
4725 pub fn from_slice(buf: &[u8]) -> &Self {
4726 assert!(buf.len() >= Self::len());
4727 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4728 unsafe { std::mem::transmute(buf.as_ptr()) }
4729 }
4730 pub fn as_array(&self) -> &[u8; 24usize] {
4731 unsafe { std::mem::transmute(self) }
4732 }
4733 pub fn from_array(buf: &[u8; 24usize]) -> &Self {
4734 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4735 unsafe { std::mem::transmute(buf) }
4736 }
4737 pub fn into_array(self) -> [u8; 24usize] {
4738 unsafe { std::mem::transmute(self) }
4739 }
4740 pub const fn len() -> usize {
4741 const _: () = assert!(std::mem::size_of::<TcPeditKey>() == 24usize);
4742 24usize
4743 }
4744}
4745#[derive(Debug)]
4746#[repr(C, packed(4))]
4747pub struct TcVlan {
4748 pub index: u32,
4749 pub capab: u32,
4750 pub action: i32,
4751 pub refcnt: i32,
4752 pub bindcnt: i32,
4753 pub v_action: i32,
4754}
4755impl Clone for TcVlan {
4756 fn clone(&self) -> Self {
4757 Self::new_from_array(*self.as_array())
4758 }
4759}
4760#[doc = "Create zero-initialized struct"]
4761impl Default for TcVlan {
4762 fn default() -> Self {
4763 Self::new()
4764 }
4765}
4766impl TcVlan {
4767 #[doc = "Create zero-initialized struct"]
4768 pub fn new() -> Self {
4769 Self::new_from_array([0u8; Self::len()])
4770 }
4771 #[doc = "Copy from contents from slice"]
4772 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
4773 if other.len() != Self::len() {
4774 return None;
4775 }
4776 let mut buf = [0u8; Self::len()];
4777 buf.clone_from_slice(other);
4778 Some(Self::new_from_array(buf))
4779 }
4780 #[doc = "Copy from contents from another slice, padding with zeros or truncating when needed"]
4781 pub fn new_from_zeroed(other: &[u8]) -> Self {
4782 let mut buf = [0u8; Self::len()];
4783 let len = buf.len().min(other.len());
4784 buf[..len].clone_from_slice(&other[..len]);
4785 Self::new_from_array(buf)
4786 }
4787 pub fn new_from_array(buf: [u8; 24usize]) -> Self {
4788 unsafe { std::mem::transmute(buf) }
4789 }
4790 pub fn as_slice(&self) -> &[u8] {
4791 unsafe {
4792 let ptr: *const u8 = std::mem::transmute(self as *const Self);
4793 std::slice::from_raw_parts(ptr, Self::len())
4794 }
4795 }
4796 pub fn from_slice(buf: &[u8]) -> &Self {
4797 assert!(buf.len() >= Self::len());
4798 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4799 unsafe { std::mem::transmute(buf.as_ptr()) }
4800 }
4801 pub fn as_array(&self) -> &[u8; 24usize] {
4802 unsafe { std::mem::transmute(self) }
4803 }
4804 pub fn from_array(buf: &[u8; 24usize]) -> &Self {
4805 assert!(buf.as_ptr() as usize % std::mem::align_of::<Self>() == 0);
4806 unsafe { std::mem::transmute(buf) }
4807 }
4808 pub fn into_array(self) -> [u8; 24usize] {
4809 unsafe { std::mem::transmute(self) }
4810 }
4811 pub const fn len() -> usize {
4812 const _: () = assert!(std::mem::size_of::<TcVlan>() == 24usize);
4813 24usize
4814 }
4815}
4816#[derive(Clone)]
4817pub enum Attrs<'a> {
4818 Kind(&'a CStr),
4819 Options(OptionsMsg<'a>),
4820 Stats(TcStats),
4821 Xstats(TcaStatsAppMsg<'a>),
4822 Rate(GnetEstimator),
4823 Fcnt(u32),
4824 Stats2(IterableTcaStatsAttrs<'a>),
4825 Stab(IterableTcaStabAttrs<'a>),
4826 Pad(&'a [u8]),
4827 DumpInvisible(()),
4828 Chain(u32),
4829 HwOffload(u8),
4830 IngressBlock(u32),
4831 EgressBlock(u32),
4832 DumpFlags(BuiltinBitfield32),
4833 ExtWarnMsg(&'a CStr),
4834}
4835impl<'a> IterableAttrs<'a> {
4836 pub fn get_kind(&self) -> Result<&'a CStr, ErrorContext> {
4837 let mut iter = self.clone();
4838 iter.pos = 0;
4839 for attr in iter {
4840 if let Ok(Attrs::Kind(val)) = attr {
4841 return Ok(val);
4842 }
4843 }
4844 Err(ErrorContext::new_missing(
4845 "Attrs",
4846 "Kind",
4847 self.orig_loc,
4848 self.buf.as_ptr() as usize,
4849 ))
4850 }
4851 pub fn get_options(&self) -> Result<OptionsMsg<'a>, ErrorContext> {
4852 let mut iter = self.clone();
4853 iter.pos = 0;
4854 for attr in iter {
4855 if let Ok(Attrs::Options(val)) = attr {
4856 return Ok(val);
4857 }
4858 }
4859 Err(ErrorContext::new_missing(
4860 "Attrs",
4861 "Options",
4862 self.orig_loc,
4863 self.buf.as_ptr() as usize,
4864 ))
4865 }
4866 pub fn get_stats(&self) -> Result<TcStats, ErrorContext> {
4867 let mut iter = self.clone();
4868 iter.pos = 0;
4869 for attr in iter {
4870 if let Ok(Attrs::Stats(val)) = attr {
4871 return Ok(val);
4872 }
4873 }
4874 Err(ErrorContext::new_missing(
4875 "Attrs",
4876 "Stats",
4877 self.orig_loc,
4878 self.buf.as_ptr() as usize,
4879 ))
4880 }
4881 pub fn get_xstats(&self) -> Result<TcaStatsAppMsg<'a>, ErrorContext> {
4882 let mut iter = self.clone();
4883 iter.pos = 0;
4884 for attr in iter {
4885 if let Ok(Attrs::Xstats(val)) = attr {
4886 return Ok(val);
4887 }
4888 }
4889 Err(ErrorContext::new_missing(
4890 "Attrs",
4891 "Xstats",
4892 self.orig_loc,
4893 self.buf.as_ptr() as usize,
4894 ))
4895 }
4896 pub fn get_rate(&self) -> Result<GnetEstimator, ErrorContext> {
4897 let mut iter = self.clone();
4898 iter.pos = 0;
4899 for attr in iter {
4900 if let Ok(Attrs::Rate(val)) = attr {
4901 return Ok(val);
4902 }
4903 }
4904 Err(ErrorContext::new_missing(
4905 "Attrs",
4906 "Rate",
4907 self.orig_loc,
4908 self.buf.as_ptr() as usize,
4909 ))
4910 }
4911 pub fn get_fcnt(&self) -> Result<u32, ErrorContext> {
4912 let mut iter = self.clone();
4913 iter.pos = 0;
4914 for attr in iter {
4915 if let Ok(Attrs::Fcnt(val)) = attr {
4916 return Ok(val);
4917 }
4918 }
4919 Err(ErrorContext::new_missing(
4920 "Attrs",
4921 "Fcnt",
4922 self.orig_loc,
4923 self.buf.as_ptr() as usize,
4924 ))
4925 }
4926 pub fn get_stats2(&self) -> Result<IterableTcaStatsAttrs<'a>, ErrorContext> {
4927 let mut iter = self.clone();
4928 iter.pos = 0;
4929 for attr in iter {
4930 if let Ok(Attrs::Stats2(val)) = attr {
4931 return Ok(val);
4932 }
4933 }
4934 Err(ErrorContext::new_missing(
4935 "Attrs",
4936 "Stats2",
4937 self.orig_loc,
4938 self.buf.as_ptr() as usize,
4939 ))
4940 }
4941 pub fn get_stab(&self) -> Result<IterableTcaStabAttrs<'a>, ErrorContext> {
4942 let mut iter = self.clone();
4943 iter.pos = 0;
4944 for attr in iter {
4945 if let Ok(Attrs::Stab(val)) = attr {
4946 return Ok(val);
4947 }
4948 }
4949 Err(ErrorContext::new_missing(
4950 "Attrs",
4951 "Stab",
4952 self.orig_loc,
4953 self.buf.as_ptr() as usize,
4954 ))
4955 }
4956 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
4957 let mut iter = self.clone();
4958 iter.pos = 0;
4959 for attr in iter {
4960 if let Ok(Attrs::Pad(val)) = attr {
4961 return Ok(val);
4962 }
4963 }
4964 Err(ErrorContext::new_missing(
4965 "Attrs",
4966 "Pad",
4967 self.orig_loc,
4968 self.buf.as_ptr() as usize,
4969 ))
4970 }
4971 pub fn get_dump_invisible(&self) -> Result<(), ErrorContext> {
4972 let mut iter = self.clone();
4973 iter.pos = 0;
4974 for attr in iter {
4975 if let Ok(Attrs::DumpInvisible(val)) = attr {
4976 return Ok(val);
4977 }
4978 }
4979 Err(ErrorContext::new_missing(
4980 "Attrs",
4981 "DumpInvisible",
4982 self.orig_loc,
4983 self.buf.as_ptr() as usize,
4984 ))
4985 }
4986 pub fn get_chain(&self) -> Result<u32, ErrorContext> {
4987 let mut iter = self.clone();
4988 iter.pos = 0;
4989 for attr in iter {
4990 if let Ok(Attrs::Chain(val)) = attr {
4991 return Ok(val);
4992 }
4993 }
4994 Err(ErrorContext::new_missing(
4995 "Attrs",
4996 "Chain",
4997 self.orig_loc,
4998 self.buf.as_ptr() as usize,
4999 ))
5000 }
5001 pub fn get_hw_offload(&self) -> Result<u8, ErrorContext> {
5002 let mut iter = self.clone();
5003 iter.pos = 0;
5004 for attr in iter {
5005 if let Ok(Attrs::HwOffload(val)) = attr {
5006 return Ok(val);
5007 }
5008 }
5009 Err(ErrorContext::new_missing(
5010 "Attrs",
5011 "HwOffload",
5012 self.orig_loc,
5013 self.buf.as_ptr() as usize,
5014 ))
5015 }
5016 pub fn get_ingress_block(&self) -> Result<u32, ErrorContext> {
5017 let mut iter = self.clone();
5018 iter.pos = 0;
5019 for attr in iter {
5020 if let Ok(Attrs::IngressBlock(val)) = attr {
5021 return Ok(val);
5022 }
5023 }
5024 Err(ErrorContext::new_missing(
5025 "Attrs",
5026 "IngressBlock",
5027 self.orig_loc,
5028 self.buf.as_ptr() as usize,
5029 ))
5030 }
5031 pub fn get_egress_block(&self) -> Result<u32, ErrorContext> {
5032 let mut iter = self.clone();
5033 iter.pos = 0;
5034 for attr in iter {
5035 if let Ok(Attrs::EgressBlock(val)) = attr {
5036 return Ok(val);
5037 }
5038 }
5039 Err(ErrorContext::new_missing(
5040 "Attrs",
5041 "EgressBlock",
5042 self.orig_loc,
5043 self.buf.as_ptr() as usize,
5044 ))
5045 }
5046 pub fn get_dump_flags(&self) -> Result<BuiltinBitfield32, ErrorContext> {
5047 let mut iter = self.clone();
5048 iter.pos = 0;
5049 for attr in iter {
5050 if let Ok(Attrs::DumpFlags(val)) = attr {
5051 return Ok(val);
5052 }
5053 }
5054 Err(ErrorContext::new_missing(
5055 "Attrs",
5056 "DumpFlags",
5057 self.orig_loc,
5058 self.buf.as_ptr() as usize,
5059 ))
5060 }
5061 pub fn get_ext_warn_msg(&self) -> Result<&'a CStr, ErrorContext> {
5062 let mut iter = self.clone();
5063 iter.pos = 0;
5064 for attr in iter {
5065 if let Ok(Attrs::ExtWarnMsg(val)) = attr {
5066 return Ok(val);
5067 }
5068 }
5069 Err(ErrorContext::new_missing(
5070 "Attrs",
5071 "ExtWarnMsg",
5072 self.orig_loc,
5073 self.buf.as_ptr() as usize,
5074 ))
5075 }
5076}
5077#[derive(Debug, Clone)]
5078pub enum OptionsMsg<'a> {
5079 Basic(IterableBasicAttrs<'a>),
5080 Bpf(IterableBpfAttrs<'a>),
5081 Bfifo(TcFifoQopt),
5082 Cake(IterableCakeAttrs<'a>),
5083 Cbs(IterableCbsAttrs<'a>),
5084 Cgroup(IterableCgroupAttrs<'a>),
5085 Choke(IterableChokeAttrs<'a>),
5086 Clsact,
5087 Codel(IterableCodelAttrs<'a>),
5088 Drr(IterableDrrAttrs<'a>),
5089 Dualpi2(IterableDualpi2Attrs<'a>),
5090 Etf(IterableEtfAttrs<'a>),
5091 Ets(IterableEtsAttrs<'a>),
5092 Flow(IterableFlowAttrs<'a>),
5093 Flower(IterableFlowerAttrs<'a>),
5094 Fq(IterableFqAttrs<'a>),
5095 FqCodel(IterableFqCodelAttrs<'a>),
5096 FqPie(IterableFqPieAttrs<'a>),
5097 Fw(IterableFwAttrs<'a>),
5098 Gred(IterableGredAttrs<'a>),
5099 Hfsc(TcHfscQopt),
5100 Hhf(IterableHhfAttrs<'a>),
5101 Htb(IterableHtbAttrs<'a>),
5102 Ingress,
5103 Matchall(IterableMatchallAttrs<'a>),
5104 Mq,
5105 Mqprio(TcMqprioQopt),
5106 Multiq(TcMultiqQopt),
5107 Netem(TcNetemQopt, IterableNetemAttrs<'a>),
5108 Pfifo(TcFifoQopt),
5109 PfifoFast(TcPrioQopt),
5110 PfifoHeadDrop(TcFifoQopt),
5111 Pie(IterablePieAttrs<'a>),
5112 Plug(TcPlugQopt),
5113 Prio(TcPrioQopt),
5114 Qfq(IterableQfqAttrs<'a>),
5115 Red(IterableRedAttrs<'a>),
5116 Route(IterableRouteAttrs<'a>),
5117 Sfb(TcSfbQopt),
5118 Sfq(TcSfqQoptV1),
5119 Taprio(IterableTaprioAttrs<'a>),
5120 Tbf(IterableTbfAttrs<'a>),
5121 U32(IterableU32Attrs<'a>),
5122}
5123impl<'a> OptionsMsg<'a> {
5124 fn select_with_loc(selector: &'a CStr, buf: &'a [u8], loc: usize) -> Option<Self> {
5125 match selector.to_bytes() {
5126 b"basic" => Some(OptionsMsg::Basic(IterableBasicAttrs::with_loc(buf, loc))),
5127 b"bpf" => Some(OptionsMsg::Bpf(IterableBpfAttrs::with_loc(buf, loc))),
5128 b"bfifo" => Some(OptionsMsg::Bfifo(TcFifoQopt::new_from_zeroed(buf))),
5129 b"cake" => Some(OptionsMsg::Cake(IterableCakeAttrs::with_loc(buf, loc))),
5130 b"cbs" => Some(OptionsMsg::Cbs(IterableCbsAttrs::with_loc(buf, loc))),
5131 b"cgroup" => Some(OptionsMsg::Cgroup(IterableCgroupAttrs::with_loc(buf, loc))),
5132 b"choke" => Some(OptionsMsg::Choke(IterableChokeAttrs::with_loc(buf, loc))),
5133 b"clsact" => Some(OptionsMsg::Clsact),
5134 b"codel" => Some(OptionsMsg::Codel(IterableCodelAttrs::with_loc(buf, loc))),
5135 b"drr" => Some(OptionsMsg::Drr(IterableDrrAttrs::with_loc(buf, loc))),
5136 b"dualpi2" => Some(OptionsMsg::Dualpi2(IterableDualpi2Attrs::with_loc(
5137 buf, loc,
5138 ))),
5139 b"etf" => Some(OptionsMsg::Etf(IterableEtfAttrs::with_loc(buf, loc))),
5140 b"ets" => Some(OptionsMsg::Ets(IterableEtsAttrs::with_loc(buf, loc))),
5141 b"flow" => Some(OptionsMsg::Flow(IterableFlowAttrs::with_loc(buf, loc))),
5142 b"flower" => Some(OptionsMsg::Flower(IterableFlowerAttrs::with_loc(buf, loc))),
5143 b"fq" => Some(OptionsMsg::Fq(IterableFqAttrs::with_loc(buf, loc))),
5144 b"fq_codel" => Some(OptionsMsg::FqCodel(IterableFqCodelAttrs::with_loc(
5145 buf, loc,
5146 ))),
5147 b"fq_pie" => Some(OptionsMsg::FqPie(IterableFqPieAttrs::with_loc(buf, loc))),
5148 b"fw" => Some(OptionsMsg::Fw(IterableFwAttrs::with_loc(buf, loc))),
5149 b"gred" => Some(OptionsMsg::Gred(IterableGredAttrs::with_loc(buf, loc))),
5150 b"hfsc" => Some(OptionsMsg::Hfsc(TcHfscQopt::new_from_zeroed(buf))),
5151 b"hhf" => Some(OptionsMsg::Hhf(IterableHhfAttrs::with_loc(buf, loc))),
5152 b"htb" => Some(OptionsMsg::Htb(IterableHtbAttrs::with_loc(buf, loc))),
5153 b"ingress" => Some(OptionsMsg::Ingress),
5154 b"matchall" => Some(OptionsMsg::Matchall(IterableMatchallAttrs::with_loc(
5155 buf, loc,
5156 ))),
5157 b"mq" => Some(OptionsMsg::Mq),
5158 b"mqprio" => Some(OptionsMsg::Mqprio(TcMqprioQopt::new_from_zeroed(buf))),
5159 b"multiq" => Some(OptionsMsg::Multiq(TcMultiqQopt::new_from_zeroed(buf))),
5160 b"netem" => {
5161 let (header, attrs) = buf.split_at(buf.len().min(TcNetemQopt::len()));
5162 Some(OptionsMsg::Netem(
5163 TcNetemQopt::new_from_slice(header)?,
5164 IterableNetemAttrs::with_loc(attrs, loc),
5165 ))
5166 }
5167 b"pfifo" => Some(OptionsMsg::Pfifo(TcFifoQopt::new_from_zeroed(buf))),
5168 b"pfifo_fast" => Some(OptionsMsg::PfifoFast(TcPrioQopt::new_from_zeroed(buf))),
5169 b"pfifo_head_drop" => Some(OptionsMsg::PfifoHeadDrop(TcFifoQopt::new_from_zeroed(buf))),
5170 b"pie" => Some(OptionsMsg::Pie(IterablePieAttrs::with_loc(buf, loc))),
5171 b"plug" => Some(OptionsMsg::Plug(TcPlugQopt::new_from_zeroed(buf))),
5172 b"prio" => Some(OptionsMsg::Prio(TcPrioQopt::new_from_zeroed(buf))),
5173 b"qfq" => Some(OptionsMsg::Qfq(IterableQfqAttrs::with_loc(buf, loc))),
5174 b"red" => Some(OptionsMsg::Red(IterableRedAttrs::with_loc(buf, loc))),
5175 b"route" => Some(OptionsMsg::Route(IterableRouteAttrs::with_loc(buf, loc))),
5176 b"sfb" => Some(OptionsMsg::Sfb(TcSfbQopt::new_from_zeroed(buf))),
5177 b"sfq" => Some(OptionsMsg::Sfq(TcSfqQoptV1::new_from_zeroed(buf))),
5178 b"taprio" => Some(OptionsMsg::Taprio(IterableTaprioAttrs::with_loc(buf, loc))),
5179 b"tbf" => Some(OptionsMsg::Tbf(IterableTbfAttrs::with_loc(buf, loc))),
5180 b"u32" => Some(OptionsMsg::U32(IterableU32Attrs::with_loc(buf, loc))),
5181 _ => None,
5182 }
5183 }
5184}
5185#[derive(Debug, Clone)]
5186pub enum TcaStatsAppMsg<'a> {
5187 Cake(IterableCakeStatsAttrs<'a>),
5188 Choke(TcChokeXstats),
5189 Codel(TcCodelXstats),
5190 Dualpi2(TcDualpi2Xstats),
5191 Fq(TcFqQdStats),
5192 FqCodel(TcFqCodelXstats),
5193 FqPie(TcFqPieXstats),
5194 Hhf(TcHhfXstats),
5195 Pie(TcPieXstats),
5196 Red(TcRedXstats),
5197 Sfb(TcSfbXstats),
5198 Sfq(TcSfqXstats),
5199}
5200impl<'a> TcaStatsAppMsg<'a> {
5201 fn select_with_loc(selector: &'a CStr, buf: &'a [u8], loc: usize) -> Option<Self> {
5202 match selector.to_bytes() {
5203 b"cake" => Some(TcaStatsAppMsg::Cake(IterableCakeStatsAttrs::with_loc(
5204 buf, loc,
5205 ))),
5206 b"choke" => Some(TcaStatsAppMsg::Choke(TcChokeXstats::new_from_zeroed(buf))),
5207 b"codel" => Some(TcaStatsAppMsg::Codel(TcCodelXstats::new_from_zeroed(buf))),
5208 b"dualpi2" => Some(TcaStatsAppMsg::Dualpi2(TcDualpi2Xstats::new_from_zeroed(
5209 buf,
5210 ))),
5211 b"fq" => Some(TcaStatsAppMsg::Fq(TcFqQdStats::new_from_zeroed(buf))),
5212 b"fq_codel" => Some(TcaStatsAppMsg::FqCodel(TcFqCodelXstats::new_from_zeroed(
5213 buf,
5214 ))),
5215 b"fq_pie" => Some(TcaStatsAppMsg::FqPie(TcFqPieXstats::new_from_zeroed(buf))),
5216 b"hhf" => Some(TcaStatsAppMsg::Hhf(TcHhfXstats::new_from_zeroed(buf))),
5217 b"pie" => Some(TcaStatsAppMsg::Pie(TcPieXstats::new_from_zeroed(buf))),
5218 b"red" => Some(TcaStatsAppMsg::Red(TcRedXstats::new_from_zeroed(buf))),
5219 b"sfb" => Some(TcaStatsAppMsg::Sfb(TcSfbXstats::new_from_zeroed(buf))),
5220 b"sfq" => Some(TcaStatsAppMsg::Sfq(TcSfqXstats::new_from_zeroed(buf))),
5221 _ => None,
5222 }
5223 }
5224}
5225impl Attrs<'_> {
5226 pub fn new<'a>(buf: &'a [u8]) -> IterableAttrs<'a> {
5227 IterableAttrs::with_loc(buf, buf.as_ptr() as usize)
5228 }
5229 fn attr_from_type(r#type: u16) -> Option<&'static str> {
5230 let res = match r#type {
5231 1u16 => "Kind",
5232 2u16 => "Options",
5233 3u16 => "Stats",
5234 4u16 => "Xstats",
5235 5u16 => "Rate",
5236 6u16 => "Fcnt",
5237 7u16 => "Stats2",
5238 8u16 => "Stab",
5239 9u16 => "Pad",
5240 10u16 => "DumpInvisible",
5241 11u16 => "Chain",
5242 12u16 => "HwOffload",
5243 13u16 => "IngressBlock",
5244 14u16 => "EgressBlock",
5245 15u16 => "DumpFlags",
5246 16u16 => "ExtWarnMsg",
5247 _ => return None,
5248 };
5249 Some(res)
5250 }
5251}
5252#[derive(Clone, Copy, Default)]
5253pub struct IterableAttrs<'a> {
5254 buf: &'a [u8],
5255 pos: usize,
5256 orig_loc: usize,
5257}
5258impl<'a> IterableAttrs<'a> {
5259 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5260 Self {
5261 buf,
5262 pos: 0,
5263 orig_loc,
5264 }
5265 }
5266 pub fn get_buf(&self) -> &'a [u8] {
5267 self.buf
5268 }
5269}
5270impl<'a> Iterator for IterableAttrs<'a> {
5271 type Item = Result<Attrs<'a>, ErrorContext>;
5272 fn next(&mut self) -> Option<Self::Item> {
5273 let mut pos;
5274 let mut r#type;
5275 loop {
5276 pos = self.pos;
5277 r#type = None;
5278 if self.buf.len() == self.pos {
5279 return None;
5280 }
5281 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
5282 self.pos = self.buf.len();
5283 break;
5284 };
5285 r#type = Some(header.r#type);
5286 let res = match header.r#type {
5287 1u16 => Attrs::Kind({
5288 let res = CStr::from_bytes_with_nul(next).ok();
5289 let Some(val) = res else { break };
5290 val
5291 }),
5292 2u16 => Attrs::Options({
5293 let res = {
5294 let Ok(selector) = self.get_kind() else { break };
5295 match OptionsMsg::select_with_loc(selector, next, self.orig_loc) {
5296 Some(sub) => Some(sub),
5297 None if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
5298 None => continue,
5299 }
5300 };
5301 let Some(val) = res else { break };
5302 val
5303 }),
5304 3u16 => Attrs::Stats({
5305 let res = Some(TcStats::new_from_zeroed(next));
5306 let Some(val) = res else { break };
5307 val
5308 }),
5309 4u16 => Attrs::Xstats({
5310 let res = {
5311 let Ok(selector) = self.get_kind() else { break };
5312 match TcaStatsAppMsg::select_with_loc(selector, next, self.orig_loc) {
5313 Some(sub) => Some(sub),
5314 None if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
5315 None => continue,
5316 }
5317 };
5318 let Some(val) = res else { break };
5319 val
5320 }),
5321 5u16 => Attrs::Rate({
5322 let res = Some(GnetEstimator::new_from_zeroed(next));
5323 let Some(val) = res else { break };
5324 val
5325 }),
5326 6u16 => Attrs::Fcnt({
5327 let res = parse_u32(next);
5328 let Some(val) = res else { break };
5329 val
5330 }),
5331 7u16 => Attrs::Stats2({
5332 let res = Some(IterableTcaStatsAttrs::with_loc(next, self.orig_loc));
5333 let Some(val) = res else { break };
5334 val
5335 }),
5336 8u16 => Attrs::Stab({
5337 let res = Some(IterableTcaStabAttrs::with_loc(next, self.orig_loc));
5338 let Some(val) = res else { break };
5339 val
5340 }),
5341 9u16 => Attrs::Pad({
5342 let res = Some(next);
5343 let Some(val) = res else { break };
5344 val
5345 }),
5346 10u16 => Attrs::DumpInvisible(()),
5347 11u16 => Attrs::Chain({
5348 let res = parse_u32(next);
5349 let Some(val) = res else { break };
5350 val
5351 }),
5352 12u16 => Attrs::HwOffload({
5353 let res = parse_u8(next);
5354 let Some(val) = res else { break };
5355 val
5356 }),
5357 13u16 => Attrs::IngressBlock({
5358 let res = parse_u32(next);
5359 let Some(val) = res else { break };
5360 val
5361 }),
5362 14u16 => Attrs::EgressBlock({
5363 let res = parse_u32(next);
5364 let Some(val) = res else { break };
5365 val
5366 }),
5367 15u16 => Attrs::DumpFlags({
5368 let res = BuiltinBitfield32::new_from_slice(next);
5369 let Some(val) = res else { break };
5370 val
5371 }),
5372 16u16 => Attrs::ExtWarnMsg({
5373 let res = CStr::from_bytes_with_nul(next).ok();
5374 let Some(val) = res else { break };
5375 val
5376 }),
5377 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
5378 n => continue,
5379 };
5380 return Some(Ok(res));
5381 }
5382 Some(Err(ErrorContext::new(
5383 "Attrs",
5384 r#type.and_then(|t| Attrs::attr_from_type(t)),
5385 self.orig_loc,
5386 self.buf.as_ptr().wrapping_add(pos) as usize,
5387 )))
5388 }
5389}
5390impl<'a> std::fmt::Debug for IterableAttrs<'_> {
5391 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5392 let mut fmt = f.debug_struct("Attrs");
5393 for attr in self.clone() {
5394 let attr = match attr {
5395 Ok(a) => a,
5396 Err(err) => {
5397 fmt.finish()?;
5398 f.write_str("Err(")?;
5399 err.fmt(f)?;
5400 return f.write_str(")");
5401 }
5402 };
5403 match attr {
5404 Attrs::Kind(val) => fmt.field("Kind", &val),
5405 Attrs::Options(val) => fmt.field("Options", &val),
5406 Attrs::Stats(val) => fmt.field("Stats", &val),
5407 Attrs::Xstats(val) => fmt.field("Xstats", &val),
5408 Attrs::Rate(val) => fmt.field("Rate", &val),
5409 Attrs::Fcnt(val) => fmt.field("Fcnt", &val),
5410 Attrs::Stats2(val) => fmt.field("Stats2", &val),
5411 Attrs::Stab(val) => fmt.field("Stab", &val),
5412 Attrs::Pad(val) => fmt.field("Pad", &val),
5413 Attrs::DumpInvisible(val) => fmt.field("DumpInvisible", &val),
5414 Attrs::Chain(val) => fmt.field("Chain", &val),
5415 Attrs::HwOffload(val) => fmt.field("HwOffload", &val),
5416 Attrs::IngressBlock(val) => fmt.field("IngressBlock", &val),
5417 Attrs::EgressBlock(val) => fmt.field("EgressBlock", &val),
5418 Attrs::DumpFlags(val) => fmt.field("DumpFlags", &val),
5419 Attrs::ExtWarnMsg(val) => fmt.field("ExtWarnMsg", &val),
5420 };
5421 }
5422 fmt.finish()
5423 }
5424}
5425impl IterableAttrs<'_> {
5426 pub fn lookup_attr(
5427 &self,
5428 offset: usize,
5429 missing_type: Option<u16>,
5430 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5431 let mut stack = Vec::new();
5432 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
5433 if missing_type.is_some() && cur == offset {
5434 stack.push(("Attrs", offset));
5435 return (stack, missing_type.and_then(|t| Attrs::attr_from_type(t)));
5436 }
5437 if cur > offset || cur + self.buf.len() < offset {
5438 return (stack, None);
5439 }
5440 let mut attrs = self.clone();
5441 let mut last_off = cur + attrs.pos;
5442 let mut missing = None;
5443 while let Some(attr) = attrs.next() {
5444 let Ok(attr) = attr else { break };
5445 match attr {
5446 Attrs::Kind(val) => {
5447 if last_off == offset {
5448 stack.push(("Kind", last_off));
5449 break;
5450 }
5451 }
5452 Attrs::Options(val) => {
5453 if last_off == offset {
5454 stack.push(("Options", last_off));
5455 break;
5456 }
5457 }
5458 Attrs::Stats(val) => {
5459 if last_off == offset {
5460 stack.push(("Stats", last_off));
5461 break;
5462 }
5463 }
5464 Attrs::Xstats(val) => {
5465 if last_off == offset {
5466 stack.push(("Xstats", last_off));
5467 break;
5468 }
5469 }
5470 Attrs::Rate(val) => {
5471 if last_off == offset {
5472 stack.push(("Rate", last_off));
5473 break;
5474 }
5475 }
5476 Attrs::Fcnt(val) => {
5477 if last_off == offset {
5478 stack.push(("Fcnt", last_off));
5479 break;
5480 }
5481 }
5482 Attrs::Stats2(val) => {
5483 (stack, missing) = val.lookup_attr(offset, missing_type);
5484 if !stack.is_empty() {
5485 break;
5486 }
5487 }
5488 Attrs::Stab(val) => {
5489 (stack, missing) = val.lookup_attr(offset, missing_type);
5490 if !stack.is_empty() {
5491 break;
5492 }
5493 }
5494 Attrs::Pad(val) => {
5495 if last_off == offset {
5496 stack.push(("Pad", last_off));
5497 break;
5498 }
5499 }
5500 Attrs::DumpInvisible(val) => {
5501 if last_off == offset {
5502 stack.push(("DumpInvisible", last_off));
5503 break;
5504 }
5505 }
5506 Attrs::Chain(val) => {
5507 if last_off == offset {
5508 stack.push(("Chain", last_off));
5509 break;
5510 }
5511 }
5512 Attrs::HwOffload(val) => {
5513 if last_off == offset {
5514 stack.push(("HwOffload", last_off));
5515 break;
5516 }
5517 }
5518 Attrs::IngressBlock(val) => {
5519 if last_off == offset {
5520 stack.push(("IngressBlock", last_off));
5521 break;
5522 }
5523 }
5524 Attrs::EgressBlock(val) => {
5525 if last_off == offset {
5526 stack.push(("EgressBlock", last_off));
5527 break;
5528 }
5529 }
5530 Attrs::DumpFlags(val) => {
5531 if last_off == offset {
5532 stack.push(("DumpFlags", last_off));
5533 break;
5534 }
5535 }
5536 Attrs::ExtWarnMsg(val) => {
5537 if last_off == offset {
5538 stack.push(("ExtWarnMsg", last_off));
5539 break;
5540 }
5541 }
5542 _ => {}
5543 };
5544 last_off = cur + attrs.pos;
5545 }
5546 if !stack.is_empty() {
5547 stack.push(("Attrs", cur));
5548 }
5549 (stack, missing)
5550 }
5551}
5552#[derive(Clone)]
5553pub enum ActAttrs<'a> {
5554 Kind(&'a CStr),
5555 Options(ActOptionsMsg<'a>),
5556 Index(u32),
5557 Stats(IterableTcaStatsAttrs<'a>),
5558 Pad(&'a [u8]),
5559 Cookie(&'a [u8]),
5560 Flags(BuiltinBitfield32),
5561 HwStats(BuiltinBitfield32),
5562 UsedHwStats(BuiltinBitfield32),
5563 InHwCount(u32),
5564}
5565impl<'a> IterableActAttrs<'a> {
5566 pub fn get_kind(&self) -> Result<&'a CStr, ErrorContext> {
5567 let mut iter = self.clone();
5568 iter.pos = 0;
5569 for attr in iter {
5570 if let Ok(ActAttrs::Kind(val)) = attr {
5571 return Ok(val);
5572 }
5573 }
5574 Err(ErrorContext::new_missing(
5575 "ActAttrs",
5576 "Kind",
5577 self.orig_loc,
5578 self.buf.as_ptr() as usize,
5579 ))
5580 }
5581 pub fn get_options(&self) -> Result<ActOptionsMsg<'a>, ErrorContext> {
5582 let mut iter = self.clone();
5583 iter.pos = 0;
5584 for attr in iter {
5585 if let Ok(ActAttrs::Options(val)) = attr {
5586 return Ok(val);
5587 }
5588 }
5589 Err(ErrorContext::new_missing(
5590 "ActAttrs",
5591 "Options",
5592 self.orig_loc,
5593 self.buf.as_ptr() as usize,
5594 ))
5595 }
5596 pub fn get_index(&self) -> Result<u32, ErrorContext> {
5597 let mut iter = self.clone();
5598 iter.pos = 0;
5599 for attr in iter {
5600 if let Ok(ActAttrs::Index(val)) = attr {
5601 return Ok(val);
5602 }
5603 }
5604 Err(ErrorContext::new_missing(
5605 "ActAttrs",
5606 "Index",
5607 self.orig_loc,
5608 self.buf.as_ptr() as usize,
5609 ))
5610 }
5611 pub fn get_stats(&self) -> Result<IterableTcaStatsAttrs<'a>, ErrorContext> {
5612 let mut iter = self.clone();
5613 iter.pos = 0;
5614 for attr in iter {
5615 if let Ok(ActAttrs::Stats(val)) = attr {
5616 return Ok(val);
5617 }
5618 }
5619 Err(ErrorContext::new_missing(
5620 "ActAttrs",
5621 "Stats",
5622 self.orig_loc,
5623 self.buf.as_ptr() as usize,
5624 ))
5625 }
5626 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
5627 let mut iter = self.clone();
5628 iter.pos = 0;
5629 for attr in iter {
5630 if let Ok(ActAttrs::Pad(val)) = attr {
5631 return Ok(val);
5632 }
5633 }
5634 Err(ErrorContext::new_missing(
5635 "ActAttrs",
5636 "Pad",
5637 self.orig_loc,
5638 self.buf.as_ptr() as usize,
5639 ))
5640 }
5641 pub fn get_cookie(&self) -> Result<&'a [u8], ErrorContext> {
5642 let mut iter = self.clone();
5643 iter.pos = 0;
5644 for attr in iter {
5645 if let Ok(ActAttrs::Cookie(val)) = attr {
5646 return Ok(val);
5647 }
5648 }
5649 Err(ErrorContext::new_missing(
5650 "ActAttrs",
5651 "Cookie",
5652 self.orig_loc,
5653 self.buf.as_ptr() as usize,
5654 ))
5655 }
5656 pub fn get_flags(&self) -> Result<BuiltinBitfield32, ErrorContext> {
5657 let mut iter = self.clone();
5658 iter.pos = 0;
5659 for attr in iter {
5660 if let Ok(ActAttrs::Flags(val)) = attr {
5661 return Ok(val);
5662 }
5663 }
5664 Err(ErrorContext::new_missing(
5665 "ActAttrs",
5666 "Flags",
5667 self.orig_loc,
5668 self.buf.as_ptr() as usize,
5669 ))
5670 }
5671 pub fn get_hw_stats(&self) -> Result<BuiltinBitfield32, ErrorContext> {
5672 let mut iter = self.clone();
5673 iter.pos = 0;
5674 for attr in iter {
5675 if let Ok(ActAttrs::HwStats(val)) = attr {
5676 return Ok(val);
5677 }
5678 }
5679 Err(ErrorContext::new_missing(
5680 "ActAttrs",
5681 "HwStats",
5682 self.orig_loc,
5683 self.buf.as_ptr() as usize,
5684 ))
5685 }
5686 pub fn get_used_hw_stats(&self) -> Result<BuiltinBitfield32, ErrorContext> {
5687 let mut iter = self.clone();
5688 iter.pos = 0;
5689 for attr in iter {
5690 if let Ok(ActAttrs::UsedHwStats(val)) = attr {
5691 return Ok(val);
5692 }
5693 }
5694 Err(ErrorContext::new_missing(
5695 "ActAttrs",
5696 "UsedHwStats",
5697 self.orig_loc,
5698 self.buf.as_ptr() as usize,
5699 ))
5700 }
5701 pub fn get_in_hw_count(&self) -> Result<u32, ErrorContext> {
5702 let mut iter = self.clone();
5703 iter.pos = 0;
5704 for attr in iter {
5705 if let Ok(ActAttrs::InHwCount(val)) = attr {
5706 return Ok(val);
5707 }
5708 }
5709 Err(ErrorContext::new_missing(
5710 "ActAttrs",
5711 "InHwCount",
5712 self.orig_loc,
5713 self.buf.as_ptr() as usize,
5714 ))
5715 }
5716}
5717#[derive(Debug, Clone)]
5718pub enum ActOptionsMsg<'a> {
5719 Bpf(IterableActBpfAttrs<'a>),
5720 Connmark(IterableActConnmarkAttrs<'a>),
5721 Csum(IterableActCsumAttrs<'a>),
5722 Ct(IterableActCtAttrs<'a>),
5723 Ctinfo(IterableActCtinfoAttrs<'a>),
5724 Gact(IterableActGactAttrs<'a>),
5725 Gate(IterableActGateAttrs<'a>),
5726 Ife(IterableActIfeAttrs<'a>),
5727 Mirred(IterableActMirredAttrs<'a>),
5728 Mpls(IterableActMplsAttrs<'a>),
5729 Nat(IterableActNatAttrs<'a>),
5730 Pedit(IterableActPeditAttrs<'a>),
5731 Police(IterablePoliceAttrs<'a>),
5732 Sample(IterableActSampleAttrs<'a>),
5733 Simple(IterableActSimpleAttrs<'a>),
5734 Skbedit(IterableActSkbeditAttrs<'a>),
5735 Skbmod(IterableActSkbmodAttrs<'a>),
5736 TunnelKey(IterableActTunnelKeyAttrs<'a>),
5737 Vlan(IterableActVlanAttrs<'a>),
5738}
5739impl<'a> ActOptionsMsg<'a> {
5740 fn select_with_loc(selector: &'a CStr, buf: &'a [u8], loc: usize) -> Option<Self> {
5741 match selector.to_bytes() {
5742 b"bpf" => Some(ActOptionsMsg::Bpf(IterableActBpfAttrs::with_loc(buf, loc))),
5743 b"connmark" => Some(ActOptionsMsg::Connmark(IterableActConnmarkAttrs::with_loc(
5744 buf, loc,
5745 ))),
5746 b"csum" => Some(ActOptionsMsg::Csum(IterableActCsumAttrs::with_loc(
5747 buf, loc,
5748 ))),
5749 b"ct" => Some(ActOptionsMsg::Ct(IterableActCtAttrs::with_loc(buf, loc))),
5750 b"ctinfo" => Some(ActOptionsMsg::Ctinfo(IterableActCtinfoAttrs::with_loc(
5751 buf, loc,
5752 ))),
5753 b"gact" => Some(ActOptionsMsg::Gact(IterableActGactAttrs::with_loc(
5754 buf, loc,
5755 ))),
5756 b"gate" => Some(ActOptionsMsg::Gate(IterableActGateAttrs::with_loc(
5757 buf, loc,
5758 ))),
5759 b"ife" => Some(ActOptionsMsg::Ife(IterableActIfeAttrs::with_loc(buf, loc))),
5760 b"mirred" => Some(ActOptionsMsg::Mirred(IterableActMirredAttrs::with_loc(
5761 buf, loc,
5762 ))),
5763 b"mpls" => Some(ActOptionsMsg::Mpls(IterableActMplsAttrs::with_loc(
5764 buf, loc,
5765 ))),
5766 b"nat" => Some(ActOptionsMsg::Nat(IterableActNatAttrs::with_loc(buf, loc))),
5767 b"pedit" => Some(ActOptionsMsg::Pedit(IterableActPeditAttrs::with_loc(
5768 buf, loc,
5769 ))),
5770 b"police" => Some(ActOptionsMsg::Police(IterablePoliceAttrs::with_loc(
5771 buf, loc,
5772 ))),
5773 b"sample" => Some(ActOptionsMsg::Sample(IterableActSampleAttrs::with_loc(
5774 buf, loc,
5775 ))),
5776 b"simple" => Some(ActOptionsMsg::Simple(IterableActSimpleAttrs::with_loc(
5777 buf, loc,
5778 ))),
5779 b"skbedit" => Some(ActOptionsMsg::Skbedit(IterableActSkbeditAttrs::with_loc(
5780 buf, loc,
5781 ))),
5782 b"skbmod" => Some(ActOptionsMsg::Skbmod(IterableActSkbmodAttrs::with_loc(
5783 buf, loc,
5784 ))),
5785 b"tunnel_key" => Some(ActOptionsMsg::TunnelKey(
5786 IterableActTunnelKeyAttrs::with_loc(buf, loc),
5787 )),
5788 b"vlan" => Some(ActOptionsMsg::Vlan(IterableActVlanAttrs::with_loc(
5789 buf, loc,
5790 ))),
5791 _ => None,
5792 }
5793 }
5794}
5795impl ActAttrs<'_> {
5796 pub fn new<'a>(buf: &'a [u8]) -> IterableActAttrs<'a> {
5797 IterableActAttrs::with_loc(buf, buf.as_ptr() as usize)
5798 }
5799 fn attr_from_type(r#type: u16) -> Option<&'static str> {
5800 let res = match r#type {
5801 1u16 => "Kind",
5802 2u16 => "Options",
5803 3u16 => "Index",
5804 4u16 => "Stats",
5805 5u16 => "Pad",
5806 6u16 => "Cookie",
5807 7u16 => "Flags",
5808 8u16 => "HwStats",
5809 9u16 => "UsedHwStats",
5810 10u16 => "InHwCount",
5811 _ => return None,
5812 };
5813 Some(res)
5814 }
5815}
5816#[derive(Clone, Copy, Default)]
5817pub struct IterableActAttrs<'a> {
5818 buf: &'a [u8],
5819 pos: usize,
5820 orig_loc: usize,
5821}
5822impl<'a> IterableActAttrs<'a> {
5823 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5824 Self {
5825 buf,
5826 pos: 0,
5827 orig_loc,
5828 }
5829 }
5830 pub fn get_buf(&self) -> &'a [u8] {
5831 self.buf
5832 }
5833}
5834impl<'a> Iterator for IterableActAttrs<'a> {
5835 type Item = Result<ActAttrs<'a>, ErrorContext>;
5836 fn next(&mut self) -> Option<Self::Item> {
5837 let mut pos;
5838 let mut r#type;
5839 loop {
5840 pos = self.pos;
5841 r#type = None;
5842 if self.buf.len() == self.pos {
5843 return None;
5844 }
5845 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
5846 self.pos = self.buf.len();
5847 break;
5848 };
5849 r#type = Some(header.r#type);
5850 let res = match header.r#type {
5851 1u16 => ActAttrs::Kind({
5852 let res = CStr::from_bytes_with_nul(next).ok();
5853 let Some(val) = res else { break };
5854 val
5855 }),
5856 2u16 => ActAttrs::Options({
5857 let res = {
5858 let Ok(selector) = self.get_kind() else { break };
5859 match ActOptionsMsg::select_with_loc(selector, next, self.orig_loc) {
5860 Some(sub) => Some(sub),
5861 None if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
5862 None => continue,
5863 }
5864 };
5865 let Some(val) = res else { break };
5866 val
5867 }),
5868 3u16 => ActAttrs::Index({
5869 let res = parse_u32(next);
5870 let Some(val) = res else { break };
5871 val
5872 }),
5873 4u16 => ActAttrs::Stats({
5874 let res = Some(IterableTcaStatsAttrs::with_loc(next, self.orig_loc));
5875 let Some(val) = res else { break };
5876 val
5877 }),
5878 5u16 => ActAttrs::Pad({
5879 let res = Some(next);
5880 let Some(val) = res else { break };
5881 val
5882 }),
5883 6u16 => ActAttrs::Cookie({
5884 let res = Some(next);
5885 let Some(val) = res else { break };
5886 val
5887 }),
5888 7u16 => ActAttrs::Flags({
5889 let res = BuiltinBitfield32::new_from_slice(next);
5890 let Some(val) = res else { break };
5891 val
5892 }),
5893 8u16 => ActAttrs::HwStats({
5894 let res = BuiltinBitfield32::new_from_slice(next);
5895 let Some(val) = res else { break };
5896 val
5897 }),
5898 9u16 => ActAttrs::UsedHwStats({
5899 let res = BuiltinBitfield32::new_from_slice(next);
5900 let Some(val) = res else { break };
5901 val
5902 }),
5903 10u16 => ActAttrs::InHwCount({
5904 let res = parse_u32(next);
5905 let Some(val) = res else { break };
5906 val
5907 }),
5908 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
5909 n => continue,
5910 };
5911 return Some(Ok(res));
5912 }
5913 Some(Err(ErrorContext::new(
5914 "ActAttrs",
5915 r#type.and_then(|t| ActAttrs::attr_from_type(t)),
5916 self.orig_loc,
5917 self.buf.as_ptr().wrapping_add(pos) as usize,
5918 )))
5919 }
5920}
5921impl<'a> std::fmt::Debug for IterableActAttrs<'_> {
5922 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5923 let mut fmt = f.debug_struct("ActAttrs");
5924 for attr in self.clone() {
5925 let attr = match attr {
5926 Ok(a) => a,
5927 Err(err) => {
5928 fmt.finish()?;
5929 f.write_str("Err(")?;
5930 err.fmt(f)?;
5931 return f.write_str(")");
5932 }
5933 };
5934 match attr {
5935 ActAttrs::Kind(val) => fmt.field("Kind", &val),
5936 ActAttrs::Options(val) => fmt.field("Options", &val),
5937 ActAttrs::Index(val) => fmt.field("Index", &val),
5938 ActAttrs::Stats(val) => fmt.field("Stats", &val),
5939 ActAttrs::Pad(val) => fmt.field("Pad", &val),
5940 ActAttrs::Cookie(val) => fmt.field("Cookie", &val),
5941 ActAttrs::Flags(val) => fmt.field("Flags", &val),
5942 ActAttrs::HwStats(val) => fmt.field("HwStats", &val),
5943 ActAttrs::UsedHwStats(val) => fmt.field("UsedHwStats", &val),
5944 ActAttrs::InHwCount(val) => fmt.field("InHwCount", &val),
5945 };
5946 }
5947 fmt.finish()
5948 }
5949}
5950impl IterableActAttrs<'_> {
5951 pub fn lookup_attr(
5952 &self,
5953 offset: usize,
5954 missing_type: Option<u16>,
5955 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5956 let mut stack = Vec::new();
5957 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
5958 if missing_type.is_some() && cur == offset {
5959 stack.push(("ActAttrs", offset));
5960 return (
5961 stack,
5962 missing_type.and_then(|t| ActAttrs::attr_from_type(t)),
5963 );
5964 }
5965 if cur > offset || cur + self.buf.len() < offset {
5966 return (stack, None);
5967 }
5968 let mut attrs = self.clone();
5969 let mut last_off = cur + attrs.pos;
5970 let mut missing = None;
5971 while let Some(attr) = attrs.next() {
5972 let Ok(attr) = attr else { break };
5973 match attr {
5974 ActAttrs::Kind(val) => {
5975 if last_off == offset {
5976 stack.push(("Kind", last_off));
5977 break;
5978 }
5979 }
5980 ActAttrs::Options(val) => {
5981 if last_off == offset {
5982 stack.push(("Options", last_off));
5983 break;
5984 }
5985 }
5986 ActAttrs::Index(val) => {
5987 if last_off == offset {
5988 stack.push(("Index", last_off));
5989 break;
5990 }
5991 }
5992 ActAttrs::Stats(val) => {
5993 (stack, missing) = val.lookup_attr(offset, missing_type);
5994 if !stack.is_empty() {
5995 break;
5996 }
5997 }
5998 ActAttrs::Pad(val) => {
5999 if last_off == offset {
6000 stack.push(("Pad", last_off));
6001 break;
6002 }
6003 }
6004 ActAttrs::Cookie(val) => {
6005 if last_off == offset {
6006 stack.push(("Cookie", last_off));
6007 break;
6008 }
6009 }
6010 ActAttrs::Flags(val) => {
6011 if last_off == offset {
6012 stack.push(("Flags", last_off));
6013 break;
6014 }
6015 }
6016 ActAttrs::HwStats(val) => {
6017 if last_off == offset {
6018 stack.push(("HwStats", last_off));
6019 break;
6020 }
6021 }
6022 ActAttrs::UsedHwStats(val) => {
6023 if last_off == offset {
6024 stack.push(("UsedHwStats", last_off));
6025 break;
6026 }
6027 }
6028 ActAttrs::InHwCount(val) => {
6029 if last_off == offset {
6030 stack.push(("InHwCount", last_off));
6031 break;
6032 }
6033 }
6034 _ => {}
6035 };
6036 last_off = cur + attrs.pos;
6037 }
6038 if !stack.is_empty() {
6039 stack.push(("ActAttrs", cur));
6040 }
6041 (stack, missing)
6042 }
6043}
6044#[derive(Clone)]
6045pub enum ActBpfAttrs<'a> {
6046 Tm(TcfT),
6047 Parms(&'a [u8]),
6048 OpsLen(u16),
6049 Ops(&'a [u8]),
6050 Fd(u32),
6051 Name(&'a CStr),
6052 Pad(&'a [u8]),
6053 Tag(&'a [u8]),
6054 Id(&'a [u8]),
6055}
6056impl<'a> IterableActBpfAttrs<'a> {
6057 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
6058 let mut iter = self.clone();
6059 iter.pos = 0;
6060 for attr in iter {
6061 if let Ok(ActBpfAttrs::Tm(val)) = attr {
6062 return Ok(val);
6063 }
6064 }
6065 Err(ErrorContext::new_missing(
6066 "ActBpfAttrs",
6067 "Tm",
6068 self.orig_loc,
6069 self.buf.as_ptr() as usize,
6070 ))
6071 }
6072 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
6073 let mut iter = self.clone();
6074 iter.pos = 0;
6075 for attr in iter {
6076 if let Ok(ActBpfAttrs::Parms(val)) = attr {
6077 return Ok(val);
6078 }
6079 }
6080 Err(ErrorContext::new_missing(
6081 "ActBpfAttrs",
6082 "Parms",
6083 self.orig_loc,
6084 self.buf.as_ptr() as usize,
6085 ))
6086 }
6087 pub fn get_ops_len(&self) -> Result<u16, ErrorContext> {
6088 let mut iter = self.clone();
6089 iter.pos = 0;
6090 for attr in iter {
6091 if let Ok(ActBpfAttrs::OpsLen(val)) = attr {
6092 return Ok(val);
6093 }
6094 }
6095 Err(ErrorContext::new_missing(
6096 "ActBpfAttrs",
6097 "OpsLen",
6098 self.orig_loc,
6099 self.buf.as_ptr() as usize,
6100 ))
6101 }
6102 pub fn get_ops(&self) -> Result<&'a [u8], ErrorContext> {
6103 let mut iter = self.clone();
6104 iter.pos = 0;
6105 for attr in iter {
6106 if let Ok(ActBpfAttrs::Ops(val)) = attr {
6107 return Ok(val);
6108 }
6109 }
6110 Err(ErrorContext::new_missing(
6111 "ActBpfAttrs",
6112 "Ops",
6113 self.orig_loc,
6114 self.buf.as_ptr() as usize,
6115 ))
6116 }
6117 pub fn get_fd(&self) -> Result<u32, ErrorContext> {
6118 let mut iter = self.clone();
6119 iter.pos = 0;
6120 for attr in iter {
6121 if let Ok(ActBpfAttrs::Fd(val)) = attr {
6122 return Ok(val);
6123 }
6124 }
6125 Err(ErrorContext::new_missing(
6126 "ActBpfAttrs",
6127 "Fd",
6128 self.orig_loc,
6129 self.buf.as_ptr() as usize,
6130 ))
6131 }
6132 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
6133 let mut iter = self.clone();
6134 iter.pos = 0;
6135 for attr in iter {
6136 if let Ok(ActBpfAttrs::Name(val)) = attr {
6137 return Ok(val);
6138 }
6139 }
6140 Err(ErrorContext::new_missing(
6141 "ActBpfAttrs",
6142 "Name",
6143 self.orig_loc,
6144 self.buf.as_ptr() as usize,
6145 ))
6146 }
6147 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
6148 let mut iter = self.clone();
6149 iter.pos = 0;
6150 for attr in iter {
6151 if let Ok(ActBpfAttrs::Pad(val)) = attr {
6152 return Ok(val);
6153 }
6154 }
6155 Err(ErrorContext::new_missing(
6156 "ActBpfAttrs",
6157 "Pad",
6158 self.orig_loc,
6159 self.buf.as_ptr() as usize,
6160 ))
6161 }
6162 pub fn get_tag(&self) -> Result<&'a [u8], ErrorContext> {
6163 let mut iter = self.clone();
6164 iter.pos = 0;
6165 for attr in iter {
6166 if let Ok(ActBpfAttrs::Tag(val)) = attr {
6167 return Ok(val);
6168 }
6169 }
6170 Err(ErrorContext::new_missing(
6171 "ActBpfAttrs",
6172 "Tag",
6173 self.orig_loc,
6174 self.buf.as_ptr() as usize,
6175 ))
6176 }
6177 pub fn get_id(&self) -> Result<&'a [u8], ErrorContext> {
6178 let mut iter = self.clone();
6179 iter.pos = 0;
6180 for attr in iter {
6181 if let Ok(ActBpfAttrs::Id(val)) = attr {
6182 return Ok(val);
6183 }
6184 }
6185 Err(ErrorContext::new_missing(
6186 "ActBpfAttrs",
6187 "Id",
6188 self.orig_loc,
6189 self.buf.as_ptr() as usize,
6190 ))
6191 }
6192}
6193impl ActBpfAttrs<'_> {
6194 pub fn new<'a>(buf: &'a [u8]) -> IterableActBpfAttrs<'a> {
6195 IterableActBpfAttrs::with_loc(buf, buf.as_ptr() as usize)
6196 }
6197 fn attr_from_type(r#type: u16) -> Option<&'static str> {
6198 let res = match r#type {
6199 1u16 => "Tm",
6200 2u16 => "Parms",
6201 3u16 => "OpsLen",
6202 4u16 => "Ops",
6203 5u16 => "Fd",
6204 6u16 => "Name",
6205 7u16 => "Pad",
6206 8u16 => "Tag",
6207 9u16 => "Id",
6208 _ => return None,
6209 };
6210 Some(res)
6211 }
6212}
6213#[derive(Clone, Copy, Default)]
6214pub struct IterableActBpfAttrs<'a> {
6215 buf: &'a [u8],
6216 pos: usize,
6217 orig_loc: usize,
6218}
6219impl<'a> IterableActBpfAttrs<'a> {
6220 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
6221 Self {
6222 buf,
6223 pos: 0,
6224 orig_loc,
6225 }
6226 }
6227 pub fn get_buf(&self) -> &'a [u8] {
6228 self.buf
6229 }
6230}
6231impl<'a> Iterator for IterableActBpfAttrs<'a> {
6232 type Item = Result<ActBpfAttrs<'a>, ErrorContext>;
6233 fn next(&mut self) -> Option<Self::Item> {
6234 let mut pos;
6235 let mut r#type;
6236 loop {
6237 pos = self.pos;
6238 r#type = None;
6239 if self.buf.len() == self.pos {
6240 return None;
6241 }
6242 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
6243 self.pos = self.buf.len();
6244 break;
6245 };
6246 r#type = Some(header.r#type);
6247 let res = match header.r#type {
6248 1u16 => ActBpfAttrs::Tm({
6249 let res = Some(TcfT::new_from_zeroed(next));
6250 let Some(val) = res else { break };
6251 val
6252 }),
6253 2u16 => ActBpfAttrs::Parms({
6254 let res = Some(next);
6255 let Some(val) = res else { break };
6256 val
6257 }),
6258 3u16 => ActBpfAttrs::OpsLen({
6259 let res = parse_u16(next);
6260 let Some(val) = res else { break };
6261 val
6262 }),
6263 4u16 => ActBpfAttrs::Ops({
6264 let res = Some(next);
6265 let Some(val) = res else { break };
6266 val
6267 }),
6268 5u16 => ActBpfAttrs::Fd({
6269 let res = parse_u32(next);
6270 let Some(val) = res else { break };
6271 val
6272 }),
6273 6u16 => ActBpfAttrs::Name({
6274 let res = CStr::from_bytes_with_nul(next).ok();
6275 let Some(val) = res else { break };
6276 val
6277 }),
6278 7u16 => ActBpfAttrs::Pad({
6279 let res = Some(next);
6280 let Some(val) = res else { break };
6281 val
6282 }),
6283 8u16 => ActBpfAttrs::Tag({
6284 let res = Some(next);
6285 let Some(val) = res else { break };
6286 val
6287 }),
6288 9u16 => ActBpfAttrs::Id({
6289 let res = Some(next);
6290 let Some(val) = res else { break };
6291 val
6292 }),
6293 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
6294 n => continue,
6295 };
6296 return Some(Ok(res));
6297 }
6298 Some(Err(ErrorContext::new(
6299 "ActBpfAttrs",
6300 r#type.and_then(|t| ActBpfAttrs::attr_from_type(t)),
6301 self.orig_loc,
6302 self.buf.as_ptr().wrapping_add(pos) as usize,
6303 )))
6304 }
6305}
6306impl<'a> std::fmt::Debug for IterableActBpfAttrs<'_> {
6307 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6308 let mut fmt = f.debug_struct("ActBpfAttrs");
6309 for attr in self.clone() {
6310 let attr = match attr {
6311 Ok(a) => a,
6312 Err(err) => {
6313 fmt.finish()?;
6314 f.write_str("Err(")?;
6315 err.fmt(f)?;
6316 return f.write_str(")");
6317 }
6318 };
6319 match attr {
6320 ActBpfAttrs::Tm(val) => fmt.field("Tm", &val),
6321 ActBpfAttrs::Parms(val) => fmt.field("Parms", &val),
6322 ActBpfAttrs::OpsLen(val) => fmt.field("OpsLen", &val),
6323 ActBpfAttrs::Ops(val) => fmt.field("Ops", &val),
6324 ActBpfAttrs::Fd(val) => fmt.field("Fd", &val),
6325 ActBpfAttrs::Name(val) => fmt.field("Name", &val),
6326 ActBpfAttrs::Pad(val) => fmt.field("Pad", &val),
6327 ActBpfAttrs::Tag(val) => fmt.field("Tag", &val),
6328 ActBpfAttrs::Id(val) => fmt.field("Id", &val),
6329 };
6330 }
6331 fmt.finish()
6332 }
6333}
6334impl IterableActBpfAttrs<'_> {
6335 pub fn lookup_attr(
6336 &self,
6337 offset: usize,
6338 missing_type: Option<u16>,
6339 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
6340 let mut stack = Vec::new();
6341 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
6342 if missing_type.is_some() && cur == offset {
6343 stack.push(("ActBpfAttrs", offset));
6344 return (
6345 stack,
6346 missing_type.and_then(|t| ActBpfAttrs::attr_from_type(t)),
6347 );
6348 }
6349 if cur > offset || cur + self.buf.len() < offset {
6350 return (stack, None);
6351 }
6352 let mut attrs = self.clone();
6353 let mut last_off = cur + attrs.pos;
6354 while let Some(attr) = attrs.next() {
6355 let Ok(attr) = attr else { break };
6356 match attr {
6357 ActBpfAttrs::Tm(val) => {
6358 if last_off == offset {
6359 stack.push(("Tm", last_off));
6360 break;
6361 }
6362 }
6363 ActBpfAttrs::Parms(val) => {
6364 if last_off == offset {
6365 stack.push(("Parms", last_off));
6366 break;
6367 }
6368 }
6369 ActBpfAttrs::OpsLen(val) => {
6370 if last_off == offset {
6371 stack.push(("OpsLen", last_off));
6372 break;
6373 }
6374 }
6375 ActBpfAttrs::Ops(val) => {
6376 if last_off == offset {
6377 stack.push(("Ops", last_off));
6378 break;
6379 }
6380 }
6381 ActBpfAttrs::Fd(val) => {
6382 if last_off == offset {
6383 stack.push(("Fd", last_off));
6384 break;
6385 }
6386 }
6387 ActBpfAttrs::Name(val) => {
6388 if last_off == offset {
6389 stack.push(("Name", last_off));
6390 break;
6391 }
6392 }
6393 ActBpfAttrs::Pad(val) => {
6394 if last_off == offset {
6395 stack.push(("Pad", last_off));
6396 break;
6397 }
6398 }
6399 ActBpfAttrs::Tag(val) => {
6400 if last_off == offset {
6401 stack.push(("Tag", last_off));
6402 break;
6403 }
6404 }
6405 ActBpfAttrs::Id(val) => {
6406 if last_off == offset {
6407 stack.push(("Id", last_off));
6408 break;
6409 }
6410 }
6411 _ => {}
6412 };
6413 last_off = cur + attrs.pos;
6414 }
6415 if !stack.is_empty() {
6416 stack.push(("ActBpfAttrs", cur));
6417 }
6418 (stack, None)
6419 }
6420}
6421#[derive(Clone)]
6422pub enum ActConnmarkAttrs<'a> {
6423 Parms(&'a [u8]),
6424 Tm(TcfT),
6425 Pad(&'a [u8]),
6426}
6427impl<'a> IterableActConnmarkAttrs<'a> {
6428 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
6429 let mut iter = self.clone();
6430 iter.pos = 0;
6431 for attr in iter {
6432 if let Ok(ActConnmarkAttrs::Parms(val)) = attr {
6433 return Ok(val);
6434 }
6435 }
6436 Err(ErrorContext::new_missing(
6437 "ActConnmarkAttrs",
6438 "Parms",
6439 self.orig_loc,
6440 self.buf.as_ptr() as usize,
6441 ))
6442 }
6443 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
6444 let mut iter = self.clone();
6445 iter.pos = 0;
6446 for attr in iter {
6447 if let Ok(ActConnmarkAttrs::Tm(val)) = attr {
6448 return Ok(val);
6449 }
6450 }
6451 Err(ErrorContext::new_missing(
6452 "ActConnmarkAttrs",
6453 "Tm",
6454 self.orig_loc,
6455 self.buf.as_ptr() as usize,
6456 ))
6457 }
6458 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
6459 let mut iter = self.clone();
6460 iter.pos = 0;
6461 for attr in iter {
6462 if let Ok(ActConnmarkAttrs::Pad(val)) = attr {
6463 return Ok(val);
6464 }
6465 }
6466 Err(ErrorContext::new_missing(
6467 "ActConnmarkAttrs",
6468 "Pad",
6469 self.orig_loc,
6470 self.buf.as_ptr() as usize,
6471 ))
6472 }
6473}
6474impl ActConnmarkAttrs<'_> {
6475 pub fn new<'a>(buf: &'a [u8]) -> IterableActConnmarkAttrs<'a> {
6476 IterableActConnmarkAttrs::with_loc(buf, buf.as_ptr() as usize)
6477 }
6478 fn attr_from_type(r#type: u16) -> Option<&'static str> {
6479 let res = match r#type {
6480 1u16 => "Parms",
6481 2u16 => "Tm",
6482 3u16 => "Pad",
6483 _ => return None,
6484 };
6485 Some(res)
6486 }
6487}
6488#[derive(Clone, Copy, Default)]
6489pub struct IterableActConnmarkAttrs<'a> {
6490 buf: &'a [u8],
6491 pos: usize,
6492 orig_loc: usize,
6493}
6494impl<'a> IterableActConnmarkAttrs<'a> {
6495 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
6496 Self {
6497 buf,
6498 pos: 0,
6499 orig_loc,
6500 }
6501 }
6502 pub fn get_buf(&self) -> &'a [u8] {
6503 self.buf
6504 }
6505}
6506impl<'a> Iterator for IterableActConnmarkAttrs<'a> {
6507 type Item = Result<ActConnmarkAttrs<'a>, ErrorContext>;
6508 fn next(&mut self) -> Option<Self::Item> {
6509 let mut pos;
6510 let mut r#type;
6511 loop {
6512 pos = self.pos;
6513 r#type = None;
6514 if self.buf.len() == self.pos {
6515 return None;
6516 }
6517 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
6518 self.pos = self.buf.len();
6519 break;
6520 };
6521 r#type = Some(header.r#type);
6522 let res = match header.r#type {
6523 1u16 => ActConnmarkAttrs::Parms({
6524 let res = Some(next);
6525 let Some(val) = res else { break };
6526 val
6527 }),
6528 2u16 => ActConnmarkAttrs::Tm({
6529 let res = Some(TcfT::new_from_zeroed(next));
6530 let Some(val) = res else { break };
6531 val
6532 }),
6533 3u16 => ActConnmarkAttrs::Pad({
6534 let res = Some(next);
6535 let Some(val) = res else { break };
6536 val
6537 }),
6538 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
6539 n => continue,
6540 };
6541 return Some(Ok(res));
6542 }
6543 Some(Err(ErrorContext::new(
6544 "ActConnmarkAttrs",
6545 r#type.and_then(|t| ActConnmarkAttrs::attr_from_type(t)),
6546 self.orig_loc,
6547 self.buf.as_ptr().wrapping_add(pos) as usize,
6548 )))
6549 }
6550}
6551impl<'a> std::fmt::Debug for IterableActConnmarkAttrs<'_> {
6552 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6553 let mut fmt = f.debug_struct("ActConnmarkAttrs");
6554 for attr in self.clone() {
6555 let attr = match attr {
6556 Ok(a) => a,
6557 Err(err) => {
6558 fmt.finish()?;
6559 f.write_str("Err(")?;
6560 err.fmt(f)?;
6561 return f.write_str(")");
6562 }
6563 };
6564 match attr {
6565 ActConnmarkAttrs::Parms(val) => fmt.field("Parms", &val),
6566 ActConnmarkAttrs::Tm(val) => fmt.field("Tm", &val),
6567 ActConnmarkAttrs::Pad(val) => fmt.field("Pad", &val),
6568 };
6569 }
6570 fmt.finish()
6571 }
6572}
6573impl IterableActConnmarkAttrs<'_> {
6574 pub fn lookup_attr(
6575 &self,
6576 offset: usize,
6577 missing_type: Option<u16>,
6578 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
6579 let mut stack = Vec::new();
6580 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
6581 if missing_type.is_some() && cur == offset {
6582 stack.push(("ActConnmarkAttrs", offset));
6583 return (
6584 stack,
6585 missing_type.and_then(|t| ActConnmarkAttrs::attr_from_type(t)),
6586 );
6587 }
6588 if cur > offset || cur + self.buf.len() < offset {
6589 return (stack, None);
6590 }
6591 let mut attrs = self.clone();
6592 let mut last_off = cur + attrs.pos;
6593 while let Some(attr) = attrs.next() {
6594 let Ok(attr) = attr else { break };
6595 match attr {
6596 ActConnmarkAttrs::Parms(val) => {
6597 if last_off == offset {
6598 stack.push(("Parms", last_off));
6599 break;
6600 }
6601 }
6602 ActConnmarkAttrs::Tm(val) => {
6603 if last_off == offset {
6604 stack.push(("Tm", last_off));
6605 break;
6606 }
6607 }
6608 ActConnmarkAttrs::Pad(val) => {
6609 if last_off == offset {
6610 stack.push(("Pad", last_off));
6611 break;
6612 }
6613 }
6614 _ => {}
6615 };
6616 last_off = cur + attrs.pos;
6617 }
6618 if !stack.is_empty() {
6619 stack.push(("ActConnmarkAttrs", cur));
6620 }
6621 (stack, None)
6622 }
6623}
6624#[derive(Clone)]
6625pub enum ActCsumAttrs<'a> {
6626 Parms(&'a [u8]),
6627 Tm(TcfT),
6628 Pad(&'a [u8]),
6629}
6630impl<'a> IterableActCsumAttrs<'a> {
6631 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
6632 let mut iter = self.clone();
6633 iter.pos = 0;
6634 for attr in iter {
6635 if let Ok(ActCsumAttrs::Parms(val)) = attr {
6636 return Ok(val);
6637 }
6638 }
6639 Err(ErrorContext::new_missing(
6640 "ActCsumAttrs",
6641 "Parms",
6642 self.orig_loc,
6643 self.buf.as_ptr() as usize,
6644 ))
6645 }
6646 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
6647 let mut iter = self.clone();
6648 iter.pos = 0;
6649 for attr in iter {
6650 if let Ok(ActCsumAttrs::Tm(val)) = attr {
6651 return Ok(val);
6652 }
6653 }
6654 Err(ErrorContext::new_missing(
6655 "ActCsumAttrs",
6656 "Tm",
6657 self.orig_loc,
6658 self.buf.as_ptr() as usize,
6659 ))
6660 }
6661 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
6662 let mut iter = self.clone();
6663 iter.pos = 0;
6664 for attr in iter {
6665 if let Ok(ActCsumAttrs::Pad(val)) = attr {
6666 return Ok(val);
6667 }
6668 }
6669 Err(ErrorContext::new_missing(
6670 "ActCsumAttrs",
6671 "Pad",
6672 self.orig_loc,
6673 self.buf.as_ptr() as usize,
6674 ))
6675 }
6676}
6677impl ActCsumAttrs<'_> {
6678 pub fn new<'a>(buf: &'a [u8]) -> IterableActCsumAttrs<'a> {
6679 IterableActCsumAttrs::with_loc(buf, buf.as_ptr() as usize)
6680 }
6681 fn attr_from_type(r#type: u16) -> Option<&'static str> {
6682 let res = match r#type {
6683 1u16 => "Parms",
6684 2u16 => "Tm",
6685 3u16 => "Pad",
6686 _ => return None,
6687 };
6688 Some(res)
6689 }
6690}
6691#[derive(Clone, Copy, Default)]
6692pub struct IterableActCsumAttrs<'a> {
6693 buf: &'a [u8],
6694 pos: usize,
6695 orig_loc: usize,
6696}
6697impl<'a> IterableActCsumAttrs<'a> {
6698 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
6699 Self {
6700 buf,
6701 pos: 0,
6702 orig_loc,
6703 }
6704 }
6705 pub fn get_buf(&self) -> &'a [u8] {
6706 self.buf
6707 }
6708}
6709impl<'a> Iterator for IterableActCsumAttrs<'a> {
6710 type Item = Result<ActCsumAttrs<'a>, ErrorContext>;
6711 fn next(&mut self) -> Option<Self::Item> {
6712 let mut pos;
6713 let mut r#type;
6714 loop {
6715 pos = self.pos;
6716 r#type = None;
6717 if self.buf.len() == self.pos {
6718 return None;
6719 }
6720 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
6721 self.pos = self.buf.len();
6722 break;
6723 };
6724 r#type = Some(header.r#type);
6725 let res = match header.r#type {
6726 1u16 => ActCsumAttrs::Parms({
6727 let res = Some(next);
6728 let Some(val) = res else { break };
6729 val
6730 }),
6731 2u16 => ActCsumAttrs::Tm({
6732 let res = Some(TcfT::new_from_zeroed(next));
6733 let Some(val) = res else { break };
6734 val
6735 }),
6736 3u16 => ActCsumAttrs::Pad({
6737 let res = Some(next);
6738 let Some(val) = res else { break };
6739 val
6740 }),
6741 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
6742 n => continue,
6743 };
6744 return Some(Ok(res));
6745 }
6746 Some(Err(ErrorContext::new(
6747 "ActCsumAttrs",
6748 r#type.and_then(|t| ActCsumAttrs::attr_from_type(t)),
6749 self.orig_loc,
6750 self.buf.as_ptr().wrapping_add(pos) as usize,
6751 )))
6752 }
6753}
6754impl<'a> std::fmt::Debug for IterableActCsumAttrs<'_> {
6755 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6756 let mut fmt = f.debug_struct("ActCsumAttrs");
6757 for attr in self.clone() {
6758 let attr = match attr {
6759 Ok(a) => a,
6760 Err(err) => {
6761 fmt.finish()?;
6762 f.write_str("Err(")?;
6763 err.fmt(f)?;
6764 return f.write_str(")");
6765 }
6766 };
6767 match attr {
6768 ActCsumAttrs::Parms(val) => fmt.field("Parms", &val),
6769 ActCsumAttrs::Tm(val) => fmt.field("Tm", &val),
6770 ActCsumAttrs::Pad(val) => fmt.field("Pad", &val),
6771 };
6772 }
6773 fmt.finish()
6774 }
6775}
6776impl IterableActCsumAttrs<'_> {
6777 pub fn lookup_attr(
6778 &self,
6779 offset: usize,
6780 missing_type: Option<u16>,
6781 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
6782 let mut stack = Vec::new();
6783 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
6784 if missing_type.is_some() && cur == offset {
6785 stack.push(("ActCsumAttrs", offset));
6786 return (
6787 stack,
6788 missing_type.and_then(|t| ActCsumAttrs::attr_from_type(t)),
6789 );
6790 }
6791 if cur > offset || cur + self.buf.len() < offset {
6792 return (stack, None);
6793 }
6794 let mut attrs = self.clone();
6795 let mut last_off = cur + attrs.pos;
6796 while let Some(attr) = attrs.next() {
6797 let Ok(attr) = attr else { break };
6798 match attr {
6799 ActCsumAttrs::Parms(val) => {
6800 if last_off == offset {
6801 stack.push(("Parms", last_off));
6802 break;
6803 }
6804 }
6805 ActCsumAttrs::Tm(val) => {
6806 if last_off == offset {
6807 stack.push(("Tm", last_off));
6808 break;
6809 }
6810 }
6811 ActCsumAttrs::Pad(val) => {
6812 if last_off == offset {
6813 stack.push(("Pad", last_off));
6814 break;
6815 }
6816 }
6817 _ => {}
6818 };
6819 last_off = cur + attrs.pos;
6820 }
6821 if !stack.is_empty() {
6822 stack.push(("ActCsumAttrs", cur));
6823 }
6824 (stack, None)
6825 }
6826}
6827#[derive(Clone)]
6828pub enum ActCtAttrs<'a> {
6829 Parms(&'a [u8]),
6830 Tm(TcfT),
6831 Action(u16),
6832 Zone(u16),
6833 Mark(u32),
6834 MarkMask(u32),
6835 Labels(&'a [u8]),
6836 LabelsMask(&'a [u8]),
6837 NatIpv4Min(u32),
6838 NatIpv4Max(u32),
6839 NatIpv6Min(&'a [u8]),
6840 NatIpv6Max(&'a [u8]),
6841 NatPortMin(u16),
6842 NatPortMax(u16),
6843 Pad(&'a [u8]),
6844 HelperName(&'a CStr),
6845 HelperFamily(u8),
6846 HelperProto(u8),
6847}
6848impl<'a> IterableActCtAttrs<'a> {
6849 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
6850 let mut iter = self.clone();
6851 iter.pos = 0;
6852 for attr in iter {
6853 if let Ok(ActCtAttrs::Parms(val)) = attr {
6854 return Ok(val);
6855 }
6856 }
6857 Err(ErrorContext::new_missing(
6858 "ActCtAttrs",
6859 "Parms",
6860 self.orig_loc,
6861 self.buf.as_ptr() as usize,
6862 ))
6863 }
6864 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
6865 let mut iter = self.clone();
6866 iter.pos = 0;
6867 for attr in iter {
6868 if let Ok(ActCtAttrs::Tm(val)) = attr {
6869 return Ok(val);
6870 }
6871 }
6872 Err(ErrorContext::new_missing(
6873 "ActCtAttrs",
6874 "Tm",
6875 self.orig_loc,
6876 self.buf.as_ptr() as usize,
6877 ))
6878 }
6879 pub fn get_action(&self) -> Result<u16, ErrorContext> {
6880 let mut iter = self.clone();
6881 iter.pos = 0;
6882 for attr in iter {
6883 if let Ok(ActCtAttrs::Action(val)) = attr {
6884 return Ok(val);
6885 }
6886 }
6887 Err(ErrorContext::new_missing(
6888 "ActCtAttrs",
6889 "Action",
6890 self.orig_loc,
6891 self.buf.as_ptr() as usize,
6892 ))
6893 }
6894 pub fn get_zone(&self) -> Result<u16, ErrorContext> {
6895 let mut iter = self.clone();
6896 iter.pos = 0;
6897 for attr in iter {
6898 if let Ok(ActCtAttrs::Zone(val)) = attr {
6899 return Ok(val);
6900 }
6901 }
6902 Err(ErrorContext::new_missing(
6903 "ActCtAttrs",
6904 "Zone",
6905 self.orig_loc,
6906 self.buf.as_ptr() as usize,
6907 ))
6908 }
6909 pub fn get_mark(&self) -> Result<u32, ErrorContext> {
6910 let mut iter = self.clone();
6911 iter.pos = 0;
6912 for attr in iter {
6913 if let Ok(ActCtAttrs::Mark(val)) = attr {
6914 return Ok(val);
6915 }
6916 }
6917 Err(ErrorContext::new_missing(
6918 "ActCtAttrs",
6919 "Mark",
6920 self.orig_loc,
6921 self.buf.as_ptr() as usize,
6922 ))
6923 }
6924 pub fn get_mark_mask(&self) -> Result<u32, ErrorContext> {
6925 let mut iter = self.clone();
6926 iter.pos = 0;
6927 for attr in iter {
6928 if let Ok(ActCtAttrs::MarkMask(val)) = attr {
6929 return Ok(val);
6930 }
6931 }
6932 Err(ErrorContext::new_missing(
6933 "ActCtAttrs",
6934 "MarkMask",
6935 self.orig_loc,
6936 self.buf.as_ptr() as usize,
6937 ))
6938 }
6939 pub fn get_labels(&self) -> Result<&'a [u8], ErrorContext> {
6940 let mut iter = self.clone();
6941 iter.pos = 0;
6942 for attr in iter {
6943 if let Ok(ActCtAttrs::Labels(val)) = attr {
6944 return Ok(val);
6945 }
6946 }
6947 Err(ErrorContext::new_missing(
6948 "ActCtAttrs",
6949 "Labels",
6950 self.orig_loc,
6951 self.buf.as_ptr() as usize,
6952 ))
6953 }
6954 pub fn get_labels_mask(&self) -> Result<&'a [u8], ErrorContext> {
6955 let mut iter = self.clone();
6956 iter.pos = 0;
6957 for attr in iter {
6958 if let Ok(ActCtAttrs::LabelsMask(val)) = attr {
6959 return Ok(val);
6960 }
6961 }
6962 Err(ErrorContext::new_missing(
6963 "ActCtAttrs",
6964 "LabelsMask",
6965 self.orig_loc,
6966 self.buf.as_ptr() as usize,
6967 ))
6968 }
6969 pub fn get_nat_ipv4_min(&self) -> Result<u32, ErrorContext> {
6970 let mut iter = self.clone();
6971 iter.pos = 0;
6972 for attr in iter {
6973 if let Ok(ActCtAttrs::NatIpv4Min(val)) = attr {
6974 return Ok(val);
6975 }
6976 }
6977 Err(ErrorContext::new_missing(
6978 "ActCtAttrs",
6979 "NatIpv4Min",
6980 self.orig_loc,
6981 self.buf.as_ptr() as usize,
6982 ))
6983 }
6984 pub fn get_nat_ipv4_max(&self) -> Result<u32, ErrorContext> {
6985 let mut iter = self.clone();
6986 iter.pos = 0;
6987 for attr in iter {
6988 if let Ok(ActCtAttrs::NatIpv4Max(val)) = attr {
6989 return Ok(val);
6990 }
6991 }
6992 Err(ErrorContext::new_missing(
6993 "ActCtAttrs",
6994 "NatIpv4Max",
6995 self.orig_loc,
6996 self.buf.as_ptr() as usize,
6997 ))
6998 }
6999 pub fn get_nat_ipv6_min(&self) -> Result<&'a [u8], ErrorContext> {
7000 let mut iter = self.clone();
7001 iter.pos = 0;
7002 for attr in iter {
7003 if let Ok(ActCtAttrs::NatIpv6Min(val)) = attr {
7004 return Ok(val);
7005 }
7006 }
7007 Err(ErrorContext::new_missing(
7008 "ActCtAttrs",
7009 "NatIpv6Min",
7010 self.orig_loc,
7011 self.buf.as_ptr() as usize,
7012 ))
7013 }
7014 pub fn get_nat_ipv6_max(&self) -> Result<&'a [u8], ErrorContext> {
7015 let mut iter = self.clone();
7016 iter.pos = 0;
7017 for attr in iter {
7018 if let Ok(ActCtAttrs::NatIpv6Max(val)) = attr {
7019 return Ok(val);
7020 }
7021 }
7022 Err(ErrorContext::new_missing(
7023 "ActCtAttrs",
7024 "NatIpv6Max",
7025 self.orig_loc,
7026 self.buf.as_ptr() as usize,
7027 ))
7028 }
7029 pub fn get_nat_port_min(&self) -> Result<u16, ErrorContext> {
7030 let mut iter = self.clone();
7031 iter.pos = 0;
7032 for attr in iter {
7033 if let Ok(ActCtAttrs::NatPortMin(val)) = attr {
7034 return Ok(val);
7035 }
7036 }
7037 Err(ErrorContext::new_missing(
7038 "ActCtAttrs",
7039 "NatPortMin",
7040 self.orig_loc,
7041 self.buf.as_ptr() as usize,
7042 ))
7043 }
7044 pub fn get_nat_port_max(&self) -> Result<u16, ErrorContext> {
7045 let mut iter = self.clone();
7046 iter.pos = 0;
7047 for attr in iter {
7048 if let Ok(ActCtAttrs::NatPortMax(val)) = attr {
7049 return Ok(val);
7050 }
7051 }
7052 Err(ErrorContext::new_missing(
7053 "ActCtAttrs",
7054 "NatPortMax",
7055 self.orig_loc,
7056 self.buf.as_ptr() as usize,
7057 ))
7058 }
7059 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
7060 let mut iter = self.clone();
7061 iter.pos = 0;
7062 for attr in iter {
7063 if let Ok(ActCtAttrs::Pad(val)) = attr {
7064 return Ok(val);
7065 }
7066 }
7067 Err(ErrorContext::new_missing(
7068 "ActCtAttrs",
7069 "Pad",
7070 self.orig_loc,
7071 self.buf.as_ptr() as usize,
7072 ))
7073 }
7074 pub fn get_helper_name(&self) -> Result<&'a CStr, ErrorContext> {
7075 let mut iter = self.clone();
7076 iter.pos = 0;
7077 for attr in iter {
7078 if let Ok(ActCtAttrs::HelperName(val)) = attr {
7079 return Ok(val);
7080 }
7081 }
7082 Err(ErrorContext::new_missing(
7083 "ActCtAttrs",
7084 "HelperName",
7085 self.orig_loc,
7086 self.buf.as_ptr() as usize,
7087 ))
7088 }
7089 pub fn get_helper_family(&self) -> Result<u8, ErrorContext> {
7090 let mut iter = self.clone();
7091 iter.pos = 0;
7092 for attr in iter {
7093 if let Ok(ActCtAttrs::HelperFamily(val)) = attr {
7094 return Ok(val);
7095 }
7096 }
7097 Err(ErrorContext::new_missing(
7098 "ActCtAttrs",
7099 "HelperFamily",
7100 self.orig_loc,
7101 self.buf.as_ptr() as usize,
7102 ))
7103 }
7104 pub fn get_helper_proto(&self) -> Result<u8, ErrorContext> {
7105 let mut iter = self.clone();
7106 iter.pos = 0;
7107 for attr in iter {
7108 if let Ok(ActCtAttrs::HelperProto(val)) = attr {
7109 return Ok(val);
7110 }
7111 }
7112 Err(ErrorContext::new_missing(
7113 "ActCtAttrs",
7114 "HelperProto",
7115 self.orig_loc,
7116 self.buf.as_ptr() as usize,
7117 ))
7118 }
7119}
7120impl ActCtAttrs<'_> {
7121 pub fn new<'a>(buf: &'a [u8]) -> IterableActCtAttrs<'a> {
7122 IterableActCtAttrs::with_loc(buf, buf.as_ptr() as usize)
7123 }
7124 fn attr_from_type(r#type: u16) -> Option<&'static str> {
7125 let res = match r#type {
7126 1u16 => "Parms",
7127 2u16 => "Tm",
7128 3u16 => "Action",
7129 4u16 => "Zone",
7130 5u16 => "Mark",
7131 6u16 => "MarkMask",
7132 7u16 => "Labels",
7133 8u16 => "LabelsMask",
7134 9u16 => "NatIpv4Min",
7135 10u16 => "NatIpv4Max",
7136 11u16 => "NatIpv6Min",
7137 12u16 => "NatIpv6Max",
7138 13u16 => "NatPortMin",
7139 14u16 => "NatPortMax",
7140 15u16 => "Pad",
7141 16u16 => "HelperName",
7142 17u16 => "HelperFamily",
7143 18u16 => "HelperProto",
7144 _ => return None,
7145 };
7146 Some(res)
7147 }
7148}
7149#[derive(Clone, Copy, Default)]
7150pub struct IterableActCtAttrs<'a> {
7151 buf: &'a [u8],
7152 pos: usize,
7153 orig_loc: usize,
7154}
7155impl<'a> IterableActCtAttrs<'a> {
7156 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
7157 Self {
7158 buf,
7159 pos: 0,
7160 orig_loc,
7161 }
7162 }
7163 pub fn get_buf(&self) -> &'a [u8] {
7164 self.buf
7165 }
7166}
7167impl<'a> Iterator for IterableActCtAttrs<'a> {
7168 type Item = Result<ActCtAttrs<'a>, ErrorContext>;
7169 fn next(&mut self) -> Option<Self::Item> {
7170 let mut pos;
7171 let mut r#type;
7172 loop {
7173 pos = self.pos;
7174 r#type = None;
7175 if self.buf.len() == self.pos {
7176 return None;
7177 }
7178 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
7179 self.pos = self.buf.len();
7180 break;
7181 };
7182 r#type = Some(header.r#type);
7183 let res = match header.r#type {
7184 1u16 => ActCtAttrs::Parms({
7185 let res = Some(next);
7186 let Some(val) = res else { break };
7187 val
7188 }),
7189 2u16 => ActCtAttrs::Tm({
7190 let res = Some(TcfT::new_from_zeroed(next));
7191 let Some(val) = res else { break };
7192 val
7193 }),
7194 3u16 => ActCtAttrs::Action({
7195 let res = parse_u16(next);
7196 let Some(val) = res else { break };
7197 val
7198 }),
7199 4u16 => ActCtAttrs::Zone({
7200 let res = parse_u16(next);
7201 let Some(val) = res else { break };
7202 val
7203 }),
7204 5u16 => ActCtAttrs::Mark({
7205 let res = parse_u32(next);
7206 let Some(val) = res else { break };
7207 val
7208 }),
7209 6u16 => ActCtAttrs::MarkMask({
7210 let res = parse_u32(next);
7211 let Some(val) = res else { break };
7212 val
7213 }),
7214 7u16 => ActCtAttrs::Labels({
7215 let res = Some(next);
7216 let Some(val) = res else { break };
7217 val
7218 }),
7219 8u16 => ActCtAttrs::LabelsMask({
7220 let res = Some(next);
7221 let Some(val) = res else { break };
7222 val
7223 }),
7224 9u16 => ActCtAttrs::NatIpv4Min({
7225 let res = parse_be_u32(next);
7226 let Some(val) = res else { break };
7227 val
7228 }),
7229 10u16 => ActCtAttrs::NatIpv4Max({
7230 let res = parse_be_u32(next);
7231 let Some(val) = res else { break };
7232 val
7233 }),
7234 11u16 => ActCtAttrs::NatIpv6Min({
7235 let res = Some(next);
7236 let Some(val) = res else { break };
7237 val
7238 }),
7239 12u16 => ActCtAttrs::NatIpv6Max({
7240 let res = Some(next);
7241 let Some(val) = res else { break };
7242 val
7243 }),
7244 13u16 => ActCtAttrs::NatPortMin({
7245 let res = parse_be_u16(next);
7246 let Some(val) = res else { break };
7247 val
7248 }),
7249 14u16 => ActCtAttrs::NatPortMax({
7250 let res = parse_be_u16(next);
7251 let Some(val) = res else { break };
7252 val
7253 }),
7254 15u16 => ActCtAttrs::Pad({
7255 let res = Some(next);
7256 let Some(val) = res else { break };
7257 val
7258 }),
7259 16u16 => ActCtAttrs::HelperName({
7260 let res = CStr::from_bytes_with_nul(next).ok();
7261 let Some(val) = res else { break };
7262 val
7263 }),
7264 17u16 => ActCtAttrs::HelperFamily({
7265 let res = parse_u8(next);
7266 let Some(val) = res else { break };
7267 val
7268 }),
7269 18u16 => ActCtAttrs::HelperProto({
7270 let res = parse_u8(next);
7271 let Some(val) = res else { break };
7272 val
7273 }),
7274 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
7275 n => continue,
7276 };
7277 return Some(Ok(res));
7278 }
7279 Some(Err(ErrorContext::new(
7280 "ActCtAttrs",
7281 r#type.and_then(|t| ActCtAttrs::attr_from_type(t)),
7282 self.orig_loc,
7283 self.buf.as_ptr().wrapping_add(pos) as usize,
7284 )))
7285 }
7286}
7287impl<'a> std::fmt::Debug for IterableActCtAttrs<'_> {
7288 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7289 let mut fmt = f.debug_struct("ActCtAttrs");
7290 for attr in self.clone() {
7291 let attr = match attr {
7292 Ok(a) => a,
7293 Err(err) => {
7294 fmt.finish()?;
7295 f.write_str("Err(")?;
7296 err.fmt(f)?;
7297 return f.write_str(")");
7298 }
7299 };
7300 match attr {
7301 ActCtAttrs::Parms(val) => fmt.field("Parms", &val),
7302 ActCtAttrs::Tm(val) => fmt.field("Tm", &val),
7303 ActCtAttrs::Action(val) => fmt.field("Action", &val),
7304 ActCtAttrs::Zone(val) => fmt.field("Zone", &val),
7305 ActCtAttrs::Mark(val) => fmt.field("Mark", &val),
7306 ActCtAttrs::MarkMask(val) => fmt.field("MarkMask", &val),
7307 ActCtAttrs::Labels(val) => fmt.field("Labels", &val),
7308 ActCtAttrs::LabelsMask(val) => fmt.field("LabelsMask", &val),
7309 ActCtAttrs::NatIpv4Min(val) => fmt.field("NatIpv4Min", &val),
7310 ActCtAttrs::NatIpv4Max(val) => fmt.field("NatIpv4Max", &val),
7311 ActCtAttrs::NatIpv6Min(val) => fmt.field("NatIpv6Min", &val),
7312 ActCtAttrs::NatIpv6Max(val) => fmt.field("NatIpv6Max", &val),
7313 ActCtAttrs::NatPortMin(val) => fmt.field("NatPortMin", &val),
7314 ActCtAttrs::NatPortMax(val) => fmt.field("NatPortMax", &val),
7315 ActCtAttrs::Pad(val) => fmt.field("Pad", &val),
7316 ActCtAttrs::HelperName(val) => fmt.field("HelperName", &val),
7317 ActCtAttrs::HelperFamily(val) => fmt.field("HelperFamily", &val),
7318 ActCtAttrs::HelperProto(val) => fmt.field("HelperProto", &val),
7319 };
7320 }
7321 fmt.finish()
7322 }
7323}
7324impl IterableActCtAttrs<'_> {
7325 pub fn lookup_attr(
7326 &self,
7327 offset: usize,
7328 missing_type: Option<u16>,
7329 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
7330 let mut stack = Vec::new();
7331 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
7332 if missing_type.is_some() && cur == offset {
7333 stack.push(("ActCtAttrs", offset));
7334 return (
7335 stack,
7336 missing_type.and_then(|t| ActCtAttrs::attr_from_type(t)),
7337 );
7338 }
7339 if cur > offset || cur + self.buf.len() < offset {
7340 return (stack, None);
7341 }
7342 let mut attrs = self.clone();
7343 let mut last_off = cur + attrs.pos;
7344 while let Some(attr) = attrs.next() {
7345 let Ok(attr) = attr else { break };
7346 match attr {
7347 ActCtAttrs::Parms(val) => {
7348 if last_off == offset {
7349 stack.push(("Parms", last_off));
7350 break;
7351 }
7352 }
7353 ActCtAttrs::Tm(val) => {
7354 if last_off == offset {
7355 stack.push(("Tm", last_off));
7356 break;
7357 }
7358 }
7359 ActCtAttrs::Action(val) => {
7360 if last_off == offset {
7361 stack.push(("Action", last_off));
7362 break;
7363 }
7364 }
7365 ActCtAttrs::Zone(val) => {
7366 if last_off == offset {
7367 stack.push(("Zone", last_off));
7368 break;
7369 }
7370 }
7371 ActCtAttrs::Mark(val) => {
7372 if last_off == offset {
7373 stack.push(("Mark", last_off));
7374 break;
7375 }
7376 }
7377 ActCtAttrs::MarkMask(val) => {
7378 if last_off == offset {
7379 stack.push(("MarkMask", last_off));
7380 break;
7381 }
7382 }
7383 ActCtAttrs::Labels(val) => {
7384 if last_off == offset {
7385 stack.push(("Labels", last_off));
7386 break;
7387 }
7388 }
7389 ActCtAttrs::LabelsMask(val) => {
7390 if last_off == offset {
7391 stack.push(("LabelsMask", last_off));
7392 break;
7393 }
7394 }
7395 ActCtAttrs::NatIpv4Min(val) => {
7396 if last_off == offset {
7397 stack.push(("NatIpv4Min", last_off));
7398 break;
7399 }
7400 }
7401 ActCtAttrs::NatIpv4Max(val) => {
7402 if last_off == offset {
7403 stack.push(("NatIpv4Max", last_off));
7404 break;
7405 }
7406 }
7407 ActCtAttrs::NatIpv6Min(val) => {
7408 if last_off == offset {
7409 stack.push(("NatIpv6Min", last_off));
7410 break;
7411 }
7412 }
7413 ActCtAttrs::NatIpv6Max(val) => {
7414 if last_off == offset {
7415 stack.push(("NatIpv6Max", last_off));
7416 break;
7417 }
7418 }
7419 ActCtAttrs::NatPortMin(val) => {
7420 if last_off == offset {
7421 stack.push(("NatPortMin", last_off));
7422 break;
7423 }
7424 }
7425 ActCtAttrs::NatPortMax(val) => {
7426 if last_off == offset {
7427 stack.push(("NatPortMax", last_off));
7428 break;
7429 }
7430 }
7431 ActCtAttrs::Pad(val) => {
7432 if last_off == offset {
7433 stack.push(("Pad", last_off));
7434 break;
7435 }
7436 }
7437 ActCtAttrs::HelperName(val) => {
7438 if last_off == offset {
7439 stack.push(("HelperName", last_off));
7440 break;
7441 }
7442 }
7443 ActCtAttrs::HelperFamily(val) => {
7444 if last_off == offset {
7445 stack.push(("HelperFamily", last_off));
7446 break;
7447 }
7448 }
7449 ActCtAttrs::HelperProto(val) => {
7450 if last_off == offset {
7451 stack.push(("HelperProto", last_off));
7452 break;
7453 }
7454 }
7455 _ => {}
7456 };
7457 last_off = cur + attrs.pos;
7458 }
7459 if !stack.is_empty() {
7460 stack.push(("ActCtAttrs", cur));
7461 }
7462 (stack, None)
7463 }
7464}
7465#[derive(Clone)]
7466pub enum ActCtinfoAttrs<'a> {
7467 Pad(&'a [u8]),
7468 Tm(TcfT),
7469 Act(&'a [u8]),
7470 Zone(u16),
7471 ParmsDscpMask(u32),
7472 ParmsDscpStatemask(u32),
7473 ParmsCpmarkMask(u32),
7474 StatsDscpSet(u64),
7475 StatsDscpError(u64),
7476 StatsCpmarkSet(u64),
7477}
7478impl<'a> IterableActCtinfoAttrs<'a> {
7479 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
7480 let mut iter = self.clone();
7481 iter.pos = 0;
7482 for attr in iter {
7483 if let Ok(ActCtinfoAttrs::Pad(val)) = attr {
7484 return Ok(val);
7485 }
7486 }
7487 Err(ErrorContext::new_missing(
7488 "ActCtinfoAttrs",
7489 "Pad",
7490 self.orig_loc,
7491 self.buf.as_ptr() as usize,
7492 ))
7493 }
7494 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
7495 let mut iter = self.clone();
7496 iter.pos = 0;
7497 for attr in iter {
7498 if let Ok(ActCtinfoAttrs::Tm(val)) = attr {
7499 return Ok(val);
7500 }
7501 }
7502 Err(ErrorContext::new_missing(
7503 "ActCtinfoAttrs",
7504 "Tm",
7505 self.orig_loc,
7506 self.buf.as_ptr() as usize,
7507 ))
7508 }
7509 pub fn get_act(&self) -> Result<&'a [u8], ErrorContext> {
7510 let mut iter = self.clone();
7511 iter.pos = 0;
7512 for attr in iter {
7513 if let Ok(ActCtinfoAttrs::Act(val)) = attr {
7514 return Ok(val);
7515 }
7516 }
7517 Err(ErrorContext::new_missing(
7518 "ActCtinfoAttrs",
7519 "Act",
7520 self.orig_loc,
7521 self.buf.as_ptr() as usize,
7522 ))
7523 }
7524 pub fn get_zone(&self) -> Result<u16, ErrorContext> {
7525 let mut iter = self.clone();
7526 iter.pos = 0;
7527 for attr in iter {
7528 if let Ok(ActCtinfoAttrs::Zone(val)) = attr {
7529 return Ok(val);
7530 }
7531 }
7532 Err(ErrorContext::new_missing(
7533 "ActCtinfoAttrs",
7534 "Zone",
7535 self.orig_loc,
7536 self.buf.as_ptr() as usize,
7537 ))
7538 }
7539 pub fn get_parms_dscp_mask(&self) -> Result<u32, ErrorContext> {
7540 let mut iter = self.clone();
7541 iter.pos = 0;
7542 for attr in iter {
7543 if let Ok(ActCtinfoAttrs::ParmsDscpMask(val)) = attr {
7544 return Ok(val);
7545 }
7546 }
7547 Err(ErrorContext::new_missing(
7548 "ActCtinfoAttrs",
7549 "ParmsDscpMask",
7550 self.orig_loc,
7551 self.buf.as_ptr() as usize,
7552 ))
7553 }
7554 pub fn get_parms_dscp_statemask(&self) -> Result<u32, ErrorContext> {
7555 let mut iter = self.clone();
7556 iter.pos = 0;
7557 for attr in iter {
7558 if let Ok(ActCtinfoAttrs::ParmsDscpStatemask(val)) = attr {
7559 return Ok(val);
7560 }
7561 }
7562 Err(ErrorContext::new_missing(
7563 "ActCtinfoAttrs",
7564 "ParmsDscpStatemask",
7565 self.orig_loc,
7566 self.buf.as_ptr() as usize,
7567 ))
7568 }
7569 pub fn get_parms_cpmark_mask(&self) -> Result<u32, ErrorContext> {
7570 let mut iter = self.clone();
7571 iter.pos = 0;
7572 for attr in iter {
7573 if let Ok(ActCtinfoAttrs::ParmsCpmarkMask(val)) = attr {
7574 return Ok(val);
7575 }
7576 }
7577 Err(ErrorContext::new_missing(
7578 "ActCtinfoAttrs",
7579 "ParmsCpmarkMask",
7580 self.orig_loc,
7581 self.buf.as_ptr() as usize,
7582 ))
7583 }
7584 pub fn get_stats_dscp_set(&self) -> Result<u64, ErrorContext> {
7585 let mut iter = self.clone();
7586 iter.pos = 0;
7587 for attr in iter {
7588 if let Ok(ActCtinfoAttrs::StatsDscpSet(val)) = attr {
7589 return Ok(val);
7590 }
7591 }
7592 Err(ErrorContext::new_missing(
7593 "ActCtinfoAttrs",
7594 "StatsDscpSet",
7595 self.orig_loc,
7596 self.buf.as_ptr() as usize,
7597 ))
7598 }
7599 pub fn get_stats_dscp_error(&self) -> Result<u64, ErrorContext> {
7600 let mut iter = self.clone();
7601 iter.pos = 0;
7602 for attr in iter {
7603 if let Ok(ActCtinfoAttrs::StatsDscpError(val)) = attr {
7604 return Ok(val);
7605 }
7606 }
7607 Err(ErrorContext::new_missing(
7608 "ActCtinfoAttrs",
7609 "StatsDscpError",
7610 self.orig_loc,
7611 self.buf.as_ptr() as usize,
7612 ))
7613 }
7614 pub fn get_stats_cpmark_set(&self) -> Result<u64, ErrorContext> {
7615 let mut iter = self.clone();
7616 iter.pos = 0;
7617 for attr in iter {
7618 if let Ok(ActCtinfoAttrs::StatsCpmarkSet(val)) = attr {
7619 return Ok(val);
7620 }
7621 }
7622 Err(ErrorContext::new_missing(
7623 "ActCtinfoAttrs",
7624 "StatsCpmarkSet",
7625 self.orig_loc,
7626 self.buf.as_ptr() as usize,
7627 ))
7628 }
7629}
7630impl ActCtinfoAttrs<'_> {
7631 pub fn new<'a>(buf: &'a [u8]) -> IterableActCtinfoAttrs<'a> {
7632 IterableActCtinfoAttrs::with_loc(buf, buf.as_ptr() as usize)
7633 }
7634 fn attr_from_type(r#type: u16) -> Option<&'static str> {
7635 let res = match r#type {
7636 1u16 => "Pad",
7637 2u16 => "Tm",
7638 3u16 => "Act",
7639 4u16 => "Zone",
7640 5u16 => "ParmsDscpMask",
7641 6u16 => "ParmsDscpStatemask",
7642 7u16 => "ParmsCpmarkMask",
7643 8u16 => "StatsDscpSet",
7644 9u16 => "StatsDscpError",
7645 10u16 => "StatsCpmarkSet",
7646 _ => return None,
7647 };
7648 Some(res)
7649 }
7650}
7651#[derive(Clone, Copy, Default)]
7652pub struct IterableActCtinfoAttrs<'a> {
7653 buf: &'a [u8],
7654 pos: usize,
7655 orig_loc: usize,
7656}
7657impl<'a> IterableActCtinfoAttrs<'a> {
7658 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
7659 Self {
7660 buf,
7661 pos: 0,
7662 orig_loc,
7663 }
7664 }
7665 pub fn get_buf(&self) -> &'a [u8] {
7666 self.buf
7667 }
7668}
7669impl<'a> Iterator for IterableActCtinfoAttrs<'a> {
7670 type Item = Result<ActCtinfoAttrs<'a>, ErrorContext>;
7671 fn next(&mut self) -> Option<Self::Item> {
7672 let mut pos;
7673 let mut r#type;
7674 loop {
7675 pos = self.pos;
7676 r#type = None;
7677 if self.buf.len() == self.pos {
7678 return None;
7679 }
7680 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
7681 self.pos = self.buf.len();
7682 break;
7683 };
7684 r#type = Some(header.r#type);
7685 let res = match header.r#type {
7686 1u16 => ActCtinfoAttrs::Pad({
7687 let res = Some(next);
7688 let Some(val) = res else { break };
7689 val
7690 }),
7691 2u16 => ActCtinfoAttrs::Tm({
7692 let res = Some(TcfT::new_from_zeroed(next));
7693 let Some(val) = res else { break };
7694 val
7695 }),
7696 3u16 => ActCtinfoAttrs::Act({
7697 let res = Some(next);
7698 let Some(val) = res else { break };
7699 val
7700 }),
7701 4u16 => ActCtinfoAttrs::Zone({
7702 let res = parse_u16(next);
7703 let Some(val) = res else { break };
7704 val
7705 }),
7706 5u16 => ActCtinfoAttrs::ParmsDscpMask({
7707 let res = parse_u32(next);
7708 let Some(val) = res else { break };
7709 val
7710 }),
7711 6u16 => ActCtinfoAttrs::ParmsDscpStatemask({
7712 let res = parse_u32(next);
7713 let Some(val) = res else { break };
7714 val
7715 }),
7716 7u16 => ActCtinfoAttrs::ParmsCpmarkMask({
7717 let res = parse_u32(next);
7718 let Some(val) = res else { break };
7719 val
7720 }),
7721 8u16 => ActCtinfoAttrs::StatsDscpSet({
7722 let res = parse_u64(next);
7723 let Some(val) = res else { break };
7724 val
7725 }),
7726 9u16 => ActCtinfoAttrs::StatsDscpError({
7727 let res = parse_u64(next);
7728 let Some(val) = res else { break };
7729 val
7730 }),
7731 10u16 => ActCtinfoAttrs::StatsCpmarkSet({
7732 let res = parse_u64(next);
7733 let Some(val) = res else { break };
7734 val
7735 }),
7736 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
7737 n => continue,
7738 };
7739 return Some(Ok(res));
7740 }
7741 Some(Err(ErrorContext::new(
7742 "ActCtinfoAttrs",
7743 r#type.and_then(|t| ActCtinfoAttrs::attr_from_type(t)),
7744 self.orig_loc,
7745 self.buf.as_ptr().wrapping_add(pos) as usize,
7746 )))
7747 }
7748}
7749impl<'a> std::fmt::Debug for IterableActCtinfoAttrs<'_> {
7750 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7751 let mut fmt = f.debug_struct("ActCtinfoAttrs");
7752 for attr in self.clone() {
7753 let attr = match attr {
7754 Ok(a) => a,
7755 Err(err) => {
7756 fmt.finish()?;
7757 f.write_str("Err(")?;
7758 err.fmt(f)?;
7759 return f.write_str(")");
7760 }
7761 };
7762 match attr {
7763 ActCtinfoAttrs::Pad(val) => fmt.field("Pad", &val),
7764 ActCtinfoAttrs::Tm(val) => fmt.field("Tm", &val),
7765 ActCtinfoAttrs::Act(val) => fmt.field("Act", &val),
7766 ActCtinfoAttrs::Zone(val) => fmt.field("Zone", &val),
7767 ActCtinfoAttrs::ParmsDscpMask(val) => fmt.field("ParmsDscpMask", &val),
7768 ActCtinfoAttrs::ParmsDscpStatemask(val) => fmt.field("ParmsDscpStatemask", &val),
7769 ActCtinfoAttrs::ParmsCpmarkMask(val) => fmt.field("ParmsCpmarkMask", &val),
7770 ActCtinfoAttrs::StatsDscpSet(val) => fmt.field("StatsDscpSet", &val),
7771 ActCtinfoAttrs::StatsDscpError(val) => fmt.field("StatsDscpError", &val),
7772 ActCtinfoAttrs::StatsCpmarkSet(val) => fmt.field("StatsCpmarkSet", &val),
7773 };
7774 }
7775 fmt.finish()
7776 }
7777}
7778impl IterableActCtinfoAttrs<'_> {
7779 pub fn lookup_attr(
7780 &self,
7781 offset: usize,
7782 missing_type: Option<u16>,
7783 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
7784 let mut stack = Vec::new();
7785 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
7786 if missing_type.is_some() && cur == offset {
7787 stack.push(("ActCtinfoAttrs", offset));
7788 return (
7789 stack,
7790 missing_type.and_then(|t| ActCtinfoAttrs::attr_from_type(t)),
7791 );
7792 }
7793 if cur > offset || cur + self.buf.len() < offset {
7794 return (stack, None);
7795 }
7796 let mut attrs = self.clone();
7797 let mut last_off = cur + attrs.pos;
7798 while let Some(attr) = attrs.next() {
7799 let Ok(attr) = attr else { break };
7800 match attr {
7801 ActCtinfoAttrs::Pad(val) => {
7802 if last_off == offset {
7803 stack.push(("Pad", last_off));
7804 break;
7805 }
7806 }
7807 ActCtinfoAttrs::Tm(val) => {
7808 if last_off == offset {
7809 stack.push(("Tm", last_off));
7810 break;
7811 }
7812 }
7813 ActCtinfoAttrs::Act(val) => {
7814 if last_off == offset {
7815 stack.push(("Act", last_off));
7816 break;
7817 }
7818 }
7819 ActCtinfoAttrs::Zone(val) => {
7820 if last_off == offset {
7821 stack.push(("Zone", last_off));
7822 break;
7823 }
7824 }
7825 ActCtinfoAttrs::ParmsDscpMask(val) => {
7826 if last_off == offset {
7827 stack.push(("ParmsDscpMask", last_off));
7828 break;
7829 }
7830 }
7831 ActCtinfoAttrs::ParmsDscpStatemask(val) => {
7832 if last_off == offset {
7833 stack.push(("ParmsDscpStatemask", last_off));
7834 break;
7835 }
7836 }
7837 ActCtinfoAttrs::ParmsCpmarkMask(val) => {
7838 if last_off == offset {
7839 stack.push(("ParmsCpmarkMask", last_off));
7840 break;
7841 }
7842 }
7843 ActCtinfoAttrs::StatsDscpSet(val) => {
7844 if last_off == offset {
7845 stack.push(("StatsDscpSet", last_off));
7846 break;
7847 }
7848 }
7849 ActCtinfoAttrs::StatsDscpError(val) => {
7850 if last_off == offset {
7851 stack.push(("StatsDscpError", last_off));
7852 break;
7853 }
7854 }
7855 ActCtinfoAttrs::StatsCpmarkSet(val) => {
7856 if last_off == offset {
7857 stack.push(("StatsCpmarkSet", last_off));
7858 break;
7859 }
7860 }
7861 _ => {}
7862 };
7863 last_off = cur + attrs.pos;
7864 }
7865 if !stack.is_empty() {
7866 stack.push(("ActCtinfoAttrs", cur));
7867 }
7868 (stack, None)
7869 }
7870}
7871#[derive(Clone)]
7872pub enum ActGateAttrs<'a> {
7873 Tm(TcfT),
7874 Parms(&'a [u8]),
7875 Pad(&'a [u8]),
7876 Priority(i32),
7877 EntryList(&'a [u8]),
7878 BaseTime(u64),
7879 CycleTime(u64),
7880 CycleTimeExt(u64),
7881 Flags(u32),
7882 Clockid(i32),
7883}
7884impl<'a> IterableActGateAttrs<'a> {
7885 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
7886 let mut iter = self.clone();
7887 iter.pos = 0;
7888 for attr in iter {
7889 if let Ok(ActGateAttrs::Tm(val)) = attr {
7890 return Ok(val);
7891 }
7892 }
7893 Err(ErrorContext::new_missing(
7894 "ActGateAttrs",
7895 "Tm",
7896 self.orig_loc,
7897 self.buf.as_ptr() as usize,
7898 ))
7899 }
7900 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
7901 let mut iter = self.clone();
7902 iter.pos = 0;
7903 for attr in iter {
7904 if let Ok(ActGateAttrs::Parms(val)) = attr {
7905 return Ok(val);
7906 }
7907 }
7908 Err(ErrorContext::new_missing(
7909 "ActGateAttrs",
7910 "Parms",
7911 self.orig_loc,
7912 self.buf.as_ptr() as usize,
7913 ))
7914 }
7915 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
7916 let mut iter = self.clone();
7917 iter.pos = 0;
7918 for attr in iter {
7919 if let Ok(ActGateAttrs::Pad(val)) = attr {
7920 return Ok(val);
7921 }
7922 }
7923 Err(ErrorContext::new_missing(
7924 "ActGateAttrs",
7925 "Pad",
7926 self.orig_loc,
7927 self.buf.as_ptr() as usize,
7928 ))
7929 }
7930 pub fn get_priority(&self) -> Result<i32, ErrorContext> {
7931 let mut iter = self.clone();
7932 iter.pos = 0;
7933 for attr in iter {
7934 if let Ok(ActGateAttrs::Priority(val)) = attr {
7935 return Ok(val);
7936 }
7937 }
7938 Err(ErrorContext::new_missing(
7939 "ActGateAttrs",
7940 "Priority",
7941 self.orig_loc,
7942 self.buf.as_ptr() as usize,
7943 ))
7944 }
7945 pub fn get_entry_list(&self) -> Result<&'a [u8], ErrorContext> {
7946 let mut iter = self.clone();
7947 iter.pos = 0;
7948 for attr in iter {
7949 if let Ok(ActGateAttrs::EntryList(val)) = attr {
7950 return Ok(val);
7951 }
7952 }
7953 Err(ErrorContext::new_missing(
7954 "ActGateAttrs",
7955 "EntryList",
7956 self.orig_loc,
7957 self.buf.as_ptr() as usize,
7958 ))
7959 }
7960 pub fn get_base_time(&self) -> Result<u64, ErrorContext> {
7961 let mut iter = self.clone();
7962 iter.pos = 0;
7963 for attr in iter {
7964 if let Ok(ActGateAttrs::BaseTime(val)) = attr {
7965 return Ok(val);
7966 }
7967 }
7968 Err(ErrorContext::new_missing(
7969 "ActGateAttrs",
7970 "BaseTime",
7971 self.orig_loc,
7972 self.buf.as_ptr() as usize,
7973 ))
7974 }
7975 pub fn get_cycle_time(&self) -> Result<u64, ErrorContext> {
7976 let mut iter = self.clone();
7977 iter.pos = 0;
7978 for attr in iter {
7979 if let Ok(ActGateAttrs::CycleTime(val)) = attr {
7980 return Ok(val);
7981 }
7982 }
7983 Err(ErrorContext::new_missing(
7984 "ActGateAttrs",
7985 "CycleTime",
7986 self.orig_loc,
7987 self.buf.as_ptr() as usize,
7988 ))
7989 }
7990 pub fn get_cycle_time_ext(&self) -> Result<u64, ErrorContext> {
7991 let mut iter = self.clone();
7992 iter.pos = 0;
7993 for attr in iter {
7994 if let Ok(ActGateAttrs::CycleTimeExt(val)) = attr {
7995 return Ok(val);
7996 }
7997 }
7998 Err(ErrorContext::new_missing(
7999 "ActGateAttrs",
8000 "CycleTimeExt",
8001 self.orig_loc,
8002 self.buf.as_ptr() as usize,
8003 ))
8004 }
8005 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
8006 let mut iter = self.clone();
8007 iter.pos = 0;
8008 for attr in iter {
8009 if let Ok(ActGateAttrs::Flags(val)) = attr {
8010 return Ok(val);
8011 }
8012 }
8013 Err(ErrorContext::new_missing(
8014 "ActGateAttrs",
8015 "Flags",
8016 self.orig_loc,
8017 self.buf.as_ptr() as usize,
8018 ))
8019 }
8020 pub fn get_clockid(&self) -> Result<i32, ErrorContext> {
8021 let mut iter = self.clone();
8022 iter.pos = 0;
8023 for attr in iter {
8024 if let Ok(ActGateAttrs::Clockid(val)) = attr {
8025 return Ok(val);
8026 }
8027 }
8028 Err(ErrorContext::new_missing(
8029 "ActGateAttrs",
8030 "Clockid",
8031 self.orig_loc,
8032 self.buf.as_ptr() as usize,
8033 ))
8034 }
8035}
8036impl ActGateAttrs<'_> {
8037 pub fn new<'a>(buf: &'a [u8]) -> IterableActGateAttrs<'a> {
8038 IterableActGateAttrs::with_loc(buf, buf.as_ptr() as usize)
8039 }
8040 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8041 let res = match r#type {
8042 1u16 => "Tm",
8043 2u16 => "Parms",
8044 3u16 => "Pad",
8045 4u16 => "Priority",
8046 5u16 => "EntryList",
8047 6u16 => "BaseTime",
8048 7u16 => "CycleTime",
8049 8u16 => "CycleTimeExt",
8050 9u16 => "Flags",
8051 10u16 => "Clockid",
8052 _ => return None,
8053 };
8054 Some(res)
8055 }
8056}
8057#[derive(Clone, Copy, Default)]
8058pub struct IterableActGateAttrs<'a> {
8059 buf: &'a [u8],
8060 pos: usize,
8061 orig_loc: usize,
8062}
8063impl<'a> IterableActGateAttrs<'a> {
8064 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
8065 Self {
8066 buf,
8067 pos: 0,
8068 orig_loc,
8069 }
8070 }
8071 pub fn get_buf(&self) -> &'a [u8] {
8072 self.buf
8073 }
8074}
8075impl<'a> Iterator for IterableActGateAttrs<'a> {
8076 type Item = Result<ActGateAttrs<'a>, ErrorContext>;
8077 fn next(&mut self) -> Option<Self::Item> {
8078 let mut pos;
8079 let mut r#type;
8080 loop {
8081 pos = self.pos;
8082 r#type = None;
8083 if self.buf.len() == self.pos {
8084 return None;
8085 }
8086 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
8087 self.pos = self.buf.len();
8088 break;
8089 };
8090 r#type = Some(header.r#type);
8091 let res = match header.r#type {
8092 1u16 => ActGateAttrs::Tm({
8093 let res = Some(TcfT::new_from_zeroed(next));
8094 let Some(val) = res else { break };
8095 val
8096 }),
8097 2u16 => ActGateAttrs::Parms({
8098 let res = Some(next);
8099 let Some(val) = res else { break };
8100 val
8101 }),
8102 3u16 => ActGateAttrs::Pad({
8103 let res = Some(next);
8104 let Some(val) = res else { break };
8105 val
8106 }),
8107 4u16 => ActGateAttrs::Priority({
8108 let res = parse_i32(next);
8109 let Some(val) = res else { break };
8110 val
8111 }),
8112 5u16 => ActGateAttrs::EntryList({
8113 let res = Some(next);
8114 let Some(val) = res else { break };
8115 val
8116 }),
8117 6u16 => ActGateAttrs::BaseTime({
8118 let res = parse_u64(next);
8119 let Some(val) = res else { break };
8120 val
8121 }),
8122 7u16 => ActGateAttrs::CycleTime({
8123 let res = parse_u64(next);
8124 let Some(val) = res else { break };
8125 val
8126 }),
8127 8u16 => ActGateAttrs::CycleTimeExt({
8128 let res = parse_u64(next);
8129 let Some(val) = res else { break };
8130 val
8131 }),
8132 9u16 => ActGateAttrs::Flags({
8133 let res = parse_u32(next);
8134 let Some(val) = res else { break };
8135 val
8136 }),
8137 10u16 => ActGateAttrs::Clockid({
8138 let res = parse_i32(next);
8139 let Some(val) = res else { break };
8140 val
8141 }),
8142 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
8143 n => continue,
8144 };
8145 return Some(Ok(res));
8146 }
8147 Some(Err(ErrorContext::new(
8148 "ActGateAttrs",
8149 r#type.and_then(|t| ActGateAttrs::attr_from_type(t)),
8150 self.orig_loc,
8151 self.buf.as_ptr().wrapping_add(pos) as usize,
8152 )))
8153 }
8154}
8155impl<'a> std::fmt::Debug for IterableActGateAttrs<'_> {
8156 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8157 let mut fmt = f.debug_struct("ActGateAttrs");
8158 for attr in self.clone() {
8159 let attr = match attr {
8160 Ok(a) => a,
8161 Err(err) => {
8162 fmt.finish()?;
8163 f.write_str("Err(")?;
8164 err.fmt(f)?;
8165 return f.write_str(")");
8166 }
8167 };
8168 match attr {
8169 ActGateAttrs::Tm(val) => fmt.field("Tm", &val),
8170 ActGateAttrs::Parms(val) => fmt.field("Parms", &val),
8171 ActGateAttrs::Pad(val) => fmt.field("Pad", &val),
8172 ActGateAttrs::Priority(val) => fmt.field("Priority", &val),
8173 ActGateAttrs::EntryList(val) => fmt.field("EntryList", &val),
8174 ActGateAttrs::BaseTime(val) => fmt.field("BaseTime", &val),
8175 ActGateAttrs::CycleTime(val) => fmt.field("CycleTime", &val),
8176 ActGateAttrs::CycleTimeExt(val) => fmt.field("CycleTimeExt", &val),
8177 ActGateAttrs::Flags(val) => fmt.field("Flags", &val),
8178 ActGateAttrs::Clockid(val) => fmt.field("Clockid", &val),
8179 };
8180 }
8181 fmt.finish()
8182 }
8183}
8184impl IterableActGateAttrs<'_> {
8185 pub fn lookup_attr(
8186 &self,
8187 offset: usize,
8188 missing_type: Option<u16>,
8189 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
8190 let mut stack = Vec::new();
8191 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
8192 if missing_type.is_some() && cur == offset {
8193 stack.push(("ActGateAttrs", offset));
8194 return (
8195 stack,
8196 missing_type.and_then(|t| ActGateAttrs::attr_from_type(t)),
8197 );
8198 }
8199 if cur > offset || cur + self.buf.len() < offset {
8200 return (stack, None);
8201 }
8202 let mut attrs = self.clone();
8203 let mut last_off = cur + attrs.pos;
8204 while let Some(attr) = attrs.next() {
8205 let Ok(attr) = attr else { break };
8206 match attr {
8207 ActGateAttrs::Tm(val) => {
8208 if last_off == offset {
8209 stack.push(("Tm", last_off));
8210 break;
8211 }
8212 }
8213 ActGateAttrs::Parms(val) => {
8214 if last_off == offset {
8215 stack.push(("Parms", last_off));
8216 break;
8217 }
8218 }
8219 ActGateAttrs::Pad(val) => {
8220 if last_off == offset {
8221 stack.push(("Pad", last_off));
8222 break;
8223 }
8224 }
8225 ActGateAttrs::Priority(val) => {
8226 if last_off == offset {
8227 stack.push(("Priority", last_off));
8228 break;
8229 }
8230 }
8231 ActGateAttrs::EntryList(val) => {
8232 if last_off == offset {
8233 stack.push(("EntryList", last_off));
8234 break;
8235 }
8236 }
8237 ActGateAttrs::BaseTime(val) => {
8238 if last_off == offset {
8239 stack.push(("BaseTime", last_off));
8240 break;
8241 }
8242 }
8243 ActGateAttrs::CycleTime(val) => {
8244 if last_off == offset {
8245 stack.push(("CycleTime", last_off));
8246 break;
8247 }
8248 }
8249 ActGateAttrs::CycleTimeExt(val) => {
8250 if last_off == offset {
8251 stack.push(("CycleTimeExt", last_off));
8252 break;
8253 }
8254 }
8255 ActGateAttrs::Flags(val) => {
8256 if last_off == offset {
8257 stack.push(("Flags", last_off));
8258 break;
8259 }
8260 }
8261 ActGateAttrs::Clockid(val) => {
8262 if last_off == offset {
8263 stack.push(("Clockid", last_off));
8264 break;
8265 }
8266 }
8267 _ => {}
8268 };
8269 last_off = cur + attrs.pos;
8270 }
8271 if !stack.is_empty() {
8272 stack.push(("ActGateAttrs", cur));
8273 }
8274 (stack, None)
8275 }
8276}
8277#[derive(Clone)]
8278pub enum ActIfeAttrs<'a> {
8279 Parms(&'a [u8]),
8280 Tm(TcfT),
8281 Dmac(&'a [u8]),
8282 Smac(&'a [u8]),
8283 Type(u16),
8284 Metalst(&'a [u8]),
8285 Pad(&'a [u8]),
8286}
8287impl<'a> IterableActIfeAttrs<'a> {
8288 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
8289 let mut iter = self.clone();
8290 iter.pos = 0;
8291 for attr in iter {
8292 if let Ok(ActIfeAttrs::Parms(val)) = attr {
8293 return Ok(val);
8294 }
8295 }
8296 Err(ErrorContext::new_missing(
8297 "ActIfeAttrs",
8298 "Parms",
8299 self.orig_loc,
8300 self.buf.as_ptr() as usize,
8301 ))
8302 }
8303 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
8304 let mut iter = self.clone();
8305 iter.pos = 0;
8306 for attr in iter {
8307 if let Ok(ActIfeAttrs::Tm(val)) = attr {
8308 return Ok(val);
8309 }
8310 }
8311 Err(ErrorContext::new_missing(
8312 "ActIfeAttrs",
8313 "Tm",
8314 self.orig_loc,
8315 self.buf.as_ptr() as usize,
8316 ))
8317 }
8318 pub fn get_dmac(&self) -> Result<&'a [u8], ErrorContext> {
8319 let mut iter = self.clone();
8320 iter.pos = 0;
8321 for attr in iter {
8322 if let Ok(ActIfeAttrs::Dmac(val)) = attr {
8323 return Ok(val);
8324 }
8325 }
8326 Err(ErrorContext::new_missing(
8327 "ActIfeAttrs",
8328 "Dmac",
8329 self.orig_loc,
8330 self.buf.as_ptr() as usize,
8331 ))
8332 }
8333 pub fn get_smac(&self) -> Result<&'a [u8], ErrorContext> {
8334 let mut iter = self.clone();
8335 iter.pos = 0;
8336 for attr in iter {
8337 if let Ok(ActIfeAttrs::Smac(val)) = attr {
8338 return Ok(val);
8339 }
8340 }
8341 Err(ErrorContext::new_missing(
8342 "ActIfeAttrs",
8343 "Smac",
8344 self.orig_loc,
8345 self.buf.as_ptr() as usize,
8346 ))
8347 }
8348 pub fn get_type(&self) -> Result<u16, ErrorContext> {
8349 let mut iter = self.clone();
8350 iter.pos = 0;
8351 for attr in iter {
8352 if let Ok(ActIfeAttrs::Type(val)) = attr {
8353 return Ok(val);
8354 }
8355 }
8356 Err(ErrorContext::new_missing(
8357 "ActIfeAttrs",
8358 "Type",
8359 self.orig_loc,
8360 self.buf.as_ptr() as usize,
8361 ))
8362 }
8363 pub fn get_metalst(&self) -> Result<&'a [u8], ErrorContext> {
8364 let mut iter = self.clone();
8365 iter.pos = 0;
8366 for attr in iter {
8367 if let Ok(ActIfeAttrs::Metalst(val)) = attr {
8368 return Ok(val);
8369 }
8370 }
8371 Err(ErrorContext::new_missing(
8372 "ActIfeAttrs",
8373 "Metalst",
8374 self.orig_loc,
8375 self.buf.as_ptr() as usize,
8376 ))
8377 }
8378 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
8379 let mut iter = self.clone();
8380 iter.pos = 0;
8381 for attr in iter {
8382 if let Ok(ActIfeAttrs::Pad(val)) = attr {
8383 return Ok(val);
8384 }
8385 }
8386 Err(ErrorContext::new_missing(
8387 "ActIfeAttrs",
8388 "Pad",
8389 self.orig_loc,
8390 self.buf.as_ptr() as usize,
8391 ))
8392 }
8393}
8394impl ActIfeAttrs<'_> {
8395 pub fn new<'a>(buf: &'a [u8]) -> IterableActIfeAttrs<'a> {
8396 IterableActIfeAttrs::with_loc(buf, buf.as_ptr() as usize)
8397 }
8398 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8399 let res = match r#type {
8400 1u16 => "Parms",
8401 2u16 => "Tm",
8402 3u16 => "Dmac",
8403 4u16 => "Smac",
8404 5u16 => "Type",
8405 6u16 => "Metalst",
8406 7u16 => "Pad",
8407 _ => return None,
8408 };
8409 Some(res)
8410 }
8411}
8412#[derive(Clone, Copy, Default)]
8413pub struct IterableActIfeAttrs<'a> {
8414 buf: &'a [u8],
8415 pos: usize,
8416 orig_loc: usize,
8417}
8418impl<'a> IterableActIfeAttrs<'a> {
8419 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
8420 Self {
8421 buf,
8422 pos: 0,
8423 orig_loc,
8424 }
8425 }
8426 pub fn get_buf(&self) -> &'a [u8] {
8427 self.buf
8428 }
8429}
8430impl<'a> Iterator for IterableActIfeAttrs<'a> {
8431 type Item = Result<ActIfeAttrs<'a>, ErrorContext>;
8432 fn next(&mut self) -> Option<Self::Item> {
8433 let mut pos;
8434 let mut r#type;
8435 loop {
8436 pos = self.pos;
8437 r#type = None;
8438 if self.buf.len() == self.pos {
8439 return None;
8440 }
8441 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
8442 self.pos = self.buf.len();
8443 break;
8444 };
8445 r#type = Some(header.r#type);
8446 let res = match header.r#type {
8447 1u16 => ActIfeAttrs::Parms({
8448 let res = Some(next);
8449 let Some(val) = res else { break };
8450 val
8451 }),
8452 2u16 => ActIfeAttrs::Tm({
8453 let res = Some(TcfT::new_from_zeroed(next));
8454 let Some(val) = res else { break };
8455 val
8456 }),
8457 3u16 => ActIfeAttrs::Dmac({
8458 let res = Some(next);
8459 let Some(val) = res else { break };
8460 val
8461 }),
8462 4u16 => ActIfeAttrs::Smac({
8463 let res = Some(next);
8464 let Some(val) = res else { break };
8465 val
8466 }),
8467 5u16 => ActIfeAttrs::Type({
8468 let res = parse_u16(next);
8469 let Some(val) = res else { break };
8470 val
8471 }),
8472 6u16 => ActIfeAttrs::Metalst({
8473 let res = Some(next);
8474 let Some(val) = res else { break };
8475 val
8476 }),
8477 7u16 => ActIfeAttrs::Pad({
8478 let res = Some(next);
8479 let Some(val) = res else { break };
8480 val
8481 }),
8482 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
8483 n => continue,
8484 };
8485 return Some(Ok(res));
8486 }
8487 Some(Err(ErrorContext::new(
8488 "ActIfeAttrs",
8489 r#type.and_then(|t| ActIfeAttrs::attr_from_type(t)),
8490 self.orig_loc,
8491 self.buf.as_ptr().wrapping_add(pos) as usize,
8492 )))
8493 }
8494}
8495impl<'a> std::fmt::Debug for IterableActIfeAttrs<'_> {
8496 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8497 let mut fmt = f.debug_struct("ActIfeAttrs");
8498 for attr in self.clone() {
8499 let attr = match attr {
8500 Ok(a) => a,
8501 Err(err) => {
8502 fmt.finish()?;
8503 f.write_str("Err(")?;
8504 err.fmt(f)?;
8505 return f.write_str(")");
8506 }
8507 };
8508 match attr {
8509 ActIfeAttrs::Parms(val) => fmt.field("Parms", &val),
8510 ActIfeAttrs::Tm(val) => fmt.field("Tm", &val),
8511 ActIfeAttrs::Dmac(val) => fmt.field("Dmac", &val),
8512 ActIfeAttrs::Smac(val) => fmt.field("Smac", &val),
8513 ActIfeAttrs::Type(val) => fmt.field("Type", &val),
8514 ActIfeAttrs::Metalst(val) => fmt.field("Metalst", &val),
8515 ActIfeAttrs::Pad(val) => fmt.field("Pad", &val),
8516 };
8517 }
8518 fmt.finish()
8519 }
8520}
8521impl IterableActIfeAttrs<'_> {
8522 pub fn lookup_attr(
8523 &self,
8524 offset: usize,
8525 missing_type: Option<u16>,
8526 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
8527 let mut stack = Vec::new();
8528 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
8529 if missing_type.is_some() && cur == offset {
8530 stack.push(("ActIfeAttrs", offset));
8531 return (
8532 stack,
8533 missing_type.and_then(|t| ActIfeAttrs::attr_from_type(t)),
8534 );
8535 }
8536 if cur > offset || cur + self.buf.len() < offset {
8537 return (stack, None);
8538 }
8539 let mut attrs = self.clone();
8540 let mut last_off = cur + attrs.pos;
8541 while let Some(attr) = attrs.next() {
8542 let Ok(attr) = attr else { break };
8543 match attr {
8544 ActIfeAttrs::Parms(val) => {
8545 if last_off == offset {
8546 stack.push(("Parms", last_off));
8547 break;
8548 }
8549 }
8550 ActIfeAttrs::Tm(val) => {
8551 if last_off == offset {
8552 stack.push(("Tm", last_off));
8553 break;
8554 }
8555 }
8556 ActIfeAttrs::Dmac(val) => {
8557 if last_off == offset {
8558 stack.push(("Dmac", last_off));
8559 break;
8560 }
8561 }
8562 ActIfeAttrs::Smac(val) => {
8563 if last_off == offset {
8564 stack.push(("Smac", last_off));
8565 break;
8566 }
8567 }
8568 ActIfeAttrs::Type(val) => {
8569 if last_off == offset {
8570 stack.push(("Type", last_off));
8571 break;
8572 }
8573 }
8574 ActIfeAttrs::Metalst(val) => {
8575 if last_off == offset {
8576 stack.push(("Metalst", last_off));
8577 break;
8578 }
8579 }
8580 ActIfeAttrs::Pad(val) => {
8581 if last_off == offset {
8582 stack.push(("Pad", last_off));
8583 break;
8584 }
8585 }
8586 _ => {}
8587 };
8588 last_off = cur + attrs.pos;
8589 }
8590 if !stack.is_empty() {
8591 stack.push(("ActIfeAttrs", cur));
8592 }
8593 (stack, None)
8594 }
8595}
8596#[derive(Clone)]
8597pub enum ActMirredAttrs<'a> {
8598 Tm(TcfT),
8599 Parms(&'a [u8]),
8600 Pad(&'a [u8]),
8601 Blockid(&'a [u8]),
8602}
8603impl<'a> IterableActMirredAttrs<'a> {
8604 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
8605 let mut iter = self.clone();
8606 iter.pos = 0;
8607 for attr in iter {
8608 if let Ok(ActMirredAttrs::Tm(val)) = attr {
8609 return Ok(val);
8610 }
8611 }
8612 Err(ErrorContext::new_missing(
8613 "ActMirredAttrs",
8614 "Tm",
8615 self.orig_loc,
8616 self.buf.as_ptr() as usize,
8617 ))
8618 }
8619 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
8620 let mut iter = self.clone();
8621 iter.pos = 0;
8622 for attr in iter {
8623 if let Ok(ActMirredAttrs::Parms(val)) = attr {
8624 return Ok(val);
8625 }
8626 }
8627 Err(ErrorContext::new_missing(
8628 "ActMirredAttrs",
8629 "Parms",
8630 self.orig_loc,
8631 self.buf.as_ptr() as usize,
8632 ))
8633 }
8634 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
8635 let mut iter = self.clone();
8636 iter.pos = 0;
8637 for attr in iter {
8638 if let Ok(ActMirredAttrs::Pad(val)) = attr {
8639 return Ok(val);
8640 }
8641 }
8642 Err(ErrorContext::new_missing(
8643 "ActMirredAttrs",
8644 "Pad",
8645 self.orig_loc,
8646 self.buf.as_ptr() as usize,
8647 ))
8648 }
8649 pub fn get_blockid(&self) -> Result<&'a [u8], ErrorContext> {
8650 let mut iter = self.clone();
8651 iter.pos = 0;
8652 for attr in iter {
8653 if let Ok(ActMirredAttrs::Blockid(val)) = attr {
8654 return Ok(val);
8655 }
8656 }
8657 Err(ErrorContext::new_missing(
8658 "ActMirredAttrs",
8659 "Blockid",
8660 self.orig_loc,
8661 self.buf.as_ptr() as usize,
8662 ))
8663 }
8664}
8665impl ActMirredAttrs<'_> {
8666 pub fn new<'a>(buf: &'a [u8]) -> IterableActMirredAttrs<'a> {
8667 IterableActMirredAttrs::with_loc(buf, buf.as_ptr() as usize)
8668 }
8669 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8670 let res = match r#type {
8671 1u16 => "Tm",
8672 2u16 => "Parms",
8673 3u16 => "Pad",
8674 4u16 => "Blockid",
8675 _ => return None,
8676 };
8677 Some(res)
8678 }
8679}
8680#[derive(Clone, Copy, Default)]
8681pub struct IterableActMirredAttrs<'a> {
8682 buf: &'a [u8],
8683 pos: usize,
8684 orig_loc: usize,
8685}
8686impl<'a> IterableActMirredAttrs<'a> {
8687 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
8688 Self {
8689 buf,
8690 pos: 0,
8691 orig_loc,
8692 }
8693 }
8694 pub fn get_buf(&self) -> &'a [u8] {
8695 self.buf
8696 }
8697}
8698impl<'a> Iterator for IterableActMirredAttrs<'a> {
8699 type Item = Result<ActMirredAttrs<'a>, ErrorContext>;
8700 fn next(&mut self) -> Option<Self::Item> {
8701 let mut pos;
8702 let mut r#type;
8703 loop {
8704 pos = self.pos;
8705 r#type = None;
8706 if self.buf.len() == self.pos {
8707 return None;
8708 }
8709 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
8710 self.pos = self.buf.len();
8711 break;
8712 };
8713 r#type = Some(header.r#type);
8714 let res = match header.r#type {
8715 1u16 => ActMirredAttrs::Tm({
8716 let res = Some(TcfT::new_from_zeroed(next));
8717 let Some(val) = res else { break };
8718 val
8719 }),
8720 2u16 => ActMirredAttrs::Parms({
8721 let res = Some(next);
8722 let Some(val) = res else { break };
8723 val
8724 }),
8725 3u16 => ActMirredAttrs::Pad({
8726 let res = Some(next);
8727 let Some(val) = res else { break };
8728 val
8729 }),
8730 4u16 => ActMirredAttrs::Blockid({
8731 let res = Some(next);
8732 let Some(val) = res else { break };
8733 val
8734 }),
8735 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
8736 n => continue,
8737 };
8738 return Some(Ok(res));
8739 }
8740 Some(Err(ErrorContext::new(
8741 "ActMirredAttrs",
8742 r#type.and_then(|t| ActMirredAttrs::attr_from_type(t)),
8743 self.orig_loc,
8744 self.buf.as_ptr().wrapping_add(pos) as usize,
8745 )))
8746 }
8747}
8748impl<'a> std::fmt::Debug for IterableActMirredAttrs<'_> {
8749 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8750 let mut fmt = f.debug_struct("ActMirredAttrs");
8751 for attr in self.clone() {
8752 let attr = match attr {
8753 Ok(a) => a,
8754 Err(err) => {
8755 fmt.finish()?;
8756 f.write_str("Err(")?;
8757 err.fmt(f)?;
8758 return f.write_str(")");
8759 }
8760 };
8761 match attr {
8762 ActMirredAttrs::Tm(val) => fmt.field("Tm", &val),
8763 ActMirredAttrs::Parms(val) => fmt.field("Parms", &val),
8764 ActMirredAttrs::Pad(val) => fmt.field("Pad", &val),
8765 ActMirredAttrs::Blockid(val) => fmt.field("Blockid", &val),
8766 };
8767 }
8768 fmt.finish()
8769 }
8770}
8771impl IterableActMirredAttrs<'_> {
8772 pub fn lookup_attr(
8773 &self,
8774 offset: usize,
8775 missing_type: Option<u16>,
8776 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
8777 let mut stack = Vec::new();
8778 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
8779 if missing_type.is_some() && cur == offset {
8780 stack.push(("ActMirredAttrs", offset));
8781 return (
8782 stack,
8783 missing_type.and_then(|t| ActMirredAttrs::attr_from_type(t)),
8784 );
8785 }
8786 if cur > offset || cur + self.buf.len() < offset {
8787 return (stack, None);
8788 }
8789 let mut attrs = self.clone();
8790 let mut last_off = cur + attrs.pos;
8791 while let Some(attr) = attrs.next() {
8792 let Ok(attr) = attr else { break };
8793 match attr {
8794 ActMirredAttrs::Tm(val) => {
8795 if last_off == offset {
8796 stack.push(("Tm", last_off));
8797 break;
8798 }
8799 }
8800 ActMirredAttrs::Parms(val) => {
8801 if last_off == offset {
8802 stack.push(("Parms", last_off));
8803 break;
8804 }
8805 }
8806 ActMirredAttrs::Pad(val) => {
8807 if last_off == offset {
8808 stack.push(("Pad", last_off));
8809 break;
8810 }
8811 }
8812 ActMirredAttrs::Blockid(val) => {
8813 if last_off == offset {
8814 stack.push(("Blockid", last_off));
8815 break;
8816 }
8817 }
8818 _ => {}
8819 };
8820 last_off = cur + attrs.pos;
8821 }
8822 if !stack.is_empty() {
8823 stack.push(("ActMirredAttrs", cur));
8824 }
8825 (stack, None)
8826 }
8827}
8828#[derive(Clone)]
8829pub enum ActMplsAttrs<'a> {
8830 Tm(TcfT),
8831 Parms(TcMpls),
8832 Pad(&'a [u8]),
8833 Proto(u16),
8834 Label(u32),
8835 Tc(u8),
8836 Ttl(u8),
8837 Bos(u8),
8838}
8839impl<'a> IterableActMplsAttrs<'a> {
8840 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
8841 let mut iter = self.clone();
8842 iter.pos = 0;
8843 for attr in iter {
8844 if let Ok(ActMplsAttrs::Tm(val)) = attr {
8845 return Ok(val);
8846 }
8847 }
8848 Err(ErrorContext::new_missing(
8849 "ActMplsAttrs",
8850 "Tm",
8851 self.orig_loc,
8852 self.buf.as_ptr() as usize,
8853 ))
8854 }
8855 pub fn get_parms(&self) -> Result<TcMpls, ErrorContext> {
8856 let mut iter = self.clone();
8857 iter.pos = 0;
8858 for attr in iter {
8859 if let Ok(ActMplsAttrs::Parms(val)) = attr {
8860 return Ok(val);
8861 }
8862 }
8863 Err(ErrorContext::new_missing(
8864 "ActMplsAttrs",
8865 "Parms",
8866 self.orig_loc,
8867 self.buf.as_ptr() as usize,
8868 ))
8869 }
8870 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
8871 let mut iter = self.clone();
8872 iter.pos = 0;
8873 for attr in iter {
8874 if let Ok(ActMplsAttrs::Pad(val)) = attr {
8875 return Ok(val);
8876 }
8877 }
8878 Err(ErrorContext::new_missing(
8879 "ActMplsAttrs",
8880 "Pad",
8881 self.orig_loc,
8882 self.buf.as_ptr() as usize,
8883 ))
8884 }
8885 pub fn get_proto(&self) -> Result<u16, ErrorContext> {
8886 let mut iter = self.clone();
8887 iter.pos = 0;
8888 for attr in iter {
8889 if let Ok(ActMplsAttrs::Proto(val)) = attr {
8890 return Ok(val);
8891 }
8892 }
8893 Err(ErrorContext::new_missing(
8894 "ActMplsAttrs",
8895 "Proto",
8896 self.orig_loc,
8897 self.buf.as_ptr() as usize,
8898 ))
8899 }
8900 pub fn get_label(&self) -> Result<u32, ErrorContext> {
8901 let mut iter = self.clone();
8902 iter.pos = 0;
8903 for attr in iter {
8904 if let Ok(ActMplsAttrs::Label(val)) = attr {
8905 return Ok(val);
8906 }
8907 }
8908 Err(ErrorContext::new_missing(
8909 "ActMplsAttrs",
8910 "Label",
8911 self.orig_loc,
8912 self.buf.as_ptr() as usize,
8913 ))
8914 }
8915 pub fn get_tc(&self) -> Result<u8, ErrorContext> {
8916 let mut iter = self.clone();
8917 iter.pos = 0;
8918 for attr in iter {
8919 if let Ok(ActMplsAttrs::Tc(val)) = attr {
8920 return Ok(val);
8921 }
8922 }
8923 Err(ErrorContext::new_missing(
8924 "ActMplsAttrs",
8925 "Tc",
8926 self.orig_loc,
8927 self.buf.as_ptr() as usize,
8928 ))
8929 }
8930 pub fn get_ttl(&self) -> Result<u8, ErrorContext> {
8931 let mut iter = self.clone();
8932 iter.pos = 0;
8933 for attr in iter {
8934 if let Ok(ActMplsAttrs::Ttl(val)) = attr {
8935 return Ok(val);
8936 }
8937 }
8938 Err(ErrorContext::new_missing(
8939 "ActMplsAttrs",
8940 "Ttl",
8941 self.orig_loc,
8942 self.buf.as_ptr() as usize,
8943 ))
8944 }
8945 pub fn get_bos(&self) -> Result<u8, ErrorContext> {
8946 let mut iter = self.clone();
8947 iter.pos = 0;
8948 for attr in iter {
8949 if let Ok(ActMplsAttrs::Bos(val)) = attr {
8950 return Ok(val);
8951 }
8952 }
8953 Err(ErrorContext::new_missing(
8954 "ActMplsAttrs",
8955 "Bos",
8956 self.orig_loc,
8957 self.buf.as_ptr() as usize,
8958 ))
8959 }
8960}
8961impl ActMplsAttrs<'_> {
8962 pub fn new<'a>(buf: &'a [u8]) -> IterableActMplsAttrs<'a> {
8963 IterableActMplsAttrs::with_loc(buf, buf.as_ptr() as usize)
8964 }
8965 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8966 let res = match r#type {
8967 1u16 => "Tm",
8968 2u16 => "Parms",
8969 3u16 => "Pad",
8970 4u16 => "Proto",
8971 5u16 => "Label",
8972 6u16 => "Tc",
8973 7u16 => "Ttl",
8974 8u16 => "Bos",
8975 _ => return None,
8976 };
8977 Some(res)
8978 }
8979}
8980#[derive(Clone, Copy, Default)]
8981pub struct IterableActMplsAttrs<'a> {
8982 buf: &'a [u8],
8983 pos: usize,
8984 orig_loc: usize,
8985}
8986impl<'a> IterableActMplsAttrs<'a> {
8987 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
8988 Self {
8989 buf,
8990 pos: 0,
8991 orig_loc,
8992 }
8993 }
8994 pub fn get_buf(&self) -> &'a [u8] {
8995 self.buf
8996 }
8997}
8998impl<'a> Iterator for IterableActMplsAttrs<'a> {
8999 type Item = Result<ActMplsAttrs<'a>, ErrorContext>;
9000 fn next(&mut self) -> Option<Self::Item> {
9001 let mut pos;
9002 let mut r#type;
9003 loop {
9004 pos = self.pos;
9005 r#type = None;
9006 if self.buf.len() == self.pos {
9007 return None;
9008 }
9009 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
9010 self.pos = self.buf.len();
9011 break;
9012 };
9013 r#type = Some(header.r#type);
9014 let res = match header.r#type {
9015 1u16 => ActMplsAttrs::Tm({
9016 let res = Some(TcfT::new_from_zeroed(next));
9017 let Some(val) = res else { break };
9018 val
9019 }),
9020 2u16 => ActMplsAttrs::Parms({
9021 let res = Some(TcMpls::new_from_zeroed(next));
9022 let Some(val) = res else { break };
9023 val
9024 }),
9025 3u16 => ActMplsAttrs::Pad({
9026 let res = Some(next);
9027 let Some(val) = res else { break };
9028 val
9029 }),
9030 4u16 => ActMplsAttrs::Proto({
9031 let res = parse_be_u16(next);
9032 let Some(val) = res else { break };
9033 val
9034 }),
9035 5u16 => ActMplsAttrs::Label({
9036 let res = parse_u32(next);
9037 let Some(val) = res else { break };
9038 val
9039 }),
9040 6u16 => ActMplsAttrs::Tc({
9041 let res = parse_u8(next);
9042 let Some(val) = res else { break };
9043 val
9044 }),
9045 7u16 => ActMplsAttrs::Ttl({
9046 let res = parse_u8(next);
9047 let Some(val) = res else { break };
9048 val
9049 }),
9050 8u16 => ActMplsAttrs::Bos({
9051 let res = parse_u8(next);
9052 let Some(val) = res else { break };
9053 val
9054 }),
9055 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
9056 n => continue,
9057 };
9058 return Some(Ok(res));
9059 }
9060 Some(Err(ErrorContext::new(
9061 "ActMplsAttrs",
9062 r#type.and_then(|t| ActMplsAttrs::attr_from_type(t)),
9063 self.orig_loc,
9064 self.buf.as_ptr().wrapping_add(pos) as usize,
9065 )))
9066 }
9067}
9068impl<'a> std::fmt::Debug for IterableActMplsAttrs<'_> {
9069 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9070 let mut fmt = f.debug_struct("ActMplsAttrs");
9071 for attr in self.clone() {
9072 let attr = match attr {
9073 Ok(a) => a,
9074 Err(err) => {
9075 fmt.finish()?;
9076 f.write_str("Err(")?;
9077 err.fmt(f)?;
9078 return f.write_str(")");
9079 }
9080 };
9081 match attr {
9082 ActMplsAttrs::Tm(val) => fmt.field("Tm", &val),
9083 ActMplsAttrs::Parms(val) => fmt.field("Parms", &val),
9084 ActMplsAttrs::Pad(val) => fmt.field("Pad", &val),
9085 ActMplsAttrs::Proto(val) => fmt.field("Proto", &val),
9086 ActMplsAttrs::Label(val) => fmt.field("Label", &val),
9087 ActMplsAttrs::Tc(val) => fmt.field("Tc", &val),
9088 ActMplsAttrs::Ttl(val) => fmt.field("Ttl", &val),
9089 ActMplsAttrs::Bos(val) => fmt.field("Bos", &val),
9090 };
9091 }
9092 fmt.finish()
9093 }
9094}
9095impl IterableActMplsAttrs<'_> {
9096 pub fn lookup_attr(
9097 &self,
9098 offset: usize,
9099 missing_type: Option<u16>,
9100 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9101 let mut stack = Vec::new();
9102 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9103 if missing_type.is_some() && cur == offset {
9104 stack.push(("ActMplsAttrs", offset));
9105 return (
9106 stack,
9107 missing_type.and_then(|t| ActMplsAttrs::attr_from_type(t)),
9108 );
9109 }
9110 if cur > offset || cur + self.buf.len() < offset {
9111 return (stack, None);
9112 }
9113 let mut attrs = self.clone();
9114 let mut last_off = cur + attrs.pos;
9115 while let Some(attr) = attrs.next() {
9116 let Ok(attr) = attr else { break };
9117 match attr {
9118 ActMplsAttrs::Tm(val) => {
9119 if last_off == offset {
9120 stack.push(("Tm", last_off));
9121 break;
9122 }
9123 }
9124 ActMplsAttrs::Parms(val) => {
9125 if last_off == offset {
9126 stack.push(("Parms", last_off));
9127 break;
9128 }
9129 }
9130 ActMplsAttrs::Pad(val) => {
9131 if last_off == offset {
9132 stack.push(("Pad", last_off));
9133 break;
9134 }
9135 }
9136 ActMplsAttrs::Proto(val) => {
9137 if last_off == offset {
9138 stack.push(("Proto", last_off));
9139 break;
9140 }
9141 }
9142 ActMplsAttrs::Label(val) => {
9143 if last_off == offset {
9144 stack.push(("Label", last_off));
9145 break;
9146 }
9147 }
9148 ActMplsAttrs::Tc(val) => {
9149 if last_off == offset {
9150 stack.push(("Tc", last_off));
9151 break;
9152 }
9153 }
9154 ActMplsAttrs::Ttl(val) => {
9155 if last_off == offset {
9156 stack.push(("Ttl", last_off));
9157 break;
9158 }
9159 }
9160 ActMplsAttrs::Bos(val) => {
9161 if last_off == offset {
9162 stack.push(("Bos", last_off));
9163 break;
9164 }
9165 }
9166 _ => {}
9167 };
9168 last_off = cur + attrs.pos;
9169 }
9170 if !stack.is_empty() {
9171 stack.push(("ActMplsAttrs", cur));
9172 }
9173 (stack, None)
9174 }
9175}
9176#[derive(Clone)]
9177pub enum ActNatAttrs<'a> {
9178 Parms(&'a [u8]),
9179 Tm(TcfT),
9180 Pad(&'a [u8]),
9181}
9182impl<'a> IterableActNatAttrs<'a> {
9183 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
9184 let mut iter = self.clone();
9185 iter.pos = 0;
9186 for attr in iter {
9187 if let Ok(ActNatAttrs::Parms(val)) = attr {
9188 return Ok(val);
9189 }
9190 }
9191 Err(ErrorContext::new_missing(
9192 "ActNatAttrs",
9193 "Parms",
9194 self.orig_loc,
9195 self.buf.as_ptr() as usize,
9196 ))
9197 }
9198 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
9199 let mut iter = self.clone();
9200 iter.pos = 0;
9201 for attr in iter {
9202 if let Ok(ActNatAttrs::Tm(val)) = attr {
9203 return Ok(val);
9204 }
9205 }
9206 Err(ErrorContext::new_missing(
9207 "ActNatAttrs",
9208 "Tm",
9209 self.orig_loc,
9210 self.buf.as_ptr() as usize,
9211 ))
9212 }
9213 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
9214 let mut iter = self.clone();
9215 iter.pos = 0;
9216 for attr in iter {
9217 if let Ok(ActNatAttrs::Pad(val)) = attr {
9218 return Ok(val);
9219 }
9220 }
9221 Err(ErrorContext::new_missing(
9222 "ActNatAttrs",
9223 "Pad",
9224 self.orig_loc,
9225 self.buf.as_ptr() as usize,
9226 ))
9227 }
9228}
9229impl ActNatAttrs<'_> {
9230 pub fn new<'a>(buf: &'a [u8]) -> IterableActNatAttrs<'a> {
9231 IterableActNatAttrs::with_loc(buf, buf.as_ptr() as usize)
9232 }
9233 fn attr_from_type(r#type: u16) -> Option<&'static str> {
9234 let res = match r#type {
9235 1u16 => "Parms",
9236 2u16 => "Tm",
9237 3u16 => "Pad",
9238 _ => return None,
9239 };
9240 Some(res)
9241 }
9242}
9243#[derive(Clone, Copy, Default)]
9244pub struct IterableActNatAttrs<'a> {
9245 buf: &'a [u8],
9246 pos: usize,
9247 orig_loc: usize,
9248}
9249impl<'a> IterableActNatAttrs<'a> {
9250 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
9251 Self {
9252 buf,
9253 pos: 0,
9254 orig_loc,
9255 }
9256 }
9257 pub fn get_buf(&self) -> &'a [u8] {
9258 self.buf
9259 }
9260}
9261impl<'a> Iterator for IterableActNatAttrs<'a> {
9262 type Item = Result<ActNatAttrs<'a>, ErrorContext>;
9263 fn next(&mut self) -> Option<Self::Item> {
9264 let mut pos;
9265 let mut r#type;
9266 loop {
9267 pos = self.pos;
9268 r#type = None;
9269 if self.buf.len() == self.pos {
9270 return None;
9271 }
9272 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
9273 self.pos = self.buf.len();
9274 break;
9275 };
9276 r#type = Some(header.r#type);
9277 let res = match header.r#type {
9278 1u16 => ActNatAttrs::Parms({
9279 let res = Some(next);
9280 let Some(val) = res else { break };
9281 val
9282 }),
9283 2u16 => ActNatAttrs::Tm({
9284 let res = Some(TcfT::new_from_zeroed(next));
9285 let Some(val) = res else { break };
9286 val
9287 }),
9288 3u16 => ActNatAttrs::Pad({
9289 let res = Some(next);
9290 let Some(val) = res else { break };
9291 val
9292 }),
9293 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
9294 n => continue,
9295 };
9296 return Some(Ok(res));
9297 }
9298 Some(Err(ErrorContext::new(
9299 "ActNatAttrs",
9300 r#type.and_then(|t| ActNatAttrs::attr_from_type(t)),
9301 self.orig_loc,
9302 self.buf.as_ptr().wrapping_add(pos) as usize,
9303 )))
9304 }
9305}
9306impl<'a> std::fmt::Debug for IterableActNatAttrs<'_> {
9307 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9308 let mut fmt = f.debug_struct("ActNatAttrs");
9309 for attr in self.clone() {
9310 let attr = match attr {
9311 Ok(a) => a,
9312 Err(err) => {
9313 fmt.finish()?;
9314 f.write_str("Err(")?;
9315 err.fmt(f)?;
9316 return f.write_str(")");
9317 }
9318 };
9319 match attr {
9320 ActNatAttrs::Parms(val) => fmt.field("Parms", &val),
9321 ActNatAttrs::Tm(val) => fmt.field("Tm", &val),
9322 ActNatAttrs::Pad(val) => fmt.field("Pad", &val),
9323 };
9324 }
9325 fmt.finish()
9326 }
9327}
9328impl IterableActNatAttrs<'_> {
9329 pub fn lookup_attr(
9330 &self,
9331 offset: usize,
9332 missing_type: Option<u16>,
9333 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9334 let mut stack = Vec::new();
9335 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9336 if missing_type.is_some() && cur == offset {
9337 stack.push(("ActNatAttrs", offset));
9338 return (
9339 stack,
9340 missing_type.and_then(|t| ActNatAttrs::attr_from_type(t)),
9341 );
9342 }
9343 if cur > offset || cur + self.buf.len() < offset {
9344 return (stack, None);
9345 }
9346 let mut attrs = self.clone();
9347 let mut last_off = cur + attrs.pos;
9348 while let Some(attr) = attrs.next() {
9349 let Ok(attr) = attr else { break };
9350 match attr {
9351 ActNatAttrs::Parms(val) => {
9352 if last_off == offset {
9353 stack.push(("Parms", last_off));
9354 break;
9355 }
9356 }
9357 ActNatAttrs::Tm(val) => {
9358 if last_off == offset {
9359 stack.push(("Tm", last_off));
9360 break;
9361 }
9362 }
9363 ActNatAttrs::Pad(val) => {
9364 if last_off == offset {
9365 stack.push(("Pad", last_off));
9366 break;
9367 }
9368 }
9369 _ => {}
9370 };
9371 last_off = cur + attrs.pos;
9372 }
9373 if !stack.is_empty() {
9374 stack.push(("ActNatAttrs", cur));
9375 }
9376 (stack, None)
9377 }
9378}
9379#[derive(Clone)]
9380pub enum ActPeditAttrs<'a> {
9381 Tm(TcfT),
9382 Parms(TcPeditSel),
9383 Pad(&'a [u8]),
9384 ParmsEx(&'a [u8]),
9385 KeysEx(&'a [u8]),
9386 KeyEx(&'a [u8]),
9387}
9388impl<'a> IterableActPeditAttrs<'a> {
9389 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
9390 let mut iter = self.clone();
9391 iter.pos = 0;
9392 for attr in iter {
9393 if let Ok(ActPeditAttrs::Tm(val)) = attr {
9394 return Ok(val);
9395 }
9396 }
9397 Err(ErrorContext::new_missing(
9398 "ActPeditAttrs",
9399 "Tm",
9400 self.orig_loc,
9401 self.buf.as_ptr() as usize,
9402 ))
9403 }
9404 pub fn get_parms(&self) -> Result<TcPeditSel, ErrorContext> {
9405 let mut iter = self.clone();
9406 iter.pos = 0;
9407 for attr in iter {
9408 if let Ok(ActPeditAttrs::Parms(val)) = attr {
9409 return Ok(val);
9410 }
9411 }
9412 Err(ErrorContext::new_missing(
9413 "ActPeditAttrs",
9414 "Parms",
9415 self.orig_loc,
9416 self.buf.as_ptr() as usize,
9417 ))
9418 }
9419 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
9420 let mut iter = self.clone();
9421 iter.pos = 0;
9422 for attr in iter {
9423 if let Ok(ActPeditAttrs::Pad(val)) = attr {
9424 return Ok(val);
9425 }
9426 }
9427 Err(ErrorContext::new_missing(
9428 "ActPeditAttrs",
9429 "Pad",
9430 self.orig_loc,
9431 self.buf.as_ptr() as usize,
9432 ))
9433 }
9434 pub fn get_parms_ex(&self) -> Result<&'a [u8], ErrorContext> {
9435 let mut iter = self.clone();
9436 iter.pos = 0;
9437 for attr in iter {
9438 if let Ok(ActPeditAttrs::ParmsEx(val)) = attr {
9439 return Ok(val);
9440 }
9441 }
9442 Err(ErrorContext::new_missing(
9443 "ActPeditAttrs",
9444 "ParmsEx",
9445 self.orig_loc,
9446 self.buf.as_ptr() as usize,
9447 ))
9448 }
9449 pub fn get_keys_ex(&self) -> Result<&'a [u8], ErrorContext> {
9450 let mut iter = self.clone();
9451 iter.pos = 0;
9452 for attr in iter {
9453 if let Ok(ActPeditAttrs::KeysEx(val)) = attr {
9454 return Ok(val);
9455 }
9456 }
9457 Err(ErrorContext::new_missing(
9458 "ActPeditAttrs",
9459 "KeysEx",
9460 self.orig_loc,
9461 self.buf.as_ptr() as usize,
9462 ))
9463 }
9464 pub fn get_key_ex(&self) -> Result<&'a [u8], ErrorContext> {
9465 let mut iter = self.clone();
9466 iter.pos = 0;
9467 for attr in iter {
9468 if let Ok(ActPeditAttrs::KeyEx(val)) = attr {
9469 return Ok(val);
9470 }
9471 }
9472 Err(ErrorContext::new_missing(
9473 "ActPeditAttrs",
9474 "KeyEx",
9475 self.orig_loc,
9476 self.buf.as_ptr() as usize,
9477 ))
9478 }
9479}
9480impl ActPeditAttrs<'_> {
9481 pub fn new<'a>(buf: &'a [u8]) -> IterableActPeditAttrs<'a> {
9482 IterableActPeditAttrs::with_loc(buf, buf.as_ptr() as usize)
9483 }
9484 fn attr_from_type(r#type: u16) -> Option<&'static str> {
9485 let res = match r#type {
9486 1u16 => "Tm",
9487 2u16 => "Parms",
9488 3u16 => "Pad",
9489 4u16 => "ParmsEx",
9490 5u16 => "KeysEx",
9491 6u16 => "KeyEx",
9492 _ => return None,
9493 };
9494 Some(res)
9495 }
9496}
9497#[derive(Clone, Copy, Default)]
9498pub struct IterableActPeditAttrs<'a> {
9499 buf: &'a [u8],
9500 pos: usize,
9501 orig_loc: usize,
9502}
9503impl<'a> IterableActPeditAttrs<'a> {
9504 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
9505 Self {
9506 buf,
9507 pos: 0,
9508 orig_loc,
9509 }
9510 }
9511 pub fn get_buf(&self) -> &'a [u8] {
9512 self.buf
9513 }
9514}
9515impl<'a> Iterator for IterableActPeditAttrs<'a> {
9516 type Item = Result<ActPeditAttrs<'a>, ErrorContext>;
9517 fn next(&mut self) -> Option<Self::Item> {
9518 let mut pos;
9519 let mut r#type;
9520 loop {
9521 pos = self.pos;
9522 r#type = None;
9523 if self.buf.len() == self.pos {
9524 return None;
9525 }
9526 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
9527 self.pos = self.buf.len();
9528 break;
9529 };
9530 r#type = Some(header.r#type);
9531 let res = match header.r#type {
9532 1u16 => ActPeditAttrs::Tm({
9533 let res = Some(TcfT::new_from_zeroed(next));
9534 let Some(val) = res else { break };
9535 val
9536 }),
9537 2u16 => ActPeditAttrs::Parms({
9538 let res = Some(TcPeditSel::new_from_zeroed(next));
9539 let Some(val) = res else { break };
9540 val
9541 }),
9542 3u16 => ActPeditAttrs::Pad({
9543 let res = Some(next);
9544 let Some(val) = res else { break };
9545 val
9546 }),
9547 4u16 => ActPeditAttrs::ParmsEx({
9548 let res = Some(next);
9549 let Some(val) = res else { break };
9550 val
9551 }),
9552 5u16 => ActPeditAttrs::KeysEx({
9553 let res = Some(next);
9554 let Some(val) = res else { break };
9555 val
9556 }),
9557 6u16 => ActPeditAttrs::KeyEx({
9558 let res = Some(next);
9559 let Some(val) = res else { break };
9560 val
9561 }),
9562 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
9563 n => continue,
9564 };
9565 return Some(Ok(res));
9566 }
9567 Some(Err(ErrorContext::new(
9568 "ActPeditAttrs",
9569 r#type.and_then(|t| ActPeditAttrs::attr_from_type(t)),
9570 self.orig_loc,
9571 self.buf.as_ptr().wrapping_add(pos) as usize,
9572 )))
9573 }
9574}
9575impl<'a> std::fmt::Debug for IterableActPeditAttrs<'_> {
9576 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9577 let mut fmt = f.debug_struct("ActPeditAttrs");
9578 for attr in self.clone() {
9579 let attr = match attr {
9580 Ok(a) => a,
9581 Err(err) => {
9582 fmt.finish()?;
9583 f.write_str("Err(")?;
9584 err.fmt(f)?;
9585 return f.write_str(")");
9586 }
9587 };
9588 match attr {
9589 ActPeditAttrs::Tm(val) => fmt.field("Tm", &val),
9590 ActPeditAttrs::Parms(val) => fmt.field("Parms", &val),
9591 ActPeditAttrs::Pad(val) => fmt.field("Pad", &val),
9592 ActPeditAttrs::ParmsEx(val) => fmt.field("ParmsEx", &val),
9593 ActPeditAttrs::KeysEx(val) => fmt.field("KeysEx", &val),
9594 ActPeditAttrs::KeyEx(val) => fmt.field("KeyEx", &val),
9595 };
9596 }
9597 fmt.finish()
9598 }
9599}
9600impl IterableActPeditAttrs<'_> {
9601 pub fn lookup_attr(
9602 &self,
9603 offset: usize,
9604 missing_type: Option<u16>,
9605 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9606 let mut stack = Vec::new();
9607 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9608 if missing_type.is_some() && cur == offset {
9609 stack.push(("ActPeditAttrs", offset));
9610 return (
9611 stack,
9612 missing_type.and_then(|t| ActPeditAttrs::attr_from_type(t)),
9613 );
9614 }
9615 if cur > offset || cur + self.buf.len() < offset {
9616 return (stack, None);
9617 }
9618 let mut attrs = self.clone();
9619 let mut last_off = cur + attrs.pos;
9620 while let Some(attr) = attrs.next() {
9621 let Ok(attr) = attr else { break };
9622 match attr {
9623 ActPeditAttrs::Tm(val) => {
9624 if last_off == offset {
9625 stack.push(("Tm", last_off));
9626 break;
9627 }
9628 }
9629 ActPeditAttrs::Parms(val) => {
9630 if last_off == offset {
9631 stack.push(("Parms", last_off));
9632 break;
9633 }
9634 }
9635 ActPeditAttrs::Pad(val) => {
9636 if last_off == offset {
9637 stack.push(("Pad", last_off));
9638 break;
9639 }
9640 }
9641 ActPeditAttrs::ParmsEx(val) => {
9642 if last_off == offset {
9643 stack.push(("ParmsEx", last_off));
9644 break;
9645 }
9646 }
9647 ActPeditAttrs::KeysEx(val) => {
9648 if last_off == offset {
9649 stack.push(("KeysEx", last_off));
9650 break;
9651 }
9652 }
9653 ActPeditAttrs::KeyEx(val) => {
9654 if last_off == offset {
9655 stack.push(("KeyEx", last_off));
9656 break;
9657 }
9658 }
9659 _ => {}
9660 };
9661 last_off = cur + attrs.pos;
9662 }
9663 if !stack.is_empty() {
9664 stack.push(("ActPeditAttrs", cur));
9665 }
9666 (stack, None)
9667 }
9668}
9669#[derive(Clone)]
9670pub enum ActSimpleAttrs<'a> {
9671 Tm(TcfT),
9672 Parms(&'a [u8]),
9673 Data(&'a [u8]),
9674 Pad(&'a [u8]),
9675}
9676impl<'a> IterableActSimpleAttrs<'a> {
9677 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
9678 let mut iter = self.clone();
9679 iter.pos = 0;
9680 for attr in iter {
9681 if let Ok(ActSimpleAttrs::Tm(val)) = attr {
9682 return Ok(val);
9683 }
9684 }
9685 Err(ErrorContext::new_missing(
9686 "ActSimpleAttrs",
9687 "Tm",
9688 self.orig_loc,
9689 self.buf.as_ptr() as usize,
9690 ))
9691 }
9692 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
9693 let mut iter = self.clone();
9694 iter.pos = 0;
9695 for attr in iter {
9696 if let Ok(ActSimpleAttrs::Parms(val)) = attr {
9697 return Ok(val);
9698 }
9699 }
9700 Err(ErrorContext::new_missing(
9701 "ActSimpleAttrs",
9702 "Parms",
9703 self.orig_loc,
9704 self.buf.as_ptr() as usize,
9705 ))
9706 }
9707 pub fn get_data(&self) -> Result<&'a [u8], ErrorContext> {
9708 let mut iter = self.clone();
9709 iter.pos = 0;
9710 for attr in iter {
9711 if let Ok(ActSimpleAttrs::Data(val)) = attr {
9712 return Ok(val);
9713 }
9714 }
9715 Err(ErrorContext::new_missing(
9716 "ActSimpleAttrs",
9717 "Data",
9718 self.orig_loc,
9719 self.buf.as_ptr() as usize,
9720 ))
9721 }
9722 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
9723 let mut iter = self.clone();
9724 iter.pos = 0;
9725 for attr in iter {
9726 if let Ok(ActSimpleAttrs::Pad(val)) = attr {
9727 return Ok(val);
9728 }
9729 }
9730 Err(ErrorContext::new_missing(
9731 "ActSimpleAttrs",
9732 "Pad",
9733 self.orig_loc,
9734 self.buf.as_ptr() as usize,
9735 ))
9736 }
9737}
9738impl ActSimpleAttrs<'_> {
9739 pub fn new<'a>(buf: &'a [u8]) -> IterableActSimpleAttrs<'a> {
9740 IterableActSimpleAttrs::with_loc(buf, buf.as_ptr() as usize)
9741 }
9742 fn attr_from_type(r#type: u16) -> Option<&'static str> {
9743 let res = match r#type {
9744 1u16 => "Tm",
9745 2u16 => "Parms",
9746 3u16 => "Data",
9747 4u16 => "Pad",
9748 _ => return None,
9749 };
9750 Some(res)
9751 }
9752}
9753#[derive(Clone, Copy, Default)]
9754pub struct IterableActSimpleAttrs<'a> {
9755 buf: &'a [u8],
9756 pos: usize,
9757 orig_loc: usize,
9758}
9759impl<'a> IterableActSimpleAttrs<'a> {
9760 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
9761 Self {
9762 buf,
9763 pos: 0,
9764 orig_loc,
9765 }
9766 }
9767 pub fn get_buf(&self) -> &'a [u8] {
9768 self.buf
9769 }
9770}
9771impl<'a> Iterator for IterableActSimpleAttrs<'a> {
9772 type Item = Result<ActSimpleAttrs<'a>, ErrorContext>;
9773 fn next(&mut self) -> Option<Self::Item> {
9774 let mut pos;
9775 let mut r#type;
9776 loop {
9777 pos = self.pos;
9778 r#type = None;
9779 if self.buf.len() == self.pos {
9780 return None;
9781 }
9782 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
9783 self.pos = self.buf.len();
9784 break;
9785 };
9786 r#type = Some(header.r#type);
9787 let res = match header.r#type {
9788 1u16 => ActSimpleAttrs::Tm({
9789 let res = Some(TcfT::new_from_zeroed(next));
9790 let Some(val) = res else { break };
9791 val
9792 }),
9793 2u16 => ActSimpleAttrs::Parms({
9794 let res = Some(next);
9795 let Some(val) = res else { break };
9796 val
9797 }),
9798 3u16 => ActSimpleAttrs::Data({
9799 let res = Some(next);
9800 let Some(val) = res else { break };
9801 val
9802 }),
9803 4u16 => ActSimpleAttrs::Pad({
9804 let res = Some(next);
9805 let Some(val) = res else { break };
9806 val
9807 }),
9808 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
9809 n => continue,
9810 };
9811 return Some(Ok(res));
9812 }
9813 Some(Err(ErrorContext::new(
9814 "ActSimpleAttrs",
9815 r#type.and_then(|t| ActSimpleAttrs::attr_from_type(t)),
9816 self.orig_loc,
9817 self.buf.as_ptr().wrapping_add(pos) as usize,
9818 )))
9819 }
9820}
9821impl<'a> std::fmt::Debug for IterableActSimpleAttrs<'_> {
9822 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9823 let mut fmt = f.debug_struct("ActSimpleAttrs");
9824 for attr in self.clone() {
9825 let attr = match attr {
9826 Ok(a) => a,
9827 Err(err) => {
9828 fmt.finish()?;
9829 f.write_str("Err(")?;
9830 err.fmt(f)?;
9831 return f.write_str(")");
9832 }
9833 };
9834 match attr {
9835 ActSimpleAttrs::Tm(val) => fmt.field("Tm", &val),
9836 ActSimpleAttrs::Parms(val) => fmt.field("Parms", &val),
9837 ActSimpleAttrs::Data(val) => fmt.field("Data", &val),
9838 ActSimpleAttrs::Pad(val) => fmt.field("Pad", &val),
9839 };
9840 }
9841 fmt.finish()
9842 }
9843}
9844impl IterableActSimpleAttrs<'_> {
9845 pub fn lookup_attr(
9846 &self,
9847 offset: usize,
9848 missing_type: Option<u16>,
9849 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9850 let mut stack = Vec::new();
9851 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9852 if missing_type.is_some() && cur == offset {
9853 stack.push(("ActSimpleAttrs", offset));
9854 return (
9855 stack,
9856 missing_type.and_then(|t| ActSimpleAttrs::attr_from_type(t)),
9857 );
9858 }
9859 if cur > offset || cur + self.buf.len() < offset {
9860 return (stack, None);
9861 }
9862 let mut attrs = self.clone();
9863 let mut last_off = cur + attrs.pos;
9864 while let Some(attr) = attrs.next() {
9865 let Ok(attr) = attr else { break };
9866 match attr {
9867 ActSimpleAttrs::Tm(val) => {
9868 if last_off == offset {
9869 stack.push(("Tm", last_off));
9870 break;
9871 }
9872 }
9873 ActSimpleAttrs::Parms(val) => {
9874 if last_off == offset {
9875 stack.push(("Parms", last_off));
9876 break;
9877 }
9878 }
9879 ActSimpleAttrs::Data(val) => {
9880 if last_off == offset {
9881 stack.push(("Data", last_off));
9882 break;
9883 }
9884 }
9885 ActSimpleAttrs::Pad(val) => {
9886 if last_off == offset {
9887 stack.push(("Pad", last_off));
9888 break;
9889 }
9890 }
9891 _ => {}
9892 };
9893 last_off = cur + attrs.pos;
9894 }
9895 if !stack.is_empty() {
9896 stack.push(("ActSimpleAttrs", cur));
9897 }
9898 (stack, None)
9899 }
9900}
9901#[derive(Clone)]
9902pub enum ActSkbeditAttrs<'a> {
9903 Tm(TcfT),
9904 Parms(&'a [u8]),
9905 Priority(u32),
9906 QueueMapping(u16),
9907 Mark(u32),
9908 Pad(&'a [u8]),
9909 Ptype(u16),
9910 Mask(u32),
9911 Flags(u64),
9912 QueueMappingMax(u16),
9913}
9914impl<'a> IterableActSkbeditAttrs<'a> {
9915 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
9916 let mut iter = self.clone();
9917 iter.pos = 0;
9918 for attr in iter {
9919 if let Ok(ActSkbeditAttrs::Tm(val)) = attr {
9920 return Ok(val);
9921 }
9922 }
9923 Err(ErrorContext::new_missing(
9924 "ActSkbeditAttrs",
9925 "Tm",
9926 self.orig_loc,
9927 self.buf.as_ptr() as usize,
9928 ))
9929 }
9930 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
9931 let mut iter = self.clone();
9932 iter.pos = 0;
9933 for attr in iter {
9934 if let Ok(ActSkbeditAttrs::Parms(val)) = attr {
9935 return Ok(val);
9936 }
9937 }
9938 Err(ErrorContext::new_missing(
9939 "ActSkbeditAttrs",
9940 "Parms",
9941 self.orig_loc,
9942 self.buf.as_ptr() as usize,
9943 ))
9944 }
9945 pub fn get_priority(&self) -> Result<u32, ErrorContext> {
9946 let mut iter = self.clone();
9947 iter.pos = 0;
9948 for attr in iter {
9949 if let Ok(ActSkbeditAttrs::Priority(val)) = attr {
9950 return Ok(val);
9951 }
9952 }
9953 Err(ErrorContext::new_missing(
9954 "ActSkbeditAttrs",
9955 "Priority",
9956 self.orig_loc,
9957 self.buf.as_ptr() as usize,
9958 ))
9959 }
9960 pub fn get_queue_mapping(&self) -> Result<u16, ErrorContext> {
9961 let mut iter = self.clone();
9962 iter.pos = 0;
9963 for attr in iter {
9964 if let Ok(ActSkbeditAttrs::QueueMapping(val)) = attr {
9965 return Ok(val);
9966 }
9967 }
9968 Err(ErrorContext::new_missing(
9969 "ActSkbeditAttrs",
9970 "QueueMapping",
9971 self.orig_loc,
9972 self.buf.as_ptr() as usize,
9973 ))
9974 }
9975 pub fn get_mark(&self) -> Result<u32, ErrorContext> {
9976 let mut iter = self.clone();
9977 iter.pos = 0;
9978 for attr in iter {
9979 if let Ok(ActSkbeditAttrs::Mark(val)) = attr {
9980 return Ok(val);
9981 }
9982 }
9983 Err(ErrorContext::new_missing(
9984 "ActSkbeditAttrs",
9985 "Mark",
9986 self.orig_loc,
9987 self.buf.as_ptr() as usize,
9988 ))
9989 }
9990 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
9991 let mut iter = self.clone();
9992 iter.pos = 0;
9993 for attr in iter {
9994 if let Ok(ActSkbeditAttrs::Pad(val)) = attr {
9995 return Ok(val);
9996 }
9997 }
9998 Err(ErrorContext::new_missing(
9999 "ActSkbeditAttrs",
10000 "Pad",
10001 self.orig_loc,
10002 self.buf.as_ptr() as usize,
10003 ))
10004 }
10005 pub fn get_ptype(&self) -> Result<u16, ErrorContext> {
10006 let mut iter = self.clone();
10007 iter.pos = 0;
10008 for attr in iter {
10009 if let Ok(ActSkbeditAttrs::Ptype(val)) = attr {
10010 return Ok(val);
10011 }
10012 }
10013 Err(ErrorContext::new_missing(
10014 "ActSkbeditAttrs",
10015 "Ptype",
10016 self.orig_loc,
10017 self.buf.as_ptr() as usize,
10018 ))
10019 }
10020 pub fn get_mask(&self) -> Result<u32, ErrorContext> {
10021 let mut iter = self.clone();
10022 iter.pos = 0;
10023 for attr in iter {
10024 if let Ok(ActSkbeditAttrs::Mask(val)) = attr {
10025 return Ok(val);
10026 }
10027 }
10028 Err(ErrorContext::new_missing(
10029 "ActSkbeditAttrs",
10030 "Mask",
10031 self.orig_loc,
10032 self.buf.as_ptr() as usize,
10033 ))
10034 }
10035 pub fn get_flags(&self) -> Result<u64, ErrorContext> {
10036 let mut iter = self.clone();
10037 iter.pos = 0;
10038 for attr in iter {
10039 if let Ok(ActSkbeditAttrs::Flags(val)) = attr {
10040 return Ok(val);
10041 }
10042 }
10043 Err(ErrorContext::new_missing(
10044 "ActSkbeditAttrs",
10045 "Flags",
10046 self.orig_loc,
10047 self.buf.as_ptr() as usize,
10048 ))
10049 }
10050 pub fn get_queue_mapping_max(&self) -> Result<u16, ErrorContext> {
10051 let mut iter = self.clone();
10052 iter.pos = 0;
10053 for attr in iter {
10054 if let Ok(ActSkbeditAttrs::QueueMappingMax(val)) = attr {
10055 return Ok(val);
10056 }
10057 }
10058 Err(ErrorContext::new_missing(
10059 "ActSkbeditAttrs",
10060 "QueueMappingMax",
10061 self.orig_loc,
10062 self.buf.as_ptr() as usize,
10063 ))
10064 }
10065}
10066impl ActSkbeditAttrs<'_> {
10067 pub fn new<'a>(buf: &'a [u8]) -> IterableActSkbeditAttrs<'a> {
10068 IterableActSkbeditAttrs::with_loc(buf, buf.as_ptr() as usize)
10069 }
10070 fn attr_from_type(r#type: u16) -> Option<&'static str> {
10071 let res = match r#type {
10072 1u16 => "Tm",
10073 2u16 => "Parms",
10074 3u16 => "Priority",
10075 4u16 => "QueueMapping",
10076 5u16 => "Mark",
10077 6u16 => "Pad",
10078 7u16 => "Ptype",
10079 8u16 => "Mask",
10080 9u16 => "Flags",
10081 10u16 => "QueueMappingMax",
10082 _ => return None,
10083 };
10084 Some(res)
10085 }
10086}
10087#[derive(Clone, Copy, Default)]
10088pub struct IterableActSkbeditAttrs<'a> {
10089 buf: &'a [u8],
10090 pos: usize,
10091 orig_loc: usize,
10092}
10093impl<'a> IterableActSkbeditAttrs<'a> {
10094 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
10095 Self {
10096 buf,
10097 pos: 0,
10098 orig_loc,
10099 }
10100 }
10101 pub fn get_buf(&self) -> &'a [u8] {
10102 self.buf
10103 }
10104}
10105impl<'a> Iterator for IterableActSkbeditAttrs<'a> {
10106 type Item = Result<ActSkbeditAttrs<'a>, ErrorContext>;
10107 fn next(&mut self) -> Option<Self::Item> {
10108 let mut pos;
10109 let mut r#type;
10110 loop {
10111 pos = self.pos;
10112 r#type = None;
10113 if self.buf.len() == self.pos {
10114 return None;
10115 }
10116 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
10117 self.pos = self.buf.len();
10118 break;
10119 };
10120 r#type = Some(header.r#type);
10121 let res = match header.r#type {
10122 1u16 => ActSkbeditAttrs::Tm({
10123 let res = Some(TcfT::new_from_zeroed(next));
10124 let Some(val) = res else { break };
10125 val
10126 }),
10127 2u16 => ActSkbeditAttrs::Parms({
10128 let res = Some(next);
10129 let Some(val) = res else { break };
10130 val
10131 }),
10132 3u16 => ActSkbeditAttrs::Priority({
10133 let res = parse_u32(next);
10134 let Some(val) = res else { break };
10135 val
10136 }),
10137 4u16 => ActSkbeditAttrs::QueueMapping({
10138 let res = parse_u16(next);
10139 let Some(val) = res else { break };
10140 val
10141 }),
10142 5u16 => ActSkbeditAttrs::Mark({
10143 let res = parse_u32(next);
10144 let Some(val) = res else { break };
10145 val
10146 }),
10147 6u16 => ActSkbeditAttrs::Pad({
10148 let res = Some(next);
10149 let Some(val) = res else { break };
10150 val
10151 }),
10152 7u16 => ActSkbeditAttrs::Ptype({
10153 let res = parse_u16(next);
10154 let Some(val) = res else { break };
10155 val
10156 }),
10157 8u16 => ActSkbeditAttrs::Mask({
10158 let res = parse_u32(next);
10159 let Some(val) = res else { break };
10160 val
10161 }),
10162 9u16 => ActSkbeditAttrs::Flags({
10163 let res = parse_u64(next);
10164 let Some(val) = res else { break };
10165 val
10166 }),
10167 10u16 => ActSkbeditAttrs::QueueMappingMax({
10168 let res = parse_u16(next);
10169 let Some(val) = res else { break };
10170 val
10171 }),
10172 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
10173 n => continue,
10174 };
10175 return Some(Ok(res));
10176 }
10177 Some(Err(ErrorContext::new(
10178 "ActSkbeditAttrs",
10179 r#type.and_then(|t| ActSkbeditAttrs::attr_from_type(t)),
10180 self.orig_loc,
10181 self.buf.as_ptr().wrapping_add(pos) as usize,
10182 )))
10183 }
10184}
10185impl<'a> std::fmt::Debug for IterableActSkbeditAttrs<'_> {
10186 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10187 let mut fmt = f.debug_struct("ActSkbeditAttrs");
10188 for attr in self.clone() {
10189 let attr = match attr {
10190 Ok(a) => a,
10191 Err(err) => {
10192 fmt.finish()?;
10193 f.write_str("Err(")?;
10194 err.fmt(f)?;
10195 return f.write_str(")");
10196 }
10197 };
10198 match attr {
10199 ActSkbeditAttrs::Tm(val) => fmt.field("Tm", &val),
10200 ActSkbeditAttrs::Parms(val) => fmt.field("Parms", &val),
10201 ActSkbeditAttrs::Priority(val) => fmt.field("Priority", &val),
10202 ActSkbeditAttrs::QueueMapping(val) => fmt.field("QueueMapping", &val),
10203 ActSkbeditAttrs::Mark(val) => fmt.field("Mark", &val),
10204 ActSkbeditAttrs::Pad(val) => fmt.field("Pad", &val),
10205 ActSkbeditAttrs::Ptype(val) => fmt.field("Ptype", &val),
10206 ActSkbeditAttrs::Mask(val) => fmt.field("Mask", &val),
10207 ActSkbeditAttrs::Flags(val) => fmt.field("Flags", &val),
10208 ActSkbeditAttrs::QueueMappingMax(val) => fmt.field("QueueMappingMax", &val),
10209 };
10210 }
10211 fmt.finish()
10212 }
10213}
10214impl IterableActSkbeditAttrs<'_> {
10215 pub fn lookup_attr(
10216 &self,
10217 offset: usize,
10218 missing_type: Option<u16>,
10219 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
10220 let mut stack = Vec::new();
10221 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
10222 if missing_type.is_some() && cur == offset {
10223 stack.push(("ActSkbeditAttrs", offset));
10224 return (
10225 stack,
10226 missing_type.and_then(|t| ActSkbeditAttrs::attr_from_type(t)),
10227 );
10228 }
10229 if cur > offset || cur + self.buf.len() < offset {
10230 return (stack, None);
10231 }
10232 let mut attrs = self.clone();
10233 let mut last_off = cur + attrs.pos;
10234 while let Some(attr) = attrs.next() {
10235 let Ok(attr) = attr else { break };
10236 match attr {
10237 ActSkbeditAttrs::Tm(val) => {
10238 if last_off == offset {
10239 stack.push(("Tm", last_off));
10240 break;
10241 }
10242 }
10243 ActSkbeditAttrs::Parms(val) => {
10244 if last_off == offset {
10245 stack.push(("Parms", last_off));
10246 break;
10247 }
10248 }
10249 ActSkbeditAttrs::Priority(val) => {
10250 if last_off == offset {
10251 stack.push(("Priority", last_off));
10252 break;
10253 }
10254 }
10255 ActSkbeditAttrs::QueueMapping(val) => {
10256 if last_off == offset {
10257 stack.push(("QueueMapping", last_off));
10258 break;
10259 }
10260 }
10261 ActSkbeditAttrs::Mark(val) => {
10262 if last_off == offset {
10263 stack.push(("Mark", last_off));
10264 break;
10265 }
10266 }
10267 ActSkbeditAttrs::Pad(val) => {
10268 if last_off == offset {
10269 stack.push(("Pad", last_off));
10270 break;
10271 }
10272 }
10273 ActSkbeditAttrs::Ptype(val) => {
10274 if last_off == offset {
10275 stack.push(("Ptype", last_off));
10276 break;
10277 }
10278 }
10279 ActSkbeditAttrs::Mask(val) => {
10280 if last_off == offset {
10281 stack.push(("Mask", last_off));
10282 break;
10283 }
10284 }
10285 ActSkbeditAttrs::Flags(val) => {
10286 if last_off == offset {
10287 stack.push(("Flags", last_off));
10288 break;
10289 }
10290 }
10291 ActSkbeditAttrs::QueueMappingMax(val) => {
10292 if last_off == offset {
10293 stack.push(("QueueMappingMax", last_off));
10294 break;
10295 }
10296 }
10297 _ => {}
10298 };
10299 last_off = cur + attrs.pos;
10300 }
10301 if !stack.is_empty() {
10302 stack.push(("ActSkbeditAttrs", cur));
10303 }
10304 (stack, None)
10305 }
10306}
10307#[derive(Clone)]
10308pub enum ActSkbmodAttrs<'a> {
10309 Tm(TcfT),
10310 Parms(&'a [u8]),
10311 Dmac(&'a [u8]),
10312 Smac(&'a [u8]),
10313 Etype(&'a [u8]),
10314 Pad(&'a [u8]),
10315}
10316impl<'a> IterableActSkbmodAttrs<'a> {
10317 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
10318 let mut iter = self.clone();
10319 iter.pos = 0;
10320 for attr in iter {
10321 if let Ok(ActSkbmodAttrs::Tm(val)) = attr {
10322 return Ok(val);
10323 }
10324 }
10325 Err(ErrorContext::new_missing(
10326 "ActSkbmodAttrs",
10327 "Tm",
10328 self.orig_loc,
10329 self.buf.as_ptr() as usize,
10330 ))
10331 }
10332 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
10333 let mut iter = self.clone();
10334 iter.pos = 0;
10335 for attr in iter {
10336 if let Ok(ActSkbmodAttrs::Parms(val)) = attr {
10337 return Ok(val);
10338 }
10339 }
10340 Err(ErrorContext::new_missing(
10341 "ActSkbmodAttrs",
10342 "Parms",
10343 self.orig_loc,
10344 self.buf.as_ptr() as usize,
10345 ))
10346 }
10347 pub fn get_dmac(&self) -> Result<&'a [u8], ErrorContext> {
10348 let mut iter = self.clone();
10349 iter.pos = 0;
10350 for attr in iter {
10351 if let Ok(ActSkbmodAttrs::Dmac(val)) = attr {
10352 return Ok(val);
10353 }
10354 }
10355 Err(ErrorContext::new_missing(
10356 "ActSkbmodAttrs",
10357 "Dmac",
10358 self.orig_loc,
10359 self.buf.as_ptr() as usize,
10360 ))
10361 }
10362 pub fn get_smac(&self) -> Result<&'a [u8], ErrorContext> {
10363 let mut iter = self.clone();
10364 iter.pos = 0;
10365 for attr in iter {
10366 if let Ok(ActSkbmodAttrs::Smac(val)) = attr {
10367 return Ok(val);
10368 }
10369 }
10370 Err(ErrorContext::new_missing(
10371 "ActSkbmodAttrs",
10372 "Smac",
10373 self.orig_loc,
10374 self.buf.as_ptr() as usize,
10375 ))
10376 }
10377 pub fn get_etype(&self) -> Result<&'a [u8], ErrorContext> {
10378 let mut iter = self.clone();
10379 iter.pos = 0;
10380 for attr in iter {
10381 if let Ok(ActSkbmodAttrs::Etype(val)) = attr {
10382 return Ok(val);
10383 }
10384 }
10385 Err(ErrorContext::new_missing(
10386 "ActSkbmodAttrs",
10387 "Etype",
10388 self.orig_loc,
10389 self.buf.as_ptr() as usize,
10390 ))
10391 }
10392 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
10393 let mut iter = self.clone();
10394 iter.pos = 0;
10395 for attr in iter {
10396 if let Ok(ActSkbmodAttrs::Pad(val)) = attr {
10397 return Ok(val);
10398 }
10399 }
10400 Err(ErrorContext::new_missing(
10401 "ActSkbmodAttrs",
10402 "Pad",
10403 self.orig_loc,
10404 self.buf.as_ptr() as usize,
10405 ))
10406 }
10407}
10408impl ActSkbmodAttrs<'_> {
10409 pub fn new<'a>(buf: &'a [u8]) -> IterableActSkbmodAttrs<'a> {
10410 IterableActSkbmodAttrs::with_loc(buf, buf.as_ptr() as usize)
10411 }
10412 fn attr_from_type(r#type: u16) -> Option<&'static str> {
10413 let res = match r#type {
10414 1u16 => "Tm",
10415 2u16 => "Parms",
10416 3u16 => "Dmac",
10417 4u16 => "Smac",
10418 5u16 => "Etype",
10419 6u16 => "Pad",
10420 _ => return None,
10421 };
10422 Some(res)
10423 }
10424}
10425#[derive(Clone, Copy, Default)]
10426pub struct IterableActSkbmodAttrs<'a> {
10427 buf: &'a [u8],
10428 pos: usize,
10429 orig_loc: usize,
10430}
10431impl<'a> IterableActSkbmodAttrs<'a> {
10432 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
10433 Self {
10434 buf,
10435 pos: 0,
10436 orig_loc,
10437 }
10438 }
10439 pub fn get_buf(&self) -> &'a [u8] {
10440 self.buf
10441 }
10442}
10443impl<'a> Iterator for IterableActSkbmodAttrs<'a> {
10444 type Item = Result<ActSkbmodAttrs<'a>, ErrorContext>;
10445 fn next(&mut self) -> Option<Self::Item> {
10446 let mut pos;
10447 let mut r#type;
10448 loop {
10449 pos = self.pos;
10450 r#type = None;
10451 if self.buf.len() == self.pos {
10452 return None;
10453 }
10454 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
10455 self.pos = self.buf.len();
10456 break;
10457 };
10458 r#type = Some(header.r#type);
10459 let res = match header.r#type {
10460 1u16 => ActSkbmodAttrs::Tm({
10461 let res = Some(TcfT::new_from_zeroed(next));
10462 let Some(val) = res else { break };
10463 val
10464 }),
10465 2u16 => ActSkbmodAttrs::Parms({
10466 let res = Some(next);
10467 let Some(val) = res else { break };
10468 val
10469 }),
10470 3u16 => ActSkbmodAttrs::Dmac({
10471 let res = Some(next);
10472 let Some(val) = res else { break };
10473 val
10474 }),
10475 4u16 => ActSkbmodAttrs::Smac({
10476 let res = Some(next);
10477 let Some(val) = res else { break };
10478 val
10479 }),
10480 5u16 => ActSkbmodAttrs::Etype({
10481 let res = Some(next);
10482 let Some(val) = res else { break };
10483 val
10484 }),
10485 6u16 => ActSkbmodAttrs::Pad({
10486 let res = Some(next);
10487 let Some(val) = res else { break };
10488 val
10489 }),
10490 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
10491 n => continue,
10492 };
10493 return Some(Ok(res));
10494 }
10495 Some(Err(ErrorContext::new(
10496 "ActSkbmodAttrs",
10497 r#type.and_then(|t| ActSkbmodAttrs::attr_from_type(t)),
10498 self.orig_loc,
10499 self.buf.as_ptr().wrapping_add(pos) as usize,
10500 )))
10501 }
10502}
10503impl<'a> std::fmt::Debug for IterableActSkbmodAttrs<'_> {
10504 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10505 let mut fmt = f.debug_struct("ActSkbmodAttrs");
10506 for attr in self.clone() {
10507 let attr = match attr {
10508 Ok(a) => a,
10509 Err(err) => {
10510 fmt.finish()?;
10511 f.write_str("Err(")?;
10512 err.fmt(f)?;
10513 return f.write_str(")");
10514 }
10515 };
10516 match attr {
10517 ActSkbmodAttrs::Tm(val) => fmt.field("Tm", &val),
10518 ActSkbmodAttrs::Parms(val) => fmt.field("Parms", &val),
10519 ActSkbmodAttrs::Dmac(val) => fmt.field("Dmac", &val),
10520 ActSkbmodAttrs::Smac(val) => fmt.field("Smac", &val),
10521 ActSkbmodAttrs::Etype(val) => fmt.field("Etype", &val),
10522 ActSkbmodAttrs::Pad(val) => fmt.field("Pad", &val),
10523 };
10524 }
10525 fmt.finish()
10526 }
10527}
10528impl IterableActSkbmodAttrs<'_> {
10529 pub fn lookup_attr(
10530 &self,
10531 offset: usize,
10532 missing_type: Option<u16>,
10533 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
10534 let mut stack = Vec::new();
10535 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
10536 if missing_type.is_some() && cur == offset {
10537 stack.push(("ActSkbmodAttrs", offset));
10538 return (
10539 stack,
10540 missing_type.and_then(|t| ActSkbmodAttrs::attr_from_type(t)),
10541 );
10542 }
10543 if cur > offset || cur + self.buf.len() < offset {
10544 return (stack, None);
10545 }
10546 let mut attrs = self.clone();
10547 let mut last_off = cur + attrs.pos;
10548 while let Some(attr) = attrs.next() {
10549 let Ok(attr) = attr else { break };
10550 match attr {
10551 ActSkbmodAttrs::Tm(val) => {
10552 if last_off == offset {
10553 stack.push(("Tm", last_off));
10554 break;
10555 }
10556 }
10557 ActSkbmodAttrs::Parms(val) => {
10558 if last_off == offset {
10559 stack.push(("Parms", last_off));
10560 break;
10561 }
10562 }
10563 ActSkbmodAttrs::Dmac(val) => {
10564 if last_off == offset {
10565 stack.push(("Dmac", last_off));
10566 break;
10567 }
10568 }
10569 ActSkbmodAttrs::Smac(val) => {
10570 if last_off == offset {
10571 stack.push(("Smac", last_off));
10572 break;
10573 }
10574 }
10575 ActSkbmodAttrs::Etype(val) => {
10576 if last_off == offset {
10577 stack.push(("Etype", last_off));
10578 break;
10579 }
10580 }
10581 ActSkbmodAttrs::Pad(val) => {
10582 if last_off == offset {
10583 stack.push(("Pad", last_off));
10584 break;
10585 }
10586 }
10587 _ => {}
10588 };
10589 last_off = cur + attrs.pos;
10590 }
10591 if !stack.is_empty() {
10592 stack.push(("ActSkbmodAttrs", cur));
10593 }
10594 (stack, None)
10595 }
10596}
10597#[derive(Clone)]
10598pub enum ActTunnelKeyAttrs<'a> {
10599 Tm(TcfT),
10600 Parms(&'a [u8]),
10601 EncIpv4Src(u32),
10602 EncIpv4Dst(u32),
10603 EncIpv6Src(&'a [u8]),
10604 EncIpv6Dst(&'a [u8]),
10605 EncKeyId(u64),
10606 Pad(&'a [u8]),
10607 EncDstPort(u16),
10608 NoCsum(u8),
10609 EncOpts(&'a [u8]),
10610 EncTos(u8),
10611 EncTtl(u8),
10612 NoFrag(()),
10613}
10614impl<'a> IterableActTunnelKeyAttrs<'a> {
10615 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
10616 let mut iter = self.clone();
10617 iter.pos = 0;
10618 for attr in iter {
10619 if let Ok(ActTunnelKeyAttrs::Tm(val)) = attr {
10620 return Ok(val);
10621 }
10622 }
10623 Err(ErrorContext::new_missing(
10624 "ActTunnelKeyAttrs",
10625 "Tm",
10626 self.orig_loc,
10627 self.buf.as_ptr() as usize,
10628 ))
10629 }
10630 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
10631 let mut iter = self.clone();
10632 iter.pos = 0;
10633 for attr in iter {
10634 if let Ok(ActTunnelKeyAttrs::Parms(val)) = attr {
10635 return Ok(val);
10636 }
10637 }
10638 Err(ErrorContext::new_missing(
10639 "ActTunnelKeyAttrs",
10640 "Parms",
10641 self.orig_loc,
10642 self.buf.as_ptr() as usize,
10643 ))
10644 }
10645 pub fn get_enc_ipv4_src(&self) -> Result<u32, ErrorContext> {
10646 let mut iter = self.clone();
10647 iter.pos = 0;
10648 for attr in iter {
10649 if let Ok(ActTunnelKeyAttrs::EncIpv4Src(val)) = attr {
10650 return Ok(val);
10651 }
10652 }
10653 Err(ErrorContext::new_missing(
10654 "ActTunnelKeyAttrs",
10655 "EncIpv4Src",
10656 self.orig_loc,
10657 self.buf.as_ptr() as usize,
10658 ))
10659 }
10660 pub fn get_enc_ipv4_dst(&self) -> Result<u32, ErrorContext> {
10661 let mut iter = self.clone();
10662 iter.pos = 0;
10663 for attr in iter {
10664 if let Ok(ActTunnelKeyAttrs::EncIpv4Dst(val)) = attr {
10665 return Ok(val);
10666 }
10667 }
10668 Err(ErrorContext::new_missing(
10669 "ActTunnelKeyAttrs",
10670 "EncIpv4Dst",
10671 self.orig_loc,
10672 self.buf.as_ptr() as usize,
10673 ))
10674 }
10675 pub fn get_enc_ipv6_src(&self) -> Result<&'a [u8], ErrorContext> {
10676 let mut iter = self.clone();
10677 iter.pos = 0;
10678 for attr in iter {
10679 if let Ok(ActTunnelKeyAttrs::EncIpv6Src(val)) = attr {
10680 return Ok(val);
10681 }
10682 }
10683 Err(ErrorContext::new_missing(
10684 "ActTunnelKeyAttrs",
10685 "EncIpv6Src",
10686 self.orig_loc,
10687 self.buf.as_ptr() as usize,
10688 ))
10689 }
10690 pub fn get_enc_ipv6_dst(&self) -> Result<&'a [u8], ErrorContext> {
10691 let mut iter = self.clone();
10692 iter.pos = 0;
10693 for attr in iter {
10694 if let Ok(ActTunnelKeyAttrs::EncIpv6Dst(val)) = attr {
10695 return Ok(val);
10696 }
10697 }
10698 Err(ErrorContext::new_missing(
10699 "ActTunnelKeyAttrs",
10700 "EncIpv6Dst",
10701 self.orig_loc,
10702 self.buf.as_ptr() as usize,
10703 ))
10704 }
10705 pub fn get_enc_key_id(&self) -> Result<u64, ErrorContext> {
10706 let mut iter = self.clone();
10707 iter.pos = 0;
10708 for attr in iter {
10709 if let Ok(ActTunnelKeyAttrs::EncKeyId(val)) = attr {
10710 return Ok(val);
10711 }
10712 }
10713 Err(ErrorContext::new_missing(
10714 "ActTunnelKeyAttrs",
10715 "EncKeyId",
10716 self.orig_loc,
10717 self.buf.as_ptr() as usize,
10718 ))
10719 }
10720 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
10721 let mut iter = self.clone();
10722 iter.pos = 0;
10723 for attr in iter {
10724 if let Ok(ActTunnelKeyAttrs::Pad(val)) = attr {
10725 return Ok(val);
10726 }
10727 }
10728 Err(ErrorContext::new_missing(
10729 "ActTunnelKeyAttrs",
10730 "Pad",
10731 self.orig_loc,
10732 self.buf.as_ptr() as usize,
10733 ))
10734 }
10735 pub fn get_enc_dst_port(&self) -> Result<u16, ErrorContext> {
10736 let mut iter = self.clone();
10737 iter.pos = 0;
10738 for attr in iter {
10739 if let Ok(ActTunnelKeyAttrs::EncDstPort(val)) = attr {
10740 return Ok(val);
10741 }
10742 }
10743 Err(ErrorContext::new_missing(
10744 "ActTunnelKeyAttrs",
10745 "EncDstPort",
10746 self.orig_loc,
10747 self.buf.as_ptr() as usize,
10748 ))
10749 }
10750 pub fn get_no_csum(&self) -> Result<u8, ErrorContext> {
10751 let mut iter = self.clone();
10752 iter.pos = 0;
10753 for attr in iter {
10754 if let Ok(ActTunnelKeyAttrs::NoCsum(val)) = attr {
10755 return Ok(val);
10756 }
10757 }
10758 Err(ErrorContext::new_missing(
10759 "ActTunnelKeyAttrs",
10760 "NoCsum",
10761 self.orig_loc,
10762 self.buf.as_ptr() as usize,
10763 ))
10764 }
10765 pub fn get_enc_opts(&self) -> Result<&'a [u8], ErrorContext> {
10766 let mut iter = self.clone();
10767 iter.pos = 0;
10768 for attr in iter {
10769 if let Ok(ActTunnelKeyAttrs::EncOpts(val)) = attr {
10770 return Ok(val);
10771 }
10772 }
10773 Err(ErrorContext::new_missing(
10774 "ActTunnelKeyAttrs",
10775 "EncOpts",
10776 self.orig_loc,
10777 self.buf.as_ptr() as usize,
10778 ))
10779 }
10780 pub fn get_enc_tos(&self) -> Result<u8, ErrorContext> {
10781 let mut iter = self.clone();
10782 iter.pos = 0;
10783 for attr in iter {
10784 if let Ok(ActTunnelKeyAttrs::EncTos(val)) = attr {
10785 return Ok(val);
10786 }
10787 }
10788 Err(ErrorContext::new_missing(
10789 "ActTunnelKeyAttrs",
10790 "EncTos",
10791 self.orig_loc,
10792 self.buf.as_ptr() as usize,
10793 ))
10794 }
10795 pub fn get_enc_ttl(&self) -> Result<u8, ErrorContext> {
10796 let mut iter = self.clone();
10797 iter.pos = 0;
10798 for attr in iter {
10799 if let Ok(ActTunnelKeyAttrs::EncTtl(val)) = attr {
10800 return Ok(val);
10801 }
10802 }
10803 Err(ErrorContext::new_missing(
10804 "ActTunnelKeyAttrs",
10805 "EncTtl",
10806 self.orig_loc,
10807 self.buf.as_ptr() as usize,
10808 ))
10809 }
10810 pub fn get_no_frag(&self) -> Result<(), ErrorContext> {
10811 let mut iter = self.clone();
10812 iter.pos = 0;
10813 for attr in iter {
10814 if let Ok(ActTunnelKeyAttrs::NoFrag(val)) = attr {
10815 return Ok(val);
10816 }
10817 }
10818 Err(ErrorContext::new_missing(
10819 "ActTunnelKeyAttrs",
10820 "NoFrag",
10821 self.orig_loc,
10822 self.buf.as_ptr() as usize,
10823 ))
10824 }
10825}
10826impl ActTunnelKeyAttrs<'_> {
10827 pub fn new<'a>(buf: &'a [u8]) -> IterableActTunnelKeyAttrs<'a> {
10828 IterableActTunnelKeyAttrs::with_loc(buf, buf.as_ptr() as usize)
10829 }
10830 fn attr_from_type(r#type: u16) -> Option<&'static str> {
10831 let res = match r#type {
10832 1u16 => "Tm",
10833 2u16 => "Parms",
10834 3u16 => "EncIpv4Src",
10835 4u16 => "EncIpv4Dst",
10836 5u16 => "EncIpv6Src",
10837 6u16 => "EncIpv6Dst",
10838 7u16 => "EncKeyId",
10839 8u16 => "Pad",
10840 9u16 => "EncDstPort",
10841 10u16 => "NoCsum",
10842 11u16 => "EncOpts",
10843 12u16 => "EncTos",
10844 13u16 => "EncTtl",
10845 14u16 => "NoFrag",
10846 _ => return None,
10847 };
10848 Some(res)
10849 }
10850}
10851#[derive(Clone, Copy, Default)]
10852pub struct IterableActTunnelKeyAttrs<'a> {
10853 buf: &'a [u8],
10854 pos: usize,
10855 orig_loc: usize,
10856}
10857impl<'a> IterableActTunnelKeyAttrs<'a> {
10858 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
10859 Self {
10860 buf,
10861 pos: 0,
10862 orig_loc,
10863 }
10864 }
10865 pub fn get_buf(&self) -> &'a [u8] {
10866 self.buf
10867 }
10868}
10869impl<'a> Iterator for IterableActTunnelKeyAttrs<'a> {
10870 type Item = Result<ActTunnelKeyAttrs<'a>, ErrorContext>;
10871 fn next(&mut self) -> Option<Self::Item> {
10872 let mut pos;
10873 let mut r#type;
10874 loop {
10875 pos = self.pos;
10876 r#type = None;
10877 if self.buf.len() == self.pos {
10878 return None;
10879 }
10880 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
10881 self.pos = self.buf.len();
10882 break;
10883 };
10884 r#type = Some(header.r#type);
10885 let res = match header.r#type {
10886 1u16 => ActTunnelKeyAttrs::Tm({
10887 let res = Some(TcfT::new_from_zeroed(next));
10888 let Some(val) = res else { break };
10889 val
10890 }),
10891 2u16 => ActTunnelKeyAttrs::Parms({
10892 let res = Some(next);
10893 let Some(val) = res else { break };
10894 val
10895 }),
10896 3u16 => ActTunnelKeyAttrs::EncIpv4Src({
10897 let res = parse_be_u32(next);
10898 let Some(val) = res else { break };
10899 val
10900 }),
10901 4u16 => ActTunnelKeyAttrs::EncIpv4Dst({
10902 let res = parse_be_u32(next);
10903 let Some(val) = res else { break };
10904 val
10905 }),
10906 5u16 => ActTunnelKeyAttrs::EncIpv6Src({
10907 let res = Some(next);
10908 let Some(val) = res else { break };
10909 val
10910 }),
10911 6u16 => ActTunnelKeyAttrs::EncIpv6Dst({
10912 let res = Some(next);
10913 let Some(val) = res else { break };
10914 val
10915 }),
10916 7u16 => ActTunnelKeyAttrs::EncKeyId({
10917 let res = parse_be_u64(next);
10918 let Some(val) = res else { break };
10919 val
10920 }),
10921 8u16 => ActTunnelKeyAttrs::Pad({
10922 let res = Some(next);
10923 let Some(val) = res else { break };
10924 val
10925 }),
10926 9u16 => ActTunnelKeyAttrs::EncDstPort({
10927 let res = parse_be_u16(next);
10928 let Some(val) = res else { break };
10929 val
10930 }),
10931 10u16 => ActTunnelKeyAttrs::NoCsum({
10932 let res = parse_u8(next);
10933 let Some(val) = res else { break };
10934 val
10935 }),
10936 11u16 => ActTunnelKeyAttrs::EncOpts({
10937 let res = Some(next);
10938 let Some(val) = res else { break };
10939 val
10940 }),
10941 12u16 => ActTunnelKeyAttrs::EncTos({
10942 let res = parse_u8(next);
10943 let Some(val) = res else { break };
10944 val
10945 }),
10946 13u16 => ActTunnelKeyAttrs::EncTtl({
10947 let res = parse_u8(next);
10948 let Some(val) = res else { break };
10949 val
10950 }),
10951 14u16 => ActTunnelKeyAttrs::NoFrag(()),
10952 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
10953 n => continue,
10954 };
10955 return Some(Ok(res));
10956 }
10957 Some(Err(ErrorContext::new(
10958 "ActTunnelKeyAttrs",
10959 r#type.and_then(|t| ActTunnelKeyAttrs::attr_from_type(t)),
10960 self.orig_loc,
10961 self.buf.as_ptr().wrapping_add(pos) as usize,
10962 )))
10963 }
10964}
10965impl<'a> std::fmt::Debug for IterableActTunnelKeyAttrs<'_> {
10966 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10967 let mut fmt = f.debug_struct("ActTunnelKeyAttrs");
10968 for attr in self.clone() {
10969 let attr = match attr {
10970 Ok(a) => a,
10971 Err(err) => {
10972 fmt.finish()?;
10973 f.write_str("Err(")?;
10974 err.fmt(f)?;
10975 return f.write_str(")");
10976 }
10977 };
10978 match attr {
10979 ActTunnelKeyAttrs::Tm(val) => fmt.field("Tm", &val),
10980 ActTunnelKeyAttrs::Parms(val) => fmt.field("Parms", &val),
10981 ActTunnelKeyAttrs::EncIpv4Src(val) => fmt.field("EncIpv4Src", &val),
10982 ActTunnelKeyAttrs::EncIpv4Dst(val) => fmt.field("EncIpv4Dst", &val),
10983 ActTunnelKeyAttrs::EncIpv6Src(val) => fmt.field("EncIpv6Src", &val),
10984 ActTunnelKeyAttrs::EncIpv6Dst(val) => fmt.field("EncIpv6Dst", &val),
10985 ActTunnelKeyAttrs::EncKeyId(val) => fmt.field("EncKeyId", &val),
10986 ActTunnelKeyAttrs::Pad(val) => fmt.field("Pad", &val),
10987 ActTunnelKeyAttrs::EncDstPort(val) => fmt.field("EncDstPort", &val),
10988 ActTunnelKeyAttrs::NoCsum(val) => fmt.field("NoCsum", &val),
10989 ActTunnelKeyAttrs::EncOpts(val) => fmt.field("EncOpts", &val),
10990 ActTunnelKeyAttrs::EncTos(val) => fmt.field("EncTos", &val),
10991 ActTunnelKeyAttrs::EncTtl(val) => fmt.field("EncTtl", &val),
10992 ActTunnelKeyAttrs::NoFrag(val) => fmt.field("NoFrag", &val),
10993 };
10994 }
10995 fmt.finish()
10996 }
10997}
10998impl IterableActTunnelKeyAttrs<'_> {
10999 pub fn lookup_attr(
11000 &self,
11001 offset: usize,
11002 missing_type: Option<u16>,
11003 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11004 let mut stack = Vec::new();
11005 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11006 if missing_type.is_some() && cur == offset {
11007 stack.push(("ActTunnelKeyAttrs", offset));
11008 return (
11009 stack,
11010 missing_type.and_then(|t| ActTunnelKeyAttrs::attr_from_type(t)),
11011 );
11012 }
11013 if cur > offset || cur + self.buf.len() < offset {
11014 return (stack, None);
11015 }
11016 let mut attrs = self.clone();
11017 let mut last_off = cur + attrs.pos;
11018 while let Some(attr) = attrs.next() {
11019 let Ok(attr) = attr else { break };
11020 match attr {
11021 ActTunnelKeyAttrs::Tm(val) => {
11022 if last_off == offset {
11023 stack.push(("Tm", last_off));
11024 break;
11025 }
11026 }
11027 ActTunnelKeyAttrs::Parms(val) => {
11028 if last_off == offset {
11029 stack.push(("Parms", last_off));
11030 break;
11031 }
11032 }
11033 ActTunnelKeyAttrs::EncIpv4Src(val) => {
11034 if last_off == offset {
11035 stack.push(("EncIpv4Src", last_off));
11036 break;
11037 }
11038 }
11039 ActTunnelKeyAttrs::EncIpv4Dst(val) => {
11040 if last_off == offset {
11041 stack.push(("EncIpv4Dst", last_off));
11042 break;
11043 }
11044 }
11045 ActTunnelKeyAttrs::EncIpv6Src(val) => {
11046 if last_off == offset {
11047 stack.push(("EncIpv6Src", last_off));
11048 break;
11049 }
11050 }
11051 ActTunnelKeyAttrs::EncIpv6Dst(val) => {
11052 if last_off == offset {
11053 stack.push(("EncIpv6Dst", last_off));
11054 break;
11055 }
11056 }
11057 ActTunnelKeyAttrs::EncKeyId(val) => {
11058 if last_off == offset {
11059 stack.push(("EncKeyId", last_off));
11060 break;
11061 }
11062 }
11063 ActTunnelKeyAttrs::Pad(val) => {
11064 if last_off == offset {
11065 stack.push(("Pad", last_off));
11066 break;
11067 }
11068 }
11069 ActTunnelKeyAttrs::EncDstPort(val) => {
11070 if last_off == offset {
11071 stack.push(("EncDstPort", last_off));
11072 break;
11073 }
11074 }
11075 ActTunnelKeyAttrs::NoCsum(val) => {
11076 if last_off == offset {
11077 stack.push(("NoCsum", last_off));
11078 break;
11079 }
11080 }
11081 ActTunnelKeyAttrs::EncOpts(val) => {
11082 if last_off == offset {
11083 stack.push(("EncOpts", last_off));
11084 break;
11085 }
11086 }
11087 ActTunnelKeyAttrs::EncTos(val) => {
11088 if last_off == offset {
11089 stack.push(("EncTos", last_off));
11090 break;
11091 }
11092 }
11093 ActTunnelKeyAttrs::EncTtl(val) => {
11094 if last_off == offset {
11095 stack.push(("EncTtl", last_off));
11096 break;
11097 }
11098 }
11099 ActTunnelKeyAttrs::NoFrag(val) => {
11100 if last_off == offset {
11101 stack.push(("NoFrag", last_off));
11102 break;
11103 }
11104 }
11105 _ => {}
11106 };
11107 last_off = cur + attrs.pos;
11108 }
11109 if !stack.is_empty() {
11110 stack.push(("ActTunnelKeyAttrs", cur));
11111 }
11112 (stack, None)
11113 }
11114}
11115#[derive(Clone)]
11116pub enum ActVlanAttrs<'a> {
11117 Tm(TcfT),
11118 Parms(TcVlan),
11119 PushVlanId(u16),
11120 PushVlanProtocol(u16),
11121 Pad(&'a [u8]),
11122 PushVlanPriority(u8),
11123 PushEthDst(&'a [u8]),
11124 PushEthSrc(&'a [u8]),
11125}
11126impl<'a> IterableActVlanAttrs<'a> {
11127 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
11128 let mut iter = self.clone();
11129 iter.pos = 0;
11130 for attr in iter {
11131 if let Ok(ActVlanAttrs::Tm(val)) = attr {
11132 return Ok(val);
11133 }
11134 }
11135 Err(ErrorContext::new_missing(
11136 "ActVlanAttrs",
11137 "Tm",
11138 self.orig_loc,
11139 self.buf.as_ptr() as usize,
11140 ))
11141 }
11142 pub fn get_parms(&self) -> Result<TcVlan, ErrorContext> {
11143 let mut iter = self.clone();
11144 iter.pos = 0;
11145 for attr in iter {
11146 if let Ok(ActVlanAttrs::Parms(val)) = attr {
11147 return Ok(val);
11148 }
11149 }
11150 Err(ErrorContext::new_missing(
11151 "ActVlanAttrs",
11152 "Parms",
11153 self.orig_loc,
11154 self.buf.as_ptr() as usize,
11155 ))
11156 }
11157 pub fn get_push_vlan_id(&self) -> Result<u16, ErrorContext> {
11158 let mut iter = self.clone();
11159 iter.pos = 0;
11160 for attr in iter {
11161 if let Ok(ActVlanAttrs::PushVlanId(val)) = attr {
11162 return Ok(val);
11163 }
11164 }
11165 Err(ErrorContext::new_missing(
11166 "ActVlanAttrs",
11167 "PushVlanId",
11168 self.orig_loc,
11169 self.buf.as_ptr() as usize,
11170 ))
11171 }
11172 pub fn get_push_vlan_protocol(&self) -> Result<u16, ErrorContext> {
11173 let mut iter = self.clone();
11174 iter.pos = 0;
11175 for attr in iter {
11176 if let Ok(ActVlanAttrs::PushVlanProtocol(val)) = attr {
11177 return Ok(val);
11178 }
11179 }
11180 Err(ErrorContext::new_missing(
11181 "ActVlanAttrs",
11182 "PushVlanProtocol",
11183 self.orig_loc,
11184 self.buf.as_ptr() as usize,
11185 ))
11186 }
11187 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
11188 let mut iter = self.clone();
11189 iter.pos = 0;
11190 for attr in iter {
11191 if let Ok(ActVlanAttrs::Pad(val)) = attr {
11192 return Ok(val);
11193 }
11194 }
11195 Err(ErrorContext::new_missing(
11196 "ActVlanAttrs",
11197 "Pad",
11198 self.orig_loc,
11199 self.buf.as_ptr() as usize,
11200 ))
11201 }
11202 pub fn get_push_vlan_priority(&self) -> Result<u8, ErrorContext> {
11203 let mut iter = self.clone();
11204 iter.pos = 0;
11205 for attr in iter {
11206 if let Ok(ActVlanAttrs::PushVlanPriority(val)) = attr {
11207 return Ok(val);
11208 }
11209 }
11210 Err(ErrorContext::new_missing(
11211 "ActVlanAttrs",
11212 "PushVlanPriority",
11213 self.orig_loc,
11214 self.buf.as_ptr() as usize,
11215 ))
11216 }
11217 pub fn get_push_eth_dst(&self) -> Result<&'a [u8], ErrorContext> {
11218 let mut iter = self.clone();
11219 iter.pos = 0;
11220 for attr in iter {
11221 if let Ok(ActVlanAttrs::PushEthDst(val)) = attr {
11222 return Ok(val);
11223 }
11224 }
11225 Err(ErrorContext::new_missing(
11226 "ActVlanAttrs",
11227 "PushEthDst",
11228 self.orig_loc,
11229 self.buf.as_ptr() as usize,
11230 ))
11231 }
11232 pub fn get_push_eth_src(&self) -> Result<&'a [u8], ErrorContext> {
11233 let mut iter = self.clone();
11234 iter.pos = 0;
11235 for attr in iter {
11236 if let Ok(ActVlanAttrs::PushEthSrc(val)) = attr {
11237 return Ok(val);
11238 }
11239 }
11240 Err(ErrorContext::new_missing(
11241 "ActVlanAttrs",
11242 "PushEthSrc",
11243 self.orig_loc,
11244 self.buf.as_ptr() as usize,
11245 ))
11246 }
11247}
11248impl ActVlanAttrs<'_> {
11249 pub fn new<'a>(buf: &'a [u8]) -> IterableActVlanAttrs<'a> {
11250 IterableActVlanAttrs::with_loc(buf, buf.as_ptr() as usize)
11251 }
11252 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11253 let res = match r#type {
11254 1u16 => "Tm",
11255 2u16 => "Parms",
11256 3u16 => "PushVlanId",
11257 4u16 => "PushVlanProtocol",
11258 5u16 => "Pad",
11259 6u16 => "PushVlanPriority",
11260 7u16 => "PushEthDst",
11261 8u16 => "PushEthSrc",
11262 _ => return None,
11263 };
11264 Some(res)
11265 }
11266}
11267#[derive(Clone, Copy, Default)]
11268pub struct IterableActVlanAttrs<'a> {
11269 buf: &'a [u8],
11270 pos: usize,
11271 orig_loc: usize,
11272}
11273impl<'a> IterableActVlanAttrs<'a> {
11274 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11275 Self {
11276 buf,
11277 pos: 0,
11278 orig_loc,
11279 }
11280 }
11281 pub fn get_buf(&self) -> &'a [u8] {
11282 self.buf
11283 }
11284}
11285impl<'a> Iterator for IterableActVlanAttrs<'a> {
11286 type Item = Result<ActVlanAttrs<'a>, ErrorContext>;
11287 fn next(&mut self) -> Option<Self::Item> {
11288 let mut pos;
11289 let mut r#type;
11290 loop {
11291 pos = self.pos;
11292 r#type = None;
11293 if self.buf.len() == self.pos {
11294 return None;
11295 }
11296 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
11297 self.pos = self.buf.len();
11298 break;
11299 };
11300 r#type = Some(header.r#type);
11301 let res = match header.r#type {
11302 1u16 => ActVlanAttrs::Tm({
11303 let res = Some(TcfT::new_from_zeroed(next));
11304 let Some(val) = res else { break };
11305 val
11306 }),
11307 2u16 => ActVlanAttrs::Parms({
11308 let res = Some(TcVlan::new_from_zeroed(next));
11309 let Some(val) = res else { break };
11310 val
11311 }),
11312 3u16 => ActVlanAttrs::PushVlanId({
11313 let res = parse_u16(next);
11314 let Some(val) = res else { break };
11315 val
11316 }),
11317 4u16 => ActVlanAttrs::PushVlanProtocol({
11318 let res = parse_u16(next);
11319 let Some(val) = res else { break };
11320 val
11321 }),
11322 5u16 => ActVlanAttrs::Pad({
11323 let res = Some(next);
11324 let Some(val) = res else { break };
11325 val
11326 }),
11327 6u16 => ActVlanAttrs::PushVlanPriority({
11328 let res = parse_u8(next);
11329 let Some(val) = res else { break };
11330 val
11331 }),
11332 7u16 => ActVlanAttrs::PushEthDst({
11333 let res = Some(next);
11334 let Some(val) = res else { break };
11335 val
11336 }),
11337 8u16 => ActVlanAttrs::PushEthSrc({
11338 let res = Some(next);
11339 let Some(val) = res else { break };
11340 val
11341 }),
11342 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
11343 n => continue,
11344 };
11345 return Some(Ok(res));
11346 }
11347 Some(Err(ErrorContext::new(
11348 "ActVlanAttrs",
11349 r#type.and_then(|t| ActVlanAttrs::attr_from_type(t)),
11350 self.orig_loc,
11351 self.buf.as_ptr().wrapping_add(pos) as usize,
11352 )))
11353 }
11354}
11355impl<'a> std::fmt::Debug for IterableActVlanAttrs<'_> {
11356 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11357 let mut fmt = f.debug_struct("ActVlanAttrs");
11358 for attr in self.clone() {
11359 let attr = match attr {
11360 Ok(a) => a,
11361 Err(err) => {
11362 fmt.finish()?;
11363 f.write_str("Err(")?;
11364 err.fmt(f)?;
11365 return f.write_str(")");
11366 }
11367 };
11368 match attr {
11369 ActVlanAttrs::Tm(val) => fmt.field("Tm", &val),
11370 ActVlanAttrs::Parms(val) => fmt.field("Parms", &val),
11371 ActVlanAttrs::PushVlanId(val) => fmt.field("PushVlanId", &val),
11372 ActVlanAttrs::PushVlanProtocol(val) => fmt.field("PushVlanProtocol", &val),
11373 ActVlanAttrs::Pad(val) => fmt.field("Pad", &val),
11374 ActVlanAttrs::PushVlanPriority(val) => fmt.field("PushVlanPriority", &val),
11375 ActVlanAttrs::PushEthDst(val) => fmt.field("PushEthDst", &val),
11376 ActVlanAttrs::PushEthSrc(val) => fmt.field("PushEthSrc", &val),
11377 };
11378 }
11379 fmt.finish()
11380 }
11381}
11382impl IterableActVlanAttrs<'_> {
11383 pub fn lookup_attr(
11384 &self,
11385 offset: usize,
11386 missing_type: Option<u16>,
11387 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11388 let mut stack = Vec::new();
11389 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11390 if missing_type.is_some() && cur == offset {
11391 stack.push(("ActVlanAttrs", offset));
11392 return (
11393 stack,
11394 missing_type.and_then(|t| ActVlanAttrs::attr_from_type(t)),
11395 );
11396 }
11397 if cur > offset || cur + self.buf.len() < offset {
11398 return (stack, None);
11399 }
11400 let mut attrs = self.clone();
11401 let mut last_off = cur + attrs.pos;
11402 while let Some(attr) = attrs.next() {
11403 let Ok(attr) = attr else { break };
11404 match attr {
11405 ActVlanAttrs::Tm(val) => {
11406 if last_off == offset {
11407 stack.push(("Tm", last_off));
11408 break;
11409 }
11410 }
11411 ActVlanAttrs::Parms(val) => {
11412 if last_off == offset {
11413 stack.push(("Parms", last_off));
11414 break;
11415 }
11416 }
11417 ActVlanAttrs::PushVlanId(val) => {
11418 if last_off == offset {
11419 stack.push(("PushVlanId", last_off));
11420 break;
11421 }
11422 }
11423 ActVlanAttrs::PushVlanProtocol(val) => {
11424 if last_off == offset {
11425 stack.push(("PushVlanProtocol", last_off));
11426 break;
11427 }
11428 }
11429 ActVlanAttrs::Pad(val) => {
11430 if last_off == offset {
11431 stack.push(("Pad", last_off));
11432 break;
11433 }
11434 }
11435 ActVlanAttrs::PushVlanPriority(val) => {
11436 if last_off == offset {
11437 stack.push(("PushVlanPriority", last_off));
11438 break;
11439 }
11440 }
11441 ActVlanAttrs::PushEthDst(val) => {
11442 if last_off == offset {
11443 stack.push(("PushEthDst", last_off));
11444 break;
11445 }
11446 }
11447 ActVlanAttrs::PushEthSrc(val) => {
11448 if last_off == offset {
11449 stack.push(("PushEthSrc", last_off));
11450 break;
11451 }
11452 }
11453 _ => {}
11454 };
11455 last_off = cur + attrs.pos;
11456 }
11457 if !stack.is_empty() {
11458 stack.push(("ActVlanAttrs", cur));
11459 }
11460 (stack, None)
11461 }
11462}
11463#[derive(Clone)]
11464pub enum BasicAttrs<'a> {
11465 Classid(u32),
11466 Ematches(IterableEmatchAttrs<'a>),
11467 Act(IterableArrayActAttrs<'a>),
11468 Police(IterablePoliceAttrs<'a>),
11469 Pcnt(TcBasicPcnt),
11470 Pad(&'a [u8]),
11471}
11472impl<'a> IterableBasicAttrs<'a> {
11473 pub fn get_classid(&self) -> Result<u32, ErrorContext> {
11474 let mut iter = self.clone();
11475 iter.pos = 0;
11476 for attr in iter {
11477 if let Ok(BasicAttrs::Classid(val)) = attr {
11478 return Ok(val);
11479 }
11480 }
11481 Err(ErrorContext::new_missing(
11482 "BasicAttrs",
11483 "Classid",
11484 self.orig_loc,
11485 self.buf.as_ptr() as usize,
11486 ))
11487 }
11488 pub fn get_ematches(&self) -> Result<IterableEmatchAttrs<'a>, ErrorContext> {
11489 let mut iter = self.clone();
11490 iter.pos = 0;
11491 for attr in iter {
11492 if let Ok(BasicAttrs::Ematches(val)) = attr {
11493 return Ok(val);
11494 }
11495 }
11496 Err(ErrorContext::new_missing(
11497 "BasicAttrs",
11498 "Ematches",
11499 self.orig_loc,
11500 self.buf.as_ptr() as usize,
11501 ))
11502 }
11503 pub fn get_act(
11504 &self,
11505 ) -> Result<ArrayIterable<IterableArrayActAttrs<'a>, IterableActAttrs<'a>>, ErrorContext> {
11506 for attr in self.clone() {
11507 if let Ok(BasicAttrs::Act(val)) = attr {
11508 return Ok(ArrayIterable::new(val));
11509 }
11510 }
11511 Err(ErrorContext::new_missing(
11512 "BasicAttrs",
11513 "Act",
11514 self.orig_loc,
11515 self.buf.as_ptr() as usize,
11516 ))
11517 }
11518 pub fn get_police(&self) -> Result<IterablePoliceAttrs<'a>, ErrorContext> {
11519 let mut iter = self.clone();
11520 iter.pos = 0;
11521 for attr in iter {
11522 if let Ok(BasicAttrs::Police(val)) = attr {
11523 return Ok(val);
11524 }
11525 }
11526 Err(ErrorContext::new_missing(
11527 "BasicAttrs",
11528 "Police",
11529 self.orig_loc,
11530 self.buf.as_ptr() as usize,
11531 ))
11532 }
11533 pub fn get_pcnt(&self) -> Result<TcBasicPcnt, ErrorContext> {
11534 let mut iter = self.clone();
11535 iter.pos = 0;
11536 for attr in iter {
11537 if let Ok(BasicAttrs::Pcnt(val)) = attr {
11538 return Ok(val);
11539 }
11540 }
11541 Err(ErrorContext::new_missing(
11542 "BasicAttrs",
11543 "Pcnt",
11544 self.orig_loc,
11545 self.buf.as_ptr() as usize,
11546 ))
11547 }
11548 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
11549 let mut iter = self.clone();
11550 iter.pos = 0;
11551 for attr in iter {
11552 if let Ok(BasicAttrs::Pad(val)) = attr {
11553 return Ok(val);
11554 }
11555 }
11556 Err(ErrorContext::new_missing(
11557 "BasicAttrs",
11558 "Pad",
11559 self.orig_loc,
11560 self.buf.as_ptr() as usize,
11561 ))
11562 }
11563}
11564impl<'a> ActAttrs<'a> {
11565 pub fn new_array(buf: &[u8]) -> IterableArrayActAttrs<'_> {
11566 IterableArrayActAttrs::with_loc(buf, buf.as_ptr() as usize)
11567 }
11568}
11569#[derive(Clone, Copy, Default)]
11570pub struct IterableArrayActAttrs<'a> {
11571 buf: &'a [u8],
11572 pos: usize,
11573 orig_loc: usize,
11574}
11575impl<'a> IterableArrayActAttrs<'a> {
11576 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11577 Self {
11578 buf,
11579 pos: 0,
11580 orig_loc,
11581 }
11582 }
11583 pub fn get_buf(&self) -> &'a [u8] {
11584 self.buf
11585 }
11586}
11587impl<'a> Iterator for IterableArrayActAttrs<'a> {
11588 type Item = Result<IterableActAttrs<'a>, ErrorContext>;
11589 fn next(&mut self) -> Option<Self::Item> {
11590 if self.buf.len() == self.pos {
11591 return None;
11592 }
11593 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
11594 {
11595 return Some(Ok(IterableActAttrs::with_loc(next, self.orig_loc)));
11596 }
11597 }
11598 let pos = self.pos;
11599 self.pos = self.buf.len();
11600 Some(Err(ErrorContext::new(
11601 "ActAttrs",
11602 None,
11603 self.orig_loc,
11604 self.buf.as_ptr().wrapping_add(pos) as usize,
11605 )))
11606 }
11607}
11608impl BasicAttrs<'_> {
11609 pub fn new<'a>(buf: &'a [u8]) -> IterableBasicAttrs<'a> {
11610 IterableBasicAttrs::with_loc(buf, buf.as_ptr() as usize)
11611 }
11612 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11613 let res = match r#type {
11614 1u16 => "Classid",
11615 2u16 => "Ematches",
11616 3u16 => "Act",
11617 4u16 => "Police",
11618 5u16 => "Pcnt",
11619 6u16 => "Pad",
11620 _ => return None,
11621 };
11622 Some(res)
11623 }
11624}
11625#[derive(Clone, Copy, Default)]
11626pub struct IterableBasicAttrs<'a> {
11627 buf: &'a [u8],
11628 pos: usize,
11629 orig_loc: usize,
11630}
11631impl<'a> IterableBasicAttrs<'a> {
11632 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11633 Self {
11634 buf,
11635 pos: 0,
11636 orig_loc,
11637 }
11638 }
11639 pub fn get_buf(&self) -> &'a [u8] {
11640 self.buf
11641 }
11642}
11643impl<'a> Iterator for IterableBasicAttrs<'a> {
11644 type Item = Result<BasicAttrs<'a>, ErrorContext>;
11645 fn next(&mut self) -> Option<Self::Item> {
11646 let mut pos;
11647 let mut r#type;
11648 loop {
11649 pos = self.pos;
11650 r#type = None;
11651 if self.buf.len() == self.pos {
11652 return None;
11653 }
11654 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
11655 self.pos = self.buf.len();
11656 break;
11657 };
11658 r#type = Some(header.r#type);
11659 let res = match header.r#type {
11660 1u16 => BasicAttrs::Classid({
11661 let res = parse_u32(next);
11662 let Some(val) = res else { break };
11663 val
11664 }),
11665 2u16 => BasicAttrs::Ematches({
11666 let res = Some(IterableEmatchAttrs::with_loc(next, self.orig_loc));
11667 let Some(val) = res else { break };
11668 val
11669 }),
11670 3u16 => BasicAttrs::Act({
11671 let res = Some(IterableArrayActAttrs::with_loc(next, self.orig_loc));
11672 let Some(val) = res else { break };
11673 val
11674 }),
11675 4u16 => BasicAttrs::Police({
11676 let res = Some(IterablePoliceAttrs::with_loc(next, self.orig_loc));
11677 let Some(val) = res else { break };
11678 val
11679 }),
11680 5u16 => BasicAttrs::Pcnt({
11681 let res = Some(TcBasicPcnt::new_from_zeroed(next));
11682 let Some(val) = res else { break };
11683 val
11684 }),
11685 6u16 => BasicAttrs::Pad({
11686 let res = Some(next);
11687 let Some(val) = res else { break };
11688 val
11689 }),
11690 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
11691 n => continue,
11692 };
11693 return Some(Ok(res));
11694 }
11695 Some(Err(ErrorContext::new(
11696 "BasicAttrs",
11697 r#type.and_then(|t| BasicAttrs::attr_from_type(t)),
11698 self.orig_loc,
11699 self.buf.as_ptr().wrapping_add(pos) as usize,
11700 )))
11701 }
11702}
11703impl std::fmt::Debug for IterableArrayActAttrs<'_> {
11704 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11705 fmt.debug_list()
11706 .entries(self.clone().map(FlattenErrorContext))
11707 .finish()
11708 }
11709}
11710impl<'a> std::fmt::Debug for IterableBasicAttrs<'_> {
11711 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11712 let mut fmt = f.debug_struct("BasicAttrs");
11713 for attr in self.clone() {
11714 let attr = match attr {
11715 Ok(a) => a,
11716 Err(err) => {
11717 fmt.finish()?;
11718 f.write_str("Err(")?;
11719 err.fmt(f)?;
11720 return f.write_str(")");
11721 }
11722 };
11723 match attr {
11724 BasicAttrs::Classid(val) => fmt.field("Classid", &val),
11725 BasicAttrs::Ematches(val) => fmt.field("Ematches", &val),
11726 BasicAttrs::Act(val) => fmt.field("Act", &val),
11727 BasicAttrs::Police(val) => fmt.field("Police", &val),
11728 BasicAttrs::Pcnt(val) => fmt.field("Pcnt", &val),
11729 BasicAttrs::Pad(val) => fmt.field("Pad", &val),
11730 };
11731 }
11732 fmt.finish()
11733 }
11734}
11735impl IterableBasicAttrs<'_> {
11736 pub fn lookup_attr(
11737 &self,
11738 offset: usize,
11739 missing_type: Option<u16>,
11740 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11741 let mut stack = Vec::new();
11742 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11743 if missing_type.is_some() && cur == offset {
11744 stack.push(("BasicAttrs", offset));
11745 return (
11746 stack,
11747 missing_type.and_then(|t| BasicAttrs::attr_from_type(t)),
11748 );
11749 }
11750 if cur > offset || cur + self.buf.len() < offset {
11751 return (stack, None);
11752 }
11753 let mut attrs = self.clone();
11754 let mut last_off = cur + attrs.pos;
11755 let mut missing = None;
11756 while let Some(attr) = attrs.next() {
11757 let Ok(attr) = attr else { break };
11758 match attr {
11759 BasicAttrs::Classid(val) => {
11760 if last_off == offset {
11761 stack.push(("Classid", last_off));
11762 break;
11763 }
11764 }
11765 BasicAttrs::Ematches(val) => {
11766 (stack, missing) = val.lookup_attr(offset, missing_type);
11767 if !stack.is_empty() {
11768 break;
11769 }
11770 }
11771 BasicAttrs::Act(val) => {
11772 for entry in val {
11773 let Ok(attr) = entry else { break };
11774 (stack, missing) = attr.lookup_attr(offset, missing_type);
11775 if !stack.is_empty() {
11776 break;
11777 }
11778 }
11779 if !stack.is_empty() {
11780 stack.push(("Act", last_off));
11781 break;
11782 }
11783 }
11784 BasicAttrs::Police(val) => {
11785 (stack, missing) = val.lookup_attr(offset, missing_type);
11786 if !stack.is_empty() {
11787 break;
11788 }
11789 }
11790 BasicAttrs::Pcnt(val) => {
11791 if last_off == offset {
11792 stack.push(("Pcnt", last_off));
11793 break;
11794 }
11795 }
11796 BasicAttrs::Pad(val) => {
11797 if last_off == offset {
11798 stack.push(("Pad", last_off));
11799 break;
11800 }
11801 }
11802 _ => {}
11803 };
11804 last_off = cur + attrs.pos;
11805 }
11806 if !stack.is_empty() {
11807 stack.push(("BasicAttrs", cur));
11808 }
11809 (stack, missing)
11810 }
11811}
11812#[derive(Clone)]
11813pub enum BpfAttrs<'a> {
11814 Act(IterableArrayActAttrs<'a>),
11815 Police(IterablePoliceAttrs<'a>),
11816 Classid(u32),
11817 OpsLen(u16),
11818 Ops(&'a [u8]),
11819 Fd(u32),
11820 Name(&'a CStr),
11821 Flags(u32),
11822 FlagsGen(u32),
11823 Tag(&'a [u8]),
11824 Id(u32),
11825}
11826impl<'a> IterableBpfAttrs<'a> {
11827 pub fn get_act(
11828 &self,
11829 ) -> Result<ArrayIterable<IterableArrayActAttrs<'a>, IterableActAttrs<'a>>, ErrorContext> {
11830 for attr in self.clone() {
11831 if let Ok(BpfAttrs::Act(val)) = attr {
11832 return Ok(ArrayIterable::new(val));
11833 }
11834 }
11835 Err(ErrorContext::new_missing(
11836 "BpfAttrs",
11837 "Act",
11838 self.orig_loc,
11839 self.buf.as_ptr() as usize,
11840 ))
11841 }
11842 pub fn get_police(&self) -> Result<IterablePoliceAttrs<'a>, ErrorContext> {
11843 let mut iter = self.clone();
11844 iter.pos = 0;
11845 for attr in iter {
11846 if let Ok(BpfAttrs::Police(val)) = attr {
11847 return Ok(val);
11848 }
11849 }
11850 Err(ErrorContext::new_missing(
11851 "BpfAttrs",
11852 "Police",
11853 self.orig_loc,
11854 self.buf.as_ptr() as usize,
11855 ))
11856 }
11857 pub fn get_classid(&self) -> Result<u32, ErrorContext> {
11858 let mut iter = self.clone();
11859 iter.pos = 0;
11860 for attr in iter {
11861 if let Ok(BpfAttrs::Classid(val)) = attr {
11862 return Ok(val);
11863 }
11864 }
11865 Err(ErrorContext::new_missing(
11866 "BpfAttrs",
11867 "Classid",
11868 self.orig_loc,
11869 self.buf.as_ptr() as usize,
11870 ))
11871 }
11872 pub fn get_ops_len(&self) -> Result<u16, ErrorContext> {
11873 let mut iter = self.clone();
11874 iter.pos = 0;
11875 for attr in iter {
11876 if let Ok(BpfAttrs::OpsLen(val)) = attr {
11877 return Ok(val);
11878 }
11879 }
11880 Err(ErrorContext::new_missing(
11881 "BpfAttrs",
11882 "OpsLen",
11883 self.orig_loc,
11884 self.buf.as_ptr() as usize,
11885 ))
11886 }
11887 pub fn get_ops(&self) -> Result<&'a [u8], ErrorContext> {
11888 let mut iter = self.clone();
11889 iter.pos = 0;
11890 for attr in iter {
11891 if let Ok(BpfAttrs::Ops(val)) = attr {
11892 return Ok(val);
11893 }
11894 }
11895 Err(ErrorContext::new_missing(
11896 "BpfAttrs",
11897 "Ops",
11898 self.orig_loc,
11899 self.buf.as_ptr() as usize,
11900 ))
11901 }
11902 pub fn get_fd(&self) -> Result<u32, ErrorContext> {
11903 let mut iter = self.clone();
11904 iter.pos = 0;
11905 for attr in iter {
11906 if let Ok(BpfAttrs::Fd(val)) = attr {
11907 return Ok(val);
11908 }
11909 }
11910 Err(ErrorContext::new_missing(
11911 "BpfAttrs",
11912 "Fd",
11913 self.orig_loc,
11914 self.buf.as_ptr() as usize,
11915 ))
11916 }
11917 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
11918 let mut iter = self.clone();
11919 iter.pos = 0;
11920 for attr in iter {
11921 if let Ok(BpfAttrs::Name(val)) = attr {
11922 return Ok(val);
11923 }
11924 }
11925 Err(ErrorContext::new_missing(
11926 "BpfAttrs",
11927 "Name",
11928 self.orig_loc,
11929 self.buf.as_ptr() as usize,
11930 ))
11931 }
11932 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
11933 let mut iter = self.clone();
11934 iter.pos = 0;
11935 for attr in iter {
11936 if let Ok(BpfAttrs::Flags(val)) = attr {
11937 return Ok(val);
11938 }
11939 }
11940 Err(ErrorContext::new_missing(
11941 "BpfAttrs",
11942 "Flags",
11943 self.orig_loc,
11944 self.buf.as_ptr() as usize,
11945 ))
11946 }
11947 pub fn get_flags_gen(&self) -> Result<u32, ErrorContext> {
11948 let mut iter = self.clone();
11949 iter.pos = 0;
11950 for attr in iter {
11951 if let Ok(BpfAttrs::FlagsGen(val)) = attr {
11952 return Ok(val);
11953 }
11954 }
11955 Err(ErrorContext::new_missing(
11956 "BpfAttrs",
11957 "FlagsGen",
11958 self.orig_loc,
11959 self.buf.as_ptr() as usize,
11960 ))
11961 }
11962 pub fn get_tag(&self) -> Result<&'a [u8], ErrorContext> {
11963 let mut iter = self.clone();
11964 iter.pos = 0;
11965 for attr in iter {
11966 if let Ok(BpfAttrs::Tag(val)) = attr {
11967 return Ok(val);
11968 }
11969 }
11970 Err(ErrorContext::new_missing(
11971 "BpfAttrs",
11972 "Tag",
11973 self.orig_loc,
11974 self.buf.as_ptr() as usize,
11975 ))
11976 }
11977 pub fn get_id(&self) -> Result<u32, ErrorContext> {
11978 let mut iter = self.clone();
11979 iter.pos = 0;
11980 for attr in iter {
11981 if let Ok(BpfAttrs::Id(val)) = attr {
11982 return Ok(val);
11983 }
11984 }
11985 Err(ErrorContext::new_missing(
11986 "BpfAttrs",
11987 "Id",
11988 self.orig_loc,
11989 self.buf.as_ptr() as usize,
11990 ))
11991 }
11992}
11993impl BpfAttrs<'_> {
11994 pub fn new<'a>(buf: &'a [u8]) -> IterableBpfAttrs<'a> {
11995 IterableBpfAttrs::with_loc(buf, buf.as_ptr() as usize)
11996 }
11997 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11998 let res = match r#type {
11999 1u16 => "Act",
12000 2u16 => "Police",
12001 3u16 => "Classid",
12002 4u16 => "OpsLen",
12003 5u16 => "Ops",
12004 6u16 => "Fd",
12005 7u16 => "Name",
12006 8u16 => "Flags",
12007 9u16 => "FlagsGen",
12008 10u16 => "Tag",
12009 11u16 => "Id",
12010 _ => return None,
12011 };
12012 Some(res)
12013 }
12014}
12015#[derive(Clone, Copy, Default)]
12016pub struct IterableBpfAttrs<'a> {
12017 buf: &'a [u8],
12018 pos: usize,
12019 orig_loc: usize,
12020}
12021impl<'a> IterableBpfAttrs<'a> {
12022 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
12023 Self {
12024 buf,
12025 pos: 0,
12026 orig_loc,
12027 }
12028 }
12029 pub fn get_buf(&self) -> &'a [u8] {
12030 self.buf
12031 }
12032}
12033impl<'a> Iterator for IterableBpfAttrs<'a> {
12034 type Item = Result<BpfAttrs<'a>, ErrorContext>;
12035 fn next(&mut self) -> Option<Self::Item> {
12036 let mut pos;
12037 let mut r#type;
12038 loop {
12039 pos = self.pos;
12040 r#type = None;
12041 if self.buf.len() == self.pos {
12042 return None;
12043 }
12044 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
12045 self.pos = self.buf.len();
12046 break;
12047 };
12048 r#type = Some(header.r#type);
12049 let res = match header.r#type {
12050 1u16 => BpfAttrs::Act({
12051 let res = Some(IterableArrayActAttrs::with_loc(next, self.orig_loc));
12052 let Some(val) = res else { break };
12053 val
12054 }),
12055 2u16 => BpfAttrs::Police({
12056 let res = Some(IterablePoliceAttrs::with_loc(next, self.orig_loc));
12057 let Some(val) = res else { break };
12058 val
12059 }),
12060 3u16 => BpfAttrs::Classid({
12061 let res = parse_u32(next);
12062 let Some(val) = res else { break };
12063 val
12064 }),
12065 4u16 => BpfAttrs::OpsLen({
12066 let res = parse_u16(next);
12067 let Some(val) = res else { break };
12068 val
12069 }),
12070 5u16 => BpfAttrs::Ops({
12071 let res = Some(next);
12072 let Some(val) = res else { break };
12073 val
12074 }),
12075 6u16 => BpfAttrs::Fd({
12076 let res = parse_u32(next);
12077 let Some(val) = res else { break };
12078 val
12079 }),
12080 7u16 => BpfAttrs::Name({
12081 let res = CStr::from_bytes_with_nul(next).ok();
12082 let Some(val) = res else { break };
12083 val
12084 }),
12085 8u16 => BpfAttrs::Flags({
12086 let res = parse_u32(next);
12087 let Some(val) = res else { break };
12088 val
12089 }),
12090 9u16 => BpfAttrs::FlagsGen({
12091 let res = parse_u32(next);
12092 let Some(val) = res else { break };
12093 val
12094 }),
12095 10u16 => BpfAttrs::Tag({
12096 let res = Some(next);
12097 let Some(val) = res else { break };
12098 val
12099 }),
12100 11u16 => BpfAttrs::Id({
12101 let res = parse_u32(next);
12102 let Some(val) = res else { break };
12103 val
12104 }),
12105 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
12106 n => continue,
12107 };
12108 return Some(Ok(res));
12109 }
12110 Some(Err(ErrorContext::new(
12111 "BpfAttrs",
12112 r#type.and_then(|t| BpfAttrs::attr_from_type(t)),
12113 self.orig_loc,
12114 self.buf.as_ptr().wrapping_add(pos) as usize,
12115 )))
12116 }
12117}
12118impl<'a> std::fmt::Debug for IterableBpfAttrs<'_> {
12119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12120 let mut fmt = f.debug_struct("BpfAttrs");
12121 for attr in self.clone() {
12122 let attr = match attr {
12123 Ok(a) => a,
12124 Err(err) => {
12125 fmt.finish()?;
12126 f.write_str("Err(")?;
12127 err.fmt(f)?;
12128 return f.write_str(")");
12129 }
12130 };
12131 match attr {
12132 BpfAttrs::Act(val) => fmt.field("Act", &val),
12133 BpfAttrs::Police(val) => fmt.field("Police", &val),
12134 BpfAttrs::Classid(val) => fmt.field("Classid", &val),
12135 BpfAttrs::OpsLen(val) => fmt.field("OpsLen", &val),
12136 BpfAttrs::Ops(val) => fmt.field("Ops", &val),
12137 BpfAttrs::Fd(val) => fmt.field("Fd", &val),
12138 BpfAttrs::Name(val) => fmt.field("Name", &val),
12139 BpfAttrs::Flags(val) => fmt.field("Flags", &val),
12140 BpfAttrs::FlagsGen(val) => fmt.field("FlagsGen", &val),
12141 BpfAttrs::Tag(val) => fmt.field("Tag", &val),
12142 BpfAttrs::Id(val) => fmt.field("Id", &val),
12143 };
12144 }
12145 fmt.finish()
12146 }
12147}
12148impl IterableBpfAttrs<'_> {
12149 pub fn lookup_attr(
12150 &self,
12151 offset: usize,
12152 missing_type: Option<u16>,
12153 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
12154 let mut stack = Vec::new();
12155 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
12156 if missing_type.is_some() && cur == offset {
12157 stack.push(("BpfAttrs", offset));
12158 return (
12159 stack,
12160 missing_type.and_then(|t| BpfAttrs::attr_from_type(t)),
12161 );
12162 }
12163 if cur > offset || cur + self.buf.len() < offset {
12164 return (stack, None);
12165 }
12166 let mut attrs = self.clone();
12167 let mut last_off = cur + attrs.pos;
12168 let mut missing = None;
12169 while let Some(attr) = attrs.next() {
12170 let Ok(attr) = attr else { break };
12171 match attr {
12172 BpfAttrs::Act(val) => {
12173 for entry in val {
12174 let Ok(attr) = entry else { break };
12175 (stack, missing) = attr.lookup_attr(offset, missing_type);
12176 if !stack.is_empty() {
12177 break;
12178 }
12179 }
12180 if !stack.is_empty() {
12181 stack.push(("Act", last_off));
12182 break;
12183 }
12184 }
12185 BpfAttrs::Police(val) => {
12186 (stack, missing) = val.lookup_attr(offset, missing_type);
12187 if !stack.is_empty() {
12188 break;
12189 }
12190 }
12191 BpfAttrs::Classid(val) => {
12192 if last_off == offset {
12193 stack.push(("Classid", last_off));
12194 break;
12195 }
12196 }
12197 BpfAttrs::OpsLen(val) => {
12198 if last_off == offset {
12199 stack.push(("OpsLen", last_off));
12200 break;
12201 }
12202 }
12203 BpfAttrs::Ops(val) => {
12204 if last_off == offset {
12205 stack.push(("Ops", last_off));
12206 break;
12207 }
12208 }
12209 BpfAttrs::Fd(val) => {
12210 if last_off == offset {
12211 stack.push(("Fd", last_off));
12212 break;
12213 }
12214 }
12215 BpfAttrs::Name(val) => {
12216 if last_off == offset {
12217 stack.push(("Name", last_off));
12218 break;
12219 }
12220 }
12221 BpfAttrs::Flags(val) => {
12222 if last_off == offset {
12223 stack.push(("Flags", last_off));
12224 break;
12225 }
12226 }
12227 BpfAttrs::FlagsGen(val) => {
12228 if last_off == offset {
12229 stack.push(("FlagsGen", last_off));
12230 break;
12231 }
12232 }
12233 BpfAttrs::Tag(val) => {
12234 if last_off == offset {
12235 stack.push(("Tag", last_off));
12236 break;
12237 }
12238 }
12239 BpfAttrs::Id(val) => {
12240 if last_off == offset {
12241 stack.push(("Id", last_off));
12242 break;
12243 }
12244 }
12245 _ => {}
12246 };
12247 last_off = cur + attrs.pos;
12248 }
12249 if !stack.is_empty() {
12250 stack.push(("BpfAttrs", cur));
12251 }
12252 (stack, missing)
12253 }
12254}
12255#[derive(Clone)]
12256pub enum CakeAttrs<'a> {
12257 Pad(&'a [u8]),
12258 BaseRate64(u64),
12259 DiffservMode(u32),
12260 Atm(u32),
12261 FlowMode(u32),
12262 Overhead(u32),
12263 Rtt(u32),
12264 Target(u32),
12265 Autorate(u32),
12266 Memory(u32),
12267 Nat(u32),
12268 Raw(u32),
12269 Wash(u32),
12270 Mpu(u32),
12271 Ingress(u32),
12272 AckFilter(u32),
12273 SplitGso(u32),
12274 Fwmark(u32),
12275}
12276impl<'a> IterableCakeAttrs<'a> {
12277 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
12278 let mut iter = self.clone();
12279 iter.pos = 0;
12280 for attr in iter {
12281 if let Ok(CakeAttrs::Pad(val)) = attr {
12282 return Ok(val);
12283 }
12284 }
12285 Err(ErrorContext::new_missing(
12286 "CakeAttrs",
12287 "Pad",
12288 self.orig_loc,
12289 self.buf.as_ptr() as usize,
12290 ))
12291 }
12292 pub fn get_base_rate64(&self) -> Result<u64, ErrorContext> {
12293 let mut iter = self.clone();
12294 iter.pos = 0;
12295 for attr in iter {
12296 if let Ok(CakeAttrs::BaseRate64(val)) = attr {
12297 return Ok(val);
12298 }
12299 }
12300 Err(ErrorContext::new_missing(
12301 "CakeAttrs",
12302 "BaseRate64",
12303 self.orig_loc,
12304 self.buf.as_ptr() as usize,
12305 ))
12306 }
12307 pub fn get_diffserv_mode(&self) -> Result<u32, ErrorContext> {
12308 let mut iter = self.clone();
12309 iter.pos = 0;
12310 for attr in iter {
12311 if let Ok(CakeAttrs::DiffservMode(val)) = attr {
12312 return Ok(val);
12313 }
12314 }
12315 Err(ErrorContext::new_missing(
12316 "CakeAttrs",
12317 "DiffservMode",
12318 self.orig_loc,
12319 self.buf.as_ptr() as usize,
12320 ))
12321 }
12322 pub fn get_atm(&self) -> Result<u32, ErrorContext> {
12323 let mut iter = self.clone();
12324 iter.pos = 0;
12325 for attr in iter {
12326 if let Ok(CakeAttrs::Atm(val)) = attr {
12327 return Ok(val);
12328 }
12329 }
12330 Err(ErrorContext::new_missing(
12331 "CakeAttrs",
12332 "Atm",
12333 self.orig_loc,
12334 self.buf.as_ptr() as usize,
12335 ))
12336 }
12337 pub fn get_flow_mode(&self) -> Result<u32, ErrorContext> {
12338 let mut iter = self.clone();
12339 iter.pos = 0;
12340 for attr in iter {
12341 if let Ok(CakeAttrs::FlowMode(val)) = attr {
12342 return Ok(val);
12343 }
12344 }
12345 Err(ErrorContext::new_missing(
12346 "CakeAttrs",
12347 "FlowMode",
12348 self.orig_loc,
12349 self.buf.as_ptr() as usize,
12350 ))
12351 }
12352 pub fn get_overhead(&self) -> Result<u32, ErrorContext> {
12353 let mut iter = self.clone();
12354 iter.pos = 0;
12355 for attr in iter {
12356 if let Ok(CakeAttrs::Overhead(val)) = attr {
12357 return Ok(val);
12358 }
12359 }
12360 Err(ErrorContext::new_missing(
12361 "CakeAttrs",
12362 "Overhead",
12363 self.orig_loc,
12364 self.buf.as_ptr() as usize,
12365 ))
12366 }
12367 pub fn get_rtt(&self) -> Result<u32, ErrorContext> {
12368 let mut iter = self.clone();
12369 iter.pos = 0;
12370 for attr in iter {
12371 if let Ok(CakeAttrs::Rtt(val)) = attr {
12372 return Ok(val);
12373 }
12374 }
12375 Err(ErrorContext::new_missing(
12376 "CakeAttrs",
12377 "Rtt",
12378 self.orig_loc,
12379 self.buf.as_ptr() as usize,
12380 ))
12381 }
12382 pub fn get_target(&self) -> Result<u32, ErrorContext> {
12383 let mut iter = self.clone();
12384 iter.pos = 0;
12385 for attr in iter {
12386 if let Ok(CakeAttrs::Target(val)) = attr {
12387 return Ok(val);
12388 }
12389 }
12390 Err(ErrorContext::new_missing(
12391 "CakeAttrs",
12392 "Target",
12393 self.orig_loc,
12394 self.buf.as_ptr() as usize,
12395 ))
12396 }
12397 pub fn get_autorate(&self) -> Result<u32, ErrorContext> {
12398 let mut iter = self.clone();
12399 iter.pos = 0;
12400 for attr in iter {
12401 if let Ok(CakeAttrs::Autorate(val)) = attr {
12402 return Ok(val);
12403 }
12404 }
12405 Err(ErrorContext::new_missing(
12406 "CakeAttrs",
12407 "Autorate",
12408 self.orig_loc,
12409 self.buf.as_ptr() as usize,
12410 ))
12411 }
12412 pub fn get_memory(&self) -> Result<u32, ErrorContext> {
12413 let mut iter = self.clone();
12414 iter.pos = 0;
12415 for attr in iter {
12416 if let Ok(CakeAttrs::Memory(val)) = attr {
12417 return Ok(val);
12418 }
12419 }
12420 Err(ErrorContext::new_missing(
12421 "CakeAttrs",
12422 "Memory",
12423 self.orig_loc,
12424 self.buf.as_ptr() as usize,
12425 ))
12426 }
12427 pub fn get_nat(&self) -> Result<u32, ErrorContext> {
12428 let mut iter = self.clone();
12429 iter.pos = 0;
12430 for attr in iter {
12431 if let Ok(CakeAttrs::Nat(val)) = attr {
12432 return Ok(val);
12433 }
12434 }
12435 Err(ErrorContext::new_missing(
12436 "CakeAttrs",
12437 "Nat",
12438 self.orig_loc,
12439 self.buf.as_ptr() as usize,
12440 ))
12441 }
12442 pub fn get_raw(&self) -> Result<u32, ErrorContext> {
12443 let mut iter = self.clone();
12444 iter.pos = 0;
12445 for attr in iter {
12446 if let Ok(CakeAttrs::Raw(val)) = attr {
12447 return Ok(val);
12448 }
12449 }
12450 Err(ErrorContext::new_missing(
12451 "CakeAttrs",
12452 "Raw",
12453 self.orig_loc,
12454 self.buf.as_ptr() as usize,
12455 ))
12456 }
12457 pub fn get_wash(&self) -> Result<u32, ErrorContext> {
12458 let mut iter = self.clone();
12459 iter.pos = 0;
12460 for attr in iter {
12461 if let Ok(CakeAttrs::Wash(val)) = attr {
12462 return Ok(val);
12463 }
12464 }
12465 Err(ErrorContext::new_missing(
12466 "CakeAttrs",
12467 "Wash",
12468 self.orig_loc,
12469 self.buf.as_ptr() as usize,
12470 ))
12471 }
12472 pub fn get_mpu(&self) -> Result<u32, ErrorContext> {
12473 let mut iter = self.clone();
12474 iter.pos = 0;
12475 for attr in iter {
12476 if let Ok(CakeAttrs::Mpu(val)) = attr {
12477 return Ok(val);
12478 }
12479 }
12480 Err(ErrorContext::new_missing(
12481 "CakeAttrs",
12482 "Mpu",
12483 self.orig_loc,
12484 self.buf.as_ptr() as usize,
12485 ))
12486 }
12487 pub fn get_ingress(&self) -> Result<u32, ErrorContext> {
12488 let mut iter = self.clone();
12489 iter.pos = 0;
12490 for attr in iter {
12491 if let Ok(CakeAttrs::Ingress(val)) = attr {
12492 return Ok(val);
12493 }
12494 }
12495 Err(ErrorContext::new_missing(
12496 "CakeAttrs",
12497 "Ingress",
12498 self.orig_loc,
12499 self.buf.as_ptr() as usize,
12500 ))
12501 }
12502 pub fn get_ack_filter(&self) -> Result<u32, ErrorContext> {
12503 let mut iter = self.clone();
12504 iter.pos = 0;
12505 for attr in iter {
12506 if let Ok(CakeAttrs::AckFilter(val)) = attr {
12507 return Ok(val);
12508 }
12509 }
12510 Err(ErrorContext::new_missing(
12511 "CakeAttrs",
12512 "AckFilter",
12513 self.orig_loc,
12514 self.buf.as_ptr() as usize,
12515 ))
12516 }
12517 pub fn get_split_gso(&self) -> Result<u32, ErrorContext> {
12518 let mut iter = self.clone();
12519 iter.pos = 0;
12520 for attr in iter {
12521 if let Ok(CakeAttrs::SplitGso(val)) = attr {
12522 return Ok(val);
12523 }
12524 }
12525 Err(ErrorContext::new_missing(
12526 "CakeAttrs",
12527 "SplitGso",
12528 self.orig_loc,
12529 self.buf.as_ptr() as usize,
12530 ))
12531 }
12532 pub fn get_fwmark(&self) -> Result<u32, ErrorContext> {
12533 let mut iter = self.clone();
12534 iter.pos = 0;
12535 for attr in iter {
12536 if let Ok(CakeAttrs::Fwmark(val)) = attr {
12537 return Ok(val);
12538 }
12539 }
12540 Err(ErrorContext::new_missing(
12541 "CakeAttrs",
12542 "Fwmark",
12543 self.orig_loc,
12544 self.buf.as_ptr() as usize,
12545 ))
12546 }
12547}
12548impl CakeAttrs<'_> {
12549 pub fn new<'a>(buf: &'a [u8]) -> IterableCakeAttrs<'a> {
12550 IterableCakeAttrs::with_loc(buf, buf.as_ptr() as usize)
12551 }
12552 fn attr_from_type(r#type: u16) -> Option<&'static str> {
12553 let res = match r#type {
12554 1u16 => "Pad",
12555 2u16 => "BaseRate64",
12556 3u16 => "DiffservMode",
12557 4u16 => "Atm",
12558 5u16 => "FlowMode",
12559 6u16 => "Overhead",
12560 7u16 => "Rtt",
12561 8u16 => "Target",
12562 9u16 => "Autorate",
12563 10u16 => "Memory",
12564 11u16 => "Nat",
12565 12u16 => "Raw",
12566 13u16 => "Wash",
12567 14u16 => "Mpu",
12568 15u16 => "Ingress",
12569 16u16 => "AckFilter",
12570 17u16 => "SplitGso",
12571 18u16 => "Fwmark",
12572 _ => return None,
12573 };
12574 Some(res)
12575 }
12576}
12577#[derive(Clone, Copy, Default)]
12578pub struct IterableCakeAttrs<'a> {
12579 buf: &'a [u8],
12580 pos: usize,
12581 orig_loc: usize,
12582}
12583impl<'a> IterableCakeAttrs<'a> {
12584 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
12585 Self {
12586 buf,
12587 pos: 0,
12588 orig_loc,
12589 }
12590 }
12591 pub fn get_buf(&self) -> &'a [u8] {
12592 self.buf
12593 }
12594}
12595impl<'a> Iterator for IterableCakeAttrs<'a> {
12596 type Item = Result<CakeAttrs<'a>, ErrorContext>;
12597 fn next(&mut self) -> Option<Self::Item> {
12598 let mut pos;
12599 let mut r#type;
12600 loop {
12601 pos = self.pos;
12602 r#type = None;
12603 if self.buf.len() == self.pos {
12604 return None;
12605 }
12606 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
12607 self.pos = self.buf.len();
12608 break;
12609 };
12610 r#type = Some(header.r#type);
12611 let res = match header.r#type {
12612 1u16 => CakeAttrs::Pad({
12613 let res = Some(next);
12614 let Some(val) = res else { break };
12615 val
12616 }),
12617 2u16 => CakeAttrs::BaseRate64({
12618 let res = parse_u64(next);
12619 let Some(val) = res else { break };
12620 val
12621 }),
12622 3u16 => CakeAttrs::DiffservMode({
12623 let res = parse_u32(next);
12624 let Some(val) = res else { break };
12625 val
12626 }),
12627 4u16 => CakeAttrs::Atm({
12628 let res = parse_u32(next);
12629 let Some(val) = res else { break };
12630 val
12631 }),
12632 5u16 => CakeAttrs::FlowMode({
12633 let res = parse_u32(next);
12634 let Some(val) = res else { break };
12635 val
12636 }),
12637 6u16 => CakeAttrs::Overhead({
12638 let res = parse_u32(next);
12639 let Some(val) = res else { break };
12640 val
12641 }),
12642 7u16 => CakeAttrs::Rtt({
12643 let res = parse_u32(next);
12644 let Some(val) = res else { break };
12645 val
12646 }),
12647 8u16 => CakeAttrs::Target({
12648 let res = parse_u32(next);
12649 let Some(val) = res else { break };
12650 val
12651 }),
12652 9u16 => CakeAttrs::Autorate({
12653 let res = parse_u32(next);
12654 let Some(val) = res else { break };
12655 val
12656 }),
12657 10u16 => CakeAttrs::Memory({
12658 let res = parse_u32(next);
12659 let Some(val) = res else { break };
12660 val
12661 }),
12662 11u16 => CakeAttrs::Nat({
12663 let res = parse_u32(next);
12664 let Some(val) = res else { break };
12665 val
12666 }),
12667 12u16 => CakeAttrs::Raw({
12668 let res = parse_u32(next);
12669 let Some(val) = res else { break };
12670 val
12671 }),
12672 13u16 => CakeAttrs::Wash({
12673 let res = parse_u32(next);
12674 let Some(val) = res else { break };
12675 val
12676 }),
12677 14u16 => CakeAttrs::Mpu({
12678 let res = parse_u32(next);
12679 let Some(val) = res else { break };
12680 val
12681 }),
12682 15u16 => CakeAttrs::Ingress({
12683 let res = parse_u32(next);
12684 let Some(val) = res else { break };
12685 val
12686 }),
12687 16u16 => CakeAttrs::AckFilter({
12688 let res = parse_u32(next);
12689 let Some(val) = res else { break };
12690 val
12691 }),
12692 17u16 => CakeAttrs::SplitGso({
12693 let res = parse_u32(next);
12694 let Some(val) = res else { break };
12695 val
12696 }),
12697 18u16 => CakeAttrs::Fwmark({
12698 let res = parse_u32(next);
12699 let Some(val) = res else { break };
12700 val
12701 }),
12702 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
12703 n => continue,
12704 };
12705 return Some(Ok(res));
12706 }
12707 Some(Err(ErrorContext::new(
12708 "CakeAttrs",
12709 r#type.and_then(|t| CakeAttrs::attr_from_type(t)),
12710 self.orig_loc,
12711 self.buf.as_ptr().wrapping_add(pos) as usize,
12712 )))
12713 }
12714}
12715impl<'a> std::fmt::Debug for IterableCakeAttrs<'_> {
12716 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12717 let mut fmt = f.debug_struct("CakeAttrs");
12718 for attr in self.clone() {
12719 let attr = match attr {
12720 Ok(a) => a,
12721 Err(err) => {
12722 fmt.finish()?;
12723 f.write_str("Err(")?;
12724 err.fmt(f)?;
12725 return f.write_str(")");
12726 }
12727 };
12728 match attr {
12729 CakeAttrs::Pad(val) => fmt.field("Pad", &val),
12730 CakeAttrs::BaseRate64(val) => fmt.field("BaseRate64", &val),
12731 CakeAttrs::DiffservMode(val) => fmt.field("DiffservMode", &val),
12732 CakeAttrs::Atm(val) => fmt.field("Atm", &val),
12733 CakeAttrs::FlowMode(val) => fmt.field("FlowMode", &val),
12734 CakeAttrs::Overhead(val) => fmt.field("Overhead", &val),
12735 CakeAttrs::Rtt(val) => fmt.field("Rtt", &val),
12736 CakeAttrs::Target(val) => fmt.field("Target", &val),
12737 CakeAttrs::Autorate(val) => fmt.field("Autorate", &val),
12738 CakeAttrs::Memory(val) => fmt.field("Memory", &val),
12739 CakeAttrs::Nat(val) => fmt.field("Nat", &val),
12740 CakeAttrs::Raw(val) => fmt.field("Raw", &val),
12741 CakeAttrs::Wash(val) => fmt.field("Wash", &val),
12742 CakeAttrs::Mpu(val) => fmt.field("Mpu", &val),
12743 CakeAttrs::Ingress(val) => fmt.field("Ingress", &val),
12744 CakeAttrs::AckFilter(val) => fmt.field("AckFilter", &val),
12745 CakeAttrs::SplitGso(val) => fmt.field("SplitGso", &val),
12746 CakeAttrs::Fwmark(val) => fmt.field("Fwmark", &val),
12747 };
12748 }
12749 fmt.finish()
12750 }
12751}
12752impl IterableCakeAttrs<'_> {
12753 pub fn lookup_attr(
12754 &self,
12755 offset: usize,
12756 missing_type: Option<u16>,
12757 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
12758 let mut stack = Vec::new();
12759 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
12760 if missing_type.is_some() && cur == offset {
12761 stack.push(("CakeAttrs", offset));
12762 return (
12763 stack,
12764 missing_type.and_then(|t| CakeAttrs::attr_from_type(t)),
12765 );
12766 }
12767 if cur > offset || cur + self.buf.len() < offset {
12768 return (stack, None);
12769 }
12770 let mut attrs = self.clone();
12771 let mut last_off = cur + attrs.pos;
12772 while let Some(attr) = attrs.next() {
12773 let Ok(attr) = attr else { break };
12774 match attr {
12775 CakeAttrs::Pad(val) => {
12776 if last_off == offset {
12777 stack.push(("Pad", last_off));
12778 break;
12779 }
12780 }
12781 CakeAttrs::BaseRate64(val) => {
12782 if last_off == offset {
12783 stack.push(("BaseRate64", last_off));
12784 break;
12785 }
12786 }
12787 CakeAttrs::DiffservMode(val) => {
12788 if last_off == offset {
12789 stack.push(("DiffservMode", last_off));
12790 break;
12791 }
12792 }
12793 CakeAttrs::Atm(val) => {
12794 if last_off == offset {
12795 stack.push(("Atm", last_off));
12796 break;
12797 }
12798 }
12799 CakeAttrs::FlowMode(val) => {
12800 if last_off == offset {
12801 stack.push(("FlowMode", last_off));
12802 break;
12803 }
12804 }
12805 CakeAttrs::Overhead(val) => {
12806 if last_off == offset {
12807 stack.push(("Overhead", last_off));
12808 break;
12809 }
12810 }
12811 CakeAttrs::Rtt(val) => {
12812 if last_off == offset {
12813 stack.push(("Rtt", last_off));
12814 break;
12815 }
12816 }
12817 CakeAttrs::Target(val) => {
12818 if last_off == offset {
12819 stack.push(("Target", last_off));
12820 break;
12821 }
12822 }
12823 CakeAttrs::Autorate(val) => {
12824 if last_off == offset {
12825 stack.push(("Autorate", last_off));
12826 break;
12827 }
12828 }
12829 CakeAttrs::Memory(val) => {
12830 if last_off == offset {
12831 stack.push(("Memory", last_off));
12832 break;
12833 }
12834 }
12835 CakeAttrs::Nat(val) => {
12836 if last_off == offset {
12837 stack.push(("Nat", last_off));
12838 break;
12839 }
12840 }
12841 CakeAttrs::Raw(val) => {
12842 if last_off == offset {
12843 stack.push(("Raw", last_off));
12844 break;
12845 }
12846 }
12847 CakeAttrs::Wash(val) => {
12848 if last_off == offset {
12849 stack.push(("Wash", last_off));
12850 break;
12851 }
12852 }
12853 CakeAttrs::Mpu(val) => {
12854 if last_off == offset {
12855 stack.push(("Mpu", last_off));
12856 break;
12857 }
12858 }
12859 CakeAttrs::Ingress(val) => {
12860 if last_off == offset {
12861 stack.push(("Ingress", last_off));
12862 break;
12863 }
12864 }
12865 CakeAttrs::AckFilter(val) => {
12866 if last_off == offset {
12867 stack.push(("AckFilter", last_off));
12868 break;
12869 }
12870 }
12871 CakeAttrs::SplitGso(val) => {
12872 if last_off == offset {
12873 stack.push(("SplitGso", last_off));
12874 break;
12875 }
12876 }
12877 CakeAttrs::Fwmark(val) => {
12878 if last_off == offset {
12879 stack.push(("Fwmark", last_off));
12880 break;
12881 }
12882 }
12883 _ => {}
12884 };
12885 last_off = cur + attrs.pos;
12886 }
12887 if !stack.is_empty() {
12888 stack.push(("CakeAttrs", cur));
12889 }
12890 (stack, None)
12891 }
12892}
12893#[derive(Clone)]
12894pub enum CakeStatsAttrs<'a> {
12895 Pad(&'a [u8]),
12896 CapacityEstimate64(u64),
12897 MemoryLimit(u32),
12898 MemoryUsed(u32),
12899 AvgNetoff(u32),
12900 MinNetlen(u32),
12901 MaxNetlen(u32),
12902 MinAdjlen(u32),
12903 MaxAdjlen(u32),
12904 TinStats(IterableArrayCakeTinStatsAttrs<'a>),
12905 Deficit(i32),
12906 CobaltCount(u32),
12907 Dropping(u32),
12908 DropNextUs(i32),
12909 PDrop(u32),
12910 BlueTimerUs(i32),
12911 ActiveQueues(u32),
12912}
12913impl<'a> IterableCakeStatsAttrs<'a> {
12914 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
12915 let mut iter = self.clone();
12916 iter.pos = 0;
12917 for attr in iter {
12918 if let Ok(CakeStatsAttrs::Pad(val)) = attr {
12919 return Ok(val);
12920 }
12921 }
12922 Err(ErrorContext::new_missing(
12923 "CakeStatsAttrs",
12924 "Pad",
12925 self.orig_loc,
12926 self.buf.as_ptr() as usize,
12927 ))
12928 }
12929 pub fn get_capacity_estimate64(&self) -> Result<u64, ErrorContext> {
12930 let mut iter = self.clone();
12931 iter.pos = 0;
12932 for attr in iter {
12933 if let Ok(CakeStatsAttrs::CapacityEstimate64(val)) = attr {
12934 return Ok(val);
12935 }
12936 }
12937 Err(ErrorContext::new_missing(
12938 "CakeStatsAttrs",
12939 "CapacityEstimate64",
12940 self.orig_loc,
12941 self.buf.as_ptr() as usize,
12942 ))
12943 }
12944 pub fn get_memory_limit(&self) -> Result<u32, ErrorContext> {
12945 let mut iter = self.clone();
12946 iter.pos = 0;
12947 for attr in iter {
12948 if let Ok(CakeStatsAttrs::MemoryLimit(val)) = attr {
12949 return Ok(val);
12950 }
12951 }
12952 Err(ErrorContext::new_missing(
12953 "CakeStatsAttrs",
12954 "MemoryLimit",
12955 self.orig_loc,
12956 self.buf.as_ptr() as usize,
12957 ))
12958 }
12959 pub fn get_memory_used(&self) -> Result<u32, ErrorContext> {
12960 let mut iter = self.clone();
12961 iter.pos = 0;
12962 for attr in iter {
12963 if let Ok(CakeStatsAttrs::MemoryUsed(val)) = attr {
12964 return Ok(val);
12965 }
12966 }
12967 Err(ErrorContext::new_missing(
12968 "CakeStatsAttrs",
12969 "MemoryUsed",
12970 self.orig_loc,
12971 self.buf.as_ptr() as usize,
12972 ))
12973 }
12974 pub fn get_avg_netoff(&self) -> Result<u32, ErrorContext> {
12975 let mut iter = self.clone();
12976 iter.pos = 0;
12977 for attr in iter {
12978 if let Ok(CakeStatsAttrs::AvgNetoff(val)) = attr {
12979 return Ok(val);
12980 }
12981 }
12982 Err(ErrorContext::new_missing(
12983 "CakeStatsAttrs",
12984 "AvgNetoff",
12985 self.orig_loc,
12986 self.buf.as_ptr() as usize,
12987 ))
12988 }
12989 pub fn get_min_netlen(&self) -> Result<u32, ErrorContext> {
12990 let mut iter = self.clone();
12991 iter.pos = 0;
12992 for attr in iter {
12993 if let Ok(CakeStatsAttrs::MinNetlen(val)) = attr {
12994 return Ok(val);
12995 }
12996 }
12997 Err(ErrorContext::new_missing(
12998 "CakeStatsAttrs",
12999 "MinNetlen",
13000 self.orig_loc,
13001 self.buf.as_ptr() as usize,
13002 ))
13003 }
13004 pub fn get_max_netlen(&self) -> Result<u32, ErrorContext> {
13005 let mut iter = self.clone();
13006 iter.pos = 0;
13007 for attr in iter {
13008 if let Ok(CakeStatsAttrs::MaxNetlen(val)) = attr {
13009 return Ok(val);
13010 }
13011 }
13012 Err(ErrorContext::new_missing(
13013 "CakeStatsAttrs",
13014 "MaxNetlen",
13015 self.orig_loc,
13016 self.buf.as_ptr() as usize,
13017 ))
13018 }
13019 pub fn get_min_adjlen(&self) -> Result<u32, ErrorContext> {
13020 let mut iter = self.clone();
13021 iter.pos = 0;
13022 for attr in iter {
13023 if let Ok(CakeStatsAttrs::MinAdjlen(val)) = attr {
13024 return Ok(val);
13025 }
13026 }
13027 Err(ErrorContext::new_missing(
13028 "CakeStatsAttrs",
13029 "MinAdjlen",
13030 self.orig_loc,
13031 self.buf.as_ptr() as usize,
13032 ))
13033 }
13034 pub fn get_max_adjlen(&self) -> Result<u32, ErrorContext> {
13035 let mut iter = self.clone();
13036 iter.pos = 0;
13037 for attr in iter {
13038 if let Ok(CakeStatsAttrs::MaxAdjlen(val)) = attr {
13039 return Ok(val);
13040 }
13041 }
13042 Err(ErrorContext::new_missing(
13043 "CakeStatsAttrs",
13044 "MaxAdjlen",
13045 self.orig_loc,
13046 self.buf.as_ptr() as usize,
13047 ))
13048 }
13049 pub fn get_tin_stats(
13050 &self,
13051 ) -> Result<
13052 ArrayIterable<IterableArrayCakeTinStatsAttrs<'a>, IterableCakeTinStatsAttrs<'a>>,
13053 ErrorContext,
13054 > {
13055 for attr in self.clone() {
13056 if let Ok(CakeStatsAttrs::TinStats(val)) = attr {
13057 return Ok(ArrayIterable::new(val));
13058 }
13059 }
13060 Err(ErrorContext::new_missing(
13061 "CakeStatsAttrs",
13062 "TinStats",
13063 self.orig_loc,
13064 self.buf.as_ptr() as usize,
13065 ))
13066 }
13067 pub fn get_deficit(&self) -> Result<i32, ErrorContext> {
13068 let mut iter = self.clone();
13069 iter.pos = 0;
13070 for attr in iter {
13071 if let Ok(CakeStatsAttrs::Deficit(val)) = attr {
13072 return Ok(val);
13073 }
13074 }
13075 Err(ErrorContext::new_missing(
13076 "CakeStatsAttrs",
13077 "Deficit",
13078 self.orig_loc,
13079 self.buf.as_ptr() as usize,
13080 ))
13081 }
13082 pub fn get_cobalt_count(&self) -> Result<u32, ErrorContext> {
13083 let mut iter = self.clone();
13084 iter.pos = 0;
13085 for attr in iter {
13086 if let Ok(CakeStatsAttrs::CobaltCount(val)) = attr {
13087 return Ok(val);
13088 }
13089 }
13090 Err(ErrorContext::new_missing(
13091 "CakeStatsAttrs",
13092 "CobaltCount",
13093 self.orig_loc,
13094 self.buf.as_ptr() as usize,
13095 ))
13096 }
13097 pub fn get_dropping(&self) -> Result<u32, ErrorContext> {
13098 let mut iter = self.clone();
13099 iter.pos = 0;
13100 for attr in iter {
13101 if let Ok(CakeStatsAttrs::Dropping(val)) = attr {
13102 return Ok(val);
13103 }
13104 }
13105 Err(ErrorContext::new_missing(
13106 "CakeStatsAttrs",
13107 "Dropping",
13108 self.orig_loc,
13109 self.buf.as_ptr() as usize,
13110 ))
13111 }
13112 pub fn get_drop_next_us(&self) -> Result<i32, ErrorContext> {
13113 let mut iter = self.clone();
13114 iter.pos = 0;
13115 for attr in iter {
13116 if let Ok(CakeStatsAttrs::DropNextUs(val)) = attr {
13117 return Ok(val);
13118 }
13119 }
13120 Err(ErrorContext::new_missing(
13121 "CakeStatsAttrs",
13122 "DropNextUs",
13123 self.orig_loc,
13124 self.buf.as_ptr() as usize,
13125 ))
13126 }
13127 pub fn get_p_drop(&self) -> Result<u32, ErrorContext> {
13128 let mut iter = self.clone();
13129 iter.pos = 0;
13130 for attr in iter {
13131 if let Ok(CakeStatsAttrs::PDrop(val)) = attr {
13132 return Ok(val);
13133 }
13134 }
13135 Err(ErrorContext::new_missing(
13136 "CakeStatsAttrs",
13137 "PDrop",
13138 self.orig_loc,
13139 self.buf.as_ptr() as usize,
13140 ))
13141 }
13142 pub fn get_blue_timer_us(&self) -> Result<i32, ErrorContext> {
13143 let mut iter = self.clone();
13144 iter.pos = 0;
13145 for attr in iter {
13146 if let Ok(CakeStatsAttrs::BlueTimerUs(val)) = attr {
13147 return Ok(val);
13148 }
13149 }
13150 Err(ErrorContext::new_missing(
13151 "CakeStatsAttrs",
13152 "BlueTimerUs",
13153 self.orig_loc,
13154 self.buf.as_ptr() as usize,
13155 ))
13156 }
13157 pub fn get_active_queues(&self) -> Result<u32, ErrorContext> {
13158 let mut iter = self.clone();
13159 iter.pos = 0;
13160 for attr in iter {
13161 if let Ok(CakeStatsAttrs::ActiveQueues(val)) = attr {
13162 return Ok(val);
13163 }
13164 }
13165 Err(ErrorContext::new_missing(
13166 "CakeStatsAttrs",
13167 "ActiveQueues",
13168 self.orig_loc,
13169 self.buf.as_ptr() as usize,
13170 ))
13171 }
13172}
13173impl<'a> CakeTinStatsAttrs<'a> {
13174 pub fn new_array(buf: &[u8]) -> IterableArrayCakeTinStatsAttrs<'_> {
13175 IterableArrayCakeTinStatsAttrs::with_loc(buf, buf.as_ptr() as usize)
13176 }
13177}
13178#[derive(Clone, Copy, Default)]
13179pub struct IterableArrayCakeTinStatsAttrs<'a> {
13180 buf: &'a [u8],
13181 pos: usize,
13182 orig_loc: usize,
13183}
13184impl<'a> IterableArrayCakeTinStatsAttrs<'a> {
13185 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
13186 Self {
13187 buf,
13188 pos: 0,
13189 orig_loc,
13190 }
13191 }
13192 pub fn get_buf(&self) -> &'a [u8] {
13193 self.buf
13194 }
13195}
13196impl<'a> Iterator for IterableArrayCakeTinStatsAttrs<'a> {
13197 type Item = Result<IterableCakeTinStatsAttrs<'a>, ErrorContext>;
13198 fn next(&mut self) -> Option<Self::Item> {
13199 if self.buf.len() == self.pos {
13200 return None;
13201 }
13202 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
13203 {
13204 return Some(Ok(IterableCakeTinStatsAttrs::with_loc(next, self.orig_loc)));
13205 }
13206 }
13207 let pos = self.pos;
13208 self.pos = self.buf.len();
13209 Some(Err(ErrorContext::new(
13210 "CakeTinStatsAttrs",
13211 None,
13212 self.orig_loc,
13213 self.buf.as_ptr().wrapping_add(pos) as usize,
13214 )))
13215 }
13216}
13217impl CakeStatsAttrs<'_> {
13218 pub fn new<'a>(buf: &'a [u8]) -> IterableCakeStatsAttrs<'a> {
13219 IterableCakeStatsAttrs::with_loc(buf, buf.as_ptr() as usize)
13220 }
13221 fn attr_from_type(r#type: u16) -> Option<&'static str> {
13222 let res = match r#type {
13223 1u16 => "Pad",
13224 2u16 => "CapacityEstimate64",
13225 3u16 => "MemoryLimit",
13226 4u16 => "MemoryUsed",
13227 5u16 => "AvgNetoff",
13228 6u16 => "MinNetlen",
13229 7u16 => "MaxNetlen",
13230 8u16 => "MinAdjlen",
13231 9u16 => "MaxAdjlen",
13232 10u16 => "TinStats",
13233 11u16 => "Deficit",
13234 12u16 => "CobaltCount",
13235 13u16 => "Dropping",
13236 14u16 => "DropNextUs",
13237 15u16 => "PDrop",
13238 16u16 => "BlueTimerUs",
13239 17u16 => "ActiveQueues",
13240 _ => return None,
13241 };
13242 Some(res)
13243 }
13244}
13245#[derive(Clone, Copy, Default)]
13246pub struct IterableCakeStatsAttrs<'a> {
13247 buf: &'a [u8],
13248 pos: usize,
13249 orig_loc: usize,
13250}
13251impl<'a> IterableCakeStatsAttrs<'a> {
13252 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
13253 Self {
13254 buf,
13255 pos: 0,
13256 orig_loc,
13257 }
13258 }
13259 pub fn get_buf(&self) -> &'a [u8] {
13260 self.buf
13261 }
13262}
13263impl<'a> Iterator for IterableCakeStatsAttrs<'a> {
13264 type Item = Result<CakeStatsAttrs<'a>, ErrorContext>;
13265 fn next(&mut self) -> Option<Self::Item> {
13266 let mut pos;
13267 let mut r#type;
13268 loop {
13269 pos = self.pos;
13270 r#type = None;
13271 if self.buf.len() == self.pos {
13272 return None;
13273 }
13274 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
13275 self.pos = self.buf.len();
13276 break;
13277 };
13278 r#type = Some(header.r#type);
13279 let res = match header.r#type {
13280 1u16 => CakeStatsAttrs::Pad({
13281 let res = Some(next);
13282 let Some(val) = res else { break };
13283 val
13284 }),
13285 2u16 => CakeStatsAttrs::CapacityEstimate64({
13286 let res = parse_u64(next);
13287 let Some(val) = res else { break };
13288 val
13289 }),
13290 3u16 => CakeStatsAttrs::MemoryLimit({
13291 let res = parse_u32(next);
13292 let Some(val) = res else { break };
13293 val
13294 }),
13295 4u16 => CakeStatsAttrs::MemoryUsed({
13296 let res = parse_u32(next);
13297 let Some(val) = res else { break };
13298 val
13299 }),
13300 5u16 => CakeStatsAttrs::AvgNetoff({
13301 let res = parse_u32(next);
13302 let Some(val) = res else { break };
13303 val
13304 }),
13305 6u16 => CakeStatsAttrs::MinNetlen({
13306 let res = parse_u32(next);
13307 let Some(val) = res else { break };
13308 val
13309 }),
13310 7u16 => CakeStatsAttrs::MaxNetlen({
13311 let res = parse_u32(next);
13312 let Some(val) = res else { break };
13313 val
13314 }),
13315 8u16 => CakeStatsAttrs::MinAdjlen({
13316 let res = parse_u32(next);
13317 let Some(val) = res else { break };
13318 val
13319 }),
13320 9u16 => CakeStatsAttrs::MaxAdjlen({
13321 let res = parse_u32(next);
13322 let Some(val) = res else { break };
13323 val
13324 }),
13325 10u16 => CakeStatsAttrs::TinStats({
13326 let res = Some(IterableArrayCakeTinStatsAttrs::with_loc(
13327 next,
13328 self.orig_loc,
13329 ));
13330 let Some(val) = res else { break };
13331 val
13332 }),
13333 11u16 => CakeStatsAttrs::Deficit({
13334 let res = parse_i32(next);
13335 let Some(val) = res else { break };
13336 val
13337 }),
13338 12u16 => CakeStatsAttrs::CobaltCount({
13339 let res = parse_u32(next);
13340 let Some(val) = res else { break };
13341 val
13342 }),
13343 13u16 => CakeStatsAttrs::Dropping({
13344 let res = parse_u32(next);
13345 let Some(val) = res else { break };
13346 val
13347 }),
13348 14u16 => CakeStatsAttrs::DropNextUs({
13349 let res = parse_i32(next);
13350 let Some(val) = res else { break };
13351 val
13352 }),
13353 15u16 => CakeStatsAttrs::PDrop({
13354 let res = parse_u32(next);
13355 let Some(val) = res else { break };
13356 val
13357 }),
13358 16u16 => CakeStatsAttrs::BlueTimerUs({
13359 let res = parse_i32(next);
13360 let Some(val) = res else { break };
13361 val
13362 }),
13363 17u16 => CakeStatsAttrs::ActiveQueues({
13364 let res = parse_u32(next);
13365 let Some(val) = res else { break };
13366 val
13367 }),
13368 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
13369 n => continue,
13370 };
13371 return Some(Ok(res));
13372 }
13373 Some(Err(ErrorContext::new(
13374 "CakeStatsAttrs",
13375 r#type.and_then(|t| CakeStatsAttrs::attr_from_type(t)),
13376 self.orig_loc,
13377 self.buf.as_ptr().wrapping_add(pos) as usize,
13378 )))
13379 }
13380}
13381impl std::fmt::Debug for IterableArrayCakeTinStatsAttrs<'_> {
13382 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13383 fmt.debug_list()
13384 .entries(self.clone().map(FlattenErrorContext))
13385 .finish()
13386 }
13387}
13388impl<'a> std::fmt::Debug for IterableCakeStatsAttrs<'_> {
13389 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13390 let mut fmt = f.debug_struct("CakeStatsAttrs");
13391 for attr in self.clone() {
13392 let attr = match attr {
13393 Ok(a) => a,
13394 Err(err) => {
13395 fmt.finish()?;
13396 f.write_str("Err(")?;
13397 err.fmt(f)?;
13398 return f.write_str(")");
13399 }
13400 };
13401 match attr {
13402 CakeStatsAttrs::Pad(val) => fmt.field("Pad", &val),
13403 CakeStatsAttrs::CapacityEstimate64(val) => fmt.field("CapacityEstimate64", &val),
13404 CakeStatsAttrs::MemoryLimit(val) => fmt.field("MemoryLimit", &val),
13405 CakeStatsAttrs::MemoryUsed(val) => fmt.field("MemoryUsed", &val),
13406 CakeStatsAttrs::AvgNetoff(val) => fmt.field("AvgNetoff", &val),
13407 CakeStatsAttrs::MinNetlen(val) => fmt.field("MinNetlen", &val),
13408 CakeStatsAttrs::MaxNetlen(val) => fmt.field("MaxNetlen", &val),
13409 CakeStatsAttrs::MinAdjlen(val) => fmt.field("MinAdjlen", &val),
13410 CakeStatsAttrs::MaxAdjlen(val) => fmt.field("MaxAdjlen", &val),
13411 CakeStatsAttrs::TinStats(val) => fmt.field("TinStats", &val),
13412 CakeStatsAttrs::Deficit(val) => fmt.field("Deficit", &val),
13413 CakeStatsAttrs::CobaltCount(val) => fmt.field("CobaltCount", &val),
13414 CakeStatsAttrs::Dropping(val) => fmt.field("Dropping", &val),
13415 CakeStatsAttrs::DropNextUs(val) => fmt.field("DropNextUs", &val),
13416 CakeStatsAttrs::PDrop(val) => fmt.field("PDrop", &val),
13417 CakeStatsAttrs::BlueTimerUs(val) => fmt.field("BlueTimerUs", &val),
13418 CakeStatsAttrs::ActiveQueues(val) => fmt.field("ActiveQueues", &val),
13419 };
13420 }
13421 fmt.finish()
13422 }
13423}
13424impl IterableCakeStatsAttrs<'_> {
13425 pub fn lookup_attr(
13426 &self,
13427 offset: usize,
13428 missing_type: Option<u16>,
13429 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
13430 let mut stack = Vec::new();
13431 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
13432 if missing_type.is_some() && cur == offset {
13433 stack.push(("CakeStatsAttrs", offset));
13434 return (
13435 stack,
13436 missing_type.and_then(|t| CakeStatsAttrs::attr_from_type(t)),
13437 );
13438 }
13439 if cur > offset || cur + self.buf.len() < offset {
13440 return (stack, None);
13441 }
13442 let mut attrs = self.clone();
13443 let mut last_off = cur + attrs.pos;
13444 let mut missing = None;
13445 while let Some(attr) = attrs.next() {
13446 let Ok(attr) = attr else { break };
13447 match attr {
13448 CakeStatsAttrs::Pad(val) => {
13449 if last_off == offset {
13450 stack.push(("Pad", last_off));
13451 break;
13452 }
13453 }
13454 CakeStatsAttrs::CapacityEstimate64(val) => {
13455 if last_off == offset {
13456 stack.push(("CapacityEstimate64", last_off));
13457 break;
13458 }
13459 }
13460 CakeStatsAttrs::MemoryLimit(val) => {
13461 if last_off == offset {
13462 stack.push(("MemoryLimit", last_off));
13463 break;
13464 }
13465 }
13466 CakeStatsAttrs::MemoryUsed(val) => {
13467 if last_off == offset {
13468 stack.push(("MemoryUsed", last_off));
13469 break;
13470 }
13471 }
13472 CakeStatsAttrs::AvgNetoff(val) => {
13473 if last_off == offset {
13474 stack.push(("AvgNetoff", last_off));
13475 break;
13476 }
13477 }
13478 CakeStatsAttrs::MinNetlen(val) => {
13479 if last_off == offset {
13480 stack.push(("MinNetlen", last_off));
13481 break;
13482 }
13483 }
13484 CakeStatsAttrs::MaxNetlen(val) => {
13485 if last_off == offset {
13486 stack.push(("MaxNetlen", last_off));
13487 break;
13488 }
13489 }
13490 CakeStatsAttrs::MinAdjlen(val) => {
13491 if last_off == offset {
13492 stack.push(("MinAdjlen", last_off));
13493 break;
13494 }
13495 }
13496 CakeStatsAttrs::MaxAdjlen(val) => {
13497 if last_off == offset {
13498 stack.push(("MaxAdjlen", last_off));
13499 break;
13500 }
13501 }
13502 CakeStatsAttrs::TinStats(val) => {
13503 for entry in val {
13504 let Ok(attr) = entry else { break };
13505 (stack, missing) = attr.lookup_attr(offset, missing_type);
13506 if !stack.is_empty() {
13507 break;
13508 }
13509 }
13510 if !stack.is_empty() {
13511 stack.push(("TinStats", last_off));
13512 break;
13513 }
13514 }
13515 CakeStatsAttrs::Deficit(val) => {
13516 if last_off == offset {
13517 stack.push(("Deficit", last_off));
13518 break;
13519 }
13520 }
13521 CakeStatsAttrs::CobaltCount(val) => {
13522 if last_off == offset {
13523 stack.push(("CobaltCount", last_off));
13524 break;
13525 }
13526 }
13527 CakeStatsAttrs::Dropping(val) => {
13528 if last_off == offset {
13529 stack.push(("Dropping", last_off));
13530 break;
13531 }
13532 }
13533 CakeStatsAttrs::DropNextUs(val) => {
13534 if last_off == offset {
13535 stack.push(("DropNextUs", last_off));
13536 break;
13537 }
13538 }
13539 CakeStatsAttrs::PDrop(val) => {
13540 if last_off == offset {
13541 stack.push(("PDrop", last_off));
13542 break;
13543 }
13544 }
13545 CakeStatsAttrs::BlueTimerUs(val) => {
13546 if last_off == offset {
13547 stack.push(("BlueTimerUs", last_off));
13548 break;
13549 }
13550 }
13551 CakeStatsAttrs::ActiveQueues(val) => {
13552 if last_off == offset {
13553 stack.push(("ActiveQueues", last_off));
13554 break;
13555 }
13556 }
13557 _ => {}
13558 };
13559 last_off = cur + attrs.pos;
13560 }
13561 if !stack.is_empty() {
13562 stack.push(("CakeStatsAttrs", cur));
13563 }
13564 (stack, missing)
13565 }
13566}
13567#[derive(Clone)]
13568pub enum CakeTinStatsAttrs<'a> {
13569 Pad(&'a [u8]),
13570 SentPackets(u32),
13571 SentBytes64(u64),
13572 DroppedPackets(u32),
13573 DroppedBytes64(u64),
13574 AcksDroppedPackets(u32),
13575 AcksDroppedBytes64(u64),
13576 EcnMarkedPackets(u32),
13577 EcnMarkedBytes64(u64),
13578 BacklogPackets(u32),
13579 BacklogBytes(u32),
13580 ThresholdRate64(u64),
13581 TargetUs(u32),
13582 IntervalUs(u32),
13583 WayIndirectHits(u32),
13584 WayMisses(u32),
13585 WayCollisions(u32),
13586 PeakDelayUs(u32),
13587 AvgDelayUs(u32),
13588 BaseDelayUs(u32),
13589 SparseFlows(u32),
13590 BulkFlows(u32),
13591 UnresponsiveFlows(u32),
13592 MaxSkblen(u32),
13593 FlowQuantum(u32),
13594}
13595impl<'a> IterableCakeTinStatsAttrs<'a> {
13596 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
13597 let mut iter = self.clone();
13598 iter.pos = 0;
13599 for attr in iter {
13600 if let Ok(CakeTinStatsAttrs::Pad(val)) = attr {
13601 return Ok(val);
13602 }
13603 }
13604 Err(ErrorContext::new_missing(
13605 "CakeTinStatsAttrs",
13606 "Pad",
13607 self.orig_loc,
13608 self.buf.as_ptr() as usize,
13609 ))
13610 }
13611 pub fn get_sent_packets(&self) -> Result<u32, ErrorContext> {
13612 let mut iter = self.clone();
13613 iter.pos = 0;
13614 for attr in iter {
13615 if let Ok(CakeTinStatsAttrs::SentPackets(val)) = attr {
13616 return Ok(val);
13617 }
13618 }
13619 Err(ErrorContext::new_missing(
13620 "CakeTinStatsAttrs",
13621 "SentPackets",
13622 self.orig_loc,
13623 self.buf.as_ptr() as usize,
13624 ))
13625 }
13626 pub fn get_sent_bytes64(&self) -> Result<u64, ErrorContext> {
13627 let mut iter = self.clone();
13628 iter.pos = 0;
13629 for attr in iter {
13630 if let Ok(CakeTinStatsAttrs::SentBytes64(val)) = attr {
13631 return Ok(val);
13632 }
13633 }
13634 Err(ErrorContext::new_missing(
13635 "CakeTinStatsAttrs",
13636 "SentBytes64",
13637 self.orig_loc,
13638 self.buf.as_ptr() as usize,
13639 ))
13640 }
13641 pub fn get_dropped_packets(&self) -> Result<u32, ErrorContext> {
13642 let mut iter = self.clone();
13643 iter.pos = 0;
13644 for attr in iter {
13645 if let Ok(CakeTinStatsAttrs::DroppedPackets(val)) = attr {
13646 return Ok(val);
13647 }
13648 }
13649 Err(ErrorContext::new_missing(
13650 "CakeTinStatsAttrs",
13651 "DroppedPackets",
13652 self.orig_loc,
13653 self.buf.as_ptr() as usize,
13654 ))
13655 }
13656 pub fn get_dropped_bytes64(&self) -> Result<u64, ErrorContext> {
13657 let mut iter = self.clone();
13658 iter.pos = 0;
13659 for attr in iter {
13660 if let Ok(CakeTinStatsAttrs::DroppedBytes64(val)) = attr {
13661 return Ok(val);
13662 }
13663 }
13664 Err(ErrorContext::new_missing(
13665 "CakeTinStatsAttrs",
13666 "DroppedBytes64",
13667 self.orig_loc,
13668 self.buf.as_ptr() as usize,
13669 ))
13670 }
13671 pub fn get_acks_dropped_packets(&self) -> Result<u32, ErrorContext> {
13672 let mut iter = self.clone();
13673 iter.pos = 0;
13674 for attr in iter {
13675 if let Ok(CakeTinStatsAttrs::AcksDroppedPackets(val)) = attr {
13676 return Ok(val);
13677 }
13678 }
13679 Err(ErrorContext::new_missing(
13680 "CakeTinStatsAttrs",
13681 "AcksDroppedPackets",
13682 self.orig_loc,
13683 self.buf.as_ptr() as usize,
13684 ))
13685 }
13686 pub fn get_acks_dropped_bytes64(&self) -> Result<u64, ErrorContext> {
13687 let mut iter = self.clone();
13688 iter.pos = 0;
13689 for attr in iter {
13690 if let Ok(CakeTinStatsAttrs::AcksDroppedBytes64(val)) = attr {
13691 return Ok(val);
13692 }
13693 }
13694 Err(ErrorContext::new_missing(
13695 "CakeTinStatsAttrs",
13696 "AcksDroppedBytes64",
13697 self.orig_loc,
13698 self.buf.as_ptr() as usize,
13699 ))
13700 }
13701 pub fn get_ecn_marked_packets(&self) -> Result<u32, ErrorContext> {
13702 let mut iter = self.clone();
13703 iter.pos = 0;
13704 for attr in iter {
13705 if let Ok(CakeTinStatsAttrs::EcnMarkedPackets(val)) = attr {
13706 return Ok(val);
13707 }
13708 }
13709 Err(ErrorContext::new_missing(
13710 "CakeTinStatsAttrs",
13711 "EcnMarkedPackets",
13712 self.orig_loc,
13713 self.buf.as_ptr() as usize,
13714 ))
13715 }
13716 pub fn get_ecn_marked_bytes64(&self) -> Result<u64, ErrorContext> {
13717 let mut iter = self.clone();
13718 iter.pos = 0;
13719 for attr in iter {
13720 if let Ok(CakeTinStatsAttrs::EcnMarkedBytes64(val)) = attr {
13721 return Ok(val);
13722 }
13723 }
13724 Err(ErrorContext::new_missing(
13725 "CakeTinStatsAttrs",
13726 "EcnMarkedBytes64",
13727 self.orig_loc,
13728 self.buf.as_ptr() as usize,
13729 ))
13730 }
13731 pub fn get_backlog_packets(&self) -> Result<u32, ErrorContext> {
13732 let mut iter = self.clone();
13733 iter.pos = 0;
13734 for attr in iter {
13735 if let Ok(CakeTinStatsAttrs::BacklogPackets(val)) = attr {
13736 return Ok(val);
13737 }
13738 }
13739 Err(ErrorContext::new_missing(
13740 "CakeTinStatsAttrs",
13741 "BacklogPackets",
13742 self.orig_loc,
13743 self.buf.as_ptr() as usize,
13744 ))
13745 }
13746 pub fn get_backlog_bytes(&self) -> Result<u32, ErrorContext> {
13747 let mut iter = self.clone();
13748 iter.pos = 0;
13749 for attr in iter {
13750 if let Ok(CakeTinStatsAttrs::BacklogBytes(val)) = attr {
13751 return Ok(val);
13752 }
13753 }
13754 Err(ErrorContext::new_missing(
13755 "CakeTinStatsAttrs",
13756 "BacklogBytes",
13757 self.orig_loc,
13758 self.buf.as_ptr() as usize,
13759 ))
13760 }
13761 pub fn get_threshold_rate64(&self) -> Result<u64, ErrorContext> {
13762 let mut iter = self.clone();
13763 iter.pos = 0;
13764 for attr in iter {
13765 if let Ok(CakeTinStatsAttrs::ThresholdRate64(val)) = attr {
13766 return Ok(val);
13767 }
13768 }
13769 Err(ErrorContext::new_missing(
13770 "CakeTinStatsAttrs",
13771 "ThresholdRate64",
13772 self.orig_loc,
13773 self.buf.as_ptr() as usize,
13774 ))
13775 }
13776 pub fn get_target_us(&self) -> Result<u32, ErrorContext> {
13777 let mut iter = self.clone();
13778 iter.pos = 0;
13779 for attr in iter {
13780 if let Ok(CakeTinStatsAttrs::TargetUs(val)) = attr {
13781 return Ok(val);
13782 }
13783 }
13784 Err(ErrorContext::new_missing(
13785 "CakeTinStatsAttrs",
13786 "TargetUs",
13787 self.orig_loc,
13788 self.buf.as_ptr() as usize,
13789 ))
13790 }
13791 pub fn get_interval_us(&self) -> Result<u32, ErrorContext> {
13792 let mut iter = self.clone();
13793 iter.pos = 0;
13794 for attr in iter {
13795 if let Ok(CakeTinStatsAttrs::IntervalUs(val)) = attr {
13796 return Ok(val);
13797 }
13798 }
13799 Err(ErrorContext::new_missing(
13800 "CakeTinStatsAttrs",
13801 "IntervalUs",
13802 self.orig_loc,
13803 self.buf.as_ptr() as usize,
13804 ))
13805 }
13806 pub fn get_way_indirect_hits(&self) -> Result<u32, ErrorContext> {
13807 let mut iter = self.clone();
13808 iter.pos = 0;
13809 for attr in iter {
13810 if let Ok(CakeTinStatsAttrs::WayIndirectHits(val)) = attr {
13811 return Ok(val);
13812 }
13813 }
13814 Err(ErrorContext::new_missing(
13815 "CakeTinStatsAttrs",
13816 "WayIndirectHits",
13817 self.orig_loc,
13818 self.buf.as_ptr() as usize,
13819 ))
13820 }
13821 pub fn get_way_misses(&self) -> Result<u32, ErrorContext> {
13822 let mut iter = self.clone();
13823 iter.pos = 0;
13824 for attr in iter {
13825 if let Ok(CakeTinStatsAttrs::WayMisses(val)) = attr {
13826 return Ok(val);
13827 }
13828 }
13829 Err(ErrorContext::new_missing(
13830 "CakeTinStatsAttrs",
13831 "WayMisses",
13832 self.orig_loc,
13833 self.buf.as_ptr() as usize,
13834 ))
13835 }
13836 pub fn get_way_collisions(&self) -> Result<u32, ErrorContext> {
13837 let mut iter = self.clone();
13838 iter.pos = 0;
13839 for attr in iter {
13840 if let Ok(CakeTinStatsAttrs::WayCollisions(val)) = attr {
13841 return Ok(val);
13842 }
13843 }
13844 Err(ErrorContext::new_missing(
13845 "CakeTinStatsAttrs",
13846 "WayCollisions",
13847 self.orig_loc,
13848 self.buf.as_ptr() as usize,
13849 ))
13850 }
13851 pub fn get_peak_delay_us(&self) -> Result<u32, ErrorContext> {
13852 let mut iter = self.clone();
13853 iter.pos = 0;
13854 for attr in iter {
13855 if let Ok(CakeTinStatsAttrs::PeakDelayUs(val)) = attr {
13856 return Ok(val);
13857 }
13858 }
13859 Err(ErrorContext::new_missing(
13860 "CakeTinStatsAttrs",
13861 "PeakDelayUs",
13862 self.orig_loc,
13863 self.buf.as_ptr() as usize,
13864 ))
13865 }
13866 pub fn get_avg_delay_us(&self) -> Result<u32, ErrorContext> {
13867 let mut iter = self.clone();
13868 iter.pos = 0;
13869 for attr in iter {
13870 if let Ok(CakeTinStatsAttrs::AvgDelayUs(val)) = attr {
13871 return Ok(val);
13872 }
13873 }
13874 Err(ErrorContext::new_missing(
13875 "CakeTinStatsAttrs",
13876 "AvgDelayUs",
13877 self.orig_loc,
13878 self.buf.as_ptr() as usize,
13879 ))
13880 }
13881 pub fn get_base_delay_us(&self) -> Result<u32, ErrorContext> {
13882 let mut iter = self.clone();
13883 iter.pos = 0;
13884 for attr in iter {
13885 if let Ok(CakeTinStatsAttrs::BaseDelayUs(val)) = attr {
13886 return Ok(val);
13887 }
13888 }
13889 Err(ErrorContext::new_missing(
13890 "CakeTinStatsAttrs",
13891 "BaseDelayUs",
13892 self.orig_loc,
13893 self.buf.as_ptr() as usize,
13894 ))
13895 }
13896 pub fn get_sparse_flows(&self) -> Result<u32, ErrorContext> {
13897 let mut iter = self.clone();
13898 iter.pos = 0;
13899 for attr in iter {
13900 if let Ok(CakeTinStatsAttrs::SparseFlows(val)) = attr {
13901 return Ok(val);
13902 }
13903 }
13904 Err(ErrorContext::new_missing(
13905 "CakeTinStatsAttrs",
13906 "SparseFlows",
13907 self.orig_loc,
13908 self.buf.as_ptr() as usize,
13909 ))
13910 }
13911 pub fn get_bulk_flows(&self) -> Result<u32, ErrorContext> {
13912 let mut iter = self.clone();
13913 iter.pos = 0;
13914 for attr in iter {
13915 if let Ok(CakeTinStatsAttrs::BulkFlows(val)) = attr {
13916 return Ok(val);
13917 }
13918 }
13919 Err(ErrorContext::new_missing(
13920 "CakeTinStatsAttrs",
13921 "BulkFlows",
13922 self.orig_loc,
13923 self.buf.as_ptr() as usize,
13924 ))
13925 }
13926 pub fn get_unresponsive_flows(&self) -> Result<u32, ErrorContext> {
13927 let mut iter = self.clone();
13928 iter.pos = 0;
13929 for attr in iter {
13930 if let Ok(CakeTinStatsAttrs::UnresponsiveFlows(val)) = attr {
13931 return Ok(val);
13932 }
13933 }
13934 Err(ErrorContext::new_missing(
13935 "CakeTinStatsAttrs",
13936 "UnresponsiveFlows",
13937 self.orig_loc,
13938 self.buf.as_ptr() as usize,
13939 ))
13940 }
13941 pub fn get_max_skblen(&self) -> Result<u32, ErrorContext> {
13942 let mut iter = self.clone();
13943 iter.pos = 0;
13944 for attr in iter {
13945 if let Ok(CakeTinStatsAttrs::MaxSkblen(val)) = attr {
13946 return Ok(val);
13947 }
13948 }
13949 Err(ErrorContext::new_missing(
13950 "CakeTinStatsAttrs",
13951 "MaxSkblen",
13952 self.orig_loc,
13953 self.buf.as_ptr() as usize,
13954 ))
13955 }
13956 pub fn get_flow_quantum(&self) -> Result<u32, ErrorContext> {
13957 let mut iter = self.clone();
13958 iter.pos = 0;
13959 for attr in iter {
13960 if let Ok(CakeTinStatsAttrs::FlowQuantum(val)) = attr {
13961 return Ok(val);
13962 }
13963 }
13964 Err(ErrorContext::new_missing(
13965 "CakeTinStatsAttrs",
13966 "FlowQuantum",
13967 self.orig_loc,
13968 self.buf.as_ptr() as usize,
13969 ))
13970 }
13971}
13972impl CakeTinStatsAttrs<'_> {
13973 pub fn new<'a>(buf: &'a [u8]) -> IterableCakeTinStatsAttrs<'a> {
13974 IterableCakeTinStatsAttrs::with_loc(buf, buf.as_ptr() as usize)
13975 }
13976 fn attr_from_type(r#type: u16) -> Option<&'static str> {
13977 let res = match r#type {
13978 1u16 => "Pad",
13979 2u16 => "SentPackets",
13980 3u16 => "SentBytes64",
13981 4u16 => "DroppedPackets",
13982 5u16 => "DroppedBytes64",
13983 6u16 => "AcksDroppedPackets",
13984 7u16 => "AcksDroppedBytes64",
13985 8u16 => "EcnMarkedPackets",
13986 9u16 => "EcnMarkedBytes64",
13987 10u16 => "BacklogPackets",
13988 11u16 => "BacklogBytes",
13989 12u16 => "ThresholdRate64",
13990 13u16 => "TargetUs",
13991 14u16 => "IntervalUs",
13992 15u16 => "WayIndirectHits",
13993 16u16 => "WayMisses",
13994 17u16 => "WayCollisions",
13995 18u16 => "PeakDelayUs",
13996 19u16 => "AvgDelayUs",
13997 20u16 => "BaseDelayUs",
13998 21u16 => "SparseFlows",
13999 22u16 => "BulkFlows",
14000 23u16 => "UnresponsiveFlows",
14001 24u16 => "MaxSkblen",
14002 25u16 => "FlowQuantum",
14003 _ => return None,
14004 };
14005 Some(res)
14006 }
14007}
14008#[derive(Clone, Copy, Default)]
14009pub struct IterableCakeTinStatsAttrs<'a> {
14010 buf: &'a [u8],
14011 pos: usize,
14012 orig_loc: usize,
14013}
14014impl<'a> IterableCakeTinStatsAttrs<'a> {
14015 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
14016 Self {
14017 buf,
14018 pos: 0,
14019 orig_loc,
14020 }
14021 }
14022 pub fn get_buf(&self) -> &'a [u8] {
14023 self.buf
14024 }
14025}
14026impl<'a> Iterator for IterableCakeTinStatsAttrs<'a> {
14027 type Item = Result<CakeTinStatsAttrs<'a>, ErrorContext>;
14028 fn next(&mut self) -> Option<Self::Item> {
14029 let mut pos;
14030 let mut r#type;
14031 loop {
14032 pos = self.pos;
14033 r#type = None;
14034 if self.buf.len() == self.pos {
14035 return None;
14036 }
14037 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
14038 self.pos = self.buf.len();
14039 break;
14040 };
14041 r#type = Some(header.r#type);
14042 let res = match header.r#type {
14043 1u16 => CakeTinStatsAttrs::Pad({
14044 let res = Some(next);
14045 let Some(val) = res else { break };
14046 val
14047 }),
14048 2u16 => CakeTinStatsAttrs::SentPackets({
14049 let res = parse_u32(next);
14050 let Some(val) = res else { break };
14051 val
14052 }),
14053 3u16 => CakeTinStatsAttrs::SentBytes64({
14054 let res = parse_u64(next);
14055 let Some(val) = res else { break };
14056 val
14057 }),
14058 4u16 => CakeTinStatsAttrs::DroppedPackets({
14059 let res = parse_u32(next);
14060 let Some(val) = res else { break };
14061 val
14062 }),
14063 5u16 => CakeTinStatsAttrs::DroppedBytes64({
14064 let res = parse_u64(next);
14065 let Some(val) = res else { break };
14066 val
14067 }),
14068 6u16 => CakeTinStatsAttrs::AcksDroppedPackets({
14069 let res = parse_u32(next);
14070 let Some(val) = res else { break };
14071 val
14072 }),
14073 7u16 => CakeTinStatsAttrs::AcksDroppedBytes64({
14074 let res = parse_u64(next);
14075 let Some(val) = res else { break };
14076 val
14077 }),
14078 8u16 => CakeTinStatsAttrs::EcnMarkedPackets({
14079 let res = parse_u32(next);
14080 let Some(val) = res else { break };
14081 val
14082 }),
14083 9u16 => CakeTinStatsAttrs::EcnMarkedBytes64({
14084 let res = parse_u64(next);
14085 let Some(val) = res else { break };
14086 val
14087 }),
14088 10u16 => CakeTinStatsAttrs::BacklogPackets({
14089 let res = parse_u32(next);
14090 let Some(val) = res else { break };
14091 val
14092 }),
14093 11u16 => CakeTinStatsAttrs::BacklogBytes({
14094 let res = parse_u32(next);
14095 let Some(val) = res else { break };
14096 val
14097 }),
14098 12u16 => CakeTinStatsAttrs::ThresholdRate64({
14099 let res = parse_u64(next);
14100 let Some(val) = res else { break };
14101 val
14102 }),
14103 13u16 => CakeTinStatsAttrs::TargetUs({
14104 let res = parse_u32(next);
14105 let Some(val) = res else { break };
14106 val
14107 }),
14108 14u16 => CakeTinStatsAttrs::IntervalUs({
14109 let res = parse_u32(next);
14110 let Some(val) = res else { break };
14111 val
14112 }),
14113 15u16 => CakeTinStatsAttrs::WayIndirectHits({
14114 let res = parse_u32(next);
14115 let Some(val) = res else { break };
14116 val
14117 }),
14118 16u16 => CakeTinStatsAttrs::WayMisses({
14119 let res = parse_u32(next);
14120 let Some(val) = res else { break };
14121 val
14122 }),
14123 17u16 => CakeTinStatsAttrs::WayCollisions({
14124 let res = parse_u32(next);
14125 let Some(val) = res else { break };
14126 val
14127 }),
14128 18u16 => CakeTinStatsAttrs::PeakDelayUs({
14129 let res = parse_u32(next);
14130 let Some(val) = res else { break };
14131 val
14132 }),
14133 19u16 => CakeTinStatsAttrs::AvgDelayUs({
14134 let res = parse_u32(next);
14135 let Some(val) = res else { break };
14136 val
14137 }),
14138 20u16 => CakeTinStatsAttrs::BaseDelayUs({
14139 let res = parse_u32(next);
14140 let Some(val) = res else { break };
14141 val
14142 }),
14143 21u16 => CakeTinStatsAttrs::SparseFlows({
14144 let res = parse_u32(next);
14145 let Some(val) = res else { break };
14146 val
14147 }),
14148 22u16 => CakeTinStatsAttrs::BulkFlows({
14149 let res = parse_u32(next);
14150 let Some(val) = res else { break };
14151 val
14152 }),
14153 23u16 => CakeTinStatsAttrs::UnresponsiveFlows({
14154 let res = parse_u32(next);
14155 let Some(val) = res else { break };
14156 val
14157 }),
14158 24u16 => CakeTinStatsAttrs::MaxSkblen({
14159 let res = parse_u32(next);
14160 let Some(val) = res else { break };
14161 val
14162 }),
14163 25u16 => CakeTinStatsAttrs::FlowQuantum({
14164 let res = parse_u32(next);
14165 let Some(val) = res else { break };
14166 val
14167 }),
14168 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
14169 n => continue,
14170 };
14171 return Some(Ok(res));
14172 }
14173 Some(Err(ErrorContext::new(
14174 "CakeTinStatsAttrs",
14175 r#type.and_then(|t| CakeTinStatsAttrs::attr_from_type(t)),
14176 self.orig_loc,
14177 self.buf.as_ptr().wrapping_add(pos) as usize,
14178 )))
14179 }
14180}
14181impl<'a> std::fmt::Debug for IterableCakeTinStatsAttrs<'_> {
14182 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14183 let mut fmt = f.debug_struct("CakeTinStatsAttrs");
14184 for attr in self.clone() {
14185 let attr = match attr {
14186 Ok(a) => a,
14187 Err(err) => {
14188 fmt.finish()?;
14189 f.write_str("Err(")?;
14190 err.fmt(f)?;
14191 return f.write_str(")");
14192 }
14193 };
14194 match attr {
14195 CakeTinStatsAttrs::Pad(val) => fmt.field("Pad", &val),
14196 CakeTinStatsAttrs::SentPackets(val) => fmt.field("SentPackets", &val),
14197 CakeTinStatsAttrs::SentBytes64(val) => fmt.field("SentBytes64", &val),
14198 CakeTinStatsAttrs::DroppedPackets(val) => fmt.field("DroppedPackets", &val),
14199 CakeTinStatsAttrs::DroppedBytes64(val) => fmt.field("DroppedBytes64", &val),
14200 CakeTinStatsAttrs::AcksDroppedPackets(val) => fmt.field("AcksDroppedPackets", &val),
14201 CakeTinStatsAttrs::AcksDroppedBytes64(val) => fmt.field("AcksDroppedBytes64", &val),
14202 CakeTinStatsAttrs::EcnMarkedPackets(val) => fmt.field("EcnMarkedPackets", &val),
14203 CakeTinStatsAttrs::EcnMarkedBytes64(val) => fmt.field("EcnMarkedBytes64", &val),
14204 CakeTinStatsAttrs::BacklogPackets(val) => fmt.field("BacklogPackets", &val),
14205 CakeTinStatsAttrs::BacklogBytes(val) => fmt.field("BacklogBytes", &val),
14206 CakeTinStatsAttrs::ThresholdRate64(val) => fmt.field("ThresholdRate64", &val),
14207 CakeTinStatsAttrs::TargetUs(val) => fmt.field("TargetUs", &val),
14208 CakeTinStatsAttrs::IntervalUs(val) => fmt.field("IntervalUs", &val),
14209 CakeTinStatsAttrs::WayIndirectHits(val) => fmt.field("WayIndirectHits", &val),
14210 CakeTinStatsAttrs::WayMisses(val) => fmt.field("WayMisses", &val),
14211 CakeTinStatsAttrs::WayCollisions(val) => fmt.field("WayCollisions", &val),
14212 CakeTinStatsAttrs::PeakDelayUs(val) => fmt.field("PeakDelayUs", &val),
14213 CakeTinStatsAttrs::AvgDelayUs(val) => fmt.field("AvgDelayUs", &val),
14214 CakeTinStatsAttrs::BaseDelayUs(val) => fmt.field("BaseDelayUs", &val),
14215 CakeTinStatsAttrs::SparseFlows(val) => fmt.field("SparseFlows", &val),
14216 CakeTinStatsAttrs::BulkFlows(val) => fmt.field("BulkFlows", &val),
14217 CakeTinStatsAttrs::UnresponsiveFlows(val) => fmt.field("UnresponsiveFlows", &val),
14218 CakeTinStatsAttrs::MaxSkblen(val) => fmt.field("MaxSkblen", &val),
14219 CakeTinStatsAttrs::FlowQuantum(val) => fmt.field("FlowQuantum", &val),
14220 };
14221 }
14222 fmt.finish()
14223 }
14224}
14225impl IterableCakeTinStatsAttrs<'_> {
14226 pub fn lookup_attr(
14227 &self,
14228 offset: usize,
14229 missing_type: Option<u16>,
14230 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
14231 let mut stack = Vec::new();
14232 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
14233 if missing_type.is_some() && cur == offset {
14234 stack.push(("CakeTinStatsAttrs", offset));
14235 return (
14236 stack,
14237 missing_type.and_then(|t| CakeTinStatsAttrs::attr_from_type(t)),
14238 );
14239 }
14240 if cur > offset || cur + self.buf.len() < offset {
14241 return (stack, None);
14242 }
14243 let mut attrs = self.clone();
14244 let mut last_off = cur + attrs.pos;
14245 while let Some(attr) = attrs.next() {
14246 let Ok(attr) = attr else { break };
14247 match attr {
14248 CakeTinStatsAttrs::Pad(val) => {
14249 if last_off == offset {
14250 stack.push(("Pad", last_off));
14251 break;
14252 }
14253 }
14254 CakeTinStatsAttrs::SentPackets(val) => {
14255 if last_off == offset {
14256 stack.push(("SentPackets", last_off));
14257 break;
14258 }
14259 }
14260 CakeTinStatsAttrs::SentBytes64(val) => {
14261 if last_off == offset {
14262 stack.push(("SentBytes64", last_off));
14263 break;
14264 }
14265 }
14266 CakeTinStatsAttrs::DroppedPackets(val) => {
14267 if last_off == offset {
14268 stack.push(("DroppedPackets", last_off));
14269 break;
14270 }
14271 }
14272 CakeTinStatsAttrs::DroppedBytes64(val) => {
14273 if last_off == offset {
14274 stack.push(("DroppedBytes64", last_off));
14275 break;
14276 }
14277 }
14278 CakeTinStatsAttrs::AcksDroppedPackets(val) => {
14279 if last_off == offset {
14280 stack.push(("AcksDroppedPackets", last_off));
14281 break;
14282 }
14283 }
14284 CakeTinStatsAttrs::AcksDroppedBytes64(val) => {
14285 if last_off == offset {
14286 stack.push(("AcksDroppedBytes64", last_off));
14287 break;
14288 }
14289 }
14290 CakeTinStatsAttrs::EcnMarkedPackets(val) => {
14291 if last_off == offset {
14292 stack.push(("EcnMarkedPackets", last_off));
14293 break;
14294 }
14295 }
14296 CakeTinStatsAttrs::EcnMarkedBytes64(val) => {
14297 if last_off == offset {
14298 stack.push(("EcnMarkedBytes64", last_off));
14299 break;
14300 }
14301 }
14302 CakeTinStatsAttrs::BacklogPackets(val) => {
14303 if last_off == offset {
14304 stack.push(("BacklogPackets", last_off));
14305 break;
14306 }
14307 }
14308 CakeTinStatsAttrs::BacklogBytes(val) => {
14309 if last_off == offset {
14310 stack.push(("BacklogBytes", last_off));
14311 break;
14312 }
14313 }
14314 CakeTinStatsAttrs::ThresholdRate64(val) => {
14315 if last_off == offset {
14316 stack.push(("ThresholdRate64", last_off));
14317 break;
14318 }
14319 }
14320 CakeTinStatsAttrs::TargetUs(val) => {
14321 if last_off == offset {
14322 stack.push(("TargetUs", last_off));
14323 break;
14324 }
14325 }
14326 CakeTinStatsAttrs::IntervalUs(val) => {
14327 if last_off == offset {
14328 stack.push(("IntervalUs", last_off));
14329 break;
14330 }
14331 }
14332 CakeTinStatsAttrs::WayIndirectHits(val) => {
14333 if last_off == offset {
14334 stack.push(("WayIndirectHits", last_off));
14335 break;
14336 }
14337 }
14338 CakeTinStatsAttrs::WayMisses(val) => {
14339 if last_off == offset {
14340 stack.push(("WayMisses", last_off));
14341 break;
14342 }
14343 }
14344 CakeTinStatsAttrs::WayCollisions(val) => {
14345 if last_off == offset {
14346 stack.push(("WayCollisions", last_off));
14347 break;
14348 }
14349 }
14350 CakeTinStatsAttrs::PeakDelayUs(val) => {
14351 if last_off == offset {
14352 stack.push(("PeakDelayUs", last_off));
14353 break;
14354 }
14355 }
14356 CakeTinStatsAttrs::AvgDelayUs(val) => {
14357 if last_off == offset {
14358 stack.push(("AvgDelayUs", last_off));
14359 break;
14360 }
14361 }
14362 CakeTinStatsAttrs::BaseDelayUs(val) => {
14363 if last_off == offset {
14364 stack.push(("BaseDelayUs", last_off));
14365 break;
14366 }
14367 }
14368 CakeTinStatsAttrs::SparseFlows(val) => {
14369 if last_off == offset {
14370 stack.push(("SparseFlows", last_off));
14371 break;
14372 }
14373 }
14374 CakeTinStatsAttrs::BulkFlows(val) => {
14375 if last_off == offset {
14376 stack.push(("BulkFlows", last_off));
14377 break;
14378 }
14379 }
14380 CakeTinStatsAttrs::UnresponsiveFlows(val) => {
14381 if last_off == offset {
14382 stack.push(("UnresponsiveFlows", last_off));
14383 break;
14384 }
14385 }
14386 CakeTinStatsAttrs::MaxSkblen(val) => {
14387 if last_off == offset {
14388 stack.push(("MaxSkblen", last_off));
14389 break;
14390 }
14391 }
14392 CakeTinStatsAttrs::FlowQuantum(val) => {
14393 if last_off == offset {
14394 stack.push(("FlowQuantum", last_off));
14395 break;
14396 }
14397 }
14398 _ => {}
14399 };
14400 last_off = cur + attrs.pos;
14401 }
14402 if !stack.is_empty() {
14403 stack.push(("CakeTinStatsAttrs", cur));
14404 }
14405 (stack, None)
14406 }
14407}
14408#[derive(Clone)]
14409pub enum CbsAttrs {
14410 Parms(TcCbsQopt),
14411}
14412impl<'a> IterableCbsAttrs<'a> {
14413 pub fn get_parms(&self) -> Result<TcCbsQopt, ErrorContext> {
14414 let mut iter = self.clone();
14415 iter.pos = 0;
14416 for attr in iter {
14417 if let Ok(CbsAttrs::Parms(val)) = attr {
14418 return Ok(val);
14419 }
14420 }
14421 Err(ErrorContext::new_missing(
14422 "CbsAttrs",
14423 "Parms",
14424 self.orig_loc,
14425 self.buf.as_ptr() as usize,
14426 ))
14427 }
14428}
14429impl CbsAttrs {
14430 pub fn new<'a>(buf: &'a [u8]) -> IterableCbsAttrs<'a> {
14431 IterableCbsAttrs::with_loc(buf, buf.as_ptr() as usize)
14432 }
14433 fn attr_from_type(r#type: u16) -> Option<&'static str> {
14434 let res = match r#type {
14435 1u16 => "Parms",
14436 _ => return None,
14437 };
14438 Some(res)
14439 }
14440}
14441#[derive(Clone, Copy, Default)]
14442pub struct IterableCbsAttrs<'a> {
14443 buf: &'a [u8],
14444 pos: usize,
14445 orig_loc: usize,
14446}
14447impl<'a> IterableCbsAttrs<'a> {
14448 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
14449 Self {
14450 buf,
14451 pos: 0,
14452 orig_loc,
14453 }
14454 }
14455 pub fn get_buf(&self) -> &'a [u8] {
14456 self.buf
14457 }
14458}
14459impl<'a> Iterator for IterableCbsAttrs<'a> {
14460 type Item = Result<CbsAttrs, ErrorContext>;
14461 fn next(&mut self) -> Option<Self::Item> {
14462 let mut pos;
14463 let mut r#type;
14464 loop {
14465 pos = self.pos;
14466 r#type = None;
14467 if self.buf.len() == self.pos {
14468 return None;
14469 }
14470 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
14471 self.pos = self.buf.len();
14472 break;
14473 };
14474 r#type = Some(header.r#type);
14475 let res = match header.r#type {
14476 1u16 => CbsAttrs::Parms({
14477 let res = Some(TcCbsQopt::new_from_zeroed(next));
14478 let Some(val) = res else { break };
14479 val
14480 }),
14481 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
14482 n => continue,
14483 };
14484 return Some(Ok(res));
14485 }
14486 Some(Err(ErrorContext::new(
14487 "CbsAttrs",
14488 r#type.and_then(|t| CbsAttrs::attr_from_type(t)),
14489 self.orig_loc,
14490 self.buf.as_ptr().wrapping_add(pos) as usize,
14491 )))
14492 }
14493}
14494impl std::fmt::Debug for IterableCbsAttrs<'_> {
14495 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14496 let mut fmt = f.debug_struct("CbsAttrs");
14497 for attr in self.clone() {
14498 let attr = match attr {
14499 Ok(a) => a,
14500 Err(err) => {
14501 fmt.finish()?;
14502 f.write_str("Err(")?;
14503 err.fmt(f)?;
14504 return f.write_str(")");
14505 }
14506 };
14507 match attr {
14508 CbsAttrs::Parms(val) => fmt.field("Parms", &val),
14509 };
14510 }
14511 fmt.finish()
14512 }
14513}
14514impl IterableCbsAttrs<'_> {
14515 pub fn lookup_attr(
14516 &self,
14517 offset: usize,
14518 missing_type: Option<u16>,
14519 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
14520 let mut stack = Vec::new();
14521 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
14522 if missing_type.is_some() && cur == offset {
14523 stack.push(("CbsAttrs", offset));
14524 return (
14525 stack,
14526 missing_type.and_then(|t| CbsAttrs::attr_from_type(t)),
14527 );
14528 }
14529 if cur > offset || cur + self.buf.len() < offset {
14530 return (stack, None);
14531 }
14532 let mut attrs = self.clone();
14533 let mut last_off = cur + attrs.pos;
14534 while let Some(attr) = attrs.next() {
14535 let Ok(attr) = attr else { break };
14536 match attr {
14537 CbsAttrs::Parms(val) => {
14538 if last_off == offset {
14539 stack.push(("Parms", last_off));
14540 break;
14541 }
14542 }
14543 _ => {}
14544 };
14545 last_off = cur + attrs.pos;
14546 }
14547 if !stack.is_empty() {
14548 stack.push(("CbsAttrs", cur));
14549 }
14550 (stack, None)
14551 }
14552}
14553#[derive(Clone)]
14554pub enum CgroupAttrs<'a> {
14555 Act(IterableArrayActAttrs<'a>),
14556 Police(IterablePoliceAttrs<'a>),
14557 Ematches(&'a [u8]),
14558}
14559impl<'a> IterableCgroupAttrs<'a> {
14560 pub fn get_act(
14561 &self,
14562 ) -> Result<ArrayIterable<IterableArrayActAttrs<'a>, IterableActAttrs<'a>>, ErrorContext> {
14563 for attr in self.clone() {
14564 if let Ok(CgroupAttrs::Act(val)) = attr {
14565 return Ok(ArrayIterable::new(val));
14566 }
14567 }
14568 Err(ErrorContext::new_missing(
14569 "CgroupAttrs",
14570 "Act",
14571 self.orig_loc,
14572 self.buf.as_ptr() as usize,
14573 ))
14574 }
14575 pub fn get_police(&self) -> Result<IterablePoliceAttrs<'a>, ErrorContext> {
14576 let mut iter = self.clone();
14577 iter.pos = 0;
14578 for attr in iter {
14579 if let Ok(CgroupAttrs::Police(val)) = attr {
14580 return Ok(val);
14581 }
14582 }
14583 Err(ErrorContext::new_missing(
14584 "CgroupAttrs",
14585 "Police",
14586 self.orig_loc,
14587 self.buf.as_ptr() as usize,
14588 ))
14589 }
14590 pub fn get_ematches(&self) -> Result<&'a [u8], ErrorContext> {
14591 let mut iter = self.clone();
14592 iter.pos = 0;
14593 for attr in iter {
14594 if let Ok(CgroupAttrs::Ematches(val)) = attr {
14595 return Ok(val);
14596 }
14597 }
14598 Err(ErrorContext::new_missing(
14599 "CgroupAttrs",
14600 "Ematches",
14601 self.orig_loc,
14602 self.buf.as_ptr() as usize,
14603 ))
14604 }
14605}
14606impl CgroupAttrs<'_> {
14607 pub fn new<'a>(buf: &'a [u8]) -> IterableCgroupAttrs<'a> {
14608 IterableCgroupAttrs::with_loc(buf, buf.as_ptr() as usize)
14609 }
14610 fn attr_from_type(r#type: u16) -> Option<&'static str> {
14611 let res = match r#type {
14612 1u16 => "Act",
14613 2u16 => "Police",
14614 3u16 => "Ematches",
14615 _ => return None,
14616 };
14617 Some(res)
14618 }
14619}
14620#[derive(Clone, Copy, Default)]
14621pub struct IterableCgroupAttrs<'a> {
14622 buf: &'a [u8],
14623 pos: usize,
14624 orig_loc: usize,
14625}
14626impl<'a> IterableCgroupAttrs<'a> {
14627 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
14628 Self {
14629 buf,
14630 pos: 0,
14631 orig_loc,
14632 }
14633 }
14634 pub fn get_buf(&self) -> &'a [u8] {
14635 self.buf
14636 }
14637}
14638impl<'a> Iterator for IterableCgroupAttrs<'a> {
14639 type Item = Result<CgroupAttrs<'a>, ErrorContext>;
14640 fn next(&mut self) -> Option<Self::Item> {
14641 let mut pos;
14642 let mut r#type;
14643 loop {
14644 pos = self.pos;
14645 r#type = None;
14646 if self.buf.len() == self.pos {
14647 return None;
14648 }
14649 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
14650 self.pos = self.buf.len();
14651 break;
14652 };
14653 r#type = Some(header.r#type);
14654 let res = match header.r#type {
14655 1u16 => CgroupAttrs::Act({
14656 let res = Some(IterableArrayActAttrs::with_loc(next, self.orig_loc));
14657 let Some(val) = res else { break };
14658 val
14659 }),
14660 2u16 => CgroupAttrs::Police({
14661 let res = Some(IterablePoliceAttrs::with_loc(next, self.orig_loc));
14662 let Some(val) = res else { break };
14663 val
14664 }),
14665 3u16 => CgroupAttrs::Ematches({
14666 let res = Some(next);
14667 let Some(val) = res else { break };
14668 val
14669 }),
14670 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
14671 n => continue,
14672 };
14673 return Some(Ok(res));
14674 }
14675 Some(Err(ErrorContext::new(
14676 "CgroupAttrs",
14677 r#type.and_then(|t| CgroupAttrs::attr_from_type(t)),
14678 self.orig_loc,
14679 self.buf.as_ptr().wrapping_add(pos) as usize,
14680 )))
14681 }
14682}
14683impl<'a> std::fmt::Debug for IterableCgroupAttrs<'_> {
14684 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14685 let mut fmt = f.debug_struct("CgroupAttrs");
14686 for attr in self.clone() {
14687 let attr = match attr {
14688 Ok(a) => a,
14689 Err(err) => {
14690 fmt.finish()?;
14691 f.write_str("Err(")?;
14692 err.fmt(f)?;
14693 return f.write_str(")");
14694 }
14695 };
14696 match attr {
14697 CgroupAttrs::Act(val) => fmt.field("Act", &val),
14698 CgroupAttrs::Police(val) => fmt.field("Police", &val),
14699 CgroupAttrs::Ematches(val) => fmt.field("Ematches", &val),
14700 };
14701 }
14702 fmt.finish()
14703 }
14704}
14705impl IterableCgroupAttrs<'_> {
14706 pub fn lookup_attr(
14707 &self,
14708 offset: usize,
14709 missing_type: Option<u16>,
14710 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
14711 let mut stack = Vec::new();
14712 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
14713 if missing_type.is_some() && cur == offset {
14714 stack.push(("CgroupAttrs", offset));
14715 return (
14716 stack,
14717 missing_type.and_then(|t| CgroupAttrs::attr_from_type(t)),
14718 );
14719 }
14720 if cur > offset || cur + self.buf.len() < offset {
14721 return (stack, None);
14722 }
14723 let mut attrs = self.clone();
14724 let mut last_off = cur + attrs.pos;
14725 let mut missing = None;
14726 while let Some(attr) = attrs.next() {
14727 let Ok(attr) = attr else { break };
14728 match attr {
14729 CgroupAttrs::Act(val) => {
14730 for entry in val {
14731 let Ok(attr) = entry else { break };
14732 (stack, missing) = attr.lookup_attr(offset, missing_type);
14733 if !stack.is_empty() {
14734 break;
14735 }
14736 }
14737 if !stack.is_empty() {
14738 stack.push(("Act", last_off));
14739 break;
14740 }
14741 }
14742 CgroupAttrs::Police(val) => {
14743 (stack, missing) = val.lookup_attr(offset, missing_type);
14744 if !stack.is_empty() {
14745 break;
14746 }
14747 }
14748 CgroupAttrs::Ematches(val) => {
14749 if last_off == offset {
14750 stack.push(("Ematches", last_off));
14751 break;
14752 }
14753 }
14754 _ => {}
14755 };
14756 last_off = cur + attrs.pos;
14757 }
14758 if !stack.is_empty() {
14759 stack.push(("CgroupAttrs", cur));
14760 }
14761 (stack, missing)
14762 }
14763}
14764#[derive(Clone)]
14765pub enum ChokeAttrs<'a> {
14766 Parms(TcRedQopt),
14767 Stab(&'a [u8]),
14768 MaxP(u32),
14769}
14770impl<'a> IterableChokeAttrs<'a> {
14771 pub fn get_parms(&self) -> Result<TcRedQopt, ErrorContext> {
14772 let mut iter = self.clone();
14773 iter.pos = 0;
14774 for attr in iter {
14775 if let Ok(ChokeAttrs::Parms(val)) = attr {
14776 return Ok(val);
14777 }
14778 }
14779 Err(ErrorContext::new_missing(
14780 "ChokeAttrs",
14781 "Parms",
14782 self.orig_loc,
14783 self.buf.as_ptr() as usize,
14784 ))
14785 }
14786 pub fn get_stab(&self) -> Result<&'a [u8], ErrorContext> {
14787 let mut iter = self.clone();
14788 iter.pos = 0;
14789 for attr in iter {
14790 if let Ok(ChokeAttrs::Stab(val)) = attr {
14791 return Ok(val);
14792 }
14793 }
14794 Err(ErrorContext::new_missing(
14795 "ChokeAttrs",
14796 "Stab",
14797 self.orig_loc,
14798 self.buf.as_ptr() as usize,
14799 ))
14800 }
14801 pub fn get_max_p(&self) -> Result<u32, ErrorContext> {
14802 let mut iter = self.clone();
14803 iter.pos = 0;
14804 for attr in iter {
14805 if let Ok(ChokeAttrs::MaxP(val)) = attr {
14806 return Ok(val);
14807 }
14808 }
14809 Err(ErrorContext::new_missing(
14810 "ChokeAttrs",
14811 "MaxP",
14812 self.orig_loc,
14813 self.buf.as_ptr() as usize,
14814 ))
14815 }
14816}
14817impl ChokeAttrs<'_> {
14818 pub fn new<'a>(buf: &'a [u8]) -> IterableChokeAttrs<'a> {
14819 IterableChokeAttrs::with_loc(buf, buf.as_ptr() as usize)
14820 }
14821 fn attr_from_type(r#type: u16) -> Option<&'static str> {
14822 let res = match r#type {
14823 1u16 => "Parms",
14824 2u16 => "Stab",
14825 3u16 => "MaxP",
14826 _ => return None,
14827 };
14828 Some(res)
14829 }
14830}
14831#[derive(Clone, Copy, Default)]
14832pub struct IterableChokeAttrs<'a> {
14833 buf: &'a [u8],
14834 pos: usize,
14835 orig_loc: usize,
14836}
14837impl<'a> IterableChokeAttrs<'a> {
14838 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
14839 Self {
14840 buf,
14841 pos: 0,
14842 orig_loc,
14843 }
14844 }
14845 pub fn get_buf(&self) -> &'a [u8] {
14846 self.buf
14847 }
14848}
14849impl<'a> Iterator for IterableChokeAttrs<'a> {
14850 type Item = Result<ChokeAttrs<'a>, ErrorContext>;
14851 fn next(&mut self) -> Option<Self::Item> {
14852 let mut pos;
14853 let mut r#type;
14854 loop {
14855 pos = self.pos;
14856 r#type = None;
14857 if self.buf.len() == self.pos {
14858 return None;
14859 }
14860 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
14861 self.pos = self.buf.len();
14862 break;
14863 };
14864 r#type = Some(header.r#type);
14865 let res = match header.r#type {
14866 1u16 => ChokeAttrs::Parms({
14867 let res = Some(TcRedQopt::new_from_zeroed(next));
14868 let Some(val) = res else { break };
14869 val
14870 }),
14871 2u16 => ChokeAttrs::Stab({
14872 let res = Some(next);
14873 let Some(val) = res else { break };
14874 val
14875 }),
14876 3u16 => ChokeAttrs::MaxP({
14877 let res = parse_u32(next);
14878 let Some(val) = res else { break };
14879 val
14880 }),
14881 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
14882 n => continue,
14883 };
14884 return Some(Ok(res));
14885 }
14886 Some(Err(ErrorContext::new(
14887 "ChokeAttrs",
14888 r#type.and_then(|t| ChokeAttrs::attr_from_type(t)),
14889 self.orig_loc,
14890 self.buf.as_ptr().wrapping_add(pos) as usize,
14891 )))
14892 }
14893}
14894impl<'a> std::fmt::Debug for IterableChokeAttrs<'_> {
14895 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14896 let mut fmt = f.debug_struct("ChokeAttrs");
14897 for attr in self.clone() {
14898 let attr = match attr {
14899 Ok(a) => a,
14900 Err(err) => {
14901 fmt.finish()?;
14902 f.write_str("Err(")?;
14903 err.fmt(f)?;
14904 return f.write_str(")");
14905 }
14906 };
14907 match attr {
14908 ChokeAttrs::Parms(val) => fmt.field("Parms", &val),
14909 ChokeAttrs::Stab(val) => fmt.field("Stab", &val),
14910 ChokeAttrs::MaxP(val) => fmt.field("MaxP", &val),
14911 };
14912 }
14913 fmt.finish()
14914 }
14915}
14916impl IterableChokeAttrs<'_> {
14917 pub fn lookup_attr(
14918 &self,
14919 offset: usize,
14920 missing_type: Option<u16>,
14921 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
14922 let mut stack = Vec::new();
14923 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
14924 if missing_type.is_some() && cur == offset {
14925 stack.push(("ChokeAttrs", offset));
14926 return (
14927 stack,
14928 missing_type.and_then(|t| ChokeAttrs::attr_from_type(t)),
14929 );
14930 }
14931 if cur > offset || cur + self.buf.len() < offset {
14932 return (stack, None);
14933 }
14934 let mut attrs = self.clone();
14935 let mut last_off = cur + attrs.pos;
14936 while let Some(attr) = attrs.next() {
14937 let Ok(attr) = attr else { break };
14938 match attr {
14939 ChokeAttrs::Parms(val) => {
14940 if last_off == offset {
14941 stack.push(("Parms", last_off));
14942 break;
14943 }
14944 }
14945 ChokeAttrs::Stab(val) => {
14946 if last_off == offset {
14947 stack.push(("Stab", last_off));
14948 break;
14949 }
14950 }
14951 ChokeAttrs::MaxP(val) => {
14952 if last_off == offset {
14953 stack.push(("MaxP", last_off));
14954 break;
14955 }
14956 }
14957 _ => {}
14958 };
14959 last_off = cur + attrs.pos;
14960 }
14961 if !stack.is_empty() {
14962 stack.push(("ChokeAttrs", cur));
14963 }
14964 (stack, None)
14965 }
14966}
14967#[derive(Clone)]
14968pub enum CodelAttrs {
14969 Target(u32),
14970 Limit(u32),
14971 Interval(u32),
14972 Ecn(u32),
14973 CeThreshold(u32),
14974}
14975impl<'a> IterableCodelAttrs<'a> {
14976 pub fn get_target(&self) -> Result<u32, ErrorContext> {
14977 let mut iter = self.clone();
14978 iter.pos = 0;
14979 for attr in iter {
14980 if let Ok(CodelAttrs::Target(val)) = attr {
14981 return Ok(val);
14982 }
14983 }
14984 Err(ErrorContext::new_missing(
14985 "CodelAttrs",
14986 "Target",
14987 self.orig_loc,
14988 self.buf.as_ptr() as usize,
14989 ))
14990 }
14991 pub fn get_limit(&self) -> Result<u32, ErrorContext> {
14992 let mut iter = self.clone();
14993 iter.pos = 0;
14994 for attr in iter {
14995 if let Ok(CodelAttrs::Limit(val)) = attr {
14996 return Ok(val);
14997 }
14998 }
14999 Err(ErrorContext::new_missing(
15000 "CodelAttrs",
15001 "Limit",
15002 self.orig_loc,
15003 self.buf.as_ptr() as usize,
15004 ))
15005 }
15006 pub fn get_interval(&self) -> Result<u32, ErrorContext> {
15007 let mut iter = self.clone();
15008 iter.pos = 0;
15009 for attr in iter {
15010 if let Ok(CodelAttrs::Interval(val)) = attr {
15011 return Ok(val);
15012 }
15013 }
15014 Err(ErrorContext::new_missing(
15015 "CodelAttrs",
15016 "Interval",
15017 self.orig_loc,
15018 self.buf.as_ptr() as usize,
15019 ))
15020 }
15021 pub fn get_ecn(&self) -> Result<u32, ErrorContext> {
15022 let mut iter = self.clone();
15023 iter.pos = 0;
15024 for attr in iter {
15025 if let Ok(CodelAttrs::Ecn(val)) = attr {
15026 return Ok(val);
15027 }
15028 }
15029 Err(ErrorContext::new_missing(
15030 "CodelAttrs",
15031 "Ecn",
15032 self.orig_loc,
15033 self.buf.as_ptr() as usize,
15034 ))
15035 }
15036 pub fn get_ce_threshold(&self) -> Result<u32, ErrorContext> {
15037 let mut iter = self.clone();
15038 iter.pos = 0;
15039 for attr in iter {
15040 if let Ok(CodelAttrs::CeThreshold(val)) = attr {
15041 return Ok(val);
15042 }
15043 }
15044 Err(ErrorContext::new_missing(
15045 "CodelAttrs",
15046 "CeThreshold",
15047 self.orig_loc,
15048 self.buf.as_ptr() as usize,
15049 ))
15050 }
15051}
15052impl CodelAttrs {
15053 pub fn new<'a>(buf: &'a [u8]) -> IterableCodelAttrs<'a> {
15054 IterableCodelAttrs::with_loc(buf, buf.as_ptr() as usize)
15055 }
15056 fn attr_from_type(r#type: u16) -> Option<&'static str> {
15057 let res = match r#type {
15058 1u16 => "Target",
15059 2u16 => "Limit",
15060 3u16 => "Interval",
15061 4u16 => "Ecn",
15062 5u16 => "CeThreshold",
15063 _ => return None,
15064 };
15065 Some(res)
15066 }
15067}
15068#[derive(Clone, Copy, Default)]
15069pub struct IterableCodelAttrs<'a> {
15070 buf: &'a [u8],
15071 pos: usize,
15072 orig_loc: usize,
15073}
15074impl<'a> IterableCodelAttrs<'a> {
15075 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15076 Self {
15077 buf,
15078 pos: 0,
15079 orig_loc,
15080 }
15081 }
15082 pub fn get_buf(&self) -> &'a [u8] {
15083 self.buf
15084 }
15085}
15086impl<'a> Iterator for IterableCodelAttrs<'a> {
15087 type Item = Result<CodelAttrs, ErrorContext>;
15088 fn next(&mut self) -> Option<Self::Item> {
15089 let mut pos;
15090 let mut r#type;
15091 loop {
15092 pos = self.pos;
15093 r#type = None;
15094 if self.buf.len() == self.pos {
15095 return None;
15096 }
15097 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
15098 self.pos = self.buf.len();
15099 break;
15100 };
15101 r#type = Some(header.r#type);
15102 let res = match header.r#type {
15103 1u16 => CodelAttrs::Target({
15104 let res = parse_u32(next);
15105 let Some(val) = res else { break };
15106 val
15107 }),
15108 2u16 => CodelAttrs::Limit({
15109 let res = parse_u32(next);
15110 let Some(val) = res else { break };
15111 val
15112 }),
15113 3u16 => CodelAttrs::Interval({
15114 let res = parse_u32(next);
15115 let Some(val) = res else { break };
15116 val
15117 }),
15118 4u16 => CodelAttrs::Ecn({
15119 let res = parse_u32(next);
15120 let Some(val) = res else { break };
15121 val
15122 }),
15123 5u16 => CodelAttrs::CeThreshold({
15124 let res = parse_u32(next);
15125 let Some(val) = res else { break };
15126 val
15127 }),
15128 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
15129 n => continue,
15130 };
15131 return Some(Ok(res));
15132 }
15133 Some(Err(ErrorContext::new(
15134 "CodelAttrs",
15135 r#type.and_then(|t| CodelAttrs::attr_from_type(t)),
15136 self.orig_loc,
15137 self.buf.as_ptr().wrapping_add(pos) as usize,
15138 )))
15139 }
15140}
15141impl std::fmt::Debug for IterableCodelAttrs<'_> {
15142 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15143 let mut fmt = f.debug_struct("CodelAttrs");
15144 for attr in self.clone() {
15145 let attr = match attr {
15146 Ok(a) => a,
15147 Err(err) => {
15148 fmt.finish()?;
15149 f.write_str("Err(")?;
15150 err.fmt(f)?;
15151 return f.write_str(")");
15152 }
15153 };
15154 match attr {
15155 CodelAttrs::Target(val) => fmt.field("Target", &val),
15156 CodelAttrs::Limit(val) => fmt.field("Limit", &val),
15157 CodelAttrs::Interval(val) => fmt.field("Interval", &val),
15158 CodelAttrs::Ecn(val) => fmt.field("Ecn", &val),
15159 CodelAttrs::CeThreshold(val) => fmt.field("CeThreshold", &val),
15160 };
15161 }
15162 fmt.finish()
15163 }
15164}
15165impl IterableCodelAttrs<'_> {
15166 pub fn lookup_attr(
15167 &self,
15168 offset: usize,
15169 missing_type: Option<u16>,
15170 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15171 let mut stack = Vec::new();
15172 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15173 if missing_type.is_some() && cur == offset {
15174 stack.push(("CodelAttrs", offset));
15175 return (
15176 stack,
15177 missing_type.and_then(|t| CodelAttrs::attr_from_type(t)),
15178 );
15179 }
15180 if cur > offset || cur + self.buf.len() < offset {
15181 return (stack, None);
15182 }
15183 let mut attrs = self.clone();
15184 let mut last_off = cur + attrs.pos;
15185 while let Some(attr) = attrs.next() {
15186 let Ok(attr) = attr else { break };
15187 match attr {
15188 CodelAttrs::Target(val) => {
15189 if last_off == offset {
15190 stack.push(("Target", last_off));
15191 break;
15192 }
15193 }
15194 CodelAttrs::Limit(val) => {
15195 if last_off == offset {
15196 stack.push(("Limit", last_off));
15197 break;
15198 }
15199 }
15200 CodelAttrs::Interval(val) => {
15201 if last_off == offset {
15202 stack.push(("Interval", last_off));
15203 break;
15204 }
15205 }
15206 CodelAttrs::Ecn(val) => {
15207 if last_off == offset {
15208 stack.push(("Ecn", last_off));
15209 break;
15210 }
15211 }
15212 CodelAttrs::CeThreshold(val) => {
15213 if last_off == offset {
15214 stack.push(("CeThreshold", last_off));
15215 break;
15216 }
15217 }
15218 _ => {}
15219 };
15220 last_off = cur + attrs.pos;
15221 }
15222 if !stack.is_empty() {
15223 stack.push(("CodelAttrs", cur));
15224 }
15225 (stack, None)
15226 }
15227}
15228#[derive(Clone)]
15229pub enum DrrAttrs {
15230 Quantum(u32),
15231}
15232impl<'a> IterableDrrAttrs<'a> {
15233 pub fn get_quantum(&self) -> Result<u32, ErrorContext> {
15234 let mut iter = self.clone();
15235 iter.pos = 0;
15236 for attr in iter {
15237 if let Ok(DrrAttrs::Quantum(val)) = attr {
15238 return Ok(val);
15239 }
15240 }
15241 Err(ErrorContext::new_missing(
15242 "DrrAttrs",
15243 "Quantum",
15244 self.orig_loc,
15245 self.buf.as_ptr() as usize,
15246 ))
15247 }
15248}
15249impl DrrAttrs {
15250 pub fn new<'a>(buf: &'a [u8]) -> IterableDrrAttrs<'a> {
15251 IterableDrrAttrs::with_loc(buf, buf.as_ptr() as usize)
15252 }
15253 fn attr_from_type(r#type: u16) -> Option<&'static str> {
15254 let res = match r#type {
15255 1u16 => "Quantum",
15256 _ => return None,
15257 };
15258 Some(res)
15259 }
15260}
15261#[derive(Clone, Copy, Default)]
15262pub struct IterableDrrAttrs<'a> {
15263 buf: &'a [u8],
15264 pos: usize,
15265 orig_loc: usize,
15266}
15267impl<'a> IterableDrrAttrs<'a> {
15268 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15269 Self {
15270 buf,
15271 pos: 0,
15272 orig_loc,
15273 }
15274 }
15275 pub fn get_buf(&self) -> &'a [u8] {
15276 self.buf
15277 }
15278}
15279impl<'a> Iterator for IterableDrrAttrs<'a> {
15280 type Item = Result<DrrAttrs, ErrorContext>;
15281 fn next(&mut self) -> Option<Self::Item> {
15282 let mut pos;
15283 let mut r#type;
15284 loop {
15285 pos = self.pos;
15286 r#type = None;
15287 if self.buf.len() == self.pos {
15288 return None;
15289 }
15290 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
15291 self.pos = self.buf.len();
15292 break;
15293 };
15294 r#type = Some(header.r#type);
15295 let res = match header.r#type {
15296 1u16 => DrrAttrs::Quantum({
15297 let res = parse_u32(next);
15298 let Some(val) = res else { break };
15299 val
15300 }),
15301 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
15302 n => continue,
15303 };
15304 return Some(Ok(res));
15305 }
15306 Some(Err(ErrorContext::new(
15307 "DrrAttrs",
15308 r#type.and_then(|t| DrrAttrs::attr_from_type(t)),
15309 self.orig_loc,
15310 self.buf.as_ptr().wrapping_add(pos) as usize,
15311 )))
15312 }
15313}
15314impl std::fmt::Debug for IterableDrrAttrs<'_> {
15315 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15316 let mut fmt = f.debug_struct("DrrAttrs");
15317 for attr in self.clone() {
15318 let attr = match attr {
15319 Ok(a) => a,
15320 Err(err) => {
15321 fmt.finish()?;
15322 f.write_str("Err(")?;
15323 err.fmt(f)?;
15324 return f.write_str(")");
15325 }
15326 };
15327 match attr {
15328 DrrAttrs::Quantum(val) => fmt.field("Quantum", &val),
15329 };
15330 }
15331 fmt.finish()
15332 }
15333}
15334impl IterableDrrAttrs<'_> {
15335 pub fn lookup_attr(
15336 &self,
15337 offset: usize,
15338 missing_type: Option<u16>,
15339 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15340 let mut stack = Vec::new();
15341 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15342 if missing_type.is_some() && cur == offset {
15343 stack.push(("DrrAttrs", offset));
15344 return (
15345 stack,
15346 missing_type.and_then(|t| DrrAttrs::attr_from_type(t)),
15347 );
15348 }
15349 if cur > offset || cur + self.buf.len() < offset {
15350 return (stack, None);
15351 }
15352 let mut attrs = self.clone();
15353 let mut last_off = cur + attrs.pos;
15354 while let Some(attr) = attrs.next() {
15355 let Ok(attr) = attr else { break };
15356 match attr {
15357 DrrAttrs::Quantum(val) => {
15358 if last_off == offset {
15359 stack.push(("Quantum", last_off));
15360 break;
15361 }
15362 }
15363 _ => {}
15364 };
15365 last_off = cur + attrs.pos;
15366 }
15367 if !stack.is_empty() {
15368 stack.push(("DrrAttrs", cur));
15369 }
15370 (stack, None)
15371 }
15372}
15373#[derive(Clone)]
15374pub enum Dualpi2Attrs {
15375 #[doc = "Limit of total number of packets in queue\n"]
15376 Limit(u32),
15377 #[doc = "Memory limit of total number of packets in queue\n"]
15378 MemoryLimit(u32),
15379 #[doc = "Classic target delay in microseconds\n"]
15380 Target(u32),
15381 #[doc = "Drop probability update interval time in microseconds\n"]
15382 Tupdate(u32),
15383 #[doc = "Integral gain factor in Hz for PI controller\n"]
15384 Alpha(u32),
15385 #[doc = "Proportional gain factor in Hz for PI controller\n"]
15386 Beta(u32),
15387 #[doc = "L4S step marking threshold in packets\n"]
15388 StepThreshPkts(u32),
15389 #[doc = "L4S Step marking threshold in microseconds\n"]
15390 StepThreshUs(u32),
15391 #[doc = "Packets enqueued to the L-queue can apply the step threshold when the\nqueue length of L-queue is larger than this value. (0 is recommended)\n"]
15392 MinQlenStep(u32),
15393 #[doc = "Probability coupling factor between Classic and L4S (2 is recommended)\n"]
15394 Coupling(u8),
15395 #[doc = "Control the overload strategy (drop to preserve latency or let the queue\noverflow)\n\nAssociated type: [`Dualpi2DropOverload`] (enum)"]
15396 DropOverload(u8),
15397 #[doc = "Decide where the Classic packets are PI-based dropped or marked\n\nAssociated type: [`Dualpi2DropEarly`] (enum)"]
15398 DropEarly(u8),
15399 #[doc = "Classic WRR weight in percentage (from 0 to 100)\n"]
15400 CProtection(u8),
15401 #[doc = "Configure the L-queue ECN classifier\n\nAssociated type: [`Dualpi2EcnMask`] (enum)"]
15402 EcnMask(u8),
15403 #[doc = "Split aggregated skb or not\n\nAssociated type: [`Dualpi2SplitGso`] (enum)"]
15404 SplitGso(u8),
15405}
15406impl<'a> IterableDualpi2Attrs<'a> {
15407 #[doc = "Limit of total number of packets in queue\n"]
15408 pub fn get_limit(&self) -> Result<u32, ErrorContext> {
15409 let mut iter = self.clone();
15410 iter.pos = 0;
15411 for attr in iter {
15412 if let Ok(Dualpi2Attrs::Limit(val)) = attr {
15413 return Ok(val);
15414 }
15415 }
15416 Err(ErrorContext::new_missing(
15417 "Dualpi2Attrs",
15418 "Limit",
15419 self.orig_loc,
15420 self.buf.as_ptr() as usize,
15421 ))
15422 }
15423 #[doc = "Memory limit of total number of packets in queue\n"]
15424 pub fn get_memory_limit(&self) -> Result<u32, ErrorContext> {
15425 let mut iter = self.clone();
15426 iter.pos = 0;
15427 for attr in iter {
15428 if let Ok(Dualpi2Attrs::MemoryLimit(val)) = attr {
15429 return Ok(val);
15430 }
15431 }
15432 Err(ErrorContext::new_missing(
15433 "Dualpi2Attrs",
15434 "MemoryLimit",
15435 self.orig_loc,
15436 self.buf.as_ptr() as usize,
15437 ))
15438 }
15439 #[doc = "Classic target delay in microseconds\n"]
15440 pub fn get_target(&self) -> Result<u32, ErrorContext> {
15441 let mut iter = self.clone();
15442 iter.pos = 0;
15443 for attr in iter {
15444 if let Ok(Dualpi2Attrs::Target(val)) = attr {
15445 return Ok(val);
15446 }
15447 }
15448 Err(ErrorContext::new_missing(
15449 "Dualpi2Attrs",
15450 "Target",
15451 self.orig_loc,
15452 self.buf.as_ptr() as usize,
15453 ))
15454 }
15455 #[doc = "Drop probability update interval time in microseconds\n"]
15456 pub fn get_tupdate(&self) -> Result<u32, ErrorContext> {
15457 let mut iter = self.clone();
15458 iter.pos = 0;
15459 for attr in iter {
15460 if let Ok(Dualpi2Attrs::Tupdate(val)) = attr {
15461 return Ok(val);
15462 }
15463 }
15464 Err(ErrorContext::new_missing(
15465 "Dualpi2Attrs",
15466 "Tupdate",
15467 self.orig_loc,
15468 self.buf.as_ptr() as usize,
15469 ))
15470 }
15471 #[doc = "Integral gain factor in Hz for PI controller\n"]
15472 pub fn get_alpha(&self) -> Result<u32, ErrorContext> {
15473 let mut iter = self.clone();
15474 iter.pos = 0;
15475 for attr in iter {
15476 if let Ok(Dualpi2Attrs::Alpha(val)) = attr {
15477 return Ok(val);
15478 }
15479 }
15480 Err(ErrorContext::new_missing(
15481 "Dualpi2Attrs",
15482 "Alpha",
15483 self.orig_loc,
15484 self.buf.as_ptr() as usize,
15485 ))
15486 }
15487 #[doc = "Proportional gain factor in Hz for PI controller\n"]
15488 pub fn get_beta(&self) -> Result<u32, ErrorContext> {
15489 let mut iter = self.clone();
15490 iter.pos = 0;
15491 for attr in iter {
15492 if let Ok(Dualpi2Attrs::Beta(val)) = attr {
15493 return Ok(val);
15494 }
15495 }
15496 Err(ErrorContext::new_missing(
15497 "Dualpi2Attrs",
15498 "Beta",
15499 self.orig_loc,
15500 self.buf.as_ptr() as usize,
15501 ))
15502 }
15503 #[doc = "L4S step marking threshold in packets\n"]
15504 pub fn get_step_thresh_pkts(&self) -> Result<u32, ErrorContext> {
15505 let mut iter = self.clone();
15506 iter.pos = 0;
15507 for attr in iter {
15508 if let Ok(Dualpi2Attrs::StepThreshPkts(val)) = attr {
15509 return Ok(val);
15510 }
15511 }
15512 Err(ErrorContext::new_missing(
15513 "Dualpi2Attrs",
15514 "StepThreshPkts",
15515 self.orig_loc,
15516 self.buf.as_ptr() as usize,
15517 ))
15518 }
15519 #[doc = "L4S Step marking threshold in microseconds\n"]
15520 pub fn get_step_thresh_us(&self) -> Result<u32, ErrorContext> {
15521 let mut iter = self.clone();
15522 iter.pos = 0;
15523 for attr in iter {
15524 if let Ok(Dualpi2Attrs::StepThreshUs(val)) = attr {
15525 return Ok(val);
15526 }
15527 }
15528 Err(ErrorContext::new_missing(
15529 "Dualpi2Attrs",
15530 "StepThreshUs",
15531 self.orig_loc,
15532 self.buf.as_ptr() as usize,
15533 ))
15534 }
15535 #[doc = "Packets enqueued to the L-queue can apply the step threshold when the\nqueue length of L-queue is larger than this value. (0 is recommended)\n"]
15536 pub fn get_min_qlen_step(&self) -> Result<u32, ErrorContext> {
15537 let mut iter = self.clone();
15538 iter.pos = 0;
15539 for attr in iter {
15540 if let Ok(Dualpi2Attrs::MinQlenStep(val)) = attr {
15541 return Ok(val);
15542 }
15543 }
15544 Err(ErrorContext::new_missing(
15545 "Dualpi2Attrs",
15546 "MinQlenStep",
15547 self.orig_loc,
15548 self.buf.as_ptr() as usize,
15549 ))
15550 }
15551 #[doc = "Probability coupling factor between Classic and L4S (2 is recommended)\n"]
15552 pub fn get_coupling(&self) -> Result<u8, ErrorContext> {
15553 let mut iter = self.clone();
15554 iter.pos = 0;
15555 for attr in iter {
15556 if let Ok(Dualpi2Attrs::Coupling(val)) = attr {
15557 return Ok(val);
15558 }
15559 }
15560 Err(ErrorContext::new_missing(
15561 "Dualpi2Attrs",
15562 "Coupling",
15563 self.orig_loc,
15564 self.buf.as_ptr() as usize,
15565 ))
15566 }
15567 #[doc = "Control the overload strategy (drop to preserve latency or let the queue\noverflow)\n\nAssociated type: [`Dualpi2DropOverload`] (enum)"]
15568 pub fn get_drop_overload(&self) -> Result<u8, ErrorContext> {
15569 let mut iter = self.clone();
15570 iter.pos = 0;
15571 for attr in iter {
15572 if let Ok(Dualpi2Attrs::DropOverload(val)) = attr {
15573 return Ok(val);
15574 }
15575 }
15576 Err(ErrorContext::new_missing(
15577 "Dualpi2Attrs",
15578 "DropOverload",
15579 self.orig_loc,
15580 self.buf.as_ptr() as usize,
15581 ))
15582 }
15583 #[doc = "Decide where the Classic packets are PI-based dropped or marked\n\nAssociated type: [`Dualpi2DropEarly`] (enum)"]
15584 pub fn get_drop_early(&self) -> Result<u8, ErrorContext> {
15585 let mut iter = self.clone();
15586 iter.pos = 0;
15587 for attr in iter {
15588 if let Ok(Dualpi2Attrs::DropEarly(val)) = attr {
15589 return Ok(val);
15590 }
15591 }
15592 Err(ErrorContext::new_missing(
15593 "Dualpi2Attrs",
15594 "DropEarly",
15595 self.orig_loc,
15596 self.buf.as_ptr() as usize,
15597 ))
15598 }
15599 #[doc = "Classic WRR weight in percentage (from 0 to 100)\n"]
15600 pub fn get_c_protection(&self) -> Result<u8, ErrorContext> {
15601 let mut iter = self.clone();
15602 iter.pos = 0;
15603 for attr in iter {
15604 if let Ok(Dualpi2Attrs::CProtection(val)) = attr {
15605 return Ok(val);
15606 }
15607 }
15608 Err(ErrorContext::new_missing(
15609 "Dualpi2Attrs",
15610 "CProtection",
15611 self.orig_loc,
15612 self.buf.as_ptr() as usize,
15613 ))
15614 }
15615 #[doc = "Configure the L-queue ECN classifier\n\nAssociated type: [`Dualpi2EcnMask`] (enum)"]
15616 pub fn get_ecn_mask(&self) -> Result<u8, ErrorContext> {
15617 let mut iter = self.clone();
15618 iter.pos = 0;
15619 for attr in iter {
15620 if let Ok(Dualpi2Attrs::EcnMask(val)) = attr {
15621 return Ok(val);
15622 }
15623 }
15624 Err(ErrorContext::new_missing(
15625 "Dualpi2Attrs",
15626 "EcnMask",
15627 self.orig_loc,
15628 self.buf.as_ptr() as usize,
15629 ))
15630 }
15631 #[doc = "Split aggregated skb or not\n\nAssociated type: [`Dualpi2SplitGso`] (enum)"]
15632 pub fn get_split_gso(&self) -> Result<u8, ErrorContext> {
15633 let mut iter = self.clone();
15634 iter.pos = 0;
15635 for attr in iter {
15636 if let Ok(Dualpi2Attrs::SplitGso(val)) = attr {
15637 return Ok(val);
15638 }
15639 }
15640 Err(ErrorContext::new_missing(
15641 "Dualpi2Attrs",
15642 "SplitGso",
15643 self.orig_loc,
15644 self.buf.as_ptr() as usize,
15645 ))
15646 }
15647}
15648impl Dualpi2Attrs {
15649 pub fn new<'a>(buf: &'a [u8]) -> IterableDualpi2Attrs<'a> {
15650 IterableDualpi2Attrs::with_loc(buf, buf.as_ptr() as usize)
15651 }
15652 fn attr_from_type(r#type: u16) -> Option<&'static str> {
15653 let res = match r#type {
15654 1u16 => "Limit",
15655 2u16 => "MemoryLimit",
15656 3u16 => "Target",
15657 4u16 => "Tupdate",
15658 5u16 => "Alpha",
15659 6u16 => "Beta",
15660 7u16 => "StepThreshPkts",
15661 8u16 => "StepThreshUs",
15662 9u16 => "MinQlenStep",
15663 10u16 => "Coupling",
15664 11u16 => "DropOverload",
15665 12u16 => "DropEarly",
15666 13u16 => "CProtection",
15667 14u16 => "EcnMask",
15668 15u16 => "SplitGso",
15669 _ => return None,
15670 };
15671 Some(res)
15672 }
15673}
15674#[derive(Clone, Copy, Default)]
15675pub struct IterableDualpi2Attrs<'a> {
15676 buf: &'a [u8],
15677 pos: usize,
15678 orig_loc: usize,
15679}
15680impl<'a> IterableDualpi2Attrs<'a> {
15681 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15682 Self {
15683 buf,
15684 pos: 0,
15685 orig_loc,
15686 }
15687 }
15688 pub fn get_buf(&self) -> &'a [u8] {
15689 self.buf
15690 }
15691}
15692impl<'a> Iterator for IterableDualpi2Attrs<'a> {
15693 type Item = Result<Dualpi2Attrs, ErrorContext>;
15694 fn next(&mut self) -> Option<Self::Item> {
15695 let mut pos;
15696 let mut r#type;
15697 loop {
15698 pos = self.pos;
15699 r#type = None;
15700 if self.buf.len() == self.pos {
15701 return None;
15702 }
15703 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
15704 self.pos = self.buf.len();
15705 break;
15706 };
15707 r#type = Some(header.r#type);
15708 let res = match header.r#type {
15709 1u16 => Dualpi2Attrs::Limit({
15710 let res = parse_u32(next);
15711 let Some(val) = res else { break };
15712 val
15713 }),
15714 2u16 => Dualpi2Attrs::MemoryLimit({
15715 let res = parse_u32(next);
15716 let Some(val) = res else { break };
15717 val
15718 }),
15719 3u16 => Dualpi2Attrs::Target({
15720 let res = parse_u32(next);
15721 let Some(val) = res else { break };
15722 val
15723 }),
15724 4u16 => Dualpi2Attrs::Tupdate({
15725 let res = parse_u32(next);
15726 let Some(val) = res else { break };
15727 val
15728 }),
15729 5u16 => Dualpi2Attrs::Alpha({
15730 let res = parse_u32(next);
15731 let Some(val) = res else { break };
15732 val
15733 }),
15734 6u16 => Dualpi2Attrs::Beta({
15735 let res = parse_u32(next);
15736 let Some(val) = res else { break };
15737 val
15738 }),
15739 7u16 => Dualpi2Attrs::StepThreshPkts({
15740 let res = parse_u32(next);
15741 let Some(val) = res else { break };
15742 val
15743 }),
15744 8u16 => Dualpi2Attrs::StepThreshUs({
15745 let res = parse_u32(next);
15746 let Some(val) = res else { break };
15747 val
15748 }),
15749 9u16 => Dualpi2Attrs::MinQlenStep({
15750 let res = parse_u32(next);
15751 let Some(val) = res else { break };
15752 val
15753 }),
15754 10u16 => Dualpi2Attrs::Coupling({
15755 let res = parse_u8(next);
15756 let Some(val) = res else { break };
15757 val
15758 }),
15759 11u16 => Dualpi2Attrs::DropOverload({
15760 let res = parse_u8(next);
15761 let Some(val) = res else { break };
15762 val
15763 }),
15764 12u16 => Dualpi2Attrs::DropEarly({
15765 let res = parse_u8(next);
15766 let Some(val) = res else { break };
15767 val
15768 }),
15769 13u16 => Dualpi2Attrs::CProtection({
15770 let res = parse_u8(next);
15771 let Some(val) = res else { break };
15772 val
15773 }),
15774 14u16 => Dualpi2Attrs::EcnMask({
15775 let res = parse_u8(next);
15776 let Some(val) = res else { break };
15777 val
15778 }),
15779 15u16 => Dualpi2Attrs::SplitGso({
15780 let res = parse_u8(next);
15781 let Some(val) = res else { break };
15782 val
15783 }),
15784 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
15785 n => continue,
15786 };
15787 return Some(Ok(res));
15788 }
15789 Some(Err(ErrorContext::new(
15790 "Dualpi2Attrs",
15791 r#type.and_then(|t| Dualpi2Attrs::attr_from_type(t)),
15792 self.orig_loc,
15793 self.buf.as_ptr().wrapping_add(pos) as usize,
15794 )))
15795 }
15796}
15797impl std::fmt::Debug for IterableDualpi2Attrs<'_> {
15798 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15799 let mut fmt = f.debug_struct("Dualpi2Attrs");
15800 for attr in self.clone() {
15801 let attr = match attr {
15802 Ok(a) => a,
15803 Err(err) => {
15804 fmt.finish()?;
15805 f.write_str("Err(")?;
15806 err.fmt(f)?;
15807 return f.write_str(")");
15808 }
15809 };
15810 match attr {
15811 Dualpi2Attrs::Limit(val) => fmt.field("Limit", &val),
15812 Dualpi2Attrs::MemoryLimit(val) => fmt.field("MemoryLimit", &val),
15813 Dualpi2Attrs::Target(val) => fmt.field("Target", &val),
15814 Dualpi2Attrs::Tupdate(val) => fmt.field("Tupdate", &val),
15815 Dualpi2Attrs::Alpha(val) => fmt.field("Alpha", &val),
15816 Dualpi2Attrs::Beta(val) => fmt.field("Beta", &val),
15817 Dualpi2Attrs::StepThreshPkts(val) => fmt.field("StepThreshPkts", &val),
15818 Dualpi2Attrs::StepThreshUs(val) => fmt.field("StepThreshUs", &val),
15819 Dualpi2Attrs::MinQlenStep(val) => fmt.field("MinQlenStep", &val),
15820 Dualpi2Attrs::Coupling(val) => fmt.field("Coupling", &val),
15821 Dualpi2Attrs::DropOverload(val) => fmt.field(
15822 "DropOverload",
15823 &FormatEnum(val.into(), Dualpi2DropOverload::from_value),
15824 ),
15825 Dualpi2Attrs::DropEarly(val) => fmt.field(
15826 "DropEarly",
15827 &FormatEnum(val.into(), Dualpi2DropEarly::from_value),
15828 ),
15829 Dualpi2Attrs::CProtection(val) => fmt.field("CProtection", &val),
15830 Dualpi2Attrs::EcnMask(val) => fmt.field(
15831 "EcnMask",
15832 &FormatEnum(val.into(), Dualpi2EcnMask::from_value),
15833 ),
15834 Dualpi2Attrs::SplitGso(val) => fmt.field(
15835 "SplitGso",
15836 &FormatEnum(val.into(), Dualpi2SplitGso::from_value),
15837 ),
15838 };
15839 }
15840 fmt.finish()
15841 }
15842}
15843impl IterableDualpi2Attrs<'_> {
15844 pub fn lookup_attr(
15845 &self,
15846 offset: usize,
15847 missing_type: Option<u16>,
15848 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15849 let mut stack = Vec::new();
15850 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15851 if missing_type.is_some() && cur == offset {
15852 stack.push(("Dualpi2Attrs", offset));
15853 return (
15854 stack,
15855 missing_type.and_then(|t| Dualpi2Attrs::attr_from_type(t)),
15856 );
15857 }
15858 if cur > offset || cur + self.buf.len() < offset {
15859 return (stack, None);
15860 }
15861 let mut attrs = self.clone();
15862 let mut last_off = cur + attrs.pos;
15863 while let Some(attr) = attrs.next() {
15864 let Ok(attr) = attr else { break };
15865 match attr {
15866 Dualpi2Attrs::Limit(val) => {
15867 if last_off == offset {
15868 stack.push(("Limit", last_off));
15869 break;
15870 }
15871 }
15872 Dualpi2Attrs::MemoryLimit(val) => {
15873 if last_off == offset {
15874 stack.push(("MemoryLimit", last_off));
15875 break;
15876 }
15877 }
15878 Dualpi2Attrs::Target(val) => {
15879 if last_off == offset {
15880 stack.push(("Target", last_off));
15881 break;
15882 }
15883 }
15884 Dualpi2Attrs::Tupdate(val) => {
15885 if last_off == offset {
15886 stack.push(("Tupdate", last_off));
15887 break;
15888 }
15889 }
15890 Dualpi2Attrs::Alpha(val) => {
15891 if last_off == offset {
15892 stack.push(("Alpha", last_off));
15893 break;
15894 }
15895 }
15896 Dualpi2Attrs::Beta(val) => {
15897 if last_off == offset {
15898 stack.push(("Beta", last_off));
15899 break;
15900 }
15901 }
15902 Dualpi2Attrs::StepThreshPkts(val) => {
15903 if last_off == offset {
15904 stack.push(("StepThreshPkts", last_off));
15905 break;
15906 }
15907 }
15908 Dualpi2Attrs::StepThreshUs(val) => {
15909 if last_off == offset {
15910 stack.push(("StepThreshUs", last_off));
15911 break;
15912 }
15913 }
15914 Dualpi2Attrs::MinQlenStep(val) => {
15915 if last_off == offset {
15916 stack.push(("MinQlenStep", last_off));
15917 break;
15918 }
15919 }
15920 Dualpi2Attrs::Coupling(val) => {
15921 if last_off == offset {
15922 stack.push(("Coupling", last_off));
15923 break;
15924 }
15925 }
15926 Dualpi2Attrs::DropOverload(val) => {
15927 if last_off == offset {
15928 stack.push(("DropOverload", last_off));
15929 break;
15930 }
15931 }
15932 Dualpi2Attrs::DropEarly(val) => {
15933 if last_off == offset {
15934 stack.push(("DropEarly", last_off));
15935 break;
15936 }
15937 }
15938 Dualpi2Attrs::CProtection(val) => {
15939 if last_off == offset {
15940 stack.push(("CProtection", last_off));
15941 break;
15942 }
15943 }
15944 Dualpi2Attrs::EcnMask(val) => {
15945 if last_off == offset {
15946 stack.push(("EcnMask", last_off));
15947 break;
15948 }
15949 }
15950 Dualpi2Attrs::SplitGso(val) => {
15951 if last_off == offset {
15952 stack.push(("SplitGso", last_off));
15953 break;
15954 }
15955 }
15956 _ => {}
15957 };
15958 last_off = cur + attrs.pos;
15959 }
15960 if !stack.is_empty() {
15961 stack.push(("Dualpi2Attrs", cur));
15962 }
15963 (stack, None)
15964 }
15965}
15966#[derive(Clone)]
15967pub enum EmatchAttrs<'a> {
15968 TreeHdr(TcfEmatchTreeHdr),
15969 TreeList(&'a [u8]),
15970}
15971impl<'a> IterableEmatchAttrs<'a> {
15972 pub fn get_tree_hdr(&self) -> Result<TcfEmatchTreeHdr, ErrorContext> {
15973 let mut iter = self.clone();
15974 iter.pos = 0;
15975 for attr in iter {
15976 if let Ok(EmatchAttrs::TreeHdr(val)) = attr {
15977 return Ok(val);
15978 }
15979 }
15980 Err(ErrorContext::new_missing(
15981 "EmatchAttrs",
15982 "TreeHdr",
15983 self.orig_loc,
15984 self.buf.as_ptr() as usize,
15985 ))
15986 }
15987 pub fn get_tree_list(&self) -> Result<&'a [u8], ErrorContext> {
15988 let mut iter = self.clone();
15989 iter.pos = 0;
15990 for attr in iter {
15991 if let Ok(EmatchAttrs::TreeList(val)) = attr {
15992 return Ok(val);
15993 }
15994 }
15995 Err(ErrorContext::new_missing(
15996 "EmatchAttrs",
15997 "TreeList",
15998 self.orig_loc,
15999 self.buf.as_ptr() as usize,
16000 ))
16001 }
16002}
16003impl EmatchAttrs<'_> {
16004 pub fn new<'a>(buf: &'a [u8]) -> IterableEmatchAttrs<'a> {
16005 IterableEmatchAttrs::with_loc(buf, buf.as_ptr() as usize)
16006 }
16007 fn attr_from_type(r#type: u16) -> Option<&'static str> {
16008 let res = match r#type {
16009 1u16 => "TreeHdr",
16010 2u16 => "TreeList",
16011 _ => return None,
16012 };
16013 Some(res)
16014 }
16015}
16016#[derive(Clone, Copy, Default)]
16017pub struct IterableEmatchAttrs<'a> {
16018 buf: &'a [u8],
16019 pos: usize,
16020 orig_loc: usize,
16021}
16022impl<'a> IterableEmatchAttrs<'a> {
16023 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
16024 Self {
16025 buf,
16026 pos: 0,
16027 orig_loc,
16028 }
16029 }
16030 pub fn get_buf(&self) -> &'a [u8] {
16031 self.buf
16032 }
16033}
16034impl<'a> Iterator for IterableEmatchAttrs<'a> {
16035 type Item = Result<EmatchAttrs<'a>, ErrorContext>;
16036 fn next(&mut self) -> Option<Self::Item> {
16037 let mut pos;
16038 let mut r#type;
16039 loop {
16040 pos = self.pos;
16041 r#type = None;
16042 if self.buf.len() == self.pos {
16043 return None;
16044 }
16045 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
16046 self.pos = self.buf.len();
16047 break;
16048 };
16049 r#type = Some(header.r#type);
16050 let res = match header.r#type {
16051 1u16 => EmatchAttrs::TreeHdr({
16052 let res = Some(TcfEmatchTreeHdr::new_from_zeroed(next));
16053 let Some(val) = res else { break };
16054 val
16055 }),
16056 2u16 => EmatchAttrs::TreeList({
16057 let res = Some(next);
16058 let Some(val) = res else { break };
16059 val
16060 }),
16061 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
16062 n => continue,
16063 };
16064 return Some(Ok(res));
16065 }
16066 Some(Err(ErrorContext::new(
16067 "EmatchAttrs",
16068 r#type.and_then(|t| EmatchAttrs::attr_from_type(t)),
16069 self.orig_loc,
16070 self.buf.as_ptr().wrapping_add(pos) as usize,
16071 )))
16072 }
16073}
16074impl<'a> std::fmt::Debug for IterableEmatchAttrs<'_> {
16075 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16076 let mut fmt = f.debug_struct("EmatchAttrs");
16077 for attr in self.clone() {
16078 let attr = match attr {
16079 Ok(a) => a,
16080 Err(err) => {
16081 fmt.finish()?;
16082 f.write_str("Err(")?;
16083 err.fmt(f)?;
16084 return f.write_str(")");
16085 }
16086 };
16087 match attr {
16088 EmatchAttrs::TreeHdr(val) => fmt.field("TreeHdr", &val),
16089 EmatchAttrs::TreeList(val) => fmt.field("TreeList", &val),
16090 };
16091 }
16092 fmt.finish()
16093 }
16094}
16095impl IterableEmatchAttrs<'_> {
16096 pub fn lookup_attr(
16097 &self,
16098 offset: usize,
16099 missing_type: Option<u16>,
16100 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16101 let mut stack = Vec::new();
16102 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
16103 if missing_type.is_some() && cur == offset {
16104 stack.push(("EmatchAttrs", offset));
16105 return (
16106 stack,
16107 missing_type.and_then(|t| EmatchAttrs::attr_from_type(t)),
16108 );
16109 }
16110 if cur > offset || cur + self.buf.len() < offset {
16111 return (stack, None);
16112 }
16113 let mut attrs = self.clone();
16114 let mut last_off = cur + attrs.pos;
16115 while let Some(attr) = attrs.next() {
16116 let Ok(attr) = attr else { break };
16117 match attr {
16118 EmatchAttrs::TreeHdr(val) => {
16119 if last_off == offset {
16120 stack.push(("TreeHdr", last_off));
16121 break;
16122 }
16123 }
16124 EmatchAttrs::TreeList(val) => {
16125 if last_off == offset {
16126 stack.push(("TreeList", last_off));
16127 break;
16128 }
16129 }
16130 _ => {}
16131 };
16132 last_off = cur + attrs.pos;
16133 }
16134 if !stack.is_empty() {
16135 stack.push(("EmatchAttrs", cur));
16136 }
16137 (stack, None)
16138 }
16139}
16140#[derive(Clone)]
16141pub enum FlowAttrs<'a> {
16142 Keys(u32),
16143 Mode(u32),
16144 Baseclass(u32),
16145 Rshift(u32),
16146 Addend(u32),
16147 Mask(u32),
16148 Xor(u32),
16149 Divisor(u32),
16150 Act(&'a [u8]),
16151 Police(IterablePoliceAttrs<'a>),
16152 Ematches(&'a [u8]),
16153 Perturb(u32),
16154}
16155impl<'a> IterableFlowAttrs<'a> {
16156 pub fn get_keys(&self) -> Result<u32, ErrorContext> {
16157 let mut iter = self.clone();
16158 iter.pos = 0;
16159 for attr in iter {
16160 if let Ok(FlowAttrs::Keys(val)) = attr {
16161 return Ok(val);
16162 }
16163 }
16164 Err(ErrorContext::new_missing(
16165 "FlowAttrs",
16166 "Keys",
16167 self.orig_loc,
16168 self.buf.as_ptr() as usize,
16169 ))
16170 }
16171 pub fn get_mode(&self) -> Result<u32, ErrorContext> {
16172 let mut iter = self.clone();
16173 iter.pos = 0;
16174 for attr in iter {
16175 if let Ok(FlowAttrs::Mode(val)) = attr {
16176 return Ok(val);
16177 }
16178 }
16179 Err(ErrorContext::new_missing(
16180 "FlowAttrs",
16181 "Mode",
16182 self.orig_loc,
16183 self.buf.as_ptr() as usize,
16184 ))
16185 }
16186 pub fn get_baseclass(&self) -> Result<u32, ErrorContext> {
16187 let mut iter = self.clone();
16188 iter.pos = 0;
16189 for attr in iter {
16190 if let Ok(FlowAttrs::Baseclass(val)) = attr {
16191 return Ok(val);
16192 }
16193 }
16194 Err(ErrorContext::new_missing(
16195 "FlowAttrs",
16196 "Baseclass",
16197 self.orig_loc,
16198 self.buf.as_ptr() as usize,
16199 ))
16200 }
16201 pub fn get_rshift(&self) -> Result<u32, ErrorContext> {
16202 let mut iter = self.clone();
16203 iter.pos = 0;
16204 for attr in iter {
16205 if let Ok(FlowAttrs::Rshift(val)) = attr {
16206 return Ok(val);
16207 }
16208 }
16209 Err(ErrorContext::new_missing(
16210 "FlowAttrs",
16211 "Rshift",
16212 self.orig_loc,
16213 self.buf.as_ptr() as usize,
16214 ))
16215 }
16216 pub fn get_addend(&self) -> Result<u32, ErrorContext> {
16217 let mut iter = self.clone();
16218 iter.pos = 0;
16219 for attr in iter {
16220 if let Ok(FlowAttrs::Addend(val)) = attr {
16221 return Ok(val);
16222 }
16223 }
16224 Err(ErrorContext::new_missing(
16225 "FlowAttrs",
16226 "Addend",
16227 self.orig_loc,
16228 self.buf.as_ptr() as usize,
16229 ))
16230 }
16231 pub fn get_mask(&self) -> Result<u32, ErrorContext> {
16232 let mut iter = self.clone();
16233 iter.pos = 0;
16234 for attr in iter {
16235 if let Ok(FlowAttrs::Mask(val)) = attr {
16236 return Ok(val);
16237 }
16238 }
16239 Err(ErrorContext::new_missing(
16240 "FlowAttrs",
16241 "Mask",
16242 self.orig_loc,
16243 self.buf.as_ptr() as usize,
16244 ))
16245 }
16246 pub fn get_xor(&self) -> Result<u32, ErrorContext> {
16247 let mut iter = self.clone();
16248 iter.pos = 0;
16249 for attr in iter {
16250 if let Ok(FlowAttrs::Xor(val)) = attr {
16251 return Ok(val);
16252 }
16253 }
16254 Err(ErrorContext::new_missing(
16255 "FlowAttrs",
16256 "Xor",
16257 self.orig_loc,
16258 self.buf.as_ptr() as usize,
16259 ))
16260 }
16261 pub fn get_divisor(&self) -> Result<u32, ErrorContext> {
16262 let mut iter = self.clone();
16263 iter.pos = 0;
16264 for attr in iter {
16265 if let Ok(FlowAttrs::Divisor(val)) = attr {
16266 return Ok(val);
16267 }
16268 }
16269 Err(ErrorContext::new_missing(
16270 "FlowAttrs",
16271 "Divisor",
16272 self.orig_loc,
16273 self.buf.as_ptr() as usize,
16274 ))
16275 }
16276 pub fn get_act(&self) -> Result<&'a [u8], ErrorContext> {
16277 let mut iter = self.clone();
16278 iter.pos = 0;
16279 for attr in iter {
16280 if let Ok(FlowAttrs::Act(val)) = attr {
16281 return Ok(val);
16282 }
16283 }
16284 Err(ErrorContext::new_missing(
16285 "FlowAttrs",
16286 "Act",
16287 self.orig_loc,
16288 self.buf.as_ptr() as usize,
16289 ))
16290 }
16291 pub fn get_police(&self) -> Result<IterablePoliceAttrs<'a>, ErrorContext> {
16292 let mut iter = self.clone();
16293 iter.pos = 0;
16294 for attr in iter {
16295 if let Ok(FlowAttrs::Police(val)) = attr {
16296 return Ok(val);
16297 }
16298 }
16299 Err(ErrorContext::new_missing(
16300 "FlowAttrs",
16301 "Police",
16302 self.orig_loc,
16303 self.buf.as_ptr() as usize,
16304 ))
16305 }
16306 pub fn get_ematches(&self) -> Result<&'a [u8], ErrorContext> {
16307 let mut iter = self.clone();
16308 iter.pos = 0;
16309 for attr in iter {
16310 if let Ok(FlowAttrs::Ematches(val)) = attr {
16311 return Ok(val);
16312 }
16313 }
16314 Err(ErrorContext::new_missing(
16315 "FlowAttrs",
16316 "Ematches",
16317 self.orig_loc,
16318 self.buf.as_ptr() as usize,
16319 ))
16320 }
16321 pub fn get_perturb(&self) -> Result<u32, ErrorContext> {
16322 let mut iter = self.clone();
16323 iter.pos = 0;
16324 for attr in iter {
16325 if let Ok(FlowAttrs::Perturb(val)) = attr {
16326 return Ok(val);
16327 }
16328 }
16329 Err(ErrorContext::new_missing(
16330 "FlowAttrs",
16331 "Perturb",
16332 self.orig_loc,
16333 self.buf.as_ptr() as usize,
16334 ))
16335 }
16336}
16337impl FlowAttrs<'_> {
16338 pub fn new<'a>(buf: &'a [u8]) -> IterableFlowAttrs<'a> {
16339 IterableFlowAttrs::with_loc(buf, buf.as_ptr() as usize)
16340 }
16341 fn attr_from_type(r#type: u16) -> Option<&'static str> {
16342 let res = match r#type {
16343 1u16 => "Keys",
16344 2u16 => "Mode",
16345 3u16 => "Baseclass",
16346 4u16 => "Rshift",
16347 5u16 => "Addend",
16348 6u16 => "Mask",
16349 7u16 => "Xor",
16350 8u16 => "Divisor",
16351 9u16 => "Act",
16352 10u16 => "Police",
16353 11u16 => "Ematches",
16354 12u16 => "Perturb",
16355 _ => return None,
16356 };
16357 Some(res)
16358 }
16359}
16360#[derive(Clone, Copy, Default)]
16361pub struct IterableFlowAttrs<'a> {
16362 buf: &'a [u8],
16363 pos: usize,
16364 orig_loc: usize,
16365}
16366impl<'a> IterableFlowAttrs<'a> {
16367 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
16368 Self {
16369 buf,
16370 pos: 0,
16371 orig_loc,
16372 }
16373 }
16374 pub fn get_buf(&self) -> &'a [u8] {
16375 self.buf
16376 }
16377}
16378impl<'a> Iterator for IterableFlowAttrs<'a> {
16379 type Item = Result<FlowAttrs<'a>, ErrorContext>;
16380 fn next(&mut self) -> Option<Self::Item> {
16381 let mut pos;
16382 let mut r#type;
16383 loop {
16384 pos = self.pos;
16385 r#type = None;
16386 if self.buf.len() == self.pos {
16387 return None;
16388 }
16389 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
16390 self.pos = self.buf.len();
16391 break;
16392 };
16393 r#type = Some(header.r#type);
16394 let res = match header.r#type {
16395 1u16 => FlowAttrs::Keys({
16396 let res = parse_u32(next);
16397 let Some(val) = res else { break };
16398 val
16399 }),
16400 2u16 => FlowAttrs::Mode({
16401 let res = parse_u32(next);
16402 let Some(val) = res else { break };
16403 val
16404 }),
16405 3u16 => FlowAttrs::Baseclass({
16406 let res = parse_u32(next);
16407 let Some(val) = res else { break };
16408 val
16409 }),
16410 4u16 => FlowAttrs::Rshift({
16411 let res = parse_u32(next);
16412 let Some(val) = res else { break };
16413 val
16414 }),
16415 5u16 => FlowAttrs::Addend({
16416 let res = parse_u32(next);
16417 let Some(val) = res else { break };
16418 val
16419 }),
16420 6u16 => FlowAttrs::Mask({
16421 let res = parse_u32(next);
16422 let Some(val) = res else { break };
16423 val
16424 }),
16425 7u16 => FlowAttrs::Xor({
16426 let res = parse_u32(next);
16427 let Some(val) = res else { break };
16428 val
16429 }),
16430 8u16 => FlowAttrs::Divisor({
16431 let res = parse_u32(next);
16432 let Some(val) = res else { break };
16433 val
16434 }),
16435 9u16 => FlowAttrs::Act({
16436 let res = Some(next);
16437 let Some(val) = res else { break };
16438 val
16439 }),
16440 10u16 => FlowAttrs::Police({
16441 let res = Some(IterablePoliceAttrs::with_loc(next, self.orig_loc));
16442 let Some(val) = res else { break };
16443 val
16444 }),
16445 11u16 => FlowAttrs::Ematches({
16446 let res = Some(next);
16447 let Some(val) = res else { break };
16448 val
16449 }),
16450 12u16 => FlowAttrs::Perturb({
16451 let res = parse_u32(next);
16452 let Some(val) = res else { break };
16453 val
16454 }),
16455 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
16456 n => continue,
16457 };
16458 return Some(Ok(res));
16459 }
16460 Some(Err(ErrorContext::new(
16461 "FlowAttrs",
16462 r#type.and_then(|t| FlowAttrs::attr_from_type(t)),
16463 self.orig_loc,
16464 self.buf.as_ptr().wrapping_add(pos) as usize,
16465 )))
16466 }
16467}
16468impl<'a> std::fmt::Debug for IterableFlowAttrs<'_> {
16469 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16470 let mut fmt = f.debug_struct("FlowAttrs");
16471 for attr in self.clone() {
16472 let attr = match attr {
16473 Ok(a) => a,
16474 Err(err) => {
16475 fmt.finish()?;
16476 f.write_str("Err(")?;
16477 err.fmt(f)?;
16478 return f.write_str(")");
16479 }
16480 };
16481 match attr {
16482 FlowAttrs::Keys(val) => fmt.field("Keys", &val),
16483 FlowAttrs::Mode(val) => fmt.field("Mode", &val),
16484 FlowAttrs::Baseclass(val) => fmt.field("Baseclass", &val),
16485 FlowAttrs::Rshift(val) => fmt.field("Rshift", &val),
16486 FlowAttrs::Addend(val) => fmt.field("Addend", &val),
16487 FlowAttrs::Mask(val) => fmt.field("Mask", &val),
16488 FlowAttrs::Xor(val) => fmt.field("Xor", &val),
16489 FlowAttrs::Divisor(val) => fmt.field("Divisor", &val),
16490 FlowAttrs::Act(val) => fmt.field("Act", &val),
16491 FlowAttrs::Police(val) => fmt.field("Police", &val),
16492 FlowAttrs::Ematches(val) => fmt.field("Ematches", &val),
16493 FlowAttrs::Perturb(val) => fmt.field("Perturb", &val),
16494 };
16495 }
16496 fmt.finish()
16497 }
16498}
16499impl IterableFlowAttrs<'_> {
16500 pub fn lookup_attr(
16501 &self,
16502 offset: usize,
16503 missing_type: Option<u16>,
16504 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16505 let mut stack = Vec::new();
16506 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
16507 if missing_type.is_some() && cur == offset {
16508 stack.push(("FlowAttrs", offset));
16509 return (
16510 stack,
16511 missing_type.and_then(|t| FlowAttrs::attr_from_type(t)),
16512 );
16513 }
16514 if cur > offset || cur + self.buf.len() < offset {
16515 return (stack, None);
16516 }
16517 let mut attrs = self.clone();
16518 let mut last_off = cur + attrs.pos;
16519 let mut missing = None;
16520 while let Some(attr) = attrs.next() {
16521 let Ok(attr) = attr else { break };
16522 match attr {
16523 FlowAttrs::Keys(val) => {
16524 if last_off == offset {
16525 stack.push(("Keys", last_off));
16526 break;
16527 }
16528 }
16529 FlowAttrs::Mode(val) => {
16530 if last_off == offset {
16531 stack.push(("Mode", last_off));
16532 break;
16533 }
16534 }
16535 FlowAttrs::Baseclass(val) => {
16536 if last_off == offset {
16537 stack.push(("Baseclass", last_off));
16538 break;
16539 }
16540 }
16541 FlowAttrs::Rshift(val) => {
16542 if last_off == offset {
16543 stack.push(("Rshift", last_off));
16544 break;
16545 }
16546 }
16547 FlowAttrs::Addend(val) => {
16548 if last_off == offset {
16549 stack.push(("Addend", last_off));
16550 break;
16551 }
16552 }
16553 FlowAttrs::Mask(val) => {
16554 if last_off == offset {
16555 stack.push(("Mask", last_off));
16556 break;
16557 }
16558 }
16559 FlowAttrs::Xor(val) => {
16560 if last_off == offset {
16561 stack.push(("Xor", last_off));
16562 break;
16563 }
16564 }
16565 FlowAttrs::Divisor(val) => {
16566 if last_off == offset {
16567 stack.push(("Divisor", last_off));
16568 break;
16569 }
16570 }
16571 FlowAttrs::Act(val) => {
16572 if last_off == offset {
16573 stack.push(("Act", last_off));
16574 break;
16575 }
16576 }
16577 FlowAttrs::Police(val) => {
16578 (stack, missing) = val.lookup_attr(offset, missing_type);
16579 if !stack.is_empty() {
16580 break;
16581 }
16582 }
16583 FlowAttrs::Ematches(val) => {
16584 if last_off == offset {
16585 stack.push(("Ematches", last_off));
16586 break;
16587 }
16588 }
16589 FlowAttrs::Perturb(val) => {
16590 if last_off == offset {
16591 stack.push(("Perturb", last_off));
16592 break;
16593 }
16594 }
16595 _ => {}
16596 };
16597 last_off = cur + attrs.pos;
16598 }
16599 if !stack.is_empty() {
16600 stack.push(("FlowAttrs", cur));
16601 }
16602 (stack, missing)
16603 }
16604}
16605#[derive(Clone)]
16606pub enum FlowerAttrs<'a> {
16607 Classid(u32),
16608 Indev(&'a CStr),
16609 Act(IterableArrayActAttrs<'a>),
16610 KeyEthDst(&'a [u8]),
16611 KeyEthDstMask(&'a [u8]),
16612 KeyEthSrc(&'a [u8]),
16613 KeyEthSrcMask(&'a [u8]),
16614 KeyEthType(u16),
16615 KeyIpProto(u8),
16616 KeyIpv4Src(std::net::Ipv4Addr),
16617 KeyIpv4SrcMask(std::net::Ipv4Addr),
16618 KeyIpv4Dst(std::net::Ipv4Addr),
16619 KeyIpv4DstMask(std::net::Ipv4Addr),
16620 KeyIpv6Src(&'a [u8]),
16621 KeyIpv6SrcMask(&'a [u8]),
16622 KeyIpv6Dst(&'a [u8]),
16623 KeyIpv6DstMask(&'a [u8]),
16624 KeyTcpSrc(u16),
16625 KeyTcpDst(u16),
16626 KeyUdpSrc(u16),
16627 KeyUdpDst(u16),
16628 #[doc = "Associated type: [`ClsFlags`] (1 bit per enumeration)"]
16629 Flags(u32),
16630 KeyVlanId(u16),
16631 KeyVlanPrio(u8),
16632 KeyVlanEthType(u16),
16633 KeyEncKeyId(u32),
16634 KeyEncIpv4Src(std::net::Ipv4Addr),
16635 KeyEncIpv4SrcMask(std::net::Ipv4Addr),
16636 KeyEncIpv4Dst(std::net::Ipv4Addr),
16637 KeyEncIpv4DstMask(std::net::Ipv4Addr),
16638 KeyEncIpv6Src(&'a [u8]),
16639 KeyEncIpv6SrcMask(&'a [u8]),
16640 KeyEncIpv6Dst(&'a [u8]),
16641 KeyEncIpv6DstMask(&'a [u8]),
16642 KeyTcpSrcMask(u16),
16643 KeyTcpDstMask(u16),
16644 KeyUdpSrcMask(u16),
16645 KeyUdpDstMask(u16),
16646 KeySctpSrcMask(u16),
16647 KeySctpDstMask(u16),
16648 KeySctpSrc(u16),
16649 KeySctpDst(u16),
16650 KeyEncUdpSrcPort(u16),
16651 KeyEncUdpSrcPortMask(u16),
16652 KeyEncUdpDstPort(u16),
16653 KeyEncUdpDstPortMask(u16),
16654 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
16655 KeyFlags(u32),
16656 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
16657 KeyFlagsMask(u32),
16658 KeyIcmpv4Code(u8),
16659 KeyIcmpv4CodeMask(u8),
16660 KeyIcmpv4Type(u8),
16661 KeyIcmpv4TypeMask(u8),
16662 KeyIcmpv6Code(u8),
16663 KeyIcmpv6CodeMask(u8),
16664 KeyIcmpv6Type(u8),
16665 KeyIcmpv6TypeMask(u8),
16666 KeyArpSip(u32),
16667 KeyArpSipMask(u32),
16668 KeyArpTip(u32),
16669 KeyArpTipMask(u32),
16670 KeyArpOp(u8),
16671 KeyArpOpMask(u8),
16672 KeyArpSha(&'a [u8]),
16673 KeyArpShaMask(&'a [u8]),
16674 KeyArpTha(&'a [u8]),
16675 KeyArpThaMask(&'a [u8]),
16676 KeyMplsTtl(u8),
16677 KeyMplsBos(u8),
16678 KeyMplsTc(u8),
16679 KeyMplsLabel(u32),
16680 KeyTcpFlags(u16),
16681 KeyTcpFlagsMask(u16),
16682 KeyIpTos(u8),
16683 KeyIpTosMask(u8),
16684 KeyIpTtl(u8),
16685 KeyIpTtlMask(u8),
16686 KeyCvlanId(u16),
16687 KeyCvlanPrio(u8),
16688 KeyCvlanEthType(u16),
16689 KeyEncIpTos(u8),
16690 KeyEncIpTosMask(u8),
16691 KeyEncIpTtl(u8),
16692 KeyEncIpTtlMask(u8),
16693 KeyEncOpts(IterableFlowerKeyEncOptsAttrs<'a>),
16694 KeyEncOptsMask(IterableFlowerKeyEncOptsAttrs<'a>),
16695 InHwCount(u32),
16696 KeyPortSrcMin(u16),
16697 KeyPortSrcMax(u16),
16698 KeyPortDstMin(u16),
16699 KeyPortDstMax(u16),
16700 KeyCtState(u16),
16701 KeyCtStateMask(u16),
16702 KeyCtZone(u16),
16703 KeyCtZoneMask(u16),
16704 KeyCtMark(u32),
16705 KeyCtMarkMask(u32),
16706 KeyCtLabels(&'a [u8]),
16707 KeyCtLabelsMask(&'a [u8]),
16708 KeyMplsOpts(IterableFlowerKeyMplsOptAttrs<'a>),
16709 KeyHash(u32),
16710 KeyHashMask(u32),
16711 KeyNumOfVlans(u8),
16712 KeyPppoeSid(u16),
16713 KeyPppProto(u16),
16714 KeyL2tpv3Sid(u32),
16715 L2Miss(u8),
16716 KeyCfm(IterableFlowerKeyCfmAttrs<'a>),
16717 KeySpi(u32),
16718 KeySpiMask(u32),
16719 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
16720 KeyEncFlags(u32),
16721 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
16722 KeyEncFlagsMask(u32),
16723}
16724impl<'a> IterableFlowerAttrs<'a> {
16725 pub fn get_classid(&self) -> Result<u32, ErrorContext> {
16726 let mut iter = self.clone();
16727 iter.pos = 0;
16728 for attr in iter {
16729 if let Ok(FlowerAttrs::Classid(val)) = attr {
16730 return Ok(val);
16731 }
16732 }
16733 Err(ErrorContext::new_missing(
16734 "FlowerAttrs",
16735 "Classid",
16736 self.orig_loc,
16737 self.buf.as_ptr() as usize,
16738 ))
16739 }
16740 pub fn get_indev(&self) -> Result<&'a CStr, ErrorContext> {
16741 let mut iter = self.clone();
16742 iter.pos = 0;
16743 for attr in iter {
16744 if let Ok(FlowerAttrs::Indev(val)) = attr {
16745 return Ok(val);
16746 }
16747 }
16748 Err(ErrorContext::new_missing(
16749 "FlowerAttrs",
16750 "Indev",
16751 self.orig_loc,
16752 self.buf.as_ptr() as usize,
16753 ))
16754 }
16755 pub fn get_act(
16756 &self,
16757 ) -> Result<ArrayIterable<IterableArrayActAttrs<'a>, IterableActAttrs<'a>>, ErrorContext> {
16758 for attr in self.clone() {
16759 if let Ok(FlowerAttrs::Act(val)) = attr {
16760 return Ok(ArrayIterable::new(val));
16761 }
16762 }
16763 Err(ErrorContext::new_missing(
16764 "FlowerAttrs",
16765 "Act",
16766 self.orig_loc,
16767 self.buf.as_ptr() as usize,
16768 ))
16769 }
16770 pub fn get_key_eth_dst(&self) -> Result<&'a [u8], ErrorContext> {
16771 let mut iter = self.clone();
16772 iter.pos = 0;
16773 for attr in iter {
16774 if let Ok(FlowerAttrs::KeyEthDst(val)) = attr {
16775 return Ok(val);
16776 }
16777 }
16778 Err(ErrorContext::new_missing(
16779 "FlowerAttrs",
16780 "KeyEthDst",
16781 self.orig_loc,
16782 self.buf.as_ptr() as usize,
16783 ))
16784 }
16785 pub fn get_key_eth_dst_mask(&self) -> Result<&'a [u8], ErrorContext> {
16786 let mut iter = self.clone();
16787 iter.pos = 0;
16788 for attr in iter {
16789 if let Ok(FlowerAttrs::KeyEthDstMask(val)) = attr {
16790 return Ok(val);
16791 }
16792 }
16793 Err(ErrorContext::new_missing(
16794 "FlowerAttrs",
16795 "KeyEthDstMask",
16796 self.orig_loc,
16797 self.buf.as_ptr() as usize,
16798 ))
16799 }
16800 pub fn get_key_eth_src(&self) -> Result<&'a [u8], ErrorContext> {
16801 let mut iter = self.clone();
16802 iter.pos = 0;
16803 for attr in iter {
16804 if let Ok(FlowerAttrs::KeyEthSrc(val)) = attr {
16805 return Ok(val);
16806 }
16807 }
16808 Err(ErrorContext::new_missing(
16809 "FlowerAttrs",
16810 "KeyEthSrc",
16811 self.orig_loc,
16812 self.buf.as_ptr() as usize,
16813 ))
16814 }
16815 pub fn get_key_eth_src_mask(&self) -> Result<&'a [u8], ErrorContext> {
16816 let mut iter = self.clone();
16817 iter.pos = 0;
16818 for attr in iter {
16819 if let Ok(FlowerAttrs::KeyEthSrcMask(val)) = attr {
16820 return Ok(val);
16821 }
16822 }
16823 Err(ErrorContext::new_missing(
16824 "FlowerAttrs",
16825 "KeyEthSrcMask",
16826 self.orig_loc,
16827 self.buf.as_ptr() as usize,
16828 ))
16829 }
16830 pub fn get_key_eth_type(&self) -> Result<u16, ErrorContext> {
16831 let mut iter = self.clone();
16832 iter.pos = 0;
16833 for attr in iter {
16834 if let Ok(FlowerAttrs::KeyEthType(val)) = attr {
16835 return Ok(val);
16836 }
16837 }
16838 Err(ErrorContext::new_missing(
16839 "FlowerAttrs",
16840 "KeyEthType",
16841 self.orig_loc,
16842 self.buf.as_ptr() as usize,
16843 ))
16844 }
16845 pub fn get_key_ip_proto(&self) -> Result<u8, ErrorContext> {
16846 let mut iter = self.clone();
16847 iter.pos = 0;
16848 for attr in iter {
16849 if let Ok(FlowerAttrs::KeyIpProto(val)) = attr {
16850 return Ok(val);
16851 }
16852 }
16853 Err(ErrorContext::new_missing(
16854 "FlowerAttrs",
16855 "KeyIpProto",
16856 self.orig_loc,
16857 self.buf.as_ptr() as usize,
16858 ))
16859 }
16860 pub fn get_key_ipv4_src(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
16861 let mut iter = self.clone();
16862 iter.pos = 0;
16863 for attr in iter {
16864 if let Ok(FlowerAttrs::KeyIpv4Src(val)) = attr {
16865 return Ok(val);
16866 }
16867 }
16868 Err(ErrorContext::new_missing(
16869 "FlowerAttrs",
16870 "KeyIpv4Src",
16871 self.orig_loc,
16872 self.buf.as_ptr() as usize,
16873 ))
16874 }
16875 pub fn get_key_ipv4_src_mask(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
16876 let mut iter = self.clone();
16877 iter.pos = 0;
16878 for attr in iter {
16879 if let Ok(FlowerAttrs::KeyIpv4SrcMask(val)) = attr {
16880 return Ok(val);
16881 }
16882 }
16883 Err(ErrorContext::new_missing(
16884 "FlowerAttrs",
16885 "KeyIpv4SrcMask",
16886 self.orig_loc,
16887 self.buf.as_ptr() as usize,
16888 ))
16889 }
16890 pub fn get_key_ipv4_dst(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
16891 let mut iter = self.clone();
16892 iter.pos = 0;
16893 for attr in iter {
16894 if let Ok(FlowerAttrs::KeyIpv4Dst(val)) = attr {
16895 return Ok(val);
16896 }
16897 }
16898 Err(ErrorContext::new_missing(
16899 "FlowerAttrs",
16900 "KeyIpv4Dst",
16901 self.orig_loc,
16902 self.buf.as_ptr() as usize,
16903 ))
16904 }
16905 pub fn get_key_ipv4_dst_mask(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
16906 let mut iter = self.clone();
16907 iter.pos = 0;
16908 for attr in iter {
16909 if let Ok(FlowerAttrs::KeyIpv4DstMask(val)) = attr {
16910 return Ok(val);
16911 }
16912 }
16913 Err(ErrorContext::new_missing(
16914 "FlowerAttrs",
16915 "KeyIpv4DstMask",
16916 self.orig_loc,
16917 self.buf.as_ptr() as usize,
16918 ))
16919 }
16920 pub fn get_key_ipv6_src(&self) -> Result<&'a [u8], ErrorContext> {
16921 let mut iter = self.clone();
16922 iter.pos = 0;
16923 for attr in iter {
16924 if let Ok(FlowerAttrs::KeyIpv6Src(val)) = attr {
16925 return Ok(val);
16926 }
16927 }
16928 Err(ErrorContext::new_missing(
16929 "FlowerAttrs",
16930 "KeyIpv6Src",
16931 self.orig_loc,
16932 self.buf.as_ptr() as usize,
16933 ))
16934 }
16935 pub fn get_key_ipv6_src_mask(&self) -> Result<&'a [u8], ErrorContext> {
16936 let mut iter = self.clone();
16937 iter.pos = 0;
16938 for attr in iter {
16939 if let Ok(FlowerAttrs::KeyIpv6SrcMask(val)) = attr {
16940 return Ok(val);
16941 }
16942 }
16943 Err(ErrorContext::new_missing(
16944 "FlowerAttrs",
16945 "KeyIpv6SrcMask",
16946 self.orig_loc,
16947 self.buf.as_ptr() as usize,
16948 ))
16949 }
16950 pub fn get_key_ipv6_dst(&self) -> Result<&'a [u8], ErrorContext> {
16951 let mut iter = self.clone();
16952 iter.pos = 0;
16953 for attr in iter {
16954 if let Ok(FlowerAttrs::KeyIpv6Dst(val)) = attr {
16955 return Ok(val);
16956 }
16957 }
16958 Err(ErrorContext::new_missing(
16959 "FlowerAttrs",
16960 "KeyIpv6Dst",
16961 self.orig_loc,
16962 self.buf.as_ptr() as usize,
16963 ))
16964 }
16965 pub fn get_key_ipv6_dst_mask(&self) -> Result<&'a [u8], ErrorContext> {
16966 let mut iter = self.clone();
16967 iter.pos = 0;
16968 for attr in iter {
16969 if let Ok(FlowerAttrs::KeyIpv6DstMask(val)) = attr {
16970 return Ok(val);
16971 }
16972 }
16973 Err(ErrorContext::new_missing(
16974 "FlowerAttrs",
16975 "KeyIpv6DstMask",
16976 self.orig_loc,
16977 self.buf.as_ptr() as usize,
16978 ))
16979 }
16980 pub fn get_key_tcp_src(&self) -> Result<u16, ErrorContext> {
16981 let mut iter = self.clone();
16982 iter.pos = 0;
16983 for attr in iter {
16984 if let Ok(FlowerAttrs::KeyTcpSrc(val)) = attr {
16985 return Ok(val);
16986 }
16987 }
16988 Err(ErrorContext::new_missing(
16989 "FlowerAttrs",
16990 "KeyTcpSrc",
16991 self.orig_loc,
16992 self.buf.as_ptr() as usize,
16993 ))
16994 }
16995 pub fn get_key_tcp_dst(&self) -> Result<u16, ErrorContext> {
16996 let mut iter = self.clone();
16997 iter.pos = 0;
16998 for attr in iter {
16999 if let Ok(FlowerAttrs::KeyTcpDst(val)) = attr {
17000 return Ok(val);
17001 }
17002 }
17003 Err(ErrorContext::new_missing(
17004 "FlowerAttrs",
17005 "KeyTcpDst",
17006 self.orig_loc,
17007 self.buf.as_ptr() as usize,
17008 ))
17009 }
17010 pub fn get_key_udp_src(&self) -> Result<u16, ErrorContext> {
17011 let mut iter = self.clone();
17012 iter.pos = 0;
17013 for attr in iter {
17014 if let Ok(FlowerAttrs::KeyUdpSrc(val)) = attr {
17015 return Ok(val);
17016 }
17017 }
17018 Err(ErrorContext::new_missing(
17019 "FlowerAttrs",
17020 "KeyUdpSrc",
17021 self.orig_loc,
17022 self.buf.as_ptr() as usize,
17023 ))
17024 }
17025 pub fn get_key_udp_dst(&self) -> Result<u16, ErrorContext> {
17026 let mut iter = self.clone();
17027 iter.pos = 0;
17028 for attr in iter {
17029 if let Ok(FlowerAttrs::KeyUdpDst(val)) = attr {
17030 return Ok(val);
17031 }
17032 }
17033 Err(ErrorContext::new_missing(
17034 "FlowerAttrs",
17035 "KeyUdpDst",
17036 self.orig_loc,
17037 self.buf.as_ptr() as usize,
17038 ))
17039 }
17040 #[doc = "Associated type: [`ClsFlags`] (1 bit per enumeration)"]
17041 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
17042 let mut iter = self.clone();
17043 iter.pos = 0;
17044 for attr in iter {
17045 if let Ok(FlowerAttrs::Flags(val)) = attr {
17046 return Ok(val);
17047 }
17048 }
17049 Err(ErrorContext::new_missing(
17050 "FlowerAttrs",
17051 "Flags",
17052 self.orig_loc,
17053 self.buf.as_ptr() as usize,
17054 ))
17055 }
17056 pub fn get_key_vlan_id(&self) -> Result<u16, ErrorContext> {
17057 let mut iter = self.clone();
17058 iter.pos = 0;
17059 for attr in iter {
17060 if let Ok(FlowerAttrs::KeyVlanId(val)) = attr {
17061 return Ok(val);
17062 }
17063 }
17064 Err(ErrorContext::new_missing(
17065 "FlowerAttrs",
17066 "KeyVlanId",
17067 self.orig_loc,
17068 self.buf.as_ptr() as usize,
17069 ))
17070 }
17071 pub fn get_key_vlan_prio(&self) -> Result<u8, ErrorContext> {
17072 let mut iter = self.clone();
17073 iter.pos = 0;
17074 for attr in iter {
17075 if let Ok(FlowerAttrs::KeyVlanPrio(val)) = attr {
17076 return Ok(val);
17077 }
17078 }
17079 Err(ErrorContext::new_missing(
17080 "FlowerAttrs",
17081 "KeyVlanPrio",
17082 self.orig_loc,
17083 self.buf.as_ptr() as usize,
17084 ))
17085 }
17086 pub fn get_key_vlan_eth_type(&self) -> Result<u16, ErrorContext> {
17087 let mut iter = self.clone();
17088 iter.pos = 0;
17089 for attr in iter {
17090 if let Ok(FlowerAttrs::KeyVlanEthType(val)) = attr {
17091 return Ok(val);
17092 }
17093 }
17094 Err(ErrorContext::new_missing(
17095 "FlowerAttrs",
17096 "KeyVlanEthType",
17097 self.orig_loc,
17098 self.buf.as_ptr() as usize,
17099 ))
17100 }
17101 pub fn get_key_enc_key_id(&self) -> Result<u32, ErrorContext> {
17102 let mut iter = self.clone();
17103 iter.pos = 0;
17104 for attr in iter {
17105 if let Ok(FlowerAttrs::KeyEncKeyId(val)) = attr {
17106 return Ok(val);
17107 }
17108 }
17109 Err(ErrorContext::new_missing(
17110 "FlowerAttrs",
17111 "KeyEncKeyId",
17112 self.orig_loc,
17113 self.buf.as_ptr() as usize,
17114 ))
17115 }
17116 pub fn get_key_enc_ipv4_src(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
17117 let mut iter = self.clone();
17118 iter.pos = 0;
17119 for attr in iter {
17120 if let Ok(FlowerAttrs::KeyEncIpv4Src(val)) = attr {
17121 return Ok(val);
17122 }
17123 }
17124 Err(ErrorContext::new_missing(
17125 "FlowerAttrs",
17126 "KeyEncIpv4Src",
17127 self.orig_loc,
17128 self.buf.as_ptr() as usize,
17129 ))
17130 }
17131 pub fn get_key_enc_ipv4_src_mask(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
17132 let mut iter = self.clone();
17133 iter.pos = 0;
17134 for attr in iter {
17135 if let Ok(FlowerAttrs::KeyEncIpv4SrcMask(val)) = attr {
17136 return Ok(val);
17137 }
17138 }
17139 Err(ErrorContext::new_missing(
17140 "FlowerAttrs",
17141 "KeyEncIpv4SrcMask",
17142 self.orig_loc,
17143 self.buf.as_ptr() as usize,
17144 ))
17145 }
17146 pub fn get_key_enc_ipv4_dst(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
17147 let mut iter = self.clone();
17148 iter.pos = 0;
17149 for attr in iter {
17150 if let Ok(FlowerAttrs::KeyEncIpv4Dst(val)) = attr {
17151 return Ok(val);
17152 }
17153 }
17154 Err(ErrorContext::new_missing(
17155 "FlowerAttrs",
17156 "KeyEncIpv4Dst",
17157 self.orig_loc,
17158 self.buf.as_ptr() as usize,
17159 ))
17160 }
17161 pub fn get_key_enc_ipv4_dst_mask(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
17162 let mut iter = self.clone();
17163 iter.pos = 0;
17164 for attr in iter {
17165 if let Ok(FlowerAttrs::KeyEncIpv4DstMask(val)) = attr {
17166 return Ok(val);
17167 }
17168 }
17169 Err(ErrorContext::new_missing(
17170 "FlowerAttrs",
17171 "KeyEncIpv4DstMask",
17172 self.orig_loc,
17173 self.buf.as_ptr() as usize,
17174 ))
17175 }
17176 pub fn get_key_enc_ipv6_src(&self) -> Result<&'a [u8], ErrorContext> {
17177 let mut iter = self.clone();
17178 iter.pos = 0;
17179 for attr in iter {
17180 if let Ok(FlowerAttrs::KeyEncIpv6Src(val)) = attr {
17181 return Ok(val);
17182 }
17183 }
17184 Err(ErrorContext::new_missing(
17185 "FlowerAttrs",
17186 "KeyEncIpv6Src",
17187 self.orig_loc,
17188 self.buf.as_ptr() as usize,
17189 ))
17190 }
17191 pub fn get_key_enc_ipv6_src_mask(&self) -> Result<&'a [u8], ErrorContext> {
17192 let mut iter = self.clone();
17193 iter.pos = 0;
17194 for attr in iter {
17195 if let Ok(FlowerAttrs::KeyEncIpv6SrcMask(val)) = attr {
17196 return Ok(val);
17197 }
17198 }
17199 Err(ErrorContext::new_missing(
17200 "FlowerAttrs",
17201 "KeyEncIpv6SrcMask",
17202 self.orig_loc,
17203 self.buf.as_ptr() as usize,
17204 ))
17205 }
17206 pub fn get_key_enc_ipv6_dst(&self) -> Result<&'a [u8], ErrorContext> {
17207 let mut iter = self.clone();
17208 iter.pos = 0;
17209 for attr in iter {
17210 if let Ok(FlowerAttrs::KeyEncIpv6Dst(val)) = attr {
17211 return Ok(val);
17212 }
17213 }
17214 Err(ErrorContext::new_missing(
17215 "FlowerAttrs",
17216 "KeyEncIpv6Dst",
17217 self.orig_loc,
17218 self.buf.as_ptr() as usize,
17219 ))
17220 }
17221 pub fn get_key_enc_ipv6_dst_mask(&self) -> Result<&'a [u8], ErrorContext> {
17222 let mut iter = self.clone();
17223 iter.pos = 0;
17224 for attr in iter {
17225 if let Ok(FlowerAttrs::KeyEncIpv6DstMask(val)) = attr {
17226 return Ok(val);
17227 }
17228 }
17229 Err(ErrorContext::new_missing(
17230 "FlowerAttrs",
17231 "KeyEncIpv6DstMask",
17232 self.orig_loc,
17233 self.buf.as_ptr() as usize,
17234 ))
17235 }
17236 pub fn get_key_tcp_src_mask(&self) -> Result<u16, ErrorContext> {
17237 let mut iter = self.clone();
17238 iter.pos = 0;
17239 for attr in iter {
17240 if let Ok(FlowerAttrs::KeyTcpSrcMask(val)) = attr {
17241 return Ok(val);
17242 }
17243 }
17244 Err(ErrorContext::new_missing(
17245 "FlowerAttrs",
17246 "KeyTcpSrcMask",
17247 self.orig_loc,
17248 self.buf.as_ptr() as usize,
17249 ))
17250 }
17251 pub fn get_key_tcp_dst_mask(&self) -> Result<u16, ErrorContext> {
17252 let mut iter = self.clone();
17253 iter.pos = 0;
17254 for attr in iter {
17255 if let Ok(FlowerAttrs::KeyTcpDstMask(val)) = attr {
17256 return Ok(val);
17257 }
17258 }
17259 Err(ErrorContext::new_missing(
17260 "FlowerAttrs",
17261 "KeyTcpDstMask",
17262 self.orig_loc,
17263 self.buf.as_ptr() as usize,
17264 ))
17265 }
17266 pub fn get_key_udp_src_mask(&self) -> Result<u16, ErrorContext> {
17267 let mut iter = self.clone();
17268 iter.pos = 0;
17269 for attr in iter {
17270 if let Ok(FlowerAttrs::KeyUdpSrcMask(val)) = attr {
17271 return Ok(val);
17272 }
17273 }
17274 Err(ErrorContext::new_missing(
17275 "FlowerAttrs",
17276 "KeyUdpSrcMask",
17277 self.orig_loc,
17278 self.buf.as_ptr() as usize,
17279 ))
17280 }
17281 pub fn get_key_udp_dst_mask(&self) -> Result<u16, ErrorContext> {
17282 let mut iter = self.clone();
17283 iter.pos = 0;
17284 for attr in iter {
17285 if let Ok(FlowerAttrs::KeyUdpDstMask(val)) = attr {
17286 return Ok(val);
17287 }
17288 }
17289 Err(ErrorContext::new_missing(
17290 "FlowerAttrs",
17291 "KeyUdpDstMask",
17292 self.orig_loc,
17293 self.buf.as_ptr() as usize,
17294 ))
17295 }
17296 pub fn get_key_sctp_src_mask(&self) -> Result<u16, ErrorContext> {
17297 let mut iter = self.clone();
17298 iter.pos = 0;
17299 for attr in iter {
17300 if let Ok(FlowerAttrs::KeySctpSrcMask(val)) = attr {
17301 return Ok(val);
17302 }
17303 }
17304 Err(ErrorContext::new_missing(
17305 "FlowerAttrs",
17306 "KeySctpSrcMask",
17307 self.orig_loc,
17308 self.buf.as_ptr() as usize,
17309 ))
17310 }
17311 pub fn get_key_sctp_dst_mask(&self) -> Result<u16, ErrorContext> {
17312 let mut iter = self.clone();
17313 iter.pos = 0;
17314 for attr in iter {
17315 if let Ok(FlowerAttrs::KeySctpDstMask(val)) = attr {
17316 return Ok(val);
17317 }
17318 }
17319 Err(ErrorContext::new_missing(
17320 "FlowerAttrs",
17321 "KeySctpDstMask",
17322 self.orig_loc,
17323 self.buf.as_ptr() as usize,
17324 ))
17325 }
17326 pub fn get_key_sctp_src(&self) -> Result<u16, ErrorContext> {
17327 let mut iter = self.clone();
17328 iter.pos = 0;
17329 for attr in iter {
17330 if let Ok(FlowerAttrs::KeySctpSrc(val)) = attr {
17331 return Ok(val);
17332 }
17333 }
17334 Err(ErrorContext::new_missing(
17335 "FlowerAttrs",
17336 "KeySctpSrc",
17337 self.orig_loc,
17338 self.buf.as_ptr() as usize,
17339 ))
17340 }
17341 pub fn get_key_sctp_dst(&self) -> Result<u16, ErrorContext> {
17342 let mut iter = self.clone();
17343 iter.pos = 0;
17344 for attr in iter {
17345 if let Ok(FlowerAttrs::KeySctpDst(val)) = attr {
17346 return Ok(val);
17347 }
17348 }
17349 Err(ErrorContext::new_missing(
17350 "FlowerAttrs",
17351 "KeySctpDst",
17352 self.orig_loc,
17353 self.buf.as_ptr() as usize,
17354 ))
17355 }
17356 pub fn get_key_enc_udp_src_port(&self) -> Result<u16, ErrorContext> {
17357 let mut iter = self.clone();
17358 iter.pos = 0;
17359 for attr in iter {
17360 if let Ok(FlowerAttrs::KeyEncUdpSrcPort(val)) = attr {
17361 return Ok(val);
17362 }
17363 }
17364 Err(ErrorContext::new_missing(
17365 "FlowerAttrs",
17366 "KeyEncUdpSrcPort",
17367 self.orig_loc,
17368 self.buf.as_ptr() as usize,
17369 ))
17370 }
17371 pub fn get_key_enc_udp_src_port_mask(&self) -> Result<u16, ErrorContext> {
17372 let mut iter = self.clone();
17373 iter.pos = 0;
17374 for attr in iter {
17375 if let Ok(FlowerAttrs::KeyEncUdpSrcPortMask(val)) = attr {
17376 return Ok(val);
17377 }
17378 }
17379 Err(ErrorContext::new_missing(
17380 "FlowerAttrs",
17381 "KeyEncUdpSrcPortMask",
17382 self.orig_loc,
17383 self.buf.as_ptr() as usize,
17384 ))
17385 }
17386 pub fn get_key_enc_udp_dst_port(&self) -> Result<u16, ErrorContext> {
17387 let mut iter = self.clone();
17388 iter.pos = 0;
17389 for attr in iter {
17390 if let Ok(FlowerAttrs::KeyEncUdpDstPort(val)) = attr {
17391 return Ok(val);
17392 }
17393 }
17394 Err(ErrorContext::new_missing(
17395 "FlowerAttrs",
17396 "KeyEncUdpDstPort",
17397 self.orig_loc,
17398 self.buf.as_ptr() as usize,
17399 ))
17400 }
17401 pub fn get_key_enc_udp_dst_port_mask(&self) -> Result<u16, ErrorContext> {
17402 let mut iter = self.clone();
17403 iter.pos = 0;
17404 for attr in iter {
17405 if let Ok(FlowerAttrs::KeyEncUdpDstPortMask(val)) = attr {
17406 return Ok(val);
17407 }
17408 }
17409 Err(ErrorContext::new_missing(
17410 "FlowerAttrs",
17411 "KeyEncUdpDstPortMask",
17412 self.orig_loc,
17413 self.buf.as_ptr() as usize,
17414 ))
17415 }
17416 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
17417 pub fn get_key_flags(&self) -> Result<u32, ErrorContext> {
17418 let mut iter = self.clone();
17419 iter.pos = 0;
17420 for attr in iter {
17421 if let Ok(FlowerAttrs::KeyFlags(val)) = attr {
17422 return Ok(val);
17423 }
17424 }
17425 Err(ErrorContext::new_missing(
17426 "FlowerAttrs",
17427 "KeyFlags",
17428 self.orig_loc,
17429 self.buf.as_ptr() as usize,
17430 ))
17431 }
17432 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
17433 pub fn get_key_flags_mask(&self) -> Result<u32, ErrorContext> {
17434 let mut iter = self.clone();
17435 iter.pos = 0;
17436 for attr in iter {
17437 if let Ok(FlowerAttrs::KeyFlagsMask(val)) = attr {
17438 return Ok(val);
17439 }
17440 }
17441 Err(ErrorContext::new_missing(
17442 "FlowerAttrs",
17443 "KeyFlagsMask",
17444 self.orig_loc,
17445 self.buf.as_ptr() as usize,
17446 ))
17447 }
17448 pub fn get_key_icmpv4_code(&self) -> Result<u8, ErrorContext> {
17449 let mut iter = self.clone();
17450 iter.pos = 0;
17451 for attr in iter {
17452 if let Ok(FlowerAttrs::KeyIcmpv4Code(val)) = attr {
17453 return Ok(val);
17454 }
17455 }
17456 Err(ErrorContext::new_missing(
17457 "FlowerAttrs",
17458 "KeyIcmpv4Code",
17459 self.orig_loc,
17460 self.buf.as_ptr() as usize,
17461 ))
17462 }
17463 pub fn get_key_icmpv4_code_mask(&self) -> Result<u8, ErrorContext> {
17464 let mut iter = self.clone();
17465 iter.pos = 0;
17466 for attr in iter {
17467 if let Ok(FlowerAttrs::KeyIcmpv4CodeMask(val)) = attr {
17468 return Ok(val);
17469 }
17470 }
17471 Err(ErrorContext::new_missing(
17472 "FlowerAttrs",
17473 "KeyIcmpv4CodeMask",
17474 self.orig_loc,
17475 self.buf.as_ptr() as usize,
17476 ))
17477 }
17478 pub fn get_key_icmpv4_type(&self) -> Result<u8, ErrorContext> {
17479 let mut iter = self.clone();
17480 iter.pos = 0;
17481 for attr in iter {
17482 if let Ok(FlowerAttrs::KeyIcmpv4Type(val)) = attr {
17483 return Ok(val);
17484 }
17485 }
17486 Err(ErrorContext::new_missing(
17487 "FlowerAttrs",
17488 "KeyIcmpv4Type",
17489 self.orig_loc,
17490 self.buf.as_ptr() as usize,
17491 ))
17492 }
17493 pub fn get_key_icmpv4_type_mask(&self) -> Result<u8, ErrorContext> {
17494 let mut iter = self.clone();
17495 iter.pos = 0;
17496 for attr in iter {
17497 if let Ok(FlowerAttrs::KeyIcmpv4TypeMask(val)) = attr {
17498 return Ok(val);
17499 }
17500 }
17501 Err(ErrorContext::new_missing(
17502 "FlowerAttrs",
17503 "KeyIcmpv4TypeMask",
17504 self.orig_loc,
17505 self.buf.as_ptr() as usize,
17506 ))
17507 }
17508 pub fn get_key_icmpv6_code(&self) -> Result<u8, ErrorContext> {
17509 let mut iter = self.clone();
17510 iter.pos = 0;
17511 for attr in iter {
17512 if let Ok(FlowerAttrs::KeyIcmpv6Code(val)) = attr {
17513 return Ok(val);
17514 }
17515 }
17516 Err(ErrorContext::new_missing(
17517 "FlowerAttrs",
17518 "KeyIcmpv6Code",
17519 self.orig_loc,
17520 self.buf.as_ptr() as usize,
17521 ))
17522 }
17523 pub fn get_key_icmpv6_code_mask(&self) -> Result<u8, ErrorContext> {
17524 let mut iter = self.clone();
17525 iter.pos = 0;
17526 for attr in iter {
17527 if let Ok(FlowerAttrs::KeyIcmpv6CodeMask(val)) = attr {
17528 return Ok(val);
17529 }
17530 }
17531 Err(ErrorContext::new_missing(
17532 "FlowerAttrs",
17533 "KeyIcmpv6CodeMask",
17534 self.orig_loc,
17535 self.buf.as_ptr() as usize,
17536 ))
17537 }
17538 pub fn get_key_icmpv6_type(&self) -> Result<u8, ErrorContext> {
17539 let mut iter = self.clone();
17540 iter.pos = 0;
17541 for attr in iter {
17542 if let Ok(FlowerAttrs::KeyIcmpv6Type(val)) = attr {
17543 return Ok(val);
17544 }
17545 }
17546 Err(ErrorContext::new_missing(
17547 "FlowerAttrs",
17548 "KeyIcmpv6Type",
17549 self.orig_loc,
17550 self.buf.as_ptr() as usize,
17551 ))
17552 }
17553 pub fn get_key_icmpv6_type_mask(&self) -> Result<u8, ErrorContext> {
17554 let mut iter = self.clone();
17555 iter.pos = 0;
17556 for attr in iter {
17557 if let Ok(FlowerAttrs::KeyIcmpv6TypeMask(val)) = attr {
17558 return Ok(val);
17559 }
17560 }
17561 Err(ErrorContext::new_missing(
17562 "FlowerAttrs",
17563 "KeyIcmpv6TypeMask",
17564 self.orig_loc,
17565 self.buf.as_ptr() as usize,
17566 ))
17567 }
17568 pub fn get_key_arp_sip(&self) -> Result<u32, ErrorContext> {
17569 let mut iter = self.clone();
17570 iter.pos = 0;
17571 for attr in iter {
17572 if let Ok(FlowerAttrs::KeyArpSip(val)) = attr {
17573 return Ok(val);
17574 }
17575 }
17576 Err(ErrorContext::new_missing(
17577 "FlowerAttrs",
17578 "KeyArpSip",
17579 self.orig_loc,
17580 self.buf.as_ptr() as usize,
17581 ))
17582 }
17583 pub fn get_key_arp_sip_mask(&self) -> Result<u32, ErrorContext> {
17584 let mut iter = self.clone();
17585 iter.pos = 0;
17586 for attr in iter {
17587 if let Ok(FlowerAttrs::KeyArpSipMask(val)) = attr {
17588 return Ok(val);
17589 }
17590 }
17591 Err(ErrorContext::new_missing(
17592 "FlowerAttrs",
17593 "KeyArpSipMask",
17594 self.orig_loc,
17595 self.buf.as_ptr() as usize,
17596 ))
17597 }
17598 pub fn get_key_arp_tip(&self) -> Result<u32, ErrorContext> {
17599 let mut iter = self.clone();
17600 iter.pos = 0;
17601 for attr in iter {
17602 if let Ok(FlowerAttrs::KeyArpTip(val)) = attr {
17603 return Ok(val);
17604 }
17605 }
17606 Err(ErrorContext::new_missing(
17607 "FlowerAttrs",
17608 "KeyArpTip",
17609 self.orig_loc,
17610 self.buf.as_ptr() as usize,
17611 ))
17612 }
17613 pub fn get_key_arp_tip_mask(&self) -> Result<u32, ErrorContext> {
17614 let mut iter = self.clone();
17615 iter.pos = 0;
17616 for attr in iter {
17617 if let Ok(FlowerAttrs::KeyArpTipMask(val)) = attr {
17618 return Ok(val);
17619 }
17620 }
17621 Err(ErrorContext::new_missing(
17622 "FlowerAttrs",
17623 "KeyArpTipMask",
17624 self.orig_loc,
17625 self.buf.as_ptr() as usize,
17626 ))
17627 }
17628 pub fn get_key_arp_op(&self) -> Result<u8, ErrorContext> {
17629 let mut iter = self.clone();
17630 iter.pos = 0;
17631 for attr in iter {
17632 if let Ok(FlowerAttrs::KeyArpOp(val)) = attr {
17633 return Ok(val);
17634 }
17635 }
17636 Err(ErrorContext::new_missing(
17637 "FlowerAttrs",
17638 "KeyArpOp",
17639 self.orig_loc,
17640 self.buf.as_ptr() as usize,
17641 ))
17642 }
17643 pub fn get_key_arp_op_mask(&self) -> Result<u8, ErrorContext> {
17644 let mut iter = self.clone();
17645 iter.pos = 0;
17646 for attr in iter {
17647 if let Ok(FlowerAttrs::KeyArpOpMask(val)) = attr {
17648 return Ok(val);
17649 }
17650 }
17651 Err(ErrorContext::new_missing(
17652 "FlowerAttrs",
17653 "KeyArpOpMask",
17654 self.orig_loc,
17655 self.buf.as_ptr() as usize,
17656 ))
17657 }
17658 pub fn get_key_arp_sha(&self) -> Result<&'a [u8], ErrorContext> {
17659 let mut iter = self.clone();
17660 iter.pos = 0;
17661 for attr in iter {
17662 if let Ok(FlowerAttrs::KeyArpSha(val)) = attr {
17663 return Ok(val);
17664 }
17665 }
17666 Err(ErrorContext::new_missing(
17667 "FlowerAttrs",
17668 "KeyArpSha",
17669 self.orig_loc,
17670 self.buf.as_ptr() as usize,
17671 ))
17672 }
17673 pub fn get_key_arp_sha_mask(&self) -> Result<&'a [u8], ErrorContext> {
17674 let mut iter = self.clone();
17675 iter.pos = 0;
17676 for attr in iter {
17677 if let Ok(FlowerAttrs::KeyArpShaMask(val)) = attr {
17678 return Ok(val);
17679 }
17680 }
17681 Err(ErrorContext::new_missing(
17682 "FlowerAttrs",
17683 "KeyArpShaMask",
17684 self.orig_loc,
17685 self.buf.as_ptr() as usize,
17686 ))
17687 }
17688 pub fn get_key_arp_tha(&self) -> Result<&'a [u8], ErrorContext> {
17689 let mut iter = self.clone();
17690 iter.pos = 0;
17691 for attr in iter {
17692 if let Ok(FlowerAttrs::KeyArpTha(val)) = attr {
17693 return Ok(val);
17694 }
17695 }
17696 Err(ErrorContext::new_missing(
17697 "FlowerAttrs",
17698 "KeyArpTha",
17699 self.orig_loc,
17700 self.buf.as_ptr() as usize,
17701 ))
17702 }
17703 pub fn get_key_arp_tha_mask(&self) -> Result<&'a [u8], ErrorContext> {
17704 let mut iter = self.clone();
17705 iter.pos = 0;
17706 for attr in iter {
17707 if let Ok(FlowerAttrs::KeyArpThaMask(val)) = attr {
17708 return Ok(val);
17709 }
17710 }
17711 Err(ErrorContext::new_missing(
17712 "FlowerAttrs",
17713 "KeyArpThaMask",
17714 self.orig_loc,
17715 self.buf.as_ptr() as usize,
17716 ))
17717 }
17718 pub fn get_key_mpls_ttl(&self) -> Result<u8, ErrorContext> {
17719 let mut iter = self.clone();
17720 iter.pos = 0;
17721 for attr in iter {
17722 if let Ok(FlowerAttrs::KeyMplsTtl(val)) = attr {
17723 return Ok(val);
17724 }
17725 }
17726 Err(ErrorContext::new_missing(
17727 "FlowerAttrs",
17728 "KeyMplsTtl",
17729 self.orig_loc,
17730 self.buf.as_ptr() as usize,
17731 ))
17732 }
17733 pub fn get_key_mpls_bos(&self) -> Result<u8, ErrorContext> {
17734 let mut iter = self.clone();
17735 iter.pos = 0;
17736 for attr in iter {
17737 if let Ok(FlowerAttrs::KeyMplsBos(val)) = attr {
17738 return Ok(val);
17739 }
17740 }
17741 Err(ErrorContext::new_missing(
17742 "FlowerAttrs",
17743 "KeyMplsBos",
17744 self.orig_loc,
17745 self.buf.as_ptr() as usize,
17746 ))
17747 }
17748 pub fn get_key_mpls_tc(&self) -> Result<u8, ErrorContext> {
17749 let mut iter = self.clone();
17750 iter.pos = 0;
17751 for attr in iter {
17752 if let Ok(FlowerAttrs::KeyMplsTc(val)) = attr {
17753 return Ok(val);
17754 }
17755 }
17756 Err(ErrorContext::new_missing(
17757 "FlowerAttrs",
17758 "KeyMplsTc",
17759 self.orig_loc,
17760 self.buf.as_ptr() as usize,
17761 ))
17762 }
17763 pub fn get_key_mpls_label(&self) -> Result<u32, ErrorContext> {
17764 let mut iter = self.clone();
17765 iter.pos = 0;
17766 for attr in iter {
17767 if let Ok(FlowerAttrs::KeyMplsLabel(val)) = attr {
17768 return Ok(val);
17769 }
17770 }
17771 Err(ErrorContext::new_missing(
17772 "FlowerAttrs",
17773 "KeyMplsLabel",
17774 self.orig_loc,
17775 self.buf.as_ptr() as usize,
17776 ))
17777 }
17778 pub fn get_key_tcp_flags(&self) -> Result<u16, ErrorContext> {
17779 let mut iter = self.clone();
17780 iter.pos = 0;
17781 for attr in iter {
17782 if let Ok(FlowerAttrs::KeyTcpFlags(val)) = attr {
17783 return Ok(val);
17784 }
17785 }
17786 Err(ErrorContext::new_missing(
17787 "FlowerAttrs",
17788 "KeyTcpFlags",
17789 self.orig_loc,
17790 self.buf.as_ptr() as usize,
17791 ))
17792 }
17793 pub fn get_key_tcp_flags_mask(&self) -> Result<u16, ErrorContext> {
17794 let mut iter = self.clone();
17795 iter.pos = 0;
17796 for attr in iter {
17797 if let Ok(FlowerAttrs::KeyTcpFlagsMask(val)) = attr {
17798 return Ok(val);
17799 }
17800 }
17801 Err(ErrorContext::new_missing(
17802 "FlowerAttrs",
17803 "KeyTcpFlagsMask",
17804 self.orig_loc,
17805 self.buf.as_ptr() as usize,
17806 ))
17807 }
17808 pub fn get_key_ip_tos(&self) -> Result<u8, ErrorContext> {
17809 let mut iter = self.clone();
17810 iter.pos = 0;
17811 for attr in iter {
17812 if let Ok(FlowerAttrs::KeyIpTos(val)) = attr {
17813 return Ok(val);
17814 }
17815 }
17816 Err(ErrorContext::new_missing(
17817 "FlowerAttrs",
17818 "KeyIpTos",
17819 self.orig_loc,
17820 self.buf.as_ptr() as usize,
17821 ))
17822 }
17823 pub fn get_key_ip_tos_mask(&self) -> Result<u8, ErrorContext> {
17824 let mut iter = self.clone();
17825 iter.pos = 0;
17826 for attr in iter {
17827 if let Ok(FlowerAttrs::KeyIpTosMask(val)) = attr {
17828 return Ok(val);
17829 }
17830 }
17831 Err(ErrorContext::new_missing(
17832 "FlowerAttrs",
17833 "KeyIpTosMask",
17834 self.orig_loc,
17835 self.buf.as_ptr() as usize,
17836 ))
17837 }
17838 pub fn get_key_ip_ttl(&self) -> Result<u8, ErrorContext> {
17839 let mut iter = self.clone();
17840 iter.pos = 0;
17841 for attr in iter {
17842 if let Ok(FlowerAttrs::KeyIpTtl(val)) = attr {
17843 return Ok(val);
17844 }
17845 }
17846 Err(ErrorContext::new_missing(
17847 "FlowerAttrs",
17848 "KeyIpTtl",
17849 self.orig_loc,
17850 self.buf.as_ptr() as usize,
17851 ))
17852 }
17853 pub fn get_key_ip_ttl_mask(&self) -> Result<u8, ErrorContext> {
17854 let mut iter = self.clone();
17855 iter.pos = 0;
17856 for attr in iter {
17857 if let Ok(FlowerAttrs::KeyIpTtlMask(val)) = attr {
17858 return Ok(val);
17859 }
17860 }
17861 Err(ErrorContext::new_missing(
17862 "FlowerAttrs",
17863 "KeyIpTtlMask",
17864 self.orig_loc,
17865 self.buf.as_ptr() as usize,
17866 ))
17867 }
17868 pub fn get_key_cvlan_id(&self) -> Result<u16, ErrorContext> {
17869 let mut iter = self.clone();
17870 iter.pos = 0;
17871 for attr in iter {
17872 if let Ok(FlowerAttrs::KeyCvlanId(val)) = attr {
17873 return Ok(val);
17874 }
17875 }
17876 Err(ErrorContext::new_missing(
17877 "FlowerAttrs",
17878 "KeyCvlanId",
17879 self.orig_loc,
17880 self.buf.as_ptr() as usize,
17881 ))
17882 }
17883 pub fn get_key_cvlan_prio(&self) -> Result<u8, ErrorContext> {
17884 let mut iter = self.clone();
17885 iter.pos = 0;
17886 for attr in iter {
17887 if let Ok(FlowerAttrs::KeyCvlanPrio(val)) = attr {
17888 return Ok(val);
17889 }
17890 }
17891 Err(ErrorContext::new_missing(
17892 "FlowerAttrs",
17893 "KeyCvlanPrio",
17894 self.orig_loc,
17895 self.buf.as_ptr() as usize,
17896 ))
17897 }
17898 pub fn get_key_cvlan_eth_type(&self) -> Result<u16, ErrorContext> {
17899 let mut iter = self.clone();
17900 iter.pos = 0;
17901 for attr in iter {
17902 if let Ok(FlowerAttrs::KeyCvlanEthType(val)) = attr {
17903 return Ok(val);
17904 }
17905 }
17906 Err(ErrorContext::new_missing(
17907 "FlowerAttrs",
17908 "KeyCvlanEthType",
17909 self.orig_loc,
17910 self.buf.as_ptr() as usize,
17911 ))
17912 }
17913 pub fn get_key_enc_ip_tos(&self) -> Result<u8, ErrorContext> {
17914 let mut iter = self.clone();
17915 iter.pos = 0;
17916 for attr in iter {
17917 if let Ok(FlowerAttrs::KeyEncIpTos(val)) = attr {
17918 return Ok(val);
17919 }
17920 }
17921 Err(ErrorContext::new_missing(
17922 "FlowerAttrs",
17923 "KeyEncIpTos",
17924 self.orig_loc,
17925 self.buf.as_ptr() as usize,
17926 ))
17927 }
17928 pub fn get_key_enc_ip_tos_mask(&self) -> Result<u8, ErrorContext> {
17929 let mut iter = self.clone();
17930 iter.pos = 0;
17931 for attr in iter {
17932 if let Ok(FlowerAttrs::KeyEncIpTosMask(val)) = attr {
17933 return Ok(val);
17934 }
17935 }
17936 Err(ErrorContext::new_missing(
17937 "FlowerAttrs",
17938 "KeyEncIpTosMask",
17939 self.orig_loc,
17940 self.buf.as_ptr() as usize,
17941 ))
17942 }
17943 pub fn get_key_enc_ip_ttl(&self) -> Result<u8, ErrorContext> {
17944 let mut iter = self.clone();
17945 iter.pos = 0;
17946 for attr in iter {
17947 if let Ok(FlowerAttrs::KeyEncIpTtl(val)) = attr {
17948 return Ok(val);
17949 }
17950 }
17951 Err(ErrorContext::new_missing(
17952 "FlowerAttrs",
17953 "KeyEncIpTtl",
17954 self.orig_loc,
17955 self.buf.as_ptr() as usize,
17956 ))
17957 }
17958 pub fn get_key_enc_ip_ttl_mask(&self) -> Result<u8, ErrorContext> {
17959 let mut iter = self.clone();
17960 iter.pos = 0;
17961 for attr in iter {
17962 if let Ok(FlowerAttrs::KeyEncIpTtlMask(val)) = attr {
17963 return Ok(val);
17964 }
17965 }
17966 Err(ErrorContext::new_missing(
17967 "FlowerAttrs",
17968 "KeyEncIpTtlMask",
17969 self.orig_loc,
17970 self.buf.as_ptr() as usize,
17971 ))
17972 }
17973 pub fn get_key_enc_opts(&self) -> Result<IterableFlowerKeyEncOptsAttrs<'a>, ErrorContext> {
17974 let mut iter = self.clone();
17975 iter.pos = 0;
17976 for attr in iter {
17977 if let Ok(FlowerAttrs::KeyEncOpts(val)) = attr {
17978 return Ok(val);
17979 }
17980 }
17981 Err(ErrorContext::new_missing(
17982 "FlowerAttrs",
17983 "KeyEncOpts",
17984 self.orig_loc,
17985 self.buf.as_ptr() as usize,
17986 ))
17987 }
17988 pub fn get_key_enc_opts_mask(&self) -> Result<IterableFlowerKeyEncOptsAttrs<'a>, ErrorContext> {
17989 let mut iter = self.clone();
17990 iter.pos = 0;
17991 for attr in iter {
17992 if let Ok(FlowerAttrs::KeyEncOptsMask(val)) = attr {
17993 return Ok(val);
17994 }
17995 }
17996 Err(ErrorContext::new_missing(
17997 "FlowerAttrs",
17998 "KeyEncOptsMask",
17999 self.orig_loc,
18000 self.buf.as_ptr() as usize,
18001 ))
18002 }
18003 pub fn get_in_hw_count(&self) -> Result<u32, ErrorContext> {
18004 let mut iter = self.clone();
18005 iter.pos = 0;
18006 for attr in iter {
18007 if let Ok(FlowerAttrs::InHwCount(val)) = attr {
18008 return Ok(val);
18009 }
18010 }
18011 Err(ErrorContext::new_missing(
18012 "FlowerAttrs",
18013 "InHwCount",
18014 self.orig_loc,
18015 self.buf.as_ptr() as usize,
18016 ))
18017 }
18018 pub fn get_key_port_src_min(&self) -> Result<u16, ErrorContext> {
18019 let mut iter = self.clone();
18020 iter.pos = 0;
18021 for attr in iter {
18022 if let Ok(FlowerAttrs::KeyPortSrcMin(val)) = attr {
18023 return Ok(val);
18024 }
18025 }
18026 Err(ErrorContext::new_missing(
18027 "FlowerAttrs",
18028 "KeyPortSrcMin",
18029 self.orig_loc,
18030 self.buf.as_ptr() as usize,
18031 ))
18032 }
18033 pub fn get_key_port_src_max(&self) -> Result<u16, ErrorContext> {
18034 let mut iter = self.clone();
18035 iter.pos = 0;
18036 for attr in iter {
18037 if let Ok(FlowerAttrs::KeyPortSrcMax(val)) = attr {
18038 return Ok(val);
18039 }
18040 }
18041 Err(ErrorContext::new_missing(
18042 "FlowerAttrs",
18043 "KeyPortSrcMax",
18044 self.orig_loc,
18045 self.buf.as_ptr() as usize,
18046 ))
18047 }
18048 pub fn get_key_port_dst_min(&self) -> Result<u16, ErrorContext> {
18049 let mut iter = self.clone();
18050 iter.pos = 0;
18051 for attr in iter {
18052 if let Ok(FlowerAttrs::KeyPortDstMin(val)) = attr {
18053 return Ok(val);
18054 }
18055 }
18056 Err(ErrorContext::new_missing(
18057 "FlowerAttrs",
18058 "KeyPortDstMin",
18059 self.orig_loc,
18060 self.buf.as_ptr() as usize,
18061 ))
18062 }
18063 pub fn get_key_port_dst_max(&self) -> Result<u16, ErrorContext> {
18064 let mut iter = self.clone();
18065 iter.pos = 0;
18066 for attr in iter {
18067 if let Ok(FlowerAttrs::KeyPortDstMax(val)) = attr {
18068 return Ok(val);
18069 }
18070 }
18071 Err(ErrorContext::new_missing(
18072 "FlowerAttrs",
18073 "KeyPortDstMax",
18074 self.orig_loc,
18075 self.buf.as_ptr() as usize,
18076 ))
18077 }
18078 pub fn get_key_ct_state(&self) -> Result<u16, ErrorContext> {
18079 let mut iter = self.clone();
18080 iter.pos = 0;
18081 for attr in iter {
18082 if let Ok(FlowerAttrs::KeyCtState(val)) = attr {
18083 return Ok(val);
18084 }
18085 }
18086 Err(ErrorContext::new_missing(
18087 "FlowerAttrs",
18088 "KeyCtState",
18089 self.orig_loc,
18090 self.buf.as_ptr() as usize,
18091 ))
18092 }
18093 pub fn get_key_ct_state_mask(&self) -> Result<u16, ErrorContext> {
18094 let mut iter = self.clone();
18095 iter.pos = 0;
18096 for attr in iter {
18097 if let Ok(FlowerAttrs::KeyCtStateMask(val)) = attr {
18098 return Ok(val);
18099 }
18100 }
18101 Err(ErrorContext::new_missing(
18102 "FlowerAttrs",
18103 "KeyCtStateMask",
18104 self.orig_loc,
18105 self.buf.as_ptr() as usize,
18106 ))
18107 }
18108 pub fn get_key_ct_zone(&self) -> Result<u16, ErrorContext> {
18109 let mut iter = self.clone();
18110 iter.pos = 0;
18111 for attr in iter {
18112 if let Ok(FlowerAttrs::KeyCtZone(val)) = attr {
18113 return Ok(val);
18114 }
18115 }
18116 Err(ErrorContext::new_missing(
18117 "FlowerAttrs",
18118 "KeyCtZone",
18119 self.orig_loc,
18120 self.buf.as_ptr() as usize,
18121 ))
18122 }
18123 pub fn get_key_ct_zone_mask(&self) -> Result<u16, ErrorContext> {
18124 let mut iter = self.clone();
18125 iter.pos = 0;
18126 for attr in iter {
18127 if let Ok(FlowerAttrs::KeyCtZoneMask(val)) = attr {
18128 return Ok(val);
18129 }
18130 }
18131 Err(ErrorContext::new_missing(
18132 "FlowerAttrs",
18133 "KeyCtZoneMask",
18134 self.orig_loc,
18135 self.buf.as_ptr() as usize,
18136 ))
18137 }
18138 pub fn get_key_ct_mark(&self) -> Result<u32, ErrorContext> {
18139 let mut iter = self.clone();
18140 iter.pos = 0;
18141 for attr in iter {
18142 if let Ok(FlowerAttrs::KeyCtMark(val)) = attr {
18143 return Ok(val);
18144 }
18145 }
18146 Err(ErrorContext::new_missing(
18147 "FlowerAttrs",
18148 "KeyCtMark",
18149 self.orig_loc,
18150 self.buf.as_ptr() as usize,
18151 ))
18152 }
18153 pub fn get_key_ct_mark_mask(&self) -> Result<u32, ErrorContext> {
18154 let mut iter = self.clone();
18155 iter.pos = 0;
18156 for attr in iter {
18157 if let Ok(FlowerAttrs::KeyCtMarkMask(val)) = attr {
18158 return Ok(val);
18159 }
18160 }
18161 Err(ErrorContext::new_missing(
18162 "FlowerAttrs",
18163 "KeyCtMarkMask",
18164 self.orig_loc,
18165 self.buf.as_ptr() as usize,
18166 ))
18167 }
18168 pub fn get_key_ct_labels(&self) -> Result<&'a [u8], ErrorContext> {
18169 let mut iter = self.clone();
18170 iter.pos = 0;
18171 for attr in iter {
18172 if let Ok(FlowerAttrs::KeyCtLabels(val)) = attr {
18173 return Ok(val);
18174 }
18175 }
18176 Err(ErrorContext::new_missing(
18177 "FlowerAttrs",
18178 "KeyCtLabels",
18179 self.orig_loc,
18180 self.buf.as_ptr() as usize,
18181 ))
18182 }
18183 pub fn get_key_ct_labels_mask(&self) -> Result<&'a [u8], ErrorContext> {
18184 let mut iter = self.clone();
18185 iter.pos = 0;
18186 for attr in iter {
18187 if let Ok(FlowerAttrs::KeyCtLabelsMask(val)) = attr {
18188 return Ok(val);
18189 }
18190 }
18191 Err(ErrorContext::new_missing(
18192 "FlowerAttrs",
18193 "KeyCtLabelsMask",
18194 self.orig_loc,
18195 self.buf.as_ptr() as usize,
18196 ))
18197 }
18198 pub fn get_key_mpls_opts(&self) -> Result<IterableFlowerKeyMplsOptAttrs<'a>, ErrorContext> {
18199 let mut iter = self.clone();
18200 iter.pos = 0;
18201 for attr in iter {
18202 if let Ok(FlowerAttrs::KeyMplsOpts(val)) = attr {
18203 return Ok(val);
18204 }
18205 }
18206 Err(ErrorContext::new_missing(
18207 "FlowerAttrs",
18208 "KeyMplsOpts",
18209 self.orig_loc,
18210 self.buf.as_ptr() as usize,
18211 ))
18212 }
18213 pub fn get_key_hash(&self) -> Result<u32, ErrorContext> {
18214 let mut iter = self.clone();
18215 iter.pos = 0;
18216 for attr in iter {
18217 if let Ok(FlowerAttrs::KeyHash(val)) = attr {
18218 return Ok(val);
18219 }
18220 }
18221 Err(ErrorContext::new_missing(
18222 "FlowerAttrs",
18223 "KeyHash",
18224 self.orig_loc,
18225 self.buf.as_ptr() as usize,
18226 ))
18227 }
18228 pub fn get_key_hash_mask(&self) -> Result<u32, ErrorContext> {
18229 let mut iter = self.clone();
18230 iter.pos = 0;
18231 for attr in iter {
18232 if let Ok(FlowerAttrs::KeyHashMask(val)) = attr {
18233 return Ok(val);
18234 }
18235 }
18236 Err(ErrorContext::new_missing(
18237 "FlowerAttrs",
18238 "KeyHashMask",
18239 self.orig_loc,
18240 self.buf.as_ptr() as usize,
18241 ))
18242 }
18243 pub fn get_key_num_of_vlans(&self) -> Result<u8, ErrorContext> {
18244 let mut iter = self.clone();
18245 iter.pos = 0;
18246 for attr in iter {
18247 if let Ok(FlowerAttrs::KeyNumOfVlans(val)) = attr {
18248 return Ok(val);
18249 }
18250 }
18251 Err(ErrorContext::new_missing(
18252 "FlowerAttrs",
18253 "KeyNumOfVlans",
18254 self.orig_loc,
18255 self.buf.as_ptr() as usize,
18256 ))
18257 }
18258 pub fn get_key_pppoe_sid(&self) -> Result<u16, ErrorContext> {
18259 let mut iter = self.clone();
18260 iter.pos = 0;
18261 for attr in iter {
18262 if let Ok(FlowerAttrs::KeyPppoeSid(val)) = attr {
18263 return Ok(val);
18264 }
18265 }
18266 Err(ErrorContext::new_missing(
18267 "FlowerAttrs",
18268 "KeyPppoeSid",
18269 self.orig_loc,
18270 self.buf.as_ptr() as usize,
18271 ))
18272 }
18273 pub fn get_key_ppp_proto(&self) -> Result<u16, ErrorContext> {
18274 let mut iter = self.clone();
18275 iter.pos = 0;
18276 for attr in iter {
18277 if let Ok(FlowerAttrs::KeyPppProto(val)) = attr {
18278 return Ok(val);
18279 }
18280 }
18281 Err(ErrorContext::new_missing(
18282 "FlowerAttrs",
18283 "KeyPppProto",
18284 self.orig_loc,
18285 self.buf.as_ptr() as usize,
18286 ))
18287 }
18288 pub fn get_key_l2tpv3_sid(&self) -> Result<u32, ErrorContext> {
18289 let mut iter = self.clone();
18290 iter.pos = 0;
18291 for attr in iter {
18292 if let Ok(FlowerAttrs::KeyL2tpv3Sid(val)) = attr {
18293 return Ok(val);
18294 }
18295 }
18296 Err(ErrorContext::new_missing(
18297 "FlowerAttrs",
18298 "KeyL2tpv3Sid",
18299 self.orig_loc,
18300 self.buf.as_ptr() as usize,
18301 ))
18302 }
18303 pub fn get_l2_miss(&self) -> Result<u8, ErrorContext> {
18304 let mut iter = self.clone();
18305 iter.pos = 0;
18306 for attr in iter {
18307 if let Ok(FlowerAttrs::L2Miss(val)) = attr {
18308 return Ok(val);
18309 }
18310 }
18311 Err(ErrorContext::new_missing(
18312 "FlowerAttrs",
18313 "L2Miss",
18314 self.orig_loc,
18315 self.buf.as_ptr() as usize,
18316 ))
18317 }
18318 pub fn get_key_cfm(&self) -> Result<IterableFlowerKeyCfmAttrs<'a>, ErrorContext> {
18319 let mut iter = self.clone();
18320 iter.pos = 0;
18321 for attr in iter {
18322 if let Ok(FlowerAttrs::KeyCfm(val)) = attr {
18323 return Ok(val);
18324 }
18325 }
18326 Err(ErrorContext::new_missing(
18327 "FlowerAttrs",
18328 "KeyCfm",
18329 self.orig_loc,
18330 self.buf.as_ptr() as usize,
18331 ))
18332 }
18333 pub fn get_key_spi(&self) -> Result<u32, ErrorContext> {
18334 let mut iter = self.clone();
18335 iter.pos = 0;
18336 for attr in iter {
18337 if let Ok(FlowerAttrs::KeySpi(val)) = attr {
18338 return Ok(val);
18339 }
18340 }
18341 Err(ErrorContext::new_missing(
18342 "FlowerAttrs",
18343 "KeySpi",
18344 self.orig_loc,
18345 self.buf.as_ptr() as usize,
18346 ))
18347 }
18348 pub fn get_key_spi_mask(&self) -> Result<u32, ErrorContext> {
18349 let mut iter = self.clone();
18350 iter.pos = 0;
18351 for attr in iter {
18352 if let Ok(FlowerAttrs::KeySpiMask(val)) = attr {
18353 return Ok(val);
18354 }
18355 }
18356 Err(ErrorContext::new_missing(
18357 "FlowerAttrs",
18358 "KeySpiMask",
18359 self.orig_loc,
18360 self.buf.as_ptr() as usize,
18361 ))
18362 }
18363 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
18364 pub fn get_key_enc_flags(&self) -> Result<u32, ErrorContext> {
18365 let mut iter = self.clone();
18366 iter.pos = 0;
18367 for attr in iter {
18368 if let Ok(FlowerAttrs::KeyEncFlags(val)) = attr {
18369 return Ok(val);
18370 }
18371 }
18372 Err(ErrorContext::new_missing(
18373 "FlowerAttrs",
18374 "KeyEncFlags",
18375 self.orig_loc,
18376 self.buf.as_ptr() as usize,
18377 ))
18378 }
18379 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
18380 pub fn get_key_enc_flags_mask(&self) -> Result<u32, ErrorContext> {
18381 let mut iter = self.clone();
18382 iter.pos = 0;
18383 for attr in iter {
18384 if let Ok(FlowerAttrs::KeyEncFlagsMask(val)) = attr {
18385 return Ok(val);
18386 }
18387 }
18388 Err(ErrorContext::new_missing(
18389 "FlowerAttrs",
18390 "KeyEncFlagsMask",
18391 self.orig_loc,
18392 self.buf.as_ptr() as usize,
18393 ))
18394 }
18395}
18396impl FlowerAttrs<'_> {
18397 pub fn new<'a>(buf: &'a [u8]) -> IterableFlowerAttrs<'a> {
18398 IterableFlowerAttrs::with_loc(buf, buf.as_ptr() as usize)
18399 }
18400 fn attr_from_type(r#type: u16) -> Option<&'static str> {
18401 let res = match r#type {
18402 1u16 => "Classid",
18403 2u16 => "Indev",
18404 3u16 => "Act",
18405 4u16 => "KeyEthDst",
18406 5u16 => "KeyEthDstMask",
18407 6u16 => "KeyEthSrc",
18408 7u16 => "KeyEthSrcMask",
18409 8u16 => "KeyEthType",
18410 9u16 => "KeyIpProto",
18411 10u16 => "KeyIpv4Src",
18412 11u16 => "KeyIpv4SrcMask",
18413 12u16 => "KeyIpv4Dst",
18414 13u16 => "KeyIpv4DstMask",
18415 14u16 => "KeyIpv6Src",
18416 15u16 => "KeyIpv6SrcMask",
18417 16u16 => "KeyIpv6Dst",
18418 17u16 => "KeyIpv6DstMask",
18419 18u16 => "KeyTcpSrc",
18420 19u16 => "KeyTcpDst",
18421 20u16 => "KeyUdpSrc",
18422 21u16 => "KeyUdpDst",
18423 22u16 => "Flags",
18424 23u16 => "KeyVlanId",
18425 24u16 => "KeyVlanPrio",
18426 25u16 => "KeyVlanEthType",
18427 26u16 => "KeyEncKeyId",
18428 27u16 => "KeyEncIpv4Src",
18429 28u16 => "KeyEncIpv4SrcMask",
18430 29u16 => "KeyEncIpv4Dst",
18431 30u16 => "KeyEncIpv4DstMask",
18432 31u16 => "KeyEncIpv6Src",
18433 32u16 => "KeyEncIpv6SrcMask",
18434 33u16 => "KeyEncIpv6Dst",
18435 34u16 => "KeyEncIpv6DstMask",
18436 35u16 => "KeyTcpSrcMask",
18437 36u16 => "KeyTcpDstMask",
18438 37u16 => "KeyUdpSrcMask",
18439 38u16 => "KeyUdpDstMask",
18440 39u16 => "KeySctpSrcMask",
18441 40u16 => "KeySctpDstMask",
18442 41u16 => "KeySctpSrc",
18443 42u16 => "KeySctpDst",
18444 43u16 => "KeyEncUdpSrcPort",
18445 44u16 => "KeyEncUdpSrcPortMask",
18446 45u16 => "KeyEncUdpDstPort",
18447 46u16 => "KeyEncUdpDstPortMask",
18448 47u16 => "KeyFlags",
18449 48u16 => "KeyFlagsMask",
18450 49u16 => "KeyIcmpv4Code",
18451 50u16 => "KeyIcmpv4CodeMask",
18452 51u16 => "KeyIcmpv4Type",
18453 52u16 => "KeyIcmpv4TypeMask",
18454 53u16 => "KeyIcmpv6Code",
18455 54u16 => "KeyIcmpv6CodeMask",
18456 55u16 => "KeyIcmpv6Type",
18457 56u16 => "KeyIcmpv6TypeMask",
18458 57u16 => "KeyArpSip",
18459 58u16 => "KeyArpSipMask",
18460 59u16 => "KeyArpTip",
18461 60u16 => "KeyArpTipMask",
18462 61u16 => "KeyArpOp",
18463 62u16 => "KeyArpOpMask",
18464 63u16 => "KeyArpSha",
18465 64u16 => "KeyArpShaMask",
18466 65u16 => "KeyArpTha",
18467 66u16 => "KeyArpThaMask",
18468 67u16 => "KeyMplsTtl",
18469 68u16 => "KeyMplsBos",
18470 69u16 => "KeyMplsTc",
18471 70u16 => "KeyMplsLabel",
18472 71u16 => "KeyTcpFlags",
18473 72u16 => "KeyTcpFlagsMask",
18474 73u16 => "KeyIpTos",
18475 74u16 => "KeyIpTosMask",
18476 75u16 => "KeyIpTtl",
18477 76u16 => "KeyIpTtlMask",
18478 77u16 => "KeyCvlanId",
18479 78u16 => "KeyCvlanPrio",
18480 79u16 => "KeyCvlanEthType",
18481 80u16 => "KeyEncIpTos",
18482 81u16 => "KeyEncIpTosMask",
18483 82u16 => "KeyEncIpTtl",
18484 83u16 => "KeyEncIpTtlMask",
18485 84u16 => "KeyEncOpts",
18486 85u16 => "KeyEncOptsMask",
18487 86u16 => "InHwCount",
18488 87u16 => "KeyPortSrcMin",
18489 88u16 => "KeyPortSrcMax",
18490 89u16 => "KeyPortDstMin",
18491 90u16 => "KeyPortDstMax",
18492 91u16 => "KeyCtState",
18493 92u16 => "KeyCtStateMask",
18494 93u16 => "KeyCtZone",
18495 94u16 => "KeyCtZoneMask",
18496 95u16 => "KeyCtMark",
18497 96u16 => "KeyCtMarkMask",
18498 97u16 => "KeyCtLabels",
18499 98u16 => "KeyCtLabelsMask",
18500 99u16 => "KeyMplsOpts",
18501 100u16 => "KeyHash",
18502 101u16 => "KeyHashMask",
18503 102u16 => "KeyNumOfVlans",
18504 103u16 => "KeyPppoeSid",
18505 104u16 => "KeyPppProto",
18506 105u16 => "KeyL2tpv3Sid",
18507 106u16 => "L2Miss",
18508 107u16 => "KeyCfm",
18509 108u16 => "KeySpi",
18510 109u16 => "KeySpiMask",
18511 110u16 => "KeyEncFlags",
18512 111u16 => "KeyEncFlagsMask",
18513 _ => return None,
18514 };
18515 Some(res)
18516 }
18517}
18518#[derive(Clone, Copy, Default)]
18519pub struct IterableFlowerAttrs<'a> {
18520 buf: &'a [u8],
18521 pos: usize,
18522 orig_loc: usize,
18523}
18524impl<'a> IterableFlowerAttrs<'a> {
18525 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
18526 Self {
18527 buf,
18528 pos: 0,
18529 orig_loc,
18530 }
18531 }
18532 pub fn get_buf(&self) -> &'a [u8] {
18533 self.buf
18534 }
18535}
18536impl<'a> Iterator for IterableFlowerAttrs<'a> {
18537 type Item = Result<FlowerAttrs<'a>, ErrorContext>;
18538 fn next(&mut self) -> Option<Self::Item> {
18539 let mut pos;
18540 let mut r#type;
18541 loop {
18542 pos = self.pos;
18543 r#type = None;
18544 if self.buf.len() == self.pos {
18545 return None;
18546 }
18547 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
18548 self.pos = self.buf.len();
18549 break;
18550 };
18551 r#type = Some(header.r#type);
18552 let res = match header.r#type {
18553 1u16 => FlowerAttrs::Classid({
18554 let res = parse_u32(next);
18555 let Some(val) = res else { break };
18556 val
18557 }),
18558 2u16 => FlowerAttrs::Indev({
18559 let res = CStr::from_bytes_with_nul(next).ok();
18560 let Some(val) = res else { break };
18561 val
18562 }),
18563 3u16 => FlowerAttrs::Act({
18564 let res = Some(IterableArrayActAttrs::with_loc(next, self.orig_loc));
18565 let Some(val) = res else { break };
18566 val
18567 }),
18568 4u16 => FlowerAttrs::KeyEthDst({
18569 let res = Some(next);
18570 let Some(val) = res else { break };
18571 val
18572 }),
18573 5u16 => FlowerAttrs::KeyEthDstMask({
18574 let res = Some(next);
18575 let Some(val) = res else { break };
18576 val
18577 }),
18578 6u16 => FlowerAttrs::KeyEthSrc({
18579 let res = Some(next);
18580 let Some(val) = res else { break };
18581 val
18582 }),
18583 7u16 => FlowerAttrs::KeyEthSrcMask({
18584 let res = Some(next);
18585 let Some(val) = res else { break };
18586 val
18587 }),
18588 8u16 => FlowerAttrs::KeyEthType({
18589 let res = parse_be_u16(next);
18590 let Some(val) = res else { break };
18591 val
18592 }),
18593 9u16 => FlowerAttrs::KeyIpProto({
18594 let res = parse_u8(next);
18595 let Some(val) = res else { break };
18596 val
18597 }),
18598 10u16 => FlowerAttrs::KeyIpv4Src({
18599 let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
18600 let Some(val) = res else { break };
18601 val
18602 }),
18603 11u16 => FlowerAttrs::KeyIpv4SrcMask({
18604 let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
18605 let Some(val) = res else { break };
18606 val
18607 }),
18608 12u16 => FlowerAttrs::KeyIpv4Dst({
18609 let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
18610 let Some(val) = res else { break };
18611 val
18612 }),
18613 13u16 => FlowerAttrs::KeyIpv4DstMask({
18614 let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
18615 let Some(val) = res else { break };
18616 val
18617 }),
18618 14u16 => FlowerAttrs::KeyIpv6Src({
18619 let res = Some(next);
18620 let Some(val) = res else { break };
18621 val
18622 }),
18623 15u16 => FlowerAttrs::KeyIpv6SrcMask({
18624 let res = Some(next);
18625 let Some(val) = res else { break };
18626 val
18627 }),
18628 16u16 => FlowerAttrs::KeyIpv6Dst({
18629 let res = Some(next);
18630 let Some(val) = res else { break };
18631 val
18632 }),
18633 17u16 => FlowerAttrs::KeyIpv6DstMask({
18634 let res = Some(next);
18635 let Some(val) = res else { break };
18636 val
18637 }),
18638 18u16 => FlowerAttrs::KeyTcpSrc({
18639 let res = parse_be_u16(next);
18640 let Some(val) = res else { break };
18641 val
18642 }),
18643 19u16 => FlowerAttrs::KeyTcpDst({
18644 let res = parse_be_u16(next);
18645 let Some(val) = res else { break };
18646 val
18647 }),
18648 20u16 => FlowerAttrs::KeyUdpSrc({
18649 let res = parse_be_u16(next);
18650 let Some(val) = res else { break };
18651 val
18652 }),
18653 21u16 => FlowerAttrs::KeyUdpDst({
18654 let res = parse_be_u16(next);
18655 let Some(val) = res else { break };
18656 val
18657 }),
18658 22u16 => FlowerAttrs::Flags({
18659 let res = parse_u32(next);
18660 let Some(val) = res else { break };
18661 val
18662 }),
18663 23u16 => FlowerAttrs::KeyVlanId({
18664 let res = parse_be_u16(next);
18665 let Some(val) = res else { break };
18666 val
18667 }),
18668 24u16 => FlowerAttrs::KeyVlanPrio({
18669 let res = parse_u8(next);
18670 let Some(val) = res else { break };
18671 val
18672 }),
18673 25u16 => FlowerAttrs::KeyVlanEthType({
18674 let res = parse_be_u16(next);
18675 let Some(val) = res else { break };
18676 val
18677 }),
18678 26u16 => FlowerAttrs::KeyEncKeyId({
18679 let res = parse_be_u32(next);
18680 let Some(val) = res else { break };
18681 val
18682 }),
18683 27u16 => FlowerAttrs::KeyEncIpv4Src({
18684 let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
18685 let Some(val) = res else { break };
18686 val
18687 }),
18688 28u16 => FlowerAttrs::KeyEncIpv4SrcMask({
18689 let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
18690 let Some(val) = res else { break };
18691 val
18692 }),
18693 29u16 => FlowerAttrs::KeyEncIpv4Dst({
18694 let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
18695 let Some(val) = res else { break };
18696 val
18697 }),
18698 30u16 => FlowerAttrs::KeyEncIpv4DstMask({
18699 let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
18700 let Some(val) = res else { break };
18701 val
18702 }),
18703 31u16 => FlowerAttrs::KeyEncIpv6Src({
18704 let res = Some(next);
18705 let Some(val) = res else { break };
18706 val
18707 }),
18708 32u16 => FlowerAttrs::KeyEncIpv6SrcMask({
18709 let res = Some(next);
18710 let Some(val) = res else { break };
18711 val
18712 }),
18713 33u16 => FlowerAttrs::KeyEncIpv6Dst({
18714 let res = Some(next);
18715 let Some(val) = res else { break };
18716 val
18717 }),
18718 34u16 => FlowerAttrs::KeyEncIpv6DstMask({
18719 let res = Some(next);
18720 let Some(val) = res else { break };
18721 val
18722 }),
18723 35u16 => FlowerAttrs::KeyTcpSrcMask({
18724 let res = parse_be_u16(next);
18725 let Some(val) = res else { break };
18726 val
18727 }),
18728 36u16 => FlowerAttrs::KeyTcpDstMask({
18729 let res = parse_be_u16(next);
18730 let Some(val) = res else { break };
18731 val
18732 }),
18733 37u16 => FlowerAttrs::KeyUdpSrcMask({
18734 let res = parse_be_u16(next);
18735 let Some(val) = res else { break };
18736 val
18737 }),
18738 38u16 => FlowerAttrs::KeyUdpDstMask({
18739 let res = parse_be_u16(next);
18740 let Some(val) = res else { break };
18741 val
18742 }),
18743 39u16 => FlowerAttrs::KeySctpSrcMask({
18744 let res = parse_be_u16(next);
18745 let Some(val) = res else { break };
18746 val
18747 }),
18748 40u16 => FlowerAttrs::KeySctpDstMask({
18749 let res = parse_be_u16(next);
18750 let Some(val) = res else { break };
18751 val
18752 }),
18753 41u16 => FlowerAttrs::KeySctpSrc({
18754 let res = parse_be_u16(next);
18755 let Some(val) = res else { break };
18756 val
18757 }),
18758 42u16 => FlowerAttrs::KeySctpDst({
18759 let res = parse_be_u16(next);
18760 let Some(val) = res else { break };
18761 val
18762 }),
18763 43u16 => FlowerAttrs::KeyEncUdpSrcPort({
18764 let res = parse_be_u16(next);
18765 let Some(val) = res else { break };
18766 val
18767 }),
18768 44u16 => FlowerAttrs::KeyEncUdpSrcPortMask({
18769 let res = parse_be_u16(next);
18770 let Some(val) = res else { break };
18771 val
18772 }),
18773 45u16 => FlowerAttrs::KeyEncUdpDstPort({
18774 let res = parse_be_u16(next);
18775 let Some(val) = res else { break };
18776 val
18777 }),
18778 46u16 => FlowerAttrs::KeyEncUdpDstPortMask({
18779 let res = parse_be_u16(next);
18780 let Some(val) = res else { break };
18781 val
18782 }),
18783 47u16 => FlowerAttrs::KeyFlags({
18784 let res = parse_be_u32(next);
18785 let Some(val) = res else { break };
18786 val
18787 }),
18788 48u16 => FlowerAttrs::KeyFlagsMask({
18789 let res = parse_be_u32(next);
18790 let Some(val) = res else { break };
18791 val
18792 }),
18793 49u16 => FlowerAttrs::KeyIcmpv4Code({
18794 let res = parse_u8(next);
18795 let Some(val) = res else { break };
18796 val
18797 }),
18798 50u16 => FlowerAttrs::KeyIcmpv4CodeMask({
18799 let res = parse_u8(next);
18800 let Some(val) = res else { break };
18801 val
18802 }),
18803 51u16 => FlowerAttrs::KeyIcmpv4Type({
18804 let res = parse_u8(next);
18805 let Some(val) = res else { break };
18806 val
18807 }),
18808 52u16 => FlowerAttrs::KeyIcmpv4TypeMask({
18809 let res = parse_u8(next);
18810 let Some(val) = res else { break };
18811 val
18812 }),
18813 53u16 => FlowerAttrs::KeyIcmpv6Code({
18814 let res = parse_u8(next);
18815 let Some(val) = res else { break };
18816 val
18817 }),
18818 54u16 => FlowerAttrs::KeyIcmpv6CodeMask({
18819 let res = parse_u8(next);
18820 let Some(val) = res else { break };
18821 val
18822 }),
18823 55u16 => FlowerAttrs::KeyIcmpv6Type({
18824 let res = parse_u8(next);
18825 let Some(val) = res else { break };
18826 val
18827 }),
18828 56u16 => FlowerAttrs::KeyIcmpv6TypeMask({
18829 let res = parse_u8(next);
18830 let Some(val) = res else { break };
18831 val
18832 }),
18833 57u16 => FlowerAttrs::KeyArpSip({
18834 let res = parse_be_u32(next);
18835 let Some(val) = res else { break };
18836 val
18837 }),
18838 58u16 => FlowerAttrs::KeyArpSipMask({
18839 let res = parse_be_u32(next);
18840 let Some(val) = res else { break };
18841 val
18842 }),
18843 59u16 => FlowerAttrs::KeyArpTip({
18844 let res = parse_be_u32(next);
18845 let Some(val) = res else { break };
18846 val
18847 }),
18848 60u16 => FlowerAttrs::KeyArpTipMask({
18849 let res = parse_be_u32(next);
18850 let Some(val) = res else { break };
18851 val
18852 }),
18853 61u16 => FlowerAttrs::KeyArpOp({
18854 let res = parse_u8(next);
18855 let Some(val) = res else { break };
18856 val
18857 }),
18858 62u16 => FlowerAttrs::KeyArpOpMask({
18859 let res = parse_u8(next);
18860 let Some(val) = res else { break };
18861 val
18862 }),
18863 63u16 => FlowerAttrs::KeyArpSha({
18864 let res = Some(next);
18865 let Some(val) = res else { break };
18866 val
18867 }),
18868 64u16 => FlowerAttrs::KeyArpShaMask({
18869 let res = Some(next);
18870 let Some(val) = res else { break };
18871 val
18872 }),
18873 65u16 => FlowerAttrs::KeyArpTha({
18874 let res = Some(next);
18875 let Some(val) = res else { break };
18876 val
18877 }),
18878 66u16 => FlowerAttrs::KeyArpThaMask({
18879 let res = Some(next);
18880 let Some(val) = res else { break };
18881 val
18882 }),
18883 67u16 => FlowerAttrs::KeyMplsTtl({
18884 let res = parse_u8(next);
18885 let Some(val) = res else { break };
18886 val
18887 }),
18888 68u16 => FlowerAttrs::KeyMplsBos({
18889 let res = parse_u8(next);
18890 let Some(val) = res else { break };
18891 val
18892 }),
18893 69u16 => FlowerAttrs::KeyMplsTc({
18894 let res = parse_u8(next);
18895 let Some(val) = res else { break };
18896 val
18897 }),
18898 70u16 => FlowerAttrs::KeyMplsLabel({
18899 let res = parse_be_u32(next);
18900 let Some(val) = res else { break };
18901 val
18902 }),
18903 71u16 => FlowerAttrs::KeyTcpFlags({
18904 let res = parse_be_u16(next);
18905 let Some(val) = res else { break };
18906 val
18907 }),
18908 72u16 => FlowerAttrs::KeyTcpFlagsMask({
18909 let res = parse_be_u16(next);
18910 let Some(val) = res else { break };
18911 val
18912 }),
18913 73u16 => FlowerAttrs::KeyIpTos({
18914 let res = parse_u8(next);
18915 let Some(val) = res else { break };
18916 val
18917 }),
18918 74u16 => FlowerAttrs::KeyIpTosMask({
18919 let res = parse_u8(next);
18920 let Some(val) = res else { break };
18921 val
18922 }),
18923 75u16 => FlowerAttrs::KeyIpTtl({
18924 let res = parse_u8(next);
18925 let Some(val) = res else { break };
18926 val
18927 }),
18928 76u16 => FlowerAttrs::KeyIpTtlMask({
18929 let res = parse_u8(next);
18930 let Some(val) = res else { break };
18931 val
18932 }),
18933 77u16 => FlowerAttrs::KeyCvlanId({
18934 let res = parse_be_u16(next);
18935 let Some(val) = res else { break };
18936 val
18937 }),
18938 78u16 => FlowerAttrs::KeyCvlanPrio({
18939 let res = parse_u8(next);
18940 let Some(val) = res else { break };
18941 val
18942 }),
18943 79u16 => FlowerAttrs::KeyCvlanEthType({
18944 let res = parse_be_u16(next);
18945 let Some(val) = res else { break };
18946 val
18947 }),
18948 80u16 => FlowerAttrs::KeyEncIpTos({
18949 let res = parse_u8(next);
18950 let Some(val) = res else { break };
18951 val
18952 }),
18953 81u16 => FlowerAttrs::KeyEncIpTosMask({
18954 let res = parse_u8(next);
18955 let Some(val) = res else { break };
18956 val
18957 }),
18958 82u16 => FlowerAttrs::KeyEncIpTtl({
18959 let res = parse_u8(next);
18960 let Some(val) = res else { break };
18961 val
18962 }),
18963 83u16 => FlowerAttrs::KeyEncIpTtlMask({
18964 let res = parse_u8(next);
18965 let Some(val) = res else { break };
18966 val
18967 }),
18968 84u16 => FlowerAttrs::KeyEncOpts({
18969 let res = Some(IterableFlowerKeyEncOptsAttrs::with_loc(next, self.orig_loc));
18970 let Some(val) = res else { break };
18971 val
18972 }),
18973 85u16 => FlowerAttrs::KeyEncOptsMask({
18974 let res = Some(IterableFlowerKeyEncOptsAttrs::with_loc(next, self.orig_loc));
18975 let Some(val) = res else { break };
18976 val
18977 }),
18978 86u16 => FlowerAttrs::InHwCount({
18979 let res = parse_u32(next);
18980 let Some(val) = res else { break };
18981 val
18982 }),
18983 87u16 => FlowerAttrs::KeyPortSrcMin({
18984 let res = parse_be_u16(next);
18985 let Some(val) = res else { break };
18986 val
18987 }),
18988 88u16 => FlowerAttrs::KeyPortSrcMax({
18989 let res = parse_be_u16(next);
18990 let Some(val) = res else { break };
18991 val
18992 }),
18993 89u16 => FlowerAttrs::KeyPortDstMin({
18994 let res = parse_be_u16(next);
18995 let Some(val) = res else { break };
18996 val
18997 }),
18998 90u16 => FlowerAttrs::KeyPortDstMax({
18999 let res = parse_be_u16(next);
19000 let Some(val) = res else { break };
19001 val
19002 }),
19003 91u16 => FlowerAttrs::KeyCtState({
19004 let res = parse_u16(next);
19005 let Some(val) = res else { break };
19006 val
19007 }),
19008 92u16 => FlowerAttrs::KeyCtStateMask({
19009 let res = parse_u16(next);
19010 let Some(val) = res else { break };
19011 val
19012 }),
19013 93u16 => FlowerAttrs::KeyCtZone({
19014 let res = parse_u16(next);
19015 let Some(val) = res else { break };
19016 val
19017 }),
19018 94u16 => FlowerAttrs::KeyCtZoneMask({
19019 let res = parse_u16(next);
19020 let Some(val) = res else { break };
19021 val
19022 }),
19023 95u16 => FlowerAttrs::KeyCtMark({
19024 let res = parse_u32(next);
19025 let Some(val) = res else { break };
19026 val
19027 }),
19028 96u16 => FlowerAttrs::KeyCtMarkMask({
19029 let res = parse_u32(next);
19030 let Some(val) = res else { break };
19031 val
19032 }),
19033 97u16 => FlowerAttrs::KeyCtLabels({
19034 let res = Some(next);
19035 let Some(val) = res else { break };
19036 val
19037 }),
19038 98u16 => FlowerAttrs::KeyCtLabelsMask({
19039 let res = Some(next);
19040 let Some(val) = res else { break };
19041 val
19042 }),
19043 99u16 => FlowerAttrs::KeyMplsOpts({
19044 let res = Some(IterableFlowerKeyMplsOptAttrs::with_loc(next, self.orig_loc));
19045 let Some(val) = res else { break };
19046 val
19047 }),
19048 100u16 => FlowerAttrs::KeyHash({
19049 let res = parse_u32(next);
19050 let Some(val) = res else { break };
19051 val
19052 }),
19053 101u16 => FlowerAttrs::KeyHashMask({
19054 let res = parse_u32(next);
19055 let Some(val) = res else { break };
19056 val
19057 }),
19058 102u16 => FlowerAttrs::KeyNumOfVlans({
19059 let res = parse_u8(next);
19060 let Some(val) = res else { break };
19061 val
19062 }),
19063 103u16 => FlowerAttrs::KeyPppoeSid({
19064 let res = parse_be_u16(next);
19065 let Some(val) = res else { break };
19066 val
19067 }),
19068 104u16 => FlowerAttrs::KeyPppProto({
19069 let res = parse_be_u16(next);
19070 let Some(val) = res else { break };
19071 val
19072 }),
19073 105u16 => FlowerAttrs::KeyL2tpv3Sid({
19074 let res = parse_be_u32(next);
19075 let Some(val) = res else { break };
19076 val
19077 }),
19078 106u16 => FlowerAttrs::L2Miss({
19079 let res = parse_u8(next);
19080 let Some(val) = res else { break };
19081 val
19082 }),
19083 107u16 => FlowerAttrs::KeyCfm({
19084 let res = Some(IterableFlowerKeyCfmAttrs::with_loc(next, self.orig_loc));
19085 let Some(val) = res else { break };
19086 val
19087 }),
19088 108u16 => FlowerAttrs::KeySpi({
19089 let res = parse_be_u32(next);
19090 let Some(val) = res else { break };
19091 val
19092 }),
19093 109u16 => FlowerAttrs::KeySpiMask({
19094 let res = parse_be_u32(next);
19095 let Some(val) = res else { break };
19096 val
19097 }),
19098 110u16 => FlowerAttrs::KeyEncFlags({
19099 let res = parse_be_u32(next);
19100 let Some(val) = res else { break };
19101 val
19102 }),
19103 111u16 => FlowerAttrs::KeyEncFlagsMask({
19104 let res = parse_be_u32(next);
19105 let Some(val) = res else { break };
19106 val
19107 }),
19108 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
19109 n => continue,
19110 };
19111 return Some(Ok(res));
19112 }
19113 Some(Err(ErrorContext::new(
19114 "FlowerAttrs",
19115 r#type.and_then(|t| FlowerAttrs::attr_from_type(t)),
19116 self.orig_loc,
19117 self.buf.as_ptr().wrapping_add(pos) as usize,
19118 )))
19119 }
19120}
19121impl<'a> std::fmt::Debug for IterableFlowerAttrs<'_> {
19122 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19123 let mut fmt = f.debug_struct("FlowerAttrs");
19124 for attr in self.clone() {
19125 let attr = match attr {
19126 Ok(a) => a,
19127 Err(err) => {
19128 fmt.finish()?;
19129 f.write_str("Err(")?;
19130 err.fmt(f)?;
19131 return f.write_str(")");
19132 }
19133 };
19134 match attr {
19135 FlowerAttrs::Classid(val) => fmt.field("Classid", &val),
19136 FlowerAttrs::Indev(val) => fmt.field("Indev", &val),
19137 FlowerAttrs::Act(val) => fmt.field("Act", &val),
19138 FlowerAttrs::KeyEthDst(val) => fmt.field("KeyEthDst", &FormatMac(val)),
19139 FlowerAttrs::KeyEthDstMask(val) => fmt.field("KeyEthDstMask", &FormatMac(val)),
19140 FlowerAttrs::KeyEthSrc(val) => fmt.field("KeyEthSrc", &FormatMac(val)),
19141 FlowerAttrs::KeyEthSrcMask(val) => fmt.field("KeyEthSrcMask", &FormatMac(val)),
19142 FlowerAttrs::KeyEthType(val) => fmt.field("KeyEthType", &val),
19143 FlowerAttrs::KeyIpProto(val) => fmt.field("KeyIpProto", &val),
19144 FlowerAttrs::KeyIpv4Src(val) => fmt.field("KeyIpv4Src", &val),
19145 FlowerAttrs::KeyIpv4SrcMask(val) => fmt.field("KeyIpv4SrcMask", &val),
19146 FlowerAttrs::KeyIpv4Dst(val) => fmt.field("KeyIpv4Dst", &val),
19147 FlowerAttrs::KeyIpv4DstMask(val) => fmt.field("KeyIpv4DstMask", &val),
19148 FlowerAttrs::KeyIpv6Src(val) => fmt.field("KeyIpv6Src", &val),
19149 FlowerAttrs::KeyIpv6SrcMask(val) => fmt.field("KeyIpv6SrcMask", &val),
19150 FlowerAttrs::KeyIpv6Dst(val) => fmt.field("KeyIpv6Dst", &val),
19151 FlowerAttrs::KeyIpv6DstMask(val) => fmt.field("KeyIpv6DstMask", &val),
19152 FlowerAttrs::KeyTcpSrc(val) => fmt.field("KeyTcpSrc", &val),
19153 FlowerAttrs::KeyTcpDst(val) => fmt.field("KeyTcpDst", &val),
19154 FlowerAttrs::KeyUdpSrc(val) => fmt.field("KeyUdpSrc", &val),
19155 FlowerAttrs::KeyUdpDst(val) => fmt.field("KeyUdpDst", &val),
19156 FlowerAttrs::Flags(val) => {
19157 fmt.field("Flags", &FormatFlags(val.into(), ClsFlags::from_value))
19158 }
19159 FlowerAttrs::KeyVlanId(val) => fmt.field("KeyVlanId", &val),
19160 FlowerAttrs::KeyVlanPrio(val) => fmt.field("KeyVlanPrio", &val),
19161 FlowerAttrs::KeyVlanEthType(val) => fmt.field("KeyVlanEthType", &val),
19162 FlowerAttrs::KeyEncKeyId(val) => fmt.field("KeyEncKeyId", &val),
19163 FlowerAttrs::KeyEncIpv4Src(val) => fmt.field("KeyEncIpv4Src", &val),
19164 FlowerAttrs::KeyEncIpv4SrcMask(val) => fmt.field("KeyEncIpv4SrcMask", &val),
19165 FlowerAttrs::KeyEncIpv4Dst(val) => fmt.field("KeyEncIpv4Dst", &val),
19166 FlowerAttrs::KeyEncIpv4DstMask(val) => fmt.field("KeyEncIpv4DstMask", &val),
19167 FlowerAttrs::KeyEncIpv6Src(val) => fmt.field("KeyEncIpv6Src", &val),
19168 FlowerAttrs::KeyEncIpv6SrcMask(val) => fmt.field("KeyEncIpv6SrcMask", &val),
19169 FlowerAttrs::KeyEncIpv6Dst(val) => fmt.field("KeyEncIpv6Dst", &val),
19170 FlowerAttrs::KeyEncIpv6DstMask(val) => fmt.field("KeyEncIpv6DstMask", &val),
19171 FlowerAttrs::KeyTcpSrcMask(val) => fmt.field("KeyTcpSrcMask", &val),
19172 FlowerAttrs::KeyTcpDstMask(val) => fmt.field("KeyTcpDstMask", &val),
19173 FlowerAttrs::KeyUdpSrcMask(val) => fmt.field("KeyUdpSrcMask", &val),
19174 FlowerAttrs::KeyUdpDstMask(val) => fmt.field("KeyUdpDstMask", &val),
19175 FlowerAttrs::KeySctpSrcMask(val) => fmt.field("KeySctpSrcMask", &val),
19176 FlowerAttrs::KeySctpDstMask(val) => fmt.field("KeySctpDstMask", &val),
19177 FlowerAttrs::KeySctpSrc(val) => fmt.field("KeySctpSrc", &val),
19178 FlowerAttrs::KeySctpDst(val) => fmt.field("KeySctpDst", &val),
19179 FlowerAttrs::KeyEncUdpSrcPort(val) => fmt.field("KeyEncUdpSrcPort", &val),
19180 FlowerAttrs::KeyEncUdpSrcPortMask(val) => fmt.field("KeyEncUdpSrcPortMask", &val),
19181 FlowerAttrs::KeyEncUdpDstPort(val) => fmt.field("KeyEncUdpDstPort", &val),
19182 FlowerAttrs::KeyEncUdpDstPortMask(val) => fmt.field("KeyEncUdpDstPortMask", &val),
19183 FlowerAttrs::KeyFlags(val) => fmt.field(
19184 "KeyFlags",
19185 &FormatFlags(val.into(), FlowerKeyCtrlFlags::from_value),
19186 ),
19187 FlowerAttrs::KeyFlagsMask(val) => fmt.field(
19188 "KeyFlagsMask",
19189 &FormatFlags(val.into(), FlowerKeyCtrlFlags::from_value),
19190 ),
19191 FlowerAttrs::KeyIcmpv4Code(val) => fmt.field("KeyIcmpv4Code", &val),
19192 FlowerAttrs::KeyIcmpv4CodeMask(val) => fmt.field("KeyIcmpv4CodeMask", &val),
19193 FlowerAttrs::KeyIcmpv4Type(val) => fmt.field("KeyIcmpv4Type", &val),
19194 FlowerAttrs::KeyIcmpv4TypeMask(val) => fmt.field("KeyIcmpv4TypeMask", &val),
19195 FlowerAttrs::KeyIcmpv6Code(val) => fmt.field("KeyIcmpv6Code", &val),
19196 FlowerAttrs::KeyIcmpv6CodeMask(val) => fmt.field("KeyIcmpv6CodeMask", &val),
19197 FlowerAttrs::KeyIcmpv6Type(val) => fmt.field("KeyIcmpv6Type", &val),
19198 FlowerAttrs::KeyIcmpv6TypeMask(val) => fmt.field("KeyIcmpv6TypeMask", &val),
19199 FlowerAttrs::KeyArpSip(val) => fmt.field("KeyArpSip", &val),
19200 FlowerAttrs::KeyArpSipMask(val) => fmt.field("KeyArpSipMask", &val),
19201 FlowerAttrs::KeyArpTip(val) => fmt.field("KeyArpTip", &val),
19202 FlowerAttrs::KeyArpTipMask(val) => fmt.field("KeyArpTipMask", &val),
19203 FlowerAttrs::KeyArpOp(val) => fmt.field("KeyArpOp", &val),
19204 FlowerAttrs::KeyArpOpMask(val) => fmt.field("KeyArpOpMask", &val),
19205 FlowerAttrs::KeyArpSha(val) => fmt.field("KeyArpSha", &FormatMac(val)),
19206 FlowerAttrs::KeyArpShaMask(val) => fmt.field("KeyArpShaMask", &FormatMac(val)),
19207 FlowerAttrs::KeyArpTha(val) => fmt.field("KeyArpTha", &FormatMac(val)),
19208 FlowerAttrs::KeyArpThaMask(val) => fmt.field("KeyArpThaMask", &FormatMac(val)),
19209 FlowerAttrs::KeyMplsTtl(val) => fmt.field("KeyMplsTtl", &val),
19210 FlowerAttrs::KeyMplsBos(val) => fmt.field("KeyMplsBos", &val),
19211 FlowerAttrs::KeyMplsTc(val) => fmt.field("KeyMplsTc", &val),
19212 FlowerAttrs::KeyMplsLabel(val) => fmt.field("KeyMplsLabel", &val),
19213 FlowerAttrs::KeyTcpFlags(val) => fmt.field("KeyTcpFlags", &val),
19214 FlowerAttrs::KeyTcpFlagsMask(val) => fmt.field("KeyTcpFlagsMask", &val),
19215 FlowerAttrs::KeyIpTos(val) => fmt.field("KeyIpTos", &val),
19216 FlowerAttrs::KeyIpTosMask(val) => fmt.field("KeyIpTosMask", &val),
19217 FlowerAttrs::KeyIpTtl(val) => fmt.field("KeyIpTtl", &val),
19218 FlowerAttrs::KeyIpTtlMask(val) => fmt.field("KeyIpTtlMask", &val),
19219 FlowerAttrs::KeyCvlanId(val) => fmt.field("KeyCvlanId", &val),
19220 FlowerAttrs::KeyCvlanPrio(val) => fmt.field("KeyCvlanPrio", &val),
19221 FlowerAttrs::KeyCvlanEthType(val) => fmt.field("KeyCvlanEthType", &val),
19222 FlowerAttrs::KeyEncIpTos(val) => fmt.field("KeyEncIpTos", &val),
19223 FlowerAttrs::KeyEncIpTosMask(val) => fmt.field("KeyEncIpTosMask", &val),
19224 FlowerAttrs::KeyEncIpTtl(val) => fmt.field("KeyEncIpTtl", &val),
19225 FlowerAttrs::KeyEncIpTtlMask(val) => fmt.field("KeyEncIpTtlMask", &val),
19226 FlowerAttrs::KeyEncOpts(val) => fmt.field("KeyEncOpts", &val),
19227 FlowerAttrs::KeyEncOptsMask(val) => fmt.field("KeyEncOptsMask", &val),
19228 FlowerAttrs::InHwCount(val) => fmt.field("InHwCount", &val),
19229 FlowerAttrs::KeyPortSrcMin(val) => fmt.field("KeyPortSrcMin", &val),
19230 FlowerAttrs::KeyPortSrcMax(val) => fmt.field("KeyPortSrcMax", &val),
19231 FlowerAttrs::KeyPortDstMin(val) => fmt.field("KeyPortDstMin", &val),
19232 FlowerAttrs::KeyPortDstMax(val) => fmt.field("KeyPortDstMax", &val),
19233 FlowerAttrs::KeyCtState(val) => fmt.field("KeyCtState", &val),
19234 FlowerAttrs::KeyCtStateMask(val) => fmt.field("KeyCtStateMask", &val),
19235 FlowerAttrs::KeyCtZone(val) => fmt.field("KeyCtZone", &val),
19236 FlowerAttrs::KeyCtZoneMask(val) => fmt.field("KeyCtZoneMask", &val),
19237 FlowerAttrs::KeyCtMark(val) => fmt.field("KeyCtMark", &val),
19238 FlowerAttrs::KeyCtMarkMask(val) => fmt.field("KeyCtMarkMask", &val),
19239 FlowerAttrs::KeyCtLabels(val) => fmt.field("KeyCtLabels", &val),
19240 FlowerAttrs::KeyCtLabelsMask(val) => fmt.field("KeyCtLabelsMask", &val),
19241 FlowerAttrs::KeyMplsOpts(val) => fmt.field("KeyMplsOpts", &val),
19242 FlowerAttrs::KeyHash(val) => fmt.field("KeyHash", &val),
19243 FlowerAttrs::KeyHashMask(val) => fmt.field("KeyHashMask", &val),
19244 FlowerAttrs::KeyNumOfVlans(val) => fmt.field("KeyNumOfVlans", &val),
19245 FlowerAttrs::KeyPppoeSid(val) => fmt.field("KeyPppoeSid", &val),
19246 FlowerAttrs::KeyPppProto(val) => fmt.field("KeyPppProto", &val),
19247 FlowerAttrs::KeyL2tpv3Sid(val) => fmt.field("KeyL2tpv3Sid", &val),
19248 FlowerAttrs::L2Miss(val) => fmt.field("L2Miss", &val),
19249 FlowerAttrs::KeyCfm(val) => fmt.field("KeyCfm", &val),
19250 FlowerAttrs::KeySpi(val) => fmt.field("KeySpi", &val),
19251 FlowerAttrs::KeySpiMask(val) => fmt.field("KeySpiMask", &val),
19252 FlowerAttrs::KeyEncFlags(val) => fmt.field(
19253 "KeyEncFlags",
19254 &FormatFlags(val.into(), FlowerKeyCtrlFlags::from_value),
19255 ),
19256 FlowerAttrs::KeyEncFlagsMask(val) => fmt.field(
19257 "KeyEncFlagsMask",
19258 &FormatFlags(val.into(), FlowerKeyCtrlFlags::from_value),
19259 ),
19260 };
19261 }
19262 fmt.finish()
19263 }
19264}
19265impl IterableFlowerAttrs<'_> {
19266 pub fn lookup_attr(
19267 &self,
19268 offset: usize,
19269 missing_type: Option<u16>,
19270 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
19271 let mut stack = Vec::new();
19272 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
19273 if missing_type.is_some() && cur == offset {
19274 stack.push(("FlowerAttrs", offset));
19275 return (
19276 stack,
19277 missing_type.and_then(|t| FlowerAttrs::attr_from_type(t)),
19278 );
19279 }
19280 if cur > offset || cur + self.buf.len() < offset {
19281 return (stack, None);
19282 }
19283 let mut attrs = self.clone();
19284 let mut last_off = cur + attrs.pos;
19285 let mut missing = None;
19286 while let Some(attr) = attrs.next() {
19287 let Ok(attr) = attr else { break };
19288 match attr {
19289 FlowerAttrs::Classid(val) => {
19290 if last_off == offset {
19291 stack.push(("Classid", last_off));
19292 break;
19293 }
19294 }
19295 FlowerAttrs::Indev(val) => {
19296 if last_off == offset {
19297 stack.push(("Indev", last_off));
19298 break;
19299 }
19300 }
19301 FlowerAttrs::Act(val) => {
19302 for entry in val {
19303 let Ok(attr) = entry else { break };
19304 (stack, missing) = attr.lookup_attr(offset, missing_type);
19305 if !stack.is_empty() {
19306 break;
19307 }
19308 }
19309 if !stack.is_empty() {
19310 stack.push(("Act", last_off));
19311 break;
19312 }
19313 }
19314 FlowerAttrs::KeyEthDst(val) => {
19315 if last_off == offset {
19316 stack.push(("KeyEthDst", last_off));
19317 break;
19318 }
19319 }
19320 FlowerAttrs::KeyEthDstMask(val) => {
19321 if last_off == offset {
19322 stack.push(("KeyEthDstMask", last_off));
19323 break;
19324 }
19325 }
19326 FlowerAttrs::KeyEthSrc(val) => {
19327 if last_off == offset {
19328 stack.push(("KeyEthSrc", last_off));
19329 break;
19330 }
19331 }
19332 FlowerAttrs::KeyEthSrcMask(val) => {
19333 if last_off == offset {
19334 stack.push(("KeyEthSrcMask", last_off));
19335 break;
19336 }
19337 }
19338 FlowerAttrs::KeyEthType(val) => {
19339 if last_off == offset {
19340 stack.push(("KeyEthType", last_off));
19341 break;
19342 }
19343 }
19344 FlowerAttrs::KeyIpProto(val) => {
19345 if last_off == offset {
19346 stack.push(("KeyIpProto", last_off));
19347 break;
19348 }
19349 }
19350 FlowerAttrs::KeyIpv4Src(val) => {
19351 if last_off == offset {
19352 stack.push(("KeyIpv4Src", last_off));
19353 break;
19354 }
19355 }
19356 FlowerAttrs::KeyIpv4SrcMask(val) => {
19357 if last_off == offset {
19358 stack.push(("KeyIpv4SrcMask", last_off));
19359 break;
19360 }
19361 }
19362 FlowerAttrs::KeyIpv4Dst(val) => {
19363 if last_off == offset {
19364 stack.push(("KeyIpv4Dst", last_off));
19365 break;
19366 }
19367 }
19368 FlowerAttrs::KeyIpv4DstMask(val) => {
19369 if last_off == offset {
19370 stack.push(("KeyIpv4DstMask", last_off));
19371 break;
19372 }
19373 }
19374 FlowerAttrs::KeyIpv6Src(val) => {
19375 if last_off == offset {
19376 stack.push(("KeyIpv6Src", last_off));
19377 break;
19378 }
19379 }
19380 FlowerAttrs::KeyIpv6SrcMask(val) => {
19381 if last_off == offset {
19382 stack.push(("KeyIpv6SrcMask", last_off));
19383 break;
19384 }
19385 }
19386 FlowerAttrs::KeyIpv6Dst(val) => {
19387 if last_off == offset {
19388 stack.push(("KeyIpv6Dst", last_off));
19389 break;
19390 }
19391 }
19392 FlowerAttrs::KeyIpv6DstMask(val) => {
19393 if last_off == offset {
19394 stack.push(("KeyIpv6DstMask", last_off));
19395 break;
19396 }
19397 }
19398 FlowerAttrs::KeyTcpSrc(val) => {
19399 if last_off == offset {
19400 stack.push(("KeyTcpSrc", last_off));
19401 break;
19402 }
19403 }
19404 FlowerAttrs::KeyTcpDst(val) => {
19405 if last_off == offset {
19406 stack.push(("KeyTcpDst", last_off));
19407 break;
19408 }
19409 }
19410 FlowerAttrs::KeyUdpSrc(val) => {
19411 if last_off == offset {
19412 stack.push(("KeyUdpSrc", last_off));
19413 break;
19414 }
19415 }
19416 FlowerAttrs::KeyUdpDst(val) => {
19417 if last_off == offset {
19418 stack.push(("KeyUdpDst", last_off));
19419 break;
19420 }
19421 }
19422 FlowerAttrs::Flags(val) => {
19423 if last_off == offset {
19424 stack.push(("Flags", last_off));
19425 break;
19426 }
19427 }
19428 FlowerAttrs::KeyVlanId(val) => {
19429 if last_off == offset {
19430 stack.push(("KeyVlanId", last_off));
19431 break;
19432 }
19433 }
19434 FlowerAttrs::KeyVlanPrio(val) => {
19435 if last_off == offset {
19436 stack.push(("KeyVlanPrio", last_off));
19437 break;
19438 }
19439 }
19440 FlowerAttrs::KeyVlanEthType(val) => {
19441 if last_off == offset {
19442 stack.push(("KeyVlanEthType", last_off));
19443 break;
19444 }
19445 }
19446 FlowerAttrs::KeyEncKeyId(val) => {
19447 if last_off == offset {
19448 stack.push(("KeyEncKeyId", last_off));
19449 break;
19450 }
19451 }
19452 FlowerAttrs::KeyEncIpv4Src(val) => {
19453 if last_off == offset {
19454 stack.push(("KeyEncIpv4Src", last_off));
19455 break;
19456 }
19457 }
19458 FlowerAttrs::KeyEncIpv4SrcMask(val) => {
19459 if last_off == offset {
19460 stack.push(("KeyEncIpv4SrcMask", last_off));
19461 break;
19462 }
19463 }
19464 FlowerAttrs::KeyEncIpv4Dst(val) => {
19465 if last_off == offset {
19466 stack.push(("KeyEncIpv4Dst", last_off));
19467 break;
19468 }
19469 }
19470 FlowerAttrs::KeyEncIpv4DstMask(val) => {
19471 if last_off == offset {
19472 stack.push(("KeyEncIpv4DstMask", last_off));
19473 break;
19474 }
19475 }
19476 FlowerAttrs::KeyEncIpv6Src(val) => {
19477 if last_off == offset {
19478 stack.push(("KeyEncIpv6Src", last_off));
19479 break;
19480 }
19481 }
19482 FlowerAttrs::KeyEncIpv6SrcMask(val) => {
19483 if last_off == offset {
19484 stack.push(("KeyEncIpv6SrcMask", last_off));
19485 break;
19486 }
19487 }
19488 FlowerAttrs::KeyEncIpv6Dst(val) => {
19489 if last_off == offset {
19490 stack.push(("KeyEncIpv6Dst", last_off));
19491 break;
19492 }
19493 }
19494 FlowerAttrs::KeyEncIpv6DstMask(val) => {
19495 if last_off == offset {
19496 stack.push(("KeyEncIpv6DstMask", last_off));
19497 break;
19498 }
19499 }
19500 FlowerAttrs::KeyTcpSrcMask(val) => {
19501 if last_off == offset {
19502 stack.push(("KeyTcpSrcMask", last_off));
19503 break;
19504 }
19505 }
19506 FlowerAttrs::KeyTcpDstMask(val) => {
19507 if last_off == offset {
19508 stack.push(("KeyTcpDstMask", last_off));
19509 break;
19510 }
19511 }
19512 FlowerAttrs::KeyUdpSrcMask(val) => {
19513 if last_off == offset {
19514 stack.push(("KeyUdpSrcMask", last_off));
19515 break;
19516 }
19517 }
19518 FlowerAttrs::KeyUdpDstMask(val) => {
19519 if last_off == offset {
19520 stack.push(("KeyUdpDstMask", last_off));
19521 break;
19522 }
19523 }
19524 FlowerAttrs::KeySctpSrcMask(val) => {
19525 if last_off == offset {
19526 stack.push(("KeySctpSrcMask", last_off));
19527 break;
19528 }
19529 }
19530 FlowerAttrs::KeySctpDstMask(val) => {
19531 if last_off == offset {
19532 stack.push(("KeySctpDstMask", last_off));
19533 break;
19534 }
19535 }
19536 FlowerAttrs::KeySctpSrc(val) => {
19537 if last_off == offset {
19538 stack.push(("KeySctpSrc", last_off));
19539 break;
19540 }
19541 }
19542 FlowerAttrs::KeySctpDst(val) => {
19543 if last_off == offset {
19544 stack.push(("KeySctpDst", last_off));
19545 break;
19546 }
19547 }
19548 FlowerAttrs::KeyEncUdpSrcPort(val) => {
19549 if last_off == offset {
19550 stack.push(("KeyEncUdpSrcPort", last_off));
19551 break;
19552 }
19553 }
19554 FlowerAttrs::KeyEncUdpSrcPortMask(val) => {
19555 if last_off == offset {
19556 stack.push(("KeyEncUdpSrcPortMask", last_off));
19557 break;
19558 }
19559 }
19560 FlowerAttrs::KeyEncUdpDstPort(val) => {
19561 if last_off == offset {
19562 stack.push(("KeyEncUdpDstPort", last_off));
19563 break;
19564 }
19565 }
19566 FlowerAttrs::KeyEncUdpDstPortMask(val) => {
19567 if last_off == offset {
19568 stack.push(("KeyEncUdpDstPortMask", last_off));
19569 break;
19570 }
19571 }
19572 FlowerAttrs::KeyFlags(val) => {
19573 if last_off == offset {
19574 stack.push(("KeyFlags", last_off));
19575 break;
19576 }
19577 }
19578 FlowerAttrs::KeyFlagsMask(val) => {
19579 if last_off == offset {
19580 stack.push(("KeyFlagsMask", last_off));
19581 break;
19582 }
19583 }
19584 FlowerAttrs::KeyIcmpv4Code(val) => {
19585 if last_off == offset {
19586 stack.push(("KeyIcmpv4Code", last_off));
19587 break;
19588 }
19589 }
19590 FlowerAttrs::KeyIcmpv4CodeMask(val) => {
19591 if last_off == offset {
19592 stack.push(("KeyIcmpv4CodeMask", last_off));
19593 break;
19594 }
19595 }
19596 FlowerAttrs::KeyIcmpv4Type(val) => {
19597 if last_off == offset {
19598 stack.push(("KeyIcmpv4Type", last_off));
19599 break;
19600 }
19601 }
19602 FlowerAttrs::KeyIcmpv4TypeMask(val) => {
19603 if last_off == offset {
19604 stack.push(("KeyIcmpv4TypeMask", last_off));
19605 break;
19606 }
19607 }
19608 FlowerAttrs::KeyIcmpv6Code(val) => {
19609 if last_off == offset {
19610 stack.push(("KeyIcmpv6Code", last_off));
19611 break;
19612 }
19613 }
19614 FlowerAttrs::KeyIcmpv6CodeMask(val) => {
19615 if last_off == offset {
19616 stack.push(("KeyIcmpv6CodeMask", last_off));
19617 break;
19618 }
19619 }
19620 FlowerAttrs::KeyIcmpv6Type(val) => {
19621 if last_off == offset {
19622 stack.push(("KeyIcmpv6Type", last_off));
19623 break;
19624 }
19625 }
19626 FlowerAttrs::KeyIcmpv6TypeMask(val) => {
19627 if last_off == offset {
19628 stack.push(("KeyIcmpv6TypeMask", last_off));
19629 break;
19630 }
19631 }
19632 FlowerAttrs::KeyArpSip(val) => {
19633 if last_off == offset {
19634 stack.push(("KeyArpSip", last_off));
19635 break;
19636 }
19637 }
19638 FlowerAttrs::KeyArpSipMask(val) => {
19639 if last_off == offset {
19640 stack.push(("KeyArpSipMask", last_off));
19641 break;
19642 }
19643 }
19644 FlowerAttrs::KeyArpTip(val) => {
19645 if last_off == offset {
19646 stack.push(("KeyArpTip", last_off));
19647 break;
19648 }
19649 }
19650 FlowerAttrs::KeyArpTipMask(val) => {
19651 if last_off == offset {
19652 stack.push(("KeyArpTipMask", last_off));
19653 break;
19654 }
19655 }
19656 FlowerAttrs::KeyArpOp(val) => {
19657 if last_off == offset {
19658 stack.push(("KeyArpOp", last_off));
19659 break;
19660 }
19661 }
19662 FlowerAttrs::KeyArpOpMask(val) => {
19663 if last_off == offset {
19664 stack.push(("KeyArpOpMask", last_off));
19665 break;
19666 }
19667 }
19668 FlowerAttrs::KeyArpSha(val) => {
19669 if last_off == offset {
19670 stack.push(("KeyArpSha", last_off));
19671 break;
19672 }
19673 }
19674 FlowerAttrs::KeyArpShaMask(val) => {
19675 if last_off == offset {
19676 stack.push(("KeyArpShaMask", last_off));
19677 break;
19678 }
19679 }
19680 FlowerAttrs::KeyArpTha(val) => {
19681 if last_off == offset {
19682 stack.push(("KeyArpTha", last_off));
19683 break;
19684 }
19685 }
19686 FlowerAttrs::KeyArpThaMask(val) => {
19687 if last_off == offset {
19688 stack.push(("KeyArpThaMask", last_off));
19689 break;
19690 }
19691 }
19692 FlowerAttrs::KeyMplsTtl(val) => {
19693 if last_off == offset {
19694 stack.push(("KeyMplsTtl", last_off));
19695 break;
19696 }
19697 }
19698 FlowerAttrs::KeyMplsBos(val) => {
19699 if last_off == offset {
19700 stack.push(("KeyMplsBos", last_off));
19701 break;
19702 }
19703 }
19704 FlowerAttrs::KeyMplsTc(val) => {
19705 if last_off == offset {
19706 stack.push(("KeyMplsTc", last_off));
19707 break;
19708 }
19709 }
19710 FlowerAttrs::KeyMplsLabel(val) => {
19711 if last_off == offset {
19712 stack.push(("KeyMplsLabel", last_off));
19713 break;
19714 }
19715 }
19716 FlowerAttrs::KeyTcpFlags(val) => {
19717 if last_off == offset {
19718 stack.push(("KeyTcpFlags", last_off));
19719 break;
19720 }
19721 }
19722 FlowerAttrs::KeyTcpFlagsMask(val) => {
19723 if last_off == offset {
19724 stack.push(("KeyTcpFlagsMask", last_off));
19725 break;
19726 }
19727 }
19728 FlowerAttrs::KeyIpTos(val) => {
19729 if last_off == offset {
19730 stack.push(("KeyIpTos", last_off));
19731 break;
19732 }
19733 }
19734 FlowerAttrs::KeyIpTosMask(val) => {
19735 if last_off == offset {
19736 stack.push(("KeyIpTosMask", last_off));
19737 break;
19738 }
19739 }
19740 FlowerAttrs::KeyIpTtl(val) => {
19741 if last_off == offset {
19742 stack.push(("KeyIpTtl", last_off));
19743 break;
19744 }
19745 }
19746 FlowerAttrs::KeyIpTtlMask(val) => {
19747 if last_off == offset {
19748 stack.push(("KeyIpTtlMask", last_off));
19749 break;
19750 }
19751 }
19752 FlowerAttrs::KeyCvlanId(val) => {
19753 if last_off == offset {
19754 stack.push(("KeyCvlanId", last_off));
19755 break;
19756 }
19757 }
19758 FlowerAttrs::KeyCvlanPrio(val) => {
19759 if last_off == offset {
19760 stack.push(("KeyCvlanPrio", last_off));
19761 break;
19762 }
19763 }
19764 FlowerAttrs::KeyCvlanEthType(val) => {
19765 if last_off == offset {
19766 stack.push(("KeyCvlanEthType", last_off));
19767 break;
19768 }
19769 }
19770 FlowerAttrs::KeyEncIpTos(val) => {
19771 if last_off == offset {
19772 stack.push(("KeyEncIpTos", last_off));
19773 break;
19774 }
19775 }
19776 FlowerAttrs::KeyEncIpTosMask(val) => {
19777 if last_off == offset {
19778 stack.push(("KeyEncIpTosMask", last_off));
19779 break;
19780 }
19781 }
19782 FlowerAttrs::KeyEncIpTtl(val) => {
19783 if last_off == offset {
19784 stack.push(("KeyEncIpTtl", last_off));
19785 break;
19786 }
19787 }
19788 FlowerAttrs::KeyEncIpTtlMask(val) => {
19789 if last_off == offset {
19790 stack.push(("KeyEncIpTtlMask", last_off));
19791 break;
19792 }
19793 }
19794 FlowerAttrs::KeyEncOpts(val) => {
19795 (stack, missing) = val.lookup_attr(offset, missing_type);
19796 if !stack.is_empty() {
19797 break;
19798 }
19799 }
19800 FlowerAttrs::KeyEncOptsMask(val) => {
19801 (stack, missing) = val.lookup_attr(offset, missing_type);
19802 if !stack.is_empty() {
19803 break;
19804 }
19805 }
19806 FlowerAttrs::InHwCount(val) => {
19807 if last_off == offset {
19808 stack.push(("InHwCount", last_off));
19809 break;
19810 }
19811 }
19812 FlowerAttrs::KeyPortSrcMin(val) => {
19813 if last_off == offset {
19814 stack.push(("KeyPortSrcMin", last_off));
19815 break;
19816 }
19817 }
19818 FlowerAttrs::KeyPortSrcMax(val) => {
19819 if last_off == offset {
19820 stack.push(("KeyPortSrcMax", last_off));
19821 break;
19822 }
19823 }
19824 FlowerAttrs::KeyPortDstMin(val) => {
19825 if last_off == offset {
19826 stack.push(("KeyPortDstMin", last_off));
19827 break;
19828 }
19829 }
19830 FlowerAttrs::KeyPortDstMax(val) => {
19831 if last_off == offset {
19832 stack.push(("KeyPortDstMax", last_off));
19833 break;
19834 }
19835 }
19836 FlowerAttrs::KeyCtState(val) => {
19837 if last_off == offset {
19838 stack.push(("KeyCtState", last_off));
19839 break;
19840 }
19841 }
19842 FlowerAttrs::KeyCtStateMask(val) => {
19843 if last_off == offset {
19844 stack.push(("KeyCtStateMask", last_off));
19845 break;
19846 }
19847 }
19848 FlowerAttrs::KeyCtZone(val) => {
19849 if last_off == offset {
19850 stack.push(("KeyCtZone", last_off));
19851 break;
19852 }
19853 }
19854 FlowerAttrs::KeyCtZoneMask(val) => {
19855 if last_off == offset {
19856 stack.push(("KeyCtZoneMask", last_off));
19857 break;
19858 }
19859 }
19860 FlowerAttrs::KeyCtMark(val) => {
19861 if last_off == offset {
19862 stack.push(("KeyCtMark", last_off));
19863 break;
19864 }
19865 }
19866 FlowerAttrs::KeyCtMarkMask(val) => {
19867 if last_off == offset {
19868 stack.push(("KeyCtMarkMask", last_off));
19869 break;
19870 }
19871 }
19872 FlowerAttrs::KeyCtLabels(val) => {
19873 if last_off == offset {
19874 stack.push(("KeyCtLabels", last_off));
19875 break;
19876 }
19877 }
19878 FlowerAttrs::KeyCtLabelsMask(val) => {
19879 if last_off == offset {
19880 stack.push(("KeyCtLabelsMask", last_off));
19881 break;
19882 }
19883 }
19884 FlowerAttrs::KeyMplsOpts(val) => {
19885 (stack, missing) = val.lookup_attr(offset, missing_type);
19886 if !stack.is_empty() {
19887 break;
19888 }
19889 }
19890 FlowerAttrs::KeyHash(val) => {
19891 if last_off == offset {
19892 stack.push(("KeyHash", last_off));
19893 break;
19894 }
19895 }
19896 FlowerAttrs::KeyHashMask(val) => {
19897 if last_off == offset {
19898 stack.push(("KeyHashMask", last_off));
19899 break;
19900 }
19901 }
19902 FlowerAttrs::KeyNumOfVlans(val) => {
19903 if last_off == offset {
19904 stack.push(("KeyNumOfVlans", last_off));
19905 break;
19906 }
19907 }
19908 FlowerAttrs::KeyPppoeSid(val) => {
19909 if last_off == offset {
19910 stack.push(("KeyPppoeSid", last_off));
19911 break;
19912 }
19913 }
19914 FlowerAttrs::KeyPppProto(val) => {
19915 if last_off == offset {
19916 stack.push(("KeyPppProto", last_off));
19917 break;
19918 }
19919 }
19920 FlowerAttrs::KeyL2tpv3Sid(val) => {
19921 if last_off == offset {
19922 stack.push(("KeyL2tpv3Sid", last_off));
19923 break;
19924 }
19925 }
19926 FlowerAttrs::L2Miss(val) => {
19927 if last_off == offset {
19928 stack.push(("L2Miss", last_off));
19929 break;
19930 }
19931 }
19932 FlowerAttrs::KeyCfm(val) => {
19933 (stack, missing) = val.lookup_attr(offset, missing_type);
19934 if !stack.is_empty() {
19935 break;
19936 }
19937 }
19938 FlowerAttrs::KeySpi(val) => {
19939 if last_off == offset {
19940 stack.push(("KeySpi", last_off));
19941 break;
19942 }
19943 }
19944 FlowerAttrs::KeySpiMask(val) => {
19945 if last_off == offset {
19946 stack.push(("KeySpiMask", last_off));
19947 break;
19948 }
19949 }
19950 FlowerAttrs::KeyEncFlags(val) => {
19951 if last_off == offset {
19952 stack.push(("KeyEncFlags", last_off));
19953 break;
19954 }
19955 }
19956 FlowerAttrs::KeyEncFlagsMask(val) => {
19957 if last_off == offset {
19958 stack.push(("KeyEncFlagsMask", last_off));
19959 break;
19960 }
19961 }
19962 _ => {}
19963 };
19964 last_off = cur + attrs.pos;
19965 }
19966 if !stack.is_empty() {
19967 stack.push(("FlowerAttrs", cur));
19968 }
19969 (stack, missing)
19970 }
19971}
19972#[derive(Clone)]
19973pub enum FlowerKeyEncOptsAttrs<'a> {
19974 Geneve(IterableFlowerKeyEncOptGeneveAttrs<'a>),
19975 Vxlan(IterableFlowerKeyEncOptVxlanAttrs<'a>),
19976 Erspan(IterableFlowerKeyEncOptErspanAttrs<'a>),
19977 Gtp(IterableFlowerKeyEncOptGtpAttrs<'a>),
19978}
19979impl<'a> IterableFlowerKeyEncOptsAttrs<'a> {
19980 pub fn get_geneve(&self) -> Result<IterableFlowerKeyEncOptGeneveAttrs<'a>, ErrorContext> {
19981 let mut iter = self.clone();
19982 iter.pos = 0;
19983 for attr in iter {
19984 if let Ok(FlowerKeyEncOptsAttrs::Geneve(val)) = attr {
19985 return Ok(val);
19986 }
19987 }
19988 Err(ErrorContext::new_missing(
19989 "FlowerKeyEncOptsAttrs",
19990 "Geneve",
19991 self.orig_loc,
19992 self.buf.as_ptr() as usize,
19993 ))
19994 }
19995 pub fn get_vxlan(&self) -> Result<IterableFlowerKeyEncOptVxlanAttrs<'a>, ErrorContext> {
19996 let mut iter = self.clone();
19997 iter.pos = 0;
19998 for attr in iter {
19999 if let Ok(FlowerKeyEncOptsAttrs::Vxlan(val)) = attr {
20000 return Ok(val);
20001 }
20002 }
20003 Err(ErrorContext::new_missing(
20004 "FlowerKeyEncOptsAttrs",
20005 "Vxlan",
20006 self.orig_loc,
20007 self.buf.as_ptr() as usize,
20008 ))
20009 }
20010 pub fn get_erspan(&self) -> Result<IterableFlowerKeyEncOptErspanAttrs<'a>, ErrorContext> {
20011 let mut iter = self.clone();
20012 iter.pos = 0;
20013 for attr in iter {
20014 if let Ok(FlowerKeyEncOptsAttrs::Erspan(val)) = attr {
20015 return Ok(val);
20016 }
20017 }
20018 Err(ErrorContext::new_missing(
20019 "FlowerKeyEncOptsAttrs",
20020 "Erspan",
20021 self.orig_loc,
20022 self.buf.as_ptr() as usize,
20023 ))
20024 }
20025 pub fn get_gtp(&self) -> Result<IterableFlowerKeyEncOptGtpAttrs<'a>, ErrorContext> {
20026 let mut iter = self.clone();
20027 iter.pos = 0;
20028 for attr in iter {
20029 if let Ok(FlowerKeyEncOptsAttrs::Gtp(val)) = attr {
20030 return Ok(val);
20031 }
20032 }
20033 Err(ErrorContext::new_missing(
20034 "FlowerKeyEncOptsAttrs",
20035 "Gtp",
20036 self.orig_loc,
20037 self.buf.as_ptr() as usize,
20038 ))
20039 }
20040}
20041impl FlowerKeyEncOptsAttrs<'_> {
20042 pub fn new<'a>(buf: &'a [u8]) -> IterableFlowerKeyEncOptsAttrs<'a> {
20043 IterableFlowerKeyEncOptsAttrs::with_loc(buf, buf.as_ptr() as usize)
20044 }
20045 fn attr_from_type(r#type: u16) -> Option<&'static str> {
20046 let res = match r#type {
20047 1u16 => "Geneve",
20048 2u16 => "Vxlan",
20049 3u16 => "Erspan",
20050 4u16 => "Gtp",
20051 _ => return None,
20052 };
20053 Some(res)
20054 }
20055}
20056#[derive(Clone, Copy, Default)]
20057pub struct IterableFlowerKeyEncOptsAttrs<'a> {
20058 buf: &'a [u8],
20059 pos: usize,
20060 orig_loc: usize,
20061}
20062impl<'a> IterableFlowerKeyEncOptsAttrs<'a> {
20063 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
20064 Self {
20065 buf,
20066 pos: 0,
20067 orig_loc,
20068 }
20069 }
20070 pub fn get_buf(&self) -> &'a [u8] {
20071 self.buf
20072 }
20073}
20074impl<'a> Iterator for IterableFlowerKeyEncOptsAttrs<'a> {
20075 type Item = Result<FlowerKeyEncOptsAttrs<'a>, ErrorContext>;
20076 fn next(&mut self) -> Option<Self::Item> {
20077 let mut pos;
20078 let mut r#type;
20079 loop {
20080 pos = self.pos;
20081 r#type = None;
20082 if self.buf.len() == self.pos {
20083 return None;
20084 }
20085 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
20086 self.pos = self.buf.len();
20087 break;
20088 };
20089 r#type = Some(header.r#type);
20090 let res = match header.r#type {
20091 1u16 => FlowerKeyEncOptsAttrs::Geneve({
20092 let res = Some(IterableFlowerKeyEncOptGeneveAttrs::with_loc(
20093 next,
20094 self.orig_loc,
20095 ));
20096 let Some(val) = res else { break };
20097 val
20098 }),
20099 2u16 => FlowerKeyEncOptsAttrs::Vxlan({
20100 let res = Some(IterableFlowerKeyEncOptVxlanAttrs::with_loc(
20101 next,
20102 self.orig_loc,
20103 ));
20104 let Some(val) = res else { break };
20105 val
20106 }),
20107 3u16 => FlowerKeyEncOptsAttrs::Erspan({
20108 let res = Some(IterableFlowerKeyEncOptErspanAttrs::with_loc(
20109 next,
20110 self.orig_loc,
20111 ));
20112 let Some(val) = res else { break };
20113 val
20114 }),
20115 4u16 => FlowerKeyEncOptsAttrs::Gtp({
20116 let res = Some(IterableFlowerKeyEncOptGtpAttrs::with_loc(
20117 next,
20118 self.orig_loc,
20119 ));
20120 let Some(val) = res else { break };
20121 val
20122 }),
20123 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
20124 n => continue,
20125 };
20126 return Some(Ok(res));
20127 }
20128 Some(Err(ErrorContext::new(
20129 "FlowerKeyEncOptsAttrs",
20130 r#type.and_then(|t| FlowerKeyEncOptsAttrs::attr_from_type(t)),
20131 self.orig_loc,
20132 self.buf.as_ptr().wrapping_add(pos) as usize,
20133 )))
20134 }
20135}
20136impl<'a> std::fmt::Debug for IterableFlowerKeyEncOptsAttrs<'_> {
20137 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20138 let mut fmt = f.debug_struct("FlowerKeyEncOptsAttrs");
20139 for attr in self.clone() {
20140 let attr = match attr {
20141 Ok(a) => a,
20142 Err(err) => {
20143 fmt.finish()?;
20144 f.write_str("Err(")?;
20145 err.fmt(f)?;
20146 return f.write_str(")");
20147 }
20148 };
20149 match attr {
20150 FlowerKeyEncOptsAttrs::Geneve(val) => fmt.field("Geneve", &val),
20151 FlowerKeyEncOptsAttrs::Vxlan(val) => fmt.field("Vxlan", &val),
20152 FlowerKeyEncOptsAttrs::Erspan(val) => fmt.field("Erspan", &val),
20153 FlowerKeyEncOptsAttrs::Gtp(val) => fmt.field("Gtp", &val),
20154 };
20155 }
20156 fmt.finish()
20157 }
20158}
20159impl IterableFlowerKeyEncOptsAttrs<'_> {
20160 pub fn lookup_attr(
20161 &self,
20162 offset: usize,
20163 missing_type: Option<u16>,
20164 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
20165 let mut stack = Vec::new();
20166 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
20167 if missing_type.is_some() && cur == offset {
20168 stack.push(("FlowerKeyEncOptsAttrs", offset));
20169 return (
20170 stack,
20171 missing_type.and_then(|t| FlowerKeyEncOptsAttrs::attr_from_type(t)),
20172 );
20173 }
20174 if cur > offset || cur + self.buf.len() < offset {
20175 return (stack, None);
20176 }
20177 let mut attrs = self.clone();
20178 let mut last_off = cur + attrs.pos;
20179 let mut missing = None;
20180 while let Some(attr) = attrs.next() {
20181 let Ok(attr) = attr else { break };
20182 match attr {
20183 FlowerKeyEncOptsAttrs::Geneve(val) => {
20184 (stack, missing) = val.lookup_attr(offset, missing_type);
20185 if !stack.is_empty() {
20186 break;
20187 }
20188 }
20189 FlowerKeyEncOptsAttrs::Vxlan(val) => {
20190 (stack, missing) = val.lookup_attr(offset, missing_type);
20191 if !stack.is_empty() {
20192 break;
20193 }
20194 }
20195 FlowerKeyEncOptsAttrs::Erspan(val) => {
20196 (stack, missing) = val.lookup_attr(offset, missing_type);
20197 if !stack.is_empty() {
20198 break;
20199 }
20200 }
20201 FlowerKeyEncOptsAttrs::Gtp(val) => {
20202 (stack, missing) = val.lookup_attr(offset, missing_type);
20203 if !stack.is_empty() {
20204 break;
20205 }
20206 }
20207 _ => {}
20208 };
20209 last_off = cur + attrs.pos;
20210 }
20211 if !stack.is_empty() {
20212 stack.push(("FlowerKeyEncOptsAttrs", cur));
20213 }
20214 (stack, missing)
20215 }
20216}
20217#[derive(Clone)]
20218pub enum FlowerKeyEncOptGeneveAttrs<'a> {
20219 Class(u16),
20220 Type(u8),
20221 Data(&'a [u8]),
20222}
20223impl<'a> IterableFlowerKeyEncOptGeneveAttrs<'a> {
20224 pub fn get_class(&self) -> Result<u16, ErrorContext> {
20225 let mut iter = self.clone();
20226 iter.pos = 0;
20227 for attr in iter {
20228 if let Ok(FlowerKeyEncOptGeneveAttrs::Class(val)) = attr {
20229 return Ok(val);
20230 }
20231 }
20232 Err(ErrorContext::new_missing(
20233 "FlowerKeyEncOptGeneveAttrs",
20234 "Class",
20235 self.orig_loc,
20236 self.buf.as_ptr() as usize,
20237 ))
20238 }
20239 pub fn get_type(&self) -> Result<u8, ErrorContext> {
20240 let mut iter = self.clone();
20241 iter.pos = 0;
20242 for attr in iter {
20243 if let Ok(FlowerKeyEncOptGeneveAttrs::Type(val)) = attr {
20244 return Ok(val);
20245 }
20246 }
20247 Err(ErrorContext::new_missing(
20248 "FlowerKeyEncOptGeneveAttrs",
20249 "Type",
20250 self.orig_loc,
20251 self.buf.as_ptr() as usize,
20252 ))
20253 }
20254 pub fn get_data(&self) -> Result<&'a [u8], ErrorContext> {
20255 let mut iter = self.clone();
20256 iter.pos = 0;
20257 for attr in iter {
20258 if let Ok(FlowerKeyEncOptGeneveAttrs::Data(val)) = attr {
20259 return Ok(val);
20260 }
20261 }
20262 Err(ErrorContext::new_missing(
20263 "FlowerKeyEncOptGeneveAttrs",
20264 "Data",
20265 self.orig_loc,
20266 self.buf.as_ptr() as usize,
20267 ))
20268 }
20269}
20270impl FlowerKeyEncOptGeneveAttrs<'_> {
20271 pub fn new<'a>(buf: &'a [u8]) -> IterableFlowerKeyEncOptGeneveAttrs<'a> {
20272 IterableFlowerKeyEncOptGeneveAttrs::with_loc(buf, buf.as_ptr() as usize)
20273 }
20274 fn attr_from_type(r#type: u16) -> Option<&'static str> {
20275 let res = match r#type {
20276 1u16 => "Class",
20277 2u16 => "Type",
20278 3u16 => "Data",
20279 _ => return None,
20280 };
20281 Some(res)
20282 }
20283}
20284#[derive(Clone, Copy, Default)]
20285pub struct IterableFlowerKeyEncOptGeneveAttrs<'a> {
20286 buf: &'a [u8],
20287 pos: usize,
20288 orig_loc: usize,
20289}
20290impl<'a> IterableFlowerKeyEncOptGeneveAttrs<'a> {
20291 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
20292 Self {
20293 buf,
20294 pos: 0,
20295 orig_loc,
20296 }
20297 }
20298 pub fn get_buf(&self) -> &'a [u8] {
20299 self.buf
20300 }
20301}
20302impl<'a> Iterator for IterableFlowerKeyEncOptGeneveAttrs<'a> {
20303 type Item = Result<FlowerKeyEncOptGeneveAttrs<'a>, ErrorContext>;
20304 fn next(&mut self) -> Option<Self::Item> {
20305 let mut pos;
20306 let mut r#type;
20307 loop {
20308 pos = self.pos;
20309 r#type = None;
20310 if self.buf.len() == self.pos {
20311 return None;
20312 }
20313 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
20314 self.pos = self.buf.len();
20315 break;
20316 };
20317 r#type = Some(header.r#type);
20318 let res = match header.r#type {
20319 1u16 => FlowerKeyEncOptGeneveAttrs::Class({
20320 let res = parse_u16(next);
20321 let Some(val) = res else { break };
20322 val
20323 }),
20324 2u16 => FlowerKeyEncOptGeneveAttrs::Type({
20325 let res = parse_u8(next);
20326 let Some(val) = res else { break };
20327 val
20328 }),
20329 3u16 => FlowerKeyEncOptGeneveAttrs::Data({
20330 let res = Some(next);
20331 let Some(val) = res else { break };
20332 val
20333 }),
20334 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
20335 n => continue,
20336 };
20337 return Some(Ok(res));
20338 }
20339 Some(Err(ErrorContext::new(
20340 "FlowerKeyEncOptGeneveAttrs",
20341 r#type.and_then(|t| FlowerKeyEncOptGeneveAttrs::attr_from_type(t)),
20342 self.orig_loc,
20343 self.buf.as_ptr().wrapping_add(pos) as usize,
20344 )))
20345 }
20346}
20347impl<'a> std::fmt::Debug for IterableFlowerKeyEncOptGeneveAttrs<'_> {
20348 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20349 let mut fmt = f.debug_struct("FlowerKeyEncOptGeneveAttrs");
20350 for attr in self.clone() {
20351 let attr = match attr {
20352 Ok(a) => a,
20353 Err(err) => {
20354 fmt.finish()?;
20355 f.write_str("Err(")?;
20356 err.fmt(f)?;
20357 return f.write_str(")");
20358 }
20359 };
20360 match attr {
20361 FlowerKeyEncOptGeneveAttrs::Class(val) => fmt.field("Class", &val),
20362 FlowerKeyEncOptGeneveAttrs::Type(val) => fmt.field("Type", &val),
20363 FlowerKeyEncOptGeneveAttrs::Data(val) => fmt.field("Data", &val),
20364 };
20365 }
20366 fmt.finish()
20367 }
20368}
20369impl IterableFlowerKeyEncOptGeneveAttrs<'_> {
20370 pub fn lookup_attr(
20371 &self,
20372 offset: usize,
20373 missing_type: Option<u16>,
20374 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
20375 let mut stack = Vec::new();
20376 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
20377 if missing_type.is_some() && cur == offset {
20378 stack.push(("FlowerKeyEncOptGeneveAttrs", offset));
20379 return (
20380 stack,
20381 missing_type.and_then(|t| FlowerKeyEncOptGeneveAttrs::attr_from_type(t)),
20382 );
20383 }
20384 if cur > offset || cur + self.buf.len() < offset {
20385 return (stack, None);
20386 }
20387 let mut attrs = self.clone();
20388 let mut last_off = cur + attrs.pos;
20389 while let Some(attr) = attrs.next() {
20390 let Ok(attr) = attr else { break };
20391 match attr {
20392 FlowerKeyEncOptGeneveAttrs::Class(val) => {
20393 if last_off == offset {
20394 stack.push(("Class", last_off));
20395 break;
20396 }
20397 }
20398 FlowerKeyEncOptGeneveAttrs::Type(val) => {
20399 if last_off == offset {
20400 stack.push(("Type", last_off));
20401 break;
20402 }
20403 }
20404 FlowerKeyEncOptGeneveAttrs::Data(val) => {
20405 if last_off == offset {
20406 stack.push(("Data", last_off));
20407 break;
20408 }
20409 }
20410 _ => {}
20411 };
20412 last_off = cur + attrs.pos;
20413 }
20414 if !stack.is_empty() {
20415 stack.push(("FlowerKeyEncOptGeneveAttrs", cur));
20416 }
20417 (stack, None)
20418 }
20419}
20420#[derive(Clone)]
20421pub enum FlowerKeyEncOptVxlanAttrs {
20422 Gbp(u32),
20423}
20424impl<'a> IterableFlowerKeyEncOptVxlanAttrs<'a> {
20425 pub fn get_gbp(&self) -> Result<u32, ErrorContext> {
20426 let mut iter = self.clone();
20427 iter.pos = 0;
20428 for attr in iter {
20429 if let Ok(FlowerKeyEncOptVxlanAttrs::Gbp(val)) = attr {
20430 return Ok(val);
20431 }
20432 }
20433 Err(ErrorContext::new_missing(
20434 "FlowerKeyEncOptVxlanAttrs",
20435 "Gbp",
20436 self.orig_loc,
20437 self.buf.as_ptr() as usize,
20438 ))
20439 }
20440}
20441impl FlowerKeyEncOptVxlanAttrs {
20442 pub fn new<'a>(buf: &'a [u8]) -> IterableFlowerKeyEncOptVxlanAttrs<'a> {
20443 IterableFlowerKeyEncOptVxlanAttrs::with_loc(buf, buf.as_ptr() as usize)
20444 }
20445 fn attr_from_type(r#type: u16) -> Option<&'static str> {
20446 let res = match r#type {
20447 1u16 => "Gbp",
20448 _ => return None,
20449 };
20450 Some(res)
20451 }
20452}
20453#[derive(Clone, Copy, Default)]
20454pub struct IterableFlowerKeyEncOptVxlanAttrs<'a> {
20455 buf: &'a [u8],
20456 pos: usize,
20457 orig_loc: usize,
20458}
20459impl<'a> IterableFlowerKeyEncOptVxlanAttrs<'a> {
20460 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
20461 Self {
20462 buf,
20463 pos: 0,
20464 orig_loc,
20465 }
20466 }
20467 pub fn get_buf(&self) -> &'a [u8] {
20468 self.buf
20469 }
20470}
20471impl<'a> Iterator for IterableFlowerKeyEncOptVxlanAttrs<'a> {
20472 type Item = Result<FlowerKeyEncOptVxlanAttrs, ErrorContext>;
20473 fn next(&mut self) -> Option<Self::Item> {
20474 let mut pos;
20475 let mut r#type;
20476 loop {
20477 pos = self.pos;
20478 r#type = None;
20479 if self.buf.len() == self.pos {
20480 return None;
20481 }
20482 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
20483 self.pos = self.buf.len();
20484 break;
20485 };
20486 r#type = Some(header.r#type);
20487 let res = match header.r#type {
20488 1u16 => FlowerKeyEncOptVxlanAttrs::Gbp({
20489 let res = parse_u32(next);
20490 let Some(val) = res else { break };
20491 val
20492 }),
20493 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
20494 n => continue,
20495 };
20496 return Some(Ok(res));
20497 }
20498 Some(Err(ErrorContext::new(
20499 "FlowerKeyEncOptVxlanAttrs",
20500 r#type.and_then(|t| FlowerKeyEncOptVxlanAttrs::attr_from_type(t)),
20501 self.orig_loc,
20502 self.buf.as_ptr().wrapping_add(pos) as usize,
20503 )))
20504 }
20505}
20506impl std::fmt::Debug for IterableFlowerKeyEncOptVxlanAttrs<'_> {
20507 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20508 let mut fmt = f.debug_struct("FlowerKeyEncOptVxlanAttrs");
20509 for attr in self.clone() {
20510 let attr = match attr {
20511 Ok(a) => a,
20512 Err(err) => {
20513 fmt.finish()?;
20514 f.write_str("Err(")?;
20515 err.fmt(f)?;
20516 return f.write_str(")");
20517 }
20518 };
20519 match attr {
20520 FlowerKeyEncOptVxlanAttrs::Gbp(val) => fmt.field("Gbp", &val),
20521 };
20522 }
20523 fmt.finish()
20524 }
20525}
20526impl IterableFlowerKeyEncOptVxlanAttrs<'_> {
20527 pub fn lookup_attr(
20528 &self,
20529 offset: usize,
20530 missing_type: Option<u16>,
20531 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
20532 let mut stack = Vec::new();
20533 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
20534 if missing_type.is_some() && cur == offset {
20535 stack.push(("FlowerKeyEncOptVxlanAttrs", offset));
20536 return (
20537 stack,
20538 missing_type.and_then(|t| FlowerKeyEncOptVxlanAttrs::attr_from_type(t)),
20539 );
20540 }
20541 if cur > offset || cur + self.buf.len() < offset {
20542 return (stack, None);
20543 }
20544 let mut attrs = self.clone();
20545 let mut last_off = cur + attrs.pos;
20546 while let Some(attr) = attrs.next() {
20547 let Ok(attr) = attr else { break };
20548 match attr {
20549 FlowerKeyEncOptVxlanAttrs::Gbp(val) => {
20550 if last_off == offset {
20551 stack.push(("Gbp", last_off));
20552 break;
20553 }
20554 }
20555 _ => {}
20556 };
20557 last_off = cur + attrs.pos;
20558 }
20559 if !stack.is_empty() {
20560 stack.push(("FlowerKeyEncOptVxlanAttrs", cur));
20561 }
20562 (stack, None)
20563 }
20564}
20565#[derive(Clone)]
20566pub enum FlowerKeyEncOptErspanAttrs {
20567 Ver(u8),
20568 Index(u32),
20569 Dir(u8),
20570 Hwid(u8),
20571}
20572impl<'a> IterableFlowerKeyEncOptErspanAttrs<'a> {
20573 pub fn get_ver(&self) -> Result<u8, ErrorContext> {
20574 let mut iter = self.clone();
20575 iter.pos = 0;
20576 for attr in iter {
20577 if let Ok(FlowerKeyEncOptErspanAttrs::Ver(val)) = attr {
20578 return Ok(val);
20579 }
20580 }
20581 Err(ErrorContext::new_missing(
20582 "FlowerKeyEncOptErspanAttrs",
20583 "Ver",
20584 self.orig_loc,
20585 self.buf.as_ptr() as usize,
20586 ))
20587 }
20588 pub fn get_index(&self) -> Result<u32, ErrorContext> {
20589 let mut iter = self.clone();
20590 iter.pos = 0;
20591 for attr in iter {
20592 if let Ok(FlowerKeyEncOptErspanAttrs::Index(val)) = attr {
20593 return Ok(val);
20594 }
20595 }
20596 Err(ErrorContext::new_missing(
20597 "FlowerKeyEncOptErspanAttrs",
20598 "Index",
20599 self.orig_loc,
20600 self.buf.as_ptr() as usize,
20601 ))
20602 }
20603 pub fn get_dir(&self) -> Result<u8, ErrorContext> {
20604 let mut iter = self.clone();
20605 iter.pos = 0;
20606 for attr in iter {
20607 if let Ok(FlowerKeyEncOptErspanAttrs::Dir(val)) = attr {
20608 return Ok(val);
20609 }
20610 }
20611 Err(ErrorContext::new_missing(
20612 "FlowerKeyEncOptErspanAttrs",
20613 "Dir",
20614 self.orig_loc,
20615 self.buf.as_ptr() as usize,
20616 ))
20617 }
20618 pub fn get_hwid(&self) -> Result<u8, ErrorContext> {
20619 let mut iter = self.clone();
20620 iter.pos = 0;
20621 for attr in iter {
20622 if let Ok(FlowerKeyEncOptErspanAttrs::Hwid(val)) = attr {
20623 return Ok(val);
20624 }
20625 }
20626 Err(ErrorContext::new_missing(
20627 "FlowerKeyEncOptErspanAttrs",
20628 "Hwid",
20629 self.orig_loc,
20630 self.buf.as_ptr() as usize,
20631 ))
20632 }
20633}
20634impl FlowerKeyEncOptErspanAttrs {
20635 pub fn new<'a>(buf: &'a [u8]) -> IterableFlowerKeyEncOptErspanAttrs<'a> {
20636 IterableFlowerKeyEncOptErspanAttrs::with_loc(buf, buf.as_ptr() as usize)
20637 }
20638 fn attr_from_type(r#type: u16) -> Option<&'static str> {
20639 let res = match r#type {
20640 1u16 => "Ver",
20641 2u16 => "Index",
20642 3u16 => "Dir",
20643 4u16 => "Hwid",
20644 _ => return None,
20645 };
20646 Some(res)
20647 }
20648}
20649#[derive(Clone, Copy, Default)]
20650pub struct IterableFlowerKeyEncOptErspanAttrs<'a> {
20651 buf: &'a [u8],
20652 pos: usize,
20653 orig_loc: usize,
20654}
20655impl<'a> IterableFlowerKeyEncOptErspanAttrs<'a> {
20656 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
20657 Self {
20658 buf,
20659 pos: 0,
20660 orig_loc,
20661 }
20662 }
20663 pub fn get_buf(&self) -> &'a [u8] {
20664 self.buf
20665 }
20666}
20667impl<'a> Iterator for IterableFlowerKeyEncOptErspanAttrs<'a> {
20668 type Item = Result<FlowerKeyEncOptErspanAttrs, ErrorContext>;
20669 fn next(&mut self) -> Option<Self::Item> {
20670 let mut pos;
20671 let mut r#type;
20672 loop {
20673 pos = self.pos;
20674 r#type = None;
20675 if self.buf.len() == self.pos {
20676 return None;
20677 }
20678 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
20679 self.pos = self.buf.len();
20680 break;
20681 };
20682 r#type = Some(header.r#type);
20683 let res = match header.r#type {
20684 1u16 => FlowerKeyEncOptErspanAttrs::Ver({
20685 let res = parse_u8(next);
20686 let Some(val) = res else { break };
20687 val
20688 }),
20689 2u16 => FlowerKeyEncOptErspanAttrs::Index({
20690 let res = parse_u32(next);
20691 let Some(val) = res else { break };
20692 val
20693 }),
20694 3u16 => FlowerKeyEncOptErspanAttrs::Dir({
20695 let res = parse_u8(next);
20696 let Some(val) = res else { break };
20697 val
20698 }),
20699 4u16 => FlowerKeyEncOptErspanAttrs::Hwid({
20700 let res = parse_u8(next);
20701 let Some(val) = res else { break };
20702 val
20703 }),
20704 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
20705 n => continue,
20706 };
20707 return Some(Ok(res));
20708 }
20709 Some(Err(ErrorContext::new(
20710 "FlowerKeyEncOptErspanAttrs",
20711 r#type.and_then(|t| FlowerKeyEncOptErspanAttrs::attr_from_type(t)),
20712 self.orig_loc,
20713 self.buf.as_ptr().wrapping_add(pos) as usize,
20714 )))
20715 }
20716}
20717impl std::fmt::Debug for IterableFlowerKeyEncOptErspanAttrs<'_> {
20718 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20719 let mut fmt = f.debug_struct("FlowerKeyEncOptErspanAttrs");
20720 for attr in self.clone() {
20721 let attr = match attr {
20722 Ok(a) => a,
20723 Err(err) => {
20724 fmt.finish()?;
20725 f.write_str("Err(")?;
20726 err.fmt(f)?;
20727 return f.write_str(")");
20728 }
20729 };
20730 match attr {
20731 FlowerKeyEncOptErspanAttrs::Ver(val) => fmt.field("Ver", &val),
20732 FlowerKeyEncOptErspanAttrs::Index(val) => fmt.field("Index", &val),
20733 FlowerKeyEncOptErspanAttrs::Dir(val) => fmt.field("Dir", &val),
20734 FlowerKeyEncOptErspanAttrs::Hwid(val) => fmt.field("Hwid", &val),
20735 };
20736 }
20737 fmt.finish()
20738 }
20739}
20740impl IterableFlowerKeyEncOptErspanAttrs<'_> {
20741 pub fn lookup_attr(
20742 &self,
20743 offset: usize,
20744 missing_type: Option<u16>,
20745 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
20746 let mut stack = Vec::new();
20747 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
20748 if missing_type.is_some() && cur == offset {
20749 stack.push(("FlowerKeyEncOptErspanAttrs", offset));
20750 return (
20751 stack,
20752 missing_type.and_then(|t| FlowerKeyEncOptErspanAttrs::attr_from_type(t)),
20753 );
20754 }
20755 if cur > offset || cur + self.buf.len() < offset {
20756 return (stack, None);
20757 }
20758 let mut attrs = self.clone();
20759 let mut last_off = cur + attrs.pos;
20760 while let Some(attr) = attrs.next() {
20761 let Ok(attr) = attr else { break };
20762 match attr {
20763 FlowerKeyEncOptErspanAttrs::Ver(val) => {
20764 if last_off == offset {
20765 stack.push(("Ver", last_off));
20766 break;
20767 }
20768 }
20769 FlowerKeyEncOptErspanAttrs::Index(val) => {
20770 if last_off == offset {
20771 stack.push(("Index", last_off));
20772 break;
20773 }
20774 }
20775 FlowerKeyEncOptErspanAttrs::Dir(val) => {
20776 if last_off == offset {
20777 stack.push(("Dir", last_off));
20778 break;
20779 }
20780 }
20781 FlowerKeyEncOptErspanAttrs::Hwid(val) => {
20782 if last_off == offset {
20783 stack.push(("Hwid", last_off));
20784 break;
20785 }
20786 }
20787 _ => {}
20788 };
20789 last_off = cur + attrs.pos;
20790 }
20791 if !stack.is_empty() {
20792 stack.push(("FlowerKeyEncOptErspanAttrs", cur));
20793 }
20794 (stack, None)
20795 }
20796}
20797#[derive(Clone)]
20798pub enum FlowerKeyEncOptGtpAttrs {
20799 PduType(u8),
20800 Qfi(u8),
20801}
20802impl<'a> IterableFlowerKeyEncOptGtpAttrs<'a> {
20803 pub fn get_pdu_type(&self) -> Result<u8, ErrorContext> {
20804 let mut iter = self.clone();
20805 iter.pos = 0;
20806 for attr in iter {
20807 if let Ok(FlowerKeyEncOptGtpAttrs::PduType(val)) = attr {
20808 return Ok(val);
20809 }
20810 }
20811 Err(ErrorContext::new_missing(
20812 "FlowerKeyEncOptGtpAttrs",
20813 "PduType",
20814 self.orig_loc,
20815 self.buf.as_ptr() as usize,
20816 ))
20817 }
20818 pub fn get_qfi(&self) -> Result<u8, ErrorContext> {
20819 let mut iter = self.clone();
20820 iter.pos = 0;
20821 for attr in iter {
20822 if let Ok(FlowerKeyEncOptGtpAttrs::Qfi(val)) = attr {
20823 return Ok(val);
20824 }
20825 }
20826 Err(ErrorContext::new_missing(
20827 "FlowerKeyEncOptGtpAttrs",
20828 "Qfi",
20829 self.orig_loc,
20830 self.buf.as_ptr() as usize,
20831 ))
20832 }
20833}
20834impl FlowerKeyEncOptGtpAttrs {
20835 pub fn new<'a>(buf: &'a [u8]) -> IterableFlowerKeyEncOptGtpAttrs<'a> {
20836 IterableFlowerKeyEncOptGtpAttrs::with_loc(buf, buf.as_ptr() as usize)
20837 }
20838 fn attr_from_type(r#type: u16) -> Option<&'static str> {
20839 let res = match r#type {
20840 1u16 => "PduType",
20841 2u16 => "Qfi",
20842 _ => return None,
20843 };
20844 Some(res)
20845 }
20846}
20847#[derive(Clone, Copy, Default)]
20848pub struct IterableFlowerKeyEncOptGtpAttrs<'a> {
20849 buf: &'a [u8],
20850 pos: usize,
20851 orig_loc: usize,
20852}
20853impl<'a> IterableFlowerKeyEncOptGtpAttrs<'a> {
20854 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
20855 Self {
20856 buf,
20857 pos: 0,
20858 orig_loc,
20859 }
20860 }
20861 pub fn get_buf(&self) -> &'a [u8] {
20862 self.buf
20863 }
20864}
20865impl<'a> Iterator for IterableFlowerKeyEncOptGtpAttrs<'a> {
20866 type Item = Result<FlowerKeyEncOptGtpAttrs, ErrorContext>;
20867 fn next(&mut self) -> Option<Self::Item> {
20868 let mut pos;
20869 let mut r#type;
20870 loop {
20871 pos = self.pos;
20872 r#type = None;
20873 if self.buf.len() == self.pos {
20874 return None;
20875 }
20876 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
20877 self.pos = self.buf.len();
20878 break;
20879 };
20880 r#type = Some(header.r#type);
20881 let res = match header.r#type {
20882 1u16 => FlowerKeyEncOptGtpAttrs::PduType({
20883 let res = parse_u8(next);
20884 let Some(val) = res else { break };
20885 val
20886 }),
20887 2u16 => FlowerKeyEncOptGtpAttrs::Qfi({
20888 let res = parse_u8(next);
20889 let Some(val) = res else { break };
20890 val
20891 }),
20892 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
20893 n => continue,
20894 };
20895 return Some(Ok(res));
20896 }
20897 Some(Err(ErrorContext::new(
20898 "FlowerKeyEncOptGtpAttrs",
20899 r#type.and_then(|t| FlowerKeyEncOptGtpAttrs::attr_from_type(t)),
20900 self.orig_loc,
20901 self.buf.as_ptr().wrapping_add(pos) as usize,
20902 )))
20903 }
20904}
20905impl std::fmt::Debug for IterableFlowerKeyEncOptGtpAttrs<'_> {
20906 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20907 let mut fmt = f.debug_struct("FlowerKeyEncOptGtpAttrs");
20908 for attr in self.clone() {
20909 let attr = match attr {
20910 Ok(a) => a,
20911 Err(err) => {
20912 fmt.finish()?;
20913 f.write_str("Err(")?;
20914 err.fmt(f)?;
20915 return f.write_str(")");
20916 }
20917 };
20918 match attr {
20919 FlowerKeyEncOptGtpAttrs::PduType(val) => fmt.field("PduType", &val),
20920 FlowerKeyEncOptGtpAttrs::Qfi(val) => fmt.field("Qfi", &val),
20921 };
20922 }
20923 fmt.finish()
20924 }
20925}
20926impl IterableFlowerKeyEncOptGtpAttrs<'_> {
20927 pub fn lookup_attr(
20928 &self,
20929 offset: usize,
20930 missing_type: Option<u16>,
20931 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
20932 let mut stack = Vec::new();
20933 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
20934 if missing_type.is_some() && cur == offset {
20935 stack.push(("FlowerKeyEncOptGtpAttrs", offset));
20936 return (
20937 stack,
20938 missing_type.and_then(|t| FlowerKeyEncOptGtpAttrs::attr_from_type(t)),
20939 );
20940 }
20941 if cur > offset || cur + self.buf.len() < offset {
20942 return (stack, None);
20943 }
20944 let mut attrs = self.clone();
20945 let mut last_off = cur + attrs.pos;
20946 while let Some(attr) = attrs.next() {
20947 let Ok(attr) = attr else { break };
20948 match attr {
20949 FlowerKeyEncOptGtpAttrs::PduType(val) => {
20950 if last_off == offset {
20951 stack.push(("PduType", last_off));
20952 break;
20953 }
20954 }
20955 FlowerKeyEncOptGtpAttrs::Qfi(val) => {
20956 if last_off == offset {
20957 stack.push(("Qfi", last_off));
20958 break;
20959 }
20960 }
20961 _ => {}
20962 };
20963 last_off = cur + attrs.pos;
20964 }
20965 if !stack.is_empty() {
20966 stack.push(("FlowerKeyEncOptGtpAttrs", cur));
20967 }
20968 (stack, None)
20969 }
20970}
20971#[derive(Clone)]
20972pub enum FlowerKeyMplsOptAttrs {
20973 LseDepth(u8),
20974 LseTtl(u8),
20975 LseBos(u8),
20976 LseTc(u8),
20977 LseLabel(u32),
20978}
20979impl<'a> IterableFlowerKeyMplsOptAttrs<'a> {
20980 pub fn get_lse_depth(&self) -> Result<u8, ErrorContext> {
20981 let mut iter = self.clone();
20982 iter.pos = 0;
20983 for attr in iter {
20984 if let Ok(FlowerKeyMplsOptAttrs::LseDepth(val)) = attr {
20985 return Ok(val);
20986 }
20987 }
20988 Err(ErrorContext::new_missing(
20989 "FlowerKeyMplsOptAttrs",
20990 "LseDepth",
20991 self.orig_loc,
20992 self.buf.as_ptr() as usize,
20993 ))
20994 }
20995 pub fn get_lse_ttl(&self) -> Result<u8, ErrorContext> {
20996 let mut iter = self.clone();
20997 iter.pos = 0;
20998 for attr in iter {
20999 if let Ok(FlowerKeyMplsOptAttrs::LseTtl(val)) = attr {
21000 return Ok(val);
21001 }
21002 }
21003 Err(ErrorContext::new_missing(
21004 "FlowerKeyMplsOptAttrs",
21005 "LseTtl",
21006 self.orig_loc,
21007 self.buf.as_ptr() as usize,
21008 ))
21009 }
21010 pub fn get_lse_bos(&self) -> Result<u8, ErrorContext> {
21011 let mut iter = self.clone();
21012 iter.pos = 0;
21013 for attr in iter {
21014 if let Ok(FlowerKeyMplsOptAttrs::LseBos(val)) = attr {
21015 return Ok(val);
21016 }
21017 }
21018 Err(ErrorContext::new_missing(
21019 "FlowerKeyMplsOptAttrs",
21020 "LseBos",
21021 self.orig_loc,
21022 self.buf.as_ptr() as usize,
21023 ))
21024 }
21025 pub fn get_lse_tc(&self) -> Result<u8, ErrorContext> {
21026 let mut iter = self.clone();
21027 iter.pos = 0;
21028 for attr in iter {
21029 if let Ok(FlowerKeyMplsOptAttrs::LseTc(val)) = attr {
21030 return Ok(val);
21031 }
21032 }
21033 Err(ErrorContext::new_missing(
21034 "FlowerKeyMplsOptAttrs",
21035 "LseTc",
21036 self.orig_loc,
21037 self.buf.as_ptr() as usize,
21038 ))
21039 }
21040 pub fn get_lse_label(&self) -> Result<u32, ErrorContext> {
21041 let mut iter = self.clone();
21042 iter.pos = 0;
21043 for attr in iter {
21044 if let Ok(FlowerKeyMplsOptAttrs::LseLabel(val)) = attr {
21045 return Ok(val);
21046 }
21047 }
21048 Err(ErrorContext::new_missing(
21049 "FlowerKeyMplsOptAttrs",
21050 "LseLabel",
21051 self.orig_loc,
21052 self.buf.as_ptr() as usize,
21053 ))
21054 }
21055}
21056impl FlowerKeyMplsOptAttrs {
21057 pub fn new<'a>(buf: &'a [u8]) -> IterableFlowerKeyMplsOptAttrs<'a> {
21058 IterableFlowerKeyMplsOptAttrs::with_loc(buf, buf.as_ptr() as usize)
21059 }
21060 fn attr_from_type(r#type: u16) -> Option<&'static str> {
21061 let res = match r#type {
21062 1u16 => "LseDepth",
21063 2u16 => "LseTtl",
21064 3u16 => "LseBos",
21065 4u16 => "LseTc",
21066 5u16 => "LseLabel",
21067 _ => return None,
21068 };
21069 Some(res)
21070 }
21071}
21072#[derive(Clone, Copy, Default)]
21073pub struct IterableFlowerKeyMplsOptAttrs<'a> {
21074 buf: &'a [u8],
21075 pos: usize,
21076 orig_loc: usize,
21077}
21078impl<'a> IterableFlowerKeyMplsOptAttrs<'a> {
21079 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
21080 Self {
21081 buf,
21082 pos: 0,
21083 orig_loc,
21084 }
21085 }
21086 pub fn get_buf(&self) -> &'a [u8] {
21087 self.buf
21088 }
21089}
21090impl<'a> Iterator for IterableFlowerKeyMplsOptAttrs<'a> {
21091 type Item = Result<FlowerKeyMplsOptAttrs, ErrorContext>;
21092 fn next(&mut self) -> Option<Self::Item> {
21093 let mut pos;
21094 let mut r#type;
21095 loop {
21096 pos = self.pos;
21097 r#type = None;
21098 if self.buf.len() == self.pos {
21099 return None;
21100 }
21101 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
21102 self.pos = self.buf.len();
21103 break;
21104 };
21105 r#type = Some(header.r#type);
21106 let res = match header.r#type {
21107 1u16 => FlowerKeyMplsOptAttrs::LseDepth({
21108 let res = parse_u8(next);
21109 let Some(val) = res else { break };
21110 val
21111 }),
21112 2u16 => FlowerKeyMplsOptAttrs::LseTtl({
21113 let res = parse_u8(next);
21114 let Some(val) = res else { break };
21115 val
21116 }),
21117 3u16 => FlowerKeyMplsOptAttrs::LseBos({
21118 let res = parse_u8(next);
21119 let Some(val) = res else { break };
21120 val
21121 }),
21122 4u16 => FlowerKeyMplsOptAttrs::LseTc({
21123 let res = parse_u8(next);
21124 let Some(val) = res else { break };
21125 val
21126 }),
21127 5u16 => FlowerKeyMplsOptAttrs::LseLabel({
21128 let res = parse_u32(next);
21129 let Some(val) = res else { break };
21130 val
21131 }),
21132 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
21133 n => continue,
21134 };
21135 return Some(Ok(res));
21136 }
21137 Some(Err(ErrorContext::new(
21138 "FlowerKeyMplsOptAttrs",
21139 r#type.and_then(|t| FlowerKeyMplsOptAttrs::attr_from_type(t)),
21140 self.orig_loc,
21141 self.buf.as_ptr().wrapping_add(pos) as usize,
21142 )))
21143 }
21144}
21145impl std::fmt::Debug for IterableFlowerKeyMplsOptAttrs<'_> {
21146 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21147 let mut fmt = f.debug_struct("FlowerKeyMplsOptAttrs");
21148 for attr in self.clone() {
21149 let attr = match attr {
21150 Ok(a) => a,
21151 Err(err) => {
21152 fmt.finish()?;
21153 f.write_str("Err(")?;
21154 err.fmt(f)?;
21155 return f.write_str(")");
21156 }
21157 };
21158 match attr {
21159 FlowerKeyMplsOptAttrs::LseDepth(val) => fmt.field("LseDepth", &val),
21160 FlowerKeyMplsOptAttrs::LseTtl(val) => fmt.field("LseTtl", &val),
21161 FlowerKeyMplsOptAttrs::LseBos(val) => fmt.field("LseBos", &val),
21162 FlowerKeyMplsOptAttrs::LseTc(val) => fmt.field("LseTc", &val),
21163 FlowerKeyMplsOptAttrs::LseLabel(val) => fmt.field("LseLabel", &val),
21164 };
21165 }
21166 fmt.finish()
21167 }
21168}
21169impl IterableFlowerKeyMplsOptAttrs<'_> {
21170 pub fn lookup_attr(
21171 &self,
21172 offset: usize,
21173 missing_type: Option<u16>,
21174 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
21175 let mut stack = Vec::new();
21176 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
21177 if missing_type.is_some() && cur == offset {
21178 stack.push(("FlowerKeyMplsOptAttrs", offset));
21179 return (
21180 stack,
21181 missing_type.and_then(|t| FlowerKeyMplsOptAttrs::attr_from_type(t)),
21182 );
21183 }
21184 if cur > offset || cur + self.buf.len() < offset {
21185 return (stack, None);
21186 }
21187 let mut attrs = self.clone();
21188 let mut last_off = cur + attrs.pos;
21189 while let Some(attr) = attrs.next() {
21190 let Ok(attr) = attr else { break };
21191 match attr {
21192 FlowerKeyMplsOptAttrs::LseDepth(val) => {
21193 if last_off == offset {
21194 stack.push(("LseDepth", last_off));
21195 break;
21196 }
21197 }
21198 FlowerKeyMplsOptAttrs::LseTtl(val) => {
21199 if last_off == offset {
21200 stack.push(("LseTtl", last_off));
21201 break;
21202 }
21203 }
21204 FlowerKeyMplsOptAttrs::LseBos(val) => {
21205 if last_off == offset {
21206 stack.push(("LseBos", last_off));
21207 break;
21208 }
21209 }
21210 FlowerKeyMplsOptAttrs::LseTc(val) => {
21211 if last_off == offset {
21212 stack.push(("LseTc", last_off));
21213 break;
21214 }
21215 }
21216 FlowerKeyMplsOptAttrs::LseLabel(val) => {
21217 if last_off == offset {
21218 stack.push(("LseLabel", last_off));
21219 break;
21220 }
21221 }
21222 _ => {}
21223 };
21224 last_off = cur + attrs.pos;
21225 }
21226 if !stack.is_empty() {
21227 stack.push(("FlowerKeyMplsOptAttrs", cur));
21228 }
21229 (stack, None)
21230 }
21231}
21232#[derive(Clone)]
21233pub enum FlowerKeyCfmAttrs {
21234 MdLevel(u8),
21235 Opcode(u8),
21236}
21237impl<'a> IterableFlowerKeyCfmAttrs<'a> {
21238 pub fn get_md_level(&self) -> Result<u8, ErrorContext> {
21239 let mut iter = self.clone();
21240 iter.pos = 0;
21241 for attr in iter {
21242 if let Ok(FlowerKeyCfmAttrs::MdLevel(val)) = attr {
21243 return Ok(val);
21244 }
21245 }
21246 Err(ErrorContext::new_missing(
21247 "FlowerKeyCfmAttrs",
21248 "MdLevel",
21249 self.orig_loc,
21250 self.buf.as_ptr() as usize,
21251 ))
21252 }
21253 pub fn get_opcode(&self) -> Result<u8, ErrorContext> {
21254 let mut iter = self.clone();
21255 iter.pos = 0;
21256 for attr in iter {
21257 if let Ok(FlowerKeyCfmAttrs::Opcode(val)) = attr {
21258 return Ok(val);
21259 }
21260 }
21261 Err(ErrorContext::new_missing(
21262 "FlowerKeyCfmAttrs",
21263 "Opcode",
21264 self.orig_loc,
21265 self.buf.as_ptr() as usize,
21266 ))
21267 }
21268}
21269impl FlowerKeyCfmAttrs {
21270 pub fn new<'a>(buf: &'a [u8]) -> IterableFlowerKeyCfmAttrs<'a> {
21271 IterableFlowerKeyCfmAttrs::with_loc(buf, buf.as_ptr() as usize)
21272 }
21273 fn attr_from_type(r#type: u16) -> Option<&'static str> {
21274 let res = match r#type {
21275 1u16 => "MdLevel",
21276 2u16 => "Opcode",
21277 _ => return None,
21278 };
21279 Some(res)
21280 }
21281}
21282#[derive(Clone, Copy, Default)]
21283pub struct IterableFlowerKeyCfmAttrs<'a> {
21284 buf: &'a [u8],
21285 pos: usize,
21286 orig_loc: usize,
21287}
21288impl<'a> IterableFlowerKeyCfmAttrs<'a> {
21289 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
21290 Self {
21291 buf,
21292 pos: 0,
21293 orig_loc,
21294 }
21295 }
21296 pub fn get_buf(&self) -> &'a [u8] {
21297 self.buf
21298 }
21299}
21300impl<'a> Iterator for IterableFlowerKeyCfmAttrs<'a> {
21301 type Item = Result<FlowerKeyCfmAttrs, ErrorContext>;
21302 fn next(&mut self) -> Option<Self::Item> {
21303 let mut pos;
21304 let mut r#type;
21305 loop {
21306 pos = self.pos;
21307 r#type = None;
21308 if self.buf.len() == self.pos {
21309 return None;
21310 }
21311 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
21312 self.pos = self.buf.len();
21313 break;
21314 };
21315 r#type = Some(header.r#type);
21316 let res = match header.r#type {
21317 1u16 => FlowerKeyCfmAttrs::MdLevel({
21318 let res = parse_u8(next);
21319 let Some(val) = res else { break };
21320 val
21321 }),
21322 2u16 => FlowerKeyCfmAttrs::Opcode({
21323 let res = parse_u8(next);
21324 let Some(val) = res else { break };
21325 val
21326 }),
21327 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
21328 n => continue,
21329 };
21330 return Some(Ok(res));
21331 }
21332 Some(Err(ErrorContext::new(
21333 "FlowerKeyCfmAttrs",
21334 r#type.and_then(|t| FlowerKeyCfmAttrs::attr_from_type(t)),
21335 self.orig_loc,
21336 self.buf.as_ptr().wrapping_add(pos) as usize,
21337 )))
21338 }
21339}
21340impl std::fmt::Debug for IterableFlowerKeyCfmAttrs<'_> {
21341 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21342 let mut fmt = f.debug_struct("FlowerKeyCfmAttrs");
21343 for attr in self.clone() {
21344 let attr = match attr {
21345 Ok(a) => a,
21346 Err(err) => {
21347 fmt.finish()?;
21348 f.write_str("Err(")?;
21349 err.fmt(f)?;
21350 return f.write_str(")");
21351 }
21352 };
21353 match attr {
21354 FlowerKeyCfmAttrs::MdLevel(val) => fmt.field("MdLevel", &val),
21355 FlowerKeyCfmAttrs::Opcode(val) => fmt.field("Opcode", &val),
21356 };
21357 }
21358 fmt.finish()
21359 }
21360}
21361impl IterableFlowerKeyCfmAttrs<'_> {
21362 pub fn lookup_attr(
21363 &self,
21364 offset: usize,
21365 missing_type: Option<u16>,
21366 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
21367 let mut stack = Vec::new();
21368 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
21369 if missing_type.is_some() && cur == offset {
21370 stack.push(("FlowerKeyCfmAttrs", offset));
21371 return (
21372 stack,
21373 missing_type.and_then(|t| FlowerKeyCfmAttrs::attr_from_type(t)),
21374 );
21375 }
21376 if cur > offset || cur + self.buf.len() < offset {
21377 return (stack, None);
21378 }
21379 let mut attrs = self.clone();
21380 let mut last_off = cur + attrs.pos;
21381 while let Some(attr) = attrs.next() {
21382 let Ok(attr) = attr else { break };
21383 match attr {
21384 FlowerKeyCfmAttrs::MdLevel(val) => {
21385 if last_off == offset {
21386 stack.push(("MdLevel", last_off));
21387 break;
21388 }
21389 }
21390 FlowerKeyCfmAttrs::Opcode(val) => {
21391 if last_off == offset {
21392 stack.push(("Opcode", last_off));
21393 break;
21394 }
21395 }
21396 _ => {}
21397 };
21398 last_off = cur + attrs.pos;
21399 }
21400 if !stack.is_empty() {
21401 stack.push(("FlowerKeyCfmAttrs", cur));
21402 }
21403 (stack, None)
21404 }
21405}
21406#[derive(Clone)]
21407pub enum FwAttrs<'a> {
21408 Classid(u32),
21409 Police(IterablePoliceAttrs<'a>),
21410 Indev(&'a CStr),
21411 Act(IterableArrayActAttrs<'a>),
21412 Mask(u32),
21413}
21414impl<'a> IterableFwAttrs<'a> {
21415 pub fn get_classid(&self) -> Result<u32, ErrorContext> {
21416 let mut iter = self.clone();
21417 iter.pos = 0;
21418 for attr in iter {
21419 if let Ok(FwAttrs::Classid(val)) = attr {
21420 return Ok(val);
21421 }
21422 }
21423 Err(ErrorContext::new_missing(
21424 "FwAttrs",
21425 "Classid",
21426 self.orig_loc,
21427 self.buf.as_ptr() as usize,
21428 ))
21429 }
21430 pub fn get_police(&self) -> Result<IterablePoliceAttrs<'a>, ErrorContext> {
21431 let mut iter = self.clone();
21432 iter.pos = 0;
21433 for attr in iter {
21434 if let Ok(FwAttrs::Police(val)) = attr {
21435 return Ok(val);
21436 }
21437 }
21438 Err(ErrorContext::new_missing(
21439 "FwAttrs",
21440 "Police",
21441 self.orig_loc,
21442 self.buf.as_ptr() as usize,
21443 ))
21444 }
21445 pub fn get_indev(&self) -> Result<&'a CStr, ErrorContext> {
21446 let mut iter = self.clone();
21447 iter.pos = 0;
21448 for attr in iter {
21449 if let Ok(FwAttrs::Indev(val)) = attr {
21450 return Ok(val);
21451 }
21452 }
21453 Err(ErrorContext::new_missing(
21454 "FwAttrs",
21455 "Indev",
21456 self.orig_loc,
21457 self.buf.as_ptr() as usize,
21458 ))
21459 }
21460 pub fn get_act(
21461 &self,
21462 ) -> Result<ArrayIterable<IterableArrayActAttrs<'a>, IterableActAttrs<'a>>, ErrorContext> {
21463 for attr in self.clone() {
21464 if let Ok(FwAttrs::Act(val)) = attr {
21465 return Ok(ArrayIterable::new(val));
21466 }
21467 }
21468 Err(ErrorContext::new_missing(
21469 "FwAttrs",
21470 "Act",
21471 self.orig_loc,
21472 self.buf.as_ptr() as usize,
21473 ))
21474 }
21475 pub fn get_mask(&self) -> Result<u32, ErrorContext> {
21476 let mut iter = self.clone();
21477 iter.pos = 0;
21478 for attr in iter {
21479 if let Ok(FwAttrs::Mask(val)) = attr {
21480 return Ok(val);
21481 }
21482 }
21483 Err(ErrorContext::new_missing(
21484 "FwAttrs",
21485 "Mask",
21486 self.orig_loc,
21487 self.buf.as_ptr() as usize,
21488 ))
21489 }
21490}
21491impl FwAttrs<'_> {
21492 pub fn new<'a>(buf: &'a [u8]) -> IterableFwAttrs<'a> {
21493 IterableFwAttrs::with_loc(buf, buf.as_ptr() as usize)
21494 }
21495 fn attr_from_type(r#type: u16) -> Option<&'static str> {
21496 let res = match r#type {
21497 1u16 => "Classid",
21498 2u16 => "Police",
21499 3u16 => "Indev",
21500 4u16 => "Act",
21501 5u16 => "Mask",
21502 _ => return None,
21503 };
21504 Some(res)
21505 }
21506}
21507#[derive(Clone, Copy, Default)]
21508pub struct IterableFwAttrs<'a> {
21509 buf: &'a [u8],
21510 pos: usize,
21511 orig_loc: usize,
21512}
21513impl<'a> IterableFwAttrs<'a> {
21514 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
21515 Self {
21516 buf,
21517 pos: 0,
21518 orig_loc,
21519 }
21520 }
21521 pub fn get_buf(&self) -> &'a [u8] {
21522 self.buf
21523 }
21524}
21525impl<'a> Iterator for IterableFwAttrs<'a> {
21526 type Item = Result<FwAttrs<'a>, ErrorContext>;
21527 fn next(&mut self) -> Option<Self::Item> {
21528 let mut pos;
21529 let mut r#type;
21530 loop {
21531 pos = self.pos;
21532 r#type = None;
21533 if self.buf.len() == self.pos {
21534 return None;
21535 }
21536 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
21537 self.pos = self.buf.len();
21538 break;
21539 };
21540 r#type = Some(header.r#type);
21541 let res = match header.r#type {
21542 1u16 => FwAttrs::Classid({
21543 let res = parse_u32(next);
21544 let Some(val) = res else { break };
21545 val
21546 }),
21547 2u16 => FwAttrs::Police({
21548 let res = Some(IterablePoliceAttrs::with_loc(next, self.orig_loc));
21549 let Some(val) = res else { break };
21550 val
21551 }),
21552 3u16 => FwAttrs::Indev({
21553 let res = CStr::from_bytes_with_nul(next).ok();
21554 let Some(val) = res else { break };
21555 val
21556 }),
21557 4u16 => FwAttrs::Act({
21558 let res = Some(IterableArrayActAttrs::with_loc(next, self.orig_loc));
21559 let Some(val) = res else { break };
21560 val
21561 }),
21562 5u16 => FwAttrs::Mask({
21563 let res = parse_u32(next);
21564 let Some(val) = res else { break };
21565 val
21566 }),
21567 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
21568 n => continue,
21569 };
21570 return Some(Ok(res));
21571 }
21572 Some(Err(ErrorContext::new(
21573 "FwAttrs",
21574 r#type.and_then(|t| FwAttrs::attr_from_type(t)),
21575 self.orig_loc,
21576 self.buf.as_ptr().wrapping_add(pos) as usize,
21577 )))
21578 }
21579}
21580impl<'a> std::fmt::Debug for IterableFwAttrs<'_> {
21581 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21582 let mut fmt = f.debug_struct("FwAttrs");
21583 for attr in self.clone() {
21584 let attr = match attr {
21585 Ok(a) => a,
21586 Err(err) => {
21587 fmt.finish()?;
21588 f.write_str("Err(")?;
21589 err.fmt(f)?;
21590 return f.write_str(")");
21591 }
21592 };
21593 match attr {
21594 FwAttrs::Classid(val) => fmt.field("Classid", &val),
21595 FwAttrs::Police(val) => fmt.field("Police", &val),
21596 FwAttrs::Indev(val) => fmt.field("Indev", &val),
21597 FwAttrs::Act(val) => fmt.field("Act", &val),
21598 FwAttrs::Mask(val) => fmt.field("Mask", &val),
21599 };
21600 }
21601 fmt.finish()
21602 }
21603}
21604impl IterableFwAttrs<'_> {
21605 pub fn lookup_attr(
21606 &self,
21607 offset: usize,
21608 missing_type: Option<u16>,
21609 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
21610 let mut stack = Vec::new();
21611 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
21612 if missing_type.is_some() && cur == offset {
21613 stack.push(("FwAttrs", offset));
21614 return (stack, missing_type.and_then(|t| FwAttrs::attr_from_type(t)));
21615 }
21616 if cur > offset || cur + self.buf.len() < offset {
21617 return (stack, None);
21618 }
21619 let mut attrs = self.clone();
21620 let mut last_off = cur + attrs.pos;
21621 let mut missing = None;
21622 while let Some(attr) = attrs.next() {
21623 let Ok(attr) = attr else { break };
21624 match attr {
21625 FwAttrs::Classid(val) => {
21626 if last_off == offset {
21627 stack.push(("Classid", last_off));
21628 break;
21629 }
21630 }
21631 FwAttrs::Police(val) => {
21632 (stack, missing) = val.lookup_attr(offset, missing_type);
21633 if !stack.is_empty() {
21634 break;
21635 }
21636 }
21637 FwAttrs::Indev(val) => {
21638 if last_off == offset {
21639 stack.push(("Indev", last_off));
21640 break;
21641 }
21642 }
21643 FwAttrs::Act(val) => {
21644 for entry in val {
21645 let Ok(attr) = entry else { break };
21646 (stack, missing) = attr.lookup_attr(offset, missing_type);
21647 if !stack.is_empty() {
21648 break;
21649 }
21650 }
21651 if !stack.is_empty() {
21652 stack.push(("Act", last_off));
21653 break;
21654 }
21655 }
21656 FwAttrs::Mask(val) => {
21657 if last_off == offset {
21658 stack.push(("Mask", last_off));
21659 break;
21660 }
21661 }
21662 _ => {}
21663 };
21664 last_off = cur + attrs.pos;
21665 }
21666 if !stack.is_empty() {
21667 stack.push(("FwAttrs", cur));
21668 }
21669 (stack, missing)
21670 }
21671}
21672#[derive(Clone)]
21673pub enum GredAttrs<'a> {
21674 Parms(&'a [u8]),
21675 Stab(&'a [u8]),
21676 Dps(TcGredSopt),
21677 MaxP(&'a [u8]),
21678 Limit(u32),
21679 VqList(IterableTcaGredVqListAttrs<'a>),
21680}
21681impl<'a> IterableGredAttrs<'a> {
21682 pub fn get_parms(&self) -> Result<&'a [u8], ErrorContext> {
21683 let mut iter = self.clone();
21684 iter.pos = 0;
21685 for attr in iter {
21686 if let Ok(GredAttrs::Parms(val)) = attr {
21687 return Ok(val);
21688 }
21689 }
21690 Err(ErrorContext::new_missing(
21691 "GredAttrs",
21692 "Parms",
21693 self.orig_loc,
21694 self.buf.as_ptr() as usize,
21695 ))
21696 }
21697 pub fn get_stab(&self) -> Result<&'a [u8], ErrorContext> {
21698 let mut iter = self.clone();
21699 iter.pos = 0;
21700 for attr in iter {
21701 if let Ok(GredAttrs::Stab(val)) = attr {
21702 return Ok(val);
21703 }
21704 }
21705 Err(ErrorContext::new_missing(
21706 "GredAttrs",
21707 "Stab",
21708 self.orig_loc,
21709 self.buf.as_ptr() as usize,
21710 ))
21711 }
21712 pub fn get_dps(&self) -> Result<TcGredSopt, ErrorContext> {
21713 let mut iter = self.clone();
21714 iter.pos = 0;
21715 for attr in iter {
21716 if let Ok(GredAttrs::Dps(val)) = attr {
21717 return Ok(val);
21718 }
21719 }
21720 Err(ErrorContext::new_missing(
21721 "GredAttrs",
21722 "Dps",
21723 self.orig_loc,
21724 self.buf.as_ptr() as usize,
21725 ))
21726 }
21727 pub fn get_max_p(&self) -> Result<&'a [u8], ErrorContext> {
21728 let mut iter = self.clone();
21729 iter.pos = 0;
21730 for attr in iter {
21731 if let Ok(GredAttrs::MaxP(val)) = attr {
21732 return Ok(val);
21733 }
21734 }
21735 Err(ErrorContext::new_missing(
21736 "GredAttrs",
21737 "MaxP",
21738 self.orig_loc,
21739 self.buf.as_ptr() as usize,
21740 ))
21741 }
21742 pub fn get_limit(&self) -> Result<u32, ErrorContext> {
21743 let mut iter = self.clone();
21744 iter.pos = 0;
21745 for attr in iter {
21746 if let Ok(GredAttrs::Limit(val)) = attr {
21747 return Ok(val);
21748 }
21749 }
21750 Err(ErrorContext::new_missing(
21751 "GredAttrs",
21752 "Limit",
21753 self.orig_loc,
21754 self.buf.as_ptr() as usize,
21755 ))
21756 }
21757 pub fn get_vq_list(&self) -> Result<IterableTcaGredVqListAttrs<'a>, ErrorContext> {
21758 let mut iter = self.clone();
21759 iter.pos = 0;
21760 for attr in iter {
21761 if let Ok(GredAttrs::VqList(val)) = attr {
21762 return Ok(val);
21763 }
21764 }
21765 Err(ErrorContext::new_missing(
21766 "GredAttrs",
21767 "VqList",
21768 self.orig_loc,
21769 self.buf.as_ptr() as usize,
21770 ))
21771 }
21772}
21773impl GredAttrs<'_> {
21774 pub fn new<'a>(buf: &'a [u8]) -> IterableGredAttrs<'a> {
21775 IterableGredAttrs::with_loc(buf, buf.as_ptr() as usize)
21776 }
21777 fn attr_from_type(r#type: u16) -> Option<&'static str> {
21778 let res = match r#type {
21779 1u16 => "Parms",
21780 2u16 => "Stab",
21781 3u16 => "Dps",
21782 4u16 => "MaxP",
21783 5u16 => "Limit",
21784 6u16 => "VqList",
21785 _ => return None,
21786 };
21787 Some(res)
21788 }
21789}
21790#[derive(Clone, Copy, Default)]
21791pub struct IterableGredAttrs<'a> {
21792 buf: &'a [u8],
21793 pos: usize,
21794 orig_loc: usize,
21795}
21796impl<'a> IterableGredAttrs<'a> {
21797 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
21798 Self {
21799 buf,
21800 pos: 0,
21801 orig_loc,
21802 }
21803 }
21804 pub fn get_buf(&self) -> &'a [u8] {
21805 self.buf
21806 }
21807}
21808impl<'a> Iterator for IterableGredAttrs<'a> {
21809 type Item = Result<GredAttrs<'a>, ErrorContext>;
21810 fn next(&mut self) -> Option<Self::Item> {
21811 let mut pos;
21812 let mut r#type;
21813 loop {
21814 pos = self.pos;
21815 r#type = None;
21816 if self.buf.len() == self.pos {
21817 return None;
21818 }
21819 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
21820 self.pos = self.buf.len();
21821 break;
21822 };
21823 r#type = Some(header.r#type);
21824 let res = match header.r#type {
21825 1u16 => GredAttrs::Parms({
21826 let res = Some(next);
21827 let Some(val) = res else { break };
21828 val
21829 }),
21830 2u16 => GredAttrs::Stab({
21831 let res = Some(next);
21832 let Some(val) = res else { break };
21833 val
21834 }),
21835 3u16 => GredAttrs::Dps({
21836 let res = Some(TcGredSopt::new_from_zeroed(next));
21837 let Some(val) = res else { break };
21838 val
21839 }),
21840 4u16 => GredAttrs::MaxP({
21841 let res = Some(next);
21842 let Some(val) = res else { break };
21843 val
21844 }),
21845 5u16 => GredAttrs::Limit({
21846 let res = parse_u32(next);
21847 let Some(val) = res else { break };
21848 val
21849 }),
21850 6u16 => GredAttrs::VqList({
21851 let res = Some(IterableTcaGredVqListAttrs::with_loc(next, self.orig_loc));
21852 let Some(val) = res else { break };
21853 val
21854 }),
21855 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
21856 n => continue,
21857 };
21858 return Some(Ok(res));
21859 }
21860 Some(Err(ErrorContext::new(
21861 "GredAttrs",
21862 r#type.and_then(|t| GredAttrs::attr_from_type(t)),
21863 self.orig_loc,
21864 self.buf.as_ptr().wrapping_add(pos) as usize,
21865 )))
21866 }
21867}
21868impl<'a> std::fmt::Debug for IterableGredAttrs<'_> {
21869 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21870 let mut fmt = f.debug_struct("GredAttrs");
21871 for attr in self.clone() {
21872 let attr = match attr {
21873 Ok(a) => a,
21874 Err(err) => {
21875 fmt.finish()?;
21876 f.write_str("Err(")?;
21877 err.fmt(f)?;
21878 return f.write_str(")");
21879 }
21880 };
21881 match attr {
21882 GredAttrs::Parms(val) => fmt.field("Parms", &val),
21883 GredAttrs::Stab(val) => fmt.field("Stab", &val),
21884 GredAttrs::Dps(val) => fmt.field("Dps", &val),
21885 GredAttrs::MaxP(val) => fmt.field("MaxP", &val),
21886 GredAttrs::Limit(val) => fmt.field("Limit", &val),
21887 GredAttrs::VqList(val) => fmt.field("VqList", &val),
21888 };
21889 }
21890 fmt.finish()
21891 }
21892}
21893impl IterableGredAttrs<'_> {
21894 pub fn lookup_attr(
21895 &self,
21896 offset: usize,
21897 missing_type: Option<u16>,
21898 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
21899 let mut stack = Vec::new();
21900 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
21901 if missing_type.is_some() && cur == offset {
21902 stack.push(("GredAttrs", offset));
21903 return (
21904 stack,
21905 missing_type.and_then(|t| GredAttrs::attr_from_type(t)),
21906 );
21907 }
21908 if cur > offset || cur + self.buf.len() < offset {
21909 return (stack, None);
21910 }
21911 let mut attrs = self.clone();
21912 let mut last_off = cur + attrs.pos;
21913 let mut missing = None;
21914 while let Some(attr) = attrs.next() {
21915 let Ok(attr) = attr else { break };
21916 match attr {
21917 GredAttrs::Parms(val) => {
21918 if last_off == offset {
21919 stack.push(("Parms", last_off));
21920 break;
21921 }
21922 }
21923 GredAttrs::Stab(val) => {
21924 if last_off == offset {
21925 stack.push(("Stab", last_off));
21926 break;
21927 }
21928 }
21929 GredAttrs::Dps(val) => {
21930 if last_off == offset {
21931 stack.push(("Dps", last_off));
21932 break;
21933 }
21934 }
21935 GredAttrs::MaxP(val) => {
21936 if last_off == offset {
21937 stack.push(("MaxP", last_off));
21938 break;
21939 }
21940 }
21941 GredAttrs::Limit(val) => {
21942 if last_off == offset {
21943 stack.push(("Limit", last_off));
21944 break;
21945 }
21946 }
21947 GredAttrs::VqList(val) => {
21948 (stack, missing) = val.lookup_attr(offset, missing_type);
21949 if !stack.is_empty() {
21950 break;
21951 }
21952 }
21953 _ => {}
21954 };
21955 last_off = cur + attrs.pos;
21956 }
21957 if !stack.is_empty() {
21958 stack.push(("GredAttrs", cur));
21959 }
21960 (stack, missing)
21961 }
21962}
21963#[derive(Clone)]
21964pub enum TcaGredVqListAttrs<'a> {
21965 #[doc = "Attribute may repeat multiple times (treat it as array)"]
21966 Entry(IterableTcaGredVqEntryAttrs<'a>),
21967}
21968impl<'a> IterableTcaGredVqListAttrs<'a> {
21969 #[doc = "Attribute may repeat multiple times (treat it as array)"]
21970 pub fn get_entry(
21971 &self,
21972 ) -> MultiAttrIterable<Self, TcaGredVqListAttrs<'a>, IterableTcaGredVqEntryAttrs<'a>> {
21973 MultiAttrIterable::new(self.clone(), |variant| {
21974 if let TcaGredVqListAttrs::Entry(val) = variant {
21975 Some(val)
21976 } else {
21977 None
21978 }
21979 })
21980 }
21981}
21982impl TcaGredVqListAttrs<'_> {
21983 pub fn new<'a>(buf: &'a [u8]) -> IterableTcaGredVqListAttrs<'a> {
21984 IterableTcaGredVqListAttrs::with_loc(buf, buf.as_ptr() as usize)
21985 }
21986 fn attr_from_type(r#type: u16) -> Option<&'static str> {
21987 let res = match r#type {
21988 1u16 => "Entry",
21989 _ => return None,
21990 };
21991 Some(res)
21992 }
21993}
21994#[derive(Clone, Copy, Default)]
21995pub struct IterableTcaGredVqListAttrs<'a> {
21996 buf: &'a [u8],
21997 pos: usize,
21998 orig_loc: usize,
21999}
22000impl<'a> IterableTcaGredVqListAttrs<'a> {
22001 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22002 Self {
22003 buf,
22004 pos: 0,
22005 orig_loc,
22006 }
22007 }
22008 pub fn get_buf(&self) -> &'a [u8] {
22009 self.buf
22010 }
22011}
22012impl<'a> Iterator for IterableTcaGredVqListAttrs<'a> {
22013 type Item = Result<TcaGredVqListAttrs<'a>, ErrorContext>;
22014 fn next(&mut self) -> Option<Self::Item> {
22015 let mut pos;
22016 let mut r#type;
22017 loop {
22018 pos = self.pos;
22019 r#type = None;
22020 if self.buf.len() == self.pos {
22021 return None;
22022 }
22023 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
22024 self.pos = self.buf.len();
22025 break;
22026 };
22027 r#type = Some(header.r#type);
22028 let res = match header.r#type {
22029 1u16 => TcaGredVqListAttrs::Entry({
22030 let res = Some(IterableTcaGredVqEntryAttrs::with_loc(next, self.orig_loc));
22031 let Some(val) = res else { break };
22032 val
22033 }),
22034 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
22035 n => continue,
22036 };
22037 return Some(Ok(res));
22038 }
22039 Some(Err(ErrorContext::new(
22040 "TcaGredVqListAttrs",
22041 r#type.and_then(|t| TcaGredVqListAttrs::attr_from_type(t)),
22042 self.orig_loc,
22043 self.buf.as_ptr().wrapping_add(pos) as usize,
22044 )))
22045 }
22046}
22047impl<'a> std::fmt::Debug for IterableTcaGredVqListAttrs<'_> {
22048 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22049 let mut fmt = f.debug_struct("TcaGredVqListAttrs");
22050 for attr in self.clone() {
22051 let attr = match attr {
22052 Ok(a) => a,
22053 Err(err) => {
22054 fmt.finish()?;
22055 f.write_str("Err(")?;
22056 err.fmt(f)?;
22057 return f.write_str(")");
22058 }
22059 };
22060 match attr {
22061 TcaGredVqListAttrs::Entry(val) => fmt.field("Entry", &val),
22062 };
22063 }
22064 fmt.finish()
22065 }
22066}
22067impl IterableTcaGredVqListAttrs<'_> {
22068 pub fn lookup_attr(
22069 &self,
22070 offset: usize,
22071 missing_type: Option<u16>,
22072 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22073 let mut stack = Vec::new();
22074 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
22075 if missing_type.is_some() && cur == offset {
22076 stack.push(("TcaGredVqListAttrs", offset));
22077 return (
22078 stack,
22079 missing_type.and_then(|t| TcaGredVqListAttrs::attr_from_type(t)),
22080 );
22081 }
22082 if cur > offset || cur + self.buf.len() < offset {
22083 return (stack, None);
22084 }
22085 let mut attrs = self.clone();
22086 let mut last_off = cur + attrs.pos;
22087 let mut missing = None;
22088 while let Some(attr) = attrs.next() {
22089 let Ok(attr) = attr else { break };
22090 match attr {
22091 TcaGredVqListAttrs::Entry(val) => {
22092 (stack, missing) = val.lookup_attr(offset, missing_type);
22093 if !stack.is_empty() {
22094 break;
22095 }
22096 }
22097 _ => {}
22098 };
22099 last_off = cur + attrs.pos;
22100 }
22101 if !stack.is_empty() {
22102 stack.push(("TcaGredVqListAttrs", cur));
22103 }
22104 (stack, missing)
22105 }
22106}
22107#[derive(Clone)]
22108pub enum TcaGredVqEntryAttrs<'a> {
22109 Pad(&'a [u8]),
22110 Dp(u32),
22111 StatBytes(u64),
22112 StatPackets(u32),
22113 StatBacklog(u32),
22114 StatProbDrop(u32),
22115 StatProbMark(u32),
22116 StatForcedDrop(u32),
22117 StatForcedMark(u32),
22118 StatPdrop(u32),
22119 StatOther(u32),
22120 Flags(u32),
22121}
22122impl<'a> IterableTcaGredVqEntryAttrs<'a> {
22123 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
22124 let mut iter = self.clone();
22125 iter.pos = 0;
22126 for attr in iter {
22127 if let Ok(TcaGredVqEntryAttrs::Pad(val)) = attr {
22128 return Ok(val);
22129 }
22130 }
22131 Err(ErrorContext::new_missing(
22132 "TcaGredVqEntryAttrs",
22133 "Pad",
22134 self.orig_loc,
22135 self.buf.as_ptr() as usize,
22136 ))
22137 }
22138 pub fn get_dp(&self) -> Result<u32, ErrorContext> {
22139 let mut iter = self.clone();
22140 iter.pos = 0;
22141 for attr in iter {
22142 if let Ok(TcaGredVqEntryAttrs::Dp(val)) = attr {
22143 return Ok(val);
22144 }
22145 }
22146 Err(ErrorContext::new_missing(
22147 "TcaGredVqEntryAttrs",
22148 "Dp",
22149 self.orig_loc,
22150 self.buf.as_ptr() as usize,
22151 ))
22152 }
22153 pub fn get_stat_bytes(&self) -> Result<u64, ErrorContext> {
22154 let mut iter = self.clone();
22155 iter.pos = 0;
22156 for attr in iter {
22157 if let Ok(TcaGredVqEntryAttrs::StatBytes(val)) = attr {
22158 return Ok(val);
22159 }
22160 }
22161 Err(ErrorContext::new_missing(
22162 "TcaGredVqEntryAttrs",
22163 "StatBytes",
22164 self.orig_loc,
22165 self.buf.as_ptr() as usize,
22166 ))
22167 }
22168 pub fn get_stat_packets(&self) -> Result<u32, ErrorContext> {
22169 let mut iter = self.clone();
22170 iter.pos = 0;
22171 for attr in iter {
22172 if let Ok(TcaGredVqEntryAttrs::StatPackets(val)) = attr {
22173 return Ok(val);
22174 }
22175 }
22176 Err(ErrorContext::new_missing(
22177 "TcaGredVqEntryAttrs",
22178 "StatPackets",
22179 self.orig_loc,
22180 self.buf.as_ptr() as usize,
22181 ))
22182 }
22183 pub fn get_stat_backlog(&self) -> Result<u32, ErrorContext> {
22184 let mut iter = self.clone();
22185 iter.pos = 0;
22186 for attr in iter {
22187 if let Ok(TcaGredVqEntryAttrs::StatBacklog(val)) = attr {
22188 return Ok(val);
22189 }
22190 }
22191 Err(ErrorContext::new_missing(
22192 "TcaGredVqEntryAttrs",
22193 "StatBacklog",
22194 self.orig_loc,
22195 self.buf.as_ptr() as usize,
22196 ))
22197 }
22198 pub fn get_stat_prob_drop(&self) -> Result<u32, ErrorContext> {
22199 let mut iter = self.clone();
22200 iter.pos = 0;
22201 for attr in iter {
22202 if let Ok(TcaGredVqEntryAttrs::StatProbDrop(val)) = attr {
22203 return Ok(val);
22204 }
22205 }
22206 Err(ErrorContext::new_missing(
22207 "TcaGredVqEntryAttrs",
22208 "StatProbDrop",
22209 self.orig_loc,
22210 self.buf.as_ptr() as usize,
22211 ))
22212 }
22213 pub fn get_stat_prob_mark(&self) -> Result<u32, ErrorContext> {
22214 let mut iter = self.clone();
22215 iter.pos = 0;
22216 for attr in iter {
22217 if let Ok(TcaGredVqEntryAttrs::StatProbMark(val)) = attr {
22218 return Ok(val);
22219 }
22220 }
22221 Err(ErrorContext::new_missing(
22222 "TcaGredVqEntryAttrs",
22223 "StatProbMark",
22224 self.orig_loc,
22225 self.buf.as_ptr() as usize,
22226 ))
22227 }
22228 pub fn get_stat_forced_drop(&self) -> Result<u32, ErrorContext> {
22229 let mut iter = self.clone();
22230 iter.pos = 0;
22231 for attr in iter {
22232 if let Ok(TcaGredVqEntryAttrs::StatForcedDrop(val)) = attr {
22233 return Ok(val);
22234 }
22235 }
22236 Err(ErrorContext::new_missing(
22237 "TcaGredVqEntryAttrs",
22238 "StatForcedDrop",
22239 self.orig_loc,
22240 self.buf.as_ptr() as usize,
22241 ))
22242 }
22243 pub fn get_stat_forced_mark(&self) -> Result<u32, ErrorContext> {
22244 let mut iter = self.clone();
22245 iter.pos = 0;
22246 for attr in iter {
22247 if let Ok(TcaGredVqEntryAttrs::StatForcedMark(val)) = attr {
22248 return Ok(val);
22249 }
22250 }
22251 Err(ErrorContext::new_missing(
22252 "TcaGredVqEntryAttrs",
22253 "StatForcedMark",
22254 self.orig_loc,
22255 self.buf.as_ptr() as usize,
22256 ))
22257 }
22258 pub fn get_stat_pdrop(&self) -> Result<u32, ErrorContext> {
22259 let mut iter = self.clone();
22260 iter.pos = 0;
22261 for attr in iter {
22262 if let Ok(TcaGredVqEntryAttrs::StatPdrop(val)) = attr {
22263 return Ok(val);
22264 }
22265 }
22266 Err(ErrorContext::new_missing(
22267 "TcaGredVqEntryAttrs",
22268 "StatPdrop",
22269 self.orig_loc,
22270 self.buf.as_ptr() as usize,
22271 ))
22272 }
22273 pub fn get_stat_other(&self) -> Result<u32, ErrorContext> {
22274 let mut iter = self.clone();
22275 iter.pos = 0;
22276 for attr in iter {
22277 if let Ok(TcaGredVqEntryAttrs::StatOther(val)) = attr {
22278 return Ok(val);
22279 }
22280 }
22281 Err(ErrorContext::new_missing(
22282 "TcaGredVqEntryAttrs",
22283 "StatOther",
22284 self.orig_loc,
22285 self.buf.as_ptr() as usize,
22286 ))
22287 }
22288 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
22289 let mut iter = self.clone();
22290 iter.pos = 0;
22291 for attr in iter {
22292 if let Ok(TcaGredVqEntryAttrs::Flags(val)) = attr {
22293 return Ok(val);
22294 }
22295 }
22296 Err(ErrorContext::new_missing(
22297 "TcaGredVqEntryAttrs",
22298 "Flags",
22299 self.orig_loc,
22300 self.buf.as_ptr() as usize,
22301 ))
22302 }
22303}
22304impl TcaGredVqEntryAttrs<'_> {
22305 pub fn new<'a>(buf: &'a [u8]) -> IterableTcaGredVqEntryAttrs<'a> {
22306 IterableTcaGredVqEntryAttrs::with_loc(buf, buf.as_ptr() as usize)
22307 }
22308 fn attr_from_type(r#type: u16) -> Option<&'static str> {
22309 let res = match r#type {
22310 1u16 => "Pad",
22311 2u16 => "Dp",
22312 3u16 => "StatBytes",
22313 4u16 => "StatPackets",
22314 5u16 => "StatBacklog",
22315 6u16 => "StatProbDrop",
22316 7u16 => "StatProbMark",
22317 8u16 => "StatForcedDrop",
22318 9u16 => "StatForcedMark",
22319 10u16 => "StatPdrop",
22320 11u16 => "StatOther",
22321 12u16 => "Flags",
22322 _ => return None,
22323 };
22324 Some(res)
22325 }
22326}
22327#[derive(Clone, Copy, Default)]
22328pub struct IterableTcaGredVqEntryAttrs<'a> {
22329 buf: &'a [u8],
22330 pos: usize,
22331 orig_loc: usize,
22332}
22333impl<'a> IterableTcaGredVqEntryAttrs<'a> {
22334 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22335 Self {
22336 buf,
22337 pos: 0,
22338 orig_loc,
22339 }
22340 }
22341 pub fn get_buf(&self) -> &'a [u8] {
22342 self.buf
22343 }
22344}
22345impl<'a> Iterator for IterableTcaGredVqEntryAttrs<'a> {
22346 type Item = Result<TcaGredVqEntryAttrs<'a>, ErrorContext>;
22347 fn next(&mut self) -> Option<Self::Item> {
22348 let mut pos;
22349 let mut r#type;
22350 loop {
22351 pos = self.pos;
22352 r#type = None;
22353 if self.buf.len() == self.pos {
22354 return None;
22355 }
22356 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
22357 self.pos = self.buf.len();
22358 break;
22359 };
22360 r#type = Some(header.r#type);
22361 let res = match header.r#type {
22362 1u16 => TcaGredVqEntryAttrs::Pad({
22363 let res = Some(next);
22364 let Some(val) = res else { break };
22365 val
22366 }),
22367 2u16 => TcaGredVqEntryAttrs::Dp({
22368 let res = parse_u32(next);
22369 let Some(val) = res else { break };
22370 val
22371 }),
22372 3u16 => TcaGredVqEntryAttrs::StatBytes({
22373 let res = parse_u64(next);
22374 let Some(val) = res else { break };
22375 val
22376 }),
22377 4u16 => TcaGredVqEntryAttrs::StatPackets({
22378 let res = parse_u32(next);
22379 let Some(val) = res else { break };
22380 val
22381 }),
22382 5u16 => TcaGredVqEntryAttrs::StatBacklog({
22383 let res = parse_u32(next);
22384 let Some(val) = res else { break };
22385 val
22386 }),
22387 6u16 => TcaGredVqEntryAttrs::StatProbDrop({
22388 let res = parse_u32(next);
22389 let Some(val) = res else { break };
22390 val
22391 }),
22392 7u16 => TcaGredVqEntryAttrs::StatProbMark({
22393 let res = parse_u32(next);
22394 let Some(val) = res else { break };
22395 val
22396 }),
22397 8u16 => TcaGredVqEntryAttrs::StatForcedDrop({
22398 let res = parse_u32(next);
22399 let Some(val) = res else { break };
22400 val
22401 }),
22402 9u16 => TcaGredVqEntryAttrs::StatForcedMark({
22403 let res = parse_u32(next);
22404 let Some(val) = res else { break };
22405 val
22406 }),
22407 10u16 => TcaGredVqEntryAttrs::StatPdrop({
22408 let res = parse_u32(next);
22409 let Some(val) = res else { break };
22410 val
22411 }),
22412 11u16 => TcaGredVqEntryAttrs::StatOther({
22413 let res = parse_u32(next);
22414 let Some(val) = res else { break };
22415 val
22416 }),
22417 12u16 => TcaGredVqEntryAttrs::Flags({
22418 let res = parse_u32(next);
22419 let Some(val) = res else { break };
22420 val
22421 }),
22422 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
22423 n => continue,
22424 };
22425 return Some(Ok(res));
22426 }
22427 Some(Err(ErrorContext::new(
22428 "TcaGredVqEntryAttrs",
22429 r#type.and_then(|t| TcaGredVqEntryAttrs::attr_from_type(t)),
22430 self.orig_loc,
22431 self.buf.as_ptr().wrapping_add(pos) as usize,
22432 )))
22433 }
22434}
22435impl<'a> std::fmt::Debug for IterableTcaGredVqEntryAttrs<'_> {
22436 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22437 let mut fmt = f.debug_struct("TcaGredVqEntryAttrs");
22438 for attr in self.clone() {
22439 let attr = match attr {
22440 Ok(a) => a,
22441 Err(err) => {
22442 fmt.finish()?;
22443 f.write_str("Err(")?;
22444 err.fmt(f)?;
22445 return f.write_str(")");
22446 }
22447 };
22448 match attr {
22449 TcaGredVqEntryAttrs::Pad(val) => fmt.field("Pad", &val),
22450 TcaGredVqEntryAttrs::Dp(val) => fmt.field("Dp", &val),
22451 TcaGredVqEntryAttrs::StatBytes(val) => fmt.field("StatBytes", &val),
22452 TcaGredVqEntryAttrs::StatPackets(val) => fmt.field("StatPackets", &val),
22453 TcaGredVqEntryAttrs::StatBacklog(val) => fmt.field("StatBacklog", &val),
22454 TcaGredVqEntryAttrs::StatProbDrop(val) => fmt.field("StatProbDrop", &val),
22455 TcaGredVqEntryAttrs::StatProbMark(val) => fmt.field("StatProbMark", &val),
22456 TcaGredVqEntryAttrs::StatForcedDrop(val) => fmt.field("StatForcedDrop", &val),
22457 TcaGredVqEntryAttrs::StatForcedMark(val) => fmt.field("StatForcedMark", &val),
22458 TcaGredVqEntryAttrs::StatPdrop(val) => fmt.field("StatPdrop", &val),
22459 TcaGredVqEntryAttrs::StatOther(val) => fmt.field("StatOther", &val),
22460 TcaGredVqEntryAttrs::Flags(val) => fmt.field("Flags", &val),
22461 };
22462 }
22463 fmt.finish()
22464 }
22465}
22466impl IterableTcaGredVqEntryAttrs<'_> {
22467 pub fn lookup_attr(
22468 &self,
22469 offset: usize,
22470 missing_type: Option<u16>,
22471 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22472 let mut stack = Vec::new();
22473 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
22474 if missing_type.is_some() && cur == offset {
22475 stack.push(("TcaGredVqEntryAttrs", offset));
22476 return (
22477 stack,
22478 missing_type.and_then(|t| TcaGredVqEntryAttrs::attr_from_type(t)),
22479 );
22480 }
22481 if cur > offset || cur + self.buf.len() < offset {
22482 return (stack, None);
22483 }
22484 let mut attrs = self.clone();
22485 let mut last_off = cur + attrs.pos;
22486 while let Some(attr) = attrs.next() {
22487 let Ok(attr) = attr else { break };
22488 match attr {
22489 TcaGredVqEntryAttrs::Pad(val) => {
22490 if last_off == offset {
22491 stack.push(("Pad", last_off));
22492 break;
22493 }
22494 }
22495 TcaGredVqEntryAttrs::Dp(val) => {
22496 if last_off == offset {
22497 stack.push(("Dp", last_off));
22498 break;
22499 }
22500 }
22501 TcaGredVqEntryAttrs::StatBytes(val) => {
22502 if last_off == offset {
22503 stack.push(("StatBytes", last_off));
22504 break;
22505 }
22506 }
22507 TcaGredVqEntryAttrs::StatPackets(val) => {
22508 if last_off == offset {
22509 stack.push(("StatPackets", last_off));
22510 break;
22511 }
22512 }
22513 TcaGredVqEntryAttrs::StatBacklog(val) => {
22514 if last_off == offset {
22515 stack.push(("StatBacklog", last_off));
22516 break;
22517 }
22518 }
22519 TcaGredVqEntryAttrs::StatProbDrop(val) => {
22520 if last_off == offset {
22521 stack.push(("StatProbDrop", last_off));
22522 break;
22523 }
22524 }
22525 TcaGredVqEntryAttrs::StatProbMark(val) => {
22526 if last_off == offset {
22527 stack.push(("StatProbMark", last_off));
22528 break;
22529 }
22530 }
22531 TcaGredVqEntryAttrs::StatForcedDrop(val) => {
22532 if last_off == offset {
22533 stack.push(("StatForcedDrop", last_off));
22534 break;
22535 }
22536 }
22537 TcaGredVqEntryAttrs::StatForcedMark(val) => {
22538 if last_off == offset {
22539 stack.push(("StatForcedMark", last_off));
22540 break;
22541 }
22542 }
22543 TcaGredVqEntryAttrs::StatPdrop(val) => {
22544 if last_off == offset {
22545 stack.push(("StatPdrop", last_off));
22546 break;
22547 }
22548 }
22549 TcaGredVqEntryAttrs::StatOther(val) => {
22550 if last_off == offset {
22551 stack.push(("StatOther", last_off));
22552 break;
22553 }
22554 }
22555 TcaGredVqEntryAttrs::Flags(val) => {
22556 if last_off == offset {
22557 stack.push(("Flags", last_off));
22558 break;
22559 }
22560 }
22561 _ => {}
22562 };
22563 last_off = cur + attrs.pos;
22564 }
22565 if !stack.is_empty() {
22566 stack.push(("TcaGredVqEntryAttrs", cur));
22567 }
22568 (stack, None)
22569 }
22570}
22571#[derive(Clone)]
22572pub enum HfscAttrs<'a> {
22573 Rsc(&'a [u8]),
22574 Fsc(&'a [u8]),
22575 Usc(&'a [u8]),
22576}
22577impl<'a> IterableHfscAttrs<'a> {
22578 pub fn get_rsc(&self) -> Result<&'a [u8], ErrorContext> {
22579 let mut iter = self.clone();
22580 iter.pos = 0;
22581 for attr in iter {
22582 if let Ok(HfscAttrs::Rsc(val)) = attr {
22583 return Ok(val);
22584 }
22585 }
22586 Err(ErrorContext::new_missing(
22587 "HfscAttrs",
22588 "Rsc",
22589 self.orig_loc,
22590 self.buf.as_ptr() as usize,
22591 ))
22592 }
22593 pub fn get_fsc(&self) -> Result<&'a [u8], ErrorContext> {
22594 let mut iter = self.clone();
22595 iter.pos = 0;
22596 for attr in iter {
22597 if let Ok(HfscAttrs::Fsc(val)) = attr {
22598 return Ok(val);
22599 }
22600 }
22601 Err(ErrorContext::new_missing(
22602 "HfscAttrs",
22603 "Fsc",
22604 self.orig_loc,
22605 self.buf.as_ptr() as usize,
22606 ))
22607 }
22608 pub fn get_usc(&self) -> Result<&'a [u8], ErrorContext> {
22609 let mut iter = self.clone();
22610 iter.pos = 0;
22611 for attr in iter {
22612 if let Ok(HfscAttrs::Usc(val)) = attr {
22613 return Ok(val);
22614 }
22615 }
22616 Err(ErrorContext::new_missing(
22617 "HfscAttrs",
22618 "Usc",
22619 self.orig_loc,
22620 self.buf.as_ptr() as usize,
22621 ))
22622 }
22623}
22624impl HfscAttrs<'_> {
22625 pub fn new<'a>(buf: &'a [u8]) -> IterableHfscAttrs<'a> {
22626 IterableHfscAttrs::with_loc(buf, buf.as_ptr() as usize)
22627 }
22628 fn attr_from_type(r#type: u16) -> Option<&'static str> {
22629 let res = match r#type {
22630 1u16 => "Rsc",
22631 2u16 => "Fsc",
22632 3u16 => "Usc",
22633 _ => return None,
22634 };
22635 Some(res)
22636 }
22637}
22638#[derive(Clone, Copy, Default)]
22639pub struct IterableHfscAttrs<'a> {
22640 buf: &'a [u8],
22641 pos: usize,
22642 orig_loc: usize,
22643}
22644impl<'a> IterableHfscAttrs<'a> {
22645 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22646 Self {
22647 buf,
22648 pos: 0,
22649 orig_loc,
22650 }
22651 }
22652 pub fn get_buf(&self) -> &'a [u8] {
22653 self.buf
22654 }
22655}
22656impl<'a> Iterator for IterableHfscAttrs<'a> {
22657 type Item = Result<HfscAttrs<'a>, ErrorContext>;
22658 fn next(&mut self) -> Option<Self::Item> {
22659 let mut pos;
22660 let mut r#type;
22661 loop {
22662 pos = self.pos;
22663 r#type = None;
22664 if self.buf.len() == self.pos {
22665 return None;
22666 }
22667 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
22668 self.pos = self.buf.len();
22669 break;
22670 };
22671 r#type = Some(header.r#type);
22672 let res = match header.r#type {
22673 1u16 => HfscAttrs::Rsc({
22674 let res = Some(next);
22675 let Some(val) = res else { break };
22676 val
22677 }),
22678 2u16 => HfscAttrs::Fsc({
22679 let res = Some(next);
22680 let Some(val) = res else { break };
22681 val
22682 }),
22683 3u16 => HfscAttrs::Usc({
22684 let res = Some(next);
22685 let Some(val) = res else { break };
22686 val
22687 }),
22688 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
22689 n => continue,
22690 };
22691 return Some(Ok(res));
22692 }
22693 Some(Err(ErrorContext::new(
22694 "HfscAttrs",
22695 r#type.and_then(|t| HfscAttrs::attr_from_type(t)),
22696 self.orig_loc,
22697 self.buf.as_ptr().wrapping_add(pos) as usize,
22698 )))
22699 }
22700}
22701impl<'a> std::fmt::Debug for IterableHfscAttrs<'_> {
22702 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22703 let mut fmt = f.debug_struct("HfscAttrs");
22704 for attr in self.clone() {
22705 let attr = match attr {
22706 Ok(a) => a,
22707 Err(err) => {
22708 fmt.finish()?;
22709 f.write_str("Err(")?;
22710 err.fmt(f)?;
22711 return f.write_str(")");
22712 }
22713 };
22714 match attr {
22715 HfscAttrs::Rsc(val) => fmt.field("Rsc", &val),
22716 HfscAttrs::Fsc(val) => fmt.field("Fsc", &val),
22717 HfscAttrs::Usc(val) => fmt.field("Usc", &val),
22718 };
22719 }
22720 fmt.finish()
22721 }
22722}
22723impl IterableHfscAttrs<'_> {
22724 pub fn lookup_attr(
22725 &self,
22726 offset: usize,
22727 missing_type: Option<u16>,
22728 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22729 let mut stack = Vec::new();
22730 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
22731 if missing_type.is_some() && cur == offset {
22732 stack.push(("HfscAttrs", offset));
22733 return (
22734 stack,
22735 missing_type.and_then(|t| HfscAttrs::attr_from_type(t)),
22736 );
22737 }
22738 if cur > offset || cur + self.buf.len() < offset {
22739 return (stack, None);
22740 }
22741 let mut attrs = self.clone();
22742 let mut last_off = cur + attrs.pos;
22743 while let Some(attr) = attrs.next() {
22744 let Ok(attr) = attr else { break };
22745 match attr {
22746 HfscAttrs::Rsc(val) => {
22747 if last_off == offset {
22748 stack.push(("Rsc", last_off));
22749 break;
22750 }
22751 }
22752 HfscAttrs::Fsc(val) => {
22753 if last_off == offset {
22754 stack.push(("Fsc", last_off));
22755 break;
22756 }
22757 }
22758 HfscAttrs::Usc(val) => {
22759 if last_off == offset {
22760 stack.push(("Usc", last_off));
22761 break;
22762 }
22763 }
22764 _ => {}
22765 };
22766 last_off = cur + attrs.pos;
22767 }
22768 if !stack.is_empty() {
22769 stack.push(("HfscAttrs", cur));
22770 }
22771 (stack, None)
22772 }
22773}
22774#[derive(Clone)]
22775pub enum HhfAttrs {
22776 BacklogLimit(u32),
22777 Quantum(u32),
22778 HhFlowsLimit(u32),
22779 ResetTimeout(u32),
22780 AdmitBytes(u32),
22781 EvictTimeout(u32),
22782 NonHhWeight(u32),
22783}
22784impl<'a> IterableHhfAttrs<'a> {
22785 pub fn get_backlog_limit(&self) -> Result<u32, ErrorContext> {
22786 let mut iter = self.clone();
22787 iter.pos = 0;
22788 for attr in iter {
22789 if let Ok(HhfAttrs::BacklogLimit(val)) = attr {
22790 return Ok(val);
22791 }
22792 }
22793 Err(ErrorContext::new_missing(
22794 "HhfAttrs",
22795 "BacklogLimit",
22796 self.orig_loc,
22797 self.buf.as_ptr() as usize,
22798 ))
22799 }
22800 pub fn get_quantum(&self) -> Result<u32, ErrorContext> {
22801 let mut iter = self.clone();
22802 iter.pos = 0;
22803 for attr in iter {
22804 if let Ok(HhfAttrs::Quantum(val)) = attr {
22805 return Ok(val);
22806 }
22807 }
22808 Err(ErrorContext::new_missing(
22809 "HhfAttrs",
22810 "Quantum",
22811 self.orig_loc,
22812 self.buf.as_ptr() as usize,
22813 ))
22814 }
22815 pub fn get_hh_flows_limit(&self) -> Result<u32, ErrorContext> {
22816 let mut iter = self.clone();
22817 iter.pos = 0;
22818 for attr in iter {
22819 if let Ok(HhfAttrs::HhFlowsLimit(val)) = attr {
22820 return Ok(val);
22821 }
22822 }
22823 Err(ErrorContext::new_missing(
22824 "HhfAttrs",
22825 "HhFlowsLimit",
22826 self.orig_loc,
22827 self.buf.as_ptr() as usize,
22828 ))
22829 }
22830 pub fn get_reset_timeout(&self) -> Result<u32, ErrorContext> {
22831 let mut iter = self.clone();
22832 iter.pos = 0;
22833 for attr in iter {
22834 if let Ok(HhfAttrs::ResetTimeout(val)) = attr {
22835 return Ok(val);
22836 }
22837 }
22838 Err(ErrorContext::new_missing(
22839 "HhfAttrs",
22840 "ResetTimeout",
22841 self.orig_loc,
22842 self.buf.as_ptr() as usize,
22843 ))
22844 }
22845 pub fn get_admit_bytes(&self) -> Result<u32, ErrorContext> {
22846 let mut iter = self.clone();
22847 iter.pos = 0;
22848 for attr in iter {
22849 if let Ok(HhfAttrs::AdmitBytes(val)) = attr {
22850 return Ok(val);
22851 }
22852 }
22853 Err(ErrorContext::new_missing(
22854 "HhfAttrs",
22855 "AdmitBytes",
22856 self.orig_loc,
22857 self.buf.as_ptr() as usize,
22858 ))
22859 }
22860 pub fn get_evict_timeout(&self) -> Result<u32, ErrorContext> {
22861 let mut iter = self.clone();
22862 iter.pos = 0;
22863 for attr in iter {
22864 if let Ok(HhfAttrs::EvictTimeout(val)) = attr {
22865 return Ok(val);
22866 }
22867 }
22868 Err(ErrorContext::new_missing(
22869 "HhfAttrs",
22870 "EvictTimeout",
22871 self.orig_loc,
22872 self.buf.as_ptr() as usize,
22873 ))
22874 }
22875 pub fn get_non_hh_weight(&self) -> Result<u32, ErrorContext> {
22876 let mut iter = self.clone();
22877 iter.pos = 0;
22878 for attr in iter {
22879 if let Ok(HhfAttrs::NonHhWeight(val)) = attr {
22880 return Ok(val);
22881 }
22882 }
22883 Err(ErrorContext::new_missing(
22884 "HhfAttrs",
22885 "NonHhWeight",
22886 self.orig_loc,
22887 self.buf.as_ptr() as usize,
22888 ))
22889 }
22890}
22891impl HhfAttrs {
22892 pub fn new<'a>(buf: &'a [u8]) -> IterableHhfAttrs<'a> {
22893 IterableHhfAttrs::with_loc(buf, buf.as_ptr() as usize)
22894 }
22895 fn attr_from_type(r#type: u16) -> Option<&'static str> {
22896 let res = match r#type {
22897 1u16 => "BacklogLimit",
22898 2u16 => "Quantum",
22899 3u16 => "HhFlowsLimit",
22900 4u16 => "ResetTimeout",
22901 5u16 => "AdmitBytes",
22902 6u16 => "EvictTimeout",
22903 7u16 => "NonHhWeight",
22904 _ => return None,
22905 };
22906 Some(res)
22907 }
22908}
22909#[derive(Clone, Copy, Default)]
22910pub struct IterableHhfAttrs<'a> {
22911 buf: &'a [u8],
22912 pos: usize,
22913 orig_loc: usize,
22914}
22915impl<'a> IterableHhfAttrs<'a> {
22916 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22917 Self {
22918 buf,
22919 pos: 0,
22920 orig_loc,
22921 }
22922 }
22923 pub fn get_buf(&self) -> &'a [u8] {
22924 self.buf
22925 }
22926}
22927impl<'a> Iterator for IterableHhfAttrs<'a> {
22928 type Item = Result<HhfAttrs, ErrorContext>;
22929 fn next(&mut self) -> Option<Self::Item> {
22930 let mut pos;
22931 let mut r#type;
22932 loop {
22933 pos = self.pos;
22934 r#type = None;
22935 if self.buf.len() == self.pos {
22936 return None;
22937 }
22938 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
22939 self.pos = self.buf.len();
22940 break;
22941 };
22942 r#type = Some(header.r#type);
22943 let res = match header.r#type {
22944 1u16 => HhfAttrs::BacklogLimit({
22945 let res = parse_u32(next);
22946 let Some(val) = res else { break };
22947 val
22948 }),
22949 2u16 => HhfAttrs::Quantum({
22950 let res = parse_u32(next);
22951 let Some(val) = res else { break };
22952 val
22953 }),
22954 3u16 => HhfAttrs::HhFlowsLimit({
22955 let res = parse_u32(next);
22956 let Some(val) = res else { break };
22957 val
22958 }),
22959 4u16 => HhfAttrs::ResetTimeout({
22960 let res = parse_u32(next);
22961 let Some(val) = res else { break };
22962 val
22963 }),
22964 5u16 => HhfAttrs::AdmitBytes({
22965 let res = parse_u32(next);
22966 let Some(val) = res else { break };
22967 val
22968 }),
22969 6u16 => HhfAttrs::EvictTimeout({
22970 let res = parse_u32(next);
22971 let Some(val) = res else { break };
22972 val
22973 }),
22974 7u16 => HhfAttrs::NonHhWeight({
22975 let res = parse_u32(next);
22976 let Some(val) = res else { break };
22977 val
22978 }),
22979 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
22980 n => continue,
22981 };
22982 return Some(Ok(res));
22983 }
22984 Some(Err(ErrorContext::new(
22985 "HhfAttrs",
22986 r#type.and_then(|t| HhfAttrs::attr_from_type(t)),
22987 self.orig_loc,
22988 self.buf.as_ptr().wrapping_add(pos) as usize,
22989 )))
22990 }
22991}
22992impl std::fmt::Debug for IterableHhfAttrs<'_> {
22993 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22994 let mut fmt = f.debug_struct("HhfAttrs");
22995 for attr in self.clone() {
22996 let attr = match attr {
22997 Ok(a) => a,
22998 Err(err) => {
22999 fmt.finish()?;
23000 f.write_str("Err(")?;
23001 err.fmt(f)?;
23002 return f.write_str(")");
23003 }
23004 };
23005 match attr {
23006 HhfAttrs::BacklogLimit(val) => fmt.field("BacklogLimit", &val),
23007 HhfAttrs::Quantum(val) => fmt.field("Quantum", &val),
23008 HhfAttrs::HhFlowsLimit(val) => fmt.field("HhFlowsLimit", &val),
23009 HhfAttrs::ResetTimeout(val) => fmt.field("ResetTimeout", &val),
23010 HhfAttrs::AdmitBytes(val) => fmt.field("AdmitBytes", &val),
23011 HhfAttrs::EvictTimeout(val) => fmt.field("EvictTimeout", &val),
23012 HhfAttrs::NonHhWeight(val) => fmt.field("NonHhWeight", &val),
23013 };
23014 }
23015 fmt.finish()
23016 }
23017}
23018impl IterableHhfAttrs<'_> {
23019 pub fn lookup_attr(
23020 &self,
23021 offset: usize,
23022 missing_type: Option<u16>,
23023 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23024 let mut stack = Vec::new();
23025 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23026 if missing_type.is_some() && cur == offset {
23027 stack.push(("HhfAttrs", offset));
23028 return (
23029 stack,
23030 missing_type.and_then(|t| HhfAttrs::attr_from_type(t)),
23031 );
23032 }
23033 if cur > offset || cur + self.buf.len() < offset {
23034 return (stack, None);
23035 }
23036 let mut attrs = self.clone();
23037 let mut last_off = cur + attrs.pos;
23038 while let Some(attr) = attrs.next() {
23039 let Ok(attr) = attr else { break };
23040 match attr {
23041 HhfAttrs::BacklogLimit(val) => {
23042 if last_off == offset {
23043 stack.push(("BacklogLimit", last_off));
23044 break;
23045 }
23046 }
23047 HhfAttrs::Quantum(val) => {
23048 if last_off == offset {
23049 stack.push(("Quantum", last_off));
23050 break;
23051 }
23052 }
23053 HhfAttrs::HhFlowsLimit(val) => {
23054 if last_off == offset {
23055 stack.push(("HhFlowsLimit", last_off));
23056 break;
23057 }
23058 }
23059 HhfAttrs::ResetTimeout(val) => {
23060 if last_off == offset {
23061 stack.push(("ResetTimeout", last_off));
23062 break;
23063 }
23064 }
23065 HhfAttrs::AdmitBytes(val) => {
23066 if last_off == offset {
23067 stack.push(("AdmitBytes", last_off));
23068 break;
23069 }
23070 }
23071 HhfAttrs::EvictTimeout(val) => {
23072 if last_off == offset {
23073 stack.push(("EvictTimeout", last_off));
23074 break;
23075 }
23076 }
23077 HhfAttrs::NonHhWeight(val) => {
23078 if last_off == offset {
23079 stack.push(("NonHhWeight", last_off));
23080 break;
23081 }
23082 }
23083 _ => {}
23084 };
23085 last_off = cur + attrs.pos;
23086 }
23087 if !stack.is_empty() {
23088 stack.push(("HhfAttrs", cur));
23089 }
23090 (stack, None)
23091 }
23092}
23093#[derive(Clone)]
23094pub enum HtbAttrs<'a> {
23095 Parms(TcHtbOpt),
23096 Init(TcHtbGlob),
23097 Ctab(&'a [u8]),
23098 Rtab(&'a [u8]),
23099 DirectQlen(u32),
23100 Rate64(u64),
23101 Ceil64(u64),
23102 Pad(&'a [u8]),
23103 Offload(()),
23104}
23105impl<'a> IterableHtbAttrs<'a> {
23106 pub fn get_parms(&self) -> Result<TcHtbOpt, ErrorContext> {
23107 let mut iter = self.clone();
23108 iter.pos = 0;
23109 for attr in iter {
23110 if let Ok(HtbAttrs::Parms(val)) = attr {
23111 return Ok(val);
23112 }
23113 }
23114 Err(ErrorContext::new_missing(
23115 "HtbAttrs",
23116 "Parms",
23117 self.orig_loc,
23118 self.buf.as_ptr() as usize,
23119 ))
23120 }
23121 pub fn get_init(&self) -> Result<TcHtbGlob, ErrorContext> {
23122 let mut iter = self.clone();
23123 iter.pos = 0;
23124 for attr in iter {
23125 if let Ok(HtbAttrs::Init(val)) = attr {
23126 return Ok(val);
23127 }
23128 }
23129 Err(ErrorContext::new_missing(
23130 "HtbAttrs",
23131 "Init",
23132 self.orig_loc,
23133 self.buf.as_ptr() as usize,
23134 ))
23135 }
23136 pub fn get_ctab(&self) -> Result<&'a [u8], ErrorContext> {
23137 let mut iter = self.clone();
23138 iter.pos = 0;
23139 for attr in iter {
23140 if let Ok(HtbAttrs::Ctab(val)) = attr {
23141 return Ok(val);
23142 }
23143 }
23144 Err(ErrorContext::new_missing(
23145 "HtbAttrs",
23146 "Ctab",
23147 self.orig_loc,
23148 self.buf.as_ptr() as usize,
23149 ))
23150 }
23151 pub fn get_rtab(&self) -> Result<&'a [u8], ErrorContext> {
23152 let mut iter = self.clone();
23153 iter.pos = 0;
23154 for attr in iter {
23155 if let Ok(HtbAttrs::Rtab(val)) = attr {
23156 return Ok(val);
23157 }
23158 }
23159 Err(ErrorContext::new_missing(
23160 "HtbAttrs",
23161 "Rtab",
23162 self.orig_loc,
23163 self.buf.as_ptr() as usize,
23164 ))
23165 }
23166 pub fn get_direct_qlen(&self) -> Result<u32, ErrorContext> {
23167 let mut iter = self.clone();
23168 iter.pos = 0;
23169 for attr in iter {
23170 if let Ok(HtbAttrs::DirectQlen(val)) = attr {
23171 return Ok(val);
23172 }
23173 }
23174 Err(ErrorContext::new_missing(
23175 "HtbAttrs",
23176 "DirectQlen",
23177 self.orig_loc,
23178 self.buf.as_ptr() as usize,
23179 ))
23180 }
23181 pub fn get_rate64(&self) -> Result<u64, ErrorContext> {
23182 let mut iter = self.clone();
23183 iter.pos = 0;
23184 for attr in iter {
23185 if let Ok(HtbAttrs::Rate64(val)) = attr {
23186 return Ok(val);
23187 }
23188 }
23189 Err(ErrorContext::new_missing(
23190 "HtbAttrs",
23191 "Rate64",
23192 self.orig_loc,
23193 self.buf.as_ptr() as usize,
23194 ))
23195 }
23196 pub fn get_ceil64(&self) -> Result<u64, ErrorContext> {
23197 let mut iter = self.clone();
23198 iter.pos = 0;
23199 for attr in iter {
23200 if let Ok(HtbAttrs::Ceil64(val)) = attr {
23201 return Ok(val);
23202 }
23203 }
23204 Err(ErrorContext::new_missing(
23205 "HtbAttrs",
23206 "Ceil64",
23207 self.orig_loc,
23208 self.buf.as_ptr() as usize,
23209 ))
23210 }
23211 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
23212 let mut iter = self.clone();
23213 iter.pos = 0;
23214 for attr in iter {
23215 if let Ok(HtbAttrs::Pad(val)) = attr {
23216 return Ok(val);
23217 }
23218 }
23219 Err(ErrorContext::new_missing(
23220 "HtbAttrs",
23221 "Pad",
23222 self.orig_loc,
23223 self.buf.as_ptr() as usize,
23224 ))
23225 }
23226 pub fn get_offload(&self) -> Result<(), ErrorContext> {
23227 let mut iter = self.clone();
23228 iter.pos = 0;
23229 for attr in iter {
23230 if let Ok(HtbAttrs::Offload(val)) = attr {
23231 return Ok(val);
23232 }
23233 }
23234 Err(ErrorContext::new_missing(
23235 "HtbAttrs",
23236 "Offload",
23237 self.orig_loc,
23238 self.buf.as_ptr() as usize,
23239 ))
23240 }
23241}
23242impl HtbAttrs<'_> {
23243 pub fn new<'a>(buf: &'a [u8]) -> IterableHtbAttrs<'a> {
23244 IterableHtbAttrs::with_loc(buf, buf.as_ptr() as usize)
23245 }
23246 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23247 let res = match r#type {
23248 1u16 => "Parms",
23249 2u16 => "Init",
23250 3u16 => "Ctab",
23251 4u16 => "Rtab",
23252 5u16 => "DirectQlen",
23253 6u16 => "Rate64",
23254 7u16 => "Ceil64",
23255 8u16 => "Pad",
23256 9u16 => "Offload",
23257 _ => return None,
23258 };
23259 Some(res)
23260 }
23261}
23262#[derive(Clone, Copy, Default)]
23263pub struct IterableHtbAttrs<'a> {
23264 buf: &'a [u8],
23265 pos: usize,
23266 orig_loc: usize,
23267}
23268impl<'a> IterableHtbAttrs<'a> {
23269 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
23270 Self {
23271 buf,
23272 pos: 0,
23273 orig_loc,
23274 }
23275 }
23276 pub fn get_buf(&self) -> &'a [u8] {
23277 self.buf
23278 }
23279}
23280impl<'a> Iterator for IterableHtbAttrs<'a> {
23281 type Item = Result<HtbAttrs<'a>, ErrorContext>;
23282 fn next(&mut self) -> Option<Self::Item> {
23283 let mut pos;
23284 let mut r#type;
23285 loop {
23286 pos = self.pos;
23287 r#type = None;
23288 if self.buf.len() == self.pos {
23289 return None;
23290 }
23291 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
23292 self.pos = self.buf.len();
23293 break;
23294 };
23295 r#type = Some(header.r#type);
23296 let res = match header.r#type {
23297 1u16 => HtbAttrs::Parms({
23298 let res = Some(TcHtbOpt::new_from_zeroed(next));
23299 let Some(val) = res else { break };
23300 val
23301 }),
23302 2u16 => HtbAttrs::Init({
23303 let res = Some(TcHtbGlob::new_from_zeroed(next));
23304 let Some(val) = res else { break };
23305 val
23306 }),
23307 3u16 => HtbAttrs::Ctab({
23308 let res = Some(next);
23309 let Some(val) = res else { break };
23310 val
23311 }),
23312 4u16 => HtbAttrs::Rtab({
23313 let res = Some(next);
23314 let Some(val) = res else { break };
23315 val
23316 }),
23317 5u16 => HtbAttrs::DirectQlen({
23318 let res = parse_u32(next);
23319 let Some(val) = res else { break };
23320 val
23321 }),
23322 6u16 => HtbAttrs::Rate64({
23323 let res = parse_u64(next);
23324 let Some(val) = res else { break };
23325 val
23326 }),
23327 7u16 => HtbAttrs::Ceil64({
23328 let res = parse_u64(next);
23329 let Some(val) = res else { break };
23330 val
23331 }),
23332 8u16 => HtbAttrs::Pad({
23333 let res = Some(next);
23334 let Some(val) = res else { break };
23335 val
23336 }),
23337 9u16 => HtbAttrs::Offload(()),
23338 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
23339 n => continue,
23340 };
23341 return Some(Ok(res));
23342 }
23343 Some(Err(ErrorContext::new(
23344 "HtbAttrs",
23345 r#type.and_then(|t| HtbAttrs::attr_from_type(t)),
23346 self.orig_loc,
23347 self.buf.as_ptr().wrapping_add(pos) as usize,
23348 )))
23349 }
23350}
23351impl<'a> std::fmt::Debug for IterableHtbAttrs<'_> {
23352 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23353 let mut fmt = f.debug_struct("HtbAttrs");
23354 for attr in self.clone() {
23355 let attr = match attr {
23356 Ok(a) => a,
23357 Err(err) => {
23358 fmt.finish()?;
23359 f.write_str("Err(")?;
23360 err.fmt(f)?;
23361 return f.write_str(")");
23362 }
23363 };
23364 match attr {
23365 HtbAttrs::Parms(val) => fmt.field("Parms", &val),
23366 HtbAttrs::Init(val) => fmt.field("Init", &val),
23367 HtbAttrs::Ctab(val) => fmt.field("Ctab", &val),
23368 HtbAttrs::Rtab(val) => fmt.field("Rtab", &val),
23369 HtbAttrs::DirectQlen(val) => fmt.field("DirectQlen", &val),
23370 HtbAttrs::Rate64(val) => fmt.field("Rate64", &val),
23371 HtbAttrs::Ceil64(val) => fmt.field("Ceil64", &val),
23372 HtbAttrs::Pad(val) => fmt.field("Pad", &val),
23373 HtbAttrs::Offload(val) => fmt.field("Offload", &val),
23374 };
23375 }
23376 fmt.finish()
23377 }
23378}
23379impl IterableHtbAttrs<'_> {
23380 pub fn lookup_attr(
23381 &self,
23382 offset: usize,
23383 missing_type: Option<u16>,
23384 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23385 let mut stack = Vec::new();
23386 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23387 if missing_type.is_some() && cur == offset {
23388 stack.push(("HtbAttrs", offset));
23389 return (
23390 stack,
23391 missing_type.and_then(|t| HtbAttrs::attr_from_type(t)),
23392 );
23393 }
23394 if cur > offset || cur + self.buf.len() < offset {
23395 return (stack, None);
23396 }
23397 let mut attrs = self.clone();
23398 let mut last_off = cur + attrs.pos;
23399 while let Some(attr) = attrs.next() {
23400 let Ok(attr) = attr else { break };
23401 match attr {
23402 HtbAttrs::Parms(val) => {
23403 if last_off == offset {
23404 stack.push(("Parms", last_off));
23405 break;
23406 }
23407 }
23408 HtbAttrs::Init(val) => {
23409 if last_off == offset {
23410 stack.push(("Init", last_off));
23411 break;
23412 }
23413 }
23414 HtbAttrs::Ctab(val) => {
23415 if last_off == offset {
23416 stack.push(("Ctab", last_off));
23417 break;
23418 }
23419 }
23420 HtbAttrs::Rtab(val) => {
23421 if last_off == offset {
23422 stack.push(("Rtab", last_off));
23423 break;
23424 }
23425 }
23426 HtbAttrs::DirectQlen(val) => {
23427 if last_off == offset {
23428 stack.push(("DirectQlen", last_off));
23429 break;
23430 }
23431 }
23432 HtbAttrs::Rate64(val) => {
23433 if last_off == offset {
23434 stack.push(("Rate64", last_off));
23435 break;
23436 }
23437 }
23438 HtbAttrs::Ceil64(val) => {
23439 if last_off == offset {
23440 stack.push(("Ceil64", last_off));
23441 break;
23442 }
23443 }
23444 HtbAttrs::Pad(val) => {
23445 if last_off == offset {
23446 stack.push(("Pad", last_off));
23447 break;
23448 }
23449 }
23450 HtbAttrs::Offload(val) => {
23451 if last_off == offset {
23452 stack.push(("Offload", last_off));
23453 break;
23454 }
23455 }
23456 _ => {}
23457 };
23458 last_off = cur + attrs.pos;
23459 }
23460 if !stack.is_empty() {
23461 stack.push(("HtbAttrs", cur));
23462 }
23463 (stack, None)
23464 }
23465}
23466#[derive(Clone)]
23467pub enum MatchallAttrs<'a> {
23468 Classid(u32),
23469 Act(IterableArrayActAttrs<'a>),
23470 Flags(u32),
23471 Pcnt(TcMatchallPcnt),
23472 Pad(&'a [u8]),
23473}
23474impl<'a> IterableMatchallAttrs<'a> {
23475 pub fn get_classid(&self) -> Result<u32, ErrorContext> {
23476 let mut iter = self.clone();
23477 iter.pos = 0;
23478 for attr in iter {
23479 if let Ok(MatchallAttrs::Classid(val)) = attr {
23480 return Ok(val);
23481 }
23482 }
23483 Err(ErrorContext::new_missing(
23484 "MatchallAttrs",
23485 "Classid",
23486 self.orig_loc,
23487 self.buf.as_ptr() as usize,
23488 ))
23489 }
23490 pub fn get_act(
23491 &self,
23492 ) -> Result<ArrayIterable<IterableArrayActAttrs<'a>, IterableActAttrs<'a>>, ErrorContext> {
23493 for attr in self.clone() {
23494 if let Ok(MatchallAttrs::Act(val)) = attr {
23495 return Ok(ArrayIterable::new(val));
23496 }
23497 }
23498 Err(ErrorContext::new_missing(
23499 "MatchallAttrs",
23500 "Act",
23501 self.orig_loc,
23502 self.buf.as_ptr() as usize,
23503 ))
23504 }
23505 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
23506 let mut iter = self.clone();
23507 iter.pos = 0;
23508 for attr in iter {
23509 if let Ok(MatchallAttrs::Flags(val)) = attr {
23510 return Ok(val);
23511 }
23512 }
23513 Err(ErrorContext::new_missing(
23514 "MatchallAttrs",
23515 "Flags",
23516 self.orig_loc,
23517 self.buf.as_ptr() as usize,
23518 ))
23519 }
23520 pub fn get_pcnt(&self) -> Result<TcMatchallPcnt, ErrorContext> {
23521 let mut iter = self.clone();
23522 iter.pos = 0;
23523 for attr in iter {
23524 if let Ok(MatchallAttrs::Pcnt(val)) = attr {
23525 return Ok(val);
23526 }
23527 }
23528 Err(ErrorContext::new_missing(
23529 "MatchallAttrs",
23530 "Pcnt",
23531 self.orig_loc,
23532 self.buf.as_ptr() as usize,
23533 ))
23534 }
23535 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
23536 let mut iter = self.clone();
23537 iter.pos = 0;
23538 for attr in iter {
23539 if let Ok(MatchallAttrs::Pad(val)) = attr {
23540 return Ok(val);
23541 }
23542 }
23543 Err(ErrorContext::new_missing(
23544 "MatchallAttrs",
23545 "Pad",
23546 self.orig_loc,
23547 self.buf.as_ptr() as usize,
23548 ))
23549 }
23550}
23551impl MatchallAttrs<'_> {
23552 pub fn new<'a>(buf: &'a [u8]) -> IterableMatchallAttrs<'a> {
23553 IterableMatchallAttrs::with_loc(buf, buf.as_ptr() as usize)
23554 }
23555 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23556 let res = match r#type {
23557 1u16 => "Classid",
23558 2u16 => "Act",
23559 3u16 => "Flags",
23560 4u16 => "Pcnt",
23561 5u16 => "Pad",
23562 _ => return None,
23563 };
23564 Some(res)
23565 }
23566}
23567#[derive(Clone, Copy, Default)]
23568pub struct IterableMatchallAttrs<'a> {
23569 buf: &'a [u8],
23570 pos: usize,
23571 orig_loc: usize,
23572}
23573impl<'a> IterableMatchallAttrs<'a> {
23574 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
23575 Self {
23576 buf,
23577 pos: 0,
23578 orig_loc,
23579 }
23580 }
23581 pub fn get_buf(&self) -> &'a [u8] {
23582 self.buf
23583 }
23584}
23585impl<'a> Iterator for IterableMatchallAttrs<'a> {
23586 type Item = Result<MatchallAttrs<'a>, ErrorContext>;
23587 fn next(&mut self) -> Option<Self::Item> {
23588 let mut pos;
23589 let mut r#type;
23590 loop {
23591 pos = self.pos;
23592 r#type = None;
23593 if self.buf.len() == self.pos {
23594 return None;
23595 }
23596 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
23597 self.pos = self.buf.len();
23598 break;
23599 };
23600 r#type = Some(header.r#type);
23601 let res = match header.r#type {
23602 1u16 => MatchallAttrs::Classid({
23603 let res = parse_u32(next);
23604 let Some(val) = res else { break };
23605 val
23606 }),
23607 2u16 => MatchallAttrs::Act({
23608 let res = Some(IterableArrayActAttrs::with_loc(next, self.orig_loc));
23609 let Some(val) = res else { break };
23610 val
23611 }),
23612 3u16 => MatchallAttrs::Flags({
23613 let res = parse_u32(next);
23614 let Some(val) = res else { break };
23615 val
23616 }),
23617 4u16 => MatchallAttrs::Pcnt({
23618 let res = Some(TcMatchallPcnt::new_from_zeroed(next));
23619 let Some(val) = res else { break };
23620 val
23621 }),
23622 5u16 => MatchallAttrs::Pad({
23623 let res = Some(next);
23624 let Some(val) = res else { break };
23625 val
23626 }),
23627 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
23628 n => continue,
23629 };
23630 return Some(Ok(res));
23631 }
23632 Some(Err(ErrorContext::new(
23633 "MatchallAttrs",
23634 r#type.and_then(|t| MatchallAttrs::attr_from_type(t)),
23635 self.orig_loc,
23636 self.buf.as_ptr().wrapping_add(pos) as usize,
23637 )))
23638 }
23639}
23640impl<'a> std::fmt::Debug for IterableMatchallAttrs<'_> {
23641 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23642 let mut fmt = f.debug_struct("MatchallAttrs");
23643 for attr in self.clone() {
23644 let attr = match attr {
23645 Ok(a) => a,
23646 Err(err) => {
23647 fmt.finish()?;
23648 f.write_str("Err(")?;
23649 err.fmt(f)?;
23650 return f.write_str(")");
23651 }
23652 };
23653 match attr {
23654 MatchallAttrs::Classid(val) => fmt.field("Classid", &val),
23655 MatchallAttrs::Act(val) => fmt.field("Act", &val),
23656 MatchallAttrs::Flags(val) => fmt.field("Flags", &val),
23657 MatchallAttrs::Pcnt(val) => fmt.field("Pcnt", &val),
23658 MatchallAttrs::Pad(val) => fmt.field("Pad", &val),
23659 };
23660 }
23661 fmt.finish()
23662 }
23663}
23664impl IterableMatchallAttrs<'_> {
23665 pub fn lookup_attr(
23666 &self,
23667 offset: usize,
23668 missing_type: Option<u16>,
23669 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23670 let mut stack = Vec::new();
23671 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23672 if missing_type.is_some() && cur == offset {
23673 stack.push(("MatchallAttrs", offset));
23674 return (
23675 stack,
23676 missing_type.and_then(|t| MatchallAttrs::attr_from_type(t)),
23677 );
23678 }
23679 if cur > offset || cur + self.buf.len() < offset {
23680 return (stack, None);
23681 }
23682 let mut attrs = self.clone();
23683 let mut last_off = cur + attrs.pos;
23684 let mut missing = None;
23685 while let Some(attr) = attrs.next() {
23686 let Ok(attr) = attr else { break };
23687 match attr {
23688 MatchallAttrs::Classid(val) => {
23689 if last_off == offset {
23690 stack.push(("Classid", last_off));
23691 break;
23692 }
23693 }
23694 MatchallAttrs::Act(val) => {
23695 for entry in val {
23696 let Ok(attr) = entry else { break };
23697 (stack, missing) = attr.lookup_attr(offset, missing_type);
23698 if !stack.is_empty() {
23699 break;
23700 }
23701 }
23702 if !stack.is_empty() {
23703 stack.push(("Act", last_off));
23704 break;
23705 }
23706 }
23707 MatchallAttrs::Flags(val) => {
23708 if last_off == offset {
23709 stack.push(("Flags", last_off));
23710 break;
23711 }
23712 }
23713 MatchallAttrs::Pcnt(val) => {
23714 if last_off == offset {
23715 stack.push(("Pcnt", last_off));
23716 break;
23717 }
23718 }
23719 MatchallAttrs::Pad(val) => {
23720 if last_off == offset {
23721 stack.push(("Pad", last_off));
23722 break;
23723 }
23724 }
23725 _ => {}
23726 };
23727 last_off = cur + attrs.pos;
23728 }
23729 if !stack.is_empty() {
23730 stack.push(("MatchallAttrs", cur));
23731 }
23732 (stack, missing)
23733 }
23734}
23735#[derive(Clone)]
23736pub enum EtfAttrs {
23737 Parms(TcEtfQopt),
23738}
23739impl<'a> IterableEtfAttrs<'a> {
23740 pub fn get_parms(&self) -> Result<TcEtfQopt, ErrorContext> {
23741 let mut iter = self.clone();
23742 iter.pos = 0;
23743 for attr in iter {
23744 if let Ok(EtfAttrs::Parms(val)) = attr {
23745 return Ok(val);
23746 }
23747 }
23748 Err(ErrorContext::new_missing(
23749 "EtfAttrs",
23750 "Parms",
23751 self.orig_loc,
23752 self.buf.as_ptr() as usize,
23753 ))
23754 }
23755}
23756impl EtfAttrs {
23757 pub fn new<'a>(buf: &'a [u8]) -> IterableEtfAttrs<'a> {
23758 IterableEtfAttrs::with_loc(buf, buf.as_ptr() as usize)
23759 }
23760 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23761 let res = match r#type {
23762 1u16 => "Parms",
23763 _ => return None,
23764 };
23765 Some(res)
23766 }
23767}
23768#[derive(Clone, Copy, Default)]
23769pub struct IterableEtfAttrs<'a> {
23770 buf: &'a [u8],
23771 pos: usize,
23772 orig_loc: usize,
23773}
23774impl<'a> IterableEtfAttrs<'a> {
23775 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
23776 Self {
23777 buf,
23778 pos: 0,
23779 orig_loc,
23780 }
23781 }
23782 pub fn get_buf(&self) -> &'a [u8] {
23783 self.buf
23784 }
23785}
23786impl<'a> Iterator for IterableEtfAttrs<'a> {
23787 type Item = Result<EtfAttrs, ErrorContext>;
23788 fn next(&mut self) -> Option<Self::Item> {
23789 let mut pos;
23790 let mut r#type;
23791 loop {
23792 pos = self.pos;
23793 r#type = None;
23794 if self.buf.len() == self.pos {
23795 return None;
23796 }
23797 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
23798 self.pos = self.buf.len();
23799 break;
23800 };
23801 r#type = Some(header.r#type);
23802 let res = match header.r#type {
23803 1u16 => EtfAttrs::Parms({
23804 let res = Some(TcEtfQopt::new_from_zeroed(next));
23805 let Some(val) = res else { break };
23806 val
23807 }),
23808 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
23809 n => continue,
23810 };
23811 return Some(Ok(res));
23812 }
23813 Some(Err(ErrorContext::new(
23814 "EtfAttrs",
23815 r#type.and_then(|t| EtfAttrs::attr_from_type(t)),
23816 self.orig_loc,
23817 self.buf.as_ptr().wrapping_add(pos) as usize,
23818 )))
23819 }
23820}
23821impl std::fmt::Debug for IterableEtfAttrs<'_> {
23822 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23823 let mut fmt = f.debug_struct("EtfAttrs");
23824 for attr in self.clone() {
23825 let attr = match attr {
23826 Ok(a) => a,
23827 Err(err) => {
23828 fmt.finish()?;
23829 f.write_str("Err(")?;
23830 err.fmt(f)?;
23831 return f.write_str(")");
23832 }
23833 };
23834 match attr {
23835 EtfAttrs::Parms(val) => fmt.field("Parms", &val),
23836 };
23837 }
23838 fmt.finish()
23839 }
23840}
23841impl IterableEtfAttrs<'_> {
23842 pub fn lookup_attr(
23843 &self,
23844 offset: usize,
23845 missing_type: Option<u16>,
23846 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23847 let mut stack = Vec::new();
23848 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23849 if missing_type.is_some() && cur == offset {
23850 stack.push(("EtfAttrs", offset));
23851 return (
23852 stack,
23853 missing_type.and_then(|t| EtfAttrs::attr_from_type(t)),
23854 );
23855 }
23856 if cur > offset || cur + self.buf.len() < offset {
23857 return (stack, None);
23858 }
23859 let mut attrs = self.clone();
23860 let mut last_off = cur + attrs.pos;
23861 while let Some(attr) = attrs.next() {
23862 let Ok(attr) = attr else { break };
23863 match attr {
23864 EtfAttrs::Parms(val) => {
23865 if last_off == offset {
23866 stack.push(("Parms", last_off));
23867 break;
23868 }
23869 }
23870 _ => {}
23871 };
23872 last_off = cur + attrs.pos;
23873 }
23874 if !stack.is_empty() {
23875 stack.push(("EtfAttrs", cur));
23876 }
23877 (stack, None)
23878 }
23879}
23880#[derive(Clone)]
23881pub enum EtsAttrs<'a> {
23882 Nbands(u8),
23883 Nstrict(u8),
23884 Quanta(IterableEtsAttrs<'a>),
23885 #[doc = "Attribute may repeat multiple times (treat it as array)"]
23886 QuantaBand(u32),
23887 Priomap(IterableEtsAttrs<'a>),
23888 #[doc = "Attribute may repeat multiple times (treat it as array)"]
23889 PriomapBand(u8),
23890}
23891impl<'a> IterableEtsAttrs<'a> {
23892 pub fn get_nbands(&self) -> Result<u8, ErrorContext> {
23893 let mut iter = self.clone();
23894 iter.pos = 0;
23895 for attr in iter {
23896 if let Ok(EtsAttrs::Nbands(val)) = attr {
23897 return Ok(val);
23898 }
23899 }
23900 Err(ErrorContext::new_missing(
23901 "EtsAttrs",
23902 "Nbands",
23903 self.orig_loc,
23904 self.buf.as_ptr() as usize,
23905 ))
23906 }
23907 pub fn get_nstrict(&self) -> Result<u8, ErrorContext> {
23908 let mut iter = self.clone();
23909 iter.pos = 0;
23910 for attr in iter {
23911 if let Ok(EtsAttrs::Nstrict(val)) = attr {
23912 return Ok(val);
23913 }
23914 }
23915 Err(ErrorContext::new_missing(
23916 "EtsAttrs",
23917 "Nstrict",
23918 self.orig_loc,
23919 self.buf.as_ptr() as usize,
23920 ))
23921 }
23922 pub fn get_quanta(&self) -> Result<IterableEtsAttrs<'a>, ErrorContext> {
23923 let mut iter = self.clone();
23924 iter.pos = 0;
23925 for attr in iter {
23926 if let Ok(EtsAttrs::Quanta(val)) = attr {
23927 return Ok(val);
23928 }
23929 }
23930 Err(ErrorContext::new_missing(
23931 "EtsAttrs",
23932 "Quanta",
23933 self.orig_loc,
23934 self.buf.as_ptr() as usize,
23935 ))
23936 }
23937 #[doc = "Attribute may repeat multiple times (treat it as array)"]
23938 pub fn get_quanta_band(&self) -> MultiAttrIterable<Self, EtsAttrs<'a>, u32> {
23939 MultiAttrIterable::new(self.clone(), |variant| {
23940 if let EtsAttrs::QuantaBand(val) = variant {
23941 Some(val)
23942 } else {
23943 None
23944 }
23945 })
23946 }
23947 pub fn get_priomap(&self) -> Result<IterableEtsAttrs<'a>, ErrorContext> {
23948 let mut iter = self.clone();
23949 iter.pos = 0;
23950 for attr in iter {
23951 if let Ok(EtsAttrs::Priomap(val)) = attr {
23952 return Ok(val);
23953 }
23954 }
23955 Err(ErrorContext::new_missing(
23956 "EtsAttrs",
23957 "Priomap",
23958 self.orig_loc,
23959 self.buf.as_ptr() as usize,
23960 ))
23961 }
23962 #[doc = "Attribute may repeat multiple times (treat it as array)"]
23963 pub fn get_priomap_band(&self) -> MultiAttrIterable<Self, EtsAttrs<'a>, u8> {
23964 MultiAttrIterable::new(self.clone(), |variant| {
23965 if let EtsAttrs::PriomapBand(val) = variant {
23966 Some(val)
23967 } else {
23968 None
23969 }
23970 })
23971 }
23972}
23973impl EtsAttrs<'_> {
23974 pub fn new<'a>(buf: &'a [u8]) -> IterableEtsAttrs<'a> {
23975 IterableEtsAttrs::with_loc(buf, buf.as_ptr() as usize)
23976 }
23977 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23978 let res = match r#type {
23979 1u16 => "Nbands",
23980 2u16 => "Nstrict",
23981 3u16 => "Quanta",
23982 4u16 => "QuantaBand",
23983 5u16 => "Priomap",
23984 6u16 => "PriomapBand",
23985 _ => return None,
23986 };
23987 Some(res)
23988 }
23989}
23990#[derive(Clone, Copy, Default)]
23991pub struct IterableEtsAttrs<'a> {
23992 buf: &'a [u8],
23993 pos: usize,
23994 orig_loc: usize,
23995}
23996impl<'a> IterableEtsAttrs<'a> {
23997 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
23998 Self {
23999 buf,
24000 pos: 0,
24001 orig_loc,
24002 }
24003 }
24004 pub fn get_buf(&self) -> &'a [u8] {
24005 self.buf
24006 }
24007}
24008impl<'a> Iterator for IterableEtsAttrs<'a> {
24009 type Item = Result<EtsAttrs<'a>, ErrorContext>;
24010 fn next(&mut self) -> Option<Self::Item> {
24011 let mut pos;
24012 let mut r#type;
24013 loop {
24014 pos = self.pos;
24015 r#type = None;
24016 if self.buf.len() == self.pos {
24017 return None;
24018 }
24019 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
24020 self.pos = self.buf.len();
24021 break;
24022 };
24023 r#type = Some(header.r#type);
24024 let res = match header.r#type {
24025 1u16 => EtsAttrs::Nbands({
24026 let res = parse_u8(next);
24027 let Some(val) = res else { break };
24028 val
24029 }),
24030 2u16 => EtsAttrs::Nstrict({
24031 let res = parse_u8(next);
24032 let Some(val) = res else { break };
24033 val
24034 }),
24035 3u16 => EtsAttrs::Quanta({
24036 let res = Some(IterableEtsAttrs::with_loc(next, self.orig_loc));
24037 let Some(val) = res else { break };
24038 val
24039 }),
24040 4u16 => EtsAttrs::QuantaBand({
24041 let res = parse_u32(next);
24042 let Some(val) = res else { break };
24043 val
24044 }),
24045 5u16 => EtsAttrs::Priomap({
24046 let res = Some(IterableEtsAttrs::with_loc(next, self.orig_loc));
24047 let Some(val) = res else { break };
24048 val
24049 }),
24050 6u16 => EtsAttrs::PriomapBand({
24051 let res = parse_u8(next);
24052 let Some(val) = res else { break };
24053 val
24054 }),
24055 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
24056 n => continue,
24057 };
24058 return Some(Ok(res));
24059 }
24060 Some(Err(ErrorContext::new(
24061 "EtsAttrs",
24062 r#type.and_then(|t| EtsAttrs::attr_from_type(t)),
24063 self.orig_loc,
24064 self.buf.as_ptr().wrapping_add(pos) as usize,
24065 )))
24066 }
24067}
24068impl<'a> std::fmt::Debug for IterableEtsAttrs<'_> {
24069 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24070 let mut fmt = f.debug_struct("EtsAttrs");
24071 for attr in self.clone() {
24072 let attr = match attr {
24073 Ok(a) => a,
24074 Err(err) => {
24075 fmt.finish()?;
24076 f.write_str("Err(")?;
24077 err.fmt(f)?;
24078 return f.write_str(")");
24079 }
24080 };
24081 match attr {
24082 EtsAttrs::Nbands(val) => fmt.field("Nbands", &val),
24083 EtsAttrs::Nstrict(val) => fmt.field("Nstrict", &val),
24084 EtsAttrs::Quanta(val) => fmt.field("Quanta", &val),
24085 EtsAttrs::QuantaBand(val) => fmt.field("QuantaBand", &val),
24086 EtsAttrs::Priomap(val) => fmt.field("Priomap", &val),
24087 EtsAttrs::PriomapBand(val) => fmt.field("PriomapBand", &val),
24088 };
24089 }
24090 fmt.finish()
24091 }
24092}
24093impl IterableEtsAttrs<'_> {
24094 pub fn lookup_attr(
24095 &self,
24096 offset: usize,
24097 missing_type: Option<u16>,
24098 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
24099 let mut stack = Vec::new();
24100 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
24101 if missing_type.is_some() && cur == offset {
24102 stack.push(("EtsAttrs", offset));
24103 return (
24104 stack,
24105 missing_type.and_then(|t| EtsAttrs::attr_from_type(t)),
24106 );
24107 }
24108 if cur > offset || cur + self.buf.len() < offset {
24109 return (stack, None);
24110 }
24111 let mut attrs = self.clone();
24112 let mut last_off = cur + attrs.pos;
24113 let mut missing = None;
24114 while let Some(attr) = attrs.next() {
24115 let Ok(attr) = attr else { break };
24116 match attr {
24117 EtsAttrs::Nbands(val) => {
24118 if last_off == offset {
24119 stack.push(("Nbands", last_off));
24120 break;
24121 }
24122 }
24123 EtsAttrs::Nstrict(val) => {
24124 if last_off == offset {
24125 stack.push(("Nstrict", last_off));
24126 break;
24127 }
24128 }
24129 EtsAttrs::Quanta(val) => {
24130 (stack, missing) = val.lookup_attr(offset, missing_type);
24131 if !stack.is_empty() {
24132 break;
24133 }
24134 }
24135 EtsAttrs::QuantaBand(val) => {
24136 if last_off == offset {
24137 stack.push(("QuantaBand", last_off));
24138 break;
24139 }
24140 }
24141 EtsAttrs::Priomap(val) => {
24142 (stack, missing) = val.lookup_attr(offset, missing_type);
24143 if !stack.is_empty() {
24144 break;
24145 }
24146 }
24147 EtsAttrs::PriomapBand(val) => {
24148 if last_off == offset {
24149 stack.push(("PriomapBand", last_off));
24150 break;
24151 }
24152 }
24153 _ => {}
24154 };
24155 last_off = cur + attrs.pos;
24156 }
24157 if !stack.is_empty() {
24158 stack.push(("EtsAttrs", cur));
24159 }
24160 (stack, missing)
24161 }
24162}
24163#[derive(Clone)]
24164pub enum FqAttrs<'a> {
24165 #[doc = "Limit of total number of packets in queue\n"]
24166 Plimit(u32),
24167 #[doc = "Limit of packets per flow\n"]
24168 FlowPlimit(u32),
24169 #[doc = "RR quantum\n"]
24170 Quantum(u32),
24171 #[doc = "RR quantum for new flow\n"]
24172 InitialQuantum(u32),
24173 #[doc = "Enable / disable rate limiting\n"]
24174 RateEnable(u32),
24175 #[doc = "Obsolete, do not use\n"]
24176 FlowDefaultRate(u32),
24177 #[doc = "Per flow max rate\n"]
24178 FlowMaxRate(u32),
24179 #[doc = "log2(number of buckets)\n"]
24180 BucketsLog(u32),
24181 #[doc = "Flow credit refill delay in usec\n"]
24182 FlowRefillDelay(u32),
24183 #[doc = "Mask applied to orphaned skb hashes\n"]
24184 OrphanMask(u32),
24185 #[doc = "Per packet delay under this rate\n"]
24186 LowRateThreshold(u32),
24187 #[doc = "DCTCP-like CE marking threshold\n"]
24188 CeThreshold(u32),
24189 TimerSlack(u32),
24190 #[doc = "Time horizon in usec\n"]
24191 Horizon(u32),
24192 #[doc = "Drop packets beyond horizon, or cap their EDT\n"]
24193 HorizonDrop(u8),
24194 Priomap(TcPrioQopt),
24195 #[doc = "Weights for each band\n"]
24196 Weights(&'a [u8]),
24197}
24198impl<'a> IterableFqAttrs<'a> {
24199 #[doc = "Limit of total number of packets in queue\n"]
24200 pub fn get_plimit(&self) -> Result<u32, ErrorContext> {
24201 let mut iter = self.clone();
24202 iter.pos = 0;
24203 for attr in iter {
24204 if let Ok(FqAttrs::Plimit(val)) = attr {
24205 return Ok(val);
24206 }
24207 }
24208 Err(ErrorContext::new_missing(
24209 "FqAttrs",
24210 "Plimit",
24211 self.orig_loc,
24212 self.buf.as_ptr() as usize,
24213 ))
24214 }
24215 #[doc = "Limit of packets per flow\n"]
24216 pub fn get_flow_plimit(&self) -> Result<u32, ErrorContext> {
24217 let mut iter = self.clone();
24218 iter.pos = 0;
24219 for attr in iter {
24220 if let Ok(FqAttrs::FlowPlimit(val)) = attr {
24221 return Ok(val);
24222 }
24223 }
24224 Err(ErrorContext::new_missing(
24225 "FqAttrs",
24226 "FlowPlimit",
24227 self.orig_loc,
24228 self.buf.as_ptr() as usize,
24229 ))
24230 }
24231 #[doc = "RR quantum\n"]
24232 pub fn get_quantum(&self) -> Result<u32, ErrorContext> {
24233 let mut iter = self.clone();
24234 iter.pos = 0;
24235 for attr in iter {
24236 if let Ok(FqAttrs::Quantum(val)) = attr {
24237 return Ok(val);
24238 }
24239 }
24240 Err(ErrorContext::new_missing(
24241 "FqAttrs",
24242 "Quantum",
24243 self.orig_loc,
24244 self.buf.as_ptr() as usize,
24245 ))
24246 }
24247 #[doc = "RR quantum for new flow\n"]
24248 pub fn get_initial_quantum(&self) -> Result<u32, ErrorContext> {
24249 let mut iter = self.clone();
24250 iter.pos = 0;
24251 for attr in iter {
24252 if let Ok(FqAttrs::InitialQuantum(val)) = attr {
24253 return Ok(val);
24254 }
24255 }
24256 Err(ErrorContext::new_missing(
24257 "FqAttrs",
24258 "InitialQuantum",
24259 self.orig_loc,
24260 self.buf.as_ptr() as usize,
24261 ))
24262 }
24263 #[doc = "Enable / disable rate limiting\n"]
24264 pub fn get_rate_enable(&self) -> Result<u32, ErrorContext> {
24265 let mut iter = self.clone();
24266 iter.pos = 0;
24267 for attr in iter {
24268 if let Ok(FqAttrs::RateEnable(val)) = attr {
24269 return Ok(val);
24270 }
24271 }
24272 Err(ErrorContext::new_missing(
24273 "FqAttrs",
24274 "RateEnable",
24275 self.orig_loc,
24276 self.buf.as_ptr() as usize,
24277 ))
24278 }
24279 #[doc = "Obsolete, do not use\n"]
24280 pub fn get_flow_default_rate(&self) -> Result<u32, ErrorContext> {
24281 let mut iter = self.clone();
24282 iter.pos = 0;
24283 for attr in iter {
24284 if let Ok(FqAttrs::FlowDefaultRate(val)) = attr {
24285 return Ok(val);
24286 }
24287 }
24288 Err(ErrorContext::new_missing(
24289 "FqAttrs",
24290 "FlowDefaultRate",
24291 self.orig_loc,
24292 self.buf.as_ptr() as usize,
24293 ))
24294 }
24295 #[doc = "Per flow max rate\n"]
24296 pub fn get_flow_max_rate(&self) -> Result<u32, ErrorContext> {
24297 let mut iter = self.clone();
24298 iter.pos = 0;
24299 for attr in iter {
24300 if let Ok(FqAttrs::FlowMaxRate(val)) = attr {
24301 return Ok(val);
24302 }
24303 }
24304 Err(ErrorContext::new_missing(
24305 "FqAttrs",
24306 "FlowMaxRate",
24307 self.orig_loc,
24308 self.buf.as_ptr() as usize,
24309 ))
24310 }
24311 #[doc = "log2(number of buckets)\n"]
24312 pub fn get_buckets_log(&self) -> Result<u32, ErrorContext> {
24313 let mut iter = self.clone();
24314 iter.pos = 0;
24315 for attr in iter {
24316 if let Ok(FqAttrs::BucketsLog(val)) = attr {
24317 return Ok(val);
24318 }
24319 }
24320 Err(ErrorContext::new_missing(
24321 "FqAttrs",
24322 "BucketsLog",
24323 self.orig_loc,
24324 self.buf.as_ptr() as usize,
24325 ))
24326 }
24327 #[doc = "Flow credit refill delay in usec\n"]
24328 pub fn get_flow_refill_delay(&self) -> Result<u32, ErrorContext> {
24329 let mut iter = self.clone();
24330 iter.pos = 0;
24331 for attr in iter {
24332 if let Ok(FqAttrs::FlowRefillDelay(val)) = attr {
24333 return Ok(val);
24334 }
24335 }
24336 Err(ErrorContext::new_missing(
24337 "FqAttrs",
24338 "FlowRefillDelay",
24339 self.orig_loc,
24340 self.buf.as_ptr() as usize,
24341 ))
24342 }
24343 #[doc = "Mask applied to orphaned skb hashes\n"]
24344 pub fn get_orphan_mask(&self) -> Result<u32, ErrorContext> {
24345 let mut iter = self.clone();
24346 iter.pos = 0;
24347 for attr in iter {
24348 if let Ok(FqAttrs::OrphanMask(val)) = attr {
24349 return Ok(val);
24350 }
24351 }
24352 Err(ErrorContext::new_missing(
24353 "FqAttrs",
24354 "OrphanMask",
24355 self.orig_loc,
24356 self.buf.as_ptr() as usize,
24357 ))
24358 }
24359 #[doc = "Per packet delay under this rate\n"]
24360 pub fn get_low_rate_threshold(&self) -> Result<u32, ErrorContext> {
24361 let mut iter = self.clone();
24362 iter.pos = 0;
24363 for attr in iter {
24364 if let Ok(FqAttrs::LowRateThreshold(val)) = attr {
24365 return Ok(val);
24366 }
24367 }
24368 Err(ErrorContext::new_missing(
24369 "FqAttrs",
24370 "LowRateThreshold",
24371 self.orig_loc,
24372 self.buf.as_ptr() as usize,
24373 ))
24374 }
24375 #[doc = "DCTCP-like CE marking threshold\n"]
24376 pub fn get_ce_threshold(&self) -> Result<u32, ErrorContext> {
24377 let mut iter = self.clone();
24378 iter.pos = 0;
24379 for attr in iter {
24380 if let Ok(FqAttrs::CeThreshold(val)) = attr {
24381 return Ok(val);
24382 }
24383 }
24384 Err(ErrorContext::new_missing(
24385 "FqAttrs",
24386 "CeThreshold",
24387 self.orig_loc,
24388 self.buf.as_ptr() as usize,
24389 ))
24390 }
24391 pub fn get_timer_slack(&self) -> Result<u32, ErrorContext> {
24392 let mut iter = self.clone();
24393 iter.pos = 0;
24394 for attr in iter {
24395 if let Ok(FqAttrs::TimerSlack(val)) = attr {
24396 return Ok(val);
24397 }
24398 }
24399 Err(ErrorContext::new_missing(
24400 "FqAttrs",
24401 "TimerSlack",
24402 self.orig_loc,
24403 self.buf.as_ptr() as usize,
24404 ))
24405 }
24406 #[doc = "Time horizon in usec\n"]
24407 pub fn get_horizon(&self) -> Result<u32, ErrorContext> {
24408 let mut iter = self.clone();
24409 iter.pos = 0;
24410 for attr in iter {
24411 if let Ok(FqAttrs::Horizon(val)) = attr {
24412 return Ok(val);
24413 }
24414 }
24415 Err(ErrorContext::new_missing(
24416 "FqAttrs",
24417 "Horizon",
24418 self.orig_loc,
24419 self.buf.as_ptr() as usize,
24420 ))
24421 }
24422 #[doc = "Drop packets beyond horizon, or cap their EDT\n"]
24423 pub fn get_horizon_drop(&self) -> Result<u8, ErrorContext> {
24424 let mut iter = self.clone();
24425 iter.pos = 0;
24426 for attr in iter {
24427 if let Ok(FqAttrs::HorizonDrop(val)) = attr {
24428 return Ok(val);
24429 }
24430 }
24431 Err(ErrorContext::new_missing(
24432 "FqAttrs",
24433 "HorizonDrop",
24434 self.orig_loc,
24435 self.buf.as_ptr() as usize,
24436 ))
24437 }
24438 pub fn get_priomap(&self) -> Result<TcPrioQopt, ErrorContext> {
24439 let mut iter = self.clone();
24440 iter.pos = 0;
24441 for attr in iter {
24442 if let Ok(FqAttrs::Priomap(val)) = attr {
24443 return Ok(val);
24444 }
24445 }
24446 Err(ErrorContext::new_missing(
24447 "FqAttrs",
24448 "Priomap",
24449 self.orig_loc,
24450 self.buf.as_ptr() as usize,
24451 ))
24452 }
24453 #[doc = "Weights for each band\n"]
24454 pub fn get_weights(&self) -> Result<&'a [u8], ErrorContext> {
24455 let mut iter = self.clone();
24456 iter.pos = 0;
24457 for attr in iter {
24458 if let Ok(FqAttrs::Weights(val)) = attr {
24459 return Ok(val);
24460 }
24461 }
24462 Err(ErrorContext::new_missing(
24463 "FqAttrs",
24464 "Weights",
24465 self.orig_loc,
24466 self.buf.as_ptr() as usize,
24467 ))
24468 }
24469}
24470impl FqAttrs<'_> {
24471 pub fn new<'a>(buf: &'a [u8]) -> IterableFqAttrs<'a> {
24472 IterableFqAttrs::with_loc(buf, buf.as_ptr() as usize)
24473 }
24474 fn attr_from_type(r#type: u16) -> Option<&'static str> {
24475 let res = match r#type {
24476 1u16 => "Plimit",
24477 2u16 => "FlowPlimit",
24478 3u16 => "Quantum",
24479 4u16 => "InitialQuantum",
24480 5u16 => "RateEnable",
24481 6u16 => "FlowDefaultRate",
24482 7u16 => "FlowMaxRate",
24483 8u16 => "BucketsLog",
24484 9u16 => "FlowRefillDelay",
24485 10u16 => "OrphanMask",
24486 11u16 => "LowRateThreshold",
24487 12u16 => "CeThreshold",
24488 13u16 => "TimerSlack",
24489 14u16 => "Horizon",
24490 15u16 => "HorizonDrop",
24491 16u16 => "Priomap",
24492 17u16 => "Weights",
24493 _ => return None,
24494 };
24495 Some(res)
24496 }
24497}
24498#[derive(Clone, Copy, Default)]
24499pub struct IterableFqAttrs<'a> {
24500 buf: &'a [u8],
24501 pos: usize,
24502 orig_loc: usize,
24503}
24504impl<'a> IterableFqAttrs<'a> {
24505 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
24506 Self {
24507 buf,
24508 pos: 0,
24509 orig_loc,
24510 }
24511 }
24512 pub fn get_buf(&self) -> &'a [u8] {
24513 self.buf
24514 }
24515}
24516impl<'a> Iterator for IterableFqAttrs<'a> {
24517 type Item = Result<FqAttrs<'a>, ErrorContext>;
24518 fn next(&mut self) -> Option<Self::Item> {
24519 let mut pos;
24520 let mut r#type;
24521 loop {
24522 pos = self.pos;
24523 r#type = None;
24524 if self.buf.len() == self.pos {
24525 return None;
24526 }
24527 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
24528 self.pos = self.buf.len();
24529 break;
24530 };
24531 r#type = Some(header.r#type);
24532 let res = match header.r#type {
24533 1u16 => FqAttrs::Plimit({
24534 let res = parse_u32(next);
24535 let Some(val) = res else { break };
24536 val
24537 }),
24538 2u16 => FqAttrs::FlowPlimit({
24539 let res = parse_u32(next);
24540 let Some(val) = res else { break };
24541 val
24542 }),
24543 3u16 => FqAttrs::Quantum({
24544 let res = parse_u32(next);
24545 let Some(val) = res else { break };
24546 val
24547 }),
24548 4u16 => FqAttrs::InitialQuantum({
24549 let res = parse_u32(next);
24550 let Some(val) = res else { break };
24551 val
24552 }),
24553 5u16 => FqAttrs::RateEnable({
24554 let res = parse_u32(next);
24555 let Some(val) = res else { break };
24556 val
24557 }),
24558 6u16 => FqAttrs::FlowDefaultRate({
24559 let res = parse_u32(next);
24560 let Some(val) = res else { break };
24561 val
24562 }),
24563 7u16 => FqAttrs::FlowMaxRate({
24564 let res = parse_u32(next);
24565 let Some(val) = res else { break };
24566 val
24567 }),
24568 8u16 => FqAttrs::BucketsLog({
24569 let res = parse_u32(next);
24570 let Some(val) = res else { break };
24571 val
24572 }),
24573 9u16 => FqAttrs::FlowRefillDelay({
24574 let res = parse_u32(next);
24575 let Some(val) = res else { break };
24576 val
24577 }),
24578 10u16 => FqAttrs::OrphanMask({
24579 let res = parse_u32(next);
24580 let Some(val) = res else { break };
24581 val
24582 }),
24583 11u16 => FqAttrs::LowRateThreshold({
24584 let res = parse_u32(next);
24585 let Some(val) = res else { break };
24586 val
24587 }),
24588 12u16 => FqAttrs::CeThreshold({
24589 let res = parse_u32(next);
24590 let Some(val) = res else { break };
24591 val
24592 }),
24593 13u16 => FqAttrs::TimerSlack({
24594 let res = parse_u32(next);
24595 let Some(val) = res else { break };
24596 val
24597 }),
24598 14u16 => FqAttrs::Horizon({
24599 let res = parse_u32(next);
24600 let Some(val) = res else { break };
24601 val
24602 }),
24603 15u16 => FqAttrs::HorizonDrop({
24604 let res = parse_u8(next);
24605 let Some(val) = res else { break };
24606 val
24607 }),
24608 16u16 => FqAttrs::Priomap({
24609 let res = Some(TcPrioQopt::new_from_zeroed(next));
24610 let Some(val) = res else { break };
24611 val
24612 }),
24613 17u16 => FqAttrs::Weights({
24614 let res = Some(next);
24615 let Some(val) = res else { break };
24616 val
24617 }),
24618 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
24619 n => continue,
24620 };
24621 return Some(Ok(res));
24622 }
24623 Some(Err(ErrorContext::new(
24624 "FqAttrs",
24625 r#type.and_then(|t| FqAttrs::attr_from_type(t)),
24626 self.orig_loc,
24627 self.buf.as_ptr().wrapping_add(pos) as usize,
24628 )))
24629 }
24630}
24631impl<'a> std::fmt::Debug for IterableFqAttrs<'_> {
24632 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24633 let mut fmt = f.debug_struct("FqAttrs");
24634 for attr in self.clone() {
24635 let attr = match attr {
24636 Ok(a) => a,
24637 Err(err) => {
24638 fmt.finish()?;
24639 f.write_str("Err(")?;
24640 err.fmt(f)?;
24641 return f.write_str(")");
24642 }
24643 };
24644 match attr {
24645 FqAttrs::Plimit(val) => fmt.field("Plimit", &val),
24646 FqAttrs::FlowPlimit(val) => fmt.field("FlowPlimit", &val),
24647 FqAttrs::Quantum(val) => fmt.field("Quantum", &val),
24648 FqAttrs::InitialQuantum(val) => fmt.field("InitialQuantum", &val),
24649 FqAttrs::RateEnable(val) => fmt.field("RateEnable", &val),
24650 FqAttrs::FlowDefaultRate(val) => fmt.field("FlowDefaultRate", &val),
24651 FqAttrs::FlowMaxRate(val) => fmt.field("FlowMaxRate", &val),
24652 FqAttrs::BucketsLog(val) => fmt.field("BucketsLog", &val),
24653 FqAttrs::FlowRefillDelay(val) => fmt.field("FlowRefillDelay", &val),
24654 FqAttrs::OrphanMask(val) => fmt.field("OrphanMask", &val),
24655 FqAttrs::LowRateThreshold(val) => fmt.field("LowRateThreshold", &val),
24656 FqAttrs::CeThreshold(val) => fmt.field("CeThreshold", &val),
24657 FqAttrs::TimerSlack(val) => fmt.field("TimerSlack", &val),
24658 FqAttrs::Horizon(val) => fmt.field("Horizon", &val),
24659 FqAttrs::HorizonDrop(val) => fmt.field("HorizonDrop", &val),
24660 FqAttrs::Priomap(val) => fmt.field("Priomap", &val),
24661 FqAttrs::Weights(val) => fmt.field("Weights", &val),
24662 };
24663 }
24664 fmt.finish()
24665 }
24666}
24667impl IterableFqAttrs<'_> {
24668 pub fn lookup_attr(
24669 &self,
24670 offset: usize,
24671 missing_type: Option<u16>,
24672 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
24673 let mut stack = Vec::new();
24674 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
24675 if missing_type.is_some() && cur == offset {
24676 stack.push(("FqAttrs", offset));
24677 return (stack, missing_type.and_then(|t| FqAttrs::attr_from_type(t)));
24678 }
24679 if cur > offset || cur + self.buf.len() < offset {
24680 return (stack, None);
24681 }
24682 let mut attrs = self.clone();
24683 let mut last_off = cur + attrs.pos;
24684 while let Some(attr) = attrs.next() {
24685 let Ok(attr) = attr else { break };
24686 match attr {
24687 FqAttrs::Plimit(val) => {
24688 if last_off == offset {
24689 stack.push(("Plimit", last_off));
24690 break;
24691 }
24692 }
24693 FqAttrs::FlowPlimit(val) => {
24694 if last_off == offset {
24695 stack.push(("FlowPlimit", last_off));
24696 break;
24697 }
24698 }
24699 FqAttrs::Quantum(val) => {
24700 if last_off == offset {
24701 stack.push(("Quantum", last_off));
24702 break;
24703 }
24704 }
24705 FqAttrs::InitialQuantum(val) => {
24706 if last_off == offset {
24707 stack.push(("InitialQuantum", last_off));
24708 break;
24709 }
24710 }
24711 FqAttrs::RateEnable(val) => {
24712 if last_off == offset {
24713 stack.push(("RateEnable", last_off));
24714 break;
24715 }
24716 }
24717 FqAttrs::FlowDefaultRate(val) => {
24718 if last_off == offset {
24719 stack.push(("FlowDefaultRate", last_off));
24720 break;
24721 }
24722 }
24723 FqAttrs::FlowMaxRate(val) => {
24724 if last_off == offset {
24725 stack.push(("FlowMaxRate", last_off));
24726 break;
24727 }
24728 }
24729 FqAttrs::BucketsLog(val) => {
24730 if last_off == offset {
24731 stack.push(("BucketsLog", last_off));
24732 break;
24733 }
24734 }
24735 FqAttrs::FlowRefillDelay(val) => {
24736 if last_off == offset {
24737 stack.push(("FlowRefillDelay", last_off));
24738 break;
24739 }
24740 }
24741 FqAttrs::OrphanMask(val) => {
24742 if last_off == offset {
24743 stack.push(("OrphanMask", last_off));
24744 break;
24745 }
24746 }
24747 FqAttrs::LowRateThreshold(val) => {
24748 if last_off == offset {
24749 stack.push(("LowRateThreshold", last_off));
24750 break;
24751 }
24752 }
24753 FqAttrs::CeThreshold(val) => {
24754 if last_off == offset {
24755 stack.push(("CeThreshold", last_off));
24756 break;
24757 }
24758 }
24759 FqAttrs::TimerSlack(val) => {
24760 if last_off == offset {
24761 stack.push(("TimerSlack", last_off));
24762 break;
24763 }
24764 }
24765 FqAttrs::Horizon(val) => {
24766 if last_off == offset {
24767 stack.push(("Horizon", last_off));
24768 break;
24769 }
24770 }
24771 FqAttrs::HorizonDrop(val) => {
24772 if last_off == offset {
24773 stack.push(("HorizonDrop", last_off));
24774 break;
24775 }
24776 }
24777 FqAttrs::Priomap(val) => {
24778 if last_off == offset {
24779 stack.push(("Priomap", last_off));
24780 break;
24781 }
24782 }
24783 FqAttrs::Weights(val) => {
24784 if last_off == offset {
24785 stack.push(("Weights", last_off));
24786 break;
24787 }
24788 }
24789 _ => {}
24790 };
24791 last_off = cur + attrs.pos;
24792 }
24793 if !stack.is_empty() {
24794 stack.push(("FqAttrs", cur));
24795 }
24796 (stack, None)
24797 }
24798}
24799#[derive(Clone)]
24800pub enum FqCodelAttrs {
24801 Target(u32),
24802 Limit(u32),
24803 Interval(u32),
24804 Ecn(u32),
24805 Flows(u32),
24806 Quantum(u32),
24807 CeThreshold(u32),
24808 DropBatchSize(u32),
24809 MemoryLimit(u32),
24810 CeThresholdSelector(u8),
24811 CeThresholdMask(u8),
24812}
24813impl<'a> IterableFqCodelAttrs<'a> {
24814 pub fn get_target(&self) -> Result<u32, ErrorContext> {
24815 let mut iter = self.clone();
24816 iter.pos = 0;
24817 for attr in iter {
24818 if let Ok(FqCodelAttrs::Target(val)) = attr {
24819 return Ok(val);
24820 }
24821 }
24822 Err(ErrorContext::new_missing(
24823 "FqCodelAttrs",
24824 "Target",
24825 self.orig_loc,
24826 self.buf.as_ptr() as usize,
24827 ))
24828 }
24829 pub fn get_limit(&self) -> Result<u32, ErrorContext> {
24830 let mut iter = self.clone();
24831 iter.pos = 0;
24832 for attr in iter {
24833 if let Ok(FqCodelAttrs::Limit(val)) = attr {
24834 return Ok(val);
24835 }
24836 }
24837 Err(ErrorContext::new_missing(
24838 "FqCodelAttrs",
24839 "Limit",
24840 self.orig_loc,
24841 self.buf.as_ptr() as usize,
24842 ))
24843 }
24844 pub fn get_interval(&self) -> Result<u32, ErrorContext> {
24845 let mut iter = self.clone();
24846 iter.pos = 0;
24847 for attr in iter {
24848 if let Ok(FqCodelAttrs::Interval(val)) = attr {
24849 return Ok(val);
24850 }
24851 }
24852 Err(ErrorContext::new_missing(
24853 "FqCodelAttrs",
24854 "Interval",
24855 self.orig_loc,
24856 self.buf.as_ptr() as usize,
24857 ))
24858 }
24859 pub fn get_ecn(&self) -> Result<u32, ErrorContext> {
24860 let mut iter = self.clone();
24861 iter.pos = 0;
24862 for attr in iter {
24863 if let Ok(FqCodelAttrs::Ecn(val)) = attr {
24864 return Ok(val);
24865 }
24866 }
24867 Err(ErrorContext::new_missing(
24868 "FqCodelAttrs",
24869 "Ecn",
24870 self.orig_loc,
24871 self.buf.as_ptr() as usize,
24872 ))
24873 }
24874 pub fn get_flows(&self) -> Result<u32, ErrorContext> {
24875 let mut iter = self.clone();
24876 iter.pos = 0;
24877 for attr in iter {
24878 if let Ok(FqCodelAttrs::Flows(val)) = attr {
24879 return Ok(val);
24880 }
24881 }
24882 Err(ErrorContext::new_missing(
24883 "FqCodelAttrs",
24884 "Flows",
24885 self.orig_loc,
24886 self.buf.as_ptr() as usize,
24887 ))
24888 }
24889 pub fn get_quantum(&self) -> Result<u32, ErrorContext> {
24890 let mut iter = self.clone();
24891 iter.pos = 0;
24892 for attr in iter {
24893 if let Ok(FqCodelAttrs::Quantum(val)) = attr {
24894 return Ok(val);
24895 }
24896 }
24897 Err(ErrorContext::new_missing(
24898 "FqCodelAttrs",
24899 "Quantum",
24900 self.orig_loc,
24901 self.buf.as_ptr() as usize,
24902 ))
24903 }
24904 pub fn get_ce_threshold(&self) -> Result<u32, ErrorContext> {
24905 let mut iter = self.clone();
24906 iter.pos = 0;
24907 for attr in iter {
24908 if let Ok(FqCodelAttrs::CeThreshold(val)) = attr {
24909 return Ok(val);
24910 }
24911 }
24912 Err(ErrorContext::new_missing(
24913 "FqCodelAttrs",
24914 "CeThreshold",
24915 self.orig_loc,
24916 self.buf.as_ptr() as usize,
24917 ))
24918 }
24919 pub fn get_drop_batch_size(&self) -> Result<u32, ErrorContext> {
24920 let mut iter = self.clone();
24921 iter.pos = 0;
24922 for attr in iter {
24923 if let Ok(FqCodelAttrs::DropBatchSize(val)) = attr {
24924 return Ok(val);
24925 }
24926 }
24927 Err(ErrorContext::new_missing(
24928 "FqCodelAttrs",
24929 "DropBatchSize",
24930 self.orig_loc,
24931 self.buf.as_ptr() as usize,
24932 ))
24933 }
24934 pub fn get_memory_limit(&self) -> Result<u32, ErrorContext> {
24935 let mut iter = self.clone();
24936 iter.pos = 0;
24937 for attr in iter {
24938 if let Ok(FqCodelAttrs::MemoryLimit(val)) = attr {
24939 return Ok(val);
24940 }
24941 }
24942 Err(ErrorContext::new_missing(
24943 "FqCodelAttrs",
24944 "MemoryLimit",
24945 self.orig_loc,
24946 self.buf.as_ptr() as usize,
24947 ))
24948 }
24949 pub fn get_ce_threshold_selector(&self) -> Result<u8, ErrorContext> {
24950 let mut iter = self.clone();
24951 iter.pos = 0;
24952 for attr in iter {
24953 if let Ok(FqCodelAttrs::CeThresholdSelector(val)) = attr {
24954 return Ok(val);
24955 }
24956 }
24957 Err(ErrorContext::new_missing(
24958 "FqCodelAttrs",
24959 "CeThresholdSelector",
24960 self.orig_loc,
24961 self.buf.as_ptr() as usize,
24962 ))
24963 }
24964 pub fn get_ce_threshold_mask(&self) -> Result<u8, ErrorContext> {
24965 let mut iter = self.clone();
24966 iter.pos = 0;
24967 for attr in iter {
24968 if let Ok(FqCodelAttrs::CeThresholdMask(val)) = attr {
24969 return Ok(val);
24970 }
24971 }
24972 Err(ErrorContext::new_missing(
24973 "FqCodelAttrs",
24974 "CeThresholdMask",
24975 self.orig_loc,
24976 self.buf.as_ptr() as usize,
24977 ))
24978 }
24979}
24980impl FqCodelAttrs {
24981 pub fn new<'a>(buf: &'a [u8]) -> IterableFqCodelAttrs<'a> {
24982 IterableFqCodelAttrs::with_loc(buf, buf.as_ptr() as usize)
24983 }
24984 fn attr_from_type(r#type: u16) -> Option<&'static str> {
24985 let res = match r#type {
24986 1u16 => "Target",
24987 2u16 => "Limit",
24988 3u16 => "Interval",
24989 4u16 => "Ecn",
24990 5u16 => "Flows",
24991 6u16 => "Quantum",
24992 7u16 => "CeThreshold",
24993 8u16 => "DropBatchSize",
24994 9u16 => "MemoryLimit",
24995 10u16 => "CeThresholdSelector",
24996 11u16 => "CeThresholdMask",
24997 _ => return None,
24998 };
24999 Some(res)
25000 }
25001}
25002#[derive(Clone, Copy, Default)]
25003pub struct IterableFqCodelAttrs<'a> {
25004 buf: &'a [u8],
25005 pos: usize,
25006 orig_loc: usize,
25007}
25008impl<'a> IterableFqCodelAttrs<'a> {
25009 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
25010 Self {
25011 buf,
25012 pos: 0,
25013 orig_loc,
25014 }
25015 }
25016 pub fn get_buf(&self) -> &'a [u8] {
25017 self.buf
25018 }
25019}
25020impl<'a> Iterator for IterableFqCodelAttrs<'a> {
25021 type Item = Result<FqCodelAttrs, ErrorContext>;
25022 fn next(&mut self) -> Option<Self::Item> {
25023 let mut pos;
25024 let mut r#type;
25025 loop {
25026 pos = self.pos;
25027 r#type = None;
25028 if self.buf.len() == self.pos {
25029 return None;
25030 }
25031 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
25032 self.pos = self.buf.len();
25033 break;
25034 };
25035 r#type = Some(header.r#type);
25036 let res = match header.r#type {
25037 1u16 => FqCodelAttrs::Target({
25038 let res = parse_u32(next);
25039 let Some(val) = res else { break };
25040 val
25041 }),
25042 2u16 => FqCodelAttrs::Limit({
25043 let res = parse_u32(next);
25044 let Some(val) = res else { break };
25045 val
25046 }),
25047 3u16 => FqCodelAttrs::Interval({
25048 let res = parse_u32(next);
25049 let Some(val) = res else { break };
25050 val
25051 }),
25052 4u16 => FqCodelAttrs::Ecn({
25053 let res = parse_u32(next);
25054 let Some(val) = res else { break };
25055 val
25056 }),
25057 5u16 => FqCodelAttrs::Flows({
25058 let res = parse_u32(next);
25059 let Some(val) = res else { break };
25060 val
25061 }),
25062 6u16 => FqCodelAttrs::Quantum({
25063 let res = parse_u32(next);
25064 let Some(val) = res else { break };
25065 val
25066 }),
25067 7u16 => FqCodelAttrs::CeThreshold({
25068 let res = parse_u32(next);
25069 let Some(val) = res else { break };
25070 val
25071 }),
25072 8u16 => FqCodelAttrs::DropBatchSize({
25073 let res = parse_u32(next);
25074 let Some(val) = res else { break };
25075 val
25076 }),
25077 9u16 => FqCodelAttrs::MemoryLimit({
25078 let res = parse_u32(next);
25079 let Some(val) = res else { break };
25080 val
25081 }),
25082 10u16 => FqCodelAttrs::CeThresholdSelector({
25083 let res = parse_u8(next);
25084 let Some(val) = res else { break };
25085 val
25086 }),
25087 11u16 => FqCodelAttrs::CeThresholdMask({
25088 let res = parse_u8(next);
25089 let Some(val) = res else { break };
25090 val
25091 }),
25092 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
25093 n => continue,
25094 };
25095 return Some(Ok(res));
25096 }
25097 Some(Err(ErrorContext::new(
25098 "FqCodelAttrs",
25099 r#type.and_then(|t| FqCodelAttrs::attr_from_type(t)),
25100 self.orig_loc,
25101 self.buf.as_ptr().wrapping_add(pos) as usize,
25102 )))
25103 }
25104}
25105impl std::fmt::Debug for IterableFqCodelAttrs<'_> {
25106 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25107 let mut fmt = f.debug_struct("FqCodelAttrs");
25108 for attr in self.clone() {
25109 let attr = match attr {
25110 Ok(a) => a,
25111 Err(err) => {
25112 fmt.finish()?;
25113 f.write_str("Err(")?;
25114 err.fmt(f)?;
25115 return f.write_str(")");
25116 }
25117 };
25118 match attr {
25119 FqCodelAttrs::Target(val) => fmt.field("Target", &val),
25120 FqCodelAttrs::Limit(val) => fmt.field("Limit", &val),
25121 FqCodelAttrs::Interval(val) => fmt.field("Interval", &val),
25122 FqCodelAttrs::Ecn(val) => fmt.field("Ecn", &val),
25123 FqCodelAttrs::Flows(val) => fmt.field("Flows", &val),
25124 FqCodelAttrs::Quantum(val) => fmt.field("Quantum", &val),
25125 FqCodelAttrs::CeThreshold(val) => fmt.field("CeThreshold", &val),
25126 FqCodelAttrs::DropBatchSize(val) => fmt.field("DropBatchSize", &val),
25127 FqCodelAttrs::MemoryLimit(val) => fmt.field("MemoryLimit", &val),
25128 FqCodelAttrs::CeThresholdSelector(val) => fmt.field("CeThresholdSelector", &val),
25129 FqCodelAttrs::CeThresholdMask(val) => fmt.field("CeThresholdMask", &val),
25130 };
25131 }
25132 fmt.finish()
25133 }
25134}
25135impl IterableFqCodelAttrs<'_> {
25136 pub fn lookup_attr(
25137 &self,
25138 offset: usize,
25139 missing_type: Option<u16>,
25140 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
25141 let mut stack = Vec::new();
25142 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
25143 if missing_type.is_some() && cur == offset {
25144 stack.push(("FqCodelAttrs", offset));
25145 return (
25146 stack,
25147 missing_type.and_then(|t| FqCodelAttrs::attr_from_type(t)),
25148 );
25149 }
25150 if cur > offset || cur + self.buf.len() < offset {
25151 return (stack, None);
25152 }
25153 let mut attrs = self.clone();
25154 let mut last_off = cur + attrs.pos;
25155 while let Some(attr) = attrs.next() {
25156 let Ok(attr) = attr else { break };
25157 match attr {
25158 FqCodelAttrs::Target(val) => {
25159 if last_off == offset {
25160 stack.push(("Target", last_off));
25161 break;
25162 }
25163 }
25164 FqCodelAttrs::Limit(val) => {
25165 if last_off == offset {
25166 stack.push(("Limit", last_off));
25167 break;
25168 }
25169 }
25170 FqCodelAttrs::Interval(val) => {
25171 if last_off == offset {
25172 stack.push(("Interval", last_off));
25173 break;
25174 }
25175 }
25176 FqCodelAttrs::Ecn(val) => {
25177 if last_off == offset {
25178 stack.push(("Ecn", last_off));
25179 break;
25180 }
25181 }
25182 FqCodelAttrs::Flows(val) => {
25183 if last_off == offset {
25184 stack.push(("Flows", last_off));
25185 break;
25186 }
25187 }
25188 FqCodelAttrs::Quantum(val) => {
25189 if last_off == offset {
25190 stack.push(("Quantum", last_off));
25191 break;
25192 }
25193 }
25194 FqCodelAttrs::CeThreshold(val) => {
25195 if last_off == offset {
25196 stack.push(("CeThreshold", last_off));
25197 break;
25198 }
25199 }
25200 FqCodelAttrs::DropBatchSize(val) => {
25201 if last_off == offset {
25202 stack.push(("DropBatchSize", last_off));
25203 break;
25204 }
25205 }
25206 FqCodelAttrs::MemoryLimit(val) => {
25207 if last_off == offset {
25208 stack.push(("MemoryLimit", last_off));
25209 break;
25210 }
25211 }
25212 FqCodelAttrs::CeThresholdSelector(val) => {
25213 if last_off == offset {
25214 stack.push(("CeThresholdSelector", last_off));
25215 break;
25216 }
25217 }
25218 FqCodelAttrs::CeThresholdMask(val) => {
25219 if last_off == offset {
25220 stack.push(("CeThresholdMask", last_off));
25221 break;
25222 }
25223 }
25224 _ => {}
25225 };
25226 last_off = cur + attrs.pos;
25227 }
25228 if !stack.is_empty() {
25229 stack.push(("FqCodelAttrs", cur));
25230 }
25231 (stack, None)
25232 }
25233}
25234#[derive(Clone)]
25235pub enum FqPieAttrs {
25236 Limit(u32),
25237 Flows(u32),
25238 Target(u32),
25239 Tupdate(u32),
25240 Alpha(u32),
25241 Beta(u32),
25242 Quantum(u32),
25243 MemoryLimit(u32),
25244 EcnProb(u32),
25245 Ecn(u32),
25246 Bytemode(u32),
25247 DqRateEstimator(u32),
25248}
25249impl<'a> IterableFqPieAttrs<'a> {
25250 pub fn get_limit(&self) -> Result<u32, ErrorContext> {
25251 let mut iter = self.clone();
25252 iter.pos = 0;
25253 for attr in iter {
25254 if let Ok(FqPieAttrs::Limit(val)) = attr {
25255 return Ok(val);
25256 }
25257 }
25258 Err(ErrorContext::new_missing(
25259 "FqPieAttrs",
25260 "Limit",
25261 self.orig_loc,
25262 self.buf.as_ptr() as usize,
25263 ))
25264 }
25265 pub fn get_flows(&self) -> Result<u32, ErrorContext> {
25266 let mut iter = self.clone();
25267 iter.pos = 0;
25268 for attr in iter {
25269 if let Ok(FqPieAttrs::Flows(val)) = attr {
25270 return Ok(val);
25271 }
25272 }
25273 Err(ErrorContext::new_missing(
25274 "FqPieAttrs",
25275 "Flows",
25276 self.orig_loc,
25277 self.buf.as_ptr() as usize,
25278 ))
25279 }
25280 pub fn get_target(&self) -> Result<u32, ErrorContext> {
25281 let mut iter = self.clone();
25282 iter.pos = 0;
25283 for attr in iter {
25284 if let Ok(FqPieAttrs::Target(val)) = attr {
25285 return Ok(val);
25286 }
25287 }
25288 Err(ErrorContext::new_missing(
25289 "FqPieAttrs",
25290 "Target",
25291 self.orig_loc,
25292 self.buf.as_ptr() as usize,
25293 ))
25294 }
25295 pub fn get_tupdate(&self) -> Result<u32, ErrorContext> {
25296 let mut iter = self.clone();
25297 iter.pos = 0;
25298 for attr in iter {
25299 if let Ok(FqPieAttrs::Tupdate(val)) = attr {
25300 return Ok(val);
25301 }
25302 }
25303 Err(ErrorContext::new_missing(
25304 "FqPieAttrs",
25305 "Tupdate",
25306 self.orig_loc,
25307 self.buf.as_ptr() as usize,
25308 ))
25309 }
25310 pub fn get_alpha(&self) -> Result<u32, ErrorContext> {
25311 let mut iter = self.clone();
25312 iter.pos = 0;
25313 for attr in iter {
25314 if let Ok(FqPieAttrs::Alpha(val)) = attr {
25315 return Ok(val);
25316 }
25317 }
25318 Err(ErrorContext::new_missing(
25319 "FqPieAttrs",
25320 "Alpha",
25321 self.orig_loc,
25322 self.buf.as_ptr() as usize,
25323 ))
25324 }
25325 pub fn get_beta(&self) -> Result<u32, ErrorContext> {
25326 let mut iter = self.clone();
25327 iter.pos = 0;
25328 for attr in iter {
25329 if let Ok(FqPieAttrs::Beta(val)) = attr {
25330 return Ok(val);
25331 }
25332 }
25333 Err(ErrorContext::new_missing(
25334 "FqPieAttrs",
25335 "Beta",
25336 self.orig_loc,
25337 self.buf.as_ptr() as usize,
25338 ))
25339 }
25340 pub fn get_quantum(&self) -> Result<u32, ErrorContext> {
25341 let mut iter = self.clone();
25342 iter.pos = 0;
25343 for attr in iter {
25344 if let Ok(FqPieAttrs::Quantum(val)) = attr {
25345 return Ok(val);
25346 }
25347 }
25348 Err(ErrorContext::new_missing(
25349 "FqPieAttrs",
25350 "Quantum",
25351 self.orig_loc,
25352 self.buf.as_ptr() as usize,
25353 ))
25354 }
25355 pub fn get_memory_limit(&self) -> Result<u32, ErrorContext> {
25356 let mut iter = self.clone();
25357 iter.pos = 0;
25358 for attr in iter {
25359 if let Ok(FqPieAttrs::MemoryLimit(val)) = attr {
25360 return Ok(val);
25361 }
25362 }
25363 Err(ErrorContext::new_missing(
25364 "FqPieAttrs",
25365 "MemoryLimit",
25366 self.orig_loc,
25367 self.buf.as_ptr() as usize,
25368 ))
25369 }
25370 pub fn get_ecn_prob(&self) -> Result<u32, ErrorContext> {
25371 let mut iter = self.clone();
25372 iter.pos = 0;
25373 for attr in iter {
25374 if let Ok(FqPieAttrs::EcnProb(val)) = attr {
25375 return Ok(val);
25376 }
25377 }
25378 Err(ErrorContext::new_missing(
25379 "FqPieAttrs",
25380 "EcnProb",
25381 self.orig_loc,
25382 self.buf.as_ptr() as usize,
25383 ))
25384 }
25385 pub fn get_ecn(&self) -> Result<u32, ErrorContext> {
25386 let mut iter = self.clone();
25387 iter.pos = 0;
25388 for attr in iter {
25389 if let Ok(FqPieAttrs::Ecn(val)) = attr {
25390 return Ok(val);
25391 }
25392 }
25393 Err(ErrorContext::new_missing(
25394 "FqPieAttrs",
25395 "Ecn",
25396 self.orig_loc,
25397 self.buf.as_ptr() as usize,
25398 ))
25399 }
25400 pub fn get_bytemode(&self) -> Result<u32, ErrorContext> {
25401 let mut iter = self.clone();
25402 iter.pos = 0;
25403 for attr in iter {
25404 if let Ok(FqPieAttrs::Bytemode(val)) = attr {
25405 return Ok(val);
25406 }
25407 }
25408 Err(ErrorContext::new_missing(
25409 "FqPieAttrs",
25410 "Bytemode",
25411 self.orig_loc,
25412 self.buf.as_ptr() as usize,
25413 ))
25414 }
25415 pub fn get_dq_rate_estimator(&self) -> Result<u32, ErrorContext> {
25416 let mut iter = self.clone();
25417 iter.pos = 0;
25418 for attr in iter {
25419 if let Ok(FqPieAttrs::DqRateEstimator(val)) = attr {
25420 return Ok(val);
25421 }
25422 }
25423 Err(ErrorContext::new_missing(
25424 "FqPieAttrs",
25425 "DqRateEstimator",
25426 self.orig_loc,
25427 self.buf.as_ptr() as usize,
25428 ))
25429 }
25430}
25431impl FqPieAttrs {
25432 pub fn new<'a>(buf: &'a [u8]) -> IterableFqPieAttrs<'a> {
25433 IterableFqPieAttrs::with_loc(buf, buf.as_ptr() as usize)
25434 }
25435 fn attr_from_type(r#type: u16) -> Option<&'static str> {
25436 let res = match r#type {
25437 1u16 => "Limit",
25438 2u16 => "Flows",
25439 3u16 => "Target",
25440 4u16 => "Tupdate",
25441 5u16 => "Alpha",
25442 6u16 => "Beta",
25443 7u16 => "Quantum",
25444 8u16 => "MemoryLimit",
25445 9u16 => "EcnProb",
25446 10u16 => "Ecn",
25447 11u16 => "Bytemode",
25448 12u16 => "DqRateEstimator",
25449 _ => return None,
25450 };
25451 Some(res)
25452 }
25453}
25454#[derive(Clone, Copy, Default)]
25455pub struct IterableFqPieAttrs<'a> {
25456 buf: &'a [u8],
25457 pos: usize,
25458 orig_loc: usize,
25459}
25460impl<'a> IterableFqPieAttrs<'a> {
25461 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
25462 Self {
25463 buf,
25464 pos: 0,
25465 orig_loc,
25466 }
25467 }
25468 pub fn get_buf(&self) -> &'a [u8] {
25469 self.buf
25470 }
25471}
25472impl<'a> Iterator for IterableFqPieAttrs<'a> {
25473 type Item = Result<FqPieAttrs, ErrorContext>;
25474 fn next(&mut self) -> Option<Self::Item> {
25475 let mut pos;
25476 let mut r#type;
25477 loop {
25478 pos = self.pos;
25479 r#type = None;
25480 if self.buf.len() == self.pos {
25481 return None;
25482 }
25483 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
25484 self.pos = self.buf.len();
25485 break;
25486 };
25487 r#type = Some(header.r#type);
25488 let res = match header.r#type {
25489 1u16 => FqPieAttrs::Limit({
25490 let res = parse_u32(next);
25491 let Some(val) = res else { break };
25492 val
25493 }),
25494 2u16 => FqPieAttrs::Flows({
25495 let res = parse_u32(next);
25496 let Some(val) = res else { break };
25497 val
25498 }),
25499 3u16 => FqPieAttrs::Target({
25500 let res = parse_u32(next);
25501 let Some(val) = res else { break };
25502 val
25503 }),
25504 4u16 => FqPieAttrs::Tupdate({
25505 let res = parse_u32(next);
25506 let Some(val) = res else { break };
25507 val
25508 }),
25509 5u16 => FqPieAttrs::Alpha({
25510 let res = parse_u32(next);
25511 let Some(val) = res else { break };
25512 val
25513 }),
25514 6u16 => FqPieAttrs::Beta({
25515 let res = parse_u32(next);
25516 let Some(val) = res else { break };
25517 val
25518 }),
25519 7u16 => FqPieAttrs::Quantum({
25520 let res = parse_u32(next);
25521 let Some(val) = res else { break };
25522 val
25523 }),
25524 8u16 => FqPieAttrs::MemoryLimit({
25525 let res = parse_u32(next);
25526 let Some(val) = res else { break };
25527 val
25528 }),
25529 9u16 => FqPieAttrs::EcnProb({
25530 let res = parse_u32(next);
25531 let Some(val) = res else { break };
25532 val
25533 }),
25534 10u16 => FqPieAttrs::Ecn({
25535 let res = parse_u32(next);
25536 let Some(val) = res else { break };
25537 val
25538 }),
25539 11u16 => FqPieAttrs::Bytemode({
25540 let res = parse_u32(next);
25541 let Some(val) = res else { break };
25542 val
25543 }),
25544 12u16 => FqPieAttrs::DqRateEstimator({
25545 let res = parse_u32(next);
25546 let Some(val) = res else { break };
25547 val
25548 }),
25549 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
25550 n => continue,
25551 };
25552 return Some(Ok(res));
25553 }
25554 Some(Err(ErrorContext::new(
25555 "FqPieAttrs",
25556 r#type.and_then(|t| FqPieAttrs::attr_from_type(t)),
25557 self.orig_loc,
25558 self.buf.as_ptr().wrapping_add(pos) as usize,
25559 )))
25560 }
25561}
25562impl std::fmt::Debug for IterableFqPieAttrs<'_> {
25563 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25564 let mut fmt = f.debug_struct("FqPieAttrs");
25565 for attr in self.clone() {
25566 let attr = match attr {
25567 Ok(a) => a,
25568 Err(err) => {
25569 fmt.finish()?;
25570 f.write_str("Err(")?;
25571 err.fmt(f)?;
25572 return f.write_str(")");
25573 }
25574 };
25575 match attr {
25576 FqPieAttrs::Limit(val) => fmt.field("Limit", &val),
25577 FqPieAttrs::Flows(val) => fmt.field("Flows", &val),
25578 FqPieAttrs::Target(val) => fmt.field("Target", &val),
25579 FqPieAttrs::Tupdate(val) => fmt.field("Tupdate", &val),
25580 FqPieAttrs::Alpha(val) => fmt.field("Alpha", &val),
25581 FqPieAttrs::Beta(val) => fmt.field("Beta", &val),
25582 FqPieAttrs::Quantum(val) => fmt.field("Quantum", &val),
25583 FqPieAttrs::MemoryLimit(val) => fmt.field("MemoryLimit", &val),
25584 FqPieAttrs::EcnProb(val) => fmt.field("EcnProb", &val),
25585 FqPieAttrs::Ecn(val) => fmt.field("Ecn", &val),
25586 FqPieAttrs::Bytemode(val) => fmt.field("Bytemode", &val),
25587 FqPieAttrs::DqRateEstimator(val) => fmt.field("DqRateEstimator", &val),
25588 };
25589 }
25590 fmt.finish()
25591 }
25592}
25593impl IterableFqPieAttrs<'_> {
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 missing_type.is_some() && cur == offset {
25602 stack.push(("FqPieAttrs", offset));
25603 return (
25604 stack,
25605 missing_type.and_then(|t| FqPieAttrs::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 while let Some(attr) = attrs.next() {
25614 let Ok(attr) = attr else { break };
25615 match attr {
25616 FqPieAttrs::Limit(val) => {
25617 if last_off == offset {
25618 stack.push(("Limit", last_off));
25619 break;
25620 }
25621 }
25622 FqPieAttrs::Flows(val) => {
25623 if last_off == offset {
25624 stack.push(("Flows", last_off));
25625 break;
25626 }
25627 }
25628 FqPieAttrs::Target(val) => {
25629 if last_off == offset {
25630 stack.push(("Target", last_off));
25631 break;
25632 }
25633 }
25634 FqPieAttrs::Tupdate(val) => {
25635 if last_off == offset {
25636 stack.push(("Tupdate", last_off));
25637 break;
25638 }
25639 }
25640 FqPieAttrs::Alpha(val) => {
25641 if last_off == offset {
25642 stack.push(("Alpha", last_off));
25643 break;
25644 }
25645 }
25646 FqPieAttrs::Beta(val) => {
25647 if last_off == offset {
25648 stack.push(("Beta", last_off));
25649 break;
25650 }
25651 }
25652 FqPieAttrs::Quantum(val) => {
25653 if last_off == offset {
25654 stack.push(("Quantum", last_off));
25655 break;
25656 }
25657 }
25658 FqPieAttrs::MemoryLimit(val) => {
25659 if last_off == offset {
25660 stack.push(("MemoryLimit", last_off));
25661 break;
25662 }
25663 }
25664 FqPieAttrs::EcnProb(val) => {
25665 if last_off == offset {
25666 stack.push(("EcnProb", last_off));
25667 break;
25668 }
25669 }
25670 FqPieAttrs::Ecn(val) => {
25671 if last_off == offset {
25672 stack.push(("Ecn", last_off));
25673 break;
25674 }
25675 }
25676 FqPieAttrs::Bytemode(val) => {
25677 if last_off == offset {
25678 stack.push(("Bytemode", last_off));
25679 break;
25680 }
25681 }
25682 FqPieAttrs::DqRateEstimator(val) => {
25683 if last_off == offset {
25684 stack.push(("DqRateEstimator", last_off));
25685 break;
25686 }
25687 }
25688 _ => {}
25689 };
25690 last_off = cur + attrs.pos;
25691 }
25692 if !stack.is_empty() {
25693 stack.push(("FqPieAttrs", cur));
25694 }
25695 (stack, None)
25696 }
25697}
25698#[derive(Clone)]
25699pub enum NetemAttrs<'a> {
25700 Corr(TcNetemCorr),
25701 DelayDist(&'a [u8]),
25702 Reorder(TcNetemReorder),
25703 Corrupt(TcNetemCorrupt),
25704 Loss(IterableNetemLossAttrs<'a>),
25705 Rate(TcNetemRate),
25706 Ecn(u32),
25707 Rate64(u64),
25708 Pad(u32),
25709 Latency64(i64),
25710 Jitter64(i64),
25711 Slot(TcNetemSlot),
25712 SlotDist(&'a [u8]),
25713 PrngSeed(u64),
25714}
25715impl<'a> IterableNetemAttrs<'a> {
25716 pub fn get_corr(&self) -> Result<TcNetemCorr, ErrorContext> {
25717 let mut iter = self.clone();
25718 iter.pos = 0;
25719 for attr in iter {
25720 if let Ok(NetemAttrs::Corr(val)) = attr {
25721 return Ok(val);
25722 }
25723 }
25724 Err(ErrorContext::new_missing(
25725 "NetemAttrs",
25726 "Corr",
25727 self.orig_loc,
25728 self.buf.as_ptr() as usize,
25729 ))
25730 }
25731 pub fn get_delay_dist(&self) -> Result<&'a [u8], ErrorContext> {
25732 let mut iter = self.clone();
25733 iter.pos = 0;
25734 for attr in iter {
25735 if let Ok(NetemAttrs::DelayDist(val)) = attr {
25736 return Ok(val);
25737 }
25738 }
25739 Err(ErrorContext::new_missing(
25740 "NetemAttrs",
25741 "DelayDist",
25742 self.orig_loc,
25743 self.buf.as_ptr() as usize,
25744 ))
25745 }
25746 pub fn get_reorder(&self) -> Result<TcNetemReorder, ErrorContext> {
25747 let mut iter = self.clone();
25748 iter.pos = 0;
25749 for attr in iter {
25750 if let Ok(NetemAttrs::Reorder(val)) = attr {
25751 return Ok(val);
25752 }
25753 }
25754 Err(ErrorContext::new_missing(
25755 "NetemAttrs",
25756 "Reorder",
25757 self.orig_loc,
25758 self.buf.as_ptr() as usize,
25759 ))
25760 }
25761 pub fn get_corrupt(&self) -> Result<TcNetemCorrupt, ErrorContext> {
25762 let mut iter = self.clone();
25763 iter.pos = 0;
25764 for attr in iter {
25765 if let Ok(NetemAttrs::Corrupt(val)) = attr {
25766 return Ok(val);
25767 }
25768 }
25769 Err(ErrorContext::new_missing(
25770 "NetemAttrs",
25771 "Corrupt",
25772 self.orig_loc,
25773 self.buf.as_ptr() as usize,
25774 ))
25775 }
25776 pub fn get_loss(&self) -> Result<IterableNetemLossAttrs<'a>, ErrorContext> {
25777 let mut iter = self.clone();
25778 iter.pos = 0;
25779 for attr in iter {
25780 if let Ok(NetemAttrs::Loss(val)) = attr {
25781 return Ok(val);
25782 }
25783 }
25784 Err(ErrorContext::new_missing(
25785 "NetemAttrs",
25786 "Loss",
25787 self.orig_loc,
25788 self.buf.as_ptr() as usize,
25789 ))
25790 }
25791 pub fn get_rate(&self) -> Result<TcNetemRate, ErrorContext> {
25792 let mut iter = self.clone();
25793 iter.pos = 0;
25794 for attr in iter {
25795 if let Ok(NetemAttrs::Rate(val)) = attr {
25796 return Ok(val);
25797 }
25798 }
25799 Err(ErrorContext::new_missing(
25800 "NetemAttrs",
25801 "Rate",
25802 self.orig_loc,
25803 self.buf.as_ptr() as usize,
25804 ))
25805 }
25806 pub fn get_ecn(&self) -> Result<u32, ErrorContext> {
25807 let mut iter = self.clone();
25808 iter.pos = 0;
25809 for attr in iter {
25810 if let Ok(NetemAttrs::Ecn(val)) = attr {
25811 return Ok(val);
25812 }
25813 }
25814 Err(ErrorContext::new_missing(
25815 "NetemAttrs",
25816 "Ecn",
25817 self.orig_loc,
25818 self.buf.as_ptr() as usize,
25819 ))
25820 }
25821 pub fn get_rate64(&self) -> Result<u64, ErrorContext> {
25822 let mut iter = self.clone();
25823 iter.pos = 0;
25824 for attr in iter {
25825 if let Ok(NetemAttrs::Rate64(val)) = attr {
25826 return Ok(val);
25827 }
25828 }
25829 Err(ErrorContext::new_missing(
25830 "NetemAttrs",
25831 "Rate64",
25832 self.orig_loc,
25833 self.buf.as_ptr() as usize,
25834 ))
25835 }
25836 pub fn get_pad(&self) -> Result<u32, ErrorContext> {
25837 let mut iter = self.clone();
25838 iter.pos = 0;
25839 for attr in iter {
25840 if let Ok(NetemAttrs::Pad(val)) = attr {
25841 return Ok(val);
25842 }
25843 }
25844 Err(ErrorContext::new_missing(
25845 "NetemAttrs",
25846 "Pad",
25847 self.orig_loc,
25848 self.buf.as_ptr() as usize,
25849 ))
25850 }
25851 pub fn get_latency64(&self) -> Result<i64, ErrorContext> {
25852 let mut iter = self.clone();
25853 iter.pos = 0;
25854 for attr in iter {
25855 if let Ok(NetemAttrs::Latency64(val)) = attr {
25856 return Ok(val);
25857 }
25858 }
25859 Err(ErrorContext::new_missing(
25860 "NetemAttrs",
25861 "Latency64",
25862 self.orig_loc,
25863 self.buf.as_ptr() as usize,
25864 ))
25865 }
25866 pub fn get_jitter64(&self) -> Result<i64, ErrorContext> {
25867 let mut iter = self.clone();
25868 iter.pos = 0;
25869 for attr in iter {
25870 if let Ok(NetemAttrs::Jitter64(val)) = attr {
25871 return Ok(val);
25872 }
25873 }
25874 Err(ErrorContext::new_missing(
25875 "NetemAttrs",
25876 "Jitter64",
25877 self.orig_loc,
25878 self.buf.as_ptr() as usize,
25879 ))
25880 }
25881 pub fn get_slot(&self) -> Result<TcNetemSlot, ErrorContext> {
25882 let mut iter = self.clone();
25883 iter.pos = 0;
25884 for attr in iter {
25885 if let Ok(NetemAttrs::Slot(val)) = attr {
25886 return Ok(val);
25887 }
25888 }
25889 Err(ErrorContext::new_missing(
25890 "NetemAttrs",
25891 "Slot",
25892 self.orig_loc,
25893 self.buf.as_ptr() as usize,
25894 ))
25895 }
25896 pub fn get_slot_dist(&self) -> Result<&'a [u8], ErrorContext> {
25897 let mut iter = self.clone();
25898 iter.pos = 0;
25899 for attr in iter {
25900 if let Ok(NetemAttrs::SlotDist(val)) = attr {
25901 return Ok(val);
25902 }
25903 }
25904 Err(ErrorContext::new_missing(
25905 "NetemAttrs",
25906 "SlotDist",
25907 self.orig_loc,
25908 self.buf.as_ptr() as usize,
25909 ))
25910 }
25911 pub fn get_prng_seed(&self) -> Result<u64, ErrorContext> {
25912 let mut iter = self.clone();
25913 iter.pos = 0;
25914 for attr in iter {
25915 if let Ok(NetemAttrs::PrngSeed(val)) = attr {
25916 return Ok(val);
25917 }
25918 }
25919 Err(ErrorContext::new_missing(
25920 "NetemAttrs",
25921 "PrngSeed",
25922 self.orig_loc,
25923 self.buf.as_ptr() as usize,
25924 ))
25925 }
25926}
25927impl NetemAttrs<'_> {
25928 pub fn new<'a>(buf: &'a [u8]) -> IterableNetemAttrs<'a> {
25929 IterableNetemAttrs::with_loc(buf, buf.as_ptr() as usize)
25930 }
25931 fn attr_from_type(r#type: u16) -> Option<&'static str> {
25932 let res = match r#type {
25933 1u16 => "Corr",
25934 2u16 => "DelayDist",
25935 3u16 => "Reorder",
25936 4u16 => "Corrupt",
25937 5u16 => "Loss",
25938 6u16 => "Rate",
25939 7u16 => "Ecn",
25940 8u16 => "Rate64",
25941 9u16 => "Pad",
25942 10u16 => "Latency64",
25943 11u16 => "Jitter64",
25944 12u16 => "Slot",
25945 13u16 => "SlotDist",
25946 14u16 => "PrngSeed",
25947 _ => return None,
25948 };
25949 Some(res)
25950 }
25951}
25952#[derive(Clone, Copy, Default)]
25953pub struct IterableNetemAttrs<'a> {
25954 buf: &'a [u8],
25955 pos: usize,
25956 orig_loc: usize,
25957}
25958impl<'a> IterableNetemAttrs<'a> {
25959 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
25960 Self {
25961 buf,
25962 pos: 0,
25963 orig_loc,
25964 }
25965 }
25966 pub fn get_buf(&self) -> &'a [u8] {
25967 self.buf
25968 }
25969}
25970impl<'a> Iterator for IterableNetemAttrs<'a> {
25971 type Item = Result<NetemAttrs<'a>, ErrorContext>;
25972 fn next(&mut self) -> Option<Self::Item> {
25973 let mut pos;
25974 let mut r#type;
25975 loop {
25976 pos = self.pos;
25977 r#type = None;
25978 if self.buf.len() == self.pos {
25979 return None;
25980 }
25981 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
25982 self.pos = self.buf.len();
25983 break;
25984 };
25985 r#type = Some(header.r#type);
25986 let res = match header.r#type {
25987 1u16 => NetemAttrs::Corr({
25988 let res = Some(TcNetemCorr::new_from_zeroed(next));
25989 let Some(val) = res else { break };
25990 val
25991 }),
25992 2u16 => NetemAttrs::DelayDist({
25993 let res = Some(next);
25994 let Some(val) = res else { break };
25995 val
25996 }),
25997 3u16 => NetemAttrs::Reorder({
25998 let res = Some(TcNetemReorder::new_from_zeroed(next));
25999 let Some(val) = res else { break };
26000 val
26001 }),
26002 4u16 => NetemAttrs::Corrupt({
26003 let res = Some(TcNetemCorrupt::new_from_zeroed(next));
26004 let Some(val) = res else { break };
26005 val
26006 }),
26007 5u16 => NetemAttrs::Loss({
26008 let res = Some(IterableNetemLossAttrs::with_loc(next, self.orig_loc));
26009 let Some(val) = res else { break };
26010 val
26011 }),
26012 6u16 => NetemAttrs::Rate({
26013 let res = Some(TcNetemRate::new_from_zeroed(next));
26014 let Some(val) = res else { break };
26015 val
26016 }),
26017 7u16 => NetemAttrs::Ecn({
26018 let res = parse_u32(next);
26019 let Some(val) = res else { break };
26020 val
26021 }),
26022 8u16 => NetemAttrs::Rate64({
26023 let res = parse_u64(next);
26024 let Some(val) = res else { break };
26025 val
26026 }),
26027 9u16 => NetemAttrs::Pad({
26028 let res = parse_u32(next);
26029 let Some(val) = res else { break };
26030 val
26031 }),
26032 10u16 => NetemAttrs::Latency64({
26033 let res = parse_i64(next);
26034 let Some(val) = res else { break };
26035 val
26036 }),
26037 11u16 => NetemAttrs::Jitter64({
26038 let res = parse_i64(next);
26039 let Some(val) = res else { break };
26040 val
26041 }),
26042 12u16 => NetemAttrs::Slot({
26043 let res = Some(TcNetemSlot::new_from_zeroed(next));
26044 let Some(val) = res else { break };
26045 val
26046 }),
26047 13u16 => NetemAttrs::SlotDist({
26048 let res = Some(next);
26049 let Some(val) = res else { break };
26050 val
26051 }),
26052 14u16 => NetemAttrs::PrngSeed({
26053 let res = parse_u64(next);
26054 let Some(val) = res else { break };
26055 val
26056 }),
26057 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
26058 n => continue,
26059 };
26060 return Some(Ok(res));
26061 }
26062 Some(Err(ErrorContext::new(
26063 "NetemAttrs",
26064 r#type.and_then(|t| NetemAttrs::attr_from_type(t)),
26065 self.orig_loc,
26066 self.buf.as_ptr().wrapping_add(pos) as usize,
26067 )))
26068 }
26069}
26070impl<'a> std::fmt::Debug for IterableNetemAttrs<'_> {
26071 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26072 let mut fmt = f.debug_struct("NetemAttrs");
26073 for attr in self.clone() {
26074 let attr = match attr {
26075 Ok(a) => a,
26076 Err(err) => {
26077 fmt.finish()?;
26078 f.write_str("Err(")?;
26079 err.fmt(f)?;
26080 return f.write_str(")");
26081 }
26082 };
26083 match attr {
26084 NetemAttrs::Corr(val) => fmt.field("Corr", &val),
26085 NetemAttrs::DelayDist(val) => fmt.field("DelayDist", &val),
26086 NetemAttrs::Reorder(val) => fmt.field("Reorder", &val),
26087 NetemAttrs::Corrupt(val) => fmt.field("Corrupt", &val),
26088 NetemAttrs::Loss(val) => fmt.field("Loss", &val),
26089 NetemAttrs::Rate(val) => fmt.field("Rate", &val),
26090 NetemAttrs::Ecn(val) => fmt.field("Ecn", &val),
26091 NetemAttrs::Rate64(val) => fmt.field("Rate64", &val),
26092 NetemAttrs::Pad(val) => fmt.field("Pad", &val),
26093 NetemAttrs::Latency64(val) => fmt.field("Latency64", &val),
26094 NetemAttrs::Jitter64(val) => fmt.field("Jitter64", &val),
26095 NetemAttrs::Slot(val) => fmt.field("Slot", &val),
26096 NetemAttrs::SlotDist(val) => fmt.field("SlotDist", &val),
26097 NetemAttrs::PrngSeed(val) => fmt.field("PrngSeed", &val),
26098 };
26099 }
26100 fmt.finish()
26101 }
26102}
26103impl IterableNetemAttrs<'_> {
26104 pub fn lookup_attr(
26105 &self,
26106 offset: usize,
26107 missing_type: Option<u16>,
26108 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
26109 let mut stack = Vec::new();
26110 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
26111 if missing_type.is_some() && cur == offset {
26112 stack.push(("NetemAttrs", offset));
26113 return (
26114 stack,
26115 missing_type.and_then(|t| NetemAttrs::attr_from_type(t)),
26116 );
26117 }
26118 if cur > offset || cur + self.buf.len() < offset {
26119 return (stack, None);
26120 }
26121 let mut attrs = self.clone();
26122 let mut last_off = cur + attrs.pos;
26123 let mut missing = None;
26124 while let Some(attr) = attrs.next() {
26125 let Ok(attr) = attr else { break };
26126 match attr {
26127 NetemAttrs::Corr(val) => {
26128 if last_off == offset {
26129 stack.push(("Corr", last_off));
26130 break;
26131 }
26132 }
26133 NetemAttrs::DelayDist(val) => {
26134 if last_off == offset {
26135 stack.push(("DelayDist", last_off));
26136 break;
26137 }
26138 }
26139 NetemAttrs::Reorder(val) => {
26140 if last_off == offset {
26141 stack.push(("Reorder", last_off));
26142 break;
26143 }
26144 }
26145 NetemAttrs::Corrupt(val) => {
26146 if last_off == offset {
26147 stack.push(("Corrupt", last_off));
26148 break;
26149 }
26150 }
26151 NetemAttrs::Loss(val) => {
26152 (stack, missing) = val.lookup_attr(offset, missing_type);
26153 if !stack.is_empty() {
26154 break;
26155 }
26156 }
26157 NetemAttrs::Rate(val) => {
26158 if last_off == offset {
26159 stack.push(("Rate", last_off));
26160 break;
26161 }
26162 }
26163 NetemAttrs::Ecn(val) => {
26164 if last_off == offset {
26165 stack.push(("Ecn", last_off));
26166 break;
26167 }
26168 }
26169 NetemAttrs::Rate64(val) => {
26170 if last_off == offset {
26171 stack.push(("Rate64", last_off));
26172 break;
26173 }
26174 }
26175 NetemAttrs::Pad(val) => {
26176 if last_off == offset {
26177 stack.push(("Pad", last_off));
26178 break;
26179 }
26180 }
26181 NetemAttrs::Latency64(val) => {
26182 if last_off == offset {
26183 stack.push(("Latency64", last_off));
26184 break;
26185 }
26186 }
26187 NetemAttrs::Jitter64(val) => {
26188 if last_off == offset {
26189 stack.push(("Jitter64", last_off));
26190 break;
26191 }
26192 }
26193 NetemAttrs::Slot(val) => {
26194 if last_off == offset {
26195 stack.push(("Slot", last_off));
26196 break;
26197 }
26198 }
26199 NetemAttrs::SlotDist(val) => {
26200 if last_off == offset {
26201 stack.push(("SlotDist", last_off));
26202 break;
26203 }
26204 }
26205 NetemAttrs::PrngSeed(val) => {
26206 if last_off == offset {
26207 stack.push(("PrngSeed", last_off));
26208 break;
26209 }
26210 }
26211 _ => {}
26212 };
26213 last_off = cur + attrs.pos;
26214 }
26215 if !stack.is_empty() {
26216 stack.push(("NetemAttrs", cur));
26217 }
26218 (stack, missing)
26219 }
26220}
26221#[derive(Clone)]
26222pub enum NetemLossAttrs {
26223 #[doc = "General Intuitive - 4 state model\n"]
26224 Gi(TcNetemGimodel),
26225 #[doc = "Gilbert Elliot models\n"]
26226 Ge(TcNetemGemodel),
26227}
26228impl<'a> IterableNetemLossAttrs<'a> {
26229 #[doc = "General Intuitive - 4 state model\n"]
26230 pub fn get_gi(&self) -> Result<TcNetemGimodel, ErrorContext> {
26231 let mut iter = self.clone();
26232 iter.pos = 0;
26233 for attr in iter {
26234 if let Ok(NetemLossAttrs::Gi(val)) = attr {
26235 return Ok(val);
26236 }
26237 }
26238 Err(ErrorContext::new_missing(
26239 "NetemLossAttrs",
26240 "Gi",
26241 self.orig_loc,
26242 self.buf.as_ptr() as usize,
26243 ))
26244 }
26245 #[doc = "Gilbert Elliot models\n"]
26246 pub fn get_ge(&self) -> Result<TcNetemGemodel, ErrorContext> {
26247 let mut iter = self.clone();
26248 iter.pos = 0;
26249 for attr in iter {
26250 if let Ok(NetemLossAttrs::Ge(val)) = attr {
26251 return Ok(val);
26252 }
26253 }
26254 Err(ErrorContext::new_missing(
26255 "NetemLossAttrs",
26256 "Ge",
26257 self.orig_loc,
26258 self.buf.as_ptr() as usize,
26259 ))
26260 }
26261}
26262impl NetemLossAttrs {
26263 pub fn new<'a>(buf: &'a [u8]) -> IterableNetemLossAttrs<'a> {
26264 IterableNetemLossAttrs::with_loc(buf, buf.as_ptr() as usize)
26265 }
26266 fn attr_from_type(r#type: u16) -> Option<&'static str> {
26267 let res = match r#type {
26268 1u16 => "Gi",
26269 2u16 => "Ge",
26270 _ => return None,
26271 };
26272 Some(res)
26273 }
26274}
26275#[derive(Clone, Copy, Default)]
26276pub struct IterableNetemLossAttrs<'a> {
26277 buf: &'a [u8],
26278 pos: usize,
26279 orig_loc: usize,
26280}
26281impl<'a> IterableNetemLossAttrs<'a> {
26282 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
26283 Self {
26284 buf,
26285 pos: 0,
26286 orig_loc,
26287 }
26288 }
26289 pub fn get_buf(&self) -> &'a [u8] {
26290 self.buf
26291 }
26292}
26293impl<'a> Iterator for IterableNetemLossAttrs<'a> {
26294 type Item = Result<NetemLossAttrs, ErrorContext>;
26295 fn next(&mut self) -> Option<Self::Item> {
26296 let mut pos;
26297 let mut r#type;
26298 loop {
26299 pos = self.pos;
26300 r#type = None;
26301 if self.buf.len() == self.pos {
26302 return None;
26303 }
26304 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
26305 self.pos = self.buf.len();
26306 break;
26307 };
26308 r#type = Some(header.r#type);
26309 let res = match header.r#type {
26310 1u16 => NetemLossAttrs::Gi({
26311 let res = Some(TcNetemGimodel::new_from_zeroed(next));
26312 let Some(val) = res else { break };
26313 val
26314 }),
26315 2u16 => NetemLossAttrs::Ge({
26316 let res = Some(TcNetemGemodel::new_from_zeroed(next));
26317 let Some(val) = res else { break };
26318 val
26319 }),
26320 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
26321 n => continue,
26322 };
26323 return Some(Ok(res));
26324 }
26325 Some(Err(ErrorContext::new(
26326 "NetemLossAttrs",
26327 r#type.and_then(|t| NetemLossAttrs::attr_from_type(t)),
26328 self.orig_loc,
26329 self.buf.as_ptr().wrapping_add(pos) as usize,
26330 )))
26331 }
26332}
26333impl std::fmt::Debug for IterableNetemLossAttrs<'_> {
26334 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26335 let mut fmt = f.debug_struct("NetemLossAttrs");
26336 for attr in self.clone() {
26337 let attr = match attr {
26338 Ok(a) => a,
26339 Err(err) => {
26340 fmt.finish()?;
26341 f.write_str("Err(")?;
26342 err.fmt(f)?;
26343 return f.write_str(")");
26344 }
26345 };
26346 match attr {
26347 NetemLossAttrs::Gi(val) => fmt.field("Gi", &val),
26348 NetemLossAttrs::Ge(val) => fmt.field("Ge", &val),
26349 };
26350 }
26351 fmt.finish()
26352 }
26353}
26354impl IterableNetemLossAttrs<'_> {
26355 pub fn lookup_attr(
26356 &self,
26357 offset: usize,
26358 missing_type: Option<u16>,
26359 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
26360 let mut stack = Vec::new();
26361 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
26362 if missing_type.is_some() && cur == offset {
26363 stack.push(("NetemLossAttrs", offset));
26364 return (
26365 stack,
26366 missing_type.and_then(|t| NetemLossAttrs::attr_from_type(t)),
26367 );
26368 }
26369 if cur > offset || cur + self.buf.len() < offset {
26370 return (stack, None);
26371 }
26372 let mut attrs = self.clone();
26373 let mut last_off = cur + attrs.pos;
26374 while let Some(attr) = attrs.next() {
26375 let Ok(attr) = attr else { break };
26376 match attr {
26377 NetemLossAttrs::Gi(val) => {
26378 if last_off == offset {
26379 stack.push(("Gi", last_off));
26380 break;
26381 }
26382 }
26383 NetemLossAttrs::Ge(val) => {
26384 if last_off == offset {
26385 stack.push(("Ge", last_off));
26386 break;
26387 }
26388 }
26389 _ => {}
26390 };
26391 last_off = cur + attrs.pos;
26392 }
26393 if !stack.is_empty() {
26394 stack.push(("NetemLossAttrs", cur));
26395 }
26396 (stack, None)
26397 }
26398}
26399#[derive(Clone)]
26400pub enum PieAttrs {
26401 Target(u32),
26402 Limit(u32),
26403 Tupdate(u32),
26404 Alpha(u32),
26405 Beta(u32),
26406 Ecn(u32),
26407 Bytemode(u32),
26408 DqRateEstimator(u32),
26409}
26410impl<'a> IterablePieAttrs<'a> {
26411 pub fn get_target(&self) -> Result<u32, ErrorContext> {
26412 let mut iter = self.clone();
26413 iter.pos = 0;
26414 for attr in iter {
26415 if let Ok(PieAttrs::Target(val)) = attr {
26416 return Ok(val);
26417 }
26418 }
26419 Err(ErrorContext::new_missing(
26420 "PieAttrs",
26421 "Target",
26422 self.orig_loc,
26423 self.buf.as_ptr() as usize,
26424 ))
26425 }
26426 pub fn get_limit(&self) -> Result<u32, ErrorContext> {
26427 let mut iter = self.clone();
26428 iter.pos = 0;
26429 for attr in iter {
26430 if let Ok(PieAttrs::Limit(val)) = attr {
26431 return Ok(val);
26432 }
26433 }
26434 Err(ErrorContext::new_missing(
26435 "PieAttrs",
26436 "Limit",
26437 self.orig_loc,
26438 self.buf.as_ptr() as usize,
26439 ))
26440 }
26441 pub fn get_tupdate(&self) -> Result<u32, ErrorContext> {
26442 let mut iter = self.clone();
26443 iter.pos = 0;
26444 for attr in iter {
26445 if let Ok(PieAttrs::Tupdate(val)) = attr {
26446 return Ok(val);
26447 }
26448 }
26449 Err(ErrorContext::new_missing(
26450 "PieAttrs",
26451 "Tupdate",
26452 self.orig_loc,
26453 self.buf.as_ptr() as usize,
26454 ))
26455 }
26456 pub fn get_alpha(&self) -> Result<u32, ErrorContext> {
26457 let mut iter = self.clone();
26458 iter.pos = 0;
26459 for attr in iter {
26460 if let Ok(PieAttrs::Alpha(val)) = attr {
26461 return Ok(val);
26462 }
26463 }
26464 Err(ErrorContext::new_missing(
26465 "PieAttrs",
26466 "Alpha",
26467 self.orig_loc,
26468 self.buf.as_ptr() as usize,
26469 ))
26470 }
26471 pub fn get_beta(&self) -> Result<u32, ErrorContext> {
26472 let mut iter = self.clone();
26473 iter.pos = 0;
26474 for attr in iter {
26475 if let Ok(PieAttrs::Beta(val)) = attr {
26476 return Ok(val);
26477 }
26478 }
26479 Err(ErrorContext::new_missing(
26480 "PieAttrs",
26481 "Beta",
26482 self.orig_loc,
26483 self.buf.as_ptr() as usize,
26484 ))
26485 }
26486 pub fn get_ecn(&self) -> Result<u32, ErrorContext> {
26487 let mut iter = self.clone();
26488 iter.pos = 0;
26489 for attr in iter {
26490 if let Ok(PieAttrs::Ecn(val)) = attr {
26491 return Ok(val);
26492 }
26493 }
26494 Err(ErrorContext::new_missing(
26495 "PieAttrs",
26496 "Ecn",
26497 self.orig_loc,
26498 self.buf.as_ptr() as usize,
26499 ))
26500 }
26501 pub fn get_bytemode(&self) -> Result<u32, ErrorContext> {
26502 let mut iter = self.clone();
26503 iter.pos = 0;
26504 for attr in iter {
26505 if let Ok(PieAttrs::Bytemode(val)) = attr {
26506 return Ok(val);
26507 }
26508 }
26509 Err(ErrorContext::new_missing(
26510 "PieAttrs",
26511 "Bytemode",
26512 self.orig_loc,
26513 self.buf.as_ptr() as usize,
26514 ))
26515 }
26516 pub fn get_dq_rate_estimator(&self) -> Result<u32, ErrorContext> {
26517 let mut iter = self.clone();
26518 iter.pos = 0;
26519 for attr in iter {
26520 if let Ok(PieAttrs::DqRateEstimator(val)) = attr {
26521 return Ok(val);
26522 }
26523 }
26524 Err(ErrorContext::new_missing(
26525 "PieAttrs",
26526 "DqRateEstimator",
26527 self.orig_loc,
26528 self.buf.as_ptr() as usize,
26529 ))
26530 }
26531}
26532impl PieAttrs {
26533 pub fn new<'a>(buf: &'a [u8]) -> IterablePieAttrs<'a> {
26534 IterablePieAttrs::with_loc(buf, buf.as_ptr() as usize)
26535 }
26536 fn attr_from_type(r#type: u16) -> Option<&'static str> {
26537 let res = match r#type {
26538 1u16 => "Target",
26539 2u16 => "Limit",
26540 3u16 => "Tupdate",
26541 4u16 => "Alpha",
26542 5u16 => "Beta",
26543 6u16 => "Ecn",
26544 7u16 => "Bytemode",
26545 8u16 => "DqRateEstimator",
26546 _ => return None,
26547 };
26548 Some(res)
26549 }
26550}
26551#[derive(Clone, Copy, Default)]
26552pub struct IterablePieAttrs<'a> {
26553 buf: &'a [u8],
26554 pos: usize,
26555 orig_loc: usize,
26556}
26557impl<'a> IterablePieAttrs<'a> {
26558 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
26559 Self {
26560 buf,
26561 pos: 0,
26562 orig_loc,
26563 }
26564 }
26565 pub fn get_buf(&self) -> &'a [u8] {
26566 self.buf
26567 }
26568}
26569impl<'a> Iterator for IterablePieAttrs<'a> {
26570 type Item = Result<PieAttrs, ErrorContext>;
26571 fn next(&mut self) -> Option<Self::Item> {
26572 let mut pos;
26573 let mut r#type;
26574 loop {
26575 pos = self.pos;
26576 r#type = None;
26577 if self.buf.len() == self.pos {
26578 return None;
26579 }
26580 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
26581 self.pos = self.buf.len();
26582 break;
26583 };
26584 r#type = Some(header.r#type);
26585 let res = match header.r#type {
26586 1u16 => PieAttrs::Target({
26587 let res = parse_u32(next);
26588 let Some(val) = res else { break };
26589 val
26590 }),
26591 2u16 => PieAttrs::Limit({
26592 let res = parse_u32(next);
26593 let Some(val) = res else { break };
26594 val
26595 }),
26596 3u16 => PieAttrs::Tupdate({
26597 let res = parse_u32(next);
26598 let Some(val) = res else { break };
26599 val
26600 }),
26601 4u16 => PieAttrs::Alpha({
26602 let res = parse_u32(next);
26603 let Some(val) = res else { break };
26604 val
26605 }),
26606 5u16 => PieAttrs::Beta({
26607 let res = parse_u32(next);
26608 let Some(val) = res else { break };
26609 val
26610 }),
26611 6u16 => PieAttrs::Ecn({
26612 let res = parse_u32(next);
26613 let Some(val) = res else { break };
26614 val
26615 }),
26616 7u16 => PieAttrs::Bytemode({
26617 let res = parse_u32(next);
26618 let Some(val) = res else { break };
26619 val
26620 }),
26621 8u16 => PieAttrs::DqRateEstimator({
26622 let res = parse_u32(next);
26623 let Some(val) = res else { break };
26624 val
26625 }),
26626 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
26627 n => continue,
26628 };
26629 return Some(Ok(res));
26630 }
26631 Some(Err(ErrorContext::new(
26632 "PieAttrs",
26633 r#type.and_then(|t| PieAttrs::attr_from_type(t)),
26634 self.orig_loc,
26635 self.buf.as_ptr().wrapping_add(pos) as usize,
26636 )))
26637 }
26638}
26639impl std::fmt::Debug for IterablePieAttrs<'_> {
26640 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26641 let mut fmt = f.debug_struct("PieAttrs");
26642 for attr in self.clone() {
26643 let attr = match attr {
26644 Ok(a) => a,
26645 Err(err) => {
26646 fmt.finish()?;
26647 f.write_str("Err(")?;
26648 err.fmt(f)?;
26649 return f.write_str(")");
26650 }
26651 };
26652 match attr {
26653 PieAttrs::Target(val) => fmt.field("Target", &val),
26654 PieAttrs::Limit(val) => fmt.field("Limit", &val),
26655 PieAttrs::Tupdate(val) => fmt.field("Tupdate", &val),
26656 PieAttrs::Alpha(val) => fmt.field("Alpha", &val),
26657 PieAttrs::Beta(val) => fmt.field("Beta", &val),
26658 PieAttrs::Ecn(val) => fmt.field("Ecn", &val),
26659 PieAttrs::Bytemode(val) => fmt.field("Bytemode", &val),
26660 PieAttrs::DqRateEstimator(val) => fmt.field("DqRateEstimator", &val),
26661 };
26662 }
26663 fmt.finish()
26664 }
26665}
26666impl IterablePieAttrs<'_> {
26667 pub fn lookup_attr(
26668 &self,
26669 offset: usize,
26670 missing_type: Option<u16>,
26671 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
26672 let mut stack = Vec::new();
26673 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
26674 if missing_type.is_some() && cur == offset {
26675 stack.push(("PieAttrs", offset));
26676 return (
26677 stack,
26678 missing_type.and_then(|t| PieAttrs::attr_from_type(t)),
26679 );
26680 }
26681 if cur > offset || cur + self.buf.len() < offset {
26682 return (stack, None);
26683 }
26684 let mut attrs = self.clone();
26685 let mut last_off = cur + attrs.pos;
26686 while let Some(attr) = attrs.next() {
26687 let Ok(attr) = attr else { break };
26688 match attr {
26689 PieAttrs::Target(val) => {
26690 if last_off == offset {
26691 stack.push(("Target", last_off));
26692 break;
26693 }
26694 }
26695 PieAttrs::Limit(val) => {
26696 if last_off == offset {
26697 stack.push(("Limit", last_off));
26698 break;
26699 }
26700 }
26701 PieAttrs::Tupdate(val) => {
26702 if last_off == offset {
26703 stack.push(("Tupdate", last_off));
26704 break;
26705 }
26706 }
26707 PieAttrs::Alpha(val) => {
26708 if last_off == offset {
26709 stack.push(("Alpha", last_off));
26710 break;
26711 }
26712 }
26713 PieAttrs::Beta(val) => {
26714 if last_off == offset {
26715 stack.push(("Beta", last_off));
26716 break;
26717 }
26718 }
26719 PieAttrs::Ecn(val) => {
26720 if last_off == offset {
26721 stack.push(("Ecn", last_off));
26722 break;
26723 }
26724 }
26725 PieAttrs::Bytemode(val) => {
26726 if last_off == offset {
26727 stack.push(("Bytemode", last_off));
26728 break;
26729 }
26730 }
26731 PieAttrs::DqRateEstimator(val) => {
26732 if last_off == offset {
26733 stack.push(("DqRateEstimator", last_off));
26734 break;
26735 }
26736 }
26737 _ => {}
26738 };
26739 last_off = cur + attrs.pos;
26740 }
26741 if !stack.is_empty() {
26742 stack.push(("PieAttrs", cur));
26743 }
26744 (stack, None)
26745 }
26746}
26747#[derive(Clone)]
26748pub enum PoliceAttrs<'a> {
26749 Tbf(TcPolice),
26750 Rate(&'a [u8]),
26751 Peakrate(&'a [u8]),
26752 Avrate(u32),
26753 Result(u32),
26754 Tm(TcfT),
26755 Pad(&'a [u8]),
26756 Rate64(u64),
26757 Peakrate64(u64),
26758 Pktrate64(u64),
26759 Pktburst64(u64),
26760}
26761impl<'a> IterablePoliceAttrs<'a> {
26762 pub fn get_tbf(&self) -> Result<TcPolice, ErrorContext> {
26763 let mut iter = self.clone();
26764 iter.pos = 0;
26765 for attr in iter {
26766 if let Ok(PoliceAttrs::Tbf(val)) = attr {
26767 return Ok(val);
26768 }
26769 }
26770 Err(ErrorContext::new_missing(
26771 "PoliceAttrs",
26772 "Tbf",
26773 self.orig_loc,
26774 self.buf.as_ptr() as usize,
26775 ))
26776 }
26777 pub fn get_rate(&self) -> Result<&'a [u8], ErrorContext> {
26778 let mut iter = self.clone();
26779 iter.pos = 0;
26780 for attr in iter {
26781 if let Ok(PoliceAttrs::Rate(val)) = attr {
26782 return Ok(val);
26783 }
26784 }
26785 Err(ErrorContext::new_missing(
26786 "PoliceAttrs",
26787 "Rate",
26788 self.orig_loc,
26789 self.buf.as_ptr() as usize,
26790 ))
26791 }
26792 pub fn get_peakrate(&self) -> Result<&'a [u8], ErrorContext> {
26793 let mut iter = self.clone();
26794 iter.pos = 0;
26795 for attr in iter {
26796 if let Ok(PoliceAttrs::Peakrate(val)) = attr {
26797 return Ok(val);
26798 }
26799 }
26800 Err(ErrorContext::new_missing(
26801 "PoliceAttrs",
26802 "Peakrate",
26803 self.orig_loc,
26804 self.buf.as_ptr() as usize,
26805 ))
26806 }
26807 pub fn get_avrate(&self) -> Result<u32, ErrorContext> {
26808 let mut iter = self.clone();
26809 iter.pos = 0;
26810 for attr in iter {
26811 if let Ok(PoliceAttrs::Avrate(val)) = attr {
26812 return Ok(val);
26813 }
26814 }
26815 Err(ErrorContext::new_missing(
26816 "PoliceAttrs",
26817 "Avrate",
26818 self.orig_loc,
26819 self.buf.as_ptr() as usize,
26820 ))
26821 }
26822 pub fn get_result(&self) -> Result<u32, ErrorContext> {
26823 let mut iter = self.clone();
26824 iter.pos = 0;
26825 for attr in iter {
26826 if let Ok(PoliceAttrs::Result(val)) = attr {
26827 return Ok(val);
26828 }
26829 }
26830 Err(ErrorContext::new_missing(
26831 "PoliceAttrs",
26832 "Result",
26833 self.orig_loc,
26834 self.buf.as_ptr() as usize,
26835 ))
26836 }
26837 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
26838 let mut iter = self.clone();
26839 iter.pos = 0;
26840 for attr in iter {
26841 if let Ok(PoliceAttrs::Tm(val)) = attr {
26842 return Ok(val);
26843 }
26844 }
26845 Err(ErrorContext::new_missing(
26846 "PoliceAttrs",
26847 "Tm",
26848 self.orig_loc,
26849 self.buf.as_ptr() as usize,
26850 ))
26851 }
26852 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
26853 let mut iter = self.clone();
26854 iter.pos = 0;
26855 for attr in iter {
26856 if let Ok(PoliceAttrs::Pad(val)) = attr {
26857 return Ok(val);
26858 }
26859 }
26860 Err(ErrorContext::new_missing(
26861 "PoliceAttrs",
26862 "Pad",
26863 self.orig_loc,
26864 self.buf.as_ptr() as usize,
26865 ))
26866 }
26867 pub fn get_rate64(&self) -> Result<u64, ErrorContext> {
26868 let mut iter = self.clone();
26869 iter.pos = 0;
26870 for attr in iter {
26871 if let Ok(PoliceAttrs::Rate64(val)) = attr {
26872 return Ok(val);
26873 }
26874 }
26875 Err(ErrorContext::new_missing(
26876 "PoliceAttrs",
26877 "Rate64",
26878 self.orig_loc,
26879 self.buf.as_ptr() as usize,
26880 ))
26881 }
26882 pub fn get_peakrate64(&self) -> Result<u64, ErrorContext> {
26883 let mut iter = self.clone();
26884 iter.pos = 0;
26885 for attr in iter {
26886 if let Ok(PoliceAttrs::Peakrate64(val)) = attr {
26887 return Ok(val);
26888 }
26889 }
26890 Err(ErrorContext::new_missing(
26891 "PoliceAttrs",
26892 "Peakrate64",
26893 self.orig_loc,
26894 self.buf.as_ptr() as usize,
26895 ))
26896 }
26897 pub fn get_pktrate64(&self) -> Result<u64, ErrorContext> {
26898 let mut iter = self.clone();
26899 iter.pos = 0;
26900 for attr in iter {
26901 if let Ok(PoliceAttrs::Pktrate64(val)) = attr {
26902 return Ok(val);
26903 }
26904 }
26905 Err(ErrorContext::new_missing(
26906 "PoliceAttrs",
26907 "Pktrate64",
26908 self.orig_loc,
26909 self.buf.as_ptr() as usize,
26910 ))
26911 }
26912 pub fn get_pktburst64(&self) -> Result<u64, ErrorContext> {
26913 let mut iter = self.clone();
26914 iter.pos = 0;
26915 for attr in iter {
26916 if let Ok(PoliceAttrs::Pktburst64(val)) = attr {
26917 return Ok(val);
26918 }
26919 }
26920 Err(ErrorContext::new_missing(
26921 "PoliceAttrs",
26922 "Pktburst64",
26923 self.orig_loc,
26924 self.buf.as_ptr() as usize,
26925 ))
26926 }
26927}
26928impl PoliceAttrs<'_> {
26929 pub fn new<'a>(buf: &'a [u8]) -> IterablePoliceAttrs<'a> {
26930 IterablePoliceAttrs::with_loc(buf, buf.as_ptr() as usize)
26931 }
26932 fn attr_from_type(r#type: u16) -> Option<&'static str> {
26933 let res = match r#type {
26934 1u16 => "Tbf",
26935 2u16 => "Rate",
26936 3u16 => "Peakrate",
26937 4u16 => "Avrate",
26938 5u16 => "Result",
26939 6u16 => "Tm",
26940 7u16 => "Pad",
26941 8u16 => "Rate64",
26942 9u16 => "Peakrate64",
26943 10u16 => "Pktrate64",
26944 11u16 => "Pktburst64",
26945 _ => return None,
26946 };
26947 Some(res)
26948 }
26949}
26950#[derive(Clone, Copy, Default)]
26951pub struct IterablePoliceAttrs<'a> {
26952 buf: &'a [u8],
26953 pos: usize,
26954 orig_loc: usize,
26955}
26956impl<'a> IterablePoliceAttrs<'a> {
26957 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
26958 Self {
26959 buf,
26960 pos: 0,
26961 orig_loc,
26962 }
26963 }
26964 pub fn get_buf(&self) -> &'a [u8] {
26965 self.buf
26966 }
26967}
26968impl<'a> Iterator for IterablePoliceAttrs<'a> {
26969 type Item = Result<PoliceAttrs<'a>, ErrorContext>;
26970 fn next(&mut self) -> Option<Self::Item> {
26971 let mut pos;
26972 let mut r#type;
26973 loop {
26974 pos = self.pos;
26975 r#type = None;
26976 if self.buf.len() == self.pos {
26977 return None;
26978 }
26979 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
26980 self.pos = self.buf.len();
26981 break;
26982 };
26983 r#type = Some(header.r#type);
26984 let res = match header.r#type {
26985 1u16 => PoliceAttrs::Tbf({
26986 let res = Some(TcPolice::new_from_zeroed(next));
26987 let Some(val) = res else { break };
26988 val
26989 }),
26990 2u16 => PoliceAttrs::Rate({
26991 let res = Some(next);
26992 let Some(val) = res else { break };
26993 val
26994 }),
26995 3u16 => PoliceAttrs::Peakrate({
26996 let res = Some(next);
26997 let Some(val) = res else { break };
26998 val
26999 }),
27000 4u16 => PoliceAttrs::Avrate({
27001 let res = parse_u32(next);
27002 let Some(val) = res else { break };
27003 val
27004 }),
27005 5u16 => PoliceAttrs::Result({
27006 let res = parse_u32(next);
27007 let Some(val) = res else { break };
27008 val
27009 }),
27010 6u16 => PoliceAttrs::Tm({
27011 let res = Some(TcfT::new_from_zeroed(next));
27012 let Some(val) = res else { break };
27013 val
27014 }),
27015 7u16 => PoliceAttrs::Pad({
27016 let res = Some(next);
27017 let Some(val) = res else { break };
27018 val
27019 }),
27020 8u16 => PoliceAttrs::Rate64({
27021 let res = parse_u64(next);
27022 let Some(val) = res else { break };
27023 val
27024 }),
27025 9u16 => PoliceAttrs::Peakrate64({
27026 let res = parse_u64(next);
27027 let Some(val) = res else { break };
27028 val
27029 }),
27030 10u16 => PoliceAttrs::Pktrate64({
27031 let res = parse_u64(next);
27032 let Some(val) = res else { break };
27033 val
27034 }),
27035 11u16 => PoliceAttrs::Pktburst64({
27036 let res = parse_u64(next);
27037 let Some(val) = res else { break };
27038 val
27039 }),
27040 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
27041 n => continue,
27042 };
27043 return Some(Ok(res));
27044 }
27045 Some(Err(ErrorContext::new(
27046 "PoliceAttrs",
27047 r#type.and_then(|t| PoliceAttrs::attr_from_type(t)),
27048 self.orig_loc,
27049 self.buf.as_ptr().wrapping_add(pos) as usize,
27050 )))
27051 }
27052}
27053impl<'a> std::fmt::Debug for IterablePoliceAttrs<'_> {
27054 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27055 let mut fmt = f.debug_struct("PoliceAttrs");
27056 for attr in self.clone() {
27057 let attr = match attr {
27058 Ok(a) => a,
27059 Err(err) => {
27060 fmt.finish()?;
27061 f.write_str("Err(")?;
27062 err.fmt(f)?;
27063 return f.write_str(")");
27064 }
27065 };
27066 match attr {
27067 PoliceAttrs::Tbf(val) => fmt.field("Tbf", &val),
27068 PoliceAttrs::Rate(val) => fmt.field("Rate", &val),
27069 PoliceAttrs::Peakrate(val) => fmt.field("Peakrate", &val),
27070 PoliceAttrs::Avrate(val) => fmt.field("Avrate", &val),
27071 PoliceAttrs::Result(val) => fmt.field("Result", &val),
27072 PoliceAttrs::Tm(val) => fmt.field("Tm", &val),
27073 PoliceAttrs::Pad(val) => fmt.field("Pad", &val),
27074 PoliceAttrs::Rate64(val) => fmt.field("Rate64", &val),
27075 PoliceAttrs::Peakrate64(val) => fmt.field("Peakrate64", &val),
27076 PoliceAttrs::Pktrate64(val) => fmt.field("Pktrate64", &val),
27077 PoliceAttrs::Pktburst64(val) => fmt.field("Pktburst64", &val),
27078 };
27079 }
27080 fmt.finish()
27081 }
27082}
27083impl IterablePoliceAttrs<'_> {
27084 pub fn lookup_attr(
27085 &self,
27086 offset: usize,
27087 missing_type: Option<u16>,
27088 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27089 let mut stack = Vec::new();
27090 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
27091 if missing_type.is_some() && cur == offset {
27092 stack.push(("PoliceAttrs", offset));
27093 return (
27094 stack,
27095 missing_type.and_then(|t| PoliceAttrs::attr_from_type(t)),
27096 );
27097 }
27098 if cur > offset || cur + self.buf.len() < offset {
27099 return (stack, None);
27100 }
27101 let mut attrs = self.clone();
27102 let mut last_off = cur + attrs.pos;
27103 while let Some(attr) = attrs.next() {
27104 let Ok(attr) = attr else { break };
27105 match attr {
27106 PoliceAttrs::Tbf(val) => {
27107 if last_off == offset {
27108 stack.push(("Tbf", last_off));
27109 break;
27110 }
27111 }
27112 PoliceAttrs::Rate(val) => {
27113 if last_off == offset {
27114 stack.push(("Rate", last_off));
27115 break;
27116 }
27117 }
27118 PoliceAttrs::Peakrate(val) => {
27119 if last_off == offset {
27120 stack.push(("Peakrate", last_off));
27121 break;
27122 }
27123 }
27124 PoliceAttrs::Avrate(val) => {
27125 if last_off == offset {
27126 stack.push(("Avrate", last_off));
27127 break;
27128 }
27129 }
27130 PoliceAttrs::Result(val) => {
27131 if last_off == offset {
27132 stack.push(("Result", last_off));
27133 break;
27134 }
27135 }
27136 PoliceAttrs::Tm(val) => {
27137 if last_off == offset {
27138 stack.push(("Tm", last_off));
27139 break;
27140 }
27141 }
27142 PoliceAttrs::Pad(val) => {
27143 if last_off == offset {
27144 stack.push(("Pad", last_off));
27145 break;
27146 }
27147 }
27148 PoliceAttrs::Rate64(val) => {
27149 if last_off == offset {
27150 stack.push(("Rate64", last_off));
27151 break;
27152 }
27153 }
27154 PoliceAttrs::Peakrate64(val) => {
27155 if last_off == offset {
27156 stack.push(("Peakrate64", last_off));
27157 break;
27158 }
27159 }
27160 PoliceAttrs::Pktrate64(val) => {
27161 if last_off == offset {
27162 stack.push(("Pktrate64", last_off));
27163 break;
27164 }
27165 }
27166 PoliceAttrs::Pktburst64(val) => {
27167 if last_off == offset {
27168 stack.push(("Pktburst64", last_off));
27169 break;
27170 }
27171 }
27172 _ => {}
27173 };
27174 last_off = cur + attrs.pos;
27175 }
27176 if !stack.is_empty() {
27177 stack.push(("PoliceAttrs", cur));
27178 }
27179 (stack, None)
27180 }
27181}
27182#[derive(Clone)]
27183pub enum QfqAttrs {
27184 Weight(u32),
27185 Lmax(u32),
27186}
27187impl<'a> IterableQfqAttrs<'a> {
27188 pub fn get_weight(&self) -> Result<u32, ErrorContext> {
27189 let mut iter = self.clone();
27190 iter.pos = 0;
27191 for attr in iter {
27192 if let Ok(QfqAttrs::Weight(val)) = attr {
27193 return Ok(val);
27194 }
27195 }
27196 Err(ErrorContext::new_missing(
27197 "QfqAttrs",
27198 "Weight",
27199 self.orig_loc,
27200 self.buf.as_ptr() as usize,
27201 ))
27202 }
27203 pub fn get_lmax(&self) -> Result<u32, ErrorContext> {
27204 let mut iter = self.clone();
27205 iter.pos = 0;
27206 for attr in iter {
27207 if let Ok(QfqAttrs::Lmax(val)) = attr {
27208 return Ok(val);
27209 }
27210 }
27211 Err(ErrorContext::new_missing(
27212 "QfqAttrs",
27213 "Lmax",
27214 self.orig_loc,
27215 self.buf.as_ptr() as usize,
27216 ))
27217 }
27218}
27219impl QfqAttrs {
27220 pub fn new<'a>(buf: &'a [u8]) -> IterableQfqAttrs<'a> {
27221 IterableQfqAttrs::with_loc(buf, buf.as_ptr() as usize)
27222 }
27223 fn attr_from_type(r#type: u16) -> Option<&'static str> {
27224 let res = match r#type {
27225 1u16 => "Weight",
27226 2u16 => "Lmax",
27227 _ => return None,
27228 };
27229 Some(res)
27230 }
27231}
27232#[derive(Clone, Copy, Default)]
27233pub struct IterableQfqAttrs<'a> {
27234 buf: &'a [u8],
27235 pos: usize,
27236 orig_loc: usize,
27237}
27238impl<'a> IterableQfqAttrs<'a> {
27239 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
27240 Self {
27241 buf,
27242 pos: 0,
27243 orig_loc,
27244 }
27245 }
27246 pub fn get_buf(&self) -> &'a [u8] {
27247 self.buf
27248 }
27249}
27250impl<'a> Iterator for IterableQfqAttrs<'a> {
27251 type Item = Result<QfqAttrs, ErrorContext>;
27252 fn next(&mut self) -> Option<Self::Item> {
27253 let mut pos;
27254 let mut r#type;
27255 loop {
27256 pos = self.pos;
27257 r#type = None;
27258 if self.buf.len() == self.pos {
27259 return None;
27260 }
27261 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
27262 self.pos = self.buf.len();
27263 break;
27264 };
27265 r#type = Some(header.r#type);
27266 let res = match header.r#type {
27267 1u16 => QfqAttrs::Weight({
27268 let res = parse_u32(next);
27269 let Some(val) = res else { break };
27270 val
27271 }),
27272 2u16 => QfqAttrs::Lmax({
27273 let res = parse_u32(next);
27274 let Some(val) = res else { break };
27275 val
27276 }),
27277 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
27278 n => continue,
27279 };
27280 return Some(Ok(res));
27281 }
27282 Some(Err(ErrorContext::new(
27283 "QfqAttrs",
27284 r#type.and_then(|t| QfqAttrs::attr_from_type(t)),
27285 self.orig_loc,
27286 self.buf.as_ptr().wrapping_add(pos) as usize,
27287 )))
27288 }
27289}
27290impl std::fmt::Debug for IterableQfqAttrs<'_> {
27291 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27292 let mut fmt = f.debug_struct("QfqAttrs");
27293 for attr in self.clone() {
27294 let attr = match attr {
27295 Ok(a) => a,
27296 Err(err) => {
27297 fmt.finish()?;
27298 f.write_str("Err(")?;
27299 err.fmt(f)?;
27300 return f.write_str(")");
27301 }
27302 };
27303 match attr {
27304 QfqAttrs::Weight(val) => fmt.field("Weight", &val),
27305 QfqAttrs::Lmax(val) => fmt.field("Lmax", &val),
27306 };
27307 }
27308 fmt.finish()
27309 }
27310}
27311impl IterableQfqAttrs<'_> {
27312 pub fn lookup_attr(
27313 &self,
27314 offset: usize,
27315 missing_type: Option<u16>,
27316 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27317 let mut stack = Vec::new();
27318 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
27319 if missing_type.is_some() && cur == offset {
27320 stack.push(("QfqAttrs", offset));
27321 return (
27322 stack,
27323 missing_type.and_then(|t| QfqAttrs::attr_from_type(t)),
27324 );
27325 }
27326 if cur > offset || cur + self.buf.len() < offset {
27327 return (stack, None);
27328 }
27329 let mut attrs = self.clone();
27330 let mut last_off = cur + attrs.pos;
27331 while let Some(attr) = attrs.next() {
27332 let Ok(attr) = attr else { break };
27333 match attr {
27334 QfqAttrs::Weight(val) => {
27335 if last_off == offset {
27336 stack.push(("Weight", last_off));
27337 break;
27338 }
27339 }
27340 QfqAttrs::Lmax(val) => {
27341 if last_off == offset {
27342 stack.push(("Lmax", last_off));
27343 break;
27344 }
27345 }
27346 _ => {}
27347 };
27348 last_off = cur + attrs.pos;
27349 }
27350 if !stack.is_empty() {
27351 stack.push(("QfqAttrs", cur));
27352 }
27353 (stack, None)
27354 }
27355}
27356#[derive(Clone)]
27357pub enum RedAttrs<'a> {
27358 Parms(TcRedQopt),
27359 Stab(&'a [u8]),
27360 MaxP(u32),
27361 Flags(BuiltinBitfield32),
27362 EarlyDropBlock(u32),
27363 MarkBlock(u32),
27364}
27365impl<'a> IterableRedAttrs<'a> {
27366 pub fn get_parms(&self) -> Result<TcRedQopt, ErrorContext> {
27367 let mut iter = self.clone();
27368 iter.pos = 0;
27369 for attr in iter {
27370 if let Ok(RedAttrs::Parms(val)) = attr {
27371 return Ok(val);
27372 }
27373 }
27374 Err(ErrorContext::new_missing(
27375 "RedAttrs",
27376 "Parms",
27377 self.orig_loc,
27378 self.buf.as_ptr() as usize,
27379 ))
27380 }
27381 pub fn get_stab(&self) -> Result<&'a [u8], ErrorContext> {
27382 let mut iter = self.clone();
27383 iter.pos = 0;
27384 for attr in iter {
27385 if let Ok(RedAttrs::Stab(val)) = attr {
27386 return Ok(val);
27387 }
27388 }
27389 Err(ErrorContext::new_missing(
27390 "RedAttrs",
27391 "Stab",
27392 self.orig_loc,
27393 self.buf.as_ptr() as usize,
27394 ))
27395 }
27396 pub fn get_max_p(&self) -> Result<u32, ErrorContext> {
27397 let mut iter = self.clone();
27398 iter.pos = 0;
27399 for attr in iter {
27400 if let Ok(RedAttrs::MaxP(val)) = attr {
27401 return Ok(val);
27402 }
27403 }
27404 Err(ErrorContext::new_missing(
27405 "RedAttrs",
27406 "MaxP",
27407 self.orig_loc,
27408 self.buf.as_ptr() as usize,
27409 ))
27410 }
27411 pub fn get_flags(&self) -> Result<BuiltinBitfield32, ErrorContext> {
27412 let mut iter = self.clone();
27413 iter.pos = 0;
27414 for attr in iter {
27415 if let Ok(RedAttrs::Flags(val)) = attr {
27416 return Ok(val);
27417 }
27418 }
27419 Err(ErrorContext::new_missing(
27420 "RedAttrs",
27421 "Flags",
27422 self.orig_loc,
27423 self.buf.as_ptr() as usize,
27424 ))
27425 }
27426 pub fn get_early_drop_block(&self) -> Result<u32, ErrorContext> {
27427 let mut iter = self.clone();
27428 iter.pos = 0;
27429 for attr in iter {
27430 if let Ok(RedAttrs::EarlyDropBlock(val)) = attr {
27431 return Ok(val);
27432 }
27433 }
27434 Err(ErrorContext::new_missing(
27435 "RedAttrs",
27436 "EarlyDropBlock",
27437 self.orig_loc,
27438 self.buf.as_ptr() as usize,
27439 ))
27440 }
27441 pub fn get_mark_block(&self) -> Result<u32, ErrorContext> {
27442 let mut iter = self.clone();
27443 iter.pos = 0;
27444 for attr in iter {
27445 if let Ok(RedAttrs::MarkBlock(val)) = attr {
27446 return Ok(val);
27447 }
27448 }
27449 Err(ErrorContext::new_missing(
27450 "RedAttrs",
27451 "MarkBlock",
27452 self.orig_loc,
27453 self.buf.as_ptr() as usize,
27454 ))
27455 }
27456}
27457impl RedAttrs<'_> {
27458 pub fn new<'a>(buf: &'a [u8]) -> IterableRedAttrs<'a> {
27459 IterableRedAttrs::with_loc(buf, buf.as_ptr() as usize)
27460 }
27461 fn attr_from_type(r#type: u16) -> Option<&'static str> {
27462 let res = match r#type {
27463 1u16 => "Parms",
27464 2u16 => "Stab",
27465 3u16 => "MaxP",
27466 4u16 => "Flags",
27467 5u16 => "EarlyDropBlock",
27468 6u16 => "MarkBlock",
27469 _ => return None,
27470 };
27471 Some(res)
27472 }
27473}
27474#[derive(Clone, Copy, Default)]
27475pub struct IterableRedAttrs<'a> {
27476 buf: &'a [u8],
27477 pos: usize,
27478 orig_loc: usize,
27479}
27480impl<'a> IterableRedAttrs<'a> {
27481 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
27482 Self {
27483 buf,
27484 pos: 0,
27485 orig_loc,
27486 }
27487 }
27488 pub fn get_buf(&self) -> &'a [u8] {
27489 self.buf
27490 }
27491}
27492impl<'a> Iterator for IterableRedAttrs<'a> {
27493 type Item = Result<RedAttrs<'a>, ErrorContext>;
27494 fn next(&mut self) -> Option<Self::Item> {
27495 let mut pos;
27496 let mut r#type;
27497 loop {
27498 pos = self.pos;
27499 r#type = None;
27500 if self.buf.len() == self.pos {
27501 return None;
27502 }
27503 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
27504 self.pos = self.buf.len();
27505 break;
27506 };
27507 r#type = Some(header.r#type);
27508 let res = match header.r#type {
27509 1u16 => RedAttrs::Parms({
27510 let res = Some(TcRedQopt::new_from_zeroed(next));
27511 let Some(val) = res else { break };
27512 val
27513 }),
27514 2u16 => RedAttrs::Stab({
27515 let res = Some(next);
27516 let Some(val) = res else { break };
27517 val
27518 }),
27519 3u16 => RedAttrs::MaxP({
27520 let res = parse_u32(next);
27521 let Some(val) = res else { break };
27522 val
27523 }),
27524 4u16 => RedAttrs::Flags({
27525 let res = BuiltinBitfield32::new_from_slice(next);
27526 let Some(val) = res else { break };
27527 val
27528 }),
27529 5u16 => RedAttrs::EarlyDropBlock({
27530 let res = parse_u32(next);
27531 let Some(val) = res else { break };
27532 val
27533 }),
27534 6u16 => RedAttrs::MarkBlock({
27535 let res = parse_u32(next);
27536 let Some(val) = res else { break };
27537 val
27538 }),
27539 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
27540 n => continue,
27541 };
27542 return Some(Ok(res));
27543 }
27544 Some(Err(ErrorContext::new(
27545 "RedAttrs",
27546 r#type.and_then(|t| RedAttrs::attr_from_type(t)),
27547 self.orig_loc,
27548 self.buf.as_ptr().wrapping_add(pos) as usize,
27549 )))
27550 }
27551}
27552impl<'a> std::fmt::Debug for IterableRedAttrs<'_> {
27553 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27554 let mut fmt = f.debug_struct("RedAttrs");
27555 for attr in self.clone() {
27556 let attr = match attr {
27557 Ok(a) => a,
27558 Err(err) => {
27559 fmt.finish()?;
27560 f.write_str("Err(")?;
27561 err.fmt(f)?;
27562 return f.write_str(")");
27563 }
27564 };
27565 match attr {
27566 RedAttrs::Parms(val) => fmt.field("Parms", &val),
27567 RedAttrs::Stab(val) => fmt.field("Stab", &val),
27568 RedAttrs::MaxP(val) => fmt.field("MaxP", &val),
27569 RedAttrs::Flags(val) => fmt.field("Flags", &val),
27570 RedAttrs::EarlyDropBlock(val) => fmt.field("EarlyDropBlock", &val),
27571 RedAttrs::MarkBlock(val) => fmt.field("MarkBlock", &val),
27572 };
27573 }
27574 fmt.finish()
27575 }
27576}
27577impl IterableRedAttrs<'_> {
27578 pub fn lookup_attr(
27579 &self,
27580 offset: usize,
27581 missing_type: Option<u16>,
27582 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27583 let mut stack = Vec::new();
27584 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
27585 if missing_type.is_some() && cur == offset {
27586 stack.push(("RedAttrs", offset));
27587 return (
27588 stack,
27589 missing_type.and_then(|t| RedAttrs::attr_from_type(t)),
27590 );
27591 }
27592 if cur > offset || cur + self.buf.len() < offset {
27593 return (stack, None);
27594 }
27595 let mut attrs = self.clone();
27596 let mut last_off = cur + attrs.pos;
27597 while let Some(attr) = attrs.next() {
27598 let Ok(attr) = attr else { break };
27599 match attr {
27600 RedAttrs::Parms(val) => {
27601 if last_off == offset {
27602 stack.push(("Parms", last_off));
27603 break;
27604 }
27605 }
27606 RedAttrs::Stab(val) => {
27607 if last_off == offset {
27608 stack.push(("Stab", last_off));
27609 break;
27610 }
27611 }
27612 RedAttrs::MaxP(val) => {
27613 if last_off == offset {
27614 stack.push(("MaxP", last_off));
27615 break;
27616 }
27617 }
27618 RedAttrs::Flags(val) => {
27619 if last_off == offset {
27620 stack.push(("Flags", last_off));
27621 break;
27622 }
27623 }
27624 RedAttrs::EarlyDropBlock(val) => {
27625 if last_off == offset {
27626 stack.push(("EarlyDropBlock", last_off));
27627 break;
27628 }
27629 }
27630 RedAttrs::MarkBlock(val) => {
27631 if last_off == offset {
27632 stack.push(("MarkBlock", last_off));
27633 break;
27634 }
27635 }
27636 _ => {}
27637 };
27638 last_off = cur + attrs.pos;
27639 }
27640 if !stack.is_empty() {
27641 stack.push(("RedAttrs", cur));
27642 }
27643 (stack, None)
27644 }
27645}
27646#[derive(Clone)]
27647pub enum RouteAttrs<'a> {
27648 Classid(u32),
27649 To(u32),
27650 From(u32),
27651 Iif(u32),
27652 Police(IterablePoliceAttrs<'a>),
27653 Act(IterableArrayActAttrs<'a>),
27654}
27655impl<'a> IterableRouteAttrs<'a> {
27656 pub fn get_classid(&self) -> Result<u32, ErrorContext> {
27657 let mut iter = self.clone();
27658 iter.pos = 0;
27659 for attr in iter {
27660 if let Ok(RouteAttrs::Classid(val)) = attr {
27661 return Ok(val);
27662 }
27663 }
27664 Err(ErrorContext::new_missing(
27665 "RouteAttrs",
27666 "Classid",
27667 self.orig_loc,
27668 self.buf.as_ptr() as usize,
27669 ))
27670 }
27671 pub fn get_to(&self) -> Result<u32, ErrorContext> {
27672 let mut iter = self.clone();
27673 iter.pos = 0;
27674 for attr in iter {
27675 if let Ok(RouteAttrs::To(val)) = attr {
27676 return Ok(val);
27677 }
27678 }
27679 Err(ErrorContext::new_missing(
27680 "RouteAttrs",
27681 "To",
27682 self.orig_loc,
27683 self.buf.as_ptr() as usize,
27684 ))
27685 }
27686 pub fn get_from(&self) -> Result<u32, ErrorContext> {
27687 let mut iter = self.clone();
27688 iter.pos = 0;
27689 for attr in iter {
27690 if let Ok(RouteAttrs::From(val)) = attr {
27691 return Ok(val);
27692 }
27693 }
27694 Err(ErrorContext::new_missing(
27695 "RouteAttrs",
27696 "From",
27697 self.orig_loc,
27698 self.buf.as_ptr() as usize,
27699 ))
27700 }
27701 pub fn get_iif(&self) -> Result<u32, ErrorContext> {
27702 let mut iter = self.clone();
27703 iter.pos = 0;
27704 for attr in iter {
27705 if let Ok(RouteAttrs::Iif(val)) = attr {
27706 return Ok(val);
27707 }
27708 }
27709 Err(ErrorContext::new_missing(
27710 "RouteAttrs",
27711 "Iif",
27712 self.orig_loc,
27713 self.buf.as_ptr() as usize,
27714 ))
27715 }
27716 pub fn get_police(&self) -> Result<IterablePoliceAttrs<'a>, ErrorContext> {
27717 let mut iter = self.clone();
27718 iter.pos = 0;
27719 for attr in iter {
27720 if let Ok(RouteAttrs::Police(val)) = attr {
27721 return Ok(val);
27722 }
27723 }
27724 Err(ErrorContext::new_missing(
27725 "RouteAttrs",
27726 "Police",
27727 self.orig_loc,
27728 self.buf.as_ptr() as usize,
27729 ))
27730 }
27731 pub fn get_act(
27732 &self,
27733 ) -> Result<ArrayIterable<IterableArrayActAttrs<'a>, IterableActAttrs<'a>>, ErrorContext> {
27734 for attr in self.clone() {
27735 if let Ok(RouteAttrs::Act(val)) = attr {
27736 return Ok(ArrayIterable::new(val));
27737 }
27738 }
27739 Err(ErrorContext::new_missing(
27740 "RouteAttrs",
27741 "Act",
27742 self.orig_loc,
27743 self.buf.as_ptr() as usize,
27744 ))
27745 }
27746}
27747impl RouteAttrs<'_> {
27748 pub fn new<'a>(buf: &'a [u8]) -> IterableRouteAttrs<'a> {
27749 IterableRouteAttrs::with_loc(buf, buf.as_ptr() as usize)
27750 }
27751 fn attr_from_type(r#type: u16) -> Option<&'static str> {
27752 let res = match r#type {
27753 1u16 => "Classid",
27754 2u16 => "To",
27755 3u16 => "From",
27756 4u16 => "Iif",
27757 5u16 => "Police",
27758 6u16 => "Act",
27759 _ => return None,
27760 };
27761 Some(res)
27762 }
27763}
27764#[derive(Clone, Copy, Default)]
27765pub struct IterableRouteAttrs<'a> {
27766 buf: &'a [u8],
27767 pos: usize,
27768 orig_loc: usize,
27769}
27770impl<'a> IterableRouteAttrs<'a> {
27771 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
27772 Self {
27773 buf,
27774 pos: 0,
27775 orig_loc,
27776 }
27777 }
27778 pub fn get_buf(&self) -> &'a [u8] {
27779 self.buf
27780 }
27781}
27782impl<'a> Iterator for IterableRouteAttrs<'a> {
27783 type Item = Result<RouteAttrs<'a>, ErrorContext>;
27784 fn next(&mut self) -> Option<Self::Item> {
27785 let mut pos;
27786 let mut r#type;
27787 loop {
27788 pos = self.pos;
27789 r#type = None;
27790 if self.buf.len() == self.pos {
27791 return None;
27792 }
27793 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
27794 self.pos = self.buf.len();
27795 break;
27796 };
27797 r#type = Some(header.r#type);
27798 let res = match header.r#type {
27799 1u16 => RouteAttrs::Classid({
27800 let res = parse_u32(next);
27801 let Some(val) = res else { break };
27802 val
27803 }),
27804 2u16 => RouteAttrs::To({
27805 let res = parse_u32(next);
27806 let Some(val) = res else { break };
27807 val
27808 }),
27809 3u16 => RouteAttrs::From({
27810 let res = parse_u32(next);
27811 let Some(val) = res else { break };
27812 val
27813 }),
27814 4u16 => RouteAttrs::Iif({
27815 let res = parse_u32(next);
27816 let Some(val) = res else { break };
27817 val
27818 }),
27819 5u16 => RouteAttrs::Police({
27820 let res = Some(IterablePoliceAttrs::with_loc(next, self.orig_loc));
27821 let Some(val) = res else { break };
27822 val
27823 }),
27824 6u16 => RouteAttrs::Act({
27825 let res = Some(IterableArrayActAttrs::with_loc(next, self.orig_loc));
27826 let Some(val) = res else { break };
27827 val
27828 }),
27829 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
27830 n => continue,
27831 };
27832 return Some(Ok(res));
27833 }
27834 Some(Err(ErrorContext::new(
27835 "RouteAttrs",
27836 r#type.and_then(|t| RouteAttrs::attr_from_type(t)),
27837 self.orig_loc,
27838 self.buf.as_ptr().wrapping_add(pos) as usize,
27839 )))
27840 }
27841}
27842impl<'a> std::fmt::Debug for IterableRouteAttrs<'_> {
27843 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27844 let mut fmt = f.debug_struct("RouteAttrs");
27845 for attr in self.clone() {
27846 let attr = match attr {
27847 Ok(a) => a,
27848 Err(err) => {
27849 fmt.finish()?;
27850 f.write_str("Err(")?;
27851 err.fmt(f)?;
27852 return f.write_str(")");
27853 }
27854 };
27855 match attr {
27856 RouteAttrs::Classid(val) => fmt.field("Classid", &val),
27857 RouteAttrs::To(val) => fmt.field("To", &val),
27858 RouteAttrs::From(val) => fmt.field("From", &val),
27859 RouteAttrs::Iif(val) => fmt.field("Iif", &val),
27860 RouteAttrs::Police(val) => fmt.field("Police", &val),
27861 RouteAttrs::Act(val) => fmt.field("Act", &val),
27862 };
27863 }
27864 fmt.finish()
27865 }
27866}
27867impl IterableRouteAttrs<'_> {
27868 pub fn lookup_attr(
27869 &self,
27870 offset: usize,
27871 missing_type: Option<u16>,
27872 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27873 let mut stack = Vec::new();
27874 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
27875 if missing_type.is_some() && cur == offset {
27876 stack.push(("RouteAttrs", offset));
27877 return (
27878 stack,
27879 missing_type.and_then(|t| RouteAttrs::attr_from_type(t)),
27880 );
27881 }
27882 if cur > offset || cur + self.buf.len() < offset {
27883 return (stack, None);
27884 }
27885 let mut attrs = self.clone();
27886 let mut last_off = cur + attrs.pos;
27887 let mut missing = None;
27888 while let Some(attr) = attrs.next() {
27889 let Ok(attr) = attr else { break };
27890 match attr {
27891 RouteAttrs::Classid(val) => {
27892 if last_off == offset {
27893 stack.push(("Classid", last_off));
27894 break;
27895 }
27896 }
27897 RouteAttrs::To(val) => {
27898 if last_off == offset {
27899 stack.push(("To", last_off));
27900 break;
27901 }
27902 }
27903 RouteAttrs::From(val) => {
27904 if last_off == offset {
27905 stack.push(("From", last_off));
27906 break;
27907 }
27908 }
27909 RouteAttrs::Iif(val) => {
27910 if last_off == offset {
27911 stack.push(("Iif", last_off));
27912 break;
27913 }
27914 }
27915 RouteAttrs::Police(val) => {
27916 (stack, missing) = val.lookup_attr(offset, missing_type);
27917 if !stack.is_empty() {
27918 break;
27919 }
27920 }
27921 RouteAttrs::Act(val) => {
27922 for entry in val {
27923 let Ok(attr) = entry else { break };
27924 (stack, missing) = attr.lookup_attr(offset, missing_type);
27925 if !stack.is_empty() {
27926 break;
27927 }
27928 }
27929 if !stack.is_empty() {
27930 stack.push(("Act", last_off));
27931 break;
27932 }
27933 }
27934 _ => {}
27935 };
27936 last_off = cur + attrs.pos;
27937 }
27938 if !stack.is_empty() {
27939 stack.push(("RouteAttrs", cur));
27940 }
27941 (stack, missing)
27942 }
27943}
27944#[derive(Clone)]
27945pub enum TaprioAttrs<'a> {
27946 Priomap(TcMqprioQopt),
27947 SchedEntryList(IterableTaprioSchedEntryList<'a>),
27948 SchedBaseTime(i64),
27949 SchedSingleEntry(IterableTaprioSchedEntry<'a>),
27950 SchedClockid(i32),
27951 Pad(&'a [u8]),
27952 AdminSched(&'a [u8]),
27953 SchedCycleTime(i64),
27954 SchedCycleTimeExtension(i64),
27955 Flags(u32),
27956 TxtimeDelay(u32),
27957 TcEntry(IterableTaprioTcEntryAttrs<'a>),
27958}
27959impl<'a> IterableTaprioAttrs<'a> {
27960 pub fn get_priomap(&self) -> Result<TcMqprioQopt, ErrorContext> {
27961 let mut iter = self.clone();
27962 iter.pos = 0;
27963 for attr in iter {
27964 if let Ok(TaprioAttrs::Priomap(val)) = attr {
27965 return Ok(val);
27966 }
27967 }
27968 Err(ErrorContext::new_missing(
27969 "TaprioAttrs",
27970 "Priomap",
27971 self.orig_loc,
27972 self.buf.as_ptr() as usize,
27973 ))
27974 }
27975 pub fn get_sched_entry_list(&self) -> Result<IterableTaprioSchedEntryList<'a>, ErrorContext> {
27976 let mut iter = self.clone();
27977 iter.pos = 0;
27978 for attr in iter {
27979 if let Ok(TaprioAttrs::SchedEntryList(val)) = attr {
27980 return Ok(val);
27981 }
27982 }
27983 Err(ErrorContext::new_missing(
27984 "TaprioAttrs",
27985 "SchedEntryList",
27986 self.orig_loc,
27987 self.buf.as_ptr() as usize,
27988 ))
27989 }
27990 pub fn get_sched_base_time(&self) -> Result<i64, ErrorContext> {
27991 let mut iter = self.clone();
27992 iter.pos = 0;
27993 for attr in iter {
27994 if let Ok(TaprioAttrs::SchedBaseTime(val)) = attr {
27995 return Ok(val);
27996 }
27997 }
27998 Err(ErrorContext::new_missing(
27999 "TaprioAttrs",
28000 "SchedBaseTime",
28001 self.orig_loc,
28002 self.buf.as_ptr() as usize,
28003 ))
28004 }
28005 pub fn get_sched_single_entry(&self) -> Result<IterableTaprioSchedEntry<'a>, ErrorContext> {
28006 let mut iter = self.clone();
28007 iter.pos = 0;
28008 for attr in iter {
28009 if let Ok(TaprioAttrs::SchedSingleEntry(val)) = attr {
28010 return Ok(val);
28011 }
28012 }
28013 Err(ErrorContext::new_missing(
28014 "TaprioAttrs",
28015 "SchedSingleEntry",
28016 self.orig_loc,
28017 self.buf.as_ptr() as usize,
28018 ))
28019 }
28020 pub fn get_sched_clockid(&self) -> Result<i32, ErrorContext> {
28021 let mut iter = self.clone();
28022 iter.pos = 0;
28023 for attr in iter {
28024 if let Ok(TaprioAttrs::SchedClockid(val)) = attr {
28025 return Ok(val);
28026 }
28027 }
28028 Err(ErrorContext::new_missing(
28029 "TaprioAttrs",
28030 "SchedClockid",
28031 self.orig_loc,
28032 self.buf.as_ptr() as usize,
28033 ))
28034 }
28035 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
28036 let mut iter = self.clone();
28037 iter.pos = 0;
28038 for attr in iter {
28039 if let Ok(TaprioAttrs::Pad(val)) = attr {
28040 return Ok(val);
28041 }
28042 }
28043 Err(ErrorContext::new_missing(
28044 "TaprioAttrs",
28045 "Pad",
28046 self.orig_loc,
28047 self.buf.as_ptr() as usize,
28048 ))
28049 }
28050 pub fn get_admin_sched(&self) -> Result<&'a [u8], ErrorContext> {
28051 let mut iter = self.clone();
28052 iter.pos = 0;
28053 for attr in iter {
28054 if let Ok(TaprioAttrs::AdminSched(val)) = attr {
28055 return Ok(val);
28056 }
28057 }
28058 Err(ErrorContext::new_missing(
28059 "TaprioAttrs",
28060 "AdminSched",
28061 self.orig_loc,
28062 self.buf.as_ptr() as usize,
28063 ))
28064 }
28065 pub fn get_sched_cycle_time(&self) -> Result<i64, ErrorContext> {
28066 let mut iter = self.clone();
28067 iter.pos = 0;
28068 for attr in iter {
28069 if let Ok(TaprioAttrs::SchedCycleTime(val)) = attr {
28070 return Ok(val);
28071 }
28072 }
28073 Err(ErrorContext::new_missing(
28074 "TaprioAttrs",
28075 "SchedCycleTime",
28076 self.orig_loc,
28077 self.buf.as_ptr() as usize,
28078 ))
28079 }
28080 pub fn get_sched_cycle_time_extension(&self) -> Result<i64, ErrorContext> {
28081 let mut iter = self.clone();
28082 iter.pos = 0;
28083 for attr in iter {
28084 if let Ok(TaprioAttrs::SchedCycleTimeExtension(val)) = attr {
28085 return Ok(val);
28086 }
28087 }
28088 Err(ErrorContext::new_missing(
28089 "TaprioAttrs",
28090 "SchedCycleTimeExtension",
28091 self.orig_loc,
28092 self.buf.as_ptr() as usize,
28093 ))
28094 }
28095 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
28096 let mut iter = self.clone();
28097 iter.pos = 0;
28098 for attr in iter {
28099 if let Ok(TaprioAttrs::Flags(val)) = attr {
28100 return Ok(val);
28101 }
28102 }
28103 Err(ErrorContext::new_missing(
28104 "TaprioAttrs",
28105 "Flags",
28106 self.orig_loc,
28107 self.buf.as_ptr() as usize,
28108 ))
28109 }
28110 pub fn get_txtime_delay(&self) -> Result<u32, ErrorContext> {
28111 let mut iter = self.clone();
28112 iter.pos = 0;
28113 for attr in iter {
28114 if let Ok(TaprioAttrs::TxtimeDelay(val)) = attr {
28115 return Ok(val);
28116 }
28117 }
28118 Err(ErrorContext::new_missing(
28119 "TaprioAttrs",
28120 "TxtimeDelay",
28121 self.orig_loc,
28122 self.buf.as_ptr() as usize,
28123 ))
28124 }
28125 pub fn get_tc_entry(&self) -> Result<IterableTaprioTcEntryAttrs<'a>, ErrorContext> {
28126 let mut iter = self.clone();
28127 iter.pos = 0;
28128 for attr in iter {
28129 if let Ok(TaprioAttrs::TcEntry(val)) = attr {
28130 return Ok(val);
28131 }
28132 }
28133 Err(ErrorContext::new_missing(
28134 "TaprioAttrs",
28135 "TcEntry",
28136 self.orig_loc,
28137 self.buf.as_ptr() as usize,
28138 ))
28139 }
28140}
28141impl TaprioAttrs<'_> {
28142 pub fn new<'a>(buf: &'a [u8]) -> IterableTaprioAttrs<'a> {
28143 IterableTaprioAttrs::with_loc(buf, buf.as_ptr() as usize)
28144 }
28145 fn attr_from_type(r#type: u16) -> Option<&'static str> {
28146 let res = match r#type {
28147 1u16 => "Priomap",
28148 2u16 => "SchedEntryList",
28149 3u16 => "SchedBaseTime",
28150 4u16 => "SchedSingleEntry",
28151 5u16 => "SchedClockid",
28152 6u16 => "Pad",
28153 7u16 => "AdminSched",
28154 8u16 => "SchedCycleTime",
28155 9u16 => "SchedCycleTimeExtension",
28156 10u16 => "Flags",
28157 11u16 => "TxtimeDelay",
28158 12u16 => "TcEntry",
28159 _ => return None,
28160 };
28161 Some(res)
28162 }
28163}
28164#[derive(Clone, Copy, Default)]
28165pub struct IterableTaprioAttrs<'a> {
28166 buf: &'a [u8],
28167 pos: usize,
28168 orig_loc: usize,
28169}
28170impl<'a> IterableTaprioAttrs<'a> {
28171 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
28172 Self {
28173 buf,
28174 pos: 0,
28175 orig_loc,
28176 }
28177 }
28178 pub fn get_buf(&self) -> &'a [u8] {
28179 self.buf
28180 }
28181}
28182impl<'a> Iterator for IterableTaprioAttrs<'a> {
28183 type Item = Result<TaprioAttrs<'a>, ErrorContext>;
28184 fn next(&mut self) -> Option<Self::Item> {
28185 let mut pos;
28186 let mut r#type;
28187 loop {
28188 pos = self.pos;
28189 r#type = None;
28190 if self.buf.len() == self.pos {
28191 return None;
28192 }
28193 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
28194 self.pos = self.buf.len();
28195 break;
28196 };
28197 r#type = Some(header.r#type);
28198 let res = match header.r#type {
28199 1u16 => TaprioAttrs::Priomap({
28200 let res = Some(TcMqprioQopt::new_from_zeroed(next));
28201 let Some(val) = res else { break };
28202 val
28203 }),
28204 2u16 => TaprioAttrs::SchedEntryList({
28205 let res = Some(IterableTaprioSchedEntryList::with_loc(next, self.orig_loc));
28206 let Some(val) = res else { break };
28207 val
28208 }),
28209 3u16 => TaprioAttrs::SchedBaseTime({
28210 let res = parse_i64(next);
28211 let Some(val) = res else { break };
28212 val
28213 }),
28214 4u16 => TaprioAttrs::SchedSingleEntry({
28215 let res = Some(IterableTaprioSchedEntry::with_loc(next, self.orig_loc));
28216 let Some(val) = res else { break };
28217 val
28218 }),
28219 5u16 => TaprioAttrs::SchedClockid({
28220 let res = parse_i32(next);
28221 let Some(val) = res else { break };
28222 val
28223 }),
28224 6u16 => TaprioAttrs::Pad({
28225 let res = Some(next);
28226 let Some(val) = res else { break };
28227 val
28228 }),
28229 7u16 => TaprioAttrs::AdminSched({
28230 let res = Some(next);
28231 let Some(val) = res else { break };
28232 val
28233 }),
28234 8u16 => TaprioAttrs::SchedCycleTime({
28235 let res = parse_i64(next);
28236 let Some(val) = res else { break };
28237 val
28238 }),
28239 9u16 => TaprioAttrs::SchedCycleTimeExtension({
28240 let res = parse_i64(next);
28241 let Some(val) = res else { break };
28242 val
28243 }),
28244 10u16 => TaprioAttrs::Flags({
28245 let res = parse_u32(next);
28246 let Some(val) = res else { break };
28247 val
28248 }),
28249 11u16 => TaprioAttrs::TxtimeDelay({
28250 let res = parse_u32(next);
28251 let Some(val) = res else { break };
28252 val
28253 }),
28254 12u16 => TaprioAttrs::TcEntry({
28255 let res = Some(IterableTaprioTcEntryAttrs::with_loc(next, self.orig_loc));
28256 let Some(val) = res else { break };
28257 val
28258 }),
28259 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
28260 n => continue,
28261 };
28262 return Some(Ok(res));
28263 }
28264 Some(Err(ErrorContext::new(
28265 "TaprioAttrs",
28266 r#type.and_then(|t| TaprioAttrs::attr_from_type(t)),
28267 self.orig_loc,
28268 self.buf.as_ptr().wrapping_add(pos) as usize,
28269 )))
28270 }
28271}
28272impl<'a> std::fmt::Debug for IterableTaprioAttrs<'_> {
28273 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28274 let mut fmt = f.debug_struct("TaprioAttrs");
28275 for attr in self.clone() {
28276 let attr = match attr {
28277 Ok(a) => a,
28278 Err(err) => {
28279 fmt.finish()?;
28280 f.write_str("Err(")?;
28281 err.fmt(f)?;
28282 return f.write_str(")");
28283 }
28284 };
28285 match attr {
28286 TaprioAttrs::Priomap(val) => fmt.field("Priomap", &val),
28287 TaprioAttrs::SchedEntryList(val) => fmt.field("SchedEntryList", &val),
28288 TaprioAttrs::SchedBaseTime(val) => fmt.field("SchedBaseTime", &val),
28289 TaprioAttrs::SchedSingleEntry(val) => fmt.field("SchedSingleEntry", &val),
28290 TaprioAttrs::SchedClockid(val) => fmt.field("SchedClockid", &val),
28291 TaprioAttrs::Pad(val) => fmt.field("Pad", &val),
28292 TaprioAttrs::AdminSched(val) => fmt.field("AdminSched", &val),
28293 TaprioAttrs::SchedCycleTime(val) => fmt.field("SchedCycleTime", &val),
28294 TaprioAttrs::SchedCycleTimeExtension(val) => {
28295 fmt.field("SchedCycleTimeExtension", &val)
28296 }
28297 TaprioAttrs::Flags(val) => fmt.field("Flags", &val),
28298 TaprioAttrs::TxtimeDelay(val) => fmt.field("TxtimeDelay", &val),
28299 TaprioAttrs::TcEntry(val) => fmt.field("TcEntry", &val),
28300 };
28301 }
28302 fmt.finish()
28303 }
28304}
28305impl IterableTaprioAttrs<'_> {
28306 pub fn lookup_attr(
28307 &self,
28308 offset: usize,
28309 missing_type: Option<u16>,
28310 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28311 let mut stack = Vec::new();
28312 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
28313 if missing_type.is_some() && cur == offset {
28314 stack.push(("TaprioAttrs", offset));
28315 return (
28316 stack,
28317 missing_type.and_then(|t| TaprioAttrs::attr_from_type(t)),
28318 );
28319 }
28320 if cur > offset || cur + self.buf.len() < offset {
28321 return (stack, None);
28322 }
28323 let mut attrs = self.clone();
28324 let mut last_off = cur + attrs.pos;
28325 let mut missing = None;
28326 while let Some(attr) = attrs.next() {
28327 let Ok(attr) = attr else { break };
28328 match attr {
28329 TaprioAttrs::Priomap(val) => {
28330 if last_off == offset {
28331 stack.push(("Priomap", last_off));
28332 break;
28333 }
28334 }
28335 TaprioAttrs::SchedEntryList(val) => {
28336 (stack, missing) = val.lookup_attr(offset, missing_type);
28337 if !stack.is_empty() {
28338 break;
28339 }
28340 }
28341 TaprioAttrs::SchedBaseTime(val) => {
28342 if last_off == offset {
28343 stack.push(("SchedBaseTime", last_off));
28344 break;
28345 }
28346 }
28347 TaprioAttrs::SchedSingleEntry(val) => {
28348 (stack, missing) = val.lookup_attr(offset, missing_type);
28349 if !stack.is_empty() {
28350 break;
28351 }
28352 }
28353 TaprioAttrs::SchedClockid(val) => {
28354 if last_off == offset {
28355 stack.push(("SchedClockid", last_off));
28356 break;
28357 }
28358 }
28359 TaprioAttrs::Pad(val) => {
28360 if last_off == offset {
28361 stack.push(("Pad", last_off));
28362 break;
28363 }
28364 }
28365 TaprioAttrs::AdminSched(val) => {
28366 if last_off == offset {
28367 stack.push(("AdminSched", last_off));
28368 break;
28369 }
28370 }
28371 TaprioAttrs::SchedCycleTime(val) => {
28372 if last_off == offset {
28373 stack.push(("SchedCycleTime", last_off));
28374 break;
28375 }
28376 }
28377 TaprioAttrs::SchedCycleTimeExtension(val) => {
28378 if last_off == offset {
28379 stack.push(("SchedCycleTimeExtension", last_off));
28380 break;
28381 }
28382 }
28383 TaprioAttrs::Flags(val) => {
28384 if last_off == offset {
28385 stack.push(("Flags", last_off));
28386 break;
28387 }
28388 }
28389 TaprioAttrs::TxtimeDelay(val) => {
28390 if last_off == offset {
28391 stack.push(("TxtimeDelay", last_off));
28392 break;
28393 }
28394 }
28395 TaprioAttrs::TcEntry(val) => {
28396 (stack, missing) = val.lookup_attr(offset, missing_type);
28397 if !stack.is_empty() {
28398 break;
28399 }
28400 }
28401 _ => {}
28402 };
28403 last_off = cur + attrs.pos;
28404 }
28405 if !stack.is_empty() {
28406 stack.push(("TaprioAttrs", cur));
28407 }
28408 (stack, missing)
28409 }
28410}
28411#[derive(Clone)]
28412pub enum TaprioSchedEntryList<'a> {
28413 #[doc = "Attribute may repeat multiple times (treat it as array)"]
28414 Entry(IterableTaprioSchedEntry<'a>),
28415}
28416impl<'a> IterableTaprioSchedEntryList<'a> {
28417 #[doc = "Attribute may repeat multiple times (treat it as array)"]
28418 pub fn get_entry(
28419 &self,
28420 ) -> MultiAttrIterable<Self, TaprioSchedEntryList<'a>, IterableTaprioSchedEntry<'a>> {
28421 MultiAttrIterable::new(self.clone(), |variant| {
28422 if let TaprioSchedEntryList::Entry(val) = variant {
28423 Some(val)
28424 } else {
28425 None
28426 }
28427 })
28428 }
28429}
28430impl TaprioSchedEntryList<'_> {
28431 pub fn new<'a>(buf: &'a [u8]) -> IterableTaprioSchedEntryList<'a> {
28432 IterableTaprioSchedEntryList::with_loc(buf, buf.as_ptr() as usize)
28433 }
28434 fn attr_from_type(r#type: u16) -> Option<&'static str> {
28435 let res = match r#type {
28436 1u16 => "Entry",
28437 _ => return None,
28438 };
28439 Some(res)
28440 }
28441}
28442#[derive(Clone, Copy, Default)]
28443pub struct IterableTaprioSchedEntryList<'a> {
28444 buf: &'a [u8],
28445 pos: usize,
28446 orig_loc: usize,
28447}
28448impl<'a> IterableTaprioSchedEntryList<'a> {
28449 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
28450 Self {
28451 buf,
28452 pos: 0,
28453 orig_loc,
28454 }
28455 }
28456 pub fn get_buf(&self) -> &'a [u8] {
28457 self.buf
28458 }
28459}
28460impl<'a> Iterator for IterableTaprioSchedEntryList<'a> {
28461 type Item = Result<TaprioSchedEntryList<'a>, ErrorContext>;
28462 fn next(&mut self) -> Option<Self::Item> {
28463 let mut pos;
28464 let mut r#type;
28465 loop {
28466 pos = self.pos;
28467 r#type = None;
28468 if self.buf.len() == self.pos {
28469 return None;
28470 }
28471 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
28472 self.pos = self.buf.len();
28473 break;
28474 };
28475 r#type = Some(header.r#type);
28476 let res = match header.r#type {
28477 1u16 => TaprioSchedEntryList::Entry({
28478 let res = Some(IterableTaprioSchedEntry::with_loc(next, self.orig_loc));
28479 let Some(val) = res else { break };
28480 val
28481 }),
28482 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
28483 n => continue,
28484 };
28485 return Some(Ok(res));
28486 }
28487 Some(Err(ErrorContext::new(
28488 "TaprioSchedEntryList",
28489 r#type.and_then(|t| TaprioSchedEntryList::attr_from_type(t)),
28490 self.orig_loc,
28491 self.buf.as_ptr().wrapping_add(pos) as usize,
28492 )))
28493 }
28494}
28495impl<'a> std::fmt::Debug for IterableTaprioSchedEntryList<'_> {
28496 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28497 let mut fmt = f.debug_struct("TaprioSchedEntryList");
28498 for attr in self.clone() {
28499 let attr = match attr {
28500 Ok(a) => a,
28501 Err(err) => {
28502 fmt.finish()?;
28503 f.write_str("Err(")?;
28504 err.fmt(f)?;
28505 return f.write_str(")");
28506 }
28507 };
28508 match attr {
28509 TaprioSchedEntryList::Entry(val) => fmt.field("Entry", &val),
28510 };
28511 }
28512 fmt.finish()
28513 }
28514}
28515impl IterableTaprioSchedEntryList<'_> {
28516 pub fn lookup_attr(
28517 &self,
28518 offset: usize,
28519 missing_type: Option<u16>,
28520 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28521 let mut stack = Vec::new();
28522 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
28523 if missing_type.is_some() && cur == offset {
28524 stack.push(("TaprioSchedEntryList", offset));
28525 return (
28526 stack,
28527 missing_type.and_then(|t| TaprioSchedEntryList::attr_from_type(t)),
28528 );
28529 }
28530 if cur > offset || cur + self.buf.len() < offset {
28531 return (stack, None);
28532 }
28533 let mut attrs = self.clone();
28534 let mut last_off = cur + attrs.pos;
28535 let mut missing = None;
28536 while let Some(attr) = attrs.next() {
28537 let Ok(attr) = attr else { break };
28538 match attr {
28539 TaprioSchedEntryList::Entry(val) => {
28540 (stack, missing) = val.lookup_attr(offset, missing_type);
28541 if !stack.is_empty() {
28542 break;
28543 }
28544 }
28545 _ => {}
28546 };
28547 last_off = cur + attrs.pos;
28548 }
28549 if !stack.is_empty() {
28550 stack.push(("TaprioSchedEntryList", cur));
28551 }
28552 (stack, missing)
28553 }
28554}
28555#[derive(Clone)]
28556pub enum TaprioSchedEntry {
28557 Index(u32),
28558 Cmd(u8),
28559 GateMask(u32),
28560 Interval(u32),
28561}
28562impl<'a> IterableTaprioSchedEntry<'a> {
28563 pub fn get_index(&self) -> Result<u32, ErrorContext> {
28564 let mut iter = self.clone();
28565 iter.pos = 0;
28566 for attr in iter {
28567 if let Ok(TaprioSchedEntry::Index(val)) = attr {
28568 return Ok(val);
28569 }
28570 }
28571 Err(ErrorContext::new_missing(
28572 "TaprioSchedEntry",
28573 "Index",
28574 self.orig_loc,
28575 self.buf.as_ptr() as usize,
28576 ))
28577 }
28578 pub fn get_cmd(&self) -> Result<u8, ErrorContext> {
28579 let mut iter = self.clone();
28580 iter.pos = 0;
28581 for attr in iter {
28582 if let Ok(TaprioSchedEntry::Cmd(val)) = attr {
28583 return Ok(val);
28584 }
28585 }
28586 Err(ErrorContext::new_missing(
28587 "TaprioSchedEntry",
28588 "Cmd",
28589 self.orig_loc,
28590 self.buf.as_ptr() as usize,
28591 ))
28592 }
28593 pub fn get_gate_mask(&self) -> Result<u32, ErrorContext> {
28594 let mut iter = self.clone();
28595 iter.pos = 0;
28596 for attr in iter {
28597 if let Ok(TaprioSchedEntry::GateMask(val)) = attr {
28598 return Ok(val);
28599 }
28600 }
28601 Err(ErrorContext::new_missing(
28602 "TaprioSchedEntry",
28603 "GateMask",
28604 self.orig_loc,
28605 self.buf.as_ptr() as usize,
28606 ))
28607 }
28608 pub fn get_interval(&self) -> Result<u32, ErrorContext> {
28609 let mut iter = self.clone();
28610 iter.pos = 0;
28611 for attr in iter {
28612 if let Ok(TaprioSchedEntry::Interval(val)) = attr {
28613 return Ok(val);
28614 }
28615 }
28616 Err(ErrorContext::new_missing(
28617 "TaprioSchedEntry",
28618 "Interval",
28619 self.orig_loc,
28620 self.buf.as_ptr() as usize,
28621 ))
28622 }
28623}
28624impl TaprioSchedEntry {
28625 pub fn new<'a>(buf: &'a [u8]) -> IterableTaprioSchedEntry<'a> {
28626 IterableTaprioSchedEntry::with_loc(buf, buf.as_ptr() as usize)
28627 }
28628 fn attr_from_type(r#type: u16) -> Option<&'static str> {
28629 let res = match r#type {
28630 1u16 => "Index",
28631 2u16 => "Cmd",
28632 3u16 => "GateMask",
28633 4u16 => "Interval",
28634 _ => return None,
28635 };
28636 Some(res)
28637 }
28638}
28639#[derive(Clone, Copy, Default)]
28640pub struct IterableTaprioSchedEntry<'a> {
28641 buf: &'a [u8],
28642 pos: usize,
28643 orig_loc: usize,
28644}
28645impl<'a> IterableTaprioSchedEntry<'a> {
28646 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
28647 Self {
28648 buf,
28649 pos: 0,
28650 orig_loc,
28651 }
28652 }
28653 pub fn get_buf(&self) -> &'a [u8] {
28654 self.buf
28655 }
28656}
28657impl<'a> Iterator for IterableTaprioSchedEntry<'a> {
28658 type Item = Result<TaprioSchedEntry, ErrorContext>;
28659 fn next(&mut self) -> Option<Self::Item> {
28660 let mut pos;
28661 let mut r#type;
28662 loop {
28663 pos = self.pos;
28664 r#type = None;
28665 if self.buf.len() == self.pos {
28666 return None;
28667 }
28668 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
28669 self.pos = self.buf.len();
28670 break;
28671 };
28672 r#type = Some(header.r#type);
28673 let res = match header.r#type {
28674 1u16 => TaprioSchedEntry::Index({
28675 let res = parse_u32(next);
28676 let Some(val) = res else { break };
28677 val
28678 }),
28679 2u16 => TaprioSchedEntry::Cmd({
28680 let res = parse_u8(next);
28681 let Some(val) = res else { break };
28682 val
28683 }),
28684 3u16 => TaprioSchedEntry::GateMask({
28685 let res = parse_u32(next);
28686 let Some(val) = res else { break };
28687 val
28688 }),
28689 4u16 => TaprioSchedEntry::Interval({
28690 let res = parse_u32(next);
28691 let Some(val) = res else { break };
28692 val
28693 }),
28694 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
28695 n => continue,
28696 };
28697 return Some(Ok(res));
28698 }
28699 Some(Err(ErrorContext::new(
28700 "TaprioSchedEntry",
28701 r#type.and_then(|t| TaprioSchedEntry::attr_from_type(t)),
28702 self.orig_loc,
28703 self.buf.as_ptr().wrapping_add(pos) as usize,
28704 )))
28705 }
28706}
28707impl std::fmt::Debug for IterableTaprioSchedEntry<'_> {
28708 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28709 let mut fmt = f.debug_struct("TaprioSchedEntry");
28710 for attr in self.clone() {
28711 let attr = match attr {
28712 Ok(a) => a,
28713 Err(err) => {
28714 fmt.finish()?;
28715 f.write_str("Err(")?;
28716 err.fmt(f)?;
28717 return f.write_str(")");
28718 }
28719 };
28720 match attr {
28721 TaprioSchedEntry::Index(val) => fmt.field("Index", &val),
28722 TaprioSchedEntry::Cmd(val) => fmt.field("Cmd", &val),
28723 TaprioSchedEntry::GateMask(val) => fmt.field("GateMask", &val),
28724 TaprioSchedEntry::Interval(val) => fmt.field("Interval", &val),
28725 };
28726 }
28727 fmt.finish()
28728 }
28729}
28730impl IterableTaprioSchedEntry<'_> {
28731 pub fn lookup_attr(
28732 &self,
28733 offset: usize,
28734 missing_type: Option<u16>,
28735 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28736 let mut stack = Vec::new();
28737 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
28738 if missing_type.is_some() && cur == offset {
28739 stack.push(("TaprioSchedEntry", offset));
28740 return (
28741 stack,
28742 missing_type.and_then(|t| TaprioSchedEntry::attr_from_type(t)),
28743 );
28744 }
28745 if cur > offset || cur + self.buf.len() < offset {
28746 return (stack, None);
28747 }
28748 let mut attrs = self.clone();
28749 let mut last_off = cur + attrs.pos;
28750 while let Some(attr) = attrs.next() {
28751 let Ok(attr) = attr else { break };
28752 match attr {
28753 TaprioSchedEntry::Index(val) => {
28754 if last_off == offset {
28755 stack.push(("Index", last_off));
28756 break;
28757 }
28758 }
28759 TaprioSchedEntry::Cmd(val) => {
28760 if last_off == offset {
28761 stack.push(("Cmd", last_off));
28762 break;
28763 }
28764 }
28765 TaprioSchedEntry::GateMask(val) => {
28766 if last_off == offset {
28767 stack.push(("GateMask", last_off));
28768 break;
28769 }
28770 }
28771 TaprioSchedEntry::Interval(val) => {
28772 if last_off == offset {
28773 stack.push(("Interval", last_off));
28774 break;
28775 }
28776 }
28777 _ => {}
28778 };
28779 last_off = cur + attrs.pos;
28780 }
28781 if !stack.is_empty() {
28782 stack.push(("TaprioSchedEntry", cur));
28783 }
28784 (stack, None)
28785 }
28786}
28787#[derive(Clone)]
28788pub enum TaprioTcEntryAttrs {
28789 Index(u32),
28790 MaxSdu(u32),
28791 Fp(u32),
28792}
28793impl<'a> IterableTaprioTcEntryAttrs<'a> {
28794 pub fn get_index(&self) -> Result<u32, ErrorContext> {
28795 let mut iter = self.clone();
28796 iter.pos = 0;
28797 for attr in iter {
28798 if let Ok(TaprioTcEntryAttrs::Index(val)) = attr {
28799 return Ok(val);
28800 }
28801 }
28802 Err(ErrorContext::new_missing(
28803 "TaprioTcEntryAttrs",
28804 "Index",
28805 self.orig_loc,
28806 self.buf.as_ptr() as usize,
28807 ))
28808 }
28809 pub fn get_max_sdu(&self) -> Result<u32, ErrorContext> {
28810 let mut iter = self.clone();
28811 iter.pos = 0;
28812 for attr in iter {
28813 if let Ok(TaprioTcEntryAttrs::MaxSdu(val)) = attr {
28814 return Ok(val);
28815 }
28816 }
28817 Err(ErrorContext::new_missing(
28818 "TaprioTcEntryAttrs",
28819 "MaxSdu",
28820 self.orig_loc,
28821 self.buf.as_ptr() as usize,
28822 ))
28823 }
28824 pub fn get_fp(&self) -> Result<u32, ErrorContext> {
28825 let mut iter = self.clone();
28826 iter.pos = 0;
28827 for attr in iter {
28828 if let Ok(TaprioTcEntryAttrs::Fp(val)) = attr {
28829 return Ok(val);
28830 }
28831 }
28832 Err(ErrorContext::new_missing(
28833 "TaprioTcEntryAttrs",
28834 "Fp",
28835 self.orig_loc,
28836 self.buf.as_ptr() as usize,
28837 ))
28838 }
28839}
28840impl TaprioTcEntryAttrs {
28841 pub fn new<'a>(buf: &'a [u8]) -> IterableTaprioTcEntryAttrs<'a> {
28842 IterableTaprioTcEntryAttrs::with_loc(buf, buf.as_ptr() as usize)
28843 }
28844 fn attr_from_type(r#type: u16) -> Option<&'static str> {
28845 let res = match r#type {
28846 1u16 => "Index",
28847 2u16 => "MaxSdu",
28848 3u16 => "Fp",
28849 _ => return None,
28850 };
28851 Some(res)
28852 }
28853}
28854#[derive(Clone, Copy, Default)]
28855pub struct IterableTaprioTcEntryAttrs<'a> {
28856 buf: &'a [u8],
28857 pos: usize,
28858 orig_loc: usize,
28859}
28860impl<'a> IterableTaprioTcEntryAttrs<'a> {
28861 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
28862 Self {
28863 buf,
28864 pos: 0,
28865 orig_loc,
28866 }
28867 }
28868 pub fn get_buf(&self) -> &'a [u8] {
28869 self.buf
28870 }
28871}
28872impl<'a> Iterator for IterableTaprioTcEntryAttrs<'a> {
28873 type Item = Result<TaprioTcEntryAttrs, ErrorContext>;
28874 fn next(&mut self) -> Option<Self::Item> {
28875 let mut pos;
28876 let mut r#type;
28877 loop {
28878 pos = self.pos;
28879 r#type = None;
28880 if self.buf.len() == self.pos {
28881 return None;
28882 }
28883 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
28884 self.pos = self.buf.len();
28885 break;
28886 };
28887 r#type = Some(header.r#type);
28888 let res = match header.r#type {
28889 1u16 => TaprioTcEntryAttrs::Index({
28890 let res = parse_u32(next);
28891 let Some(val) = res else { break };
28892 val
28893 }),
28894 2u16 => TaprioTcEntryAttrs::MaxSdu({
28895 let res = parse_u32(next);
28896 let Some(val) = res else { break };
28897 val
28898 }),
28899 3u16 => TaprioTcEntryAttrs::Fp({
28900 let res = parse_u32(next);
28901 let Some(val) = res else { break };
28902 val
28903 }),
28904 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
28905 n => continue,
28906 };
28907 return Some(Ok(res));
28908 }
28909 Some(Err(ErrorContext::new(
28910 "TaprioTcEntryAttrs",
28911 r#type.and_then(|t| TaprioTcEntryAttrs::attr_from_type(t)),
28912 self.orig_loc,
28913 self.buf.as_ptr().wrapping_add(pos) as usize,
28914 )))
28915 }
28916}
28917impl std::fmt::Debug for IterableTaprioTcEntryAttrs<'_> {
28918 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28919 let mut fmt = f.debug_struct("TaprioTcEntryAttrs");
28920 for attr in self.clone() {
28921 let attr = match attr {
28922 Ok(a) => a,
28923 Err(err) => {
28924 fmt.finish()?;
28925 f.write_str("Err(")?;
28926 err.fmt(f)?;
28927 return f.write_str(")");
28928 }
28929 };
28930 match attr {
28931 TaprioTcEntryAttrs::Index(val) => fmt.field("Index", &val),
28932 TaprioTcEntryAttrs::MaxSdu(val) => fmt.field("MaxSdu", &val),
28933 TaprioTcEntryAttrs::Fp(val) => fmt.field("Fp", &val),
28934 };
28935 }
28936 fmt.finish()
28937 }
28938}
28939impl IterableTaprioTcEntryAttrs<'_> {
28940 pub fn lookup_attr(
28941 &self,
28942 offset: usize,
28943 missing_type: Option<u16>,
28944 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28945 let mut stack = Vec::new();
28946 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
28947 if missing_type.is_some() && cur == offset {
28948 stack.push(("TaprioTcEntryAttrs", offset));
28949 return (
28950 stack,
28951 missing_type.and_then(|t| TaprioTcEntryAttrs::attr_from_type(t)),
28952 );
28953 }
28954 if cur > offset || cur + self.buf.len() < offset {
28955 return (stack, None);
28956 }
28957 let mut attrs = self.clone();
28958 let mut last_off = cur + attrs.pos;
28959 while let Some(attr) = attrs.next() {
28960 let Ok(attr) = attr else { break };
28961 match attr {
28962 TaprioTcEntryAttrs::Index(val) => {
28963 if last_off == offset {
28964 stack.push(("Index", last_off));
28965 break;
28966 }
28967 }
28968 TaprioTcEntryAttrs::MaxSdu(val) => {
28969 if last_off == offset {
28970 stack.push(("MaxSdu", last_off));
28971 break;
28972 }
28973 }
28974 TaprioTcEntryAttrs::Fp(val) => {
28975 if last_off == offset {
28976 stack.push(("Fp", last_off));
28977 break;
28978 }
28979 }
28980 _ => {}
28981 };
28982 last_off = cur + attrs.pos;
28983 }
28984 if !stack.is_empty() {
28985 stack.push(("TaprioTcEntryAttrs", cur));
28986 }
28987 (stack, None)
28988 }
28989}
28990#[derive(Clone)]
28991pub enum TbfAttrs<'a> {
28992 Parms(TcTbfQopt),
28993 Rtab(&'a [u8]),
28994 Ptab(&'a [u8]),
28995 Rate64(u64),
28996 Prate64(u64),
28997 Burst(u32),
28998 Pburst(u32),
28999 Pad(&'a [u8]),
29000}
29001impl<'a> IterableTbfAttrs<'a> {
29002 pub fn get_parms(&self) -> Result<TcTbfQopt, ErrorContext> {
29003 let mut iter = self.clone();
29004 iter.pos = 0;
29005 for attr in iter {
29006 if let Ok(TbfAttrs::Parms(val)) = attr {
29007 return Ok(val);
29008 }
29009 }
29010 Err(ErrorContext::new_missing(
29011 "TbfAttrs",
29012 "Parms",
29013 self.orig_loc,
29014 self.buf.as_ptr() as usize,
29015 ))
29016 }
29017 pub fn get_rtab(&self) -> Result<&'a [u8], ErrorContext> {
29018 let mut iter = self.clone();
29019 iter.pos = 0;
29020 for attr in iter {
29021 if let Ok(TbfAttrs::Rtab(val)) = attr {
29022 return Ok(val);
29023 }
29024 }
29025 Err(ErrorContext::new_missing(
29026 "TbfAttrs",
29027 "Rtab",
29028 self.orig_loc,
29029 self.buf.as_ptr() as usize,
29030 ))
29031 }
29032 pub fn get_ptab(&self) -> Result<&'a [u8], ErrorContext> {
29033 let mut iter = self.clone();
29034 iter.pos = 0;
29035 for attr in iter {
29036 if let Ok(TbfAttrs::Ptab(val)) = attr {
29037 return Ok(val);
29038 }
29039 }
29040 Err(ErrorContext::new_missing(
29041 "TbfAttrs",
29042 "Ptab",
29043 self.orig_loc,
29044 self.buf.as_ptr() as usize,
29045 ))
29046 }
29047 pub fn get_rate64(&self) -> Result<u64, ErrorContext> {
29048 let mut iter = self.clone();
29049 iter.pos = 0;
29050 for attr in iter {
29051 if let Ok(TbfAttrs::Rate64(val)) = attr {
29052 return Ok(val);
29053 }
29054 }
29055 Err(ErrorContext::new_missing(
29056 "TbfAttrs",
29057 "Rate64",
29058 self.orig_loc,
29059 self.buf.as_ptr() as usize,
29060 ))
29061 }
29062 pub fn get_prate64(&self) -> Result<u64, ErrorContext> {
29063 let mut iter = self.clone();
29064 iter.pos = 0;
29065 for attr in iter {
29066 if let Ok(TbfAttrs::Prate64(val)) = attr {
29067 return Ok(val);
29068 }
29069 }
29070 Err(ErrorContext::new_missing(
29071 "TbfAttrs",
29072 "Prate64",
29073 self.orig_loc,
29074 self.buf.as_ptr() as usize,
29075 ))
29076 }
29077 pub fn get_burst(&self) -> Result<u32, ErrorContext> {
29078 let mut iter = self.clone();
29079 iter.pos = 0;
29080 for attr in iter {
29081 if let Ok(TbfAttrs::Burst(val)) = attr {
29082 return Ok(val);
29083 }
29084 }
29085 Err(ErrorContext::new_missing(
29086 "TbfAttrs",
29087 "Burst",
29088 self.orig_loc,
29089 self.buf.as_ptr() as usize,
29090 ))
29091 }
29092 pub fn get_pburst(&self) -> Result<u32, ErrorContext> {
29093 let mut iter = self.clone();
29094 iter.pos = 0;
29095 for attr in iter {
29096 if let Ok(TbfAttrs::Pburst(val)) = attr {
29097 return Ok(val);
29098 }
29099 }
29100 Err(ErrorContext::new_missing(
29101 "TbfAttrs",
29102 "Pburst",
29103 self.orig_loc,
29104 self.buf.as_ptr() as usize,
29105 ))
29106 }
29107 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
29108 let mut iter = self.clone();
29109 iter.pos = 0;
29110 for attr in iter {
29111 if let Ok(TbfAttrs::Pad(val)) = attr {
29112 return Ok(val);
29113 }
29114 }
29115 Err(ErrorContext::new_missing(
29116 "TbfAttrs",
29117 "Pad",
29118 self.orig_loc,
29119 self.buf.as_ptr() as usize,
29120 ))
29121 }
29122}
29123impl TbfAttrs<'_> {
29124 pub fn new<'a>(buf: &'a [u8]) -> IterableTbfAttrs<'a> {
29125 IterableTbfAttrs::with_loc(buf, buf.as_ptr() as usize)
29126 }
29127 fn attr_from_type(r#type: u16) -> Option<&'static str> {
29128 let res = match r#type {
29129 1u16 => "Parms",
29130 2u16 => "Rtab",
29131 3u16 => "Ptab",
29132 4u16 => "Rate64",
29133 5u16 => "Prate64",
29134 6u16 => "Burst",
29135 7u16 => "Pburst",
29136 8u16 => "Pad",
29137 _ => return None,
29138 };
29139 Some(res)
29140 }
29141}
29142#[derive(Clone, Copy, Default)]
29143pub struct IterableTbfAttrs<'a> {
29144 buf: &'a [u8],
29145 pos: usize,
29146 orig_loc: usize,
29147}
29148impl<'a> IterableTbfAttrs<'a> {
29149 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
29150 Self {
29151 buf,
29152 pos: 0,
29153 orig_loc,
29154 }
29155 }
29156 pub fn get_buf(&self) -> &'a [u8] {
29157 self.buf
29158 }
29159}
29160impl<'a> Iterator for IterableTbfAttrs<'a> {
29161 type Item = Result<TbfAttrs<'a>, ErrorContext>;
29162 fn next(&mut self) -> Option<Self::Item> {
29163 let mut pos;
29164 let mut r#type;
29165 loop {
29166 pos = self.pos;
29167 r#type = None;
29168 if self.buf.len() == self.pos {
29169 return None;
29170 }
29171 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
29172 self.pos = self.buf.len();
29173 break;
29174 };
29175 r#type = Some(header.r#type);
29176 let res = match header.r#type {
29177 1u16 => TbfAttrs::Parms({
29178 let res = Some(TcTbfQopt::new_from_zeroed(next));
29179 let Some(val) = res else { break };
29180 val
29181 }),
29182 2u16 => TbfAttrs::Rtab({
29183 let res = Some(next);
29184 let Some(val) = res else { break };
29185 val
29186 }),
29187 3u16 => TbfAttrs::Ptab({
29188 let res = Some(next);
29189 let Some(val) = res else { break };
29190 val
29191 }),
29192 4u16 => TbfAttrs::Rate64({
29193 let res = parse_u64(next);
29194 let Some(val) = res else { break };
29195 val
29196 }),
29197 5u16 => TbfAttrs::Prate64({
29198 let res = parse_u64(next);
29199 let Some(val) = res else { break };
29200 val
29201 }),
29202 6u16 => TbfAttrs::Burst({
29203 let res = parse_u32(next);
29204 let Some(val) = res else { break };
29205 val
29206 }),
29207 7u16 => TbfAttrs::Pburst({
29208 let res = parse_u32(next);
29209 let Some(val) = res else { break };
29210 val
29211 }),
29212 8u16 => TbfAttrs::Pad({
29213 let res = Some(next);
29214 let Some(val) = res else { break };
29215 val
29216 }),
29217 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
29218 n => continue,
29219 };
29220 return Some(Ok(res));
29221 }
29222 Some(Err(ErrorContext::new(
29223 "TbfAttrs",
29224 r#type.and_then(|t| TbfAttrs::attr_from_type(t)),
29225 self.orig_loc,
29226 self.buf.as_ptr().wrapping_add(pos) as usize,
29227 )))
29228 }
29229}
29230impl<'a> std::fmt::Debug for IterableTbfAttrs<'_> {
29231 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29232 let mut fmt = f.debug_struct("TbfAttrs");
29233 for attr in self.clone() {
29234 let attr = match attr {
29235 Ok(a) => a,
29236 Err(err) => {
29237 fmt.finish()?;
29238 f.write_str("Err(")?;
29239 err.fmt(f)?;
29240 return f.write_str(")");
29241 }
29242 };
29243 match attr {
29244 TbfAttrs::Parms(val) => fmt.field("Parms", &val),
29245 TbfAttrs::Rtab(val) => fmt.field("Rtab", &val),
29246 TbfAttrs::Ptab(val) => fmt.field("Ptab", &val),
29247 TbfAttrs::Rate64(val) => fmt.field("Rate64", &val),
29248 TbfAttrs::Prate64(val) => fmt.field("Prate64", &val),
29249 TbfAttrs::Burst(val) => fmt.field("Burst", &val),
29250 TbfAttrs::Pburst(val) => fmt.field("Pburst", &val),
29251 TbfAttrs::Pad(val) => fmt.field("Pad", &val),
29252 };
29253 }
29254 fmt.finish()
29255 }
29256}
29257impl IterableTbfAttrs<'_> {
29258 pub fn lookup_attr(
29259 &self,
29260 offset: usize,
29261 missing_type: Option<u16>,
29262 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
29263 let mut stack = Vec::new();
29264 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
29265 if missing_type.is_some() && cur == offset {
29266 stack.push(("TbfAttrs", offset));
29267 return (
29268 stack,
29269 missing_type.and_then(|t| TbfAttrs::attr_from_type(t)),
29270 );
29271 }
29272 if cur > offset || cur + self.buf.len() < offset {
29273 return (stack, None);
29274 }
29275 let mut attrs = self.clone();
29276 let mut last_off = cur + attrs.pos;
29277 while let Some(attr) = attrs.next() {
29278 let Ok(attr) = attr else { break };
29279 match attr {
29280 TbfAttrs::Parms(val) => {
29281 if last_off == offset {
29282 stack.push(("Parms", last_off));
29283 break;
29284 }
29285 }
29286 TbfAttrs::Rtab(val) => {
29287 if last_off == offset {
29288 stack.push(("Rtab", last_off));
29289 break;
29290 }
29291 }
29292 TbfAttrs::Ptab(val) => {
29293 if last_off == offset {
29294 stack.push(("Ptab", last_off));
29295 break;
29296 }
29297 }
29298 TbfAttrs::Rate64(val) => {
29299 if last_off == offset {
29300 stack.push(("Rate64", last_off));
29301 break;
29302 }
29303 }
29304 TbfAttrs::Prate64(val) => {
29305 if last_off == offset {
29306 stack.push(("Prate64", last_off));
29307 break;
29308 }
29309 }
29310 TbfAttrs::Burst(val) => {
29311 if last_off == offset {
29312 stack.push(("Burst", last_off));
29313 break;
29314 }
29315 }
29316 TbfAttrs::Pburst(val) => {
29317 if last_off == offset {
29318 stack.push(("Pburst", last_off));
29319 break;
29320 }
29321 }
29322 TbfAttrs::Pad(val) => {
29323 if last_off == offset {
29324 stack.push(("Pad", last_off));
29325 break;
29326 }
29327 }
29328 _ => {}
29329 };
29330 last_off = cur + attrs.pos;
29331 }
29332 if !stack.is_empty() {
29333 stack.push(("TbfAttrs", cur));
29334 }
29335 (stack, None)
29336 }
29337}
29338#[derive(Clone)]
29339pub enum ActSampleAttrs<'a> {
29340 Tm(TcfT),
29341 Parms(TcGact),
29342 Rate(u32),
29343 TruncSize(u32),
29344 PsampleGroup(u32),
29345 Pad(&'a [u8]),
29346}
29347impl<'a> IterableActSampleAttrs<'a> {
29348 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
29349 let mut iter = self.clone();
29350 iter.pos = 0;
29351 for attr in iter {
29352 if let Ok(ActSampleAttrs::Tm(val)) = attr {
29353 return Ok(val);
29354 }
29355 }
29356 Err(ErrorContext::new_missing(
29357 "ActSampleAttrs",
29358 "Tm",
29359 self.orig_loc,
29360 self.buf.as_ptr() as usize,
29361 ))
29362 }
29363 pub fn get_parms(&self) -> Result<TcGact, ErrorContext> {
29364 let mut iter = self.clone();
29365 iter.pos = 0;
29366 for attr in iter {
29367 if let Ok(ActSampleAttrs::Parms(val)) = attr {
29368 return Ok(val);
29369 }
29370 }
29371 Err(ErrorContext::new_missing(
29372 "ActSampleAttrs",
29373 "Parms",
29374 self.orig_loc,
29375 self.buf.as_ptr() as usize,
29376 ))
29377 }
29378 pub fn get_rate(&self) -> Result<u32, ErrorContext> {
29379 let mut iter = self.clone();
29380 iter.pos = 0;
29381 for attr in iter {
29382 if let Ok(ActSampleAttrs::Rate(val)) = attr {
29383 return Ok(val);
29384 }
29385 }
29386 Err(ErrorContext::new_missing(
29387 "ActSampleAttrs",
29388 "Rate",
29389 self.orig_loc,
29390 self.buf.as_ptr() as usize,
29391 ))
29392 }
29393 pub fn get_trunc_size(&self) -> Result<u32, ErrorContext> {
29394 let mut iter = self.clone();
29395 iter.pos = 0;
29396 for attr in iter {
29397 if let Ok(ActSampleAttrs::TruncSize(val)) = attr {
29398 return Ok(val);
29399 }
29400 }
29401 Err(ErrorContext::new_missing(
29402 "ActSampleAttrs",
29403 "TruncSize",
29404 self.orig_loc,
29405 self.buf.as_ptr() as usize,
29406 ))
29407 }
29408 pub fn get_psample_group(&self) -> Result<u32, ErrorContext> {
29409 let mut iter = self.clone();
29410 iter.pos = 0;
29411 for attr in iter {
29412 if let Ok(ActSampleAttrs::PsampleGroup(val)) = attr {
29413 return Ok(val);
29414 }
29415 }
29416 Err(ErrorContext::new_missing(
29417 "ActSampleAttrs",
29418 "PsampleGroup",
29419 self.orig_loc,
29420 self.buf.as_ptr() as usize,
29421 ))
29422 }
29423 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
29424 let mut iter = self.clone();
29425 iter.pos = 0;
29426 for attr in iter {
29427 if let Ok(ActSampleAttrs::Pad(val)) = attr {
29428 return Ok(val);
29429 }
29430 }
29431 Err(ErrorContext::new_missing(
29432 "ActSampleAttrs",
29433 "Pad",
29434 self.orig_loc,
29435 self.buf.as_ptr() as usize,
29436 ))
29437 }
29438}
29439impl ActSampleAttrs<'_> {
29440 pub fn new<'a>(buf: &'a [u8]) -> IterableActSampleAttrs<'a> {
29441 IterableActSampleAttrs::with_loc(buf, buf.as_ptr() as usize)
29442 }
29443 fn attr_from_type(r#type: u16) -> Option<&'static str> {
29444 let res = match r#type {
29445 1u16 => "Tm",
29446 2u16 => "Parms",
29447 3u16 => "Rate",
29448 4u16 => "TruncSize",
29449 5u16 => "PsampleGroup",
29450 6u16 => "Pad",
29451 _ => return None,
29452 };
29453 Some(res)
29454 }
29455}
29456#[derive(Clone, Copy, Default)]
29457pub struct IterableActSampleAttrs<'a> {
29458 buf: &'a [u8],
29459 pos: usize,
29460 orig_loc: usize,
29461}
29462impl<'a> IterableActSampleAttrs<'a> {
29463 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
29464 Self {
29465 buf,
29466 pos: 0,
29467 orig_loc,
29468 }
29469 }
29470 pub fn get_buf(&self) -> &'a [u8] {
29471 self.buf
29472 }
29473}
29474impl<'a> Iterator for IterableActSampleAttrs<'a> {
29475 type Item = Result<ActSampleAttrs<'a>, ErrorContext>;
29476 fn next(&mut self) -> Option<Self::Item> {
29477 let mut pos;
29478 let mut r#type;
29479 loop {
29480 pos = self.pos;
29481 r#type = None;
29482 if self.buf.len() == self.pos {
29483 return None;
29484 }
29485 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
29486 self.pos = self.buf.len();
29487 break;
29488 };
29489 r#type = Some(header.r#type);
29490 let res = match header.r#type {
29491 1u16 => ActSampleAttrs::Tm({
29492 let res = Some(TcfT::new_from_zeroed(next));
29493 let Some(val) = res else { break };
29494 val
29495 }),
29496 2u16 => ActSampleAttrs::Parms({
29497 let res = Some(TcGact::new_from_zeroed(next));
29498 let Some(val) = res else { break };
29499 val
29500 }),
29501 3u16 => ActSampleAttrs::Rate({
29502 let res = parse_u32(next);
29503 let Some(val) = res else { break };
29504 val
29505 }),
29506 4u16 => ActSampleAttrs::TruncSize({
29507 let res = parse_u32(next);
29508 let Some(val) = res else { break };
29509 val
29510 }),
29511 5u16 => ActSampleAttrs::PsampleGroup({
29512 let res = parse_u32(next);
29513 let Some(val) = res else { break };
29514 val
29515 }),
29516 6u16 => ActSampleAttrs::Pad({
29517 let res = Some(next);
29518 let Some(val) = res else { break };
29519 val
29520 }),
29521 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
29522 n => continue,
29523 };
29524 return Some(Ok(res));
29525 }
29526 Some(Err(ErrorContext::new(
29527 "ActSampleAttrs",
29528 r#type.and_then(|t| ActSampleAttrs::attr_from_type(t)),
29529 self.orig_loc,
29530 self.buf.as_ptr().wrapping_add(pos) as usize,
29531 )))
29532 }
29533}
29534impl<'a> std::fmt::Debug for IterableActSampleAttrs<'_> {
29535 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29536 let mut fmt = f.debug_struct("ActSampleAttrs");
29537 for attr in self.clone() {
29538 let attr = match attr {
29539 Ok(a) => a,
29540 Err(err) => {
29541 fmt.finish()?;
29542 f.write_str("Err(")?;
29543 err.fmt(f)?;
29544 return f.write_str(")");
29545 }
29546 };
29547 match attr {
29548 ActSampleAttrs::Tm(val) => fmt.field("Tm", &val),
29549 ActSampleAttrs::Parms(val) => fmt.field("Parms", &val),
29550 ActSampleAttrs::Rate(val) => fmt.field("Rate", &val),
29551 ActSampleAttrs::TruncSize(val) => fmt.field("TruncSize", &val),
29552 ActSampleAttrs::PsampleGroup(val) => fmt.field("PsampleGroup", &val),
29553 ActSampleAttrs::Pad(val) => fmt.field("Pad", &val),
29554 };
29555 }
29556 fmt.finish()
29557 }
29558}
29559impl IterableActSampleAttrs<'_> {
29560 pub fn lookup_attr(
29561 &self,
29562 offset: usize,
29563 missing_type: Option<u16>,
29564 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
29565 let mut stack = Vec::new();
29566 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
29567 if missing_type.is_some() && cur == offset {
29568 stack.push(("ActSampleAttrs", offset));
29569 return (
29570 stack,
29571 missing_type.and_then(|t| ActSampleAttrs::attr_from_type(t)),
29572 );
29573 }
29574 if cur > offset || cur + self.buf.len() < offset {
29575 return (stack, None);
29576 }
29577 let mut attrs = self.clone();
29578 let mut last_off = cur + attrs.pos;
29579 while let Some(attr) = attrs.next() {
29580 let Ok(attr) = attr else { break };
29581 match attr {
29582 ActSampleAttrs::Tm(val) => {
29583 if last_off == offset {
29584 stack.push(("Tm", last_off));
29585 break;
29586 }
29587 }
29588 ActSampleAttrs::Parms(val) => {
29589 if last_off == offset {
29590 stack.push(("Parms", last_off));
29591 break;
29592 }
29593 }
29594 ActSampleAttrs::Rate(val) => {
29595 if last_off == offset {
29596 stack.push(("Rate", last_off));
29597 break;
29598 }
29599 }
29600 ActSampleAttrs::TruncSize(val) => {
29601 if last_off == offset {
29602 stack.push(("TruncSize", last_off));
29603 break;
29604 }
29605 }
29606 ActSampleAttrs::PsampleGroup(val) => {
29607 if last_off == offset {
29608 stack.push(("PsampleGroup", last_off));
29609 break;
29610 }
29611 }
29612 ActSampleAttrs::Pad(val) => {
29613 if last_off == offset {
29614 stack.push(("Pad", last_off));
29615 break;
29616 }
29617 }
29618 _ => {}
29619 };
29620 last_off = cur + attrs.pos;
29621 }
29622 if !stack.is_empty() {
29623 stack.push(("ActSampleAttrs", cur));
29624 }
29625 (stack, None)
29626 }
29627}
29628#[derive(Clone)]
29629pub enum ActGactAttrs<'a> {
29630 Tm(TcfT),
29631 Parms(TcGact),
29632 Prob(TcGactP),
29633 Pad(&'a [u8]),
29634}
29635impl<'a> IterableActGactAttrs<'a> {
29636 pub fn get_tm(&self) -> Result<TcfT, ErrorContext> {
29637 let mut iter = self.clone();
29638 iter.pos = 0;
29639 for attr in iter {
29640 if let Ok(ActGactAttrs::Tm(val)) = attr {
29641 return Ok(val);
29642 }
29643 }
29644 Err(ErrorContext::new_missing(
29645 "ActGactAttrs",
29646 "Tm",
29647 self.orig_loc,
29648 self.buf.as_ptr() as usize,
29649 ))
29650 }
29651 pub fn get_parms(&self) -> Result<TcGact, ErrorContext> {
29652 let mut iter = self.clone();
29653 iter.pos = 0;
29654 for attr in iter {
29655 if let Ok(ActGactAttrs::Parms(val)) = attr {
29656 return Ok(val);
29657 }
29658 }
29659 Err(ErrorContext::new_missing(
29660 "ActGactAttrs",
29661 "Parms",
29662 self.orig_loc,
29663 self.buf.as_ptr() as usize,
29664 ))
29665 }
29666 pub fn get_prob(&self) -> Result<TcGactP, ErrorContext> {
29667 let mut iter = self.clone();
29668 iter.pos = 0;
29669 for attr in iter {
29670 if let Ok(ActGactAttrs::Prob(val)) = attr {
29671 return Ok(val);
29672 }
29673 }
29674 Err(ErrorContext::new_missing(
29675 "ActGactAttrs",
29676 "Prob",
29677 self.orig_loc,
29678 self.buf.as_ptr() as usize,
29679 ))
29680 }
29681 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
29682 let mut iter = self.clone();
29683 iter.pos = 0;
29684 for attr in iter {
29685 if let Ok(ActGactAttrs::Pad(val)) = attr {
29686 return Ok(val);
29687 }
29688 }
29689 Err(ErrorContext::new_missing(
29690 "ActGactAttrs",
29691 "Pad",
29692 self.orig_loc,
29693 self.buf.as_ptr() as usize,
29694 ))
29695 }
29696}
29697impl ActGactAttrs<'_> {
29698 pub fn new<'a>(buf: &'a [u8]) -> IterableActGactAttrs<'a> {
29699 IterableActGactAttrs::with_loc(buf, buf.as_ptr() as usize)
29700 }
29701 fn attr_from_type(r#type: u16) -> Option<&'static str> {
29702 let res = match r#type {
29703 1u16 => "Tm",
29704 2u16 => "Parms",
29705 3u16 => "Prob",
29706 4u16 => "Pad",
29707 _ => return None,
29708 };
29709 Some(res)
29710 }
29711}
29712#[derive(Clone, Copy, Default)]
29713pub struct IterableActGactAttrs<'a> {
29714 buf: &'a [u8],
29715 pos: usize,
29716 orig_loc: usize,
29717}
29718impl<'a> IterableActGactAttrs<'a> {
29719 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
29720 Self {
29721 buf,
29722 pos: 0,
29723 orig_loc,
29724 }
29725 }
29726 pub fn get_buf(&self) -> &'a [u8] {
29727 self.buf
29728 }
29729}
29730impl<'a> Iterator for IterableActGactAttrs<'a> {
29731 type Item = Result<ActGactAttrs<'a>, ErrorContext>;
29732 fn next(&mut self) -> Option<Self::Item> {
29733 let mut pos;
29734 let mut r#type;
29735 loop {
29736 pos = self.pos;
29737 r#type = None;
29738 if self.buf.len() == self.pos {
29739 return None;
29740 }
29741 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
29742 self.pos = self.buf.len();
29743 break;
29744 };
29745 r#type = Some(header.r#type);
29746 let res = match header.r#type {
29747 1u16 => ActGactAttrs::Tm({
29748 let res = Some(TcfT::new_from_zeroed(next));
29749 let Some(val) = res else { break };
29750 val
29751 }),
29752 2u16 => ActGactAttrs::Parms({
29753 let res = Some(TcGact::new_from_zeroed(next));
29754 let Some(val) = res else { break };
29755 val
29756 }),
29757 3u16 => ActGactAttrs::Prob({
29758 let res = Some(TcGactP::new_from_zeroed(next));
29759 let Some(val) = res else { break };
29760 val
29761 }),
29762 4u16 => ActGactAttrs::Pad({
29763 let res = Some(next);
29764 let Some(val) = res else { break };
29765 val
29766 }),
29767 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
29768 n => continue,
29769 };
29770 return Some(Ok(res));
29771 }
29772 Some(Err(ErrorContext::new(
29773 "ActGactAttrs",
29774 r#type.and_then(|t| ActGactAttrs::attr_from_type(t)),
29775 self.orig_loc,
29776 self.buf.as_ptr().wrapping_add(pos) as usize,
29777 )))
29778 }
29779}
29780impl<'a> std::fmt::Debug for IterableActGactAttrs<'_> {
29781 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29782 let mut fmt = f.debug_struct("ActGactAttrs");
29783 for attr in self.clone() {
29784 let attr = match attr {
29785 Ok(a) => a,
29786 Err(err) => {
29787 fmt.finish()?;
29788 f.write_str("Err(")?;
29789 err.fmt(f)?;
29790 return f.write_str(")");
29791 }
29792 };
29793 match attr {
29794 ActGactAttrs::Tm(val) => fmt.field("Tm", &val),
29795 ActGactAttrs::Parms(val) => fmt.field("Parms", &val),
29796 ActGactAttrs::Prob(val) => fmt.field("Prob", &val),
29797 ActGactAttrs::Pad(val) => fmt.field("Pad", &val),
29798 };
29799 }
29800 fmt.finish()
29801 }
29802}
29803impl IterableActGactAttrs<'_> {
29804 pub fn lookup_attr(
29805 &self,
29806 offset: usize,
29807 missing_type: Option<u16>,
29808 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
29809 let mut stack = Vec::new();
29810 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
29811 if missing_type.is_some() && cur == offset {
29812 stack.push(("ActGactAttrs", offset));
29813 return (
29814 stack,
29815 missing_type.and_then(|t| ActGactAttrs::attr_from_type(t)),
29816 );
29817 }
29818 if cur > offset || cur + self.buf.len() < offset {
29819 return (stack, None);
29820 }
29821 let mut attrs = self.clone();
29822 let mut last_off = cur + attrs.pos;
29823 while let Some(attr) = attrs.next() {
29824 let Ok(attr) = attr else { break };
29825 match attr {
29826 ActGactAttrs::Tm(val) => {
29827 if last_off == offset {
29828 stack.push(("Tm", last_off));
29829 break;
29830 }
29831 }
29832 ActGactAttrs::Parms(val) => {
29833 if last_off == offset {
29834 stack.push(("Parms", last_off));
29835 break;
29836 }
29837 }
29838 ActGactAttrs::Prob(val) => {
29839 if last_off == offset {
29840 stack.push(("Prob", last_off));
29841 break;
29842 }
29843 }
29844 ActGactAttrs::Pad(val) => {
29845 if last_off == offset {
29846 stack.push(("Pad", last_off));
29847 break;
29848 }
29849 }
29850 _ => {}
29851 };
29852 last_off = cur + attrs.pos;
29853 }
29854 if !stack.is_empty() {
29855 stack.push(("ActGactAttrs", cur));
29856 }
29857 (stack, None)
29858 }
29859}
29860#[derive(Clone)]
29861pub enum TcaStabAttrs<'a> {
29862 Base(TcSizespec),
29863 Data(&'a [u8]),
29864}
29865impl<'a> IterableTcaStabAttrs<'a> {
29866 pub fn get_base(&self) -> Result<TcSizespec, ErrorContext> {
29867 let mut iter = self.clone();
29868 iter.pos = 0;
29869 for attr in iter {
29870 if let Ok(TcaStabAttrs::Base(val)) = attr {
29871 return Ok(val);
29872 }
29873 }
29874 Err(ErrorContext::new_missing(
29875 "TcaStabAttrs",
29876 "Base",
29877 self.orig_loc,
29878 self.buf.as_ptr() as usize,
29879 ))
29880 }
29881 pub fn get_data(&self) -> Result<&'a [u8], ErrorContext> {
29882 let mut iter = self.clone();
29883 iter.pos = 0;
29884 for attr in iter {
29885 if let Ok(TcaStabAttrs::Data(val)) = attr {
29886 return Ok(val);
29887 }
29888 }
29889 Err(ErrorContext::new_missing(
29890 "TcaStabAttrs",
29891 "Data",
29892 self.orig_loc,
29893 self.buf.as_ptr() as usize,
29894 ))
29895 }
29896}
29897impl TcaStabAttrs<'_> {
29898 pub fn new<'a>(buf: &'a [u8]) -> IterableTcaStabAttrs<'a> {
29899 IterableTcaStabAttrs::with_loc(buf, buf.as_ptr() as usize)
29900 }
29901 fn attr_from_type(r#type: u16) -> Option<&'static str> {
29902 let res = match r#type {
29903 1u16 => "Base",
29904 2u16 => "Data",
29905 _ => return None,
29906 };
29907 Some(res)
29908 }
29909}
29910#[derive(Clone, Copy, Default)]
29911pub struct IterableTcaStabAttrs<'a> {
29912 buf: &'a [u8],
29913 pos: usize,
29914 orig_loc: usize,
29915}
29916impl<'a> IterableTcaStabAttrs<'a> {
29917 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
29918 Self {
29919 buf,
29920 pos: 0,
29921 orig_loc,
29922 }
29923 }
29924 pub fn get_buf(&self) -> &'a [u8] {
29925 self.buf
29926 }
29927}
29928impl<'a> Iterator for IterableTcaStabAttrs<'a> {
29929 type Item = Result<TcaStabAttrs<'a>, ErrorContext>;
29930 fn next(&mut self) -> Option<Self::Item> {
29931 let mut pos;
29932 let mut r#type;
29933 loop {
29934 pos = self.pos;
29935 r#type = None;
29936 if self.buf.len() == self.pos {
29937 return None;
29938 }
29939 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
29940 self.pos = self.buf.len();
29941 break;
29942 };
29943 r#type = Some(header.r#type);
29944 let res = match header.r#type {
29945 1u16 => TcaStabAttrs::Base({
29946 let res = Some(TcSizespec::new_from_zeroed(next));
29947 let Some(val) = res else { break };
29948 val
29949 }),
29950 2u16 => TcaStabAttrs::Data({
29951 let res = Some(next);
29952 let Some(val) = res else { break };
29953 val
29954 }),
29955 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
29956 n => continue,
29957 };
29958 return Some(Ok(res));
29959 }
29960 Some(Err(ErrorContext::new(
29961 "TcaStabAttrs",
29962 r#type.and_then(|t| TcaStabAttrs::attr_from_type(t)),
29963 self.orig_loc,
29964 self.buf.as_ptr().wrapping_add(pos) as usize,
29965 )))
29966 }
29967}
29968impl<'a> std::fmt::Debug for IterableTcaStabAttrs<'_> {
29969 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29970 let mut fmt = f.debug_struct("TcaStabAttrs");
29971 for attr in self.clone() {
29972 let attr = match attr {
29973 Ok(a) => a,
29974 Err(err) => {
29975 fmt.finish()?;
29976 f.write_str("Err(")?;
29977 err.fmt(f)?;
29978 return f.write_str(")");
29979 }
29980 };
29981 match attr {
29982 TcaStabAttrs::Base(val) => fmt.field("Base", &val),
29983 TcaStabAttrs::Data(val) => fmt.field("Data", &val),
29984 };
29985 }
29986 fmt.finish()
29987 }
29988}
29989impl IterableTcaStabAttrs<'_> {
29990 pub fn lookup_attr(
29991 &self,
29992 offset: usize,
29993 missing_type: Option<u16>,
29994 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
29995 let mut stack = Vec::new();
29996 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
29997 if missing_type.is_some() && cur == offset {
29998 stack.push(("TcaStabAttrs", offset));
29999 return (
30000 stack,
30001 missing_type.and_then(|t| TcaStabAttrs::attr_from_type(t)),
30002 );
30003 }
30004 if cur > offset || cur + self.buf.len() < offset {
30005 return (stack, None);
30006 }
30007 let mut attrs = self.clone();
30008 let mut last_off = cur + attrs.pos;
30009 while let Some(attr) = attrs.next() {
30010 let Ok(attr) = attr else { break };
30011 match attr {
30012 TcaStabAttrs::Base(val) => {
30013 if last_off == offset {
30014 stack.push(("Base", last_off));
30015 break;
30016 }
30017 }
30018 TcaStabAttrs::Data(val) => {
30019 if last_off == offset {
30020 stack.push(("Data", last_off));
30021 break;
30022 }
30023 }
30024 _ => {}
30025 };
30026 last_off = cur + attrs.pos;
30027 }
30028 if !stack.is_empty() {
30029 stack.push(("TcaStabAttrs", cur));
30030 }
30031 (stack, None)
30032 }
30033}
30034#[derive(Clone)]
30035pub enum TcaStatsAttrs<'a> {
30036 Basic(GnetStatsBasic),
30037 RateEst(GnetStatsRateEst),
30038 Queue(GnetStatsQueue),
30039 App(TcaStatsAppMsg<'a>),
30040 RateEst64(GnetStatsRateEst64),
30041 Pad(&'a [u8]),
30042 BasicHw(GnetStatsBasic),
30043 Pkt64(u64),
30044}
30045impl<'a> IterableTcaStatsAttrs<'a> {
30046 pub fn get_basic(&self) -> Result<GnetStatsBasic, ErrorContext> {
30047 let mut iter = self.clone();
30048 iter.pos = 0;
30049 for attr in iter {
30050 if let Ok(TcaStatsAttrs::Basic(val)) = attr {
30051 return Ok(val);
30052 }
30053 }
30054 Err(ErrorContext::new_missing(
30055 "TcaStatsAttrs",
30056 "Basic",
30057 self.orig_loc,
30058 self.buf.as_ptr() as usize,
30059 ))
30060 }
30061 pub fn get_rate_est(&self) -> Result<GnetStatsRateEst, ErrorContext> {
30062 let mut iter = self.clone();
30063 iter.pos = 0;
30064 for attr in iter {
30065 if let Ok(TcaStatsAttrs::RateEst(val)) = attr {
30066 return Ok(val);
30067 }
30068 }
30069 Err(ErrorContext::new_missing(
30070 "TcaStatsAttrs",
30071 "RateEst",
30072 self.orig_loc,
30073 self.buf.as_ptr() as usize,
30074 ))
30075 }
30076 pub fn get_queue(&self) -> Result<GnetStatsQueue, ErrorContext> {
30077 let mut iter = self.clone();
30078 iter.pos = 0;
30079 for attr in iter {
30080 if let Ok(TcaStatsAttrs::Queue(val)) = attr {
30081 return Ok(val);
30082 }
30083 }
30084 Err(ErrorContext::new_missing(
30085 "TcaStatsAttrs",
30086 "Queue",
30087 self.orig_loc,
30088 self.buf.as_ptr() as usize,
30089 ))
30090 }
30091 pub fn get_app(&self) -> Result<TcaStatsAppMsg<'a>, ErrorContext> {
30092 let mut iter = self.clone();
30093 iter.pos = 0;
30094 for attr in iter {
30095 if let Ok(TcaStatsAttrs::App(val)) = attr {
30096 return Ok(val);
30097 }
30098 }
30099 Err(ErrorContext::new_missing(
30100 "TcaStatsAttrs",
30101 "App",
30102 self.orig_loc,
30103 self.buf.as_ptr() as usize,
30104 ))
30105 }
30106 pub fn get_rate_est64(&self) -> Result<GnetStatsRateEst64, ErrorContext> {
30107 let mut iter = self.clone();
30108 iter.pos = 0;
30109 for attr in iter {
30110 if let Ok(TcaStatsAttrs::RateEst64(val)) = attr {
30111 return Ok(val);
30112 }
30113 }
30114 Err(ErrorContext::new_missing(
30115 "TcaStatsAttrs",
30116 "RateEst64",
30117 self.orig_loc,
30118 self.buf.as_ptr() as usize,
30119 ))
30120 }
30121 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
30122 let mut iter = self.clone();
30123 iter.pos = 0;
30124 for attr in iter {
30125 if let Ok(TcaStatsAttrs::Pad(val)) = attr {
30126 return Ok(val);
30127 }
30128 }
30129 Err(ErrorContext::new_missing(
30130 "TcaStatsAttrs",
30131 "Pad",
30132 self.orig_loc,
30133 self.buf.as_ptr() as usize,
30134 ))
30135 }
30136 pub fn get_basic_hw(&self) -> Result<GnetStatsBasic, ErrorContext> {
30137 let mut iter = self.clone();
30138 iter.pos = 0;
30139 for attr in iter {
30140 if let Ok(TcaStatsAttrs::BasicHw(val)) = attr {
30141 return Ok(val);
30142 }
30143 }
30144 Err(ErrorContext::new_missing(
30145 "TcaStatsAttrs",
30146 "BasicHw",
30147 self.orig_loc,
30148 self.buf.as_ptr() as usize,
30149 ))
30150 }
30151 pub fn get_pkt64(&self) -> Result<u64, ErrorContext> {
30152 let mut iter = self.clone();
30153 iter.pos = 0;
30154 for attr in iter {
30155 if let Ok(TcaStatsAttrs::Pkt64(val)) = attr {
30156 return Ok(val);
30157 }
30158 }
30159 Err(ErrorContext::new_missing(
30160 "TcaStatsAttrs",
30161 "Pkt64",
30162 self.orig_loc,
30163 self.buf.as_ptr() as usize,
30164 ))
30165 }
30166}
30167impl TcaStatsAttrs<'_> {
30168 pub fn new<'a>(buf: &'a [u8]) -> IterableTcaStatsAttrs<'a> {
30169 IterableTcaStatsAttrs::with_loc(buf, buf.as_ptr() as usize)
30170 }
30171 fn attr_from_type(r#type: u16) -> Option<&'static str> {
30172 let res = match r#type {
30173 1u16 => "Basic",
30174 2u16 => "RateEst",
30175 3u16 => "Queue",
30176 4u16 => "App",
30177 5u16 => "RateEst64",
30178 6u16 => "Pad",
30179 7u16 => "BasicHw",
30180 8u16 => "Pkt64",
30181 _ => return None,
30182 };
30183 Some(res)
30184 }
30185}
30186#[derive(Clone, Copy, Default)]
30187pub struct IterableTcaStatsAttrs<'a> {
30188 buf: &'a [u8],
30189 pos: usize,
30190 orig_loc: usize,
30191}
30192impl<'a> IterableTcaStatsAttrs<'a> {
30193 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
30194 Self {
30195 buf,
30196 pos: 0,
30197 orig_loc,
30198 }
30199 }
30200 pub fn get_buf(&self) -> &'a [u8] {
30201 self.buf
30202 }
30203}
30204impl<'a> Iterator for IterableTcaStatsAttrs<'a> {
30205 type Item = Result<TcaStatsAttrs<'a>, ErrorContext>;
30206 fn next(&mut self) -> Option<Self::Item> {
30207 let mut pos;
30208 let mut r#type;
30209 loop {
30210 pos = self.pos;
30211 r#type = None;
30212 if self.buf.len() == self.pos {
30213 return None;
30214 }
30215 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
30216 self.pos = self.buf.len();
30217 break;
30218 };
30219 r#type = Some(header.r#type);
30220 let res = match header.r#type {
30221 1u16 => TcaStatsAttrs::Basic({
30222 let res = Some(GnetStatsBasic::new_from_zeroed(next));
30223 let Some(val) = res else { break };
30224 val
30225 }),
30226 2u16 => TcaStatsAttrs::RateEst({
30227 let res = Some(GnetStatsRateEst::new_from_zeroed(next));
30228 let Some(val) = res else { break };
30229 val
30230 }),
30231 3u16 => TcaStatsAttrs::Queue({
30232 let res = Some(GnetStatsQueue::new_from_zeroed(next));
30233 let Some(val) = res else { break };
30234 val
30235 }),
30236 5u16 => TcaStatsAttrs::RateEst64({
30237 let res = Some(GnetStatsRateEst64::new_from_zeroed(next));
30238 let Some(val) = res else { break };
30239 val
30240 }),
30241 6u16 => TcaStatsAttrs::Pad({
30242 let res = Some(next);
30243 let Some(val) = res else { break };
30244 val
30245 }),
30246 7u16 => TcaStatsAttrs::BasicHw({
30247 let res = Some(GnetStatsBasic::new_from_zeroed(next));
30248 let Some(val) = res else { break };
30249 val
30250 }),
30251 8u16 => TcaStatsAttrs::Pkt64({
30252 let res = parse_u64(next);
30253 let Some(val) = res else { break };
30254 val
30255 }),
30256 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
30257 n => continue,
30258 };
30259 return Some(Ok(res));
30260 }
30261 Some(Err(ErrorContext::new(
30262 "TcaStatsAttrs",
30263 r#type.and_then(|t| TcaStatsAttrs::attr_from_type(t)),
30264 self.orig_loc,
30265 self.buf.as_ptr().wrapping_add(pos) as usize,
30266 )))
30267 }
30268}
30269impl<'a> std::fmt::Debug for IterableTcaStatsAttrs<'_> {
30270 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30271 let mut fmt = f.debug_struct("TcaStatsAttrs");
30272 for attr in self.clone() {
30273 let attr = match attr {
30274 Ok(a) => a,
30275 Err(err) => {
30276 fmt.finish()?;
30277 f.write_str("Err(")?;
30278 err.fmt(f)?;
30279 return f.write_str(")");
30280 }
30281 };
30282 match attr {
30283 TcaStatsAttrs::Basic(val) => fmt.field("Basic", &val),
30284 TcaStatsAttrs::RateEst(val) => fmt.field("RateEst", &val),
30285 TcaStatsAttrs::Queue(val) => fmt.field("Queue", &val),
30286 TcaStatsAttrs::App(val) => fmt.field("App", &val),
30287 TcaStatsAttrs::RateEst64(val) => fmt.field("RateEst64", &val),
30288 TcaStatsAttrs::Pad(val) => fmt.field("Pad", &val),
30289 TcaStatsAttrs::BasicHw(val) => fmt.field("BasicHw", &val),
30290 TcaStatsAttrs::Pkt64(val) => fmt.field("Pkt64", &val),
30291 };
30292 }
30293 fmt.finish()
30294 }
30295}
30296impl IterableTcaStatsAttrs<'_> {
30297 pub fn lookup_attr(
30298 &self,
30299 offset: usize,
30300 missing_type: Option<u16>,
30301 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
30302 let mut stack = Vec::new();
30303 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
30304 if missing_type.is_some() && cur == offset {
30305 stack.push(("TcaStatsAttrs", offset));
30306 return (
30307 stack,
30308 missing_type.and_then(|t| TcaStatsAttrs::attr_from_type(t)),
30309 );
30310 }
30311 if cur > offset || cur + self.buf.len() < offset {
30312 return (stack, None);
30313 }
30314 let mut attrs = self.clone();
30315 let mut last_off = cur + attrs.pos;
30316 while let Some(attr) = attrs.next() {
30317 let Ok(attr) = attr else { break };
30318 match attr {
30319 TcaStatsAttrs::Basic(val) => {
30320 if last_off == offset {
30321 stack.push(("Basic", last_off));
30322 break;
30323 }
30324 }
30325 TcaStatsAttrs::RateEst(val) => {
30326 if last_off == offset {
30327 stack.push(("RateEst", last_off));
30328 break;
30329 }
30330 }
30331 TcaStatsAttrs::Queue(val) => {
30332 if last_off == offset {
30333 stack.push(("Queue", last_off));
30334 break;
30335 }
30336 }
30337 TcaStatsAttrs::App(val) => {
30338 if last_off == offset {
30339 stack.push(("App", last_off));
30340 break;
30341 }
30342 }
30343 TcaStatsAttrs::RateEst64(val) => {
30344 if last_off == offset {
30345 stack.push(("RateEst64", last_off));
30346 break;
30347 }
30348 }
30349 TcaStatsAttrs::Pad(val) => {
30350 if last_off == offset {
30351 stack.push(("Pad", last_off));
30352 break;
30353 }
30354 }
30355 TcaStatsAttrs::BasicHw(val) => {
30356 if last_off == offset {
30357 stack.push(("BasicHw", last_off));
30358 break;
30359 }
30360 }
30361 TcaStatsAttrs::Pkt64(val) => {
30362 if last_off == offset {
30363 stack.push(("Pkt64", last_off));
30364 break;
30365 }
30366 }
30367 _ => {}
30368 };
30369 last_off = cur + attrs.pos;
30370 }
30371 if !stack.is_empty() {
30372 stack.push(("TcaStatsAttrs", cur));
30373 }
30374 (stack, None)
30375 }
30376}
30377#[derive(Clone)]
30378pub enum U32Attrs<'a> {
30379 Classid(u32),
30380 Hash(u32),
30381 Link(u32),
30382 Divisor(u32),
30383 Sel(TcU32Sel),
30384 Police(IterablePoliceAttrs<'a>),
30385 Act(IterableArrayActAttrs<'a>),
30386 Indev(&'a CStr),
30387 Pcnt(TcU32Pcnt),
30388 Mark(TcU32Mark),
30389 Flags(u32),
30390 Pad(&'a [u8]),
30391}
30392impl<'a> IterableU32Attrs<'a> {
30393 pub fn get_classid(&self) -> Result<u32, ErrorContext> {
30394 let mut iter = self.clone();
30395 iter.pos = 0;
30396 for attr in iter {
30397 if let Ok(U32Attrs::Classid(val)) = attr {
30398 return Ok(val);
30399 }
30400 }
30401 Err(ErrorContext::new_missing(
30402 "U32Attrs",
30403 "Classid",
30404 self.orig_loc,
30405 self.buf.as_ptr() as usize,
30406 ))
30407 }
30408 pub fn get_hash(&self) -> Result<u32, ErrorContext> {
30409 let mut iter = self.clone();
30410 iter.pos = 0;
30411 for attr in iter {
30412 if let Ok(U32Attrs::Hash(val)) = attr {
30413 return Ok(val);
30414 }
30415 }
30416 Err(ErrorContext::new_missing(
30417 "U32Attrs",
30418 "Hash",
30419 self.orig_loc,
30420 self.buf.as_ptr() as usize,
30421 ))
30422 }
30423 pub fn get_link(&self) -> Result<u32, ErrorContext> {
30424 let mut iter = self.clone();
30425 iter.pos = 0;
30426 for attr in iter {
30427 if let Ok(U32Attrs::Link(val)) = attr {
30428 return Ok(val);
30429 }
30430 }
30431 Err(ErrorContext::new_missing(
30432 "U32Attrs",
30433 "Link",
30434 self.orig_loc,
30435 self.buf.as_ptr() as usize,
30436 ))
30437 }
30438 pub fn get_divisor(&self) -> Result<u32, ErrorContext> {
30439 let mut iter = self.clone();
30440 iter.pos = 0;
30441 for attr in iter {
30442 if let Ok(U32Attrs::Divisor(val)) = attr {
30443 return Ok(val);
30444 }
30445 }
30446 Err(ErrorContext::new_missing(
30447 "U32Attrs",
30448 "Divisor",
30449 self.orig_loc,
30450 self.buf.as_ptr() as usize,
30451 ))
30452 }
30453 pub fn get_sel(&self) -> Result<TcU32Sel, ErrorContext> {
30454 let mut iter = self.clone();
30455 iter.pos = 0;
30456 for attr in iter {
30457 if let Ok(U32Attrs::Sel(val)) = attr {
30458 return Ok(val);
30459 }
30460 }
30461 Err(ErrorContext::new_missing(
30462 "U32Attrs",
30463 "Sel",
30464 self.orig_loc,
30465 self.buf.as_ptr() as usize,
30466 ))
30467 }
30468 pub fn get_police(&self) -> Result<IterablePoliceAttrs<'a>, ErrorContext> {
30469 let mut iter = self.clone();
30470 iter.pos = 0;
30471 for attr in iter {
30472 if let Ok(U32Attrs::Police(val)) = attr {
30473 return Ok(val);
30474 }
30475 }
30476 Err(ErrorContext::new_missing(
30477 "U32Attrs",
30478 "Police",
30479 self.orig_loc,
30480 self.buf.as_ptr() as usize,
30481 ))
30482 }
30483 pub fn get_act(
30484 &self,
30485 ) -> Result<ArrayIterable<IterableArrayActAttrs<'a>, IterableActAttrs<'a>>, ErrorContext> {
30486 for attr in self.clone() {
30487 if let Ok(U32Attrs::Act(val)) = attr {
30488 return Ok(ArrayIterable::new(val));
30489 }
30490 }
30491 Err(ErrorContext::new_missing(
30492 "U32Attrs",
30493 "Act",
30494 self.orig_loc,
30495 self.buf.as_ptr() as usize,
30496 ))
30497 }
30498 pub fn get_indev(&self) -> Result<&'a CStr, ErrorContext> {
30499 let mut iter = self.clone();
30500 iter.pos = 0;
30501 for attr in iter {
30502 if let Ok(U32Attrs::Indev(val)) = attr {
30503 return Ok(val);
30504 }
30505 }
30506 Err(ErrorContext::new_missing(
30507 "U32Attrs",
30508 "Indev",
30509 self.orig_loc,
30510 self.buf.as_ptr() as usize,
30511 ))
30512 }
30513 pub fn get_pcnt(&self) -> Result<TcU32Pcnt, ErrorContext> {
30514 let mut iter = self.clone();
30515 iter.pos = 0;
30516 for attr in iter {
30517 if let Ok(U32Attrs::Pcnt(val)) = attr {
30518 return Ok(val);
30519 }
30520 }
30521 Err(ErrorContext::new_missing(
30522 "U32Attrs",
30523 "Pcnt",
30524 self.orig_loc,
30525 self.buf.as_ptr() as usize,
30526 ))
30527 }
30528 pub fn get_mark(&self) -> Result<TcU32Mark, ErrorContext> {
30529 let mut iter = self.clone();
30530 iter.pos = 0;
30531 for attr in iter {
30532 if let Ok(U32Attrs::Mark(val)) = attr {
30533 return Ok(val);
30534 }
30535 }
30536 Err(ErrorContext::new_missing(
30537 "U32Attrs",
30538 "Mark",
30539 self.orig_loc,
30540 self.buf.as_ptr() as usize,
30541 ))
30542 }
30543 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
30544 let mut iter = self.clone();
30545 iter.pos = 0;
30546 for attr in iter {
30547 if let Ok(U32Attrs::Flags(val)) = attr {
30548 return Ok(val);
30549 }
30550 }
30551 Err(ErrorContext::new_missing(
30552 "U32Attrs",
30553 "Flags",
30554 self.orig_loc,
30555 self.buf.as_ptr() as usize,
30556 ))
30557 }
30558 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
30559 let mut iter = self.clone();
30560 iter.pos = 0;
30561 for attr in iter {
30562 if let Ok(U32Attrs::Pad(val)) = attr {
30563 return Ok(val);
30564 }
30565 }
30566 Err(ErrorContext::new_missing(
30567 "U32Attrs",
30568 "Pad",
30569 self.orig_loc,
30570 self.buf.as_ptr() as usize,
30571 ))
30572 }
30573}
30574impl U32Attrs<'_> {
30575 pub fn new<'a>(buf: &'a [u8]) -> IterableU32Attrs<'a> {
30576 IterableU32Attrs::with_loc(buf, buf.as_ptr() as usize)
30577 }
30578 fn attr_from_type(r#type: u16) -> Option<&'static str> {
30579 let res = match r#type {
30580 1u16 => "Classid",
30581 2u16 => "Hash",
30582 3u16 => "Link",
30583 4u16 => "Divisor",
30584 5u16 => "Sel",
30585 6u16 => "Police",
30586 7u16 => "Act",
30587 8u16 => "Indev",
30588 9u16 => "Pcnt",
30589 10u16 => "Mark",
30590 11u16 => "Flags",
30591 12u16 => "Pad",
30592 _ => return None,
30593 };
30594 Some(res)
30595 }
30596}
30597#[derive(Clone, Copy, Default)]
30598pub struct IterableU32Attrs<'a> {
30599 buf: &'a [u8],
30600 pos: usize,
30601 orig_loc: usize,
30602}
30603impl<'a> IterableU32Attrs<'a> {
30604 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
30605 Self {
30606 buf,
30607 pos: 0,
30608 orig_loc,
30609 }
30610 }
30611 pub fn get_buf(&self) -> &'a [u8] {
30612 self.buf
30613 }
30614}
30615impl<'a> Iterator for IterableU32Attrs<'a> {
30616 type Item = Result<U32Attrs<'a>, ErrorContext>;
30617 fn next(&mut self) -> Option<Self::Item> {
30618 let mut pos;
30619 let mut r#type;
30620 loop {
30621 pos = self.pos;
30622 r#type = None;
30623 if self.buf.len() == self.pos {
30624 return None;
30625 }
30626 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
30627 self.pos = self.buf.len();
30628 break;
30629 };
30630 r#type = Some(header.r#type);
30631 let res = match header.r#type {
30632 1u16 => U32Attrs::Classid({
30633 let res = parse_u32(next);
30634 let Some(val) = res else { break };
30635 val
30636 }),
30637 2u16 => U32Attrs::Hash({
30638 let res = parse_u32(next);
30639 let Some(val) = res else { break };
30640 val
30641 }),
30642 3u16 => U32Attrs::Link({
30643 let res = parse_u32(next);
30644 let Some(val) = res else { break };
30645 val
30646 }),
30647 4u16 => U32Attrs::Divisor({
30648 let res = parse_u32(next);
30649 let Some(val) = res else { break };
30650 val
30651 }),
30652 5u16 => U32Attrs::Sel({
30653 let res = Some(TcU32Sel::new_from_zeroed(next));
30654 let Some(val) = res else { break };
30655 val
30656 }),
30657 6u16 => U32Attrs::Police({
30658 let res = Some(IterablePoliceAttrs::with_loc(next, self.orig_loc));
30659 let Some(val) = res else { break };
30660 val
30661 }),
30662 7u16 => U32Attrs::Act({
30663 let res = Some(IterableArrayActAttrs::with_loc(next, self.orig_loc));
30664 let Some(val) = res else { break };
30665 val
30666 }),
30667 8u16 => U32Attrs::Indev({
30668 let res = CStr::from_bytes_with_nul(next).ok();
30669 let Some(val) = res else { break };
30670 val
30671 }),
30672 9u16 => U32Attrs::Pcnt({
30673 let res = Some(TcU32Pcnt::new_from_zeroed(next));
30674 let Some(val) = res else { break };
30675 val
30676 }),
30677 10u16 => U32Attrs::Mark({
30678 let res = Some(TcU32Mark::new_from_zeroed(next));
30679 let Some(val) = res else { break };
30680 val
30681 }),
30682 11u16 => U32Attrs::Flags({
30683 let res = parse_u32(next);
30684 let Some(val) = res else { break };
30685 val
30686 }),
30687 12u16 => U32Attrs::Pad({
30688 let res = Some(next);
30689 let Some(val) = res else { break };
30690 val
30691 }),
30692 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
30693 n => continue,
30694 };
30695 return Some(Ok(res));
30696 }
30697 Some(Err(ErrorContext::new(
30698 "U32Attrs",
30699 r#type.and_then(|t| U32Attrs::attr_from_type(t)),
30700 self.orig_loc,
30701 self.buf.as_ptr().wrapping_add(pos) as usize,
30702 )))
30703 }
30704}
30705impl<'a> std::fmt::Debug for IterableU32Attrs<'_> {
30706 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30707 let mut fmt = f.debug_struct("U32Attrs");
30708 for attr in self.clone() {
30709 let attr = match attr {
30710 Ok(a) => a,
30711 Err(err) => {
30712 fmt.finish()?;
30713 f.write_str("Err(")?;
30714 err.fmt(f)?;
30715 return f.write_str(")");
30716 }
30717 };
30718 match attr {
30719 U32Attrs::Classid(val) => fmt.field("Classid", &val),
30720 U32Attrs::Hash(val) => fmt.field("Hash", &val),
30721 U32Attrs::Link(val) => fmt.field("Link", &val),
30722 U32Attrs::Divisor(val) => fmt.field("Divisor", &val),
30723 U32Attrs::Sel(val) => fmt.field("Sel", &val),
30724 U32Attrs::Police(val) => fmt.field("Police", &val),
30725 U32Attrs::Act(val) => fmt.field("Act", &val),
30726 U32Attrs::Indev(val) => fmt.field("Indev", &val),
30727 U32Attrs::Pcnt(val) => fmt.field("Pcnt", &val),
30728 U32Attrs::Mark(val) => fmt.field("Mark", &val),
30729 U32Attrs::Flags(val) => fmt.field("Flags", &val),
30730 U32Attrs::Pad(val) => fmt.field("Pad", &val),
30731 };
30732 }
30733 fmt.finish()
30734 }
30735}
30736impl IterableU32Attrs<'_> {
30737 pub fn lookup_attr(
30738 &self,
30739 offset: usize,
30740 missing_type: Option<u16>,
30741 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
30742 let mut stack = Vec::new();
30743 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
30744 if missing_type.is_some() && cur == offset {
30745 stack.push(("U32Attrs", offset));
30746 return (
30747 stack,
30748 missing_type.and_then(|t| U32Attrs::attr_from_type(t)),
30749 );
30750 }
30751 if cur > offset || cur + self.buf.len() < offset {
30752 return (stack, None);
30753 }
30754 let mut attrs = self.clone();
30755 let mut last_off = cur + attrs.pos;
30756 let mut missing = None;
30757 while let Some(attr) = attrs.next() {
30758 let Ok(attr) = attr else { break };
30759 match attr {
30760 U32Attrs::Classid(val) => {
30761 if last_off == offset {
30762 stack.push(("Classid", last_off));
30763 break;
30764 }
30765 }
30766 U32Attrs::Hash(val) => {
30767 if last_off == offset {
30768 stack.push(("Hash", last_off));
30769 break;
30770 }
30771 }
30772 U32Attrs::Link(val) => {
30773 if last_off == offset {
30774 stack.push(("Link", last_off));
30775 break;
30776 }
30777 }
30778 U32Attrs::Divisor(val) => {
30779 if last_off == offset {
30780 stack.push(("Divisor", last_off));
30781 break;
30782 }
30783 }
30784 U32Attrs::Sel(val) => {
30785 if last_off == offset {
30786 stack.push(("Sel", last_off));
30787 break;
30788 }
30789 }
30790 U32Attrs::Police(val) => {
30791 (stack, missing) = val.lookup_attr(offset, missing_type);
30792 if !stack.is_empty() {
30793 break;
30794 }
30795 }
30796 U32Attrs::Act(val) => {
30797 for entry in val {
30798 let Ok(attr) = entry else { break };
30799 (stack, missing) = attr.lookup_attr(offset, missing_type);
30800 if !stack.is_empty() {
30801 break;
30802 }
30803 }
30804 if !stack.is_empty() {
30805 stack.push(("Act", last_off));
30806 break;
30807 }
30808 }
30809 U32Attrs::Indev(val) => {
30810 if last_off == offset {
30811 stack.push(("Indev", last_off));
30812 break;
30813 }
30814 }
30815 U32Attrs::Pcnt(val) => {
30816 if last_off == offset {
30817 stack.push(("Pcnt", last_off));
30818 break;
30819 }
30820 }
30821 U32Attrs::Mark(val) => {
30822 if last_off == offset {
30823 stack.push(("Mark", last_off));
30824 break;
30825 }
30826 }
30827 U32Attrs::Flags(val) => {
30828 if last_off == offset {
30829 stack.push(("Flags", last_off));
30830 break;
30831 }
30832 }
30833 U32Attrs::Pad(val) => {
30834 if last_off == offset {
30835 stack.push(("Pad", last_off));
30836 break;
30837 }
30838 }
30839 _ => {}
30840 };
30841 last_off = cur + attrs.pos;
30842 }
30843 if !stack.is_empty() {
30844 stack.push(("U32Attrs", cur));
30845 }
30846 (stack, missing)
30847 }
30848}
30849pub struct PushAttrs<Prev: Pusher> {
30850 pub(crate) prev: Option<Prev>,
30851 pub(crate) header_offset: Option<usize>,
30852}
30853impl<Prev: Pusher> Pusher for PushAttrs<Prev> {
30854 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
30855 self.prev.as_mut().unwrap().as_vec_mut()
30856 }
30857 fn as_vec(&self) -> &Vec<u8> {
30858 self.prev.as_ref().unwrap().as_vec()
30859 }
30860}
30861impl<Prev: Pusher> PushAttrs<Prev> {
30862 pub fn new(prev: Prev) -> Self {
30863 Self {
30864 prev: Some(prev),
30865 header_offset: None,
30866 }
30867 }
30868 pub fn end_nested(mut self) -> Prev {
30869 let mut prev = self.prev.take().unwrap();
30870 if let Some(header_offset) = &self.header_offset {
30871 finalize_nested_header(prev.as_vec_mut(), *header_offset);
30872 }
30873 prev
30874 }
30875 pub fn push_kind(mut self, value: &CStr) -> Self {
30876 push_header(
30877 self.as_vec_mut(),
30878 1u16,
30879 value.to_bytes_with_nul().len() as u16,
30880 );
30881 self.as_vec_mut().extend(value.to_bytes_with_nul());
30882 self
30883 }
30884 pub fn push_kind_bytes(mut self, value: &[u8]) -> Self {
30885 push_header(self.as_vec_mut(), 1u16, (value.len() + 1) as u16);
30886 self.as_vec_mut().extend(value);
30887 self.as_vec_mut().push(0);
30888 self
30889 }
30890 #[doc = "Selector attribute `kind` is inserted automatically."]
30891 #[doc = "At most one sub-message attribute is expected per attribute set."]
30892 pub fn nested_options_basic(mut self) -> PushBasicAttrs<PushDummy<Prev>> {
30893 self = self.push_kind(c"basic");
30894 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
30895 let dummy = PushDummy {
30896 prev: self.prev.take(),
30897 header_offset: self.header_offset.take(),
30898 };
30899 PushBasicAttrs {
30900 prev: Some(dummy),
30901 header_offset: Some(new_header_offset),
30902 }
30903 }
30904 #[doc = "Selector attribute `kind` is inserted automatically."]
30905 #[doc = "At most one sub-message attribute is expected per attribute set."]
30906 pub fn nested_options_bpf(mut self) -> PushBpfAttrs<PushDummy<Prev>> {
30907 self = self.push_kind(c"bpf");
30908 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
30909 let dummy = PushDummy {
30910 prev: self.prev.take(),
30911 header_offset: self.header_offset.take(),
30912 };
30913 PushBpfAttrs {
30914 prev: Some(dummy),
30915 header_offset: Some(new_header_offset),
30916 }
30917 }
30918 #[doc = "Selector attribute `kind` is inserted automatically."]
30919 #[doc = "At most one sub-message attribute is expected per attribute set."]
30920 pub fn nested_options_bfifo(mut self, fixed_header: &TcFifoQopt) -> Self {
30921 self = self.push_kind(c"bfifo");
30922 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
30923 self.as_vec_mut().extend(fixed_header.as_slice());
30924 self
30925 }
30926 #[doc = "Selector attribute `kind` is inserted automatically."]
30927 #[doc = "At most one sub-message attribute is expected per attribute set."]
30928 pub fn nested_options_cake(mut self) -> PushCakeAttrs<PushDummy<Prev>> {
30929 self = self.push_kind(c"cake");
30930 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
30931 let dummy = PushDummy {
30932 prev: self.prev.take(),
30933 header_offset: self.header_offset.take(),
30934 };
30935 PushCakeAttrs {
30936 prev: Some(dummy),
30937 header_offset: Some(new_header_offset),
30938 }
30939 }
30940 #[doc = "Selector attribute `kind` is inserted automatically."]
30941 #[doc = "At most one sub-message attribute is expected per attribute set."]
30942 pub fn nested_options_cbs(mut self) -> PushCbsAttrs<PushDummy<Prev>> {
30943 self = self.push_kind(c"cbs");
30944 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
30945 let dummy = PushDummy {
30946 prev: self.prev.take(),
30947 header_offset: self.header_offset.take(),
30948 };
30949 PushCbsAttrs {
30950 prev: Some(dummy),
30951 header_offset: Some(new_header_offset),
30952 }
30953 }
30954 #[doc = "Selector attribute `kind` is inserted automatically."]
30955 #[doc = "At most one sub-message attribute is expected per attribute set."]
30956 pub fn nested_options_cgroup(mut self) -> PushCgroupAttrs<PushDummy<Prev>> {
30957 self = self.push_kind(c"cgroup");
30958 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
30959 let dummy = PushDummy {
30960 prev: self.prev.take(),
30961 header_offset: self.header_offset.take(),
30962 };
30963 PushCgroupAttrs {
30964 prev: Some(dummy),
30965 header_offset: Some(new_header_offset),
30966 }
30967 }
30968 #[doc = "Selector attribute `kind` is inserted automatically."]
30969 #[doc = "At most one sub-message attribute is expected per attribute set."]
30970 pub fn nested_options_choke(mut self) -> PushChokeAttrs<PushDummy<Prev>> {
30971 self = self.push_kind(c"choke");
30972 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
30973 let dummy = PushDummy {
30974 prev: self.prev.take(),
30975 header_offset: self.header_offset.take(),
30976 };
30977 PushChokeAttrs {
30978 prev: Some(dummy),
30979 header_offset: Some(new_header_offset),
30980 }
30981 }
30982 #[doc = "Selector attribute `kind` is inserted automatically."]
30983 #[doc = "At most one sub-message attribute is expected per attribute set."]
30984 pub fn nested_options_clsact(mut self) -> Self {
30985 self = self.push_kind(c"clsact");
30986 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
30987 self
30988 }
30989 #[doc = "Selector attribute `kind` is inserted automatically."]
30990 #[doc = "At most one sub-message attribute is expected per attribute set."]
30991 pub fn nested_options_codel(mut self) -> PushCodelAttrs<PushDummy<Prev>> {
30992 self = self.push_kind(c"codel");
30993 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
30994 let dummy = PushDummy {
30995 prev: self.prev.take(),
30996 header_offset: self.header_offset.take(),
30997 };
30998 PushCodelAttrs {
30999 prev: Some(dummy),
31000 header_offset: Some(new_header_offset),
31001 }
31002 }
31003 #[doc = "Selector attribute `kind` is inserted automatically."]
31004 #[doc = "At most one sub-message attribute is expected per attribute set."]
31005 pub fn nested_options_drr(mut self) -> PushDrrAttrs<PushDummy<Prev>> {
31006 self = self.push_kind(c"drr");
31007 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31008 let dummy = PushDummy {
31009 prev: self.prev.take(),
31010 header_offset: self.header_offset.take(),
31011 };
31012 PushDrrAttrs {
31013 prev: Some(dummy),
31014 header_offset: Some(new_header_offset),
31015 }
31016 }
31017 #[doc = "Selector attribute `kind` is inserted automatically."]
31018 #[doc = "At most one sub-message attribute is expected per attribute set."]
31019 pub fn nested_options_dualpi2(mut self) -> PushDualpi2Attrs<PushDummy<Prev>> {
31020 self = self.push_kind(c"dualpi2");
31021 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31022 let dummy = PushDummy {
31023 prev: self.prev.take(),
31024 header_offset: self.header_offset.take(),
31025 };
31026 PushDualpi2Attrs {
31027 prev: Some(dummy),
31028 header_offset: Some(new_header_offset),
31029 }
31030 }
31031 #[doc = "Selector attribute `kind` is inserted automatically."]
31032 #[doc = "At most one sub-message attribute is expected per attribute set."]
31033 pub fn nested_options_etf(mut self) -> PushEtfAttrs<PushDummy<Prev>> {
31034 self = self.push_kind(c"etf");
31035 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31036 let dummy = PushDummy {
31037 prev: self.prev.take(),
31038 header_offset: self.header_offset.take(),
31039 };
31040 PushEtfAttrs {
31041 prev: Some(dummy),
31042 header_offset: Some(new_header_offset),
31043 }
31044 }
31045 #[doc = "Selector attribute `kind` is inserted automatically."]
31046 #[doc = "At most one sub-message attribute is expected per attribute set."]
31047 pub fn nested_options_ets(mut self) -> PushEtsAttrs<PushDummy<Prev>> {
31048 self = self.push_kind(c"ets");
31049 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31050 let dummy = PushDummy {
31051 prev: self.prev.take(),
31052 header_offset: self.header_offset.take(),
31053 };
31054 PushEtsAttrs {
31055 prev: Some(dummy),
31056 header_offset: Some(new_header_offset),
31057 }
31058 }
31059 #[doc = "Selector attribute `kind` is inserted automatically."]
31060 #[doc = "At most one sub-message attribute is expected per attribute set."]
31061 pub fn nested_options_flow(mut self) -> PushFlowAttrs<PushDummy<Prev>> {
31062 self = self.push_kind(c"flow");
31063 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31064 let dummy = PushDummy {
31065 prev: self.prev.take(),
31066 header_offset: self.header_offset.take(),
31067 };
31068 PushFlowAttrs {
31069 prev: Some(dummy),
31070 header_offset: Some(new_header_offset),
31071 }
31072 }
31073 #[doc = "Selector attribute `kind` is inserted automatically."]
31074 #[doc = "At most one sub-message attribute is expected per attribute set."]
31075 pub fn nested_options_flower(mut self) -> PushFlowerAttrs<PushDummy<Prev>> {
31076 self = self.push_kind(c"flower");
31077 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31078 let dummy = PushDummy {
31079 prev: self.prev.take(),
31080 header_offset: self.header_offset.take(),
31081 };
31082 PushFlowerAttrs {
31083 prev: Some(dummy),
31084 header_offset: Some(new_header_offset),
31085 }
31086 }
31087 #[doc = "Selector attribute `kind` is inserted automatically."]
31088 #[doc = "At most one sub-message attribute is expected per attribute set."]
31089 pub fn nested_options_fq(mut self) -> PushFqAttrs<PushDummy<Prev>> {
31090 self = self.push_kind(c"fq");
31091 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31092 let dummy = PushDummy {
31093 prev: self.prev.take(),
31094 header_offset: self.header_offset.take(),
31095 };
31096 PushFqAttrs {
31097 prev: Some(dummy),
31098 header_offset: Some(new_header_offset),
31099 }
31100 }
31101 #[doc = "Selector attribute `kind` is inserted automatically."]
31102 #[doc = "At most one sub-message attribute is expected per attribute set."]
31103 pub fn nested_options_fq_codel(mut self) -> PushFqCodelAttrs<PushDummy<Prev>> {
31104 self = self.push_kind(c"fq_codel");
31105 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31106 let dummy = PushDummy {
31107 prev: self.prev.take(),
31108 header_offset: self.header_offset.take(),
31109 };
31110 PushFqCodelAttrs {
31111 prev: Some(dummy),
31112 header_offset: Some(new_header_offset),
31113 }
31114 }
31115 #[doc = "Selector attribute `kind` is inserted automatically."]
31116 #[doc = "At most one sub-message attribute is expected per attribute set."]
31117 pub fn nested_options_fq_pie(mut self) -> PushFqPieAttrs<PushDummy<Prev>> {
31118 self = self.push_kind(c"fq_pie");
31119 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31120 let dummy = PushDummy {
31121 prev: self.prev.take(),
31122 header_offset: self.header_offset.take(),
31123 };
31124 PushFqPieAttrs {
31125 prev: Some(dummy),
31126 header_offset: Some(new_header_offset),
31127 }
31128 }
31129 #[doc = "Selector attribute `kind` is inserted automatically."]
31130 #[doc = "At most one sub-message attribute is expected per attribute set."]
31131 pub fn nested_options_fw(mut self) -> PushFwAttrs<PushDummy<Prev>> {
31132 self = self.push_kind(c"fw");
31133 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31134 let dummy = PushDummy {
31135 prev: self.prev.take(),
31136 header_offset: self.header_offset.take(),
31137 };
31138 PushFwAttrs {
31139 prev: Some(dummy),
31140 header_offset: Some(new_header_offset),
31141 }
31142 }
31143 #[doc = "Selector attribute `kind` is inserted automatically."]
31144 #[doc = "At most one sub-message attribute is expected per attribute set."]
31145 pub fn nested_options_gred(mut self) -> PushGredAttrs<PushDummy<Prev>> {
31146 self = self.push_kind(c"gred");
31147 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31148 let dummy = PushDummy {
31149 prev: self.prev.take(),
31150 header_offset: self.header_offset.take(),
31151 };
31152 PushGredAttrs {
31153 prev: Some(dummy),
31154 header_offset: Some(new_header_offset),
31155 }
31156 }
31157 #[doc = "Selector attribute `kind` is inserted automatically."]
31158 #[doc = "At most one sub-message attribute is expected per attribute set."]
31159 pub fn nested_options_hfsc(mut self, fixed_header: &TcHfscQopt) -> Self {
31160 self = self.push_kind(c"hfsc");
31161 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31162 self.as_vec_mut().extend(fixed_header.as_slice());
31163 self
31164 }
31165 #[doc = "Selector attribute `kind` is inserted automatically."]
31166 #[doc = "At most one sub-message attribute is expected per attribute set."]
31167 pub fn nested_options_hhf(mut self) -> PushHhfAttrs<PushDummy<Prev>> {
31168 self = self.push_kind(c"hhf");
31169 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31170 let dummy = PushDummy {
31171 prev: self.prev.take(),
31172 header_offset: self.header_offset.take(),
31173 };
31174 PushHhfAttrs {
31175 prev: Some(dummy),
31176 header_offset: Some(new_header_offset),
31177 }
31178 }
31179 #[doc = "Selector attribute `kind` is inserted automatically."]
31180 #[doc = "At most one sub-message attribute is expected per attribute set."]
31181 pub fn nested_options_htb(mut self) -> PushHtbAttrs<PushDummy<Prev>> {
31182 self = self.push_kind(c"htb");
31183 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31184 let dummy = PushDummy {
31185 prev: self.prev.take(),
31186 header_offset: self.header_offset.take(),
31187 };
31188 PushHtbAttrs {
31189 prev: Some(dummy),
31190 header_offset: Some(new_header_offset),
31191 }
31192 }
31193 #[doc = "Selector attribute `kind` is inserted automatically."]
31194 #[doc = "At most one sub-message attribute is expected per attribute set."]
31195 pub fn nested_options_ingress(mut self) -> Self {
31196 self = self.push_kind(c"ingress");
31197 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31198 self
31199 }
31200 #[doc = "Selector attribute `kind` is inserted automatically."]
31201 #[doc = "At most one sub-message attribute is expected per attribute set."]
31202 pub fn nested_options_matchall(mut self) -> PushMatchallAttrs<PushDummy<Prev>> {
31203 self = self.push_kind(c"matchall");
31204 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31205 let dummy = PushDummy {
31206 prev: self.prev.take(),
31207 header_offset: self.header_offset.take(),
31208 };
31209 PushMatchallAttrs {
31210 prev: Some(dummy),
31211 header_offset: Some(new_header_offset),
31212 }
31213 }
31214 #[doc = "Selector attribute `kind` is inserted automatically."]
31215 #[doc = "At most one sub-message attribute is expected per attribute set."]
31216 pub fn nested_options_mq(mut self) -> Self {
31217 self = self.push_kind(c"mq");
31218 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31219 self
31220 }
31221 #[doc = "Selector attribute `kind` is inserted automatically."]
31222 #[doc = "At most one sub-message attribute is expected per attribute set."]
31223 pub fn nested_options_mqprio(mut self, fixed_header: &TcMqprioQopt) -> Self {
31224 self = self.push_kind(c"mqprio");
31225 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31226 self.as_vec_mut().extend(fixed_header.as_slice());
31227 self
31228 }
31229 #[doc = "Selector attribute `kind` is inserted automatically."]
31230 #[doc = "At most one sub-message attribute is expected per attribute set."]
31231 pub fn nested_options_multiq(mut self, fixed_header: &TcMultiqQopt) -> Self {
31232 self = self.push_kind(c"multiq");
31233 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31234 self.as_vec_mut().extend(fixed_header.as_slice());
31235 self
31236 }
31237 #[doc = "Selector attribute `kind` is inserted automatically."]
31238 #[doc = "At most one sub-message attribute is expected per attribute set."]
31239 pub fn nested_options_netem(
31240 mut self,
31241 fixed_header: &TcNetemQopt,
31242 ) -> PushNetemAttrs<PushDummy<Prev>> {
31243 self = self.push_kind(c"netem");
31244 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31245 self.as_vec_mut().extend(fixed_header.as_slice());
31246 let dummy = PushDummy {
31247 prev: self.prev.take(),
31248 header_offset: self.header_offset.take(),
31249 };
31250 PushNetemAttrs {
31251 prev: Some(dummy),
31252 header_offset: Some(new_header_offset),
31253 }
31254 }
31255 #[doc = "Selector attribute `kind` is inserted automatically."]
31256 #[doc = "At most one sub-message attribute is expected per attribute set."]
31257 pub fn nested_options_pfifo(mut self, fixed_header: &TcFifoQopt) -> Self {
31258 self = self.push_kind(c"pfifo");
31259 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31260 self.as_vec_mut().extend(fixed_header.as_slice());
31261 self
31262 }
31263 #[doc = "Selector attribute `kind` is inserted automatically."]
31264 #[doc = "At most one sub-message attribute is expected per attribute set."]
31265 pub fn nested_options_pfifo_fast(mut self, fixed_header: &TcPrioQopt) -> Self {
31266 self = self.push_kind(c"pfifo_fast");
31267 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31268 self.as_vec_mut().extend(fixed_header.as_slice());
31269 self
31270 }
31271 #[doc = "Selector attribute `kind` is inserted automatically."]
31272 #[doc = "At most one sub-message attribute is expected per attribute set."]
31273 pub fn nested_options_pfifo_head_drop(mut self, fixed_header: &TcFifoQopt) -> Self {
31274 self = self.push_kind(c"pfifo_head_drop");
31275 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31276 self.as_vec_mut().extend(fixed_header.as_slice());
31277 self
31278 }
31279 #[doc = "Selector attribute `kind` is inserted automatically."]
31280 #[doc = "At most one sub-message attribute is expected per attribute set."]
31281 pub fn nested_options_pie(mut self) -> PushPieAttrs<PushDummy<Prev>> {
31282 self = self.push_kind(c"pie");
31283 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31284 let dummy = PushDummy {
31285 prev: self.prev.take(),
31286 header_offset: self.header_offset.take(),
31287 };
31288 PushPieAttrs {
31289 prev: Some(dummy),
31290 header_offset: Some(new_header_offset),
31291 }
31292 }
31293 #[doc = "Selector attribute `kind` is inserted automatically."]
31294 #[doc = "At most one sub-message attribute is expected per attribute set."]
31295 pub fn nested_options_plug(mut self, fixed_header: &TcPlugQopt) -> Self {
31296 self = self.push_kind(c"plug");
31297 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31298 self.as_vec_mut().extend(fixed_header.as_slice());
31299 self
31300 }
31301 #[doc = "Selector attribute `kind` is inserted automatically."]
31302 #[doc = "At most one sub-message attribute is expected per attribute set."]
31303 pub fn nested_options_prio(mut self, fixed_header: &TcPrioQopt) -> Self {
31304 self = self.push_kind(c"prio");
31305 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31306 self.as_vec_mut().extend(fixed_header.as_slice());
31307 self
31308 }
31309 #[doc = "Selector attribute `kind` is inserted automatically."]
31310 #[doc = "At most one sub-message attribute is expected per attribute set."]
31311 pub fn nested_options_qfq(mut self) -> PushQfqAttrs<PushDummy<Prev>> {
31312 self = self.push_kind(c"qfq");
31313 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31314 let dummy = PushDummy {
31315 prev: self.prev.take(),
31316 header_offset: self.header_offset.take(),
31317 };
31318 PushQfqAttrs {
31319 prev: Some(dummy),
31320 header_offset: Some(new_header_offset),
31321 }
31322 }
31323 #[doc = "Selector attribute `kind` is inserted automatically."]
31324 #[doc = "At most one sub-message attribute is expected per attribute set."]
31325 pub fn nested_options_red(mut self) -> PushRedAttrs<PushDummy<Prev>> {
31326 self = self.push_kind(c"red");
31327 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31328 let dummy = PushDummy {
31329 prev: self.prev.take(),
31330 header_offset: self.header_offset.take(),
31331 };
31332 PushRedAttrs {
31333 prev: Some(dummy),
31334 header_offset: Some(new_header_offset),
31335 }
31336 }
31337 #[doc = "Selector attribute `kind` is inserted automatically."]
31338 #[doc = "At most one sub-message attribute is expected per attribute set."]
31339 pub fn nested_options_route(mut self) -> PushRouteAttrs<PushDummy<Prev>> {
31340 self = self.push_kind(c"route");
31341 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31342 let dummy = PushDummy {
31343 prev: self.prev.take(),
31344 header_offset: self.header_offset.take(),
31345 };
31346 PushRouteAttrs {
31347 prev: Some(dummy),
31348 header_offset: Some(new_header_offset),
31349 }
31350 }
31351 #[doc = "Selector attribute `kind` is inserted automatically."]
31352 #[doc = "At most one sub-message attribute is expected per attribute set."]
31353 pub fn nested_options_sfb(mut self, fixed_header: &TcSfbQopt) -> Self {
31354 self = self.push_kind(c"sfb");
31355 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31356 self.as_vec_mut().extend(fixed_header.as_slice());
31357 self
31358 }
31359 #[doc = "Selector attribute `kind` is inserted automatically."]
31360 #[doc = "At most one sub-message attribute is expected per attribute set."]
31361 pub fn nested_options_sfq(mut self, fixed_header: &TcSfqQoptV1) -> Self {
31362 self = self.push_kind(c"sfq");
31363 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 2u16));
31364 self.as_vec_mut().extend(fixed_header.as_slice());
31365 self
31366 }
31367 #[doc = "Selector attribute `kind` is inserted automatically."]
31368 #[doc = "At most one sub-message attribute is expected per attribute set."]
31369 pub fn nested_options_taprio(mut self) -> PushTaprioAttrs<PushDummy<Prev>> {
31370 self = self.push_kind(c"taprio");
31371 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31372 let dummy = PushDummy {
31373 prev: self.prev.take(),
31374 header_offset: self.header_offset.take(),
31375 };
31376 PushTaprioAttrs {
31377 prev: Some(dummy),
31378 header_offset: Some(new_header_offset),
31379 }
31380 }
31381 #[doc = "Selector attribute `kind` is inserted automatically."]
31382 #[doc = "At most one sub-message attribute is expected per attribute set."]
31383 pub fn nested_options_tbf(mut self) -> PushTbfAttrs<PushDummy<Prev>> {
31384 self = self.push_kind(c"tbf");
31385 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31386 let dummy = PushDummy {
31387 prev: self.prev.take(),
31388 header_offset: self.header_offset.take(),
31389 };
31390 PushTbfAttrs {
31391 prev: Some(dummy),
31392 header_offset: Some(new_header_offset),
31393 }
31394 }
31395 #[doc = "Selector attribute `kind` is inserted automatically."]
31396 #[doc = "At most one sub-message attribute is expected per attribute set."]
31397 pub fn nested_options_u32(mut self) -> PushU32Attrs<PushDummy<Prev>> {
31398 self = self.push_kind(c"u32");
31399 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31400 let dummy = PushDummy {
31401 prev: self.prev.take(),
31402 header_offset: self.header_offset.take(),
31403 };
31404 PushU32Attrs {
31405 prev: Some(dummy),
31406 header_offset: Some(new_header_offset),
31407 }
31408 }
31409 pub fn push_stats(mut self, value: TcStats) -> Self {
31410 push_header(self.as_vec_mut(), 3u16, value.as_slice().len() as u16);
31411 self.as_vec_mut().extend(value.as_slice());
31412 self
31413 }
31414 #[doc = "Selector attribute `kind` is inserted automatically."]
31415 #[doc = "At most one sub-message attribute is expected per attribute set."]
31416 pub fn nested_xstats_cake(mut self) -> PushCakeStatsAttrs<PushDummy<Prev>> {
31417 self = self.push_kind(c"cake");
31418 let new_header_offset = push_nested_header(self.as_vec_mut(), 4u16);
31419 let dummy = PushDummy {
31420 prev: self.prev.take(),
31421 header_offset: self.header_offset.take(),
31422 };
31423 PushCakeStatsAttrs {
31424 prev: Some(dummy),
31425 header_offset: Some(new_header_offset),
31426 }
31427 }
31428 #[doc = "Selector attribute `kind` is inserted automatically."]
31429 #[doc = "At most one sub-message attribute is expected per attribute set."]
31430 pub fn nested_xstats_choke(mut self, fixed_header: &TcChokeXstats) -> Self {
31431 self = self.push_kind(c"choke");
31432 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31433 self.as_vec_mut().extend(fixed_header.as_slice());
31434 self
31435 }
31436 #[doc = "Selector attribute `kind` is inserted automatically."]
31437 #[doc = "At most one sub-message attribute is expected per attribute set."]
31438 pub fn nested_xstats_codel(mut self, fixed_header: &TcCodelXstats) -> Self {
31439 self = self.push_kind(c"codel");
31440 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31441 self.as_vec_mut().extend(fixed_header.as_slice());
31442 self
31443 }
31444 #[doc = "Selector attribute `kind` is inserted automatically."]
31445 #[doc = "At most one sub-message attribute is expected per attribute set."]
31446 pub fn nested_xstats_dualpi2(mut self, fixed_header: &TcDualpi2Xstats) -> Self {
31447 self = self.push_kind(c"dualpi2");
31448 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31449 self.as_vec_mut().extend(fixed_header.as_slice());
31450 self
31451 }
31452 #[doc = "Selector attribute `kind` is inserted automatically."]
31453 #[doc = "At most one sub-message attribute is expected per attribute set."]
31454 pub fn nested_xstats_fq(mut self, fixed_header: &TcFqQdStats) -> Self {
31455 self = self.push_kind(c"fq");
31456 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31457 self.as_vec_mut().extend(fixed_header.as_slice());
31458 self
31459 }
31460 #[doc = "Selector attribute `kind` is inserted automatically."]
31461 #[doc = "At most one sub-message attribute is expected per attribute set."]
31462 pub fn nested_xstats_fq_codel(mut self, fixed_header: &TcFqCodelXstats) -> Self {
31463 self = self.push_kind(c"fq_codel");
31464 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31465 self.as_vec_mut().extend(fixed_header.as_slice());
31466 self
31467 }
31468 #[doc = "Selector attribute `kind` is inserted automatically."]
31469 #[doc = "At most one sub-message attribute is expected per attribute set."]
31470 pub fn nested_xstats_fq_pie(mut self, fixed_header: &TcFqPieXstats) -> Self {
31471 self = self.push_kind(c"fq_pie");
31472 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31473 self.as_vec_mut().extend(fixed_header.as_slice());
31474 self
31475 }
31476 #[doc = "Selector attribute `kind` is inserted automatically."]
31477 #[doc = "At most one sub-message attribute is expected per attribute set."]
31478 pub fn nested_xstats_hhf(mut self, fixed_header: &TcHhfXstats) -> Self {
31479 self = self.push_kind(c"hhf");
31480 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31481 self.as_vec_mut().extend(fixed_header.as_slice());
31482 self
31483 }
31484 #[doc = "Selector attribute `kind` is inserted automatically."]
31485 #[doc = "At most one sub-message attribute is expected per attribute set."]
31486 pub fn nested_xstats_pie(mut self, fixed_header: &TcPieXstats) -> Self {
31487 self = self.push_kind(c"pie");
31488 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31489 self.as_vec_mut().extend(fixed_header.as_slice());
31490 self
31491 }
31492 #[doc = "Selector attribute `kind` is inserted automatically."]
31493 #[doc = "At most one sub-message attribute is expected per attribute set."]
31494 pub fn nested_xstats_red(mut self, fixed_header: &TcRedXstats) -> Self {
31495 self = self.push_kind(c"red");
31496 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31497 self.as_vec_mut().extend(fixed_header.as_slice());
31498 self
31499 }
31500 #[doc = "Selector attribute `kind` is inserted automatically."]
31501 #[doc = "At most one sub-message attribute is expected per attribute set."]
31502 pub fn nested_xstats_sfb(mut self, fixed_header: &TcSfbXstats) -> Self {
31503 self = self.push_kind(c"sfb");
31504 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31505 self.as_vec_mut().extend(fixed_header.as_slice());
31506 self
31507 }
31508 #[doc = "Selector attribute `kind` is inserted automatically."]
31509 #[doc = "At most one sub-message attribute is expected per attribute set."]
31510 pub fn nested_xstats_sfq(mut self, fixed_header: &TcSfqXstats) -> Self {
31511 self = self.push_kind(c"sfq");
31512 self.header_offset = Some(push_nested_header(self.as_vec_mut(), 4u16));
31513 self.as_vec_mut().extend(fixed_header.as_slice());
31514 self
31515 }
31516 pub fn push_rate(mut self, value: GnetEstimator) -> Self {
31517 push_header(self.as_vec_mut(), 5u16, value.as_slice().len() as u16);
31518 self.as_vec_mut().extend(value.as_slice());
31519 self
31520 }
31521 pub fn push_fcnt(mut self, value: u32) -> Self {
31522 push_header(self.as_vec_mut(), 6u16, 4 as u16);
31523 self.as_vec_mut().extend(value.to_ne_bytes());
31524 self
31525 }
31526 pub fn nested_stats2(mut self) -> PushTcaStatsAttrs<Self> {
31527 let header_offset = push_nested_header(self.as_vec_mut(), 7u16);
31528 PushTcaStatsAttrs {
31529 prev: Some(self),
31530 header_offset: Some(header_offset),
31531 }
31532 }
31533 pub fn nested_stab(mut self) -> PushTcaStabAttrs<Self> {
31534 let header_offset = push_nested_header(self.as_vec_mut(), 8u16);
31535 PushTcaStabAttrs {
31536 prev: Some(self),
31537 header_offset: Some(header_offset),
31538 }
31539 }
31540 pub fn push_pad(mut self, value: &[u8]) -> Self {
31541 push_header(self.as_vec_mut(), 9u16, value.len() as u16);
31542 self.as_vec_mut().extend(value);
31543 self
31544 }
31545 pub fn push_dump_invisible(mut self, value: ()) -> Self {
31546 push_header(self.as_vec_mut(), 10u16, 0 as u16);
31547 self
31548 }
31549 pub fn push_chain(mut self, value: u32) -> Self {
31550 push_header(self.as_vec_mut(), 11u16, 4 as u16);
31551 self.as_vec_mut().extend(value.to_ne_bytes());
31552 self
31553 }
31554 pub fn push_hw_offload(mut self, value: u8) -> Self {
31555 push_header(self.as_vec_mut(), 12u16, 1 as u16);
31556 self.as_vec_mut().extend(value.to_ne_bytes());
31557 self
31558 }
31559 pub fn push_ingress_block(mut self, value: u32) -> Self {
31560 push_header(self.as_vec_mut(), 13u16, 4 as u16);
31561 self.as_vec_mut().extend(value.to_ne_bytes());
31562 self
31563 }
31564 pub fn push_egress_block(mut self, value: u32) -> Self {
31565 push_header(self.as_vec_mut(), 14u16, 4 as u16);
31566 self.as_vec_mut().extend(value.to_ne_bytes());
31567 self
31568 }
31569 pub fn push_dump_flags(mut self, value: BuiltinBitfield32) -> Self {
31570 push_header(self.as_vec_mut(), 15u16, value.as_slice().len() as u16);
31571 self.as_vec_mut().extend(value.as_slice());
31572 self
31573 }
31574 pub fn push_ext_warn_msg(mut self, value: &CStr) -> Self {
31575 push_header(
31576 self.as_vec_mut(),
31577 16u16,
31578 value.to_bytes_with_nul().len() as u16,
31579 );
31580 self.as_vec_mut().extend(value.to_bytes_with_nul());
31581 self
31582 }
31583 pub fn push_ext_warn_msg_bytes(mut self, value: &[u8]) -> Self {
31584 push_header(self.as_vec_mut(), 16u16, (value.len() + 1) as u16);
31585 self.as_vec_mut().extend(value);
31586 self.as_vec_mut().push(0);
31587 self
31588 }
31589}
31590impl<Prev: Pusher> Drop for PushAttrs<Prev> {
31591 fn drop(&mut self) {
31592 if let Some(prev) = &mut self.prev {
31593 if let Some(header_offset) = &self.header_offset {
31594 finalize_nested_header(prev.as_vec_mut(), *header_offset);
31595 }
31596 }
31597 }
31598}
31599pub struct PushActAttrs<Prev: Pusher> {
31600 pub(crate) prev: Option<Prev>,
31601 pub(crate) header_offset: Option<usize>,
31602}
31603impl<Prev: Pusher> Pusher for PushActAttrs<Prev> {
31604 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
31605 self.prev.as_mut().unwrap().as_vec_mut()
31606 }
31607 fn as_vec(&self) -> &Vec<u8> {
31608 self.prev.as_ref().unwrap().as_vec()
31609 }
31610}
31611impl<Prev: Pusher> PushActAttrs<Prev> {
31612 pub fn new(prev: Prev) -> Self {
31613 Self {
31614 prev: Some(prev),
31615 header_offset: None,
31616 }
31617 }
31618 pub fn end_nested(mut self) -> Prev {
31619 let mut prev = self.prev.take().unwrap();
31620 if let Some(header_offset) = &self.header_offset {
31621 finalize_nested_header(prev.as_vec_mut(), *header_offset);
31622 }
31623 prev
31624 }
31625 pub fn push_kind(mut self, value: &CStr) -> Self {
31626 push_header(
31627 self.as_vec_mut(),
31628 1u16,
31629 value.to_bytes_with_nul().len() as u16,
31630 );
31631 self.as_vec_mut().extend(value.to_bytes_with_nul());
31632 self
31633 }
31634 pub fn push_kind_bytes(mut self, value: &[u8]) -> Self {
31635 push_header(self.as_vec_mut(), 1u16, (value.len() + 1) as u16);
31636 self.as_vec_mut().extend(value);
31637 self.as_vec_mut().push(0);
31638 self
31639 }
31640 #[doc = "Selector attribute `kind` is inserted automatically."]
31641 #[doc = "At most one sub-message attribute is expected per attribute set."]
31642 pub fn nested_options_bpf(mut self) -> PushActBpfAttrs<PushDummy<Prev>> {
31643 self = self.push_kind(c"bpf");
31644 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31645 let dummy = PushDummy {
31646 prev: self.prev.take(),
31647 header_offset: self.header_offset.take(),
31648 };
31649 PushActBpfAttrs {
31650 prev: Some(dummy),
31651 header_offset: Some(new_header_offset),
31652 }
31653 }
31654 #[doc = "Selector attribute `kind` is inserted automatically."]
31655 #[doc = "At most one sub-message attribute is expected per attribute set."]
31656 pub fn nested_options_connmark(mut self) -> PushActConnmarkAttrs<PushDummy<Prev>> {
31657 self = self.push_kind(c"connmark");
31658 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31659 let dummy = PushDummy {
31660 prev: self.prev.take(),
31661 header_offset: self.header_offset.take(),
31662 };
31663 PushActConnmarkAttrs {
31664 prev: Some(dummy),
31665 header_offset: Some(new_header_offset),
31666 }
31667 }
31668 #[doc = "Selector attribute `kind` is inserted automatically."]
31669 #[doc = "At most one sub-message attribute is expected per attribute set."]
31670 pub fn nested_options_csum(mut self) -> PushActCsumAttrs<PushDummy<Prev>> {
31671 self = self.push_kind(c"csum");
31672 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31673 let dummy = PushDummy {
31674 prev: self.prev.take(),
31675 header_offset: self.header_offset.take(),
31676 };
31677 PushActCsumAttrs {
31678 prev: Some(dummy),
31679 header_offset: Some(new_header_offset),
31680 }
31681 }
31682 #[doc = "Selector attribute `kind` is inserted automatically."]
31683 #[doc = "At most one sub-message attribute is expected per attribute set."]
31684 pub fn nested_options_ct(mut self) -> PushActCtAttrs<PushDummy<Prev>> {
31685 self = self.push_kind(c"ct");
31686 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31687 let dummy = PushDummy {
31688 prev: self.prev.take(),
31689 header_offset: self.header_offset.take(),
31690 };
31691 PushActCtAttrs {
31692 prev: Some(dummy),
31693 header_offset: Some(new_header_offset),
31694 }
31695 }
31696 #[doc = "Selector attribute `kind` is inserted automatically."]
31697 #[doc = "At most one sub-message attribute is expected per attribute set."]
31698 pub fn nested_options_ctinfo(mut self) -> PushActCtinfoAttrs<PushDummy<Prev>> {
31699 self = self.push_kind(c"ctinfo");
31700 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31701 let dummy = PushDummy {
31702 prev: self.prev.take(),
31703 header_offset: self.header_offset.take(),
31704 };
31705 PushActCtinfoAttrs {
31706 prev: Some(dummy),
31707 header_offset: Some(new_header_offset),
31708 }
31709 }
31710 #[doc = "Selector attribute `kind` is inserted automatically."]
31711 #[doc = "At most one sub-message attribute is expected per attribute set."]
31712 pub fn nested_options_gact(mut self) -> PushActGactAttrs<PushDummy<Prev>> {
31713 self = self.push_kind(c"gact");
31714 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31715 let dummy = PushDummy {
31716 prev: self.prev.take(),
31717 header_offset: self.header_offset.take(),
31718 };
31719 PushActGactAttrs {
31720 prev: Some(dummy),
31721 header_offset: Some(new_header_offset),
31722 }
31723 }
31724 #[doc = "Selector attribute `kind` is inserted automatically."]
31725 #[doc = "At most one sub-message attribute is expected per attribute set."]
31726 pub fn nested_options_gate(mut self) -> PushActGateAttrs<PushDummy<Prev>> {
31727 self = self.push_kind(c"gate");
31728 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31729 let dummy = PushDummy {
31730 prev: self.prev.take(),
31731 header_offset: self.header_offset.take(),
31732 };
31733 PushActGateAttrs {
31734 prev: Some(dummy),
31735 header_offset: Some(new_header_offset),
31736 }
31737 }
31738 #[doc = "Selector attribute `kind` is inserted automatically."]
31739 #[doc = "At most one sub-message attribute is expected per attribute set."]
31740 pub fn nested_options_ife(mut self) -> PushActIfeAttrs<PushDummy<Prev>> {
31741 self = self.push_kind(c"ife");
31742 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31743 let dummy = PushDummy {
31744 prev: self.prev.take(),
31745 header_offset: self.header_offset.take(),
31746 };
31747 PushActIfeAttrs {
31748 prev: Some(dummy),
31749 header_offset: Some(new_header_offset),
31750 }
31751 }
31752 #[doc = "Selector attribute `kind` is inserted automatically."]
31753 #[doc = "At most one sub-message attribute is expected per attribute set."]
31754 pub fn nested_options_mirred(mut self) -> PushActMirredAttrs<PushDummy<Prev>> {
31755 self = self.push_kind(c"mirred");
31756 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31757 let dummy = PushDummy {
31758 prev: self.prev.take(),
31759 header_offset: self.header_offset.take(),
31760 };
31761 PushActMirredAttrs {
31762 prev: Some(dummy),
31763 header_offset: Some(new_header_offset),
31764 }
31765 }
31766 #[doc = "Selector attribute `kind` is inserted automatically."]
31767 #[doc = "At most one sub-message attribute is expected per attribute set."]
31768 pub fn nested_options_mpls(mut self) -> PushActMplsAttrs<PushDummy<Prev>> {
31769 self = self.push_kind(c"mpls");
31770 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31771 let dummy = PushDummy {
31772 prev: self.prev.take(),
31773 header_offset: self.header_offset.take(),
31774 };
31775 PushActMplsAttrs {
31776 prev: Some(dummy),
31777 header_offset: Some(new_header_offset),
31778 }
31779 }
31780 #[doc = "Selector attribute `kind` is inserted automatically."]
31781 #[doc = "At most one sub-message attribute is expected per attribute set."]
31782 pub fn nested_options_nat(mut self) -> PushActNatAttrs<PushDummy<Prev>> {
31783 self = self.push_kind(c"nat");
31784 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31785 let dummy = PushDummy {
31786 prev: self.prev.take(),
31787 header_offset: self.header_offset.take(),
31788 };
31789 PushActNatAttrs {
31790 prev: Some(dummy),
31791 header_offset: Some(new_header_offset),
31792 }
31793 }
31794 #[doc = "Selector attribute `kind` is inserted automatically."]
31795 #[doc = "At most one sub-message attribute is expected per attribute set."]
31796 pub fn nested_options_pedit(mut self) -> PushActPeditAttrs<PushDummy<Prev>> {
31797 self = self.push_kind(c"pedit");
31798 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31799 let dummy = PushDummy {
31800 prev: self.prev.take(),
31801 header_offset: self.header_offset.take(),
31802 };
31803 PushActPeditAttrs {
31804 prev: Some(dummy),
31805 header_offset: Some(new_header_offset),
31806 }
31807 }
31808 #[doc = "Selector attribute `kind` is inserted automatically."]
31809 #[doc = "At most one sub-message attribute is expected per attribute set."]
31810 pub fn nested_options_police(mut self) -> PushPoliceAttrs<PushDummy<Prev>> {
31811 self = self.push_kind(c"police");
31812 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31813 let dummy = PushDummy {
31814 prev: self.prev.take(),
31815 header_offset: self.header_offset.take(),
31816 };
31817 PushPoliceAttrs {
31818 prev: Some(dummy),
31819 header_offset: Some(new_header_offset),
31820 }
31821 }
31822 #[doc = "Selector attribute `kind` is inserted automatically."]
31823 #[doc = "At most one sub-message attribute is expected per attribute set."]
31824 pub fn nested_options_sample(mut self) -> PushActSampleAttrs<PushDummy<Prev>> {
31825 self = self.push_kind(c"sample");
31826 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31827 let dummy = PushDummy {
31828 prev: self.prev.take(),
31829 header_offset: self.header_offset.take(),
31830 };
31831 PushActSampleAttrs {
31832 prev: Some(dummy),
31833 header_offset: Some(new_header_offset),
31834 }
31835 }
31836 #[doc = "Selector attribute `kind` is inserted automatically."]
31837 #[doc = "At most one sub-message attribute is expected per attribute set."]
31838 pub fn nested_options_simple(mut self) -> PushActSimpleAttrs<PushDummy<Prev>> {
31839 self = self.push_kind(c"simple");
31840 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31841 let dummy = PushDummy {
31842 prev: self.prev.take(),
31843 header_offset: self.header_offset.take(),
31844 };
31845 PushActSimpleAttrs {
31846 prev: Some(dummy),
31847 header_offset: Some(new_header_offset),
31848 }
31849 }
31850 #[doc = "Selector attribute `kind` is inserted automatically."]
31851 #[doc = "At most one sub-message attribute is expected per attribute set."]
31852 pub fn nested_options_skbedit(mut self) -> PushActSkbeditAttrs<PushDummy<Prev>> {
31853 self = self.push_kind(c"skbedit");
31854 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31855 let dummy = PushDummy {
31856 prev: self.prev.take(),
31857 header_offset: self.header_offset.take(),
31858 };
31859 PushActSkbeditAttrs {
31860 prev: Some(dummy),
31861 header_offset: Some(new_header_offset),
31862 }
31863 }
31864 #[doc = "Selector attribute `kind` is inserted automatically."]
31865 #[doc = "At most one sub-message attribute is expected per attribute set."]
31866 pub fn nested_options_skbmod(mut self) -> PushActSkbmodAttrs<PushDummy<Prev>> {
31867 self = self.push_kind(c"skbmod");
31868 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31869 let dummy = PushDummy {
31870 prev: self.prev.take(),
31871 header_offset: self.header_offset.take(),
31872 };
31873 PushActSkbmodAttrs {
31874 prev: Some(dummy),
31875 header_offset: Some(new_header_offset),
31876 }
31877 }
31878 #[doc = "Selector attribute `kind` is inserted automatically."]
31879 #[doc = "At most one sub-message attribute is expected per attribute set."]
31880 pub fn nested_options_tunnel_key(mut self) -> PushActTunnelKeyAttrs<PushDummy<Prev>> {
31881 self = self.push_kind(c"tunnel_key");
31882 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31883 let dummy = PushDummy {
31884 prev: self.prev.take(),
31885 header_offset: self.header_offset.take(),
31886 };
31887 PushActTunnelKeyAttrs {
31888 prev: Some(dummy),
31889 header_offset: Some(new_header_offset),
31890 }
31891 }
31892 #[doc = "Selector attribute `kind` is inserted automatically."]
31893 #[doc = "At most one sub-message attribute is expected per attribute set."]
31894 pub fn nested_options_vlan(mut self) -> PushActVlanAttrs<PushDummy<Prev>> {
31895 self = self.push_kind(c"vlan");
31896 let new_header_offset = push_nested_header(self.as_vec_mut(), 2u16);
31897 let dummy = PushDummy {
31898 prev: self.prev.take(),
31899 header_offset: self.header_offset.take(),
31900 };
31901 PushActVlanAttrs {
31902 prev: Some(dummy),
31903 header_offset: Some(new_header_offset),
31904 }
31905 }
31906 pub fn push_index(mut self, value: u32) -> Self {
31907 push_header(self.as_vec_mut(), 3u16, 4 as u16);
31908 self.as_vec_mut().extend(value.to_ne_bytes());
31909 self
31910 }
31911 pub fn nested_stats(mut self) -> PushTcaStatsAttrs<Self> {
31912 let header_offset = push_nested_header(self.as_vec_mut(), 4u16);
31913 PushTcaStatsAttrs {
31914 prev: Some(self),
31915 header_offset: Some(header_offset),
31916 }
31917 }
31918 pub fn push_pad(mut self, value: &[u8]) -> Self {
31919 push_header(self.as_vec_mut(), 5u16, value.len() as u16);
31920 self.as_vec_mut().extend(value);
31921 self
31922 }
31923 pub fn push_cookie(mut self, value: &[u8]) -> Self {
31924 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
31925 self.as_vec_mut().extend(value);
31926 self
31927 }
31928 pub fn push_flags(mut self, value: BuiltinBitfield32) -> Self {
31929 push_header(self.as_vec_mut(), 7u16, value.as_slice().len() as u16);
31930 self.as_vec_mut().extend(value.as_slice());
31931 self
31932 }
31933 pub fn push_hw_stats(mut self, value: BuiltinBitfield32) -> Self {
31934 push_header(self.as_vec_mut(), 8u16, value.as_slice().len() as u16);
31935 self.as_vec_mut().extend(value.as_slice());
31936 self
31937 }
31938 pub fn push_used_hw_stats(mut self, value: BuiltinBitfield32) -> Self {
31939 push_header(self.as_vec_mut(), 9u16, value.as_slice().len() as u16);
31940 self.as_vec_mut().extend(value.as_slice());
31941 self
31942 }
31943 pub fn push_in_hw_count(mut self, value: u32) -> Self {
31944 push_header(self.as_vec_mut(), 10u16, 4 as u16);
31945 self.as_vec_mut().extend(value.to_ne_bytes());
31946 self
31947 }
31948}
31949impl<Prev: Pusher> Drop for PushActAttrs<Prev> {
31950 fn drop(&mut self) {
31951 if let Some(prev) = &mut self.prev {
31952 if let Some(header_offset) = &self.header_offset {
31953 finalize_nested_header(prev.as_vec_mut(), *header_offset);
31954 }
31955 }
31956 }
31957}
31958pub struct PushActBpfAttrs<Prev: Pusher> {
31959 pub(crate) prev: Option<Prev>,
31960 pub(crate) header_offset: Option<usize>,
31961}
31962impl<Prev: Pusher> Pusher for PushActBpfAttrs<Prev> {
31963 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
31964 self.prev.as_mut().unwrap().as_vec_mut()
31965 }
31966 fn as_vec(&self) -> &Vec<u8> {
31967 self.prev.as_ref().unwrap().as_vec()
31968 }
31969}
31970impl<Prev: Pusher> PushActBpfAttrs<Prev> {
31971 pub fn new(prev: Prev) -> Self {
31972 Self {
31973 prev: Some(prev),
31974 header_offset: None,
31975 }
31976 }
31977 pub fn end_nested(mut self) -> Prev {
31978 let mut prev = self.prev.take().unwrap();
31979 if let Some(header_offset) = &self.header_offset {
31980 finalize_nested_header(prev.as_vec_mut(), *header_offset);
31981 }
31982 prev
31983 }
31984 pub fn push_tm(mut self, value: TcfT) -> Self {
31985 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
31986 self.as_vec_mut().extend(value.as_slice());
31987 self
31988 }
31989 pub fn push_parms(mut self, value: &[u8]) -> Self {
31990 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
31991 self.as_vec_mut().extend(value);
31992 self
31993 }
31994 pub fn push_ops_len(mut self, value: u16) -> Self {
31995 push_header(self.as_vec_mut(), 3u16, 2 as u16);
31996 self.as_vec_mut().extend(value.to_ne_bytes());
31997 self
31998 }
31999 pub fn push_ops(mut self, value: &[u8]) -> Self {
32000 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
32001 self.as_vec_mut().extend(value);
32002 self
32003 }
32004 pub fn push_fd(mut self, value: u32) -> Self {
32005 push_header(self.as_vec_mut(), 5u16, 4 as u16);
32006 self.as_vec_mut().extend(value.to_ne_bytes());
32007 self
32008 }
32009 pub fn push_name(mut self, value: &CStr) -> Self {
32010 push_header(
32011 self.as_vec_mut(),
32012 6u16,
32013 value.to_bytes_with_nul().len() as u16,
32014 );
32015 self.as_vec_mut().extend(value.to_bytes_with_nul());
32016 self
32017 }
32018 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
32019 push_header(self.as_vec_mut(), 6u16, (value.len() + 1) as u16);
32020 self.as_vec_mut().extend(value);
32021 self.as_vec_mut().push(0);
32022 self
32023 }
32024 pub fn push_pad(mut self, value: &[u8]) -> Self {
32025 push_header(self.as_vec_mut(), 7u16, value.len() as u16);
32026 self.as_vec_mut().extend(value);
32027 self
32028 }
32029 pub fn push_tag(mut self, value: &[u8]) -> Self {
32030 push_header(self.as_vec_mut(), 8u16, value.len() as u16);
32031 self.as_vec_mut().extend(value);
32032 self
32033 }
32034 pub fn push_id(mut self, value: &[u8]) -> Self {
32035 push_header(self.as_vec_mut(), 9u16, value.len() as u16);
32036 self.as_vec_mut().extend(value);
32037 self
32038 }
32039}
32040impl<Prev: Pusher> Drop for PushActBpfAttrs<Prev> {
32041 fn drop(&mut self) {
32042 if let Some(prev) = &mut self.prev {
32043 if let Some(header_offset) = &self.header_offset {
32044 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32045 }
32046 }
32047 }
32048}
32049pub struct PushActConnmarkAttrs<Prev: Pusher> {
32050 pub(crate) prev: Option<Prev>,
32051 pub(crate) header_offset: Option<usize>,
32052}
32053impl<Prev: Pusher> Pusher for PushActConnmarkAttrs<Prev> {
32054 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32055 self.prev.as_mut().unwrap().as_vec_mut()
32056 }
32057 fn as_vec(&self) -> &Vec<u8> {
32058 self.prev.as_ref().unwrap().as_vec()
32059 }
32060}
32061impl<Prev: Pusher> PushActConnmarkAttrs<Prev> {
32062 pub fn new(prev: Prev) -> Self {
32063 Self {
32064 prev: Some(prev),
32065 header_offset: None,
32066 }
32067 }
32068 pub fn end_nested(mut self) -> Prev {
32069 let mut prev = self.prev.take().unwrap();
32070 if let Some(header_offset) = &self.header_offset {
32071 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32072 }
32073 prev
32074 }
32075 pub fn push_parms(mut self, value: &[u8]) -> Self {
32076 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
32077 self.as_vec_mut().extend(value);
32078 self
32079 }
32080 pub fn push_tm(mut self, value: TcfT) -> Self {
32081 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
32082 self.as_vec_mut().extend(value.as_slice());
32083 self
32084 }
32085 pub fn push_pad(mut self, value: &[u8]) -> Self {
32086 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32087 self.as_vec_mut().extend(value);
32088 self
32089 }
32090}
32091impl<Prev: Pusher> Drop for PushActConnmarkAttrs<Prev> {
32092 fn drop(&mut self) {
32093 if let Some(prev) = &mut self.prev {
32094 if let Some(header_offset) = &self.header_offset {
32095 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32096 }
32097 }
32098 }
32099}
32100pub struct PushActCsumAttrs<Prev: Pusher> {
32101 pub(crate) prev: Option<Prev>,
32102 pub(crate) header_offset: Option<usize>,
32103}
32104impl<Prev: Pusher> Pusher for PushActCsumAttrs<Prev> {
32105 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32106 self.prev.as_mut().unwrap().as_vec_mut()
32107 }
32108 fn as_vec(&self) -> &Vec<u8> {
32109 self.prev.as_ref().unwrap().as_vec()
32110 }
32111}
32112impl<Prev: Pusher> PushActCsumAttrs<Prev> {
32113 pub fn new(prev: Prev) -> Self {
32114 Self {
32115 prev: Some(prev),
32116 header_offset: None,
32117 }
32118 }
32119 pub fn end_nested(mut self) -> Prev {
32120 let mut prev = self.prev.take().unwrap();
32121 if let Some(header_offset) = &self.header_offset {
32122 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32123 }
32124 prev
32125 }
32126 pub fn push_parms(mut self, value: &[u8]) -> Self {
32127 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
32128 self.as_vec_mut().extend(value);
32129 self
32130 }
32131 pub fn push_tm(mut self, value: TcfT) -> Self {
32132 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
32133 self.as_vec_mut().extend(value.as_slice());
32134 self
32135 }
32136 pub fn push_pad(mut self, value: &[u8]) -> Self {
32137 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32138 self.as_vec_mut().extend(value);
32139 self
32140 }
32141}
32142impl<Prev: Pusher> Drop for PushActCsumAttrs<Prev> {
32143 fn drop(&mut self) {
32144 if let Some(prev) = &mut self.prev {
32145 if let Some(header_offset) = &self.header_offset {
32146 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32147 }
32148 }
32149 }
32150}
32151pub struct PushActCtAttrs<Prev: Pusher> {
32152 pub(crate) prev: Option<Prev>,
32153 pub(crate) header_offset: Option<usize>,
32154}
32155impl<Prev: Pusher> Pusher for PushActCtAttrs<Prev> {
32156 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32157 self.prev.as_mut().unwrap().as_vec_mut()
32158 }
32159 fn as_vec(&self) -> &Vec<u8> {
32160 self.prev.as_ref().unwrap().as_vec()
32161 }
32162}
32163impl<Prev: Pusher> PushActCtAttrs<Prev> {
32164 pub fn new(prev: Prev) -> Self {
32165 Self {
32166 prev: Some(prev),
32167 header_offset: None,
32168 }
32169 }
32170 pub fn end_nested(mut self) -> Prev {
32171 let mut prev = self.prev.take().unwrap();
32172 if let Some(header_offset) = &self.header_offset {
32173 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32174 }
32175 prev
32176 }
32177 pub fn push_parms(mut self, value: &[u8]) -> Self {
32178 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
32179 self.as_vec_mut().extend(value);
32180 self
32181 }
32182 pub fn push_tm(mut self, value: TcfT) -> Self {
32183 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
32184 self.as_vec_mut().extend(value.as_slice());
32185 self
32186 }
32187 pub fn push_action(mut self, value: u16) -> Self {
32188 push_header(self.as_vec_mut(), 3u16, 2 as u16);
32189 self.as_vec_mut().extend(value.to_ne_bytes());
32190 self
32191 }
32192 pub fn push_zone(mut self, value: u16) -> Self {
32193 push_header(self.as_vec_mut(), 4u16, 2 as u16);
32194 self.as_vec_mut().extend(value.to_ne_bytes());
32195 self
32196 }
32197 pub fn push_mark(mut self, value: u32) -> Self {
32198 push_header(self.as_vec_mut(), 5u16, 4 as u16);
32199 self.as_vec_mut().extend(value.to_ne_bytes());
32200 self
32201 }
32202 pub fn push_mark_mask(mut self, value: u32) -> Self {
32203 push_header(self.as_vec_mut(), 6u16, 4 as u16);
32204 self.as_vec_mut().extend(value.to_ne_bytes());
32205 self
32206 }
32207 pub fn push_labels(mut self, value: &[u8]) -> Self {
32208 push_header(self.as_vec_mut(), 7u16, value.len() as u16);
32209 self.as_vec_mut().extend(value);
32210 self
32211 }
32212 pub fn push_labels_mask(mut self, value: &[u8]) -> Self {
32213 push_header(self.as_vec_mut(), 8u16, value.len() as u16);
32214 self.as_vec_mut().extend(value);
32215 self
32216 }
32217 pub fn push_nat_ipv4_min(mut self, value: u32) -> Self {
32218 push_header(self.as_vec_mut(), 9u16, 4 as u16);
32219 self.as_vec_mut().extend(value.to_be_bytes());
32220 self
32221 }
32222 pub fn push_nat_ipv4_max(mut self, value: u32) -> Self {
32223 push_header(self.as_vec_mut(), 10u16, 4 as u16);
32224 self.as_vec_mut().extend(value.to_be_bytes());
32225 self
32226 }
32227 pub fn push_nat_ipv6_min(mut self, value: &[u8]) -> Self {
32228 push_header(self.as_vec_mut(), 11u16, value.len() as u16);
32229 self.as_vec_mut().extend(value);
32230 self
32231 }
32232 pub fn push_nat_ipv6_max(mut self, value: &[u8]) -> Self {
32233 push_header(self.as_vec_mut(), 12u16, value.len() as u16);
32234 self.as_vec_mut().extend(value);
32235 self
32236 }
32237 pub fn push_nat_port_min(mut self, value: u16) -> Self {
32238 push_header(self.as_vec_mut(), 13u16, 2 as u16);
32239 self.as_vec_mut().extend(value.to_be_bytes());
32240 self
32241 }
32242 pub fn push_nat_port_max(mut self, value: u16) -> Self {
32243 push_header(self.as_vec_mut(), 14u16, 2 as u16);
32244 self.as_vec_mut().extend(value.to_be_bytes());
32245 self
32246 }
32247 pub fn push_pad(mut self, value: &[u8]) -> Self {
32248 push_header(self.as_vec_mut(), 15u16, value.len() as u16);
32249 self.as_vec_mut().extend(value);
32250 self
32251 }
32252 pub fn push_helper_name(mut self, value: &CStr) -> Self {
32253 push_header(
32254 self.as_vec_mut(),
32255 16u16,
32256 value.to_bytes_with_nul().len() as u16,
32257 );
32258 self.as_vec_mut().extend(value.to_bytes_with_nul());
32259 self
32260 }
32261 pub fn push_helper_name_bytes(mut self, value: &[u8]) -> Self {
32262 push_header(self.as_vec_mut(), 16u16, (value.len() + 1) as u16);
32263 self.as_vec_mut().extend(value);
32264 self.as_vec_mut().push(0);
32265 self
32266 }
32267 pub fn push_helper_family(mut self, value: u8) -> Self {
32268 push_header(self.as_vec_mut(), 17u16, 1 as u16);
32269 self.as_vec_mut().extend(value.to_ne_bytes());
32270 self
32271 }
32272 pub fn push_helper_proto(mut self, value: u8) -> Self {
32273 push_header(self.as_vec_mut(), 18u16, 1 as u16);
32274 self.as_vec_mut().extend(value.to_ne_bytes());
32275 self
32276 }
32277}
32278impl<Prev: Pusher> Drop for PushActCtAttrs<Prev> {
32279 fn drop(&mut self) {
32280 if let Some(prev) = &mut self.prev {
32281 if let Some(header_offset) = &self.header_offset {
32282 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32283 }
32284 }
32285 }
32286}
32287pub struct PushActCtinfoAttrs<Prev: Pusher> {
32288 pub(crate) prev: Option<Prev>,
32289 pub(crate) header_offset: Option<usize>,
32290}
32291impl<Prev: Pusher> Pusher for PushActCtinfoAttrs<Prev> {
32292 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32293 self.prev.as_mut().unwrap().as_vec_mut()
32294 }
32295 fn as_vec(&self) -> &Vec<u8> {
32296 self.prev.as_ref().unwrap().as_vec()
32297 }
32298}
32299impl<Prev: Pusher> PushActCtinfoAttrs<Prev> {
32300 pub fn new(prev: Prev) -> Self {
32301 Self {
32302 prev: Some(prev),
32303 header_offset: None,
32304 }
32305 }
32306 pub fn end_nested(mut self) -> Prev {
32307 let mut prev = self.prev.take().unwrap();
32308 if let Some(header_offset) = &self.header_offset {
32309 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32310 }
32311 prev
32312 }
32313 pub fn push_pad(mut self, value: &[u8]) -> Self {
32314 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
32315 self.as_vec_mut().extend(value);
32316 self
32317 }
32318 pub fn push_tm(mut self, value: TcfT) -> Self {
32319 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
32320 self.as_vec_mut().extend(value.as_slice());
32321 self
32322 }
32323 pub fn push_act(mut self, value: &[u8]) -> Self {
32324 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32325 self.as_vec_mut().extend(value);
32326 self
32327 }
32328 pub fn push_zone(mut self, value: u16) -> Self {
32329 push_header(self.as_vec_mut(), 4u16, 2 as u16);
32330 self.as_vec_mut().extend(value.to_ne_bytes());
32331 self
32332 }
32333 pub fn push_parms_dscp_mask(mut self, value: u32) -> Self {
32334 push_header(self.as_vec_mut(), 5u16, 4 as u16);
32335 self.as_vec_mut().extend(value.to_ne_bytes());
32336 self
32337 }
32338 pub fn push_parms_dscp_statemask(mut self, value: u32) -> Self {
32339 push_header(self.as_vec_mut(), 6u16, 4 as u16);
32340 self.as_vec_mut().extend(value.to_ne_bytes());
32341 self
32342 }
32343 pub fn push_parms_cpmark_mask(mut self, value: u32) -> Self {
32344 push_header(self.as_vec_mut(), 7u16, 4 as u16);
32345 self.as_vec_mut().extend(value.to_ne_bytes());
32346 self
32347 }
32348 pub fn push_stats_dscp_set(mut self, value: u64) -> Self {
32349 push_header(self.as_vec_mut(), 8u16, 8 as u16);
32350 self.as_vec_mut().extend(value.to_ne_bytes());
32351 self
32352 }
32353 pub fn push_stats_dscp_error(mut self, value: u64) -> Self {
32354 push_header(self.as_vec_mut(), 9u16, 8 as u16);
32355 self.as_vec_mut().extend(value.to_ne_bytes());
32356 self
32357 }
32358 pub fn push_stats_cpmark_set(mut self, value: u64) -> Self {
32359 push_header(self.as_vec_mut(), 10u16, 8 as u16);
32360 self.as_vec_mut().extend(value.to_ne_bytes());
32361 self
32362 }
32363}
32364impl<Prev: Pusher> Drop for PushActCtinfoAttrs<Prev> {
32365 fn drop(&mut self) {
32366 if let Some(prev) = &mut self.prev {
32367 if let Some(header_offset) = &self.header_offset {
32368 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32369 }
32370 }
32371 }
32372}
32373pub struct PushActGateAttrs<Prev: Pusher> {
32374 pub(crate) prev: Option<Prev>,
32375 pub(crate) header_offset: Option<usize>,
32376}
32377impl<Prev: Pusher> Pusher for PushActGateAttrs<Prev> {
32378 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32379 self.prev.as_mut().unwrap().as_vec_mut()
32380 }
32381 fn as_vec(&self) -> &Vec<u8> {
32382 self.prev.as_ref().unwrap().as_vec()
32383 }
32384}
32385impl<Prev: Pusher> PushActGateAttrs<Prev> {
32386 pub fn new(prev: Prev) -> Self {
32387 Self {
32388 prev: Some(prev),
32389 header_offset: None,
32390 }
32391 }
32392 pub fn end_nested(mut self) -> Prev {
32393 let mut prev = self.prev.take().unwrap();
32394 if let Some(header_offset) = &self.header_offset {
32395 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32396 }
32397 prev
32398 }
32399 pub fn push_tm(mut self, value: TcfT) -> Self {
32400 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
32401 self.as_vec_mut().extend(value.as_slice());
32402 self
32403 }
32404 pub fn push_parms(mut self, value: &[u8]) -> Self {
32405 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
32406 self.as_vec_mut().extend(value);
32407 self
32408 }
32409 pub fn push_pad(mut self, value: &[u8]) -> Self {
32410 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32411 self.as_vec_mut().extend(value);
32412 self
32413 }
32414 pub fn push_priority(mut self, value: i32) -> Self {
32415 push_header(self.as_vec_mut(), 4u16, 4 as u16);
32416 self.as_vec_mut().extend(value.to_ne_bytes());
32417 self
32418 }
32419 pub fn push_entry_list(mut self, value: &[u8]) -> Self {
32420 push_header(self.as_vec_mut(), 5u16, value.len() as u16);
32421 self.as_vec_mut().extend(value);
32422 self
32423 }
32424 pub fn push_base_time(mut self, value: u64) -> Self {
32425 push_header(self.as_vec_mut(), 6u16, 8 as u16);
32426 self.as_vec_mut().extend(value.to_ne_bytes());
32427 self
32428 }
32429 pub fn push_cycle_time(mut self, value: u64) -> Self {
32430 push_header(self.as_vec_mut(), 7u16, 8 as u16);
32431 self.as_vec_mut().extend(value.to_ne_bytes());
32432 self
32433 }
32434 pub fn push_cycle_time_ext(mut self, value: u64) -> Self {
32435 push_header(self.as_vec_mut(), 8u16, 8 as u16);
32436 self.as_vec_mut().extend(value.to_ne_bytes());
32437 self
32438 }
32439 pub fn push_flags(mut self, value: u32) -> Self {
32440 push_header(self.as_vec_mut(), 9u16, 4 as u16);
32441 self.as_vec_mut().extend(value.to_ne_bytes());
32442 self
32443 }
32444 pub fn push_clockid(mut self, value: i32) -> Self {
32445 push_header(self.as_vec_mut(), 10u16, 4 as u16);
32446 self.as_vec_mut().extend(value.to_ne_bytes());
32447 self
32448 }
32449}
32450impl<Prev: Pusher> Drop for PushActGateAttrs<Prev> {
32451 fn drop(&mut self) {
32452 if let Some(prev) = &mut self.prev {
32453 if let Some(header_offset) = &self.header_offset {
32454 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32455 }
32456 }
32457 }
32458}
32459pub struct PushActIfeAttrs<Prev: Pusher> {
32460 pub(crate) prev: Option<Prev>,
32461 pub(crate) header_offset: Option<usize>,
32462}
32463impl<Prev: Pusher> Pusher for PushActIfeAttrs<Prev> {
32464 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32465 self.prev.as_mut().unwrap().as_vec_mut()
32466 }
32467 fn as_vec(&self) -> &Vec<u8> {
32468 self.prev.as_ref().unwrap().as_vec()
32469 }
32470}
32471impl<Prev: Pusher> PushActIfeAttrs<Prev> {
32472 pub fn new(prev: Prev) -> Self {
32473 Self {
32474 prev: Some(prev),
32475 header_offset: None,
32476 }
32477 }
32478 pub fn end_nested(mut self) -> Prev {
32479 let mut prev = self.prev.take().unwrap();
32480 if let Some(header_offset) = &self.header_offset {
32481 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32482 }
32483 prev
32484 }
32485 pub fn push_parms(mut self, value: &[u8]) -> Self {
32486 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
32487 self.as_vec_mut().extend(value);
32488 self
32489 }
32490 pub fn push_tm(mut self, value: TcfT) -> Self {
32491 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
32492 self.as_vec_mut().extend(value.as_slice());
32493 self
32494 }
32495 pub fn push_dmac(mut self, value: &[u8]) -> Self {
32496 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32497 self.as_vec_mut().extend(value);
32498 self
32499 }
32500 pub fn push_smac(mut self, value: &[u8]) -> Self {
32501 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
32502 self.as_vec_mut().extend(value);
32503 self
32504 }
32505 pub fn push_type(mut self, value: u16) -> Self {
32506 push_header(self.as_vec_mut(), 5u16, 2 as u16);
32507 self.as_vec_mut().extend(value.to_ne_bytes());
32508 self
32509 }
32510 pub fn push_metalst(mut self, value: &[u8]) -> Self {
32511 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
32512 self.as_vec_mut().extend(value);
32513 self
32514 }
32515 pub fn push_pad(mut self, value: &[u8]) -> Self {
32516 push_header(self.as_vec_mut(), 7u16, value.len() as u16);
32517 self.as_vec_mut().extend(value);
32518 self
32519 }
32520}
32521impl<Prev: Pusher> Drop for PushActIfeAttrs<Prev> {
32522 fn drop(&mut self) {
32523 if let Some(prev) = &mut self.prev {
32524 if let Some(header_offset) = &self.header_offset {
32525 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32526 }
32527 }
32528 }
32529}
32530pub struct PushActMirredAttrs<Prev: Pusher> {
32531 pub(crate) prev: Option<Prev>,
32532 pub(crate) header_offset: Option<usize>,
32533}
32534impl<Prev: Pusher> Pusher for PushActMirredAttrs<Prev> {
32535 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32536 self.prev.as_mut().unwrap().as_vec_mut()
32537 }
32538 fn as_vec(&self) -> &Vec<u8> {
32539 self.prev.as_ref().unwrap().as_vec()
32540 }
32541}
32542impl<Prev: Pusher> PushActMirredAttrs<Prev> {
32543 pub fn new(prev: Prev) -> Self {
32544 Self {
32545 prev: Some(prev),
32546 header_offset: None,
32547 }
32548 }
32549 pub fn end_nested(mut self) -> Prev {
32550 let mut prev = self.prev.take().unwrap();
32551 if let Some(header_offset) = &self.header_offset {
32552 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32553 }
32554 prev
32555 }
32556 pub fn push_tm(mut self, value: TcfT) -> Self {
32557 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
32558 self.as_vec_mut().extend(value.as_slice());
32559 self
32560 }
32561 pub fn push_parms(mut self, value: &[u8]) -> Self {
32562 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
32563 self.as_vec_mut().extend(value);
32564 self
32565 }
32566 pub fn push_pad(mut self, value: &[u8]) -> Self {
32567 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32568 self.as_vec_mut().extend(value);
32569 self
32570 }
32571 pub fn push_blockid(mut self, value: &[u8]) -> Self {
32572 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
32573 self.as_vec_mut().extend(value);
32574 self
32575 }
32576}
32577impl<Prev: Pusher> Drop for PushActMirredAttrs<Prev> {
32578 fn drop(&mut self) {
32579 if let Some(prev) = &mut self.prev {
32580 if let Some(header_offset) = &self.header_offset {
32581 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32582 }
32583 }
32584 }
32585}
32586pub struct PushActMplsAttrs<Prev: Pusher> {
32587 pub(crate) prev: Option<Prev>,
32588 pub(crate) header_offset: Option<usize>,
32589}
32590impl<Prev: Pusher> Pusher for PushActMplsAttrs<Prev> {
32591 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32592 self.prev.as_mut().unwrap().as_vec_mut()
32593 }
32594 fn as_vec(&self) -> &Vec<u8> {
32595 self.prev.as_ref().unwrap().as_vec()
32596 }
32597}
32598impl<Prev: Pusher> PushActMplsAttrs<Prev> {
32599 pub fn new(prev: Prev) -> Self {
32600 Self {
32601 prev: Some(prev),
32602 header_offset: None,
32603 }
32604 }
32605 pub fn end_nested(mut self) -> Prev {
32606 let mut prev = self.prev.take().unwrap();
32607 if let Some(header_offset) = &self.header_offset {
32608 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32609 }
32610 prev
32611 }
32612 pub fn push_tm(mut self, value: TcfT) -> Self {
32613 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
32614 self.as_vec_mut().extend(value.as_slice());
32615 self
32616 }
32617 pub fn push_parms(mut self, value: TcMpls) -> Self {
32618 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
32619 self.as_vec_mut().extend(value.as_slice());
32620 self
32621 }
32622 pub fn push_pad(mut self, value: &[u8]) -> Self {
32623 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32624 self.as_vec_mut().extend(value);
32625 self
32626 }
32627 pub fn push_proto(mut self, value: u16) -> Self {
32628 push_header(self.as_vec_mut(), 4u16, 2 as u16);
32629 self.as_vec_mut().extend(value.to_be_bytes());
32630 self
32631 }
32632 pub fn push_label(mut self, value: u32) -> Self {
32633 push_header(self.as_vec_mut(), 5u16, 4 as u16);
32634 self.as_vec_mut().extend(value.to_ne_bytes());
32635 self
32636 }
32637 pub fn push_tc(mut self, value: u8) -> Self {
32638 push_header(self.as_vec_mut(), 6u16, 1 as u16);
32639 self.as_vec_mut().extend(value.to_ne_bytes());
32640 self
32641 }
32642 pub fn push_ttl(mut self, value: u8) -> Self {
32643 push_header(self.as_vec_mut(), 7u16, 1 as u16);
32644 self.as_vec_mut().extend(value.to_ne_bytes());
32645 self
32646 }
32647 pub fn push_bos(mut self, value: u8) -> Self {
32648 push_header(self.as_vec_mut(), 8u16, 1 as u16);
32649 self.as_vec_mut().extend(value.to_ne_bytes());
32650 self
32651 }
32652}
32653impl<Prev: Pusher> Drop for PushActMplsAttrs<Prev> {
32654 fn drop(&mut self) {
32655 if let Some(prev) = &mut self.prev {
32656 if let Some(header_offset) = &self.header_offset {
32657 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32658 }
32659 }
32660 }
32661}
32662pub struct PushActNatAttrs<Prev: Pusher> {
32663 pub(crate) prev: Option<Prev>,
32664 pub(crate) header_offset: Option<usize>,
32665}
32666impl<Prev: Pusher> Pusher for PushActNatAttrs<Prev> {
32667 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32668 self.prev.as_mut().unwrap().as_vec_mut()
32669 }
32670 fn as_vec(&self) -> &Vec<u8> {
32671 self.prev.as_ref().unwrap().as_vec()
32672 }
32673}
32674impl<Prev: Pusher> PushActNatAttrs<Prev> {
32675 pub fn new(prev: Prev) -> Self {
32676 Self {
32677 prev: Some(prev),
32678 header_offset: None,
32679 }
32680 }
32681 pub fn end_nested(mut self) -> Prev {
32682 let mut prev = self.prev.take().unwrap();
32683 if let Some(header_offset) = &self.header_offset {
32684 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32685 }
32686 prev
32687 }
32688 pub fn push_parms(mut self, value: &[u8]) -> Self {
32689 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
32690 self.as_vec_mut().extend(value);
32691 self
32692 }
32693 pub fn push_tm(mut self, value: TcfT) -> Self {
32694 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
32695 self.as_vec_mut().extend(value.as_slice());
32696 self
32697 }
32698 pub fn push_pad(mut self, value: &[u8]) -> Self {
32699 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32700 self.as_vec_mut().extend(value);
32701 self
32702 }
32703}
32704impl<Prev: Pusher> Drop for PushActNatAttrs<Prev> {
32705 fn drop(&mut self) {
32706 if let Some(prev) = &mut self.prev {
32707 if let Some(header_offset) = &self.header_offset {
32708 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32709 }
32710 }
32711 }
32712}
32713pub struct PushActPeditAttrs<Prev: Pusher> {
32714 pub(crate) prev: Option<Prev>,
32715 pub(crate) header_offset: Option<usize>,
32716}
32717impl<Prev: Pusher> Pusher for PushActPeditAttrs<Prev> {
32718 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32719 self.prev.as_mut().unwrap().as_vec_mut()
32720 }
32721 fn as_vec(&self) -> &Vec<u8> {
32722 self.prev.as_ref().unwrap().as_vec()
32723 }
32724}
32725impl<Prev: Pusher> PushActPeditAttrs<Prev> {
32726 pub fn new(prev: Prev) -> Self {
32727 Self {
32728 prev: Some(prev),
32729 header_offset: None,
32730 }
32731 }
32732 pub fn end_nested(mut self) -> Prev {
32733 let mut prev = self.prev.take().unwrap();
32734 if let Some(header_offset) = &self.header_offset {
32735 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32736 }
32737 prev
32738 }
32739 pub fn push_tm(mut self, value: TcfT) -> Self {
32740 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
32741 self.as_vec_mut().extend(value.as_slice());
32742 self
32743 }
32744 pub fn push_parms(mut self, value: TcPeditSel) -> Self {
32745 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
32746 self.as_vec_mut().extend(value.as_slice());
32747 self
32748 }
32749 pub fn push_pad(mut self, value: &[u8]) -> Self {
32750 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32751 self.as_vec_mut().extend(value);
32752 self
32753 }
32754 pub fn push_parms_ex(mut self, value: &[u8]) -> Self {
32755 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
32756 self.as_vec_mut().extend(value);
32757 self
32758 }
32759 pub fn push_keys_ex(mut self, value: &[u8]) -> Self {
32760 push_header(self.as_vec_mut(), 5u16, value.len() as u16);
32761 self.as_vec_mut().extend(value);
32762 self
32763 }
32764 pub fn push_key_ex(mut self, value: &[u8]) -> Self {
32765 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
32766 self.as_vec_mut().extend(value);
32767 self
32768 }
32769}
32770impl<Prev: Pusher> Drop for PushActPeditAttrs<Prev> {
32771 fn drop(&mut self) {
32772 if let Some(prev) = &mut self.prev {
32773 if let Some(header_offset) = &self.header_offset {
32774 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32775 }
32776 }
32777 }
32778}
32779pub struct PushActSimpleAttrs<Prev: Pusher> {
32780 pub(crate) prev: Option<Prev>,
32781 pub(crate) header_offset: Option<usize>,
32782}
32783impl<Prev: Pusher> Pusher for PushActSimpleAttrs<Prev> {
32784 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32785 self.prev.as_mut().unwrap().as_vec_mut()
32786 }
32787 fn as_vec(&self) -> &Vec<u8> {
32788 self.prev.as_ref().unwrap().as_vec()
32789 }
32790}
32791impl<Prev: Pusher> PushActSimpleAttrs<Prev> {
32792 pub fn new(prev: Prev) -> Self {
32793 Self {
32794 prev: Some(prev),
32795 header_offset: None,
32796 }
32797 }
32798 pub fn end_nested(mut self) -> Prev {
32799 let mut prev = self.prev.take().unwrap();
32800 if let Some(header_offset) = &self.header_offset {
32801 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32802 }
32803 prev
32804 }
32805 pub fn push_tm(mut self, value: TcfT) -> Self {
32806 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
32807 self.as_vec_mut().extend(value.as_slice());
32808 self
32809 }
32810 pub fn push_parms(mut self, value: &[u8]) -> Self {
32811 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
32812 self.as_vec_mut().extend(value);
32813 self
32814 }
32815 pub fn push_data(mut self, value: &[u8]) -> Self {
32816 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32817 self.as_vec_mut().extend(value);
32818 self
32819 }
32820 pub fn push_pad(mut self, value: &[u8]) -> Self {
32821 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
32822 self.as_vec_mut().extend(value);
32823 self
32824 }
32825}
32826impl<Prev: Pusher> Drop for PushActSimpleAttrs<Prev> {
32827 fn drop(&mut self) {
32828 if let Some(prev) = &mut self.prev {
32829 if let Some(header_offset) = &self.header_offset {
32830 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32831 }
32832 }
32833 }
32834}
32835pub struct PushActSkbeditAttrs<Prev: Pusher> {
32836 pub(crate) prev: Option<Prev>,
32837 pub(crate) header_offset: Option<usize>,
32838}
32839impl<Prev: Pusher> Pusher for PushActSkbeditAttrs<Prev> {
32840 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32841 self.prev.as_mut().unwrap().as_vec_mut()
32842 }
32843 fn as_vec(&self) -> &Vec<u8> {
32844 self.prev.as_ref().unwrap().as_vec()
32845 }
32846}
32847impl<Prev: Pusher> PushActSkbeditAttrs<Prev> {
32848 pub fn new(prev: Prev) -> Self {
32849 Self {
32850 prev: Some(prev),
32851 header_offset: None,
32852 }
32853 }
32854 pub fn end_nested(mut self) -> Prev {
32855 let mut prev = self.prev.take().unwrap();
32856 if let Some(header_offset) = &self.header_offset {
32857 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32858 }
32859 prev
32860 }
32861 pub fn push_tm(mut self, value: TcfT) -> Self {
32862 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
32863 self.as_vec_mut().extend(value.as_slice());
32864 self
32865 }
32866 pub fn push_parms(mut self, value: &[u8]) -> Self {
32867 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
32868 self.as_vec_mut().extend(value);
32869 self
32870 }
32871 pub fn push_priority(mut self, value: u32) -> Self {
32872 push_header(self.as_vec_mut(), 3u16, 4 as u16);
32873 self.as_vec_mut().extend(value.to_ne_bytes());
32874 self
32875 }
32876 pub fn push_queue_mapping(mut self, value: u16) -> Self {
32877 push_header(self.as_vec_mut(), 4u16, 2 as u16);
32878 self.as_vec_mut().extend(value.to_ne_bytes());
32879 self
32880 }
32881 pub fn push_mark(mut self, value: u32) -> Self {
32882 push_header(self.as_vec_mut(), 5u16, 4 as u16);
32883 self.as_vec_mut().extend(value.to_ne_bytes());
32884 self
32885 }
32886 pub fn push_pad(mut self, value: &[u8]) -> Self {
32887 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
32888 self.as_vec_mut().extend(value);
32889 self
32890 }
32891 pub fn push_ptype(mut self, value: u16) -> Self {
32892 push_header(self.as_vec_mut(), 7u16, 2 as u16);
32893 self.as_vec_mut().extend(value.to_ne_bytes());
32894 self
32895 }
32896 pub fn push_mask(mut self, value: u32) -> Self {
32897 push_header(self.as_vec_mut(), 8u16, 4 as u16);
32898 self.as_vec_mut().extend(value.to_ne_bytes());
32899 self
32900 }
32901 pub fn push_flags(mut self, value: u64) -> Self {
32902 push_header(self.as_vec_mut(), 9u16, 8 as u16);
32903 self.as_vec_mut().extend(value.to_ne_bytes());
32904 self
32905 }
32906 pub fn push_queue_mapping_max(mut self, value: u16) -> Self {
32907 push_header(self.as_vec_mut(), 10u16, 2 as u16);
32908 self.as_vec_mut().extend(value.to_ne_bytes());
32909 self
32910 }
32911}
32912impl<Prev: Pusher> Drop for PushActSkbeditAttrs<Prev> {
32913 fn drop(&mut self) {
32914 if let Some(prev) = &mut self.prev {
32915 if let Some(header_offset) = &self.header_offset {
32916 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32917 }
32918 }
32919 }
32920}
32921pub struct PushActSkbmodAttrs<Prev: Pusher> {
32922 pub(crate) prev: Option<Prev>,
32923 pub(crate) header_offset: Option<usize>,
32924}
32925impl<Prev: Pusher> Pusher for PushActSkbmodAttrs<Prev> {
32926 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32927 self.prev.as_mut().unwrap().as_vec_mut()
32928 }
32929 fn as_vec(&self) -> &Vec<u8> {
32930 self.prev.as_ref().unwrap().as_vec()
32931 }
32932}
32933impl<Prev: Pusher> PushActSkbmodAttrs<Prev> {
32934 pub fn new(prev: Prev) -> Self {
32935 Self {
32936 prev: Some(prev),
32937 header_offset: None,
32938 }
32939 }
32940 pub fn end_nested(mut self) -> Prev {
32941 let mut prev = self.prev.take().unwrap();
32942 if let Some(header_offset) = &self.header_offset {
32943 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32944 }
32945 prev
32946 }
32947 pub fn push_tm(mut self, value: TcfT) -> Self {
32948 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
32949 self.as_vec_mut().extend(value.as_slice());
32950 self
32951 }
32952 pub fn push_parms(mut self, value: &[u8]) -> Self {
32953 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
32954 self.as_vec_mut().extend(value);
32955 self
32956 }
32957 pub fn push_dmac(mut self, value: &[u8]) -> Self {
32958 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
32959 self.as_vec_mut().extend(value);
32960 self
32961 }
32962 pub fn push_smac(mut self, value: &[u8]) -> Self {
32963 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
32964 self.as_vec_mut().extend(value);
32965 self
32966 }
32967 pub fn push_etype(mut self, value: &[u8]) -> Self {
32968 push_header(self.as_vec_mut(), 5u16, value.len() as u16);
32969 self.as_vec_mut().extend(value);
32970 self
32971 }
32972 pub fn push_pad(mut self, value: &[u8]) -> Self {
32973 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
32974 self.as_vec_mut().extend(value);
32975 self
32976 }
32977}
32978impl<Prev: Pusher> Drop for PushActSkbmodAttrs<Prev> {
32979 fn drop(&mut self) {
32980 if let Some(prev) = &mut self.prev {
32981 if let Some(header_offset) = &self.header_offset {
32982 finalize_nested_header(prev.as_vec_mut(), *header_offset);
32983 }
32984 }
32985 }
32986}
32987pub struct PushActTunnelKeyAttrs<Prev: Pusher> {
32988 pub(crate) prev: Option<Prev>,
32989 pub(crate) header_offset: Option<usize>,
32990}
32991impl<Prev: Pusher> Pusher for PushActTunnelKeyAttrs<Prev> {
32992 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
32993 self.prev.as_mut().unwrap().as_vec_mut()
32994 }
32995 fn as_vec(&self) -> &Vec<u8> {
32996 self.prev.as_ref().unwrap().as_vec()
32997 }
32998}
32999impl<Prev: Pusher> PushActTunnelKeyAttrs<Prev> {
33000 pub fn new(prev: Prev) -> Self {
33001 Self {
33002 prev: Some(prev),
33003 header_offset: None,
33004 }
33005 }
33006 pub fn end_nested(mut self) -> Prev {
33007 let mut prev = self.prev.take().unwrap();
33008 if let Some(header_offset) = &self.header_offset {
33009 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33010 }
33011 prev
33012 }
33013 pub fn push_tm(mut self, value: TcfT) -> Self {
33014 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
33015 self.as_vec_mut().extend(value.as_slice());
33016 self
33017 }
33018 pub fn push_parms(mut self, value: &[u8]) -> Self {
33019 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
33020 self.as_vec_mut().extend(value);
33021 self
33022 }
33023 pub fn push_enc_ipv4_src(mut self, value: u32) -> Self {
33024 push_header(self.as_vec_mut(), 3u16, 4 as u16);
33025 self.as_vec_mut().extend(value.to_be_bytes());
33026 self
33027 }
33028 pub fn push_enc_ipv4_dst(mut self, value: u32) -> Self {
33029 push_header(self.as_vec_mut(), 4u16, 4 as u16);
33030 self.as_vec_mut().extend(value.to_be_bytes());
33031 self
33032 }
33033 pub fn push_enc_ipv6_src(mut self, value: &[u8]) -> Self {
33034 push_header(self.as_vec_mut(), 5u16, value.len() as u16);
33035 self.as_vec_mut().extend(value);
33036 self
33037 }
33038 pub fn push_enc_ipv6_dst(mut self, value: &[u8]) -> Self {
33039 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
33040 self.as_vec_mut().extend(value);
33041 self
33042 }
33043 pub fn push_enc_key_id(mut self, value: u64) -> Self {
33044 push_header(self.as_vec_mut(), 7u16, 8 as u16);
33045 self.as_vec_mut().extend(value.to_be_bytes());
33046 self
33047 }
33048 pub fn push_pad(mut self, value: &[u8]) -> Self {
33049 push_header(self.as_vec_mut(), 8u16, value.len() as u16);
33050 self.as_vec_mut().extend(value);
33051 self
33052 }
33053 pub fn push_enc_dst_port(mut self, value: u16) -> Self {
33054 push_header(self.as_vec_mut(), 9u16, 2 as u16);
33055 self.as_vec_mut().extend(value.to_be_bytes());
33056 self
33057 }
33058 pub fn push_no_csum(mut self, value: u8) -> Self {
33059 push_header(self.as_vec_mut(), 10u16, 1 as u16);
33060 self.as_vec_mut().extend(value.to_ne_bytes());
33061 self
33062 }
33063 pub fn push_enc_opts(mut self, value: &[u8]) -> Self {
33064 push_header(self.as_vec_mut(), 11u16, value.len() as u16);
33065 self.as_vec_mut().extend(value);
33066 self
33067 }
33068 pub fn push_enc_tos(mut self, value: u8) -> Self {
33069 push_header(self.as_vec_mut(), 12u16, 1 as u16);
33070 self.as_vec_mut().extend(value.to_ne_bytes());
33071 self
33072 }
33073 pub fn push_enc_ttl(mut self, value: u8) -> Self {
33074 push_header(self.as_vec_mut(), 13u16, 1 as u16);
33075 self.as_vec_mut().extend(value.to_ne_bytes());
33076 self
33077 }
33078 pub fn push_no_frag(mut self, value: ()) -> Self {
33079 push_header(self.as_vec_mut(), 14u16, 0 as u16);
33080 self
33081 }
33082}
33083impl<Prev: Pusher> Drop for PushActTunnelKeyAttrs<Prev> {
33084 fn drop(&mut self) {
33085 if let Some(prev) = &mut self.prev {
33086 if let Some(header_offset) = &self.header_offset {
33087 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33088 }
33089 }
33090 }
33091}
33092pub struct PushActVlanAttrs<Prev: Pusher> {
33093 pub(crate) prev: Option<Prev>,
33094 pub(crate) header_offset: Option<usize>,
33095}
33096impl<Prev: Pusher> Pusher for PushActVlanAttrs<Prev> {
33097 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33098 self.prev.as_mut().unwrap().as_vec_mut()
33099 }
33100 fn as_vec(&self) -> &Vec<u8> {
33101 self.prev.as_ref().unwrap().as_vec()
33102 }
33103}
33104impl<Prev: Pusher> PushActVlanAttrs<Prev> {
33105 pub fn new(prev: Prev) -> Self {
33106 Self {
33107 prev: Some(prev),
33108 header_offset: None,
33109 }
33110 }
33111 pub fn end_nested(mut self) -> Prev {
33112 let mut prev = self.prev.take().unwrap();
33113 if let Some(header_offset) = &self.header_offset {
33114 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33115 }
33116 prev
33117 }
33118 pub fn push_tm(mut self, value: TcfT) -> Self {
33119 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
33120 self.as_vec_mut().extend(value.as_slice());
33121 self
33122 }
33123 pub fn push_parms(mut self, value: TcVlan) -> Self {
33124 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
33125 self.as_vec_mut().extend(value.as_slice());
33126 self
33127 }
33128 pub fn push_push_vlan_id(mut self, value: u16) -> Self {
33129 push_header(self.as_vec_mut(), 3u16, 2 as u16);
33130 self.as_vec_mut().extend(value.to_ne_bytes());
33131 self
33132 }
33133 pub fn push_push_vlan_protocol(mut self, value: u16) -> Self {
33134 push_header(self.as_vec_mut(), 4u16, 2 as u16);
33135 self.as_vec_mut().extend(value.to_ne_bytes());
33136 self
33137 }
33138 pub fn push_pad(mut self, value: &[u8]) -> Self {
33139 push_header(self.as_vec_mut(), 5u16, value.len() as u16);
33140 self.as_vec_mut().extend(value);
33141 self
33142 }
33143 pub fn push_push_vlan_priority(mut self, value: u8) -> Self {
33144 push_header(self.as_vec_mut(), 6u16, 1 as u16);
33145 self.as_vec_mut().extend(value.to_ne_bytes());
33146 self
33147 }
33148 pub fn push_push_eth_dst(mut self, value: &[u8]) -> Self {
33149 push_header(self.as_vec_mut(), 7u16, value.len() as u16);
33150 self.as_vec_mut().extend(value);
33151 self
33152 }
33153 pub fn push_push_eth_src(mut self, value: &[u8]) -> Self {
33154 push_header(self.as_vec_mut(), 8u16, value.len() as u16);
33155 self.as_vec_mut().extend(value);
33156 self
33157 }
33158}
33159impl<Prev: Pusher> Drop for PushActVlanAttrs<Prev> {
33160 fn drop(&mut self) {
33161 if let Some(prev) = &mut self.prev {
33162 if let Some(header_offset) = &self.header_offset {
33163 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33164 }
33165 }
33166 }
33167}
33168pub struct PushBasicAttrs<Prev: Pusher> {
33169 pub(crate) prev: Option<Prev>,
33170 pub(crate) header_offset: Option<usize>,
33171}
33172impl<Prev: Pusher> Pusher for PushBasicAttrs<Prev> {
33173 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33174 self.prev.as_mut().unwrap().as_vec_mut()
33175 }
33176 fn as_vec(&self) -> &Vec<u8> {
33177 self.prev.as_ref().unwrap().as_vec()
33178 }
33179}
33180pub struct PushArrayActAttrs<Prev: Pusher> {
33181 pub(crate) prev: Option<Prev>,
33182 pub(crate) header_offset: Option<usize>,
33183 pub(crate) counter: u16,
33184}
33185impl<Prev: Pusher> Pusher for PushArrayActAttrs<Prev> {
33186 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33187 self.prev.as_mut().unwrap().as_vec_mut()
33188 }
33189 fn as_vec(&self) -> &Vec<u8> {
33190 self.prev.as_ref().unwrap().as_vec()
33191 }
33192}
33193impl<Prev: Pusher> PushArrayActAttrs<Prev> {
33194 pub fn new(prev: Prev) -> Self {
33195 Self {
33196 prev: Some(prev),
33197 header_offset: None,
33198 counter: 0,
33199 }
33200 }
33201 pub fn end_array(mut self) -> Prev {
33202 let mut prev = self.prev.take().unwrap();
33203 if let Some(header_offset) = &self.header_offset {
33204 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33205 }
33206 prev
33207 }
33208 pub fn entry_nested(mut self) -> PushActAttrs<Self> {
33209 let index = self.counter;
33210 self.counter += 1;
33211 let header_offset = push_nested_header(self.as_vec_mut(), index);
33212 PushActAttrs {
33213 prev: Some(self),
33214 header_offset: Some(header_offset),
33215 }
33216 }
33217}
33218impl<Prev: Pusher> Drop for PushArrayActAttrs<Prev> {
33219 fn drop(&mut self) {
33220 if let Some(prev) = &mut self.prev {
33221 if let Some(header_offset) = &self.header_offset {
33222 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33223 }
33224 }
33225 }
33226}
33227impl<Prev: Pusher> PushBasicAttrs<Prev> {
33228 pub fn new(prev: Prev) -> Self {
33229 Self {
33230 prev: Some(prev),
33231 header_offset: None,
33232 }
33233 }
33234 pub fn end_nested(mut self) -> Prev {
33235 let mut prev = self.prev.take().unwrap();
33236 if let Some(header_offset) = &self.header_offset {
33237 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33238 }
33239 prev
33240 }
33241 pub fn push_classid(mut self, value: u32) -> Self {
33242 push_header(self.as_vec_mut(), 1u16, 4 as u16);
33243 self.as_vec_mut().extend(value.to_ne_bytes());
33244 self
33245 }
33246 pub fn nested_ematches(mut self) -> PushEmatchAttrs<Self> {
33247 let header_offset = push_nested_header(self.as_vec_mut(), 2u16);
33248 PushEmatchAttrs {
33249 prev: Some(self),
33250 header_offset: Some(header_offset),
33251 }
33252 }
33253 pub fn array_act(mut self) -> PushArrayActAttrs<Self> {
33254 let header_offset = push_nested_header(self.as_vec_mut(), 3u16);
33255 PushArrayActAttrs {
33256 prev: Some(self),
33257 header_offset: Some(header_offset),
33258 counter: 0,
33259 }
33260 }
33261 pub fn nested_police(mut self) -> PushPoliceAttrs<Self> {
33262 let header_offset = push_nested_header(self.as_vec_mut(), 4u16);
33263 PushPoliceAttrs {
33264 prev: Some(self),
33265 header_offset: Some(header_offset),
33266 }
33267 }
33268 pub fn push_pcnt(mut self, value: TcBasicPcnt) -> Self {
33269 push_header(self.as_vec_mut(), 5u16, value.as_slice().len() as u16);
33270 self.as_vec_mut().extend(value.as_slice());
33271 self
33272 }
33273 pub fn push_pad(mut self, value: &[u8]) -> Self {
33274 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
33275 self.as_vec_mut().extend(value);
33276 self
33277 }
33278}
33279impl<Prev: Pusher> Drop for PushBasicAttrs<Prev> {
33280 fn drop(&mut self) {
33281 if let Some(prev) = &mut self.prev {
33282 if let Some(header_offset) = &self.header_offset {
33283 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33284 }
33285 }
33286 }
33287}
33288pub struct PushBpfAttrs<Prev: Pusher> {
33289 pub(crate) prev: Option<Prev>,
33290 pub(crate) header_offset: Option<usize>,
33291}
33292impl<Prev: Pusher> Pusher for PushBpfAttrs<Prev> {
33293 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33294 self.prev.as_mut().unwrap().as_vec_mut()
33295 }
33296 fn as_vec(&self) -> &Vec<u8> {
33297 self.prev.as_ref().unwrap().as_vec()
33298 }
33299}
33300impl<Prev: Pusher> PushBpfAttrs<Prev> {
33301 pub fn new(prev: Prev) -> Self {
33302 Self {
33303 prev: Some(prev),
33304 header_offset: None,
33305 }
33306 }
33307 pub fn end_nested(mut self) -> Prev {
33308 let mut prev = self.prev.take().unwrap();
33309 if let Some(header_offset) = &self.header_offset {
33310 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33311 }
33312 prev
33313 }
33314 pub fn array_act(mut self) -> PushArrayActAttrs<Self> {
33315 let header_offset = push_nested_header(self.as_vec_mut(), 1u16);
33316 PushArrayActAttrs {
33317 prev: Some(self),
33318 header_offset: Some(header_offset),
33319 counter: 0,
33320 }
33321 }
33322 pub fn nested_police(mut self) -> PushPoliceAttrs<Self> {
33323 let header_offset = push_nested_header(self.as_vec_mut(), 2u16);
33324 PushPoliceAttrs {
33325 prev: Some(self),
33326 header_offset: Some(header_offset),
33327 }
33328 }
33329 pub fn push_classid(mut self, value: u32) -> Self {
33330 push_header(self.as_vec_mut(), 3u16, 4 as u16);
33331 self.as_vec_mut().extend(value.to_ne_bytes());
33332 self
33333 }
33334 pub fn push_ops_len(mut self, value: u16) -> Self {
33335 push_header(self.as_vec_mut(), 4u16, 2 as u16);
33336 self.as_vec_mut().extend(value.to_ne_bytes());
33337 self
33338 }
33339 pub fn push_ops(mut self, value: &[u8]) -> Self {
33340 push_header(self.as_vec_mut(), 5u16, value.len() as u16);
33341 self.as_vec_mut().extend(value);
33342 self
33343 }
33344 pub fn push_fd(mut self, value: u32) -> Self {
33345 push_header(self.as_vec_mut(), 6u16, 4 as u16);
33346 self.as_vec_mut().extend(value.to_ne_bytes());
33347 self
33348 }
33349 pub fn push_name(mut self, value: &CStr) -> Self {
33350 push_header(
33351 self.as_vec_mut(),
33352 7u16,
33353 value.to_bytes_with_nul().len() as u16,
33354 );
33355 self.as_vec_mut().extend(value.to_bytes_with_nul());
33356 self
33357 }
33358 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
33359 push_header(self.as_vec_mut(), 7u16, (value.len() + 1) as u16);
33360 self.as_vec_mut().extend(value);
33361 self.as_vec_mut().push(0);
33362 self
33363 }
33364 pub fn push_flags(mut self, value: u32) -> Self {
33365 push_header(self.as_vec_mut(), 8u16, 4 as u16);
33366 self.as_vec_mut().extend(value.to_ne_bytes());
33367 self
33368 }
33369 pub fn push_flags_gen(mut self, value: u32) -> Self {
33370 push_header(self.as_vec_mut(), 9u16, 4 as u16);
33371 self.as_vec_mut().extend(value.to_ne_bytes());
33372 self
33373 }
33374 pub fn push_tag(mut self, value: &[u8]) -> Self {
33375 push_header(self.as_vec_mut(), 10u16, value.len() as u16);
33376 self.as_vec_mut().extend(value);
33377 self
33378 }
33379 pub fn push_id(mut self, value: u32) -> Self {
33380 push_header(self.as_vec_mut(), 11u16, 4 as u16);
33381 self.as_vec_mut().extend(value.to_ne_bytes());
33382 self
33383 }
33384}
33385impl<Prev: Pusher> Drop for PushBpfAttrs<Prev> {
33386 fn drop(&mut self) {
33387 if let Some(prev) = &mut self.prev {
33388 if let Some(header_offset) = &self.header_offset {
33389 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33390 }
33391 }
33392 }
33393}
33394pub struct PushCakeAttrs<Prev: Pusher> {
33395 pub(crate) prev: Option<Prev>,
33396 pub(crate) header_offset: Option<usize>,
33397}
33398impl<Prev: Pusher> Pusher for PushCakeAttrs<Prev> {
33399 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33400 self.prev.as_mut().unwrap().as_vec_mut()
33401 }
33402 fn as_vec(&self) -> &Vec<u8> {
33403 self.prev.as_ref().unwrap().as_vec()
33404 }
33405}
33406impl<Prev: Pusher> PushCakeAttrs<Prev> {
33407 pub fn new(prev: Prev) -> Self {
33408 Self {
33409 prev: Some(prev),
33410 header_offset: None,
33411 }
33412 }
33413 pub fn end_nested(mut self) -> Prev {
33414 let mut prev = self.prev.take().unwrap();
33415 if let Some(header_offset) = &self.header_offset {
33416 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33417 }
33418 prev
33419 }
33420 pub fn push_pad(mut self, value: &[u8]) -> Self {
33421 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
33422 self.as_vec_mut().extend(value);
33423 self
33424 }
33425 pub fn push_base_rate64(mut self, value: u64) -> Self {
33426 push_header(self.as_vec_mut(), 2u16, 8 as u16);
33427 self.as_vec_mut().extend(value.to_ne_bytes());
33428 self
33429 }
33430 pub fn push_diffserv_mode(mut self, value: u32) -> Self {
33431 push_header(self.as_vec_mut(), 3u16, 4 as u16);
33432 self.as_vec_mut().extend(value.to_ne_bytes());
33433 self
33434 }
33435 pub fn push_atm(mut self, value: u32) -> Self {
33436 push_header(self.as_vec_mut(), 4u16, 4 as u16);
33437 self.as_vec_mut().extend(value.to_ne_bytes());
33438 self
33439 }
33440 pub fn push_flow_mode(mut self, value: u32) -> Self {
33441 push_header(self.as_vec_mut(), 5u16, 4 as u16);
33442 self.as_vec_mut().extend(value.to_ne_bytes());
33443 self
33444 }
33445 pub fn push_overhead(mut self, value: u32) -> Self {
33446 push_header(self.as_vec_mut(), 6u16, 4 as u16);
33447 self.as_vec_mut().extend(value.to_ne_bytes());
33448 self
33449 }
33450 pub fn push_rtt(mut self, value: u32) -> Self {
33451 push_header(self.as_vec_mut(), 7u16, 4 as u16);
33452 self.as_vec_mut().extend(value.to_ne_bytes());
33453 self
33454 }
33455 pub fn push_target(mut self, value: u32) -> Self {
33456 push_header(self.as_vec_mut(), 8u16, 4 as u16);
33457 self.as_vec_mut().extend(value.to_ne_bytes());
33458 self
33459 }
33460 pub fn push_autorate(mut self, value: u32) -> Self {
33461 push_header(self.as_vec_mut(), 9u16, 4 as u16);
33462 self.as_vec_mut().extend(value.to_ne_bytes());
33463 self
33464 }
33465 pub fn push_memory(mut self, value: u32) -> Self {
33466 push_header(self.as_vec_mut(), 10u16, 4 as u16);
33467 self.as_vec_mut().extend(value.to_ne_bytes());
33468 self
33469 }
33470 pub fn push_nat(mut self, value: u32) -> Self {
33471 push_header(self.as_vec_mut(), 11u16, 4 as u16);
33472 self.as_vec_mut().extend(value.to_ne_bytes());
33473 self
33474 }
33475 pub fn push_raw(mut self, value: u32) -> Self {
33476 push_header(self.as_vec_mut(), 12u16, 4 as u16);
33477 self.as_vec_mut().extend(value.to_ne_bytes());
33478 self
33479 }
33480 pub fn push_wash(mut self, value: u32) -> Self {
33481 push_header(self.as_vec_mut(), 13u16, 4 as u16);
33482 self.as_vec_mut().extend(value.to_ne_bytes());
33483 self
33484 }
33485 pub fn push_mpu(mut self, value: u32) -> Self {
33486 push_header(self.as_vec_mut(), 14u16, 4 as u16);
33487 self.as_vec_mut().extend(value.to_ne_bytes());
33488 self
33489 }
33490 pub fn push_ingress(mut self, value: u32) -> Self {
33491 push_header(self.as_vec_mut(), 15u16, 4 as u16);
33492 self.as_vec_mut().extend(value.to_ne_bytes());
33493 self
33494 }
33495 pub fn push_ack_filter(mut self, value: u32) -> Self {
33496 push_header(self.as_vec_mut(), 16u16, 4 as u16);
33497 self.as_vec_mut().extend(value.to_ne_bytes());
33498 self
33499 }
33500 pub fn push_split_gso(mut self, value: u32) -> Self {
33501 push_header(self.as_vec_mut(), 17u16, 4 as u16);
33502 self.as_vec_mut().extend(value.to_ne_bytes());
33503 self
33504 }
33505 pub fn push_fwmark(mut self, value: u32) -> Self {
33506 push_header(self.as_vec_mut(), 18u16, 4 as u16);
33507 self.as_vec_mut().extend(value.to_ne_bytes());
33508 self
33509 }
33510}
33511impl<Prev: Pusher> Drop for PushCakeAttrs<Prev> {
33512 fn drop(&mut self) {
33513 if let Some(prev) = &mut self.prev {
33514 if let Some(header_offset) = &self.header_offset {
33515 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33516 }
33517 }
33518 }
33519}
33520pub struct PushCakeStatsAttrs<Prev: Pusher> {
33521 pub(crate) prev: Option<Prev>,
33522 pub(crate) header_offset: Option<usize>,
33523}
33524impl<Prev: Pusher> Pusher for PushCakeStatsAttrs<Prev> {
33525 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33526 self.prev.as_mut().unwrap().as_vec_mut()
33527 }
33528 fn as_vec(&self) -> &Vec<u8> {
33529 self.prev.as_ref().unwrap().as_vec()
33530 }
33531}
33532pub struct PushArrayCakeTinStatsAttrs<Prev: Pusher> {
33533 pub(crate) prev: Option<Prev>,
33534 pub(crate) header_offset: Option<usize>,
33535 pub(crate) counter: u16,
33536}
33537impl<Prev: Pusher> Pusher for PushArrayCakeTinStatsAttrs<Prev> {
33538 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33539 self.prev.as_mut().unwrap().as_vec_mut()
33540 }
33541 fn as_vec(&self) -> &Vec<u8> {
33542 self.prev.as_ref().unwrap().as_vec()
33543 }
33544}
33545impl<Prev: Pusher> PushArrayCakeTinStatsAttrs<Prev> {
33546 pub fn new(prev: Prev) -> Self {
33547 Self {
33548 prev: Some(prev),
33549 header_offset: None,
33550 counter: 0,
33551 }
33552 }
33553 pub fn end_array(mut self) -> Prev {
33554 let mut prev = self.prev.take().unwrap();
33555 if let Some(header_offset) = &self.header_offset {
33556 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33557 }
33558 prev
33559 }
33560 pub fn entry_nested(mut self) -> PushCakeTinStatsAttrs<Self> {
33561 let index = self.counter;
33562 self.counter += 1;
33563 let header_offset = push_nested_header(self.as_vec_mut(), index);
33564 PushCakeTinStatsAttrs {
33565 prev: Some(self),
33566 header_offset: Some(header_offset),
33567 }
33568 }
33569}
33570impl<Prev: Pusher> Drop for PushArrayCakeTinStatsAttrs<Prev> {
33571 fn drop(&mut self) {
33572 if let Some(prev) = &mut self.prev {
33573 if let Some(header_offset) = &self.header_offset {
33574 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33575 }
33576 }
33577 }
33578}
33579impl<Prev: Pusher> PushCakeStatsAttrs<Prev> {
33580 pub fn new(prev: Prev) -> Self {
33581 Self {
33582 prev: Some(prev),
33583 header_offset: None,
33584 }
33585 }
33586 pub fn end_nested(mut self) -> Prev {
33587 let mut prev = self.prev.take().unwrap();
33588 if let Some(header_offset) = &self.header_offset {
33589 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33590 }
33591 prev
33592 }
33593 pub fn push_pad(mut self, value: &[u8]) -> Self {
33594 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
33595 self.as_vec_mut().extend(value);
33596 self
33597 }
33598 pub fn push_capacity_estimate64(mut self, value: u64) -> Self {
33599 push_header(self.as_vec_mut(), 2u16, 8 as u16);
33600 self.as_vec_mut().extend(value.to_ne_bytes());
33601 self
33602 }
33603 pub fn push_memory_limit(mut self, value: u32) -> Self {
33604 push_header(self.as_vec_mut(), 3u16, 4 as u16);
33605 self.as_vec_mut().extend(value.to_ne_bytes());
33606 self
33607 }
33608 pub fn push_memory_used(mut self, value: u32) -> Self {
33609 push_header(self.as_vec_mut(), 4u16, 4 as u16);
33610 self.as_vec_mut().extend(value.to_ne_bytes());
33611 self
33612 }
33613 pub fn push_avg_netoff(mut self, value: u32) -> Self {
33614 push_header(self.as_vec_mut(), 5u16, 4 as u16);
33615 self.as_vec_mut().extend(value.to_ne_bytes());
33616 self
33617 }
33618 pub fn push_min_netlen(mut self, value: u32) -> Self {
33619 push_header(self.as_vec_mut(), 6u16, 4 as u16);
33620 self.as_vec_mut().extend(value.to_ne_bytes());
33621 self
33622 }
33623 pub fn push_max_netlen(mut self, value: u32) -> Self {
33624 push_header(self.as_vec_mut(), 7u16, 4 as u16);
33625 self.as_vec_mut().extend(value.to_ne_bytes());
33626 self
33627 }
33628 pub fn push_min_adjlen(mut self, value: u32) -> Self {
33629 push_header(self.as_vec_mut(), 8u16, 4 as u16);
33630 self.as_vec_mut().extend(value.to_ne_bytes());
33631 self
33632 }
33633 pub fn push_max_adjlen(mut self, value: u32) -> Self {
33634 push_header(self.as_vec_mut(), 9u16, 4 as u16);
33635 self.as_vec_mut().extend(value.to_ne_bytes());
33636 self
33637 }
33638 pub fn array_tin_stats(mut self) -> PushArrayCakeTinStatsAttrs<Self> {
33639 let header_offset = push_nested_header(self.as_vec_mut(), 10u16);
33640 PushArrayCakeTinStatsAttrs {
33641 prev: Some(self),
33642 header_offset: Some(header_offset),
33643 counter: 0,
33644 }
33645 }
33646 pub fn push_deficit(mut self, value: i32) -> Self {
33647 push_header(self.as_vec_mut(), 11u16, 4 as u16);
33648 self.as_vec_mut().extend(value.to_ne_bytes());
33649 self
33650 }
33651 pub fn push_cobalt_count(mut self, value: u32) -> Self {
33652 push_header(self.as_vec_mut(), 12u16, 4 as u16);
33653 self.as_vec_mut().extend(value.to_ne_bytes());
33654 self
33655 }
33656 pub fn push_dropping(mut self, value: u32) -> Self {
33657 push_header(self.as_vec_mut(), 13u16, 4 as u16);
33658 self.as_vec_mut().extend(value.to_ne_bytes());
33659 self
33660 }
33661 pub fn push_drop_next_us(mut self, value: i32) -> Self {
33662 push_header(self.as_vec_mut(), 14u16, 4 as u16);
33663 self.as_vec_mut().extend(value.to_ne_bytes());
33664 self
33665 }
33666 pub fn push_p_drop(mut self, value: u32) -> Self {
33667 push_header(self.as_vec_mut(), 15u16, 4 as u16);
33668 self.as_vec_mut().extend(value.to_ne_bytes());
33669 self
33670 }
33671 pub fn push_blue_timer_us(mut self, value: i32) -> Self {
33672 push_header(self.as_vec_mut(), 16u16, 4 as u16);
33673 self.as_vec_mut().extend(value.to_ne_bytes());
33674 self
33675 }
33676 pub fn push_active_queues(mut self, value: u32) -> Self {
33677 push_header(self.as_vec_mut(), 17u16, 4 as u16);
33678 self.as_vec_mut().extend(value.to_ne_bytes());
33679 self
33680 }
33681}
33682impl<Prev: Pusher> Drop for PushCakeStatsAttrs<Prev> {
33683 fn drop(&mut self) {
33684 if let Some(prev) = &mut self.prev {
33685 if let Some(header_offset) = &self.header_offset {
33686 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33687 }
33688 }
33689 }
33690}
33691pub struct PushCakeTinStatsAttrs<Prev: Pusher> {
33692 pub(crate) prev: Option<Prev>,
33693 pub(crate) header_offset: Option<usize>,
33694}
33695impl<Prev: Pusher> Pusher for PushCakeTinStatsAttrs<Prev> {
33696 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33697 self.prev.as_mut().unwrap().as_vec_mut()
33698 }
33699 fn as_vec(&self) -> &Vec<u8> {
33700 self.prev.as_ref().unwrap().as_vec()
33701 }
33702}
33703impl<Prev: Pusher> PushCakeTinStatsAttrs<Prev> {
33704 pub fn new(prev: Prev) -> Self {
33705 Self {
33706 prev: Some(prev),
33707 header_offset: None,
33708 }
33709 }
33710 pub fn end_nested(mut self) -> Prev {
33711 let mut prev = self.prev.take().unwrap();
33712 if let Some(header_offset) = &self.header_offset {
33713 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33714 }
33715 prev
33716 }
33717 pub fn push_pad(mut self, value: &[u8]) -> Self {
33718 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
33719 self.as_vec_mut().extend(value);
33720 self
33721 }
33722 pub fn push_sent_packets(mut self, value: u32) -> Self {
33723 push_header(self.as_vec_mut(), 2u16, 4 as u16);
33724 self.as_vec_mut().extend(value.to_ne_bytes());
33725 self
33726 }
33727 pub fn push_sent_bytes64(mut self, value: u64) -> Self {
33728 push_header(self.as_vec_mut(), 3u16, 8 as u16);
33729 self.as_vec_mut().extend(value.to_ne_bytes());
33730 self
33731 }
33732 pub fn push_dropped_packets(mut self, value: u32) -> Self {
33733 push_header(self.as_vec_mut(), 4u16, 4 as u16);
33734 self.as_vec_mut().extend(value.to_ne_bytes());
33735 self
33736 }
33737 pub fn push_dropped_bytes64(mut self, value: u64) -> Self {
33738 push_header(self.as_vec_mut(), 5u16, 8 as u16);
33739 self.as_vec_mut().extend(value.to_ne_bytes());
33740 self
33741 }
33742 pub fn push_acks_dropped_packets(mut self, value: u32) -> Self {
33743 push_header(self.as_vec_mut(), 6u16, 4 as u16);
33744 self.as_vec_mut().extend(value.to_ne_bytes());
33745 self
33746 }
33747 pub fn push_acks_dropped_bytes64(mut self, value: u64) -> Self {
33748 push_header(self.as_vec_mut(), 7u16, 8 as u16);
33749 self.as_vec_mut().extend(value.to_ne_bytes());
33750 self
33751 }
33752 pub fn push_ecn_marked_packets(mut self, value: u32) -> Self {
33753 push_header(self.as_vec_mut(), 8u16, 4 as u16);
33754 self.as_vec_mut().extend(value.to_ne_bytes());
33755 self
33756 }
33757 pub fn push_ecn_marked_bytes64(mut self, value: u64) -> Self {
33758 push_header(self.as_vec_mut(), 9u16, 8 as u16);
33759 self.as_vec_mut().extend(value.to_ne_bytes());
33760 self
33761 }
33762 pub fn push_backlog_packets(mut self, value: u32) -> Self {
33763 push_header(self.as_vec_mut(), 10u16, 4 as u16);
33764 self.as_vec_mut().extend(value.to_ne_bytes());
33765 self
33766 }
33767 pub fn push_backlog_bytes(mut self, value: u32) -> Self {
33768 push_header(self.as_vec_mut(), 11u16, 4 as u16);
33769 self.as_vec_mut().extend(value.to_ne_bytes());
33770 self
33771 }
33772 pub fn push_threshold_rate64(mut self, value: u64) -> Self {
33773 push_header(self.as_vec_mut(), 12u16, 8 as u16);
33774 self.as_vec_mut().extend(value.to_ne_bytes());
33775 self
33776 }
33777 pub fn push_target_us(mut self, value: u32) -> Self {
33778 push_header(self.as_vec_mut(), 13u16, 4 as u16);
33779 self.as_vec_mut().extend(value.to_ne_bytes());
33780 self
33781 }
33782 pub fn push_interval_us(mut self, value: u32) -> Self {
33783 push_header(self.as_vec_mut(), 14u16, 4 as u16);
33784 self.as_vec_mut().extend(value.to_ne_bytes());
33785 self
33786 }
33787 pub fn push_way_indirect_hits(mut self, value: u32) -> Self {
33788 push_header(self.as_vec_mut(), 15u16, 4 as u16);
33789 self.as_vec_mut().extend(value.to_ne_bytes());
33790 self
33791 }
33792 pub fn push_way_misses(mut self, value: u32) -> Self {
33793 push_header(self.as_vec_mut(), 16u16, 4 as u16);
33794 self.as_vec_mut().extend(value.to_ne_bytes());
33795 self
33796 }
33797 pub fn push_way_collisions(mut self, value: u32) -> Self {
33798 push_header(self.as_vec_mut(), 17u16, 4 as u16);
33799 self.as_vec_mut().extend(value.to_ne_bytes());
33800 self
33801 }
33802 pub fn push_peak_delay_us(mut self, value: u32) -> Self {
33803 push_header(self.as_vec_mut(), 18u16, 4 as u16);
33804 self.as_vec_mut().extend(value.to_ne_bytes());
33805 self
33806 }
33807 pub fn push_avg_delay_us(mut self, value: u32) -> Self {
33808 push_header(self.as_vec_mut(), 19u16, 4 as u16);
33809 self.as_vec_mut().extend(value.to_ne_bytes());
33810 self
33811 }
33812 pub fn push_base_delay_us(mut self, value: u32) -> Self {
33813 push_header(self.as_vec_mut(), 20u16, 4 as u16);
33814 self.as_vec_mut().extend(value.to_ne_bytes());
33815 self
33816 }
33817 pub fn push_sparse_flows(mut self, value: u32) -> Self {
33818 push_header(self.as_vec_mut(), 21u16, 4 as u16);
33819 self.as_vec_mut().extend(value.to_ne_bytes());
33820 self
33821 }
33822 pub fn push_bulk_flows(mut self, value: u32) -> Self {
33823 push_header(self.as_vec_mut(), 22u16, 4 as u16);
33824 self.as_vec_mut().extend(value.to_ne_bytes());
33825 self
33826 }
33827 pub fn push_unresponsive_flows(mut self, value: u32) -> Self {
33828 push_header(self.as_vec_mut(), 23u16, 4 as u16);
33829 self.as_vec_mut().extend(value.to_ne_bytes());
33830 self
33831 }
33832 pub fn push_max_skblen(mut self, value: u32) -> Self {
33833 push_header(self.as_vec_mut(), 24u16, 4 as u16);
33834 self.as_vec_mut().extend(value.to_ne_bytes());
33835 self
33836 }
33837 pub fn push_flow_quantum(mut self, value: u32) -> Self {
33838 push_header(self.as_vec_mut(), 25u16, 4 as u16);
33839 self.as_vec_mut().extend(value.to_ne_bytes());
33840 self
33841 }
33842}
33843impl<Prev: Pusher> Drop for PushCakeTinStatsAttrs<Prev> {
33844 fn drop(&mut self) {
33845 if let Some(prev) = &mut self.prev {
33846 if let Some(header_offset) = &self.header_offset {
33847 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33848 }
33849 }
33850 }
33851}
33852pub struct PushCbsAttrs<Prev: Pusher> {
33853 pub(crate) prev: Option<Prev>,
33854 pub(crate) header_offset: Option<usize>,
33855}
33856impl<Prev: Pusher> Pusher for PushCbsAttrs<Prev> {
33857 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33858 self.prev.as_mut().unwrap().as_vec_mut()
33859 }
33860 fn as_vec(&self) -> &Vec<u8> {
33861 self.prev.as_ref().unwrap().as_vec()
33862 }
33863}
33864impl<Prev: Pusher> PushCbsAttrs<Prev> {
33865 pub fn new(prev: Prev) -> Self {
33866 Self {
33867 prev: Some(prev),
33868 header_offset: None,
33869 }
33870 }
33871 pub fn end_nested(mut self) -> Prev {
33872 let mut prev = self.prev.take().unwrap();
33873 if let Some(header_offset) = &self.header_offset {
33874 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33875 }
33876 prev
33877 }
33878 pub fn push_parms(mut self, value: TcCbsQopt) -> Self {
33879 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
33880 self.as_vec_mut().extend(value.as_slice());
33881 self
33882 }
33883}
33884impl<Prev: Pusher> Drop for PushCbsAttrs<Prev> {
33885 fn drop(&mut self) {
33886 if let Some(prev) = &mut self.prev {
33887 if let Some(header_offset) = &self.header_offset {
33888 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33889 }
33890 }
33891 }
33892}
33893pub struct PushCgroupAttrs<Prev: Pusher> {
33894 pub(crate) prev: Option<Prev>,
33895 pub(crate) header_offset: Option<usize>,
33896}
33897impl<Prev: Pusher> Pusher for PushCgroupAttrs<Prev> {
33898 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33899 self.prev.as_mut().unwrap().as_vec_mut()
33900 }
33901 fn as_vec(&self) -> &Vec<u8> {
33902 self.prev.as_ref().unwrap().as_vec()
33903 }
33904}
33905impl<Prev: Pusher> PushCgroupAttrs<Prev> {
33906 pub fn new(prev: Prev) -> Self {
33907 Self {
33908 prev: Some(prev),
33909 header_offset: None,
33910 }
33911 }
33912 pub fn end_nested(mut self) -> Prev {
33913 let mut prev = self.prev.take().unwrap();
33914 if let Some(header_offset) = &self.header_offset {
33915 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33916 }
33917 prev
33918 }
33919 pub fn array_act(mut self) -> PushArrayActAttrs<Self> {
33920 let header_offset = push_nested_header(self.as_vec_mut(), 1u16);
33921 PushArrayActAttrs {
33922 prev: Some(self),
33923 header_offset: Some(header_offset),
33924 counter: 0,
33925 }
33926 }
33927 pub fn nested_police(mut self) -> PushPoliceAttrs<Self> {
33928 let header_offset = push_nested_header(self.as_vec_mut(), 2u16);
33929 PushPoliceAttrs {
33930 prev: Some(self),
33931 header_offset: Some(header_offset),
33932 }
33933 }
33934 pub fn push_ematches(mut self, value: &[u8]) -> Self {
33935 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
33936 self.as_vec_mut().extend(value);
33937 self
33938 }
33939}
33940impl<Prev: Pusher> Drop for PushCgroupAttrs<Prev> {
33941 fn drop(&mut self) {
33942 if let Some(prev) = &mut self.prev {
33943 if let Some(header_offset) = &self.header_offset {
33944 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33945 }
33946 }
33947 }
33948}
33949pub struct PushChokeAttrs<Prev: Pusher> {
33950 pub(crate) prev: Option<Prev>,
33951 pub(crate) header_offset: Option<usize>,
33952}
33953impl<Prev: Pusher> Pusher for PushChokeAttrs<Prev> {
33954 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
33955 self.prev.as_mut().unwrap().as_vec_mut()
33956 }
33957 fn as_vec(&self) -> &Vec<u8> {
33958 self.prev.as_ref().unwrap().as_vec()
33959 }
33960}
33961impl<Prev: Pusher> PushChokeAttrs<Prev> {
33962 pub fn new(prev: Prev) -> Self {
33963 Self {
33964 prev: Some(prev),
33965 header_offset: None,
33966 }
33967 }
33968 pub fn end_nested(mut self) -> Prev {
33969 let mut prev = self.prev.take().unwrap();
33970 if let Some(header_offset) = &self.header_offset {
33971 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33972 }
33973 prev
33974 }
33975 pub fn push_parms(mut self, value: TcRedQopt) -> Self {
33976 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
33977 self.as_vec_mut().extend(value.as_slice());
33978 self
33979 }
33980 pub fn push_stab(mut self, value: &[u8]) -> Self {
33981 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
33982 self.as_vec_mut().extend(value);
33983 self
33984 }
33985 pub fn push_max_p(mut self, value: u32) -> Self {
33986 push_header(self.as_vec_mut(), 3u16, 4 as u16);
33987 self.as_vec_mut().extend(value.to_ne_bytes());
33988 self
33989 }
33990}
33991impl<Prev: Pusher> Drop for PushChokeAttrs<Prev> {
33992 fn drop(&mut self) {
33993 if let Some(prev) = &mut self.prev {
33994 if let Some(header_offset) = &self.header_offset {
33995 finalize_nested_header(prev.as_vec_mut(), *header_offset);
33996 }
33997 }
33998 }
33999}
34000pub struct PushCodelAttrs<Prev: Pusher> {
34001 pub(crate) prev: Option<Prev>,
34002 pub(crate) header_offset: Option<usize>,
34003}
34004impl<Prev: Pusher> Pusher for PushCodelAttrs<Prev> {
34005 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
34006 self.prev.as_mut().unwrap().as_vec_mut()
34007 }
34008 fn as_vec(&self) -> &Vec<u8> {
34009 self.prev.as_ref().unwrap().as_vec()
34010 }
34011}
34012impl<Prev: Pusher> PushCodelAttrs<Prev> {
34013 pub fn new(prev: Prev) -> Self {
34014 Self {
34015 prev: Some(prev),
34016 header_offset: None,
34017 }
34018 }
34019 pub fn end_nested(mut self) -> Prev {
34020 let mut prev = self.prev.take().unwrap();
34021 if let Some(header_offset) = &self.header_offset {
34022 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34023 }
34024 prev
34025 }
34026 pub fn push_target(mut self, value: u32) -> Self {
34027 push_header(self.as_vec_mut(), 1u16, 4 as u16);
34028 self.as_vec_mut().extend(value.to_ne_bytes());
34029 self
34030 }
34031 pub fn push_limit(mut self, value: u32) -> Self {
34032 push_header(self.as_vec_mut(), 2u16, 4 as u16);
34033 self.as_vec_mut().extend(value.to_ne_bytes());
34034 self
34035 }
34036 pub fn push_interval(mut self, value: u32) -> Self {
34037 push_header(self.as_vec_mut(), 3u16, 4 as u16);
34038 self.as_vec_mut().extend(value.to_ne_bytes());
34039 self
34040 }
34041 pub fn push_ecn(mut self, value: u32) -> Self {
34042 push_header(self.as_vec_mut(), 4u16, 4 as u16);
34043 self.as_vec_mut().extend(value.to_ne_bytes());
34044 self
34045 }
34046 pub fn push_ce_threshold(mut self, value: u32) -> Self {
34047 push_header(self.as_vec_mut(), 5u16, 4 as u16);
34048 self.as_vec_mut().extend(value.to_ne_bytes());
34049 self
34050 }
34051}
34052impl<Prev: Pusher> Drop for PushCodelAttrs<Prev> {
34053 fn drop(&mut self) {
34054 if let Some(prev) = &mut self.prev {
34055 if let Some(header_offset) = &self.header_offset {
34056 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34057 }
34058 }
34059 }
34060}
34061pub struct PushDrrAttrs<Prev: Pusher> {
34062 pub(crate) prev: Option<Prev>,
34063 pub(crate) header_offset: Option<usize>,
34064}
34065impl<Prev: Pusher> Pusher for PushDrrAttrs<Prev> {
34066 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
34067 self.prev.as_mut().unwrap().as_vec_mut()
34068 }
34069 fn as_vec(&self) -> &Vec<u8> {
34070 self.prev.as_ref().unwrap().as_vec()
34071 }
34072}
34073impl<Prev: Pusher> PushDrrAttrs<Prev> {
34074 pub fn new(prev: Prev) -> Self {
34075 Self {
34076 prev: Some(prev),
34077 header_offset: None,
34078 }
34079 }
34080 pub fn end_nested(mut self) -> Prev {
34081 let mut prev = self.prev.take().unwrap();
34082 if let Some(header_offset) = &self.header_offset {
34083 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34084 }
34085 prev
34086 }
34087 pub fn push_quantum(mut self, value: u32) -> Self {
34088 push_header(self.as_vec_mut(), 1u16, 4 as u16);
34089 self.as_vec_mut().extend(value.to_ne_bytes());
34090 self
34091 }
34092}
34093impl<Prev: Pusher> Drop for PushDrrAttrs<Prev> {
34094 fn drop(&mut self) {
34095 if let Some(prev) = &mut self.prev {
34096 if let Some(header_offset) = &self.header_offset {
34097 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34098 }
34099 }
34100 }
34101}
34102pub struct PushDualpi2Attrs<Prev: Pusher> {
34103 pub(crate) prev: Option<Prev>,
34104 pub(crate) header_offset: Option<usize>,
34105}
34106impl<Prev: Pusher> Pusher for PushDualpi2Attrs<Prev> {
34107 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
34108 self.prev.as_mut().unwrap().as_vec_mut()
34109 }
34110 fn as_vec(&self) -> &Vec<u8> {
34111 self.prev.as_ref().unwrap().as_vec()
34112 }
34113}
34114impl<Prev: Pusher> PushDualpi2Attrs<Prev> {
34115 pub fn new(prev: Prev) -> Self {
34116 Self {
34117 prev: Some(prev),
34118 header_offset: None,
34119 }
34120 }
34121 pub fn end_nested(mut self) -> Prev {
34122 let mut prev = self.prev.take().unwrap();
34123 if let Some(header_offset) = &self.header_offset {
34124 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34125 }
34126 prev
34127 }
34128 #[doc = "Limit of total number of packets in queue\n"]
34129 pub fn push_limit(mut self, value: u32) -> Self {
34130 push_header(self.as_vec_mut(), 1u16, 4 as u16);
34131 self.as_vec_mut().extend(value.to_ne_bytes());
34132 self
34133 }
34134 #[doc = "Memory limit of total number of packets in queue\n"]
34135 pub fn push_memory_limit(mut self, value: u32) -> Self {
34136 push_header(self.as_vec_mut(), 2u16, 4 as u16);
34137 self.as_vec_mut().extend(value.to_ne_bytes());
34138 self
34139 }
34140 #[doc = "Classic target delay in microseconds\n"]
34141 pub fn push_target(mut self, value: u32) -> Self {
34142 push_header(self.as_vec_mut(), 3u16, 4 as u16);
34143 self.as_vec_mut().extend(value.to_ne_bytes());
34144 self
34145 }
34146 #[doc = "Drop probability update interval time in microseconds\n"]
34147 pub fn push_tupdate(mut self, value: u32) -> Self {
34148 push_header(self.as_vec_mut(), 4u16, 4 as u16);
34149 self.as_vec_mut().extend(value.to_ne_bytes());
34150 self
34151 }
34152 #[doc = "Integral gain factor in Hz for PI controller\n"]
34153 pub fn push_alpha(mut self, value: u32) -> Self {
34154 push_header(self.as_vec_mut(), 5u16, 4 as u16);
34155 self.as_vec_mut().extend(value.to_ne_bytes());
34156 self
34157 }
34158 #[doc = "Proportional gain factor in Hz for PI controller\n"]
34159 pub fn push_beta(mut self, value: u32) -> Self {
34160 push_header(self.as_vec_mut(), 6u16, 4 as u16);
34161 self.as_vec_mut().extend(value.to_ne_bytes());
34162 self
34163 }
34164 #[doc = "L4S step marking threshold in packets\n"]
34165 pub fn push_step_thresh_pkts(mut self, value: u32) -> Self {
34166 push_header(self.as_vec_mut(), 7u16, 4 as u16);
34167 self.as_vec_mut().extend(value.to_ne_bytes());
34168 self
34169 }
34170 #[doc = "L4S Step marking threshold in microseconds\n"]
34171 pub fn push_step_thresh_us(mut self, value: u32) -> Self {
34172 push_header(self.as_vec_mut(), 8u16, 4 as u16);
34173 self.as_vec_mut().extend(value.to_ne_bytes());
34174 self
34175 }
34176 #[doc = "Packets enqueued to the L-queue can apply the step threshold when the\nqueue length of L-queue is larger than this value. (0 is recommended)\n"]
34177 pub fn push_min_qlen_step(mut self, value: u32) -> Self {
34178 push_header(self.as_vec_mut(), 9u16, 4 as u16);
34179 self.as_vec_mut().extend(value.to_ne_bytes());
34180 self
34181 }
34182 #[doc = "Probability coupling factor between Classic and L4S (2 is recommended)\n"]
34183 pub fn push_coupling(mut self, value: u8) -> Self {
34184 push_header(self.as_vec_mut(), 10u16, 1 as u16);
34185 self.as_vec_mut().extend(value.to_ne_bytes());
34186 self
34187 }
34188 #[doc = "Control the overload strategy (drop to preserve latency or let the queue\noverflow)\n\nAssociated type: [`Dualpi2DropOverload`] (enum)"]
34189 pub fn push_drop_overload(mut self, value: u8) -> Self {
34190 push_header(self.as_vec_mut(), 11u16, 1 as u16);
34191 self.as_vec_mut().extend(value.to_ne_bytes());
34192 self
34193 }
34194 #[doc = "Decide where the Classic packets are PI-based dropped or marked\n\nAssociated type: [`Dualpi2DropEarly`] (enum)"]
34195 pub fn push_drop_early(mut self, value: u8) -> Self {
34196 push_header(self.as_vec_mut(), 12u16, 1 as u16);
34197 self.as_vec_mut().extend(value.to_ne_bytes());
34198 self
34199 }
34200 #[doc = "Classic WRR weight in percentage (from 0 to 100)\n"]
34201 pub fn push_c_protection(mut self, value: u8) -> Self {
34202 push_header(self.as_vec_mut(), 13u16, 1 as u16);
34203 self.as_vec_mut().extend(value.to_ne_bytes());
34204 self
34205 }
34206 #[doc = "Configure the L-queue ECN classifier\n\nAssociated type: [`Dualpi2EcnMask`] (enum)"]
34207 pub fn push_ecn_mask(mut self, value: u8) -> Self {
34208 push_header(self.as_vec_mut(), 14u16, 1 as u16);
34209 self.as_vec_mut().extend(value.to_ne_bytes());
34210 self
34211 }
34212 #[doc = "Split aggregated skb or not\n\nAssociated type: [`Dualpi2SplitGso`] (enum)"]
34213 pub fn push_split_gso(mut self, value: u8) -> Self {
34214 push_header(self.as_vec_mut(), 15u16, 1 as u16);
34215 self.as_vec_mut().extend(value.to_ne_bytes());
34216 self
34217 }
34218}
34219impl<Prev: Pusher> Drop for PushDualpi2Attrs<Prev> {
34220 fn drop(&mut self) {
34221 if let Some(prev) = &mut self.prev {
34222 if let Some(header_offset) = &self.header_offset {
34223 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34224 }
34225 }
34226 }
34227}
34228pub struct PushEmatchAttrs<Prev: Pusher> {
34229 pub(crate) prev: Option<Prev>,
34230 pub(crate) header_offset: Option<usize>,
34231}
34232impl<Prev: Pusher> Pusher for PushEmatchAttrs<Prev> {
34233 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
34234 self.prev.as_mut().unwrap().as_vec_mut()
34235 }
34236 fn as_vec(&self) -> &Vec<u8> {
34237 self.prev.as_ref().unwrap().as_vec()
34238 }
34239}
34240impl<Prev: Pusher> PushEmatchAttrs<Prev> {
34241 pub fn new(prev: Prev) -> Self {
34242 Self {
34243 prev: Some(prev),
34244 header_offset: None,
34245 }
34246 }
34247 pub fn end_nested(mut self) -> Prev {
34248 let mut prev = self.prev.take().unwrap();
34249 if let Some(header_offset) = &self.header_offset {
34250 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34251 }
34252 prev
34253 }
34254 pub fn push_tree_hdr(mut self, value: TcfEmatchTreeHdr) -> Self {
34255 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
34256 self.as_vec_mut().extend(value.as_slice());
34257 self
34258 }
34259 pub fn push_tree_list(mut self, value: &[u8]) -> Self {
34260 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
34261 self.as_vec_mut().extend(value);
34262 self
34263 }
34264}
34265impl<Prev: Pusher> Drop for PushEmatchAttrs<Prev> {
34266 fn drop(&mut self) {
34267 if let Some(prev) = &mut self.prev {
34268 if let Some(header_offset) = &self.header_offset {
34269 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34270 }
34271 }
34272 }
34273}
34274pub struct PushFlowAttrs<Prev: Pusher> {
34275 pub(crate) prev: Option<Prev>,
34276 pub(crate) header_offset: Option<usize>,
34277}
34278impl<Prev: Pusher> Pusher for PushFlowAttrs<Prev> {
34279 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
34280 self.prev.as_mut().unwrap().as_vec_mut()
34281 }
34282 fn as_vec(&self) -> &Vec<u8> {
34283 self.prev.as_ref().unwrap().as_vec()
34284 }
34285}
34286impl<Prev: Pusher> PushFlowAttrs<Prev> {
34287 pub fn new(prev: Prev) -> Self {
34288 Self {
34289 prev: Some(prev),
34290 header_offset: None,
34291 }
34292 }
34293 pub fn end_nested(mut self) -> Prev {
34294 let mut prev = self.prev.take().unwrap();
34295 if let Some(header_offset) = &self.header_offset {
34296 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34297 }
34298 prev
34299 }
34300 pub fn push_keys(mut self, value: u32) -> Self {
34301 push_header(self.as_vec_mut(), 1u16, 4 as u16);
34302 self.as_vec_mut().extend(value.to_ne_bytes());
34303 self
34304 }
34305 pub fn push_mode(mut self, value: u32) -> Self {
34306 push_header(self.as_vec_mut(), 2u16, 4 as u16);
34307 self.as_vec_mut().extend(value.to_ne_bytes());
34308 self
34309 }
34310 pub fn push_baseclass(mut self, value: u32) -> Self {
34311 push_header(self.as_vec_mut(), 3u16, 4 as u16);
34312 self.as_vec_mut().extend(value.to_ne_bytes());
34313 self
34314 }
34315 pub fn push_rshift(mut self, value: u32) -> Self {
34316 push_header(self.as_vec_mut(), 4u16, 4 as u16);
34317 self.as_vec_mut().extend(value.to_ne_bytes());
34318 self
34319 }
34320 pub fn push_addend(mut self, value: u32) -> Self {
34321 push_header(self.as_vec_mut(), 5u16, 4 as u16);
34322 self.as_vec_mut().extend(value.to_ne_bytes());
34323 self
34324 }
34325 pub fn push_mask(mut self, value: u32) -> Self {
34326 push_header(self.as_vec_mut(), 6u16, 4 as u16);
34327 self.as_vec_mut().extend(value.to_ne_bytes());
34328 self
34329 }
34330 pub fn push_xor(mut self, value: u32) -> Self {
34331 push_header(self.as_vec_mut(), 7u16, 4 as u16);
34332 self.as_vec_mut().extend(value.to_ne_bytes());
34333 self
34334 }
34335 pub fn push_divisor(mut self, value: u32) -> Self {
34336 push_header(self.as_vec_mut(), 8u16, 4 as u16);
34337 self.as_vec_mut().extend(value.to_ne_bytes());
34338 self
34339 }
34340 pub fn push_act(mut self, value: &[u8]) -> Self {
34341 push_header(self.as_vec_mut(), 9u16, value.len() as u16);
34342 self.as_vec_mut().extend(value);
34343 self
34344 }
34345 pub fn nested_police(mut self) -> PushPoliceAttrs<Self> {
34346 let header_offset = push_nested_header(self.as_vec_mut(), 10u16);
34347 PushPoliceAttrs {
34348 prev: Some(self),
34349 header_offset: Some(header_offset),
34350 }
34351 }
34352 pub fn push_ematches(mut self, value: &[u8]) -> Self {
34353 push_header(self.as_vec_mut(), 11u16, value.len() as u16);
34354 self.as_vec_mut().extend(value);
34355 self
34356 }
34357 pub fn push_perturb(mut self, value: u32) -> Self {
34358 push_header(self.as_vec_mut(), 12u16, 4 as u16);
34359 self.as_vec_mut().extend(value.to_ne_bytes());
34360 self
34361 }
34362}
34363impl<Prev: Pusher> Drop for PushFlowAttrs<Prev> {
34364 fn drop(&mut self) {
34365 if let Some(prev) = &mut self.prev {
34366 if let Some(header_offset) = &self.header_offset {
34367 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34368 }
34369 }
34370 }
34371}
34372pub struct PushFlowerAttrs<Prev: Pusher> {
34373 pub(crate) prev: Option<Prev>,
34374 pub(crate) header_offset: Option<usize>,
34375}
34376impl<Prev: Pusher> Pusher for PushFlowerAttrs<Prev> {
34377 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
34378 self.prev.as_mut().unwrap().as_vec_mut()
34379 }
34380 fn as_vec(&self) -> &Vec<u8> {
34381 self.prev.as_ref().unwrap().as_vec()
34382 }
34383}
34384impl<Prev: Pusher> PushFlowerAttrs<Prev> {
34385 pub fn new(prev: Prev) -> Self {
34386 Self {
34387 prev: Some(prev),
34388 header_offset: None,
34389 }
34390 }
34391 pub fn end_nested(mut self) -> Prev {
34392 let mut prev = self.prev.take().unwrap();
34393 if let Some(header_offset) = &self.header_offset {
34394 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34395 }
34396 prev
34397 }
34398 pub fn push_classid(mut self, value: u32) -> Self {
34399 push_header(self.as_vec_mut(), 1u16, 4 as u16);
34400 self.as_vec_mut().extend(value.to_ne_bytes());
34401 self
34402 }
34403 pub fn push_indev(mut self, value: &CStr) -> Self {
34404 push_header(
34405 self.as_vec_mut(),
34406 2u16,
34407 value.to_bytes_with_nul().len() as u16,
34408 );
34409 self.as_vec_mut().extend(value.to_bytes_with_nul());
34410 self
34411 }
34412 pub fn push_indev_bytes(mut self, value: &[u8]) -> Self {
34413 push_header(self.as_vec_mut(), 2u16, (value.len() + 1) as u16);
34414 self.as_vec_mut().extend(value);
34415 self.as_vec_mut().push(0);
34416 self
34417 }
34418 pub fn array_act(mut self) -> PushArrayActAttrs<Self> {
34419 let header_offset = push_nested_header(self.as_vec_mut(), 3u16);
34420 PushArrayActAttrs {
34421 prev: Some(self),
34422 header_offset: Some(header_offset),
34423 counter: 0,
34424 }
34425 }
34426 pub fn push_key_eth_dst(mut self, value: &[u8]) -> Self {
34427 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
34428 self.as_vec_mut().extend(value);
34429 self
34430 }
34431 pub fn push_key_eth_dst_mask(mut self, value: &[u8]) -> Self {
34432 push_header(self.as_vec_mut(), 5u16, value.len() as u16);
34433 self.as_vec_mut().extend(value);
34434 self
34435 }
34436 pub fn push_key_eth_src(mut self, value: &[u8]) -> Self {
34437 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
34438 self.as_vec_mut().extend(value);
34439 self
34440 }
34441 pub fn push_key_eth_src_mask(mut self, value: &[u8]) -> Self {
34442 push_header(self.as_vec_mut(), 7u16, value.len() as u16);
34443 self.as_vec_mut().extend(value);
34444 self
34445 }
34446 pub fn push_key_eth_type(mut self, value: u16) -> Self {
34447 push_header(self.as_vec_mut(), 8u16, 2 as u16);
34448 self.as_vec_mut().extend(value.to_be_bytes());
34449 self
34450 }
34451 pub fn push_key_ip_proto(mut self, value: u8) -> Self {
34452 push_header(self.as_vec_mut(), 9u16, 1 as u16);
34453 self.as_vec_mut().extend(value.to_ne_bytes());
34454 self
34455 }
34456 pub fn push_key_ipv4_src(mut self, value: std::net::Ipv4Addr) -> Self {
34457 push_header(self.as_vec_mut(), 10u16, 4 as u16);
34458 self.as_vec_mut().extend(&value.to_bits().to_be_bytes());
34459 self
34460 }
34461 pub fn push_key_ipv4_src_mask(mut self, value: std::net::Ipv4Addr) -> Self {
34462 push_header(self.as_vec_mut(), 11u16, 4 as u16);
34463 self.as_vec_mut().extend(&value.to_bits().to_be_bytes());
34464 self
34465 }
34466 pub fn push_key_ipv4_dst(mut self, value: std::net::Ipv4Addr) -> Self {
34467 push_header(self.as_vec_mut(), 12u16, 4 as u16);
34468 self.as_vec_mut().extend(&value.to_bits().to_be_bytes());
34469 self
34470 }
34471 pub fn push_key_ipv4_dst_mask(mut self, value: std::net::Ipv4Addr) -> Self {
34472 push_header(self.as_vec_mut(), 13u16, 4 as u16);
34473 self.as_vec_mut().extend(&value.to_bits().to_be_bytes());
34474 self
34475 }
34476 pub fn push_key_ipv6_src(mut self, value: &[u8]) -> Self {
34477 push_header(self.as_vec_mut(), 14u16, value.len() as u16);
34478 self.as_vec_mut().extend(value);
34479 self
34480 }
34481 pub fn push_key_ipv6_src_mask(mut self, value: &[u8]) -> Self {
34482 push_header(self.as_vec_mut(), 15u16, value.len() as u16);
34483 self.as_vec_mut().extend(value);
34484 self
34485 }
34486 pub fn push_key_ipv6_dst(mut self, value: &[u8]) -> Self {
34487 push_header(self.as_vec_mut(), 16u16, value.len() as u16);
34488 self.as_vec_mut().extend(value);
34489 self
34490 }
34491 pub fn push_key_ipv6_dst_mask(mut self, value: &[u8]) -> Self {
34492 push_header(self.as_vec_mut(), 17u16, value.len() as u16);
34493 self.as_vec_mut().extend(value);
34494 self
34495 }
34496 pub fn push_key_tcp_src(mut self, value: u16) -> Self {
34497 push_header(self.as_vec_mut(), 18u16, 2 as u16);
34498 self.as_vec_mut().extend(value.to_be_bytes());
34499 self
34500 }
34501 pub fn push_key_tcp_dst(mut self, value: u16) -> Self {
34502 push_header(self.as_vec_mut(), 19u16, 2 as u16);
34503 self.as_vec_mut().extend(value.to_be_bytes());
34504 self
34505 }
34506 pub fn push_key_udp_src(mut self, value: u16) -> Self {
34507 push_header(self.as_vec_mut(), 20u16, 2 as u16);
34508 self.as_vec_mut().extend(value.to_be_bytes());
34509 self
34510 }
34511 pub fn push_key_udp_dst(mut self, value: u16) -> Self {
34512 push_header(self.as_vec_mut(), 21u16, 2 as u16);
34513 self.as_vec_mut().extend(value.to_be_bytes());
34514 self
34515 }
34516 #[doc = "Associated type: [`ClsFlags`] (1 bit per enumeration)"]
34517 pub fn push_flags(mut self, value: u32) -> Self {
34518 push_header(self.as_vec_mut(), 22u16, 4 as u16);
34519 self.as_vec_mut().extend(value.to_ne_bytes());
34520 self
34521 }
34522 pub fn push_key_vlan_id(mut self, value: u16) -> Self {
34523 push_header(self.as_vec_mut(), 23u16, 2 as u16);
34524 self.as_vec_mut().extend(value.to_be_bytes());
34525 self
34526 }
34527 pub fn push_key_vlan_prio(mut self, value: u8) -> Self {
34528 push_header(self.as_vec_mut(), 24u16, 1 as u16);
34529 self.as_vec_mut().extend(value.to_ne_bytes());
34530 self
34531 }
34532 pub fn push_key_vlan_eth_type(mut self, value: u16) -> Self {
34533 push_header(self.as_vec_mut(), 25u16, 2 as u16);
34534 self.as_vec_mut().extend(value.to_be_bytes());
34535 self
34536 }
34537 pub fn push_key_enc_key_id(mut self, value: u32) -> Self {
34538 push_header(self.as_vec_mut(), 26u16, 4 as u16);
34539 self.as_vec_mut().extend(value.to_be_bytes());
34540 self
34541 }
34542 pub fn push_key_enc_ipv4_src(mut self, value: std::net::Ipv4Addr) -> Self {
34543 push_header(self.as_vec_mut(), 27u16, 4 as u16);
34544 self.as_vec_mut().extend(&value.to_bits().to_be_bytes());
34545 self
34546 }
34547 pub fn push_key_enc_ipv4_src_mask(mut self, value: std::net::Ipv4Addr) -> Self {
34548 push_header(self.as_vec_mut(), 28u16, 4 as u16);
34549 self.as_vec_mut().extend(&value.to_bits().to_be_bytes());
34550 self
34551 }
34552 pub fn push_key_enc_ipv4_dst(mut self, value: std::net::Ipv4Addr) -> Self {
34553 push_header(self.as_vec_mut(), 29u16, 4 as u16);
34554 self.as_vec_mut().extend(&value.to_bits().to_be_bytes());
34555 self
34556 }
34557 pub fn push_key_enc_ipv4_dst_mask(mut self, value: std::net::Ipv4Addr) -> Self {
34558 push_header(self.as_vec_mut(), 30u16, 4 as u16);
34559 self.as_vec_mut().extend(&value.to_bits().to_be_bytes());
34560 self
34561 }
34562 pub fn push_key_enc_ipv6_src(mut self, value: &[u8]) -> Self {
34563 push_header(self.as_vec_mut(), 31u16, value.len() as u16);
34564 self.as_vec_mut().extend(value);
34565 self
34566 }
34567 pub fn push_key_enc_ipv6_src_mask(mut self, value: &[u8]) -> Self {
34568 push_header(self.as_vec_mut(), 32u16, value.len() as u16);
34569 self.as_vec_mut().extend(value);
34570 self
34571 }
34572 pub fn push_key_enc_ipv6_dst(mut self, value: &[u8]) -> Self {
34573 push_header(self.as_vec_mut(), 33u16, value.len() as u16);
34574 self.as_vec_mut().extend(value);
34575 self
34576 }
34577 pub fn push_key_enc_ipv6_dst_mask(mut self, value: &[u8]) -> Self {
34578 push_header(self.as_vec_mut(), 34u16, value.len() as u16);
34579 self.as_vec_mut().extend(value);
34580 self
34581 }
34582 pub fn push_key_tcp_src_mask(mut self, value: u16) -> Self {
34583 push_header(self.as_vec_mut(), 35u16, 2 as u16);
34584 self.as_vec_mut().extend(value.to_be_bytes());
34585 self
34586 }
34587 pub fn push_key_tcp_dst_mask(mut self, value: u16) -> Self {
34588 push_header(self.as_vec_mut(), 36u16, 2 as u16);
34589 self.as_vec_mut().extend(value.to_be_bytes());
34590 self
34591 }
34592 pub fn push_key_udp_src_mask(mut self, value: u16) -> Self {
34593 push_header(self.as_vec_mut(), 37u16, 2 as u16);
34594 self.as_vec_mut().extend(value.to_be_bytes());
34595 self
34596 }
34597 pub fn push_key_udp_dst_mask(mut self, value: u16) -> Self {
34598 push_header(self.as_vec_mut(), 38u16, 2 as u16);
34599 self.as_vec_mut().extend(value.to_be_bytes());
34600 self
34601 }
34602 pub fn push_key_sctp_src_mask(mut self, value: u16) -> Self {
34603 push_header(self.as_vec_mut(), 39u16, 2 as u16);
34604 self.as_vec_mut().extend(value.to_be_bytes());
34605 self
34606 }
34607 pub fn push_key_sctp_dst_mask(mut self, value: u16) -> Self {
34608 push_header(self.as_vec_mut(), 40u16, 2 as u16);
34609 self.as_vec_mut().extend(value.to_be_bytes());
34610 self
34611 }
34612 pub fn push_key_sctp_src(mut self, value: u16) -> Self {
34613 push_header(self.as_vec_mut(), 41u16, 2 as u16);
34614 self.as_vec_mut().extend(value.to_be_bytes());
34615 self
34616 }
34617 pub fn push_key_sctp_dst(mut self, value: u16) -> Self {
34618 push_header(self.as_vec_mut(), 42u16, 2 as u16);
34619 self.as_vec_mut().extend(value.to_be_bytes());
34620 self
34621 }
34622 pub fn push_key_enc_udp_src_port(mut self, value: u16) -> Self {
34623 push_header(self.as_vec_mut(), 43u16, 2 as u16);
34624 self.as_vec_mut().extend(value.to_be_bytes());
34625 self
34626 }
34627 pub fn push_key_enc_udp_src_port_mask(mut self, value: u16) -> Self {
34628 push_header(self.as_vec_mut(), 44u16, 2 as u16);
34629 self.as_vec_mut().extend(value.to_be_bytes());
34630 self
34631 }
34632 pub fn push_key_enc_udp_dst_port(mut self, value: u16) -> Self {
34633 push_header(self.as_vec_mut(), 45u16, 2 as u16);
34634 self.as_vec_mut().extend(value.to_be_bytes());
34635 self
34636 }
34637 pub fn push_key_enc_udp_dst_port_mask(mut self, value: u16) -> Self {
34638 push_header(self.as_vec_mut(), 46u16, 2 as u16);
34639 self.as_vec_mut().extend(value.to_be_bytes());
34640 self
34641 }
34642 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
34643 pub fn push_key_flags(mut self, value: u32) -> Self {
34644 push_header(self.as_vec_mut(), 47u16, 4 as u16);
34645 self.as_vec_mut().extend(value.to_be_bytes());
34646 self
34647 }
34648 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
34649 pub fn push_key_flags_mask(mut self, value: u32) -> Self {
34650 push_header(self.as_vec_mut(), 48u16, 4 as u16);
34651 self.as_vec_mut().extend(value.to_be_bytes());
34652 self
34653 }
34654 pub fn push_key_icmpv4_code(mut self, value: u8) -> Self {
34655 push_header(self.as_vec_mut(), 49u16, 1 as u16);
34656 self.as_vec_mut().extend(value.to_ne_bytes());
34657 self
34658 }
34659 pub fn push_key_icmpv4_code_mask(mut self, value: u8) -> Self {
34660 push_header(self.as_vec_mut(), 50u16, 1 as u16);
34661 self.as_vec_mut().extend(value.to_ne_bytes());
34662 self
34663 }
34664 pub fn push_key_icmpv4_type(mut self, value: u8) -> Self {
34665 push_header(self.as_vec_mut(), 51u16, 1 as u16);
34666 self.as_vec_mut().extend(value.to_ne_bytes());
34667 self
34668 }
34669 pub fn push_key_icmpv4_type_mask(mut self, value: u8) -> Self {
34670 push_header(self.as_vec_mut(), 52u16, 1 as u16);
34671 self.as_vec_mut().extend(value.to_ne_bytes());
34672 self
34673 }
34674 pub fn push_key_icmpv6_code(mut self, value: u8) -> Self {
34675 push_header(self.as_vec_mut(), 53u16, 1 as u16);
34676 self.as_vec_mut().extend(value.to_ne_bytes());
34677 self
34678 }
34679 pub fn push_key_icmpv6_code_mask(mut self, value: u8) -> Self {
34680 push_header(self.as_vec_mut(), 54u16, 1 as u16);
34681 self.as_vec_mut().extend(value.to_ne_bytes());
34682 self
34683 }
34684 pub fn push_key_icmpv6_type(mut self, value: u8) -> Self {
34685 push_header(self.as_vec_mut(), 55u16, 1 as u16);
34686 self.as_vec_mut().extend(value.to_ne_bytes());
34687 self
34688 }
34689 pub fn push_key_icmpv6_type_mask(mut self, value: u8) -> Self {
34690 push_header(self.as_vec_mut(), 56u16, 1 as u16);
34691 self.as_vec_mut().extend(value.to_ne_bytes());
34692 self
34693 }
34694 pub fn push_key_arp_sip(mut self, value: u32) -> Self {
34695 push_header(self.as_vec_mut(), 57u16, 4 as u16);
34696 self.as_vec_mut().extend(value.to_be_bytes());
34697 self
34698 }
34699 pub fn push_key_arp_sip_mask(mut self, value: u32) -> Self {
34700 push_header(self.as_vec_mut(), 58u16, 4 as u16);
34701 self.as_vec_mut().extend(value.to_be_bytes());
34702 self
34703 }
34704 pub fn push_key_arp_tip(mut self, value: u32) -> Self {
34705 push_header(self.as_vec_mut(), 59u16, 4 as u16);
34706 self.as_vec_mut().extend(value.to_be_bytes());
34707 self
34708 }
34709 pub fn push_key_arp_tip_mask(mut self, value: u32) -> Self {
34710 push_header(self.as_vec_mut(), 60u16, 4 as u16);
34711 self.as_vec_mut().extend(value.to_be_bytes());
34712 self
34713 }
34714 pub fn push_key_arp_op(mut self, value: u8) -> Self {
34715 push_header(self.as_vec_mut(), 61u16, 1 as u16);
34716 self.as_vec_mut().extend(value.to_ne_bytes());
34717 self
34718 }
34719 pub fn push_key_arp_op_mask(mut self, value: u8) -> Self {
34720 push_header(self.as_vec_mut(), 62u16, 1 as u16);
34721 self.as_vec_mut().extend(value.to_ne_bytes());
34722 self
34723 }
34724 pub fn push_key_arp_sha(mut self, value: &[u8]) -> Self {
34725 push_header(self.as_vec_mut(), 63u16, value.len() as u16);
34726 self.as_vec_mut().extend(value);
34727 self
34728 }
34729 pub fn push_key_arp_sha_mask(mut self, value: &[u8]) -> Self {
34730 push_header(self.as_vec_mut(), 64u16, value.len() as u16);
34731 self.as_vec_mut().extend(value);
34732 self
34733 }
34734 pub fn push_key_arp_tha(mut self, value: &[u8]) -> Self {
34735 push_header(self.as_vec_mut(), 65u16, value.len() as u16);
34736 self.as_vec_mut().extend(value);
34737 self
34738 }
34739 pub fn push_key_arp_tha_mask(mut self, value: &[u8]) -> Self {
34740 push_header(self.as_vec_mut(), 66u16, value.len() as u16);
34741 self.as_vec_mut().extend(value);
34742 self
34743 }
34744 pub fn push_key_mpls_ttl(mut self, value: u8) -> Self {
34745 push_header(self.as_vec_mut(), 67u16, 1 as u16);
34746 self.as_vec_mut().extend(value.to_ne_bytes());
34747 self
34748 }
34749 pub fn push_key_mpls_bos(mut self, value: u8) -> Self {
34750 push_header(self.as_vec_mut(), 68u16, 1 as u16);
34751 self.as_vec_mut().extend(value.to_ne_bytes());
34752 self
34753 }
34754 pub fn push_key_mpls_tc(mut self, value: u8) -> Self {
34755 push_header(self.as_vec_mut(), 69u16, 1 as u16);
34756 self.as_vec_mut().extend(value.to_ne_bytes());
34757 self
34758 }
34759 pub fn push_key_mpls_label(mut self, value: u32) -> Self {
34760 push_header(self.as_vec_mut(), 70u16, 4 as u16);
34761 self.as_vec_mut().extend(value.to_be_bytes());
34762 self
34763 }
34764 pub fn push_key_tcp_flags(mut self, value: u16) -> Self {
34765 push_header(self.as_vec_mut(), 71u16, 2 as u16);
34766 self.as_vec_mut().extend(value.to_be_bytes());
34767 self
34768 }
34769 pub fn push_key_tcp_flags_mask(mut self, value: u16) -> Self {
34770 push_header(self.as_vec_mut(), 72u16, 2 as u16);
34771 self.as_vec_mut().extend(value.to_be_bytes());
34772 self
34773 }
34774 pub fn push_key_ip_tos(mut self, value: u8) -> Self {
34775 push_header(self.as_vec_mut(), 73u16, 1 as u16);
34776 self.as_vec_mut().extend(value.to_ne_bytes());
34777 self
34778 }
34779 pub fn push_key_ip_tos_mask(mut self, value: u8) -> Self {
34780 push_header(self.as_vec_mut(), 74u16, 1 as u16);
34781 self.as_vec_mut().extend(value.to_ne_bytes());
34782 self
34783 }
34784 pub fn push_key_ip_ttl(mut self, value: u8) -> Self {
34785 push_header(self.as_vec_mut(), 75u16, 1 as u16);
34786 self.as_vec_mut().extend(value.to_ne_bytes());
34787 self
34788 }
34789 pub fn push_key_ip_ttl_mask(mut self, value: u8) -> Self {
34790 push_header(self.as_vec_mut(), 76u16, 1 as u16);
34791 self.as_vec_mut().extend(value.to_ne_bytes());
34792 self
34793 }
34794 pub fn push_key_cvlan_id(mut self, value: u16) -> Self {
34795 push_header(self.as_vec_mut(), 77u16, 2 as u16);
34796 self.as_vec_mut().extend(value.to_be_bytes());
34797 self
34798 }
34799 pub fn push_key_cvlan_prio(mut self, value: u8) -> Self {
34800 push_header(self.as_vec_mut(), 78u16, 1 as u16);
34801 self.as_vec_mut().extend(value.to_ne_bytes());
34802 self
34803 }
34804 pub fn push_key_cvlan_eth_type(mut self, value: u16) -> Self {
34805 push_header(self.as_vec_mut(), 79u16, 2 as u16);
34806 self.as_vec_mut().extend(value.to_be_bytes());
34807 self
34808 }
34809 pub fn push_key_enc_ip_tos(mut self, value: u8) -> Self {
34810 push_header(self.as_vec_mut(), 80u16, 1 as u16);
34811 self.as_vec_mut().extend(value.to_ne_bytes());
34812 self
34813 }
34814 pub fn push_key_enc_ip_tos_mask(mut self, value: u8) -> Self {
34815 push_header(self.as_vec_mut(), 81u16, 1 as u16);
34816 self.as_vec_mut().extend(value.to_ne_bytes());
34817 self
34818 }
34819 pub fn push_key_enc_ip_ttl(mut self, value: u8) -> Self {
34820 push_header(self.as_vec_mut(), 82u16, 1 as u16);
34821 self.as_vec_mut().extend(value.to_ne_bytes());
34822 self
34823 }
34824 pub fn push_key_enc_ip_ttl_mask(mut self, value: u8) -> Self {
34825 push_header(self.as_vec_mut(), 83u16, 1 as u16);
34826 self.as_vec_mut().extend(value.to_ne_bytes());
34827 self
34828 }
34829 pub fn nested_key_enc_opts(mut self) -> PushFlowerKeyEncOptsAttrs<Self> {
34830 let header_offset = push_nested_header(self.as_vec_mut(), 84u16);
34831 PushFlowerKeyEncOptsAttrs {
34832 prev: Some(self),
34833 header_offset: Some(header_offset),
34834 }
34835 }
34836 pub fn nested_key_enc_opts_mask(mut self) -> PushFlowerKeyEncOptsAttrs<Self> {
34837 let header_offset = push_nested_header(self.as_vec_mut(), 85u16);
34838 PushFlowerKeyEncOptsAttrs {
34839 prev: Some(self),
34840 header_offset: Some(header_offset),
34841 }
34842 }
34843 pub fn push_in_hw_count(mut self, value: u32) -> Self {
34844 push_header(self.as_vec_mut(), 86u16, 4 as u16);
34845 self.as_vec_mut().extend(value.to_ne_bytes());
34846 self
34847 }
34848 pub fn push_key_port_src_min(mut self, value: u16) -> Self {
34849 push_header(self.as_vec_mut(), 87u16, 2 as u16);
34850 self.as_vec_mut().extend(value.to_be_bytes());
34851 self
34852 }
34853 pub fn push_key_port_src_max(mut self, value: u16) -> Self {
34854 push_header(self.as_vec_mut(), 88u16, 2 as u16);
34855 self.as_vec_mut().extend(value.to_be_bytes());
34856 self
34857 }
34858 pub fn push_key_port_dst_min(mut self, value: u16) -> Self {
34859 push_header(self.as_vec_mut(), 89u16, 2 as u16);
34860 self.as_vec_mut().extend(value.to_be_bytes());
34861 self
34862 }
34863 pub fn push_key_port_dst_max(mut self, value: u16) -> Self {
34864 push_header(self.as_vec_mut(), 90u16, 2 as u16);
34865 self.as_vec_mut().extend(value.to_be_bytes());
34866 self
34867 }
34868 pub fn push_key_ct_state(mut self, value: u16) -> Self {
34869 push_header(self.as_vec_mut(), 91u16, 2 as u16);
34870 self.as_vec_mut().extend(value.to_ne_bytes());
34871 self
34872 }
34873 pub fn push_key_ct_state_mask(mut self, value: u16) -> Self {
34874 push_header(self.as_vec_mut(), 92u16, 2 as u16);
34875 self.as_vec_mut().extend(value.to_ne_bytes());
34876 self
34877 }
34878 pub fn push_key_ct_zone(mut self, value: u16) -> Self {
34879 push_header(self.as_vec_mut(), 93u16, 2 as u16);
34880 self.as_vec_mut().extend(value.to_ne_bytes());
34881 self
34882 }
34883 pub fn push_key_ct_zone_mask(mut self, value: u16) -> Self {
34884 push_header(self.as_vec_mut(), 94u16, 2 as u16);
34885 self.as_vec_mut().extend(value.to_ne_bytes());
34886 self
34887 }
34888 pub fn push_key_ct_mark(mut self, value: u32) -> Self {
34889 push_header(self.as_vec_mut(), 95u16, 4 as u16);
34890 self.as_vec_mut().extend(value.to_ne_bytes());
34891 self
34892 }
34893 pub fn push_key_ct_mark_mask(mut self, value: u32) -> Self {
34894 push_header(self.as_vec_mut(), 96u16, 4 as u16);
34895 self.as_vec_mut().extend(value.to_ne_bytes());
34896 self
34897 }
34898 pub fn push_key_ct_labels(mut self, value: &[u8]) -> Self {
34899 push_header(self.as_vec_mut(), 97u16, value.len() as u16);
34900 self.as_vec_mut().extend(value);
34901 self
34902 }
34903 pub fn push_key_ct_labels_mask(mut self, value: &[u8]) -> Self {
34904 push_header(self.as_vec_mut(), 98u16, value.len() as u16);
34905 self.as_vec_mut().extend(value);
34906 self
34907 }
34908 pub fn nested_key_mpls_opts(mut self) -> PushFlowerKeyMplsOptAttrs<Self> {
34909 let header_offset = push_nested_header(self.as_vec_mut(), 99u16);
34910 PushFlowerKeyMplsOptAttrs {
34911 prev: Some(self),
34912 header_offset: Some(header_offset),
34913 }
34914 }
34915 pub fn push_key_hash(mut self, value: u32) -> Self {
34916 push_header(self.as_vec_mut(), 100u16, 4 as u16);
34917 self.as_vec_mut().extend(value.to_ne_bytes());
34918 self
34919 }
34920 pub fn push_key_hash_mask(mut self, value: u32) -> Self {
34921 push_header(self.as_vec_mut(), 101u16, 4 as u16);
34922 self.as_vec_mut().extend(value.to_ne_bytes());
34923 self
34924 }
34925 pub fn push_key_num_of_vlans(mut self, value: u8) -> Self {
34926 push_header(self.as_vec_mut(), 102u16, 1 as u16);
34927 self.as_vec_mut().extend(value.to_ne_bytes());
34928 self
34929 }
34930 pub fn push_key_pppoe_sid(mut self, value: u16) -> Self {
34931 push_header(self.as_vec_mut(), 103u16, 2 as u16);
34932 self.as_vec_mut().extend(value.to_be_bytes());
34933 self
34934 }
34935 pub fn push_key_ppp_proto(mut self, value: u16) -> Self {
34936 push_header(self.as_vec_mut(), 104u16, 2 as u16);
34937 self.as_vec_mut().extend(value.to_be_bytes());
34938 self
34939 }
34940 pub fn push_key_l2tpv3_sid(mut self, value: u32) -> Self {
34941 push_header(self.as_vec_mut(), 105u16, 4 as u16);
34942 self.as_vec_mut().extend(value.to_be_bytes());
34943 self
34944 }
34945 pub fn push_l2_miss(mut self, value: u8) -> Self {
34946 push_header(self.as_vec_mut(), 106u16, 1 as u16);
34947 self.as_vec_mut().extend(value.to_ne_bytes());
34948 self
34949 }
34950 pub fn nested_key_cfm(mut self) -> PushFlowerKeyCfmAttrs<Self> {
34951 let header_offset = push_nested_header(self.as_vec_mut(), 107u16);
34952 PushFlowerKeyCfmAttrs {
34953 prev: Some(self),
34954 header_offset: Some(header_offset),
34955 }
34956 }
34957 pub fn push_key_spi(mut self, value: u32) -> Self {
34958 push_header(self.as_vec_mut(), 108u16, 4 as u16);
34959 self.as_vec_mut().extend(value.to_be_bytes());
34960 self
34961 }
34962 pub fn push_key_spi_mask(mut self, value: u32) -> Self {
34963 push_header(self.as_vec_mut(), 109u16, 4 as u16);
34964 self.as_vec_mut().extend(value.to_be_bytes());
34965 self
34966 }
34967 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
34968 pub fn push_key_enc_flags(mut self, value: u32) -> Self {
34969 push_header(self.as_vec_mut(), 110u16, 4 as u16);
34970 self.as_vec_mut().extend(value.to_be_bytes());
34971 self
34972 }
34973 #[doc = "Associated type: [`FlowerKeyCtrlFlags`] (1 bit per enumeration)"]
34974 pub fn push_key_enc_flags_mask(mut self, value: u32) -> Self {
34975 push_header(self.as_vec_mut(), 111u16, 4 as u16);
34976 self.as_vec_mut().extend(value.to_be_bytes());
34977 self
34978 }
34979}
34980impl<Prev: Pusher> Drop for PushFlowerAttrs<Prev> {
34981 fn drop(&mut self) {
34982 if let Some(prev) = &mut self.prev {
34983 if let Some(header_offset) = &self.header_offset {
34984 finalize_nested_header(prev.as_vec_mut(), *header_offset);
34985 }
34986 }
34987 }
34988}
34989pub struct PushFlowerKeyEncOptsAttrs<Prev: Pusher> {
34990 pub(crate) prev: Option<Prev>,
34991 pub(crate) header_offset: Option<usize>,
34992}
34993impl<Prev: Pusher> Pusher for PushFlowerKeyEncOptsAttrs<Prev> {
34994 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
34995 self.prev.as_mut().unwrap().as_vec_mut()
34996 }
34997 fn as_vec(&self) -> &Vec<u8> {
34998 self.prev.as_ref().unwrap().as_vec()
34999 }
35000}
35001impl<Prev: Pusher> PushFlowerKeyEncOptsAttrs<Prev> {
35002 pub fn new(prev: Prev) -> Self {
35003 Self {
35004 prev: Some(prev),
35005 header_offset: None,
35006 }
35007 }
35008 pub fn end_nested(mut self) -> Prev {
35009 let mut prev = self.prev.take().unwrap();
35010 if let Some(header_offset) = &self.header_offset {
35011 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35012 }
35013 prev
35014 }
35015 pub fn nested_geneve(mut self) -> PushFlowerKeyEncOptGeneveAttrs<Self> {
35016 let header_offset = push_nested_header(self.as_vec_mut(), 1u16);
35017 PushFlowerKeyEncOptGeneveAttrs {
35018 prev: Some(self),
35019 header_offset: Some(header_offset),
35020 }
35021 }
35022 pub fn nested_vxlan(mut self) -> PushFlowerKeyEncOptVxlanAttrs<Self> {
35023 let header_offset = push_nested_header(self.as_vec_mut(), 2u16);
35024 PushFlowerKeyEncOptVxlanAttrs {
35025 prev: Some(self),
35026 header_offset: Some(header_offset),
35027 }
35028 }
35029 pub fn nested_erspan(mut self) -> PushFlowerKeyEncOptErspanAttrs<Self> {
35030 let header_offset = push_nested_header(self.as_vec_mut(), 3u16);
35031 PushFlowerKeyEncOptErspanAttrs {
35032 prev: Some(self),
35033 header_offset: Some(header_offset),
35034 }
35035 }
35036 pub fn nested_gtp(mut self) -> PushFlowerKeyEncOptGtpAttrs<Self> {
35037 let header_offset = push_nested_header(self.as_vec_mut(), 4u16);
35038 PushFlowerKeyEncOptGtpAttrs {
35039 prev: Some(self),
35040 header_offset: Some(header_offset),
35041 }
35042 }
35043}
35044impl<Prev: Pusher> Drop for PushFlowerKeyEncOptsAttrs<Prev> {
35045 fn drop(&mut self) {
35046 if let Some(prev) = &mut self.prev {
35047 if let Some(header_offset) = &self.header_offset {
35048 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35049 }
35050 }
35051 }
35052}
35053pub struct PushFlowerKeyEncOptGeneveAttrs<Prev: Pusher> {
35054 pub(crate) prev: Option<Prev>,
35055 pub(crate) header_offset: Option<usize>,
35056}
35057impl<Prev: Pusher> Pusher for PushFlowerKeyEncOptGeneveAttrs<Prev> {
35058 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35059 self.prev.as_mut().unwrap().as_vec_mut()
35060 }
35061 fn as_vec(&self) -> &Vec<u8> {
35062 self.prev.as_ref().unwrap().as_vec()
35063 }
35064}
35065impl<Prev: Pusher> PushFlowerKeyEncOptGeneveAttrs<Prev> {
35066 pub fn new(prev: Prev) -> Self {
35067 Self {
35068 prev: Some(prev),
35069 header_offset: None,
35070 }
35071 }
35072 pub fn end_nested(mut self) -> Prev {
35073 let mut prev = self.prev.take().unwrap();
35074 if let Some(header_offset) = &self.header_offset {
35075 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35076 }
35077 prev
35078 }
35079 pub fn push_class(mut self, value: u16) -> Self {
35080 push_header(self.as_vec_mut(), 1u16, 2 as u16);
35081 self.as_vec_mut().extend(value.to_ne_bytes());
35082 self
35083 }
35084 pub fn push_type(mut self, value: u8) -> Self {
35085 push_header(self.as_vec_mut(), 2u16, 1 as u16);
35086 self.as_vec_mut().extend(value.to_ne_bytes());
35087 self
35088 }
35089 pub fn push_data(mut self, value: &[u8]) -> Self {
35090 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
35091 self.as_vec_mut().extend(value);
35092 self
35093 }
35094}
35095impl<Prev: Pusher> Drop for PushFlowerKeyEncOptGeneveAttrs<Prev> {
35096 fn drop(&mut self) {
35097 if let Some(prev) = &mut self.prev {
35098 if let Some(header_offset) = &self.header_offset {
35099 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35100 }
35101 }
35102 }
35103}
35104pub struct PushFlowerKeyEncOptVxlanAttrs<Prev: Pusher> {
35105 pub(crate) prev: Option<Prev>,
35106 pub(crate) header_offset: Option<usize>,
35107}
35108impl<Prev: Pusher> Pusher for PushFlowerKeyEncOptVxlanAttrs<Prev> {
35109 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35110 self.prev.as_mut().unwrap().as_vec_mut()
35111 }
35112 fn as_vec(&self) -> &Vec<u8> {
35113 self.prev.as_ref().unwrap().as_vec()
35114 }
35115}
35116impl<Prev: Pusher> PushFlowerKeyEncOptVxlanAttrs<Prev> {
35117 pub fn new(prev: Prev) -> Self {
35118 Self {
35119 prev: Some(prev),
35120 header_offset: None,
35121 }
35122 }
35123 pub fn end_nested(mut self) -> Prev {
35124 let mut prev = self.prev.take().unwrap();
35125 if let Some(header_offset) = &self.header_offset {
35126 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35127 }
35128 prev
35129 }
35130 pub fn push_gbp(mut self, value: u32) -> Self {
35131 push_header(self.as_vec_mut(), 1u16, 4 as u16);
35132 self.as_vec_mut().extend(value.to_ne_bytes());
35133 self
35134 }
35135}
35136impl<Prev: Pusher> Drop for PushFlowerKeyEncOptVxlanAttrs<Prev> {
35137 fn drop(&mut self) {
35138 if let Some(prev) = &mut self.prev {
35139 if let Some(header_offset) = &self.header_offset {
35140 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35141 }
35142 }
35143 }
35144}
35145pub struct PushFlowerKeyEncOptErspanAttrs<Prev: Pusher> {
35146 pub(crate) prev: Option<Prev>,
35147 pub(crate) header_offset: Option<usize>,
35148}
35149impl<Prev: Pusher> Pusher for PushFlowerKeyEncOptErspanAttrs<Prev> {
35150 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35151 self.prev.as_mut().unwrap().as_vec_mut()
35152 }
35153 fn as_vec(&self) -> &Vec<u8> {
35154 self.prev.as_ref().unwrap().as_vec()
35155 }
35156}
35157impl<Prev: Pusher> PushFlowerKeyEncOptErspanAttrs<Prev> {
35158 pub fn new(prev: Prev) -> Self {
35159 Self {
35160 prev: Some(prev),
35161 header_offset: None,
35162 }
35163 }
35164 pub fn end_nested(mut self) -> Prev {
35165 let mut prev = self.prev.take().unwrap();
35166 if let Some(header_offset) = &self.header_offset {
35167 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35168 }
35169 prev
35170 }
35171 pub fn push_ver(mut self, value: u8) -> Self {
35172 push_header(self.as_vec_mut(), 1u16, 1 as u16);
35173 self.as_vec_mut().extend(value.to_ne_bytes());
35174 self
35175 }
35176 pub fn push_index(mut self, value: u32) -> Self {
35177 push_header(self.as_vec_mut(), 2u16, 4 as u16);
35178 self.as_vec_mut().extend(value.to_ne_bytes());
35179 self
35180 }
35181 pub fn push_dir(mut self, value: u8) -> Self {
35182 push_header(self.as_vec_mut(), 3u16, 1 as u16);
35183 self.as_vec_mut().extend(value.to_ne_bytes());
35184 self
35185 }
35186 pub fn push_hwid(mut self, value: u8) -> Self {
35187 push_header(self.as_vec_mut(), 4u16, 1 as u16);
35188 self.as_vec_mut().extend(value.to_ne_bytes());
35189 self
35190 }
35191}
35192impl<Prev: Pusher> Drop for PushFlowerKeyEncOptErspanAttrs<Prev> {
35193 fn drop(&mut self) {
35194 if let Some(prev) = &mut self.prev {
35195 if let Some(header_offset) = &self.header_offset {
35196 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35197 }
35198 }
35199 }
35200}
35201pub struct PushFlowerKeyEncOptGtpAttrs<Prev: Pusher> {
35202 pub(crate) prev: Option<Prev>,
35203 pub(crate) header_offset: Option<usize>,
35204}
35205impl<Prev: Pusher> Pusher for PushFlowerKeyEncOptGtpAttrs<Prev> {
35206 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35207 self.prev.as_mut().unwrap().as_vec_mut()
35208 }
35209 fn as_vec(&self) -> &Vec<u8> {
35210 self.prev.as_ref().unwrap().as_vec()
35211 }
35212}
35213impl<Prev: Pusher> PushFlowerKeyEncOptGtpAttrs<Prev> {
35214 pub fn new(prev: Prev) -> Self {
35215 Self {
35216 prev: Some(prev),
35217 header_offset: None,
35218 }
35219 }
35220 pub fn end_nested(mut self) -> Prev {
35221 let mut prev = self.prev.take().unwrap();
35222 if let Some(header_offset) = &self.header_offset {
35223 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35224 }
35225 prev
35226 }
35227 pub fn push_pdu_type(mut self, value: u8) -> Self {
35228 push_header(self.as_vec_mut(), 1u16, 1 as u16);
35229 self.as_vec_mut().extend(value.to_ne_bytes());
35230 self
35231 }
35232 pub fn push_qfi(mut self, value: u8) -> Self {
35233 push_header(self.as_vec_mut(), 2u16, 1 as u16);
35234 self.as_vec_mut().extend(value.to_ne_bytes());
35235 self
35236 }
35237}
35238impl<Prev: Pusher> Drop for PushFlowerKeyEncOptGtpAttrs<Prev> {
35239 fn drop(&mut self) {
35240 if let Some(prev) = &mut self.prev {
35241 if let Some(header_offset) = &self.header_offset {
35242 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35243 }
35244 }
35245 }
35246}
35247pub struct PushFlowerKeyMplsOptAttrs<Prev: Pusher> {
35248 pub(crate) prev: Option<Prev>,
35249 pub(crate) header_offset: Option<usize>,
35250}
35251impl<Prev: Pusher> Pusher for PushFlowerKeyMplsOptAttrs<Prev> {
35252 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35253 self.prev.as_mut().unwrap().as_vec_mut()
35254 }
35255 fn as_vec(&self) -> &Vec<u8> {
35256 self.prev.as_ref().unwrap().as_vec()
35257 }
35258}
35259impl<Prev: Pusher> PushFlowerKeyMplsOptAttrs<Prev> {
35260 pub fn new(prev: Prev) -> Self {
35261 Self {
35262 prev: Some(prev),
35263 header_offset: None,
35264 }
35265 }
35266 pub fn end_nested(mut self) -> Prev {
35267 let mut prev = self.prev.take().unwrap();
35268 if let Some(header_offset) = &self.header_offset {
35269 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35270 }
35271 prev
35272 }
35273 pub fn push_lse_depth(mut self, value: u8) -> Self {
35274 push_header(self.as_vec_mut(), 1u16, 1 as u16);
35275 self.as_vec_mut().extend(value.to_ne_bytes());
35276 self
35277 }
35278 pub fn push_lse_ttl(mut self, value: u8) -> Self {
35279 push_header(self.as_vec_mut(), 2u16, 1 as u16);
35280 self.as_vec_mut().extend(value.to_ne_bytes());
35281 self
35282 }
35283 pub fn push_lse_bos(mut self, value: u8) -> Self {
35284 push_header(self.as_vec_mut(), 3u16, 1 as u16);
35285 self.as_vec_mut().extend(value.to_ne_bytes());
35286 self
35287 }
35288 pub fn push_lse_tc(mut self, value: u8) -> Self {
35289 push_header(self.as_vec_mut(), 4u16, 1 as u16);
35290 self.as_vec_mut().extend(value.to_ne_bytes());
35291 self
35292 }
35293 pub fn push_lse_label(mut self, value: u32) -> Self {
35294 push_header(self.as_vec_mut(), 5u16, 4 as u16);
35295 self.as_vec_mut().extend(value.to_ne_bytes());
35296 self
35297 }
35298}
35299impl<Prev: Pusher> Drop for PushFlowerKeyMplsOptAttrs<Prev> {
35300 fn drop(&mut self) {
35301 if let Some(prev) = &mut self.prev {
35302 if let Some(header_offset) = &self.header_offset {
35303 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35304 }
35305 }
35306 }
35307}
35308pub struct PushFlowerKeyCfmAttrs<Prev: Pusher> {
35309 pub(crate) prev: Option<Prev>,
35310 pub(crate) header_offset: Option<usize>,
35311}
35312impl<Prev: Pusher> Pusher for PushFlowerKeyCfmAttrs<Prev> {
35313 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35314 self.prev.as_mut().unwrap().as_vec_mut()
35315 }
35316 fn as_vec(&self) -> &Vec<u8> {
35317 self.prev.as_ref().unwrap().as_vec()
35318 }
35319}
35320impl<Prev: Pusher> PushFlowerKeyCfmAttrs<Prev> {
35321 pub fn new(prev: Prev) -> Self {
35322 Self {
35323 prev: Some(prev),
35324 header_offset: None,
35325 }
35326 }
35327 pub fn end_nested(mut self) -> Prev {
35328 let mut prev = self.prev.take().unwrap();
35329 if let Some(header_offset) = &self.header_offset {
35330 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35331 }
35332 prev
35333 }
35334 pub fn push_md_level(mut self, value: u8) -> Self {
35335 push_header(self.as_vec_mut(), 1u16, 1 as u16);
35336 self.as_vec_mut().extend(value.to_ne_bytes());
35337 self
35338 }
35339 pub fn push_opcode(mut self, value: u8) -> Self {
35340 push_header(self.as_vec_mut(), 2u16, 1 as u16);
35341 self.as_vec_mut().extend(value.to_ne_bytes());
35342 self
35343 }
35344}
35345impl<Prev: Pusher> Drop for PushFlowerKeyCfmAttrs<Prev> {
35346 fn drop(&mut self) {
35347 if let Some(prev) = &mut self.prev {
35348 if let Some(header_offset) = &self.header_offset {
35349 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35350 }
35351 }
35352 }
35353}
35354pub struct PushFwAttrs<Prev: Pusher> {
35355 pub(crate) prev: Option<Prev>,
35356 pub(crate) header_offset: Option<usize>,
35357}
35358impl<Prev: Pusher> Pusher for PushFwAttrs<Prev> {
35359 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35360 self.prev.as_mut().unwrap().as_vec_mut()
35361 }
35362 fn as_vec(&self) -> &Vec<u8> {
35363 self.prev.as_ref().unwrap().as_vec()
35364 }
35365}
35366impl<Prev: Pusher> PushFwAttrs<Prev> {
35367 pub fn new(prev: Prev) -> Self {
35368 Self {
35369 prev: Some(prev),
35370 header_offset: None,
35371 }
35372 }
35373 pub fn end_nested(mut self) -> Prev {
35374 let mut prev = self.prev.take().unwrap();
35375 if let Some(header_offset) = &self.header_offset {
35376 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35377 }
35378 prev
35379 }
35380 pub fn push_classid(mut self, value: u32) -> Self {
35381 push_header(self.as_vec_mut(), 1u16, 4 as u16);
35382 self.as_vec_mut().extend(value.to_ne_bytes());
35383 self
35384 }
35385 pub fn nested_police(mut self) -> PushPoliceAttrs<Self> {
35386 let header_offset = push_nested_header(self.as_vec_mut(), 2u16);
35387 PushPoliceAttrs {
35388 prev: Some(self),
35389 header_offset: Some(header_offset),
35390 }
35391 }
35392 pub fn push_indev(mut self, value: &CStr) -> Self {
35393 push_header(
35394 self.as_vec_mut(),
35395 3u16,
35396 value.to_bytes_with_nul().len() as u16,
35397 );
35398 self.as_vec_mut().extend(value.to_bytes_with_nul());
35399 self
35400 }
35401 pub fn push_indev_bytes(mut self, value: &[u8]) -> Self {
35402 push_header(self.as_vec_mut(), 3u16, (value.len() + 1) as u16);
35403 self.as_vec_mut().extend(value);
35404 self.as_vec_mut().push(0);
35405 self
35406 }
35407 pub fn array_act(mut self) -> PushArrayActAttrs<Self> {
35408 let header_offset = push_nested_header(self.as_vec_mut(), 4u16);
35409 PushArrayActAttrs {
35410 prev: Some(self),
35411 header_offset: Some(header_offset),
35412 counter: 0,
35413 }
35414 }
35415 pub fn push_mask(mut self, value: u32) -> Self {
35416 push_header(self.as_vec_mut(), 5u16, 4 as u16);
35417 self.as_vec_mut().extend(value.to_ne_bytes());
35418 self
35419 }
35420}
35421impl<Prev: Pusher> Drop for PushFwAttrs<Prev> {
35422 fn drop(&mut self) {
35423 if let Some(prev) = &mut self.prev {
35424 if let Some(header_offset) = &self.header_offset {
35425 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35426 }
35427 }
35428 }
35429}
35430pub struct PushGredAttrs<Prev: Pusher> {
35431 pub(crate) prev: Option<Prev>,
35432 pub(crate) header_offset: Option<usize>,
35433}
35434impl<Prev: Pusher> Pusher for PushGredAttrs<Prev> {
35435 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35436 self.prev.as_mut().unwrap().as_vec_mut()
35437 }
35438 fn as_vec(&self) -> &Vec<u8> {
35439 self.prev.as_ref().unwrap().as_vec()
35440 }
35441}
35442impl<Prev: Pusher> PushGredAttrs<Prev> {
35443 pub fn new(prev: Prev) -> Self {
35444 Self {
35445 prev: Some(prev),
35446 header_offset: None,
35447 }
35448 }
35449 pub fn end_nested(mut self) -> Prev {
35450 let mut prev = self.prev.take().unwrap();
35451 if let Some(header_offset) = &self.header_offset {
35452 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35453 }
35454 prev
35455 }
35456 pub fn push_parms(mut self, value: &[u8]) -> Self {
35457 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
35458 self.as_vec_mut().extend(value);
35459 self
35460 }
35461 pub fn push_stab(mut self, value: &[u8]) -> Self {
35462 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
35463 self.as_vec_mut().extend(value);
35464 self
35465 }
35466 pub fn push_dps(mut self, value: TcGredSopt) -> Self {
35467 push_header(self.as_vec_mut(), 3u16, value.as_slice().len() as u16);
35468 self.as_vec_mut().extend(value.as_slice());
35469 self
35470 }
35471 pub fn push_max_p(mut self, value: &[u8]) -> Self {
35472 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
35473 self.as_vec_mut().extend(value);
35474 self
35475 }
35476 pub fn push_limit(mut self, value: u32) -> Self {
35477 push_header(self.as_vec_mut(), 5u16, 4 as u16);
35478 self.as_vec_mut().extend(value.to_ne_bytes());
35479 self
35480 }
35481 pub fn nested_vq_list(mut self) -> PushTcaGredVqListAttrs<Self> {
35482 let header_offset = push_nested_header(self.as_vec_mut(), 6u16);
35483 PushTcaGredVqListAttrs {
35484 prev: Some(self),
35485 header_offset: Some(header_offset),
35486 }
35487 }
35488}
35489impl<Prev: Pusher> Drop for PushGredAttrs<Prev> {
35490 fn drop(&mut self) {
35491 if let Some(prev) = &mut self.prev {
35492 if let Some(header_offset) = &self.header_offset {
35493 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35494 }
35495 }
35496 }
35497}
35498pub struct PushTcaGredVqListAttrs<Prev: Pusher> {
35499 pub(crate) prev: Option<Prev>,
35500 pub(crate) header_offset: Option<usize>,
35501}
35502impl<Prev: Pusher> Pusher for PushTcaGredVqListAttrs<Prev> {
35503 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35504 self.prev.as_mut().unwrap().as_vec_mut()
35505 }
35506 fn as_vec(&self) -> &Vec<u8> {
35507 self.prev.as_ref().unwrap().as_vec()
35508 }
35509}
35510impl<Prev: Pusher> PushTcaGredVqListAttrs<Prev> {
35511 pub fn new(prev: Prev) -> Self {
35512 Self {
35513 prev: Some(prev),
35514 header_offset: None,
35515 }
35516 }
35517 pub fn end_nested(mut self) -> Prev {
35518 let mut prev = self.prev.take().unwrap();
35519 if let Some(header_offset) = &self.header_offset {
35520 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35521 }
35522 prev
35523 }
35524 #[doc = "Attribute may repeat multiple times (treat it as array)"]
35525 pub fn nested_entry(mut self) -> PushTcaGredVqEntryAttrs<Self> {
35526 let header_offset = push_nested_header(self.as_vec_mut(), 1u16);
35527 PushTcaGredVqEntryAttrs {
35528 prev: Some(self),
35529 header_offset: Some(header_offset),
35530 }
35531 }
35532}
35533impl<Prev: Pusher> Drop for PushTcaGredVqListAttrs<Prev> {
35534 fn drop(&mut self) {
35535 if let Some(prev) = &mut self.prev {
35536 if let Some(header_offset) = &self.header_offset {
35537 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35538 }
35539 }
35540 }
35541}
35542pub struct PushTcaGredVqEntryAttrs<Prev: Pusher> {
35543 pub(crate) prev: Option<Prev>,
35544 pub(crate) header_offset: Option<usize>,
35545}
35546impl<Prev: Pusher> Pusher for PushTcaGredVqEntryAttrs<Prev> {
35547 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35548 self.prev.as_mut().unwrap().as_vec_mut()
35549 }
35550 fn as_vec(&self) -> &Vec<u8> {
35551 self.prev.as_ref().unwrap().as_vec()
35552 }
35553}
35554impl<Prev: Pusher> PushTcaGredVqEntryAttrs<Prev> {
35555 pub fn new(prev: Prev) -> Self {
35556 Self {
35557 prev: Some(prev),
35558 header_offset: None,
35559 }
35560 }
35561 pub fn end_nested(mut self) -> Prev {
35562 let mut prev = self.prev.take().unwrap();
35563 if let Some(header_offset) = &self.header_offset {
35564 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35565 }
35566 prev
35567 }
35568 pub fn push_pad(mut self, value: &[u8]) -> Self {
35569 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
35570 self.as_vec_mut().extend(value);
35571 self
35572 }
35573 pub fn push_dp(mut self, value: u32) -> Self {
35574 push_header(self.as_vec_mut(), 2u16, 4 as u16);
35575 self.as_vec_mut().extend(value.to_ne_bytes());
35576 self
35577 }
35578 pub fn push_stat_bytes(mut self, value: u64) -> Self {
35579 push_header(self.as_vec_mut(), 3u16, 8 as u16);
35580 self.as_vec_mut().extend(value.to_ne_bytes());
35581 self
35582 }
35583 pub fn push_stat_packets(mut self, value: u32) -> Self {
35584 push_header(self.as_vec_mut(), 4u16, 4 as u16);
35585 self.as_vec_mut().extend(value.to_ne_bytes());
35586 self
35587 }
35588 pub fn push_stat_backlog(mut self, value: u32) -> Self {
35589 push_header(self.as_vec_mut(), 5u16, 4 as u16);
35590 self.as_vec_mut().extend(value.to_ne_bytes());
35591 self
35592 }
35593 pub fn push_stat_prob_drop(mut self, value: u32) -> Self {
35594 push_header(self.as_vec_mut(), 6u16, 4 as u16);
35595 self.as_vec_mut().extend(value.to_ne_bytes());
35596 self
35597 }
35598 pub fn push_stat_prob_mark(mut self, value: u32) -> Self {
35599 push_header(self.as_vec_mut(), 7u16, 4 as u16);
35600 self.as_vec_mut().extend(value.to_ne_bytes());
35601 self
35602 }
35603 pub fn push_stat_forced_drop(mut self, value: u32) -> Self {
35604 push_header(self.as_vec_mut(), 8u16, 4 as u16);
35605 self.as_vec_mut().extend(value.to_ne_bytes());
35606 self
35607 }
35608 pub fn push_stat_forced_mark(mut self, value: u32) -> Self {
35609 push_header(self.as_vec_mut(), 9u16, 4 as u16);
35610 self.as_vec_mut().extend(value.to_ne_bytes());
35611 self
35612 }
35613 pub fn push_stat_pdrop(mut self, value: u32) -> Self {
35614 push_header(self.as_vec_mut(), 10u16, 4 as u16);
35615 self.as_vec_mut().extend(value.to_ne_bytes());
35616 self
35617 }
35618 pub fn push_stat_other(mut self, value: u32) -> Self {
35619 push_header(self.as_vec_mut(), 11u16, 4 as u16);
35620 self.as_vec_mut().extend(value.to_ne_bytes());
35621 self
35622 }
35623 pub fn push_flags(mut self, value: u32) -> Self {
35624 push_header(self.as_vec_mut(), 12u16, 4 as u16);
35625 self.as_vec_mut().extend(value.to_ne_bytes());
35626 self
35627 }
35628}
35629impl<Prev: Pusher> Drop for PushTcaGredVqEntryAttrs<Prev> {
35630 fn drop(&mut self) {
35631 if let Some(prev) = &mut self.prev {
35632 if let Some(header_offset) = &self.header_offset {
35633 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35634 }
35635 }
35636 }
35637}
35638pub struct PushHfscAttrs<Prev: Pusher> {
35639 pub(crate) prev: Option<Prev>,
35640 pub(crate) header_offset: Option<usize>,
35641}
35642impl<Prev: Pusher> Pusher for PushHfscAttrs<Prev> {
35643 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35644 self.prev.as_mut().unwrap().as_vec_mut()
35645 }
35646 fn as_vec(&self) -> &Vec<u8> {
35647 self.prev.as_ref().unwrap().as_vec()
35648 }
35649}
35650impl<Prev: Pusher> PushHfscAttrs<Prev> {
35651 pub fn new(prev: Prev) -> Self {
35652 Self {
35653 prev: Some(prev),
35654 header_offset: None,
35655 }
35656 }
35657 pub fn end_nested(mut self) -> Prev {
35658 let mut prev = self.prev.take().unwrap();
35659 if let Some(header_offset) = &self.header_offset {
35660 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35661 }
35662 prev
35663 }
35664 pub fn push_rsc(mut self, value: &[u8]) -> Self {
35665 push_header(self.as_vec_mut(), 1u16, value.len() as u16);
35666 self.as_vec_mut().extend(value);
35667 self
35668 }
35669 pub fn push_fsc(mut self, value: &[u8]) -> Self {
35670 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
35671 self.as_vec_mut().extend(value);
35672 self
35673 }
35674 pub fn push_usc(mut self, value: &[u8]) -> Self {
35675 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
35676 self.as_vec_mut().extend(value);
35677 self
35678 }
35679}
35680impl<Prev: Pusher> Drop for PushHfscAttrs<Prev> {
35681 fn drop(&mut self) {
35682 if let Some(prev) = &mut self.prev {
35683 if let Some(header_offset) = &self.header_offset {
35684 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35685 }
35686 }
35687 }
35688}
35689pub struct PushHhfAttrs<Prev: Pusher> {
35690 pub(crate) prev: Option<Prev>,
35691 pub(crate) header_offset: Option<usize>,
35692}
35693impl<Prev: Pusher> Pusher for PushHhfAttrs<Prev> {
35694 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35695 self.prev.as_mut().unwrap().as_vec_mut()
35696 }
35697 fn as_vec(&self) -> &Vec<u8> {
35698 self.prev.as_ref().unwrap().as_vec()
35699 }
35700}
35701impl<Prev: Pusher> PushHhfAttrs<Prev> {
35702 pub fn new(prev: Prev) -> Self {
35703 Self {
35704 prev: Some(prev),
35705 header_offset: None,
35706 }
35707 }
35708 pub fn end_nested(mut self) -> Prev {
35709 let mut prev = self.prev.take().unwrap();
35710 if let Some(header_offset) = &self.header_offset {
35711 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35712 }
35713 prev
35714 }
35715 pub fn push_backlog_limit(mut self, value: u32) -> Self {
35716 push_header(self.as_vec_mut(), 1u16, 4 as u16);
35717 self.as_vec_mut().extend(value.to_ne_bytes());
35718 self
35719 }
35720 pub fn push_quantum(mut self, value: u32) -> Self {
35721 push_header(self.as_vec_mut(), 2u16, 4 as u16);
35722 self.as_vec_mut().extend(value.to_ne_bytes());
35723 self
35724 }
35725 pub fn push_hh_flows_limit(mut self, value: u32) -> Self {
35726 push_header(self.as_vec_mut(), 3u16, 4 as u16);
35727 self.as_vec_mut().extend(value.to_ne_bytes());
35728 self
35729 }
35730 pub fn push_reset_timeout(mut self, value: u32) -> Self {
35731 push_header(self.as_vec_mut(), 4u16, 4 as u16);
35732 self.as_vec_mut().extend(value.to_ne_bytes());
35733 self
35734 }
35735 pub fn push_admit_bytes(mut self, value: u32) -> Self {
35736 push_header(self.as_vec_mut(), 5u16, 4 as u16);
35737 self.as_vec_mut().extend(value.to_ne_bytes());
35738 self
35739 }
35740 pub fn push_evict_timeout(mut self, value: u32) -> Self {
35741 push_header(self.as_vec_mut(), 6u16, 4 as u16);
35742 self.as_vec_mut().extend(value.to_ne_bytes());
35743 self
35744 }
35745 pub fn push_non_hh_weight(mut self, value: u32) -> Self {
35746 push_header(self.as_vec_mut(), 7u16, 4 as u16);
35747 self.as_vec_mut().extend(value.to_ne_bytes());
35748 self
35749 }
35750}
35751impl<Prev: Pusher> Drop for PushHhfAttrs<Prev> {
35752 fn drop(&mut self) {
35753 if let Some(prev) = &mut self.prev {
35754 if let Some(header_offset) = &self.header_offset {
35755 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35756 }
35757 }
35758 }
35759}
35760pub struct PushHtbAttrs<Prev: Pusher> {
35761 pub(crate) prev: Option<Prev>,
35762 pub(crate) header_offset: Option<usize>,
35763}
35764impl<Prev: Pusher> Pusher for PushHtbAttrs<Prev> {
35765 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35766 self.prev.as_mut().unwrap().as_vec_mut()
35767 }
35768 fn as_vec(&self) -> &Vec<u8> {
35769 self.prev.as_ref().unwrap().as_vec()
35770 }
35771}
35772impl<Prev: Pusher> PushHtbAttrs<Prev> {
35773 pub fn new(prev: Prev) -> Self {
35774 Self {
35775 prev: Some(prev),
35776 header_offset: None,
35777 }
35778 }
35779 pub fn end_nested(mut self) -> Prev {
35780 let mut prev = self.prev.take().unwrap();
35781 if let Some(header_offset) = &self.header_offset {
35782 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35783 }
35784 prev
35785 }
35786 pub fn push_parms(mut self, value: TcHtbOpt) -> Self {
35787 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
35788 self.as_vec_mut().extend(value.as_slice());
35789 self
35790 }
35791 pub fn push_init(mut self, value: TcHtbGlob) -> Self {
35792 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
35793 self.as_vec_mut().extend(value.as_slice());
35794 self
35795 }
35796 pub fn push_ctab(mut self, value: &[u8]) -> Self {
35797 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
35798 self.as_vec_mut().extend(value);
35799 self
35800 }
35801 pub fn push_rtab(mut self, value: &[u8]) -> Self {
35802 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
35803 self.as_vec_mut().extend(value);
35804 self
35805 }
35806 pub fn push_direct_qlen(mut self, value: u32) -> Self {
35807 push_header(self.as_vec_mut(), 5u16, 4 as u16);
35808 self.as_vec_mut().extend(value.to_ne_bytes());
35809 self
35810 }
35811 pub fn push_rate64(mut self, value: u64) -> Self {
35812 push_header(self.as_vec_mut(), 6u16, 8 as u16);
35813 self.as_vec_mut().extend(value.to_ne_bytes());
35814 self
35815 }
35816 pub fn push_ceil64(mut self, value: u64) -> Self {
35817 push_header(self.as_vec_mut(), 7u16, 8 as u16);
35818 self.as_vec_mut().extend(value.to_ne_bytes());
35819 self
35820 }
35821 pub fn push_pad(mut self, value: &[u8]) -> Self {
35822 push_header(self.as_vec_mut(), 8u16, value.len() as u16);
35823 self.as_vec_mut().extend(value);
35824 self
35825 }
35826 pub fn push_offload(mut self, value: ()) -> Self {
35827 push_header(self.as_vec_mut(), 9u16, 0 as u16);
35828 self
35829 }
35830}
35831impl<Prev: Pusher> Drop for PushHtbAttrs<Prev> {
35832 fn drop(&mut self) {
35833 if let Some(prev) = &mut self.prev {
35834 if let Some(header_offset) = &self.header_offset {
35835 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35836 }
35837 }
35838 }
35839}
35840pub struct PushMatchallAttrs<Prev: Pusher> {
35841 pub(crate) prev: Option<Prev>,
35842 pub(crate) header_offset: Option<usize>,
35843}
35844impl<Prev: Pusher> Pusher for PushMatchallAttrs<Prev> {
35845 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35846 self.prev.as_mut().unwrap().as_vec_mut()
35847 }
35848 fn as_vec(&self) -> &Vec<u8> {
35849 self.prev.as_ref().unwrap().as_vec()
35850 }
35851}
35852impl<Prev: Pusher> PushMatchallAttrs<Prev> {
35853 pub fn new(prev: Prev) -> Self {
35854 Self {
35855 prev: Some(prev),
35856 header_offset: None,
35857 }
35858 }
35859 pub fn end_nested(mut self) -> Prev {
35860 let mut prev = self.prev.take().unwrap();
35861 if let Some(header_offset) = &self.header_offset {
35862 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35863 }
35864 prev
35865 }
35866 pub fn push_classid(mut self, value: u32) -> Self {
35867 push_header(self.as_vec_mut(), 1u16, 4 as u16);
35868 self.as_vec_mut().extend(value.to_ne_bytes());
35869 self
35870 }
35871 pub fn array_act(mut self) -> PushArrayActAttrs<Self> {
35872 let header_offset = push_nested_header(self.as_vec_mut(), 2u16);
35873 PushArrayActAttrs {
35874 prev: Some(self),
35875 header_offset: Some(header_offset),
35876 counter: 0,
35877 }
35878 }
35879 pub fn push_flags(mut self, value: u32) -> Self {
35880 push_header(self.as_vec_mut(), 3u16, 4 as u16);
35881 self.as_vec_mut().extend(value.to_ne_bytes());
35882 self
35883 }
35884 pub fn push_pcnt(mut self, value: TcMatchallPcnt) -> Self {
35885 push_header(self.as_vec_mut(), 4u16, value.as_slice().len() as u16);
35886 self.as_vec_mut().extend(value.as_slice());
35887 self
35888 }
35889 pub fn push_pad(mut self, value: &[u8]) -> Self {
35890 push_header(self.as_vec_mut(), 5u16, value.len() as u16);
35891 self.as_vec_mut().extend(value);
35892 self
35893 }
35894}
35895impl<Prev: Pusher> Drop for PushMatchallAttrs<Prev> {
35896 fn drop(&mut self) {
35897 if let Some(prev) = &mut self.prev {
35898 if let Some(header_offset) = &self.header_offset {
35899 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35900 }
35901 }
35902 }
35903}
35904pub struct PushEtfAttrs<Prev: Pusher> {
35905 pub(crate) prev: Option<Prev>,
35906 pub(crate) header_offset: Option<usize>,
35907}
35908impl<Prev: Pusher> Pusher for PushEtfAttrs<Prev> {
35909 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35910 self.prev.as_mut().unwrap().as_vec_mut()
35911 }
35912 fn as_vec(&self) -> &Vec<u8> {
35913 self.prev.as_ref().unwrap().as_vec()
35914 }
35915}
35916impl<Prev: Pusher> PushEtfAttrs<Prev> {
35917 pub fn new(prev: Prev) -> Self {
35918 Self {
35919 prev: Some(prev),
35920 header_offset: None,
35921 }
35922 }
35923 pub fn end_nested(mut self) -> Prev {
35924 let mut prev = self.prev.take().unwrap();
35925 if let Some(header_offset) = &self.header_offset {
35926 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35927 }
35928 prev
35929 }
35930 pub fn push_parms(mut self, value: TcEtfQopt) -> Self {
35931 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
35932 self.as_vec_mut().extend(value.as_slice());
35933 self
35934 }
35935}
35936impl<Prev: Pusher> Drop for PushEtfAttrs<Prev> {
35937 fn drop(&mut self) {
35938 if let Some(prev) = &mut self.prev {
35939 if let Some(header_offset) = &self.header_offset {
35940 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35941 }
35942 }
35943 }
35944}
35945pub struct PushEtsAttrs<Prev: Pusher> {
35946 pub(crate) prev: Option<Prev>,
35947 pub(crate) header_offset: Option<usize>,
35948}
35949impl<Prev: Pusher> Pusher for PushEtsAttrs<Prev> {
35950 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
35951 self.prev.as_mut().unwrap().as_vec_mut()
35952 }
35953 fn as_vec(&self) -> &Vec<u8> {
35954 self.prev.as_ref().unwrap().as_vec()
35955 }
35956}
35957impl<Prev: Pusher> PushEtsAttrs<Prev> {
35958 pub fn new(prev: Prev) -> Self {
35959 Self {
35960 prev: Some(prev),
35961 header_offset: None,
35962 }
35963 }
35964 pub fn end_nested(mut self) -> Prev {
35965 let mut prev = self.prev.take().unwrap();
35966 if let Some(header_offset) = &self.header_offset {
35967 finalize_nested_header(prev.as_vec_mut(), *header_offset);
35968 }
35969 prev
35970 }
35971 pub fn push_nbands(mut self, value: u8) -> Self {
35972 push_header(self.as_vec_mut(), 1u16, 1 as u16);
35973 self.as_vec_mut().extend(value.to_ne_bytes());
35974 self
35975 }
35976 pub fn push_nstrict(mut self, value: u8) -> Self {
35977 push_header(self.as_vec_mut(), 2u16, 1 as u16);
35978 self.as_vec_mut().extend(value.to_ne_bytes());
35979 self
35980 }
35981 pub fn nested_quanta(mut self) -> PushEtsAttrs<Self> {
35982 let header_offset = push_nested_header(self.as_vec_mut(), 3u16);
35983 PushEtsAttrs {
35984 prev: Some(self),
35985 header_offset: Some(header_offset),
35986 }
35987 }
35988 #[doc = "Attribute may repeat multiple times (treat it as array)"]
35989 pub fn push_quanta_band(mut self, value: u32) -> Self {
35990 push_header(self.as_vec_mut(), 4u16, 4 as u16);
35991 self.as_vec_mut().extend(value.to_ne_bytes());
35992 self
35993 }
35994 pub fn nested_priomap(mut self) -> PushEtsAttrs<Self> {
35995 let header_offset = push_nested_header(self.as_vec_mut(), 5u16);
35996 PushEtsAttrs {
35997 prev: Some(self),
35998 header_offset: Some(header_offset),
35999 }
36000 }
36001 #[doc = "Attribute may repeat multiple times (treat it as array)"]
36002 pub fn push_priomap_band(mut self, value: u8) -> Self {
36003 push_header(self.as_vec_mut(), 6u16, 1 as u16);
36004 self.as_vec_mut().extend(value.to_ne_bytes());
36005 self
36006 }
36007}
36008impl<Prev: Pusher> Drop for PushEtsAttrs<Prev> {
36009 fn drop(&mut self) {
36010 if let Some(prev) = &mut self.prev {
36011 if let Some(header_offset) = &self.header_offset {
36012 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36013 }
36014 }
36015 }
36016}
36017pub struct PushFqAttrs<Prev: Pusher> {
36018 pub(crate) prev: Option<Prev>,
36019 pub(crate) header_offset: Option<usize>,
36020}
36021impl<Prev: Pusher> Pusher for PushFqAttrs<Prev> {
36022 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36023 self.prev.as_mut().unwrap().as_vec_mut()
36024 }
36025 fn as_vec(&self) -> &Vec<u8> {
36026 self.prev.as_ref().unwrap().as_vec()
36027 }
36028}
36029impl<Prev: Pusher> PushFqAttrs<Prev> {
36030 pub fn new(prev: Prev) -> Self {
36031 Self {
36032 prev: Some(prev),
36033 header_offset: None,
36034 }
36035 }
36036 pub fn end_nested(mut self) -> Prev {
36037 let mut prev = self.prev.take().unwrap();
36038 if let Some(header_offset) = &self.header_offset {
36039 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36040 }
36041 prev
36042 }
36043 #[doc = "Limit of total number of packets in queue\n"]
36044 pub fn push_plimit(mut self, value: u32) -> Self {
36045 push_header(self.as_vec_mut(), 1u16, 4 as u16);
36046 self.as_vec_mut().extend(value.to_ne_bytes());
36047 self
36048 }
36049 #[doc = "Limit of packets per flow\n"]
36050 pub fn push_flow_plimit(mut self, value: u32) -> Self {
36051 push_header(self.as_vec_mut(), 2u16, 4 as u16);
36052 self.as_vec_mut().extend(value.to_ne_bytes());
36053 self
36054 }
36055 #[doc = "RR quantum\n"]
36056 pub fn push_quantum(mut self, value: u32) -> Self {
36057 push_header(self.as_vec_mut(), 3u16, 4 as u16);
36058 self.as_vec_mut().extend(value.to_ne_bytes());
36059 self
36060 }
36061 #[doc = "RR quantum for new flow\n"]
36062 pub fn push_initial_quantum(mut self, value: u32) -> Self {
36063 push_header(self.as_vec_mut(), 4u16, 4 as u16);
36064 self.as_vec_mut().extend(value.to_ne_bytes());
36065 self
36066 }
36067 #[doc = "Enable / disable rate limiting\n"]
36068 pub fn push_rate_enable(mut self, value: u32) -> Self {
36069 push_header(self.as_vec_mut(), 5u16, 4 as u16);
36070 self.as_vec_mut().extend(value.to_ne_bytes());
36071 self
36072 }
36073 #[doc = "Obsolete, do not use\n"]
36074 pub fn push_flow_default_rate(mut self, value: u32) -> Self {
36075 push_header(self.as_vec_mut(), 6u16, 4 as u16);
36076 self.as_vec_mut().extend(value.to_ne_bytes());
36077 self
36078 }
36079 #[doc = "Per flow max rate\n"]
36080 pub fn push_flow_max_rate(mut self, value: u32) -> Self {
36081 push_header(self.as_vec_mut(), 7u16, 4 as u16);
36082 self.as_vec_mut().extend(value.to_ne_bytes());
36083 self
36084 }
36085 #[doc = "log2(number of buckets)\n"]
36086 pub fn push_buckets_log(mut self, value: u32) -> Self {
36087 push_header(self.as_vec_mut(), 8u16, 4 as u16);
36088 self.as_vec_mut().extend(value.to_ne_bytes());
36089 self
36090 }
36091 #[doc = "Flow credit refill delay in usec\n"]
36092 pub fn push_flow_refill_delay(mut self, value: u32) -> Self {
36093 push_header(self.as_vec_mut(), 9u16, 4 as u16);
36094 self.as_vec_mut().extend(value.to_ne_bytes());
36095 self
36096 }
36097 #[doc = "Mask applied to orphaned skb hashes\n"]
36098 pub fn push_orphan_mask(mut self, value: u32) -> Self {
36099 push_header(self.as_vec_mut(), 10u16, 4 as u16);
36100 self.as_vec_mut().extend(value.to_ne_bytes());
36101 self
36102 }
36103 #[doc = "Per packet delay under this rate\n"]
36104 pub fn push_low_rate_threshold(mut self, value: u32) -> Self {
36105 push_header(self.as_vec_mut(), 11u16, 4 as u16);
36106 self.as_vec_mut().extend(value.to_ne_bytes());
36107 self
36108 }
36109 #[doc = "DCTCP-like CE marking threshold\n"]
36110 pub fn push_ce_threshold(mut self, value: u32) -> Self {
36111 push_header(self.as_vec_mut(), 12u16, 4 as u16);
36112 self.as_vec_mut().extend(value.to_ne_bytes());
36113 self
36114 }
36115 pub fn push_timer_slack(mut self, value: u32) -> Self {
36116 push_header(self.as_vec_mut(), 13u16, 4 as u16);
36117 self.as_vec_mut().extend(value.to_ne_bytes());
36118 self
36119 }
36120 #[doc = "Time horizon in usec\n"]
36121 pub fn push_horizon(mut self, value: u32) -> Self {
36122 push_header(self.as_vec_mut(), 14u16, 4 as u16);
36123 self.as_vec_mut().extend(value.to_ne_bytes());
36124 self
36125 }
36126 #[doc = "Drop packets beyond horizon, or cap their EDT\n"]
36127 pub fn push_horizon_drop(mut self, value: u8) -> Self {
36128 push_header(self.as_vec_mut(), 15u16, 1 as u16);
36129 self.as_vec_mut().extend(value.to_ne_bytes());
36130 self
36131 }
36132 pub fn push_priomap(mut self, value: TcPrioQopt) -> Self {
36133 push_header(self.as_vec_mut(), 16u16, value.as_slice().len() as u16);
36134 self.as_vec_mut().extend(value.as_slice());
36135 self
36136 }
36137 #[doc = "Weights for each band\n"]
36138 pub fn push_weights(mut self, value: &[u8]) -> Self {
36139 push_header(self.as_vec_mut(), 17u16, value.len() as u16);
36140 self.as_vec_mut().extend(value);
36141 self
36142 }
36143}
36144impl<Prev: Pusher> Drop for PushFqAttrs<Prev> {
36145 fn drop(&mut self) {
36146 if let Some(prev) = &mut self.prev {
36147 if let Some(header_offset) = &self.header_offset {
36148 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36149 }
36150 }
36151 }
36152}
36153pub struct PushFqCodelAttrs<Prev: Pusher> {
36154 pub(crate) prev: Option<Prev>,
36155 pub(crate) header_offset: Option<usize>,
36156}
36157impl<Prev: Pusher> Pusher for PushFqCodelAttrs<Prev> {
36158 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36159 self.prev.as_mut().unwrap().as_vec_mut()
36160 }
36161 fn as_vec(&self) -> &Vec<u8> {
36162 self.prev.as_ref().unwrap().as_vec()
36163 }
36164}
36165impl<Prev: Pusher> PushFqCodelAttrs<Prev> {
36166 pub fn new(prev: Prev) -> Self {
36167 Self {
36168 prev: Some(prev),
36169 header_offset: None,
36170 }
36171 }
36172 pub fn end_nested(mut self) -> Prev {
36173 let mut prev = self.prev.take().unwrap();
36174 if let Some(header_offset) = &self.header_offset {
36175 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36176 }
36177 prev
36178 }
36179 pub fn push_target(mut self, value: u32) -> Self {
36180 push_header(self.as_vec_mut(), 1u16, 4 as u16);
36181 self.as_vec_mut().extend(value.to_ne_bytes());
36182 self
36183 }
36184 pub fn push_limit(mut self, value: u32) -> Self {
36185 push_header(self.as_vec_mut(), 2u16, 4 as u16);
36186 self.as_vec_mut().extend(value.to_ne_bytes());
36187 self
36188 }
36189 pub fn push_interval(mut self, value: u32) -> Self {
36190 push_header(self.as_vec_mut(), 3u16, 4 as u16);
36191 self.as_vec_mut().extend(value.to_ne_bytes());
36192 self
36193 }
36194 pub fn push_ecn(mut self, value: u32) -> Self {
36195 push_header(self.as_vec_mut(), 4u16, 4 as u16);
36196 self.as_vec_mut().extend(value.to_ne_bytes());
36197 self
36198 }
36199 pub fn push_flows(mut self, value: u32) -> Self {
36200 push_header(self.as_vec_mut(), 5u16, 4 as u16);
36201 self.as_vec_mut().extend(value.to_ne_bytes());
36202 self
36203 }
36204 pub fn push_quantum(mut self, value: u32) -> Self {
36205 push_header(self.as_vec_mut(), 6u16, 4 as u16);
36206 self.as_vec_mut().extend(value.to_ne_bytes());
36207 self
36208 }
36209 pub fn push_ce_threshold(mut self, value: u32) -> Self {
36210 push_header(self.as_vec_mut(), 7u16, 4 as u16);
36211 self.as_vec_mut().extend(value.to_ne_bytes());
36212 self
36213 }
36214 pub fn push_drop_batch_size(mut self, value: u32) -> Self {
36215 push_header(self.as_vec_mut(), 8u16, 4 as u16);
36216 self.as_vec_mut().extend(value.to_ne_bytes());
36217 self
36218 }
36219 pub fn push_memory_limit(mut self, value: u32) -> Self {
36220 push_header(self.as_vec_mut(), 9u16, 4 as u16);
36221 self.as_vec_mut().extend(value.to_ne_bytes());
36222 self
36223 }
36224 pub fn push_ce_threshold_selector(mut self, value: u8) -> Self {
36225 push_header(self.as_vec_mut(), 10u16, 1 as u16);
36226 self.as_vec_mut().extend(value.to_ne_bytes());
36227 self
36228 }
36229 pub fn push_ce_threshold_mask(mut self, value: u8) -> Self {
36230 push_header(self.as_vec_mut(), 11u16, 1 as u16);
36231 self.as_vec_mut().extend(value.to_ne_bytes());
36232 self
36233 }
36234}
36235impl<Prev: Pusher> Drop for PushFqCodelAttrs<Prev> {
36236 fn drop(&mut self) {
36237 if let Some(prev) = &mut self.prev {
36238 if let Some(header_offset) = &self.header_offset {
36239 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36240 }
36241 }
36242 }
36243}
36244pub struct PushFqPieAttrs<Prev: Pusher> {
36245 pub(crate) prev: Option<Prev>,
36246 pub(crate) header_offset: Option<usize>,
36247}
36248impl<Prev: Pusher> Pusher for PushFqPieAttrs<Prev> {
36249 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36250 self.prev.as_mut().unwrap().as_vec_mut()
36251 }
36252 fn as_vec(&self) -> &Vec<u8> {
36253 self.prev.as_ref().unwrap().as_vec()
36254 }
36255}
36256impl<Prev: Pusher> PushFqPieAttrs<Prev> {
36257 pub fn new(prev: Prev) -> Self {
36258 Self {
36259 prev: Some(prev),
36260 header_offset: None,
36261 }
36262 }
36263 pub fn end_nested(mut self) -> Prev {
36264 let mut prev = self.prev.take().unwrap();
36265 if let Some(header_offset) = &self.header_offset {
36266 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36267 }
36268 prev
36269 }
36270 pub fn push_limit(mut self, value: u32) -> Self {
36271 push_header(self.as_vec_mut(), 1u16, 4 as u16);
36272 self.as_vec_mut().extend(value.to_ne_bytes());
36273 self
36274 }
36275 pub fn push_flows(mut self, value: u32) -> Self {
36276 push_header(self.as_vec_mut(), 2u16, 4 as u16);
36277 self.as_vec_mut().extend(value.to_ne_bytes());
36278 self
36279 }
36280 pub fn push_target(mut self, value: u32) -> Self {
36281 push_header(self.as_vec_mut(), 3u16, 4 as u16);
36282 self.as_vec_mut().extend(value.to_ne_bytes());
36283 self
36284 }
36285 pub fn push_tupdate(mut self, value: u32) -> Self {
36286 push_header(self.as_vec_mut(), 4u16, 4 as u16);
36287 self.as_vec_mut().extend(value.to_ne_bytes());
36288 self
36289 }
36290 pub fn push_alpha(mut self, value: u32) -> Self {
36291 push_header(self.as_vec_mut(), 5u16, 4 as u16);
36292 self.as_vec_mut().extend(value.to_ne_bytes());
36293 self
36294 }
36295 pub fn push_beta(mut self, value: u32) -> Self {
36296 push_header(self.as_vec_mut(), 6u16, 4 as u16);
36297 self.as_vec_mut().extend(value.to_ne_bytes());
36298 self
36299 }
36300 pub fn push_quantum(mut self, value: u32) -> Self {
36301 push_header(self.as_vec_mut(), 7u16, 4 as u16);
36302 self.as_vec_mut().extend(value.to_ne_bytes());
36303 self
36304 }
36305 pub fn push_memory_limit(mut self, value: u32) -> Self {
36306 push_header(self.as_vec_mut(), 8u16, 4 as u16);
36307 self.as_vec_mut().extend(value.to_ne_bytes());
36308 self
36309 }
36310 pub fn push_ecn_prob(mut self, value: u32) -> Self {
36311 push_header(self.as_vec_mut(), 9u16, 4 as u16);
36312 self.as_vec_mut().extend(value.to_ne_bytes());
36313 self
36314 }
36315 pub fn push_ecn(mut self, value: u32) -> Self {
36316 push_header(self.as_vec_mut(), 10u16, 4 as u16);
36317 self.as_vec_mut().extend(value.to_ne_bytes());
36318 self
36319 }
36320 pub fn push_bytemode(mut self, value: u32) -> Self {
36321 push_header(self.as_vec_mut(), 11u16, 4 as u16);
36322 self.as_vec_mut().extend(value.to_ne_bytes());
36323 self
36324 }
36325 pub fn push_dq_rate_estimator(mut self, value: u32) -> Self {
36326 push_header(self.as_vec_mut(), 12u16, 4 as u16);
36327 self.as_vec_mut().extend(value.to_ne_bytes());
36328 self
36329 }
36330}
36331impl<Prev: Pusher> Drop for PushFqPieAttrs<Prev> {
36332 fn drop(&mut self) {
36333 if let Some(prev) = &mut self.prev {
36334 if let Some(header_offset) = &self.header_offset {
36335 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36336 }
36337 }
36338 }
36339}
36340pub struct PushNetemAttrs<Prev: Pusher> {
36341 pub(crate) prev: Option<Prev>,
36342 pub(crate) header_offset: Option<usize>,
36343}
36344impl<Prev: Pusher> Pusher for PushNetemAttrs<Prev> {
36345 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36346 self.prev.as_mut().unwrap().as_vec_mut()
36347 }
36348 fn as_vec(&self) -> &Vec<u8> {
36349 self.prev.as_ref().unwrap().as_vec()
36350 }
36351}
36352impl<Prev: Pusher> PushNetemAttrs<Prev> {
36353 pub fn new(prev: Prev) -> Self {
36354 Self {
36355 prev: Some(prev),
36356 header_offset: None,
36357 }
36358 }
36359 pub fn end_nested(mut self) -> Prev {
36360 let mut prev = self.prev.take().unwrap();
36361 if let Some(header_offset) = &self.header_offset {
36362 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36363 }
36364 prev
36365 }
36366 pub fn push_corr(mut self, value: TcNetemCorr) -> Self {
36367 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
36368 self.as_vec_mut().extend(value.as_slice());
36369 self
36370 }
36371 pub fn push_delay_dist(mut self, value: &[u8]) -> Self {
36372 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
36373 self.as_vec_mut().extend(value);
36374 self
36375 }
36376 pub fn push_reorder(mut self, value: TcNetemReorder) -> Self {
36377 push_header(self.as_vec_mut(), 3u16, value.as_slice().len() as u16);
36378 self.as_vec_mut().extend(value.as_slice());
36379 self
36380 }
36381 pub fn push_corrupt(mut self, value: TcNetemCorrupt) -> Self {
36382 push_header(self.as_vec_mut(), 4u16, value.as_slice().len() as u16);
36383 self.as_vec_mut().extend(value.as_slice());
36384 self
36385 }
36386 pub fn nested_loss(mut self) -> PushNetemLossAttrs<Self> {
36387 let header_offset = push_nested_header(self.as_vec_mut(), 5u16);
36388 PushNetemLossAttrs {
36389 prev: Some(self),
36390 header_offset: Some(header_offset),
36391 }
36392 }
36393 pub fn push_rate(mut self, value: TcNetemRate) -> Self {
36394 push_header(self.as_vec_mut(), 6u16, value.as_slice().len() as u16);
36395 self.as_vec_mut().extend(value.as_slice());
36396 self
36397 }
36398 pub fn push_ecn(mut self, value: u32) -> Self {
36399 push_header(self.as_vec_mut(), 7u16, 4 as u16);
36400 self.as_vec_mut().extend(value.to_ne_bytes());
36401 self
36402 }
36403 pub fn push_rate64(mut self, value: u64) -> Self {
36404 push_header(self.as_vec_mut(), 8u16, 8 as u16);
36405 self.as_vec_mut().extend(value.to_ne_bytes());
36406 self
36407 }
36408 pub fn push_pad(mut self, value: u32) -> Self {
36409 push_header(self.as_vec_mut(), 9u16, 4 as u16);
36410 self.as_vec_mut().extend(value.to_ne_bytes());
36411 self
36412 }
36413 pub fn push_latency64(mut self, value: i64) -> Self {
36414 push_header(self.as_vec_mut(), 10u16, 8 as u16);
36415 self.as_vec_mut().extend(value.to_ne_bytes());
36416 self
36417 }
36418 pub fn push_jitter64(mut self, value: i64) -> Self {
36419 push_header(self.as_vec_mut(), 11u16, 8 as u16);
36420 self.as_vec_mut().extend(value.to_ne_bytes());
36421 self
36422 }
36423 pub fn push_slot(mut self, value: TcNetemSlot) -> Self {
36424 push_header(self.as_vec_mut(), 12u16, value.as_slice().len() as u16);
36425 self.as_vec_mut().extend(value.as_slice());
36426 self
36427 }
36428 pub fn push_slot_dist(mut self, value: &[u8]) -> Self {
36429 push_header(self.as_vec_mut(), 13u16, value.len() as u16);
36430 self.as_vec_mut().extend(value);
36431 self
36432 }
36433 pub fn push_prng_seed(mut self, value: u64) -> Self {
36434 push_header(self.as_vec_mut(), 14u16, 8 as u16);
36435 self.as_vec_mut().extend(value.to_ne_bytes());
36436 self
36437 }
36438}
36439impl<Prev: Pusher> Drop for PushNetemAttrs<Prev> {
36440 fn drop(&mut self) {
36441 if let Some(prev) = &mut self.prev {
36442 if let Some(header_offset) = &self.header_offset {
36443 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36444 }
36445 }
36446 }
36447}
36448pub struct PushNetemLossAttrs<Prev: Pusher> {
36449 pub(crate) prev: Option<Prev>,
36450 pub(crate) header_offset: Option<usize>,
36451}
36452impl<Prev: Pusher> Pusher for PushNetemLossAttrs<Prev> {
36453 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36454 self.prev.as_mut().unwrap().as_vec_mut()
36455 }
36456 fn as_vec(&self) -> &Vec<u8> {
36457 self.prev.as_ref().unwrap().as_vec()
36458 }
36459}
36460impl<Prev: Pusher> PushNetemLossAttrs<Prev> {
36461 pub fn new(prev: Prev) -> Self {
36462 Self {
36463 prev: Some(prev),
36464 header_offset: None,
36465 }
36466 }
36467 pub fn end_nested(mut self) -> Prev {
36468 let mut prev = self.prev.take().unwrap();
36469 if let Some(header_offset) = &self.header_offset {
36470 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36471 }
36472 prev
36473 }
36474 #[doc = "General Intuitive - 4 state model\n"]
36475 pub fn push_gi(mut self, value: TcNetemGimodel) -> Self {
36476 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
36477 self.as_vec_mut().extend(value.as_slice());
36478 self
36479 }
36480 #[doc = "Gilbert Elliot models\n"]
36481 pub fn push_ge(mut self, value: TcNetemGemodel) -> Self {
36482 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
36483 self.as_vec_mut().extend(value.as_slice());
36484 self
36485 }
36486}
36487impl<Prev: Pusher> Drop for PushNetemLossAttrs<Prev> {
36488 fn drop(&mut self) {
36489 if let Some(prev) = &mut self.prev {
36490 if let Some(header_offset) = &self.header_offset {
36491 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36492 }
36493 }
36494 }
36495}
36496pub struct PushPieAttrs<Prev: Pusher> {
36497 pub(crate) prev: Option<Prev>,
36498 pub(crate) header_offset: Option<usize>,
36499}
36500impl<Prev: Pusher> Pusher for PushPieAttrs<Prev> {
36501 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36502 self.prev.as_mut().unwrap().as_vec_mut()
36503 }
36504 fn as_vec(&self) -> &Vec<u8> {
36505 self.prev.as_ref().unwrap().as_vec()
36506 }
36507}
36508impl<Prev: Pusher> PushPieAttrs<Prev> {
36509 pub fn new(prev: Prev) -> Self {
36510 Self {
36511 prev: Some(prev),
36512 header_offset: None,
36513 }
36514 }
36515 pub fn end_nested(mut self) -> Prev {
36516 let mut prev = self.prev.take().unwrap();
36517 if let Some(header_offset) = &self.header_offset {
36518 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36519 }
36520 prev
36521 }
36522 pub fn push_target(mut self, value: u32) -> Self {
36523 push_header(self.as_vec_mut(), 1u16, 4 as u16);
36524 self.as_vec_mut().extend(value.to_ne_bytes());
36525 self
36526 }
36527 pub fn push_limit(mut self, value: u32) -> Self {
36528 push_header(self.as_vec_mut(), 2u16, 4 as u16);
36529 self.as_vec_mut().extend(value.to_ne_bytes());
36530 self
36531 }
36532 pub fn push_tupdate(mut self, value: u32) -> Self {
36533 push_header(self.as_vec_mut(), 3u16, 4 as u16);
36534 self.as_vec_mut().extend(value.to_ne_bytes());
36535 self
36536 }
36537 pub fn push_alpha(mut self, value: u32) -> Self {
36538 push_header(self.as_vec_mut(), 4u16, 4 as u16);
36539 self.as_vec_mut().extend(value.to_ne_bytes());
36540 self
36541 }
36542 pub fn push_beta(mut self, value: u32) -> Self {
36543 push_header(self.as_vec_mut(), 5u16, 4 as u16);
36544 self.as_vec_mut().extend(value.to_ne_bytes());
36545 self
36546 }
36547 pub fn push_ecn(mut self, value: u32) -> Self {
36548 push_header(self.as_vec_mut(), 6u16, 4 as u16);
36549 self.as_vec_mut().extend(value.to_ne_bytes());
36550 self
36551 }
36552 pub fn push_bytemode(mut self, value: u32) -> Self {
36553 push_header(self.as_vec_mut(), 7u16, 4 as u16);
36554 self.as_vec_mut().extend(value.to_ne_bytes());
36555 self
36556 }
36557 pub fn push_dq_rate_estimator(mut self, value: u32) -> Self {
36558 push_header(self.as_vec_mut(), 8u16, 4 as u16);
36559 self.as_vec_mut().extend(value.to_ne_bytes());
36560 self
36561 }
36562}
36563impl<Prev: Pusher> Drop for PushPieAttrs<Prev> {
36564 fn drop(&mut self) {
36565 if let Some(prev) = &mut self.prev {
36566 if let Some(header_offset) = &self.header_offset {
36567 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36568 }
36569 }
36570 }
36571}
36572pub struct PushPoliceAttrs<Prev: Pusher> {
36573 pub(crate) prev: Option<Prev>,
36574 pub(crate) header_offset: Option<usize>,
36575}
36576impl<Prev: Pusher> Pusher for PushPoliceAttrs<Prev> {
36577 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36578 self.prev.as_mut().unwrap().as_vec_mut()
36579 }
36580 fn as_vec(&self) -> &Vec<u8> {
36581 self.prev.as_ref().unwrap().as_vec()
36582 }
36583}
36584impl<Prev: Pusher> PushPoliceAttrs<Prev> {
36585 pub fn new(prev: Prev) -> Self {
36586 Self {
36587 prev: Some(prev),
36588 header_offset: None,
36589 }
36590 }
36591 pub fn end_nested(mut self) -> Prev {
36592 let mut prev = self.prev.take().unwrap();
36593 if let Some(header_offset) = &self.header_offset {
36594 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36595 }
36596 prev
36597 }
36598 pub fn push_tbf(mut self, value: TcPolice) -> Self {
36599 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
36600 self.as_vec_mut().extend(value.as_slice());
36601 self
36602 }
36603 pub fn push_rate(mut self, value: &[u8]) -> Self {
36604 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
36605 self.as_vec_mut().extend(value);
36606 self
36607 }
36608 pub fn push_peakrate(mut self, value: &[u8]) -> Self {
36609 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
36610 self.as_vec_mut().extend(value);
36611 self
36612 }
36613 pub fn push_avrate(mut self, value: u32) -> Self {
36614 push_header(self.as_vec_mut(), 4u16, 4 as u16);
36615 self.as_vec_mut().extend(value.to_ne_bytes());
36616 self
36617 }
36618 pub fn push_result(mut self, value: u32) -> Self {
36619 push_header(self.as_vec_mut(), 5u16, 4 as u16);
36620 self.as_vec_mut().extend(value.to_ne_bytes());
36621 self
36622 }
36623 pub fn push_tm(mut self, value: TcfT) -> Self {
36624 push_header(self.as_vec_mut(), 6u16, value.as_slice().len() as u16);
36625 self.as_vec_mut().extend(value.as_slice());
36626 self
36627 }
36628 pub fn push_pad(mut self, value: &[u8]) -> Self {
36629 push_header(self.as_vec_mut(), 7u16, value.len() as u16);
36630 self.as_vec_mut().extend(value);
36631 self
36632 }
36633 pub fn push_rate64(mut self, value: u64) -> Self {
36634 push_header(self.as_vec_mut(), 8u16, 8 as u16);
36635 self.as_vec_mut().extend(value.to_ne_bytes());
36636 self
36637 }
36638 pub fn push_peakrate64(mut self, value: u64) -> Self {
36639 push_header(self.as_vec_mut(), 9u16, 8 as u16);
36640 self.as_vec_mut().extend(value.to_ne_bytes());
36641 self
36642 }
36643 pub fn push_pktrate64(mut self, value: u64) -> Self {
36644 push_header(self.as_vec_mut(), 10u16, 8 as u16);
36645 self.as_vec_mut().extend(value.to_ne_bytes());
36646 self
36647 }
36648 pub fn push_pktburst64(mut self, value: u64) -> Self {
36649 push_header(self.as_vec_mut(), 11u16, 8 as u16);
36650 self.as_vec_mut().extend(value.to_ne_bytes());
36651 self
36652 }
36653}
36654impl<Prev: Pusher> Drop for PushPoliceAttrs<Prev> {
36655 fn drop(&mut self) {
36656 if let Some(prev) = &mut self.prev {
36657 if let Some(header_offset) = &self.header_offset {
36658 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36659 }
36660 }
36661 }
36662}
36663pub struct PushQfqAttrs<Prev: Pusher> {
36664 pub(crate) prev: Option<Prev>,
36665 pub(crate) header_offset: Option<usize>,
36666}
36667impl<Prev: Pusher> Pusher for PushQfqAttrs<Prev> {
36668 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36669 self.prev.as_mut().unwrap().as_vec_mut()
36670 }
36671 fn as_vec(&self) -> &Vec<u8> {
36672 self.prev.as_ref().unwrap().as_vec()
36673 }
36674}
36675impl<Prev: Pusher> PushQfqAttrs<Prev> {
36676 pub fn new(prev: Prev) -> Self {
36677 Self {
36678 prev: Some(prev),
36679 header_offset: None,
36680 }
36681 }
36682 pub fn end_nested(mut self) -> Prev {
36683 let mut prev = self.prev.take().unwrap();
36684 if let Some(header_offset) = &self.header_offset {
36685 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36686 }
36687 prev
36688 }
36689 pub fn push_weight(mut self, value: u32) -> Self {
36690 push_header(self.as_vec_mut(), 1u16, 4 as u16);
36691 self.as_vec_mut().extend(value.to_ne_bytes());
36692 self
36693 }
36694 pub fn push_lmax(mut self, value: u32) -> Self {
36695 push_header(self.as_vec_mut(), 2u16, 4 as u16);
36696 self.as_vec_mut().extend(value.to_ne_bytes());
36697 self
36698 }
36699}
36700impl<Prev: Pusher> Drop for PushQfqAttrs<Prev> {
36701 fn drop(&mut self) {
36702 if let Some(prev) = &mut self.prev {
36703 if let Some(header_offset) = &self.header_offset {
36704 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36705 }
36706 }
36707 }
36708}
36709pub struct PushRedAttrs<Prev: Pusher> {
36710 pub(crate) prev: Option<Prev>,
36711 pub(crate) header_offset: Option<usize>,
36712}
36713impl<Prev: Pusher> Pusher for PushRedAttrs<Prev> {
36714 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36715 self.prev.as_mut().unwrap().as_vec_mut()
36716 }
36717 fn as_vec(&self) -> &Vec<u8> {
36718 self.prev.as_ref().unwrap().as_vec()
36719 }
36720}
36721impl<Prev: Pusher> PushRedAttrs<Prev> {
36722 pub fn new(prev: Prev) -> Self {
36723 Self {
36724 prev: Some(prev),
36725 header_offset: None,
36726 }
36727 }
36728 pub fn end_nested(mut self) -> Prev {
36729 let mut prev = self.prev.take().unwrap();
36730 if let Some(header_offset) = &self.header_offset {
36731 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36732 }
36733 prev
36734 }
36735 pub fn push_parms(mut self, value: TcRedQopt) -> Self {
36736 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
36737 self.as_vec_mut().extend(value.as_slice());
36738 self
36739 }
36740 pub fn push_stab(mut self, value: &[u8]) -> Self {
36741 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
36742 self.as_vec_mut().extend(value);
36743 self
36744 }
36745 pub fn push_max_p(mut self, value: u32) -> Self {
36746 push_header(self.as_vec_mut(), 3u16, 4 as u16);
36747 self.as_vec_mut().extend(value.to_ne_bytes());
36748 self
36749 }
36750 pub fn push_flags(mut self, value: BuiltinBitfield32) -> Self {
36751 push_header(self.as_vec_mut(), 4u16, value.as_slice().len() as u16);
36752 self.as_vec_mut().extend(value.as_slice());
36753 self
36754 }
36755 pub fn push_early_drop_block(mut self, value: u32) -> Self {
36756 push_header(self.as_vec_mut(), 5u16, 4 as u16);
36757 self.as_vec_mut().extend(value.to_ne_bytes());
36758 self
36759 }
36760 pub fn push_mark_block(mut self, value: u32) -> Self {
36761 push_header(self.as_vec_mut(), 6u16, 4 as u16);
36762 self.as_vec_mut().extend(value.to_ne_bytes());
36763 self
36764 }
36765}
36766impl<Prev: Pusher> Drop for PushRedAttrs<Prev> {
36767 fn drop(&mut self) {
36768 if let Some(prev) = &mut self.prev {
36769 if let Some(header_offset) = &self.header_offset {
36770 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36771 }
36772 }
36773 }
36774}
36775pub struct PushRouteAttrs<Prev: Pusher> {
36776 pub(crate) prev: Option<Prev>,
36777 pub(crate) header_offset: Option<usize>,
36778}
36779impl<Prev: Pusher> Pusher for PushRouteAttrs<Prev> {
36780 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36781 self.prev.as_mut().unwrap().as_vec_mut()
36782 }
36783 fn as_vec(&self) -> &Vec<u8> {
36784 self.prev.as_ref().unwrap().as_vec()
36785 }
36786}
36787impl<Prev: Pusher> PushRouteAttrs<Prev> {
36788 pub fn new(prev: Prev) -> Self {
36789 Self {
36790 prev: Some(prev),
36791 header_offset: None,
36792 }
36793 }
36794 pub fn end_nested(mut self) -> Prev {
36795 let mut prev = self.prev.take().unwrap();
36796 if let Some(header_offset) = &self.header_offset {
36797 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36798 }
36799 prev
36800 }
36801 pub fn push_classid(mut self, value: u32) -> Self {
36802 push_header(self.as_vec_mut(), 1u16, 4 as u16);
36803 self.as_vec_mut().extend(value.to_ne_bytes());
36804 self
36805 }
36806 pub fn push_to(mut self, value: u32) -> Self {
36807 push_header(self.as_vec_mut(), 2u16, 4 as u16);
36808 self.as_vec_mut().extend(value.to_ne_bytes());
36809 self
36810 }
36811 pub fn push_from(mut self, value: u32) -> Self {
36812 push_header(self.as_vec_mut(), 3u16, 4 as u16);
36813 self.as_vec_mut().extend(value.to_ne_bytes());
36814 self
36815 }
36816 pub fn push_iif(mut self, value: u32) -> Self {
36817 push_header(self.as_vec_mut(), 4u16, 4 as u16);
36818 self.as_vec_mut().extend(value.to_ne_bytes());
36819 self
36820 }
36821 pub fn nested_police(mut self) -> PushPoliceAttrs<Self> {
36822 let header_offset = push_nested_header(self.as_vec_mut(), 5u16);
36823 PushPoliceAttrs {
36824 prev: Some(self),
36825 header_offset: Some(header_offset),
36826 }
36827 }
36828 pub fn array_act(mut self) -> PushArrayActAttrs<Self> {
36829 let header_offset = push_nested_header(self.as_vec_mut(), 6u16);
36830 PushArrayActAttrs {
36831 prev: Some(self),
36832 header_offset: Some(header_offset),
36833 counter: 0,
36834 }
36835 }
36836}
36837impl<Prev: Pusher> Drop for PushRouteAttrs<Prev> {
36838 fn drop(&mut self) {
36839 if let Some(prev) = &mut self.prev {
36840 if let Some(header_offset) = &self.header_offset {
36841 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36842 }
36843 }
36844 }
36845}
36846pub struct PushTaprioAttrs<Prev: Pusher> {
36847 pub(crate) prev: Option<Prev>,
36848 pub(crate) header_offset: Option<usize>,
36849}
36850impl<Prev: Pusher> Pusher for PushTaprioAttrs<Prev> {
36851 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36852 self.prev.as_mut().unwrap().as_vec_mut()
36853 }
36854 fn as_vec(&self) -> &Vec<u8> {
36855 self.prev.as_ref().unwrap().as_vec()
36856 }
36857}
36858impl<Prev: Pusher> PushTaprioAttrs<Prev> {
36859 pub fn new(prev: Prev) -> Self {
36860 Self {
36861 prev: Some(prev),
36862 header_offset: None,
36863 }
36864 }
36865 pub fn end_nested(mut self) -> Prev {
36866 let mut prev = self.prev.take().unwrap();
36867 if let Some(header_offset) = &self.header_offset {
36868 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36869 }
36870 prev
36871 }
36872 pub fn push_priomap(mut self, value: TcMqprioQopt) -> Self {
36873 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
36874 self.as_vec_mut().extend(value.as_slice());
36875 self
36876 }
36877 pub fn nested_sched_entry_list(mut self) -> PushTaprioSchedEntryList<Self> {
36878 let header_offset = push_nested_header(self.as_vec_mut(), 2u16);
36879 PushTaprioSchedEntryList {
36880 prev: Some(self),
36881 header_offset: Some(header_offset),
36882 }
36883 }
36884 pub fn push_sched_base_time(mut self, value: i64) -> Self {
36885 push_header(self.as_vec_mut(), 3u16, 8 as u16);
36886 self.as_vec_mut().extend(value.to_ne_bytes());
36887 self
36888 }
36889 pub fn nested_sched_single_entry(mut self) -> PushTaprioSchedEntry<Self> {
36890 let header_offset = push_nested_header(self.as_vec_mut(), 4u16);
36891 PushTaprioSchedEntry {
36892 prev: Some(self),
36893 header_offset: Some(header_offset),
36894 }
36895 }
36896 pub fn push_sched_clockid(mut self, value: i32) -> Self {
36897 push_header(self.as_vec_mut(), 5u16, 4 as u16);
36898 self.as_vec_mut().extend(value.to_ne_bytes());
36899 self
36900 }
36901 pub fn push_pad(mut self, value: &[u8]) -> Self {
36902 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
36903 self.as_vec_mut().extend(value);
36904 self
36905 }
36906 pub fn push_admin_sched(mut self, value: &[u8]) -> Self {
36907 push_header(self.as_vec_mut(), 7u16, value.len() as u16);
36908 self.as_vec_mut().extend(value);
36909 self
36910 }
36911 pub fn push_sched_cycle_time(mut self, value: i64) -> Self {
36912 push_header(self.as_vec_mut(), 8u16, 8 as u16);
36913 self.as_vec_mut().extend(value.to_ne_bytes());
36914 self
36915 }
36916 pub fn push_sched_cycle_time_extension(mut self, value: i64) -> Self {
36917 push_header(self.as_vec_mut(), 9u16, 8 as u16);
36918 self.as_vec_mut().extend(value.to_ne_bytes());
36919 self
36920 }
36921 pub fn push_flags(mut self, value: u32) -> Self {
36922 push_header(self.as_vec_mut(), 10u16, 4 as u16);
36923 self.as_vec_mut().extend(value.to_ne_bytes());
36924 self
36925 }
36926 pub fn push_txtime_delay(mut self, value: u32) -> Self {
36927 push_header(self.as_vec_mut(), 11u16, 4 as u16);
36928 self.as_vec_mut().extend(value.to_ne_bytes());
36929 self
36930 }
36931 pub fn nested_tc_entry(mut self) -> PushTaprioTcEntryAttrs<Self> {
36932 let header_offset = push_nested_header(self.as_vec_mut(), 12u16);
36933 PushTaprioTcEntryAttrs {
36934 prev: Some(self),
36935 header_offset: Some(header_offset),
36936 }
36937 }
36938}
36939impl<Prev: Pusher> Drop for PushTaprioAttrs<Prev> {
36940 fn drop(&mut self) {
36941 if let Some(prev) = &mut self.prev {
36942 if let Some(header_offset) = &self.header_offset {
36943 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36944 }
36945 }
36946 }
36947}
36948pub struct PushTaprioSchedEntryList<Prev: Pusher> {
36949 pub(crate) prev: Option<Prev>,
36950 pub(crate) header_offset: Option<usize>,
36951}
36952impl<Prev: Pusher> Pusher for PushTaprioSchedEntryList<Prev> {
36953 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36954 self.prev.as_mut().unwrap().as_vec_mut()
36955 }
36956 fn as_vec(&self) -> &Vec<u8> {
36957 self.prev.as_ref().unwrap().as_vec()
36958 }
36959}
36960impl<Prev: Pusher> PushTaprioSchedEntryList<Prev> {
36961 pub fn new(prev: Prev) -> Self {
36962 Self {
36963 prev: Some(prev),
36964 header_offset: None,
36965 }
36966 }
36967 pub fn end_nested(mut self) -> Prev {
36968 let mut prev = self.prev.take().unwrap();
36969 if let Some(header_offset) = &self.header_offset {
36970 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36971 }
36972 prev
36973 }
36974 #[doc = "Attribute may repeat multiple times (treat it as array)"]
36975 pub fn nested_entry(mut self) -> PushTaprioSchedEntry<Self> {
36976 let header_offset = push_nested_header(self.as_vec_mut(), 1u16);
36977 PushTaprioSchedEntry {
36978 prev: Some(self),
36979 header_offset: Some(header_offset),
36980 }
36981 }
36982}
36983impl<Prev: Pusher> Drop for PushTaprioSchedEntryList<Prev> {
36984 fn drop(&mut self) {
36985 if let Some(prev) = &mut self.prev {
36986 if let Some(header_offset) = &self.header_offset {
36987 finalize_nested_header(prev.as_vec_mut(), *header_offset);
36988 }
36989 }
36990 }
36991}
36992pub struct PushTaprioSchedEntry<Prev: Pusher> {
36993 pub(crate) prev: Option<Prev>,
36994 pub(crate) header_offset: Option<usize>,
36995}
36996impl<Prev: Pusher> Pusher for PushTaprioSchedEntry<Prev> {
36997 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
36998 self.prev.as_mut().unwrap().as_vec_mut()
36999 }
37000 fn as_vec(&self) -> &Vec<u8> {
37001 self.prev.as_ref().unwrap().as_vec()
37002 }
37003}
37004impl<Prev: Pusher> PushTaprioSchedEntry<Prev> {
37005 pub fn new(prev: Prev) -> Self {
37006 Self {
37007 prev: Some(prev),
37008 header_offset: None,
37009 }
37010 }
37011 pub fn end_nested(mut self) -> Prev {
37012 let mut prev = self.prev.take().unwrap();
37013 if let Some(header_offset) = &self.header_offset {
37014 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37015 }
37016 prev
37017 }
37018 pub fn push_index(mut self, value: u32) -> Self {
37019 push_header(self.as_vec_mut(), 1u16, 4 as u16);
37020 self.as_vec_mut().extend(value.to_ne_bytes());
37021 self
37022 }
37023 pub fn push_cmd(mut self, value: u8) -> Self {
37024 push_header(self.as_vec_mut(), 2u16, 1 as u16);
37025 self.as_vec_mut().extend(value.to_ne_bytes());
37026 self
37027 }
37028 pub fn push_gate_mask(mut self, value: u32) -> Self {
37029 push_header(self.as_vec_mut(), 3u16, 4 as u16);
37030 self.as_vec_mut().extend(value.to_ne_bytes());
37031 self
37032 }
37033 pub fn push_interval(mut self, value: u32) -> Self {
37034 push_header(self.as_vec_mut(), 4u16, 4 as u16);
37035 self.as_vec_mut().extend(value.to_ne_bytes());
37036 self
37037 }
37038}
37039impl<Prev: Pusher> Drop for PushTaprioSchedEntry<Prev> {
37040 fn drop(&mut self) {
37041 if let Some(prev) = &mut self.prev {
37042 if let Some(header_offset) = &self.header_offset {
37043 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37044 }
37045 }
37046 }
37047}
37048pub struct PushTaprioTcEntryAttrs<Prev: Pusher> {
37049 pub(crate) prev: Option<Prev>,
37050 pub(crate) header_offset: Option<usize>,
37051}
37052impl<Prev: Pusher> Pusher for PushTaprioTcEntryAttrs<Prev> {
37053 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
37054 self.prev.as_mut().unwrap().as_vec_mut()
37055 }
37056 fn as_vec(&self) -> &Vec<u8> {
37057 self.prev.as_ref().unwrap().as_vec()
37058 }
37059}
37060impl<Prev: Pusher> PushTaprioTcEntryAttrs<Prev> {
37061 pub fn new(prev: Prev) -> Self {
37062 Self {
37063 prev: Some(prev),
37064 header_offset: None,
37065 }
37066 }
37067 pub fn end_nested(mut self) -> Prev {
37068 let mut prev = self.prev.take().unwrap();
37069 if let Some(header_offset) = &self.header_offset {
37070 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37071 }
37072 prev
37073 }
37074 pub fn push_index(mut self, value: u32) -> Self {
37075 push_header(self.as_vec_mut(), 1u16, 4 as u16);
37076 self.as_vec_mut().extend(value.to_ne_bytes());
37077 self
37078 }
37079 pub fn push_max_sdu(mut self, value: u32) -> Self {
37080 push_header(self.as_vec_mut(), 2u16, 4 as u16);
37081 self.as_vec_mut().extend(value.to_ne_bytes());
37082 self
37083 }
37084 pub fn push_fp(mut self, value: u32) -> Self {
37085 push_header(self.as_vec_mut(), 3u16, 4 as u16);
37086 self.as_vec_mut().extend(value.to_ne_bytes());
37087 self
37088 }
37089}
37090impl<Prev: Pusher> Drop for PushTaprioTcEntryAttrs<Prev> {
37091 fn drop(&mut self) {
37092 if let Some(prev) = &mut self.prev {
37093 if let Some(header_offset) = &self.header_offset {
37094 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37095 }
37096 }
37097 }
37098}
37099pub struct PushTbfAttrs<Prev: Pusher> {
37100 pub(crate) prev: Option<Prev>,
37101 pub(crate) header_offset: Option<usize>,
37102}
37103impl<Prev: Pusher> Pusher for PushTbfAttrs<Prev> {
37104 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
37105 self.prev.as_mut().unwrap().as_vec_mut()
37106 }
37107 fn as_vec(&self) -> &Vec<u8> {
37108 self.prev.as_ref().unwrap().as_vec()
37109 }
37110}
37111impl<Prev: Pusher> PushTbfAttrs<Prev> {
37112 pub fn new(prev: Prev) -> Self {
37113 Self {
37114 prev: Some(prev),
37115 header_offset: None,
37116 }
37117 }
37118 pub fn end_nested(mut self) -> Prev {
37119 let mut prev = self.prev.take().unwrap();
37120 if let Some(header_offset) = &self.header_offset {
37121 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37122 }
37123 prev
37124 }
37125 pub fn push_parms(mut self, value: TcTbfQopt) -> Self {
37126 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
37127 self.as_vec_mut().extend(value.as_slice());
37128 self
37129 }
37130 pub fn push_rtab(mut self, value: &[u8]) -> Self {
37131 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
37132 self.as_vec_mut().extend(value);
37133 self
37134 }
37135 pub fn push_ptab(mut self, value: &[u8]) -> Self {
37136 push_header(self.as_vec_mut(), 3u16, value.len() as u16);
37137 self.as_vec_mut().extend(value);
37138 self
37139 }
37140 pub fn push_rate64(mut self, value: u64) -> Self {
37141 push_header(self.as_vec_mut(), 4u16, 8 as u16);
37142 self.as_vec_mut().extend(value.to_ne_bytes());
37143 self
37144 }
37145 pub fn push_prate64(mut self, value: u64) -> Self {
37146 push_header(self.as_vec_mut(), 5u16, 8 as u16);
37147 self.as_vec_mut().extend(value.to_ne_bytes());
37148 self
37149 }
37150 pub fn push_burst(mut self, value: u32) -> Self {
37151 push_header(self.as_vec_mut(), 6u16, 4 as u16);
37152 self.as_vec_mut().extend(value.to_ne_bytes());
37153 self
37154 }
37155 pub fn push_pburst(mut self, value: u32) -> Self {
37156 push_header(self.as_vec_mut(), 7u16, 4 as u16);
37157 self.as_vec_mut().extend(value.to_ne_bytes());
37158 self
37159 }
37160 pub fn push_pad(mut self, value: &[u8]) -> Self {
37161 push_header(self.as_vec_mut(), 8u16, value.len() as u16);
37162 self.as_vec_mut().extend(value);
37163 self
37164 }
37165}
37166impl<Prev: Pusher> Drop for PushTbfAttrs<Prev> {
37167 fn drop(&mut self) {
37168 if let Some(prev) = &mut self.prev {
37169 if let Some(header_offset) = &self.header_offset {
37170 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37171 }
37172 }
37173 }
37174}
37175pub struct PushActSampleAttrs<Prev: Pusher> {
37176 pub(crate) prev: Option<Prev>,
37177 pub(crate) header_offset: Option<usize>,
37178}
37179impl<Prev: Pusher> Pusher for PushActSampleAttrs<Prev> {
37180 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
37181 self.prev.as_mut().unwrap().as_vec_mut()
37182 }
37183 fn as_vec(&self) -> &Vec<u8> {
37184 self.prev.as_ref().unwrap().as_vec()
37185 }
37186}
37187impl<Prev: Pusher> PushActSampleAttrs<Prev> {
37188 pub fn new(prev: Prev) -> Self {
37189 Self {
37190 prev: Some(prev),
37191 header_offset: None,
37192 }
37193 }
37194 pub fn end_nested(mut self) -> Prev {
37195 let mut prev = self.prev.take().unwrap();
37196 if let Some(header_offset) = &self.header_offset {
37197 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37198 }
37199 prev
37200 }
37201 pub fn push_tm(mut self, value: TcfT) -> Self {
37202 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
37203 self.as_vec_mut().extend(value.as_slice());
37204 self
37205 }
37206 pub fn push_parms(mut self, value: TcGact) -> Self {
37207 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
37208 self.as_vec_mut().extend(value.as_slice());
37209 self
37210 }
37211 pub fn push_rate(mut self, value: u32) -> Self {
37212 push_header(self.as_vec_mut(), 3u16, 4 as u16);
37213 self.as_vec_mut().extend(value.to_ne_bytes());
37214 self
37215 }
37216 pub fn push_trunc_size(mut self, value: u32) -> Self {
37217 push_header(self.as_vec_mut(), 4u16, 4 as u16);
37218 self.as_vec_mut().extend(value.to_ne_bytes());
37219 self
37220 }
37221 pub fn push_psample_group(mut self, value: u32) -> Self {
37222 push_header(self.as_vec_mut(), 5u16, 4 as u16);
37223 self.as_vec_mut().extend(value.to_ne_bytes());
37224 self
37225 }
37226 pub fn push_pad(mut self, value: &[u8]) -> Self {
37227 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
37228 self.as_vec_mut().extend(value);
37229 self
37230 }
37231}
37232impl<Prev: Pusher> Drop for PushActSampleAttrs<Prev> {
37233 fn drop(&mut self) {
37234 if let Some(prev) = &mut self.prev {
37235 if let Some(header_offset) = &self.header_offset {
37236 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37237 }
37238 }
37239 }
37240}
37241pub struct PushActGactAttrs<Prev: Pusher> {
37242 pub(crate) prev: Option<Prev>,
37243 pub(crate) header_offset: Option<usize>,
37244}
37245impl<Prev: Pusher> Pusher for PushActGactAttrs<Prev> {
37246 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
37247 self.prev.as_mut().unwrap().as_vec_mut()
37248 }
37249 fn as_vec(&self) -> &Vec<u8> {
37250 self.prev.as_ref().unwrap().as_vec()
37251 }
37252}
37253impl<Prev: Pusher> PushActGactAttrs<Prev> {
37254 pub fn new(prev: Prev) -> Self {
37255 Self {
37256 prev: Some(prev),
37257 header_offset: None,
37258 }
37259 }
37260 pub fn end_nested(mut self) -> Prev {
37261 let mut prev = self.prev.take().unwrap();
37262 if let Some(header_offset) = &self.header_offset {
37263 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37264 }
37265 prev
37266 }
37267 pub fn push_tm(mut self, value: TcfT) -> Self {
37268 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
37269 self.as_vec_mut().extend(value.as_slice());
37270 self
37271 }
37272 pub fn push_parms(mut self, value: TcGact) -> Self {
37273 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
37274 self.as_vec_mut().extend(value.as_slice());
37275 self
37276 }
37277 pub fn push_prob(mut self, value: TcGactP) -> Self {
37278 push_header(self.as_vec_mut(), 3u16, value.as_slice().len() as u16);
37279 self.as_vec_mut().extend(value.as_slice());
37280 self
37281 }
37282 pub fn push_pad(mut self, value: &[u8]) -> Self {
37283 push_header(self.as_vec_mut(), 4u16, value.len() as u16);
37284 self.as_vec_mut().extend(value);
37285 self
37286 }
37287}
37288impl<Prev: Pusher> Drop for PushActGactAttrs<Prev> {
37289 fn drop(&mut self) {
37290 if let Some(prev) = &mut self.prev {
37291 if let Some(header_offset) = &self.header_offset {
37292 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37293 }
37294 }
37295 }
37296}
37297pub struct PushTcaStabAttrs<Prev: Pusher> {
37298 pub(crate) prev: Option<Prev>,
37299 pub(crate) header_offset: Option<usize>,
37300}
37301impl<Prev: Pusher> Pusher for PushTcaStabAttrs<Prev> {
37302 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
37303 self.prev.as_mut().unwrap().as_vec_mut()
37304 }
37305 fn as_vec(&self) -> &Vec<u8> {
37306 self.prev.as_ref().unwrap().as_vec()
37307 }
37308}
37309impl<Prev: Pusher> PushTcaStabAttrs<Prev> {
37310 pub fn new(prev: Prev) -> Self {
37311 Self {
37312 prev: Some(prev),
37313 header_offset: None,
37314 }
37315 }
37316 pub fn end_nested(mut self) -> Prev {
37317 let mut prev = self.prev.take().unwrap();
37318 if let Some(header_offset) = &self.header_offset {
37319 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37320 }
37321 prev
37322 }
37323 pub fn push_base(mut self, value: TcSizespec) -> Self {
37324 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
37325 self.as_vec_mut().extend(value.as_slice());
37326 self
37327 }
37328 pub fn push_data(mut self, value: &[u8]) -> Self {
37329 push_header(self.as_vec_mut(), 2u16, value.len() as u16);
37330 self.as_vec_mut().extend(value);
37331 self
37332 }
37333}
37334impl<Prev: Pusher> Drop for PushTcaStabAttrs<Prev> {
37335 fn drop(&mut self) {
37336 if let Some(prev) = &mut self.prev {
37337 if let Some(header_offset) = &self.header_offset {
37338 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37339 }
37340 }
37341 }
37342}
37343pub struct PushTcaStatsAttrs<Prev: Pusher> {
37344 pub(crate) prev: Option<Prev>,
37345 pub(crate) header_offset: Option<usize>,
37346}
37347impl<Prev: Pusher> Pusher for PushTcaStatsAttrs<Prev> {
37348 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
37349 self.prev.as_mut().unwrap().as_vec_mut()
37350 }
37351 fn as_vec(&self) -> &Vec<u8> {
37352 self.prev.as_ref().unwrap().as_vec()
37353 }
37354}
37355impl<Prev: Pusher> PushTcaStatsAttrs<Prev> {
37356 pub fn new(prev: Prev) -> Self {
37357 Self {
37358 prev: Some(prev),
37359 header_offset: None,
37360 }
37361 }
37362 pub fn end_nested(mut self) -> Prev {
37363 let mut prev = self.prev.take().unwrap();
37364 if let Some(header_offset) = &self.header_offset {
37365 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37366 }
37367 prev
37368 }
37369 pub fn push_basic(mut self, value: GnetStatsBasic) -> Self {
37370 push_header(self.as_vec_mut(), 1u16, value.as_slice().len() as u16);
37371 self.as_vec_mut().extend(value.as_slice());
37372 self
37373 }
37374 pub fn push_rate_est(mut self, value: GnetStatsRateEst) -> Self {
37375 push_header(self.as_vec_mut(), 2u16, value.as_slice().len() as u16);
37376 self.as_vec_mut().extend(value.as_slice());
37377 self
37378 }
37379 pub fn push_queue(mut self, value: GnetStatsQueue) -> Self {
37380 push_header(self.as_vec_mut(), 3u16, value.as_slice().len() as u16);
37381 self.as_vec_mut().extend(value.as_slice());
37382 self
37383 }
37384 pub fn push_rate_est64(mut self, value: GnetStatsRateEst64) -> Self {
37385 push_header(self.as_vec_mut(), 5u16, value.as_slice().len() as u16);
37386 self.as_vec_mut().extend(value.as_slice());
37387 self
37388 }
37389 pub fn push_pad(mut self, value: &[u8]) -> Self {
37390 push_header(self.as_vec_mut(), 6u16, value.len() as u16);
37391 self.as_vec_mut().extend(value);
37392 self
37393 }
37394 pub fn push_basic_hw(mut self, value: GnetStatsBasic) -> Self {
37395 push_header(self.as_vec_mut(), 7u16, value.as_slice().len() as u16);
37396 self.as_vec_mut().extend(value.as_slice());
37397 self
37398 }
37399 pub fn push_pkt64(mut self, value: u64) -> Self {
37400 push_header(self.as_vec_mut(), 8u16, 8 as u16);
37401 self.as_vec_mut().extend(value.to_ne_bytes());
37402 self
37403 }
37404}
37405impl<Prev: Pusher> Drop for PushTcaStatsAttrs<Prev> {
37406 fn drop(&mut self) {
37407 if let Some(prev) = &mut self.prev {
37408 if let Some(header_offset) = &self.header_offset {
37409 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37410 }
37411 }
37412 }
37413}
37414pub struct PushU32Attrs<Prev: Pusher> {
37415 pub(crate) prev: Option<Prev>,
37416 pub(crate) header_offset: Option<usize>,
37417}
37418impl<Prev: Pusher> Pusher for PushU32Attrs<Prev> {
37419 fn as_vec_mut(&mut self) -> &mut Vec<u8> {
37420 self.prev.as_mut().unwrap().as_vec_mut()
37421 }
37422 fn as_vec(&self) -> &Vec<u8> {
37423 self.prev.as_ref().unwrap().as_vec()
37424 }
37425}
37426impl<Prev: Pusher> PushU32Attrs<Prev> {
37427 pub fn new(prev: Prev) -> Self {
37428 Self {
37429 prev: Some(prev),
37430 header_offset: None,
37431 }
37432 }
37433 pub fn end_nested(mut self) -> Prev {
37434 let mut prev = self.prev.take().unwrap();
37435 if let Some(header_offset) = &self.header_offset {
37436 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37437 }
37438 prev
37439 }
37440 pub fn push_classid(mut self, value: u32) -> Self {
37441 push_header(self.as_vec_mut(), 1u16, 4 as u16);
37442 self.as_vec_mut().extend(value.to_ne_bytes());
37443 self
37444 }
37445 pub fn push_hash(mut self, value: u32) -> Self {
37446 push_header(self.as_vec_mut(), 2u16, 4 as u16);
37447 self.as_vec_mut().extend(value.to_ne_bytes());
37448 self
37449 }
37450 pub fn push_link(mut self, value: u32) -> Self {
37451 push_header(self.as_vec_mut(), 3u16, 4 as u16);
37452 self.as_vec_mut().extend(value.to_ne_bytes());
37453 self
37454 }
37455 pub fn push_divisor(mut self, value: u32) -> Self {
37456 push_header(self.as_vec_mut(), 4u16, 4 as u16);
37457 self.as_vec_mut().extend(value.to_ne_bytes());
37458 self
37459 }
37460 pub fn push_sel(mut self, value: TcU32Sel) -> Self {
37461 push_header(self.as_vec_mut(), 5u16, value.as_slice().len() as u16);
37462 self.as_vec_mut().extend(value.as_slice());
37463 self
37464 }
37465 pub fn nested_police(mut self) -> PushPoliceAttrs<Self> {
37466 let header_offset = push_nested_header(self.as_vec_mut(), 6u16);
37467 PushPoliceAttrs {
37468 prev: Some(self),
37469 header_offset: Some(header_offset),
37470 }
37471 }
37472 pub fn array_act(mut self) -> PushArrayActAttrs<Self> {
37473 let header_offset = push_nested_header(self.as_vec_mut(), 7u16);
37474 PushArrayActAttrs {
37475 prev: Some(self),
37476 header_offset: Some(header_offset),
37477 counter: 0,
37478 }
37479 }
37480 pub fn push_indev(mut self, value: &CStr) -> Self {
37481 push_header(
37482 self.as_vec_mut(),
37483 8u16,
37484 value.to_bytes_with_nul().len() as u16,
37485 );
37486 self.as_vec_mut().extend(value.to_bytes_with_nul());
37487 self
37488 }
37489 pub fn push_indev_bytes(mut self, value: &[u8]) -> Self {
37490 push_header(self.as_vec_mut(), 8u16, (value.len() + 1) as u16);
37491 self.as_vec_mut().extend(value);
37492 self.as_vec_mut().push(0);
37493 self
37494 }
37495 pub fn push_pcnt(mut self, value: TcU32Pcnt) -> Self {
37496 push_header(self.as_vec_mut(), 9u16, value.as_slice().len() as u16);
37497 self.as_vec_mut().extend(value.as_slice());
37498 self
37499 }
37500 pub fn push_mark(mut self, value: TcU32Mark) -> Self {
37501 push_header(self.as_vec_mut(), 10u16, value.as_slice().len() as u16);
37502 self.as_vec_mut().extend(value.as_slice());
37503 self
37504 }
37505 pub fn push_flags(mut self, value: u32) -> Self {
37506 push_header(self.as_vec_mut(), 11u16, 4 as u16);
37507 self.as_vec_mut().extend(value.to_ne_bytes());
37508 self
37509 }
37510 pub fn push_pad(mut self, value: &[u8]) -> Self {
37511 push_header(self.as_vec_mut(), 12u16, value.len() as u16);
37512 self.as_vec_mut().extend(value);
37513 self
37514 }
37515}
37516impl<Prev: Pusher> Drop for PushU32Attrs<Prev> {
37517 fn drop(&mut self) {
37518 if let Some(prev) = &mut self.prev {
37519 if let Some(header_offset) = &self.header_offset {
37520 finalize_nested_header(prev.as_vec_mut(), *header_offset);
37521 }
37522 }
37523 }
37524}
37525#[doc = "Create new tc qdisc.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.nested_options_basic()](PushAttrs::nested_options_basic)\n- [.nested_options_bpf()](PushAttrs::nested_options_bpf)\n- [.nested_options_bfifo()](PushAttrs::nested_options_bfifo)\n- [.nested_options_cake()](PushAttrs::nested_options_cake)\n- [.nested_options_cbs()](PushAttrs::nested_options_cbs)\n- [.nested_options_cgroup()](PushAttrs::nested_options_cgroup)\n- [.nested_options_choke()](PushAttrs::nested_options_choke)\n- [.nested_options_clsact()](PushAttrs::nested_options_clsact)\n- [.nested_options_codel()](PushAttrs::nested_options_codel)\n- [.nested_options_drr()](PushAttrs::nested_options_drr)\n- [.nested_options_dualpi2()](PushAttrs::nested_options_dualpi2)\n- [.nested_options_etf()](PushAttrs::nested_options_etf)\n- [.nested_options_ets()](PushAttrs::nested_options_ets)\n- [.nested_options_flow()](PushAttrs::nested_options_flow)\n- [.nested_options_flower()](PushAttrs::nested_options_flower)\n- [.nested_options_fq()](PushAttrs::nested_options_fq)\n- [.nested_options_fq_codel()](PushAttrs::nested_options_fq_codel)\n- [.nested_options_fq_pie()](PushAttrs::nested_options_fq_pie)\n- [.nested_options_fw()](PushAttrs::nested_options_fw)\n- [.nested_options_gred()](PushAttrs::nested_options_gred)\n- [.nested_options_hfsc()](PushAttrs::nested_options_hfsc)\n- [.nested_options_hhf()](PushAttrs::nested_options_hhf)\n- [.nested_options_htb()](PushAttrs::nested_options_htb)\n- [.nested_options_ingress()](PushAttrs::nested_options_ingress)\n- [.nested_options_matchall()](PushAttrs::nested_options_matchall)\n- [.nested_options_mq()](PushAttrs::nested_options_mq)\n- [.nested_options_mqprio()](PushAttrs::nested_options_mqprio)\n- [.nested_options_multiq()](PushAttrs::nested_options_multiq)\n- [.nested_options_netem()](PushAttrs::nested_options_netem)\n- [.nested_options_pfifo()](PushAttrs::nested_options_pfifo)\n- [.nested_options_pfifo_fast()](PushAttrs::nested_options_pfifo_fast)\n- [.nested_options_pfifo_head_drop()](PushAttrs::nested_options_pfifo_head_drop)\n- [.nested_options_pie()](PushAttrs::nested_options_pie)\n- [.nested_options_plug()](PushAttrs::nested_options_plug)\n- [.nested_options_prio()](PushAttrs::nested_options_prio)\n- [.nested_options_qfq()](PushAttrs::nested_options_qfq)\n- [.nested_options_red()](PushAttrs::nested_options_red)\n- [.nested_options_route()](PushAttrs::nested_options_route)\n- [.nested_options_sfb()](PushAttrs::nested_options_sfb)\n- [.nested_options_sfq()](PushAttrs::nested_options_sfq)\n- [.nested_options_taprio()](PushAttrs::nested_options_taprio)\n- [.nested_options_tbf()](PushAttrs::nested_options_tbf)\n- [.nested_options_u32()](PushAttrs::nested_options_u32)\n- [.push_rate()](PushAttrs::push_rate)\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_ingress_block()](PushAttrs::push_ingress_block)\n- [.push_egress_block()](PushAttrs::push_egress_block)\n\n"]
37526#[derive(Debug)]
37527pub struct OpNewqdiscDo<'r> {
37528 request: Request<'r>,
37529}
37530impl<'r> OpNewqdiscDo<'r> {
37531 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
37532 Self::write_header(request.buf_mut(), header);
37533 Self { request: request }
37534 }
37535 pub fn encode_request<'buf>(
37536 buf: &'buf mut Vec<u8>,
37537 header: &Tcmsg,
37538 ) -> PushAttrs<&'buf mut Vec<u8>> {
37539 Self::write_header(buf, header);
37540 PushAttrs::new(buf)
37541 }
37542 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
37543 PushAttrs::new(self.request.buf_mut())
37544 }
37545 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
37546 PushAttrs::new(self.request.buf)
37547 }
37548 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
37549 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
37550 (
37551 Tcmsg::new_from_slice(header).unwrap_or_default(),
37552 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
37553 )
37554 }
37555 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
37556 prev.as_vec_mut().extend(header.as_slice());
37557 }
37558}
37559impl NetlinkRequest for OpNewqdiscDo<'_> {
37560 fn protocol(&self) -> Protocol {
37561 Protocol::Raw {
37562 protonum: 0u16,
37563 request_type: 36u16,
37564 }
37565 }
37566 fn flags(&self) -> u16 {
37567 self.request.flags
37568 }
37569 fn payload(&self) -> &[u8] {
37570 self.request.buf()
37571 }
37572 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
37573 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
37574 Self::decode_request(buf)
37575 }
37576 fn lookup(
37577 buf: &[u8],
37578 offset: usize,
37579 missing_type: Option<u16>,
37580 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37581 Self::decode_request(buf)
37582 .1
37583 .lookup_attr(offset, missing_type)
37584 }
37585}
37586#[doc = "Delete existing tc qdisc.\n\n"]
37587#[derive(Debug)]
37588pub struct OpDelqdiscDo<'r> {
37589 request: Request<'r>,
37590}
37591impl<'r> OpDelqdiscDo<'r> {
37592 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
37593 Self::write_header(request.buf_mut(), header);
37594 Self { request: request }
37595 }
37596 pub fn encode_request<'buf>(
37597 buf: &'buf mut Vec<u8>,
37598 header: &Tcmsg,
37599 ) -> PushAttrs<&'buf mut Vec<u8>> {
37600 Self::write_header(buf, header);
37601 PushAttrs::new(buf)
37602 }
37603 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
37604 PushAttrs::new(self.request.buf_mut())
37605 }
37606 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
37607 PushAttrs::new(self.request.buf)
37608 }
37609 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
37610 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
37611 (
37612 Tcmsg::new_from_slice(header).unwrap_or_default(),
37613 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
37614 )
37615 }
37616 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
37617 prev.as_vec_mut().extend(header.as_slice());
37618 }
37619}
37620impl NetlinkRequest for OpDelqdiscDo<'_> {
37621 fn protocol(&self) -> Protocol {
37622 Protocol::Raw {
37623 protonum: 0u16,
37624 request_type: 37u16,
37625 }
37626 }
37627 fn flags(&self) -> u16 {
37628 self.request.flags
37629 }
37630 fn payload(&self) -> &[u8] {
37631 self.request.buf()
37632 }
37633 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
37634 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
37635 Self::decode_request(buf)
37636 }
37637 fn lookup(
37638 buf: &[u8],
37639 offset: usize,
37640 missing_type: Option<u16>,
37641 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37642 Self::decode_request(buf)
37643 .1
37644 .lookup_attr(offset, missing_type)
37645 }
37646}
37647#[doc = "Get / dump tc qdisc information.\n\nRequest attributes:\n- [.push_dump_invisible()](PushAttrs::push_dump_invisible)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
37648#[derive(Debug)]
37649pub struct OpGetqdiscDump<'r> {
37650 request: Request<'r>,
37651}
37652impl<'r> OpGetqdiscDump<'r> {
37653 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
37654 Self::write_header(request.buf_mut(), header);
37655 Self {
37656 request: request.set_dump(),
37657 }
37658 }
37659 pub fn encode_request<'buf>(
37660 buf: &'buf mut Vec<u8>,
37661 header: &Tcmsg,
37662 ) -> PushAttrs<&'buf mut Vec<u8>> {
37663 Self::write_header(buf, header);
37664 PushAttrs::new(buf)
37665 }
37666 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
37667 PushAttrs::new(self.request.buf_mut())
37668 }
37669 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
37670 PushAttrs::new(self.request.buf)
37671 }
37672 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
37673 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
37674 (
37675 Tcmsg::new_from_slice(header).unwrap_or_default(),
37676 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
37677 )
37678 }
37679 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
37680 prev.as_vec_mut().extend(header.as_slice());
37681 }
37682}
37683impl NetlinkRequest for OpGetqdiscDump<'_> {
37684 fn protocol(&self) -> Protocol {
37685 Protocol::Raw {
37686 protonum: 0u16,
37687 request_type: 38u16,
37688 }
37689 }
37690 fn flags(&self) -> u16 {
37691 self.request.flags
37692 }
37693 fn payload(&self) -> &[u8] {
37694 self.request.buf()
37695 }
37696 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
37697 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
37698 Self::decode_request(buf)
37699 }
37700 fn lookup(
37701 buf: &[u8],
37702 offset: usize,
37703 missing_type: Option<u16>,
37704 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37705 Self::decode_request(buf)
37706 .1
37707 .lookup_attr(offset, missing_type)
37708 }
37709}
37710#[doc = "Get / dump tc qdisc information.\n\nRequest attributes:\n- [.push_dump_invisible()](PushAttrs::push_dump_invisible)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
37711#[derive(Debug)]
37712pub struct OpGetqdiscDo<'r> {
37713 request: Request<'r>,
37714}
37715impl<'r> OpGetqdiscDo<'r> {
37716 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
37717 Self::write_header(request.buf_mut(), header);
37718 Self { request: request }
37719 }
37720 pub fn encode_request<'buf>(
37721 buf: &'buf mut Vec<u8>,
37722 header: &Tcmsg,
37723 ) -> PushAttrs<&'buf mut Vec<u8>> {
37724 Self::write_header(buf, header);
37725 PushAttrs::new(buf)
37726 }
37727 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
37728 PushAttrs::new(self.request.buf_mut())
37729 }
37730 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
37731 PushAttrs::new(self.request.buf)
37732 }
37733 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
37734 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
37735 (
37736 Tcmsg::new_from_slice(header).unwrap_or_default(),
37737 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
37738 )
37739 }
37740 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
37741 prev.as_vec_mut().extend(header.as_slice());
37742 }
37743}
37744impl NetlinkRequest for OpGetqdiscDo<'_> {
37745 fn protocol(&self) -> Protocol {
37746 Protocol::Raw {
37747 protonum: 0u16,
37748 request_type: 38u16,
37749 }
37750 }
37751 fn flags(&self) -> u16 {
37752 self.request.flags
37753 }
37754 fn payload(&self) -> &[u8] {
37755 self.request.buf()
37756 }
37757 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
37758 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
37759 Self::decode_request(buf)
37760 }
37761 fn lookup(
37762 buf: &[u8],
37763 offset: usize,
37764 missing_type: Option<u16>,
37765 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37766 Self::decode_request(buf)
37767 .1
37768 .lookup_attr(offset, missing_type)
37769 }
37770}
37771#[doc = "Get / dump tc traffic class information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.nested_options_basic()](PushAttrs::nested_options_basic)\n- [.nested_options_bpf()](PushAttrs::nested_options_bpf)\n- [.nested_options_bfifo()](PushAttrs::nested_options_bfifo)\n- [.nested_options_cake()](PushAttrs::nested_options_cake)\n- [.nested_options_cbs()](PushAttrs::nested_options_cbs)\n- [.nested_options_cgroup()](PushAttrs::nested_options_cgroup)\n- [.nested_options_choke()](PushAttrs::nested_options_choke)\n- [.nested_options_clsact()](PushAttrs::nested_options_clsact)\n- [.nested_options_codel()](PushAttrs::nested_options_codel)\n- [.nested_options_drr()](PushAttrs::nested_options_drr)\n- [.nested_options_dualpi2()](PushAttrs::nested_options_dualpi2)\n- [.nested_options_etf()](PushAttrs::nested_options_etf)\n- [.nested_options_ets()](PushAttrs::nested_options_ets)\n- [.nested_options_flow()](PushAttrs::nested_options_flow)\n- [.nested_options_flower()](PushAttrs::nested_options_flower)\n- [.nested_options_fq()](PushAttrs::nested_options_fq)\n- [.nested_options_fq_codel()](PushAttrs::nested_options_fq_codel)\n- [.nested_options_fq_pie()](PushAttrs::nested_options_fq_pie)\n- [.nested_options_fw()](PushAttrs::nested_options_fw)\n- [.nested_options_gred()](PushAttrs::nested_options_gred)\n- [.nested_options_hfsc()](PushAttrs::nested_options_hfsc)\n- [.nested_options_hhf()](PushAttrs::nested_options_hhf)\n- [.nested_options_htb()](PushAttrs::nested_options_htb)\n- [.nested_options_ingress()](PushAttrs::nested_options_ingress)\n- [.nested_options_matchall()](PushAttrs::nested_options_matchall)\n- [.nested_options_mq()](PushAttrs::nested_options_mq)\n- [.nested_options_mqprio()](PushAttrs::nested_options_mqprio)\n- [.nested_options_multiq()](PushAttrs::nested_options_multiq)\n- [.nested_options_netem()](PushAttrs::nested_options_netem)\n- [.nested_options_pfifo()](PushAttrs::nested_options_pfifo)\n- [.nested_options_pfifo_fast()](PushAttrs::nested_options_pfifo_fast)\n- [.nested_options_pfifo_head_drop()](PushAttrs::nested_options_pfifo_head_drop)\n- [.nested_options_pie()](PushAttrs::nested_options_pie)\n- [.nested_options_plug()](PushAttrs::nested_options_plug)\n- [.nested_options_prio()](PushAttrs::nested_options_prio)\n- [.nested_options_qfq()](PushAttrs::nested_options_qfq)\n- [.nested_options_red()](PushAttrs::nested_options_red)\n- [.nested_options_route()](PushAttrs::nested_options_route)\n- [.nested_options_sfb()](PushAttrs::nested_options_sfb)\n- [.nested_options_sfq()](PushAttrs::nested_options_sfq)\n- [.nested_options_taprio()](PushAttrs::nested_options_taprio)\n- [.nested_options_tbf()](PushAttrs::nested_options_tbf)\n- [.nested_options_u32()](PushAttrs::nested_options_u32)\n- [.push_rate()](PushAttrs::push_rate)\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_ingress_block()](PushAttrs::push_ingress_block)\n- [.push_egress_block()](PushAttrs::push_egress_block)\n\n"]
37772#[derive(Debug)]
37773pub struct OpNewtclassDo<'r> {
37774 request: Request<'r>,
37775}
37776impl<'r> OpNewtclassDo<'r> {
37777 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
37778 Self::write_header(request.buf_mut(), header);
37779 Self { request: request }
37780 }
37781 pub fn encode_request<'buf>(
37782 buf: &'buf mut Vec<u8>,
37783 header: &Tcmsg,
37784 ) -> PushAttrs<&'buf mut Vec<u8>> {
37785 Self::write_header(buf, header);
37786 PushAttrs::new(buf)
37787 }
37788 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
37789 PushAttrs::new(self.request.buf_mut())
37790 }
37791 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
37792 PushAttrs::new(self.request.buf)
37793 }
37794 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
37795 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
37796 (
37797 Tcmsg::new_from_slice(header).unwrap_or_default(),
37798 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
37799 )
37800 }
37801 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
37802 prev.as_vec_mut().extend(header.as_slice());
37803 }
37804}
37805impl NetlinkRequest for OpNewtclassDo<'_> {
37806 fn protocol(&self) -> Protocol {
37807 Protocol::Raw {
37808 protonum: 0u16,
37809 request_type: 40u16,
37810 }
37811 }
37812 fn flags(&self) -> u16 {
37813 self.request.flags
37814 }
37815 fn payload(&self) -> &[u8] {
37816 self.request.buf()
37817 }
37818 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
37819 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
37820 Self::decode_request(buf)
37821 }
37822 fn lookup(
37823 buf: &[u8],
37824 offset: usize,
37825 missing_type: Option<u16>,
37826 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37827 Self::decode_request(buf)
37828 .1
37829 .lookup_attr(offset, missing_type)
37830 }
37831}
37832#[doc = "Get / dump tc traffic class information.\n\n"]
37833#[derive(Debug)]
37834pub struct OpDeltclassDo<'r> {
37835 request: Request<'r>,
37836}
37837impl<'r> OpDeltclassDo<'r> {
37838 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
37839 Self::write_header(request.buf_mut(), header);
37840 Self { request: request }
37841 }
37842 pub fn encode_request<'buf>(
37843 buf: &'buf mut Vec<u8>,
37844 header: &Tcmsg,
37845 ) -> PushAttrs<&'buf mut Vec<u8>> {
37846 Self::write_header(buf, header);
37847 PushAttrs::new(buf)
37848 }
37849 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
37850 PushAttrs::new(self.request.buf_mut())
37851 }
37852 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
37853 PushAttrs::new(self.request.buf)
37854 }
37855 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
37856 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
37857 (
37858 Tcmsg::new_from_slice(header).unwrap_or_default(),
37859 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
37860 )
37861 }
37862 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
37863 prev.as_vec_mut().extend(header.as_slice());
37864 }
37865}
37866impl NetlinkRequest for OpDeltclassDo<'_> {
37867 fn protocol(&self) -> Protocol {
37868 Protocol::Raw {
37869 protonum: 0u16,
37870 request_type: 41u16,
37871 }
37872 }
37873 fn flags(&self) -> u16 {
37874 self.request.flags
37875 }
37876 fn payload(&self) -> &[u8] {
37877 self.request.buf()
37878 }
37879 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
37880 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
37881 Self::decode_request(buf)
37882 }
37883 fn lookup(
37884 buf: &[u8],
37885 offset: usize,
37886 missing_type: Option<u16>,
37887 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37888 Self::decode_request(buf)
37889 .1
37890 .lookup_attr(offset, missing_type)
37891 }
37892}
37893#[doc = "Get / dump tc traffic class information.\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
37894#[derive(Debug)]
37895pub struct OpGettclassDo<'r> {
37896 request: Request<'r>,
37897}
37898impl<'r> OpGettclassDo<'r> {
37899 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
37900 Self::write_header(request.buf_mut(), header);
37901 Self { request: request }
37902 }
37903 pub fn encode_request<'buf>(
37904 buf: &'buf mut Vec<u8>,
37905 header: &Tcmsg,
37906 ) -> PushAttrs<&'buf mut Vec<u8>> {
37907 Self::write_header(buf, header);
37908 PushAttrs::new(buf)
37909 }
37910 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
37911 PushAttrs::new(self.request.buf_mut())
37912 }
37913 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
37914 PushAttrs::new(self.request.buf)
37915 }
37916 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
37917 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
37918 (
37919 Tcmsg::new_from_slice(header).unwrap_or_default(),
37920 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
37921 )
37922 }
37923 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
37924 prev.as_vec_mut().extend(header.as_slice());
37925 }
37926}
37927impl NetlinkRequest for OpGettclassDo<'_> {
37928 fn protocol(&self) -> Protocol {
37929 Protocol::Raw {
37930 protonum: 0u16,
37931 request_type: 42u16,
37932 }
37933 }
37934 fn flags(&self) -> u16 {
37935 self.request.flags
37936 }
37937 fn payload(&self) -> &[u8] {
37938 self.request.buf()
37939 }
37940 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
37941 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
37942 Self::decode_request(buf)
37943 }
37944 fn lookup(
37945 buf: &[u8],
37946 offset: usize,
37947 missing_type: Option<u16>,
37948 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37949 Self::decode_request(buf)
37950 .1
37951 .lookup_attr(offset, missing_type)
37952 }
37953}
37954#[doc = "Get / dump tc filter information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.nested_options_basic()](PushAttrs::nested_options_basic)\n- [.nested_options_bpf()](PushAttrs::nested_options_bpf)\n- [.nested_options_bfifo()](PushAttrs::nested_options_bfifo)\n- [.nested_options_cake()](PushAttrs::nested_options_cake)\n- [.nested_options_cbs()](PushAttrs::nested_options_cbs)\n- [.nested_options_cgroup()](PushAttrs::nested_options_cgroup)\n- [.nested_options_choke()](PushAttrs::nested_options_choke)\n- [.nested_options_clsact()](PushAttrs::nested_options_clsact)\n- [.nested_options_codel()](PushAttrs::nested_options_codel)\n- [.nested_options_drr()](PushAttrs::nested_options_drr)\n- [.nested_options_dualpi2()](PushAttrs::nested_options_dualpi2)\n- [.nested_options_etf()](PushAttrs::nested_options_etf)\n- [.nested_options_ets()](PushAttrs::nested_options_ets)\n- [.nested_options_flow()](PushAttrs::nested_options_flow)\n- [.nested_options_flower()](PushAttrs::nested_options_flower)\n- [.nested_options_fq()](PushAttrs::nested_options_fq)\n- [.nested_options_fq_codel()](PushAttrs::nested_options_fq_codel)\n- [.nested_options_fq_pie()](PushAttrs::nested_options_fq_pie)\n- [.nested_options_fw()](PushAttrs::nested_options_fw)\n- [.nested_options_gred()](PushAttrs::nested_options_gred)\n- [.nested_options_hfsc()](PushAttrs::nested_options_hfsc)\n- [.nested_options_hhf()](PushAttrs::nested_options_hhf)\n- [.nested_options_htb()](PushAttrs::nested_options_htb)\n- [.nested_options_ingress()](PushAttrs::nested_options_ingress)\n- [.nested_options_matchall()](PushAttrs::nested_options_matchall)\n- [.nested_options_mq()](PushAttrs::nested_options_mq)\n- [.nested_options_mqprio()](PushAttrs::nested_options_mqprio)\n- [.nested_options_multiq()](PushAttrs::nested_options_multiq)\n- [.nested_options_netem()](PushAttrs::nested_options_netem)\n- [.nested_options_pfifo()](PushAttrs::nested_options_pfifo)\n- [.nested_options_pfifo_fast()](PushAttrs::nested_options_pfifo_fast)\n- [.nested_options_pfifo_head_drop()](PushAttrs::nested_options_pfifo_head_drop)\n- [.nested_options_pie()](PushAttrs::nested_options_pie)\n- [.nested_options_plug()](PushAttrs::nested_options_plug)\n- [.nested_options_prio()](PushAttrs::nested_options_prio)\n- [.nested_options_qfq()](PushAttrs::nested_options_qfq)\n- [.nested_options_red()](PushAttrs::nested_options_red)\n- [.nested_options_route()](PushAttrs::nested_options_route)\n- [.nested_options_sfb()](PushAttrs::nested_options_sfb)\n- [.nested_options_sfq()](PushAttrs::nested_options_sfq)\n- [.nested_options_taprio()](PushAttrs::nested_options_taprio)\n- [.nested_options_tbf()](PushAttrs::nested_options_tbf)\n- [.nested_options_u32()](PushAttrs::nested_options_u32)\n- [.push_rate()](PushAttrs::push_rate)\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_ingress_block()](PushAttrs::push_ingress_block)\n- [.push_egress_block()](PushAttrs::push_egress_block)\n\n"]
37955#[derive(Debug)]
37956pub struct OpNewtfilterDo<'r> {
37957 request: Request<'r>,
37958}
37959impl<'r> OpNewtfilterDo<'r> {
37960 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
37961 Self::write_header(request.buf_mut(), header);
37962 Self { request: request }
37963 }
37964 pub fn encode_request<'buf>(
37965 buf: &'buf mut Vec<u8>,
37966 header: &Tcmsg,
37967 ) -> PushAttrs<&'buf mut Vec<u8>> {
37968 Self::write_header(buf, header);
37969 PushAttrs::new(buf)
37970 }
37971 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
37972 PushAttrs::new(self.request.buf_mut())
37973 }
37974 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
37975 PushAttrs::new(self.request.buf)
37976 }
37977 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
37978 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
37979 (
37980 Tcmsg::new_from_slice(header).unwrap_or_default(),
37981 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
37982 )
37983 }
37984 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
37985 prev.as_vec_mut().extend(header.as_slice());
37986 }
37987}
37988impl NetlinkRequest for OpNewtfilterDo<'_> {
37989 fn protocol(&self) -> Protocol {
37990 Protocol::Raw {
37991 protonum: 0u16,
37992 request_type: 44u16,
37993 }
37994 }
37995 fn flags(&self) -> u16 {
37996 self.request.flags
37997 }
37998 fn payload(&self) -> &[u8] {
37999 self.request.buf()
38000 }
38001 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
38002 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
38003 Self::decode_request(buf)
38004 }
38005 fn lookup(
38006 buf: &[u8],
38007 offset: usize,
38008 missing_type: Option<u16>,
38009 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38010 Self::decode_request(buf)
38011 .1
38012 .lookup_attr(offset, missing_type)
38013 }
38014}
38015#[doc = "Get / dump tc filter information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.push_chain()](PushAttrs::push_chain)\n\n"]
38016#[derive(Debug)]
38017pub struct OpDeltfilterDo<'r> {
38018 request: Request<'r>,
38019}
38020impl<'r> OpDeltfilterDo<'r> {
38021 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
38022 Self::write_header(request.buf_mut(), header);
38023 Self { request: request }
38024 }
38025 pub fn encode_request<'buf>(
38026 buf: &'buf mut Vec<u8>,
38027 header: &Tcmsg,
38028 ) -> PushAttrs<&'buf mut Vec<u8>> {
38029 Self::write_header(buf, header);
38030 PushAttrs::new(buf)
38031 }
38032 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
38033 PushAttrs::new(self.request.buf_mut())
38034 }
38035 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
38036 PushAttrs::new(self.request.buf)
38037 }
38038 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
38039 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
38040 (
38041 Tcmsg::new_from_slice(header).unwrap_or_default(),
38042 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
38043 )
38044 }
38045 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
38046 prev.as_vec_mut().extend(header.as_slice());
38047 }
38048}
38049impl NetlinkRequest for OpDeltfilterDo<'_> {
38050 fn protocol(&self) -> Protocol {
38051 Protocol::Raw {
38052 protonum: 0u16,
38053 request_type: 45u16,
38054 }
38055 }
38056 fn flags(&self) -> u16 {
38057 self.request.flags
38058 }
38059 fn payload(&self) -> &[u8] {
38060 self.request.buf()
38061 }
38062 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
38063 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
38064 Self::decode_request(buf)
38065 }
38066 fn lookup(
38067 buf: &[u8],
38068 offset: usize,
38069 missing_type: Option<u16>,
38070 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38071 Self::decode_request(buf)
38072 .1
38073 .lookup_attr(offset, missing_type)
38074 }
38075}
38076#[doc = "Get / dump tc filter information.\n\nRequest attributes:\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_dump_flags()](PushAttrs::push_dump_flags)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
38077#[derive(Debug)]
38078pub struct OpGettfilterDump<'r> {
38079 request: Request<'r>,
38080}
38081impl<'r> OpGettfilterDump<'r> {
38082 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
38083 Self::write_header(request.buf_mut(), header);
38084 Self {
38085 request: request.set_dump(),
38086 }
38087 }
38088 pub fn encode_request<'buf>(
38089 buf: &'buf mut Vec<u8>,
38090 header: &Tcmsg,
38091 ) -> PushAttrs<&'buf mut Vec<u8>> {
38092 Self::write_header(buf, header);
38093 PushAttrs::new(buf)
38094 }
38095 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
38096 PushAttrs::new(self.request.buf_mut())
38097 }
38098 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
38099 PushAttrs::new(self.request.buf)
38100 }
38101 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
38102 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
38103 (
38104 Tcmsg::new_from_slice(header).unwrap_or_default(),
38105 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
38106 )
38107 }
38108 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
38109 prev.as_vec_mut().extend(header.as_slice());
38110 }
38111}
38112impl NetlinkRequest for OpGettfilterDump<'_> {
38113 fn protocol(&self) -> Protocol {
38114 Protocol::Raw {
38115 protonum: 0u16,
38116 request_type: 46u16,
38117 }
38118 }
38119 fn flags(&self) -> u16 {
38120 self.request.flags
38121 }
38122 fn payload(&self) -> &[u8] {
38123 self.request.buf()
38124 }
38125 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
38126 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
38127 Self::decode_request(buf)
38128 }
38129 fn lookup(
38130 buf: &[u8],
38131 offset: usize,
38132 missing_type: Option<u16>,
38133 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38134 Self::decode_request(buf)
38135 .1
38136 .lookup_attr(offset, missing_type)
38137 }
38138}
38139#[doc = "Get / dump tc filter information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.push_chain()](PushAttrs::push_chain)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
38140#[derive(Debug)]
38141pub struct OpGettfilterDo<'r> {
38142 request: Request<'r>,
38143}
38144impl<'r> OpGettfilterDo<'r> {
38145 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
38146 Self::write_header(request.buf_mut(), header);
38147 Self { request: request }
38148 }
38149 pub fn encode_request<'buf>(
38150 buf: &'buf mut Vec<u8>,
38151 header: &Tcmsg,
38152 ) -> PushAttrs<&'buf mut Vec<u8>> {
38153 Self::write_header(buf, header);
38154 PushAttrs::new(buf)
38155 }
38156 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
38157 PushAttrs::new(self.request.buf_mut())
38158 }
38159 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
38160 PushAttrs::new(self.request.buf)
38161 }
38162 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
38163 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
38164 (
38165 Tcmsg::new_from_slice(header).unwrap_or_default(),
38166 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
38167 )
38168 }
38169 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
38170 prev.as_vec_mut().extend(header.as_slice());
38171 }
38172}
38173impl NetlinkRequest for OpGettfilterDo<'_> {
38174 fn protocol(&self) -> Protocol {
38175 Protocol::Raw {
38176 protonum: 0u16,
38177 request_type: 46u16,
38178 }
38179 }
38180 fn flags(&self) -> u16 {
38181 self.request.flags
38182 }
38183 fn payload(&self) -> &[u8] {
38184 self.request.buf()
38185 }
38186 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
38187 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
38188 Self::decode_request(buf)
38189 }
38190 fn lookup(
38191 buf: &[u8],
38192 offset: usize,
38193 missing_type: Option<u16>,
38194 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38195 Self::decode_request(buf)
38196 .1
38197 .lookup_attr(offset, missing_type)
38198 }
38199}
38200#[doc = "Get / dump tc chain information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.nested_options_basic()](PushAttrs::nested_options_basic)\n- [.nested_options_bpf()](PushAttrs::nested_options_bpf)\n- [.nested_options_bfifo()](PushAttrs::nested_options_bfifo)\n- [.nested_options_cake()](PushAttrs::nested_options_cake)\n- [.nested_options_cbs()](PushAttrs::nested_options_cbs)\n- [.nested_options_cgroup()](PushAttrs::nested_options_cgroup)\n- [.nested_options_choke()](PushAttrs::nested_options_choke)\n- [.nested_options_clsact()](PushAttrs::nested_options_clsact)\n- [.nested_options_codel()](PushAttrs::nested_options_codel)\n- [.nested_options_drr()](PushAttrs::nested_options_drr)\n- [.nested_options_dualpi2()](PushAttrs::nested_options_dualpi2)\n- [.nested_options_etf()](PushAttrs::nested_options_etf)\n- [.nested_options_ets()](PushAttrs::nested_options_ets)\n- [.nested_options_flow()](PushAttrs::nested_options_flow)\n- [.nested_options_flower()](PushAttrs::nested_options_flower)\n- [.nested_options_fq()](PushAttrs::nested_options_fq)\n- [.nested_options_fq_codel()](PushAttrs::nested_options_fq_codel)\n- [.nested_options_fq_pie()](PushAttrs::nested_options_fq_pie)\n- [.nested_options_fw()](PushAttrs::nested_options_fw)\n- [.nested_options_gred()](PushAttrs::nested_options_gred)\n- [.nested_options_hfsc()](PushAttrs::nested_options_hfsc)\n- [.nested_options_hhf()](PushAttrs::nested_options_hhf)\n- [.nested_options_htb()](PushAttrs::nested_options_htb)\n- [.nested_options_ingress()](PushAttrs::nested_options_ingress)\n- [.nested_options_matchall()](PushAttrs::nested_options_matchall)\n- [.nested_options_mq()](PushAttrs::nested_options_mq)\n- [.nested_options_mqprio()](PushAttrs::nested_options_mqprio)\n- [.nested_options_multiq()](PushAttrs::nested_options_multiq)\n- [.nested_options_netem()](PushAttrs::nested_options_netem)\n- [.nested_options_pfifo()](PushAttrs::nested_options_pfifo)\n- [.nested_options_pfifo_fast()](PushAttrs::nested_options_pfifo_fast)\n- [.nested_options_pfifo_head_drop()](PushAttrs::nested_options_pfifo_head_drop)\n- [.nested_options_pie()](PushAttrs::nested_options_pie)\n- [.nested_options_plug()](PushAttrs::nested_options_plug)\n- [.nested_options_prio()](PushAttrs::nested_options_prio)\n- [.nested_options_qfq()](PushAttrs::nested_options_qfq)\n- [.nested_options_red()](PushAttrs::nested_options_red)\n- [.nested_options_route()](PushAttrs::nested_options_route)\n- [.nested_options_sfb()](PushAttrs::nested_options_sfb)\n- [.nested_options_sfq()](PushAttrs::nested_options_sfq)\n- [.nested_options_taprio()](PushAttrs::nested_options_taprio)\n- [.nested_options_tbf()](PushAttrs::nested_options_tbf)\n- [.nested_options_u32()](PushAttrs::nested_options_u32)\n- [.push_rate()](PushAttrs::push_rate)\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_ingress_block()](PushAttrs::push_ingress_block)\n- [.push_egress_block()](PushAttrs::push_egress_block)\n\n"]
38201#[derive(Debug)]
38202pub struct OpNewchainDo<'r> {
38203 request: Request<'r>,
38204}
38205impl<'r> OpNewchainDo<'r> {
38206 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
38207 Self::write_header(request.buf_mut(), header);
38208 Self { request: request }
38209 }
38210 pub fn encode_request<'buf>(
38211 buf: &'buf mut Vec<u8>,
38212 header: &Tcmsg,
38213 ) -> PushAttrs<&'buf mut Vec<u8>> {
38214 Self::write_header(buf, header);
38215 PushAttrs::new(buf)
38216 }
38217 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
38218 PushAttrs::new(self.request.buf_mut())
38219 }
38220 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
38221 PushAttrs::new(self.request.buf)
38222 }
38223 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
38224 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
38225 (
38226 Tcmsg::new_from_slice(header).unwrap_or_default(),
38227 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
38228 )
38229 }
38230 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
38231 prev.as_vec_mut().extend(header.as_slice());
38232 }
38233}
38234impl NetlinkRequest for OpNewchainDo<'_> {
38235 fn protocol(&self) -> Protocol {
38236 Protocol::Raw {
38237 protonum: 0u16,
38238 request_type: 100u16,
38239 }
38240 }
38241 fn flags(&self) -> u16 {
38242 self.request.flags
38243 }
38244 fn payload(&self) -> &[u8] {
38245 self.request.buf()
38246 }
38247 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
38248 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
38249 Self::decode_request(buf)
38250 }
38251 fn lookup(
38252 buf: &[u8],
38253 offset: usize,
38254 missing_type: Option<u16>,
38255 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38256 Self::decode_request(buf)
38257 .1
38258 .lookup_attr(offset, missing_type)
38259 }
38260}
38261#[doc = "Get / dump tc chain information.\n\nRequest attributes:\n- [.push_chain()](PushAttrs::push_chain)\n\n"]
38262#[derive(Debug)]
38263pub struct OpDelchainDo<'r> {
38264 request: Request<'r>,
38265}
38266impl<'r> OpDelchainDo<'r> {
38267 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
38268 Self::write_header(request.buf_mut(), header);
38269 Self { request: request }
38270 }
38271 pub fn encode_request<'buf>(
38272 buf: &'buf mut Vec<u8>,
38273 header: &Tcmsg,
38274 ) -> PushAttrs<&'buf mut Vec<u8>> {
38275 Self::write_header(buf, header);
38276 PushAttrs::new(buf)
38277 }
38278 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
38279 PushAttrs::new(self.request.buf_mut())
38280 }
38281 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
38282 PushAttrs::new(self.request.buf)
38283 }
38284 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
38285 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
38286 (
38287 Tcmsg::new_from_slice(header).unwrap_or_default(),
38288 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
38289 )
38290 }
38291 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
38292 prev.as_vec_mut().extend(header.as_slice());
38293 }
38294}
38295impl NetlinkRequest for OpDelchainDo<'_> {
38296 fn protocol(&self) -> Protocol {
38297 Protocol::Raw {
38298 protonum: 0u16,
38299 request_type: 101u16,
38300 }
38301 }
38302 fn flags(&self) -> u16 {
38303 self.request.flags
38304 }
38305 fn payload(&self) -> &[u8] {
38306 self.request.buf()
38307 }
38308 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
38309 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
38310 Self::decode_request(buf)
38311 }
38312 fn lookup(
38313 buf: &[u8],
38314 offset: usize,
38315 missing_type: Option<u16>,
38316 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38317 Self::decode_request(buf)
38318 .1
38319 .lookup_attr(offset, missing_type)
38320 }
38321}
38322#[doc = "Get / dump tc chain information.\n\nRequest attributes:\n- [.push_chain()](PushAttrs::push_chain)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
38323#[derive(Debug)]
38324pub struct OpGetchainDo<'r> {
38325 request: Request<'r>,
38326}
38327impl<'r> OpGetchainDo<'r> {
38328 pub fn new(mut request: Request<'r>, header: &Tcmsg) -> Self {
38329 Self::write_header(request.buf_mut(), header);
38330 Self { request: request }
38331 }
38332 pub fn encode_request<'buf>(
38333 buf: &'buf mut Vec<u8>,
38334 header: &Tcmsg,
38335 ) -> PushAttrs<&'buf mut Vec<u8>> {
38336 Self::write_header(buf, header);
38337 PushAttrs::new(buf)
38338 }
38339 pub fn encode(&mut self) -> PushAttrs<&mut Vec<u8>> {
38340 PushAttrs::new(self.request.buf_mut())
38341 }
38342 pub fn into_encoder(self) -> PushAttrs<RequestBuf<'r>> {
38343 PushAttrs::new(self.request.buf)
38344 }
38345 pub fn decode_request<'a>(buf: &'a [u8]) -> (Tcmsg, IterableAttrs<'a>) {
38346 let (header, attrs) = buf.split_at(buf.len().min(Tcmsg::len()));
38347 (
38348 Tcmsg::new_from_slice(header).unwrap_or_default(),
38349 IterableAttrs::with_loc(attrs, buf.as_ptr() as usize),
38350 )
38351 }
38352 fn write_header<Prev: Pusher>(prev: &mut Prev, header: &Tcmsg) {
38353 prev.as_vec_mut().extend(header.as_slice());
38354 }
38355}
38356impl NetlinkRequest for OpGetchainDo<'_> {
38357 fn protocol(&self) -> Protocol {
38358 Protocol::Raw {
38359 protonum: 0u16,
38360 request_type: 102u16,
38361 }
38362 }
38363 fn flags(&self) -> u16 {
38364 self.request.flags
38365 }
38366 fn payload(&self) -> &[u8] {
38367 self.request.buf()
38368 }
38369 type ReplyType<'buf> = (Tcmsg, IterableAttrs<'buf>);
38370 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
38371 Self::decode_request(buf)
38372 }
38373 fn lookup(
38374 buf: &[u8],
38375 offset: usize,
38376 missing_type: Option<u16>,
38377 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38378 Self::decode_request(buf)
38379 .1
38380 .lookup_attr(offset, missing_type)
38381 }
38382}
38383#[derive(Debug)]
38384pub struct ChainedFinal<'a> {
38385 inner: Chained<'a>,
38386}
38387#[derive(Debug)]
38388pub struct Chained<'a> {
38389 buf: RequestBuf<'a>,
38390 first_seq: u32,
38391 lookups: Vec<(&'static str, LookupFn)>,
38392 last_header_offset: usize,
38393 last_kind: Option<RequestInfo>,
38394}
38395impl<'a> ChainedFinal<'a> {
38396 pub fn into_chained(self) -> Chained<'a> {
38397 self.inner
38398 }
38399 pub fn buf(&self) -> &Vec<u8> {
38400 self.inner.buf()
38401 }
38402 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
38403 self.inner.buf_mut()
38404 }
38405 fn get_index(&self, seq: u32) -> Option<u32> {
38406 let min = self.inner.first_seq;
38407 let max = min.wrapping_add(self.inner.lookups.len() as u32);
38408 return if min <= max {
38409 (min..max).contains(&seq).then(|| seq - min)
38410 } else if min <= seq {
38411 Some(seq - min)
38412 } else if seq < max {
38413 Some(u32::MAX - min + seq)
38414 } else {
38415 None
38416 };
38417 }
38418}
38419impl crate::traits::NetlinkChained for ChainedFinal<'_> {
38420 fn protonum(&self) -> u16 {
38421 PROTONUM
38422 }
38423 fn payload(&self) -> &[u8] {
38424 self.buf()
38425 }
38426 fn chain_len(&self) -> usize {
38427 self.inner.lookups.len()
38428 }
38429 fn get_index(&self, seq: u32) -> Option<usize> {
38430 self.get_index(seq).map(|n| n as usize)
38431 }
38432 fn name(&self, index: usize) -> &'static str {
38433 self.inner.lookups[index].0
38434 }
38435 fn lookup(&self, index: usize) -> LookupFn {
38436 self.inner.lookups[index].1
38437 }
38438}
38439impl Chained<'static> {
38440 pub fn new(first_seq: u32) -> Self {
38441 Self::new_from_buf(Vec::new(), first_seq)
38442 }
38443 pub fn new_from_buf(buf: Vec<u8>, first_seq: u32) -> Self {
38444 Self {
38445 buf: RequestBuf::Own(buf),
38446 first_seq,
38447 lookups: Vec::new(),
38448 last_header_offset: 0,
38449 last_kind: None,
38450 }
38451 }
38452 pub fn into_buf(self) -> Vec<u8> {
38453 match self.buf {
38454 RequestBuf::Own(buf) => buf,
38455 _ => unreachable!(),
38456 }
38457 }
38458}
38459impl<'a> Chained<'a> {
38460 pub fn new_with_buf(buf: &'a mut Vec<u8>, first_seq: u32) -> Self {
38461 Self {
38462 buf: RequestBuf::Ref(buf),
38463 first_seq,
38464 lookups: Vec::new(),
38465 last_header_offset: 0,
38466 last_kind: None,
38467 }
38468 }
38469 pub fn finalize(mut self) -> ChainedFinal<'a> {
38470 self.update_header();
38471 ChainedFinal { inner: self }
38472 }
38473 pub fn request(&mut self) -> Request<'_> {
38474 self.update_header();
38475 self.last_header_offset = self.buf().len();
38476 self.buf_mut().extend_from_slice(Nlmsghdr::new().as_slice());
38477 let mut request = Request::new_extend(self.buf.buf_mut());
38478 self.last_kind = None;
38479 request.writeback = Some(&mut self.last_kind);
38480 request
38481 }
38482 pub fn buf(&self) -> &Vec<u8> {
38483 self.buf.buf()
38484 }
38485 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
38486 self.buf.buf_mut()
38487 }
38488 fn update_header(&mut self) {
38489 let Some(RequestInfo {
38490 protocol,
38491 flags,
38492 name,
38493 lookup,
38494 }) = self.last_kind
38495 else {
38496 if !self.buf().is_empty() {
38497 assert_eq!(self.last_header_offset + Nlmsghdr::len(), self.buf().len());
38498 self.buf.buf_mut().truncate(self.last_header_offset);
38499 }
38500 return;
38501 };
38502 let header_offset = self.last_header_offset;
38503 let request_type = match protocol {
38504 Protocol::Raw { request_type, .. } => request_type,
38505 Protocol::Generic(_) => unreachable!(),
38506 };
38507 let index = self.lookups.len();
38508 let seq = self.first_seq.wrapping_add(index as u32);
38509 self.lookups.push((name, lookup));
38510 let buf = self.buf_mut();
38511 align(buf);
38512 let header = Nlmsghdr {
38513 len: (buf.len() - header_offset) as u32,
38514 r#type: request_type,
38515 flags: flags | consts::NLM_F_REQUEST as u16 | consts::NLM_F_ACK as u16,
38516 seq,
38517 pid: 0,
38518 };
38519 buf[header_offset..(header_offset + 16)].clone_from_slice(header.as_slice());
38520 }
38521}
38522use crate::traits::LookupFn;
38523use crate::utils::RequestBuf;
38524#[derive(Debug)]
38525pub struct Request<'buf> {
38526 buf: RequestBuf<'buf>,
38527 flags: u16,
38528 writeback: Option<&'buf mut Option<RequestInfo>>,
38529}
38530#[allow(unused)]
38531#[derive(Debug, Clone)]
38532pub struct RequestInfo {
38533 protocol: Protocol,
38534 flags: u16,
38535 name: &'static str,
38536 lookup: LookupFn,
38537}
38538impl Request<'static> {
38539 pub fn new() -> Self {
38540 Self::new_from_buf(Vec::new())
38541 }
38542 pub fn new_from_buf(buf: Vec<u8>) -> Self {
38543 Self {
38544 flags: 0,
38545 buf: RequestBuf::Own(buf),
38546 writeback: None,
38547 }
38548 }
38549 pub fn into_buf(self) -> Vec<u8> {
38550 match self.buf {
38551 RequestBuf::Own(buf) => buf,
38552 _ => unreachable!(),
38553 }
38554 }
38555}
38556impl<'buf> Request<'buf> {
38557 pub fn new_with_buf(buf: &'buf mut Vec<u8>) -> Self {
38558 buf.clear();
38559 Self::new_extend(buf)
38560 }
38561 pub fn new_extend(buf: &'buf mut Vec<u8>) -> Self {
38562 Self {
38563 flags: 0,
38564 buf: RequestBuf::Ref(buf),
38565 writeback: None,
38566 }
38567 }
38568 fn do_writeback(&mut self, protocol: Protocol, name: &'static str, lookup: LookupFn) {
38569 let Some(writeback) = &mut self.writeback else {
38570 return;
38571 };
38572 **writeback = Some(RequestInfo {
38573 protocol,
38574 flags: self.flags,
38575 name,
38576 lookup,
38577 })
38578 }
38579 pub fn buf(&self) -> &Vec<u8> {
38580 self.buf.buf()
38581 }
38582 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
38583 self.buf.buf_mut()
38584 }
38585 #[doc = "Set `NLM_F_CREATE` flag"]
38586 pub fn set_create(mut self) -> Self {
38587 self.flags |= consts::NLM_F_CREATE as u16;
38588 self
38589 }
38590 #[doc = "Set `NLM_F_EXCL` flag"]
38591 pub fn set_excl(mut self) -> Self {
38592 self.flags |= consts::NLM_F_EXCL as u16;
38593 self
38594 }
38595 #[doc = "Set `NLM_F_REPLACE` flag"]
38596 pub fn set_replace(mut self) -> Self {
38597 self.flags |= consts::NLM_F_REPLACE as u16;
38598 self
38599 }
38600 #[doc = "Set `NLM_F_CREATE` and `NLM_F_REPLACE` flag"]
38601 pub fn set_change(self) -> Self {
38602 self.set_create().set_replace()
38603 }
38604 #[doc = "Set `NLM_F_APPEND` flag"]
38605 pub fn set_append(mut self) -> Self {
38606 self.flags |= consts::NLM_F_APPEND as u16;
38607 self
38608 }
38609 #[doc = "Set `self.flags |= flags`"]
38610 pub fn set_flags(mut self, flags: u16) -> Self {
38611 self.flags |= flags;
38612 self
38613 }
38614 #[doc = "Set `self.flags ^= self.flags & flags`"]
38615 pub fn unset_flags(mut self, flags: u16) -> Self {
38616 self.flags ^= self.flags & flags;
38617 self
38618 }
38619 #[doc = "Set `NLM_F_DUMP` flag"]
38620 fn set_dump(mut self) -> Self {
38621 self.flags |= consts::NLM_F_DUMP as u16;
38622 self
38623 }
38624 #[doc = "Create new tc qdisc.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.nested_options_basic()](PushAttrs::nested_options_basic)\n- [.nested_options_bpf()](PushAttrs::nested_options_bpf)\n- [.nested_options_bfifo()](PushAttrs::nested_options_bfifo)\n- [.nested_options_cake()](PushAttrs::nested_options_cake)\n- [.nested_options_cbs()](PushAttrs::nested_options_cbs)\n- [.nested_options_cgroup()](PushAttrs::nested_options_cgroup)\n- [.nested_options_choke()](PushAttrs::nested_options_choke)\n- [.nested_options_clsact()](PushAttrs::nested_options_clsact)\n- [.nested_options_codel()](PushAttrs::nested_options_codel)\n- [.nested_options_drr()](PushAttrs::nested_options_drr)\n- [.nested_options_dualpi2()](PushAttrs::nested_options_dualpi2)\n- [.nested_options_etf()](PushAttrs::nested_options_etf)\n- [.nested_options_ets()](PushAttrs::nested_options_ets)\n- [.nested_options_flow()](PushAttrs::nested_options_flow)\n- [.nested_options_flower()](PushAttrs::nested_options_flower)\n- [.nested_options_fq()](PushAttrs::nested_options_fq)\n- [.nested_options_fq_codel()](PushAttrs::nested_options_fq_codel)\n- [.nested_options_fq_pie()](PushAttrs::nested_options_fq_pie)\n- [.nested_options_fw()](PushAttrs::nested_options_fw)\n- [.nested_options_gred()](PushAttrs::nested_options_gred)\n- [.nested_options_hfsc()](PushAttrs::nested_options_hfsc)\n- [.nested_options_hhf()](PushAttrs::nested_options_hhf)\n- [.nested_options_htb()](PushAttrs::nested_options_htb)\n- [.nested_options_ingress()](PushAttrs::nested_options_ingress)\n- [.nested_options_matchall()](PushAttrs::nested_options_matchall)\n- [.nested_options_mq()](PushAttrs::nested_options_mq)\n- [.nested_options_mqprio()](PushAttrs::nested_options_mqprio)\n- [.nested_options_multiq()](PushAttrs::nested_options_multiq)\n- [.nested_options_netem()](PushAttrs::nested_options_netem)\n- [.nested_options_pfifo()](PushAttrs::nested_options_pfifo)\n- [.nested_options_pfifo_fast()](PushAttrs::nested_options_pfifo_fast)\n- [.nested_options_pfifo_head_drop()](PushAttrs::nested_options_pfifo_head_drop)\n- [.nested_options_pie()](PushAttrs::nested_options_pie)\n- [.nested_options_plug()](PushAttrs::nested_options_plug)\n- [.nested_options_prio()](PushAttrs::nested_options_prio)\n- [.nested_options_qfq()](PushAttrs::nested_options_qfq)\n- [.nested_options_red()](PushAttrs::nested_options_red)\n- [.nested_options_route()](PushAttrs::nested_options_route)\n- [.nested_options_sfb()](PushAttrs::nested_options_sfb)\n- [.nested_options_sfq()](PushAttrs::nested_options_sfq)\n- [.nested_options_taprio()](PushAttrs::nested_options_taprio)\n- [.nested_options_tbf()](PushAttrs::nested_options_tbf)\n- [.nested_options_u32()](PushAttrs::nested_options_u32)\n- [.push_rate()](PushAttrs::push_rate)\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_ingress_block()](PushAttrs::push_ingress_block)\n- [.push_egress_block()](PushAttrs::push_egress_block)\n\n"]
38625 pub fn op_newqdisc_do(self, header: &Tcmsg) -> OpNewqdiscDo<'buf> {
38626 let mut res = OpNewqdiscDo::new(self, header);
38627 res.request
38628 .do_writeback(res.protocol(), "op-newqdisc-do", OpNewqdiscDo::lookup);
38629 res
38630 }
38631 #[doc = "Delete existing tc qdisc.\n\n"]
38632 pub fn op_delqdisc_do(self, header: &Tcmsg) -> OpDelqdiscDo<'buf> {
38633 let mut res = OpDelqdiscDo::new(self, header);
38634 res.request
38635 .do_writeback(res.protocol(), "op-delqdisc-do", OpDelqdiscDo::lookup);
38636 res
38637 }
38638 #[doc = "Get / dump tc qdisc information.\n\nRequest attributes:\n- [.push_dump_invisible()](PushAttrs::push_dump_invisible)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
38639 pub fn op_getqdisc_dump(self, header: &Tcmsg) -> OpGetqdiscDump<'buf> {
38640 let mut res = OpGetqdiscDump::new(self, header);
38641 res.request
38642 .do_writeback(res.protocol(), "op-getqdisc-dump", OpGetqdiscDump::lookup);
38643 res
38644 }
38645 #[doc = "Get / dump tc qdisc information.\n\nRequest attributes:\n- [.push_dump_invisible()](PushAttrs::push_dump_invisible)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
38646 pub fn op_getqdisc_do(self, header: &Tcmsg) -> OpGetqdiscDo<'buf> {
38647 let mut res = OpGetqdiscDo::new(self, header);
38648 res.request
38649 .do_writeback(res.protocol(), "op-getqdisc-do", OpGetqdiscDo::lookup);
38650 res
38651 }
38652 #[doc = "Get / dump tc traffic class information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.nested_options_basic()](PushAttrs::nested_options_basic)\n- [.nested_options_bpf()](PushAttrs::nested_options_bpf)\n- [.nested_options_bfifo()](PushAttrs::nested_options_bfifo)\n- [.nested_options_cake()](PushAttrs::nested_options_cake)\n- [.nested_options_cbs()](PushAttrs::nested_options_cbs)\n- [.nested_options_cgroup()](PushAttrs::nested_options_cgroup)\n- [.nested_options_choke()](PushAttrs::nested_options_choke)\n- [.nested_options_clsact()](PushAttrs::nested_options_clsact)\n- [.nested_options_codel()](PushAttrs::nested_options_codel)\n- [.nested_options_drr()](PushAttrs::nested_options_drr)\n- [.nested_options_dualpi2()](PushAttrs::nested_options_dualpi2)\n- [.nested_options_etf()](PushAttrs::nested_options_etf)\n- [.nested_options_ets()](PushAttrs::nested_options_ets)\n- [.nested_options_flow()](PushAttrs::nested_options_flow)\n- [.nested_options_flower()](PushAttrs::nested_options_flower)\n- [.nested_options_fq()](PushAttrs::nested_options_fq)\n- [.nested_options_fq_codel()](PushAttrs::nested_options_fq_codel)\n- [.nested_options_fq_pie()](PushAttrs::nested_options_fq_pie)\n- [.nested_options_fw()](PushAttrs::nested_options_fw)\n- [.nested_options_gred()](PushAttrs::nested_options_gred)\n- [.nested_options_hfsc()](PushAttrs::nested_options_hfsc)\n- [.nested_options_hhf()](PushAttrs::nested_options_hhf)\n- [.nested_options_htb()](PushAttrs::nested_options_htb)\n- [.nested_options_ingress()](PushAttrs::nested_options_ingress)\n- [.nested_options_matchall()](PushAttrs::nested_options_matchall)\n- [.nested_options_mq()](PushAttrs::nested_options_mq)\n- [.nested_options_mqprio()](PushAttrs::nested_options_mqprio)\n- [.nested_options_multiq()](PushAttrs::nested_options_multiq)\n- [.nested_options_netem()](PushAttrs::nested_options_netem)\n- [.nested_options_pfifo()](PushAttrs::nested_options_pfifo)\n- [.nested_options_pfifo_fast()](PushAttrs::nested_options_pfifo_fast)\n- [.nested_options_pfifo_head_drop()](PushAttrs::nested_options_pfifo_head_drop)\n- [.nested_options_pie()](PushAttrs::nested_options_pie)\n- [.nested_options_plug()](PushAttrs::nested_options_plug)\n- [.nested_options_prio()](PushAttrs::nested_options_prio)\n- [.nested_options_qfq()](PushAttrs::nested_options_qfq)\n- [.nested_options_red()](PushAttrs::nested_options_red)\n- [.nested_options_route()](PushAttrs::nested_options_route)\n- [.nested_options_sfb()](PushAttrs::nested_options_sfb)\n- [.nested_options_sfq()](PushAttrs::nested_options_sfq)\n- [.nested_options_taprio()](PushAttrs::nested_options_taprio)\n- [.nested_options_tbf()](PushAttrs::nested_options_tbf)\n- [.nested_options_u32()](PushAttrs::nested_options_u32)\n- [.push_rate()](PushAttrs::push_rate)\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_ingress_block()](PushAttrs::push_ingress_block)\n- [.push_egress_block()](PushAttrs::push_egress_block)\n\n"]
38653 pub fn op_newtclass_do(self, header: &Tcmsg) -> OpNewtclassDo<'buf> {
38654 let mut res = OpNewtclassDo::new(self, header);
38655 res.request
38656 .do_writeback(res.protocol(), "op-newtclass-do", OpNewtclassDo::lookup);
38657 res
38658 }
38659 #[doc = "Get / dump tc traffic class information.\n\n"]
38660 pub fn op_deltclass_do(self, header: &Tcmsg) -> OpDeltclassDo<'buf> {
38661 let mut res = OpDeltclassDo::new(self, header);
38662 res.request
38663 .do_writeback(res.protocol(), "op-deltclass-do", OpDeltclassDo::lookup);
38664 res
38665 }
38666 #[doc = "Get / dump tc traffic class information.\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
38667 pub fn op_gettclass_do(self, header: &Tcmsg) -> OpGettclassDo<'buf> {
38668 let mut res = OpGettclassDo::new(self, header);
38669 res.request
38670 .do_writeback(res.protocol(), "op-gettclass-do", OpGettclassDo::lookup);
38671 res
38672 }
38673 #[doc = "Get / dump tc filter information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.nested_options_basic()](PushAttrs::nested_options_basic)\n- [.nested_options_bpf()](PushAttrs::nested_options_bpf)\n- [.nested_options_bfifo()](PushAttrs::nested_options_bfifo)\n- [.nested_options_cake()](PushAttrs::nested_options_cake)\n- [.nested_options_cbs()](PushAttrs::nested_options_cbs)\n- [.nested_options_cgroup()](PushAttrs::nested_options_cgroup)\n- [.nested_options_choke()](PushAttrs::nested_options_choke)\n- [.nested_options_clsact()](PushAttrs::nested_options_clsact)\n- [.nested_options_codel()](PushAttrs::nested_options_codel)\n- [.nested_options_drr()](PushAttrs::nested_options_drr)\n- [.nested_options_dualpi2()](PushAttrs::nested_options_dualpi2)\n- [.nested_options_etf()](PushAttrs::nested_options_etf)\n- [.nested_options_ets()](PushAttrs::nested_options_ets)\n- [.nested_options_flow()](PushAttrs::nested_options_flow)\n- [.nested_options_flower()](PushAttrs::nested_options_flower)\n- [.nested_options_fq()](PushAttrs::nested_options_fq)\n- [.nested_options_fq_codel()](PushAttrs::nested_options_fq_codel)\n- [.nested_options_fq_pie()](PushAttrs::nested_options_fq_pie)\n- [.nested_options_fw()](PushAttrs::nested_options_fw)\n- [.nested_options_gred()](PushAttrs::nested_options_gred)\n- [.nested_options_hfsc()](PushAttrs::nested_options_hfsc)\n- [.nested_options_hhf()](PushAttrs::nested_options_hhf)\n- [.nested_options_htb()](PushAttrs::nested_options_htb)\n- [.nested_options_ingress()](PushAttrs::nested_options_ingress)\n- [.nested_options_matchall()](PushAttrs::nested_options_matchall)\n- [.nested_options_mq()](PushAttrs::nested_options_mq)\n- [.nested_options_mqprio()](PushAttrs::nested_options_mqprio)\n- [.nested_options_multiq()](PushAttrs::nested_options_multiq)\n- [.nested_options_netem()](PushAttrs::nested_options_netem)\n- [.nested_options_pfifo()](PushAttrs::nested_options_pfifo)\n- [.nested_options_pfifo_fast()](PushAttrs::nested_options_pfifo_fast)\n- [.nested_options_pfifo_head_drop()](PushAttrs::nested_options_pfifo_head_drop)\n- [.nested_options_pie()](PushAttrs::nested_options_pie)\n- [.nested_options_plug()](PushAttrs::nested_options_plug)\n- [.nested_options_prio()](PushAttrs::nested_options_prio)\n- [.nested_options_qfq()](PushAttrs::nested_options_qfq)\n- [.nested_options_red()](PushAttrs::nested_options_red)\n- [.nested_options_route()](PushAttrs::nested_options_route)\n- [.nested_options_sfb()](PushAttrs::nested_options_sfb)\n- [.nested_options_sfq()](PushAttrs::nested_options_sfq)\n- [.nested_options_taprio()](PushAttrs::nested_options_taprio)\n- [.nested_options_tbf()](PushAttrs::nested_options_tbf)\n- [.nested_options_u32()](PushAttrs::nested_options_u32)\n- [.push_rate()](PushAttrs::push_rate)\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_ingress_block()](PushAttrs::push_ingress_block)\n- [.push_egress_block()](PushAttrs::push_egress_block)\n\n"]
38674 pub fn op_newtfilter_do(self, header: &Tcmsg) -> OpNewtfilterDo<'buf> {
38675 let mut res = OpNewtfilterDo::new(self, header);
38676 res.request
38677 .do_writeback(res.protocol(), "op-newtfilter-do", OpNewtfilterDo::lookup);
38678 res
38679 }
38680 #[doc = "Get / dump tc filter information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.push_chain()](PushAttrs::push_chain)\n\n"]
38681 pub fn op_deltfilter_do(self, header: &Tcmsg) -> OpDeltfilterDo<'buf> {
38682 let mut res = OpDeltfilterDo::new(self, header);
38683 res.request
38684 .do_writeback(res.protocol(), "op-deltfilter-do", OpDeltfilterDo::lookup);
38685 res
38686 }
38687 #[doc = "Get / dump tc filter information.\n\nRequest attributes:\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_dump_flags()](PushAttrs::push_dump_flags)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
38688 pub fn op_gettfilter_dump(self, header: &Tcmsg) -> OpGettfilterDump<'buf> {
38689 let mut res = OpGettfilterDump::new(self, header);
38690 res.request.do_writeback(
38691 res.protocol(),
38692 "op-gettfilter-dump",
38693 OpGettfilterDump::lookup,
38694 );
38695 res
38696 }
38697 #[doc = "Get / dump tc filter information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.push_chain()](PushAttrs::push_chain)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
38698 pub fn op_gettfilter_do(self, header: &Tcmsg) -> OpGettfilterDo<'buf> {
38699 let mut res = OpGettfilterDo::new(self, header);
38700 res.request
38701 .do_writeback(res.protocol(), "op-gettfilter-do", OpGettfilterDo::lookup);
38702 res
38703 }
38704 #[doc = "Get / dump tc chain information.\n\nRequest attributes:\n- [.push_kind()](PushAttrs::push_kind)\n- [.nested_options_basic()](PushAttrs::nested_options_basic)\n- [.nested_options_bpf()](PushAttrs::nested_options_bpf)\n- [.nested_options_bfifo()](PushAttrs::nested_options_bfifo)\n- [.nested_options_cake()](PushAttrs::nested_options_cake)\n- [.nested_options_cbs()](PushAttrs::nested_options_cbs)\n- [.nested_options_cgroup()](PushAttrs::nested_options_cgroup)\n- [.nested_options_choke()](PushAttrs::nested_options_choke)\n- [.nested_options_clsact()](PushAttrs::nested_options_clsact)\n- [.nested_options_codel()](PushAttrs::nested_options_codel)\n- [.nested_options_drr()](PushAttrs::nested_options_drr)\n- [.nested_options_dualpi2()](PushAttrs::nested_options_dualpi2)\n- [.nested_options_etf()](PushAttrs::nested_options_etf)\n- [.nested_options_ets()](PushAttrs::nested_options_ets)\n- [.nested_options_flow()](PushAttrs::nested_options_flow)\n- [.nested_options_flower()](PushAttrs::nested_options_flower)\n- [.nested_options_fq()](PushAttrs::nested_options_fq)\n- [.nested_options_fq_codel()](PushAttrs::nested_options_fq_codel)\n- [.nested_options_fq_pie()](PushAttrs::nested_options_fq_pie)\n- [.nested_options_fw()](PushAttrs::nested_options_fw)\n- [.nested_options_gred()](PushAttrs::nested_options_gred)\n- [.nested_options_hfsc()](PushAttrs::nested_options_hfsc)\n- [.nested_options_hhf()](PushAttrs::nested_options_hhf)\n- [.nested_options_htb()](PushAttrs::nested_options_htb)\n- [.nested_options_ingress()](PushAttrs::nested_options_ingress)\n- [.nested_options_matchall()](PushAttrs::nested_options_matchall)\n- [.nested_options_mq()](PushAttrs::nested_options_mq)\n- [.nested_options_mqprio()](PushAttrs::nested_options_mqprio)\n- [.nested_options_multiq()](PushAttrs::nested_options_multiq)\n- [.nested_options_netem()](PushAttrs::nested_options_netem)\n- [.nested_options_pfifo()](PushAttrs::nested_options_pfifo)\n- [.nested_options_pfifo_fast()](PushAttrs::nested_options_pfifo_fast)\n- [.nested_options_pfifo_head_drop()](PushAttrs::nested_options_pfifo_head_drop)\n- [.nested_options_pie()](PushAttrs::nested_options_pie)\n- [.nested_options_plug()](PushAttrs::nested_options_plug)\n- [.nested_options_prio()](PushAttrs::nested_options_prio)\n- [.nested_options_qfq()](PushAttrs::nested_options_qfq)\n- [.nested_options_red()](PushAttrs::nested_options_red)\n- [.nested_options_route()](PushAttrs::nested_options_route)\n- [.nested_options_sfb()](PushAttrs::nested_options_sfb)\n- [.nested_options_sfq()](PushAttrs::nested_options_sfq)\n- [.nested_options_taprio()](PushAttrs::nested_options_taprio)\n- [.nested_options_tbf()](PushAttrs::nested_options_tbf)\n- [.nested_options_u32()](PushAttrs::nested_options_u32)\n- [.push_rate()](PushAttrs::push_rate)\n- [.push_chain()](PushAttrs::push_chain)\n- [.push_ingress_block()](PushAttrs::push_ingress_block)\n- [.push_egress_block()](PushAttrs::push_egress_block)\n\n"]
38705 pub fn op_newchain_do(self, header: &Tcmsg) -> OpNewchainDo<'buf> {
38706 let mut res = OpNewchainDo::new(self, header);
38707 res.request
38708 .do_writeback(res.protocol(), "op-newchain-do", OpNewchainDo::lookup);
38709 res
38710 }
38711 #[doc = "Get / dump tc chain information.\n\nRequest attributes:\n- [.push_chain()](PushAttrs::push_chain)\n\n"]
38712 pub fn op_delchain_do(self, header: &Tcmsg) -> OpDelchainDo<'buf> {
38713 let mut res = OpDelchainDo::new(self, header);
38714 res.request
38715 .do_writeback(res.protocol(), "op-delchain-do", OpDelchainDo::lookup);
38716 res
38717 }
38718 #[doc = "Get / dump tc chain information.\n\nRequest attributes:\n- [.push_chain()](PushAttrs::push_chain)\n\nReply attributes:\n- [.get_kind()](IterableAttrs::get_kind)\n- [.get_options()](IterableAttrs::get_options)\n- [.get_stats()](IterableAttrs::get_stats)\n- [.get_xstats()](IterableAttrs::get_xstats)\n- [.get_rate()](IterableAttrs::get_rate)\n- [.get_fcnt()](IterableAttrs::get_fcnt)\n- [.get_stats2()](IterableAttrs::get_stats2)\n- [.get_stab()](IterableAttrs::get_stab)\n- [.get_chain()](IterableAttrs::get_chain)\n- [.get_ingress_block()](IterableAttrs::get_ingress_block)\n- [.get_egress_block()](IterableAttrs::get_egress_block)\n\n"]
38719 pub fn op_getchain_do(self, header: &Tcmsg) -> OpGetchainDo<'buf> {
38720 let mut res = OpGetchainDo::new(self, header);
38721 res.request
38722 .do_writeback(res.protocol(), "op-getchain-do", OpGetchainDo::lookup);
38723 res
38724 }
38725}
38726#[cfg(test)]
38727mod generated_tests {
38728 use super::*;
38729 #[test]
38730 fn tests() {
38731 let _ = IterableAttrs::get_chain;
38732 let _ = IterableAttrs::get_egress_block;
38733 let _ = IterableAttrs::get_fcnt;
38734 let _ = IterableAttrs::get_ingress_block;
38735 let _ = IterableAttrs::get_kind;
38736 let _ = IterableAttrs::get_options;
38737 let _ = IterableAttrs::get_rate;
38738 let _ = IterableAttrs::get_stab;
38739 let _ = IterableAttrs::get_stats2;
38740 let _ = IterableAttrs::get_stats;
38741 let _ = IterableAttrs::get_xstats;
38742 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_basic;
38743 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_bfifo;
38744 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_bpf;
38745 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_cake;
38746 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_cbs;
38747 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_cgroup;
38748 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_choke;
38749 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_clsact;
38750 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_codel;
38751 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_drr;
38752 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_dualpi2;
38753 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_etf;
38754 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_ets;
38755 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_flow;
38756 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_flower;
38757 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_fq;
38758 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_fq_codel;
38759 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_fq_pie;
38760 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_fw;
38761 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_gred;
38762 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_hfsc;
38763 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_hhf;
38764 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_htb;
38765 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_ingress;
38766 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_matchall;
38767 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_mq;
38768 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_mqprio;
38769 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_multiq;
38770 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_netem;
38771 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_pfifo;
38772 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_pfifo_fast;
38773 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_pfifo_head_drop;
38774 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_pie;
38775 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_plug;
38776 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_prio;
38777 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_qfq;
38778 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_red;
38779 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_route;
38780 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_sfb;
38781 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_sfq;
38782 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_taprio;
38783 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_tbf;
38784 let _ = PushAttrs::<&mut Vec<u8>>::nested_options_u32;
38785 let _ = PushAttrs::<&mut Vec<u8>>::push_chain;
38786 let _ = PushAttrs::<&mut Vec<u8>>::push_dump_flags;
38787 let _ = PushAttrs::<&mut Vec<u8>>::push_dump_invisible;
38788 let _ = PushAttrs::<&mut Vec<u8>>::push_egress_block;
38789 let _ = PushAttrs::<&mut Vec<u8>>::push_ingress_block;
38790 let _ = PushAttrs::<&mut Vec<u8>>::push_kind;
38791 let _ = PushAttrs::<&mut Vec<u8>>::push_rate;
38792 }
38793}