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
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)