fidl_fuchsia_net_stack_common/
fidl_fuchsia_net_stack_common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11/// A path to a device node.
12pub type DevicePath = String;
13
14/// A value indicating that a [`ForwardingEntry`]'s metric is unspecified.
15pub const UNSPECIFIED_METRIC: u32 = 0;
16
17#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
18#[repr(u32)]
19pub enum Error {
20    Internal = 1,
21    NotSupported = 2,
22    InvalidArgs = 3,
23    BadState = 4,
24    TimeOut = 5,
25    NotFound = 6,
26    AlreadyExists = 7,
27    Io = 8,
28}
29
30impl Error {
31    #[inline]
32    pub fn from_primitive(prim: u32) -> Option<Self> {
33        match prim {
34            1 => Some(Self::Internal),
35            2 => Some(Self::NotSupported),
36            3 => Some(Self::InvalidArgs),
37            4 => Some(Self::BadState),
38            5 => Some(Self::TimeOut),
39            6 => Some(Self::NotFound),
40            7 => Some(Self::AlreadyExists),
41            8 => Some(Self::Io),
42            _ => None,
43        }
44    }
45
46    #[inline]
47    pub const fn into_primitive(self) -> u32 {
48        self as u32
49    }
50
51    #[deprecated = "Strict enums should not use `is_unknown`"]
52    #[inline]
53    pub fn is_unknown(&self) -> bool {
54        false
55    }
56}
57
58/// An entry in the forwarding table for the network stack.
59///
60/// Valid if at least one of [`device_id`] and [`next_hop`] is specified.
61#[derive(Clone, Debug, PartialEq)]
62pub struct ForwardingEntry {
63    /// The destination subnet this route can be used to send to.
64    pub subnet: fidl_fuchsia_net::Subnet,
65    /// The opaque identifier of the device to which packets should be forwarded. The zero value is
66    /// interpreted as unspecified. If unspecified, [`next_hop`] must be set, and will be used by
67    /// the server to select an appropriate device.
68    pub device_id: u64,
69    /// The IP address of the next hop. Used for link-layer address resolution, if present.
70    pub next_hop: Option<Box<fidl_fuchsia_net::IpAddress>>,
71    /// This entry's metric.
72    ///
73    /// [`UNSPECIFIED_METRIC`] is interpreted as unspecified.
74    pub metric: u32,
75}
76
77impl fidl::Persistable for ForwardingEntry {}
78
79#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
80pub struct LogSetLogPacketsRequest {
81    pub enabled: bool,
82}
83
84impl fidl::Persistable for LogSetLogPacketsRequest {}
85
86#[derive(Clone, Debug, PartialEq)]
87pub struct StackAddForwardingEntryRequest {
88    pub entry: ForwardingEntry,
89}
90
91impl fidl::Persistable for StackAddForwardingEntryRequest {}
92
93#[derive(Clone, Debug, PartialEq)]
94pub struct StackDelForwardingEntryRequest {
95    pub entry: ForwardingEntry,
96}
97
98impl fidl::Persistable for StackDelForwardingEntryRequest {}
99
100mod internal {
101    use super::*;
102    unsafe impl fidl::encoding::TypeMarker for Error {
103        type Owned = Self;
104
105        #[inline(always)]
106        fn inline_align(_context: fidl::encoding::Context) -> usize {
107            std::mem::align_of::<u32>()
108        }
109
110        #[inline(always)]
111        fn inline_size(_context: fidl::encoding::Context) -> usize {
112            std::mem::size_of::<u32>()
113        }
114
115        #[inline(always)]
116        fn encode_is_copy() -> bool {
117            true
118        }
119
120        #[inline(always)]
121        fn decode_is_copy() -> bool {
122            false
123        }
124    }
125
126    impl fidl::encoding::ValueTypeMarker for Error {
127        type Borrowed<'a> = Self;
128        #[inline(always)]
129        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
130            *value
131        }
132    }
133
134    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
135        #[inline]
136        unsafe fn encode(
137            self,
138            encoder: &mut fidl::encoding::Encoder<'_, D>,
139            offset: usize,
140            _depth: fidl::encoding::Depth,
141        ) -> fidl::Result<()> {
142            encoder.debug_check_bounds::<Self>(offset);
143            encoder.write_num(self.into_primitive(), offset);
144            Ok(())
145        }
146    }
147
148    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
149        #[inline(always)]
150        fn new_empty() -> Self {
151            Self::Internal
152        }
153
154        #[inline]
155        unsafe fn decode(
156            &mut self,
157            decoder: &mut fidl::encoding::Decoder<'_, D>,
158            offset: usize,
159            _depth: fidl::encoding::Depth,
160        ) -> fidl::Result<()> {
161            decoder.debug_check_bounds::<Self>(offset);
162            let prim = decoder.read_num::<u32>(offset);
163
164            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
165            Ok(())
166        }
167    }
168
169    impl fidl::encoding::ValueTypeMarker for ForwardingEntry {
170        type Borrowed<'a> = &'a Self;
171        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
172            value
173        }
174    }
175
176    unsafe impl fidl::encoding::TypeMarker for ForwardingEntry {
177        type Owned = Self;
178
179        #[inline(always)]
180        fn inline_align(_context: fidl::encoding::Context) -> usize {
181            8
182        }
183
184        #[inline(always)]
185        fn inline_size(_context: fidl::encoding::Context) -> usize {
186            56
187        }
188    }
189
190    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ForwardingEntry, D>
191        for &ForwardingEntry
192    {
193        #[inline]
194        unsafe fn encode(
195            self,
196            encoder: &mut fidl::encoding::Encoder<'_, D>,
197            offset: usize,
198            _depth: fidl::encoding::Depth,
199        ) -> fidl::Result<()> {
200            encoder.debug_check_bounds::<ForwardingEntry>(offset);
201            // Delegate to tuple encoding.
202            fidl::encoding::Encode::<ForwardingEntry, D>::encode(
203                (
204                    <fidl_fuchsia_net::Subnet as fidl::encoding::ValueTypeMarker>::borrow(&self.subnet),
205                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.device_id),
206                    <fidl::encoding::OptionalUnion<fidl_fuchsia_net::IpAddress> as fidl::encoding::ValueTypeMarker>::borrow(&self.next_hop),
207                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.metric),
208                ),
209                encoder, offset, _depth
210            )
211        }
212    }
213    unsafe impl<
214            D: fidl::encoding::ResourceDialect,
215            T0: fidl::encoding::Encode<fidl_fuchsia_net::Subnet, D>,
216            T1: fidl::encoding::Encode<u64, D>,
217            T2: fidl::encoding::Encode<fidl::encoding::OptionalUnion<fidl_fuchsia_net::IpAddress>, D>,
218            T3: fidl::encoding::Encode<u32, D>,
219        > fidl::encoding::Encode<ForwardingEntry, D> for (T0, T1, T2, T3)
220    {
221        #[inline]
222        unsafe fn encode(
223            self,
224            encoder: &mut fidl::encoding::Encoder<'_, D>,
225            offset: usize,
226            depth: fidl::encoding::Depth,
227        ) -> fidl::Result<()> {
228            encoder.debug_check_bounds::<ForwardingEntry>(offset);
229            // Zero out padding regions. There's no need to apply masks
230            // because the unmasked parts will be overwritten by fields.
231            unsafe {
232                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(48);
233                (ptr as *mut u64).write_unaligned(0);
234            }
235            // Write the fields.
236            self.0.encode(encoder, offset + 0, depth)?;
237            self.1.encode(encoder, offset + 24, depth)?;
238            self.2.encode(encoder, offset + 32, depth)?;
239            self.3.encode(encoder, offset + 48, depth)?;
240            Ok(())
241        }
242    }
243
244    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ForwardingEntry {
245        #[inline(always)]
246        fn new_empty() -> Self {
247            Self {
248                subnet: fidl::new_empty!(fidl_fuchsia_net::Subnet, D),
249                device_id: fidl::new_empty!(u64, D),
250                next_hop: fidl::new_empty!(
251                    fidl::encoding::OptionalUnion<fidl_fuchsia_net::IpAddress>,
252                    D
253                ),
254                metric: fidl::new_empty!(u32, D),
255            }
256        }
257
258        #[inline]
259        unsafe fn decode(
260            &mut self,
261            decoder: &mut fidl::encoding::Decoder<'_, D>,
262            offset: usize,
263            _depth: fidl::encoding::Depth,
264        ) -> fidl::Result<()> {
265            decoder.debug_check_bounds::<Self>(offset);
266            // Verify that padding bytes are zero.
267            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(48) };
268            let padval = unsafe { (ptr as *const u64).read_unaligned() };
269            let mask = 0xffffffff00000000u64;
270            let maskedval = padval & mask;
271            if maskedval != 0 {
272                return Err(fidl::Error::NonZeroPadding {
273                    padding_start: offset + 48 + ((mask as u64).trailing_zeros() / 8) as usize,
274                });
275            }
276            fidl::decode!(
277                fidl_fuchsia_net::Subnet,
278                D,
279                &mut self.subnet,
280                decoder,
281                offset + 0,
282                _depth
283            )?;
284            fidl::decode!(u64, D, &mut self.device_id, decoder, offset + 24, _depth)?;
285            fidl::decode!(
286                fidl::encoding::OptionalUnion<fidl_fuchsia_net::IpAddress>,
287                D,
288                &mut self.next_hop,
289                decoder,
290                offset + 32,
291                _depth
292            )?;
293            fidl::decode!(u32, D, &mut self.metric, decoder, offset + 48, _depth)?;
294            Ok(())
295        }
296    }
297
298    impl fidl::encoding::ValueTypeMarker for LogSetLogPacketsRequest {
299        type Borrowed<'a> = &'a Self;
300        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
301            value
302        }
303    }
304
305    unsafe impl fidl::encoding::TypeMarker for LogSetLogPacketsRequest {
306        type Owned = Self;
307
308        #[inline(always)]
309        fn inline_align(_context: fidl::encoding::Context) -> usize {
310            1
311        }
312
313        #[inline(always)]
314        fn inline_size(_context: fidl::encoding::Context) -> usize {
315            1
316        }
317    }
318
319    unsafe impl<D: fidl::encoding::ResourceDialect>
320        fidl::encoding::Encode<LogSetLogPacketsRequest, D> for &LogSetLogPacketsRequest
321    {
322        #[inline]
323        unsafe fn encode(
324            self,
325            encoder: &mut fidl::encoding::Encoder<'_, D>,
326            offset: usize,
327            _depth: fidl::encoding::Depth,
328        ) -> fidl::Result<()> {
329            encoder.debug_check_bounds::<LogSetLogPacketsRequest>(offset);
330            // Delegate to tuple encoding.
331            fidl::encoding::Encode::<LogSetLogPacketsRequest, D>::encode(
332                (<bool as fidl::encoding::ValueTypeMarker>::borrow(&self.enabled),),
333                encoder,
334                offset,
335                _depth,
336            )
337        }
338    }
339    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<bool, D>>
340        fidl::encoding::Encode<LogSetLogPacketsRequest, D> for (T0,)
341    {
342        #[inline]
343        unsafe fn encode(
344            self,
345            encoder: &mut fidl::encoding::Encoder<'_, D>,
346            offset: usize,
347            depth: fidl::encoding::Depth,
348        ) -> fidl::Result<()> {
349            encoder.debug_check_bounds::<LogSetLogPacketsRequest>(offset);
350            // Zero out padding regions. There's no need to apply masks
351            // because the unmasked parts will be overwritten by fields.
352            // Write the fields.
353            self.0.encode(encoder, offset + 0, depth)?;
354            Ok(())
355        }
356    }
357
358    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
359        for LogSetLogPacketsRequest
360    {
361        #[inline(always)]
362        fn new_empty() -> Self {
363            Self { enabled: fidl::new_empty!(bool, D) }
364        }
365
366        #[inline]
367        unsafe fn decode(
368            &mut self,
369            decoder: &mut fidl::encoding::Decoder<'_, D>,
370            offset: usize,
371            _depth: fidl::encoding::Depth,
372        ) -> fidl::Result<()> {
373            decoder.debug_check_bounds::<Self>(offset);
374            // Verify that padding bytes are zero.
375            fidl::decode!(bool, D, &mut self.enabled, decoder, offset + 0, _depth)?;
376            Ok(())
377        }
378    }
379
380    impl fidl::encoding::ValueTypeMarker for StackAddForwardingEntryRequest {
381        type Borrowed<'a> = &'a Self;
382        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
383            value
384        }
385    }
386
387    unsafe impl fidl::encoding::TypeMarker for StackAddForwardingEntryRequest {
388        type Owned = Self;
389
390        #[inline(always)]
391        fn inline_align(_context: fidl::encoding::Context) -> usize {
392            8
393        }
394
395        #[inline(always)]
396        fn inline_size(_context: fidl::encoding::Context) -> usize {
397            56
398        }
399    }
400
401    unsafe impl<D: fidl::encoding::ResourceDialect>
402        fidl::encoding::Encode<StackAddForwardingEntryRequest, D>
403        for &StackAddForwardingEntryRequest
404    {
405        #[inline]
406        unsafe fn encode(
407            self,
408            encoder: &mut fidl::encoding::Encoder<'_, D>,
409            offset: usize,
410            _depth: fidl::encoding::Depth,
411        ) -> fidl::Result<()> {
412            encoder.debug_check_bounds::<StackAddForwardingEntryRequest>(offset);
413            // Delegate to tuple encoding.
414            fidl::encoding::Encode::<StackAddForwardingEntryRequest, D>::encode(
415                (<ForwardingEntry as fidl::encoding::ValueTypeMarker>::borrow(&self.entry),),
416                encoder,
417                offset,
418                _depth,
419            )
420        }
421    }
422    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<ForwardingEntry, D>>
423        fidl::encoding::Encode<StackAddForwardingEntryRequest, D> for (T0,)
424    {
425        #[inline]
426        unsafe fn encode(
427            self,
428            encoder: &mut fidl::encoding::Encoder<'_, D>,
429            offset: usize,
430            depth: fidl::encoding::Depth,
431        ) -> fidl::Result<()> {
432            encoder.debug_check_bounds::<StackAddForwardingEntryRequest>(offset);
433            // Zero out padding regions. There's no need to apply masks
434            // because the unmasked parts will be overwritten by fields.
435            // Write the fields.
436            self.0.encode(encoder, offset + 0, depth)?;
437            Ok(())
438        }
439    }
440
441    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
442        for StackAddForwardingEntryRequest
443    {
444        #[inline(always)]
445        fn new_empty() -> Self {
446            Self { entry: fidl::new_empty!(ForwardingEntry, D) }
447        }
448
449        #[inline]
450        unsafe fn decode(
451            &mut self,
452            decoder: &mut fidl::encoding::Decoder<'_, D>,
453            offset: usize,
454            _depth: fidl::encoding::Depth,
455        ) -> fidl::Result<()> {
456            decoder.debug_check_bounds::<Self>(offset);
457            // Verify that padding bytes are zero.
458            fidl::decode!(ForwardingEntry, D, &mut self.entry, decoder, offset + 0, _depth)?;
459            Ok(())
460        }
461    }
462
463    impl fidl::encoding::ValueTypeMarker for StackDelForwardingEntryRequest {
464        type Borrowed<'a> = &'a Self;
465        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
466            value
467        }
468    }
469
470    unsafe impl fidl::encoding::TypeMarker for StackDelForwardingEntryRequest {
471        type Owned = Self;
472
473        #[inline(always)]
474        fn inline_align(_context: fidl::encoding::Context) -> usize {
475            8
476        }
477
478        #[inline(always)]
479        fn inline_size(_context: fidl::encoding::Context) -> usize {
480            56
481        }
482    }
483
484    unsafe impl<D: fidl::encoding::ResourceDialect>
485        fidl::encoding::Encode<StackDelForwardingEntryRequest, D>
486        for &StackDelForwardingEntryRequest
487    {
488        #[inline]
489        unsafe fn encode(
490            self,
491            encoder: &mut fidl::encoding::Encoder<'_, D>,
492            offset: usize,
493            _depth: fidl::encoding::Depth,
494        ) -> fidl::Result<()> {
495            encoder.debug_check_bounds::<StackDelForwardingEntryRequest>(offset);
496            // Delegate to tuple encoding.
497            fidl::encoding::Encode::<StackDelForwardingEntryRequest, D>::encode(
498                (<ForwardingEntry as fidl::encoding::ValueTypeMarker>::borrow(&self.entry),),
499                encoder,
500                offset,
501                _depth,
502            )
503        }
504    }
505    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<ForwardingEntry, D>>
506        fidl::encoding::Encode<StackDelForwardingEntryRequest, D> for (T0,)
507    {
508        #[inline]
509        unsafe fn encode(
510            self,
511            encoder: &mut fidl::encoding::Encoder<'_, D>,
512            offset: usize,
513            depth: fidl::encoding::Depth,
514        ) -> fidl::Result<()> {
515            encoder.debug_check_bounds::<StackDelForwardingEntryRequest>(offset);
516            // Zero out padding regions. There's no need to apply masks
517            // because the unmasked parts will be overwritten by fields.
518            // Write the fields.
519            self.0.encode(encoder, offset + 0, depth)?;
520            Ok(())
521        }
522    }
523
524    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
525        for StackDelForwardingEntryRequest
526    {
527        #[inline(always)]
528        fn new_empty() -> Self {
529            Self { entry: fidl::new_empty!(ForwardingEntry, D) }
530        }
531
532        #[inline]
533        unsafe fn decode(
534            &mut self,
535            decoder: &mut fidl::encoding::Decoder<'_, D>,
536            offset: usize,
537            _depth: fidl::encoding::Depth,
538        ) -> fidl::Result<()> {
539            decoder.debug_check_bounds::<Self>(offset);
540            // Verify that padding bytes are zero.
541            fidl::decode!(ForwardingEntry, D, &mut self.entry, decoder, offset + 0, _depth)?;
542            Ok(())
543        }
544    }
545}