pub struct UdpLayer {
port_map: RwLock<BTreeMap<u16, Weak<UdpSocket>>>,
next_ephemeral_port: Mutex<u16>,
stats: RwLock<NetworkLayerStats>,
self_weak: Weak<UdpLayer>,
}Expand description
UDP layer
Manages UDP port bindings and handles UDP datagrams.
Fields§
§port_map: RwLock<BTreeMap<u16, Weak<UdpSocket>>>Port-to-socket mapping for receiving datagrams
next_ephemeral_port: Mutex<u16>Port allocation (ephemeral ports start from 49152)
stats: RwLock<NetworkLayerStats>Statistics
self_weak: Weak<UdpLayer>Implementations§
Source§impl UdpLayer
impl UdpLayer
Sourcepub fn init(network_manager: &NetworkManager)
pub fn init(network_manager: &NetworkManager)
Initialize and register the UDP layer with NetworkManager
Registers with NetworkManager and registers itself with Ipv4Layer for protocol number 17 (UDP).
§Panics
Panics if Ipv4Layer is not registered (must be initialized first).
Sourcepub fn create_socket(&self) -> Arc<UdpSocket>
pub fn create_socket(&self) -> Arc<UdpSocket>
Create a new UDP socket
Sourcepub fn allocate_port(&self) -> u16
pub fn allocate_port(&self) -> u16
Allocate an ephemeral port
Sourcepub fn register_port(&self, port: u16, socket: Weak<UdpSocket>)
pub fn register_port(&self, port: u16, socket: Weak<UdpSocket>)
Register a socket for a specific port
Sourcepub fn unregister_socket(&self, port: u16, socket: &Weak<UdpSocket>)
pub fn unregister_socket(&self, port: u16, socket: &Weak<UdpSocket>)
Unregister a specific socket from a port
Only removes the port entry if the registered socket matches.
Sourcepub fn find_socket(&self, port: u16) -> Option<Arc<UdpSocket>>
pub fn find_socket(&self, port: u16) -> Option<Arc<UdpSocket>>
Find socket for a destination port
Sourcepub fn configure_socket(
&self,
socket: Weak<UdpSocket>,
config: &SocketConfig,
) -> Result<(), SocketError>
pub fn configure_socket( &self, socket: Weak<UdpSocket>, config: &SocketConfig, ) -> Result<(), SocketError>
Configure a UDP socket (bind)
Sourcepub fn send_datagram(
&self,
socket: &UdpSocket,
dest_ip: [u8; 4],
dest_port: u16,
data: Vec<u8>,
) -> Result<(), SocketError>
pub fn send_datagram( &self, socket: &UdpSocket, dest_ip: [u8; 4], dest_port: u16, data: Vec<u8>, ) -> Result<(), SocketError>
Send a UDP datagram
Sourcepub fn receive_datagram(
&self,
src_ip: Ipv4Address,
src_port: u16,
dst_port: u16,
data: Vec<u8>,
)
pub fn receive_datagram( &self, src_ip: Ipv4Address, src_port: u16, dst_port: u16, data: Vec<u8>, )
Receive a UDP datagram
Source§impl UdpLayer
impl UdpLayer
Sourcepub fn receive_packet(
&self,
src_ip: Ipv4Address,
_dst_ip: Ipv4Address,
packet: &[u8],
) -> Result<(), SocketError>
pub fn receive_packet( &self, src_ip: Ipv4Address, _dst_ip: Ipv4Address, packet: &[u8], ) -> Result<(), SocketError>
Receive a UDP datagram
Trait Implementations§
Source§impl NetworkLayer for UdpLayer
impl NetworkLayer for UdpLayer
Source§fn register_protocol(&self, _proto_num: u16, _handler: Arc<dyn NetworkLayer>)
fn register_protocol(&self, _proto_num: u16, _handler: Arc<dyn NetworkLayer>)
Register a protocol handler for this layer Read more
Source§fn send(
&self,
_packet: &[u8],
_context: &LayerContext,
_next_layers: &[Arc<dyn NetworkLayer>],
) -> Result<(), SocketError>
fn send( &self, _packet: &[u8], _context: &LayerContext, _next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>
Send a packet through this layer Read more
Source§fn receive(
&self,
packet: &[u8],
context: Option<&LayerContext>,
) -> Result<(), SocketError>
fn receive( &self, packet: &[u8], context: Option<&LayerContext>, ) -> Result<(), SocketError>
Receive and process a packet at this layer Read more
Source§fn stats(&self) -> NetworkLayerStats
fn stats(&self) -> NetworkLayerStats
Get layer statistics
Source§fn configure(
&self,
config: &SocketConfig,
next_layers: &[Arc<dyn NetworkLayer>],
) -> Result<(), SocketError>
fn configure( &self, config: &SocketConfig, next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>
Configure this layer with socket-specific parameters Read more