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