1#![doc = "Netfilter nftables configuration over netlink.\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"nftables";
17pub const PROTONUM: u16 = 12u16;
18#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
19#[derive(Debug, Clone, Copy)]
20pub enum MetaKeys {
21 Len = 0,
22 Protocol = 1,
23 Priority = 2,
24 Mark = 3,
25 Iif = 4,
26 Oif = 5,
27 Iifname = 6,
28 Oifname = 7,
29 Iftype = 8,
30 Oiftype = 9,
31 Skuid = 10,
32 Skgid = 11,
33 Nftrace = 12,
34 Rtclassid = 13,
35 Secmark = 14,
36 Nfproto = 15,
37 L4Proto = 16,
38 BriIifname = 17,
39 BriOifname = 18,
40 Pkttype = 19,
41 Cpu = 20,
42 Iifgroup = 21,
43 Oifgroup = 22,
44 Cgroup = 23,
45 Prandom = 24,
46 Secpath = 25,
47 Iifkind = 26,
48 Oifkind = 27,
49 BriIifpvid = 28,
50 BriIifvproto = 29,
51 TimeNs = 30,
52 TimeDay = 31,
53 TimeHour = 32,
54 Sdif = 33,
55 Sdifname = 34,
56 BriBroute = 35,
57}
58impl MetaKeys {
59 pub fn from_value(value: u64) -> Option<Self> {
60 Some(match value {
61 0 => Self::Len,
62 1 => Self::Protocol,
63 2 => Self::Priority,
64 3 => Self::Mark,
65 4 => Self::Iif,
66 5 => Self::Oif,
67 6 => Self::Iifname,
68 7 => Self::Oifname,
69 8 => Self::Iftype,
70 9 => Self::Oiftype,
71 10 => Self::Skuid,
72 11 => Self::Skgid,
73 12 => Self::Nftrace,
74 13 => Self::Rtclassid,
75 14 => Self::Secmark,
76 15 => Self::Nfproto,
77 16 => Self::L4Proto,
78 17 => Self::BriIifname,
79 18 => Self::BriOifname,
80 19 => Self::Pkttype,
81 20 => Self::Cpu,
82 21 => Self::Iifgroup,
83 22 => Self::Oifgroup,
84 23 => Self::Cgroup,
85 24 => Self::Prandom,
86 25 => Self::Secpath,
87 26 => Self::Iifkind,
88 27 => Self::Oifkind,
89 28 => Self::BriIifpvid,
90 29 => Self::BriIifvproto,
91 30 => Self::TimeNs,
92 31 => Self::TimeDay,
93 32 => Self::TimeHour,
94 33 => Self::Sdif,
95 34 => Self::Sdifname,
96 35 => Self::BriBroute,
97 _ => return None,
98 })
99 }
100}
101#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
102#[derive(Debug, Clone, Copy)]
103pub enum BitwiseOps {
104 #[doc = "mask-and-xor operation used to implement NOT, AND, OR and XOR\n dreg = (sreg & mask) ^ xor\nwith these mask and xor values:\n mask xor\n NOT: 1 1\n OR: ~x x\n XOR: 1 x\n AND: x 0\n"]
105 MaskXor = 0,
106 Lshift = 1,
107 Rshift = 2,
108 And = 3,
109 Or = 4,
110 Xor = 5,
111}
112impl BitwiseOps {
113 pub fn from_value(value: u64) -> Option<Self> {
114 Some(match value {
115 0 => Self::MaskXor,
116 1 => Self::Lshift,
117 2 => Self::Rshift,
118 3 => Self::And,
119 4 => Self::Or,
120 5 => Self::Xor,
121 _ => return None,
122 })
123 }
124}
125#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
126#[derive(Debug, Clone, Copy)]
127pub enum CmpOps {
128 Eq = 0,
129 Neq = 1,
130 Lt = 2,
131 Lte = 3,
132 Gt = 4,
133 Gte = 5,
134}
135impl CmpOps {
136 pub fn from_value(value: u64) -> Option<Self> {
137 Some(match value {
138 0 => Self::Eq,
139 1 => Self::Neq,
140 2 => Self::Lt,
141 3 => Self::Lte,
142 4 => Self::Gt,
143 5 => Self::Gte,
144 _ => return None,
145 })
146 }
147}
148#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
149#[derive(Debug, Clone, Copy)]
150pub enum ObjectType {
151 Unspec = 0,
152 Counter = 1,
153 Quota = 2,
154 CtHelper = 3,
155 Limit = 4,
156 Connlimit = 5,
157 Tunnel = 6,
158 CtTimeout = 7,
159 Secmark = 8,
160 CtExpect = 9,
161 Synproxy = 10,
162}
163impl ObjectType {
164 pub fn from_value(value: u64) -> Option<Self> {
165 Some(match value {
166 0 => Self::Unspec,
167 1 => Self::Counter,
168 2 => Self::Quota,
169 3 => Self::CtHelper,
170 4 => Self::Limit,
171 5 => Self::Connlimit,
172 6 => Self::Tunnel,
173 7 => Self::CtTimeout,
174 8 => Self::Secmark,
175 9 => Self::CtExpect,
176 10 => Self::Synproxy,
177 _ => return None,
178 })
179 }
180}
181#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
182#[derive(Debug, Clone, Copy)]
183pub enum NatRangeFlags {
184 MapIps = 1 << 0,
185 ProtoSpecified = 1 << 1,
186 ProtoRandom = 1 << 2,
187 Persistent = 1 << 3,
188 ProtoRandomFully = 1 << 4,
189 ProtoOffset = 1 << 5,
190 Netmap = 1 << 6,
191}
192impl NatRangeFlags {
193 pub fn from_value(value: u64) -> Option<Self> {
194 Some(match value {
195 n if n == 1 << 0 => Self::MapIps,
196 n if n == 1 << 1 => Self::ProtoSpecified,
197 n if n == 1 << 2 => Self::ProtoRandom,
198 n if n == 1 << 3 => Self::Persistent,
199 n if n == 1 << 4 => Self::ProtoRandomFully,
200 n if n == 1 << 5 => Self::ProtoOffset,
201 n if n == 1 << 6 => Self::Netmap,
202 _ => return None,
203 })
204 }
205}
206#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
207#[derive(Debug, Clone, Copy)]
208pub enum TableFlags {
209 Dormant = 1 << 0,
210 Owner = 1 << 1,
211 Persist = 1 << 2,
212}
213impl TableFlags {
214 pub fn from_value(value: u64) -> Option<Self> {
215 Some(match value {
216 n if n == 1 << 0 => Self::Dormant,
217 n if n == 1 << 1 => Self::Owner,
218 n if n == 1 << 2 => Self::Persist,
219 _ => return None,
220 })
221 }
222}
223#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
224#[derive(Debug, Clone, Copy)]
225pub enum ChainFlags {
226 Base = 1 << 0,
227 HwOffload = 1 << 1,
228 Binding = 1 << 2,
229}
230impl ChainFlags {
231 pub fn from_value(value: u64) -> Option<Self> {
232 Some(match value {
233 n if n == 1 << 0 => Self::Base,
234 n if n == 1 << 1 => Self::HwOffload,
235 n if n == 1 << 2 => Self::Binding,
236 _ => return None,
237 })
238 }
239}
240#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
241#[derive(Debug, Clone, Copy)]
242pub enum SetFlags {
243 Anonymous = 1 << 0,
244 Constant = 1 << 1,
245 Interval = 1 << 2,
246 Map = 1 << 3,
247 Timeout = 1 << 4,
248 Eval = 1 << 5,
249 Object = 1 << 6,
250 Concat = 1 << 7,
251 Expr = 1 << 8,
252}
253impl SetFlags {
254 pub fn from_value(value: u64) -> Option<Self> {
255 Some(match value {
256 n if n == 1 << 0 => Self::Anonymous,
257 n if n == 1 << 1 => Self::Constant,
258 n if n == 1 << 2 => Self::Interval,
259 n if n == 1 << 3 => Self::Map,
260 n if n == 1 << 4 => Self::Timeout,
261 n if n == 1 << 5 => Self::Eval,
262 n if n == 1 << 6 => Self::Object,
263 n if n == 1 << 7 => Self::Concat,
264 n if n == 1 << 8 => Self::Expr,
265 _ => return None,
266 })
267 }
268}
269#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
270#[derive(Debug, Clone, Copy)]
271pub enum LookupFlags {
272 Invert = 1 << 0,
273}
274impl LookupFlags {
275 pub fn from_value(value: u64) -> Option<Self> {
276 Some(match value {
277 n if n == 1 << 0 => Self::Invert,
278 _ => return None,
279 })
280 }
281}
282#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
283#[derive(Debug, Clone, Copy)]
284pub enum CtKeys {
285 State = 0,
286 Direction = 1,
287 Status = 2,
288 Mark = 3,
289 Secmark = 4,
290 Expiration = 5,
291 Helper = 6,
292 L3protocol = 7,
293 Src = 8,
294 Dst = 9,
295 Protocol = 10,
296 ProtoSrc = 11,
297 ProtoDst = 12,
298 Labels = 13,
299 Pkts = 14,
300 Bytes = 15,
301 Avgpkt = 16,
302 Zone = 17,
303 Eventmask = 18,
304 SrcIp = 19,
305 DstIp = 20,
306 SrcIp6 = 21,
307 DstIp6 = 22,
308 CtId = 23,
309}
310impl CtKeys {
311 pub fn from_value(value: u64) -> Option<Self> {
312 Some(match value {
313 0 => Self::State,
314 1 => Self::Direction,
315 2 => Self::Status,
316 3 => Self::Mark,
317 4 => Self::Secmark,
318 5 => Self::Expiration,
319 6 => Self::Helper,
320 7 => Self::L3protocol,
321 8 => Self::Src,
322 9 => Self::Dst,
323 10 => Self::Protocol,
324 11 => Self::ProtoSrc,
325 12 => Self::ProtoDst,
326 13 => Self::Labels,
327 14 => Self::Pkts,
328 15 => Self::Bytes,
329 16 => Self::Avgpkt,
330 17 => Self::Zone,
331 18 => Self::Eventmask,
332 19 => Self::SrcIp,
333 20 => Self::DstIp,
334 21 => Self::SrcIp6,
335 22 => Self::DstIp6,
336 23 => Self::CtId,
337 _ => return None,
338 })
339 }
340}
341#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
342#[derive(Debug, Clone, Copy)]
343pub enum CtDirection {
344 Original = 0,
345 Reply = 1,
346}
347impl CtDirection {
348 pub fn from_value(value: u64) -> Option<Self> {
349 Some(match value {
350 0 => Self::Original,
351 1 => Self::Reply,
352 _ => return None,
353 })
354 }
355}
356#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
357#[derive(Debug, Clone, Copy)]
358pub enum QuotaFlags {
359 Invert = 1 << 0,
360 Depleted = 1 << 1,
361}
362impl QuotaFlags {
363 pub fn from_value(value: u64) -> Option<Self> {
364 Some(match value {
365 n if n == 1 << 0 => Self::Invert,
366 n if n == 1 << 1 => Self::Depleted,
367 _ => return None,
368 })
369 }
370}
371#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
372#[derive(Debug, Clone, Copy)]
373pub enum VerdictCode {
374 Continue = 4294967295,
375 Break = 4294967294,
376 Jump = 4294967293,
377 Goto = 4294967292,
378 Return = 4294967291,
379 Drop = 0,
380 Accept = 1,
381 Stolen = 2,
382 Queue = 3,
383 Repeat = 4,
384}
385impl VerdictCode {
386 pub fn from_value(value: u64) -> Option<Self> {
387 Some(match value {
388 4294967295 => Self::Continue,
389 4294967294 => Self::Break,
390 4294967293 => Self::Jump,
391 4294967292 => Self::Goto,
392 4294967291 => Self::Return,
393 0 => Self::Drop,
394 1 => Self::Accept,
395 2 => Self::Stolen,
396 3 => Self::Queue,
397 4 => Self::Repeat,
398 _ => return None,
399 })
400 }
401}
402#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
403#[derive(Debug, Clone, Copy)]
404pub enum FibResult {
405 Oif = 0,
406 Oifname = 1,
407 Addrtype = 2,
408}
409impl FibResult {
410 pub fn from_value(value: u64) -> Option<Self> {
411 Some(match value {
412 0 => Self::Oif,
413 1 => Self::Oifname,
414 2 => Self::Addrtype,
415 _ => return None,
416 })
417 }
418}
419#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
420#[derive(Debug, Clone, Copy)]
421pub enum FibFlags {
422 Saddr = 1 << 0,
423 Daddr = 1 << 1,
424 Mark = 1 << 2,
425 Iif = 1 << 3,
426 Oif = 1 << 4,
427 Present = 1 << 5,
428}
429impl FibFlags {
430 pub fn from_value(value: u64) -> Option<Self> {
431 Some(match value {
432 n if n == 1 << 0 => Self::Saddr,
433 n if n == 1 << 1 => Self::Daddr,
434 n if n == 1 << 2 => Self::Mark,
435 n if n == 1 << 3 => Self::Iif,
436 n if n == 1 << 4 => Self::Oif,
437 n if n == 1 << 5 => Self::Present,
438 _ => return None,
439 })
440 }
441}
442#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
443#[derive(Debug, Clone, Copy)]
444pub enum RejectTypes {
445 IcmpUnreach = 0,
446 TcpRst = 1,
447 IcmpxUnreach = 2,
448}
449impl RejectTypes {
450 pub fn from_value(value: u64) -> Option<Self> {
451 Some(match value {
452 0 => Self::IcmpUnreach,
453 1 => Self::TcpRst,
454 2 => Self::IcmpxUnreach,
455 _ => return None,
456 })
457 }
458}
459#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
460#[derive(Debug, Clone, Copy)]
461pub enum PayloadBase {
462 LinkLayerHeader = 0,
463 NetworkHeader = 1,
464 TransportHeader = 2,
465 InnerHeader = 3,
466 TunHeader = 4,
467}
468impl PayloadBase {
469 pub fn from_value(value: u64) -> Option<Self> {
470 Some(match value {
471 0 => Self::LinkLayerHeader,
472 1 => Self::NetworkHeader,
473 2 => Self::TransportHeader,
474 3 => Self::InnerHeader,
475 4 => Self::TunHeader,
476 _ => return None,
477 })
478 }
479}
480#[doc = "Range operator"]
481#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
482#[derive(Debug, Clone, Copy)]
483pub enum RangeOps {
484 Eq = 0,
485 Neq = 1,
486}
487impl RangeOps {
488 pub fn from_value(value: u64) -> Option<Self> {
489 Some(match value {
490 0 => Self::Eq,
491 1 => Self::Neq,
492 _ => return None,
493 })
494 }
495}
496#[doc = "nf_tables registers.\nnf_tables used to have five registers: a verdict register and four data\nregisters of size 16. The data registers have been changed to 16 registers\nof size 4. For compatibility reasons, the NFT_REG_[1-4] registers still\nmap to areas of size 16, the 4 byte registers are addressed using\nNFT_REG32_00 - NFT_REG32_15.\n"]
497#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
498#[derive(Debug, Clone, Copy)]
499pub enum Registers {
500 RegVerdict = 0,
501 Reg1 = 1,
502 Reg2 = 2,
503 Reg3 = 3,
504 Reg4 = 4,
505 Reg3200 = 8,
506 Reg3201 = 9,
507 Reg3202 = 10,
508 Reg3203 = 11,
509 Reg3204 = 12,
510 Reg3205 = 13,
511 Reg3206 = 14,
512 Reg3207 = 15,
513 Reg3208 = 16,
514 Reg3209 = 17,
515 Reg3210 = 18,
516 Reg3211 = 19,
517 Reg3212 = 20,
518 Reg3213 = 21,
519 Reg3214 = 22,
520 Reg3215 = 23,
521}
522impl Registers {
523 pub fn from_value(value: u64) -> Option<Self> {
524 Some(match value {
525 0 => Self::RegVerdict,
526 1 => Self::Reg1,
527 2 => Self::Reg2,
528 3 => Self::Reg3,
529 4 => Self::Reg4,
530 8 => Self::Reg3200,
531 9 => Self::Reg3201,
532 10 => Self::Reg3202,
533 11 => Self::Reg3203,
534 12 => Self::Reg3204,
535 13 => Self::Reg3205,
536 14 => Self::Reg3206,
537 15 => Self::Reg3207,
538 16 => Self::Reg3208,
539 17 => Self::Reg3209,
540 18 => Self::Reg3210,
541 19 => Self::Reg3211,
542 20 => Self::Reg3212,
543 21 => Self::Reg3213,
544 22 => Self::Reg3214,
545 23 => Self::Reg3215,
546 _ => return None,
547 })
548 }
549}
550#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
551#[derive(Debug, Clone, Copy)]
552pub enum NumgenTypes {
553 Incremental = 0,
554 Random = 1,
555}
556impl NumgenTypes {
557 pub fn from_value(value: u64) -> Option<Self> {
558 Some(match value {
559 0 => Self::Incremental,
560 1 => Self::Random,
561 _ => return None,
562 })
563 }
564}
565#[doc = "nf_tables log levels"]
566#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
567#[derive(Debug, Clone, Copy)]
568pub enum LogLevel {
569 #[doc = "system is unusable"]
570 Emerg = 0,
571 #[doc = "action must be taken immediately"]
572 Alert = 1,
573 #[doc = "critical conditions"]
574 Crit = 2,
575 #[doc = "error conditions"]
576 Err = 3,
577 #[doc = "warning conditions"]
578 Warning = 4,
579 #[doc = "normal but significant condition"]
580 Notice = 5,
581 #[doc = "informational"]
582 Info = 6,
583 #[doc = "debug-level messages"]
584 Debug = 7,
585 #[doc = "enabling audit logging"]
586 Audit = 8,
587}
588impl LogLevel {
589 pub fn from_value(value: u64) -> Option<Self> {
590 Some(match value {
591 0 => Self::Emerg,
592 1 => Self::Alert,
593 2 => Self::Crit,
594 3 => Self::Err,
595 4 => Self::Warning,
596 5 => Self::Notice,
597 6 => Self::Info,
598 7 => Self::Debug,
599 8 => Self::Audit,
600 _ => return None,
601 })
602 }
603}
604#[doc = "nf_tables log flags"]
605#[doc = "Flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)"]
606#[derive(Debug, Clone, Copy)]
607pub enum LogFlags {
608 #[doc = "Log TCP sequence numbers"]
609 Tcpseq = 1 << 0,
610 #[doc = "Log TCP options"]
611 Tcpopt = 1 << 1,
612 #[doc = "Log IP options"]
613 Ipopt = 1 << 2,
614 #[doc = "Log UID owning local socket"]
615 Uid = 1 << 3,
616 #[doc = "Unsupported, don't reuse"]
617 Nflog = 1 << 4,
618 #[doc = "Decode MAC header"]
619 Macdecode = 1 << 5,
620}
621impl LogFlags {
622 pub fn from_value(value: u64) -> Option<Self> {
623 Some(match value {
624 n if n == 1 << 0 => Self::Tcpseq,
625 n if n == 1 << 1 => Self::Tcpopt,
626 n if n == 1 << 2 => Self::Ipopt,
627 n if n == 1 << 3 => Self::Uid,
628 n if n == 1 << 4 => Self::Nflog,
629 n if n == 1 << 5 => Self::Macdecode,
630 _ => return None,
631 })
632 }
633}
634#[derive(Clone)]
635pub enum LogAttrs<'a> {
636 #[doc = "netlink group to send messages to"]
637 Group(u16),
638 #[doc = "prefix to prepend to log messages"]
639 Prefix(&'a CStr),
640 #[doc = "length of payload to include in netlink message"]
641 Snaplen(u32),
642 #[doc = "queue threshold"]
643 Qthreshold(u16),
644 #[doc = "log level\nAssociated type: \"LogLevel\" (enum)"]
645 Level(u32),
646 #[doc = "logging flags\nAssociated type: \"LogFlags\" (enum)"]
647 Flags(u32),
648}
649impl<'a> IterableLogAttrs<'a> {
650 #[doc = "netlink group to send messages to"]
651 pub fn get_group(&self) -> Result<u16, ErrorContext> {
652 let mut iter = self.clone();
653 iter.pos = 0;
654 for attr in iter {
655 if let LogAttrs::Group(val) = attr? {
656 return Ok(val);
657 }
658 }
659 Err(ErrorContext::new_missing(
660 "LogAttrs",
661 "Group",
662 self.orig_loc,
663 self.buf.as_ptr() as usize,
664 ))
665 }
666 #[doc = "prefix to prepend to log messages"]
667 pub fn get_prefix(&self) -> Result<&'a CStr, ErrorContext> {
668 let mut iter = self.clone();
669 iter.pos = 0;
670 for attr in iter {
671 if let LogAttrs::Prefix(val) = attr? {
672 return Ok(val);
673 }
674 }
675 Err(ErrorContext::new_missing(
676 "LogAttrs",
677 "Prefix",
678 self.orig_loc,
679 self.buf.as_ptr() as usize,
680 ))
681 }
682 #[doc = "length of payload to include in netlink message"]
683 pub fn get_snaplen(&self) -> Result<u32, ErrorContext> {
684 let mut iter = self.clone();
685 iter.pos = 0;
686 for attr in iter {
687 if let LogAttrs::Snaplen(val) = attr? {
688 return Ok(val);
689 }
690 }
691 Err(ErrorContext::new_missing(
692 "LogAttrs",
693 "Snaplen",
694 self.orig_loc,
695 self.buf.as_ptr() as usize,
696 ))
697 }
698 #[doc = "queue threshold"]
699 pub fn get_qthreshold(&self) -> Result<u16, ErrorContext> {
700 let mut iter = self.clone();
701 iter.pos = 0;
702 for attr in iter {
703 if let LogAttrs::Qthreshold(val) = attr? {
704 return Ok(val);
705 }
706 }
707 Err(ErrorContext::new_missing(
708 "LogAttrs",
709 "Qthreshold",
710 self.orig_loc,
711 self.buf.as_ptr() as usize,
712 ))
713 }
714 #[doc = "log level\nAssociated type: \"LogLevel\" (enum)"]
715 pub fn get_level(&self) -> Result<u32, ErrorContext> {
716 let mut iter = self.clone();
717 iter.pos = 0;
718 for attr in iter {
719 if let LogAttrs::Level(val) = attr? {
720 return Ok(val);
721 }
722 }
723 Err(ErrorContext::new_missing(
724 "LogAttrs",
725 "Level",
726 self.orig_loc,
727 self.buf.as_ptr() as usize,
728 ))
729 }
730 #[doc = "logging flags\nAssociated type: \"LogFlags\" (enum)"]
731 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
732 let mut iter = self.clone();
733 iter.pos = 0;
734 for attr in iter {
735 if let LogAttrs::Flags(val) = attr? {
736 return Ok(val);
737 }
738 }
739 Err(ErrorContext::new_missing(
740 "LogAttrs",
741 "Flags",
742 self.orig_loc,
743 self.buf.as_ptr() as usize,
744 ))
745 }
746}
747impl<'a> LogAttrs<'a> {
748 pub fn new(buf: &'a [u8]) -> IterableLogAttrs<'a> {
749 IterableLogAttrs::with_loc(buf, buf.as_ptr() as usize)
750 }
751 fn attr_from_type(r#type: u16) -> Option<&'static str> {
752 let res = match r#type {
753 1u16 => "Group",
754 2u16 => "Prefix",
755 3u16 => "Snaplen",
756 4u16 => "Qthreshold",
757 5u16 => "Level",
758 6u16 => "Flags",
759 _ => return None,
760 };
761 Some(res)
762 }
763}
764#[derive(Clone, Copy, Default)]
765pub struct IterableLogAttrs<'a> {
766 buf: &'a [u8],
767 pos: usize,
768 orig_loc: usize,
769}
770impl<'a> IterableLogAttrs<'a> {
771 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
772 Self {
773 buf,
774 pos: 0,
775 orig_loc,
776 }
777 }
778 pub fn get_buf(&self) -> &'a [u8] {
779 self.buf
780 }
781}
782impl<'a> Iterator for IterableLogAttrs<'a> {
783 type Item = Result<LogAttrs<'a>, ErrorContext>;
784 fn next(&mut self) -> Option<Self::Item> {
785 if self.buf.len() == self.pos {
786 return None;
787 }
788 let pos = self.pos;
789 let mut r#type = None;
790 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
791 r#type = Some(header.r#type);
792 let res = match header.r#type {
793 1u16 => LogAttrs::Group({
794 let res = parse_be_u16(next);
795 let Some(val) = res else { break };
796 val
797 }),
798 2u16 => LogAttrs::Prefix({
799 let res = CStr::from_bytes_with_nul(next).ok();
800 let Some(val) = res else { break };
801 val
802 }),
803 3u16 => LogAttrs::Snaplen({
804 let res = parse_be_u32(next);
805 let Some(val) = res else { break };
806 val
807 }),
808 4u16 => LogAttrs::Qthreshold({
809 let res = parse_be_u16(next);
810 let Some(val) = res else { break };
811 val
812 }),
813 5u16 => LogAttrs::Level({
814 let res = parse_be_u32(next);
815 let Some(val) = res else { break };
816 val
817 }),
818 6u16 => LogAttrs::Flags({
819 let res = parse_be_u32(next);
820 let Some(val) = res else { break };
821 val
822 }),
823 n => {
824 if cfg!(any(test, feature = "deny-unknown-attrs")) {
825 break;
826 } else {
827 continue;
828 }
829 }
830 };
831 return Some(Ok(res));
832 }
833 Some(Err(ErrorContext::new(
834 "LogAttrs",
835 r#type.and_then(|t| LogAttrs::attr_from_type(t)),
836 self.orig_loc,
837 self.buf.as_ptr().wrapping_add(pos) as usize,
838 )))
839 }
840}
841impl<'a> std::fmt::Debug for IterableLogAttrs<'_> {
842 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
843 let mut fmt = f.debug_struct("LogAttrs");
844 for attr in self.clone() {
845 let attr = match attr {
846 Ok(a) => a,
847 Err(err) => {
848 fmt.finish()?;
849 f.write_str("Err(")?;
850 err.fmt(f)?;
851 return f.write_str(")");
852 }
853 };
854 match attr {
855 LogAttrs::Group(val) => fmt.field("Group", &val),
856 LogAttrs::Prefix(val) => fmt.field("Prefix", &val),
857 LogAttrs::Snaplen(val) => fmt.field("Snaplen", &val),
858 LogAttrs::Qthreshold(val) => fmt.field("Qthreshold", &val),
859 LogAttrs::Level(val) => {
860 fmt.field("Level", &FormatEnum(val.into(), LogLevel::from_value))
861 }
862 LogAttrs::Flags(val) => {
863 fmt.field("Flags", &FormatFlags(val.into(), LogFlags::from_value))
864 }
865 };
866 }
867 fmt.finish()
868 }
869}
870impl IterableLogAttrs<'_> {
871 pub fn lookup_attr(
872 &self,
873 offset: usize,
874 missing_type: Option<u16>,
875 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
876 let mut stack = Vec::new();
877 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
878 if cur == offset {
879 stack.push(("LogAttrs", offset));
880 return (
881 stack,
882 missing_type.and_then(|t| LogAttrs::attr_from_type(t)),
883 );
884 }
885 if cur > offset || cur + self.buf.len() < offset {
886 return (stack, None);
887 }
888 let mut attrs = self.clone();
889 let mut last_off = cur + attrs.pos;
890 while let Some(attr) = attrs.next() {
891 let Ok(attr) = attr else { break };
892 match attr {
893 LogAttrs::Group(val) => {
894 if last_off == offset {
895 stack.push(("Group", last_off));
896 break;
897 }
898 }
899 LogAttrs::Prefix(val) => {
900 if last_off == offset {
901 stack.push(("Prefix", last_off));
902 break;
903 }
904 }
905 LogAttrs::Snaplen(val) => {
906 if last_off == offset {
907 stack.push(("Snaplen", last_off));
908 break;
909 }
910 }
911 LogAttrs::Qthreshold(val) => {
912 if last_off == offset {
913 stack.push(("Qthreshold", last_off));
914 break;
915 }
916 }
917 LogAttrs::Level(val) => {
918 if last_off == offset {
919 stack.push(("Level", last_off));
920 break;
921 }
922 }
923 LogAttrs::Flags(val) => {
924 if last_off == offset {
925 stack.push(("Flags", last_off));
926 break;
927 }
928 }
929 _ => {}
930 };
931 last_off = cur + attrs.pos;
932 }
933 if !stack.is_empty() {
934 stack.push(("LogAttrs", cur));
935 }
936 (stack, None)
937 }
938}
939#[derive(Clone)]
940pub enum NumgenAttrs {
941 #[doc = "destination register\nAssociated type: \"Registers\" (enum)"]
942 Dreg(u32),
943 #[doc = "maximum counter value"]
944 Modulus(u32),
945 #[doc = "operation type\nAssociated type: \"NumgenTypes\" (enum)"]
946 Type(u32),
947 #[doc = "offset to be added to the counter"]
948 Offset(u32),
949}
950impl<'a> IterableNumgenAttrs<'a> {
951 #[doc = "destination register\nAssociated type: \"Registers\" (enum)"]
952 pub fn get_dreg(&self) -> Result<u32, ErrorContext> {
953 let mut iter = self.clone();
954 iter.pos = 0;
955 for attr in iter {
956 if let NumgenAttrs::Dreg(val) = attr? {
957 return Ok(val);
958 }
959 }
960 Err(ErrorContext::new_missing(
961 "NumgenAttrs",
962 "Dreg",
963 self.orig_loc,
964 self.buf.as_ptr() as usize,
965 ))
966 }
967 #[doc = "maximum counter value"]
968 pub fn get_modulus(&self) -> Result<u32, ErrorContext> {
969 let mut iter = self.clone();
970 iter.pos = 0;
971 for attr in iter {
972 if let NumgenAttrs::Modulus(val) = attr? {
973 return Ok(val);
974 }
975 }
976 Err(ErrorContext::new_missing(
977 "NumgenAttrs",
978 "Modulus",
979 self.orig_loc,
980 self.buf.as_ptr() as usize,
981 ))
982 }
983 #[doc = "operation type\nAssociated type: \"NumgenTypes\" (enum)"]
984 pub fn get_type(&self) -> Result<u32, ErrorContext> {
985 let mut iter = self.clone();
986 iter.pos = 0;
987 for attr in iter {
988 if let NumgenAttrs::Type(val) = attr? {
989 return Ok(val);
990 }
991 }
992 Err(ErrorContext::new_missing(
993 "NumgenAttrs",
994 "Type",
995 self.orig_loc,
996 self.buf.as_ptr() as usize,
997 ))
998 }
999 #[doc = "offset to be added to the counter"]
1000 pub fn get_offset(&self) -> Result<u32, ErrorContext> {
1001 let mut iter = self.clone();
1002 iter.pos = 0;
1003 for attr in iter {
1004 if let NumgenAttrs::Offset(val) = attr? {
1005 return Ok(val);
1006 }
1007 }
1008 Err(ErrorContext::new_missing(
1009 "NumgenAttrs",
1010 "Offset",
1011 self.orig_loc,
1012 self.buf.as_ptr() as usize,
1013 ))
1014 }
1015}
1016impl NumgenAttrs {
1017 pub fn new(buf: &'_ [u8]) -> IterableNumgenAttrs<'_> {
1018 IterableNumgenAttrs::with_loc(buf, buf.as_ptr() as usize)
1019 }
1020 fn attr_from_type(r#type: u16) -> Option<&'static str> {
1021 let res = match r#type {
1022 1u16 => "Dreg",
1023 2u16 => "Modulus",
1024 3u16 => "Type",
1025 4u16 => "Offset",
1026 _ => return None,
1027 };
1028 Some(res)
1029 }
1030}
1031#[derive(Clone, Copy, Default)]
1032pub struct IterableNumgenAttrs<'a> {
1033 buf: &'a [u8],
1034 pos: usize,
1035 orig_loc: usize,
1036}
1037impl<'a> IterableNumgenAttrs<'a> {
1038 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1039 Self {
1040 buf,
1041 pos: 0,
1042 orig_loc,
1043 }
1044 }
1045 pub fn get_buf(&self) -> &'a [u8] {
1046 self.buf
1047 }
1048}
1049impl<'a> Iterator for IterableNumgenAttrs<'a> {
1050 type Item = Result<NumgenAttrs, ErrorContext>;
1051 fn next(&mut self) -> Option<Self::Item> {
1052 if self.buf.len() == self.pos {
1053 return None;
1054 }
1055 let pos = self.pos;
1056 let mut r#type = None;
1057 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
1058 r#type = Some(header.r#type);
1059 let res = match header.r#type {
1060 1u16 => NumgenAttrs::Dreg({
1061 let res = parse_u32(next);
1062 let Some(val) = res else { break };
1063 val
1064 }),
1065 2u16 => NumgenAttrs::Modulus({
1066 let res = parse_be_u32(next);
1067 let Some(val) = res else { break };
1068 val
1069 }),
1070 3u16 => NumgenAttrs::Type({
1071 let res = parse_be_u32(next);
1072 let Some(val) = res else { break };
1073 val
1074 }),
1075 4u16 => NumgenAttrs::Offset({
1076 let res = parse_be_u32(next);
1077 let Some(val) = res else { break };
1078 val
1079 }),
1080 n => {
1081 if cfg!(any(test, feature = "deny-unknown-attrs")) {
1082 break;
1083 } else {
1084 continue;
1085 }
1086 }
1087 };
1088 return Some(Ok(res));
1089 }
1090 Some(Err(ErrorContext::new(
1091 "NumgenAttrs",
1092 r#type.and_then(|t| NumgenAttrs::attr_from_type(t)),
1093 self.orig_loc,
1094 self.buf.as_ptr().wrapping_add(pos) as usize,
1095 )))
1096 }
1097}
1098impl std::fmt::Debug for IterableNumgenAttrs<'_> {
1099 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1100 let mut fmt = f.debug_struct("NumgenAttrs");
1101 for attr in self.clone() {
1102 let attr = match attr {
1103 Ok(a) => a,
1104 Err(err) => {
1105 fmt.finish()?;
1106 f.write_str("Err(")?;
1107 err.fmt(f)?;
1108 return f.write_str(")");
1109 }
1110 };
1111 match attr {
1112 NumgenAttrs::Dreg(val) => {
1113 fmt.field("Dreg", &FormatEnum(val.into(), Registers::from_value))
1114 }
1115 NumgenAttrs::Modulus(val) => fmt.field("Modulus", &val),
1116 NumgenAttrs::Type(val) => {
1117 fmt.field("Type", &FormatEnum(val.into(), NumgenTypes::from_value))
1118 }
1119 NumgenAttrs::Offset(val) => fmt.field("Offset", &val),
1120 };
1121 }
1122 fmt.finish()
1123 }
1124}
1125impl IterableNumgenAttrs<'_> {
1126 pub fn lookup_attr(
1127 &self,
1128 offset: usize,
1129 missing_type: Option<u16>,
1130 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
1131 let mut stack = Vec::new();
1132 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
1133 if cur == offset {
1134 stack.push(("NumgenAttrs", offset));
1135 return (
1136 stack,
1137 missing_type.and_then(|t| NumgenAttrs::attr_from_type(t)),
1138 );
1139 }
1140 if cur > offset || cur + self.buf.len() < offset {
1141 return (stack, None);
1142 }
1143 let mut attrs = self.clone();
1144 let mut last_off = cur + attrs.pos;
1145 while let Some(attr) = attrs.next() {
1146 let Ok(attr) = attr else { break };
1147 match attr {
1148 NumgenAttrs::Dreg(val) => {
1149 if last_off == offset {
1150 stack.push(("Dreg", last_off));
1151 break;
1152 }
1153 }
1154 NumgenAttrs::Modulus(val) => {
1155 if last_off == offset {
1156 stack.push(("Modulus", last_off));
1157 break;
1158 }
1159 }
1160 NumgenAttrs::Type(val) => {
1161 if last_off == offset {
1162 stack.push(("Type", last_off));
1163 break;
1164 }
1165 }
1166 NumgenAttrs::Offset(val) => {
1167 if last_off == offset {
1168 stack.push(("Offset", last_off));
1169 break;
1170 }
1171 }
1172 _ => {}
1173 };
1174 last_off = cur + attrs.pos;
1175 }
1176 if !stack.is_empty() {
1177 stack.push(("NumgenAttrs", cur));
1178 }
1179 (stack, None)
1180 }
1181}
1182#[derive(Clone)]
1183pub enum RangeAttrs<'a> {
1184 #[doc = "source register of data to compare\nAssociated type: \"Registers\" (enum)"]
1185 Sreg(u32),
1186 #[doc = "cmp operation\nAssociated type: \"RangeOps\" (enum)"]
1187 Op(u32),
1188 #[doc = "data range from"]
1189 FromData(IterableDataAttrs<'a>),
1190 #[doc = "data range to"]
1191 ToData(IterableDataAttrs<'a>),
1192}
1193impl<'a> IterableRangeAttrs<'a> {
1194 #[doc = "source register of data to compare\nAssociated type: \"Registers\" (enum)"]
1195 pub fn get_sreg(&self) -> Result<u32, ErrorContext> {
1196 let mut iter = self.clone();
1197 iter.pos = 0;
1198 for attr in iter {
1199 if let RangeAttrs::Sreg(val) = attr? {
1200 return Ok(val);
1201 }
1202 }
1203 Err(ErrorContext::new_missing(
1204 "RangeAttrs",
1205 "Sreg",
1206 self.orig_loc,
1207 self.buf.as_ptr() as usize,
1208 ))
1209 }
1210 #[doc = "cmp operation\nAssociated type: \"RangeOps\" (enum)"]
1211 pub fn get_op(&self) -> Result<u32, ErrorContext> {
1212 let mut iter = self.clone();
1213 iter.pos = 0;
1214 for attr in iter {
1215 if let RangeAttrs::Op(val) = attr? {
1216 return Ok(val);
1217 }
1218 }
1219 Err(ErrorContext::new_missing(
1220 "RangeAttrs",
1221 "Op",
1222 self.orig_loc,
1223 self.buf.as_ptr() as usize,
1224 ))
1225 }
1226 #[doc = "data range from"]
1227 pub fn get_from_data(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
1228 let mut iter = self.clone();
1229 iter.pos = 0;
1230 for attr in iter {
1231 if let RangeAttrs::FromData(val) = attr? {
1232 return Ok(val);
1233 }
1234 }
1235 Err(ErrorContext::new_missing(
1236 "RangeAttrs",
1237 "FromData",
1238 self.orig_loc,
1239 self.buf.as_ptr() as usize,
1240 ))
1241 }
1242 #[doc = "data range to"]
1243 pub fn get_to_data(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
1244 let mut iter = self.clone();
1245 iter.pos = 0;
1246 for attr in iter {
1247 if let RangeAttrs::ToData(val) = attr? {
1248 return Ok(val);
1249 }
1250 }
1251 Err(ErrorContext::new_missing(
1252 "RangeAttrs",
1253 "ToData",
1254 self.orig_loc,
1255 self.buf.as_ptr() as usize,
1256 ))
1257 }
1258}
1259impl<'a> RangeAttrs<'a> {
1260 pub fn new(buf: &'a [u8]) -> IterableRangeAttrs<'a> {
1261 IterableRangeAttrs::with_loc(buf, buf.as_ptr() as usize)
1262 }
1263 fn attr_from_type(r#type: u16) -> Option<&'static str> {
1264 let res = match r#type {
1265 1u16 => "Sreg",
1266 2u16 => "Op",
1267 3u16 => "FromData",
1268 4u16 => "ToData",
1269 _ => return None,
1270 };
1271 Some(res)
1272 }
1273}
1274#[derive(Clone, Copy, Default)]
1275pub struct IterableRangeAttrs<'a> {
1276 buf: &'a [u8],
1277 pos: usize,
1278 orig_loc: usize,
1279}
1280impl<'a> IterableRangeAttrs<'a> {
1281 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1282 Self {
1283 buf,
1284 pos: 0,
1285 orig_loc,
1286 }
1287 }
1288 pub fn get_buf(&self) -> &'a [u8] {
1289 self.buf
1290 }
1291}
1292impl<'a> Iterator for IterableRangeAttrs<'a> {
1293 type Item = Result<RangeAttrs<'a>, ErrorContext>;
1294 fn next(&mut self) -> Option<Self::Item> {
1295 if self.buf.len() == self.pos {
1296 return None;
1297 }
1298 let pos = self.pos;
1299 let mut r#type = None;
1300 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
1301 r#type = Some(header.r#type);
1302 let res = match header.r#type {
1303 1u16 => RangeAttrs::Sreg({
1304 let res = parse_be_u32(next);
1305 let Some(val) = res else { break };
1306 val
1307 }),
1308 2u16 => RangeAttrs::Op({
1309 let res = parse_be_u32(next);
1310 let Some(val) = res else { break };
1311 val
1312 }),
1313 3u16 => RangeAttrs::FromData({
1314 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
1315 let Some(val) = res else { break };
1316 val
1317 }),
1318 4u16 => RangeAttrs::ToData({
1319 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
1320 let Some(val) = res else { break };
1321 val
1322 }),
1323 n => {
1324 if cfg!(any(test, feature = "deny-unknown-attrs")) {
1325 break;
1326 } else {
1327 continue;
1328 }
1329 }
1330 };
1331 return Some(Ok(res));
1332 }
1333 Some(Err(ErrorContext::new(
1334 "RangeAttrs",
1335 r#type.and_then(|t| RangeAttrs::attr_from_type(t)),
1336 self.orig_loc,
1337 self.buf.as_ptr().wrapping_add(pos) as usize,
1338 )))
1339 }
1340}
1341impl<'a> std::fmt::Debug for IterableRangeAttrs<'_> {
1342 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1343 let mut fmt = f.debug_struct("RangeAttrs");
1344 for attr in self.clone() {
1345 let attr = match attr {
1346 Ok(a) => a,
1347 Err(err) => {
1348 fmt.finish()?;
1349 f.write_str("Err(")?;
1350 err.fmt(f)?;
1351 return f.write_str(")");
1352 }
1353 };
1354 match attr {
1355 RangeAttrs::Sreg(val) => {
1356 fmt.field("Sreg", &FormatEnum(val.into(), Registers::from_value))
1357 }
1358 RangeAttrs::Op(val) => {
1359 fmt.field("Op", &FormatEnum(val.into(), RangeOps::from_value))
1360 }
1361 RangeAttrs::FromData(val) => fmt.field("FromData", &val),
1362 RangeAttrs::ToData(val) => fmt.field("ToData", &val),
1363 };
1364 }
1365 fmt.finish()
1366 }
1367}
1368impl IterableRangeAttrs<'_> {
1369 pub fn lookup_attr(
1370 &self,
1371 offset: usize,
1372 missing_type: Option<u16>,
1373 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
1374 let mut stack = Vec::new();
1375 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
1376 if cur == offset {
1377 stack.push(("RangeAttrs", offset));
1378 return (
1379 stack,
1380 missing_type.and_then(|t| RangeAttrs::attr_from_type(t)),
1381 );
1382 }
1383 if cur > offset || cur + self.buf.len() < offset {
1384 return (stack, None);
1385 }
1386 let mut attrs = self.clone();
1387 let mut last_off = cur + attrs.pos;
1388 let mut missing = None;
1389 while let Some(attr) = attrs.next() {
1390 let Ok(attr) = attr else { break };
1391 match attr {
1392 RangeAttrs::Sreg(val) => {
1393 if last_off == offset {
1394 stack.push(("Sreg", last_off));
1395 break;
1396 }
1397 }
1398 RangeAttrs::Op(val) => {
1399 if last_off == offset {
1400 stack.push(("Op", last_off));
1401 break;
1402 }
1403 }
1404 RangeAttrs::FromData(val) => {
1405 (stack, missing) = val.lookup_attr(offset, missing_type);
1406 if !stack.is_empty() {
1407 break;
1408 }
1409 }
1410 RangeAttrs::ToData(val) => {
1411 (stack, missing) = val.lookup_attr(offset, missing_type);
1412 if !stack.is_empty() {
1413 break;
1414 }
1415 }
1416 _ => {}
1417 };
1418 last_off = cur + attrs.pos;
1419 }
1420 if !stack.is_empty() {
1421 stack.push(("RangeAttrs", cur));
1422 }
1423 (stack, missing)
1424 }
1425}
1426#[derive(Clone)]
1427pub enum BatchAttrs {
1428 #[doc = "generation ID for this changeset"]
1429 Genid(u32),
1430}
1431impl<'a> IterableBatchAttrs<'a> {
1432 #[doc = "generation ID for this changeset"]
1433 pub fn get_genid(&self) -> Result<u32, ErrorContext> {
1434 let mut iter = self.clone();
1435 iter.pos = 0;
1436 for attr in iter {
1437 if let BatchAttrs::Genid(val) = attr? {
1438 return Ok(val);
1439 }
1440 }
1441 Err(ErrorContext::new_missing(
1442 "BatchAttrs",
1443 "Genid",
1444 self.orig_loc,
1445 self.buf.as_ptr() as usize,
1446 ))
1447 }
1448}
1449impl BatchAttrs {
1450 pub fn new(buf: &'_ [u8]) -> IterableBatchAttrs<'_> {
1451 IterableBatchAttrs::with_loc(buf, buf.as_ptr() as usize)
1452 }
1453 fn attr_from_type(r#type: u16) -> Option<&'static str> {
1454 let res = match r#type {
1455 1u16 => "Genid",
1456 _ => return None,
1457 };
1458 Some(res)
1459 }
1460}
1461#[derive(Clone, Copy, Default)]
1462pub struct IterableBatchAttrs<'a> {
1463 buf: &'a [u8],
1464 pos: usize,
1465 orig_loc: usize,
1466}
1467impl<'a> IterableBatchAttrs<'a> {
1468 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1469 Self {
1470 buf,
1471 pos: 0,
1472 orig_loc,
1473 }
1474 }
1475 pub fn get_buf(&self) -> &'a [u8] {
1476 self.buf
1477 }
1478}
1479impl<'a> Iterator for IterableBatchAttrs<'a> {
1480 type Item = Result<BatchAttrs, ErrorContext>;
1481 fn next(&mut self) -> Option<Self::Item> {
1482 if self.buf.len() == self.pos {
1483 return None;
1484 }
1485 let pos = self.pos;
1486 let mut r#type = None;
1487 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
1488 r#type = Some(header.r#type);
1489 let res = match header.r#type {
1490 1u16 => BatchAttrs::Genid({
1491 let res = parse_be_u32(next);
1492 let Some(val) = res else { break };
1493 val
1494 }),
1495 n => {
1496 if cfg!(any(test, feature = "deny-unknown-attrs")) {
1497 break;
1498 } else {
1499 continue;
1500 }
1501 }
1502 };
1503 return Some(Ok(res));
1504 }
1505 Some(Err(ErrorContext::new(
1506 "BatchAttrs",
1507 r#type.and_then(|t| BatchAttrs::attr_from_type(t)),
1508 self.orig_loc,
1509 self.buf.as_ptr().wrapping_add(pos) as usize,
1510 )))
1511 }
1512}
1513impl std::fmt::Debug for IterableBatchAttrs<'_> {
1514 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1515 let mut fmt = f.debug_struct("BatchAttrs");
1516 for attr in self.clone() {
1517 let attr = match attr {
1518 Ok(a) => a,
1519 Err(err) => {
1520 fmt.finish()?;
1521 f.write_str("Err(")?;
1522 err.fmt(f)?;
1523 return f.write_str(")");
1524 }
1525 };
1526 match attr {
1527 BatchAttrs::Genid(val) => fmt.field("Genid", &val),
1528 };
1529 }
1530 fmt.finish()
1531 }
1532}
1533impl IterableBatchAttrs<'_> {
1534 pub fn lookup_attr(
1535 &self,
1536 offset: usize,
1537 missing_type: Option<u16>,
1538 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
1539 let mut stack = Vec::new();
1540 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
1541 if cur == offset {
1542 stack.push(("BatchAttrs", offset));
1543 return (
1544 stack,
1545 missing_type.and_then(|t| BatchAttrs::attr_from_type(t)),
1546 );
1547 }
1548 if cur > offset || cur + self.buf.len() < offset {
1549 return (stack, None);
1550 }
1551 let mut attrs = self.clone();
1552 let mut last_off = cur + attrs.pos;
1553 while let Some(attr) = attrs.next() {
1554 let Ok(attr) = attr else { break };
1555 match attr {
1556 BatchAttrs::Genid(val) => {
1557 if last_off == offset {
1558 stack.push(("Genid", last_off));
1559 break;
1560 }
1561 }
1562 _ => {}
1563 };
1564 last_off = cur + attrs.pos;
1565 }
1566 if !stack.is_empty() {
1567 stack.push(("BatchAttrs", cur));
1568 }
1569 (stack, None)
1570 }
1571}
1572#[derive(Clone)]
1573pub enum TableAttrs<'a> {
1574 #[doc = "name of the table"]
1575 Name(&'a CStr),
1576 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
1577 Flags(u32),
1578 #[doc = "number of chains in this table"]
1579 Use(u32),
1580 #[doc = "numeric handle of the table"]
1581 Handle(u64),
1582 Pad(&'a [u8]),
1583 #[doc = "user data"]
1584 Userdata(&'a [u8]),
1585 #[doc = "owner of this table through netlink portID"]
1586 Owner(u32),
1587}
1588impl<'a> IterableTableAttrs<'a> {
1589 #[doc = "name of the table"]
1590 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
1591 let mut iter = self.clone();
1592 iter.pos = 0;
1593 for attr in iter {
1594 if let TableAttrs::Name(val) = attr? {
1595 return Ok(val);
1596 }
1597 }
1598 Err(ErrorContext::new_missing(
1599 "TableAttrs",
1600 "Name",
1601 self.orig_loc,
1602 self.buf.as_ptr() as usize,
1603 ))
1604 }
1605 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
1606 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
1607 let mut iter = self.clone();
1608 iter.pos = 0;
1609 for attr in iter {
1610 if let TableAttrs::Flags(val) = attr? {
1611 return Ok(val);
1612 }
1613 }
1614 Err(ErrorContext::new_missing(
1615 "TableAttrs",
1616 "Flags",
1617 self.orig_loc,
1618 self.buf.as_ptr() as usize,
1619 ))
1620 }
1621 #[doc = "number of chains in this table"]
1622 pub fn get_use(&self) -> Result<u32, ErrorContext> {
1623 let mut iter = self.clone();
1624 iter.pos = 0;
1625 for attr in iter {
1626 if let TableAttrs::Use(val) = attr? {
1627 return Ok(val);
1628 }
1629 }
1630 Err(ErrorContext::new_missing(
1631 "TableAttrs",
1632 "Use",
1633 self.orig_loc,
1634 self.buf.as_ptr() as usize,
1635 ))
1636 }
1637 #[doc = "numeric handle of the table"]
1638 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
1639 let mut iter = self.clone();
1640 iter.pos = 0;
1641 for attr in iter {
1642 if let TableAttrs::Handle(val) = attr? {
1643 return Ok(val);
1644 }
1645 }
1646 Err(ErrorContext::new_missing(
1647 "TableAttrs",
1648 "Handle",
1649 self.orig_loc,
1650 self.buf.as_ptr() as usize,
1651 ))
1652 }
1653 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
1654 let mut iter = self.clone();
1655 iter.pos = 0;
1656 for attr in iter {
1657 if let TableAttrs::Pad(val) = attr? {
1658 return Ok(val);
1659 }
1660 }
1661 Err(ErrorContext::new_missing(
1662 "TableAttrs",
1663 "Pad",
1664 self.orig_loc,
1665 self.buf.as_ptr() as usize,
1666 ))
1667 }
1668 #[doc = "user data"]
1669 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
1670 let mut iter = self.clone();
1671 iter.pos = 0;
1672 for attr in iter {
1673 if let TableAttrs::Userdata(val) = attr? {
1674 return Ok(val);
1675 }
1676 }
1677 Err(ErrorContext::new_missing(
1678 "TableAttrs",
1679 "Userdata",
1680 self.orig_loc,
1681 self.buf.as_ptr() as usize,
1682 ))
1683 }
1684 #[doc = "owner of this table through netlink portID"]
1685 pub fn get_owner(&self) -> Result<u32, ErrorContext> {
1686 let mut iter = self.clone();
1687 iter.pos = 0;
1688 for attr in iter {
1689 if let TableAttrs::Owner(val) = attr? {
1690 return Ok(val);
1691 }
1692 }
1693 Err(ErrorContext::new_missing(
1694 "TableAttrs",
1695 "Owner",
1696 self.orig_loc,
1697 self.buf.as_ptr() as usize,
1698 ))
1699 }
1700}
1701impl<'a> TableAttrs<'a> {
1702 pub fn new(buf: &'a [u8]) -> IterableTableAttrs<'a> {
1703 IterableTableAttrs::with_loc(buf, buf.as_ptr() as usize)
1704 }
1705 fn attr_from_type(r#type: u16) -> Option<&'static str> {
1706 let res = match r#type {
1707 1u16 => "Name",
1708 2u16 => "Flags",
1709 3u16 => "Use",
1710 4u16 => "Handle",
1711 5u16 => "Pad",
1712 6u16 => "Userdata",
1713 7u16 => "Owner",
1714 _ => return None,
1715 };
1716 Some(res)
1717 }
1718}
1719#[derive(Clone, Copy, Default)]
1720pub struct IterableTableAttrs<'a> {
1721 buf: &'a [u8],
1722 pos: usize,
1723 orig_loc: usize,
1724}
1725impl<'a> IterableTableAttrs<'a> {
1726 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1727 Self {
1728 buf,
1729 pos: 0,
1730 orig_loc,
1731 }
1732 }
1733 pub fn get_buf(&self) -> &'a [u8] {
1734 self.buf
1735 }
1736}
1737impl<'a> Iterator for IterableTableAttrs<'a> {
1738 type Item = Result<TableAttrs<'a>, ErrorContext>;
1739 fn next(&mut self) -> Option<Self::Item> {
1740 if self.buf.len() == self.pos {
1741 return None;
1742 }
1743 let pos = self.pos;
1744 let mut r#type = None;
1745 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
1746 r#type = Some(header.r#type);
1747 let res = match header.r#type {
1748 1u16 => TableAttrs::Name({
1749 let res = CStr::from_bytes_with_nul(next).ok();
1750 let Some(val) = res else { break };
1751 val
1752 }),
1753 2u16 => TableAttrs::Flags({
1754 let res = parse_be_u32(next);
1755 let Some(val) = res else { break };
1756 val
1757 }),
1758 3u16 => TableAttrs::Use({
1759 let res = parse_be_u32(next);
1760 let Some(val) = res else { break };
1761 val
1762 }),
1763 4u16 => TableAttrs::Handle({
1764 let res = parse_be_u64(next);
1765 let Some(val) = res else { break };
1766 val
1767 }),
1768 5u16 => TableAttrs::Pad({
1769 let res = Some(next);
1770 let Some(val) = res else { break };
1771 val
1772 }),
1773 6u16 => TableAttrs::Userdata({
1774 let res = Some(next);
1775 let Some(val) = res else { break };
1776 val
1777 }),
1778 7u16 => TableAttrs::Owner({
1779 let res = parse_be_u32(next);
1780 let Some(val) = res else { break };
1781 val
1782 }),
1783 n => {
1784 if cfg!(any(test, feature = "deny-unknown-attrs")) {
1785 break;
1786 } else {
1787 continue;
1788 }
1789 }
1790 };
1791 return Some(Ok(res));
1792 }
1793 Some(Err(ErrorContext::new(
1794 "TableAttrs",
1795 r#type.and_then(|t| TableAttrs::attr_from_type(t)),
1796 self.orig_loc,
1797 self.buf.as_ptr().wrapping_add(pos) as usize,
1798 )))
1799 }
1800}
1801impl<'a> std::fmt::Debug for IterableTableAttrs<'_> {
1802 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1803 let mut fmt = f.debug_struct("TableAttrs");
1804 for attr in self.clone() {
1805 let attr = match attr {
1806 Ok(a) => a,
1807 Err(err) => {
1808 fmt.finish()?;
1809 f.write_str("Err(")?;
1810 err.fmt(f)?;
1811 return f.write_str(")");
1812 }
1813 };
1814 match attr {
1815 TableAttrs::Name(val) => fmt.field("Name", &val),
1816 TableAttrs::Flags(val) => {
1817 fmt.field("Flags", &FormatFlags(val.into(), TableFlags::from_value))
1818 }
1819 TableAttrs::Use(val) => fmt.field("Use", &val),
1820 TableAttrs::Handle(val) => fmt.field("Handle", &val),
1821 TableAttrs::Pad(val) => fmt.field("Pad", &val),
1822 TableAttrs::Userdata(val) => fmt.field("Userdata", &val),
1823 TableAttrs::Owner(val) => fmt.field("Owner", &val),
1824 };
1825 }
1826 fmt.finish()
1827 }
1828}
1829impl IterableTableAttrs<'_> {
1830 pub fn lookup_attr(
1831 &self,
1832 offset: usize,
1833 missing_type: Option<u16>,
1834 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
1835 let mut stack = Vec::new();
1836 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
1837 if cur == offset {
1838 stack.push(("TableAttrs", offset));
1839 return (
1840 stack,
1841 missing_type.and_then(|t| TableAttrs::attr_from_type(t)),
1842 );
1843 }
1844 if cur > offset || cur + self.buf.len() < offset {
1845 return (stack, None);
1846 }
1847 let mut attrs = self.clone();
1848 let mut last_off = cur + attrs.pos;
1849 while let Some(attr) = attrs.next() {
1850 let Ok(attr) = attr else { break };
1851 match attr {
1852 TableAttrs::Name(val) => {
1853 if last_off == offset {
1854 stack.push(("Name", last_off));
1855 break;
1856 }
1857 }
1858 TableAttrs::Flags(val) => {
1859 if last_off == offset {
1860 stack.push(("Flags", last_off));
1861 break;
1862 }
1863 }
1864 TableAttrs::Use(val) => {
1865 if last_off == offset {
1866 stack.push(("Use", last_off));
1867 break;
1868 }
1869 }
1870 TableAttrs::Handle(val) => {
1871 if last_off == offset {
1872 stack.push(("Handle", last_off));
1873 break;
1874 }
1875 }
1876 TableAttrs::Pad(val) => {
1877 if last_off == offset {
1878 stack.push(("Pad", last_off));
1879 break;
1880 }
1881 }
1882 TableAttrs::Userdata(val) => {
1883 if last_off == offset {
1884 stack.push(("Userdata", last_off));
1885 break;
1886 }
1887 }
1888 TableAttrs::Owner(val) => {
1889 if last_off == offset {
1890 stack.push(("Owner", last_off));
1891 break;
1892 }
1893 }
1894 _ => {}
1895 };
1896 last_off = cur + attrs.pos;
1897 }
1898 if !stack.is_empty() {
1899 stack.push(("TableAttrs", cur));
1900 }
1901 (stack, None)
1902 }
1903}
1904#[derive(Clone)]
1905pub enum ChainAttrs<'a> {
1906 #[doc = "name of the table containing the chain"]
1907 Table(&'a CStr),
1908 #[doc = "numeric handle of the chain"]
1909 Handle(u64),
1910 #[doc = "name of the chain"]
1911 Name(&'a CStr),
1912 #[doc = "hook specification for basechains"]
1913 Hook(IterableNftHookAttrs<'a>),
1914 #[doc = "numeric policy of the chain"]
1915 Policy(u32),
1916 #[doc = "number of references to this chain"]
1917 Use(u32),
1918 #[doc = "type name of the chain"]
1919 Type(&'a CStr),
1920 #[doc = "counter specification of the chain"]
1921 Counters(IterableNftCounterAttrs<'a>),
1922 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
1923 Flags(u32),
1924 #[doc = "uniquely identifies a chain in a transaction"]
1925 Id(u32),
1926 #[doc = "user data"]
1927 Userdata(&'a [u8]),
1928}
1929impl<'a> IterableChainAttrs<'a> {
1930 #[doc = "name of the table containing the chain"]
1931 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
1932 let mut iter = self.clone();
1933 iter.pos = 0;
1934 for attr in iter {
1935 if let ChainAttrs::Table(val) = attr? {
1936 return Ok(val);
1937 }
1938 }
1939 Err(ErrorContext::new_missing(
1940 "ChainAttrs",
1941 "Table",
1942 self.orig_loc,
1943 self.buf.as_ptr() as usize,
1944 ))
1945 }
1946 #[doc = "numeric handle of the chain"]
1947 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
1948 let mut iter = self.clone();
1949 iter.pos = 0;
1950 for attr in iter {
1951 if let ChainAttrs::Handle(val) = attr? {
1952 return Ok(val);
1953 }
1954 }
1955 Err(ErrorContext::new_missing(
1956 "ChainAttrs",
1957 "Handle",
1958 self.orig_loc,
1959 self.buf.as_ptr() as usize,
1960 ))
1961 }
1962 #[doc = "name of the chain"]
1963 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
1964 let mut iter = self.clone();
1965 iter.pos = 0;
1966 for attr in iter {
1967 if let ChainAttrs::Name(val) = attr? {
1968 return Ok(val);
1969 }
1970 }
1971 Err(ErrorContext::new_missing(
1972 "ChainAttrs",
1973 "Name",
1974 self.orig_loc,
1975 self.buf.as_ptr() as usize,
1976 ))
1977 }
1978 #[doc = "hook specification for basechains"]
1979 pub fn get_hook(&self) -> Result<IterableNftHookAttrs<'a>, ErrorContext> {
1980 let mut iter = self.clone();
1981 iter.pos = 0;
1982 for attr in iter {
1983 if let ChainAttrs::Hook(val) = attr? {
1984 return Ok(val);
1985 }
1986 }
1987 Err(ErrorContext::new_missing(
1988 "ChainAttrs",
1989 "Hook",
1990 self.orig_loc,
1991 self.buf.as_ptr() as usize,
1992 ))
1993 }
1994 #[doc = "numeric policy of the chain"]
1995 pub fn get_policy(&self) -> Result<u32, ErrorContext> {
1996 let mut iter = self.clone();
1997 iter.pos = 0;
1998 for attr in iter {
1999 if let ChainAttrs::Policy(val) = attr? {
2000 return Ok(val);
2001 }
2002 }
2003 Err(ErrorContext::new_missing(
2004 "ChainAttrs",
2005 "Policy",
2006 self.orig_loc,
2007 self.buf.as_ptr() as usize,
2008 ))
2009 }
2010 #[doc = "number of references to this chain"]
2011 pub fn get_use(&self) -> Result<u32, ErrorContext> {
2012 let mut iter = self.clone();
2013 iter.pos = 0;
2014 for attr in iter {
2015 if let ChainAttrs::Use(val) = attr? {
2016 return Ok(val);
2017 }
2018 }
2019 Err(ErrorContext::new_missing(
2020 "ChainAttrs",
2021 "Use",
2022 self.orig_loc,
2023 self.buf.as_ptr() as usize,
2024 ))
2025 }
2026 #[doc = "type name of the chain"]
2027 pub fn get_type(&self) -> Result<&'a CStr, ErrorContext> {
2028 let mut iter = self.clone();
2029 iter.pos = 0;
2030 for attr in iter {
2031 if let ChainAttrs::Type(val) = attr? {
2032 return Ok(val);
2033 }
2034 }
2035 Err(ErrorContext::new_missing(
2036 "ChainAttrs",
2037 "Type",
2038 self.orig_loc,
2039 self.buf.as_ptr() as usize,
2040 ))
2041 }
2042 #[doc = "counter specification of the chain"]
2043 pub fn get_counters(&self) -> Result<IterableNftCounterAttrs<'a>, ErrorContext> {
2044 let mut iter = self.clone();
2045 iter.pos = 0;
2046 for attr in iter {
2047 if let ChainAttrs::Counters(val) = attr? {
2048 return Ok(val);
2049 }
2050 }
2051 Err(ErrorContext::new_missing(
2052 "ChainAttrs",
2053 "Counters",
2054 self.orig_loc,
2055 self.buf.as_ptr() as usize,
2056 ))
2057 }
2058 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
2059 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
2060 let mut iter = self.clone();
2061 iter.pos = 0;
2062 for attr in iter {
2063 if let ChainAttrs::Flags(val) = attr? {
2064 return Ok(val);
2065 }
2066 }
2067 Err(ErrorContext::new_missing(
2068 "ChainAttrs",
2069 "Flags",
2070 self.orig_loc,
2071 self.buf.as_ptr() as usize,
2072 ))
2073 }
2074 #[doc = "uniquely identifies a chain in a transaction"]
2075 pub fn get_id(&self) -> Result<u32, ErrorContext> {
2076 let mut iter = self.clone();
2077 iter.pos = 0;
2078 for attr in iter {
2079 if let ChainAttrs::Id(val) = attr? {
2080 return Ok(val);
2081 }
2082 }
2083 Err(ErrorContext::new_missing(
2084 "ChainAttrs",
2085 "Id",
2086 self.orig_loc,
2087 self.buf.as_ptr() as usize,
2088 ))
2089 }
2090 #[doc = "user data"]
2091 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
2092 let mut iter = self.clone();
2093 iter.pos = 0;
2094 for attr in iter {
2095 if let ChainAttrs::Userdata(val) = attr? {
2096 return Ok(val);
2097 }
2098 }
2099 Err(ErrorContext::new_missing(
2100 "ChainAttrs",
2101 "Userdata",
2102 self.orig_loc,
2103 self.buf.as_ptr() as usize,
2104 ))
2105 }
2106}
2107impl<'a> ChainAttrs<'a> {
2108 pub fn new(buf: &'a [u8]) -> IterableChainAttrs<'a> {
2109 IterableChainAttrs::with_loc(buf, buf.as_ptr() as usize)
2110 }
2111 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2112 let res = match r#type {
2113 1u16 => "Table",
2114 2u16 => "Handle",
2115 3u16 => "Name",
2116 4u16 => "Hook",
2117 5u16 => "Policy",
2118 6u16 => "Use",
2119 7u16 => "Type",
2120 8u16 => "Counters",
2121 9u16 => "Flags",
2122 10u16 => "Id",
2123 11u16 => "Userdata",
2124 _ => return None,
2125 };
2126 Some(res)
2127 }
2128}
2129#[derive(Clone, Copy, Default)]
2130pub struct IterableChainAttrs<'a> {
2131 buf: &'a [u8],
2132 pos: usize,
2133 orig_loc: usize,
2134}
2135impl<'a> IterableChainAttrs<'a> {
2136 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2137 Self {
2138 buf,
2139 pos: 0,
2140 orig_loc,
2141 }
2142 }
2143 pub fn get_buf(&self) -> &'a [u8] {
2144 self.buf
2145 }
2146}
2147impl<'a> Iterator for IterableChainAttrs<'a> {
2148 type Item = Result<ChainAttrs<'a>, ErrorContext>;
2149 fn next(&mut self) -> Option<Self::Item> {
2150 if self.buf.len() == self.pos {
2151 return None;
2152 }
2153 let pos = self.pos;
2154 let mut r#type = None;
2155 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
2156 r#type = Some(header.r#type);
2157 let res = match header.r#type {
2158 1u16 => ChainAttrs::Table({
2159 let res = CStr::from_bytes_with_nul(next).ok();
2160 let Some(val) = res else { break };
2161 val
2162 }),
2163 2u16 => ChainAttrs::Handle({
2164 let res = parse_be_u64(next);
2165 let Some(val) = res else { break };
2166 val
2167 }),
2168 3u16 => ChainAttrs::Name({
2169 let res = CStr::from_bytes_with_nul(next).ok();
2170 let Some(val) = res else { break };
2171 val
2172 }),
2173 4u16 => ChainAttrs::Hook({
2174 let res = Some(IterableNftHookAttrs::with_loc(next, self.orig_loc));
2175 let Some(val) = res else { break };
2176 val
2177 }),
2178 5u16 => ChainAttrs::Policy({
2179 let res = parse_be_u32(next);
2180 let Some(val) = res else { break };
2181 val
2182 }),
2183 6u16 => ChainAttrs::Use({
2184 let res = parse_be_u32(next);
2185 let Some(val) = res else { break };
2186 val
2187 }),
2188 7u16 => ChainAttrs::Type({
2189 let res = CStr::from_bytes_with_nul(next).ok();
2190 let Some(val) = res else { break };
2191 val
2192 }),
2193 8u16 => ChainAttrs::Counters({
2194 let res = Some(IterableNftCounterAttrs::with_loc(next, self.orig_loc));
2195 let Some(val) = res else { break };
2196 val
2197 }),
2198 9u16 => ChainAttrs::Flags({
2199 let res = parse_be_u32(next);
2200 let Some(val) = res else { break };
2201 val
2202 }),
2203 10u16 => ChainAttrs::Id({
2204 let res = parse_be_u32(next);
2205 let Some(val) = res else { break };
2206 val
2207 }),
2208 11u16 => ChainAttrs::Userdata({
2209 let res = Some(next);
2210 let Some(val) = res else { break };
2211 val
2212 }),
2213 n => {
2214 if cfg!(any(test, feature = "deny-unknown-attrs")) {
2215 break;
2216 } else {
2217 continue;
2218 }
2219 }
2220 };
2221 return Some(Ok(res));
2222 }
2223 Some(Err(ErrorContext::new(
2224 "ChainAttrs",
2225 r#type.and_then(|t| ChainAttrs::attr_from_type(t)),
2226 self.orig_loc,
2227 self.buf.as_ptr().wrapping_add(pos) as usize,
2228 )))
2229 }
2230}
2231impl<'a> std::fmt::Debug for IterableChainAttrs<'_> {
2232 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2233 let mut fmt = f.debug_struct("ChainAttrs");
2234 for attr in self.clone() {
2235 let attr = match attr {
2236 Ok(a) => a,
2237 Err(err) => {
2238 fmt.finish()?;
2239 f.write_str("Err(")?;
2240 err.fmt(f)?;
2241 return f.write_str(")");
2242 }
2243 };
2244 match attr {
2245 ChainAttrs::Table(val) => fmt.field("Table", &val),
2246 ChainAttrs::Handle(val) => fmt.field("Handle", &val),
2247 ChainAttrs::Name(val) => fmt.field("Name", &val),
2248 ChainAttrs::Hook(val) => fmt.field("Hook", &val),
2249 ChainAttrs::Policy(val) => fmt.field("Policy", &val),
2250 ChainAttrs::Use(val) => fmt.field("Use", &val),
2251 ChainAttrs::Type(val) => fmt.field("Type", &val),
2252 ChainAttrs::Counters(val) => fmt.field("Counters", &val),
2253 ChainAttrs::Flags(val) => {
2254 fmt.field("Flags", &FormatFlags(val.into(), ChainFlags::from_value))
2255 }
2256 ChainAttrs::Id(val) => fmt.field("Id", &val),
2257 ChainAttrs::Userdata(val) => fmt.field("Userdata", &val),
2258 };
2259 }
2260 fmt.finish()
2261 }
2262}
2263impl IterableChainAttrs<'_> {
2264 pub fn lookup_attr(
2265 &self,
2266 offset: usize,
2267 missing_type: Option<u16>,
2268 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2269 let mut stack = Vec::new();
2270 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2271 if cur == offset {
2272 stack.push(("ChainAttrs", offset));
2273 return (
2274 stack,
2275 missing_type.and_then(|t| ChainAttrs::attr_from_type(t)),
2276 );
2277 }
2278 if cur > offset || cur + self.buf.len() < offset {
2279 return (stack, None);
2280 }
2281 let mut attrs = self.clone();
2282 let mut last_off = cur + attrs.pos;
2283 let mut missing = None;
2284 while let Some(attr) = attrs.next() {
2285 let Ok(attr) = attr else { break };
2286 match attr {
2287 ChainAttrs::Table(val) => {
2288 if last_off == offset {
2289 stack.push(("Table", last_off));
2290 break;
2291 }
2292 }
2293 ChainAttrs::Handle(val) => {
2294 if last_off == offset {
2295 stack.push(("Handle", last_off));
2296 break;
2297 }
2298 }
2299 ChainAttrs::Name(val) => {
2300 if last_off == offset {
2301 stack.push(("Name", last_off));
2302 break;
2303 }
2304 }
2305 ChainAttrs::Hook(val) => {
2306 (stack, missing) = val.lookup_attr(offset, missing_type);
2307 if !stack.is_empty() {
2308 break;
2309 }
2310 }
2311 ChainAttrs::Policy(val) => {
2312 if last_off == offset {
2313 stack.push(("Policy", last_off));
2314 break;
2315 }
2316 }
2317 ChainAttrs::Use(val) => {
2318 if last_off == offset {
2319 stack.push(("Use", last_off));
2320 break;
2321 }
2322 }
2323 ChainAttrs::Type(val) => {
2324 if last_off == offset {
2325 stack.push(("Type", last_off));
2326 break;
2327 }
2328 }
2329 ChainAttrs::Counters(val) => {
2330 (stack, missing) = val.lookup_attr(offset, missing_type);
2331 if !stack.is_empty() {
2332 break;
2333 }
2334 }
2335 ChainAttrs::Flags(val) => {
2336 if last_off == offset {
2337 stack.push(("Flags", last_off));
2338 break;
2339 }
2340 }
2341 ChainAttrs::Id(val) => {
2342 if last_off == offset {
2343 stack.push(("Id", last_off));
2344 break;
2345 }
2346 }
2347 ChainAttrs::Userdata(val) => {
2348 if last_off == offset {
2349 stack.push(("Userdata", last_off));
2350 break;
2351 }
2352 }
2353 _ => {}
2354 };
2355 last_off = cur + attrs.pos;
2356 }
2357 if !stack.is_empty() {
2358 stack.push(("ChainAttrs", cur));
2359 }
2360 (stack, missing)
2361 }
2362}
2363#[derive(Clone)]
2364pub enum CounterAttrs<'a> {
2365 Bytes(u64),
2366 Packets(u64),
2367 Pad(&'a [u8]),
2368}
2369impl<'a> IterableCounterAttrs<'a> {
2370 pub fn get_bytes(&self) -> Result<u64, ErrorContext> {
2371 let mut iter = self.clone();
2372 iter.pos = 0;
2373 for attr in iter {
2374 if let CounterAttrs::Bytes(val) = attr? {
2375 return Ok(val);
2376 }
2377 }
2378 Err(ErrorContext::new_missing(
2379 "CounterAttrs",
2380 "Bytes",
2381 self.orig_loc,
2382 self.buf.as_ptr() as usize,
2383 ))
2384 }
2385 pub fn get_packets(&self) -> Result<u64, ErrorContext> {
2386 let mut iter = self.clone();
2387 iter.pos = 0;
2388 for attr in iter {
2389 if let CounterAttrs::Packets(val) = attr? {
2390 return Ok(val);
2391 }
2392 }
2393 Err(ErrorContext::new_missing(
2394 "CounterAttrs",
2395 "Packets",
2396 self.orig_loc,
2397 self.buf.as_ptr() as usize,
2398 ))
2399 }
2400 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
2401 let mut iter = self.clone();
2402 iter.pos = 0;
2403 for attr in iter {
2404 if let CounterAttrs::Pad(val) = attr? {
2405 return Ok(val);
2406 }
2407 }
2408 Err(ErrorContext::new_missing(
2409 "CounterAttrs",
2410 "Pad",
2411 self.orig_loc,
2412 self.buf.as_ptr() as usize,
2413 ))
2414 }
2415}
2416impl<'a> CounterAttrs<'a> {
2417 pub fn new(buf: &'a [u8]) -> IterableCounterAttrs<'a> {
2418 IterableCounterAttrs::with_loc(buf, buf.as_ptr() as usize)
2419 }
2420 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2421 let res = match r#type {
2422 1u16 => "Bytes",
2423 2u16 => "Packets",
2424 3u16 => "Pad",
2425 _ => return None,
2426 };
2427 Some(res)
2428 }
2429}
2430#[derive(Clone, Copy, Default)]
2431pub struct IterableCounterAttrs<'a> {
2432 buf: &'a [u8],
2433 pos: usize,
2434 orig_loc: usize,
2435}
2436impl<'a> IterableCounterAttrs<'a> {
2437 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2438 Self {
2439 buf,
2440 pos: 0,
2441 orig_loc,
2442 }
2443 }
2444 pub fn get_buf(&self) -> &'a [u8] {
2445 self.buf
2446 }
2447}
2448impl<'a> Iterator for IterableCounterAttrs<'a> {
2449 type Item = Result<CounterAttrs<'a>, ErrorContext>;
2450 fn next(&mut self) -> Option<Self::Item> {
2451 if self.buf.len() == self.pos {
2452 return None;
2453 }
2454 let pos = self.pos;
2455 let mut r#type = None;
2456 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
2457 r#type = Some(header.r#type);
2458 let res = match header.r#type {
2459 1u16 => CounterAttrs::Bytes({
2460 let res = parse_be_u64(next);
2461 let Some(val) = res else { break };
2462 val
2463 }),
2464 2u16 => CounterAttrs::Packets({
2465 let res = parse_be_u64(next);
2466 let Some(val) = res else { break };
2467 val
2468 }),
2469 3u16 => CounterAttrs::Pad({
2470 let res = Some(next);
2471 let Some(val) = res else { break };
2472 val
2473 }),
2474 n => {
2475 if cfg!(any(test, feature = "deny-unknown-attrs")) {
2476 break;
2477 } else {
2478 continue;
2479 }
2480 }
2481 };
2482 return Some(Ok(res));
2483 }
2484 Some(Err(ErrorContext::new(
2485 "CounterAttrs",
2486 r#type.and_then(|t| CounterAttrs::attr_from_type(t)),
2487 self.orig_loc,
2488 self.buf.as_ptr().wrapping_add(pos) as usize,
2489 )))
2490 }
2491}
2492impl<'a> std::fmt::Debug for IterableCounterAttrs<'_> {
2493 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2494 let mut fmt = f.debug_struct("CounterAttrs");
2495 for attr in self.clone() {
2496 let attr = match attr {
2497 Ok(a) => a,
2498 Err(err) => {
2499 fmt.finish()?;
2500 f.write_str("Err(")?;
2501 err.fmt(f)?;
2502 return f.write_str(")");
2503 }
2504 };
2505 match attr {
2506 CounterAttrs::Bytes(val) => fmt.field("Bytes", &val),
2507 CounterAttrs::Packets(val) => fmt.field("Packets", &val),
2508 CounterAttrs::Pad(val) => fmt.field("Pad", &val),
2509 };
2510 }
2511 fmt.finish()
2512 }
2513}
2514impl IterableCounterAttrs<'_> {
2515 pub fn lookup_attr(
2516 &self,
2517 offset: usize,
2518 missing_type: Option<u16>,
2519 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2520 let mut stack = Vec::new();
2521 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2522 if cur == offset {
2523 stack.push(("CounterAttrs", offset));
2524 return (
2525 stack,
2526 missing_type.and_then(|t| CounterAttrs::attr_from_type(t)),
2527 );
2528 }
2529 if cur > offset || cur + self.buf.len() < offset {
2530 return (stack, None);
2531 }
2532 let mut attrs = self.clone();
2533 let mut last_off = cur + attrs.pos;
2534 while let Some(attr) = attrs.next() {
2535 let Ok(attr) = attr else { break };
2536 match attr {
2537 CounterAttrs::Bytes(val) => {
2538 if last_off == offset {
2539 stack.push(("Bytes", last_off));
2540 break;
2541 }
2542 }
2543 CounterAttrs::Packets(val) => {
2544 if last_off == offset {
2545 stack.push(("Packets", last_off));
2546 break;
2547 }
2548 }
2549 CounterAttrs::Pad(val) => {
2550 if last_off == offset {
2551 stack.push(("Pad", last_off));
2552 break;
2553 }
2554 }
2555 _ => {}
2556 };
2557 last_off = cur + attrs.pos;
2558 }
2559 if !stack.is_empty() {
2560 stack.push(("CounterAttrs", cur));
2561 }
2562 (stack, None)
2563 }
2564}
2565#[derive(Clone)]
2566pub enum NftHookAttrs<'a> {
2567 Num(u32),
2568 Priority(i32),
2569 #[doc = "net device name"]
2570 Dev(&'a CStr),
2571 #[doc = "list of net devices"]
2572 Devs(IterableHookDevAttrs<'a>),
2573}
2574impl<'a> IterableNftHookAttrs<'a> {
2575 pub fn get_num(&self) -> Result<u32, ErrorContext> {
2576 let mut iter = self.clone();
2577 iter.pos = 0;
2578 for attr in iter {
2579 if let NftHookAttrs::Num(val) = attr? {
2580 return Ok(val);
2581 }
2582 }
2583 Err(ErrorContext::new_missing(
2584 "NftHookAttrs",
2585 "Num",
2586 self.orig_loc,
2587 self.buf.as_ptr() as usize,
2588 ))
2589 }
2590 pub fn get_priority(&self) -> Result<i32, ErrorContext> {
2591 let mut iter = self.clone();
2592 iter.pos = 0;
2593 for attr in iter {
2594 if let NftHookAttrs::Priority(val) = attr? {
2595 return Ok(val);
2596 }
2597 }
2598 Err(ErrorContext::new_missing(
2599 "NftHookAttrs",
2600 "Priority",
2601 self.orig_loc,
2602 self.buf.as_ptr() as usize,
2603 ))
2604 }
2605 #[doc = "net device name"]
2606 pub fn get_dev(&self) -> Result<&'a CStr, ErrorContext> {
2607 let mut iter = self.clone();
2608 iter.pos = 0;
2609 for attr in iter {
2610 if let NftHookAttrs::Dev(val) = attr? {
2611 return Ok(val);
2612 }
2613 }
2614 Err(ErrorContext::new_missing(
2615 "NftHookAttrs",
2616 "Dev",
2617 self.orig_loc,
2618 self.buf.as_ptr() as usize,
2619 ))
2620 }
2621 #[doc = "list of net devices"]
2622 pub fn get_devs(&self) -> Result<IterableHookDevAttrs<'a>, ErrorContext> {
2623 let mut iter = self.clone();
2624 iter.pos = 0;
2625 for attr in iter {
2626 if let NftHookAttrs::Devs(val) = attr? {
2627 return Ok(val);
2628 }
2629 }
2630 Err(ErrorContext::new_missing(
2631 "NftHookAttrs",
2632 "Devs",
2633 self.orig_loc,
2634 self.buf.as_ptr() as usize,
2635 ))
2636 }
2637}
2638impl<'a> NftHookAttrs<'a> {
2639 pub fn new(buf: &'a [u8]) -> IterableNftHookAttrs<'a> {
2640 IterableNftHookAttrs::with_loc(buf, buf.as_ptr() as usize)
2641 }
2642 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2643 let res = match r#type {
2644 1u16 => "Num",
2645 2u16 => "Priority",
2646 3u16 => "Dev",
2647 4u16 => "Devs",
2648 _ => return None,
2649 };
2650 Some(res)
2651 }
2652}
2653#[derive(Clone, Copy, Default)]
2654pub struct IterableNftHookAttrs<'a> {
2655 buf: &'a [u8],
2656 pos: usize,
2657 orig_loc: usize,
2658}
2659impl<'a> IterableNftHookAttrs<'a> {
2660 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2661 Self {
2662 buf,
2663 pos: 0,
2664 orig_loc,
2665 }
2666 }
2667 pub fn get_buf(&self) -> &'a [u8] {
2668 self.buf
2669 }
2670}
2671impl<'a> Iterator for IterableNftHookAttrs<'a> {
2672 type Item = Result<NftHookAttrs<'a>, ErrorContext>;
2673 fn next(&mut self) -> Option<Self::Item> {
2674 if self.buf.len() == self.pos {
2675 return None;
2676 }
2677 let pos = self.pos;
2678 let mut r#type = None;
2679 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
2680 r#type = Some(header.r#type);
2681 let res = match header.r#type {
2682 1u16 => NftHookAttrs::Num({
2683 let res = parse_be_u32(next);
2684 let Some(val) = res else { break };
2685 val
2686 }),
2687 2u16 => NftHookAttrs::Priority({
2688 let res = parse_be_i32(next);
2689 let Some(val) = res else { break };
2690 val
2691 }),
2692 3u16 => NftHookAttrs::Dev({
2693 let res = CStr::from_bytes_with_nul(next).ok();
2694 let Some(val) = res else { break };
2695 val
2696 }),
2697 4u16 => NftHookAttrs::Devs({
2698 let res = Some(IterableHookDevAttrs::with_loc(next, self.orig_loc));
2699 let Some(val) = res else { break };
2700 val
2701 }),
2702 n => {
2703 if cfg!(any(test, feature = "deny-unknown-attrs")) {
2704 break;
2705 } else {
2706 continue;
2707 }
2708 }
2709 };
2710 return Some(Ok(res));
2711 }
2712 Some(Err(ErrorContext::new(
2713 "NftHookAttrs",
2714 r#type.and_then(|t| NftHookAttrs::attr_from_type(t)),
2715 self.orig_loc,
2716 self.buf.as_ptr().wrapping_add(pos) as usize,
2717 )))
2718 }
2719}
2720impl<'a> std::fmt::Debug for IterableNftHookAttrs<'_> {
2721 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2722 let mut fmt = f.debug_struct("NftHookAttrs");
2723 for attr in self.clone() {
2724 let attr = match attr {
2725 Ok(a) => a,
2726 Err(err) => {
2727 fmt.finish()?;
2728 f.write_str("Err(")?;
2729 err.fmt(f)?;
2730 return f.write_str(")");
2731 }
2732 };
2733 match attr {
2734 NftHookAttrs::Num(val) => fmt.field("Num", &val),
2735 NftHookAttrs::Priority(val) => fmt.field("Priority", &val),
2736 NftHookAttrs::Dev(val) => fmt.field("Dev", &val),
2737 NftHookAttrs::Devs(val) => fmt.field("Devs", &val),
2738 };
2739 }
2740 fmt.finish()
2741 }
2742}
2743impl IterableNftHookAttrs<'_> {
2744 pub fn lookup_attr(
2745 &self,
2746 offset: usize,
2747 missing_type: Option<u16>,
2748 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2749 let mut stack = Vec::new();
2750 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2751 if cur == offset {
2752 stack.push(("NftHookAttrs", offset));
2753 return (
2754 stack,
2755 missing_type.and_then(|t| NftHookAttrs::attr_from_type(t)),
2756 );
2757 }
2758 if cur > offset || cur + self.buf.len() < offset {
2759 return (stack, None);
2760 }
2761 let mut attrs = self.clone();
2762 let mut last_off = cur + attrs.pos;
2763 let mut missing = None;
2764 while let Some(attr) = attrs.next() {
2765 let Ok(attr) = attr else { break };
2766 match attr {
2767 NftHookAttrs::Num(val) => {
2768 if last_off == offset {
2769 stack.push(("Num", last_off));
2770 break;
2771 }
2772 }
2773 NftHookAttrs::Priority(val) => {
2774 if last_off == offset {
2775 stack.push(("Priority", last_off));
2776 break;
2777 }
2778 }
2779 NftHookAttrs::Dev(val) => {
2780 if last_off == offset {
2781 stack.push(("Dev", last_off));
2782 break;
2783 }
2784 }
2785 NftHookAttrs::Devs(val) => {
2786 (stack, missing) = val.lookup_attr(offset, missing_type);
2787 if !stack.is_empty() {
2788 break;
2789 }
2790 }
2791 _ => {}
2792 };
2793 last_off = cur + attrs.pos;
2794 }
2795 if !stack.is_empty() {
2796 stack.push(("NftHookAttrs", cur));
2797 }
2798 (stack, missing)
2799 }
2800}
2801#[derive(Clone)]
2802pub enum HookDevAttrs<'a> {
2803 #[doc = "Attribute may repeat multiple times (treat it as array)"]
2804 Name(&'a CStr),
2805}
2806impl<'a> IterableHookDevAttrs<'a> {
2807 #[doc = "Attribute may repeat multiple times (treat it as array)"]
2808 pub fn get_name(&self) -> MultiAttrIterable<Self, HookDevAttrs<'a>, &'a CStr> {
2809 MultiAttrIterable::new(self.clone(), |variant| {
2810 if let HookDevAttrs::Name(val) = variant {
2811 Some(val)
2812 } else {
2813 None
2814 }
2815 })
2816 }
2817}
2818impl<'a> HookDevAttrs<'a> {
2819 pub fn new(buf: &'a [u8]) -> IterableHookDevAttrs<'a> {
2820 IterableHookDevAttrs::with_loc(buf, buf.as_ptr() as usize)
2821 }
2822 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2823 let res = match r#type {
2824 1u16 => "Name",
2825 _ => return None,
2826 };
2827 Some(res)
2828 }
2829}
2830#[derive(Clone, Copy, Default)]
2831pub struct IterableHookDevAttrs<'a> {
2832 buf: &'a [u8],
2833 pos: usize,
2834 orig_loc: usize,
2835}
2836impl<'a> IterableHookDevAttrs<'a> {
2837 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2838 Self {
2839 buf,
2840 pos: 0,
2841 orig_loc,
2842 }
2843 }
2844 pub fn get_buf(&self) -> &'a [u8] {
2845 self.buf
2846 }
2847}
2848impl<'a> Iterator for IterableHookDevAttrs<'a> {
2849 type Item = Result<HookDevAttrs<'a>, ErrorContext>;
2850 fn next(&mut self) -> Option<Self::Item> {
2851 if self.buf.len() == self.pos {
2852 return None;
2853 }
2854 let pos = self.pos;
2855 let mut r#type = None;
2856 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
2857 r#type = Some(header.r#type);
2858 let res = match header.r#type {
2859 1u16 => HookDevAttrs::Name({
2860 let res = CStr::from_bytes_with_nul(next).ok();
2861 let Some(val) = res else { break };
2862 val
2863 }),
2864 n => {
2865 if cfg!(any(test, feature = "deny-unknown-attrs")) {
2866 break;
2867 } else {
2868 continue;
2869 }
2870 }
2871 };
2872 return Some(Ok(res));
2873 }
2874 Some(Err(ErrorContext::new(
2875 "HookDevAttrs",
2876 r#type.and_then(|t| HookDevAttrs::attr_from_type(t)),
2877 self.orig_loc,
2878 self.buf.as_ptr().wrapping_add(pos) as usize,
2879 )))
2880 }
2881}
2882impl<'a> std::fmt::Debug for IterableHookDevAttrs<'_> {
2883 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2884 let mut fmt = f.debug_struct("HookDevAttrs");
2885 for attr in self.clone() {
2886 let attr = match attr {
2887 Ok(a) => a,
2888 Err(err) => {
2889 fmt.finish()?;
2890 f.write_str("Err(")?;
2891 err.fmt(f)?;
2892 return f.write_str(")");
2893 }
2894 };
2895 match attr {
2896 HookDevAttrs::Name(val) => fmt.field("Name", &val),
2897 };
2898 }
2899 fmt.finish()
2900 }
2901}
2902impl IterableHookDevAttrs<'_> {
2903 pub fn lookup_attr(
2904 &self,
2905 offset: usize,
2906 missing_type: Option<u16>,
2907 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2908 let mut stack = Vec::new();
2909 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2910 if cur == offset {
2911 stack.push(("HookDevAttrs", offset));
2912 return (
2913 stack,
2914 missing_type.and_then(|t| HookDevAttrs::attr_from_type(t)),
2915 );
2916 }
2917 if cur > offset || cur + self.buf.len() < offset {
2918 return (stack, None);
2919 }
2920 let mut attrs = self.clone();
2921 let mut last_off = cur + attrs.pos;
2922 while let Some(attr) = attrs.next() {
2923 let Ok(attr) = attr else { break };
2924 match attr {
2925 HookDevAttrs::Name(val) => {
2926 if last_off == offset {
2927 stack.push(("Name", last_off));
2928 break;
2929 }
2930 }
2931 _ => {}
2932 };
2933 last_off = cur + attrs.pos;
2934 }
2935 if !stack.is_empty() {
2936 stack.push(("HookDevAttrs", cur));
2937 }
2938 (stack, None)
2939 }
2940}
2941#[derive(Clone)]
2942pub enum NftCounterAttrs {
2943 Bytes(u64),
2944 Packets(u64),
2945}
2946impl<'a> IterableNftCounterAttrs<'a> {
2947 pub fn get_bytes(&self) -> Result<u64, ErrorContext> {
2948 let mut iter = self.clone();
2949 iter.pos = 0;
2950 for attr in iter {
2951 if let NftCounterAttrs::Bytes(val) = attr? {
2952 return Ok(val);
2953 }
2954 }
2955 Err(ErrorContext::new_missing(
2956 "NftCounterAttrs",
2957 "Bytes",
2958 self.orig_loc,
2959 self.buf.as_ptr() as usize,
2960 ))
2961 }
2962 pub fn get_packets(&self) -> Result<u64, ErrorContext> {
2963 let mut iter = self.clone();
2964 iter.pos = 0;
2965 for attr in iter {
2966 if let NftCounterAttrs::Packets(val) = attr? {
2967 return Ok(val);
2968 }
2969 }
2970 Err(ErrorContext::new_missing(
2971 "NftCounterAttrs",
2972 "Packets",
2973 self.orig_loc,
2974 self.buf.as_ptr() as usize,
2975 ))
2976 }
2977}
2978impl NftCounterAttrs {
2979 pub fn new(buf: &'_ [u8]) -> IterableNftCounterAttrs<'_> {
2980 IterableNftCounterAttrs::with_loc(buf, buf.as_ptr() as usize)
2981 }
2982 fn attr_from_type(r#type: u16) -> Option<&'static str> {
2983 let res = match r#type {
2984 1u16 => "Bytes",
2985 2u16 => "Packets",
2986 _ => return None,
2987 };
2988 Some(res)
2989 }
2990}
2991#[derive(Clone, Copy, Default)]
2992pub struct IterableNftCounterAttrs<'a> {
2993 buf: &'a [u8],
2994 pos: usize,
2995 orig_loc: usize,
2996}
2997impl<'a> IterableNftCounterAttrs<'a> {
2998 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2999 Self {
3000 buf,
3001 pos: 0,
3002 orig_loc,
3003 }
3004 }
3005 pub fn get_buf(&self) -> &'a [u8] {
3006 self.buf
3007 }
3008}
3009impl<'a> Iterator for IterableNftCounterAttrs<'a> {
3010 type Item = Result<NftCounterAttrs, ErrorContext>;
3011 fn next(&mut self) -> Option<Self::Item> {
3012 if self.buf.len() == self.pos {
3013 return None;
3014 }
3015 let pos = self.pos;
3016 let mut r#type = None;
3017 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
3018 r#type = Some(header.r#type);
3019 let res = match header.r#type {
3020 1u16 => NftCounterAttrs::Bytes({
3021 let res = parse_be_u64(next);
3022 let Some(val) = res else { break };
3023 val
3024 }),
3025 2u16 => NftCounterAttrs::Packets({
3026 let res = parse_be_u64(next);
3027 let Some(val) = res else { break };
3028 val
3029 }),
3030 n => {
3031 if cfg!(any(test, feature = "deny-unknown-attrs")) {
3032 break;
3033 } else {
3034 continue;
3035 }
3036 }
3037 };
3038 return Some(Ok(res));
3039 }
3040 Some(Err(ErrorContext::new(
3041 "NftCounterAttrs",
3042 r#type.and_then(|t| NftCounterAttrs::attr_from_type(t)),
3043 self.orig_loc,
3044 self.buf.as_ptr().wrapping_add(pos) as usize,
3045 )))
3046 }
3047}
3048impl std::fmt::Debug for IterableNftCounterAttrs<'_> {
3049 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3050 let mut fmt = f.debug_struct("NftCounterAttrs");
3051 for attr in self.clone() {
3052 let attr = match attr {
3053 Ok(a) => a,
3054 Err(err) => {
3055 fmt.finish()?;
3056 f.write_str("Err(")?;
3057 err.fmt(f)?;
3058 return f.write_str(")");
3059 }
3060 };
3061 match attr {
3062 NftCounterAttrs::Bytes(val) => fmt.field("Bytes", &val),
3063 NftCounterAttrs::Packets(val) => fmt.field("Packets", &val),
3064 };
3065 }
3066 fmt.finish()
3067 }
3068}
3069impl IterableNftCounterAttrs<'_> {
3070 pub fn lookup_attr(
3071 &self,
3072 offset: usize,
3073 missing_type: Option<u16>,
3074 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3075 let mut stack = Vec::new();
3076 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3077 if cur == offset {
3078 stack.push(("NftCounterAttrs", offset));
3079 return (
3080 stack,
3081 missing_type.and_then(|t| NftCounterAttrs::attr_from_type(t)),
3082 );
3083 }
3084 if cur > offset || cur + self.buf.len() < offset {
3085 return (stack, None);
3086 }
3087 let mut attrs = self.clone();
3088 let mut last_off = cur + attrs.pos;
3089 while let Some(attr) = attrs.next() {
3090 let Ok(attr) = attr else { break };
3091 match attr {
3092 NftCounterAttrs::Bytes(val) => {
3093 if last_off == offset {
3094 stack.push(("Bytes", last_off));
3095 break;
3096 }
3097 }
3098 NftCounterAttrs::Packets(val) => {
3099 if last_off == offset {
3100 stack.push(("Packets", last_off));
3101 break;
3102 }
3103 }
3104 _ => {}
3105 };
3106 last_off = cur + attrs.pos;
3107 }
3108 if !stack.is_empty() {
3109 stack.push(("NftCounterAttrs", cur));
3110 }
3111 (stack, None)
3112 }
3113}
3114#[derive(Clone)]
3115pub enum RuleAttrs<'a> {
3116 #[doc = "name of the table containing the rule"]
3117 Table(&'a CStr),
3118 #[doc = "name of the chain containing the rule"]
3119 Chain(&'a CStr),
3120 #[doc = "numeric handle of the rule"]
3121 Handle(u64),
3122 #[doc = "list of expressions"]
3123 Expressions(IterableExprListAttrs<'a>),
3124 #[doc = "compatibility specifications of the rule"]
3125 Compat(IterableRuleCompatAttrs<'a>),
3126 #[doc = "numeric handle of the previous rule"]
3127 Position(u64),
3128 #[doc = "user data"]
3129 Userdata(&'a [u8]),
3130 #[doc = "uniquely identifies a rule in a transaction"]
3131 Id(u32),
3132 #[doc = "transaction unique identifier of the previous rule"]
3133 PositionId(u32),
3134 #[doc = "add the rule to chain by ID, alternative to chain name"]
3135 ChainId(u32),
3136}
3137impl<'a> IterableRuleAttrs<'a> {
3138 #[doc = "name of the table containing the rule"]
3139 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
3140 let mut iter = self.clone();
3141 iter.pos = 0;
3142 for attr in iter {
3143 if let RuleAttrs::Table(val) = attr? {
3144 return Ok(val);
3145 }
3146 }
3147 Err(ErrorContext::new_missing(
3148 "RuleAttrs",
3149 "Table",
3150 self.orig_loc,
3151 self.buf.as_ptr() as usize,
3152 ))
3153 }
3154 #[doc = "name of the chain containing the rule"]
3155 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
3156 let mut iter = self.clone();
3157 iter.pos = 0;
3158 for attr in iter {
3159 if let RuleAttrs::Chain(val) = attr? {
3160 return Ok(val);
3161 }
3162 }
3163 Err(ErrorContext::new_missing(
3164 "RuleAttrs",
3165 "Chain",
3166 self.orig_loc,
3167 self.buf.as_ptr() as usize,
3168 ))
3169 }
3170 #[doc = "numeric handle of the rule"]
3171 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
3172 let mut iter = self.clone();
3173 iter.pos = 0;
3174 for attr in iter {
3175 if let RuleAttrs::Handle(val) = attr? {
3176 return Ok(val);
3177 }
3178 }
3179 Err(ErrorContext::new_missing(
3180 "RuleAttrs",
3181 "Handle",
3182 self.orig_loc,
3183 self.buf.as_ptr() as usize,
3184 ))
3185 }
3186 #[doc = "list of expressions"]
3187 pub fn get_expressions(&self) -> Result<IterableExprListAttrs<'a>, ErrorContext> {
3188 let mut iter = self.clone();
3189 iter.pos = 0;
3190 for attr in iter {
3191 if let RuleAttrs::Expressions(val) = attr? {
3192 return Ok(val);
3193 }
3194 }
3195 Err(ErrorContext::new_missing(
3196 "RuleAttrs",
3197 "Expressions",
3198 self.orig_loc,
3199 self.buf.as_ptr() as usize,
3200 ))
3201 }
3202 #[doc = "compatibility specifications of the rule"]
3203 pub fn get_compat(&self) -> Result<IterableRuleCompatAttrs<'a>, ErrorContext> {
3204 let mut iter = self.clone();
3205 iter.pos = 0;
3206 for attr in iter {
3207 if let RuleAttrs::Compat(val) = attr? {
3208 return Ok(val);
3209 }
3210 }
3211 Err(ErrorContext::new_missing(
3212 "RuleAttrs",
3213 "Compat",
3214 self.orig_loc,
3215 self.buf.as_ptr() as usize,
3216 ))
3217 }
3218 #[doc = "numeric handle of the previous rule"]
3219 pub fn get_position(&self) -> Result<u64, ErrorContext> {
3220 let mut iter = self.clone();
3221 iter.pos = 0;
3222 for attr in iter {
3223 if let RuleAttrs::Position(val) = attr? {
3224 return Ok(val);
3225 }
3226 }
3227 Err(ErrorContext::new_missing(
3228 "RuleAttrs",
3229 "Position",
3230 self.orig_loc,
3231 self.buf.as_ptr() as usize,
3232 ))
3233 }
3234 #[doc = "user data"]
3235 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
3236 let mut iter = self.clone();
3237 iter.pos = 0;
3238 for attr in iter {
3239 if let RuleAttrs::Userdata(val) = attr? {
3240 return Ok(val);
3241 }
3242 }
3243 Err(ErrorContext::new_missing(
3244 "RuleAttrs",
3245 "Userdata",
3246 self.orig_loc,
3247 self.buf.as_ptr() as usize,
3248 ))
3249 }
3250 #[doc = "uniquely identifies a rule in a transaction"]
3251 pub fn get_id(&self) -> Result<u32, ErrorContext> {
3252 let mut iter = self.clone();
3253 iter.pos = 0;
3254 for attr in iter {
3255 if let RuleAttrs::Id(val) = attr? {
3256 return Ok(val);
3257 }
3258 }
3259 Err(ErrorContext::new_missing(
3260 "RuleAttrs",
3261 "Id",
3262 self.orig_loc,
3263 self.buf.as_ptr() as usize,
3264 ))
3265 }
3266 #[doc = "transaction unique identifier of the previous rule"]
3267 pub fn get_position_id(&self) -> Result<u32, ErrorContext> {
3268 let mut iter = self.clone();
3269 iter.pos = 0;
3270 for attr in iter {
3271 if let RuleAttrs::PositionId(val) = attr? {
3272 return Ok(val);
3273 }
3274 }
3275 Err(ErrorContext::new_missing(
3276 "RuleAttrs",
3277 "PositionId",
3278 self.orig_loc,
3279 self.buf.as_ptr() as usize,
3280 ))
3281 }
3282 #[doc = "add the rule to chain by ID, alternative to chain name"]
3283 pub fn get_chain_id(&self) -> Result<u32, ErrorContext> {
3284 let mut iter = self.clone();
3285 iter.pos = 0;
3286 for attr in iter {
3287 if let RuleAttrs::ChainId(val) = attr? {
3288 return Ok(val);
3289 }
3290 }
3291 Err(ErrorContext::new_missing(
3292 "RuleAttrs",
3293 "ChainId",
3294 self.orig_loc,
3295 self.buf.as_ptr() as usize,
3296 ))
3297 }
3298}
3299impl<'a> RuleAttrs<'a> {
3300 pub fn new(buf: &'a [u8]) -> IterableRuleAttrs<'a> {
3301 IterableRuleAttrs::with_loc(buf, buf.as_ptr() as usize)
3302 }
3303 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3304 let res = match r#type {
3305 1u16 => "Table",
3306 2u16 => "Chain",
3307 3u16 => "Handle",
3308 4u16 => "Expressions",
3309 5u16 => "Compat",
3310 6u16 => "Position",
3311 7u16 => "Userdata",
3312 8u16 => "Id",
3313 9u16 => "PositionId",
3314 10u16 => "ChainId",
3315 _ => return None,
3316 };
3317 Some(res)
3318 }
3319}
3320#[derive(Clone, Copy, Default)]
3321pub struct IterableRuleAttrs<'a> {
3322 buf: &'a [u8],
3323 pos: usize,
3324 orig_loc: usize,
3325}
3326impl<'a> IterableRuleAttrs<'a> {
3327 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3328 Self {
3329 buf,
3330 pos: 0,
3331 orig_loc,
3332 }
3333 }
3334 pub fn get_buf(&self) -> &'a [u8] {
3335 self.buf
3336 }
3337}
3338impl<'a> Iterator for IterableRuleAttrs<'a> {
3339 type Item = Result<RuleAttrs<'a>, ErrorContext>;
3340 fn next(&mut self) -> Option<Self::Item> {
3341 if self.buf.len() == self.pos {
3342 return None;
3343 }
3344 let pos = self.pos;
3345 let mut r#type = None;
3346 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
3347 r#type = Some(header.r#type);
3348 let res = match header.r#type {
3349 1u16 => RuleAttrs::Table({
3350 let res = CStr::from_bytes_with_nul(next).ok();
3351 let Some(val) = res else { break };
3352 val
3353 }),
3354 2u16 => RuleAttrs::Chain({
3355 let res = CStr::from_bytes_with_nul(next).ok();
3356 let Some(val) = res else { break };
3357 val
3358 }),
3359 3u16 => RuleAttrs::Handle({
3360 let res = parse_be_u64(next);
3361 let Some(val) = res else { break };
3362 val
3363 }),
3364 4u16 => RuleAttrs::Expressions({
3365 let res = Some(IterableExprListAttrs::with_loc(next, self.orig_loc));
3366 let Some(val) = res else { break };
3367 val
3368 }),
3369 5u16 => RuleAttrs::Compat({
3370 let res = Some(IterableRuleCompatAttrs::with_loc(next, self.orig_loc));
3371 let Some(val) = res else { break };
3372 val
3373 }),
3374 6u16 => RuleAttrs::Position({
3375 let res = parse_be_u64(next);
3376 let Some(val) = res else { break };
3377 val
3378 }),
3379 7u16 => RuleAttrs::Userdata({
3380 let res = Some(next);
3381 let Some(val) = res else { break };
3382 val
3383 }),
3384 8u16 => RuleAttrs::Id({
3385 let res = parse_u32(next);
3386 let Some(val) = res else { break };
3387 val
3388 }),
3389 9u16 => RuleAttrs::PositionId({
3390 let res = parse_u32(next);
3391 let Some(val) = res else { break };
3392 val
3393 }),
3394 10u16 => RuleAttrs::ChainId({
3395 let res = parse_u32(next);
3396 let Some(val) = res else { break };
3397 val
3398 }),
3399 n => {
3400 if cfg!(any(test, feature = "deny-unknown-attrs")) {
3401 break;
3402 } else {
3403 continue;
3404 }
3405 }
3406 };
3407 return Some(Ok(res));
3408 }
3409 Some(Err(ErrorContext::new(
3410 "RuleAttrs",
3411 r#type.and_then(|t| RuleAttrs::attr_from_type(t)),
3412 self.orig_loc,
3413 self.buf.as_ptr().wrapping_add(pos) as usize,
3414 )))
3415 }
3416}
3417impl<'a> std::fmt::Debug for IterableRuleAttrs<'_> {
3418 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3419 let mut fmt = f.debug_struct("RuleAttrs");
3420 for attr in self.clone() {
3421 let attr = match attr {
3422 Ok(a) => a,
3423 Err(err) => {
3424 fmt.finish()?;
3425 f.write_str("Err(")?;
3426 err.fmt(f)?;
3427 return f.write_str(")");
3428 }
3429 };
3430 match attr {
3431 RuleAttrs::Table(val) => fmt.field("Table", &val),
3432 RuleAttrs::Chain(val) => fmt.field("Chain", &val),
3433 RuleAttrs::Handle(val) => fmt.field("Handle", &val),
3434 RuleAttrs::Expressions(val) => fmt.field("Expressions", &val),
3435 RuleAttrs::Compat(val) => fmt.field("Compat", &val),
3436 RuleAttrs::Position(val) => fmt.field("Position", &val),
3437 RuleAttrs::Userdata(val) => fmt.field("Userdata", &val),
3438 RuleAttrs::Id(val) => fmt.field("Id", &val),
3439 RuleAttrs::PositionId(val) => fmt.field("PositionId", &val),
3440 RuleAttrs::ChainId(val) => fmt.field("ChainId", &val),
3441 };
3442 }
3443 fmt.finish()
3444 }
3445}
3446impl IterableRuleAttrs<'_> {
3447 pub fn lookup_attr(
3448 &self,
3449 offset: usize,
3450 missing_type: Option<u16>,
3451 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3452 let mut stack = Vec::new();
3453 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3454 if cur == offset {
3455 stack.push(("RuleAttrs", offset));
3456 return (
3457 stack,
3458 missing_type.and_then(|t| RuleAttrs::attr_from_type(t)),
3459 );
3460 }
3461 if cur > offset || cur + self.buf.len() < offset {
3462 return (stack, None);
3463 }
3464 let mut attrs = self.clone();
3465 let mut last_off = cur + attrs.pos;
3466 let mut missing = None;
3467 while let Some(attr) = attrs.next() {
3468 let Ok(attr) = attr else { break };
3469 match attr {
3470 RuleAttrs::Table(val) => {
3471 if last_off == offset {
3472 stack.push(("Table", last_off));
3473 break;
3474 }
3475 }
3476 RuleAttrs::Chain(val) => {
3477 if last_off == offset {
3478 stack.push(("Chain", last_off));
3479 break;
3480 }
3481 }
3482 RuleAttrs::Handle(val) => {
3483 if last_off == offset {
3484 stack.push(("Handle", last_off));
3485 break;
3486 }
3487 }
3488 RuleAttrs::Expressions(val) => {
3489 (stack, missing) = val.lookup_attr(offset, missing_type);
3490 if !stack.is_empty() {
3491 break;
3492 }
3493 }
3494 RuleAttrs::Compat(val) => {
3495 (stack, missing) = val.lookup_attr(offset, missing_type);
3496 if !stack.is_empty() {
3497 break;
3498 }
3499 }
3500 RuleAttrs::Position(val) => {
3501 if last_off == offset {
3502 stack.push(("Position", last_off));
3503 break;
3504 }
3505 }
3506 RuleAttrs::Userdata(val) => {
3507 if last_off == offset {
3508 stack.push(("Userdata", last_off));
3509 break;
3510 }
3511 }
3512 RuleAttrs::Id(val) => {
3513 if last_off == offset {
3514 stack.push(("Id", last_off));
3515 break;
3516 }
3517 }
3518 RuleAttrs::PositionId(val) => {
3519 if last_off == offset {
3520 stack.push(("PositionId", last_off));
3521 break;
3522 }
3523 }
3524 RuleAttrs::ChainId(val) => {
3525 if last_off == offset {
3526 stack.push(("ChainId", last_off));
3527 break;
3528 }
3529 }
3530 _ => {}
3531 };
3532 last_off = cur + attrs.pos;
3533 }
3534 if !stack.is_empty() {
3535 stack.push(("RuleAttrs", cur));
3536 }
3537 (stack, missing)
3538 }
3539}
3540#[derive(Clone)]
3541pub enum ExprListAttrs<'a> {
3542 #[doc = "Attribute may repeat multiple times (treat it as array)"]
3543 Elem(IterableExprAttrs<'a>),
3544}
3545impl<'a> IterableExprListAttrs<'a> {
3546 #[doc = "Attribute may repeat multiple times (treat it as array)"]
3547 pub fn get_elem(&self) -> MultiAttrIterable<Self, ExprListAttrs<'a>, IterableExprAttrs<'a>> {
3548 MultiAttrIterable::new(self.clone(), |variant| {
3549 if let ExprListAttrs::Elem(val) = variant {
3550 Some(val)
3551 } else {
3552 None
3553 }
3554 })
3555 }
3556}
3557impl<'a> ExprListAttrs<'a> {
3558 pub fn new(buf: &'a [u8]) -> IterableExprListAttrs<'a> {
3559 IterableExprListAttrs::with_loc(buf, buf.as_ptr() as usize)
3560 }
3561 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3562 let res = match r#type {
3563 1u16 => "Elem",
3564 _ => return None,
3565 };
3566 Some(res)
3567 }
3568}
3569#[derive(Clone, Copy, Default)]
3570pub struct IterableExprListAttrs<'a> {
3571 buf: &'a [u8],
3572 pos: usize,
3573 orig_loc: usize,
3574}
3575impl<'a> IterableExprListAttrs<'a> {
3576 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3577 Self {
3578 buf,
3579 pos: 0,
3580 orig_loc,
3581 }
3582 }
3583 pub fn get_buf(&self) -> &'a [u8] {
3584 self.buf
3585 }
3586}
3587impl<'a> Iterator for IterableExprListAttrs<'a> {
3588 type Item = Result<ExprListAttrs<'a>, ErrorContext>;
3589 fn next(&mut self) -> Option<Self::Item> {
3590 if self.buf.len() == self.pos {
3591 return None;
3592 }
3593 let pos = self.pos;
3594 let mut r#type = None;
3595 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
3596 r#type = Some(header.r#type);
3597 let res = match header.r#type {
3598 1u16 => ExprListAttrs::Elem({
3599 let res = Some(IterableExprAttrs::with_loc(next, self.orig_loc));
3600 let Some(val) = res else { break };
3601 val
3602 }),
3603 n => {
3604 if cfg!(any(test, feature = "deny-unknown-attrs")) {
3605 break;
3606 } else {
3607 continue;
3608 }
3609 }
3610 };
3611 return Some(Ok(res));
3612 }
3613 Some(Err(ErrorContext::new(
3614 "ExprListAttrs",
3615 r#type.and_then(|t| ExprListAttrs::attr_from_type(t)),
3616 self.orig_loc,
3617 self.buf.as_ptr().wrapping_add(pos) as usize,
3618 )))
3619 }
3620}
3621impl<'a> std::fmt::Debug for IterableExprListAttrs<'_> {
3622 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3623 let mut fmt = f.debug_struct("ExprListAttrs");
3624 for attr in self.clone() {
3625 let attr = match attr {
3626 Ok(a) => a,
3627 Err(err) => {
3628 fmt.finish()?;
3629 f.write_str("Err(")?;
3630 err.fmt(f)?;
3631 return f.write_str(")");
3632 }
3633 };
3634 match attr {
3635 ExprListAttrs::Elem(val) => fmt.field("Elem", &val),
3636 };
3637 }
3638 fmt.finish()
3639 }
3640}
3641impl IterableExprListAttrs<'_> {
3642 pub fn lookup_attr(
3643 &self,
3644 offset: usize,
3645 missing_type: Option<u16>,
3646 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3647 let mut stack = Vec::new();
3648 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3649 if cur == offset {
3650 stack.push(("ExprListAttrs", offset));
3651 return (
3652 stack,
3653 missing_type.and_then(|t| ExprListAttrs::attr_from_type(t)),
3654 );
3655 }
3656 if cur > offset || cur + self.buf.len() < offset {
3657 return (stack, None);
3658 }
3659 let mut attrs = self.clone();
3660 let mut last_off = cur + attrs.pos;
3661 let mut missing = None;
3662 while let Some(attr) = attrs.next() {
3663 let Ok(attr) = attr else { break };
3664 match attr {
3665 ExprListAttrs::Elem(val) => {
3666 (stack, missing) = val.lookup_attr(offset, missing_type);
3667 if !stack.is_empty() {
3668 break;
3669 }
3670 }
3671 _ => {}
3672 };
3673 last_off = cur + attrs.pos;
3674 }
3675 if !stack.is_empty() {
3676 stack.push(("ExprListAttrs", cur));
3677 }
3678 (stack, missing)
3679 }
3680}
3681#[derive(Clone)]
3682pub enum ExprAttrs<'a> {
3683 #[doc = "name of the expression type"]
3684 Name(&'a CStr),
3685 #[doc = "type specific data"]
3686 Data(ExprOps<'a>),
3687}
3688impl<'a> IterableExprAttrs<'a> {
3689 #[doc = "name of the expression type"]
3690 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
3691 let mut iter = self.clone();
3692 iter.pos = 0;
3693 for attr in iter {
3694 if let ExprAttrs::Name(val) = attr? {
3695 return Ok(val);
3696 }
3697 }
3698 Err(ErrorContext::new_missing(
3699 "ExprAttrs",
3700 "Name",
3701 self.orig_loc,
3702 self.buf.as_ptr() as usize,
3703 ))
3704 }
3705 #[doc = "type specific data"]
3706 pub fn get_data(&self) -> Result<ExprOps<'a>, ErrorContext> {
3707 let mut iter = self.clone();
3708 iter.pos = 0;
3709 for attr in iter {
3710 if let ExprAttrs::Data(val) = attr? {
3711 return Ok(val);
3712 }
3713 }
3714 Err(ErrorContext::new_missing(
3715 "ExprAttrs",
3716 "Data",
3717 self.orig_loc,
3718 self.buf.as_ptr() as usize,
3719 ))
3720 }
3721}
3722#[derive(Debug, Clone)]
3723pub enum ExprOps<'a> {
3724 Bitwise(IterableExprBitwiseAttrs<'a>),
3725 Cmp(IterableExprCmpAttrs<'a>),
3726 Counter(IterableExprCounterAttrs<'a>),
3727 Ct(IterableExprCtAttrs<'a>),
3728 Fib(IterableExprFibAttrs<'a>),
3729 FlowOffload(IterableExprFlowOffloadAttrs<'a>),
3730 Immediate(IterableExprImmediateAttrs<'a>),
3731 Lookup(IterableExprLookupAttrs<'a>),
3732 Meta(IterableExprMetaAttrs<'a>),
3733 Nat(IterableExprNatAttrs<'a>),
3734 Objref(IterableExprObjrefAttrs<'a>),
3735 Payload(IterableExprPayloadAttrs<'a>),
3736 Quota(IterableQuotaAttrs<'a>),
3737 Reject(IterableExprRejectAttrs<'a>),
3738 Target(IterableExprTargetAttrs<'a>),
3739 Tproxy(IterableExprTproxyAttrs<'a>),
3740 Match(IterableCompatMatchAttrs<'a>),
3741 Range(IterableRangeAttrs<'a>),
3742 Numgen(IterableNumgenAttrs<'a>),
3743 Log(IterableLogAttrs<'a>),
3744}
3745impl<'a> ExprOps<'a> {
3746 fn select_with_loc(selector: &'a CStr, buf: &'a [u8], loc: usize) -> Option<Self> {
3747 match selector.to_bytes() {
3748 b"bitwise" => Some(ExprOps::Bitwise(IterableExprBitwiseAttrs::with_loc(
3749 buf, loc,
3750 ))),
3751 b"cmp" => Some(ExprOps::Cmp(IterableExprCmpAttrs::with_loc(buf, loc))),
3752 b"counter" => Some(ExprOps::Counter(IterableExprCounterAttrs::with_loc(
3753 buf, loc,
3754 ))),
3755 b"ct" => Some(ExprOps::Ct(IterableExprCtAttrs::with_loc(buf, loc))),
3756 b"fib" => Some(ExprOps::Fib(IterableExprFibAttrs::with_loc(buf, loc))),
3757 b"flow_offload" => Some(ExprOps::FlowOffload(
3758 IterableExprFlowOffloadAttrs::with_loc(buf, loc),
3759 )),
3760 b"immediate" => Some(ExprOps::Immediate(IterableExprImmediateAttrs::with_loc(
3761 buf, loc,
3762 ))),
3763 b"lookup" => Some(ExprOps::Lookup(IterableExprLookupAttrs::with_loc(buf, loc))),
3764 b"meta" => Some(ExprOps::Meta(IterableExprMetaAttrs::with_loc(buf, loc))),
3765 b"nat" => Some(ExprOps::Nat(IterableExprNatAttrs::with_loc(buf, loc))),
3766 b"objref" => Some(ExprOps::Objref(IterableExprObjrefAttrs::with_loc(buf, loc))),
3767 b"payload" => Some(ExprOps::Payload(IterableExprPayloadAttrs::with_loc(
3768 buf, loc,
3769 ))),
3770 b"quota" => Some(ExprOps::Quota(IterableQuotaAttrs::with_loc(buf, loc))),
3771 b"reject" => Some(ExprOps::Reject(IterableExprRejectAttrs::with_loc(buf, loc))),
3772 b"target" => Some(ExprOps::Target(IterableExprTargetAttrs::with_loc(buf, loc))),
3773 b"tproxy" => Some(ExprOps::Tproxy(IterableExprTproxyAttrs::with_loc(buf, loc))),
3774 b"match" => Some(ExprOps::Match(IterableCompatMatchAttrs::with_loc(buf, loc))),
3775 b"range" => Some(ExprOps::Range(IterableRangeAttrs::with_loc(buf, loc))),
3776 b"numgen" => Some(ExprOps::Numgen(IterableNumgenAttrs::with_loc(buf, loc))),
3777 b"log" => Some(ExprOps::Log(IterableLogAttrs::with_loc(buf, loc))),
3778 _ => None,
3779 }
3780 }
3781}
3782impl<'a> ExprAttrs<'a> {
3783 pub fn new(buf: &'a [u8]) -> IterableExprAttrs<'a> {
3784 IterableExprAttrs::with_loc(buf, buf.as_ptr() as usize)
3785 }
3786 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3787 let res = match r#type {
3788 1u16 => "Name",
3789 2u16 => "Data",
3790 _ => return None,
3791 };
3792 Some(res)
3793 }
3794}
3795#[derive(Clone, Copy, Default)]
3796pub struct IterableExprAttrs<'a> {
3797 buf: &'a [u8],
3798 pos: usize,
3799 orig_loc: usize,
3800}
3801impl<'a> IterableExprAttrs<'a> {
3802 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3803 Self {
3804 buf,
3805 pos: 0,
3806 orig_loc,
3807 }
3808 }
3809 pub fn get_buf(&self) -> &'a [u8] {
3810 self.buf
3811 }
3812}
3813impl<'a> Iterator for IterableExprAttrs<'a> {
3814 type Item = Result<ExprAttrs<'a>, ErrorContext>;
3815 fn next(&mut self) -> Option<Self::Item> {
3816 if self.buf.len() == self.pos {
3817 return None;
3818 }
3819 let pos = self.pos;
3820 let mut r#type = None;
3821 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
3822 r#type = Some(header.r#type);
3823 let res = match header.r#type {
3824 1u16 => ExprAttrs::Name({
3825 let res = CStr::from_bytes_with_nul(next).ok();
3826 let Some(val) = res else { break };
3827 val
3828 }),
3829 2u16 => ExprAttrs::Data({
3830 let res = {
3831 let Ok(selector) = self.get_name() else { break };
3832 ExprOps::select_with_loc(selector, next, self.orig_loc)
3833 };
3834 let Some(val) = res else { break };
3835 val
3836 }),
3837 n => {
3838 if cfg!(any(test, feature = "deny-unknown-attrs")) {
3839 break;
3840 } else {
3841 continue;
3842 }
3843 }
3844 };
3845 return Some(Ok(res));
3846 }
3847 Some(Err(ErrorContext::new(
3848 "ExprAttrs",
3849 r#type.and_then(|t| ExprAttrs::attr_from_type(t)),
3850 self.orig_loc,
3851 self.buf.as_ptr().wrapping_add(pos) as usize,
3852 )))
3853 }
3854}
3855impl<'a> std::fmt::Debug for IterableExprAttrs<'_> {
3856 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3857 let mut fmt = f.debug_struct("ExprAttrs");
3858 for attr in self.clone() {
3859 let attr = match attr {
3860 Ok(a) => a,
3861 Err(err) => {
3862 fmt.finish()?;
3863 f.write_str("Err(")?;
3864 err.fmt(f)?;
3865 return f.write_str(")");
3866 }
3867 };
3868 match attr {
3869 ExprAttrs::Name(val) => fmt.field("Name", &val),
3870 ExprAttrs::Data(val) => fmt.field("Data", &val),
3871 };
3872 }
3873 fmt.finish()
3874 }
3875}
3876impl IterableExprAttrs<'_> {
3877 pub fn lookup_attr(
3878 &self,
3879 offset: usize,
3880 missing_type: Option<u16>,
3881 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3882 let mut stack = Vec::new();
3883 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3884 if cur == offset {
3885 stack.push(("ExprAttrs", offset));
3886 return (
3887 stack,
3888 missing_type.and_then(|t| ExprAttrs::attr_from_type(t)),
3889 );
3890 }
3891 if cur > offset || cur + self.buf.len() < offset {
3892 return (stack, None);
3893 }
3894 let mut attrs = self.clone();
3895 let mut last_off = cur + attrs.pos;
3896 while let Some(attr) = attrs.next() {
3897 let Ok(attr) = attr else { break };
3898 match attr {
3899 ExprAttrs::Name(val) => {
3900 if last_off == offset {
3901 stack.push(("Name", last_off));
3902 break;
3903 }
3904 }
3905 ExprAttrs::Data(val) => {
3906 if last_off == offset {
3907 stack.push(("Data", last_off));
3908 break;
3909 }
3910 }
3911 _ => {}
3912 };
3913 last_off = cur + attrs.pos;
3914 }
3915 if !stack.is_empty() {
3916 stack.push(("ExprAttrs", cur));
3917 }
3918 (stack, None)
3919 }
3920}
3921#[derive(Clone)]
3922pub enum RuleCompatAttrs {
3923 #[doc = "numeric value of the handled protocol"]
3924 Proto(u32),
3925 #[doc = "bitmask of flags"]
3926 Flags(u32),
3927}
3928impl<'a> IterableRuleCompatAttrs<'a> {
3929 #[doc = "numeric value of the handled protocol"]
3930 pub fn get_proto(&self) -> Result<u32, ErrorContext> {
3931 let mut iter = self.clone();
3932 iter.pos = 0;
3933 for attr in iter {
3934 if let RuleCompatAttrs::Proto(val) = attr? {
3935 return Ok(val);
3936 }
3937 }
3938 Err(ErrorContext::new_missing(
3939 "RuleCompatAttrs",
3940 "Proto",
3941 self.orig_loc,
3942 self.buf.as_ptr() as usize,
3943 ))
3944 }
3945 #[doc = "bitmask of flags"]
3946 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
3947 let mut iter = self.clone();
3948 iter.pos = 0;
3949 for attr in iter {
3950 if let RuleCompatAttrs::Flags(val) = attr? {
3951 return Ok(val);
3952 }
3953 }
3954 Err(ErrorContext::new_missing(
3955 "RuleCompatAttrs",
3956 "Flags",
3957 self.orig_loc,
3958 self.buf.as_ptr() as usize,
3959 ))
3960 }
3961}
3962impl RuleCompatAttrs {
3963 pub fn new(buf: &'_ [u8]) -> IterableRuleCompatAttrs<'_> {
3964 IterableRuleCompatAttrs::with_loc(buf, buf.as_ptr() as usize)
3965 }
3966 fn attr_from_type(r#type: u16) -> Option<&'static str> {
3967 let res = match r#type {
3968 1u16 => "Proto",
3969 2u16 => "Flags",
3970 _ => return None,
3971 };
3972 Some(res)
3973 }
3974}
3975#[derive(Clone, Copy, Default)]
3976pub struct IterableRuleCompatAttrs<'a> {
3977 buf: &'a [u8],
3978 pos: usize,
3979 orig_loc: usize,
3980}
3981impl<'a> IterableRuleCompatAttrs<'a> {
3982 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3983 Self {
3984 buf,
3985 pos: 0,
3986 orig_loc,
3987 }
3988 }
3989 pub fn get_buf(&self) -> &'a [u8] {
3990 self.buf
3991 }
3992}
3993impl<'a> Iterator for IterableRuleCompatAttrs<'a> {
3994 type Item = Result<RuleCompatAttrs, ErrorContext>;
3995 fn next(&mut self) -> Option<Self::Item> {
3996 if self.buf.len() == self.pos {
3997 return None;
3998 }
3999 let pos = self.pos;
4000 let mut r#type = None;
4001 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
4002 r#type = Some(header.r#type);
4003 let res = match header.r#type {
4004 1u16 => RuleCompatAttrs::Proto({
4005 let res = parse_be_u32(next);
4006 let Some(val) = res else { break };
4007 val
4008 }),
4009 2u16 => RuleCompatAttrs::Flags({
4010 let res = parse_be_u32(next);
4011 let Some(val) = res else { break };
4012 val
4013 }),
4014 n => {
4015 if cfg!(any(test, feature = "deny-unknown-attrs")) {
4016 break;
4017 } else {
4018 continue;
4019 }
4020 }
4021 };
4022 return Some(Ok(res));
4023 }
4024 Some(Err(ErrorContext::new(
4025 "RuleCompatAttrs",
4026 r#type.and_then(|t| RuleCompatAttrs::attr_from_type(t)),
4027 self.orig_loc,
4028 self.buf.as_ptr().wrapping_add(pos) as usize,
4029 )))
4030 }
4031}
4032impl std::fmt::Debug for IterableRuleCompatAttrs<'_> {
4033 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4034 let mut fmt = f.debug_struct("RuleCompatAttrs");
4035 for attr in self.clone() {
4036 let attr = match attr {
4037 Ok(a) => a,
4038 Err(err) => {
4039 fmt.finish()?;
4040 f.write_str("Err(")?;
4041 err.fmt(f)?;
4042 return f.write_str(")");
4043 }
4044 };
4045 match attr {
4046 RuleCompatAttrs::Proto(val) => fmt.field("Proto", &val),
4047 RuleCompatAttrs::Flags(val) => fmt.field("Flags", &val),
4048 };
4049 }
4050 fmt.finish()
4051 }
4052}
4053impl IterableRuleCompatAttrs<'_> {
4054 pub fn lookup_attr(
4055 &self,
4056 offset: usize,
4057 missing_type: Option<u16>,
4058 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
4059 let mut stack = Vec::new();
4060 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
4061 if cur == offset {
4062 stack.push(("RuleCompatAttrs", offset));
4063 return (
4064 stack,
4065 missing_type.and_then(|t| RuleCompatAttrs::attr_from_type(t)),
4066 );
4067 }
4068 if cur > offset || cur + self.buf.len() < offset {
4069 return (stack, None);
4070 }
4071 let mut attrs = self.clone();
4072 let mut last_off = cur + attrs.pos;
4073 while let Some(attr) = attrs.next() {
4074 let Ok(attr) = attr else { break };
4075 match attr {
4076 RuleCompatAttrs::Proto(val) => {
4077 if last_off == offset {
4078 stack.push(("Proto", last_off));
4079 break;
4080 }
4081 }
4082 RuleCompatAttrs::Flags(val) => {
4083 if last_off == offset {
4084 stack.push(("Flags", last_off));
4085 break;
4086 }
4087 }
4088 _ => {}
4089 };
4090 last_off = cur + attrs.pos;
4091 }
4092 if !stack.is_empty() {
4093 stack.push(("RuleCompatAttrs", cur));
4094 }
4095 (stack, None)
4096 }
4097}
4098#[derive(Clone)]
4099pub enum SetAttrs<'a> {
4100 #[doc = "table name"]
4101 Table(&'a CStr),
4102 #[doc = "set name"]
4103 Name(&'a CStr),
4104 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
4105 Flags(u32),
4106 #[doc = "key data type, informational purpose only"]
4107 KeyType(u32),
4108 #[doc = "key data length"]
4109 KeyLen(u32),
4110 #[doc = "mapping data type"]
4111 DataType(u32),
4112 #[doc = "mapping data length"]
4113 DataLen(u32),
4114 #[doc = "selection policy"]
4115 Policy(u32),
4116 #[doc = "set description"]
4117 Desc(IterableSetDescAttrs<'a>),
4118 #[doc = "uniquely identifies a set in a transaction"]
4119 Id(u32),
4120 #[doc = "default timeout value"]
4121 Timeout(u64),
4122 #[doc = "garbage collection interval"]
4123 GcInterval(u32),
4124 #[doc = "user data"]
4125 Userdata(&'a [u8]),
4126 Pad(&'a [u8]),
4127 #[doc = "stateful object type"]
4128 ObjType(u32),
4129 #[doc = "set handle"]
4130 Handle(u64),
4131 #[doc = "set expression\nAttribute may repeat multiple times (treat it as array)"]
4132 Expr(IterableExprAttrs<'a>),
4133 #[doc = "list of expressions"]
4134 Expressions(IterableSetListAttrs<'a>),
4135 #[doc = "set backend type"]
4136 Type(&'a CStr),
4137 #[doc = "number of set elements"]
4138 Count(u32),
4139}
4140impl<'a> IterableSetAttrs<'a> {
4141 #[doc = "table name"]
4142 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
4143 let mut iter = self.clone();
4144 iter.pos = 0;
4145 for attr in iter {
4146 if let SetAttrs::Table(val) = attr? {
4147 return Ok(val);
4148 }
4149 }
4150 Err(ErrorContext::new_missing(
4151 "SetAttrs",
4152 "Table",
4153 self.orig_loc,
4154 self.buf.as_ptr() as usize,
4155 ))
4156 }
4157 #[doc = "set name"]
4158 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
4159 let mut iter = self.clone();
4160 iter.pos = 0;
4161 for attr in iter {
4162 if let SetAttrs::Name(val) = attr? {
4163 return Ok(val);
4164 }
4165 }
4166 Err(ErrorContext::new_missing(
4167 "SetAttrs",
4168 "Name",
4169 self.orig_loc,
4170 self.buf.as_ptr() as usize,
4171 ))
4172 }
4173 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
4174 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
4175 let mut iter = self.clone();
4176 iter.pos = 0;
4177 for attr in iter {
4178 if let SetAttrs::Flags(val) = attr? {
4179 return Ok(val);
4180 }
4181 }
4182 Err(ErrorContext::new_missing(
4183 "SetAttrs",
4184 "Flags",
4185 self.orig_loc,
4186 self.buf.as_ptr() as usize,
4187 ))
4188 }
4189 #[doc = "key data type, informational purpose only"]
4190 pub fn get_key_type(&self) -> Result<u32, ErrorContext> {
4191 let mut iter = self.clone();
4192 iter.pos = 0;
4193 for attr in iter {
4194 if let SetAttrs::KeyType(val) = attr? {
4195 return Ok(val);
4196 }
4197 }
4198 Err(ErrorContext::new_missing(
4199 "SetAttrs",
4200 "KeyType",
4201 self.orig_loc,
4202 self.buf.as_ptr() as usize,
4203 ))
4204 }
4205 #[doc = "key data length"]
4206 pub fn get_key_len(&self) -> Result<u32, ErrorContext> {
4207 let mut iter = self.clone();
4208 iter.pos = 0;
4209 for attr in iter {
4210 if let SetAttrs::KeyLen(val) = attr? {
4211 return Ok(val);
4212 }
4213 }
4214 Err(ErrorContext::new_missing(
4215 "SetAttrs",
4216 "KeyLen",
4217 self.orig_loc,
4218 self.buf.as_ptr() as usize,
4219 ))
4220 }
4221 #[doc = "mapping data type"]
4222 pub fn get_data_type(&self) -> Result<u32, ErrorContext> {
4223 let mut iter = self.clone();
4224 iter.pos = 0;
4225 for attr in iter {
4226 if let SetAttrs::DataType(val) = attr? {
4227 return Ok(val);
4228 }
4229 }
4230 Err(ErrorContext::new_missing(
4231 "SetAttrs",
4232 "DataType",
4233 self.orig_loc,
4234 self.buf.as_ptr() as usize,
4235 ))
4236 }
4237 #[doc = "mapping data length"]
4238 pub fn get_data_len(&self) -> Result<u32, ErrorContext> {
4239 let mut iter = self.clone();
4240 iter.pos = 0;
4241 for attr in iter {
4242 if let SetAttrs::DataLen(val) = attr? {
4243 return Ok(val);
4244 }
4245 }
4246 Err(ErrorContext::new_missing(
4247 "SetAttrs",
4248 "DataLen",
4249 self.orig_loc,
4250 self.buf.as_ptr() as usize,
4251 ))
4252 }
4253 #[doc = "selection policy"]
4254 pub fn get_policy(&self) -> Result<u32, ErrorContext> {
4255 let mut iter = self.clone();
4256 iter.pos = 0;
4257 for attr in iter {
4258 if let SetAttrs::Policy(val) = attr? {
4259 return Ok(val);
4260 }
4261 }
4262 Err(ErrorContext::new_missing(
4263 "SetAttrs",
4264 "Policy",
4265 self.orig_loc,
4266 self.buf.as_ptr() as usize,
4267 ))
4268 }
4269 #[doc = "set description"]
4270 pub fn get_desc(&self) -> Result<IterableSetDescAttrs<'a>, ErrorContext> {
4271 let mut iter = self.clone();
4272 iter.pos = 0;
4273 for attr in iter {
4274 if let SetAttrs::Desc(val) = attr? {
4275 return Ok(val);
4276 }
4277 }
4278 Err(ErrorContext::new_missing(
4279 "SetAttrs",
4280 "Desc",
4281 self.orig_loc,
4282 self.buf.as_ptr() as usize,
4283 ))
4284 }
4285 #[doc = "uniquely identifies a set in a transaction"]
4286 pub fn get_id(&self) -> Result<u32, ErrorContext> {
4287 let mut iter = self.clone();
4288 iter.pos = 0;
4289 for attr in iter {
4290 if let SetAttrs::Id(val) = attr? {
4291 return Ok(val);
4292 }
4293 }
4294 Err(ErrorContext::new_missing(
4295 "SetAttrs",
4296 "Id",
4297 self.orig_loc,
4298 self.buf.as_ptr() as usize,
4299 ))
4300 }
4301 #[doc = "default timeout value"]
4302 pub fn get_timeout(&self) -> Result<u64, ErrorContext> {
4303 let mut iter = self.clone();
4304 iter.pos = 0;
4305 for attr in iter {
4306 if let SetAttrs::Timeout(val) = attr? {
4307 return Ok(val);
4308 }
4309 }
4310 Err(ErrorContext::new_missing(
4311 "SetAttrs",
4312 "Timeout",
4313 self.orig_loc,
4314 self.buf.as_ptr() as usize,
4315 ))
4316 }
4317 #[doc = "garbage collection interval"]
4318 pub fn get_gc_interval(&self) -> Result<u32, ErrorContext> {
4319 let mut iter = self.clone();
4320 iter.pos = 0;
4321 for attr in iter {
4322 if let SetAttrs::GcInterval(val) = attr? {
4323 return Ok(val);
4324 }
4325 }
4326 Err(ErrorContext::new_missing(
4327 "SetAttrs",
4328 "GcInterval",
4329 self.orig_loc,
4330 self.buf.as_ptr() as usize,
4331 ))
4332 }
4333 #[doc = "user data"]
4334 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
4335 let mut iter = self.clone();
4336 iter.pos = 0;
4337 for attr in iter {
4338 if let SetAttrs::Userdata(val) = attr? {
4339 return Ok(val);
4340 }
4341 }
4342 Err(ErrorContext::new_missing(
4343 "SetAttrs",
4344 "Userdata",
4345 self.orig_loc,
4346 self.buf.as_ptr() as usize,
4347 ))
4348 }
4349 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
4350 let mut iter = self.clone();
4351 iter.pos = 0;
4352 for attr in iter {
4353 if let SetAttrs::Pad(val) = attr? {
4354 return Ok(val);
4355 }
4356 }
4357 Err(ErrorContext::new_missing(
4358 "SetAttrs",
4359 "Pad",
4360 self.orig_loc,
4361 self.buf.as_ptr() as usize,
4362 ))
4363 }
4364 #[doc = "stateful object type"]
4365 pub fn get_obj_type(&self) -> Result<u32, ErrorContext> {
4366 let mut iter = self.clone();
4367 iter.pos = 0;
4368 for attr in iter {
4369 if let SetAttrs::ObjType(val) = attr? {
4370 return Ok(val);
4371 }
4372 }
4373 Err(ErrorContext::new_missing(
4374 "SetAttrs",
4375 "ObjType",
4376 self.orig_loc,
4377 self.buf.as_ptr() as usize,
4378 ))
4379 }
4380 #[doc = "set handle"]
4381 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
4382 let mut iter = self.clone();
4383 iter.pos = 0;
4384 for attr in iter {
4385 if let SetAttrs::Handle(val) = attr? {
4386 return Ok(val);
4387 }
4388 }
4389 Err(ErrorContext::new_missing(
4390 "SetAttrs",
4391 "Handle",
4392 self.orig_loc,
4393 self.buf.as_ptr() as usize,
4394 ))
4395 }
4396 #[doc = "set expression\nAttribute may repeat multiple times (treat it as array)"]
4397 pub fn get_expr(&self) -> MultiAttrIterable<Self, SetAttrs<'a>, IterableExprAttrs<'a>> {
4398 MultiAttrIterable::new(self.clone(), |variant| {
4399 if let SetAttrs::Expr(val) = variant {
4400 Some(val)
4401 } else {
4402 None
4403 }
4404 })
4405 }
4406 #[doc = "list of expressions"]
4407 pub fn get_expressions(&self) -> Result<IterableSetListAttrs<'a>, ErrorContext> {
4408 let mut iter = self.clone();
4409 iter.pos = 0;
4410 for attr in iter {
4411 if let SetAttrs::Expressions(val) = attr? {
4412 return Ok(val);
4413 }
4414 }
4415 Err(ErrorContext::new_missing(
4416 "SetAttrs",
4417 "Expressions",
4418 self.orig_loc,
4419 self.buf.as_ptr() as usize,
4420 ))
4421 }
4422 #[doc = "set backend type"]
4423 pub fn get_type(&self) -> Result<&'a CStr, ErrorContext> {
4424 let mut iter = self.clone();
4425 iter.pos = 0;
4426 for attr in iter {
4427 if let SetAttrs::Type(val) = attr? {
4428 return Ok(val);
4429 }
4430 }
4431 Err(ErrorContext::new_missing(
4432 "SetAttrs",
4433 "Type",
4434 self.orig_loc,
4435 self.buf.as_ptr() as usize,
4436 ))
4437 }
4438 #[doc = "number of set elements"]
4439 pub fn get_count(&self) -> Result<u32, ErrorContext> {
4440 let mut iter = self.clone();
4441 iter.pos = 0;
4442 for attr in iter {
4443 if let SetAttrs::Count(val) = attr? {
4444 return Ok(val);
4445 }
4446 }
4447 Err(ErrorContext::new_missing(
4448 "SetAttrs",
4449 "Count",
4450 self.orig_loc,
4451 self.buf.as_ptr() as usize,
4452 ))
4453 }
4454}
4455impl<'a> SetAttrs<'a> {
4456 pub fn new(buf: &'a [u8]) -> IterableSetAttrs<'a> {
4457 IterableSetAttrs::with_loc(buf, buf.as_ptr() as usize)
4458 }
4459 fn attr_from_type(r#type: u16) -> Option<&'static str> {
4460 let res = match r#type {
4461 1u16 => "Table",
4462 2u16 => "Name",
4463 3u16 => "Flags",
4464 4u16 => "KeyType",
4465 5u16 => "KeyLen",
4466 6u16 => "DataType",
4467 7u16 => "DataLen",
4468 8u16 => "Policy",
4469 9u16 => "Desc",
4470 10u16 => "Id",
4471 11u16 => "Timeout",
4472 12u16 => "GcInterval",
4473 13u16 => "Userdata",
4474 14u16 => "Pad",
4475 15u16 => "ObjType",
4476 16u16 => "Handle",
4477 17u16 => "Expr",
4478 18u16 => "Expressions",
4479 19u16 => "Type",
4480 20u16 => "Count",
4481 _ => return None,
4482 };
4483 Some(res)
4484 }
4485}
4486#[derive(Clone, Copy, Default)]
4487pub struct IterableSetAttrs<'a> {
4488 buf: &'a [u8],
4489 pos: usize,
4490 orig_loc: usize,
4491}
4492impl<'a> IterableSetAttrs<'a> {
4493 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
4494 Self {
4495 buf,
4496 pos: 0,
4497 orig_loc,
4498 }
4499 }
4500 pub fn get_buf(&self) -> &'a [u8] {
4501 self.buf
4502 }
4503}
4504impl<'a> Iterator for IterableSetAttrs<'a> {
4505 type Item = Result<SetAttrs<'a>, ErrorContext>;
4506 fn next(&mut self) -> Option<Self::Item> {
4507 if self.buf.len() == self.pos {
4508 return None;
4509 }
4510 let pos = self.pos;
4511 let mut r#type = None;
4512 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
4513 r#type = Some(header.r#type);
4514 let res = match header.r#type {
4515 1u16 => SetAttrs::Table({
4516 let res = CStr::from_bytes_with_nul(next).ok();
4517 let Some(val) = res else { break };
4518 val
4519 }),
4520 2u16 => SetAttrs::Name({
4521 let res = CStr::from_bytes_with_nul(next).ok();
4522 let Some(val) = res else { break };
4523 val
4524 }),
4525 3u16 => SetAttrs::Flags({
4526 let res = parse_be_u32(next);
4527 let Some(val) = res else { break };
4528 val
4529 }),
4530 4u16 => SetAttrs::KeyType({
4531 let res = parse_be_u32(next);
4532 let Some(val) = res else { break };
4533 val
4534 }),
4535 5u16 => SetAttrs::KeyLen({
4536 let res = parse_be_u32(next);
4537 let Some(val) = res else { break };
4538 val
4539 }),
4540 6u16 => SetAttrs::DataType({
4541 let res = parse_be_u32(next);
4542 let Some(val) = res else { break };
4543 val
4544 }),
4545 7u16 => SetAttrs::DataLen({
4546 let res = parse_be_u32(next);
4547 let Some(val) = res else { break };
4548 val
4549 }),
4550 8u16 => SetAttrs::Policy({
4551 let res = parse_be_u32(next);
4552 let Some(val) = res else { break };
4553 val
4554 }),
4555 9u16 => SetAttrs::Desc({
4556 let res = Some(IterableSetDescAttrs::with_loc(next, self.orig_loc));
4557 let Some(val) = res else { break };
4558 val
4559 }),
4560 10u16 => SetAttrs::Id({
4561 let res = parse_u32(next);
4562 let Some(val) = res else { break };
4563 val
4564 }),
4565 11u16 => SetAttrs::Timeout({
4566 let res = parse_u64(next);
4567 let Some(val) = res else { break };
4568 val
4569 }),
4570 12u16 => SetAttrs::GcInterval({
4571 let res = parse_u32(next);
4572 let Some(val) = res else { break };
4573 val
4574 }),
4575 13u16 => SetAttrs::Userdata({
4576 let res = Some(next);
4577 let Some(val) = res else { break };
4578 val
4579 }),
4580 14u16 => SetAttrs::Pad({
4581 let res = Some(next);
4582 let Some(val) = res else { break };
4583 val
4584 }),
4585 15u16 => SetAttrs::ObjType({
4586 let res = parse_be_u32(next);
4587 let Some(val) = res else { break };
4588 val
4589 }),
4590 16u16 => SetAttrs::Handle({
4591 let res = parse_be_u64(next);
4592 let Some(val) = res else { break };
4593 val
4594 }),
4595 17u16 => SetAttrs::Expr({
4596 let res = Some(IterableExprAttrs::with_loc(next, self.orig_loc));
4597 let Some(val) = res else { break };
4598 val
4599 }),
4600 18u16 => SetAttrs::Expressions({
4601 let res = Some(IterableSetListAttrs::with_loc(next, self.orig_loc));
4602 let Some(val) = res else { break };
4603 val
4604 }),
4605 19u16 => SetAttrs::Type({
4606 let res = CStr::from_bytes_with_nul(next).ok();
4607 let Some(val) = res else { break };
4608 val
4609 }),
4610 20u16 => SetAttrs::Count({
4611 let res = parse_be_u32(next);
4612 let Some(val) = res else { break };
4613 val
4614 }),
4615 n => {
4616 if cfg!(any(test, feature = "deny-unknown-attrs")) {
4617 break;
4618 } else {
4619 continue;
4620 }
4621 }
4622 };
4623 return Some(Ok(res));
4624 }
4625 Some(Err(ErrorContext::new(
4626 "SetAttrs",
4627 r#type.and_then(|t| SetAttrs::attr_from_type(t)),
4628 self.orig_loc,
4629 self.buf.as_ptr().wrapping_add(pos) as usize,
4630 )))
4631 }
4632}
4633impl<'a> std::fmt::Debug for IterableSetAttrs<'_> {
4634 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4635 let mut fmt = f.debug_struct("SetAttrs");
4636 for attr in self.clone() {
4637 let attr = match attr {
4638 Ok(a) => a,
4639 Err(err) => {
4640 fmt.finish()?;
4641 f.write_str("Err(")?;
4642 err.fmt(f)?;
4643 return f.write_str(")");
4644 }
4645 };
4646 match attr {
4647 SetAttrs::Table(val) => fmt.field("Table", &val),
4648 SetAttrs::Name(val) => fmt.field("Name", &val),
4649 SetAttrs::Flags(val) => {
4650 fmt.field("Flags", &FormatFlags(val.into(), SetFlags::from_value))
4651 }
4652 SetAttrs::KeyType(val) => fmt.field("KeyType", &val),
4653 SetAttrs::KeyLen(val) => fmt.field("KeyLen", &val),
4654 SetAttrs::DataType(val) => fmt.field("DataType", &val),
4655 SetAttrs::DataLen(val) => fmt.field("DataLen", &val),
4656 SetAttrs::Policy(val) => fmt.field("Policy", &val),
4657 SetAttrs::Desc(val) => fmt.field("Desc", &val),
4658 SetAttrs::Id(val) => fmt.field("Id", &val),
4659 SetAttrs::Timeout(val) => fmt.field("Timeout", &val),
4660 SetAttrs::GcInterval(val) => fmt.field("GcInterval", &val),
4661 SetAttrs::Userdata(val) => fmt.field("Userdata", &val),
4662 SetAttrs::Pad(val) => fmt.field("Pad", &val),
4663 SetAttrs::ObjType(val) => fmt.field("ObjType", &val),
4664 SetAttrs::Handle(val) => fmt.field("Handle", &val),
4665 SetAttrs::Expr(val) => fmt.field("Expr", &val),
4666 SetAttrs::Expressions(val) => fmt.field("Expressions", &val),
4667 SetAttrs::Type(val) => fmt.field("Type", &val),
4668 SetAttrs::Count(val) => fmt.field("Count", &val),
4669 };
4670 }
4671 fmt.finish()
4672 }
4673}
4674impl IterableSetAttrs<'_> {
4675 pub fn lookup_attr(
4676 &self,
4677 offset: usize,
4678 missing_type: Option<u16>,
4679 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
4680 let mut stack = Vec::new();
4681 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
4682 if cur == offset {
4683 stack.push(("SetAttrs", offset));
4684 return (
4685 stack,
4686 missing_type.and_then(|t| SetAttrs::attr_from_type(t)),
4687 );
4688 }
4689 if cur > offset || cur + self.buf.len() < offset {
4690 return (stack, None);
4691 }
4692 let mut attrs = self.clone();
4693 let mut last_off = cur + attrs.pos;
4694 let mut missing = None;
4695 while let Some(attr) = attrs.next() {
4696 let Ok(attr) = attr else { break };
4697 match attr {
4698 SetAttrs::Table(val) => {
4699 if last_off == offset {
4700 stack.push(("Table", last_off));
4701 break;
4702 }
4703 }
4704 SetAttrs::Name(val) => {
4705 if last_off == offset {
4706 stack.push(("Name", last_off));
4707 break;
4708 }
4709 }
4710 SetAttrs::Flags(val) => {
4711 if last_off == offset {
4712 stack.push(("Flags", last_off));
4713 break;
4714 }
4715 }
4716 SetAttrs::KeyType(val) => {
4717 if last_off == offset {
4718 stack.push(("KeyType", last_off));
4719 break;
4720 }
4721 }
4722 SetAttrs::KeyLen(val) => {
4723 if last_off == offset {
4724 stack.push(("KeyLen", last_off));
4725 break;
4726 }
4727 }
4728 SetAttrs::DataType(val) => {
4729 if last_off == offset {
4730 stack.push(("DataType", last_off));
4731 break;
4732 }
4733 }
4734 SetAttrs::DataLen(val) => {
4735 if last_off == offset {
4736 stack.push(("DataLen", last_off));
4737 break;
4738 }
4739 }
4740 SetAttrs::Policy(val) => {
4741 if last_off == offset {
4742 stack.push(("Policy", last_off));
4743 break;
4744 }
4745 }
4746 SetAttrs::Desc(val) => {
4747 (stack, missing) = val.lookup_attr(offset, missing_type);
4748 if !stack.is_empty() {
4749 break;
4750 }
4751 }
4752 SetAttrs::Id(val) => {
4753 if last_off == offset {
4754 stack.push(("Id", last_off));
4755 break;
4756 }
4757 }
4758 SetAttrs::Timeout(val) => {
4759 if last_off == offset {
4760 stack.push(("Timeout", last_off));
4761 break;
4762 }
4763 }
4764 SetAttrs::GcInterval(val) => {
4765 if last_off == offset {
4766 stack.push(("GcInterval", last_off));
4767 break;
4768 }
4769 }
4770 SetAttrs::Userdata(val) => {
4771 if last_off == offset {
4772 stack.push(("Userdata", last_off));
4773 break;
4774 }
4775 }
4776 SetAttrs::Pad(val) => {
4777 if last_off == offset {
4778 stack.push(("Pad", last_off));
4779 break;
4780 }
4781 }
4782 SetAttrs::ObjType(val) => {
4783 if last_off == offset {
4784 stack.push(("ObjType", last_off));
4785 break;
4786 }
4787 }
4788 SetAttrs::Handle(val) => {
4789 if last_off == offset {
4790 stack.push(("Handle", last_off));
4791 break;
4792 }
4793 }
4794 SetAttrs::Expr(val) => {
4795 (stack, missing) = val.lookup_attr(offset, missing_type);
4796 if !stack.is_empty() {
4797 break;
4798 }
4799 }
4800 SetAttrs::Expressions(val) => {
4801 (stack, missing) = val.lookup_attr(offset, missing_type);
4802 if !stack.is_empty() {
4803 break;
4804 }
4805 }
4806 SetAttrs::Type(val) => {
4807 if last_off == offset {
4808 stack.push(("Type", last_off));
4809 break;
4810 }
4811 }
4812 SetAttrs::Count(val) => {
4813 if last_off == offset {
4814 stack.push(("Count", last_off));
4815 break;
4816 }
4817 }
4818 _ => {}
4819 };
4820 last_off = cur + attrs.pos;
4821 }
4822 if !stack.is_empty() {
4823 stack.push(("SetAttrs", cur));
4824 }
4825 (stack, missing)
4826 }
4827}
4828#[derive(Clone)]
4829pub enum SetDescAttrs<'a> {
4830 #[doc = "number of elements in set"]
4831 Size(u32),
4832 #[doc = "description of field concatenation\nAttribute may repeat multiple times (treat it as array)"]
4833 Concat(IterableSetDescConcatAttrs<'a>),
4834}
4835impl<'a> IterableSetDescAttrs<'a> {
4836 #[doc = "number of elements in set"]
4837 pub fn get_size(&self) -> Result<u32, ErrorContext> {
4838 let mut iter = self.clone();
4839 iter.pos = 0;
4840 for attr in iter {
4841 if let SetDescAttrs::Size(val) = attr? {
4842 return Ok(val);
4843 }
4844 }
4845 Err(ErrorContext::new_missing(
4846 "SetDescAttrs",
4847 "Size",
4848 self.orig_loc,
4849 self.buf.as_ptr() as usize,
4850 ))
4851 }
4852 #[doc = "description of field concatenation\nAttribute may repeat multiple times (treat it as array)"]
4853 pub fn get_concat(
4854 &self,
4855 ) -> MultiAttrIterable<Self, SetDescAttrs<'a>, IterableSetDescConcatAttrs<'a>> {
4856 MultiAttrIterable::new(self.clone(), |variant| {
4857 if let SetDescAttrs::Concat(val) = variant {
4858 Some(val)
4859 } else {
4860 None
4861 }
4862 })
4863 }
4864}
4865impl<'a> SetDescAttrs<'a> {
4866 pub fn new(buf: &'a [u8]) -> IterableSetDescAttrs<'a> {
4867 IterableSetDescAttrs::with_loc(buf, buf.as_ptr() as usize)
4868 }
4869 fn attr_from_type(r#type: u16) -> Option<&'static str> {
4870 let res = match r#type {
4871 1u16 => "Size",
4872 2u16 => "Concat",
4873 _ => return None,
4874 };
4875 Some(res)
4876 }
4877}
4878#[derive(Clone, Copy, Default)]
4879pub struct IterableSetDescAttrs<'a> {
4880 buf: &'a [u8],
4881 pos: usize,
4882 orig_loc: usize,
4883}
4884impl<'a> IterableSetDescAttrs<'a> {
4885 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
4886 Self {
4887 buf,
4888 pos: 0,
4889 orig_loc,
4890 }
4891 }
4892 pub fn get_buf(&self) -> &'a [u8] {
4893 self.buf
4894 }
4895}
4896impl<'a> Iterator for IterableSetDescAttrs<'a> {
4897 type Item = Result<SetDescAttrs<'a>, ErrorContext>;
4898 fn next(&mut self) -> Option<Self::Item> {
4899 if self.buf.len() == self.pos {
4900 return None;
4901 }
4902 let pos = self.pos;
4903 let mut r#type = None;
4904 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
4905 r#type = Some(header.r#type);
4906 let res = match header.r#type {
4907 1u16 => SetDescAttrs::Size({
4908 let res = parse_be_u32(next);
4909 let Some(val) = res else { break };
4910 val
4911 }),
4912 2u16 => SetDescAttrs::Concat({
4913 let res = Some(IterableSetDescConcatAttrs::with_loc(next, self.orig_loc));
4914 let Some(val) = res else { break };
4915 val
4916 }),
4917 n => {
4918 if cfg!(any(test, feature = "deny-unknown-attrs")) {
4919 break;
4920 } else {
4921 continue;
4922 }
4923 }
4924 };
4925 return Some(Ok(res));
4926 }
4927 Some(Err(ErrorContext::new(
4928 "SetDescAttrs",
4929 r#type.and_then(|t| SetDescAttrs::attr_from_type(t)),
4930 self.orig_loc,
4931 self.buf.as_ptr().wrapping_add(pos) as usize,
4932 )))
4933 }
4934}
4935impl<'a> std::fmt::Debug for IterableSetDescAttrs<'_> {
4936 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4937 let mut fmt = f.debug_struct("SetDescAttrs");
4938 for attr in self.clone() {
4939 let attr = match attr {
4940 Ok(a) => a,
4941 Err(err) => {
4942 fmt.finish()?;
4943 f.write_str("Err(")?;
4944 err.fmt(f)?;
4945 return f.write_str(")");
4946 }
4947 };
4948 match attr {
4949 SetDescAttrs::Size(val) => fmt.field("Size", &val),
4950 SetDescAttrs::Concat(val) => fmt.field("Concat", &val),
4951 };
4952 }
4953 fmt.finish()
4954 }
4955}
4956impl IterableSetDescAttrs<'_> {
4957 pub fn lookup_attr(
4958 &self,
4959 offset: usize,
4960 missing_type: Option<u16>,
4961 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
4962 let mut stack = Vec::new();
4963 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
4964 if cur == offset {
4965 stack.push(("SetDescAttrs", offset));
4966 return (
4967 stack,
4968 missing_type.and_then(|t| SetDescAttrs::attr_from_type(t)),
4969 );
4970 }
4971 if cur > offset || cur + self.buf.len() < offset {
4972 return (stack, None);
4973 }
4974 let mut attrs = self.clone();
4975 let mut last_off = cur + attrs.pos;
4976 let mut missing = None;
4977 while let Some(attr) = attrs.next() {
4978 let Ok(attr) = attr else { break };
4979 match attr {
4980 SetDescAttrs::Size(val) => {
4981 if last_off == offset {
4982 stack.push(("Size", last_off));
4983 break;
4984 }
4985 }
4986 SetDescAttrs::Concat(val) => {
4987 (stack, missing) = val.lookup_attr(offset, missing_type);
4988 if !stack.is_empty() {
4989 break;
4990 }
4991 }
4992 _ => {}
4993 };
4994 last_off = cur + attrs.pos;
4995 }
4996 if !stack.is_empty() {
4997 stack.push(("SetDescAttrs", cur));
4998 }
4999 (stack, missing)
5000 }
5001}
5002#[derive(Clone)]
5003pub enum SetDescConcatAttrs<'a> {
5004 Elem(IterableSetFieldAttrs<'a>),
5005}
5006impl<'a> IterableSetDescConcatAttrs<'a> {
5007 pub fn get_elem(&self) -> Result<IterableSetFieldAttrs<'a>, ErrorContext> {
5008 let mut iter = self.clone();
5009 iter.pos = 0;
5010 for attr in iter {
5011 if let SetDescConcatAttrs::Elem(val) = attr? {
5012 return Ok(val);
5013 }
5014 }
5015 Err(ErrorContext::new_missing(
5016 "SetDescConcatAttrs",
5017 "Elem",
5018 self.orig_loc,
5019 self.buf.as_ptr() as usize,
5020 ))
5021 }
5022}
5023impl<'a> SetDescConcatAttrs<'a> {
5024 pub fn new(buf: &'a [u8]) -> IterableSetDescConcatAttrs<'a> {
5025 IterableSetDescConcatAttrs::with_loc(buf, buf.as_ptr() as usize)
5026 }
5027 fn attr_from_type(r#type: u16) -> Option<&'static str> {
5028 let res = match r#type {
5029 1u16 => "Elem",
5030 _ => return None,
5031 };
5032 Some(res)
5033 }
5034}
5035#[derive(Clone, Copy, Default)]
5036pub struct IterableSetDescConcatAttrs<'a> {
5037 buf: &'a [u8],
5038 pos: usize,
5039 orig_loc: usize,
5040}
5041impl<'a> IterableSetDescConcatAttrs<'a> {
5042 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5043 Self {
5044 buf,
5045 pos: 0,
5046 orig_loc,
5047 }
5048 }
5049 pub fn get_buf(&self) -> &'a [u8] {
5050 self.buf
5051 }
5052}
5053impl<'a> Iterator for IterableSetDescConcatAttrs<'a> {
5054 type Item = Result<SetDescConcatAttrs<'a>, ErrorContext>;
5055 fn next(&mut self) -> Option<Self::Item> {
5056 if self.buf.len() == self.pos {
5057 return None;
5058 }
5059 let pos = self.pos;
5060 let mut r#type = None;
5061 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
5062 r#type = Some(header.r#type);
5063 let res = match header.r#type {
5064 1u16 => SetDescConcatAttrs::Elem({
5065 let res = Some(IterableSetFieldAttrs::with_loc(next, self.orig_loc));
5066 let Some(val) = res else { break };
5067 val
5068 }),
5069 n => {
5070 if cfg!(any(test, feature = "deny-unknown-attrs")) {
5071 break;
5072 } else {
5073 continue;
5074 }
5075 }
5076 };
5077 return Some(Ok(res));
5078 }
5079 Some(Err(ErrorContext::new(
5080 "SetDescConcatAttrs",
5081 r#type.and_then(|t| SetDescConcatAttrs::attr_from_type(t)),
5082 self.orig_loc,
5083 self.buf.as_ptr().wrapping_add(pos) as usize,
5084 )))
5085 }
5086}
5087impl<'a> std::fmt::Debug for IterableSetDescConcatAttrs<'_> {
5088 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5089 let mut fmt = f.debug_struct("SetDescConcatAttrs");
5090 for attr in self.clone() {
5091 let attr = match attr {
5092 Ok(a) => a,
5093 Err(err) => {
5094 fmt.finish()?;
5095 f.write_str("Err(")?;
5096 err.fmt(f)?;
5097 return f.write_str(")");
5098 }
5099 };
5100 match attr {
5101 SetDescConcatAttrs::Elem(val) => fmt.field("Elem", &val),
5102 };
5103 }
5104 fmt.finish()
5105 }
5106}
5107impl IterableSetDescConcatAttrs<'_> {
5108 pub fn lookup_attr(
5109 &self,
5110 offset: usize,
5111 missing_type: Option<u16>,
5112 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5113 let mut stack = Vec::new();
5114 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
5115 if cur == offset {
5116 stack.push(("SetDescConcatAttrs", offset));
5117 return (
5118 stack,
5119 missing_type.and_then(|t| SetDescConcatAttrs::attr_from_type(t)),
5120 );
5121 }
5122 if cur > offset || cur + self.buf.len() < offset {
5123 return (stack, None);
5124 }
5125 let mut attrs = self.clone();
5126 let mut last_off = cur + attrs.pos;
5127 let mut missing = None;
5128 while let Some(attr) = attrs.next() {
5129 let Ok(attr) = attr else { break };
5130 match attr {
5131 SetDescConcatAttrs::Elem(val) => {
5132 (stack, missing) = val.lookup_attr(offset, missing_type);
5133 if !stack.is_empty() {
5134 break;
5135 }
5136 }
5137 _ => {}
5138 };
5139 last_off = cur + attrs.pos;
5140 }
5141 if !stack.is_empty() {
5142 stack.push(("SetDescConcatAttrs", cur));
5143 }
5144 (stack, missing)
5145 }
5146}
5147#[derive(Clone)]
5148pub enum SetFieldAttrs {
5149 Len(u32),
5150}
5151impl<'a> IterableSetFieldAttrs<'a> {
5152 pub fn get_len(&self) -> Result<u32, ErrorContext> {
5153 let mut iter = self.clone();
5154 iter.pos = 0;
5155 for attr in iter {
5156 if let SetFieldAttrs::Len(val) = attr? {
5157 return Ok(val);
5158 }
5159 }
5160 Err(ErrorContext::new_missing(
5161 "SetFieldAttrs",
5162 "Len",
5163 self.orig_loc,
5164 self.buf.as_ptr() as usize,
5165 ))
5166 }
5167}
5168impl SetFieldAttrs {
5169 pub fn new(buf: &'_ [u8]) -> IterableSetFieldAttrs<'_> {
5170 IterableSetFieldAttrs::with_loc(buf, buf.as_ptr() as usize)
5171 }
5172 fn attr_from_type(r#type: u16) -> Option<&'static str> {
5173 let res = match r#type {
5174 1u16 => "Len",
5175 _ => return None,
5176 };
5177 Some(res)
5178 }
5179}
5180#[derive(Clone, Copy, Default)]
5181pub struct IterableSetFieldAttrs<'a> {
5182 buf: &'a [u8],
5183 pos: usize,
5184 orig_loc: usize,
5185}
5186impl<'a> IterableSetFieldAttrs<'a> {
5187 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5188 Self {
5189 buf,
5190 pos: 0,
5191 orig_loc,
5192 }
5193 }
5194 pub fn get_buf(&self) -> &'a [u8] {
5195 self.buf
5196 }
5197}
5198impl<'a> Iterator for IterableSetFieldAttrs<'a> {
5199 type Item = Result<SetFieldAttrs, ErrorContext>;
5200 fn next(&mut self) -> Option<Self::Item> {
5201 if self.buf.len() == self.pos {
5202 return None;
5203 }
5204 let pos = self.pos;
5205 let mut r#type = None;
5206 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
5207 r#type = Some(header.r#type);
5208 let res = match header.r#type {
5209 1u16 => SetFieldAttrs::Len({
5210 let res = parse_be_u32(next);
5211 let Some(val) = res else { break };
5212 val
5213 }),
5214 n => {
5215 if cfg!(any(test, feature = "deny-unknown-attrs")) {
5216 break;
5217 } else {
5218 continue;
5219 }
5220 }
5221 };
5222 return Some(Ok(res));
5223 }
5224 Some(Err(ErrorContext::new(
5225 "SetFieldAttrs",
5226 r#type.and_then(|t| SetFieldAttrs::attr_from_type(t)),
5227 self.orig_loc,
5228 self.buf.as_ptr().wrapping_add(pos) as usize,
5229 )))
5230 }
5231}
5232impl std::fmt::Debug for IterableSetFieldAttrs<'_> {
5233 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5234 let mut fmt = f.debug_struct("SetFieldAttrs");
5235 for attr in self.clone() {
5236 let attr = match attr {
5237 Ok(a) => a,
5238 Err(err) => {
5239 fmt.finish()?;
5240 f.write_str("Err(")?;
5241 err.fmt(f)?;
5242 return f.write_str(")");
5243 }
5244 };
5245 match attr {
5246 SetFieldAttrs::Len(val) => fmt.field("Len", &val),
5247 };
5248 }
5249 fmt.finish()
5250 }
5251}
5252impl IterableSetFieldAttrs<'_> {
5253 pub fn lookup_attr(
5254 &self,
5255 offset: usize,
5256 missing_type: Option<u16>,
5257 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5258 let mut stack = Vec::new();
5259 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
5260 if cur == offset {
5261 stack.push(("SetFieldAttrs", offset));
5262 return (
5263 stack,
5264 missing_type.and_then(|t| SetFieldAttrs::attr_from_type(t)),
5265 );
5266 }
5267 if cur > offset || cur + self.buf.len() < offset {
5268 return (stack, None);
5269 }
5270 let mut attrs = self.clone();
5271 let mut last_off = cur + attrs.pos;
5272 while let Some(attr) = attrs.next() {
5273 let Ok(attr) = attr else { break };
5274 match attr {
5275 SetFieldAttrs::Len(val) => {
5276 if last_off == offset {
5277 stack.push(("Len", last_off));
5278 break;
5279 }
5280 }
5281 _ => {}
5282 };
5283 last_off = cur + attrs.pos;
5284 }
5285 if !stack.is_empty() {
5286 stack.push(("SetFieldAttrs", cur));
5287 }
5288 (stack, None)
5289 }
5290}
5291#[derive(Clone)]
5292pub enum SetListAttrs<'a> {
5293 #[doc = "Attribute may repeat multiple times (treat it as array)"]
5294 Elem(IterableExprAttrs<'a>),
5295}
5296impl<'a> IterableSetListAttrs<'a> {
5297 #[doc = "Attribute may repeat multiple times (treat it as array)"]
5298 pub fn get_elem(&self) -> MultiAttrIterable<Self, SetListAttrs<'a>, IterableExprAttrs<'a>> {
5299 MultiAttrIterable::new(self.clone(), |variant| {
5300 if let SetListAttrs::Elem(val) = variant {
5301 Some(val)
5302 } else {
5303 None
5304 }
5305 })
5306 }
5307}
5308impl<'a> SetListAttrs<'a> {
5309 pub fn new(buf: &'a [u8]) -> IterableSetListAttrs<'a> {
5310 IterableSetListAttrs::with_loc(buf, buf.as_ptr() as usize)
5311 }
5312 fn attr_from_type(r#type: u16) -> Option<&'static str> {
5313 let res = match r#type {
5314 1u16 => "Elem",
5315 _ => return None,
5316 };
5317 Some(res)
5318 }
5319}
5320#[derive(Clone, Copy, Default)]
5321pub struct IterableSetListAttrs<'a> {
5322 buf: &'a [u8],
5323 pos: usize,
5324 orig_loc: usize,
5325}
5326impl<'a> IterableSetListAttrs<'a> {
5327 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5328 Self {
5329 buf,
5330 pos: 0,
5331 orig_loc,
5332 }
5333 }
5334 pub fn get_buf(&self) -> &'a [u8] {
5335 self.buf
5336 }
5337}
5338impl<'a> Iterator for IterableSetListAttrs<'a> {
5339 type Item = Result<SetListAttrs<'a>, ErrorContext>;
5340 fn next(&mut self) -> Option<Self::Item> {
5341 if self.buf.len() == self.pos {
5342 return None;
5343 }
5344 let pos = self.pos;
5345 let mut r#type = None;
5346 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
5347 r#type = Some(header.r#type);
5348 let res = match header.r#type {
5349 1u16 => SetListAttrs::Elem({
5350 let res = Some(IterableExprAttrs::with_loc(next, self.orig_loc));
5351 let Some(val) = res else { break };
5352 val
5353 }),
5354 n => {
5355 if cfg!(any(test, feature = "deny-unknown-attrs")) {
5356 break;
5357 } else {
5358 continue;
5359 }
5360 }
5361 };
5362 return Some(Ok(res));
5363 }
5364 Some(Err(ErrorContext::new(
5365 "SetListAttrs",
5366 r#type.and_then(|t| SetListAttrs::attr_from_type(t)),
5367 self.orig_loc,
5368 self.buf.as_ptr().wrapping_add(pos) as usize,
5369 )))
5370 }
5371}
5372impl<'a> std::fmt::Debug for IterableSetListAttrs<'_> {
5373 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5374 let mut fmt = f.debug_struct("SetListAttrs");
5375 for attr in self.clone() {
5376 let attr = match attr {
5377 Ok(a) => a,
5378 Err(err) => {
5379 fmt.finish()?;
5380 f.write_str("Err(")?;
5381 err.fmt(f)?;
5382 return f.write_str(")");
5383 }
5384 };
5385 match attr {
5386 SetListAttrs::Elem(val) => fmt.field("Elem", &val),
5387 };
5388 }
5389 fmt.finish()
5390 }
5391}
5392impl IterableSetListAttrs<'_> {
5393 pub fn lookup_attr(
5394 &self,
5395 offset: usize,
5396 missing_type: Option<u16>,
5397 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5398 let mut stack = Vec::new();
5399 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
5400 if cur == offset {
5401 stack.push(("SetListAttrs", offset));
5402 return (
5403 stack,
5404 missing_type.and_then(|t| SetListAttrs::attr_from_type(t)),
5405 );
5406 }
5407 if cur > offset || cur + self.buf.len() < offset {
5408 return (stack, None);
5409 }
5410 let mut attrs = self.clone();
5411 let mut last_off = cur + attrs.pos;
5412 let mut missing = None;
5413 while let Some(attr) = attrs.next() {
5414 let Ok(attr) = attr else { break };
5415 match attr {
5416 SetListAttrs::Elem(val) => {
5417 (stack, missing) = val.lookup_attr(offset, missing_type);
5418 if !stack.is_empty() {
5419 break;
5420 }
5421 }
5422 _ => {}
5423 };
5424 last_off = cur + attrs.pos;
5425 }
5426 if !stack.is_empty() {
5427 stack.push(("SetListAttrs", cur));
5428 }
5429 (stack, missing)
5430 }
5431}
5432#[derive(Clone)]
5433pub enum SetelemAttrs<'a> {
5434 #[doc = "key value"]
5435 Key(IterableDataAttrs<'a>),
5436 #[doc = "data value of mapping"]
5437 Data(IterableDataAttrs<'a>),
5438 #[doc = "bitmask of nft_set_elem_flags"]
5439 Flags(&'a [u8]),
5440 #[doc = "timeout value"]
5441 Timeout(u64),
5442 #[doc = "expiration time"]
5443 Expiration(u64),
5444 #[doc = "user data"]
5445 Userdata(&'a [u8]),
5446 #[doc = "expression"]
5447 Expr(IterableExprAttrs<'a>),
5448 #[doc = "stateful object reference"]
5449 Objref(&'a CStr),
5450 #[doc = "closing key value"]
5451 KeyEnd(IterableDataAttrs<'a>),
5452 #[doc = "list of expressions"]
5453 Expressions(IterableExprListAttrs<'a>),
5454}
5455impl<'a> IterableSetelemAttrs<'a> {
5456 #[doc = "key value"]
5457 pub fn get_key(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
5458 let mut iter = self.clone();
5459 iter.pos = 0;
5460 for attr in iter {
5461 if let SetelemAttrs::Key(val) = attr? {
5462 return Ok(val);
5463 }
5464 }
5465 Err(ErrorContext::new_missing(
5466 "SetelemAttrs",
5467 "Key",
5468 self.orig_loc,
5469 self.buf.as_ptr() as usize,
5470 ))
5471 }
5472 #[doc = "data value of mapping"]
5473 pub fn get_data(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
5474 let mut iter = self.clone();
5475 iter.pos = 0;
5476 for attr in iter {
5477 if let SetelemAttrs::Data(val) = attr? {
5478 return Ok(val);
5479 }
5480 }
5481 Err(ErrorContext::new_missing(
5482 "SetelemAttrs",
5483 "Data",
5484 self.orig_loc,
5485 self.buf.as_ptr() as usize,
5486 ))
5487 }
5488 #[doc = "bitmask of nft_set_elem_flags"]
5489 pub fn get_flags(&self) -> Result<&'a [u8], ErrorContext> {
5490 let mut iter = self.clone();
5491 iter.pos = 0;
5492 for attr in iter {
5493 if let SetelemAttrs::Flags(val) = attr? {
5494 return Ok(val);
5495 }
5496 }
5497 Err(ErrorContext::new_missing(
5498 "SetelemAttrs",
5499 "Flags",
5500 self.orig_loc,
5501 self.buf.as_ptr() as usize,
5502 ))
5503 }
5504 #[doc = "timeout value"]
5505 pub fn get_timeout(&self) -> Result<u64, ErrorContext> {
5506 let mut iter = self.clone();
5507 iter.pos = 0;
5508 for attr in iter {
5509 if let SetelemAttrs::Timeout(val) = attr? {
5510 return Ok(val);
5511 }
5512 }
5513 Err(ErrorContext::new_missing(
5514 "SetelemAttrs",
5515 "Timeout",
5516 self.orig_loc,
5517 self.buf.as_ptr() as usize,
5518 ))
5519 }
5520 #[doc = "expiration time"]
5521 pub fn get_expiration(&self) -> Result<u64, ErrorContext> {
5522 let mut iter = self.clone();
5523 iter.pos = 0;
5524 for attr in iter {
5525 if let SetelemAttrs::Expiration(val) = attr? {
5526 return Ok(val);
5527 }
5528 }
5529 Err(ErrorContext::new_missing(
5530 "SetelemAttrs",
5531 "Expiration",
5532 self.orig_loc,
5533 self.buf.as_ptr() as usize,
5534 ))
5535 }
5536 #[doc = "user data"]
5537 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
5538 let mut iter = self.clone();
5539 iter.pos = 0;
5540 for attr in iter {
5541 if let SetelemAttrs::Userdata(val) = attr? {
5542 return Ok(val);
5543 }
5544 }
5545 Err(ErrorContext::new_missing(
5546 "SetelemAttrs",
5547 "Userdata",
5548 self.orig_loc,
5549 self.buf.as_ptr() as usize,
5550 ))
5551 }
5552 #[doc = "expression"]
5553 pub fn get_expr(&self) -> Result<IterableExprAttrs<'a>, ErrorContext> {
5554 let mut iter = self.clone();
5555 iter.pos = 0;
5556 for attr in iter {
5557 if let SetelemAttrs::Expr(val) = attr? {
5558 return Ok(val);
5559 }
5560 }
5561 Err(ErrorContext::new_missing(
5562 "SetelemAttrs",
5563 "Expr",
5564 self.orig_loc,
5565 self.buf.as_ptr() as usize,
5566 ))
5567 }
5568 #[doc = "stateful object reference"]
5569 pub fn get_objref(&self) -> Result<&'a CStr, ErrorContext> {
5570 let mut iter = self.clone();
5571 iter.pos = 0;
5572 for attr in iter {
5573 if let SetelemAttrs::Objref(val) = attr? {
5574 return Ok(val);
5575 }
5576 }
5577 Err(ErrorContext::new_missing(
5578 "SetelemAttrs",
5579 "Objref",
5580 self.orig_loc,
5581 self.buf.as_ptr() as usize,
5582 ))
5583 }
5584 #[doc = "closing key value"]
5585 pub fn get_key_end(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
5586 let mut iter = self.clone();
5587 iter.pos = 0;
5588 for attr in iter {
5589 if let SetelemAttrs::KeyEnd(val) = attr? {
5590 return Ok(val);
5591 }
5592 }
5593 Err(ErrorContext::new_missing(
5594 "SetelemAttrs",
5595 "KeyEnd",
5596 self.orig_loc,
5597 self.buf.as_ptr() as usize,
5598 ))
5599 }
5600 #[doc = "list of expressions"]
5601 pub fn get_expressions(&self) -> Result<IterableExprListAttrs<'a>, ErrorContext> {
5602 let mut iter = self.clone();
5603 iter.pos = 0;
5604 for attr in iter {
5605 if let SetelemAttrs::Expressions(val) = attr? {
5606 return Ok(val);
5607 }
5608 }
5609 Err(ErrorContext::new_missing(
5610 "SetelemAttrs",
5611 "Expressions",
5612 self.orig_loc,
5613 self.buf.as_ptr() as usize,
5614 ))
5615 }
5616}
5617impl<'a> SetelemAttrs<'a> {
5618 pub fn new(buf: &'a [u8]) -> IterableSetelemAttrs<'a> {
5619 IterableSetelemAttrs::with_loc(buf, buf.as_ptr() as usize)
5620 }
5621 fn attr_from_type(r#type: u16) -> Option<&'static str> {
5622 let res = match r#type {
5623 1u16 => "Key",
5624 2u16 => "Data",
5625 3u16 => "Flags",
5626 4u16 => "Timeout",
5627 5u16 => "Expiration",
5628 6u16 => "Userdata",
5629 7u16 => "Expr",
5630 8u16 => "Objref",
5631 9u16 => "KeyEnd",
5632 10u16 => "Expressions",
5633 _ => return None,
5634 };
5635 Some(res)
5636 }
5637}
5638#[derive(Clone, Copy, Default)]
5639pub struct IterableSetelemAttrs<'a> {
5640 buf: &'a [u8],
5641 pos: usize,
5642 orig_loc: usize,
5643}
5644impl<'a> IterableSetelemAttrs<'a> {
5645 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5646 Self {
5647 buf,
5648 pos: 0,
5649 orig_loc,
5650 }
5651 }
5652 pub fn get_buf(&self) -> &'a [u8] {
5653 self.buf
5654 }
5655}
5656impl<'a> Iterator for IterableSetelemAttrs<'a> {
5657 type Item = Result<SetelemAttrs<'a>, ErrorContext>;
5658 fn next(&mut self) -> Option<Self::Item> {
5659 if self.buf.len() == self.pos {
5660 return None;
5661 }
5662 let pos = self.pos;
5663 let mut r#type = None;
5664 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
5665 r#type = Some(header.r#type);
5666 let res = match header.r#type {
5667 1u16 => SetelemAttrs::Key({
5668 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
5669 let Some(val) = res else { break };
5670 val
5671 }),
5672 2u16 => SetelemAttrs::Data({
5673 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
5674 let Some(val) = res else { break };
5675 val
5676 }),
5677 3u16 => SetelemAttrs::Flags({
5678 let res = Some(next);
5679 let Some(val) = res else { break };
5680 val
5681 }),
5682 4u16 => SetelemAttrs::Timeout({
5683 let res = parse_u64(next);
5684 let Some(val) = res else { break };
5685 val
5686 }),
5687 5u16 => SetelemAttrs::Expiration({
5688 let res = parse_u64(next);
5689 let Some(val) = res else { break };
5690 val
5691 }),
5692 6u16 => SetelemAttrs::Userdata({
5693 let res = Some(next);
5694 let Some(val) = res else { break };
5695 val
5696 }),
5697 7u16 => SetelemAttrs::Expr({
5698 let res = Some(IterableExprAttrs::with_loc(next, self.orig_loc));
5699 let Some(val) = res else { break };
5700 val
5701 }),
5702 8u16 => SetelemAttrs::Objref({
5703 let res = CStr::from_bytes_with_nul(next).ok();
5704 let Some(val) = res else { break };
5705 val
5706 }),
5707 9u16 => SetelemAttrs::KeyEnd({
5708 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
5709 let Some(val) = res else { break };
5710 val
5711 }),
5712 10u16 => SetelemAttrs::Expressions({
5713 let res = Some(IterableExprListAttrs::with_loc(next, self.orig_loc));
5714 let Some(val) = res else { break };
5715 val
5716 }),
5717 n => {
5718 if cfg!(any(test, feature = "deny-unknown-attrs")) {
5719 break;
5720 } else {
5721 continue;
5722 }
5723 }
5724 };
5725 return Some(Ok(res));
5726 }
5727 Some(Err(ErrorContext::new(
5728 "SetelemAttrs",
5729 r#type.and_then(|t| SetelemAttrs::attr_from_type(t)),
5730 self.orig_loc,
5731 self.buf.as_ptr().wrapping_add(pos) as usize,
5732 )))
5733 }
5734}
5735impl<'a> std::fmt::Debug for IterableSetelemAttrs<'_> {
5736 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5737 let mut fmt = f.debug_struct("SetelemAttrs");
5738 for attr in self.clone() {
5739 let attr = match attr {
5740 Ok(a) => a,
5741 Err(err) => {
5742 fmt.finish()?;
5743 f.write_str("Err(")?;
5744 err.fmt(f)?;
5745 return f.write_str(")");
5746 }
5747 };
5748 match attr {
5749 SetelemAttrs::Key(val) => fmt.field("Key", &val),
5750 SetelemAttrs::Data(val) => fmt.field("Data", &val),
5751 SetelemAttrs::Flags(val) => fmt.field("Flags", &val),
5752 SetelemAttrs::Timeout(val) => fmt.field("Timeout", &val),
5753 SetelemAttrs::Expiration(val) => fmt.field("Expiration", &val),
5754 SetelemAttrs::Userdata(val) => fmt.field("Userdata", &val),
5755 SetelemAttrs::Expr(val) => fmt.field("Expr", &val),
5756 SetelemAttrs::Objref(val) => fmt.field("Objref", &val),
5757 SetelemAttrs::KeyEnd(val) => fmt.field("KeyEnd", &val),
5758 SetelemAttrs::Expressions(val) => fmt.field("Expressions", &val),
5759 };
5760 }
5761 fmt.finish()
5762 }
5763}
5764impl IterableSetelemAttrs<'_> {
5765 pub fn lookup_attr(
5766 &self,
5767 offset: usize,
5768 missing_type: Option<u16>,
5769 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5770 let mut stack = Vec::new();
5771 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
5772 if cur == offset {
5773 stack.push(("SetelemAttrs", offset));
5774 return (
5775 stack,
5776 missing_type.and_then(|t| SetelemAttrs::attr_from_type(t)),
5777 );
5778 }
5779 if cur > offset || cur + self.buf.len() < offset {
5780 return (stack, None);
5781 }
5782 let mut attrs = self.clone();
5783 let mut last_off = cur + attrs.pos;
5784 let mut missing = None;
5785 while let Some(attr) = attrs.next() {
5786 let Ok(attr) = attr else { break };
5787 match attr {
5788 SetelemAttrs::Key(val) => {
5789 (stack, missing) = val.lookup_attr(offset, missing_type);
5790 if !stack.is_empty() {
5791 break;
5792 }
5793 }
5794 SetelemAttrs::Data(val) => {
5795 (stack, missing) = val.lookup_attr(offset, missing_type);
5796 if !stack.is_empty() {
5797 break;
5798 }
5799 }
5800 SetelemAttrs::Flags(val) => {
5801 if last_off == offset {
5802 stack.push(("Flags", last_off));
5803 break;
5804 }
5805 }
5806 SetelemAttrs::Timeout(val) => {
5807 if last_off == offset {
5808 stack.push(("Timeout", last_off));
5809 break;
5810 }
5811 }
5812 SetelemAttrs::Expiration(val) => {
5813 if last_off == offset {
5814 stack.push(("Expiration", last_off));
5815 break;
5816 }
5817 }
5818 SetelemAttrs::Userdata(val) => {
5819 if last_off == offset {
5820 stack.push(("Userdata", last_off));
5821 break;
5822 }
5823 }
5824 SetelemAttrs::Expr(val) => {
5825 (stack, missing) = val.lookup_attr(offset, missing_type);
5826 if !stack.is_empty() {
5827 break;
5828 }
5829 }
5830 SetelemAttrs::Objref(val) => {
5831 if last_off == offset {
5832 stack.push(("Objref", last_off));
5833 break;
5834 }
5835 }
5836 SetelemAttrs::KeyEnd(val) => {
5837 (stack, missing) = val.lookup_attr(offset, missing_type);
5838 if !stack.is_empty() {
5839 break;
5840 }
5841 }
5842 SetelemAttrs::Expressions(val) => {
5843 (stack, missing) = val.lookup_attr(offset, missing_type);
5844 if !stack.is_empty() {
5845 break;
5846 }
5847 }
5848 _ => {}
5849 };
5850 last_off = cur + attrs.pos;
5851 }
5852 if !stack.is_empty() {
5853 stack.push(("SetelemAttrs", cur));
5854 }
5855 (stack, missing)
5856 }
5857}
5858#[derive(Clone)]
5859pub enum SetelemListElemAttrs<'a> {
5860 #[doc = "Attribute may repeat multiple times (treat it as array)"]
5861 Elem(IterableSetelemAttrs<'a>),
5862}
5863impl<'a> IterableSetelemListElemAttrs<'a> {
5864 #[doc = "Attribute may repeat multiple times (treat it as array)"]
5865 pub fn get_elem(
5866 &self,
5867 ) -> MultiAttrIterable<Self, SetelemListElemAttrs<'a>, IterableSetelemAttrs<'a>> {
5868 MultiAttrIterable::new(self.clone(), |variant| {
5869 if let SetelemListElemAttrs::Elem(val) = variant {
5870 Some(val)
5871 } else {
5872 None
5873 }
5874 })
5875 }
5876}
5877impl<'a> SetelemListElemAttrs<'a> {
5878 pub fn new(buf: &'a [u8]) -> IterableSetelemListElemAttrs<'a> {
5879 IterableSetelemListElemAttrs::with_loc(buf, buf.as_ptr() as usize)
5880 }
5881 fn attr_from_type(r#type: u16) -> Option<&'static str> {
5882 let res = match r#type {
5883 1u16 => "Elem",
5884 _ => return None,
5885 };
5886 Some(res)
5887 }
5888}
5889#[derive(Clone, Copy, Default)]
5890pub struct IterableSetelemListElemAttrs<'a> {
5891 buf: &'a [u8],
5892 pos: usize,
5893 orig_loc: usize,
5894}
5895impl<'a> IterableSetelemListElemAttrs<'a> {
5896 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
5897 Self {
5898 buf,
5899 pos: 0,
5900 orig_loc,
5901 }
5902 }
5903 pub fn get_buf(&self) -> &'a [u8] {
5904 self.buf
5905 }
5906}
5907impl<'a> Iterator for IterableSetelemListElemAttrs<'a> {
5908 type Item = Result<SetelemListElemAttrs<'a>, ErrorContext>;
5909 fn next(&mut self) -> Option<Self::Item> {
5910 if self.buf.len() == self.pos {
5911 return None;
5912 }
5913 let pos = self.pos;
5914 let mut r#type = None;
5915 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
5916 r#type = Some(header.r#type);
5917 let res = match header.r#type {
5918 1u16 => SetelemListElemAttrs::Elem({
5919 let res = Some(IterableSetelemAttrs::with_loc(next, self.orig_loc));
5920 let Some(val) = res else { break };
5921 val
5922 }),
5923 n => {
5924 if cfg!(any(test, feature = "deny-unknown-attrs")) {
5925 break;
5926 } else {
5927 continue;
5928 }
5929 }
5930 };
5931 return Some(Ok(res));
5932 }
5933 Some(Err(ErrorContext::new(
5934 "SetelemListElemAttrs",
5935 r#type.and_then(|t| SetelemListElemAttrs::attr_from_type(t)),
5936 self.orig_loc,
5937 self.buf.as_ptr().wrapping_add(pos) as usize,
5938 )))
5939 }
5940}
5941impl<'a> std::fmt::Debug for IterableSetelemListElemAttrs<'_> {
5942 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5943 let mut fmt = f.debug_struct("SetelemListElemAttrs");
5944 for attr in self.clone() {
5945 let attr = match attr {
5946 Ok(a) => a,
5947 Err(err) => {
5948 fmt.finish()?;
5949 f.write_str("Err(")?;
5950 err.fmt(f)?;
5951 return f.write_str(")");
5952 }
5953 };
5954 match attr {
5955 SetelemListElemAttrs::Elem(val) => fmt.field("Elem", &val),
5956 };
5957 }
5958 fmt.finish()
5959 }
5960}
5961impl IterableSetelemListElemAttrs<'_> {
5962 pub fn lookup_attr(
5963 &self,
5964 offset: usize,
5965 missing_type: Option<u16>,
5966 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5967 let mut stack = Vec::new();
5968 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
5969 if cur == offset {
5970 stack.push(("SetelemListElemAttrs", offset));
5971 return (
5972 stack,
5973 missing_type.and_then(|t| SetelemListElemAttrs::attr_from_type(t)),
5974 );
5975 }
5976 if cur > offset || cur + self.buf.len() < offset {
5977 return (stack, None);
5978 }
5979 let mut attrs = self.clone();
5980 let mut last_off = cur + attrs.pos;
5981 let mut missing = None;
5982 while let Some(attr) = attrs.next() {
5983 let Ok(attr) = attr else { break };
5984 match attr {
5985 SetelemListElemAttrs::Elem(val) => {
5986 (stack, missing) = val.lookup_attr(offset, missing_type);
5987 if !stack.is_empty() {
5988 break;
5989 }
5990 }
5991 _ => {}
5992 };
5993 last_off = cur + attrs.pos;
5994 }
5995 if !stack.is_empty() {
5996 stack.push(("SetelemListElemAttrs", cur));
5997 }
5998 (stack, missing)
5999 }
6000}
6001#[derive(Clone)]
6002pub enum SetelemListAttrs<'a> {
6003 Table(&'a CStr),
6004 Set(&'a CStr),
6005 Elements(IterableSetelemListElemAttrs<'a>),
6006 SetId(u32),
6007}
6008impl<'a> IterableSetelemListAttrs<'a> {
6009 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
6010 let mut iter = self.clone();
6011 iter.pos = 0;
6012 for attr in iter {
6013 if let SetelemListAttrs::Table(val) = attr? {
6014 return Ok(val);
6015 }
6016 }
6017 Err(ErrorContext::new_missing(
6018 "SetelemListAttrs",
6019 "Table",
6020 self.orig_loc,
6021 self.buf.as_ptr() as usize,
6022 ))
6023 }
6024 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
6025 let mut iter = self.clone();
6026 iter.pos = 0;
6027 for attr in iter {
6028 if let SetelemListAttrs::Set(val) = attr? {
6029 return Ok(val);
6030 }
6031 }
6032 Err(ErrorContext::new_missing(
6033 "SetelemListAttrs",
6034 "Set",
6035 self.orig_loc,
6036 self.buf.as_ptr() as usize,
6037 ))
6038 }
6039 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
6040 let mut iter = self.clone();
6041 iter.pos = 0;
6042 for attr in iter {
6043 if let SetelemListAttrs::Elements(val) = attr? {
6044 return Ok(val);
6045 }
6046 }
6047 Err(ErrorContext::new_missing(
6048 "SetelemListAttrs",
6049 "Elements",
6050 self.orig_loc,
6051 self.buf.as_ptr() as usize,
6052 ))
6053 }
6054 pub fn get_set_id(&self) -> Result<u32, ErrorContext> {
6055 let mut iter = self.clone();
6056 iter.pos = 0;
6057 for attr in iter {
6058 if let SetelemListAttrs::SetId(val) = attr? {
6059 return Ok(val);
6060 }
6061 }
6062 Err(ErrorContext::new_missing(
6063 "SetelemListAttrs",
6064 "SetId",
6065 self.orig_loc,
6066 self.buf.as_ptr() as usize,
6067 ))
6068 }
6069}
6070impl<'a> SetelemListAttrs<'a> {
6071 pub fn new(buf: &'a [u8]) -> IterableSetelemListAttrs<'a> {
6072 IterableSetelemListAttrs::with_loc(buf, buf.as_ptr() as usize)
6073 }
6074 fn attr_from_type(r#type: u16) -> Option<&'static str> {
6075 let res = match r#type {
6076 1u16 => "Table",
6077 2u16 => "Set",
6078 3u16 => "Elements",
6079 4u16 => "SetId",
6080 _ => return None,
6081 };
6082 Some(res)
6083 }
6084}
6085#[derive(Clone, Copy, Default)]
6086pub struct IterableSetelemListAttrs<'a> {
6087 buf: &'a [u8],
6088 pos: usize,
6089 orig_loc: usize,
6090}
6091impl<'a> IterableSetelemListAttrs<'a> {
6092 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
6093 Self {
6094 buf,
6095 pos: 0,
6096 orig_loc,
6097 }
6098 }
6099 pub fn get_buf(&self) -> &'a [u8] {
6100 self.buf
6101 }
6102}
6103impl<'a> Iterator for IterableSetelemListAttrs<'a> {
6104 type Item = Result<SetelemListAttrs<'a>, ErrorContext>;
6105 fn next(&mut self) -> Option<Self::Item> {
6106 if self.buf.len() == self.pos {
6107 return None;
6108 }
6109 let pos = self.pos;
6110 let mut r#type = None;
6111 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
6112 r#type = Some(header.r#type);
6113 let res = match header.r#type {
6114 1u16 => SetelemListAttrs::Table({
6115 let res = CStr::from_bytes_with_nul(next).ok();
6116 let Some(val) = res else { break };
6117 val
6118 }),
6119 2u16 => SetelemListAttrs::Set({
6120 let res = CStr::from_bytes_with_nul(next).ok();
6121 let Some(val) = res else { break };
6122 val
6123 }),
6124 3u16 => SetelemListAttrs::Elements({
6125 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
6126 let Some(val) = res else { break };
6127 val
6128 }),
6129 4u16 => SetelemListAttrs::SetId({
6130 let res = parse_u32(next);
6131 let Some(val) = res else { break };
6132 val
6133 }),
6134 n => {
6135 if cfg!(any(test, feature = "deny-unknown-attrs")) {
6136 break;
6137 } else {
6138 continue;
6139 }
6140 }
6141 };
6142 return Some(Ok(res));
6143 }
6144 Some(Err(ErrorContext::new(
6145 "SetelemListAttrs",
6146 r#type.and_then(|t| SetelemListAttrs::attr_from_type(t)),
6147 self.orig_loc,
6148 self.buf.as_ptr().wrapping_add(pos) as usize,
6149 )))
6150 }
6151}
6152impl<'a> std::fmt::Debug for IterableSetelemListAttrs<'_> {
6153 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6154 let mut fmt = f.debug_struct("SetelemListAttrs");
6155 for attr in self.clone() {
6156 let attr = match attr {
6157 Ok(a) => a,
6158 Err(err) => {
6159 fmt.finish()?;
6160 f.write_str("Err(")?;
6161 err.fmt(f)?;
6162 return f.write_str(")");
6163 }
6164 };
6165 match attr {
6166 SetelemListAttrs::Table(val) => fmt.field("Table", &val),
6167 SetelemListAttrs::Set(val) => fmt.field("Set", &val),
6168 SetelemListAttrs::Elements(val) => fmt.field("Elements", &val),
6169 SetelemListAttrs::SetId(val) => fmt.field("SetId", &val),
6170 };
6171 }
6172 fmt.finish()
6173 }
6174}
6175impl IterableSetelemListAttrs<'_> {
6176 pub fn lookup_attr(
6177 &self,
6178 offset: usize,
6179 missing_type: Option<u16>,
6180 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
6181 let mut stack = Vec::new();
6182 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
6183 if cur == offset {
6184 stack.push(("SetelemListAttrs", offset));
6185 return (
6186 stack,
6187 missing_type.and_then(|t| SetelemListAttrs::attr_from_type(t)),
6188 );
6189 }
6190 if cur > offset || cur + self.buf.len() < offset {
6191 return (stack, None);
6192 }
6193 let mut attrs = self.clone();
6194 let mut last_off = cur + attrs.pos;
6195 let mut missing = None;
6196 while let Some(attr) = attrs.next() {
6197 let Ok(attr) = attr else { break };
6198 match attr {
6199 SetelemListAttrs::Table(val) => {
6200 if last_off == offset {
6201 stack.push(("Table", last_off));
6202 break;
6203 }
6204 }
6205 SetelemListAttrs::Set(val) => {
6206 if last_off == offset {
6207 stack.push(("Set", last_off));
6208 break;
6209 }
6210 }
6211 SetelemListAttrs::Elements(val) => {
6212 (stack, missing) = val.lookup_attr(offset, missing_type);
6213 if !stack.is_empty() {
6214 break;
6215 }
6216 }
6217 SetelemListAttrs::SetId(val) => {
6218 if last_off == offset {
6219 stack.push(("SetId", last_off));
6220 break;
6221 }
6222 }
6223 _ => {}
6224 };
6225 last_off = cur + attrs.pos;
6226 }
6227 if !stack.is_empty() {
6228 stack.push(("SetelemListAttrs", cur));
6229 }
6230 (stack, missing)
6231 }
6232}
6233#[derive(Clone)]
6234pub enum GenAttrs<'a> {
6235 #[doc = "ruleset generation id"]
6236 Id(u32),
6237 ProcPid(u32),
6238 ProcName(&'a CStr),
6239}
6240impl<'a> IterableGenAttrs<'a> {
6241 #[doc = "ruleset generation id"]
6242 pub fn get_id(&self) -> Result<u32, ErrorContext> {
6243 let mut iter = self.clone();
6244 iter.pos = 0;
6245 for attr in iter {
6246 if let GenAttrs::Id(val) = attr? {
6247 return Ok(val);
6248 }
6249 }
6250 Err(ErrorContext::new_missing(
6251 "GenAttrs",
6252 "Id",
6253 self.orig_loc,
6254 self.buf.as_ptr() as usize,
6255 ))
6256 }
6257 pub fn get_proc_pid(&self) -> Result<u32, ErrorContext> {
6258 let mut iter = self.clone();
6259 iter.pos = 0;
6260 for attr in iter {
6261 if let GenAttrs::ProcPid(val) = attr? {
6262 return Ok(val);
6263 }
6264 }
6265 Err(ErrorContext::new_missing(
6266 "GenAttrs",
6267 "ProcPid",
6268 self.orig_loc,
6269 self.buf.as_ptr() as usize,
6270 ))
6271 }
6272 pub fn get_proc_name(&self) -> Result<&'a CStr, ErrorContext> {
6273 let mut iter = self.clone();
6274 iter.pos = 0;
6275 for attr in iter {
6276 if let GenAttrs::ProcName(val) = attr? {
6277 return Ok(val);
6278 }
6279 }
6280 Err(ErrorContext::new_missing(
6281 "GenAttrs",
6282 "ProcName",
6283 self.orig_loc,
6284 self.buf.as_ptr() as usize,
6285 ))
6286 }
6287}
6288impl<'a> GenAttrs<'a> {
6289 pub fn new(buf: &'a [u8]) -> IterableGenAttrs<'a> {
6290 IterableGenAttrs::with_loc(buf, buf.as_ptr() as usize)
6291 }
6292 fn attr_from_type(r#type: u16) -> Option<&'static str> {
6293 let res = match r#type {
6294 1u16 => "Id",
6295 2u16 => "ProcPid",
6296 3u16 => "ProcName",
6297 _ => return None,
6298 };
6299 Some(res)
6300 }
6301}
6302#[derive(Clone, Copy, Default)]
6303pub struct IterableGenAttrs<'a> {
6304 buf: &'a [u8],
6305 pos: usize,
6306 orig_loc: usize,
6307}
6308impl<'a> IterableGenAttrs<'a> {
6309 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
6310 Self {
6311 buf,
6312 pos: 0,
6313 orig_loc,
6314 }
6315 }
6316 pub fn get_buf(&self) -> &'a [u8] {
6317 self.buf
6318 }
6319}
6320impl<'a> Iterator for IterableGenAttrs<'a> {
6321 type Item = Result<GenAttrs<'a>, ErrorContext>;
6322 fn next(&mut self) -> Option<Self::Item> {
6323 if self.buf.len() == self.pos {
6324 return None;
6325 }
6326 let pos = self.pos;
6327 let mut r#type = None;
6328 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
6329 r#type = Some(header.r#type);
6330 let res = match header.r#type {
6331 1u16 => GenAttrs::Id({
6332 let res = parse_be_u32(next);
6333 let Some(val) = res else { break };
6334 val
6335 }),
6336 2u16 => GenAttrs::ProcPid({
6337 let res = parse_be_u32(next);
6338 let Some(val) = res else { break };
6339 val
6340 }),
6341 3u16 => GenAttrs::ProcName({
6342 let res = CStr::from_bytes_with_nul(next).ok();
6343 let Some(val) = res else { break };
6344 val
6345 }),
6346 n => {
6347 if cfg!(any(test, feature = "deny-unknown-attrs")) {
6348 break;
6349 } else {
6350 continue;
6351 }
6352 }
6353 };
6354 return Some(Ok(res));
6355 }
6356 Some(Err(ErrorContext::new(
6357 "GenAttrs",
6358 r#type.and_then(|t| GenAttrs::attr_from_type(t)),
6359 self.orig_loc,
6360 self.buf.as_ptr().wrapping_add(pos) as usize,
6361 )))
6362 }
6363}
6364impl<'a> std::fmt::Debug for IterableGenAttrs<'_> {
6365 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6366 let mut fmt = f.debug_struct("GenAttrs");
6367 for attr in self.clone() {
6368 let attr = match attr {
6369 Ok(a) => a,
6370 Err(err) => {
6371 fmt.finish()?;
6372 f.write_str("Err(")?;
6373 err.fmt(f)?;
6374 return f.write_str(")");
6375 }
6376 };
6377 match attr {
6378 GenAttrs::Id(val) => fmt.field("Id", &val),
6379 GenAttrs::ProcPid(val) => fmt.field("ProcPid", &val),
6380 GenAttrs::ProcName(val) => fmt.field("ProcName", &val),
6381 };
6382 }
6383 fmt.finish()
6384 }
6385}
6386impl IterableGenAttrs<'_> {
6387 pub fn lookup_attr(
6388 &self,
6389 offset: usize,
6390 missing_type: Option<u16>,
6391 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
6392 let mut stack = Vec::new();
6393 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
6394 if cur == offset {
6395 stack.push(("GenAttrs", offset));
6396 return (
6397 stack,
6398 missing_type.and_then(|t| GenAttrs::attr_from_type(t)),
6399 );
6400 }
6401 if cur > offset || cur + self.buf.len() < offset {
6402 return (stack, None);
6403 }
6404 let mut attrs = self.clone();
6405 let mut last_off = cur + attrs.pos;
6406 while let Some(attr) = attrs.next() {
6407 let Ok(attr) = attr else { break };
6408 match attr {
6409 GenAttrs::Id(val) => {
6410 if last_off == offset {
6411 stack.push(("Id", last_off));
6412 break;
6413 }
6414 }
6415 GenAttrs::ProcPid(val) => {
6416 if last_off == offset {
6417 stack.push(("ProcPid", last_off));
6418 break;
6419 }
6420 }
6421 GenAttrs::ProcName(val) => {
6422 if last_off == offset {
6423 stack.push(("ProcName", last_off));
6424 break;
6425 }
6426 }
6427 _ => {}
6428 };
6429 last_off = cur + attrs.pos;
6430 }
6431 if !stack.is_empty() {
6432 stack.push(("GenAttrs", cur));
6433 }
6434 (stack, None)
6435 }
6436}
6437#[derive(Clone)]
6438pub enum ObjAttrs<'a> {
6439 #[doc = "name of the table containing the expression"]
6440 Table(&'a CStr),
6441 #[doc = "name of this expression type"]
6442 Name(&'a CStr),
6443 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
6444 Type(u32),
6445 #[doc = "stateful object data"]
6446 Data(ObjData<'a>),
6447 #[doc = "number of references to this expression"]
6448 Use(u32),
6449 #[doc = "object handle"]
6450 Handle(u64),
6451 Pad(&'a [u8]),
6452 #[doc = "user data"]
6453 Userdata(&'a [u8]),
6454}
6455impl<'a> IterableObjAttrs<'a> {
6456 #[doc = "name of the table containing the expression"]
6457 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
6458 let mut iter = self.clone();
6459 iter.pos = 0;
6460 for attr in iter {
6461 if let ObjAttrs::Table(val) = attr? {
6462 return Ok(val);
6463 }
6464 }
6465 Err(ErrorContext::new_missing(
6466 "ObjAttrs",
6467 "Table",
6468 self.orig_loc,
6469 self.buf.as_ptr() as usize,
6470 ))
6471 }
6472 #[doc = "name of this expression type"]
6473 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
6474 let mut iter = self.clone();
6475 iter.pos = 0;
6476 for attr in iter {
6477 if let ObjAttrs::Name(val) = attr? {
6478 return Ok(val);
6479 }
6480 }
6481 Err(ErrorContext::new_missing(
6482 "ObjAttrs",
6483 "Name",
6484 self.orig_loc,
6485 self.buf.as_ptr() as usize,
6486 ))
6487 }
6488 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
6489 pub fn get_type(&self) -> Result<u32, ErrorContext> {
6490 let mut iter = self.clone();
6491 iter.pos = 0;
6492 for attr in iter {
6493 if let ObjAttrs::Type(val) = attr? {
6494 return Ok(val);
6495 }
6496 }
6497 Err(ErrorContext::new_missing(
6498 "ObjAttrs",
6499 "Type",
6500 self.orig_loc,
6501 self.buf.as_ptr() as usize,
6502 ))
6503 }
6504 #[doc = "stateful object data"]
6505 pub fn get_data(&self) -> Result<ObjData<'a>, ErrorContext> {
6506 let mut iter = self.clone();
6507 iter.pos = 0;
6508 for attr in iter {
6509 if let ObjAttrs::Data(val) = attr? {
6510 return Ok(val);
6511 }
6512 }
6513 Err(ErrorContext::new_missing(
6514 "ObjAttrs",
6515 "Data",
6516 self.orig_loc,
6517 self.buf.as_ptr() as usize,
6518 ))
6519 }
6520 #[doc = "number of references to this expression"]
6521 pub fn get_use(&self) -> Result<u32, ErrorContext> {
6522 let mut iter = self.clone();
6523 iter.pos = 0;
6524 for attr in iter {
6525 if let ObjAttrs::Use(val) = attr? {
6526 return Ok(val);
6527 }
6528 }
6529 Err(ErrorContext::new_missing(
6530 "ObjAttrs",
6531 "Use",
6532 self.orig_loc,
6533 self.buf.as_ptr() as usize,
6534 ))
6535 }
6536 #[doc = "object handle"]
6537 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
6538 let mut iter = self.clone();
6539 iter.pos = 0;
6540 for attr in iter {
6541 if let ObjAttrs::Handle(val) = attr? {
6542 return Ok(val);
6543 }
6544 }
6545 Err(ErrorContext::new_missing(
6546 "ObjAttrs",
6547 "Handle",
6548 self.orig_loc,
6549 self.buf.as_ptr() as usize,
6550 ))
6551 }
6552 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
6553 let mut iter = self.clone();
6554 iter.pos = 0;
6555 for attr in iter {
6556 if let ObjAttrs::Pad(val) = attr? {
6557 return Ok(val);
6558 }
6559 }
6560 Err(ErrorContext::new_missing(
6561 "ObjAttrs",
6562 "Pad",
6563 self.orig_loc,
6564 self.buf.as_ptr() as usize,
6565 ))
6566 }
6567 #[doc = "user data"]
6568 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
6569 let mut iter = self.clone();
6570 iter.pos = 0;
6571 for attr in iter {
6572 if let ObjAttrs::Userdata(val) = attr? {
6573 return Ok(val);
6574 }
6575 }
6576 Err(ErrorContext::new_missing(
6577 "ObjAttrs",
6578 "Userdata",
6579 self.orig_loc,
6580 self.buf.as_ptr() as usize,
6581 ))
6582 }
6583}
6584#[derive(Debug, Clone)]
6585pub enum ObjData<'a> {
6586 Counter(IterableCounterAttrs<'a>),
6587 Quota(IterableQuotaAttrs<'a>),
6588}
6589impl<'a> ObjData<'a> {
6590 fn select_with_loc(selector: u32, buf: &'a [u8], loc: usize) -> Option<Self> {
6591 match selector {
6592 val if val == ObjectType::Counter as u32 => {
6593 Some(ObjData::Counter(IterableCounterAttrs::with_loc(buf, loc)))
6594 }
6595 val if val == ObjectType::Quota as u32 => {
6596 Some(ObjData::Quota(IterableQuotaAttrs::with_loc(buf, loc)))
6597 }
6598 _ => None,
6599 }
6600 }
6601}
6602impl<'a> ObjAttrs<'a> {
6603 pub fn new(buf: &'a [u8]) -> IterableObjAttrs<'a> {
6604 IterableObjAttrs::with_loc(buf, buf.as_ptr() as usize)
6605 }
6606 fn attr_from_type(r#type: u16) -> Option<&'static str> {
6607 let res = match r#type {
6608 1u16 => "Table",
6609 2u16 => "Name",
6610 3u16 => "Type",
6611 4u16 => "Data",
6612 5u16 => "Use",
6613 6u16 => "Handle",
6614 7u16 => "Pad",
6615 8u16 => "Userdata",
6616 _ => return None,
6617 };
6618 Some(res)
6619 }
6620}
6621#[derive(Clone, Copy, Default)]
6622pub struct IterableObjAttrs<'a> {
6623 buf: &'a [u8],
6624 pos: usize,
6625 orig_loc: usize,
6626}
6627impl<'a> IterableObjAttrs<'a> {
6628 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
6629 Self {
6630 buf,
6631 pos: 0,
6632 orig_loc,
6633 }
6634 }
6635 pub fn get_buf(&self) -> &'a [u8] {
6636 self.buf
6637 }
6638}
6639impl<'a> Iterator for IterableObjAttrs<'a> {
6640 type Item = Result<ObjAttrs<'a>, ErrorContext>;
6641 fn next(&mut self) -> Option<Self::Item> {
6642 if self.buf.len() == self.pos {
6643 return None;
6644 }
6645 let pos = self.pos;
6646 let mut r#type = None;
6647 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
6648 r#type = Some(header.r#type);
6649 let res = match header.r#type {
6650 1u16 => ObjAttrs::Table({
6651 let res = CStr::from_bytes_with_nul(next).ok();
6652 let Some(val) = res else { break };
6653 val
6654 }),
6655 2u16 => ObjAttrs::Name({
6656 let res = CStr::from_bytes_with_nul(next).ok();
6657 let Some(val) = res else { break };
6658 val
6659 }),
6660 3u16 => ObjAttrs::Type({
6661 let res = parse_be_u32(next);
6662 let Some(val) = res else { break };
6663 val
6664 }),
6665 4u16 => ObjAttrs::Data({
6666 let res = {
6667 let Ok(selector) = self.get_type() else { break };
6668 ObjData::select_with_loc(selector, next, self.orig_loc)
6669 };
6670 let Some(val) = res else { break };
6671 val
6672 }),
6673 5u16 => ObjAttrs::Use({
6674 let res = parse_be_u32(next);
6675 let Some(val) = res else { break };
6676 val
6677 }),
6678 6u16 => ObjAttrs::Handle({
6679 let res = parse_be_u64(next);
6680 let Some(val) = res else { break };
6681 val
6682 }),
6683 7u16 => ObjAttrs::Pad({
6684 let res = Some(next);
6685 let Some(val) = res else { break };
6686 val
6687 }),
6688 8u16 => ObjAttrs::Userdata({
6689 let res = Some(next);
6690 let Some(val) = res else { break };
6691 val
6692 }),
6693 n => {
6694 if cfg!(any(test, feature = "deny-unknown-attrs")) {
6695 break;
6696 } else {
6697 continue;
6698 }
6699 }
6700 };
6701 return Some(Ok(res));
6702 }
6703 Some(Err(ErrorContext::new(
6704 "ObjAttrs",
6705 r#type.and_then(|t| ObjAttrs::attr_from_type(t)),
6706 self.orig_loc,
6707 self.buf.as_ptr().wrapping_add(pos) as usize,
6708 )))
6709 }
6710}
6711impl<'a> std::fmt::Debug for IterableObjAttrs<'_> {
6712 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6713 let mut fmt = f.debug_struct("ObjAttrs");
6714 for attr in self.clone() {
6715 let attr = match attr {
6716 Ok(a) => a,
6717 Err(err) => {
6718 fmt.finish()?;
6719 f.write_str("Err(")?;
6720 err.fmt(f)?;
6721 return f.write_str(")");
6722 }
6723 };
6724 match attr {
6725 ObjAttrs::Table(val) => fmt.field("Table", &val),
6726 ObjAttrs::Name(val) => fmt.field("Name", &val),
6727 ObjAttrs::Type(val) => {
6728 fmt.field("Type", &FormatEnum(val.into(), ObjectType::from_value))
6729 }
6730 ObjAttrs::Data(val) => fmt.field("Data", &val),
6731 ObjAttrs::Use(val) => fmt.field("Use", &val),
6732 ObjAttrs::Handle(val) => fmt.field("Handle", &val),
6733 ObjAttrs::Pad(val) => fmt.field("Pad", &val),
6734 ObjAttrs::Userdata(val) => fmt.field("Userdata", &val),
6735 };
6736 }
6737 fmt.finish()
6738 }
6739}
6740impl IterableObjAttrs<'_> {
6741 pub fn lookup_attr(
6742 &self,
6743 offset: usize,
6744 missing_type: Option<u16>,
6745 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
6746 let mut stack = Vec::new();
6747 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
6748 if cur == offset {
6749 stack.push(("ObjAttrs", offset));
6750 return (
6751 stack,
6752 missing_type.and_then(|t| ObjAttrs::attr_from_type(t)),
6753 );
6754 }
6755 if cur > offset || cur + self.buf.len() < offset {
6756 return (stack, None);
6757 }
6758 let mut attrs = self.clone();
6759 let mut last_off = cur + attrs.pos;
6760 while let Some(attr) = attrs.next() {
6761 let Ok(attr) = attr else { break };
6762 match attr {
6763 ObjAttrs::Table(val) => {
6764 if last_off == offset {
6765 stack.push(("Table", last_off));
6766 break;
6767 }
6768 }
6769 ObjAttrs::Name(val) => {
6770 if last_off == offset {
6771 stack.push(("Name", last_off));
6772 break;
6773 }
6774 }
6775 ObjAttrs::Type(val) => {
6776 if last_off == offset {
6777 stack.push(("Type", last_off));
6778 break;
6779 }
6780 }
6781 ObjAttrs::Data(val) => {
6782 if last_off == offset {
6783 stack.push(("Data", last_off));
6784 break;
6785 }
6786 }
6787 ObjAttrs::Use(val) => {
6788 if last_off == offset {
6789 stack.push(("Use", last_off));
6790 break;
6791 }
6792 }
6793 ObjAttrs::Handle(val) => {
6794 if last_off == offset {
6795 stack.push(("Handle", last_off));
6796 break;
6797 }
6798 }
6799 ObjAttrs::Pad(val) => {
6800 if last_off == offset {
6801 stack.push(("Pad", last_off));
6802 break;
6803 }
6804 }
6805 ObjAttrs::Userdata(val) => {
6806 if last_off == offset {
6807 stack.push(("Userdata", last_off));
6808 break;
6809 }
6810 }
6811 _ => {}
6812 };
6813 last_off = cur + attrs.pos;
6814 }
6815 if !stack.is_empty() {
6816 stack.push(("ObjAttrs", cur));
6817 }
6818 (stack, None)
6819 }
6820}
6821#[derive(Clone)]
6822pub enum QuotaAttrs<'a> {
6823 Bytes(u64),
6824 #[doc = "Associated type: \"QuotaFlags\" (enum)"]
6825 Flags(u32),
6826 Pad(&'a [u8]),
6827 Consumed(u64),
6828}
6829impl<'a> IterableQuotaAttrs<'a> {
6830 pub fn get_bytes(&self) -> Result<u64, ErrorContext> {
6831 let mut iter = self.clone();
6832 iter.pos = 0;
6833 for attr in iter {
6834 if let QuotaAttrs::Bytes(val) = attr? {
6835 return Ok(val);
6836 }
6837 }
6838 Err(ErrorContext::new_missing(
6839 "QuotaAttrs",
6840 "Bytes",
6841 self.orig_loc,
6842 self.buf.as_ptr() as usize,
6843 ))
6844 }
6845 #[doc = "Associated type: \"QuotaFlags\" (enum)"]
6846 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
6847 let mut iter = self.clone();
6848 iter.pos = 0;
6849 for attr in iter {
6850 if let QuotaAttrs::Flags(val) = attr? {
6851 return Ok(val);
6852 }
6853 }
6854 Err(ErrorContext::new_missing(
6855 "QuotaAttrs",
6856 "Flags",
6857 self.orig_loc,
6858 self.buf.as_ptr() as usize,
6859 ))
6860 }
6861 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
6862 let mut iter = self.clone();
6863 iter.pos = 0;
6864 for attr in iter {
6865 if let QuotaAttrs::Pad(val) = attr? {
6866 return Ok(val);
6867 }
6868 }
6869 Err(ErrorContext::new_missing(
6870 "QuotaAttrs",
6871 "Pad",
6872 self.orig_loc,
6873 self.buf.as_ptr() as usize,
6874 ))
6875 }
6876 pub fn get_consumed(&self) -> Result<u64, ErrorContext> {
6877 let mut iter = self.clone();
6878 iter.pos = 0;
6879 for attr in iter {
6880 if let QuotaAttrs::Consumed(val) = attr? {
6881 return Ok(val);
6882 }
6883 }
6884 Err(ErrorContext::new_missing(
6885 "QuotaAttrs",
6886 "Consumed",
6887 self.orig_loc,
6888 self.buf.as_ptr() as usize,
6889 ))
6890 }
6891}
6892impl<'a> QuotaAttrs<'a> {
6893 pub fn new(buf: &'a [u8]) -> IterableQuotaAttrs<'a> {
6894 IterableQuotaAttrs::with_loc(buf, buf.as_ptr() as usize)
6895 }
6896 fn attr_from_type(r#type: u16) -> Option<&'static str> {
6897 let res = match r#type {
6898 1u16 => "Bytes",
6899 2u16 => "Flags",
6900 3u16 => "Pad",
6901 4u16 => "Consumed",
6902 _ => return None,
6903 };
6904 Some(res)
6905 }
6906}
6907#[derive(Clone, Copy, Default)]
6908pub struct IterableQuotaAttrs<'a> {
6909 buf: &'a [u8],
6910 pos: usize,
6911 orig_loc: usize,
6912}
6913impl<'a> IterableQuotaAttrs<'a> {
6914 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
6915 Self {
6916 buf,
6917 pos: 0,
6918 orig_loc,
6919 }
6920 }
6921 pub fn get_buf(&self) -> &'a [u8] {
6922 self.buf
6923 }
6924}
6925impl<'a> Iterator for IterableQuotaAttrs<'a> {
6926 type Item = Result<QuotaAttrs<'a>, ErrorContext>;
6927 fn next(&mut self) -> Option<Self::Item> {
6928 if self.buf.len() == self.pos {
6929 return None;
6930 }
6931 let pos = self.pos;
6932 let mut r#type = None;
6933 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
6934 r#type = Some(header.r#type);
6935 let res = match header.r#type {
6936 1u16 => QuotaAttrs::Bytes({
6937 let res = parse_be_u64(next);
6938 let Some(val) = res else { break };
6939 val
6940 }),
6941 2u16 => QuotaAttrs::Flags({
6942 let res = parse_be_u32(next);
6943 let Some(val) = res else { break };
6944 val
6945 }),
6946 3u16 => QuotaAttrs::Pad({
6947 let res = Some(next);
6948 let Some(val) = res else { break };
6949 val
6950 }),
6951 4u16 => QuotaAttrs::Consumed({
6952 let res = parse_be_u64(next);
6953 let Some(val) = res else { break };
6954 val
6955 }),
6956 n => {
6957 if cfg!(any(test, feature = "deny-unknown-attrs")) {
6958 break;
6959 } else {
6960 continue;
6961 }
6962 }
6963 };
6964 return Some(Ok(res));
6965 }
6966 Some(Err(ErrorContext::new(
6967 "QuotaAttrs",
6968 r#type.and_then(|t| QuotaAttrs::attr_from_type(t)),
6969 self.orig_loc,
6970 self.buf.as_ptr().wrapping_add(pos) as usize,
6971 )))
6972 }
6973}
6974impl<'a> std::fmt::Debug for IterableQuotaAttrs<'_> {
6975 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6976 let mut fmt = f.debug_struct("QuotaAttrs");
6977 for attr in self.clone() {
6978 let attr = match attr {
6979 Ok(a) => a,
6980 Err(err) => {
6981 fmt.finish()?;
6982 f.write_str("Err(")?;
6983 err.fmt(f)?;
6984 return f.write_str(")");
6985 }
6986 };
6987 match attr {
6988 QuotaAttrs::Bytes(val) => fmt.field("Bytes", &val),
6989 QuotaAttrs::Flags(val) => {
6990 fmt.field("Flags", &FormatFlags(val.into(), QuotaFlags::from_value))
6991 }
6992 QuotaAttrs::Pad(val) => fmt.field("Pad", &val),
6993 QuotaAttrs::Consumed(val) => fmt.field("Consumed", &val),
6994 };
6995 }
6996 fmt.finish()
6997 }
6998}
6999impl IterableQuotaAttrs<'_> {
7000 pub fn lookup_attr(
7001 &self,
7002 offset: usize,
7003 missing_type: Option<u16>,
7004 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
7005 let mut stack = Vec::new();
7006 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
7007 if cur == offset {
7008 stack.push(("QuotaAttrs", offset));
7009 return (
7010 stack,
7011 missing_type.and_then(|t| QuotaAttrs::attr_from_type(t)),
7012 );
7013 }
7014 if cur > offset || cur + self.buf.len() < offset {
7015 return (stack, None);
7016 }
7017 let mut attrs = self.clone();
7018 let mut last_off = cur + attrs.pos;
7019 while let Some(attr) = attrs.next() {
7020 let Ok(attr) = attr else { break };
7021 match attr {
7022 QuotaAttrs::Bytes(val) => {
7023 if last_off == offset {
7024 stack.push(("Bytes", last_off));
7025 break;
7026 }
7027 }
7028 QuotaAttrs::Flags(val) => {
7029 if last_off == offset {
7030 stack.push(("Flags", last_off));
7031 break;
7032 }
7033 }
7034 QuotaAttrs::Pad(val) => {
7035 if last_off == offset {
7036 stack.push(("Pad", last_off));
7037 break;
7038 }
7039 }
7040 QuotaAttrs::Consumed(val) => {
7041 if last_off == offset {
7042 stack.push(("Consumed", last_off));
7043 break;
7044 }
7045 }
7046 _ => {}
7047 };
7048 last_off = cur + attrs.pos;
7049 }
7050 if !stack.is_empty() {
7051 stack.push(("QuotaAttrs", cur));
7052 }
7053 (stack, None)
7054 }
7055}
7056#[derive(Clone)]
7057pub enum FlowtableAttrs<'a> {
7058 Table(&'a CStr),
7059 Name(&'a CStr),
7060 Hook(IterableFlowtableHookAttrs<'a>),
7061 Use(u32),
7062 Handle(u64),
7063 Pad(&'a [u8]),
7064 Flags(u32),
7065}
7066impl<'a> IterableFlowtableAttrs<'a> {
7067 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
7068 let mut iter = self.clone();
7069 iter.pos = 0;
7070 for attr in iter {
7071 if let FlowtableAttrs::Table(val) = attr? {
7072 return Ok(val);
7073 }
7074 }
7075 Err(ErrorContext::new_missing(
7076 "FlowtableAttrs",
7077 "Table",
7078 self.orig_loc,
7079 self.buf.as_ptr() as usize,
7080 ))
7081 }
7082 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
7083 let mut iter = self.clone();
7084 iter.pos = 0;
7085 for attr in iter {
7086 if let FlowtableAttrs::Name(val) = attr? {
7087 return Ok(val);
7088 }
7089 }
7090 Err(ErrorContext::new_missing(
7091 "FlowtableAttrs",
7092 "Name",
7093 self.orig_loc,
7094 self.buf.as_ptr() as usize,
7095 ))
7096 }
7097 pub fn get_hook(&self) -> Result<IterableFlowtableHookAttrs<'a>, ErrorContext> {
7098 let mut iter = self.clone();
7099 iter.pos = 0;
7100 for attr in iter {
7101 if let FlowtableAttrs::Hook(val) = attr? {
7102 return Ok(val);
7103 }
7104 }
7105 Err(ErrorContext::new_missing(
7106 "FlowtableAttrs",
7107 "Hook",
7108 self.orig_loc,
7109 self.buf.as_ptr() as usize,
7110 ))
7111 }
7112 pub fn get_use(&self) -> Result<u32, ErrorContext> {
7113 let mut iter = self.clone();
7114 iter.pos = 0;
7115 for attr in iter {
7116 if let FlowtableAttrs::Use(val) = attr? {
7117 return Ok(val);
7118 }
7119 }
7120 Err(ErrorContext::new_missing(
7121 "FlowtableAttrs",
7122 "Use",
7123 self.orig_loc,
7124 self.buf.as_ptr() as usize,
7125 ))
7126 }
7127 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
7128 let mut iter = self.clone();
7129 iter.pos = 0;
7130 for attr in iter {
7131 if let FlowtableAttrs::Handle(val) = attr? {
7132 return Ok(val);
7133 }
7134 }
7135 Err(ErrorContext::new_missing(
7136 "FlowtableAttrs",
7137 "Handle",
7138 self.orig_loc,
7139 self.buf.as_ptr() as usize,
7140 ))
7141 }
7142 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
7143 let mut iter = self.clone();
7144 iter.pos = 0;
7145 for attr in iter {
7146 if let FlowtableAttrs::Pad(val) = attr? {
7147 return Ok(val);
7148 }
7149 }
7150 Err(ErrorContext::new_missing(
7151 "FlowtableAttrs",
7152 "Pad",
7153 self.orig_loc,
7154 self.buf.as_ptr() as usize,
7155 ))
7156 }
7157 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
7158 let mut iter = self.clone();
7159 iter.pos = 0;
7160 for attr in iter {
7161 if let FlowtableAttrs::Flags(val) = attr? {
7162 return Ok(val);
7163 }
7164 }
7165 Err(ErrorContext::new_missing(
7166 "FlowtableAttrs",
7167 "Flags",
7168 self.orig_loc,
7169 self.buf.as_ptr() as usize,
7170 ))
7171 }
7172}
7173impl<'a> FlowtableAttrs<'a> {
7174 pub fn new(buf: &'a [u8]) -> IterableFlowtableAttrs<'a> {
7175 IterableFlowtableAttrs::with_loc(buf, buf.as_ptr() as usize)
7176 }
7177 fn attr_from_type(r#type: u16) -> Option<&'static str> {
7178 let res = match r#type {
7179 1u16 => "Table",
7180 2u16 => "Name",
7181 3u16 => "Hook",
7182 4u16 => "Use",
7183 5u16 => "Handle",
7184 6u16 => "Pad",
7185 7u16 => "Flags",
7186 _ => return None,
7187 };
7188 Some(res)
7189 }
7190}
7191#[derive(Clone, Copy, Default)]
7192pub struct IterableFlowtableAttrs<'a> {
7193 buf: &'a [u8],
7194 pos: usize,
7195 orig_loc: usize,
7196}
7197impl<'a> IterableFlowtableAttrs<'a> {
7198 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
7199 Self {
7200 buf,
7201 pos: 0,
7202 orig_loc,
7203 }
7204 }
7205 pub fn get_buf(&self) -> &'a [u8] {
7206 self.buf
7207 }
7208}
7209impl<'a> Iterator for IterableFlowtableAttrs<'a> {
7210 type Item = Result<FlowtableAttrs<'a>, ErrorContext>;
7211 fn next(&mut self) -> Option<Self::Item> {
7212 if self.buf.len() == self.pos {
7213 return None;
7214 }
7215 let pos = self.pos;
7216 let mut r#type = None;
7217 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
7218 r#type = Some(header.r#type);
7219 let res = match header.r#type {
7220 1u16 => FlowtableAttrs::Table({
7221 let res = CStr::from_bytes_with_nul(next).ok();
7222 let Some(val) = res else { break };
7223 val
7224 }),
7225 2u16 => FlowtableAttrs::Name({
7226 let res = CStr::from_bytes_with_nul(next).ok();
7227 let Some(val) = res else { break };
7228 val
7229 }),
7230 3u16 => FlowtableAttrs::Hook({
7231 let res = Some(IterableFlowtableHookAttrs::with_loc(next, self.orig_loc));
7232 let Some(val) = res else { break };
7233 val
7234 }),
7235 4u16 => FlowtableAttrs::Use({
7236 let res = parse_be_u32(next);
7237 let Some(val) = res else { break };
7238 val
7239 }),
7240 5u16 => FlowtableAttrs::Handle({
7241 let res = parse_be_u64(next);
7242 let Some(val) = res else { break };
7243 val
7244 }),
7245 6u16 => FlowtableAttrs::Pad({
7246 let res = Some(next);
7247 let Some(val) = res else { break };
7248 val
7249 }),
7250 7u16 => FlowtableAttrs::Flags({
7251 let res = parse_be_u32(next);
7252 let Some(val) = res else { break };
7253 val
7254 }),
7255 n => {
7256 if cfg!(any(test, feature = "deny-unknown-attrs")) {
7257 break;
7258 } else {
7259 continue;
7260 }
7261 }
7262 };
7263 return Some(Ok(res));
7264 }
7265 Some(Err(ErrorContext::new(
7266 "FlowtableAttrs",
7267 r#type.and_then(|t| FlowtableAttrs::attr_from_type(t)),
7268 self.orig_loc,
7269 self.buf.as_ptr().wrapping_add(pos) as usize,
7270 )))
7271 }
7272}
7273impl<'a> std::fmt::Debug for IterableFlowtableAttrs<'_> {
7274 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7275 let mut fmt = f.debug_struct("FlowtableAttrs");
7276 for attr in self.clone() {
7277 let attr = match attr {
7278 Ok(a) => a,
7279 Err(err) => {
7280 fmt.finish()?;
7281 f.write_str("Err(")?;
7282 err.fmt(f)?;
7283 return f.write_str(")");
7284 }
7285 };
7286 match attr {
7287 FlowtableAttrs::Table(val) => fmt.field("Table", &val),
7288 FlowtableAttrs::Name(val) => fmt.field("Name", &val),
7289 FlowtableAttrs::Hook(val) => fmt.field("Hook", &val),
7290 FlowtableAttrs::Use(val) => fmt.field("Use", &val),
7291 FlowtableAttrs::Handle(val) => fmt.field("Handle", &val),
7292 FlowtableAttrs::Pad(val) => fmt.field("Pad", &val),
7293 FlowtableAttrs::Flags(val) => fmt.field("Flags", &val),
7294 };
7295 }
7296 fmt.finish()
7297 }
7298}
7299impl IterableFlowtableAttrs<'_> {
7300 pub fn lookup_attr(
7301 &self,
7302 offset: usize,
7303 missing_type: Option<u16>,
7304 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
7305 let mut stack = Vec::new();
7306 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
7307 if cur == offset {
7308 stack.push(("FlowtableAttrs", offset));
7309 return (
7310 stack,
7311 missing_type.and_then(|t| FlowtableAttrs::attr_from_type(t)),
7312 );
7313 }
7314 if cur > offset || cur + self.buf.len() < offset {
7315 return (stack, None);
7316 }
7317 let mut attrs = self.clone();
7318 let mut last_off = cur + attrs.pos;
7319 let mut missing = None;
7320 while let Some(attr) = attrs.next() {
7321 let Ok(attr) = attr else { break };
7322 match attr {
7323 FlowtableAttrs::Table(val) => {
7324 if last_off == offset {
7325 stack.push(("Table", last_off));
7326 break;
7327 }
7328 }
7329 FlowtableAttrs::Name(val) => {
7330 if last_off == offset {
7331 stack.push(("Name", last_off));
7332 break;
7333 }
7334 }
7335 FlowtableAttrs::Hook(val) => {
7336 (stack, missing) = val.lookup_attr(offset, missing_type);
7337 if !stack.is_empty() {
7338 break;
7339 }
7340 }
7341 FlowtableAttrs::Use(val) => {
7342 if last_off == offset {
7343 stack.push(("Use", last_off));
7344 break;
7345 }
7346 }
7347 FlowtableAttrs::Handle(val) => {
7348 if last_off == offset {
7349 stack.push(("Handle", last_off));
7350 break;
7351 }
7352 }
7353 FlowtableAttrs::Pad(val) => {
7354 if last_off == offset {
7355 stack.push(("Pad", last_off));
7356 break;
7357 }
7358 }
7359 FlowtableAttrs::Flags(val) => {
7360 if last_off == offset {
7361 stack.push(("Flags", last_off));
7362 break;
7363 }
7364 }
7365 _ => {}
7366 };
7367 last_off = cur + attrs.pos;
7368 }
7369 if !stack.is_empty() {
7370 stack.push(("FlowtableAttrs", cur));
7371 }
7372 (stack, missing)
7373 }
7374}
7375#[derive(Clone)]
7376pub enum FlowtableHookAttrs<'a> {
7377 Num(u32),
7378 Priority(u32),
7379 Devs(IterableHookDevAttrs<'a>),
7380}
7381impl<'a> IterableFlowtableHookAttrs<'a> {
7382 pub fn get_num(&self) -> Result<u32, ErrorContext> {
7383 let mut iter = self.clone();
7384 iter.pos = 0;
7385 for attr in iter {
7386 if let FlowtableHookAttrs::Num(val) = attr? {
7387 return Ok(val);
7388 }
7389 }
7390 Err(ErrorContext::new_missing(
7391 "FlowtableHookAttrs",
7392 "Num",
7393 self.orig_loc,
7394 self.buf.as_ptr() as usize,
7395 ))
7396 }
7397 pub fn get_priority(&self) -> Result<u32, ErrorContext> {
7398 let mut iter = self.clone();
7399 iter.pos = 0;
7400 for attr in iter {
7401 if let FlowtableHookAttrs::Priority(val) = attr? {
7402 return Ok(val);
7403 }
7404 }
7405 Err(ErrorContext::new_missing(
7406 "FlowtableHookAttrs",
7407 "Priority",
7408 self.orig_loc,
7409 self.buf.as_ptr() as usize,
7410 ))
7411 }
7412 pub fn get_devs(&self) -> Result<IterableHookDevAttrs<'a>, ErrorContext> {
7413 let mut iter = self.clone();
7414 iter.pos = 0;
7415 for attr in iter {
7416 if let FlowtableHookAttrs::Devs(val) = attr? {
7417 return Ok(val);
7418 }
7419 }
7420 Err(ErrorContext::new_missing(
7421 "FlowtableHookAttrs",
7422 "Devs",
7423 self.orig_loc,
7424 self.buf.as_ptr() as usize,
7425 ))
7426 }
7427}
7428impl<'a> FlowtableHookAttrs<'a> {
7429 pub fn new(buf: &'a [u8]) -> IterableFlowtableHookAttrs<'a> {
7430 IterableFlowtableHookAttrs::with_loc(buf, buf.as_ptr() as usize)
7431 }
7432 fn attr_from_type(r#type: u16) -> Option<&'static str> {
7433 let res = match r#type {
7434 1u16 => "Num",
7435 2u16 => "Priority",
7436 3u16 => "Devs",
7437 _ => return None,
7438 };
7439 Some(res)
7440 }
7441}
7442#[derive(Clone, Copy, Default)]
7443pub struct IterableFlowtableHookAttrs<'a> {
7444 buf: &'a [u8],
7445 pos: usize,
7446 orig_loc: usize,
7447}
7448impl<'a> IterableFlowtableHookAttrs<'a> {
7449 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
7450 Self {
7451 buf,
7452 pos: 0,
7453 orig_loc,
7454 }
7455 }
7456 pub fn get_buf(&self) -> &'a [u8] {
7457 self.buf
7458 }
7459}
7460impl<'a> Iterator for IterableFlowtableHookAttrs<'a> {
7461 type Item = Result<FlowtableHookAttrs<'a>, ErrorContext>;
7462 fn next(&mut self) -> Option<Self::Item> {
7463 if self.buf.len() == self.pos {
7464 return None;
7465 }
7466 let pos = self.pos;
7467 let mut r#type = None;
7468 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
7469 r#type = Some(header.r#type);
7470 let res = match header.r#type {
7471 1u16 => FlowtableHookAttrs::Num({
7472 let res = parse_be_u32(next);
7473 let Some(val) = res else { break };
7474 val
7475 }),
7476 2u16 => FlowtableHookAttrs::Priority({
7477 let res = parse_be_u32(next);
7478 let Some(val) = res else { break };
7479 val
7480 }),
7481 3u16 => FlowtableHookAttrs::Devs({
7482 let res = Some(IterableHookDevAttrs::with_loc(next, self.orig_loc));
7483 let Some(val) = res else { break };
7484 val
7485 }),
7486 n => {
7487 if cfg!(any(test, feature = "deny-unknown-attrs")) {
7488 break;
7489 } else {
7490 continue;
7491 }
7492 }
7493 };
7494 return Some(Ok(res));
7495 }
7496 Some(Err(ErrorContext::new(
7497 "FlowtableHookAttrs",
7498 r#type.and_then(|t| FlowtableHookAttrs::attr_from_type(t)),
7499 self.orig_loc,
7500 self.buf.as_ptr().wrapping_add(pos) as usize,
7501 )))
7502 }
7503}
7504impl<'a> std::fmt::Debug for IterableFlowtableHookAttrs<'_> {
7505 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7506 let mut fmt = f.debug_struct("FlowtableHookAttrs");
7507 for attr in self.clone() {
7508 let attr = match attr {
7509 Ok(a) => a,
7510 Err(err) => {
7511 fmt.finish()?;
7512 f.write_str("Err(")?;
7513 err.fmt(f)?;
7514 return f.write_str(")");
7515 }
7516 };
7517 match attr {
7518 FlowtableHookAttrs::Num(val) => fmt.field("Num", &val),
7519 FlowtableHookAttrs::Priority(val) => fmt.field("Priority", &val),
7520 FlowtableHookAttrs::Devs(val) => fmt.field("Devs", &val),
7521 };
7522 }
7523 fmt.finish()
7524 }
7525}
7526impl IterableFlowtableHookAttrs<'_> {
7527 pub fn lookup_attr(
7528 &self,
7529 offset: usize,
7530 missing_type: Option<u16>,
7531 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
7532 let mut stack = Vec::new();
7533 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
7534 if cur == offset {
7535 stack.push(("FlowtableHookAttrs", offset));
7536 return (
7537 stack,
7538 missing_type.and_then(|t| FlowtableHookAttrs::attr_from_type(t)),
7539 );
7540 }
7541 if cur > offset || cur + self.buf.len() < offset {
7542 return (stack, None);
7543 }
7544 let mut attrs = self.clone();
7545 let mut last_off = cur + attrs.pos;
7546 let mut missing = None;
7547 while let Some(attr) = attrs.next() {
7548 let Ok(attr) = attr else { break };
7549 match attr {
7550 FlowtableHookAttrs::Num(val) => {
7551 if last_off == offset {
7552 stack.push(("Num", last_off));
7553 break;
7554 }
7555 }
7556 FlowtableHookAttrs::Priority(val) => {
7557 if last_off == offset {
7558 stack.push(("Priority", last_off));
7559 break;
7560 }
7561 }
7562 FlowtableHookAttrs::Devs(val) => {
7563 (stack, missing) = val.lookup_attr(offset, missing_type);
7564 if !stack.is_empty() {
7565 break;
7566 }
7567 }
7568 _ => {}
7569 };
7570 last_off = cur + attrs.pos;
7571 }
7572 if !stack.is_empty() {
7573 stack.push(("FlowtableHookAttrs", cur));
7574 }
7575 (stack, missing)
7576 }
7577}
7578#[derive(Clone)]
7579pub enum ExprBitwiseAttrs<'a> {
7580 Sreg(u32),
7581 Dreg(u32),
7582 Len(u32),
7583 Mask(IterableDataAttrs<'a>),
7584 Xor(IterableDataAttrs<'a>),
7585 #[doc = "Associated type: \"BitwiseOps\" (enum)"]
7586 Op(u32),
7587 Data(IterableDataAttrs<'a>),
7588}
7589impl<'a> IterableExprBitwiseAttrs<'a> {
7590 pub fn get_sreg(&self) -> Result<u32, ErrorContext> {
7591 let mut iter = self.clone();
7592 iter.pos = 0;
7593 for attr in iter {
7594 if let ExprBitwiseAttrs::Sreg(val) = attr? {
7595 return Ok(val);
7596 }
7597 }
7598 Err(ErrorContext::new_missing(
7599 "ExprBitwiseAttrs",
7600 "Sreg",
7601 self.orig_loc,
7602 self.buf.as_ptr() as usize,
7603 ))
7604 }
7605 pub fn get_dreg(&self) -> Result<u32, ErrorContext> {
7606 let mut iter = self.clone();
7607 iter.pos = 0;
7608 for attr in iter {
7609 if let ExprBitwiseAttrs::Dreg(val) = attr? {
7610 return Ok(val);
7611 }
7612 }
7613 Err(ErrorContext::new_missing(
7614 "ExprBitwiseAttrs",
7615 "Dreg",
7616 self.orig_loc,
7617 self.buf.as_ptr() as usize,
7618 ))
7619 }
7620 pub fn get_len(&self) -> Result<u32, ErrorContext> {
7621 let mut iter = self.clone();
7622 iter.pos = 0;
7623 for attr in iter {
7624 if let ExprBitwiseAttrs::Len(val) = attr? {
7625 return Ok(val);
7626 }
7627 }
7628 Err(ErrorContext::new_missing(
7629 "ExprBitwiseAttrs",
7630 "Len",
7631 self.orig_loc,
7632 self.buf.as_ptr() as usize,
7633 ))
7634 }
7635 pub fn get_mask(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
7636 let mut iter = self.clone();
7637 iter.pos = 0;
7638 for attr in iter {
7639 if let ExprBitwiseAttrs::Mask(val) = attr? {
7640 return Ok(val);
7641 }
7642 }
7643 Err(ErrorContext::new_missing(
7644 "ExprBitwiseAttrs",
7645 "Mask",
7646 self.orig_loc,
7647 self.buf.as_ptr() as usize,
7648 ))
7649 }
7650 pub fn get_xor(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
7651 let mut iter = self.clone();
7652 iter.pos = 0;
7653 for attr in iter {
7654 if let ExprBitwiseAttrs::Xor(val) = attr? {
7655 return Ok(val);
7656 }
7657 }
7658 Err(ErrorContext::new_missing(
7659 "ExprBitwiseAttrs",
7660 "Xor",
7661 self.orig_loc,
7662 self.buf.as_ptr() as usize,
7663 ))
7664 }
7665 #[doc = "Associated type: \"BitwiseOps\" (enum)"]
7666 pub fn get_op(&self) -> Result<u32, ErrorContext> {
7667 let mut iter = self.clone();
7668 iter.pos = 0;
7669 for attr in iter {
7670 if let ExprBitwiseAttrs::Op(val) = attr? {
7671 return Ok(val);
7672 }
7673 }
7674 Err(ErrorContext::new_missing(
7675 "ExprBitwiseAttrs",
7676 "Op",
7677 self.orig_loc,
7678 self.buf.as_ptr() as usize,
7679 ))
7680 }
7681 pub fn get_data(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
7682 let mut iter = self.clone();
7683 iter.pos = 0;
7684 for attr in iter {
7685 if let ExprBitwiseAttrs::Data(val) = attr? {
7686 return Ok(val);
7687 }
7688 }
7689 Err(ErrorContext::new_missing(
7690 "ExprBitwiseAttrs",
7691 "Data",
7692 self.orig_loc,
7693 self.buf.as_ptr() as usize,
7694 ))
7695 }
7696}
7697impl<'a> ExprBitwiseAttrs<'a> {
7698 pub fn new(buf: &'a [u8]) -> IterableExprBitwiseAttrs<'a> {
7699 IterableExprBitwiseAttrs::with_loc(buf, buf.as_ptr() as usize)
7700 }
7701 fn attr_from_type(r#type: u16) -> Option<&'static str> {
7702 let res = match r#type {
7703 1u16 => "Sreg",
7704 2u16 => "Dreg",
7705 3u16 => "Len",
7706 4u16 => "Mask",
7707 5u16 => "Xor",
7708 6u16 => "Op",
7709 7u16 => "Data",
7710 _ => return None,
7711 };
7712 Some(res)
7713 }
7714}
7715#[derive(Clone, Copy, Default)]
7716pub struct IterableExprBitwiseAttrs<'a> {
7717 buf: &'a [u8],
7718 pos: usize,
7719 orig_loc: usize,
7720}
7721impl<'a> IterableExprBitwiseAttrs<'a> {
7722 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
7723 Self {
7724 buf,
7725 pos: 0,
7726 orig_loc,
7727 }
7728 }
7729 pub fn get_buf(&self) -> &'a [u8] {
7730 self.buf
7731 }
7732}
7733impl<'a> Iterator for IterableExprBitwiseAttrs<'a> {
7734 type Item = Result<ExprBitwiseAttrs<'a>, ErrorContext>;
7735 fn next(&mut self) -> Option<Self::Item> {
7736 if self.buf.len() == self.pos {
7737 return None;
7738 }
7739 let pos = self.pos;
7740 let mut r#type = None;
7741 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
7742 r#type = Some(header.r#type);
7743 let res = match header.r#type {
7744 1u16 => ExprBitwiseAttrs::Sreg({
7745 let res = parse_be_u32(next);
7746 let Some(val) = res else { break };
7747 val
7748 }),
7749 2u16 => ExprBitwiseAttrs::Dreg({
7750 let res = parse_be_u32(next);
7751 let Some(val) = res else { break };
7752 val
7753 }),
7754 3u16 => ExprBitwiseAttrs::Len({
7755 let res = parse_be_u32(next);
7756 let Some(val) = res else { break };
7757 val
7758 }),
7759 4u16 => ExprBitwiseAttrs::Mask({
7760 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
7761 let Some(val) = res else { break };
7762 val
7763 }),
7764 5u16 => ExprBitwiseAttrs::Xor({
7765 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
7766 let Some(val) = res else { break };
7767 val
7768 }),
7769 6u16 => ExprBitwiseAttrs::Op({
7770 let res = parse_be_u32(next);
7771 let Some(val) = res else { break };
7772 val
7773 }),
7774 7u16 => ExprBitwiseAttrs::Data({
7775 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
7776 let Some(val) = res else { break };
7777 val
7778 }),
7779 n => {
7780 if cfg!(any(test, feature = "deny-unknown-attrs")) {
7781 break;
7782 } else {
7783 continue;
7784 }
7785 }
7786 };
7787 return Some(Ok(res));
7788 }
7789 Some(Err(ErrorContext::new(
7790 "ExprBitwiseAttrs",
7791 r#type.and_then(|t| ExprBitwiseAttrs::attr_from_type(t)),
7792 self.orig_loc,
7793 self.buf.as_ptr().wrapping_add(pos) as usize,
7794 )))
7795 }
7796}
7797impl<'a> std::fmt::Debug for IterableExprBitwiseAttrs<'_> {
7798 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7799 let mut fmt = f.debug_struct("ExprBitwiseAttrs");
7800 for attr in self.clone() {
7801 let attr = match attr {
7802 Ok(a) => a,
7803 Err(err) => {
7804 fmt.finish()?;
7805 f.write_str("Err(")?;
7806 err.fmt(f)?;
7807 return f.write_str(")");
7808 }
7809 };
7810 match attr {
7811 ExprBitwiseAttrs::Sreg(val) => fmt.field("Sreg", &val),
7812 ExprBitwiseAttrs::Dreg(val) => fmt.field("Dreg", &val),
7813 ExprBitwiseAttrs::Len(val) => fmt.field("Len", &val),
7814 ExprBitwiseAttrs::Mask(val) => fmt.field("Mask", &val),
7815 ExprBitwiseAttrs::Xor(val) => fmt.field("Xor", &val),
7816 ExprBitwiseAttrs::Op(val) => {
7817 fmt.field("Op", &FormatEnum(val.into(), BitwiseOps::from_value))
7818 }
7819 ExprBitwiseAttrs::Data(val) => fmt.field("Data", &val),
7820 };
7821 }
7822 fmt.finish()
7823 }
7824}
7825impl IterableExprBitwiseAttrs<'_> {
7826 pub fn lookup_attr(
7827 &self,
7828 offset: usize,
7829 missing_type: Option<u16>,
7830 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
7831 let mut stack = Vec::new();
7832 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
7833 if cur == offset {
7834 stack.push(("ExprBitwiseAttrs", offset));
7835 return (
7836 stack,
7837 missing_type.and_then(|t| ExprBitwiseAttrs::attr_from_type(t)),
7838 );
7839 }
7840 if cur > offset || cur + self.buf.len() < offset {
7841 return (stack, None);
7842 }
7843 let mut attrs = self.clone();
7844 let mut last_off = cur + attrs.pos;
7845 let mut missing = None;
7846 while let Some(attr) = attrs.next() {
7847 let Ok(attr) = attr else { break };
7848 match attr {
7849 ExprBitwiseAttrs::Sreg(val) => {
7850 if last_off == offset {
7851 stack.push(("Sreg", last_off));
7852 break;
7853 }
7854 }
7855 ExprBitwiseAttrs::Dreg(val) => {
7856 if last_off == offset {
7857 stack.push(("Dreg", last_off));
7858 break;
7859 }
7860 }
7861 ExprBitwiseAttrs::Len(val) => {
7862 if last_off == offset {
7863 stack.push(("Len", last_off));
7864 break;
7865 }
7866 }
7867 ExprBitwiseAttrs::Mask(val) => {
7868 (stack, missing) = val.lookup_attr(offset, missing_type);
7869 if !stack.is_empty() {
7870 break;
7871 }
7872 }
7873 ExprBitwiseAttrs::Xor(val) => {
7874 (stack, missing) = val.lookup_attr(offset, missing_type);
7875 if !stack.is_empty() {
7876 break;
7877 }
7878 }
7879 ExprBitwiseAttrs::Op(val) => {
7880 if last_off == offset {
7881 stack.push(("Op", last_off));
7882 break;
7883 }
7884 }
7885 ExprBitwiseAttrs::Data(val) => {
7886 (stack, missing) = val.lookup_attr(offset, missing_type);
7887 if !stack.is_empty() {
7888 break;
7889 }
7890 }
7891 _ => {}
7892 };
7893 last_off = cur + attrs.pos;
7894 }
7895 if !stack.is_empty() {
7896 stack.push(("ExprBitwiseAttrs", cur));
7897 }
7898 (stack, missing)
7899 }
7900}
7901#[derive(Clone)]
7902pub enum ExprCmpAttrs<'a> {
7903 Sreg(u32),
7904 #[doc = "Associated type: \"CmpOps\" (enum)"]
7905 Op(u32),
7906 Data(IterableDataAttrs<'a>),
7907}
7908impl<'a> IterableExprCmpAttrs<'a> {
7909 pub fn get_sreg(&self) -> Result<u32, ErrorContext> {
7910 let mut iter = self.clone();
7911 iter.pos = 0;
7912 for attr in iter {
7913 if let ExprCmpAttrs::Sreg(val) = attr? {
7914 return Ok(val);
7915 }
7916 }
7917 Err(ErrorContext::new_missing(
7918 "ExprCmpAttrs",
7919 "Sreg",
7920 self.orig_loc,
7921 self.buf.as_ptr() as usize,
7922 ))
7923 }
7924 #[doc = "Associated type: \"CmpOps\" (enum)"]
7925 pub fn get_op(&self) -> Result<u32, ErrorContext> {
7926 let mut iter = self.clone();
7927 iter.pos = 0;
7928 for attr in iter {
7929 if let ExprCmpAttrs::Op(val) = attr? {
7930 return Ok(val);
7931 }
7932 }
7933 Err(ErrorContext::new_missing(
7934 "ExprCmpAttrs",
7935 "Op",
7936 self.orig_loc,
7937 self.buf.as_ptr() as usize,
7938 ))
7939 }
7940 pub fn get_data(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
7941 let mut iter = self.clone();
7942 iter.pos = 0;
7943 for attr in iter {
7944 if let ExprCmpAttrs::Data(val) = attr? {
7945 return Ok(val);
7946 }
7947 }
7948 Err(ErrorContext::new_missing(
7949 "ExprCmpAttrs",
7950 "Data",
7951 self.orig_loc,
7952 self.buf.as_ptr() as usize,
7953 ))
7954 }
7955}
7956impl<'a> ExprCmpAttrs<'a> {
7957 pub fn new(buf: &'a [u8]) -> IterableExprCmpAttrs<'a> {
7958 IterableExprCmpAttrs::with_loc(buf, buf.as_ptr() as usize)
7959 }
7960 fn attr_from_type(r#type: u16) -> Option<&'static str> {
7961 let res = match r#type {
7962 1u16 => "Sreg",
7963 2u16 => "Op",
7964 3u16 => "Data",
7965 _ => return None,
7966 };
7967 Some(res)
7968 }
7969}
7970#[derive(Clone, Copy, Default)]
7971pub struct IterableExprCmpAttrs<'a> {
7972 buf: &'a [u8],
7973 pos: usize,
7974 orig_loc: usize,
7975}
7976impl<'a> IterableExprCmpAttrs<'a> {
7977 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
7978 Self {
7979 buf,
7980 pos: 0,
7981 orig_loc,
7982 }
7983 }
7984 pub fn get_buf(&self) -> &'a [u8] {
7985 self.buf
7986 }
7987}
7988impl<'a> Iterator for IterableExprCmpAttrs<'a> {
7989 type Item = Result<ExprCmpAttrs<'a>, ErrorContext>;
7990 fn next(&mut self) -> Option<Self::Item> {
7991 if self.buf.len() == self.pos {
7992 return None;
7993 }
7994 let pos = self.pos;
7995 let mut r#type = None;
7996 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
7997 r#type = Some(header.r#type);
7998 let res = match header.r#type {
7999 1u16 => ExprCmpAttrs::Sreg({
8000 let res = parse_be_u32(next);
8001 let Some(val) = res else { break };
8002 val
8003 }),
8004 2u16 => ExprCmpAttrs::Op({
8005 let res = parse_be_u32(next);
8006 let Some(val) = res else { break };
8007 val
8008 }),
8009 3u16 => ExprCmpAttrs::Data({
8010 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
8011 let Some(val) = res else { break };
8012 val
8013 }),
8014 n => {
8015 if cfg!(any(test, feature = "deny-unknown-attrs")) {
8016 break;
8017 } else {
8018 continue;
8019 }
8020 }
8021 };
8022 return Some(Ok(res));
8023 }
8024 Some(Err(ErrorContext::new(
8025 "ExprCmpAttrs",
8026 r#type.and_then(|t| ExprCmpAttrs::attr_from_type(t)),
8027 self.orig_loc,
8028 self.buf.as_ptr().wrapping_add(pos) as usize,
8029 )))
8030 }
8031}
8032impl<'a> std::fmt::Debug for IterableExprCmpAttrs<'_> {
8033 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8034 let mut fmt = f.debug_struct("ExprCmpAttrs");
8035 for attr in self.clone() {
8036 let attr = match attr {
8037 Ok(a) => a,
8038 Err(err) => {
8039 fmt.finish()?;
8040 f.write_str("Err(")?;
8041 err.fmt(f)?;
8042 return f.write_str(")");
8043 }
8044 };
8045 match attr {
8046 ExprCmpAttrs::Sreg(val) => fmt.field("Sreg", &val),
8047 ExprCmpAttrs::Op(val) => {
8048 fmt.field("Op", &FormatEnum(val.into(), CmpOps::from_value))
8049 }
8050 ExprCmpAttrs::Data(val) => fmt.field("Data", &val),
8051 };
8052 }
8053 fmt.finish()
8054 }
8055}
8056impl IterableExprCmpAttrs<'_> {
8057 pub fn lookup_attr(
8058 &self,
8059 offset: usize,
8060 missing_type: Option<u16>,
8061 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
8062 let mut stack = Vec::new();
8063 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
8064 if cur == offset {
8065 stack.push(("ExprCmpAttrs", offset));
8066 return (
8067 stack,
8068 missing_type.and_then(|t| ExprCmpAttrs::attr_from_type(t)),
8069 );
8070 }
8071 if cur > offset || cur + self.buf.len() < offset {
8072 return (stack, None);
8073 }
8074 let mut attrs = self.clone();
8075 let mut last_off = cur + attrs.pos;
8076 let mut missing = None;
8077 while let Some(attr) = attrs.next() {
8078 let Ok(attr) = attr else { break };
8079 match attr {
8080 ExprCmpAttrs::Sreg(val) => {
8081 if last_off == offset {
8082 stack.push(("Sreg", last_off));
8083 break;
8084 }
8085 }
8086 ExprCmpAttrs::Op(val) => {
8087 if last_off == offset {
8088 stack.push(("Op", last_off));
8089 break;
8090 }
8091 }
8092 ExprCmpAttrs::Data(val) => {
8093 (stack, missing) = val.lookup_attr(offset, missing_type);
8094 if !stack.is_empty() {
8095 break;
8096 }
8097 }
8098 _ => {}
8099 };
8100 last_off = cur + attrs.pos;
8101 }
8102 if !stack.is_empty() {
8103 stack.push(("ExprCmpAttrs", cur));
8104 }
8105 (stack, missing)
8106 }
8107}
8108#[derive(Clone)]
8109pub enum DataAttrs<'a> {
8110 Value(&'a [u8]),
8111 Verdict(IterableVerdictAttrs<'a>),
8112}
8113impl<'a> IterableDataAttrs<'a> {
8114 pub fn get_value(&self) -> Result<&'a [u8], ErrorContext> {
8115 let mut iter = self.clone();
8116 iter.pos = 0;
8117 for attr in iter {
8118 if let DataAttrs::Value(val) = attr? {
8119 return Ok(val);
8120 }
8121 }
8122 Err(ErrorContext::new_missing(
8123 "DataAttrs",
8124 "Value",
8125 self.orig_loc,
8126 self.buf.as_ptr() as usize,
8127 ))
8128 }
8129 pub fn get_verdict(&self) -> Result<IterableVerdictAttrs<'a>, ErrorContext> {
8130 let mut iter = self.clone();
8131 iter.pos = 0;
8132 for attr in iter {
8133 if let DataAttrs::Verdict(val) = attr? {
8134 return Ok(val);
8135 }
8136 }
8137 Err(ErrorContext::new_missing(
8138 "DataAttrs",
8139 "Verdict",
8140 self.orig_loc,
8141 self.buf.as_ptr() as usize,
8142 ))
8143 }
8144}
8145impl<'a> DataAttrs<'a> {
8146 pub fn new(buf: &'a [u8]) -> IterableDataAttrs<'a> {
8147 IterableDataAttrs::with_loc(buf, buf.as_ptr() as usize)
8148 }
8149 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8150 let res = match r#type {
8151 1u16 => "Value",
8152 2u16 => "Verdict",
8153 _ => return None,
8154 };
8155 Some(res)
8156 }
8157}
8158#[derive(Clone, Copy, Default)]
8159pub struct IterableDataAttrs<'a> {
8160 buf: &'a [u8],
8161 pos: usize,
8162 orig_loc: usize,
8163}
8164impl<'a> IterableDataAttrs<'a> {
8165 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
8166 Self {
8167 buf,
8168 pos: 0,
8169 orig_loc,
8170 }
8171 }
8172 pub fn get_buf(&self) -> &'a [u8] {
8173 self.buf
8174 }
8175}
8176impl<'a> Iterator for IterableDataAttrs<'a> {
8177 type Item = Result<DataAttrs<'a>, ErrorContext>;
8178 fn next(&mut self) -> Option<Self::Item> {
8179 if self.buf.len() == self.pos {
8180 return None;
8181 }
8182 let pos = self.pos;
8183 let mut r#type = None;
8184 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
8185 r#type = Some(header.r#type);
8186 let res = match header.r#type {
8187 1u16 => DataAttrs::Value({
8188 let res = Some(next);
8189 let Some(val) = res else { break };
8190 val
8191 }),
8192 2u16 => DataAttrs::Verdict({
8193 let res = Some(IterableVerdictAttrs::with_loc(next, self.orig_loc));
8194 let Some(val) = res else { break };
8195 val
8196 }),
8197 n => {
8198 if cfg!(any(test, feature = "deny-unknown-attrs")) {
8199 break;
8200 } else {
8201 continue;
8202 }
8203 }
8204 };
8205 return Some(Ok(res));
8206 }
8207 Some(Err(ErrorContext::new(
8208 "DataAttrs",
8209 r#type.and_then(|t| DataAttrs::attr_from_type(t)),
8210 self.orig_loc,
8211 self.buf.as_ptr().wrapping_add(pos) as usize,
8212 )))
8213 }
8214}
8215impl<'a> std::fmt::Debug for IterableDataAttrs<'_> {
8216 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8217 let mut fmt = f.debug_struct("DataAttrs");
8218 for attr in self.clone() {
8219 let attr = match attr {
8220 Ok(a) => a,
8221 Err(err) => {
8222 fmt.finish()?;
8223 f.write_str("Err(")?;
8224 err.fmt(f)?;
8225 return f.write_str(")");
8226 }
8227 };
8228 match attr {
8229 DataAttrs::Value(val) => fmt.field("Value", &val),
8230 DataAttrs::Verdict(val) => fmt.field("Verdict", &val),
8231 };
8232 }
8233 fmt.finish()
8234 }
8235}
8236impl IterableDataAttrs<'_> {
8237 pub fn lookup_attr(
8238 &self,
8239 offset: usize,
8240 missing_type: Option<u16>,
8241 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
8242 let mut stack = Vec::new();
8243 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
8244 if cur == offset {
8245 stack.push(("DataAttrs", offset));
8246 return (
8247 stack,
8248 missing_type.and_then(|t| DataAttrs::attr_from_type(t)),
8249 );
8250 }
8251 if cur > offset || cur + self.buf.len() < offset {
8252 return (stack, None);
8253 }
8254 let mut attrs = self.clone();
8255 let mut last_off = cur + attrs.pos;
8256 let mut missing = None;
8257 while let Some(attr) = attrs.next() {
8258 let Ok(attr) = attr else { break };
8259 match attr {
8260 DataAttrs::Value(val) => {
8261 if last_off == offset {
8262 stack.push(("Value", last_off));
8263 break;
8264 }
8265 }
8266 DataAttrs::Verdict(val) => {
8267 (stack, missing) = val.lookup_attr(offset, missing_type);
8268 if !stack.is_empty() {
8269 break;
8270 }
8271 }
8272 _ => {}
8273 };
8274 last_off = cur + attrs.pos;
8275 }
8276 if !stack.is_empty() {
8277 stack.push(("DataAttrs", cur));
8278 }
8279 (stack, missing)
8280 }
8281}
8282#[derive(Clone)]
8283pub enum VerdictAttrs<'a> {
8284 #[doc = "nf_tables verdict\nAssociated type: \"VerdictCode\" (enum)"]
8285 Code(u32),
8286 #[doc = "jump target chain name"]
8287 Chain(&'a CStr),
8288 #[doc = "jump target chain ID"]
8289 ChainId(u32),
8290}
8291impl<'a> IterableVerdictAttrs<'a> {
8292 #[doc = "nf_tables verdict\nAssociated type: \"VerdictCode\" (enum)"]
8293 pub fn get_code(&self) -> Result<u32, ErrorContext> {
8294 let mut iter = self.clone();
8295 iter.pos = 0;
8296 for attr in iter {
8297 if let VerdictAttrs::Code(val) = attr? {
8298 return Ok(val);
8299 }
8300 }
8301 Err(ErrorContext::new_missing(
8302 "VerdictAttrs",
8303 "Code",
8304 self.orig_loc,
8305 self.buf.as_ptr() as usize,
8306 ))
8307 }
8308 #[doc = "jump target chain name"]
8309 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
8310 let mut iter = self.clone();
8311 iter.pos = 0;
8312 for attr in iter {
8313 if let VerdictAttrs::Chain(val) = attr? {
8314 return Ok(val);
8315 }
8316 }
8317 Err(ErrorContext::new_missing(
8318 "VerdictAttrs",
8319 "Chain",
8320 self.orig_loc,
8321 self.buf.as_ptr() as usize,
8322 ))
8323 }
8324 #[doc = "jump target chain ID"]
8325 pub fn get_chain_id(&self) -> Result<u32, ErrorContext> {
8326 let mut iter = self.clone();
8327 iter.pos = 0;
8328 for attr in iter {
8329 if let VerdictAttrs::ChainId(val) = attr? {
8330 return Ok(val);
8331 }
8332 }
8333 Err(ErrorContext::new_missing(
8334 "VerdictAttrs",
8335 "ChainId",
8336 self.orig_loc,
8337 self.buf.as_ptr() as usize,
8338 ))
8339 }
8340}
8341impl<'a> VerdictAttrs<'a> {
8342 pub fn new(buf: &'a [u8]) -> IterableVerdictAttrs<'a> {
8343 IterableVerdictAttrs::with_loc(buf, buf.as_ptr() as usize)
8344 }
8345 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8346 let res = match r#type {
8347 1u16 => "Code",
8348 2u16 => "Chain",
8349 3u16 => "ChainId",
8350 _ => return None,
8351 };
8352 Some(res)
8353 }
8354}
8355#[derive(Clone, Copy, Default)]
8356pub struct IterableVerdictAttrs<'a> {
8357 buf: &'a [u8],
8358 pos: usize,
8359 orig_loc: usize,
8360}
8361impl<'a> IterableVerdictAttrs<'a> {
8362 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
8363 Self {
8364 buf,
8365 pos: 0,
8366 orig_loc,
8367 }
8368 }
8369 pub fn get_buf(&self) -> &'a [u8] {
8370 self.buf
8371 }
8372}
8373impl<'a> Iterator for IterableVerdictAttrs<'a> {
8374 type Item = Result<VerdictAttrs<'a>, ErrorContext>;
8375 fn next(&mut self) -> Option<Self::Item> {
8376 if self.buf.len() == self.pos {
8377 return None;
8378 }
8379 let pos = self.pos;
8380 let mut r#type = None;
8381 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
8382 r#type = Some(header.r#type);
8383 let res = match header.r#type {
8384 1u16 => VerdictAttrs::Code({
8385 let res = parse_be_u32(next);
8386 let Some(val) = res else { break };
8387 val
8388 }),
8389 2u16 => VerdictAttrs::Chain({
8390 let res = CStr::from_bytes_with_nul(next).ok();
8391 let Some(val) = res else { break };
8392 val
8393 }),
8394 3u16 => VerdictAttrs::ChainId({
8395 let res = parse_be_u32(next);
8396 let Some(val) = res else { break };
8397 val
8398 }),
8399 n => {
8400 if cfg!(any(test, feature = "deny-unknown-attrs")) {
8401 break;
8402 } else {
8403 continue;
8404 }
8405 }
8406 };
8407 return Some(Ok(res));
8408 }
8409 Some(Err(ErrorContext::new(
8410 "VerdictAttrs",
8411 r#type.and_then(|t| VerdictAttrs::attr_from_type(t)),
8412 self.orig_loc,
8413 self.buf.as_ptr().wrapping_add(pos) as usize,
8414 )))
8415 }
8416}
8417impl<'a> std::fmt::Debug for IterableVerdictAttrs<'_> {
8418 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8419 let mut fmt = f.debug_struct("VerdictAttrs");
8420 for attr in self.clone() {
8421 let attr = match attr {
8422 Ok(a) => a,
8423 Err(err) => {
8424 fmt.finish()?;
8425 f.write_str("Err(")?;
8426 err.fmt(f)?;
8427 return f.write_str(")");
8428 }
8429 };
8430 match attr {
8431 VerdictAttrs::Code(val) => {
8432 fmt.field("Code", &FormatEnum(val.into(), VerdictCode::from_value))
8433 }
8434 VerdictAttrs::Chain(val) => fmt.field("Chain", &val),
8435 VerdictAttrs::ChainId(val) => fmt.field("ChainId", &val),
8436 };
8437 }
8438 fmt.finish()
8439 }
8440}
8441impl IterableVerdictAttrs<'_> {
8442 pub fn lookup_attr(
8443 &self,
8444 offset: usize,
8445 missing_type: Option<u16>,
8446 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
8447 let mut stack = Vec::new();
8448 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
8449 if cur == offset {
8450 stack.push(("VerdictAttrs", offset));
8451 return (
8452 stack,
8453 missing_type.and_then(|t| VerdictAttrs::attr_from_type(t)),
8454 );
8455 }
8456 if cur > offset || cur + self.buf.len() < offset {
8457 return (stack, None);
8458 }
8459 let mut attrs = self.clone();
8460 let mut last_off = cur + attrs.pos;
8461 while let Some(attr) = attrs.next() {
8462 let Ok(attr) = attr else { break };
8463 match attr {
8464 VerdictAttrs::Code(val) => {
8465 if last_off == offset {
8466 stack.push(("Code", last_off));
8467 break;
8468 }
8469 }
8470 VerdictAttrs::Chain(val) => {
8471 if last_off == offset {
8472 stack.push(("Chain", last_off));
8473 break;
8474 }
8475 }
8476 VerdictAttrs::ChainId(val) => {
8477 if last_off == offset {
8478 stack.push(("ChainId", last_off));
8479 break;
8480 }
8481 }
8482 _ => {}
8483 };
8484 last_off = cur + attrs.pos;
8485 }
8486 if !stack.is_empty() {
8487 stack.push(("VerdictAttrs", cur));
8488 }
8489 (stack, None)
8490 }
8491}
8492#[derive(Clone)]
8493pub enum ExprCounterAttrs<'a> {
8494 #[doc = "Number of bytes"]
8495 Bytes(u64),
8496 #[doc = "Number of packets"]
8497 Packets(u64),
8498 Pad(&'a [u8]),
8499}
8500impl<'a> IterableExprCounterAttrs<'a> {
8501 #[doc = "Number of bytes"]
8502 pub fn get_bytes(&self) -> Result<u64, ErrorContext> {
8503 let mut iter = self.clone();
8504 iter.pos = 0;
8505 for attr in iter {
8506 if let ExprCounterAttrs::Bytes(val) = attr? {
8507 return Ok(val);
8508 }
8509 }
8510 Err(ErrorContext::new_missing(
8511 "ExprCounterAttrs",
8512 "Bytes",
8513 self.orig_loc,
8514 self.buf.as_ptr() as usize,
8515 ))
8516 }
8517 #[doc = "Number of packets"]
8518 pub fn get_packets(&self) -> Result<u64, ErrorContext> {
8519 let mut iter = self.clone();
8520 iter.pos = 0;
8521 for attr in iter {
8522 if let ExprCounterAttrs::Packets(val) = attr? {
8523 return Ok(val);
8524 }
8525 }
8526 Err(ErrorContext::new_missing(
8527 "ExprCounterAttrs",
8528 "Packets",
8529 self.orig_loc,
8530 self.buf.as_ptr() as usize,
8531 ))
8532 }
8533 pub fn get_pad(&self) -> Result<&'a [u8], ErrorContext> {
8534 let mut iter = self.clone();
8535 iter.pos = 0;
8536 for attr in iter {
8537 if let ExprCounterAttrs::Pad(val) = attr? {
8538 return Ok(val);
8539 }
8540 }
8541 Err(ErrorContext::new_missing(
8542 "ExprCounterAttrs",
8543 "Pad",
8544 self.orig_loc,
8545 self.buf.as_ptr() as usize,
8546 ))
8547 }
8548}
8549impl<'a> ExprCounterAttrs<'a> {
8550 pub fn new(buf: &'a [u8]) -> IterableExprCounterAttrs<'a> {
8551 IterableExprCounterAttrs::with_loc(buf, buf.as_ptr() as usize)
8552 }
8553 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8554 let res = match r#type {
8555 1u16 => "Bytes",
8556 2u16 => "Packets",
8557 3u16 => "Pad",
8558 _ => return None,
8559 };
8560 Some(res)
8561 }
8562}
8563#[derive(Clone, Copy, Default)]
8564pub struct IterableExprCounterAttrs<'a> {
8565 buf: &'a [u8],
8566 pos: usize,
8567 orig_loc: usize,
8568}
8569impl<'a> IterableExprCounterAttrs<'a> {
8570 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
8571 Self {
8572 buf,
8573 pos: 0,
8574 orig_loc,
8575 }
8576 }
8577 pub fn get_buf(&self) -> &'a [u8] {
8578 self.buf
8579 }
8580}
8581impl<'a> Iterator for IterableExprCounterAttrs<'a> {
8582 type Item = Result<ExprCounterAttrs<'a>, ErrorContext>;
8583 fn next(&mut self) -> Option<Self::Item> {
8584 if self.buf.len() == self.pos {
8585 return None;
8586 }
8587 let pos = self.pos;
8588 let mut r#type = None;
8589 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
8590 r#type = Some(header.r#type);
8591 let res = match header.r#type {
8592 1u16 => ExprCounterAttrs::Bytes({
8593 let res = parse_be_u64(next);
8594 let Some(val) = res else { break };
8595 val
8596 }),
8597 2u16 => ExprCounterAttrs::Packets({
8598 let res = parse_be_u64(next);
8599 let Some(val) = res else { break };
8600 val
8601 }),
8602 3u16 => ExprCounterAttrs::Pad({
8603 let res = Some(next);
8604 let Some(val) = res else { break };
8605 val
8606 }),
8607 n => {
8608 if cfg!(any(test, feature = "deny-unknown-attrs")) {
8609 break;
8610 } else {
8611 continue;
8612 }
8613 }
8614 };
8615 return Some(Ok(res));
8616 }
8617 Some(Err(ErrorContext::new(
8618 "ExprCounterAttrs",
8619 r#type.and_then(|t| ExprCounterAttrs::attr_from_type(t)),
8620 self.orig_loc,
8621 self.buf.as_ptr().wrapping_add(pos) as usize,
8622 )))
8623 }
8624}
8625impl<'a> std::fmt::Debug for IterableExprCounterAttrs<'_> {
8626 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8627 let mut fmt = f.debug_struct("ExprCounterAttrs");
8628 for attr in self.clone() {
8629 let attr = match attr {
8630 Ok(a) => a,
8631 Err(err) => {
8632 fmt.finish()?;
8633 f.write_str("Err(")?;
8634 err.fmt(f)?;
8635 return f.write_str(")");
8636 }
8637 };
8638 match attr {
8639 ExprCounterAttrs::Bytes(val) => fmt.field("Bytes", &val),
8640 ExprCounterAttrs::Packets(val) => fmt.field("Packets", &val),
8641 ExprCounterAttrs::Pad(val) => fmt.field("Pad", &val),
8642 };
8643 }
8644 fmt.finish()
8645 }
8646}
8647impl IterableExprCounterAttrs<'_> {
8648 pub fn lookup_attr(
8649 &self,
8650 offset: usize,
8651 missing_type: Option<u16>,
8652 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
8653 let mut stack = Vec::new();
8654 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
8655 if cur == offset {
8656 stack.push(("ExprCounterAttrs", offset));
8657 return (
8658 stack,
8659 missing_type.and_then(|t| ExprCounterAttrs::attr_from_type(t)),
8660 );
8661 }
8662 if cur > offset || cur + self.buf.len() < offset {
8663 return (stack, None);
8664 }
8665 let mut attrs = self.clone();
8666 let mut last_off = cur + attrs.pos;
8667 while let Some(attr) = attrs.next() {
8668 let Ok(attr) = attr else { break };
8669 match attr {
8670 ExprCounterAttrs::Bytes(val) => {
8671 if last_off == offset {
8672 stack.push(("Bytes", last_off));
8673 break;
8674 }
8675 }
8676 ExprCounterAttrs::Packets(val) => {
8677 if last_off == offset {
8678 stack.push(("Packets", last_off));
8679 break;
8680 }
8681 }
8682 ExprCounterAttrs::Pad(val) => {
8683 if last_off == offset {
8684 stack.push(("Pad", last_off));
8685 break;
8686 }
8687 }
8688 _ => {}
8689 };
8690 last_off = cur + attrs.pos;
8691 }
8692 if !stack.is_empty() {
8693 stack.push(("ExprCounterAttrs", cur));
8694 }
8695 (stack, None)
8696 }
8697}
8698#[derive(Clone)]
8699pub enum ExprFibAttrs {
8700 Dreg(u32),
8701 #[doc = "Associated type: \"FibResult\" (enum)"]
8702 Result(u32),
8703 #[doc = "Associated type: \"FibFlags\" (enum)"]
8704 Flags(u32),
8705}
8706impl<'a> IterableExprFibAttrs<'a> {
8707 pub fn get_dreg(&self) -> Result<u32, ErrorContext> {
8708 let mut iter = self.clone();
8709 iter.pos = 0;
8710 for attr in iter {
8711 if let ExprFibAttrs::Dreg(val) = attr? {
8712 return Ok(val);
8713 }
8714 }
8715 Err(ErrorContext::new_missing(
8716 "ExprFibAttrs",
8717 "Dreg",
8718 self.orig_loc,
8719 self.buf.as_ptr() as usize,
8720 ))
8721 }
8722 #[doc = "Associated type: \"FibResult\" (enum)"]
8723 pub fn get_result(&self) -> Result<u32, ErrorContext> {
8724 let mut iter = self.clone();
8725 iter.pos = 0;
8726 for attr in iter {
8727 if let ExprFibAttrs::Result(val) = attr? {
8728 return Ok(val);
8729 }
8730 }
8731 Err(ErrorContext::new_missing(
8732 "ExprFibAttrs",
8733 "Result",
8734 self.orig_loc,
8735 self.buf.as_ptr() as usize,
8736 ))
8737 }
8738 #[doc = "Associated type: \"FibFlags\" (enum)"]
8739 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
8740 let mut iter = self.clone();
8741 iter.pos = 0;
8742 for attr in iter {
8743 if let ExprFibAttrs::Flags(val) = attr? {
8744 return Ok(val);
8745 }
8746 }
8747 Err(ErrorContext::new_missing(
8748 "ExprFibAttrs",
8749 "Flags",
8750 self.orig_loc,
8751 self.buf.as_ptr() as usize,
8752 ))
8753 }
8754}
8755impl ExprFibAttrs {
8756 pub fn new(buf: &'_ [u8]) -> IterableExprFibAttrs<'_> {
8757 IterableExprFibAttrs::with_loc(buf, buf.as_ptr() as usize)
8758 }
8759 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8760 let res = match r#type {
8761 1u16 => "Dreg",
8762 2u16 => "Result",
8763 3u16 => "Flags",
8764 _ => return None,
8765 };
8766 Some(res)
8767 }
8768}
8769#[derive(Clone, Copy, Default)]
8770pub struct IterableExprFibAttrs<'a> {
8771 buf: &'a [u8],
8772 pos: usize,
8773 orig_loc: usize,
8774}
8775impl<'a> IterableExprFibAttrs<'a> {
8776 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
8777 Self {
8778 buf,
8779 pos: 0,
8780 orig_loc,
8781 }
8782 }
8783 pub fn get_buf(&self) -> &'a [u8] {
8784 self.buf
8785 }
8786}
8787impl<'a> Iterator for IterableExprFibAttrs<'a> {
8788 type Item = Result<ExprFibAttrs, ErrorContext>;
8789 fn next(&mut self) -> Option<Self::Item> {
8790 if self.buf.len() == self.pos {
8791 return None;
8792 }
8793 let pos = self.pos;
8794 let mut r#type = None;
8795 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
8796 r#type = Some(header.r#type);
8797 let res = match header.r#type {
8798 1u16 => ExprFibAttrs::Dreg({
8799 let res = parse_be_u32(next);
8800 let Some(val) = res else { break };
8801 val
8802 }),
8803 2u16 => ExprFibAttrs::Result({
8804 let res = parse_be_u32(next);
8805 let Some(val) = res else { break };
8806 val
8807 }),
8808 3u16 => ExprFibAttrs::Flags({
8809 let res = parse_be_u32(next);
8810 let Some(val) = res else { break };
8811 val
8812 }),
8813 n => {
8814 if cfg!(any(test, feature = "deny-unknown-attrs")) {
8815 break;
8816 } else {
8817 continue;
8818 }
8819 }
8820 };
8821 return Some(Ok(res));
8822 }
8823 Some(Err(ErrorContext::new(
8824 "ExprFibAttrs",
8825 r#type.and_then(|t| ExprFibAttrs::attr_from_type(t)),
8826 self.orig_loc,
8827 self.buf.as_ptr().wrapping_add(pos) as usize,
8828 )))
8829 }
8830}
8831impl std::fmt::Debug for IterableExprFibAttrs<'_> {
8832 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8833 let mut fmt = f.debug_struct("ExprFibAttrs");
8834 for attr in self.clone() {
8835 let attr = match attr {
8836 Ok(a) => a,
8837 Err(err) => {
8838 fmt.finish()?;
8839 f.write_str("Err(")?;
8840 err.fmt(f)?;
8841 return f.write_str(")");
8842 }
8843 };
8844 match attr {
8845 ExprFibAttrs::Dreg(val) => fmt.field("Dreg", &val),
8846 ExprFibAttrs::Result(val) => {
8847 fmt.field("Result", &FormatEnum(val.into(), FibResult::from_value))
8848 }
8849 ExprFibAttrs::Flags(val) => {
8850 fmt.field("Flags", &FormatFlags(val.into(), FibFlags::from_value))
8851 }
8852 };
8853 }
8854 fmt.finish()
8855 }
8856}
8857impl IterableExprFibAttrs<'_> {
8858 pub fn lookup_attr(
8859 &self,
8860 offset: usize,
8861 missing_type: Option<u16>,
8862 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
8863 let mut stack = Vec::new();
8864 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
8865 if cur == offset {
8866 stack.push(("ExprFibAttrs", offset));
8867 return (
8868 stack,
8869 missing_type.and_then(|t| ExprFibAttrs::attr_from_type(t)),
8870 );
8871 }
8872 if cur > offset || cur + self.buf.len() < offset {
8873 return (stack, None);
8874 }
8875 let mut attrs = self.clone();
8876 let mut last_off = cur + attrs.pos;
8877 while let Some(attr) = attrs.next() {
8878 let Ok(attr) = attr else { break };
8879 match attr {
8880 ExprFibAttrs::Dreg(val) => {
8881 if last_off == offset {
8882 stack.push(("Dreg", last_off));
8883 break;
8884 }
8885 }
8886 ExprFibAttrs::Result(val) => {
8887 if last_off == offset {
8888 stack.push(("Result", last_off));
8889 break;
8890 }
8891 }
8892 ExprFibAttrs::Flags(val) => {
8893 if last_off == offset {
8894 stack.push(("Flags", last_off));
8895 break;
8896 }
8897 }
8898 _ => {}
8899 };
8900 last_off = cur + attrs.pos;
8901 }
8902 if !stack.is_empty() {
8903 stack.push(("ExprFibAttrs", cur));
8904 }
8905 (stack, None)
8906 }
8907}
8908#[derive(Clone)]
8909pub enum ExprCtAttrs {
8910 Dreg(u32),
8911 #[doc = "Associated type: \"CtKeys\" (enum)"]
8912 Key(u32),
8913 #[doc = "Associated type: \"CtDirection\" (enum)"]
8914 Direction(u8),
8915 Sreg(u32),
8916}
8917impl<'a> IterableExprCtAttrs<'a> {
8918 pub fn get_dreg(&self) -> Result<u32, ErrorContext> {
8919 let mut iter = self.clone();
8920 iter.pos = 0;
8921 for attr in iter {
8922 if let ExprCtAttrs::Dreg(val) = attr? {
8923 return Ok(val);
8924 }
8925 }
8926 Err(ErrorContext::new_missing(
8927 "ExprCtAttrs",
8928 "Dreg",
8929 self.orig_loc,
8930 self.buf.as_ptr() as usize,
8931 ))
8932 }
8933 #[doc = "Associated type: \"CtKeys\" (enum)"]
8934 pub fn get_key(&self) -> Result<u32, ErrorContext> {
8935 let mut iter = self.clone();
8936 iter.pos = 0;
8937 for attr in iter {
8938 if let ExprCtAttrs::Key(val) = attr? {
8939 return Ok(val);
8940 }
8941 }
8942 Err(ErrorContext::new_missing(
8943 "ExprCtAttrs",
8944 "Key",
8945 self.orig_loc,
8946 self.buf.as_ptr() as usize,
8947 ))
8948 }
8949 #[doc = "Associated type: \"CtDirection\" (enum)"]
8950 pub fn get_direction(&self) -> Result<u8, ErrorContext> {
8951 let mut iter = self.clone();
8952 iter.pos = 0;
8953 for attr in iter {
8954 if let ExprCtAttrs::Direction(val) = attr? {
8955 return Ok(val);
8956 }
8957 }
8958 Err(ErrorContext::new_missing(
8959 "ExprCtAttrs",
8960 "Direction",
8961 self.orig_loc,
8962 self.buf.as_ptr() as usize,
8963 ))
8964 }
8965 pub fn get_sreg(&self) -> Result<u32, ErrorContext> {
8966 let mut iter = self.clone();
8967 iter.pos = 0;
8968 for attr in iter {
8969 if let ExprCtAttrs::Sreg(val) = attr? {
8970 return Ok(val);
8971 }
8972 }
8973 Err(ErrorContext::new_missing(
8974 "ExprCtAttrs",
8975 "Sreg",
8976 self.orig_loc,
8977 self.buf.as_ptr() as usize,
8978 ))
8979 }
8980}
8981impl ExprCtAttrs {
8982 pub fn new(buf: &'_ [u8]) -> IterableExprCtAttrs<'_> {
8983 IterableExprCtAttrs::with_loc(buf, buf.as_ptr() as usize)
8984 }
8985 fn attr_from_type(r#type: u16) -> Option<&'static str> {
8986 let res = match r#type {
8987 1u16 => "Dreg",
8988 2u16 => "Key",
8989 3u16 => "Direction",
8990 4u16 => "Sreg",
8991 _ => return None,
8992 };
8993 Some(res)
8994 }
8995}
8996#[derive(Clone, Copy, Default)]
8997pub struct IterableExprCtAttrs<'a> {
8998 buf: &'a [u8],
8999 pos: usize,
9000 orig_loc: usize,
9001}
9002impl<'a> IterableExprCtAttrs<'a> {
9003 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
9004 Self {
9005 buf,
9006 pos: 0,
9007 orig_loc,
9008 }
9009 }
9010 pub fn get_buf(&self) -> &'a [u8] {
9011 self.buf
9012 }
9013}
9014impl<'a> Iterator for IterableExprCtAttrs<'a> {
9015 type Item = Result<ExprCtAttrs, ErrorContext>;
9016 fn next(&mut self) -> Option<Self::Item> {
9017 if self.buf.len() == self.pos {
9018 return None;
9019 }
9020 let pos = self.pos;
9021 let mut r#type = None;
9022 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
9023 r#type = Some(header.r#type);
9024 let res = match header.r#type {
9025 1u16 => ExprCtAttrs::Dreg({
9026 let res = parse_be_u32(next);
9027 let Some(val) = res else { break };
9028 val
9029 }),
9030 2u16 => ExprCtAttrs::Key({
9031 let res = parse_be_u32(next);
9032 let Some(val) = res else { break };
9033 val
9034 }),
9035 3u16 => ExprCtAttrs::Direction({
9036 let res = parse_u8(next);
9037 let Some(val) = res else { break };
9038 val
9039 }),
9040 4u16 => ExprCtAttrs::Sreg({
9041 let res = parse_be_u32(next);
9042 let Some(val) = res else { break };
9043 val
9044 }),
9045 n => {
9046 if cfg!(any(test, feature = "deny-unknown-attrs")) {
9047 break;
9048 } else {
9049 continue;
9050 }
9051 }
9052 };
9053 return Some(Ok(res));
9054 }
9055 Some(Err(ErrorContext::new(
9056 "ExprCtAttrs",
9057 r#type.and_then(|t| ExprCtAttrs::attr_from_type(t)),
9058 self.orig_loc,
9059 self.buf.as_ptr().wrapping_add(pos) as usize,
9060 )))
9061 }
9062}
9063impl std::fmt::Debug for IterableExprCtAttrs<'_> {
9064 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9065 let mut fmt = f.debug_struct("ExprCtAttrs");
9066 for attr in self.clone() {
9067 let attr = match attr {
9068 Ok(a) => a,
9069 Err(err) => {
9070 fmt.finish()?;
9071 f.write_str("Err(")?;
9072 err.fmt(f)?;
9073 return f.write_str(")");
9074 }
9075 };
9076 match attr {
9077 ExprCtAttrs::Dreg(val) => fmt.field("Dreg", &val),
9078 ExprCtAttrs::Key(val) => {
9079 fmt.field("Key", &FormatEnum(val.into(), CtKeys::from_value))
9080 }
9081 ExprCtAttrs::Direction(val) => fmt.field(
9082 "Direction",
9083 &FormatEnum(val.into(), CtDirection::from_value),
9084 ),
9085 ExprCtAttrs::Sreg(val) => fmt.field("Sreg", &val),
9086 };
9087 }
9088 fmt.finish()
9089 }
9090}
9091impl IterableExprCtAttrs<'_> {
9092 pub fn lookup_attr(
9093 &self,
9094 offset: usize,
9095 missing_type: Option<u16>,
9096 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9097 let mut stack = Vec::new();
9098 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9099 if cur == offset {
9100 stack.push(("ExprCtAttrs", offset));
9101 return (
9102 stack,
9103 missing_type.and_then(|t| ExprCtAttrs::attr_from_type(t)),
9104 );
9105 }
9106 if cur > offset || cur + self.buf.len() < offset {
9107 return (stack, None);
9108 }
9109 let mut attrs = self.clone();
9110 let mut last_off = cur + attrs.pos;
9111 while let Some(attr) = attrs.next() {
9112 let Ok(attr) = attr else { break };
9113 match attr {
9114 ExprCtAttrs::Dreg(val) => {
9115 if last_off == offset {
9116 stack.push(("Dreg", last_off));
9117 break;
9118 }
9119 }
9120 ExprCtAttrs::Key(val) => {
9121 if last_off == offset {
9122 stack.push(("Key", last_off));
9123 break;
9124 }
9125 }
9126 ExprCtAttrs::Direction(val) => {
9127 if last_off == offset {
9128 stack.push(("Direction", last_off));
9129 break;
9130 }
9131 }
9132 ExprCtAttrs::Sreg(val) => {
9133 if last_off == offset {
9134 stack.push(("Sreg", last_off));
9135 break;
9136 }
9137 }
9138 _ => {}
9139 };
9140 last_off = cur + attrs.pos;
9141 }
9142 if !stack.is_empty() {
9143 stack.push(("ExprCtAttrs", cur));
9144 }
9145 (stack, None)
9146 }
9147}
9148#[derive(Clone)]
9149pub enum ExprFlowOffloadAttrs<'a> {
9150 #[doc = "Flow offload table name"]
9151 Name(&'a CStr),
9152}
9153impl<'a> IterableExprFlowOffloadAttrs<'a> {
9154 #[doc = "Flow offload table name"]
9155 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
9156 let mut iter = self.clone();
9157 iter.pos = 0;
9158 for attr in iter {
9159 if let ExprFlowOffloadAttrs::Name(val) = attr? {
9160 return Ok(val);
9161 }
9162 }
9163 Err(ErrorContext::new_missing(
9164 "ExprFlowOffloadAttrs",
9165 "Name",
9166 self.orig_loc,
9167 self.buf.as_ptr() as usize,
9168 ))
9169 }
9170}
9171impl<'a> ExprFlowOffloadAttrs<'a> {
9172 pub fn new(buf: &'a [u8]) -> IterableExprFlowOffloadAttrs<'a> {
9173 IterableExprFlowOffloadAttrs::with_loc(buf, buf.as_ptr() as usize)
9174 }
9175 fn attr_from_type(r#type: u16) -> Option<&'static str> {
9176 let res = match r#type {
9177 1u16 => "Name",
9178 _ => return None,
9179 };
9180 Some(res)
9181 }
9182}
9183#[derive(Clone, Copy, Default)]
9184pub struct IterableExprFlowOffloadAttrs<'a> {
9185 buf: &'a [u8],
9186 pos: usize,
9187 orig_loc: usize,
9188}
9189impl<'a> IterableExprFlowOffloadAttrs<'a> {
9190 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
9191 Self {
9192 buf,
9193 pos: 0,
9194 orig_loc,
9195 }
9196 }
9197 pub fn get_buf(&self) -> &'a [u8] {
9198 self.buf
9199 }
9200}
9201impl<'a> Iterator for IterableExprFlowOffloadAttrs<'a> {
9202 type Item = Result<ExprFlowOffloadAttrs<'a>, ErrorContext>;
9203 fn next(&mut self) -> Option<Self::Item> {
9204 if self.buf.len() == self.pos {
9205 return None;
9206 }
9207 let pos = self.pos;
9208 let mut r#type = None;
9209 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
9210 r#type = Some(header.r#type);
9211 let res = match header.r#type {
9212 1u16 => ExprFlowOffloadAttrs::Name({
9213 let res = CStr::from_bytes_with_nul(next).ok();
9214 let Some(val) = res else { break };
9215 val
9216 }),
9217 n => {
9218 if cfg!(any(test, feature = "deny-unknown-attrs")) {
9219 break;
9220 } else {
9221 continue;
9222 }
9223 }
9224 };
9225 return Some(Ok(res));
9226 }
9227 Some(Err(ErrorContext::new(
9228 "ExprFlowOffloadAttrs",
9229 r#type.and_then(|t| ExprFlowOffloadAttrs::attr_from_type(t)),
9230 self.orig_loc,
9231 self.buf.as_ptr().wrapping_add(pos) as usize,
9232 )))
9233 }
9234}
9235impl<'a> std::fmt::Debug for IterableExprFlowOffloadAttrs<'_> {
9236 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9237 let mut fmt = f.debug_struct("ExprFlowOffloadAttrs");
9238 for attr in self.clone() {
9239 let attr = match attr {
9240 Ok(a) => a,
9241 Err(err) => {
9242 fmt.finish()?;
9243 f.write_str("Err(")?;
9244 err.fmt(f)?;
9245 return f.write_str(")");
9246 }
9247 };
9248 match attr {
9249 ExprFlowOffloadAttrs::Name(val) => fmt.field("Name", &val),
9250 };
9251 }
9252 fmt.finish()
9253 }
9254}
9255impl IterableExprFlowOffloadAttrs<'_> {
9256 pub fn lookup_attr(
9257 &self,
9258 offset: usize,
9259 missing_type: Option<u16>,
9260 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9261 let mut stack = Vec::new();
9262 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9263 if cur == offset {
9264 stack.push(("ExprFlowOffloadAttrs", offset));
9265 return (
9266 stack,
9267 missing_type.and_then(|t| ExprFlowOffloadAttrs::attr_from_type(t)),
9268 );
9269 }
9270 if cur > offset || cur + self.buf.len() < offset {
9271 return (stack, None);
9272 }
9273 let mut attrs = self.clone();
9274 let mut last_off = cur + attrs.pos;
9275 while let Some(attr) = attrs.next() {
9276 let Ok(attr) = attr else { break };
9277 match attr {
9278 ExprFlowOffloadAttrs::Name(val) => {
9279 if last_off == offset {
9280 stack.push(("Name", last_off));
9281 break;
9282 }
9283 }
9284 _ => {}
9285 };
9286 last_off = cur + attrs.pos;
9287 }
9288 if !stack.is_empty() {
9289 stack.push(("ExprFlowOffloadAttrs", cur));
9290 }
9291 (stack, None)
9292 }
9293}
9294#[derive(Clone)]
9295pub enum ExprImmediateAttrs<'a> {
9296 Dreg(u32),
9297 Data(IterableDataAttrs<'a>),
9298}
9299impl<'a> IterableExprImmediateAttrs<'a> {
9300 pub fn get_dreg(&self) -> Result<u32, ErrorContext> {
9301 let mut iter = self.clone();
9302 iter.pos = 0;
9303 for attr in iter {
9304 if let ExprImmediateAttrs::Dreg(val) = attr? {
9305 return Ok(val);
9306 }
9307 }
9308 Err(ErrorContext::new_missing(
9309 "ExprImmediateAttrs",
9310 "Dreg",
9311 self.orig_loc,
9312 self.buf.as_ptr() as usize,
9313 ))
9314 }
9315 pub fn get_data(&self) -> Result<IterableDataAttrs<'a>, ErrorContext> {
9316 let mut iter = self.clone();
9317 iter.pos = 0;
9318 for attr in iter {
9319 if let ExprImmediateAttrs::Data(val) = attr? {
9320 return Ok(val);
9321 }
9322 }
9323 Err(ErrorContext::new_missing(
9324 "ExprImmediateAttrs",
9325 "Data",
9326 self.orig_loc,
9327 self.buf.as_ptr() as usize,
9328 ))
9329 }
9330}
9331impl<'a> ExprImmediateAttrs<'a> {
9332 pub fn new(buf: &'a [u8]) -> IterableExprImmediateAttrs<'a> {
9333 IterableExprImmediateAttrs::with_loc(buf, buf.as_ptr() as usize)
9334 }
9335 fn attr_from_type(r#type: u16) -> Option<&'static str> {
9336 let res = match r#type {
9337 1u16 => "Dreg",
9338 2u16 => "Data",
9339 _ => return None,
9340 };
9341 Some(res)
9342 }
9343}
9344#[derive(Clone, Copy, Default)]
9345pub struct IterableExprImmediateAttrs<'a> {
9346 buf: &'a [u8],
9347 pos: usize,
9348 orig_loc: usize,
9349}
9350impl<'a> IterableExprImmediateAttrs<'a> {
9351 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
9352 Self {
9353 buf,
9354 pos: 0,
9355 orig_loc,
9356 }
9357 }
9358 pub fn get_buf(&self) -> &'a [u8] {
9359 self.buf
9360 }
9361}
9362impl<'a> Iterator for IterableExprImmediateAttrs<'a> {
9363 type Item = Result<ExprImmediateAttrs<'a>, ErrorContext>;
9364 fn next(&mut self) -> Option<Self::Item> {
9365 if self.buf.len() == self.pos {
9366 return None;
9367 }
9368 let pos = self.pos;
9369 let mut r#type = None;
9370 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
9371 r#type = Some(header.r#type);
9372 let res = match header.r#type {
9373 1u16 => ExprImmediateAttrs::Dreg({
9374 let res = parse_be_u32(next);
9375 let Some(val) = res else { break };
9376 val
9377 }),
9378 2u16 => ExprImmediateAttrs::Data({
9379 let res = Some(IterableDataAttrs::with_loc(next, self.orig_loc));
9380 let Some(val) = res else { break };
9381 val
9382 }),
9383 n => {
9384 if cfg!(any(test, feature = "deny-unknown-attrs")) {
9385 break;
9386 } else {
9387 continue;
9388 }
9389 }
9390 };
9391 return Some(Ok(res));
9392 }
9393 Some(Err(ErrorContext::new(
9394 "ExprImmediateAttrs",
9395 r#type.and_then(|t| ExprImmediateAttrs::attr_from_type(t)),
9396 self.orig_loc,
9397 self.buf.as_ptr().wrapping_add(pos) as usize,
9398 )))
9399 }
9400}
9401impl<'a> std::fmt::Debug for IterableExprImmediateAttrs<'_> {
9402 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9403 let mut fmt = f.debug_struct("ExprImmediateAttrs");
9404 for attr in self.clone() {
9405 let attr = match attr {
9406 Ok(a) => a,
9407 Err(err) => {
9408 fmt.finish()?;
9409 f.write_str("Err(")?;
9410 err.fmt(f)?;
9411 return f.write_str(")");
9412 }
9413 };
9414 match attr {
9415 ExprImmediateAttrs::Dreg(val) => fmt.field("Dreg", &val),
9416 ExprImmediateAttrs::Data(val) => fmt.field("Data", &val),
9417 };
9418 }
9419 fmt.finish()
9420 }
9421}
9422impl IterableExprImmediateAttrs<'_> {
9423 pub fn lookup_attr(
9424 &self,
9425 offset: usize,
9426 missing_type: Option<u16>,
9427 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9428 let mut stack = Vec::new();
9429 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9430 if cur == offset {
9431 stack.push(("ExprImmediateAttrs", offset));
9432 return (
9433 stack,
9434 missing_type.and_then(|t| ExprImmediateAttrs::attr_from_type(t)),
9435 );
9436 }
9437 if cur > offset || cur + self.buf.len() < offset {
9438 return (stack, None);
9439 }
9440 let mut attrs = self.clone();
9441 let mut last_off = cur + attrs.pos;
9442 let mut missing = None;
9443 while let Some(attr) = attrs.next() {
9444 let Ok(attr) = attr else { break };
9445 match attr {
9446 ExprImmediateAttrs::Dreg(val) => {
9447 if last_off == offset {
9448 stack.push(("Dreg", last_off));
9449 break;
9450 }
9451 }
9452 ExprImmediateAttrs::Data(val) => {
9453 (stack, missing) = val.lookup_attr(offset, missing_type);
9454 if !stack.is_empty() {
9455 break;
9456 }
9457 }
9458 _ => {}
9459 };
9460 last_off = cur + attrs.pos;
9461 }
9462 if !stack.is_empty() {
9463 stack.push(("ExprImmediateAttrs", cur));
9464 }
9465 (stack, missing)
9466 }
9467}
9468#[derive(Clone)]
9469pub enum ExprLookupAttrs<'a> {
9470 #[doc = "Name of set to use"]
9471 Set(&'a CStr),
9472 #[doc = "ID of set to use"]
9473 SetId(u32),
9474 Sreg(u32),
9475 Dreg(u32),
9476 #[doc = "Associated type: \"LookupFlags\" (enum)"]
9477 Flags(u32),
9478}
9479impl<'a> IterableExprLookupAttrs<'a> {
9480 #[doc = "Name of set to use"]
9481 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
9482 let mut iter = self.clone();
9483 iter.pos = 0;
9484 for attr in iter {
9485 if let ExprLookupAttrs::Set(val) = attr? {
9486 return Ok(val);
9487 }
9488 }
9489 Err(ErrorContext::new_missing(
9490 "ExprLookupAttrs",
9491 "Set",
9492 self.orig_loc,
9493 self.buf.as_ptr() as usize,
9494 ))
9495 }
9496 #[doc = "ID of set to use"]
9497 pub fn get_set_id(&self) -> Result<u32, ErrorContext> {
9498 let mut iter = self.clone();
9499 iter.pos = 0;
9500 for attr in iter {
9501 if let ExprLookupAttrs::SetId(val) = attr? {
9502 return Ok(val);
9503 }
9504 }
9505 Err(ErrorContext::new_missing(
9506 "ExprLookupAttrs",
9507 "SetId",
9508 self.orig_loc,
9509 self.buf.as_ptr() as usize,
9510 ))
9511 }
9512 pub fn get_sreg(&self) -> Result<u32, ErrorContext> {
9513 let mut iter = self.clone();
9514 iter.pos = 0;
9515 for attr in iter {
9516 if let ExprLookupAttrs::Sreg(val) = attr? {
9517 return Ok(val);
9518 }
9519 }
9520 Err(ErrorContext::new_missing(
9521 "ExprLookupAttrs",
9522 "Sreg",
9523 self.orig_loc,
9524 self.buf.as_ptr() as usize,
9525 ))
9526 }
9527 pub fn get_dreg(&self) -> Result<u32, ErrorContext> {
9528 let mut iter = self.clone();
9529 iter.pos = 0;
9530 for attr in iter {
9531 if let ExprLookupAttrs::Dreg(val) = attr? {
9532 return Ok(val);
9533 }
9534 }
9535 Err(ErrorContext::new_missing(
9536 "ExprLookupAttrs",
9537 "Dreg",
9538 self.orig_loc,
9539 self.buf.as_ptr() as usize,
9540 ))
9541 }
9542 #[doc = "Associated type: \"LookupFlags\" (enum)"]
9543 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
9544 let mut iter = self.clone();
9545 iter.pos = 0;
9546 for attr in iter {
9547 if let ExprLookupAttrs::Flags(val) = attr? {
9548 return Ok(val);
9549 }
9550 }
9551 Err(ErrorContext::new_missing(
9552 "ExprLookupAttrs",
9553 "Flags",
9554 self.orig_loc,
9555 self.buf.as_ptr() as usize,
9556 ))
9557 }
9558}
9559impl<'a> ExprLookupAttrs<'a> {
9560 pub fn new(buf: &'a [u8]) -> IterableExprLookupAttrs<'a> {
9561 IterableExprLookupAttrs::with_loc(buf, buf.as_ptr() as usize)
9562 }
9563 fn attr_from_type(r#type: u16) -> Option<&'static str> {
9564 let res = match r#type {
9565 1u16 => "Set",
9566 2u16 => "SetId",
9567 3u16 => "Sreg",
9568 4u16 => "Dreg",
9569 5u16 => "Flags",
9570 _ => return None,
9571 };
9572 Some(res)
9573 }
9574}
9575#[derive(Clone, Copy, Default)]
9576pub struct IterableExprLookupAttrs<'a> {
9577 buf: &'a [u8],
9578 pos: usize,
9579 orig_loc: usize,
9580}
9581impl<'a> IterableExprLookupAttrs<'a> {
9582 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
9583 Self {
9584 buf,
9585 pos: 0,
9586 orig_loc,
9587 }
9588 }
9589 pub fn get_buf(&self) -> &'a [u8] {
9590 self.buf
9591 }
9592}
9593impl<'a> Iterator for IterableExprLookupAttrs<'a> {
9594 type Item = Result<ExprLookupAttrs<'a>, ErrorContext>;
9595 fn next(&mut self) -> Option<Self::Item> {
9596 if self.buf.len() == self.pos {
9597 return None;
9598 }
9599 let pos = self.pos;
9600 let mut r#type = None;
9601 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
9602 r#type = Some(header.r#type);
9603 let res = match header.r#type {
9604 1u16 => ExprLookupAttrs::Set({
9605 let res = CStr::from_bytes_with_nul(next).ok();
9606 let Some(val) = res else { break };
9607 val
9608 }),
9609 2u16 => ExprLookupAttrs::SetId({
9610 let res = parse_be_u32(next);
9611 let Some(val) = res else { break };
9612 val
9613 }),
9614 3u16 => ExprLookupAttrs::Sreg({
9615 let res = parse_be_u32(next);
9616 let Some(val) = res else { break };
9617 val
9618 }),
9619 4u16 => ExprLookupAttrs::Dreg({
9620 let res = parse_be_u32(next);
9621 let Some(val) = res else { break };
9622 val
9623 }),
9624 5u16 => ExprLookupAttrs::Flags({
9625 let res = parse_be_u32(next);
9626 let Some(val) = res else { break };
9627 val
9628 }),
9629 n => {
9630 if cfg!(any(test, feature = "deny-unknown-attrs")) {
9631 break;
9632 } else {
9633 continue;
9634 }
9635 }
9636 };
9637 return Some(Ok(res));
9638 }
9639 Some(Err(ErrorContext::new(
9640 "ExprLookupAttrs",
9641 r#type.and_then(|t| ExprLookupAttrs::attr_from_type(t)),
9642 self.orig_loc,
9643 self.buf.as_ptr().wrapping_add(pos) as usize,
9644 )))
9645 }
9646}
9647impl<'a> std::fmt::Debug for IterableExprLookupAttrs<'_> {
9648 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9649 let mut fmt = f.debug_struct("ExprLookupAttrs");
9650 for attr in self.clone() {
9651 let attr = match attr {
9652 Ok(a) => a,
9653 Err(err) => {
9654 fmt.finish()?;
9655 f.write_str("Err(")?;
9656 err.fmt(f)?;
9657 return f.write_str(")");
9658 }
9659 };
9660 match attr {
9661 ExprLookupAttrs::Set(val) => fmt.field("Set", &val),
9662 ExprLookupAttrs::SetId(val) => fmt.field("SetId", &val),
9663 ExprLookupAttrs::Sreg(val) => fmt.field("Sreg", &val),
9664 ExprLookupAttrs::Dreg(val) => fmt.field("Dreg", &val),
9665 ExprLookupAttrs::Flags(val) => {
9666 fmt.field("Flags", &FormatFlags(val.into(), LookupFlags::from_value))
9667 }
9668 };
9669 }
9670 fmt.finish()
9671 }
9672}
9673impl IterableExprLookupAttrs<'_> {
9674 pub fn lookup_attr(
9675 &self,
9676 offset: usize,
9677 missing_type: Option<u16>,
9678 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9679 let mut stack = Vec::new();
9680 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9681 if cur == offset {
9682 stack.push(("ExprLookupAttrs", offset));
9683 return (
9684 stack,
9685 missing_type.and_then(|t| ExprLookupAttrs::attr_from_type(t)),
9686 );
9687 }
9688 if cur > offset || cur + self.buf.len() < offset {
9689 return (stack, None);
9690 }
9691 let mut attrs = self.clone();
9692 let mut last_off = cur + attrs.pos;
9693 while let Some(attr) = attrs.next() {
9694 let Ok(attr) = attr else { break };
9695 match attr {
9696 ExprLookupAttrs::Set(val) => {
9697 if last_off == offset {
9698 stack.push(("Set", last_off));
9699 break;
9700 }
9701 }
9702 ExprLookupAttrs::SetId(val) => {
9703 if last_off == offset {
9704 stack.push(("SetId", last_off));
9705 break;
9706 }
9707 }
9708 ExprLookupAttrs::Sreg(val) => {
9709 if last_off == offset {
9710 stack.push(("Sreg", last_off));
9711 break;
9712 }
9713 }
9714 ExprLookupAttrs::Dreg(val) => {
9715 if last_off == offset {
9716 stack.push(("Dreg", last_off));
9717 break;
9718 }
9719 }
9720 ExprLookupAttrs::Flags(val) => {
9721 if last_off == offset {
9722 stack.push(("Flags", last_off));
9723 break;
9724 }
9725 }
9726 _ => {}
9727 };
9728 last_off = cur + attrs.pos;
9729 }
9730 if !stack.is_empty() {
9731 stack.push(("ExprLookupAttrs", cur));
9732 }
9733 (stack, None)
9734 }
9735}
9736#[derive(Clone)]
9737pub enum ExprMetaAttrs {
9738 Dreg(u32),
9739 #[doc = "Associated type: \"MetaKeys\" (enum)"]
9740 Key(u32),
9741 Sreg(u32),
9742}
9743impl<'a> IterableExprMetaAttrs<'a> {
9744 pub fn get_dreg(&self) -> Result<u32, ErrorContext> {
9745 let mut iter = self.clone();
9746 iter.pos = 0;
9747 for attr in iter {
9748 if let ExprMetaAttrs::Dreg(val) = attr? {
9749 return Ok(val);
9750 }
9751 }
9752 Err(ErrorContext::new_missing(
9753 "ExprMetaAttrs",
9754 "Dreg",
9755 self.orig_loc,
9756 self.buf.as_ptr() as usize,
9757 ))
9758 }
9759 #[doc = "Associated type: \"MetaKeys\" (enum)"]
9760 pub fn get_key(&self) -> Result<u32, ErrorContext> {
9761 let mut iter = self.clone();
9762 iter.pos = 0;
9763 for attr in iter {
9764 if let ExprMetaAttrs::Key(val) = attr? {
9765 return Ok(val);
9766 }
9767 }
9768 Err(ErrorContext::new_missing(
9769 "ExprMetaAttrs",
9770 "Key",
9771 self.orig_loc,
9772 self.buf.as_ptr() as usize,
9773 ))
9774 }
9775 pub fn get_sreg(&self) -> Result<u32, ErrorContext> {
9776 let mut iter = self.clone();
9777 iter.pos = 0;
9778 for attr in iter {
9779 if let ExprMetaAttrs::Sreg(val) = attr? {
9780 return Ok(val);
9781 }
9782 }
9783 Err(ErrorContext::new_missing(
9784 "ExprMetaAttrs",
9785 "Sreg",
9786 self.orig_loc,
9787 self.buf.as_ptr() as usize,
9788 ))
9789 }
9790}
9791impl ExprMetaAttrs {
9792 pub fn new(buf: &'_ [u8]) -> IterableExprMetaAttrs<'_> {
9793 IterableExprMetaAttrs::with_loc(buf, buf.as_ptr() as usize)
9794 }
9795 fn attr_from_type(r#type: u16) -> Option<&'static str> {
9796 let res = match r#type {
9797 1u16 => "Dreg",
9798 2u16 => "Key",
9799 3u16 => "Sreg",
9800 _ => return None,
9801 };
9802 Some(res)
9803 }
9804}
9805#[derive(Clone, Copy, Default)]
9806pub struct IterableExprMetaAttrs<'a> {
9807 buf: &'a [u8],
9808 pos: usize,
9809 orig_loc: usize,
9810}
9811impl<'a> IterableExprMetaAttrs<'a> {
9812 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
9813 Self {
9814 buf,
9815 pos: 0,
9816 orig_loc,
9817 }
9818 }
9819 pub fn get_buf(&self) -> &'a [u8] {
9820 self.buf
9821 }
9822}
9823impl<'a> Iterator for IterableExprMetaAttrs<'a> {
9824 type Item = Result<ExprMetaAttrs, ErrorContext>;
9825 fn next(&mut self) -> Option<Self::Item> {
9826 if self.buf.len() == self.pos {
9827 return None;
9828 }
9829 let pos = self.pos;
9830 let mut r#type = None;
9831 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
9832 r#type = Some(header.r#type);
9833 let res = match header.r#type {
9834 1u16 => ExprMetaAttrs::Dreg({
9835 let res = parse_be_u32(next);
9836 let Some(val) = res else { break };
9837 val
9838 }),
9839 2u16 => ExprMetaAttrs::Key({
9840 let res = parse_be_u32(next);
9841 let Some(val) = res else { break };
9842 val
9843 }),
9844 3u16 => ExprMetaAttrs::Sreg({
9845 let res = parse_be_u32(next);
9846 let Some(val) = res else { break };
9847 val
9848 }),
9849 n => {
9850 if cfg!(any(test, feature = "deny-unknown-attrs")) {
9851 break;
9852 } else {
9853 continue;
9854 }
9855 }
9856 };
9857 return Some(Ok(res));
9858 }
9859 Some(Err(ErrorContext::new(
9860 "ExprMetaAttrs",
9861 r#type.and_then(|t| ExprMetaAttrs::attr_from_type(t)),
9862 self.orig_loc,
9863 self.buf.as_ptr().wrapping_add(pos) as usize,
9864 )))
9865 }
9866}
9867impl std::fmt::Debug for IterableExprMetaAttrs<'_> {
9868 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9869 let mut fmt = f.debug_struct("ExprMetaAttrs");
9870 for attr in self.clone() {
9871 let attr = match attr {
9872 Ok(a) => a,
9873 Err(err) => {
9874 fmt.finish()?;
9875 f.write_str("Err(")?;
9876 err.fmt(f)?;
9877 return f.write_str(")");
9878 }
9879 };
9880 match attr {
9881 ExprMetaAttrs::Dreg(val) => fmt.field("Dreg", &val),
9882 ExprMetaAttrs::Key(val) => {
9883 fmt.field("Key", &FormatEnum(val.into(), MetaKeys::from_value))
9884 }
9885 ExprMetaAttrs::Sreg(val) => fmt.field("Sreg", &val),
9886 };
9887 }
9888 fmt.finish()
9889 }
9890}
9891impl IterableExprMetaAttrs<'_> {
9892 pub fn lookup_attr(
9893 &self,
9894 offset: usize,
9895 missing_type: Option<u16>,
9896 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
9897 let mut stack = Vec::new();
9898 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
9899 if cur == offset {
9900 stack.push(("ExprMetaAttrs", offset));
9901 return (
9902 stack,
9903 missing_type.and_then(|t| ExprMetaAttrs::attr_from_type(t)),
9904 );
9905 }
9906 if cur > offset || cur + self.buf.len() < offset {
9907 return (stack, None);
9908 }
9909 let mut attrs = self.clone();
9910 let mut last_off = cur + attrs.pos;
9911 while let Some(attr) = attrs.next() {
9912 let Ok(attr) = attr else { break };
9913 match attr {
9914 ExprMetaAttrs::Dreg(val) => {
9915 if last_off == offset {
9916 stack.push(("Dreg", last_off));
9917 break;
9918 }
9919 }
9920 ExprMetaAttrs::Key(val) => {
9921 if last_off == offset {
9922 stack.push(("Key", last_off));
9923 break;
9924 }
9925 }
9926 ExprMetaAttrs::Sreg(val) => {
9927 if last_off == offset {
9928 stack.push(("Sreg", last_off));
9929 break;
9930 }
9931 }
9932 _ => {}
9933 };
9934 last_off = cur + attrs.pos;
9935 }
9936 if !stack.is_empty() {
9937 stack.push(("ExprMetaAttrs", cur));
9938 }
9939 (stack, None)
9940 }
9941}
9942#[derive(Clone)]
9943pub enum ExprNatAttrs {
9944 Type(u32),
9945 Family(u32),
9946 RegAddrMin(u32),
9947 RegAddrMax(u32),
9948 RegProtoMin(u32),
9949 RegProtoMax(u32),
9950 #[doc = "Associated type: \"NatRangeFlags\" (1 bit per enumeration)"]
9951 Flags(u32),
9952}
9953impl<'a> IterableExprNatAttrs<'a> {
9954 pub fn get_type(&self) -> Result<u32, ErrorContext> {
9955 let mut iter = self.clone();
9956 iter.pos = 0;
9957 for attr in iter {
9958 if let ExprNatAttrs::Type(val) = attr? {
9959 return Ok(val);
9960 }
9961 }
9962 Err(ErrorContext::new_missing(
9963 "ExprNatAttrs",
9964 "Type",
9965 self.orig_loc,
9966 self.buf.as_ptr() as usize,
9967 ))
9968 }
9969 pub fn get_family(&self) -> Result<u32, ErrorContext> {
9970 let mut iter = self.clone();
9971 iter.pos = 0;
9972 for attr in iter {
9973 if let ExprNatAttrs::Family(val) = attr? {
9974 return Ok(val);
9975 }
9976 }
9977 Err(ErrorContext::new_missing(
9978 "ExprNatAttrs",
9979 "Family",
9980 self.orig_loc,
9981 self.buf.as_ptr() as usize,
9982 ))
9983 }
9984 pub fn get_reg_addr_min(&self) -> Result<u32, ErrorContext> {
9985 let mut iter = self.clone();
9986 iter.pos = 0;
9987 for attr in iter {
9988 if let ExprNatAttrs::RegAddrMin(val) = attr? {
9989 return Ok(val);
9990 }
9991 }
9992 Err(ErrorContext::new_missing(
9993 "ExprNatAttrs",
9994 "RegAddrMin",
9995 self.orig_loc,
9996 self.buf.as_ptr() as usize,
9997 ))
9998 }
9999 pub fn get_reg_addr_max(&self) -> Result<u32, ErrorContext> {
10000 let mut iter = self.clone();
10001 iter.pos = 0;
10002 for attr in iter {
10003 if let ExprNatAttrs::RegAddrMax(val) = attr? {
10004 return Ok(val);
10005 }
10006 }
10007 Err(ErrorContext::new_missing(
10008 "ExprNatAttrs",
10009 "RegAddrMax",
10010 self.orig_loc,
10011 self.buf.as_ptr() as usize,
10012 ))
10013 }
10014 pub fn get_reg_proto_min(&self) -> Result<u32, ErrorContext> {
10015 let mut iter = self.clone();
10016 iter.pos = 0;
10017 for attr in iter {
10018 if let ExprNatAttrs::RegProtoMin(val) = attr? {
10019 return Ok(val);
10020 }
10021 }
10022 Err(ErrorContext::new_missing(
10023 "ExprNatAttrs",
10024 "RegProtoMin",
10025 self.orig_loc,
10026 self.buf.as_ptr() as usize,
10027 ))
10028 }
10029 pub fn get_reg_proto_max(&self) -> Result<u32, ErrorContext> {
10030 let mut iter = self.clone();
10031 iter.pos = 0;
10032 for attr in iter {
10033 if let ExprNatAttrs::RegProtoMax(val) = attr? {
10034 return Ok(val);
10035 }
10036 }
10037 Err(ErrorContext::new_missing(
10038 "ExprNatAttrs",
10039 "RegProtoMax",
10040 self.orig_loc,
10041 self.buf.as_ptr() as usize,
10042 ))
10043 }
10044 #[doc = "Associated type: \"NatRangeFlags\" (1 bit per enumeration)"]
10045 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
10046 let mut iter = self.clone();
10047 iter.pos = 0;
10048 for attr in iter {
10049 if let ExprNatAttrs::Flags(val) = attr? {
10050 return Ok(val);
10051 }
10052 }
10053 Err(ErrorContext::new_missing(
10054 "ExprNatAttrs",
10055 "Flags",
10056 self.orig_loc,
10057 self.buf.as_ptr() as usize,
10058 ))
10059 }
10060}
10061impl ExprNatAttrs {
10062 pub fn new(buf: &'_ [u8]) -> IterableExprNatAttrs<'_> {
10063 IterableExprNatAttrs::with_loc(buf, buf.as_ptr() as usize)
10064 }
10065 fn attr_from_type(r#type: u16) -> Option<&'static str> {
10066 let res = match r#type {
10067 1u16 => "Type",
10068 2u16 => "Family",
10069 3u16 => "RegAddrMin",
10070 4u16 => "RegAddrMax",
10071 5u16 => "RegProtoMin",
10072 6u16 => "RegProtoMax",
10073 7u16 => "Flags",
10074 _ => return None,
10075 };
10076 Some(res)
10077 }
10078}
10079#[derive(Clone, Copy, Default)]
10080pub struct IterableExprNatAttrs<'a> {
10081 buf: &'a [u8],
10082 pos: usize,
10083 orig_loc: usize,
10084}
10085impl<'a> IterableExprNatAttrs<'a> {
10086 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
10087 Self {
10088 buf,
10089 pos: 0,
10090 orig_loc,
10091 }
10092 }
10093 pub fn get_buf(&self) -> &'a [u8] {
10094 self.buf
10095 }
10096}
10097impl<'a> Iterator for IterableExprNatAttrs<'a> {
10098 type Item = Result<ExprNatAttrs, ErrorContext>;
10099 fn next(&mut self) -> Option<Self::Item> {
10100 if self.buf.len() == self.pos {
10101 return None;
10102 }
10103 let pos = self.pos;
10104 let mut r#type = None;
10105 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
10106 r#type = Some(header.r#type);
10107 let res = match header.r#type {
10108 1u16 => ExprNatAttrs::Type({
10109 let res = parse_be_u32(next);
10110 let Some(val) = res else { break };
10111 val
10112 }),
10113 2u16 => ExprNatAttrs::Family({
10114 let res = parse_be_u32(next);
10115 let Some(val) = res else { break };
10116 val
10117 }),
10118 3u16 => ExprNatAttrs::RegAddrMin({
10119 let res = parse_be_u32(next);
10120 let Some(val) = res else { break };
10121 val
10122 }),
10123 4u16 => ExprNatAttrs::RegAddrMax({
10124 let res = parse_be_u32(next);
10125 let Some(val) = res else { break };
10126 val
10127 }),
10128 5u16 => ExprNatAttrs::RegProtoMin({
10129 let res = parse_be_u32(next);
10130 let Some(val) = res else { break };
10131 val
10132 }),
10133 6u16 => ExprNatAttrs::RegProtoMax({
10134 let res = parse_be_u32(next);
10135 let Some(val) = res else { break };
10136 val
10137 }),
10138 7u16 => ExprNatAttrs::Flags({
10139 let res = parse_be_u32(next);
10140 let Some(val) = res else { break };
10141 val
10142 }),
10143 n => {
10144 if cfg!(any(test, feature = "deny-unknown-attrs")) {
10145 break;
10146 } else {
10147 continue;
10148 }
10149 }
10150 };
10151 return Some(Ok(res));
10152 }
10153 Some(Err(ErrorContext::new(
10154 "ExprNatAttrs",
10155 r#type.and_then(|t| ExprNatAttrs::attr_from_type(t)),
10156 self.orig_loc,
10157 self.buf.as_ptr().wrapping_add(pos) as usize,
10158 )))
10159 }
10160}
10161impl std::fmt::Debug for IterableExprNatAttrs<'_> {
10162 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10163 let mut fmt = f.debug_struct("ExprNatAttrs");
10164 for attr in self.clone() {
10165 let attr = match attr {
10166 Ok(a) => a,
10167 Err(err) => {
10168 fmt.finish()?;
10169 f.write_str("Err(")?;
10170 err.fmt(f)?;
10171 return f.write_str(")");
10172 }
10173 };
10174 match attr {
10175 ExprNatAttrs::Type(val) => fmt.field("Type", &val),
10176 ExprNatAttrs::Family(val) => fmt.field("Family", &val),
10177 ExprNatAttrs::RegAddrMin(val) => fmt.field("RegAddrMin", &val),
10178 ExprNatAttrs::RegAddrMax(val) => fmt.field("RegAddrMax", &val),
10179 ExprNatAttrs::RegProtoMin(val) => fmt.field("RegProtoMin", &val),
10180 ExprNatAttrs::RegProtoMax(val) => fmt.field("RegProtoMax", &val),
10181 ExprNatAttrs::Flags(val) => {
10182 fmt.field("Flags", &FormatFlags(val.into(), NatRangeFlags::from_value))
10183 }
10184 };
10185 }
10186 fmt.finish()
10187 }
10188}
10189impl IterableExprNatAttrs<'_> {
10190 pub fn lookup_attr(
10191 &self,
10192 offset: usize,
10193 missing_type: Option<u16>,
10194 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
10195 let mut stack = Vec::new();
10196 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
10197 if cur == offset {
10198 stack.push(("ExprNatAttrs", offset));
10199 return (
10200 stack,
10201 missing_type.and_then(|t| ExprNatAttrs::attr_from_type(t)),
10202 );
10203 }
10204 if cur > offset || cur + self.buf.len() < offset {
10205 return (stack, None);
10206 }
10207 let mut attrs = self.clone();
10208 let mut last_off = cur + attrs.pos;
10209 while let Some(attr) = attrs.next() {
10210 let Ok(attr) = attr else { break };
10211 match attr {
10212 ExprNatAttrs::Type(val) => {
10213 if last_off == offset {
10214 stack.push(("Type", last_off));
10215 break;
10216 }
10217 }
10218 ExprNatAttrs::Family(val) => {
10219 if last_off == offset {
10220 stack.push(("Family", last_off));
10221 break;
10222 }
10223 }
10224 ExprNatAttrs::RegAddrMin(val) => {
10225 if last_off == offset {
10226 stack.push(("RegAddrMin", last_off));
10227 break;
10228 }
10229 }
10230 ExprNatAttrs::RegAddrMax(val) => {
10231 if last_off == offset {
10232 stack.push(("RegAddrMax", last_off));
10233 break;
10234 }
10235 }
10236 ExprNatAttrs::RegProtoMin(val) => {
10237 if last_off == offset {
10238 stack.push(("RegProtoMin", last_off));
10239 break;
10240 }
10241 }
10242 ExprNatAttrs::RegProtoMax(val) => {
10243 if last_off == offset {
10244 stack.push(("RegProtoMax", last_off));
10245 break;
10246 }
10247 }
10248 ExprNatAttrs::Flags(val) => {
10249 if last_off == offset {
10250 stack.push(("Flags", last_off));
10251 break;
10252 }
10253 }
10254 _ => {}
10255 };
10256 last_off = cur + attrs.pos;
10257 }
10258 if !stack.is_empty() {
10259 stack.push(("ExprNatAttrs", cur));
10260 }
10261 (stack, None)
10262 }
10263}
10264#[derive(Clone)]
10265pub enum ExprPayloadAttrs {
10266 #[doc = "destination register to load data into\nAssociated type: \"Registers\" (enum)"]
10267 Dreg(u32),
10268 #[doc = "payload base\nAssociated type: \"PayloadBase\" (enum)"]
10269 Base(u32),
10270 #[doc = "payload offset relative to base"]
10271 Offset(u32),
10272 #[doc = "payload length"]
10273 Len(u32),
10274 #[doc = "source register to load data from\nAssociated type: \"Registers\" (enum)"]
10275 Sreg(u32),
10276 #[doc = "checksum type"]
10277 CsumType(u32),
10278 #[doc = "checksum offset relative to base"]
10279 CsumOffset(u32),
10280 #[doc = "checksum flags"]
10281 CsumFlags(u32),
10282}
10283impl<'a> IterableExprPayloadAttrs<'a> {
10284 #[doc = "destination register to load data into\nAssociated type: \"Registers\" (enum)"]
10285 pub fn get_dreg(&self) -> Result<u32, ErrorContext> {
10286 let mut iter = self.clone();
10287 iter.pos = 0;
10288 for attr in iter {
10289 if let ExprPayloadAttrs::Dreg(val) = attr? {
10290 return Ok(val);
10291 }
10292 }
10293 Err(ErrorContext::new_missing(
10294 "ExprPayloadAttrs",
10295 "Dreg",
10296 self.orig_loc,
10297 self.buf.as_ptr() as usize,
10298 ))
10299 }
10300 #[doc = "payload base\nAssociated type: \"PayloadBase\" (enum)"]
10301 pub fn get_base(&self) -> Result<u32, ErrorContext> {
10302 let mut iter = self.clone();
10303 iter.pos = 0;
10304 for attr in iter {
10305 if let ExprPayloadAttrs::Base(val) = attr? {
10306 return Ok(val);
10307 }
10308 }
10309 Err(ErrorContext::new_missing(
10310 "ExprPayloadAttrs",
10311 "Base",
10312 self.orig_loc,
10313 self.buf.as_ptr() as usize,
10314 ))
10315 }
10316 #[doc = "payload offset relative to base"]
10317 pub fn get_offset(&self) -> Result<u32, ErrorContext> {
10318 let mut iter = self.clone();
10319 iter.pos = 0;
10320 for attr in iter {
10321 if let ExprPayloadAttrs::Offset(val) = attr? {
10322 return Ok(val);
10323 }
10324 }
10325 Err(ErrorContext::new_missing(
10326 "ExprPayloadAttrs",
10327 "Offset",
10328 self.orig_loc,
10329 self.buf.as_ptr() as usize,
10330 ))
10331 }
10332 #[doc = "payload length"]
10333 pub fn get_len(&self) -> Result<u32, ErrorContext> {
10334 let mut iter = self.clone();
10335 iter.pos = 0;
10336 for attr in iter {
10337 if let ExprPayloadAttrs::Len(val) = attr? {
10338 return Ok(val);
10339 }
10340 }
10341 Err(ErrorContext::new_missing(
10342 "ExprPayloadAttrs",
10343 "Len",
10344 self.orig_loc,
10345 self.buf.as_ptr() as usize,
10346 ))
10347 }
10348 #[doc = "source register to load data from\nAssociated type: \"Registers\" (enum)"]
10349 pub fn get_sreg(&self) -> Result<u32, ErrorContext> {
10350 let mut iter = self.clone();
10351 iter.pos = 0;
10352 for attr in iter {
10353 if let ExprPayloadAttrs::Sreg(val) = attr? {
10354 return Ok(val);
10355 }
10356 }
10357 Err(ErrorContext::new_missing(
10358 "ExprPayloadAttrs",
10359 "Sreg",
10360 self.orig_loc,
10361 self.buf.as_ptr() as usize,
10362 ))
10363 }
10364 #[doc = "checksum type"]
10365 pub fn get_csum_type(&self) -> Result<u32, ErrorContext> {
10366 let mut iter = self.clone();
10367 iter.pos = 0;
10368 for attr in iter {
10369 if let ExprPayloadAttrs::CsumType(val) = attr? {
10370 return Ok(val);
10371 }
10372 }
10373 Err(ErrorContext::new_missing(
10374 "ExprPayloadAttrs",
10375 "CsumType",
10376 self.orig_loc,
10377 self.buf.as_ptr() as usize,
10378 ))
10379 }
10380 #[doc = "checksum offset relative to base"]
10381 pub fn get_csum_offset(&self) -> Result<u32, ErrorContext> {
10382 let mut iter = self.clone();
10383 iter.pos = 0;
10384 for attr in iter {
10385 if let ExprPayloadAttrs::CsumOffset(val) = attr? {
10386 return Ok(val);
10387 }
10388 }
10389 Err(ErrorContext::new_missing(
10390 "ExprPayloadAttrs",
10391 "CsumOffset",
10392 self.orig_loc,
10393 self.buf.as_ptr() as usize,
10394 ))
10395 }
10396 #[doc = "checksum flags"]
10397 pub fn get_csum_flags(&self) -> Result<u32, ErrorContext> {
10398 let mut iter = self.clone();
10399 iter.pos = 0;
10400 for attr in iter {
10401 if let ExprPayloadAttrs::CsumFlags(val) = attr? {
10402 return Ok(val);
10403 }
10404 }
10405 Err(ErrorContext::new_missing(
10406 "ExprPayloadAttrs",
10407 "CsumFlags",
10408 self.orig_loc,
10409 self.buf.as_ptr() as usize,
10410 ))
10411 }
10412}
10413impl ExprPayloadAttrs {
10414 pub fn new(buf: &'_ [u8]) -> IterableExprPayloadAttrs<'_> {
10415 IterableExprPayloadAttrs::with_loc(buf, buf.as_ptr() as usize)
10416 }
10417 fn attr_from_type(r#type: u16) -> Option<&'static str> {
10418 let res = match r#type {
10419 1u16 => "Dreg",
10420 2u16 => "Base",
10421 3u16 => "Offset",
10422 4u16 => "Len",
10423 5u16 => "Sreg",
10424 6u16 => "CsumType",
10425 7u16 => "CsumOffset",
10426 8u16 => "CsumFlags",
10427 _ => return None,
10428 };
10429 Some(res)
10430 }
10431}
10432#[derive(Clone, Copy, Default)]
10433pub struct IterableExprPayloadAttrs<'a> {
10434 buf: &'a [u8],
10435 pos: usize,
10436 orig_loc: usize,
10437}
10438impl<'a> IterableExprPayloadAttrs<'a> {
10439 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
10440 Self {
10441 buf,
10442 pos: 0,
10443 orig_loc,
10444 }
10445 }
10446 pub fn get_buf(&self) -> &'a [u8] {
10447 self.buf
10448 }
10449}
10450impl<'a> Iterator for IterableExprPayloadAttrs<'a> {
10451 type Item = Result<ExprPayloadAttrs, ErrorContext>;
10452 fn next(&mut self) -> Option<Self::Item> {
10453 if self.buf.len() == self.pos {
10454 return None;
10455 }
10456 let pos = self.pos;
10457 let mut r#type = None;
10458 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
10459 r#type = Some(header.r#type);
10460 let res = match header.r#type {
10461 1u16 => ExprPayloadAttrs::Dreg({
10462 let res = parse_be_u32(next);
10463 let Some(val) = res else { break };
10464 val
10465 }),
10466 2u16 => ExprPayloadAttrs::Base({
10467 let res = parse_be_u32(next);
10468 let Some(val) = res else { break };
10469 val
10470 }),
10471 3u16 => ExprPayloadAttrs::Offset({
10472 let res = parse_be_u32(next);
10473 let Some(val) = res else { break };
10474 val
10475 }),
10476 4u16 => ExprPayloadAttrs::Len({
10477 let res = parse_be_u32(next);
10478 let Some(val) = res else { break };
10479 val
10480 }),
10481 5u16 => ExprPayloadAttrs::Sreg({
10482 let res = parse_be_u32(next);
10483 let Some(val) = res else { break };
10484 val
10485 }),
10486 6u16 => ExprPayloadAttrs::CsumType({
10487 let res = parse_be_u32(next);
10488 let Some(val) = res else { break };
10489 val
10490 }),
10491 7u16 => ExprPayloadAttrs::CsumOffset({
10492 let res = parse_be_u32(next);
10493 let Some(val) = res else { break };
10494 val
10495 }),
10496 8u16 => ExprPayloadAttrs::CsumFlags({
10497 let res = parse_be_u32(next);
10498 let Some(val) = res else { break };
10499 val
10500 }),
10501 n => {
10502 if cfg!(any(test, feature = "deny-unknown-attrs")) {
10503 break;
10504 } else {
10505 continue;
10506 }
10507 }
10508 };
10509 return Some(Ok(res));
10510 }
10511 Some(Err(ErrorContext::new(
10512 "ExprPayloadAttrs",
10513 r#type.and_then(|t| ExprPayloadAttrs::attr_from_type(t)),
10514 self.orig_loc,
10515 self.buf.as_ptr().wrapping_add(pos) as usize,
10516 )))
10517 }
10518}
10519impl std::fmt::Debug for IterableExprPayloadAttrs<'_> {
10520 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10521 let mut fmt = f.debug_struct("ExprPayloadAttrs");
10522 for attr in self.clone() {
10523 let attr = match attr {
10524 Ok(a) => a,
10525 Err(err) => {
10526 fmt.finish()?;
10527 f.write_str("Err(")?;
10528 err.fmt(f)?;
10529 return f.write_str(")");
10530 }
10531 };
10532 match attr {
10533 ExprPayloadAttrs::Dreg(val) => {
10534 fmt.field("Dreg", &FormatEnum(val.into(), Registers::from_value))
10535 }
10536 ExprPayloadAttrs::Base(val) => {
10537 fmt.field("Base", &FormatEnum(val.into(), PayloadBase::from_value))
10538 }
10539 ExprPayloadAttrs::Offset(val) => fmt.field("Offset", &val),
10540 ExprPayloadAttrs::Len(val) => fmt.field("Len", &val),
10541 ExprPayloadAttrs::Sreg(val) => {
10542 fmt.field("Sreg", &FormatEnum(val.into(), Registers::from_value))
10543 }
10544 ExprPayloadAttrs::CsumType(val) => fmt.field("CsumType", &val),
10545 ExprPayloadAttrs::CsumOffset(val) => fmt.field("CsumOffset", &val),
10546 ExprPayloadAttrs::CsumFlags(val) => fmt.field("CsumFlags", &val),
10547 };
10548 }
10549 fmt.finish()
10550 }
10551}
10552impl IterableExprPayloadAttrs<'_> {
10553 pub fn lookup_attr(
10554 &self,
10555 offset: usize,
10556 missing_type: Option<u16>,
10557 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
10558 let mut stack = Vec::new();
10559 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
10560 if cur == offset {
10561 stack.push(("ExprPayloadAttrs", offset));
10562 return (
10563 stack,
10564 missing_type.and_then(|t| ExprPayloadAttrs::attr_from_type(t)),
10565 );
10566 }
10567 if cur > offset || cur + self.buf.len() < offset {
10568 return (stack, None);
10569 }
10570 let mut attrs = self.clone();
10571 let mut last_off = cur + attrs.pos;
10572 while let Some(attr) = attrs.next() {
10573 let Ok(attr) = attr else { break };
10574 match attr {
10575 ExprPayloadAttrs::Dreg(val) => {
10576 if last_off == offset {
10577 stack.push(("Dreg", last_off));
10578 break;
10579 }
10580 }
10581 ExprPayloadAttrs::Base(val) => {
10582 if last_off == offset {
10583 stack.push(("Base", last_off));
10584 break;
10585 }
10586 }
10587 ExprPayloadAttrs::Offset(val) => {
10588 if last_off == offset {
10589 stack.push(("Offset", last_off));
10590 break;
10591 }
10592 }
10593 ExprPayloadAttrs::Len(val) => {
10594 if last_off == offset {
10595 stack.push(("Len", last_off));
10596 break;
10597 }
10598 }
10599 ExprPayloadAttrs::Sreg(val) => {
10600 if last_off == offset {
10601 stack.push(("Sreg", last_off));
10602 break;
10603 }
10604 }
10605 ExprPayloadAttrs::CsumType(val) => {
10606 if last_off == offset {
10607 stack.push(("CsumType", last_off));
10608 break;
10609 }
10610 }
10611 ExprPayloadAttrs::CsumOffset(val) => {
10612 if last_off == offset {
10613 stack.push(("CsumOffset", last_off));
10614 break;
10615 }
10616 }
10617 ExprPayloadAttrs::CsumFlags(val) => {
10618 if last_off == offset {
10619 stack.push(("CsumFlags", last_off));
10620 break;
10621 }
10622 }
10623 _ => {}
10624 };
10625 last_off = cur + attrs.pos;
10626 }
10627 if !stack.is_empty() {
10628 stack.push(("ExprPayloadAttrs", cur));
10629 }
10630 (stack, None)
10631 }
10632}
10633#[derive(Clone)]
10634pub enum ExprRejectAttrs {
10635 #[doc = "Associated type: \"RejectTypes\" (enum)"]
10636 Type(u32),
10637 IcmpCode(u8),
10638}
10639impl<'a> IterableExprRejectAttrs<'a> {
10640 #[doc = "Associated type: \"RejectTypes\" (enum)"]
10641 pub fn get_type(&self) -> Result<u32, ErrorContext> {
10642 let mut iter = self.clone();
10643 iter.pos = 0;
10644 for attr in iter {
10645 if let ExprRejectAttrs::Type(val) = attr? {
10646 return Ok(val);
10647 }
10648 }
10649 Err(ErrorContext::new_missing(
10650 "ExprRejectAttrs",
10651 "Type",
10652 self.orig_loc,
10653 self.buf.as_ptr() as usize,
10654 ))
10655 }
10656 pub fn get_icmp_code(&self) -> Result<u8, ErrorContext> {
10657 let mut iter = self.clone();
10658 iter.pos = 0;
10659 for attr in iter {
10660 if let ExprRejectAttrs::IcmpCode(val) = attr? {
10661 return Ok(val);
10662 }
10663 }
10664 Err(ErrorContext::new_missing(
10665 "ExprRejectAttrs",
10666 "IcmpCode",
10667 self.orig_loc,
10668 self.buf.as_ptr() as usize,
10669 ))
10670 }
10671}
10672impl ExprRejectAttrs {
10673 pub fn new(buf: &'_ [u8]) -> IterableExprRejectAttrs<'_> {
10674 IterableExprRejectAttrs::with_loc(buf, buf.as_ptr() as usize)
10675 }
10676 fn attr_from_type(r#type: u16) -> Option<&'static str> {
10677 let res = match r#type {
10678 1u16 => "Type",
10679 2u16 => "IcmpCode",
10680 _ => return None,
10681 };
10682 Some(res)
10683 }
10684}
10685#[derive(Clone, Copy, Default)]
10686pub struct IterableExprRejectAttrs<'a> {
10687 buf: &'a [u8],
10688 pos: usize,
10689 orig_loc: usize,
10690}
10691impl<'a> IterableExprRejectAttrs<'a> {
10692 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
10693 Self {
10694 buf,
10695 pos: 0,
10696 orig_loc,
10697 }
10698 }
10699 pub fn get_buf(&self) -> &'a [u8] {
10700 self.buf
10701 }
10702}
10703impl<'a> Iterator for IterableExprRejectAttrs<'a> {
10704 type Item = Result<ExprRejectAttrs, ErrorContext>;
10705 fn next(&mut self) -> Option<Self::Item> {
10706 if self.buf.len() == self.pos {
10707 return None;
10708 }
10709 let pos = self.pos;
10710 let mut r#type = None;
10711 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
10712 r#type = Some(header.r#type);
10713 let res = match header.r#type {
10714 1u16 => ExprRejectAttrs::Type({
10715 let res = parse_be_u32(next);
10716 let Some(val) = res else { break };
10717 val
10718 }),
10719 2u16 => ExprRejectAttrs::IcmpCode({
10720 let res = parse_u8(next);
10721 let Some(val) = res else { break };
10722 val
10723 }),
10724 n => {
10725 if cfg!(any(test, feature = "deny-unknown-attrs")) {
10726 break;
10727 } else {
10728 continue;
10729 }
10730 }
10731 };
10732 return Some(Ok(res));
10733 }
10734 Some(Err(ErrorContext::new(
10735 "ExprRejectAttrs",
10736 r#type.and_then(|t| ExprRejectAttrs::attr_from_type(t)),
10737 self.orig_loc,
10738 self.buf.as_ptr().wrapping_add(pos) as usize,
10739 )))
10740 }
10741}
10742impl std::fmt::Debug for IterableExprRejectAttrs<'_> {
10743 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10744 let mut fmt = f.debug_struct("ExprRejectAttrs");
10745 for attr in self.clone() {
10746 let attr = match attr {
10747 Ok(a) => a,
10748 Err(err) => {
10749 fmt.finish()?;
10750 f.write_str("Err(")?;
10751 err.fmt(f)?;
10752 return f.write_str(")");
10753 }
10754 };
10755 match attr {
10756 ExprRejectAttrs::Type(val) => {
10757 fmt.field("Type", &FormatEnum(val.into(), RejectTypes::from_value))
10758 }
10759 ExprRejectAttrs::IcmpCode(val) => fmt.field("IcmpCode", &val),
10760 };
10761 }
10762 fmt.finish()
10763 }
10764}
10765impl IterableExprRejectAttrs<'_> {
10766 pub fn lookup_attr(
10767 &self,
10768 offset: usize,
10769 missing_type: Option<u16>,
10770 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
10771 let mut stack = Vec::new();
10772 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
10773 if cur == offset {
10774 stack.push(("ExprRejectAttrs", offset));
10775 return (
10776 stack,
10777 missing_type.and_then(|t| ExprRejectAttrs::attr_from_type(t)),
10778 );
10779 }
10780 if cur > offset || cur + self.buf.len() < offset {
10781 return (stack, None);
10782 }
10783 let mut attrs = self.clone();
10784 let mut last_off = cur + attrs.pos;
10785 while let Some(attr) = attrs.next() {
10786 let Ok(attr) = attr else { break };
10787 match attr {
10788 ExprRejectAttrs::Type(val) => {
10789 if last_off == offset {
10790 stack.push(("Type", last_off));
10791 break;
10792 }
10793 }
10794 ExprRejectAttrs::IcmpCode(val) => {
10795 if last_off == offset {
10796 stack.push(("IcmpCode", last_off));
10797 break;
10798 }
10799 }
10800 _ => {}
10801 };
10802 last_off = cur + attrs.pos;
10803 }
10804 if !stack.is_empty() {
10805 stack.push(("ExprRejectAttrs", cur));
10806 }
10807 (stack, None)
10808 }
10809}
10810#[derive(Clone)]
10811pub enum ExprTargetAttrs<'a> {
10812 Name(&'a CStr),
10813 Rev(u32),
10814 Info(&'a [u8]),
10815}
10816impl<'a> IterableExprTargetAttrs<'a> {
10817 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
10818 let mut iter = self.clone();
10819 iter.pos = 0;
10820 for attr in iter {
10821 if let ExprTargetAttrs::Name(val) = attr? {
10822 return Ok(val);
10823 }
10824 }
10825 Err(ErrorContext::new_missing(
10826 "ExprTargetAttrs",
10827 "Name",
10828 self.orig_loc,
10829 self.buf.as_ptr() as usize,
10830 ))
10831 }
10832 pub fn get_rev(&self) -> Result<u32, ErrorContext> {
10833 let mut iter = self.clone();
10834 iter.pos = 0;
10835 for attr in iter {
10836 if let ExprTargetAttrs::Rev(val) = attr? {
10837 return Ok(val);
10838 }
10839 }
10840 Err(ErrorContext::new_missing(
10841 "ExprTargetAttrs",
10842 "Rev",
10843 self.orig_loc,
10844 self.buf.as_ptr() as usize,
10845 ))
10846 }
10847 pub fn get_info(&self) -> Result<&'a [u8], ErrorContext> {
10848 let mut iter = self.clone();
10849 iter.pos = 0;
10850 for attr in iter {
10851 if let ExprTargetAttrs::Info(val) = attr? {
10852 return Ok(val);
10853 }
10854 }
10855 Err(ErrorContext::new_missing(
10856 "ExprTargetAttrs",
10857 "Info",
10858 self.orig_loc,
10859 self.buf.as_ptr() as usize,
10860 ))
10861 }
10862}
10863impl<'a> ExprTargetAttrs<'a> {
10864 pub fn new(buf: &'a [u8]) -> IterableExprTargetAttrs<'a> {
10865 IterableExprTargetAttrs::with_loc(buf, buf.as_ptr() as usize)
10866 }
10867 fn attr_from_type(r#type: u16) -> Option<&'static str> {
10868 let res = match r#type {
10869 1u16 => "Name",
10870 2u16 => "Rev",
10871 3u16 => "Info",
10872 _ => return None,
10873 };
10874 Some(res)
10875 }
10876}
10877#[derive(Clone, Copy, Default)]
10878pub struct IterableExprTargetAttrs<'a> {
10879 buf: &'a [u8],
10880 pos: usize,
10881 orig_loc: usize,
10882}
10883impl<'a> IterableExprTargetAttrs<'a> {
10884 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
10885 Self {
10886 buf,
10887 pos: 0,
10888 orig_loc,
10889 }
10890 }
10891 pub fn get_buf(&self) -> &'a [u8] {
10892 self.buf
10893 }
10894}
10895impl<'a> Iterator for IterableExprTargetAttrs<'a> {
10896 type Item = Result<ExprTargetAttrs<'a>, ErrorContext>;
10897 fn next(&mut self) -> Option<Self::Item> {
10898 if self.buf.len() == self.pos {
10899 return None;
10900 }
10901 let pos = self.pos;
10902 let mut r#type = None;
10903 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
10904 r#type = Some(header.r#type);
10905 let res = match header.r#type {
10906 1u16 => ExprTargetAttrs::Name({
10907 let res = CStr::from_bytes_with_nul(next).ok();
10908 let Some(val) = res else { break };
10909 val
10910 }),
10911 2u16 => ExprTargetAttrs::Rev({
10912 let res = parse_be_u32(next);
10913 let Some(val) = res else { break };
10914 val
10915 }),
10916 3u16 => ExprTargetAttrs::Info({
10917 let res = Some(next);
10918 let Some(val) = res else { break };
10919 val
10920 }),
10921 n => {
10922 if cfg!(any(test, feature = "deny-unknown-attrs")) {
10923 break;
10924 } else {
10925 continue;
10926 }
10927 }
10928 };
10929 return Some(Ok(res));
10930 }
10931 Some(Err(ErrorContext::new(
10932 "ExprTargetAttrs",
10933 r#type.and_then(|t| ExprTargetAttrs::attr_from_type(t)),
10934 self.orig_loc,
10935 self.buf.as_ptr().wrapping_add(pos) as usize,
10936 )))
10937 }
10938}
10939impl<'a> std::fmt::Debug for IterableExprTargetAttrs<'_> {
10940 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10941 let mut fmt = f.debug_struct("ExprTargetAttrs");
10942 for attr in self.clone() {
10943 let attr = match attr {
10944 Ok(a) => a,
10945 Err(err) => {
10946 fmt.finish()?;
10947 f.write_str("Err(")?;
10948 err.fmt(f)?;
10949 return f.write_str(")");
10950 }
10951 };
10952 match attr {
10953 ExprTargetAttrs::Name(val) => fmt.field("Name", &val),
10954 ExprTargetAttrs::Rev(val) => fmt.field("Rev", &val),
10955 ExprTargetAttrs::Info(val) => fmt.field("Info", &val),
10956 };
10957 }
10958 fmt.finish()
10959 }
10960}
10961impl IterableExprTargetAttrs<'_> {
10962 pub fn lookup_attr(
10963 &self,
10964 offset: usize,
10965 missing_type: Option<u16>,
10966 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
10967 let mut stack = Vec::new();
10968 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
10969 if cur == offset {
10970 stack.push(("ExprTargetAttrs", offset));
10971 return (
10972 stack,
10973 missing_type.and_then(|t| ExprTargetAttrs::attr_from_type(t)),
10974 );
10975 }
10976 if cur > offset || cur + self.buf.len() < offset {
10977 return (stack, None);
10978 }
10979 let mut attrs = self.clone();
10980 let mut last_off = cur + attrs.pos;
10981 while let Some(attr) = attrs.next() {
10982 let Ok(attr) = attr else { break };
10983 match attr {
10984 ExprTargetAttrs::Name(val) => {
10985 if last_off == offset {
10986 stack.push(("Name", last_off));
10987 break;
10988 }
10989 }
10990 ExprTargetAttrs::Rev(val) => {
10991 if last_off == offset {
10992 stack.push(("Rev", last_off));
10993 break;
10994 }
10995 }
10996 ExprTargetAttrs::Info(val) => {
10997 if last_off == offset {
10998 stack.push(("Info", last_off));
10999 break;
11000 }
11001 }
11002 _ => {}
11003 };
11004 last_off = cur + attrs.pos;
11005 }
11006 if !stack.is_empty() {
11007 stack.push(("ExprTargetAttrs", cur));
11008 }
11009 (stack, None)
11010 }
11011}
11012#[derive(Clone)]
11013pub enum ExprTproxyAttrs {
11014 Family(u32),
11015 RegAddr(u32),
11016 RegPort(u32),
11017}
11018impl<'a> IterableExprTproxyAttrs<'a> {
11019 pub fn get_family(&self) -> Result<u32, ErrorContext> {
11020 let mut iter = self.clone();
11021 iter.pos = 0;
11022 for attr in iter {
11023 if let ExprTproxyAttrs::Family(val) = attr? {
11024 return Ok(val);
11025 }
11026 }
11027 Err(ErrorContext::new_missing(
11028 "ExprTproxyAttrs",
11029 "Family",
11030 self.orig_loc,
11031 self.buf.as_ptr() as usize,
11032 ))
11033 }
11034 pub fn get_reg_addr(&self) -> Result<u32, ErrorContext> {
11035 let mut iter = self.clone();
11036 iter.pos = 0;
11037 for attr in iter {
11038 if let ExprTproxyAttrs::RegAddr(val) = attr? {
11039 return Ok(val);
11040 }
11041 }
11042 Err(ErrorContext::new_missing(
11043 "ExprTproxyAttrs",
11044 "RegAddr",
11045 self.orig_loc,
11046 self.buf.as_ptr() as usize,
11047 ))
11048 }
11049 pub fn get_reg_port(&self) -> Result<u32, ErrorContext> {
11050 let mut iter = self.clone();
11051 iter.pos = 0;
11052 for attr in iter {
11053 if let ExprTproxyAttrs::RegPort(val) = attr? {
11054 return Ok(val);
11055 }
11056 }
11057 Err(ErrorContext::new_missing(
11058 "ExprTproxyAttrs",
11059 "RegPort",
11060 self.orig_loc,
11061 self.buf.as_ptr() as usize,
11062 ))
11063 }
11064}
11065impl ExprTproxyAttrs {
11066 pub fn new(buf: &'_ [u8]) -> IterableExprTproxyAttrs<'_> {
11067 IterableExprTproxyAttrs::with_loc(buf, buf.as_ptr() as usize)
11068 }
11069 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11070 let res = match r#type {
11071 1u16 => "Family",
11072 2u16 => "RegAddr",
11073 3u16 => "RegPort",
11074 _ => return None,
11075 };
11076 Some(res)
11077 }
11078}
11079#[derive(Clone, Copy, Default)]
11080pub struct IterableExprTproxyAttrs<'a> {
11081 buf: &'a [u8],
11082 pos: usize,
11083 orig_loc: usize,
11084}
11085impl<'a> IterableExprTproxyAttrs<'a> {
11086 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11087 Self {
11088 buf,
11089 pos: 0,
11090 orig_loc,
11091 }
11092 }
11093 pub fn get_buf(&self) -> &'a [u8] {
11094 self.buf
11095 }
11096}
11097impl<'a> Iterator for IterableExprTproxyAttrs<'a> {
11098 type Item = Result<ExprTproxyAttrs, ErrorContext>;
11099 fn next(&mut self) -> Option<Self::Item> {
11100 if self.buf.len() == self.pos {
11101 return None;
11102 }
11103 let pos = self.pos;
11104 let mut r#type = None;
11105 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
11106 r#type = Some(header.r#type);
11107 let res = match header.r#type {
11108 1u16 => ExprTproxyAttrs::Family({
11109 let res = parse_be_u32(next);
11110 let Some(val) = res else { break };
11111 val
11112 }),
11113 2u16 => ExprTproxyAttrs::RegAddr({
11114 let res = parse_be_u32(next);
11115 let Some(val) = res else { break };
11116 val
11117 }),
11118 3u16 => ExprTproxyAttrs::RegPort({
11119 let res = parse_be_u32(next);
11120 let Some(val) = res else { break };
11121 val
11122 }),
11123 n => {
11124 if cfg!(any(test, feature = "deny-unknown-attrs")) {
11125 break;
11126 } else {
11127 continue;
11128 }
11129 }
11130 };
11131 return Some(Ok(res));
11132 }
11133 Some(Err(ErrorContext::new(
11134 "ExprTproxyAttrs",
11135 r#type.and_then(|t| ExprTproxyAttrs::attr_from_type(t)),
11136 self.orig_loc,
11137 self.buf.as_ptr().wrapping_add(pos) as usize,
11138 )))
11139 }
11140}
11141impl std::fmt::Debug for IterableExprTproxyAttrs<'_> {
11142 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11143 let mut fmt = f.debug_struct("ExprTproxyAttrs");
11144 for attr in self.clone() {
11145 let attr = match attr {
11146 Ok(a) => a,
11147 Err(err) => {
11148 fmt.finish()?;
11149 f.write_str("Err(")?;
11150 err.fmt(f)?;
11151 return f.write_str(")");
11152 }
11153 };
11154 match attr {
11155 ExprTproxyAttrs::Family(val) => fmt.field("Family", &val),
11156 ExprTproxyAttrs::RegAddr(val) => fmt.field("RegAddr", &val),
11157 ExprTproxyAttrs::RegPort(val) => fmt.field("RegPort", &val),
11158 };
11159 }
11160 fmt.finish()
11161 }
11162}
11163impl IterableExprTproxyAttrs<'_> {
11164 pub fn lookup_attr(
11165 &self,
11166 offset: usize,
11167 missing_type: Option<u16>,
11168 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11169 let mut stack = Vec::new();
11170 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11171 if cur == offset {
11172 stack.push(("ExprTproxyAttrs", offset));
11173 return (
11174 stack,
11175 missing_type.and_then(|t| ExprTproxyAttrs::attr_from_type(t)),
11176 );
11177 }
11178 if cur > offset || cur + self.buf.len() < offset {
11179 return (stack, None);
11180 }
11181 let mut attrs = self.clone();
11182 let mut last_off = cur + attrs.pos;
11183 while let Some(attr) = attrs.next() {
11184 let Ok(attr) = attr else { break };
11185 match attr {
11186 ExprTproxyAttrs::Family(val) => {
11187 if last_off == offset {
11188 stack.push(("Family", last_off));
11189 break;
11190 }
11191 }
11192 ExprTproxyAttrs::RegAddr(val) => {
11193 if last_off == offset {
11194 stack.push(("RegAddr", last_off));
11195 break;
11196 }
11197 }
11198 ExprTproxyAttrs::RegPort(val) => {
11199 if last_off == offset {
11200 stack.push(("RegPort", last_off));
11201 break;
11202 }
11203 }
11204 _ => {}
11205 };
11206 last_off = cur + attrs.pos;
11207 }
11208 if !stack.is_empty() {
11209 stack.push(("ExprTproxyAttrs", cur));
11210 }
11211 (stack, None)
11212 }
11213}
11214#[derive(Clone)]
11215pub enum ExprObjrefAttrs<'a> {
11216 ImmType(u32),
11217 #[doc = "object name"]
11218 ImmName(&'a CStr),
11219 SetSreg(u32),
11220 #[doc = "name of object map"]
11221 SetName(&'a CStr),
11222 #[doc = "id of object map"]
11223 SetId(u32),
11224}
11225impl<'a> IterableExprObjrefAttrs<'a> {
11226 pub fn get_imm_type(&self) -> Result<u32, ErrorContext> {
11227 let mut iter = self.clone();
11228 iter.pos = 0;
11229 for attr in iter {
11230 if let ExprObjrefAttrs::ImmType(val) = attr? {
11231 return Ok(val);
11232 }
11233 }
11234 Err(ErrorContext::new_missing(
11235 "ExprObjrefAttrs",
11236 "ImmType",
11237 self.orig_loc,
11238 self.buf.as_ptr() as usize,
11239 ))
11240 }
11241 #[doc = "object name"]
11242 pub fn get_imm_name(&self) -> Result<&'a CStr, ErrorContext> {
11243 let mut iter = self.clone();
11244 iter.pos = 0;
11245 for attr in iter {
11246 if let ExprObjrefAttrs::ImmName(val) = attr? {
11247 return Ok(val);
11248 }
11249 }
11250 Err(ErrorContext::new_missing(
11251 "ExprObjrefAttrs",
11252 "ImmName",
11253 self.orig_loc,
11254 self.buf.as_ptr() as usize,
11255 ))
11256 }
11257 pub fn get_set_sreg(&self) -> Result<u32, ErrorContext> {
11258 let mut iter = self.clone();
11259 iter.pos = 0;
11260 for attr in iter {
11261 if let ExprObjrefAttrs::SetSreg(val) = attr? {
11262 return Ok(val);
11263 }
11264 }
11265 Err(ErrorContext::new_missing(
11266 "ExprObjrefAttrs",
11267 "SetSreg",
11268 self.orig_loc,
11269 self.buf.as_ptr() as usize,
11270 ))
11271 }
11272 #[doc = "name of object map"]
11273 pub fn get_set_name(&self) -> Result<&'a CStr, ErrorContext> {
11274 let mut iter = self.clone();
11275 iter.pos = 0;
11276 for attr in iter {
11277 if let ExprObjrefAttrs::SetName(val) = attr? {
11278 return Ok(val);
11279 }
11280 }
11281 Err(ErrorContext::new_missing(
11282 "ExprObjrefAttrs",
11283 "SetName",
11284 self.orig_loc,
11285 self.buf.as_ptr() as usize,
11286 ))
11287 }
11288 #[doc = "id of object map"]
11289 pub fn get_set_id(&self) -> Result<u32, ErrorContext> {
11290 let mut iter = self.clone();
11291 iter.pos = 0;
11292 for attr in iter {
11293 if let ExprObjrefAttrs::SetId(val) = attr? {
11294 return Ok(val);
11295 }
11296 }
11297 Err(ErrorContext::new_missing(
11298 "ExprObjrefAttrs",
11299 "SetId",
11300 self.orig_loc,
11301 self.buf.as_ptr() as usize,
11302 ))
11303 }
11304}
11305impl<'a> ExprObjrefAttrs<'a> {
11306 pub fn new(buf: &'a [u8]) -> IterableExprObjrefAttrs<'a> {
11307 IterableExprObjrefAttrs::with_loc(buf, buf.as_ptr() as usize)
11308 }
11309 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11310 let res = match r#type {
11311 1u16 => "ImmType",
11312 2u16 => "ImmName",
11313 3u16 => "SetSreg",
11314 4u16 => "SetName",
11315 5u16 => "SetId",
11316 _ => return None,
11317 };
11318 Some(res)
11319 }
11320}
11321#[derive(Clone, Copy, Default)]
11322pub struct IterableExprObjrefAttrs<'a> {
11323 buf: &'a [u8],
11324 pos: usize,
11325 orig_loc: usize,
11326}
11327impl<'a> IterableExprObjrefAttrs<'a> {
11328 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11329 Self {
11330 buf,
11331 pos: 0,
11332 orig_loc,
11333 }
11334 }
11335 pub fn get_buf(&self) -> &'a [u8] {
11336 self.buf
11337 }
11338}
11339impl<'a> Iterator for IterableExprObjrefAttrs<'a> {
11340 type Item = Result<ExprObjrefAttrs<'a>, ErrorContext>;
11341 fn next(&mut self) -> Option<Self::Item> {
11342 if self.buf.len() == self.pos {
11343 return None;
11344 }
11345 let pos = self.pos;
11346 let mut r#type = None;
11347 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
11348 r#type = Some(header.r#type);
11349 let res = match header.r#type {
11350 1u16 => ExprObjrefAttrs::ImmType({
11351 let res = parse_be_u32(next);
11352 let Some(val) = res else { break };
11353 val
11354 }),
11355 2u16 => ExprObjrefAttrs::ImmName({
11356 let res = CStr::from_bytes_with_nul(next).ok();
11357 let Some(val) = res else { break };
11358 val
11359 }),
11360 3u16 => ExprObjrefAttrs::SetSreg({
11361 let res = parse_be_u32(next);
11362 let Some(val) = res else { break };
11363 val
11364 }),
11365 4u16 => ExprObjrefAttrs::SetName({
11366 let res = CStr::from_bytes_with_nul(next).ok();
11367 let Some(val) = res else { break };
11368 val
11369 }),
11370 5u16 => ExprObjrefAttrs::SetId({
11371 let res = parse_be_u32(next);
11372 let Some(val) = res else { break };
11373 val
11374 }),
11375 n => {
11376 if cfg!(any(test, feature = "deny-unknown-attrs")) {
11377 break;
11378 } else {
11379 continue;
11380 }
11381 }
11382 };
11383 return Some(Ok(res));
11384 }
11385 Some(Err(ErrorContext::new(
11386 "ExprObjrefAttrs",
11387 r#type.and_then(|t| ExprObjrefAttrs::attr_from_type(t)),
11388 self.orig_loc,
11389 self.buf.as_ptr().wrapping_add(pos) as usize,
11390 )))
11391 }
11392}
11393impl<'a> std::fmt::Debug for IterableExprObjrefAttrs<'_> {
11394 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11395 let mut fmt = f.debug_struct("ExprObjrefAttrs");
11396 for attr in self.clone() {
11397 let attr = match attr {
11398 Ok(a) => a,
11399 Err(err) => {
11400 fmt.finish()?;
11401 f.write_str("Err(")?;
11402 err.fmt(f)?;
11403 return f.write_str(")");
11404 }
11405 };
11406 match attr {
11407 ExprObjrefAttrs::ImmType(val) => fmt.field("ImmType", &val),
11408 ExprObjrefAttrs::ImmName(val) => fmt.field("ImmName", &val),
11409 ExprObjrefAttrs::SetSreg(val) => fmt.field("SetSreg", &val),
11410 ExprObjrefAttrs::SetName(val) => fmt.field("SetName", &val),
11411 ExprObjrefAttrs::SetId(val) => fmt.field("SetId", &val),
11412 };
11413 }
11414 fmt.finish()
11415 }
11416}
11417impl IterableExprObjrefAttrs<'_> {
11418 pub fn lookup_attr(
11419 &self,
11420 offset: usize,
11421 missing_type: Option<u16>,
11422 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11423 let mut stack = Vec::new();
11424 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11425 if cur == offset {
11426 stack.push(("ExprObjrefAttrs", offset));
11427 return (
11428 stack,
11429 missing_type.and_then(|t| ExprObjrefAttrs::attr_from_type(t)),
11430 );
11431 }
11432 if cur > offset || cur + self.buf.len() < offset {
11433 return (stack, None);
11434 }
11435 let mut attrs = self.clone();
11436 let mut last_off = cur + attrs.pos;
11437 while let Some(attr) = attrs.next() {
11438 let Ok(attr) = attr else { break };
11439 match attr {
11440 ExprObjrefAttrs::ImmType(val) => {
11441 if last_off == offset {
11442 stack.push(("ImmType", last_off));
11443 break;
11444 }
11445 }
11446 ExprObjrefAttrs::ImmName(val) => {
11447 if last_off == offset {
11448 stack.push(("ImmName", last_off));
11449 break;
11450 }
11451 }
11452 ExprObjrefAttrs::SetSreg(val) => {
11453 if last_off == offset {
11454 stack.push(("SetSreg", last_off));
11455 break;
11456 }
11457 }
11458 ExprObjrefAttrs::SetName(val) => {
11459 if last_off == offset {
11460 stack.push(("SetName", last_off));
11461 break;
11462 }
11463 }
11464 ExprObjrefAttrs::SetId(val) => {
11465 if last_off == offset {
11466 stack.push(("SetId", last_off));
11467 break;
11468 }
11469 }
11470 _ => {}
11471 };
11472 last_off = cur + attrs.pos;
11473 }
11474 if !stack.is_empty() {
11475 stack.push(("ExprObjrefAttrs", cur));
11476 }
11477 (stack, None)
11478 }
11479}
11480#[derive(Clone)]
11481pub enum CompatTargetAttrs<'a> {
11482 Name(&'a CStr),
11483 Rev(u32),
11484 Info(&'a [u8]),
11485}
11486impl<'a> IterableCompatTargetAttrs<'a> {
11487 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
11488 let mut iter = self.clone();
11489 iter.pos = 0;
11490 for attr in iter {
11491 if let CompatTargetAttrs::Name(val) = attr? {
11492 return Ok(val);
11493 }
11494 }
11495 Err(ErrorContext::new_missing(
11496 "CompatTargetAttrs",
11497 "Name",
11498 self.orig_loc,
11499 self.buf.as_ptr() as usize,
11500 ))
11501 }
11502 pub fn get_rev(&self) -> Result<u32, ErrorContext> {
11503 let mut iter = self.clone();
11504 iter.pos = 0;
11505 for attr in iter {
11506 if let CompatTargetAttrs::Rev(val) = attr? {
11507 return Ok(val);
11508 }
11509 }
11510 Err(ErrorContext::new_missing(
11511 "CompatTargetAttrs",
11512 "Rev",
11513 self.orig_loc,
11514 self.buf.as_ptr() as usize,
11515 ))
11516 }
11517 pub fn get_info(&self) -> Result<&'a [u8], ErrorContext> {
11518 let mut iter = self.clone();
11519 iter.pos = 0;
11520 for attr in iter {
11521 if let CompatTargetAttrs::Info(val) = attr? {
11522 return Ok(val);
11523 }
11524 }
11525 Err(ErrorContext::new_missing(
11526 "CompatTargetAttrs",
11527 "Info",
11528 self.orig_loc,
11529 self.buf.as_ptr() as usize,
11530 ))
11531 }
11532}
11533impl<'a> CompatTargetAttrs<'a> {
11534 pub fn new(buf: &'a [u8]) -> IterableCompatTargetAttrs<'a> {
11535 IterableCompatTargetAttrs::with_loc(buf, buf.as_ptr() as usize)
11536 }
11537 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11538 let res = match r#type {
11539 1u16 => "Name",
11540 2u16 => "Rev",
11541 3u16 => "Info",
11542 _ => return None,
11543 };
11544 Some(res)
11545 }
11546}
11547#[derive(Clone, Copy, Default)]
11548pub struct IterableCompatTargetAttrs<'a> {
11549 buf: &'a [u8],
11550 pos: usize,
11551 orig_loc: usize,
11552}
11553impl<'a> IterableCompatTargetAttrs<'a> {
11554 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11555 Self {
11556 buf,
11557 pos: 0,
11558 orig_loc,
11559 }
11560 }
11561 pub fn get_buf(&self) -> &'a [u8] {
11562 self.buf
11563 }
11564}
11565impl<'a> Iterator for IterableCompatTargetAttrs<'a> {
11566 type Item = Result<CompatTargetAttrs<'a>, ErrorContext>;
11567 fn next(&mut self) -> Option<Self::Item> {
11568 if self.buf.len() == self.pos {
11569 return None;
11570 }
11571 let pos = self.pos;
11572 let mut r#type = None;
11573 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
11574 r#type = Some(header.r#type);
11575 let res = match header.r#type {
11576 1u16 => CompatTargetAttrs::Name({
11577 let res = CStr::from_bytes_with_nul(next).ok();
11578 let Some(val) = res else { break };
11579 val
11580 }),
11581 2u16 => CompatTargetAttrs::Rev({
11582 let res = parse_be_u32(next);
11583 let Some(val) = res else { break };
11584 val
11585 }),
11586 3u16 => CompatTargetAttrs::Info({
11587 let res = Some(next);
11588 let Some(val) = res else { break };
11589 val
11590 }),
11591 n => {
11592 if cfg!(any(test, feature = "deny-unknown-attrs")) {
11593 break;
11594 } else {
11595 continue;
11596 }
11597 }
11598 };
11599 return Some(Ok(res));
11600 }
11601 Some(Err(ErrorContext::new(
11602 "CompatTargetAttrs",
11603 r#type.and_then(|t| CompatTargetAttrs::attr_from_type(t)),
11604 self.orig_loc,
11605 self.buf.as_ptr().wrapping_add(pos) as usize,
11606 )))
11607 }
11608}
11609impl<'a> std::fmt::Debug for IterableCompatTargetAttrs<'_> {
11610 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11611 let mut fmt = f.debug_struct("CompatTargetAttrs");
11612 for attr in self.clone() {
11613 let attr = match attr {
11614 Ok(a) => a,
11615 Err(err) => {
11616 fmt.finish()?;
11617 f.write_str("Err(")?;
11618 err.fmt(f)?;
11619 return f.write_str(")");
11620 }
11621 };
11622 match attr {
11623 CompatTargetAttrs::Name(val) => fmt.field("Name", &val),
11624 CompatTargetAttrs::Rev(val) => fmt.field("Rev", &val),
11625 CompatTargetAttrs::Info(val) => fmt.field("Info", &val),
11626 };
11627 }
11628 fmt.finish()
11629 }
11630}
11631impl IterableCompatTargetAttrs<'_> {
11632 pub fn lookup_attr(
11633 &self,
11634 offset: usize,
11635 missing_type: Option<u16>,
11636 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11637 let mut stack = Vec::new();
11638 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11639 if cur == offset {
11640 stack.push(("CompatTargetAttrs", offset));
11641 return (
11642 stack,
11643 missing_type.and_then(|t| CompatTargetAttrs::attr_from_type(t)),
11644 );
11645 }
11646 if cur > offset || cur + self.buf.len() < offset {
11647 return (stack, None);
11648 }
11649 let mut attrs = self.clone();
11650 let mut last_off = cur + attrs.pos;
11651 while let Some(attr) = attrs.next() {
11652 let Ok(attr) = attr else { break };
11653 match attr {
11654 CompatTargetAttrs::Name(val) => {
11655 if last_off == offset {
11656 stack.push(("Name", last_off));
11657 break;
11658 }
11659 }
11660 CompatTargetAttrs::Rev(val) => {
11661 if last_off == offset {
11662 stack.push(("Rev", last_off));
11663 break;
11664 }
11665 }
11666 CompatTargetAttrs::Info(val) => {
11667 if last_off == offset {
11668 stack.push(("Info", last_off));
11669 break;
11670 }
11671 }
11672 _ => {}
11673 };
11674 last_off = cur + attrs.pos;
11675 }
11676 if !stack.is_empty() {
11677 stack.push(("CompatTargetAttrs", cur));
11678 }
11679 (stack, None)
11680 }
11681}
11682#[derive(Clone)]
11683pub enum CompatMatchAttrs<'a> {
11684 Name(&'a CStr),
11685 Rev(u32),
11686 Info(&'a [u8]),
11687}
11688impl<'a> IterableCompatMatchAttrs<'a> {
11689 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
11690 let mut iter = self.clone();
11691 iter.pos = 0;
11692 for attr in iter {
11693 if let CompatMatchAttrs::Name(val) = attr? {
11694 return Ok(val);
11695 }
11696 }
11697 Err(ErrorContext::new_missing(
11698 "CompatMatchAttrs",
11699 "Name",
11700 self.orig_loc,
11701 self.buf.as_ptr() as usize,
11702 ))
11703 }
11704 pub fn get_rev(&self) -> Result<u32, ErrorContext> {
11705 let mut iter = self.clone();
11706 iter.pos = 0;
11707 for attr in iter {
11708 if let CompatMatchAttrs::Rev(val) = attr? {
11709 return Ok(val);
11710 }
11711 }
11712 Err(ErrorContext::new_missing(
11713 "CompatMatchAttrs",
11714 "Rev",
11715 self.orig_loc,
11716 self.buf.as_ptr() as usize,
11717 ))
11718 }
11719 pub fn get_info(&self) -> Result<&'a [u8], ErrorContext> {
11720 let mut iter = self.clone();
11721 iter.pos = 0;
11722 for attr in iter {
11723 if let CompatMatchAttrs::Info(val) = attr? {
11724 return Ok(val);
11725 }
11726 }
11727 Err(ErrorContext::new_missing(
11728 "CompatMatchAttrs",
11729 "Info",
11730 self.orig_loc,
11731 self.buf.as_ptr() as usize,
11732 ))
11733 }
11734}
11735impl<'a> CompatMatchAttrs<'a> {
11736 pub fn new(buf: &'a [u8]) -> IterableCompatMatchAttrs<'a> {
11737 IterableCompatMatchAttrs::with_loc(buf, buf.as_ptr() as usize)
11738 }
11739 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11740 let res = match r#type {
11741 1u16 => "Name",
11742 2u16 => "Rev",
11743 3u16 => "Info",
11744 _ => return None,
11745 };
11746 Some(res)
11747 }
11748}
11749#[derive(Clone, Copy, Default)]
11750pub struct IterableCompatMatchAttrs<'a> {
11751 buf: &'a [u8],
11752 pos: usize,
11753 orig_loc: usize,
11754}
11755impl<'a> IterableCompatMatchAttrs<'a> {
11756 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11757 Self {
11758 buf,
11759 pos: 0,
11760 orig_loc,
11761 }
11762 }
11763 pub fn get_buf(&self) -> &'a [u8] {
11764 self.buf
11765 }
11766}
11767impl<'a> Iterator for IterableCompatMatchAttrs<'a> {
11768 type Item = Result<CompatMatchAttrs<'a>, ErrorContext>;
11769 fn next(&mut self) -> Option<Self::Item> {
11770 if self.buf.len() == self.pos {
11771 return None;
11772 }
11773 let pos = self.pos;
11774 let mut r#type = None;
11775 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
11776 r#type = Some(header.r#type);
11777 let res = match header.r#type {
11778 1u16 => CompatMatchAttrs::Name({
11779 let res = CStr::from_bytes_with_nul(next).ok();
11780 let Some(val) = res else { break };
11781 val
11782 }),
11783 2u16 => CompatMatchAttrs::Rev({
11784 let res = parse_be_u32(next);
11785 let Some(val) = res else { break };
11786 val
11787 }),
11788 3u16 => CompatMatchAttrs::Info({
11789 let res = Some(next);
11790 let Some(val) = res else { break };
11791 val
11792 }),
11793 n => {
11794 if cfg!(any(test, feature = "deny-unknown-attrs")) {
11795 break;
11796 } else {
11797 continue;
11798 }
11799 }
11800 };
11801 return Some(Ok(res));
11802 }
11803 Some(Err(ErrorContext::new(
11804 "CompatMatchAttrs",
11805 r#type.and_then(|t| CompatMatchAttrs::attr_from_type(t)),
11806 self.orig_loc,
11807 self.buf.as_ptr().wrapping_add(pos) as usize,
11808 )))
11809 }
11810}
11811impl<'a> std::fmt::Debug for IterableCompatMatchAttrs<'_> {
11812 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11813 let mut fmt = f.debug_struct("CompatMatchAttrs");
11814 for attr in self.clone() {
11815 let attr = match attr {
11816 Ok(a) => a,
11817 Err(err) => {
11818 fmt.finish()?;
11819 f.write_str("Err(")?;
11820 err.fmt(f)?;
11821 return f.write_str(")");
11822 }
11823 };
11824 match attr {
11825 CompatMatchAttrs::Name(val) => fmt.field("Name", &val),
11826 CompatMatchAttrs::Rev(val) => fmt.field("Rev", &val),
11827 CompatMatchAttrs::Info(val) => fmt.field("Info", &val),
11828 };
11829 }
11830 fmt.finish()
11831 }
11832}
11833impl IterableCompatMatchAttrs<'_> {
11834 pub fn lookup_attr(
11835 &self,
11836 offset: usize,
11837 missing_type: Option<u16>,
11838 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
11839 let mut stack = Vec::new();
11840 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
11841 if cur == offset {
11842 stack.push(("CompatMatchAttrs", offset));
11843 return (
11844 stack,
11845 missing_type.and_then(|t| CompatMatchAttrs::attr_from_type(t)),
11846 );
11847 }
11848 if cur > offset || cur + self.buf.len() < offset {
11849 return (stack, None);
11850 }
11851 let mut attrs = self.clone();
11852 let mut last_off = cur + attrs.pos;
11853 while let Some(attr) = attrs.next() {
11854 let Ok(attr) = attr else { break };
11855 match attr {
11856 CompatMatchAttrs::Name(val) => {
11857 if last_off == offset {
11858 stack.push(("Name", last_off));
11859 break;
11860 }
11861 }
11862 CompatMatchAttrs::Rev(val) => {
11863 if last_off == offset {
11864 stack.push(("Rev", last_off));
11865 break;
11866 }
11867 }
11868 CompatMatchAttrs::Info(val) => {
11869 if last_off == offset {
11870 stack.push(("Info", last_off));
11871 break;
11872 }
11873 }
11874 _ => {}
11875 };
11876 last_off = cur + attrs.pos;
11877 }
11878 if !stack.is_empty() {
11879 stack.push(("CompatMatchAttrs", cur));
11880 }
11881 (stack, None)
11882 }
11883}
11884#[derive(Clone)]
11885pub enum CompatAttrs<'a> {
11886 Name(&'a CStr),
11887 Rev(u32),
11888 Type(u32),
11889}
11890impl<'a> IterableCompatAttrs<'a> {
11891 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
11892 let mut iter = self.clone();
11893 iter.pos = 0;
11894 for attr in iter {
11895 if let CompatAttrs::Name(val) = attr? {
11896 return Ok(val);
11897 }
11898 }
11899 Err(ErrorContext::new_missing(
11900 "CompatAttrs",
11901 "Name",
11902 self.orig_loc,
11903 self.buf.as_ptr() as usize,
11904 ))
11905 }
11906 pub fn get_rev(&self) -> Result<u32, ErrorContext> {
11907 let mut iter = self.clone();
11908 iter.pos = 0;
11909 for attr in iter {
11910 if let CompatAttrs::Rev(val) = attr? {
11911 return Ok(val);
11912 }
11913 }
11914 Err(ErrorContext::new_missing(
11915 "CompatAttrs",
11916 "Rev",
11917 self.orig_loc,
11918 self.buf.as_ptr() as usize,
11919 ))
11920 }
11921 pub fn get_type(&self) -> Result<u32, ErrorContext> {
11922 let mut iter = self.clone();
11923 iter.pos = 0;
11924 for attr in iter {
11925 if let CompatAttrs::Type(val) = attr? {
11926 return Ok(val);
11927 }
11928 }
11929 Err(ErrorContext::new_missing(
11930 "CompatAttrs",
11931 "Type",
11932 self.orig_loc,
11933 self.buf.as_ptr() as usize,
11934 ))
11935 }
11936}
11937impl<'a> CompatAttrs<'a> {
11938 pub fn new(buf: &'a [u8]) -> IterableCompatAttrs<'a> {
11939 IterableCompatAttrs::with_loc(buf, buf.as_ptr() as usize)
11940 }
11941 fn attr_from_type(r#type: u16) -> Option<&'static str> {
11942 let res = match r#type {
11943 1u16 => "Name",
11944 2u16 => "Rev",
11945 3u16 => "Type",
11946 _ => return None,
11947 };
11948 Some(res)
11949 }
11950}
11951#[derive(Clone, Copy, Default)]
11952pub struct IterableCompatAttrs<'a> {
11953 buf: &'a [u8],
11954 pos: usize,
11955 orig_loc: usize,
11956}
11957impl<'a> IterableCompatAttrs<'a> {
11958 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
11959 Self {
11960 buf,
11961 pos: 0,
11962 orig_loc,
11963 }
11964 }
11965 pub fn get_buf(&self) -> &'a [u8] {
11966 self.buf
11967 }
11968}
11969impl<'a> Iterator for IterableCompatAttrs<'a> {
11970 type Item = Result<CompatAttrs<'a>, ErrorContext>;
11971 fn next(&mut self) -> Option<Self::Item> {
11972 if self.buf.len() == self.pos {
11973 return None;
11974 }
11975 let pos = self.pos;
11976 let mut r#type = None;
11977 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
11978 r#type = Some(header.r#type);
11979 let res = match header.r#type {
11980 1u16 => CompatAttrs::Name({
11981 let res = CStr::from_bytes_with_nul(next).ok();
11982 let Some(val) = res else { break };
11983 val
11984 }),
11985 2u16 => CompatAttrs::Rev({
11986 let res = parse_be_u32(next);
11987 let Some(val) = res else { break };
11988 val
11989 }),
11990 3u16 => CompatAttrs::Type({
11991 let res = parse_be_u32(next);
11992 let Some(val) = res else { break };
11993 val
11994 }),
11995 n => {
11996 if cfg!(any(test, feature = "deny-unknown-attrs")) {
11997 break;
11998 } else {
11999 continue;
12000 }
12001 }
12002 };
12003 return Some(Ok(res));
12004 }
12005 Some(Err(ErrorContext::new(
12006 "CompatAttrs",
12007 r#type.and_then(|t| CompatAttrs::attr_from_type(t)),
12008 self.orig_loc,
12009 self.buf.as_ptr().wrapping_add(pos) as usize,
12010 )))
12011 }
12012}
12013impl<'a> std::fmt::Debug for IterableCompatAttrs<'_> {
12014 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12015 let mut fmt = f.debug_struct("CompatAttrs");
12016 for attr in self.clone() {
12017 let attr = match attr {
12018 Ok(a) => a,
12019 Err(err) => {
12020 fmt.finish()?;
12021 f.write_str("Err(")?;
12022 err.fmt(f)?;
12023 return f.write_str(")");
12024 }
12025 };
12026 match attr {
12027 CompatAttrs::Name(val) => fmt.field("Name", &val),
12028 CompatAttrs::Rev(val) => fmt.field("Rev", &val),
12029 CompatAttrs::Type(val) => fmt.field("Type", &val),
12030 };
12031 }
12032 fmt.finish()
12033 }
12034}
12035impl IterableCompatAttrs<'_> {
12036 pub fn lookup_attr(
12037 &self,
12038 offset: usize,
12039 missing_type: Option<u16>,
12040 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
12041 let mut stack = Vec::new();
12042 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
12043 if cur == offset {
12044 stack.push(("CompatAttrs", offset));
12045 return (
12046 stack,
12047 missing_type.and_then(|t| CompatAttrs::attr_from_type(t)),
12048 );
12049 }
12050 if cur > offset || cur + self.buf.len() < offset {
12051 return (stack, None);
12052 }
12053 let mut attrs = self.clone();
12054 let mut last_off = cur + attrs.pos;
12055 while let Some(attr) = attrs.next() {
12056 let Ok(attr) = attr else { break };
12057 match attr {
12058 CompatAttrs::Name(val) => {
12059 if last_off == offset {
12060 stack.push(("Name", last_off));
12061 break;
12062 }
12063 }
12064 CompatAttrs::Rev(val) => {
12065 if last_off == offset {
12066 stack.push(("Rev", last_off));
12067 break;
12068 }
12069 }
12070 CompatAttrs::Type(val) => {
12071 if last_off == offset {
12072 stack.push(("Type", last_off));
12073 break;
12074 }
12075 }
12076 _ => {}
12077 };
12078 last_off = cur + attrs.pos;
12079 }
12080 if !stack.is_empty() {
12081 stack.push(("CompatAttrs", cur));
12082 }
12083 (stack, None)
12084 }
12085}
12086pub struct PushLogAttrs<Prev: Rec> {
12087 pub(crate) prev: Option<Prev>,
12088 pub(crate) header_offset: Option<usize>,
12089}
12090impl<Prev: Rec> Rec for PushLogAttrs<Prev> {
12091 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12092 self.prev.as_mut().unwrap().as_rec_mut()
12093 }
12094}
12095impl<Prev: Rec> PushLogAttrs<Prev> {
12096 pub fn new(prev: Prev) -> Self {
12097 Self {
12098 prev: Some(prev),
12099 header_offset: None,
12100 }
12101 }
12102 pub fn end_nested(mut self) -> Prev {
12103 let mut prev = self.prev.take().unwrap();
12104 if let Some(header_offset) = &self.header_offset {
12105 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12106 }
12107 prev
12108 }
12109 #[doc = "netlink group to send messages to"]
12110 pub fn push_group(mut self, value: u16) -> Self {
12111 push_header(self.as_rec_mut(), 1u16, 2 as u16);
12112 self.as_rec_mut().extend(value.to_be_bytes());
12113 self
12114 }
12115 #[doc = "prefix to prepend to log messages"]
12116 pub fn push_prefix(mut self, value: &CStr) -> Self {
12117 push_header(
12118 self.as_rec_mut(),
12119 2u16,
12120 value.to_bytes_with_nul().len() as u16,
12121 );
12122 self.as_rec_mut().extend(value.to_bytes_with_nul());
12123 self
12124 }
12125 #[doc = "prefix to prepend to log messages"]
12126 pub fn push_prefix_bytes(mut self, value: &[u8]) -> Self {
12127 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
12128 self.as_rec_mut().extend(value);
12129 self.as_rec_mut().push(0);
12130 self
12131 }
12132 #[doc = "length of payload to include in netlink message"]
12133 pub fn push_snaplen(mut self, value: u32) -> Self {
12134 push_header(self.as_rec_mut(), 3u16, 4 as u16);
12135 self.as_rec_mut().extend(value.to_be_bytes());
12136 self
12137 }
12138 #[doc = "queue threshold"]
12139 pub fn push_qthreshold(mut self, value: u16) -> Self {
12140 push_header(self.as_rec_mut(), 4u16, 2 as u16);
12141 self.as_rec_mut().extend(value.to_be_bytes());
12142 self
12143 }
12144 #[doc = "log level\nAssociated type: \"LogLevel\" (enum)"]
12145 pub fn push_level(mut self, value: u32) -> Self {
12146 push_header(self.as_rec_mut(), 5u16, 4 as u16);
12147 self.as_rec_mut().extend(value.to_be_bytes());
12148 self
12149 }
12150 #[doc = "logging flags\nAssociated type: \"LogFlags\" (enum)"]
12151 pub fn push_flags(mut self, value: u32) -> Self {
12152 push_header(self.as_rec_mut(), 6u16, 4 as u16);
12153 self.as_rec_mut().extend(value.to_be_bytes());
12154 self
12155 }
12156}
12157impl<Prev: Rec> Drop for PushLogAttrs<Prev> {
12158 fn drop(&mut self) {
12159 if let Some(prev) = &mut self.prev {
12160 if let Some(header_offset) = &self.header_offset {
12161 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12162 }
12163 }
12164 }
12165}
12166pub struct PushNumgenAttrs<Prev: Rec> {
12167 pub(crate) prev: Option<Prev>,
12168 pub(crate) header_offset: Option<usize>,
12169}
12170impl<Prev: Rec> Rec for PushNumgenAttrs<Prev> {
12171 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12172 self.prev.as_mut().unwrap().as_rec_mut()
12173 }
12174}
12175impl<Prev: Rec> PushNumgenAttrs<Prev> {
12176 pub fn new(prev: Prev) -> Self {
12177 Self {
12178 prev: Some(prev),
12179 header_offset: None,
12180 }
12181 }
12182 pub fn end_nested(mut self) -> Prev {
12183 let mut prev = self.prev.take().unwrap();
12184 if let Some(header_offset) = &self.header_offset {
12185 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12186 }
12187 prev
12188 }
12189 #[doc = "destination register\nAssociated type: \"Registers\" (enum)"]
12190 pub fn push_dreg(mut self, value: u32) -> Self {
12191 push_header(self.as_rec_mut(), 1u16, 4 as u16);
12192 self.as_rec_mut().extend(value.to_ne_bytes());
12193 self
12194 }
12195 #[doc = "maximum counter value"]
12196 pub fn push_modulus(mut self, value: u32) -> Self {
12197 push_header(self.as_rec_mut(), 2u16, 4 as u16);
12198 self.as_rec_mut().extend(value.to_be_bytes());
12199 self
12200 }
12201 #[doc = "operation type\nAssociated type: \"NumgenTypes\" (enum)"]
12202 pub fn push_type(mut self, value: u32) -> Self {
12203 push_header(self.as_rec_mut(), 3u16, 4 as u16);
12204 self.as_rec_mut().extend(value.to_be_bytes());
12205 self
12206 }
12207 #[doc = "offset to be added to the counter"]
12208 pub fn push_offset(mut self, value: u32) -> Self {
12209 push_header(self.as_rec_mut(), 4u16, 4 as u16);
12210 self.as_rec_mut().extend(value.to_be_bytes());
12211 self
12212 }
12213}
12214impl<Prev: Rec> Drop for PushNumgenAttrs<Prev> {
12215 fn drop(&mut self) {
12216 if let Some(prev) = &mut self.prev {
12217 if let Some(header_offset) = &self.header_offset {
12218 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12219 }
12220 }
12221 }
12222}
12223pub struct PushRangeAttrs<Prev: Rec> {
12224 pub(crate) prev: Option<Prev>,
12225 pub(crate) header_offset: Option<usize>,
12226}
12227impl<Prev: Rec> Rec for PushRangeAttrs<Prev> {
12228 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12229 self.prev.as_mut().unwrap().as_rec_mut()
12230 }
12231}
12232impl<Prev: Rec> PushRangeAttrs<Prev> {
12233 pub fn new(prev: Prev) -> Self {
12234 Self {
12235 prev: Some(prev),
12236 header_offset: None,
12237 }
12238 }
12239 pub fn end_nested(mut self) -> Prev {
12240 let mut prev = self.prev.take().unwrap();
12241 if let Some(header_offset) = &self.header_offset {
12242 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12243 }
12244 prev
12245 }
12246 #[doc = "source register of data to compare\nAssociated type: \"Registers\" (enum)"]
12247 pub fn push_sreg(mut self, value: u32) -> Self {
12248 push_header(self.as_rec_mut(), 1u16, 4 as u16);
12249 self.as_rec_mut().extend(value.to_be_bytes());
12250 self
12251 }
12252 #[doc = "cmp operation\nAssociated type: \"RangeOps\" (enum)"]
12253 pub fn push_op(mut self, value: u32) -> Self {
12254 push_header(self.as_rec_mut(), 2u16, 4 as u16);
12255 self.as_rec_mut().extend(value.to_be_bytes());
12256 self
12257 }
12258 #[doc = "data range from"]
12259 pub fn nested_from_data(mut self) -> PushDataAttrs<Self> {
12260 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
12261 PushDataAttrs {
12262 prev: Some(self),
12263 header_offset: Some(header_offset),
12264 }
12265 }
12266 #[doc = "data range to"]
12267 pub fn nested_to_data(mut self) -> PushDataAttrs<Self> {
12268 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
12269 PushDataAttrs {
12270 prev: Some(self),
12271 header_offset: Some(header_offset),
12272 }
12273 }
12274}
12275impl<Prev: Rec> Drop for PushRangeAttrs<Prev> {
12276 fn drop(&mut self) {
12277 if let Some(prev) = &mut self.prev {
12278 if let Some(header_offset) = &self.header_offset {
12279 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12280 }
12281 }
12282 }
12283}
12284pub struct PushBatchAttrs<Prev: Rec> {
12285 pub(crate) prev: Option<Prev>,
12286 pub(crate) header_offset: Option<usize>,
12287}
12288impl<Prev: Rec> Rec for PushBatchAttrs<Prev> {
12289 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12290 self.prev.as_mut().unwrap().as_rec_mut()
12291 }
12292}
12293impl<Prev: Rec> PushBatchAttrs<Prev> {
12294 pub fn new(prev: Prev) -> Self {
12295 Self {
12296 prev: Some(prev),
12297 header_offset: None,
12298 }
12299 }
12300 pub fn end_nested(mut self) -> Prev {
12301 let mut prev = self.prev.take().unwrap();
12302 if let Some(header_offset) = &self.header_offset {
12303 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12304 }
12305 prev
12306 }
12307 #[doc = "generation ID for this changeset"]
12308 pub fn push_genid(mut self, value: u32) -> Self {
12309 push_header(self.as_rec_mut(), 1u16, 4 as u16);
12310 self.as_rec_mut().extend(value.to_be_bytes());
12311 self
12312 }
12313}
12314impl<Prev: Rec> Drop for PushBatchAttrs<Prev> {
12315 fn drop(&mut self) {
12316 if let Some(prev) = &mut self.prev {
12317 if let Some(header_offset) = &self.header_offset {
12318 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12319 }
12320 }
12321 }
12322}
12323pub struct PushTableAttrs<Prev: Rec> {
12324 pub(crate) prev: Option<Prev>,
12325 pub(crate) header_offset: Option<usize>,
12326}
12327impl<Prev: Rec> Rec for PushTableAttrs<Prev> {
12328 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12329 self.prev.as_mut().unwrap().as_rec_mut()
12330 }
12331}
12332impl<Prev: Rec> PushTableAttrs<Prev> {
12333 pub fn new(prev: Prev) -> Self {
12334 Self {
12335 prev: Some(prev),
12336 header_offset: None,
12337 }
12338 }
12339 pub fn end_nested(mut self) -> Prev {
12340 let mut prev = self.prev.take().unwrap();
12341 if let Some(header_offset) = &self.header_offset {
12342 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12343 }
12344 prev
12345 }
12346 #[doc = "name of the table"]
12347 pub fn push_name(mut self, value: &CStr) -> Self {
12348 push_header(
12349 self.as_rec_mut(),
12350 1u16,
12351 value.to_bytes_with_nul().len() as u16,
12352 );
12353 self.as_rec_mut().extend(value.to_bytes_with_nul());
12354 self
12355 }
12356 #[doc = "name of the table"]
12357 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
12358 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
12359 self.as_rec_mut().extend(value);
12360 self.as_rec_mut().push(0);
12361 self
12362 }
12363 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
12364 pub fn push_flags(mut self, value: u32) -> Self {
12365 push_header(self.as_rec_mut(), 2u16, 4 as u16);
12366 self.as_rec_mut().extend(value.to_be_bytes());
12367 self
12368 }
12369 #[doc = "number of chains in this table"]
12370 pub fn push_use(mut self, value: u32) -> Self {
12371 push_header(self.as_rec_mut(), 3u16, 4 as u16);
12372 self.as_rec_mut().extend(value.to_be_bytes());
12373 self
12374 }
12375 #[doc = "numeric handle of the table"]
12376 pub fn push_handle(mut self, value: u64) -> Self {
12377 push_header(self.as_rec_mut(), 4u16, 8 as u16);
12378 self.as_rec_mut().extend(value.to_be_bytes());
12379 self
12380 }
12381 pub fn push_pad(mut self, value: &[u8]) -> Self {
12382 push_header(self.as_rec_mut(), 5u16, value.len() as u16);
12383 self.as_rec_mut().extend(value);
12384 self
12385 }
12386 #[doc = "user data"]
12387 pub fn push_userdata(mut self, value: &[u8]) -> Self {
12388 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
12389 self.as_rec_mut().extend(value);
12390 self
12391 }
12392 #[doc = "owner of this table through netlink portID"]
12393 pub fn push_owner(mut self, value: u32) -> Self {
12394 push_header(self.as_rec_mut(), 7u16, 4 as u16);
12395 self.as_rec_mut().extend(value.to_be_bytes());
12396 self
12397 }
12398}
12399impl<Prev: Rec> Drop for PushTableAttrs<Prev> {
12400 fn drop(&mut self) {
12401 if let Some(prev) = &mut self.prev {
12402 if let Some(header_offset) = &self.header_offset {
12403 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12404 }
12405 }
12406 }
12407}
12408pub struct PushChainAttrs<Prev: Rec> {
12409 pub(crate) prev: Option<Prev>,
12410 pub(crate) header_offset: Option<usize>,
12411}
12412impl<Prev: Rec> Rec for PushChainAttrs<Prev> {
12413 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12414 self.prev.as_mut().unwrap().as_rec_mut()
12415 }
12416}
12417impl<Prev: Rec> PushChainAttrs<Prev> {
12418 pub fn new(prev: Prev) -> Self {
12419 Self {
12420 prev: Some(prev),
12421 header_offset: None,
12422 }
12423 }
12424 pub fn end_nested(mut self) -> Prev {
12425 let mut prev = self.prev.take().unwrap();
12426 if let Some(header_offset) = &self.header_offset {
12427 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12428 }
12429 prev
12430 }
12431 #[doc = "name of the table containing the chain"]
12432 pub fn push_table(mut self, value: &CStr) -> Self {
12433 push_header(
12434 self.as_rec_mut(),
12435 1u16,
12436 value.to_bytes_with_nul().len() as u16,
12437 );
12438 self.as_rec_mut().extend(value.to_bytes_with_nul());
12439 self
12440 }
12441 #[doc = "name of the table containing the chain"]
12442 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
12443 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
12444 self.as_rec_mut().extend(value);
12445 self.as_rec_mut().push(0);
12446 self
12447 }
12448 #[doc = "numeric handle of the chain"]
12449 pub fn push_handle(mut self, value: u64) -> Self {
12450 push_header(self.as_rec_mut(), 2u16, 8 as u16);
12451 self.as_rec_mut().extend(value.to_be_bytes());
12452 self
12453 }
12454 #[doc = "name of the chain"]
12455 pub fn push_name(mut self, value: &CStr) -> Self {
12456 push_header(
12457 self.as_rec_mut(),
12458 3u16,
12459 value.to_bytes_with_nul().len() as u16,
12460 );
12461 self.as_rec_mut().extend(value.to_bytes_with_nul());
12462 self
12463 }
12464 #[doc = "name of the chain"]
12465 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
12466 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
12467 self.as_rec_mut().extend(value);
12468 self.as_rec_mut().push(0);
12469 self
12470 }
12471 #[doc = "hook specification for basechains"]
12472 pub fn nested_hook(mut self) -> PushNftHookAttrs<Self> {
12473 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
12474 PushNftHookAttrs {
12475 prev: Some(self),
12476 header_offset: Some(header_offset),
12477 }
12478 }
12479 #[doc = "numeric policy of the chain"]
12480 pub fn push_policy(mut self, value: u32) -> Self {
12481 push_header(self.as_rec_mut(), 5u16, 4 as u16);
12482 self.as_rec_mut().extend(value.to_be_bytes());
12483 self
12484 }
12485 #[doc = "number of references to this chain"]
12486 pub fn push_use(mut self, value: u32) -> Self {
12487 push_header(self.as_rec_mut(), 6u16, 4 as u16);
12488 self.as_rec_mut().extend(value.to_be_bytes());
12489 self
12490 }
12491 #[doc = "type name of the chain"]
12492 pub fn push_type(mut self, value: &CStr) -> Self {
12493 push_header(
12494 self.as_rec_mut(),
12495 7u16,
12496 value.to_bytes_with_nul().len() as u16,
12497 );
12498 self.as_rec_mut().extend(value.to_bytes_with_nul());
12499 self
12500 }
12501 #[doc = "type name of the chain"]
12502 pub fn push_type_bytes(mut self, value: &[u8]) -> Self {
12503 push_header(self.as_rec_mut(), 7u16, (value.len() + 1) as u16);
12504 self.as_rec_mut().extend(value);
12505 self.as_rec_mut().push(0);
12506 self
12507 }
12508 #[doc = "counter specification of the chain"]
12509 pub fn nested_counters(mut self) -> PushNftCounterAttrs<Self> {
12510 let header_offset = push_nested_header(self.as_rec_mut(), 8u16);
12511 PushNftCounterAttrs {
12512 prev: Some(self),
12513 header_offset: Some(header_offset),
12514 }
12515 }
12516 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
12517 pub fn push_flags(mut self, value: u32) -> Self {
12518 push_header(self.as_rec_mut(), 9u16, 4 as u16);
12519 self.as_rec_mut().extend(value.to_be_bytes());
12520 self
12521 }
12522 #[doc = "uniquely identifies a chain in a transaction"]
12523 pub fn push_id(mut self, value: u32) -> Self {
12524 push_header(self.as_rec_mut(), 10u16, 4 as u16);
12525 self.as_rec_mut().extend(value.to_be_bytes());
12526 self
12527 }
12528 #[doc = "user data"]
12529 pub fn push_userdata(mut self, value: &[u8]) -> Self {
12530 push_header(self.as_rec_mut(), 11u16, value.len() as u16);
12531 self.as_rec_mut().extend(value);
12532 self
12533 }
12534}
12535impl<Prev: Rec> Drop for PushChainAttrs<Prev> {
12536 fn drop(&mut self) {
12537 if let Some(prev) = &mut self.prev {
12538 if let Some(header_offset) = &self.header_offset {
12539 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12540 }
12541 }
12542 }
12543}
12544pub struct PushCounterAttrs<Prev: Rec> {
12545 pub(crate) prev: Option<Prev>,
12546 pub(crate) header_offset: Option<usize>,
12547}
12548impl<Prev: Rec> Rec for PushCounterAttrs<Prev> {
12549 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12550 self.prev.as_mut().unwrap().as_rec_mut()
12551 }
12552}
12553impl<Prev: Rec> PushCounterAttrs<Prev> {
12554 pub fn new(prev: Prev) -> Self {
12555 Self {
12556 prev: Some(prev),
12557 header_offset: None,
12558 }
12559 }
12560 pub fn end_nested(mut self) -> Prev {
12561 let mut prev = self.prev.take().unwrap();
12562 if let Some(header_offset) = &self.header_offset {
12563 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12564 }
12565 prev
12566 }
12567 pub fn push_bytes(mut self, value: u64) -> Self {
12568 push_header(self.as_rec_mut(), 1u16, 8 as u16);
12569 self.as_rec_mut().extend(value.to_be_bytes());
12570 self
12571 }
12572 pub fn push_packets(mut self, value: u64) -> Self {
12573 push_header(self.as_rec_mut(), 2u16, 8 as u16);
12574 self.as_rec_mut().extend(value.to_be_bytes());
12575 self
12576 }
12577 pub fn push_pad(mut self, value: &[u8]) -> Self {
12578 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
12579 self.as_rec_mut().extend(value);
12580 self
12581 }
12582}
12583impl<Prev: Rec> Drop for PushCounterAttrs<Prev> {
12584 fn drop(&mut self) {
12585 if let Some(prev) = &mut self.prev {
12586 if let Some(header_offset) = &self.header_offset {
12587 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12588 }
12589 }
12590 }
12591}
12592pub struct PushNftHookAttrs<Prev: Rec> {
12593 pub(crate) prev: Option<Prev>,
12594 pub(crate) header_offset: Option<usize>,
12595}
12596impl<Prev: Rec> Rec for PushNftHookAttrs<Prev> {
12597 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12598 self.prev.as_mut().unwrap().as_rec_mut()
12599 }
12600}
12601impl<Prev: Rec> PushNftHookAttrs<Prev> {
12602 pub fn new(prev: Prev) -> Self {
12603 Self {
12604 prev: Some(prev),
12605 header_offset: None,
12606 }
12607 }
12608 pub fn end_nested(mut self) -> Prev {
12609 let mut prev = self.prev.take().unwrap();
12610 if let Some(header_offset) = &self.header_offset {
12611 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12612 }
12613 prev
12614 }
12615 pub fn push_num(mut self, value: u32) -> Self {
12616 push_header(self.as_rec_mut(), 1u16, 4 as u16);
12617 self.as_rec_mut().extend(value.to_be_bytes());
12618 self
12619 }
12620 pub fn push_priority(mut self, value: i32) -> Self {
12621 push_header(self.as_rec_mut(), 2u16, 4 as u16);
12622 self.as_rec_mut().extend(value.to_be_bytes());
12623 self
12624 }
12625 #[doc = "net device name"]
12626 pub fn push_dev(mut self, value: &CStr) -> Self {
12627 push_header(
12628 self.as_rec_mut(),
12629 3u16,
12630 value.to_bytes_with_nul().len() as u16,
12631 );
12632 self.as_rec_mut().extend(value.to_bytes_with_nul());
12633 self
12634 }
12635 #[doc = "net device name"]
12636 pub fn push_dev_bytes(mut self, value: &[u8]) -> Self {
12637 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
12638 self.as_rec_mut().extend(value);
12639 self.as_rec_mut().push(0);
12640 self
12641 }
12642 #[doc = "list of net devices"]
12643 pub fn nested_devs(mut self) -> PushHookDevAttrs<Self> {
12644 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
12645 PushHookDevAttrs {
12646 prev: Some(self),
12647 header_offset: Some(header_offset),
12648 }
12649 }
12650}
12651impl<Prev: Rec> Drop for PushNftHookAttrs<Prev> {
12652 fn drop(&mut self) {
12653 if let Some(prev) = &mut self.prev {
12654 if let Some(header_offset) = &self.header_offset {
12655 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12656 }
12657 }
12658 }
12659}
12660pub struct PushHookDevAttrs<Prev: Rec> {
12661 pub(crate) prev: Option<Prev>,
12662 pub(crate) header_offset: Option<usize>,
12663}
12664impl<Prev: Rec> Rec for PushHookDevAttrs<Prev> {
12665 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12666 self.prev.as_mut().unwrap().as_rec_mut()
12667 }
12668}
12669impl<Prev: Rec> PushHookDevAttrs<Prev> {
12670 pub fn new(prev: Prev) -> Self {
12671 Self {
12672 prev: Some(prev),
12673 header_offset: None,
12674 }
12675 }
12676 pub fn end_nested(mut self) -> Prev {
12677 let mut prev = self.prev.take().unwrap();
12678 if let Some(header_offset) = &self.header_offset {
12679 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12680 }
12681 prev
12682 }
12683 #[doc = "Attribute may repeat multiple times (treat it as array)"]
12684 pub fn push_name(mut self, value: &CStr) -> Self {
12685 push_header(
12686 self.as_rec_mut(),
12687 1u16,
12688 value.to_bytes_with_nul().len() as u16,
12689 );
12690 self.as_rec_mut().extend(value.to_bytes_with_nul());
12691 self
12692 }
12693 #[doc = "Attribute may repeat multiple times (treat it as array)"]
12694 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
12695 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
12696 self.as_rec_mut().extend(value);
12697 self.as_rec_mut().push(0);
12698 self
12699 }
12700}
12701impl<Prev: Rec> Drop for PushHookDevAttrs<Prev> {
12702 fn drop(&mut self) {
12703 if let Some(prev) = &mut self.prev {
12704 if let Some(header_offset) = &self.header_offset {
12705 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12706 }
12707 }
12708 }
12709}
12710pub struct PushNftCounterAttrs<Prev: Rec> {
12711 pub(crate) prev: Option<Prev>,
12712 pub(crate) header_offset: Option<usize>,
12713}
12714impl<Prev: Rec> Rec for PushNftCounterAttrs<Prev> {
12715 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12716 self.prev.as_mut().unwrap().as_rec_mut()
12717 }
12718}
12719impl<Prev: Rec> PushNftCounterAttrs<Prev> {
12720 pub fn new(prev: Prev) -> Self {
12721 Self {
12722 prev: Some(prev),
12723 header_offset: None,
12724 }
12725 }
12726 pub fn end_nested(mut self) -> Prev {
12727 let mut prev = self.prev.take().unwrap();
12728 if let Some(header_offset) = &self.header_offset {
12729 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12730 }
12731 prev
12732 }
12733 pub fn push_bytes(mut self, value: u64) -> Self {
12734 push_header(self.as_rec_mut(), 1u16, 8 as u16);
12735 self.as_rec_mut().extend(value.to_be_bytes());
12736 self
12737 }
12738 pub fn push_packets(mut self, value: u64) -> Self {
12739 push_header(self.as_rec_mut(), 2u16, 8 as u16);
12740 self.as_rec_mut().extend(value.to_be_bytes());
12741 self
12742 }
12743}
12744impl<Prev: Rec> Drop for PushNftCounterAttrs<Prev> {
12745 fn drop(&mut self) {
12746 if let Some(prev) = &mut self.prev {
12747 if let Some(header_offset) = &self.header_offset {
12748 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12749 }
12750 }
12751 }
12752}
12753pub struct PushRuleAttrs<Prev: Rec> {
12754 pub(crate) prev: Option<Prev>,
12755 pub(crate) header_offset: Option<usize>,
12756}
12757impl<Prev: Rec> Rec for PushRuleAttrs<Prev> {
12758 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12759 self.prev.as_mut().unwrap().as_rec_mut()
12760 }
12761}
12762impl<Prev: Rec> PushRuleAttrs<Prev> {
12763 pub fn new(prev: Prev) -> Self {
12764 Self {
12765 prev: Some(prev),
12766 header_offset: None,
12767 }
12768 }
12769 pub fn end_nested(mut self) -> Prev {
12770 let mut prev = self.prev.take().unwrap();
12771 if let Some(header_offset) = &self.header_offset {
12772 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12773 }
12774 prev
12775 }
12776 #[doc = "name of the table containing the rule"]
12777 pub fn push_table(mut self, value: &CStr) -> Self {
12778 push_header(
12779 self.as_rec_mut(),
12780 1u16,
12781 value.to_bytes_with_nul().len() as u16,
12782 );
12783 self.as_rec_mut().extend(value.to_bytes_with_nul());
12784 self
12785 }
12786 #[doc = "name of the table containing the rule"]
12787 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
12788 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
12789 self.as_rec_mut().extend(value);
12790 self.as_rec_mut().push(0);
12791 self
12792 }
12793 #[doc = "name of the chain containing the rule"]
12794 pub fn push_chain(mut self, value: &CStr) -> Self {
12795 push_header(
12796 self.as_rec_mut(),
12797 2u16,
12798 value.to_bytes_with_nul().len() as u16,
12799 );
12800 self.as_rec_mut().extend(value.to_bytes_with_nul());
12801 self
12802 }
12803 #[doc = "name of the chain containing the rule"]
12804 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
12805 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
12806 self.as_rec_mut().extend(value);
12807 self.as_rec_mut().push(0);
12808 self
12809 }
12810 #[doc = "numeric handle of the rule"]
12811 pub fn push_handle(mut self, value: u64) -> Self {
12812 push_header(self.as_rec_mut(), 3u16, 8 as u16);
12813 self.as_rec_mut().extend(value.to_be_bytes());
12814 self
12815 }
12816 #[doc = "list of expressions"]
12817 pub fn nested_expressions(mut self) -> PushExprListAttrs<Self> {
12818 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
12819 PushExprListAttrs {
12820 prev: Some(self),
12821 header_offset: Some(header_offset),
12822 }
12823 }
12824 #[doc = "compatibility specifications of the rule"]
12825 pub fn nested_compat(mut self) -> PushRuleCompatAttrs<Self> {
12826 let header_offset = push_nested_header(self.as_rec_mut(), 5u16);
12827 PushRuleCompatAttrs {
12828 prev: Some(self),
12829 header_offset: Some(header_offset),
12830 }
12831 }
12832 #[doc = "numeric handle of the previous rule"]
12833 pub fn push_position(mut self, value: u64) -> Self {
12834 push_header(self.as_rec_mut(), 6u16, 8 as u16);
12835 self.as_rec_mut().extend(value.to_be_bytes());
12836 self
12837 }
12838 #[doc = "user data"]
12839 pub fn push_userdata(mut self, value: &[u8]) -> Self {
12840 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
12841 self.as_rec_mut().extend(value);
12842 self
12843 }
12844 #[doc = "uniquely identifies a rule in a transaction"]
12845 pub fn push_id(mut self, value: u32) -> Self {
12846 push_header(self.as_rec_mut(), 8u16, 4 as u16);
12847 self.as_rec_mut().extend(value.to_ne_bytes());
12848 self
12849 }
12850 #[doc = "transaction unique identifier of the previous rule"]
12851 pub fn push_position_id(mut self, value: u32) -> Self {
12852 push_header(self.as_rec_mut(), 9u16, 4 as u16);
12853 self.as_rec_mut().extend(value.to_ne_bytes());
12854 self
12855 }
12856 #[doc = "add the rule to chain by ID, alternative to chain name"]
12857 pub fn push_chain_id(mut self, value: u32) -> Self {
12858 push_header(self.as_rec_mut(), 10u16, 4 as u16);
12859 self.as_rec_mut().extend(value.to_ne_bytes());
12860 self
12861 }
12862}
12863impl<Prev: Rec> Drop for PushRuleAttrs<Prev> {
12864 fn drop(&mut self) {
12865 if let Some(prev) = &mut self.prev {
12866 if let Some(header_offset) = &self.header_offset {
12867 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12868 }
12869 }
12870 }
12871}
12872pub struct PushExprListAttrs<Prev: Rec> {
12873 pub(crate) prev: Option<Prev>,
12874 pub(crate) header_offset: Option<usize>,
12875}
12876impl<Prev: Rec> Rec for PushExprListAttrs<Prev> {
12877 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12878 self.prev.as_mut().unwrap().as_rec_mut()
12879 }
12880}
12881impl<Prev: Rec> PushExprListAttrs<Prev> {
12882 pub fn new(prev: Prev) -> Self {
12883 Self {
12884 prev: Some(prev),
12885 header_offset: None,
12886 }
12887 }
12888 pub fn end_nested(mut self) -> Prev {
12889 let mut prev = self.prev.take().unwrap();
12890 if let Some(header_offset) = &self.header_offset {
12891 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12892 }
12893 prev
12894 }
12895 #[doc = "Attribute may repeat multiple times (treat it as array)"]
12896 pub fn nested_elem(mut self) -> PushExprAttrs<Self> {
12897 let header_offset = push_nested_header(self.as_rec_mut(), 1u16);
12898 PushExprAttrs {
12899 prev: Some(self),
12900 header_offset: Some(header_offset),
12901 }
12902 }
12903}
12904impl<Prev: Rec> Drop for PushExprListAttrs<Prev> {
12905 fn drop(&mut self) {
12906 if let Some(prev) = &mut self.prev {
12907 if let Some(header_offset) = &self.header_offset {
12908 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12909 }
12910 }
12911 }
12912}
12913pub struct PushExprAttrs<Prev: Rec> {
12914 pub(crate) prev: Option<Prev>,
12915 pub(crate) header_offset: Option<usize>,
12916}
12917impl<Prev: Rec> Rec for PushExprAttrs<Prev> {
12918 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
12919 self.prev.as_mut().unwrap().as_rec_mut()
12920 }
12921}
12922impl<Prev: Rec> PushExprAttrs<Prev> {
12923 pub fn new(prev: Prev) -> Self {
12924 Self {
12925 prev: Some(prev),
12926 header_offset: None,
12927 }
12928 }
12929 pub fn end_nested(mut self) -> Prev {
12930 let mut prev = self.prev.take().unwrap();
12931 if let Some(header_offset) = &self.header_offset {
12932 finalize_nested_header(prev.as_rec_mut(), *header_offset);
12933 }
12934 prev
12935 }
12936 #[doc = "name of the expression type"]
12937 pub fn push_name(mut self, value: &CStr) -> Self {
12938 push_header(
12939 self.as_rec_mut(),
12940 1u16,
12941 value.to_bytes_with_nul().len() as u16,
12942 );
12943 self.as_rec_mut().extend(value.to_bytes_with_nul());
12944 self
12945 }
12946 #[doc = "name of the expression type"]
12947 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
12948 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
12949 self.as_rec_mut().extend(value);
12950 self.as_rec_mut().push(0);
12951 self
12952 }
12953 #[doc = "type specific data"]
12954 #[doc = "Selector attribute is inserted automatically."]
12955 #[doc = "At most one sub-message attribute is expected per attribute set."]
12956 pub fn nested_data_bitwise(mut self) -> PushExprBitwiseAttrs<PushDummy<Prev>> {
12957 self = self.push_name(c"bitwise");
12958 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
12959 let dummy = PushDummy {
12960 prev: self.prev.take(),
12961 header_offset: self.header_offset.take(),
12962 };
12963 PushExprBitwiseAttrs {
12964 prev: Some(dummy),
12965 header_offset: Some(new_header_offset),
12966 }
12967 }
12968 #[doc = "Selector attribute is inserted automatically."]
12969 #[doc = "At most one sub-message attribute is expected per attribute set."]
12970 pub fn nested_data_cmp(mut self) -> PushExprCmpAttrs<PushDummy<Prev>> {
12971 self = self.push_name(c"cmp");
12972 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
12973 let dummy = PushDummy {
12974 prev: self.prev.take(),
12975 header_offset: self.header_offset.take(),
12976 };
12977 PushExprCmpAttrs {
12978 prev: Some(dummy),
12979 header_offset: Some(new_header_offset),
12980 }
12981 }
12982 #[doc = "Selector attribute is inserted automatically."]
12983 #[doc = "At most one sub-message attribute is expected per attribute set."]
12984 pub fn nested_data_counter(mut self) -> PushExprCounterAttrs<PushDummy<Prev>> {
12985 self = self.push_name(c"counter");
12986 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
12987 let dummy = PushDummy {
12988 prev: self.prev.take(),
12989 header_offset: self.header_offset.take(),
12990 };
12991 PushExprCounterAttrs {
12992 prev: Some(dummy),
12993 header_offset: Some(new_header_offset),
12994 }
12995 }
12996 #[doc = "Selector attribute is inserted automatically."]
12997 #[doc = "At most one sub-message attribute is expected per attribute set."]
12998 pub fn nested_data_ct(mut self) -> PushExprCtAttrs<PushDummy<Prev>> {
12999 self = self.push_name(c"ct");
13000 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13001 let dummy = PushDummy {
13002 prev: self.prev.take(),
13003 header_offset: self.header_offset.take(),
13004 };
13005 PushExprCtAttrs {
13006 prev: Some(dummy),
13007 header_offset: Some(new_header_offset),
13008 }
13009 }
13010 #[doc = "Selector attribute is inserted automatically."]
13011 #[doc = "At most one sub-message attribute is expected per attribute set."]
13012 pub fn nested_data_fib(mut self) -> PushExprFibAttrs<PushDummy<Prev>> {
13013 self = self.push_name(c"fib");
13014 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13015 let dummy = PushDummy {
13016 prev: self.prev.take(),
13017 header_offset: self.header_offset.take(),
13018 };
13019 PushExprFibAttrs {
13020 prev: Some(dummy),
13021 header_offset: Some(new_header_offset),
13022 }
13023 }
13024 #[doc = "Selector attribute is inserted automatically."]
13025 #[doc = "At most one sub-message attribute is expected per attribute set."]
13026 pub fn nested_data_flow_offload(mut self) -> PushExprFlowOffloadAttrs<PushDummy<Prev>> {
13027 self = self.push_name(c"flow_offload");
13028 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13029 let dummy = PushDummy {
13030 prev: self.prev.take(),
13031 header_offset: self.header_offset.take(),
13032 };
13033 PushExprFlowOffloadAttrs {
13034 prev: Some(dummy),
13035 header_offset: Some(new_header_offset),
13036 }
13037 }
13038 #[doc = "Selector attribute is inserted automatically."]
13039 #[doc = "At most one sub-message attribute is expected per attribute set."]
13040 pub fn nested_data_immediate(mut self) -> PushExprImmediateAttrs<PushDummy<Prev>> {
13041 self = self.push_name(c"immediate");
13042 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13043 let dummy = PushDummy {
13044 prev: self.prev.take(),
13045 header_offset: self.header_offset.take(),
13046 };
13047 PushExprImmediateAttrs {
13048 prev: Some(dummy),
13049 header_offset: Some(new_header_offset),
13050 }
13051 }
13052 #[doc = "Selector attribute is inserted automatically."]
13053 #[doc = "At most one sub-message attribute is expected per attribute set."]
13054 pub fn nested_data_lookup(mut self) -> PushExprLookupAttrs<PushDummy<Prev>> {
13055 self = self.push_name(c"lookup");
13056 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13057 let dummy = PushDummy {
13058 prev: self.prev.take(),
13059 header_offset: self.header_offset.take(),
13060 };
13061 PushExprLookupAttrs {
13062 prev: Some(dummy),
13063 header_offset: Some(new_header_offset),
13064 }
13065 }
13066 #[doc = "Selector attribute is inserted automatically."]
13067 #[doc = "At most one sub-message attribute is expected per attribute set."]
13068 pub fn nested_data_meta(mut self) -> PushExprMetaAttrs<PushDummy<Prev>> {
13069 self = self.push_name(c"meta");
13070 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13071 let dummy = PushDummy {
13072 prev: self.prev.take(),
13073 header_offset: self.header_offset.take(),
13074 };
13075 PushExprMetaAttrs {
13076 prev: Some(dummy),
13077 header_offset: Some(new_header_offset),
13078 }
13079 }
13080 #[doc = "Selector attribute is inserted automatically."]
13081 #[doc = "At most one sub-message attribute is expected per attribute set."]
13082 pub fn nested_data_nat(mut self) -> PushExprNatAttrs<PushDummy<Prev>> {
13083 self = self.push_name(c"nat");
13084 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13085 let dummy = PushDummy {
13086 prev: self.prev.take(),
13087 header_offset: self.header_offset.take(),
13088 };
13089 PushExprNatAttrs {
13090 prev: Some(dummy),
13091 header_offset: Some(new_header_offset),
13092 }
13093 }
13094 #[doc = "Selector attribute is inserted automatically."]
13095 #[doc = "At most one sub-message attribute is expected per attribute set."]
13096 pub fn nested_data_objref(mut self) -> PushExprObjrefAttrs<PushDummy<Prev>> {
13097 self = self.push_name(c"objref");
13098 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13099 let dummy = PushDummy {
13100 prev: self.prev.take(),
13101 header_offset: self.header_offset.take(),
13102 };
13103 PushExprObjrefAttrs {
13104 prev: Some(dummy),
13105 header_offset: Some(new_header_offset),
13106 }
13107 }
13108 #[doc = "Selector attribute is inserted automatically."]
13109 #[doc = "At most one sub-message attribute is expected per attribute set."]
13110 pub fn nested_data_payload(mut self) -> PushExprPayloadAttrs<PushDummy<Prev>> {
13111 self = self.push_name(c"payload");
13112 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13113 let dummy = PushDummy {
13114 prev: self.prev.take(),
13115 header_offset: self.header_offset.take(),
13116 };
13117 PushExprPayloadAttrs {
13118 prev: Some(dummy),
13119 header_offset: Some(new_header_offset),
13120 }
13121 }
13122 #[doc = "Selector attribute is inserted automatically."]
13123 #[doc = "At most one sub-message attribute is expected per attribute set."]
13124 pub fn nested_data_quota(mut self) -> PushQuotaAttrs<PushDummy<Prev>> {
13125 self = self.push_name(c"quota");
13126 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13127 let dummy = PushDummy {
13128 prev: self.prev.take(),
13129 header_offset: self.header_offset.take(),
13130 };
13131 PushQuotaAttrs {
13132 prev: Some(dummy),
13133 header_offset: Some(new_header_offset),
13134 }
13135 }
13136 #[doc = "Selector attribute is inserted automatically."]
13137 #[doc = "At most one sub-message attribute is expected per attribute set."]
13138 pub fn nested_data_reject(mut self) -> PushExprRejectAttrs<PushDummy<Prev>> {
13139 self = self.push_name(c"reject");
13140 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13141 let dummy = PushDummy {
13142 prev: self.prev.take(),
13143 header_offset: self.header_offset.take(),
13144 };
13145 PushExprRejectAttrs {
13146 prev: Some(dummy),
13147 header_offset: Some(new_header_offset),
13148 }
13149 }
13150 #[doc = "Selector attribute is inserted automatically."]
13151 #[doc = "At most one sub-message attribute is expected per attribute set."]
13152 pub fn nested_data_target(mut self) -> PushExprTargetAttrs<PushDummy<Prev>> {
13153 self = self.push_name(c"target");
13154 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13155 let dummy = PushDummy {
13156 prev: self.prev.take(),
13157 header_offset: self.header_offset.take(),
13158 };
13159 PushExprTargetAttrs {
13160 prev: Some(dummy),
13161 header_offset: Some(new_header_offset),
13162 }
13163 }
13164 #[doc = "Selector attribute is inserted automatically."]
13165 #[doc = "At most one sub-message attribute is expected per attribute set."]
13166 pub fn nested_data_tproxy(mut self) -> PushExprTproxyAttrs<PushDummy<Prev>> {
13167 self = self.push_name(c"tproxy");
13168 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13169 let dummy = PushDummy {
13170 prev: self.prev.take(),
13171 header_offset: self.header_offset.take(),
13172 };
13173 PushExprTproxyAttrs {
13174 prev: Some(dummy),
13175 header_offset: Some(new_header_offset),
13176 }
13177 }
13178 #[doc = "Selector attribute is inserted automatically."]
13179 #[doc = "At most one sub-message attribute is expected per attribute set."]
13180 pub fn nested_data_match(mut self) -> PushCompatMatchAttrs<PushDummy<Prev>> {
13181 self = self.push_name(c"match");
13182 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13183 let dummy = PushDummy {
13184 prev: self.prev.take(),
13185 header_offset: self.header_offset.take(),
13186 };
13187 PushCompatMatchAttrs {
13188 prev: Some(dummy),
13189 header_offset: Some(new_header_offset),
13190 }
13191 }
13192 #[doc = "Selector attribute is inserted automatically."]
13193 #[doc = "At most one sub-message attribute is expected per attribute set."]
13194 pub fn nested_data_range(mut self) -> PushRangeAttrs<PushDummy<Prev>> {
13195 self = self.push_name(c"range");
13196 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13197 let dummy = PushDummy {
13198 prev: self.prev.take(),
13199 header_offset: self.header_offset.take(),
13200 };
13201 PushRangeAttrs {
13202 prev: Some(dummy),
13203 header_offset: Some(new_header_offset),
13204 }
13205 }
13206 #[doc = "Selector attribute is inserted automatically."]
13207 #[doc = "At most one sub-message attribute is expected per attribute set."]
13208 pub fn nested_data_numgen(mut self) -> PushNumgenAttrs<PushDummy<Prev>> {
13209 self = self.push_name(c"numgen");
13210 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13211 let dummy = PushDummy {
13212 prev: self.prev.take(),
13213 header_offset: self.header_offset.take(),
13214 };
13215 PushNumgenAttrs {
13216 prev: Some(dummy),
13217 header_offset: Some(new_header_offset),
13218 }
13219 }
13220 #[doc = "Selector attribute is inserted automatically."]
13221 #[doc = "At most one sub-message attribute is expected per attribute set."]
13222 pub fn nested_data_log(mut self) -> PushLogAttrs<PushDummy<Prev>> {
13223 self = self.push_name(c"log");
13224 let new_header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13225 let dummy = PushDummy {
13226 prev: self.prev.take(),
13227 header_offset: self.header_offset.take(),
13228 };
13229 PushLogAttrs {
13230 prev: Some(dummy),
13231 header_offset: Some(new_header_offset),
13232 }
13233 }
13234}
13235impl<Prev: Rec> Drop for PushExprAttrs<Prev> {
13236 fn drop(&mut self) {
13237 if let Some(prev) = &mut self.prev {
13238 if let Some(header_offset) = &self.header_offset {
13239 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13240 }
13241 }
13242 }
13243}
13244pub struct PushRuleCompatAttrs<Prev: Rec> {
13245 pub(crate) prev: Option<Prev>,
13246 pub(crate) header_offset: Option<usize>,
13247}
13248impl<Prev: Rec> Rec for PushRuleCompatAttrs<Prev> {
13249 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13250 self.prev.as_mut().unwrap().as_rec_mut()
13251 }
13252}
13253impl<Prev: Rec> PushRuleCompatAttrs<Prev> {
13254 pub fn new(prev: Prev) -> Self {
13255 Self {
13256 prev: Some(prev),
13257 header_offset: None,
13258 }
13259 }
13260 pub fn end_nested(mut self) -> Prev {
13261 let mut prev = self.prev.take().unwrap();
13262 if let Some(header_offset) = &self.header_offset {
13263 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13264 }
13265 prev
13266 }
13267 #[doc = "numeric value of the handled protocol"]
13268 pub fn push_proto(mut self, value: u32) -> Self {
13269 push_header(self.as_rec_mut(), 1u16, 4 as u16);
13270 self.as_rec_mut().extend(value.to_be_bytes());
13271 self
13272 }
13273 #[doc = "bitmask of flags"]
13274 pub fn push_flags(mut self, value: u32) -> Self {
13275 push_header(self.as_rec_mut(), 2u16, 4 as u16);
13276 self.as_rec_mut().extend(value.to_be_bytes());
13277 self
13278 }
13279}
13280impl<Prev: Rec> Drop for PushRuleCompatAttrs<Prev> {
13281 fn drop(&mut self) {
13282 if let Some(prev) = &mut self.prev {
13283 if let Some(header_offset) = &self.header_offset {
13284 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13285 }
13286 }
13287 }
13288}
13289pub struct PushSetAttrs<Prev: Rec> {
13290 pub(crate) prev: Option<Prev>,
13291 pub(crate) header_offset: Option<usize>,
13292}
13293impl<Prev: Rec> Rec for PushSetAttrs<Prev> {
13294 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13295 self.prev.as_mut().unwrap().as_rec_mut()
13296 }
13297}
13298impl<Prev: Rec> PushSetAttrs<Prev> {
13299 pub fn new(prev: Prev) -> Self {
13300 Self {
13301 prev: Some(prev),
13302 header_offset: None,
13303 }
13304 }
13305 pub fn end_nested(mut self) -> Prev {
13306 let mut prev = self.prev.take().unwrap();
13307 if let Some(header_offset) = &self.header_offset {
13308 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13309 }
13310 prev
13311 }
13312 #[doc = "table name"]
13313 pub fn push_table(mut self, value: &CStr) -> Self {
13314 push_header(
13315 self.as_rec_mut(),
13316 1u16,
13317 value.to_bytes_with_nul().len() as u16,
13318 );
13319 self.as_rec_mut().extend(value.to_bytes_with_nul());
13320 self
13321 }
13322 #[doc = "table name"]
13323 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
13324 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
13325 self.as_rec_mut().extend(value);
13326 self.as_rec_mut().push(0);
13327 self
13328 }
13329 #[doc = "set name"]
13330 pub fn push_name(mut self, value: &CStr) -> Self {
13331 push_header(
13332 self.as_rec_mut(),
13333 2u16,
13334 value.to_bytes_with_nul().len() as u16,
13335 );
13336 self.as_rec_mut().extend(value.to_bytes_with_nul());
13337 self
13338 }
13339 #[doc = "set name"]
13340 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
13341 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
13342 self.as_rec_mut().extend(value);
13343 self.as_rec_mut().push(0);
13344 self
13345 }
13346 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
13347 pub fn push_flags(mut self, value: u32) -> Self {
13348 push_header(self.as_rec_mut(), 3u16, 4 as u16);
13349 self.as_rec_mut().extend(value.to_be_bytes());
13350 self
13351 }
13352 #[doc = "key data type, informational purpose only"]
13353 pub fn push_key_type(mut self, value: u32) -> Self {
13354 push_header(self.as_rec_mut(), 4u16, 4 as u16);
13355 self.as_rec_mut().extend(value.to_be_bytes());
13356 self
13357 }
13358 #[doc = "key data length"]
13359 pub fn push_key_len(mut self, value: u32) -> Self {
13360 push_header(self.as_rec_mut(), 5u16, 4 as u16);
13361 self.as_rec_mut().extend(value.to_be_bytes());
13362 self
13363 }
13364 #[doc = "mapping data type"]
13365 pub fn push_data_type(mut self, value: u32) -> Self {
13366 push_header(self.as_rec_mut(), 6u16, 4 as u16);
13367 self.as_rec_mut().extend(value.to_be_bytes());
13368 self
13369 }
13370 #[doc = "mapping data length"]
13371 pub fn push_data_len(mut self, value: u32) -> Self {
13372 push_header(self.as_rec_mut(), 7u16, 4 as u16);
13373 self.as_rec_mut().extend(value.to_be_bytes());
13374 self
13375 }
13376 #[doc = "selection policy"]
13377 pub fn push_policy(mut self, value: u32) -> Self {
13378 push_header(self.as_rec_mut(), 8u16, 4 as u16);
13379 self.as_rec_mut().extend(value.to_be_bytes());
13380 self
13381 }
13382 #[doc = "set description"]
13383 pub fn nested_desc(mut self) -> PushSetDescAttrs<Self> {
13384 let header_offset = push_nested_header(self.as_rec_mut(), 9u16);
13385 PushSetDescAttrs {
13386 prev: Some(self),
13387 header_offset: Some(header_offset),
13388 }
13389 }
13390 #[doc = "uniquely identifies a set in a transaction"]
13391 pub fn push_id(mut self, value: u32) -> Self {
13392 push_header(self.as_rec_mut(), 10u16, 4 as u16);
13393 self.as_rec_mut().extend(value.to_ne_bytes());
13394 self
13395 }
13396 #[doc = "default timeout value"]
13397 pub fn push_timeout(mut self, value: u64) -> Self {
13398 push_header(self.as_rec_mut(), 11u16, 8 as u16);
13399 self.as_rec_mut().extend(value.to_ne_bytes());
13400 self
13401 }
13402 #[doc = "garbage collection interval"]
13403 pub fn push_gc_interval(mut self, value: u32) -> Self {
13404 push_header(self.as_rec_mut(), 12u16, 4 as u16);
13405 self.as_rec_mut().extend(value.to_ne_bytes());
13406 self
13407 }
13408 #[doc = "user data"]
13409 pub fn push_userdata(mut self, value: &[u8]) -> Self {
13410 push_header(self.as_rec_mut(), 13u16, value.len() as u16);
13411 self.as_rec_mut().extend(value);
13412 self
13413 }
13414 pub fn push_pad(mut self, value: &[u8]) -> Self {
13415 push_header(self.as_rec_mut(), 14u16, value.len() as u16);
13416 self.as_rec_mut().extend(value);
13417 self
13418 }
13419 #[doc = "stateful object type"]
13420 pub fn push_obj_type(mut self, value: u32) -> Self {
13421 push_header(self.as_rec_mut(), 15u16, 4 as u16);
13422 self.as_rec_mut().extend(value.to_be_bytes());
13423 self
13424 }
13425 #[doc = "set handle"]
13426 pub fn push_handle(mut self, value: u64) -> Self {
13427 push_header(self.as_rec_mut(), 16u16, 8 as u16);
13428 self.as_rec_mut().extend(value.to_be_bytes());
13429 self
13430 }
13431 #[doc = "set expression\nAttribute may repeat multiple times (treat it as array)"]
13432 pub fn nested_expr(mut self) -> PushExprAttrs<Self> {
13433 let header_offset = push_nested_header(self.as_rec_mut(), 17u16);
13434 PushExprAttrs {
13435 prev: Some(self),
13436 header_offset: Some(header_offset),
13437 }
13438 }
13439 #[doc = "list of expressions"]
13440 pub fn nested_expressions(mut self) -> PushSetListAttrs<Self> {
13441 let header_offset = push_nested_header(self.as_rec_mut(), 18u16);
13442 PushSetListAttrs {
13443 prev: Some(self),
13444 header_offset: Some(header_offset),
13445 }
13446 }
13447 #[doc = "set backend type"]
13448 pub fn push_type(mut self, value: &CStr) -> Self {
13449 push_header(
13450 self.as_rec_mut(),
13451 19u16,
13452 value.to_bytes_with_nul().len() as u16,
13453 );
13454 self.as_rec_mut().extend(value.to_bytes_with_nul());
13455 self
13456 }
13457 #[doc = "set backend type"]
13458 pub fn push_type_bytes(mut self, value: &[u8]) -> Self {
13459 push_header(self.as_rec_mut(), 19u16, (value.len() + 1) as u16);
13460 self.as_rec_mut().extend(value);
13461 self.as_rec_mut().push(0);
13462 self
13463 }
13464 #[doc = "number of set elements"]
13465 pub fn push_count(mut self, value: u32) -> Self {
13466 push_header(self.as_rec_mut(), 20u16, 4 as u16);
13467 self.as_rec_mut().extend(value.to_be_bytes());
13468 self
13469 }
13470}
13471impl<Prev: Rec> Drop for PushSetAttrs<Prev> {
13472 fn drop(&mut self) {
13473 if let Some(prev) = &mut self.prev {
13474 if let Some(header_offset) = &self.header_offset {
13475 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13476 }
13477 }
13478 }
13479}
13480pub struct PushSetDescAttrs<Prev: Rec> {
13481 pub(crate) prev: Option<Prev>,
13482 pub(crate) header_offset: Option<usize>,
13483}
13484impl<Prev: Rec> Rec for PushSetDescAttrs<Prev> {
13485 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13486 self.prev.as_mut().unwrap().as_rec_mut()
13487 }
13488}
13489impl<Prev: Rec> PushSetDescAttrs<Prev> {
13490 pub fn new(prev: Prev) -> Self {
13491 Self {
13492 prev: Some(prev),
13493 header_offset: None,
13494 }
13495 }
13496 pub fn end_nested(mut self) -> Prev {
13497 let mut prev = self.prev.take().unwrap();
13498 if let Some(header_offset) = &self.header_offset {
13499 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13500 }
13501 prev
13502 }
13503 #[doc = "number of elements in set"]
13504 pub fn push_size(mut self, value: u32) -> Self {
13505 push_header(self.as_rec_mut(), 1u16, 4 as u16);
13506 self.as_rec_mut().extend(value.to_be_bytes());
13507 self
13508 }
13509 #[doc = "description of field concatenation\nAttribute may repeat multiple times (treat it as array)"]
13510 pub fn nested_concat(mut self) -> PushSetDescConcatAttrs<Self> {
13511 let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13512 PushSetDescConcatAttrs {
13513 prev: Some(self),
13514 header_offset: Some(header_offset),
13515 }
13516 }
13517}
13518impl<Prev: Rec> Drop for PushSetDescAttrs<Prev> {
13519 fn drop(&mut self) {
13520 if let Some(prev) = &mut self.prev {
13521 if let Some(header_offset) = &self.header_offset {
13522 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13523 }
13524 }
13525 }
13526}
13527pub struct PushSetDescConcatAttrs<Prev: Rec> {
13528 pub(crate) prev: Option<Prev>,
13529 pub(crate) header_offset: Option<usize>,
13530}
13531impl<Prev: Rec> Rec for PushSetDescConcatAttrs<Prev> {
13532 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13533 self.prev.as_mut().unwrap().as_rec_mut()
13534 }
13535}
13536impl<Prev: Rec> PushSetDescConcatAttrs<Prev> {
13537 pub fn new(prev: Prev) -> Self {
13538 Self {
13539 prev: Some(prev),
13540 header_offset: None,
13541 }
13542 }
13543 pub fn end_nested(mut self) -> Prev {
13544 let mut prev = self.prev.take().unwrap();
13545 if let Some(header_offset) = &self.header_offset {
13546 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13547 }
13548 prev
13549 }
13550 pub fn nested_elem(mut self) -> PushSetFieldAttrs<Self> {
13551 let header_offset = push_nested_header(self.as_rec_mut(), 1u16);
13552 PushSetFieldAttrs {
13553 prev: Some(self),
13554 header_offset: Some(header_offset),
13555 }
13556 }
13557}
13558impl<Prev: Rec> Drop for PushSetDescConcatAttrs<Prev> {
13559 fn drop(&mut self) {
13560 if let Some(prev) = &mut self.prev {
13561 if let Some(header_offset) = &self.header_offset {
13562 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13563 }
13564 }
13565 }
13566}
13567pub struct PushSetFieldAttrs<Prev: Rec> {
13568 pub(crate) prev: Option<Prev>,
13569 pub(crate) header_offset: Option<usize>,
13570}
13571impl<Prev: Rec> Rec for PushSetFieldAttrs<Prev> {
13572 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13573 self.prev.as_mut().unwrap().as_rec_mut()
13574 }
13575}
13576impl<Prev: Rec> PushSetFieldAttrs<Prev> {
13577 pub fn new(prev: Prev) -> Self {
13578 Self {
13579 prev: Some(prev),
13580 header_offset: None,
13581 }
13582 }
13583 pub fn end_nested(mut self) -> Prev {
13584 let mut prev = self.prev.take().unwrap();
13585 if let Some(header_offset) = &self.header_offset {
13586 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13587 }
13588 prev
13589 }
13590 pub fn push_len(mut self, value: u32) -> Self {
13591 push_header(self.as_rec_mut(), 1u16, 4 as u16);
13592 self.as_rec_mut().extend(value.to_be_bytes());
13593 self
13594 }
13595}
13596impl<Prev: Rec> Drop for PushSetFieldAttrs<Prev> {
13597 fn drop(&mut self) {
13598 if let Some(prev) = &mut self.prev {
13599 if let Some(header_offset) = &self.header_offset {
13600 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13601 }
13602 }
13603 }
13604}
13605pub struct PushSetListAttrs<Prev: Rec> {
13606 pub(crate) prev: Option<Prev>,
13607 pub(crate) header_offset: Option<usize>,
13608}
13609impl<Prev: Rec> Rec for PushSetListAttrs<Prev> {
13610 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13611 self.prev.as_mut().unwrap().as_rec_mut()
13612 }
13613}
13614impl<Prev: Rec> PushSetListAttrs<Prev> {
13615 pub fn new(prev: Prev) -> Self {
13616 Self {
13617 prev: Some(prev),
13618 header_offset: None,
13619 }
13620 }
13621 pub fn end_nested(mut self) -> Prev {
13622 let mut prev = self.prev.take().unwrap();
13623 if let Some(header_offset) = &self.header_offset {
13624 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13625 }
13626 prev
13627 }
13628 #[doc = "Attribute may repeat multiple times (treat it as array)"]
13629 pub fn nested_elem(mut self) -> PushExprAttrs<Self> {
13630 let header_offset = push_nested_header(self.as_rec_mut(), 1u16);
13631 PushExprAttrs {
13632 prev: Some(self),
13633 header_offset: Some(header_offset),
13634 }
13635 }
13636}
13637impl<Prev: Rec> Drop for PushSetListAttrs<Prev> {
13638 fn drop(&mut self) {
13639 if let Some(prev) = &mut self.prev {
13640 if let Some(header_offset) = &self.header_offset {
13641 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13642 }
13643 }
13644 }
13645}
13646pub struct PushSetelemAttrs<Prev: Rec> {
13647 pub(crate) prev: Option<Prev>,
13648 pub(crate) header_offset: Option<usize>,
13649}
13650impl<Prev: Rec> Rec for PushSetelemAttrs<Prev> {
13651 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13652 self.prev.as_mut().unwrap().as_rec_mut()
13653 }
13654}
13655impl<Prev: Rec> PushSetelemAttrs<Prev> {
13656 pub fn new(prev: Prev) -> Self {
13657 Self {
13658 prev: Some(prev),
13659 header_offset: None,
13660 }
13661 }
13662 pub fn end_nested(mut self) -> Prev {
13663 let mut prev = self.prev.take().unwrap();
13664 if let Some(header_offset) = &self.header_offset {
13665 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13666 }
13667 prev
13668 }
13669 #[doc = "key value"]
13670 pub fn nested_key(mut self) -> PushDataAttrs<Self> {
13671 let header_offset = push_nested_header(self.as_rec_mut(), 1u16);
13672 PushDataAttrs {
13673 prev: Some(self),
13674 header_offset: Some(header_offset),
13675 }
13676 }
13677 #[doc = "data value of mapping"]
13678 pub fn nested_data(mut self) -> PushDataAttrs<Self> {
13679 let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
13680 PushDataAttrs {
13681 prev: Some(self),
13682 header_offset: Some(header_offset),
13683 }
13684 }
13685 #[doc = "bitmask of nft_set_elem_flags"]
13686 pub fn push_flags(mut self, value: &[u8]) -> Self {
13687 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
13688 self.as_rec_mut().extend(value);
13689 self
13690 }
13691 #[doc = "timeout value"]
13692 pub fn push_timeout(mut self, value: u64) -> Self {
13693 push_header(self.as_rec_mut(), 4u16, 8 as u16);
13694 self.as_rec_mut().extend(value.to_ne_bytes());
13695 self
13696 }
13697 #[doc = "expiration time"]
13698 pub fn push_expiration(mut self, value: u64) -> Self {
13699 push_header(self.as_rec_mut(), 5u16, 8 as u16);
13700 self.as_rec_mut().extend(value.to_ne_bytes());
13701 self
13702 }
13703 #[doc = "user data"]
13704 pub fn push_userdata(mut self, value: &[u8]) -> Self {
13705 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
13706 self.as_rec_mut().extend(value);
13707 self
13708 }
13709 #[doc = "expression"]
13710 pub fn nested_expr(mut self) -> PushExprAttrs<Self> {
13711 let header_offset = push_nested_header(self.as_rec_mut(), 7u16);
13712 PushExprAttrs {
13713 prev: Some(self),
13714 header_offset: Some(header_offset),
13715 }
13716 }
13717 #[doc = "stateful object reference"]
13718 pub fn push_objref(mut self, value: &CStr) -> Self {
13719 push_header(
13720 self.as_rec_mut(),
13721 8u16,
13722 value.to_bytes_with_nul().len() as u16,
13723 );
13724 self.as_rec_mut().extend(value.to_bytes_with_nul());
13725 self
13726 }
13727 #[doc = "stateful object reference"]
13728 pub fn push_objref_bytes(mut self, value: &[u8]) -> Self {
13729 push_header(self.as_rec_mut(), 8u16, (value.len() + 1) as u16);
13730 self.as_rec_mut().extend(value);
13731 self.as_rec_mut().push(0);
13732 self
13733 }
13734 #[doc = "closing key value"]
13735 pub fn nested_key_end(mut self) -> PushDataAttrs<Self> {
13736 let header_offset = push_nested_header(self.as_rec_mut(), 9u16);
13737 PushDataAttrs {
13738 prev: Some(self),
13739 header_offset: Some(header_offset),
13740 }
13741 }
13742 #[doc = "list of expressions"]
13743 pub fn nested_expressions(mut self) -> PushExprListAttrs<Self> {
13744 let header_offset = push_nested_header(self.as_rec_mut(), 10u16);
13745 PushExprListAttrs {
13746 prev: Some(self),
13747 header_offset: Some(header_offset),
13748 }
13749 }
13750}
13751impl<Prev: Rec> Drop for PushSetelemAttrs<Prev> {
13752 fn drop(&mut self) {
13753 if let Some(prev) = &mut self.prev {
13754 if let Some(header_offset) = &self.header_offset {
13755 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13756 }
13757 }
13758 }
13759}
13760pub struct PushSetelemListElemAttrs<Prev: Rec> {
13761 pub(crate) prev: Option<Prev>,
13762 pub(crate) header_offset: Option<usize>,
13763}
13764impl<Prev: Rec> Rec for PushSetelemListElemAttrs<Prev> {
13765 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13766 self.prev.as_mut().unwrap().as_rec_mut()
13767 }
13768}
13769impl<Prev: Rec> PushSetelemListElemAttrs<Prev> {
13770 pub fn new(prev: Prev) -> Self {
13771 Self {
13772 prev: Some(prev),
13773 header_offset: None,
13774 }
13775 }
13776 pub fn end_nested(mut self) -> Prev {
13777 let mut prev = self.prev.take().unwrap();
13778 if let Some(header_offset) = &self.header_offset {
13779 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13780 }
13781 prev
13782 }
13783 #[doc = "Attribute may repeat multiple times (treat it as array)"]
13784 pub fn nested_elem(mut self) -> PushSetelemAttrs<Self> {
13785 let header_offset = push_nested_header(self.as_rec_mut(), 1u16);
13786 PushSetelemAttrs {
13787 prev: Some(self),
13788 header_offset: Some(header_offset),
13789 }
13790 }
13791}
13792impl<Prev: Rec> Drop for PushSetelemListElemAttrs<Prev> {
13793 fn drop(&mut self) {
13794 if let Some(prev) = &mut self.prev {
13795 if let Some(header_offset) = &self.header_offset {
13796 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13797 }
13798 }
13799 }
13800}
13801pub struct PushSetelemListAttrs<Prev: Rec> {
13802 pub(crate) prev: Option<Prev>,
13803 pub(crate) header_offset: Option<usize>,
13804}
13805impl<Prev: Rec> Rec for PushSetelemListAttrs<Prev> {
13806 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13807 self.prev.as_mut().unwrap().as_rec_mut()
13808 }
13809}
13810impl<Prev: Rec> PushSetelemListAttrs<Prev> {
13811 pub fn new(prev: Prev) -> Self {
13812 Self {
13813 prev: Some(prev),
13814 header_offset: None,
13815 }
13816 }
13817 pub fn end_nested(mut self) -> Prev {
13818 let mut prev = self.prev.take().unwrap();
13819 if let Some(header_offset) = &self.header_offset {
13820 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13821 }
13822 prev
13823 }
13824 pub fn push_table(mut self, value: &CStr) -> Self {
13825 push_header(
13826 self.as_rec_mut(),
13827 1u16,
13828 value.to_bytes_with_nul().len() as u16,
13829 );
13830 self.as_rec_mut().extend(value.to_bytes_with_nul());
13831 self
13832 }
13833 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
13834 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
13835 self.as_rec_mut().extend(value);
13836 self.as_rec_mut().push(0);
13837 self
13838 }
13839 pub fn push_set(mut self, value: &CStr) -> Self {
13840 push_header(
13841 self.as_rec_mut(),
13842 2u16,
13843 value.to_bytes_with_nul().len() as u16,
13844 );
13845 self.as_rec_mut().extend(value.to_bytes_with_nul());
13846 self
13847 }
13848 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
13849 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
13850 self.as_rec_mut().extend(value);
13851 self.as_rec_mut().push(0);
13852 self
13853 }
13854 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
13855 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
13856 PushSetelemListElemAttrs {
13857 prev: Some(self),
13858 header_offset: Some(header_offset),
13859 }
13860 }
13861 pub fn push_set_id(mut self, value: u32) -> Self {
13862 push_header(self.as_rec_mut(), 4u16, 4 as u16);
13863 self.as_rec_mut().extend(value.to_ne_bytes());
13864 self
13865 }
13866}
13867impl<Prev: Rec> Drop for PushSetelemListAttrs<Prev> {
13868 fn drop(&mut self) {
13869 if let Some(prev) = &mut self.prev {
13870 if let Some(header_offset) = &self.header_offset {
13871 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13872 }
13873 }
13874 }
13875}
13876pub struct PushGenAttrs<Prev: Rec> {
13877 pub(crate) prev: Option<Prev>,
13878 pub(crate) header_offset: Option<usize>,
13879}
13880impl<Prev: Rec> Rec for PushGenAttrs<Prev> {
13881 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13882 self.prev.as_mut().unwrap().as_rec_mut()
13883 }
13884}
13885impl<Prev: Rec> PushGenAttrs<Prev> {
13886 pub fn new(prev: Prev) -> Self {
13887 Self {
13888 prev: Some(prev),
13889 header_offset: None,
13890 }
13891 }
13892 pub fn end_nested(mut self) -> Prev {
13893 let mut prev = self.prev.take().unwrap();
13894 if let Some(header_offset) = &self.header_offset {
13895 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13896 }
13897 prev
13898 }
13899 #[doc = "ruleset generation id"]
13900 pub fn push_id(mut self, value: u32) -> Self {
13901 push_header(self.as_rec_mut(), 1u16, 4 as u16);
13902 self.as_rec_mut().extend(value.to_be_bytes());
13903 self
13904 }
13905 pub fn push_proc_pid(mut self, value: u32) -> Self {
13906 push_header(self.as_rec_mut(), 2u16, 4 as u16);
13907 self.as_rec_mut().extend(value.to_be_bytes());
13908 self
13909 }
13910 pub fn push_proc_name(mut self, value: &CStr) -> Self {
13911 push_header(
13912 self.as_rec_mut(),
13913 3u16,
13914 value.to_bytes_with_nul().len() as u16,
13915 );
13916 self.as_rec_mut().extend(value.to_bytes_with_nul());
13917 self
13918 }
13919 pub fn push_proc_name_bytes(mut self, value: &[u8]) -> Self {
13920 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
13921 self.as_rec_mut().extend(value);
13922 self.as_rec_mut().push(0);
13923 self
13924 }
13925}
13926impl<Prev: Rec> Drop for PushGenAttrs<Prev> {
13927 fn drop(&mut self) {
13928 if let Some(prev) = &mut self.prev {
13929 if let Some(header_offset) = &self.header_offset {
13930 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13931 }
13932 }
13933 }
13934}
13935pub struct PushObjAttrs<Prev: Rec> {
13936 pub(crate) prev: Option<Prev>,
13937 pub(crate) header_offset: Option<usize>,
13938}
13939impl<Prev: Rec> Rec for PushObjAttrs<Prev> {
13940 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
13941 self.prev.as_mut().unwrap().as_rec_mut()
13942 }
13943}
13944impl<Prev: Rec> PushObjAttrs<Prev> {
13945 pub fn new(prev: Prev) -> Self {
13946 Self {
13947 prev: Some(prev),
13948 header_offset: None,
13949 }
13950 }
13951 pub fn end_nested(mut self) -> Prev {
13952 let mut prev = self.prev.take().unwrap();
13953 if let Some(header_offset) = &self.header_offset {
13954 finalize_nested_header(prev.as_rec_mut(), *header_offset);
13955 }
13956 prev
13957 }
13958 #[doc = "name of the table containing the expression"]
13959 pub fn push_table(mut self, value: &CStr) -> Self {
13960 push_header(
13961 self.as_rec_mut(),
13962 1u16,
13963 value.to_bytes_with_nul().len() as u16,
13964 );
13965 self.as_rec_mut().extend(value.to_bytes_with_nul());
13966 self
13967 }
13968 #[doc = "name of the table containing the expression"]
13969 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
13970 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
13971 self.as_rec_mut().extend(value);
13972 self.as_rec_mut().push(0);
13973 self
13974 }
13975 #[doc = "name of this expression type"]
13976 pub fn push_name(mut self, value: &CStr) -> Self {
13977 push_header(
13978 self.as_rec_mut(),
13979 2u16,
13980 value.to_bytes_with_nul().len() as u16,
13981 );
13982 self.as_rec_mut().extend(value.to_bytes_with_nul());
13983 self
13984 }
13985 #[doc = "name of this expression type"]
13986 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
13987 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
13988 self.as_rec_mut().extend(value);
13989 self.as_rec_mut().push(0);
13990 self
13991 }
13992 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
13993 pub fn push_type(mut self, value: u32) -> Self {
13994 push_header(self.as_rec_mut(), 3u16, 4 as u16);
13995 self.as_rec_mut().extend(value.to_be_bytes());
13996 self
13997 }
13998 #[doc = "stateful object data"]
13999 #[doc = "Selector attribute is inserted automatically."]
14000 #[doc = "At most one sub-message attribute is expected per attribute set."]
14001 pub fn nested_data_counter(mut self) -> PushCounterAttrs<PushDummy<Prev>> {
14002 self = self.push_type(ObjectType::Counter as u32);
14003 let new_header_offset = push_nested_header(self.as_rec_mut(), 4u16);
14004 let dummy = PushDummy {
14005 prev: self.prev.take(),
14006 header_offset: self.header_offset.take(),
14007 };
14008 PushCounterAttrs {
14009 prev: Some(dummy),
14010 header_offset: Some(new_header_offset),
14011 }
14012 }
14013 #[doc = "Selector attribute is inserted automatically."]
14014 #[doc = "At most one sub-message attribute is expected per attribute set."]
14015 pub fn nested_data_quota(mut self) -> PushQuotaAttrs<PushDummy<Prev>> {
14016 self = self.push_type(ObjectType::Quota as u32);
14017 let new_header_offset = push_nested_header(self.as_rec_mut(), 4u16);
14018 let dummy = PushDummy {
14019 prev: self.prev.take(),
14020 header_offset: self.header_offset.take(),
14021 };
14022 PushQuotaAttrs {
14023 prev: Some(dummy),
14024 header_offset: Some(new_header_offset),
14025 }
14026 }
14027 #[doc = "number of references to this expression"]
14028 pub fn push_use(mut self, value: u32) -> Self {
14029 push_header(self.as_rec_mut(), 5u16, 4 as u16);
14030 self.as_rec_mut().extend(value.to_be_bytes());
14031 self
14032 }
14033 #[doc = "object handle"]
14034 pub fn push_handle(mut self, value: u64) -> Self {
14035 push_header(self.as_rec_mut(), 6u16, 8 as u16);
14036 self.as_rec_mut().extend(value.to_be_bytes());
14037 self
14038 }
14039 pub fn push_pad(mut self, value: &[u8]) -> Self {
14040 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
14041 self.as_rec_mut().extend(value);
14042 self
14043 }
14044 #[doc = "user data"]
14045 pub fn push_userdata(mut self, value: &[u8]) -> Self {
14046 push_header(self.as_rec_mut(), 8u16, value.len() as u16);
14047 self.as_rec_mut().extend(value);
14048 self
14049 }
14050}
14051impl<Prev: Rec> Drop for PushObjAttrs<Prev> {
14052 fn drop(&mut self) {
14053 if let Some(prev) = &mut self.prev {
14054 if let Some(header_offset) = &self.header_offset {
14055 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14056 }
14057 }
14058 }
14059}
14060pub struct PushQuotaAttrs<Prev: Rec> {
14061 pub(crate) prev: Option<Prev>,
14062 pub(crate) header_offset: Option<usize>,
14063}
14064impl<Prev: Rec> Rec for PushQuotaAttrs<Prev> {
14065 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14066 self.prev.as_mut().unwrap().as_rec_mut()
14067 }
14068}
14069impl<Prev: Rec> PushQuotaAttrs<Prev> {
14070 pub fn new(prev: Prev) -> Self {
14071 Self {
14072 prev: Some(prev),
14073 header_offset: None,
14074 }
14075 }
14076 pub fn end_nested(mut self) -> Prev {
14077 let mut prev = self.prev.take().unwrap();
14078 if let Some(header_offset) = &self.header_offset {
14079 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14080 }
14081 prev
14082 }
14083 pub fn push_bytes(mut self, value: u64) -> Self {
14084 push_header(self.as_rec_mut(), 1u16, 8 as u16);
14085 self.as_rec_mut().extend(value.to_be_bytes());
14086 self
14087 }
14088 #[doc = "Associated type: \"QuotaFlags\" (enum)"]
14089 pub fn push_flags(mut self, value: u32) -> Self {
14090 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14091 self.as_rec_mut().extend(value.to_be_bytes());
14092 self
14093 }
14094 pub fn push_pad(mut self, value: &[u8]) -> Self {
14095 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
14096 self.as_rec_mut().extend(value);
14097 self
14098 }
14099 pub fn push_consumed(mut self, value: u64) -> Self {
14100 push_header(self.as_rec_mut(), 4u16, 8 as u16);
14101 self.as_rec_mut().extend(value.to_be_bytes());
14102 self
14103 }
14104}
14105impl<Prev: Rec> Drop for PushQuotaAttrs<Prev> {
14106 fn drop(&mut self) {
14107 if let Some(prev) = &mut self.prev {
14108 if let Some(header_offset) = &self.header_offset {
14109 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14110 }
14111 }
14112 }
14113}
14114pub struct PushFlowtableAttrs<Prev: Rec> {
14115 pub(crate) prev: Option<Prev>,
14116 pub(crate) header_offset: Option<usize>,
14117}
14118impl<Prev: Rec> Rec for PushFlowtableAttrs<Prev> {
14119 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14120 self.prev.as_mut().unwrap().as_rec_mut()
14121 }
14122}
14123impl<Prev: Rec> PushFlowtableAttrs<Prev> {
14124 pub fn new(prev: Prev) -> Self {
14125 Self {
14126 prev: Some(prev),
14127 header_offset: None,
14128 }
14129 }
14130 pub fn end_nested(mut self) -> Prev {
14131 let mut prev = self.prev.take().unwrap();
14132 if let Some(header_offset) = &self.header_offset {
14133 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14134 }
14135 prev
14136 }
14137 pub fn push_table(mut self, value: &CStr) -> Self {
14138 push_header(
14139 self.as_rec_mut(),
14140 1u16,
14141 value.to_bytes_with_nul().len() as u16,
14142 );
14143 self.as_rec_mut().extend(value.to_bytes_with_nul());
14144 self
14145 }
14146 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
14147 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
14148 self.as_rec_mut().extend(value);
14149 self.as_rec_mut().push(0);
14150 self
14151 }
14152 pub fn push_name(mut self, value: &CStr) -> Self {
14153 push_header(
14154 self.as_rec_mut(),
14155 2u16,
14156 value.to_bytes_with_nul().len() as u16,
14157 );
14158 self.as_rec_mut().extend(value.to_bytes_with_nul());
14159 self
14160 }
14161 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
14162 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
14163 self.as_rec_mut().extend(value);
14164 self.as_rec_mut().push(0);
14165 self
14166 }
14167 pub fn nested_hook(mut self) -> PushFlowtableHookAttrs<Self> {
14168 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
14169 PushFlowtableHookAttrs {
14170 prev: Some(self),
14171 header_offset: Some(header_offset),
14172 }
14173 }
14174 pub fn push_use(mut self, value: u32) -> Self {
14175 push_header(self.as_rec_mut(), 4u16, 4 as u16);
14176 self.as_rec_mut().extend(value.to_be_bytes());
14177 self
14178 }
14179 pub fn push_handle(mut self, value: u64) -> Self {
14180 push_header(self.as_rec_mut(), 5u16, 8 as u16);
14181 self.as_rec_mut().extend(value.to_be_bytes());
14182 self
14183 }
14184 pub fn push_pad(mut self, value: &[u8]) -> Self {
14185 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
14186 self.as_rec_mut().extend(value);
14187 self
14188 }
14189 pub fn push_flags(mut self, value: u32) -> Self {
14190 push_header(self.as_rec_mut(), 7u16, 4 as u16);
14191 self.as_rec_mut().extend(value.to_be_bytes());
14192 self
14193 }
14194}
14195impl<Prev: Rec> Drop for PushFlowtableAttrs<Prev> {
14196 fn drop(&mut self) {
14197 if let Some(prev) = &mut self.prev {
14198 if let Some(header_offset) = &self.header_offset {
14199 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14200 }
14201 }
14202 }
14203}
14204pub struct PushFlowtableHookAttrs<Prev: Rec> {
14205 pub(crate) prev: Option<Prev>,
14206 pub(crate) header_offset: Option<usize>,
14207}
14208impl<Prev: Rec> Rec for PushFlowtableHookAttrs<Prev> {
14209 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14210 self.prev.as_mut().unwrap().as_rec_mut()
14211 }
14212}
14213impl<Prev: Rec> PushFlowtableHookAttrs<Prev> {
14214 pub fn new(prev: Prev) -> Self {
14215 Self {
14216 prev: Some(prev),
14217 header_offset: None,
14218 }
14219 }
14220 pub fn end_nested(mut self) -> Prev {
14221 let mut prev = self.prev.take().unwrap();
14222 if let Some(header_offset) = &self.header_offset {
14223 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14224 }
14225 prev
14226 }
14227 pub fn push_num(mut self, value: u32) -> Self {
14228 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14229 self.as_rec_mut().extend(value.to_be_bytes());
14230 self
14231 }
14232 pub fn push_priority(mut self, value: u32) -> Self {
14233 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14234 self.as_rec_mut().extend(value.to_be_bytes());
14235 self
14236 }
14237 pub fn nested_devs(mut self) -> PushHookDevAttrs<Self> {
14238 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
14239 PushHookDevAttrs {
14240 prev: Some(self),
14241 header_offset: Some(header_offset),
14242 }
14243 }
14244}
14245impl<Prev: Rec> Drop for PushFlowtableHookAttrs<Prev> {
14246 fn drop(&mut self) {
14247 if let Some(prev) = &mut self.prev {
14248 if let Some(header_offset) = &self.header_offset {
14249 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14250 }
14251 }
14252 }
14253}
14254pub struct PushExprBitwiseAttrs<Prev: Rec> {
14255 pub(crate) prev: Option<Prev>,
14256 pub(crate) header_offset: Option<usize>,
14257}
14258impl<Prev: Rec> Rec for PushExprBitwiseAttrs<Prev> {
14259 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14260 self.prev.as_mut().unwrap().as_rec_mut()
14261 }
14262}
14263impl<Prev: Rec> PushExprBitwiseAttrs<Prev> {
14264 pub fn new(prev: Prev) -> Self {
14265 Self {
14266 prev: Some(prev),
14267 header_offset: None,
14268 }
14269 }
14270 pub fn end_nested(mut self) -> Prev {
14271 let mut prev = self.prev.take().unwrap();
14272 if let Some(header_offset) = &self.header_offset {
14273 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14274 }
14275 prev
14276 }
14277 pub fn push_sreg(mut self, value: u32) -> Self {
14278 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14279 self.as_rec_mut().extend(value.to_be_bytes());
14280 self
14281 }
14282 pub fn push_dreg(mut self, value: u32) -> Self {
14283 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14284 self.as_rec_mut().extend(value.to_be_bytes());
14285 self
14286 }
14287 pub fn push_len(mut self, value: u32) -> Self {
14288 push_header(self.as_rec_mut(), 3u16, 4 as u16);
14289 self.as_rec_mut().extend(value.to_be_bytes());
14290 self
14291 }
14292 pub fn nested_mask(mut self) -> PushDataAttrs<Self> {
14293 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
14294 PushDataAttrs {
14295 prev: Some(self),
14296 header_offset: Some(header_offset),
14297 }
14298 }
14299 pub fn nested_xor(mut self) -> PushDataAttrs<Self> {
14300 let header_offset = push_nested_header(self.as_rec_mut(), 5u16);
14301 PushDataAttrs {
14302 prev: Some(self),
14303 header_offset: Some(header_offset),
14304 }
14305 }
14306 #[doc = "Associated type: \"BitwiseOps\" (enum)"]
14307 pub fn push_op(mut self, value: u32) -> Self {
14308 push_header(self.as_rec_mut(), 6u16, 4 as u16);
14309 self.as_rec_mut().extend(value.to_be_bytes());
14310 self
14311 }
14312 pub fn nested_data(mut self) -> PushDataAttrs<Self> {
14313 let header_offset = push_nested_header(self.as_rec_mut(), 7u16);
14314 PushDataAttrs {
14315 prev: Some(self),
14316 header_offset: Some(header_offset),
14317 }
14318 }
14319}
14320impl<Prev: Rec> Drop for PushExprBitwiseAttrs<Prev> {
14321 fn drop(&mut self) {
14322 if let Some(prev) = &mut self.prev {
14323 if let Some(header_offset) = &self.header_offset {
14324 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14325 }
14326 }
14327 }
14328}
14329pub struct PushExprCmpAttrs<Prev: Rec> {
14330 pub(crate) prev: Option<Prev>,
14331 pub(crate) header_offset: Option<usize>,
14332}
14333impl<Prev: Rec> Rec for PushExprCmpAttrs<Prev> {
14334 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14335 self.prev.as_mut().unwrap().as_rec_mut()
14336 }
14337}
14338impl<Prev: Rec> PushExprCmpAttrs<Prev> {
14339 pub fn new(prev: Prev) -> Self {
14340 Self {
14341 prev: Some(prev),
14342 header_offset: None,
14343 }
14344 }
14345 pub fn end_nested(mut self) -> Prev {
14346 let mut prev = self.prev.take().unwrap();
14347 if let Some(header_offset) = &self.header_offset {
14348 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14349 }
14350 prev
14351 }
14352 pub fn push_sreg(mut self, value: u32) -> Self {
14353 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14354 self.as_rec_mut().extend(value.to_be_bytes());
14355 self
14356 }
14357 #[doc = "Associated type: \"CmpOps\" (enum)"]
14358 pub fn push_op(mut self, value: u32) -> Self {
14359 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14360 self.as_rec_mut().extend(value.to_be_bytes());
14361 self
14362 }
14363 pub fn nested_data(mut self) -> PushDataAttrs<Self> {
14364 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
14365 PushDataAttrs {
14366 prev: Some(self),
14367 header_offset: Some(header_offset),
14368 }
14369 }
14370}
14371impl<Prev: Rec> Drop for PushExprCmpAttrs<Prev> {
14372 fn drop(&mut self) {
14373 if let Some(prev) = &mut self.prev {
14374 if let Some(header_offset) = &self.header_offset {
14375 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14376 }
14377 }
14378 }
14379}
14380pub struct PushDataAttrs<Prev: Rec> {
14381 pub(crate) prev: Option<Prev>,
14382 pub(crate) header_offset: Option<usize>,
14383}
14384impl<Prev: Rec> Rec for PushDataAttrs<Prev> {
14385 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14386 self.prev.as_mut().unwrap().as_rec_mut()
14387 }
14388}
14389impl<Prev: Rec> PushDataAttrs<Prev> {
14390 pub fn new(prev: Prev) -> Self {
14391 Self {
14392 prev: Some(prev),
14393 header_offset: None,
14394 }
14395 }
14396 pub fn end_nested(mut self) -> Prev {
14397 let mut prev = self.prev.take().unwrap();
14398 if let Some(header_offset) = &self.header_offset {
14399 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14400 }
14401 prev
14402 }
14403 pub fn push_value(mut self, value: &[u8]) -> Self {
14404 push_header(self.as_rec_mut(), 1u16, value.len() as u16);
14405 self.as_rec_mut().extend(value);
14406 self
14407 }
14408 pub fn nested_verdict(mut self) -> PushVerdictAttrs<Self> {
14409 let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
14410 PushVerdictAttrs {
14411 prev: Some(self),
14412 header_offset: Some(header_offset),
14413 }
14414 }
14415}
14416impl<Prev: Rec> Drop for PushDataAttrs<Prev> {
14417 fn drop(&mut self) {
14418 if let Some(prev) = &mut self.prev {
14419 if let Some(header_offset) = &self.header_offset {
14420 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14421 }
14422 }
14423 }
14424}
14425pub struct PushVerdictAttrs<Prev: Rec> {
14426 pub(crate) prev: Option<Prev>,
14427 pub(crate) header_offset: Option<usize>,
14428}
14429impl<Prev: Rec> Rec for PushVerdictAttrs<Prev> {
14430 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14431 self.prev.as_mut().unwrap().as_rec_mut()
14432 }
14433}
14434impl<Prev: Rec> PushVerdictAttrs<Prev> {
14435 pub fn new(prev: Prev) -> Self {
14436 Self {
14437 prev: Some(prev),
14438 header_offset: None,
14439 }
14440 }
14441 pub fn end_nested(mut self) -> Prev {
14442 let mut prev = self.prev.take().unwrap();
14443 if let Some(header_offset) = &self.header_offset {
14444 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14445 }
14446 prev
14447 }
14448 #[doc = "nf_tables verdict\nAssociated type: \"VerdictCode\" (enum)"]
14449 pub fn push_code(mut self, value: u32) -> Self {
14450 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14451 self.as_rec_mut().extend(value.to_be_bytes());
14452 self
14453 }
14454 #[doc = "jump target chain name"]
14455 pub fn push_chain(mut self, value: &CStr) -> Self {
14456 push_header(
14457 self.as_rec_mut(),
14458 2u16,
14459 value.to_bytes_with_nul().len() as u16,
14460 );
14461 self.as_rec_mut().extend(value.to_bytes_with_nul());
14462 self
14463 }
14464 #[doc = "jump target chain name"]
14465 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
14466 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
14467 self.as_rec_mut().extend(value);
14468 self.as_rec_mut().push(0);
14469 self
14470 }
14471 #[doc = "jump target chain ID"]
14472 pub fn push_chain_id(mut self, value: u32) -> Self {
14473 push_header(self.as_rec_mut(), 3u16, 4 as u16);
14474 self.as_rec_mut().extend(value.to_be_bytes());
14475 self
14476 }
14477}
14478impl<Prev: Rec> Drop for PushVerdictAttrs<Prev> {
14479 fn drop(&mut self) {
14480 if let Some(prev) = &mut self.prev {
14481 if let Some(header_offset) = &self.header_offset {
14482 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14483 }
14484 }
14485 }
14486}
14487pub struct PushExprCounterAttrs<Prev: Rec> {
14488 pub(crate) prev: Option<Prev>,
14489 pub(crate) header_offset: Option<usize>,
14490}
14491impl<Prev: Rec> Rec for PushExprCounterAttrs<Prev> {
14492 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14493 self.prev.as_mut().unwrap().as_rec_mut()
14494 }
14495}
14496impl<Prev: Rec> PushExprCounterAttrs<Prev> {
14497 pub fn new(prev: Prev) -> Self {
14498 Self {
14499 prev: Some(prev),
14500 header_offset: None,
14501 }
14502 }
14503 pub fn end_nested(mut self) -> Prev {
14504 let mut prev = self.prev.take().unwrap();
14505 if let Some(header_offset) = &self.header_offset {
14506 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14507 }
14508 prev
14509 }
14510 #[doc = "Number of bytes"]
14511 pub fn push_bytes(mut self, value: u64) -> Self {
14512 push_header(self.as_rec_mut(), 1u16, 8 as u16);
14513 self.as_rec_mut().extend(value.to_be_bytes());
14514 self
14515 }
14516 #[doc = "Number of packets"]
14517 pub fn push_packets(mut self, value: u64) -> Self {
14518 push_header(self.as_rec_mut(), 2u16, 8 as u16);
14519 self.as_rec_mut().extend(value.to_be_bytes());
14520 self
14521 }
14522 pub fn push_pad(mut self, value: &[u8]) -> Self {
14523 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
14524 self.as_rec_mut().extend(value);
14525 self
14526 }
14527}
14528impl<Prev: Rec> Drop for PushExprCounterAttrs<Prev> {
14529 fn drop(&mut self) {
14530 if let Some(prev) = &mut self.prev {
14531 if let Some(header_offset) = &self.header_offset {
14532 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14533 }
14534 }
14535 }
14536}
14537pub struct PushExprFibAttrs<Prev: Rec> {
14538 pub(crate) prev: Option<Prev>,
14539 pub(crate) header_offset: Option<usize>,
14540}
14541impl<Prev: Rec> Rec for PushExprFibAttrs<Prev> {
14542 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14543 self.prev.as_mut().unwrap().as_rec_mut()
14544 }
14545}
14546impl<Prev: Rec> PushExprFibAttrs<Prev> {
14547 pub fn new(prev: Prev) -> Self {
14548 Self {
14549 prev: Some(prev),
14550 header_offset: None,
14551 }
14552 }
14553 pub fn end_nested(mut self) -> Prev {
14554 let mut prev = self.prev.take().unwrap();
14555 if let Some(header_offset) = &self.header_offset {
14556 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14557 }
14558 prev
14559 }
14560 pub fn push_dreg(mut self, value: u32) -> Self {
14561 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14562 self.as_rec_mut().extend(value.to_be_bytes());
14563 self
14564 }
14565 #[doc = "Associated type: \"FibResult\" (enum)"]
14566 pub fn push_result(mut self, value: u32) -> Self {
14567 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14568 self.as_rec_mut().extend(value.to_be_bytes());
14569 self
14570 }
14571 #[doc = "Associated type: \"FibFlags\" (enum)"]
14572 pub fn push_flags(mut self, value: u32) -> Self {
14573 push_header(self.as_rec_mut(), 3u16, 4 as u16);
14574 self.as_rec_mut().extend(value.to_be_bytes());
14575 self
14576 }
14577}
14578impl<Prev: Rec> Drop for PushExprFibAttrs<Prev> {
14579 fn drop(&mut self) {
14580 if let Some(prev) = &mut self.prev {
14581 if let Some(header_offset) = &self.header_offset {
14582 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14583 }
14584 }
14585 }
14586}
14587pub struct PushExprCtAttrs<Prev: Rec> {
14588 pub(crate) prev: Option<Prev>,
14589 pub(crate) header_offset: Option<usize>,
14590}
14591impl<Prev: Rec> Rec for PushExprCtAttrs<Prev> {
14592 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14593 self.prev.as_mut().unwrap().as_rec_mut()
14594 }
14595}
14596impl<Prev: Rec> PushExprCtAttrs<Prev> {
14597 pub fn new(prev: Prev) -> Self {
14598 Self {
14599 prev: Some(prev),
14600 header_offset: None,
14601 }
14602 }
14603 pub fn end_nested(mut self) -> Prev {
14604 let mut prev = self.prev.take().unwrap();
14605 if let Some(header_offset) = &self.header_offset {
14606 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14607 }
14608 prev
14609 }
14610 pub fn push_dreg(mut self, value: u32) -> Self {
14611 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14612 self.as_rec_mut().extend(value.to_be_bytes());
14613 self
14614 }
14615 #[doc = "Associated type: \"CtKeys\" (enum)"]
14616 pub fn push_key(mut self, value: u32) -> Self {
14617 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14618 self.as_rec_mut().extend(value.to_be_bytes());
14619 self
14620 }
14621 #[doc = "Associated type: \"CtDirection\" (enum)"]
14622 pub fn push_direction(mut self, value: u8) -> Self {
14623 push_header(self.as_rec_mut(), 3u16, 1 as u16);
14624 self.as_rec_mut().extend(value.to_ne_bytes());
14625 self
14626 }
14627 pub fn push_sreg(mut self, value: u32) -> Self {
14628 push_header(self.as_rec_mut(), 4u16, 4 as u16);
14629 self.as_rec_mut().extend(value.to_be_bytes());
14630 self
14631 }
14632}
14633impl<Prev: Rec> Drop for PushExprCtAttrs<Prev> {
14634 fn drop(&mut self) {
14635 if let Some(prev) = &mut self.prev {
14636 if let Some(header_offset) = &self.header_offset {
14637 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14638 }
14639 }
14640 }
14641}
14642pub struct PushExprFlowOffloadAttrs<Prev: Rec> {
14643 pub(crate) prev: Option<Prev>,
14644 pub(crate) header_offset: Option<usize>,
14645}
14646impl<Prev: Rec> Rec for PushExprFlowOffloadAttrs<Prev> {
14647 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14648 self.prev.as_mut().unwrap().as_rec_mut()
14649 }
14650}
14651impl<Prev: Rec> PushExprFlowOffloadAttrs<Prev> {
14652 pub fn new(prev: Prev) -> Self {
14653 Self {
14654 prev: Some(prev),
14655 header_offset: None,
14656 }
14657 }
14658 pub fn end_nested(mut self) -> Prev {
14659 let mut prev = self.prev.take().unwrap();
14660 if let Some(header_offset) = &self.header_offset {
14661 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14662 }
14663 prev
14664 }
14665 #[doc = "Flow offload table name"]
14666 pub fn push_name(mut self, value: &CStr) -> Self {
14667 push_header(
14668 self.as_rec_mut(),
14669 1u16,
14670 value.to_bytes_with_nul().len() as u16,
14671 );
14672 self.as_rec_mut().extend(value.to_bytes_with_nul());
14673 self
14674 }
14675 #[doc = "Flow offload table name"]
14676 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
14677 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
14678 self.as_rec_mut().extend(value);
14679 self.as_rec_mut().push(0);
14680 self
14681 }
14682}
14683impl<Prev: Rec> Drop for PushExprFlowOffloadAttrs<Prev> {
14684 fn drop(&mut self) {
14685 if let Some(prev) = &mut self.prev {
14686 if let Some(header_offset) = &self.header_offset {
14687 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14688 }
14689 }
14690 }
14691}
14692pub struct PushExprImmediateAttrs<Prev: Rec> {
14693 pub(crate) prev: Option<Prev>,
14694 pub(crate) header_offset: Option<usize>,
14695}
14696impl<Prev: Rec> Rec for PushExprImmediateAttrs<Prev> {
14697 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14698 self.prev.as_mut().unwrap().as_rec_mut()
14699 }
14700}
14701impl<Prev: Rec> PushExprImmediateAttrs<Prev> {
14702 pub fn new(prev: Prev) -> Self {
14703 Self {
14704 prev: Some(prev),
14705 header_offset: None,
14706 }
14707 }
14708 pub fn end_nested(mut self) -> Prev {
14709 let mut prev = self.prev.take().unwrap();
14710 if let Some(header_offset) = &self.header_offset {
14711 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14712 }
14713 prev
14714 }
14715 pub fn push_dreg(mut self, value: u32) -> Self {
14716 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14717 self.as_rec_mut().extend(value.to_be_bytes());
14718 self
14719 }
14720 pub fn nested_data(mut self) -> PushDataAttrs<Self> {
14721 let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
14722 PushDataAttrs {
14723 prev: Some(self),
14724 header_offset: Some(header_offset),
14725 }
14726 }
14727}
14728impl<Prev: Rec> Drop for PushExprImmediateAttrs<Prev> {
14729 fn drop(&mut self) {
14730 if let Some(prev) = &mut self.prev {
14731 if let Some(header_offset) = &self.header_offset {
14732 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14733 }
14734 }
14735 }
14736}
14737pub struct PushExprLookupAttrs<Prev: Rec> {
14738 pub(crate) prev: Option<Prev>,
14739 pub(crate) header_offset: Option<usize>,
14740}
14741impl<Prev: Rec> Rec for PushExprLookupAttrs<Prev> {
14742 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14743 self.prev.as_mut().unwrap().as_rec_mut()
14744 }
14745}
14746impl<Prev: Rec> PushExprLookupAttrs<Prev> {
14747 pub fn new(prev: Prev) -> Self {
14748 Self {
14749 prev: Some(prev),
14750 header_offset: None,
14751 }
14752 }
14753 pub fn end_nested(mut self) -> Prev {
14754 let mut prev = self.prev.take().unwrap();
14755 if let Some(header_offset) = &self.header_offset {
14756 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14757 }
14758 prev
14759 }
14760 #[doc = "Name of set to use"]
14761 pub fn push_set(mut self, value: &CStr) -> Self {
14762 push_header(
14763 self.as_rec_mut(),
14764 1u16,
14765 value.to_bytes_with_nul().len() as u16,
14766 );
14767 self.as_rec_mut().extend(value.to_bytes_with_nul());
14768 self
14769 }
14770 #[doc = "Name of set to use"]
14771 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
14772 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
14773 self.as_rec_mut().extend(value);
14774 self.as_rec_mut().push(0);
14775 self
14776 }
14777 #[doc = "ID of set to use"]
14778 pub fn push_set_id(mut self, value: u32) -> Self {
14779 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14780 self.as_rec_mut().extend(value.to_be_bytes());
14781 self
14782 }
14783 pub fn push_sreg(mut self, value: u32) -> Self {
14784 push_header(self.as_rec_mut(), 3u16, 4 as u16);
14785 self.as_rec_mut().extend(value.to_be_bytes());
14786 self
14787 }
14788 pub fn push_dreg(mut self, value: u32) -> Self {
14789 push_header(self.as_rec_mut(), 4u16, 4 as u16);
14790 self.as_rec_mut().extend(value.to_be_bytes());
14791 self
14792 }
14793 #[doc = "Associated type: \"LookupFlags\" (enum)"]
14794 pub fn push_flags(mut self, value: u32) -> Self {
14795 push_header(self.as_rec_mut(), 5u16, 4 as u16);
14796 self.as_rec_mut().extend(value.to_be_bytes());
14797 self
14798 }
14799}
14800impl<Prev: Rec> Drop for PushExprLookupAttrs<Prev> {
14801 fn drop(&mut self) {
14802 if let Some(prev) = &mut self.prev {
14803 if let Some(header_offset) = &self.header_offset {
14804 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14805 }
14806 }
14807 }
14808}
14809pub struct PushExprMetaAttrs<Prev: Rec> {
14810 pub(crate) prev: Option<Prev>,
14811 pub(crate) header_offset: Option<usize>,
14812}
14813impl<Prev: Rec> Rec for PushExprMetaAttrs<Prev> {
14814 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14815 self.prev.as_mut().unwrap().as_rec_mut()
14816 }
14817}
14818impl<Prev: Rec> PushExprMetaAttrs<Prev> {
14819 pub fn new(prev: Prev) -> Self {
14820 Self {
14821 prev: Some(prev),
14822 header_offset: None,
14823 }
14824 }
14825 pub fn end_nested(mut self) -> Prev {
14826 let mut prev = self.prev.take().unwrap();
14827 if let Some(header_offset) = &self.header_offset {
14828 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14829 }
14830 prev
14831 }
14832 pub fn push_dreg(mut self, value: u32) -> Self {
14833 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14834 self.as_rec_mut().extend(value.to_be_bytes());
14835 self
14836 }
14837 #[doc = "Associated type: \"MetaKeys\" (enum)"]
14838 pub fn push_key(mut self, value: u32) -> Self {
14839 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14840 self.as_rec_mut().extend(value.to_be_bytes());
14841 self
14842 }
14843 pub fn push_sreg(mut self, value: u32) -> Self {
14844 push_header(self.as_rec_mut(), 3u16, 4 as u16);
14845 self.as_rec_mut().extend(value.to_be_bytes());
14846 self
14847 }
14848}
14849impl<Prev: Rec> Drop for PushExprMetaAttrs<Prev> {
14850 fn drop(&mut self) {
14851 if let Some(prev) = &mut self.prev {
14852 if let Some(header_offset) = &self.header_offset {
14853 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14854 }
14855 }
14856 }
14857}
14858pub struct PushExprNatAttrs<Prev: Rec> {
14859 pub(crate) prev: Option<Prev>,
14860 pub(crate) header_offset: Option<usize>,
14861}
14862impl<Prev: Rec> Rec for PushExprNatAttrs<Prev> {
14863 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14864 self.prev.as_mut().unwrap().as_rec_mut()
14865 }
14866}
14867impl<Prev: Rec> PushExprNatAttrs<Prev> {
14868 pub fn new(prev: Prev) -> Self {
14869 Self {
14870 prev: Some(prev),
14871 header_offset: None,
14872 }
14873 }
14874 pub fn end_nested(mut self) -> Prev {
14875 let mut prev = self.prev.take().unwrap();
14876 if let Some(header_offset) = &self.header_offset {
14877 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14878 }
14879 prev
14880 }
14881 pub fn push_type(mut self, value: u32) -> Self {
14882 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14883 self.as_rec_mut().extend(value.to_be_bytes());
14884 self
14885 }
14886 pub fn push_family(mut self, value: u32) -> Self {
14887 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14888 self.as_rec_mut().extend(value.to_be_bytes());
14889 self
14890 }
14891 pub fn push_reg_addr_min(mut self, value: u32) -> Self {
14892 push_header(self.as_rec_mut(), 3u16, 4 as u16);
14893 self.as_rec_mut().extend(value.to_be_bytes());
14894 self
14895 }
14896 pub fn push_reg_addr_max(mut self, value: u32) -> Self {
14897 push_header(self.as_rec_mut(), 4u16, 4 as u16);
14898 self.as_rec_mut().extend(value.to_be_bytes());
14899 self
14900 }
14901 pub fn push_reg_proto_min(mut self, value: u32) -> Self {
14902 push_header(self.as_rec_mut(), 5u16, 4 as u16);
14903 self.as_rec_mut().extend(value.to_be_bytes());
14904 self
14905 }
14906 pub fn push_reg_proto_max(mut self, value: u32) -> Self {
14907 push_header(self.as_rec_mut(), 6u16, 4 as u16);
14908 self.as_rec_mut().extend(value.to_be_bytes());
14909 self
14910 }
14911 #[doc = "Associated type: \"NatRangeFlags\" (1 bit per enumeration)"]
14912 pub fn push_flags(mut self, value: u32) -> Self {
14913 push_header(self.as_rec_mut(), 7u16, 4 as u16);
14914 self.as_rec_mut().extend(value.to_be_bytes());
14915 self
14916 }
14917}
14918impl<Prev: Rec> Drop for PushExprNatAttrs<Prev> {
14919 fn drop(&mut self) {
14920 if let Some(prev) = &mut self.prev {
14921 if let Some(header_offset) = &self.header_offset {
14922 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14923 }
14924 }
14925 }
14926}
14927pub struct PushExprPayloadAttrs<Prev: Rec> {
14928 pub(crate) prev: Option<Prev>,
14929 pub(crate) header_offset: Option<usize>,
14930}
14931impl<Prev: Rec> Rec for PushExprPayloadAttrs<Prev> {
14932 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
14933 self.prev.as_mut().unwrap().as_rec_mut()
14934 }
14935}
14936impl<Prev: Rec> PushExprPayloadAttrs<Prev> {
14937 pub fn new(prev: Prev) -> Self {
14938 Self {
14939 prev: Some(prev),
14940 header_offset: None,
14941 }
14942 }
14943 pub fn end_nested(mut self) -> Prev {
14944 let mut prev = self.prev.take().unwrap();
14945 if let Some(header_offset) = &self.header_offset {
14946 finalize_nested_header(prev.as_rec_mut(), *header_offset);
14947 }
14948 prev
14949 }
14950 #[doc = "destination register to load data into\nAssociated type: \"Registers\" (enum)"]
14951 pub fn push_dreg(mut self, value: u32) -> Self {
14952 push_header(self.as_rec_mut(), 1u16, 4 as u16);
14953 self.as_rec_mut().extend(value.to_be_bytes());
14954 self
14955 }
14956 #[doc = "payload base\nAssociated type: \"PayloadBase\" (enum)"]
14957 pub fn push_base(mut self, value: u32) -> Self {
14958 push_header(self.as_rec_mut(), 2u16, 4 as u16);
14959 self.as_rec_mut().extend(value.to_be_bytes());
14960 self
14961 }
14962 #[doc = "payload offset relative to base"]
14963 pub fn push_offset(mut self, value: u32) -> Self {
14964 push_header(self.as_rec_mut(), 3u16, 4 as u16);
14965 self.as_rec_mut().extend(value.to_be_bytes());
14966 self
14967 }
14968 #[doc = "payload length"]
14969 pub fn push_len(mut self, value: u32) -> Self {
14970 push_header(self.as_rec_mut(), 4u16, 4 as u16);
14971 self.as_rec_mut().extend(value.to_be_bytes());
14972 self
14973 }
14974 #[doc = "source register to load data from\nAssociated type: \"Registers\" (enum)"]
14975 pub fn push_sreg(mut self, value: u32) -> Self {
14976 push_header(self.as_rec_mut(), 5u16, 4 as u16);
14977 self.as_rec_mut().extend(value.to_be_bytes());
14978 self
14979 }
14980 #[doc = "checksum type"]
14981 pub fn push_csum_type(mut self, value: u32) -> Self {
14982 push_header(self.as_rec_mut(), 6u16, 4 as u16);
14983 self.as_rec_mut().extend(value.to_be_bytes());
14984 self
14985 }
14986 #[doc = "checksum offset relative to base"]
14987 pub fn push_csum_offset(mut self, value: u32) -> Self {
14988 push_header(self.as_rec_mut(), 7u16, 4 as u16);
14989 self.as_rec_mut().extend(value.to_be_bytes());
14990 self
14991 }
14992 #[doc = "checksum flags"]
14993 pub fn push_csum_flags(mut self, value: u32) -> Self {
14994 push_header(self.as_rec_mut(), 8u16, 4 as u16);
14995 self.as_rec_mut().extend(value.to_be_bytes());
14996 self
14997 }
14998}
14999impl<Prev: Rec> Drop for PushExprPayloadAttrs<Prev> {
15000 fn drop(&mut self) {
15001 if let Some(prev) = &mut self.prev {
15002 if let Some(header_offset) = &self.header_offset {
15003 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15004 }
15005 }
15006 }
15007}
15008pub struct PushExprRejectAttrs<Prev: Rec> {
15009 pub(crate) prev: Option<Prev>,
15010 pub(crate) header_offset: Option<usize>,
15011}
15012impl<Prev: Rec> Rec for PushExprRejectAttrs<Prev> {
15013 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15014 self.prev.as_mut().unwrap().as_rec_mut()
15015 }
15016}
15017impl<Prev: Rec> PushExprRejectAttrs<Prev> {
15018 pub fn new(prev: Prev) -> Self {
15019 Self {
15020 prev: Some(prev),
15021 header_offset: None,
15022 }
15023 }
15024 pub fn end_nested(mut self) -> Prev {
15025 let mut prev = self.prev.take().unwrap();
15026 if let Some(header_offset) = &self.header_offset {
15027 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15028 }
15029 prev
15030 }
15031 #[doc = "Associated type: \"RejectTypes\" (enum)"]
15032 pub fn push_type(mut self, value: u32) -> Self {
15033 push_header(self.as_rec_mut(), 1u16, 4 as u16);
15034 self.as_rec_mut().extend(value.to_be_bytes());
15035 self
15036 }
15037 pub fn push_icmp_code(mut self, value: u8) -> Self {
15038 push_header(self.as_rec_mut(), 2u16, 1 as u16);
15039 self.as_rec_mut().extend(value.to_ne_bytes());
15040 self
15041 }
15042}
15043impl<Prev: Rec> Drop for PushExprRejectAttrs<Prev> {
15044 fn drop(&mut self) {
15045 if let Some(prev) = &mut self.prev {
15046 if let Some(header_offset) = &self.header_offset {
15047 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15048 }
15049 }
15050 }
15051}
15052pub struct PushExprTargetAttrs<Prev: Rec> {
15053 pub(crate) prev: Option<Prev>,
15054 pub(crate) header_offset: Option<usize>,
15055}
15056impl<Prev: Rec> Rec for PushExprTargetAttrs<Prev> {
15057 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15058 self.prev.as_mut().unwrap().as_rec_mut()
15059 }
15060}
15061impl<Prev: Rec> PushExprTargetAttrs<Prev> {
15062 pub fn new(prev: Prev) -> Self {
15063 Self {
15064 prev: Some(prev),
15065 header_offset: None,
15066 }
15067 }
15068 pub fn end_nested(mut self) -> Prev {
15069 let mut prev = self.prev.take().unwrap();
15070 if let Some(header_offset) = &self.header_offset {
15071 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15072 }
15073 prev
15074 }
15075 pub fn push_name(mut self, value: &CStr) -> Self {
15076 push_header(
15077 self.as_rec_mut(),
15078 1u16,
15079 value.to_bytes_with_nul().len() as u16,
15080 );
15081 self.as_rec_mut().extend(value.to_bytes_with_nul());
15082 self
15083 }
15084 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
15085 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
15086 self.as_rec_mut().extend(value);
15087 self.as_rec_mut().push(0);
15088 self
15089 }
15090 pub fn push_rev(mut self, value: u32) -> Self {
15091 push_header(self.as_rec_mut(), 2u16, 4 as u16);
15092 self.as_rec_mut().extend(value.to_be_bytes());
15093 self
15094 }
15095 pub fn push_info(mut self, value: &[u8]) -> Self {
15096 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
15097 self.as_rec_mut().extend(value);
15098 self
15099 }
15100}
15101impl<Prev: Rec> Drop for PushExprTargetAttrs<Prev> {
15102 fn drop(&mut self) {
15103 if let Some(prev) = &mut self.prev {
15104 if let Some(header_offset) = &self.header_offset {
15105 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15106 }
15107 }
15108 }
15109}
15110pub struct PushExprTproxyAttrs<Prev: Rec> {
15111 pub(crate) prev: Option<Prev>,
15112 pub(crate) header_offset: Option<usize>,
15113}
15114impl<Prev: Rec> Rec for PushExprTproxyAttrs<Prev> {
15115 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15116 self.prev.as_mut().unwrap().as_rec_mut()
15117 }
15118}
15119impl<Prev: Rec> PushExprTproxyAttrs<Prev> {
15120 pub fn new(prev: Prev) -> Self {
15121 Self {
15122 prev: Some(prev),
15123 header_offset: None,
15124 }
15125 }
15126 pub fn end_nested(mut self) -> Prev {
15127 let mut prev = self.prev.take().unwrap();
15128 if let Some(header_offset) = &self.header_offset {
15129 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15130 }
15131 prev
15132 }
15133 pub fn push_family(mut self, value: u32) -> Self {
15134 push_header(self.as_rec_mut(), 1u16, 4 as u16);
15135 self.as_rec_mut().extend(value.to_be_bytes());
15136 self
15137 }
15138 pub fn push_reg_addr(mut self, value: u32) -> Self {
15139 push_header(self.as_rec_mut(), 2u16, 4 as u16);
15140 self.as_rec_mut().extend(value.to_be_bytes());
15141 self
15142 }
15143 pub fn push_reg_port(mut self, value: u32) -> Self {
15144 push_header(self.as_rec_mut(), 3u16, 4 as u16);
15145 self.as_rec_mut().extend(value.to_be_bytes());
15146 self
15147 }
15148}
15149impl<Prev: Rec> Drop for PushExprTproxyAttrs<Prev> {
15150 fn drop(&mut self) {
15151 if let Some(prev) = &mut self.prev {
15152 if let Some(header_offset) = &self.header_offset {
15153 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15154 }
15155 }
15156 }
15157}
15158pub struct PushExprObjrefAttrs<Prev: Rec> {
15159 pub(crate) prev: Option<Prev>,
15160 pub(crate) header_offset: Option<usize>,
15161}
15162impl<Prev: Rec> Rec for PushExprObjrefAttrs<Prev> {
15163 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15164 self.prev.as_mut().unwrap().as_rec_mut()
15165 }
15166}
15167impl<Prev: Rec> PushExprObjrefAttrs<Prev> {
15168 pub fn new(prev: Prev) -> Self {
15169 Self {
15170 prev: Some(prev),
15171 header_offset: None,
15172 }
15173 }
15174 pub fn end_nested(mut self) -> Prev {
15175 let mut prev = self.prev.take().unwrap();
15176 if let Some(header_offset) = &self.header_offset {
15177 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15178 }
15179 prev
15180 }
15181 pub fn push_imm_type(mut self, value: u32) -> Self {
15182 push_header(self.as_rec_mut(), 1u16, 4 as u16);
15183 self.as_rec_mut().extend(value.to_be_bytes());
15184 self
15185 }
15186 #[doc = "object name"]
15187 pub fn push_imm_name(mut self, value: &CStr) -> Self {
15188 push_header(
15189 self.as_rec_mut(),
15190 2u16,
15191 value.to_bytes_with_nul().len() as u16,
15192 );
15193 self.as_rec_mut().extend(value.to_bytes_with_nul());
15194 self
15195 }
15196 #[doc = "object name"]
15197 pub fn push_imm_name_bytes(mut self, value: &[u8]) -> Self {
15198 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
15199 self.as_rec_mut().extend(value);
15200 self.as_rec_mut().push(0);
15201 self
15202 }
15203 pub fn push_set_sreg(mut self, value: u32) -> Self {
15204 push_header(self.as_rec_mut(), 3u16, 4 as u16);
15205 self.as_rec_mut().extend(value.to_be_bytes());
15206 self
15207 }
15208 #[doc = "name of object map"]
15209 pub fn push_set_name(mut self, value: &CStr) -> Self {
15210 push_header(
15211 self.as_rec_mut(),
15212 4u16,
15213 value.to_bytes_with_nul().len() as u16,
15214 );
15215 self.as_rec_mut().extend(value.to_bytes_with_nul());
15216 self
15217 }
15218 #[doc = "name of object map"]
15219 pub fn push_set_name_bytes(mut self, value: &[u8]) -> Self {
15220 push_header(self.as_rec_mut(), 4u16, (value.len() + 1) as u16);
15221 self.as_rec_mut().extend(value);
15222 self.as_rec_mut().push(0);
15223 self
15224 }
15225 #[doc = "id of object map"]
15226 pub fn push_set_id(mut self, value: u32) -> Self {
15227 push_header(self.as_rec_mut(), 5u16, 4 as u16);
15228 self.as_rec_mut().extend(value.to_be_bytes());
15229 self
15230 }
15231}
15232impl<Prev: Rec> Drop for PushExprObjrefAttrs<Prev> {
15233 fn drop(&mut self) {
15234 if let Some(prev) = &mut self.prev {
15235 if let Some(header_offset) = &self.header_offset {
15236 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15237 }
15238 }
15239 }
15240}
15241pub struct PushCompatTargetAttrs<Prev: Rec> {
15242 pub(crate) prev: Option<Prev>,
15243 pub(crate) header_offset: Option<usize>,
15244}
15245impl<Prev: Rec> Rec for PushCompatTargetAttrs<Prev> {
15246 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15247 self.prev.as_mut().unwrap().as_rec_mut()
15248 }
15249}
15250impl<Prev: Rec> PushCompatTargetAttrs<Prev> {
15251 pub fn new(prev: Prev) -> Self {
15252 Self {
15253 prev: Some(prev),
15254 header_offset: None,
15255 }
15256 }
15257 pub fn end_nested(mut self) -> Prev {
15258 let mut prev = self.prev.take().unwrap();
15259 if let Some(header_offset) = &self.header_offset {
15260 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15261 }
15262 prev
15263 }
15264 pub fn push_name(mut self, value: &CStr) -> Self {
15265 push_header(
15266 self.as_rec_mut(),
15267 1u16,
15268 value.to_bytes_with_nul().len() as u16,
15269 );
15270 self.as_rec_mut().extend(value.to_bytes_with_nul());
15271 self
15272 }
15273 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
15274 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
15275 self.as_rec_mut().extend(value);
15276 self.as_rec_mut().push(0);
15277 self
15278 }
15279 pub fn push_rev(mut self, value: u32) -> Self {
15280 push_header(self.as_rec_mut(), 2u16, 4 as u16);
15281 self.as_rec_mut().extend(value.to_be_bytes());
15282 self
15283 }
15284 pub fn push_info(mut self, value: &[u8]) -> Self {
15285 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
15286 self.as_rec_mut().extend(value);
15287 self
15288 }
15289}
15290impl<Prev: Rec> Drop for PushCompatTargetAttrs<Prev> {
15291 fn drop(&mut self) {
15292 if let Some(prev) = &mut self.prev {
15293 if let Some(header_offset) = &self.header_offset {
15294 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15295 }
15296 }
15297 }
15298}
15299pub struct PushCompatMatchAttrs<Prev: Rec> {
15300 pub(crate) prev: Option<Prev>,
15301 pub(crate) header_offset: Option<usize>,
15302}
15303impl<Prev: Rec> Rec for PushCompatMatchAttrs<Prev> {
15304 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15305 self.prev.as_mut().unwrap().as_rec_mut()
15306 }
15307}
15308impl<Prev: Rec> PushCompatMatchAttrs<Prev> {
15309 pub fn new(prev: Prev) -> Self {
15310 Self {
15311 prev: Some(prev),
15312 header_offset: None,
15313 }
15314 }
15315 pub fn end_nested(mut self) -> Prev {
15316 let mut prev = self.prev.take().unwrap();
15317 if let Some(header_offset) = &self.header_offset {
15318 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15319 }
15320 prev
15321 }
15322 pub fn push_name(mut self, value: &CStr) -> Self {
15323 push_header(
15324 self.as_rec_mut(),
15325 1u16,
15326 value.to_bytes_with_nul().len() as u16,
15327 );
15328 self.as_rec_mut().extend(value.to_bytes_with_nul());
15329 self
15330 }
15331 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
15332 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
15333 self.as_rec_mut().extend(value);
15334 self.as_rec_mut().push(0);
15335 self
15336 }
15337 pub fn push_rev(mut self, value: u32) -> Self {
15338 push_header(self.as_rec_mut(), 2u16, 4 as u16);
15339 self.as_rec_mut().extend(value.to_be_bytes());
15340 self
15341 }
15342 pub fn push_info(mut self, value: &[u8]) -> Self {
15343 push_header(self.as_rec_mut(), 3u16, value.len() as u16);
15344 self.as_rec_mut().extend(value);
15345 self
15346 }
15347}
15348impl<Prev: Rec> Drop for PushCompatMatchAttrs<Prev> {
15349 fn drop(&mut self) {
15350 if let Some(prev) = &mut self.prev {
15351 if let Some(header_offset) = &self.header_offset {
15352 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15353 }
15354 }
15355 }
15356}
15357pub struct PushCompatAttrs<Prev: Rec> {
15358 pub(crate) prev: Option<Prev>,
15359 pub(crate) header_offset: Option<usize>,
15360}
15361impl<Prev: Rec> Rec for PushCompatAttrs<Prev> {
15362 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15363 self.prev.as_mut().unwrap().as_rec_mut()
15364 }
15365}
15366impl<Prev: Rec> PushCompatAttrs<Prev> {
15367 pub fn new(prev: Prev) -> Self {
15368 Self {
15369 prev: Some(prev),
15370 header_offset: None,
15371 }
15372 }
15373 pub fn end_nested(mut self) -> Prev {
15374 let mut prev = self.prev.take().unwrap();
15375 if let Some(header_offset) = &self.header_offset {
15376 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15377 }
15378 prev
15379 }
15380 pub fn push_name(mut self, value: &CStr) -> Self {
15381 push_header(
15382 self.as_rec_mut(),
15383 1u16,
15384 value.to_bytes_with_nul().len() as u16,
15385 );
15386 self.as_rec_mut().extend(value.to_bytes_with_nul());
15387 self
15388 }
15389 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
15390 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
15391 self.as_rec_mut().extend(value);
15392 self.as_rec_mut().push(0);
15393 self
15394 }
15395 pub fn push_rev(mut self, value: u32) -> Self {
15396 push_header(self.as_rec_mut(), 2u16, 4 as u16);
15397 self.as_rec_mut().extend(value.to_be_bytes());
15398 self
15399 }
15400 pub fn push_type(mut self, value: u32) -> Self {
15401 push_header(self.as_rec_mut(), 3u16, 4 as u16);
15402 self.as_rec_mut().extend(value.to_be_bytes());
15403 self
15404 }
15405}
15406impl<Prev: Rec> Drop for PushCompatAttrs<Prev> {
15407 fn drop(&mut self) {
15408 if let Some(prev) = &mut self.prev {
15409 if let Some(header_offset) = &self.header_offset {
15410 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15411 }
15412 }
15413 }
15414}
15415#[derive(Clone)]
15416pub struct PushNfgenmsg {
15417 pub(crate) buf: [u8; 4usize],
15418}
15419#[doc = "Create zero-initialized struct"]
15420impl Default for PushNfgenmsg {
15421 fn default() -> Self {
15422 Self { buf: [0u8; 4usize] }
15423 }
15424}
15425impl PushNfgenmsg {
15426 #[doc = "Create zero-initialized struct"]
15427 pub fn new() -> Self {
15428 Default::default()
15429 }
15430 #[doc = "Copy from contents from other slice"]
15431 pub fn new_from_slice(other: &[u8]) -> Option<Self> {
15432 if other.len() != Self::len() {
15433 return None;
15434 }
15435 let mut buf = [0u8; Self::len()];
15436 buf.clone_from_slice(other);
15437 Some(Self { buf })
15438 }
15439 pub fn as_slice(&self) -> &[u8] {
15440 &self.buf
15441 }
15442 pub fn as_mut_slice(&mut self) -> &mut [u8] {
15443 &mut self.buf
15444 }
15445 pub const fn len() -> usize {
15446 4usize
15447 }
15448 pub fn nfgen_family(&self) -> u8 {
15449 parse_u8(&self.buf[0usize..1usize]).unwrap()
15450 }
15451 pub fn set_nfgen_family(&mut self, value: u8) {
15452 self.buf[0usize..1usize].copy_from_slice(&value.to_ne_bytes())
15453 }
15454 pub fn version(&self) -> u8 {
15455 parse_u8(&self.buf[1usize..2usize]).unwrap()
15456 }
15457 pub fn set_version(&mut self, value: u8) {
15458 self.buf[1usize..2usize].copy_from_slice(&value.to_ne_bytes())
15459 }
15460 pub fn res_id(&self) -> u16 {
15461 parse_be_u16(&self.buf[2usize..4usize]).unwrap()
15462 }
15463 pub fn set_res_id(&mut self, value: u16) {
15464 self.buf[2usize..4usize].copy_from_slice(&value.to_be_bytes())
15465 }
15466}
15467impl std::fmt::Debug for PushNfgenmsg {
15468 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15469 fmt.debug_struct("Nfgenmsg")
15470 .field("nfgen_family", &self.nfgen_family())
15471 .field("version", &self.version())
15472 .field("res_id", &self.res_id())
15473 .finish()
15474 }
15475}
15476#[doc = "Get / dump nft_compat info"]
15477pub struct PushOpGetcompatDumpRequest<Prev: Rec> {
15478 pub(crate) prev: Option<Prev>,
15479 pub(crate) header_offset: Option<usize>,
15480}
15481impl<Prev: Rec> Rec for PushOpGetcompatDumpRequest<Prev> {
15482 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15483 self.prev.as_mut().unwrap().as_rec_mut()
15484 }
15485}
15486impl<Prev: Rec> PushOpGetcompatDumpRequest<Prev> {
15487 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
15488 Self::write_header(&mut prev, header);
15489 Self::new_without_header(prev)
15490 }
15491 fn new_without_header(prev: Prev) -> Self {
15492 Self {
15493 prev: Some(prev),
15494 header_offset: None,
15495 }
15496 }
15497 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
15498 prev.as_rec_mut().extend(header.as_slice());
15499 }
15500 pub fn end_nested(mut self) -> Prev {
15501 let mut prev = self.prev.take().unwrap();
15502 if let Some(header_offset) = &self.header_offset {
15503 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15504 }
15505 prev
15506 }
15507}
15508impl<Prev: Rec> Drop for PushOpGetcompatDumpRequest<Prev> {
15509 fn drop(&mut self) {
15510 if let Some(prev) = &mut self.prev {
15511 if let Some(header_offset) = &self.header_offset {
15512 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15513 }
15514 }
15515 }
15516}
15517#[doc = "Get / dump nft_compat info"]
15518#[derive(Clone)]
15519pub enum OpGetcompatDumpRequest {}
15520impl<'a> IterableOpGetcompatDumpRequest<'a> {}
15521impl OpGetcompatDumpRequest {
15522 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpGetcompatDumpRequest<'_>) {
15523 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
15524 (
15525 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
15526 IterableOpGetcompatDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
15527 )
15528 }
15529 fn attr_from_type(r#type: u16) -> Option<&'static str> {
15530 CompatAttrs::attr_from_type(r#type)
15531 }
15532}
15533#[derive(Clone, Copy, Default)]
15534pub struct IterableOpGetcompatDumpRequest<'a> {
15535 buf: &'a [u8],
15536 pos: usize,
15537 orig_loc: usize,
15538}
15539impl<'a> IterableOpGetcompatDumpRequest<'a> {
15540 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15541 Self {
15542 buf,
15543 pos: 0,
15544 orig_loc,
15545 }
15546 }
15547 pub fn get_buf(&self) -> &'a [u8] {
15548 self.buf
15549 }
15550}
15551impl<'a> Iterator for IterableOpGetcompatDumpRequest<'a> {
15552 type Item = Result<OpGetcompatDumpRequest, ErrorContext>;
15553 fn next(&mut self) -> Option<Self::Item> {
15554 if self.buf.len() == self.pos {
15555 return None;
15556 }
15557 let pos = self.pos;
15558 let mut r#type = None;
15559 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
15560 r#type = Some(header.r#type);
15561 let res = match header.r#type {
15562 n => {
15563 if cfg!(any(test, feature = "deny-unknown-attrs")) {
15564 break;
15565 } else {
15566 continue;
15567 }
15568 }
15569 };
15570 return Some(Ok(res));
15571 }
15572 Some(Err(ErrorContext::new(
15573 "OpGetcompatDumpRequest",
15574 r#type.and_then(|t| OpGetcompatDumpRequest::attr_from_type(t)),
15575 self.orig_loc,
15576 self.buf.as_ptr().wrapping_add(pos) as usize,
15577 )))
15578 }
15579}
15580impl std::fmt::Debug for IterableOpGetcompatDumpRequest<'_> {
15581 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15582 let mut fmt = f.debug_struct("OpGetcompatDumpRequest");
15583 for attr in self.clone() {
15584 let attr = match attr {
15585 Ok(a) => a,
15586 Err(err) => {
15587 fmt.finish()?;
15588 f.write_str("Err(")?;
15589 err.fmt(f)?;
15590 return f.write_str(")");
15591 }
15592 };
15593 match attr {};
15594 }
15595 fmt.finish()
15596 }
15597}
15598impl IterableOpGetcompatDumpRequest<'_> {
15599 pub fn lookup_attr(
15600 &self,
15601 offset: usize,
15602 missing_type: Option<u16>,
15603 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15604 let mut stack = Vec::new();
15605 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15606 if cur == offset + PushNfgenmsg::len() {
15607 stack.push(("OpGetcompatDumpRequest", offset));
15608 return (
15609 stack,
15610 missing_type.and_then(|t| OpGetcompatDumpRequest::attr_from_type(t)),
15611 );
15612 }
15613 (stack, None)
15614 }
15615}
15616#[doc = "Get / dump nft_compat info"]
15617pub struct PushOpGetcompatDumpReply<Prev: Rec> {
15618 pub(crate) prev: Option<Prev>,
15619 pub(crate) header_offset: Option<usize>,
15620}
15621impl<Prev: Rec> Rec for PushOpGetcompatDumpReply<Prev> {
15622 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15623 self.prev.as_mut().unwrap().as_rec_mut()
15624 }
15625}
15626impl<Prev: Rec> PushOpGetcompatDumpReply<Prev> {
15627 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
15628 Self::write_header(&mut prev, header);
15629 Self::new_without_header(prev)
15630 }
15631 fn new_without_header(prev: Prev) -> Self {
15632 Self {
15633 prev: Some(prev),
15634 header_offset: None,
15635 }
15636 }
15637 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
15638 prev.as_rec_mut().extend(header.as_slice());
15639 }
15640 pub fn end_nested(mut self) -> Prev {
15641 let mut prev = self.prev.take().unwrap();
15642 if let Some(header_offset) = &self.header_offset {
15643 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15644 }
15645 prev
15646 }
15647 pub fn push_name(mut self, value: &CStr) -> Self {
15648 push_header(
15649 self.as_rec_mut(),
15650 1u16,
15651 value.to_bytes_with_nul().len() as u16,
15652 );
15653 self.as_rec_mut().extend(value.to_bytes_with_nul());
15654 self
15655 }
15656 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
15657 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
15658 self.as_rec_mut().extend(value);
15659 self.as_rec_mut().push(0);
15660 self
15661 }
15662 pub fn push_rev(mut self, value: u32) -> Self {
15663 push_header(self.as_rec_mut(), 2u16, 4 as u16);
15664 self.as_rec_mut().extend(value.to_be_bytes());
15665 self
15666 }
15667 pub fn push_type(mut self, value: u32) -> Self {
15668 push_header(self.as_rec_mut(), 3u16, 4 as u16);
15669 self.as_rec_mut().extend(value.to_be_bytes());
15670 self
15671 }
15672}
15673impl<Prev: Rec> Drop for PushOpGetcompatDumpReply<Prev> {
15674 fn drop(&mut self) {
15675 if let Some(prev) = &mut self.prev {
15676 if let Some(header_offset) = &self.header_offset {
15677 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15678 }
15679 }
15680 }
15681}
15682#[doc = "Get / dump nft_compat info"]
15683#[derive(Clone)]
15684pub enum OpGetcompatDumpReply<'a> {
15685 Name(&'a CStr),
15686 Rev(u32),
15687 Type(u32),
15688}
15689impl<'a> IterableOpGetcompatDumpReply<'a> {
15690 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
15691 let mut iter = self.clone();
15692 iter.pos = 0;
15693 for attr in iter {
15694 if let OpGetcompatDumpReply::Name(val) = attr? {
15695 return Ok(val);
15696 }
15697 }
15698 Err(ErrorContext::new_missing(
15699 "OpGetcompatDumpReply",
15700 "Name",
15701 self.orig_loc,
15702 self.buf.as_ptr() as usize,
15703 ))
15704 }
15705 pub fn get_rev(&self) -> Result<u32, ErrorContext> {
15706 let mut iter = self.clone();
15707 iter.pos = 0;
15708 for attr in iter {
15709 if let OpGetcompatDumpReply::Rev(val) = attr? {
15710 return Ok(val);
15711 }
15712 }
15713 Err(ErrorContext::new_missing(
15714 "OpGetcompatDumpReply",
15715 "Rev",
15716 self.orig_loc,
15717 self.buf.as_ptr() as usize,
15718 ))
15719 }
15720 pub fn get_type(&self) -> Result<u32, ErrorContext> {
15721 let mut iter = self.clone();
15722 iter.pos = 0;
15723 for attr in iter {
15724 if let OpGetcompatDumpReply::Type(val) = attr? {
15725 return Ok(val);
15726 }
15727 }
15728 Err(ErrorContext::new_missing(
15729 "OpGetcompatDumpReply",
15730 "Type",
15731 self.orig_loc,
15732 self.buf.as_ptr() as usize,
15733 ))
15734 }
15735}
15736impl<'a> OpGetcompatDumpReply<'a> {
15737 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetcompatDumpReply<'a>) {
15738 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
15739 (
15740 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
15741 IterableOpGetcompatDumpReply::with_loc(attrs, buf.as_ptr() as usize),
15742 )
15743 }
15744 fn attr_from_type(r#type: u16) -> Option<&'static str> {
15745 CompatAttrs::attr_from_type(r#type)
15746 }
15747}
15748#[derive(Clone, Copy, Default)]
15749pub struct IterableOpGetcompatDumpReply<'a> {
15750 buf: &'a [u8],
15751 pos: usize,
15752 orig_loc: usize,
15753}
15754impl<'a> IterableOpGetcompatDumpReply<'a> {
15755 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
15756 Self {
15757 buf,
15758 pos: 0,
15759 orig_loc,
15760 }
15761 }
15762 pub fn get_buf(&self) -> &'a [u8] {
15763 self.buf
15764 }
15765}
15766impl<'a> Iterator for IterableOpGetcompatDumpReply<'a> {
15767 type Item = Result<OpGetcompatDumpReply<'a>, ErrorContext>;
15768 fn next(&mut self) -> Option<Self::Item> {
15769 if self.buf.len() == self.pos {
15770 return None;
15771 }
15772 let pos = self.pos;
15773 let mut r#type = None;
15774 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
15775 r#type = Some(header.r#type);
15776 let res = match header.r#type {
15777 1u16 => OpGetcompatDumpReply::Name({
15778 let res = CStr::from_bytes_with_nul(next).ok();
15779 let Some(val) = res else { break };
15780 val
15781 }),
15782 2u16 => OpGetcompatDumpReply::Rev({
15783 let res = parse_be_u32(next);
15784 let Some(val) = res else { break };
15785 val
15786 }),
15787 3u16 => OpGetcompatDumpReply::Type({
15788 let res = parse_be_u32(next);
15789 let Some(val) = res else { break };
15790 val
15791 }),
15792 n => {
15793 if cfg!(any(test, feature = "deny-unknown-attrs")) {
15794 break;
15795 } else {
15796 continue;
15797 }
15798 }
15799 };
15800 return Some(Ok(res));
15801 }
15802 Some(Err(ErrorContext::new(
15803 "OpGetcompatDumpReply",
15804 r#type.and_then(|t| OpGetcompatDumpReply::attr_from_type(t)),
15805 self.orig_loc,
15806 self.buf.as_ptr().wrapping_add(pos) as usize,
15807 )))
15808 }
15809}
15810impl<'a> std::fmt::Debug for IterableOpGetcompatDumpReply<'_> {
15811 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15812 let mut fmt = f.debug_struct("OpGetcompatDumpReply");
15813 for attr in self.clone() {
15814 let attr = match attr {
15815 Ok(a) => a,
15816 Err(err) => {
15817 fmt.finish()?;
15818 f.write_str("Err(")?;
15819 err.fmt(f)?;
15820 return f.write_str(")");
15821 }
15822 };
15823 match attr {
15824 OpGetcompatDumpReply::Name(val) => fmt.field("Name", &val),
15825 OpGetcompatDumpReply::Rev(val) => fmt.field("Rev", &val),
15826 OpGetcompatDumpReply::Type(val) => fmt.field("Type", &val),
15827 };
15828 }
15829 fmt.finish()
15830 }
15831}
15832impl IterableOpGetcompatDumpReply<'_> {
15833 pub fn lookup_attr(
15834 &self,
15835 offset: usize,
15836 missing_type: Option<u16>,
15837 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15838 let mut stack = Vec::new();
15839 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
15840 if cur == offset + PushNfgenmsg::len() {
15841 stack.push(("OpGetcompatDumpReply", offset));
15842 return (
15843 stack,
15844 missing_type.and_then(|t| OpGetcompatDumpReply::attr_from_type(t)),
15845 );
15846 }
15847 if cur > offset || cur + self.buf.len() < offset {
15848 return (stack, None);
15849 }
15850 let mut attrs = self.clone();
15851 let mut last_off = cur + attrs.pos;
15852 while let Some(attr) = attrs.next() {
15853 let Ok(attr) = attr else { break };
15854 match attr {
15855 OpGetcompatDumpReply::Name(val) => {
15856 if last_off == offset {
15857 stack.push(("Name", last_off));
15858 break;
15859 }
15860 }
15861 OpGetcompatDumpReply::Rev(val) => {
15862 if last_off == offset {
15863 stack.push(("Rev", last_off));
15864 break;
15865 }
15866 }
15867 OpGetcompatDumpReply::Type(val) => {
15868 if last_off == offset {
15869 stack.push(("Type", last_off));
15870 break;
15871 }
15872 }
15873 _ => {}
15874 };
15875 last_off = cur + attrs.pos;
15876 }
15877 if !stack.is_empty() {
15878 stack.push(("OpGetcompatDumpReply", cur));
15879 }
15880 (stack, None)
15881 }
15882}
15883#[derive(Debug)]
15884pub struct RequestOpGetcompatDumpRequest<'r> {
15885 request: Request<'r>,
15886}
15887impl<'r> RequestOpGetcompatDumpRequest<'r> {
15888 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
15889 PushOpGetcompatDumpRequest::write_header(&mut request.buf_mut(), header);
15890 Self {
15891 request: request.set_dump(),
15892 }
15893 }
15894 pub fn encode(&mut self) -> PushOpGetcompatDumpRequest<&mut Vec<u8>> {
15895 PushOpGetcompatDumpRequest::new_without_header(self.request.buf_mut())
15896 }
15897 pub fn into_encoder(self) -> PushOpGetcompatDumpRequest<RequestBuf<'r>> {
15898 PushOpGetcompatDumpRequest::new_without_header(self.request.buf)
15899 }
15900}
15901impl NetlinkRequest for RequestOpGetcompatDumpRequest<'_> {
15902 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetcompatDumpReply<'buf>);
15903 fn protocol(&self) -> Protocol {
15904 Protocol::Raw {
15905 protonum: 12u16,
15906 request_type: 2816u16,
15907 }
15908 }
15909 fn flags(&self) -> u16 {
15910 self.request.flags
15911 }
15912 fn payload(&self) -> &[u8] {
15913 self.request.buf()
15914 }
15915 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
15916 OpGetcompatDumpReply::new(buf)
15917 }
15918 fn lookup(
15919 buf: &[u8],
15920 offset: usize,
15921 missing_type: Option<u16>,
15922 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
15923 OpGetcompatDumpRequest::new(buf)
15924 .1
15925 .lookup_attr(offset, missing_type)
15926 }
15927}
15928#[doc = "Get / dump nft_compat info"]
15929pub struct PushOpGetcompatDoRequest<Prev: Rec> {
15930 pub(crate) prev: Option<Prev>,
15931 pub(crate) header_offset: Option<usize>,
15932}
15933impl<Prev: Rec> Rec for PushOpGetcompatDoRequest<Prev> {
15934 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
15935 self.prev.as_mut().unwrap().as_rec_mut()
15936 }
15937}
15938impl<Prev: Rec> PushOpGetcompatDoRequest<Prev> {
15939 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
15940 Self::write_header(&mut prev, header);
15941 Self::new_without_header(prev)
15942 }
15943 fn new_without_header(prev: Prev) -> Self {
15944 Self {
15945 prev: Some(prev),
15946 header_offset: None,
15947 }
15948 }
15949 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
15950 prev.as_rec_mut().extend(header.as_slice());
15951 }
15952 pub fn end_nested(mut self) -> Prev {
15953 let mut prev = self.prev.take().unwrap();
15954 if let Some(header_offset) = &self.header_offset {
15955 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15956 }
15957 prev
15958 }
15959 pub fn push_name(mut self, value: &CStr) -> Self {
15960 push_header(
15961 self.as_rec_mut(),
15962 1u16,
15963 value.to_bytes_with_nul().len() as u16,
15964 );
15965 self.as_rec_mut().extend(value.to_bytes_with_nul());
15966 self
15967 }
15968 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
15969 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
15970 self.as_rec_mut().extend(value);
15971 self.as_rec_mut().push(0);
15972 self
15973 }
15974 pub fn push_rev(mut self, value: u32) -> Self {
15975 push_header(self.as_rec_mut(), 2u16, 4 as u16);
15976 self.as_rec_mut().extend(value.to_be_bytes());
15977 self
15978 }
15979 pub fn push_type(mut self, value: u32) -> Self {
15980 push_header(self.as_rec_mut(), 3u16, 4 as u16);
15981 self.as_rec_mut().extend(value.to_be_bytes());
15982 self
15983 }
15984}
15985impl<Prev: Rec> Drop for PushOpGetcompatDoRequest<Prev> {
15986 fn drop(&mut self) {
15987 if let Some(prev) = &mut self.prev {
15988 if let Some(header_offset) = &self.header_offset {
15989 finalize_nested_header(prev.as_rec_mut(), *header_offset);
15990 }
15991 }
15992 }
15993}
15994#[doc = "Get / dump nft_compat info"]
15995#[derive(Clone)]
15996pub enum OpGetcompatDoRequest<'a> {
15997 Name(&'a CStr),
15998 Rev(u32),
15999 Type(u32),
16000}
16001impl<'a> IterableOpGetcompatDoRequest<'a> {
16002 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
16003 let mut iter = self.clone();
16004 iter.pos = 0;
16005 for attr in iter {
16006 if let OpGetcompatDoRequest::Name(val) = attr? {
16007 return Ok(val);
16008 }
16009 }
16010 Err(ErrorContext::new_missing(
16011 "OpGetcompatDoRequest",
16012 "Name",
16013 self.orig_loc,
16014 self.buf.as_ptr() as usize,
16015 ))
16016 }
16017 pub fn get_rev(&self) -> Result<u32, ErrorContext> {
16018 let mut iter = self.clone();
16019 iter.pos = 0;
16020 for attr in iter {
16021 if let OpGetcompatDoRequest::Rev(val) = attr? {
16022 return Ok(val);
16023 }
16024 }
16025 Err(ErrorContext::new_missing(
16026 "OpGetcompatDoRequest",
16027 "Rev",
16028 self.orig_loc,
16029 self.buf.as_ptr() as usize,
16030 ))
16031 }
16032 pub fn get_type(&self) -> Result<u32, ErrorContext> {
16033 let mut iter = self.clone();
16034 iter.pos = 0;
16035 for attr in iter {
16036 if let OpGetcompatDoRequest::Type(val) = attr? {
16037 return Ok(val);
16038 }
16039 }
16040 Err(ErrorContext::new_missing(
16041 "OpGetcompatDoRequest",
16042 "Type",
16043 self.orig_loc,
16044 self.buf.as_ptr() as usize,
16045 ))
16046 }
16047}
16048impl<'a> OpGetcompatDoRequest<'a> {
16049 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetcompatDoRequest<'a>) {
16050 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
16051 (
16052 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
16053 IterableOpGetcompatDoRequest::with_loc(attrs, buf.as_ptr() as usize),
16054 )
16055 }
16056 fn attr_from_type(r#type: u16) -> Option<&'static str> {
16057 CompatAttrs::attr_from_type(r#type)
16058 }
16059}
16060#[derive(Clone, Copy, Default)]
16061pub struct IterableOpGetcompatDoRequest<'a> {
16062 buf: &'a [u8],
16063 pos: usize,
16064 orig_loc: usize,
16065}
16066impl<'a> IterableOpGetcompatDoRequest<'a> {
16067 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
16068 Self {
16069 buf,
16070 pos: 0,
16071 orig_loc,
16072 }
16073 }
16074 pub fn get_buf(&self) -> &'a [u8] {
16075 self.buf
16076 }
16077}
16078impl<'a> Iterator for IterableOpGetcompatDoRequest<'a> {
16079 type Item = Result<OpGetcompatDoRequest<'a>, ErrorContext>;
16080 fn next(&mut self) -> Option<Self::Item> {
16081 if self.buf.len() == self.pos {
16082 return None;
16083 }
16084 let pos = self.pos;
16085 let mut r#type = None;
16086 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
16087 r#type = Some(header.r#type);
16088 let res = match header.r#type {
16089 1u16 => OpGetcompatDoRequest::Name({
16090 let res = CStr::from_bytes_with_nul(next).ok();
16091 let Some(val) = res else { break };
16092 val
16093 }),
16094 2u16 => OpGetcompatDoRequest::Rev({
16095 let res = parse_be_u32(next);
16096 let Some(val) = res else { break };
16097 val
16098 }),
16099 3u16 => OpGetcompatDoRequest::Type({
16100 let res = parse_be_u32(next);
16101 let Some(val) = res else { break };
16102 val
16103 }),
16104 n => {
16105 if cfg!(any(test, feature = "deny-unknown-attrs")) {
16106 break;
16107 } else {
16108 continue;
16109 }
16110 }
16111 };
16112 return Some(Ok(res));
16113 }
16114 Some(Err(ErrorContext::new(
16115 "OpGetcompatDoRequest",
16116 r#type.and_then(|t| OpGetcompatDoRequest::attr_from_type(t)),
16117 self.orig_loc,
16118 self.buf.as_ptr().wrapping_add(pos) as usize,
16119 )))
16120 }
16121}
16122impl<'a> std::fmt::Debug for IterableOpGetcompatDoRequest<'_> {
16123 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16124 let mut fmt = f.debug_struct("OpGetcompatDoRequest");
16125 for attr in self.clone() {
16126 let attr = match attr {
16127 Ok(a) => a,
16128 Err(err) => {
16129 fmt.finish()?;
16130 f.write_str("Err(")?;
16131 err.fmt(f)?;
16132 return f.write_str(")");
16133 }
16134 };
16135 match attr {
16136 OpGetcompatDoRequest::Name(val) => fmt.field("Name", &val),
16137 OpGetcompatDoRequest::Rev(val) => fmt.field("Rev", &val),
16138 OpGetcompatDoRequest::Type(val) => fmt.field("Type", &val),
16139 };
16140 }
16141 fmt.finish()
16142 }
16143}
16144impl IterableOpGetcompatDoRequest<'_> {
16145 pub fn lookup_attr(
16146 &self,
16147 offset: usize,
16148 missing_type: Option<u16>,
16149 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16150 let mut stack = Vec::new();
16151 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
16152 if cur == offset + PushNfgenmsg::len() {
16153 stack.push(("OpGetcompatDoRequest", offset));
16154 return (
16155 stack,
16156 missing_type.and_then(|t| OpGetcompatDoRequest::attr_from_type(t)),
16157 );
16158 }
16159 if cur > offset || cur + self.buf.len() < offset {
16160 return (stack, None);
16161 }
16162 let mut attrs = self.clone();
16163 let mut last_off = cur + attrs.pos;
16164 while let Some(attr) = attrs.next() {
16165 let Ok(attr) = attr else { break };
16166 match attr {
16167 OpGetcompatDoRequest::Name(val) => {
16168 if last_off == offset {
16169 stack.push(("Name", last_off));
16170 break;
16171 }
16172 }
16173 OpGetcompatDoRequest::Rev(val) => {
16174 if last_off == offset {
16175 stack.push(("Rev", last_off));
16176 break;
16177 }
16178 }
16179 OpGetcompatDoRequest::Type(val) => {
16180 if last_off == offset {
16181 stack.push(("Type", last_off));
16182 break;
16183 }
16184 }
16185 _ => {}
16186 };
16187 last_off = cur + attrs.pos;
16188 }
16189 if !stack.is_empty() {
16190 stack.push(("OpGetcompatDoRequest", cur));
16191 }
16192 (stack, None)
16193 }
16194}
16195#[doc = "Get / dump nft_compat info"]
16196pub struct PushOpGetcompatDoReply<Prev: Rec> {
16197 pub(crate) prev: Option<Prev>,
16198 pub(crate) header_offset: Option<usize>,
16199}
16200impl<Prev: Rec> Rec for PushOpGetcompatDoReply<Prev> {
16201 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
16202 self.prev.as_mut().unwrap().as_rec_mut()
16203 }
16204}
16205impl<Prev: Rec> PushOpGetcompatDoReply<Prev> {
16206 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
16207 Self::write_header(&mut prev, header);
16208 Self::new_without_header(prev)
16209 }
16210 fn new_without_header(prev: Prev) -> Self {
16211 Self {
16212 prev: Some(prev),
16213 header_offset: None,
16214 }
16215 }
16216 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
16217 prev.as_rec_mut().extend(header.as_slice());
16218 }
16219 pub fn end_nested(mut self) -> Prev {
16220 let mut prev = self.prev.take().unwrap();
16221 if let Some(header_offset) = &self.header_offset {
16222 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16223 }
16224 prev
16225 }
16226 pub fn push_name(mut self, value: &CStr) -> Self {
16227 push_header(
16228 self.as_rec_mut(),
16229 1u16,
16230 value.to_bytes_with_nul().len() as u16,
16231 );
16232 self.as_rec_mut().extend(value.to_bytes_with_nul());
16233 self
16234 }
16235 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
16236 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
16237 self.as_rec_mut().extend(value);
16238 self.as_rec_mut().push(0);
16239 self
16240 }
16241 pub fn push_rev(mut self, value: u32) -> Self {
16242 push_header(self.as_rec_mut(), 2u16, 4 as u16);
16243 self.as_rec_mut().extend(value.to_be_bytes());
16244 self
16245 }
16246 pub fn push_type(mut self, value: u32) -> Self {
16247 push_header(self.as_rec_mut(), 3u16, 4 as u16);
16248 self.as_rec_mut().extend(value.to_be_bytes());
16249 self
16250 }
16251}
16252impl<Prev: Rec> Drop for PushOpGetcompatDoReply<Prev> {
16253 fn drop(&mut self) {
16254 if let Some(prev) = &mut self.prev {
16255 if let Some(header_offset) = &self.header_offset {
16256 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16257 }
16258 }
16259 }
16260}
16261#[doc = "Get / dump nft_compat info"]
16262#[derive(Clone)]
16263pub enum OpGetcompatDoReply<'a> {
16264 Name(&'a CStr),
16265 Rev(u32),
16266 Type(u32),
16267}
16268impl<'a> IterableOpGetcompatDoReply<'a> {
16269 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
16270 let mut iter = self.clone();
16271 iter.pos = 0;
16272 for attr in iter {
16273 if let OpGetcompatDoReply::Name(val) = attr? {
16274 return Ok(val);
16275 }
16276 }
16277 Err(ErrorContext::new_missing(
16278 "OpGetcompatDoReply",
16279 "Name",
16280 self.orig_loc,
16281 self.buf.as_ptr() as usize,
16282 ))
16283 }
16284 pub fn get_rev(&self) -> Result<u32, ErrorContext> {
16285 let mut iter = self.clone();
16286 iter.pos = 0;
16287 for attr in iter {
16288 if let OpGetcompatDoReply::Rev(val) = attr? {
16289 return Ok(val);
16290 }
16291 }
16292 Err(ErrorContext::new_missing(
16293 "OpGetcompatDoReply",
16294 "Rev",
16295 self.orig_loc,
16296 self.buf.as_ptr() as usize,
16297 ))
16298 }
16299 pub fn get_type(&self) -> Result<u32, ErrorContext> {
16300 let mut iter = self.clone();
16301 iter.pos = 0;
16302 for attr in iter {
16303 if let OpGetcompatDoReply::Type(val) = attr? {
16304 return Ok(val);
16305 }
16306 }
16307 Err(ErrorContext::new_missing(
16308 "OpGetcompatDoReply",
16309 "Type",
16310 self.orig_loc,
16311 self.buf.as_ptr() as usize,
16312 ))
16313 }
16314}
16315impl<'a> OpGetcompatDoReply<'a> {
16316 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetcompatDoReply<'a>) {
16317 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
16318 (
16319 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
16320 IterableOpGetcompatDoReply::with_loc(attrs, buf.as_ptr() as usize),
16321 )
16322 }
16323 fn attr_from_type(r#type: u16) -> Option<&'static str> {
16324 CompatAttrs::attr_from_type(r#type)
16325 }
16326}
16327#[derive(Clone, Copy, Default)]
16328pub struct IterableOpGetcompatDoReply<'a> {
16329 buf: &'a [u8],
16330 pos: usize,
16331 orig_loc: usize,
16332}
16333impl<'a> IterableOpGetcompatDoReply<'a> {
16334 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
16335 Self {
16336 buf,
16337 pos: 0,
16338 orig_loc,
16339 }
16340 }
16341 pub fn get_buf(&self) -> &'a [u8] {
16342 self.buf
16343 }
16344}
16345impl<'a> Iterator for IterableOpGetcompatDoReply<'a> {
16346 type Item = Result<OpGetcompatDoReply<'a>, ErrorContext>;
16347 fn next(&mut self) -> Option<Self::Item> {
16348 if self.buf.len() == self.pos {
16349 return None;
16350 }
16351 let pos = self.pos;
16352 let mut r#type = None;
16353 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
16354 r#type = Some(header.r#type);
16355 let res = match header.r#type {
16356 1u16 => OpGetcompatDoReply::Name({
16357 let res = CStr::from_bytes_with_nul(next).ok();
16358 let Some(val) = res else { break };
16359 val
16360 }),
16361 2u16 => OpGetcompatDoReply::Rev({
16362 let res = parse_be_u32(next);
16363 let Some(val) = res else { break };
16364 val
16365 }),
16366 3u16 => OpGetcompatDoReply::Type({
16367 let res = parse_be_u32(next);
16368 let Some(val) = res else { break };
16369 val
16370 }),
16371 n => {
16372 if cfg!(any(test, feature = "deny-unknown-attrs")) {
16373 break;
16374 } else {
16375 continue;
16376 }
16377 }
16378 };
16379 return Some(Ok(res));
16380 }
16381 Some(Err(ErrorContext::new(
16382 "OpGetcompatDoReply",
16383 r#type.and_then(|t| OpGetcompatDoReply::attr_from_type(t)),
16384 self.orig_loc,
16385 self.buf.as_ptr().wrapping_add(pos) as usize,
16386 )))
16387 }
16388}
16389impl<'a> std::fmt::Debug for IterableOpGetcompatDoReply<'_> {
16390 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16391 let mut fmt = f.debug_struct("OpGetcompatDoReply");
16392 for attr in self.clone() {
16393 let attr = match attr {
16394 Ok(a) => a,
16395 Err(err) => {
16396 fmt.finish()?;
16397 f.write_str("Err(")?;
16398 err.fmt(f)?;
16399 return f.write_str(")");
16400 }
16401 };
16402 match attr {
16403 OpGetcompatDoReply::Name(val) => fmt.field("Name", &val),
16404 OpGetcompatDoReply::Rev(val) => fmt.field("Rev", &val),
16405 OpGetcompatDoReply::Type(val) => fmt.field("Type", &val),
16406 };
16407 }
16408 fmt.finish()
16409 }
16410}
16411impl IterableOpGetcompatDoReply<'_> {
16412 pub fn lookup_attr(
16413 &self,
16414 offset: usize,
16415 missing_type: Option<u16>,
16416 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16417 let mut stack = Vec::new();
16418 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
16419 if cur == offset + PushNfgenmsg::len() {
16420 stack.push(("OpGetcompatDoReply", offset));
16421 return (
16422 stack,
16423 missing_type.and_then(|t| OpGetcompatDoReply::attr_from_type(t)),
16424 );
16425 }
16426 if cur > offset || cur + self.buf.len() < offset {
16427 return (stack, None);
16428 }
16429 let mut attrs = self.clone();
16430 let mut last_off = cur + attrs.pos;
16431 while let Some(attr) = attrs.next() {
16432 let Ok(attr) = attr else { break };
16433 match attr {
16434 OpGetcompatDoReply::Name(val) => {
16435 if last_off == offset {
16436 stack.push(("Name", last_off));
16437 break;
16438 }
16439 }
16440 OpGetcompatDoReply::Rev(val) => {
16441 if last_off == offset {
16442 stack.push(("Rev", last_off));
16443 break;
16444 }
16445 }
16446 OpGetcompatDoReply::Type(val) => {
16447 if last_off == offset {
16448 stack.push(("Type", last_off));
16449 break;
16450 }
16451 }
16452 _ => {}
16453 };
16454 last_off = cur + attrs.pos;
16455 }
16456 if !stack.is_empty() {
16457 stack.push(("OpGetcompatDoReply", cur));
16458 }
16459 (stack, None)
16460 }
16461}
16462#[derive(Debug)]
16463pub struct RequestOpGetcompatDoRequest<'r> {
16464 request: Request<'r>,
16465}
16466impl<'r> RequestOpGetcompatDoRequest<'r> {
16467 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
16468 PushOpGetcompatDoRequest::write_header(&mut request.buf_mut(), header);
16469 Self { request: request }
16470 }
16471 pub fn encode(&mut self) -> PushOpGetcompatDoRequest<&mut Vec<u8>> {
16472 PushOpGetcompatDoRequest::new_without_header(self.request.buf_mut())
16473 }
16474 pub fn into_encoder(self) -> PushOpGetcompatDoRequest<RequestBuf<'r>> {
16475 PushOpGetcompatDoRequest::new_without_header(self.request.buf)
16476 }
16477}
16478impl NetlinkRequest for RequestOpGetcompatDoRequest<'_> {
16479 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetcompatDoReply<'buf>);
16480 fn protocol(&self) -> Protocol {
16481 Protocol::Raw {
16482 protonum: 12u16,
16483 request_type: 2816u16,
16484 }
16485 }
16486 fn flags(&self) -> u16 {
16487 self.request.flags
16488 }
16489 fn payload(&self) -> &[u8] {
16490 self.request.buf()
16491 }
16492 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
16493 OpGetcompatDoReply::new(buf)
16494 }
16495 fn lookup(
16496 buf: &[u8],
16497 offset: usize,
16498 missing_type: Option<u16>,
16499 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16500 OpGetcompatDoRequest::new(buf)
16501 .1
16502 .lookup_attr(offset, missing_type)
16503 }
16504}
16505#[doc = "Start a batch of operations"]
16506pub struct PushOpBatchBeginDoRequest<Prev: Rec> {
16507 pub(crate) prev: Option<Prev>,
16508 pub(crate) header_offset: Option<usize>,
16509}
16510impl<Prev: Rec> Rec for PushOpBatchBeginDoRequest<Prev> {
16511 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
16512 self.prev.as_mut().unwrap().as_rec_mut()
16513 }
16514}
16515impl<Prev: Rec> PushOpBatchBeginDoRequest<Prev> {
16516 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
16517 Self::write_header(&mut prev, header);
16518 Self::new_without_header(prev)
16519 }
16520 fn new_without_header(prev: Prev) -> Self {
16521 Self {
16522 prev: Some(prev),
16523 header_offset: None,
16524 }
16525 }
16526 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
16527 prev.as_rec_mut().extend(header.as_slice());
16528 }
16529 pub fn end_nested(mut self) -> Prev {
16530 let mut prev = self.prev.take().unwrap();
16531 if let Some(header_offset) = &self.header_offset {
16532 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16533 }
16534 prev
16535 }
16536 #[doc = "generation ID for this changeset"]
16537 pub fn push_genid(mut self, value: u32) -> Self {
16538 push_header(self.as_rec_mut(), 1u16, 4 as u16);
16539 self.as_rec_mut().extend(value.to_be_bytes());
16540 self
16541 }
16542}
16543impl<Prev: Rec> Drop for PushOpBatchBeginDoRequest<Prev> {
16544 fn drop(&mut self) {
16545 if let Some(prev) = &mut self.prev {
16546 if let Some(header_offset) = &self.header_offset {
16547 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16548 }
16549 }
16550 }
16551}
16552#[doc = "Start a batch of operations"]
16553#[derive(Clone)]
16554pub enum OpBatchBeginDoRequest {
16555 #[doc = "generation ID for this changeset"]
16556 Genid(u32),
16557}
16558impl<'a> IterableOpBatchBeginDoRequest<'a> {
16559 #[doc = "generation ID for this changeset"]
16560 pub fn get_genid(&self) -> Result<u32, ErrorContext> {
16561 let mut iter = self.clone();
16562 iter.pos = 0;
16563 for attr in iter {
16564 if let OpBatchBeginDoRequest::Genid(val) = attr? {
16565 return Ok(val);
16566 }
16567 }
16568 Err(ErrorContext::new_missing(
16569 "OpBatchBeginDoRequest",
16570 "Genid",
16571 self.orig_loc,
16572 self.buf.as_ptr() as usize,
16573 ))
16574 }
16575}
16576impl OpBatchBeginDoRequest {
16577 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpBatchBeginDoRequest<'_>) {
16578 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
16579 (
16580 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
16581 IterableOpBatchBeginDoRequest::with_loc(attrs, buf.as_ptr() as usize),
16582 )
16583 }
16584 fn attr_from_type(r#type: u16) -> Option<&'static str> {
16585 BatchAttrs::attr_from_type(r#type)
16586 }
16587}
16588#[derive(Clone, Copy, Default)]
16589pub struct IterableOpBatchBeginDoRequest<'a> {
16590 buf: &'a [u8],
16591 pos: usize,
16592 orig_loc: usize,
16593}
16594impl<'a> IterableOpBatchBeginDoRequest<'a> {
16595 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
16596 Self {
16597 buf,
16598 pos: 0,
16599 orig_loc,
16600 }
16601 }
16602 pub fn get_buf(&self) -> &'a [u8] {
16603 self.buf
16604 }
16605}
16606impl<'a> Iterator for IterableOpBatchBeginDoRequest<'a> {
16607 type Item = Result<OpBatchBeginDoRequest, ErrorContext>;
16608 fn next(&mut self) -> Option<Self::Item> {
16609 if self.buf.len() == self.pos {
16610 return None;
16611 }
16612 let pos = self.pos;
16613 let mut r#type = None;
16614 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
16615 r#type = Some(header.r#type);
16616 let res = match header.r#type {
16617 1u16 => OpBatchBeginDoRequest::Genid({
16618 let res = parse_be_u32(next);
16619 let Some(val) = res else { break };
16620 val
16621 }),
16622 n => {
16623 if cfg!(any(test, feature = "deny-unknown-attrs")) {
16624 break;
16625 } else {
16626 continue;
16627 }
16628 }
16629 };
16630 return Some(Ok(res));
16631 }
16632 Some(Err(ErrorContext::new(
16633 "OpBatchBeginDoRequest",
16634 r#type.and_then(|t| OpBatchBeginDoRequest::attr_from_type(t)),
16635 self.orig_loc,
16636 self.buf.as_ptr().wrapping_add(pos) as usize,
16637 )))
16638 }
16639}
16640impl std::fmt::Debug for IterableOpBatchBeginDoRequest<'_> {
16641 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16642 let mut fmt = f.debug_struct("OpBatchBeginDoRequest");
16643 for attr in self.clone() {
16644 let attr = match attr {
16645 Ok(a) => a,
16646 Err(err) => {
16647 fmt.finish()?;
16648 f.write_str("Err(")?;
16649 err.fmt(f)?;
16650 return f.write_str(")");
16651 }
16652 };
16653 match attr {
16654 OpBatchBeginDoRequest::Genid(val) => fmt.field("Genid", &val),
16655 };
16656 }
16657 fmt.finish()
16658 }
16659}
16660impl IterableOpBatchBeginDoRequest<'_> {
16661 pub fn lookup_attr(
16662 &self,
16663 offset: usize,
16664 missing_type: Option<u16>,
16665 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16666 let mut stack = Vec::new();
16667 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
16668 if cur == offset + PushNfgenmsg::len() {
16669 stack.push(("OpBatchBeginDoRequest", offset));
16670 return (
16671 stack,
16672 missing_type.and_then(|t| OpBatchBeginDoRequest::attr_from_type(t)),
16673 );
16674 }
16675 if cur > offset || cur + self.buf.len() < offset {
16676 return (stack, None);
16677 }
16678 let mut attrs = self.clone();
16679 let mut last_off = cur + attrs.pos;
16680 while let Some(attr) = attrs.next() {
16681 let Ok(attr) = attr else { break };
16682 match attr {
16683 OpBatchBeginDoRequest::Genid(val) => {
16684 if last_off == offset {
16685 stack.push(("Genid", last_off));
16686 break;
16687 }
16688 }
16689 _ => {}
16690 };
16691 last_off = cur + attrs.pos;
16692 }
16693 if !stack.is_empty() {
16694 stack.push(("OpBatchBeginDoRequest", cur));
16695 }
16696 (stack, None)
16697 }
16698}
16699#[doc = "Start a batch of operations"]
16700pub struct PushOpBatchBeginDoReply<Prev: Rec> {
16701 pub(crate) prev: Option<Prev>,
16702 pub(crate) header_offset: Option<usize>,
16703}
16704impl<Prev: Rec> Rec for PushOpBatchBeginDoReply<Prev> {
16705 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
16706 self.prev.as_mut().unwrap().as_rec_mut()
16707 }
16708}
16709impl<Prev: Rec> PushOpBatchBeginDoReply<Prev> {
16710 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
16711 Self::write_header(&mut prev, header);
16712 Self::new_without_header(prev)
16713 }
16714 fn new_without_header(prev: Prev) -> Self {
16715 Self {
16716 prev: Some(prev),
16717 header_offset: None,
16718 }
16719 }
16720 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
16721 prev.as_rec_mut().extend(header.as_slice());
16722 }
16723 pub fn end_nested(mut self) -> Prev {
16724 let mut prev = self.prev.take().unwrap();
16725 if let Some(header_offset) = &self.header_offset {
16726 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16727 }
16728 prev
16729 }
16730 #[doc = "generation ID for this changeset"]
16731 pub fn push_genid(mut self, value: u32) -> Self {
16732 push_header(self.as_rec_mut(), 1u16, 4 as u16);
16733 self.as_rec_mut().extend(value.to_be_bytes());
16734 self
16735 }
16736}
16737impl<Prev: Rec> Drop for PushOpBatchBeginDoReply<Prev> {
16738 fn drop(&mut self) {
16739 if let Some(prev) = &mut self.prev {
16740 if let Some(header_offset) = &self.header_offset {
16741 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16742 }
16743 }
16744 }
16745}
16746#[doc = "Start a batch of operations"]
16747#[derive(Clone)]
16748pub enum OpBatchBeginDoReply {
16749 #[doc = "generation ID for this changeset"]
16750 Genid(u32),
16751}
16752impl<'a> IterableOpBatchBeginDoReply<'a> {
16753 #[doc = "generation ID for this changeset"]
16754 pub fn get_genid(&self) -> Result<u32, ErrorContext> {
16755 let mut iter = self.clone();
16756 iter.pos = 0;
16757 for attr in iter {
16758 if let OpBatchBeginDoReply::Genid(val) = attr? {
16759 return Ok(val);
16760 }
16761 }
16762 Err(ErrorContext::new_missing(
16763 "OpBatchBeginDoReply",
16764 "Genid",
16765 self.orig_loc,
16766 self.buf.as_ptr() as usize,
16767 ))
16768 }
16769}
16770impl OpBatchBeginDoReply {
16771 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpBatchBeginDoReply<'_>) {
16772 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
16773 (
16774 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
16775 IterableOpBatchBeginDoReply::with_loc(attrs, buf.as_ptr() as usize),
16776 )
16777 }
16778 fn attr_from_type(r#type: u16) -> Option<&'static str> {
16779 BatchAttrs::attr_from_type(r#type)
16780 }
16781}
16782#[derive(Clone, Copy, Default)]
16783pub struct IterableOpBatchBeginDoReply<'a> {
16784 buf: &'a [u8],
16785 pos: usize,
16786 orig_loc: usize,
16787}
16788impl<'a> IterableOpBatchBeginDoReply<'a> {
16789 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
16790 Self {
16791 buf,
16792 pos: 0,
16793 orig_loc,
16794 }
16795 }
16796 pub fn get_buf(&self) -> &'a [u8] {
16797 self.buf
16798 }
16799}
16800impl<'a> Iterator for IterableOpBatchBeginDoReply<'a> {
16801 type Item = Result<OpBatchBeginDoReply, ErrorContext>;
16802 fn next(&mut self) -> Option<Self::Item> {
16803 if self.buf.len() == self.pos {
16804 return None;
16805 }
16806 let pos = self.pos;
16807 let mut r#type = None;
16808 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
16809 r#type = Some(header.r#type);
16810 let res = match header.r#type {
16811 1u16 => OpBatchBeginDoReply::Genid({
16812 let res = parse_be_u32(next);
16813 let Some(val) = res else { break };
16814 val
16815 }),
16816 n => {
16817 if cfg!(any(test, feature = "deny-unknown-attrs")) {
16818 break;
16819 } else {
16820 continue;
16821 }
16822 }
16823 };
16824 return Some(Ok(res));
16825 }
16826 Some(Err(ErrorContext::new(
16827 "OpBatchBeginDoReply",
16828 r#type.and_then(|t| OpBatchBeginDoReply::attr_from_type(t)),
16829 self.orig_loc,
16830 self.buf.as_ptr().wrapping_add(pos) as usize,
16831 )))
16832 }
16833}
16834impl std::fmt::Debug for IterableOpBatchBeginDoReply<'_> {
16835 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16836 let mut fmt = f.debug_struct("OpBatchBeginDoReply");
16837 for attr in self.clone() {
16838 let attr = match attr {
16839 Ok(a) => a,
16840 Err(err) => {
16841 fmt.finish()?;
16842 f.write_str("Err(")?;
16843 err.fmt(f)?;
16844 return f.write_str(")");
16845 }
16846 };
16847 match attr {
16848 OpBatchBeginDoReply::Genid(val) => fmt.field("Genid", &val),
16849 };
16850 }
16851 fmt.finish()
16852 }
16853}
16854impl IterableOpBatchBeginDoReply<'_> {
16855 pub fn lookup_attr(
16856 &self,
16857 offset: usize,
16858 missing_type: Option<u16>,
16859 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16860 let mut stack = Vec::new();
16861 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
16862 if cur == offset + PushNfgenmsg::len() {
16863 stack.push(("OpBatchBeginDoReply", offset));
16864 return (
16865 stack,
16866 missing_type.and_then(|t| OpBatchBeginDoReply::attr_from_type(t)),
16867 );
16868 }
16869 if cur > offset || cur + self.buf.len() < offset {
16870 return (stack, None);
16871 }
16872 let mut attrs = self.clone();
16873 let mut last_off = cur + attrs.pos;
16874 while let Some(attr) = attrs.next() {
16875 let Ok(attr) = attr else { break };
16876 match attr {
16877 OpBatchBeginDoReply::Genid(val) => {
16878 if last_off == offset {
16879 stack.push(("Genid", last_off));
16880 break;
16881 }
16882 }
16883 _ => {}
16884 };
16885 last_off = cur + attrs.pos;
16886 }
16887 if !stack.is_empty() {
16888 stack.push(("OpBatchBeginDoReply", cur));
16889 }
16890 (stack, None)
16891 }
16892}
16893#[derive(Debug)]
16894pub struct RequestOpBatchBeginDoRequest<'r> {
16895 request: Request<'r>,
16896}
16897impl<'r> RequestOpBatchBeginDoRequest<'r> {
16898 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
16899 PushOpBatchBeginDoRequest::write_header(&mut request.buf_mut(), header);
16900 Self { request: request }
16901 }
16902 pub fn encode(&mut self) -> PushOpBatchBeginDoRequest<&mut Vec<u8>> {
16903 PushOpBatchBeginDoRequest::new_without_header(self.request.buf_mut())
16904 }
16905 pub fn into_encoder(self) -> PushOpBatchBeginDoRequest<RequestBuf<'r>> {
16906 PushOpBatchBeginDoRequest::new_without_header(self.request.buf)
16907 }
16908}
16909impl NetlinkRequest for RequestOpBatchBeginDoRequest<'_> {
16910 type ReplyType<'buf> = (PushNfgenmsg, IterableOpBatchBeginDoReply<'buf>);
16911 fn protocol(&self) -> Protocol {
16912 Protocol::Raw {
16913 protonum: 12u16,
16914 request_type: 16u16,
16915 }
16916 }
16917 fn flags(&self) -> u16 {
16918 self.request.flags
16919 }
16920 fn payload(&self) -> &[u8] {
16921 self.request.buf()
16922 }
16923 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
16924 OpBatchBeginDoReply::new(buf)
16925 }
16926 fn lookup(
16927 buf: &[u8],
16928 offset: usize,
16929 missing_type: Option<u16>,
16930 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
16931 OpBatchBeginDoRequest::new(buf)
16932 .1
16933 .lookup_attr(offset, missing_type)
16934 }
16935}
16936#[doc = "Finish a batch of operations"]
16937pub struct PushOpBatchEndDoRequest<Prev: Rec> {
16938 pub(crate) prev: Option<Prev>,
16939 pub(crate) header_offset: Option<usize>,
16940}
16941impl<Prev: Rec> Rec for PushOpBatchEndDoRequest<Prev> {
16942 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
16943 self.prev.as_mut().unwrap().as_rec_mut()
16944 }
16945}
16946impl<Prev: Rec> PushOpBatchEndDoRequest<Prev> {
16947 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
16948 Self::write_header(&mut prev, header);
16949 Self::new_without_header(prev)
16950 }
16951 fn new_without_header(prev: Prev) -> Self {
16952 Self {
16953 prev: Some(prev),
16954 header_offset: None,
16955 }
16956 }
16957 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
16958 prev.as_rec_mut().extend(header.as_slice());
16959 }
16960 pub fn end_nested(mut self) -> Prev {
16961 let mut prev = self.prev.take().unwrap();
16962 if let Some(header_offset) = &self.header_offset {
16963 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16964 }
16965 prev
16966 }
16967 #[doc = "generation ID for this changeset"]
16968 pub fn push_genid(mut self, value: u32) -> Self {
16969 push_header(self.as_rec_mut(), 1u16, 4 as u16);
16970 self.as_rec_mut().extend(value.to_be_bytes());
16971 self
16972 }
16973}
16974impl<Prev: Rec> Drop for PushOpBatchEndDoRequest<Prev> {
16975 fn drop(&mut self) {
16976 if let Some(prev) = &mut self.prev {
16977 if let Some(header_offset) = &self.header_offset {
16978 finalize_nested_header(prev.as_rec_mut(), *header_offset);
16979 }
16980 }
16981 }
16982}
16983#[doc = "Finish a batch of operations"]
16984#[derive(Clone)]
16985pub enum OpBatchEndDoRequest {
16986 #[doc = "generation ID for this changeset"]
16987 Genid(u32),
16988}
16989impl<'a> IterableOpBatchEndDoRequest<'a> {
16990 #[doc = "generation ID for this changeset"]
16991 pub fn get_genid(&self) -> Result<u32, ErrorContext> {
16992 let mut iter = self.clone();
16993 iter.pos = 0;
16994 for attr in iter {
16995 if let OpBatchEndDoRequest::Genid(val) = attr? {
16996 return Ok(val);
16997 }
16998 }
16999 Err(ErrorContext::new_missing(
17000 "OpBatchEndDoRequest",
17001 "Genid",
17002 self.orig_loc,
17003 self.buf.as_ptr() as usize,
17004 ))
17005 }
17006}
17007impl OpBatchEndDoRequest {
17008 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpBatchEndDoRequest<'_>) {
17009 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
17010 (
17011 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
17012 IterableOpBatchEndDoRequest::with_loc(attrs, buf.as_ptr() as usize),
17013 )
17014 }
17015 fn attr_from_type(r#type: u16) -> Option<&'static str> {
17016 BatchAttrs::attr_from_type(r#type)
17017 }
17018}
17019#[derive(Clone, Copy, Default)]
17020pub struct IterableOpBatchEndDoRequest<'a> {
17021 buf: &'a [u8],
17022 pos: usize,
17023 orig_loc: usize,
17024}
17025impl<'a> IterableOpBatchEndDoRequest<'a> {
17026 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
17027 Self {
17028 buf,
17029 pos: 0,
17030 orig_loc,
17031 }
17032 }
17033 pub fn get_buf(&self) -> &'a [u8] {
17034 self.buf
17035 }
17036}
17037impl<'a> Iterator for IterableOpBatchEndDoRequest<'a> {
17038 type Item = Result<OpBatchEndDoRequest, ErrorContext>;
17039 fn next(&mut self) -> Option<Self::Item> {
17040 if self.buf.len() == self.pos {
17041 return None;
17042 }
17043 let pos = self.pos;
17044 let mut r#type = None;
17045 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
17046 r#type = Some(header.r#type);
17047 let res = match header.r#type {
17048 1u16 => OpBatchEndDoRequest::Genid({
17049 let res = parse_be_u32(next);
17050 let Some(val) = res else { break };
17051 val
17052 }),
17053 n => {
17054 if cfg!(any(test, feature = "deny-unknown-attrs")) {
17055 break;
17056 } else {
17057 continue;
17058 }
17059 }
17060 };
17061 return Some(Ok(res));
17062 }
17063 Some(Err(ErrorContext::new(
17064 "OpBatchEndDoRequest",
17065 r#type.and_then(|t| OpBatchEndDoRequest::attr_from_type(t)),
17066 self.orig_loc,
17067 self.buf.as_ptr().wrapping_add(pos) as usize,
17068 )))
17069 }
17070}
17071impl std::fmt::Debug for IterableOpBatchEndDoRequest<'_> {
17072 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17073 let mut fmt = f.debug_struct("OpBatchEndDoRequest");
17074 for attr in self.clone() {
17075 let attr = match attr {
17076 Ok(a) => a,
17077 Err(err) => {
17078 fmt.finish()?;
17079 f.write_str("Err(")?;
17080 err.fmt(f)?;
17081 return f.write_str(")");
17082 }
17083 };
17084 match attr {
17085 OpBatchEndDoRequest::Genid(val) => fmt.field("Genid", &val),
17086 };
17087 }
17088 fmt.finish()
17089 }
17090}
17091impl IterableOpBatchEndDoRequest<'_> {
17092 pub fn lookup_attr(
17093 &self,
17094 offset: usize,
17095 missing_type: Option<u16>,
17096 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
17097 let mut stack = Vec::new();
17098 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
17099 if cur == offset + PushNfgenmsg::len() {
17100 stack.push(("OpBatchEndDoRequest", offset));
17101 return (
17102 stack,
17103 missing_type.and_then(|t| OpBatchEndDoRequest::attr_from_type(t)),
17104 );
17105 }
17106 if cur > offset || cur + self.buf.len() < offset {
17107 return (stack, None);
17108 }
17109 let mut attrs = self.clone();
17110 let mut last_off = cur + attrs.pos;
17111 while let Some(attr) = attrs.next() {
17112 let Ok(attr) = attr else { break };
17113 match attr {
17114 OpBatchEndDoRequest::Genid(val) => {
17115 if last_off == offset {
17116 stack.push(("Genid", last_off));
17117 break;
17118 }
17119 }
17120 _ => {}
17121 };
17122 last_off = cur + attrs.pos;
17123 }
17124 if !stack.is_empty() {
17125 stack.push(("OpBatchEndDoRequest", cur));
17126 }
17127 (stack, None)
17128 }
17129}
17130#[doc = "Finish a batch of operations"]
17131pub struct PushOpBatchEndDoReply<Prev: Rec> {
17132 pub(crate) prev: Option<Prev>,
17133 pub(crate) header_offset: Option<usize>,
17134}
17135impl<Prev: Rec> Rec for PushOpBatchEndDoReply<Prev> {
17136 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17137 self.prev.as_mut().unwrap().as_rec_mut()
17138 }
17139}
17140impl<Prev: Rec> PushOpBatchEndDoReply<Prev> {
17141 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
17142 Self::write_header(&mut prev, header);
17143 Self::new_without_header(prev)
17144 }
17145 fn new_without_header(prev: Prev) -> Self {
17146 Self {
17147 prev: Some(prev),
17148 header_offset: None,
17149 }
17150 }
17151 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
17152 prev.as_rec_mut().extend(header.as_slice());
17153 }
17154 pub fn end_nested(mut self) -> Prev {
17155 let mut prev = self.prev.take().unwrap();
17156 if let Some(header_offset) = &self.header_offset {
17157 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17158 }
17159 prev
17160 }
17161}
17162impl<Prev: Rec> Drop for PushOpBatchEndDoReply<Prev> {
17163 fn drop(&mut self) {
17164 if let Some(prev) = &mut self.prev {
17165 if let Some(header_offset) = &self.header_offset {
17166 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17167 }
17168 }
17169 }
17170}
17171#[doc = "Finish a batch of operations"]
17172#[derive(Clone)]
17173pub enum OpBatchEndDoReply {}
17174impl<'a> IterableOpBatchEndDoReply<'a> {}
17175impl OpBatchEndDoReply {
17176 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpBatchEndDoReply<'_>) {
17177 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
17178 (
17179 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
17180 IterableOpBatchEndDoReply::with_loc(attrs, buf.as_ptr() as usize),
17181 )
17182 }
17183 fn attr_from_type(r#type: u16) -> Option<&'static str> {
17184 BatchAttrs::attr_from_type(r#type)
17185 }
17186}
17187#[derive(Clone, Copy, Default)]
17188pub struct IterableOpBatchEndDoReply<'a> {
17189 buf: &'a [u8],
17190 pos: usize,
17191 orig_loc: usize,
17192}
17193impl<'a> IterableOpBatchEndDoReply<'a> {
17194 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
17195 Self {
17196 buf,
17197 pos: 0,
17198 orig_loc,
17199 }
17200 }
17201 pub fn get_buf(&self) -> &'a [u8] {
17202 self.buf
17203 }
17204}
17205impl<'a> Iterator for IterableOpBatchEndDoReply<'a> {
17206 type Item = Result<OpBatchEndDoReply, ErrorContext>;
17207 fn next(&mut self) -> Option<Self::Item> {
17208 if self.buf.len() == self.pos {
17209 return None;
17210 }
17211 let pos = self.pos;
17212 let mut r#type = None;
17213 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
17214 r#type = Some(header.r#type);
17215 let res = match header.r#type {
17216 n => {
17217 if cfg!(any(test, feature = "deny-unknown-attrs")) {
17218 break;
17219 } else {
17220 continue;
17221 }
17222 }
17223 };
17224 return Some(Ok(res));
17225 }
17226 Some(Err(ErrorContext::new(
17227 "OpBatchEndDoReply",
17228 r#type.and_then(|t| OpBatchEndDoReply::attr_from_type(t)),
17229 self.orig_loc,
17230 self.buf.as_ptr().wrapping_add(pos) as usize,
17231 )))
17232 }
17233}
17234impl std::fmt::Debug for IterableOpBatchEndDoReply<'_> {
17235 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17236 let mut fmt = f.debug_struct("OpBatchEndDoReply");
17237 for attr in self.clone() {
17238 let attr = match attr {
17239 Ok(a) => a,
17240 Err(err) => {
17241 fmt.finish()?;
17242 f.write_str("Err(")?;
17243 err.fmt(f)?;
17244 return f.write_str(")");
17245 }
17246 };
17247 match attr {};
17248 }
17249 fmt.finish()
17250 }
17251}
17252impl IterableOpBatchEndDoReply<'_> {
17253 pub fn lookup_attr(
17254 &self,
17255 offset: usize,
17256 missing_type: Option<u16>,
17257 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
17258 let mut stack = Vec::new();
17259 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
17260 if cur == offset + PushNfgenmsg::len() {
17261 stack.push(("OpBatchEndDoReply", offset));
17262 return (
17263 stack,
17264 missing_type.and_then(|t| OpBatchEndDoReply::attr_from_type(t)),
17265 );
17266 }
17267 (stack, None)
17268 }
17269}
17270#[derive(Debug)]
17271pub struct RequestOpBatchEndDoRequest<'r> {
17272 request: Request<'r>,
17273}
17274impl<'r> RequestOpBatchEndDoRequest<'r> {
17275 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
17276 PushOpBatchEndDoRequest::write_header(&mut request.buf_mut(), header);
17277 Self { request: request }
17278 }
17279 pub fn encode(&mut self) -> PushOpBatchEndDoRequest<&mut Vec<u8>> {
17280 PushOpBatchEndDoRequest::new_without_header(self.request.buf_mut())
17281 }
17282 pub fn into_encoder(self) -> PushOpBatchEndDoRequest<RequestBuf<'r>> {
17283 PushOpBatchEndDoRequest::new_without_header(self.request.buf)
17284 }
17285}
17286impl NetlinkRequest for RequestOpBatchEndDoRequest<'_> {
17287 type ReplyType<'buf> = (PushNfgenmsg, IterableOpBatchEndDoReply<'buf>);
17288 fn protocol(&self) -> Protocol {
17289 Protocol::Raw {
17290 protonum: 12u16,
17291 request_type: 17u16,
17292 }
17293 }
17294 fn flags(&self) -> u16 {
17295 self.request.flags
17296 }
17297 fn payload(&self) -> &[u8] {
17298 self.request.buf()
17299 }
17300 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
17301 OpBatchEndDoReply::new(buf)
17302 }
17303 fn lookup(
17304 buf: &[u8],
17305 offset: usize,
17306 missing_type: Option<u16>,
17307 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
17308 OpBatchEndDoRequest::new(buf)
17309 .1
17310 .lookup_attr(offset, missing_type)
17311 }
17312}
17313#[doc = "Create a new table."]
17314pub struct PushOpNewtableDoRequest<Prev: Rec> {
17315 pub(crate) prev: Option<Prev>,
17316 pub(crate) header_offset: Option<usize>,
17317}
17318impl<Prev: Rec> Rec for PushOpNewtableDoRequest<Prev> {
17319 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17320 self.prev.as_mut().unwrap().as_rec_mut()
17321 }
17322}
17323impl<Prev: Rec> PushOpNewtableDoRequest<Prev> {
17324 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
17325 Self::write_header(&mut prev, header);
17326 Self::new_without_header(prev)
17327 }
17328 fn new_without_header(prev: Prev) -> Self {
17329 Self {
17330 prev: Some(prev),
17331 header_offset: None,
17332 }
17333 }
17334 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
17335 prev.as_rec_mut().extend(header.as_slice());
17336 }
17337 pub fn end_nested(mut self) -> Prev {
17338 let mut prev = self.prev.take().unwrap();
17339 if let Some(header_offset) = &self.header_offset {
17340 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17341 }
17342 prev
17343 }
17344 #[doc = "name of the table"]
17345 pub fn push_name(mut self, value: &CStr) -> Self {
17346 push_header(
17347 self.as_rec_mut(),
17348 1u16,
17349 value.to_bytes_with_nul().len() as u16,
17350 );
17351 self.as_rec_mut().extend(value.to_bytes_with_nul());
17352 self
17353 }
17354 #[doc = "name of the table"]
17355 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
17356 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
17357 self.as_rec_mut().extend(value);
17358 self.as_rec_mut().push(0);
17359 self
17360 }
17361 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
17362 pub fn push_flags(mut self, value: u32) -> Self {
17363 push_header(self.as_rec_mut(), 2u16, 4 as u16);
17364 self.as_rec_mut().extend(value.to_be_bytes());
17365 self
17366 }
17367 #[doc = "user data"]
17368 pub fn push_userdata(mut self, value: &[u8]) -> Self {
17369 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
17370 self.as_rec_mut().extend(value);
17371 self
17372 }
17373}
17374impl<Prev: Rec> Drop for PushOpNewtableDoRequest<Prev> {
17375 fn drop(&mut self) {
17376 if let Some(prev) = &mut self.prev {
17377 if let Some(header_offset) = &self.header_offset {
17378 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17379 }
17380 }
17381 }
17382}
17383#[doc = "Create a new table."]
17384#[derive(Clone)]
17385pub enum OpNewtableDoRequest<'a> {
17386 #[doc = "name of the table"]
17387 Name(&'a CStr),
17388 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
17389 Flags(u32),
17390 #[doc = "user data"]
17391 Userdata(&'a [u8]),
17392}
17393impl<'a> IterableOpNewtableDoRequest<'a> {
17394 #[doc = "name of the table"]
17395 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
17396 let mut iter = self.clone();
17397 iter.pos = 0;
17398 for attr in iter {
17399 if let OpNewtableDoRequest::Name(val) = attr? {
17400 return Ok(val);
17401 }
17402 }
17403 Err(ErrorContext::new_missing(
17404 "OpNewtableDoRequest",
17405 "Name",
17406 self.orig_loc,
17407 self.buf.as_ptr() as usize,
17408 ))
17409 }
17410 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
17411 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
17412 let mut iter = self.clone();
17413 iter.pos = 0;
17414 for attr in iter {
17415 if let OpNewtableDoRequest::Flags(val) = attr? {
17416 return Ok(val);
17417 }
17418 }
17419 Err(ErrorContext::new_missing(
17420 "OpNewtableDoRequest",
17421 "Flags",
17422 self.orig_loc,
17423 self.buf.as_ptr() as usize,
17424 ))
17425 }
17426 #[doc = "user data"]
17427 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
17428 let mut iter = self.clone();
17429 iter.pos = 0;
17430 for attr in iter {
17431 if let OpNewtableDoRequest::Userdata(val) = attr? {
17432 return Ok(val);
17433 }
17434 }
17435 Err(ErrorContext::new_missing(
17436 "OpNewtableDoRequest",
17437 "Userdata",
17438 self.orig_loc,
17439 self.buf.as_ptr() as usize,
17440 ))
17441 }
17442}
17443impl<'a> OpNewtableDoRequest<'a> {
17444 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpNewtableDoRequest<'a>) {
17445 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
17446 (
17447 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
17448 IterableOpNewtableDoRequest::with_loc(attrs, buf.as_ptr() as usize),
17449 )
17450 }
17451 fn attr_from_type(r#type: u16) -> Option<&'static str> {
17452 TableAttrs::attr_from_type(r#type)
17453 }
17454}
17455#[derive(Clone, Copy, Default)]
17456pub struct IterableOpNewtableDoRequest<'a> {
17457 buf: &'a [u8],
17458 pos: usize,
17459 orig_loc: usize,
17460}
17461impl<'a> IterableOpNewtableDoRequest<'a> {
17462 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
17463 Self {
17464 buf,
17465 pos: 0,
17466 orig_loc,
17467 }
17468 }
17469 pub fn get_buf(&self) -> &'a [u8] {
17470 self.buf
17471 }
17472}
17473impl<'a> Iterator for IterableOpNewtableDoRequest<'a> {
17474 type Item = Result<OpNewtableDoRequest<'a>, ErrorContext>;
17475 fn next(&mut self) -> Option<Self::Item> {
17476 if self.buf.len() == self.pos {
17477 return None;
17478 }
17479 let pos = self.pos;
17480 let mut r#type = None;
17481 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
17482 r#type = Some(header.r#type);
17483 let res = match header.r#type {
17484 1u16 => OpNewtableDoRequest::Name({
17485 let res = CStr::from_bytes_with_nul(next).ok();
17486 let Some(val) = res else { break };
17487 val
17488 }),
17489 2u16 => OpNewtableDoRequest::Flags({
17490 let res = parse_be_u32(next);
17491 let Some(val) = res else { break };
17492 val
17493 }),
17494 6u16 => OpNewtableDoRequest::Userdata({
17495 let res = Some(next);
17496 let Some(val) = res else { break };
17497 val
17498 }),
17499 n => {
17500 if cfg!(any(test, feature = "deny-unknown-attrs")) {
17501 break;
17502 } else {
17503 continue;
17504 }
17505 }
17506 };
17507 return Some(Ok(res));
17508 }
17509 Some(Err(ErrorContext::new(
17510 "OpNewtableDoRequest",
17511 r#type.and_then(|t| OpNewtableDoRequest::attr_from_type(t)),
17512 self.orig_loc,
17513 self.buf.as_ptr().wrapping_add(pos) as usize,
17514 )))
17515 }
17516}
17517impl<'a> std::fmt::Debug for IterableOpNewtableDoRequest<'_> {
17518 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17519 let mut fmt = f.debug_struct("OpNewtableDoRequest");
17520 for attr in self.clone() {
17521 let attr = match attr {
17522 Ok(a) => a,
17523 Err(err) => {
17524 fmt.finish()?;
17525 f.write_str("Err(")?;
17526 err.fmt(f)?;
17527 return f.write_str(")");
17528 }
17529 };
17530 match attr {
17531 OpNewtableDoRequest::Name(val) => fmt.field("Name", &val),
17532 OpNewtableDoRequest::Flags(val) => {
17533 fmt.field("Flags", &FormatFlags(val.into(), TableFlags::from_value))
17534 }
17535 OpNewtableDoRequest::Userdata(val) => fmt.field("Userdata", &val),
17536 };
17537 }
17538 fmt.finish()
17539 }
17540}
17541impl IterableOpNewtableDoRequest<'_> {
17542 pub fn lookup_attr(
17543 &self,
17544 offset: usize,
17545 missing_type: Option<u16>,
17546 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
17547 let mut stack = Vec::new();
17548 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
17549 if cur == offset + PushNfgenmsg::len() {
17550 stack.push(("OpNewtableDoRequest", offset));
17551 return (
17552 stack,
17553 missing_type.and_then(|t| OpNewtableDoRequest::attr_from_type(t)),
17554 );
17555 }
17556 if cur > offset || cur + self.buf.len() < offset {
17557 return (stack, None);
17558 }
17559 let mut attrs = self.clone();
17560 let mut last_off = cur + attrs.pos;
17561 while let Some(attr) = attrs.next() {
17562 let Ok(attr) = attr else { break };
17563 match attr {
17564 OpNewtableDoRequest::Name(val) => {
17565 if last_off == offset {
17566 stack.push(("Name", last_off));
17567 break;
17568 }
17569 }
17570 OpNewtableDoRequest::Flags(val) => {
17571 if last_off == offset {
17572 stack.push(("Flags", last_off));
17573 break;
17574 }
17575 }
17576 OpNewtableDoRequest::Userdata(val) => {
17577 if last_off == offset {
17578 stack.push(("Userdata", last_off));
17579 break;
17580 }
17581 }
17582 _ => {}
17583 };
17584 last_off = cur + attrs.pos;
17585 }
17586 if !stack.is_empty() {
17587 stack.push(("OpNewtableDoRequest", cur));
17588 }
17589 (stack, None)
17590 }
17591}
17592#[doc = "Create a new table."]
17593pub struct PushOpNewtableDoReply<Prev: Rec> {
17594 pub(crate) prev: Option<Prev>,
17595 pub(crate) header_offset: Option<usize>,
17596}
17597impl<Prev: Rec> Rec for PushOpNewtableDoReply<Prev> {
17598 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17599 self.prev.as_mut().unwrap().as_rec_mut()
17600 }
17601}
17602impl<Prev: Rec> PushOpNewtableDoReply<Prev> {
17603 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
17604 Self::write_header(&mut prev, header);
17605 Self::new_without_header(prev)
17606 }
17607 fn new_without_header(prev: Prev) -> Self {
17608 Self {
17609 prev: Some(prev),
17610 header_offset: None,
17611 }
17612 }
17613 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
17614 prev.as_rec_mut().extend(header.as_slice());
17615 }
17616 pub fn end_nested(mut self) -> Prev {
17617 let mut prev = self.prev.take().unwrap();
17618 if let Some(header_offset) = &self.header_offset {
17619 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17620 }
17621 prev
17622 }
17623}
17624impl<Prev: Rec> Drop for PushOpNewtableDoReply<Prev> {
17625 fn drop(&mut self) {
17626 if let Some(prev) = &mut self.prev {
17627 if let Some(header_offset) = &self.header_offset {
17628 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17629 }
17630 }
17631 }
17632}
17633#[doc = "Create a new table."]
17634#[derive(Clone)]
17635pub enum OpNewtableDoReply {}
17636impl<'a> IterableOpNewtableDoReply<'a> {}
17637impl OpNewtableDoReply {
17638 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpNewtableDoReply<'_>) {
17639 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
17640 (
17641 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
17642 IterableOpNewtableDoReply::with_loc(attrs, buf.as_ptr() as usize),
17643 )
17644 }
17645 fn attr_from_type(r#type: u16) -> Option<&'static str> {
17646 TableAttrs::attr_from_type(r#type)
17647 }
17648}
17649#[derive(Clone, Copy, Default)]
17650pub struct IterableOpNewtableDoReply<'a> {
17651 buf: &'a [u8],
17652 pos: usize,
17653 orig_loc: usize,
17654}
17655impl<'a> IterableOpNewtableDoReply<'a> {
17656 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
17657 Self {
17658 buf,
17659 pos: 0,
17660 orig_loc,
17661 }
17662 }
17663 pub fn get_buf(&self) -> &'a [u8] {
17664 self.buf
17665 }
17666}
17667impl<'a> Iterator for IterableOpNewtableDoReply<'a> {
17668 type Item = Result<OpNewtableDoReply, ErrorContext>;
17669 fn next(&mut self) -> Option<Self::Item> {
17670 if self.buf.len() == self.pos {
17671 return None;
17672 }
17673 let pos = self.pos;
17674 let mut r#type = None;
17675 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
17676 r#type = Some(header.r#type);
17677 let res = match header.r#type {
17678 n => {
17679 if cfg!(any(test, feature = "deny-unknown-attrs")) {
17680 break;
17681 } else {
17682 continue;
17683 }
17684 }
17685 };
17686 return Some(Ok(res));
17687 }
17688 Some(Err(ErrorContext::new(
17689 "OpNewtableDoReply",
17690 r#type.and_then(|t| OpNewtableDoReply::attr_from_type(t)),
17691 self.orig_loc,
17692 self.buf.as_ptr().wrapping_add(pos) as usize,
17693 )))
17694 }
17695}
17696impl std::fmt::Debug for IterableOpNewtableDoReply<'_> {
17697 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17698 let mut fmt = f.debug_struct("OpNewtableDoReply");
17699 for attr in self.clone() {
17700 let attr = match attr {
17701 Ok(a) => a,
17702 Err(err) => {
17703 fmt.finish()?;
17704 f.write_str("Err(")?;
17705 err.fmt(f)?;
17706 return f.write_str(")");
17707 }
17708 };
17709 match attr {};
17710 }
17711 fmt.finish()
17712 }
17713}
17714impl IterableOpNewtableDoReply<'_> {
17715 pub fn lookup_attr(
17716 &self,
17717 offset: usize,
17718 missing_type: Option<u16>,
17719 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
17720 let mut stack = Vec::new();
17721 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
17722 if cur == offset + PushNfgenmsg::len() {
17723 stack.push(("OpNewtableDoReply", offset));
17724 return (
17725 stack,
17726 missing_type.and_then(|t| OpNewtableDoReply::attr_from_type(t)),
17727 );
17728 }
17729 (stack, None)
17730 }
17731}
17732#[derive(Debug)]
17733pub struct RequestOpNewtableDoRequest<'r> {
17734 request: Request<'r>,
17735}
17736impl<'r> RequestOpNewtableDoRequest<'r> {
17737 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
17738 PushOpNewtableDoRequest::write_header(&mut request.buf_mut(), header);
17739 Self { request: request }
17740 }
17741 pub fn encode(&mut self) -> PushOpNewtableDoRequest<&mut Vec<u8>> {
17742 PushOpNewtableDoRequest::new_without_header(self.request.buf_mut())
17743 }
17744 pub fn into_encoder(self) -> PushOpNewtableDoRequest<RequestBuf<'r>> {
17745 PushOpNewtableDoRequest::new_without_header(self.request.buf)
17746 }
17747}
17748impl NetlinkRequest for RequestOpNewtableDoRequest<'_> {
17749 type ReplyType<'buf> = (PushNfgenmsg, IterableOpNewtableDoReply<'buf>);
17750 fn protocol(&self) -> Protocol {
17751 Protocol::Raw {
17752 protonum: 12u16,
17753 request_type: 2560u16,
17754 }
17755 }
17756 fn flags(&self) -> u16 {
17757 self.request.flags
17758 }
17759 fn payload(&self) -> &[u8] {
17760 self.request.buf()
17761 }
17762 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
17763 OpNewtableDoReply::new(buf)
17764 }
17765 fn lookup(
17766 buf: &[u8],
17767 offset: usize,
17768 missing_type: Option<u16>,
17769 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
17770 OpNewtableDoRequest::new(buf)
17771 .1
17772 .lookup_attr(offset, missing_type)
17773 }
17774}
17775#[doc = "Get / dump tables."]
17776pub struct PushOpGettableDumpRequest<Prev: Rec> {
17777 pub(crate) prev: Option<Prev>,
17778 pub(crate) header_offset: Option<usize>,
17779}
17780impl<Prev: Rec> Rec for PushOpGettableDumpRequest<Prev> {
17781 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17782 self.prev.as_mut().unwrap().as_rec_mut()
17783 }
17784}
17785impl<Prev: Rec> PushOpGettableDumpRequest<Prev> {
17786 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
17787 Self::write_header(&mut prev, header);
17788 Self::new_without_header(prev)
17789 }
17790 fn new_without_header(prev: Prev) -> Self {
17791 Self {
17792 prev: Some(prev),
17793 header_offset: None,
17794 }
17795 }
17796 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
17797 prev.as_rec_mut().extend(header.as_slice());
17798 }
17799 pub fn end_nested(mut self) -> Prev {
17800 let mut prev = self.prev.take().unwrap();
17801 if let Some(header_offset) = &self.header_offset {
17802 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17803 }
17804 prev
17805 }
17806}
17807impl<Prev: Rec> Drop for PushOpGettableDumpRequest<Prev> {
17808 fn drop(&mut self) {
17809 if let Some(prev) = &mut self.prev {
17810 if let Some(header_offset) = &self.header_offset {
17811 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17812 }
17813 }
17814 }
17815}
17816#[doc = "Get / dump tables."]
17817#[derive(Clone)]
17818pub enum OpGettableDumpRequest {}
17819impl<'a> IterableOpGettableDumpRequest<'a> {}
17820impl OpGettableDumpRequest {
17821 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpGettableDumpRequest<'_>) {
17822 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
17823 (
17824 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
17825 IterableOpGettableDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
17826 )
17827 }
17828 fn attr_from_type(r#type: u16) -> Option<&'static str> {
17829 TableAttrs::attr_from_type(r#type)
17830 }
17831}
17832#[derive(Clone, Copy, Default)]
17833pub struct IterableOpGettableDumpRequest<'a> {
17834 buf: &'a [u8],
17835 pos: usize,
17836 orig_loc: usize,
17837}
17838impl<'a> IterableOpGettableDumpRequest<'a> {
17839 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
17840 Self {
17841 buf,
17842 pos: 0,
17843 orig_loc,
17844 }
17845 }
17846 pub fn get_buf(&self) -> &'a [u8] {
17847 self.buf
17848 }
17849}
17850impl<'a> Iterator for IterableOpGettableDumpRequest<'a> {
17851 type Item = Result<OpGettableDumpRequest, ErrorContext>;
17852 fn next(&mut self) -> Option<Self::Item> {
17853 if self.buf.len() == self.pos {
17854 return None;
17855 }
17856 let pos = self.pos;
17857 let mut r#type = None;
17858 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
17859 r#type = Some(header.r#type);
17860 let res = match header.r#type {
17861 n => {
17862 if cfg!(any(test, feature = "deny-unknown-attrs")) {
17863 break;
17864 } else {
17865 continue;
17866 }
17867 }
17868 };
17869 return Some(Ok(res));
17870 }
17871 Some(Err(ErrorContext::new(
17872 "OpGettableDumpRequest",
17873 r#type.and_then(|t| OpGettableDumpRequest::attr_from_type(t)),
17874 self.orig_loc,
17875 self.buf.as_ptr().wrapping_add(pos) as usize,
17876 )))
17877 }
17878}
17879impl std::fmt::Debug for IterableOpGettableDumpRequest<'_> {
17880 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17881 let mut fmt = f.debug_struct("OpGettableDumpRequest");
17882 for attr in self.clone() {
17883 let attr = match attr {
17884 Ok(a) => a,
17885 Err(err) => {
17886 fmt.finish()?;
17887 f.write_str("Err(")?;
17888 err.fmt(f)?;
17889 return f.write_str(")");
17890 }
17891 };
17892 match attr {};
17893 }
17894 fmt.finish()
17895 }
17896}
17897impl IterableOpGettableDumpRequest<'_> {
17898 pub fn lookup_attr(
17899 &self,
17900 offset: usize,
17901 missing_type: Option<u16>,
17902 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
17903 let mut stack = Vec::new();
17904 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
17905 if cur == offset + PushNfgenmsg::len() {
17906 stack.push(("OpGettableDumpRequest", offset));
17907 return (
17908 stack,
17909 missing_type.and_then(|t| OpGettableDumpRequest::attr_from_type(t)),
17910 );
17911 }
17912 (stack, None)
17913 }
17914}
17915#[doc = "Get / dump tables."]
17916pub struct PushOpGettableDumpReply<Prev: Rec> {
17917 pub(crate) prev: Option<Prev>,
17918 pub(crate) header_offset: Option<usize>,
17919}
17920impl<Prev: Rec> Rec for PushOpGettableDumpReply<Prev> {
17921 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
17922 self.prev.as_mut().unwrap().as_rec_mut()
17923 }
17924}
17925impl<Prev: Rec> PushOpGettableDumpReply<Prev> {
17926 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
17927 Self::write_header(&mut prev, header);
17928 Self::new_without_header(prev)
17929 }
17930 fn new_without_header(prev: Prev) -> Self {
17931 Self {
17932 prev: Some(prev),
17933 header_offset: None,
17934 }
17935 }
17936 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
17937 prev.as_rec_mut().extend(header.as_slice());
17938 }
17939 pub fn end_nested(mut self) -> Prev {
17940 let mut prev = self.prev.take().unwrap();
17941 if let Some(header_offset) = &self.header_offset {
17942 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17943 }
17944 prev
17945 }
17946 #[doc = "name of the table"]
17947 pub fn push_name(mut self, value: &CStr) -> Self {
17948 push_header(
17949 self.as_rec_mut(),
17950 1u16,
17951 value.to_bytes_with_nul().len() as u16,
17952 );
17953 self.as_rec_mut().extend(value.to_bytes_with_nul());
17954 self
17955 }
17956 #[doc = "name of the table"]
17957 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
17958 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
17959 self.as_rec_mut().extend(value);
17960 self.as_rec_mut().push(0);
17961 self
17962 }
17963 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
17964 pub fn push_flags(mut self, value: u32) -> Self {
17965 push_header(self.as_rec_mut(), 2u16, 4 as u16);
17966 self.as_rec_mut().extend(value.to_be_bytes());
17967 self
17968 }
17969 #[doc = "number of chains in this table"]
17970 pub fn push_use(mut self, value: u32) -> Self {
17971 push_header(self.as_rec_mut(), 3u16, 4 as u16);
17972 self.as_rec_mut().extend(value.to_be_bytes());
17973 self
17974 }
17975 #[doc = "numeric handle of the table"]
17976 pub fn push_handle(mut self, value: u64) -> Self {
17977 push_header(self.as_rec_mut(), 4u16, 8 as u16);
17978 self.as_rec_mut().extend(value.to_be_bytes());
17979 self
17980 }
17981 #[doc = "user data"]
17982 pub fn push_userdata(mut self, value: &[u8]) -> Self {
17983 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
17984 self.as_rec_mut().extend(value);
17985 self
17986 }
17987 #[doc = "owner of this table through netlink portID"]
17988 pub fn push_owner(mut self, value: u32) -> Self {
17989 push_header(self.as_rec_mut(), 7u16, 4 as u16);
17990 self.as_rec_mut().extend(value.to_be_bytes());
17991 self
17992 }
17993}
17994impl<Prev: Rec> Drop for PushOpGettableDumpReply<Prev> {
17995 fn drop(&mut self) {
17996 if let Some(prev) = &mut self.prev {
17997 if let Some(header_offset) = &self.header_offset {
17998 finalize_nested_header(prev.as_rec_mut(), *header_offset);
17999 }
18000 }
18001 }
18002}
18003#[doc = "Get / dump tables."]
18004#[derive(Clone)]
18005pub enum OpGettableDumpReply<'a> {
18006 #[doc = "name of the table"]
18007 Name(&'a CStr),
18008 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
18009 Flags(u32),
18010 #[doc = "number of chains in this table"]
18011 Use(u32),
18012 #[doc = "numeric handle of the table"]
18013 Handle(u64),
18014 #[doc = "user data"]
18015 Userdata(&'a [u8]),
18016 #[doc = "owner of this table through netlink portID"]
18017 Owner(u32),
18018}
18019impl<'a> IterableOpGettableDumpReply<'a> {
18020 #[doc = "name of the table"]
18021 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
18022 let mut iter = self.clone();
18023 iter.pos = 0;
18024 for attr in iter {
18025 if let OpGettableDumpReply::Name(val) = attr? {
18026 return Ok(val);
18027 }
18028 }
18029 Err(ErrorContext::new_missing(
18030 "OpGettableDumpReply",
18031 "Name",
18032 self.orig_loc,
18033 self.buf.as_ptr() as usize,
18034 ))
18035 }
18036 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
18037 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
18038 let mut iter = self.clone();
18039 iter.pos = 0;
18040 for attr in iter {
18041 if let OpGettableDumpReply::Flags(val) = attr? {
18042 return Ok(val);
18043 }
18044 }
18045 Err(ErrorContext::new_missing(
18046 "OpGettableDumpReply",
18047 "Flags",
18048 self.orig_loc,
18049 self.buf.as_ptr() as usize,
18050 ))
18051 }
18052 #[doc = "number of chains in this table"]
18053 pub fn get_use(&self) -> Result<u32, ErrorContext> {
18054 let mut iter = self.clone();
18055 iter.pos = 0;
18056 for attr in iter {
18057 if let OpGettableDumpReply::Use(val) = attr? {
18058 return Ok(val);
18059 }
18060 }
18061 Err(ErrorContext::new_missing(
18062 "OpGettableDumpReply",
18063 "Use",
18064 self.orig_loc,
18065 self.buf.as_ptr() as usize,
18066 ))
18067 }
18068 #[doc = "numeric handle of the table"]
18069 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
18070 let mut iter = self.clone();
18071 iter.pos = 0;
18072 for attr in iter {
18073 if let OpGettableDumpReply::Handle(val) = attr? {
18074 return Ok(val);
18075 }
18076 }
18077 Err(ErrorContext::new_missing(
18078 "OpGettableDumpReply",
18079 "Handle",
18080 self.orig_loc,
18081 self.buf.as_ptr() as usize,
18082 ))
18083 }
18084 #[doc = "user data"]
18085 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
18086 let mut iter = self.clone();
18087 iter.pos = 0;
18088 for attr in iter {
18089 if let OpGettableDumpReply::Userdata(val) = attr? {
18090 return Ok(val);
18091 }
18092 }
18093 Err(ErrorContext::new_missing(
18094 "OpGettableDumpReply",
18095 "Userdata",
18096 self.orig_loc,
18097 self.buf.as_ptr() as usize,
18098 ))
18099 }
18100 #[doc = "owner of this table through netlink portID"]
18101 pub fn get_owner(&self) -> Result<u32, ErrorContext> {
18102 let mut iter = self.clone();
18103 iter.pos = 0;
18104 for attr in iter {
18105 if let OpGettableDumpReply::Owner(val) = attr? {
18106 return Ok(val);
18107 }
18108 }
18109 Err(ErrorContext::new_missing(
18110 "OpGettableDumpReply",
18111 "Owner",
18112 self.orig_loc,
18113 self.buf.as_ptr() as usize,
18114 ))
18115 }
18116}
18117impl<'a> OpGettableDumpReply<'a> {
18118 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGettableDumpReply<'a>) {
18119 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
18120 (
18121 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
18122 IterableOpGettableDumpReply::with_loc(attrs, buf.as_ptr() as usize),
18123 )
18124 }
18125 fn attr_from_type(r#type: u16) -> Option<&'static str> {
18126 TableAttrs::attr_from_type(r#type)
18127 }
18128}
18129#[derive(Clone, Copy, Default)]
18130pub struct IterableOpGettableDumpReply<'a> {
18131 buf: &'a [u8],
18132 pos: usize,
18133 orig_loc: usize,
18134}
18135impl<'a> IterableOpGettableDumpReply<'a> {
18136 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
18137 Self {
18138 buf,
18139 pos: 0,
18140 orig_loc,
18141 }
18142 }
18143 pub fn get_buf(&self) -> &'a [u8] {
18144 self.buf
18145 }
18146}
18147impl<'a> Iterator for IterableOpGettableDumpReply<'a> {
18148 type Item = Result<OpGettableDumpReply<'a>, ErrorContext>;
18149 fn next(&mut self) -> Option<Self::Item> {
18150 if self.buf.len() == self.pos {
18151 return None;
18152 }
18153 let pos = self.pos;
18154 let mut r#type = None;
18155 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
18156 r#type = Some(header.r#type);
18157 let res = match header.r#type {
18158 1u16 => OpGettableDumpReply::Name({
18159 let res = CStr::from_bytes_with_nul(next).ok();
18160 let Some(val) = res else { break };
18161 val
18162 }),
18163 2u16 => OpGettableDumpReply::Flags({
18164 let res = parse_be_u32(next);
18165 let Some(val) = res else { break };
18166 val
18167 }),
18168 3u16 => OpGettableDumpReply::Use({
18169 let res = parse_be_u32(next);
18170 let Some(val) = res else { break };
18171 val
18172 }),
18173 4u16 => OpGettableDumpReply::Handle({
18174 let res = parse_be_u64(next);
18175 let Some(val) = res else { break };
18176 val
18177 }),
18178 6u16 => OpGettableDumpReply::Userdata({
18179 let res = Some(next);
18180 let Some(val) = res else { break };
18181 val
18182 }),
18183 7u16 => OpGettableDumpReply::Owner({
18184 let res = parse_be_u32(next);
18185 let Some(val) = res else { break };
18186 val
18187 }),
18188 n => {
18189 if cfg!(any(test, feature = "deny-unknown-attrs")) {
18190 break;
18191 } else {
18192 continue;
18193 }
18194 }
18195 };
18196 return Some(Ok(res));
18197 }
18198 Some(Err(ErrorContext::new(
18199 "OpGettableDumpReply",
18200 r#type.and_then(|t| OpGettableDumpReply::attr_from_type(t)),
18201 self.orig_loc,
18202 self.buf.as_ptr().wrapping_add(pos) as usize,
18203 )))
18204 }
18205}
18206impl<'a> std::fmt::Debug for IterableOpGettableDumpReply<'_> {
18207 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18208 let mut fmt = f.debug_struct("OpGettableDumpReply");
18209 for attr in self.clone() {
18210 let attr = match attr {
18211 Ok(a) => a,
18212 Err(err) => {
18213 fmt.finish()?;
18214 f.write_str("Err(")?;
18215 err.fmt(f)?;
18216 return f.write_str(")");
18217 }
18218 };
18219 match attr {
18220 OpGettableDumpReply::Name(val) => fmt.field("Name", &val),
18221 OpGettableDumpReply::Flags(val) => {
18222 fmt.field("Flags", &FormatFlags(val.into(), TableFlags::from_value))
18223 }
18224 OpGettableDumpReply::Use(val) => fmt.field("Use", &val),
18225 OpGettableDumpReply::Handle(val) => fmt.field("Handle", &val),
18226 OpGettableDumpReply::Userdata(val) => fmt.field("Userdata", &val),
18227 OpGettableDumpReply::Owner(val) => fmt.field("Owner", &val),
18228 };
18229 }
18230 fmt.finish()
18231 }
18232}
18233impl IterableOpGettableDumpReply<'_> {
18234 pub fn lookup_attr(
18235 &self,
18236 offset: usize,
18237 missing_type: Option<u16>,
18238 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
18239 let mut stack = Vec::new();
18240 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
18241 if cur == offset + PushNfgenmsg::len() {
18242 stack.push(("OpGettableDumpReply", offset));
18243 return (
18244 stack,
18245 missing_type.and_then(|t| OpGettableDumpReply::attr_from_type(t)),
18246 );
18247 }
18248 if cur > offset || cur + self.buf.len() < offset {
18249 return (stack, None);
18250 }
18251 let mut attrs = self.clone();
18252 let mut last_off = cur + attrs.pos;
18253 while let Some(attr) = attrs.next() {
18254 let Ok(attr) = attr else { break };
18255 match attr {
18256 OpGettableDumpReply::Name(val) => {
18257 if last_off == offset {
18258 stack.push(("Name", last_off));
18259 break;
18260 }
18261 }
18262 OpGettableDumpReply::Flags(val) => {
18263 if last_off == offset {
18264 stack.push(("Flags", last_off));
18265 break;
18266 }
18267 }
18268 OpGettableDumpReply::Use(val) => {
18269 if last_off == offset {
18270 stack.push(("Use", last_off));
18271 break;
18272 }
18273 }
18274 OpGettableDumpReply::Handle(val) => {
18275 if last_off == offset {
18276 stack.push(("Handle", last_off));
18277 break;
18278 }
18279 }
18280 OpGettableDumpReply::Userdata(val) => {
18281 if last_off == offset {
18282 stack.push(("Userdata", last_off));
18283 break;
18284 }
18285 }
18286 OpGettableDumpReply::Owner(val) => {
18287 if last_off == offset {
18288 stack.push(("Owner", last_off));
18289 break;
18290 }
18291 }
18292 _ => {}
18293 };
18294 last_off = cur + attrs.pos;
18295 }
18296 if !stack.is_empty() {
18297 stack.push(("OpGettableDumpReply", cur));
18298 }
18299 (stack, None)
18300 }
18301}
18302#[derive(Debug)]
18303pub struct RequestOpGettableDumpRequest<'r> {
18304 request: Request<'r>,
18305}
18306impl<'r> RequestOpGettableDumpRequest<'r> {
18307 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
18308 PushOpGettableDumpRequest::write_header(&mut request.buf_mut(), header);
18309 Self {
18310 request: request.set_dump(),
18311 }
18312 }
18313 pub fn encode(&mut self) -> PushOpGettableDumpRequest<&mut Vec<u8>> {
18314 PushOpGettableDumpRequest::new_without_header(self.request.buf_mut())
18315 }
18316 pub fn into_encoder(self) -> PushOpGettableDumpRequest<RequestBuf<'r>> {
18317 PushOpGettableDumpRequest::new_without_header(self.request.buf)
18318 }
18319}
18320impl NetlinkRequest for RequestOpGettableDumpRequest<'_> {
18321 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGettableDumpReply<'buf>);
18322 fn protocol(&self) -> Protocol {
18323 Protocol::Raw {
18324 protonum: 12u16,
18325 request_type: 2561u16,
18326 }
18327 }
18328 fn flags(&self) -> u16 {
18329 self.request.flags
18330 }
18331 fn payload(&self) -> &[u8] {
18332 self.request.buf()
18333 }
18334 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
18335 OpGettableDumpReply::new(buf)
18336 }
18337 fn lookup(
18338 buf: &[u8],
18339 offset: usize,
18340 missing_type: Option<u16>,
18341 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
18342 OpGettableDumpRequest::new(buf)
18343 .1
18344 .lookup_attr(offset, missing_type)
18345 }
18346}
18347#[doc = "Get / dump tables."]
18348pub struct PushOpGettableDoRequest<Prev: Rec> {
18349 pub(crate) prev: Option<Prev>,
18350 pub(crate) header_offset: Option<usize>,
18351}
18352impl<Prev: Rec> Rec for PushOpGettableDoRequest<Prev> {
18353 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18354 self.prev.as_mut().unwrap().as_rec_mut()
18355 }
18356}
18357impl<Prev: Rec> PushOpGettableDoRequest<Prev> {
18358 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
18359 Self::write_header(&mut prev, header);
18360 Self::new_without_header(prev)
18361 }
18362 fn new_without_header(prev: Prev) -> Self {
18363 Self {
18364 prev: Some(prev),
18365 header_offset: None,
18366 }
18367 }
18368 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
18369 prev.as_rec_mut().extend(header.as_slice());
18370 }
18371 pub fn end_nested(mut self) -> Prev {
18372 let mut prev = self.prev.take().unwrap();
18373 if let Some(header_offset) = &self.header_offset {
18374 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18375 }
18376 prev
18377 }
18378 #[doc = "name of the table"]
18379 pub fn push_name(mut self, value: &CStr) -> Self {
18380 push_header(
18381 self.as_rec_mut(),
18382 1u16,
18383 value.to_bytes_with_nul().len() as u16,
18384 );
18385 self.as_rec_mut().extend(value.to_bytes_with_nul());
18386 self
18387 }
18388 #[doc = "name of the table"]
18389 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
18390 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
18391 self.as_rec_mut().extend(value);
18392 self.as_rec_mut().push(0);
18393 self
18394 }
18395}
18396impl<Prev: Rec> Drop for PushOpGettableDoRequest<Prev> {
18397 fn drop(&mut self) {
18398 if let Some(prev) = &mut self.prev {
18399 if let Some(header_offset) = &self.header_offset {
18400 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18401 }
18402 }
18403 }
18404}
18405#[doc = "Get / dump tables."]
18406#[derive(Clone)]
18407pub enum OpGettableDoRequest<'a> {
18408 #[doc = "name of the table"]
18409 Name(&'a CStr),
18410}
18411impl<'a> IterableOpGettableDoRequest<'a> {
18412 #[doc = "name of the table"]
18413 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
18414 let mut iter = self.clone();
18415 iter.pos = 0;
18416 for attr in iter {
18417 if let OpGettableDoRequest::Name(val) = attr? {
18418 return Ok(val);
18419 }
18420 }
18421 Err(ErrorContext::new_missing(
18422 "OpGettableDoRequest",
18423 "Name",
18424 self.orig_loc,
18425 self.buf.as_ptr() as usize,
18426 ))
18427 }
18428}
18429impl<'a> OpGettableDoRequest<'a> {
18430 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGettableDoRequest<'a>) {
18431 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
18432 (
18433 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
18434 IterableOpGettableDoRequest::with_loc(attrs, buf.as_ptr() as usize),
18435 )
18436 }
18437 fn attr_from_type(r#type: u16) -> Option<&'static str> {
18438 TableAttrs::attr_from_type(r#type)
18439 }
18440}
18441#[derive(Clone, Copy, Default)]
18442pub struct IterableOpGettableDoRequest<'a> {
18443 buf: &'a [u8],
18444 pos: usize,
18445 orig_loc: usize,
18446}
18447impl<'a> IterableOpGettableDoRequest<'a> {
18448 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
18449 Self {
18450 buf,
18451 pos: 0,
18452 orig_loc,
18453 }
18454 }
18455 pub fn get_buf(&self) -> &'a [u8] {
18456 self.buf
18457 }
18458}
18459impl<'a> Iterator for IterableOpGettableDoRequest<'a> {
18460 type Item = Result<OpGettableDoRequest<'a>, ErrorContext>;
18461 fn next(&mut self) -> Option<Self::Item> {
18462 if self.buf.len() == self.pos {
18463 return None;
18464 }
18465 let pos = self.pos;
18466 let mut r#type = None;
18467 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
18468 r#type = Some(header.r#type);
18469 let res = match header.r#type {
18470 1u16 => OpGettableDoRequest::Name({
18471 let res = CStr::from_bytes_with_nul(next).ok();
18472 let Some(val) = res else { break };
18473 val
18474 }),
18475 n => {
18476 if cfg!(any(test, feature = "deny-unknown-attrs")) {
18477 break;
18478 } else {
18479 continue;
18480 }
18481 }
18482 };
18483 return Some(Ok(res));
18484 }
18485 Some(Err(ErrorContext::new(
18486 "OpGettableDoRequest",
18487 r#type.and_then(|t| OpGettableDoRequest::attr_from_type(t)),
18488 self.orig_loc,
18489 self.buf.as_ptr().wrapping_add(pos) as usize,
18490 )))
18491 }
18492}
18493impl<'a> std::fmt::Debug for IterableOpGettableDoRequest<'_> {
18494 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18495 let mut fmt = f.debug_struct("OpGettableDoRequest");
18496 for attr in self.clone() {
18497 let attr = match attr {
18498 Ok(a) => a,
18499 Err(err) => {
18500 fmt.finish()?;
18501 f.write_str("Err(")?;
18502 err.fmt(f)?;
18503 return f.write_str(")");
18504 }
18505 };
18506 match attr {
18507 OpGettableDoRequest::Name(val) => fmt.field("Name", &val),
18508 };
18509 }
18510 fmt.finish()
18511 }
18512}
18513impl IterableOpGettableDoRequest<'_> {
18514 pub fn lookup_attr(
18515 &self,
18516 offset: usize,
18517 missing_type: Option<u16>,
18518 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
18519 let mut stack = Vec::new();
18520 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
18521 if cur == offset + PushNfgenmsg::len() {
18522 stack.push(("OpGettableDoRequest", offset));
18523 return (
18524 stack,
18525 missing_type.and_then(|t| OpGettableDoRequest::attr_from_type(t)),
18526 );
18527 }
18528 if cur > offset || cur + self.buf.len() < offset {
18529 return (stack, None);
18530 }
18531 let mut attrs = self.clone();
18532 let mut last_off = cur + attrs.pos;
18533 while let Some(attr) = attrs.next() {
18534 let Ok(attr) = attr else { break };
18535 match attr {
18536 OpGettableDoRequest::Name(val) => {
18537 if last_off == offset {
18538 stack.push(("Name", last_off));
18539 break;
18540 }
18541 }
18542 _ => {}
18543 };
18544 last_off = cur + attrs.pos;
18545 }
18546 if !stack.is_empty() {
18547 stack.push(("OpGettableDoRequest", cur));
18548 }
18549 (stack, None)
18550 }
18551}
18552#[doc = "Get / dump tables."]
18553pub struct PushOpGettableDoReply<Prev: Rec> {
18554 pub(crate) prev: Option<Prev>,
18555 pub(crate) header_offset: Option<usize>,
18556}
18557impl<Prev: Rec> Rec for PushOpGettableDoReply<Prev> {
18558 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18559 self.prev.as_mut().unwrap().as_rec_mut()
18560 }
18561}
18562impl<Prev: Rec> PushOpGettableDoReply<Prev> {
18563 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
18564 Self::write_header(&mut prev, header);
18565 Self::new_without_header(prev)
18566 }
18567 fn new_without_header(prev: Prev) -> Self {
18568 Self {
18569 prev: Some(prev),
18570 header_offset: None,
18571 }
18572 }
18573 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
18574 prev.as_rec_mut().extend(header.as_slice());
18575 }
18576 pub fn end_nested(mut self) -> Prev {
18577 let mut prev = self.prev.take().unwrap();
18578 if let Some(header_offset) = &self.header_offset {
18579 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18580 }
18581 prev
18582 }
18583 #[doc = "name of the table"]
18584 pub fn push_name(mut self, value: &CStr) -> Self {
18585 push_header(
18586 self.as_rec_mut(),
18587 1u16,
18588 value.to_bytes_with_nul().len() as u16,
18589 );
18590 self.as_rec_mut().extend(value.to_bytes_with_nul());
18591 self
18592 }
18593 #[doc = "name of the table"]
18594 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
18595 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
18596 self.as_rec_mut().extend(value);
18597 self.as_rec_mut().push(0);
18598 self
18599 }
18600 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
18601 pub fn push_flags(mut self, value: u32) -> Self {
18602 push_header(self.as_rec_mut(), 2u16, 4 as u16);
18603 self.as_rec_mut().extend(value.to_be_bytes());
18604 self
18605 }
18606 #[doc = "number of chains in this table"]
18607 pub fn push_use(mut self, value: u32) -> Self {
18608 push_header(self.as_rec_mut(), 3u16, 4 as u16);
18609 self.as_rec_mut().extend(value.to_be_bytes());
18610 self
18611 }
18612 #[doc = "numeric handle of the table"]
18613 pub fn push_handle(mut self, value: u64) -> Self {
18614 push_header(self.as_rec_mut(), 4u16, 8 as u16);
18615 self.as_rec_mut().extend(value.to_be_bytes());
18616 self
18617 }
18618 #[doc = "user data"]
18619 pub fn push_userdata(mut self, value: &[u8]) -> Self {
18620 push_header(self.as_rec_mut(), 6u16, value.len() as u16);
18621 self.as_rec_mut().extend(value);
18622 self
18623 }
18624 #[doc = "owner of this table through netlink portID"]
18625 pub fn push_owner(mut self, value: u32) -> Self {
18626 push_header(self.as_rec_mut(), 7u16, 4 as u16);
18627 self.as_rec_mut().extend(value.to_be_bytes());
18628 self
18629 }
18630}
18631impl<Prev: Rec> Drop for PushOpGettableDoReply<Prev> {
18632 fn drop(&mut self) {
18633 if let Some(prev) = &mut self.prev {
18634 if let Some(header_offset) = &self.header_offset {
18635 finalize_nested_header(prev.as_rec_mut(), *header_offset);
18636 }
18637 }
18638 }
18639}
18640#[doc = "Get / dump tables."]
18641#[derive(Clone)]
18642pub enum OpGettableDoReply<'a> {
18643 #[doc = "name of the table"]
18644 Name(&'a CStr),
18645 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
18646 Flags(u32),
18647 #[doc = "number of chains in this table"]
18648 Use(u32),
18649 #[doc = "numeric handle of the table"]
18650 Handle(u64),
18651 #[doc = "user data"]
18652 Userdata(&'a [u8]),
18653 #[doc = "owner of this table through netlink portID"]
18654 Owner(u32),
18655}
18656impl<'a> IterableOpGettableDoReply<'a> {
18657 #[doc = "name of the table"]
18658 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
18659 let mut iter = self.clone();
18660 iter.pos = 0;
18661 for attr in iter {
18662 if let OpGettableDoReply::Name(val) = attr? {
18663 return Ok(val);
18664 }
18665 }
18666 Err(ErrorContext::new_missing(
18667 "OpGettableDoReply",
18668 "Name",
18669 self.orig_loc,
18670 self.buf.as_ptr() as usize,
18671 ))
18672 }
18673 #[doc = "bitmask of flags\nAssociated type: \"TableFlags\" (1 bit per enumeration)"]
18674 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
18675 let mut iter = self.clone();
18676 iter.pos = 0;
18677 for attr in iter {
18678 if let OpGettableDoReply::Flags(val) = attr? {
18679 return Ok(val);
18680 }
18681 }
18682 Err(ErrorContext::new_missing(
18683 "OpGettableDoReply",
18684 "Flags",
18685 self.orig_loc,
18686 self.buf.as_ptr() as usize,
18687 ))
18688 }
18689 #[doc = "number of chains in this table"]
18690 pub fn get_use(&self) -> Result<u32, ErrorContext> {
18691 let mut iter = self.clone();
18692 iter.pos = 0;
18693 for attr in iter {
18694 if let OpGettableDoReply::Use(val) = attr? {
18695 return Ok(val);
18696 }
18697 }
18698 Err(ErrorContext::new_missing(
18699 "OpGettableDoReply",
18700 "Use",
18701 self.orig_loc,
18702 self.buf.as_ptr() as usize,
18703 ))
18704 }
18705 #[doc = "numeric handle of the table"]
18706 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
18707 let mut iter = self.clone();
18708 iter.pos = 0;
18709 for attr in iter {
18710 if let OpGettableDoReply::Handle(val) = attr? {
18711 return Ok(val);
18712 }
18713 }
18714 Err(ErrorContext::new_missing(
18715 "OpGettableDoReply",
18716 "Handle",
18717 self.orig_loc,
18718 self.buf.as_ptr() as usize,
18719 ))
18720 }
18721 #[doc = "user data"]
18722 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
18723 let mut iter = self.clone();
18724 iter.pos = 0;
18725 for attr in iter {
18726 if let OpGettableDoReply::Userdata(val) = attr? {
18727 return Ok(val);
18728 }
18729 }
18730 Err(ErrorContext::new_missing(
18731 "OpGettableDoReply",
18732 "Userdata",
18733 self.orig_loc,
18734 self.buf.as_ptr() as usize,
18735 ))
18736 }
18737 #[doc = "owner of this table through netlink portID"]
18738 pub fn get_owner(&self) -> Result<u32, ErrorContext> {
18739 let mut iter = self.clone();
18740 iter.pos = 0;
18741 for attr in iter {
18742 if let OpGettableDoReply::Owner(val) = attr? {
18743 return Ok(val);
18744 }
18745 }
18746 Err(ErrorContext::new_missing(
18747 "OpGettableDoReply",
18748 "Owner",
18749 self.orig_loc,
18750 self.buf.as_ptr() as usize,
18751 ))
18752 }
18753}
18754impl<'a> OpGettableDoReply<'a> {
18755 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGettableDoReply<'a>) {
18756 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
18757 (
18758 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
18759 IterableOpGettableDoReply::with_loc(attrs, buf.as_ptr() as usize),
18760 )
18761 }
18762 fn attr_from_type(r#type: u16) -> Option<&'static str> {
18763 TableAttrs::attr_from_type(r#type)
18764 }
18765}
18766#[derive(Clone, Copy, Default)]
18767pub struct IterableOpGettableDoReply<'a> {
18768 buf: &'a [u8],
18769 pos: usize,
18770 orig_loc: usize,
18771}
18772impl<'a> IterableOpGettableDoReply<'a> {
18773 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
18774 Self {
18775 buf,
18776 pos: 0,
18777 orig_loc,
18778 }
18779 }
18780 pub fn get_buf(&self) -> &'a [u8] {
18781 self.buf
18782 }
18783}
18784impl<'a> Iterator for IterableOpGettableDoReply<'a> {
18785 type Item = Result<OpGettableDoReply<'a>, ErrorContext>;
18786 fn next(&mut self) -> Option<Self::Item> {
18787 if self.buf.len() == self.pos {
18788 return None;
18789 }
18790 let pos = self.pos;
18791 let mut r#type = None;
18792 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
18793 r#type = Some(header.r#type);
18794 let res = match header.r#type {
18795 1u16 => OpGettableDoReply::Name({
18796 let res = CStr::from_bytes_with_nul(next).ok();
18797 let Some(val) = res else { break };
18798 val
18799 }),
18800 2u16 => OpGettableDoReply::Flags({
18801 let res = parse_be_u32(next);
18802 let Some(val) = res else { break };
18803 val
18804 }),
18805 3u16 => OpGettableDoReply::Use({
18806 let res = parse_be_u32(next);
18807 let Some(val) = res else { break };
18808 val
18809 }),
18810 4u16 => OpGettableDoReply::Handle({
18811 let res = parse_be_u64(next);
18812 let Some(val) = res else { break };
18813 val
18814 }),
18815 6u16 => OpGettableDoReply::Userdata({
18816 let res = Some(next);
18817 let Some(val) = res else { break };
18818 val
18819 }),
18820 7u16 => OpGettableDoReply::Owner({
18821 let res = parse_be_u32(next);
18822 let Some(val) = res else { break };
18823 val
18824 }),
18825 n => {
18826 if cfg!(any(test, feature = "deny-unknown-attrs")) {
18827 break;
18828 } else {
18829 continue;
18830 }
18831 }
18832 };
18833 return Some(Ok(res));
18834 }
18835 Some(Err(ErrorContext::new(
18836 "OpGettableDoReply",
18837 r#type.and_then(|t| OpGettableDoReply::attr_from_type(t)),
18838 self.orig_loc,
18839 self.buf.as_ptr().wrapping_add(pos) as usize,
18840 )))
18841 }
18842}
18843impl<'a> std::fmt::Debug for IterableOpGettableDoReply<'_> {
18844 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18845 let mut fmt = f.debug_struct("OpGettableDoReply");
18846 for attr in self.clone() {
18847 let attr = match attr {
18848 Ok(a) => a,
18849 Err(err) => {
18850 fmt.finish()?;
18851 f.write_str("Err(")?;
18852 err.fmt(f)?;
18853 return f.write_str(")");
18854 }
18855 };
18856 match attr {
18857 OpGettableDoReply::Name(val) => fmt.field("Name", &val),
18858 OpGettableDoReply::Flags(val) => {
18859 fmt.field("Flags", &FormatFlags(val.into(), TableFlags::from_value))
18860 }
18861 OpGettableDoReply::Use(val) => fmt.field("Use", &val),
18862 OpGettableDoReply::Handle(val) => fmt.field("Handle", &val),
18863 OpGettableDoReply::Userdata(val) => fmt.field("Userdata", &val),
18864 OpGettableDoReply::Owner(val) => fmt.field("Owner", &val),
18865 };
18866 }
18867 fmt.finish()
18868 }
18869}
18870impl IterableOpGettableDoReply<'_> {
18871 pub fn lookup_attr(
18872 &self,
18873 offset: usize,
18874 missing_type: Option<u16>,
18875 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
18876 let mut stack = Vec::new();
18877 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
18878 if cur == offset + PushNfgenmsg::len() {
18879 stack.push(("OpGettableDoReply", offset));
18880 return (
18881 stack,
18882 missing_type.and_then(|t| OpGettableDoReply::attr_from_type(t)),
18883 );
18884 }
18885 if cur > offset || cur + self.buf.len() < offset {
18886 return (stack, None);
18887 }
18888 let mut attrs = self.clone();
18889 let mut last_off = cur + attrs.pos;
18890 while let Some(attr) = attrs.next() {
18891 let Ok(attr) = attr else { break };
18892 match attr {
18893 OpGettableDoReply::Name(val) => {
18894 if last_off == offset {
18895 stack.push(("Name", last_off));
18896 break;
18897 }
18898 }
18899 OpGettableDoReply::Flags(val) => {
18900 if last_off == offset {
18901 stack.push(("Flags", last_off));
18902 break;
18903 }
18904 }
18905 OpGettableDoReply::Use(val) => {
18906 if last_off == offset {
18907 stack.push(("Use", last_off));
18908 break;
18909 }
18910 }
18911 OpGettableDoReply::Handle(val) => {
18912 if last_off == offset {
18913 stack.push(("Handle", last_off));
18914 break;
18915 }
18916 }
18917 OpGettableDoReply::Userdata(val) => {
18918 if last_off == offset {
18919 stack.push(("Userdata", last_off));
18920 break;
18921 }
18922 }
18923 OpGettableDoReply::Owner(val) => {
18924 if last_off == offset {
18925 stack.push(("Owner", last_off));
18926 break;
18927 }
18928 }
18929 _ => {}
18930 };
18931 last_off = cur + attrs.pos;
18932 }
18933 if !stack.is_empty() {
18934 stack.push(("OpGettableDoReply", cur));
18935 }
18936 (stack, None)
18937 }
18938}
18939#[derive(Debug)]
18940pub struct RequestOpGettableDoRequest<'r> {
18941 request: Request<'r>,
18942}
18943impl<'r> RequestOpGettableDoRequest<'r> {
18944 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
18945 PushOpGettableDoRequest::write_header(&mut request.buf_mut(), header);
18946 Self { request: request }
18947 }
18948 pub fn encode(&mut self) -> PushOpGettableDoRequest<&mut Vec<u8>> {
18949 PushOpGettableDoRequest::new_without_header(self.request.buf_mut())
18950 }
18951 pub fn into_encoder(self) -> PushOpGettableDoRequest<RequestBuf<'r>> {
18952 PushOpGettableDoRequest::new_without_header(self.request.buf)
18953 }
18954}
18955impl NetlinkRequest for RequestOpGettableDoRequest<'_> {
18956 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGettableDoReply<'buf>);
18957 fn protocol(&self) -> Protocol {
18958 Protocol::Raw {
18959 protonum: 12u16,
18960 request_type: 2561u16,
18961 }
18962 }
18963 fn flags(&self) -> u16 {
18964 self.request.flags
18965 }
18966 fn payload(&self) -> &[u8] {
18967 self.request.buf()
18968 }
18969 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
18970 OpGettableDoReply::new(buf)
18971 }
18972 fn lookup(
18973 buf: &[u8],
18974 offset: usize,
18975 missing_type: Option<u16>,
18976 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
18977 OpGettableDoRequest::new(buf)
18978 .1
18979 .lookup_attr(offset, missing_type)
18980 }
18981}
18982#[doc = "Delete an existing table."]
18983pub struct PushOpDeltableDoRequest<Prev: Rec> {
18984 pub(crate) prev: Option<Prev>,
18985 pub(crate) header_offset: Option<usize>,
18986}
18987impl<Prev: Rec> Rec for PushOpDeltableDoRequest<Prev> {
18988 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
18989 self.prev.as_mut().unwrap().as_rec_mut()
18990 }
18991}
18992impl<Prev: Rec> PushOpDeltableDoRequest<Prev> {
18993 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
18994 Self::write_header(&mut prev, header);
18995 Self::new_without_header(prev)
18996 }
18997 fn new_without_header(prev: Prev) -> Self {
18998 Self {
18999 prev: Some(prev),
19000 header_offset: None,
19001 }
19002 }
19003 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
19004 prev.as_rec_mut().extend(header.as_slice());
19005 }
19006 pub fn end_nested(mut self) -> Prev {
19007 let mut prev = self.prev.take().unwrap();
19008 if let Some(header_offset) = &self.header_offset {
19009 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19010 }
19011 prev
19012 }
19013 #[doc = "name of the table"]
19014 pub fn push_name(mut self, value: &CStr) -> Self {
19015 push_header(
19016 self.as_rec_mut(),
19017 1u16,
19018 value.to_bytes_with_nul().len() as u16,
19019 );
19020 self.as_rec_mut().extend(value.to_bytes_with_nul());
19021 self
19022 }
19023 #[doc = "name of the table"]
19024 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
19025 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
19026 self.as_rec_mut().extend(value);
19027 self.as_rec_mut().push(0);
19028 self
19029 }
19030 #[doc = "numeric handle of the table"]
19031 pub fn push_handle(mut self, value: u64) -> Self {
19032 push_header(self.as_rec_mut(), 4u16, 8 as u16);
19033 self.as_rec_mut().extend(value.to_be_bytes());
19034 self
19035 }
19036}
19037impl<Prev: Rec> Drop for PushOpDeltableDoRequest<Prev> {
19038 fn drop(&mut self) {
19039 if let Some(prev) = &mut self.prev {
19040 if let Some(header_offset) = &self.header_offset {
19041 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19042 }
19043 }
19044 }
19045}
19046#[doc = "Delete an existing table."]
19047#[derive(Clone)]
19048pub enum OpDeltableDoRequest<'a> {
19049 #[doc = "name of the table"]
19050 Name(&'a CStr),
19051 #[doc = "numeric handle of the table"]
19052 Handle(u64),
19053}
19054impl<'a> IterableOpDeltableDoRequest<'a> {
19055 #[doc = "name of the table"]
19056 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
19057 let mut iter = self.clone();
19058 iter.pos = 0;
19059 for attr in iter {
19060 if let OpDeltableDoRequest::Name(val) = attr? {
19061 return Ok(val);
19062 }
19063 }
19064 Err(ErrorContext::new_missing(
19065 "OpDeltableDoRequest",
19066 "Name",
19067 self.orig_loc,
19068 self.buf.as_ptr() as usize,
19069 ))
19070 }
19071 #[doc = "numeric handle of the table"]
19072 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
19073 let mut iter = self.clone();
19074 iter.pos = 0;
19075 for attr in iter {
19076 if let OpDeltableDoRequest::Handle(val) = attr? {
19077 return Ok(val);
19078 }
19079 }
19080 Err(ErrorContext::new_missing(
19081 "OpDeltableDoRequest",
19082 "Handle",
19083 self.orig_loc,
19084 self.buf.as_ptr() as usize,
19085 ))
19086 }
19087}
19088impl<'a> OpDeltableDoRequest<'a> {
19089 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDeltableDoRequest<'a>) {
19090 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
19091 (
19092 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
19093 IterableOpDeltableDoRequest::with_loc(attrs, buf.as_ptr() as usize),
19094 )
19095 }
19096 fn attr_from_type(r#type: u16) -> Option<&'static str> {
19097 TableAttrs::attr_from_type(r#type)
19098 }
19099}
19100#[derive(Clone, Copy, Default)]
19101pub struct IterableOpDeltableDoRequest<'a> {
19102 buf: &'a [u8],
19103 pos: usize,
19104 orig_loc: usize,
19105}
19106impl<'a> IterableOpDeltableDoRequest<'a> {
19107 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
19108 Self {
19109 buf,
19110 pos: 0,
19111 orig_loc,
19112 }
19113 }
19114 pub fn get_buf(&self) -> &'a [u8] {
19115 self.buf
19116 }
19117}
19118impl<'a> Iterator for IterableOpDeltableDoRequest<'a> {
19119 type Item = Result<OpDeltableDoRequest<'a>, ErrorContext>;
19120 fn next(&mut self) -> Option<Self::Item> {
19121 if self.buf.len() == self.pos {
19122 return None;
19123 }
19124 let pos = self.pos;
19125 let mut r#type = None;
19126 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
19127 r#type = Some(header.r#type);
19128 let res = match header.r#type {
19129 1u16 => OpDeltableDoRequest::Name({
19130 let res = CStr::from_bytes_with_nul(next).ok();
19131 let Some(val) = res else { break };
19132 val
19133 }),
19134 4u16 => OpDeltableDoRequest::Handle({
19135 let res = parse_be_u64(next);
19136 let Some(val) = res else { break };
19137 val
19138 }),
19139 n => {
19140 if cfg!(any(test, feature = "deny-unknown-attrs")) {
19141 break;
19142 } else {
19143 continue;
19144 }
19145 }
19146 };
19147 return Some(Ok(res));
19148 }
19149 Some(Err(ErrorContext::new(
19150 "OpDeltableDoRequest",
19151 r#type.and_then(|t| OpDeltableDoRequest::attr_from_type(t)),
19152 self.orig_loc,
19153 self.buf.as_ptr().wrapping_add(pos) as usize,
19154 )))
19155 }
19156}
19157impl<'a> std::fmt::Debug for IterableOpDeltableDoRequest<'_> {
19158 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19159 let mut fmt = f.debug_struct("OpDeltableDoRequest");
19160 for attr in self.clone() {
19161 let attr = match attr {
19162 Ok(a) => a,
19163 Err(err) => {
19164 fmt.finish()?;
19165 f.write_str("Err(")?;
19166 err.fmt(f)?;
19167 return f.write_str(")");
19168 }
19169 };
19170 match attr {
19171 OpDeltableDoRequest::Name(val) => fmt.field("Name", &val),
19172 OpDeltableDoRequest::Handle(val) => fmt.field("Handle", &val),
19173 };
19174 }
19175 fmt.finish()
19176 }
19177}
19178impl IterableOpDeltableDoRequest<'_> {
19179 pub fn lookup_attr(
19180 &self,
19181 offset: usize,
19182 missing_type: Option<u16>,
19183 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
19184 let mut stack = Vec::new();
19185 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
19186 if cur == offset + PushNfgenmsg::len() {
19187 stack.push(("OpDeltableDoRequest", offset));
19188 return (
19189 stack,
19190 missing_type.and_then(|t| OpDeltableDoRequest::attr_from_type(t)),
19191 );
19192 }
19193 if cur > offset || cur + self.buf.len() < offset {
19194 return (stack, None);
19195 }
19196 let mut attrs = self.clone();
19197 let mut last_off = cur + attrs.pos;
19198 while let Some(attr) = attrs.next() {
19199 let Ok(attr) = attr else { break };
19200 match attr {
19201 OpDeltableDoRequest::Name(val) => {
19202 if last_off == offset {
19203 stack.push(("Name", last_off));
19204 break;
19205 }
19206 }
19207 OpDeltableDoRequest::Handle(val) => {
19208 if last_off == offset {
19209 stack.push(("Handle", last_off));
19210 break;
19211 }
19212 }
19213 _ => {}
19214 };
19215 last_off = cur + attrs.pos;
19216 }
19217 if !stack.is_empty() {
19218 stack.push(("OpDeltableDoRequest", cur));
19219 }
19220 (stack, None)
19221 }
19222}
19223#[doc = "Delete an existing table."]
19224pub struct PushOpDeltableDoReply<Prev: Rec> {
19225 pub(crate) prev: Option<Prev>,
19226 pub(crate) header_offset: Option<usize>,
19227}
19228impl<Prev: Rec> Rec for PushOpDeltableDoReply<Prev> {
19229 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19230 self.prev.as_mut().unwrap().as_rec_mut()
19231 }
19232}
19233impl<Prev: Rec> PushOpDeltableDoReply<Prev> {
19234 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
19235 Self::write_header(&mut prev, header);
19236 Self::new_without_header(prev)
19237 }
19238 fn new_without_header(prev: Prev) -> Self {
19239 Self {
19240 prev: Some(prev),
19241 header_offset: None,
19242 }
19243 }
19244 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
19245 prev.as_rec_mut().extend(header.as_slice());
19246 }
19247 pub fn end_nested(mut self) -> Prev {
19248 let mut prev = self.prev.take().unwrap();
19249 if let Some(header_offset) = &self.header_offset {
19250 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19251 }
19252 prev
19253 }
19254}
19255impl<Prev: Rec> Drop for PushOpDeltableDoReply<Prev> {
19256 fn drop(&mut self) {
19257 if let Some(prev) = &mut self.prev {
19258 if let Some(header_offset) = &self.header_offset {
19259 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19260 }
19261 }
19262 }
19263}
19264#[doc = "Delete an existing table."]
19265#[derive(Clone)]
19266pub enum OpDeltableDoReply {}
19267impl<'a> IterableOpDeltableDoReply<'a> {}
19268impl OpDeltableDoReply {
19269 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDeltableDoReply<'_>) {
19270 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
19271 (
19272 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
19273 IterableOpDeltableDoReply::with_loc(attrs, buf.as_ptr() as usize),
19274 )
19275 }
19276 fn attr_from_type(r#type: u16) -> Option<&'static str> {
19277 TableAttrs::attr_from_type(r#type)
19278 }
19279}
19280#[derive(Clone, Copy, Default)]
19281pub struct IterableOpDeltableDoReply<'a> {
19282 buf: &'a [u8],
19283 pos: usize,
19284 orig_loc: usize,
19285}
19286impl<'a> IterableOpDeltableDoReply<'a> {
19287 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
19288 Self {
19289 buf,
19290 pos: 0,
19291 orig_loc,
19292 }
19293 }
19294 pub fn get_buf(&self) -> &'a [u8] {
19295 self.buf
19296 }
19297}
19298impl<'a> Iterator for IterableOpDeltableDoReply<'a> {
19299 type Item = Result<OpDeltableDoReply, ErrorContext>;
19300 fn next(&mut self) -> Option<Self::Item> {
19301 if self.buf.len() == self.pos {
19302 return None;
19303 }
19304 let pos = self.pos;
19305 let mut r#type = None;
19306 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
19307 r#type = Some(header.r#type);
19308 let res = match header.r#type {
19309 n => {
19310 if cfg!(any(test, feature = "deny-unknown-attrs")) {
19311 break;
19312 } else {
19313 continue;
19314 }
19315 }
19316 };
19317 return Some(Ok(res));
19318 }
19319 Some(Err(ErrorContext::new(
19320 "OpDeltableDoReply",
19321 r#type.and_then(|t| OpDeltableDoReply::attr_from_type(t)),
19322 self.orig_loc,
19323 self.buf.as_ptr().wrapping_add(pos) as usize,
19324 )))
19325 }
19326}
19327impl std::fmt::Debug for IterableOpDeltableDoReply<'_> {
19328 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19329 let mut fmt = f.debug_struct("OpDeltableDoReply");
19330 for attr in self.clone() {
19331 let attr = match attr {
19332 Ok(a) => a,
19333 Err(err) => {
19334 fmt.finish()?;
19335 f.write_str("Err(")?;
19336 err.fmt(f)?;
19337 return f.write_str(")");
19338 }
19339 };
19340 match attr {};
19341 }
19342 fmt.finish()
19343 }
19344}
19345impl IterableOpDeltableDoReply<'_> {
19346 pub fn lookup_attr(
19347 &self,
19348 offset: usize,
19349 missing_type: Option<u16>,
19350 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
19351 let mut stack = Vec::new();
19352 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
19353 if cur == offset + PushNfgenmsg::len() {
19354 stack.push(("OpDeltableDoReply", offset));
19355 return (
19356 stack,
19357 missing_type.and_then(|t| OpDeltableDoReply::attr_from_type(t)),
19358 );
19359 }
19360 (stack, None)
19361 }
19362}
19363#[derive(Debug)]
19364pub struct RequestOpDeltableDoRequest<'r> {
19365 request: Request<'r>,
19366}
19367impl<'r> RequestOpDeltableDoRequest<'r> {
19368 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
19369 PushOpDeltableDoRequest::write_header(&mut request.buf_mut(), header);
19370 Self { request: request }
19371 }
19372 pub fn encode(&mut self) -> PushOpDeltableDoRequest<&mut Vec<u8>> {
19373 PushOpDeltableDoRequest::new_without_header(self.request.buf_mut())
19374 }
19375 pub fn into_encoder(self) -> PushOpDeltableDoRequest<RequestBuf<'r>> {
19376 PushOpDeltableDoRequest::new_without_header(self.request.buf)
19377 }
19378}
19379impl NetlinkRequest for RequestOpDeltableDoRequest<'_> {
19380 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDeltableDoReply<'buf>);
19381 fn protocol(&self) -> Protocol {
19382 Protocol::Raw {
19383 protonum: 12u16,
19384 request_type: 2562u16,
19385 }
19386 }
19387 fn flags(&self) -> u16 {
19388 self.request.flags
19389 }
19390 fn payload(&self) -> &[u8] {
19391 self.request.buf()
19392 }
19393 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
19394 OpDeltableDoReply::new(buf)
19395 }
19396 fn lookup(
19397 buf: &[u8],
19398 offset: usize,
19399 missing_type: Option<u16>,
19400 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
19401 OpDeltableDoRequest::new(buf)
19402 .1
19403 .lookup_attr(offset, missing_type)
19404 }
19405}
19406#[doc = "Delete an existing table with destroy semantics (ignoring ENOENT\nerrors).\n"]
19407pub struct PushOpDestroytableDoRequest<Prev: Rec> {
19408 pub(crate) prev: Option<Prev>,
19409 pub(crate) header_offset: Option<usize>,
19410}
19411impl<Prev: Rec> Rec for PushOpDestroytableDoRequest<Prev> {
19412 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19413 self.prev.as_mut().unwrap().as_rec_mut()
19414 }
19415}
19416impl<Prev: Rec> PushOpDestroytableDoRequest<Prev> {
19417 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
19418 Self::write_header(&mut prev, header);
19419 Self::new_without_header(prev)
19420 }
19421 fn new_without_header(prev: Prev) -> Self {
19422 Self {
19423 prev: Some(prev),
19424 header_offset: None,
19425 }
19426 }
19427 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
19428 prev.as_rec_mut().extend(header.as_slice());
19429 }
19430 pub fn end_nested(mut self) -> Prev {
19431 let mut prev = self.prev.take().unwrap();
19432 if let Some(header_offset) = &self.header_offset {
19433 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19434 }
19435 prev
19436 }
19437 #[doc = "name of the table"]
19438 pub fn push_name(mut self, value: &CStr) -> Self {
19439 push_header(
19440 self.as_rec_mut(),
19441 1u16,
19442 value.to_bytes_with_nul().len() as u16,
19443 );
19444 self.as_rec_mut().extend(value.to_bytes_with_nul());
19445 self
19446 }
19447 #[doc = "name of the table"]
19448 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
19449 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
19450 self.as_rec_mut().extend(value);
19451 self.as_rec_mut().push(0);
19452 self
19453 }
19454 #[doc = "numeric handle of the table"]
19455 pub fn push_handle(mut self, value: u64) -> Self {
19456 push_header(self.as_rec_mut(), 4u16, 8 as u16);
19457 self.as_rec_mut().extend(value.to_be_bytes());
19458 self
19459 }
19460}
19461impl<Prev: Rec> Drop for PushOpDestroytableDoRequest<Prev> {
19462 fn drop(&mut self) {
19463 if let Some(prev) = &mut self.prev {
19464 if let Some(header_offset) = &self.header_offset {
19465 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19466 }
19467 }
19468 }
19469}
19470#[doc = "Delete an existing table with destroy semantics (ignoring ENOENT\nerrors).\n"]
19471#[derive(Clone)]
19472pub enum OpDestroytableDoRequest<'a> {
19473 #[doc = "name of the table"]
19474 Name(&'a CStr),
19475 #[doc = "numeric handle of the table"]
19476 Handle(u64),
19477}
19478impl<'a> IterableOpDestroytableDoRequest<'a> {
19479 #[doc = "name of the table"]
19480 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
19481 let mut iter = self.clone();
19482 iter.pos = 0;
19483 for attr in iter {
19484 if let OpDestroytableDoRequest::Name(val) = attr? {
19485 return Ok(val);
19486 }
19487 }
19488 Err(ErrorContext::new_missing(
19489 "OpDestroytableDoRequest",
19490 "Name",
19491 self.orig_loc,
19492 self.buf.as_ptr() as usize,
19493 ))
19494 }
19495 #[doc = "numeric handle of the table"]
19496 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
19497 let mut iter = self.clone();
19498 iter.pos = 0;
19499 for attr in iter {
19500 if let OpDestroytableDoRequest::Handle(val) = attr? {
19501 return Ok(val);
19502 }
19503 }
19504 Err(ErrorContext::new_missing(
19505 "OpDestroytableDoRequest",
19506 "Handle",
19507 self.orig_loc,
19508 self.buf.as_ptr() as usize,
19509 ))
19510 }
19511}
19512impl<'a> OpDestroytableDoRequest<'a> {
19513 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDestroytableDoRequest<'a>) {
19514 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
19515 (
19516 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
19517 IterableOpDestroytableDoRequest::with_loc(attrs, buf.as_ptr() as usize),
19518 )
19519 }
19520 fn attr_from_type(r#type: u16) -> Option<&'static str> {
19521 TableAttrs::attr_from_type(r#type)
19522 }
19523}
19524#[derive(Clone, Copy, Default)]
19525pub struct IterableOpDestroytableDoRequest<'a> {
19526 buf: &'a [u8],
19527 pos: usize,
19528 orig_loc: usize,
19529}
19530impl<'a> IterableOpDestroytableDoRequest<'a> {
19531 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
19532 Self {
19533 buf,
19534 pos: 0,
19535 orig_loc,
19536 }
19537 }
19538 pub fn get_buf(&self) -> &'a [u8] {
19539 self.buf
19540 }
19541}
19542impl<'a> Iterator for IterableOpDestroytableDoRequest<'a> {
19543 type Item = Result<OpDestroytableDoRequest<'a>, ErrorContext>;
19544 fn next(&mut self) -> Option<Self::Item> {
19545 if self.buf.len() == self.pos {
19546 return None;
19547 }
19548 let pos = self.pos;
19549 let mut r#type = None;
19550 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
19551 r#type = Some(header.r#type);
19552 let res = match header.r#type {
19553 1u16 => OpDestroytableDoRequest::Name({
19554 let res = CStr::from_bytes_with_nul(next).ok();
19555 let Some(val) = res else { break };
19556 val
19557 }),
19558 4u16 => OpDestroytableDoRequest::Handle({
19559 let res = parse_be_u64(next);
19560 let Some(val) = res else { break };
19561 val
19562 }),
19563 n => {
19564 if cfg!(any(test, feature = "deny-unknown-attrs")) {
19565 break;
19566 } else {
19567 continue;
19568 }
19569 }
19570 };
19571 return Some(Ok(res));
19572 }
19573 Some(Err(ErrorContext::new(
19574 "OpDestroytableDoRequest",
19575 r#type.and_then(|t| OpDestroytableDoRequest::attr_from_type(t)),
19576 self.orig_loc,
19577 self.buf.as_ptr().wrapping_add(pos) as usize,
19578 )))
19579 }
19580}
19581impl<'a> std::fmt::Debug for IterableOpDestroytableDoRequest<'_> {
19582 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19583 let mut fmt = f.debug_struct("OpDestroytableDoRequest");
19584 for attr in self.clone() {
19585 let attr = match attr {
19586 Ok(a) => a,
19587 Err(err) => {
19588 fmt.finish()?;
19589 f.write_str("Err(")?;
19590 err.fmt(f)?;
19591 return f.write_str(")");
19592 }
19593 };
19594 match attr {
19595 OpDestroytableDoRequest::Name(val) => fmt.field("Name", &val),
19596 OpDestroytableDoRequest::Handle(val) => fmt.field("Handle", &val),
19597 };
19598 }
19599 fmt.finish()
19600 }
19601}
19602impl IterableOpDestroytableDoRequest<'_> {
19603 pub fn lookup_attr(
19604 &self,
19605 offset: usize,
19606 missing_type: Option<u16>,
19607 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
19608 let mut stack = Vec::new();
19609 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
19610 if cur == offset + PushNfgenmsg::len() {
19611 stack.push(("OpDestroytableDoRequest", offset));
19612 return (
19613 stack,
19614 missing_type.and_then(|t| OpDestroytableDoRequest::attr_from_type(t)),
19615 );
19616 }
19617 if cur > offset || cur + self.buf.len() < offset {
19618 return (stack, None);
19619 }
19620 let mut attrs = self.clone();
19621 let mut last_off = cur + attrs.pos;
19622 while let Some(attr) = attrs.next() {
19623 let Ok(attr) = attr else { break };
19624 match attr {
19625 OpDestroytableDoRequest::Name(val) => {
19626 if last_off == offset {
19627 stack.push(("Name", last_off));
19628 break;
19629 }
19630 }
19631 OpDestroytableDoRequest::Handle(val) => {
19632 if last_off == offset {
19633 stack.push(("Handle", last_off));
19634 break;
19635 }
19636 }
19637 _ => {}
19638 };
19639 last_off = cur + attrs.pos;
19640 }
19641 if !stack.is_empty() {
19642 stack.push(("OpDestroytableDoRequest", cur));
19643 }
19644 (stack, None)
19645 }
19646}
19647#[doc = "Delete an existing table with destroy semantics (ignoring ENOENT\nerrors).\n"]
19648pub struct PushOpDestroytableDoReply<Prev: Rec> {
19649 pub(crate) prev: Option<Prev>,
19650 pub(crate) header_offset: Option<usize>,
19651}
19652impl<Prev: Rec> Rec for PushOpDestroytableDoReply<Prev> {
19653 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19654 self.prev.as_mut().unwrap().as_rec_mut()
19655 }
19656}
19657impl<Prev: Rec> PushOpDestroytableDoReply<Prev> {
19658 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
19659 Self::write_header(&mut prev, header);
19660 Self::new_without_header(prev)
19661 }
19662 fn new_without_header(prev: Prev) -> Self {
19663 Self {
19664 prev: Some(prev),
19665 header_offset: None,
19666 }
19667 }
19668 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
19669 prev.as_rec_mut().extend(header.as_slice());
19670 }
19671 pub fn end_nested(mut self) -> Prev {
19672 let mut prev = self.prev.take().unwrap();
19673 if let Some(header_offset) = &self.header_offset {
19674 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19675 }
19676 prev
19677 }
19678}
19679impl<Prev: Rec> Drop for PushOpDestroytableDoReply<Prev> {
19680 fn drop(&mut self) {
19681 if let Some(prev) = &mut self.prev {
19682 if let Some(header_offset) = &self.header_offset {
19683 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19684 }
19685 }
19686 }
19687}
19688#[doc = "Delete an existing table with destroy semantics (ignoring ENOENT\nerrors).\n"]
19689#[derive(Clone)]
19690pub enum OpDestroytableDoReply {}
19691impl<'a> IterableOpDestroytableDoReply<'a> {}
19692impl OpDestroytableDoReply {
19693 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDestroytableDoReply<'_>) {
19694 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
19695 (
19696 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
19697 IterableOpDestroytableDoReply::with_loc(attrs, buf.as_ptr() as usize),
19698 )
19699 }
19700 fn attr_from_type(r#type: u16) -> Option<&'static str> {
19701 TableAttrs::attr_from_type(r#type)
19702 }
19703}
19704#[derive(Clone, Copy, Default)]
19705pub struct IterableOpDestroytableDoReply<'a> {
19706 buf: &'a [u8],
19707 pos: usize,
19708 orig_loc: usize,
19709}
19710impl<'a> IterableOpDestroytableDoReply<'a> {
19711 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
19712 Self {
19713 buf,
19714 pos: 0,
19715 orig_loc,
19716 }
19717 }
19718 pub fn get_buf(&self) -> &'a [u8] {
19719 self.buf
19720 }
19721}
19722impl<'a> Iterator for IterableOpDestroytableDoReply<'a> {
19723 type Item = Result<OpDestroytableDoReply, ErrorContext>;
19724 fn next(&mut self) -> Option<Self::Item> {
19725 if self.buf.len() == self.pos {
19726 return None;
19727 }
19728 let pos = self.pos;
19729 let mut r#type = None;
19730 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
19731 r#type = Some(header.r#type);
19732 let res = match header.r#type {
19733 n => {
19734 if cfg!(any(test, feature = "deny-unknown-attrs")) {
19735 break;
19736 } else {
19737 continue;
19738 }
19739 }
19740 };
19741 return Some(Ok(res));
19742 }
19743 Some(Err(ErrorContext::new(
19744 "OpDestroytableDoReply",
19745 r#type.and_then(|t| OpDestroytableDoReply::attr_from_type(t)),
19746 self.orig_loc,
19747 self.buf.as_ptr().wrapping_add(pos) as usize,
19748 )))
19749 }
19750}
19751impl std::fmt::Debug for IterableOpDestroytableDoReply<'_> {
19752 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19753 let mut fmt = f.debug_struct("OpDestroytableDoReply");
19754 for attr in self.clone() {
19755 let attr = match attr {
19756 Ok(a) => a,
19757 Err(err) => {
19758 fmt.finish()?;
19759 f.write_str("Err(")?;
19760 err.fmt(f)?;
19761 return f.write_str(")");
19762 }
19763 };
19764 match attr {};
19765 }
19766 fmt.finish()
19767 }
19768}
19769impl IterableOpDestroytableDoReply<'_> {
19770 pub fn lookup_attr(
19771 &self,
19772 offset: usize,
19773 missing_type: Option<u16>,
19774 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
19775 let mut stack = Vec::new();
19776 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
19777 if cur == offset + PushNfgenmsg::len() {
19778 stack.push(("OpDestroytableDoReply", offset));
19779 return (
19780 stack,
19781 missing_type.and_then(|t| OpDestroytableDoReply::attr_from_type(t)),
19782 );
19783 }
19784 (stack, None)
19785 }
19786}
19787#[derive(Debug)]
19788pub struct RequestOpDestroytableDoRequest<'r> {
19789 request: Request<'r>,
19790}
19791impl<'r> RequestOpDestroytableDoRequest<'r> {
19792 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
19793 PushOpDestroytableDoRequest::write_header(&mut request.buf_mut(), header);
19794 Self { request: request }
19795 }
19796 pub fn encode(&mut self) -> PushOpDestroytableDoRequest<&mut Vec<u8>> {
19797 PushOpDestroytableDoRequest::new_without_header(self.request.buf_mut())
19798 }
19799 pub fn into_encoder(self) -> PushOpDestroytableDoRequest<RequestBuf<'r>> {
19800 PushOpDestroytableDoRequest::new_without_header(self.request.buf)
19801 }
19802}
19803impl NetlinkRequest for RequestOpDestroytableDoRequest<'_> {
19804 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDestroytableDoReply<'buf>);
19805 fn protocol(&self) -> Protocol {
19806 Protocol::Raw {
19807 protonum: 12u16,
19808 request_type: 2586u16,
19809 }
19810 }
19811 fn flags(&self) -> u16 {
19812 self.request.flags
19813 }
19814 fn payload(&self) -> &[u8] {
19815 self.request.buf()
19816 }
19817 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
19818 OpDestroytableDoReply::new(buf)
19819 }
19820 fn lookup(
19821 buf: &[u8],
19822 offset: usize,
19823 missing_type: Option<u16>,
19824 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
19825 OpDestroytableDoRequest::new(buf)
19826 .1
19827 .lookup_attr(offset, missing_type)
19828 }
19829}
19830#[doc = "Create a new chain."]
19831pub struct PushOpNewchainDoRequest<Prev: Rec> {
19832 pub(crate) prev: Option<Prev>,
19833 pub(crate) header_offset: Option<usize>,
19834}
19835impl<Prev: Rec> Rec for PushOpNewchainDoRequest<Prev> {
19836 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
19837 self.prev.as_mut().unwrap().as_rec_mut()
19838 }
19839}
19840impl<Prev: Rec> PushOpNewchainDoRequest<Prev> {
19841 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
19842 Self::write_header(&mut prev, header);
19843 Self::new_without_header(prev)
19844 }
19845 fn new_without_header(prev: Prev) -> Self {
19846 Self {
19847 prev: Some(prev),
19848 header_offset: None,
19849 }
19850 }
19851 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
19852 prev.as_rec_mut().extend(header.as_slice());
19853 }
19854 pub fn end_nested(mut self) -> Prev {
19855 let mut prev = self.prev.take().unwrap();
19856 if let Some(header_offset) = &self.header_offset {
19857 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19858 }
19859 prev
19860 }
19861 #[doc = "name of the table containing the chain"]
19862 pub fn push_table(mut self, value: &CStr) -> Self {
19863 push_header(
19864 self.as_rec_mut(),
19865 1u16,
19866 value.to_bytes_with_nul().len() as u16,
19867 );
19868 self.as_rec_mut().extend(value.to_bytes_with_nul());
19869 self
19870 }
19871 #[doc = "name of the table containing the chain"]
19872 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
19873 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
19874 self.as_rec_mut().extend(value);
19875 self.as_rec_mut().push(0);
19876 self
19877 }
19878 #[doc = "numeric handle of the chain"]
19879 pub fn push_handle(mut self, value: u64) -> Self {
19880 push_header(self.as_rec_mut(), 2u16, 8 as u16);
19881 self.as_rec_mut().extend(value.to_be_bytes());
19882 self
19883 }
19884 #[doc = "name of the chain"]
19885 pub fn push_name(mut self, value: &CStr) -> Self {
19886 push_header(
19887 self.as_rec_mut(),
19888 3u16,
19889 value.to_bytes_with_nul().len() as u16,
19890 );
19891 self.as_rec_mut().extend(value.to_bytes_with_nul());
19892 self
19893 }
19894 #[doc = "name of the chain"]
19895 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
19896 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
19897 self.as_rec_mut().extend(value);
19898 self.as_rec_mut().push(0);
19899 self
19900 }
19901 #[doc = "hook specification for basechains"]
19902 pub fn nested_hook(mut self) -> PushNftHookAttrs<Self> {
19903 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
19904 PushNftHookAttrs {
19905 prev: Some(self),
19906 header_offset: Some(header_offset),
19907 }
19908 }
19909 #[doc = "numeric policy of the chain"]
19910 pub fn push_policy(mut self, value: u32) -> Self {
19911 push_header(self.as_rec_mut(), 5u16, 4 as u16);
19912 self.as_rec_mut().extend(value.to_be_bytes());
19913 self
19914 }
19915 #[doc = "counter specification of the chain"]
19916 pub fn nested_counters(mut self) -> PushNftCounterAttrs<Self> {
19917 let header_offset = push_nested_header(self.as_rec_mut(), 8u16);
19918 PushNftCounterAttrs {
19919 prev: Some(self),
19920 header_offset: Some(header_offset),
19921 }
19922 }
19923 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
19924 pub fn push_flags(mut self, value: u32) -> Self {
19925 push_header(self.as_rec_mut(), 9u16, 4 as u16);
19926 self.as_rec_mut().extend(value.to_be_bytes());
19927 self
19928 }
19929 #[doc = "user data"]
19930 pub fn push_userdata(mut self, value: &[u8]) -> Self {
19931 push_header(self.as_rec_mut(), 11u16, value.len() as u16);
19932 self.as_rec_mut().extend(value);
19933 self
19934 }
19935}
19936impl<Prev: Rec> Drop for PushOpNewchainDoRequest<Prev> {
19937 fn drop(&mut self) {
19938 if let Some(prev) = &mut self.prev {
19939 if let Some(header_offset) = &self.header_offset {
19940 finalize_nested_header(prev.as_rec_mut(), *header_offset);
19941 }
19942 }
19943 }
19944}
19945#[doc = "Create a new chain."]
19946#[derive(Clone)]
19947pub enum OpNewchainDoRequest<'a> {
19948 #[doc = "name of the table containing the chain"]
19949 Table(&'a CStr),
19950 #[doc = "numeric handle of the chain"]
19951 Handle(u64),
19952 #[doc = "name of the chain"]
19953 Name(&'a CStr),
19954 #[doc = "hook specification for basechains"]
19955 Hook(IterableNftHookAttrs<'a>),
19956 #[doc = "numeric policy of the chain"]
19957 Policy(u32),
19958 #[doc = "counter specification of the chain"]
19959 Counters(IterableNftCounterAttrs<'a>),
19960 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
19961 Flags(u32),
19962 #[doc = "user data"]
19963 Userdata(&'a [u8]),
19964}
19965impl<'a> IterableOpNewchainDoRequest<'a> {
19966 #[doc = "name of the table containing the chain"]
19967 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
19968 let mut iter = self.clone();
19969 iter.pos = 0;
19970 for attr in iter {
19971 if let OpNewchainDoRequest::Table(val) = attr? {
19972 return Ok(val);
19973 }
19974 }
19975 Err(ErrorContext::new_missing(
19976 "OpNewchainDoRequest",
19977 "Table",
19978 self.orig_loc,
19979 self.buf.as_ptr() as usize,
19980 ))
19981 }
19982 #[doc = "numeric handle of the chain"]
19983 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
19984 let mut iter = self.clone();
19985 iter.pos = 0;
19986 for attr in iter {
19987 if let OpNewchainDoRequest::Handle(val) = attr? {
19988 return Ok(val);
19989 }
19990 }
19991 Err(ErrorContext::new_missing(
19992 "OpNewchainDoRequest",
19993 "Handle",
19994 self.orig_loc,
19995 self.buf.as_ptr() as usize,
19996 ))
19997 }
19998 #[doc = "name of the chain"]
19999 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
20000 let mut iter = self.clone();
20001 iter.pos = 0;
20002 for attr in iter {
20003 if let OpNewchainDoRequest::Name(val) = attr? {
20004 return Ok(val);
20005 }
20006 }
20007 Err(ErrorContext::new_missing(
20008 "OpNewchainDoRequest",
20009 "Name",
20010 self.orig_loc,
20011 self.buf.as_ptr() as usize,
20012 ))
20013 }
20014 #[doc = "hook specification for basechains"]
20015 pub fn get_hook(&self) -> Result<IterableNftHookAttrs<'a>, ErrorContext> {
20016 let mut iter = self.clone();
20017 iter.pos = 0;
20018 for attr in iter {
20019 if let OpNewchainDoRequest::Hook(val) = attr? {
20020 return Ok(val);
20021 }
20022 }
20023 Err(ErrorContext::new_missing(
20024 "OpNewchainDoRequest",
20025 "Hook",
20026 self.orig_loc,
20027 self.buf.as_ptr() as usize,
20028 ))
20029 }
20030 #[doc = "numeric policy of the chain"]
20031 pub fn get_policy(&self) -> Result<u32, ErrorContext> {
20032 let mut iter = self.clone();
20033 iter.pos = 0;
20034 for attr in iter {
20035 if let OpNewchainDoRequest::Policy(val) = attr? {
20036 return Ok(val);
20037 }
20038 }
20039 Err(ErrorContext::new_missing(
20040 "OpNewchainDoRequest",
20041 "Policy",
20042 self.orig_loc,
20043 self.buf.as_ptr() as usize,
20044 ))
20045 }
20046 #[doc = "counter specification of the chain"]
20047 pub fn get_counters(&self) -> Result<IterableNftCounterAttrs<'a>, ErrorContext> {
20048 let mut iter = self.clone();
20049 iter.pos = 0;
20050 for attr in iter {
20051 if let OpNewchainDoRequest::Counters(val) = attr? {
20052 return Ok(val);
20053 }
20054 }
20055 Err(ErrorContext::new_missing(
20056 "OpNewchainDoRequest",
20057 "Counters",
20058 self.orig_loc,
20059 self.buf.as_ptr() as usize,
20060 ))
20061 }
20062 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
20063 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
20064 let mut iter = self.clone();
20065 iter.pos = 0;
20066 for attr in iter {
20067 if let OpNewchainDoRequest::Flags(val) = attr? {
20068 return Ok(val);
20069 }
20070 }
20071 Err(ErrorContext::new_missing(
20072 "OpNewchainDoRequest",
20073 "Flags",
20074 self.orig_loc,
20075 self.buf.as_ptr() as usize,
20076 ))
20077 }
20078 #[doc = "user data"]
20079 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
20080 let mut iter = self.clone();
20081 iter.pos = 0;
20082 for attr in iter {
20083 if let OpNewchainDoRequest::Userdata(val) = attr? {
20084 return Ok(val);
20085 }
20086 }
20087 Err(ErrorContext::new_missing(
20088 "OpNewchainDoRequest",
20089 "Userdata",
20090 self.orig_loc,
20091 self.buf.as_ptr() as usize,
20092 ))
20093 }
20094}
20095impl<'a> OpNewchainDoRequest<'a> {
20096 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpNewchainDoRequest<'a>) {
20097 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
20098 (
20099 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
20100 IterableOpNewchainDoRequest::with_loc(attrs, buf.as_ptr() as usize),
20101 )
20102 }
20103 fn attr_from_type(r#type: u16) -> Option<&'static str> {
20104 ChainAttrs::attr_from_type(r#type)
20105 }
20106}
20107#[derive(Clone, Copy, Default)]
20108pub struct IterableOpNewchainDoRequest<'a> {
20109 buf: &'a [u8],
20110 pos: usize,
20111 orig_loc: usize,
20112}
20113impl<'a> IterableOpNewchainDoRequest<'a> {
20114 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
20115 Self {
20116 buf,
20117 pos: 0,
20118 orig_loc,
20119 }
20120 }
20121 pub fn get_buf(&self) -> &'a [u8] {
20122 self.buf
20123 }
20124}
20125impl<'a> Iterator for IterableOpNewchainDoRequest<'a> {
20126 type Item = Result<OpNewchainDoRequest<'a>, ErrorContext>;
20127 fn next(&mut self) -> Option<Self::Item> {
20128 if self.buf.len() == self.pos {
20129 return None;
20130 }
20131 let pos = self.pos;
20132 let mut r#type = None;
20133 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
20134 r#type = Some(header.r#type);
20135 let res = match header.r#type {
20136 1u16 => OpNewchainDoRequest::Table({
20137 let res = CStr::from_bytes_with_nul(next).ok();
20138 let Some(val) = res else { break };
20139 val
20140 }),
20141 2u16 => OpNewchainDoRequest::Handle({
20142 let res = parse_be_u64(next);
20143 let Some(val) = res else { break };
20144 val
20145 }),
20146 3u16 => OpNewchainDoRequest::Name({
20147 let res = CStr::from_bytes_with_nul(next).ok();
20148 let Some(val) = res else { break };
20149 val
20150 }),
20151 4u16 => OpNewchainDoRequest::Hook({
20152 let res = Some(IterableNftHookAttrs::with_loc(next, self.orig_loc));
20153 let Some(val) = res else { break };
20154 val
20155 }),
20156 5u16 => OpNewchainDoRequest::Policy({
20157 let res = parse_be_u32(next);
20158 let Some(val) = res else { break };
20159 val
20160 }),
20161 8u16 => OpNewchainDoRequest::Counters({
20162 let res = Some(IterableNftCounterAttrs::with_loc(next, self.orig_loc));
20163 let Some(val) = res else { break };
20164 val
20165 }),
20166 9u16 => OpNewchainDoRequest::Flags({
20167 let res = parse_be_u32(next);
20168 let Some(val) = res else { break };
20169 val
20170 }),
20171 11u16 => OpNewchainDoRequest::Userdata({
20172 let res = Some(next);
20173 let Some(val) = res else { break };
20174 val
20175 }),
20176 n => {
20177 if cfg!(any(test, feature = "deny-unknown-attrs")) {
20178 break;
20179 } else {
20180 continue;
20181 }
20182 }
20183 };
20184 return Some(Ok(res));
20185 }
20186 Some(Err(ErrorContext::new(
20187 "OpNewchainDoRequest",
20188 r#type.and_then(|t| OpNewchainDoRequest::attr_from_type(t)),
20189 self.orig_loc,
20190 self.buf.as_ptr().wrapping_add(pos) as usize,
20191 )))
20192 }
20193}
20194impl<'a> std::fmt::Debug for IterableOpNewchainDoRequest<'_> {
20195 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20196 let mut fmt = f.debug_struct("OpNewchainDoRequest");
20197 for attr in self.clone() {
20198 let attr = match attr {
20199 Ok(a) => a,
20200 Err(err) => {
20201 fmt.finish()?;
20202 f.write_str("Err(")?;
20203 err.fmt(f)?;
20204 return f.write_str(")");
20205 }
20206 };
20207 match attr {
20208 OpNewchainDoRequest::Table(val) => fmt.field("Table", &val),
20209 OpNewchainDoRequest::Handle(val) => fmt.field("Handle", &val),
20210 OpNewchainDoRequest::Name(val) => fmt.field("Name", &val),
20211 OpNewchainDoRequest::Hook(val) => fmt.field("Hook", &val),
20212 OpNewchainDoRequest::Policy(val) => fmt.field("Policy", &val),
20213 OpNewchainDoRequest::Counters(val) => fmt.field("Counters", &val),
20214 OpNewchainDoRequest::Flags(val) => {
20215 fmt.field("Flags", &FormatFlags(val.into(), ChainFlags::from_value))
20216 }
20217 OpNewchainDoRequest::Userdata(val) => fmt.field("Userdata", &val),
20218 };
20219 }
20220 fmt.finish()
20221 }
20222}
20223impl IterableOpNewchainDoRequest<'_> {
20224 pub fn lookup_attr(
20225 &self,
20226 offset: usize,
20227 missing_type: Option<u16>,
20228 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
20229 let mut stack = Vec::new();
20230 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
20231 if cur == offset + PushNfgenmsg::len() {
20232 stack.push(("OpNewchainDoRequest", offset));
20233 return (
20234 stack,
20235 missing_type.and_then(|t| OpNewchainDoRequest::attr_from_type(t)),
20236 );
20237 }
20238 if cur > offset || cur + self.buf.len() < offset {
20239 return (stack, None);
20240 }
20241 let mut attrs = self.clone();
20242 let mut last_off = cur + attrs.pos;
20243 let mut missing = None;
20244 while let Some(attr) = attrs.next() {
20245 let Ok(attr) = attr else { break };
20246 match attr {
20247 OpNewchainDoRequest::Table(val) => {
20248 if last_off == offset {
20249 stack.push(("Table", last_off));
20250 break;
20251 }
20252 }
20253 OpNewchainDoRequest::Handle(val) => {
20254 if last_off == offset {
20255 stack.push(("Handle", last_off));
20256 break;
20257 }
20258 }
20259 OpNewchainDoRequest::Name(val) => {
20260 if last_off == offset {
20261 stack.push(("Name", last_off));
20262 break;
20263 }
20264 }
20265 OpNewchainDoRequest::Hook(val) => {
20266 (stack, missing) = val.lookup_attr(offset, missing_type);
20267 if !stack.is_empty() {
20268 break;
20269 }
20270 }
20271 OpNewchainDoRequest::Policy(val) => {
20272 if last_off == offset {
20273 stack.push(("Policy", last_off));
20274 break;
20275 }
20276 }
20277 OpNewchainDoRequest::Counters(val) => {
20278 (stack, missing) = val.lookup_attr(offset, missing_type);
20279 if !stack.is_empty() {
20280 break;
20281 }
20282 }
20283 OpNewchainDoRequest::Flags(val) => {
20284 if last_off == offset {
20285 stack.push(("Flags", last_off));
20286 break;
20287 }
20288 }
20289 OpNewchainDoRequest::Userdata(val) => {
20290 if last_off == offset {
20291 stack.push(("Userdata", last_off));
20292 break;
20293 }
20294 }
20295 _ => {}
20296 };
20297 last_off = cur + attrs.pos;
20298 }
20299 if !stack.is_empty() {
20300 stack.push(("OpNewchainDoRequest", cur));
20301 }
20302 (stack, missing)
20303 }
20304}
20305#[doc = "Create a new chain."]
20306pub struct PushOpNewchainDoReply<Prev: Rec> {
20307 pub(crate) prev: Option<Prev>,
20308 pub(crate) header_offset: Option<usize>,
20309}
20310impl<Prev: Rec> Rec for PushOpNewchainDoReply<Prev> {
20311 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
20312 self.prev.as_mut().unwrap().as_rec_mut()
20313 }
20314}
20315impl<Prev: Rec> PushOpNewchainDoReply<Prev> {
20316 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
20317 Self::write_header(&mut prev, header);
20318 Self::new_without_header(prev)
20319 }
20320 fn new_without_header(prev: Prev) -> Self {
20321 Self {
20322 prev: Some(prev),
20323 header_offset: None,
20324 }
20325 }
20326 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
20327 prev.as_rec_mut().extend(header.as_slice());
20328 }
20329 pub fn end_nested(mut self) -> Prev {
20330 let mut prev = self.prev.take().unwrap();
20331 if let Some(header_offset) = &self.header_offset {
20332 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20333 }
20334 prev
20335 }
20336}
20337impl<Prev: Rec> Drop for PushOpNewchainDoReply<Prev> {
20338 fn drop(&mut self) {
20339 if let Some(prev) = &mut self.prev {
20340 if let Some(header_offset) = &self.header_offset {
20341 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20342 }
20343 }
20344 }
20345}
20346#[doc = "Create a new chain."]
20347#[derive(Clone)]
20348pub enum OpNewchainDoReply {}
20349impl<'a> IterableOpNewchainDoReply<'a> {}
20350impl OpNewchainDoReply {
20351 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpNewchainDoReply<'_>) {
20352 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
20353 (
20354 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
20355 IterableOpNewchainDoReply::with_loc(attrs, buf.as_ptr() as usize),
20356 )
20357 }
20358 fn attr_from_type(r#type: u16) -> Option<&'static str> {
20359 ChainAttrs::attr_from_type(r#type)
20360 }
20361}
20362#[derive(Clone, Copy, Default)]
20363pub struct IterableOpNewchainDoReply<'a> {
20364 buf: &'a [u8],
20365 pos: usize,
20366 orig_loc: usize,
20367}
20368impl<'a> IterableOpNewchainDoReply<'a> {
20369 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
20370 Self {
20371 buf,
20372 pos: 0,
20373 orig_loc,
20374 }
20375 }
20376 pub fn get_buf(&self) -> &'a [u8] {
20377 self.buf
20378 }
20379}
20380impl<'a> Iterator for IterableOpNewchainDoReply<'a> {
20381 type Item = Result<OpNewchainDoReply, ErrorContext>;
20382 fn next(&mut self) -> Option<Self::Item> {
20383 if self.buf.len() == self.pos {
20384 return None;
20385 }
20386 let pos = self.pos;
20387 let mut r#type = None;
20388 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
20389 r#type = Some(header.r#type);
20390 let res = match header.r#type {
20391 n => {
20392 if cfg!(any(test, feature = "deny-unknown-attrs")) {
20393 break;
20394 } else {
20395 continue;
20396 }
20397 }
20398 };
20399 return Some(Ok(res));
20400 }
20401 Some(Err(ErrorContext::new(
20402 "OpNewchainDoReply",
20403 r#type.and_then(|t| OpNewchainDoReply::attr_from_type(t)),
20404 self.orig_loc,
20405 self.buf.as_ptr().wrapping_add(pos) as usize,
20406 )))
20407 }
20408}
20409impl std::fmt::Debug for IterableOpNewchainDoReply<'_> {
20410 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20411 let mut fmt = f.debug_struct("OpNewchainDoReply");
20412 for attr in self.clone() {
20413 let attr = match attr {
20414 Ok(a) => a,
20415 Err(err) => {
20416 fmt.finish()?;
20417 f.write_str("Err(")?;
20418 err.fmt(f)?;
20419 return f.write_str(")");
20420 }
20421 };
20422 match attr {};
20423 }
20424 fmt.finish()
20425 }
20426}
20427impl IterableOpNewchainDoReply<'_> {
20428 pub fn lookup_attr(
20429 &self,
20430 offset: usize,
20431 missing_type: Option<u16>,
20432 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
20433 let mut stack = Vec::new();
20434 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
20435 if cur == offset + PushNfgenmsg::len() {
20436 stack.push(("OpNewchainDoReply", offset));
20437 return (
20438 stack,
20439 missing_type.and_then(|t| OpNewchainDoReply::attr_from_type(t)),
20440 );
20441 }
20442 (stack, None)
20443 }
20444}
20445#[derive(Debug)]
20446pub struct RequestOpNewchainDoRequest<'r> {
20447 request: Request<'r>,
20448}
20449impl<'r> RequestOpNewchainDoRequest<'r> {
20450 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
20451 PushOpNewchainDoRequest::write_header(&mut request.buf_mut(), header);
20452 Self { request: request }
20453 }
20454 pub fn encode(&mut self) -> PushOpNewchainDoRequest<&mut Vec<u8>> {
20455 PushOpNewchainDoRequest::new_without_header(self.request.buf_mut())
20456 }
20457 pub fn into_encoder(self) -> PushOpNewchainDoRequest<RequestBuf<'r>> {
20458 PushOpNewchainDoRequest::new_without_header(self.request.buf)
20459 }
20460}
20461impl NetlinkRequest for RequestOpNewchainDoRequest<'_> {
20462 type ReplyType<'buf> = (PushNfgenmsg, IterableOpNewchainDoReply<'buf>);
20463 fn protocol(&self) -> Protocol {
20464 Protocol::Raw {
20465 protonum: 12u16,
20466 request_type: 2563u16,
20467 }
20468 }
20469 fn flags(&self) -> u16 {
20470 self.request.flags
20471 }
20472 fn payload(&self) -> &[u8] {
20473 self.request.buf()
20474 }
20475 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
20476 OpNewchainDoReply::new(buf)
20477 }
20478 fn lookup(
20479 buf: &[u8],
20480 offset: usize,
20481 missing_type: Option<u16>,
20482 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
20483 OpNewchainDoRequest::new(buf)
20484 .1
20485 .lookup_attr(offset, missing_type)
20486 }
20487}
20488#[doc = "Get / dump chains."]
20489pub struct PushOpGetchainDumpRequest<Prev: Rec> {
20490 pub(crate) prev: Option<Prev>,
20491 pub(crate) header_offset: Option<usize>,
20492}
20493impl<Prev: Rec> Rec for PushOpGetchainDumpRequest<Prev> {
20494 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
20495 self.prev.as_mut().unwrap().as_rec_mut()
20496 }
20497}
20498impl<Prev: Rec> PushOpGetchainDumpRequest<Prev> {
20499 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
20500 Self::write_header(&mut prev, header);
20501 Self::new_without_header(prev)
20502 }
20503 fn new_without_header(prev: Prev) -> Self {
20504 Self {
20505 prev: Some(prev),
20506 header_offset: None,
20507 }
20508 }
20509 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
20510 prev.as_rec_mut().extend(header.as_slice());
20511 }
20512 pub fn end_nested(mut self) -> Prev {
20513 let mut prev = self.prev.take().unwrap();
20514 if let Some(header_offset) = &self.header_offset {
20515 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20516 }
20517 prev
20518 }
20519}
20520impl<Prev: Rec> Drop for PushOpGetchainDumpRequest<Prev> {
20521 fn drop(&mut self) {
20522 if let Some(prev) = &mut self.prev {
20523 if let Some(header_offset) = &self.header_offset {
20524 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20525 }
20526 }
20527 }
20528}
20529#[doc = "Get / dump chains."]
20530#[derive(Clone)]
20531pub enum OpGetchainDumpRequest {}
20532impl<'a> IterableOpGetchainDumpRequest<'a> {}
20533impl OpGetchainDumpRequest {
20534 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpGetchainDumpRequest<'_>) {
20535 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
20536 (
20537 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
20538 IterableOpGetchainDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
20539 )
20540 }
20541 fn attr_from_type(r#type: u16) -> Option<&'static str> {
20542 ChainAttrs::attr_from_type(r#type)
20543 }
20544}
20545#[derive(Clone, Copy, Default)]
20546pub struct IterableOpGetchainDumpRequest<'a> {
20547 buf: &'a [u8],
20548 pos: usize,
20549 orig_loc: usize,
20550}
20551impl<'a> IterableOpGetchainDumpRequest<'a> {
20552 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
20553 Self {
20554 buf,
20555 pos: 0,
20556 orig_loc,
20557 }
20558 }
20559 pub fn get_buf(&self) -> &'a [u8] {
20560 self.buf
20561 }
20562}
20563impl<'a> Iterator for IterableOpGetchainDumpRequest<'a> {
20564 type Item = Result<OpGetchainDumpRequest, ErrorContext>;
20565 fn next(&mut self) -> Option<Self::Item> {
20566 if self.buf.len() == self.pos {
20567 return None;
20568 }
20569 let pos = self.pos;
20570 let mut r#type = None;
20571 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
20572 r#type = Some(header.r#type);
20573 let res = match header.r#type {
20574 n => {
20575 if cfg!(any(test, feature = "deny-unknown-attrs")) {
20576 break;
20577 } else {
20578 continue;
20579 }
20580 }
20581 };
20582 return Some(Ok(res));
20583 }
20584 Some(Err(ErrorContext::new(
20585 "OpGetchainDumpRequest",
20586 r#type.and_then(|t| OpGetchainDumpRequest::attr_from_type(t)),
20587 self.orig_loc,
20588 self.buf.as_ptr().wrapping_add(pos) as usize,
20589 )))
20590 }
20591}
20592impl std::fmt::Debug for IterableOpGetchainDumpRequest<'_> {
20593 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20594 let mut fmt = f.debug_struct("OpGetchainDumpRequest");
20595 for attr in self.clone() {
20596 let attr = match attr {
20597 Ok(a) => a,
20598 Err(err) => {
20599 fmt.finish()?;
20600 f.write_str("Err(")?;
20601 err.fmt(f)?;
20602 return f.write_str(")");
20603 }
20604 };
20605 match attr {};
20606 }
20607 fmt.finish()
20608 }
20609}
20610impl IterableOpGetchainDumpRequest<'_> {
20611 pub fn lookup_attr(
20612 &self,
20613 offset: usize,
20614 missing_type: Option<u16>,
20615 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
20616 let mut stack = Vec::new();
20617 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
20618 if cur == offset + PushNfgenmsg::len() {
20619 stack.push(("OpGetchainDumpRequest", offset));
20620 return (
20621 stack,
20622 missing_type.and_then(|t| OpGetchainDumpRequest::attr_from_type(t)),
20623 );
20624 }
20625 (stack, None)
20626 }
20627}
20628#[doc = "Get / dump chains."]
20629pub struct PushOpGetchainDumpReply<Prev: Rec> {
20630 pub(crate) prev: Option<Prev>,
20631 pub(crate) header_offset: Option<usize>,
20632}
20633impl<Prev: Rec> Rec for PushOpGetchainDumpReply<Prev> {
20634 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
20635 self.prev.as_mut().unwrap().as_rec_mut()
20636 }
20637}
20638impl<Prev: Rec> PushOpGetchainDumpReply<Prev> {
20639 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
20640 Self::write_header(&mut prev, header);
20641 Self::new_without_header(prev)
20642 }
20643 fn new_without_header(prev: Prev) -> Self {
20644 Self {
20645 prev: Some(prev),
20646 header_offset: None,
20647 }
20648 }
20649 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
20650 prev.as_rec_mut().extend(header.as_slice());
20651 }
20652 pub fn end_nested(mut self) -> Prev {
20653 let mut prev = self.prev.take().unwrap();
20654 if let Some(header_offset) = &self.header_offset {
20655 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20656 }
20657 prev
20658 }
20659 #[doc = "name of the table containing the chain"]
20660 pub fn push_table(mut self, value: &CStr) -> Self {
20661 push_header(
20662 self.as_rec_mut(),
20663 1u16,
20664 value.to_bytes_with_nul().len() as u16,
20665 );
20666 self.as_rec_mut().extend(value.to_bytes_with_nul());
20667 self
20668 }
20669 #[doc = "name of the table containing the chain"]
20670 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
20671 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
20672 self.as_rec_mut().extend(value);
20673 self.as_rec_mut().push(0);
20674 self
20675 }
20676 #[doc = "numeric handle of the chain"]
20677 pub fn push_handle(mut self, value: u64) -> Self {
20678 push_header(self.as_rec_mut(), 2u16, 8 as u16);
20679 self.as_rec_mut().extend(value.to_be_bytes());
20680 self
20681 }
20682 #[doc = "name of the chain"]
20683 pub fn push_name(mut self, value: &CStr) -> Self {
20684 push_header(
20685 self.as_rec_mut(),
20686 3u16,
20687 value.to_bytes_with_nul().len() as u16,
20688 );
20689 self.as_rec_mut().extend(value.to_bytes_with_nul());
20690 self
20691 }
20692 #[doc = "name of the chain"]
20693 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
20694 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
20695 self.as_rec_mut().extend(value);
20696 self.as_rec_mut().push(0);
20697 self
20698 }
20699 #[doc = "hook specification for basechains"]
20700 pub fn nested_hook(mut self) -> PushNftHookAttrs<Self> {
20701 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
20702 PushNftHookAttrs {
20703 prev: Some(self),
20704 header_offset: Some(header_offset),
20705 }
20706 }
20707 #[doc = "numeric policy of the chain"]
20708 pub fn push_policy(mut self, value: u32) -> Self {
20709 push_header(self.as_rec_mut(), 5u16, 4 as u16);
20710 self.as_rec_mut().extend(value.to_be_bytes());
20711 self
20712 }
20713 #[doc = "number of references to this chain"]
20714 pub fn push_use(mut self, value: u32) -> Self {
20715 push_header(self.as_rec_mut(), 6u16, 4 as u16);
20716 self.as_rec_mut().extend(value.to_be_bytes());
20717 self
20718 }
20719 #[doc = "type name of the chain"]
20720 pub fn push_type(mut self, value: &CStr) -> Self {
20721 push_header(
20722 self.as_rec_mut(),
20723 7u16,
20724 value.to_bytes_with_nul().len() as u16,
20725 );
20726 self.as_rec_mut().extend(value.to_bytes_with_nul());
20727 self
20728 }
20729 #[doc = "type name of the chain"]
20730 pub fn push_type_bytes(mut self, value: &[u8]) -> Self {
20731 push_header(self.as_rec_mut(), 7u16, (value.len() + 1) as u16);
20732 self.as_rec_mut().extend(value);
20733 self.as_rec_mut().push(0);
20734 self
20735 }
20736 #[doc = "counter specification of the chain"]
20737 pub fn nested_counters(mut self) -> PushNftCounterAttrs<Self> {
20738 let header_offset = push_nested_header(self.as_rec_mut(), 8u16);
20739 PushNftCounterAttrs {
20740 prev: Some(self),
20741 header_offset: Some(header_offset),
20742 }
20743 }
20744 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
20745 pub fn push_flags(mut self, value: u32) -> Self {
20746 push_header(self.as_rec_mut(), 9u16, 4 as u16);
20747 self.as_rec_mut().extend(value.to_be_bytes());
20748 self
20749 }
20750 #[doc = "uniquely identifies a chain in a transaction"]
20751 pub fn push_id(mut self, value: u32) -> Self {
20752 push_header(self.as_rec_mut(), 10u16, 4 as u16);
20753 self.as_rec_mut().extend(value.to_be_bytes());
20754 self
20755 }
20756 #[doc = "user data"]
20757 pub fn push_userdata(mut self, value: &[u8]) -> Self {
20758 push_header(self.as_rec_mut(), 11u16, value.len() as u16);
20759 self.as_rec_mut().extend(value);
20760 self
20761 }
20762}
20763impl<Prev: Rec> Drop for PushOpGetchainDumpReply<Prev> {
20764 fn drop(&mut self) {
20765 if let Some(prev) = &mut self.prev {
20766 if let Some(header_offset) = &self.header_offset {
20767 finalize_nested_header(prev.as_rec_mut(), *header_offset);
20768 }
20769 }
20770 }
20771}
20772#[doc = "Get / dump chains."]
20773#[derive(Clone)]
20774pub enum OpGetchainDumpReply<'a> {
20775 #[doc = "name of the table containing the chain"]
20776 Table(&'a CStr),
20777 #[doc = "numeric handle of the chain"]
20778 Handle(u64),
20779 #[doc = "name of the chain"]
20780 Name(&'a CStr),
20781 #[doc = "hook specification for basechains"]
20782 Hook(IterableNftHookAttrs<'a>),
20783 #[doc = "numeric policy of the chain"]
20784 Policy(u32),
20785 #[doc = "number of references to this chain"]
20786 Use(u32),
20787 #[doc = "type name of the chain"]
20788 Type(&'a CStr),
20789 #[doc = "counter specification of the chain"]
20790 Counters(IterableNftCounterAttrs<'a>),
20791 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
20792 Flags(u32),
20793 #[doc = "uniquely identifies a chain in a transaction"]
20794 Id(u32),
20795 #[doc = "user data"]
20796 Userdata(&'a [u8]),
20797}
20798impl<'a> IterableOpGetchainDumpReply<'a> {
20799 #[doc = "name of the table containing the chain"]
20800 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
20801 let mut iter = self.clone();
20802 iter.pos = 0;
20803 for attr in iter {
20804 if let OpGetchainDumpReply::Table(val) = attr? {
20805 return Ok(val);
20806 }
20807 }
20808 Err(ErrorContext::new_missing(
20809 "OpGetchainDumpReply",
20810 "Table",
20811 self.orig_loc,
20812 self.buf.as_ptr() as usize,
20813 ))
20814 }
20815 #[doc = "numeric handle of the chain"]
20816 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
20817 let mut iter = self.clone();
20818 iter.pos = 0;
20819 for attr in iter {
20820 if let OpGetchainDumpReply::Handle(val) = attr? {
20821 return Ok(val);
20822 }
20823 }
20824 Err(ErrorContext::new_missing(
20825 "OpGetchainDumpReply",
20826 "Handle",
20827 self.orig_loc,
20828 self.buf.as_ptr() as usize,
20829 ))
20830 }
20831 #[doc = "name of the chain"]
20832 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
20833 let mut iter = self.clone();
20834 iter.pos = 0;
20835 for attr in iter {
20836 if let OpGetchainDumpReply::Name(val) = attr? {
20837 return Ok(val);
20838 }
20839 }
20840 Err(ErrorContext::new_missing(
20841 "OpGetchainDumpReply",
20842 "Name",
20843 self.orig_loc,
20844 self.buf.as_ptr() as usize,
20845 ))
20846 }
20847 #[doc = "hook specification for basechains"]
20848 pub fn get_hook(&self) -> Result<IterableNftHookAttrs<'a>, ErrorContext> {
20849 let mut iter = self.clone();
20850 iter.pos = 0;
20851 for attr in iter {
20852 if let OpGetchainDumpReply::Hook(val) = attr? {
20853 return Ok(val);
20854 }
20855 }
20856 Err(ErrorContext::new_missing(
20857 "OpGetchainDumpReply",
20858 "Hook",
20859 self.orig_loc,
20860 self.buf.as_ptr() as usize,
20861 ))
20862 }
20863 #[doc = "numeric policy of the chain"]
20864 pub fn get_policy(&self) -> Result<u32, ErrorContext> {
20865 let mut iter = self.clone();
20866 iter.pos = 0;
20867 for attr in iter {
20868 if let OpGetchainDumpReply::Policy(val) = attr? {
20869 return Ok(val);
20870 }
20871 }
20872 Err(ErrorContext::new_missing(
20873 "OpGetchainDumpReply",
20874 "Policy",
20875 self.orig_loc,
20876 self.buf.as_ptr() as usize,
20877 ))
20878 }
20879 #[doc = "number of references to this chain"]
20880 pub fn get_use(&self) -> Result<u32, ErrorContext> {
20881 let mut iter = self.clone();
20882 iter.pos = 0;
20883 for attr in iter {
20884 if let OpGetchainDumpReply::Use(val) = attr? {
20885 return Ok(val);
20886 }
20887 }
20888 Err(ErrorContext::new_missing(
20889 "OpGetchainDumpReply",
20890 "Use",
20891 self.orig_loc,
20892 self.buf.as_ptr() as usize,
20893 ))
20894 }
20895 #[doc = "type name of the chain"]
20896 pub fn get_type(&self) -> Result<&'a CStr, ErrorContext> {
20897 let mut iter = self.clone();
20898 iter.pos = 0;
20899 for attr in iter {
20900 if let OpGetchainDumpReply::Type(val) = attr? {
20901 return Ok(val);
20902 }
20903 }
20904 Err(ErrorContext::new_missing(
20905 "OpGetchainDumpReply",
20906 "Type",
20907 self.orig_loc,
20908 self.buf.as_ptr() as usize,
20909 ))
20910 }
20911 #[doc = "counter specification of the chain"]
20912 pub fn get_counters(&self) -> Result<IterableNftCounterAttrs<'a>, ErrorContext> {
20913 let mut iter = self.clone();
20914 iter.pos = 0;
20915 for attr in iter {
20916 if let OpGetchainDumpReply::Counters(val) = attr? {
20917 return Ok(val);
20918 }
20919 }
20920 Err(ErrorContext::new_missing(
20921 "OpGetchainDumpReply",
20922 "Counters",
20923 self.orig_loc,
20924 self.buf.as_ptr() as usize,
20925 ))
20926 }
20927 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
20928 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
20929 let mut iter = self.clone();
20930 iter.pos = 0;
20931 for attr in iter {
20932 if let OpGetchainDumpReply::Flags(val) = attr? {
20933 return Ok(val);
20934 }
20935 }
20936 Err(ErrorContext::new_missing(
20937 "OpGetchainDumpReply",
20938 "Flags",
20939 self.orig_loc,
20940 self.buf.as_ptr() as usize,
20941 ))
20942 }
20943 #[doc = "uniquely identifies a chain in a transaction"]
20944 pub fn get_id(&self) -> Result<u32, ErrorContext> {
20945 let mut iter = self.clone();
20946 iter.pos = 0;
20947 for attr in iter {
20948 if let OpGetchainDumpReply::Id(val) = attr? {
20949 return Ok(val);
20950 }
20951 }
20952 Err(ErrorContext::new_missing(
20953 "OpGetchainDumpReply",
20954 "Id",
20955 self.orig_loc,
20956 self.buf.as_ptr() as usize,
20957 ))
20958 }
20959 #[doc = "user data"]
20960 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
20961 let mut iter = self.clone();
20962 iter.pos = 0;
20963 for attr in iter {
20964 if let OpGetchainDumpReply::Userdata(val) = attr? {
20965 return Ok(val);
20966 }
20967 }
20968 Err(ErrorContext::new_missing(
20969 "OpGetchainDumpReply",
20970 "Userdata",
20971 self.orig_loc,
20972 self.buf.as_ptr() as usize,
20973 ))
20974 }
20975}
20976impl<'a> OpGetchainDumpReply<'a> {
20977 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetchainDumpReply<'a>) {
20978 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
20979 (
20980 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
20981 IterableOpGetchainDumpReply::with_loc(attrs, buf.as_ptr() as usize),
20982 )
20983 }
20984 fn attr_from_type(r#type: u16) -> Option<&'static str> {
20985 ChainAttrs::attr_from_type(r#type)
20986 }
20987}
20988#[derive(Clone, Copy, Default)]
20989pub struct IterableOpGetchainDumpReply<'a> {
20990 buf: &'a [u8],
20991 pos: usize,
20992 orig_loc: usize,
20993}
20994impl<'a> IterableOpGetchainDumpReply<'a> {
20995 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
20996 Self {
20997 buf,
20998 pos: 0,
20999 orig_loc,
21000 }
21001 }
21002 pub fn get_buf(&self) -> &'a [u8] {
21003 self.buf
21004 }
21005}
21006impl<'a> Iterator for IterableOpGetchainDumpReply<'a> {
21007 type Item = Result<OpGetchainDumpReply<'a>, ErrorContext>;
21008 fn next(&mut self) -> Option<Self::Item> {
21009 if self.buf.len() == self.pos {
21010 return None;
21011 }
21012 let pos = self.pos;
21013 let mut r#type = None;
21014 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
21015 r#type = Some(header.r#type);
21016 let res = match header.r#type {
21017 1u16 => OpGetchainDumpReply::Table({
21018 let res = CStr::from_bytes_with_nul(next).ok();
21019 let Some(val) = res else { break };
21020 val
21021 }),
21022 2u16 => OpGetchainDumpReply::Handle({
21023 let res = parse_be_u64(next);
21024 let Some(val) = res else { break };
21025 val
21026 }),
21027 3u16 => OpGetchainDumpReply::Name({
21028 let res = CStr::from_bytes_with_nul(next).ok();
21029 let Some(val) = res else { break };
21030 val
21031 }),
21032 4u16 => OpGetchainDumpReply::Hook({
21033 let res = Some(IterableNftHookAttrs::with_loc(next, self.orig_loc));
21034 let Some(val) = res else { break };
21035 val
21036 }),
21037 5u16 => OpGetchainDumpReply::Policy({
21038 let res = parse_be_u32(next);
21039 let Some(val) = res else { break };
21040 val
21041 }),
21042 6u16 => OpGetchainDumpReply::Use({
21043 let res = parse_be_u32(next);
21044 let Some(val) = res else { break };
21045 val
21046 }),
21047 7u16 => OpGetchainDumpReply::Type({
21048 let res = CStr::from_bytes_with_nul(next).ok();
21049 let Some(val) = res else { break };
21050 val
21051 }),
21052 8u16 => OpGetchainDumpReply::Counters({
21053 let res = Some(IterableNftCounterAttrs::with_loc(next, self.orig_loc));
21054 let Some(val) = res else { break };
21055 val
21056 }),
21057 9u16 => OpGetchainDumpReply::Flags({
21058 let res = parse_be_u32(next);
21059 let Some(val) = res else { break };
21060 val
21061 }),
21062 10u16 => OpGetchainDumpReply::Id({
21063 let res = parse_be_u32(next);
21064 let Some(val) = res else { break };
21065 val
21066 }),
21067 11u16 => OpGetchainDumpReply::Userdata({
21068 let res = Some(next);
21069 let Some(val) = res else { break };
21070 val
21071 }),
21072 n => {
21073 if cfg!(any(test, feature = "deny-unknown-attrs")) {
21074 break;
21075 } else {
21076 continue;
21077 }
21078 }
21079 };
21080 return Some(Ok(res));
21081 }
21082 Some(Err(ErrorContext::new(
21083 "OpGetchainDumpReply",
21084 r#type.and_then(|t| OpGetchainDumpReply::attr_from_type(t)),
21085 self.orig_loc,
21086 self.buf.as_ptr().wrapping_add(pos) as usize,
21087 )))
21088 }
21089}
21090impl<'a> std::fmt::Debug for IterableOpGetchainDumpReply<'_> {
21091 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21092 let mut fmt = f.debug_struct("OpGetchainDumpReply");
21093 for attr in self.clone() {
21094 let attr = match attr {
21095 Ok(a) => a,
21096 Err(err) => {
21097 fmt.finish()?;
21098 f.write_str("Err(")?;
21099 err.fmt(f)?;
21100 return f.write_str(")");
21101 }
21102 };
21103 match attr {
21104 OpGetchainDumpReply::Table(val) => fmt.field("Table", &val),
21105 OpGetchainDumpReply::Handle(val) => fmt.field("Handle", &val),
21106 OpGetchainDumpReply::Name(val) => fmt.field("Name", &val),
21107 OpGetchainDumpReply::Hook(val) => fmt.field("Hook", &val),
21108 OpGetchainDumpReply::Policy(val) => fmt.field("Policy", &val),
21109 OpGetchainDumpReply::Use(val) => fmt.field("Use", &val),
21110 OpGetchainDumpReply::Type(val) => fmt.field("Type", &val),
21111 OpGetchainDumpReply::Counters(val) => fmt.field("Counters", &val),
21112 OpGetchainDumpReply::Flags(val) => {
21113 fmt.field("Flags", &FormatFlags(val.into(), ChainFlags::from_value))
21114 }
21115 OpGetchainDumpReply::Id(val) => fmt.field("Id", &val),
21116 OpGetchainDumpReply::Userdata(val) => fmt.field("Userdata", &val),
21117 };
21118 }
21119 fmt.finish()
21120 }
21121}
21122impl IterableOpGetchainDumpReply<'_> {
21123 pub fn lookup_attr(
21124 &self,
21125 offset: usize,
21126 missing_type: Option<u16>,
21127 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
21128 let mut stack = Vec::new();
21129 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
21130 if cur == offset + PushNfgenmsg::len() {
21131 stack.push(("OpGetchainDumpReply", offset));
21132 return (
21133 stack,
21134 missing_type.and_then(|t| OpGetchainDumpReply::attr_from_type(t)),
21135 );
21136 }
21137 if cur > offset || cur + self.buf.len() < offset {
21138 return (stack, None);
21139 }
21140 let mut attrs = self.clone();
21141 let mut last_off = cur + attrs.pos;
21142 let mut missing = None;
21143 while let Some(attr) = attrs.next() {
21144 let Ok(attr) = attr else { break };
21145 match attr {
21146 OpGetchainDumpReply::Table(val) => {
21147 if last_off == offset {
21148 stack.push(("Table", last_off));
21149 break;
21150 }
21151 }
21152 OpGetchainDumpReply::Handle(val) => {
21153 if last_off == offset {
21154 stack.push(("Handle", last_off));
21155 break;
21156 }
21157 }
21158 OpGetchainDumpReply::Name(val) => {
21159 if last_off == offset {
21160 stack.push(("Name", last_off));
21161 break;
21162 }
21163 }
21164 OpGetchainDumpReply::Hook(val) => {
21165 (stack, missing) = val.lookup_attr(offset, missing_type);
21166 if !stack.is_empty() {
21167 break;
21168 }
21169 }
21170 OpGetchainDumpReply::Policy(val) => {
21171 if last_off == offset {
21172 stack.push(("Policy", last_off));
21173 break;
21174 }
21175 }
21176 OpGetchainDumpReply::Use(val) => {
21177 if last_off == offset {
21178 stack.push(("Use", last_off));
21179 break;
21180 }
21181 }
21182 OpGetchainDumpReply::Type(val) => {
21183 if last_off == offset {
21184 stack.push(("Type", last_off));
21185 break;
21186 }
21187 }
21188 OpGetchainDumpReply::Counters(val) => {
21189 (stack, missing) = val.lookup_attr(offset, missing_type);
21190 if !stack.is_empty() {
21191 break;
21192 }
21193 }
21194 OpGetchainDumpReply::Flags(val) => {
21195 if last_off == offset {
21196 stack.push(("Flags", last_off));
21197 break;
21198 }
21199 }
21200 OpGetchainDumpReply::Id(val) => {
21201 if last_off == offset {
21202 stack.push(("Id", last_off));
21203 break;
21204 }
21205 }
21206 OpGetchainDumpReply::Userdata(val) => {
21207 if last_off == offset {
21208 stack.push(("Userdata", last_off));
21209 break;
21210 }
21211 }
21212 _ => {}
21213 };
21214 last_off = cur + attrs.pos;
21215 }
21216 if !stack.is_empty() {
21217 stack.push(("OpGetchainDumpReply", cur));
21218 }
21219 (stack, missing)
21220 }
21221}
21222#[derive(Debug)]
21223pub struct RequestOpGetchainDumpRequest<'r> {
21224 request: Request<'r>,
21225}
21226impl<'r> RequestOpGetchainDumpRequest<'r> {
21227 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
21228 PushOpGetchainDumpRequest::write_header(&mut request.buf_mut(), header);
21229 Self {
21230 request: request.set_dump(),
21231 }
21232 }
21233 pub fn encode(&mut self) -> PushOpGetchainDumpRequest<&mut Vec<u8>> {
21234 PushOpGetchainDumpRequest::new_without_header(self.request.buf_mut())
21235 }
21236 pub fn into_encoder(self) -> PushOpGetchainDumpRequest<RequestBuf<'r>> {
21237 PushOpGetchainDumpRequest::new_without_header(self.request.buf)
21238 }
21239}
21240impl NetlinkRequest for RequestOpGetchainDumpRequest<'_> {
21241 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetchainDumpReply<'buf>);
21242 fn protocol(&self) -> Protocol {
21243 Protocol::Raw {
21244 protonum: 12u16,
21245 request_type: 2564u16,
21246 }
21247 }
21248 fn flags(&self) -> u16 {
21249 self.request.flags
21250 }
21251 fn payload(&self) -> &[u8] {
21252 self.request.buf()
21253 }
21254 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
21255 OpGetchainDumpReply::new(buf)
21256 }
21257 fn lookup(
21258 buf: &[u8],
21259 offset: usize,
21260 missing_type: Option<u16>,
21261 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
21262 OpGetchainDumpRequest::new(buf)
21263 .1
21264 .lookup_attr(offset, missing_type)
21265 }
21266}
21267#[doc = "Get / dump chains."]
21268pub struct PushOpGetchainDoRequest<Prev: Rec> {
21269 pub(crate) prev: Option<Prev>,
21270 pub(crate) header_offset: Option<usize>,
21271}
21272impl<Prev: Rec> Rec for PushOpGetchainDoRequest<Prev> {
21273 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
21274 self.prev.as_mut().unwrap().as_rec_mut()
21275 }
21276}
21277impl<Prev: Rec> PushOpGetchainDoRequest<Prev> {
21278 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
21279 Self::write_header(&mut prev, header);
21280 Self::new_without_header(prev)
21281 }
21282 fn new_without_header(prev: Prev) -> Self {
21283 Self {
21284 prev: Some(prev),
21285 header_offset: None,
21286 }
21287 }
21288 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
21289 prev.as_rec_mut().extend(header.as_slice());
21290 }
21291 pub fn end_nested(mut self) -> Prev {
21292 let mut prev = self.prev.take().unwrap();
21293 if let Some(header_offset) = &self.header_offset {
21294 finalize_nested_header(prev.as_rec_mut(), *header_offset);
21295 }
21296 prev
21297 }
21298 #[doc = "name of the table containing the chain"]
21299 pub fn push_table(mut self, value: &CStr) -> Self {
21300 push_header(
21301 self.as_rec_mut(),
21302 1u16,
21303 value.to_bytes_with_nul().len() as u16,
21304 );
21305 self.as_rec_mut().extend(value.to_bytes_with_nul());
21306 self
21307 }
21308 #[doc = "name of the table containing the chain"]
21309 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
21310 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
21311 self.as_rec_mut().extend(value);
21312 self.as_rec_mut().push(0);
21313 self
21314 }
21315 #[doc = "name of the chain"]
21316 pub fn push_name(mut self, value: &CStr) -> Self {
21317 push_header(
21318 self.as_rec_mut(),
21319 3u16,
21320 value.to_bytes_with_nul().len() as u16,
21321 );
21322 self.as_rec_mut().extend(value.to_bytes_with_nul());
21323 self
21324 }
21325 #[doc = "name of the chain"]
21326 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
21327 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
21328 self.as_rec_mut().extend(value);
21329 self.as_rec_mut().push(0);
21330 self
21331 }
21332}
21333impl<Prev: Rec> Drop for PushOpGetchainDoRequest<Prev> {
21334 fn drop(&mut self) {
21335 if let Some(prev) = &mut self.prev {
21336 if let Some(header_offset) = &self.header_offset {
21337 finalize_nested_header(prev.as_rec_mut(), *header_offset);
21338 }
21339 }
21340 }
21341}
21342#[doc = "Get / dump chains."]
21343#[derive(Clone)]
21344pub enum OpGetchainDoRequest<'a> {
21345 #[doc = "name of the table containing the chain"]
21346 Table(&'a CStr),
21347 #[doc = "name of the chain"]
21348 Name(&'a CStr),
21349}
21350impl<'a> IterableOpGetchainDoRequest<'a> {
21351 #[doc = "name of the table containing the chain"]
21352 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
21353 let mut iter = self.clone();
21354 iter.pos = 0;
21355 for attr in iter {
21356 if let OpGetchainDoRequest::Table(val) = attr? {
21357 return Ok(val);
21358 }
21359 }
21360 Err(ErrorContext::new_missing(
21361 "OpGetchainDoRequest",
21362 "Table",
21363 self.orig_loc,
21364 self.buf.as_ptr() as usize,
21365 ))
21366 }
21367 #[doc = "name of the chain"]
21368 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
21369 let mut iter = self.clone();
21370 iter.pos = 0;
21371 for attr in iter {
21372 if let OpGetchainDoRequest::Name(val) = attr? {
21373 return Ok(val);
21374 }
21375 }
21376 Err(ErrorContext::new_missing(
21377 "OpGetchainDoRequest",
21378 "Name",
21379 self.orig_loc,
21380 self.buf.as_ptr() as usize,
21381 ))
21382 }
21383}
21384impl<'a> OpGetchainDoRequest<'a> {
21385 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetchainDoRequest<'a>) {
21386 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
21387 (
21388 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
21389 IterableOpGetchainDoRequest::with_loc(attrs, buf.as_ptr() as usize),
21390 )
21391 }
21392 fn attr_from_type(r#type: u16) -> Option<&'static str> {
21393 ChainAttrs::attr_from_type(r#type)
21394 }
21395}
21396#[derive(Clone, Copy, Default)]
21397pub struct IterableOpGetchainDoRequest<'a> {
21398 buf: &'a [u8],
21399 pos: usize,
21400 orig_loc: usize,
21401}
21402impl<'a> IterableOpGetchainDoRequest<'a> {
21403 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
21404 Self {
21405 buf,
21406 pos: 0,
21407 orig_loc,
21408 }
21409 }
21410 pub fn get_buf(&self) -> &'a [u8] {
21411 self.buf
21412 }
21413}
21414impl<'a> Iterator for IterableOpGetchainDoRequest<'a> {
21415 type Item = Result<OpGetchainDoRequest<'a>, ErrorContext>;
21416 fn next(&mut self) -> Option<Self::Item> {
21417 if self.buf.len() == self.pos {
21418 return None;
21419 }
21420 let pos = self.pos;
21421 let mut r#type = None;
21422 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
21423 r#type = Some(header.r#type);
21424 let res = match header.r#type {
21425 1u16 => OpGetchainDoRequest::Table({
21426 let res = CStr::from_bytes_with_nul(next).ok();
21427 let Some(val) = res else { break };
21428 val
21429 }),
21430 3u16 => OpGetchainDoRequest::Name({
21431 let res = CStr::from_bytes_with_nul(next).ok();
21432 let Some(val) = res else { break };
21433 val
21434 }),
21435 n => {
21436 if cfg!(any(test, feature = "deny-unknown-attrs")) {
21437 break;
21438 } else {
21439 continue;
21440 }
21441 }
21442 };
21443 return Some(Ok(res));
21444 }
21445 Some(Err(ErrorContext::new(
21446 "OpGetchainDoRequest",
21447 r#type.and_then(|t| OpGetchainDoRequest::attr_from_type(t)),
21448 self.orig_loc,
21449 self.buf.as_ptr().wrapping_add(pos) as usize,
21450 )))
21451 }
21452}
21453impl<'a> std::fmt::Debug for IterableOpGetchainDoRequest<'_> {
21454 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21455 let mut fmt = f.debug_struct("OpGetchainDoRequest");
21456 for attr in self.clone() {
21457 let attr = match attr {
21458 Ok(a) => a,
21459 Err(err) => {
21460 fmt.finish()?;
21461 f.write_str("Err(")?;
21462 err.fmt(f)?;
21463 return f.write_str(")");
21464 }
21465 };
21466 match attr {
21467 OpGetchainDoRequest::Table(val) => fmt.field("Table", &val),
21468 OpGetchainDoRequest::Name(val) => fmt.field("Name", &val),
21469 };
21470 }
21471 fmt.finish()
21472 }
21473}
21474impl IterableOpGetchainDoRequest<'_> {
21475 pub fn lookup_attr(
21476 &self,
21477 offset: usize,
21478 missing_type: Option<u16>,
21479 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
21480 let mut stack = Vec::new();
21481 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
21482 if cur == offset + PushNfgenmsg::len() {
21483 stack.push(("OpGetchainDoRequest", offset));
21484 return (
21485 stack,
21486 missing_type.and_then(|t| OpGetchainDoRequest::attr_from_type(t)),
21487 );
21488 }
21489 if cur > offset || cur + self.buf.len() < offset {
21490 return (stack, None);
21491 }
21492 let mut attrs = self.clone();
21493 let mut last_off = cur + attrs.pos;
21494 while let Some(attr) = attrs.next() {
21495 let Ok(attr) = attr else { break };
21496 match attr {
21497 OpGetchainDoRequest::Table(val) => {
21498 if last_off == offset {
21499 stack.push(("Table", last_off));
21500 break;
21501 }
21502 }
21503 OpGetchainDoRequest::Name(val) => {
21504 if last_off == offset {
21505 stack.push(("Name", last_off));
21506 break;
21507 }
21508 }
21509 _ => {}
21510 };
21511 last_off = cur + attrs.pos;
21512 }
21513 if !stack.is_empty() {
21514 stack.push(("OpGetchainDoRequest", cur));
21515 }
21516 (stack, None)
21517 }
21518}
21519#[doc = "Get / dump chains."]
21520pub struct PushOpGetchainDoReply<Prev: Rec> {
21521 pub(crate) prev: Option<Prev>,
21522 pub(crate) header_offset: Option<usize>,
21523}
21524impl<Prev: Rec> Rec for PushOpGetchainDoReply<Prev> {
21525 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
21526 self.prev.as_mut().unwrap().as_rec_mut()
21527 }
21528}
21529impl<Prev: Rec> PushOpGetchainDoReply<Prev> {
21530 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
21531 Self::write_header(&mut prev, header);
21532 Self::new_without_header(prev)
21533 }
21534 fn new_without_header(prev: Prev) -> Self {
21535 Self {
21536 prev: Some(prev),
21537 header_offset: None,
21538 }
21539 }
21540 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
21541 prev.as_rec_mut().extend(header.as_slice());
21542 }
21543 pub fn end_nested(mut self) -> Prev {
21544 let mut prev = self.prev.take().unwrap();
21545 if let Some(header_offset) = &self.header_offset {
21546 finalize_nested_header(prev.as_rec_mut(), *header_offset);
21547 }
21548 prev
21549 }
21550 #[doc = "name of the table containing the chain"]
21551 pub fn push_table(mut self, value: &CStr) -> Self {
21552 push_header(
21553 self.as_rec_mut(),
21554 1u16,
21555 value.to_bytes_with_nul().len() as u16,
21556 );
21557 self.as_rec_mut().extend(value.to_bytes_with_nul());
21558 self
21559 }
21560 #[doc = "name of the table containing the chain"]
21561 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
21562 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
21563 self.as_rec_mut().extend(value);
21564 self.as_rec_mut().push(0);
21565 self
21566 }
21567 #[doc = "numeric handle of the chain"]
21568 pub fn push_handle(mut self, value: u64) -> Self {
21569 push_header(self.as_rec_mut(), 2u16, 8 as u16);
21570 self.as_rec_mut().extend(value.to_be_bytes());
21571 self
21572 }
21573 #[doc = "name of the chain"]
21574 pub fn push_name(mut self, value: &CStr) -> Self {
21575 push_header(
21576 self.as_rec_mut(),
21577 3u16,
21578 value.to_bytes_with_nul().len() as u16,
21579 );
21580 self.as_rec_mut().extend(value.to_bytes_with_nul());
21581 self
21582 }
21583 #[doc = "name of the chain"]
21584 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
21585 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
21586 self.as_rec_mut().extend(value);
21587 self.as_rec_mut().push(0);
21588 self
21589 }
21590 #[doc = "hook specification for basechains"]
21591 pub fn nested_hook(mut self) -> PushNftHookAttrs<Self> {
21592 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
21593 PushNftHookAttrs {
21594 prev: Some(self),
21595 header_offset: Some(header_offset),
21596 }
21597 }
21598 #[doc = "numeric policy of the chain"]
21599 pub fn push_policy(mut self, value: u32) -> Self {
21600 push_header(self.as_rec_mut(), 5u16, 4 as u16);
21601 self.as_rec_mut().extend(value.to_be_bytes());
21602 self
21603 }
21604 #[doc = "number of references to this chain"]
21605 pub fn push_use(mut self, value: u32) -> Self {
21606 push_header(self.as_rec_mut(), 6u16, 4 as u16);
21607 self.as_rec_mut().extend(value.to_be_bytes());
21608 self
21609 }
21610 #[doc = "type name of the chain"]
21611 pub fn push_type(mut self, value: &CStr) -> Self {
21612 push_header(
21613 self.as_rec_mut(),
21614 7u16,
21615 value.to_bytes_with_nul().len() as u16,
21616 );
21617 self.as_rec_mut().extend(value.to_bytes_with_nul());
21618 self
21619 }
21620 #[doc = "type name of the chain"]
21621 pub fn push_type_bytes(mut self, value: &[u8]) -> Self {
21622 push_header(self.as_rec_mut(), 7u16, (value.len() + 1) as u16);
21623 self.as_rec_mut().extend(value);
21624 self.as_rec_mut().push(0);
21625 self
21626 }
21627 #[doc = "counter specification of the chain"]
21628 pub fn nested_counters(mut self) -> PushNftCounterAttrs<Self> {
21629 let header_offset = push_nested_header(self.as_rec_mut(), 8u16);
21630 PushNftCounterAttrs {
21631 prev: Some(self),
21632 header_offset: Some(header_offset),
21633 }
21634 }
21635 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
21636 pub fn push_flags(mut self, value: u32) -> Self {
21637 push_header(self.as_rec_mut(), 9u16, 4 as u16);
21638 self.as_rec_mut().extend(value.to_be_bytes());
21639 self
21640 }
21641 #[doc = "uniquely identifies a chain in a transaction"]
21642 pub fn push_id(mut self, value: u32) -> Self {
21643 push_header(self.as_rec_mut(), 10u16, 4 as u16);
21644 self.as_rec_mut().extend(value.to_be_bytes());
21645 self
21646 }
21647 #[doc = "user data"]
21648 pub fn push_userdata(mut self, value: &[u8]) -> Self {
21649 push_header(self.as_rec_mut(), 11u16, value.len() as u16);
21650 self.as_rec_mut().extend(value);
21651 self
21652 }
21653}
21654impl<Prev: Rec> Drop for PushOpGetchainDoReply<Prev> {
21655 fn drop(&mut self) {
21656 if let Some(prev) = &mut self.prev {
21657 if let Some(header_offset) = &self.header_offset {
21658 finalize_nested_header(prev.as_rec_mut(), *header_offset);
21659 }
21660 }
21661 }
21662}
21663#[doc = "Get / dump chains."]
21664#[derive(Clone)]
21665pub enum OpGetchainDoReply<'a> {
21666 #[doc = "name of the table containing the chain"]
21667 Table(&'a CStr),
21668 #[doc = "numeric handle of the chain"]
21669 Handle(u64),
21670 #[doc = "name of the chain"]
21671 Name(&'a CStr),
21672 #[doc = "hook specification for basechains"]
21673 Hook(IterableNftHookAttrs<'a>),
21674 #[doc = "numeric policy of the chain"]
21675 Policy(u32),
21676 #[doc = "number of references to this chain"]
21677 Use(u32),
21678 #[doc = "type name of the chain"]
21679 Type(&'a CStr),
21680 #[doc = "counter specification of the chain"]
21681 Counters(IterableNftCounterAttrs<'a>),
21682 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
21683 Flags(u32),
21684 #[doc = "uniquely identifies a chain in a transaction"]
21685 Id(u32),
21686 #[doc = "user data"]
21687 Userdata(&'a [u8]),
21688}
21689impl<'a> IterableOpGetchainDoReply<'a> {
21690 #[doc = "name of the table containing the chain"]
21691 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
21692 let mut iter = self.clone();
21693 iter.pos = 0;
21694 for attr in iter {
21695 if let OpGetchainDoReply::Table(val) = attr? {
21696 return Ok(val);
21697 }
21698 }
21699 Err(ErrorContext::new_missing(
21700 "OpGetchainDoReply",
21701 "Table",
21702 self.orig_loc,
21703 self.buf.as_ptr() as usize,
21704 ))
21705 }
21706 #[doc = "numeric handle of the chain"]
21707 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
21708 let mut iter = self.clone();
21709 iter.pos = 0;
21710 for attr in iter {
21711 if let OpGetchainDoReply::Handle(val) = attr? {
21712 return Ok(val);
21713 }
21714 }
21715 Err(ErrorContext::new_missing(
21716 "OpGetchainDoReply",
21717 "Handle",
21718 self.orig_loc,
21719 self.buf.as_ptr() as usize,
21720 ))
21721 }
21722 #[doc = "name of the chain"]
21723 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
21724 let mut iter = self.clone();
21725 iter.pos = 0;
21726 for attr in iter {
21727 if let OpGetchainDoReply::Name(val) = attr? {
21728 return Ok(val);
21729 }
21730 }
21731 Err(ErrorContext::new_missing(
21732 "OpGetchainDoReply",
21733 "Name",
21734 self.orig_loc,
21735 self.buf.as_ptr() as usize,
21736 ))
21737 }
21738 #[doc = "hook specification for basechains"]
21739 pub fn get_hook(&self) -> Result<IterableNftHookAttrs<'a>, ErrorContext> {
21740 let mut iter = self.clone();
21741 iter.pos = 0;
21742 for attr in iter {
21743 if let OpGetchainDoReply::Hook(val) = attr? {
21744 return Ok(val);
21745 }
21746 }
21747 Err(ErrorContext::new_missing(
21748 "OpGetchainDoReply",
21749 "Hook",
21750 self.orig_loc,
21751 self.buf.as_ptr() as usize,
21752 ))
21753 }
21754 #[doc = "numeric policy of the chain"]
21755 pub fn get_policy(&self) -> Result<u32, ErrorContext> {
21756 let mut iter = self.clone();
21757 iter.pos = 0;
21758 for attr in iter {
21759 if let OpGetchainDoReply::Policy(val) = attr? {
21760 return Ok(val);
21761 }
21762 }
21763 Err(ErrorContext::new_missing(
21764 "OpGetchainDoReply",
21765 "Policy",
21766 self.orig_loc,
21767 self.buf.as_ptr() as usize,
21768 ))
21769 }
21770 #[doc = "number of references to this chain"]
21771 pub fn get_use(&self) -> Result<u32, ErrorContext> {
21772 let mut iter = self.clone();
21773 iter.pos = 0;
21774 for attr in iter {
21775 if let OpGetchainDoReply::Use(val) = attr? {
21776 return Ok(val);
21777 }
21778 }
21779 Err(ErrorContext::new_missing(
21780 "OpGetchainDoReply",
21781 "Use",
21782 self.orig_loc,
21783 self.buf.as_ptr() as usize,
21784 ))
21785 }
21786 #[doc = "type name of the chain"]
21787 pub fn get_type(&self) -> Result<&'a CStr, ErrorContext> {
21788 let mut iter = self.clone();
21789 iter.pos = 0;
21790 for attr in iter {
21791 if let OpGetchainDoReply::Type(val) = attr? {
21792 return Ok(val);
21793 }
21794 }
21795 Err(ErrorContext::new_missing(
21796 "OpGetchainDoReply",
21797 "Type",
21798 self.orig_loc,
21799 self.buf.as_ptr() as usize,
21800 ))
21801 }
21802 #[doc = "counter specification of the chain"]
21803 pub fn get_counters(&self) -> Result<IterableNftCounterAttrs<'a>, ErrorContext> {
21804 let mut iter = self.clone();
21805 iter.pos = 0;
21806 for attr in iter {
21807 if let OpGetchainDoReply::Counters(val) = attr? {
21808 return Ok(val);
21809 }
21810 }
21811 Err(ErrorContext::new_missing(
21812 "OpGetchainDoReply",
21813 "Counters",
21814 self.orig_loc,
21815 self.buf.as_ptr() as usize,
21816 ))
21817 }
21818 #[doc = "chain flags\nAssociated type: \"ChainFlags\" (1 bit per enumeration)"]
21819 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
21820 let mut iter = self.clone();
21821 iter.pos = 0;
21822 for attr in iter {
21823 if let OpGetchainDoReply::Flags(val) = attr? {
21824 return Ok(val);
21825 }
21826 }
21827 Err(ErrorContext::new_missing(
21828 "OpGetchainDoReply",
21829 "Flags",
21830 self.orig_loc,
21831 self.buf.as_ptr() as usize,
21832 ))
21833 }
21834 #[doc = "uniquely identifies a chain in a transaction"]
21835 pub fn get_id(&self) -> Result<u32, ErrorContext> {
21836 let mut iter = self.clone();
21837 iter.pos = 0;
21838 for attr in iter {
21839 if let OpGetchainDoReply::Id(val) = attr? {
21840 return Ok(val);
21841 }
21842 }
21843 Err(ErrorContext::new_missing(
21844 "OpGetchainDoReply",
21845 "Id",
21846 self.orig_loc,
21847 self.buf.as_ptr() as usize,
21848 ))
21849 }
21850 #[doc = "user data"]
21851 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
21852 let mut iter = self.clone();
21853 iter.pos = 0;
21854 for attr in iter {
21855 if let OpGetchainDoReply::Userdata(val) = attr? {
21856 return Ok(val);
21857 }
21858 }
21859 Err(ErrorContext::new_missing(
21860 "OpGetchainDoReply",
21861 "Userdata",
21862 self.orig_loc,
21863 self.buf.as_ptr() as usize,
21864 ))
21865 }
21866}
21867impl<'a> OpGetchainDoReply<'a> {
21868 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetchainDoReply<'a>) {
21869 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
21870 (
21871 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
21872 IterableOpGetchainDoReply::with_loc(attrs, buf.as_ptr() as usize),
21873 )
21874 }
21875 fn attr_from_type(r#type: u16) -> Option<&'static str> {
21876 ChainAttrs::attr_from_type(r#type)
21877 }
21878}
21879#[derive(Clone, Copy, Default)]
21880pub struct IterableOpGetchainDoReply<'a> {
21881 buf: &'a [u8],
21882 pos: usize,
21883 orig_loc: usize,
21884}
21885impl<'a> IterableOpGetchainDoReply<'a> {
21886 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
21887 Self {
21888 buf,
21889 pos: 0,
21890 orig_loc,
21891 }
21892 }
21893 pub fn get_buf(&self) -> &'a [u8] {
21894 self.buf
21895 }
21896}
21897impl<'a> Iterator for IterableOpGetchainDoReply<'a> {
21898 type Item = Result<OpGetchainDoReply<'a>, ErrorContext>;
21899 fn next(&mut self) -> Option<Self::Item> {
21900 if self.buf.len() == self.pos {
21901 return None;
21902 }
21903 let pos = self.pos;
21904 let mut r#type = None;
21905 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
21906 r#type = Some(header.r#type);
21907 let res = match header.r#type {
21908 1u16 => OpGetchainDoReply::Table({
21909 let res = CStr::from_bytes_with_nul(next).ok();
21910 let Some(val) = res else { break };
21911 val
21912 }),
21913 2u16 => OpGetchainDoReply::Handle({
21914 let res = parse_be_u64(next);
21915 let Some(val) = res else { break };
21916 val
21917 }),
21918 3u16 => OpGetchainDoReply::Name({
21919 let res = CStr::from_bytes_with_nul(next).ok();
21920 let Some(val) = res else { break };
21921 val
21922 }),
21923 4u16 => OpGetchainDoReply::Hook({
21924 let res = Some(IterableNftHookAttrs::with_loc(next, self.orig_loc));
21925 let Some(val) = res else { break };
21926 val
21927 }),
21928 5u16 => OpGetchainDoReply::Policy({
21929 let res = parse_be_u32(next);
21930 let Some(val) = res else { break };
21931 val
21932 }),
21933 6u16 => OpGetchainDoReply::Use({
21934 let res = parse_be_u32(next);
21935 let Some(val) = res else { break };
21936 val
21937 }),
21938 7u16 => OpGetchainDoReply::Type({
21939 let res = CStr::from_bytes_with_nul(next).ok();
21940 let Some(val) = res else { break };
21941 val
21942 }),
21943 8u16 => OpGetchainDoReply::Counters({
21944 let res = Some(IterableNftCounterAttrs::with_loc(next, self.orig_loc));
21945 let Some(val) = res else { break };
21946 val
21947 }),
21948 9u16 => OpGetchainDoReply::Flags({
21949 let res = parse_be_u32(next);
21950 let Some(val) = res else { break };
21951 val
21952 }),
21953 10u16 => OpGetchainDoReply::Id({
21954 let res = parse_be_u32(next);
21955 let Some(val) = res else { break };
21956 val
21957 }),
21958 11u16 => OpGetchainDoReply::Userdata({
21959 let res = Some(next);
21960 let Some(val) = res else { break };
21961 val
21962 }),
21963 n => {
21964 if cfg!(any(test, feature = "deny-unknown-attrs")) {
21965 break;
21966 } else {
21967 continue;
21968 }
21969 }
21970 };
21971 return Some(Ok(res));
21972 }
21973 Some(Err(ErrorContext::new(
21974 "OpGetchainDoReply",
21975 r#type.and_then(|t| OpGetchainDoReply::attr_from_type(t)),
21976 self.orig_loc,
21977 self.buf.as_ptr().wrapping_add(pos) as usize,
21978 )))
21979 }
21980}
21981impl<'a> std::fmt::Debug for IterableOpGetchainDoReply<'_> {
21982 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21983 let mut fmt = f.debug_struct("OpGetchainDoReply");
21984 for attr in self.clone() {
21985 let attr = match attr {
21986 Ok(a) => a,
21987 Err(err) => {
21988 fmt.finish()?;
21989 f.write_str("Err(")?;
21990 err.fmt(f)?;
21991 return f.write_str(")");
21992 }
21993 };
21994 match attr {
21995 OpGetchainDoReply::Table(val) => fmt.field("Table", &val),
21996 OpGetchainDoReply::Handle(val) => fmt.field("Handle", &val),
21997 OpGetchainDoReply::Name(val) => fmt.field("Name", &val),
21998 OpGetchainDoReply::Hook(val) => fmt.field("Hook", &val),
21999 OpGetchainDoReply::Policy(val) => fmt.field("Policy", &val),
22000 OpGetchainDoReply::Use(val) => fmt.field("Use", &val),
22001 OpGetchainDoReply::Type(val) => fmt.field("Type", &val),
22002 OpGetchainDoReply::Counters(val) => fmt.field("Counters", &val),
22003 OpGetchainDoReply::Flags(val) => {
22004 fmt.field("Flags", &FormatFlags(val.into(), ChainFlags::from_value))
22005 }
22006 OpGetchainDoReply::Id(val) => fmt.field("Id", &val),
22007 OpGetchainDoReply::Userdata(val) => fmt.field("Userdata", &val),
22008 };
22009 }
22010 fmt.finish()
22011 }
22012}
22013impl IterableOpGetchainDoReply<'_> {
22014 pub fn lookup_attr(
22015 &self,
22016 offset: usize,
22017 missing_type: Option<u16>,
22018 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22019 let mut stack = Vec::new();
22020 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
22021 if cur == offset + PushNfgenmsg::len() {
22022 stack.push(("OpGetchainDoReply", offset));
22023 return (
22024 stack,
22025 missing_type.and_then(|t| OpGetchainDoReply::attr_from_type(t)),
22026 );
22027 }
22028 if cur > offset || cur + self.buf.len() < offset {
22029 return (stack, None);
22030 }
22031 let mut attrs = self.clone();
22032 let mut last_off = cur + attrs.pos;
22033 let mut missing = None;
22034 while let Some(attr) = attrs.next() {
22035 let Ok(attr) = attr else { break };
22036 match attr {
22037 OpGetchainDoReply::Table(val) => {
22038 if last_off == offset {
22039 stack.push(("Table", last_off));
22040 break;
22041 }
22042 }
22043 OpGetchainDoReply::Handle(val) => {
22044 if last_off == offset {
22045 stack.push(("Handle", last_off));
22046 break;
22047 }
22048 }
22049 OpGetchainDoReply::Name(val) => {
22050 if last_off == offset {
22051 stack.push(("Name", last_off));
22052 break;
22053 }
22054 }
22055 OpGetchainDoReply::Hook(val) => {
22056 (stack, missing) = val.lookup_attr(offset, missing_type);
22057 if !stack.is_empty() {
22058 break;
22059 }
22060 }
22061 OpGetchainDoReply::Policy(val) => {
22062 if last_off == offset {
22063 stack.push(("Policy", last_off));
22064 break;
22065 }
22066 }
22067 OpGetchainDoReply::Use(val) => {
22068 if last_off == offset {
22069 stack.push(("Use", last_off));
22070 break;
22071 }
22072 }
22073 OpGetchainDoReply::Type(val) => {
22074 if last_off == offset {
22075 stack.push(("Type", last_off));
22076 break;
22077 }
22078 }
22079 OpGetchainDoReply::Counters(val) => {
22080 (stack, missing) = val.lookup_attr(offset, missing_type);
22081 if !stack.is_empty() {
22082 break;
22083 }
22084 }
22085 OpGetchainDoReply::Flags(val) => {
22086 if last_off == offset {
22087 stack.push(("Flags", last_off));
22088 break;
22089 }
22090 }
22091 OpGetchainDoReply::Id(val) => {
22092 if last_off == offset {
22093 stack.push(("Id", last_off));
22094 break;
22095 }
22096 }
22097 OpGetchainDoReply::Userdata(val) => {
22098 if last_off == offset {
22099 stack.push(("Userdata", last_off));
22100 break;
22101 }
22102 }
22103 _ => {}
22104 };
22105 last_off = cur + attrs.pos;
22106 }
22107 if !stack.is_empty() {
22108 stack.push(("OpGetchainDoReply", cur));
22109 }
22110 (stack, missing)
22111 }
22112}
22113#[derive(Debug)]
22114pub struct RequestOpGetchainDoRequest<'r> {
22115 request: Request<'r>,
22116}
22117impl<'r> RequestOpGetchainDoRequest<'r> {
22118 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
22119 PushOpGetchainDoRequest::write_header(&mut request.buf_mut(), header);
22120 Self { request: request }
22121 }
22122 pub fn encode(&mut self) -> PushOpGetchainDoRequest<&mut Vec<u8>> {
22123 PushOpGetchainDoRequest::new_without_header(self.request.buf_mut())
22124 }
22125 pub fn into_encoder(self) -> PushOpGetchainDoRequest<RequestBuf<'r>> {
22126 PushOpGetchainDoRequest::new_without_header(self.request.buf)
22127 }
22128}
22129impl NetlinkRequest for RequestOpGetchainDoRequest<'_> {
22130 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetchainDoReply<'buf>);
22131 fn protocol(&self) -> Protocol {
22132 Protocol::Raw {
22133 protonum: 12u16,
22134 request_type: 2564u16,
22135 }
22136 }
22137 fn flags(&self) -> u16 {
22138 self.request.flags
22139 }
22140 fn payload(&self) -> &[u8] {
22141 self.request.buf()
22142 }
22143 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
22144 OpGetchainDoReply::new(buf)
22145 }
22146 fn lookup(
22147 buf: &[u8],
22148 offset: usize,
22149 missing_type: Option<u16>,
22150 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22151 OpGetchainDoRequest::new(buf)
22152 .1
22153 .lookup_attr(offset, missing_type)
22154 }
22155}
22156#[doc = "Delete an existing chain."]
22157pub struct PushOpDelchainDoRequest<Prev: Rec> {
22158 pub(crate) prev: Option<Prev>,
22159 pub(crate) header_offset: Option<usize>,
22160}
22161impl<Prev: Rec> Rec for PushOpDelchainDoRequest<Prev> {
22162 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
22163 self.prev.as_mut().unwrap().as_rec_mut()
22164 }
22165}
22166impl<Prev: Rec> PushOpDelchainDoRequest<Prev> {
22167 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
22168 Self::write_header(&mut prev, header);
22169 Self::new_without_header(prev)
22170 }
22171 fn new_without_header(prev: Prev) -> Self {
22172 Self {
22173 prev: Some(prev),
22174 header_offset: None,
22175 }
22176 }
22177 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
22178 prev.as_rec_mut().extend(header.as_slice());
22179 }
22180 pub fn end_nested(mut self) -> Prev {
22181 let mut prev = self.prev.take().unwrap();
22182 if let Some(header_offset) = &self.header_offset {
22183 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22184 }
22185 prev
22186 }
22187 #[doc = "name of the table containing the chain"]
22188 pub fn push_table(mut self, value: &CStr) -> Self {
22189 push_header(
22190 self.as_rec_mut(),
22191 1u16,
22192 value.to_bytes_with_nul().len() as u16,
22193 );
22194 self.as_rec_mut().extend(value.to_bytes_with_nul());
22195 self
22196 }
22197 #[doc = "name of the table containing the chain"]
22198 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
22199 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
22200 self.as_rec_mut().extend(value);
22201 self.as_rec_mut().push(0);
22202 self
22203 }
22204 #[doc = "numeric handle of the chain"]
22205 pub fn push_handle(mut self, value: u64) -> Self {
22206 push_header(self.as_rec_mut(), 2u16, 8 as u16);
22207 self.as_rec_mut().extend(value.to_be_bytes());
22208 self
22209 }
22210 #[doc = "name of the chain"]
22211 pub fn push_name(mut self, value: &CStr) -> Self {
22212 push_header(
22213 self.as_rec_mut(),
22214 3u16,
22215 value.to_bytes_with_nul().len() as u16,
22216 );
22217 self.as_rec_mut().extend(value.to_bytes_with_nul());
22218 self
22219 }
22220 #[doc = "name of the chain"]
22221 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
22222 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
22223 self.as_rec_mut().extend(value);
22224 self.as_rec_mut().push(0);
22225 self
22226 }
22227 #[doc = "hook specification for basechains"]
22228 pub fn nested_hook(mut self) -> PushNftHookAttrs<Self> {
22229 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
22230 PushNftHookAttrs {
22231 prev: Some(self),
22232 header_offset: Some(header_offset),
22233 }
22234 }
22235}
22236impl<Prev: Rec> Drop for PushOpDelchainDoRequest<Prev> {
22237 fn drop(&mut self) {
22238 if let Some(prev) = &mut self.prev {
22239 if let Some(header_offset) = &self.header_offset {
22240 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22241 }
22242 }
22243 }
22244}
22245#[doc = "Delete an existing chain."]
22246#[derive(Clone)]
22247pub enum OpDelchainDoRequest<'a> {
22248 #[doc = "name of the table containing the chain"]
22249 Table(&'a CStr),
22250 #[doc = "numeric handle of the chain"]
22251 Handle(u64),
22252 #[doc = "name of the chain"]
22253 Name(&'a CStr),
22254 #[doc = "hook specification for basechains"]
22255 Hook(IterableNftHookAttrs<'a>),
22256}
22257impl<'a> IterableOpDelchainDoRequest<'a> {
22258 #[doc = "name of the table containing the chain"]
22259 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
22260 let mut iter = self.clone();
22261 iter.pos = 0;
22262 for attr in iter {
22263 if let OpDelchainDoRequest::Table(val) = attr? {
22264 return Ok(val);
22265 }
22266 }
22267 Err(ErrorContext::new_missing(
22268 "OpDelchainDoRequest",
22269 "Table",
22270 self.orig_loc,
22271 self.buf.as_ptr() as usize,
22272 ))
22273 }
22274 #[doc = "numeric handle of the chain"]
22275 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
22276 let mut iter = self.clone();
22277 iter.pos = 0;
22278 for attr in iter {
22279 if let OpDelchainDoRequest::Handle(val) = attr? {
22280 return Ok(val);
22281 }
22282 }
22283 Err(ErrorContext::new_missing(
22284 "OpDelchainDoRequest",
22285 "Handle",
22286 self.orig_loc,
22287 self.buf.as_ptr() as usize,
22288 ))
22289 }
22290 #[doc = "name of the chain"]
22291 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
22292 let mut iter = self.clone();
22293 iter.pos = 0;
22294 for attr in iter {
22295 if let OpDelchainDoRequest::Name(val) = attr? {
22296 return Ok(val);
22297 }
22298 }
22299 Err(ErrorContext::new_missing(
22300 "OpDelchainDoRequest",
22301 "Name",
22302 self.orig_loc,
22303 self.buf.as_ptr() as usize,
22304 ))
22305 }
22306 #[doc = "hook specification for basechains"]
22307 pub fn get_hook(&self) -> Result<IterableNftHookAttrs<'a>, ErrorContext> {
22308 let mut iter = self.clone();
22309 iter.pos = 0;
22310 for attr in iter {
22311 if let OpDelchainDoRequest::Hook(val) = attr? {
22312 return Ok(val);
22313 }
22314 }
22315 Err(ErrorContext::new_missing(
22316 "OpDelchainDoRequest",
22317 "Hook",
22318 self.orig_loc,
22319 self.buf.as_ptr() as usize,
22320 ))
22321 }
22322}
22323impl<'a> OpDelchainDoRequest<'a> {
22324 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDelchainDoRequest<'a>) {
22325 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
22326 (
22327 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
22328 IterableOpDelchainDoRequest::with_loc(attrs, buf.as_ptr() as usize),
22329 )
22330 }
22331 fn attr_from_type(r#type: u16) -> Option<&'static str> {
22332 ChainAttrs::attr_from_type(r#type)
22333 }
22334}
22335#[derive(Clone, Copy, Default)]
22336pub struct IterableOpDelchainDoRequest<'a> {
22337 buf: &'a [u8],
22338 pos: usize,
22339 orig_loc: usize,
22340}
22341impl<'a> IterableOpDelchainDoRequest<'a> {
22342 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22343 Self {
22344 buf,
22345 pos: 0,
22346 orig_loc,
22347 }
22348 }
22349 pub fn get_buf(&self) -> &'a [u8] {
22350 self.buf
22351 }
22352}
22353impl<'a> Iterator for IterableOpDelchainDoRequest<'a> {
22354 type Item = Result<OpDelchainDoRequest<'a>, ErrorContext>;
22355 fn next(&mut self) -> Option<Self::Item> {
22356 if self.buf.len() == self.pos {
22357 return None;
22358 }
22359 let pos = self.pos;
22360 let mut r#type = None;
22361 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
22362 r#type = Some(header.r#type);
22363 let res = match header.r#type {
22364 1u16 => OpDelchainDoRequest::Table({
22365 let res = CStr::from_bytes_with_nul(next).ok();
22366 let Some(val) = res else { break };
22367 val
22368 }),
22369 2u16 => OpDelchainDoRequest::Handle({
22370 let res = parse_be_u64(next);
22371 let Some(val) = res else { break };
22372 val
22373 }),
22374 3u16 => OpDelchainDoRequest::Name({
22375 let res = CStr::from_bytes_with_nul(next).ok();
22376 let Some(val) = res else { break };
22377 val
22378 }),
22379 4u16 => OpDelchainDoRequest::Hook({
22380 let res = Some(IterableNftHookAttrs::with_loc(next, self.orig_loc));
22381 let Some(val) = res else { break };
22382 val
22383 }),
22384 n => {
22385 if cfg!(any(test, feature = "deny-unknown-attrs")) {
22386 break;
22387 } else {
22388 continue;
22389 }
22390 }
22391 };
22392 return Some(Ok(res));
22393 }
22394 Some(Err(ErrorContext::new(
22395 "OpDelchainDoRequest",
22396 r#type.and_then(|t| OpDelchainDoRequest::attr_from_type(t)),
22397 self.orig_loc,
22398 self.buf.as_ptr().wrapping_add(pos) as usize,
22399 )))
22400 }
22401}
22402impl<'a> std::fmt::Debug for IterableOpDelchainDoRequest<'_> {
22403 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22404 let mut fmt = f.debug_struct("OpDelchainDoRequest");
22405 for attr in self.clone() {
22406 let attr = match attr {
22407 Ok(a) => a,
22408 Err(err) => {
22409 fmt.finish()?;
22410 f.write_str("Err(")?;
22411 err.fmt(f)?;
22412 return f.write_str(")");
22413 }
22414 };
22415 match attr {
22416 OpDelchainDoRequest::Table(val) => fmt.field("Table", &val),
22417 OpDelchainDoRequest::Handle(val) => fmt.field("Handle", &val),
22418 OpDelchainDoRequest::Name(val) => fmt.field("Name", &val),
22419 OpDelchainDoRequest::Hook(val) => fmt.field("Hook", &val),
22420 };
22421 }
22422 fmt.finish()
22423 }
22424}
22425impl IterableOpDelchainDoRequest<'_> {
22426 pub fn lookup_attr(
22427 &self,
22428 offset: usize,
22429 missing_type: Option<u16>,
22430 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22431 let mut stack = Vec::new();
22432 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
22433 if cur == offset + PushNfgenmsg::len() {
22434 stack.push(("OpDelchainDoRequest", offset));
22435 return (
22436 stack,
22437 missing_type.and_then(|t| OpDelchainDoRequest::attr_from_type(t)),
22438 );
22439 }
22440 if cur > offset || cur + self.buf.len() < offset {
22441 return (stack, None);
22442 }
22443 let mut attrs = self.clone();
22444 let mut last_off = cur + attrs.pos;
22445 let mut missing = None;
22446 while let Some(attr) = attrs.next() {
22447 let Ok(attr) = attr else { break };
22448 match attr {
22449 OpDelchainDoRequest::Table(val) => {
22450 if last_off == offset {
22451 stack.push(("Table", last_off));
22452 break;
22453 }
22454 }
22455 OpDelchainDoRequest::Handle(val) => {
22456 if last_off == offset {
22457 stack.push(("Handle", last_off));
22458 break;
22459 }
22460 }
22461 OpDelchainDoRequest::Name(val) => {
22462 if last_off == offset {
22463 stack.push(("Name", last_off));
22464 break;
22465 }
22466 }
22467 OpDelchainDoRequest::Hook(val) => {
22468 (stack, missing) = val.lookup_attr(offset, missing_type);
22469 if !stack.is_empty() {
22470 break;
22471 }
22472 }
22473 _ => {}
22474 };
22475 last_off = cur + attrs.pos;
22476 }
22477 if !stack.is_empty() {
22478 stack.push(("OpDelchainDoRequest", cur));
22479 }
22480 (stack, missing)
22481 }
22482}
22483#[doc = "Delete an existing chain."]
22484pub struct PushOpDelchainDoReply<Prev: Rec> {
22485 pub(crate) prev: Option<Prev>,
22486 pub(crate) header_offset: Option<usize>,
22487}
22488impl<Prev: Rec> Rec for PushOpDelchainDoReply<Prev> {
22489 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
22490 self.prev.as_mut().unwrap().as_rec_mut()
22491 }
22492}
22493impl<Prev: Rec> PushOpDelchainDoReply<Prev> {
22494 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
22495 Self::write_header(&mut prev, header);
22496 Self::new_without_header(prev)
22497 }
22498 fn new_without_header(prev: Prev) -> Self {
22499 Self {
22500 prev: Some(prev),
22501 header_offset: None,
22502 }
22503 }
22504 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
22505 prev.as_rec_mut().extend(header.as_slice());
22506 }
22507 pub fn end_nested(mut self) -> Prev {
22508 let mut prev = self.prev.take().unwrap();
22509 if let Some(header_offset) = &self.header_offset {
22510 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22511 }
22512 prev
22513 }
22514}
22515impl<Prev: Rec> Drop for PushOpDelchainDoReply<Prev> {
22516 fn drop(&mut self) {
22517 if let Some(prev) = &mut self.prev {
22518 if let Some(header_offset) = &self.header_offset {
22519 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22520 }
22521 }
22522 }
22523}
22524#[doc = "Delete an existing chain."]
22525#[derive(Clone)]
22526pub enum OpDelchainDoReply {}
22527impl<'a> IterableOpDelchainDoReply<'a> {}
22528impl OpDelchainDoReply {
22529 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDelchainDoReply<'_>) {
22530 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
22531 (
22532 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
22533 IterableOpDelchainDoReply::with_loc(attrs, buf.as_ptr() as usize),
22534 )
22535 }
22536 fn attr_from_type(r#type: u16) -> Option<&'static str> {
22537 ChainAttrs::attr_from_type(r#type)
22538 }
22539}
22540#[derive(Clone, Copy, Default)]
22541pub struct IterableOpDelchainDoReply<'a> {
22542 buf: &'a [u8],
22543 pos: usize,
22544 orig_loc: usize,
22545}
22546impl<'a> IterableOpDelchainDoReply<'a> {
22547 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22548 Self {
22549 buf,
22550 pos: 0,
22551 orig_loc,
22552 }
22553 }
22554 pub fn get_buf(&self) -> &'a [u8] {
22555 self.buf
22556 }
22557}
22558impl<'a> Iterator for IterableOpDelchainDoReply<'a> {
22559 type Item = Result<OpDelchainDoReply, ErrorContext>;
22560 fn next(&mut self) -> Option<Self::Item> {
22561 if self.buf.len() == self.pos {
22562 return None;
22563 }
22564 let pos = self.pos;
22565 let mut r#type = None;
22566 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
22567 r#type = Some(header.r#type);
22568 let res = match header.r#type {
22569 n => {
22570 if cfg!(any(test, feature = "deny-unknown-attrs")) {
22571 break;
22572 } else {
22573 continue;
22574 }
22575 }
22576 };
22577 return Some(Ok(res));
22578 }
22579 Some(Err(ErrorContext::new(
22580 "OpDelchainDoReply",
22581 r#type.and_then(|t| OpDelchainDoReply::attr_from_type(t)),
22582 self.orig_loc,
22583 self.buf.as_ptr().wrapping_add(pos) as usize,
22584 )))
22585 }
22586}
22587impl std::fmt::Debug for IterableOpDelchainDoReply<'_> {
22588 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22589 let mut fmt = f.debug_struct("OpDelchainDoReply");
22590 for attr in self.clone() {
22591 let attr = match attr {
22592 Ok(a) => a,
22593 Err(err) => {
22594 fmt.finish()?;
22595 f.write_str("Err(")?;
22596 err.fmt(f)?;
22597 return f.write_str(")");
22598 }
22599 };
22600 match attr {};
22601 }
22602 fmt.finish()
22603 }
22604}
22605impl IterableOpDelchainDoReply<'_> {
22606 pub fn lookup_attr(
22607 &self,
22608 offset: usize,
22609 missing_type: Option<u16>,
22610 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22611 let mut stack = Vec::new();
22612 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
22613 if cur == offset + PushNfgenmsg::len() {
22614 stack.push(("OpDelchainDoReply", offset));
22615 return (
22616 stack,
22617 missing_type.and_then(|t| OpDelchainDoReply::attr_from_type(t)),
22618 );
22619 }
22620 (stack, None)
22621 }
22622}
22623#[derive(Debug)]
22624pub struct RequestOpDelchainDoRequest<'r> {
22625 request: Request<'r>,
22626}
22627impl<'r> RequestOpDelchainDoRequest<'r> {
22628 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
22629 PushOpDelchainDoRequest::write_header(&mut request.buf_mut(), header);
22630 Self { request: request }
22631 }
22632 pub fn encode(&mut self) -> PushOpDelchainDoRequest<&mut Vec<u8>> {
22633 PushOpDelchainDoRequest::new_without_header(self.request.buf_mut())
22634 }
22635 pub fn into_encoder(self) -> PushOpDelchainDoRequest<RequestBuf<'r>> {
22636 PushOpDelchainDoRequest::new_without_header(self.request.buf)
22637 }
22638}
22639impl NetlinkRequest for RequestOpDelchainDoRequest<'_> {
22640 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDelchainDoReply<'buf>);
22641 fn protocol(&self) -> Protocol {
22642 Protocol::Raw {
22643 protonum: 12u16,
22644 request_type: 2565u16,
22645 }
22646 }
22647 fn flags(&self) -> u16 {
22648 self.request.flags
22649 }
22650 fn payload(&self) -> &[u8] {
22651 self.request.buf()
22652 }
22653 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
22654 OpDelchainDoReply::new(buf)
22655 }
22656 fn lookup(
22657 buf: &[u8],
22658 offset: usize,
22659 missing_type: Option<u16>,
22660 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22661 OpDelchainDoRequest::new(buf)
22662 .1
22663 .lookup_attr(offset, missing_type)
22664 }
22665}
22666#[doc = "Delete an existing chain with destroy semantics (ignoring ENOENT\nerrors).\n"]
22667pub struct PushOpDestroychainDoRequest<Prev: Rec> {
22668 pub(crate) prev: Option<Prev>,
22669 pub(crate) header_offset: Option<usize>,
22670}
22671impl<Prev: Rec> Rec for PushOpDestroychainDoRequest<Prev> {
22672 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
22673 self.prev.as_mut().unwrap().as_rec_mut()
22674 }
22675}
22676impl<Prev: Rec> PushOpDestroychainDoRequest<Prev> {
22677 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
22678 Self::write_header(&mut prev, header);
22679 Self::new_without_header(prev)
22680 }
22681 fn new_without_header(prev: Prev) -> Self {
22682 Self {
22683 prev: Some(prev),
22684 header_offset: None,
22685 }
22686 }
22687 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
22688 prev.as_rec_mut().extend(header.as_slice());
22689 }
22690 pub fn end_nested(mut self) -> Prev {
22691 let mut prev = self.prev.take().unwrap();
22692 if let Some(header_offset) = &self.header_offset {
22693 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22694 }
22695 prev
22696 }
22697 #[doc = "name of the table containing the chain"]
22698 pub fn push_table(mut self, value: &CStr) -> Self {
22699 push_header(
22700 self.as_rec_mut(),
22701 1u16,
22702 value.to_bytes_with_nul().len() as u16,
22703 );
22704 self.as_rec_mut().extend(value.to_bytes_with_nul());
22705 self
22706 }
22707 #[doc = "name of the table containing the chain"]
22708 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
22709 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
22710 self.as_rec_mut().extend(value);
22711 self.as_rec_mut().push(0);
22712 self
22713 }
22714 #[doc = "numeric handle of the chain"]
22715 pub fn push_handle(mut self, value: u64) -> Self {
22716 push_header(self.as_rec_mut(), 2u16, 8 as u16);
22717 self.as_rec_mut().extend(value.to_be_bytes());
22718 self
22719 }
22720 #[doc = "name of the chain"]
22721 pub fn push_name(mut self, value: &CStr) -> Self {
22722 push_header(
22723 self.as_rec_mut(),
22724 3u16,
22725 value.to_bytes_with_nul().len() as u16,
22726 );
22727 self.as_rec_mut().extend(value.to_bytes_with_nul());
22728 self
22729 }
22730 #[doc = "name of the chain"]
22731 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
22732 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
22733 self.as_rec_mut().extend(value);
22734 self.as_rec_mut().push(0);
22735 self
22736 }
22737 #[doc = "hook specification for basechains"]
22738 pub fn nested_hook(mut self) -> PushNftHookAttrs<Self> {
22739 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
22740 PushNftHookAttrs {
22741 prev: Some(self),
22742 header_offset: Some(header_offset),
22743 }
22744 }
22745}
22746impl<Prev: Rec> Drop for PushOpDestroychainDoRequest<Prev> {
22747 fn drop(&mut self) {
22748 if let Some(prev) = &mut self.prev {
22749 if let Some(header_offset) = &self.header_offset {
22750 finalize_nested_header(prev.as_rec_mut(), *header_offset);
22751 }
22752 }
22753 }
22754}
22755#[doc = "Delete an existing chain with destroy semantics (ignoring ENOENT\nerrors).\n"]
22756#[derive(Clone)]
22757pub enum OpDestroychainDoRequest<'a> {
22758 #[doc = "name of the table containing the chain"]
22759 Table(&'a CStr),
22760 #[doc = "numeric handle of the chain"]
22761 Handle(u64),
22762 #[doc = "name of the chain"]
22763 Name(&'a CStr),
22764 #[doc = "hook specification for basechains"]
22765 Hook(IterableNftHookAttrs<'a>),
22766}
22767impl<'a> IterableOpDestroychainDoRequest<'a> {
22768 #[doc = "name of the table containing the chain"]
22769 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
22770 let mut iter = self.clone();
22771 iter.pos = 0;
22772 for attr in iter {
22773 if let OpDestroychainDoRequest::Table(val) = attr? {
22774 return Ok(val);
22775 }
22776 }
22777 Err(ErrorContext::new_missing(
22778 "OpDestroychainDoRequest",
22779 "Table",
22780 self.orig_loc,
22781 self.buf.as_ptr() as usize,
22782 ))
22783 }
22784 #[doc = "numeric handle of the chain"]
22785 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
22786 let mut iter = self.clone();
22787 iter.pos = 0;
22788 for attr in iter {
22789 if let OpDestroychainDoRequest::Handle(val) = attr? {
22790 return Ok(val);
22791 }
22792 }
22793 Err(ErrorContext::new_missing(
22794 "OpDestroychainDoRequest",
22795 "Handle",
22796 self.orig_loc,
22797 self.buf.as_ptr() as usize,
22798 ))
22799 }
22800 #[doc = "name of the chain"]
22801 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
22802 let mut iter = self.clone();
22803 iter.pos = 0;
22804 for attr in iter {
22805 if let OpDestroychainDoRequest::Name(val) = attr? {
22806 return Ok(val);
22807 }
22808 }
22809 Err(ErrorContext::new_missing(
22810 "OpDestroychainDoRequest",
22811 "Name",
22812 self.orig_loc,
22813 self.buf.as_ptr() as usize,
22814 ))
22815 }
22816 #[doc = "hook specification for basechains"]
22817 pub fn get_hook(&self) -> Result<IterableNftHookAttrs<'a>, ErrorContext> {
22818 let mut iter = self.clone();
22819 iter.pos = 0;
22820 for attr in iter {
22821 if let OpDestroychainDoRequest::Hook(val) = attr? {
22822 return Ok(val);
22823 }
22824 }
22825 Err(ErrorContext::new_missing(
22826 "OpDestroychainDoRequest",
22827 "Hook",
22828 self.orig_loc,
22829 self.buf.as_ptr() as usize,
22830 ))
22831 }
22832}
22833impl<'a> OpDestroychainDoRequest<'a> {
22834 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDestroychainDoRequest<'a>) {
22835 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
22836 (
22837 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
22838 IterableOpDestroychainDoRequest::with_loc(attrs, buf.as_ptr() as usize),
22839 )
22840 }
22841 fn attr_from_type(r#type: u16) -> Option<&'static str> {
22842 ChainAttrs::attr_from_type(r#type)
22843 }
22844}
22845#[derive(Clone, Copy, Default)]
22846pub struct IterableOpDestroychainDoRequest<'a> {
22847 buf: &'a [u8],
22848 pos: usize,
22849 orig_loc: usize,
22850}
22851impl<'a> IterableOpDestroychainDoRequest<'a> {
22852 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
22853 Self {
22854 buf,
22855 pos: 0,
22856 orig_loc,
22857 }
22858 }
22859 pub fn get_buf(&self) -> &'a [u8] {
22860 self.buf
22861 }
22862}
22863impl<'a> Iterator for IterableOpDestroychainDoRequest<'a> {
22864 type Item = Result<OpDestroychainDoRequest<'a>, ErrorContext>;
22865 fn next(&mut self) -> Option<Self::Item> {
22866 if self.buf.len() == self.pos {
22867 return None;
22868 }
22869 let pos = self.pos;
22870 let mut r#type = None;
22871 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
22872 r#type = Some(header.r#type);
22873 let res = match header.r#type {
22874 1u16 => OpDestroychainDoRequest::Table({
22875 let res = CStr::from_bytes_with_nul(next).ok();
22876 let Some(val) = res else { break };
22877 val
22878 }),
22879 2u16 => OpDestroychainDoRequest::Handle({
22880 let res = parse_be_u64(next);
22881 let Some(val) = res else { break };
22882 val
22883 }),
22884 3u16 => OpDestroychainDoRequest::Name({
22885 let res = CStr::from_bytes_with_nul(next).ok();
22886 let Some(val) = res else { break };
22887 val
22888 }),
22889 4u16 => OpDestroychainDoRequest::Hook({
22890 let res = Some(IterableNftHookAttrs::with_loc(next, self.orig_loc));
22891 let Some(val) = res else { break };
22892 val
22893 }),
22894 n => {
22895 if cfg!(any(test, feature = "deny-unknown-attrs")) {
22896 break;
22897 } else {
22898 continue;
22899 }
22900 }
22901 };
22902 return Some(Ok(res));
22903 }
22904 Some(Err(ErrorContext::new(
22905 "OpDestroychainDoRequest",
22906 r#type.and_then(|t| OpDestroychainDoRequest::attr_from_type(t)),
22907 self.orig_loc,
22908 self.buf.as_ptr().wrapping_add(pos) as usize,
22909 )))
22910 }
22911}
22912impl<'a> std::fmt::Debug for IterableOpDestroychainDoRequest<'_> {
22913 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22914 let mut fmt = f.debug_struct("OpDestroychainDoRequest");
22915 for attr in self.clone() {
22916 let attr = match attr {
22917 Ok(a) => a,
22918 Err(err) => {
22919 fmt.finish()?;
22920 f.write_str("Err(")?;
22921 err.fmt(f)?;
22922 return f.write_str(")");
22923 }
22924 };
22925 match attr {
22926 OpDestroychainDoRequest::Table(val) => fmt.field("Table", &val),
22927 OpDestroychainDoRequest::Handle(val) => fmt.field("Handle", &val),
22928 OpDestroychainDoRequest::Name(val) => fmt.field("Name", &val),
22929 OpDestroychainDoRequest::Hook(val) => fmt.field("Hook", &val),
22930 };
22931 }
22932 fmt.finish()
22933 }
22934}
22935impl IterableOpDestroychainDoRequest<'_> {
22936 pub fn lookup_attr(
22937 &self,
22938 offset: usize,
22939 missing_type: Option<u16>,
22940 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
22941 let mut stack = Vec::new();
22942 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
22943 if cur == offset + PushNfgenmsg::len() {
22944 stack.push(("OpDestroychainDoRequest", offset));
22945 return (
22946 stack,
22947 missing_type.and_then(|t| OpDestroychainDoRequest::attr_from_type(t)),
22948 );
22949 }
22950 if cur > offset || cur + self.buf.len() < offset {
22951 return (stack, None);
22952 }
22953 let mut attrs = self.clone();
22954 let mut last_off = cur + attrs.pos;
22955 let mut missing = None;
22956 while let Some(attr) = attrs.next() {
22957 let Ok(attr) = attr else { break };
22958 match attr {
22959 OpDestroychainDoRequest::Table(val) => {
22960 if last_off == offset {
22961 stack.push(("Table", last_off));
22962 break;
22963 }
22964 }
22965 OpDestroychainDoRequest::Handle(val) => {
22966 if last_off == offset {
22967 stack.push(("Handle", last_off));
22968 break;
22969 }
22970 }
22971 OpDestroychainDoRequest::Name(val) => {
22972 if last_off == offset {
22973 stack.push(("Name", last_off));
22974 break;
22975 }
22976 }
22977 OpDestroychainDoRequest::Hook(val) => {
22978 (stack, missing) = val.lookup_attr(offset, missing_type);
22979 if !stack.is_empty() {
22980 break;
22981 }
22982 }
22983 _ => {}
22984 };
22985 last_off = cur + attrs.pos;
22986 }
22987 if !stack.is_empty() {
22988 stack.push(("OpDestroychainDoRequest", cur));
22989 }
22990 (stack, missing)
22991 }
22992}
22993#[doc = "Delete an existing chain with destroy semantics (ignoring ENOENT\nerrors).\n"]
22994pub struct PushOpDestroychainDoReply<Prev: Rec> {
22995 pub(crate) prev: Option<Prev>,
22996 pub(crate) header_offset: Option<usize>,
22997}
22998impl<Prev: Rec> Rec for PushOpDestroychainDoReply<Prev> {
22999 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
23000 self.prev.as_mut().unwrap().as_rec_mut()
23001 }
23002}
23003impl<Prev: Rec> PushOpDestroychainDoReply<Prev> {
23004 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
23005 Self::write_header(&mut prev, header);
23006 Self::new_without_header(prev)
23007 }
23008 fn new_without_header(prev: Prev) -> Self {
23009 Self {
23010 prev: Some(prev),
23011 header_offset: None,
23012 }
23013 }
23014 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
23015 prev.as_rec_mut().extend(header.as_slice());
23016 }
23017 pub fn end_nested(mut self) -> Prev {
23018 let mut prev = self.prev.take().unwrap();
23019 if let Some(header_offset) = &self.header_offset {
23020 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23021 }
23022 prev
23023 }
23024}
23025impl<Prev: Rec> Drop for PushOpDestroychainDoReply<Prev> {
23026 fn drop(&mut self) {
23027 if let Some(prev) = &mut self.prev {
23028 if let Some(header_offset) = &self.header_offset {
23029 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23030 }
23031 }
23032 }
23033}
23034#[doc = "Delete an existing chain with destroy semantics (ignoring ENOENT\nerrors).\n"]
23035#[derive(Clone)]
23036pub enum OpDestroychainDoReply {}
23037impl<'a> IterableOpDestroychainDoReply<'a> {}
23038impl OpDestroychainDoReply {
23039 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDestroychainDoReply<'_>) {
23040 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
23041 (
23042 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
23043 IterableOpDestroychainDoReply::with_loc(attrs, buf.as_ptr() as usize),
23044 )
23045 }
23046 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23047 ChainAttrs::attr_from_type(r#type)
23048 }
23049}
23050#[derive(Clone, Copy, Default)]
23051pub struct IterableOpDestroychainDoReply<'a> {
23052 buf: &'a [u8],
23053 pos: usize,
23054 orig_loc: usize,
23055}
23056impl<'a> IterableOpDestroychainDoReply<'a> {
23057 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
23058 Self {
23059 buf,
23060 pos: 0,
23061 orig_loc,
23062 }
23063 }
23064 pub fn get_buf(&self) -> &'a [u8] {
23065 self.buf
23066 }
23067}
23068impl<'a> Iterator for IterableOpDestroychainDoReply<'a> {
23069 type Item = Result<OpDestroychainDoReply, ErrorContext>;
23070 fn next(&mut self) -> Option<Self::Item> {
23071 if self.buf.len() == self.pos {
23072 return None;
23073 }
23074 let pos = self.pos;
23075 let mut r#type = None;
23076 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
23077 r#type = Some(header.r#type);
23078 let res = match header.r#type {
23079 n => {
23080 if cfg!(any(test, feature = "deny-unknown-attrs")) {
23081 break;
23082 } else {
23083 continue;
23084 }
23085 }
23086 };
23087 return Some(Ok(res));
23088 }
23089 Some(Err(ErrorContext::new(
23090 "OpDestroychainDoReply",
23091 r#type.and_then(|t| OpDestroychainDoReply::attr_from_type(t)),
23092 self.orig_loc,
23093 self.buf.as_ptr().wrapping_add(pos) as usize,
23094 )))
23095 }
23096}
23097impl std::fmt::Debug for IterableOpDestroychainDoReply<'_> {
23098 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23099 let mut fmt = f.debug_struct("OpDestroychainDoReply");
23100 for attr in self.clone() {
23101 let attr = match attr {
23102 Ok(a) => a,
23103 Err(err) => {
23104 fmt.finish()?;
23105 f.write_str("Err(")?;
23106 err.fmt(f)?;
23107 return f.write_str(")");
23108 }
23109 };
23110 match attr {};
23111 }
23112 fmt.finish()
23113 }
23114}
23115impl IterableOpDestroychainDoReply<'_> {
23116 pub fn lookup_attr(
23117 &self,
23118 offset: usize,
23119 missing_type: Option<u16>,
23120 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23121 let mut stack = Vec::new();
23122 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23123 if cur == offset + PushNfgenmsg::len() {
23124 stack.push(("OpDestroychainDoReply", offset));
23125 return (
23126 stack,
23127 missing_type.and_then(|t| OpDestroychainDoReply::attr_from_type(t)),
23128 );
23129 }
23130 (stack, None)
23131 }
23132}
23133#[derive(Debug)]
23134pub struct RequestOpDestroychainDoRequest<'r> {
23135 request: Request<'r>,
23136}
23137impl<'r> RequestOpDestroychainDoRequest<'r> {
23138 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
23139 PushOpDestroychainDoRequest::write_header(&mut request.buf_mut(), header);
23140 Self { request: request }
23141 }
23142 pub fn encode(&mut self) -> PushOpDestroychainDoRequest<&mut Vec<u8>> {
23143 PushOpDestroychainDoRequest::new_without_header(self.request.buf_mut())
23144 }
23145 pub fn into_encoder(self) -> PushOpDestroychainDoRequest<RequestBuf<'r>> {
23146 PushOpDestroychainDoRequest::new_without_header(self.request.buf)
23147 }
23148}
23149impl NetlinkRequest for RequestOpDestroychainDoRequest<'_> {
23150 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDestroychainDoReply<'buf>);
23151 fn protocol(&self) -> Protocol {
23152 Protocol::Raw {
23153 protonum: 12u16,
23154 request_type: 2587u16,
23155 }
23156 }
23157 fn flags(&self) -> u16 {
23158 self.request.flags
23159 }
23160 fn payload(&self) -> &[u8] {
23161 self.request.buf()
23162 }
23163 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
23164 OpDestroychainDoReply::new(buf)
23165 }
23166 fn lookup(
23167 buf: &[u8],
23168 offset: usize,
23169 missing_type: Option<u16>,
23170 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23171 OpDestroychainDoRequest::new(buf)
23172 .1
23173 .lookup_attr(offset, missing_type)
23174 }
23175}
23176#[doc = "Create a new rule."]
23177pub struct PushOpNewruleDoRequest<Prev: Rec> {
23178 pub(crate) prev: Option<Prev>,
23179 pub(crate) header_offset: Option<usize>,
23180}
23181impl<Prev: Rec> Rec for PushOpNewruleDoRequest<Prev> {
23182 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
23183 self.prev.as_mut().unwrap().as_rec_mut()
23184 }
23185}
23186impl<Prev: Rec> PushOpNewruleDoRequest<Prev> {
23187 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
23188 Self::write_header(&mut prev, header);
23189 Self::new_without_header(prev)
23190 }
23191 fn new_without_header(prev: Prev) -> Self {
23192 Self {
23193 prev: Some(prev),
23194 header_offset: None,
23195 }
23196 }
23197 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
23198 prev.as_rec_mut().extend(header.as_slice());
23199 }
23200 pub fn end_nested(mut self) -> Prev {
23201 let mut prev = self.prev.take().unwrap();
23202 if let Some(header_offset) = &self.header_offset {
23203 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23204 }
23205 prev
23206 }
23207 #[doc = "name of the table containing the rule"]
23208 pub fn push_table(mut self, value: &CStr) -> Self {
23209 push_header(
23210 self.as_rec_mut(),
23211 1u16,
23212 value.to_bytes_with_nul().len() as u16,
23213 );
23214 self.as_rec_mut().extend(value.to_bytes_with_nul());
23215 self
23216 }
23217 #[doc = "name of the table containing the rule"]
23218 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
23219 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
23220 self.as_rec_mut().extend(value);
23221 self.as_rec_mut().push(0);
23222 self
23223 }
23224 #[doc = "name of the chain containing the rule"]
23225 pub fn push_chain(mut self, value: &CStr) -> Self {
23226 push_header(
23227 self.as_rec_mut(),
23228 2u16,
23229 value.to_bytes_with_nul().len() as u16,
23230 );
23231 self.as_rec_mut().extend(value.to_bytes_with_nul());
23232 self
23233 }
23234 #[doc = "name of the chain containing the rule"]
23235 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
23236 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
23237 self.as_rec_mut().extend(value);
23238 self.as_rec_mut().push(0);
23239 self
23240 }
23241 #[doc = "numeric handle of the rule"]
23242 pub fn push_handle(mut self, value: u64) -> Self {
23243 push_header(self.as_rec_mut(), 3u16, 8 as u16);
23244 self.as_rec_mut().extend(value.to_be_bytes());
23245 self
23246 }
23247 #[doc = "list of expressions"]
23248 pub fn nested_expressions(mut self) -> PushExprListAttrs<Self> {
23249 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
23250 PushExprListAttrs {
23251 prev: Some(self),
23252 header_offset: Some(header_offset),
23253 }
23254 }
23255 #[doc = "compatibility specifications of the rule"]
23256 pub fn nested_compat(mut self) -> PushRuleCompatAttrs<Self> {
23257 let header_offset = push_nested_header(self.as_rec_mut(), 5u16);
23258 PushRuleCompatAttrs {
23259 prev: Some(self),
23260 header_offset: Some(header_offset),
23261 }
23262 }
23263 #[doc = "numeric handle of the previous rule"]
23264 pub fn push_position(mut self, value: u64) -> Self {
23265 push_header(self.as_rec_mut(), 6u16, 8 as u16);
23266 self.as_rec_mut().extend(value.to_be_bytes());
23267 self
23268 }
23269 #[doc = "user data"]
23270 pub fn push_userdata(mut self, value: &[u8]) -> Self {
23271 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
23272 self.as_rec_mut().extend(value);
23273 self
23274 }
23275 #[doc = "transaction unique identifier of the previous rule"]
23276 pub fn push_position_id(mut self, value: u32) -> Self {
23277 push_header(self.as_rec_mut(), 9u16, 4 as u16);
23278 self.as_rec_mut().extend(value.to_ne_bytes());
23279 self
23280 }
23281 #[doc = "add the rule to chain by ID, alternative to chain name"]
23282 pub fn push_chain_id(mut self, value: u32) -> Self {
23283 push_header(self.as_rec_mut(), 10u16, 4 as u16);
23284 self.as_rec_mut().extend(value.to_ne_bytes());
23285 self
23286 }
23287}
23288impl<Prev: Rec> Drop for PushOpNewruleDoRequest<Prev> {
23289 fn drop(&mut self) {
23290 if let Some(prev) = &mut self.prev {
23291 if let Some(header_offset) = &self.header_offset {
23292 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23293 }
23294 }
23295 }
23296}
23297#[doc = "Create a new rule."]
23298#[derive(Clone)]
23299pub enum OpNewruleDoRequest<'a> {
23300 #[doc = "name of the table containing the rule"]
23301 Table(&'a CStr),
23302 #[doc = "name of the chain containing the rule"]
23303 Chain(&'a CStr),
23304 #[doc = "numeric handle of the rule"]
23305 Handle(u64),
23306 #[doc = "list of expressions"]
23307 Expressions(IterableExprListAttrs<'a>),
23308 #[doc = "compatibility specifications of the rule"]
23309 Compat(IterableRuleCompatAttrs<'a>),
23310 #[doc = "numeric handle of the previous rule"]
23311 Position(u64),
23312 #[doc = "user data"]
23313 Userdata(&'a [u8]),
23314 #[doc = "transaction unique identifier of the previous rule"]
23315 PositionId(u32),
23316 #[doc = "add the rule to chain by ID, alternative to chain name"]
23317 ChainId(u32),
23318}
23319impl<'a> IterableOpNewruleDoRequest<'a> {
23320 #[doc = "name of the table containing the rule"]
23321 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
23322 let mut iter = self.clone();
23323 iter.pos = 0;
23324 for attr in iter {
23325 if let OpNewruleDoRequest::Table(val) = attr? {
23326 return Ok(val);
23327 }
23328 }
23329 Err(ErrorContext::new_missing(
23330 "OpNewruleDoRequest",
23331 "Table",
23332 self.orig_loc,
23333 self.buf.as_ptr() as usize,
23334 ))
23335 }
23336 #[doc = "name of the chain containing the rule"]
23337 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
23338 let mut iter = self.clone();
23339 iter.pos = 0;
23340 for attr in iter {
23341 if let OpNewruleDoRequest::Chain(val) = attr? {
23342 return Ok(val);
23343 }
23344 }
23345 Err(ErrorContext::new_missing(
23346 "OpNewruleDoRequest",
23347 "Chain",
23348 self.orig_loc,
23349 self.buf.as_ptr() as usize,
23350 ))
23351 }
23352 #[doc = "numeric handle of the rule"]
23353 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
23354 let mut iter = self.clone();
23355 iter.pos = 0;
23356 for attr in iter {
23357 if let OpNewruleDoRequest::Handle(val) = attr? {
23358 return Ok(val);
23359 }
23360 }
23361 Err(ErrorContext::new_missing(
23362 "OpNewruleDoRequest",
23363 "Handle",
23364 self.orig_loc,
23365 self.buf.as_ptr() as usize,
23366 ))
23367 }
23368 #[doc = "list of expressions"]
23369 pub fn get_expressions(&self) -> Result<IterableExprListAttrs<'a>, ErrorContext> {
23370 let mut iter = self.clone();
23371 iter.pos = 0;
23372 for attr in iter {
23373 if let OpNewruleDoRequest::Expressions(val) = attr? {
23374 return Ok(val);
23375 }
23376 }
23377 Err(ErrorContext::new_missing(
23378 "OpNewruleDoRequest",
23379 "Expressions",
23380 self.orig_loc,
23381 self.buf.as_ptr() as usize,
23382 ))
23383 }
23384 #[doc = "compatibility specifications of the rule"]
23385 pub fn get_compat(&self) -> Result<IterableRuleCompatAttrs<'a>, ErrorContext> {
23386 let mut iter = self.clone();
23387 iter.pos = 0;
23388 for attr in iter {
23389 if let OpNewruleDoRequest::Compat(val) = attr? {
23390 return Ok(val);
23391 }
23392 }
23393 Err(ErrorContext::new_missing(
23394 "OpNewruleDoRequest",
23395 "Compat",
23396 self.orig_loc,
23397 self.buf.as_ptr() as usize,
23398 ))
23399 }
23400 #[doc = "numeric handle of the previous rule"]
23401 pub fn get_position(&self) -> Result<u64, ErrorContext> {
23402 let mut iter = self.clone();
23403 iter.pos = 0;
23404 for attr in iter {
23405 if let OpNewruleDoRequest::Position(val) = attr? {
23406 return Ok(val);
23407 }
23408 }
23409 Err(ErrorContext::new_missing(
23410 "OpNewruleDoRequest",
23411 "Position",
23412 self.orig_loc,
23413 self.buf.as_ptr() as usize,
23414 ))
23415 }
23416 #[doc = "user data"]
23417 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
23418 let mut iter = self.clone();
23419 iter.pos = 0;
23420 for attr in iter {
23421 if let OpNewruleDoRequest::Userdata(val) = attr? {
23422 return Ok(val);
23423 }
23424 }
23425 Err(ErrorContext::new_missing(
23426 "OpNewruleDoRequest",
23427 "Userdata",
23428 self.orig_loc,
23429 self.buf.as_ptr() as usize,
23430 ))
23431 }
23432 #[doc = "transaction unique identifier of the previous rule"]
23433 pub fn get_position_id(&self) -> Result<u32, ErrorContext> {
23434 let mut iter = self.clone();
23435 iter.pos = 0;
23436 for attr in iter {
23437 if let OpNewruleDoRequest::PositionId(val) = attr? {
23438 return Ok(val);
23439 }
23440 }
23441 Err(ErrorContext::new_missing(
23442 "OpNewruleDoRequest",
23443 "PositionId",
23444 self.orig_loc,
23445 self.buf.as_ptr() as usize,
23446 ))
23447 }
23448 #[doc = "add the rule to chain by ID, alternative to chain name"]
23449 pub fn get_chain_id(&self) -> Result<u32, ErrorContext> {
23450 let mut iter = self.clone();
23451 iter.pos = 0;
23452 for attr in iter {
23453 if let OpNewruleDoRequest::ChainId(val) = attr? {
23454 return Ok(val);
23455 }
23456 }
23457 Err(ErrorContext::new_missing(
23458 "OpNewruleDoRequest",
23459 "ChainId",
23460 self.orig_loc,
23461 self.buf.as_ptr() as usize,
23462 ))
23463 }
23464}
23465impl<'a> OpNewruleDoRequest<'a> {
23466 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpNewruleDoRequest<'a>) {
23467 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
23468 (
23469 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
23470 IterableOpNewruleDoRequest::with_loc(attrs, buf.as_ptr() as usize),
23471 )
23472 }
23473 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23474 RuleAttrs::attr_from_type(r#type)
23475 }
23476}
23477#[derive(Clone, Copy, Default)]
23478pub struct IterableOpNewruleDoRequest<'a> {
23479 buf: &'a [u8],
23480 pos: usize,
23481 orig_loc: usize,
23482}
23483impl<'a> IterableOpNewruleDoRequest<'a> {
23484 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
23485 Self {
23486 buf,
23487 pos: 0,
23488 orig_loc,
23489 }
23490 }
23491 pub fn get_buf(&self) -> &'a [u8] {
23492 self.buf
23493 }
23494}
23495impl<'a> Iterator for IterableOpNewruleDoRequest<'a> {
23496 type Item = Result<OpNewruleDoRequest<'a>, ErrorContext>;
23497 fn next(&mut self) -> Option<Self::Item> {
23498 if self.buf.len() == self.pos {
23499 return None;
23500 }
23501 let pos = self.pos;
23502 let mut r#type = None;
23503 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
23504 r#type = Some(header.r#type);
23505 let res = match header.r#type {
23506 1u16 => OpNewruleDoRequest::Table({
23507 let res = CStr::from_bytes_with_nul(next).ok();
23508 let Some(val) = res else { break };
23509 val
23510 }),
23511 2u16 => OpNewruleDoRequest::Chain({
23512 let res = CStr::from_bytes_with_nul(next).ok();
23513 let Some(val) = res else { break };
23514 val
23515 }),
23516 3u16 => OpNewruleDoRequest::Handle({
23517 let res = parse_be_u64(next);
23518 let Some(val) = res else { break };
23519 val
23520 }),
23521 4u16 => OpNewruleDoRequest::Expressions({
23522 let res = Some(IterableExprListAttrs::with_loc(next, self.orig_loc));
23523 let Some(val) = res else { break };
23524 val
23525 }),
23526 5u16 => OpNewruleDoRequest::Compat({
23527 let res = Some(IterableRuleCompatAttrs::with_loc(next, self.orig_loc));
23528 let Some(val) = res else { break };
23529 val
23530 }),
23531 6u16 => OpNewruleDoRequest::Position({
23532 let res = parse_be_u64(next);
23533 let Some(val) = res else { break };
23534 val
23535 }),
23536 7u16 => OpNewruleDoRequest::Userdata({
23537 let res = Some(next);
23538 let Some(val) = res else { break };
23539 val
23540 }),
23541 9u16 => OpNewruleDoRequest::PositionId({
23542 let res = parse_u32(next);
23543 let Some(val) = res else { break };
23544 val
23545 }),
23546 10u16 => OpNewruleDoRequest::ChainId({
23547 let res = parse_u32(next);
23548 let Some(val) = res else { break };
23549 val
23550 }),
23551 n => {
23552 if cfg!(any(test, feature = "deny-unknown-attrs")) {
23553 break;
23554 } else {
23555 continue;
23556 }
23557 }
23558 };
23559 return Some(Ok(res));
23560 }
23561 Some(Err(ErrorContext::new(
23562 "OpNewruleDoRequest",
23563 r#type.and_then(|t| OpNewruleDoRequest::attr_from_type(t)),
23564 self.orig_loc,
23565 self.buf.as_ptr().wrapping_add(pos) as usize,
23566 )))
23567 }
23568}
23569impl<'a> std::fmt::Debug for IterableOpNewruleDoRequest<'_> {
23570 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23571 let mut fmt = f.debug_struct("OpNewruleDoRequest");
23572 for attr in self.clone() {
23573 let attr = match attr {
23574 Ok(a) => a,
23575 Err(err) => {
23576 fmt.finish()?;
23577 f.write_str("Err(")?;
23578 err.fmt(f)?;
23579 return f.write_str(")");
23580 }
23581 };
23582 match attr {
23583 OpNewruleDoRequest::Table(val) => fmt.field("Table", &val),
23584 OpNewruleDoRequest::Chain(val) => fmt.field("Chain", &val),
23585 OpNewruleDoRequest::Handle(val) => fmt.field("Handle", &val),
23586 OpNewruleDoRequest::Expressions(val) => fmt.field("Expressions", &val),
23587 OpNewruleDoRequest::Compat(val) => fmt.field("Compat", &val),
23588 OpNewruleDoRequest::Position(val) => fmt.field("Position", &val),
23589 OpNewruleDoRequest::Userdata(val) => fmt.field("Userdata", &val),
23590 OpNewruleDoRequest::PositionId(val) => fmt.field("PositionId", &val),
23591 OpNewruleDoRequest::ChainId(val) => fmt.field("ChainId", &val),
23592 };
23593 }
23594 fmt.finish()
23595 }
23596}
23597impl IterableOpNewruleDoRequest<'_> {
23598 pub fn lookup_attr(
23599 &self,
23600 offset: usize,
23601 missing_type: Option<u16>,
23602 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23603 let mut stack = Vec::new();
23604 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23605 if cur == offset + PushNfgenmsg::len() {
23606 stack.push(("OpNewruleDoRequest", offset));
23607 return (
23608 stack,
23609 missing_type.and_then(|t| OpNewruleDoRequest::attr_from_type(t)),
23610 );
23611 }
23612 if cur > offset || cur + self.buf.len() < offset {
23613 return (stack, None);
23614 }
23615 let mut attrs = self.clone();
23616 let mut last_off = cur + attrs.pos;
23617 let mut missing = None;
23618 while let Some(attr) = attrs.next() {
23619 let Ok(attr) = attr else { break };
23620 match attr {
23621 OpNewruleDoRequest::Table(val) => {
23622 if last_off == offset {
23623 stack.push(("Table", last_off));
23624 break;
23625 }
23626 }
23627 OpNewruleDoRequest::Chain(val) => {
23628 if last_off == offset {
23629 stack.push(("Chain", last_off));
23630 break;
23631 }
23632 }
23633 OpNewruleDoRequest::Handle(val) => {
23634 if last_off == offset {
23635 stack.push(("Handle", last_off));
23636 break;
23637 }
23638 }
23639 OpNewruleDoRequest::Expressions(val) => {
23640 (stack, missing) = val.lookup_attr(offset, missing_type);
23641 if !stack.is_empty() {
23642 break;
23643 }
23644 }
23645 OpNewruleDoRequest::Compat(val) => {
23646 (stack, missing) = val.lookup_attr(offset, missing_type);
23647 if !stack.is_empty() {
23648 break;
23649 }
23650 }
23651 OpNewruleDoRequest::Position(val) => {
23652 if last_off == offset {
23653 stack.push(("Position", last_off));
23654 break;
23655 }
23656 }
23657 OpNewruleDoRequest::Userdata(val) => {
23658 if last_off == offset {
23659 stack.push(("Userdata", last_off));
23660 break;
23661 }
23662 }
23663 OpNewruleDoRequest::PositionId(val) => {
23664 if last_off == offset {
23665 stack.push(("PositionId", last_off));
23666 break;
23667 }
23668 }
23669 OpNewruleDoRequest::ChainId(val) => {
23670 if last_off == offset {
23671 stack.push(("ChainId", last_off));
23672 break;
23673 }
23674 }
23675 _ => {}
23676 };
23677 last_off = cur + attrs.pos;
23678 }
23679 if !stack.is_empty() {
23680 stack.push(("OpNewruleDoRequest", cur));
23681 }
23682 (stack, missing)
23683 }
23684}
23685#[doc = "Create a new rule."]
23686pub struct PushOpNewruleDoReply<Prev: Rec> {
23687 pub(crate) prev: Option<Prev>,
23688 pub(crate) header_offset: Option<usize>,
23689}
23690impl<Prev: Rec> Rec for PushOpNewruleDoReply<Prev> {
23691 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
23692 self.prev.as_mut().unwrap().as_rec_mut()
23693 }
23694}
23695impl<Prev: Rec> PushOpNewruleDoReply<Prev> {
23696 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
23697 Self::write_header(&mut prev, header);
23698 Self::new_without_header(prev)
23699 }
23700 fn new_without_header(prev: Prev) -> Self {
23701 Self {
23702 prev: Some(prev),
23703 header_offset: None,
23704 }
23705 }
23706 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
23707 prev.as_rec_mut().extend(header.as_slice());
23708 }
23709 pub fn end_nested(mut self) -> Prev {
23710 let mut prev = self.prev.take().unwrap();
23711 if let Some(header_offset) = &self.header_offset {
23712 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23713 }
23714 prev
23715 }
23716}
23717impl<Prev: Rec> Drop for PushOpNewruleDoReply<Prev> {
23718 fn drop(&mut self) {
23719 if let Some(prev) = &mut self.prev {
23720 if let Some(header_offset) = &self.header_offset {
23721 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23722 }
23723 }
23724 }
23725}
23726#[doc = "Create a new rule."]
23727#[derive(Clone)]
23728pub enum OpNewruleDoReply {}
23729impl<'a> IterableOpNewruleDoReply<'a> {}
23730impl OpNewruleDoReply {
23731 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpNewruleDoReply<'_>) {
23732 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
23733 (
23734 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
23735 IterableOpNewruleDoReply::with_loc(attrs, buf.as_ptr() as usize),
23736 )
23737 }
23738 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23739 RuleAttrs::attr_from_type(r#type)
23740 }
23741}
23742#[derive(Clone, Copy, Default)]
23743pub struct IterableOpNewruleDoReply<'a> {
23744 buf: &'a [u8],
23745 pos: usize,
23746 orig_loc: usize,
23747}
23748impl<'a> IterableOpNewruleDoReply<'a> {
23749 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
23750 Self {
23751 buf,
23752 pos: 0,
23753 orig_loc,
23754 }
23755 }
23756 pub fn get_buf(&self) -> &'a [u8] {
23757 self.buf
23758 }
23759}
23760impl<'a> Iterator for IterableOpNewruleDoReply<'a> {
23761 type Item = Result<OpNewruleDoReply, ErrorContext>;
23762 fn next(&mut self) -> Option<Self::Item> {
23763 if self.buf.len() == self.pos {
23764 return None;
23765 }
23766 let pos = self.pos;
23767 let mut r#type = None;
23768 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
23769 r#type = Some(header.r#type);
23770 let res = match header.r#type {
23771 n => {
23772 if cfg!(any(test, feature = "deny-unknown-attrs")) {
23773 break;
23774 } else {
23775 continue;
23776 }
23777 }
23778 };
23779 return Some(Ok(res));
23780 }
23781 Some(Err(ErrorContext::new(
23782 "OpNewruleDoReply",
23783 r#type.and_then(|t| OpNewruleDoReply::attr_from_type(t)),
23784 self.orig_loc,
23785 self.buf.as_ptr().wrapping_add(pos) as usize,
23786 )))
23787 }
23788}
23789impl std::fmt::Debug for IterableOpNewruleDoReply<'_> {
23790 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23791 let mut fmt = f.debug_struct("OpNewruleDoReply");
23792 for attr in self.clone() {
23793 let attr = match attr {
23794 Ok(a) => a,
23795 Err(err) => {
23796 fmt.finish()?;
23797 f.write_str("Err(")?;
23798 err.fmt(f)?;
23799 return f.write_str(")");
23800 }
23801 };
23802 match attr {};
23803 }
23804 fmt.finish()
23805 }
23806}
23807impl IterableOpNewruleDoReply<'_> {
23808 pub fn lookup_attr(
23809 &self,
23810 offset: usize,
23811 missing_type: Option<u16>,
23812 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23813 let mut stack = Vec::new();
23814 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
23815 if cur == offset + PushNfgenmsg::len() {
23816 stack.push(("OpNewruleDoReply", offset));
23817 return (
23818 stack,
23819 missing_type.and_then(|t| OpNewruleDoReply::attr_from_type(t)),
23820 );
23821 }
23822 (stack, None)
23823 }
23824}
23825#[derive(Debug)]
23826pub struct RequestOpNewruleDoRequest<'r> {
23827 request: Request<'r>,
23828}
23829impl<'r> RequestOpNewruleDoRequest<'r> {
23830 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
23831 PushOpNewruleDoRequest::write_header(&mut request.buf_mut(), header);
23832 Self { request: request }
23833 }
23834 pub fn encode(&mut self) -> PushOpNewruleDoRequest<&mut Vec<u8>> {
23835 PushOpNewruleDoRequest::new_without_header(self.request.buf_mut())
23836 }
23837 pub fn into_encoder(self) -> PushOpNewruleDoRequest<RequestBuf<'r>> {
23838 PushOpNewruleDoRequest::new_without_header(self.request.buf)
23839 }
23840}
23841impl NetlinkRequest for RequestOpNewruleDoRequest<'_> {
23842 type ReplyType<'buf> = (PushNfgenmsg, IterableOpNewruleDoReply<'buf>);
23843 fn protocol(&self) -> Protocol {
23844 Protocol::Raw {
23845 protonum: 12u16,
23846 request_type: 2566u16,
23847 }
23848 }
23849 fn flags(&self) -> u16 {
23850 self.request.flags
23851 }
23852 fn payload(&self) -> &[u8] {
23853 self.request.buf()
23854 }
23855 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
23856 OpNewruleDoReply::new(buf)
23857 }
23858 fn lookup(
23859 buf: &[u8],
23860 offset: usize,
23861 missing_type: Option<u16>,
23862 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
23863 OpNewruleDoRequest::new(buf)
23864 .1
23865 .lookup_attr(offset, missing_type)
23866 }
23867}
23868#[doc = "Get / dump rules."]
23869pub struct PushOpGetruleDumpRequest<Prev: Rec> {
23870 pub(crate) prev: Option<Prev>,
23871 pub(crate) header_offset: Option<usize>,
23872}
23873impl<Prev: Rec> Rec for PushOpGetruleDumpRequest<Prev> {
23874 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
23875 self.prev.as_mut().unwrap().as_rec_mut()
23876 }
23877}
23878impl<Prev: Rec> PushOpGetruleDumpRequest<Prev> {
23879 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
23880 Self::write_header(&mut prev, header);
23881 Self::new_without_header(prev)
23882 }
23883 fn new_without_header(prev: Prev) -> Self {
23884 Self {
23885 prev: Some(prev),
23886 header_offset: None,
23887 }
23888 }
23889 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
23890 prev.as_rec_mut().extend(header.as_slice());
23891 }
23892 pub fn end_nested(mut self) -> Prev {
23893 let mut prev = self.prev.take().unwrap();
23894 if let Some(header_offset) = &self.header_offset {
23895 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23896 }
23897 prev
23898 }
23899 #[doc = "name of the table containing the rule"]
23900 pub fn push_table(mut self, value: &CStr) -> Self {
23901 push_header(
23902 self.as_rec_mut(),
23903 1u16,
23904 value.to_bytes_with_nul().len() as u16,
23905 );
23906 self.as_rec_mut().extend(value.to_bytes_with_nul());
23907 self
23908 }
23909 #[doc = "name of the table containing the rule"]
23910 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
23911 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
23912 self.as_rec_mut().extend(value);
23913 self.as_rec_mut().push(0);
23914 self
23915 }
23916 #[doc = "name of the chain containing the rule"]
23917 pub fn push_chain(mut self, value: &CStr) -> Self {
23918 push_header(
23919 self.as_rec_mut(),
23920 2u16,
23921 value.to_bytes_with_nul().len() as u16,
23922 );
23923 self.as_rec_mut().extend(value.to_bytes_with_nul());
23924 self
23925 }
23926 #[doc = "name of the chain containing the rule"]
23927 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
23928 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
23929 self.as_rec_mut().extend(value);
23930 self.as_rec_mut().push(0);
23931 self
23932 }
23933}
23934impl<Prev: Rec> Drop for PushOpGetruleDumpRequest<Prev> {
23935 fn drop(&mut self) {
23936 if let Some(prev) = &mut self.prev {
23937 if let Some(header_offset) = &self.header_offset {
23938 finalize_nested_header(prev.as_rec_mut(), *header_offset);
23939 }
23940 }
23941 }
23942}
23943#[doc = "Get / dump rules."]
23944#[derive(Clone)]
23945pub enum OpGetruleDumpRequest<'a> {
23946 #[doc = "name of the table containing the rule"]
23947 Table(&'a CStr),
23948 #[doc = "name of the chain containing the rule"]
23949 Chain(&'a CStr),
23950}
23951impl<'a> IterableOpGetruleDumpRequest<'a> {
23952 #[doc = "name of the table containing the rule"]
23953 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
23954 let mut iter = self.clone();
23955 iter.pos = 0;
23956 for attr in iter {
23957 if let OpGetruleDumpRequest::Table(val) = attr? {
23958 return Ok(val);
23959 }
23960 }
23961 Err(ErrorContext::new_missing(
23962 "OpGetruleDumpRequest",
23963 "Table",
23964 self.orig_loc,
23965 self.buf.as_ptr() as usize,
23966 ))
23967 }
23968 #[doc = "name of the chain containing the rule"]
23969 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
23970 let mut iter = self.clone();
23971 iter.pos = 0;
23972 for attr in iter {
23973 if let OpGetruleDumpRequest::Chain(val) = attr? {
23974 return Ok(val);
23975 }
23976 }
23977 Err(ErrorContext::new_missing(
23978 "OpGetruleDumpRequest",
23979 "Chain",
23980 self.orig_loc,
23981 self.buf.as_ptr() as usize,
23982 ))
23983 }
23984}
23985impl<'a> OpGetruleDumpRequest<'a> {
23986 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetruleDumpRequest<'a>) {
23987 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
23988 (
23989 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
23990 IterableOpGetruleDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
23991 )
23992 }
23993 fn attr_from_type(r#type: u16) -> Option<&'static str> {
23994 RuleAttrs::attr_from_type(r#type)
23995 }
23996}
23997#[derive(Clone, Copy, Default)]
23998pub struct IterableOpGetruleDumpRequest<'a> {
23999 buf: &'a [u8],
24000 pos: usize,
24001 orig_loc: usize,
24002}
24003impl<'a> IterableOpGetruleDumpRequest<'a> {
24004 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
24005 Self {
24006 buf,
24007 pos: 0,
24008 orig_loc,
24009 }
24010 }
24011 pub fn get_buf(&self) -> &'a [u8] {
24012 self.buf
24013 }
24014}
24015impl<'a> Iterator for IterableOpGetruleDumpRequest<'a> {
24016 type Item = Result<OpGetruleDumpRequest<'a>, ErrorContext>;
24017 fn next(&mut self) -> Option<Self::Item> {
24018 if self.buf.len() == self.pos {
24019 return None;
24020 }
24021 let pos = self.pos;
24022 let mut r#type = None;
24023 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
24024 r#type = Some(header.r#type);
24025 let res = match header.r#type {
24026 1u16 => OpGetruleDumpRequest::Table({
24027 let res = CStr::from_bytes_with_nul(next).ok();
24028 let Some(val) = res else { break };
24029 val
24030 }),
24031 2u16 => OpGetruleDumpRequest::Chain({
24032 let res = CStr::from_bytes_with_nul(next).ok();
24033 let Some(val) = res else { break };
24034 val
24035 }),
24036 n => {
24037 if cfg!(any(test, feature = "deny-unknown-attrs")) {
24038 break;
24039 } else {
24040 continue;
24041 }
24042 }
24043 };
24044 return Some(Ok(res));
24045 }
24046 Some(Err(ErrorContext::new(
24047 "OpGetruleDumpRequest",
24048 r#type.and_then(|t| OpGetruleDumpRequest::attr_from_type(t)),
24049 self.orig_loc,
24050 self.buf.as_ptr().wrapping_add(pos) as usize,
24051 )))
24052 }
24053}
24054impl<'a> std::fmt::Debug for IterableOpGetruleDumpRequest<'_> {
24055 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24056 let mut fmt = f.debug_struct("OpGetruleDumpRequest");
24057 for attr in self.clone() {
24058 let attr = match attr {
24059 Ok(a) => a,
24060 Err(err) => {
24061 fmt.finish()?;
24062 f.write_str("Err(")?;
24063 err.fmt(f)?;
24064 return f.write_str(")");
24065 }
24066 };
24067 match attr {
24068 OpGetruleDumpRequest::Table(val) => fmt.field("Table", &val),
24069 OpGetruleDumpRequest::Chain(val) => fmt.field("Chain", &val),
24070 };
24071 }
24072 fmt.finish()
24073 }
24074}
24075impl IterableOpGetruleDumpRequest<'_> {
24076 pub fn lookup_attr(
24077 &self,
24078 offset: usize,
24079 missing_type: Option<u16>,
24080 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
24081 let mut stack = Vec::new();
24082 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
24083 if cur == offset + PushNfgenmsg::len() {
24084 stack.push(("OpGetruleDumpRequest", offset));
24085 return (
24086 stack,
24087 missing_type.and_then(|t| OpGetruleDumpRequest::attr_from_type(t)),
24088 );
24089 }
24090 if cur > offset || cur + self.buf.len() < offset {
24091 return (stack, None);
24092 }
24093 let mut attrs = self.clone();
24094 let mut last_off = cur + attrs.pos;
24095 while let Some(attr) = attrs.next() {
24096 let Ok(attr) = attr else { break };
24097 match attr {
24098 OpGetruleDumpRequest::Table(val) => {
24099 if last_off == offset {
24100 stack.push(("Table", last_off));
24101 break;
24102 }
24103 }
24104 OpGetruleDumpRequest::Chain(val) => {
24105 if last_off == offset {
24106 stack.push(("Chain", last_off));
24107 break;
24108 }
24109 }
24110 _ => {}
24111 };
24112 last_off = cur + attrs.pos;
24113 }
24114 if !stack.is_empty() {
24115 stack.push(("OpGetruleDumpRequest", cur));
24116 }
24117 (stack, None)
24118 }
24119}
24120#[doc = "Get / dump rules."]
24121pub struct PushOpGetruleDumpReply<Prev: Rec> {
24122 pub(crate) prev: Option<Prev>,
24123 pub(crate) header_offset: Option<usize>,
24124}
24125impl<Prev: Rec> Rec for PushOpGetruleDumpReply<Prev> {
24126 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
24127 self.prev.as_mut().unwrap().as_rec_mut()
24128 }
24129}
24130impl<Prev: Rec> PushOpGetruleDumpReply<Prev> {
24131 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
24132 Self::write_header(&mut prev, header);
24133 Self::new_without_header(prev)
24134 }
24135 fn new_without_header(prev: Prev) -> Self {
24136 Self {
24137 prev: Some(prev),
24138 header_offset: None,
24139 }
24140 }
24141 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
24142 prev.as_rec_mut().extend(header.as_slice());
24143 }
24144 pub fn end_nested(mut self) -> Prev {
24145 let mut prev = self.prev.take().unwrap();
24146 if let Some(header_offset) = &self.header_offset {
24147 finalize_nested_header(prev.as_rec_mut(), *header_offset);
24148 }
24149 prev
24150 }
24151 #[doc = "name of the table containing the rule"]
24152 pub fn push_table(mut self, value: &CStr) -> Self {
24153 push_header(
24154 self.as_rec_mut(),
24155 1u16,
24156 value.to_bytes_with_nul().len() as u16,
24157 );
24158 self.as_rec_mut().extend(value.to_bytes_with_nul());
24159 self
24160 }
24161 #[doc = "name of the table containing the rule"]
24162 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
24163 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
24164 self.as_rec_mut().extend(value);
24165 self.as_rec_mut().push(0);
24166 self
24167 }
24168 #[doc = "name of the chain containing the rule"]
24169 pub fn push_chain(mut self, value: &CStr) -> Self {
24170 push_header(
24171 self.as_rec_mut(),
24172 2u16,
24173 value.to_bytes_with_nul().len() as u16,
24174 );
24175 self.as_rec_mut().extend(value.to_bytes_with_nul());
24176 self
24177 }
24178 #[doc = "name of the chain containing the rule"]
24179 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
24180 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
24181 self.as_rec_mut().extend(value);
24182 self.as_rec_mut().push(0);
24183 self
24184 }
24185 #[doc = "numeric handle of the rule"]
24186 pub fn push_handle(mut self, value: u64) -> Self {
24187 push_header(self.as_rec_mut(), 3u16, 8 as u16);
24188 self.as_rec_mut().extend(value.to_be_bytes());
24189 self
24190 }
24191 #[doc = "list of expressions"]
24192 pub fn nested_expressions(mut self) -> PushExprListAttrs<Self> {
24193 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
24194 PushExprListAttrs {
24195 prev: Some(self),
24196 header_offset: Some(header_offset),
24197 }
24198 }
24199 #[doc = "numeric handle of the previous rule"]
24200 pub fn push_position(mut self, value: u64) -> Self {
24201 push_header(self.as_rec_mut(), 6u16, 8 as u16);
24202 self.as_rec_mut().extend(value.to_be_bytes());
24203 self
24204 }
24205 #[doc = "user data"]
24206 pub fn push_userdata(mut self, value: &[u8]) -> Self {
24207 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
24208 self.as_rec_mut().extend(value);
24209 self
24210 }
24211}
24212impl<Prev: Rec> Drop for PushOpGetruleDumpReply<Prev> {
24213 fn drop(&mut self) {
24214 if let Some(prev) = &mut self.prev {
24215 if let Some(header_offset) = &self.header_offset {
24216 finalize_nested_header(prev.as_rec_mut(), *header_offset);
24217 }
24218 }
24219 }
24220}
24221#[doc = "Get / dump rules."]
24222#[derive(Clone)]
24223pub enum OpGetruleDumpReply<'a> {
24224 #[doc = "name of the table containing the rule"]
24225 Table(&'a CStr),
24226 #[doc = "name of the chain containing the rule"]
24227 Chain(&'a CStr),
24228 #[doc = "numeric handle of the rule"]
24229 Handle(u64),
24230 #[doc = "list of expressions"]
24231 Expressions(IterableExprListAttrs<'a>),
24232 #[doc = "numeric handle of the previous rule"]
24233 Position(u64),
24234 #[doc = "user data"]
24235 Userdata(&'a [u8]),
24236}
24237impl<'a> IterableOpGetruleDumpReply<'a> {
24238 #[doc = "name of the table containing the rule"]
24239 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
24240 let mut iter = self.clone();
24241 iter.pos = 0;
24242 for attr in iter {
24243 if let OpGetruleDumpReply::Table(val) = attr? {
24244 return Ok(val);
24245 }
24246 }
24247 Err(ErrorContext::new_missing(
24248 "OpGetruleDumpReply",
24249 "Table",
24250 self.orig_loc,
24251 self.buf.as_ptr() as usize,
24252 ))
24253 }
24254 #[doc = "name of the chain containing the rule"]
24255 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
24256 let mut iter = self.clone();
24257 iter.pos = 0;
24258 for attr in iter {
24259 if let OpGetruleDumpReply::Chain(val) = attr? {
24260 return Ok(val);
24261 }
24262 }
24263 Err(ErrorContext::new_missing(
24264 "OpGetruleDumpReply",
24265 "Chain",
24266 self.orig_loc,
24267 self.buf.as_ptr() as usize,
24268 ))
24269 }
24270 #[doc = "numeric handle of the rule"]
24271 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
24272 let mut iter = self.clone();
24273 iter.pos = 0;
24274 for attr in iter {
24275 if let OpGetruleDumpReply::Handle(val) = attr? {
24276 return Ok(val);
24277 }
24278 }
24279 Err(ErrorContext::new_missing(
24280 "OpGetruleDumpReply",
24281 "Handle",
24282 self.orig_loc,
24283 self.buf.as_ptr() as usize,
24284 ))
24285 }
24286 #[doc = "list of expressions"]
24287 pub fn get_expressions(&self) -> Result<IterableExprListAttrs<'a>, ErrorContext> {
24288 let mut iter = self.clone();
24289 iter.pos = 0;
24290 for attr in iter {
24291 if let OpGetruleDumpReply::Expressions(val) = attr? {
24292 return Ok(val);
24293 }
24294 }
24295 Err(ErrorContext::new_missing(
24296 "OpGetruleDumpReply",
24297 "Expressions",
24298 self.orig_loc,
24299 self.buf.as_ptr() as usize,
24300 ))
24301 }
24302 #[doc = "numeric handle of the previous rule"]
24303 pub fn get_position(&self) -> Result<u64, ErrorContext> {
24304 let mut iter = self.clone();
24305 iter.pos = 0;
24306 for attr in iter {
24307 if let OpGetruleDumpReply::Position(val) = attr? {
24308 return Ok(val);
24309 }
24310 }
24311 Err(ErrorContext::new_missing(
24312 "OpGetruleDumpReply",
24313 "Position",
24314 self.orig_loc,
24315 self.buf.as_ptr() as usize,
24316 ))
24317 }
24318 #[doc = "user data"]
24319 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
24320 let mut iter = self.clone();
24321 iter.pos = 0;
24322 for attr in iter {
24323 if let OpGetruleDumpReply::Userdata(val) = attr? {
24324 return Ok(val);
24325 }
24326 }
24327 Err(ErrorContext::new_missing(
24328 "OpGetruleDumpReply",
24329 "Userdata",
24330 self.orig_loc,
24331 self.buf.as_ptr() as usize,
24332 ))
24333 }
24334}
24335impl<'a> OpGetruleDumpReply<'a> {
24336 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetruleDumpReply<'a>) {
24337 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
24338 (
24339 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
24340 IterableOpGetruleDumpReply::with_loc(attrs, buf.as_ptr() as usize),
24341 )
24342 }
24343 fn attr_from_type(r#type: u16) -> Option<&'static str> {
24344 RuleAttrs::attr_from_type(r#type)
24345 }
24346}
24347#[derive(Clone, Copy, Default)]
24348pub struct IterableOpGetruleDumpReply<'a> {
24349 buf: &'a [u8],
24350 pos: usize,
24351 orig_loc: usize,
24352}
24353impl<'a> IterableOpGetruleDumpReply<'a> {
24354 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
24355 Self {
24356 buf,
24357 pos: 0,
24358 orig_loc,
24359 }
24360 }
24361 pub fn get_buf(&self) -> &'a [u8] {
24362 self.buf
24363 }
24364}
24365impl<'a> Iterator for IterableOpGetruleDumpReply<'a> {
24366 type Item = Result<OpGetruleDumpReply<'a>, ErrorContext>;
24367 fn next(&mut self) -> Option<Self::Item> {
24368 if self.buf.len() == self.pos {
24369 return None;
24370 }
24371 let pos = self.pos;
24372 let mut r#type = None;
24373 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
24374 r#type = Some(header.r#type);
24375 let res = match header.r#type {
24376 1u16 => OpGetruleDumpReply::Table({
24377 let res = CStr::from_bytes_with_nul(next).ok();
24378 let Some(val) = res else { break };
24379 val
24380 }),
24381 2u16 => OpGetruleDumpReply::Chain({
24382 let res = CStr::from_bytes_with_nul(next).ok();
24383 let Some(val) = res else { break };
24384 val
24385 }),
24386 3u16 => OpGetruleDumpReply::Handle({
24387 let res = parse_be_u64(next);
24388 let Some(val) = res else { break };
24389 val
24390 }),
24391 4u16 => OpGetruleDumpReply::Expressions({
24392 let res = Some(IterableExprListAttrs::with_loc(next, self.orig_loc));
24393 let Some(val) = res else { break };
24394 val
24395 }),
24396 6u16 => OpGetruleDumpReply::Position({
24397 let res = parse_be_u64(next);
24398 let Some(val) = res else { break };
24399 val
24400 }),
24401 7u16 => OpGetruleDumpReply::Userdata({
24402 let res = Some(next);
24403 let Some(val) = res else { break };
24404 val
24405 }),
24406 n => {
24407 if cfg!(any(test, feature = "deny-unknown-attrs")) {
24408 break;
24409 } else {
24410 continue;
24411 }
24412 }
24413 };
24414 return Some(Ok(res));
24415 }
24416 Some(Err(ErrorContext::new(
24417 "OpGetruleDumpReply",
24418 r#type.and_then(|t| OpGetruleDumpReply::attr_from_type(t)),
24419 self.orig_loc,
24420 self.buf.as_ptr().wrapping_add(pos) as usize,
24421 )))
24422 }
24423}
24424impl<'a> std::fmt::Debug for IterableOpGetruleDumpReply<'_> {
24425 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24426 let mut fmt = f.debug_struct("OpGetruleDumpReply");
24427 for attr in self.clone() {
24428 let attr = match attr {
24429 Ok(a) => a,
24430 Err(err) => {
24431 fmt.finish()?;
24432 f.write_str("Err(")?;
24433 err.fmt(f)?;
24434 return f.write_str(")");
24435 }
24436 };
24437 match attr {
24438 OpGetruleDumpReply::Table(val) => fmt.field("Table", &val),
24439 OpGetruleDumpReply::Chain(val) => fmt.field("Chain", &val),
24440 OpGetruleDumpReply::Handle(val) => fmt.field("Handle", &val),
24441 OpGetruleDumpReply::Expressions(val) => fmt.field("Expressions", &val),
24442 OpGetruleDumpReply::Position(val) => fmt.field("Position", &val),
24443 OpGetruleDumpReply::Userdata(val) => fmt.field("Userdata", &val),
24444 };
24445 }
24446 fmt.finish()
24447 }
24448}
24449impl IterableOpGetruleDumpReply<'_> {
24450 pub fn lookup_attr(
24451 &self,
24452 offset: usize,
24453 missing_type: Option<u16>,
24454 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
24455 let mut stack = Vec::new();
24456 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
24457 if cur == offset + PushNfgenmsg::len() {
24458 stack.push(("OpGetruleDumpReply", offset));
24459 return (
24460 stack,
24461 missing_type.and_then(|t| OpGetruleDumpReply::attr_from_type(t)),
24462 );
24463 }
24464 if cur > offset || cur + self.buf.len() < offset {
24465 return (stack, None);
24466 }
24467 let mut attrs = self.clone();
24468 let mut last_off = cur + attrs.pos;
24469 let mut missing = None;
24470 while let Some(attr) = attrs.next() {
24471 let Ok(attr) = attr else { break };
24472 match attr {
24473 OpGetruleDumpReply::Table(val) => {
24474 if last_off == offset {
24475 stack.push(("Table", last_off));
24476 break;
24477 }
24478 }
24479 OpGetruleDumpReply::Chain(val) => {
24480 if last_off == offset {
24481 stack.push(("Chain", last_off));
24482 break;
24483 }
24484 }
24485 OpGetruleDumpReply::Handle(val) => {
24486 if last_off == offset {
24487 stack.push(("Handle", last_off));
24488 break;
24489 }
24490 }
24491 OpGetruleDumpReply::Expressions(val) => {
24492 (stack, missing) = val.lookup_attr(offset, missing_type);
24493 if !stack.is_empty() {
24494 break;
24495 }
24496 }
24497 OpGetruleDumpReply::Position(val) => {
24498 if last_off == offset {
24499 stack.push(("Position", last_off));
24500 break;
24501 }
24502 }
24503 OpGetruleDumpReply::Userdata(val) => {
24504 if last_off == offset {
24505 stack.push(("Userdata", last_off));
24506 break;
24507 }
24508 }
24509 _ => {}
24510 };
24511 last_off = cur + attrs.pos;
24512 }
24513 if !stack.is_empty() {
24514 stack.push(("OpGetruleDumpReply", cur));
24515 }
24516 (stack, missing)
24517 }
24518}
24519#[derive(Debug)]
24520pub struct RequestOpGetruleDumpRequest<'r> {
24521 request: Request<'r>,
24522}
24523impl<'r> RequestOpGetruleDumpRequest<'r> {
24524 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
24525 PushOpGetruleDumpRequest::write_header(&mut request.buf_mut(), header);
24526 Self {
24527 request: request.set_dump(),
24528 }
24529 }
24530 pub fn encode(&mut self) -> PushOpGetruleDumpRequest<&mut Vec<u8>> {
24531 PushOpGetruleDumpRequest::new_without_header(self.request.buf_mut())
24532 }
24533 pub fn into_encoder(self) -> PushOpGetruleDumpRequest<RequestBuf<'r>> {
24534 PushOpGetruleDumpRequest::new_without_header(self.request.buf)
24535 }
24536}
24537impl NetlinkRequest for RequestOpGetruleDumpRequest<'_> {
24538 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetruleDumpReply<'buf>);
24539 fn protocol(&self) -> Protocol {
24540 Protocol::Raw {
24541 protonum: 12u16,
24542 request_type: 2567u16,
24543 }
24544 }
24545 fn flags(&self) -> u16 {
24546 self.request.flags
24547 }
24548 fn payload(&self) -> &[u8] {
24549 self.request.buf()
24550 }
24551 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
24552 OpGetruleDumpReply::new(buf)
24553 }
24554 fn lookup(
24555 buf: &[u8],
24556 offset: usize,
24557 missing_type: Option<u16>,
24558 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
24559 OpGetruleDumpRequest::new(buf)
24560 .1
24561 .lookup_attr(offset, missing_type)
24562 }
24563}
24564#[doc = "Get / dump rules."]
24565pub struct PushOpGetruleDoRequest<Prev: Rec> {
24566 pub(crate) prev: Option<Prev>,
24567 pub(crate) header_offset: Option<usize>,
24568}
24569impl<Prev: Rec> Rec for PushOpGetruleDoRequest<Prev> {
24570 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
24571 self.prev.as_mut().unwrap().as_rec_mut()
24572 }
24573}
24574impl<Prev: Rec> PushOpGetruleDoRequest<Prev> {
24575 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
24576 Self::write_header(&mut prev, header);
24577 Self::new_without_header(prev)
24578 }
24579 fn new_without_header(prev: Prev) -> Self {
24580 Self {
24581 prev: Some(prev),
24582 header_offset: None,
24583 }
24584 }
24585 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
24586 prev.as_rec_mut().extend(header.as_slice());
24587 }
24588 pub fn end_nested(mut self) -> Prev {
24589 let mut prev = self.prev.take().unwrap();
24590 if let Some(header_offset) = &self.header_offset {
24591 finalize_nested_header(prev.as_rec_mut(), *header_offset);
24592 }
24593 prev
24594 }
24595 #[doc = "name of the table containing the rule"]
24596 pub fn push_table(mut self, value: &CStr) -> Self {
24597 push_header(
24598 self.as_rec_mut(),
24599 1u16,
24600 value.to_bytes_with_nul().len() as u16,
24601 );
24602 self.as_rec_mut().extend(value.to_bytes_with_nul());
24603 self
24604 }
24605 #[doc = "name of the table containing the rule"]
24606 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
24607 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
24608 self.as_rec_mut().extend(value);
24609 self.as_rec_mut().push(0);
24610 self
24611 }
24612 #[doc = "name of the chain containing the rule"]
24613 pub fn push_chain(mut self, value: &CStr) -> Self {
24614 push_header(
24615 self.as_rec_mut(),
24616 2u16,
24617 value.to_bytes_with_nul().len() as u16,
24618 );
24619 self.as_rec_mut().extend(value.to_bytes_with_nul());
24620 self
24621 }
24622 #[doc = "name of the chain containing the rule"]
24623 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
24624 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
24625 self.as_rec_mut().extend(value);
24626 self.as_rec_mut().push(0);
24627 self
24628 }
24629 #[doc = "numeric handle of the rule"]
24630 pub fn push_handle(mut self, value: u64) -> Self {
24631 push_header(self.as_rec_mut(), 3u16, 8 as u16);
24632 self.as_rec_mut().extend(value.to_be_bytes());
24633 self
24634 }
24635}
24636impl<Prev: Rec> Drop for PushOpGetruleDoRequest<Prev> {
24637 fn drop(&mut self) {
24638 if let Some(prev) = &mut self.prev {
24639 if let Some(header_offset) = &self.header_offset {
24640 finalize_nested_header(prev.as_rec_mut(), *header_offset);
24641 }
24642 }
24643 }
24644}
24645#[doc = "Get / dump rules."]
24646#[derive(Clone)]
24647pub enum OpGetruleDoRequest<'a> {
24648 #[doc = "name of the table containing the rule"]
24649 Table(&'a CStr),
24650 #[doc = "name of the chain containing the rule"]
24651 Chain(&'a CStr),
24652 #[doc = "numeric handle of the rule"]
24653 Handle(u64),
24654}
24655impl<'a> IterableOpGetruleDoRequest<'a> {
24656 #[doc = "name of the table containing the rule"]
24657 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
24658 let mut iter = self.clone();
24659 iter.pos = 0;
24660 for attr in iter {
24661 if let OpGetruleDoRequest::Table(val) = attr? {
24662 return Ok(val);
24663 }
24664 }
24665 Err(ErrorContext::new_missing(
24666 "OpGetruleDoRequest",
24667 "Table",
24668 self.orig_loc,
24669 self.buf.as_ptr() as usize,
24670 ))
24671 }
24672 #[doc = "name of the chain containing the rule"]
24673 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
24674 let mut iter = self.clone();
24675 iter.pos = 0;
24676 for attr in iter {
24677 if let OpGetruleDoRequest::Chain(val) = attr? {
24678 return Ok(val);
24679 }
24680 }
24681 Err(ErrorContext::new_missing(
24682 "OpGetruleDoRequest",
24683 "Chain",
24684 self.orig_loc,
24685 self.buf.as_ptr() as usize,
24686 ))
24687 }
24688 #[doc = "numeric handle of the rule"]
24689 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
24690 let mut iter = self.clone();
24691 iter.pos = 0;
24692 for attr in iter {
24693 if let OpGetruleDoRequest::Handle(val) = attr? {
24694 return Ok(val);
24695 }
24696 }
24697 Err(ErrorContext::new_missing(
24698 "OpGetruleDoRequest",
24699 "Handle",
24700 self.orig_loc,
24701 self.buf.as_ptr() as usize,
24702 ))
24703 }
24704}
24705impl<'a> OpGetruleDoRequest<'a> {
24706 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetruleDoRequest<'a>) {
24707 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
24708 (
24709 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
24710 IterableOpGetruleDoRequest::with_loc(attrs, buf.as_ptr() as usize),
24711 )
24712 }
24713 fn attr_from_type(r#type: u16) -> Option<&'static str> {
24714 RuleAttrs::attr_from_type(r#type)
24715 }
24716}
24717#[derive(Clone, Copy, Default)]
24718pub struct IterableOpGetruleDoRequest<'a> {
24719 buf: &'a [u8],
24720 pos: usize,
24721 orig_loc: usize,
24722}
24723impl<'a> IterableOpGetruleDoRequest<'a> {
24724 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
24725 Self {
24726 buf,
24727 pos: 0,
24728 orig_loc,
24729 }
24730 }
24731 pub fn get_buf(&self) -> &'a [u8] {
24732 self.buf
24733 }
24734}
24735impl<'a> Iterator for IterableOpGetruleDoRequest<'a> {
24736 type Item = Result<OpGetruleDoRequest<'a>, ErrorContext>;
24737 fn next(&mut self) -> Option<Self::Item> {
24738 if self.buf.len() == self.pos {
24739 return None;
24740 }
24741 let pos = self.pos;
24742 let mut r#type = None;
24743 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
24744 r#type = Some(header.r#type);
24745 let res = match header.r#type {
24746 1u16 => OpGetruleDoRequest::Table({
24747 let res = CStr::from_bytes_with_nul(next).ok();
24748 let Some(val) = res else { break };
24749 val
24750 }),
24751 2u16 => OpGetruleDoRequest::Chain({
24752 let res = CStr::from_bytes_with_nul(next).ok();
24753 let Some(val) = res else { break };
24754 val
24755 }),
24756 3u16 => OpGetruleDoRequest::Handle({
24757 let res = parse_be_u64(next);
24758 let Some(val) = res else { break };
24759 val
24760 }),
24761 n => {
24762 if cfg!(any(test, feature = "deny-unknown-attrs")) {
24763 break;
24764 } else {
24765 continue;
24766 }
24767 }
24768 };
24769 return Some(Ok(res));
24770 }
24771 Some(Err(ErrorContext::new(
24772 "OpGetruleDoRequest",
24773 r#type.and_then(|t| OpGetruleDoRequest::attr_from_type(t)),
24774 self.orig_loc,
24775 self.buf.as_ptr().wrapping_add(pos) as usize,
24776 )))
24777 }
24778}
24779impl<'a> std::fmt::Debug for IterableOpGetruleDoRequest<'_> {
24780 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24781 let mut fmt = f.debug_struct("OpGetruleDoRequest");
24782 for attr in self.clone() {
24783 let attr = match attr {
24784 Ok(a) => a,
24785 Err(err) => {
24786 fmt.finish()?;
24787 f.write_str("Err(")?;
24788 err.fmt(f)?;
24789 return f.write_str(")");
24790 }
24791 };
24792 match attr {
24793 OpGetruleDoRequest::Table(val) => fmt.field("Table", &val),
24794 OpGetruleDoRequest::Chain(val) => fmt.field("Chain", &val),
24795 OpGetruleDoRequest::Handle(val) => fmt.field("Handle", &val),
24796 };
24797 }
24798 fmt.finish()
24799 }
24800}
24801impl IterableOpGetruleDoRequest<'_> {
24802 pub fn lookup_attr(
24803 &self,
24804 offset: usize,
24805 missing_type: Option<u16>,
24806 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
24807 let mut stack = Vec::new();
24808 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
24809 if cur == offset + PushNfgenmsg::len() {
24810 stack.push(("OpGetruleDoRequest", offset));
24811 return (
24812 stack,
24813 missing_type.and_then(|t| OpGetruleDoRequest::attr_from_type(t)),
24814 );
24815 }
24816 if cur > offset || cur + self.buf.len() < offset {
24817 return (stack, None);
24818 }
24819 let mut attrs = self.clone();
24820 let mut last_off = cur + attrs.pos;
24821 while let Some(attr) = attrs.next() {
24822 let Ok(attr) = attr else { break };
24823 match attr {
24824 OpGetruleDoRequest::Table(val) => {
24825 if last_off == offset {
24826 stack.push(("Table", last_off));
24827 break;
24828 }
24829 }
24830 OpGetruleDoRequest::Chain(val) => {
24831 if last_off == offset {
24832 stack.push(("Chain", last_off));
24833 break;
24834 }
24835 }
24836 OpGetruleDoRequest::Handle(val) => {
24837 if last_off == offset {
24838 stack.push(("Handle", last_off));
24839 break;
24840 }
24841 }
24842 _ => {}
24843 };
24844 last_off = cur + attrs.pos;
24845 }
24846 if !stack.is_empty() {
24847 stack.push(("OpGetruleDoRequest", cur));
24848 }
24849 (stack, None)
24850 }
24851}
24852#[doc = "Get / dump rules."]
24853pub struct PushOpGetruleDoReply<Prev: Rec> {
24854 pub(crate) prev: Option<Prev>,
24855 pub(crate) header_offset: Option<usize>,
24856}
24857impl<Prev: Rec> Rec for PushOpGetruleDoReply<Prev> {
24858 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
24859 self.prev.as_mut().unwrap().as_rec_mut()
24860 }
24861}
24862impl<Prev: Rec> PushOpGetruleDoReply<Prev> {
24863 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
24864 Self::write_header(&mut prev, header);
24865 Self::new_without_header(prev)
24866 }
24867 fn new_without_header(prev: Prev) -> Self {
24868 Self {
24869 prev: Some(prev),
24870 header_offset: None,
24871 }
24872 }
24873 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
24874 prev.as_rec_mut().extend(header.as_slice());
24875 }
24876 pub fn end_nested(mut self) -> Prev {
24877 let mut prev = self.prev.take().unwrap();
24878 if let Some(header_offset) = &self.header_offset {
24879 finalize_nested_header(prev.as_rec_mut(), *header_offset);
24880 }
24881 prev
24882 }
24883 #[doc = "name of the table containing the rule"]
24884 pub fn push_table(mut self, value: &CStr) -> Self {
24885 push_header(
24886 self.as_rec_mut(),
24887 1u16,
24888 value.to_bytes_with_nul().len() as u16,
24889 );
24890 self.as_rec_mut().extend(value.to_bytes_with_nul());
24891 self
24892 }
24893 #[doc = "name of the table containing the rule"]
24894 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
24895 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
24896 self.as_rec_mut().extend(value);
24897 self.as_rec_mut().push(0);
24898 self
24899 }
24900 #[doc = "name of the chain containing the rule"]
24901 pub fn push_chain(mut self, value: &CStr) -> Self {
24902 push_header(
24903 self.as_rec_mut(),
24904 2u16,
24905 value.to_bytes_with_nul().len() as u16,
24906 );
24907 self.as_rec_mut().extend(value.to_bytes_with_nul());
24908 self
24909 }
24910 #[doc = "name of the chain containing the rule"]
24911 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
24912 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
24913 self.as_rec_mut().extend(value);
24914 self.as_rec_mut().push(0);
24915 self
24916 }
24917 #[doc = "numeric handle of the rule"]
24918 pub fn push_handle(mut self, value: u64) -> Self {
24919 push_header(self.as_rec_mut(), 3u16, 8 as u16);
24920 self.as_rec_mut().extend(value.to_be_bytes());
24921 self
24922 }
24923 #[doc = "list of expressions"]
24924 pub fn nested_expressions(mut self) -> PushExprListAttrs<Self> {
24925 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
24926 PushExprListAttrs {
24927 prev: Some(self),
24928 header_offset: Some(header_offset),
24929 }
24930 }
24931 #[doc = "numeric handle of the previous rule"]
24932 pub fn push_position(mut self, value: u64) -> Self {
24933 push_header(self.as_rec_mut(), 6u16, 8 as u16);
24934 self.as_rec_mut().extend(value.to_be_bytes());
24935 self
24936 }
24937 #[doc = "user data"]
24938 pub fn push_userdata(mut self, value: &[u8]) -> Self {
24939 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
24940 self.as_rec_mut().extend(value);
24941 self
24942 }
24943}
24944impl<Prev: Rec> Drop for PushOpGetruleDoReply<Prev> {
24945 fn drop(&mut self) {
24946 if let Some(prev) = &mut self.prev {
24947 if let Some(header_offset) = &self.header_offset {
24948 finalize_nested_header(prev.as_rec_mut(), *header_offset);
24949 }
24950 }
24951 }
24952}
24953#[doc = "Get / dump rules."]
24954#[derive(Clone)]
24955pub enum OpGetruleDoReply<'a> {
24956 #[doc = "name of the table containing the rule"]
24957 Table(&'a CStr),
24958 #[doc = "name of the chain containing the rule"]
24959 Chain(&'a CStr),
24960 #[doc = "numeric handle of the rule"]
24961 Handle(u64),
24962 #[doc = "list of expressions"]
24963 Expressions(IterableExprListAttrs<'a>),
24964 #[doc = "numeric handle of the previous rule"]
24965 Position(u64),
24966 #[doc = "user data"]
24967 Userdata(&'a [u8]),
24968}
24969impl<'a> IterableOpGetruleDoReply<'a> {
24970 #[doc = "name of the table containing the rule"]
24971 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
24972 let mut iter = self.clone();
24973 iter.pos = 0;
24974 for attr in iter {
24975 if let OpGetruleDoReply::Table(val) = attr? {
24976 return Ok(val);
24977 }
24978 }
24979 Err(ErrorContext::new_missing(
24980 "OpGetruleDoReply",
24981 "Table",
24982 self.orig_loc,
24983 self.buf.as_ptr() as usize,
24984 ))
24985 }
24986 #[doc = "name of the chain containing the rule"]
24987 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
24988 let mut iter = self.clone();
24989 iter.pos = 0;
24990 for attr in iter {
24991 if let OpGetruleDoReply::Chain(val) = attr? {
24992 return Ok(val);
24993 }
24994 }
24995 Err(ErrorContext::new_missing(
24996 "OpGetruleDoReply",
24997 "Chain",
24998 self.orig_loc,
24999 self.buf.as_ptr() as usize,
25000 ))
25001 }
25002 #[doc = "numeric handle of the rule"]
25003 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
25004 let mut iter = self.clone();
25005 iter.pos = 0;
25006 for attr in iter {
25007 if let OpGetruleDoReply::Handle(val) = attr? {
25008 return Ok(val);
25009 }
25010 }
25011 Err(ErrorContext::new_missing(
25012 "OpGetruleDoReply",
25013 "Handle",
25014 self.orig_loc,
25015 self.buf.as_ptr() as usize,
25016 ))
25017 }
25018 #[doc = "list of expressions"]
25019 pub fn get_expressions(&self) -> Result<IterableExprListAttrs<'a>, ErrorContext> {
25020 let mut iter = self.clone();
25021 iter.pos = 0;
25022 for attr in iter {
25023 if let OpGetruleDoReply::Expressions(val) = attr? {
25024 return Ok(val);
25025 }
25026 }
25027 Err(ErrorContext::new_missing(
25028 "OpGetruleDoReply",
25029 "Expressions",
25030 self.orig_loc,
25031 self.buf.as_ptr() as usize,
25032 ))
25033 }
25034 #[doc = "numeric handle of the previous rule"]
25035 pub fn get_position(&self) -> Result<u64, ErrorContext> {
25036 let mut iter = self.clone();
25037 iter.pos = 0;
25038 for attr in iter {
25039 if let OpGetruleDoReply::Position(val) = attr? {
25040 return Ok(val);
25041 }
25042 }
25043 Err(ErrorContext::new_missing(
25044 "OpGetruleDoReply",
25045 "Position",
25046 self.orig_loc,
25047 self.buf.as_ptr() as usize,
25048 ))
25049 }
25050 #[doc = "user data"]
25051 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
25052 let mut iter = self.clone();
25053 iter.pos = 0;
25054 for attr in iter {
25055 if let OpGetruleDoReply::Userdata(val) = attr? {
25056 return Ok(val);
25057 }
25058 }
25059 Err(ErrorContext::new_missing(
25060 "OpGetruleDoReply",
25061 "Userdata",
25062 self.orig_loc,
25063 self.buf.as_ptr() as usize,
25064 ))
25065 }
25066}
25067impl<'a> OpGetruleDoReply<'a> {
25068 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetruleDoReply<'a>) {
25069 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
25070 (
25071 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
25072 IterableOpGetruleDoReply::with_loc(attrs, buf.as_ptr() as usize),
25073 )
25074 }
25075 fn attr_from_type(r#type: u16) -> Option<&'static str> {
25076 RuleAttrs::attr_from_type(r#type)
25077 }
25078}
25079#[derive(Clone, Copy, Default)]
25080pub struct IterableOpGetruleDoReply<'a> {
25081 buf: &'a [u8],
25082 pos: usize,
25083 orig_loc: usize,
25084}
25085impl<'a> IterableOpGetruleDoReply<'a> {
25086 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
25087 Self {
25088 buf,
25089 pos: 0,
25090 orig_loc,
25091 }
25092 }
25093 pub fn get_buf(&self) -> &'a [u8] {
25094 self.buf
25095 }
25096}
25097impl<'a> Iterator for IterableOpGetruleDoReply<'a> {
25098 type Item = Result<OpGetruleDoReply<'a>, ErrorContext>;
25099 fn next(&mut self) -> Option<Self::Item> {
25100 if self.buf.len() == self.pos {
25101 return None;
25102 }
25103 let pos = self.pos;
25104 let mut r#type = None;
25105 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
25106 r#type = Some(header.r#type);
25107 let res = match header.r#type {
25108 1u16 => OpGetruleDoReply::Table({
25109 let res = CStr::from_bytes_with_nul(next).ok();
25110 let Some(val) = res else { break };
25111 val
25112 }),
25113 2u16 => OpGetruleDoReply::Chain({
25114 let res = CStr::from_bytes_with_nul(next).ok();
25115 let Some(val) = res else { break };
25116 val
25117 }),
25118 3u16 => OpGetruleDoReply::Handle({
25119 let res = parse_be_u64(next);
25120 let Some(val) = res else { break };
25121 val
25122 }),
25123 4u16 => OpGetruleDoReply::Expressions({
25124 let res = Some(IterableExprListAttrs::with_loc(next, self.orig_loc));
25125 let Some(val) = res else { break };
25126 val
25127 }),
25128 6u16 => OpGetruleDoReply::Position({
25129 let res = parse_be_u64(next);
25130 let Some(val) = res else { break };
25131 val
25132 }),
25133 7u16 => OpGetruleDoReply::Userdata({
25134 let res = Some(next);
25135 let Some(val) = res else { break };
25136 val
25137 }),
25138 n => {
25139 if cfg!(any(test, feature = "deny-unknown-attrs")) {
25140 break;
25141 } else {
25142 continue;
25143 }
25144 }
25145 };
25146 return Some(Ok(res));
25147 }
25148 Some(Err(ErrorContext::new(
25149 "OpGetruleDoReply",
25150 r#type.and_then(|t| OpGetruleDoReply::attr_from_type(t)),
25151 self.orig_loc,
25152 self.buf.as_ptr().wrapping_add(pos) as usize,
25153 )))
25154 }
25155}
25156impl<'a> std::fmt::Debug for IterableOpGetruleDoReply<'_> {
25157 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25158 let mut fmt = f.debug_struct("OpGetruleDoReply");
25159 for attr in self.clone() {
25160 let attr = match attr {
25161 Ok(a) => a,
25162 Err(err) => {
25163 fmt.finish()?;
25164 f.write_str("Err(")?;
25165 err.fmt(f)?;
25166 return f.write_str(")");
25167 }
25168 };
25169 match attr {
25170 OpGetruleDoReply::Table(val) => fmt.field("Table", &val),
25171 OpGetruleDoReply::Chain(val) => fmt.field("Chain", &val),
25172 OpGetruleDoReply::Handle(val) => fmt.field("Handle", &val),
25173 OpGetruleDoReply::Expressions(val) => fmt.field("Expressions", &val),
25174 OpGetruleDoReply::Position(val) => fmt.field("Position", &val),
25175 OpGetruleDoReply::Userdata(val) => fmt.field("Userdata", &val),
25176 };
25177 }
25178 fmt.finish()
25179 }
25180}
25181impl IterableOpGetruleDoReply<'_> {
25182 pub fn lookup_attr(
25183 &self,
25184 offset: usize,
25185 missing_type: Option<u16>,
25186 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
25187 let mut stack = Vec::new();
25188 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
25189 if cur == offset + PushNfgenmsg::len() {
25190 stack.push(("OpGetruleDoReply", offset));
25191 return (
25192 stack,
25193 missing_type.and_then(|t| OpGetruleDoReply::attr_from_type(t)),
25194 );
25195 }
25196 if cur > offset || cur + self.buf.len() < offset {
25197 return (stack, None);
25198 }
25199 let mut attrs = self.clone();
25200 let mut last_off = cur + attrs.pos;
25201 let mut missing = None;
25202 while let Some(attr) = attrs.next() {
25203 let Ok(attr) = attr else { break };
25204 match attr {
25205 OpGetruleDoReply::Table(val) => {
25206 if last_off == offset {
25207 stack.push(("Table", last_off));
25208 break;
25209 }
25210 }
25211 OpGetruleDoReply::Chain(val) => {
25212 if last_off == offset {
25213 stack.push(("Chain", last_off));
25214 break;
25215 }
25216 }
25217 OpGetruleDoReply::Handle(val) => {
25218 if last_off == offset {
25219 stack.push(("Handle", last_off));
25220 break;
25221 }
25222 }
25223 OpGetruleDoReply::Expressions(val) => {
25224 (stack, missing) = val.lookup_attr(offset, missing_type);
25225 if !stack.is_empty() {
25226 break;
25227 }
25228 }
25229 OpGetruleDoReply::Position(val) => {
25230 if last_off == offset {
25231 stack.push(("Position", last_off));
25232 break;
25233 }
25234 }
25235 OpGetruleDoReply::Userdata(val) => {
25236 if last_off == offset {
25237 stack.push(("Userdata", last_off));
25238 break;
25239 }
25240 }
25241 _ => {}
25242 };
25243 last_off = cur + attrs.pos;
25244 }
25245 if !stack.is_empty() {
25246 stack.push(("OpGetruleDoReply", cur));
25247 }
25248 (stack, missing)
25249 }
25250}
25251#[derive(Debug)]
25252pub struct RequestOpGetruleDoRequest<'r> {
25253 request: Request<'r>,
25254}
25255impl<'r> RequestOpGetruleDoRequest<'r> {
25256 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
25257 PushOpGetruleDoRequest::write_header(&mut request.buf_mut(), header);
25258 Self { request: request }
25259 }
25260 pub fn encode(&mut self) -> PushOpGetruleDoRequest<&mut Vec<u8>> {
25261 PushOpGetruleDoRequest::new_without_header(self.request.buf_mut())
25262 }
25263 pub fn into_encoder(self) -> PushOpGetruleDoRequest<RequestBuf<'r>> {
25264 PushOpGetruleDoRequest::new_without_header(self.request.buf)
25265 }
25266}
25267impl NetlinkRequest for RequestOpGetruleDoRequest<'_> {
25268 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetruleDoReply<'buf>);
25269 fn protocol(&self) -> Protocol {
25270 Protocol::Raw {
25271 protonum: 12u16,
25272 request_type: 2567u16,
25273 }
25274 }
25275 fn flags(&self) -> u16 {
25276 self.request.flags
25277 }
25278 fn payload(&self) -> &[u8] {
25279 self.request.buf()
25280 }
25281 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
25282 OpGetruleDoReply::new(buf)
25283 }
25284 fn lookup(
25285 buf: &[u8],
25286 offset: usize,
25287 missing_type: Option<u16>,
25288 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
25289 OpGetruleDoRequest::new(buf)
25290 .1
25291 .lookup_attr(offset, missing_type)
25292 }
25293}
25294#[doc = "Get / dump rules and reset stateful expressions."]
25295pub struct PushOpGetruleResetDumpRequest<Prev: Rec> {
25296 pub(crate) prev: Option<Prev>,
25297 pub(crate) header_offset: Option<usize>,
25298}
25299impl<Prev: Rec> Rec for PushOpGetruleResetDumpRequest<Prev> {
25300 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
25301 self.prev.as_mut().unwrap().as_rec_mut()
25302 }
25303}
25304impl<Prev: Rec> PushOpGetruleResetDumpRequest<Prev> {
25305 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
25306 Self::write_header(&mut prev, header);
25307 Self::new_without_header(prev)
25308 }
25309 fn new_without_header(prev: Prev) -> Self {
25310 Self {
25311 prev: Some(prev),
25312 header_offset: None,
25313 }
25314 }
25315 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
25316 prev.as_rec_mut().extend(header.as_slice());
25317 }
25318 pub fn end_nested(mut self) -> Prev {
25319 let mut prev = self.prev.take().unwrap();
25320 if let Some(header_offset) = &self.header_offset {
25321 finalize_nested_header(prev.as_rec_mut(), *header_offset);
25322 }
25323 prev
25324 }
25325 #[doc = "name of the table containing the rule"]
25326 pub fn push_table(mut self, value: &CStr) -> Self {
25327 push_header(
25328 self.as_rec_mut(),
25329 1u16,
25330 value.to_bytes_with_nul().len() as u16,
25331 );
25332 self.as_rec_mut().extend(value.to_bytes_with_nul());
25333 self
25334 }
25335 #[doc = "name of the table containing the rule"]
25336 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
25337 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
25338 self.as_rec_mut().extend(value);
25339 self.as_rec_mut().push(0);
25340 self
25341 }
25342 #[doc = "name of the chain containing the rule"]
25343 pub fn push_chain(mut self, value: &CStr) -> Self {
25344 push_header(
25345 self.as_rec_mut(),
25346 2u16,
25347 value.to_bytes_with_nul().len() as u16,
25348 );
25349 self.as_rec_mut().extend(value.to_bytes_with_nul());
25350 self
25351 }
25352 #[doc = "name of the chain containing the rule"]
25353 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
25354 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
25355 self.as_rec_mut().extend(value);
25356 self.as_rec_mut().push(0);
25357 self
25358 }
25359 #[doc = "numeric handle of the rule"]
25360 pub fn push_handle(mut self, value: u64) -> Self {
25361 push_header(self.as_rec_mut(), 3u16, 8 as u16);
25362 self.as_rec_mut().extend(value.to_be_bytes());
25363 self
25364 }
25365}
25366impl<Prev: Rec> Drop for PushOpGetruleResetDumpRequest<Prev> {
25367 fn drop(&mut self) {
25368 if let Some(prev) = &mut self.prev {
25369 if let Some(header_offset) = &self.header_offset {
25370 finalize_nested_header(prev.as_rec_mut(), *header_offset);
25371 }
25372 }
25373 }
25374}
25375#[doc = "Get / dump rules and reset stateful expressions."]
25376#[derive(Clone)]
25377pub enum OpGetruleResetDumpRequest<'a> {
25378 #[doc = "name of the table containing the rule"]
25379 Table(&'a CStr),
25380 #[doc = "name of the chain containing the rule"]
25381 Chain(&'a CStr),
25382 #[doc = "numeric handle of the rule"]
25383 Handle(u64),
25384}
25385impl<'a> IterableOpGetruleResetDumpRequest<'a> {
25386 #[doc = "name of the table containing the rule"]
25387 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
25388 let mut iter = self.clone();
25389 iter.pos = 0;
25390 for attr in iter {
25391 if let OpGetruleResetDumpRequest::Table(val) = attr? {
25392 return Ok(val);
25393 }
25394 }
25395 Err(ErrorContext::new_missing(
25396 "OpGetruleResetDumpRequest",
25397 "Table",
25398 self.orig_loc,
25399 self.buf.as_ptr() as usize,
25400 ))
25401 }
25402 #[doc = "name of the chain containing the rule"]
25403 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
25404 let mut iter = self.clone();
25405 iter.pos = 0;
25406 for attr in iter {
25407 if let OpGetruleResetDumpRequest::Chain(val) = attr? {
25408 return Ok(val);
25409 }
25410 }
25411 Err(ErrorContext::new_missing(
25412 "OpGetruleResetDumpRequest",
25413 "Chain",
25414 self.orig_loc,
25415 self.buf.as_ptr() as usize,
25416 ))
25417 }
25418 #[doc = "numeric handle of the rule"]
25419 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
25420 let mut iter = self.clone();
25421 iter.pos = 0;
25422 for attr in iter {
25423 if let OpGetruleResetDumpRequest::Handle(val) = attr? {
25424 return Ok(val);
25425 }
25426 }
25427 Err(ErrorContext::new_missing(
25428 "OpGetruleResetDumpRequest",
25429 "Handle",
25430 self.orig_loc,
25431 self.buf.as_ptr() as usize,
25432 ))
25433 }
25434}
25435impl<'a> OpGetruleResetDumpRequest<'a> {
25436 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetruleResetDumpRequest<'a>) {
25437 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
25438 (
25439 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
25440 IterableOpGetruleResetDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
25441 )
25442 }
25443 fn attr_from_type(r#type: u16) -> Option<&'static str> {
25444 RuleAttrs::attr_from_type(r#type)
25445 }
25446}
25447#[derive(Clone, Copy, Default)]
25448pub struct IterableOpGetruleResetDumpRequest<'a> {
25449 buf: &'a [u8],
25450 pos: usize,
25451 orig_loc: usize,
25452}
25453impl<'a> IterableOpGetruleResetDumpRequest<'a> {
25454 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
25455 Self {
25456 buf,
25457 pos: 0,
25458 orig_loc,
25459 }
25460 }
25461 pub fn get_buf(&self) -> &'a [u8] {
25462 self.buf
25463 }
25464}
25465impl<'a> Iterator for IterableOpGetruleResetDumpRequest<'a> {
25466 type Item = Result<OpGetruleResetDumpRequest<'a>, ErrorContext>;
25467 fn next(&mut self) -> Option<Self::Item> {
25468 if self.buf.len() == self.pos {
25469 return None;
25470 }
25471 let pos = self.pos;
25472 let mut r#type = None;
25473 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
25474 r#type = Some(header.r#type);
25475 let res = match header.r#type {
25476 1u16 => OpGetruleResetDumpRequest::Table({
25477 let res = CStr::from_bytes_with_nul(next).ok();
25478 let Some(val) = res else { break };
25479 val
25480 }),
25481 2u16 => OpGetruleResetDumpRequest::Chain({
25482 let res = CStr::from_bytes_with_nul(next).ok();
25483 let Some(val) = res else { break };
25484 val
25485 }),
25486 3u16 => OpGetruleResetDumpRequest::Handle({
25487 let res = parse_be_u64(next);
25488 let Some(val) = res else { break };
25489 val
25490 }),
25491 n => {
25492 if cfg!(any(test, feature = "deny-unknown-attrs")) {
25493 break;
25494 } else {
25495 continue;
25496 }
25497 }
25498 };
25499 return Some(Ok(res));
25500 }
25501 Some(Err(ErrorContext::new(
25502 "OpGetruleResetDumpRequest",
25503 r#type.and_then(|t| OpGetruleResetDumpRequest::attr_from_type(t)),
25504 self.orig_loc,
25505 self.buf.as_ptr().wrapping_add(pos) as usize,
25506 )))
25507 }
25508}
25509impl<'a> std::fmt::Debug for IterableOpGetruleResetDumpRequest<'_> {
25510 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25511 let mut fmt = f.debug_struct("OpGetruleResetDumpRequest");
25512 for attr in self.clone() {
25513 let attr = match attr {
25514 Ok(a) => a,
25515 Err(err) => {
25516 fmt.finish()?;
25517 f.write_str("Err(")?;
25518 err.fmt(f)?;
25519 return f.write_str(")");
25520 }
25521 };
25522 match attr {
25523 OpGetruleResetDumpRequest::Table(val) => fmt.field("Table", &val),
25524 OpGetruleResetDumpRequest::Chain(val) => fmt.field("Chain", &val),
25525 OpGetruleResetDumpRequest::Handle(val) => fmt.field("Handle", &val),
25526 };
25527 }
25528 fmt.finish()
25529 }
25530}
25531impl IterableOpGetruleResetDumpRequest<'_> {
25532 pub fn lookup_attr(
25533 &self,
25534 offset: usize,
25535 missing_type: Option<u16>,
25536 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
25537 let mut stack = Vec::new();
25538 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
25539 if cur == offset + PushNfgenmsg::len() {
25540 stack.push(("OpGetruleResetDumpRequest", offset));
25541 return (
25542 stack,
25543 missing_type.and_then(|t| OpGetruleResetDumpRequest::attr_from_type(t)),
25544 );
25545 }
25546 if cur > offset || cur + self.buf.len() < offset {
25547 return (stack, None);
25548 }
25549 let mut attrs = self.clone();
25550 let mut last_off = cur + attrs.pos;
25551 while let Some(attr) = attrs.next() {
25552 let Ok(attr) = attr else { break };
25553 match attr {
25554 OpGetruleResetDumpRequest::Table(val) => {
25555 if last_off == offset {
25556 stack.push(("Table", last_off));
25557 break;
25558 }
25559 }
25560 OpGetruleResetDumpRequest::Chain(val) => {
25561 if last_off == offset {
25562 stack.push(("Chain", last_off));
25563 break;
25564 }
25565 }
25566 OpGetruleResetDumpRequest::Handle(val) => {
25567 if last_off == offset {
25568 stack.push(("Handle", last_off));
25569 break;
25570 }
25571 }
25572 _ => {}
25573 };
25574 last_off = cur + attrs.pos;
25575 }
25576 if !stack.is_empty() {
25577 stack.push(("OpGetruleResetDumpRequest", cur));
25578 }
25579 (stack, None)
25580 }
25581}
25582#[doc = "Get / dump rules and reset stateful expressions."]
25583pub struct PushOpGetruleResetDumpReply<Prev: Rec> {
25584 pub(crate) prev: Option<Prev>,
25585 pub(crate) header_offset: Option<usize>,
25586}
25587impl<Prev: Rec> Rec for PushOpGetruleResetDumpReply<Prev> {
25588 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
25589 self.prev.as_mut().unwrap().as_rec_mut()
25590 }
25591}
25592impl<Prev: Rec> PushOpGetruleResetDumpReply<Prev> {
25593 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
25594 Self::write_header(&mut prev, header);
25595 Self::new_without_header(prev)
25596 }
25597 fn new_without_header(prev: Prev) -> Self {
25598 Self {
25599 prev: Some(prev),
25600 header_offset: None,
25601 }
25602 }
25603 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
25604 prev.as_rec_mut().extend(header.as_slice());
25605 }
25606 pub fn end_nested(mut self) -> Prev {
25607 let mut prev = self.prev.take().unwrap();
25608 if let Some(header_offset) = &self.header_offset {
25609 finalize_nested_header(prev.as_rec_mut(), *header_offset);
25610 }
25611 prev
25612 }
25613 #[doc = "name of the table containing the rule"]
25614 pub fn push_table(mut self, value: &CStr) -> Self {
25615 push_header(
25616 self.as_rec_mut(),
25617 1u16,
25618 value.to_bytes_with_nul().len() as u16,
25619 );
25620 self.as_rec_mut().extend(value.to_bytes_with_nul());
25621 self
25622 }
25623 #[doc = "name of the table containing the rule"]
25624 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
25625 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
25626 self.as_rec_mut().extend(value);
25627 self.as_rec_mut().push(0);
25628 self
25629 }
25630 #[doc = "name of the chain containing the rule"]
25631 pub fn push_chain(mut self, value: &CStr) -> Self {
25632 push_header(
25633 self.as_rec_mut(),
25634 2u16,
25635 value.to_bytes_with_nul().len() as u16,
25636 );
25637 self.as_rec_mut().extend(value.to_bytes_with_nul());
25638 self
25639 }
25640 #[doc = "name of the chain containing the rule"]
25641 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
25642 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
25643 self.as_rec_mut().extend(value);
25644 self.as_rec_mut().push(0);
25645 self
25646 }
25647 #[doc = "numeric handle of the rule"]
25648 pub fn push_handle(mut self, value: u64) -> Self {
25649 push_header(self.as_rec_mut(), 3u16, 8 as u16);
25650 self.as_rec_mut().extend(value.to_be_bytes());
25651 self
25652 }
25653 #[doc = "list of expressions"]
25654 pub fn nested_expressions(mut self) -> PushExprListAttrs<Self> {
25655 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
25656 PushExprListAttrs {
25657 prev: Some(self),
25658 header_offset: Some(header_offset),
25659 }
25660 }
25661 #[doc = "numeric handle of the previous rule"]
25662 pub fn push_position(mut self, value: u64) -> Self {
25663 push_header(self.as_rec_mut(), 6u16, 8 as u16);
25664 self.as_rec_mut().extend(value.to_be_bytes());
25665 self
25666 }
25667 #[doc = "user data"]
25668 pub fn push_userdata(mut self, value: &[u8]) -> Self {
25669 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
25670 self.as_rec_mut().extend(value);
25671 self
25672 }
25673}
25674impl<Prev: Rec> Drop for PushOpGetruleResetDumpReply<Prev> {
25675 fn drop(&mut self) {
25676 if let Some(prev) = &mut self.prev {
25677 if let Some(header_offset) = &self.header_offset {
25678 finalize_nested_header(prev.as_rec_mut(), *header_offset);
25679 }
25680 }
25681 }
25682}
25683#[doc = "Get / dump rules and reset stateful expressions."]
25684#[derive(Clone)]
25685pub enum OpGetruleResetDumpReply<'a> {
25686 #[doc = "name of the table containing the rule"]
25687 Table(&'a CStr),
25688 #[doc = "name of the chain containing the rule"]
25689 Chain(&'a CStr),
25690 #[doc = "numeric handle of the rule"]
25691 Handle(u64),
25692 #[doc = "list of expressions"]
25693 Expressions(IterableExprListAttrs<'a>),
25694 #[doc = "numeric handle of the previous rule"]
25695 Position(u64),
25696 #[doc = "user data"]
25697 Userdata(&'a [u8]),
25698}
25699impl<'a> IterableOpGetruleResetDumpReply<'a> {
25700 #[doc = "name of the table containing the rule"]
25701 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
25702 let mut iter = self.clone();
25703 iter.pos = 0;
25704 for attr in iter {
25705 if let OpGetruleResetDumpReply::Table(val) = attr? {
25706 return Ok(val);
25707 }
25708 }
25709 Err(ErrorContext::new_missing(
25710 "OpGetruleResetDumpReply",
25711 "Table",
25712 self.orig_loc,
25713 self.buf.as_ptr() as usize,
25714 ))
25715 }
25716 #[doc = "name of the chain containing the rule"]
25717 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
25718 let mut iter = self.clone();
25719 iter.pos = 0;
25720 for attr in iter {
25721 if let OpGetruleResetDumpReply::Chain(val) = attr? {
25722 return Ok(val);
25723 }
25724 }
25725 Err(ErrorContext::new_missing(
25726 "OpGetruleResetDumpReply",
25727 "Chain",
25728 self.orig_loc,
25729 self.buf.as_ptr() as usize,
25730 ))
25731 }
25732 #[doc = "numeric handle of the rule"]
25733 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
25734 let mut iter = self.clone();
25735 iter.pos = 0;
25736 for attr in iter {
25737 if let OpGetruleResetDumpReply::Handle(val) = attr? {
25738 return Ok(val);
25739 }
25740 }
25741 Err(ErrorContext::new_missing(
25742 "OpGetruleResetDumpReply",
25743 "Handle",
25744 self.orig_loc,
25745 self.buf.as_ptr() as usize,
25746 ))
25747 }
25748 #[doc = "list of expressions"]
25749 pub fn get_expressions(&self) -> Result<IterableExprListAttrs<'a>, ErrorContext> {
25750 let mut iter = self.clone();
25751 iter.pos = 0;
25752 for attr in iter {
25753 if let OpGetruleResetDumpReply::Expressions(val) = attr? {
25754 return Ok(val);
25755 }
25756 }
25757 Err(ErrorContext::new_missing(
25758 "OpGetruleResetDumpReply",
25759 "Expressions",
25760 self.orig_loc,
25761 self.buf.as_ptr() as usize,
25762 ))
25763 }
25764 #[doc = "numeric handle of the previous rule"]
25765 pub fn get_position(&self) -> Result<u64, ErrorContext> {
25766 let mut iter = self.clone();
25767 iter.pos = 0;
25768 for attr in iter {
25769 if let OpGetruleResetDumpReply::Position(val) = attr? {
25770 return Ok(val);
25771 }
25772 }
25773 Err(ErrorContext::new_missing(
25774 "OpGetruleResetDumpReply",
25775 "Position",
25776 self.orig_loc,
25777 self.buf.as_ptr() as usize,
25778 ))
25779 }
25780 #[doc = "user data"]
25781 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
25782 let mut iter = self.clone();
25783 iter.pos = 0;
25784 for attr in iter {
25785 if let OpGetruleResetDumpReply::Userdata(val) = attr? {
25786 return Ok(val);
25787 }
25788 }
25789 Err(ErrorContext::new_missing(
25790 "OpGetruleResetDumpReply",
25791 "Userdata",
25792 self.orig_loc,
25793 self.buf.as_ptr() as usize,
25794 ))
25795 }
25796}
25797impl<'a> OpGetruleResetDumpReply<'a> {
25798 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetruleResetDumpReply<'a>) {
25799 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
25800 (
25801 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
25802 IterableOpGetruleResetDumpReply::with_loc(attrs, buf.as_ptr() as usize),
25803 )
25804 }
25805 fn attr_from_type(r#type: u16) -> Option<&'static str> {
25806 RuleAttrs::attr_from_type(r#type)
25807 }
25808}
25809#[derive(Clone, Copy, Default)]
25810pub struct IterableOpGetruleResetDumpReply<'a> {
25811 buf: &'a [u8],
25812 pos: usize,
25813 orig_loc: usize,
25814}
25815impl<'a> IterableOpGetruleResetDumpReply<'a> {
25816 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
25817 Self {
25818 buf,
25819 pos: 0,
25820 orig_loc,
25821 }
25822 }
25823 pub fn get_buf(&self) -> &'a [u8] {
25824 self.buf
25825 }
25826}
25827impl<'a> Iterator for IterableOpGetruleResetDumpReply<'a> {
25828 type Item = Result<OpGetruleResetDumpReply<'a>, ErrorContext>;
25829 fn next(&mut self) -> Option<Self::Item> {
25830 if self.buf.len() == self.pos {
25831 return None;
25832 }
25833 let pos = self.pos;
25834 let mut r#type = None;
25835 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
25836 r#type = Some(header.r#type);
25837 let res = match header.r#type {
25838 1u16 => OpGetruleResetDumpReply::Table({
25839 let res = CStr::from_bytes_with_nul(next).ok();
25840 let Some(val) = res else { break };
25841 val
25842 }),
25843 2u16 => OpGetruleResetDumpReply::Chain({
25844 let res = CStr::from_bytes_with_nul(next).ok();
25845 let Some(val) = res else { break };
25846 val
25847 }),
25848 3u16 => OpGetruleResetDumpReply::Handle({
25849 let res = parse_be_u64(next);
25850 let Some(val) = res else { break };
25851 val
25852 }),
25853 4u16 => OpGetruleResetDumpReply::Expressions({
25854 let res = Some(IterableExprListAttrs::with_loc(next, self.orig_loc));
25855 let Some(val) = res else { break };
25856 val
25857 }),
25858 6u16 => OpGetruleResetDumpReply::Position({
25859 let res = parse_be_u64(next);
25860 let Some(val) = res else { break };
25861 val
25862 }),
25863 7u16 => OpGetruleResetDumpReply::Userdata({
25864 let res = Some(next);
25865 let Some(val) = res else { break };
25866 val
25867 }),
25868 n => {
25869 if cfg!(any(test, feature = "deny-unknown-attrs")) {
25870 break;
25871 } else {
25872 continue;
25873 }
25874 }
25875 };
25876 return Some(Ok(res));
25877 }
25878 Some(Err(ErrorContext::new(
25879 "OpGetruleResetDumpReply",
25880 r#type.and_then(|t| OpGetruleResetDumpReply::attr_from_type(t)),
25881 self.orig_loc,
25882 self.buf.as_ptr().wrapping_add(pos) as usize,
25883 )))
25884 }
25885}
25886impl<'a> std::fmt::Debug for IterableOpGetruleResetDumpReply<'_> {
25887 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25888 let mut fmt = f.debug_struct("OpGetruleResetDumpReply");
25889 for attr in self.clone() {
25890 let attr = match attr {
25891 Ok(a) => a,
25892 Err(err) => {
25893 fmt.finish()?;
25894 f.write_str("Err(")?;
25895 err.fmt(f)?;
25896 return f.write_str(")");
25897 }
25898 };
25899 match attr {
25900 OpGetruleResetDumpReply::Table(val) => fmt.field("Table", &val),
25901 OpGetruleResetDumpReply::Chain(val) => fmt.field("Chain", &val),
25902 OpGetruleResetDumpReply::Handle(val) => fmt.field("Handle", &val),
25903 OpGetruleResetDumpReply::Expressions(val) => fmt.field("Expressions", &val),
25904 OpGetruleResetDumpReply::Position(val) => fmt.field("Position", &val),
25905 OpGetruleResetDumpReply::Userdata(val) => fmt.field("Userdata", &val),
25906 };
25907 }
25908 fmt.finish()
25909 }
25910}
25911impl IterableOpGetruleResetDumpReply<'_> {
25912 pub fn lookup_attr(
25913 &self,
25914 offset: usize,
25915 missing_type: Option<u16>,
25916 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
25917 let mut stack = Vec::new();
25918 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
25919 if cur == offset + PushNfgenmsg::len() {
25920 stack.push(("OpGetruleResetDumpReply", offset));
25921 return (
25922 stack,
25923 missing_type.and_then(|t| OpGetruleResetDumpReply::attr_from_type(t)),
25924 );
25925 }
25926 if cur > offset || cur + self.buf.len() < offset {
25927 return (stack, None);
25928 }
25929 let mut attrs = self.clone();
25930 let mut last_off = cur + attrs.pos;
25931 let mut missing = None;
25932 while let Some(attr) = attrs.next() {
25933 let Ok(attr) = attr else { break };
25934 match attr {
25935 OpGetruleResetDumpReply::Table(val) => {
25936 if last_off == offset {
25937 stack.push(("Table", last_off));
25938 break;
25939 }
25940 }
25941 OpGetruleResetDumpReply::Chain(val) => {
25942 if last_off == offset {
25943 stack.push(("Chain", last_off));
25944 break;
25945 }
25946 }
25947 OpGetruleResetDumpReply::Handle(val) => {
25948 if last_off == offset {
25949 stack.push(("Handle", last_off));
25950 break;
25951 }
25952 }
25953 OpGetruleResetDumpReply::Expressions(val) => {
25954 (stack, missing) = val.lookup_attr(offset, missing_type);
25955 if !stack.is_empty() {
25956 break;
25957 }
25958 }
25959 OpGetruleResetDumpReply::Position(val) => {
25960 if last_off == offset {
25961 stack.push(("Position", last_off));
25962 break;
25963 }
25964 }
25965 OpGetruleResetDumpReply::Userdata(val) => {
25966 if last_off == offset {
25967 stack.push(("Userdata", last_off));
25968 break;
25969 }
25970 }
25971 _ => {}
25972 };
25973 last_off = cur + attrs.pos;
25974 }
25975 if !stack.is_empty() {
25976 stack.push(("OpGetruleResetDumpReply", cur));
25977 }
25978 (stack, missing)
25979 }
25980}
25981#[derive(Debug)]
25982pub struct RequestOpGetruleResetDumpRequest<'r> {
25983 request: Request<'r>,
25984}
25985impl<'r> RequestOpGetruleResetDumpRequest<'r> {
25986 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
25987 PushOpGetruleResetDumpRequest::write_header(&mut request.buf_mut(), header);
25988 Self {
25989 request: request.set_dump(),
25990 }
25991 }
25992 pub fn encode(&mut self) -> PushOpGetruleResetDumpRequest<&mut Vec<u8>> {
25993 PushOpGetruleResetDumpRequest::new_without_header(self.request.buf_mut())
25994 }
25995 pub fn into_encoder(self) -> PushOpGetruleResetDumpRequest<RequestBuf<'r>> {
25996 PushOpGetruleResetDumpRequest::new_without_header(self.request.buf)
25997 }
25998}
25999impl NetlinkRequest for RequestOpGetruleResetDumpRequest<'_> {
26000 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetruleResetDumpReply<'buf>);
26001 fn protocol(&self) -> Protocol {
26002 Protocol::Raw {
26003 protonum: 12u16,
26004 request_type: 2585u16,
26005 }
26006 }
26007 fn flags(&self) -> u16 {
26008 self.request.flags
26009 }
26010 fn payload(&self) -> &[u8] {
26011 self.request.buf()
26012 }
26013 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
26014 OpGetruleResetDumpReply::new(buf)
26015 }
26016 fn lookup(
26017 buf: &[u8],
26018 offset: usize,
26019 missing_type: Option<u16>,
26020 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
26021 OpGetruleResetDumpRequest::new(buf)
26022 .1
26023 .lookup_attr(offset, missing_type)
26024 }
26025}
26026#[doc = "Get / dump rules and reset stateful expressions."]
26027pub struct PushOpGetruleResetDoRequest<Prev: Rec> {
26028 pub(crate) prev: Option<Prev>,
26029 pub(crate) header_offset: Option<usize>,
26030}
26031impl<Prev: Rec> Rec for PushOpGetruleResetDoRequest<Prev> {
26032 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
26033 self.prev.as_mut().unwrap().as_rec_mut()
26034 }
26035}
26036impl<Prev: Rec> PushOpGetruleResetDoRequest<Prev> {
26037 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
26038 Self::write_header(&mut prev, header);
26039 Self::new_without_header(prev)
26040 }
26041 fn new_without_header(prev: Prev) -> Self {
26042 Self {
26043 prev: Some(prev),
26044 header_offset: None,
26045 }
26046 }
26047 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
26048 prev.as_rec_mut().extend(header.as_slice());
26049 }
26050 pub fn end_nested(mut self) -> Prev {
26051 let mut prev = self.prev.take().unwrap();
26052 if let Some(header_offset) = &self.header_offset {
26053 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26054 }
26055 prev
26056 }
26057 #[doc = "name of the table containing the rule"]
26058 pub fn push_table(mut self, value: &CStr) -> Self {
26059 push_header(
26060 self.as_rec_mut(),
26061 1u16,
26062 value.to_bytes_with_nul().len() as u16,
26063 );
26064 self.as_rec_mut().extend(value.to_bytes_with_nul());
26065 self
26066 }
26067 #[doc = "name of the table containing the rule"]
26068 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
26069 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
26070 self.as_rec_mut().extend(value);
26071 self.as_rec_mut().push(0);
26072 self
26073 }
26074 #[doc = "name of the chain containing the rule"]
26075 pub fn push_chain(mut self, value: &CStr) -> Self {
26076 push_header(
26077 self.as_rec_mut(),
26078 2u16,
26079 value.to_bytes_with_nul().len() as u16,
26080 );
26081 self.as_rec_mut().extend(value.to_bytes_with_nul());
26082 self
26083 }
26084 #[doc = "name of the chain containing the rule"]
26085 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
26086 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
26087 self.as_rec_mut().extend(value);
26088 self.as_rec_mut().push(0);
26089 self
26090 }
26091 #[doc = "numeric handle of the rule"]
26092 pub fn push_handle(mut self, value: u64) -> Self {
26093 push_header(self.as_rec_mut(), 3u16, 8 as u16);
26094 self.as_rec_mut().extend(value.to_be_bytes());
26095 self
26096 }
26097}
26098impl<Prev: Rec> Drop for PushOpGetruleResetDoRequest<Prev> {
26099 fn drop(&mut self) {
26100 if let Some(prev) = &mut self.prev {
26101 if let Some(header_offset) = &self.header_offset {
26102 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26103 }
26104 }
26105 }
26106}
26107#[doc = "Get / dump rules and reset stateful expressions."]
26108#[derive(Clone)]
26109pub enum OpGetruleResetDoRequest<'a> {
26110 #[doc = "name of the table containing the rule"]
26111 Table(&'a CStr),
26112 #[doc = "name of the chain containing the rule"]
26113 Chain(&'a CStr),
26114 #[doc = "numeric handle of the rule"]
26115 Handle(u64),
26116}
26117impl<'a> IterableOpGetruleResetDoRequest<'a> {
26118 #[doc = "name of the table containing the rule"]
26119 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
26120 let mut iter = self.clone();
26121 iter.pos = 0;
26122 for attr in iter {
26123 if let OpGetruleResetDoRequest::Table(val) = attr? {
26124 return Ok(val);
26125 }
26126 }
26127 Err(ErrorContext::new_missing(
26128 "OpGetruleResetDoRequest",
26129 "Table",
26130 self.orig_loc,
26131 self.buf.as_ptr() as usize,
26132 ))
26133 }
26134 #[doc = "name of the chain containing the rule"]
26135 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
26136 let mut iter = self.clone();
26137 iter.pos = 0;
26138 for attr in iter {
26139 if let OpGetruleResetDoRequest::Chain(val) = attr? {
26140 return Ok(val);
26141 }
26142 }
26143 Err(ErrorContext::new_missing(
26144 "OpGetruleResetDoRequest",
26145 "Chain",
26146 self.orig_loc,
26147 self.buf.as_ptr() as usize,
26148 ))
26149 }
26150 #[doc = "numeric handle of the rule"]
26151 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
26152 let mut iter = self.clone();
26153 iter.pos = 0;
26154 for attr in iter {
26155 if let OpGetruleResetDoRequest::Handle(val) = attr? {
26156 return Ok(val);
26157 }
26158 }
26159 Err(ErrorContext::new_missing(
26160 "OpGetruleResetDoRequest",
26161 "Handle",
26162 self.orig_loc,
26163 self.buf.as_ptr() as usize,
26164 ))
26165 }
26166}
26167impl<'a> OpGetruleResetDoRequest<'a> {
26168 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetruleResetDoRequest<'a>) {
26169 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
26170 (
26171 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
26172 IterableOpGetruleResetDoRequest::with_loc(attrs, buf.as_ptr() as usize),
26173 )
26174 }
26175 fn attr_from_type(r#type: u16) -> Option<&'static str> {
26176 RuleAttrs::attr_from_type(r#type)
26177 }
26178}
26179#[derive(Clone, Copy, Default)]
26180pub struct IterableOpGetruleResetDoRequest<'a> {
26181 buf: &'a [u8],
26182 pos: usize,
26183 orig_loc: usize,
26184}
26185impl<'a> IterableOpGetruleResetDoRequest<'a> {
26186 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
26187 Self {
26188 buf,
26189 pos: 0,
26190 orig_loc,
26191 }
26192 }
26193 pub fn get_buf(&self) -> &'a [u8] {
26194 self.buf
26195 }
26196}
26197impl<'a> Iterator for IterableOpGetruleResetDoRequest<'a> {
26198 type Item = Result<OpGetruleResetDoRequest<'a>, ErrorContext>;
26199 fn next(&mut self) -> Option<Self::Item> {
26200 if self.buf.len() == self.pos {
26201 return None;
26202 }
26203 let pos = self.pos;
26204 let mut r#type = None;
26205 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
26206 r#type = Some(header.r#type);
26207 let res = match header.r#type {
26208 1u16 => OpGetruleResetDoRequest::Table({
26209 let res = CStr::from_bytes_with_nul(next).ok();
26210 let Some(val) = res else { break };
26211 val
26212 }),
26213 2u16 => OpGetruleResetDoRequest::Chain({
26214 let res = CStr::from_bytes_with_nul(next).ok();
26215 let Some(val) = res else { break };
26216 val
26217 }),
26218 3u16 => OpGetruleResetDoRequest::Handle({
26219 let res = parse_be_u64(next);
26220 let Some(val) = res else { break };
26221 val
26222 }),
26223 n => {
26224 if cfg!(any(test, feature = "deny-unknown-attrs")) {
26225 break;
26226 } else {
26227 continue;
26228 }
26229 }
26230 };
26231 return Some(Ok(res));
26232 }
26233 Some(Err(ErrorContext::new(
26234 "OpGetruleResetDoRequest",
26235 r#type.and_then(|t| OpGetruleResetDoRequest::attr_from_type(t)),
26236 self.orig_loc,
26237 self.buf.as_ptr().wrapping_add(pos) as usize,
26238 )))
26239 }
26240}
26241impl<'a> std::fmt::Debug for IterableOpGetruleResetDoRequest<'_> {
26242 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26243 let mut fmt = f.debug_struct("OpGetruleResetDoRequest");
26244 for attr in self.clone() {
26245 let attr = match attr {
26246 Ok(a) => a,
26247 Err(err) => {
26248 fmt.finish()?;
26249 f.write_str("Err(")?;
26250 err.fmt(f)?;
26251 return f.write_str(")");
26252 }
26253 };
26254 match attr {
26255 OpGetruleResetDoRequest::Table(val) => fmt.field("Table", &val),
26256 OpGetruleResetDoRequest::Chain(val) => fmt.field("Chain", &val),
26257 OpGetruleResetDoRequest::Handle(val) => fmt.field("Handle", &val),
26258 };
26259 }
26260 fmt.finish()
26261 }
26262}
26263impl IterableOpGetruleResetDoRequest<'_> {
26264 pub fn lookup_attr(
26265 &self,
26266 offset: usize,
26267 missing_type: Option<u16>,
26268 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
26269 let mut stack = Vec::new();
26270 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
26271 if cur == offset + PushNfgenmsg::len() {
26272 stack.push(("OpGetruleResetDoRequest", offset));
26273 return (
26274 stack,
26275 missing_type.and_then(|t| OpGetruleResetDoRequest::attr_from_type(t)),
26276 );
26277 }
26278 if cur > offset || cur + self.buf.len() < offset {
26279 return (stack, None);
26280 }
26281 let mut attrs = self.clone();
26282 let mut last_off = cur + attrs.pos;
26283 while let Some(attr) = attrs.next() {
26284 let Ok(attr) = attr else { break };
26285 match attr {
26286 OpGetruleResetDoRequest::Table(val) => {
26287 if last_off == offset {
26288 stack.push(("Table", last_off));
26289 break;
26290 }
26291 }
26292 OpGetruleResetDoRequest::Chain(val) => {
26293 if last_off == offset {
26294 stack.push(("Chain", last_off));
26295 break;
26296 }
26297 }
26298 OpGetruleResetDoRequest::Handle(val) => {
26299 if last_off == offset {
26300 stack.push(("Handle", last_off));
26301 break;
26302 }
26303 }
26304 _ => {}
26305 };
26306 last_off = cur + attrs.pos;
26307 }
26308 if !stack.is_empty() {
26309 stack.push(("OpGetruleResetDoRequest", cur));
26310 }
26311 (stack, None)
26312 }
26313}
26314#[doc = "Get / dump rules and reset stateful expressions."]
26315pub struct PushOpGetruleResetDoReply<Prev: Rec> {
26316 pub(crate) prev: Option<Prev>,
26317 pub(crate) header_offset: Option<usize>,
26318}
26319impl<Prev: Rec> Rec for PushOpGetruleResetDoReply<Prev> {
26320 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
26321 self.prev.as_mut().unwrap().as_rec_mut()
26322 }
26323}
26324impl<Prev: Rec> PushOpGetruleResetDoReply<Prev> {
26325 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
26326 Self::write_header(&mut prev, header);
26327 Self::new_without_header(prev)
26328 }
26329 fn new_without_header(prev: Prev) -> Self {
26330 Self {
26331 prev: Some(prev),
26332 header_offset: None,
26333 }
26334 }
26335 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
26336 prev.as_rec_mut().extend(header.as_slice());
26337 }
26338 pub fn end_nested(mut self) -> Prev {
26339 let mut prev = self.prev.take().unwrap();
26340 if let Some(header_offset) = &self.header_offset {
26341 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26342 }
26343 prev
26344 }
26345 #[doc = "name of the table containing the rule"]
26346 pub fn push_table(mut self, value: &CStr) -> Self {
26347 push_header(
26348 self.as_rec_mut(),
26349 1u16,
26350 value.to_bytes_with_nul().len() as u16,
26351 );
26352 self.as_rec_mut().extend(value.to_bytes_with_nul());
26353 self
26354 }
26355 #[doc = "name of the table containing the rule"]
26356 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
26357 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
26358 self.as_rec_mut().extend(value);
26359 self.as_rec_mut().push(0);
26360 self
26361 }
26362 #[doc = "name of the chain containing the rule"]
26363 pub fn push_chain(mut self, value: &CStr) -> Self {
26364 push_header(
26365 self.as_rec_mut(),
26366 2u16,
26367 value.to_bytes_with_nul().len() as u16,
26368 );
26369 self.as_rec_mut().extend(value.to_bytes_with_nul());
26370 self
26371 }
26372 #[doc = "name of the chain containing the rule"]
26373 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
26374 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
26375 self.as_rec_mut().extend(value);
26376 self.as_rec_mut().push(0);
26377 self
26378 }
26379 #[doc = "numeric handle of the rule"]
26380 pub fn push_handle(mut self, value: u64) -> Self {
26381 push_header(self.as_rec_mut(), 3u16, 8 as u16);
26382 self.as_rec_mut().extend(value.to_be_bytes());
26383 self
26384 }
26385 #[doc = "list of expressions"]
26386 pub fn nested_expressions(mut self) -> PushExprListAttrs<Self> {
26387 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
26388 PushExprListAttrs {
26389 prev: Some(self),
26390 header_offset: Some(header_offset),
26391 }
26392 }
26393 #[doc = "numeric handle of the previous rule"]
26394 pub fn push_position(mut self, value: u64) -> Self {
26395 push_header(self.as_rec_mut(), 6u16, 8 as u16);
26396 self.as_rec_mut().extend(value.to_be_bytes());
26397 self
26398 }
26399 #[doc = "user data"]
26400 pub fn push_userdata(mut self, value: &[u8]) -> Self {
26401 push_header(self.as_rec_mut(), 7u16, value.len() as u16);
26402 self.as_rec_mut().extend(value);
26403 self
26404 }
26405}
26406impl<Prev: Rec> Drop for PushOpGetruleResetDoReply<Prev> {
26407 fn drop(&mut self) {
26408 if let Some(prev) = &mut self.prev {
26409 if let Some(header_offset) = &self.header_offset {
26410 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26411 }
26412 }
26413 }
26414}
26415#[doc = "Get / dump rules and reset stateful expressions."]
26416#[derive(Clone)]
26417pub enum OpGetruleResetDoReply<'a> {
26418 #[doc = "name of the table containing the rule"]
26419 Table(&'a CStr),
26420 #[doc = "name of the chain containing the rule"]
26421 Chain(&'a CStr),
26422 #[doc = "numeric handle of the rule"]
26423 Handle(u64),
26424 #[doc = "list of expressions"]
26425 Expressions(IterableExprListAttrs<'a>),
26426 #[doc = "numeric handle of the previous rule"]
26427 Position(u64),
26428 #[doc = "user data"]
26429 Userdata(&'a [u8]),
26430}
26431impl<'a> IterableOpGetruleResetDoReply<'a> {
26432 #[doc = "name of the table containing the rule"]
26433 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
26434 let mut iter = self.clone();
26435 iter.pos = 0;
26436 for attr in iter {
26437 if let OpGetruleResetDoReply::Table(val) = attr? {
26438 return Ok(val);
26439 }
26440 }
26441 Err(ErrorContext::new_missing(
26442 "OpGetruleResetDoReply",
26443 "Table",
26444 self.orig_loc,
26445 self.buf.as_ptr() as usize,
26446 ))
26447 }
26448 #[doc = "name of the chain containing the rule"]
26449 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
26450 let mut iter = self.clone();
26451 iter.pos = 0;
26452 for attr in iter {
26453 if let OpGetruleResetDoReply::Chain(val) = attr? {
26454 return Ok(val);
26455 }
26456 }
26457 Err(ErrorContext::new_missing(
26458 "OpGetruleResetDoReply",
26459 "Chain",
26460 self.orig_loc,
26461 self.buf.as_ptr() as usize,
26462 ))
26463 }
26464 #[doc = "numeric handle of the rule"]
26465 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
26466 let mut iter = self.clone();
26467 iter.pos = 0;
26468 for attr in iter {
26469 if let OpGetruleResetDoReply::Handle(val) = attr? {
26470 return Ok(val);
26471 }
26472 }
26473 Err(ErrorContext::new_missing(
26474 "OpGetruleResetDoReply",
26475 "Handle",
26476 self.orig_loc,
26477 self.buf.as_ptr() as usize,
26478 ))
26479 }
26480 #[doc = "list of expressions"]
26481 pub fn get_expressions(&self) -> Result<IterableExprListAttrs<'a>, ErrorContext> {
26482 let mut iter = self.clone();
26483 iter.pos = 0;
26484 for attr in iter {
26485 if let OpGetruleResetDoReply::Expressions(val) = attr? {
26486 return Ok(val);
26487 }
26488 }
26489 Err(ErrorContext::new_missing(
26490 "OpGetruleResetDoReply",
26491 "Expressions",
26492 self.orig_loc,
26493 self.buf.as_ptr() as usize,
26494 ))
26495 }
26496 #[doc = "numeric handle of the previous rule"]
26497 pub fn get_position(&self) -> Result<u64, ErrorContext> {
26498 let mut iter = self.clone();
26499 iter.pos = 0;
26500 for attr in iter {
26501 if let OpGetruleResetDoReply::Position(val) = attr? {
26502 return Ok(val);
26503 }
26504 }
26505 Err(ErrorContext::new_missing(
26506 "OpGetruleResetDoReply",
26507 "Position",
26508 self.orig_loc,
26509 self.buf.as_ptr() as usize,
26510 ))
26511 }
26512 #[doc = "user data"]
26513 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
26514 let mut iter = self.clone();
26515 iter.pos = 0;
26516 for attr in iter {
26517 if let OpGetruleResetDoReply::Userdata(val) = attr? {
26518 return Ok(val);
26519 }
26520 }
26521 Err(ErrorContext::new_missing(
26522 "OpGetruleResetDoReply",
26523 "Userdata",
26524 self.orig_loc,
26525 self.buf.as_ptr() as usize,
26526 ))
26527 }
26528}
26529impl<'a> OpGetruleResetDoReply<'a> {
26530 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetruleResetDoReply<'a>) {
26531 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
26532 (
26533 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
26534 IterableOpGetruleResetDoReply::with_loc(attrs, buf.as_ptr() as usize),
26535 )
26536 }
26537 fn attr_from_type(r#type: u16) -> Option<&'static str> {
26538 RuleAttrs::attr_from_type(r#type)
26539 }
26540}
26541#[derive(Clone, Copy, Default)]
26542pub struct IterableOpGetruleResetDoReply<'a> {
26543 buf: &'a [u8],
26544 pos: usize,
26545 orig_loc: usize,
26546}
26547impl<'a> IterableOpGetruleResetDoReply<'a> {
26548 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
26549 Self {
26550 buf,
26551 pos: 0,
26552 orig_loc,
26553 }
26554 }
26555 pub fn get_buf(&self) -> &'a [u8] {
26556 self.buf
26557 }
26558}
26559impl<'a> Iterator for IterableOpGetruleResetDoReply<'a> {
26560 type Item = Result<OpGetruleResetDoReply<'a>, ErrorContext>;
26561 fn next(&mut self) -> Option<Self::Item> {
26562 if self.buf.len() == self.pos {
26563 return None;
26564 }
26565 let pos = self.pos;
26566 let mut r#type = None;
26567 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
26568 r#type = Some(header.r#type);
26569 let res = match header.r#type {
26570 1u16 => OpGetruleResetDoReply::Table({
26571 let res = CStr::from_bytes_with_nul(next).ok();
26572 let Some(val) = res else { break };
26573 val
26574 }),
26575 2u16 => OpGetruleResetDoReply::Chain({
26576 let res = CStr::from_bytes_with_nul(next).ok();
26577 let Some(val) = res else { break };
26578 val
26579 }),
26580 3u16 => OpGetruleResetDoReply::Handle({
26581 let res = parse_be_u64(next);
26582 let Some(val) = res else { break };
26583 val
26584 }),
26585 4u16 => OpGetruleResetDoReply::Expressions({
26586 let res = Some(IterableExprListAttrs::with_loc(next, self.orig_loc));
26587 let Some(val) = res else { break };
26588 val
26589 }),
26590 6u16 => OpGetruleResetDoReply::Position({
26591 let res = parse_be_u64(next);
26592 let Some(val) = res else { break };
26593 val
26594 }),
26595 7u16 => OpGetruleResetDoReply::Userdata({
26596 let res = Some(next);
26597 let Some(val) = res else { break };
26598 val
26599 }),
26600 n => {
26601 if cfg!(any(test, feature = "deny-unknown-attrs")) {
26602 break;
26603 } else {
26604 continue;
26605 }
26606 }
26607 };
26608 return Some(Ok(res));
26609 }
26610 Some(Err(ErrorContext::new(
26611 "OpGetruleResetDoReply",
26612 r#type.and_then(|t| OpGetruleResetDoReply::attr_from_type(t)),
26613 self.orig_loc,
26614 self.buf.as_ptr().wrapping_add(pos) as usize,
26615 )))
26616 }
26617}
26618impl<'a> std::fmt::Debug for IterableOpGetruleResetDoReply<'_> {
26619 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26620 let mut fmt = f.debug_struct("OpGetruleResetDoReply");
26621 for attr in self.clone() {
26622 let attr = match attr {
26623 Ok(a) => a,
26624 Err(err) => {
26625 fmt.finish()?;
26626 f.write_str("Err(")?;
26627 err.fmt(f)?;
26628 return f.write_str(")");
26629 }
26630 };
26631 match attr {
26632 OpGetruleResetDoReply::Table(val) => fmt.field("Table", &val),
26633 OpGetruleResetDoReply::Chain(val) => fmt.field("Chain", &val),
26634 OpGetruleResetDoReply::Handle(val) => fmt.field("Handle", &val),
26635 OpGetruleResetDoReply::Expressions(val) => fmt.field("Expressions", &val),
26636 OpGetruleResetDoReply::Position(val) => fmt.field("Position", &val),
26637 OpGetruleResetDoReply::Userdata(val) => fmt.field("Userdata", &val),
26638 };
26639 }
26640 fmt.finish()
26641 }
26642}
26643impl IterableOpGetruleResetDoReply<'_> {
26644 pub fn lookup_attr(
26645 &self,
26646 offset: usize,
26647 missing_type: Option<u16>,
26648 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
26649 let mut stack = Vec::new();
26650 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
26651 if cur == offset + PushNfgenmsg::len() {
26652 stack.push(("OpGetruleResetDoReply", offset));
26653 return (
26654 stack,
26655 missing_type.and_then(|t| OpGetruleResetDoReply::attr_from_type(t)),
26656 );
26657 }
26658 if cur > offset || cur + self.buf.len() < offset {
26659 return (stack, None);
26660 }
26661 let mut attrs = self.clone();
26662 let mut last_off = cur + attrs.pos;
26663 let mut missing = None;
26664 while let Some(attr) = attrs.next() {
26665 let Ok(attr) = attr else { break };
26666 match attr {
26667 OpGetruleResetDoReply::Table(val) => {
26668 if last_off == offset {
26669 stack.push(("Table", last_off));
26670 break;
26671 }
26672 }
26673 OpGetruleResetDoReply::Chain(val) => {
26674 if last_off == offset {
26675 stack.push(("Chain", last_off));
26676 break;
26677 }
26678 }
26679 OpGetruleResetDoReply::Handle(val) => {
26680 if last_off == offset {
26681 stack.push(("Handle", last_off));
26682 break;
26683 }
26684 }
26685 OpGetruleResetDoReply::Expressions(val) => {
26686 (stack, missing) = val.lookup_attr(offset, missing_type);
26687 if !stack.is_empty() {
26688 break;
26689 }
26690 }
26691 OpGetruleResetDoReply::Position(val) => {
26692 if last_off == offset {
26693 stack.push(("Position", last_off));
26694 break;
26695 }
26696 }
26697 OpGetruleResetDoReply::Userdata(val) => {
26698 if last_off == offset {
26699 stack.push(("Userdata", last_off));
26700 break;
26701 }
26702 }
26703 _ => {}
26704 };
26705 last_off = cur + attrs.pos;
26706 }
26707 if !stack.is_empty() {
26708 stack.push(("OpGetruleResetDoReply", cur));
26709 }
26710 (stack, missing)
26711 }
26712}
26713#[derive(Debug)]
26714pub struct RequestOpGetruleResetDoRequest<'r> {
26715 request: Request<'r>,
26716}
26717impl<'r> RequestOpGetruleResetDoRequest<'r> {
26718 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
26719 PushOpGetruleResetDoRequest::write_header(&mut request.buf_mut(), header);
26720 Self { request: request }
26721 }
26722 pub fn encode(&mut self) -> PushOpGetruleResetDoRequest<&mut Vec<u8>> {
26723 PushOpGetruleResetDoRequest::new_without_header(self.request.buf_mut())
26724 }
26725 pub fn into_encoder(self) -> PushOpGetruleResetDoRequest<RequestBuf<'r>> {
26726 PushOpGetruleResetDoRequest::new_without_header(self.request.buf)
26727 }
26728}
26729impl NetlinkRequest for RequestOpGetruleResetDoRequest<'_> {
26730 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetruleResetDoReply<'buf>);
26731 fn protocol(&self) -> Protocol {
26732 Protocol::Raw {
26733 protonum: 12u16,
26734 request_type: 2585u16,
26735 }
26736 }
26737 fn flags(&self) -> u16 {
26738 self.request.flags
26739 }
26740 fn payload(&self) -> &[u8] {
26741 self.request.buf()
26742 }
26743 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
26744 OpGetruleResetDoReply::new(buf)
26745 }
26746 fn lookup(
26747 buf: &[u8],
26748 offset: usize,
26749 missing_type: Option<u16>,
26750 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
26751 OpGetruleResetDoRequest::new(buf)
26752 .1
26753 .lookup_attr(offset, missing_type)
26754 }
26755}
26756#[doc = "Delete an existing rule."]
26757pub struct PushOpDelruleDoRequest<Prev: Rec> {
26758 pub(crate) prev: Option<Prev>,
26759 pub(crate) header_offset: Option<usize>,
26760}
26761impl<Prev: Rec> Rec for PushOpDelruleDoRequest<Prev> {
26762 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
26763 self.prev.as_mut().unwrap().as_rec_mut()
26764 }
26765}
26766impl<Prev: Rec> PushOpDelruleDoRequest<Prev> {
26767 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
26768 Self::write_header(&mut prev, header);
26769 Self::new_without_header(prev)
26770 }
26771 fn new_without_header(prev: Prev) -> Self {
26772 Self {
26773 prev: Some(prev),
26774 header_offset: None,
26775 }
26776 }
26777 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
26778 prev.as_rec_mut().extend(header.as_slice());
26779 }
26780 pub fn end_nested(mut self) -> Prev {
26781 let mut prev = self.prev.take().unwrap();
26782 if let Some(header_offset) = &self.header_offset {
26783 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26784 }
26785 prev
26786 }
26787 #[doc = "name of the table containing the rule"]
26788 pub fn push_table(mut self, value: &CStr) -> Self {
26789 push_header(
26790 self.as_rec_mut(),
26791 1u16,
26792 value.to_bytes_with_nul().len() as u16,
26793 );
26794 self.as_rec_mut().extend(value.to_bytes_with_nul());
26795 self
26796 }
26797 #[doc = "name of the table containing the rule"]
26798 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
26799 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
26800 self.as_rec_mut().extend(value);
26801 self.as_rec_mut().push(0);
26802 self
26803 }
26804 #[doc = "name of the chain containing the rule"]
26805 pub fn push_chain(mut self, value: &CStr) -> Self {
26806 push_header(
26807 self.as_rec_mut(),
26808 2u16,
26809 value.to_bytes_with_nul().len() as u16,
26810 );
26811 self.as_rec_mut().extend(value.to_bytes_with_nul());
26812 self
26813 }
26814 #[doc = "name of the chain containing the rule"]
26815 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
26816 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
26817 self.as_rec_mut().extend(value);
26818 self.as_rec_mut().push(0);
26819 self
26820 }
26821 #[doc = "numeric handle of the rule"]
26822 pub fn push_handle(mut self, value: u64) -> Self {
26823 push_header(self.as_rec_mut(), 3u16, 8 as u16);
26824 self.as_rec_mut().extend(value.to_be_bytes());
26825 self
26826 }
26827 #[doc = "list of expressions"]
26828 pub fn nested_expressions(mut self) -> PushExprListAttrs<Self> {
26829 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
26830 PushExprListAttrs {
26831 prev: Some(self),
26832 header_offset: Some(header_offset),
26833 }
26834 }
26835 #[doc = "uniquely identifies a rule in a transaction"]
26836 pub fn push_id(mut self, value: u32) -> Self {
26837 push_header(self.as_rec_mut(), 8u16, 4 as u16);
26838 self.as_rec_mut().extend(value.to_ne_bytes());
26839 self
26840 }
26841}
26842impl<Prev: Rec> Drop for PushOpDelruleDoRequest<Prev> {
26843 fn drop(&mut self) {
26844 if let Some(prev) = &mut self.prev {
26845 if let Some(header_offset) = &self.header_offset {
26846 finalize_nested_header(prev.as_rec_mut(), *header_offset);
26847 }
26848 }
26849 }
26850}
26851#[doc = "Delete an existing rule."]
26852#[derive(Clone)]
26853pub enum OpDelruleDoRequest<'a> {
26854 #[doc = "name of the table containing the rule"]
26855 Table(&'a CStr),
26856 #[doc = "name of the chain containing the rule"]
26857 Chain(&'a CStr),
26858 #[doc = "numeric handle of the rule"]
26859 Handle(u64),
26860 #[doc = "list of expressions"]
26861 Expressions(IterableExprListAttrs<'a>),
26862 #[doc = "uniquely identifies a rule in a transaction"]
26863 Id(u32),
26864}
26865impl<'a> IterableOpDelruleDoRequest<'a> {
26866 #[doc = "name of the table containing the rule"]
26867 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
26868 let mut iter = self.clone();
26869 iter.pos = 0;
26870 for attr in iter {
26871 if let OpDelruleDoRequest::Table(val) = attr? {
26872 return Ok(val);
26873 }
26874 }
26875 Err(ErrorContext::new_missing(
26876 "OpDelruleDoRequest",
26877 "Table",
26878 self.orig_loc,
26879 self.buf.as_ptr() as usize,
26880 ))
26881 }
26882 #[doc = "name of the chain containing the rule"]
26883 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
26884 let mut iter = self.clone();
26885 iter.pos = 0;
26886 for attr in iter {
26887 if let OpDelruleDoRequest::Chain(val) = attr? {
26888 return Ok(val);
26889 }
26890 }
26891 Err(ErrorContext::new_missing(
26892 "OpDelruleDoRequest",
26893 "Chain",
26894 self.orig_loc,
26895 self.buf.as_ptr() as usize,
26896 ))
26897 }
26898 #[doc = "numeric handle of the rule"]
26899 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
26900 let mut iter = self.clone();
26901 iter.pos = 0;
26902 for attr in iter {
26903 if let OpDelruleDoRequest::Handle(val) = attr? {
26904 return Ok(val);
26905 }
26906 }
26907 Err(ErrorContext::new_missing(
26908 "OpDelruleDoRequest",
26909 "Handle",
26910 self.orig_loc,
26911 self.buf.as_ptr() as usize,
26912 ))
26913 }
26914 #[doc = "list of expressions"]
26915 pub fn get_expressions(&self) -> Result<IterableExprListAttrs<'a>, ErrorContext> {
26916 let mut iter = self.clone();
26917 iter.pos = 0;
26918 for attr in iter {
26919 if let OpDelruleDoRequest::Expressions(val) = attr? {
26920 return Ok(val);
26921 }
26922 }
26923 Err(ErrorContext::new_missing(
26924 "OpDelruleDoRequest",
26925 "Expressions",
26926 self.orig_loc,
26927 self.buf.as_ptr() as usize,
26928 ))
26929 }
26930 #[doc = "uniquely identifies a rule in a transaction"]
26931 pub fn get_id(&self) -> Result<u32, ErrorContext> {
26932 let mut iter = self.clone();
26933 iter.pos = 0;
26934 for attr in iter {
26935 if let OpDelruleDoRequest::Id(val) = attr? {
26936 return Ok(val);
26937 }
26938 }
26939 Err(ErrorContext::new_missing(
26940 "OpDelruleDoRequest",
26941 "Id",
26942 self.orig_loc,
26943 self.buf.as_ptr() as usize,
26944 ))
26945 }
26946}
26947impl<'a> OpDelruleDoRequest<'a> {
26948 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDelruleDoRequest<'a>) {
26949 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
26950 (
26951 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
26952 IterableOpDelruleDoRequest::with_loc(attrs, buf.as_ptr() as usize),
26953 )
26954 }
26955 fn attr_from_type(r#type: u16) -> Option<&'static str> {
26956 RuleAttrs::attr_from_type(r#type)
26957 }
26958}
26959#[derive(Clone, Copy, Default)]
26960pub struct IterableOpDelruleDoRequest<'a> {
26961 buf: &'a [u8],
26962 pos: usize,
26963 orig_loc: usize,
26964}
26965impl<'a> IterableOpDelruleDoRequest<'a> {
26966 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
26967 Self {
26968 buf,
26969 pos: 0,
26970 orig_loc,
26971 }
26972 }
26973 pub fn get_buf(&self) -> &'a [u8] {
26974 self.buf
26975 }
26976}
26977impl<'a> Iterator for IterableOpDelruleDoRequest<'a> {
26978 type Item = Result<OpDelruleDoRequest<'a>, ErrorContext>;
26979 fn next(&mut self) -> Option<Self::Item> {
26980 if self.buf.len() == self.pos {
26981 return None;
26982 }
26983 let pos = self.pos;
26984 let mut r#type = None;
26985 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
26986 r#type = Some(header.r#type);
26987 let res = match header.r#type {
26988 1u16 => OpDelruleDoRequest::Table({
26989 let res = CStr::from_bytes_with_nul(next).ok();
26990 let Some(val) = res else { break };
26991 val
26992 }),
26993 2u16 => OpDelruleDoRequest::Chain({
26994 let res = CStr::from_bytes_with_nul(next).ok();
26995 let Some(val) = res else { break };
26996 val
26997 }),
26998 3u16 => OpDelruleDoRequest::Handle({
26999 let res = parse_be_u64(next);
27000 let Some(val) = res else { break };
27001 val
27002 }),
27003 4u16 => OpDelruleDoRequest::Expressions({
27004 let res = Some(IterableExprListAttrs::with_loc(next, self.orig_loc));
27005 let Some(val) = res else { break };
27006 val
27007 }),
27008 8u16 => OpDelruleDoRequest::Id({
27009 let res = parse_u32(next);
27010 let Some(val) = res else { break };
27011 val
27012 }),
27013 n => {
27014 if cfg!(any(test, feature = "deny-unknown-attrs")) {
27015 break;
27016 } else {
27017 continue;
27018 }
27019 }
27020 };
27021 return Some(Ok(res));
27022 }
27023 Some(Err(ErrorContext::new(
27024 "OpDelruleDoRequest",
27025 r#type.and_then(|t| OpDelruleDoRequest::attr_from_type(t)),
27026 self.orig_loc,
27027 self.buf.as_ptr().wrapping_add(pos) as usize,
27028 )))
27029 }
27030}
27031impl<'a> std::fmt::Debug for IterableOpDelruleDoRequest<'_> {
27032 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27033 let mut fmt = f.debug_struct("OpDelruleDoRequest");
27034 for attr in self.clone() {
27035 let attr = match attr {
27036 Ok(a) => a,
27037 Err(err) => {
27038 fmt.finish()?;
27039 f.write_str("Err(")?;
27040 err.fmt(f)?;
27041 return f.write_str(")");
27042 }
27043 };
27044 match attr {
27045 OpDelruleDoRequest::Table(val) => fmt.field("Table", &val),
27046 OpDelruleDoRequest::Chain(val) => fmt.field("Chain", &val),
27047 OpDelruleDoRequest::Handle(val) => fmt.field("Handle", &val),
27048 OpDelruleDoRequest::Expressions(val) => fmt.field("Expressions", &val),
27049 OpDelruleDoRequest::Id(val) => fmt.field("Id", &val),
27050 };
27051 }
27052 fmt.finish()
27053 }
27054}
27055impl IterableOpDelruleDoRequest<'_> {
27056 pub fn lookup_attr(
27057 &self,
27058 offset: usize,
27059 missing_type: Option<u16>,
27060 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27061 let mut stack = Vec::new();
27062 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
27063 if cur == offset + PushNfgenmsg::len() {
27064 stack.push(("OpDelruleDoRequest", offset));
27065 return (
27066 stack,
27067 missing_type.and_then(|t| OpDelruleDoRequest::attr_from_type(t)),
27068 );
27069 }
27070 if cur > offset || cur + self.buf.len() < offset {
27071 return (stack, None);
27072 }
27073 let mut attrs = self.clone();
27074 let mut last_off = cur + attrs.pos;
27075 let mut missing = None;
27076 while let Some(attr) = attrs.next() {
27077 let Ok(attr) = attr else { break };
27078 match attr {
27079 OpDelruleDoRequest::Table(val) => {
27080 if last_off == offset {
27081 stack.push(("Table", last_off));
27082 break;
27083 }
27084 }
27085 OpDelruleDoRequest::Chain(val) => {
27086 if last_off == offset {
27087 stack.push(("Chain", last_off));
27088 break;
27089 }
27090 }
27091 OpDelruleDoRequest::Handle(val) => {
27092 if last_off == offset {
27093 stack.push(("Handle", last_off));
27094 break;
27095 }
27096 }
27097 OpDelruleDoRequest::Expressions(val) => {
27098 (stack, missing) = val.lookup_attr(offset, missing_type);
27099 if !stack.is_empty() {
27100 break;
27101 }
27102 }
27103 OpDelruleDoRequest::Id(val) => {
27104 if last_off == offset {
27105 stack.push(("Id", last_off));
27106 break;
27107 }
27108 }
27109 _ => {}
27110 };
27111 last_off = cur + attrs.pos;
27112 }
27113 if !stack.is_empty() {
27114 stack.push(("OpDelruleDoRequest", cur));
27115 }
27116 (stack, missing)
27117 }
27118}
27119#[doc = "Delete an existing rule."]
27120pub struct PushOpDelruleDoReply<Prev: Rec> {
27121 pub(crate) prev: Option<Prev>,
27122 pub(crate) header_offset: Option<usize>,
27123}
27124impl<Prev: Rec> Rec for PushOpDelruleDoReply<Prev> {
27125 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
27126 self.prev.as_mut().unwrap().as_rec_mut()
27127 }
27128}
27129impl<Prev: Rec> PushOpDelruleDoReply<Prev> {
27130 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
27131 Self::write_header(&mut prev, header);
27132 Self::new_without_header(prev)
27133 }
27134 fn new_without_header(prev: Prev) -> Self {
27135 Self {
27136 prev: Some(prev),
27137 header_offset: None,
27138 }
27139 }
27140 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
27141 prev.as_rec_mut().extend(header.as_slice());
27142 }
27143 pub fn end_nested(mut self) -> Prev {
27144 let mut prev = self.prev.take().unwrap();
27145 if let Some(header_offset) = &self.header_offset {
27146 finalize_nested_header(prev.as_rec_mut(), *header_offset);
27147 }
27148 prev
27149 }
27150}
27151impl<Prev: Rec> Drop for PushOpDelruleDoReply<Prev> {
27152 fn drop(&mut self) {
27153 if let Some(prev) = &mut self.prev {
27154 if let Some(header_offset) = &self.header_offset {
27155 finalize_nested_header(prev.as_rec_mut(), *header_offset);
27156 }
27157 }
27158 }
27159}
27160#[doc = "Delete an existing rule."]
27161#[derive(Clone)]
27162pub enum OpDelruleDoReply {}
27163impl<'a> IterableOpDelruleDoReply<'a> {}
27164impl OpDelruleDoReply {
27165 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDelruleDoReply<'_>) {
27166 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
27167 (
27168 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
27169 IterableOpDelruleDoReply::with_loc(attrs, buf.as_ptr() as usize),
27170 )
27171 }
27172 fn attr_from_type(r#type: u16) -> Option<&'static str> {
27173 RuleAttrs::attr_from_type(r#type)
27174 }
27175}
27176#[derive(Clone, Copy, Default)]
27177pub struct IterableOpDelruleDoReply<'a> {
27178 buf: &'a [u8],
27179 pos: usize,
27180 orig_loc: usize,
27181}
27182impl<'a> IterableOpDelruleDoReply<'a> {
27183 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
27184 Self {
27185 buf,
27186 pos: 0,
27187 orig_loc,
27188 }
27189 }
27190 pub fn get_buf(&self) -> &'a [u8] {
27191 self.buf
27192 }
27193}
27194impl<'a> Iterator for IterableOpDelruleDoReply<'a> {
27195 type Item = Result<OpDelruleDoReply, ErrorContext>;
27196 fn next(&mut self) -> Option<Self::Item> {
27197 if self.buf.len() == self.pos {
27198 return None;
27199 }
27200 let pos = self.pos;
27201 let mut r#type = None;
27202 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
27203 r#type = Some(header.r#type);
27204 let res = match header.r#type {
27205 n => {
27206 if cfg!(any(test, feature = "deny-unknown-attrs")) {
27207 break;
27208 } else {
27209 continue;
27210 }
27211 }
27212 };
27213 return Some(Ok(res));
27214 }
27215 Some(Err(ErrorContext::new(
27216 "OpDelruleDoReply",
27217 r#type.and_then(|t| OpDelruleDoReply::attr_from_type(t)),
27218 self.orig_loc,
27219 self.buf.as_ptr().wrapping_add(pos) as usize,
27220 )))
27221 }
27222}
27223impl std::fmt::Debug for IterableOpDelruleDoReply<'_> {
27224 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27225 let mut fmt = f.debug_struct("OpDelruleDoReply");
27226 for attr in self.clone() {
27227 let attr = match attr {
27228 Ok(a) => a,
27229 Err(err) => {
27230 fmt.finish()?;
27231 f.write_str("Err(")?;
27232 err.fmt(f)?;
27233 return f.write_str(")");
27234 }
27235 };
27236 match attr {};
27237 }
27238 fmt.finish()
27239 }
27240}
27241impl IterableOpDelruleDoReply<'_> {
27242 pub fn lookup_attr(
27243 &self,
27244 offset: usize,
27245 missing_type: Option<u16>,
27246 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27247 let mut stack = Vec::new();
27248 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
27249 if cur == offset + PushNfgenmsg::len() {
27250 stack.push(("OpDelruleDoReply", offset));
27251 return (
27252 stack,
27253 missing_type.and_then(|t| OpDelruleDoReply::attr_from_type(t)),
27254 );
27255 }
27256 (stack, None)
27257 }
27258}
27259#[derive(Debug)]
27260pub struct RequestOpDelruleDoRequest<'r> {
27261 request: Request<'r>,
27262}
27263impl<'r> RequestOpDelruleDoRequest<'r> {
27264 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
27265 PushOpDelruleDoRequest::write_header(&mut request.buf_mut(), header);
27266 Self { request: request }
27267 }
27268 pub fn encode(&mut self) -> PushOpDelruleDoRequest<&mut Vec<u8>> {
27269 PushOpDelruleDoRequest::new_without_header(self.request.buf_mut())
27270 }
27271 pub fn into_encoder(self) -> PushOpDelruleDoRequest<RequestBuf<'r>> {
27272 PushOpDelruleDoRequest::new_without_header(self.request.buf)
27273 }
27274}
27275impl NetlinkRequest for RequestOpDelruleDoRequest<'_> {
27276 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDelruleDoReply<'buf>);
27277 fn protocol(&self) -> Protocol {
27278 Protocol::Raw {
27279 protonum: 12u16,
27280 request_type: 2568u16,
27281 }
27282 }
27283 fn flags(&self) -> u16 {
27284 self.request.flags
27285 }
27286 fn payload(&self) -> &[u8] {
27287 self.request.buf()
27288 }
27289 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
27290 OpDelruleDoReply::new(buf)
27291 }
27292 fn lookup(
27293 buf: &[u8],
27294 offset: usize,
27295 missing_type: Option<u16>,
27296 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27297 OpDelruleDoRequest::new(buf)
27298 .1
27299 .lookup_attr(offset, missing_type)
27300 }
27301}
27302#[doc = "Delete an existing rule with destroy semantics (ignoring ENOENT errors).\n"]
27303pub struct PushOpDestroyruleDoRequest<Prev: Rec> {
27304 pub(crate) prev: Option<Prev>,
27305 pub(crate) header_offset: Option<usize>,
27306}
27307impl<Prev: Rec> Rec for PushOpDestroyruleDoRequest<Prev> {
27308 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
27309 self.prev.as_mut().unwrap().as_rec_mut()
27310 }
27311}
27312impl<Prev: Rec> PushOpDestroyruleDoRequest<Prev> {
27313 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
27314 Self::write_header(&mut prev, header);
27315 Self::new_without_header(prev)
27316 }
27317 fn new_without_header(prev: Prev) -> Self {
27318 Self {
27319 prev: Some(prev),
27320 header_offset: None,
27321 }
27322 }
27323 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
27324 prev.as_rec_mut().extend(header.as_slice());
27325 }
27326 pub fn end_nested(mut self) -> Prev {
27327 let mut prev = self.prev.take().unwrap();
27328 if let Some(header_offset) = &self.header_offset {
27329 finalize_nested_header(prev.as_rec_mut(), *header_offset);
27330 }
27331 prev
27332 }
27333 #[doc = "name of the table containing the rule"]
27334 pub fn push_table(mut self, value: &CStr) -> Self {
27335 push_header(
27336 self.as_rec_mut(),
27337 1u16,
27338 value.to_bytes_with_nul().len() as u16,
27339 );
27340 self.as_rec_mut().extend(value.to_bytes_with_nul());
27341 self
27342 }
27343 #[doc = "name of the table containing the rule"]
27344 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
27345 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
27346 self.as_rec_mut().extend(value);
27347 self.as_rec_mut().push(0);
27348 self
27349 }
27350 #[doc = "name of the chain containing the rule"]
27351 pub fn push_chain(mut self, value: &CStr) -> Self {
27352 push_header(
27353 self.as_rec_mut(),
27354 2u16,
27355 value.to_bytes_with_nul().len() as u16,
27356 );
27357 self.as_rec_mut().extend(value.to_bytes_with_nul());
27358 self
27359 }
27360 #[doc = "name of the chain containing the rule"]
27361 pub fn push_chain_bytes(mut self, value: &[u8]) -> Self {
27362 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
27363 self.as_rec_mut().extend(value);
27364 self.as_rec_mut().push(0);
27365 self
27366 }
27367 #[doc = "numeric handle of the rule"]
27368 pub fn push_handle(mut self, value: u64) -> Self {
27369 push_header(self.as_rec_mut(), 3u16, 8 as u16);
27370 self.as_rec_mut().extend(value.to_be_bytes());
27371 self
27372 }
27373 #[doc = "list of expressions"]
27374 pub fn nested_expressions(mut self) -> PushExprListAttrs<Self> {
27375 let header_offset = push_nested_header(self.as_rec_mut(), 4u16);
27376 PushExprListAttrs {
27377 prev: Some(self),
27378 header_offset: Some(header_offset),
27379 }
27380 }
27381 #[doc = "uniquely identifies a rule in a transaction"]
27382 pub fn push_id(mut self, value: u32) -> Self {
27383 push_header(self.as_rec_mut(), 8u16, 4 as u16);
27384 self.as_rec_mut().extend(value.to_ne_bytes());
27385 self
27386 }
27387}
27388impl<Prev: Rec> Drop for PushOpDestroyruleDoRequest<Prev> {
27389 fn drop(&mut self) {
27390 if let Some(prev) = &mut self.prev {
27391 if let Some(header_offset) = &self.header_offset {
27392 finalize_nested_header(prev.as_rec_mut(), *header_offset);
27393 }
27394 }
27395 }
27396}
27397#[doc = "Delete an existing rule with destroy semantics (ignoring ENOENT errors).\n"]
27398#[derive(Clone)]
27399pub enum OpDestroyruleDoRequest<'a> {
27400 #[doc = "name of the table containing the rule"]
27401 Table(&'a CStr),
27402 #[doc = "name of the chain containing the rule"]
27403 Chain(&'a CStr),
27404 #[doc = "numeric handle of the rule"]
27405 Handle(u64),
27406 #[doc = "list of expressions"]
27407 Expressions(IterableExprListAttrs<'a>),
27408 #[doc = "uniquely identifies a rule in a transaction"]
27409 Id(u32),
27410}
27411impl<'a> IterableOpDestroyruleDoRequest<'a> {
27412 #[doc = "name of the table containing the rule"]
27413 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
27414 let mut iter = self.clone();
27415 iter.pos = 0;
27416 for attr in iter {
27417 if let OpDestroyruleDoRequest::Table(val) = attr? {
27418 return Ok(val);
27419 }
27420 }
27421 Err(ErrorContext::new_missing(
27422 "OpDestroyruleDoRequest",
27423 "Table",
27424 self.orig_loc,
27425 self.buf.as_ptr() as usize,
27426 ))
27427 }
27428 #[doc = "name of the chain containing the rule"]
27429 pub fn get_chain(&self) -> Result<&'a CStr, ErrorContext> {
27430 let mut iter = self.clone();
27431 iter.pos = 0;
27432 for attr in iter {
27433 if let OpDestroyruleDoRequest::Chain(val) = attr? {
27434 return Ok(val);
27435 }
27436 }
27437 Err(ErrorContext::new_missing(
27438 "OpDestroyruleDoRequest",
27439 "Chain",
27440 self.orig_loc,
27441 self.buf.as_ptr() as usize,
27442 ))
27443 }
27444 #[doc = "numeric handle of the rule"]
27445 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
27446 let mut iter = self.clone();
27447 iter.pos = 0;
27448 for attr in iter {
27449 if let OpDestroyruleDoRequest::Handle(val) = attr? {
27450 return Ok(val);
27451 }
27452 }
27453 Err(ErrorContext::new_missing(
27454 "OpDestroyruleDoRequest",
27455 "Handle",
27456 self.orig_loc,
27457 self.buf.as_ptr() as usize,
27458 ))
27459 }
27460 #[doc = "list of expressions"]
27461 pub fn get_expressions(&self) -> Result<IterableExprListAttrs<'a>, ErrorContext> {
27462 let mut iter = self.clone();
27463 iter.pos = 0;
27464 for attr in iter {
27465 if let OpDestroyruleDoRequest::Expressions(val) = attr? {
27466 return Ok(val);
27467 }
27468 }
27469 Err(ErrorContext::new_missing(
27470 "OpDestroyruleDoRequest",
27471 "Expressions",
27472 self.orig_loc,
27473 self.buf.as_ptr() as usize,
27474 ))
27475 }
27476 #[doc = "uniquely identifies a rule in a transaction"]
27477 pub fn get_id(&self) -> Result<u32, ErrorContext> {
27478 let mut iter = self.clone();
27479 iter.pos = 0;
27480 for attr in iter {
27481 if let OpDestroyruleDoRequest::Id(val) = attr? {
27482 return Ok(val);
27483 }
27484 }
27485 Err(ErrorContext::new_missing(
27486 "OpDestroyruleDoRequest",
27487 "Id",
27488 self.orig_loc,
27489 self.buf.as_ptr() as usize,
27490 ))
27491 }
27492}
27493impl<'a> OpDestroyruleDoRequest<'a> {
27494 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDestroyruleDoRequest<'a>) {
27495 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
27496 (
27497 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
27498 IterableOpDestroyruleDoRequest::with_loc(attrs, buf.as_ptr() as usize),
27499 )
27500 }
27501 fn attr_from_type(r#type: u16) -> Option<&'static str> {
27502 RuleAttrs::attr_from_type(r#type)
27503 }
27504}
27505#[derive(Clone, Copy, Default)]
27506pub struct IterableOpDestroyruleDoRequest<'a> {
27507 buf: &'a [u8],
27508 pos: usize,
27509 orig_loc: usize,
27510}
27511impl<'a> IterableOpDestroyruleDoRequest<'a> {
27512 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
27513 Self {
27514 buf,
27515 pos: 0,
27516 orig_loc,
27517 }
27518 }
27519 pub fn get_buf(&self) -> &'a [u8] {
27520 self.buf
27521 }
27522}
27523impl<'a> Iterator for IterableOpDestroyruleDoRequest<'a> {
27524 type Item = Result<OpDestroyruleDoRequest<'a>, ErrorContext>;
27525 fn next(&mut self) -> Option<Self::Item> {
27526 if self.buf.len() == self.pos {
27527 return None;
27528 }
27529 let pos = self.pos;
27530 let mut r#type = None;
27531 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
27532 r#type = Some(header.r#type);
27533 let res = match header.r#type {
27534 1u16 => OpDestroyruleDoRequest::Table({
27535 let res = CStr::from_bytes_with_nul(next).ok();
27536 let Some(val) = res else { break };
27537 val
27538 }),
27539 2u16 => OpDestroyruleDoRequest::Chain({
27540 let res = CStr::from_bytes_with_nul(next).ok();
27541 let Some(val) = res else { break };
27542 val
27543 }),
27544 3u16 => OpDestroyruleDoRequest::Handle({
27545 let res = parse_be_u64(next);
27546 let Some(val) = res else { break };
27547 val
27548 }),
27549 4u16 => OpDestroyruleDoRequest::Expressions({
27550 let res = Some(IterableExprListAttrs::with_loc(next, self.orig_loc));
27551 let Some(val) = res else { break };
27552 val
27553 }),
27554 8u16 => OpDestroyruleDoRequest::Id({
27555 let res = parse_u32(next);
27556 let Some(val) = res else { break };
27557 val
27558 }),
27559 n => {
27560 if cfg!(any(test, feature = "deny-unknown-attrs")) {
27561 break;
27562 } else {
27563 continue;
27564 }
27565 }
27566 };
27567 return Some(Ok(res));
27568 }
27569 Some(Err(ErrorContext::new(
27570 "OpDestroyruleDoRequest",
27571 r#type.and_then(|t| OpDestroyruleDoRequest::attr_from_type(t)),
27572 self.orig_loc,
27573 self.buf.as_ptr().wrapping_add(pos) as usize,
27574 )))
27575 }
27576}
27577impl<'a> std::fmt::Debug for IterableOpDestroyruleDoRequest<'_> {
27578 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27579 let mut fmt = f.debug_struct("OpDestroyruleDoRequest");
27580 for attr in self.clone() {
27581 let attr = match attr {
27582 Ok(a) => a,
27583 Err(err) => {
27584 fmt.finish()?;
27585 f.write_str("Err(")?;
27586 err.fmt(f)?;
27587 return f.write_str(")");
27588 }
27589 };
27590 match attr {
27591 OpDestroyruleDoRequest::Table(val) => fmt.field("Table", &val),
27592 OpDestroyruleDoRequest::Chain(val) => fmt.field("Chain", &val),
27593 OpDestroyruleDoRequest::Handle(val) => fmt.field("Handle", &val),
27594 OpDestroyruleDoRequest::Expressions(val) => fmt.field("Expressions", &val),
27595 OpDestroyruleDoRequest::Id(val) => fmt.field("Id", &val),
27596 };
27597 }
27598 fmt.finish()
27599 }
27600}
27601impl IterableOpDestroyruleDoRequest<'_> {
27602 pub fn lookup_attr(
27603 &self,
27604 offset: usize,
27605 missing_type: Option<u16>,
27606 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27607 let mut stack = Vec::new();
27608 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
27609 if cur == offset + PushNfgenmsg::len() {
27610 stack.push(("OpDestroyruleDoRequest", offset));
27611 return (
27612 stack,
27613 missing_type.and_then(|t| OpDestroyruleDoRequest::attr_from_type(t)),
27614 );
27615 }
27616 if cur > offset || cur + self.buf.len() < offset {
27617 return (stack, None);
27618 }
27619 let mut attrs = self.clone();
27620 let mut last_off = cur + attrs.pos;
27621 let mut missing = None;
27622 while let Some(attr) = attrs.next() {
27623 let Ok(attr) = attr else { break };
27624 match attr {
27625 OpDestroyruleDoRequest::Table(val) => {
27626 if last_off == offset {
27627 stack.push(("Table", last_off));
27628 break;
27629 }
27630 }
27631 OpDestroyruleDoRequest::Chain(val) => {
27632 if last_off == offset {
27633 stack.push(("Chain", last_off));
27634 break;
27635 }
27636 }
27637 OpDestroyruleDoRequest::Handle(val) => {
27638 if last_off == offset {
27639 stack.push(("Handle", last_off));
27640 break;
27641 }
27642 }
27643 OpDestroyruleDoRequest::Expressions(val) => {
27644 (stack, missing) = val.lookup_attr(offset, missing_type);
27645 if !stack.is_empty() {
27646 break;
27647 }
27648 }
27649 OpDestroyruleDoRequest::Id(val) => {
27650 if last_off == offset {
27651 stack.push(("Id", last_off));
27652 break;
27653 }
27654 }
27655 _ => {}
27656 };
27657 last_off = cur + attrs.pos;
27658 }
27659 if !stack.is_empty() {
27660 stack.push(("OpDestroyruleDoRequest", cur));
27661 }
27662 (stack, missing)
27663 }
27664}
27665#[doc = "Delete an existing rule with destroy semantics (ignoring ENOENT errors).\n"]
27666pub struct PushOpDestroyruleDoReply<Prev: Rec> {
27667 pub(crate) prev: Option<Prev>,
27668 pub(crate) header_offset: Option<usize>,
27669}
27670impl<Prev: Rec> Rec for PushOpDestroyruleDoReply<Prev> {
27671 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
27672 self.prev.as_mut().unwrap().as_rec_mut()
27673 }
27674}
27675impl<Prev: Rec> PushOpDestroyruleDoReply<Prev> {
27676 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
27677 Self::write_header(&mut prev, header);
27678 Self::new_without_header(prev)
27679 }
27680 fn new_without_header(prev: Prev) -> Self {
27681 Self {
27682 prev: Some(prev),
27683 header_offset: None,
27684 }
27685 }
27686 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
27687 prev.as_rec_mut().extend(header.as_slice());
27688 }
27689 pub fn end_nested(mut self) -> Prev {
27690 let mut prev = self.prev.take().unwrap();
27691 if let Some(header_offset) = &self.header_offset {
27692 finalize_nested_header(prev.as_rec_mut(), *header_offset);
27693 }
27694 prev
27695 }
27696}
27697impl<Prev: Rec> Drop for PushOpDestroyruleDoReply<Prev> {
27698 fn drop(&mut self) {
27699 if let Some(prev) = &mut self.prev {
27700 if let Some(header_offset) = &self.header_offset {
27701 finalize_nested_header(prev.as_rec_mut(), *header_offset);
27702 }
27703 }
27704 }
27705}
27706#[doc = "Delete an existing rule with destroy semantics (ignoring ENOENT errors).\n"]
27707#[derive(Clone)]
27708pub enum OpDestroyruleDoReply {}
27709impl<'a> IterableOpDestroyruleDoReply<'a> {}
27710impl OpDestroyruleDoReply {
27711 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDestroyruleDoReply<'_>) {
27712 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
27713 (
27714 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
27715 IterableOpDestroyruleDoReply::with_loc(attrs, buf.as_ptr() as usize),
27716 )
27717 }
27718 fn attr_from_type(r#type: u16) -> Option<&'static str> {
27719 RuleAttrs::attr_from_type(r#type)
27720 }
27721}
27722#[derive(Clone, Copy, Default)]
27723pub struct IterableOpDestroyruleDoReply<'a> {
27724 buf: &'a [u8],
27725 pos: usize,
27726 orig_loc: usize,
27727}
27728impl<'a> IterableOpDestroyruleDoReply<'a> {
27729 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
27730 Self {
27731 buf,
27732 pos: 0,
27733 orig_loc,
27734 }
27735 }
27736 pub fn get_buf(&self) -> &'a [u8] {
27737 self.buf
27738 }
27739}
27740impl<'a> Iterator for IterableOpDestroyruleDoReply<'a> {
27741 type Item = Result<OpDestroyruleDoReply, ErrorContext>;
27742 fn next(&mut self) -> Option<Self::Item> {
27743 if self.buf.len() == self.pos {
27744 return None;
27745 }
27746 let pos = self.pos;
27747 let mut r#type = None;
27748 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
27749 r#type = Some(header.r#type);
27750 let res = match header.r#type {
27751 n => {
27752 if cfg!(any(test, feature = "deny-unknown-attrs")) {
27753 break;
27754 } else {
27755 continue;
27756 }
27757 }
27758 };
27759 return Some(Ok(res));
27760 }
27761 Some(Err(ErrorContext::new(
27762 "OpDestroyruleDoReply",
27763 r#type.and_then(|t| OpDestroyruleDoReply::attr_from_type(t)),
27764 self.orig_loc,
27765 self.buf.as_ptr().wrapping_add(pos) as usize,
27766 )))
27767 }
27768}
27769impl std::fmt::Debug for IterableOpDestroyruleDoReply<'_> {
27770 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27771 let mut fmt = f.debug_struct("OpDestroyruleDoReply");
27772 for attr in self.clone() {
27773 let attr = match attr {
27774 Ok(a) => a,
27775 Err(err) => {
27776 fmt.finish()?;
27777 f.write_str("Err(")?;
27778 err.fmt(f)?;
27779 return f.write_str(")");
27780 }
27781 };
27782 match attr {};
27783 }
27784 fmt.finish()
27785 }
27786}
27787impl IterableOpDestroyruleDoReply<'_> {
27788 pub fn lookup_attr(
27789 &self,
27790 offset: usize,
27791 missing_type: Option<u16>,
27792 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27793 let mut stack = Vec::new();
27794 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
27795 if cur == offset + PushNfgenmsg::len() {
27796 stack.push(("OpDestroyruleDoReply", offset));
27797 return (
27798 stack,
27799 missing_type.and_then(|t| OpDestroyruleDoReply::attr_from_type(t)),
27800 );
27801 }
27802 (stack, None)
27803 }
27804}
27805#[derive(Debug)]
27806pub struct RequestOpDestroyruleDoRequest<'r> {
27807 request: Request<'r>,
27808}
27809impl<'r> RequestOpDestroyruleDoRequest<'r> {
27810 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
27811 PushOpDestroyruleDoRequest::write_header(&mut request.buf_mut(), header);
27812 Self { request: request }
27813 }
27814 pub fn encode(&mut self) -> PushOpDestroyruleDoRequest<&mut Vec<u8>> {
27815 PushOpDestroyruleDoRequest::new_without_header(self.request.buf_mut())
27816 }
27817 pub fn into_encoder(self) -> PushOpDestroyruleDoRequest<RequestBuf<'r>> {
27818 PushOpDestroyruleDoRequest::new_without_header(self.request.buf)
27819 }
27820}
27821impl NetlinkRequest for RequestOpDestroyruleDoRequest<'_> {
27822 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDestroyruleDoReply<'buf>);
27823 fn protocol(&self) -> Protocol {
27824 Protocol::Raw {
27825 protonum: 12u16,
27826 request_type: 2588u16,
27827 }
27828 }
27829 fn flags(&self) -> u16 {
27830 self.request.flags
27831 }
27832 fn payload(&self) -> &[u8] {
27833 self.request.buf()
27834 }
27835 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
27836 OpDestroyruleDoReply::new(buf)
27837 }
27838 fn lookup(
27839 buf: &[u8],
27840 offset: usize,
27841 missing_type: Option<u16>,
27842 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
27843 OpDestroyruleDoRequest::new(buf)
27844 .1
27845 .lookup_attr(offset, missing_type)
27846 }
27847}
27848#[doc = "Create a new set."]
27849pub struct PushOpNewsetDoRequest<Prev: Rec> {
27850 pub(crate) prev: Option<Prev>,
27851 pub(crate) header_offset: Option<usize>,
27852}
27853impl<Prev: Rec> Rec for PushOpNewsetDoRequest<Prev> {
27854 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
27855 self.prev.as_mut().unwrap().as_rec_mut()
27856 }
27857}
27858impl<Prev: Rec> PushOpNewsetDoRequest<Prev> {
27859 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
27860 Self::write_header(&mut prev, header);
27861 Self::new_without_header(prev)
27862 }
27863 fn new_without_header(prev: Prev) -> Self {
27864 Self {
27865 prev: Some(prev),
27866 header_offset: None,
27867 }
27868 }
27869 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
27870 prev.as_rec_mut().extend(header.as_slice());
27871 }
27872 pub fn end_nested(mut self) -> Prev {
27873 let mut prev = self.prev.take().unwrap();
27874 if let Some(header_offset) = &self.header_offset {
27875 finalize_nested_header(prev.as_rec_mut(), *header_offset);
27876 }
27877 prev
27878 }
27879 #[doc = "table name"]
27880 pub fn push_table(mut self, value: &CStr) -> Self {
27881 push_header(
27882 self.as_rec_mut(),
27883 1u16,
27884 value.to_bytes_with_nul().len() as u16,
27885 );
27886 self.as_rec_mut().extend(value.to_bytes_with_nul());
27887 self
27888 }
27889 #[doc = "table name"]
27890 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
27891 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
27892 self.as_rec_mut().extend(value);
27893 self.as_rec_mut().push(0);
27894 self
27895 }
27896 #[doc = "set name"]
27897 pub fn push_name(mut self, value: &CStr) -> Self {
27898 push_header(
27899 self.as_rec_mut(),
27900 2u16,
27901 value.to_bytes_with_nul().len() as u16,
27902 );
27903 self.as_rec_mut().extend(value.to_bytes_with_nul());
27904 self
27905 }
27906 #[doc = "set name"]
27907 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
27908 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
27909 self.as_rec_mut().extend(value);
27910 self.as_rec_mut().push(0);
27911 self
27912 }
27913 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
27914 pub fn push_flags(mut self, value: u32) -> Self {
27915 push_header(self.as_rec_mut(), 3u16, 4 as u16);
27916 self.as_rec_mut().extend(value.to_be_bytes());
27917 self
27918 }
27919 #[doc = "key data type, informational purpose only"]
27920 pub fn push_key_type(mut self, value: u32) -> Self {
27921 push_header(self.as_rec_mut(), 4u16, 4 as u16);
27922 self.as_rec_mut().extend(value.to_be_bytes());
27923 self
27924 }
27925 #[doc = "key data length"]
27926 pub fn push_key_len(mut self, value: u32) -> Self {
27927 push_header(self.as_rec_mut(), 5u16, 4 as u16);
27928 self.as_rec_mut().extend(value.to_be_bytes());
27929 self
27930 }
27931 #[doc = "mapping data type"]
27932 pub fn push_data_type(mut self, value: u32) -> Self {
27933 push_header(self.as_rec_mut(), 6u16, 4 as u16);
27934 self.as_rec_mut().extend(value.to_be_bytes());
27935 self
27936 }
27937 #[doc = "mapping data length"]
27938 pub fn push_data_len(mut self, value: u32) -> Self {
27939 push_header(self.as_rec_mut(), 7u16, 4 as u16);
27940 self.as_rec_mut().extend(value.to_be_bytes());
27941 self
27942 }
27943 #[doc = "selection policy"]
27944 pub fn push_policy(mut self, value: u32) -> Self {
27945 push_header(self.as_rec_mut(), 8u16, 4 as u16);
27946 self.as_rec_mut().extend(value.to_be_bytes());
27947 self
27948 }
27949 #[doc = "set description"]
27950 pub fn nested_desc(mut self) -> PushSetDescAttrs<Self> {
27951 let header_offset = push_nested_header(self.as_rec_mut(), 9u16);
27952 PushSetDescAttrs {
27953 prev: Some(self),
27954 header_offset: Some(header_offset),
27955 }
27956 }
27957 #[doc = "uniquely identifies a set in a transaction"]
27958 pub fn push_id(mut self, value: u32) -> Self {
27959 push_header(self.as_rec_mut(), 10u16, 4 as u16);
27960 self.as_rec_mut().extend(value.to_ne_bytes());
27961 self
27962 }
27963 #[doc = "default timeout value"]
27964 pub fn push_timeout(mut self, value: u64) -> Self {
27965 push_header(self.as_rec_mut(), 11u16, 8 as u16);
27966 self.as_rec_mut().extend(value.to_ne_bytes());
27967 self
27968 }
27969 #[doc = "garbage collection interval"]
27970 pub fn push_gc_interval(mut self, value: u32) -> Self {
27971 push_header(self.as_rec_mut(), 12u16, 4 as u16);
27972 self.as_rec_mut().extend(value.to_ne_bytes());
27973 self
27974 }
27975 #[doc = "user data"]
27976 pub fn push_userdata(mut self, value: &[u8]) -> Self {
27977 push_header(self.as_rec_mut(), 13u16, value.len() as u16);
27978 self.as_rec_mut().extend(value);
27979 self
27980 }
27981 #[doc = "stateful object type"]
27982 pub fn push_obj_type(mut self, value: u32) -> Self {
27983 push_header(self.as_rec_mut(), 15u16, 4 as u16);
27984 self.as_rec_mut().extend(value.to_be_bytes());
27985 self
27986 }
27987}
27988impl<Prev: Rec> Drop for PushOpNewsetDoRequest<Prev> {
27989 fn drop(&mut self) {
27990 if let Some(prev) = &mut self.prev {
27991 if let Some(header_offset) = &self.header_offset {
27992 finalize_nested_header(prev.as_rec_mut(), *header_offset);
27993 }
27994 }
27995 }
27996}
27997#[doc = "Create a new set."]
27998#[derive(Clone)]
27999pub enum OpNewsetDoRequest<'a> {
28000 #[doc = "table name"]
28001 Table(&'a CStr),
28002 #[doc = "set name"]
28003 Name(&'a CStr),
28004 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
28005 Flags(u32),
28006 #[doc = "key data type, informational purpose only"]
28007 KeyType(u32),
28008 #[doc = "key data length"]
28009 KeyLen(u32),
28010 #[doc = "mapping data type"]
28011 DataType(u32),
28012 #[doc = "mapping data length"]
28013 DataLen(u32),
28014 #[doc = "selection policy"]
28015 Policy(u32),
28016 #[doc = "set description"]
28017 Desc(IterableSetDescAttrs<'a>),
28018 #[doc = "uniquely identifies a set in a transaction"]
28019 Id(u32),
28020 #[doc = "default timeout value"]
28021 Timeout(u64),
28022 #[doc = "garbage collection interval"]
28023 GcInterval(u32),
28024 #[doc = "user data"]
28025 Userdata(&'a [u8]),
28026 #[doc = "stateful object type"]
28027 ObjType(u32),
28028}
28029impl<'a> IterableOpNewsetDoRequest<'a> {
28030 #[doc = "table name"]
28031 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
28032 let mut iter = self.clone();
28033 iter.pos = 0;
28034 for attr in iter {
28035 if let OpNewsetDoRequest::Table(val) = attr? {
28036 return Ok(val);
28037 }
28038 }
28039 Err(ErrorContext::new_missing(
28040 "OpNewsetDoRequest",
28041 "Table",
28042 self.orig_loc,
28043 self.buf.as_ptr() as usize,
28044 ))
28045 }
28046 #[doc = "set name"]
28047 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
28048 let mut iter = self.clone();
28049 iter.pos = 0;
28050 for attr in iter {
28051 if let OpNewsetDoRequest::Name(val) = attr? {
28052 return Ok(val);
28053 }
28054 }
28055 Err(ErrorContext::new_missing(
28056 "OpNewsetDoRequest",
28057 "Name",
28058 self.orig_loc,
28059 self.buf.as_ptr() as usize,
28060 ))
28061 }
28062 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
28063 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
28064 let mut iter = self.clone();
28065 iter.pos = 0;
28066 for attr in iter {
28067 if let OpNewsetDoRequest::Flags(val) = attr? {
28068 return Ok(val);
28069 }
28070 }
28071 Err(ErrorContext::new_missing(
28072 "OpNewsetDoRequest",
28073 "Flags",
28074 self.orig_loc,
28075 self.buf.as_ptr() as usize,
28076 ))
28077 }
28078 #[doc = "key data type, informational purpose only"]
28079 pub fn get_key_type(&self) -> Result<u32, ErrorContext> {
28080 let mut iter = self.clone();
28081 iter.pos = 0;
28082 for attr in iter {
28083 if let OpNewsetDoRequest::KeyType(val) = attr? {
28084 return Ok(val);
28085 }
28086 }
28087 Err(ErrorContext::new_missing(
28088 "OpNewsetDoRequest",
28089 "KeyType",
28090 self.orig_loc,
28091 self.buf.as_ptr() as usize,
28092 ))
28093 }
28094 #[doc = "key data length"]
28095 pub fn get_key_len(&self) -> Result<u32, ErrorContext> {
28096 let mut iter = self.clone();
28097 iter.pos = 0;
28098 for attr in iter {
28099 if let OpNewsetDoRequest::KeyLen(val) = attr? {
28100 return Ok(val);
28101 }
28102 }
28103 Err(ErrorContext::new_missing(
28104 "OpNewsetDoRequest",
28105 "KeyLen",
28106 self.orig_loc,
28107 self.buf.as_ptr() as usize,
28108 ))
28109 }
28110 #[doc = "mapping data type"]
28111 pub fn get_data_type(&self) -> Result<u32, ErrorContext> {
28112 let mut iter = self.clone();
28113 iter.pos = 0;
28114 for attr in iter {
28115 if let OpNewsetDoRequest::DataType(val) = attr? {
28116 return Ok(val);
28117 }
28118 }
28119 Err(ErrorContext::new_missing(
28120 "OpNewsetDoRequest",
28121 "DataType",
28122 self.orig_loc,
28123 self.buf.as_ptr() as usize,
28124 ))
28125 }
28126 #[doc = "mapping data length"]
28127 pub fn get_data_len(&self) -> Result<u32, ErrorContext> {
28128 let mut iter = self.clone();
28129 iter.pos = 0;
28130 for attr in iter {
28131 if let OpNewsetDoRequest::DataLen(val) = attr? {
28132 return Ok(val);
28133 }
28134 }
28135 Err(ErrorContext::new_missing(
28136 "OpNewsetDoRequest",
28137 "DataLen",
28138 self.orig_loc,
28139 self.buf.as_ptr() as usize,
28140 ))
28141 }
28142 #[doc = "selection policy"]
28143 pub fn get_policy(&self) -> Result<u32, ErrorContext> {
28144 let mut iter = self.clone();
28145 iter.pos = 0;
28146 for attr in iter {
28147 if let OpNewsetDoRequest::Policy(val) = attr? {
28148 return Ok(val);
28149 }
28150 }
28151 Err(ErrorContext::new_missing(
28152 "OpNewsetDoRequest",
28153 "Policy",
28154 self.orig_loc,
28155 self.buf.as_ptr() as usize,
28156 ))
28157 }
28158 #[doc = "set description"]
28159 pub fn get_desc(&self) -> Result<IterableSetDescAttrs<'a>, ErrorContext> {
28160 let mut iter = self.clone();
28161 iter.pos = 0;
28162 for attr in iter {
28163 if let OpNewsetDoRequest::Desc(val) = attr? {
28164 return Ok(val);
28165 }
28166 }
28167 Err(ErrorContext::new_missing(
28168 "OpNewsetDoRequest",
28169 "Desc",
28170 self.orig_loc,
28171 self.buf.as_ptr() as usize,
28172 ))
28173 }
28174 #[doc = "uniquely identifies a set in a transaction"]
28175 pub fn get_id(&self) -> Result<u32, ErrorContext> {
28176 let mut iter = self.clone();
28177 iter.pos = 0;
28178 for attr in iter {
28179 if let OpNewsetDoRequest::Id(val) = attr? {
28180 return Ok(val);
28181 }
28182 }
28183 Err(ErrorContext::new_missing(
28184 "OpNewsetDoRequest",
28185 "Id",
28186 self.orig_loc,
28187 self.buf.as_ptr() as usize,
28188 ))
28189 }
28190 #[doc = "default timeout value"]
28191 pub fn get_timeout(&self) -> Result<u64, ErrorContext> {
28192 let mut iter = self.clone();
28193 iter.pos = 0;
28194 for attr in iter {
28195 if let OpNewsetDoRequest::Timeout(val) = attr? {
28196 return Ok(val);
28197 }
28198 }
28199 Err(ErrorContext::new_missing(
28200 "OpNewsetDoRequest",
28201 "Timeout",
28202 self.orig_loc,
28203 self.buf.as_ptr() as usize,
28204 ))
28205 }
28206 #[doc = "garbage collection interval"]
28207 pub fn get_gc_interval(&self) -> Result<u32, ErrorContext> {
28208 let mut iter = self.clone();
28209 iter.pos = 0;
28210 for attr in iter {
28211 if let OpNewsetDoRequest::GcInterval(val) = attr? {
28212 return Ok(val);
28213 }
28214 }
28215 Err(ErrorContext::new_missing(
28216 "OpNewsetDoRequest",
28217 "GcInterval",
28218 self.orig_loc,
28219 self.buf.as_ptr() as usize,
28220 ))
28221 }
28222 #[doc = "user data"]
28223 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
28224 let mut iter = self.clone();
28225 iter.pos = 0;
28226 for attr in iter {
28227 if let OpNewsetDoRequest::Userdata(val) = attr? {
28228 return Ok(val);
28229 }
28230 }
28231 Err(ErrorContext::new_missing(
28232 "OpNewsetDoRequest",
28233 "Userdata",
28234 self.orig_loc,
28235 self.buf.as_ptr() as usize,
28236 ))
28237 }
28238 #[doc = "stateful object type"]
28239 pub fn get_obj_type(&self) -> Result<u32, ErrorContext> {
28240 let mut iter = self.clone();
28241 iter.pos = 0;
28242 for attr in iter {
28243 if let OpNewsetDoRequest::ObjType(val) = attr? {
28244 return Ok(val);
28245 }
28246 }
28247 Err(ErrorContext::new_missing(
28248 "OpNewsetDoRequest",
28249 "ObjType",
28250 self.orig_loc,
28251 self.buf.as_ptr() as usize,
28252 ))
28253 }
28254}
28255impl<'a> OpNewsetDoRequest<'a> {
28256 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpNewsetDoRequest<'a>) {
28257 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
28258 (
28259 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
28260 IterableOpNewsetDoRequest::with_loc(attrs, buf.as_ptr() as usize),
28261 )
28262 }
28263 fn attr_from_type(r#type: u16) -> Option<&'static str> {
28264 SetAttrs::attr_from_type(r#type)
28265 }
28266}
28267#[derive(Clone, Copy, Default)]
28268pub struct IterableOpNewsetDoRequest<'a> {
28269 buf: &'a [u8],
28270 pos: usize,
28271 orig_loc: usize,
28272}
28273impl<'a> IterableOpNewsetDoRequest<'a> {
28274 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
28275 Self {
28276 buf,
28277 pos: 0,
28278 orig_loc,
28279 }
28280 }
28281 pub fn get_buf(&self) -> &'a [u8] {
28282 self.buf
28283 }
28284}
28285impl<'a> Iterator for IterableOpNewsetDoRequest<'a> {
28286 type Item = Result<OpNewsetDoRequest<'a>, ErrorContext>;
28287 fn next(&mut self) -> Option<Self::Item> {
28288 if self.buf.len() == self.pos {
28289 return None;
28290 }
28291 let pos = self.pos;
28292 let mut r#type = None;
28293 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
28294 r#type = Some(header.r#type);
28295 let res = match header.r#type {
28296 1u16 => OpNewsetDoRequest::Table({
28297 let res = CStr::from_bytes_with_nul(next).ok();
28298 let Some(val) = res else { break };
28299 val
28300 }),
28301 2u16 => OpNewsetDoRequest::Name({
28302 let res = CStr::from_bytes_with_nul(next).ok();
28303 let Some(val) = res else { break };
28304 val
28305 }),
28306 3u16 => OpNewsetDoRequest::Flags({
28307 let res = parse_be_u32(next);
28308 let Some(val) = res else { break };
28309 val
28310 }),
28311 4u16 => OpNewsetDoRequest::KeyType({
28312 let res = parse_be_u32(next);
28313 let Some(val) = res else { break };
28314 val
28315 }),
28316 5u16 => OpNewsetDoRequest::KeyLen({
28317 let res = parse_be_u32(next);
28318 let Some(val) = res else { break };
28319 val
28320 }),
28321 6u16 => OpNewsetDoRequest::DataType({
28322 let res = parse_be_u32(next);
28323 let Some(val) = res else { break };
28324 val
28325 }),
28326 7u16 => OpNewsetDoRequest::DataLen({
28327 let res = parse_be_u32(next);
28328 let Some(val) = res else { break };
28329 val
28330 }),
28331 8u16 => OpNewsetDoRequest::Policy({
28332 let res = parse_be_u32(next);
28333 let Some(val) = res else { break };
28334 val
28335 }),
28336 9u16 => OpNewsetDoRequest::Desc({
28337 let res = Some(IterableSetDescAttrs::with_loc(next, self.orig_loc));
28338 let Some(val) = res else { break };
28339 val
28340 }),
28341 10u16 => OpNewsetDoRequest::Id({
28342 let res = parse_u32(next);
28343 let Some(val) = res else { break };
28344 val
28345 }),
28346 11u16 => OpNewsetDoRequest::Timeout({
28347 let res = parse_u64(next);
28348 let Some(val) = res else { break };
28349 val
28350 }),
28351 12u16 => OpNewsetDoRequest::GcInterval({
28352 let res = parse_u32(next);
28353 let Some(val) = res else { break };
28354 val
28355 }),
28356 13u16 => OpNewsetDoRequest::Userdata({
28357 let res = Some(next);
28358 let Some(val) = res else { break };
28359 val
28360 }),
28361 15u16 => OpNewsetDoRequest::ObjType({
28362 let res = parse_be_u32(next);
28363 let Some(val) = res else { break };
28364 val
28365 }),
28366 n => {
28367 if cfg!(any(test, feature = "deny-unknown-attrs")) {
28368 break;
28369 } else {
28370 continue;
28371 }
28372 }
28373 };
28374 return Some(Ok(res));
28375 }
28376 Some(Err(ErrorContext::new(
28377 "OpNewsetDoRequest",
28378 r#type.and_then(|t| OpNewsetDoRequest::attr_from_type(t)),
28379 self.orig_loc,
28380 self.buf.as_ptr().wrapping_add(pos) as usize,
28381 )))
28382 }
28383}
28384impl<'a> std::fmt::Debug for IterableOpNewsetDoRequest<'_> {
28385 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28386 let mut fmt = f.debug_struct("OpNewsetDoRequest");
28387 for attr in self.clone() {
28388 let attr = match attr {
28389 Ok(a) => a,
28390 Err(err) => {
28391 fmt.finish()?;
28392 f.write_str("Err(")?;
28393 err.fmt(f)?;
28394 return f.write_str(")");
28395 }
28396 };
28397 match attr {
28398 OpNewsetDoRequest::Table(val) => fmt.field("Table", &val),
28399 OpNewsetDoRequest::Name(val) => fmt.field("Name", &val),
28400 OpNewsetDoRequest::Flags(val) => {
28401 fmt.field("Flags", &FormatFlags(val.into(), SetFlags::from_value))
28402 }
28403 OpNewsetDoRequest::KeyType(val) => fmt.field("KeyType", &val),
28404 OpNewsetDoRequest::KeyLen(val) => fmt.field("KeyLen", &val),
28405 OpNewsetDoRequest::DataType(val) => fmt.field("DataType", &val),
28406 OpNewsetDoRequest::DataLen(val) => fmt.field("DataLen", &val),
28407 OpNewsetDoRequest::Policy(val) => fmt.field("Policy", &val),
28408 OpNewsetDoRequest::Desc(val) => fmt.field("Desc", &val),
28409 OpNewsetDoRequest::Id(val) => fmt.field("Id", &val),
28410 OpNewsetDoRequest::Timeout(val) => fmt.field("Timeout", &val),
28411 OpNewsetDoRequest::GcInterval(val) => fmt.field("GcInterval", &val),
28412 OpNewsetDoRequest::Userdata(val) => fmt.field("Userdata", &val),
28413 OpNewsetDoRequest::ObjType(val) => fmt.field("ObjType", &val),
28414 };
28415 }
28416 fmt.finish()
28417 }
28418}
28419impl IterableOpNewsetDoRequest<'_> {
28420 pub fn lookup_attr(
28421 &self,
28422 offset: usize,
28423 missing_type: Option<u16>,
28424 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28425 let mut stack = Vec::new();
28426 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
28427 if cur == offset + PushNfgenmsg::len() {
28428 stack.push(("OpNewsetDoRequest", offset));
28429 return (
28430 stack,
28431 missing_type.and_then(|t| OpNewsetDoRequest::attr_from_type(t)),
28432 );
28433 }
28434 if cur > offset || cur + self.buf.len() < offset {
28435 return (stack, None);
28436 }
28437 let mut attrs = self.clone();
28438 let mut last_off = cur + attrs.pos;
28439 let mut missing = None;
28440 while let Some(attr) = attrs.next() {
28441 let Ok(attr) = attr else { break };
28442 match attr {
28443 OpNewsetDoRequest::Table(val) => {
28444 if last_off == offset {
28445 stack.push(("Table", last_off));
28446 break;
28447 }
28448 }
28449 OpNewsetDoRequest::Name(val) => {
28450 if last_off == offset {
28451 stack.push(("Name", last_off));
28452 break;
28453 }
28454 }
28455 OpNewsetDoRequest::Flags(val) => {
28456 if last_off == offset {
28457 stack.push(("Flags", last_off));
28458 break;
28459 }
28460 }
28461 OpNewsetDoRequest::KeyType(val) => {
28462 if last_off == offset {
28463 stack.push(("KeyType", last_off));
28464 break;
28465 }
28466 }
28467 OpNewsetDoRequest::KeyLen(val) => {
28468 if last_off == offset {
28469 stack.push(("KeyLen", last_off));
28470 break;
28471 }
28472 }
28473 OpNewsetDoRequest::DataType(val) => {
28474 if last_off == offset {
28475 stack.push(("DataType", last_off));
28476 break;
28477 }
28478 }
28479 OpNewsetDoRequest::DataLen(val) => {
28480 if last_off == offset {
28481 stack.push(("DataLen", last_off));
28482 break;
28483 }
28484 }
28485 OpNewsetDoRequest::Policy(val) => {
28486 if last_off == offset {
28487 stack.push(("Policy", last_off));
28488 break;
28489 }
28490 }
28491 OpNewsetDoRequest::Desc(val) => {
28492 (stack, missing) = val.lookup_attr(offset, missing_type);
28493 if !stack.is_empty() {
28494 break;
28495 }
28496 }
28497 OpNewsetDoRequest::Id(val) => {
28498 if last_off == offset {
28499 stack.push(("Id", last_off));
28500 break;
28501 }
28502 }
28503 OpNewsetDoRequest::Timeout(val) => {
28504 if last_off == offset {
28505 stack.push(("Timeout", last_off));
28506 break;
28507 }
28508 }
28509 OpNewsetDoRequest::GcInterval(val) => {
28510 if last_off == offset {
28511 stack.push(("GcInterval", last_off));
28512 break;
28513 }
28514 }
28515 OpNewsetDoRequest::Userdata(val) => {
28516 if last_off == offset {
28517 stack.push(("Userdata", last_off));
28518 break;
28519 }
28520 }
28521 OpNewsetDoRequest::ObjType(val) => {
28522 if last_off == offset {
28523 stack.push(("ObjType", last_off));
28524 break;
28525 }
28526 }
28527 _ => {}
28528 };
28529 last_off = cur + attrs.pos;
28530 }
28531 if !stack.is_empty() {
28532 stack.push(("OpNewsetDoRequest", cur));
28533 }
28534 (stack, missing)
28535 }
28536}
28537#[doc = "Create a new set."]
28538pub struct PushOpNewsetDoReply<Prev: Rec> {
28539 pub(crate) prev: Option<Prev>,
28540 pub(crate) header_offset: Option<usize>,
28541}
28542impl<Prev: Rec> Rec for PushOpNewsetDoReply<Prev> {
28543 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
28544 self.prev.as_mut().unwrap().as_rec_mut()
28545 }
28546}
28547impl<Prev: Rec> PushOpNewsetDoReply<Prev> {
28548 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
28549 Self::write_header(&mut prev, header);
28550 Self::new_without_header(prev)
28551 }
28552 fn new_without_header(prev: Prev) -> Self {
28553 Self {
28554 prev: Some(prev),
28555 header_offset: None,
28556 }
28557 }
28558 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
28559 prev.as_rec_mut().extend(header.as_slice());
28560 }
28561 pub fn end_nested(mut self) -> Prev {
28562 let mut prev = self.prev.take().unwrap();
28563 if let Some(header_offset) = &self.header_offset {
28564 finalize_nested_header(prev.as_rec_mut(), *header_offset);
28565 }
28566 prev
28567 }
28568}
28569impl<Prev: Rec> Drop for PushOpNewsetDoReply<Prev> {
28570 fn drop(&mut self) {
28571 if let Some(prev) = &mut self.prev {
28572 if let Some(header_offset) = &self.header_offset {
28573 finalize_nested_header(prev.as_rec_mut(), *header_offset);
28574 }
28575 }
28576 }
28577}
28578#[doc = "Create a new set."]
28579#[derive(Clone)]
28580pub enum OpNewsetDoReply {}
28581impl<'a> IterableOpNewsetDoReply<'a> {}
28582impl OpNewsetDoReply {
28583 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpNewsetDoReply<'_>) {
28584 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
28585 (
28586 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
28587 IterableOpNewsetDoReply::with_loc(attrs, buf.as_ptr() as usize),
28588 )
28589 }
28590 fn attr_from_type(r#type: u16) -> Option<&'static str> {
28591 SetAttrs::attr_from_type(r#type)
28592 }
28593}
28594#[derive(Clone, Copy, Default)]
28595pub struct IterableOpNewsetDoReply<'a> {
28596 buf: &'a [u8],
28597 pos: usize,
28598 orig_loc: usize,
28599}
28600impl<'a> IterableOpNewsetDoReply<'a> {
28601 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
28602 Self {
28603 buf,
28604 pos: 0,
28605 orig_loc,
28606 }
28607 }
28608 pub fn get_buf(&self) -> &'a [u8] {
28609 self.buf
28610 }
28611}
28612impl<'a> Iterator for IterableOpNewsetDoReply<'a> {
28613 type Item = Result<OpNewsetDoReply, ErrorContext>;
28614 fn next(&mut self) -> Option<Self::Item> {
28615 if self.buf.len() == self.pos {
28616 return None;
28617 }
28618 let pos = self.pos;
28619 let mut r#type = None;
28620 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
28621 r#type = Some(header.r#type);
28622 let res = match header.r#type {
28623 n => {
28624 if cfg!(any(test, feature = "deny-unknown-attrs")) {
28625 break;
28626 } else {
28627 continue;
28628 }
28629 }
28630 };
28631 return Some(Ok(res));
28632 }
28633 Some(Err(ErrorContext::new(
28634 "OpNewsetDoReply",
28635 r#type.and_then(|t| OpNewsetDoReply::attr_from_type(t)),
28636 self.orig_loc,
28637 self.buf.as_ptr().wrapping_add(pos) as usize,
28638 )))
28639 }
28640}
28641impl std::fmt::Debug for IterableOpNewsetDoReply<'_> {
28642 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28643 let mut fmt = f.debug_struct("OpNewsetDoReply");
28644 for attr in self.clone() {
28645 let attr = match attr {
28646 Ok(a) => a,
28647 Err(err) => {
28648 fmt.finish()?;
28649 f.write_str("Err(")?;
28650 err.fmt(f)?;
28651 return f.write_str(")");
28652 }
28653 };
28654 match attr {};
28655 }
28656 fmt.finish()
28657 }
28658}
28659impl IterableOpNewsetDoReply<'_> {
28660 pub fn lookup_attr(
28661 &self,
28662 offset: usize,
28663 missing_type: Option<u16>,
28664 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28665 let mut stack = Vec::new();
28666 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
28667 if cur == offset + PushNfgenmsg::len() {
28668 stack.push(("OpNewsetDoReply", offset));
28669 return (
28670 stack,
28671 missing_type.and_then(|t| OpNewsetDoReply::attr_from_type(t)),
28672 );
28673 }
28674 (stack, None)
28675 }
28676}
28677#[derive(Debug)]
28678pub struct RequestOpNewsetDoRequest<'r> {
28679 request: Request<'r>,
28680}
28681impl<'r> RequestOpNewsetDoRequest<'r> {
28682 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
28683 PushOpNewsetDoRequest::write_header(&mut request.buf_mut(), header);
28684 Self { request: request }
28685 }
28686 pub fn encode(&mut self) -> PushOpNewsetDoRequest<&mut Vec<u8>> {
28687 PushOpNewsetDoRequest::new_without_header(self.request.buf_mut())
28688 }
28689 pub fn into_encoder(self) -> PushOpNewsetDoRequest<RequestBuf<'r>> {
28690 PushOpNewsetDoRequest::new_without_header(self.request.buf)
28691 }
28692}
28693impl NetlinkRequest for RequestOpNewsetDoRequest<'_> {
28694 type ReplyType<'buf> = (PushNfgenmsg, IterableOpNewsetDoReply<'buf>);
28695 fn protocol(&self) -> Protocol {
28696 Protocol::Raw {
28697 protonum: 12u16,
28698 request_type: 2569u16,
28699 }
28700 }
28701 fn flags(&self) -> u16 {
28702 self.request.flags
28703 }
28704 fn payload(&self) -> &[u8] {
28705 self.request.buf()
28706 }
28707 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
28708 OpNewsetDoReply::new(buf)
28709 }
28710 fn lookup(
28711 buf: &[u8],
28712 offset: usize,
28713 missing_type: Option<u16>,
28714 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28715 OpNewsetDoRequest::new(buf)
28716 .1
28717 .lookup_attr(offset, missing_type)
28718 }
28719}
28720#[doc = "Get / dump sets."]
28721pub struct PushOpGetsetDumpRequest<Prev: Rec> {
28722 pub(crate) prev: Option<Prev>,
28723 pub(crate) header_offset: Option<usize>,
28724}
28725impl<Prev: Rec> Rec for PushOpGetsetDumpRequest<Prev> {
28726 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
28727 self.prev.as_mut().unwrap().as_rec_mut()
28728 }
28729}
28730impl<Prev: Rec> PushOpGetsetDumpRequest<Prev> {
28731 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
28732 Self::write_header(&mut prev, header);
28733 Self::new_without_header(prev)
28734 }
28735 fn new_without_header(prev: Prev) -> Self {
28736 Self {
28737 prev: Some(prev),
28738 header_offset: None,
28739 }
28740 }
28741 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
28742 prev.as_rec_mut().extend(header.as_slice());
28743 }
28744 pub fn end_nested(mut self) -> Prev {
28745 let mut prev = self.prev.take().unwrap();
28746 if let Some(header_offset) = &self.header_offset {
28747 finalize_nested_header(prev.as_rec_mut(), *header_offset);
28748 }
28749 prev
28750 }
28751 #[doc = "table name"]
28752 pub fn push_table(mut self, value: &CStr) -> Self {
28753 push_header(
28754 self.as_rec_mut(),
28755 1u16,
28756 value.to_bytes_with_nul().len() as u16,
28757 );
28758 self.as_rec_mut().extend(value.to_bytes_with_nul());
28759 self
28760 }
28761 #[doc = "table name"]
28762 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
28763 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
28764 self.as_rec_mut().extend(value);
28765 self.as_rec_mut().push(0);
28766 self
28767 }
28768}
28769impl<Prev: Rec> Drop for PushOpGetsetDumpRequest<Prev> {
28770 fn drop(&mut self) {
28771 if let Some(prev) = &mut self.prev {
28772 if let Some(header_offset) = &self.header_offset {
28773 finalize_nested_header(prev.as_rec_mut(), *header_offset);
28774 }
28775 }
28776 }
28777}
28778#[doc = "Get / dump sets."]
28779#[derive(Clone)]
28780pub enum OpGetsetDumpRequest<'a> {
28781 #[doc = "table name"]
28782 Table(&'a CStr),
28783}
28784impl<'a> IterableOpGetsetDumpRequest<'a> {
28785 #[doc = "table name"]
28786 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
28787 let mut iter = self.clone();
28788 iter.pos = 0;
28789 for attr in iter {
28790 if let OpGetsetDumpRequest::Table(val) = attr? {
28791 return Ok(val);
28792 }
28793 }
28794 Err(ErrorContext::new_missing(
28795 "OpGetsetDumpRequest",
28796 "Table",
28797 self.orig_loc,
28798 self.buf.as_ptr() as usize,
28799 ))
28800 }
28801}
28802impl<'a> OpGetsetDumpRequest<'a> {
28803 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetDumpRequest<'a>) {
28804 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
28805 (
28806 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
28807 IterableOpGetsetDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
28808 )
28809 }
28810 fn attr_from_type(r#type: u16) -> Option<&'static str> {
28811 SetAttrs::attr_from_type(r#type)
28812 }
28813}
28814#[derive(Clone, Copy, Default)]
28815pub struct IterableOpGetsetDumpRequest<'a> {
28816 buf: &'a [u8],
28817 pos: usize,
28818 orig_loc: usize,
28819}
28820impl<'a> IterableOpGetsetDumpRequest<'a> {
28821 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
28822 Self {
28823 buf,
28824 pos: 0,
28825 orig_loc,
28826 }
28827 }
28828 pub fn get_buf(&self) -> &'a [u8] {
28829 self.buf
28830 }
28831}
28832impl<'a> Iterator for IterableOpGetsetDumpRequest<'a> {
28833 type Item = Result<OpGetsetDumpRequest<'a>, ErrorContext>;
28834 fn next(&mut self) -> Option<Self::Item> {
28835 if self.buf.len() == self.pos {
28836 return None;
28837 }
28838 let pos = self.pos;
28839 let mut r#type = None;
28840 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
28841 r#type = Some(header.r#type);
28842 let res = match header.r#type {
28843 1u16 => OpGetsetDumpRequest::Table({
28844 let res = CStr::from_bytes_with_nul(next).ok();
28845 let Some(val) = res else { break };
28846 val
28847 }),
28848 n => {
28849 if cfg!(any(test, feature = "deny-unknown-attrs")) {
28850 break;
28851 } else {
28852 continue;
28853 }
28854 }
28855 };
28856 return Some(Ok(res));
28857 }
28858 Some(Err(ErrorContext::new(
28859 "OpGetsetDumpRequest",
28860 r#type.and_then(|t| OpGetsetDumpRequest::attr_from_type(t)),
28861 self.orig_loc,
28862 self.buf.as_ptr().wrapping_add(pos) as usize,
28863 )))
28864 }
28865}
28866impl<'a> std::fmt::Debug for IterableOpGetsetDumpRequest<'_> {
28867 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28868 let mut fmt = f.debug_struct("OpGetsetDumpRequest");
28869 for attr in self.clone() {
28870 let attr = match attr {
28871 Ok(a) => a,
28872 Err(err) => {
28873 fmt.finish()?;
28874 f.write_str("Err(")?;
28875 err.fmt(f)?;
28876 return f.write_str(")");
28877 }
28878 };
28879 match attr {
28880 OpGetsetDumpRequest::Table(val) => fmt.field("Table", &val),
28881 };
28882 }
28883 fmt.finish()
28884 }
28885}
28886impl IterableOpGetsetDumpRequest<'_> {
28887 pub fn lookup_attr(
28888 &self,
28889 offset: usize,
28890 missing_type: Option<u16>,
28891 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
28892 let mut stack = Vec::new();
28893 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
28894 if cur == offset + PushNfgenmsg::len() {
28895 stack.push(("OpGetsetDumpRequest", offset));
28896 return (
28897 stack,
28898 missing_type.and_then(|t| OpGetsetDumpRequest::attr_from_type(t)),
28899 );
28900 }
28901 if cur > offset || cur + self.buf.len() < offset {
28902 return (stack, None);
28903 }
28904 let mut attrs = self.clone();
28905 let mut last_off = cur + attrs.pos;
28906 while let Some(attr) = attrs.next() {
28907 let Ok(attr) = attr else { break };
28908 match attr {
28909 OpGetsetDumpRequest::Table(val) => {
28910 if last_off == offset {
28911 stack.push(("Table", last_off));
28912 break;
28913 }
28914 }
28915 _ => {}
28916 };
28917 last_off = cur + attrs.pos;
28918 }
28919 if !stack.is_empty() {
28920 stack.push(("OpGetsetDumpRequest", cur));
28921 }
28922 (stack, None)
28923 }
28924}
28925#[doc = "Get / dump sets."]
28926pub struct PushOpGetsetDumpReply<Prev: Rec> {
28927 pub(crate) prev: Option<Prev>,
28928 pub(crate) header_offset: Option<usize>,
28929}
28930impl<Prev: Rec> Rec for PushOpGetsetDumpReply<Prev> {
28931 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
28932 self.prev.as_mut().unwrap().as_rec_mut()
28933 }
28934}
28935impl<Prev: Rec> PushOpGetsetDumpReply<Prev> {
28936 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
28937 Self::write_header(&mut prev, header);
28938 Self::new_without_header(prev)
28939 }
28940 fn new_without_header(prev: Prev) -> Self {
28941 Self {
28942 prev: Some(prev),
28943 header_offset: None,
28944 }
28945 }
28946 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
28947 prev.as_rec_mut().extend(header.as_slice());
28948 }
28949 pub fn end_nested(mut self) -> Prev {
28950 let mut prev = self.prev.take().unwrap();
28951 if let Some(header_offset) = &self.header_offset {
28952 finalize_nested_header(prev.as_rec_mut(), *header_offset);
28953 }
28954 prev
28955 }
28956 #[doc = "table name"]
28957 pub fn push_table(mut self, value: &CStr) -> Self {
28958 push_header(
28959 self.as_rec_mut(),
28960 1u16,
28961 value.to_bytes_with_nul().len() as u16,
28962 );
28963 self.as_rec_mut().extend(value.to_bytes_with_nul());
28964 self
28965 }
28966 #[doc = "table name"]
28967 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
28968 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
28969 self.as_rec_mut().extend(value);
28970 self.as_rec_mut().push(0);
28971 self
28972 }
28973 #[doc = "set name"]
28974 pub fn push_name(mut self, value: &CStr) -> Self {
28975 push_header(
28976 self.as_rec_mut(),
28977 2u16,
28978 value.to_bytes_with_nul().len() as u16,
28979 );
28980 self.as_rec_mut().extend(value.to_bytes_with_nul());
28981 self
28982 }
28983 #[doc = "set name"]
28984 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
28985 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
28986 self.as_rec_mut().extend(value);
28987 self.as_rec_mut().push(0);
28988 self
28989 }
28990 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
28991 pub fn push_flags(mut self, value: u32) -> Self {
28992 push_header(self.as_rec_mut(), 3u16, 4 as u16);
28993 self.as_rec_mut().extend(value.to_be_bytes());
28994 self
28995 }
28996 #[doc = "key data type, informational purpose only"]
28997 pub fn push_key_type(mut self, value: u32) -> Self {
28998 push_header(self.as_rec_mut(), 4u16, 4 as u16);
28999 self.as_rec_mut().extend(value.to_be_bytes());
29000 self
29001 }
29002 #[doc = "key data length"]
29003 pub fn push_key_len(mut self, value: u32) -> Self {
29004 push_header(self.as_rec_mut(), 5u16, 4 as u16);
29005 self.as_rec_mut().extend(value.to_be_bytes());
29006 self
29007 }
29008 #[doc = "mapping data type"]
29009 pub fn push_data_type(mut self, value: u32) -> Self {
29010 push_header(self.as_rec_mut(), 6u16, 4 as u16);
29011 self.as_rec_mut().extend(value.to_be_bytes());
29012 self
29013 }
29014 #[doc = "mapping data length"]
29015 pub fn push_data_len(mut self, value: u32) -> Self {
29016 push_header(self.as_rec_mut(), 7u16, 4 as u16);
29017 self.as_rec_mut().extend(value.to_be_bytes());
29018 self
29019 }
29020 #[doc = "selection policy"]
29021 pub fn push_policy(mut self, value: u32) -> Self {
29022 push_header(self.as_rec_mut(), 8u16, 4 as u16);
29023 self.as_rec_mut().extend(value.to_be_bytes());
29024 self
29025 }
29026 #[doc = "set description"]
29027 pub fn nested_desc(mut self) -> PushSetDescAttrs<Self> {
29028 let header_offset = push_nested_header(self.as_rec_mut(), 9u16);
29029 PushSetDescAttrs {
29030 prev: Some(self),
29031 header_offset: Some(header_offset),
29032 }
29033 }
29034 #[doc = "garbage collection interval"]
29035 pub fn push_gc_interval(mut self, value: u32) -> Self {
29036 push_header(self.as_rec_mut(), 12u16, 4 as u16);
29037 self.as_rec_mut().extend(value.to_ne_bytes());
29038 self
29039 }
29040 #[doc = "user data"]
29041 pub fn push_userdata(mut self, value: &[u8]) -> Self {
29042 push_header(self.as_rec_mut(), 13u16, value.len() as u16);
29043 self.as_rec_mut().extend(value);
29044 self
29045 }
29046 #[doc = "stateful object type"]
29047 pub fn push_obj_type(mut self, value: u32) -> Self {
29048 push_header(self.as_rec_mut(), 15u16, 4 as u16);
29049 self.as_rec_mut().extend(value.to_be_bytes());
29050 self
29051 }
29052 #[doc = "set handle"]
29053 pub fn push_handle(mut self, value: u64) -> Self {
29054 push_header(self.as_rec_mut(), 16u16, 8 as u16);
29055 self.as_rec_mut().extend(value.to_be_bytes());
29056 self
29057 }
29058 #[doc = "set expression\nAttribute may repeat multiple times (treat it as array)"]
29059 pub fn nested_expr(mut self) -> PushExprAttrs<Self> {
29060 let header_offset = push_nested_header(self.as_rec_mut(), 17u16);
29061 PushExprAttrs {
29062 prev: Some(self),
29063 header_offset: Some(header_offset),
29064 }
29065 }
29066 #[doc = "list of expressions"]
29067 pub fn nested_expressions(mut self) -> PushSetListAttrs<Self> {
29068 let header_offset = push_nested_header(self.as_rec_mut(), 18u16);
29069 PushSetListAttrs {
29070 prev: Some(self),
29071 header_offset: Some(header_offset),
29072 }
29073 }
29074}
29075impl<Prev: Rec> Drop for PushOpGetsetDumpReply<Prev> {
29076 fn drop(&mut self) {
29077 if let Some(prev) = &mut self.prev {
29078 if let Some(header_offset) = &self.header_offset {
29079 finalize_nested_header(prev.as_rec_mut(), *header_offset);
29080 }
29081 }
29082 }
29083}
29084#[doc = "Get / dump sets."]
29085#[derive(Clone)]
29086pub enum OpGetsetDumpReply<'a> {
29087 #[doc = "table name"]
29088 Table(&'a CStr),
29089 #[doc = "set name"]
29090 Name(&'a CStr),
29091 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
29092 Flags(u32),
29093 #[doc = "key data type, informational purpose only"]
29094 KeyType(u32),
29095 #[doc = "key data length"]
29096 KeyLen(u32),
29097 #[doc = "mapping data type"]
29098 DataType(u32),
29099 #[doc = "mapping data length"]
29100 DataLen(u32),
29101 #[doc = "selection policy"]
29102 Policy(u32),
29103 #[doc = "set description"]
29104 Desc(IterableSetDescAttrs<'a>),
29105 #[doc = "garbage collection interval"]
29106 GcInterval(u32),
29107 #[doc = "user data"]
29108 Userdata(&'a [u8]),
29109 #[doc = "stateful object type"]
29110 ObjType(u32),
29111 #[doc = "set handle"]
29112 Handle(u64),
29113 #[doc = "set expression\nAttribute may repeat multiple times (treat it as array)"]
29114 Expr(IterableExprAttrs<'a>),
29115 #[doc = "list of expressions"]
29116 Expressions(IterableSetListAttrs<'a>),
29117}
29118impl<'a> IterableOpGetsetDumpReply<'a> {
29119 #[doc = "table name"]
29120 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
29121 let mut iter = self.clone();
29122 iter.pos = 0;
29123 for attr in iter {
29124 if let OpGetsetDumpReply::Table(val) = attr? {
29125 return Ok(val);
29126 }
29127 }
29128 Err(ErrorContext::new_missing(
29129 "OpGetsetDumpReply",
29130 "Table",
29131 self.orig_loc,
29132 self.buf.as_ptr() as usize,
29133 ))
29134 }
29135 #[doc = "set name"]
29136 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
29137 let mut iter = self.clone();
29138 iter.pos = 0;
29139 for attr in iter {
29140 if let OpGetsetDumpReply::Name(val) = attr? {
29141 return Ok(val);
29142 }
29143 }
29144 Err(ErrorContext::new_missing(
29145 "OpGetsetDumpReply",
29146 "Name",
29147 self.orig_loc,
29148 self.buf.as_ptr() as usize,
29149 ))
29150 }
29151 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
29152 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
29153 let mut iter = self.clone();
29154 iter.pos = 0;
29155 for attr in iter {
29156 if let OpGetsetDumpReply::Flags(val) = attr? {
29157 return Ok(val);
29158 }
29159 }
29160 Err(ErrorContext::new_missing(
29161 "OpGetsetDumpReply",
29162 "Flags",
29163 self.orig_loc,
29164 self.buf.as_ptr() as usize,
29165 ))
29166 }
29167 #[doc = "key data type, informational purpose only"]
29168 pub fn get_key_type(&self) -> Result<u32, ErrorContext> {
29169 let mut iter = self.clone();
29170 iter.pos = 0;
29171 for attr in iter {
29172 if let OpGetsetDumpReply::KeyType(val) = attr? {
29173 return Ok(val);
29174 }
29175 }
29176 Err(ErrorContext::new_missing(
29177 "OpGetsetDumpReply",
29178 "KeyType",
29179 self.orig_loc,
29180 self.buf.as_ptr() as usize,
29181 ))
29182 }
29183 #[doc = "key data length"]
29184 pub fn get_key_len(&self) -> Result<u32, ErrorContext> {
29185 let mut iter = self.clone();
29186 iter.pos = 0;
29187 for attr in iter {
29188 if let OpGetsetDumpReply::KeyLen(val) = attr? {
29189 return Ok(val);
29190 }
29191 }
29192 Err(ErrorContext::new_missing(
29193 "OpGetsetDumpReply",
29194 "KeyLen",
29195 self.orig_loc,
29196 self.buf.as_ptr() as usize,
29197 ))
29198 }
29199 #[doc = "mapping data type"]
29200 pub fn get_data_type(&self) -> Result<u32, ErrorContext> {
29201 let mut iter = self.clone();
29202 iter.pos = 0;
29203 for attr in iter {
29204 if let OpGetsetDumpReply::DataType(val) = attr? {
29205 return Ok(val);
29206 }
29207 }
29208 Err(ErrorContext::new_missing(
29209 "OpGetsetDumpReply",
29210 "DataType",
29211 self.orig_loc,
29212 self.buf.as_ptr() as usize,
29213 ))
29214 }
29215 #[doc = "mapping data length"]
29216 pub fn get_data_len(&self) -> Result<u32, ErrorContext> {
29217 let mut iter = self.clone();
29218 iter.pos = 0;
29219 for attr in iter {
29220 if let OpGetsetDumpReply::DataLen(val) = attr? {
29221 return Ok(val);
29222 }
29223 }
29224 Err(ErrorContext::new_missing(
29225 "OpGetsetDumpReply",
29226 "DataLen",
29227 self.orig_loc,
29228 self.buf.as_ptr() as usize,
29229 ))
29230 }
29231 #[doc = "selection policy"]
29232 pub fn get_policy(&self) -> Result<u32, ErrorContext> {
29233 let mut iter = self.clone();
29234 iter.pos = 0;
29235 for attr in iter {
29236 if let OpGetsetDumpReply::Policy(val) = attr? {
29237 return Ok(val);
29238 }
29239 }
29240 Err(ErrorContext::new_missing(
29241 "OpGetsetDumpReply",
29242 "Policy",
29243 self.orig_loc,
29244 self.buf.as_ptr() as usize,
29245 ))
29246 }
29247 #[doc = "set description"]
29248 pub fn get_desc(&self) -> Result<IterableSetDescAttrs<'a>, ErrorContext> {
29249 let mut iter = self.clone();
29250 iter.pos = 0;
29251 for attr in iter {
29252 if let OpGetsetDumpReply::Desc(val) = attr? {
29253 return Ok(val);
29254 }
29255 }
29256 Err(ErrorContext::new_missing(
29257 "OpGetsetDumpReply",
29258 "Desc",
29259 self.orig_loc,
29260 self.buf.as_ptr() as usize,
29261 ))
29262 }
29263 #[doc = "garbage collection interval"]
29264 pub fn get_gc_interval(&self) -> Result<u32, ErrorContext> {
29265 let mut iter = self.clone();
29266 iter.pos = 0;
29267 for attr in iter {
29268 if let OpGetsetDumpReply::GcInterval(val) = attr? {
29269 return Ok(val);
29270 }
29271 }
29272 Err(ErrorContext::new_missing(
29273 "OpGetsetDumpReply",
29274 "GcInterval",
29275 self.orig_loc,
29276 self.buf.as_ptr() as usize,
29277 ))
29278 }
29279 #[doc = "user data"]
29280 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
29281 let mut iter = self.clone();
29282 iter.pos = 0;
29283 for attr in iter {
29284 if let OpGetsetDumpReply::Userdata(val) = attr? {
29285 return Ok(val);
29286 }
29287 }
29288 Err(ErrorContext::new_missing(
29289 "OpGetsetDumpReply",
29290 "Userdata",
29291 self.orig_loc,
29292 self.buf.as_ptr() as usize,
29293 ))
29294 }
29295 #[doc = "stateful object type"]
29296 pub fn get_obj_type(&self) -> Result<u32, ErrorContext> {
29297 let mut iter = self.clone();
29298 iter.pos = 0;
29299 for attr in iter {
29300 if let OpGetsetDumpReply::ObjType(val) = attr? {
29301 return Ok(val);
29302 }
29303 }
29304 Err(ErrorContext::new_missing(
29305 "OpGetsetDumpReply",
29306 "ObjType",
29307 self.orig_loc,
29308 self.buf.as_ptr() as usize,
29309 ))
29310 }
29311 #[doc = "set handle"]
29312 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
29313 let mut iter = self.clone();
29314 iter.pos = 0;
29315 for attr in iter {
29316 if let OpGetsetDumpReply::Handle(val) = attr? {
29317 return Ok(val);
29318 }
29319 }
29320 Err(ErrorContext::new_missing(
29321 "OpGetsetDumpReply",
29322 "Handle",
29323 self.orig_loc,
29324 self.buf.as_ptr() as usize,
29325 ))
29326 }
29327 #[doc = "set expression\nAttribute may repeat multiple times (treat it as array)"]
29328 pub fn get_expr(
29329 &self,
29330 ) -> MultiAttrIterable<Self, OpGetsetDumpReply<'a>, IterableExprAttrs<'a>> {
29331 MultiAttrIterable::new(self.clone(), |variant| {
29332 if let OpGetsetDumpReply::Expr(val) = variant {
29333 Some(val)
29334 } else {
29335 None
29336 }
29337 })
29338 }
29339 #[doc = "list of expressions"]
29340 pub fn get_expressions(&self) -> Result<IterableSetListAttrs<'a>, ErrorContext> {
29341 let mut iter = self.clone();
29342 iter.pos = 0;
29343 for attr in iter {
29344 if let OpGetsetDumpReply::Expressions(val) = attr? {
29345 return Ok(val);
29346 }
29347 }
29348 Err(ErrorContext::new_missing(
29349 "OpGetsetDumpReply",
29350 "Expressions",
29351 self.orig_loc,
29352 self.buf.as_ptr() as usize,
29353 ))
29354 }
29355}
29356impl<'a> OpGetsetDumpReply<'a> {
29357 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetDumpReply<'a>) {
29358 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
29359 (
29360 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
29361 IterableOpGetsetDumpReply::with_loc(attrs, buf.as_ptr() as usize),
29362 )
29363 }
29364 fn attr_from_type(r#type: u16) -> Option<&'static str> {
29365 SetAttrs::attr_from_type(r#type)
29366 }
29367}
29368#[derive(Clone, Copy, Default)]
29369pub struct IterableOpGetsetDumpReply<'a> {
29370 buf: &'a [u8],
29371 pos: usize,
29372 orig_loc: usize,
29373}
29374impl<'a> IterableOpGetsetDumpReply<'a> {
29375 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
29376 Self {
29377 buf,
29378 pos: 0,
29379 orig_loc,
29380 }
29381 }
29382 pub fn get_buf(&self) -> &'a [u8] {
29383 self.buf
29384 }
29385}
29386impl<'a> Iterator for IterableOpGetsetDumpReply<'a> {
29387 type Item = Result<OpGetsetDumpReply<'a>, ErrorContext>;
29388 fn next(&mut self) -> Option<Self::Item> {
29389 if self.buf.len() == self.pos {
29390 return None;
29391 }
29392 let pos = self.pos;
29393 let mut r#type = None;
29394 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
29395 r#type = Some(header.r#type);
29396 let res = match header.r#type {
29397 1u16 => OpGetsetDumpReply::Table({
29398 let res = CStr::from_bytes_with_nul(next).ok();
29399 let Some(val) = res else { break };
29400 val
29401 }),
29402 2u16 => OpGetsetDumpReply::Name({
29403 let res = CStr::from_bytes_with_nul(next).ok();
29404 let Some(val) = res else { break };
29405 val
29406 }),
29407 3u16 => OpGetsetDumpReply::Flags({
29408 let res = parse_be_u32(next);
29409 let Some(val) = res else { break };
29410 val
29411 }),
29412 4u16 => OpGetsetDumpReply::KeyType({
29413 let res = parse_be_u32(next);
29414 let Some(val) = res else { break };
29415 val
29416 }),
29417 5u16 => OpGetsetDumpReply::KeyLen({
29418 let res = parse_be_u32(next);
29419 let Some(val) = res else { break };
29420 val
29421 }),
29422 6u16 => OpGetsetDumpReply::DataType({
29423 let res = parse_be_u32(next);
29424 let Some(val) = res else { break };
29425 val
29426 }),
29427 7u16 => OpGetsetDumpReply::DataLen({
29428 let res = parse_be_u32(next);
29429 let Some(val) = res else { break };
29430 val
29431 }),
29432 8u16 => OpGetsetDumpReply::Policy({
29433 let res = parse_be_u32(next);
29434 let Some(val) = res else { break };
29435 val
29436 }),
29437 9u16 => OpGetsetDumpReply::Desc({
29438 let res = Some(IterableSetDescAttrs::with_loc(next, self.orig_loc));
29439 let Some(val) = res else { break };
29440 val
29441 }),
29442 12u16 => OpGetsetDumpReply::GcInterval({
29443 let res = parse_u32(next);
29444 let Some(val) = res else { break };
29445 val
29446 }),
29447 13u16 => OpGetsetDumpReply::Userdata({
29448 let res = Some(next);
29449 let Some(val) = res else { break };
29450 val
29451 }),
29452 15u16 => OpGetsetDumpReply::ObjType({
29453 let res = parse_be_u32(next);
29454 let Some(val) = res else { break };
29455 val
29456 }),
29457 16u16 => OpGetsetDumpReply::Handle({
29458 let res = parse_be_u64(next);
29459 let Some(val) = res else { break };
29460 val
29461 }),
29462 17u16 => OpGetsetDumpReply::Expr({
29463 let res = Some(IterableExprAttrs::with_loc(next, self.orig_loc));
29464 let Some(val) = res else { break };
29465 val
29466 }),
29467 18u16 => OpGetsetDumpReply::Expressions({
29468 let res = Some(IterableSetListAttrs::with_loc(next, self.orig_loc));
29469 let Some(val) = res else { break };
29470 val
29471 }),
29472 n => {
29473 if cfg!(any(test, feature = "deny-unknown-attrs")) {
29474 break;
29475 } else {
29476 continue;
29477 }
29478 }
29479 };
29480 return Some(Ok(res));
29481 }
29482 Some(Err(ErrorContext::new(
29483 "OpGetsetDumpReply",
29484 r#type.and_then(|t| OpGetsetDumpReply::attr_from_type(t)),
29485 self.orig_loc,
29486 self.buf.as_ptr().wrapping_add(pos) as usize,
29487 )))
29488 }
29489}
29490impl<'a> std::fmt::Debug for IterableOpGetsetDumpReply<'_> {
29491 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29492 let mut fmt = f.debug_struct("OpGetsetDumpReply");
29493 for attr in self.clone() {
29494 let attr = match attr {
29495 Ok(a) => a,
29496 Err(err) => {
29497 fmt.finish()?;
29498 f.write_str("Err(")?;
29499 err.fmt(f)?;
29500 return f.write_str(")");
29501 }
29502 };
29503 match attr {
29504 OpGetsetDumpReply::Table(val) => fmt.field("Table", &val),
29505 OpGetsetDumpReply::Name(val) => fmt.field("Name", &val),
29506 OpGetsetDumpReply::Flags(val) => {
29507 fmt.field("Flags", &FormatFlags(val.into(), SetFlags::from_value))
29508 }
29509 OpGetsetDumpReply::KeyType(val) => fmt.field("KeyType", &val),
29510 OpGetsetDumpReply::KeyLen(val) => fmt.field("KeyLen", &val),
29511 OpGetsetDumpReply::DataType(val) => fmt.field("DataType", &val),
29512 OpGetsetDumpReply::DataLen(val) => fmt.field("DataLen", &val),
29513 OpGetsetDumpReply::Policy(val) => fmt.field("Policy", &val),
29514 OpGetsetDumpReply::Desc(val) => fmt.field("Desc", &val),
29515 OpGetsetDumpReply::GcInterval(val) => fmt.field("GcInterval", &val),
29516 OpGetsetDumpReply::Userdata(val) => fmt.field("Userdata", &val),
29517 OpGetsetDumpReply::ObjType(val) => fmt.field("ObjType", &val),
29518 OpGetsetDumpReply::Handle(val) => fmt.field("Handle", &val),
29519 OpGetsetDumpReply::Expr(val) => fmt.field("Expr", &val),
29520 OpGetsetDumpReply::Expressions(val) => fmt.field("Expressions", &val),
29521 };
29522 }
29523 fmt.finish()
29524 }
29525}
29526impl IterableOpGetsetDumpReply<'_> {
29527 pub fn lookup_attr(
29528 &self,
29529 offset: usize,
29530 missing_type: Option<u16>,
29531 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
29532 let mut stack = Vec::new();
29533 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
29534 if cur == offset + PushNfgenmsg::len() {
29535 stack.push(("OpGetsetDumpReply", offset));
29536 return (
29537 stack,
29538 missing_type.and_then(|t| OpGetsetDumpReply::attr_from_type(t)),
29539 );
29540 }
29541 if cur > offset || cur + self.buf.len() < offset {
29542 return (stack, None);
29543 }
29544 let mut attrs = self.clone();
29545 let mut last_off = cur + attrs.pos;
29546 let mut missing = None;
29547 while let Some(attr) = attrs.next() {
29548 let Ok(attr) = attr else { break };
29549 match attr {
29550 OpGetsetDumpReply::Table(val) => {
29551 if last_off == offset {
29552 stack.push(("Table", last_off));
29553 break;
29554 }
29555 }
29556 OpGetsetDumpReply::Name(val) => {
29557 if last_off == offset {
29558 stack.push(("Name", last_off));
29559 break;
29560 }
29561 }
29562 OpGetsetDumpReply::Flags(val) => {
29563 if last_off == offset {
29564 stack.push(("Flags", last_off));
29565 break;
29566 }
29567 }
29568 OpGetsetDumpReply::KeyType(val) => {
29569 if last_off == offset {
29570 stack.push(("KeyType", last_off));
29571 break;
29572 }
29573 }
29574 OpGetsetDumpReply::KeyLen(val) => {
29575 if last_off == offset {
29576 stack.push(("KeyLen", last_off));
29577 break;
29578 }
29579 }
29580 OpGetsetDumpReply::DataType(val) => {
29581 if last_off == offset {
29582 stack.push(("DataType", last_off));
29583 break;
29584 }
29585 }
29586 OpGetsetDumpReply::DataLen(val) => {
29587 if last_off == offset {
29588 stack.push(("DataLen", last_off));
29589 break;
29590 }
29591 }
29592 OpGetsetDumpReply::Policy(val) => {
29593 if last_off == offset {
29594 stack.push(("Policy", last_off));
29595 break;
29596 }
29597 }
29598 OpGetsetDumpReply::Desc(val) => {
29599 (stack, missing) = val.lookup_attr(offset, missing_type);
29600 if !stack.is_empty() {
29601 break;
29602 }
29603 }
29604 OpGetsetDumpReply::GcInterval(val) => {
29605 if last_off == offset {
29606 stack.push(("GcInterval", last_off));
29607 break;
29608 }
29609 }
29610 OpGetsetDumpReply::Userdata(val) => {
29611 if last_off == offset {
29612 stack.push(("Userdata", last_off));
29613 break;
29614 }
29615 }
29616 OpGetsetDumpReply::ObjType(val) => {
29617 if last_off == offset {
29618 stack.push(("ObjType", last_off));
29619 break;
29620 }
29621 }
29622 OpGetsetDumpReply::Handle(val) => {
29623 if last_off == offset {
29624 stack.push(("Handle", last_off));
29625 break;
29626 }
29627 }
29628 OpGetsetDumpReply::Expr(val) => {
29629 (stack, missing) = val.lookup_attr(offset, missing_type);
29630 if !stack.is_empty() {
29631 break;
29632 }
29633 }
29634 OpGetsetDumpReply::Expressions(val) => {
29635 (stack, missing) = val.lookup_attr(offset, missing_type);
29636 if !stack.is_empty() {
29637 break;
29638 }
29639 }
29640 _ => {}
29641 };
29642 last_off = cur + attrs.pos;
29643 }
29644 if !stack.is_empty() {
29645 stack.push(("OpGetsetDumpReply", cur));
29646 }
29647 (stack, missing)
29648 }
29649}
29650#[derive(Debug)]
29651pub struct RequestOpGetsetDumpRequest<'r> {
29652 request: Request<'r>,
29653}
29654impl<'r> RequestOpGetsetDumpRequest<'r> {
29655 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
29656 PushOpGetsetDumpRequest::write_header(&mut request.buf_mut(), header);
29657 Self {
29658 request: request.set_dump(),
29659 }
29660 }
29661 pub fn encode(&mut self) -> PushOpGetsetDumpRequest<&mut Vec<u8>> {
29662 PushOpGetsetDumpRequest::new_without_header(self.request.buf_mut())
29663 }
29664 pub fn into_encoder(self) -> PushOpGetsetDumpRequest<RequestBuf<'r>> {
29665 PushOpGetsetDumpRequest::new_without_header(self.request.buf)
29666 }
29667}
29668impl NetlinkRequest for RequestOpGetsetDumpRequest<'_> {
29669 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetsetDumpReply<'buf>);
29670 fn protocol(&self) -> Protocol {
29671 Protocol::Raw {
29672 protonum: 12u16,
29673 request_type: 2570u16,
29674 }
29675 }
29676 fn flags(&self) -> u16 {
29677 self.request.flags
29678 }
29679 fn payload(&self) -> &[u8] {
29680 self.request.buf()
29681 }
29682 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
29683 OpGetsetDumpReply::new(buf)
29684 }
29685 fn lookup(
29686 buf: &[u8],
29687 offset: usize,
29688 missing_type: Option<u16>,
29689 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
29690 OpGetsetDumpRequest::new(buf)
29691 .1
29692 .lookup_attr(offset, missing_type)
29693 }
29694}
29695#[doc = "Get / dump sets."]
29696pub struct PushOpGetsetDoRequest<Prev: Rec> {
29697 pub(crate) prev: Option<Prev>,
29698 pub(crate) header_offset: Option<usize>,
29699}
29700impl<Prev: Rec> Rec for PushOpGetsetDoRequest<Prev> {
29701 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
29702 self.prev.as_mut().unwrap().as_rec_mut()
29703 }
29704}
29705impl<Prev: Rec> PushOpGetsetDoRequest<Prev> {
29706 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
29707 Self::write_header(&mut prev, header);
29708 Self::new_without_header(prev)
29709 }
29710 fn new_without_header(prev: Prev) -> Self {
29711 Self {
29712 prev: Some(prev),
29713 header_offset: None,
29714 }
29715 }
29716 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
29717 prev.as_rec_mut().extend(header.as_slice());
29718 }
29719 pub fn end_nested(mut self) -> Prev {
29720 let mut prev = self.prev.take().unwrap();
29721 if let Some(header_offset) = &self.header_offset {
29722 finalize_nested_header(prev.as_rec_mut(), *header_offset);
29723 }
29724 prev
29725 }
29726 #[doc = "table name"]
29727 pub fn push_table(mut self, value: &CStr) -> Self {
29728 push_header(
29729 self.as_rec_mut(),
29730 1u16,
29731 value.to_bytes_with_nul().len() as u16,
29732 );
29733 self.as_rec_mut().extend(value.to_bytes_with_nul());
29734 self
29735 }
29736 #[doc = "table name"]
29737 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
29738 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
29739 self.as_rec_mut().extend(value);
29740 self.as_rec_mut().push(0);
29741 self
29742 }
29743 #[doc = "set name"]
29744 pub fn push_name(mut self, value: &CStr) -> Self {
29745 push_header(
29746 self.as_rec_mut(),
29747 2u16,
29748 value.to_bytes_with_nul().len() as u16,
29749 );
29750 self.as_rec_mut().extend(value.to_bytes_with_nul());
29751 self
29752 }
29753 #[doc = "set name"]
29754 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
29755 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
29756 self.as_rec_mut().extend(value);
29757 self.as_rec_mut().push(0);
29758 self
29759 }
29760}
29761impl<Prev: Rec> Drop for PushOpGetsetDoRequest<Prev> {
29762 fn drop(&mut self) {
29763 if let Some(prev) = &mut self.prev {
29764 if let Some(header_offset) = &self.header_offset {
29765 finalize_nested_header(prev.as_rec_mut(), *header_offset);
29766 }
29767 }
29768 }
29769}
29770#[doc = "Get / dump sets."]
29771#[derive(Clone)]
29772pub enum OpGetsetDoRequest<'a> {
29773 #[doc = "table name"]
29774 Table(&'a CStr),
29775 #[doc = "set name"]
29776 Name(&'a CStr),
29777}
29778impl<'a> IterableOpGetsetDoRequest<'a> {
29779 #[doc = "table name"]
29780 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
29781 let mut iter = self.clone();
29782 iter.pos = 0;
29783 for attr in iter {
29784 if let OpGetsetDoRequest::Table(val) = attr? {
29785 return Ok(val);
29786 }
29787 }
29788 Err(ErrorContext::new_missing(
29789 "OpGetsetDoRequest",
29790 "Table",
29791 self.orig_loc,
29792 self.buf.as_ptr() as usize,
29793 ))
29794 }
29795 #[doc = "set name"]
29796 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
29797 let mut iter = self.clone();
29798 iter.pos = 0;
29799 for attr in iter {
29800 if let OpGetsetDoRequest::Name(val) = attr? {
29801 return Ok(val);
29802 }
29803 }
29804 Err(ErrorContext::new_missing(
29805 "OpGetsetDoRequest",
29806 "Name",
29807 self.orig_loc,
29808 self.buf.as_ptr() as usize,
29809 ))
29810 }
29811}
29812impl<'a> OpGetsetDoRequest<'a> {
29813 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetDoRequest<'a>) {
29814 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
29815 (
29816 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
29817 IterableOpGetsetDoRequest::with_loc(attrs, buf.as_ptr() as usize),
29818 )
29819 }
29820 fn attr_from_type(r#type: u16) -> Option<&'static str> {
29821 SetAttrs::attr_from_type(r#type)
29822 }
29823}
29824#[derive(Clone, Copy, Default)]
29825pub struct IterableOpGetsetDoRequest<'a> {
29826 buf: &'a [u8],
29827 pos: usize,
29828 orig_loc: usize,
29829}
29830impl<'a> IterableOpGetsetDoRequest<'a> {
29831 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
29832 Self {
29833 buf,
29834 pos: 0,
29835 orig_loc,
29836 }
29837 }
29838 pub fn get_buf(&self) -> &'a [u8] {
29839 self.buf
29840 }
29841}
29842impl<'a> Iterator for IterableOpGetsetDoRequest<'a> {
29843 type Item = Result<OpGetsetDoRequest<'a>, ErrorContext>;
29844 fn next(&mut self) -> Option<Self::Item> {
29845 if self.buf.len() == self.pos {
29846 return None;
29847 }
29848 let pos = self.pos;
29849 let mut r#type = None;
29850 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
29851 r#type = Some(header.r#type);
29852 let res = match header.r#type {
29853 1u16 => OpGetsetDoRequest::Table({
29854 let res = CStr::from_bytes_with_nul(next).ok();
29855 let Some(val) = res else { break };
29856 val
29857 }),
29858 2u16 => OpGetsetDoRequest::Name({
29859 let res = CStr::from_bytes_with_nul(next).ok();
29860 let Some(val) = res else { break };
29861 val
29862 }),
29863 n => {
29864 if cfg!(any(test, feature = "deny-unknown-attrs")) {
29865 break;
29866 } else {
29867 continue;
29868 }
29869 }
29870 };
29871 return Some(Ok(res));
29872 }
29873 Some(Err(ErrorContext::new(
29874 "OpGetsetDoRequest",
29875 r#type.and_then(|t| OpGetsetDoRequest::attr_from_type(t)),
29876 self.orig_loc,
29877 self.buf.as_ptr().wrapping_add(pos) as usize,
29878 )))
29879 }
29880}
29881impl<'a> std::fmt::Debug for IterableOpGetsetDoRequest<'_> {
29882 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29883 let mut fmt = f.debug_struct("OpGetsetDoRequest");
29884 for attr in self.clone() {
29885 let attr = match attr {
29886 Ok(a) => a,
29887 Err(err) => {
29888 fmt.finish()?;
29889 f.write_str("Err(")?;
29890 err.fmt(f)?;
29891 return f.write_str(")");
29892 }
29893 };
29894 match attr {
29895 OpGetsetDoRequest::Table(val) => fmt.field("Table", &val),
29896 OpGetsetDoRequest::Name(val) => fmt.field("Name", &val),
29897 };
29898 }
29899 fmt.finish()
29900 }
29901}
29902impl IterableOpGetsetDoRequest<'_> {
29903 pub fn lookup_attr(
29904 &self,
29905 offset: usize,
29906 missing_type: Option<u16>,
29907 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
29908 let mut stack = Vec::new();
29909 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
29910 if cur == offset + PushNfgenmsg::len() {
29911 stack.push(("OpGetsetDoRequest", offset));
29912 return (
29913 stack,
29914 missing_type.and_then(|t| OpGetsetDoRequest::attr_from_type(t)),
29915 );
29916 }
29917 if cur > offset || cur + self.buf.len() < offset {
29918 return (stack, None);
29919 }
29920 let mut attrs = self.clone();
29921 let mut last_off = cur + attrs.pos;
29922 while let Some(attr) = attrs.next() {
29923 let Ok(attr) = attr else { break };
29924 match attr {
29925 OpGetsetDoRequest::Table(val) => {
29926 if last_off == offset {
29927 stack.push(("Table", last_off));
29928 break;
29929 }
29930 }
29931 OpGetsetDoRequest::Name(val) => {
29932 if last_off == offset {
29933 stack.push(("Name", last_off));
29934 break;
29935 }
29936 }
29937 _ => {}
29938 };
29939 last_off = cur + attrs.pos;
29940 }
29941 if !stack.is_empty() {
29942 stack.push(("OpGetsetDoRequest", cur));
29943 }
29944 (stack, None)
29945 }
29946}
29947#[doc = "Get / dump sets."]
29948pub struct PushOpGetsetDoReply<Prev: Rec> {
29949 pub(crate) prev: Option<Prev>,
29950 pub(crate) header_offset: Option<usize>,
29951}
29952impl<Prev: Rec> Rec for PushOpGetsetDoReply<Prev> {
29953 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
29954 self.prev.as_mut().unwrap().as_rec_mut()
29955 }
29956}
29957impl<Prev: Rec> PushOpGetsetDoReply<Prev> {
29958 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
29959 Self::write_header(&mut prev, header);
29960 Self::new_without_header(prev)
29961 }
29962 fn new_without_header(prev: Prev) -> Self {
29963 Self {
29964 prev: Some(prev),
29965 header_offset: None,
29966 }
29967 }
29968 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
29969 prev.as_rec_mut().extend(header.as_slice());
29970 }
29971 pub fn end_nested(mut self) -> Prev {
29972 let mut prev = self.prev.take().unwrap();
29973 if let Some(header_offset) = &self.header_offset {
29974 finalize_nested_header(prev.as_rec_mut(), *header_offset);
29975 }
29976 prev
29977 }
29978 #[doc = "table name"]
29979 pub fn push_table(mut self, value: &CStr) -> Self {
29980 push_header(
29981 self.as_rec_mut(),
29982 1u16,
29983 value.to_bytes_with_nul().len() as u16,
29984 );
29985 self.as_rec_mut().extend(value.to_bytes_with_nul());
29986 self
29987 }
29988 #[doc = "table name"]
29989 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
29990 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
29991 self.as_rec_mut().extend(value);
29992 self.as_rec_mut().push(0);
29993 self
29994 }
29995 #[doc = "set name"]
29996 pub fn push_name(mut self, value: &CStr) -> Self {
29997 push_header(
29998 self.as_rec_mut(),
29999 2u16,
30000 value.to_bytes_with_nul().len() as u16,
30001 );
30002 self.as_rec_mut().extend(value.to_bytes_with_nul());
30003 self
30004 }
30005 #[doc = "set name"]
30006 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
30007 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
30008 self.as_rec_mut().extend(value);
30009 self.as_rec_mut().push(0);
30010 self
30011 }
30012 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
30013 pub fn push_flags(mut self, value: u32) -> Self {
30014 push_header(self.as_rec_mut(), 3u16, 4 as u16);
30015 self.as_rec_mut().extend(value.to_be_bytes());
30016 self
30017 }
30018 #[doc = "key data type, informational purpose only"]
30019 pub fn push_key_type(mut self, value: u32) -> Self {
30020 push_header(self.as_rec_mut(), 4u16, 4 as u16);
30021 self.as_rec_mut().extend(value.to_be_bytes());
30022 self
30023 }
30024 #[doc = "key data length"]
30025 pub fn push_key_len(mut self, value: u32) -> Self {
30026 push_header(self.as_rec_mut(), 5u16, 4 as u16);
30027 self.as_rec_mut().extend(value.to_be_bytes());
30028 self
30029 }
30030 #[doc = "mapping data type"]
30031 pub fn push_data_type(mut self, value: u32) -> Self {
30032 push_header(self.as_rec_mut(), 6u16, 4 as u16);
30033 self.as_rec_mut().extend(value.to_be_bytes());
30034 self
30035 }
30036 #[doc = "mapping data length"]
30037 pub fn push_data_len(mut self, value: u32) -> Self {
30038 push_header(self.as_rec_mut(), 7u16, 4 as u16);
30039 self.as_rec_mut().extend(value.to_be_bytes());
30040 self
30041 }
30042 #[doc = "selection policy"]
30043 pub fn push_policy(mut self, value: u32) -> Self {
30044 push_header(self.as_rec_mut(), 8u16, 4 as u16);
30045 self.as_rec_mut().extend(value.to_be_bytes());
30046 self
30047 }
30048 #[doc = "set description"]
30049 pub fn nested_desc(mut self) -> PushSetDescAttrs<Self> {
30050 let header_offset = push_nested_header(self.as_rec_mut(), 9u16);
30051 PushSetDescAttrs {
30052 prev: Some(self),
30053 header_offset: Some(header_offset),
30054 }
30055 }
30056 #[doc = "garbage collection interval"]
30057 pub fn push_gc_interval(mut self, value: u32) -> Self {
30058 push_header(self.as_rec_mut(), 12u16, 4 as u16);
30059 self.as_rec_mut().extend(value.to_ne_bytes());
30060 self
30061 }
30062 #[doc = "user data"]
30063 pub fn push_userdata(mut self, value: &[u8]) -> Self {
30064 push_header(self.as_rec_mut(), 13u16, value.len() as u16);
30065 self.as_rec_mut().extend(value);
30066 self
30067 }
30068 #[doc = "stateful object type"]
30069 pub fn push_obj_type(mut self, value: u32) -> Self {
30070 push_header(self.as_rec_mut(), 15u16, 4 as u16);
30071 self.as_rec_mut().extend(value.to_be_bytes());
30072 self
30073 }
30074 #[doc = "set handle"]
30075 pub fn push_handle(mut self, value: u64) -> Self {
30076 push_header(self.as_rec_mut(), 16u16, 8 as u16);
30077 self.as_rec_mut().extend(value.to_be_bytes());
30078 self
30079 }
30080 #[doc = "set expression\nAttribute may repeat multiple times (treat it as array)"]
30081 pub fn nested_expr(mut self) -> PushExprAttrs<Self> {
30082 let header_offset = push_nested_header(self.as_rec_mut(), 17u16);
30083 PushExprAttrs {
30084 prev: Some(self),
30085 header_offset: Some(header_offset),
30086 }
30087 }
30088 #[doc = "list of expressions"]
30089 pub fn nested_expressions(mut self) -> PushSetListAttrs<Self> {
30090 let header_offset = push_nested_header(self.as_rec_mut(), 18u16);
30091 PushSetListAttrs {
30092 prev: Some(self),
30093 header_offset: Some(header_offset),
30094 }
30095 }
30096}
30097impl<Prev: Rec> Drop for PushOpGetsetDoReply<Prev> {
30098 fn drop(&mut self) {
30099 if let Some(prev) = &mut self.prev {
30100 if let Some(header_offset) = &self.header_offset {
30101 finalize_nested_header(prev.as_rec_mut(), *header_offset);
30102 }
30103 }
30104 }
30105}
30106#[doc = "Get / dump sets."]
30107#[derive(Clone)]
30108pub enum OpGetsetDoReply<'a> {
30109 #[doc = "table name"]
30110 Table(&'a CStr),
30111 #[doc = "set name"]
30112 Name(&'a CStr),
30113 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
30114 Flags(u32),
30115 #[doc = "key data type, informational purpose only"]
30116 KeyType(u32),
30117 #[doc = "key data length"]
30118 KeyLen(u32),
30119 #[doc = "mapping data type"]
30120 DataType(u32),
30121 #[doc = "mapping data length"]
30122 DataLen(u32),
30123 #[doc = "selection policy"]
30124 Policy(u32),
30125 #[doc = "set description"]
30126 Desc(IterableSetDescAttrs<'a>),
30127 #[doc = "garbage collection interval"]
30128 GcInterval(u32),
30129 #[doc = "user data"]
30130 Userdata(&'a [u8]),
30131 #[doc = "stateful object type"]
30132 ObjType(u32),
30133 #[doc = "set handle"]
30134 Handle(u64),
30135 #[doc = "set expression\nAttribute may repeat multiple times (treat it as array)"]
30136 Expr(IterableExprAttrs<'a>),
30137 #[doc = "list of expressions"]
30138 Expressions(IterableSetListAttrs<'a>),
30139}
30140impl<'a> IterableOpGetsetDoReply<'a> {
30141 #[doc = "table name"]
30142 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
30143 let mut iter = self.clone();
30144 iter.pos = 0;
30145 for attr in iter {
30146 if let OpGetsetDoReply::Table(val) = attr? {
30147 return Ok(val);
30148 }
30149 }
30150 Err(ErrorContext::new_missing(
30151 "OpGetsetDoReply",
30152 "Table",
30153 self.orig_loc,
30154 self.buf.as_ptr() as usize,
30155 ))
30156 }
30157 #[doc = "set name"]
30158 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
30159 let mut iter = self.clone();
30160 iter.pos = 0;
30161 for attr in iter {
30162 if let OpGetsetDoReply::Name(val) = attr? {
30163 return Ok(val);
30164 }
30165 }
30166 Err(ErrorContext::new_missing(
30167 "OpGetsetDoReply",
30168 "Name",
30169 self.orig_loc,
30170 self.buf.as_ptr() as usize,
30171 ))
30172 }
30173 #[doc = "bitmask of enum nft_set_flags\nAssociated type: \"SetFlags\" (enum)"]
30174 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
30175 let mut iter = self.clone();
30176 iter.pos = 0;
30177 for attr in iter {
30178 if let OpGetsetDoReply::Flags(val) = attr? {
30179 return Ok(val);
30180 }
30181 }
30182 Err(ErrorContext::new_missing(
30183 "OpGetsetDoReply",
30184 "Flags",
30185 self.orig_loc,
30186 self.buf.as_ptr() as usize,
30187 ))
30188 }
30189 #[doc = "key data type, informational purpose only"]
30190 pub fn get_key_type(&self) -> Result<u32, ErrorContext> {
30191 let mut iter = self.clone();
30192 iter.pos = 0;
30193 for attr in iter {
30194 if let OpGetsetDoReply::KeyType(val) = attr? {
30195 return Ok(val);
30196 }
30197 }
30198 Err(ErrorContext::new_missing(
30199 "OpGetsetDoReply",
30200 "KeyType",
30201 self.orig_loc,
30202 self.buf.as_ptr() as usize,
30203 ))
30204 }
30205 #[doc = "key data length"]
30206 pub fn get_key_len(&self) -> Result<u32, ErrorContext> {
30207 let mut iter = self.clone();
30208 iter.pos = 0;
30209 for attr in iter {
30210 if let OpGetsetDoReply::KeyLen(val) = attr? {
30211 return Ok(val);
30212 }
30213 }
30214 Err(ErrorContext::new_missing(
30215 "OpGetsetDoReply",
30216 "KeyLen",
30217 self.orig_loc,
30218 self.buf.as_ptr() as usize,
30219 ))
30220 }
30221 #[doc = "mapping data type"]
30222 pub fn get_data_type(&self) -> Result<u32, ErrorContext> {
30223 let mut iter = self.clone();
30224 iter.pos = 0;
30225 for attr in iter {
30226 if let OpGetsetDoReply::DataType(val) = attr? {
30227 return Ok(val);
30228 }
30229 }
30230 Err(ErrorContext::new_missing(
30231 "OpGetsetDoReply",
30232 "DataType",
30233 self.orig_loc,
30234 self.buf.as_ptr() as usize,
30235 ))
30236 }
30237 #[doc = "mapping data length"]
30238 pub fn get_data_len(&self) -> Result<u32, ErrorContext> {
30239 let mut iter = self.clone();
30240 iter.pos = 0;
30241 for attr in iter {
30242 if let OpGetsetDoReply::DataLen(val) = attr? {
30243 return Ok(val);
30244 }
30245 }
30246 Err(ErrorContext::new_missing(
30247 "OpGetsetDoReply",
30248 "DataLen",
30249 self.orig_loc,
30250 self.buf.as_ptr() as usize,
30251 ))
30252 }
30253 #[doc = "selection policy"]
30254 pub fn get_policy(&self) -> Result<u32, ErrorContext> {
30255 let mut iter = self.clone();
30256 iter.pos = 0;
30257 for attr in iter {
30258 if let OpGetsetDoReply::Policy(val) = attr? {
30259 return Ok(val);
30260 }
30261 }
30262 Err(ErrorContext::new_missing(
30263 "OpGetsetDoReply",
30264 "Policy",
30265 self.orig_loc,
30266 self.buf.as_ptr() as usize,
30267 ))
30268 }
30269 #[doc = "set description"]
30270 pub fn get_desc(&self) -> Result<IterableSetDescAttrs<'a>, ErrorContext> {
30271 let mut iter = self.clone();
30272 iter.pos = 0;
30273 for attr in iter {
30274 if let OpGetsetDoReply::Desc(val) = attr? {
30275 return Ok(val);
30276 }
30277 }
30278 Err(ErrorContext::new_missing(
30279 "OpGetsetDoReply",
30280 "Desc",
30281 self.orig_loc,
30282 self.buf.as_ptr() as usize,
30283 ))
30284 }
30285 #[doc = "garbage collection interval"]
30286 pub fn get_gc_interval(&self) -> Result<u32, ErrorContext> {
30287 let mut iter = self.clone();
30288 iter.pos = 0;
30289 for attr in iter {
30290 if let OpGetsetDoReply::GcInterval(val) = attr? {
30291 return Ok(val);
30292 }
30293 }
30294 Err(ErrorContext::new_missing(
30295 "OpGetsetDoReply",
30296 "GcInterval",
30297 self.orig_loc,
30298 self.buf.as_ptr() as usize,
30299 ))
30300 }
30301 #[doc = "user data"]
30302 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
30303 let mut iter = self.clone();
30304 iter.pos = 0;
30305 for attr in iter {
30306 if let OpGetsetDoReply::Userdata(val) = attr? {
30307 return Ok(val);
30308 }
30309 }
30310 Err(ErrorContext::new_missing(
30311 "OpGetsetDoReply",
30312 "Userdata",
30313 self.orig_loc,
30314 self.buf.as_ptr() as usize,
30315 ))
30316 }
30317 #[doc = "stateful object type"]
30318 pub fn get_obj_type(&self) -> Result<u32, ErrorContext> {
30319 let mut iter = self.clone();
30320 iter.pos = 0;
30321 for attr in iter {
30322 if let OpGetsetDoReply::ObjType(val) = attr? {
30323 return Ok(val);
30324 }
30325 }
30326 Err(ErrorContext::new_missing(
30327 "OpGetsetDoReply",
30328 "ObjType",
30329 self.orig_loc,
30330 self.buf.as_ptr() as usize,
30331 ))
30332 }
30333 #[doc = "set handle"]
30334 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
30335 let mut iter = self.clone();
30336 iter.pos = 0;
30337 for attr in iter {
30338 if let OpGetsetDoReply::Handle(val) = attr? {
30339 return Ok(val);
30340 }
30341 }
30342 Err(ErrorContext::new_missing(
30343 "OpGetsetDoReply",
30344 "Handle",
30345 self.orig_loc,
30346 self.buf.as_ptr() as usize,
30347 ))
30348 }
30349 #[doc = "set expression\nAttribute may repeat multiple times (treat it as array)"]
30350 pub fn get_expr(&self) -> MultiAttrIterable<Self, OpGetsetDoReply<'a>, IterableExprAttrs<'a>> {
30351 MultiAttrIterable::new(self.clone(), |variant| {
30352 if let OpGetsetDoReply::Expr(val) = variant {
30353 Some(val)
30354 } else {
30355 None
30356 }
30357 })
30358 }
30359 #[doc = "list of expressions"]
30360 pub fn get_expressions(&self) -> Result<IterableSetListAttrs<'a>, ErrorContext> {
30361 let mut iter = self.clone();
30362 iter.pos = 0;
30363 for attr in iter {
30364 if let OpGetsetDoReply::Expressions(val) = attr? {
30365 return Ok(val);
30366 }
30367 }
30368 Err(ErrorContext::new_missing(
30369 "OpGetsetDoReply",
30370 "Expressions",
30371 self.orig_loc,
30372 self.buf.as_ptr() as usize,
30373 ))
30374 }
30375}
30376impl<'a> OpGetsetDoReply<'a> {
30377 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetDoReply<'a>) {
30378 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
30379 (
30380 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
30381 IterableOpGetsetDoReply::with_loc(attrs, buf.as_ptr() as usize),
30382 )
30383 }
30384 fn attr_from_type(r#type: u16) -> Option<&'static str> {
30385 SetAttrs::attr_from_type(r#type)
30386 }
30387}
30388#[derive(Clone, Copy, Default)]
30389pub struct IterableOpGetsetDoReply<'a> {
30390 buf: &'a [u8],
30391 pos: usize,
30392 orig_loc: usize,
30393}
30394impl<'a> IterableOpGetsetDoReply<'a> {
30395 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
30396 Self {
30397 buf,
30398 pos: 0,
30399 orig_loc,
30400 }
30401 }
30402 pub fn get_buf(&self) -> &'a [u8] {
30403 self.buf
30404 }
30405}
30406impl<'a> Iterator for IterableOpGetsetDoReply<'a> {
30407 type Item = Result<OpGetsetDoReply<'a>, ErrorContext>;
30408 fn next(&mut self) -> Option<Self::Item> {
30409 if self.buf.len() == self.pos {
30410 return None;
30411 }
30412 let pos = self.pos;
30413 let mut r#type = None;
30414 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
30415 r#type = Some(header.r#type);
30416 let res = match header.r#type {
30417 1u16 => OpGetsetDoReply::Table({
30418 let res = CStr::from_bytes_with_nul(next).ok();
30419 let Some(val) = res else { break };
30420 val
30421 }),
30422 2u16 => OpGetsetDoReply::Name({
30423 let res = CStr::from_bytes_with_nul(next).ok();
30424 let Some(val) = res else { break };
30425 val
30426 }),
30427 3u16 => OpGetsetDoReply::Flags({
30428 let res = parse_be_u32(next);
30429 let Some(val) = res else { break };
30430 val
30431 }),
30432 4u16 => OpGetsetDoReply::KeyType({
30433 let res = parse_be_u32(next);
30434 let Some(val) = res else { break };
30435 val
30436 }),
30437 5u16 => OpGetsetDoReply::KeyLen({
30438 let res = parse_be_u32(next);
30439 let Some(val) = res else { break };
30440 val
30441 }),
30442 6u16 => OpGetsetDoReply::DataType({
30443 let res = parse_be_u32(next);
30444 let Some(val) = res else { break };
30445 val
30446 }),
30447 7u16 => OpGetsetDoReply::DataLen({
30448 let res = parse_be_u32(next);
30449 let Some(val) = res else { break };
30450 val
30451 }),
30452 8u16 => OpGetsetDoReply::Policy({
30453 let res = parse_be_u32(next);
30454 let Some(val) = res else { break };
30455 val
30456 }),
30457 9u16 => OpGetsetDoReply::Desc({
30458 let res = Some(IterableSetDescAttrs::with_loc(next, self.orig_loc));
30459 let Some(val) = res else { break };
30460 val
30461 }),
30462 12u16 => OpGetsetDoReply::GcInterval({
30463 let res = parse_u32(next);
30464 let Some(val) = res else { break };
30465 val
30466 }),
30467 13u16 => OpGetsetDoReply::Userdata({
30468 let res = Some(next);
30469 let Some(val) = res else { break };
30470 val
30471 }),
30472 15u16 => OpGetsetDoReply::ObjType({
30473 let res = parse_be_u32(next);
30474 let Some(val) = res else { break };
30475 val
30476 }),
30477 16u16 => OpGetsetDoReply::Handle({
30478 let res = parse_be_u64(next);
30479 let Some(val) = res else { break };
30480 val
30481 }),
30482 17u16 => OpGetsetDoReply::Expr({
30483 let res = Some(IterableExprAttrs::with_loc(next, self.orig_loc));
30484 let Some(val) = res else { break };
30485 val
30486 }),
30487 18u16 => OpGetsetDoReply::Expressions({
30488 let res = Some(IterableSetListAttrs::with_loc(next, self.orig_loc));
30489 let Some(val) = res else { break };
30490 val
30491 }),
30492 n => {
30493 if cfg!(any(test, feature = "deny-unknown-attrs")) {
30494 break;
30495 } else {
30496 continue;
30497 }
30498 }
30499 };
30500 return Some(Ok(res));
30501 }
30502 Some(Err(ErrorContext::new(
30503 "OpGetsetDoReply",
30504 r#type.and_then(|t| OpGetsetDoReply::attr_from_type(t)),
30505 self.orig_loc,
30506 self.buf.as_ptr().wrapping_add(pos) as usize,
30507 )))
30508 }
30509}
30510impl<'a> std::fmt::Debug for IterableOpGetsetDoReply<'_> {
30511 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30512 let mut fmt = f.debug_struct("OpGetsetDoReply");
30513 for attr in self.clone() {
30514 let attr = match attr {
30515 Ok(a) => a,
30516 Err(err) => {
30517 fmt.finish()?;
30518 f.write_str("Err(")?;
30519 err.fmt(f)?;
30520 return f.write_str(")");
30521 }
30522 };
30523 match attr {
30524 OpGetsetDoReply::Table(val) => fmt.field("Table", &val),
30525 OpGetsetDoReply::Name(val) => fmt.field("Name", &val),
30526 OpGetsetDoReply::Flags(val) => {
30527 fmt.field("Flags", &FormatFlags(val.into(), SetFlags::from_value))
30528 }
30529 OpGetsetDoReply::KeyType(val) => fmt.field("KeyType", &val),
30530 OpGetsetDoReply::KeyLen(val) => fmt.field("KeyLen", &val),
30531 OpGetsetDoReply::DataType(val) => fmt.field("DataType", &val),
30532 OpGetsetDoReply::DataLen(val) => fmt.field("DataLen", &val),
30533 OpGetsetDoReply::Policy(val) => fmt.field("Policy", &val),
30534 OpGetsetDoReply::Desc(val) => fmt.field("Desc", &val),
30535 OpGetsetDoReply::GcInterval(val) => fmt.field("GcInterval", &val),
30536 OpGetsetDoReply::Userdata(val) => fmt.field("Userdata", &val),
30537 OpGetsetDoReply::ObjType(val) => fmt.field("ObjType", &val),
30538 OpGetsetDoReply::Handle(val) => fmt.field("Handle", &val),
30539 OpGetsetDoReply::Expr(val) => fmt.field("Expr", &val),
30540 OpGetsetDoReply::Expressions(val) => fmt.field("Expressions", &val),
30541 };
30542 }
30543 fmt.finish()
30544 }
30545}
30546impl IterableOpGetsetDoReply<'_> {
30547 pub fn lookup_attr(
30548 &self,
30549 offset: usize,
30550 missing_type: Option<u16>,
30551 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
30552 let mut stack = Vec::new();
30553 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
30554 if cur == offset + PushNfgenmsg::len() {
30555 stack.push(("OpGetsetDoReply", offset));
30556 return (
30557 stack,
30558 missing_type.and_then(|t| OpGetsetDoReply::attr_from_type(t)),
30559 );
30560 }
30561 if cur > offset || cur + self.buf.len() < offset {
30562 return (stack, None);
30563 }
30564 let mut attrs = self.clone();
30565 let mut last_off = cur + attrs.pos;
30566 let mut missing = None;
30567 while let Some(attr) = attrs.next() {
30568 let Ok(attr) = attr else { break };
30569 match attr {
30570 OpGetsetDoReply::Table(val) => {
30571 if last_off == offset {
30572 stack.push(("Table", last_off));
30573 break;
30574 }
30575 }
30576 OpGetsetDoReply::Name(val) => {
30577 if last_off == offset {
30578 stack.push(("Name", last_off));
30579 break;
30580 }
30581 }
30582 OpGetsetDoReply::Flags(val) => {
30583 if last_off == offset {
30584 stack.push(("Flags", last_off));
30585 break;
30586 }
30587 }
30588 OpGetsetDoReply::KeyType(val) => {
30589 if last_off == offset {
30590 stack.push(("KeyType", last_off));
30591 break;
30592 }
30593 }
30594 OpGetsetDoReply::KeyLen(val) => {
30595 if last_off == offset {
30596 stack.push(("KeyLen", last_off));
30597 break;
30598 }
30599 }
30600 OpGetsetDoReply::DataType(val) => {
30601 if last_off == offset {
30602 stack.push(("DataType", last_off));
30603 break;
30604 }
30605 }
30606 OpGetsetDoReply::DataLen(val) => {
30607 if last_off == offset {
30608 stack.push(("DataLen", last_off));
30609 break;
30610 }
30611 }
30612 OpGetsetDoReply::Policy(val) => {
30613 if last_off == offset {
30614 stack.push(("Policy", last_off));
30615 break;
30616 }
30617 }
30618 OpGetsetDoReply::Desc(val) => {
30619 (stack, missing) = val.lookup_attr(offset, missing_type);
30620 if !stack.is_empty() {
30621 break;
30622 }
30623 }
30624 OpGetsetDoReply::GcInterval(val) => {
30625 if last_off == offset {
30626 stack.push(("GcInterval", last_off));
30627 break;
30628 }
30629 }
30630 OpGetsetDoReply::Userdata(val) => {
30631 if last_off == offset {
30632 stack.push(("Userdata", last_off));
30633 break;
30634 }
30635 }
30636 OpGetsetDoReply::ObjType(val) => {
30637 if last_off == offset {
30638 stack.push(("ObjType", last_off));
30639 break;
30640 }
30641 }
30642 OpGetsetDoReply::Handle(val) => {
30643 if last_off == offset {
30644 stack.push(("Handle", last_off));
30645 break;
30646 }
30647 }
30648 OpGetsetDoReply::Expr(val) => {
30649 (stack, missing) = val.lookup_attr(offset, missing_type);
30650 if !stack.is_empty() {
30651 break;
30652 }
30653 }
30654 OpGetsetDoReply::Expressions(val) => {
30655 (stack, missing) = val.lookup_attr(offset, missing_type);
30656 if !stack.is_empty() {
30657 break;
30658 }
30659 }
30660 _ => {}
30661 };
30662 last_off = cur + attrs.pos;
30663 }
30664 if !stack.is_empty() {
30665 stack.push(("OpGetsetDoReply", cur));
30666 }
30667 (stack, missing)
30668 }
30669}
30670#[derive(Debug)]
30671pub struct RequestOpGetsetDoRequest<'r> {
30672 request: Request<'r>,
30673}
30674impl<'r> RequestOpGetsetDoRequest<'r> {
30675 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
30676 PushOpGetsetDoRequest::write_header(&mut request.buf_mut(), header);
30677 Self { request: request }
30678 }
30679 pub fn encode(&mut self) -> PushOpGetsetDoRequest<&mut Vec<u8>> {
30680 PushOpGetsetDoRequest::new_without_header(self.request.buf_mut())
30681 }
30682 pub fn into_encoder(self) -> PushOpGetsetDoRequest<RequestBuf<'r>> {
30683 PushOpGetsetDoRequest::new_without_header(self.request.buf)
30684 }
30685}
30686impl NetlinkRequest for RequestOpGetsetDoRequest<'_> {
30687 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetsetDoReply<'buf>);
30688 fn protocol(&self) -> Protocol {
30689 Protocol::Raw {
30690 protonum: 12u16,
30691 request_type: 2570u16,
30692 }
30693 }
30694 fn flags(&self) -> u16 {
30695 self.request.flags
30696 }
30697 fn payload(&self) -> &[u8] {
30698 self.request.buf()
30699 }
30700 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
30701 OpGetsetDoReply::new(buf)
30702 }
30703 fn lookup(
30704 buf: &[u8],
30705 offset: usize,
30706 missing_type: Option<u16>,
30707 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
30708 OpGetsetDoRequest::new(buf)
30709 .1
30710 .lookup_attr(offset, missing_type)
30711 }
30712}
30713#[doc = "Delete an existing set."]
30714pub struct PushOpDelsetDoRequest<Prev: Rec> {
30715 pub(crate) prev: Option<Prev>,
30716 pub(crate) header_offset: Option<usize>,
30717}
30718impl<Prev: Rec> Rec for PushOpDelsetDoRequest<Prev> {
30719 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
30720 self.prev.as_mut().unwrap().as_rec_mut()
30721 }
30722}
30723impl<Prev: Rec> PushOpDelsetDoRequest<Prev> {
30724 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
30725 Self::write_header(&mut prev, header);
30726 Self::new_without_header(prev)
30727 }
30728 fn new_without_header(prev: Prev) -> Self {
30729 Self {
30730 prev: Some(prev),
30731 header_offset: None,
30732 }
30733 }
30734 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
30735 prev.as_rec_mut().extend(header.as_slice());
30736 }
30737 pub fn end_nested(mut self) -> Prev {
30738 let mut prev = self.prev.take().unwrap();
30739 if let Some(header_offset) = &self.header_offset {
30740 finalize_nested_header(prev.as_rec_mut(), *header_offset);
30741 }
30742 prev
30743 }
30744 #[doc = "table name"]
30745 pub fn push_table(mut self, value: &CStr) -> Self {
30746 push_header(
30747 self.as_rec_mut(),
30748 1u16,
30749 value.to_bytes_with_nul().len() as u16,
30750 );
30751 self.as_rec_mut().extend(value.to_bytes_with_nul());
30752 self
30753 }
30754 #[doc = "table name"]
30755 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
30756 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
30757 self.as_rec_mut().extend(value);
30758 self.as_rec_mut().push(0);
30759 self
30760 }
30761 #[doc = "set name"]
30762 pub fn push_name(mut self, value: &CStr) -> Self {
30763 push_header(
30764 self.as_rec_mut(),
30765 2u16,
30766 value.to_bytes_with_nul().len() as u16,
30767 );
30768 self.as_rec_mut().extend(value.to_bytes_with_nul());
30769 self
30770 }
30771 #[doc = "set name"]
30772 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
30773 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
30774 self.as_rec_mut().extend(value);
30775 self.as_rec_mut().push(0);
30776 self
30777 }
30778 #[doc = "set handle"]
30779 pub fn push_handle(mut self, value: u64) -> Self {
30780 push_header(self.as_rec_mut(), 16u16, 8 as u16);
30781 self.as_rec_mut().extend(value.to_be_bytes());
30782 self
30783 }
30784}
30785impl<Prev: Rec> Drop for PushOpDelsetDoRequest<Prev> {
30786 fn drop(&mut self) {
30787 if let Some(prev) = &mut self.prev {
30788 if let Some(header_offset) = &self.header_offset {
30789 finalize_nested_header(prev.as_rec_mut(), *header_offset);
30790 }
30791 }
30792 }
30793}
30794#[doc = "Delete an existing set."]
30795#[derive(Clone)]
30796pub enum OpDelsetDoRequest<'a> {
30797 #[doc = "table name"]
30798 Table(&'a CStr),
30799 #[doc = "set name"]
30800 Name(&'a CStr),
30801 #[doc = "set handle"]
30802 Handle(u64),
30803}
30804impl<'a> IterableOpDelsetDoRequest<'a> {
30805 #[doc = "table name"]
30806 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
30807 let mut iter = self.clone();
30808 iter.pos = 0;
30809 for attr in iter {
30810 if let OpDelsetDoRequest::Table(val) = attr? {
30811 return Ok(val);
30812 }
30813 }
30814 Err(ErrorContext::new_missing(
30815 "OpDelsetDoRequest",
30816 "Table",
30817 self.orig_loc,
30818 self.buf.as_ptr() as usize,
30819 ))
30820 }
30821 #[doc = "set name"]
30822 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
30823 let mut iter = self.clone();
30824 iter.pos = 0;
30825 for attr in iter {
30826 if let OpDelsetDoRequest::Name(val) = attr? {
30827 return Ok(val);
30828 }
30829 }
30830 Err(ErrorContext::new_missing(
30831 "OpDelsetDoRequest",
30832 "Name",
30833 self.orig_loc,
30834 self.buf.as_ptr() as usize,
30835 ))
30836 }
30837 #[doc = "set handle"]
30838 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
30839 let mut iter = self.clone();
30840 iter.pos = 0;
30841 for attr in iter {
30842 if let OpDelsetDoRequest::Handle(val) = attr? {
30843 return Ok(val);
30844 }
30845 }
30846 Err(ErrorContext::new_missing(
30847 "OpDelsetDoRequest",
30848 "Handle",
30849 self.orig_loc,
30850 self.buf.as_ptr() as usize,
30851 ))
30852 }
30853}
30854impl<'a> OpDelsetDoRequest<'a> {
30855 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDelsetDoRequest<'a>) {
30856 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
30857 (
30858 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
30859 IterableOpDelsetDoRequest::with_loc(attrs, buf.as_ptr() as usize),
30860 )
30861 }
30862 fn attr_from_type(r#type: u16) -> Option<&'static str> {
30863 SetAttrs::attr_from_type(r#type)
30864 }
30865}
30866#[derive(Clone, Copy, Default)]
30867pub struct IterableOpDelsetDoRequest<'a> {
30868 buf: &'a [u8],
30869 pos: usize,
30870 orig_loc: usize,
30871}
30872impl<'a> IterableOpDelsetDoRequest<'a> {
30873 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
30874 Self {
30875 buf,
30876 pos: 0,
30877 orig_loc,
30878 }
30879 }
30880 pub fn get_buf(&self) -> &'a [u8] {
30881 self.buf
30882 }
30883}
30884impl<'a> Iterator for IterableOpDelsetDoRequest<'a> {
30885 type Item = Result<OpDelsetDoRequest<'a>, ErrorContext>;
30886 fn next(&mut self) -> Option<Self::Item> {
30887 if self.buf.len() == self.pos {
30888 return None;
30889 }
30890 let pos = self.pos;
30891 let mut r#type = None;
30892 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
30893 r#type = Some(header.r#type);
30894 let res = match header.r#type {
30895 1u16 => OpDelsetDoRequest::Table({
30896 let res = CStr::from_bytes_with_nul(next).ok();
30897 let Some(val) = res else { break };
30898 val
30899 }),
30900 2u16 => OpDelsetDoRequest::Name({
30901 let res = CStr::from_bytes_with_nul(next).ok();
30902 let Some(val) = res else { break };
30903 val
30904 }),
30905 16u16 => OpDelsetDoRequest::Handle({
30906 let res = parse_be_u64(next);
30907 let Some(val) = res else { break };
30908 val
30909 }),
30910 n => {
30911 if cfg!(any(test, feature = "deny-unknown-attrs")) {
30912 break;
30913 } else {
30914 continue;
30915 }
30916 }
30917 };
30918 return Some(Ok(res));
30919 }
30920 Some(Err(ErrorContext::new(
30921 "OpDelsetDoRequest",
30922 r#type.and_then(|t| OpDelsetDoRequest::attr_from_type(t)),
30923 self.orig_loc,
30924 self.buf.as_ptr().wrapping_add(pos) as usize,
30925 )))
30926 }
30927}
30928impl<'a> std::fmt::Debug for IterableOpDelsetDoRequest<'_> {
30929 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30930 let mut fmt = f.debug_struct("OpDelsetDoRequest");
30931 for attr in self.clone() {
30932 let attr = match attr {
30933 Ok(a) => a,
30934 Err(err) => {
30935 fmt.finish()?;
30936 f.write_str("Err(")?;
30937 err.fmt(f)?;
30938 return f.write_str(")");
30939 }
30940 };
30941 match attr {
30942 OpDelsetDoRequest::Table(val) => fmt.field("Table", &val),
30943 OpDelsetDoRequest::Name(val) => fmt.field("Name", &val),
30944 OpDelsetDoRequest::Handle(val) => fmt.field("Handle", &val),
30945 };
30946 }
30947 fmt.finish()
30948 }
30949}
30950impl IterableOpDelsetDoRequest<'_> {
30951 pub fn lookup_attr(
30952 &self,
30953 offset: usize,
30954 missing_type: Option<u16>,
30955 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
30956 let mut stack = Vec::new();
30957 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
30958 if cur == offset + PushNfgenmsg::len() {
30959 stack.push(("OpDelsetDoRequest", offset));
30960 return (
30961 stack,
30962 missing_type.and_then(|t| OpDelsetDoRequest::attr_from_type(t)),
30963 );
30964 }
30965 if cur > offset || cur + self.buf.len() < offset {
30966 return (stack, None);
30967 }
30968 let mut attrs = self.clone();
30969 let mut last_off = cur + attrs.pos;
30970 while let Some(attr) = attrs.next() {
30971 let Ok(attr) = attr else { break };
30972 match attr {
30973 OpDelsetDoRequest::Table(val) => {
30974 if last_off == offset {
30975 stack.push(("Table", last_off));
30976 break;
30977 }
30978 }
30979 OpDelsetDoRequest::Name(val) => {
30980 if last_off == offset {
30981 stack.push(("Name", last_off));
30982 break;
30983 }
30984 }
30985 OpDelsetDoRequest::Handle(val) => {
30986 if last_off == offset {
30987 stack.push(("Handle", last_off));
30988 break;
30989 }
30990 }
30991 _ => {}
30992 };
30993 last_off = cur + attrs.pos;
30994 }
30995 if !stack.is_empty() {
30996 stack.push(("OpDelsetDoRequest", cur));
30997 }
30998 (stack, None)
30999 }
31000}
31001#[doc = "Delete an existing set."]
31002pub struct PushOpDelsetDoReply<Prev: Rec> {
31003 pub(crate) prev: Option<Prev>,
31004 pub(crate) header_offset: Option<usize>,
31005}
31006impl<Prev: Rec> Rec for PushOpDelsetDoReply<Prev> {
31007 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
31008 self.prev.as_mut().unwrap().as_rec_mut()
31009 }
31010}
31011impl<Prev: Rec> PushOpDelsetDoReply<Prev> {
31012 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
31013 Self::write_header(&mut prev, header);
31014 Self::new_without_header(prev)
31015 }
31016 fn new_without_header(prev: Prev) -> Self {
31017 Self {
31018 prev: Some(prev),
31019 header_offset: None,
31020 }
31021 }
31022 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
31023 prev.as_rec_mut().extend(header.as_slice());
31024 }
31025 pub fn end_nested(mut self) -> Prev {
31026 let mut prev = self.prev.take().unwrap();
31027 if let Some(header_offset) = &self.header_offset {
31028 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31029 }
31030 prev
31031 }
31032}
31033impl<Prev: Rec> Drop for PushOpDelsetDoReply<Prev> {
31034 fn drop(&mut self) {
31035 if let Some(prev) = &mut self.prev {
31036 if let Some(header_offset) = &self.header_offset {
31037 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31038 }
31039 }
31040 }
31041}
31042#[doc = "Delete an existing set."]
31043#[derive(Clone)]
31044pub enum OpDelsetDoReply {}
31045impl<'a> IterableOpDelsetDoReply<'a> {}
31046impl OpDelsetDoReply {
31047 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDelsetDoReply<'_>) {
31048 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
31049 (
31050 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
31051 IterableOpDelsetDoReply::with_loc(attrs, buf.as_ptr() as usize),
31052 )
31053 }
31054 fn attr_from_type(r#type: u16) -> Option<&'static str> {
31055 SetAttrs::attr_from_type(r#type)
31056 }
31057}
31058#[derive(Clone, Copy, Default)]
31059pub struct IterableOpDelsetDoReply<'a> {
31060 buf: &'a [u8],
31061 pos: usize,
31062 orig_loc: usize,
31063}
31064impl<'a> IterableOpDelsetDoReply<'a> {
31065 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
31066 Self {
31067 buf,
31068 pos: 0,
31069 orig_loc,
31070 }
31071 }
31072 pub fn get_buf(&self) -> &'a [u8] {
31073 self.buf
31074 }
31075}
31076impl<'a> Iterator for IterableOpDelsetDoReply<'a> {
31077 type Item = Result<OpDelsetDoReply, ErrorContext>;
31078 fn next(&mut self) -> Option<Self::Item> {
31079 if self.buf.len() == self.pos {
31080 return None;
31081 }
31082 let pos = self.pos;
31083 let mut r#type = None;
31084 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
31085 r#type = Some(header.r#type);
31086 let res = match header.r#type {
31087 n => {
31088 if cfg!(any(test, feature = "deny-unknown-attrs")) {
31089 break;
31090 } else {
31091 continue;
31092 }
31093 }
31094 };
31095 return Some(Ok(res));
31096 }
31097 Some(Err(ErrorContext::new(
31098 "OpDelsetDoReply",
31099 r#type.and_then(|t| OpDelsetDoReply::attr_from_type(t)),
31100 self.orig_loc,
31101 self.buf.as_ptr().wrapping_add(pos) as usize,
31102 )))
31103 }
31104}
31105impl std::fmt::Debug for IterableOpDelsetDoReply<'_> {
31106 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31107 let mut fmt = f.debug_struct("OpDelsetDoReply");
31108 for attr in self.clone() {
31109 let attr = match attr {
31110 Ok(a) => a,
31111 Err(err) => {
31112 fmt.finish()?;
31113 f.write_str("Err(")?;
31114 err.fmt(f)?;
31115 return f.write_str(")");
31116 }
31117 };
31118 match attr {};
31119 }
31120 fmt.finish()
31121 }
31122}
31123impl IterableOpDelsetDoReply<'_> {
31124 pub fn lookup_attr(
31125 &self,
31126 offset: usize,
31127 missing_type: Option<u16>,
31128 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31129 let mut stack = Vec::new();
31130 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
31131 if cur == offset + PushNfgenmsg::len() {
31132 stack.push(("OpDelsetDoReply", offset));
31133 return (
31134 stack,
31135 missing_type.and_then(|t| OpDelsetDoReply::attr_from_type(t)),
31136 );
31137 }
31138 (stack, None)
31139 }
31140}
31141#[derive(Debug)]
31142pub struct RequestOpDelsetDoRequest<'r> {
31143 request: Request<'r>,
31144}
31145impl<'r> RequestOpDelsetDoRequest<'r> {
31146 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
31147 PushOpDelsetDoRequest::write_header(&mut request.buf_mut(), header);
31148 Self { request: request }
31149 }
31150 pub fn encode(&mut self) -> PushOpDelsetDoRequest<&mut Vec<u8>> {
31151 PushOpDelsetDoRequest::new_without_header(self.request.buf_mut())
31152 }
31153 pub fn into_encoder(self) -> PushOpDelsetDoRequest<RequestBuf<'r>> {
31154 PushOpDelsetDoRequest::new_without_header(self.request.buf)
31155 }
31156}
31157impl NetlinkRequest for RequestOpDelsetDoRequest<'_> {
31158 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDelsetDoReply<'buf>);
31159 fn protocol(&self) -> Protocol {
31160 Protocol::Raw {
31161 protonum: 12u16,
31162 request_type: 2571u16,
31163 }
31164 }
31165 fn flags(&self) -> u16 {
31166 self.request.flags
31167 }
31168 fn payload(&self) -> &[u8] {
31169 self.request.buf()
31170 }
31171 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
31172 OpDelsetDoReply::new(buf)
31173 }
31174 fn lookup(
31175 buf: &[u8],
31176 offset: usize,
31177 missing_type: Option<u16>,
31178 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31179 OpDelsetDoRequest::new(buf)
31180 .1
31181 .lookup_attr(offset, missing_type)
31182 }
31183}
31184#[doc = "Delete an existing set with destroy semantics (ignoring ENOENT errors).\n"]
31185pub struct PushOpDestroysetDoRequest<Prev: Rec> {
31186 pub(crate) prev: Option<Prev>,
31187 pub(crate) header_offset: Option<usize>,
31188}
31189impl<Prev: Rec> Rec for PushOpDestroysetDoRequest<Prev> {
31190 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
31191 self.prev.as_mut().unwrap().as_rec_mut()
31192 }
31193}
31194impl<Prev: Rec> PushOpDestroysetDoRequest<Prev> {
31195 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
31196 Self::write_header(&mut prev, header);
31197 Self::new_without_header(prev)
31198 }
31199 fn new_without_header(prev: Prev) -> Self {
31200 Self {
31201 prev: Some(prev),
31202 header_offset: None,
31203 }
31204 }
31205 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
31206 prev.as_rec_mut().extend(header.as_slice());
31207 }
31208 pub fn end_nested(mut self) -> Prev {
31209 let mut prev = self.prev.take().unwrap();
31210 if let Some(header_offset) = &self.header_offset {
31211 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31212 }
31213 prev
31214 }
31215 #[doc = "table name"]
31216 pub fn push_table(mut self, value: &CStr) -> Self {
31217 push_header(
31218 self.as_rec_mut(),
31219 1u16,
31220 value.to_bytes_with_nul().len() as u16,
31221 );
31222 self.as_rec_mut().extend(value.to_bytes_with_nul());
31223 self
31224 }
31225 #[doc = "table name"]
31226 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
31227 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
31228 self.as_rec_mut().extend(value);
31229 self.as_rec_mut().push(0);
31230 self
31231 }
31232 #[doc = "set name"]
31233 pub fn push_name(mut self, value: &CStr) -> Self {
31234 push_header(
31235 self.as_rec_mut(),
31236 2u16,
31237 value.to_bytes_with_nul().len() as u16,
31238 );
31239 self.as_rec_mut().extend(value.to_bytes_with_nul());
31240 self
31241 }
31242 #[doc = "set name"]
31243 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
31244 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
31245 self.as_rec_mut().extend(value);
31246 self.as_rec_mut().push(0);
31247 self
31248 }
31249 #[doc = "set handle"]
31250 pub fn push_handle(mut self, value: u64) -> Self {
31251 push_header(self.as_rec_mut(), 16u16, 8 as u16);
31252 self.as_rec_mut().extend(value.to_be_bytes());
31253 self
31254 }
31255}
31256impl<Prev: Rec> Drop for PushOpDestroysetDoRequest<Prev> {
31257 fn drop(&mut self) {
31258 if let Some(prev) = &mut self.prev {
31259 if let Some(header_offset) = &self.header_offset {
31260 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31261 }
31262 }
31263 }
31264}
31265#[doc = "Delete an existing set with destroy semantics (ignoring ENOENT errors).\n"]
31266#[derive(Clone)]
31267pub enum OpDestroysetDoRequest<'a> {
31268 #[doc = "table name"]
31269 Table(&'a CStr),
31270 #[doc = "set name"]
31271 Name(&'a CStr),
31272 #[doc = "set handle"]
31273 Handle(u64),
31274}
31275impl<'a> IterableOpDestroysetDoRequest<'a> {
31276 #[doc = "table name"]
31277 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
31278 let mut iter = self.clone();
31279 iter.pos = 0;
31280 for attr in iter {
31281 if let OpDestroysetDoRequest::Table(val) = attr? {
31282 return Ok(val);
31283 }
31284 }
31285 Err(ErrorContext::new_missing(
31286 "OpDestroysetDoRequest",
31287 "Table",
31288 self.orig_loc,
31289 self.buf.as_ptr() as usize,
31290 ))
31291 }
31292 #[doc = "set name"]
31293 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
31294 let mut iter = self.clone();
31295 iter.pos = 0;
31296 for attr in iter {
31297 if let OpDestroysetDoRequest::Name(val) = attr? {
31298 return Ok(val);
31299 }
31300 }
31301 Err(ErrorContext::new_missing(
31302 "OpDestroysetDoRequest",
31303 "Name",
31304 self.orig_loc,
31305 self.buf.as_ptr() as usize,
31306 ))
31307 }
31308 #[doc = "set handle"]
31309 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
31310 let mut iter = self.clone();
31311 iter.pos = 0;
31312 for attr in iter {
31313 if let OpDestroysetDoRequest::Handle(val) = attr? {
31314 return Ok(val);
31315 }
31316 }
31317 Err(ErrorContext::new_missing(
31318 "OpDestroysetDoRequest",
31319 "Handle",
31320 self.orig_loc,
31321 self.buf.as_ptr() as usize,
31322 ))
31323 }
31324}
31325impl<'a> OpDestroysetDoRequest<'a> {
31326 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDestroysetDoRequest<'a>) {
31327 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
31328 (
31329 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
31330 IterableOpDestroysetDoRequest::with_loc(attrs, buf.as_ptr() as usize),
31331 )
31332 }
31333 fn attr_from_type(r#type: u16) -> Option<&'static str> {
31334 SetAttrs::attr_from_type(r#type)
31335 }
31336}
31337#[derive(Clone, Copy, Default)]
31338pub struct IterableOpDestroysetDoRequest<'a> {
31339 buf: &'a [u8],
31340 pos: usize,
31341 orig_loc: usize,
31342}
31343impl<'a> IterableOpDestroysetDoRequest<'a> {
31344 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
31345 Self {
31346 buf,
31347 pos: 0,
31348 orig_loc,
31349 }
31350 }
31351 pub fn get_buf(&self) -> &'a [u8] {
31352 self.buf
31353 }
31354}
31355impl<'a> Iterator for IterableOpDestroysetDoRequest<'a> {
31356 type Item = Result<OpDestroysetDoRequest<'a>, ErrorContext>;
31357 fn next(&mut self) -> Option<Self::Item> {
31358 if self.buf.len() == self.pos {
31359 return None;
31360 }
31361 let pos = self.pos;
31362 let mut r#type = None;
31363 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
31364 r#type = Some(header.r#type);
31365 let res = match header.r#type {
31366 1u16 => OpDestroysetDoRequest::Table({
31367 let res = CStr::from_bytes_with_nul(next).ok();
31368 let Some(val) = res else { break };
31369 val
31370 }),
31371 2u16 => OpDestroysetDoRequest::Name({
31372 let res = CStr::from_bytes_with_nul(next).ok();
31373 let Some(val) = res else { break };
31374 val
31375 }),
31376 16u16 => OpDestroysetDoRequest::Handle({
31377 let res = parse_be_u64(next);
31378 let Some(val) = res else { break };
31379 val
31380 }),
31381 n => {
31382 if cfg!(any(test, feature = "deny-unknown-attrs")) {
31383 break;
31384 } else {
31385 continue;
31386 }
31387 }
31388 };
31389 return Some(Ok(res));
31390 }
31391 Some(Err(ErrorContext::new(
31392 "OpDestroysetDoRequest",
31393 r#type.and_then(|t| OpDestroysetDoRequest::attr_from_type(t)),
31394 self.orig_loc,
31395 self.buf.as_ptr().wrapping_add(pos) as usize,
31396 )))
31397 }
31398}
31399impl<'a> std::fmt::Debug for IterableOpDestroysetDoRequest<'_> {
31400 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31401 let mut fmt = f.debug_struct("OpDestroysetDoRequest");
31402 for attr in self.clone() {
31403 let attr = match attr {
31404 Ok(a) => a,
31405 Err(err) => {
31406 fmt.finish()?;
31407 f.write_str("Err(")?;
31408 err.fmt(f)?;
31409 return f.write_str(")");
31410 }
31411 };
31412 match attr {
31413 OpDestroysetDoRequest::Table(val) => fmt.field("Table", &val),
31414 OpDestroysetDoRequest::Name(val) => fmt.field("Name", &val),
31415 OpDestroysetDoRequest::Handle(val) => fmt.field("Handle", &val),
31416 };
31417 }
31418 fmt.finish()
31419 }
31420}
31421impl IterableOpDestroysetDoRequest<'_> {
31422 pub fn lookup_attr(
31423 &self,
31424 offset: usize,
31425 missing_type: Option<u16>,
31426 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31427 let mut stack = Vec::new();
31428 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
31429 if cur == offset + PushNfgenmsg::len() {
31430 stack.push(("OpDestroysetDoRequest", offset));
31431 return (
31432 stack,
31433 missing_type.and_then(|t| OpDestroysetDoRequest::attr_from_type(t)),
31434 );
31435 }
31436 if cur > offset || cur + self.buf.len() < offset {
31437 return (stack, None);
31438 }
31439 let mut attrs = self.clone();
31440 let mut last_off = cur + attrs.pos;
31441 while let Some(attr) = attrs.next() {
31442 let Ok(attr) = attr else { break };
31443 match attr {
31444 OpDestroysetDoRequest::Table(val) => {
31445 if last_off == offset {
31446 stack.push(("Table", last_off));
31447 break;
31448 }
31449 }
31450 OpDestroysetDoRequest::Name(val) => {
31451 if last_off == offset {
31452 stack.push(("Name", last_off));
31453 break;
31454 }
31455 }
31456 OpDestroysetDoRequest::Handle(val) => {
31457 if last_off == offset {
31458 stack.push(("Handle", last_off));
31459 break;
31460 }
31461 }
31462 _ => {}
31463 };
31464 last_off = cur + attrs.pos;
31465 }
31466 if !stack.is_empty() {
31467 stack.push(("OpDestroysetDoRequest", cur));
31468 }
31469 (stack, None)
31470 }
31471}
31472#[doc = "Delete an existing set with destroy semantics (ignoring ENOENT errors).\n"]
31473pub struct PushOpDestroysetDoReply<Prev: Rec> {
31474 pub(crate) prev: Option<Prev>,
31475 pub(crate) header_offset: Option<usize>,
31476}
31477impl<Prev: Rec> Rec for PushOpDestroysetDoReply<Prev> {
31478 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
31479 self.prev.as_mut().unwrap().as_rec_mut()
31480 }
31481}
31482impl<Prev: Rec> PushOpDestroysetDoReply<Prev> {
31483 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
31484 Self::write_header(&mut prev, header);
31485 Self::new_without_header(prev)
31486 }
31487 fn new_without_header(prev: Prev) -> Self {
31488 Self {
31489 prev: Some(prev),
31490 header_offset: None,
31491 }
31492 }
31493 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
31494 prev.as_rec_mut().extend(header.as_slice());
31495 }
31496 pub fn end_nested(mut self) -> Prev {
31497 let mut prev = self.prev.take().unwrap();
31498 if let Some(header_offset) = &self.header_offset {
31499 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31500 }
31501 prev
31502 }
31503}
31504impl<Prev: Rec> Drop for PushOpDestroysetDoReply<Prev> {
31505 fn drop(&mut self) {
31506 if let Some(prev) = &mut self.prev {
31507 if let Some(header_offset) = &self.header_offset {
31508 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31509 }
31510 }
31511 }
31512}
31513#[doc = "Delete an existing set with destroy semantics (ignoring ENOENT errors).\n"]
31514#[derive(Clone)]
31515pub enum OpDestroysetDoReply {}
31516impl<'a> IterableOpDestroysetDoReply<'a> {}
31517impl OpDestroysetDoReply {
31518 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDestroysetDoReply<'_>) {
31519 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
31520 (
31521 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
31522 IterableOpDestroysetDoReply::with_loc(attrs, buf.as_ptr() as usize),
31523 )
31524 }
31525 fn attr_from_type(r#type: u16) -> Option<&'static str> {
31526 SetAttrs::attr_from_type(r#type)
31527 }
31528}
31529#[derive(Clone, Copy, Default)]
31530pub struct IterableOpDestroysetDoReply<'a> {
31531 buf: &'a [u8],
31532 pos: usize,
31533 orig_loc: usize,
31534}
31535impl<'a> IterableOpDestroysetDoReply<'a> {
31536 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
31537 Self {
31538 buf,
31539 pos: 0,
31540 orig_loc,
31541 }
31542 }
31543 pub fn get_buf(&self) -> &'a [u8] {
31544 self.buf
31545 }
31546}
31547impl<'a> Iterator for IterableOpDestroysetDoReply<'a> {
31548 type Item = Result<OpDestroysetDoReply, ErrorContext>;
31549 fn next(&mut self) -> Option<Self::Item> {
31550 if self.buf.len() == self.pos {
31551 return None;
31552 }
31553 let pos = self.pos;
31554 let mut r#type = None;
31555 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
31556 r#type = Some(header.r#type);
31557 let res = match header.r#type {
31558 n => {
31559 if cfg!(any(test, feature = "deny-unknown-attrs")) {
31560 break;
31561 } else {
31562 continue;
31563 }
31564 }
31565 };
31566 return Some(Ok(res));
31567 }
31568 Some(Err(ErrorContext::new(
31569 "OpDestroysetDoReply",
31570 r#type.and_then(|t| OpDestroysetDoReply::attr_from_type(t)),
31571 self.orig_loc,
31572 self.buf.as_ptr().wrapping_add(pos) as usize,
31573 )))
31574 }
31575}
31576impl std::fmt::Debug for IterableOpDestroysetDoReply<'_> {
31577 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31578 let mut fmt = f.debug_struct("OpDestroysetDoReply");
31579 for attr in self.clone() {
31580 let attr = match attr {
31581 Ok(a) => a,
31582 Err(err) => {
31583 fmt.finish()?;
31584 f.write_str("Err(")?;
31585 err.fmt(f)?;
31586 return f.write_str(")");
31587 }
31588 };
31589 match attr {};
31590 }
31591 fmt.finish()
31592 }
31593}
31594impl IterableOpDestroysetDoReply<'_> {
31595 pub fn lookup_attr(
31596 &self,
31597 offset: usize,
31598 missing_type: Option<u16>,
31599 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31600 let mut stack = Vec::new();
31601 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
31602 if cur == offset + PushNfgenmsg::len() {
31603 stack.push(("OpDestroysetDoReply", offset));
31604 return (
31605 stack,
31606 missing_type.and_then(|t| OpDestroysetDoReply::attr_from_type(t)),
31607 );
31608 }
31609 (stack, None)
31610 }
31611}
31612#[derive(Debug)]
31613pub struct RequestOpDestroysetDoRequest<'r> {
31614 request: Request<'r>,
31615}
31616impl<'r> RequestOpDestroysetDoRequest<'r> {
31617 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
31618 PushOpDestroysetDoRequest::write_header(&mut request.buf_mut(), header);
31619 Self { request: request }
31620 }
31621 pub fn encode(&mut self) -> PushOpDestroysetDoRequest<&mut Vec<u8>> {
31622 PushOpDestroysetDoRequest::new_without_header(self.request.buf_mut())
31623 }
31624 pub fn into_encoder(self) -> PushOpDestroysetDoRequest<RequestBuf<'r>> {
31625 PushOpDestroysetDoRequest::new_without_header(self.request.buf)
31626 }
31627}
31628impl NetlinkRequest for RequestOpDestroysetDoRequest<'_> {
31629 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDestroysetDoReply<'buf>);
31630 fn protocol(&self) -> Protocol {
31631 Protocol::Raw {
31632 protonum: 12u16,
31633 request_type: 2589u16,
31634 }
31635 }
31636 fn flags(&self) -> u16 {
31637 self.request.flags
31638 }
31639 fn payload(&self) -> &[u8] {
31640 self.request.buf()
31641 }
31642 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
31643 OpDestroysetDoReply::new(buf)
31644 }
31645 fn lookup(
31646 buf: &[u8],
31647 offset: usize,
31648 missing_type: Option<u16>,
31649 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31650 OpDestroysetDoRequest::new(buf)
31651 .1
31652 .lookup_attr(offset, missing_type)
31653 }
31654}
31655#[doc = "Create a new set element."]
31656pub struct PushOpNewsetelemDoRequest<Prev: Rec> {
31657 pub(crate) prev: Option<Prev>,
31658 pub(crate) header_offset: Option<usize>,
31659}
31660impl<Prev: Rec> Rec for PushOpNewsetelemDoRequest<Prev> {
31661 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
31662 self.prev.as_mut().unwrap().as_rec_mut()
31663 }
31664}
31665impl<Prev: Rec> PushOpNewsetelemDoRequest<Prev> {
31666 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
31667 Self::write_header(&mut prev, header);
31668 Self::new_without_header(prev)
31669 }
31670 fn new_without_header(prev: Prev) -> Self {
31671 Self {
31672 prev: Some(prev),
31673 header_offset: None,
31674 }
31675 }
31676 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
31677 prev.as_rec_mut().extend(header.as_slice());
31678 }
31679 pub fn end_nested(mut self) -> Prev {
31680 let mut prev = self.prev.take().unwrap();
31681 if let Some(header_offset) = &self.header_offset {
31682 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31683 }
31684 prev
31685 }
31686 pub fn push_table(mut self, value: &CStr) -> Self {
31687 push_header(
31688 self.as_rec_mut(),
31689 1u16,
31690 value.to_bytes_with_nul().len() as u16,
31691 );
31692 self.as_rec_mut().extend(value.to_bytes_with_nul());
31693 self
31694 }
31695 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
31696 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
31697 self.as_rec_mut().extend(value);
31698 self.as_rec_mut().push(0);
31699 self
31700 }
31701 pub fn push_set(mut self, value: &CStr) -> Self {
31702 push_header(
31703 self.as_rec_mut(),
31704 2u16,
31705 value.to_bytes_with_nul().len() as u16,
31706 );
31707 self.as_rec_mut().extend(value.to_bytes_with_nul());
31708 self
31709 }
31710 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
31711 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
31712 self.as_rec_mut().extend(value);
31713 self.as_rec_mut().push(0);
31714 self
31715 }
31716 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
31717 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
31718 PushSetelemListElemAttrs {
31719 prev: Some(self),
31720 header_offset: Some(header_offset),
31721 }
31722 }
31723 pub fn push_set_id(mut self, value: u32) -> Self {
31724 push_header(self.as_rec_mut(), 4u16, 4 as u16);
31725 self.as_rec_mut().extend(value.to_ne_bytes());
31726 self
31727 }
31728}
31729impl<Prev: Rec> Drop for PushOpNewsetelemDoRequest<Prev> {
31730 fn drop(&mut self) {
31731 if let Some(prev) = &mut self.prev {
31732 if let Some(header_offset) = &self.header_offset {
31733 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31734 }
31735 }
31736 }
31737}
31738#[doc = "Create a new set element."]
31739#[derive(Clone)]
31740pub enum OpNewsetelemDoRequest<'a> {
31741 Table(&'a CStr),
31742 Set(&'a CStr),
31743 Elements(IterableSetelemListElemAttrs<'a>),
31744 SetId(u32),
31745}
31746impl<'a> IterableOpNewsetelemDoRequest<'a> {
31747 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
31748 let mut iter = self.clone();
31749 iter.pos = 0;
31750 for attr in iter {
31751 if let OpNewsetelemDoRequest::Table(val) = attr? {
31752 return Ok(val);
31753 }
31754 }
31755 Err(ErrorContext::new_missing(
31756 "OpNewsetelemDoRequest",
31757 "Table",
31758 self.orig_loc,
31759 self.buf.as_ptr() as usize,
31760 ))
31761 }
31762 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
31763 let mut iter = self.clone();
31764 iter.pos = 0;
31765 for attr in iter {
31766 if let OpNewsetelemDoRequest::Set(val) = attr? {
31767 return Ok(val);
31768 }
31769 }
31770 Err(ErrorContext::new_missing(
31771 "OpNewsetelemDoRequest",
31772 "Set",
31773 self.orig_loc,
31774 self.buf.as_ptr() as usize,
31775 ))
31776 }
31777 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
31778 let mut iter = self.clone();
31779 iter.pos = 0;
31780 for attr in iter {
31781 if let OpNewsetelemDoRequest::Elements(val) = attr? {
31782 return Ok(val);
31783 }
31784 }
31785 Err(ErrorContext::new_missing(
31786 "OpNewsetelemDoRequest",
31787 "Elements",
31788 self.orig_loc,
31789 self.buf.as_ptr() as usize,
31790 ))
31791 }
31792 pub fn get_set_id(&self) -> Result<u32, ErrorContext> {
31793 let mut iter = self.clone();
31794 iter.pos = 0;
31795 for attr in iter {
31796 if let OpNewsetelemDoRequest::SetId(val) = attr? {
31797 return Ok(val);
31798 }
31799 }
31800 Err(ErrorContext::new_missing(
31801 "OpNewsetelemDoRequest",
31802 "SetId",
31803 self.orig_loc,
31804 self.buf.as_ptr() as usize,
31805 ))
31806 }
31807}
31808impl<'a> OpNewsetelemDoRequest<'a> {
31809 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpNewsetelemDoRequest<'a>) {
31810 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
31811 (
31812 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
31813 IterableOpNewsetelemDoRequest::with_loc(attrs, buf.as_ptr() as usize),
31814 )
31815 }
31816 fn attr_from_type(r#type: u16) -> Option<&'static str> {
31817 SetelemListAttrs::attr_from_type(r#type)
31818 }
31819}
31820#[derive(Clone, Copy, Default)]
31821pub struct IterableOpNewsetelemDoRequest<'a> {
31822 buf: &'a [u8],
31823 pos: usize,
31824 orig_loc: usize,
31825}
31826impl<'a> IterableOpNewsetelemDoRequest<'a> {
31827 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
31828 Self {
31829 buf,
31830 pos: 0,
31831 orig_loc,
31832 }
31833 }
31834 pub fn get_buf(&self) -> &'a [u8] {
31835 self.buf
31836 }
31837}
31838impl<'a> Iterator for IterableOpNewsetelemDoRequest<'a> {
31839 type Item = Result<OpNewsetelemDoRequest<'a>, ErrorContext>;
31840 fn next(&mut self) -> Option<Self::Item> {
31841 if self.buf.len() == self.pos {
31842 return None;
31843 }
31844 let pos = self.pos;
31845 let mut r#type = None;
31846 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
31847 r#type = Some(header.r#type);
31848 let res = match header.r#type {
31849 1u16 => OpNewsetelemDoRequest::Table({
31850 let res = CStr::from_bytes_with_nul(next).ok();
31851 let Some(val) = res else { break };
31852 val
31853 }),
31854 2u16 => OpNewsetelemDoRequest::Set({
31855 let res = CStr::from_bytes_with_nul(next).ok();
31856 let Some(val) = res else { break };
31857 val
31858 }),
31859 3u16 => OpNewsetelemDoRequest::Elements({
31860 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
31861 let Some(val) = res else { break };
31862 val
31863 }),
31864 4u16 => OpNewsetelemDoRequest::SetId({
31865 let res = parse_u32(next);
31866 let Some(val) = res else { break };
31867 val
31868 }),
31869 n => {
31870 if cfg!(any(test, feature = "deny-unknown-attrs")) {
31871 break;
31872 } else {
31873 continue;
31874 }
31875 }
31876 };
31877 return Some(Ok(res));
31878 }
31879 Some(Err(ErrorContext::new(
31880 "OpNewsetelemDoRequest",
31881 r#type.and_then(|t| OpNewsetelemDoRequest::attr_from_type(t)),
31882 self.orig_loc,
31883 self.buf.as_ptr().wrapping_add(pos) as usize,
31884 )))
31885 }
31886}
31887impl<'a> std::fmt::Debug for IterableOpNewsetelemDoRequest<'_> {
31888 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31889 let mut fmt = f.debug_struct("OpNewsetelemDoRequest");
31890 for attr in self.clone() {
31891 let attr = match attr {
31892 Ok(a) => a,
31893 Err(err) => {
31894 fmt.finish()?;
31895 f.write_str("Err(")?;
31896 err.fmt(f)?;
31897 return f.write_str(")");
31898 }
31899 };
31900 match attr {
31901 OpNewsetelemDoRequest::Table(val) => fmt.field("Table", &val),
31902 OpNewsetelemDoRequest::Set(val) => fmt.field("Set", &val),
31903 OpNewsetelemDoRequest::Elements(val) => fmt.field("Elements", &val),
31904 OpNewsetelemDoRequest::SetId(val) => fmt.field("SetId", &val),
31905 };
31906 }
31907 fmt.finish()
31908 }
31909}
31910impl IterableOpNewsetelemDoRequest<'_> {
31911 pub fn lookup_attr(
31912 &self,
31913 offset: usize,
31914 missing_type: Option<u16>,
31915 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
31916 let mut stack = Vec::new();
31917 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
31918 if cur == offset + PushNfgenmsg::len() {
31919 stack.push(("OpNewsetelemDoRequest", offset));
31920 return (
31921 stack,
31922 missing_type.and_then(|t| OpNewsetelemDoRequest::attr_from_type(t)),
31923 );
31924 }
31925 if cur > offset || cur + self.buf.len() < offset {
31926 return (stack, None);
31927 }
31928 let mut attrs = self.clone();
31929 let mut last_off = cur + attrs.pos;
31930 let mut missing = None;
31931 while let Some(attr) = attrs.next() {
31932 let Ok(attr) = attr else { break };
31933 match attr {
31934 OpNewsetelemDoRequest::Table(val) => {
31935 if last_off == offset {
31936 stack.push(("Table", last_off));
31937 break;
31938 }
31939 }
31940 OpNewsetelemDoRequest::Set(val) => {
31941 if last_off == offset {
31942 stack.push(("Set", last_off));
31943 break;
31944 }
31945 }
31946 OpNewsetelemDoRequest::Elements(val) => {
31947 (stack, missing) = val.lookup_attr(offset, missing_type);
31948 if !stack.is_empty() {
31949 break;
31950 }
31951 }
31952 OpNewsetelemDoRequest::SetId(val) => {
31953 if last_off == offset {
31954 stack.push(("SetId", last_off));
31955 break;
31956 }
31957 }
31958 _ => {}
31959 };
31960 last_off = cur + attrs.pos;
31961 }
31962 if !stack.is_empty() {
31963 stack.push(("OpNewsetelemDoRequest", cur));
31964 }
31965 (stack, missing)
31966 }
31967}
31968#[doc = "Create a new set element."]
31969pub struct PushOpNewsetelemDoReply<Prev: Rec> {
31970 pub(crate) prev: Option<Prev>,
31971 pub(crate) header_offset: Option<usize>,
31972}
31973impl<Prev: Rec> Rec for PushOpNewsetelemDoReply<Prev> {
31974 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
31975 self.prev.as_mut().unwrap().as_rec_mut()
31976 }
31977}
31978impl<Prev: Rec> PushOpNewsetelemDoReply<Prev> {
31979 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
31980 Self::write_header(&mut prev, header);
31981 Self::new_without_header(prev)
31982 }
31983 fn new_without_header(prev: Prev) -> Self {
31984 Self {
31985 prev: Some(prev),
31986 header_offset: None,
31987 }
31988 }
31989 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
31990 prev.as_rec_mut().extend(header.as_slice());
31991 }
31992 pub fn end_nested(mut self) -> Prev {
31993 let mut prev = self.prev.take().unwrap();
31994 if let Some(header_offset) = &self.header_offset {
31995 finalize_nested_header(prev.as_rec_mut(), *header_offset);
31996 }
31997 prev
31998 }
31999}
32000impl<Prev: Rec> Drop for PushOpNewsetelemDoReply<Prev> {
32001 fn drop(&mut self) {
32002 if let Some(prev) = &mut self.prev {
32003 if let Some(header_offset) = &self.header_offset {
32004 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32005 }
32006 }
32007 }
32008}
32009#[doc = "Create a new set element."]
32010#[derive(Clone)]
32011pub enum OpNewsetelemDoReply {}
32012impl<'a> IterableOpNewsetelemDoReply<'a> {}
32013impl OpNewsetelemDoReply {
32014 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpNewsetelemDoReply<'_>) {
32015 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
32016 (
32017 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
32018 IterableOpNewsetelemDoReply::with_loc(attrs, buf.as_ptr() as usize),
32019 )
32020 }
32021 fn attr_from_type(r#type: u16) -> Option<&'static str> {
32022 SetelemListAttrs::attr_from_type(r#type)
32023 }
32024}
32025#[derive(Clone, Copy, Default)]
32026pub struct IterableOpNewsetelemDoReply<'a> {
32027 buf: &'a [u8],
32028 pos: usize,
32029 orig_loc: usize,
32030}
32031impl<'a> IterableOpNewsetelemDoReply<'a> {
32032 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
32033 Self {
32034 buf,
32035 pos: 0,
32036 orig_loc,
32037 }
32038 }
32039 pub fn get_buf(&self) -> &'a [u8] {
32040 self.buf
32041 }
32042}
32043impl<'a> Iterator for IterableOpNewsetelemDoReply<'a> {
32044 type Item = Result<OpNewsetelemDoReply, ErrorContext>;
32045 fn next(&mut self) -> Option<Self::Item> {
32046 if self.buf.len() == self.pos {
32047 return None;
32048 }
32049 let pos = self.pos;
32050 let mut r#type = None;
32051 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
32052 r#type = Some(header.r#type);
32053 let res = match header.r#type {
32054 n => {
32055 if cfg!(any(test, feature = "deny-unknown-attrs")) {
32056 break;
32057 } else {
32058 continue;
32059 }
32060 }
32061 };
32062 return Some(Ok(res));
32063 }
32064 Some(Err(ErrorContext::new(
32065 "OpNewsetelemDoReply",
32066 r#type.and_then(|t| OpNewsetelemDoReply::attr_from_type(t)),
32067 self.orig_loc,
32068 self.buf.as_ptr().wrapping_add(pos) as usize,
32069 )))
32070 }
32071}
32072impl std::fmt::Debug for IterableOpNewsetelemDoReply<'_> {
32073 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32074 let mut fmt = f.debug_struct("OpNewsetelemDoReply");
32075 for attr in self.clone() {
32076 let attr = match attr {
32077 Ok(a) => a,
32078 Err(err) => {
32079 fmt.finish()?;
32080 f.write_str("Err(")?;
32081 err.fmt(f)?;
32082 return f.write_str(")");
32083 }
32084 };
32085 match attr {};
32086 }
32087 fmt.finish()
32088 }
32089}
32090impl IterableOpNewsetelemDoReply<'_> {
32091 pub fn lookup_attr(
32092 &self,
32093 offset: usize,
32094 missing_type: Option<u16>,
32095 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32096 let mut stack = Vec::new();
32097 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
32098 if cur == offset + PushNfgenmsg::len() {
32099 stack.push(("OpNewsetelemDoReply", offset));
32100 return (
32101 stack,
32102 missing_type.and_then(|t| OpNewsetelemDoReply::attr_from_type(t)),
32103 );
32104 }
32105 (stack, None)
32106 }
32107}
32108#[derive(Debug)]
32109pub struct RequestOpNewsetelemDoRequest<'r> {
32110 request: Request<'r>,
32111}
32112impl<'r> RequestOpNewsetelemDoRequest<'r> {
32113 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
32114 PushOpNewsetelemDoRequest::write_header(&mut request.buf_mut(), header);
32115 Self { request: request }
32116 }
32117 pub fn encode(&mut self) -> PushOpNewsetelemDoRequest<&mut Vec<u8>> {
32118 PushOpNewsetelemDoRequest::new_without_header(self.request.buf_mut())
32119 }
32120 pub fn into_encoder(self) -> PushOpNewsetelemDoRequest<RequestBuf<'r>> {
32121 PushOpNewsetelemDoRequest::new_without_header(self.request.buf)
32122 }
32123}
32124impl NetlinkRequest for RequestOpNewsetelemDoRequest<'_> {
32125 type ReplyType<'buf> = (PushNfgenmsg, IterableOpNewsetelemDoReply<'buf>);
32126 fn protocol(&self) -> Protocol {
32127 Protocol::Raw {
32128 protonum: 12u16,
32129 request_type: 2572u16,
32130 }
32131 }
32132 fn flags(&self) -> u16 {
32133 self.request.flags
32134 }
32135 fn payload(&self) -> &[u8] {
32136 self.request.buf()
32137 }
32138 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
32139 OpNewsetelemDoReply::new(buf)
32140 }
32141 fn lookup(
32142 buf: &[u8],
32143 offset: usize,
32144 missing_type: Option<u16>,
32145 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32146 OpNewsetelemDoRequest::new(buf)
32147 .1
32148 .lookup_attr(offset, missing_type)
32149 }
32150}
32151#[doc = "Get / dump set elements."]
32152pub struct PushOpGetsetelemDumpRequest<Prev: Rec> {
32153 pub(crate) prev: Option<Prev>,
32154 pub(crate) header_offset: Option<usize>,
32155}
32156impl<Prev: Rec> Rec for PushOpGetsetelemDumpRequest<Prev> {
32157 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
32158 self.prev.as_mut().unwrap().as_rec_mut()
32159 }
32160}
32161impl<Prev: Rec> PushOpGetsetelemDumpRequest<Prev> {
32162 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
32163 Self::write_header(&mut prev, header);
32164 Self::new_without_header(prev)
32165 }
32166 fn new_without_header(prev: Prev) -> Self {
32167 Self {
32168 prev: Some(prev),
32169 header_offset: None,
32170 }
32171 }
32172 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
32173 prev.as_rec_mut().extend(header.as_slice());
32174 }
32175 pub fn end_nested(mut self) -> Prev {
32176 let mut prev = self.prev.take().unwrap();
32177 if let Some(header_offset) = &self.header_offset {
32178 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32179 }
32180 prev
32181 }
32182 pub fn push_table(mut self, value: &CStr) -> Self {
32183 push_header(
32184 self.as_rec_mut(),
32185 1u16,
32186 value.to_bytes_with_nul().len() as u16,
32187 );
32188 self.as_rec_mut().extend(value.to_bytes_with_nul());
32189 self
32190 }
32191 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
32192 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
32193 self.as_rec_mut().extend(value);
32194 self.as_rec_mut().push(0);
32195 self
32196 }
32197 pub fn push_set(mut self, value: &CStr) -> Self {
32198 push_header(
32199 self.as_rec_mut(),
32200 2u16,
32201 value.to_bytes_with_nul().len() as u16,
32202 );
32203 self.as_rec_mut().extend(value.to_bytes_with_nul());
32204 self
32205 }
32206 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
32207 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
32208 self.as_rec_mut().extend(value);
32209 self.as_rec_mut().push(0);
32210 self
32211 }
32212}
32213impl<Prev: Rec> Drop for PushOpGetsetelemDumpRequest<Prev> {
32214 fn drop(&mut self) {
32215 if let Some(prev) = &mut self.prev {
32216 if let Some(header_offset) = &self.header_offset {
32217 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32218 }
32219 }
32220 }
32221}
32222#[doc = "Get / dump set elements."]
32223#[derive(Clone)]
32224pub enum OpGetsetelemDumpRequest<'a> {
32225 Table(&'a CStr),
32226 Set(&'a CStr),
32227}
32228impl<'a> IterableOpGetsetelemDumpRequest<'a> {
32229 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
32230 let mut iter = self.clone();
32231 iter.pos = 0;
32232 for attr in iter {
32233 if let OpGetsetelemDumpRequest::Table(val) = attr? {
32234 return Ok(val);
32235 }
32236 }
32237 Err(ErrorContext::new_missing(
32238 "OpGetsetelemDumpRequest",
32239 "Table",
32240 self.orig_loc,
32241 self.buf.as_ptr() as usize,
32242 ))
32243 }
32244 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
32245 let mut iter = self.clone();
32246 iter.pos = 0;
32247 for attr in iter {
32248 if let OpGetsetelemDumpRequest::Set(val) = attr? {
32249 return Ok(val);
32250 }
32251 }
32252 Err(ErrorContext::new_missing(
32253 "OpGetsetelemDumpRequest",
32254 "Set",
32255 self.orig_loc,
32256 self.buf.as_ptr() as usize,
32257 ))
32258 }
32259}
32260impl<'a> OpGetsetelemDumpRequest<'a> {
32261 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetelemDumpRequest<'a>) {
32262 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
32263 (
32264 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
32265 IterableOpGetsetelemDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
32266 )
32267 }
32268 fn attr_from_type(r#type: u16) -> Option<&'static str> {
32269 SetelemListAttrs::attr_from_type(r#type)
32270 }
32271}
32272#[derive(Clone, Copy, Default)]
32273pub struct IterableOpGetsetelemDumpRequest<'a> {
32274 buf: &'a [u8],
32275 pos: usize,
32276 orig_loc: usize,
32277}
32278impl<'a> IterableOpGetsetelemDumpRequest<'a> {
32279 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
32280 Self {
32281 buf,
32282 pos: 0,
32283 orig_loc,
32284 }
32285 }
32286 pub fn get_buf(&self) -> &'a [u8] {
32287 self.buf
32288 }
32289}
32290impl<'a> Iterator for IterableOpGetsetelemDumpRequest<'a> {
32291 type Item = Result<OpGetsetelemDumpRequest<'a>, ErrorContext>;
32292 fn next(&mut self) -> Option<Self::Item> {
32293 if self.buf.len() == self.pos {
32294 return None;
32295 }
32296 let pos = self.pos;
32297 let mut r#type = None;
32298 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
32299 r#type = Some(header.r#type);
32300 let res = match header.r#type {
32301 1u16 => OpGetsetelemDumpRequest::Table({
32302 let res = CStr::from_bytes_with_nul(next).ok();
32303 let Some(val) = res else { break };
32304 val
32305 }),
32306 2u16 => OpGetsetelemDumpRequest::Set({
32307 let res = CStr::from_bytes_with_nul(next).ok();
32308 let Some(val) = res else { break };
32309 val
32310 }),
32311 n => {
32312 if cfg!(any(test, feature = "deny-unknown-attrs")) {
32313 break;
32314 } else {
32315 continue;
32316 }
32317 }
32318 };
32319 return Some(Ok(res));
32320 }
32321 Some(Err(ErrorContext::new(
32322 "OpGetsetelemDumpRequest",
32323 r#type.and_then(|t| OpGetsetelemDumpRequest::attr_from_type(t)),
32324 self.orig_loc,
32325 self.buf.as_ptr().wrapping_add(pos) as usize,
32326 )))
32327 }
32328}
32329impl<'a> std::fmt::Debug for IterableOpGetsetelemDumpRequest<'_> {
32330 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32331 let mut fmt = f.debug_struct("OpGetsetelemDumpRequest");
32332 for attr in self.clone() {
32333 let attr = match attr {
32334 Ok(a) => a,
32335 Err(err) => {
32336 fmt.finish()?;
32337 f.write_str("Err(")?;
32338 err.fmt(f)?;
32339 return f.write_str(")");
32340 }
32341 };
32342 match attr {
32343 OpGetsetelemDumpRequest::Table(val) => fmt.field("Table", &val),
32344 OpGetsetelemDumpRequest::Set(val) => fmt.field("Set", &val),
32345 };
32346 }
32347 fmt.finish()
32348 }
32349}
32350impl IterableOpGetsetelemDumpRequest<'_> {
32351 pub fn lookup_attr(
32352 &self,
32353 offset: usize,
32354 missing_type: Option<u16>,
32355 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32356 let mut stack = Vec::new();
32357 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
32358 if cur == offset + PushNfgenmsg::len() {
32359 stack.push(("OpGetsetelemDumpRequest", offset));
32360 return (
32361 stack,
32362 missing_type.and_then(|t| OpGetsetelemDumpRequest::attr_from_type(t)),
32363 );
32364 }
32365 if cur > offset || cur + self.buf.len() < offset {
32366 return (stack, None);
32367 }
32368 let mut attrs = self.clone();
32369 let mut last_off = cur + attrs.pos;
32370 while let Some(attr) = attrs.next() {
32371 let Ok(attr) = attr else { break };
32372 match attr {
32373 OpGetsetelemDumpRequest::Table(val) => {
32374 if last_off == offset {
32375 stack.push(("Table", last_off));
32376 break;
32377 }
32378 }
32379 OpGetsetelemDumpRequest::Set(val) => {
32380 if last_off == offset {
32381 stack.push(("Set", last_off));
32382 break;
32383 }
32384 }
32385 _ => {}
32386 };
32387 last_off = cur + attrs.pos;
32388 }
32389 if !stack.is_empty() {
32390 stack.push(("OpGetsetelemDumpRequest", cur));
32391 }
32392 (stack, None)
32393 }
32394}
32395#[doc = "Get / dump set elements."]
32396pub struct PushOpGetsetelemDumpReply<Prev: Rec> {
32397 pub(crate) prev: Option<Prev>,
32398 pub(crate) header_offset: Option<usize>,
32399}
32400impl<Prev: Rec> Rec for PushOpGetsetelemDumpReply<Prev> {
32401 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
32402 self.prev.as_mut().unwrap().as_rec_mut()
32403 }
32404}
32405impl<Prev: Rec> PushOpGetsetelemDumpReply<Prev> {
32406 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
32407 Self::write_header(&mut prev, header);
32408 Self::new_without_header(prev)
32409 }
32410 fn new_without_header(prev: Prev) -> Self {
32411 Self {
32412 prev: Some(prev),
32413 header_offset: None,
32414 }
32415 }
32416 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
32417 prev.as_rec_mut().extend(header.as_slice());
32418 }
32419 pub fn end_nested(mut self) -> Prev {
32420 let mut prev = self.prev.take().unwrap();
32421 if let Some(header_offset) = &self.header_offset {
32422 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32423 }
32424 prev
32425 }
32426 pub fn push_table(mut self, value: &CStr) -> Self {
32427 push_header(
32428 self.as_rec_mut(),
32429 1u16,
32430 value.to_bytes_with_nul().len() as u16,
32431 );
32432 self.as_rec_mut().extend(value.to_bytes_with_nul());
32433 self
32434 }
32435 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
32436 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
32437 self.as_rec_mut().extend(value);
32438 self.as_rec_mut().push(0);
32439 self
32440 }
32441 pub fn push_set(mut self, value: &CStr) -> Self {
32442 push_header(
32443 self.as_rec_mut(),
32444 2u16,
32445 value.to_bytes_with_nul().len() as u16,
32446 );
32447 self.as_rec_mut().extend(value.to_bytes_with_nul());
32448 self
32449 }
32450 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
32451 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
32452 self.as_rec_mut().extend(value);
32453 self.as_rec_mut().push(0);
32454 self
32455 }
32456 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
32457 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
32458 PushSetelemListElemAttrs {
32459 prev: Some(self),
32460 header_offset: Some(header_offset),
32461 }
32462 }
32463}
32464impl<Prev: Rec> Drop for PushOpGetsetelemDumpReply<Prev> {
32465 fn drop(&mut self) {
32466 if let Some(prev) = &mut self.prev {
32467 if let Some(header_offset) = &self.header_offset {
32468 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32469 }
32470 }
32471 }
32472}
32473#[doc = "Get / dump set elements."]
32474#[derive(Clone)]
32475pub enum OpGetsetelemDumpReply<'a> {
32476 Table(&'a CStr),
32477 Set(&'a CStr),
32478 Elements(IterableSetelemListElemAttrs<'a>),
32479}
32480impl<'a> IterableOpGetsetelemDumpReply<'a> {
32481 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
32482 let mut iter = self.clone();
32483 iter.pos = 0;
32484 for attr in iter {
32485 if let OpGetsetelemDumpReply::Table(val) = attr? {
32486 return Ok(val);
32487 }
32488 }
32489 Err(ErrorContext::new_missing(
32490 "OpGetsetelemDumpReply",
32491 "Table",
32492 self.orig_loc,
32493 self.buf.as_ptr() as usize,
32494 ))
32495 }
32496 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
32497 let mut iter = self.clone();
32498 iter.pos = 0;
32499 for attr in iter {
32500 if let OpGetsetelemDumpReply::Set(val) = attr? {
32501 return Ok(val);
32502 }
32503 }
32504 Err(ErrorContext::new_missing(
32505 "OpGetsetelemDumpReply",
32506 "Set",
32507 self.orig_loc,
32508 self.buf.as_ptr() as usize,
32509 ))
32510 }
32511 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
32512 let mut iter = self.clone();
32513 iter.pos = 0;
32514 for attr in iter {
32515 if let OpGetsetelemDumpReply::Elements(val) = attr? {
32516 return Ok(val);
32517 }
32518 }
32519 Err(ErrorContext::new_missing(
32520 "OpGetsetelemDumpReply",
32521 "Elements",
32522 self.orig_loc,
32523 self.buf.as_ptr() as usize,
32524 ))
32525 }
32526}
32527impl<'a> OpGetsetelemDumpReply<'a> {
32528 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetelemDumpReply<'a>) {
32529 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
32530 (
32531 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
32532 IterableOpGetsetelemDumpReply::with_loc(attrs, buf.as_ptr() as usize),
32533 )
32534 }
32535 fn attr_from_type(r#type: u16) -> Option<&'static str> {
32536 SetelemListAttrs::attr_from_type(r#type)
32537 }
32538}
32539#[derive(Clone, Copy, Default)]
32540pub struct IterableOpGetsetelemDumpReply<'a> {
32541 buf: &'a [u8],
32542 pos: usize,
32543 orig_loc: usize,
32544}
32545impl<'a> IterableOpGetsetelemDumpReply<'a> {
32546 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
32547 Self {
32548 buf,
32549 pos: 0,
32550 orig_loc,
32551 }
32552 }
32553 pub fn get_buf(&self) -> &'a [u8] {
32554 self.buf
32555 }
32556}
32557impl<'a> Iterator for IterableOpGetsetelemDumpReply<'a> {
32558 type Item = Result<OpGetsetelemDumpReply<'a>, ErrorContext>;
32559 fn next(&mut self) -> Option<Self::Item> {
32560 if self.buf.len() == self.pos {
32561 return None;
32562 }
32563 let pos = self.pos;
32564 let mut r#type = None;
32565 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
32566 r#type = Some(header.r#type);
32567 let res = match header.r#type {
32568 1u16 => OpGetsetelemDumpReply::Table({
32569 let res = CStr::from_bytes_with_nul(next).ok();
32570 let Some(val) = res else { break };
32571 val
32572 }),
32573 2u16 => OpGetsetelemDumpReply::Set({
32574 let res = CStr::from_bytes_with_nul(next).ok();
32575 let Some(val) = res else { break };
32576 val
32577 }),
32578 3u16 => OpGetsetelemDumpReply::Elements({
32579 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
32580 let Some(val) = res else { break };
32581 val
32582 }),
32583 n => {
32584 if cfg!(any(test, feature = "deny-unknown-attrs")) {
32585 break;
32586 } else {
32587 continue;
32588 }
32589 }
32590 };
32591 return Some(Ok(res));
32592 }
32593 Some(Err(ErrorContext::new(
32594 "OpGetsetelemDumpReply",
32595 r#type.and_then(|t| OpGetsetelemDumpReply::attr_from_type(t)),
32596 self.orig_loc,
32597 self.buf.as_ptr().wrapping_add(pos) as usize,
32598 )))
32599 }
32600}
32601impl<'a> std::fmt::Debug for IterableOpGetsetelemDumpReply<'_> {
32602 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32603 let mut fmt = f.debug_struct("OpGetsetelemDumpReply");
32604 for attr in self.clone() {
32605 let attr = match attr {
32606 Ok(a) => a,
32607 Err(err) => {
32608 fmt.finish()?;
32609 f.write_str("Err(")?;
32610 err.fmt(f)?;
32611 return f.write_str(")");
32612 }
32613 };
32614 match attr {
32615 OpGetsetelemDumpReply::Table(val) => fmt.field("Table", &val),
32616 OpGetsetelemDumpReply::Set(val) => fmt.field("Set", &val),
32617 OpGetsetelemDumpReply::Elements(val) => fmt.field("Elements", &val),
32618 };
32619 }
32620 fmt.finish()
32621 }
32622}
32623impl IterableOpGetsetelemDumpReply<'_> {
32624 pub fn lookup_attr(
32625 &self,
32626 offset: usize,
32627 missing_type: Option<u16>,
32628 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32629 let mut stack = Vec::new();
32630 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
32631 if cur == offset + PushNfgenmsg::len() {
32632 stack.push(("OpGetsetelemDumpReply", offset));
32633 return (
32634 stack,
32635 missing_type.and_then(|t| OpGetsetelemDumpReply::attr_from_type(t)),
32636 );
32637 }
32638 if cur > offset || cur + self.buf.len() < offset {
32639 return (stack, None);
32640 }
32641 let mut attrs = self.clone();
32642 let mut last_off = cur + attrs.pos;
32643 let mut missing = None;
32644 while let Some(attr) = attrs.next() {
32645 let Ok(attr) = attr else { break };
32646 match attr {
32647 OpGetsetelemDumpReply::Table(val) => {
32648 if last_off == offset {
32649 stack.push(("Table", last_off));
32650 break;
32651 }
32652 }
32653 OpGetsetelemDumpReply::Set(val) => {
32654 if last_off == offset {
32655 stack.push(("Set", last_off));
32656 break;
32657 }
32658 }
32659 OpGetsetelemDumpReply::Elements(val) => {
32660 (stack, missing) = val.lookup_attr(offset, missing_type);
32661 if !stack.is_empty() {
32662 break;
32663 }
32664 }
32665 _ => {}
32666 };
32667 last_off = cur + attrs.pos;
32668 }
32669 if !stack.is_empty() {
32670 stack.push(("OpGetsetelemDumpReply", cur));
32671 }
32672 (stack, missing)
32673 }
32674}
32675#[derive(Debug)]
32676pub struct RequestOpGetsetelemDumpRequest<'r> {
32677 request: Request<'r>,
32678}
32679impl<'r> RequestOpGetsetelemDumpRequest<'r> {
32680 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
32681 PushOpGetsetelemDumpRequest::write_header(&mut request.buf_mut(), header);
32682 Self {
32683 request: request.set_dump(),
32684 }
32685 }
32686 pub fn encode(&mut self) -> PushOpGetsetelemDumpRequest<&mut Vec<u8>> {
32687 PushOpGetsetelemDumpRequest::new_without_header(self.request.buf_mut())
32688 }
32689 pub fn into_encoder(self) -> PushOpGetsetelemDumpRequest<RequestBuf<'r>> {
32690 PushOpGetsetelemDumpRequest::new_without_header(self.request.buf)
32691 }
32692}
32693impl NetlinkRequest for RequestOpGetsetelemDumpRequest<'_> {
32694 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetsetelemDumpReply<'buf>);
32695 fn protocol(&self) -> Protocol {
32696 Protocol::Raw {
32697 protonum: 12u16,
32698 request_type: 2573u16,
32699 }
32700 }
32701 fn flags(&self) -> u16 {
32702 self.request.flags
32703 }
32704 fn payload(&self) -> &[u8] {
32705 self.request.buf()
32706 }
32707 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
32708 OpGetsetelemDumpReply::new(buf)
32709 }
32710 fn lookup(
32711 buf: &[u8],
32712 offset: usize,
32713 missing_type: Option<u16>,
32714 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32715 OpGetsetelemDumpRequest::new(buf)
32716 .1
32717 .lookup_attr(offset, missing_type)
32718 }
32719}
32720#[doc = "Get / dump set elements."]
32721pub struct PushOpGetsetelemDoRequest<Prev: Rec> {
32722 pub(crate) prev: Option<Prev>,
32723 pub(crate) header_offset: Option<usize>,
32724}
32725impl<Prev: Rec> Rec for PushOpGetsetelemDoRequest<Prev> {
32726 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
32727 self.prev.as_mut().unwrap().as_rec_mut()
32728 }
32729}
32730impl<Prev: Rec> PushOpGetsetelemDoRequest<Prev> {
32731 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
32732 Self::write_header(&mut prev, header);
32733 Self::new_without_header(prev)
32734 }
32735 fn new_without_header(prev: Prev) -> Self {
32736 Self {
32737 prev: Some(prev),
32738 header_offset: None,
32739 }
32740 }
32741 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
32742 prev.as_rec_mut().extend(header.as_slice());
32743 }
32744 pub fn end_nested(mut self) -> Prev {
32745 let mut prev = self.prev.take().unwrap();
32746 if let Some(header_offset) = &self.header_offset {
32747 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32748 }
32749 prev
32750 }
32751 pub fn push_table(mut self, value: &CStr) -> Self {
32752 push_header(
32753 self.as_rec_mut(),
32754 1u16,
32755 value.to_bytes_with_nul().len() as u16,
32756 );
32757 self.as_rec_mut().extend(value.to_bytes_with_nul());
32758 self
32759 }
32760 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
32761 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
32762 self.as_rec_mut().extend(value);
32763 self.as_rec_mut().push(0);
32764 self
32765 }
32766 pub fn push_set(mut self, value: &CStr) -> Self {
32767 push_header(
32768 self.as_rec_mut(),
32769 2u16,
32770 value.to_bytes_with_nul().len() as u16,
32771 );
32772 self.as_rec_mut().extend(value.to_bytes_with_nul());
32773 self
32774 }
32775 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
32776 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
32777 self.as_rec_mut().extend(value);
32778 self.as_rec_mut().push(0);
32779 self
32780 }
32781 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
32782 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
32783 PushSetelemListElemAttrs {
32784 prev: Some(self),
32785 header_offset: Some(header_offset),
32786 }
32787 }
32788}
32789impl<Prev: Rec> Drop for PushOpGetsetelemDoRequest<Prev> {
32790 fn drop(&mut self) {
32791 if let Some(prev) = &mut self.prev {
32792 if let Some(header_offset) = &self.header_offset {
32793 finalize_nested_header(prev.as_rec_mut(), *header_offset);
32794 }
32795 }
32796 }
32797}
32798#[doc = "Get / dump set elements."]
32799#[derive(Clone)]
32800pub enum OpGetsetelemDoRequest<'a> {
32801 Table(&'a CStr),
32802 Set(&'a CStr),
32803 Elements(IterableSetelemListElemAttrs<'a>),
32804}
32805impl<'a> IterableOpGetsetelemDoRequest<'a> {
32806 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
32807 let mut iter = self.clone();
32808 iter.pos = 0;
32809 for attr in iter {
32810 if let OpGetsetelemDoRequest::Table(val) = attr? {
32811 return Ok(val);
32812 }
32813 }
32814 Err(ErrorContext::new_missing(
32815 "OpGetsetelemDoRequest",
32816 "Table",
32817 self.orig_loc,
32818 self.buf.as_ptr() as usize,
32819 ))
32820 }
32821 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
32822 let mut iter = self.clone();
32823 iter.pos = 0;
32824 for attr in iter {
32825 if let OpGetsetelemDoRequest::Set(val) = attr? {
32826 return Ok(val);
32827 }
32828 }
32829 Err(ErrorContext::new_missing(
32830 "OpGetsetelemDoRequest",
32831 "Set",
32832 self.orig_loc,
32833 self.buf.as_ptr() as usize,
32834 ))
32835 }
32836 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
32837 let mut iter = self.clone();
32838 iter.pos = 0;
32839 for attr in iter {
32840 if let OpGetsetelemDoRequest::Elements(val) = attr? {
32841 return Ok(val);
32842 }
32843 }
32844 Err(ErrorContext::new_missing(
32845 "OpGetsetelemDoRequest",
32846 "Elements",
32847 self.orig_loc,
32848 self.buf.as_ptr() as usize,
32849 ))
32850 }
32851}
32852impl<'a> OpGetsetelemDoRequest<'a> {
32853 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetelemDoRequest<'a>) {
32854 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
32855 (
32856 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
32857 IterableOpGetsetelemDoRequest::with_loc(attrs, buf.as_ptr() as usize),
32858 )
32859 }
32860 fn attr_from_type(r#type: u16) -> Option<&'static str> {
32861 SetelemListAttrs::attr_from_type(r#type)
32862 }
32863}
32864#[derive(Clone, Copy, Default)]
32865pub struct IterableOpGetsetelemDoRequest<'a> {
32866 buf: &'a [u8],
32867 pos: usize,
32868 orig_loc: usize,
32869}
32870impl<'a> IterableOpGetsetelemDoRequest<'a> {
32871 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
32872 Self {
32873 buf,
32874 pos: 0,
32875 orig_loc,
32876 }
32877 }
32878 pub fn get_buf(&self) -> &'a [u8] {
32879 self.buf
32880 }
32881}
32882impl<'a> Iterator for IterableOpGetsetelemDoRequest<'a> {
32883 type Item = Result<OpGetsetelemDoRequest<'a>, ErrorContext>;
32884 fn next(&mut self) -> Option<Self::Item> {
32885 if self.buf.len() == self.pos {
32886 return None;
32887 }
32888 let pos = self.pos;
32889 let mut r#type = None;
32890 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
32891 r#type = Some(header.r#type);
32892 let res = match header.r#type {
32893 1u16 => OpGetsetelemDoRequest::Table({
32894 let res = CStr::from_bytes_with_nul(next).ok();
32895 let Some(val) = res else { break };
32896 val
32897 }),
32898 2u16 => OpGetsetelemDoRequest::Set({
32899 let res = CStr::from_bytes_with_nul(next).ok();
32900 let Some(val) = res else { break };
32901 val
32902 }),
32903 3u16 => OpGetsetelemDoRequest::Elements({
32904 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
32905 let Some(val) = res else { break };
32906 val
32907 }),
32908 n => {
32909 if cfg!(any(test, feature = "deny-unknown-attrs")) {
32910 break;
32911 } else {
32912 continue;
32913 }
32914 }
32915 };
32916 return Some(Ok(res));
32917 }
32918 Some(Err(ErrorContext::new(
32919 "OpGetsetelemDoRequest",
32920 r#type.and_then(|t| OpGetsetelemDoRequest::attr_from_type(t)),
32921 self.orig_loc,
32922 self.buf.as_ptr().wrapping_add(pos) as usize,
32923 )))
32924 }
32925}
32926impl<'a> std::fmt::Debug for IterableOpGetsetelemDoRequest<'_> {
32927 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32928 let mut fmt = f.debug_struct("OpGetsetelemDoRequest");
32929 for attr in self.clone() {
32930 let attr = match attr {
32931 Ok(a) => a,
32932 Err(err) => {
32933 fmt.finish()?;
32934 f.write_str("Err(")?;
32935 err.fmt(f)?;
32936 return f.write_str(")");
32937 }
32938 };
32939 match attr {
32940 OpGetsetelemDoRequest::Table(val) => fmt.field("Table", &val),
32941 OpGetsetelemDoRequest::Set(val) => fmt.field("Set", &val),
32942 OpGetsetelemDoRequest::Elements(val) => fmt.field("Elements", &val),
32943 };
32944 }
32945 fmt.finish()
32946 }
32947}
32948impl IterableOpGetsetelemDoRequest<'_> {
32949 pub fn lookup_attr(
32950 &self,
32951 offset: usize,
32952 missing_type: Option<u16>,
32953 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
32954 let mut stack = Vec::new();
32955 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
32956 if cur == offset + PushNfgenmsg::len() {
32957 stack.push(("OpGetsetelemDoRequest", offset));
32958 return (
32959 stack,
32960 missing_type.and_then(|t| OpGetsetelemDoRequest::attr_from_type(t)),
32961 );
32962 }
32963 if cur > offset || cur + self.buf.len() < offset {
32964 return (stack, None);
32965 }
32966 let mut attrs = self.clone();
32967 let mut last_off = cur + attrs.pos;
32968 let mut missing = None;
32969 while let Some(attr) = attrs.next() {
32970 let Ok(attr) = attr else { break };
32971 match attr {
32972 OpGetsetelemDoRequest::Table(val) => {
32973 if last_off == offset {
32974 stack.push(("Table", last_off));
32975 break;
32976 }
32977 }
32978 OpGetsetelemDoRequest::Set(val) => {
32979 if last_off == offset {
32980 stack.push(("Set", last_off));
32981 break;
32982 }
32983 }
32984 OpGetsetelemDoRequest::Elements(val) => {
32985 (stack, missing) = val.lookup_attr(offset, missing_type);
32986 if !stack.is_empty() {
32987 break;
32988 }
32989 }
32990 _ => {}
32991 };
32992 last_off = cur + attrs.pos;
32993 }
32994 if !stack.is_empty() {
32995 stack.push(("OpGetsetelemDoRequest", cur));
32996 }
32997 (stack, missing)
32998 }
32999}
33000#[doc = "Get / dump set elements."]
33001pub struct PushOpGetsetelemDoReply<Prev: Rec> {
33002 pub(crate) prev: Option<Prev>,
33003 pub(crate) header_offset: Option<usize>,
33004}
33005impl<Prev: Rec> Rec for PushOpGetsetelemDoReply<Prev> {
33006 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
33007 self.prev.as_mut().unwrap().as_rec_mut()
33008 }
33009}
33010impl<Prev: Rec> PushOpGetsetelemDoReply<Prev> {
33011 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
33012 Self::write_header(&mut prev, header);
33013 Self::new_without_header(prev)
33014 }
33015 fn new_without_header(prev: Prev) -> Self {
33016 Self {
33017 prev: Some(prev),
33018 header_offset: None,
33019 }
33020 }
33021 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
33022 prev.as_rec_mut().extend(header.as_slice());
33023 }
33024 pub fn end_nested(mut self) -> Prev {
33025 let mut prev = self.prev.take().unwrap();
33026 if let Some(header_offset) = &self.header_offset {
33027 finalize_nested_header(prev.as_rec_mut(), *header_offset);
33028 }
33029 prev
33030 }
33031 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
33032 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
33033 PushSetelemListElemAttrs {
33034 prev: Some(self),
33035 header_offset: Some(header_offset),
33036 }
33037 }
33038}
33039impl<Prev: Rec> Drop for PushOpGetsetelemDoReply<Prev> {
33040 fn drop(&mut self) {
33041 if let Some(prev) = &mut self.prev {
33042 if let Some(header_offset) = &self.header_offset {
33043 finalize_nested_header(prev.as_rec_mut(), *header_offset);
33044 }
33045 }
33046 }
33047}
33048#[doc = "Get / dump set elements."]
33049#[derive(Clone)]
33050pub enum OpGetsetelemDoReply<'a> {
33051 Elements(IterableSetelemListElemAttrs<'a>),
33052}
33053impl<'a> IterableOpGetsetelemDoReply<'a> {
33054 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
33055 let mut iter = self.clone();
33056 iter.pos = 0;
33057 for attr in iter {
33058 if let OpGetsetelemDoReply::Elements(val) = attr? {
33059 return Ok(val);
33060 }
33061 }
33062 Err(ErrorContext::new_missing(
33063 "OpGetsetelemDoReply",
33064 "Elements",
33065 self.orig_loc,
33066 self.buf.as_ptr() as usize,
33067 ))
33068 }
33069}
33070impl<'a> OpGetsetelemDoReply<'a> {
33071 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetelemDoReply<'a>) {
33072 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
33073 (
33074 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
33075 IterableOpGetsetelemDoReply::with_loc(attrs, buf.as_ptr() as usize),
33076 )
33077 }
33078 fn attr_from_type(r#type: u16) -> Option<&'static str> {
33079 SetelemListAttrs::attr_from_type(r#type)
33080 }
33081}
33082#[derive(Clone, Copy, Default)]
33083pub struct IterableOpGetsetelemDoReply<'a> {
33084 buf: &'a [u8],
33085 pos: usize,
33086 orig_loc: usize,
33087}
33088impl<'a> IterableOpGetsetelemDoReply<'a> {
33089 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
33090 Self {
33091 buf,
33092 pos: 0,
33093 orig_loc,
33094 }
33095 }
33096 pub fn get_buf(&self) -> &'a [u8] {
33097 self.buf
33098 }
33099}
33100impl<'a> Iterator for IterableOpGetsetelemDoReply<'a> {
33101 type Item = Result<OpGetsetelemDoReply<'a>, ErrorContext>;
33102 fn next(&mut self) -> Option<Self::Item> {
33103 if self.buf.len() == self.pos {
33104 return None;
33105 }
33106 let pos = self.pos;
33107 let mut r#type = None;
33108 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
33109 r#type = Some(header.r#type);
33110 let res = match header.r#type {
33111 3u16 => OpGetsetelemDoReply::Elements({
33112 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
33113 let Some(val) = res else { break };
33114 val
33115 }),
33116 n => {
33117 if cfg!(any(test, feature = "deny-unknown-attrs")) {
33118 break;
33119 } else {
33120 continue;
33121 }
33122 }
33123 };
33124 return Some(Ok(res));
33125 }
33126 Some(Err(ErrorContext::new(
33127 "OpGetsetelemDoReply",
33128 r#type.and_then(|t| OpGetsetelemDoReply::attr_from_type(t)),
33129 self.orig_loc,
33130 self.buf.as_ptr().wrapping_add(pos) as usize,
33131 )))
33132 }
33133}
33134impl<'a> std::fmt::Debug for IterableOpGetsetelemDoReply<'_> {
33135 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33136 let mut fmt = f.debug_struct("OpGetsetelemDoReply");
33137 for attr in self.clone() {
33138 let attr = match attr {
33139 Ok(a) => a,
33140 Err(err) => {
33141 fmt.finish()?;
33142 f.write_str("Err(")?;
33143 err.fmt(f)?;
33144 return f.write_str(")");
33145 }
33146 };
33147 match attr {
33148 OpGetsetelemDoReply::Elements(val) => fmt.field("Elements", &val),
33149 };
33150 }
33151 fmt.finish()
33152 }
33153}
33154impl IterableOpGetsetelemDoReply<'_> {
33155 pub fn lookup_attr(
33156 &self,
33157 offset: usize,
33158 missing_type: Option<u16>,
33159 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
33160 let mut stack = Vec::new();
33161 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
33162 if cur == offset + PushNfgenmsg::len() {
33163 stack.push(("OpGetsetelemDoReply", offset));
33164 return (
33165 stack,
33166 missing_type.and_then(|t| OpGetsetelemDoReply::attr_from_type(t)),
33167 );
33168 }
33169 if cur > offset || cur + self.buf.len() < offset {
33170 return (stack, None);
33171 }
33172 let mut attrs = self.clone();
33173 let mut last_off = cur + attrs.pos;
33174 let mut missing = None;
33175 while let Some(attr) = attrs.next() {
33176 let Ok(attr) = attr else { break };
33177 match attr {
33178 OpGetsetelemDoReply::Elements(val) => {
33179 (stack, missing) = val.lookup_attr(offset, missing_type);
33180 if !stack.is_empty() {
33181 break;
33182 }
33183 }
33184 _ => {}
33185 };
33186 last_off = cur + attrs.pos;
33187 }
33188 if !stack.is_empty() {
33189 stack.push(("OpGetsetelemDoReply", cur));
33190 }
33191 (stack, missing)
33192 }
33193}
33194#[derive(Debug)]
33195pub struct RequestOpGetsetelemDoRequest<'r> {
33196 request: Request<'r>,
33197}
33198impl<'r> RequestOpGetsetelemDoRequest<'r> {
33199 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
33200 PushOpGetsetelemDoRequest::write_header(&mut request.buf_mut(), header);
33201 Self { request: request }
33202 }
33203 pub fn encode(&mut self) -> PushOpGetsetelemDoRequest<&mut Vec<u8>> {
33204 PushOpGetsetelemDoRequest::new_without_header(self.request.buf_mut())
33205 }
33206 pub fn into_encoder(self) -> PushOpGetsetelemDoRequest<RequestBuf<'r>> {
33207 PushOpGetsetelemDoRequest::new_without_header(self.request.buf)
33208 }
33209}
33210impl NetlinkRequest for RequestOpGetsetelemDoRequest<'_> {
33211 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetsetelemDoReply<'buf>);
33212 fn protocol(&self) -> Protocol {
33213 Protocol::Raw {
33214 protonum: 12u16,
33215 request_type: 2573u16,
33216 }
33217 }
33218 fn flags(&self) -> u16 {
33219 self.request.flags
33220 }
33221 fn payload(&self) -> &[u8] {
33222 self.request.buf()
33223 }
33224 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
33225 OpGetsetelemDoReply::new(buf)
33226 }
33227 fn lookup(
33228 buf: &[u8],
33229 offset: usize,
33230 missing_type: Option<u16>,
33231 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
33232 OpGetsetelemDoRequest::new(buf)
33233 .1
33234 .lookup_attr(offset, missing_type)
33235 }
33236}
33237#[doc = "Get / dump set elements and reset stateful expressions."]
33238pub struct PushOpGetsetelemResetDumpRequest<Prev: Rec> {
33239 pub(crate) prev: Option<Prev>,
33240 pub(crate) header_offset: Option<usize>,
33241}
33242impl<Prev: Rec> Rec for PushOpGetsetelemResetDumpRequest<Prev> {
33243 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
33244 self.prev.as_mut().unwrap().as_rec_mut()
33245 }
33246}
33247impl<Prev: Rec> PushOpGetsetelemResetDumpRequest<Prev> {
33248 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
33249 Self::write_header(&mut prev, header);
33250 Self::new_without_header(prev)
33251 }
33252 fn new_without_header(prev: Prev) -> Self {
33253 Self {
33254 prev: Some(prev),
33255 header_offset: None,
33256 }
33257 }
33258 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
33259 prev.as_rec_mut().extend(header.as_slice());
33260 }
33261 pub fn end_nested(mut self) -> Prev {
33262 let mut prev = self.prev.take().unwrap();
33263 if let Some(header_offset) = &self.header_offset {
33264 finalize_nested_header(prev.as_rec_mut(), *header_offset);
33265 }
33266 prev
33267 }
33268 pub fn push_table(mut self, value: &CStr) -> Self {
33269 push_header(
33270 self.as_rec_mut(),
33271 1u16,
33272 value.to_bytes_with_nul().len() as u16,
33273 );
33274 self.as_rec_mut().extend(value.to_bytes_with_nul());
33275 self
33276 }
33277 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
33278 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
33279 self.as_rec_mut().extend(value);
33280 self.as_rec_mut().push(0);
33281 self
33282 }
33283 pub fn push_set(mut self, value: &CStr) -> Self {
33284 push_header(
33285 self.as_rec_mut(),
33286 2u16,
33287 value.to_bytes_with_nul().len() as u16,
33288 );
33289 self.as_rec_mut().extend(value.to_bytes_with_nul());
33290 self
33291 }
33292 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
33293 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
33294 self.as_rec_mut().extend(value);
33295 self.as_rec_mut().push(0);
33296 self
33297 }
33298}
33299impl<Prev: Rec> Drop for PushOpGetsetelemResetDumpRequest<Prev> {
33300 fn drop(&mut self) {
33301 if let Some(prev) = &mut self.prev {
33302 if let Some(header_offset) = &self.header_offset {
33303 finalize_nested_header(prev.as_rec_mut(), *header_offset);
33304 }
33305 }
33306 }
33307}
33308#[doc = "Get / dump set elements and reset stateful expressions."]
33309#[derive(Clone)]
33310pub enum OpGetsetelemResetDumpRequest<'a> {
33311 Table(&'a CStr),
33312 Set(&'a CStr),
33313}
33314impl<'a> IterableOpGetsetelemResetDumpRequest<'a> {
33315 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
33316 let mut iter = self.clone();
33317 iter.pos = 0;
33318 for attr in iter {
33319 if let OpGetsetelemResetDumpRequest::Table(val) = attr? {
33320 return Ok(val);
33321 }
33322 }
33323 Err(ErrorContext::new_missing(
33324 "OpGetsetelemResetDumpRequest",
33325 "Table",
33326 self.orig_loc,
33327 self.buf.as_ptr() as usize,
33328 ))
33329 }
33330 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
33331 let mut iter = self.clone();
33332 iter.pos = 0;
33333 for attr in iter {
33334 if let OpGetsetelemResetDumpRequest::Set(val) = attr? {
33335 return Ok(val);
33336 }
33337 }
33338 Err(ErrorContext::new_missing(
33339 "OpGetsetelemResetDumpRequest",
33340 "Set",
33341 self.orig_loc,
33342 self.buf.as_ptr() as usize,
33343 ))
33344 }
33345}
33346impl<'a> OpGetsetelemResetDumpRequest<'a> {
33347 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetelemResetDumpRequest<'a>) {
33348 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
33349 (
33350 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
33351 IterableOpGetsetelemResetDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
33352 )
33353 }
33354 fn attr_from_type(r#type: u16) -> Option<&'static str> {
33355 SetelemListAttrs::attr_from_type(r#type)
33356 }
33357}
33358#[derive(Clone, Copy, Default)]
33359pub struct IterableOpGetsetelemResetDumpRequest<'a> {
33360 buf: &'a [u8],
33361 pos: usize,
33362 orig_loc: usize,
33363}
33364impl<'a> IterableOpGetsetelemResetDumpRequest<'a> {
33365 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
33366 Self {
33367 buf,
33368 pos: 0,
33369 orig_loc,
33370 }
33371 }
33372 pub fn get_buf(&self) -> &'a [u8] {
33373 self.buf
33374 }
33375}
33376impl<'a> Iterator for IterableOpGetsetelemResetDumpRequest<'a> {
33377 type Item = Result<OpGetsetelemResetDumpRequest<'a>, ErrorContext>;
33378 fn next(&mut self) -> Option<Self::Item> {
33379 if self.buf.len() == self.pos {
33380 return None;
33381 }
33382 let pos = self.pos;
33383 let mut r#type = None;
33384 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
33385 r#type = Some(header.r#type);
33386 let res = match header.r#type {
33387 1u16 => OpGetsetelemResetDumpRequest::Table({
33388 let res = CStr::from_bytes_with_nul(next).ok();
33389 let Some(val) = res else { break };
33390 val
33391 }),
33392 2u16 => OpGetsetelemResetDumpRequest::Set({
33393 let res = CStr::from_bytes_with_nul(next).ok();
33394 let Some(val) = res else { break };
33395 val
33396 }),
33397 n => {
33398 if cfg!(any(test, feature = "deny-unknown-attrs")) {
33399 break;
33400 } else {
33401 continue;
33402 }
33403 }
33404 };
33405 return Some(Ok(res));
33406 }
33407 Some(Err(ErrorContext::new(
33408 "OpGetsetelemResetDumpRequest",
33409 r#type.and_then(|t| OpGetsetelemResetDumpRequest::attr_from_type(t)),
33410 self.orig_loc,
33411 self.buf.as_ptr().wrapping_add(pos) as usize,
33412 )))
33413 }
33414}
33415impl<'a> std::fmt::Debug for IterableOpGetsetelemResetDumpRequest<'_> {
33416 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33417 let mut fmt = f.debug_struct("OpGetsetelemResetDumpRequest");
33418 for attr in self.clone() {
33419 let attr = match attr {
33420 Ok(a) => a,
33421 Err(err) => {
33422 fmt.finish()?;
33423 f.write_str("Err(")?;
33424 err.fmt(f)?;
33425 return f.write_str(")");
33426 }
33427 };
33428 match attr {
33429 OpGetsetelemResetDumpRequest::Table(val) => fmt.field("Table", &val),
33430 OpGetsetelemResetDumpRequest::Set(val) => fmt.field("Set", &val),
33431 };
33432 }
33433 fmt.finish()
33434 }
33435}
33436impl IterableOpGetsetelemResetDumpRequest<'_> {
33437 pub fn lookup_attr(
33438 &self,
33439 offset: usize,
33440 missing_type: Option<u16>,
33441 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
33442 let mut stack = Vec::new();
33443 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
33444 if cur == offset + PushNfgenmsg::len() {
33445 stack.push(("OpGetsetelemResetDumpRequest", offset));
33446 return (
33447 stack,
33448 missing_type.and_then(|t| OpGetsetelemResetDumpRequest::attr_from_type(t)),
33449 );
33450 }
33451 if cur > offset || cur + self.buf.len() < offset {
33452 return (stack, None);
33453 }
33454 let mut attrs = self.clone();
33455 let mut last_off = cur + attrs.pos;
33456 while let Some(attr) = attrs.next() {
33457 let Ok(attr) = attr else { break };
33458 match attr {
33459 OpGetsetelemResetDumpRequest::Table(val) => {
33460 if last_off == offset {
33461 stack.push(("Table", last_off));
33462 break;
33463 }
33464 }
33465 OpGetsetelemResetDumpRequest::Set(val) => {
33466 if last_off == offset {
33467 stack.push(("Set", last_off));
33468 break;
33469 }
33470 }
33471 _ => {}
33472 };
33473 last_off = cur + attrs.pos;
33474 }
33475 if !stack.is_empty() {
33476 stack.push(("OpGetsetelemResetDumpRequest", cur));
33477 }
33478 (stack, None)
33479 }
33480}
33481#[doc = "Get / dump set elements and reset stateful expressions."]
33482pub struct PushOpGetsetelemResetDumpReply<Prev: Rec> {
33483 pub(crate) prev: Option<Prev>,
33484 pub(crate) header_offset: Option<usize>,
33485}
33486impl<Prev: Rec> Rec for PushOpGetsetelemResetDumpReply<Prev> {
33487 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
33488 self.prev.as_mut().unwrap().as_rec_mut()
33489 }
33490}
33491impl<Prev: Rec> PushOpGetsetelemResetDumpReply<Prev> {
33492 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
33493 Self::write_header(&mut prev, header);
33494 Self::new_without_header(prev)
33495 }
33496 fn new_without_header(prev: Prev) -> Self {
33497 Self {
33498 prev: Some(prev),
33499 header_offset: None,
33500 }
33501 }
33502 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
33503 prev.as_rec_mut().extend(header.as_slice());
33504 }
33505 pub fn end_nested(mut self) -> Prev {
33506 let mut prev = self.prev.take().unwrap();
33507 if let Some(header_offset) = &self.header_offset {
33508 finalize_nested_header(prev.as_rec_mut(), *header_offset);
33509 }
33510 prev
33511 }
33512 pub fn push_table(mut self, value: &CStr) -> Self {
33513 push_header(
33514 self.as_rec_mut(),
33515 1u16,
33516 value.to_bytes_with_nul().len() as u16,
33517 );
33518 self.as_rec_mut().extend(value.to_bytes_with_nul());
33519 self
33520 }
33521 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
33522 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
33523 self.as_rec_mut().extend(value);
33524 self.as_rec_mut().push(0);
33525 self
33526 }
33527 pub fn push_set(mut self, value: &CStr) -> Self {
33528 push_header(
33529 self.as_rec_mut(),
33530 2u16,
33531 value.to_bytes_with_nul().len() as u16,
33532 );
33533 self.as_rec_mut().extend(value.to_bytes_with_nul());
33534 self
33535 }
33536 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
33537 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
33538 self.as_rec_mut().extend(value);
33539 self.as_rec_mut().push(0);
33540 self
33541 }
33542 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
33543 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
33544 PushSetelemListElemAttrs {
33545 prev: Some(self),
33546 header_offset: Some(header_offset),
33547 }
33548 }
33549}
33550impl<Prev: Rec> Drop for PushOpGetsetelemResetDumpReply<Prev> {
33551 fn drop(&mut self) {
33552 if let Some(prev) = &mut self.prev {
33553 if let Some(header_offset) = &self.header_offset {
33554 finalize_nested_header(prev.as_rec_mut(), *header_offset);
33555 }
33556 }
33557 }
33558}
33559#[doc = "Get / dump set elements and reset stateful expressions."]
33560#[derive(Clone)]
33561pub enum OpGetsetelemResetDumpReply<'a> {
33562 Table(&'a CStr),
33563 Set(&'a CStr),
33564 Elements(IterableSetelemListElemAttrs<'a>),
33565}
33566impl<'a> IterableOpGetsetelemResetDumpReply<'a> {
33567 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
33568 let mut iter = self.clone();
33569 iter.pos = 0;
33570 for attr in iter {
33571 if let OpGetsetelemResetDumpReply::Table(val) = attr? {
33572 return Ok(val);
33573 }
33574 }
33575 Err(ErrorContext::new_missing(
33576 "OpGetsetelemResetDumpReply",
33577 "Table",
33578 self.orig_loc,
33579 self.buf.as_ptr() as usize,
33580 ))
33581 }
33582 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
33583 let mut iter = self.clone();
33584 iter.pos = 0;
33585 for attr in iter {
33586 if let OpGetsetelemResetDumpReply::Set(val) = attr? {
33587 return Ok(val);
33588 }
33589 }
33590 Err(ErrorContext::new_missing(
33591 "OpGetsetelemResetDumpReply",
33592 "Set",
33593 self.orig_loc,
33594 self.buf.as_ptr() as usize,
33595 ))
33596 }
33597 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
33598 let mut iter = self.clone();
33599 iter.pos = 0;
33600 for attr in iter {
33601 if let OpGetsetelemResetDumpReply::Elements(val) = attr? {
33602 return Ok(val);
33603 }
33604 }
33605 Err(ErrorContext::new_missing(
33606 "OpGetsetelemResetDumpReply",
33607 "Elements",
33608 self.orig_loc,
33609 self.buf.as_ptr() as usize,
33610 ))
33611 }
33612}
33613impl<'a> OpGetsetelemResetDumpReply<'a> {
33614 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetelemResetDumpReply<'a>) {
33615 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
33616 (
33617 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
33618 IterableOpGetsetelemResetDumpReply::with_loc(attrs, buf.as_ptr() as usize),
33619 )
33620 }
33621 fn attr_from_type(r#type: u16) -> Option<&'static str> {
33622 SetelemListAttrs::attr_from_type(r#type)
33623 }
33624}
33625#[derive(Clone, Copy, Default)]
33626pub struct IterableOpGetsetelemResetDumpReply<'a> {
33627 buf: &'a [u8],
33628 pos: usize,
33629 orig_loc: usize,
33630}
33631impl<'a> IterableOpGetsetelemResetDumpReply<'a> {
33632 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
33633 Self {
33634 buf,
33635 pos: 0,
33636 orig_loc,
33637 }
33638 }
33639 pub fn get_buf(&self) -> &'a [u8] {
33640 self.buf
33641 }
33642}
33643impl<'a> Iterator for IterableOpGetsetelemResetDumpReply<'a> {
33644 type Item = Result<OpGetsetelemResetDumpReply<'a>, ErrorContext>;
33645 fn next(&mut self) -> Option<Self::Item> {
33646 if self.buf.len() == self.pos {
33647 return None;
33648 }
33649 let pos = self.pos;
33650 let mut r#type = None;
33651 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
33652 r#type = Some(header.r#type);
33653 let res = match header.r#type {
33654 1u16 => OpGetsetelemResetDumpReply::Table({
33655 let res = CStr::from_bytes_with_nul(next).ok();
33656 let Some(val) = res else { break };
33657 val
33658 }),
33659 2u16 => OpGetsetelemResetDumpReply::Set({
33660 let res = CStr::from_bytes_with_nul(next).ok();
33661 let Some(val) = res else { break };
33662 val
33663 }),
33664 3u16 => OpGetsetelemResetDumpReply::Elements({
33665 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
33666 let Some(val) = res else { break };
33667 val
33668 }),
33669 n => {
33670 if cfg!(any(test, feature = "deny-unknown-attrs")) {
33671 break;
33672 } else {
33673 continue;
33674 }
33675 }
33676 };
33677 return Some(Ok(res));
33678 }
33679 Some(Err(ErrorContext::new(
33680 "OpGetsetelemResetDumpReply",
33681 r#type.and_then(|t| OpGetsetelemResetDumpReply::attr_from_type(t)),
33682 self.orig_loc,
33683 self.buf.as_ptr().wrapping_add(pos) as usize,
33684 )))
33685 }
33686}
33687impl<'a> std::fmt::Debug for IterableOpGetsetelemResetDumpReply<'_> {
33688 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33689 let mut fmt = f.debug_struct("OpGetsetelemResetDumpReply");
33690 for attr in self.clone() {
33691 let attr = match attr {
33692 Ok(a) => a,
33693 Err(err) => {
33694 fmt.finish()?;
33695 f.write_str("Err(")?;
33696 err.fmt(f)?;
33697 return f.write_str(")");
33698 }
33699 };
33700 match attr {
33701 OpGetsetelemResetDumpReply::Table(val) => fmt.field("Table", &val),
33702 OpGetsetelemResetDumpReply::Set(val) => fmt.field("Set", &val),
33703 OpGetsetelemResetDumpReply::Elements(val) => fmt.field("Elements", &val),
33704 };
33705 }
33706 fmt.finish()
33707 }
33708}
33709impl IterableOpGetsetelemResetDumpReply<'_> {
33710 pub fn lookup_attr(
33711 &self,
33712 offset: usize,
33713 missing_type: Option<u16>,
33714 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
33715 let mut stack = Vec::new();
33716 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
33717 if cur == offset + PushNfgenmsg::len() {
33718 stack.push(("OpGetsetelemResetDumpReply", offset));
33719 return (
33720 stack,
33721 missing_type.and_then(|t| OpGetsetelemResetDumpReply::attr_from_type(t)),
33722 );
33723 }
33724 if cur > offset || cur + self.buf.len() < offset {
33725 return (stack, None);
33726 }
33727 let mut attrs = self.clone();
33728 let mut last_off = cur + attrs.pos;
33729 let mut missing = None;
33730 while let Some(attr) = attrs.next() {
33731 let Ok(attr) = attr else { break };
33732 match attr {
33733 OpGetsetelemResetDumpReply::Table(val) => {
33734 if last_off == offset {
33735 stack.push(("Table", last_off));
33736 break;
33737 }
33738 }
33739 OpGetsetelemResetDumpReply::Set(val) => {
33740 if last_off == offset {
33741 stack.push(("Set", last_off));
33742 break;
33743 }
33744 }
33745 OpGetsetelemResetDumpReply::Elements(val) => {
33746 (stack, missing) = val.lookup_attr(offset, missing_type);
33747 if !stack.is_empty() {
33748 break;
33749 }
33750 }
33751 _ => {}
33752 };
33753 last_off = cur + attrs.pos;
33754 }
33755 if !stack.is_empty() {
33756 stack.push(("OpGetsetelemResetDumpReply", cur));
33757 }
33758 (stack, missing)
33759 }
33760}
33761#[derive(Debug)]
33762pub struct RequestOpGetsetelemResetDumpRequest<'r> {
33763 request: Request<'r>,
33764}
33765impl<'r> RequestOpGetsetelemResetDumpRequest<'r> {
33766 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
33767 PushOpGetsetelemResetDumpRequest::write_header(&mut request.buf_mut(), header);
33768 Self {
33769 request: request.set_dump(),
33770 }
33771 }
33772 pub fn encode(&mut self) -> PushOpGetsetelemResetDumpRequest<&mut Vec<u8>> {
33773 PushOpGetsetelemResetDumpRequest::new_without_header(self.request.buf_mut())
33774 }
33775 pub fn into_encoder(self) -> PushOpGetsetelemResetDumpRequest<RequestBuf<'r>> {
33776 PushOpGetsetelemResetDumpRequest::new_without_header(self.request.buf)
33777 }
33778}
33779impl NetlinkRequest for RequestOpGetsetelemResetDumpRequest<'_> {
33780 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetsetelemResetDumpReply<'buf>);
33781 fn protocol(&self) -> Protocol {
33782 Protocol::Raw {
33783 protonum: 12u16,
33784 request_type: 2593u16,
33785 }
33786 }
33787 fn flags(&self) -> u16 {
33788 self.request.flags
33789 }
33790 fn payload(&self) -> &[u8] {
33791 self.request.buf()
33792 }
33793 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
33794 OpGetsetelemResetDumpReply::new(buf)
33795 }
33796 fn lookup(
33797 buf: &[u8],
33798 offset: usize,
33799 missing_type: Option<u16>,
33800 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
33801 OpGetsetelemResetDumpRequest::new(buf)
33802 .1
33803 .lookup_attr(offset, missing_type)
33804 }
33805}
33806#[doc = "Get / dump set elements and reset stateful expressions."]
33807pub struct PushOpGetsetelemResetDoRequest<Prev: Rec> {
33808 pub(crate) prev: Option<Prev>,
33809 pub(crate) header_offset: Option<usize>,
33810}
33811impl<Prev: Rec> Rec for PushOpGetsetelemResetDoRequest<Prev> {
33812 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
33813 self.prev.as_mut().unwrap().as_rec_mut()
33814 }
33815}
33816impl<Prev: Rec> PushOpGetsetelemResetDoRequest<Prev> {
33817 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
33818 Self::write_header(&mut prev, header);
33819 Self::new_without_header(prev)
33820 }
33821 fn new_without_header(prev: Prev) -> Self {
33822 Self {
33823 prev: Some(prev),
33824 header_offset: None,
33825 }
33826 }
33827 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
33828 prev.as_rec_mut().extend(header.as_slice());
33829 }
33830 pub fn end_nested(mut self) -> Prev {
33831 let mut prev = self.prev.take().unwrap();
33832 if let Some(header_offset) = &self.header_offset {
33833 finalize_nested_header(prev.as_rec_mut(), *header_offset);
33834 }
33835 prev
33836 }
33837 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
33838 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
33839 PushSetelemListElemAttrs {
33840 prev: Some(self),
33841 header_offset: Some(header_offset),
33842 }
33843 }
33844}
33845impl<Prev: Rec> Drop for PushOpGetsetelemResetDoRequest<Prev> {
33846 fn drop(&mut self) {
33847 if let Some(prev) = &mut self.prev {
33848 if let Some(header_offset) = &self.header_offset {
33849 finalize_nested_header(prev.as_rec_mut(), *header_offset);
33850 }
33851 }
33852 }
33853}
33854#[doc = "Get / dump set elements and reset stateful expressions."]
33855#[derive(Clone)]
33856pub enum OpGetsetelemResetDoRequest<'a> {
33857 Elements(IterableSetelemListElemAttrs<'a>),
33858}
33859impl<'a> IterableOpGetsetelemResetDoRequest<'a> {
33860 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
33861 let mut iter = self.clone();
33862 iter.pos = 0;
33863 for attr in iter {
33864 if let OpGetsetelemResetDoRequest::Elements(val) = attr? {
33865 return Ok(val);
33866 }
33867 }
33868 Err(ErrorContext::new_missing(
33869 "OpGetsetelemResetDoRequest",
33870 "Elements",
33871 self.orig_loc,
33872 self.buf.as_ptr() as usize,
33873 ))
33874 }
33875}
33876impl<'a> OpGetsetelemResetDoRequest<'a> {
33877 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetelemResetDoRequest<'a>) {
33878 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
33879 (
33880 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
33881 IterableOpGetsetelemResetDoRequest::with_loc(attrs, buf.as_ptr() as usize),
33882 )
33883 }
33884 fn attr_from_type(r#type: u16) -> Option<&'static str> {
33885 SetelemListAttrs::attr_from_type(r#type)
33886 }
33887}
33888#[derive(Clone, Copy, Default)]
33889pub struct IterableOpGetsetelemResetDoRequest<'a> {
33890 buf: &'a [u8],
33891 pos: usize,
33892 orig_loc: usize,
33893}
33894impl<'a> IterableOpGetsetelemResetDoRequest<'a> {
33895 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
33896 Self {
33897 buf,
33898 pos: 0,
33899 orig_loc,
33900 }
33901 }
33902 pub fn get_buf(&self) -> &'a [u8] {
33903 self.buf
33904 }
33905}
33906impl<'a> Iterator for IterableOpGetsetelemResetDoRequest<'a> {
33907 type Item = Result<OpGetsetelemResetDoRequest<'a>, ErrorContext>;
33908 fn next(&mut self) -> Option<Self::Item> {
33909 if self.buf.len() == self.pos {
33910 return None;
33911 }
33912 let pos = self.pos;
33913 let mut r#type = None;
33914 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
33915 r#type = Some(header.r#type);
33916 let res = match header.r#type {
33917 3u16 => OpGetsetelemResetDoRequest::Elements({
33918 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
33919 let Some(val) = res else { break };
33920 val
33921 }),
33922 n => {
33923 if cfg!(any(test, feature = "deny-unknown-attrs")) {
33924 break;
33925 } else {
33926 continue;
33927 }
33928 }
33929 };
33930 return Some(Ok(res));
33931 }
33932 Some(Err(ErrorContext::new(
33933 "OpGetsetelemResetDoRequest",
33934 r#type.and_then(|t| OpGetsetelemResetDoRequest::attr_from_type(t)),
33935 self.orig_loc,
33936 self.buf.as_ptr().wrapping_add(pos) as usize,
33937 )))
33938 }
33939}
33940impl<'a> std::fmt::Debug for IterableOpGetsetelemResetDoRequest<'_> {
33941 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33942 let mut fmt = f.debug_struct("OpGetsetelemResetDoRequest");
33943 for attr in self.clone() {
33944 let attr = match attr {
33945 Ok(a) => a,
33946 Err(err) => {
33947 fmt.finish()?;
33948 f.write_str("Err(")?;
33949 err.fmt(f)?;
33950 return f.write_str(")");
33951 }
33952 };
33953 match attr {
33954 OpGetsetelemResetDoRequest::Elements(val) => fmt.field("Elements", &val),
33955 };
33956 }
33957 fmt.finish()
33958 }
33959}
33960impl IterableOpGetsetelemResetDoRequest<'_> {
33961 pub fn lookup_attr(
33962 &self,
33963 offset: usize,
33964 missing_type: Option<u16>,
33965 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
33966 let mut stack = Vec::new();
33967 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
33968 if cur == offset + PushNfgenmsg::len() {
33969 stack.push(("OpGetsetelemResetDoRequest", offset));
33970 return (
33971 stack,
33972 missing_type.and_then(|t| OpGetsetelemResetDoRequest::attr_from_type(t)),
33973 );
33974 }
33975 if cur > offset || cur + self.buf.len() < offset {
33976 return (stack, None);
33977 }
33978 let mut attrs = self.clone();
33979 let mut last_off = cur + attrs.pos;
33980 let mut missing = None;
33981 while let Some(attr) = attrs.next() {
33982 let Ok(attr) = attr else { break };
33983 match attr {
33984 OpGetsetelemResetDoRequest::Elements(val) => {
33985 (stack, missing) = val.lookup_attr(offset, missing_type);
33986 if !stack.is_empty() {
33987 break;
33988 }
33989 }
33990 _ => {}
33991 };
33992 last_off = cur + attrs.pos;
33993 }
33994 if !stack.is_empty() {
33995 stack.push(("OpGetsetelemResetDoRequest", cur));
33996 }
33997 (stack, missing)
33998 }
33999}
34000#[doc = "Get / dump set elements and reset stateful expressions."]
34001pub struct PushOpGetsetelemResetDoReply<Prev: Rec> {
34002 pub(crate) prev: Option<Prev>,
34003 pub(crate) header_offset: Option<usize>,
34004}
34005impl<Prev: Rec> Rec for PushOpGetsetelemResetDoReply<Prev> {
34006 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
34007 self.prev.as_mut().unwrap().as_rec_mut()
34008 }
34009}
34010impl<Prev: Rec> PushOpGetsetelemResetDoReply<Prev> {
34011 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
34012 Self::write_header(&mut prev, header);
34013 Self::new_without_header(prev)
34014 }
34015 fn new_without_header(prev: Prev) -> Self {
34016 Self {
34017 prev: Some(prev),
34018 header_offset: None,
34019 }
34020 }
34021 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
34022 prev.as_rec_mut().extend(header.as_slice());
34023 }
34024 pub fn end_nested(mut self) -> Prev {
34025 let mut prev = self.prev.take().unwrap();
34026 if let Some(header_offset) = &self.header_offset {
34027 finalize_nested_header(prev.as_rec_mut(), *header_offset);
34028 }
34029 prev
34030 }
34031 pub fn push_table(mut self, value: &CStr) -> Self {
34032 push_header(
34033 self.as_rec_mut(),
34034 1u16,
34035 value.to_bytes_with_nul().len() as u16,
34036 );
34037 self.as_rec_mut().extend(value.to_bytes_with_nul());
34038 self
34039 }
34040 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
34041 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
34042 self.as_rec_mut().extend(value);
34043 self.as_rec_mut().push(0);
34044 self
34045 }
34046 pub fn push_set(mut self, value: &CStr) -> Self {
34047 push_header(
34048 self.as_rec_mut(),
34049 2u16,
34050 value.to_bytes_with_nul().len() as u16,
34051 );
34052 self.as_rec_mut().extend(value.to_bytes_with_nul());
34053 self
34054 }
34055 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
34056 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
34057 self.as_rec_mut().extend(value);
34058 self.as_rec_mut().push(0);
34059 self
34060 }
34061 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
34062 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
34063 PushSetelemListElemAttrs {
34064 prev: Some(self),
34065 header_offset: Some(header_offset),
34066 }
34067 }
34068}
34069impl<Prev: Rec> Drop for PushOpGetsetelemResetDoReply<Prev> {
34070 fn drop(&mut self) {
34071 if let Some(prev) = &mut self.prev {
34072 if let Some(header_offset) = &self.header_offset {
34073 finalize_nested_header(prev.as_rec_mut(), *header_offset);
34074 }
34075 }
34076 }
34077}
34078#[doc = "Get / dump set elements and reset stateful expressions."]
34079#[derive(Clone)]
34080pub enum OpGetsetelemResetDoReply<'a> {
34081 Table(&'a CStr),
34082 Set(&'a CStr),
34083 Elements(IterableSetelemListElemAttrs<'a>),
34084}
34085impl<'a> IterableOpGetsetelemResetDoReply<'a> {
34086 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
34087 let mut iter = self.clone();
34088 iter.pos = 0;
34089 for attr in iter {
34090 if let OpGetsetelemResetDoReply::Table(val) = attr? {
34091 return Ok(val);
34092 }
34093 }
34094 Err(ErrorContext::new_missing(
34095 "OpGetsetelemResetDoReply",
34096 "Table",
34097 self.orig_loc,
34098 self.buf.as_ptr() as usize,
34099 ))
34100 }
34101 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
34102 let mut iter = self.clone();
34103 iter.pos = 0;
34104 for attr in iter {
34105 if let OpGetsetelemResetDoReply::Set(val) = attr? {
34106 return Ok(val);
34107 }
34108 }
34109 Err(ErrorContext::new_missing(
34110 "OpGetsetelemResetDoReply",
34111 "Set",
34112 self.orig_loc,
34113 self.buf.as_ptr() as usize,
34114 ))
34115 }
34116 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
34117 let mut iter = self.clone();
34118 iter.pos = 0;
34119 for attr in iter {
34120 if let OpGetsetelemResetDoReply::Elements(val) = attr? {
34121 return Ok(val);
34122 }
34123 }
34124 Err(ErrorContext::new_missing(
34125 "OpGetsetelemResetDoReply",
34126 "Elements",
34127 self.orig_loc,
34128 self.buf.as_ptr() as usize,
34129 ))
34130 }
34131}
34132impl<'a> OpGetsetelemResetDoReply<'a> {
34133 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetsetelemResetDoReply<'a>) {
34134 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
34135 (
34136 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
34137 IterableOpGetsetelemResetDoReply::with_loc(attrs, buf.as_ptr() as usize),
34138 )
34139 }
34140 fn attr_from_type(r#type: u16) -> Option<&'static str> {
34141 SetelemListAttrs::attr_from_type(r#type)
34142 }
34143}
34144#[derive(Clone, Copy, Default)]
34145pub struct IterableOpGetsetelemResetDoReply<'a> {
34146 buf: &'a [u8],
34147 pos: usize,
34148 orig_loc: usize,
34149}
34150impl<'a> IterableOpGetsetelemResetDoReply<'a> {
34151 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
34152 Self {
34153 buf,
34154 pos: 0,
34155 orig_loc,
34156 }
34157 }
34158 pub fn get_buf(&self) -> &'a [u8] {
34159 self.buf
34160 }
34161}
34162impl<'a> Iterator for IterableOpGetsetelemResetDoReply<'a> {
34163 type Item = Result<OpGetsetelemResetDoReply<'a>, ErrorContext>;
34164 fn next(&mut self) -> Option<Self::Item> {
34165 if self.buf.len() == self.pos {
34166 return None;
34167 }
34168 let pos = self.pos;
34169 let mut r#type = None;
34170 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
34171 r#type = Some(header.r#type);
34172 let res = match header.r#type {
34173 1u16 => OpGetsetelemResetDoReply::Table({
34174 let res = CStr::from_bytes_with_nul(next).ok();
34175 let Some(val) = res else { break };
34176 val
34177 }),
34178 2u16 => OpGetsetelemResetDoReply::Set({
34179 let res = CStr::from_bytes_with_nul(next).ok();
34180 let Some(val) = res else { break };
34181 val
34182 }),
34183 3u16 => OpGetsetelemResetDoReply::Elements({
34184 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
34185 let Some(val) = res else { break };
34186 val
34187 }),
34188 n => {
34189 if cfg!(any(test, feature = "deny-unknown-attrs")) {
34190 break;
34191 } else {
34192 continue;
34193 }
34194 }
34195 };
34196 return Some(Ok(res));
34197 }
34198 Some(Err(ErrorContext::new(
34199 "OpGetsetelemResetDoReply",
34200 r#type.and_then(|t| OpGetsetelemResetDoReply::attr_from_type(t)),
34201 self.orig_loc,
34202 self.buf.as_ptr().wrapping_add(pos) as usize,
34203 )))
34204 }
34205}
34206impl<'a> std::fmt::Debug for IterableOpGetsetelemResetDoReply<'_> {
34207 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34208 let mut fmt = f.debug_struct("OpGetsetelemResetDoReply");
34209 for attr in self.clone() {
34210 let attr = match attr {
34211 Ok(a) => a,
34212 Err(err) => {
34213 fmt.finish()?;
34214 f.write_str("Err(")?;
34215 err.fmt(f)?;
34216 return f.write_str(")");
34217 }
34218 };
34219 match attr {
34220 OpGetsetelemResetDoReply::Table(val) => fmt.field("Table", &val),
34221 OpGetsetelemResetDoReply::Set(val) => fmt.field("Set", &val),
34222 OpGetsetelemResetDoReply::Elements(val) => fmt.field("Elements", &val),
34223 };
34224 }
34225 fmt.finish()
34226 }
34227}
34228impl IterableOpGetsetelemResetDoReply<'_> {
34229 pub fn lookup_attr(
34230 &self,
34231 offset: usize,
34232 missing_type: Option<u16>,
34233 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
34234 let mut stack = Vec::new();
34235 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
34236 if cur == offset + PushNfgenmsg::len() {
34237 stack.push(("OpGetsetelemResetDoReply", offset));
34238 return (
34239 stack,
34240 missing_type.and_then(|t| OpGetsetelemResetDoReply::attr_from_type(t)),
34241 );
34242 }
34243 if cur > offset || cur + self.buf.len() < offset {
34244 return (stack, None);
34245 }
34246 let mut attrs = self.clone();
34247 let mut last_off = cur + attrs.pos;
34248 let mut missing = None;
34249 while let Some(attr) = attrs.next() {
34250 let Ok(attr) = attr else { break };
34251 match attr {
34252 OpGetsetelemResetDoReply::Table(val) => {
34253 if last_off == offset {
34254 stack.push(("Table", last_off));
34255 break;
34256 }
34257 }
34258 OpGetsetelemResetDoReply::Set(val) => {
34259 if last_off == offset {
34260 stack.push(("Set", last_off));
34261 break;
34262 }
34263 }
34264 OpGetsetelemResetDoReply::Elements(val) => {
34265 (stack, missing) = val.lookup_attr(offset, missing_type);
34266 if !stack.is_empty() {
34267 break;
34268 }
34269 }
34270 _ => {}
34271 };
34272 last_off = cur + attrs.pos;
34273 }
34274 if !stack.is_empty() {
34275 stack.push(("OpGetsetelemResetDoReply", cur));
34276 }
34277 (stack, missing)
34278 }
34279}
34280#[derive(Debug)]
34281pub struct RequestOpGetsetelemResetDoRequest<'r> {
34282 request: Request<'r>,
34283}
34284impl<'r> RequestOpGetsetelemResetDoRequest<'r> {
34285 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
34286 PushOpGetsetelemResetDoRequest::write_header(&mut request.buf_mut(), header);
34287 Self { request: request }
34288 }
34289 pub fn encode(&mut self) -> PushOpGetsetelemResetDoRequest<&mut Vec<u8>> {
34290 PushOpGetsetelemResetDoRequest::new_without_header(self.request.buf_mut())
34291 }
34292 pub fn into_encoder(self) -> PushOpGetsetelemResetDoRequest<RequestBuf<'r>> {
34293 PushOpGetsetelemResetDoRequest::new_without_header(self.request.buf)
34294 }
34295}
34296impl NetlinkRequest for RequestOpGetsetelemResetDoRequest<'_> {
34297 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetsetelemResetDoReply<'buf>);
34298 fn protocol(&self) -> Protocol {
34299 Protocol::Raw {
34300 protonum: 12u16,
34301 request_type: 2593u16,
34302 }
34303 }
34304 fn flags(&self) -> u16 {
34305 self.request.flags
34306 }
34307 fn payload(&self) -> &[u8] {
34308 self.request.buf()
34309 }
34310 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
34311 OpGetsetelemResetDoReply::new(buf)
34312 }
34313 fn lookup(
34314 buf: &[u8],
34315 offset: usize,
34316 missing_type: Option<u16>,
34317 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
34318 OpGetsetelemResetDoRequest::new(buf)
34319 .1
34320 .lookup_attr(offset, missing_type)
34321 }
34322}
34323#[doc = "Delete an existing set element."]
34324pub struct PushOpDelsetelemDoRequest<Prev: Rec> {
34325 pub(crate) prev: Option<Prev>,
34326 pub(crate) header_offset: Option<usize>,
34327}
34328impl<Prev: Rec> Rec for PushOpDelsetelemDoRequest<Prev> {
34329 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
34330 self.prev.as_mut().unwrap().as_rec_mut()
34331 }
34332}
34333impl<Prev: Rec> PushOpDelsetelemDoRequest<Prev> {
34334 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
34335 Self::write_header(&mut prev, header);
34336 Self::new_without_header(prev)
34337 }
34338 fn new_without_header(prev: Prev) -> Self {
34339 Self {
34340 prev: Some(prev),
34341 header_offset: None,
34342 }
34343 }
34344 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
34345 prev.as_rec_mut().extend(header.as_slice());
34346 }
34347 pub fn end_nested(mut self) -> Prev {
34348 let mut prev = self.prev.take().unwrap();
34349 if let Some(header_offset) = &self.header_offset {
34350 finalize_nested_header(prev.as_rec_mut(), *header_offset);
34351 }
34352 prev
34353 }
34354 pub fn push_table(mut self, value: &CStr) -> Self {
34355 push_header(
34356 self.as_rec_mut(),
34357 1u16,
34358 value.to_bytes_with_nul().len() as u16,
34359 );
34360 self.as_rec_mut().extend(value.to_bytes_with_nul());
34361 self
34362 }
34363 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
34364 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
34365 self.as_rec_mut().extend(value);
34366 self.as_rec_mut().push(0);
34367 self
34368 }
34369 pub fn push_set(mut self, value: &CStr) -> Self {
34370 push_header(
34371 self.as_rec_mut(),
34372 2u16,
34373 value.to_bytes_with_nul().len() as u16,
34374 );
34375 self.as_rec_mut().extend(value.to_bytes_with_nul());
34376 self
34377 }
34378 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
34379 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
34380 self.as_rec_mut().extend(value);
34381 self.as_rec_mut().push(0);
34382 self
34383 }
34384 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
34385 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
34386 PushSetelemListElemAttrs {
34387 prev: Some(self),
34388 header_offset: Some(header_offset),
34389 }
34390 }
34391}
34392impl<Prev: Rec> Drop for PushOpDelsetelemDoRequest<Prev> {
34393 fn drop(&mut self) {
34394 if let Some(prev) = &mut self.prev {
34395 if let Some(header_offset) = &self.header_offset {
34396 finalize_nested_header(prev.as_rec_mut(), *header_offset);
34397 }
34398 }
34399 }
34400}
34401#[doc = "Delete an existing set element."]
34402#[derive(Clone)]
34403pub enum OpDelsetelemDoRequest<'a> {
34404 Table(&'a CStr),
34405 Set(&'a CStr),
34406 Elements(IterableSetelemListElemAttrs<'a>),
34407}
34408impl<'a> IterableOpDelsetelemDoRequest<'a> {
34409 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
34410 let mut iter = self.clone();
34411 iter.pos = 0;
34412 for attr in iter {
34413 if let OpDelsetelemDoRequest::Table(val) = attr? {
34414 return Ok(val);
34415 }
34416 }
34417 Err(ErrorContext::new_missing(
34418 "OpDelsetelemDoRequest",
34419 "Table",
34420 self.orig_loc,
34421 self.buf.as_ptr() as usize,
34422 ))
34423 }
34424 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
34425 let mut iter = self.clone();
34426 iter.pos = 0;
34427 for attr in iter {
34428 if let OpDelsetelemDoRequest::Set(val) = attr? {
34429 return Ok(val);
34430 }
34431 }
34432 Err(ErrorContext::new_missing(
34433 "OpDelsetelemDoRequest",
34434 "Set",
34435 self.orig_loc,
34436 self.buf.as_ptr() as usize,
34437 ))
34438 }
34439 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
34440 let mut iter = self.clone();
34441 iter.pos = 0;
34442 for attr in iter {
34443 if let OpDelsetelemDoRequest::Elements(val) = attr? {
34444 return Ok(val);
34445 }
34446 }
34447 Err(ErrorContext::new_missing(
34448 "OpDelsetelemDoRequest",
34449 "Elements",
34450 self.orig_loc,
34451 self.buf.as_ptr() as usize,
34452 ))
34453 }
34454}
34455impl<'a> OpDelsetelemDoRequest<'a> {
34456 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDelsetelemDoRequest<'a>) {
34457 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
34458 (
34459 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
34460 IterableOpDelsetelemDoRequest::with_loc(attrs, buf.as_ptr() as usize),
34461 )
34462 }
34463 fn attr_from_type(r#type: u16) -> Option<&'static str> {
34464 SetelemListAttrs::attr_from_type(r#type)
34465 }
34466}
34467#[derive(Clone, Copy, Default)]
34468pub struct IterableOpDelsetelemDoRequest<'a> {
34469 buf: &'a [u8],
34470 pos: usize,
34471 orig_loc: usize,
34472}
34473impl<'a> IterableOpDelsetelemDoRequest<'a> {
34474 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
34475 Self {
34476 buf,
34477 pos: 0,
34478 orig_loc,
34479 }
34480 }
34481 pub fn get_buf(&self) -> &'a [u8] {
34482 self.buf
34483 }
34484}
34485impl<'a> Iterator for IterableOpDelsetelemDoRequest<'a> {
34486 type Item = Result<OpDelsetelemDoRequest<'a>, ErrorContext>;
34487 fn next(&mut self) -> Option<Self::Item> {
34488 if self.buf.len() == self.pos {
34489 return None;
34490 }
34491 let pos = self.pos;
34492 let mut r#type = None;
34493 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
34494 r#type = Some(header.r#type);
34495 let res = match header.r#type {
34496 1u16 => OpDelsetelemDoRequest::Table({
34497 let res = CStr::from_bytes_with_nul(next).ok();
34498 let Some(val) = res else { break };
34499 val
34500 }),
34501 2u16 => OpDelsetelemDoRequest::Set({
34502 let res = CStr::from_bytes_with_nul(next).ok();
34503 let Some(val) = res else { break };
34504 val
34505 }),
34506 3u16 => OpDelsetelemDoRequest::Elements({
34507 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
34508 let Some(val) = res else { break };
34509 val
34510 }),
34511 n => {
34512 if cfg!(any(test, feature = "deny-unknown-attrs")) {
34513 break;
34514 } else {
34515 continue;
34516 }
34517 }
34518 };
34519 return Some(Ok(res));
34520 }
34521 Some(Err(ErrorContext::new(
34522 "OpDelsetelemDoRequest",
34523 r#type.and_then(|t| OpDelsetelemDoRequest::attr_from_type(t)),
34524 self.orig_loc,
34525 self.buf.as_ptr().wrapping_add(pos) as usize,
34526 )))
34527 }
34528}
34529impl<'a> std::fmt::Debug for IterableOpDelsetelemDoRequest<'_> {
34530 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34531 let mut fmt = f.debug_struct("OpDelsetelemDoRequest");
34532 for attr in self.clone() {
34533 let attr = match attr {
34534 Ok(a) => a,
34535 Err(err) => {
34536 fmt.finish()?;
34537 f.write_str("Err(")?;
34538 err.fmt(f)?;
34539 return f.write_str(")");
34540 }
34541 };
34542 match attr {
34543 OpDelsetelemDoRequest::Table(val) => fmt.field("Table", &val),
34544 OpDelsetelemDoRequest::Set(val) => fmt.field("Set", &val),
34545 OpDelsetelemDoRequest::Elements(val) => fmt.field("Elements", &val),
34546 };
34547 }
34548 fmt.finish()
34549 }
34550}
34551impl IterableOpDelsetelemDoRequest<'_> {
34552 pub fn lookup_attr(
34553 &self,
34554 offset: usize,
34555 missing_type: Option<u16>,
34556 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
34557 let mut stack = Vec::new();
34558 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
34559 if cur == offset + PushNfgenmsg::len() {
34560 stack.push(("OpDelsetelemDoRequest", offset));
34561 return (
34562 stack,
34563 missing_type.and_then(|t| OpDelsetelemDoRequest::attr_from_type(t)),
34564 );
34565 }
34566 if cur > offset || cur + self.buf.len() < offset {
34567 return (stack, None);
34568 }
34569 let mut attrs = self.clone();
34570 let mut last_off = cur + attrs.pos;
34571 let mut missing = None;
34572 while let Some(attr) = attrs.next() {
34573 let Ok(attr) = attr else { break };
34574 match attr {
34575 OpDelsetelemDoRequest::Table(val) => {
34576 if last_off == offset {
34577 stack.push(("Table", last_off));
34578 break;
34579 }
34580 }
34581 OpDelsetelemDoRequest::Set(val) => {
34582 if last_off == offset {
34583 stack.push(("Set", last_off));
34584 break;
34585 }
34586 }
34587 OpDelsetelemDoRequest::Elements(val) => {
34588 (stack, missing) = val.lookup_attr(offset, missing_type);
34589 if !stack.is_empty() {
34590 break;
34591 }
34592 }
34593 _ => {}
34594 };
34595 last_off = cur + attrs.pos;
34596 }
34597 if !stack.is_empty() {
34598 stack.push(("OpDelsetelemDoRequest", cur));
34599 }
34600 (stack, missing)
34601 }
34602}
34603#[doc = "Delete an existing set element."]
34604pub struct PushOpDelsetelemDoReply<Prev: Rec> {
34605 pub(crate) prev: Option<Prev>,
34606 pub(crate) header_offset: Option<usize>,
34607}
34608impl<Prev: Rec> Rec for PushOpDelsetelemDoReply<Prev> {
34609 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
34610 self.prev.as_mut().unwrap().as_rec_mut()
34611 }
34612}
34613impl<Prev: Rec> PushOpDelsetelemDoReply<Prev> {
34614 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
34615 Self::write_header(&mut prev, header);
34616 Self::new_without_header(prev)
34617 }
34618 fn new_without_header(prev: Prev) -> Self {
34619 Self {
34620 prev: Some(prev),
34621 header_offset: None,
34622 }
34623 }
34624 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
34625 prev.as_rec_mut().extend(header.as_slice());
34626 }
34627 pub fn end_nested(mut self) -> Prev {
34628 let mut prev = self.prev.take().unwrap();
34629 if let Some(header_offset) = &self.header_offset {
34630 finalize_nested_header(prev.as_rec_mut(), *header_offset);
34631 }
34632 prev
34633 }
34634}
34635impl<Prev: Rec> Drop for PushOpDelsetelemDoReply<Prev> {
34636 fn drop(&mut self) {
34637 if let Some(prev) = &mut self.prev {
34638 if let Some(header_offset) = &self.header_offset {
34639 finalize_nested_header(prev.as_rec_mut(), *header_offset);
34640 }
34641 }
34642 }
34643}
34644#[doc = "Delete an existing set element."]
34645#[derive(Clone)]
34646pub enum OpDelsetelemDoReply {}
34647impl<'a> IterableOpDelsetelemDoReply<'a> {}
34648impl OpDelsetelemDoReply {
34649 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDelsetelemDoReply<'_>) {
34650 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
34651 (
34652 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
34653 IterableOpDelsetelemDoReply::with_loc(attrs, buf.as_ptr() as usize),
34654 )
34655 }
34656 fn attr_from_type(r#type: u16) -> Option<&'static str> {
34657 SetelemListAttrs::attr_from_type(r#type)
34658 }
34659}
34660#[derive(Clone, Copy, Default)]
34661pub struct IterableOpDelsetelemDoReply<'a> {
34662 buf: &'a [u8],
34663 pos: usize,
34664 orig_loc: usize,
34665}
34666impl<'a> IterableOpDelsetelemDoReply<'a> {
34667 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
34668 Self {
34669 buf,
34670 pos: 0,
34671 orig_loc,
34672 }
34673 }
34674 pub fn get_buf(&self) -> &'a [u8] {
34675 self.buf
34676 }
34677}
34678impl<'a> Iterator for IterableOpDelsetelemDoReply<'a> {
34679 type Item = Result<OpDelsetelemDoReply, ErrorContext>;
34680 fn next(&mut self) -> Option<Self::Item> {
34681 if self.buf.len() == self.pos {
34682 return None;
34683 }
34684 let pos = self.pos;
34685 let mut r#type = None;
34686 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
34687 r#type = Some(header.r#type);
34688 let res = match header.r#type {
34689 n => {
34690 if cfg!(any(test, feature = "deny-unknown-attrs")) {
34691 break;
34692 } else {
34693 continue;
34694 }
34695 }
34696 };
34697 return Some(Ok(res));
34698 }
34699 Some(Err(ErrorContext::new(
34700 "OpDelsetelemDoReply",
34701 r#type.and_then(|t| OpDelsetelemDoReply::attr_from_type(t)),
34702 self.orig_loc,
34703 self.buf.as_ptr().wrapping_add(pos) as usize,
34704 )))
34705 }
34706}
34707impl std::fmt::Debug for IterableOpDelsetelemDoReply<'_> {
34708 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34709 let mut fmt = f.debug_struct("OpDelsetelemDoReply");
34710 for attr in self.clone() {
34711 let attr = match attr {
34712 Ok(a) => a,
34713 Err(err) => {
34714 fmt.finish()?;
34715 f.write_str("Err(")?;
34716 err.fmt(f)?;
34717 return f.write_str(")");
34718 }
34719 };
34720 match attr {};
34721 }
34722 fmt.finish()
34723 }
34724}
34725impl IterableOpDelsetelemDoReply<'_> {
34726 pub fn lookup_attr(
34727 &self,
34728 offset: usize,
34729 missing_type: Option<u16>,
34730 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
34731 let mut stack = Vec::new();
34732 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
34733 if cur == offset + PushNfgenmsg::len() {
34734 stack.push(("OpDelsetelemDoReply", offset));
34735 return (
34736 stack,
34737 missing_type.and_then(|t| OpDelsetelemDoReply::attr_from_type(t)),
34738 );
34739 }
34740 (stack, None)
34741 }
34742}
34743#[derive(Debug)]
34744pub struct RequestOpDelsetelemDoRequest<'r> {
34745 request: Request<'r>,
34746}
34747impl<'r> RequestOpDelsetelemDoRequest<'r> {
34748 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
34749 PushOpDelsetelemDoRequest::write_header(&mut request.buf_mut(), header);
34750 Self { request: request }
34751 }
34752 pub fn encode(&mut self) -> PushOpDelsetelemDoRequest<&mut Vec<u8>> {
34753 PushOpDelsetelemDoRequest::new_without_header(self.request.buf_mut())
34754 }
34755 pub fn into_encoder(self) -> PushOpDelsetelemDoRequest<RequestBuf<'r>> {
34756 PushOpDelsetelemDoRequest::new_without_header(self.request.buf)
34757 }
34758}
34759impl NetlinkRequest for RequestOpDelsetelemDoRequest<'_> {
34760 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDelsetelemDoReply<'buf>);
34761 fn protocol(&self) -> Protocol {
34762 Protocol::Raw {
34763 protonum: 12u16,
34764 request_type: 2574u16,
34765 }
34766 }
34767 fn flags(&self) -> u16 {
34768 self.request.flags
34769 }
34770 fn payload(&self) -> &[u8] {
34771 self.request.buf()
34772 }
34773 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
34774 OpDelsetelemDoReply::new(buf)
34775 }
34776 fn lookup(
34777 buf: &[u8],
34778 offset: usize,
34779 missing_type: Option<u16>,
34780 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
34781 OpDelsetelemDoRequest::new(buf)
34782 .1
34783 .lookup_attr(offset, missing_type)
34784 }
34785}
34786#[doc = "Delete an existing set element with destroy semantics."]
34787pub struct PushOpDestroysetelemDoRequest<Prev: Rec> {
34788 pub(crate) prev: Option<Prev>,
34789 pub(crate) header_offset: Option<usize>,
34790}
34791impl<Prev: Rec> Rec for PushOpDestroysetelemDoRequest<Prev> {
34792 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
34793 self.prev.as_mut().unwrap().as_rec_mut()
34794 }
34795}
34796impl<Prev: Rec> PushOpDestroysetelemDoRequest<Prev> {
34797 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
34798 Self::write_header(&mut prev, header);
34799 Self::new_without_header(prev)
34800 }
34801 fn new_without_header(prev: Prev) -> Self {
34802 Self {
34803 prev: Some(prev),
34804 header_offset: None,
34805 }
34806 }
34807 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
34808 prev.as_rec_mut().extend(header.as_slice());
34809 }
34810 pub fn end_nested(mut self) -> Prev {
34811 let mut prev = self.prev.take().unwrap();
34812 if let Some(header_offset) = &self.header_offset {
34813 finalize_nested_header(prev.as_rec_mut(), *header_offset);
34814 }
34815 prev
34816 }
34817 pub fn push_table(mut self, value: &CStr) -> Self {
34818 push_header(
34819 self.as_rec_mut(),
34820 1u16,
34821 value.to_bytes_with_nul().len() as u16,
34822 );
34823 self.as_rec_mut().extend(value.to_bytes_with_nul());
34824 self
34825 }
34826 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
34827 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
34828 self.as_rec_mut().extend(value);
34829 self.as_rec_mut().push(0);
34830 self
34831 }
34832 pub fn push_set(mut self, value: &CStr) -> Self {
34833 push_header(
34834 self.as_rec_mut(),
34835 2u16,
34836 value.to_bytes_with_nul().len() as u16,
34837 );
34838 self.as_rec_mut().extend(value.to_bytes_with_nul());
34839 self
34840 }
34841 pub fn push_set_bytes(mut self, value: &[u8]) -> Self {
34842 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
34843 self.as_rec_mut().extend(value);
34844 self.as_rec_mut().push(0);
34845 self
34846 }
34847 pub fn nested_elements(mut self) -> PushSetelemListElemAttrs<Self> {
34848 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
34849 PushSetelemListElemAttrs {
34850 prev: Some(self),
34851 header_offset: Some(header_offset),
34852 }
34853 }
34854}
34855impl<Prev: Rec> Drop for PushOpDestroysetelemDoRequest<Prev> {
34856 fn drop(&mut self) {
34857 if let Some(prev) = &mut self.prev {
34858 if let Some(header_offset) = &self.header_offset {
34859 finalize_nested_header(prev.as_rec_mut(), *header_offset);
34860 }
34861 }
34862 }
34863}
34864#[doc = "Delete an existing set element with destroy semantics."]
34865#[derive(Clone)]
34866pub enum OpDestroysetelemDoRequest<'a> {
34867 Table(&'a CStr),
34868 Set(&'a CStr),
34869 Elements(IterableSetelemListElemAttrs<'a>),
34870}
34871impl<'a> IterableOpDestroysetelemDoRequest<'a> {
34872 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
34873 let mut iter = self.clone();
34874 iter.pos = 0;
34875 for attr in iter {
34876 if let OpDestroysetelemDoRequest::Table(val) = attr? {
34877 return Ok(val);
34878 }
34879 }
34880 Err(ErrorContext::new_missing(
34881 "OpDestroysetelemDoRequest",
34882 "Table",
34883 self.orig_loc,
34884 self.buf.as_ptr() as usize,
34885 ))
34886 }
34887 pub fn get_set(&self) -> Result<&'a CStr, ErrorContext> {
34888 let mut iter = self.clone();
34889 iter.pos = 0;
34890 for attr in iter {
34891 if let OpDestroysetelemDoRequest::Set(val) = attr? {
34892 return Ok(val);
34893 }
34894 }
34895 Err(ErrorContext::new_missing(
34896 "OpDestroysetelemDoRequest",
34897 "Set",
34898 self.orig_loc,
34899 self.buf.as_ptr() as usize,
34900 ))
34901 }
34902 pub fn get_elements(&self) -> Result<IterableSetelemListElemAttrs<'a>, ErrorContext> {
34903 let mut iter = self.clone();
34904 iter.pos = 0;
34905 for attr in iter {
34906 if let OpDestroysetelemDoRequest::Elements(val) = attr? {
34907 return Ok(val);
34908 }
34909 }
34910 Err(ErrorContext::new_missing(
34911 "OpDestroysetelemDoRequest",
34912 "Elements",
34913 self.orig_loc,
34914 self.buf.as_ptr() as usize,
34915 ))
34916 }
34917}
34918impl<'a> OpDestroysetelemDoRequest<'a> {
34919 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDestroysetelemDoRequest<'a>) {
34920 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
34921 (
34922 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
34923 IterableOpDestroysetelemDoRequest::with_loc(attrs, buf.as_ptr() as usize),
34924 )
34925 }
34926 fn attr_from_type(r#type: u16) -> Option<&'static str> {
34927 SetelemListAttrs::attr_from_type(r#type)
34928 }
34929}
34930#[derive(Clone, Copy, Default)]
34931pub struct IterableOpDestroysetelemDoRequest<'a> {
34932 buf: &'a [u8],
34933 pos: usize,
34934 orig_loc: usize,
34935}
34936impl<'a> IterableOpDestroysetelemDoRequest<'a> {
34937 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
34938 Self {
34939 buf,
34940 pos: 0,
34941 orig_loc,
34942 }
34943 }
34944 pub fn get_buf(&self) -> &'a [u8] {
34945 self.buf
34946 }
34947}
34948impl<'a> Iterator for IterableOpDestroysetelemDoRequest<'a> {
34949 type Item = Result<OpDestroysetelemDoRequest<'a>, ErrorContext>;
34950 fn next(&mut self) -> Option<Self::Item> {
34951 if self.buf.len() == self.pos {
34952 return None;
34953 }
34954 let pos = self.pos;
34955 let mut r#type = None;
34956 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
34957 r#type = Some(header.r#type);
34958 let res = match header.r#type {
34959 1u16 => OpDestroysetelemDoRequest::Table({
34960 let res = CStr::from_bytes_with_nul(next).ok();
34961 let Some(val) = res else { break };
34962 val
34963 }),
34964 2u16 => OpDestroysetelemDoRequest::Set({
34965 let res = CStr::from_bytes_with_nul(next).ok();
34966 let Some(val) = res else { break };
34967 val
34968 }),
34969 3u16 => OpDestroysetelemDoRequest::Elements({
34970 let res = Some(IterableSetelemListElemAttrs::with_loc(next, self.orig_loc));
34971 let Some(val) = res else { break };
34972 val
34973 }),
34974 n => {
34975 if cfg!(any(test, feature = "deny-unknown-attrs")) {
34976 break;
34977 } else {
34978 continue;
34979 }
34980 }
34981 };
34982 return Some(Ok(res));
34983 }
34984 Some(Err(ErrorContext::new(
34985 "OpDestroysetelemDoRequest",
34986 r#type.and_then(|t| OpDestroysetelemDoRequest::attr_from_type(t)),
34987 self.orig_loc,
34988 self.buf.as_ptr().wrapping_add(pos) as usize,
34989 )))
34990 }
34991}
34992impl<'a> std::fmt::Debug for IterableOpDestroysetelemDoRequest<'_> {
34993 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34994 let mut fmt = f.debug_struct("OpDestroysetelemDoRequest");
34995 for attr in self.clone() {
34996 let attr = match attr {
34997 Ok(a) => a,
34998 Err(err) => {
34999 fmt.finish()?;
35000 f.write_str("Err(")?;
35001 err.fmt(f)?;
35002 return f.write_str(")");
35003 }
35004 };
35005 match attr {
35006 OpDestroysetelemDoRequest::Table(val) => fmt.field("Table", &val),
35007 OpDestroysetelemDoRequest::Set(val) => fmt.field("Set", &val),
35008 OpDestroysetelemDoRequest::Elements(val) => fmt.field("Elements", &val),
35009 };
35010 }
35011 fmt.finish()
35012 }
35013}
35014impl IterableOpDestroysetelemDoRequest<'_> {
35015 pub fn lookup_attr(
35016 &self,
35017 offset: usize,
35018 missing_type: Option<u16>,
35019 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
35020 let mut stack = Vec::new();
35021 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
35022 if cur == offset + PushNfgenmsg::len() {
35023 stack.push(("OpDestroysetelemDoRequest", offset));
35024 return (
35025 stack,
35026 missing_type.and_then(|t| OpDestroysetelemDoRequest::attr_from_type(t)),
35027 );
35028 }
35029 if cur > offset || cur + self.buf.len() < offset {
35030 return (stack, None);
35031 }
35032 let mut attrs = self.clone();
35033 let mut last_off = cur + attrs.pos;
35034 let mut missing = None;
35035 while let Some(attr) = attrs.next() {
35036 let Ok(attr) = attr else { break };
35037 match attr {
35038 OpDestroysetelemDoRequest::Table(val) => {
35039 if last_off == offset {
35040 stack.push(("Table", last_off));
35041 break;
35042 }
35043 }
35044 OpDestroysetelemDoRequest::Set(val) => {
35045 if last_off == offset {
35046 stack.push(("Set", last_off));
35047 break;
35048 }
35049 }
35050 OpDestroysetelemDoRequest::Elements(val) => {
35051 (stack, missing) = val.lookup_attr(offset, missing_type);
35052 if !stack.is_empty() {
35053 break;
35054 }
35055 }
35056 _ => {}
35057 };
35058 last_off = cur + attrs.pos;
35059 }
35060 if !stack.is_empty() {
35061 stack.push(("OpDestroysetelemDoRequest", cur));
35062 }
35063 (stack, missing)
35064 }
35065}
35066#[doc = "Delete an existing set element with destroy semantics."]
35067pub struct PushOpDestroysetelemDoReply<Prev: Rec> {
35068 pub(crate) prev: Option<Prev>,
35069 pub(crate) header_offset: Option<usize>,
35070}
35071impl<Prev: Rec> Rec for PushOpDestroysetelemDoReply<Prev> {
35072 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
35073 self.prev.as_mut().unwrap().as_rec_mut()
35074 }
35075}
35076impl<Prev: Rec> PushOpDestroysetelemDoReply<Prev> {
35077 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
35078 Self::write_header(&mut prev, header);
35079 Self::new_without_header(prev)
35080 }
35081 fn new_without_header(prev: Prev) -> Self {
35082 Self {
35083 prev: Some(prev),
35084 header_offset: None,
35085 }
35086 }
35087 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
35088 prev.as_rec_mut().extend(header.as_slice());
35089 }
35090 pub fn end_nested(mut self) -> Prev {
35091 let mut prev = self.prev.take().unwrap();
35092 if let Some(header_offset) = &self.header_offset {
35093 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35094 }
35095 prev
35096 }
35097}
35098impl<Prev: Rec> Drop for PushOpDestroysetelemDoReply<Prev> {
35099 fn drop(&mut self) {
35100 if let Some(prev) = &mut self.prev {
35101 if let Some(header_offset) = &self.header_offset {
35102 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35103 }
35104 }
35105 }
35106}
35107#[doc = "Delete an existing set element with destroy semantics."]
35108#[derive(Clone)]
35109pub enum OpDestroysetelemDoReply {}
35110impl<'a> IterableOpDestroysetelemDoReply<'a> {}
35111impl OpDestroysetelemDoReply {
35112 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDestroysetelemDoReply<'_>) {
35113 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
35114 (
35115 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
35116 IterableOpDestroysetelemDoReply::with_loc(attrs, buf.as_ptr() as usize),
35117 )
35118 }
35119 fn attr_from_type(r#type: u16) -> Option<&'static str> {
35120 SetelemListAttrs::attr_from_type(r#type)
35121 }
35122}
35123#[derive(Clone, Copy, Default)]
35124pub struct IterableOpDestroysetelemDoReply<'a> {
35125 buf: &'a [u8],
35126 pos: usize,
35127 orig_loc: usize,
35128}
35129impl<'a> IterableOpDestroysetelemDoReply<'a> {
35130 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
35131 Self {
35132 buf,
35133 pos: 0,
35134 orig_loc,
35135 }
35136 }
35137 pub fn get_buf(&self) -> &'a [u8] {
35138 self.buf
35139 }
35140}
35141impl<'a> Iterator for IterableOpDestroysetelemDoReply<'a> {
35142 type Item = Result<OpDestroysetelemDoReply, ErrorContext>;
35143 fn next(&mut self) -> Option<Self::Item> {
35144 if self.buf.len() == self.pos {
35145 return None;
35146 }
35147 let pos = self.pos;
35148 let mut r#type = None;
35149 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
35150 r#type = Some(header.r#type);
35151 let res = match header.r#type {
35152 n => {
35153 if cfg!(any(test, feature = "deny-unknown-attrs")) {
35154 break;
35155 } else {
35156 continue;
35157 }
35158 }
35159 };
35160 return Some(Ok(res));
35161 }
35162 Some(Err(ErrorContext::new(
35163 "OpDestroysetelemDoReply",
35164 r#type.and_then(|t| OpDestroysetelemDoReply::attr_from_type(t)),
35165 self.orig_loc,
35166 self.buf.as_ptr().wrapping_add(pos) as usize,
35167 )))
35168 }
35169}
35170impl std::fmt::Debug for IterableOpDestroysetelemDoReply<'_> {
35171 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35172 let mut fmt = f.debug_struct("OpDestroysetelemDoReply");
35173 for attr in self.clone() {
35174 let attr = match attr {
35175 Ok(a) => a,
35176 Err(err) => {
35177 fmt.finish()?;
35178 f.write_str("Err(")?;
35179 err.fmt(f)?;
35180 return f.write_str(")");
35181 }
35182 };
35183 match attr {};
35184 }
35185 fmt.finish()
35186 }
35187}
35188impl IterableOpDestroysetelemDoReply<'_> {
35189 pub fn lookup_attr(
35190 &self,
35191 offset: usize,
35192 missing_type: Option<u16>,
35193 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
35194 let mut stack = Vec::new();
35195 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
35196 if cur == offset + PushNfgenmsg::len() {
35197 stack.push(("OpDestroysetelemDoReply", offset));
35198 return (
35199 stack,
35200 missing_type.and_then(|t| OpDestroysetelemDoReply::attr_from_type(t)),
35201 );
35202 }
35203 (stack, None)
35204 }
35205}
35206#[derive(Debug)]
35207pub struct RequestOpDestroysetelemDoRequest<'r> {
35208 request: Request<'r>,
35209}
35210impl<'r> RequestOpDestroysetelemDoRequest<'r> {
35211 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
35212 PushOpDestroysetelemDoRequest::write_header(&mut request.buf_mut(), header);
35213 Self { request: request }
35214 }
35215 pub fn encode(&mut self) -> PushOpDestroysetelemDoRequest<&mut Vec<u8>> {
35216 PushOpDestroysetelemDoRequest::new_without_header(self.request.buf_mut())
35217 }
35218 pub fn into_encoder(self) -> PushOpDestroysetelemDoRequest<RequestBuf<'r>> {
35219 PushOpDestroysetelemDoRequest::new_without_header(self.request.buf)
35220 }
35221}
35222impl NetlinkRequest for RequestOpDestroysetelemDoRequest<'_> {
35223 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDestroysetelemDoReply<'buf>);
35224 fn protocol(&self) -> Protocol {
35225 Protocol::Raw {
35226 protonum: 12u16,
35227 request_type: 2590u16,
35228 }
35229 }
35230 fn flags(&self) -> u16 {
35231 self.request.flags
35232 }
35233 fn payload(&self) -> &[u8] {
35234 self.request.buf()
35235 }
35236 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
35237 OpDestroysetelemDoReply::new(buf)
35238 }
35239 fn lookup(
35240 buf: &[u8],
35241 offset: usize,
35242 missing_type: Option<u16>,
35243 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
35244 OpDestroysetelemDoRequest::new(buf)
35245 .1
35246 .lookup_attr(offset, missing_type)
35247 }
35248}
35249#[doc = "Get / dump rule-set generation."]
35250pub struct PushOpGetgenDumpRequest<Prev: Rec> {
35251 pub(crate) prev: Option<Prev>,
35252 pub(crate) header_offset: Option<usize>,
35253}
35254impl<Prev: Rec> Rec for PushOpGetgenDumpRequest<Prev> {
35255 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
35256 self.prev.as_mut().unwrap().as_rec_mut()
35257 }
35258}
35259impl<Prev: Rec> PushOpGetgenDumpRequest<Prev> {
35260 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
35261 Self::write_header(&mut prev, header);
35262 Self::new_without_header(prev)
35263 }
35264 fn new_without_header(prev: Prev) -> Self {
35265 Self {
35266 prev: Some(prev),
35267 header_offset: None,
35268 }
35269 }
35270 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
35271 prev.as_rec_mut().extend(header.as_slice());
35272 }
35273 pub fn end_nested(mut self) -> Prev {
35274 let mut prev = self.prev.take().unwrap();
35275 if let Some(header_offset) = &self.header_offset {
35276 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35277 }
35278 prev
35279 }
35280}
35281impl<Prev: Rec> Drop for PushOpGetgenDumpRequest<Prev> {
35282 fn drop(&mut self) {
35283 if let Some(prev) = &mut self.prev {
35284 if let Some(header_offset) = &self.header_offset {
35285 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35286 }
35287 }
35288 }
35289}
35290#[doc = "Get / dump rule-set generation."]
35291#[derive(Clone)]
35292pub enum OpGetgenDumpRequest {}
35293impl<'a> IterableOpGetgenDumpRequest<'a> {}
35294impl OpGetgenDumpRequest {
35295 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpGetgenDumpRequest<'_>) {
35296 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
35297 (
35298 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
35299 IterableOpGetgenDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
35300 )
35301 }
35302 fn attr_from_type(r#type: u16) -> Option<&'static str> {
35303 GenAttrs::attr_from_type(r#type)
35304 }
35305}
35306#[derive(Clone, Copy, Default)]
35307pub struct IterableOpGetgenDumpRequest<'a> {
35308 buf: &'a [u8],
35309 pos: usize,
35310 orig_loc: usize,
35311}
35312impl<'a> IterableOpGetgenDumpRequest<'a> {
35313 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
35314 Self {
35315 buf,
35316 pos: 0,
35317 orig_loc,
35318 }
35319 }
35320 pub fn get_buf(&self) -> &'a [u8] {
35321 self.buf
35322 }
35323}
35324impl<'a> Iterator for IterableOpGetgenDumpRequest<'a> {
35325 type Item = Result<OpGetgenDumpRequest, ErrorContext>;
35326 fn next(&mut self) -> Option<Self::Item> {
35327 if self.buf.len() == self.pos {
35328 return None;
35329 }
35330 let pos = self.pos;
35331 let mut r#type = None;
35332 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
35333 r#type = Some(header.r#type);
35334 let res = match header.r#type {
35335 n => {
35336 if cfg!(any(test, feature = "deny-unknown-attrs")) {
35337 break;
35338 } else {
35339 continue;
35340 }
35341 }
35342 };
35343 return Some(Ok(res));
35344 }
35345 Some(Err(ErrorContext::new(
35346 "OpGetgenDumpRequest",
35347 r#type.and_then(|t| OpGetgenDumpRequest::attr_from_type(t)),
35348 self.orig_loc,
35349 self.buf.as_ptr().wrapping_add(pos) as usize,
35350 )))
35351 }
35352}
35353impl std::fmt::Debug for IterableOpGetgenDumpRequest<'_> {
35354 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35355 let mut fmt = f.debug_struct("OpGetgenDumpRequest");
35356 for attr in self.clone() {
35357 let attr = match attr {
35358 Ok(a) => a,
35359 Err(err) => {
35360 fmt.finish()?;
35361 f.write_str("Err(")?;
35362 err.fmt(f)?;
35363 return f.write_str(")");
35364 }
35365 };
35366 match attr {};
35367 }
35368 fmt.finish()
35369 }
35370}
35371impl IterableOpGetgenDumpRequest<'_> {
35372 pub fn lookup_attr(
35373 &self,
35374 offset: usize,
35375 missing_type: Option<u16>,
35376 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
35377 let mut stack = Vec::new();
35378 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
35379 if cur == offset + PushNfgenmsg::len() {
35380 stack.push(("OpGetgenDumpRequest", offset));
35381 return (
35382 stack,
35383 missing_type.and_then(|t| OpGetgenDumpRequest::attr_from_type(t)),
35384 );
35385 }
35386 (stack, None)
35387 }
35388}
35389#[doc = "Get / dump rule-set generation."]
35390pub struct PushOpGetgenDumpReply<Prev: Rec> {
35391 pub(crate) prev: Option<Prev>,
35392 pub(crate) header_offset: Option<usize>,
35393}
35394impl<Prev: Rec> Rec for PushOpGetgenDumpReply<Prev> {
35395 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
35396 self.prev.as_mut().unwrap().as_rec_mut()
35397 }
35398}
35399impl<Prev: Rec> PushOpGetgenDumpReply<Prev> {
35400 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
35401 Self::write_header(&mut prev, header);
35402 Self::new_without_header(prev)
35403 }
35404 fn new_without_header(prev: Prev) -> Self {
35405 Self {
35406 prev: Some(prev),
35407 header_offset: None,
35408 }
35409 }
35410 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
35411 prev.as_rec_mut().extend(header.as_slice());
35412 }
35413 pub fn end_nested(mut self) -> Prev {
35414 let mut prev = self.prev.take().unwrap();
35415 if let Some(header_offset) = &self.header_offset {
35416 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35417 }
35418 prev
35419 }
35420 #[doc = "ruleset generation id"]
35421 pub fn push_id(mut self, value: u32) -> Self {
35422 push_header(self.as_rec_mut(), 1u16, 4 as u16);
35423 self.as_rec_mut().extend(value.to_be_bytes());
35424 self
35425 }
35426 pub fn push_proc_pid(mut self, value: u32) -> Self {
35427 push_header(self.as_rec_mut(), 2u16, 4 as u16);
35428 self.as_rec_mut().extend(value.to_be_bytes());
35429 self
35430 }
35431 pub fn push_proc_name(mut self, value: &CStr) -> Self {
35432 push_header(
35433 self.as_rec_mut(),
35434 3u16,
35435 value.to_bytes_with_nul().len() as u16,
35436 );
35437 self.as_rec_mut().extend(value.to_bytes_with_nul());
35438 self
35439 }
35440 pub fn push_proc_name_bytes(mut self, value: &[u8]) -> Self {
35441 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
35442 self.as_rec_mut().extend(value);
35443 self.as_rec_mut().push(0);
35444 self
35445 }
35446}
35447impl<Prev: Rec> Drop for PushOpGetgenDumpReply<Prev> {
35448 fn drop(&mut self) {
35449 if let Some(prev) = &mut self.prev {
35450 if let Some(header_offset) = &self.header_offset {
35451 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35452 }
35453 }
35454 }
35455}
35456#[doc = "Get / dump rule-set generation."]
35457#[derive(Clone)]
35458pub enum OpGetgenDumpReply<'a> {
35459 #[doc = "ruleset generation id"]
35460 Id(u32),
35461 ProcPid(u32),
35462 ProcName(&'a CStr),
35463}
35464impl<'a> IterableOpGetgenDumpReply<'a> {
35465 #[doc = "ruleset generation id"]
35466 pub fn get_id(&self) -> Result<u32, ErrorContext> {
35467 let mut iter = self.clone();
35468 iter.pos = 0;
35469 for attr in iter {
35470 if let OpGetgenDumpReply::Id(val) = attr? {
35471 return Ok(val);
35472 }
35473 }
35474 Err(ErrorContext::new_missing(
35475 "OpGetgenDumpReply",
35476 "Id",
35477 self.orig_loc,
35478 self.buf.as_ptr() as usize,
35479 ))
35480 }
35481 pub fn get_proc_pid(&self) -> Result<u32, ErrorContext> {
35482 let mut iter = self.clone();
35483 iter.pos = 0;
35484 for attr in iter {
35485 if let OpGetgenDumpReply::ProcPid(val) = attr? {
35486 return Ok(val);
35487 }
35488 }
35489 Err(ErrorContext::new_missing(
35490 "OpGetgenDumpReply",
35491 "ProcPid",
35492 self.orig_loc,
35493 self.buf.as_ptr() as usize,
35494 ))
35495 }
35496 pub fn get_proc_name(&self) -> Result<&'a CStr, ErrorContext> {
35497 let mut iter = self.clone();
35498 iter.pos = 0;
35499 for attr in iter {
35500 if let OpGetgenDumpReply::ProcName(val) = attr? {
35501 return Ok(val);
35502 }
35503 }
35504 Err(ErrorContext::new_missing(
35505 "OpGetgenDumpReply",
35506 "ProcName",
35507 self.orig_loc,
35508 self.buf.as_ptr() as usize,
35509 ))
35510 }
35511}
35512impl<'a> OpGetgenDumpReply<'a> {
35513 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetgenDumpReply<'a>) {
35514 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
35515 (
35516 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
35517 IterableOpGetgenDumpReply::with_loc(attrs, buf.as_ptr() as usize),
35518 )
35519 }
35520 fn attr_from_type(r#type: u16) -> Option<&'static str> {
35521 GenAttrs::attr_from_type(r#type)
35522 }
35523}
35524#[derive(Clone, Copy, Default)]
35525pub struct IterableOpGetgenDumpReply<'a> {
35526 buf: &'a [u8],
35527 pos: usize,
35528 orig_loc: usize,
35529}
35530impl<'a> IterableOpGetgenDumpReply<'a> {
35531 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
35532 Self {
35533 buf,
35534 pos: 0,
35535 orig_loc,
35536 }
35537 }
35538 pub fn get_buf(&self) -> &'a [u8] {
35539 self.buf
35540 }
35541}
35542impl<'a> Iterator for IterableOpGetgenDumpReply<'a> {
35543 type Item = Result<OpGetgenDumpReply<'a>, ErrorContext>;
35544 fn next(&mut self) -> Option<Self::Item> {
35545 if self.buf.len() == self.pos {
35546 return None;
35547 }
35548 let pos = self.pos;
35549 let mut r#type = None;
35550 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
35551 r#type = Some(header.r#type);
35552 let res = match header.r#type {
35553 1u16 => OpGetgenDumpReply::Id({
35554 let res = parse_be_u32(next);
35555 let Some(val) = res else { break };
35556 val
35557 }),
35558 2u16 => OpGetgenDumpReply::ProcPid({
35559 let res = parse_be_u32(next);
35560 let Some(val) = res else { break };
35561 val
35562 }),
35563 3u16 => OpGetgenDumpReply::ProcName({
35564 let res = CStr::from_bytes_with_nul(next).ok();
35565 let Some(val) = res else { break };
35566 val
35567 }),
35568 n => {
35569 if cfg!(any(test, feature = "deny-unknown-attrs")) {
35570 break;
35571 } else {
35572 continue;
35573 }
35574 }
35575 };
35576 return Some(Ok(res));
35577 }
35578 Some(Err(ErrorContext::new(
35579 "OpGetgenDumpReply",
35580 r#type.and_then(|t| OpGetgenDumpReply::attr_from_type(t)),
35581 self.orig_loc,
35582 self.buf.as_ptr().wrapping_add(pos) as usize,
35583 )))
35584 }
35585}
35586impl<'a> std::fmt::Debug for IterableOpGetgenDumpReply<'_> {
35587 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35588 let mut fmt = f.debug_struct("OpGetgenDumpReply");
35589 for attr in self.clone() {
35590 let attr = match attr {
35591 Ok(a) => a,
35592 Err(err) => {
35593 fmt.finish()?;
35594 f.write_str("Err(")?;
35595 err.fmt(f)?;
35596 return f.write_str(")");
35597 }
35598 };
35599 match attr {
35600 OpGetgenDumpReply::Id(val) => fmt.field("Id", &val),
35601 OpGetgenDumpReply::ProcPid(val) => fmt.field("ProcPid", &val),
35602 OpGetgenDumpReply::ProcName(val) => fmt.field("ProcName", &val),
35603 };
35604 }
35605 fmt.finish()
35606 }
35607}
35608impl IterableOpGetgenDumpReply<'_> {
35609 pub fn lookup_attr(
35610 &self,
35611 offset: usize,
35612 missing_type: Option<u16>,
35613 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
35614 let mut stack = Vec::new();
35615 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
35616 if cur == offset + PushNfgenmsg::len() {
35617 stack.push(("OpGetgenDumpReply", offset));
35618 return (
35619 stack,
35620 missing_type.and_then(|t| OpGetgenDumpReply::attr_from_type(t)),
35621 );
35622 }
35623 if cur > offset || cur + self.buf.len() < offset {
35624 return (stack, None);
35625 }
35626 let mut attrs = self.clone();
35627 let mut last_off = cur + attrs.pos;
35628 while let Some(attr) = attrs.next() {
35629 let Ok(attr) = attr else { break };
35630 match attr {
35631 OpGetgenDumpReply::Id(val) => {
35632 if last_off == offset {
35633 stack.push(("Id", last_off));
35634 break;
35635 }
35636 }
35637 OpGetgenDumpReply::ProcPid(val) => {
35638 if last_off == offset {
35639 stack.push(("ProcPid", last_off));
35640 break;
35641 }
35642 }
35643 OpGetgenDumpReply::ProcName(val) => {
35644 if last_off == offset {
35645 stack.push(("ProcName", last_off));
35646 break;
35647 }
35648 }
35649 _ => {}
35650 };
35651 last_off = cur + attrs.pos;
35652 }
35653 if !stack.is_empty() {
35654 stack.push(("OpGetgenDumpReply", cur));
35655 }
35656 (stack, None)
35657 }
35658}
35659#[derive(Debug)]
35660pub struct RequestOpGetgenDumpRequest<'r> {
35661 request: Request<'r>,
35662}
35663impl<'r> RequestOpGetgenDumpRequest<'r> {
35664 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
35665 PushOpGetgenDumpRequest::write_header(&mut request.buf_mut(), header);
35666 Self {
35667 request: request.set_dump(),
35668 }
35669 }
35670 pub fn encode(&mut self) -> PushOpGetgenDumpRequest<&mut Vec<u8>> {
35671 PushOpGetgenDumpRequest::new_without_header(self.request.buf_mut())
35672 }
35673 pub fn into_encoder(self) -> PushOpGetgenDumpRequest<RequestBuf<'r>> {
35674 PushOpGetgenDumpRequest::new_without_header(self.request.buf)
35675 }
35676}
35677impl NetlinkRequest for RequestOpGetgenDumpRequest<'_> {
35678 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetgenDumpReply<'buf>);
35679 fn protocol(&self) -> Protocol {
35680 Protocol::Raw {
35681 protonum: 12u16,
35682 request_type: 2576u16,
35683 }
35684 }
35685 fn flags(&self) -> u16 {
35686 self.request.flags
35687 }
35688 fn payload(&self) -> &[u8] {
35689 self.request.buf()
35690 }
35691 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
35692 OpGetgenDumpReply::new(buf)
35693 }
35694 fn lookup(
35695 buf: &[u8],
35696 offset: usize,
35697 missing_type: Option<u16>,
35698 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
35699 OpGetgenDumpRequest::new(buf)
35700 .1
35701 .lookup_attr(offset, missing_type)
35702 }
35703}
35704#[doc = "Get / dump rule-set generation."]
35705pub struct PushOpGetgenDoRequest<Prev: Rec> {
35706 pub(crate) prev: Option<Prev>,
35707 pub(crate) header_offset: Option<usize>,
35708}
35709impl<Prev: Rec> Rec for PushOpGetgenDoRequest<Prev> {
35710 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
35711 self.prev.as_mut().unwrap().as_rec_mut()
35712 }
35713}
35714impl<Prev: Rec> PushOpGetgenDoRequest<Prev> {
35715 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
35716 Self::write_header(&mut prev, header);
35717 Self::new_without_header(prev)
35718 }
35719 fn new_without_header(prev: Prev) -> Self {
35720 Self {
35721 prev: Some(prev),
35722 header_offset: None,
35723 }
35724 }
35725 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
35726 prev.as_rec_mut().extend(header.as_slice());
35727 }
35728 pub fn end_nested(mut self) -> Prev {
35729 let mut prev = self.prev.take().unwrap();
35730 if let Some(header_offset) = &self.header_offset {
35731 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35732 }
35733 prev
35734 }
35735}
35736impl<Prev: Rec> Drop for PushOpGetgenDoRequest<Prev> {
35737 fn drop(&mut self) {
35738 if let Some(prev) = &mut self.prev {
35739 if let Some(header_offset) = &self.header_offset {
35740 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35741 }
35742 }
35743 }
35744}
35745#[doc = "Get / dump rule-set generation."]
35746#[derive(Clone)]
35747pub enum OpGetgenDoRequest {}
35748impl<'a> IterableOpGetgenDoRequest<'a> {}
35749impl OpGetgenDoRequest {
35750 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpGetgenDoRequest<'_>) {
35751 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
35752 (
35753 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
35754 IterableOpGetgenDoRequest::with_loc(attrs, buf.as_ptr() as usize),
35755 )
35756 }
35757 fn attr_from_type(r#type: u16) -> Option<&'static str> {
35758 GenAttrs::attr_from_type(r#type)
35759 }
35760}
35761#[derive(Clone, Copy, Default)]
35762pub struct IterableOpGetgenDoRequest<'a> {
35763 buf: &'a [u8],
35764 pos: usize,
35765 orig_loc: usize,
35766}
35767impl<'a> IterableOpGetgenDoRequest<'a> {
35768 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
35769 Self {
35770 buf,
35771 pos: 0,
35772 orig_loc,
35773 }
35774 }
35775 pub fn get_buf(&self) -> &'a [u8] {
35776 self.buf
35777 }
35778}
35779impl<'a> Iterator for IterableOpGetgenDoRequest<'a> {
35780 type Item = Result<OpGetgenDoRequest, ErrorContext>;
35781 fn next(&mut self) -> Option<Self::Item> {
35782 if self.buf.len() == self.pos {
35783 return None;
35784 }
35785 let pos = self.pos;
35786 let mut r#type = None;
35787 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
35788 r#type = Some(header.r#type);
35789 let res = match header.r#type {
35790 n => {
35791 if cfg!(any(test, feature = "deny-unknown-attrs")) {
35792 break;
35793 } else {
35794 continue;
35795 }
35796 }
35797 };
35798 return Some(Ok(res));
35799 }
35800 Some(Err(ErrorContext::new(
35801 "OpGetgenDoRequest",
35802 r#type.and_then(|t| OpGetgenDoRequest::attr_from_type(t)),
35803 self.orig_loc,
35804 self.buf.as_ptr().wrapping_add(pos) as usize,
35805 )))
35806 }
35807}
35808impl std::fmt::Debug for IterableOpGetgenDoRequest<'_> {
35809 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35810 let mut fmt = f.debug_struct("OpGetgenDoRequest");
35811 for attr in self.clone() {
35812 let attr = match attr {
35813 Ok(a) => a,
35814 Err(err) => {
35815 fmt.finish()?;
35816 f.write_str("Err(")?;
35817 err.fmt(f)?;
35818 return f.write_str(")");
35819 }
35820 };
35821 match attr {};
35822 }
35823 fmt.finish()
35824 }
35825}
35826impl IterableOpGetgenDoRequest<'_> {
35827 pub fn lookup_attr(
35828 &self,
35829 offset: usize,
35830 missing_type: Option<u16>,
35831 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
35832 let mut stack = Vec::new();
35833 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
35834 if cur == offset + PushNfgenmsg::len() {
35835 stack.push(("OpGetgenDoRequest", offset));
35836 return (
35837 stack,
35838 missing_type.and_then(|t| OpGetgenDoRequest::attr_from_type(t)),
35839 );
35840 }
35841 (stack, None)
35842 }
35843}
35844#[doc = "Get / dump rule-set generation."]
35845pub struct PushOpGetgenDoReply<Prev: Rec> {
35846 pub(crate) prev: Option<Prev>,
35847 pub(crate) header_offset: Option<usize>,
35848}
35849impl<Prev: Rec> Rec for PushOpGetgenDoReply<Prev> {
35850 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
35851 self.prev.as_mut().unwrap().as_rec_mut()
35852 }
35853}
35854impl<Prev: Rec> PushOpGetgenDoReply<Prev> {
35855 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
35856 Self::write_header(&mut prev, header);
35857 Self::new_without_header(prev)
35858 }
35859 fn new_without_header(prev: Prev) -> Self {
35860 Self {
35861 prev: Some(prev),
35862 header_offset: None,
35863 }
35864 }
35865 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
35866 prev.as_rec_mut().extend(header.as_slice());
35867 }
35868 pub fn end_nested(mut self) -> Prev {
35869 let mut prev = self.prev.take().unwrap();
35870 if let Some(header_offset) = &self.header_offset {
35871 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35872 }
35873 prev
35874 }
35875 #[doc = "ruleset generation id"]
35876 pub fn push_id(mut self, value: u32) -> Self {
35877 push_header(self.as_rec_mut(), 1u16, 4 as u16);
35878 self.as_rec_mut().extend(value.to_be_bytes());
35879 self
35880 }
35881 pub fn push_proc_pid(mut self, value: u32) -> Self {
35882 push_header(self.as_rec_mut(), 2u16, 4 as u16);
35883 self.as_rec_mut().extend(value.to_be_bytes());
35884 self
35885 }
35886 pub fn push_proc_name(mut self, value: &CStr) -> Self {
35887 push_header(
35888 self.as_rec_mut(),
35889 3u16,
35890 value.to_bytes_with_nul().len() as u16,
35891 );
35892 self.as_rec_mut().extend(value.to_bytes_with_nul());
35893 self
35894 }
35895 pub fn push_proc_name_bytes(mut self, value: &[u8]) -> Self {
35896 push_header(self.as_rec_mut(), 3u16, (value.len() + 1) as u16);
35897 self.as_rec_mut().extend(value);
35898 self.as_rec_mut().push(0);
35899 self
35900 }
35901}
35902impl<Prev: Rec> Drop for PushOpGetgenDoReply<Prev> {
35903 fn drop(&mut self) {
35904 if let Some(prev) = &mut self.prev {
35905 if let Some(header_offset) = &self.header_offset {
35906 finalize_nested_header(prev.as_rec_mut(), *header_offset);
35907 }
35908 }
35909 }
35910}
35911#[doc = "Get / dump rule-set generation."]
35912#[derive(Clone)]
35913pub enum OpGetgenDoReply<'a> {
35914 #[doc = "ruleset generation id"]
35915 Id(u32),
35916 ProcPid(u32),
35917 ProcName(&'a CStr),
35918}
35919impl<'a> IterableOpGetgenDoReply<'a> {
35920 #[doc = "ruleset generation id"]
35921 pub fn get_id(&self) -> Result<u32, ErrorContext> {
35922 let mut iter = self.clone();
35923 iter.pos = 0;
35924 for attr in iter {
35925 if let OpGetgenDoReply::Id(val) = attr? {
35926 return Ok(val);
35927 }
35928 }
35929 Err(ErrorContext::new_missing(
35930 "OpGetgenDoReply",
35931 "Id",
35932 self.orig_loc,
35933 self.buf.as_ptr() as usize,
35934 ))
35935 }
35936 pub fn get_proc_pid(&self) -> Result<u32, ErrorContext> {
35937 let mut iter = self.clone();
35938 iter.pos = 0;
35939 for attr in iter {
35940 if let OpGetgenDoReply::ProcPid(val) = attr? {
35941 return Ok(val);
35942 }
35943 }
35944 Err(ErrorContext::new_missing(
35945 "OpGetgenDoReply",
35946 "ProcPid",
35947 self.orig_loc,
35948 self.buf.as_ptr() as usize,
35949 ))
35950 }
35951 pub fn get_proc_name(&self) -> Result<&'a CStr, ErrorContext> {
35952 let mut iter = self.clone();
35953 iter.pos = 0;
35954 for attr in iter {
35955 if let OpGetgenDoReply::ProcName(val) = attr? {
35956 return Ok(val);
35957 }
35958 }
35959 Err(ErrorContext::new_missing(
35960 "OpGetgenDoReply",
35961 "ProcName",
35962 self.orig_loc,
35963 self.buf.as_ptr() as usize,
35964 ))
35965 }
35966}
35967impl<'a> OpGetgenDoReply<'a> {
35968 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetgenDoReply<'a>) {
35969 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
35970 (
35971 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
35972 IterableOpGetgenDoReply::with_loc(attrs, buf.as_ptr() as usize),
35973 )
35974 }
35975 fn attr_from_type(r#type: u16) -> Option<&'static str> {
35976 GenAttrs::attr_from_type(r#type)
35977 }
35978}
35979#[derive(Clone, Copy, Default)]
35980pub struct IterableOpGetgenDoReply<'a> {
35981 buf: &'a [u8],
35982 pos: usize,
35983 orig_loc: usize,
35984}
35985impl<'a> IterableOpGetgenDoReply<'a> {
35986 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
35987 Self {
35988 buf,
35989 pos: 0,
35990 orig_loc,
35991 }
35992 }
35993 pub fn get_buf(&self) -> &'a [u8] {
35994 self.buf
35995 }
35996}
35997impl<'a> Iterator for IterableOpGetgenDoReply<'a> {
35998 type Item = Result<OpGetgenDoReply<'a>, ErrorContext>;
35999 fn next(&mut self) -> Option<Self::Item> {
36000 if self.buf.len() == self.pos {
36001 return None;
36002 }
36003 let pos = self.pos;
36004 let mut r#type = None;
36005 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
36006 r#type = Some(header.r#type);
36007 let res = match header.r#type {
36008 1u16 => OpGetgenDoReply::Id({
36009 let res = parse_be_u32(next);
36010 let Some(val) = res else { break };
36011 val
36012 }),
36013 2u16 => OpGetgenDoReply::ProcPid({
36014 let res = parse_be_u32(next);
36015 let Some(val) = res else { break };
36016 val
36017 }),
36018 3u16 => OpGetgenDoReply::ProcName({
36019 let res = CStr::from_bytes_with_nul(next).ok();
36020 let Some(val) = res else { break };
36021 val
36022 }),
36023 n => {
36024 if cfg!(any(test, feature = "deny-unknown-attrs")) {
36025 break;
36026 } else {
36027 continue;
36028 }
36029 }
36030 };
36031 return Some(Ok(res));
36032 }
36033 Some(Err(ErrorContext::new(
36034 "OpGetgenDoReply",
36035 r#type.and_then(|t| OpGetgenDoReply::attr_from_type(t)),
36036 self.orig_loc,
36037 self.buf.as_ptr().wrapping_add(pos) as usize,
36038 )))
36039 }
36040}
36041impl<'a> std::fmt::Debug for IterableOpGetgenDoReply<'_> {
36042 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36043 let mut fmt = f.debug_struct("OpGetgenDoReply");
36044 for attr in self.clone() {
36045 let attr = match attr {
36046 Ok(a) => a,
36047 Err(err) => {
36048 fmt.finish()?;
36049 f.write_str("Err(")?;
36050 err.fmt(f)?;
36051 return f.write_str(")");
36052 }
36053 };
36054 match attr {
36055 OpGetgenDoReply::Id(val) => fmt.field("Id", &val),
36056 OpGetgenDoReply::ProcPid(val) => fmt.field("ProcPid", &val),
36057 OpGetgenDoReply::ProcName(val) => fmt.field("ProcName", &val),
36058 };
36059 }
36060 fmt.finish()
36061 }
36062}
36063impl IterableOpGetgenDoReply<'_> {
36064 pub fn lookup_attr(
36065 &self,
36066 offset: usize,
36067 missing_type: Option<u16>,
36068 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
36069 let mut stack = Vec::new();
36070 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
36071 if cur == offset + PushNfgenmsg::len() {
36072 stack.push(("OpGetgenDoReply", offset));
36073 return (
36074 stack,
36075 missing_type.and_then(|t| OpGetgenDoReply::attr_from_type(t)),
36076 );
36077 }
36078 if cur > offset || cur + self.buf.len() < offset {
36079 return (stack, None);
36080 }
36081 let mut attrs = self.clone();
36082 let mut last_off = cur + attrs.pos;
36083 while let Some(attr) = attrs.next() {
36084 let Ok(attr) = attr else { break };
36085 match attr {
36086 OpGetgenDoReply::Id(val) => {
36087 if last_off == offset {
36088 stack.push(("Id", last_off));
36089 break;
36090 }
36091 }
36092 OpGetgenDoReply::ProcPid(val) => {
36093 if last_off == offset {
36094 stack.push(("ProcPid", last_off));
36095 break;
36096 }
36097 }
36098 OpGetgenDoReply::ProcName(val) => {
36099 if last_off == offset {
36100 stack.push(("ProcName", last_off));
36101 break;
36102 }
36103 }
36104 _ => {}
36105 };
36106 last_off = cur + attrs.pos;
36107 }
36108 if !stack.is_empty() {
36109 stack.push(("OpGetgenDoReply", cur));
36110 }
36111 (stack, None)
36112 }
36113}
36114#[derive(Debug)]
36115pub struct RequestOpGetgenDoRequest<'r> {
36116 request: Request<'r>,
36117}
36118impl<'r> RequestOpGetgenDoRequest<'r> {
36119 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
36120 PushOpGetgenDoRequest::write_header(&mut request.buf_mut(), header);
36121 Self { request: request }
36122 }
36123 pub fn encode(&mut self) -> PushOpGetgenDoRequest<&mut Vec<u8>> {
36124 PushOpGetgenDoRequest::new_without_header(self.request.buf_mut())
36125 }
36126 pub fn into_encoder(self) -> PushOpGetgenDoRequest<RequestBuf<'r>> {
36127 PushOpGetgenDoRequest::new_without_header(self.request.buf)
36128 }
36129}
36130impl NetlinkRequest for RequestOpGetgenDoRequest<'_> {
36131 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetgenDoReply<'buf>);
36132 fn protocol(&self) -> Protocol {
36133 Protocol::Raw {
36134 protonum: 12u16,
36135 request_type: 2576u16,
36136 }
36137 }
36138 fn flags(&self) -> u16 {
36139 self.request.flags
36140 }
36141 fn payload(&self) -> &[u8] {
36142 self.request.buf()
36143 }
36144 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
36145 OpGetgenDoReply::new(buf)
36146 }
36147 fn lookup(
36148 buf: &[u8],
36149 offset: usize,
36150 missing_type: Option<u16>,
36151 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
36152 OpGetgenDoRequest::new(buf)
36153 .1
36154 .lookup_attr(offset, missing_type)
36155 }
36156}
36157#[doc = "Create a new stateful object."]
36158pub struct PushOpNewobjDoRequest<Prev: Rec> {
36159 pub(crate) prev: Option<Prev>,
36160 pub(crate) header_offset: Option<usize>,
36161}
36162impl<Prev: Rec> Rec for PushOpNewobjDoRequest<Prev> {
36163 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
36164 self.prev.as_mut().unwrap().as_rec_mut()
36165 }
36166}
36167impl<Prev: Rec> PushOpNewobjDoRequest<Prev> {
36168 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
36169 Self::write_header(&mut prev, header);
36170 Self::new_without_header(prev)
36171 }
36172 fn new_without_header(prev: Prev) -> Self {
36173 Self {
36174 prev: Some(prev),
36175 header_offset: None,
36176 }
36177 }
36178 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
36179 prev.as_rec_mut().extend(header.as_slice());
36180 }
36181 pub fn end_nested(mut self) -> Prev {
36182 let mut prev = self.prev.take().unwrap();
36183 if let Some(header_offset) = &self.header_offset {
36184 finalize_nested_header(prev.as_rec_mut(), *header_offset);
36185 }
36186 prev
36187 }
36188 #[doc = "name of the table containing the expression"]
36189 pub fn push_table(mut self, value: &CStr) -> Self {
36190 push_header(
36191 self.as_rec_mut(),
36192 1u16,
36193 value.to_bytes_with_nul().len() as u16,
36194 );
36195 self.as_rec_mut().extend(value.to_bytes_with_nul());
36196 self
36197 }
36198 #[doc = "name of the table containing the expression"]
36199 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
36200 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
36201 self.as_rec_mut().extend(value);
36202 self.as_rec_mut().push(0);
36203 self
36204 }
36205 #[doc = "name of this expression type"]
36206 pub fn push_name(mut self, value: &CStr) -> Self {
36207 push_header(
36208 self.as_rec_mut(),
36209 2u16,
36210 value.to_bytes_with_nul().len() as u16,
36211 );
36212 self.as_rec_mut().extend(value.to_bytes_with_nul());
36213 self
36214 }
36215 #[doc = "name of this expression type"]
36216 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
36217 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
36218 self.as_rec_mut().extend(value);
36219 self.as_rec_mut().push(0);
36220 self
36221 }
36222 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
36223 pub fn push_type(mut self, value: u32) -> Self {
36224 push_header(self.as_rec_mut(), 3u16, 4 as u16);
36225 self.as_rec_mut().extend(value.to_be_bytes());
36226 self
36227 }
36228 #[doc = "stateful object data"]
36229 #[doc = "Selector attribute is inserted automatically."]
36230 #[doc = "At most one sub-message attribute is expected per attribute set."]
36231 pub fn nested_data_counter(mut self) -> PushCounterAttrs<PushDummy<Prev>> {
36232 self = self.push_type(ObjectType::Counter as u32);
36233 let new_header_offset = push_nested_header(self.as_rec_mut(), 4u16);
36234 let dummy = PushDummy {
36235 prev: self.prev.take(),
36236 header_offset: self.header_offset.take(),
36237 };
36238 PushCounterAttrs {
36239 prev: Some(dummy),
36240 header_offset: Some(new_header_offset),
36241 }
36242 }
36243 #[doc = "Selector attribute is inserted automatically."]
36244 #[doc = "At most one sub-message attribute is expected per attribute set."]
36245 pub fn nested_data_quota(mut self) -> PushQuotaAttrs<PushDummy<Prev>> {
36246 self = self.push_type(ObjectType::Quota as u32);
36247 let new_header_offset = push_nested_header(self.as_rec_mut(), 4u16);
36248 let dummy = PushDummy {
36249 prev: self.prev.take(),
36250 header_offset: self.header_offset.take(),
36251 };
36252 PushQuotaAttrs {
36253 prev: Some(dummy),
36254 header_offset: Some(new_header_offset),
36255 }
36256 }
36257 #[doc = "user data"]
36258 pub fn push_userdata(mut self, value: &[u8]) -> Self {
36259 push_header(self.as_rec_mut(), 8u16, value.len() as u16);
36260 self.as_rec_mut().extend(value);
36261 self
36262 }
36263}
36264impl<Prev: Rec> Drop for PushOpNewobjDoRequest<Prev> {
36265 fn drop(&mut self) {
36266 if let Some(prev) = &mut self.prev {
36267 if let Some(header_offset) = &self.header_offset {
36268 finalize_nested_header(prev.as_rec_mut(), *header_offset);
36269 }
36270 }
36271 }
36272}
36273#[doc = "Create a new stateful object."]
36274#[derive(Clone)]
36275pub enum OpNewobjDoRequest<'a> {
36276 #[doc = "name of the table containing the expression"]
36277 Table(&'a CStr),
36278 #[doc = "name of this expression type"]
36279 Name(&'a CStr),
36280 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
36281 Type(u32),
36282 #[doc = "stateful object data"]
36283 Data(ObjData<'a>),
36284 #[doc = "user data"]
36285 Userdata(&'a [u8]),
36286}
36287impl<'a> IterableOpNewobjDoRequest<'a> {
36288 #[doc = "name of the table containing the expression"]
36289 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
36290 let mut iter = self.clone();
36291 iter.pos = 0;
36292 for attr in iter {
36293 if let OpNewobjDoRequest::Table(val) = attr? {
36294 return Ok(val);
36295 }
36296 }
36297 Err(ErrorContext::new_missing(
36298 "OpNewobjDoRequest",
36299 "Table",
36300 self.orig_loc,
36301 self.buf.as_ptr() as usize,
36302 ))
36303 }
36304 #[doc = "name of this expression type"]
36305 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
36306 let mut iter = self.clone();
36307 iter.pos = 0;
36308 for attr in iter {
36309 if let OpNewobjDoRequest::Name(val) = attr? {
36310 return Ok(val);
36311 }
36312 }
36313 Err(ErrorContext::new_missing(
36314 "OpNewobjDoRequest",
36315 "Name",
36316 self.orig_loc,
36317 self.buf.as_ptr() as usize,
36318 ))
36319 }
36320 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
36321 pub fn get_type(&self) -> Result<u32, ErrorContext> {
36322 let mut iter = self.clone();
36323 iter.pos = 0;
36324 for attr in iter {
36325 if let OpNewobjDoRequest::Type(val) = attr? {
36326 return Ok(val);
36327 }
36328 }
36329 Err(ErrorContext::new_missing(
36330 "OpNewobjDoRequest",
36331 "Type",
36332 self.orig_loc,
36333 self.buf.as_ptr() as usize,
36334 ))
36335 }
36336 #[doc = "stateful object data"]
36337 pub fn get_data(&self) -> Result<ObjData<'a>, ErrorContext> {
36338 let mut iter = self.clone();
36339 iter.pos = 0;
36340 for attr in iter {
36341 if let OpNewobjDoRequest::Data(val) = attr? {
36342 return Ok(val);
36343 }
36344 }
36345 Err(ErrorContext::new_missing(
36346 "OpNewobjDoRequest",
36347 "Data",
36348 self.orig_loc,
36349 self.buf.as_ptr() as usize,
36350 ))
36351 }
36352 #[doc = "user data"]
36353 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
36354 let mut iter = self.clone();
36355 iter.pos = 0;
36356 for attr in iter {
36357 if let OpNewobjDoRequest::Userdata(val) = attr? {
36358 return Ok(val);
36359 }
36360 }
36361 Err(ErrorContext::new_missing(
36362 "OpNewobjDoRequest",
36363 "Userdata",
36364 self.orig_loc,
36365 self.buf.as_ptr() as usize,
36366 ))
36367 }
36368}
36369impl<'a> OpNewobjDoRequest<'a> {
36370 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpNewobjDoRequest<'a>) {
36371 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
36372 (
36373 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
36374 IterableOpNewobjDoRequest::with_loc(attrs, buf.as_ptr() as usize),
36375 )
36376 }
36377 fn attr_from_type(r#type: u16) -> Option<&'static str> {
36378 ObjAttrs::attr_from_type(r#type)
36379 }
36380}
36381#[derive(Clone, Copy, Default)]
36382pub struct IterableOpNewobjDoRequest<'a> {
36383 buf: &'a [u8],
36384 pos: usize,
36385 orig_loc: usize,
36386}
36387impl<'a> IterableOpNewobjDoRequest<'a> {
36388 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
36389 Self {
36390 buf,
36391 pos: 0,
36392 orig_loc,
36393 }
36394 }
36395 pub fn get_buf(&self) -> &'a [u8] {
36396 self.buf
36397 }
36398}
36399impl<'a> Iterator for IterableOpNewobjDoRequest<'a> {
36400 type Item = Result<OpNewobjDoRequest<'a>, ErrorContext>;
36401 fn next(&mut self) -> Option<Self::Item> {
36402 if self.buf.len() == self.pos {
36403 return None;
36404 }
36405 let pos = self.pos;
36406 let mut r#type = None;
36407 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
36408 r#type = Some(header.r#type);
36409 let res = match header.r#type {
36410 1u16 => OpNewobjDoRequest::Table({
36411 let res = CStr::from_bytes_with_nul(next).ok();
36412 let Some(val) = res else { break };
36413 val
36414 }),
36415 2u16 => OpNewobjDoRequest::Name({
36416 let res = CStr::from_bytes_with_nul(next).ok();
36417 let Some(val) = res else { break };
36418 val
36419 }),
36420 3u16 => OpNewobjDoRequest::Type({
36421 let res = parse_be_u32(next);
36422 let Some(val) = res else { break };
36423 val
36424 }),
36425 4u16 => OpNewobjDoRequest::Data({
36426 let res = {
36427 let Ok(selector) = self.get_type() else { break };
36428 ObjData::select_with_loc(selector, next, self.orig_loc)
36429 };
36430 let Some(val) = res else { break };
36431 val
36432 }),
36433 8u16 => OpNewobjDoRequest::Userdata({
36434 let res = Some(next);
36435 let Some(val) = res else { break };
36436 val
36437 }),
36438 n => {
36439 if cfg!(any(test, feature = "deny-unknown-attrs")) {
36440 break;
36441 } else {
36442 continue;
36443 }
36444 }
36445 };
36446 return Some(Ok(res));
36447 }
36448 Some(Err(ErrorContext::new(
36449 "OpNewobjDoRequest",
36450 r#type.and_then(|t| OpNewobjDoRequest::attr_from_type(t)),
36451 self.orig_loc,
36452 self.buf.as_ptr().wrapping_add(pos) as usize,
36453 )))
36454 }
36455}
36456impl<'a> std::fmt::Debug for IterableOpNewobjDoRequest<'_> {
36457 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36458 let mut fmt = f.debug_struct("OpNewobjDoRequest");
36459 for attr in self.clone() {
36460 let attr = match attr {
36461 Ok(a) => a,
36462 Err(err) => {
36463 fmt.finish()?;
36464 f.write_str("Err(")?;
36465 err.fmt(f)?;
36466 return f.write_str(")");
36467 }
36468 };
36469 match attr {
36470 OpNewobjDoRequest::Table(val) => fmt.field("Table", &val),
36471 OpNewobjDoRequest::Name(val) => fmt.field("Name", &val),
36472 OpNewobjDoRequest::Type(val) => {
36473 fmt.field("Type", &FormatEnum(val.into(), ObjectType::from_value))
36474 }
36475 OpNewobjDoRequest::Data(val) => fmt.field("Data", &val),
36476 OpNewobjDoRequest::Userdata(val) => fmt.field("Userdata", &val),
36477 };
36478 }
36479 fmt.finish()
36480 }
36481}
36482impl IterableOpNewobjDoRequest<'_> {
36483 pub fn lookup_attr(
36484 &self,
36485 offset: usize,
36486 missing_type: Option<u16>,
36487 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
36488 let mut stack = Vec::new();
36489 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
36490 if cur == offset + PushNfgenmsg::len() {
36491 stack.push(("OpNewobjDoRequest", offset));
36492 return (
36493 stack,
36494 missing_type.and_then(|t| OpNewobjDoRequest::attr_from_type(t)),
36495 );
36496 }
36497 if cur > offset || cur + self.buf.len() < offset {
36498 return (stack, None);
36499 }
36500 let mut attrs = self.clone();
36501 let mut last_off = cur + attrs.pos;
36502 while let Some(attr) = attrs.next() {
36503 let Ok(attr) = attr else { break };
36504 match attr {
36505 OpNewobjDoRequest::Table(val) => {
36506 if last_off == offset {
36507 stack.push(("Table", last_off));
36508 break;
36509 }
36510 }
36511 OpNewobjDoRequest::Name(val) => {
36512 if last_off == offset {
36513 stack.push(("Name", last_off));
36514 break;
36515 }
36516 }
36517 OpNewobjDoRequest::Type(val) => {
36518 if last_off == offset {
36519 stack.push(("Type", last_off));
36520 break;
36521 }
36522 }
36523 OpNewobjDoRequest::Data(val) => {
36524 if last_off == offset {
36525 stack.push(("Data", last_off));
36526 break;
36527 }
36528 }
36529 OpNewobjDoRequest::Userdata(val) => {
36530 if last_off == offset {
36531 stack.push(("Userdata", last_off));
36532 break;
36533 }
36534 }
36535 _ => {}
36536 };
36537 last_off = cur + attrs.pos;
36538 }
36539 if !stack.is_empty() {
36540 stack.push(("OpNewobjDoRequest", cur));
36541 }
36542 (stack, None)
36543 }
36544}
36545#[doc = "Create a new stateful object."]
36546pub struct PushOpNewobjDoReply<Prev: Rec> {
36547 pub(crate) prev: Option<Prev>,
36548 pub(crate) header_offset: Option<usize>,
36549}
36550impl<Prev: Rec> Rec for PushOpNewobjDoReply<Prev> {
36551 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
36552 self.prev.as_mut().unwrap().as_rec_mut()
36553 }
36554}
36555impl<Prev: Rec> PushOpNewobjDoReply<Prev> {
36556 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
36557 Self::write_header(&mut prev, header);
36558 Self::new_without_header(prev)
36559 }
36560 fn new_without_header(prev: Prev) -> Self {
36561 Self {
36562 prev: Some(prev),
36563 header_offset: None,
36564 }
36565 }
36566 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
36567 prev.as_rec_mut().extend(header.as_slice());
36568 }
36569 pub fn end_nested(mut self) -> Prev {
36570 let mut prev = self.prev.take().unwrap();
36571 if let Some(header_offset) = &self.header_offset {
36572 finalize_nested_header(prev.as_rec_mut(), *header_offset);
36573 }
36574 prev
36575 }
36576}
36577impl<Prev: Rec> Drop for PushOpNewobjDoReply<Prev> {
36578 fn drop(&mut self) {
36579 if let Some(prev) = &mut self.prev {
36580 if let Some(header_offset) = &self.header_offset {
36581 finalize_nested_header(prev.as_rec_mut(), *header_offset);
36582 }
36583 }
36584 }
36585}
36586#[doc = "Create a new stateful object."]
36587#[derive(Clone)]
36588pub enum OpNewobjDoReply {}
36589impl<'a> IterableOpNewobjDoReply<'a> {}
36590impl OpNewobjDoReply {
36591 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpNewobjDoReply<'_>) {
36592 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
36593 (
36594 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
36595 IterableOpNewobjDoReply::with_loc(attrs, buf.as_ptr() as usize),
36596 )
36597 }
36598 fn attr_from_type(r#type: u16) -> Option<&'static str> {
36599 ObjAttrs::attr_from_type(r#type)
36600 }
36601}
36602#[derive(Clone, Copy, Default)]
36603pub struct IterableOpNewobjDoReply<'a> {
36604 buf: &'a [u8],
36605 pos: usize,
36606 orig_loc: usize,
36607}
36608impl<'a> IterableOpNewobjDoReply<'a> {
36609 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
36610 Self {
36611 buf,
36612 pos: 0,
36613 orig_loc,
36614 }
36615 }
36616 pub fn get_buf(&self) -> &'a [u8] {
36617 self.buf
36618 }
36619}
36620impl<'a> Iterator for IterableOpNewobjDoReply<'a> {
36621 type Item = Result<OpNewobjDoReply, ErrorContext>;
36622 fn next(&mut self) -> Option<Self::Item> {
36623 if self.buf.len() == self.pos {
36624 return None;
36625 }
36626 let pos = self.pos;
36627 let mut r#type = None;
36628 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
36629 r#type = Some(header.r#type);
36630 let res = match header.r#type {
36631 n => {
36632 if cfg!(any(test, feature = "deny-unknown-attrs")) {
36633 break;
36634 } else {
36635 continue;
36636 }
36637 }
36638 };
36639 return Some(Ok(res));
36640 }
36641 Some(Err(ErrorContext::new(
36642 "OpNewobjDoReply",
36643 r#type.and_then(|t| OpNewobjDoReply::attr_from_type(t)),
36644 self.orig_loc,
36645 self.buf.as_ptr().wrapping_add(pos) as usize,
36646 )))
36647 }
36648}
36649impl std::fmt::Debug for IterableOpNewobjDoReply<'_> {
36650 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36651 let mut fmt = f.debug_struct("OpNewobjDoReply");
36652 for attr in self.clone() {
36653 let attr = match attr {
36654 Ok(a) => a,
36655 Err(err) => {
36656 fmt.finish()?;
36657 f.write_str("Err(")?;
36658 err.fmt(f)?;
36659 return f.write_str(")");
36660 }
36661 };
36662 match attr {};
36663 }
36664 fmt.finish()
36665 }
36666}
36667impl IterableOpNewobjDoReply<'_> {
36668 pub fn lookup_attr(
36669 &self,
36670 offset: usize,
36671 missing_type: Option<u16>,
36672 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
36673 let mut stack = Vec::new();
36674 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
36675 if cur == offset + PushNfgenmsg::len() {
36676 stack.push(("OpNewobjDoReply", offset));
36677 return (
36678 stack,
36679 missing_type.and_then(|t| OpNewobjDoReply::attr_from_type(t)),
36680 );
36681 }
36682 (stack, None)
36683 }
36684}
36685#[derive(Debug)]
36686pub struct RequestOpNewobjDoRequest<'r> {
36687 request: Request<'r>,
36688}
36689impl<'r> RequestOpNewobjDoRequest<'r> {
36690 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
36691 PushOpNewobjDoRequest::write_header(&mut request.buf_mut(), header);
36692 Self { request: request }
36693 }
36694 pub fn encode(&mut self) -> PushOpNewobjDoRequest<&mut Vec<u8>> {
36695 PushOpNewobjDoRequest::new_without_header(self.request.buf_mut())
36696 }
36697 pub fn into_encoder(self) -> PushOpNewobjDoRequest<RequestBuf<'r>> {
36698 PushOpNewobjDoRequest::new_without_header(self.request.buf)
36699 }
36700}
36701impl NetlinkRequest for RequestOpNewobjDoRequest<'_> {
36702 type ReplyType<'buf> = (PushNfgenmsg, IterableOpNewobjDoReply<'buf>);
36703 fn protocol(&self) -> Protocol {
36704 Protocol::Raw {
36705 protonum: 12u16,
36706 request_type: 2578u16,
36707 }
36708 }
36709 fn flags(&self) -> u16 {
36710 self.request.flags
36711 }
36712 fn payload(&self) -> &[u8] {
36713 self.request.buf()
36714 }
36715 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
36716 OpNewobjDoReply::new(buf)
36717 }
36718 fn lookup(
36719 buf: &[u8],
36720 offset: usize,
36721 missing_type: Option<u16>,
36722 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
36723 OpNewobjDoRequest::new(buf)
36724 .1
36725 .lookup_attr(offset, missing_type)
36726 }
36727}
36728#[doc = "Get / dump stateful objects."]
36729pub struct PushOpGetobjDumpRequest<Prev: Rec> {
36730 pub(crate) prev: Option<Prev>,
36731 pub(crate) header_offset: Option<usize>,
36732}
36733impl<Prev: Rec> Rec for PushOpGetobjDumpRequest<Prev> {
36734 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
36735 self.prev.as_mut().unwrap().as_rec_mut()
36736 }
36737}
36738impl<Prev: Rec> PushOpGetobjDumpRequest<Prev> {
36739 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
36740 Self::write_header(&mut prev, header);
36741 Self::new_without_header(prev)
36742 }
36743 fn new_without_header(prev: Prev) -> Self {
36744 Self {
36745 prev: Some(prev),
36746 header_offset: None,
36747 }
36748 }
36749 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
36750 prev.as_rec_mut().extend(header.as_slice());
36751 }
36752 pub fn end_nested(mut self) -> Prev {
36753 let mut prev = self.prev.take().unwrap();
36754 if let Some(header_offset) = &self.header_offset {
36755 finalize_nested_header(prev.as_rec_mut(), *header_offset);
36756 }
36757 prev
36758 }
36759 #[doc = "name of the table containing the expression"]
36760 pub fn push_table(mut self, value: &CStr) -> Self {
36761 push_header(
36762 self.as_rec_mut(),
36763 1u16,
36764 value.to_bytes_with_nul().len() as u16,
36765 );
36766 self.as_rec_mut().extend(value.to_bytes_with_nul());
36767 self
36768 }
36769 #[doc = "name of the table containing the expression"]
36770 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
36771 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
36772 self.as_rec_mut().extend(value);
36773 self.as_rec_mut().push(0);
36774 self
36775 }
36776 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
36777 pub fn push_type(mut self, value: u32) -> Self {
36778 push_header(self.as_rec_mut(), 3u16, 4 as u16);
36779 self.as_rec_mut().extend(value.to_be_bytes());
36780 self
36781 }
36782}
36783impl<Prev: Rec> Drop for PushOpGetobjDumpRequest<Prev> {
36784 fn drop(&mut self) {
36785 if let Some(prev) = &mut self.prev {
36786 if let Some(header_offset) = &self.header_offset {
36787 finalize_nested_header(prev.as_rec_mut(), *header_offset);
36788 }
36789 }
36790 }
36791}
36792#[doc = "Get / dump stateful objects."]
36793#[derive(Clone)]
36794pub enum OpGetobjDumpRequest<'a> {
36795 #[doc = "name of the table containing the expression"]
36796 Table(&'a CStr),
36797 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
36798 Type(u32),
36799}
36800impl<'a> IterableOpGetobjDumpRequest<'a> {
36801 #[doc = "name of the table containing the expression"]
36802 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
36803 let mut iter = self.clone();
36804 iter.pos = 0;
36805 for attr in iter {
36806 if let OpGetobjDumpRequest::Table(val) = attr? {
36807 return Ok(val);
36808 }
36809 }
36810 Err(ErrorContext::new_missing(
36811 "OpGetobjDumpRequest",
36812 "Table",
36813 self.orig_loc,
36814 self.buf.as_ptr() as usize,
36815 ))
36816 }
36817 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
36818 pub fn get_type(&self) -> Result<u32, ErrorContext> {
36819 let mut iter = self.clone();
36820 iter.pos = 0;
36821 for attr in iter {
36822 if let OpGetobjDumpRequest::Type(val) = attr? {
36823 return Ok(val);
36824 }
36825 }
36826 Err(ErrorContext::new_missing(
36827 "OpGetobjDumpRequest",
36828 "Type",
36829 self.orig_loc,
36830 self.buf.as_ptr() as usize,
36831 ))
36832 }
36833}
36834impl<'a> OpGetobjDumpRequest<'a> {
36835 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetobjDumpRequest<'a>) {
36836 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
36837 (
36838 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
36839 IterableOpGetobjDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
36840 )
36841 }
36842 fn attr_from_type(r#type: u16) -> Option<&'static str> {
36843 ObjAttrs::attr_from_type(r#type)
36844 }
36845}
36846#[derive(Clone, Copy, Default)]
36847pub struct IterableOpGetobjDumpRequest<'a> {
36848 buf: &'a [u8],
36849 pos: usize,
36850 orig_loc: usize,
36851}
36852impl<'a> IterableOpGetobjDumpRequest<'a> {
36853 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
36854 Self {
36855 buf,
36856 pos: 0,
36857 orig_loc,
36858 }
36859 }
36860 pub fn get_buf(&self) -> &'a [u8] {
36861 self.buf
36862 }
36863}
36864impl<'a> Iterator for IterableOpGetobjDumpRequest<'a> {
36865 type Item = Result<OpGetobjDumpRequest<'a>, ErrorContext>;
36866 fn next(&mut self) -> Option<Self::Item> {
36867 if self.buf.len() == self.pos {
36868 return None;
36869 }
36870 let pos = self.pos;
36871 let mut r#type = None;
36872 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
36873 r#type = Some(header.r#type);
36874 let res = match header.r#type {
36875 1u16 => OpGetobjDumpRequest::Table({
36876 let res = CStr::from_bytes_with_nul(next).ok();
36877 let Some(val) = res else { break };
36878 val
36879 }),
36880 3u16 => OpGetobjDumpRequest::Type({
36881 let res = parse_be_u32(next);
36882 let Some(val) = res else { break };
36883 val
36884 }),
36885 n => {
36886 if cfg!(any(test, feature = "deny-unknown-attrs")) {
36887 break;
36888 } else {
36889 continue;
36890 }
36891 }
36892 };
36893 return Some(Ok(res));
36894 }
36895 Some(Err(ErrorContext::new(
36896 "OpGetobjDumpRequest",
36897 r#type.and_then(|t| OpGetobjDumpRequest::attr_from_type(t)),
36898 self.orig_loc,
36899 self.buf.as_ptr().wrapping_add(pos) as usize,
36900 )))
36901 }
36902}
36903impl<'a> std::fmt::Debug for IterableOpGetobjDumpRequest<'_> {
36904 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36905 let mut fmt = f.debug_struct("OpGetobjDumpRequest");
36906 for attr in self.clone() {
36907 let attr = match attr {
36908 Ok(a) => a,
36909 Err(err) => {
36910 fmt.finish()?;
36911 f.write_str("Err(")?;
36912 err.fmt(f)?;
36913 return f.write_str(")");
36914 }
36915 };
36916 match attr {
36917 OpGetobjDumpRequest::Table(val) => fmt.field("Table", &val),
36918 OpGetobjDumpRequest::Type(val) => {
36919 fmt.field("Type", &FormatEnum(val.into(), ObjectType::from_value))
36920 }
36921 };
36922 }
36923 fmt.finish()
36924 }
36925}
36926impl IterableOpGetobjDumpRequest<'_> {
36927 pub fn lookup_attr(
36928 &self,
36929 offset: usize,
36930 missing_type: Option<u16>,
36931 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
36932 let mut stack = Vec::new();
36933 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
36934 if cur == offset + PushNfgenmsg::len() {
36935 stack.push(("OpGetobjDumpRequest", offset));
36936 return (
36937 stack,
36938 missing_type.and_then(|t| OpGetobjDumpRequest::attr_from_type(t)),
36939 );
36940 }
36941 if cur > offset || cur + self.buf.len() < offset {
36942 return (stack, None);
36943 }
36944 let mut attrs = self.clone();
36945 let mut last_off = cur + attrs.pos;
36946 while let Some(attr) = attrs.next() {
36947 let Ok(attr) = attr else { break };
36948 match attr {
36949 OpGetobjDumpRequest::Table(val) => {
36950 if last_off == offset {
36951 stack.push(("Table", last_off));
36952 break;
36953 }
36954 }
36955 OpGetobjDumpRequest::Type(val) => {
36956 if last_off == offset {
36957 stack.push(("Type", last_off));
36958 break;
36959 }
36960 }
36961 _ => {}
36962 };
36963 last_off = cur + attrs.pos;
36964 }
36965 if !stack.is_empty() {
36966 stack.push(("OpGetobjDumpRequest", cur));
36967 }
36968 (stack, None)
36969 }
36970}
36971#[doc = "Get / dump stateful objects."]
36972pub struct PushOpGetobjDumpReply<Prev: Rec> {
36973 pub(crate) prev: Option<Prev>,
36974 pub(crate) header_offset: Option<usize>,
36975}
36976impl<Prev: Rec> Rec for PushOpGetobjDumpReply<Prev> {
36977 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
36978 self.prev.as_mut().unwrap().as_rec_mut()
36979 }
36980}
36981impl<Prev: Rec> PushOpGetobjDumpReply<Prev> {
36982 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
36983 Self::write_header(&mut prev, header);
36984 Self::new_without_header(prev)
36985 }
36986 fn new_without_header(prev: Prev) -> Self {
36987 Self {
36988 prev: Some(prev),
36989 header_offset: None,
36990 }
36991 }
36992 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
36993 prev.as_rec_mut().extend(header.as_slice());
36994 }
36995 pub fn end_nested(mut self) -> Prev {
36996 let mut prev = self.prev.take().unwrap();
36997 if let Some(header_offset) = &self.header_offset {
36998 finalize_nested_header(prev.as_rec_mut(), *header_offset);
36999 }
37000 prev
37001 }
37002 #[doc = "name of the table containing the expression"]
37003 pub fn push_table(mut self, value: &CStr) -> Self {
37004 push_header(
37005 self.as_rec_mut(),
37006 1u16,
37007 value.to_bytes_with_nul().len() as u16,
37008 );
37009 self.as_rec_mut().extend(value.to_bytes_with_nul());
37010 self
37011 }
37012 #[doc = "name of the table containing the expression"]
37013 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
37014 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
37015 self.as_rec_mut().extend(value);
37016 self.as_rec_mut().push(0);
37017 self
37018 }
37019 #[doc = "name of this expression type"]
37020 pub fn push_name(mut self, value: &CStr) -> Self {
37021 push_header(
37022 self.as_rec_mut(),
37023 2u16,
37024 value.to_bytes_with_nul().len() as u16,
37025 );
37026 self.as_rec_mut().extend(value.to_bytes_with_nul());
37027 self
37028 }
37029 #[doc = "name of this expression type"]
37030 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
37031 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
37032 self.as_rec_mut().extend(value);
37033 self.as_rec_mut().push(0);
37034 self
37035 }
37036 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
37037 pub fn push_type(mut self, value: u32) -> Self {
37038 push_header(self.as_rec_mut(), 3u16, 4 as u16);
37039 self.as_rec_mut().extend(value.to_be_bytes());
37040 self
37041 }
37042 #[doc = "stateful object data"]
37043 #[doc = "Selector attribute is inserted automatically."]
37044 #[doc = "At most one sub-message attribute is expected per attribute set."]
37045 pub fn nested_data_counter(mut self) -> PushCounterAttrs<PushDummy<Prev>> {
37046 self = self.push_type(ObjectType::Counter as u32);
37047 let new_header_offset = push_nested_header(self.as_rec_mut(), 4u16);
37048 let dummy = PushDummy {
37049 prev: self.prev.take(),
37050 header_offset: self.header_offset.take(),
37051 };
37052 PushCounterAttrs {
37053 prev: Some(dummy),
37054 header_offset: Some(new_header_offset),
37055 }
37056 }
37057 #[doc = "Selector attribute is inserted automatically."]
37058 #[doc = "At most one sub-message attribute is expected per attribute set."]
37059 pub fn nested_data_quota(mut self) -> PushQuotaAttrs<PushDummy<Prev>> {
37060 self = self.push_type(ObjectType::Quota as u32);
37061 let new_header_offset = push_nested_header(self.as_rec_mut(), 4u16);
37062 let dummy = PushDummy {
37063 prev: self.prev.take(),
37064 header_offset: self.header_offset.take(),
37065 };
37066 PushQuotaAttrs {
37067 prev: Some(dummy),
37068 header_offset: Some(new_header_offset),
37069 }
37070 }
37071 #[doc = "number of references to this expression"]
37072 pub fn push_use(mut self, value: u32) -> Self {
37073 push_header(self.as_rec_mut(), 5u16, 4 as u16);
37074 self.as_rec_mut().extend(value.to_be_bytes());
37075 self
37076 }
37077 #[doc = "object handle"]
37078 pub fn push_handle(mut self, value: u64) -> Self {
37079 push_header(self.as_rec_mut(), 6u16, 8 as u16);
37080 self.as_rec_mut().extend(value.to_be_bytes());
37081 self
37082 }
37083 #[doc = "user data"]
37084 pub fn push_userdata(mut self, value: &[u8]) -> Self {
37085 push_header(self.as_rec_mut(), 8u16, value.len() as u16);
37086 self.as_rec_mut().extend(value);
37087 self
37088 }
37089}
37090impl<Prev: Rec> Drop for PushOpGetobjDumpReply<Prev> {
37091 fn drop(&mut self) {
37092 if let Some(prev) = &mut self.prev {
37093 if let Some(header_offset) = &self.header_offset {
37094 finalize_nested_header(prev.as_rec_mut(), *header_offset);
37095 }
37096 }
37097 }
37098}
37099#[doc = "Get / dump stateful objects."]
37100#[derive(Clone)]
37101pub enum OpGetobjDumpReply<'a> {
37102 #[doc = "name of the table containing the expression"]
37103 Table(&'a CStr),
37104 #[doc = "name of this expression type"]
37105 Name(&'a CStr),
37106 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
37107 Type(u32),
37108 #[doc = "stateful object data"]
37109 Data(ObjData<'a>),
37110 #[doc = "number of references to this expression"]
37111 Use(u32),
37112 #[doc = "object handle"]
37113 Handle(u64),
37114 #[doc = "user data"]
37115 Userdata(&'a [u8]),
37116}
37117impl<'a> IterableOpGetobjDumpReply<'a> {
37118 #[doc = "name of the table containing the expression"]
37119 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
37120 let mut iter = self.clone();
37121 iter.pos = 0;
37122 for attr in iter {
37123 if let OpGetobjDumpReply::Table(val) = attr? {
37124 return Ok(val);
37125 }
37126 }
37127 Err(ErrorContext::new_missing(
37128 "OpGetobjDumpReply",
37129 "Table",
37130 self.orig_loc,
37131 self.buf.as_ptr() as usize,
37132 ))
37133 }
37134 #[doc = "name of this expression type"]
37135 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
37136 let mut iter = self.clone();
37137 iter.pos = 0;
37138 for attr in iter {
37139 if let OpGetobjDumpReply::Name(val) = attr? {
37140 return Ok(val);
37141 }
37142 }
37143 Err(ErrorContext::new_missing(
37144 "OpGetobjDumpReply",
37145 "Name",
37146 self.orig_loc,
37147 self.buf.as_ptr() as usize,
37148 ))
37149 }
37150 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
37151 pub fn get_type(&self) -> Result<u32, ErrorContext> {
37152 let mut iter = self.clone();
37153 iter.pos = 0;
37154 for attr in iter {
37155 if let OpGetobjDumpReply::Type(val) = attr? {
37156 return Ok(val);
37157 }
37158 }
37159 Err(ErrorContext::new_missing(
37160 "OpGetobjDumpReply",
37161 "Type",
37162 self.orig_loc,
37163 self.buf.as_ptr() as usize,
37164 ))
37165 }
37166 #[doc = "stateful object data"]
37167 pub fn get_data(&self) -> Result<ObjData<'a>, ErrorContext> {
37168 let mut iter = self.clone();
37169 iter.pos = 0;
37170 for attr in iter {
37171 if let OpGetobjDumpReply::Data(val) = attr? {
37172 return Ok(val);
37173 }
37174 }
37175 Err(ErrorContext::new_missing(
37176 "OpGetobjDumpReply",
37177 "Data",
37178 self.orig_loc,
37179 self.buf.as_ptr() as usize,
37180 ))
37181 }
37182 #[doc = "number of references to this expression"]
37183 pub fn get_use(&self) -> Result<u32, ErrorContext> {
37184 let mut iter = self.clone();
37185 iter.pos = 0;
37186 for attr in iter {
37187 if let OpGetobjDumpReply::Use(val) = attr? {
37188 return Ok(val);
37189 }
37190 }
37191 Err(ErrorContext::new_missing(
37192 "OpGetobjDumpReply",
37193 "Use",
37194 self.orig_loc,
37195 self.buf.as_ptr() as usize,
37196 ))
37197 }
37198 #[doc = "object handle"]
37199 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
37200 let mut iter = self.clone();
37201 iter.pos = 0;
37202 for attr in iter {
37203 if let OpGetobjDumpReply::Handle(val) = attr? {
37204 return Ok(val);
37205 }
37206 }
37207 Err(ErrorContext::new_missing(
37208 "OpGetobjDumpReply",
37209 "Handle",
37210 self.orig_loc,
37211 self.buf.as_ptr() as usize,
37212 ))
37213 }
37214 #[doc = "user data"]
37215 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
37216 let mut iter = self.clone();
37217 iter.pos = 0;
37218 for attr in iter {
37219 if let OpGetobjDumpReply::Userdata(val) = attr? {
37220 return Ok(val);
37221 }
37222 }
37223 Err(ErrorContext::new_missing(
37224 "OpGetobjDumpReply",
37225 "Userdata",
37226 self.orig_loc,
37227 self.buf.as_ptr() as usize,
37228 ))
37229 }
37230}
37231impl<'a> OpGetobjDumpReply<'a> {
37232 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetobjDumpReply<'a>) {
37233 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
37234 (
37235 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
37236 IterableOpGetobjDumpReply::with_loc(attrs, buf.as_ptr() as usize),
37237 )
37238 }
37239 fn attr_from_type(r#type: u16) -> Option<&'static str> {
37240 ObjAttrs::attr_from_type(r#type)
37241 }
37242}
37243#[derive(Clone, Copy, Default)]
37244pub struct IterableOpGetobjDumpReply<'a> {
37245 buf: &'a [u8],
37246 pos: usize,
37247 orig_loc: usize,
37248}
37249impl<'a> IterableOpGetobjDumpReply<'a> {
37250 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
37251 Self {
37252 buf,
37253 pos: 0,
37254 orig_loc,
37255 }
37256 }
37257 pub fn get_buf(&self) -> &'a [u8] {
37258 self.buf
37259 }
37260}
37261impl<'a> Iterator for IterableOpGetobjDumpReply<'a> {
37262 type Item = Result<OpGetobjDumpReply<'a>, ErrorContext>;
37263 fn next(&mut self) -> Option<Self::Item> {
37264 if self.buf.len() == self.pos {
37265 return None;
37266 }
37267 let pos = self.pos;
37268 let mut r#type = None;
37269 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
37270 r#type = Some(header.r#type);
37271 let res = match header.r#type {
37272 1u16 => OpGetobjDumpReply::Table({
37273 let res = CStr::from_bytes_with_nul(next).ok();
37274 let Some(val) = res else { break };
37275 val
37276 }),
37277 2u16 => OpGetobjDumpReply::Name({
37278 let res = CStr::from_bytes_with_nul(next).ok();
37279 let Some(val) = res else { break };
37280 val
37281 }),
37282 3u16 => OpGetobjDumpReply::Type({
37283 let res = parse_be_u32(next);
37284 let Some(val) = res else { break };
37285 val
37286 }),
37287 4u16 => OpGetobjDumpReply::Data({
37288 let res = {
37289 let Ok(selector) = self.get_type() else { break };
37290 ObjData::select_with_loc(selector, next, self.orig_loc)
37291 };
37292 let Some(val) = res else { break };
37293 val
37294 }),
37295 5u16 => OpGetobjDumpReply::Use({
37296 let res = parse_be_u32(next);
37297 let Some(val) = res else { break };
37298 val
37299 }),
37300 6u16 => OpGetobjDumpReply::Handle({
37301 let res = parse_be_u64(next);
37302 let Some(val) = res else { break };
37303 val
37304 }),
37305 8u16 => OpGetobjDumpReply::Userdata({
37306 let res = Some(next);
37307 let Some(val) = res else { break };
37308 val
37309 }),
37310 n => {
37311 if cfg!(any(test, feature = "deny-unknown-attrs")) {
37312 break;
37313 } else {
37314 continue;
37315 }
37316 }
37317 };
37318 return Some(Ok(res));
37319 }
37320 Some(Err(ErrorContext::new(
37321 "OpGetobjDumpReply",
37322 r#type.and_then(|t| OpGetobjDumpReply::attr_from_type(t)),
37323 self.orig_loc,
37324 self.buf.as_ptr().wrapping_add(pos) as usize,
37325 )))
37326 }
37327}
37328impl<'a> std::fmt::Debug for IterableOpGetobjDumpReply<'_> {
37329 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37330 let mut fmt = f.debug_struct("OpGetobjDumpReply");
37331 for attr in self.clone() {
37332 let attr = match attr {
37333 Ok(a) => a,
37334 Err(err) => {
37335 fmt.finish()?;
37336 f.write_str("Err(")?;
37337 err.fmt(f)?;
37338 return f.write_str(")");
37339 }
37340 };
37341 match attr {
37342 OpGetobjDumpReply::Table(val) => fmt.field("Table", &val),
37343 OpGetobjDumpReply::Name(val) => fmt.field("Name", &val),
37344 OpGetobjDumpReply::Type(val) => {
37345 fmt.field("Type", &FormatEnum(val.into(), ObjectType::from_value))
37346 }
37347 OpGetobjDumpReply::Data(val) => fmt.field("Data", &val),
37348 OpGetobjDumpReply::Use(val) => fmt.field("Use", &val),
37349 OpGetobjDumpReply::Handle(val) => fmt.field("Handle", &val),
37350 OpGetobjDumpReply::Userdata(val) => fmt.field("Userdata", &val),
37351 };
37352 }
37353 fmt.finish()
37354 }
37355}
37356impl IterableOpGetobjDumpReply<'_> {
37357 pub fn lookup_attr(
37358 &self,
37359 offset: usize,
37360 missing_type: Option<u16>,
37361 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37362 let mut stack = Vec::new();
37363 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
37364 if cur == offset + PushNfgenmsg::len() {
37365 stack.push(("OpGetobjDumpReply", offset));
37366 return (
37367 stack,
37368 missing_type.and_then(|t| OpGetobjDumpReply::attr_from_type(t)),
37369 );
37370 }
37371 if cur > offset || cur + self.buf.len() < offset {
37372 return (stack, None);
37373 }
37374 let mut attrs = self.clone();
37375 let mut last_off = cur + attrs.pos;
37376 while let Some(attr) = attrs.next() {
37377 let Ok(attr) = attr else { break };
37378 match attr {
37379 OpGetobjDumpReply::Table(val) => {
37380 if last_off == offset {
37381 stack.push(("Table", last_off));
37382 break;
37383 }
37384 }
37385 OpGetobjDumpReply::Name(val) => {
37386 if last_off == offset {
37387 stack.push(("Name", last_off));
37388 break;
37389 }
37390 }
37391 OpGetobjDumpReply::Type(val) => {
37392 if last_off == offset {
37393 stack.push(("Type", last_off));
37394 break;
37395 }
37396 }
37397 OpGetobjDumpReply::Data(val) => {
37398 if last_off == offset {
37399 stack.push(("Data", last_off));
37400 break;
37401 }
37402 }
37403 OpGetobjDumpReply::Use(val) => {
37404 if last_off == offset {
37405 stack.push(("Use", last_off));
37406 break;
37407 }
37408 }
37409 OpGetobjDumpReply::Handle(val) => {
37410 if last_off == offset {
37411 stack.push(("Handle", last_off));
37412 break;
37413 }
37414 }
37415 OpGetobjDumpReply::Userdata(val) => {
37416 if last_off == offset {
37417 stack.push(("Userdata", last_off));
37418 break;
37419 }
37420 }
37421 _ => {}
37422 };
37423 last_off = cur + attrs.pos;
37424 }
37425 if !stack.is_empty() {
37426 stack.push(("OpGetobjDumpReply", cur));
37427 }
37428 (stack, None)
37429 }
37430}
37431#[derive(Debug)]
37432pub struct RequestOpGetobjDumpRequest<'r> {
37433 request: Request<'r>,
37434}
37435impl<'r> RequestOpGetobjDumpRequest<'r> {
37436 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
37437 PushOpGetobjDumpRequest::write_header(&mut request.buf_mut(), header);
37438 Self {
37439 request: request.set_dump(),
37440 }
37441 }
37442 pub fn encode(&mut self) -> PushOpGetobjDumpRequest<&mut Vec<u8>> {
37443 PushOpGetobjDumpRequest::new_without_header(self.request.buf_mut())
37444 }
37445 pub fn into_encoder(self) -> PushOpGetobjDumpRequest<RequestBuf<'r>> {
37446 PushOpGetobjDumpRequest::new_without_header(self.request.buf)
37447 }
37448}
37449impl NetlinkRequest for RequestOpGetobjDumpRequest<'_> {
37450 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetobjDumpReply<'buf>);
37451 fn protocol(&self) -> Protocol {
37452 Protocol::Raw {
37453 protonum: 12u16,
37454 request_type: 2579u16,
37455 }
37456 }
37457 fn flags(&self) -> u16 {
37458 self.request.flags
37459 }
37460 fn payload(&self) -> &[u8] {
37461 self.request.buf()
37462 }
37463 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
37464 OpGetobjDumpReply::new(buf)
37465 }
37466 fn lookup(
37467 buf: &[u8],
37468 offset: usize,
37469 missing_type: Option<u16>,
37470 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37471 OpGetobjDumpRequest::new(buf)
37472 .1
37473 .lookup_attr(offset, missing_type)
37474 }
37475}
37476#[doc = "Get / dump stateful objects."]
37477pub struct PushOpGetobjDoRequest<Prev: Rec> {
37478 pub(crate) prev: Option<Prev>,
37479 pub(crate) header_offset: Option<usize>,
37480}
37481impl<Prev: Rec> Rec for PushOpGetobjDoRequest<Prev> {
37482 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
37483 self.prev.as_mut().unwrap().as_rec_mut()
37484 }
37485}
37486impl<Prev: Rec> PushOpGetobjDoRequest<Prev> {
37487 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
37488 Self::write_header(&mut prev, header);
37489 Self::new_without_header(prev)
37490 }
37491 fn new_without_header(prev: Prev) -> Self {
37492 Self {
37493 prev: Some(prev),
37494 header_offset: None,
37495 }
37496 }
37497 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
37498 prev.as_rec_mut().extend(header.as_slice());
37499 }
37500 pub fn end_nested(mut self) -> Prev {
37501 let mut prev = self.prev.take().unwrap();
37502 if let Some(header_offset) = &self.header_offset {
37503 finalize_nested_header(prev.as_rec_mut(), *header_offset);
37504 }
37505 prev
37506 }
37507 #[doc = "name of the table containing the expression"]
37508 pub fn push_table(mut self, value: &CStr) -> Self {
37509 push_header(
37510 self.as_rec_mut(),
37511 1u16,
37512 value.to_bytes_with_nul().len() as u16,
37513 );
37514 self.as_rec_mut().extend(value.to_bytes_with_nul());
37515 self
37516 }
37517 #[doc = "name of the table containing the expression"]
37518 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
37519 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
37520 self.as_rec_mut().extend(value);
37521 self.as_rec_mut().push(0);
37522 self
37523 }
37524 #[doc = "name of this expression type"]
37525 pub fn push_name(mut self, value: &CStr) -> Self {
37526 push_header(
37527 self.as_rec_mut(),
37528 2u16,
37529 value.to_bytes_with_nul().len() as u16,
37530 );
37531 self.as_rec_mut().extend(value.to_bytes_with_nul());
37532 self
37533 }
37534 #[doc = "name of this expression type"]
37535 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
37536 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
37537 self.as_rec_mut().extend(value);
37538 self.as_rec_mut().push(0);
37539 self
37540 }
37541 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
37542 pub fn push_type(mut self, value: u32) -> Self {
37543 push_header(self.as_rec_mut(), 3u16, 4 as u16);
37544 self.as_rec_mut().extend(value.to_be_bytes());
37545 self
37546 }
37547}
37548impl<Prev: Rec> Drop for PushOpGetobjDoRequest<Prev> {
37549 fn drop(&mut self) {
37550 if let Some(prev) = &mut self.prev {
37551 if let Some(header_offset) = &self.header_offset {
37552 finalize_nested_header(prev.as_rec_mut(), *header_offset);
37553 }
37554 }
37555 }
37556}
37557#[doc = "Get / dump stateful objects."]
37558#[derive(Clone)]
37559pub enum OpGetobjDoRequest<'a> {
37560 #[doc = "name of the table containing the expression"]
37561 Table(&'a CStr),
37562 #[doc = "name of this expression type"]
37563 Name(&'a CStr),
37564 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
37565 Type(u32),
37566}
37567impl<'a> IterableOpGetobjDoRequest<'a> {
37568 #[doc = "name of the table containing the expression"]
37569 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
37570 let mut iter = self.clone();
37571 iter.pos = 0;
37572 for attr in iter {
37573 if let OpGetobjDoRequest::Table(val) = attr? {
37574 return Ok(val);
37575 }
37576 }
37577 Err(ErrorContext::new_missing(
37578 "OpGetobjDoRequest",
37579 "Table",
37580 self.orig_loc,
37581 self.buf.as_ptr() as usize,
37582 ))
37583 }
37584 #[doc = "name of this expression type"]
37585 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
37586 let mut iter = self.clone();
37587 iter.pos = 0;
37588 for attr in iter {
37589 if let OpGetobjDoRequest::Name(val) = attr? {
37590 return Ok(val);
37591 }
37592 }
37593 Err(ErrorContext::new_missing(
37594 "OpGetobjDoRequest",
37595 "Name",
37596 self.orig_loc,
37597 self.buf.as_ptr() as usize,
37598 ))
37599 }
37600 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
37601 pub fn get_type(&self) -> Result<u32, ErrorContext> {
37602 let mut iter = self.clone();
37603 iter.pos = 0;
37604 for attr in iter {
37605 if let OpGetobjDoRequest::Type(val) = attr? {
37606 return Ok(val);
37607 }
37608 }
37609 Err(ErrorContext::new_missing(
37610 "OpGetobjDoRequest",
37611 "Type",
37612 self.orig_loc,
37613 self.buf.as_ptr() as usize,
37614 ))
37615 }
37616}
37617impl<'a> OpGetobjDoRequest<'a> {
37618 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetobjDoRequest<'a>) {
37619 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
37620 (
37621 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
37622 IterableOpGetobjDoRequest::with_loc(attrs, buf.as_ptr() as usize),
37623 )
37624 }
37625 fn attr_from_type(r#type: u16) -> Option<&'static str> {
37626 ObjAttrs::attr_from_type(r#type)
37627 }
37628}
37629#[derive(Clone, Copy, Default)]
37630pub struct IterableOpGetobjDoRequest<'a> {
37631 buf: &'a [u8],
37632 pos: usize,
37633 orig_loc: usize,
37634}
37635impl<'a> IterableOpGetobjDoRequest<'a> {
37636 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
37637 Self {
37638 buf,
37639 pos: 0,
37640 orig_loc,
37641 }
37642 }
37643 pub fn get_buf(&self) -> &'a [u8] {
37644 self.buf
37645 }
37646}
37647impl<'a> Iterator for IterableOpGetobjDoRequest<'a> {
37648 type Item = Result<OpGetobjDoRequest<'a>, ErrorContext>;
37649 fn next(&mut self) -> Option<Self::Item> {
37650 if self.buf.len() == self.pos {
37651 return None;
37652 }
37653 let pos = self.pos;
37654 let mut r#type = None;
37655 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
37656 r#type = Some(header.r#type);
37657 let res = match header.r#type {
37658 1u16 => OpGetobjDoRequest::Table({
37659 let res = CStr::from_bytes_with_nul(next).ok();
37660 let Some(val) = res else { break };
37661 val
37662 }),
37663 2u16 => OpGetobjDoRequest::Name({
37664 let res = CStr::from_bytes_with_nul(next).ok();
37665 let Some(val) = res else { break };
37666 val
37667 }),
37668 3u16 => OpGetobjDoRequest::Type({
37669 let res = parse_be_u32(next);
37670 let Some(val) = res else { break };
37671 val
37672 }),
37673 n => {
37674 if cfg!(any(test, feature = "deny-unknown-attrs")) {
37675 break;
37676 } else {
37677 continue;
37678 }
37679 }
37680 };
37681 return Some(Ok(res));
37682 }
37683 Some(Err(ErrorContext::new(
37684 "OpGetobjDoRequest",
37685 r#type.and_then(|t| OpGetobjDoRequest::attr_from_type(t)),
37686 self.orig_loc,
37687 self.buf.as_ptr().wrapping_add(pos) as usize,
37688 )))
37689 }
37690}
37691impl<'a> std::fmt::Debug for IterableOpGetobjDoRequest<'_> {
37692 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37693 let mut fmt = f.debug_struct("OpGetobjDoRequest");
37694 for attr in self.clone() {
37695 let attr = match attr {
37696 Ok(a) => a,
37697 Err(err) => {
37698 fmt.finish()?;
37699 f.write_str("Err(")?;
37700 err.fmt(f)?;
37701 return f.write_str(")");
37702 }
37703 };
37704 match attr {
37705 OpGetobjDoRequest::Table(val) => fmt.field("Table", &val),
37706 OpGetobjDoRequest::Name(val) => fmt.field("Name", &val),
37707 OpGetobjDoRequest::Type(val) => {
37708 fmt.field("Type", &FormatEnum(val.into(), ObjectType::from_value))
37709 }
37710 };
37711 }
37712 fmt.finish()
37713 }
37714}
37715impl IterableOpGetobjDoRequest<'_> {
37716 pub fn lookup_attr(
37717 &self,
37718 offset: usize,
37719 missing_type: Option<u16>,
37720 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
37721 let mut stack = Vec::new();
37722 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
37723 if cur == offset + PushNfgenmsg::len() {
37724 stack.push(("OpGetobjDoRequest", offset));
37725 return (
37726 stack,
37727 missing_type.and_then(|t| OpGetobjDoRequest::attr_from_type(t)),
37728 );
37729 }
37730 if cur > offset || cur + self.buf.len() < offset {
37731 return (stack, None);
37732 }
37733 let mut attrs = self.clone();
37734 let mut last_off = cur + attrs.pos;
37735 while let Some(attr) = attrs.next() {
37736 let Ok(attr) = attr else { break };
37737 match attr {
37738 OpGetobjDoRequest::Table(val) => {
37739 if last_off == offset {
37740 stack.push(("Table", last_off));
37741 break;
37742 }
37743 }
37744 OpGetobjDoRequest::Name(val) => {
37745 if last_off == offset {
37746 stack.push(("Name", last_off));
37747 break;
37748 }
37749 }
37750 OpGetobjDoRequest::Type(val) => {
37751 if last_off == offset {
37752 stack.push(("Type", last_off));
37753 break;
37754 }
37755 }
37756 _ => {}
37757 };
37758 last_off = cur + attrs.pos;
37759 }
37760 if !stack.is_empty() {
37761 stack.push(("OpGetobjDoRequest", cur));
37762 }
37763 (stack, None)
37764 }
37765}
37766#[doc = "Get / dump stateful objects."]
37767pub struct PushOpGetobjDoReply<Prev: Rec> {
37768 pub(crate) prev: Option<Prev>,
37769 pub(crate) header_offset: Option<usize>,
37770}
37771impl<Prev: Rec> Rec for PushOpGetobjDoReply<Prev> {
37772 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
37773 self.prev.as_mut().unwrap().as_rec_mut()
37774 }
37775}
37776impl<Prev: Rec> PushOpGetobjDoReply<Prev> {
37777 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
37778 Self::write_header(&mut prev, header);
37779 Self::new_without_header(prev)
37780 }
37781 fn new_without_header(prev: Prev) -> Self {
37782 Self {
37783 prev: Some(prev),
37784 header_offset: None,
37785 }
37786 }
37787 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
37788 prev.as_rec_mut().extend(header.as_slice());
37789 }
37790 pub fn end_nested(mut self) -> Prev {
37791 let mut prev = self.prev.take().unwrap();
37792 if let Some(header_offset) = &self.header_offset {
37793 finalize_nested_header(prev.as_rec_mut(), *header_offset);
37794 }
37795 prev
37796 }
37797 #[doc = "name of the table containing the expression"]
37798 pub fn push_table(mut self, value: &CStr) -> Self {
37799 push_header(
37800 self.as_rec_mut(),
37801 1u16,
37802 value.to_bytes_with_nul().len() as u16,
37803 );
37804 self.as_rec_mut().extend(value.to_bytes_with_nul());
37805 self
37806 }
37807 #[doc = "name of the table containing the expression"]
37808 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
37809 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
37810 self.as_rec_mut().extend(value);
37811 self.as_rec_mut().push(0);
37812 self
37813 }
37814 #[doc = "name of this expression type"]
37815 pub fn push_name(mut self, value: &CStr) -> Self {
37816 push_header(
37817 self.as_rec_mut(),
37818 2u16,
37819 value.to_bytes_with_nul().len() as u16,
37820 );
37821 self.as_rec_mut().extend(value.to_bytes_with_nul());
37822 self
37823 }
37824 #[doc = "name of this expression type"]
37825 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
37826 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
37827 self.as_rec_mut().extend(value);
37828 self.as_rec_mut().push(0);
37829 self
37830 }
37831 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
37832 pub fn push_type(mut self, value: u32) -> Self {
37833 push_header(self.as_rec_mut(), 3u16, 4 as u16);
37834 self.as_rec_mut().extend(value.to_be_bytes());
37835 self
37836 }
37837 #[doc = "stateful object data"]
37838 #[doc = "Selector attribute is inserted automatically."]
37839 #[doc = "At most one sub-message attribute is expected per attribute set."]
37840 pub fn nested_data_counter(mut self) -> PushCounterAttrs<PushDummy<Prev>> {
37841 self = self.push_type(ObjectType::Counter as u32);
37842 let new_header_offset = push_nested_header(self.as_rec_mut(), 4u16);
37843 let dummy = PushDummy {
37844 prev: self.prev.take(),
37845 header_offset: self.header_offset.take(),
37846 };
37847 PushCounterAttrs {
37848 prev: Some(dummy),
37849 header_offset: Some(new_header_offset),
37850 }
37851 }
37852 #[doc = "Selector attribute is inserted automatically."]
37853 #[doc = "At most one sub-message attribute is expected per attribute set."]
37854 pub fn nested_data_quota(mut self) -> PushQuotaAttrs<PushDummy<Prev>> {
37855 self = self.push_type(ObjectType::Quota as u32);
37856 let new_header_offset = push_nested_header(self.as_rec_mut(), 4u16);
37857 let dummy = PushDummy {
37858 prev: self.prev.take(),
37859 header_offset: self.header_offset.take(),
37860 };
37861 PushQuotaAttrs {
37862 prev: Some(dummy),
37863 header_offset: Some(new_header_offset),
37864 }
37865 }
37866 #[doc = "number of references to this expression"]
37867 pub fn push_use(mut self, value: u32) -> Self {
37868 push_header(self.as_rec_mut(), 5u16, 4 as u16);
37869 self.as_rec_mut().extend(value.to_be_bytes());
37870 self
37871 }
37872 #[doc = "object handle"]
37873 pub fn push_handle(mut self, value: u64) -> Self {
37874 push_header(self.as_rec_mut(), 6u16, 8 as u16);
37875 self.as_rec_mut().extend(value.to_be_bytes());
37876 self
37877 }
37878 #[doc = "user data"]
37879 pub fn push_userdata(mut self, value: &[u8]) -> Self {
37880 push_header(self.as_rec_mut(), 8u16, value.len() as u16);
37881 self.as_rec_mut().extend(value);
37882 self
37883 }
37884}
37885impl<Prev: Rec> Drop for PushOpGetobjDoReply<Prev> {
37886 fn drop(&mut self) {
37887 if let Some(prev) = &mut self.prev {
37888 if let Some(header_offset) = &self.header_offset {
37889 finalize_nested_header(prev.as_rec_mut(), *header_offset);
37890 }
37891 }
37892 }
37893}
37894#[doc = "Get / dump stateful objects."]
37895#[derive(Clone)]
37896pub enum OpGetobjDoReply<'a> {
37897 #[doc = "name of the table containing the expression"]
37898 Table(&'a CStr),
37899 #[doc = "name of this expression type"]
37900 Name(&'a CStr),
37901 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
37902 Type(u32),
37903 #[doc = "stateful object data"]
37904 Data(ObjData<'a>),
37905 #[doc = "number of references to this expression"]
37906 Use(u32),
37907 #[doc = "object handle"]
37908 Handle(u64),
37909 #[doc = "user data"]
37910 Userdata(&'a [u8]),
37911}
37912impl<'a> IterableOpGetobjDoReply<'a> {
37913 #[doc = "name of the table containing the expression"]
37914 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
37915 let mut iter = self.clone();
37916 iter.pos = 0;
37917 for attr in iter {
37918 if let OpGetobjDoReply::Table(val) = attr? {
37919 return Ok(val);
37920 }
37921 }
37922 Err(ErrorContext::new_missing(
37923 "OpGetobjDoReply",
37924 "Table",
37925 self.orig_loc,
37926 self.buf.as_ptr() as usize,
37927 ))
37928 }
37929 #[doc = "name of this expression type"]
37930 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
37931 let mut iter = self.clone();
37932 iter.pos = 0;
37933 for attr in iter {
37934 if let OpGetobjDoReply::Name(val) = attr? {
37935 return Ok(val);
37936 }
37937 }
37938 Err(ErrorContext::new_missing(
37939 "OpGetobjDoReply",
37940 "Name",
37941 self.orig_loc,
37942 self.buf.as_ptr() as usize,
37943 ))
37944 }
37945 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
37946 pub fn get_type(&self) -> Result<u32, ErrorContext> {
37947 let mut iter = self.clone();
37948 iter.pos = 0;
37949 for attr in iter {
37950 if let OpGetobjDoReply::Type(val) = attr? {
37951 return Ok(val);
37952 }
37953 }
37954 Err(ErrorContext::new_missing(
37955 "OpGetobjDoReply",
37956 "Type",
37957 self.orig_loc,
37958 self.buf.as_ptr() as usize,
37959 ))
37960 }
37961 #[doc = "stateful object data"]
37962 pub fn get_data(&self) -> Result<ObjData<'a>, ErrorContext> {
37963 let mut iter = self.clone();
37964 iter.pos = 0;
37965 for attr in iter {
37966 if let OpGetobjDoReply::Data(val) = attr? {
37967 return Ok(val);
37968 }
37969 }
37970 Err(ErrorContext::new_missing(
37971 "OpGetobjDoReply",
37972 "Data",
37973 self.orig_loc,
37974 self.buf.as_ptr() as usize,
37975 ))
37976 }
37977 #[doc = "number of references to this expression"]
37978 pub fn get_use(&self) -> Result<u32, ErrorContext> {
37979 let mut iter = self.clone();
37980 iter.pos = 0;
37981 for attr in iter {
37982 if let OpGetobjDoReply::Use(val) = attr? {
37983 return Ok(val);
37984 }
37985 }
37986 Err(ErrorContext::new_missing(
37987 "OpGetobjDoReply",
37988 "Use",
37989 self.orig_loc,
37990 self.buf.as_ptr() as usize,
37991 ))
37992 }
37993 #[doc = "object handle"]
37994 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
37995 let mut iter = self.clone();
37996 iter.pos = 0;
37997 for attr in iter {
37998 if let OpGetobjDoReply::Handle(val) = attr? {
37999 return Ok(val);
38000 }
38001 }
38002 Err(ErrorContext::new_missing(
38003 "OpGetobjDoReply",
38004 "Handle",
38005 self.orig_loc,
38006 self.buf.as_ptr() as usize,
38007 ))
38008 }
38009 #[doc = "user data"]
38010 pub fn get_userdata(&self) -> Result<&'a [u8], ErrorContext> {
38011 let mut iter = self.clone();
38012 iter.pos = 0;
38013 for attr in iter {
38014 if let OpGetobjDoReply::Userdata(val) = attr? {
38015 return Ok(val);
38016 }
38017 }
38018 Err(ErrorContext::new_missing(
38019 "OpGetobjDoReply",
38020 "Userdata",
38021 self.orig_loc,
38022 self.buf.as_ptr() as usize,
38023 ))
38024 }
38025}
38026impl<'a> OpGetobjDoReply<'a> {
38027 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetobjDoReply<'a>) {
38028 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
38029 (
38030 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
38031 IterableOpGetobjDoReply::with_loc(attrs, buf.as_ptr() as usize),
38032 )
38033 }
38034 fn attr_from_type(r#type: u16) -> Option<&'static str> {
38035 ObjAttrs::attr_from_type(r#type)
38036 }
38037}
38038#[derive(Clone, Copy, Default)]
38039pub struct IterableOpGetobjDoReply<'a> {
38040 buf: &'a [u8],
38041 pos: usize,
38042 orig_loc: usize,
38043}
38044impl<'a> IterableOpGetobjDoReply<'a> {
38045 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
38046 Self {
38047 buf,
38048 pos: 0,
38049 orig_loc,
38050 }
38051 }
38052 pub fn get_buf(&self) -> &'a [u8] {
38053 self.buf
38054 }
38055}
38056impl<'a> Iterator for IterableOpGetobjDoReply<'a> {
38057 type Item = Result<OpGetobjDoReply<'a>, ErrorContext>;
38058 fn next(&mut self) -> Option<Self::Item> {
38059 if self.buf.len() == self.pos {
38060 return None;
38061 }
38062 let pos = self.pos;
38063 let mut r#type = None;
38064 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
38065 r#type = Some(header.r#type);
38066 let res = match header.r#type {
38067 1u16 => OpGetobjDoReply::Table({
38068 let res = CStr::from_bytes_with_nul(next).ok();
38069 let Some(val) = res else { break };
38070 val
38071 }),
38072 2u16 => OpGetobjDoReply::Name({
38073 let res = CStr::from_bytes_with_nul(next).ok();
38074 let Some(val) = res else { break };
38075 val
38076 }),
38077 3u16 => OpGetobjDoReply::Type({
38078 let res = parse_be_u32(next);
38079 let Some(val) = res else { break };
38080 val
38081 }),
38082 4u16 => OpGetobjDoReply::Data({
38083 let res = {
38084 let Ok(selector) = self.get_type() else { break };
38085 ObjData::select_with_loc(selector, next, self.orig_loc)
38086 };
38087 let Some(val) = res else { break };
38088 val
38089 }),
38090 5u16 => OpGetobjDoReply::Use({
38091 let res = parse_be_u32(next);
38092 let Some(val) = res else { break };
38093 val
38094 }),
38095 6u16 => OpGetobjDoReply::Handle({
38096 let res = parse_be_u64(next);
38097 let Some(val) = res else { break };
38098 val
38099 }),
38100 8u16 => OpGetobjDoReply::Userdata({
38101 let res = Some(next);
38102 let Some(val) = res else { break };
38103 val
38104 }),
38105 n => {
38106 if cfg!(any(test, feature = "deny-unknown-attrs")) {
38107 break;
38108 } else {
38109 continue;
38110 }
38111 }
38112 };
38113 return Some(Ok(res));
38114 }
38115 Some(Err(ErrorContext::new(
38116 "OpGetobjDoReply",
38117 r#type.and_then(|t| OpGetobjDoReply::attr_from_type(t)),
38118 self.orig_loc,
38119 self.buf.as_ptr().wrapping_add(pos) as usize,
38120 )))
38121 }
38122}
38123impl<'a> std::fmt::Debug for IterableOpGetobjDoReply<'_> {
38124 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38125 let mut fmt = f.debug_struct("OpGetobjDoReply");
38126 for attr in self.clone() {
38127 let attr = match attr {
38128 Ok(a) => a,
38129 Err(err) => {
38130 fmt.finish()?;
38131 f.write_str("Err(")?;
38132 err.fmt(f)?;
38133 return f.write_str(")");
38134 }
38135 };
38136 match attr {
38137 OpGetobjDoReply::Table(val) => fmt.field("Table", &val),
38138 OpGetobjDoReply::Name(val) => fmt.field("Name", &val),
38139 OpGetobjDoReply::Type(val) => {
38140 fmt.field("Type", &FormatEnum(val.into(), ObjectType::from_value))
38141 }
38142 OpGetobjDoReply::Data(val) => fmt.field("Data", &val),
38143 OpGetobjDoReply::Use(val) => fmt.field("Use", &val),
38144 OpGetobjDoReply::Handle(val) => fmt.field("Handle", &val),
38145 OpGetobjDoReply::Userdata(val) => fmt.field("Userdata", &val),
38146 };
38147 }
38148 fmt.finish()
38149 }
38150}
38151impl IterableOpGetobjDoReply<'_> {
38152 pub fn lookup_attr(
38153 &self,
38154 offset: usize,
38155 missing_type: Option<u16>,
38156 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38157 let mut stack = Vec::new();
38158 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
38159 if cur == offset + PushNfgenmsg::len() {
38160 stack.push(("OpGetobjDoReply", offset));
38161 return (
38162 stack,
38163 missing_type.and_then(|t| OpGetobjDoReply::attr_from_type(t)),
38164 );
38165 }
38166 if cur > offset || cur + self.buf.len() < offset {
38167 return (stack, None);
38168 }
38169 let mut attrs = self.clone();
38170 let mut last_off = cur + attrs.pos;
38171 while let Some(attr) = attrs.next() {
38172 let Ok(attr) = attr else { break };
38173 match attr {
38174 OpGetobjDoReply::Table(val) => {
38175 if last_off == offset {
38176 stack.push(("Table", last_off));
38177 break;
38178 }
38179 }
38180 OpGetobjDoReply::Name(val) => {
38181 if last_off == offset {
38182 stack.push(("Name", last_off));
38183 break;
38184 }
38185 }
38186 OpGetobjDoReply::Type(val) => {
38187 if last_off == offset {
38188 stack.push(("Type", last_off));
38189 break;
38190 }
38191 }
38192 OpGetobjDoReply::Data(val) => {
38193 if last_off == offset {
38194 stack.push(("Data", last_off));
38195 break;
38196 }
38197 }
38198 OpGetobjDoReply::Use(val) => {
38199 if last_off == offset {
38200 stack.push(("Use", last_off));
38201 break;
38202 }
38203 }
38204 OpGetobjDoReply::Handle(val) => {
38205 if last_off == offset {
38206 stack.push(("Handle", last_off));
38207 break;
38208 }
38209 }
38210 OpGetobjDoReply::Userdata(val) => {
38211 if last_off == offset {
38212 stack.push(("Userdata", last_off));
38213 break;
38214 }
38215 }
38216 _ => {}
38217 };
38218 last_off = cur + attrs.pos;
38219 }
38220 if !stack.is_empty() {
38221 stack.push(("OpGetobjDoReply", cur));
38222 }
38223 (stack, None)
38224 }
38225}
38226#[derive(Debug)]
38227pub struct RequestOpGetobjDoRequest<'r> {
38228 request: Request<'r>,
38229}
38230impl<'r> RequestOpGetobjDoRequest<'r> {
38231 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
38232 PushOpGetobjDoRequest::write_header(&mut request.buf_mut(), header);
38233 Self { request: request }
38234 }
38235 pub fn encode(&mut self) -> PushOpGetobjDoRequest<&mut Vec<u8>> {
38236 PushOpGetobjDoRequest::new_without_header(self.request.buf_mut())
38237 }
38238 pub fn into_encoder(self) -> PushOpGetobjDoRequest<RequestBuf<'r>> {
38239 PushOpGetobjDoRequest::new_without_header(self.request.buf)
38240 }
38241}
38242impl NetlinkRequest for RequestOpGetobjDoRequest<'_> {
38243 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetobjDoReply<'buf>);
38244 fn protocol(&self) -> Protocol {
38245 Protocol::Raw {
38246 protonum: 12u16,
38247 request_type: 2579u16,
38248 }
38249 }
38250 fn flags(&self) -> u16 {
38251 self.request.flags
38252 }
38253 fn payload(&self) -> &[u8] {
38254 self.request.buf()
38255 }
38256 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
38257 OpGetobjDoReply::new(buf)
38258 }
38259 fn lookup(
38260 buf: &[u8],
38261 offset: usize,
38262 missing_type: Option<u16>,
38263 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38264 OpGetobjDoRequest::new(buf)
38265 .1
38266 .lookup_attr(offset, missing_type)
38267 }
38268}
38269#[doc = "Delete an existing stateful object."]
38270pub struct PushOpDelobjDoRequest<Prev: Rec> {
38271 pub(crate) prev: Option<Prev>,
38272 pub(crate) header_offset: Option<usize>,
38273}
38274impl<Prev: Rec> Rec for PushOpDelobjDoRequest<Prev> {
38275 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
38276 self.prev.as_mut().unwrap().as_rec_mut()
38277 }
38278}
38279impl<Prev: Rec> PushOpDelobjDoRequest<Prev> {
38280 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
38281 Self::write_header(&mut prev, header);
38282 Self::new_without_header(prev)
38283 }
38284 fn new_without_header(prev: Prev) -> Self {
38285 Self {
38286 prev: Some(prev),
38287 header_offset: None,
38288 }
38289 }
38290 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
38291 prev.as_rec_mut().extend(header.as_slice());
38292 }
38293 pub fn end_nested(mut self) -> Prev {
38294 let mut prev = self.prev.take().unwrap();
38295 if let Some(header_offset) = &self.header_offset {
38296 finalize_nested_header(prev.as_rec_mut(), *header_offset);
38297 }
38298 prev
38299 }
38300 #[doc = "name of the table containing the expression"]
38301 pub fn push_table(mut self, value: &CStr) -> Self {
38302 push_header(
38303 self.as_rec_mut(),
38304 1u16,
38305 value.to_bytes_with_nul().len() as u16,
38306 );
38307 self.as_rec_mut().extend(value.to_bytes_with_nul());
38308 self
38309 }
38310 #[doc = "name of the table containing the expression"]
38311 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
38312 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
38313 self.as_rec_mut().extend(value);
38314 self.as_rec_mut().push(0);
38315 self
38316 }
38317 #[doc = "name of this expression type"]
38318 pub fn push_name(mut self, value: &CStr) -> Self {
38319 push_header(
38320 self.as_rec_mut(),
38321 2u16,
38322 value.to_bytes_with_nul().len() as u16,
38323 );
38324 self.as_rec_mut().extend(value.to_bytes_with_nul());
38325 self
38326 }
38327 #[doc = "name of this expression type"]
38328 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
38329 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
38330 self.as_rec_mut().extend(value);
38331 self.as_rec_mut().push(0);
38332 self
38333 }
38334 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
38335 pub fn push_type(mut self, value: u32) -> Self {
38336 push_header(self.as_rec_mut(), 3u16, 4 as u16);
38337 self.as_rec_mut().extend(value.to_be_bytes());
38338 self
38339 }
38340 #[doc = "object handle"]
38341 pub fn push_handle(mut self, value: u64) -> Self {
38342 push_header(self.as_rec_mut(), 6u16, 8 as u16);
38343 self.as_rec_mut().extend(value.to_be_bytes());
38344 self
38345 }
38346}
38347impl<Prev: Rec> Drop for PushOpDelobjDoRequest<Prev> {
38348 fn drop(&mut self) {
38349 if let Some(prev) = &mut self.prev {
38350 if let Some(header_offset) = &self.header_offset {
38351 finalize_nested_header(prev.as_rec_mut(), *header_offset);
38352 }
38353 }
38354 }
38355}
38356#[doc = "Delete an existing stateful object."]
38357#[derive(Clone)]
38358pub enum OpDelobjDoRequest<'a> {
38359 #[doc = "name of the table containing the expression"]
38360 Table(&'a CStr),
38361 #[doc = "name of this expression type"]
38362 Name(&'a CStr),
38363 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
38364 Type(u32),
38365 #[doc = "object handle"]
38366 Handle(u64),
38367}
38368impl<'a> IterableOpDelobjDoRequest<'a> {
38369 #[doc = "name of the table containing the expression"]
38370 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
38371 let mut iter = self.clone();
38372 iter.pos = 0;
38373 for attr in iter {
38374 if let OpDelobjDoRequest::Table(val) = attr? {
38375 return Ok(val);
38376 }
38377 }
38378 Err(ErrorContext::new_missing(
38379 "OpDelobjDoRequest",
38380 "Table",
38381 self.orig_loc,
38382 self.buf.as_ptr() as usize,
38383 ))
38384 }
38385 #[doc = "name of this expression type"]
38386 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
38387 let mut iter = self.clone();
38388 iter.pos = 0;
38389 for attr in iter {
38390 if let OpDelobjDoRequest::Name(val) = attr? {
38391 return Ok(val);
38392 }
38393 }
38394 Err(ErrorContext::new_missing(
38395 "OpDelobjDoRequest",
38396 "Name",
38397 self.orig_loc,
38398 self.buf.as_ptr() as usize,
38399 ))
38400 }
38401 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
38402 pub fn get_type(&self) -> Result<u32, ErrorContext> {
38403 let mut iter = self.clone();
38404 iter.pos = 0;
38405 for attr in iter {
38406 if let OpDelobjDoRequest::Type(val) = attr? {
38407 return Ok(val);
38408 }
38409 }
38410 Err(ErrorContext::new_missing(
38411 "OpDelobjDoRequest",
38412 "Type",
38413 self.orig_loc,
38414 self.buf.as_ptr() as usize,
38415 ))
38416 }
38417 #[doc = "object handle"]
38418 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
38419 let mut iter = self.clone();
38420 iter.pos = 0;
38421 for attr in iter {
38422 if let OpDelobjDoRequest::Handle(val) = attr? {
38423 return Ok(val);
38424 }
38425 }
38426 Err(ErrorContext::new_missing(
38427 "OpDelobjDoRequest",
38428 "Handle",
38429 self.orig_loc,
38430 self.buf.as_ptr() as usize,
38431 ))
38432 }
38433}
38434impl<'a> OpDelobjDoRequest<'a> {
38435 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDelobjDoRequest<'a>) {
38436 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
38437 (
38438 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
38439 IterableOpDelobjDoRequest::with_loc(attrs, buf.as_ptr() as usize),
38440 )
38441 }
38442 fn attr_from_type(r#type: u16) -> Option<&'static str> {
38443 ObjAttrs::attr_from_type(r#type)
38444 }
38445}
38446#[derive(Clone, Copy, Default)]
38447pub struct IterableOpDelobjDoRequest<'a> {
38448 buf: &'a [u8],
38449 pos: usize,
38450 orig_loc: usize,
38451}
38452impl<'a> IterableOpDelobjDoRequest<'a> {
38453 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
38454 Self {
38455 buf,
38456 pos: 0,
38457 orig_loc,
38458 }
38459 }
38460 pub fn get_buf(&self) -> &'a [u8] {
38461 self.buf
38462 }
38463}
38464impl<'a> Iterator for IterableOpDelobjDoRequest<'a> {
38465 type Item = Result<OpDelobjDoRequest<'a>, ErrorContext>;
38466 fn next(&mut self) -> Option<Self::Item> {
38467 if self.buf.len() == self.pos {
38468 return None;
38469 }
38470 let pos = self.pos;
38471 let mut r#type = None;
38472 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
38473 r#type = Some(header.r#type);
38474 let res = match header.r#type {
38475 1u16 => OpDelobjDoRequest::Table({
38476 let res = CStr::from_bytes_with_nul(next).ok();
38477 let Some(val) = res else { break };
38478 val
38479 }),
38480 2u16 => OpDelobjDoRequest::Name({
38481 let res = CStr::from_bytes_with_nul(next).ok();
38482 let Some(val) = res else { break };
38483 val
38484 }),
38485 3u16 => OpDelobjDoRequest::Type({
38486 let res = parse_be_u32(next);
38487 let Some(val) = res else { break };
38488 val
38489 }),
38490 6u16 => OpDelobjDoRequest::Handle({
38491 let res = parse_be_u64(next);
38492 let Some(val) = res else { break };
38493 val
38494 }),
38495 n => {
38496 if cfg!(any(test, feature = "deny-unknown-attrs")) {
38497 break;
38498 } else {
38499 continue;
38500 }
38501 }
38502 };
38503 return Some(Ok(res));
38504 }
38505 Some(Err(ErrorContext::new(
38506 "OpDelobjDoRequest",
38507 r#type.and_then(|t| OpDelobjDoRequest::attr_from_type(t)),
38508 self.orig_loc,
38509 self.buf.as_ptr().wrapping_add(pos) as usize,
38510 )))
38511 }
38512}
38513impl<'a> std::fmt::Debug for IterableOpDelobjDoRequest<'_> {
38514 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38515 let mut fmt = f.debug_struct("OpDelobjDoRequest");
38516 for attr in self.clone() {
38517 let attr = match attr {
38518 Ok(a) => a,
38519 Err(err) => {
38520 fmt.finish()?;
38521 f.write_str("Err(")?;
38522 err.fmt(f)?;
38523 return f.write_str(")");
38524 }
38525 };
38526 match attr {
38527 OpDelobjDoRequest::Table(val) => fmt.field("Table", &val),
38528 OpDelobjDoRequest::Name(val) => fmt.field("Name", &val),
38529 OpDelobjDoRequest::Type(val) => {
38530 fmt.field("Type", &FormatEnum(val.into(), ObjectType::from_value))
38531 }
38532 OpDelobjDoRequest::Handle(val) => fmt.field("Handle", &val),
38533 };
38534 }
38535 fmt.finish()
38536 }
38537}
38538impl IterableOpDelobjDoRequest<'_> {
38539 pub fn lookup_attr(
38540 &self,
38541 offset: usize,
38542 missing_type: Option<u16>,
38543 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38544 let mut stack = Vec::new();
38545 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
38546 if cur == offset + PushNfgenmsg::len() {
38547 stack.push(("OpDelobjDoRequest", offset));
38548 return (
38549 stack,
38550 missing_type.and_then(|t| OpDelobjDoRequest::attr_from_type(t)),
38551 );
38552 }
38553 if cur > offset || cur + self.buf.len() < offset {
38554 return (stack, None);
38555 }
38556 let mut attrs = self.clone();
38557 let mut last_off = cur + attrs.pos;
38558 while let Some(attr) = attrs.next() {
38559 let Ok(attr) = attr else { break };
38560 match attr {
38561 OpDelobjDoRequest::Table(val) => {
38562 if last_off == offset {
38563 stack.push(("Table", last_off));
38564 break;
38565 }
38566 }
38567 OpDelobjDoRequest::Name(val) => {
38568 if last_off == offset {
38569 stack.push(("Name", last_off));
38570 break;
38571 }
38572 }
38573 OpDelobjDoRequest::Type(val) => {
38574 if last_off == offset {
38575 stack.push(("Type", last_off));
38576 break;
38577 }
38578 }
38579 OpDelobjDoRequest::Handle(val) => {
38580 if last_off == offset {
38581 stack.push(("Handle", last_off));
38582 break;
38583 }
38584 }
38585 _ => {}
38586 };
38587 last_off = cur + attrs.pos;
38588 }
38589 if !stack.is_empty() {
38590 stack.push(("OpDelobjDoRequest", cur));
38591 }
38592 (stack, None)
38593 }
38594}
38595#[doc = "Delete an existing stateful object."]
38596pub struct PushOpDelobjDoReply<Prev: Rec> {
38597 pub(crate) prev: Option<Prev>,
38598 pub(crate) header_offset: Option<usize>,
38599}
38600impl<Prev: Rec> Rec for PushOpDelobjDoReply<Prev> {
38601 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
38602 self.prev.as_mut().unwrap().as_rec_mut()
38603 }
38604}
38605impl<Prev: Rec> PushOpDelobjDoReply<Prev> {
38606 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
38607 Self::write_header(&mut prev, header);
38608 Self::new_without_header(prev)
38609 }
38610 fn new_without_header(prev: Prev) -> Self {
38611 Self {
38612 prev: Some(prev),
38613 header_offset: None,
38614 }
38615 }
38616 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
38617 prev.as_rec_mut().extend(header.as_slice());
38618 }
38619 pub fn end_nested(mut self) -> Prev {
38620 let mut prev = self.prev.take().unwrap();
38621 if let Some(header_offset) = &self.header_offset {
38622 finalize_nested_header(prev.as_rec_mut(), *header_offset);
38623 }
38624 prev
38625 }
38626}
38627impl<Prev: Rec> Drop for PushOpDelobjDoReply<Prev> {
38628 fn drop(&mut self) {
38629 if let Some(prev) = &mut self.prev {
38630 if let Some(header_offset) = &self.header_offset {
38631 finalize_nested_header(prev.as_rec_mut(), *header_offset);
38632 }
38633 }
38634 }
38635}
38636#[doc = "Delete an existing stateful object."]
38637#[derive(Clone)]
38638pub enum OpDelobjDoReply {}
38639impl<'a> IterableOpDelobjDoReply<'a> {}
38640impl OpDelobjDoReply {
38641 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDelobjDoReply<'_>) {
38642 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
38643 (
38644 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
38645 IterableOpDelobjDoReply::with_loc(attrs, buf.as_ptr() as usize),
38646 )
38647 }
38648 fn attr_from_type(r#type: u16) -> Option<&'static str> {
38649 ObjAttrs::attr_from_type(r#type)
38650 }
38651}
38652#[derive(Clone, Copy, Default)]
38653pub struct IterableOpDelobjDoReply<'a> {
38654 buf: &'a [u8],
38655 pos: usize,
38656 orig_loc: usize,
38657}
38658impl<'a> IterableOpDelobjDoReply<'a> {
38659 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
38660 Self {
38661 buf,
38662 pos: 0,
38663 orig_loc,
38664 }
38665 }
38666 pub fn get_buf(&self) -> &'a [u8] {
38667 self.buf
38668 }
38669}
38670impl<'a> Iterator for IterableOpDelobjDoReply<'a> {
38671 type Item = Result<OpDelobjDoReply, ErrorContext>;
38672 fn next(&mut self) -> Option<Self::Item> {
38673 if self.buf.len() == self.pos {
38674 return None;
38675 }
38676 let pos = self.pos;
38677 let mut r#type = None;
38678 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
38679 r#type = Some(header.r#type);
38680 let res = match header.r#type {
38681 n => {
38682 if cfg!(any(test, feature = "deny-unknown-attrs")) {
38683 break;
38684 } else {
38685 continue;
38686 }
38687 }
38688 };
38689 return Some(Ok(res));
38690 }
38691 Some(Err(ErrorContext::new(
38692 "OpDelobjDoReply",
38693 r#type.and_then(|t| OpDelobjDoReply::attr_from_type(t)),
38694 self.orig_loc,
38695 self.buf.as_ptr().wrapping_add(pos) as usize,
38696 )))
38697 }
38698}
38699impl std::fmt::Debug for IterableOpDelobjDoReply<'_> {
38700 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38701 let mut fmt = f.debug_struct("OpDelobjDoReply");
38702 for attr in self.clone() {
38703 let attr = match attr {
38704 Ok(a) => a,
38705 Err(err) => {
38706 fmt.finish()?;
38707 f.write_str("Err(")?;
38708 err.fmt(f)?;
38709 return f.write_str(")");
38710 }
38711 };
38712 match attr {};
38713 }
38714 fmt.finish()
38715 }
38716}
38717impl IterableOpDelobjDoReply<'_> {
38718 pub fn lookup_attr(
38719 &self,
38720 offset: usize,
38721 missing_type: Option<u16>,
38722 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38723 let mut stack = Vec::new();
38724 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
38725 if cur == offset + PushNfgenmsg::len() {
38726 stack.push(("OpDelobjDoReply", offset));
38727 return (
38728 stack,
38729 missing_type.and_then(|t| OpDelobjDoReply::attr_from_type(t)),
38730 );
38731 }
38732 (stack, None)
38733 }
38734}
38735#[derive(Debug)]
38736pub struct RequestOpDelobjDoRequest<'r> {
38737 request: Request<'r>,
38738}
38739impl<'r> RequestOpDelobjDoRequest<'r> {
38740 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
38741 PushOpDelobjDoRequest::write_header(&mut request.buf_mut(), header);
38742 Self { request: request }
38743 }
38744 pub fn encode(&mut self) -> PushOpDelobjDoRequest<&mut Vec<u8>> {
38745 PushOpDelobjDoRequest::new_without_header(self.request.buf_mut())
38746 }
38747 pub fn into_encoder(self) -> PushOpDelobjDoRequest<RequestBuf<'r>> {
38748 PushOpDelobjDoRequest::new_without_header(self.request.buf)
38749 }
38750}
38751impl NetlinkRequest for RequestOpDelobjDoRequest<'_> {
38752 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDelobjDoReply<'buf>);
38753 fn protocol(&self) -> Protocol {
38754 Protocol::Raw {
38755 protonum: 12u16,
38756 request_type: 2580u16,
38757 }
38758 }
38759 fn flags(&self) -> u16 {
38760 self.request.flags
38761 }
38762 fn payload(&self) -> &[u8] {
38763 self.request.buf()
38764 }
38765 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
38766 OpDelobjDoReply::new(buf)
38767 }
38768 fn lookup(
38769 buf: &[u8],
38770 offset: usize,
38771 missing_type: Option<u16>,
38772 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
38773 OpDelobjDoRequest::new(buf)
38774 .1
38775 .lookup_attr(offset, missing_type)
38776 }
38777}
38778#[doc = "Delete an existing stateful object with destroy semantics."]
38779pub struct PushOpDestroyobjDoRequest<Prev: Rec> {
38780 pub(crate) prev: Option<Prev>,
38781 pub(crate) header_offset: Option<usize>,
38782}
38783impl<Prev: Rec> Rec for PushOpDestroyobjDoRequest<Prev> {
38784 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
38785 self.prev.as_mut().unwrap().as_rec_mut()
38786 }
38787}
38788impl<Prev: Rec> PushOpDestroyobjDoRequest<Prev> {
38789 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
38790 Self::write_header(&mut prev, header);
38791 Self::new_without_header(prev)
38792 }
38793 fn new_without_header(prev: Prev) -> Self {
38794 Self {
38795 prev: Some(prev),
38796 header_offset: None,
38797 }
38798 }
38799 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
38800 prev.as_rec_mut().extend(header.as_slice());
38801 }
38802 pub fn end_nested(mut self) -> Prev {
38803 let mut prev = self.prev.take().unwrap();
38804 if let Some(header_offset) = &self.header_offset {
38805 finalize_nested_header(prev.as_rec_mut(), *header_offset);
38806 }
38807 prev
38808 }
38809 #[doc = "name of the table containing the expression"]
38810 pub fn push_table(mut self, value: &CStr) -> Self {
38811 push_header(
38812 self.as_rec_mut(),
38813 1u16,
38814 value.to_bytes_with_nul().len() as u16,
38815 );
38816 self.as_rec_mut().extend(value.to_bytes_with_nul());
38817 self
38818 }
38819 #[doc = "name of the table containing the expression"]
38820 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
38821 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
38822 self.as_rec_mut().extend(value);
38823 self.as_rec_mut().push(0);
38824 self
38825 }
38826 #[doc = "name of this expression type"]
38827 pub fn push_name(mut self, value: &CStr) -> Self {
38828 push_header(
38829 self.as_rec_mut(),
38830 2u16,
38831 value.to_bytes_with_nul().len() as u16,
38832 );
38833 self.as_rec_mut().extend(value.to_bytes_with_nul());
38834 self
38835 }
38836 #[doc = "name of this expression type"]
38837 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
38838 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
38839 self.as_rec_mut().extend(value);
38840 self.as_rec_mut().push(0);
38841 self
38842 }
38843 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
38844 pub fn push_type(mut self, value: u32) -> Self {
38845 push_header(self.as_rec_mut(), 3u16, 4 as u16);
38846 self.as_rec_mut().extend(value.to_be_bytes());
38847 self
38848 }
38849 #[doc = "object handle"]
38850 pub fn push_handle(mut self, value: u64) -> Self {
38851 push_header(self.as_rec_mut(), 6u16, 8 as u16);
38852 self.as_rec_mut().extend(value.to_be_bytes());
38853 self
38854 }
38855}
38856impl<Prev: Rec> Drop for PushOpDestroyobjDoRequest<Prev> {
38857 fn drop(&mut self) {
38858 if let Some(prev) = &mut self.prev {
38859 if let Some(header_offset) = &self.header_offset {
38860 finalize_nested_header(prev.as_rec_mut(), *header_offset);
38861 }
38862 }
38863 }
38864}
38865#[doc = "Delete an existing stateful object with destroy semantics."]
38866#[derive(Clone)]
38867pub enum OpDestroyobjDoRequest<'a> {
38868 #[doc = "name of the table containing the expression"]
38869 Table(&'a CStr),
38870 #[doc = "name of this expression type"]
38871 Name(&'a CStr),
38872 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
38873 Type(u32),
38874 #[doc = "object handle"]
38875 Handle(u64),
38876}
38877impl<'a> IterableOpDestroyobjDoRequest<'a> {
38878 #[doc = "name of the table containing the expression"]
38879 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
38880 let mut iter = self.clone();
38881 iter.pos = 0;
38882 for attr in iter {
38883 if let OpDestroyobjDoRequest::Table(val) = attr? {
38884 return Ok(val);
38885 }
38886 }
38887 Err(ErrorContext::new_missing(
38888 "OpDestroyobjDoRequest",
38889 "Table",
38890 self.orig_loc,
38891 self.buf.as_ptr() as usize,
38892 ))
38893 }
38894 #[doc = "name of this expression type"]
38895 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
38896 let mut iter = self.clone();
38897 iter.pos = 0;
38898 for attr in iter {
38899 if let OpDestroyobjDoRequest::Name(val) = attr? {
38900 return Ok(val);
38901 }
38902 }
38903 Err(ErrorContext::new_missing(
38904 "OpDestroyobjDoRequest",
38905 "Name",
38906 self.orig_loc,
38907 self.buf.as_ptr() as usize,
38908 ))
38909 }
38910 #[doc = "stateful object type\nAssociated type: \"ObjectType\" (enum)"]
38911 pub fn get_type(&self) -> Result<u32, ErrorContext> {
38912 let mut iter = self.clone();
38913 iter.pos = 0;
38914 for attr in iter {
38915 if let OpDestroyobjDoRequest::Type(val) = attr? {
38916 return Ok(val);
38917 }
38918 }
38919 Err(ErrorContext::new_missing(
38920 "OpDestroyobjDoRequest",
38921 "Type",
38922 self.orig_loc,
38923 self.buf.as_ptr() as usize,
38924 ))
38925 }
38926 #[doc = "object handle"]
38927 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
38928 let mut iter = self.clone();
38929 iter.pos = 0;
38930 for attr in iter {
38931 if let OpDestroyobjDoRequest::Handle(val) = attr? {
38932 return Ok(val);
38933 }
38934 }
38935 Err(ErrorContext::new_missing(
38936 "OpDestroyobjDoRequest",
38937 "Handle",
38938 self.orig_loc,
38939 self.buf.as_ptr() as usize,
38940 ))
38941 }
38942}
38943impl<'a> OpDestroyobjDoRequest<'a> {
38944 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDestroyobjDoRequest<'a>) {
38945 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
38946 (
38947 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
38948 IterableOpDestroyobjDoRequest::with_loc(attrs, buf.as_ptr() as usize),
38949 )
38950 }
38951 fn attr_from_type(r#type: u16) -> Option<&'static str> {
38952 ObjAttrs::attr_from_type(r#type)
38953 }
38954}
38955#[derive(Clone, Copy, Default)]
38956pub struct IterableOpDestroyobjDoRequest<'a> {
38957 buf: &'a [u8],
38958 pos: usize,
38959 orig_loc: usize,
38960}
38961impl<'a> IterableOpDestroyobjDoRequest<'a> {
38962 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
38963 Self {
38964 buf,
38965 pos: 0,
38966 orig_loc,
38967 }
38968 }
38969 pub fn get_buf(&self) -> &'a [u8] {
38970 self.buf
38971 }
38972}
38973impl<'a> Iterator for IterableOpDestroyobjDoRequest<'a> {
38974 type Item = Result<OpDestroyobjDoRequest<'a>, ErrorContext>;
38975 fn next(&mut self) -> Option<Self::Item> {
38976 if self.buf.len() == self.pos {
38977 return None;
38978 }
38979 let pos = self.pos;
38980 let mut r#type = None;
38981 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
38982 r#type = Some(header.r#type);
38983 let res = match header.r#type {
38984 1u16 => OpDestroyobjDoRequest::Table({
38985 let res = CStr::from_bytes_with_nul(next).ok();
38986 let Some(val) = res else { break };
38987 val
38988 }),
38989 2u16 => OpDestroyobjDoRequest::Name({
38990 let res = CStr::from_bytes_with_nul(next).ok();
38991 let Some(val) = res else { break };
38992 val
38993 }),
38994 3u16 => OpDestroyobjDoRequest::Type({
38995 let res = parse_be_u32(next);
38996 let Some(val) = res else { break };
38997 val
38998 }),
38999 6u16 => OpDestroyobjDoRequest::Handle({
39000 let res = parse_be_u64(next);
39001 let Some(val) = res else { break };
39002 val
39003 }),
39004 n => {
39005 if cfg!(any(test, feature = "deny-unknown-attrs")) {
39006 break;
39007 } else {
39008 continue;
39009 }
39010 }
39011 };
39012 return Some(Ok(res));
39013 }
39014 Some(Err(ErrorContext::new(
39015 "OpDestroyobjDoRequest",
39016 r#type.and_then(|t| OpDestroyobjDoRequest::attr_from_type(t)),
39017 self.orig_loc,
39018 self.buf.as_ptr().wrapping_add(pos) as usize,
39019 )))
39020 }
39021}
39022impl<'a> std::fmt::Debug for IterableOpDestroyobjDoRequest<'_> {
39023 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39024 let mut fmt = f.debug_struct("OpDestroyobjDoRequest");
39025 for attr in self.clone() {
39026 let attr = match attr {
39027 Ok(a) => a,
39028 Err(err) => {
39029 fmt.finish()?;
39030 f.write_str("Err(")?;
39031 err.fmt(f)?;
39032 return f.write_str(")");
39033 }
39034 };
39035 match attr {
39036 OpDestroyobjDoRequest::Table(val) => fmt.field("Table", &val),
39037 OpDestroyobjDoRequest::Name(val) => fmt.field("Name", &val),
39038 OpDestroyobjDoRequest::Type(val) => {
39039 fmt.field("Type", &FormatEnum(val.into(), ObjectType::from_value))
39040 }
39041 OpDestroyobjDoRequest::Handle(val) => fmt.field("Handle", &val),
39042 };
39043 }
39044 fmt.finish()
39045 }
39046}
39047impl IterableOpDestroyobjDoRequest<'_> {
39048 pub fn lookup_attr(
39049 &self,
39050 offset: usize,
39051 missing_type: Option<u16>,
39052 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
39053 let mut stack = Vec::new();
39054 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
39055 if cur == offset + PushNfgenmsg::len() {
39056 stack.push(("OpDestroyobjDoRequest", offset));
39057 return (
39058 stack,
39059 missing_type.and_then(|t| OpDestroyobjDoRequest::attr_from_type(t)),
39060 );
39061 }
39062 if cur > offset || cur + self.buf.len() < offset {
39063 return (stack, None);
39064 }
39065 let mut attrs = self.clone();
39066 let mut last_off = cur + attrs.pos;
39067 while let Some(attr) = attrs.next() {
39068 let Ok(attr) = attr else { break };
39069 match attr {
39070 OpDestroyobjDoRequest::Table(val) => {
39071 if last_off == offset {
39072 stack.push(("Table", last_off));
39073 break;
39074 }
39075 }
39076 OpDestroyobjDoRequest::Name(val) => {
39077 if last_off == offset {
39078 stack.push(("Name", last_off));
39079 break;
39080 }
39081 }
39082 OpDestroyobjDoRequest::Type(val) => {
39083 if last_off == offset {
39084 stack.push(("Type", last_off));
39085 break;
39086 }
39087 }
39088 OpDestroyobjDoRequest::Handle(val) => {
39089 if last_off == offset {
39090 stack.push(("Handle", last_off));
39091 break;
39092 }
39093 }
39094 _ => {}
39095 };
39096 last_off = cur + attrs.pos;
39097 }
39098 if !stack.is_empty() {
39099 stack.push(("OpDestroyobjDoRequest", cur));
39100 }
39101 (stack, None)
39102 }
39103}
39104#[doc = "Delete an existing stateful object with destroy semantics."]
39105pub struct PushOpDestroyobjDoReply<Prev: Rec> {
39106 pub(crate) prev: Option<Prev>,
39107 pub(crate) header_offset: Option<usize>,
39108}
39109impl<Prev: Rec> Rec for PushOpDestroyobjDoReply<Prev> {
39110 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
39111 self.prev.as_mut().unwrap().as_rec_mut()
39112 }
39113}
39114impl<Prev: Rec> PushOpDestroyobjDoReply<Prev> {
39115 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
39116 Self::write_header(&mut prev, header);
39117 Self::new_without_header(prev)
39118 }
39119 fn new_without_header(prev: Prev) -> Self {
39120 Self {
39121 prev: Some(prev),
39122 header_offset: None,
39123 }
39124 }
39125 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
39126 prev.as_rec_mut().extend(header.as_slice());
39127 }
39128 pub fn end_nested(mut self) -> Prev {
39129 let mut prev = self.prev.take().unwrap();
39130 if let Some(header_offset) = &self.header_offset {
39131 finalize_nested_header(prev.as_rec_mut(), *header_offset);
39132 }
39133 prev
39134 }
39135}
39136impl<Prev: Rec> Drop for PushOpDestroyobjDoReply<Prev> {
39137 fn drop(&mut self) {
39138 if let Some(prev) = &mut self.prev {
39139 if let Some(header_offset) = &self.header_offset {
39140 finalize_nested_header(prev.as_rec_mut(), *header_offset);
39141 }
39142 }
39143 }
39144}
39145#[doc = "Delete an existing stateful object with destroy semantics."]
39146#[derive(Clone)]
39147pub enum OpDestroyobjDoReply {}
39148impl<'a> IterableOpDestroyobjDoReply<'a> {}
39149impl OpDestroyobjDoReply {
39150 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDestroyobjDoReply<'_>) {
39151 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
39152 (
39153 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
39154 IterableOpDestroyobjDoReply::with_loc(attrs, buf.as_ptr() as usize),
39155 )
39156 }
39157 fn attr_from_type(r#type: u16) -> Option<&'static str> {
39158 ObjAttrs::attr_from_type(r#type)
39159 }
39160}
39161#[derive(Clone, Copy, Default)]
39162pub struct IterableOpDestroyobjDoReply<'a> {
39163 buf: &'a [u8],
39164 pos: usize,
39165 orig_loc: usize,
39166}
39167impl<'a> IterableOpDestroyobjDoReply<'a> {
39168 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
39169 Self {
39170 buf,
39171 pos: 0,
39172 orig_loc,
39173 }
39174 }
39175 pub fn get_buf(&self) -> &'a [u8] {
39176 self.buf
39177 }
39178}
39179impl<'a> Iterator for IterableOpDestroyobjDoReply<'a> {
39180 type Item = Result<OpDestroyobjDoReply, ErrorContext>;
39181 fn next(&mut self) -> Option<Self::Item> {
39182 if self.buf.len() == self.pos {
39183 return None;
39184 }
39185 let pos = self.pos;
39186 let mut r#type = None;
39187 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
39188 r#type = Some(header.r#type);
39189 let res = match header.r#type {
39190 n => {
39191 if cfg!(any(test, feature = "deny-unknown-attrs")) {
39192 break;
39193 } else {
39194 continue;
39195 }
39196 }
39197 };
39198 return Some(Ok(res));
39199 }
39200 Some(Err(ErrorContext::new(
39201 "OpDestroyobjDoReply",
39202 r#type.and_then(|t| OpDestroyobjDoReply::attr_from_type(t)),
39203 self.orig_loc,
39204 self.buf.as_ptr().wrapping_add(pos) as usize,
39205 )))
39206 }
39207}
39208impl std::fmt::Debug for IterableOpDestroyobjDoReply<'_> {
39209 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39210 let mut fmt = f.debug_struct("OpDestroyobjDoReply");
39211 for attr in self.clone() {
39212 let attr = match attr {
39213 Ok(a) => a,
39214 Err(err) => {
39215 fmt.finish()?;
39216 f.write_str("Err(")?;
39217 err.fmt(f)?;
39218 return f.write_str(")");
39219 }
39220 };
39221 match attr {};
39222 }
39223 fmt.finish()
39224 }
39225}
39226impl IterableOpDestroyobjDoReply<'_> {
39227 pub fn lookup_attr(
39228 &self,
39229 offset: usize,
39230 missing_type: Option<u16>,
39231 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
39232 let mut stack = Vec::new();
39233 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
39234 if cur == offset + PushNfgenmsg::len() {
39235 stack.push(("OpDestroyobjDoReply", offset));
39236 return (
39237 stack,
39238 missing_type.and_then(|t| OpDestroyobjDoReply::attr_from_type(t)),
39239 );
39240 }
39241 (stack, None)
39242 }
39243}
39244#[derive(Debug)]
39245pub struct RequestOpDestroyobjDoRequest<'r> {
39246 request: Request<'r>,
39247}
39248impl<'r> RequestOpDestroyobjDoRequest<'r> {
39249 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
39250 PushOpDestroyobjDoRequest::write_header(&mut request.buf_mut(), header);
39251 Self { request: request }
39252 }
39253 pub fn encode(&mut self) -> PushOpDestroyobjDoRequest<&mut Vec<u8>> {
39254 PushOpDestroyobjDoRequest::new_without_header(self.request.buf_mut())
39255 }
39256 pub fn into_encoder(self) -> PushOpDestroyobjDoRequest<RequestBuf<'r>> {
39257 PushOpDestroyobjDoRequest::new_without_header(self.request.buf)
39258 }
39259}
39260impl NetlinkRequest for RequestOpDestroyobjDoRequest<'_> {
39261 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDestroyobjDoReply<'buf>);
39262 fn protocol(&self) -> Protocol {
39263 Protocol::Raw {
39264 protonum: 12u16,
39265 request_type: 2591u16,
39266 }
39267 }
39268 fn flags(&self) -> u16 {
39269 self.request.flags
39270 }
39271 fn payload(&self) -> &[u8] {
39272 self.request.buf()
39273 }
39274 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
39275 OpDestroyobjDoReply::new(buf)
39276 }
39277 fn lookup(
39278 buf: &[u8],
39279 offset: usize,
39280 missing_type: Option<u16>,
39281 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
39282 OpDestroyobjDoRequest::new(buf)
39283 .1
39284 .lookup_attr(offset, missing_type)
39285 }
39286}
39287#[doc = "Create a new flow table."]
39288pub struct PushOpNewflowtableDoRequest<Prev: Rec> {
39289 pub(crate) prev: Option<Prev>,
39290 pub(crate) header_offset: Option<usize>,
39291}
39292impl<Prev: Rec> Rec for PushOpNewflowtableDoRequest<Prev> {
39293 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
39294 self.prev.as_mut().unwrap().as_rec_mut()
39295 }
39296}
39297impl<Prev: Rec> PushOpNewflowtableDoRequest<Prev> {
39298 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
39299 Self::write_header(&mut prev, header);
39300 Self::new_without_header(prev)
39301 }
39302 fn new_without_header(prev: Prev) -> Self {
39303 Self {
39304 prev: Some(prev),
39305 header_offset: None,
39306 }
39307 }
39308 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
39309 prev.as_rec_mut().extend(header.as_slice());
39310 }
39311 pub fn end_nested(mut self) -> Prev {
39312 let mut prev = self.prev.take().unwrap();
39313 if let Some(header_offset) = &self.header_offset {
39314 finalize_nested_header(prev.as_rec_mut(), *header_offset);
39315 }
39316 prev
39317 }
39318 pub fn push_table(mut self, value: &CStr) -> Self {
39319 push_header(
39320 self.as_rec_mut(),
39321 1u16,
39322 value.to_bytes_with_nul().len() as u16,
39323 );
39324 self.as_rec_mut().extend(value.to_bytes_with_nul());
39325 self
39326 }
39327 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
39328 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
39329 self.as_rec_mut().extend(value);
39330 self.as_rec_mut().push(0);
39331 self
39332 }
39333 pub fn push_name(mut self, value: &CStr) -> Self {
39334 push_header(
39335 self.as_rec_mut(),
39336 2u16,
39337 value.to_bytes_with_nul().len() as u16,
39338 );
39339 self.as_rec_mut().extend(value.to_bytes_with_nul());
39340 self
39341 }
39342 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
39343 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
39344 self.as_rec_mut().extend(value);
39345 self.as_rec_mut().push(0);
39346 self
39347 }
39348 pub fn nested_hook(mut self) -> PushFlowtableHookAttrs<Self> {
39349 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
39350 PushFlowtableHookAttrs {
39351 prev: Some(self),
39352 header_offset: Some(header_offset),
39353 }
39354 }
39355 pub fn push_flags(mut self, value: u32) -> Self {
39356 push_header(self.as_rec_mut(), 7u16, 4 as u16);
39357 self.as_rec_mut().extend(value.to_be_bytes());
39358 self
39359 }
39360}
39361impl<Prev: Rec> Drop for PushOpNewflowtableDoRequest<Prev> {
39362 fn drop(&mut self) {
39363 if let Some(prev) = &mut self.prev {
39364 if let Some(header_offset) = &self.header_offset {
39365 finalize_nested_header(prev.as_rec_mut(), *header_offset);
39366 }
39367 }
39368 }
39369}
39370#[doc = "Create a new flow table."]
39371#[derive(Clone)]
39372pub enum OpNewflowtableDoRequest<'a> {
39373 Table(&'a CStr),
39374 Name(&'a CStr),
39375 Hook(IterableFlowtableHookAttrs<'a>),
39376 Flags(u32),
39377}
39378impl<'a> IterableOpNewflowtableDoRequest<'a> {
39379 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
39380 let mut iter = self.clone();
39381 iter.pos = 0;
39382 for attr in iter {
39383 if let OpNewflowtableDoRequest::Table(val) = attr? {
39384 return Ok(val);
39385 }
39386 }
39387 Err(ErrorContext::new_missing(
39388 "OpNewflowtableDoRequest",
39389 "Table",
39390 self.orig_loc,
39391 self.buf.as_ptr() as usize,
39392 ))
39393 }
39394 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
39395 let mut iter = self.clone();
39396 iter.pos = 0;
39397 for attr in iter {
39398 if let OpNewflowtableDoRequest::Name(val) = attr? {
39399 return Ok(val);
39400 }
39401 }
39402 Err(ErrorContext::new_missing(
39403 "OpNewflowtableDoRequest",
39404 "Name",
39405 self.orig_loc,
39406 self.buf.as_ptr() as usize,
39407 ))
39408 }
39409 pub fn get_hook(&self) -> Result<IterableFlowtableHookAttrs<'a>, ErrorContext> {
39410 let mut iter = self.clone();
39411 iter.pos = 0;
39412 for attr in iter {
39413 if let OpNewflowtableDoRequest::Hook(val) = attr? {
39414 return Ok(val);
39415 }
39416 }
39417 Err(ErrorContext::new_missing(
39418 "OpNewflowtableDoRequest",
39419 "Hook",
39420 self.orig_loc,
39421 self.buf.as_ptr() as usize,
39422 ))
39423 }
39424 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
39425 let mut iter = self.clone();
39426 iter.pos = 0;
39427 for attr in iter {
39428 if let OpNewflowtableDoRequest::Flags(val) = attr? {
39429 return Ok(val);
39430 }
39431 }
39432 Err(ErrorContext::new_missing(
39433 "OpNewflowtableDoRequest",
39434 "Flags",
39435 self.orig_loc,
39436 self.buf.as_ptr() as usize,
39437 ))
39438 }
39439}
39440impl<'a> OpNewflowtableDoRequest<'a> {
39441 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpNewflowtableDoRequest<'a>) {
39442 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
39443 (
39444 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
39445 IterableOpNewflowtableDoRequest::with_loc(attrs, buf.as_ptr() as usize),
39446 )
39447 }
39448 fn attr_from_type(r#type: u16) -> Option<&'static str> {
39449 FlowtableAttrs::attr_from_type(r#type)
39450 }
39451}
39452#[derive(Clone, Copy, Default)]
39453pub struct IterableOpNewflowtableDoRequest<'a> {
39454 buf: &'a [u8],
39455 pos: usize,
39456 orig_loc: usize,
39457}
39458impl<'a> IterableOpNewflowtableDoRequest<'a> {
39459 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
39460 Self {
39461 buf,
39462 pos: 0,
39463 orig_loc,
39464 }
39465 }
39466 pub fn get_buf(&self) -> &'a [u8] {
39467 self.buf
39468 }
39469}
39470impl<'a> Iterator for IterableOpNewflowtableDoRequest<'a> {
39471 type Item = Result<OpNewflowtableDoRequest<'a>, ErrorContext>;
39472 fn next(&mut self) -> Option<Self::Item> {
39473 if self.buf.len() == self.pos {
39474 return None;
39475 }
39476 let pos = self.pos;
39477 let mut r#type = None;
39478 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
39479 r#type = Some(header.r#type);
39480 let res = match header.r#type {
39481 1u16 => OpNewflowtableDoRequest::Table({
39482 let res = CStr::from_bytes_with_nul(next).ok();
39483 let Some(val) = res else { break };
39484 val
39485 }),
39486 2u16 => OpNewflowtableDoRequest::Name({
39487 let res = CStr::from_bytes_with_nul(next).ok();
39488 let Some(val) = res else { break };
39489 val
39490 }),
39491 3u16 => OpNewflowtableDoRequest::Hook({
39492 let res = Some(IterableFlowtableHookAttrs::with_loc(next, self.orig_loc));
39493 let Some(val) = res else { break };
39494 val
39495 }),
39496 7u16 => OpNewflowtableDoRequest::Flags({
39497 let res = parse_be_u32(next);
39498 let Some(val) = res else { break };
39499 val
39500 }),
39501 n => {
39502 if cfg!(any(test, feature = "deny-unknown-attrs")) {
39503 break;
39504 } else {
39505 continue;
39506 }
39507 }
39508 };
39509 return Some(Ok(res));
39510 }
39511 Some(Err(ErrorContext::new(
39512 "OpNewflowtableDoRequest",
39513 r#type.and_then(|t| OpNewflowtableDoRequest::attr_from_type(t)),
39514 self.orig_loc,
39515 self.buf.as_ptr().wrapping_add(pos) as usize,
39516 )))
39517 }
39518}
39519impl<'a> std::fmt::Debug for IterableOpNewflowtableDoRequest<'_> {
39520 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39521 let mut fmt = f.debug_struct("OpNewflowtableDoRequest");
39522 for attr in self.clone() {
39523 let attr = match attr {
39524 Ok(a) => a,
39525 Err(err) => {
39526 fmt.finish()?;
39527 f.write_str("Err(")?;
39528 err.fmt(f)?;
39529 return f.write_str(")");
39530 }
39531 };
39532 match attr {
39533 OpNewflowtableDoRequest::Table(val) => fmt.field("Table", &val),
39534 OpNewflowtableDoRequest::Name(val) => fmt.field("Name", &val),
39535 OpNewflowtableDoRequest::Hook(val) => fmt.field("Hook", &val),
39536 OpNewflowtableDoRequest::Flags(val) => fmt.field("Flags", &val),
39537 };
39538 }
39539 fmt.finish()
39540 }
39541}
39542impl IterableOpNewflowtableDoRequest<'_> {
39543 pub fn lookup_attr(
39544 &self,
39545 offset: usize,
39546 missing_type: Option<u16>,
39547 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
39548 let mut stack = Vec::new();
39549 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
39550 if cur == offset + PushNfgenmsg::len() {
39551 stack.push(("OpNewflowtableDoRequest", offset));
39552 return (
39553 stack,
39554 missing_type.and_then(|t| OpNewflowtableDoRequest::attr_from_type(t)),
39555 );
39556 }
39557 if cur > offset || cur + self.buf.len() < offset {
39558 return (stack, None);
39559 }
39560 let mut attrs = self.clone();
39561 let mut last_off = cur + attrs.pos;
39562 let mut missing = None;
39563 while let Some(attr) = attrs.next() {
39564 let Ok(attr) = attr else { break };
39565 match attr {
39566 OpNewflowtableDoRequest::Table(val) => {
39567 if last_off == offset {
39568 stack.push(("Table", last_off));
39569 break;
39570 }
39571 }
39572 OpNewflowtableDoRequest::Name(val) => {
39573 if last_off == offset {
39574 stack.push(("Name", last_off));
39575 break;
39576 }
39577 }
39578 OpNewflowtableDoRequest::Hook(val) => {
39579 (stack, missing) = val.lookup_attr(offset, missing_type);
39580 if !stack.is_empty() {
39581 break;
39582 }
39583 }
39584 OpNewflowtableDoRequest::Flags(val) => {
39585 if last_off == offset {
39586 stack.push(("Flags", last_off));
39587 break;
39588 }
39589 }
39590 _ => {}
39591 };
39592 last_off = cur + attrs.pos;
39593 }
39594 if !stack.is_empty() {
39595 stack.push(("OpNewflowtableDoRequest", cur));
39596 }
39597 (stack, missing)
39598 }
39599}
39600#[doc = "Create a new flow table."]
39601pub struct PushOpNewflowtableDoReply<Prev: Rec> {
39602 pub(crate) prev: Option<Prev>,
39603 pub(crate) header_offset: Option<usize>,
39604}
39605impl<Prev: Rec> Rec for PushOpNewflowtableDoReply<Prev> {
39606 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
39607 self.prev.as_mut().unwrap().as_rec_mut()
39608 }
39609}
39610impl<Prev: Rec> PushOpNewflowtableDoReply<Prev> {
39611 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
39612 Self::write_header(&mut prev, header);
39613 Self::new_without_header(prev)
39614 }
39615 fn new_without_header(prev: Prev) -> Self {
39616 Self {
39617 prev: Some(prev),
39618 header_offset: None,
39619 }
39620 }
39621 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
39622 prev.as_rec_mut().extend(header.as_slice());
39623 }
39624 pub fn end_nested(mut self) -> Prev {
39625 let mut prev = self.prev.take().unwrap();
39626 if let Some(header_offset) = &self.header_offset {
39627 finalize_nested_header(prev.as_rec_mut(), *header_offset);
39628 }
39629 prev
39630 }
39631}
39632impl<Prev: Rec> Drop for PushOpNewflowtableDoReply<Prev> {
39633 fn drop(&mut self) {
39634 if let Some(prev) = &mut self.prev {
39635 if let Some(header_offset) = &self.header_offset {
39636 finalize_nested_header(prev.as_rec_mut(), *header_offset);
39637 }
39638 }
39639 }
39640}
39641#[doc = "Create a new flow table."]
39642#[derive(Clone)]
39643pub enum OpNewflowtableDoReply {}
39644impl<'a> IterableOpNewflowtableDoReply<'a> {}
39645impl OpNewflowtableDoReply {
39646 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpNewflowtableDoReply<'_>) {
39647 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
39648 (
39649 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
39650 IterableOpNewflowtableDoReply::with_loc(attrs, buf.as_ptr() as usize),
39651 )
39652 }
39653 fn attr_from_type(r#type: u16) -> Option<&'static str> {
39654 FlowtableAttrs::attr_from_type(r#type)
39655 }
39656}
39657#[derive(Clone, Copy, Default)]
39658pub struct IterableOpNewflowtableDoReply<'a> {
39659 buf: &'a [u8],
39660 pos: usize,
39661 orig_loc: usize,
39662}
39663impl<'a> IterableOpNewflowtableDoReply<'a> {
39664 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
39665 Self {
39666 buf,
39667 pos: 0,
39668 orig_loc,
39669 }
39670 }
39671 pub fn get_buf(&self) -> &'a [u8] {
39672 self.buf
39673 }
39674}
39675impl<'a> Iterator for IterableOpNewflowtableDoReply<'a> {
39676 type Item = Result<OpNewflowtableDoReply, ErrorContext>;
39677 fn next(&mut self) -> Option<Self::Item> {
39678 if self.buf.len() == self.pos {
39679 return None;
39680 }
39681 let pos = self.pos;
39682 let mut r#type = None;
39683 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
39684 r#type = Some(header.r#type);
39685 let res = match header.r#type {
39686 n => {
39687 if cfg!(any(test, feature = "deny-unknown-attrs")) {
39688 break;
39689 } else {
39690 continue;
39691 }
39692 }
39693 };
39694 return Some(Ok(res));
39695 }
39696 Some(Err(ErrorContext::new(
39697 "OpNewflowtableDoReply",
39698 r#type.and_then(|t| OpNewflowtableDoReply::attr_from_type(t)),
39699 self.orig_loc,
39700 self.buf.as_ptr().wrapping_add(pos) as usize,
39701 )))
39702 }
39703}
39704impl std::fmt::Debug for IterableOpNewflowtableDoReply<'_> {
39705 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39706 let mut fmt = f.debug_struct("OpNewflowtableDoReply");
39707 for attr in self.clone() {
39708 let attr = match attr {
39709 Ok(a) => a,
39710 Err(err) => {
39711 fmt.finish()?;
39712 f.write_str("Err(")?;
39713 err.fmt(f)?;
39714 return f.write_str(")");
39715 }
39716 };
39717 match attr {};
39718 }
39719 fmt.finish()
39720 }
39721}
39722impl IterableOpNewflowtableDoReply<'_> {
39723 pub fn lookup_attr(
39724 &self,
39725 offset: usize,
39726 missing_type: Option<u16>,
39727 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
39728 let mut stack = Vec::new();
39729 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
39730 if cur == offset + PushNfgenmsg::len() {
39731 stack.push(("OpNewflowtableDoReply", offset));
39732 return (
39733 stack,
39734 missing_type.and_then(|t| OpNewflowtableDoReply::attr_from_type(t)),
39735 );
39736 }
39737 (stack, None)
39738 }
39739}
39740#[derive(Debug)]
39741pub struct RequestOpNewflowtableDoRequest<'r> {
39742 request: Request<'r>,
39743}
39744impl<'r> RequestOpNewflowtableDoRequest<'r> {
39745 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
39746 PushOpNewflowtableDoRequest::write_header(&mut request.buf_mut(), header);
39747 Self { request: request }
39748 }
39749 pub fn encode(&mut self) -> PushOpNewflowtableDoRequest<&mut Vec<u8>> {
39750 PushOpNewflowtableDoRequest::new_without_header(self.request.buf_mut())
39751 }
39752 pub fn into_encoder(self) -> PushOpNewflowtableDoRequest<RequestBuf<'r>> {
39753 PushOpNewflowtableDoRequest::new_without_header(self.request.buf)
39754 }
39755}
39756impl NetlinkRequest for RequestOpNewflowtableDoRequest<'_> {
39757 type ReplyType<'buf> = (PushNfgenmsg, IterableOpNewflowtableDoReply<'buf>);
39758 fn protocol(&self) -> Protocol {
39759 Protocol::Raw {
39760 protonum: 12u16,
39761 request_type: 2582u16,
39762 }
39763 }
39764 fn flags(&self) -> u16 {
39765 self.request.flags
39766 }
39767 fn payload(&self) -> &[u8] {
39768 self.request.buf()
39769 }
39770 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
39771 OpNewflowtableDoReply::new(buf)
39772 }
39773 fn lookup(
39774 buf: &[u8],
39775 offset: usize,
39776 missing_type: Option<u16>,
39777 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
39778 OpNewflowtableDoRequest::new(buf)
39779 .1
39780 .lookup_attr(offset, missing_type)
39781 }
39782}
39783#[doc = "Get / dump flow tables."]
39784pub struct PushOpGetflowtableDumpRequest<Prev: Rec> {
39785 pub(crate) prev: Option<Prev>,
39786 pub(crate) header_offset: Option<usize>,
39787}
39788impl<Prev: Rec> Rec for PushOpGetflowtableDumpRequest<Prev> {
39789 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
39790 self.prev.as_mut().unwrap().as_rec_mut()
39791 }
39792}
39793impl<Prev: Rec> PushOpGetflowtableDumpRequest<Prev> {
39794 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
39795 Self::write_header(&mut prev, header);
39796 Self::new_without_header(prev)
39797 }
39798 fn new_without_header(prev: Prev) -> Self {
39799 Self {
39800 prev: Some(prev),
39801 header_offset: None,
39802 }
39803 }
39804 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
39805 prev.as_rec_mut().extend(header.as_slice());
39806 }
39807 pub fn end_nested(mut self) -> Prev {
39808 let mut prev = self.prev.take().unwrap();
39809 if let Some(header_offset) = &self.header_offset {
39810 finalize_nested_header(prev.as_rec_mut(), *header_offset);
39811 }
39812 prev
39813 }
39814}
39815impl<Prev: Rec> Drop for PushOpGetflowtableDumpRequest<Prev> {
39816 fn drop(&mut self) {
39817 if let Some(prev) = &mut self.prev {
39818 if let Some(header_offset) = &self.header_offset {
39819 finalize_nested_header(prev.as_rec_mut(), *header_offset);
39820 }
39821 }
39822 }
39823}
39824#[doc = "Get / dump flow tables."]
39825#[derive(Clone)]
39826pub enum OpGetflowtableDumpRequest {}
39827impl<'a> IterableOpGetflowtableDumpRequest<'a> {}
39828impl OpGetflowtableDumpRequest {
39829 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpGetflowtableDumpRequest<'_>) {
39830 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
39831 (
39832 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
39833 IterableOpGetflowtableDumpRequest::with_loc(attrs, buf.as_ptr() as usize),
39834 )
39835 }
39836 fn attr_from_type(r#type: u16) -> Option<&'static str> {
39837 FlowtableAttrs::attr_from_type(r#type)
39838 }
39839}
39840#[derive(Clone, Copy, Default)]
39841pub struct IterableOpGetflowtableDumpRequest<'a> {
39842 buf: &'a [u8],
39843 pos: usize,
39844 orig_loc: usize,
39845}
39846impl<'a> IterableOpGetflowtableDumpRequest<'a> {
39847 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
39848 Self {
39849 buf,
39850 pos: 0,
39851 orig_loc,
39852 }
39853 }
39854 pub fn get_buf(&self) -> &'a [u8] {
39855 self.buf
39856 }
39857}
39858impl<'a> Iterator for IterableOpGetflowtableDumpRequest<'a> {
39859 type Item = Result<OpGetflowtableDumpRequest, ErrorContext>;
39860 fn next(&mut self) -> Option<Self::Item> {
39861 if self.buf.len() == self.pos {
39862 return None;
39863 }
39864 let pos = self.pos;
39865 let mut r#type = None;
39866 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
39867 r#type = Some(header.r#type);
39868 let res = match header.r#type {
39869 n => {
39870 if cfg!(any(test, feature = "deny-unknown-attrs")) {
39871 break;
39872 } else {
39873 continue;
39874 }
39875 }
39876 };
39877 return Some(Ok(res));
39878 }
39879 Some(Err(ErrorContext::new(
39880 "OpGetflowtableDumpRequest",
39881 r#type.and_then(|t| OpGetflowtableDumpRequest::attr_from_type(t)),
39882 self.orig_loc,
39883 self.buf.as_ptr().wrapping_add(pos) as usize,
39884 )))
39885 }
39886}
39887impl std::fmt::Debug for IterableOpGetflowtableDumpRequest<'_> {
39888 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39889 let mut fmt = f.debug_struct("OpGetflowtableDumpRequest");
39890 for attr in self.clone() {
39891 let attr = match attr {
39892 Ok(a) => a,
39893 Err(err) => {
39894 fmt.finish()?;
39895 f.write_str("Err(")?;
39896 err.fmt(f)?;
39897 return f.write_str(")");
39898 }
39899 };
39900 match attr {};
39901 }
39902 fmt.finish()
39903 }
39904}
39905impl IterableOpGetflowtableDumpRequest<'_> {
39906 pub fn lookup_attr(
39907 &self,
39908 offset: usize,
39909 missing_type: Option<u16>,
39910 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
39911 let mut stack = Vec::new();
39912 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
39913 if cur == offset + PushNfgenmsg::len() {
39914 stack.push(("OpGetflowtableDumpRequest", offset));
39915 return (
39916 stack,
39917 missing_type.and_then(|t| OpGetflowtableDumpRequest::attr_from_type(t)),
39918 );
39919 }
39920 (stack, None)
39921 }
39922}
39923#[doc = "Get / dump flow tables."]
39924pub struct PushOpGetflowtableDumpReply<Prev: Rec> {
39925 pub(crate) prev: Option<Prev>,
39926 pub(crate) header_offset: Option<usize>,
39927}
39928impl<Prev: Rec> Rec for PushOpGetflowtableDumpReply<Prev> {
39929 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
39930 self.prev.as_mut().unwrap().as_rec_mut()
39931 }
39932}
39933impl<Prev: Rec> PushOpGetflowtableDumpReply<Prev> {
39934 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
39935 Self::write_header(&mut prev, header);
39936 Self::new_without_header(prev)
39937 }
39938 fn new_without_header(prev: Prev) -> Self {
39939 Self {
39940 prev: Some(prev),
39941 header_offset: None,
39942 }
39943 }
39944 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
39945 prev.as_rec_mut().extend(header.as_slice());
39946 }
39947 pub fn end_nested(mut self) -> Prev {
39948 let mut prev = self.prev.take().unwrap();
39949 if let Some(header_offset) = &self.header_offset {
39950 finalize_nested_header(prev.as_rec_mut(), *header_offset);
39951 }
39952 prev
39953 }
39954 pub fn push_table(mut self, value: &CStr) -> Self {
39955 push_header(
39956 self.as_rec_mut(),
39957 1u16,
39958 value.to_bytes_with_nul().len() as u16,
39959 );
39960 self.as_rec_mut().extend(value.to_bytes_with_nul());
39961 self
39962 }
39963 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
39964 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
39965 self.as_rec_mut().extend(value);
39966 self.as_rec_mut().push(0);
39967 self
39968 }
39969 pub fn push_name(mut self, value: &CStr) -> Self {
39970 push_header(
39971 self.as_rec_mut(),
39972 2u16,
39973 value.to_bytes_with_nul().len() as u16,
39974 );
39975 self.as_rec_mut().extend(value.to_bytes_with_nul());
39976 self
39977 }
39978 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
39979 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
39980 self.as_rec_mut().extend(value);
39981 self.as_rec_mut().push(0);
39982 self
39983 }
39984 pub fn nested_hook(mut self) -> PushFlowtableHookAttrs<Self> {
39985 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
39986 PushFlowtableHookAttrs {
39987 prev: Some(self),
39988 header_offset: Some(header_offset),
39989 }
39990 }
39991 pub fn push_use(mut self, value: u32) -> Self {
39992 push_header(self.as_rec_mut(), 4u16, 4 as u16);
39993 self.as_rec_mut().extend(value.to_be_bytes());
39994 self
39995 }
39996 pub fn push_handle(mut self, value: u64) -> Self {
39997 push_header(self.as_rec_mut(), 5u16, 8 as u16);
39998 self.as_rec_mut().extend(value.to_be_bytes());
39999 self
40000 }
40001 pub fn push_flags(mut self, value: u32) -> Self {
40002 push_header(self.as_rec_mut(), 7u16, 4 as u16);
40003 self.as_rec_mut().extend(value.to_be_bytes());
40004 self
40005 }
40006}
40007impl<Prev: Rec> Drop for PushOpGetflowtableDumpReply<Prev> {
40008 fn drop(&mut self) {
40009 if let Some(prev) = &mut self.prev {
40010 if let Some(header_offset) = &self.header_offset {
40011 finalize_nested_header(prev.as_rec_mut(), *header_offset);
40012 }
40013 }
40014 }
40015}
40016#[doc = "Get / dump flow tables."]
40017#[derive(Clone)]
40018pub enum OpGetflowtableDumpReply<'a> {
40019 Table(&'a CStr),
40020 Name(&'a CStr),
40021 Hook(IterableFlowtableHookAttrs<'a>),
40022 Use(u32),
40023 Handle(u64),
40024 Flags(u32),
40025}
40026impl<'a> IterableOpGetflowtableDumpReply<'a> {
40027 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
40028 let mut iter = self.clone();
40029 iter.pos = 0;
40030 for attr in iter {
40031 if let OpGetflowtableDumpReply::Table(val) = attr? {
40032 return Ok(val);
40033 }
40034 }
40035 Err(ErrorContext::new_missing(
40036 "OpGetflowtableDumpReply",
40037 "Table",
40038 self.orig_loc,
40039 self.buf.as_ptr() as usize,
40040 ))
40041 }
40042 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
40043 let mut iter = self.clone();
40044 iter.pos = 0;
40045 for attr in iter {
40046 if let OpGetflowtableDumpReply::Name(val) = attr? {
40047 return Ok(val);
40048 }
40049 }
40050 Err(ErrorContext::new_missing(
40051 "OpGetflowtableDumpReply",
40052 "Name",
40053 self.orig_loc,
40054 self.buf.as_ptr() as usize,
40055 ))
40056 }
40057 pub fn get_hook(&self) -> Result<IterableFlowtableHookAttrs<'a>, ErrorContext> {
40058 let mut iter = self.clone();
40059 iter.pos = 0;
40060 for attr in iter {
40061 if let OpGetflowtableDumpReply::Hook(val) = attr? {
40062 return Ok(val);
40063 }
40064 }
40065 Err(ErrorContext::new_missing(
40066 "OpGetflowtableDumpReply",
40067 "Hook",
40068 self.orig_loc,
40069 self.buf.as_ptr() as usize,
40070 ))
40071 }
40072 pub fn get_use(&self) -> Result<u32, ErrorContext> {
40073 let mut iter = self.clone();
40074 iter.pos = 0;
40075 for attr in iter {
40076 if let OpGetflowtableDumpReply::Use(val) = attr? {
40077 return Ok(val);
40078 }
40079 }
40080 Err(ErrorContext::new_missing(
40081 "OpGetflowtableDumpReply",
40082 "Use",
40083 self.orig_loc,
40084 self.buf.as_ptr() as usize,
40085 ))
40086 }
40087 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
40088 let mut iter = self.clone();
40089 iter.pos = 0;
40090 for attr in iter {
40091 if let OpGetflowtableDumpReply::Handle(val) = attr? {
40092 return Ok(val);
40093 }
40094 }
40095 Err(ErrorContext::new_missing(
40096 "OpGetflowtableDumpReply",
40097 "Handle",
40098 self.orig_loc,
40099 self.buf.as_ptr() as usize,
40100 ))
40101 }
40102 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
40103 let mut iter = self.clone();
40104 iter.pos = 0;
40105 for attr in iter {
40106 if let OpGetflowtableDumpReply::Flags(val) = attr? {
40107 return Ok(val);
40108 }
40109 }
40110 Err(ErrorContext::new_missing(
40111 "OpGetflowtableDumpReply",
40112 "Flags",
40113 self.orig_loc,
40114 self.buf.as_ptr() as usize,
40115 ))
40116 }
40117}
40118impl<'a> OpGetflowtableDumpReply<'a> {
40119 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetflowtableDumpReply<'a>) {
40120 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
40121 (
40122 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
40123 IterableOpGetflowtableDumpReply::with_loc(attrs, buf.as_ptr() as usize),
40124 )
40125 }
40126 fn attr_from_type(r#type: u16) -> Option<&'static str> {
40127 FlowtableAttrs::attr_from_type(r#type)
40128 }
40129}
40130#[derive(Clone, Copy, Default)]
40131pub struct IterableOpGetflowtableDumpReply<'a> {
40132 buf: &'a [u8],
40133 pos: usize,
40134 orig_loc: usize,
40135}
40136impl<'a> IterableOpGetflowtableDumpReply<'a> {
40137 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
40138 Self {
40139 buf,
40140 pos: 0,
40141 orig_loc,
40142 }
40143 }
40144 pub fn get_buf(&self) -> &'a [u8] {
40145 self.buf
40146 }
40147}
40148impl<'a> Iterator for IterableOpGetflowtableDumpReply<'a> {
40149 type Item = Result<OpGetflowtableDumpReply<'a>, ErrorContext>;
40150 fn next(&mut self) -> Option<Self::Item> {
40151 if self.buf.len() == self.pos {
40152 return None;
40153 }
40154 let pos = self.pos;
40155 let mut r#type = None;
40156 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
40157 r#type = Some(header.r#type);
40158 let res = match header.r#type {
40159 1u16 => OpGetflowtableDumpReply::Table({
40160 let res = CStr::from_bytes_with_nul(next).ok();
40161 let Some(val) = res else { break };
40162 val
40163 }),
40164 2u16 => OpGetflowtableDumpReply::Name({
40165 let res = CStr::from_bytes_with_nul(next).ok();
40166 let Some(val) = res else { break };
40167 val
40168 }),
40169 3u16 => OpGetflowtableDumpReply::Hook({
40170 let res = Some(IterableFlowtableHookAttrs::with_loc(next, self.orig_loc));
40171 let Some(val) = res else { break };
40172 val
40173 }),
40174 4u16 => OpGetflowtableDumpReply::Use({
40175 let res = parse_be_u32(next);
40176 let Some(val) = res else { break };
40177 val
40178 }),
40179 5u16 => OpGetflowtableDumpReply::Handle({
40180 let res = parse_be_u64(next);
40181 let Some(val) = res else { break };
40182 val
40183 }),
40184 7u16 => OpGetflowtableDumpReply::Flags({
40185 let res = parse_be_u32(next);
40186 let Some(val) = res else { break };
40187 val
40188 }),
40189 n => {
40190 if cfg!(any(test, feature = "deny-unknown-attrs")) {
40191 break;
40192 } else {
40193 continue;
40194 }
40195 }
40196 };
40197 return Some(Ok(res));
40198 }
40199 Some(Err(ErrorContext::new(
40200 "OpGetflowtableDumpReply",
40201 r#type.and_then(|t| OpGetflowtableDumpReply::attr_from_type(t)),
40202 self.orig_loc,
40203 self.buf.as_ptr().wrapping_add(pos) as usize,
40204 )))
40205 }
40206}
40207impl<'a> std::fmt::Debug for IterableOpGetflowtableDumpReply<'_> {
40208 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40209 let mut fmt = f.debug_struct("OpGetflowtableDumpReply");
40210 for attr in self.clone() {
40211 let attr = match attr {
40212 Ok(a) => a,
40213 Err(err) => {
40214 fmt.finish()?;
40215 f.write_str("Err(")?;
40216 err.fmt(f)?;
40217 return f.write_str(")");
40218 }
40219 };
40220 match attr {
40221 OpGetflowtableDumpReply::Table(val) => fmt.field("Table", &val),
40222 OpGetflowtableDumpReply::Name(val) => fmt.field("Name", &val),
40223 OpGetflowtableDumpReply::Hook(val) => fmt.field("Hook", &val),
40224 OpGetflowtableDumpReply::Use(val) => fmt.field("Use", &val),
40225 OpGetflowtableDumpReply::Handle(val) => fmt.field("Handle", &val),
40226 OpGetflowtableDumpReply::Flags(val) => fmt.field("Flags", &val),
40227 };
40228 }
40229 fmt.finish()
40230 }
40231}
40232impl IterableOpGetflowtableDumpReply<'_> {
40233 pub fn lookup_attr(
40234 &self,
40235 offset: usize,
40236 missing_type: Option<u16>,
40237 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
40238 let mut stack = Vec::new();
40239 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
40240 if cur == offset + PushNfgenmsg::len() {
40241 stack.push(("OpGetflowtableDumpReply", offset));
40242 return (
40243 stack,
40244 missing_type.and_then(|t| OpGetflowtableDumpReply::attr_from_type(t)),
40245 );
40246 }
40247 if cur > offset || cur + self.buf.len() < offset {
40248 return (stack, None);
40249 }
40250 let mut attrs = self.clone();
40251 let mut last_off = cur + attrs.pos;
40252 let mut missing = None;
40253 while let Some(attr) = attrs.next() {
40254 let Ok(attr) = attr else { break };
40255 match attr {
40256 OpGetflowtableDumpReply::Table(val) => {
40257 if last_off == offset {
40258 stack.push(("Table", last_off));
40259 break;
40260 }
40261 }
40262 OpGetflowtableDumpReply::Name(val) => {
40263 if last_off == offset {
40264 stack.push(("Name", last_off));
40265 break;
40266 }
40267 }
40268 OpGetflowtableDumpReply::Hook(val) => {
40269 (stack, missing) = val.lookup_attr(offset, missing_type);
40270 if !stack.is_empty() {
40271 break;
40272 }
40273 }
40274 OpGetflowtableDumpReply::Use(val) => {
40275 if last_off == offset {
40276 stack.push(("Use", last_off));
40277 break;
40278 }
40279 }
40280 OpGetflowtableDumpReply::Handle(val) => {
40281 if last_off == offset {
40282 stack.push(("Handle", last_off));
40283 break;
40284 }
40285 }
40286 OpGetflowtableDumpReply::Flags(val) => {
40287 if last_off == offset {
40288 stack.push(("Flags", last_off));
40289 break;
40290 }
40291 }
40292 _ => {}
40293 };
40294 last_off = cur + attrs.pos;
40295 }
40296 if !stack.is_empty() {
40297 stack.push(("OpGetflowtableDumpReply", cur));
40298 }
40299 (stack, missing)
40300 }
40301}
40302#[derive(Debug)]
40303pub struct RequestOpGetflowtableDumpRequest<'r> {
40304 request: Request<'r>,
40305}
40306impl<'r> RequestOpGetflowtableDumpRequest<'r> {
40307 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
40308 PushOpGetflowtableDumpRequest::write_header(&mut request.buf_mut(), header);
40309 Self {
40310 request: request.set_dump(),
40311 }
40312 }
40313 pub fn encode(&mut self) -> PushOpGetflowtableDumpRequest<&mut Vec<u8>> {
40314 PushOpGetflowtableDumpRequest::new_without_header(self.request.buf_mut())
40315 }
40316 pub fn into_encoder(self) -> PushOpGetflowtableDumpRequest<RequestBuf<'r>> {
40317 PushOpGetflowtableDumpRequest::new_without_header(self.request.buf)
40318 }
40319}
40320impl NetlinkRequest for RequestOpGetflowtableDumpRequest<'_> {
40321 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetflowtableDumpReply<'buf>);
40322 fn protocol(&self) -> Protocol {
40323 Protocol::Raw {
40324 protonum: 12u16,
40325 request_type: 2583u16,
40326 }
40327 }
40328 fn flags(&self) -> u16 {
40329 self.request.flags
40330 }
40331 fn payload(&self) -> &[u8] {
40332 self.request.buf()
40333 }
40334 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
40335 OpGetflowtableDumpReply::new(buf)
40336 }
40337 fn lookup(
40338 buf: &[u8],
40339 offset: usize,
40340 missing_type: Option<u16>,
40341 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
40342 OpGetflowtableDumpRequest::new(buf)
40343 .1
40344 .lookup_attr(offset, missing_type)
40345 }
40346}
40347#[doc = "Get / dump flow tables."]
40348pub struct PushOpGetflowtableDoRequest<Prev: Rec> {
40349 pub(crate) prev: Option<Prev>,
40350 pub(crate) header_offset: Option<usize>,
40351}
40352impl<Prev: Rec> Rec for PushOpGetflowtableDoRequest<Prev> {
40353 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
40354 self.prev.as_mut().unwrap().as_rec_mut()
40355 }
40356}
40357impl<Prev: Rec> PushOpGetflowtableDoRequest<Prev> {
40358 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
40359 Self::write_header(&mut prev, header);
40360 Self::new_without_header(prev)
40361 }
40362 fn new_without_header(prev: Prev) -> Self {
40363 Self {
40364 prev: Some(prev),
40365 header_offset: None,
40366 }
40367 }
40368 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
40369 prev.as_rec_mut().extend(header.as_slice());
40370 }
40371 pub fn end_nested(mut self) -> Prev {
40372 let mut prev = self.prev.take().unwrap();
40373 if let Some(header_offset) = &self.header_offset {
40374 finalize_nested_header(prev.as_rec_mut(), *header_offset);
40375 }
40376 prev
40377 }
40378 pub fn push_table(mut self, value: &CStr) -> Self {
40379 push_header(
40380 self.as_rec_mut(),
40381 1u16,
40382 value.to_bytes_with_nul().len() as u16,
40383 );
40384 self.as_rec_mut().extend(value.to_bytes_with_nul());
40385 self
40386 }
40387 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
40388 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
40389 self.as_rec_mut().extend(value);
40390 self.as_rec_mut().push(0);
40391 self
40392 }
40393 pub fn push_name(mut self, value: &CStr) -> Self {
40394 push_header(
40395 self.as_rec_mut(),
40396 2u16,
40397 value.to_bytes_with_nul().len() as u16,
40398 );
40399 self.as_rec_mut().extend(value.to_bytes_with_nul());
40400 self
40401 }
40402 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
40403 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
40404 self.as_rec_mut().extend(value);
40405 self.as_rec_mut().push(0);
40406 self
40407 }
40408}
40409impl<Prev: Rec> Drop for PushOpGetflowtableDoRequest<Prev> {
40410 fn drop(&mut self) {
40411 if let Some(prev) = &mut self.prev {
40412 if let Some(header_offset) = &self.header_offset {
40413 finalize_nested_header(prev.as_rec_mut(), *header_offset);
40414 }
40415 }
40416 }
40417}
40418#[doc = "Get / dump flow tables."]
40419#[derive(Clone)]
40420pub enum OpGetflowtableDoRequest<'a> {
40421 Table(&'a CStr),
40422 Name(&'a CStr),
40423}
40424impl<'a> IterableOpGetflowtableDoRequest<'a> {
40425 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
40426 let mut iter = self.clone();
40427 iter.pos = 0;
40428 for attr in iter {
40429 if let OpGetflowtableDoRequest::Table(val) = attr? {
40430 return Ok(val);
40431 }
40432 }
40433 Err(ErrorContext::new_missing(
40434 "OpGetflowtableDoRequest",
40435 "Table",
40436 self.orig_loc,
40437 self.buf.as_ptr() as usize,
40438 ))
40439 }
40440 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
40441 let mut iter = self.clone();
40442 iter.pos = 0;
40443 for attr in iter {
40444 if let OpGetflowtableDoRequest::Name(val) = attr? {
40445 return Ok(val);
40446 }
40447 }
40448 Err(ErrorContext::new_missing(
40449 "OpGetflowtableDoRequest",
40450 "Name",
40451 self.orig_loc,
40452 self.buf.as_ptr() as usize,
40453 ))
40454 }
40455}
40456impl<'a> OpGetflowtableDoRequest<'a> {
40457 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetflowtableDoRequest<'a>) {
40458 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
40459 (
40460 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
40461 IterableOpGetflowtableDoRequest::with_loc(attrs, buf.as_ptr() as usize),
40462 )
40463 }
40464 fn attr_from_type(r#type: u16) -> Option<&'static str> {
40465 FlowtableAttrs::attr_from_type(r#type)
40466 }
40467}
40468#[derive(Clone, Copy, Default)]
40469pub struct IterableOpGetflowtableDoRequest<'a> {
40470 buf: &'a [u8],
40471 pos: usize,
40472 orig_loc: usize,
40473}
40474impl<'a> IterableOpGetflowtableDoRequest<'a> {
40475 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
40476 Self {
40477 buf,
40478 pos: 0,
40479 orig_loc,
40480 }
40481 }
40482 pub fn get_buf(&self) -> &'a [u8] {
40483 self.buf
40484 }
40485}
40486impl<'a> Iterator for IterableOpGetflowtableDoRequest<'a> {
40487 type Item = Result<OpGetflowtableDoRequest<'a>, ErrorContext>;
40488 fn next(&mut self) -> Option<Self::Item> {
40489 if self.buf.len() == self.pos {
40490 return None;
40491 }
40492 let pos = self.pos;
40493 let mut r#type = None;
40494 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
40495 r#type = Some(header.r#type);
40496 let res = match header.r#type {
40497 1u16 => OpGetflowtableDoRequest::Table({
40498 let res = CStr::from_bytes_with_nul(next).ok();
40499 let Some(val) = res else { break };
40500 val
40501 }),
40502 2u16 => OpGetflowtableDoRequest::Name({
40503 let res = CStr::from_bytes_with_nul(next).ok();
40504 let Some(val) = res else { break };
40505 val
40506 }),
40507 n => {
40508 if cfg!(any(test, feature = "deny-unknown-attrs")) {
40509 break;
40510 } else {
40511 continue;
40512 }
40513 }
40514 };
40515 return Some(Ok(res));
40516 }
40517 Some(Err(ErrorContext::new(
40518 "OpGetflowtableDoRequest",
40519 r#type.and_then(|t| OpGetflowtableDoRequest::attr_from_type(t)),
40520 self.orig_loc,
40521 self.buf.as_ptr().wrapping_add(pos) as usize,
40522 )))
40523 }
40524}
40525impl<'a> std::fmt::Debug for IterableOpGetflowtableDoRequest<'_> {
40526 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40527 let mut fmt = f.debug_struct("OpGetflowtableDoRequest");
40528 for attr in self.clone() {
40529 let attr = match attr {
40530 Ok(a) => a,
40531 Err(err) => {
40532 fmt.finish()?;
40533 f.write_str("Err(")?;
40534 err.fmt(f)?;
40535 return f.write_str(")");
40536 }
40537 };
40538 match attr {
40539 OpGetflowtableDoRequest::Table(val) => fmt.field("Table", &val),
40540 OpGetflowtableDoRequest::Name(val) => fmt.field("Name", &val),
40541 };
40542 }
40543 fmt.finish()
40544 }
40545}
40546impl IterableOpGetflowtableDoRequest<'_> {
40547 pub fn lookup_attr(
40548 &self,
40549 offset: usize,
40550 missing_type: Option<u16>,
40551 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
40552 let mut stack = Vec::new();
40553 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
40554 if cur == offset + PushNfgenmsg::len() {
40555 stack.push(("OpGetflowtableDoRequest", offset));
40556 return (
40557 stack,
40558 missing_type.and_then(|t| OpGetflowtableDoRequest::attr_from_type(t)),
40559 );
40560 }
40561 if cur > offset || cur + self.buf.len() < offset {
40562 return (stack, None);
40563 }
40564 let mut attrs = self.clone();
40565 let mut last_off = cur + attrs.pos;
40566 while let Some(attr) = attrs.next() {
40567 let Ok(attr) = attr else { break };
40568 match attr {
40569 OpGetflowtableDoRequest::Table(val) => {
40570 if last_off == offset {
40571 stack.push(("Table", last_off));
40572 break;
40573 }
40574 }
40575 OpGetflowtableDoRequest::Name(val) => {
40576 if last_off == offset {
40577 stack.push(("Name", last_off));
40578 break;
40579 }
40580 }
40581 _ => {}
40582 };
40583 last_off = cur + attrs.pos;
40584 }
40585 if !stack.is_empty() {
40586 stack.push(("OpGetflowtableDoRequest", cur));
40587 }
40588 (stack, None)
40589 }
40590}
40591#[doc = "Get / dump flow tables."]
40592pub struct PushOpGetflowtableDoReply<Prev: Rec> {
40593 pub(crate) prev: Option<Prev>,
40594 pub(crate) header_offset: Option<usize>,
40595}
40596impl<Prev: Rec> Rec for PushOpGetflowtableDoReply<Prev> {
40597 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
40598 self.prev.as_mut().unwrap().as_rec_mut()
40599 }
40600}
40601impl<Prev: Rec> PushOpGetflowtableDoReply<Prev> {
40602 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
40603 Self::write_header(&mut prev, header);
40604 Self::new_without_header(prev)
40605 }
40606 fn new_without_header(prev: Prev) -> Self {
40607 Self {
40608 prev: Some(prev),
40609 header_offset: None,
40610 }
40611 }
40612 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
40613 prev.as_rec_mut().extend(header.as_slice());
40614 }
40615 pub fn end_nested(mut self) -> Prev {
40616 let mut prev = self.prev.take().unwrap();
40617 if let Some(header_offset) = &self.header_offset {
40618 finalize_nested_header(prev.as_rec_mut(), *header_offset);
40619 }
40620 prev
40621 }
40622 pub fn push_table(mut self, value: &CStr) -> Self {
40623 push_header(
40624 self.as_rec_mut(),
40625 1u16,
40626 value.to_bytes_with_nul().len() as u16,
40627 );
40628 self.as_rec_mut().extend(value.to_bytes_with_nul());
40629 self
40630 }
40631 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
40632 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
40633 self.as_rec_mut().extend(value);
40634 self.as_rec_mut().push(0);
40635 self
40636 }
40637 pub fn push_name(mut self, value: &CStr) -> Self {
40638 push_header(
40639 self.as_rec_mut(),
40640 2u16,
40641 value.to_bytes_with_nul().len() as u16,
40642 );
40643 self.as_rec_mut().extend(value.to_bytes_with_nul());
40644 self
40645 }
40646 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
40647 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
40648 self.as_rec_mut().extend(value);
40649 self.as_rec_mut().push(0);
40650 self
40651 }
40652 pub fn nested_hook(mut self) -> PushFlowtableHookAttrs<Self> {
40653 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
40654 PushFlowtableHookAttrs {
40655 prev: Some(self),
40656 header_offset: Some(header_offset),
40657 }
40658 }
40659 pub fn push_use(mut self, value: u32) -> Self {
40660 push_header(self.as_rec_mut(), 4u16, 4 as u16);
40661 self.as_rec_mut().extend(value.to_be_bytes());
40662 self
40663 }
40664 pub fn push_handle(mut self, value: u64) -> Self {
40665 push_header(self.as_rec_mut(), 5u16, 8 as u16);
40666 self.as_rec_mut().extend(value.to_be_bytes());
40667 self
40668 }
40669 pub fn push_flags(mut self, value: u32) -> Self {
40670 push_header(self.as_rec_mut(), 7u16, 4 as u16);
40671 self.as_rec_mut().extend(value.to_be_bytes());
40672 self
40673 }
40674}
40675impl<Prev: Rec> Drop for PushOpGetflowtableDoReply<Prev> {
40676 fn drop(&mut self) {
40677 if let Some(prev) = &mut self.prev {
40678 if let Some(header_offset) = &self.header_offset {
40679 finalize_nested_header(prev.as_rec_mut(), *header_offset);
40680 }
40681 }
40682 }
40683}
40684#[doc = "Get / dump flow tables."]
40685#[derive(Clone)]
40686pub enum OpGetflowtableDoReply<'a> {
40687 Table(&'a CStr),
40688 Name(&'a CStr),
40689 Hook(IterableFlowtableHookAttrs<'a>),
40690 Use(u32),
40691 Handle(u64),
40692 Flags(u32),
40693}
40694impl<'a> IterableOpGetflowtableDoReply<'a> {
40695 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
40696 let mut iter = self.clone();
40697 iter.pos = 0;
40698 for attr in iter {
40699 if let OpGetflowtableDoReply::Table(val) = attr? {
40700 return Ok(val);
40701 }
40702 }
40703 Err(ErrorContext::new_missing(
40704 "OpGetflowtableDoReply",
40705 "Table",
40706 self.orig_loc,
40707 self.buf.as_ptr() as usize,
40708 ))
40709 }
40710 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
40711 let mut iter = self.clone();
40712 iter.pos = 0;
40713 for attr in iter {
40714 if let OpGetflowtableDoReply::Name(val) = attr? {
40715 return Ok(val);
40716 }
40717 }
40718 Err(ErrorContext::new_missing(
40719 "OpGetflowtableDoReply",
40720 "Name",
40721 self.orig_loc,
40722 self.buf.as_ptr() as usize,
40723 ))
40724 }
40725 pub fn get_hook(&self) -> Result<IterableFlowtableHookAttrs<'a>, ErrorContext> {
40726 let mut iter = self.clone();
40727 iter.pos = 0;
40728 for attr in iter {
40729 if let OpGetflowtableDoReply::Hook(val) = attr? {
40730 return Ok(val);
40731 }
40732 }
40733 Err(ErrorContext::new_missing(
40734 "OpGetflowtableDoReply",
40735 "Hook",
40736 self.orig_loc,
40737 self.buf.as_ptr() as usize,
40738 ))
40739 }
40740 pub fn get_use(&self) -> Result<u32, ErrorContext> {
40741 let mut iter = self.clone();
40742 iter.pos = 0;
40743 for attr in iter {
40744 if let OpGetflowtableDoReply::Use(val) = attr? {
40745 return Ok(val);
40746 }
40747 }
40748 Err(ErrorContext::new_missing(
40749 "OpGetflowtableDoReply",
40750 "Use",
40751 self.orig_loc,
40752 self.buf.as_ptr() as usize,
40753 ))
40754 }
40755 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
40756 let mut iter = self.clone();
40757 iter.pos = 0;
40758 for attr in iter {
40759 if let OpGetflowtableDoReply::Handle(val) = attr? {
40760 return Ok(val);
40761 }
40762 }
40763 Err(ErrorContext::new_missing(
40764 "OpGetflowtableDoReply",
40765 "Handle",
40766 self.orig_loc,
40767 self.buf.as_ptr() as usize,
40768 ))
40769 }
40770 pub fn get_flags(&self) -> Result<u32, ErrorContext> {
40771 let mut iter = self.clone();
40772 iter.pos = 0;
40773 for attr in iter {
40774 if let OpGetflowtableDoReply::Flags(val) = attr? {
40775 return Ok(val);
40776 }
40777 }
40778 Err(ErrorContext::new_missing(
40779 "OpGetflowtableDoReply",
40780 "Flags",
40781 self.orig_loc,
40782 self.buf.as_ptr() as usize,
40783 ))
40784 }
40785}
40786impl<'a> OpGetflowtableDoReply<'a> {
40787 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpGetflowtableDoReply<'a>) {
40788 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
40789 (
40790 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
40791 IterableOpGetflowtableDoReply::with_loc(attrs, buf.as_ptr() as usize),
40792 )
40793 }
40794 fn attr_from_type(r#type: u16) -> Option<&'static str> {
40795 FlowtableAttrs::attr_from_type(r#type)
40796 }
40797}
40798#[derive(Clone, Copy, Default)]
40799pub struct IterableOpGetflowtableDoReply<'a> {
40800 buf: &'a [u8],
40801 pos: usize,
40802 orig_loc: usize,
40803}
40804impl<'a> IterableOpGetflowtableDoReply<'a> {
40805 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
40806 Self {
40807 buf,
40808 pos: 0,
40809 orig_loc,
40810 }
40811 }
40812 pub fn get_buf(&self) -> &'a [u8] {
40813 self.buf
40814 }
40815}
40816impl<'a> Iterator for IterableOpGetflowtableDoReply<'a> {
40817 type Item = Result<OpGetflowtableDoReply<'a>, ErrorContext>;
40818 fn next(&mut self) -> Option<Self::Item> {
40819 if self.buf.len() == self.pos {
40820 return None;
40821 }
40822 let pos = self.pos;
40823 let mut r#type = None;
40824 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
40825 r#type = Some(header.r#type);
40826 let res = match header.r#type {
40827 1u16 => OpGetflowtableDoReply::Table({
40828 let res = CStr::from_bytes_with_nul(next).ok();
40829 let Some(val) = res else { break };
40830 val
40831 }),
40832 2u16 => OpGetflowtableDoReply::Name({
40833 let res = CStr::from_bytes_with_nul(next).ok();
40834 let Some(val) = res else { break };
40835 val
40836 }),
40837 3u16 => OpGetflowtableDoReply::Hook({
40838 let res = Some(IterableFlowtableHookAttrs::with_loc(next, self.orig_loc));
40839 let Some(val) = res else { break };
40840 val
40841 }),
40842 4u16 => OpGetflowtableDoReply::Use({
40843 let res = parse_be_u32(next);
40844 let Some(val) = res else { break };
40845 val
40846 }),
40847 5u16 => OpGetflowtableDoReply::Handle({
40848 let res = parse_be_u64(next);
40849 let Some(val) = res else { break };
40850 val
40851 }),
40852 7u16 => OpGetflowtableDoReply::Flags({
40853 let res = parse_be_u32(next);
40854 let Some(val) = res else { break };
40855 val
40856 }),
40857 n => {
40858 if cfg!(any(test, feature = "deny-unknown-attrs")) {
40859 break;
40860 } else {
40861 continue;
40862 }
40863 }
40864 };
40865 return Some(Ok(res));
40866 }
40867 Some(Err(ErrorContext::new(
40868 "OpGetflowtableDoReply",
40869 r#type.and_then(|t| OpGetflowtableDoReply::attr_from_type(t)),
40870 self.orig_loc,
40871 self.buf.as_ptr().wrapping_add(pos) as usize,
40872 )))
40873 }
40874}
40875impl<'a> std::fmt::Debug for IterableOpGetflowtableDoReply<'_> {
40876 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40877 let mut fmt = f.debug_struct("OpGetflowtableDoReply");
40878 for attr in self.clone() {
40879 let attr = match attr {
40880 Ok(a) => a,
40881 Err(err) => {
40882 fmt.finish()?;
40883 f.write_str("Err(")?;
40884 err.fmt(f)?;
40885 return f.write_str(")");
40886 }
40887 };
40888 match attr {
40889 OpGetflowtableDoReply::Table(val) => fmt.field("Table", &val),
40890 OpGetflowtableDoReply::Name(val) => fmt.field("Name", &val),
40891 OpGetflowtableDoReply::Hook(val) => fmt.field("Hook", &val),
40892 OpGetflowtableDoReply::Use(val) => fmt.field("Use", &val),
40893 OpGetflowtableDoReply::Handle(val) => fmt.field("Handle", &val),
40894 OpGetflowtableDoReply::Flags(val) => fmt.field("Flags", &val),
40895 };
40896 }
40897 fmt.finish()
40898 }
40899}
40900impl IterableOpGetflowtableDoReply<'_> {
40901 pub fn lookup_attr(
40902 &self,
40903 offset: usize,
40904 missing_type: Option<u16>,
40905 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
40906 let mut stack = Vec::new();
40907 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
40908 if cur == offset + PushNfgenmsg::len() {
40909 stack.push(("OpGetflowtableDoReply", offset));
40910 return (
40911 stack,
40912 missing_type.and_then(|t| OpGetflowtableDoReply::attr_from_type(t)),
40913 );
40914 }
40915 if cur > offset || cur + self.buf.len() < offset {
40916 return (stack, None);
40917 }
40918 let mut attrs = self.clone();
40919 let mut last_off = cur + attrs.pos;
40920 let mut missing = None;
40921 while let Some(attr) = attrs.next() {
40922 let Ok(attr) = attr else { break };
40923 match attr {
40924 OpGetflowtableDoReply::Table(val) => {
40925 if last_off == offset {
40926 stack.push(("Table", last_off));
40927 break;
40928 }
40929 }
40930 OpGetflowtableDoReply::Name(val) => {
40931 if last_off == offset {
40932 stack.push(("Name", last_off));
40933 break;
40934 }
40935 }
40936 OpGetflowtableDoReply::Hook(val) => {
40937 (stack, missing) = val.lookup_attr(offset, missing_type);
40938 if !stack.is_empty() {
40939 break;
40940 }
40941 }
40942 OpGetflowtableDoReply::Use(val) => {
40943 if last_off == offset {
40944 stack.push(("Use", last_off));
40945 break;
40946 }
40947 }
40948 OpGetflowtableDoReply::Handle(val) => {
40949 if last_off == offset {
40950 stack.push(("Handle", last_off));
40951 break;
40952 }
40953 }
40954 OpGetflowtableDoReply::Flags(val) => {
40955 if last_off == offset {
40956 stack.push(("Flags", last_off));
40957 break;
40958 }
40959 }
40960 _ => {}
40961 };
40962 last_off = cur + attrs.pos;
40963 }
40964 if !stack.is_empty() {
40965 stack.push(("OpGetflowtableDoReply", cur));
40966 }
40967 (stack, missing)
40968 }
40969}
40970#[derive(Debug)]
40971pub struct RequestOpGetflowtableDoRequest<'r> {
40972 request: Request<'r>,
40973}
40974impl<'r> RequestOpGetflowtableDoRequest<'r> {
40975 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
40976 PushOpGetflowtableDoRequest::write_header(&mut request.buf_mut(), header);
40977 Self { request: request }
40978 }
40979 pub fn encode(&mut self) -> PushOpGetflowtableDoRequest<&mut Vec<u8>> {
40980 PushOpGetflowtableDoRequest::new_without_header(self.request.buf_mut())
40981 }
40982 pub fn into_encoder(self) -> PushOpGetflowtableDoRequest<RequestBuf<'r>> {
40983 PushOpGetflowtableDoRequest::new_without_header(self.request.buf)
40984 }
40985}
40986impl NetlinkRequest for RequestOpGetflowtableDoRequest<'_> {
40987 type ReplyType<'buf> = (PushNfgenmsg, IterableOpGetflowtableDoReply<'buf>);
40988 fn protocol(&self) -> Protocol {
40989 Protocol::Raw {
40990 protonum: 12u16,
40991 request_type: 2583u16,
40992 }
40993 }
40994 fn flags(&self) -> u16 {
40995 self.request.flags
40996 }
40997 fn payload(&self) -> &[u8] {
40998 self.request.buf()
40999 }
41000 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
41001 OpGetflowtableDoReply::new(buf)
41002 }
41003 fn lookup(
41004 buf: &[u8],
41005 offset: usize,
41006 missing_type: Option<u16>,
41007 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
41008 OpGetflowtableDoRequest::new(buf)
41009 .1
41010 .lookup_attr(offset, missing_type)
41011 }
41012}
41013#[doc = "Delete an existing flow table."]
41014pub struct PushOpDelflowtableDoRequest<Prev: Rec> {
41015 pub(crate) prev: Option<Prev>,
41016 pub(crate) header_offset: Option<usize>,
41017}
41018impl<Prev: Rec> Rec for PushOpDelflowtableDoRequest<Prev> {
41019 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
41020 self.prev.as_mut().unwrap().as_rec_mut()
41021 }
41022}
41023impl<Prev: Rec> PushOpDelflowtableDoRequest<Prev> {
41024 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
41025 Self::write_header(&mut prev, header);
41026 Self::new_without_header(prev)
41027 }
41028 fn new_without_header(prev: Prev) -> Self {
41029 Self {
41030 prev: Some(prev),
41031 header_offset: None,
41032 }
41033 }
41034 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
41035 prev.as_rec_mut().extend(header.as_slice());
41036 }
41037 pub fn end_nested(mut self) -> Prev {
41038 let mut prev = self.prev.take().unwrap();
41039 if let Some(header_offset) = &self.header_offset {
41040 finalize_nested_header(prev.as_rec_mut(), *header_offset);
41041 }
41042 prev
41043 }
41044 pub fn push_table(mut self, value: &CStr) -> Self {
41045 push_header(
41046 self.as_rec_mut(),
41047 1u16,
41048 value.to_bytes_with_nul().len() as u16,
41049 );
41050 self.as_rec_mut().extend(value.to_bytes_with_nul());
41051 self
41052 }
41053 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
41054 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
41055 self.as_rec_mut().extend(value);
41056 self.as_rec_mut().push(0);
41057 self
41058 }
41059 pub fn push_name(mut self, value: &CStr) -> Self {
41060 push_header(
41061 self.as_rec_mut(),
41062 2u16,
41063 value.to_bytes_with_nul().len() as u16,
41064 );
41065 self.as_rec_mut().extend(value.to_bytes_with_nul());
41066 self
41067 }
41068 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
41069 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
41070 self.as_rec_mut().extend(value);
41071 self.as_rec_mut().push(0);
41072 self
41073 }
41074 pub fn nested_hook(mut self) -> PushFlowtableHookAttrs<Self> {
41075 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
41076 PushFlowtableHookAttrs {
41077 prev: Some(self),
41078 header_offset: Some(header_offset),
41079 }
41080 }
41081 pub fn push_handle(mut self, value: u64) -> Self {
41082 push_header(self.as_rec_mut(), 5u16, 8 as u16);
41083 self.as_rec_mut().extend(value.to_be_bytes());
41084 self
41085 }
41086}
41087impl<Prev: Rec> Drop for PushOpDelflowtableDoRequest<Prev> {
41088 fn drop(&mut self) {
41089 if let Some(prev) = &mut self.prev {
41090 if let Some(header_offset) = &self.header_offset {
41091 finalize_nested_header(prev.as_rec_mut(), *header_offset);
41092 }
41093 }
41094 }
41095}
41096#[doc = "Delete an existing flow table."]
41097#[derive(Clone)]
41098pub enum OpDelflowtableDoRequest<'a> {
41099 Table(&'a CStr),
41100 Name(&'a CStr),
41101 Hook(IterableFlowtableHookAttrs<'a>),
41102 Handle(u64),
41103}
41104impl<'a> IterableOpDelflowtableDoRequest<'a> {
41105 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
41106 let mut iter = self.clone();
41107 iter.pos = 0;
41108 for attr in iter {
41109 if let OpDelflowtableDoRequest::Table(val) = attr? {
41110 return Ok(val);
41111 }
41112 }
41113 Err(ErrorContext::new_missing(
41114 "OpDelflowtableDoRequest",
41115 "Table",
41116 self.orig_loc,
41117 self.buf.as_ptr() as usize,
41118 ))
41119 }
41120 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
41121 let mut iter = self.clone();
41122 iter.pos = 0;
41123 for attr in iter {
41124 if let OpDelflowtableDoRequest::Name(val) = attr? {
41125 return Ok(val);
41126 }
41127 }
41128 Err(ErrorContext::new_missing(
41129 "OpDelflowtableDoRequest",
41130 "Name",
41131 self.orig_loc,
41132 self.buf.as_ptr() as usize,
41133 ))
41134 }
41135 pub fn get_hook(&self) -> Result<IterableFlowtableHookAttrs<'a>, ErrorContext> {
41136 let mut iter = self.clone();
41137 iter.pos = 0;
41138 for attr in iter {
41139 if let OpDelflowtableDoRequest::Hook(val) = attr? {
41140 return Ok(val);
41141 }
41142 }
41143 Err(ErrorContext::new_missing(
41144 "OpDelflowtableDoRequest",
41145 "Hook",
41146 self.orig_loc,
41147 self.buf.as_ptr() as usize,
41148 ))
41149 }
41150 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
41151 let mut iter = self.clone();
41152 iter.pos = 0;
41153 for attr in iter {
41154 if let OpDelflowtableDoRequest::Handle(val) = attr? {
41155 return Ok(val);
41156 }
41157 }
41158 Err(ErrorContext::new_missing(
41159 "OpDelflowtableDoRequest",
41160 "Handle",
41161 self.orig_loc,
41162 self.buf.as_ptr() as usize,
41163 ))
41164 }
41165}
41166impl<'a> OpDelflowtableDoRequest<'a> {
41167 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDelflowtableDoRequest<'a>) {
41168 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
41169 (
41170 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
41171 IterableOpDelflowtableDoRequest::with_loc(attrs, buf.as_ptr() as usize),
41172 )
41173 }
41174 fn attr_from_type(r#type: u16) -> Option<&'static str> {
41175 FlowtableAttrs::attr_from_type(r#type)
41176 }
41177}
41178#[derive(Clone, Copy, Default)]
41179pub struct IterableOpDelflowtableDoRequest<'a> {
41180 buf: &'a [u8],
41181 pos: usize,
41182 orig_loc: usize,
41183}
41184impl<'a> IterableOpDelflowtableDoRequest<'a> {
41185 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
41186 Self {
41187 buf,
41188 pos: 0,
41189 orig_loc,
41190 }
41191 }
41192 pub fn get_buf(&self) -> &'a [u8] {
41193 self.buf
41194 }
41195}
41196impl<'a> Iterator for IterableOpDelflowtableDoRequest<'a> {
41197 type Item = Result<OpDelflowtableDoRequest<'a>, ErrorContext>;
41198 fn next(&mut self) -> Option<Self::Item> {
41199 if self.buf.len() == self.pos {
41200 return None;
41201 }
41202 let pos = self.pos;
41203 let mut r#type = None;
41204 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
41205 r#type = Some(header.r#type);
41206 let res = match header.r#type {
41207 1u16 => OpDelflowtableDoRequest::Table({
41208 let res = CStr::from_bytes_with_nul(next).ok();
41209 let Some(val) = res else { break };
41210 val
41211 }),
41212 2u16 => OpDelflowtableDoRequest::Name({
41213 let res = CStr::from_bytes_with_nul(next).ok();
41214 let Some(val) = res else { break };
41215 val
41216 }),
41217 3u16 => OpDelflowtableDoRequest::Hook({
41218 let res = Some(IterableFlowtableHookAttrs::with_loc(next, self.orig_loc));
41219 let Some(val) = res else { break };
41220 val
41221 }),
41222 5u16 => OpDelflowtableDoRequest::Handle({
41223 let res = parse_be_u64(next);
41224 let Some(val) = res else { break };
41225 val
41226 }),
41227 n => {
41228 if cfg!(any(test, feature = "deny-unknown-attrs")) {
41229 break;
41230 } else {
41231 continue;
41232 }
41233 }
41234 };
41235 return Some(Ok(res));
41236 }
41237 Some(Err(ErrorContext::new(
41238 "OpDelflowtableDoRequest",
41239 r#type.and_then(|t| OpDelflowtableDoRequest::attr_from_type(t)),
41240 self.orig_loc,
41241 self.buf.as_ptr().wrapping_add(pos) as usize,
41242 )))
41243 }
41244}
41245impl<'a> std::fmt::Debug for IterableOpDelflowtableDoRequest<'_> {
41246 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41247 let mut fmt = f.debug_struct("OpDelflowtableDoRequest");
41248 for attr in self.clone() {
41249 let attr = match attr {
41250 Ok(a) => a,
41251 Err(err) => {
41252 fmt.finish()?;
41253 f.write_str("Err(")?;
41254 err.fmt(f)?;
41255 return f.write_str(")");
41256 }
41257 };
41258 match attr {
41259 OpDelflowtableDoRequest::Table(val) => fmt.field("Table", &val),
41260 OpDelflowtableDoRequest::Name(val) => fmt.field("Name", &val),
41261 OpDelflowtableDoRequest::Hook(val) => fmt.field("Hook", &val),
41262 OpDelflowtableDoRequest::Handle(val) => fmt.field("Handle", &val),
41263 };
41264 }
41265 fmt.finish()
41266 }
41267}
41268impl IterableOpDelflowtableDoRequest<'_> {
41269 pub fn lookup_attr(
41270 &self,
41271 offset: usize,
41272 missing_type: Option<u16>,
41273 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
41274 let mut stack = Vec::new();
41275 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
41276 if cur == offset + PushNfgenmsg::len() {
41277 stack.push(("OpDelflowtableDoRequest", offset));
41278 return (
41279 stack,
41280 missing_type.and_then(|t| OpDelflowtableDoRequest::attr_from_type(t)),
41281 );
41282 }
41283 if cur > offset || cur + self.buf.len() < offset {
41284 return (stack, None);
41285 }
41286 let mut attrs = self.clone();
41287 let mut last_off = cur + attrs.pos;
41288 let mut missing = None;
41289 while let Some(attr) = attrs.next() {
41290 let Ok(attr) = attr else { break };
41291 match attr {
41292 OpDelflowtableDoRequest::Table(val) => {
41293 if last_off == offset {
41294 stack.push(("Table", last_off));
41295 break;
41296 }
41297 }
41298 OpDelflowtableDoRequest::Name(val) => {
41299 if last_off == offset {
41300 stack.push(("Name", last_off));
41301 break;
41302 }
41303 }
41304 OpDelflowtableDoRequest::Hook(val) => {
41305 (stack, missing) = val.lookup_attr(offset, missing_type);
41306 if !stack.is_empty() {
41307 break;
41308 }
41309 }
41310 OpDelflowtableDoRequest::Handle(val) => {
41311 if last_off == offset {
41312 stack.push(("Handle", last_off));
41313 break;
41314 }
41315 }
41316 _ => {}
41317 };
41318 last_off = cur + attrs.pos;
41319 }
41320 if !stack.is_empty() {
41321 stack.push(("OpDelflowtableDoRequest", cur));
41322 }
41323 (stack, missing)
41324 }
41325}
41326#[doc = "Delete an existing flow table."]
41327pub struct PushOpDelflowtableDoReply<Prev: Rec> {
41328 pub(crate) prev: Option<Prev>,
41329 pub(crate) header_offset: Option<usize>,
41330}
41331impl<Prev: Rec> Rec for PushOpDelflowtableDoReply<Prev> {
41332 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
41333 self.prev.as_mut().unwrap().as_rec_mut()
41334 }
41335}
41336impl<Prev: Rec> PushOpDelflowtableDoReply<Prev> {
41337 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
41338 Self::write_header(&mut prev, header);
41339 Self::new_without_header(prev)
41340 }
41341 fn new_without_header(prev: Prev) -> Self {
41342 Self {
41343 prev: Some(prev),
41344 header_offset: None,
41345 }
41346 }
41347 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
41348 prev.as_rec_mut().extend(header.as_slice());
41349 }
41350 pub fn end_nested(mut self) -> Prev {
41351 let mut prev = self.prev.take().unwrap();
41352 if let Some(header_offset) = &self.header_offset {
41353 finalize_nested_header(prev.as_rec_mut(), *header_offset);
41354 }
41355 prev
41356 }
41357}
41358impl<Prev: Rec> Drop for PushOpDelflowtableDoReply<Prev> {
41359 fn drop(&mut self) {
41360 if let Some(prev) = &mut self.prev {
41361 if let Some(header_offset) = &self.header_offset {
41362 finalize_nested_header(prev.as_rec_mut(), *header_offset);
41363 }
41364 }
41365 }
41366}
41367#[doc = "Delete an existing flow table."]
41368#[derive(Clone)]
41369pub enum OpDelflowtableDoReply {}
41370impl<'a> IterableOpDelflowtableDoReply<'a> {}
41371impl OpDelflowtableDoReply {
41372 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDelflowtableDoReply<'_>) {
41373 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
41374 (
41375 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
41376 IterableOpDelflowtableDoReply::with_loc(attrs, buf.as_ptr() as usize),
41377 )
41378 }
41379 fn attr_from_type(r#type: u16) -> Option<&'static str> {
41380 FlowtableAttrs::attr_from_type(r#type)
41381 }
41382}
41383#[derive(Clone, Copy, Default)]
41384pub struct IterableOpDelflowtableDoReply<'a> {
41385 buf: &'a [u8],
41386 pos: usize,
41387 orig_loc: usize,
41388}
41389impl<'a> IterableOpDelflowtableDoReply<'a> {
41390 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
41391 Self {
41392 buf,
41393 pos: 0,
41394 orig_loc,
41395 }
41396 }
41397 pub fn get_buf(&self) -> &'a [u8] {
41398 self.buf
41399 }
41400}
41401impl<'a> Iterator for IterableOpDelflowtableDoReply<'a> {
41402 type Item = Result<OpDelflowtableDoReply, ErrorContext>;
41403 fn next(&mut self) -> Option<Self::Item> {
41404 if self.buf.len() == self.pos {
41405 return None;
41406 }
41407 let pos = self.pos;
41408 let mut r#type = None;
41409 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
41410 r#type = Some(header.r#type);
41411 let res = match header.r#type {
41412 n => {
41413 if cfg!(any(test, feature = "deny-unknown-attrs")) {
41414 break;
41415 } else {
41416 continue;
41417 }
41418 }
41419 };
41420 return Some(Ok(res));
41421 }
41422 Some(Err(ErrorContext::new(
41423 "OpDelflowtableDoReply",
41424 r#type.and_then(|t| OpDelflowtableDoReply::attr_from_type(t)),
41425 self.orig_loc,
41426 self.buf.as_ptr().wrapping_add(pos) as usize,
41427 )))
41428 }
41429}
41430impl std::fmt::Debug for IterableOpDelflowtableDoReply<'_> {
41431 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41432 let mut fmt = f.debug_struct("OpDelflowtableDoReply");
41433 for attr in self.clone() {
41434 let attr = match attr {
41435 Ok(a) => a,
41436 Err(err) => {
41437 fmt.finish()?;
41438 f.write_str("Err(")?;
41439 err.fmt(f)?;
41440 return f.write_str(")");
41441 }
41442 };
41443 match attr {};
41444 }
41445 fmt.finish()
41446 }
41447}
41448impl IterableOpDelflowtableDoReply<'_> {
41449 pub fn lookup_attr(
41450 &self,
41451 offset: usize,
41452 missing_type: Option<u16>,
41453 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
41454 let mut stack = Vec::new();
41455 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
41456 if cur == offset + PushNfgenmsg::len() {
41457 stack.push(("OpDelflowtableDoReply", offset));
41458 return (
41459 stack,
41460 missing_type.and_then(|t| OpDelflowtableDoReply::attr_from_type(t)),
41461 );
41462 }
41463 (stack, None)
41464 }
41465}
41466#[derive(Debug)]
41467pub struct RequestOpDelflowtableDoRequest<'r> {
41468 request: Request<'r>,
41469}
41470impl<'r> RequestOpDelflowtableDoRequest<'r> {
41471 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
41472 PushOpDelflowtableDoRequest::write_header(&mut request.buf_mut(), header);
41473 Self { request: request }
41474 }
41475 pub fn encode(&mut self) -> PushOpDelflowtableDoRequest<&mut Vec<u8>> {
41476 PushOpDelflowtableDoRequest::new_without_header(self.request.buf_mut())
41477 }
41478 pub fn into_encoder(self) -> PushOpDelflowtableDoRequest<RequestBuf<'r>> {
41479 PushOpDelflowtableDoRequest::new_without_header(self.request.buf)
41480 }
41481}
41482impl NetlinkRequest for RequestOpDelflowtableDoRequest<'_> {
41483 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDelflowtableDoReply<'buf>);
41484 fn protocol(&self) -> Protocol {
41485 Protocol::Raw {
41486 protonum: 12u16,
41487 request_type: 2584u16,
41488 }
41489 }
41490 fn flags(&self) -> u16 {
41491 self.request.flags
41492 }
41493 fn payload(&self) -> &[u8] {
41494 self.request.buf()
41495 }
41496 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
41497 OpDelflowtableDoReply::new(buf)
41498 }
41499 fn lookup(
41500 buf: &[u8],
41501 offset: usize,
41502 missing_type: Option<u16>,
41503 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
41504 OpDelflowtableDoRequest::new(buf)
41505 .1
41506 .lookup_attr(offset, missing_type)
41507 }
41508}
41509#[doc = "Delete an existing flow table with destroy semantics."]
41510pub struct PushOpDestroyflowtableDoRequest<Prev: Rec> {
41511 pub(crate) prev: Option<Prev>,
41512 pub(crate) header_offset: Option<usize>,
41513}
41514impl<Prev: Rec> Rec for PushOpDestroyflowtableDoRequest<Prev> {
41515 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
41516 self.prev.as_mut().unwrap().as_rec_mut()
41517 }
41518}
41519impl<Prev: Rec> PushOpDestroyflowtableDoRequest<Prev> {
41520 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
41521 Self::write_header(&mut prev, header);
41522 Self::new_without_header(prev)
41523 }
41524 fn new_without_header(prev: Prev) -> Self {
41525 Self {
41526 prev: Some(prev),
41527 header_offset: None,
41528 }
41529 }
41530 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
41531 prev.as_rec_mut().extend(header.as_slice());
41532 }
41533 pub fn end_nested(mut self) -> Prev {
41534 let mut prev = self.prev.take().unwrap();
41535 if let Some(header_offset) = &self.header_offset {
41536 finalize_nested_header(prev.as_rec_mut(), *header_offset);
41537 }
41538 prev
41539 }
41540 pub fn push_table(mut self, value: &CStr) -> Self {
41541 push_header(
41542 self.as_rec_mut(),
41543 1u16,
41544 value.to_bytes_with_nul().len() as u16,
41545 );
41546 self.as_rec_mut().extend(value.to_bytes_with_nul());
41547 self
41548 }
41549 pub fn push_table_bytes(mut self, value: &[u8]) -> Self {
41550 push_header(self.as_rec_mut(), 1u16, (value.len() + 1) as u16);
41551 self.as_rec_mut().extend(value);
41552 self.as_rec_mut().push(0);
41553 self
41554 }
41555 pub fn push_name(mut self, value: &CStr) -> Self {
41556 push_header(
41557 self.as_rec_mut(),
41558 2u16,
41559 value.to_bytes_with_nul().len() as u16,
41560 );
41561 self.as_rec_mut().extend(value.to_bytes_with_nul());
41562 self
41563 }
41564 pub fn push_name_bytes(mut self, value: &[u8]) -> Self {
41565 push_header(self.as_rec_mut(), 2u16, (value.len() + 1) as u16);
41566 self.as_rec_mut().extend(value);
41567 self.as_rec_mut().push(0);
41568 self
41569 }
41570 pub fn nested_hook(mut self) -> PushFlowtableHookAttrs<Self> {
41571 let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
41572 PushFlowtableHookAttrs {
41573 prev: Some(self),
41574 header_offset: Some(header_offset),
41575 }
41576 }
41577 pub fn push_handle(mut self, value: u64) -> Self {
41578 push_header(self.as_rec_mut(), 5u16, 8 as u16);
41579 self.as_rec_mut().extend(value.to_be_bytes());
41580 self
41581 }
41582}
41583impl<Prev: Rec> Drop for PushOpDestroyflowtableDoRequest<Prev> {
41584 fn drop(&mut self) {
41585 if let Some(prev) = &mut self.prev {
41586 if let Some(header_offset) = &self.header_offset {
41587 finalize_nested_header(prev.as_rec_mut(), *header_offset);
41588 }
41589 }
41590 }
41591}
41592#[doc = "Delete an existing flow table with destroy semantics."]
41593#[derive(Clone)]
41594pub enum OpDestroyflowtableDoRequest<'a> {
41595 Table(&'a CStr),
41596 Name(&'a CStr),
41597 Hook(IterableFlowtableHookAttrs<'a>),
41598 Handle(u64),
41599}
41600impl<'a> IterableOpDestroyflowtableDoRequest<'a> {
41601 pub fn get_table(&self) -> Result<&'a CStr, ErrorContext> {
41602 let mut iter = self.clone();
41603 iter.pos = 0;
41604 for attr in iter {
41605 if let OpDestroyflowtableDoRequest::Table(val) = attr? {
41606 return Ok(val);
41607 }
41608 }
41609 Err(ErrorContext::new_missing(
41610 "OpDestroyflowtableDoRequest",
41611 "Table",
41612 self.orig_loc,
41613 self.buf.as_ptr() as usize,
41614 ))
41615 }
41616 pub fn get_name(&self) -> Result<&'a CStr, ErrorContext> {
41617 let mut iter = self.clone();
41618 iter.pos = 0;
41619 for attr in iter {
41620 if let OpDestroyflowtableDoRequest::Name(val) = attr? {
41621 return Ok(val);
41622 }
41623 }
41624 Err(ErrorContext::new_missing(
41625 "OpDestroyflowtableDoRequest",
41626 "Name",
41627 self.orig_loc,
41628 self.buf.as_ptr() as usize,
41629 ))
41630 }
41631 pub fn get_hook(&self) -> Result<IterableFlowtableHookAttrs<'a>, ErrorContext> {
41632 let mut iter = self.clone();
41633 iter.pos = 0;
41634 for attr in iter {
41635 if let OpDestroyflowtableDoRequest::Hook(val) = attr? {
41636 return Ok(val);
41637 }
41638 }
41639 Err(ErrorContext::new_missing(
41640 "OpDestroyflowtableDoRequest",
41641 "Hook",
41642 self.orig_loc,
41643 self.buf.as_ptr() as usize,
41644 ))
41645 }
41646 pub fn get_handle(&self) -> Result<u64, ErrorContext> {
41647 let mut iter = self.clone();
41648 iter.pos = 0;
41649 for attr in iter {
41650 if let OpDestroyflowtableDoRequest::Handle(val) = attr? {
41651 return Ok(val);
41652 }
41653 }
41654 Err(ErrorContext::new_missing(
41655 "OpDestroyflowtableDoRequest",
41656 "Handle",
41657 self.orig_loc,
41658 self.buf.as_ptr() as usize,
41659 ))
41660 }
41661}
41662impl<'a> OpDestroyflowtableDoRequest<'a> {
41663 pub fn new(buf: &'a [u8]) -> (PushNfgenmsg, IterableOpDestroyflowtableDoRequest<'a>) {
41664 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
41665 (
41666 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
41667 IterableOpDestroyflowtableDoRequest::with_loc(attrs, buf.as_ptr() as usize),
41668 )
41669 }
41670 fn attr_from_type(r#type: u16) -> Option<&'static str> {
41671 FlowtableAttrs::attr_from_type(r#type)
41672 }
41673}
41674#[derive(Clone, Copy, Default)]
41675pub struct IterableOpDestroyflowtableDoRequest<'a> {
41676 buf: &'a [u8],
41677 pos: usize,
41678 orig_loc: usize,
41679}
41680impl<'a> IterableOpDestroyflowtableDoRequest<'a> {
41681 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
41682 Self {
41683 buf,
41684 pos: 0,
41685 orig_loc,
41686 }
41687 }
41688 pub fn get_buf(&self) -> &'a [u8] {
41689 self.buf
41690 }
41691}
41692impl<'a> Iterator for IterableOpDestroyflowtableDoRequest<'a> {
41693 type Item = Result<OpDestroyflowtableDoRequest<'a>, ErrorContext>;
41694 fn next(&mut self) -> Option<Self::Item> {
41695 if self.buf.len() == self.pos {
41696 return None;
41697 }
41698 let pos = self.pos;
41699 let mut r#type = None;
41700 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
41701 r#type = Some(header.r#type);
41702 let res = match header.r#type {
41703 1u16 => OpDestroyflowtableDoRequest::Table({
41704 let res = CStr::from_bytes_with_nul(next).ok();
41705 let Some(val) = res else { break };
41706 val
41707 }),
41708 2u16 => OpDestroyflowtableDoRequest::Name({
41709 let res = CStr::from_bytes_with_nul(next).ok();
41710 let Some(val) = res else { break };
41711 val
41712 }),
41713 3u16 => OpDestroyflowtableDoRequest::Hook({
41714 let res = Some(IterableFlowtableHookAttrs::with_loc(next, self.orig_loc));
41715 let Some(val) = res else { break };
41716 val
41717 }),
41718 5u16 => OpDestroyflowtableDoRequest::Handle({
41719 let res = parse_be_u64(next);
41720 let Some(val) = res else { break };
41721 val
41722 }),
41723 n => {
41724 if cfg!(any(test, feature = "deny-unknown-attrs")) {
41725 break;
41726 } else {
41727 continue;
41728 }
41729 }
41730 };
41731 return Some(Ok(res));
41732 }
41733 Some(Err(ErrorContext::new(
41734 "OpDestroyflowtableDoRequest",
41735 r#type.and_then(|t| OpDestroyflowtableDoRequest::attr_from_type(t)),
41736 self.orig_loc,
41737 self.buf.as_ptr().wrapping_add(pos) as usize,
41738 )))
41739 }
41740}
41741impl<'a> std::fmt::Debug for IterableOpDestroyflowtableDoRequest<'_> {
41742 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41743 let mut fmt = f.debug_struct("OpDestroyflowtableDoRequest");
41744 for attr in self.clone() {
41745 let attr = match attr {
41746 Ok(a) => a,
41747 Err(err) => {
41748 fmt.finish()?;
41749 f.write_str("Err(")?;
41750 err.fmt(f)?;
41751 return f.write_str(")");
41752 }
41753 };
41754 match attr {
41755 OpDestroyflowtableDoRequest::Table(val) => fmt.field("Table", &val),
41756 OpDestroyflowtableDoRequest::Name(val) => fmt.field("Name", &val),
41757 OpDestroyflowtableDoRequest::Hook(val) => fmt.field("Hook", &val),
41758 OpDestroyflowtableDoRequest::Handle(val) => fmt.field("Handle", &val),
41759 };
41760 }
41761 fmt.finish()
41762 }
41763}
41764impl IterableOpDestroyflowtableDoRequest<'_> {
41765 pub fn lookup_attr(
41766 &self,
41767 offset: usize,
41768 missing_type: Option<u16>,
41769 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
41770 let mut stack = Vec::new();
41771 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
41772 if cur == offset + PushNfgenmsg::len() {
41773 stack.push(("OpDestroyflowtableDoRequest", offset));
41774 return (
41775 stack,
41776 missing_type.and_then(|t| OpDestroyflowtableDoRequest::attr_from_type(t)),
41777 );
41778 }
41779 if cur > offset || cur + self.buf.len() < offset {
41780 return (stack, None);
41781 }
41782 let mut attrs = self.clone();
41783 let mut last_off = cur + attrs.pos;
41784 let mut missing = None;
41785 while let Some(attr) = attrs.next() {
41786 let Ok(attr) = attr else { break };
41787 match attr {
41788 OpDestroyflowtableDoRequest::Table(val) => {
41789 if last_off == offset {
41790 stack.push(("Table", last_off));
41791 break;
41792 }
41793 }
41794 OpDestroyflowtableDoRequest::Name(val) => {
41795 if last_off == offset {
41796 stack.push(("Name", last_off));
41797 break;
41798 }
41799 }
41800 OpDestroyflowtableDoRequest::Hook(val) => {
41801 (stack, missing) = val.lookup_attr(offset, missing_type);
41802 if !stack.is_empty() {
41803 break;
41804 }
41805 }
41806 OpDestroyflowtableDoRequest::Handle(val) => {
41807 if last_off == offset {
41808 stack.push(("Handle", last_off));
41809 break;
41810 }
41811 }
41812 _ => {}
41813 };
41814 last_off = cur + attrs.pos;
41815 }
41816 if !stack.is_empty() {
41817 stack.push(("OpDestroyflowtableDoRequest", cur));
41818 }
41819 (stack, missing)
41820 }
41821}
41822#[doc = "Delete an existing flow table with destroy semantics."]
41823pub struct PushOpDestroyflowtableDoReply<Prev: Rec> {
41824 pub(crate) prev: Option<Prev>,
41825 pub(crate) header_offset: Option<usize>,
41826}
41827impl<Prev: Rec> Rec for PushOpDestroyflowtableDoReply<Prev> {
41828 fn as_rec_mut(&mut self) -> &mut Vec<u8> {
41829 self.prev.as_mut().unwrap().as_rec_mut()
41830 }
41831}
41832impl<Prev: Rec> PushOpDestroyflowtableDoReply<Prev> {
41833 pub fn new(mut prev: Prev, header: &PushNfgenmsg) -> Self {
41834 Self::write_header(&mut prev, header);
41835 Self::new_without_header(prev)
41836 }
41837 fn new_without_header(prev: Prev) -> Self {
41838 Self {
41839 prev: Some(prev),
41840 header_offset: None,
41841 }
41842 }
41843 fn write_header(prev: &mut Prev, header: &PushNfgenmsg) {
41844 prev.as_rec_mut().extend(header.as_slice());
41845 }
41846 pub fn end_nested(mut self) -> Prev {
41847 let mut prev = self.prev.take().unwrap();
41848 if let Some(header_offset) = &self.header_offset {
41849 finalize_nested_header(prev.as_rec_mut(), *header_offset);
41850 }
41851 prev
41852 }
41853}
41854impl<Prev: Rec> Drop for PushOpDestroyflowtableDoReply<Prev> {
41855 fn drop(&mut self) {
41856 if let Some(prev) = &mut self.prev {
41857 if let Some(header_offset) = &self.header_offset {
41858 finalize_nested_header(prev.as_rec_mut(), *header_offset);
41859 }
41860 }
41861 }
41862}
41863#[doc = "Delete an existing flow table with destroy semantics."]
41864#[derive(Clone)]
41865pub enum OpDestroyflowtableDoReply {}
41866impl<'a> IterableOpDestroyflowtableDoReply<'a> {}
41867impl OpDestroyflowtableDoReply {
41868 pub fn new(buf: &'_ [u8]) -> (PushNfgenmsg, IterableOpDestroyflowtableDoReply<'_>) {
41869 let (header, attrs) = buf.split_at(buf.len().min(PushNfgenmsg::len()));
41870 (
41871 PushNfgenmsg::new_from_slice(header).unwrap_or_default(),
41872 IterableOpDestroyflowtableDoReply::with_loc(attrs, buf.as_ptr() as usize),
41873 )
41874 }
41875 fn attr_from_type(r#type: u16) -> Option<&'static str> {
41876 FlowtableAttrs::attr_from_type(r#type)
41877 }
41878}
41879#[derive(Clone, Copy, Default)]
41880pub struct IterableOpDestroyflowtableDoReply<'a> {
41881 buf: &'a [u8],
41882 pos: usize,
41883 orig_loc: usize,
41884}
41885impl<'a> IterableOpDestroyflowtableDoReply<'a> {
41886 fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
41887 Self {
41888 buf,
41889 pos: 0,
41890 orig_loc,
41891 }
41892 }
41893 pub fn get_buf(&self) -> &'a [u8] {
41894 self.buf
41895 }
41896}
41897impl<'a> Iterator for IterableOpDestroyflowtableDoReply<'a> {
41898 type Item = Result<OpDestroyflowtableDoReply, ErrorContext>;
41899 fn next(&mut self) -> Option<Self::Item> {
41900 if self.buf.len() == self.pos {
41901 return None;
41902 }
41903 let pos = self.pos;
41904 let mut r#type = None;
41905 while let Some((header, next)) = chop_header(self.buf, &mut self.pos) {
41906 r#type = Some(header.r#type);
41907 let res = match header.r#type {
41908 n => {
41909 if cfg!(any(test, feature = "deny-unknown-attrs")) {
41910 break;
41911 } else {
41912 continue;
41913 }
41914 }
41915 };
41916 return Some(Ok(res));
41917 }
41918 Some(Err(ErrorContext::new(
41919 "OpDestroyflowtableDoReply",
41920 r#type.and_then(|t| OpDestroyflowtableDoReply::attr_from_type(t)),
41921 self.orig_loc,
41922 self.buf.as_ptr().wrapping_add(pos) as usize,
41923 )))
41924 }
41925}
41926impl std::fmt::Debug for IterableOpDestroyflowtableDoReply<'_> {
41927 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41928 let mut fmt = f.debug_struct("OpDestroyflowtableDoReply");
41929 for attr in self.clone() {
41930 let attr = match attr {
41931 Ok(a) => a,
41932 Err(err) => {
41933 fmt.finish()?;
41934 f.write_str("Err(")?;
41935 err.fmt(f)?;
41936 return f.write_str(")");
41937 }
41938 };
41939 match attr {};
41940 }
41941 fmt.finish()
41942 }
41943}
41944impl IterableOpDestroyflowtableDoReply<'_> {
41945 pub fn lookup_attr(
41946 &self,
41947 offset: usize,
41948 missing_type: Option<u16>,
41949 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
41950 let mut stack = Vec::new();
41951 let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
41952 if cur == offset + PushNfgenmsg::len() {
41953 stack.push(("OpDestroyflowtableDoReply", offset));
41954 return (
41955 stack,
41956 missing_type.and_then(|t| OpDestroyflowtableDoReply::attr_from_type(t)),
41957 );
41958 }
41959 (stack, None)
41960 }
41961}
41962#[derive(Debug)]
41963pub struct RequestOpDestroyflowtableDoRequest<'r> {
41964 request: Request<'r>,
41965}
41966impl<'r> RequestOpDestroyflowtableDoRequest<'r> {
41967 pub fn new(mut request: Request<'r>, header: &PushNfgenmsg) -> Self {
41968 PushOpDestroyflowtableDoRequest::write_header(&mut request.buf_mut(), header);
41969 Self { request: request }
41970 }
41971 pub fn encode(&mut self) -> PushOpDestroyflowtableDoRequest<&mut Vec<u8>> {
41972 PushOpDestroyflowtableDoRequest::new_without_header(self.request.buf_mut())
41973 }
41974 pub fn into_encoder(self) -> PushOpDestroyflowtableDoRequest<RequestBuf<'r>> {
41975 PushOpDestroyflowtableDoRequest::new_without_header(self.request.buf)
41976 }
41977}
41978impl NetlinkRequest for RequestOpDestroyflowtableDoRequest<'_> {
41979 type ReplyType<'buf> = (PushNfgenmsg, IterableOpDestroyflowtableDoReply<'buf>);
41980 fn protocol(&self) -> Protocol {
41981 Protocol::Raw {
41982 protonum: 12u16,
41983 request_type: 2592u16,
41984 }
41985 }
41986 fn flags(&self) -> u16 {
41987 self.request.flags
41988 }
41989 fn payload(&self) -> &[u8] {
41990 self.request.buf()
41991 }
41992 fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
41993 OpDestroyflowtableDoReply::new(buf)
41994 }
41995 fn lookup(
41996 buf: &[u8],
41997 offset: usize,
41998 missing_type: Option<u16>,
41999 ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
42000 OpDestroyflowtableDoRequest::new(buf)
42001 .1
42002 .lookup_attr(offset, missing_type)
42003 }
42004}
42005#[derive(Debug)]
42006pub struct ChainedFinal<'a> {
42007 inner: Chained<'a>,
42008}
42009#[derive(Debug)]
42010pub struct Chained<'a> {
42011 buf: RequestBuf<'a>,
42012 first_seq: u32,
42013 lookups: Vec<(&'static str, LookupFn)>,
42014 last_header_offset: usize,
42015 last_kind: Option<RequestInfo>,
42016}
42017impl<'a> ChainedFinal<'a> {
42018 pub fn into_chained(self) -> Chained<'a> {
42019 self.inner
42020 }
42021 pub fn buf(&self) -> &Vec<u8> {
42022 self.inner.buf()
42023 }
42024 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
42025 self.inner.buf_mut()
42026 }
42027 fn get_index(&self, seq: u32) -> Option<u32> {
42028 let min = self.inner.first_seq;
42029 let max = min.wrapping_add(self.inner.lookups.len() as u32);
42030 return if min <= max {
42031 (min..max).contains(&seq).then(|| seq - min)
42032 } else if min <= seq {
42033 Some(seq - min)
42034 } else if seq < max {
42035 Some(u32::MAX - min + seq)
42036 } else {
42037 None
42038 };
42039 }
42040}
42041impl crate::traits::NetlinkChained for ChainedFinal<'_> {
42042 fn protonum(&self) -> u16 {
42043 PROTONUM
42044 }
42045 fn payload(&self) -> &[u8] {
42046 self.buf()
42047 }
42048 fn chain_len(&self) -> usize {
42049 self.inner.lookups.len()
42050 }
42051 fn get_index(&self, seq: u32) -> Option<usize> {
42052 self.get_index(seq).map(|n| n as usize)
42053 }
42054 fn name(&self, index: usize) -> &'static str {
42055 self.inner.lookups[index].0
42056 }
42057 fn lookup(&self, index: usize) -> LookupFn {
42058 self.inner.lookups[index].1
42059 }
42060}
42061impl Chained<'static> {
42062 pub fn new(first_seq: u32) -> Self {
42063 Self::new_from_buf(Vec::new(), first_seq)
42064 }
42065 pub fn new_from_buf(buf: Vec<u8>, first_seq: u32) -> Self {
42066 Self {
42067 buf: RequestBuf::Own(buf),
42068 first_seq,
42069 lookups: Vec::new(),
42070 last_header_offset: 0,
42071 last_kind: None,
42072 }
42073 }
42074 pub fn into_buf(self) -> Vec<u8> {
42075 match self.buf {
42076 RequestBuf::Own(buf) => buf,
42077 _ => unreachable!(),
42078 }
42079 }
42080}
42081impl<'a> Chained<'a> {
42082 pub fn new_with_buf(buf: &'a mut Vec<u8>, first_seq: u32) -> Self {
42083 Self {
42084 buf: RequestBuf::Ref(buf),
42085 first_seq,
42086 lookups: Vec::new(),
42087 last_header_offset: 0,
42088 last_kind: None,
42089 }
42090 }
42091 pub fn finalize(mut self) -> ChainedFinal<'a> {
42092 self.update_header();
42093 ChainedFinal { inner: self }
42094 }
42095 pub fn request(&mut self) -> Request<'_> {
42096 self.update_header();
42097 self.last_header_offset = self.buf().len();
42098 self.buf_mut()
42099 .extend_from_slice(PushNlmsghdr::new().as_slice());
42100 let mut request = Request::new_extend(self.buf.buf_mut());
42101 self.last_kind = None;
42102 request.writeback = Some(&mut self.last_kind);
42103 request
42104 }
42105 pub fn buf(&self) -> &Vec<u8> {
42106 self.buf.buf()
42107 }
42108 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
42109 self.buf.buf_mut()
42110 }
42111 fn update_header(&mut self) {
42112 let Some(RequestInfo {
42113 protocol,
42114 flags,
42115 name,
42116 lookup,
42117 }) = self.last_kind
42118 else {
42119 if !self.buf().is_empty() {
42120 assert_eq!(
42121 self.last_header_offset + PushNlmsghdr::len(),
42122 self.buf().len()
42123 );
42124 self.buf.buf_mut().truncate(self.last_header_offset);
42125 }
42126 return;
42127 };
42128 let header_offset = self.last_header_offset;
42129 let request_type = match protocol {
42130 Protocol::Raw { request_type, .. } => request_type,
42131 Protocol::Generic(_) => unreachable!(),
42132 };
42133 let index = self.lookups.len();
42134 let seq = self.first_seq.wrapping_add(index as u32);
42135 self.lookups.push((name, lookup));
42136 let buf = self.buf_mut();
42137 align(buf);
42138 let mut header = PushNlmsghdr::new();
42139 header.set_len((buf.len() - header_offset) as u32);
42140 header.set_type(request_type);
42141 header.set_flags(flags | consts::NLM_F_REQUEST as u16 | consts::NLM_F_ACK as u16);
42142 header.set_seq(seq);
42143 buf[header_offset..(header_offset + 16)].clone_from_slice(header.as_slice());
42144 }
42145}
42146use crate::traits::LookupFn;
42147use crate::utils::RequestBuf;
42148#[derive(Debug)]
42149pub struct Request<'buf> {
42150 buf: RequestBuf<'buf>,
42151 flags: u16,
42152 writeback: Option<&'buf mut Option<RequestInfo>>,
42153}
42154#[allow(unused)]
42155#[derive(Debug, Clone)]
42156pub struct RequestInfo {
42157 protocol: Protocol,
42158 flags: u16,
42159 name: &'static str,
42160 lookup: LookupFn,
42161}
42162impl Request<'static> {
42163 pub fn new() -> Self {
42164 Self::new_from_buf(Vec::new())
42165 }
42166 pub fn new_from_buf(buf: Vec<u8>) -> Self {
42167 Self {
42168 flags: 0,
42169 buf: RequestBuf::Own(buf),
42170 writeback: None,
42171 }
42172 }
42173 pub fn into_buf(self) -> Vec<u8> {
42174 match self.buf {
42175 RequestBuf::Own(buf) => buf,
42176 _ => unreachable!(),
42177 }
42178 }
42179}
42180impl<'buf> Request<'buf> {
42181 pub fn new_with_buf(buf: &'buf mut Vec<u8>) -> Self {
42182 buf.clear();
42183 Self::new_extend(buf)
42184 }
42185 pub fn new_extend(buf: &'buf mut Vec<u8>) -> Self {
42186 Self {
42187 flags: 0,
42188 buf: RequestBuf::Ref(buf),
42189 writeback: None,
42190 }
42191 }
42192 fn do_writeback(&mut self, protocol: Protocol, name: &'static str, lookup: LookupFn) {
42193 let Some(writeback) = &mut self.writeback else {
42194 return;
42195 };
42196 **writeback = Some(RequestInfo {
42197 protocol,
42198 flags: self.flags,
42199 name,
42200 lookup,
42201 })
42202 }
42203 pub fn buf(&self) -> &Vec<u8> {
42204 self.buf.buf()
42205 }
42206 pub fn buf_mut(&mut self) -> &mut Vec<u8> {
42207 self.buf.buf_mut()
42208 }
42209 #[doc = "Set `NLM_F_CREATE` flag"]
42210 pub fn set_create(mut self) -> Self {
42211 self.flags |= consts::NLM_F_CREATE as u16;
42212 self
42213 }
42214 #[doc = "Set `NLM_F_EXCL` flag"]
42215 pub fn set_excl(mut self) -> Self {
42216 self.flags |= consts::NLM_F_EXCL as u16;
42217 self
42218 }
42219 #[doc = "Set `NLM_F_REPLACE` flag"]
42220 pub fn set_replace(mut self) -> Self {
42221 self.flags |= consts::NLM_F_REPLACE as u16;
42222 self
42223 }
42224 #[doc = "Set `NLM_F_CREATE` and `NLM_F_REPLACE` flag"]
42225 pub fn set_change(self) -> Self {
42226 self.set_create().set_replace()
42227 }
42228 #[doc = "Set `NLM_F_APPEND` flag"]
42229 pub fn set_append(mut self) -> Self {
42230 self.flags |= consts::NLM_F_APPEND as u16;
42231 self
42232 }
42233 #[doc = "Set `NLM_F_DUMP` flag"]
42234 fn set_dump(mut self) -> Self {
42235 self.flags |= consts::NLM_F_DUMP as u16;
42236 self
42237 }
42238 pub fn op_getcompat_dump_request(
42239 self,
42240 header: &PushNfgenmsg,
42241 ) -> RequestOpGetcompatDumpRequest<'buf> {
42242 let mut res = RequestOpGetcompatDumpRequest::new(self, header);
42243 res.request.do_writeback(
42244 res.protocol(),
42245 "op-getcompat-dump-request",
42246 RequestOpGetcompatDumpRequest::lookup,
42247 );
42248 res
42249 }
42250 pub fn op_getcompat_do_request(
42251 self,
42252 header: &PushNfgenmsg,
42253 ) -> RequestOpGetcompatDoRequest<'buf> {
42254 let mut res = RequestOpGetcompatDoRequest::new(self, header);
42255 res.request.do_writeback(
42256 res.protocol(),
42257 "op-getcompat-do-request",
42258 RequestOpGetcompatDoRequest::lookup,
42259 );
42260 res
42261 }
42262 pub fn op_batch_begin_do_request(
42263 self,
42264 header: &PushNfgenmsg,
42265 ) -> RequestOpBatchBeginDoRequest<'buf> {
42266 let mut res = RequestOpBatchBeginDoRequest::new(self, header);
42267 res.request.do_writeback(
42268 res.protocol(),
42269 "op-batch-begin-do-request",
42270 RequestOpBatchBeginDoRequest::lookup,
42271 );
42272 res
42273 }
42274 pub fn op_batch_end_do_request(
42275 self,
42276 header: &PushNfgenmsg,
42277 ) -> RequestOpBatchEndDoRequest<'buf> {
42278 let mut res = RequestOpBatchEndDoRequest::new(self, header);
42279 res.request.do_writeback(
42280 res.protocol(),
42281 "op-batch-end-do-request",
42282 RequestOpBatchEndDoRequest::lookup,
42283 );
42284 res
42285 }
42286 pub fn op_newtable_do_request(self, header: &PushNfgenmsg) -> RequestOpNewtableDoRequest<'buf> {
42287 let mut res = RequestOpNewtableDoRequest::new(self, header);
42288 res.request.do_writeback(
42289 res.protocol(),
42290 "op-newtable-do-request",
42291 RequestOpNewtableDoRequest::lookup,
42292 );
42293 res
42294 }
42295 pub fn op_gettable_dump_request(
42296 self,
42297 header: &PushNfgenmsg,
42298 ) -> RequestOpGettableDumpRequest<'buf> {
42299 let mut res = RequestOpGettableDumpRequest::new(self, header);
42300 res.request.do_writeback(
42301 res.protocol(),
42302 "op-gettable-dump-request",
42303 RequestOpGettableDumpRequest::lookup,
42304 );
42305 res
42306 }
42307 pub fn op_gettable_do_request(self, header: &PushNfgenmsg) -> RequestOpGettableDoRequest<'buf> {
42308 let mut res = RequestOpGettableDoRequest::new(self, header);
42309 res.request.do_writeback(
42310 res.protocol(),
42311 "op-gettable-do-request",
42312 RequestOpGettableDoRequest::lookup,
42313 );
42314 res
42315 }
42316 pub fn op_deltable_do_request(self, header: &PushNfgenmsg) -> RequestOpDeltableDoRequest<'buf> {
42317 let mut res = RequestOpDeltableDoRequest::new(self, header);
42318 res.request.do_writeback(
42319 res.protocol(),
42320 "op-deltable-do-request",
42321 RequestOpDeltableDoRequest::lookup,
42322 );
42323 res
42324 }
42325 pub fn op_destroytable_do_request(
42326 self,
42327 header: &PushNfgenmsg,
42328 ) -> RequestOpDestroytableDoRequest<'buf> {
42329 let mut res = RequestOpDestroytableDoRequest::new(self, header);
42330 res.request.do_writeback(
42331 res.protocol(),
42332 "op-destroytable-do-request",
42333 RequestOpDestroytableDoRequest::lookup,
42334 );
42335 res
42336 }
42337 pub fn op_newchain_do_request(self, header: &PushNfgenmsg) -> RequestOpNewchainDoRequest<'buf> {
42338 let mut res = RequestOpNewchainDoRequest::new(self, header);
42339 res.request.do_writeback(
42340 res.protocol(),
42341 "op-newchain-do-request",
42342 RequestOpNewchainDoRequest::lookup,
42343 );
42344 res
42345 }
42346 pub fn op_getchain_dump_request(
42347 self,
42348 header: &PushNfgenmsg,
42349 ) -> RequestOpGetchainDumpRequest<'buf> {
42350 let mut res = RequestOpGetchainDumpRequest::new(self, header);
42351 res.request.do_writeback(
42352 res.protocol(),
42353 "op-getchain-dump-request",
42354 RequestOpGetchainDumpRequest::lookup,
42355 );
42356 res
42357 }
42358 pub fn op_getchain_do_request(self, header: &PushNfgenmsg) -> RequestOpGetchainDoRequest<'buf> {
42359 let mut res = RequestOpGetchainDoRequest::new(self, header);
42360 res.request.do_writeback(
42361 res.protocol(),
42362 "op-getchain-do-request",
42363 RequestOpGetchainDoRequest::lookup,
42364 );
42365 res
42366 }
42367 pub fn op_delchain_do_request(self, header: &PushNfgenmsg) -> RequestOpDelchainDoRequest<'buf> {
42368 let mut res = RequestOpDelchainDoRequest::new(self, header);
42369 res.request.do_writeback(
42370 res.protocol(),
42371 "op-delchain-do-request",
42372 RequestOpDelchainDoRequest::lookup,
42373 );
42374 res
42375 }
42376 pub fn op_destroychain_do_request(
42377 self,
42378 header: &PushNfgenmsg,
42379 ) -> RequestOpDestroychainDoRequest<'buf> {
42380 let mut res = RequestOpDestroychainDoRequest::new(self, header);
42381 res.request.do_writeback(
42382 res.protocol(),
42383 "op-destroychain-do-request",
42384 RequestOpDestroychainDoRequest::lookup,
42385 );
42386 res
42387 }
42388 pub fn op_newrule_do_request(self, header: &PushNfgenmsg) -> RequestOpNewruleDoRequest<'buf> {
42389 let mut res = RequestOpNewruleDoRequest::new(self, header);
42390 res.request.do_writeback(
42391 res.protocol(),
42392 "op-newrule-do-request",
42393 RequestOpNewruleDoRequest::lookup,
42394 );
42395 res
42396 }
42397 pub fn op_getrule_dump_request(
42398 self,
42399 header: &PushNfgenmsg,
42400 ) -> RequestOpGetruleDumpRequest<'buf> {
42401 let mut res = RequestOpGetruleDumpRequest::new(self, header);
42402 res.request.do_writeback(
42403 res.protocol(),
42404 "op-getrule-dump-request",
42405 RequestOpGetruleDumpRequest::lookup,
42406 );
42407 res
42408 }
42409 pub fn op_getrule_do_request(self, header: &PushNfgenmsg) -> RequestOpGetruleDoRequest<'buf> {
42410 let mut res = RequestOpGetruleDoRequest::new(self, header);
42411 res.request.do_writeback(
42412 res.protocol(),
42413 "op-getrule-do-request",
42414 RequestOpGetruleDoRequest::lookup,
42415 );
42416 res
42417 }
42418 pub fn op_getrule_reset_dump_request(
42419 self,
42420 header: &PushNfgenmsg,
42421 ) -> RequestOpGetruleResetDumpRequest<'buf> {
42422 let mut res = RequestOpGetruleResetDumpRequest::new(self, header);
42423 res.request.do_writeback(
42424 res.protocol(),
42425 "op-getrule-reset-dump-request",
42426 RequestOpGetruleResetDumpRequest::lookup,
42427 );
42428 res
42429 }
42430 pub fn op_getrule_reset_do_request(
42431 self,
42432 header: &PushNfgenmsg,
42433 ) -> RequestOpGetruleResetDoRequest<'buf> {
42434 let mut res = RequestOpGetruleResetDoRequest::new(self, header);
42435 res.request.do_writeback(
42436 res.protocol(),
42437 "op-getrule-reset-do-request",
42438 RequestOpGetruleResetDoRequest::lookup,
42439 );
42440 res
42441 }
42442 pub fn op_delrule_do_request(self, header: &PushNfgenmsg) -> RequestOpDelruleDoRequest<'buf> {
42443 let mut res = RequestOpDelruleDoRequest::new(self, header);
42444 res.request.do_writeback(
42445 res.protocol(),
42446 "op-delrule-do-request",
42447 RequestOpDelruleDoRequest::lookup,
42448 );
42449 res
42450 }
42451 pub fn op_destroyrule_do_request(
42452 self,
42453 header: &PushNfgenmsg,
42454 ) -> RequestOpDestroyruleDoRequest<'buf> {
42455 let mut res = RequestOpDestroyruleDoRequest::new(self, header);
42456 res.request.do_writeback(
42457 res.protocol(),
42458 "op-destroyrule-do-request",
42459 RequestOpDestroyruleDoRequest::lookup,
42460 );
42461 res
42462 }
42463 pub fn op_newset_do_request(self, header: &PushNfgenmsg) -> RequestOpNewsetDoRequest<'buf> {
42464 let mut res = RequestOpNewsetDoRequest::new(self, header);
42465 res.request.do_writeback(
42466 res.protocol(),
42467 "op-newset-do-request",
42468 RequestOpNewsetDoRequest::lookup,
42469 );
42470 res
42471 }
42472 pub fn op_getset_dump_request(self, header: &PushNfgenmsg) -> RequestOpGetsetDumpRequest<'buf> {
42473 let mut res = RequestOpGetsetDumpRequest::new(self, header);
42474 res.request.do_writeback(
42475 res.protocol(),
42476 "op-getset-dump-request",
42477 RequestOpGetsetDumpRequest::lookup,
42478 );
42479 res
42480 }
42481 pub fn op_getset_do_request(self, header: &PushNfgenmsg) -> RequestOpGetsetDoRequest<'buf> {
42482 let mut res = RequestOpGetsetDoRequest::new(self, header);
42483 res.request.do_writeback(
42484 res.protocol(),
42485 "op-getset-do-request",
42486 RequestOpGetsetDoRequest::lookup,
42487 );
42488 res
42489 }
42490 pub fn op_delset_do_request(self, header: &PushNfgenmsg) -> RequestOpDelsetDoRequest<'buf> {
42491 let mut res = RequestOpDelsetDoRequest::new(self, header);
42492 res.request.do_writeback(
42493 res.protocol(),
42494 "op-delset-do-request",
42495 RequestOpDelsetDoRequest::lookup,
42496 );
42497 res
42498 }
42499 pub fn op_destroyset_do_request(
42500 self,
42501 header: &PushNfgenmsg,
42502 ) -> RequestOpDestroysetDoRequest<'buf> {
42503 let mut res = RequestOpDestroysetDoRequest::new(self, header);
42504 res.request.do_writeback(
42505 res.protocol(),
42506 "op-destroyset-do-request",
42507 RequestOpDestroysetDoRequest::lookup,
42508 );
42509 res
42510 }
42511 pub fn op_newsetelem_do_request(
42512 self,
42513 header: &PushNfgenmsg,
42514 ) -> RequestOpNewsetelemDoRequest<'buf> {
42515 let mut res = RequestOpNewsetelemDoRequest::new(self, header);
42516 res.request.do_writeback(
42517 res.protocol(),
42518 "op-newsetelem-do-request",
42519 RequestOpNewsetelemDoRequest::lookup,
42520 );
42521 res
42522 }
42523 pub fn op_getsetelem_dump_request(
42524 self,
42525 header: &PushNfgenmsg,
42526 ) -> RequestOpGetsetelemDumpRequest<'buf> {
42527 let mut res = RequestOpGetsetelemDumpRequest::new(self, header);
42528 res.request.do_writeback(
42529 res.protocol(),
42530 "op-getsetelem-dump-request",
42531 RequestOpGetsetelemDumpRequest::lookup,
42532 );
42533 res
42534 }
42535 pub fn op_getsetelem_do_request(
42536 self,
42537 header: &PushNfgenmsg,
42538 ) -> RequestOpGetsetelemDoRequest<'buf> {
42539 let mut res = RequestOpGetsetelemDoRequest::new(self, header);
42540 res.request.do_writeback(
42541 res.protocol(),
42542 "op-getsetelem-do-request",
42543 RequestOpGetsetelemDoRequest::lookup,
42544 );
42545 res
42546 }
42547 pub fn op_getsetelem_reset_dump_request(
42548 self,
42549 header: &PushNfgenmsg,
42550 ) -> RequestOpGetsetelemResetDumpRequest<'buf> {
42551 let mut res = RequestOpGetsetelemResetDumpRequest::new(self, header);
42552 res.request.do_writeback(
42553 res.protocol(),
42554 "op-getsetelem-reset-dump-request",
42555 RequestOpGetsetelemResetDumpRequest::lookup,
42556 );
42557 res
42558 }
42559 pub fn op_getsetelem_reset_do_request(
42560 self,
42561 header: &PushNfgenmsg,
42562 ) -> RequestOpGetsetelemResetDoRequest<'buf> {
42563 let mut res = RequestOpGetsetelemResetDoRequest::new(self, header);
42564 res.request.do_writeback(
42565 res.protocol(),
42566 "op-getsetelem-reset-do-request",
42567 RequestOpGetsetelemResetDoRequest::lookup,
42568 );
42569 res
42570 }
42571 pub fn op_delsetelem_do_request(
42572 self,
42573 header: &PushNfgenmsg,
42574 ) -> RequestOpDelsetelemDoRequest<'buf> {
42575 let mut res = RequestOpDelsetelemDoRequest::new(self, header);
42576 res.request.do_writeback(
42577 res.protocol(),
42578 "op-delsetelem-do-request",
42579 RequestOpDelsetelemDoRequest::lookup,
42580 );
42581 res
42582 }
42583 pub fn op_destroysetelem_do_request(
42584 self,
42585 header: &PushNfgenmsg,
42586 ) -> RequestOpDestroysetelemDoRequest<'buf> {
42587 let mut res = RequestOpDestroysetelemDoRequest::new(self, header);
42588 res.request.do_writeback(
42589 res.protocol(),
42590 "op-destroysetelem-do-request",
42591 RequestOpDestroysetelemDoRequest::lookup,
42592 );
42593 res
42594 }
42595 pub fn op_getgen_dump_request(self, header: &PushNfgenmsg) -> RequestOpGetgenDumpRequest<'buf> {
42596 let mut res = RequestOpGetgenDumpRequest::new(self, header);
42597 res.request.do_writeback(
42598 res.protocol(),
42599 "op-getgen-dump-request",
42600 RequestOpGetgenDumpRequest::lookup,
42601 );
42602 res
42603 }
42604 pub fn op_getgen_do_request(self, header: &PushNfgenmsg) -> RequestOpGetgenDoRequest<'buf> {
42605 let mut res = RequestOpGetgenDoRequest::new(self, header);
42606 res.request.do_writeback(
42607 res.protocol(),
42608 "op-getgen-do-request",
42609 RequestOpGetgenDoRequest::lookup,
42610 );
42611 res
42612 }
42613 pub fn op_newobj_do_request(self, header: &PushNfgenmsg) -> RequestOpNewobjDoRequest<'buf> {
42614 let mut res = RequestOpNewobjDoRequest::new(self, header);
42615 res.request.do_writeback(
42616 res.protocol(),
42617 "op-newobj-do-request",
42618 RequestOpNewobjDoRequest::lookup,
42619 );
42620 res
42621 }
42622 pub fn op_getobj_dump_request(self, header: &PushNfgenmsg) -> RequestOpGetobjDumpRequest<'buf> {
42623 let mut res = RequestOpGetobjDumpRequest::new(self, header);
42624 res.request.do_writeback(
42625 res.protocol(),
42626 "op-getobj-dump-request",
42627 RequestOpGetobjDumpRequest::lookup,
42628 );
42629 res
42630 }
42631 pub fn op_getobj_do_request(self, header: &PushNfgenmsg) -> RequestOpGetobjDoRequest<'buf> {
42632 let mut res = RequestOpGetobjDoRequest::new(self, header);
42633 res.request.do_writeback(
42634 res.protocol(),
42635 "op-getobj-do-request",
42636 RequestOpGetobjDoRequest::lookup,
42637 );
42638 res
42639 }
42640 pub fn op_delobj_do_request(self, header: &PushNfgenmsg) -> RequestOpDelobjDoRequest<'buf> {
42641 let mut res = RequestOpDelobjDoRequest::new(self, header);
42642 res.request.do_writeback(
42643 res.protocol(),
42644 "op-delobj-do-request",
42645 RequestOpDelobjDoRequest::lookup,
42646 );
42647 res
42648 }
42649 pub fn op_destroyobj_do_request(
42650 self,
42651 header: &PushNfgenmsg,
42652 ) -> RequestOpDestroyobjDoRequest<'buf> {
42653 let mut res = RequestOpDestroyobjDoRequest::new(self, header);
42654 res.request.do_writeback(
42655 res.protocol(),
42656 "op-destroyobj-do-request",
42657 RequestOpDestroyobjDoRequest::lookup,
42658 );
42659 res
42660 }
42661 pub fn op_newflowtable_do_request(
42662 self,
42663 header: &PushNfgenmsg,
42664 ) -> RequestOpNewflowtableDoRequest<'buf> {
42665 let mut res = RequestOpNewflowtableDoRequest::new(self, header);
42666 res.request.do_writeback(
42667 res.protocol(),
42668 "op-newflowtable-do-request",
42669 RequestOpNewflowtableDoRequest::lookup,
42670 );
42671 res
42672 }
42673 pub fn op_getflowtable_dump_request(
42674 self,
42675 header: &PushNfgenmsg,
42676 ) -> RequestOpGetflowtableDumpRequest<'buf> {
42677 let mut res = RequestOpGetflowtableDumpRequest::new(self, header);
42678 res.request.do_writeback(
42679 res.protocol(),
42680 "op-getflowtable-dump-request",
42681 RequestOpGetflowtableDumpRequest::lookup,
42682 );
42683 res
42684 }
42685 pub fn op_getflowtable_do_request(
42686 self,
42687 header: &PushNfgenmsg,
42688 ) -> RequestOpGetflowtableDoRequest<'buf> {
42689 let mut res = RequestOpGetflowtableDoRequest::new(self, header);
42690 res.request.do_writeback(
42691 res.protocol(),
42692 "op-getflowtable-do-request",
42693 RequestOpGetflowtableDoRequest::lookup,
42694 );
42695 res
42696 }
42697 pub fn op_delflowtable_do_request(
42698 self,
42699 header: &PushNfgenmsg,
42700 ) -> RequestOpDelflowtableDoRequest<'buf> {
42701 let mut res = RequestOpDelflowtableDoRequest::new(self, header);
42702 res.request.do_writeback(
42703 res.protocol(),
42704 "op-delflowtable-do-request",
42705 RequestOpDelflowtableDoRequest::lookup,
42706 );
42707 res
42708 }
42709 pub fn op_destroyflowtable_do_request(
42710 self,
42711 header: &PushNfgenmsg,
42712 ) -> RequestOpDestroyflowtableDoRequest<'buf> {
42713 let mut res = RequestOpDestroyflowtableDoRequest::new(self, header);
42714 res.request.do_writeback(
42715 res.protocol(),
42716 "op-destroyflowtable-do-request",
42717 RequestOpDestroyflowtableDoRequest::lookup,
42718 );
42719 res
42720 }
42721}