fidl_fuchsia_net_stack/
fidl_fuchsia_net_stack.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::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_net_stack__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct StackBridgeInterfacesRequest {
16    pub interfaces: Vec<u64>,
17    pub bridge: fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for StackBridgeInterfacesRequest
22{
23}
24
25#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
26pub struct StackSetDhcpClientEnabledRequest {
27    pub id: u64,
28    pub enable: bool,
29}
30
31impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
32    for StackSetDhcpClientEnabledRequest
33{
34}
35
36#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
37pub struct LogMarker;
38
39impl fidl::endpoints::ProtocolMarker for LogMarker {
40    type Proxy = LogProxy;
41    type RequestStream = LogRequestStream;
42    #[cfg(target_os = "fuchsia")]
43    type SynchronousProxy = LogSynchronousProxy;
44
45    const DEBUG_NAME: &'static str = "fuchsia.net.stack.Log";
46}
47impl fidl::endpoints::DiscoverableProtocolMarker for LogMarker {}
48
49pub trait LogProxyInterface: Send + Sync {
50    type SetLogPacketsResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
51    fn r#set_log_packets(&self, enabled: bool) -> Self::SetLogPacketsResponseFut;
52}
53#[derive(Debug)]
54#[cfg(target_os = "fuchsia")]
55pub struct LogSynchronousProxy {
56    client: fidl::client::sync::Client,
57}
58
59#[cfg(target_os = "fuchsia")]
60impl fidl::endpoints::SynchronousProxy for LogSynchronousProxy {
61    type Proxy = LogProxy;
62    type Protocol = LogMarker;
63
64    fn from_channel(inner: fidl::Channel) -> Self {
65        Self::new(inner)
66    }
67
68    fn into_channel(self) -> fidl::Channel {
69        self.client.into_channel()
70    }
71
72    fn as_channel(&self) -> &fidl::Channel {
73        self.client.as_channel()
74    }
75}
76
77#[cfg(target_os = "fuchsia")]
78impl LogSynchronousProxy {
79    pub fn new(channel: fidl::Channel) -> Self {
80        let protocol_name = <LogMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
81        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
82    }
83
84    pub fn into_channel(self) -> fidl::Channel {
85        self.client.into_channel()
86    }
87
88    /// Waits until an event arrives and returns it. It is safe for other
89    /// threads to make concurrent requests while waiting for an event.
90    pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<LogEvent, fidl::Error> {
91        LogEvent::decode(self.client.wait_for_event(deadline)?)
92    }
93
94    /// Dynamically set packet logging.
95    pub fn r#set_log_packets(
96        &self,
97        mut enabled: bool,
98        ___deadline: zx::MonotonicInstant,
99    ) -> Result<(), fidl::Error> {
100        let _response =
101            self.client.send_query::<LogSetLogPacketsRequest, fidl::encoding::EmptyPayload>(
102                (enabled,),
103                0x2176044cba5f378e,
104                fidl::encoding::DynamicFlags::empty(),
105                ___deadline,
106            )?;
107        Ok(_response)
108    }
109}
110
111#[cfg(target_os = "fuchsia")]
112impl From<LogSynchronousProxy> for zx::NullableHandle {
113    fn from(value: LogSynchronousProxy) -> Self {
114        value.into_channel().into()
115    }
116}
117
118#[cfg(target_os = "fuchsia")]
119impl From<fidl::Channel> for LogSynchronousProxy {
120    fn from(value: fidl::Channel) -> Self {
121        Self::new(value)
122    }
123}
124
125#[cfg(target_os = "fuchsia")]
126impl fidl::endpoints::FromClient for LogSynchronousProxy {
127    type Protocol = LogMarker;
128
129    fn from_client(value: fidl::endpoints::ClientEnd<LogMarker>) -> Self {
130        Self::new(value.into_channel())
131    }
132}
133
134#[derive(Debug, Clone)]
135pub struct LogProxy {
136    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
137}
138
139impl fidl::endpoints::Proxy for LogProxy {
140    type Protocol = LogMarker;
141
142    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
143        Self::new(inner)
144    }
145
146    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
147        self.client.into_channel().map_err(|client| Self { client })
148    }
149
150    fn as_channel(&self) -> &::fidl::AsyncChannel {
151        self.client.as_channel()
152    }
153}
154
155impl LogProxy {
156    /// Create a new Proxy for fuchsia.net.stack/Log.
157    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
158        let protocol_name = <LogMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
159        Self { client: fidl::client::Client::new(channel, protocol_name) }
160    }
161
162    /// Get a Stream of events from the remote end of the protocol.
163    ///
164    /// # Panics
165    ///
166    /// Panics if the event stream was already taken.
167    pub fn take_event_stream(&self) -> LogEventStream {
168        LogEventStream { event_receiver: self.client.take_event_receiver() }
169    }
170
171    /// Dynamically set packet logging.
172    pub fn r#set_log_packets(
173        &self,
174        mut enabled: bool,
175    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
176        LogProxyInterface::r#set_log_packets(self, enabled)
177    }
178}
179
180impl LogProxyInterface for LogProxy {
181    type SetLogPacketsResponseFut =
182        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
183    fn r#set_log_packets(&self, mut enabled: bool) -> Self::SetLogPacketsResponseFut {
184        fn _decode(
185            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
186        ) -> Result<(), fidl::Error> {
187            let _response = fidl::client::decode_transaction_body::<
188                fidl::encoding::EmptyPayload,
189                fidl::encoding::DefaultFuchsiaResourceDialect,
190                0x2176044cba5f378e,
191            >(_buf?)?;
192            Ok(_response)
193        }
194        self.client.send_query_and_decode::<LogSetLogPacketsRequest, ()>(
195            (enabled,),
196            0x2176044cba5f378e,
197            fidl::encoding::DynamicFlags::empty(),
198            _decode,
199        )
200    }
201}
202
203pub struct LogEventStream {
204    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
205}
206
207impl std::marker::Unpin for LogEventStream {}
208
209impl futures::stream::FusedStream for LogEventStream {
210    fn is_terminated(&self) -> bool {
211        self.event_receiver.is_terminated()
212    }
213}
214
215impl futures::Stream for LogEventStream {
216    type Item = Result<LogEvent, fidl::Error>;
217
218    fn poll_next(
219        mut self: std::pin::Pin<&mut Self>,
220        cx: &mut std::task::Context<'_>,
221    ) -> std::task::Poll<Option<Self::Item>> {
222        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
223            &mut self.event_receiver,
224            cx
225        )?) {
226            Some(buf) => std::task::Poll::Ready(Some(LogEvent::decode(buf))),
227            None => std::task::Poll::Ready(None),
228        }
229    }
230}
231
232#[derive(Debug)]
233pub enum LogEvent {}
234
235impl LogEvent {
236    /// Decodes a message buffer as a [`LogEvent`].
237    fn decode(
238        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
239    ) -> Result<LogEvent, fidl::Error> {
240        let (bytes, _handles) = buf.split_mut();
241        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
242        debug_assert_eq!(tx_header.tx_id, 0);
243        match tx_header.ordinal {
244            _ => Err(fidl::Error::UnknownOrdinal {
245                ordinal: tx_header.ordinal,
246                protocol_name: <LogMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
247            }),
248        }
249    }
250}
251
252/// A Stream of incoming requests for fuchsia.net.stack/Log.
253pub struct LogRequestStream {
254    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
255    is_terminated: bool,
256}
257
258impl std::marker::Unpin for LogRequestStream {}
259
260impl futures::stream::FusedStream for LogRequestStream {
261    fn is_terminated(&self) -> bool {
262        self.is_terminated
263    }
264}
265
266impl fidl::endpoints::RequestStream for LogRequestStream {
267    type Protocol = LogMarker;
268    type ControlHandle = LogControlHandle;
269
270    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
271        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
272    }
273
274    fn control_handle(&self) -> Self::ControlHandle {
275        LogControlHandle { inner: self.inner.clone() }
276    }
277
278    fn into_inner(
279        self,
280    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
281    {
282        (self.inner, self.is_terminated)
283    }
284
285    fn from_inner(
286        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
287        is_terminated: bool,
288    ) -> Self {
289        Self { inner, is_terminated }
290    }
291}
292
293impl futures::Stream for LogRequestStream {
294    type Item = Result<LogRequest, fidl::Error>;
295
296    fn poll_next(
297        mut self: std::pin::Pin<&mut Self>,
298        cx: &mut std::task::Context<'_>,
299    ) -> std::task::Poll<Option<Self::Item>> {
300        let this = &mut *self;
301        if this.inner.check_shutdown(cx) {
302            this.is_terminated = true;
303            return std::task::Poll::Ready(None);
304        }
305        if this.is_terminated {
306            panic!("polled LogRequestStream after completion");
307        }
308        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
309            |bytes, handles| {
310                match this.inner.channel().read_etc(cx, bytes, handles) {
311                    std::task::Poll::Ready(Ok(())) => {}
312                    std::task::Poll::Pending => return std::task::Poll::Pending,
313                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
314                        this.is_terminated = true;
315                        return std::task::Poll::Ready(None);
316                    }
317                    std::task::Poll::Ready(Err(e)) => {
318                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
319                            e.into(),
320                        ))));
321                    }
322                }
323
324                // A message has been received from the channel
325                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
326
327                std::task::Poll::Ready(Some(match header.ordinal {
328                    0x2176044cba5f378e => {
329                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
330                        let mut req = fidl::new_empty!(
331                            LogSetLogPacketsRequest,
332                            fidl::encoding::DefaultFuchsiaResourceDialect
333                        );
334                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<LogSetLogPacketsRequest>(&header, _body_bytes, handles, &mut req)?;
335                        let control_handle = LogControlHandle { inner: this.inner.clone() };
336                        Ok(LogRequest::SetLogPackets {
337                            enabled: req.enabled,
338
339                            responder: LogSetLogPacketsResponder {
340                                control_handle: std::mem::ManuallyDrop::new(control_handle),
341                                tx_id: header.tx_id,
342                            },
343                        })
344                    }
345                    _ => Err(fidl::Error::UnknownOrdinal {
346                        ordinal: header.ordinal,
347                        protocol_name: <LogMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
348                    }),
349                }))
350            },
351        )
352    }
353}
354
355#[derive(Debug)]
356pub enum LogRequest {
357    /// Dynamically set packet logging.
358    SetLogPackets { enabled: bool, responder: LogSetLogPacketsResponder },
359}
360
361impl LogRequest {
362    #[allow(irrefutable_let_patterns)]
363    pub fn into_set_log_packets(self) -> Option<(bool, LogSetLogPacketsResponder)> {
364        if let LogRequest::SetLogPackets { enabled, responder } = self {
365            Some((enabled, responder))
366        } else {
367            None
368        }
369    }
370
371    /// Name of the method defined in FIDL
372    pub fn method_name(&self) -> &'static str {
373        match *self {
374            LogRequest::SetLogPackets { .. } => "set_log_packets",
375        }
376    }
377}
378
379#[derive(Debug, Clone)]
380pub struct LogControlHandle {
381    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
382}
383
384impl fidl::endpoints::ControlHandle for LogControlHandle {
385    fn shutdown(&self) {
386        self.inner.shutdown()
387    }
388
389    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
390        self.inner.shutdown_with_epitaph(status)
391    }
392
393    fn is_closed(&self) -> bool {
394        self.inner.channel().is_closed()
395    }
396    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
397        self.inner.channel().on_closed()
398    }
399
400    #[cfg(target_os = "fuchsia")]
401    fn signal_peer(
402        &self,
403        clear_mask: zx::Signals,
404        set_mask: zx::Signals,
405    ) -> Result<(), zx_status::Status> {
406        use fidl::Peered;
407        self.inner.channel().signal_peer(clear_mask, set_mask)
408    }
409}
410
411impl LogControlHandle {}
412
413#[must_use = "FIDL methods require a response to be sent"]
414#[derive(Debug)]
415pub struct LogSetLogPacketsResponder {
416    control_handle: std::mem::ManuallyDrop<LogControlHandle>,
417    tx_id: u32,
418}
419
420/// Set the the channel to be shutdown (see [`LogControlHandle::shutdown`])
421/// if the responder is dropped without sending a response, so that the client
422/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
423impl std::ops::Drop for LogSetLogPacketsResponder {
424    fn drop(&mut self) {
425        self.control_handle.shutdown();
426        // Safety: drops once, never accessed again
427        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
428    }
429}
430
431impl fidl::endpoints::Responder for LogSetLogPacketsResponder {
432    type ControlHandle = LogControlHandle;
433
434    fn control_handle(&self) -> &LogControlHandle {
435        &self.control_handle
436    }
437
438    fn drop_without_shutdown(mut self) {
439        // Safety: drops once, never accessed again due to mem::forget
440        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
441        // Prevent Drop from running (which would shut down the channel)
442        std::mem::forget(self);
443    }
444}
445
446impl LogSetLogPacketsResponder {
447    /// Sends a response to the FIDL transaction.
448    ///
449    /// Sets the channel to shutdown if an error occurs.
450    pub fn send(self) -> Result<(), fidl::Error> {
451        let _result = self.send_raw();
452        if _result.is_err() {
453            self.control_handle.shutdown();
454        }
455        self.drop_without_shutdown();
456        _result
457    }
458
459    /// Similar to "send" but does not shutdown the channel if an error occurs.
460    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
461        let _result = self.send_raw();
462        self.drop_without_shutdown();
463        _result
464    }
465
466    fn send_raw(&self) -> Result<(), fidl::Error> {
467        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
468            (),
469            self.tx_id,
470            0x2176044cba5f378e,
471            fidl::encoding::DynamicFlags::empty(),
472        )
473    }
474}
475
476#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
477pub struct StackMarker;
478
479impl fidl::endpoints::ProtocolMarker for StackMarker {
480    type Proxy = StackProxy;
481    type RequestStream = StackRequestStream;
482    #[cfg(target_os = "fuchsia")]
483    type SynchronousProxy = StackSynchronousProxy;
484
485    const DEBUG_NAME: &'static str = "fuchsia.net.stack.Stack";
486}
487impl fidl::endpoints::DiscoverableProtocolMarker for StackMarker {}
488pub type StackAddForwardingEntryResult = Result<(), Error>;
489pub type StackDelForwardingEntryResult = Result<(), Error>;
490pub type StackSetDhcpClientEnabledResult = Result<(), Error>;
491
492pub trait StackProxyInterface: Send + Sync {
493    type AddForwardingEntryResponseFut: std::future::Future<Output = Result<StackAddForwardingEntryResult, fidl::Error>>
494        + Send;
495    fn r#add_forwarding_entry(
496        &self,
497        entry: &ForwardingEntry,
498    ) -> Self::AddForwardingEntryResponseFut;
499    type DelForwardingEntryResponseFut: std::future::Future<Output = Result<StackDelForwardingEntryResult, fidl::Error>>
500        + Send;
501    fn r#del_forwarding_entry(
502        &self,
503        entry: &ForwardingEntry,
504    ) -> Self::DelForwardingEntryResponseFut;
505    type SetDhcpClientEnabledResponseFut: std::future::Future<Output = Result<StackSetDhcpClientEnabledResult, fidl::Error>>
506        + Send;
507    fn r#set_dhcp_client_enabled(
508        &self,
509        id: u64,
510        enable: bool,
511    ) -> Self::SetDhcpClientEnabledResponseFut;
512    fn r#bridge_interfaces(
513        &self,
514        interfaces: &[u64],
515        bridge: fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>,
516    ) -> Result<(), fidl::Error>;
517}
518#[derive(Debug)]
519#[cfg(target_os = "fuchsia")]
520pub struct StackSynchronousProxy {
521    client: fidl::client::sync::Client,
522}
523
524#[cfg(target_os = "fuchsia")]
525impl fidl::endpoints::SynchronousProxy for StackSynchronousProxy {
526    type Proxy = StackProxy;
527    type Protocol = StackMarker;
528
529    fn from_channel(inner: fidl::Channel) -> Self {
530        Self::new(inner)
531    }
532
533    fn into_channel(self) -> fidl::Channel {
534        self.client.into_channel()
535    }
536
537    fn as_channel(&self) -> &fidl::Channel {
538        self.client.as_channel()
539    }
540}
541
542#[cfg(target_os = "fuchsia")]
543impl StackSynchronousProxy {
544    pub fn new(channel: fidl::Channel) -> Self {
545        let protocol_name = <StackMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
546        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
547    }
548
549    pub fn into_channel(self) -> fidl::Channel {
550        self.client.into_channel()
551    }
552
553    /// Waits until an event arrives and returns it. It is safe for other
554    /// threads to make concurrent requests while waiting for an event.
555    pub fn wait_for_event(
556        &self,
557        deadline: zx::MonotonicInstant,
558    ) -> Result<StackEvent, fidl::Error> {
559        StackEvent::decode(self.client.wait_for_event(deadline)?)
560    }
561
562    /// Add a new entry to the forwarding table.
563    ///
564    /// If the table already contains an entry with the same subnet and
565    /// destination, an already exists error is returned.
566    pub fn r#add_forwarding_entry(
567        &self,
568        mut entry: &ForwardingEntry,
569        ___deadline: zx::MonotonicInstant,
570    ) -> Result<StackAddForwardingEntryResult, fidl::Error> {
571        let _response = self.client.send_query::<
572            StackAddForwardingEntryRequest,
573            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
574        >(
575            (entry,),
576            0x5fe2020877107909,
577            fidl::encoding::DynamicFlags::empty(),
578            ___deadline,
579        )?;
580        Ok(_response.map(|x| x))
581    }
582
583    /// Removes the forwarding entry. The entry must exactly match an entry in
584    /// the forwarding table, with the exception of the metric value, which is
585    /// ignored.
586    pub fn r#del_forwarding_entry(
587        &self,
588        mut entry: &ForwardingEntry,
589        ___deadline: zx::MonotonicInstant,
590    ) -> Result<StackDelForwardingEntryResult, fidl::Error> {
591        let _response = self.client.send_query::<
592            StackDelForwardingEntryRequest,
593            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
594        >(
595            (entry,),
596            0x560f3944c4cb51bd,
597            fidl::encoding::DynamicFlags::empty(),
598            ___deadline,
599        )?;
600        Ok(_response.map(|x| x))
601    }
602
603    /// Enables or disables the DHCP client on an interface.
604    /// TODO(https://fxbug.dev/42162065): Remove this once the DHCP client is moved
605    /// out of the netstack.
606    pub fn r#set_dhcp_client_enabled(
607        &self,
608        mut id: u64,
609        mut enable: bool,
610        ___deadline: zx::MonotonicInstant,
611    ) -> Result<StackSetDhcpClientEnabledResult, fidl::Error> {
612        let _response = self.client.send_query::<
613            StackSetDhcpClientEnabledRequest,
614            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
615        >(
616            (id, enable,),
617            0x6dead3a6025b0543,
618            fidl::encoding::DynamicFlags::empty(),
619            ___deadline,
620        )?;
621        Ok(_response.map(|x| x))
622    }
623
624    /// Creates a bridge over the provided `interfaces`.
625    ///
626    /// If the bridge can't be created, `bridge` is closed with a `BAD_PORT`
627    /// termination reason.
628    ///
629    /// NOTE: We're shoehorning bridging into the `admin/Control` API and
630    /// reassigning meaning to `BAD_PORT` because we don't want to leak
631    /// bridging-specific errors there. The POR is that bridging is going to get
632    /// its own API at some point.
633    ///
634    /// Bridge lifetime is controlled through the `bridge` handle.
635    pub fn r#bridge_interfaces(
636        &self,
637        mut interfaces: &[u64],
638        mut bridge: fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>,
639    ) -> Result<(), fidl::Error> {
640        self.client.send::<StackBridgeInterfacesRequest>(
641            (interfaces, bridge),
642            0x60509044a41ac976,
643            fidl::encoding::DynamicFlags::empty(),
644        )
645    }
646}
647
648#[cfg(target_os = "fuchsia")]
649impl From<StackSynchronousProxy> for zx::NullableHandle {
650    fn from(value: StackSynchronousProxy) -> Self {
651        value.into_channel().into()
652    }
653}
654
655#[cfg(target_os = "fuchsia")]
656impl From<fidl::Channel> for StackSynchronousProxy {
657    fn from(value: fidl::Channel) -> Self {
658        Self::new(value)
659    }
660}
661
662#[cfg(target_os = "fuchsia")]
663impl fidl::endpoints::FromClient for StackSynchronousProxy {
664    type Protocol = StackMarker;
665
666    fn from_client(value: fidl::endpoints::ClientEnd<StackMarker>) -> Self {
667        Self::new(value.into_channel())
668    }
669}
670
671#[derive(Debug, Clone)]
672pub struct StackProxy {
673    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
674}
675
676impl fidl::endpoints::Proxy for StackProxy {
677    type Protocol = StackMarker;
678
679    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
680        Self::new(inner)
681    }
682
683    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
684        self.client.into_channel().map_err(|client| Self { client })
685    }
686
687    fn as_channel(&self) -> &::fidl::AsyncChannel {
688        self.client.as_channel()
689    }
690}
691
692impl StackProxy {
693    /// Create a new Proxy for fuchsia.net.stack/Stack.
694    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
695        let protocol_name = <StackMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
696        Self { client: fidl::client::Client::new(channel, protocol_name) }
697    }
698
699    /// Get a Stream of events from the remote end of the protocol.
700    ///
701    /// # Panics
702    ///
703    /// Panics if the event stream was already taken.
704    pub fn take_event_stream(&self) -> StackEventStream {
705        StackEventStream { event_receiver: self.client.take_event_receiver() }
706    }
707
708    /// Add a new entry to the forwarding table.
709    ///
710    /// If the table already contains an entry with the same subnet and
711    /// destination, an already exists error is returned.
712    pub fn r#add_forwarding_entry(
713        &self,
714        mut entry: &ForwardingEntry,
715    ) -> fidl::client::QueryResponseFut<
716        StackAddForwardingEntryResult,
717        fidl::encoding::DefaultFuchsiaResourceDialect,
718    > {
719        StackProxyInterface::r#add_forwarding_entry(self, entry)
720    }
721
722    /// Removes the forwarding entry. The entry must exactly match an entry in
723    /// the forwarding table, with the exception of the metric value, which is
724    /// ignored.
725    pub fn r#del_forwarding_entry(
726        &self,
727        mut entry: &ForwardingEntry,
728    ) -> fidl::client::QueryResponseFut<
729        StackDelForwardingEntryResult,
730        fidl::encoding::DefaultFuchsiaResourceDialect,
731    > {
732        StackProxyInterface::r#del_forwarding_entry(self, entry)
733    }
734
735    /// Enables or disables the DHCP client on an interface.
736    /// TODO(https://fxbug.dev/42162065): Remove this once the DHCP client is moved
737    /// out of the netstack.
738    pub fn r#set_dhcp_client_enabled(
739        &self,
740        mut id: u64,
741        mut enable: bool,
742    ) -> fidl::client::QueryResponseFut<
743        StackSetDhcpClientEnabledResult,
744        fidl::encoding::DefaultFuchsiaResourceDialect,
745    > {
746        StackProxyInterface::r#set_dhcp_client_enabled(self, id, enable)
747    }
748
749    /// Creates a bridge over the provided `interfaces`.
750    ///
751    /// If the bridge can't be created, `bridge` is closed with a `BAD_PORT`
752    /// termination reason.
753    ///
754    /// NOTE: We're shoehorning bridging into the `admin/Control` API and
755    /// reassigning meaning to `BAD_PORT` because we don't want to leak
756    /// bridging-specific errors there. The POR is that bridging is going to get
757    /// its own API at some point.
758    ///
759    /// Bridge lifetime is controlled through the `bridge` handle.
760    pub fn r#bridge_interfaces(
761        &self,
762        mut interfaces: &[u64],
763        mut bridge: fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>,
764    ) -> Result<(), fidl::Error> {
765        StackProxyInterface::r#bridge_interfaces(self, interfaces, bridge)
766    }
767}
768
769impl StackProxyInterface for StackProxy {
770    type AddForwardingEntryResponseFut = fidl::client::QueryResponseFut<
771        StackAddForwardingEntryResult,
772        fidl::encoding::DefaultFuchsiaResourceDialect,
773    >;
774    fn r#add_forwarding_entry(
775        &self,
776        mut entry: &ForwardingEntry,
777    ) -> Self::AddForwardingEntryResponseFut {
778        fn _decode(
779            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
780        ) -> Result<StackAddForwardingEntryResult, fidl::Error> {
781            let _response = fidl::client::decode_transaction_body::<
782                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
783                fidl::encoding::DefaultFuchsiaResourceDialect,
784                0x5fe2020877107909,
785            >(_buf?)?;
786            Ok(_response.map(|x| x))
787        }
788        self.client
789            .send_query_and_decode::<StackAddForwardingEntryRequest, StackAddForwardingEntryResult>(
790                (entry,),
791                0x5fe2020877107909,
792                fidl::encoding::DynamicFlags::empty(),
793                _decode,
794            )
795    }
796
797    type DelForwardingEntryResponseFut = fidl::client::QueryResponseFut<
798        StackDelForwardingEntryResult,
799        fidl::encoding::DefaultFuchsiaResourceDialect,
800    >;
801    fn r#del_forwarding_entry(
802        &self,
803        mut entry: &ForwardingEntry,
804    ) -> Self::DelForwardingEntryResponseFut {
805        fn _decode(
806            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
807        ) -> Result<StackDelForwardingEntryResult, fidl::Error> {
808            let _response = fidl::client::decode_transaction_body::<
809                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
810                fidl::encoding::DefaultFuchsiaResourceDialect,
811                0x560f3944c4cb51bd,
812            >(_buf?)?;
813            Ok(_response.map(|x| x))
814        }
815        self.client
816            .send_query_and_decode::<StackDelForwardingEntryRequest, StackDelForwardingEntryResult>(
817                (entry,),
818                0x560f3944c4cb51bd,
819                fidl::encoding::DynamicFlags::empty(),
820                _decode,
821            )
822    }
823
824    type SetDhcpClientEnabledResponseFut = fidl::client::QueryResponseFut<
825        StackSetDhcpClientEnabledResult,
826        fidl::encoding::DefaultFuchsiaResourceDialect,
827    >;
828    fn r#set_dhcp_client_enabled(
829        &self,
830        mut id: u64,
831        mut enable: bool,
832    ) -> Self::SetDhcpClientEnabledResponseFut {
833        fn _decode(
834            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
835        ) -> Result<StackSetDhcpClientEnabledResult, fidl::Error> {
836            let _response = fidl::client::decode_transaction_body::<
837                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
838                fidl::encoding::DefaultFuchsiaResourceDialect,
839                0x6dead3a6025b0543,
840            >(_buf?)?;
841            Ok(_response.map(|x| x))
842        }
843        self.client.send_query_and_decode::<
844            StackSetDhcpClientEnabledRequest,
845            StackSetDhcpClientEnabledResult,
846        >(
847            (id, enable,),
848            0x6dead3a6025b0543,
849            fidl::encoding::DynamicFlags::empty(),
850            _decode,
851        )
852    }
853
854    fn r#bridge_interfaces(
855        &self,
856        mut interfaces: &[u64],
857        mut bridge: fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>,
858    ) -> Result<(), fidl::Error> {
859        self.client.send::<StackBridgeInterfacesRequest>(
860            (interfaces, bridge),
861            0x60509044a41ac976,
862            fidl::encoding::DynamicFlags::empty(),
863        )
864    }
865}
866
867pub struct StackEventStream {
868    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
869}
870
871impl std::marker::Unpin for StackEventStream {}
872
873impl futures::stream::FusedStream for StackEventStream {
874    fn is_terminated(&self) -> bool {
875        self.event_receiver.is_terminated()
876    }
877}
878
879impl futures::Stream for StackEventStream {
880    type Item = Result<StackEvent, fidl::Error>;
881
882    fn poll_next(
883        mut self: std::pin::Pin<&mut Self>,
884        cx: &mut std::task::Context<'_>,
885    ) -> std::task::Poll<Option<Self::Item>> {
886        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
887            &mut self.event_receiver,
888            cx
889        )?) {
890            Some(buf) => std::task::Poll::Ready(Some(StackEvent::decode(buf))),
891            None => std::task::Poll::Ready(None),
892        }
893    }
894}
895
896#[derive(Debug)]
897pub enum StackEvent {}
898
899impl StackEvent {
900    /// Decodes a message buffer as a [`StackEvent`].
901    fn decode(
902        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
903    ) -> Result<StackEvent, fidl::Error> {
904        let (bytes, _handles) = buf.split_mut();
905        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
906        debug_assert_eq!(tx_header.tx_id, 0);
907        match tx_header.ordinal {
908            _ => Err(fidl::Error::UnknownOrdinal {
909                ordinal: tx_header.ordinal,
910                protocol_name: <StackMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
911            }),
912        }
913    }
914}
915
916/// A Stream of incoming requests for fuchsia.net.stack/Stack.
917pub struct StackRequestStream {
918    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
919    is_terminated: bool,
920}
921
922impl std::marker::Unpin for StackRequestStream {}
923
924impl futures::stream::FusedStream for StackRequestStream {
925    fn is_terminated(&self) -> bool {
926        self.is_terminated
927    }
928}
929
930impl fidl::endpoints::RequestStream for StackRequestStream {
931    type Protocol = StackMarker;
932    type ControlHandle = StackControlHandle;
933
934    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
935        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
936    }
937
938    fn control_handle(&self) -> Self::ControlHandle {
939        StackControlHandle { inner: self.inner.clone() }
940    }
941
942    fn into_inner(
943        self,
944    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
945    {
946        (self.inner, self.is_terminated)
947    }
948
949    fn from_inner(
950        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
951        is_terminated: bool,
952    ) -> Self {
953        Self { inner, is_terminated }
954    }
955}
956
957impl futures::Stream for StackRequestStream {
958    type Item = Result<StackRequest, fidl::Error>;
959
960    fn poll_next(
961        mut self: std::pin::Pin<&mut Self>,
962        cx: &mut std::task::Context<'_>,
963    ) -> std::task::Poll<Option<Self::Item>> {
964        let this = &mut *self;
965        if this.inner.check_shutdown(cx) {
966            this.is_terminated = true;
967            return std::task::Poll::Ready(None);
968        }
969        if this.is_terminated {
970            panic!("polled StackRequestStream after completion");
971        }
972        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
973            |bytes, handles| {
974                match this.inner.channel().read_etc(cx, bytes, handles) {
975                    std::task::Poll::Ready(Ok(())) => {}
976                    std::task::Poll::Pending => return std::task::Poll::Pending,
977                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
978                        this.is_terminated = true;
979                        return std::task::Poll::Ready(None);
980                    }
981                    std::task::Poll::Ready(Err(e)) => {
982                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
983                            e.into(),
984                        ))));
985                    }
986                }
987
988                // A message has been received from the channel
989                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
990
991                std::task::Poll::Ready(Some(match header.ordinal {
992                    0x5fe2020877107909 => {
993                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
994                        let mut req = fidl::new_empty!(
995                            StackAddForwardingEntryRequest,
996                            fidl::encoding::DefaultFuchsiaResourceDialect
997                        );
998                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StackAddForwardingEntryRequest>(&header, _body_bytes, handles, &mut req)?;
999                        let control_handle = StackControlHandle { inner: this.inner.clone() };
1000                        Ok(StackRequest::AddForwardingEntry {
1001                            entry: req.entry,
1002
1003                            responder: StackAddForwardingEntryResponder {
1004                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1005                                tx_id: header.tx_id,
1006                            },
1007                        })
1008                    }
1009                    0x560f3944c4cb51bd => {
1010                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1011                        let mut req = fidl::new_empty!(
1012                            StackDelForwardingEntryRequest,
1013                            fidl::encoding::DefaultFuchsiaResourceDialect
1014                        );
1015                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StackDelForwardingEntryRequest>(&header, _body_bytes, handles, &mut req)?;
1016                        let control_handle = StackControlHandle { inner: this.inner.clone() };
1017                        Ok(StackRequest::DelForwardingEntry {
1018                            entry: req.entry,
1019
1020                            responder: StackDelForwardingEntryResponder {
1021                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1022                                tx_id: header.tx_id,
1023                            },
1024                        })
1025                    }
1026                    0x6dead3a6025b0543 => {
1027                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1028                        let mut req = fidl::new_empty!(
1029                            StackSetDhcpClientEnabledRequest,
1030                            fidl::encoding::DefaultFuchsiaResourceDialect
1031                        );
1032                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StackSetDhcpClientEnabledRequest>(&header, _body_bytes, handles, &mut req)?;
1033                        let control_handle = StackControlHandle { inner: this.inner.clone() };
1034                        Ok(StackRequest::SetDhcpClientEnabled {
1035                            id: req.id,
1036                            enable: req.enable,
1037
1038                            responder: StackSetDhcpClientEnabledResponder {
1039                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1040                                tx_id: header.tx_id,
1041                            },
1042                        })
1043                    }
1044                    0x60509044a41ac976 => {
1045                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1046                        let mut req = fidl::new_empty!(
1047                            StackBridgeInterfacesRequest,
1048                            fidl::encoding::DefaultFuchsiaResourceDialect
1049                        );
1050                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StackBridgeInterfacesRequest>(&header, _body_bytes, handles, &mut req)?;
1051                        let control_handle = StackControlHandle { inner: this.inner.clone() };
1052                        Ok(StackRequest::BridgeInterfaces {
1053                            interfaces: req.interfaces,
1054                            bridge: req.bridge,
1055
1056                            control_handle,
1057                        })
1058                    }
1059                    _ => Err(fidl::Error::UnknownOrdinal {
1060                        ordinal: header.ordinal,
1061                        protocol_name: <StackMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1062                    }),
1063                }))
1064            },
1065        )
1066    }
1067}
1068
1069#[derive(Debug)]
1070pub enum StackRequest {
1071    /// Add a new entry to the forwarding table.
1072    ///
1073    /// If the table already contains an entry with the same subnet and
1074    /// destination, an already exists error is returned.
1075    AddForwardingEntry { entry: ForwardingEntry, responder: StackAddForwardingEntryResponder },
1076    /// Removes the forwarding entry. The entry must exactly match an entry in
1077    /// the forwarding table, with the exception of the metric value, which is
1078    /// ignored.
1079    DelForwardingEntry { entry: ForwardingEntry, responder: StackDelForwardingEntryResponder },
1080    /// Enables or disables the DHCP client on an interface.
1081    /// TODO(https://fxbug.dev/42162065): Remove this once the DHCP client is moved
1082    /// out of the netstack.
1083    SetDhcpClientEnabled { id: u64, enable: bool, responder: StackSetDhcpClientEnabledResponder },
1084    /// Creates a bridge over the provided `interfaces`.
1085    ///
1086    /// If the bridge can't be created, `bridge` is closed with a `BAD_PORT`
1087    /// termination reason.
1088    ///
1089    /// NOTE: We're shoehorning bridging into the `admin/Control` API and
1090    /// reassigning meaning to `BAD_PORT` because we don't want to leak
1091    /// bridging-specific errors there. The POR is that bridging is going to get
1092    /// its own API at some point.
1093    ///
1094    /// Bridge lifetime is controlled through the `bridge` handle.
1095    BridgeInterfaces {
1096        interfaces: Vec<u64>,
1097        bridge: fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>,
1098        control_handle: StackControlHandle,
1099    },
1100}
1101
1102impl StackRequest {
1103    #[allow(irrefutable_let_patterns)]
1104    pub fn into_add_forwarding_entry(
1105        self,
1106    ) -> Option<(ForwardingEntry, StackAddForwardingEntryResponder)> {
1107        if let StackRequest::AddForwardingEntry { entry, responder } = self {
1108            Some((entry, responder))
1109        } else {
1110            None
1111        }
1112    }
1113
1114    #[allow(irrefutable_let_patterns)]
1115    pub fn into_del_forwarding_entry(
1116        self,
1117    ) -> Option<(ForwardingEntry, StackDelForwardingEntryResponder)> {
1118        if let StackRequest::DelForwardingEntry { entry, responder } = self {
1119            Some((entry, responder))
1120        } else {
1121            None
1122        }
1123    }
1124
1125    #[allow(irrefutable_let_patterns)]
1126    pub fn into_set_dhcp_client_enabled(
1127        self,
1128    ) -> Option<(u64, bool, StackSetDhcpClientEnabledResponder)> {
1129        if let StackRequest::SetDhcpClientEnabled { id, enable, responder } = self {
1130            Some((id, enable, responder))
1131        } else {
1132            None
1133        }
1134    }
1135
1136    #[allow(irrefutable_let_patterns)]
1137    pub fn into_bridge_interfaces(
1138        self,
1139    ) -> Option<(
1140        Vec<u64>,
1141        fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>,
1142        StackControlHandle,
1143    )> {
1144        if let StackRequest::BridgeInterfaces { interfaces, bridge, control_handle } = self {
1145            Some((interfaces, bridge, control_handle))
1146        } else {
1147            None
1148        }
1149    }
1150
1151    /// Name of the method defined in FIDL
1152    pub fn method_name(&self) -> &'static str {
1153        match *self {
1154            StackRequest::AddForwardingEntry { .. } => "add_forwarding_entry",
1155            StackRequest::DelForwardingEntry { .. } => "del_forwarding_entry",
1156            StackRequest::SetDhcpClientEnabled { .. } => "set_dhcp_client_enabled",
1157            StackRequest::BridgeInterfaces { .. } => "bridge_interfaces",
1158        }
1159    }
1160}
1161
1162#[derive(Debug, Clone)]
1163pub struct StackControlHandle {
1164    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1165}
1166
1167impl fidl::endpoints::ControlHandle for StackControlHandle {
1168    fn shutdown(&self) {
1169        self.inner.shutdown()
1170    }
1171
1172    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1173        self.inner.shutdown_with_epitaph(status)
1174    }
1175
1176    fn is_closed(&self) -> bool {
1177        self.inner.channel().is_closed()
1178    }
1179    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1180        self.inner.channel().on_closed()
1181    }
1182
1183    #[cfg(target_os = "fuchsia")]
1184    fn signal_peer(
1185        &self,
1186        clear_mask: zx::Signals,
1187        set_mask: zx::Signals,
1188    ) -> Result<(), zx_status::Status> {
1189        use fidl::Peered;
1190        self.inner.channel().signal_peer(clear_mask, set_mask)
1191    }
1192}
1193
1194impl StackControlHandle {}
1195
1196#[must_use = "FIDL methods require a response to be sent"]
1197#[derive(Debug)]
1198pub struct StackAddForwardingEntryResponder {
1199    control_handle: std::mem::ManuallyDrop<StackControlHandle>,
1200    tx_id: u32,
1201}
1202
1203/// Set the the channel to be shutdown (see [`StackControlHandle::shutdown`])
1204/// if the responder is dropped without sending a response, so that the client
1205/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1206impl std::ops::Drop for StackAddForwardingEntryResponder {
1207    fn drop(&mut self) {
1208        self.control_handle.shutdown();
1209        // Safety: drops once, never accessed again
1210        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1211    }
1212}
1213
1214impl fidl::endpoints::Responder for StackAddForwardingEntryResponder {
1215    type ControlHandle = StackControlHandle;
1216
1217    fn control_handle(&self) -> &StackControlHandle {
1218        &self.control_handle
1219    }
1220
1221    fn drop_without_shutdown(mut self) {
1222        // Safety: drops once, never accessed again due to mem::forget
1223        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1224        // Prevent Drop from running (which would shut down the channel)
1225        std::mem::forget(self);
1226    }
1227}
1228
1229impl StackAddForwardingEntryResponder {
1230    /// Sends a response to the FIDL transaction.
1231    ///
1232    /// Sets the channel to shutdown if an error occurs.
1233    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1234        let _result = self.send_raw(result);
1235        if _result.is_err() {
1236            self.control_handle.shutdown();
1237        }
1238        self.drop_without_shutdown();
1239        _result
1240    }
1241
1242    /// Similar to "send" but does not shutdown the channel if an error occurs.
1243    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1244        let _result = self.send_raw(result);
1245        self.drop_without_shutdown();
1246        _result
1247    }
1248
1249    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1250        self.control_handle
1251            .inner
1252            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
1253                result,
1254                self.tx_id,
1255                0x5fe2020877107909,
1256                fidl::encoding::DynamicFlags::empty(),
1257            )
1258    }
1259}
1260
1261#[must_use = "FIDL methods require a response to be sent"]
1262#[derive(Debug)]
1263pub struct StackDelForwardingEntryResponder {
1264    control_handle: std::mem::ManuallyDrop<StackControlHandle>,
1265    tx_id: u32,
1266}
1267
1268/// Set the the channel to be shutdown (see [`StackControlHandle::shutdown`])
1269/// if the responder is dropped without sending a response, so that the client
1270/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1271impl std::ops::Drop for StackDelForwardingEntryResponder {
1272    fn drop(&mut self) {
1273        self.control_handle.shutdown();
1274        // Safety: drops once, never accessed again
1275        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1276    }
1277}
1278
1279impl fidl::endpoints::Responder for StackDelForwardingEntryResponder {
1280    type ControlHandle = StackControlHandle;
1281
1282    fn control_handle(&self) -> &StackControlHandle {
1283        &self.control_handle
1284    }
1285
1286    fn drop_without_shutdown(mut self) {
1287        // Safety: drops once, never accessed again due to mem::forget
1288        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1289        // Prevent Drop from running (which would shut down the channel)
1290        std::mem::forget(self);
1291    }
1292}
1293
1294impl StackDelForwardingEntryResponder {
1295    /// Sends a response to the FIDL transaction.
1296    ///
1297    /// Sets the channel to shutdown if an error occurs.
1298    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1299        let _result = self.send_raw(result);
1300        if _result.is_err() {
1301            self.control_handle.shutdown();
1302        }
1303        self.drop_without_shutdown();
1304        _result
1305    }
1306
1307    /// Similar to "send" but does not shutdown the channel if an error occurs.
1308    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1309        let _result = self.send_raw(result);
1310        self.drop_without_shutdown();
1311        _result
1312    }
1313
1314    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1315        self.control_handle
1316            .inner
1317            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
1318                result,
1319                self.tx_id,
1320                0x560f3944c4cb51bd,
1321                fidl::encoding::DynamicFlags::empty(),
1322            )
1323    }
1324}
1325
1326#[must_use = "FIDL methods require a response to be sent"]
1327#[derive(Debug)]
1328pub struct StackSetDhcpClientEnabledResponder {
1329    control_handle: std::mem::ManuallyDrop<StackControlHandle>,
1330    tx_id: u32,
1331}
1332
1333/// Set the the channel to be shutdown (see [`StackControlHandle::shutdown`])
1334/// if the responder is dropped without sending a response, so that the client
1335/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1336impl std::ops::Drop for StackSetDhcpClientEnabledResponder {
1337    fn drop(&mut self) {
1338        self.control_handle.shutdown();
1339        // Safety: drops once, never accessed again
1340        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1341    }
1342}
1343
1344impl fidl::endpoints::Responder for StackSetDhcpClientEnabledResponder {
1345    type ControlHandle = StackControlHandle;
1346
1347    fn control_handle(&self) -> &StackControlHandle {
1348        &self.control_handle
1349    }
1350
1351    fn drop_without_shutdown(mut self) {
1352        // Safety: drops once, never accessed again due to mem::forget
1353        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1354        // Prevent Drop from running (which would shut down the channel)
1355        std::mem::forget(self);
1356    }
1357}
1358
1359impl StackSetDhcpClientEnabledResponder {
1360    /// Sends a response to the FIDL transaction.
1361    ///
1362    /// Sets the channel to shutdown if an error occurs.
1363    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1364        let _result = self.send_raw(result);
1365        if _result.is_err() {
1366            self.control_handle.shutdown();
1367        }
1368        self.drop_without_shutdown();
1369        _result
1370    }
1371
1372    /// Similar to "send" but does not shutdown the channel if an error occurs.
1373    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1374        let _result = self.send_raw(result);
1375        self.drop_without_shutdown();
1376        _result
1377    }
1378
1379    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1380        self.control_handle
1381            .inner
1382            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
1383                result,
1384                self.tx_id,
1385                0x6dead3a6025b0543,
1386                fidl::encoding::DynamicFlags::empty(),
1387            )
1388    }
1389}
1390
1391mod internal {
1392    use super::*;
1393
1394    impl fidl::encoding::ResourceTypeMarker for StackBridgeInterfacesRequest {
1395        type Borrowed<'a> = &'a mut Self;
1396        fn take_or_borrow<'a>(
1397            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1398        ) -> Self::Borrowed<'a> {
1399            value
1400        }
1401    }
1402
1403    unsafe impl fidl::encoding::TypeMarker for StackBridgeInterfacesRequest {
1404        type Owned = Self;
1405
1406        #[inline(always)]
1407        fn inline_align(_context: fidl::encoding::Context) -> usize {
1408            8
1409        }
1410
1411        #[inline(always)]
1412        fn inline_size(_context: fidl::encoding::Context) -> usize {
1413            24
1414        }
1415    }
1416
1417    unsafe impl
1418        fidl::encoding::Encode<
1419            StackBridgeInterfacesRequest,
1420            fidl::encoding::DefaultFuchsiaResourceDialect,
1421        > for &mut StackBridgeInterfacesRequest
1422    {
1423        #[inline]
1424        unsafe fn encode(
1425            self,
1426            encoder: &mut fidl::encoding::Encoder<
1427                '_,
1428                fidl::encoding::DefaultFuchsiaResourceDialect,
1429            >,
1430            offset: usize,
1431            _depth: fidl::encoding::Depth,
1432        ) -> fidl::Result<()> {
1433            encoder.debug_check_bounds::<StackBridgeInterfacesRequest>(offset);
1434            // Delegate to tuple encoding.
1435            fidl::encoding::Encode::<StackBridgeInterfacesRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1436                (
1437                    <fidl::encoding::UnboundedVector<u64> as fidl::encoding::ValueTypeMarker>::borrow(&self.interfaces),
1438                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.bridge),
1439                ),
1440                encoder, offset, _depth
1441            )
1442        }
1443    }
1444    unsafe impl<
1445        T0: fidl::encoding::Encode<
1446                fidl::encoding::UnboundedVector<u64>,
1447                fidl::encoding::DefaultFuchsiaResourceDialect,
1448            >,
1449        T1: fidl::encoding::Encode<
1450                fidl::encoding::Endpoint<
1451                    fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>,
1452                >,
1453                fidl::encoding::DefaultFuchsiaResourceDialect,
1454            >,
1455    >
1456        fidl::encoding::Encode<
1457            StackBridgeInterfacesRequest,
1458            fidl::encoding::DefaultFuchsiaResourceDialect,
1459        > for (T0, T1)
1460    {
1461        #[inline]
1462        unsafe fn encode(
1463            self,
1464            encoder: &mut fidl::encoding::Encoder<
1465                '_,
1466                fidl::encoding::DefaultFuchsiaResourceDialect,
1467            >,
1468            offset: usize,
1469            depth: fidl::encoding::Depth,
1470        ) -> fidl::Result<()> {
1471            encoder.debug_check_bounds::<StackBridgeInterfacesRequest>(offset);
1472            // Zero out padding regions. There's no need to apply masks
1473            // because the unmasked parts will be overwritten by fields.
1474            unsafe {
1475                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1476                (ptr as *mut u64).write_unaligned(0);
1477            }
1478            // Write the fields.
1479            self.0.encode(encoder, offset + 0, depth)?;
1480            self.1.encode(encoder, offset + 16, depth)?;
1481            Ok(())
1482        }
1483    }
1484
1485    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1486        for StackBridgeInterfacesRequest
1487    {
1488        #[inline(always)]
1489        fn new_empty() -> Self {
1490            Self {
1491                interfaces: fidl::new_empty!(
1492                    fidl::encoding::UnboundedVector<u64>,
1493                    fidl::encoding::DefaultFuchsiaResourceDialect
1494                ),
1495                bridge: fidl::new_empty!(
1496                    fidl::encoding::Endpoint<
1497                        fidl::endpoints::ServerEnd<
1498                            fidl_fuchsia_net_interfaces_admin::ControlMarker,
1499                        >,
1500                    >,
1501                    fidl::encoding::DefaultFuchsiaResourceDialect
1502                ),
1503            }
1504        }
1505
1506        #[inline]
1507        unsafe fn decode(
1508            &mut self,
1509            decoder: &mut fidl::encoding::Decoder<
1510                '_,
1511                fidl::encoding::DefaultFuchsiaResourceDialect,
1512            >,
1513            offset: usize,
1514            _depth: fidl::encoding::Depth,
1515        ) -> fidl::Result<()> {
1516            decoder.debug_check_bounds::<Self>(offset);
1517            // Verify that padding bytes are zero.
1518            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1519            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1520            let mask = 0xffffffff00000000u64;
1521            let maskedval = padval & mask;
1522            if maskedval != 0 {
1523                return Err(fidl::Error::NonZeroPadding {
1524                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1525                });
1526            }
1527            fidl::decode!(
1528                fidl::encoding::UnboundedVector<u64>,
1529                fidl::encoding::DefaultFuchsiaResourceDialect,
1530                &mut self.interfaces,
1531                decoder,
1532                offset + 0,
1533                _depth
1534            )?;
1535            fidl::decode!(
1536                fidl::encoding::Endpoint<
1537                    fidl::endpoints::ServerEnd<fidl_fuchsia_net_interfaces_admin::ControlMarker>,
1538                >,
1539                fidl::encoding::DefaultFuchsiaResourceDialect,
1540                &mut self.bridge,
1541                decoder,
1542                offset + 16,
1543                _depth
1544            )?;
1545            Ok(())
1546        }
1547    }
1548
1549    impl fidl::encoding::ResourceTypeMarker for StackSetDhcpClientEnabledRequest {
1550        type Borrowed<'a> = &'a mut Self;
1551        fn take_or_borrow<'a>(
1552            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1553        ) -> Self::Borrowed<'a> {
1554            value
1555        }
1556    }
1557
1558    unsafe impl fidl::encoding::TypeMarker for StackSetDhcpClientEnabledRequest {
1559        type Owned = Self;
1560
1561        #[inline(always)]
1562        fn inline_align(_context: fidl::encoding::Context) -> usize {
1563            8
1564        }
1565
1566        #[inline(always)]
1567        fn inline_size(_context: fidl::encoding::Context) -> usize {
1568            16
1569        }
1570    }
1571
1572    unsafe impl
1573        fidl::encoding::Encode<
1574            StackSetDhcpClientEnabledRequest,
1575            fidl::encoding::DefaultFuchsiaResourceDialect,
1576        > for &mut StackSetDhcpClientEnabledRequest
1577    {
1578        #[inline]
1579        unsafe fn encode(
1580            self,
1581            encoder: &mut fidl::encoding::Encoder<
1582                '_,
1583                fidl::encoding::DefaultFuchsiaResourceDialect,
1584            >,
1585            offset: usize,
1586            _depth: fidl::encoding::Depth,
1587        ) -> fidl::Result<()> {
1588            encoder.debug_check_bounds::<StackSetDhcpClientEnabledRequest>(offset);
1589            // Delegate to tuple encoding.
1590            fidl::encoding::Encode::<
1591                StackSetDhcpClientEnabledRequest,
1592                fidl::encoding::DefaultFuchsiaResourceDialect,
1593            >::encode(
1594                (
1595                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.id),
1596                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.enable),
1597                ),
1598                encoder,
1599                offset,
1600                _depth,
1601            )
1602        }
1603    }
1604    unsafe impl<
1605        T0: fidl::encoding::Encode<u64, fidl::encoding::DefaultFuchsiaResourceDialect>,
1606        T1: fidl::encoding::Encode<bool, fidl::encoding::DefaultFuchsiaResourceDialect>,
1607    >
1608        fidl::encoding::Encode<
1609            StackSetDhcpClientEnabledRequest,
1610            fidl::encoding::DefaultFuchsiaResourceDialect,
1611        > for (T0, T1)
1612    {
1613        #[inline]
1614        unsafe fn encode(
1615            self,
1616            encoder: &mut fidl::encoding::Encoder<
1617                '_,
1618                fidl::encoding::DefaultFuchsiaResourceDialect,
1619            >,
1620            offset: usize,
1621            depth: fidl::encoding::Depth,
1622        ) -> fidl::Result<()> {
1623            encoder.debug_check_bounds::<StackSetDhcpClientEnabledRequest>(offset);
1624            // Zero out padding regions. There's no need to apply masks
1625            // because the unmasked parts will be overwritten by fields.
1626            unsafe {
1627                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(8);
1628                (ptr as *mut u64).write_unaligned(0);
1629            }
1630            // Write the fields.
1631            self.0.encode(encoder, offset + 0, depth)?;
1632            self.1.encode(encoder, offset + 8, depth)?;
1633            Ok(())
1634        }
1635    }
1636
1637    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1638        for StackSetDhcpClientEnabledRequest
1639    {
1640        #[inline(always)]
1641        fn new_empty() -> Self {
1642            Self {
1643                id: fidl::new_empty!(u64, fidl::encoding::DefaultFuchsiaResourceDialect),
1644                enable: fidl::new_empty!(bool, fidl::encoding::DefaultFuchsiaResourceDialect),
1645            }
1646        }
1647
1648        #[inline]
1649        unsafe fn decode(
1650            &mut self,
1651            decoder: &mut fidl::encoding::Decoder<
1652                '_,
1653                fidl::encoding::DefaultFuchsiaResourceDialect,
1654            >,
1655            offset: usize,
1656            _depth: fidl::encoding::Depth,
1657        ) -> fidl::Result<()> {
1658            decoder.debug_check_bounds::<Self>(offset);
1659            // Verify that padding bytes are zero.
1660            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(8) };
1661            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1662            let mask = 0xffffffffffffff00u64;
1663            let maskedval = padval & mask;
1664            if maskedval != 0 {
1665                return Err(fidl::Error::NonZeroPadding {
1666                    padding_start: offset + 8 + ((mask as u64).trailing_zeros() / 8) as usize,
1667                });
1668            }
1669            fidl::decode!(
1670                u64,
1671                fidl::encoding::DefaultFuchsiaResourceDialect,
1672                &mut self.id,
1673                decoder,
1674                offset + 0,
1675                _depth
1676            )?;
1677            fidl::decode!(
1678                bool,
1679                fidl::encoding::DefaultFuchsiaResourceDialect,
1680                &mut self.enable,
1681                decoder,
1682                offset + 8,
1683                _depth
1684            )?;
1685            Ok(())
1686        }
1687    }
1688}