pub trait IpSocketHandler<I: IpExt, BC>: DeviceIdContext<AnyDevice> {
// Required methods
fn new_ip_socket<O>(
&mut self,
bindings_ctx: &mut BC,
device: Option<EitherDeviceId<&Self::DeviceId, &Self::WeakDeviceId>>,
local_ip: Option<IpDeviceAddr<I::Addr>>,
remote_ip: SocketIpAddr<I::Addr>,
proto: I::Proto,
options: &O,
) -> Result<IpSock<I, Self::WeakDeviceId>, IpSockCreationError>
where O: RouteResolutionOptions<I>;
fn send_ip_packet<S, O>(
&mut self,
bindings_ctx: &mut BC,
socket: &IpSock<I, Self::WeakDeviceId>,
body: S,
options: &O,
) -> Result<(), IpSockSendError>
where S: TransportPacketSerializer<I>,
S::Buffer: BufferMut,
O: SendOptions<I> + RouteResolutionOptions<I>;
fn confirm_reachable<O>(
&mut self,
bindings_ctx: &mut BC,
socket: &IpSock<I, Self::WeakDeviceId>,
options: &O,
)
where O: RouteResolutionOptions<I>;
// Provided methods
fn send_oneshot_ip_packet_with_fallible_serializer<S, E, F, O>(
&mut self,
bindings_ctx: &mut BC,
device: Option<EitherDeviceId<&Self::DeviceId, &Self::WeakDeviceId>>,
local_ip: Option<IpDeviceAddr<I::Addr>>,
remote_ip: RoutableIpAddr<I::Addr>,
proto: I::Proto,
options: &O,
get_body_from_src_ip: F,
) -> Result<(), SendOneShotIpPacketError<E>>
where S: TransportPacketSerializer<I>,
S::Buffer: BufferMut,
F: FnOnce(IpDeviceAddr<I::Addr>) -> Result<S, E>,
O: SendOptions<I> + RouteResolutionOptions<I> { ... }
fn send_oneshot_ip_packet<S, F, O>(
&mut self,
bindings_ctx: &mut BC,
device: Option<EitherDeviceId<&Self::DeviceId, &Self::WeakDeviceId>>,
local_ip: Option<IpDeviceAddr<I::Addr>>,
remote_ip: SocketIpAddr<I::Addr>,
proto: I::Proto,
options: &O,
get_body_from_src_ip: F,
) -> Result<(), IpSockCreateAndSendError>
where S: TransportPacketSerializer<I>,
S::Buffer: BufferMut,
F: FnOnce(IpDeviceAddr<I::Addr>) -> S,
O: SendOptions<I> + RouteResolutionOptions<I> { ... }
}
Expand description
An execution context defining a type of IP socket.
Required Methods§
Sourcefn new_ip_socket<O>(
&mut self,
bindings_ctx: &mut BC,
device: Option<EitherDeviceId<&Self::DeviceId, &Self::WeakDeviceId>>,
local_ip: Option<IpDeviceAddr<I::Addr>>,
remote_ip: SocketIpAddr<I::Addr>,
proto: I::Proto,
options: &O,
) -> Result<IpSock<I, Self::WeakDeviceId>, IpSockCreationError>where
O: RouteResolutionOptions<I>,
fn new_ip_socket<O>(
&mut self,
bindings_ctx: &mut BC,
device: Option<EitherDeviceId<&Self::DeviceId, &Self::WeakDeviceId>>,
local_ip: Option<IpDeviceAddr<I::Addr>>,
remote_ip: SocketIpAddr<I::Addr>,
proto: I::Proto,
options: &O,
) -> Result<IpSock<I, Self::WeakDeviceId>, IpSockCreationError>where
O: RouteResolutionOptions<I>,
Constructs a new IpSock
.
new_ip_socket
constructs a new IpSock
to the given remote IP
address from the given local IP address with the given IP protocol. If
no local IP address is given, one will be chosen automatically. If
device
is Some
, the socket will be bound to the given device - only
routes which egress over the device will be used. If no route is
available which egresses over the device - even if routes are available
which egress over other devices - the socket will be considered
unroutable.
new_ip_socket
returns an error if no route to the remote was found in
the forwarding table or if the given local IP address is not valid for
the found route.
Sourcefn send_ip_packet<S, O>(
&mut self,
bindings_ctx: &mut BC,
socket: &IpSock<I, Self::WeakDeviceId>,
body: S,
options: &O,
) -> Result<(), IpSockSendError>where
S: TransportPacketSerializer<I>,
S::Buffer: BufferMut,
O: SendOptions<I> + RouteResolutionOptions<I>,
fn send_ip_packet<S, O>(
&mut self,
bindings_ctx: &mut BC,
socket: &IpSock<I, Self::WeakDeviceId>,
body: S,
options: &O,
) -> Result<(), IpSockSendError>where
S: TransportPacketSerializer<I>,
S::Buffer: BufferMut,
O: SendOptions<I> + RouteResolutionOptions<I>,
Sends an IP packet on a socket.
The generated packet has its metadata initialized from socket
,
including the source and destination addresses, the Time To Live/Hop
Limit, and the Protocol/Next Header. The outbound device is also chosen
based on information stored in the socket.
mtu
may be used to optionally impose an MTU on the outgoing packet.
Note that the device’s MTU will still be imposed on the packet. That is,
the smaller of mtu
and the device’s MTU will be imposed on the packet.
If the socket is currently unroutable, an error is returned.
Sourcefn confirm_reachable<O>(
&mut self,
bindings_ctx: &mut BC,
socket: &IpSock<I, Self::WeakDeviceId>,
options: &O,
)where
O: RouteResolutionOptions<I>,
fn confirm_reachable<O>(
&mut self,
bindings_ctx: &mut BC,
socket: &IpSock<I, Self::WeakDeviceId>,
options: &O,
)where
O: RouteResolutionOptions<I>,
Confirms the provided IP socket destination is reachable.
Implementations must retrieve the next hop given the provided IP socket and confirm neighbor reachability for the resolved target device.
Provided Methods§
Sourcefn send_oneshot_ip_packet_with_fallible_serializer<S, E, F, O>(
&mut self,
bindings_ctx: &mut BC,
device: Option<EitherDeviceId<&Self::DeviceId, &Self::WeakDeviceId>>,
local_ip: Option<IpDeviceAddr<I::Addr>>,
remote_ip: RoutableIpAddr<I::Addr>,
proto: I::Proto,
options: &O,
get_body_from_src_ip: F,
) -> Result<(), SendOneShotIpPacketError<E>>where
S: TransportPacketSerializer<I>,
S::Buffer: BufferMut,
F: FnOnce(IpDeviceAddr<I::Addr>) -> Result<S, E>,
O: SendOptions<I> + RouteResolutionOptions<I>,
fn send_oneshot_ip_packet_with_fallible_serializer<S, E, F, O>(
&mut self,
bindings_ctx: &mut BC,
device: Option<EitherDeviceId<&Self::DeviceId, &Self::WeakDeviceId>>,
local_ip: Option<IpDeviceAddr<I::Addr>>,
remote_ip: RoutableIpAddr<I::Addr>,
proto: I::Proto,
options: &O,
get_body_from_src_ip: F,
) -> Result<(), SendOneShotIpPacketError<E>>where
S: TransportPacketSerializer<I>,
S::Buffer: BufferMut,
F: FnOnce(IpDeviceAddr<I::Addr>) -> Result<S, E>,
O: SendOptions<I> + RouteResolutionOptions<I>,
Creates a temporary IP socket and sends a single packet on it.
local_ip
, remote_ip
, proto
, and options
are passed directly to
IpSocketHandler::new_ip_socket
. get_body_from_src_ip
is given the
source IP address for the packet - which may have been chosen
automatically if local_ip
is None
- and returns the body to be
encapsulated. This is provided in case the body’s contents depend on the
chosen source IP address.
If device
is specified, the available routes are limited to those that
egress over the device.
mtu
may be used to optionally impose an MTU on the outgoing packet.
Note that the device’s MTU will still be imposed on the packet. That is,
the smaller of mtu
and the device’s MTU will be imposed on the packet.
§Errors
If an error is encountered while constructing the temporary IP socket
or sending the packet, options
will be returned along with the
error. get_body_from_src_ip
is fallible, and if there’s an error,
it will be returned as well.
Sourcefn send_oneshot_ip_packet<S, F, O>(
&mut self,
bindings_ctx: &mut BC,
device: Option<EitherDeviceId<&Self::DeviceId, &Self::WeakDeviceId>>,
local_ip: Option<IpDeviceAddr<I::Addr>>,
remote_ip: SocketIpAddr<I::Addr>,
proto: I::Proto,
options: &O,
get_body_from_src_ip: F,
) -> Result<(), IpSockCreateAndSendError>where
S: TransportPacketSerializer<I>,
S::Buffer: BufferMut,
F: FnOnce(IpDeviceAddr<I::Addr>) -> S,
O: SendOptions<I> + RouteResolutionOptions<I>,
fn send_oneshot_ip_packet<S, F, O>(
&mut self,
bindings_ctx: &mut BC,
device: Option<EitherDeviceId<&Self::DeviceId, &Self::WeakDeviceId>>,
local_ip: Option<IpDeviceAddr<I::Addr>>,
remote_ip: SocketIpAddr<I::Addr>,
proto: I::Proto,
options: &O,
get_body_from_src_ip: F,
) -> Result<(), IpSockCreateAndSendError>where
S: TransportPacketSerializer<I>,
S::Buffer: BufferMut,
F: FnOnce(IpDeviceAddr<I::Addr>) -> S,
O: SendOptions<I> + RouteResolutionOptions<I>,
Sends a one-shot IP packet but with a non-fallible serializer.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.