| // Copyright 2020 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| use fidl_fuchsia_net_dhcp as fnet_dhcp; |
| use fuchsia_zircon as zx; |
| |
| use anyhow::Context as _; |
| |
| use crate::errors; |
| |
| /// Start the DHCP server. |
| pub(super) async fn start_server( |
| dhcp_server: &fnet_dhcp::Server_Proxy, |
| ) -> Result<(), errors::Error> { |
| dhcp_server |
| .start_serving() |
| .await |
| .context("error sending start DHCP server request") |
| .map_err(errors::Error::NonFatal)? |
| .map_err(zx::Status::from_raw) |
| .context("error starting DHCP server") |
| .map_err(errors::Error::NonFatal) |
| } |
| |
| /// Stop the DHCP server. |
| pub(super) async fn stop_server( |
| dhcp_server: &fnet_dhcp::Server_Proxy, |
| ) -> Result<(), errors::Error> { |
| dhcp_server |
| .stop_serving() |
| .await |
| .context("error sending stop DHCP server request") |
| .map_err(errors::Error::NonFatal) |
| } |