netstack: SocketT trait + all impls take (level, name) for sockopt

DEF-P0-11 (Finding 1.7: option collision) from
NETWORKING-AND-DRIVERS-CODE-ASSESSMENT-2026-07-27.md §3.4: SocketT
trait methods get_sock_opt and set_sock_opt previously took a single
'name' parameter. The dispatch in scheme/socket.rs now reads
metadata[1] as level and metadata[2] as name, but the trait didn't
have the level parameter. This commit updates the trait and all
impls (socket.rs stub, tcp.rs, udp.rs) to take (level, name) as
separate parameters. The impls ignore level for now (each impl
only handles its own protocol family), but the parameter is there
so future per-level dispatch (e.g. 'IP_TTL only valid at
IPPROTO_IP') can reject early with ENOPROTOOPT.
This commit is contained in:
Red Bear OS
2026-07-27 18:02:15 +09:00
parent e3f87fa3cf
commit 181eb63dd2
3 changed files with 21 additions and 2 deletions
+17 -2
View File
@@ -264,6 +264,7 @@ where
fn get_sock_opt(
&self,
_file: &SchemeFile<Self>,
_level: usize,
_name: usize,
_buf: &mut [u8],
) -> SyscallResult<usize> {
@@ -273,6 +274,7 @@ fn get_sock_opt(
fn set_sock_opt(
&mut self,
_file: &SchemeFile<Self>,
_level: usize,
_name: usize,
_buf: &[u8],
) -> SyscallResult<usize> {
@@ -475,10 +477,17 @@ where
Handle::File(file) => {
let mut socket_set = self.socket_set.borrow_mut();
let socket = socket_set.get_mut::<SocketT>(file.socket_handle());
// Wire format: [SocketCall::SetSockOpt, level, option]
// level is SOL_SOCKET (1), IPPROTO_TCP (6), IPPROTO_IP (0),
// etc. Without level, option 4 reads as IP_TOS at
// IPPROTO_IP when caller asked for TCP_KEEPIDLE at
// SOL_SOCKET. See NETWORKING-AND-DRIVERS-CODE-ASSESSMENT
// §3.4 (Finding 1.7: option collision).
SocketT::set_sock_opt(
socket,
file,
metadata[1] as usize,
metadata[1] as usize, // level
metadata[2] as usize, // option
payload,
)
}
@@ -492,7 +501,13 @@ where
Handle::File(ref mut file) => {
let mut socket_set = self.socket_set.borrow_mut();
let socket = socket_set.get_mut::<SocketT>(file.socket_handle());
SocketT::get_sock_opt(socket, file, metadata[1] as usize, payload)
SocketT::get_sock_opt(
socket,
file,
metadata[1] as usize, // level
metadata[2] as usize, // option
payload,
)
}
Handle::Null(_) => {
// TODO
+2
View File
@@ -427,6 +427,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> {
fn get_sock_opt(
&self,
_file: &SchemeFile<Self>,
_level: usize,
name: usize,
buf: &mut [u8],
) -> SyscallResult<usize> {
@@ -558,6 +559,7 @@ unsafe {
fn set_sock_opt(
&mut self,
_file: &SchemeFile<Self>,
_level: usize,
name: usize,
buf: &[u8],
) -> SyscallResult<usize> {
+2
View File
@@ -479,6 +479,7 @@ impl<'a> SchemeSocket for UdpSocket<'a> {
fn get_sock_opt(
&self,
_file: &SchemeFile<Self>,
_level: usize,
name: usize,
buf: &mut [u8],
) -> SyscallResult<usize> {
@@ -516,6 +517,7 @@ impl<'a> SchemeSocket for UdpSocket<'a> {
fn set_sock_opt(
&mut self,
_file: &SchemeFile<Self>,
_level: usize,
name: usize,
buf: &[u8],
) -> SyscallResult<usize> {