blob: 037059b19201f2580ae8b2b6f940f49307c0d663 [file] [log] [blame] [edit]
// Copyright 2023 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.
/// Library containing methods to enable address masquerading for a given subnet
/// and egress interface.
@available(added=HEAD)
library fuchsia.net.masquerade;
using fuchsia.net;
/// All possible error types that may be returned by calls to `Control` or `Factory`.
type Error = enum {
/// An unsupported configuration was provided. For example, the provided
/// `src_subnet` was unspecified (`0/0`).
UNSUPPORTED = 0;
/// One or more of the configuration fields was invalid (e.g. `src_if` is 0).
INVALID_ARGUMENTS = 1;
/// The provided `src_if` was not found.
NOT_FOUND = 2;
/// The provided `src_subnet`/`output_interface` pair already exist in the Nat
/// rules.
ALREADY_EXISTS = 3;
/// The call to `fuchsia.net.filter.deprecated.Filter::UpdateNatRules`
/// returned `BadRule`.
BAD_RULE = 4;
/// The attempt to update the Nat rules failed with `GenerationMismatch` too
/// many times.
RETRY_EXCEEDED = 5;
};
/// Control provides a IP masquerade instance.
///
/// This protocol is associated with the lifetime of the IP masquerade. This
/// configuration will be torn down whenever either end of the protocol is
/// closed.
closed protocol Control {
/// SetEnabled enables or disabled IP masquerading for the configured
/// instance. Newly created instances are disabled and must be enabled
/// via this API.
///
/// + request `enabled` True to enable masquerade; false to disable.
/// - response `was_enabled` True if the interface was enabled before this call.
strict SetEnabled(struct {
enabled bool;
}) -> (struct {
was_enabled bool;
}) error Error;
};
/// Factory instantiates Control protocol instances for IP masquerading.
///
/// This protocol is used to create instances allowing for the control of
/// IP masquerade of a particular network.
@discoverable
closed protocol Factory {
/// Create a new IP masquerade instance using the supplied
/// configuration.
///
/// Configurations cannot be changed once instantiated. If a different
/// configuration is to be applied, the prior instance should first be
/// disabled and the channel torn down.
///
/// The instance that is returned is initially in a disabled state and
/// must be explicitly enabled prior to use.
///
/// + request `config` Configuration to use for the IP masquerade
/// instance.
/// + request `control` Control handle to use for configuring the
/// instance.
strict Create(resource struct {
config @generated_name("ControlConfig") struct {
/// The network to be masqueraded.
src_subnet fuchsia.net.Subnet;
/// The interface through which to masquerade.
output_interface fuchsia.net.InterfaceId;
};
control server_end:Control;
}) -> () error Error;
};