From 3fc396f5f1c7e0da84c69aecce81b684082f1c03 Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Tue, 24 Sep 2024 13:30:47 +0800 Subject: [PATCH] Adjust the ephemeral port --- kernel/libs/aster-bigtcp/src/iface/common.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/libs/aster-bigtcp/src/iface/common.rs b/kernel/libs/aster-bigtcp/src/iface/common.rs index b92048881..eb63e14e9 100644 --- a/kernel/libs/aster-bigtcp/src/iface/common.rs +++ b/kernel/libs/aster-bigtcp/src/iface/common.rs @@ -67,7 +67,11 @@ impl IfaceCommon { self.interface.lock().ipv4_addr() } - /// Alloc an unused port range from 49152 ~ 65535 (According to smoltcp docs) + /// Allocates an unused ephemeral port. + /// + /// We follow the port range that many Linux kernels use by default, which is 32768-60999. + /// + /// See . fn alloc_ephemeral_port(&self) -> Option { let mut used_ports = self.used_ports.lock(); for port in IP_LOCAL_PORT_START..=IP_LOCAL_PORT_END { @@ -95,7 +99,7 @@ impl IfaceCommon { true } - /// Release port number so the port can be used again. For reused port, the port may still be in use. + /// Releases the port so that it can be used again (if it is not being reused). pub(crate) fn release_port(&self, port: u16) { let mut used_ports = self.used_ports.lock(); if let Some(used_times) = used_ports.remove(&port) { @@ -246,5 +250,5 @@ impl IfaceCommon { } } -const IP_LOCAL_PORT_START: u16 = 49152; -const IP_LOCAL_PORT_END: u16 = 65535; +const IP_LOCAL_PORT_START: u16 = 32768; +const IP_LOCAL_PORT_END: u16 = 60999;