netstack3_udp

Struct UdpApi

Source
pub struct UdpApi<I: Ip, C>(/* private fields */);
Expand description

The UDP socket API.

Implementations§

Source§

impl<I: Ip, C> UdpApi<I, C>

Source

pub fn new(ctx: C) -> Self

Creates a new UdpApi from ctx.

Source§

impl<I, C> UdpApi<I, C>

Source

pub fn create( &mut self, ) -> UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>

Creates a new unbound UDP socket with default external data.

Source

pub fn create_with( &mut self, external_data: <C::BindingsContext as UdpBindingsTypes>::ExternalData<I>, ) -> UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>

Creates a new unbound UDP socket with provided external data.

Source

pub fn connect( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, remote_ip: Option<ZonedAddr<SpecifiedAddr<I::Addr>, <C::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>>, remote_port: UdpRemotePort, ) -> Result<(), ConnectError>

Connect a UDP socket

connect binds id as a connection to the remote address and port. It is also bound to a local address and port, meaning that packets sent on this connection will always come from that address and port. The local address will be chosen based on the route to the remote address, and the local port will be chosen from the available ones.

§Errors

connect will fail in the following cases:

  • If both local_ip and local_port are specified but conflict with an existing connection or listener
  • If one or both are left unspecified but there is still no way to satisfy the request (e.g., local_ip is specified but there are no available local ports for that address)
  • If there is no route to remote_ip
  • If id belongs to an already-connected socket
Source

pub fn set_device( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, device_id: Option<&<C::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>, ) -> Result<(), SocketError>

Sets the bound device for a socket.

Sets the device to be used for sending and receiving packets for a socket. If the socket is not currently bound to a local address and port, the device will be used when binding.

Source

pub fn get_bound_device( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> Option<<C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>

Gets the device the specified socket is bound to.

Source

pub fn set_dual_stack_enabled( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, enabled: bool, ) -> Result<(), SetDualStackEnabledError>

Enable or disable dual stack operations on the given socket.

This is notionally the inverse of the IPV6_V6ONLY socket option.

§Errors

Returns an error if the socket does not support the IPV6_V6ONLY socket option (e.g. an IPv4 socket).

Source

pub fn get_dual_stack_enabled( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> Result<bool, NotDualStackCapableError>

Get the enabled state of dual stack operations on the given socket.

This is notionally the inverse of the IPV6_V6ONLY socket option.

§Errors

Returns an error if the socket does not support the IPV6_V6ONLY socket option (e.g. an IPv4 socket).

Source

pub fn set_posix_reuse_addr( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, reuse_addr: bool, ) -> Result<(), ExpectedUnboundError>

Sets the POSIX SO_REUSEADDR option for the specified socket.

§Errors

Returns an error if the socket is already bound.

Source

pub fn get_posix_reuse_addr( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> bool

Gets the POSIX SO_REUSEADDR option for the specified socket.

Source

pub fn set_posix_reuse_port( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, reuse_port: bool, ) -> Result<(), ExpectedUnboundError>

Sets the POSIX SO_REUSEPORT option for the specified socket.

§Errors

Returns an error if the socket is already bound.

Source

pub fn get_posix_reuse_port( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> bool

Gets the POSIX SO_REUSEPORT option for the specified socket.

Source

pub fn set_multicast_membership( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, multicast_group: MulticastAddr<I::Addr>, interface: MulticastMembershipInterfaceSelector<I::Addr, <C::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>, want_membership: bool, ) -> Result<(), SetMulticastMembershipError>

Sets the specified socket’s membership status for the given group.

An error is returned if the membership change request is invalid (e.g. leaving a group that was not joined, or joining a group multiple times) or if the device to use to join is unspecified or conflicts with the existing socket state.

Source

pub fn set_unicast_hop_limit( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, unicast_hop_limit: Option<NonZeroU8>, ip_version: IpVersion, ) -> Result<(), NotDualStackCapableError>

Sets the hop limit for packets sent by the socket to a unicast destination.

Sets the IPv4 TTL when ip_version is IpVersion::V4, and the IPv6 hop limits when ip_version is IpVersion::V6.

Returns NotDualStackCapableError if called on an IPv4 Socket with an ip_version of IpVersion::V6.

Source

pub fn set_multicast_hop_limit( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, multicast_hop_limit: Option<NonZeroU8>, ip_version: IpVersion, ) -> Result<(), NotDualStackCapableError>

Sets the hop limit for packets sent by the socket to a multicast destination.

Sets the IPv4 TTL when ip_version is IpVersion::V4, and the IPv6 hop limits when ip_version is IpVersion::V6.

Returns NotDualStackCapableError if called on an IPv4 Socket with an ip_version of IpVersion::V6.

Source

pub fn get_unicast_hop_limit( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ip_version: IpVersion, ) -> Result<NonZeroU8, NotDualStackCapableError>

Gets the hop limit for packets sent by the socket to a unicast destination.

Gets the IPv4 TTL when ip_version is IpVersion::V4, and the IPv6 hop limits when ip_version is IpVersion::V6.

Returns NotDualStackCapableError if called on an IPv4 Socket with an ip_version of IpVersion::V6.

Source

pub fn get_multicast_hop_limit( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ip_version: IpVersion, ) -> Result<NonZeroU8, NotDualStackCapableError>

Gets the hop limit for packets sent by the socket to a multicast destination.

Gets the IPv4 TTL when ip_version is IpVersion::V4, and the IPv6 hop limits when ip_version is IpVersion::V6.

Returns NotDualStackCapableError if called on an IPv4 Socket with an ip_version of IpVersion::V6.

Source

pub fn get_multicast_interface( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ip_version: IpVersion, ) -> Result<Option<<C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>, NotDualStackCapableError>

Returns the configured multicast interface for the socket.

Source

pub fn set_multicast_interface( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, interface: Option<&<C::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>, ip_version: IpVersion, ) -> Result<(), NotDualStackCapableError>

Sets the multicast interface to interface for a socket.

Source

pub fn get_transparent( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> bool

Gets the transparent option.

Source

pub fn set_transparent( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, value: bool, )

Sets the transparent option.

Source

pub fn get_mark( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, domain: MarkDomain, ) -> Mark

Gets the socket mark at the mark domain.

Source

pub fn set_mark( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, domain: MarkDomain, mark: Mark, )

Sets the socket mark at the mark domain.

Source

pub fn get_broadcast( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> bool

Gets the broadcast option.

Source

pub fn set_broadcast( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, value: bool, )

Sets the broadcast option.

Source

pub fn get_multicast_loop( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ip_version: IpVersion, ) -> Result<bool, NotDualStackCapableError>

Gets the loopback multicast option.

Source

pub fn set_multicast_loop( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, value: bool, ip_version: IpVersion, ) -> Result<(), NotDualStackCapableError>

Sets the loopback multicast option.

Source

pub fn get_dscp_and_ecn( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ip_version: IpVersion, ) -> Result<DscpAndEcn, NotDualStackCapableError>

Gets the TCLASS/TOS option.

Source

pub fn set_dscp_and_ecn( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, value: DscpAndEcn, ip_version: IpVersion, ) -> Result<(), NotDualStackCapableError>

Sets the TCLASS/TOS option.

Source

pub fn disconnect( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> Result<(), ExpectedConnError>

Disconnects a connected UDP socket.

disconnect removes an existing connected socket and replaces it with a listening socket bound to the same local address and port.

§Errors

Returns an error if the socket is not connected.

Source

pub fn shutdown( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, which: ShutdownType, ) -> Result<(), ExpectedConnError>

Shuts down a socket for reading and/or writing.

§Errors

Returns an error if the socket is not connected.

Source

pub fn get_shutdown( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> Option<ShutdownType>

Get the shutdown state for a socket.

If the socket is not connected, or if shutdown was not called on it, returns None.

Source

pub fn close( &mut self, id: UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> RemoveResourceResultWithContext<<C::BindingsContext as UdpBindingsTypes>::ExternalData<I>, C::BindingsContext>

Removes a socket that was previously created.

Source

pub fn get_info( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, ) -> SocketInfo<I::Addr, <C::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId>

Gets the SocketInfo associated with the UDP socket referenced by id.

Source

pub fn listen( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, addr: Option<ZonedAddr<SpecifiedAddr<I::Addr>, <C::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>>, port: Option<NonZeroU16>, ) -> Result<(), Either<ExpectedUnboundError, LocalAddressError>>

Use an existing socket to listen for incoming UDP packets.

listen_udp converts id into a listening socket and registers the new socket as a listener for incoming UDP packets on the given port. If addr is None, the listener is a “wildcard listener”, and is bound to all local addresses. See the [crate::transport] module documentation for more details.

If addr is Some``, and addris already bound on the given port (either by a listener or a connection),listen_udpwill fail. IfaddrisNone, and a wildcard listener is already bound to the given port, listen_udp` will fail.

§Errors

Returns an error if the socket is not currently unbound.

Source

pub fn send<B: BufferMut>( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, body: B, ) -> Result<(), Either<SendError, ExpectedConnError>>

Sends a UDP packet on an existing socket.

§Errors

Returns an error if the socket is not connected or the packet cannot be sent. On error, the original body is returned unmodified so that it can be reused by the caller.

Source

pub fn send_to<B: BufferMut>( &mut self, id: &UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>, remote_ip: Option<ZonedAddr<SpecifiedAddr<I::Addr>, <C::CoreContext as DeviceIdContext<AnyDevice>>::DeviceId>>, remote_port: UdpRemotePort, body: B, ) -> Result<(), Either<LocalAddressError, SendToError>>

Sends a UDP packet to the provided destination address.

If this is called with an unbound socket, the socket will be implicitly bound. If that succeeds, the ID for the new socket is returned.

§Errors

Returns an error if the socket is unbound and connecting fails, or if the packet could not be sent. If the socket is unbound and connecting succeeds but sending fails, the socket remains connected.

Source

pub fn collect_all_sockets( &mut self, ) -> Vec<UdpSocketId<I, <<C as ContextPair>::CoreContext as DeviceIdContext<AnyDevice>>::WeakDeviceId, <C as ContextPair>::BindingsContext>>

Collects all currently opened sockets, returning a cloned reference for each one.

Source

pub fn inspect<N>(&mut self, inspector: &mut N)

Provides inspect data for UDP sockets.

Auto Trait Implementations§

§

impl<I, C> Freeze for UdpApi<I, C>
where C: Freeze,

§

impl<I, C> RefUnwindSafe for UdpApi<I, C>

§

impl<I, C> Send for UdpApi<I, C>
where C: Send,

§

impl<I, C> Sync for UdpApi<I, C>
where C: Sync,

§

impl<I, C> Unpin for UdpApi<I, C>
where C: Unpin, I: Unpin,

§

impl<I, C> UnwindSafe for UdpApi<I, C>
where C: UnwindSafe, I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<CC, BC, Meta> RecvFrameContext<Meta, BC> for CC
where Meta: ReceivableFrameMeta<CC, BC>,

Source§

fn receive_frame<B>(&mut self, bindings_ctx: &mut BC, metadata: Meta, frame: B)
where B: BufferMut + Debug,

Receive a frame. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<CC, BC, Meta> SendFrameContext<BC, Meta> for CC
where Meta: SendableFrameMeta<CC, BC>,

Source§

fn send_frame<S>( &mut self, bindings_ctx: &mut BC, metadata: Meta, frame: S, ) -> Result<(), ErrorAndSerializer<SendFrameErrorReason, S>>
where S: Serializer, <S as Serializer>::Buffer: BufferMut,

Send a frame. Read more
Source§

impl<Id, CC, BC> TimerHandler<BC, Id> for CC
where BC: TimerBindingsTypes, Id: HandleableTimer<CC, BC>,

Source§

fn handle_timer( &mut self, bindings_ctx: &mut BC, dispatch: Id, timer: <BC as TimerBindingsTypes>::UniqueTimerId, )

Handle a timer firing. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<L, T> UnlockedAccess<L> for T

Source§

type Data = <L as UnlockedAccessMarkerFor<T>>::Data

The type of state being accessed.
Source§

type Guard<'l> = &'l <L as UnlockedAccessMarkerFor<T>>::Data where T: 'l

A guard providing read access to the data.
Source§

fn access(&self) -> <T as UnlockedAccess<L>>::Guard<'_>

How to access the state.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<B, A> LockBefore<B> for A
where B: LockAfter<A>,