1#![doc = "genetlink meta-family that exposes information about all genetlink\nfamilies registered in the kernel (including itself).\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)]
10use crate::builtin::{PushBuiltinBitfield32, PushBuiltinNfgenmsg, PushDummy, PushNlmsghdr};
11use crate::{
12 consts,
13 traits::{NetlinkRequest, Protocol},
14 utils::*,
15};
16pub const PROTONAME: &CStr = c"nlctrl";
17#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
18#[derive(Debug, Clone, Copy)]
19pub enum OpFlags {
20 AdminPerm = 1 << 0,
21 CmdCapDo = 1 << 1,
22 CmdCapDump = 1 << 2,
23 CmdCapHaspol = 1 << 3,
24 UnsAdminPerm = 1 << 4,
25}
26impl OpFlags {
27 pub fn from_value(value: u64) -> Option<Self> {
28 Some(match value {
29 n if n == 1 << 0 => Self::AdminPerm,
30 n if n == 1 << 1 => Self::CmdCapDo,
31 n if n == 1 << 2 => Self::CmdCapDump,
32 n if n == 1 << 3 => Self::CmdCapHaspol,
33 n if n == 1 << 4 => Self::UnsAdminPerm,
34 _ => return None,
35 })
36 }
37}
38#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
39#[derive(Debug, Clone, Copy)]
40pub enum AttrType {
41 Invalid = 0,
42 Flag = 1,
43 U8 = 2,
44 U16 = 3,
45 U32 = 4,
46 U64 = 5,
47 S8 = 6,
48 S16 = 7,
49 S32 = 8,
50 S64 = 9,
51 Binary = 10,
52 String = 11,
53 NulString = 12,
54 Nested = 13,
55 NestedArray = 14,
56 Bitfield32 = 15,
57 Sint = 16,
58 Uint = 17,
59}
60impl AttrType {
61 pub fn from_value(value: u64) -> Option<Self> {
62 Some(match value {
63 0 => Self::Invalid,
64 1 => Self::Flag,
65 2 => Self::U8,
66 3 => Self::U16,
67 4 => Self::U32,
68 5 => Self::U64,
69 6 => Self::S8,
70 7 => Self::S16,
71 8 => Self::S32,
72 9 => Self::S64,
73 10 => Self::Binary,
74 11 => Self::String,
75 12 => Self::NulString,
76 13 => Self::Nested,
77 14 => Self::NestedArray,
78 15 => Self::Bitfield32,
79 16 => Self::Sint,
80 17 => Self::Uint,
81 _ => return None,
82 })
83 }
84}
85#[derive(Clone)]
86pub enum CtrlAttrs<'a> {
87 FamilyId(u16),
88 FamilyName(&'a CStr),
89 Version(u32),
90 Hdrsize(u32),
91 Maxattr(u32),
92 Ops(IterableArrayOpAttrs<'a>),
93 McastGroups(IterableArrayMcastGroupAttrs<'a>),
94 Policy(IterablePolicyAttrs<'a>),
95 OpPolicy(IterableOpPolicyAttrs<'a>),
96 Op(u32),
97}
98impl<'a> IterableCtrlAttrs<'a> {
99 pub fn get_family_id(&self) -> Result<u16, ErrorContext> {
100 let mut iter = self.clone();
101 iter.pos = 0;
102 for attr in iter {
103 if let CtrlAttrs::FamilyId(val) = attr? {
104 return Ok(val);
105 }
106 }
107 Err(ErrorContext::new_missing(
108 "CtrlAttrs",
109 "FamilyId",
110 self.orig_loc,
111 self.buf.as_ptr() as usize,
112 ))
113 }
114 pub fn get_family_name(&self) -> Result<&'a CStr, ErrorContext> {
115 let mut iter = self.clone();
116 iter.pos = 0;
117 for attr in iter {
118 if let CtrlAttrs::FamilyName(val) = attr? {
119 return Ok(val);
120 }
121 }
122 Err(ErrorContext::new_missing(
123 "CtrlAttrs",
124 "FamilyName",
125 self.orig_loc,
126 self.buf.as_ptr() as usize,
127 ))
128 }
129 pub fn get_version(&self) -> Result<u32, ErrorContext> {
130 let mut iter = self.clone();
131 iter.pos = 0;
132 for attr in iter {
133 if let CtrlAttrs::Version(val) = attr? {
134 return Ok(val);
135 }
136 }
137 Err(ErrorContext::new_missing(
138 "CtrlAttrs",
139 "Version",
140 self.orig_loc,
141 self.buf.as_ptr() as usize,
142 ))
143 }
144 pub fn get_hdrsize(&self) -> Result<u32, ErrorContext> {
145 let mut iter = self.clone();
146 iter.pos = 0;
147 for attr in iter {
148 if let CtrlAttrs::Hdrsize(val) = attr? {
149 return Ok(val);
150 }
151 }
152 Err(ErrorContext::new_missing(
153 "CtrlAttrs",
154 "Hdrsize",
155 self.orig_loc,
156 self.buf.as_ptr() as usize,
157 ))
158 }
159 pub fn get_maxattr(&self) -> Result<u32, ErrorContext> {
160 let mut iter = self.clone();
161 iter.pos = 0;
162 for attr in iter {
163 if let CtrlAttrs::Maxattr(val) = attr? {
164 return Ok(val);
165 }
166 }
167 Err(ErrorContext::new_missing(
168 "CtrlAttrs",
169 "Maxattr",
170 self.orig_loc,
171 self.buf.as_ptr() as usize,
172 ))
173 }
174 pub fn get_ops(
175 &self,
176 ) -> Result<ArrayIterable<IterableArrayOpAttrs<'a>, IterableOpAttrs<'a>>, ErrorContext> {
177 for attr in self.clone() {
178 if let CtrlAttrs::Ops(val) = attr? {
179 return Ok(ArrayIterable::new(val));
180 }
181 }
182 Err(ErrorContext::new_missing(
183 "CtrlAttrs",
184 "Ops",
185 self.orig_loc,
186 self.buf.as_ptr() as usize,
187 ))
188 }
189 pub fn get_mcast_groups(
190 &self,
191 ) -> Result<
192 ArrayIterable<IterableArrayMcastGroupAttrs<'a>, IterableMcastGroupAttrs<'a>>,
193 ErrorContext,
194 > {
195 for attr in self.clone() {
196 if let CtrlAttrs::McastGroups(val) = attr? {
197 return Ok(ArrayIterable::new(val));
198 }
199 }
200 Err(ErrorContext::new_missing(
201 "CtrlAttrs",
202 "McastGroups",
203 self.orig_loc,
204 self.buf.as_ptr() as usize,
205 ))
206 }
207 pub fn get_policy(&self) -> Result<IterablePolicyAttrs<'a>, ErrorContext> {
208 let mut iter = self.clone();
209 iter.pos = 0;
210 for attr in iter {
211 if let CtrlAttrs::Policy(val) = attr? {
212 return Ok(val);
213 }
214 }
215 Err(ErrorContext::new_missing(
216 "CtrlAttrs",
217 "Policy",
218 self.orig_loc,
219 self.buf.as_ptr() as usize,
220 ))
221 }
222 pub fn get_op_policy(&self) -> Result<IterableOpPolicyAttrs<'a>, ErrorContext> {
223 let mut iter = self.clone();
224 iter.pos = 0;
225 for attr in iter {
226 if let CtrlAttrs::OpPolicy(val) = attr? {
227 return Ok(val);
228 }
229 }
230 Err(ErrorContext::new_missing(
231 "CtrlAttrs",
232 "OpPolicy",
233 self.orig_loc,
234 self.buf.as_ptr() as usize,
235 ))
236 }
237 pub fn get_op(&self) -> Result<u32, ErrorContext> {
238 let mut iter = self.clone();
239 iter.pos = 0;
240 for attr in iter {
241 if let CtrlAttrs::Op(val) = attr? {
242 return Ok(val);
243 }
244 }
245 Err(ErrorContext::new_missing(
246 "CtrlAttrs",
247 "Op",
248 self.orig_loc,
249 self.buf.as_ptr() as usize,
250 ))
251 }
252}
253impl OpAttrs {
254 pub fn new_array(buf: &[u8]) -> IterableArrayOpAttrs<'_> {
255 IterableArrayOpAttrs::with_loc(buf, buf.as_ptr() as usize)
256 }
257}
258#[derive(Clone, Copy, Default)]
259pub struct IterableArrayOpAttrs<'a> {
260 buf: &'a [u8],
261 pos: usize,
262 orig_loc: usize,
263}
264impl<'a> IterableArrayOpAttrs<'a> {
265 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
266 Self {
267 buf,
268 pos: 0,
269 orig_loc,
270 }
271 }
272 pub fn get_buf(&self) -> &'a [u8] {
273 self.buf
274 }
275}
276impl<'a> Iterator for IterableArrayOpAttrs<'a> {
277 type Item = Result<IterableOpAttrs<'a>, ErrorContext>;
278 fn next(&mut self) -> Option<Self::Item> {
279 if self.buf.len() == self.pos {
280 return None;
281 }
282 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
283 {
284 return Some(Ok(IterableOpAttrs::with_loc(next, self.orig_loc)));
285 }
286 }
287 Some(Err(ErrorContext::new(
288 "OpAttrs",
289 None,
290 self.orig_loc,
291 self.buf.as_ptr().wrapping_add(self.pos) as usize,
292 )))
293 }
294}
295impl<'a> McastGroupAttrs<'a> {
296 pub fn new_array(buf: &[u8]) -> IterableArrayMcastGroupAttrs<'_> {
297 IterableArrayMcastGroupAttrs::with_loc(buf, buf.as_ptr() as usize)
298 }
299}
300#[derive(Clone, Copy, Default)]
301pub struct IterableArrayMcastGroupAttrs<'a> {
302 buf: &'a [u8],
303 pos: usize,
304 orig_loc: usize,
305}
306impl<'a> IterableArrayMcastGroupAttrs<'a> {
307 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
308 Self {
309 buf,
310 pos: 0,
311 orig_loc,
312 }
313 }
314 pub fn get_buf(&self) -> &'a [u8] {
315 self.buf
316 }
317}
318impl<'a> Iterator for IterableArrayMcastGroupAttrs<'a> {
319 type Item = Result<IterableMcastGroupAttrs<'a>, ErrorContext>;
320 fn next(&mut self) -> Option<Self::Item> {
321 if self.buf.len() == self.pos {
322 return None;
323 }
324 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
325 {
326 return Some(Ok(IterableMcastGroupAttrs::with_loc(next, self.orig_loc)));
327 }
328 }
329 Some(Err(ErrorContext::new(
330 "McastGroupAttrs",
331 None,
332 self.orig_loc,
333 self.buf.as_ptr().wrapping_add(self.pos) as usize,
334 )))
335 }
336}
337impl CtrlAttrs<'_> {
338 pub fn new<'a>(buf: &'a [u8]) -> IterableCtrlAttrs<'a> {
339 IterableCtrlAttrs::with_loc(buf, buf.as_ptr() as usize)
340 }
341 fn attr_from_type(r#type: u16) -> Option<&'static str> {
342 let res = match r#type {
343 1u16 => "FamilyId",
344 2u16 => "FamilyName",
345 3u16 => "Version",
346 4u16 => "Hdrsize",
347 5u16 => "Maxattr",
348 6u16 => "Ops",
349 7u16 => "McastGroups",
350 8u16 => "Policy",
351 9u16 => "OpPolicy",
352 10u16 => "Op",
353 _ => return None,
354 };
355 Some(res)
356 }
357}
358#[derive(Clone, Copy, Default)]
359pub struct IterableCtrlAttrs<'a> {
360 buf: &'a [u8],
361 pos: usize,
362 orig_loc: usize,
363}
364impl<'a> IterableCtrlAttrs<'a> {
365 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
366 Self {
367 buf,
368 pos: 0,
369 orig_loc,
370 }
371 }
372 pub fn get_buf(&self) -> &'a [u8] {
373 self.buf
374 }
375}
376impl<'a> Iterator for IterableCtrlAttrs<'a> {
377 type Item = Result<CtrlAttrs<'a>, ErrorContext>;
378 fn next(&mut self) -> Option<Self::Item> {
379 let pos = self.pos;
380 let mut r#type;
381 loop {
382 r#type = None;
383 if self.buf.len() == self.pos {
384 return None;
385 }
386 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
387 break;
388 };
389 r#type = Some(header.r#type);
390 let res = match header.r#type {
391 1u16 => CtrlAttrs::FamilyId({
392 let res = parse_u16(next);
393 let Some(val) = res else { break };
394 val
395 }),
396 2u16 => CtrlAttrs::FamilyName({
397 let res = CStr::from_bytes_with_nul(next).ok();
398 let Some(val) = res else { break };
399 val
400 }),
401 3u16 => CtrlAttrs::Version({
402 let res = parse_u32(next);
403 let Some(val) = res else { break };
404 val
405 }),
406 4u16 => CtrlAttrs::Hdrsize({
407 let res = parse_u32(next);
408 let Some(val) = res else { break };
409 val
410 }),
411 5u16 => CtrlAttrs::Maxattr({
412 let res = parse_u32(next);
413 let Some(val) = res else { break };
414 val
415 }),
416 6u16 => CtrlAttrs::Ops({
417 let res = Some(IterableArrayOpAttrs::with_loc(next, self.orig_loc));
418 let Some(val) = res else { break };
419 val
420 }),
421 7u16 => CtrlAttrs::McastGroups({
422 let res = Some(IterableArrayMcastGroupAttrs::with_loc(next, self.orig_loc));
423 let Some(val) = res else { break };
424 val
425 }),
426 8u16 => CtrlAttrs::Policy({
427 let res = Some(IterablePolicyAttrs::with_loc(next, self.orig_loc));
428 let Some(val) = res else { break };
429 val
430 }),
431 9u16 => CtrlAttrs::OpPolicy({
432 let res = Some(IterableOpPolicyAttrs::with_loc(next, self.orig_loc));
433 let Some(val) = res else { break };
434 val
435 }),
436 10u16 => CtrlAttrs::Op({
437 let res = parse_u32(next);
438 let Some(val) = res else { break };
439 val
440 }),
441 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
442 n => continue,
443 };
444 return Some(Ok(res));
445 }
446 Some(Err(ErrorContext::new(
447 "CtrlAttrs",
448 r#type.and_then(|t| CtrlAttrs::attr_from_type(t)),
449 self.orig_loc,
450 self.buf.as_ptr().wrapping_add(pos) as usize,
451 )))
452 }
453}
454impl std::fmt::Debug for IterableArrayOpAttrs<'_> {
455 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
456 fmt.debug_list()
457 .entries(self.clone().map(FlattenErrorContext))
458 .finish()
459 }
460}
461impl std::fmt::Debug for IterableArrayMcastGroupAttrs<'_> {
462 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
463 fmt.debug_list()
464 .entries(self.clone().map(FlattenErrorContext))
465 .finish()
466 }
467}
468impl<'a> std::fmt::Debug for IterableCtrlAttrs<'_> {
469 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
470 let mut fmt = f.debug_struct("CtrlAttrs");
471 for attr in self.clone() {
472 let attr = match attr {
473 Ok(a) => a,
474 Err(err) => {
475 fmt.finish()?;
476 f.write_str("Err(")?;
477 err.fmt(f)?;
478 return f.write_str(")");
479 }
480 };
481 match attr {
482 CtrlAttrs::FamilyId(val) => fmt.field("FamilyId", &val),
483 CtrlAttrs::FamilyName(val) => fmt.field("FamilyName", &val),
484 CtrlAttrs::Version(val) => fmt.field("Version", &val),
485 CtrlAttrs::Hdrsize(val) => fmt.field("Hdrsize", &val),
486 CtrlAttrs::Maxattr(val) => fmt.field("Maxattr", &val),
487 CtrlAttrs::Ops(val) => fmt.field("Ops", &val),
488 CtrlAttrs::McastGroups(val) => fmt.field("McastGroups", &val),
489 CtrlAttrs::Policy(val) => fmt.field("Policy", &val),
490 CtrlAttrs::OpPolicy(val) => fmt.field("OpPolicy", &val),
491 CtrlAttrs::Op(val) => fmt.field("Op", &val),
492 };
493 }
494 fmt.finish()
495 }
496}
497impl IterableCtrlAttrs<'_> {
498 pub fn lookup_attr(
499 &self,
500 offset: usize,
501 missing_type: Option<u16>,
502 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
503 let mut stack = Vec::new();
504 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
505 if cur == offset {
506 stack.push(("CtrlAttrs", offset));
507 return (
508 stack,
509 missing_type.and_then(|t| CtrlAttrs::attr_from_type(t)),
510 );
511 }
512 if cur > offset || cur + self.buf.len() < offset {
513 return (stack, None);
514 }
515 let mut attrs = self.clone();
516 let mut last_off = cur + attrs.pos;
517 let mut missing = None;
518 while let Some(attr) = attrs.next() {
519 let Ok(attr) = attr else { break };
520 match attr {
521 CtrlAttrs::FamilyId(val) => {
522 if last_off == offset {
523 stack.push(("FamilyId", last_off));
524 break;
525 }
526 }
527 CtrlAttrs::FamilyName(val) => {
528 if last_off == offset {
529 stack.push(("FamilyName", last_off));
530 break;
531 }
532 }
533 CtrlAttrs::Version(val) => {
534 if last_off == offset {
535 stack.push(("Version", last_off));
536 break;
537 }
538 }
539 CtrlAttrs::Hdrsize(val) => {
540 if last_off == offset {
541 stack.push(("Hdrsize", last_off));
542 break;
543 }
544 }
545 CtrlAttrs::Maxattr(val) => {
546 if last_off == offset {
547 stack.push(("Maxattr", last_off));
548 break;
549 }
550 }
551 CtrlAttrs::Ops(val) => {
552 for entry in val {
553 let Ok(attr) = entry else { break };
554 (stack, missing) = attr.lookup_attr(offset, missing_type);
555 if !stack.is_empty() {
556 break;
557 }
558 }
559 if !stack.is_empty() {
560 stack.push(("Ops", last_off));
561 break;
562 }
563 }
564 CtrlAttrs::McastGroups(val) => {
565 for entry in val {
566 let Ok(attr) = entry else { break };
567 (stack, missing) = attr.lookup_attr(offset, missing_type);
568 if !stack.is_empty() {
569 break;
570 }
571 }
572 if !stack.is_empty() {
573 stack.push(("McastGroups", last_off));
574 break;
575 }
576 }
577 CtrlAttrs::Policy(val) => {
578 (stack, missing) = val.lookup_attr(offset, missing_type);
579 if !stack.is_empty() {
580 break;
581 }
582 }
583 CtrlAttrs::OpPolicy(val) => {
584 (stack, missing) = val.lookup_attr(offset, missing_type);
585 if !stack.is_empty() {
586 break;
587 }
588 }
589 CtrlAttrs::Op(val) => {
590 if last_off == offset {
591 stack.push(("Op", last_off));
592 break;
593 }
594 }
595 _ => {}
596 };
597 last_off = cur + attrs.pos;
598 }
599 if !stack.is_empty() {
600 stack.push(("CtrlAttrs", cur));
601 }
602 (stack, missing)
603 }
604}
605#[derive(Clone)]
606pub enum McastGroupAttrs<'a> {
607 Name(&'a CStr),
608 Id(u32),
609}
610impl<'a> IterableMcastGroupAttrs<'a> {
611 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
612 let mut iter = self.clone();
613 iter.pos = 0;
614 for attr in iter {
615 if let McastGroupAttrs::Name(val) = attr? {
616 return Ok(val);
617 }
618 }
619 Err(ErrorContext::new_missing(
620 "McastGroupAttrs",
621 "Name",
622 self.orig_loc,
623 self.buf.as_ptr() as usize,
624 ))
625 }
626 pub fn get_id(&self) -> Result<u32, ErrorContext> {
627 let mut iter = self.clone();
628 iter.pos = 0;
629 for attr in iter {
630 if let McastGroupAttrs::Id(val) = attr? {
631 return Ok(val);
632 }
633 }
634 Err(ErrorContext::new_missing(
635 "McastGroupAttrs",
636 "Id",
637 self.orig_loc,
638 self.buf.as_ptr() as usize,
639 ))
640 }
641}
642impl McastGroupAttrs<'_> {
643 pub fn new<'a>(buf: &'a [u8]) -> IterableMcastGroupAttrs<'a> {
644 IterableMcastGroupAttrs::with_loc(buf, buf.as_ptr() as usize)
645 }
646 fn attr_from_type(r#type: u16) -> Option<&'static str> {
647 let res = match r#type {
648 1u16 => "Name",
649 2u16 => "Id",
650 _ => return None,
651 };
652 Some(res)
653 }
654}
655#[derive(Clone, Copy, Default)]
656pub struct IterableMcastGroupAttrs<'a> {
657 buf: &'a [u8],
658 pos: usize,
659 orig_loc: usize,
660}
661impl<'a> IterableMcastGroupAttrs<'a> {
662 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
663 Self {
664 buf,
665 pos: 0,
666 orig_loc,
667 }
668 }
669 pub fn get_buf(&self) -> &'a [u8] {
670 self.buf
671 }
672}
673impl<'a> Iterator for IterableMcastGroupAttrs<'a> {
674 type Item = Result<McastGroupAttrs<'a>, ErrorContext>;
675 fn next(&mut self) -> Option<Self::Item> {
676 let pos = self.pos;
677 let mut r#type;
678 loop {
679 r#type = None;
680 if self.buf.len() == self.pos {
681 return None;
682 }
683 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
684 break;
685 };
686 r#type = Some(header.r#type);
687 let res = match header.r#type {
688 1u16 => McastGroupAttrs::Name({
689 let res = CStr::from_bytes_with_nul(next).ok();
690 let Some(val) = res else { break };
691 val
692 }),
693 2u16 => McastGroupAttrs::Id({
694 let res = parse_u32(next);
695 let Some(val) = res else { break };
696 val
697 }),
698 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
699 n => continue,
700 };
701 return Some(Ok(res));
702 }
703 Some(Err(ErrorContext::new(
704 "McastGroupAttrs",
705 r#type.and_then(|t| McastGroupAttrs::attr_from_type(t)),
706 self.orig_loc,
707 self.buf.as_ptr().wrapping_add(pos) as usize,
708 )))
709 }
710}
711impl<'a> std::fmt::Debug for IterableMcastGroupAttrs<'_> {
712 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
713 let mut fmt = f.debug_struct("McastGroupAttrs");
714 for attr in self.clone() {
715 let attr = match attr {
716 Ok(a) => a,
717 Err(err) => {
718 fmt.finish()?;
719 f.write_str("Err(")?;
720 err.fmt(f)?;
721 return f.write_str(")");
722 }
723 };
724 match attr {
725 McastGroupAttrs::Name(val) => fmt.field("Name", &val),
726 McastGroupAttrs::Id(val) => fmt.field("Id", &val),
727 };
728 }
729 fmt.finish()
730 }
731}
732impl IterableMcastGroupAttrs<'_> {
733 pub fn lookup_attr(
734 &self,
735 offset: usize,
736 missing_type: Option<u16>,
737 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
738 let mut stack = Vec::new();
739 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
740 if cur == offset {
741 stack.push(("McastGroupAttrs", offset));
742 return (
743 stack,
744 missing_type.and_then(|t| McastGroupAttrs::attr_from_type(t)),
745 );
746 }
747 if cur > offset || cur + self.buf.len() < offset {
748 return (stack, None);
749 }
750 let mut attrs = self.clone();
751 let mut last_off = cur + attrs.pos;
752 while let Some(attr) = attrs.next() {
753 let Ok(attr) = attr else { break };
754 match attr {
755 McastGroupAttrs::Name(val) => {
756 if last_off == offset {
757 stack.push(("Name", last_off));
758 break;
759 }
760 }
761 McastGroupAttrs::Id(val) => {
762 if last_off == offset {
763 stack.push(("Id", last_off));
764 break;
765 }
766 }
767 _ => {}
768 };
769 last_off = cur + attrs.pos;
770 }
771 if !stack.is_empty() {
772 stack.push(("McastGroupAttrs", cur));
773 }
774 (stack, None)
775 }
776}
777#[derive(Clone)]
778pub enum OpAttrs {
779 Id(u32),
780 #[doc = "Associated type: \"OpFlags\" (1 bit per enumeration)"]
781 Flags(u32),
782}
783impl<'a> IterableOpAttrs<'a> {
784 pub fn get_id(&self) -> Result<u32, ErrorContext> {
785 let mut iter = self.clone();
786 iter.pos = 0;
787 for attr in iter {
788 if let OpAttrs::Id(val) = attr? {
789 return Ok(val);
790 }
791 }
792 Err(ErrorContext::new_missing(
793 "OpAttrs",
794 "Id",
795 self.orig_loc,
796 self.buf.as_ptr() as usize,
797 ))
798 }
799 #[doc = "Associated type: \"OpFlags\" (1 bit per enumeration)"]
800 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
801 let mut iter = self.clone();
802 iter.pos = 0;
803 for attr in iter {
804 if let OpAttrs::Flags(val) = attr? {
805 return Ok(val);
806 }
807 }
808 Err(ErrorContext::new_missing(
809 "OpAttrs",
810 "Flags",
811 self.orig_loc,
812 self.buf.as_ptr() as usize,
813 ))
814 }
815}
816impl OpAttrs {
817 pub fn new<'a>(buf: &'a [u8]) -> IterableOpAttrs<'a> {
818 IterableOpAttrs::with_loc(buf, buf.as_ptr() as usize)
819 }
820 fn attr_from_type(r#type: u16) -> Option<&'static str> {
821 let res = match r#type {
822 1u16 => "Id",
823 2u16 => "Flags",
824 _ => return None,
825 };
826 Some(res)
827 }
828}
829#[derive(Clone, Copy, Default)]
830pub struct IterableOpAttrs<'a> {
831 buf: &'a [u8],
832 pos: usize,
833 orig_loc: usize,
834}
835impl<'a> IterableOpAttrs<'a> {
836 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
837 Self {
838 buf,
839 pos: 0,
840 orig_loc,
841 }
842 }
843 pub fn get_buf(&self) -> &'a [u8] {
844 self.buf
845 }
846}
847impl<'a> Iterator for IterableOpAttrs<'a> {
848 type Item = Result<OpAttrs, ErrorContext>;
849 fn next(&mut self) -> Option<Self::Item> {
850 let pos = self.pos;
851 let mut r#type;
852 loop {
853 r#type = None;
854 if self.buf.len() == self.pos {
855 return None;
856 }
857 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
858 break;
859 };
860 r#type = Some(header.r#type);
861 let res = match header.r#type {
862 1u16 => OpAttrs::Id({
863 let res = parse_u32(next);
864 let Some(val) = res else { break };
865 val
866 }),
867 2u16 => OpAttrs::Flags({
868 let res = parse_u32(next);
869 let Some(val) = res else { break };
870 val
871 }),
872 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
873 n => continue,
874 };
875 return Some(Ok(res));
876 }
877 Some(Err(ErrorContext::new(
878 "OpAttrs",
879 r#type.and_then(|t| OpAttrs::attr_from_type(t)),
880 self.orig_loc,
881 self.buf.as_ptr().wrapping_add(pos) as usize,
882 )))
883 }
884}
885impl std::fmt::Debug for IterableOpAttrs<'_> {
886 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
887 let mut fmt = f.debug_struct("OpAttrs");
888 for attr in self.clone() {
889 let attr = match attr {
890 Ok(a) => a,
891 Err(err) => {
892 fmt.finish()?;
893 f.write_str("Err(")?;
894 err.fmt(f)?;
895 return f.write_str(")");
896 }
897 };
898 match attr {
899 OpAttrs::Id(val) => fmt.field("Id", &val),
900 OpAttrs::Flags(val) => {
901 fmt.field("Flags", &FormatFlags(val.into(), OpFlags::from_value))
902 }
903 };
904 }
905 fmt.finish()
906 }
907}
908impl IterableOpAttrs<'_> {
909 pub fn lookup_attr(
910 &self,
911 offset: usize,
912 missing_type: Option<u16>,
913 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
914 let mut stack = Vec::new();
915 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
916 if cur == offset {
917 stack.push(("OpAttrs", offset));
918 return (stack, missing_type.and_then(|t| OpAttrs::attr_from_type(t)));
919 }
920 if cur > offset || cur + self.buf.len() < offset {
921 return (stack, None);
922 }
923 let mut attrs = self.clone();
924 let mut last_off = cur + attrs.pos;
925 while let Some(attr) = attrs.next() {
926 let Ok(attr) = attr else { break };
927 match attr {
928 OpAttrs::Id(val) => {
929 if last_off == offset {
930 stack.push(("Id", last_off));
931 break;
932 }
933 }
934 OpAttrs::Flags(val) => {
935 if last_off == offset {
936 stack.push(("Flags", last_off));
937 break;
938 }
939 }
940 _ => {}
941 };
942 last_off = cur + attrs.pos;
943 }
944 if !stack.is_empty() {
945 stack.push(("OpAttrs", cur));
946 }
947 (stack, None)
948 }
949}
950#[derive(Clone)]
951pub enum PolicyAttrs<'a> {
952 #[doc = "Associated type: \"AttrType\" (enum)"]
953 Type(u32),
954 MinValueS(i64),
955 MaxValueS(i64),
956 MinValueU(u64),
957 MaxValueU(u64),
958 MinLength(u32),
959 MaxLength(u32),
960 PolicyIdx(u32),
961 PolicyMaxtype(u32),
962 Bitfield32Mask(u32),
963 Mask(u64),
964 Pad(&'a [u8]),
965}
966impl<'a> IterablePolicyAttrs<'a> {
967 #[doc = "Associated type: \"AttrType\" (enum)"]
968 pub fn get_type(&self) -> Result<u32, ErrorContext> {
969 let mut iter = self.clone();
970 iter.pos = 0;
971 for attr in iter {
972 if let PolicyAttrs::Type(val) = attr? {
973 return Ok(val);
974 }
975 }
976 Err(ErrorContext::new_missing(
977 "PolicyAttrs",
978 "Type",
979 self.orig_loc,
980 self.buf.as_ptr() as usize,
981 ))
982 }
983 pub fn get_min_value_s(&self) -> Result<i64, ErrorContext> {
984 let mut iter = self.clone();
985 iter.pos = 0;
986 for attr in iter {
987 if let PolicyAttrs::MinValueS(val) = attr? {
988 return Ok(val);
989 }
990 }
991 Err(ErrorContext::new_missing(
992 "PolicyAttrs",
993 "MinValueS",
994 self.orig_loc,
995 self.buf.as_ptr() as usize,
996 ))
997 }
998 pub fn get_max_value_s(&self) -> Result<i64, ErrorContext> {
999 let mut iter = self.clone();
1000 iter.pos = 0;
1001 for attr in iter {
1002 if let PolicyAttrs::MaxValueS(val) = attr? {
1003 return Ok(val);
1004 }
1005 }
1006 Err(ErrorContext::new_missing(
1007 "PolicyAttrs",
1008 "MaxValueS",
1009 self.orig_loc,
1010 self.buf.as_ptr() as usize,
1011 ))
1012 }
1013 pub fn get_min_value_u(&self) -> Result<u64, ErrorContext> {
1014 let mut iter = self.clone();
1015 iter.pos = 0;
1016 for attr in iter {
1017 if let PolicyAttrs::MinValueU(val) = attr? {
1018 return Ok(val);
1019 }
1020 }
1021 Err(ErrorContext::new_missing(
1022 "PolicyAttrs",
1023 "MinValueU",
1024 self.orig_loc,
1025 self.buf.as_ptr() as usize,
1026 ))
1027 }
1028 pub fn get_max_value_u(&self) -> Result<u64, ErrorContext> {
1029 let mut iter = self.clone();
1030 iter.pos = 0;
1031 for attr in iter {
1032 if let PolicyAttrs::MaxValueU(val) = attr? {
1033 return Ok(val);
1034 }
1035 }
1036 Err(ErrorContext::new_missing(
1037 "PolicyAttrs",
1038 "MaxValueU",
1039 self.orig_loc,
1040 self.buf.as_ptr() as usize,
1041 ))
1042 }
1043 pub fn get_min_length(&self) -> Result<u32, ErrorContext> {
1044 let mut iter = self.clone();
1045 iter.pos = 0;
1046 for attr in iter {
1047 if let PolicyAttrs::MinLength(val) = attr? {
1048 return Ok(val);
1049 }
1050 }
1051 Err(ErrorContext::new_missing(
1052 "PolicyAttrs",
1053 "MinLength",
1054 self.orig_loc,
1055 self.buf.as_ptr() as usize,
1056 ))
1057 }
1058 pub fn get_max_length(&self) -> Result<u32, ErrorContext> {
1059 let mut iter = self.clone();
1060 iter.pos = 0;
1061 for attr in iter {
1062 if let PolicyAttrs::MaxLength(val) = attr? {
1063 return Ok(val);
1064 }
1065 }
1066 Err(ErrorContext::new_missing(
1067 "PolicyAttrs",
1068 "MaxLength",
1069 self.orig_loc,
1070 self.buf.as_ptr() as usize,
1071 ))
1072 }
1073 pub fn get_policy_idx(&self) -> Result<u32, ErrorContext> {
1074 let mut iter = self.clone();
1075 iter.pos = 0;
1076 for attr in iter {
1077 if let PolicyAttrs::PolicyIdx(val) = attr? {
1078 return Ok(val);
1079 }
1080 }
1081 Err(ErrorContext::new_missing(
1082 "PolicyAttrs",
1083 "PolicyIdx",
1084 self.orig_loc,
1085 self.buf.as_ptr() as usize,
1086 ))
1087 }
1088 pub fn get_policy_maxtype(&self) -> Result<u32, ErrorContext> {
1089 let mut iter = self.clone();
1090 iter.pos = 0;
1091 for attr in iter {
1092 if let PolicyAttrs::PolicyMaxtype(val) = attr? {
1093 return Ok(val);
1094 }
1095 }
1096 Err(ErrorContext::new_missing(
1097 "PolicyAttrs",
1098 "PolicyMaxtype",
1099 self.orig_loc,
1100 self.buf.as_ptr() as usize,
1101 ))
1102 }
1103 pub fn get_bitfield32_mask(&self) -> Result<u32, ErrorContext> {
1104 let mut iter = self.clone();
1105 iter.pos = 0;
1106 for attr in iter {
1107 if let PolicyAttrs::Bitfield32Mask(val) = attr? {
1108 return Ok(val);
1109 }
1110 }
1111 Err(ErrorContext::new_missing(
1112 "PolicyAttrs",
1113 "Bitfield32Mask",
1114 self.orig_loc,
1115 self.buf.as_ptr() as usize,
1116 ))
1117 }
1118 pub fn get_mask(&self) -> Result<u64, ErrorContext> {
1119 let mut iter = self.clone();
1120 iter.pos = 0;
1121 for attr in iter {
1122 if let PolicyAttrs::Mask(val) = attr? {
1123 return Ok(val);
1124 }
1125 }
1126 Err(ErrorContext::new_missing(
1127 "PolicyAttrs",
1128 "Mask",
1129 self.orig_loc,
1130 self.buf.as_ptr() as usize,
1131 ))
1132 }
1133 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
1134 let mut iter = self.clone();
1135 iter.pos = 0;
1136 for attr in iter {
1137 if let PolicyAttrs::Pad(val) = attr? {
1138 return Ok(val);
1139 }
1140 }
1141 Err(ErrorContext::new_missing(
1142 "PolicyAttrs",
1143 "Pad",
1144 self.orig_loc,
1145 self.buf.as_ptr() as usize,
1146 ))
1147 }
1148}
1149impl PolicyAttrs<'_> {
1150 pub fn new<'a>(buf: &'a [u8]) -> IterablePolicyAttrs<'a> {
1151 IterablePolicyAttrs::with_loc(buf, buf.as_ptr() as usize)
1152 }
1153 fn attr_from_type(r#type: u16) -> Option<&'static str> {
1154 let res = match r#type {
1155 1u16 => "Type",
1156 2u16 => "MinValueS",
1157 3u16 => "MaxValueS",
1158 4u16 => "MinValueU",
1159 5u16 => "MaxValueU",
1160 6u16 => "MinLength",
1161 7u16 => "MaxLength",
1162 8u16 => "PolicyIdx",
1163 9u16 => "PolicyMaxtype",
1164 10u16 => "Bitfield32Mask",
1165 11u16 => "Mask",
1166 12u16 => "Pad",
1167 _ => return None,
1168 };
1169 Some(res)
1170 }
1171}
1172#[derive(Clone, Copy, Default)]
1173pub struct IterablePolicyAttrs<'a> {
1174 buf: &'a [u8],
1175 pos: usize,
1176 orig_loc: usize,
1177}
1178impl<'a> IterablePolicyAttrs<'a> {
1179 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1180 Self {
1181 buf,
1182 pos: 0,
1183 orig_loc,
1184 }
1185 }
1186 pub fn get_buf(&self) -> &'a [u8] {
1187 self.buf
1188 }
1189}
1190impl<'a> Iterator for IterablePolicyAttrs<'a> {
1191 type Item = Result<PolicyAttrs<'a>, ErrorContext>;
1192 fn next(&mut self) -> Option<Self::Item> {
1193 let pos = self.pos;
1194 let mut r#type;
1195 loop {
1196 r#type = None;
1197 if self.buf.len() == self.pos {
1198 return None;
1199 }
1200 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
1201 break;
1202 };
1203 r#type = Some(header.r#type);
1204 let res = match header.r#type {
1205 1u16 => PolicyAttrs::Type({
1206 let res = parse_u32(next);
1207 let Some(val) = res else { break };
1208 val
1209 }),
1210 2u16 => PolicyAttrs::MinValueS({
1211 let res = parse_i64(next);
1212 let Some(val) = res else { break };
1213 val
1214 }),
1215 3u16 => PolicyAttrs::MaxValueS({
1216 let res = parse_i64(next);
1217 let Some(val) = res else { break };
1218 val
1219 }),
1220 4u16 => PolicyAttrs::MinValueU({
1221 let res = parse_u64(next);
1222 let Some(val) = res else { break };
1223 val
1224 }),
1225 5u16 => PolicyAttrs::MaxValueU({
1226 let res = parse_u64(next);
1227 let Some(val) = res else { break };
1228 val
1229 }),
1230 6u16 => PolicyAttrs::MinLength({
1231 let res = parse_u32(next);
1232 let Some(val) = res else { break };
1233 val
1234 }),
1235 7u16 => PolicyAttrs::MaxLength({
1236 let res = parse_u32(next);
1237 let Some(val) = res else { break };
1238 val
1239 }),
1240 8u16 => PolicyAttrs::PolicyIdx({
1241 let res = parse_u32(next);
1242 let Some(val) = res else { break };
1243 val
1244 }),
1245 9u16 => PolicyAttrs::PolicyMaxtype({
1246 let res = parse_u32(next);
1247 let Some(val) = res else { break };
1248 val
1249 }),
1250 10u16 => PolicyAttrs::Bitfield32Mask({
1251 let res = parse_u32(next);
1252 let Some(val) = res else { break };
1253 val
1254 }),
1255 11u16 => PolicyAttrs::Mask({
1256 let res = parse_u64(next);
1257 let Some(val) = res else { break };
1258 val
1259 }),
1260 12u16 => PolicyAttrs::Pad({
1261 let res = Some(next);
1262 let Some(val) = res else { break };
1263 val
1264 }),
1265 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
1266 n => continue,
1267 };
1268 return Some(Ok(res));
1269 }
1270 Some(Err(ErrorContext::new(
1271 "PolicyAttrs",
1272 r#type.and_then(|t| PolicyAttrs::attr_from_type(t)),
1273 self.orig_loc,
1274 self.buf.as_ptr().wrapping_add(pos) as usize,
1275 )))
1276 }
1277}
1278impl<'a> std::fmt::Debug for IterablePolicyAttrs<'_> {
1279 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1280 let mut fmt = f.debug_struct("PolicyAttrs");
1281 for attr in self.clone() {
1282 let attr = match attr {
1283 Ok(a) => a,
1284 Err(err) => {
1285 fmt.finish()?;
1286 f.write_str("Err(")?;
1287 err.fmt(f)?;
1288 return f.write_str(")");
1289 }
1290 };
1291 match attr {
1292 PolicyAttrs::Type(val) => {
1293 fmt.field("Type", &FormatEnum(val.into(), AttrType::from_value))
1294 }
1295 PolicyAttrs::MinValueS(val) => fmt.field("MinValueS", &val),
1296 PolicyAttrs::MaxValueS(val) => fmt.field("MaxValueS", &val),
1297 PolicyAttrs::MinValueU(val) => fmt.field("MinValueU", &val),
1298 PolicyAttrs::MaxValueU(val) => fmt.field("MaxValueU", &val),
1299 PolicyAttrs::MinLength(val) => fmt.field("MinLength", &val),
1300 PolicyAttrs::MaxLength(val) => fmt.field("MaxLength", &val),
1301 PolicyAttrs::PolicyIdx(val) => fmt.field("PolicyIdx", &val),
1302 PolicyAttrs::PolicyMaxtype(val) => fmt.field("PolicyMaxtype", &val),
1303 PolicyAttrs::Bitfield32Mask(val) => fmt.field("Bitfield32Mask", &val),
1304 PolicyAttrs::Mask(val) => fmt.field("Mask", &val),
1305 PolicyAttrs::Pad(val) => fmt.field("Pad", &val),
1306 };
1307 }
1308 fmt.finish()
1309 }
1310}
1311impl IterablePolicyAttrs<'_> {
1312 pub fn lookup_attr(
1313 &self,
1314 offset: usize,
1315 missing_type: Option<u16>,
1316 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
1317 let mut stack = Vec::new();
1318 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
1319 if cur == offset {
1320 stack.push(("PolicyAttrs", offset));
1321 return (
1322 stack,
1323 missing_type.and_then(|t| PolicyAttrs::attr_from_type(t)),
1324 );
1325 }
1326 if cur > offset || cur + self.buf.len() < offset {
1327 return (stack, None);
1328 }
1329 let mut attrs = self.clone();
1330 let mut last_off = cur + attrs.pos;
1331 while let Some(attr) = attrs.next() {
1332 let Ok(attr) = attr else { break };
1333 match attr {
1334 PolicyAttrs::Type(val) => {
1335 if last_off == offset {
1336 stack.push(("Type", last_off));
1337 break;
1338 }
1339 }
1340 PolicyAttrs::MinValueS(val) => {
1341 if last_off == offset {
1342 stack.push(("MinValueS", last_off));
1343 break;
1344 }
1345 }
1346 PolicyAttrs::MaxValueS(val) => {
1347 if last_off == offset {
1348 stack.push(("MaxValueS", last_off));
1349 break;
1350 }
1351 }
1352 PolicyAttrs::MinValueU(val) => {
1353 if last_off == offset {
1354 stack.push(("MinValueU", last_off));
1355 break;
1356 }
1357 }
1358 PolicyAttrs::MaxValueU(val) => {
1359 if last_off == offset {
1360 stack.push(("MaxValueU", last_off));
1361 break;
1362 }
1363 }
1364 PolicyAttrs::MinLength(val) => {
1365 if last_off == offset {
1366 stack.push(("MinLength", last_off));
1367 break;
1368 }
1369 }
1370 PolicyAttrs::MaxLength(val) => {
1371 if last_off == offset {
1372 stack.push(("MaxLength", last_off));
1373 break;
1374 }
1375 }
1376 PolicyAttrs::PolicyIdx(val) => {
1377 if last_off == offset {
1378 stack.push(("PolicyIdx", last_off));
1379 break;
1380 }
1381 }
1382 PolicyAttrs::PolicyMaxtype(val) => {
1383 if last_off == offset {
1384 stack.push(("PolicyMaxtype", last_off));
1385 break;
1386 }
1387 }
1388 PolicyAttrs::Bitfield32Mask(val) => {
1389 if last_off == offset {
1390 stack.push(("Bitfield32Mask", last_off));
1391 break;
1392 }
1393 }
1394 PolicyAttrs::Mask(val) => {
1395 if last_off == offset {
1396 stack.push(("Mask", last_off));
1397 break;
1398 }
1399 }
1400 PolicyAttrs::Pad(val) => {
1401 if last_off == offset {
1402 stack.push(("Pad", last_off));
1403 break;
1404 }
1405 }
1406 _ => {}
1407 };
1408 last_off = cur + attrs.pos;
1409 }
1410 if !stack.is_empty() {
1411 stack.push(("PolicyAttrs", cur));
1412 }
1413 (stack, None)
1414 }
1415}
1416#[derive(Clone)]
1417pub enum OpPolicyAttrs {
1418 Do(u32),
1419 Dump(u32),
1420}
1421impl<'a> IterableOpPolicyAttrs<'a> {
1422 pub fn get_do(&self) -> Result<u32, ErrorContext> {
1423 let mut iter = self.clone();
1424 iter.pos = 0;
1425 for attr in iter {
1426 if let OpPolicyAttrs::Do(val) = attr? {
1427 return Ok(val);
1428 }
1429 }
1430 Err(ErrorContext::new_missing(
1431 "OpPolicyAttrs",
1432 "Do",
1433 self.orig_loc,
1434 self.buf.as_ptr() as usize,
1435 ))
1436 }
1437 pub fn get_dump(&self) -> Result<u32, ErrorContext> {
1438 let mut iter = self.clone();
1439 iter.pos = 0;
1440 for attr in iter {
1441 if let OpPolicyAttrs::Dump(val) = attr? {
1442 return Ok(val);
1443 }
1444 }
1445 Err(ErrorContext::new_missing(
1446 "OpPolicyAttrs",
1447 "Dump",
1448 self.orig_loc,
1449 self.buf.as_ptr() as usize,
1450 ))
1451 }
1452}
1453impl OpPolicyAttrs {
1454 pub fn new<'a>(buf: &'a [u8]) -> IterableOpPolicyAttrs<'a> {
1455 IterableOpPolicyAttrs::with_loc(buf, buf.as_ptr() as usize)
1456 }
1457 fn attr_from_type(r#type: u16) -> Option<&'static str> {
1458 let res = match r#type {
1459 1u16 => "Do",
1460 2u16 => "Dump",
1461 _ => return None,
1462 };
1463 Some(res)
1464 }
1465}
1466#[derive(Clone, Copy, Default)]
1467pub struct IterableOpPolicyAttrs<'a> {
1468 buf: &'a [u8],
1469 pos: usize,
1470 orig_loc: usize,
1471}
1472impl<'a> IterableOpPolicyAttrs<'a> {
1473 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1474 Self {
1475 buf,
1476 pos: 0,
1477 orig_loc,
1478 }
1479 }
1480 pub fn get_buf(&self) -> &'a [u8] {
1481 self.buf
1482 }
1483}
1484impl<'a> Iterator for IterableOpPolicyAttrs<'a> {
1485 type Item = Result<OpPolicyAttrs, ErrorContext>;
1486 fn next(&mut self) -> Option<Self::Item> {
1487 let pos = self.pos;
1488 let mut r#type;
1489 loop {
1490 r#type = None;
1491 if self.buf.len() == self.pos {
1492 return None;
1493 }
1494 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
1495 break;
1496 };
1497 r#type = Some(header.r#type);
1498 let res = match header.r#type {
1499 1u16 => OpPolicyAttrs::Do({
1500 let res = parse_u32(next);
1501 let Some(val) = res else { break };
1502 val
1503 }),
1504 2u16 => OpPolicyAttrs::Dump({
1505 let res = parse_u32(next);
1506 let Some(val) = res else { break };
1507 val
1508 }),
1509 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
1510 n => continue,
1511 };
1512 return Some(Ok(res));
1513 }
1514 Some(Err(ErrorContext::new(
1515 "OpPolicyAttrs",
1516 r#type.and_then(|t| OpPolicyAttrs::attr_from_type(t)),
1517 self.orig_loc,
1518 self.buf.as_ptr().wrapping_add(pos) as usize,
1519 )))
1520 }
1521}
1522impl std::fmt::Debug for IterableOpPolicyAttrs<'_> {
1523 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1524 let mut fmt = f.debug_struct("OpPolicyAttrs");
1525 for attr in self.clone() {
1526 let attr = match attr {
1527 Ok(a) => a,
1528 Err(err) => {
1529 fmt.finish()?;
1530 f.write_str("Err(")?;
1531 err.fmt(f)?;
1532 return f.write_str(")");
1533 }
1534 };
1535 match attr {
1536 OpPolicyAttrs::Do(val) => fmt.field("Do", &val),
1537 OpPolicyAttrs::Dump(val) => fmt.field("Dump", &val),
1538 };
1539 }
1540 fmt.finish()
1541 }
1542}
1543impl IterableOpPolicyAttrs<'_> {
1544 pub fn lookup_attr(
1545 &self,
1546 offset: usize,
1547 missing_type: Option<u16>,
1548 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
1549 let mut stack = Vec::new();
1550 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
1551 if cur == offset {
1552 stack.push(("OpPolicyAttrs", offset));
1553 return (
1554 stack,
1555 missing_type.and_then(|t| OpPolicyAttrs::attr_from_type(t)),
1556 );
1557 }
1558 if cur > offset || cur + self.buf.len() < offset {
1559 return (stack, None);
1560 }
1561 let mut attrs = self.clone();
1562 let mut last_off = cur + attrs.pos;
1563 while let Some(attr) = attrs.next() {
1564 let Ok(attr) = attr else { break };
1565 match attr {
1566 OpPolicyAttrs::Do(val) => {
1567 if last_off == offset {
1568 stack.push(("Do", last_off));
1569 break;
1570 }
1571 }
1572 OpPolicyAttrs::Dump(val) => {
1573 if last_off == offset {
1574 stack.push(("Dump", last_off));
1575 break;
1576 }
1577 }
1578 _ => {}
1579 };
1580 last_off = cur + attrs.pos;
1581 }
1582 if !stack.is_empty() {
1583 stack.push(("OpPolicyAttrs", cur));
1584 }
1585 (stack, None)
1586 }
1587}
1588pub struct PushCtrlAttrs<Prev: Rec> {
1589 pub(crate) prev: Option<Prev>,
1590 pub(crate) header_offset: Option<usize>,
1591}
1592impl<Prev: Rec> Rec for PushCtrlAttrs<Prev> {
1593 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
1594 self.prev.as_mut().unwrap().as_rec_mut()
1595 }
1596 fn as_rec(&self) -> &Vec<u8> {
1597 self.prev.as_ref().unwrap().as_rec()
1598 }
1599}
1600pub struct PushArrayOpAttrs<Prev: Rec> {
1601 pub(crate) prev: Option<Prev>,
1602 pub(crate) header_offset: Option<usize>,
1603 pub(crate) counter: u16,
1604}
1605impl<Prev: Rec> Rec for PushArrayOpAttrs<Prev> {
1606 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
1607 self.prev.as_mut().unwrap().as_rec_mut()
1608 }
1609 fn as_rec(&self) -> &Vec<u8> {
1610 self.prev.as_ref().unwrap().as_rec()
1611 }
1612}
1613impl<Prev: Rec> PushArrayOpAttrs<Prev> {
1614 pub fn new(prev: Prev) -> Self {
1615 Self {
1616 prev: Some(prev),
1617 header_offset: None,
1618 counter: 0,
1619 }
1620 }
1621 pub fn end_array(mut self) -> Prev {
1622 let mut prev = self.prev.take().unwrap();
1623 if let Some(header_offset) = &self.header_offset {
1624 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1625 }
1626 prev
1627 }
1628 pub fn entry_nested(mut self) -> PushOpAttrs<Self> {
1629 let index = self.counter;
1630 self.counter += 1;
1631 let header_offset = push_nested_header(self.as_rec_mut(), index);
1632 PushOpAttrs {
1633 prev: Some(self),
1634 header_offset: Some(header_offset),
1635 }
1636 }
1637}
1638impl<Prev: Rec> Drop for PushArrayOpAttrs<Prev> {
1639 fn drop(&mut self) {
1640 if let Some(prev) = &mut self.prev {
1641 if let Some(header_offset) = &self.header_offset {
1642 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1643 }
1644 }
1645 }
1646}
1647pub struct PushArrayMcastGroupAttrs<Prev: Rec> {
1648 pub(crate) prev: Option<Prev>,
1649 pub(crate) header_offset: Option<usize>,
1650 pub(crate) counter: u16,
1651}
1652impl<Prev: Rec> Rec for PushArrayMcastGroupAttrs<Prev> {
1653 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
1654 self.prev.as_mut().unwrap().as_rec_mut()
1655 }
1656 fn as_rec(&self) -> &Vec<u8> {
1657 self.prev.as_ref().unwrap().as_rec()
1658 }
1659}
1660impl<Prev: Rec> PushArrayMcastGroupAttrs<Prev> {
1661 pub fn new(prev: Prev) -> Self {
1662 Self {
1663 prev: Some(prev),
1664 header_offset: None,
1665 counter: 0,
1666 }
1667 }
1668 pub fn end_array(mut self) -> Prev {
1669 let mut prev = self.prev.take().unwrap();
1670 if let Some(header_offset) = &self.header_offset {
1671 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1672 }
1673 prev
1674 }
1675 pub fn entry_nested(mut self) -> PushMcastGroupAttrs<Self> {
1676 let index = self.counter;
1677 self.counter += 1;
1678 let header_offset = push_nested_header(self.as_rec_mut(), index);
1679 PushMcastGroupAttrs {
1680 prev: Some(self),
1681 header_offset: Some(header_offset),
1682 }
1683 }
1684}
1685impl<Prev: Rec> Drop for PushArrayMcastGroupAttrs<Prev> {
1686 fn drop(&mut self) {
1687 if let Some(prev) = &mut self.prev {
1688 if let Some(header_offset) = &self.header_offset {
1689 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1690 }
1691 }
1692 }
1693}
1694impl<Prev: Rec> PushCtrlAttrs<Prev> {
1695 pub fn new(prev: Prev) -> Self {
1696 Self {
1697 prev: Some(prev),
1698 header_offset: None,
1699 }
1700 }
1701 pub fn end_nested(mut self) -> Prev {
1702 let mut prev = self.prev.take().unwrap();
1703 if let Some(header_offset) = &self.header_offset {
1704 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1705 }
1706 prev
1707 }
1708 pub fn push_family_id(mut self, value: u16) -> Self {
1709 push_header(self.as_rec_mut(), 1u16, 2 as u16);
1710 self.as_rec_mut().extend(value.to_ne_bytes());
1711 self
1712 }
1713 pub fn push_family_name(mut self, value: &CStr) -> Self {
1714 push_header(
1715 self.as_rec_mut(),
1716 2u16,
1717 value.to_bytes_with_nul().len() as u16,
1718 );
1719 self.as_rec_mut().extend(value.to_bytes_with_nul());
1720 self
1721 }
1722 pub fn push_family_name_bytes(mut self, value: &[u8]) -> Self {
1723 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
1724 self.as_rec_mut().extend(value);
1725 self.as_rec_mut().push(0);
1726 self
1727 }
1728 pub fn push_version(mut self, value: u32) -> Self {
1729 push_header(self.as_rec_mut(), 3u16, 4 as u16);
1730 self.as_rec_mut().extend(value.to_ne_bytes());
1731 self
1732 }
1733 pub fn push_hdrsize(mut self, value: u32) -> Self {
1734 push_header(self.as_rec_mut(), 4u16, 4 as u16);
1735 self.as_rec_mut().extend(value.to_ne_bytes());
1736 self
1737 }
1738 pub fn push_maxattr(mut self, value: u32) -> Self {
1739 push_header(self.as_rec_mut(), 5u16, 4 as u16);
1740 self.as_rec_mut().extend(value.to_ne_bytes());
1741 self
1742 }
1743 pub fn array_ops(mut self) -> PushArrayOpAttrs<Self> {
1744 let header_offset = push_nested_header(self.as_rec_mut(), 6u16);
1745 PushArrayOpAttrs {
1746 prev: Some(self),
1747 header_offset: Some(header_offset),
1748 counter: 0,
1749 }
1750 }
1751 pub fn array_mcast_groups(mut self) -> PushArrayMcastGroupAttrs<Self> {
1752 let header_offset = push_nested_header(self.as_rec_mut(), 7u16);
1753 PushArrayMcastGroupAttrs {
1754 prev: Some(self),
1755 header_offset: Some(header_offset),
1756 counter: 0,
1757 }
1758 }
1759 pub fn nested_policy(mut self) -> PushPolicyAttrs<Self> {
1760 let header_offset = push_nested_header(self.as_rec_mut(), 8u16);
1761 PushPolicyAttrs {
1762 prev: Some(self),
1763 header_offset: Some(header_offset),
1764 }
1765 }
1766 pub fn nested_op_policy(mut self) -> PushOpPolicyAttrs<Self> {
1767 let header_offset = push_nested_header(self.as_rec_mut(), 9u16);
1768 PushOpPolicyAttrs {
1769 prev: Some(self),
1770 header_offset: Some(header_offset),
1771 }
1772 }
1773 pub fn push_op(mut self, value: u32) -> Self {
1774 push_header(self.as_rec_mut(), 10u16, 4 as u16);
1775 self.as_rec_mut().extend(value.to_ne_bytes());
1776 self
1777 }
1778}
1779impl<Prev: Rec> Drop for PushCtrlAttrs<Prev> {
1780 fn drop(&mut self) {
1781 if let Some(prev) = &mut self.prev {
1782 if let Some(header_offset) = &self.header_offset {
1783 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1784 }
1785 }
1786 }
1787}
1788pub struct PushMcastGroupAttrs<Prev: Rec> {
1789 pub(crate) prev: Option<Prev>,
1790 pub(crate) header_offset: Option<usize>,
1791}
1792impl<Prev: Rec> Rec for PushMcastGroupAttrs<Prev> {
1793 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
1794 self.prev.as_mut().unwrap().as_rec_mut()
1795 }
1796 fn as_rec(&self) -> &Vec<u8> {
1797 self.prev.as_ref().unwrap().as_rec()
1798 }
1799}
1800impl<Prev: Rec> PushMcastGroupAttrs<Prev> {
1801 pub fn new(prev: Prev) -> Self {
1802 Self {
1803 prev: Some(prev),
1804 header_offset: None,
1805 }
1806 }
1807 pub fn end_nested(mut self) -> Prev {
1808 let mut prev = self.prev.take().unwrap();
1809 if let Some(header_offset) = &self.header_offset {
1810 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1811 }
1812 prev
1813 }
1814 pub fn push_name(mut self, value: &CStr) -> Self {
1815 push_header(
1816 self.as_rec_mut(),
1817 1u16,
1818 value.to_bytes_with_nul().len() as u16,
1819 );
1820 self.as_rec_mut().extend(value.to_bytes_with_nul());
1821 self
1822 }
1823 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
1824 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
1825 self.as_rec_mut().extend(value);
1826 self.as_rec_mut().push(0);
1827 self
1828 }
1829 pub fn push_id(mut self, value: u32) -> Self {
1830 push_header(self.as_rec_mut(), 2u16, 4 as u16);
1831 self.as_rec_mut().extend(value.to_ne_bytes());
1832 self
1833 }
1834}
1835impl<Prev: Rec> Drop for PushMcastGroupAttrs<Prev> {
1836 fn drop(&mut self) {
1837 if let Some(prev) = &mut self.prev {
1838 if let Some(header_offset) = &self.header_offset {
1839 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1840 }
1841 }
1842 }
1843}
1844pub struct PushOpAttrs<Prev: Rec> {
1845 pub(crate) prev: Option<Prev>,
1846 pub(crate) header_offset: Option<usize>,
1847}
1848impl<Prev: Rec> Rec for PushOpAttrs<Prev> {
1849 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
1850 self.prev.as_mut().unwrap().as_rec_mut()
1851 }
1852 fn as_rec(&self) -> &Vec<u8> {
1853 self.prev.as_ref().unwrap().as_rec()
1854 }
1855}
1856impl<Prev: Rec> PushOpAttrs<Prev> {
1857 pub fn new(prev: Prev) -> Self {
1858 Self {
1859 prev: Some(prev),
1860 header_offset: None,
1861 }
1862 }
1863 pub fn end_nested(mut self) -> Prev {
1864 let mut prev = self.prev.take().unwrap();
1865 if let Some(header_offset) = &self.header_offset {
1866 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1867 }
1868 prev
1869 }
1870 pub fn push_id(mut self, value: u32) -> Self {
1871 push_header(self.as_rec_mut(), 1u16, 4 as u16);
1872 self.as_rec_mut().extend(value.to_ne_bytes());
1873 self
1874 }
1875 #[doc = "Associated type: \"OpFlags\" (1 bit per enumeration)"]
1876 pub fn push_flags(mut self, value: u32) -> Self {
1877 push_header(self.as_rec_mut(), 2u16, 4 as u16);
1878 self.as_rec_mut().extend(value.to_ne_bytes());
1879 self
1880 }
1881}
1882impl<Prev: Rec> Drop for PushOpAttrs<Prev> {
1883 fn drop(&mut self) {
1884 if let Some(prev) = &mut self.prev {
1885 if let Some(header_offset) = &self.header_offset {
1886 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1887 }
1888 }
1889 }
1890}
1891pub struct PushPolicyAttrs<Prev: Rec> {
1892 pub(crate) prev: Option<Prev>,
1893 pub(crate) header_offset: Option<usize>,
1894}
1895impl<Prev: Rec> Rec for PushPolicyAttrs<Prev> {
1896 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
1897 self.prev.as_mut().unwrap().as_rec_mut()
1898 }
1899 fn as_rec(&self) -> &Vec<u8> {
1900 self.prev.as_ref().unwrap().as_rec()
1901 }
1902}
1903impl<Prev: Rec> PushPolicyAttrs<Prev> {
1904 pub fn new(prev: Prev) -> Self {
1905 Self {
1906 prev: Some(prev),
1907 header_offset: None,
1908 }
1909 }
1910 pub fn end_nested(mut self) -> Prev {
1911 let mut prev = self.prev.take().unwrap();
1912 if let Some(header_offset) = &self.header_offset {
1913 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1914 }
1915 prev
1916 }
1917 #[doc = "Associated type: \"AttrType\" (enum)"]
1918 pub fn push_type(mut self, value: u32) -> Self {
1919 push_header(self.as_rec_mut(), 1u16, 4 as u16);
1920 self.as_rec_mut().extend(value.to_ne_bytes());
1921 self
1922 }
1923 pub fn push_min_value_s(mut self, value: i64) -> Self {
1924 push_header(self.as_rec_mut(), 2u16, 8 as u16);
1925 self.as_rec_mut().extend(value.to_ne_bytes());
1926 self
1927 }
1928 pub fn push_max_value_s(mut self, value: i64) -> Self {
1929 push_header(self.as_rec_mut(), 3u16, 8 as u16);
1930 self.as_rec_mut().extend(value.to_ne_bytes());
1931 self
1932 }
1933 pub fn push_min_value_u(mut self, value: u64) -> Self {
1934 push_header(self.as_rec_mut(), 4u16, 8 as u16);
1935 self.as_rec_mut().extend(value.to_ne_bytes());
1936 self
1937 }
1938 pub fn push_max_value_u(mut self, value: u64) -> Self {
1939 push_header(self.as_rec_mut(), 5u16, 8 as u16);
1940 self.as_rec_mut().extend(value.to_ne_bytes());
1941 self
1942 }
1943 pub fn push_min_length(mut self, value: u32) -> Self {
1944 push_header(self.as_rec_mut(), 6u16, 4 as u16);
1945 self.as_rec_mut().extend(value.to_ne_bytes());
1946 self
1947 }
1948 pub fn push_max_length(mut self, value: u32) -> Self {
1949 push_header(self.as_rec_mut(), 7u16, 4 as u16);
1950 self.as_rec_mut().extend(value.to_ne_bytes());
1951 self
1952 }
1953 pub fn push_policy_idx(mut self, value: u32) -> Self {
1954 push_header(self.as_rec_mut(), 8u16, 4 as u16);
1955 self.as_rec_mut().extend(value.to_ne_bytes());
1956 self
1957 }
1958 pub fn push_policy_maxtype(mut self, value: u32) -> Self {
1959 push_header(self.as_rec_mut(), 9u16, 4 as u16);
1960 self.as_rec_mut().extend(value.to_ne_bytes());
1961 self
1962 }
1963 pub fn push_bitfield32_mask(mut self, value: u32) -> Self {
1964 push_header(self.as_rec_mut(), 10u16, 4 as u16);
1965 self.as_rec_mut().extend(value.to_ne_bytes());
1966 self
1967 }
1968 pub fn push_mask(mut self, value: u64) -> Self {
1969 push_header(self.as_rec_mut(), 11u16, 8 as u16);
1970 self.as_rec_mut().extend(value.to_ne_bytes());
1971 self
1972 }
1973 pub fn push_pad(mut self, value: &[u8]) -> Self {
1974 push_header(self.as_rec_mut(), 12u16, value.len() as u16);
1975 self.as_rec_mut().extend(value);
1976 self
1977 }
1978}
1979impl<Prev: Rec> Drop for PushPolicyAttrs<Prev> {
1980 fn drop(&mut self) {
1981 if let Some(prev) = &mut self.prev {
1982 if let Some(header_offset) = &self.header_offset {
1983 finalize_nested_header(prev.as_rec_mut(), *header_offset);
1984 }
1985 }
1986 }
1987}
1988pub struct PushOpPolicyAttrs<Prev: Rec> {
1989 pub(crate) prev: Option<Prev>,
1990 pub(crate) header_offset: Option<usize>,
1991}
1992impl<Prev: Rec> Rec for PushOpPolicyAttrs<Prev> {
1993 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
1994 self.prev.as_mut().unwrap().as_rec_mut()
1995 }
1996 fn as_rec(&self) -> &Vec<u8> {
1997 self.prev.as_ref().unwrap().as_rec()
1998 }
1999}
2000impl<Prev: Rec> PushOpPolicyAttrs<Prev> {
2001 pub fn new(prev: Prev) -> Self {
2002 Self {
2003 prev: Some(prev),
2004 header_offset: None,
2005 }
2006 }
2007 pub fn end_nested(mut self) -> Prev {
2008 let mut prev = self.prev.take().unwrap();
2009 if let Some(header_offset) = &self.header_offset {
2010 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2011 }
2012 prev
2013 }
2014 pub fn push_do(mut self, value: u32) -> Self {
2015 push_header(self.as_rec_mut(), 1u16, 4 as u16);
2016 self.as_rec_mut().extend(value.to_ne_bytes());
2017 self
2018 }
2019 pub fn push_dump(mut self, value: u32) -> Self {
2020 push_header(self.as_rec_mut(), 2u16, 4 as u16);
2021 self.as_rec_mut().extend(value.to_ne_bytes());
2022 self
2023 }
2024}
2025impl<Prev: Rec> Drop for PushOpPolicyAttrs<Prev> {
2026 fn drop(&mut self) {
2027 if let Some(prev) = &mut self.prev {
2028 if let Some(header_offset) = &self.header_offset {
2029 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2030 }
2031 }
2032 }
2033}
2034#[doc = "Get / dump genetlink families"]
2035pub struct PushOpGetfamilyDumpRequest<Prev: Rec> {
2036 pub(crate) prev: Option<Prev>,
2037 pub(crate) header_offset: Option<usize>,
2038}
2039impl<Prev: Rec> Rec for PushOpGetfamilyDumpRequest<Prev> {
2040 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
2041 self.prev.as_mut().unwrap().as_rec_mut()
2042 }
2043 fn as_rec(&self) -> &Vec<u8> {
2044 self.prev.as_ref().unwrap().as_rec()
2045 }
2046}
2047impl<Prev: Rec> PushOpGetfamilyDumpRequest<Prev> {
2048 pub fn new(mut prev: Prev) -> Self {
2049 Self::write_header(&mut prev);
2050 Self::new_without_header(prev)
2051 }
2052 fn new_without_header(prev: Prev) -> Self {
2053 Self {
2054 prev: Some(prev),
2055 header_offset: None,
2056 }
2057 }
2058 fn write_header(prev: &mut Prev) {
2059 let mut header = PushBuiltinNfgenmsg::new();
2060 header.set_cmd(3u8);
2061 header.set_version(1u8);
2062 prev.as_rec_mut().extend(header.as_slice());
2063 }
2064 pub fn end_nested(mut self) -> Prev {
2065 let mut prev = self.prev.take().unwrap();
2066 if let Some(header_offset) = &self.header_offset {
2067 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2068 }
2069 prev
2070 }
2071}
2072impl<Prev: Rec> Drop for PushOpGetfamilyDumpRequest<Prev> {
2073 fn drop(&mut self) {
2074 if let Some(prev) = &mut self.prev {
2075 if let Some(header_offset) = &self.header_offset {
2076 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2077 }
2078 }
2079 }
2080}
2081#[doc = "Get / dump genetlink families"]
2082#[derive(Clone)]
2083pub enum OpGetfamilyDumpRequest {}
2084impl<'a> IterableOpGetfamilyDumpRequest<'a> {}
2085impl OpGetfamilyDumpRequest {
2086 pub fn new<'a>(buf: &'a [u8]) -> IterableOpGetfamilyDumpRequest<'a> {
2087 let (_header, attrs) = buf.split_at(buf.len().min(PushBuiltinNfgenmsg::len()));
2088 IterableOpGetfamilyDumpRequest::with_loc(attrs, buf.as_ptr() as usize)
2089 }
2090 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2091 CtrlAttrs::attr_from_type(r#type)
2092 }
2093}
2094#[derive(Clone, Copy, Default)]
2095pub struct IterableOpGetfamilyDumpRequest<'a> {
2096 buf: &'a [u8],
2097 pos: usize,
2098 orig_loc: usize,
2099}
2100impl<'a> IterableOpGetfamilyDumpRequest<'a> {
2101 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2102 Self {
2103 buf,
2104 pos: 0,
2105 orig_loc,
2106 }
2107 }
2108 pub fn get_buf(&self) -> &'a [u8] {
2109 self.buf
2110 }
2111}
2112impl<'a> Iterator for IterableOpGetfamilyDumpRequest<'a> {
2113 type Item = Result<OpGetfamilyDumpRequest, ErrorContext>;
2114 fn next(&mut self) -> Option<Self::Item> {
2115 let pos = self.pos;
2116 let mut r#type;
2117 loop {
2118 r#type = None;
2119 if self.buf.len() == self.pos {
2120 return None;
2121 }
2122 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
2123 break;
2124 };
2125 r#type = Some(header.r#type);
2126 let res = match header.r#type {
2127 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
2128 n => continue,
2129 };
2130 return Some(Ok(res));
2131 }
2132 Some(Err(ErrorContext::new(
2133 "OpGetfamilyDumpRequest",
2134 r#type.and_then(|t| OpGetfamilyDumpRequest::attr_from_type(t)),
2135 self.orig_loc,
2136 self.buf.as_ptr().wrapping_add(pos) as usize,
2137 )))
2138 }
2139}
2140impl std::fmt::Debug for IterableOpGetfamilyDumpRequest<'_> {
2141 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2142 let mut fmt = f.debug_struct("OpGetfamilyDumpRequest");
2143 for attr in self.clone() {
2144 let attr = match attr {
2145 Ok(a) => a,
2146 Err(err) => {
2147 fmt.finish()?;
2148 f.write_str("Err(")?;
2149 err.fmt(f)?;
2150 return f.write_str(")");
2151 }
2152 };
2153 match attr {};
2154 }
2155 fmt.finish()
2156 }
2157}
2158impl IterableOpGetfamilyDumpRequest<'_> {
2159 pub fn lookup_attr(
2160 &self,
2161 offset: usize,
2162 missing_type: Option<u16>,
2163 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2164 let mut stack = Vec::new();
2165 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2166 if cur == offset + PushBuiltinNfgenmsg::len() {
2167 stack.push(("OpGetfamilyDumpRequest", offset));
2168 return (
2169 stack,
2170 missing_type.and_then(|t| OpGetfamilyDumpRequest::attr_from_type(t)),
2171 );
2172 }
2173 (stack, None)
2174 }
2175}
2176#[doc = "Get / dump genetlink families"]
2177pub struct PushOpGetfamilyDumpReply<Prev: Rec> {
2178 pub(crate) prev: Option<Prev>,
2179 pub(crate) header_offset: Option<usize>,
2180}
2181impl<Prev: Rec> Rec for PushOpGetfamilyDumpReply<Prev> {
2182 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
2183 self.prev.as_mut().unwrap().as_rec_mut()
2184 }
2185 fn as_rec(&self) -> &Vec<u8> {
2186 self.prev.as_ref().unwrap().as_rec()
2187 }
2188}
2189impl<Prev: Rec> PushOpGetfamilyDumpReply<Prev> {
2190 pub fn new(mut prev: Prev) -> Self {
2191 Self::write_header(&mut prev);
2192 Self::new_without_header(prev)
2193 }
2194 fn new_without_header(prev: Prev) -> Self {
2195 Self {
2196 prev: Some(prev),
2197 header_offset: None,
2198 }
2199 }
2200 fn write_header(prev: &mut Prev) {
2201 let mut header = PushBuiltinNfgenmsg::new();
2202 header.set_cmd(1u8);
2203 header.set_version(1u8);
2204 prev.as_rec_mut().extend(header.as_slice());
2205 }
2206 pub fn end_nested(mut self) -> Prev {
2207 let mut prev = self.prev.take().unwrap();
2208 if let Some(header_offset) = &self.header_offset {
2209 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2210 }
2211 prev
2212 }
2213 pub fn push_family_id(mut self, value: u16) -> Self {
2214 push_header(self.as_rec_mut(), 1u16, 2 as u16);
2215 self.as_rec_mut().extend(value.to_ne_bytes());
2216 self
2217 }
2218 pub fn push_family_name(mut self, value: &CStr) -> Self {
2219 push_header(
2220 self.as_rec_mut(),
2221 2u16,
2222 value.to_bytes_with_nul().len() as u16,
2223 );
2224 self.as_rec_mut().extend(value.to_bytes_with_nul());
2225 self
2226 }
2227 pub fn push_family_name_bytes(mut self, value: &[u8]) -> Self {
2228 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
2229 self.as_rec_mut().extend(value);
2230 self.as_rec_mut().push(0);
2231 self
2232 }
2233 pub fn push_version(mut self, value: u32) -> Self {
2234 push_header(self.as_rec_mut(), 3u16, 4 as u16);
2235 self.as_rec_mut().extend(value.to_ne_bytes());
2236 self
2237 }
2238 pub fn push_hdrsize(mut self, value: u32) -> Self {
2239 push_header(self.as_rec_mut(), 4u16, 4 as u16);
2240 self.as_rec_mut().extend(value.to_ne_bytes());
2241 self
2242 }
2243 pub fn push_maxattr(mut self, value: u32) -> Self {
2244 push_header(self.as_rec_mut(), 5u16, 4 as u16);
2245 self.as_rec_mut().extend(value.to_ne_bytes());
2246 self
2247 }
2248 pub fn array_ops(mut self) -> PushArrayOpAttrs<Self> {
2249 let header_offset = push_nested_header(self.as_rec_mut(), 6u16);
2250 PushArrayOpAttrs {
2251 prev: Some(self),
2252 header_offset: Some(header_offset),
2253 counter: 0,
2254 }
2255 }
2256 pub fn array_mcast_groups(mut self) -> PushArrayMcastGroupAttrs<Self> {
2257 let header_offset = push_nested_header(self.as_rec_mut(), 7u16);
2258 PushArrayMcastGroupAttrs {
2259 prev: Some(self),
2260 header_offset: Some(header_offset),
2261 counter: 0,
2262 }
2263 }
2264}
2265impl<Prev: Rec> Drop for PushOpGetfamilyDumpReply<Prev> {
2266 fn drop(&mut self) {
2267 if let Some(prev) = &mut self.prev {
2268 if let Some(header_offset) = &self.header_offset {
2269 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2270 }
2271 }
2272 }
2273}
2274#[doc = "Get / dump genetlink families"]
2275#[derive(Clone)]
2276pub enum OpGetfamilyDumpReply<'a> {
2277 FamilyId(u16),
2278 FamilyName(&'a CStr),
2279 Version(u32),
2280 Hdrsize(u32),
2281 Maxattr(u32),
2282 Ops(IterableArrayOpAttrs<'a>),
2283 McastGroups(IterableArrayMcastGroupAttrs<'a>),
2284}
2285impl<'a> IterableOpGetfamilyDumpReply<'a> {
2286 pub fn get_family_id(&self) -> Result<u16, ErrorContext> {
2287 let mut iter = self.clone();
2288 iter.pos = 0;
2289 for attr in iter {
2290 if let OpGetfamilyDumpReply::FamilyId(val) = attr? {
2291 return Ok(val);
2292 }
2293 }
2294 Err(ErrorContext::new_missing(
2295 "OpGetfamilyDumpReply",
2296 "FamilyId",
2297 self.orig_loc,
2298 self.buf.as_ptr() as usize,
2299 ))
2300 }
2301 pub fn get_family_name(&self) -> Result<&'a CStr, ErrorContext> {
2302 let mut iter = self.clone();
2303 iter.pos = 0;
2304 for attr in iter {
2305 if let OpGetfamilyDumpReply::FamilyName(val) = attr? {
2306 return Ok(val);
2307 }
2308 }
2309 Err(ErrorContext::new_missing(
2310 "OpGetfamilyDumpReply",
2311 "FamilyName",
2312 self.orig_loc,
2313 self.buf.as_ptr() as usize,
2314 ))
2315 }
2316 pub fn get_version(&self) -> Result<u32, ErrorContext> {
2317 let mut iter = self.clone();
2318 iter.pos = 0;
2319 for attr in iter {
2320 if let OpGetfamilyDumpReply::Version(val) = attr? {
2321 return Ok(val);
2322 }
2323 }
2324 Err(ErrorContext::new_missing(
2325 "OpGetfamilyDumpReply",
2326 "Version",
2327 self.orig_loc,
2328 self.buf.as_ptr() as usize,
2329 ))
2330 }
2331 pub fn get_hdrsize(&self) -> Result<u32, ErrorContext> {
2332 let mut iter = self.clone();
2333 iter.pos = 0;
2334 for attr in iter {
2335 if let OpGetfamilyDumpReply::Hdrsize(val) = attr? {
2336 return Ok(val);
2337 }
2338 }
2339 Err(ErrorContext::new_missing(
2340 "OpGetfamilyDumpReply",
2341 "Hdrsize",
2342 self.orig_loc,
2343 self.buf.as_ptr() as usize,
2344 ))
2345 }
2346 pub fn get_maxattr(&self) -> Result<u32, ErrorContext> {
2347 let mut iter = self.clone();
2348 iter.pos = 0;
2349 for attr in iter {
2350 if let OpGetfamilyDumpReply::Maxattr(val) = attr? {
2351 return Ok(val);
2352 }
2353 }
2354 Err(ErrorContext::new_missing(
2355 "OpGetfamilyDumpReply",
2356 "Maxattr",
2357 self.orig_loc,
2358 self.buf.as_ptr() as usize,
2359 ))
2360 }
2361 pub fn get_ops(
2362 &self,
2363 ) -> Result<ArrayIterable<IterableArrayOpAttrs<'a>, IterableOpAttrs<'a>>, ErrorContext> {
2364 for attr in self.clone() {
2365 if let OpGetfamilyDumpReply::Ops(val) = attr? {
2366 return Ok(ArrayIterable::new(val));
2367 }
2368 }
2369 Err(ErrorContext::new_missing(
2370 "OpGetfamilyDumpReply",
2371 "Ops",
2372 self.orig_loc,
2373 self.buf.as_ptr() as usize,
2374 ))
2375 }
2376 pub fn get_mcast_groups(
2377 &self,
2378 ) -> Result<
2379 ArrayIterable<IterableArrayMcastGroupAttrs<'a>, IterableMcastGroupAttrs<'a>>,
2380 ErrorContext,
2381 > {
2382 for attr in self.clone() {
2383 if let OpGetfamilyDumpReply::McastGroups(val) = attr? {
2384 return Ok(ArrayIterable::new(val));
2385 }
2386 }
2387 Err(ErrorContext::new_missing(
2388 "OpGetfamilyDumpReply",
2389 "McastGroups",
2390 self.orig_loc,
2391 self.buf.as_ptr() as usize,
2392 ))
2393 }
2394}
2395impl OpGetfamilyDumpReply<'_> {
2396 pub fn new<'a>(buf: &'a [u8]) -> IterableOpGetfamilyDumpReply<'a> {
2397 let (_header, attrs) = buf.split_at(buf.len().min(PushBuiltinNfgenmsg::len()));
2398 IterableOpGetfamilyDumpReply::with_loc(attrs, buf.as_ptr() as usize)
2399 }
2400 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2401 CtrlAttrs::attr_from_type(r#type)
2402 }
2403}
2404#[derive(Clone, Copy, Default)]
2405pub struct IterableOpGetfamilyDumpReply<'a> {
2406 buf: &'a [u8],
2407 pos: usize,
2408 orig_loc: usize,
2409}
2410impl<'a> IterableOpGetfamilyDumpReply<'a> {
2411 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2412 Self {
2413 buf,
2414 pos: 0,
2415 orig_loc,
2416 }
2417 }
2418 pub fn get_buf(&self) -> &'a [u8] {
2419 self.buf
2420 }
2421}
2422impl<'a> Iterator for IterableOpGetfamilyDumpReply<'a> {
2423 type Item = Result<OpGetfamilyDumpReply<'a>, ErrorContext>;
2424 fn next(&mut self) -> Option<Self::Item> {
2425 let pos = self.pos;
2426 let mut r#type;
2427 loop {
2428 r#type = None;
2429 if self.buf.len() == self.pos {
2430 return None;
2431 }
2432 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
2433 break;
2434 };
2435 r#type = Some(header.r#type);
2436 let res = match header.r#type {
2437 1u16 => OpGetfamilyDumpReply::FamilyId({
2438 let res = parse_u16(next);
2439 let Some(val) = res else { break };
2440 val
2441 }),
2442 2u16 => OpGetfamilyDumpReply::FamilyName({
2443 let res = CStr::from_bytes_with_nul(next).ok();
2444 let Some(val) = res else { break };
2445 val
2446 }),
2447 3u16 => OpGetfamilyDumpReply::Version({
2448 let res = parse_u32(next);
2449 let Some(val) = res else { break };
2450 val
2451 }),
2452 4u16 => OpGetfamilyDumpReply::Hdrsize({
2453 let res = parse_u32(next);
2454 let Some(val) = res else { break };
2455 val
2456 }),
2457 5u16 => OpGetfamilyDumpReply::Maxattr({
2458 let res = parse_u32(next);
2459 let Some(val) = res else { break };
2460 val
2461 }),
2462 6u16 => OpGetfamilyDumpReply::Ops({
2463 let res = Some(IterableArrayOpAttrs::with_loc(next, self.orig_loc));
2464 let Some(val) = res else { break };
2465 val
2466 }),
2467 7u16 => OpGetfamilyDumpReply::McastGroups({
2468 let res = Some(IterableArrayMcastGroupAttrs::with_loc(next, self.orig_loc));
2469 let Some(val) = res else { break };
2470 val
2471 }),
2472 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
2473 n => continue,
2474 };
2475 return Some(Ok(res));
2476 }
2477 Some(Err(ErrorContext::new(
2478 "OpGetfamilyDumpReply",
2479 r#type.and_then(|t| OpGetfamilyDumpReply::attr_from_type(t)),
2480 self.orig_loc,
2481 self.buf.as_ptr().wrapping_add(pos) as usize,
2482 )))
2483 }
2484}
2485impl<'a> std::fmt::Debug for IterableOpGetfamilyDumpReply<'_> {
2486 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2487 let mut fmt = f.debug_struct("OpGetfamilyDumpReply");
2488 for attr in self.clone() {
2489 let attr = match attr {
2490 Ok(a) => a,
2491 Err(err) => {
2492 fmt.finish()?;
2493 f.write_str("Err(")?;
2494 err.fmt(f)?;
2495 return f.write_str(")");
2496 }
2497 };
2498 match attr {
2499 OpGetfamilyDumpReply::FamilyId(val) => fmt.field("FamilyId", &val),
2500 OpGetfamilyDumpReply::FamilyName(val) => fmt.field("FamilyName", &val),
2501 OpGetfamilyDumpReply::Version(val) => fmt.field("Version", &val),
2502 OpGetfamilyDumpReply::Hdrsize(val) => fmt.field("Hdrsize", &val),
2503 OpGetfamilyDumpReply::Maxattr(val) => fmt.field("Maxattr", &val),
2504 OpGetfamilyDumpReply::Ops(val) => fmt.field("Ops", &val),
2505 OpGetfamilyDumpReply::McastGroups(val) => fmt.field("McastGroups", &val),
2506 };
2507 }
2508 fmt.finish()
2509 }
2510}
2511impl IterableOpGetfamilyDumpReply<'_> {
2512 pub fn lookup_attr(
2513 &self,
2514 offset: usize,
2515 missing_type: Option<u16>,
2516 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2517 let mut stack = Vec::new();
2518 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2519 if cur == offset + PushBuiltinNfgenmsg::len() {
2520 stack.push(("OpGetfamilyDumpReply", offset));
2521 return (
2522 stack,
2523 missing_type.and_then(|t| OpGetfamilyDumpReply::attr_from_type(t)),
2524 );
2525 }
2526 if cur > offset || cur + self.buf.len() < offset {
2527 return (stack, None);
2528 }
2529 let mut attrs = self.clone();
2530 let mut last_off = cur + attrs.pos;
2531 let mut missing = None;
2532 while let Some(attr) = attrs.next() {
2533 let Ok(attr) = attr else { break };
2534 match attr {
2535 OpGetfamilyDumpReply::FamilyId(val) => {
2536 if last_off == offset {
2537 stack.push(("FamilyId", last_off));
2538 break;
2539 }
2540 }
2541 OpGetfamilyDumpReply::FamilyName(val) => {
2542 if last_off == offset {
2543 stack.push(("FamilyName", last_off));
2544 break;
2545 }
2546 }
2547 OpGetfamilyDumpReply::Version(val) => {
2548 if last_off == offset {
2549 stack.push(("Version", last_off));
2550 break;
2551 }
2552 }
2553 OpGetfamilyDumpReply::Hdrsize(val) => {
2554 if last_off == offset {
2555 stack.push(("Hdrsize", last_off));
2556 break;
2557 }
2558 }
2559 OpGetfamilyDumpReply::Maxattr(val) => {
2560 if last_off == offset {
2561 stack.push(("Maxattr", last_off));
2562 break;
2563 }
2564 }
2565 OpGetfamilyDumpReply::Ops(val) => {
2566 for entry in val {
2567 let Ok(attr) = entry else { break };
2568 (stack, missing) = attr.lookup_attr(offset, missing_type);
2569 if !stack.is_empty() {
2570 break;
2571 }
2572 }
2573 if !stack.is_empty() {
2574 stack.push(("Ops", last_off));
2575 break;
2576 }
2577 }
2578 OpGetfamilyDumpReply::McastGroups(val) => {
2579 for entry in val {
2580 let Ok(attr) = entry else { break };
2581 (stack, missing) = attr.lookup_attr(offset, missing_type);
2582 if !stack.is_empty() {
2583 break;
2584 }
2585 }
2586 if !stack.is_empty() {
2587 stack.push(("McastGroups", last_off));
2588 break;
2589 }
2590 }
2591 _ => {}
2592 };
2593 last_off = cur + attrs.pos;
2594 }
2595 if !stack.is_empty() {
2596 stack.push(("OpGetfamilyDumpReply", cur));
2597 }
2598 (stack, missing)
2599 }
2600}
2601#[derive(Debug)]
2602pub struct RequestOpGetfamilyDumpRequest<'r> {
2603 request: Request<'r>,
2604}
2605impl<'r> RequestOpGetfamilyDumpRequest<'r> {
2606 pub fn new(mut request: Request<'r>) -> Self {
2607 PushOpGetfamilyDumpRequest::write_header(&mut request.buf_mut());
2608 Self {
2609 request: request.set_dump(),
2610 }
2611 }
2612 pub fn encode(&mut self) -> PushOpGetfamilyDumpRequest<&mut Vec<u8>> {
2613 PushOpGetfamilyDumpRequest::new_without_header(self.request.buf_mut())
2614 }
2615 pub fn into_encoder(self) -> PushOpGetfamilyDumpRequest<RequestBuf<'r>> {
2616 PushOpGetfamilyDumpRequest::new_without_header(self.request.buf)
2617 }
2618 pub fn decode_request<'buf>(buf: &'buf [u8]) -> IterableOpGetfamilyDumpRequest<'buf> {
2619 OpGetfamilyDumpRequest::new(buf)
2620 }
2621}
2622impl NetlinkRequest for RequestOpGetfamilyDumpRequest<'_> {
2623 fn protocol(&self) -> Protocol {
2624 Protocol::Raw {
2625 protonum: 0x10,
2626 request_type: 0x10,
2627 }
2628 }
2629 fn flags(&self) -> u16 {
2630 self.request.flags
2631 }
2632 fn payload(&self) -> &[u8] {
2633 self.request.buf()
2634 }
2635 type ReplyType<'buf> = IterableOpGetfamilyDumpReply<'buf>;
2636 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
2637 OpGetfamilyDumpReply::new(buf)
2638 }
2639 fn lookup(
2640 buf: &[u8],
2641 offset: usize,
2642 missing_type: Option<u16>,
2643 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2644 OpGetfamilyDumpRequest::new(buf).lookup_attr(offset, missing_type)
2645 }
2646}
2647#[doc = "Get / dump genetlink families"]
2648pub struct PushOpGetfamilyDoRequest<Prev: Rec> {
2649 pub(crate) prev: Option<Prev>,
2650 pub(crate) header_offset: Option<usize>,
2651}
2652impl<Prev: Rec> Rec for PushOpGetfamilyDoRequest<Prev> {
2653 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
2654 self.prev.as_mut().unwrap().as_rec_mut()
2655 }
2656 fn as_rec(&self) -> &Vec<u8> {
2657 self.prev.as_ref().unwrap().as_rec()
2658 }
2659}
2660impl<Prev: Rec> PushOpGetfamilyDoRequest<Prev> {
2661 pub fn new(mut prev: Prev) -> Self {
2662 Self::write_header(&mut prev);
2663 Self::new_without_header(prev)
2664 }
2665 fn new_without_header(prev: Prev) -> Self {
2666 Self {
2667 prev: Some(prev),
2668 header_offset: None,
2669 }
2670 }
2671 fn write_header(prev: &mut Prev) {
2672 let mut header = PushBuiltinNfgenmsg::new();
2673 header.set_cmd(3u8);
2674 header.set_version(1u8);
2675 prev.as_rec_mut().extend(header.as_slice());
2676 }
2677 pub fn end_nested(mut self) -> Prev {
2678 let mut prev = self.prev.take().unwrap();
2679 if let Some(header_offset) = &self.header_offset {
2680 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2681 }
2682 prev
2683 }
2684 pub fn push_family_name(mut self, value: &CStr) -> Self {
2685 push_header(
2686 self.as_rec_mut(),
2687 2u16,
2688 value.to_bytes_with_nul().len() as u16,
2689 );
2690 self.as_rec_mut().extend(value.to_bytes_with_nul());
2691 self
2692 }
2693 pub fn push_family_name_bytes(mut self, value: &[u8]) -> Self {
2694 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
2695 self.as_rec_mut().extend(value);
2696 self.as_rec_mut().push(0);
2697 self
2698 }
2699}
2700impl<Prev: Rec> Drop for PushOpGetfamilyDoRequest<Prev> {
2701 fn drop(&mut self) {
2702 if let Some(prev) = &mut self.prev {
2703 if let Some(header_offset) = &self.header_offset {
2704 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2705 }
2706 }
2707 }
2708}
2709#[doc = "Get / dump genetlink families"]
2710#[derive(Clone)]
2711pub enum OpGetfamilyDoRequest<'a> {
2712 FamilyName(&'a CStr),
2713}
2714impl<'a> IterableOpGetfamilyDoRequest<'a> {
2715 pub fn get_family_name(&self) -> Result<&'a CStr, ErrorContext> {
2716 let mut iter = self.clone();
2717 iter.pos = 0;
2718 for attr in iter {
2719 if let OpGetfamilyDoRequest::FamilyName(val) = attr? {
2720 return Ok(val);
2721 }
2722 }
2723 Err(ErrorContext::new_missing(
2724 "OpGetfamilyDoRequest",
2725 "FamilyName",
2726 self.orig_loc,
2727 self.buf.as_ptr() as usize,
2728 ))
2729 }
2730}
2731impl OpGetfamilyDoRequest<'_> {
2732 pub fn new<'a>(buf: &'a [u8]) -> IterableOpGetfamilyDoRequest<'a> {
2733 let (_header, attrs) = buf.split_at(buf.len().min(PushBuiltinNfgenmsg::len()));
2734 IterableOpGetfamilyDoRequest::with_loc(attrs, buf.as_ptr() as usize)
2735 }
2736 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2737 CtrlAttrs::attr_from_type(r#type)
2738 }
2739}
2740#[derive(Clone, Copy, Default)]
2741pub struct IterableOpGetfamilyDoRequest<'a> {
2742 buf: &'a [u8],
2743 pos: usize,
2744 orig_loc: usize,
2745}
2746impl<'a> IterableOpGetfamilyDoRequest<'a> {
2747 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2748 Self {
2749 buf,
2750 pos: 0,
2751 orig_loc,
2752 }
2753 }
2754 pub fn get_buf(&self) -> &'a [u8] {
2755 self.buf
2756 }
2757}
2758impl<'a> Iterator for IterableOpGetfamilyDoRequest<'a> {
2759 type Item = Result<OpGetfamilyDoRequest<'a>, ErrorContext>;
2760 fn next(&mut self) -> Option<Self::Item> {
2761 let pos = self.pos;
2762 let mut r#type;
2763 loop {
2764 r#type = None;
2765 if self.buf.len() == self.pos {
2766 return None;
2767 }
2768 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
2769 break;
2770 };
2771 r#type = Some(header.r#type);
2772 let res = match header.r#type {
2773 2u16 => OpGetfamilyDoRequest::FamilyName({
2774 let res = CStr::from_bytes_with_nul(next).ok();
2775 let Some(val) = res else { break };
2776 val
2777 }),
2778 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
2779 n => continue,
2780 };
2781 return Some(Ok(res));
2782 }
2783 Some(Err(ErrorContext::new(
2784 "OpGetfamilyDoRequest",
2785 r#type.and_then(|t| OpGetfamilyDoRequest::attr_from_type(t)),
2786 self.orig_loc,
2787 self.buf.as_ptr().wrapping_add(pos) as usize,
2788 )))
2789 }
2790}
2791impl<'a> std::fmt::Debug for IterableOpGetfamilyDoRequest<'_> {
2792 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2793 let mut fmt = f.debug_struct("OpGetfamilyDoRequest");
2794 for attr in self.clone() {
2795 let attr = match attr {
2796 Ok(a) => a,
2797 Err(err) => {
2798 fmt.finish()?;
2799 f.write_str("Err(")?;
2800 err.fmt(f)?;
2801 return f.write_str(")");
2802 }
2803 };
2804 match attr {
2805 OpGetfamilyDoRequest::FamilyName(val) => fmt.field("FamilyName", &val),
2806 };
2807 }
2808 fmt.finish()
2809 }
2810}
2811impl IterableOpGetfamilyDoRequest<'_> {
2812 pub fn lookup_attr(
2813 &self,
2814 offset: usize,
2815 missing_type: Option<u16>,
2816 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2817 let mut stack = Vec::new();
2818 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2819 if cur == offset + PushBuiltinNfgenmsg::len() {
2820 stack.push(("OpGetfamilyDoRequest", offset));
2821 return (
2822 stack,
2823 missing_type.and_then(|t| OpGetfamilyDoRequest::attr_from_type(t)),
2824 );
2825 }
2826 if cur > offset || cur + self.buf.len() < offset {
2827 return (stack, None);
2828 }
2829 let mut attrs = self.clone();
2830 let mut last_off = cur + attrs.pos;
2831 while let Some(attr) = attrs.next() {
2832 let Ok(attr) = attr else { break };
2833 match attr {
2834 OpGetfamilyDoRequest::FamilyName(val) => {
2835 if last_off == offset {
2836 stack.push(("FamilyName", last_off));
2837 break;
2838 }
2839 }
2840 _ => {}
2841 };
2842 last_off = cur + attrs.pos;
2843 }
2844 if !stack.is_empty() {
2845 stack.push(("OpGetfamilyDoRequest", cur));
2846 }
2847 (stack, None)
2848 }
2849}
2850#[doc = "Get / dump genetlink families"]
2851pub struct PushOpGetfamilyDoReply<Prev: Rec> {
2852 pub(crate) prev: Option<Prev>,
2853 pub(crate) header_offset: Option<usize>,
2854}
2855impl<Prev: Rec> Rec for PushOpGetfamilyDoReply<Prev> {
2856 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
2857 self.prev.as_mut().unwrap().as_rec_mut()
2858 }
2859 fn as_rec(&self) -> &Vec<u8> {
2860 self.prev.as_ref().unwrap().as_rec()
2861 }
2862}
2863impl<Prev: Rec> PushOpGetfamilyDoReply<Prev> {
2864 pub fn new(mut prev: Prev) -> Self {
2865 Self::write_header(&mut prev);
2866 Self::new_without_header(prev)
2867 }
2868 fn new_without_header(prev: Prev) -> Self {
2869 Self {
2870 prev: Some(prev),
2871 header_offset: None,
2872 }
2873 }
2874 fn write_header(prev: &mut Prev) {
2875 let mut header = PushBuiltinNfgenmsg::new();
2876 header.set_cmd(1u8);
2877 header.set_version(1u8);
2878 prev.as_rec_mut().extend(header.as_slice());
2879 }
2880 pub fn end_nested(mut self) -> Prev {
2881 let mut prev = self.prev.take().unwrap();
2882 if let Some(header_offset) = &self.header_offset {
2883 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2884 }
2885 prev
2886 }
2887 pub fn push_family_id(mut self, value: u16) -> Self {
2888 push_header(self.as_rec_mut(), 1u16, 2 as u16);
2889 self.as_rec_mut().extend(value.to_ne_bytes());
2890 self
2891 }
2892 pub fn push_family_name(mut self, value: &CStr) -> Self {
2893 push_header(
2894 self.as_rec_mut(),
2895 2u16,
2896 value.to_bytes_with_nul().len() as u16,
2897 );
2898 self.as_rec_mut().extend(value.to_bytes_with_nul());
2899 self
2900 }
2901 pub fn push_family_name_bytes(mut self, value: &[u8]) -> Self {
2902 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
2903 self.as_rec_mut().extend(value);
2904 self.as_rec_mut().push(0);
2905 self
2906 }
2907 pub fn push_version(mut self, value: u32) -> Self {
2908 push_header(self.as_rec_mut(), 3u16, 4 as u16);
2909 self.as_rec_mut().extend(value.to_ne_bytes());
2910 self
2911 }
2912 pub fn push_hdrsize(mut self, value: u32) -> Self {
2913 push_header(self.as_rec_mut(), 4u16, 4 as u16);
2914 self.as_rec_mut().extend(value.to_ne_bytes());
2915 self
2916 }
2917 pub fn push_maxattr(mut self, value: u32) -> Self {
2918 push_header(self.as_rec_mut(), 5u16, 4 as u16);
2919 self.as_rec_mut().extend(value.to_ne_bytes());
2920 self
2921 }
2922 pub fn array_ops(mut self) -> PushArrayOpAttrs<Self> {
2923 let header_offset = push_nested_header(self.as_rec_mut(), 6u16);
2924 PushArrayOpAttrs {
2925 prev: Some(self),
2926 header_offset: Some(header_offset),
2927 counter: 0,
2928 }
2929 }
2930 pub fn array_mcast_groups(mut self) -> PushArrayMcastGroupAttrs<Self> {
2931 let header_offset = push_nested_header(self.as_rec_mut(), 7u16);
2932 PushArrayMcastGroupAttrs {
2933 prev: Some(self),
2934 header_offset: Some(header_offset),
2935 counter: 0,
2936 }
2937 }
2938}
2939impl<Prev: Rec> Drop for PushOpGetfamilyDoReply<Prev> {
2940 fn drop(&mut self) {
2941 if let Some(prev) = &mut self.prev {
2942 if let Some(header_offset) = &self.header_offset {
2943 finalize_nested_header(prev.as_rec_mut(), *header_offset);
2944 }
2945 }
2946 }
2947}
2948#[doc = "Get / dump genetlink families"]
2949#[derive(Clone)]
2950pub enum OpGetfamilyDoReply<'a> {
2951 FamilyId(u16),
2952 FamilyName(&'a CStr),
2953 Version(u32),
2954 Hdrsize(u32),
2955 Maxattr(u32),
2956 Ops(IterableArrayOpAttrs<'a>),
2957 McastGroups(IterableArrayMcastGroupAttrs<'a>),
2958}
2959impl<'a> IterableOpGetfamilyDoReply<'a> {
2960 pub fn get_family_id(&self) -> Result<u16, ErrorContext> {
2961 let mut iter = self.clone();
2962 iter.pos = 0;
2963 for attr in iter {
2964 if let OpGetfamilyDoReply::FamilyId(val) = attr? {
2965 return Ok(val);
2966 }
2967 }
2968 Err(ErrorContext::new_missing(
2969 "OpGetfamilyDoReply",
2970 "FamilyId",
2971 self.orig_loc,
2972 self.buf.as_ptr() as usize,
2973 ))
2974 }
2975 pub fn get_family_name(&self) -> Result<&'a CStr, ErrorContext> {
2976 let mut iter = self.clone();
2977 iter.pos = 0;
2978 for attr in iter {
2979 if let OpGetfamilyDoReply::FamilyName(val) = attr? {
2980 return Ok(val);
2981 }
2982 }
2983 Err(ErrorContext::new_missing(
2984 "OpGetfamilyDoReply",
2985 "FamilyName",
2986 self.orig_loc,
2987 self.buf.as_ptr() as usize,
2988 ))
2989 }
2990 pub fn get_version(&self) -> Result<u32, ErrorContext> {
2991 let mut iter = self.clone();
2992 iter.pos = 0;
2993 for attr in iter {
2994 if let OpGetfamilyDoReply::Version(val) = attr? {
2995 return Ok(val);
2996 }
2997 }
2998 Err(ErrorContext::new_missing(
2999 "OpGetfamilyDoReply",
3000 "Version",
3001 self.orig_loc,
3002 self.buf.as_ptr() as usize,
3003 ))
3004 }
3005 pub fn get_hdrsize(&self) -> Result<u32, ErrorContext> {
3006 let mut iter = self.clone();
3007 iter.pos = 0;
3008 for attr in iter {
3009 if let OpGetfamilyDoReply::Hdrsize(val) = attr? {
3010 return Ok(val);
3011 }
3012 }
3013 Err(ErrorContext::new_missing(
3014 "OpGetfamilyDoReply",
3015 "Hdrsize",
3016 self.orig_loc,
3017 self.buf.as_ptr() as usize,
3018 ))
3019 }
3020 pub fn get_maxattr(&self) -> Result<u32, ErrorContext> {
3021 let mut iter = self.clone();
3022 iter.pos = 0;
3023 for attr in iter {
3024 if let OpGetfamilyDoReply::Maxattr(val) = attr? {
3025 return Ok(val);
3026 }
3027 }
3028 Err(ErrorContext::new_missing(
3029 "OpGetfamilyDoReply",
3030 "Maxattr",
3031 self.orig_loc,
3032 self.buf.as_ptr() as usize,
3033 ))
3034 }
3035 pub fn get_ops(
3036 &self,
3037 ) -> Result<ArrayIterable<IterableArrayOpAttrs<'a>, IterableOpAttrs<'a>>, ErrorContext> {
3038 for attr in self.clone() {
3039 if let OpGetfamilyDoReply::Ops(val) = attr? {
3040 return Ok(ArrayIterable::new(val));
3041 }
3042 }
3043 Err(ErrorContext::new_missing(
3044 "OpGetfamilyDoReply",
3045 "Ops",
3046 self.orig_loc,
3047 self.buf.as_ptr() as usize,
3048 ))
3049 }
3050 pub fn get_mcast_groups(
3051 &self,
3052 ) -> Result<
3053 ArrayIterable<IterableArrayMcastGroupAttrs<'a>, IterableMcastGroupAttrs<'a>>,
3054 ErrorContext,
3055 > {
3056 for attr in self.clone() {
3057 if let OpGetfamilyDoReply::McastGroups(val) = attr? {
3058 return Ok(ArrayIterable::new(val));
3059 }
3060 }
3061 Err(ErrorContext::new_missing(
3062 "OpGetfamilyDoReply",
3063 "McastGroups",
3064 self.orig_loc,
3065 self.buf.as_ptr() as usize,
3066 ))
3067 }
3068}
3069impl OpGetfamilyDoReply<'_> {
3070 pub fn new<'a>(buf: &'a [u8]) -> IterableOpGetfamilyDoReply<'a> {
3071 let (_header, attrs) = buf.split_at(buf.len().min(PushBuiltinNfgenmsg::len()));
3072 IterableOpGetfamilyDoReply::with_loc(attrs, buf.as_ptr() as usize)
3073 }
3074 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3075 CtrlAttrs::attr_from_type(r#type)
3076 }
3077}
3078#[derive(Clone, Copy, Default)]
3079pub struct IterableOpGetfamilyDoReply<'a> {
3080 buf: &'a [u8],
3081 pos: usize,
3082 orig_loc: usize,
3083}
3084impl<'a> IterableOpGetfamilyDoReply<'a> {
3085 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3086 Self {
3087 buf,
3088 pos: 0,
3089 orig_loc,
3090 }
3091 }
3092 pub fn get_buf(&self) -> &'a [u8] {
3093 self.buf
3094 }
3095}
3096impl<'a> Iterator for IterableOpGetfamilyDoReply<'a> {
3097 type Item = Result<OpGetfamilyDoReply<'a>, ErrorContext>;
3098 fn next(&mut self) -> Option<Self::Item> {
3099 let pos = self.pos;
3100 let mut r#type;
3101 loop {
3102 r#type = None;
3103 if self.buf.len() == self.pos {
3104 return None;
3105 }
3106 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
3107 break;
3108 };
3109 r#type = Some(header.r#type);
3110 let res = match header.r#type {
3111 1u16 => OpGetfamilyDoReply::FamilyId({
3112 let res = parse_u16(next);
3113 let Some(val) = res else { break };
3114 val
3115 }),
3116 2u16 => OpGetfamilyDoReply::FamilyName({
3117 let res = CStr::from_bytes_with_nul(next).ok();
3118 let Some(val) = res else { break };
3119 val
3120 }),
3121 3u16 => OpGetfamilyDoReply::Version({
3122 let res = parse_u32(next);
3123 let Some(val) = res else { break };
3124 val
3125 }),
3126 4u16 => OpGetfamilyDoReply::Hdrsize({
3127 let res = parse_u32(next);
3128 let Some(val) = res else { break };
3129 val
3130 }),
3131 5u16 => OpGetfamilyDoReply::Maxattr({
3132 let res = parse_u32(next);
3133 let Some(val) = res else { break };
3134 val
3135 }),
3136 6u16 => OpGetfamilyDoReply::Ops({
3137 let res = Some(IterableArrayOpAttrs::with_loc(next, self.orig_loc));
3138 let Some(val) = res else { break };
3139 val
3140 }),
3141 7u16 => OpGetfamilyDoReply::McastGroups({
3142 let res = Some(IterableArrayMcastGroupAttrs::with_loc(next, self.orig_loc));
3143 let Some(val) = res else { break };
3144 val
3145 }),
3146 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
3147 n => continue,
3148 };
3149 return Some(Ok(res));
3150 }
3151 Some(Err(ErrorContext::new(
3152 "OpGetfamilyDoReply",
3153 r#type.and_then(|t| OpGetfamilyDoReply::attr_from_type(t)),
3154 self.orig_loc,
3155 self.buf.as_ptr().wrapping_add(pos) as usize,
3156 )))
3157 }
3158}
3159impl<'a> std::fmt::Debug for IterableOpGetfamilyDoReply<'_> {
3160 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3161 let mut fmt = f.debug_struct("OpGetfamilyDoReply");
3162 for attr in self.clone() {
3163 let attr = match attr {
3164 Ok(a) => a,
3165 Err(err) => {
3166 fmt.finish()?;
3167 f.write_str("Err(")?;
3168 err.fmt(f)?;
3169 return f.write_str(")");
3170 }
3171 };
3172 match attr {
3173 OpGetfamilyDoReply::FamilyId(val) => fmt.field("FamilyId", &val),
3174 OpGetfamilyDoReply::FamilyName(val) => fmt.field("FamilyName", &val),
3175 OpGetfamilyDoReply::Version(val) => fmt.field("Version", &val),
3176 OpGetfamilyDoReply::Hdrsize(val) => fmt.field("Hdrsize", &val),
3177 OpGetfamilyDoReply::Maxattr(val) => fmt.field("Maxattr", &val),
3178 OpGetfamilyDoReply::Ops(val) => fmt.field("Ops", &val),
3179 OpGetfamilyDoReply::McastGroups(val) => fmt.field("McastGroups", &val),
3180 };
3181 }
3182 fmt.finish()
3183 }
3184}
3185impl IterableOpGetfamilyDoReply<'_> {
3186 pub fn lookup_attr(
3187 &self,
3188 offset: usize,
3189 missing_type: Option<u16>,
3190 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3191 let mut stack = Vec::new();
3192 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3193 if cur == offset + PushBuiltinNfgenmsg::len() {
3194 stack.push(("OpGetfamilyDoReply", offset));
3195 return (
3196 stack,
3197 missing_type.and_then(|t| OpGetfamilyDoReply::attr_from_type(t)),
3198 );
3199 }
3200 if cur > offset || cur + self.buf.len() < offset {
3201 return (stack, None);
3202 }
3203 let mut attrs = self.clone();
3204 let mut last_off = cur + attrs.pos;
3205 let mut missing = None;
3206 while let Some(attr) = attrs.next() {
3207 let Ok(attr) = attr else { break };
3208 match attr {
3209 OpGetfamilyDoReply::FamilyId(val) => {
3210 if last_off == offset {
3211 stack.push(("FamilyId", last_off));
3212 break;
3213 }
3214 }
3215 OpGetfamilyDoReply::FamilyName(val) => {
3216 if last_off == offset {
3217 stack.push(("FamilyName", last_off));
3218 break;
3219 }
3220 }
3221 OpGetfamilyDoReply::Version(val) => {
3222 if last_off == offset {
3223 stack.push(("Version", last_off));
3224 break;
3225 }
3226 }
3227 OpGetfamilyDoReply::Hdrsize(val) => {
3228 if last_off == offset {
3229 stack.push(("Hdrsize", last_off));
3230 break;
3231 }
3232 }
3233 OpGetfamilyDoReply::Maxattr(val) => {
3234 if last_off == offset {
3235 stack.push(("Maxattr", last_off));
3236 break;
3237 }
3238 }
3239 OpGetfamilyDoReply::Ops(val) => {
3240 for entry in val {
3241 let Ok(attr) = entry else { break };
3242 (stack, missing) = attr.lookup_attr(offset, missing_type);
3243 if !stack.is_empty() {
3244 break;
3245 }
3246 }
3247 if !stack.is_empty() {
3248 stack.push(("Ops", last_off));
3249 break;
3250 }
3251 }
3252 OpGetfamilyDoReply::McastGroups(val) => {
3253 for entry in val {
3254 let Ok(attr) = entry else { break };
3255 (stack, missing) = attr.lookup_attr(offset, missing_type);
3256 if !stack.is_empty() {
3257 break;
3258 }
3259 }
3260 if !stack.is_empty() {
3261 stack.push(("McastGroups", last_off));
3262 break;
3263 }
3264 }
3265 _ => {}
3266 };
3267 last_off = cur + attrs.pos;
3268 }
3269 if !stack.is_empty() {
3270 stack.push(("OpGetfamilyDoReply", cur));
3271 }
3272 (stack, missing)
3273 }
3274}
3275#[derive(Debug)]
3276pub struct RequestOpGetfamilyDoRequest<'r> {
3277 request: Request<'r>,
3278}
3279impl<'r> RequestOpGetfamilyDoRequest<'r> {
3280 pub fn new(mut request: Request<'r>) -> Self {
3281 PushOpGetfamilyDoRequest::write_header(&mut request.buf_mut());
3282 Self { request: request }
3283 }
3284 pub fn encode(&mut self) -> PushOpGetfamilyDoRequest<&mut Vec<u8>> {
3285 PushOpGetfamilyDoRequest::new_without_header(self.request.buf_mut())
3286 }
3287 pub fn into_encoder(self) -> PushOpGetfamilyDoRequest<RequestBuf<'r>> {
3288 PushOpGetfamilyDoRequest::new_without_header(self.request.buf)
3289 }
3290 pub fn decode_request<'buf>(buf: &'buf [u8]) -> IterableOpGetfamilyDoRequest<'buf> {
3291 OpGetfamilyDoRequest::new(buf)
3292 }
3293}
3294impl NetlinkRequest for RequestOpGetfamilyDoRequest<'_> {
3295 fn protocol(&self) -> Protocol {
3296 Protocol::Raw {
3297 protonum: 0x10,
3298 request_type: 0x10,
3299 }
3300 }
3301 fn flags(&self) -> u16 {
3302 self.request.flags
3303 }
3304 fn payload(&self) -> &[u8] {
3305 self.request.buf()
3306 }
3307 type ReplyType<'buf> = IterableOpGetfamilyDoReply<'buf>;
3308 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
3309 OpGetfamilyDoReply::new(buf)
3310 }
3311 fn lookup(
3312 buf: &[u8],
3313 offset: usize,
3314 missing_type: Option<u16>,
3315 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3316 OpGetfamilyDoRequest::new(buf).lookup_attr(offset, missing_type)
3317 }
3318}
3319#[doc = "Get / dump genetlink policies"]
3320pub struct PushOpGetpolicyDumpRequest<Prev: Rec> {
3321 pub(crate) prev: Option<Prev>,
3322 pub(crate) header_offset: Option<usize>,
3323}
3324impl<Prev: Rec> Rec for PushOpGetpolicyDumpRequest<Prev> {
3325 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
3326 self.prev.as_mut().unwrap().as_rec_mut()
3327 }
3328 fn as_rec(&self) -> &Vec<u8> {
3329 self.prev.as_ref().unwrap().as_rec()
3330 }
3331}
3332impl<Prev: Rec> PushOpGetpolicyDumpRequest<Prev> {
3333 pub fn new(mut prev: Prev) -> Self {
3334 Self::write_header(&mut prev);
3335 Self::new_without_header(prev)
3336 }
3337 fn new_without_header(prev: Prev) -> Self {
3338 Self {
3339 prev: Some(prev),
3340 header_offset: None,
3341 }
3342 }
3343 fn write_header(prev: &mut Prev) {
3344 let mut header = PushBuiltinNfgenmsg::new();
3345 header.set_cmd(10u8);
3346 header.set_version(1u8);
3347 prev.as_rec_mut().extend(header.as_slice());
3348 }
3349 pub fn end_nested(mut self) -> Prev {
3350 let mut prev = self.prev.take().unwrap();
3351 if let Some(header_offset) = &self.header_offset {
3352 finalize_nested_header(prev.as_rec_mut(), *header_offset);
3353 }
3354 prev
3355 }
3356 pub fn push_family_id(mut self, value: u16) -> Self {
3357 push_header(self.as_rec_mut(), 1u16, 2 as u16);
3358 self.as_rec_mut().extend(value.to_ne_bytes());
3359 self
3360 }
3361 pub fn push_family_name(mut self, value: &CStr) -> Self {
3362 push_header(
3363 self.as_rec_mut(),
3364 2u16,
3365 value.to_bytes_with_nul().len() as u16,
3366 );
3367 self.as_rec_mut().extend(value.to_bytes_with_nul());
3368 self
3369 }
3370 pub fn push_family_name_bytes(mut self, value: &[u8]) -> Self {
3371 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
3372 self.as_rec_mut().extend(value);
3373 self.as_rec_mut().push(0);
3374 self
3375 }
3376 pub fn push_op(mut self, value: u32) -> Self {
3377 push_header(self.as_rec_mut(), 10u16, 4 as u16);
3378 self.as_rec_mut().extend(value.to_ne_bytes());
3379 self
3380 }
3381}
3382impl<Prev: Rec> Drop for PushOpGetpolicyDumpRequest<Prev> {
3383 fn drop(&mut self) {
3384 if let Some(prev) = &mut self.prev {
3385 if let Some(header_offset) = &self.header_offset {
3386 finalize_nested_header(prev.as_rec_mut(), *header_offset);
3387 }
3388 }
3389 }
3390}
3391#[doc = "Get / dump genetlink policies"]
3392#[derive(Clone)]
3393pub enum OpGetpolicyDumpRequest<'a> {
3394 FamilyId(u16),
3395 FamilyName(&'a CStr),
3396 Op(u32),
3397}
3398impl<'a> IterableOpGetpolicyDumpRequest<'a> {
3399 pub fn get_family_id(&self) -> Result<u16, ErrorContext> {
3400 let mut iter = self.clone();
3401 iter.pos = 0;
3402 for attr in iter {
3403 if let OpGetpolicyDumpRequest::FamilyId(val) = attr? {
3404 return Ok(val);
3405 }
3406 }
3407 Err(ErrorContext::new_missing(
3408 "OpGetpolicyDumpRequest",
3409 "FamilyId",
3410 self.orig_loc,
3411 self.buf.as_ptr() as usize,
3412 ))
3413 }
3414 pub fn get_family_name(&self) -> Result<&'a CStr, ErrorContext> {
3415 let mut iter = self.clone();
3416 iter.pos = 0;
3417 for attr in iter {
3418 if let OpGetpolicyDumpRequest::FamilyName(val) = attr? {
3419 return Ok(val);
3420 }
3421 }
3422 Err(ErrorContext::new_missing(
3423 "OpGetpolicyDumpRequest",
3424 "FamilyName",
3425 self.orig_loc,
3426 self.buf.as_ptr() as usize,
3427 ))
3428 }
3429 pub fn get_op(&self) -> Result<u32, ErrorContext> {
3430 let mut iter = self.clone();
3431 iter.pos = 0;
3432 for attr in iter {
3433 if let OpGetpolicyDumpRequest::Op(val) = attr? {
3434 return Ok(val);
3435 }
3436 }
3437 Err(ErrorContext::new_missing(
3438 "OpGetpolicyDumpRequest",
3439 "Op",
3440 self.orig_loc,
3441 self.buf.as_ptr() as usize,
3442 ))
3443 }
3444}
3445impl OpGetpolicyDumpRequest<'_> {
3446 pub fn new<'a>(buf: &'a [u8]) -> IterableOpGetpolicyDumpRequest<'a> {
3447 let (_header, attrs) = buf.split_at(buf.len().min(PushBuiltinNfgenmsg::len()));
3448 IterableOpGetpolicyDumpRequest::with_loc(attrs, buf.as_ptr() as usize)
3449 }
3450 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3451 CtrlAttrs::attr_from_type(r#type)
3452 }
3453}
3454#[derive(Clone, Copy, Default)]
3455pub struct IterableOpGetpolicyDumpRequest<'a> {
3456 buf: &'a [u8],
3457 pos: usize,
3458 orig_loc: usize,
3459}
3460impl<'a> IterableOpGetpolicyDumpRequest<'a> {
3461 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3462 Self {
3463 buf,
3464 pos: 0,
3465 orig_loc,
3466 }
3467 }
3468 pub fn get_buf(&self) -> &'a [u8] {
3469 self.buf
3470 }
3471}
3472impl<'a> Iterator for IterableOpGetpolicyDumpRequest<'a> {
3473 type Item = Result<OpGetpolicyDumpRequest<'a>, ErrorContext>;
3474 fn next(&mut self) -> Option<Self::Item> {
3475 let pos = self.pos;
3476 let mut r#type;
3477 loop {
3478 r#type = None;
3479 if self.buf.len() == self.pos {
3480 return None;
3481 }
3482 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
3483 break;
3484 };
3485 r#type = Some(header.r#type);
3486 let res = match header.r#type {
3487 1u16 => OpGetpolicyDumpRequest::FamilyId({
3488 let res = parse_u16(next);
3489 let Some(val) = res else { break };
3490 val
3491 }),
3492 2u16 => OpGetpolicyDumpRequest::FamilyName({
3493 let res = CStr::from_bytes_with_nul(next).ok();
3494 let Some(val) = res else { break };
3495 val
3496 }),
3497 10u16 => OpGetpolicyDumpRequest::Op({
3498 let res = parse_u32(next);
3499 let Some(val) = res else { break };
3500 val
3501 }),
3502 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
3503 n => continue,
3504 };
3505 return Some(Ok(res));
3506 }
3507 Some(Err(ErrorContext::new(
3508 "OpGetpolicyDumpRequest",
3509 r#type.and_then(|t| OpGetpolicyDumpRequest::attr_from_type(t)),
3510 self.orig_loc,
3511 self.buf.as_ptr().wrapping_add(pos) as usize,
3512 )))
3513 }
3514}
3515impl<'a> std::fmt::Debug for IterableOpGetpolicyDumpRequest<'_> {
3516 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3517 let mut fmt = f.debug_struct("OpGetpolicyDumpRequest");
3518 for attr in self.clone() {
3519 let attr = match attr {
3520 Ok(a) => a,
3521 Err(err) => {
3522 fmt.finish()?;
3523 f.write_str("Err(")?;
3524 err.fmt(f)?;
3525 return f.write_str(")");
3526 }
3527 };
3528 match attr {
3529 OpGetpolicyDumpRequest::FamilyId(val) => fmt.field("FamilyId", &val),
3530 OpGetpolicyDumpRequest::FamilyName(val) => fmt.field("FamilyName", &val),
3531 OpGetpolicyDumpRequest::Op(val) => fmt.field("Op", &val),
3532 };
3533 }
3534 fmt.finish()
3535 }
3536}
3537impl IterableOpGetpolicyDumpRequest<'_> {
3538 pub fn lookup_attr(
3539 &self,
3540 offset: usize,
3541 missing_type: Option<u16>,
3542 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3543 let mut stack = Vec::new();
3544 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3545 if cur == offset + PushBuiltinNfgenmsg::len() {
3546 stack.push(("OpGetpolicyDumpRequest", offset));
3547 return (
3548 stack,
3549 missing_type.and_then(|t| OpGetpolicyDumpRequest::attr_from_type(t)),
3550 );
3551 }
3552 if cur > offset || cur + self.buf.len() < offset {
3553 return (stack, None);
3554 }
3555 let mut attrs = self.clone();
3556 let mut last_off = cur + attrs.pos;
3557 while let Some(attr) = attrs.next() {
3558 let Ok(attr) = attr else { break };
3559 match attr {
3560 OpGetpolicyDumpRequest::FamilyId(val) => {
3561 if last_off == offset {
3562 stack.push(("FamilyId", last_off));
3563 break;
3564 }
3565 }
3566 OpGetpolicyDumpRequest::FamilyName(val) => {
3567 if last_off == offset {
3568 stack.push(("FamilyName", last_off));
3569 break;
3570 }
3571 }
3572 OpGetpolicyDumpRequest::Op(val) => {
3573 if last_off == offset {
3574 stack.push(("Op", last_off));
3575 break;
3576 }
3577 }
3578 _ => {}
3579 };
3580 last_off = cur + attrs.pos;
3581 }
3582 if !stack.is_empty() {
3583 stack.push(("OpGetpolicyDumpRequest", cur));
3584 }
3585 (stack, None)
3586 }
3587}
3588#[doc = "Get / dump genetlink policies"]
3589pub struct PushOpGetpolicyDumpReply<Prev: Rec> {
3590 pub(crate) prev: Option<Prev>,
3591 pub(crate) header_offset: Option<usize>,
3592}
3593impl<Prev: Rec> Rec for PushOpGetpolicyDumpReply<Prev> {
3594 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
3595 self.prev.as_mut().unwrap().as_rec_mut()
3596 }
3597 fn as_rec(&self) -> &Vec<u8> {
3598 self.prev.as_ref().unwrap().as_rec()
3599 }
3600}
3601impl<Prev: Rec> PushOpGetpolicyDumpReply<Prev> {
3602 pub fn new(mut prev: Prev) -> Self {
3603 Self::write_header(&mut prev);
3604 Self::new_without_header(prev)
3605 }
3606 fn new_without_header(prev: Prev) -> Self {
3607 Self {
3608 prev: Some(prev),
3609 header_offset: None,
3610 }
3611 }
3612 fn write_header(prev: &mut Prev) {
3613 let mut header = PushBuiltinNfgenmsg::new();
3614 header.set_cmd(10u8);
3615 header.set_version(1u8);
3616 prev.as_rec_mut().extend(header.as_slice());
3617 }
3618 pub fn end_nested(mut self) -> Prev {
3619 let mut prev = self.prev.take().unwrap();
3620 if let Some(header_offset) = &self.header_offset {
3621 finalize_nested_header(prev.as_rec_mut(), *header_offset);
3622 }
3623 prev
3624 }
3625 pub fn push_family_id(mut self, value: u16) -> Self {
3626 push_header(self.as_rec_mut(), 1u16, 2 as u16);
3627 self.as_rec_mut().extend(value.to_ne_bytes());
3628 self
3629 }
3630 pub fn nested_policy(mut self) -> PushPolicyAttrs<Self> {
3631 let header_offset = push_nested_header(self.as_rec_mut(), 8u16);
3632 PushPolicyAttrs {
3633 prev: Some(self),
3634 header_offset: Some(header_offset),
3635 }
3636 }
3637 pub fn nested_op_policy(mut self) -> PushOpPolicyAttrs<Self> {
3638 let header_offset = push_nested_header(self.as_rec_mut(), 9u16);
3639 PushOpPolicyAttrs {
3640 prev: Some(self),
3641 header_offset: Some(header_offset),
3642 }
3643 }
3644}
3645impl<Prev: Rec> Drop for PushOpGetpolicyDumpReply<Prev> {
3646 fn drop(&mut self) {
3647 if let Some(prev) = &mut self.prev {
3648 if let Some(header_offset) = &self.header_offset {
3649 finalize_nested_header(prev.as_rec_mut(), *header_offset);
3650 }
3651 }
3652 }
3653}
3654#[doc = "Get / dump genetlink policies"]
3655#[derive(Clone)]
3656pub enum OpGetpolicyDumpReply<'a> {
3657 FamilyId(u16),
3658 Policy(IterablePolicyAttrs<'a>),
3659 OpPolicy(IterableOpPolicyAttrs<'a>),
3660}
3661impl<'a> IterableOpGetpolicyDumpReply<'a> {
3662 pub fn get_family_id(&self) -> Result<u16, ErrorContext> {
3663 let mut iter = self.clone();
3664 iter.pos = 0;
3665 for attr in iter {
3666 if let OpGetpolicyDumpReply::FamilyId(val) = attr? {
3667 return Ok(val);
3668 }
3669 }
3670 Err(ErrorContext::new_missing(
3671 "OpGetpolicyDumpReply",
3672 "FamilyId",
3673 self.orig_loc,
3674 self.buf.as_ptr() as usize,
3675 ))
3676 }
3677 pub fn get_policy(&self) -> Result<IterablePolicyAttrs<'a>, ErrorContext> {
3678 let mut iter = self.clone();
3679 iter.pos = 0;
3680 for attr in iter {
3681 if let OpGetpolicyDumpReply::Policy(val) = attr? {
3682 return Ok(val);
3683 }
3684 }
3685 Err(ErrorContext::new_missing(
3686 "OpGetpolicyDumpReply",
3687 "Policy",
3688 self.orig_loc,
3689 self.buf.as_ptr() as usize,
3690 ))
3691 }
3692 pub fn get_op_policy(&self) -> Result<IterableOpPolicyAttrs<'a>, ErrorContext> {
3693 let mut iter = self.clone();
3694 iter.pos = 0;
3695 for attr in iter {
3696 if let OpGetpolicyDumpReply::OpPolicy(val) = attr? {
3697 return Ok(val);
3698 }
3699 }
3700 Err(ErrorContext::new_missing(
3701 "OpGetpolicyDumpReply",
3702 "OpPolicy",
3703 self.orig_loc,
3704 self.buf.as_ptr() as usize,
3705 ))
3706 }
3707}
3708impl OpGetpolicyDumpReply<'_> {
3709 pub fn new<'a>(buf: &'a [u8]) -> IterableOpGetpolicyDumpReply<'a> {
3710 let (_header, attrs) = buf.split_at(buf.len().min(PushBuiltinNfgenmsg::len()));
3711 IterableOpGetpolicyDumpReply::with_loc(attrs, buf.as_ptr() as usize)
3712 }
3713 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3714 CtrlAttrs::attr_from_type(r#type)
3715 }
3716}
3717#[derive(Clone, Copy, Default)]
3718pub struct IterableOpGetpolicyDumpReply<'a> {
3719 buf: &'a [u8],
3720 pos: usize,
3721 orig_loc: usize,
3722}
3723impl<'a> IterableOpGetpolicyDumpReply<'a> {
3724 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3725 Self {
3726 buf,
3727 pos: 0,
3728 orig_loc,
3729 }
3730 }
3731 pub fn get_buf(&self) -> &'a [u8] {
3732 self.buf
3733 }
3734}
3735impl<'a> Iterator for IterableOpGetpolicyDumpReply<'a> {
3736 type Item = Result<OpGetpolicyDumpReply<'a>, ErrorContext>;
3737 fn next(&mut self) -> Option<Self::Item> {
3738 let pos = self.pos;
3739 let mut r#type;
3740 loop {
3741 r#type = None;
3742 if self.buf.len() == self.pos {
3743 return None;
3744 }
3745 let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
3746 break;
3747 };
3748 r#type = Some(header.r#type);
3749 let res = match header.r#type {
3750 1u16 => OpGetpolicyDumpReply::FamilyId({
3751 let res = parse_u16(next);
3752 let Some(val) = res else { break };
3753 val
3754 }),
3755 8u16 => OpGetpolicyDumpReply::Policy({
3756 let res = Some(IterablePolicyAttrs::with_loc(next, self.orig_loc));
3757 let Some(val) = res else { break };
3758 val
3759 }),
3760 9u16 => OpGetpolicyDumpReply::OpPolicy({
3761 let res = Some(IterableOpPolicyAttrs::with_loc(next, self.orig_loc));
3762 let Some(val) = res else { break };
3763 val
3764 }),
3765 n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
3766 n => continue,
3767 };
3768 return Some(Ok(res));
3769 }
3770 Some(Err(ErrorContext::new(
3771 "OpGetpolicyDumpReply",
3772 r#type.and_then(|t| OpGetpolicyDumpReply::attr_from_type(t)),
3773 self.orig_loc,
3774 self.buf.as_ptr().wrapping_add(pos) as usize,
3775 )))
3776 }
3777}
3778impl<'a> std::fmt::Debug for IterableOpGetpolicyDumpReply<'_> {
3779 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3780 let mut fmt = f.debug_struct("OpGetpolicyDumpReply");
3781 for attr in self.clone() {
3782 let attr = match attr {
3783 Ok(a) => a,
3784 Err(err) => {
3785 fmt.finish()?;
3786 f.write_str("Err(")?;
3787 err.fmt(f)?;
3788 return f.write_str(")");
3789 }
3790 };
3791 match attr {
3792 OpGetpolicyDumpReply::FamilyId(val) => fmt.field("FamilyId", &val),
3793 OpGetpolicyDumpReply::Policy(val) => fmt.field("Policy", &val),
3794 OpGetpolicyDumpReply::OpPolicy(val) => fmt.field("OpPolicy", &val),
3795 };
3796 }
3797 fmt.finish()
3798 }
3799}
3800impl IterableOpGetpolicyDumpReply<'_> {
3801 pub fn lookup_attr(
3802 &self,
3803 offset: usize,
3804 missing_type: Option<u16>,
3805 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3806 let mut stack = Vec::new();
3807 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3808 if cur == offset + PushBuiltinNfgenmsg::len() {
3809 stack.push(("OpGetpolicyDumpReply", offset));
3810 return (
3811 stack,
3812 missing_type.and_then(|t| OpGetpolicyDumpReply::attr_from_type(t)),
3813 );
3814 }
3815 if cur > offset || cur + self.buf.len() < offset {
3816 return (stack, None);
3817 }
3818 let mut attrs = self.clone();
3819 let mut last_off = cur + attrs.pos;
3820 let mut missing = None;
3821 while let Some(attr) = attrs.next() {
3822 let Ok(attr) = attr else { break };
3823 match attr {
3824 OpGetpolicyDumpReply::FamilyId(val) => {
3825 if last_off == offset {
3826 stack.push(("FamilyId", last_off));
3827 break;
3828 }
3829 }
3830 OpGetpolicyDumpReply::Policy(val) => {
3831 (stack, missing) = val.lookup_attr(offset, missing_type);
3832 if !stack.is_empty() {
3833 break;
3834 }
3835 }
3836 OpGetpolicyDumpReply::OpPolicy(val) => {
3837 (stack, missing) = val.lookup_attr(offset, missing_type);
3838 if !stack.is_empty() {
3839 break;
3840 }
3841 }
3842 _ => {}
3843 };
3844 last_off = cur + attrs.pos;
3845 }
3846 if !stack.is_empty() {
3847 stack.push(("OpGetpolicyDumpReply", cur));
3848 }
3849 (stack, missing)
3850 }
3851}
3852#[derive(Debug)]
3853pub struct RequestOpGetpolicyDumpRequest<'r> {
3854 request: Request<'r>,
3855}
3856impl<'r> RequestOpGetpolicyDumpRequest<'r> {
3857 pub fn new(mut request: Request<'r>) -> Self {
3858 PushOpGetpolicyDumpRequest::write_header(&mut request.buf_mut());
3859 Self {
3860 request: request.set_dump(),
3861 }
3862 }
3863 pub fn encode(&mut self) -> PushOpGetpolicyDumpRequest<&mut Vec<u8>> {
3864 PushOpGetpolicyDumpRequest::new_without_header(self.request.buf_mut())
3865 }
3866 pub fn into_encoder(self) -> PushOpGetpolicyDumpRequest<RequestBuf<'r>> {
3867 PushOpGetpolicyDumpRequest::new_without_header(self.request.buf)
3868 }
3869 pub fn decode_request<'buf>(buf: &'buf [u8]) -> IterableOpGetpolicyDumpRequest<'buf> {
3870 OpGetpolicyDumpRequest::new(buf)
3871 }
3872}
3873impl NetlinkRequest for RequestOpGetpolicyDumpRequest<'_> {
3874 fn protocol(&self) -> Protocol {
3875 Protocol::Raw {
3876 protonum: 0x10,
3877 request_type: 0x10,
3878 }
3879 }
3880 fn flags(&self) -> u16 {
3881 self.request.flags
3882 }
3883 fn payload(&self) -> &[u8] {
3884 self.request.buf()
3885 }
3886 type ReplyType<'buf> = IterableOpGetpolicyDumpReply<'buf>;
3887 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
3888 OpGetpolicyDumpReply::new(buf)
3889 }
3890 fn lookup(
3891 buf: &[u8],
3892 offset: usize,
3893 missing_type: Option<u16>,
3894 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3895 OpGetpolicyDumpRequest::new(buf).lookup_attr(offset, missing_type)
3896 }
3897}
3898use crate::traits::LookupFn;
3899use crate::utils::RequestBuf;
3900#[derive(Debug)]
3901pub struct Request<'buf> {
3902 buf: RequestBuf<'buf>,
3903 flags: u16,
3904 writeback: Option<&'buf mut Option<RequestInfo>>,
3905}
3906#[allow(unused)]
3907#[derive(Debug, Clone)]
3908pub struct RequestInfo {
3909 protocol: Protocol,
3910 flags: u16,
3911 name: &'static str,
3912 lookup: LookupFn,
3913}
3914impl Request<'static> {
3915 pub fn new() -> Self {
3916 Self::new_from_buf(Vec::new())
3917 }
3918 pub fn new_from_buf(buf: Vec<u8>) -> Self {
3919 Self {
3920 flags: 0,
3921 buf: RequestBuf::Own(buf),
3922 writeback: None,
3923 }
3924 }
3925 pub fn into_buf(self) -> Vec<u8> {
3926 match self.buf {
3927 RequestBuf::Own(buf) => buf,
3928 _ => unreachable!(),
3929 }
3930 }
3931}
3932impl<'buf> Request<'buf> {
3933 pub fn new_with_buf(buf: &'buf mut Vec<u8>) -> Self {
3934 buf.clear();
3935 Self::new_extend(buf)
3936 }
3937 pub fn new_extend(buf: &'buf mut Vec<u8>) -> Self {
3938 Self {
3939 flags: 0,
3940 buf: RequestBuf::Ref(buf),
3941 writeback: None,
3942 }
3943 }
3944 fn do_writeback(&mut self, protocol: Protocol, name: &'static str, lookup: LookupFn) {
3945 let Some(writeback) = &mut self.writeback else {
3946 return;
3947 };
3948 **writeback = Some(RequestInfo {
3949 protocol,
3950 flags: self.flags,
3951 name,
3952 lookup,
3953 })
3954 }
3955 pub fn buf(&self) -> &Vec<u8> {
3956 self.buf.buf()
3957 }
3958 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
3959 self.buf.buf_mut()
3960 }
3961 #[doc = "Set `NLM_F_CREATE` flag"]
3962 pub fn set_create(mut self) -> Self {
3963 self.flags |= consts::NLM_F_CREATE as u16;
3964 self
3965 }
3966 #[doc = "Set `NLM_F_EXCL` flag"]
3967 pub fn set_excl(mut self) -> Self {
3968 self.flags |= consts::NLM_F_EXCL as u16;
3969 self
3970 }
3971 #[doc = "Set `NLM_F_REPLACE` flag"]
3972 pub fn set_replace(mut self) -> Self {
3973 self.flags |= consts::NLM_F_REPLACE as u16;
3974 self
3975 }
3976 #[doc = "Set `NLM_F_CREATE` and `NLM_F_REPLACE` flag"]
3977 pub fn set_change(self) -> Self {
3978 self.set_create().set_replace()
3979 }
3980 #[doc = "Set `NLM_F_APPEND` flag"]
3981 pub fn set_append(mut self) -> Self {
3982 self.flags |= consts::NLM_F_APPEND as u16;
3983 self
3984 }
3985 #[doc = "Set `NLM_F_DUMP` flag"]
3986 fn set_dump(mut self) -> Self {
3987 self.flags |= consts::NLM_F_DUMP as u16;
3988 self
3989 }
3990 pub fn op_getfamily_dump_request(self) -> RequestOpGetfamilyDumpRequest<'buf> {
3991 let mut res = RequestOpGetfamilyDumpRequest::new(self);
3992 res.request.do_writeback(
3993 res.protocol(),
3994 "op-getfamily-dump-request",
3995 RequestOpGetfamilyDumpRequest::lookup,
3996 );
3997 res
3998 }
3999 pub fn op_getfamily_do_request(self) -> RequestOpGetfamilyDoRequest<'buf> {
4000 let mut res = RequestOpGetfamilyDoRequest::new(self);
4001 res.request.do_writeback(
4002 res.protocol(),
4003 "op-getfamily-do-request",
4004 RequestOpGetfamilyDoRequest::lookup,
4005 );
4006 res
4007 }
4008 pub fn op_getpolicy_dump_request(self) -> RequestOpGetpolicyDumpRequest<'buf> {
4009 let mut res = RequestOpGetpolicyDumpRequest::new(self);
4010 res.request.do_writeback(
4011 res.protocol(),
4012 "op-getpolicy-dump-request",
4013 RequestOpGetpolicyDumpRequest::lookup,
4014 );
4015 res
4016 }
4017}