Skip to main content

netlink_bindings/ovpn/
mod.rs

1#![doc = "Netlink protocol to control OpenVPN network devices"]
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::{BuiltinBitfield32, BuiltinNfgenmsg, Nlmsghdr, PushDummy};
11use crate::{
12    consts,
13    traits::{NetlinkRequest, Protocol},
14    utils::*,
15};
16pub const PROTONAME: &str = "ovpn";
17pub const PROTONAME_CSTR: &CStr = c"ovpn";
18pub const NONCE_TAIL_SIZE: u64 = 8u64;
19#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
20#[derive(Debug, Clone, Copy)]
21pub enum CipherAlg {
22    None = 0,
23    AesGcm = 1,
24    Chacha20Poly1305 = 2,
25}
26impl CipherAlg {
27    pub fn from_value(value: u64) -> Option<Self> {
28        Some(match value {
29            0 => Self::None,
30            1 => Self::AesGcm,
31            2 => Self::Chacha20Poly1305,
32            _ => return None,
33        })
34    }
35}
36#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
37#[derive(Debug, Clone, Copy)]
38pub enum DelPeerReason {
39    Teardown = 0,
40    Userspace = 1,
41    Expired = 2,
42    TransportError = 3,
43    TransportDisconnect = 4,
44}
45impl DelPeerReason {
46    pub fn from_value(value: u64) -> Option<Self> {
47        Some(match value {
48            0 => Self::Teardown,
49            1 => Self::Userspace,
50            2 => Self::Expired,
51            3 => Self::TransportError,
52            4 => Self::TransportDisconnect,
53            _ => return None,
54        })
55    }
56}
57#[doc = "Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)"]
58#[derive(Debug, Clone, Copy)]
59pub enum KeySlot {
60    Primary = 0,
61    Secondary = 1,
62}
63impl KeySlot {
64    pub fn from_value(value: u64) -> Option<Self> {
65        Some(match value {
66            0 => Self::Primary,
67            1 => Self::Secondary,
68            _ => return None,
69        })
70    }
71}
72#[derive(Clone)]
73pub enum Peer<'a> {
74    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
75    Id(u32),
76    #[doc = "The remote IPv4 address of the peer"]
77    RemoteIpv4(std::net::Ipv4Addr),
78    #[doc = "The remote IPv6 address of the peer"]
79    RemoteIpv6(&'a [u8]),
80    #[doc = "The scope id of the remote IPv6 address of the peer (RFC2553)"]
81    RemoteIpv6ScopeId(u32),
82    #[doc = "The remote port of the peer"]
83    RemotePort(u16),
84    #[doc = "The socket to be used to communicate with the peer"]
85    Socket(u32),
86    #[doc = "The ID of the netns the socket assigned to this peer lives in"]
87    SocketNetnsid(i32),
88    #[doc = "The IPv4 address assigned to the peer by the server"]
89    VpnIpv4(std::net::Ipv4Addr),
90    #[doc = "The IPv6 address assigned to the peer by the server"]
91    VpnIpv6(&'a [u8]),
92    #[doc = "The local IPv4 to be used to send packets to the peer (UDP only)"]
93    LocalIpv4(std::net::Ipv4Addr),
94    #[doc = "The local IPv6 to be used to send packets to the peer (UDP only)"]
95    LocalIpv6(&'a [u8]),
96    #[doc = "The local port to be used to send packets to the peer (UDP only)"]
97    LocalPort(u16),
98    #[doc = "The number of seconds after which a keep alive message is sent to the peer"]
99    KeepaliveInterval(u32),
100    #[doc = "The number of seconds from the last activity after which the peer is assumed dead"]
101    KeepaliveTimeout(u32),
102    #[doc = "The reason why a peer was deleted\nAssociated type: [`DelPeerReason`] (enum)"]
103    DelReason(u32),
104    #[doc = "Number of bytes received over the tunnel"]
105    VpnRxBytes(u32),
106    #[doc = "Number of bytes transmitted over the tunnel"]
107    VpnTxBytes(u32),
108    #[doc = "Number of packets received over the tunnel"]
109    VpnRxPackets(u32),
110    #[doc = "Number of packets transmitted over the tunnel"]
111    VpnTxPackets(u32),
112    #[doc = "Number of bytes received at the transport level"]
113    LinkRxBytes(u32),
114    #[doc = "Number of bytes transmitted at the transport level"]
115    LinkTxBytes(u32),
116    #[doc = "Number of packets received at the transport level"]
117    LinkRxPackets(u32),
118    #[doc = "Number of packets transmitted at the transport level"]
119    LinkTxPackets(u32),
120}
121impl<'a> IterablePeer<'a> {
122    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
123    pub fn get_id(&self) -> Result<u32, ErrorContext> {
124        let mut iter = self.clone();
125        iter.pos = 0;
126        for attr in iter {
127            if let Peer::Id(val) = attr? {
128                return Ok(val);
129            }
130        }
131        Err(ErrorContext::new_missing(
132            "Peer",
133            "Id",
134            self.orig_loc,
135            self.buf.as_ptr() as usize,
136        ))
137    }
138    #[doc = "The remote IPv4 address of the peer"]
139    pub fn get_remote_ipv4(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
140        let mut iter = self.clone();
141        iter.pos = 0;
142        for attr in iter {
143            if let Peer::RemoteIpv4(val) = attr? {
144                return Ok(val);
145            }
146        }
147        Err(ErrorContext::new_missing(
148            "Peer",
149            "RemoteIpv4",
150            self.orig_loc,
151            self.buf.as_ptr() as usize,
152        ))
153    }
154    #[doc = "The remote IPv6 address of the peer"]
155    pub fn get_remote_ipv6(&self) -> Result<&'a [u8], ErrorContext> {
156        let mut iter = self.clone();
157        iter.pos = 0;
158        for attr in iter {
159            if let Peer::RemoteIpv6(val) = attr? {
160                return Ok(val);
161            }
162        }
163        Err(ErrorContext::new_missing(
164            "Peer",
165            "RemoteIpv6",
166            self.orig_loc,
167            self.buf.as_ptr() as usize,
168        ))
169    }
170    #[doc = "The scope id of the remote IPv6 address of the peer (RFC2553)"]
171    pub fn get_remote_ipv6_scope_id(&self) -> Result<u32, ErrorContext> {
172        let mut iter = self.clone();
173        iter.pos = 0;
174        for attr in iter {
175            if let Peer::RemoteIpv6ScopeId(val) = attr? {
176                return Ok(val);
177            }
178        }
179        Err(ErrorContext::new_missing(
180            "Peer",
181            "RemoteIpv6ScopeId",
182            self.orig_loc,
183            self.buf.as_ptr() as usize,
184        ))
185    }
186    #[doc = "The remote port of the peer"]
187    pub fn get_remote_port(&self) -> Result<u16, ErrorContext> {
188        let mut iter = self.clone();
189        iter.pos = 0;
190        for attr in iter {
191            if let Peer::RemotePort(val) = attr? {
192                return Ok(val);
193            }
194        }
195        Err(ErrorContext::new_missing(
196            "Peer",
197            "RemotePort",
198            self.orig_loc,
199            self.buf.as_ptr() as usize,
200        ))
201    }
202    #[doc = "The socket to be used to communicate with the peer"]
203    pub fn get_socket(&self) -> Result<u32, ErrorContext> {
204        let mut iter = self.clone();
205        iter.pos = 0;
206        for attr in iter {
207            if let Peer::Socket(val) = attr? {
208                return Ok(val);
209            }
210        }
211        Err(ErrorContext::new_missing(
212            "Peer",
213            "Socket",
214            self.orig_loc,
215            self.buf.as_ptr() as usize,
216        ))
217    }
218    #[doc = "The ID of the netns the socket assigned to this peer lives in"]
219    pub fn get_socket_netnsid(&self) -> Result<i32, ErrorContext> {
220        let mut iter = self.clone();
221        iter.pos = 0;
222        for attr in iter {
223            if let Peer::SocketNetnsid(val) = attr? {
224                return Ok(val);
225            }
226        }
227        Err(ErrorContext::new_missing(
228            "Peer",
229            "SocketNetnsid",
230            self.orig_loc,
231            self.buf.as_ptr() as usize,
232        ))
233    }
234    #[doc = "The IPv4 address assigned to the peer by the server"]
235    pub fn get_vpn_ipv4(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
236        let mut iter = self.clone();
237        iter.pos = 0;
238        for attr in iter {
239            if let Peer::VpnIpv4(val) = attr? {
240                return Ok(val);
241            }
242        }
243        Err(ErrorContext::new_missing(
244            "Peer",
245            "VpnIpv4",
246            self.orig_loc,
247            self.buf.as_ptr() as usize,
248        ))
249    }
250    #[doc = "The IPv6 address assigned to the peer by the server"]
251    pub fn get_vpn_ipv6(&self) -> Result<&'a [u8], ErrorContext> {
252        let mut iter = self.clone();
253        iter.pos = 0;
254        for attr in iter {
255            if let Peer::VpnIpv6(val) = attr? {
256                return Ok(val);
257            }
258        }
259        Err(ErrorContext::new_missing(
260            "Peer",
261            "VpnIpv6",
262            self.orig_loc,
263            self.buf.as_ptr() as usize,
264        ))
265    }
266    #[doc = "The local IPv4 to be used to send packets to the peer (UDP only)"]
267    pub fn get_local_ipv4(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
268        let mut iter = self.clone();
269        iter.pos = 0;
270        for attr in iter {
271            if let Peer::LocalIpv4(val) = attr? {
272                return Ok(val);
273            }
274        }
275        Err(ErrorContext::new_missing(
276            "Peer",
277            "LocalIpv4",
278            self.orig_loc,
279            self.buf.as_ptr() as usize,
280        ))
281    }
282    #[doc = "The local IPv6 to be used to send packets to the peer (UDP only)"]
283    pub fn get_local_ipv6(&self) -> Result<&'a [u8], ErrorContext> {
284        let mut iter = self.clone();
285        iter.pos = 0;
286        for attr in iter {
287            if let Peer::LocalIpv6(val) = attr? {
288                return Ok(val);
289            }
290        }
291        Err(ErrorContext::new_missing(
292            "Peer",
293            "LocalIpv6",
294            self.orig_loc,
295            self.buf.as_ptr() as usize,
296        ))
297    }
298    #[doc = "The local port to be used to send packets to the peer (UDP only)"]
299    pub fn get_local_port(&self) -> Result<u16, ErrorContext> {
300        let mut iter = self.clone();
301        iter.pos = 0;
302        for attr in iter {
303            if let Peer::LocalPort(val) = attr? {
304                return Ok(val);
305            }
306        }
307        Err(ErrorContext::new_missing(
308            "Peer",
309            "LocalPort",
310            self.orig_loc,
311            self.buf.as_ptr() as usize,
312        ))
313    }
314    #[doc = "The number of seconds after which a keep alive message is sent to the peer"]
315    pub fn get_keepalive_interval(&self) -> Result<u32, ErrorContext> {
316        let mut iter = self.clone();
317        iter.pos = 0;
318        for attr in iter {
319            if let Peer::KeepaliveInterval(val) = attr? {
320                return Ok(val);
321            }
322        }
323        Err(ErrorContext::new_missing(
324            "Peer",
325            "KeepaliveInterval",
326            self.orig_loc,
327            self.buf.as_ptr() as usize,
328        ))
329    }
330    #[doc = "The number of seconds from the last activity after which the peer is assumed dead"]
331    pub fn get_keepalive_timeout(&self) -> Result<u32, ErrorContext> {
332        let mut iter = self.clone();
333        iter.pos = 0;
334        for attr in iter {
335            if let Peer::KeepaliveTimeout(val) = attr? {
336                return Ok(val);
337            }
338        }
339        Err(ErrorContext::new_missing(
340            "Peer",
341            "KeepaliveTimeout",
342            self.orig_loc,
343            self.buf.as_ptr() as usize,
344        ))
345    }
346    #[doc = "The reason why a peer was deleted\nAssociated type: [`DelPeerReason`] (enum)"]
347    pub fn get_del_reason(&self) -> Result<u32, ErrorContext> {
348        let mut iter = self.clone();
349        iter.pos = 0;
350        for attr in iter {
351            if let Peer::DelReason(val) = attr? {
352                return Ok(val);
353            }
354        }
355        Err(ErrorContext::new_missing(
356            "Peer",
357            "DelReason",
358            self.orig_loc,
359            self.buf.as_ptr() as usize,
360        ))
361    }
362    #[doc = "Number of bytes received over the tunnel"]
363    pub fn get_vpn_rx_bytes(&self) -> Result<u32, ErrorContext> {
364        let mut iter = self.clone();
365        iter.pos = 0;
366        for attr in iter {
367            if let Peer::VpnRxBytes(val) = attr? {
368                return Ok(val);
369            }
370        }
371        Err(ErrorContext::new_missing(
372            "Peer",
373            "VpnRxBytes",
374            self.orig_loc,
375            self.buf.as_ptr() as usize,
376        ))
377    }
378    #[doc = "Number of bytes transmitted over the tunnel"]
379    pub fn get_vpn_tx_bytes(&self) -> Result<u32, ErrorContext> {
380        let mut iter = self.clone();
381        iter.pos = 0;
382        for attr in iter {
383            if let Peer::VpnTxBytes(val) = attr? {
384                return Ok(val);
385            }
386        }
387        Err(ErrorContext::new_missing(
388            "Peer",
389            "VpnTxBytes",
390            self.orig_loc,
391            self.buf.as_ptr() as usize,
392        ))
393    }
394    #[doc = "Number of packets received over the tunnel"]
395    pub fn get_vpn_rx_packets(&self) -> Result<u32, ErrorContext> {
396        let mut iter = self.clone();
397        iter.pos = 0;
398        for attr in iter {
399            if let Peer::VpnRxPackets(val) = attr? {
400                return Ok(val);
401            }
402        }
403        Err(ErrorContext::new_missing(
404            "Peer",
405            "VpnRxPackets",
406            self.orig_loc,
407            self.buf.as_ptr() as usize,
408        ))
409    }
410    #[doc = "Number of packets transmitted over the tunnel"]
411    pub fn get_vpn_tx_packets(&self) -> Result<u32, ErrorContext> {
412        let mut iter = self.clone();
413        iter.pos = 0;
414        for attr in iter {
415            if let Peer::VpnTxPackets(val) = attr? {
416                return Ok(val);
417            }
418        }
419        Err(ErrorContext::new_missing(
420            "Peer",
421            "VpnTxPackets",
422            self.orig_loc,
423            self.buf.as_ptr() as usize,
424        ))
425    }
426    #[doc = "Number of bytes received at the transport level"]
427    pub fn get_link_rx_bytes(&self) -> Result<u32, ErrorContext> {
428        let mut iter = self.clone();
429        iter.pos = 0;
430        for attr in iter {
431            if let Peer::LinkRxBytes(val) = attr? {
432                return Ok(val);
433            }
434        }
435        Err(ErrorContext::new_missing(
436            "Peer",
437            "LinkRxBytes",
438            self.orig_loc,
439            self.buf.as_ptr() as usize,
440        ))
441    }
442    #[doc = "Number of bytes transmitted at the transport level"]
443    pub fn get_link_tx_bytes(&self) -> Result<u32, ErrorContext> {
444        let mut iter = self.clone();
445        iter.pos = 0;
446        for attr in iter {
447            if let Peer::LinkTxBytes(val) = attr? {
448                return Ok(val);
449            }
450        }
451        Err(ErrorContext::new_missing(
452            "Peer",
453            "LinkTxBytes",
454            self.orig_loc,
455            self.buf.as_ptr() as usize,
456        ))
457    }
458    #[doc = "Number of packets received at the transport level"]
459    pub fn get_link_rx_packets(&self) -> Result<u32, ErrorContext> {
460        let mut iter = self.clone();
461        iter.pos = 0;
462        for attr in iter {
463            if let Peer::LinkRxPackets(val) = attr? {
464                return Ok(val);
465            }
466        }
467        Err(ErrorContext::new_missing(
468            "Peer",
469            "LinkRxPackets",
470            self.orig_loc,
471            self.buf.as_ptr() as usize,
472        ))
473    }
474    #[doc = "Number of packets transmitted at the transport level"]
475    pub fn get_link_tx_packets(&self) -> Result<u32, ErrorContext> {
476        let mut iter = self.clone();
477        iter.pos = 0;
478        for attr in iter {
479            if let Peer::LinkTxPackets(val) = attr? {
480                return Ok(val);
481            }
482        }
483        Err(ErrorContext::new_missing(
484            "Peer",
485            "LinkTxPackets",
486            self.orig_loc,
487            self.buf.as_ptr() as usize,
488        ))
489    }
490}
491impl Peer<'_> {
492    pub fn new<'a>(buf: &'a [u8]) -> IterablePeer<'a> {
493        IterablePeer::with_loc(buf, buf.as_ptr() as usize)
494    }
495    fn attr_from_type(r#type: u16) -> Option<&'static str> {
496        let res = match r#type {
497            1u16 => "Id",
498            2u16 => "RemoteIpv4",
499            3u16 => "RemoteIpv6",
500            4u16 => "RemoteIpv6ScopeId",
501            5u16 => "RemotePort",
502            6u16 => "Socket",
503            7u16 => "SocketNetnsid",
504            8u16 => "VpnIpv4",
505            9u16 => "VpnIpv6",
506            10u16 => "LocalIpv4",
507            11u16 => "LocalIpv6",
508            12u16 => "LocalPort",
509            13u16 => "KeepaliveInterval",
510            14u16 => "KeepaliveTimeout",
511            15u16 => "DelReason",
512            16u16 => "VpnRxBytes",
513            17u16 => "VpnTxBytes",
514            18u16 => "VpnRxPackets",
515            19u16 => "VpnTxPackets",
516            20u16 => "LinkRxBytes",
517            21u16 => "LinkTxBytes",
518            22u16 => "LinkRxPackets",
519            23u16 => "LinkTxPackets",
520            _ => return None,
521        };
522        Some(res)
523    }
524}
525#[derive(Clone, Copy, Default)]
526pub struct IterablePeer<'a> {
527    buf: &'a [u8],
528    pos: usize,
529    orig_loc: usize,
530}
531impl<'a> IterablePeer<'a> {
532    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
533        Self {
534            buf,
535            pos: 0,
536            orig_loc,
537        }
538    }
539    pub fn get_buf(&self) -> &'a [u8] {
540        self.buf
541    }
542}
543impl<'a> Iterator for IterablePeer<'a> {
544    type Item = Result<Peer<'a>, ErrorContext>;
545    fn next(&mut self) -> Option<Self::Item> {
546        let pos = self.pos;
547        let mut r#type;
548        loop {
549            r#type = None;
550            if self.buf.len() == self.pos {
551                return None;
552            }
553            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
554                break;
555            };
556            r#type = Some(header.r#type);
557            let res = match header.r#type {
558                1u16 => Peer::Id({
559                    let res = parse_u32(next);
560                    let Some(val) = res else { break };
561                    val
562                }),
563                2u16 => Peer::RemoteIpv4({
564                    let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
565                    let Some(val) = res else { break };
566                    val
567                }),
568                3u16 => Peer::RemoteIpv6({
569                    let res = Some(next);
570                    let Some(val) = res else { break };
571                    val
572                }),
573                4u16 => Peer::RemoteIpv6ScopeId({
574                    let res = parse_u32(next);
575                    let Some(val) = res else { break };
576                    val
577                }),
578                5u16 => Peer::RemotePort({
579                    let res = parse_be_u16(next);
580                    let Some(val) = res else { break };
581                    val
582                }),
583                6u16 => Peer::Socket({
584                    let res = parse_u32(next);
585                    let Some(val) = res else { break };
586                    val
587                }),
588                7u16 => Peer::SocketNetnsid({
589                    let res = parse_i32(next);
590                    let Some(val) = res else { break };
591                    val
592                }),
593                8u16 => Peer::VpnIpv4({
594                    let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
595                    let Some(val) = res else { break };
596                    val
597                }),
598                9u16 => Peer::VpnIpv6({
599                    let res = Some(next);
600                    let Some(val) = res else { break };
601                    val
602                }),
603                10u16 => Peer::LocalIpv4({
604                    let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
605                    let Some(val) = res else { break };
606                    val
607                }),
608                11u16 => Peer::LocalIpv6({
609                    let res = Some(next);
610                    let Some(val) = res else { break };
611                    val
612                }),
613                12u16 => Peer::LocalPort({
614                    let res = parse_be_u16(next);
615                    let Some(val) = res else { break };
616                    val
617                }),
618                13u16 => Peer::KeepaliveInterval({
619                    let res = parse_u32(next);
620                    let Some(val) = res else { break };
621                    val
622                }),
623                14u16 => Peer::KeepaliveTimeout({
624                    let res = parse_u32(next);
625                    let Some(val) = res else { break };
626                    val
627                }),
628                15u16 => Peer::DelReason({
629                    let res = parse_u32(next);
630                    let Some(val) = res else { break };
631                    val
632                }),
633                16u16 => Peer::VpnRxBytes({
634                    let res = parse_u32(next);
635                    let Some(val) = res else { break };
636                    val
637                }),
638                17u16 => Peer::VpnTxBytes({
639                    let res = parse_u32(next);
640                    let Some(val) = res else { break };
641                    val
642                }),
643                18u16 => Peer::VpnRxPackets({
644                    let res = parse_u32(next);
645                    let Some(val) = res else { break };
646                    val
647                }),
648                19u16 => Peer::VpnTxPackets({
649                    let res = parse_u32(next);
650                    let Some(val) = res else { break };
651                    val
652                }),
653                20u16 => Peer::LinkRxBytes({
654                    let res = parse_u32(next);
655                    let Some(val) = res else { break };
656                    val
657                }),
658                21u16 => Peer::LinkTxBytes({
659                    let res = parse_u32(next);
660                    let Some(val) = res else { break };
661                    val
662                }),
663                22u16 => Peer::LinkRxPackets({
664                    let res = parse_u32(next);
665                    let Some(val) = res else { break };
666                    val
667                }),
668                23u16 => Peer::LinkTxPackets({
669                    let res = parse_u32(next);
670                    let Some(val) = res else { break };
671                    val
672                }),
673                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
674                n => continue,
675            };
676            return Some(Ok(res));
677        }
678        Some(Err(ErrorContext::new(
679            "Peer",
680            r#type.and_then(|t| Peer::attr_from_type(t)),
681            self.orig_loc,
682            self.buf.as_ptr().wrapping_add(pos) as usize,
683        )))
684    }
685}
686impl<'a> std::fmt::Debug for IterablePeer<'_> {
687    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
688        let mut fmt = f.debug_struct("Peer");
689        for attr in self.clone() {
690            let attr = match attr {
691                Ok(a) => a,
692                Err(err) => {
693                    fmt.finish()?;
694                    f.write_str("Err(")?;
695                    err.fmt(f)?;
696                    return f.write_str(")");
697                }
698            };
699            match attr {
700                Peer::Id(val) => fmt.field("Id", &val),
701                Peer::RemoteIpv4(val) => fmt.field("RemoteIpv4", &val),
702                Peer::RemoteIpv6(val) => fmt.field("RemoteIpv6", &val),
703                Peer::RemoteIpv6ScopeId(val) => fmt.field("RemoteIpv6ScopeId", &val),
704                Peer::RemotePort(val) => fmt.field("RemotePort", &val),
705                Peer::Socket(val) => fmt.field("Socket", &val),
706                Peer::SocketNetnsid(val) => fmt.field("SocketNetnsid", &val),
707                Peer::VpnIpv4(val) => fmt.field("VpnIpv4", &val),
708                Peer::VpnIpv6(val) => fmt.field("VpnIpv6", &val),
709                Peer::LocalIpv4(val) => fmt.field("LocalIpv4", &val),
710                Peer::LocalIpv6(val) => fmt.field("LocalIpv6", &val),
711                Peer::LocalPort(val) => fmt.field("LocalPort", &val),
712                Peer::KeepaliveInterval(val) => fmt.field("KeepaliveInterval", &val),
713                Peer::KeepaliveTimeout(val) => fmt.field("KeepaliveTimeout", &val),
714                Peer::DelReason(val) => fmt.field(
715                    "DelReason",
716                    &FormatEnum(val.into(), DelPeerReason::from_value),
717                ),
718                Peer::VpnRxBytes(val) => fmt.field("VpnRxBytes", &val),
719                Peer::VpnTxBytes(val) => fmt.field("VpnTxBytes", &val),
720                Peer::VpnRxPackets(val) => fmt.field("VpnRxPackets", &val),
721                Peer::VpnTxPackets(val) => fmt.field("VpnTxPackets", &val),
722                Peer::LinkRxBytes(val) => fmt.field("LinkRxBytes", &val),
723                Peer::LinkTxBytes(val) => fmt.field("LinkTxBytes", &val),
724                Peer::LinkRxPackets(val) => fmt.field("LinkRxPackets", &val),
725                Peer::LinkTxPackets(val) => fmt.field("LinkTxPackets", &val),
726            };
727        }
728        fmt.finish()
729    }
730}
731impl IterablePeer<'_> {
732    pub fn lookup_attr(
733        &self,
734        offset: usize,
735        missing_type: Option<u16>,
736    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
737        let mut stack = Vec::new();
738        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
739        if missing_type.is_some() && cur == offset {
740            stack.push(("Peer", offset));
741            return (stack, missing_type.and_then(|t| Peer::attr_from_type(t)));
742        }
743        if cur > offset || cur + self.buf.len() < offset {
744            return (stack, None);
745        }
746        let mut attrs = self.clone();
747        let mut last_off = cur + attrs.pos;
748        while let Some(attr) = attrs.next() {
749            let Ok(attr) = attr else { break };
750            match attr {
751                Peer::Id(val) => {
752                    if last_off == offset {
753                        stack.push(("Id", last_off));
754                        break;
755                    }
756                }
757                Peer::RemoteIpv4(val) => {
758                    if last_off == offset {
759                        stack.push(("RemoteIpv4", last_off));
760                        break;
761                    }
762                }
763                Peer::RemoteIpv6(val) => {
764                    if last_off == offset {
765                        stack.push(("RemoteIpv6", last_off));
766                        break;
767                    }
768                }
769                Peer::RemoteIpv6ScopeId(val) => {
770                    if last_off == offset {
771                        stack.push(("RemoteIpv6ScopeId", last_off));
772                        break;
773                    }
774                }
775                Peer::RemotePort(val) => {
776                    if last_off == offset {
777                        stack.push(("RemotePort", last_off));
778                        break;
779                    }
780                }
781                Peer::Socket(val) => {
782                    if last_off == offset {
783                        stack.push(("Socket", last_off));
784                        break;
785                    }
786                }
787                Peer::SocketNetnsid(val) => {
788                    if last_off == offset {
789                        stack.push(("SocketNetnsid", last_off));
790                        break;
791                    }
792                }
793                Peer::VpnIpv4(val) => {
794                    if last_off == offset {
795                        stack.push(("VpnIpv4", last_off));
796                        break;
797                    }
798                }
799                Peer::VpnIpv6(val) => {
800                    if last_off == offset {
801                        stack.push(("VpnIpv6", last_off));
802                        break;
803                    }
804                }
805                Peer::LocalIpv4(val) => {
806                    if last_off == offset {
807                        stack.push(("LocalIpv4", last_off));
808                        break;
809                    }
810                }
811                Peer::LocalIpv6(val) => {
812                    if last_off == offset {
813                        stack.push(("LocalIpv6", last_off));
814                        break;
815                    }
816                }
817                Peer::LocalPort(val) => {
818                    if last_off == offset {
819                        stack.push(("LocalPort", last_off));
820                        break;
821                    }
822                }
823                Peer::KeepaliveInterval(val) => {
824                    if last_off == offset {
825                        stack.push(("KeepaliveInterval", last_off));
826                        break;
827                    }
828                }
829                Peer::KeepaliveTimeout(val) => {
830                    if last_off == offset {
831                        stack.push(("KeepaliveTimeout", last_off));
832                        break;
833                    }
834                }
835                Peer::DelReason(val) => {
836                    if last_off == offset {
837                        stack.push(("DelReason", last_off));
838                        break;
839                    }
840                }
841                Peer::VpnRxBytes(val) => {
842                    if last_off == offset {
843                        stack.push(("VpnRxBytes", last_off));
844                        break;
845                    }
846                }
847                Peer::VpnTxBytes(val) => {
848                    if last_off == offset {
849                        stack.push(("VpnTxBytes", last_off));
850                        break;
851                    }
852                }
853                Peer::VpnRxPackets(val) => {
854                    if last_off == offset {
855                        stack.push(("VpnRxPackets", last_off));
856                        break;
857                    }
858                }
859                Peer::VpnTxPackets(val) => {
860                    if last_off == offset {
861                        stack.push(("VpnTxPackets", last_off));
862                        break;
863                    }
864                }
865                Peer::LinkRxBytes(val) => {
866                    if last_off == offset {
867                        stack.push(("LinkRxBytes", last_off));
868                        break;
869                    }
870                }
871                Peer::LinkTxBytes(val) => {
872                    if last_off == offset {
873                        stack.push(("LinkTxBytes", last_off));
874                        break;
875                    }
876                }
877                Peer::LinkRxPackets(val) => {
878                    if last_off == offset {
879                        stack.push(("LinkRxPackets", last_off));
880                        break;
881                    }
882                }
883                Peer::LinkTxPackets(val) => {
884                    if last_off == offset {
885                        stack.push(("LinkTxPackets", last_off));
886                        break;
887                    }
888                }
889                _ => {}
890            };
891            last_off = cur + attrs.pos;
892        }
893        if !stack.is_empty() {
894            stack.push(("Peer", cur));
895        }
896        (stack, None)
897    }
898}
899#[derive(Clone)]
900pub enum PeerNewInput<'a> {
901    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
902    Id(u32),
903    #[doc = "The remote IPv4 address of the peer"]
904    RemoteIpv4(std::net::Ipv4Addr),
905    #[doc = "The remote IPv6 address of the peer"]
906    RemoteIpv6(&'a [u8]),
907    #[doc = "The scope id of the remote IPv6 address of the peer (RFC2553)"]
908    RemoteIpv6ScopeId(u32),
909    #[doc = "The remote port of the peer"]
910    RemotePort(u16),
911    #[doc = "The socket to be used to communicate with the peer"]
912    Socket(u32),
913    #[doc = "The IPv4 address assigned to the peer by the server"]
914    VpnIpv4(std::net::Ipv4Addr),
915    #[doc = "The IPv6 address assigned to the peer by the server"]
916    VpnIpv6(&'a [u8]),
917    #[doc = "The local IPv4 to be used to send packets to the peer (UDP only)"]
918    LocalIpv4(std::net::Ipv4Addr),
919    #[doc = "The local IPv6 to be used to send packets to the peer (UDP only)"]
920    LocalIpv6(&'a [u8]),
921    #[doc = "The number of seconds after which a keep alive message is sent to the peer"]
922    KeepaliveInterval(u32),
923    #[doc = "The number of seconds from the last activity after which the peer is assumed dead"]
924    KeepaliveTimeout(u32),
925}
926impl<'a> IterablePeerNewInput<'a> {
927    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
928    pub fn get_id(&self) -> Result<u32, ErrorContext> {
929        let mut iter = self.clone();
930        iter.pos = 0;
931        for attr in iter {
932            if let PeerNewInput::Id(val) = attr? {
933                return Ok(val);
934            }
935        }
936        Err(ErrorContext::new_missing(
937            "PeerNewInput",
938            "Id",
939            self.orig_loc,
940            self.buf.as_ptr() as usize,
941        ))
942    }
943    #[doc = "The remote IPv4 address of the peer"]
944    pub fn get_remote_ipv4(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
945        let mut iter = self.clone();
946        iter.pos = 0;
947        for attr in iter {
948            if let PeerNewInput::RemoteIpv4(val) = attr? {
949                return Ok(val);
950            }
951        }
952        Err(ErrorContext::new_missing(
953            "PeerNewInput",
954            "RemoteIpv4",
955            self.orig_loc,
956            self.buf.as_ptr() as usize,
957        ))
958    }
959    #[doc = "The remote IPv6 address of the peer"]
960    pub fn get_remote_ipv6(&self) -> Result<&'a [u8], ErrorContext> {
961        let mut iter = self.clone();
962        iter.pos = 0;
963        for attr in iter {
964            if let PeerNewInput::RemoteIpv6(val) = attr? {
965                return Ok(val);
966            }
967        }
968        Err(ErrorContext::new_missing(
969            "PeerNewInput",
970            "RemoteIpv6",
971            self.orig_loc,
972            self.buf.as_ptr() as usize,
973        ))
974    }
975    #[doc = "The scope id of the remote IPv6 address of the peer (RFC2553)"]
976    pub fn get_remote_ipv6_scope_id(&self) -> Result<u32, ErrorContext> {
977        let mut iter = self.clone();
978        iter.pos = 0;
979        for attr in iter {
980            if let PeerNewInput::RemoteIpv6ScopeId(val) = attr? {
981                return Ok(val);
982            }
983        }
984        Err(ErrorContext::new_missing(
985            "PeerNewInput",
986            "RemoteIpv6ScopeId",
987            self.orig_loc,
988            self.buf.as_ptr() as usize,
989        ))
990    }
991    #[doc = "The remote port of the peer"]
992    pub fn get_remote_port(&self) -> Result<u16, ErrorContext> {
993        let mut iter = self.clone();
994        iter.pos = 0;
995        for attr in iter {
996            if let PeerNewInput::RemotePort(val) = attr? {
997                return Ok(val);
998            }
999        }
1000        Err(ErrorContext::new_missing(
1001            "PeerNewInput",
1002            "RemotePort",
1003            self.orig_loc,
1004            self.buf.as_ptr() as usize,
1005        ))
1006    }
1007    #[doc = "The socket to be used to communicate with the peer"]
1008    pub fn get_socket(&self) -> Result<u32, ErrorContext> {
1009        let mut iter = self.clone();
1010        iter.pos = 0;
1011        for attr in iter {
1012            if let PeerNewInput::Socket(val) = attr? {
1013                return Ok(val);
1014            }
1015        }
1016        Err(ErrorContext::new_missing(
1017            "PeerNewInput",
1018            "Socket",
1019            self.orig_loc,
1020            self.buf.as_ptr() as usize,
1021        ))
1022    }
1023    #[doc = "The IPv4 address assigned to the peer by the server"]
1024    pub fn get_vpn_ipv4(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
1025        let mut iter = self.clone();
1026        iter.pos = 0;
1027        for attr in iter {
1028            if let PeerNewInput::VpnIpv4(val) = attr? {
1029                return Ok(val);
1030            }
1031        }
1032        Err(ErrorContext::new_missing(
1033            "PeerNewInput",
1034            "VpnIpv4",
1035            self.orig_loc,
1036            self.buf.as_ptr() as usize,
1037        ))
1038    }
1039    #[doc = "The IPv6 address assigned to the peer by the server"]
1040    pub fn get_vpn_ipv6(&self) -> Result<&'a [u8], ErrorContext> {
1041        let mut iter = self.clone();
1042        iter.pos = 0;
1043        for attr in iter {
1044            if let PeerNewInput::VpnIpv6(val) = attr? {
1045                return Ok(val);
1046            }
1047        }
1048        Err(ErrorContext::new_missing(
1049            "PeerNewInput",
1050            "VpnIpv6",
1051            self.orig_loc,
1052            self.buf.as_ptr() as usize,
1053        ))
1054    }
1055    #[doc = "The local IPv4 to be used to send packets to the peer (UDP only)"]
1056    pub fn get_local_ipv4(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
1057        let mut iter = self.clone();
1058        iter.pos = 0;
1059        for attr in iter {
1060            if let PeerNewInput::LocalIpv4(val) = attr? {
1061                return Ok(val);
1062            }
1063        }
1064        Err(ErrorContext::new_missing(
1065            "PeerNewInput",
1066            "LocalIpv4",
1067            self.orig_loc,
1068            self.buf.as_ptr() as usize,
1069        ))
1070    }
1071    #[doc = "The local IPv6 to be used to send packets to the peer (UDP only)"]
1072    pub fn get_local_ipv6(&self) -> Result<&'a [u8], ErrorContext> {
1073        let mut iter = self.clone();
1074        iter.pos = 0;
1075        for attr in iter {
1076            if let PeerNewInput::LocalIpv6(val) = attr? {
1077                return Ok(val);
1078            }
1079        }
1080        Err(ErrorContext::new_missing(
1081            "PeerNewInput",
1082            "LocalIpv6",
1083            self.orig_loc,
1084            self.buf.as_ptr() as usize,
1085        ))
1086    }
1087    #[doc = "The number of seconds after which a keep alive message is sent to the peer"]
1088    pub fn get_keepalive_interval(&self) -> Result<u32, ErrorContext> {
1089        let mut iter = self.clone();
1090        iter.pos = 0;
1091        for attr in iter {
1092            if let PeerNewInput::KeepaliveInterval(val) = attr? {
1093                return Ok(val);
1094            }
1095        }
1096        Err(ErrorContext::new_missing(
1097            "PeerNewInput",
1098            "KeepaliveInterval",
1099            self.orig_loc,
1100            self.buf.as_ptr() as usize,
1101        ))
1102    }
1103    #[doc = "The number of seconds from the last activity after which the peer is assumed dead"]
1104    pub fn get_keepalive_timeout(&self) -> Result<u32, ErrorContext> {
1105        let mut iter = self.clone();
1106        iter.pos = 0;
1107        for attr in iter {
1108            if let PeerNewInput::KeepaliveTimeout(val) = attr? {
1109                return Ok(val);
1110            }
1111        }
1112        Err(ErrorContext::new_missing(
1113            "PeerNewInput",
1114            "KeepaliveTimeout",
1115            self.orig_loc,
1116            self.buf.as_ptr() as usize,
1117        ))
1118    }
1119}
1120impl PeerNewInput<'_> {
1121    pub fn new<'a>(buf: &'a [u8]) -> IterablePeerNewInput<'a> {
1122        IterablePeerNewInput::with_loc(buf, buf.as_ptr() as usize)
1123    }
1124    fn attr_from_type(r#type: u16) -> Option<&'static str> {
1125        Peer::attr_from_type(r#type)
1126    }
1127}
1128#[derive(Clone, Copy, Default)]
1129pub struct IterablePeerNewInput<'a> {
1130    buf: &'a [u8],
1131    pos: usize,
1132    orig_loc: usize,
1133}
1134impl<'a> IterablePeerNewInput<'a> {
1135    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1136        Self {
1137            buf,
1138            pos: 0,
1139            orig_loc,
1140        }
1141    }
1142    pub fn get_buf(&self) -> &'a [u8] {
1143        self.buf
1144    }
1145}
1146impl<'a> Iterator for IterablePeerNewInput<'a> {
1147    type Item = Result<PeerNewInput<'a>, ErrorContext>;
1148    fn next(&mut self) -> Option<Self::Item> {
1149        let pos = self.pos;
1150        let mut r#type;
1151        loop {
1152            r#type = None;
1153            if self.buf.len() == self.pos {
1154                return None;
1155            }
1156            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
1157                break;
1158            };
1159            r#type = Some(header.r#type);
1160            let res = match header.r#type {
1161                1u16 => PeerNewInput::Id({
1162                    let res = parse_u32(next);
1163                    let Some(val) = res else { break };
1164                    val
1165                }),
1166                2u16 => PeerNewInput::RemoteIpv4({
1167                    let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
1168                    let Some(val) = res else { break };
1169                    val
1170                }),
1171                3u16 => PeerNewInput::RemoteIpv6({
1172                    let res = Some(next);
1173                    let Some(val) = res else { break };
1174                    val
1175                }),
1176                4u16 => PeerNewInput::RemoteIpv6ScopeId({
1177                    let res = parse_u32(next);
1178                    let Some(val) = res else { break };
1179                    val
1180                }),
1181                5u16 => PeerNewInput::RemotePort({
1182                    let res = parse_be_u16(next);
1183                    let Some(val) = res else { break };
1184                    val
1185                }),
1186                6u16 => PeerNewInput::Socket({
1187                    let res = parse_u32(next);
1188                    let Some(val) = res else { break };
1189                    val
1190                }),
1191                8u16 => PeerNewInput::VpnIpv4({
1192                    let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
1193                    let Some(val) = res else { break };
1194                    val
1195                }),
1196                9u16 => PeerNewInput::VpnIpv6({
1197                    let res = Some(next);
1198                    let Some(val) = res else { break };
1199                    val
1200                }),
1201                10u16 => PeerNewInput::LocalIpv4({
1202                    let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
1203                    let Some(val) = res else { break };
1204                    val
1205                }),
1206                11u16 => PeerNewInput::LocalIpv6({
1207                    let res = Some(next);
1208                    let Some(val) = res else { break };
1209                    val
1210                }),
1211                13u16 => PeerNewInput::KeepaliveInterval({
1212                    let res = parse_u32(next);
1213                    let Some(val) = res else { break };
1214                    val
1215                }),
1216                14u16 => PeerNewInput::KeepaliveTimeout({
1217                    let res = parse_u32(next);
1218                    let Some(val) = res else { break };
1219                    val
1220                }),
1221                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
1222                n => continue,
1223            };
1224            return Some(Ok(res));
1225        }
1226        Some(Err(ErrorContext::new(
1227            "PeerNewInput",
1228            r#type.and_then(|t| PeerNewInput::attr_from_type(t)),
1229            self.orig_loc,
1230            self.buf.as_ptr().wrapping_add(pos) as usize,
1231        )))
1232    }
1233}
1234impl<'a> std::fmt::Debug for IterablePeerNewInput<'_> {
1235    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1236        let mut fmt = f.debug_struct("PeerNewInput");
1237        for attr in self.clone() {
1238            let attr = match attr {
1239                Ok(a) => a,
1240                Err(err) => {
1241                    fmt.finish()?;
1242                    f.write_str("Err(")?;
1243                    err.fmt(f)?;
1244                    return f.write_str(")");
1245                }
1246            };
1247            match attr {
1248                PeerNewInput::Id(val) => fmt.field("Id", &val),
1249                PeerNewInput::RemoteIpv4(val) => fmt.field("RemoteIpv4", &val),
1250                PeerNewInput::RemoteIpv6(val) => fmt.field("RemoteIpv6", &val),
1251                PeerNewInput::RemoteIpv6ScopeId(val) => fmt.field("RemoteIpv6ScopeId", &val),
1252                PeerNewInput::RemotePort(val) => fmt.field("RemotePort", &val),
1253                PeerNewInput::Socket(val) => fmt.field("Socket", &val),
1254                PeerNewInput::VpnIpv4(val) => fmt.field("VpnIpv4", &val),
1255                PeerNewInput::VpnIpv6(val) => fmt.field("VpnIpv6", &val),
1256                PeerNewInput::LocalIpv4(val) => fmt.field("LocalIpv4", &val),
1257                PeerNewInput::LocalIpv6(val) => fmt.field("LocalIpv6", &val),
1258                PeerNewInput::KeepaliveInterval(val) => fmt.field("KeepaliveInterval", &val),
1259                PeerNewInput::KeepaliveTimeout(val) => fmt.field("KeepaliveTimeout", &val),
1260            };
1261        }
1262        fmt.finish()
1263    }
1264}
1265impl IterablePeerNewInput<'_> {
1266    pub fn lookup_attr(
1267        &self,
1268        offset: usize,
1269        missing_type: Option<u16>,
1270    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
1271        let mut stack = Vec::new();
1272        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
1273        if missing_type.is_some() && cur == offset {
1274            stack.push(("PeerNewInput", offset));
1275            return (
1276                stack,
1277                missing_type.and_then(|t| PeerNewInput::attr_from_type(t)),
1278            );
1279        }
1280        if cur > offset || cur + self.buf.len() < offset {
1281            return (stack, None);
1282        }
1283        let mut attrs = self.clone();
1284        let mut last_off = cur + attrs.pos;
1285        while let Some(attr) = attrs.next() {
1286            let Ok(attr) = attr else { break };
1287            match attr {
1288                PeerNewInput::Id(val) => {
1289                    if last_off == offset {
1290                        stack.push(("Id", last_off));
1291                        break;
1292                    }
1293                }
1294                PeerNewInput::RemoteIpv4(val) => {
1295                    if last_off == offset {
1296                        stack.push(("RemoteIpv4", last_off));
1297                        break;
1298                    }
1299                }
1300                PeerNewInput::RemoteIpv6(val) => {
1301                    if last_off == offset {
1302                        stack.push(("RemoteIpv6", last_off));
1303                        break;
1304                    }
1305                }
1306                PeerNewInput::RemoteIpv6ScopeId(val) => {
1307                    if last_off == offset {
1308                        stack.push(("RemoteIpv6ScopeId", last_off));
1309                        break;
1310                    }
1311                }
1312                PeerNewInput::RemotePort(val) => {
1313                    if last_off == offset {
1314                        stack.push(("RemotePort", last_off));
1315                        break;
1316                    }
1317                }
1318                PeerNewInput::Socket(val) => {
1319                    if last_off == offset {
1320                        stack.push(("Socket", last_off));
1321                        break;
1322                    }
1323                }
1324                PeerNewInput::VpnIpv4(val) => {
1325                    if last_off == offset {
1326                        stack.push(("VpnIpv4", last_off));
1327                        break;
1328                    }
1329                }
1330                PeerNewInput::VpnIpv6(val) => {
1331                    if last_off == offset {
1332                        stack.push(("VpnIpv6", last_off));
1333                        break;
1334                    }
1335                }
1336                PeerNewInput::LocalIpv4(val) => {
1337                    if last_off == offset {
1338                        stack.push(("LocalIpv4", last_off));
1339                        break;
1340                    }
1341                }
1342                PeerNewInput::LocalIpv6(val) => {
1343                    if last_off == offset {
1344                        stack.push(("LocalIpv6", last_off));
1345                        break;
1346                    }
1347                }
1348                PeerNewInput::KeepaliveInterval(val) => {
1349                    if last_off == offset {
1350                        stack.push(("KeepaliveInterval", last_off));
1351                        break;
1352                    }
1353                }
1354                PeerNewInput::KeepaliveTimeout(val) => {
1355                    if last_off == offset {
1356                        stack.push(("KeepaliveTimeout", last_off));
1357                        break;
1358                    }
1359                }
1360                _ => {}
1361            };
1362            last_off = cur + attrs.pos;
1363        }
1364        if !stack.is_empty() {
1365            stack.push(("PeerNewInput", cur));
1366        }
1367        (stack, None)
1368    }
1369}
1370#[derive(Clone)]
1371pub enum PeerSetInput<'a> {
1372    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
1373    Id(u32),
1374    #[doc = "The remote IPv4 address of the peer"]
1375    RemoteIpv4(std::net::Ipv4Addr),
1376    #[doc = "The remote IPv6 address of the peer"]
1377    RemoteIpv6(&'a [u8]),
1378    #[doc = "The scope id of the remote IPv6 address of the peer (RFC2553)"]
1379    RemoteIpv6ScopeId(u32),
1380    #[doc = "The remote port of the peer"]
1381    RemotePort(u16),
1382    #[doc = "The IPv4 address assigned to the peer by the server"]
1383    VpnIpv4(std::net::Ipv4Addr),
1384    #[doc = "The IPv6 address assigned to the peer by the server"]
1385    VpnIpv6(&'a [u8]),
1386    #[doc = "The local IPv4 to be used to send packets to the peer (UDP only)"]
1387    LocalIpv4(std::net::Ipv4Addr),
1388    #[doc = "The local IPv6 to be used to send packets to the peer (UDP only)"]
1389    LocalIpv6(&'a [u8]),
1390    #[doc = "The number of seconds after which a keep alive message is sent to the peer"]
1391    KeepaliveInterval(u32),
1392    #[doc = "The number of seconds from the last activity after which the peer is assumed dead"]
1393    KeepaliveTimeout(u32),
1394}
1395impl<'a> IterablePeerSetInput<'a> {
1396    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
1397    pub fn get_id(&self) -> Result<u32, ErrorContext> {
1398        let mut iter = self.clone();
1399        iter.pos = 0;
1400        for attr in iter {
1401            if let PeerSetInput::Id(val) = attr? {
1402                return Ok(val);
1403            }
1404        }
1405        Err(ErrorContext::new_missing(
1406            "PeerSetInput",
1407            "Id",
1408            self.orig_loc,
1409            self.buf.as_ptr() as usize,
1410        ))
1411    }
1412    #[doc = "The remote IPv4 address of the peer"]
1413    pub fn get_remote_ipv4(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
1414        let mut iter = self.clone();
1415        iter.pos = 0;
1416        for attr in iter {
1417            if let PeerSetInput::RemoteIpv4(val) = attr? {
1418                return Ok(val);
1419            }
1420        }
1421        Err(ErrorContext::new_missing(
1422            "PeerSetInput",
1423            "RemoteIpv4",
1424            self.orig_loc,
1425            self.buf.as_ptr() as usize,
1426        ))
1427    }
1428    #[doc = "The remote IPv6 address of the peer"]
1429    pub fn get_remote_ipv6(&self) -> Result<&'a [u8], ErrorContext> {
1430        let mut iter = self.clone();
1431        iter.pos = 0;
1432        for attr in iter {
1433            if let PeerSetInput::RemoteIpv6(val) = attr? {
1434                return Ok(val);
1435            }
1436        }
1437        Err(ErrorContext::new_missing(
1438            "PeerSetInput",
1439            "RemoteIpv6",
1440            self.orig_loc,
1441            self.buf.as_ptr() as usize,
1442        ))
1443    }
1444    #[doc = "The scope id of the remote IPv6 address of the peer (RFC2553)"]
1445    pub fn get_remote_ipv6_scope_id(&self) -> Result<u32, ErrorContext> {
1446        let mut iter = self.clone();
1447        iter.pos = 0;
1448        for attr in iter {
1449            if let PeerSetInput::RemoteIpv6ScopeId(val) = attr? {
1450                return Ok(val);
1451            }
1452        }
1453        Err(ErrorContext::new_missing(
1454            "PeerSetInput",
1455            "RemoteIpv6ScopeId",
1456            self.orig_loc,
1457            self.buf.as_ptr() as usize,
1458        ))
1459    }
1460    #[doc = "The remote port of the peer"]
1461    pub fn get_remote_port(&self) -> Result<u16, ErrorContext> {
1462        let mut iter = self.clone();
1463        iter.pos = 0;
1464        for attr in iter {
1465            if let PeerSetInput::RemotePort(val) = attr? {
1466                return Ok(val);
1467            }
1468        }
1469        Err(ErrorContext::new_missing(
1470            "PeerSetInput",
1471            "RemotePort",
1472            self.orig_loc,
1473            self.buf.as_ptr() as usize,
1474        ))
1475    }
1476    #[doc = "The IPv4 address assigned to the peer by the server"]
1477    pub fn get_vpn_ipv4(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
1478        let mut iter = self.clone();
1479        iter.pos = 0;
1480        for attr in iter {
1481            if let PeerSetInput::VpnIpv4(val) = attr? {
1482                return Ok(val);
1483            }
1484        }
1485        Err(ErrorContext::new_missing(
1486            "PeerSetInput",
1487            "VpnIpv4",
1488            self.orig_loc,
1489            self.buf.as_ptr() as usize,
1490        ))
1491    }
1492    #[doc = "The IPv6 address assigned to the peer by the server"]
1493    pub fn get_vpn_ipv6(&self) -> Result<&'a [u8], ErrorContext> {
1494        let mut iter = self.clone();
1495        iter.pos = 0;
1496        for attr in iter {
1497            if let PeerSetInput::VpnIpv6(val) = attr? {
1498                return Ok(val);
1499            }
1500        }
1501        Err(ErrorContext::new_missing(
1502            "PeerSetInput",
1503            "VpnIpv6",
1504            self.orig_loc,
1505            self.buf.as_ptr() as usize,
1506        ))
1507    }
1508    #[doc = "The local IPv4 to be used to send packets to the peer (UDP only)"]
1509    pub fn get_local_ipv4(&self) -> Result<std::net::Ipv4Addr, ErrorContext> {
1510        let mut iter = self.clone();
1511        iter.pos = 0;
1512        for attr in iter {
1513            if let PeerSetInput::LocalIpv4(val) = attr? {
1514                return Ok(val);
1515            }
1516        }
1517        Err(ErrorContext::new_missing(
1518            "PeerSetInput",
1519            "LocalIpv4",
1520            self.orig_loc,
1521            self.buf.as_ptr() as usize,
1522        ))
1523    }
1524    #[doc = "The local IPv6 to be used to send packets to the peer (UDP only)"]
1525    pub fn get_local_ipv6(&self) -> Result<&'a [u8], ErrorContext> {
1526        let mut iter = self.clone();
1527        iter.pos = 0;
1528        for attr in iter {
1529            if let PeerSetInput::LocalIpv6(val) = attr? {
1530                return Ok(val);
1531            }
1532        }
1533        Err(ErrorContext::new_missing(
1534            "PeerSetInput",
1535            "LocalIpv6",
1536            self.orig_loc,
1537            self.buf.as_ptr() as usize,
1538        ))
1539    }
1540    #[doc = "The number of seconds after which a keep alive message is sent to the peer"]
1541    pub fn get_keepalive_interval(&self) -> Result<u32, ErrorContext> {
1542        let mut iter = self.clone();
1543        iter.pos = 0;
1544        for attr in iter {
1545            if let PeerSetInput::KeepaliveInterval(val) = attr? {
1546                return Ok(val);
1547            }
1548        }
1549        Err(ErrorContext::new_missing(
1550            "PeerSetInput",
1551            "KeepaliveInterval",
1552            self.orig_loc,
1553            self.buf.as_ptr() as usize,
1554        ))
1555    }
1556    #[doc = "The number of seconds from the last activity after which the peer is assumed dead"]
1557    pub fn get_keepalive_timeout(&self) -> Result<u32, ErrorContext> {
1558        let mut iter = self.clone();
1559        iter.pos = 0;
1560        for attr in iter {
1561            if let PeerSetInput::KeepaliveTimeout(val) = attr? {
1562                return Ok(val);
1563            }
1564        }
1565        Err(ErrorContext::new_missing(
1566            "PeerSetInput",
1567            "KeepaliveTimeout",
1568            self.orig_loc,
1569            self.buf.as_ptr() as usize,
1570        ))
1571    }
1572}
1573impl PeerSetInput<'_> {
1574    pub fn new<'a>(buf: &'a [u8]) -> IterablePeerSetInput<'a> {
1575        IterablePeerSetInput::with_loc(buf, buf.as_ptr() as usize)
1576    }
1577    fn attr_from_type(r#type: u16) -> Option<&'static str> {
1578        Peer::attr_from_type(r#type)
1579    }
1580}
1581#[derive(Clone, Copy, Default)]
1582pub struct IterablePeerSetInput<'a> {
1583    buf: &'a [u8],
1584    pos: usize,
1585    orig_loc: usize,
1586}
1587impl<'a> IterablePeerSetInput<'a> {
1588    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1589        Self {
1590            buf,
1591            pos: 0,
1592            orig_loc,
1593        }
1594    }
1595    pub fn get_buf(&self) -> &'a [u8] {
1596        self.buf
1597    }
1598}
1599impl<'a> Iterator for IterablePeerSetInput<'a> {
1600    type Item = Result<PeerSetInput<'a>, ErrorContext>;
1601    fn next(&mut self) -> Option<Self::Item> {
1602        let pos = self.pos;
1603        let mut r#type;
1604        loop {
1605            r#type = None;
1606            if self.buf.len() == self.pos {
1607                return None;
1608            }
1609            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
1610                break;
1611            };
1612            r#type = Some(header.r#type);
1613            let res = match header.r#type {
1614                1u16 => PeerSetInput::Id({
1615                    let res = parse_u32(next);
1616                    let Some(val) = res else { break };
1617                    val
1618                }),
1619                2u16 => PeerSetInput::RemoteIpv4({
1620                    let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
1621                    let Some(val) = res else { break };
1622                    val
1623                }),
1624                3u16 => PeerSetInput::RemoteIpv6({
1625                    let res = Some(next);
1626                    let Some(val) = res else { break };
1627                    val
1628                }),
1629                4u16 => PeerSetInput::RemoteIpv6ScopeId({
1630                    let res = parse_u32(next);
1631                    let Some(val) = res else { break };
1632                    val
1633                }),
1634                5u16 => PeerSetInput::RemotePort({
1635                    let res = parse_be_u16(next);
1636                    let Some(val) = res else { break };
1637                    val
1638                }),
1639                8u16 => PeerSetInput::VpnIpv4({
1640                    let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
1641                    let Some(val) = res else { break };
1642                    val
1643                }),
1644                9u16 => PeerSetInput::VpnIpv6({
1645                    let res = Some(next);
1646                    let Some(val) = res else { break };
1647                    val
1648                }),
1649                10u16 => PeerSetInput::LocalIpv4({
1650                    let res = parse_be_u32(next).map(Ipv4Addr::from_bits);
1651                    let Some(val) = res else { break };
1652                    val
1653                }),
1654                11u16 => PeerSetInput::LocalIpv6({
1655                    let res = Some(next);
1656                    let Some(val) = res else { break };
1657                    val
1658                }),
1659                13u16 => PeerSetInput::KeepaliveInterval({
1660                    let res = parse_u32(next);
1661                    let Some(val) = res else { break };
1662                    val
1663                }),
1664                14u16 => PeerSetInput::KeepaliveTimeout({
1665                    let res = parse_u32(next);
1666                    let Some(val) = res else { break };
1667                    val
1668                }),
1669                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
1670                n => continue,
1671            };
1672            return Some(Ok(res));
1673        }
1674        Some(Err(ErrorContext::new(
1675            "PeerSetInput",
1676            r#type.and_then(|t| PeerSetInput::attr_from_type(t)),
1677            self.orig_loc,
1678            self.buf.as_ptr().wrapping_add(pos) as usize,
1679        )))
1680    }
1681}
1682impl<'a> std::fmt::Debug for IterablePeerSetInput<'_> {
1683    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1684        let mut fmt = f.debug_struct("PeerSetInput");
1685        for attr in self.clone() {
1686            let attr = match attr {
1687                Ok(a) => a,
1688                Err(err) => {
1689                    fmt.finish()?;
1690                    f.write_str("Err(")?;
1691                    err.fmt(f)?;
1692                    return f.write_str(")");
1693                }
1694            };
1695            match attr {
1696                PeerSetInput::Id(val) => fmt.field("Id", &val),
1697                PeerSetInput::RemoteIpv4(val) => fmt.field("RemoteIpv4", &val),
1698                PeerSetInput::RemoteIpv6(val) => fmt.field("RemoteIpv6", &val),
1699                PeerSetInput::RemoteIpv6ScopeId(val) => fmt.field("RemoteIpv6ScopeId", &val),
1700                PeerSetInput::RemotePort(val) => fmt.field("RemotePort", &val),
1701                PeerSetInput::VpnIpv4(val) => fmt.field("VpnIpv4", &val),
1702                PeerSetInput::VpnIpv6(val) => fmt.field("VpnIpv6", &val),
1703                PeerSetInput::LocalIpv4(val) => fmt.field("LocalIpv4", &val),
1704                PeerSetInput::LocalIpv6(val) => fmt.field("LocalIpv6", &val),
1705                PeerSetInput::KeepaliveInterval(val) => fmt.field("KeepaliveInterval", &val),
1706                PeerSetInput::KeepaliveTimeout(val) => fmt.field("KeepaliveTimeout", &val),
1707            };
1708        }
1709        fmt.finish()
1710    }
1711}
1712impl IterablePeerSetInput<'_> {
1713    pub fn lookup_attr(
1714        &self,
1715        offset: usize,
1716        missing_type: Option<u16>,
1717    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
1718        let mut stack = Vec::new();
1719        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
1720        if missing_type.is_some() && cur == offset {
1721            stack.push(("PeerSetInput", offset));
1722            return (
1723                stack,
1724                missing_type.and_then(|t| PeerSetInput::attr_from_type(t)),
1725            );
1726        }
1727        if cur > offset || cur + self.buf.len() < offset {
1728            return (stack, None);
1729        }
1730        let mut attrs = self.clone();
1731        let mut last_off = cur + attrs.pos;
1732        while let Some(attr) = attrs.next() {
1733            let Ok(attr) = attr else { break };
1734            match attr {
1735                PeerSetInput::Id(val) => {
1736                    if last_off == offset {
1737                        stack.push(("Id", last_off));
1738                        break;
1739                    }
1740                }
1741                PeerSetInput::RemoteIpv4(val) => {
1742                    if last_off == offset {
1743                        stack.push(("RemoteIpv4", last_off));
1744                        break;
1745                    }
1746                }
1747                PeerSetInput::RemoteIpv6(val) => {
1748                    if last_off == offset {
1749                        stack.push(("RemoteIpv6", last_off));
1750                        break;
1751                    }
1752                }
1753                PeerSetInput::RemoteIpv6ScopeId(val) => {
1754                    if last_off == offset {
1755                        stack.push(("RemoteIpv6ScopeId", last_off));
1756                        break;
1757                    }
1758                }
1759                PeerSetInput::RemotePort(val) => {
1760                    if last_off == offset {
1761                        stack.push(("RemotePort", last_off));
1762                        break;
1763                    }
1764                }
1765                PeerSetInput::VpnIpv4(val) => {
1766                    if last_off == offset {
1767                        stack.push(("VpnIpv4", last_off));
1768                        break;
1769                    }
1770                }
1771                PeerSetInput::VpnIpv6(val) => {
1772                    if last_off == offset {
1773                        stack.push(("VpnIpv6", last_off));
1774                        break;
1775                    }
1776                }
1777                PeerSetInput::LocalIpv4(val) => {
1778                    if last_off == offset {
1779                        stack.push(("LocalIpv4", last_off));
1780                        break;
1781                    }
1782                }
1783                PeerSetInput::LocalIpv6(val) => {
1784                    if last_off == offset {
1785                        stack.push(("LocalIpv6", last_off));
1786                        break;
1787                    }
1788                }
1789                PeerSetInput::KeepaliveInterval(val) => {
1790                    if last_off == offset {
1791                        stack.push(("KeepaliveInterval", last_off));
1792                        break;
1793                    }
1794                }
1795                PeerSetInput::KeepaliveTimeout(val) => {
1796                    if last_off == offset {
1797                        stack.push(("KeepaliveTimeout", last_off));
1798                        break;
1799                    }
1800                }
1801                _ => {}
1802            };
1803            last_off = cur + attrs.pos;
1804        }
1805        if !stack.is_empty() {
1806            stack.push(("PeerSetInput", cur));
1807        }
1808        (stack, None)
1809    }
1810}
1811#[derive(Clone)]
1812pub enum PeerDelInput {
1813    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
1814    Id(u32),
1815}
1816impl<'a> IterablePeerDelInput<'a> {
1817    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
1818    pub fn get_id(&self) -> Result<u32, ErrorContext> {
1819        let mut iter = self.clone();
1820        iter.pos = 0;
1821        for attr in iter {
1822            if let PeerDelInput::Id(val) = attr? {
1823                return Ok(val);
1824            }
1825        }
1826        Err(ErrorContext::new_missing(
1827            "PeerDelInput",
1828            "Id",
1829            self.orig_loc,
1830            self.buf.as_ptr() as usize,
1831        ))
1832    }
1833}
1834impl PeerDelInput {
1835    pub fn new<'a>(buf: &'a [u8]) -> IterablePeerDelInput<'a> {
1836        IterablePeerDelInput::with_loc(buf, buf.as_ptr() as usize)
1837    }
1838    fn attr_from_type(r#type: u16) -> Option<&'static str> {
1839        Peer::attr_from_type(r#type)
1840    }
1841}
1842#[derive(Clone, Copy, Default)]
1843pub struct IterablePeerDelInput<'a> {
1844    buf: &'a [u8],
1845    pos: usize,
1846    orig_loc: usize,
1847}
1848impl<'a> IterablePeerDelInput<'a> {
1849    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
1850        Self {
1851            buf,
1852            pos: 0,
1853            orig_loc,
1854        }
1855    }
1856    pub fn get_buf(&self) -> &'a [u8] {
1857        self.buf
1858    }
1859}
1860impl<'a> Iterator for IterablePeerDelInput<'a> {
1861    type Item = Result<PeerDelInput, ErrorContext>;
1862    fn next(&mut self) -> Option<Self::Item> {
1863        let pos = self.pos;
1864        let mut r#type;
1865        loop {
1866            r#type = None;
1867            if self.buf.len() == self.pos {
1868                return None;
1869            }
1870            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
1871                break;
1872            };
1873            r#type = Some(header.r#type);
1874            let res = match header.r#type {
1875                1u16 => PeerDelInput::Id({
1876                    let res = parse_u32(next);
1877                    let Some(val) = res else { break };
1878                    val
1879                }),
1880                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
1881                n => continue,
1882            };
1883            return Some(Ok(res));
1884        }
1885        Some(Err(ErrorContext::new(
1886            "PeerDelInput",
1887            r#type.and_then(|t| PeerDelInput::attr_from_type(t)),
1888            self.orig_loc,
1889            self.buf.as_ptr().wrapping_add(pos) as usize,
1890        )))
1891    }
1892}
1893impl std::fmt::Debug for IterablePeerDelInput<'_> {
1894    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1895        let mut fmt = f.debug_struct("PeerDelInput");
1896        for attr in self.clone() {
1897            let attr = match attr {
1898                Ok(a) => a,
1899                Err(err) => {
1900                    fmt.finish()?;
1901                    f.write_str("Err(")?;
1902                    err.fmt(f)?;
1903                    return f.write_str(")");
1904                }
1905            };
1906            match attr {
1907                PeerDelInput::Id(val) => fmt.field("Id", &val),
1908            };
1909        }
1910        fmt.finish()
1911    }
1912}
1913impl IterablePeerDelInput<'_> {
1914    pub fn lookup_attr(
1915        &self,
1916        offset: usize,
1917        missing_type: Option<u16>,
1918    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
1919        let mut stack = Vec::new();
1920        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
1921        if missing_type.is_some() && cur == offset {
1922            stack.push(("PeerDelInput", offset));
1923            return (
1924                stack,
1925                missing_type.and_then(|t| PeerDelInput::attr_from_type(t)),
1926            );
1927        }
1928        if cur > offset || cur + self.buf.len() < offset {
1929            return (stack, None);
1930        }
1931        let mut attrs = self.clone();
1932        let mut last_off = cur + attrs.pos;
1933        while let Some(attr) = attrs.next() {
1934            let Ok(attr) = attr else { break };
1935            match attr {
1936                PeerDelInput::Id(val) => {
1937                    if last_off == offset {
1938                        stack.push(("Id", last_off));
1939                        break;
1940                    }
1941                }
1942                _ => {}
1943            };
1944            last_off = cur + attrs.pos;
1945        }
1946        if !stack.is_empty() {
1947            stack.push(("PeerDelInput", cur));
1948        }
1949        (stack, None)
1950    }
1951}
1952#[derive(Clone)]
1953pub enum Keyconf<'a> {
1954    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
1955    PeerId(u32),
1956    #[doc = "The slot where the key should be stored\nAssociated type: [`KeySlot`] (enum)"]
1957    Slot(u32),
1958    #[doc = "The unique ID of the key in the peer context\\. Used to fetch the correct key upon decryption"]
1959    KeyId(u32),
1960    #[doc = "The cipher to be used when communicating with the peer\nAssociated type: [`CipherAlg`] (enum)"]
1961    CipherAlg(u32),
1962    #[doc = "Key material for encrypt direction"]
1963    EncryptDir(IterableKeydir<'a>),
1964    #[doc = "Key material for decrypt direction"]
1965    DecryptDir(IterableKeydir<'a>),
1966}
1967impl<'a> IterableKeyconf<'a> {
1968    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
1969    pub fn get_peer_id(&self) -> Result<u32, ErrorContext> {
1970        let mut iter = self.clone();
1971        iter.pos = 0;
1972        for attr in iter {
1973            if let Keyconf::PeerId(val) = attr? {
1974                return Ok(val);
1975            }
1976        }
1977        Err(ErrorContext::new_missing(
1978            "Keyconf",
1979            "PeerId",
1980            self.orig_loc,
1981            self.buf.as_ptr() as usize,
1982        ))
1983    }
1984    #[doc = "The slot where the key should be stored\nAssociated type: [`KeySlot`] (enum)"]
1985    pub fn get_slot(&self) -> Result<u32, ErrorContext> {
1986        let mut iter = self.clone();
1987        iter.pos = 0;
1988        for attr in iter {
1989            if let Keyconf::Slot(val) = attr? {
1990                return Ok(val);
1991            }
1992        }
1993        Err(ErrorContext::new_missing(
1994            "Keyconf",
1995            "Slot",
1996            self.orig_loc,
1997            self.buf.as_ptr() as usize,
1998        ))
1999    }
2000    #[doc = "The unique ID of the key in the peer context\\. Used to fetch the correct key upon decryption"]
2001    pub fn get_key_id(&self) -> Result<u32, ErrorContext> {
2002        let mut iter = self.clone();
2003        iter.pos = 0;
2004        for attr in iter {
2005            if let Keyconf::KeyId(val) = attr? {
2006                return Ok(val);
2007            }
2008        }
2009        Err(ErrorContext::new_missing(
2010            "Keyconf",
2011            "KeyId",
2012            self.orig_loc,
2013            self.buf.as_ptr() as usize,
2014        ))
2015    }
2016    #[doc = "The cipher to be used when communicating with the peer\nAssociated type: [`CipherAlg`] (enum)"]
2017    pub fn get_cipher_alg(&self) -> Result<u32, ErrorContext> {
2018        let mut iter = self.clone();
2019        iter.pos = 0;
2020        for attr in iter {
2021            if let Keyconf::CipherAlg(val) = attr? {
2022                return Ok(val);
2023            }
2024        }
2025        Err(ErrorContext::new_missing(
2026            "Keyconf",
2027            "CipherAlg",
2028            self.orig_loc,
2029            self.buf.as_ptr() as usize,
2030        ))
2031    }
2032    #[doc = "Key material for encrypt direction"]
2033    pub fn get_encrypt_dir(&self) -> Result<IterableKeydir<'a>, ErrorContext> {
2034        let mut iter = self.clone();
2035        iter.pos = 0;
2036        for attr in iter {
2037            if let Keyconf::EncryptDir(val) = attr? {
2038                return Ok(val);
2039            }
2040        }
2041        Err(ErrorContext::new_missing(
2042            "Keyconf",
2043            "EncryptDir",
2044            self.orig_loc,
2045            self.buf.as_ptr() as usize,
2046        ))
2047    }
2048    #[doc = "Key material for decrypt direction"]
2049    pub fn get_decrypt_dir(&self) -> Result<IterableKeydir<'a>, ErrorContext> {
2050        let mut iter = self.clone();
2051        iter.pos = 0;
2052        for attr in iter {
2053            if let Keyconf::DecryptDir(val) = attr? {
2054                return Ok(val);
2055            }
2056        }
2057        Err(ErrorContext::new_missing(
2058            "Keyconf",
2059            "DecryptDir",
2060            self.orig_loc,
2061            self.buf.as_ptr() as usize,
2062        ))
2063    }
2064}
2065impl Keyconf<'_> {
2066    pub fn new<'a>(buf: &'a [u8]) -> IterableKeyconf<'a> {
2067        IterableKeyconf::with_loc(buf, buf.as_ptr() as usize)
2068    }
2069    fn attr_from_type(r#type: u16) -> Option<&'static str> {
2070        let res = match r#type {
2071            1u16 => "PeerId",
2072            2u16 => "Slot",
2073            3u16 => "KeyId",
2074            4u16 => "CipherAlg",
2075            5u16 => "EncryptDir",
2076            6u16 => "DecryptDir",
2077            _ => return None,
2078        };
2079        Some(res)
2080    }
2081}
2082#[derive(Clone, Copy, Default)]
2083pub struct IterableKeyconf<'a> {
2084    buf: &'a [u8],
2085    pos: usize,
2086    orig_loc: usize,
2087}
2088impl<'a> IterableKeyconf<'a> {
2089    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2090        Self {
2091            buf,
2092            pos: 0,
2093            orig_loc,
2094        }
2095    }
2096    pub fn get_buf(&self) -> &'a [u8] {
2097        self.buf
2098    }
2099}
2100impl<'a> Iterator for IterableKeyconf<'a> {
2101    type Item = Result<Keyconf<'a>, ErrorContext>;
2102    fn next(&mut self) -> Option<Self::Item> {
2103        let pos = self.pos;
2104        let mut r#type;
2105        loop {
2106            r#type = None;
2107            if self.buf.len() == self.pos {
2108                return None;
2109            }
2110            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
2111                break;
2112            };
2113            r#type = Some(header.r#type);
2114            let res = match header.r#type {
2115                1u16 => Keyconf::PeerId({
2116                    let res = parse_u32(next);
2117                    let Some(val) = res else { break };
2118                    val
2119                }),
2120                2u16 => Keyconf::Slot({
2121                    let res = parse_u32(next);
2122                    let Some(val) = res else { break };
2123                    val
2124                }),
2125                3u16 => Keyconf::KeyId({
2126                    let res = parse_u32(next);
2127                    let Some(val) = res else { break };
2128                    val
2129                }),
2130                4u16 => Keyconf::CipherAlg({
2131                    let res = parse_u32(next);
2132                    let Some(val) = res else { break };
2133                    val
2134                }),
2135                5u16 => Keyconf::EncryptDir({
2136                    let res = Some(IterableKeydir::with_loc(next, self.orig_loc));
2137                    let Some(val) = res else { break };
2138                    val
2139                }),
2140                6u16 => Keyconf::DecryptDir({
2141                    let res = Some(IterableKeydir::with_loc(next, self.orig_loc));
2142                    let Some(val) = res else { break };
2143                    val
2144                }),
2145                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
2146                n => continue,
2147            };
2148            return Some(Ok(res));
2149        }
2150        Some(Err(ErrorContext::new(
2151            "Keyconf",
2152            r#type.and_then(|t| Keyconf::attr_from_type(t)),
2153            self.orig_loc,
2154            self.buf.as_ptr().wrapping_add(pos) as usize,
2155        )))
2156    }
2157}
2158impl<'a> std::fmt::Debug for IterableKeyconf<'_> {
2159    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2160        let mut fmt = f.debug_struct("Keyconf");
2161        for attr in self.clone() {
2162            let attr = match attr {
2163                Ok(a) => a,
2164                Err(err) => {
2165                    fmt.finish()?;
2166                    f.write_str("Err(")?;
2167                    err.fmt(f)?;
2168                    return f.write_str(")");
2169                }
2170            };
2171            match attr {
2172                Keyconf::PeerId(val) => fmt.field("PeerId", &val),
2173                Keyconf::Slot(val) => {
2174                    fmt.field("Slot", &FormatEnum(val.into(), KeySlot::from_value))
2175                }
2176                Keyconf::KeyId(val) => fmt.field("KeyId", &val),
2177                Keyconf::CipherAlg(val) => {
2178                    fmt.field("CipherAlg", &FormatEnum(val.into(), CipherAlg::from_value))
2179                }
2180                Keyconf::EncryptDir(val) => fmt.field("EncryptDir", &val),
2181                Keyconf::DecryptDir(val) => fmt.field("DecryptDir", &val),
2182            };
2183        }
2184        fmt.finish()
2185    }
2186}
2187impl IterableKeyconf<'_> {
2188    pub fn lookup_attr(
2189        &self,
2190        offset: usize,
2191        missing_type: Option<u16>,
2192    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2193        let mut stack = Vec::new();
2194        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2195        if missing_type.is_some() && cur == offset {
2196            stack.push(("Keyconf", offset));
2197            return (stack, missing_type.and_then(|t| Keyconf::attr_from_type(t)));
2198        }
2199        if cur > offset || cur + self.buf.len() < offset {
2200            return (stack, None);
2201        }
2202        let mut attrs = self.clone();
2203        let mut last_off = cur + attrs.pos;
2204        let mut missing = None;
2205        while let Some(attr) = attrs.next() {
2206            let Ok(attr) = attr else { break };
2207            match attr {
2208                Keyconf::PeerId(val) => {
2209                    if last_off == offset {
2210                        stack.push(("PeerId", last_off));
2211                        break;
2212                    }
2213                }
2214                Keyconf::Slot(val) => {
2215                    if last_off == offset {
2216                        stack.push(("Slot", last_off));
2217                        break;
2218                    }
2219                }
2220                Keyconf::KeyId(val) => {
2221                    if last_off == offset {
2222                        stack.push(("KeyId", last_off));
2223                        break;
2224                    }
2225                }
2226                Keyconf::CipherAlg(val) => {
2227                    if last_off == offset {
2228                        stack.push(("CipherAlg", last_off));
2229                        break;
2230                    }
2231                }
2232                Keyconf::EncryptDir(val) => {
2233                    (stack, missing) = val.lookup_attr(offset, missing_type);
2234                    if !stack.is_empty() {
2235                        break;
2236                    }
2237                }
2238                Keyconf::DecryptDir(val) => {
2239                    (stack, missing) = val.lookup_attr(offset, missing_type);
2240                    if !stack.is_empty() {
2241                        break;
2242                    }
2243                }
2244                _ => {}
2245            };
2246            last_off = cur + attrs.pos;
2247        }
2248        if !stack.is_empty() {
2249            stack.push(("Keyconf", cur));
2250        }
2251        (stack, missing)
2252    }
2253}
2254#[derive(Clone)]
2255pub enum Keydir<'a> {
2256    #[doc = "The actual key to be used by the cipher"]
2257    CipherKey(&'a [u8]),
2258    #[doc = "Random nonce to be concatenated to the packet ID, in order to obtain the actual cipher IV"]
2259    NonceTail(&'a [u8]),
2260}
2261impl<'a> IterableKeydir<'a> {
2262    #[doc = "The actual key to be used by the cipher"]
2263    pub fn get_cipher_key(&self) -> Result<&'a [u8], ErrorContext> {
2264        let mut iter = self.clone();
2265        iter.pos = 0;
2266        for attr in iter {
2267            if let Keydir::CipherKey(val) = attr? {
2268                return Ok(val);
2269            }
2270        }
2271        Err(ErrorContext::new_missing(
2272            "Keydir",
2273            "CipherKey",
2274            self.orig_loc,
2275            self.buf.as_ptr() as usize,
2276        ))
2277    }
2278    #[doc = "Random nonce to be concatenated to the packet ID, in order to obtain the actual cipher IV"]
2279    pub fn get_nonce_tail(&self) -> Result<&'a [u8], ErrorContext> {
2280        let mut iter = self.clone();
2281        iter.pos = 0;
2282        for attr in iter {
2283            if let Keydir::NonceTail(val) = attr? {
2284                return Ok(val);
2285            }
2286        }
2287        Err(ErrorContext::new_missing(
2288            "Keydir",
2289            "NonceTail",
2290            self.orig_loc,
2291            self.buf.as_ptr() as usize,
2292        ))
2293    }
2294}
2295impl Keydir<'_> {
2296    pub fn new<'a>(buf: &'a [u8]) -> IterableKeydir<'a> {
2297        IterableKeydir::with_loc(buf, buf.as_ptr() as usize)
2298    }
2299    fn attr_from_type(r#type: u16) -> Option<&'static str> {
2300        let res = match r#type {
2301            1u16 => "CipherKey",
2302            2u16 => "NonceTail",
2303            _ => return None,
2304        };
2305        Some(res)
2306    }
2307}
2308#[derive(Clone, Copy, Default)]
2309pub struct IterableKeydir<'a> {
2310    buf: &'a [u8],
2311    pos: usize,
2312    orig_loc: usize,
2313}
2314impl<'a> IterableKeydir<'a> {
2315    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2316        Self {
2317            buf,
2318            pos: 0,
2319            orig_loc,
2320        }
2321    }
2322    pub fn get_buf(&self) -> &'a [u8] {
2323        self.buf
2324    }
2325}
2326impl<'a> Iterator for IterableKeydir<'a> {
2327    type Item = Result<Keydir<'a>, ErrorContext>;
2328    fn next(&mut self) -> Option<Self::Item> {
2329        let pos = self.pos;
2330        let mut r#type;
2331        loop {
2332            r#type = None;
2333            if self.buf.len() == self.pos {
2334                return None;
2335            }
2336            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
2337                break;
2338            };
2339            r#type = Some(header.r#type);
2340            let res = match header.r#type {
2341                1u16 => Keydir::CipherKey({
2342                    let res = Some(next);
2343                    let Some(val) = res else { break };
2344                    val
2345                }),
2346                2u16 => Keydir::NonceTail({
2347                    let res = Some(next);
2348                    let Some(val) = res else { break };
2349                    val
2350                }),
2351                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
2352                n => continue,
2353            };
2354            return Some(Ok(res));
2355        }
2356        Some(Err(ErrorContext::new(
2357            "Keydir",
2358            r#type.and_then(|t| Keydir::attr_from_type(t)),
2359            self.orig_loc,
2360            self.buf.as_ptr().wrapping_add(pos) as usize,
2361        )))
2362    }
2363}
2364impl<'a> std::fmt::Debug for IterableKeydir<'_> {
2365    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2366        let mut fmt = f.debug_struct("Keydir");
2367        for attr in self.clone() {
2368            let attr = match attr {
2369                Ok(a) => a,
2370                Err(err) => {
2371                    fmt.finish()?;
2372                    f.write_str("Err(")?;
2373                    err.fmt(f)?;
2374                    return f.write_str(")");
2375                }
2376            };
2377            match attr {
2378                Keydir::CipherKey(val) => fmt.field("CipherKey", &val),
2379                Keydir::NonceTail(val) => fmt.field("NonceTail", &val),
2380            };
2381        }
2382        fmt.finish()
2383    }
2384}
2385impl IterableKeydir<'_> {
2386    pub fn lookup_attr(
2387        &self,
2388        offset: usize,
2389        missing_type: Option<u16>,
2390    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2391        let mut stack = Vec::new();
2392        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2393        if missing_type.is_some() && cur == offset {
2394            stack.push(("Keydir", offset));
2395            return (stack, missing_type.and_then(|t| Keydir::attr_from_type(t)));
2396        }
2397        if cur > offset || cur + self.buf.len() < offset {
2398            return (stack, None);
2399        }
2400        let mut attrs = self.clone();
2401        let mut last_off = cur + attrs.pos;
2402        while let Some(attr) = attrs.next() {
2403            let Ok(attr) = attr else { break };
2404            match attr {
2405                Keydir::CipherKey(val) => {
2406                    if last_off == offset {
2407                        stack.push(("CipherKey", last_off));
2408                        break;
2409                    }
2410                }
2411                Keydir::NonceTail(val) => {
2412                    if last_off == offset {
2413                        stack.push(("NonceTail", last_off));
2414                        break;
2415                    }
2416                }
2417                _ => {}
2418            };
2419            last_off = cur + attrs.pos;
2420        }
2421        if !stack.is_empty() {
2422            stack.push(("Keydir", cur));
2423        }
2424        (stack, None)
2425    }
2426}
2427#[derive(Clone)]
2428pub enum KeyconfGet {
2429    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
2430    PeerId(u32),
2431    #[doc = "The slot where the key should be stored\nAssociated type: [`KeySlot`] (enum)"]
2432    Slot(u32),
2433    #[doc = "The unique ID of the key in the peer context\\. Used to fetch the correct key upon decryption"]
2434    KeyId(u32),
2435    #[doc = "The cipher to be used when communicating with the peer\nAssociated type: [`CipherAlg`] (enum)"]
2436    CipherAlg(u32),
2437}
2438impl<'a> IterableKeyconfGet<'a> {
2439    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
2440    pub fn get_peer_id(&self) -> Result<u32, ErrorContext> {
2441        let mut iter = self.clone();
2442        iter.pos = 0;
2443        for attr in iter {
2444            if let KeyconfGet::PeerId(val) = attr? {
2445                return Ok(val);
2446            }
2447        }
2448        Err(ErrorContext::new_missing(
2449            "KeyconfGet",
2450            "PeerId",
2451            self.orig_loc,
2452            self.buf.as_ptr() as usize,
2453        ))
2454    }
2455    #[doc = "The slot where the key should be stored\nAssociated type: [`KeySlot`] (enum)"]
2456    pub fn get_slot(&self) -> Result<u32, ErrorContext> {
2457        let mut iter = self.clone();
2458        iter.pos = 0;
2459        for attr in iter {
2460            if let KeyconfGet::Slot(val) = attr? {
2461                return Ok(val);
2462            }
2463        }
2464        Err(ErrorContext::new_missing(
2465            "KeyconfGet",
2466            "Slot",
2467            self.orig_loc,
2468            self.buf.as_ptr() as usize,
2469        ))
2470    }
2471    #[doc = "The unique ID of the key in the peer context\\. Used to fetch the correct key upon decryption"]
2472    pub fn get_key_id(&self) -> Result<u32, ErrorContext> {
2473        let mut iter = self.clone();
2474        iter.pos = 0;
2475        for attr in iter {
2476            if let KeyconfGet::KeyId(val) = attr? {
2477                return Ok(val);
2478            }
2479        }
2480        Err(ErrorContext::new_missing(
2481            "KeyconfGet",
2482            "KeyId",
2483            self.orig_loc,
2484            self.buf.as_ptr() as usize,
2485        ))
2486    }
2487    #[doc = "The cipher to be used when communicating with the peer\nAssociated type: [`CipherAlg`] (enum)"]
2488    pub fn get_cipher_alg(&self) -> Result<u32, ErrorContext> {
2489        let mut iter = self.clone();
2490        iter.pos = 0;
2491        for attr in iter {
2492            if let KeyconfGet::CipherAlg(val) = attr? {
2493                return Ok(val);
2494            }
2495        }
2496        Err(ErrorContext::new_missing(
2497            "KeyconfGet",
2498            "CipherAlg",
2499            self.orig_loc,
2500            self.buf.as_ptr() as usize,
2501        ))
2502    }
2503}
2504impl KeyconfGet {
2505    pub fn new<'a>(buf: &'a [u8]) -> IterableKeyconfGet<'a> {
2506        IterableKeyconfGet::with_loc(buf, buf.as_ptr() as usize)
2507    }
2508    fn attr_from_type(r#type: u16) -> Option<&'static str> {
2509        Keyconf::attr_from_type(r#type)
2510    }
2511}
2512#[derive(Clone, Copy, Default)]
2513pub struct IterableKeyconfGet<'a> {
2514    buf: &'a [u8],
2515    pos: usize,
2516    orig_loc: usize,
2517}
2518impl<'a> IterableKeyconfGet<'a> {
2519    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2520        Self {
2521            buf,
2522            pos: 0,
2523            orig_loc,
2524        }
2525    }
2526    pub fn get_buf(&self) -> &'a [u8] {
2527        self.buf
2528    }
2529}
2530impl<'a> Iterator for IterableKeyconfGet<'a> {
2531    type Item = Result<KeyconfGet, ErrorContext>;
2532    fn next(&mut self) -> Option<Self::Item> {
2533        let pos = self.pos;
2534        let mut r#type;
2535        loop {
2536            r#type = None;
2537            if self.buf.len() == self.pos {
2538                return None;
2539            }
2540            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
2541                break;
2542            };
2543            r#type = Some(header.r#type);
2544            let res = match header.r#type {
2545                1u16 => KeyconfGet::PeerId({
2546                    let res = parse_u32(next);
2547                    let Some(val) = res else { break };
2548                    val
2549                }),
2550                2u16 => KeyconfGet::Slot({
2551                    let res = parse_u32(next);
2552                    let Some(val) = res else { break };
2553                    val
2554                }),
2555                3u16 => KeyconfGet::KeyId({
2556                    let res = parse_u32(next);
2557                    let Some(val) = res else { break };
2558                    val
2559                }),
2560                4u16 => KeyconfGet::CipherAlg({
2561                    let res = parse_u32(next);
2562                    let Some(val) = res else { break };
2563                    val
2564                }),
2565                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
2566                n => continue,
2567            };
2568            return Some(Ok(res));
2569        }
2570        Some(Err(ErrorContext::new(
2571            "KeyconfGet",
2572            r#type.and_then(|t| KeyconfGet::attr_from_type(t)),
2573            self.orig_loc,
2574            self.buf.as_ptr().wrapping_add(pos) as usize,
2575        )))
2576    }
2577}
2578impl std::fmt::Debug for IterableKeyconfGet<'_> {
2579    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2580        let mut fmt = f.debug_struct("KeyconfGet");
2581        for attr in self.clone() {
2582            let attr = match attr {
2583                Ok(a) => a,
2584                Err(err) => {
2585                    fmt.finish()?;
2586                    f.write_str("Err(")?;
2587                    err.fmt(f)?;
2588                    return f.write_str(")");
2589                }
2590            };
2591            match attr {
2592                KeyconfGet::PeerId(val) => fmt.field("PeerId", &val),
2593                KeyconfGet::Slot(val) => {
2594                    fmt.field("Slot", &FormatEnum(val.into(), KeySlot::from_value))
2595                }
2596                KeyconfGet::KeyId(val) => fmt.field("KeyId", &val),
2597                KeyconfGet::CipherAlg(val) => {
2598                    fmt.field("CipherAlg", &FormatEnum(val.into(), CipherAlg::from_value))
2599                }
2600            };
2601        }
2602        fmt.finish()
2603    }
2604}
2605impl IterableKeyconfGet<'_> {
2606    pub fn lookup_attr(
2607        &self,
2608        offset: usize,
2609        missing_type: Option<u16>,
2610    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2611        let mut stack = Vec::new();
2612        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2613        if missing_type.is_some() && cur == offset {
2614            stack.push(("KeyconfGet", offset));
2615            return (
2616                stack,
2617                missing_type.and_then(|t| KeyconfGet::attr_from_type(t)),
2618            );
2619        }
2620        if cur > offset || cur + self.buf.len() < offset {
2621            return (stack, None);
2622        }
2623        let mut attrs = self.clone();
2624        let mut last_off = cur + attrs.pos;
2625        while let Some(attr) = attrs.next() {
2626            let Ok(attr) = attr else { break };
2627            match attr {
2628                KeyconfGet::PeerId(val) => {
2629                    if last_off == offset {
2630                        stack.push(("PeerId", last_off));
2631                        break;
2632                    }
2633                }
2634                KeyconfGet::Slot(val) => {
2635                    if last_off == offset {
2636                        stack.push(("Slot", last_off));
2637                        break;
2638                    }
2639                }
2640                KeyconfGet::KeyId(val) => {
2641                    if last_off == offset {
2642                        stack.push(("KeyId", last_off));
2643                        break;
2644                    }
2645                }
2646                KeyconfGet::CipherAlg(val) => {
2647                    if last_off == offset {
2648                        stack.push(("CipherAlg", last_off));
2649                        break;
2650                    }
2651                }
2652                _ => {}
2653            };
2654            last_off = cur + attrs.pos;
2655        }
2656        if !stack.is_empty() {
2657            stack.push(("KeyconfGet", cur));
2658        }
2659        (stack, None)
2660    }
2661}
2662#[derive(Clone)]
2663pub enum KeyconfSwapInput {
2664    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
2665    PeerId(u32),
2666}
2667impl<'a> IterableKeyconfSwapInput<'a> {
2668    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
2669    pub fn get_peer_id(&self) -> Result<u32, ErrorContext> {
2670        let mut iter = self.clone();
2671        iter.pos = 0;
2672        for attr in iter {
2673            if let KeyconfSwapInput::PeerId(val) = attr? {
2674                return Ok(val);
2675            }
2676        }
2677        Err(ErrorContext::new_missing(
2678            "KeyconfSwapInput",
2679            "PeerId",
2680            self.orig_loc,
2681            self.buf.as_ptr() as usize,
2682        ))
2683    }
2684}
2685impl KeyconfSwapInput {
2686    pub fn new<'a>(buf: &'a [u8]) -> IterableKeyconfSwapInput<'a> {
2687        IterableKeyconfSwapInput::with_loc(buf, buf.as_ptr() as usize)
2688    }
2689    fn attr_from_type(r#type: u16) -> Option<&'static str> {
2690        Keyconf::attr_from_type(r#type)
2691    }
2692}
2693#[derive(Clone, Copy, Default)]
2694pub struct IterableKeyconfSwapInput<'a> {
2695    buf: &'a [u8],
2696    pos: usize,
2697    orig_loc: usize,
2698}
2699impl<'a> IterableKeyconfSwapInput<'a> {
2700    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2701        Self {
2702            buf,
2703            pos: 0,
2704            orig_loc,
2705        }
2706    }
2707    pub fn get_buf(&self) -> &'a [u8] {
2708        self.buf
2709    }
2710}
2711impl<'a> Iterator for IterableKeyconfSwapInput<'a> {
2712    type Item = Result<KeyconfSwapInput, ErrorContext>;
2713    fn next(&mut self) -> Option<Self::Item> {
2714        let pos = self.pos;
2715        let mut r#type;
2716        loop {
2717            r#type = None;
2718            if self.buf.len() == self.pos {
2719                return None;
2720            }
2721            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
2722                break;
2723            };
2724            r#type = Some(header.r#type);
2725            let res = match header.r#type {
2726                1u16 => KeyconfSwapInput::PeerId({
2727                    let res = parse_u32(next);
2728                    let Some(val) = res else { break };
2729                    val
2730                }),
2731                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
2732                n => continue,
2733            };
2734            return Some(Ok(res));
2735        }
2736        Some(Err(ErrorContext::new(
2737            "KeyconfSwapInput",
2738            r#type.and_then(|t| KeyconfSwapInput::attr_from_type(t)),
2739            self.orig_loc,
2740            self.buf.as_ptr().wrapping_add(pos) as usize,
2741        )))
2742    }
2743}
2744impl std::fmt::Debug for IterableKeyconfSwapInput<'_> {
2745    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2746        let mut fmt = f.debug_struct("KeyconfSwapInput");
2747        for attr in self.clone() {
2748            let attr = match attr {
2749                Ok(a) => a,
2750                Err(err) => {
2751                    fmt.finish()?;
2752                    f.write_str("Err(")?;
2753                    err.fmt(f)?;
2754                    return f.write_str(")");
2755                }
2756            };
2757            match attr {
2758                KeyconfSwapInput::PeerId(val) => fmt.field("PeerId", &val),
2759            };
2760        }
2761        fmt.finish()
2762    }
2763}
2764impl IterableKeyconfSwapInput<'_> {
2765    pub fn lookup_attr(
2766        &self,
2767        offset: usize,
2768        missing_type: Option<u16>,
2769    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2770        let mut stack = Vec::new();
2771        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2772        if missing_type.is_some() && cur == offset {
2773            stack.push(("KeyconfSwapInput", offset));
2774            return (
2775                stack,
2776                missing_type.and_then(|t| KeyconfSwapInput::attr_from_type(t)),
2777            );
2778        }
2779        if cur > offset || cur + self.buf.len() < offset {
2780            return (stack, None);
2781        }
2782        let mut attrs = self.clone();
2783        let mut last_off = cur + attrs.pos;
2784        while let Some(attr) = attrs.next() {
2785            let Ok(attr) = attr else { break };
2786            match attr {
2787                KeyconfSwapInput::PeerId(val) => {
2788                    if last_off == offset {
2789                        stack.push(("PeerId", last_off));
2790                        break;
2791                    }
2792                }
2793                _ => {}
2794            };
2795            last_off = cur + attrs.pos;
2796        }
2797        if !stack.is_empty() {
2798            stack.push(("KeyconfSwapInput", cur));
2799        }
2800        (stack, None)
2801    }
2802}
2803#[derive(Clone)]
2804pub enum KeyconfDelInput {
2805    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
2806    PeerId(u32),
2807    #[doc = "The slot where the key should be stored\nAssociated type: [`KeySlot`] (enum)"]
2808    Slot(u32),
2809}
2810impl<'a> IterableKeyconfDelInput<'a> {
2811    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
2812    pub fn get_peer_id(&self) -> Result<u32, ErrorContext> {
2813        let mut iter = self.clone();
2814        iter.pos = 0;
2815        for attr in iter {
2816            if let KeyconfDelInput::PeerId(val) = attr? {
2817                return Ok(val);
2818            }
2819        }
2820        Err(ErrorContext::new_missing(
2821            "KeyconfDelInput",
2822            "PeerId",
2823            self.orig_loc,
2824            self.buf.as_ptr() as usize,
2825        ))
2826    }
2827    #[doc = "The slot where the key should be stored\nAssociated type: [`KeySlot`] (enum)"]
2828    pub fn get_slot(&self) -> Result<u32, ErrorContext> {
2829        let mut iter = self.clone();
2830        iter.pos = 0;
2831        for attr in iter {
2832            if let KeyconfDelInput::Slot(val) = attr? {
2833                return Ok(val);
2834            }
2835        }
2836        Err(ErrorContext::new_missing(
2837            "KeyconfDelInput",
2838            "Slot",
2839            self.orig_loc,
2840            self.buf.as_ptr() as usize,
2841        ))
2842    }
2843}
2844impl KeyconfDelInput {
2845    pub fn new<'a>(buf: &'a [u8]) -> IterableKeyconfDelInput<'a> {
2846        IterableKeyconfDelInput::with_loc(buf, buf.as_ptr() as usize)
2847    }
2848    fn attr_from_type(r#type: u16) -> Option<&'static str> {
2849        Keyconf::attr_from_type(r#type)
2850    }
2851}
2852#[derive(Clone, Copy, Default)]
2853pub struct IterableKeyconfDelInput<'a> {
2854    buf: &'a [u8],
2855    pos: usize,
2856    orig_loc: usize,
2857}
2858impl<'a> IterableKeyconfDelInput<'a> {
2859    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
2860        Self {
2861            buf,
2862            pos: 0,
2863            orig_loc,
2864        }
2865    }
2866    pub fn get_buf(&self) -> &'a [u8] {
2867        self.buf
2868    }
2869}
2870impl<'a> Iterator for IterableKeyconfDelInput<'a> {
2871    type Item = Result<KeyconfDelInput, ErrorContext>;
2872    fn next(&mut self) -> Option<Self::Item> {
2873        let pos = self.pos;
2874        let mut r#type;
2875        loop {
2876            r#type = None;
2877            if self.buf.len() == self.pos {
2878                return None;
2879            }
2880            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
2881                break;
2882            };
2883            r#type = Some(header.r#type);
2884            let res = match header.r#type {
2885                1u16 => KeyconfDelInput::PeerId({
2886                    let res = parse_u32(next);
2887                    let Some(val) = res else { break };
2888                    val
2889                }),
2890                2u16 => KeyconfDelInput::Slot({
2891                    let res = parse_u32(next);
2892                    let Some(val) = res else { break };
2893                    val
2894                }),
2895                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
2896                n => continue,
2897            };
2898            return Some(Ok(res));
2899        }
2900        Some(Err(ErrorContext::new(
2901            "KeyconfDelInput",
2902            r#type.and_then(|t| KeyconfDelInput::attr_from_type(t)),
2903            self.orig_loc,
2904            self.buf.as_ptr().wrapping_add(pos) as usize,
2905        )))
2906    }
2907}
2908impl std::fmt::Debug for IterableKeyconfDelInput<'_> {
2909    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2910        let mut fmt = f.debug_struct("KeyconfDelInput");
2911        for attr in self.clone() {
2912            let attr = match attr {
2913                Ok(a) => a,
2914                Err(err) => {
2915                    fmt.finish()?;
2916                    f.write_str("Err(")?;
2917                    err.fmt(f)?;
2918                    return f.write_str(")");
2919                }
2920            };
2921            match attr {
2922                KeyconfDelInput::PeerId(val) => fmt.field("PeerId", &val),
2923                KeyconfDelInput::Slot(val) => {
2924                    fmt.field("Slot", &FormatEnum(val.into(), KeySlot::from_value))
2925                }
2926            };
2927        }
2928        fmt.finish()
2929    }
2930}
2931impl IterableKeyconfDelInput<'_> {
2932    pub fn lookup_attr(
2933        &self,
2934        offset: usize,
2935        missing_type: Option<u16>,
2936    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
2937        let mut stack = Vec::new();
2938        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
2939        if missing_type.is_some() && cur == offset {
2940            stack.push(("KeyconfDelInput", offset));
2941            return (
2942                stack,
2943                missing_type.and_then(|t| KeyconfDelInput::attr_from_type(t)),
2944            );
2945        }
2946        if cur > offset || cur + self.buf.len() < offset {
2947            return (stack, None);
2948        }
2949        let mut attrs = self.clone();
2950        let mut last_off = cur + attrs.pos;
2951        while let Some(attr) = attrs.next() {
2952            let Ok(attr) = attr else { break };
2953            match attr {
2954                KeyconfDelInput::PeerId(val) => {
2955                    if last_off == offset {
2956                        stack.push(("PeerId", last_off));
2957                        break;
2958                    }
2959                }
2960                KeyconfDelInput::Slot(val) => {
2961                    if last_off == offset {
2962                        stack.push(("Slot", last_off));
2963                        break;
2964                    }
2965                }
2966                _ => {}
2967            };
2968            last_off = cur + attrs.pos;
2969        }
2970        if !stack.is_empty() {
2971            stack.push(("KeyconfDelInput", cur));
2972        }
2973        (stack, None)
2974    }
2975}
2976#[derive(Clone)]
2977pub enum Ovpn<'a> {
2978    #[doc = "Index of the ovpn interface to operate on"]
2979    Ifindex(u32),
2980    #[doc = "The peer object containing the attributed of interest for the specific operation"]
2981    Peer(IterablePeer<'a>),
2982    #[doc = "Peer specific cipher configuration"]
2983    Keyconf(IterableKeyconf<'a>),
2984}
2985impl<'a> IterableOvpn<'a> {
2986    #[doc = "Index of the ovpn interface to operate on"]
2987    pub fn get_ifindex(&self) -> Result<u32, ErrorContext> {
2988        let mut iter = self.clone();
2989        iter.pos = 0;
2990        for attr in iter {
2991            if let Ovpn::Ifindex(val) = attr? {
2992                return Ok(val);
2993            }
2994        }
2995        Err(ErrorContext::new_missing(
2996            "Ovpn",
2997            "Ifindex",
2998            self.orig_loc,
2999            self.buf.as_ptr() as usize,
3000        ))
3001    }
3002    #[doc = "The peer object containing the attributed of interest for the specific operation"]
3003    pub fn get_peer(&self) -> Result<IterablePeer<'a>, ErrorContext> {
3004        let mut iter = self.clone();
3005        iter.pos = 0;
3006        for attr in iter {
3007            if let Ovpn::Peer(val) = attr? {
3008                return Ok(val);
3009            }
3010        }
3011        Err(ErrorContext::new_missing(
3012            "Ovpn",
3013            "Peer",
3014            self.orig_loc,
3015            self.buf.as_ptr() as usize,
3016        ))
3017    }
3018    #[doc = "Peer specific cipher configuration"]
3019    pub fn get_keyconf(&self) -> Result<IterableKeyconf<'a>, ErrorContext> {
3020        let mut iter = self.clone();
3021        iter.pos = 0;
3022        for attr in iter {
3023            if let Ovpn::Keyconf(val) = attr? {
3024                return Ok(val);
3025            }
3026        }
3027        Err(ErrorContext::new_missing(
3028            "Ovpn",
3029            "Keyconf",
3030            self.orig_loc,
3031            self.buf.as_ptr() as usize,
3032        ))
3033    }
3034}
3035impl Ovpn<'_> {
3036    pub fn new<'a>(buf: &'a [u8]) -> IterableOvpn<'a> {
3037        IterableOvpn::with_loc(buf, buf.as_ptr() as usize)
3038    }
3039    fn attr_from_type(r#type: u16) -> Option<&'static str> {
3040        let res = match r#type {
3041            1u16 => "Ifindex",
3042            2u16 => "Peer",
3043            3u16 => "Keyconf",
3044            _ => return None,
3045        };
3046        Some(res)
3047    }
3048}
3049#[derive(Clone, Copy, Default)]
3050pub struct IterableOvpn<'a> {
3051    buf: &'a [u8],
3052    pos: usize,
3053    orig_loc: usize,
3054}
3055impl<'a> IterableOvpn<'a> {
3056    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3057        Self {
3058            buf,
3059            pos: 0,
3060            orig_loc,
3061        }
3062    }
3063    pub fn get_buf(&self) -> &'a [u8] {
3064        self.buf
3065    }
3066}
3067impl<'a> Iterator for IterableOvpn<'a> {
3068    type Item = Result<Ovpn<'a>, ErrorContext>;
3069    fn next(&mut self) -> Option<Self::Item> {
3070        let pos = self.pos;
3071        let mut r#type;
3072        loop {
3073            r#type = None;
3074            if self.buf.len() == self.pos {
3075                return None;
3076            }
3077            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
3078                break;
3079            };
3080            r#type = Some(header.r#type);
3081            let res = match header.r#type {
3082                1u16 => Ovpn::Ifindex({
3083                    let res = parse_u32(next);
3084                    let Some(val) = res else { break };
3085                    val
3086                }),
3087                2u16 => Ovpn::Peer({
3088                    let res = Some(IterablePeer::with_loc(next, self.orig_loc));
3089                    let Some(val) = res else { break };
3090                    val
3091                }),
3092                3u16 => Ovpn::Keyconf({
3093                    let res = Some(IterableKeyconf::with_loc(next, self.orig_loc));
3094                    let Some(val) = res else { break };
3095                    val
3096                }),
3097                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
3098                n => continue,
3099            };
3100            return Some(Ok(res));
3101        }
3102        Some(Err(ErrorContext::new(
3103            "Ovpn",
3104            r#type.and_then(|t| Ovpn::attr_from_type(t)),
3105            self.orig_loc,
3106            self.buf.as_ptr().wrapping_add(pos) as usize,
3107        )))
3108    }
3109}
3110impl<'a> std::fmt::Debug for IterableOvpn<'_> {
3111    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3112        let mut fmt = f.debug_struct("Ovpn");
3113        for attr in self.clone() {
3114            let attr = match attr {
3115                Ok(a) => a,
3116                Err(err) => {
3117                    fmt.finish()?;
3118                    f.write_str("Err(")?;
3119                    err.fmt(f)?;
3120                    return f.write_str(")");
3121                }
3122            };
3123            match attr {
3124                Ovpn::Ifindex(val) => fmt.field("Ifindex", &val),
3125                Ovpn::Peer(val) => fmt.field("Peer", &val),
3126                Ovpn::Keyconf(val) => fmt.field("Keyconf", &val),
3127            };
3128        }
3129        fmt.finish()
3130    }
3131}
3132impl IterableOvpn<'_> {
3133    pub fn lookup_attr(
3134        &self,
3135        offset: usize,
3136        missing_type: Option<u16>,
3137    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3138        let mut stack = Vec::new();
3139        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3140        if missing_type.is_some() && cur == offset {
3141            stack.push(("Ovpn", offset));
3142            return (stack, missing_type.and_then(|t| Ovpn::attr_from_type(t)));
3143        }
3144        if cur > offset || cur + self.buf.len() < offset {
3145            return (stack, None);
3146        }
3147        let mut attrs = self.clone();
3148        let mut last_off = cur + attrs.pos;
3149        let mut missing = None;
3150        while let Some(attr) = attrs.next() {
3151            let Ok(attr) = attr else { break };
3152            match attr {
3153                Ovpn::Ifindex(val) => {
3154                    if last_off == offset {
3155                        stack.push(("Ifindex", last_off));
3156                        break;
3157                    }
3158                }
3159                Ovpn::Peer(val) => {
3160                    (stack, missing) = val.lookup_attr(offset, missing_type);
3161                    if !stack.is_empty() {
3162                        break;
3163                    }
3164                }
3165                Ovpn::Keyconf(val) => {
3166                    (stack, missing) = val.lookup_attr(offset, missing_type);
3167                    if !stack.is_empty() {
3168                        break;
3169                    }
3170                }
3171                _ => {}
3172            };
3173            last_off = cur + attrs.pos;
3174        }
3175        if !stack.is_empty() {
3176            stack.push(("Ovpn", cur));
3177        }
3178        (stack, missing)
3179    }
3180}
3181#[derive(Clone)]
3182pub enum OvpnPeerNewInput<'a> {
3183    #[doc = "Index of the ovpn interface to operate on"]
3184    Ifindex(u32),
3185    #[doc = "The peer object containing the attributed of interest for the specific operation"]
3186    Peer(IterablePeerNewInput<'a>),
3187}
3188impl<'a> IterableOvpnPeerNewInput<'a> {
3189    #[doc = "Index of the ovpn interface to operate on"]
3190    pub fn get_ifindex(&self) -> Result<u32, ErrorContext> {
3191        let mut iter = self.clone();
3192        iter.pos = 0;
3193        for attr in iter {
3194            if let OvpnPeerNewInput::Ifindex(val) = attr? {
3195                return Ok(val);
3196            }
3197        }
3198        Err(ErrorContext::new_missing(
3199            "OvpnPeerNewInput",
3200            "Ifindex",
3201            self.orig_loc,
3202            self.buf.as_ptr() as usize,
3203        ))
3204    }
3205    #[doc = "The peer object containing the attributed of interest for the specific operation"]
3206    pub fn get_peer(&self) -> Result<IterablePeerNewInput<'a>, ErrorContext> {
3207        let mut iter = self.clone();
3208        iter.pos = 0;
3209        for attr in iter {
3210            if let OvpnPeerNewInput::Peer(val) = attr? {
3211                return Ok(val);
3212            }
3213        }
3214        Err(ErrorContext::new_missing(
3215            "OvpnPeerNewInput",
3216            "Peer",
3217            self.orig_loc,
3218            self.buf.as_ptr() as usize,
3219        ))
3220    }
3221}
3222impl OvpnPeerNewInput<'_> {
3223    pub fn new<'a>(buf: &'a [u8]) -> IterableOvpnPeerNewInput<'a> {
3224        IterableOvpnPeerNewInput::with_loc(buf, buf.as_ptr() as usize)
3225    }
3226    fn attr_from_type(r#type: u16) -> Option<&'static str> {
3227        Ovpn::attr_from_type(r#type)
3228    }
3229}
3230#[derive(Clone, Copy, Default)]
3231pub struct IterableOvpnPeerNewInput<'a> {
3232    buf: &'a [u8],
3233    pos: usize,
3234    orig_loc: usize,
3235}
3236impl<'a> IterableOvpnPeerNewInput<'a> {
3237    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3238        Self {
3239            buf,
3240            pos: 0,
3241            orig_loc,
3242        }
3243    }
3244    pub fn get_buf(&self) -> &'a [u8] {
3245        self.buf
3246    }
3247}
3248impl<'a> Iterator for IterableOvpnPeerNewInput<'a> {
3249    type Item = Result<OvpnPeerNewInput<'a>, ErrorContext>;
3250    fn next(&mut self) -> Option<Self::Item> {
3251        let pos = self.pos;
3252        let mut r#type;
3253        loop {
3254            r#type = None;
3255            if self.buf.len() == self.pos {
3256                return None;
3257            }
3258            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
3259                break;
3260            };
3261            r#type = Some(header.r#type);
3262            let res = match header.r#type {
3263                1u16 => OvpnPeerNewInput::Ifindex({
3264                    let res = parse_u32(next);
3265                    let Some(val) = res else { break };
3266                    val
3267                }),
3268                2u16 => OvpnPeerNewInput::Peer({
3269                    let res = Some(IterablePeerNewInput::with_loc(next, self.orig_loc));
3270                    let Some(val) = res else { break };
3271                    val
3272                }),
3273                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
3274                n => continue,
3275            };
3276            return Some(Ok(res));
3277        }
3278        Some(Err(ErrorContext::new(
3279            "OvpnPeerNewInput",
3280            r#type.and_then(|t| OvpnPeerNewInput::attr_from_type(t)),
3281            self.orig_loc,
3282            self.buf.as_ptr().wrapping_add(pos) as usize,
3283        )))
3284    }
3285}
3286impl<'a> std::fmt::Debug for IterableOvpnPeerNewInput<'_> {
3287    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3288        let mut fmt = f.debug_struct("OvpnPeerNewInput");
3289        for attr in self.clone() {
3290            let attr = match attr {
3291                Ok(a) => a,
3292                Err(err) => {
3293                    fmt.finish()?;
3294                    f.write_str("Err(")?;
3295                    err.fmt(f)?;
3296                    return f.write_str(")");
3297                }
3298            };
3299            match attr {
3300                OvpnPeerNewInput::Ifindex(val) => fmt.field("Ifindex", &val),
3301                OvpnPeerNewInput::Peer(val) => fmt.field("Peer", &val),
3302            };
3303        }
3304        fmt.finish()
3305    }
3306}
3307impl IterableOvpnPeerNewInput<'_> {
3308    pub fn lookup_attr(
3309        &self,
3310        offset: usize,
3311        missing_type: Option<u16>,
3312    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3313        let mut stack = Vec::new();
3314        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3315        if missing_type.is_some() && cur == offset {
3316            stack.push(("OvpnPeerNewInput", offset));
3317            return (
3318                stack,
3319                missing_type.and_then(|t| OvpnPeerNewInput::attr_from_type(t)),
3320            );
3321        }
3322        if cur > offset || cur + self.buf.len() < offset {
3323            return (stack, None);
3324        }
3325        let mut attrs = self.clone();
3326        let mut last_off = cur + attrs.pos;
3327        let mut missing = None;
3328        while let Some(attr) = attrs.next() {
3329            let Ok(attr) = attr else { break };
3330            match attr {
3331                OvpnPeerNewInput::Ifindex(val) => {
3332                    if last_off == offset {
3333                        stack.push(("Ifindex", last_off));
3334                        break;
3335                    }
3336                }
3337                OvpnPeerNewInput::Peer(val) => {
3338                    (stack, missing) = val.lookup_attr(offset, missing_type);
3339                    if !stack.is_empty() {
3340                        break;
3341                    }
3342                }
3343                _ => {}
3344            };
3345            last_off = cur + attrs.pos;
3346        }
3347        if !stack.is_empty() {
3348            stack.push(("OvpnPeerNewInput", cur));
3349        }
3350        (stack, missing)
3351    }
3352}
3353#[derive(Clone)]
3354pub enum OvpnPeerSetInput<'a> {
3355    #[doc = "Index of the ovpn interface to operate on"]
3356    Ifindex(u32),
3357    #[doc = "The peer object containing the attributed of interest for the specific operation"]
3358    Peer(IterablePeerSetInput<'a>),
3359}
3360impl<'a> IterableOvpnPeerSetInput<'a> {
3361    #[doc = "Index of the ovpn interface to operate on"]
3362    pub fn get_ifindex(&self) -> Result<u32, ErrorContext> {
3363        let mut iter = self.clone();
3364        iter.pos = 0;
3365        for attr in iter {
3366            if let OvpnPeerSetInput::Ifindex(val) = attr? {
3367                return Ok(val);
3368            }
3369        }
3370        Err(ErrorContext::new_missing(
3371            "OvpnPeerSetInput",
3372            "Ifindex",
3373            self.orig_loc,
3374            self.buf.as_ptr() as usize,
3375        ))
3376    }
3377    #[doc = "The peer object containing the attributed of interest for the specific operation"]
3378    pub fn get_peer(&self) -> Result<IterablePeerSetInput<'a>, ErrorContext> {
3379        let mut iter = self.clone();
3380        iter.pos = 0;
3381        for attr in iter {
3382            if let OvpnPeerSetInput::Peer(val) = attr? {
3383                return Ok(val);
3384            }
3385        }
3386        Err(ErrorContext::new_missing(
3387            "OvpnPeerSetInput",
3388            "Peer",
3389            self.orig_loc,
3390            self.buf.as_ptr() as usize,
3391        ))
3392    }
3393}
3394impl OvpnPeerSetInput<'_> {
3395    pub fn new<'a>(buf: &'a [u8]) -> IterableOvpnPeerSetInput<'a> {
3396        IterableOvpnPeerSetInput::with_loc(buf, buf.as_ptr() as usize)
3397    }
3398    fn attr_from_type(r#type: u16) -> Option<&'static str> {
3399        Ovpn::attr_from_type(r#type)
3400    }
3401}
3402#[derive(Clone, Copy, Default)]
3403pub struct IterableOvpnPeerSetInput<'a> {
3404    buf: &'a [u8],
3405    pos: usize,
3406    orig_loc: usize,
3407}
3408impl<'a> IterableOvpnPeerSetInput<'a> {
3409    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3410        Self {
3411            buf,
3412            pos: 0,
3413            orig_loc,
3414        }
3415    }
3416    pub fn get_buf(&self) -> &'a [u8] {
3417        self.buf
3418    }
3419}
3420impl<'a> Iterator for IterableOvpnPeerSetInput<'a> {
3421    type Item = Result<OvpnPeerSetInput<'a>, ErrorContext>;
3422    fn next(&mut self) -> Option<Self::Item> {
3423        let pos = self.pos;
3424        let mut r#type;
3425        loop {
3426            r#type = None;
3427            if self.buf.len() == self.pos {
3428                return None;
3429            }
3430            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
3431                break;
3432            };
3433            r#type = Some(header.r#type);
3434            let res = match header.r#type {
3435                1u16 => OvpnPeerSetInput::Ifindex({
3436                    let res = parse_u32(next);
3437                    let Some(val) = res else { break };
3438                    val
3439                }),
3440                2u16 => OvpnPeerSetInput::Peer({
3441                    let res = Some(IterablePeerSetInput::with_loc(next, self.orig_loc));
3442                    let Some(val) = res else { break };
3443                    val
3444                }),
3445                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
3446                n => continue,
3447            };
3448            return Some(Ok(res));
3449        }
3450        Some(Err(ErrorContext::new(
3451            "OvpnPeerSetInput",
3452            r#type.and_then(|t| OvpnPeerSetInput::attr_from_type(t)),
3453            self.orig_loc,
3454            self.buf.as_ptr().wrapping_add(pos) as usize,
3455        )))
3456    }
3457}
3458impl<'a> std::fmt::Debug for IterableOvpnPeerSetInput<'_> {
3459    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3460        let mut fmt = f.debug_struct("OvpnPeerSetInput");
3461        for attr in self.clone() {
3462            let attr = match attr {
3463                Ok(a) => a,
3464                Err(err) => {
3465                    fmt.finish()?;
3466                    f.write_str("Err(")?;
3467                    err.fmt(f)?;
3468                    return f.write_str(")");
3469                }
3470            };
3471            match attr {
3472                OvpnPeerSetInput::Ifindex(val) => fmt.field("Ifindex", &val),
3473                OvpnPeerSetInput::Peer(val) => fmt.field("Peer", &val),
3474            };
3475        }
3476        fmt.finish()
3477    }
3478}
3479impl IterableOvpnPeerSetInput<'_> {
3480    pub fn lookup_attr(
3481        &self,
3482        offset: usize,
3483        missing_type: Option<u16>,
3484    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3485        let mut stack = Vec::new();
3486        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3487        if missing_type.is_some() && cur == offset {
3488            stack.push(("OvpnPeerSetInput", offset));
3489            return (
3490                stack,
3491                missing_type.and_then(|t| OvpnPeerSetInput::attr_from_type(t)),
3492            );
3493        }
3494        if cur > offset || cur + self.buf.len() < offset {
3495            return (stack, None);
3496        }
3497        let mut attrs = self.clone();
3498        let mut last_off = cur + attrs.pos;
3499        let mut missing = None;
3500        while let Some(attr) = attrs.next() {
3501            let Ok(attr) = attr else { break };
3502            match attr {
3503                OvpnPeerSetInput::Ifindex(val) => {
3504                    if last_off == offset {
3505                        stack.push(("Ifindex", last_off));
3506                        break;
3507                    }
3508                }
3509                OvpnPeerSetInput::Peer(val) => {
3510                    (stack, missing) = val.lookup_attr(offset, missing_type);
3511                    if !stack.is_empty() {
3512                        break;
3513                    }
3514                }
3515                _ => {}
3516            };
3517            last_off = cur + attrs.pos;
3518        }
3519        if !stack.is_empty() {
3520            stack.push(("OvpnPeerSetInput", cur));
3521        }
3522        (stack, missing)
3523    }
3524}
3525#[derive(Clone)]
3526pub enum OvpnPeerDelInput<'a> {
3527    #[doc = "Index of the ovpn interface to operate on"]
3528    Ifindex(u32),
3529    #[doc = "The peer object containing the attributed of interest for the specific operation"]
3530    Peer(IterablePeerDelInput<'a>),
3531}
3532impl<'a> IterableOvpnPeerDelInput<'a> {
3533    #[doc = "Index of the ovpn interface to operate on"]
3534    pub fn get_ifindex(&self) -> Result<u32, ErrorContext> {
3535        let mut iter = self.clone();
3536        iter.pos = 0;
3537        for attr in iter {
3538            if let OvpnPeerDelInput::Ifindex(val) = attr? {
3539                return Ok(val);
3540            }
3541        }
3542        Err(ErrorContext::new_missing(
3543            "OvpnPeerDelInput",
3544            "Ifindex",
3545            self.orig_loc,
3546            self.buf.as_ptr() as usize,
3547        ))
3548    }
3549    #[doc = "The peer object containing the attributed of interest for the specific operation"]
3550    pub fn get_peer(&self) -> Result<IterablePeerDelInput<'a>, ErrorContext> {
3551        let mut iter = self.clone();
3552        iter.pos = 0;
3553        for attr in iter {
3554            if let OvpnPeerDelInput::Peer(val) = attr? {
3555                return Ok(val);
3556            }
3557        }
3558        Err(ErrorContext::new_missing(
3559            "OvpnPeerDelInput",
3560            "Peer",
3561            self.orig_loc,
3562            self.buf.as_ptr() as usize,
3563        ))
3564    }
3565}
3566impl OvpnPeerDelInput<'_> {
3567    pub fn new<'a>(buf: &'a [u8]) -> IterableOvpnPeerDelInput<'a> {
3568        IterableOvpnPeerDelInput::with_loc(buf, buf.as_ptr() as usize)
3569    }
3570    fn attr_from_type(r#type: u16) -> Option<&'static str> {
3571        Ovpn::attr_from_type(r#type)
3572    }
3573}
3574#[derive(Clone, Copy, Default)]
3575pub struct IterableOvpnPeerDelInput<'a> {
3576    buf: &'a [u8],
3577    pos: usize,
3578    orig_loc: usize,
3579}
3580impl<'a> IterableOvpnPeerDelInput<'a> {
3581    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3582        Self {
3583            buf,
3584            pos: 0,
3585            orig_loc,
3586        }
3587    }
3588    pub fn get_buf(&self) -> &'a [u8] {
3589        self.buf
3590    }
3591}
3592impl<'a> Iterator for IterableOvpnPeerDelInput<'a> {
3593    type Item = Result<OvpnPeerDelInput<'a>, ErrorContext>;
3594    fn next(&mut self) -> Option<Self::Item> {
3595        let pos = self.pos;
3596        let mut r#type;
3597        loop {
3598            r#type = None;
3599            if self.buf.len() == self.pos {
3600                return None;
3601            }
3602            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
3603                break;
3604            };
3605            r#type = Some(header.r#type);
3606            let res = match header.r#type {
3607                1u16 => OvpnPeerDelInput::Ifindex({
3608                    let res = parse_u32(next);
3609                    let Some(val) = res else { break };
3610                    val
3611                }),
3612                2u16 => OvpnPeerDelInput::Peer({
3613                    let res = Some(IterablePeerDelInput::with_loc(next, self.orig_loc));
3614                    let Some(val) = res else { break };
3615                    val
3616                }),
3617                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
3618                n => continue,
3619            };
3620            return Some(Ok(res));
3621        }
3622        Some(Err(ErrorContext::new(
3623            "OvpnPeerDelInput",
3624            r#type.and_then(|t| OvpnPeerDelInput::attr_from_type(t)),
3625            self.orig_loc,
3626            self.buf.as_ptr().wrapping_add(pos) as usize,
3627        )))
3628    }
3629}
3630impl<'a> std::fmt::Debug for IterableOvpnPeerDelInput<'_> {
3631    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3632        let mut fmt = f.debug_struct("OvpnPeerDelInput");
3633        for attr in self.clone() {
3634            let attr = match attr {
3635                Ok(a) => a,
3636                Err(err) => {
3637                    fmt.finish()?;
3638                    f.write_str("Err(")?;
3639                    err.fmt(f)?;
3640                    return f.write_str(")");
3641                }
3642            };
3643            match attr {
3644                OvpnPeerDelInput::Ifindex(val) => fmt.field("Ifindex", &val),
3645                OvpnPeerDelInput::Peer(val) => fmt.field("Peer", &val),
3646            };
3647        }
3648        fmt.finish()
3649    }
3650}
3651impl IterableOvpnPeerDelInput<'_> {
3652    pub fn lookup_attr(
3653        &self,
3654        offset: usize,
3655        missing_type: Option<u16>,
3656    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3657        let mut stack = Vec::new();
3658        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3659        if missing_type.is_some() && cur == offset {
3660            stack.push(("OvpnPeerDelInput", offset));
3661            return (
3662                stack,
3663                missing_type.and_then(|t| OvpnPeerDelInput::attr_from_type(t)),
3664            );
3665        }
3666        if cur > offset || cur + self.buf.len() < offset {
3667            return (stack, None);
3668        }
3669        let mut attrs = self.clone();
3670        let mut last_off = cur + attrs.pos;
3671        let mut missing = None;
3672        while let Some(attr) = attrs.next() {
3673            let Ok(attr) = attr else { break };
3674            match attr {
3675                OvpnPeerDelInput::Ifindex(val) => {
3676                    if last_off == offset {
3677                        stack.push(("Ifindex", last_off));
3678                        break;
3679                    }
3680                }
3681                OvpnPeerDelInput::Peer(val) => {
3682                    (stack, missing) = val.lookup_attr(offset, missing_type);
3683                    if !stack.is_empty() {
3684                        break;
3685                    }
3686                }
3687                _ => {}
3688            };
3689            last_off = cur + attrs.pos;
3690        }
3691        if !stack.is_empty() {
3692            stack.push(("OvpnPeerDelInput", cur));
3693        }
3694        (stack, missing)
3695    }
3696}
3697#[derive(Clone)]
3698pub enum OvpnKeyconfGet<'a> {
3699    #[doc = "Index of the ovpn interface to operate on"]
3700    Ifindex(u32),
3701    #[doc = "Peer specific cipher configuration"]
3702    Keyconf(IterableKeyconfGet<'a>),
3703}
3704impl<'a> IterableOvpnKeyconfGet<'a> {
3705    #[doc = "Index of the ovpn interface to operate on"]
3706    pub fn get_ifindex(&self) -> Result<u32, ErrorContext> {
3707        let mut iter = self.clone();
3708        iter.pos = 0;
3709        for attr in iter {
3710            if let OvpnKeyconfGet::Ifindex(val) = attr? {
3711                return Ok(val);
3712            }
3713        }
3714        Err(ErrorContext::new_missing(
3715            "OvpnKeyconfGet",
3716            "Ifindex",
3717            self.orig_loc,
3718            self.buf.as_ptr() as usize,
3719        ))
3720    }
3721    #[doc = "Peer specific cipher configuration"]
3722    pub fn get_keyconf(&self) -> Result<IterableKeyconfGet<'a>, ErrorContext> {
3723        let mut iter = self.clone();
3724        iter.pos = 0;
3725        for attr in iter {
3726            if let OvpnKeyconfGet::Keyconf(val) = attr? {
3727                return Ok(val);
3728            }
3729        }
3730        Err(ErrorContext::new_missing(
3731            "OvpnKeyconfGet",
3732            "Keyconf",
3733            self.orig_loc,
3734            self.buf.as_ptr() as usize,
3735        ))
3736    }
3737}
3738impl OvpnKeyconfGet<'_> {
3739    pub fn new<'a>(buf: &'a [u8]) -> IterableOvpnKeyconfGet<'a> {
3740        IterableOvpnKeyconfGet::with_loc(buf, buf.as_ptr() as usize)
3741    }
3742    fn attr_from_type(r#type: u16) -> Option<&'static str> {
3743        Ovpn::attr_from_type(r#type)
3744    }
3745}
3746#[derive(Clone, Copy, Default)]
3747pub struct IterableOvpnKeyconfGet<'a> {
3748    buf: &'a [u8],
3749    pos: usize,
3750    orig_loc: usize,
3751}
3752impl<'a> IterableOvpnKeyconfGet<'a> {
3753    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3754        Self {
3755            buf,
3756            pos: 0,
3757            orig_loc,
3758        }
3759    }
3760    pub fn get_buf(&self) -> &'a [u8] {
3761        self.buf
3762    }
3763}
3764impl<'a> Iterator for IterableOvpnKeyconfGet<'a> {
3765    type Item = Result<OvpnKeyconfGet<'a>, ErrorContext>;
3766    fn next(&mut self) -> Option<Self::Item> {
3767        let pos = self.pos;
3768        let mut r#type;
3769        loop {
3770            r#type = None;
3771            if self.buf.len() == self.pos {
3772                return None;
3773            }
3774            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
3775                break;
3776            };
3777            r#type = Some(header.r#type);
3778            let res = match header.r#type {
3779                1u16 => OvpnKeyconfGet::Ifindex({
3780                    let res = parse_u32(next);
3781                    let Some(val) = res else { break };
3782                    val
3783                }),
3784                3u16 => OvpnKeyconfGet::Keyconf({
3785                    let res = Some(IterableKeyconfGet::with_loc(next, self.orig_loc));
3786                    let Some(val) = res else { break };
3787                    val
3788                }),
3789                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
3790                n => continue,
3791            };
3792            return Some(Ok(res));
3793        }
3794        Some(Err(ErrorContext::new(
3795            "OvpnKeyconfGet",
3796            r#type.and_then(|t| OvpnKeyconfGet::attr_from_type(t)),
3797            self.orig_loc,
3798            self.buf.as_ptr().wrapping_add(pos) as usize,
3799        )))
3800    }
3801}
3802impl<'a> std::fmt::Debug for IterableOvpnKeyconfGet<'_> {
3803    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3804        let mut fmt = f.debug_struct("OvpnKeyconfGet");
3805        for attr in self.clone() {
3806            let attr = match attr {
3807                Ok(a) => a,
3808                Err(err) => {
3809                    fmt.finish()?;
3810                    f.write_str("Err(")?;
3811                    err.fmt(f)?;
3812                    return f.write_str(")");
3813                }
3814            };
3815            match attr {
3816                OvpnKeyconfGet::Ifindex(val) => fmt.field("Ifindex", &val),
3817                OvpnKeyconfGet::Keyconf(val) => fmt.field("Keyconf", &val),
3818            };
3819        }
3820        fmt.finish()
3821    }
3822}
3823impl IterableOvpnKeyconfGet<'_> {
3824    pub fn lookup_attr(
3825        &self,
3826        offset: usize,
3827        missing_type: Option<u16>,
3828    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
3829        let mut stack = Vec::new();
3830        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
3831        if missing_type.is_some() && cur == offset {
3832            stack.push(("OvpnKeyconfGet", offset));
3833            return (
3834                stack,
3835                missing_type.and_then(|t| OvpnKeyconfGet::attr_from_type(t)),
3836            );
3837        }
3838        if cur > offset || cur + self.buf.len() < offset {
3839            return (stack, None);
3840        }
3841        let mut attrs = self.clone();
3842        let mut last_off = cur + attrs.pos;
3843        let mut missing = None;
3844        while let Some(attr) = attrs.next() {
3845            let Ok(attr) = attr else { break };
3846            match attr {
3847                OvpnKeyconfGet::Ifindex(val) => {
3848                    if last_off == offset {
3849                        stack.push(("Ifindex", last_off));
3850                        break;
3851                    }
3852                }
3853                OvpnKeyconfGet::Keyconf(val) => {
3854                    (stack, missing) = val.lookup_attr(offset, missing_type);
3855                    if !stack.is_empty() {
3856                        break;
3857                    }
3858                }
3859                _ => {}
3860            };
3861            last_off = cur + attrs.pos;
3862        }
3863        if !stack.is_empty() {
3864            stack.push(("OvpnKeyconfGet", cur));
3865        }
3866        (stack, missing)
3867    }
3868}
3869#[derive(Clone)]
3870pub enum OvpnKeyconfSwapInput<'a> {
3871    #[doc = "Index of the ovpn interface to operate on"]
3872    Ifindex(u32),
3873    #[doc = "Peer specific cipher configuration"]
3874    Keyconf(IterableKeyconfSwapInput<'a>),
3875}
3876impl<'a> IterableOvpnKeyconfSwapInput<'a> {
3877    #[doc = "Index of the ovpn interface to operate on"]
3878    pub fn get_ifindex(&self) -> Result<u32, ErrorContext> {
3879        let mut iter = self.clone();
3880        iter.pos = 0;
3881        for attr in iter {
3882            if let OvpnKeyconfSwapInput::Ifindex(val) = attr? {
3883                return Ok(val);
3884            }
3885        }
3886        Err(ErrorContext::new_missing(
3887            "OvpnKeyconfSwapInput",
3888            "Ifindex",
3889            self.orig_loc,
3890            self.buf.as_ptr() as usize,
3891        ))
3892    }
3893    #[doc = "Peer specific cipher configuration"]
3894    pub fn get_keyconf(&self) -> Result<IterableKeyconfSwapInput<'a>, ErrorContext> {
3895        let mut iter = self.clone();
3896        iter.pos = 0;
3897        for attr in iter {
3898            if let OvpnKeyconfSwapInput::Keyconf(val) = attr? {
3899                return Ok(val);
3900            }
3901        }
3902        Err(ErrorContext::new_missing(
3903            "OvpnKeyconfSwapInput",
3904            "Keyconf",
3905            self.orig_loc,
3906            self.buf.as_ptr() as usize,
3907        ))
3908    }
3909}
3910impl OvpnKeyconfSwapInput<'_> {
3911    pub fn new<'a>(buf: &'a [u8]) -> IterableOvpnKeyconfSwapInput<'a> {
3912        IterableOvpnKeyconfSwapInput::with_loc(buf, buf.as_ptr() as usize)
3913    }
3914    fn attr_from_type(r#type: u16) -> Option<&'static str> {
3915        Ovpn::attr_from_type(r#type)
3916    }
3917}
3918#[derive(Clone, Copy, Default)]
3919pub struct IterableOvpnKeyconfSwapInput<'a> {
3920    buf: &'a [u8],
3921    pos: usize,
3922    orig_loc: usize,
3923}
3924impl<'a> IterableOvpnKeyconfSwapInput<'a> {
3925    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
3926        Self {
3927            buf,
3928            pos: 0,
3929            orig_loc,
3930        }
3931    }
3932    pub fn get_buf(&self) -> &'a [u8] {
3933        self.buf
3934    }
3935}
3936impl<'a> Iterator for IterableOvpnKeyconfSwapInput<'a> {
3937    type Item = Result<OvpnKeyconfSwapInput<'a>, ErrorContext>;
3938    fn next(&mut self) -> Option<Self::Item> {
3939        let pos = self.pos;
3940        let mut r#type;
3941        loop {
3942            r#type = None;
3943            if self.buf.len() == self.pos {
3944                return None;
3945            }
3946            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
3947                break;
3948            };
3949            r#type = Some(header.r#type);
3950            let res = match header.r#type {
3951                1u16 => OvpnKeyconfSwapInput::Ifindex({
3952                    let res = parse_u32(next);
3953                    let Some(val) = res else { break };
3954                    val
3955                }),
3956                3u16 => OvpnKeyconfSwapInput::Keyconf({
3957                    let res = Some(IterableKeyconfSwapInput::with_loc(next, self.orig_loc));
3958                    let Some(val) = res else { break };
3959                    val
3960                }),
3961                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
3962                n => continue,
3963            };
3964            return Some(Ok(res));
3965        }
3966        Some(Err(ErrorContext::new(
3967            "OvpnKeyconfSwapInput",
3968            r#type.and_then(|t| OvpnKeyconfSwapInput::attr_from_type(t)),
3969            self.orig_loc,
3970            self.buf.as_ptr().wrapping_add(pos) as usize,
3971        )))
3972    }
3973}
3974impl<'a> std::fmt::Debug for IterableOvpnKeyconfSwapInput<'_> {
3975    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3976        let mut fmt = f.debug_struct("OvpnKeyconfSwapInput");
3977        for attr in self.clone() {
3978            let attr = match attr {
3979                Ok(a) => a,
3980                Err(err) => {
3981                    fmt.finish()?;
3982                    f.write_str("Err(")?;
3983                    err.fmt(f)?;
3984                    return f.write_str(")");
3985                }
3986            };
3987            match attr {
3988                OvpnKeyconfSwapInput::Ifindex(val) => fmt.field("Ifindex", &val),
3989                OvpnKeyconfSwapInput::Keyconf(val) => fmt.field("Keyconf", &val),
3990            };
3991        }
3992        fmt.finish()
3993    }
3994}
3995impl IterableOvpnKeyconfSwapInput<'_> {
3996    pub fn lookup_attr(
3997        &self,
3998        offset: usize,
3999        missing_type: Option<u16>,
4000    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
4001        let mut stack = Vec::new();
4002        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
4003        if missing_type.is_some() && cur == offset {
4004            stack.push(("OvpnKeyconfSwapInput", offset));
4005            return (
4006                stack,
4007                missing_type.and_then(|t| OvpnKeyconfSwapInput::attr_from_type(t)),
4008            );
4009        }
4010        if cur > offset || cur + self.buf.len() < offset {
4011            return (stack, None);
4012        }
4013        let mut attrs = self.clone();
4014        let mut last_off = cur + attrs.pos;
4015        let mut missing = None;
4016        while let Some(attr) = attrs.next() {
4017            let Ok(attr) = attr else { break };
4018            match attr {
4019                OvpnKeyconfSwapInput::Ifindex(val) => {
4020                    if last_off == offset {
4021                        stack.push(("Ifindex", last_off));
4022                        break;
4023                    }
4024                }
4025                OvpnKeyconfSwapInput::Keyconf(val) => {
4026                    (stack, missing) = val.lookup_attr(offset, missing_type);
4027                    if !stack.is_empty() {
4028                        break;
4029                    }
4030                }
4031                _ => {}
4032            };
4033            last_off = cur + attrs.pos;
4034        }
4035        if !stack.is_empty() {
4036            stack.push(("OvpnKeyconfSwapInput", cur));
4037        }
4038        (stack, missing)
4039    }
4040}
4041#[derive(Clone)]
4042pub enum OvpnKeyconfDelInput<'a> {
4043    #[doc = "Index of the ovpn interface to operate on"]
4044    Ifindex(u32),
4045    #[doc = "Peer specific cipher configuration"]
4046    Keyconf(IterableKeyconfDelInput<'a>),
4047}
4048impl<'a> IterableOvpnKeyconfDelInput<'a> {
4049    #[doc = "Index of the ovpn interface to operate on"]
4050    pub fn get_ifindex(&self) -> Result<u32, ErrorContext> {
4051        let mut iter = self.clone();
4052        iter.pos = 0;
4053        for attr in iter {
4054            if let OvpnKeyconfDelInput::Ifindex(val) = attr? {
4055                return Ok(val);
4056            }
4057        }
4058        Err(ErrorContext::new_missing(
4059            "OvpnKeyconfDelInput",
4060            "Ifindex",
4061            self.orig_loc,
4062            self.buf.as_ptr() as usize,
4063        ))
4064    }
4065    #[doc = "Peer specific cipher configuration"]
4066    pub fn get_keyconf(&self) -> Result<IterableKeyconfDelInput<'a>, ErrorContext> {
4067        let mut iter = self.clone();
4068        iter.pos = 0;
4069        for attr in iter {
4070            if let OvpnKeyconfDelInput::Keyconf(val) = attr? {
4071                return Ok(val);
4072            }
4073        }
4074        Err(ErrorContext::new_missing(
4075            "OvpnKeyconfDelInput",
4076            "Keyconf",
4077            self.orig_loc,
4078            self.buf.as_ptr() as usize,
4079        ))
4080    }
4081}
4082impl OvpnKeyconfDelInput<'_> {
4083    pub fn new<'a>(buf: &'a [u8]) -> IterableOvpnKeyconfDelInput<'a> {
4084        IterableOvpnKeyconfDelInput::with_loc(buf, buf.as_ptr() as usize)
4085    }
4086    fn attr_from_type(r#type: u16) -> Option<&'static str> {
4087        Ovpn::attr_from_type(r#type)
4088    }
4089}
4090#[derive(Clone, Copy, Default)]
4091pub struct IterableOvpnKeyconfDelInput<'a> {
4092    buf: &'a [u8],
4093    pos: usize,
4094    orig_loc: usize,
4095}
4096impl<'a> IterableOvpnKeyconfDelInput<'a> {
4097    fn with_loc(buf: &'a [u8], orig_loc: usize) -> Self {
4098        Self {
4099            buf,
4100            pos: 0,
4101            orig_loc,
4102        }
4103    }
4104    pub fn get_buf(&self) -> &'a [u8] {
4105        self.buf
4106    }
4107}
4108impl<'a> Iterator for IterableOvpnKeyconfDelInput<'a> {
4109    type Item = Result<OvpnKeyconfDelInput<'a>, ErrorContext>;
4110    fn next(&mut self) -> Option<Self::Item> {
4111        let pos = self.pos;
4112        let mut r#type;
4113        loop {
4114            r#type = None;
4115            if self.buf.len() == self.pos {
4116                return None;
4117            }
4118            let Some((header, next)) = chop_header(self.buf, &mut self.pos) else {
4119                break;
4120            };
4121            r#type = Some(header.r#type);
4122            let res = match header.r#type {
4123                1u16 => OvpnKeyconfDelInput::Ifindex({
4124                    let res = parse_u32(next);
4125                    let Some(val) = res else { break };
4126                    val
4127                }),
4128                3u16 => OvpnKeyconfDelInput::Keyconf({
4129                    let res = Some(IterableKeyconfDelInput::with_loc(next, self.orig_loc));
4130                    let Some(val) = res else { break };
4131                    val
4132                }),
4133                n if cfg!(any(test, feature = "deny-unknown-attrs")) => break,
4134                n => continue,
4135            };
4136            return Some(Ok(res));
4137        }
4138        Some(Err(ErrorContext::new(
4139            "OvpnKeyconfDelInput",
4140            r#type.and_then(|t| OvpnKeyconfDelInput::attr_from_type(t)),
4141            self.orig_loc,
4142            self.buf.as_ptr().wrapping_add(pos) as usize,
4143        )))
4144    }
4145}
4146impl<'a> std::fmt::Debug for IterableOvpnKeyconfDelInput<'_> {
4147    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4148        let mut fmt = f.debug_struct("OvpnKeyconfDelInput");
4149        for attr in self.clone() {
4150            let attr = match attr {
4151                Ok(a) => a,
4152                Err(err) => {
4153                    fmt.finish()?;
4154                    f.write_str("Err(")?;
4155                    err.fmt(f)?;
4156                    return f.write_str(")");
4157                }
4158            };
4159            match attr {
4160                OvpnKeyconfDelInput::Ifindex(val) => fmt.field("Ifindex", &val),
4161                OvpnKeyconfDelInput::Keyconf(val) => fmt.field("Keyconf", &val),
4162            };
4163        }
4164        fmt.finish()
4165    }
4166}
4167impl IterableOvpnKeyconfDelInput<'_> {
4168    pub fn lookup_attr(
4169        &self,
4170        offset: usize,
4171        missing_type: Option<u16>,
4172    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
4173        let mut stack = Vec::new();
4174        let cur = ErrorContext::calc_offset(self.orig_loc, self.buf.as_ptr() as usize);
4175        if missing_type.is_some() && cur == offset {
4176            stack.push(("OvpnKeyconfDelInput", offset));
4177            return (
4178                stack,
4179                missing_type.and_then(|t| OvpnKeyconfDelInput::attr_from_type(t)),
4180            );
4181        }
4182        if cur > offset || cur + self.buf.len() < offset {
4183            return (stack, None);
4184        }
4185        let mut attrs = self.clone();
4186        let mut last_off = cur + attrs.pos;
4187        let mut missing = None;
4188        while let Some(attr) = attrs.next() {
4189            let Ok(attr) = attr else { break };
4190            match attr {
4191                OvpnKeyconfDelInput::Ifindex(val) => {
4192                    if last_off == offset {
4193                        stack.push(("Ifindex", last_off));
4194                        break;
4195                    }
4196                }
4197                OvpnKeyconfDelInput::Keyconf(val) => {
4198                    (stack, missing) = val.lookup_attr(offset, missing_type);
4199                    if !stack.is_empty() {
4200                        break;
4201                    }
4202                }
4203                _ => {}
4204            };
4205            last_off = cur + attrs.pos;
4206        }
4207        if !stack.is_empty() {
4208            stack.push(("OvpnKeyconfDelInput", cur));
4209        }
4210        (stack, missing)
4211    }
4212}
4213pub struct PushPeer<Prev: Rec> {
4214    pub(crate) prev: Option<Prev>,
4215    pub(crate) header_offset: Option<usize>,
4216}
4217impl<Prev: Rec> Rec for PushPeer<Prev> {
4218    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4219        self.prev.as_mut().unwrap().as_rec_mut()
4220    }
4221    fn as_rec(&self) -> &Vec<u8> {
4222        self.prev.as_ref().unwrap().as_rec()
4223    }
4224}
4225impl<Prev: Rec> PushPeer<Prev> {
4226    pub fn new(prev: Prev) -> Self {
4227        Self {
4228            prev: Some(prev),
4229            header_offset: None,
4230        }
4231    }
4232    pub fn end_nested(mut self) -> Prev {
4233        let mut prev = self.prev.take().unwrap();
4234        if let Some(header_offset) = &self.header_offset {
4235            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4236        }
4237        prev
4238    }
4239    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
4240    pub fn push_id(mut self, value: u32) -> Self {
4241        push_header(self.as_rec_mut(), 1u16, 4 as u16);
4242        self.as_rec_mut().extend(value.to_ne_bytes());
4243        self
4244    }
4245    #[doc = "The remote IPv4 address of the peer"]
4246    pub fn push_remote_ipv4(mut self, value: std::net::Ipv4Addr) -> Self {
4247        push_header(self.as_rec_mut(), 2u16, 4 as u16);
4248        self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
4249        self
4250    }
4251    #[doc = "The remote IPv6 address of the peer"]
4252    pub fn push_remote_ipv6(mut self, value: &[u8]) -> Self {
4253        push_header(self.as_rec_mut(), 3u16, value.len() as u16);
4254        self.as_rec_mut().extend(value);
4255        self
4256    }
4257    #[doc = "The scope id of the remote IPv6 address of the peer (RFC2553)"]
4258    pub fn push_remote_ipv6_scope_id(mut self, value: u32) -> Self {
4259        push_header(self.as_rec_mut(), 4u16, 4 as u16);
4260        self.as_rec_mut().extend(value.to_ne_bytes());
4261        self
4262    }
4263    #[doc = "The remote port of the peer"]
4264    pub fn push_remote_port(mut self, value: u16) -> Self {
4265        push_header(self.as_rec_mut(), 5u16, 2 as u16);
4266        self.as_rec_mut().extend(value.to_be_bytes());
4267        self
4268    }
4269    #[doc = "The socket to be used to communicate with the peer"]
4270    pub fn push_socket(mut self, value: u32) -> Self {
4271        push_header(self.as_rec_mut(), 6u16, 4 as u16);
4272        self.as_rec_mut().extend(value.to_ne_bytes());
4273        self
4274    }
4275    #[doc = "The ID of the netns the socket assigned to this peer lives in"]
4276    pub fn push_socket_netnsid(mut self, value: i32) -> Self {
4277        push_header(self.as_rec_mut(), 7u16, 4 as u16);
4278        self.as_rec_mut().extend(value.to_ne_bytes());
4279        self
4280    }
4281    #[doc = "The IPv4 address assigned to the peer by the server"]
4282    pub fn push_vpn_ipv4(mut self, value: std::net::Ipv4Addr) -> Self {
4283        push_header(self.as_rec_mut(), 8u16, 4 as u16);
4284        self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
4285        self
4286    }
4287    #[doc = "The IPv6 address assigned to the peer by the server"]
4288    pub fn push_vpn_ipv6(mut self, value: &[u8]) -> Self {
4289        push_header(self.as_rec_mut(), 9u16, value.len() as u16);
4290        self.as_rec_mut().extend(value);
4291        self
4292    }
4293    #[doc = "The local IPv4 to be used to send packets to the peer (UDP only)"]
4294    pub fn push_local_ipv4(mut self, value: std::net::Ipv4Addr) -> Self {
4295        push_header(self.as_rec_mut(), 10u16, 4 as u16);
4296        self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
4297        self
4298    }
4299    #[doc = "The local IPv6 to be used to send packets to the peer (UDP only)"]
4300    pub fn push_local_ipv6(mut self, value: &[u8]) -> Self {
4301        push_header(self.as_rec_mut(), 11u16, value.len() as u16);
4302        self.as_rec_mut().extend(value);
4303        self
4304    }
4305    #[doc = "The local port to be used to send packets to the peer (UDP only)"]
4306    pub fn push_local_port(mut self, value: u16) -> Self {
4307        push_header(self.as_rec_mut(), 12u16, 2 as u16);
4308        self.as_rec_mut().extend(value.to_be_bytes());
4309        self
4310    }
4311    #[doc = "The number of seconds after which a keep alive message is sent to the peer"]
4312    pub fn push_keepalive_interval(mut self, value: u32) -> Self {
4313        push_header(self.as_rec_mut(), 13u16, 4 as u16);
4314        self.as_rec_mut().extend(value.to_ne_bytes());
4315        self
4316    }
4317    #[doc = "The number of seconds from the last activity after which the peer is assumed dead"]
4318    pub fn push_keepalive_timeout(mut self, value: u32) -> Self {
4319        push_header(self.as_rec_mut(), 14u16, 4 as u16);
4320        self.as_rec_mut().extend(value.to_ne_bytes());
4321        self
4322    }
4323    #[doc = "The reason why a peer was deleted\nAssociated type: [`DelPeerReason`] (enum)"]
4324    pub fn push_del_reason(mut self, value: u32) -> Self {
4325        push_header(self.as_rec_mut(), 15u16, 4 as u16);
4326        self.as_rec_mut().extend(value.to_ne_bytes());
4327        self
4328    }
4329    #[doc = "Number of bytes received over the tunnel"]
4330    pub fn push_vpn_rx_bytes(mut self, value: u32) -> Self {
4331        push_header(self.as_rec_mut(), 16u16, 4 as u16);
4332        self.as_rec_mut().extend(value.to_ne_bytes());
4333        self
4334    }
4335    #[doc = "Number of bytes transmitted over the tunnel"]
4336    pub fn push_vpn_tx_bytes(mut self, value: u32) -> Self {
4337        push_header(self.as_rec_mut(), 17u16, 4 as u16);
4338        self.as_rec_mut().extend(value.to_ne_bytes());
4339        self
4340    }
4341    #[doc = "Number of packets received over the tunnel"]
4342    pub fn push_vpn_rx_packets(mut self, value: u32) -> Self {
4343        push_header(self.as_rec_mut(), 18u16, 4 as u16);
4344        self.as_rec_mut().extend(value.to_ne_bytes());
4345        self
4346    }
4347    #[doc = "Number of packets transmitted over the tunnel"]
4348    pub fn push_vpn_tx_packets(mut self, value: u32) -> Self {
4349        push_header(self.as_rec_mut(), 19u16, 4 as u16);
4350        self.as_rec_mut().extend(value.to_ne_bytes());
4351        self
4352    }
4353    #[doc = "Number of bytes received at the transport level"]
4354    pub fn push_link_rx_bytes(mut self, value: u32) -> Self {
4355        push_header(self.as_rec_mut(), 20u16, 4 as u16);
4356        self.as_rec_mut().extend(value.to_ne_bytes());
4357        self
4358    }
4359    #[doc = "Number of bytes transmitted at the transport level"]
4360    pub fn push_link_tx_bytes(mut self, value: u32) -> Self {
4361        push_header(self.as_rec_mut(), 21u16, 4 as u16);
4362        self.as_rec_mut().extend(value.to_ne_bytes());
4363        self
4364    }
4365    #[doc = "Number of packets received at the transport level"]
4366    pub fn push_link_rx_packets(mut self, value: u32) -> Self {
4367        push_header(self.as_rec_mut(), 22u16, 4 as u16);
4368        self.as_rec_mut().extend(value.to_ne_bytes());
4369        self
4370    }
4371    #[doc = "Number of packets transmitted at the transport level"]
4372    pub fn push_link_tx_packets(mut self, value: u32) -> Self {
4373        push_header(self.as_rec_mut(), 23u16, 4 as u16);
4374        self.as_rec_mut().extend(value.to_ne_bytes());
4375        self
4376    }
4377}
4378impl<Prev: Rec> Drop for PushPeer<Prev> {
4379    fn drop(&mut self) {
4380        if let Some(prev) = &mut self.prev {
4381            if let Some(header_offset) = &self.header_offset {
4382                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4383            }
4384        }
4385    }
4386}
4387pub struct PushPeerNewInput<Prev: Rec> {
4388    pub(crate) prev: Option<Prev>,
4389    pub(crate) header_offset: Option<usize>,
4390}
4391impl<Prev: Rec> Rec for PushPeerNewInput<Prev> {
4392    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4393        self.prev.as_mut().unwrap().as_rec_mut()
4394    }
4395    fn as_rec(&self) -> &Vec<u8> {
4396        self.prev.as_ref().unwrap().as_rec()
4397    }
4398}
4399impl<Prev: Rec> PushPeerNewInput<Prev> {
4400    pub fn new(prev: Prev) -> Self {
4401        Self {
4402            prev: Some(prev),
4403            header_offset: None,
4404        }
4405    }
4406    pub fn end_nested(mut self) -> Prev {
4407        let mut prev = self.prev.take().unwrap();
4408        if let Some(header_offset) = &self.header_offset {
4409            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4410        }
4411        prev
4412    }
4413    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
4414    pub fn push_id(mut self, value: u32) -> Self {
4415        push_header(self.as_rec_mut(), 1u16, 4 as u16);
4416        self.as_rec_mut().extend(value.to_ne_bytes());
4417        self
4418    }
4419    #[doc = "The remote IPv4 address of the peer"]
4420    pub fn push_remote_ipv4(mut self, value: std::net::Ipv4Addr) -> Self {
4421        push_header(self.as_rec_mut(), 2u16, 4 as u16);
4422        self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
4423        self
4424    }
4425    #[doc = "The remote IPv6 address of the peer"]
4426    pub fn push_remote_ipv6(mut self, value: &[u8]) -> Self {
4427        push_header(self.as_rec_mut(), 3u16, value.len() as u16);
4428        self.as_rec_mut().extend(value);
4429        self
4430    }
4431    #[doc = "The scope id of the remote IPv6 address of the peer (RFC2553)"]
4432    pub fn push_remote_ipv6_scope_id(mut self, value: u32) -> Self {
4433        push_header(self.as_rec_mut(), 4u16, 4 as u16);
4434        self.as_rec_mut().extend(value.to_ne_bytes());
4435        self
4436    }
4437    #[doc = "The remote port of the peer"]
4438    pub fn push_remote_port(mut self, value: u16) -> Self {
4439        push_header(self.as_rec_mut(), 5u16, 2 as u16);
4440        self.as_rec_mut().extend(value.to_be_bytes());
4441        self
4442    }
4443    #[doc = "The socket to be used to communicate with the peer"]
4444    pub fn push_socket(mut self, value: u32) -> Self {
4445        push_header(self.as_rec_mut(), 6u16, 4 as u16);
4446        self.as_rec_mut().extend(value.to_ne_bytes());
4447        self
4448    }
4449    #[doc = "The IPv4 address assigned to the peer by the server"]
4450    pub fn push_vpn_ipv4(mut self, value: std::net::Ipv4Addr) -> Self {
4451        push_header(self.as_rec_mut(), 8u16, 4 as u16);
4452        self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
4453        self
4454    }
4455    #[doc = "The IPv6 address assigned to the peer by the server"]
4456    pub fn push_vpn_ipv6(mut self, value: &[u8]) -> Self {
4457        push_header(self.as_rec_mut(), 9u16, value.len() as u16);
4458        self.as_rec_mut().extend(value);
4459        self
4460    }
4461    #[doc = "The local IPv4 to be used to send packets to the peer (UDP only)"]
4462    pub fn push_local_ipv4(mut self, value: std::net::Ipv4Addr) -> Self {
4463        push_header(self.as_rec_mut(), 10u16, 4 as u16);
4464        self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
4465        self
4466    }
4467    #[doc = "The local IPv6 to be used to send packets to the peer (UDP only)"]
4468    pub fn push_local_ipv6(mut self, value: &[u8]) -> Self {
4469        push_header(self.as_rec_mut(), 11u16, value.len() as u16);
4470        self.as_rec_mut().extend(value);
4471        self
4472    }
4473    #[doc = "The number of seconds after which a keep alive message is sent to the peer"]
4474    pub fn push_keepalive_interval(mut self, value: u32) -> Self {
4475        push_header(self.as_rec_mut(), 13u16, 4 as u16);
4476        self.as_rec_mut().extend(value.to_ne_bytes());
4477        self
4478    }
4479    #[doc = "The number of seconds from the last activity after which the peer is assumed dead"]
4480    pub fn push_keepalive_timeout(mut self, value: u32) -> Self {
4481        push_header(self.as_rec_mut(), 14u16, 4 as u16);
4482        self.as_rec_mut().extend(value.to_ne_bytes());
4483        self
4484    }
4485}
4486impl<Prev: Rec> Drop for PushPeerNewInput<Prev> {
4487    fn drop(&mut self) {
4488        if let Some(prev) = &mut self.prev {
4489            if let Some(header_offset) = &self.header_offset {
4490                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4491            }
4492        }
4493    }
4494}
4495pub struct PushPeerSetInput<Prev: Rec> {
4496    pub(crate) prev: Option<Prev>,
4497    pub(crate) header_offset: Option<usize>,
4498}
4499impl<Prev: Rec> Rec for PushPeerSetInput<Prev> {
4500    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4501        self.prev.as_mut().unwrap().as_rec_mut()
4502    }
4503    fn as_rec(&self) -> &Vec<u8> {
4504        self.prev.as_ref().unwrap().as_rec()
4505    }
4506}
4507impl<Prev: Rec> PushPeerSetInput<Prev> {
4508    pub fn new(prev: Prev) -> Self {
4509        Self {
4510            prev: Some(prev),
4511            header_offset: None,
4512        }
4513    }
4514    pub fn end_nested(mut self) -> Prev {
4515        let mut prev = self.prev.take().unwrap();
4516        if let Some(header_offset) = &self.header_offset {
4517            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4518        }
4519        prev
4520    }
4521    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
4522    pub fn push_id(mut self, value: u32) -> Self {
4523        push_header(self.as_rec_mut(), 1u16, 4 as u16);
4524        self.as_rec_mut().extend(value.to_ne_bytes());
4525        self
4526    }
4527    #[doc = "The remote IPv4 address of the peer"]
4528    pub fn push_remote_ipv4(mut self, value: std::net::Ipv4Addr) -> Self {
4529        push_header(self.as_rec_mut(), 2u16, 4 as u16);
4530        self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
4531        self
4532    }
4533    #[doc = "The remote IPv6 address of the peer"]
4534    pub fn push_remote_ipv6(mut self, value: &[u8]) -> Self {
4535        push_header(self.as_rec_mut(), 3u16, value.len() as u16);
4536        self.as_rec_mut().extend(value);
4537        self
4538    }
4539    #[doc = "The scope id of the remote IPv6 address of the peer (RFC2553)"]
4540    pub fn push_remote_ipv6_scope_id(mut self, value: u32) -> Self {
4541        push_header(self.as_rec_mut(), 4u16, 4 as u16);
4542        self.as_rec_mut().extend(value.to_ne_bytes());
4543        self
4544    }
4545    #[doc = "The remote port of the peer"]
4546    pub fn push_remote_port(mut self, value: u16) -> Self {
4547        push_header(self.as_rec_mut(), 5u16, 2 as u16);
4548        self.as_rec_mut().extend(value.to_be_bytes());
4549        self
4550    }
4551    #[doc = "The IPv4 address assigned to the peer by the server"]
4552    pub fn push_vpn_ipv4(mut self, value: std::net::Ipv4Addr) -> Self {
4553        push_header(self.as_rec_mut(), 8u16, 4 as u16);
4554        self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
4555        self
4556    }
4557    #[doc = "The IPv6 address assigned to the peer by the server"]
4558    pub fn push_vpn_ipv6(mut self, value: &[u8]) -> Self {
4559        push_header(self.as_rec_mut(), 9u16, value.len() as u16);
4560        self.as_rec_mut().extend(value);
4561        self
4562    }
4563    #[doc = "The local IPv4 to be used to send packets to the peer (UDP only)"]
4564    pub fn push_local_ipv4(mut self, value: std::net::Ipv4Addr) -> Self {
4565        push_header(self.as_rec_mut(), 10u16, 4 as u16);
4566        self.as_rec_mut().extend(&value.to_bits().to_be_bytes());
4567        self
4568    }
4569    #[doc = "The local IPv6 to be used to send packets to the peer (UDP only)"]
4570    pub fn push_local_ipv6(mut self, value: &[u8]) -> Self {
4571        push_header(self.as_rec_mut(), 11u16, value.len() as u16);
4572        self.as_rec_mut().extend(value);
4573        self
4574    }
4575    #[doc = "The number of seconds after which a keep alive message is sent to the peer"]
4576    pub fn push_keepalive_interval(mut self, value: u32) -> Self {
4577        push_header(self.as_rec_mut(), 13u16, 4 as u16);
4578        self.as_rec_mut().extend(value.to_ne_bytes());
4579        self
4580    }
4581    #[doc = "The number of seconds from the last activity after which the peer is assumed dead"]
4582    pub fn push_keepalive_timeout(mut self, value: u32) -> Self {
4583        push_header(self.as_rec_mut(), 14u16, 4 as u16);
4584        self.as_rec_mut().extend(value.to_ne_bytes());
4585        self
4586    }
4587}
4588impl<Prev: Rec> Drop for PushPeerSetInput<Prev> {
4589    fn drop(&mut self) {
4590        if let Some(prev) = &mut self.prev {
4591            if let Some(header_offset) = &self.header_offset {
4592                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4593            }
4594        }
4595    }
4596}
4597pub struct PushPeerDelInput<Prev: Rec> {
4598    pub(crate) prev: Option<Prev>,
4599    pub(crate) header_offset: Option<usize>,
4600}
4601impl<Prev: Rec> Rec for PushPeerDelInput<Prev> {
4602    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4603        self.prev.as_mut().unwrap().as_rec_mut()
4604    }
4605    fn as_rec(&self) -> &Vec<u8> {
4606        self.prev.as_ref().unwrap().as_rec()
4607    }
4608}
4609impl<Prev: Rec> PushPeerDelInput<Prev> {
4610    pub fn new(prev: Prev) -> Self {
4611        Self {
4612            prev: Some(prev),
4613            header_offset: None,
4614        }
4615    }
4616    pub fn end_nested(mut self) -> Prev {
4617        let mut prev = self.prev.take().unwrap();
4618        if let Some(header_offset) = &self.header_offset {
4619            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4620        }
4621        prev
4622    }
4623    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during operations for a specific device"]
4624    pub fn push_id(mut self, value: u32) -> Self {
4625        push_header(self.as_rec_mut(), 1u16, 4 as u16);
4626        self.as_rec_mut().extend(value.to_ne_bytes());
4627        self
4628    }
4629}
4630impl<Prev: Rec> Drop for PushPeerDelInput<Prev> {
4631    fn drop(&mut self) {
4632        if let Some(prev) = &mut self.prev {
4633            if let Some(header_offset) = &self.header_offset {
4634                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4635            }
4636        }
4637    }
4638}
4639pub struct PushKeyconf<Prev: Rec> {
4640    pub(crate) prev: Option<Prev>,
4641    pub(crate) header_offset: Option<usize>,
4642}
4643impl<Prev: Rec> Rec for PushKeyconf<Prev> {
4644    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4645        self.prev.as_mut().unwrap().as_rec_mut()
4646    }
4647    fn as_rec(&self) -> &Vec<u8> {
4648        self.prev.as_ref().unwrap().as_rec()
4649    }
4650}
4651impl<Prev: Rec> PushKeyconf<Prev> {
4652    pub fn new(prev: Prev) -> Self {
4653        Self {
4654            prev: Some(prev),
4655            header_offset: None,
4656        }
4657    }
4658    pub fn end_nested(mut self) -> Prev {
4659        let mut prev = self.prev.take().unwrap();
4660        if let Some(header_offset) = &self.header_offset {
4661            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4662        }
4663        prev
4664    }
4665    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
4666    pub fn push_peer_id(mut self, value: u32) -> Self {
4667        push_header(self.as_rec_mut(), 1u16, 4 as u16);
4668        self.as_rec_mut().extend(value.to_ne_bytes());
4669        self
4670    }
4671    #[doc = "The slot where the key should be stored\nAssociated type: [`KeySlot`] (enum)"]
4672    pub fn push_slot(mut self, value: u32) -> Self {
4673        push_header(self.as_rec_mut(), 2u16, 4 as u16);
4674        self.as_rec_mut().extend(value.to_ne_bytes());
4675        self
4676    }
4677    #[doc = "The unique ID of the key in the peer context\\. Used to fetch the correct key upon decryption"]
4678    pub fn push_key_id(mut self, value: u32) -> Self {
4679        push_header(self.as_rec_mut(), 3u16, 4 as u16);
4680        self.as_rec_mut().extend(value.to_ne_bytes());
4681        self
4682    }
4683    #[doc = "The cipher to be used when communicating with the peer\nAssociated type: [`CipherAlg`] (enum)"]
4684    pub fn push_cipher_alg(mut self, value: u32) -> Self {
4685        push_header(self.as_rec_mut(), 4u16, 4 as u16);
4686        self.as_rec_mut().extend(value.to_ne_bytes());
4687        self
4688    }
4689    #[doc = "Key material for encrypt direction"]
4690    pub fn nested_encrypt_dir(mut self) -> PushKeydir<Self> {
4691        let header_offset = push_nested_header(self.as_rec_mut(), 5u16);
4692        PushKeydir {
4693            prev: Some(self),
4694            header_offset: Some(header_offset),
4695        }
4696    }
4697    #[doc = "Key material for decrypt direction"]
4698    pub fn nested_decrypt_dir(mut self) -> PushKeydir<Self> {
4699        let header_offset = push_nested_header(self.as_rec_mut(), 6u16);
4700        PushKeydir {
4701            prev: Some(self),
4702            header_offset: Some(header_offset),
4703        }
4704    }
4705}
4706impl<Prev: Rec> Drop for PushKeyconf<Prev> {
4707    fn drop(&mut self) {
4708        if let Some(prev) = &mut self.prev {
4709            if let Some(header_offset) = &self.header_offset {
4710                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4711            }
4712        }
4713    }
4714}
4715pub struct PushKeydir<Prev: Rec> {
4716    pub(crate) prev: Option<Prev>,
4717    pub(crate) header_offset: Option<usize>,
4718}
4719impl<Prev: Rec> Rec for PushKeydir<Prev> {
4720    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4721        self.prev.as_mut().unwrap().as_rec_mut()
4722    }
4723    fn as_rec(&self) -> &Vec<u8> {
4724        self.prev.as_ref().unwrap().as_rec()
4725    }
4726}
4727impl<Prev: Rec> PushKeydir<Prev> {
4728    pub fn new(prev: Prev) -> Self {
4729        Self {
4730            prev: Some(prev),
4731            header_offset: None,
4732        }
4733    }
4734    pub fn end_nested(mut self) -> Prev {
4735        let mut prev = self.prev.take().unwrap();
4736        if let Some(header_offset) = &self.header_offset {
4737            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4738        }
4739        prev
4740    }
4741    #[doc = "The actual key to be used by the cipher"]
4742    pub fn push_cipher_key(mut self, value: &[u8]) -> Self {
4743        push_header(self.as_rec_mut(), 1u16, value.len() as u16);
4744        self.as_rec_mut().extend(value);
4745        self
4746    }
4747    #[doc = "Random nonce to be concatenated to the packet ID, in order to obtain the actual cipher IV"]
4748    pub fn push_nonce_tail(mut self, value: &[u8]) -> Self {
4749        push_header(self.as_rec_mut(), 2u16, value.len() as u16);
4750        self.as_rec_mut().extend(value);
4751        self
4752    }
4753}
4754impl<Prev: Rec> Drop for PushKeydir<Prev> {
4755    fn drop(&mut self) {
4756        if let Some(prev) = &mut self.prev {
4757            if let Some(header_offset) = &self.header_offset {
4758                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4759            }
4760        }
4761    }
4762}
4763pub struct PushKeyconfGet<Prev: Rec> {
4764    pub(crate) prev: Option<Prev>,
4765    pub(crate) header_offset: Option<usize>,
4766}
4767impl<Prev: Rec> Rec for PushKeyconfGet<Prev> {
4768    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4769        self.prev.as_mut().unwrap().as_rec_mut()
4770    }
4771    fn as_rec(&self) -> &Vec<u8> {
4772        self.prev.as_ref().unwrap().as_rec()
4773    }
4774}
4775impl<Prev: Rec> PushKeyconfGet<Prev> {
4776    pub fn new(prev: Prev) -> Self {
4777        Self {
4778            prev: Some(prev),
4779            header_offset: None,
4780        }
4781    }
4782    pub fn end_nested(mut self) -> Prev {
4783        let mut prev = self.prev.take().unwrap();
4784        if let Some(header_offset) = &self.header_offset {
4785            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4786        }
4787        prev
4788    }
4789    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
4790    pub fn push_peer_id(mut self, value: u32) -> Self {
4791        push_header(self.as_rec_mut(), 1u16, 4 as u16);
4792        self.as_rec_mut().extend(value.to_ne_bytes());
4793        self
4794    }
4795    #[doc = "The slot where the key should be stored\nAssociated type: [`KeySlot`] (enum)"]
4796    pub fn push_slot(mut self, value: u32) -> Self {
4797        push_header(self.as_rec_mut(), 2u16, 4 as u16);
4798        self.as_rec_mut().extend(value.to_ne_bytes());
4799        self
4800    }
4801    #[doc = "The unique ID of the key in the peer context\\. Used to fetch the correct key upon decryption"]
4802    pub fn push_key_id(mut self, value: u32) -> Self {
4803        push_header(self.as_rec_mut(), 3u16, 4 as u16);
4804        self.as_rec_mut().extend(value.to_ne_bytes());
4805        self
4806    }
4807    #[doc = "The cipher to be used when communicating with the peer\nAssociated type: [`CipherAlg`] (enum)"]
4808    pub fn push_cipher_alg(mut self, value: u32) -> Self {
4809        push_header(self.as_rec_mut(), 4u16, 4 as u16);
4810        self.as_rec_mut().extend(value.to_ne_bytes());
4811        self
4812    }
4813}
4814impl<Prev: Rec> Drop for PushKeyconfGet<Prev> {
4815    fn drop(&mut self) {
4816        if let Some(prev) = &mut self.prev {
4817            if let Some(header_offset) = &self.header_offset {
4818                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4819            }
4820        }
4821    }
4822}
4823pub struct PushKeyconfSwapInput<Prev: Rec> {
4824    pub(crate) prev: Option<Prev>,
4825    pub(crate) header_offset: Option<usize>,
4826}
4827impl<Prev: Rec> Rec for PushKeyconfSwapInput<Prev> {
4828    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4829        self.prev.as_mut().unwrap().as_rec_mut()
4830    }
4831    fn as_rec(&self) -> &Vec<u8> {
4832        self.prev.as_ref().unwrap().as_rec()
4833    }
4834}
4835impl<Prev: Rec> PushKeyconfSwapInput<Prev> {
4836    pub fn new(prev: Prev) -> Self {
4837        Self {
4838            prev: Some(prev),
4839            header_offset: None,
4840        }
4841    }
4842    pub fn end_nested(mut self) -> Prev {
4843        let mut prev = self.prev.take().unwrap();
4844        if let Some(header_offset) = &self.header_offset {
4845            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4846        }
4847        prev
4848    }
4849    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
4850    pub fn push_peer_id(mut self, value: u32) -> Self {
4851        push_header(self.as_rec_mut(), 1u16, 4 as u16);
4852        self.as_rec_mut().extend(value.to_ne_bytes());
4853        self
4854    }
4855}
4856impl<Prev: Rec> Drop for PushKeyconfSwapInput<Prev> {
4857    fn drop(&mut self) {
4858        if let Some(prev) = &mut self.prev {
4859            if let Some(header_offset) = &self.header_offset {
4860                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4861            }
4862        }
4863    }
4864}
4865pub struct PushKeyconfDelInput<Prev: Rec> {
4866    pub(crate) prev: Option<Prev>,
4867    pub(crate) header_offset: Option<usize>,
4868}
4869impl<Prev: Rec> Rec for PushKeyconfDelInput<Prev> {
4870    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4871        self.prev.as_mut().unwrap().as_rec_mut()
4872    }
4873    fn as_rec(&self) -> &Vec<u8> {
4874        self.prev.as_ref().unwrap().as_rec()
4875    }
4876}
4877impl<Prev: Rec> PushKeyconfDelInput<Prev> {
4878    pub fn new(prev: Prev) -> Self {
4879        Self {
4880            prev: Some(prev),
4881            header_offset: None,
4882        }
4883    }
4884    pub fn end_nested(mut self) -> Prev {
4885        let mut prev = self.prev.take().unwrap();
4886        if let Some(header_offset) = &self.header_offset {
4887            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4888        }
4889        prev
4890    }
4891    #[doc = "The unique ID of the peer in the device context\\. To be used to identify peers during key operations"]
4892    pub fn push_peer_id(mut self, value: u32) -> Self {
4893        push_header(self.as_rec_mut(), 1u16, 4 as u16);
4894        self.as_rec_mut().extend(value.to_ne_bytes());
4895        self
4896    }
4897    #[doc = "The slot where the key should be stored\nAssociated type: [`KeySlot`] (enum)"]
4898    pub fn push_slot(mut self, value: u32) -> Self {
4899        push_header(self.as_rec_mut(), 2u16, 4 as u16);
4900        self.as_rec_mut().extend(value.to_ne_bytes());
4901        self
4902    }
4903}
4904impl<Prev: Rec> Drop for PushKeyconfDelInput<Prev> {
4905    fn drop(&mut self) {
4906        if let Some(prev) = &mut self.prev {
4907            if let Some(header_offset) = &self.header_offset {
4908                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4909            }
4910        }
4911    }
4912}
4913pub struct PushOvpn<Prev: Rec> {
4914    pub(crate) prev: Option<Prev>,
4915    pub(crate) header_offset: Option<usize>,
4916}
4917impl<Prev: Rec> Rec for PushOvpn<Prev> {
4918    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4919        self.prev.as_mut().unwrap().as_rec_mut()
4920    }
4921    fn as_rec(&self) -> &Vec<u8> {
4922        self.prev.as_ref().unwrap().as_rec()
4923    }
4924}
4925impl<Prev: Rec> PushOvpn<Prev> {
4926    pub fn new(prev: Prev) -> Self {
4927        Self {
4928            prev: Some(prev),
4929            header_offset: None,
4930        }
4931    }
4932    pub fn end_nested(mut self) -> Prev {
4933        let mut prev = self.prev.take().unwrap();
4934        if let Some(header_offset) = &self.header_offset {
4935            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4936        }
4937        prev
4938    }
4939    #[doc = "Index of the ovpn interface to operate on"]
4940    pub fn push_ifindex(mut self, value: u32) -> Self {
4941        push_header(self.as_rec_mut(), 1u16, 4 as u16);
4942        self.as_rec_mut().extend(value.to_ne_bytes());
4943        self
4944    }
4945    #[doc = "The peer object containing the attributed of interest for the specific operation"]
4946    pub fn nested_peer(mut self) -> PushPeer<Self> {
4947        let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
4948        PushPeer {
4949            prev: Some(self),
4950            header_offset: Some(header_offset),
4951        }
4952    }
4953    #[doc = "Peer specific cipher configuration"]
4954    pub fn nested_keyconf(mut self) -> PushKeyconf<Self> {
4955        let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
4956        PushKeyconf {
4957            prev: Some(self),
4958            header_offset: Some(header_offset),
4959        }
4960    }
4961}
4962impl<Prev: Rec> Drop for PushOvpn<Prev> {
4963    fn drop(&mut self) {
4964        if let Some(prev) = &mut self.prev {
4965            if let Some(header_offset) = &self.header_offset {
4966                finalize_nested_header(prev.as_rec_mut(), *header_offset);
4967            }
4968        }
4969    }
4970}
4971pub struct PushOvpnPeerNewInput<Prev: Rec> {
4972    pub(crate) prev: Option<Prev>,
4973    pub(crate) header_offset: Option<usize>,
4974}
4975impl<Prev: Rec> Rec for PushOvpnPeerNewInput<Prev> {
4976    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
4977        self.prev.as_mut().unwrap().as_rec_mut()
4978    }
4979    fn as_rec(&self) -> &Vec<u8> {
4980        self.prev.as_ref().unwrap().as_rec()
4981    }
4982}
4983impl<Prev: Rec> PushOvpnPeerNewInput<Prev> {
4984    pub fn new(prev: Prev) -> Self {
4985        Self {
4986            prev: Some(prev),
4987            header_offset: None,
4988        }
4989    }
4990    pub fn end_nested(mut self) -> Prev {
4991        let mut prev = self.prev.take().unwrap();
4992        if let Some(header_offset) = &self.header_offset {
4993            finalize_nested_header(prev.as_rec_mut(), *header_offset);
4994        }
4995        prev
4996    }
4997    #[doc = "Index of the ovpn interface to operate on"]
4998    pub fn push_ifindex(mut self, value: u32) -> Self {
4999        push_header(self.as_rec_mut(), 1u16, 4 as u16);
5000        self.as_rec_mut().extend(value.to_ne_bytes());
5001        self
5002    }
5003    #[doc = "The peer object containing the attributed of interest for the specific operation"]
5004    pub fn nested_peer(mut self) -> PushPeerNewInput<Self> {
5005        let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
5006        PushPeerNewInput {
5007            prev: Some(self),
5008            header_offset: Some(header_offset),
5009        }
5010    }
5011}
5012impl<Prev: Rec> Drop for PushOvpnPeerNewInput<Prev> {
5013    fn drop(&mut self) {
5014        if let Some(prev) = &mut self.prev {
5015            if let Some(header_offset) = &self.header_offset {
5016                finalize_nested_header(prev.as_rec_mut(), *header_offset);
5017            }
5018        }
5019    }
5020}
5021pub struct PushOvpnPeerSetInput<Prev: Rec> {
5022    pub(crate) prev: Option<Prev>,
5023    pub(crate) header_offset: Option<usize>,
5024}
5025impl<Prev: Rec> Rec for PushOvpnPeerSetInput<Prev> {
5026    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
5027        self.prev.as_mut().unwrap().as_rec_mut()
5028    }
5029    fn as_rec(&self) -> &Vec<u8> {
5030        self.prev.as_ref().unwrap().as_rec()
5031    }
5032}
5033impl<Prev: Rec> PushOvpnPeerSetInput<Prev> {
5034    pub fn new(prev: Prev) -> Self {
5035        Self {
5036            prev: Some(prev),
5037            header_offset: None,
5038        }
5039    }
5040    pub fn end_nested(mut self) -> Prev {
5041        let mut prev = self.prev.take().unwrap();
5042        if let Some(header_offset) = &self.header_offset {
5043            finalize_nested_header(prev.as_rec_mut(), *header_offset);
5044        }
5045        prev
5046    }
5047    #[doc = "Index of the ovpn interface to operate on"]
5048    pub fn push_ifindex(mut self, value: u32) -> Self {
5049        push_header(self.as_rec_mut(), 1u16, 4 as u16);
5050        self.as_rec_mut().extend(value.to_ne_bytes());
5051        self
5052    }
5053    #[doc = "The peer object containing the attributed of interest for the specific operation"]
5054    pub fn nested_peer(mut self) -> PushPeerSetInput<Self> {
5055        let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
5056        PushPeerSetInput {
5057            prev: Some(self),
5058            header_offset: Some(header_offset),
5059        }
5060    }
5061}
5062impl<Prev: Rec> Drop for PushOvpnPeerSetInput<Prev> {
5063    fn drop(&mut self) {
5064        if let Some(prev) = &mut self.prev {
5065            if let Some(header_offset) = &self.header_offset {
5066                finalize_nested_header(prev.as_rec_mut(), *header_offset);
5067            }
5068        }
5069    }
5070}
5071pub struct PushOvpnPeerDelInput<Prev: Rec> {
5072    pub(crate) prev: Option<Prev>,
5073    pub(crate) header_offset: Option<usize>,
5074}
5075impl<Prev: Rec> Rec for PushOvpnPeerDelInput<Prev> {
5076    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
5077        self.prev.as_mut().unwrap().as_rec_mut()
5078    }
5079    fn as_rec(&self) -> &Vec<u8> {
5080        self.prev.as_ref().unwrap().as_rec()
5081    }
5082}
5083impl<Prev: Rec> PushOvpnPeerDelInput<Prev> {
5084    pub fn new(prev: Prev) -> Self {
5085        Self {
5086            prev: Some(prev),
5087            header_offset: None,
5088        }
5089    }
5090    pub fn end_nested(mut self) -> Prev {
5091        let mut prev = self.prev.take().unwrap();
5092        if let Some(header_offset) = &self.header_offset {
5093            finalize_nested_header(prev.as_rec_mut(), *header_offset);
5094        }
5095        prev
5096    }
5097    #[doc = "Index of the ovpn interface to operate on"]
5098    pub fn push_ifindex(mut self, value: u32) -> Self {
5099        push_header(self.as_rec_mut(), 1u16, 4 as u16);
5100        self.as_rec_mut().extend(value.to_ne_bytes());
5101        self
5102    }
5103    #[doc = "The peer object containing the attributed of interest for the specific operation"]
5104    pub fn nested_peer(mut self) -> PushPeerDelInput<Self> {
5105        let header_offset = push_nested_header(self.as_rec_mut(), 2u16);
5106        PushPeerDelInput {
5107            prev: Some(self),
5108            header_offset: Some(header_offset),
5109        }
5110    }
5111}
5112impl<Prev: Rec> Drop for PushOvpnPeerDelInput<Prev> {
5113    fn drop(&mut self) {
5114        if let Some(prev) = &mut self.prev {
5115            if let Some(header_offset) = &self.header_offset {
5116                finalize_nested_header(prev.as_rec_mut(), *header_offset);
5117            }
5118        }
5119    }
5120}
5121pub struct PushOvpnKeyconfGet<Prev: Rec> {
5122    pub(crate) prev: Option<Prev>,
5123    pub(crate) header_offset: Option<usize>,
5124}
5125impl<Prev: Rec> Rec for PushOvpnKeyconfGet<Prev> {
5126    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
5127        self.prev.as_mut().unwrap().as_rec_mut()
5128    }
5129    fn as_rec(&self) -> &Vec<u8> {
5130        self.prev.as_ref().unwrap().as_rec()
5131    }
5132}
5133impl<Prev: Rec> PushOvpnKeyconfGet<Prev> {
5134    pub fn new(prev: Prev) -> Self {
5135        Self {
5136            prev: Some(prev),
5137            header_offset: None,
5138        }
5139    }
5140    pub fn end_nested(mut self) -> Prev {
5141        let mut prev = self.prev.take().unwrap();
5142        if let Some(header_offset) = &self.header_offset {
5143            finalize_nested_header(prev.as_rec_mut(), *header_offset);
5144        }
5145        prev
5146    }
5147    #[doc = "Index of the ovpn interface to operate on"]
5148    pub fn push_ifindex(mut self, value: u32) -> Self {
5149        push_header(self.as_rec_mut(), 1u16, 4 as u16);
5150        self.as_rec_mut().extend(value.to_ne_bytes());
5151        self
5152    }
5153    #[doc = "Peer specific cipher configuration"]
5154    pub fn nested_keyconf(mut self) -> PushKeyconfGet<Self> {
5155        let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
5156        PushKeyconfGet {
5157            prev: Some(self),
5158            header_offset: Some(header_offset),
5159        }
5160    }
5161}
5162impl<Prev: Rec> Drop for PushOvpnKeyconfGet<Prev> {
5163    fn drop(&mut self) {
5164        if let Some(prev) = &mut self.prev {
5165            if let Some(header_offset) = &self.header_offset {
5166                finalize_nested_header(prev.as_rec_mut(), *header_offset);
5167            }
5168        }
5169    }
5170}
5171pub struct PushOvpnKeyconfSwapInput<Prev: Rec> {
5172    pub(crate) prev: Option<Prev>,
5173    pub(crate) header_offset: Option<usize>,
5174}
5175impl<Prev: Rec> Rec for PushOvpnKeyconfSwapInput<Prev> {
5176    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
5177        self.prev.as_mut().unwrap().as_rec_mut()
5178    }
5179    fn as_rec(&self) -> &Vec<u8> {
5180        self.prev.as_ref().unwrap().as_rec()
5181    }
5182}
5183impl<Prev: Rec> PushOvpnKeyconfSwapInput<Prev> {
5184    pub fn new(prev: Prev) -> Self {
5185        Self {
5186            prev: Some(prev),
5187            header_offset: None,
5188        }
5189    }
5190    pub fn end_nested(mut self) -> Prev {
5191        let mut prev = self.prev.take().unwrap();
5192        if let Some(header_offset) = &self.header_offset {
5193            finalize_nested_header(prev.as_rec_mut(), *header_offset);
5194        }
5195        prev
5196    }
5197    #[doc = "Index of the ovpn interface to operate on"]
5198    pub fn push_ifindex(mut self, value: u32) -> Self {
5199        push_header(self.as_rec_mut(), 1u16, 4 as u16);
5200        self.as_rec_mut().extend(value.to_ne_bytes());
5201        self
5202    }
5203    #[doc = "Peer specific cipher configuration"]
5204    pub fn nested_keyconf(mut self) -> PushKeyconfSwapInput<Self> {
5205        let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
5206        PushKeyconfSwapInput {
5207            prev: Some(self),
5208            header_offset: Some(header_offset),
5209        }
5210    }
5211}
5212impl<Prev: Rec> Drop for PushOvpnKeyconfSwapInput<Prev> {
5213    fn drop(&mut self) {
5214        if let Some(prev) = &mut self.prev {
5215            if let Some(header_offset) = &self.header_offset {
5216                finalize_nested_header(prev.as_rec_mut(), *header_offset);
5217            }
5218        }
5219    }
5220}
5221pub struct PushOvpnKeyconfDelInput<Prev: Rec> {
5222    pub(crate) prev: Option<Prev>,
5223    pub(crate) header_offset: Option<usize>,
5224}
5225impl<Prev: Rec> Rec for PushOvpnKeyconfDelInput<Prev> {
5226    fn as_rec_mut(&mut self) -> &mut Vec<u8> {
5227        self.prev.as_mut().unwrap().as_rec_mut()
5228    }
5229    fn as_rec(&self) -> &Vec<u8> {
5230        self.prev.as_ref().unwrap().as_rec()
5231    }
5232}
5233impl<Prev: Rec> PushOvpnKeyconfDelInput<Prev> {
5234    pub fn new(prev: Prev) -> Self {
5235        Self {
5236            prev: Some(prev),
5237            header_offset: None,
5238        }
5239    }
5240    pub fn end_nested(mut self) -> Prev {
5241        let mut prev = self.prev.take().unwrap();
5242        if let Some(header_offset) = &self.header_offset {
5243            finalize_nested_header(prev.as_rec_mut(), *header_offset);
5244        }
5245        prev
5246    }
5247    #[doc = "Index of the ovpn interface to operate on"]
5248    pub fn push_ifindex(mut self, value: u32) -> Self {
5249        push_header(self.as_rec_mut(), 1u16, 4 as u16);
5250        self.as_rec_mut().extend(value.to_ne_bytes());
5251        self
5252    }
5253    #[doc = "Peer specific cipher configuration"]
5254    pub fn nested_keyconf(mut self) -> PushKeyconfDelInput<Self> {
5255        let header_offset = push_nested_header(self.as_rec_mut(), 3u16);
5256        PushKeyconfDelInput {
5257            prev: Some(self),
5258            header_offset: Some(header_offset),
5259        }
5260    }
5261}
5262impl<Prev: Rec> Drop for PushOvpnKeyconfDelInput<Prev> {
5263    fn drop(&mut self) {
5264        if let Some(prev) = &mut self.prev {
5265            if let Some(header_offset) = &self.header_offset {
5266                finalize_nested_header(prev.as_rec_mut(), *header_offset);
5267            }
5268        }
5269    }
5270}
5271#[doc = "Notify attributes:\n- [`.get_peer()`](IterableOvpn::get_peer)\n"]
5272#[derive(Debug)]
5273pub struct OpPeerDelNotif;
5274impl OpPeerDelNotif {
5275    pub const CMD: u8 = 5u8;
5276    pub fn decode_notif<'a>(buf: &'a [u8]) -> IterableOvpn<'a> {
5277        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5278        IterableOvpn::with_loc(attrs, buf.as_ptr() as usize)
5279    }
5280}
5281#[doc = "Notify attributes:\n- [`.get_keyconf()`](IterableOvpnKeyconfGet::get_keyconf)\n"]
5282#[derive(Debug)]
5283pub struct OpKeySwapNotif;
5284impl OpKeySwapNotif {
5285    pub const CMD: u8 = 9u8;
5286    pub fn decode_notif<'a>(buf: &'a [u8]) -> IterableOvpnKeyconfGet<'a> {
5287        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5288        IterableOvpnKeyconfGet::with_loc(attrs, buf.as_ptr() as usize)
5289    }
5290}
5291pub struct NotifGroup;
5292impl NotifGroup {
5293    #[doc = "Notifications:\n- [`OpPeerDelNotif`]\n- [`OpKeySwapNotif`]\n"]
5294    pub const PEERS: &str = "peers";
5295    #[doc = "Notifications:\n- [`OpPeerDelNotif`]\n- [`OpKeySwapNotif`]\n"]
5296    pub const PEERS_CSTR: &CStr = c"peers";
5297}
5298#[doc = "Add a remote peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnPeerNewInput::push_ifindex)\n- [.nested_peer()](PushOvpnPeerNewInput::nested_peer)\n"]
5299#[derive(Debug)]
5300pub struct OpPeerNewDo<'r> {
5301    request: Request<'r>,
5302}
5303impl<'r> OpPeerNewDo<'r> {
5304    pub fn new(mut request: Request<'r>) -> Self {
5305        Self::write_header(request.buf_mut());
5306        Self { request: request }
5307    }
5308    pub fn encode_request<'buf>(buf: &'buf mut Vec<u8>) -> PushOvpnPeerNewInput<&'buf mut Vec<u8>> {
5309        Self::write_header(buf);
5310        PushOvpnPeerNewInput::new(buf)
5311    }
5312    pub fn encode(&mut self) -> PushOvpnPeerNewInput<&mut Vec<u8>> {
5313        PushOvpnPeerNewInput::new(self.request.buf_mut())
5314    }
5315    pub fn into_encoder(self) -> PushOvpnPeerNewInput<RequestBuf<'r>> {
5316        PushOvpnPeerNewInput::new(self.request.buf)
5317    }
5318    pub fn decode_request<'a>(buf: &'a [u8]) -> IterableOvpnPeerNewInput<'a> {
5319        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5320        IterableOvpnPeerNewInput::with_loc(attrs, buf.as_ptr() as usize)
5321    }
5322    fn write_header<Prev: Rec>(prev: &mut Prev) {
5323        let mut header = BuiltinNfgenmsg::new();
5324        header.cmd = 1u8;
5325        header.version = 1u8;
5326        prev.as_rec_mut().extend(header.as_slice());
5327    }
5328}
5329impl NetlinkRequest for OpPeerNewDo<'_> {
5330    fn protocol(&self) -> Protocol {
5331        Protocol::Generic("ovpn".as_bytes())
5332    }
5333    fn flags(&self) -> u16 {
5334        self.request.flags
5335    }
5336    fn payload(&self) -> &[u8] {
5337        self.request.buf()
5338    }
5339    type ReplyType<'buf> = IterableOvpnPeerNewInput<'buf>;
5340    fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
5341        Self::decode_request(buf)
5342    }
5343    fn lookup(
5344        buf: &[u8],
5345        offset: usize,
5346        missing_type: Option<u16>,
5347    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5348        Self::decode_request(buf).lookup_attr(offset, missing_type)
5349    }
5350}
5351#[doc = "modify a remote peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnPeerSetInput::push_ifindex)\n- [.nested_peer()](PushOvpnPeerSetInput::nested_peer)\n"]
5352#[derive(Debug)]
5353pub struct OpPeerSetDo<'r> {
5354    request: Request<'r>,
5355}
5356impl<'r> OpPeerSetDo<'r> {
5357    pub fn new(mut request: Request<'r>) -> Self {
5358        Self::write_header(request.buf_mut());
5359        Self { request: request }
5360    }
5361    pub fn encode_request<'buf>(buf: &'buf mut Vec<u8>) -> PushOvpnPeerSetInput<&'buf mut Vec<u8>> {
5362        Self::write_header(buf);
5363        PushOvpnPeerSetInput::new(buf)
5364    }
5365    pub fn encode(&mut self) -> PushOvpnPeerSetInput<&mut Vec<u8>> {
5366        PushOvpnPeerSetInput::new(self.request.buf_mut())
5367    }
5368    pub fn into_encoder(self) -> PushOvpnPeerSetInput<RequestBuf<'r>> {
5369        PushOvpnPeerSetInput::new(self.request.buf)
5370    }
5371    pub fn decode_request<'a>(buf: &'a [u8]) -> IterableOvpnPeerSetInput<'a> {
5372        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5373        IterableOvpnPeerSetInput::with_loc(attrs, buf.as_ptr() as usize)
5374    }
5375    fn write_header<Prev: Rec>(prev: &mut Prev) {
5376        let mut header = BuiltinNfgenmsg::new();
5377        header.cmd = 2u8;
5378        header.version = 1u8;
5379        prev.as_rec_mut().extend(header.as_slice());
5380    }
5381}
5382impl NetlinkRequest for OpPeerSetDo<'_> {
5383    fn protocol(&self) -> Protocol {
5384        Protocol::Generic("ovpn".as_bytes())
5385    }
5386    fn flags(&self) -> u16 {
5387        self.request.flags
5388    }
5389    fn payload(&self) -> &[u8] {
5390        self.request.buf()
5391    }
5392    type ReplyType<'buf> = IterableOvpnPeerSetInput<'buf>;
5393    fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
5394        Self::decode_request(buf)
5395    }
5396    fn lookup(
5397        buf: &[u8],
5398        offset: usize,
5399        missing_type: Option<u16>,
5400    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5401        Self::decode_request(buf).lookup_attr(offset, missing_type)
5402    }
5403}
5404#[doc = "Retrieve data about existing remote peers (or a specific one)\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpn::push_ifindex)\n\nReply attributes:\n- [.get_peer()](IterableOvpn::get_peer)\n"]
5405#[derive(Debug)]
5406pub struct OpPeerGetDump<'r> {
5407    request: Request<'r>,
5408}
5409impl<'r> OpPeerGetDump<'r> {
5410    pub fn new(mut request: Request<'r>) -> Self {
5411        Self::write_header(request.buf_mut());
5412        Self {
5413            request: request.set_dump(),
5414        }
5415    }
5416    pub fn encode_request<'buf>(buf: &'buf mut Vec<u8>) -> PushOvpn<&'buf mut Vec<u8>> {
5417        Self::write_header(buf);
5418        PushOvpn::new(buf)
5419    }
5420    pub fn encode(&mut self) -> PushOvpn<&mut Vec<u8>> {
5421        PushOvpn::new(self.request.buf_mut())
5422    }
5423    pub fn into_encoder(self) -> PushOvpn<RequestBuf<'r>> {
5424        PushOvpn::new(self.request.buf)
5425    }
5426    pub fn decode_request<'a>(buf: &'a [u8]) -> IterableOvpn<'a> {
5427        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5428        IterableOvpn::with_loc(attrs, buf.as_ptr() as usize)
5429    }
5430    fn write_header<Prev: Rec>(prev: &mut Prev) {
5431        let mut header = BuiltinNfgenmsg::new();
5432        header.cmd = 3u8;
5433        header.version = 1u8;
5434        prev.as_rec_mut().extend(header.as_slice());
5435    }
5436}
5437impl NetlinkRequest for OpPeerGetDump<'_> {
5438    fn protocol(&self) -> Protocol {
5439        Protocol::Generic("ovpn".as_bytes())
5440    }
5441    fn flags(&self) -> u16 {
5442        self.request.flags
5443    }
5444    fn payload(&self) -> &[u8] {
5445        self.request.buf()
5446    }
5447    type ReplyType<'buf> = IterableOvpn<'buf>;
5448    fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
5449        Self::decode_request(buf)
5450    }
5451    fn lookup(
5452        buf: &[u8],
5453        offset: usize,
5454        missing_type: Option<u16>,
5455    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5456        Self::decode_request(buf).lookup_attr(offset, missing_type)
5457    }
5458}
5459#[doc = "Retrieve data about existing remote peers (or a specific one)\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpn::push_ifindex)\n- [.nested_peer()](PushOvpn::nested_peer)\n\nReply attributes:\n- [.get_peer()](IterableOvpn::get_peer)\n"]
5460#[derive(Debug)]
5461pub struct OpPeerGetDo<'r> {
5462    request: Request<'r>,
5463}
5464impl<'r> OpPeerGetDo<'r> {
5465    pub fn new(mut request: Request<'r>) -> Self {
5466        Self::write_header(request.buf_mut());
5467        Self { request: request }
5468    }
5469    pub fn encode_request<'buf>(buf: &'buf mut Vec<u8>) -> PushOvpn<&'buf mut Vec<u8>> {
5470        Self::write_header(buf);
5471        PushOvpn::new(buf)
5472    }
5473    pub fn encode(&mut self) -> PushOvpn<&mut Vec<u8>> {
5474        PushOvpn::new(self.request.buf_mut())
5475    }
5476    pub fn into_encoder(self) -> PushOvpn<RequestBuf<'r>> {
5477        PushOvpn::new(self.request.buf)
5478    }
5479    pub fn decode_request<'a>(buf: &'a [u8]) -> IterableOvpn<'a> {
5480        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5481        IterableOvpn::with_loc(attrs, buf.as_ptr() as usize)
5482    }
5483    fn write_header<Prev: Rec>(prev: &mut Prev) {
5484        let mut header = BuiltinNfgenmsg::new();
5485        header.cmd = 3u8;
5486        header.version = 1u8;
5487        prev.as_rec_mut().extend(header.as_slice());
5488    }
5489}
5490impl NetlinkRequest for OpPeerGetDo<'_> {
5491    fn protocol(&self) -> Protocol {
5492        Protocol::Generic("ovpn".as_bytes())
5493    }
5494    fn flags(&self) -> u16 {
5495        self.request.flags
5496    }
5497    fn payload(&self) -> &[u8] {
5498        self.request.buf()
5499    }
5500    type ReplyType<'buf> = IterableOvpn<'buf>;
5501    fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
5502        Self::decode_request(buf)
5503    }
5504    fn lookup(
5505        buf: &[u8],
5506        offset: usize,
5507        missing_type: Option<u16>,
5508    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5509        Self::decode_request(buf).lookup_attr(offset, missing_type)
5510    }
5511}
5512#[doc = "Delete existing remote peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnPeerDelInput::push_ifindex)\n- [.nested_peer()](PushOvpnPeerDelInput::nested_peer)\n"]
5513#[derive(Debug)]
5514pub struct OpPeerDelDo<'r> {
5515    request: Request<'r>,
5516}
5517impl<'r> OpPeerDelDo<'r> {
5518    pub fn new(mut request: Request<'r>) -> Self {
5519        Self::write_header(request.buf_mut());
5520        Self { request: request }
5521    }
5522    pub fn encode_request<'buf>(buf: &'buf mut Vec<u8>) -> PushOvpnPeerDelInput<&'buf mut Vec<u8>> {
5523        Self::write_header(buf);
5524        PushOvpnPeerDelInput::new(buf)
5525    }
5526    pub fn encode(&mut self) -> PushOvpnPeerDelInput<&mut Vec<u8>> {
5527        PushOvpnPeerDelInput::new(self.request.buf_mut())
5528    }
5529    pub fn into_encoder(self) -> PushOvpnPeerDelInput<RequestBuf<'r>> {
5530        PushOvpnPeerDelInput::new(self.request.buf)
5531    }
5532    pub fn decode_request<'a>(buf: &'a [u8]) -> IterableOvpnPeerDelInput<'a> {
5533        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5534        IterableOvpnPeerDelInput::with_loc(attrs, buf.as_ptr() as usize)
5535    }
5536    fn write_header<Prev: Rec>(prev: &mut Prev) {
5537        let mut header = BuiltinNfgenmsg::new();
5538        header.cmd = 4u8;
5539        header.version = 1u8;
5540        prev.as_rec_mut().extend(header.as_slice());
5541    }
5542}
5543impl NetlinkRequest for OpPeerDelDo<'_> {
5544    fn protocol(&self) -> Protocol {
5545        Protocol::Generic("ovpn".as_bytes())
5546    }
5547    fn flags(&self) -> u16 {
5548        self.request.flags
5549    }
5550    fn payload(&self) -> &[u8] {
5551        self.request.buf()
5552    }
5553    type ReplyType<'buf> = IterableOvpnPeerDelInput<'buf>;
5554    fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
5555        Self::decode_request(buf)
5556    }
5557    fn lookup(
5558        buf: &[u8],
5559        offset: usize,
5560        missing_type: Option<u16>,
5561    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5562        Self::decode_request(buf).lookup_attr(offset, missing_type)
5563    }
5564}
5565#[doc = "Add a cipher key for a specific peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpn::push_ifindex)\n- [.nested_keyconf()](PushOvpn::nested_keyconf)\n"]
5566#[derive(Debug)]
5567pub struct OpKeyNewDo<'r> {
5568    request: Request<'r>,
5569}
5570impl<'r> OpKeyNewDo<'r> {
5571    pub fn new(mut request: Request<'r>) -> Self {
5572        Self::write_header(request.buf_mut());
5573        Self { request: request }
5574    }
5575    pub fn encode_request<'buf>(buf: &'buf mut Vec<u8>) -> PushOvpn<&'buf mut Vec<u8>> {
5576        Self::write_header(buf);
5577        PushOvpn::new(buf)
5578    }
5579    pub fn encode(&mut self) -> PushOvpn<&mut Vec<u8>> {
5580        PushOvpn::new(self.request.buf_mut())
5581    }
5582    pub fn into_encoder(self) -> PushOvpn<RequestBuf<'r>> {
5583        PushOvpn::new(self.request.buf)
5584    }
5585    pub fn decode_request<'a>(buf: &'a [u8]) -> IterableOvpn<'a> {
5586        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5587        IterableOvpn::with_loc(attrs, buf.as_ptr() as usize)
5588    }
5589    fn write_header<Prev: Rec>(prev: &mut Prev) {
5590        let mut header = BuiltinNfgenmsg::new();
5591        header.cmd = 6u8;
5592        header.version = 1u8;
5593        prev.as_rec_mut().extend(header.as_slice());
5594    }
5595}
5596impl NetlinkRequest for OpKeyNewDo<'_> {
5597    fn protocol(&self) -> Protocol {
5598        Protocol::Generic("ovpn".as_bytes())
5599    }
5600    fn flags(&self) -> u16 {
5601        self.request.flags
5602    }
5603    fn payload(&self) -> &[u8] {
5604        self.request.buf()
5605    }
5606    type ReplyType<'buf> = IterableOvpn<'buf>;
5607    fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
5608        Self::decode_request(buf)
5609    }
5610    fn lookup(
5611        buf: &[u8],
5612        offset: usize,
5613        missing_type: Option<u16>,
5614    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5615        Self::decode_request(buf).lookup_attr(offset, missing_type)
5616    }
5617}
5618#[doc = "Retrieve non\\-sensitive data about peer key and cipher\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnKeyconfGet::push_ifindex)\n- [.nested_keyconf()](PushOvpnKeyconfGet::nested_keyconf)\n\nReply attributes:\n- [.get_keyconf()](IterableOvpnKeyconfGet::get_keyconf)\n"]
5619#[derive(Debug)]
5620pub struct OpKeyGetDo<'r> {
5621    request: Request<'r>,
5622}
5623impl<'r> OpKeyGetDo<'r> {
5624    pub fn new(mut request: Request<'r>) -> Self {
5625        Self::write_header(request.buf_mut());
5626        Self { request: request }
5627    }
5628    pub fn encode_request<'buf>(buf: &'buf mut Vec<u8>) -> PushOvpnKeyconfGet<&'buf mut Vec<u8>> {
5629        Self::write_header(buf);
5630        PushOvpnKeyconfGet::new(buf)
5631    }
5632    pub fn encode(&mut self) -> PushOvpnKeyconfGet<&mut Vec<u8>> {
5633        PushOvpnKeyconfGet::new(self.request.buf_mut())
5634    }
5635    pub fn into_encoder(self) -> PushOvpnKeyconfGet<RequestBuf<'r>> {
5636        PushOvpnKeyconfGet::new(self.request.buf)
5637    }
5638    pub fn decode_request<'a>(buf: &'a [u8]) -> IterableOvpnKeyconfGet<'a> {
5639        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5640        IterableOvpnKeyconfGet::with_loc(attrs, buf.as_ptr() as usize)
5641    }
5642    fn write_header<Prev: Rec>(prev: &mut Prev) {
5643        let mut header = BuiltinNfgenmsg::new();
5644        header.cmd = 7u8;
5645        header.version = 1u8;
5646        prev.as_rec_mut().extend(header.as_slice());
5647    }
5648}
5649impl NetlinkRequest for OpKeyGetDo<'_> {
5650    fn protocol(&self) -> Protocol {
5651        Protocol::Generic("ovpn".as_bytes())
5652    }
5653    fn flags(&self) -> u16 {
5654        self.request.flags
5655    }
5656    fn payload(&self) -> &[u8] {
5657        self.request.buf()
5658    }
5659    type ReplyType<'buf> = IterableOvpnKeyconfGet<'buf>;
5660    fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
5661        Self::decode_request(buf)
5662    }
5663    fn lookup(
5664        buf: &[u8],
5665        offset: usize,
5666        missing_type: Option<u16>,
5667    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5668        Self::decode_request(buf).lookup_attr(offset, missing_type)
5669    }
5670}
5671#[doc = "Swap primary and secondary session keys for a specific peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnKeyconfSwapInput::push_ifindex)\n- [.nested_keyconf()](PushOvpnKeyconfSwapInput::nested_keyconf)\n"]
5672#[derive(Debug)]
5673pub struct OpKeySwapDo<'r> {
5674    request: Request<'r>,
5675}
5676impl<'r> OpKeySwapDo<'r> {
5677    pub fn new(mut request: Request<'r>) -> Self {
5678        Self::write_header(request.buf_mut());
5679        Self { request: request }
5680    }
5681    pub fn encode_request<'buf>(
5682        buf: &'buf mut Vec<u8>,
5683    ) -> PushOvpnKeyconfSwapInput<&'buf mut Vec<u8>> {
5684        Self::write_header(buf);
5685        PushOvpnKeyconfSwapInput::new(buf)
5686    }
5687    pub fn encode(&mut self) -> PushOvpnKeyconfSwapInput<&mut Vec<u8>> {
5688        PushOvpnKeyconfSwapInput::new(self.request.buf_mut())
5689    }
5690    pub fn into_encoder(self) -> PushOvpnKeyconfSwapInput<RequestBuf<'r>> {
5691        PushOvpnKeyconfSwapInput::new(self.request.buf)
5692    }
5693    pub fn decode_request<'a>(buf: &'a [u8]) -> IterableOvpnKeyconfSwapInput<'a> {
5694        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5695        IterableOvpnKeyconfSwapInput::with_loc(attrs, buf.as_ptr() as usize)
5696    }
5697    fn write_header<Prev: Rec>(prev: &mut Prev) {
5698        let mut header = BuiltinNfgenmsg::new();
5699        header.cmd = 8u8;
5700        header.version = 1u8;
5701        prev.as_rec_mut().extend(header.as_slice());
5702    }
5703}
5704impl NetlinkRequest for OpKeySwapDo<'_> {
5705    fn protocol(&self) -> Protocol {
5706        Protocol::Generic("ovpn".as_bytes())
5707    }
5708    fn flags(&self) -> u16 {
5709        self.request.flags
5710    }
5711    fn payload(&self) -> &[u8] {
5712        self.request.buf()
5713    }
5714    type ReplyType<'buf> = IterableOvpnKeyconfSwapInput<'buf>;
5715    fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
5716        Self::decode_request(buf)
5717    }
5718    fn lookup(
5719        buf: &[u8],
5720        offset: usize,
5721        missing_type: Option<u16>,
5722    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5723        Self::decode_request(buf).lookup_attr(offset, missing_type)
5724    }
5725}
5726#[doc = "Delete cipher key for a specific peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnKeyconfDelInput::push_ifindex)\n- [.nested_keyconf()](PushOvpnKeyconfDelInput::nested_keyconf)\n"]
5727#[derive(Debug)]
5728pub struct OpKeyDelDo<'r> {
5729    request: Request<'r>,
5730}
5731impl<'r> OpKeyDelDo<'r> {
5732    pub fn new(mut request: Request<'r>) -> Self {
5733        Self::write_header(request.buf_mut());
5734        Self { request: request }
5735    }
5736    pub fn encode_request<'buf>(
5737        buf: &'buf mut Vec<u8>,
5738    ) -> PushOvpnKeyconfDelInput<&'buf mut Vec<u8>> {
5739        Self::write_header(buf);
5740        PushOvpnKeyconfDelInput::new(buf)
5741    }
5742    pub fn encode(&mut self) -> PushOvpnKeyconfDelInput<&mut Vec<u8>> {
5743        PushOvpnKeyconfDelInput::new(self.request.buf_mut())
5744    }
5745    pub fn into_encoder(self) -> PushOvpnKeyconfDelInput<RequestBuf<'r>> {
5746        PushOvpnKeyconfDelInput::new(self.request.buf)
5747    }
5748    pub fn decode_request<'a>(buf: &'a [u8]) -> IterableOvpnKeyconfDelInput<'a> {
5749        let (_header, attrs) = buf.split_at(buf.len().min(BuiltinNfgenmsg::len()));
5750        IterableOvpnKeyconfDelInput::with_loc(attrs, buf.as_ptr() as usize)
5751    }
5752    fn write_header<Prev: Rec>(prev: &mut Prev) {
5753        let mut header = BuiltinNfgenmsg::new();
5754        header.cmd = 10u8;
5755        header.version = 1u8;
5756        prev.as_rec_mut().extend(header.as_slice());
5757    }
5758}
5759impl NetlinkRequest for OpKeyDelDo<'_> {
5760    fn protocol(&self) -> Protocol {
5761        Protocol::Generic("ovpn".as_bytes())
5762    }
5763    fn flags(&self) -> u16 {
5764        self.request.flags
5765    }
5766    fn payload(&self) -> &[u8] {
5767        self.request.buf()
5768    }
5769    type ReplyType<'buf> = IterableOvpnKeyconfDelInput<'buf>;
5770    fn decode_reply<'buf>(buf: &'buf [u8]) -> Self::ReplyType<'buf> {
5771        Self::decode_request(buf)
5772    }
5773    fn lookup(
5774        buf: &[u8],
5775        offset: usize,
5776        missing_type: Option<u16>,
5777    ) -> (Vec<(&'static str, usize)>, Option<&'static str>) {
5778        Self::decode_request(buf).lookup_attr(offset, missing_type)
5779    }
5780}
5781use crate::traits::LookupFn;
5782use crate::utils::RequestBuf;
5783#[derive(Debug)]
5784pub struct Request<'buf> {
5785    buf: RequestBuf<'buf>,
5786    flags: u16,
5787    writeback: Option<&'buf mut Option<RequestInfo>>,
5788}
5789#[allow(unused)]
5790#[derive(Debug, Clone)]
5791pub struct RequestInfo {
5792    protocol: Protocol,
5793    flags: u16,
5794    name: &'static str,
5795    lookup: LookupFn,
5796}
5797impl Request<'static> {
5798    pub fn new() -> Self {
5799        Self::new_from_buf(Vec::new())
5800    }
5801    pub fn new_from_buf(buf: Vec<u8>) -> Self {
5802        Self {
5803            flags: 0,
5804            buf: RequestBuf::Own(buf),
5805            writeback: None,
5806        }
5807    }
5808    pub fn into_buf(self) -> Vec<u8> {
5809        match self.buf {
5810            RequestBuf::Own(buf) => buf,
5811            _ => unreachable!(),
5812        }
5813    }
5814}
5815impl<'buf> Request<'buf> {
5816    pub fn new_with_buf(buf: &'buf mut Vec<u8>) -> Self {
5817        buf.clear();
5818        Self::new_extend(buf)
5819    }
5820    pub fn new_extend(buf: &'buf mut Vec<u8>) -> Self {
5821        Self {
5822            flags: 0,
5823            buf: RequestBuf::Ref(buf),
5824            writeback: None,
5825        }
5826    }
5827    fn do_writeback(&mut self, protocol: Protocol, name: &'static str, lookup: LookupFn) {
5828        let Some(writeback) = &mut self.writeback else {
5829            return;
5830        };
5831        **writeback = Some(RequestInfo {
5832            protocol,
5833            flags: self.flags,
5834            name,
5835            lookup,
5836        })
5837    }
5838    pub fn buf(&self) -> &Vec<u8> {
5839        self.buf.buf()
5840    }
5841    pub fn buf_mut(&mut self) -> &mut Vec<u8> {
5842        self.buf.buf_mut()
5843    }
5844    #[doc = "Set `NLM_F_CREATE` flag"]
5845    pub fn set_create(mut self) -> Self {
5846        self.flags |= consts::NLM_F_CREATE as u16;
5847        self
5848    }
5849    #[doc = "Set `NLM_F_EXCL` flag"]
5850    pub fn set_excl(mut self) -> Self {
5851        self.flags |= consts::NLM_F_EXCL as u16;
5852        self
5853    }
5854    #[doc = "Set `NLM_F_REPLACE` flag"]
5855    pub fn set_replace(mut self) -> Self {
5856        self.flags |= consts::NLM_F_REPLACE as u16;
5857        self
5858    }
5859    #[doc = "Set `NLM_F_CREATE` and `NLM_F_REPLACE` flag"]
5860    pub fn set_change(self) -> Self {
5861        self.set_create().set_replace()
5862    }
5863    #[doc = "Set `NLM_F_APPEND` flag"]
5864    pub fn set_append(mut self) -> Self {
5865        self.flags |= consts::NLM_F_APPEND as u16;
5866        self
5867    }
5868    #[doc = "Set `self.flags |= flags`"]
5869    pub fn set_flags(mut self, flags: u16) -> Self {
5870        self.flags |= flags;
5871        self
5872    }
5873    #[doc = "Set `self.flags ^= self.flags & flags`"]
5874    pub fn unset_flags(mut self, flags: u16) -> Self {
5875        self.flags ^= self.flags & flags;
5876        self
5877    }
5878    #[doc = "Set `NLM_F_DUMP` flag"]
5879    fn set_dump(mut self) -> Self {
5880        self.flags |= consts::NLM_F_DUMP as u16;
5881        self
5882    }
5883    #[doc = "Add a remote peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnPeerNewInput::push_ifindex)\n- [.nested_peer()](PushOvpnPeerNewInput::nested_peer)\n"]
5884    pub fn op_peer_new_do(self) -> OpPeerNewDo<'buf> {
5885        let mut res = OpPeerNewDo::new(self);
5886        res.request
5887            .do_writeback(res.protocol(), "op-peer-new-do", OpPeerNewDo::lookup);
5888        res
5889    }
5890    #[doc = "modify a remote peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnPeerSetInput::push_ifindex)\n- [.nested_peer()](PushOvpnPeerSetInput::nested_peer)\n"]
5891    pub fn op_peer_set_do(self) -> OpPeerSetDo<'buf> {
5892        let mut res = OpPeerSetDo::new(self);
5893        res.request
5894            .do_writeback(res.protocol(), "op-peer-set-do", OpPeerSetDo::lookup);
5895        res
5896    }
5897    #[doc = "Retrieve data about existing remote peers (or a specific one)\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpn::push_ifindex)\n\nReply attributes:\n- [.get_peer()](IterableOvpn::get_peer)\n"]
5898    pub fn op_peer_get_dump(self) -> OpPeerGetDump<'buf> {
5899        let mut res = OpPeerGetDump::new(self);
5900        res.request
5901            .do_writeback(res.protocol(), "op-peer-get-dump", OpPeerGetDump::lookup);
5902        res
5903    }
5904    #[doc = "Retrieve data about existing remote peers (or a specific one)\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpn::push_ifindex)\n- [.nested_peer()](PushOvpn::nested_peer)\n\nReply attributes:\n- [.get_peer()](IterableOvpn::get_peer)\n"]
5905    pub fn op_peer_get_do(self) -> OpPeerGetDo<'buf> {
5906        let mut res = OpPeerGetDo::new(self);
5907        res.request
5908            .do_writeback(res.protocol(), "op-peer-get-do", OpPeerGetDo::lookup);
5909        res
5910    }
5911    #[doc = "Delete existing remote peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnPeerDelInput::push_ifindex)\n- [.nested_peer()](PushOvpnPeerDelInput::nested_peer)\n"]
5912    pub fn op_peer_del_do(self) -> OpPeerDelDo<'buf> {
5913        let mut res = OpPeerDelDo::new(self);
5914        res.request
5915            .do_writeback(res.protocol(), "op-peer-del-do", OpPeerDelDo::lookup);
5916        res
5917    }
5918    #[doc = "Add a cipher key for a specific peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpn::push_ifindex)\n- [.nested_keyconf()](PushOvpn::nested_keyconf)\n"]
5919    pub fn op_key_new_do(self) -> OpKeyNewDo<'buf> {
5920        let mut res = OpKeyNewDo::new(self);
5921        res.request
5922            .do_writeback(res.protocol(), "op-key-new-do", OpKeyNewDo::lookup);
5923        res
5924    }
5925    #[doc = "Retrieve non\\-sensitive data about peer key and cipher\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnKeyconfGet::push_ifindex)\n- [.nested_keyconf()](PushOvpnKeyconfGet::nested_keyconf)\n\nReply attributes:\n- [.get_keyconf()](IterableOvpnKeyconfGet::get_keyconf)\n"]
5926    pub fn op_key_get_do(self) -> OpKeyGetDo<'buf> {
5927        let mut res = OpKeyGetDo::new(self);
5928        res.request
5929            .do_writeback(res.protocol(), "op-key-get-do", OpKeyGetDo::lookup);
5930        res
5931    }
5932    #[doc = "Swap primary and secondary session keys for a specific peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnKeyconfSwapInput::push_ifindex)\n- [.nested_keyconf()](PushOvpnKeyconfSwapInput::nested_keyconf)\n"]
5933    pub fn op_key_swap_do(self) -> OpKeySwapDo<'buf> {
5934        let mut res = OpKeySwapDo::new(self);
5935        res.request
5936            .do_writeback(res.protocol(), "op-key-swap-do", OpKeySwapDo::lookup);
5937        res
5938    }
5939    #[doc = "Delete cipher key for a specific peer\nFlags: admin-perm\nRequest attributes:\n- [.push_ifindex()](PushOvpnKeyconfDelInput::push_ifindex)\n- [.nested_keyconf()](PushOvpnKeyconfDelInput::nested_keyconf)\n"]
5940    pub fn op_key_del_do(self) -> OpKeyDelDo<'buf> {
5941        let mut res = OpKeyDelDo::new(self);
5942        res.request
5943            .do_writeback(res.protocol(), "op-key-del-do", OpKeyDelDo::lookup);
5944        res
5945    }
5946}
5947#[cfg(test)]
5948mod generated_tests {
5949    use super::*;
5950    #[test]
5951    fn tests() {
5952        let _ = IterableOvpn::get_peer;
5953        let _ = IterableOvpnKeyconfGet::get_keyconf;
5954        let _ = OpKeySwapNotif;
5955        let _ = OpPeerDelNotif;
5956        let _ = PushOvpn::<&mut Vec<u8>>::nested_keyconf;
5957        let _ = PushOvpn::<&mut Vec<u8>>::nested_peer;
5958        let _ = PushOvpn::<&mut Vec<u8>>::push_ifindex;
5959        let _ = PushOvpnKeyconfDelInput::<&mut Vec<u8>>::nested_keyconf;
5960        let _ = PushOvpnKeyconfDelInput::<&mut Vec<u8>>::push_ifindex;
5961        let _ = PushOvpnKeyconfGet::<&mut Vec<u8>>::nested_keyconf;
5962        let _ = PushOvpnKeyconfGet::<&mut Vec<u8>>::push_ifindex;
5963        let _ = PushOvpnKeyconfSwapInput::<&mut Vec<u8>>::nested_keyconf;
5964        let _ = PushOvpnKeyconfSwapInput::<&mut Vec<u8>>::push_ifindex;
5965        let _ = PushOvpnPeerDelInput::<&mut Vec<u8>>::nested_peer;
5966        let _ = PushOvpnPeerDelInput::<&mut Vec<u8>>::push_ifindex;
5967        let _ = PushOvpnPeerNewInput::<&mut Vec<u8>>::nested_peer;
5968        let _ = PushOvpnPeerNewInput::<&mut Vec<u8>>::push_ifindex;
5969        let _ = PushOvpnPeerSetInput::<&mut Vec<u8>>::nested_peer;
5970        let _ = PushOvpnPeerSetInput::<&mut Vec<u8>>::push_ifindex;
5971    }
5972}