Enum netstack3_core::udp::UdpRemotePort
source · pub enum UdpRemotePort {
Set(NonZero<u16>),
Unset,
}
Expand description
The remote port for a UDP socket.
Variants§
Set(NonZero<u16>)
The remote port is set to the following value.
Unset
The remote port is unset (i.e. “0”) value. An unset remote port is treated specially in a few places:
-
Attempting to send to an unset remote port results in a [
UdpSerializeError::RemotePortUnset
] error. Note that this behavior diverges from Linux, which does allow sending to a remote_port of 0 (supported bysend
but notsend_to
). The rationale for this divergence originates from RFC 8085 Section 5.1:A UDP sender SHOULD NOT use a source port value of zero. A source port number that cannot be easily determined from the address or payload type provides protection at the receiver from data injection attacks by off-path devices. A UDP receiver SHOULD NOT bind to port zero.
Applications SHOULD implement receiver port and address checks at the application layer or explicitly request that the operating system filter the received packets to prevent receiving packets with an arbitrary port. This measure is designed to provide additional protection from data injection attacks from an off-path source (where the port values may not be known).
Combined, these two stanzas recommend hosts discard incoming traffic destined to remote port 0 for security reasons. Thus we choose to not allow hosts to send such packets under the assumption that it will be dropped by the receiving end.
- A socket connected to a remote host on port 0 will not receive any
packets from the remote host. This is because the
[
BoundSocketMap::lookup
] implementation only delivers packets that specify a remote port to connected sockets with an exact match. Further, packets that don’t specify a remote port are only delivered to listener sockets. This diverges from Linux (which treats a remote_port of 0) as wild card. If and when a concrete need for such behavior is identified, the [BoundSocketMap
] lookup behavior can be adjusted accordingly.
Trait Implementations§
source§impl Clone for UdpRemotePort
impl Clone for UdpRemotePort
source§fn clone(&self) -> UdpRemotePort
fn clone(&self) -> UdpRemotePort
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for UdpRemotePort
impl Debug for UdpRemotePort
source§impl From<u16> for UdpRemotePort
impl From<u16> for UdpRemotePort
source§fn from(p: u16) -> UdpRemotePort
fn from(p: u16) -> UdpRemotePort
source§impl Hash for UdpRemotePort
impl Hash for UdpRemotePort
source§impl PartialEq for UdpRemotePort
impl PartialEq for UdpRemotePort
source§fn eq(&self, other: &UdpRemotePort) -> bool
fn eq(&self, other: &UdpRemotePort) -> bool
self
and other
values to be equal, and is used
by ==
.impl Copy for UdpRemotePort
impl Eq for UdpRemotePort
impl StructuralPartialEq for UdpRemotePort
Auto Trait Implementations§
impl Freeze for UdpRemotePort
impl RefUnwindSafe for UdpRemotePort
impl Send for UdpRemotePort
impl Sync for UdpRemotePort
impl Unpin for UdpRemotePort
impl UnwindSafe for UdpRemotePort
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)