feat(axnet-ng): implement SO_TYPE, SO_PROTOCOL, SO_DOMAIN socket options - #884
Merged
Conversation
Contributor
There was a problem hiding this comment.
PR #884 Review: feat(axnet-ng): implement SO_TYPE, SO_PROTOCOL, SO_DOMAIN socket options
变更概述
本 PR 为 axnet-ng 的 GeneralOptions 新增 socket_type、domain、protocol 三个字段,实现 SO_TYPE、SO_PROTOCOL、SO_DOMAIN 三个只读 socket option,解决 pip/ssl 因 getsockopt(SO_TYPE) 返回 ENOPROTOOPT 而失败的问题。
实现正确性
- Linux 语义符合:三个 option 均为只读,
getsockopt返回 socket 创建时的常量值,setsockopt返回ENOPROTOOPT,完全符合 Linuxsocket(7)/getsockopt(2)语义。 - 构造函数签名扩展合理:移除
Defaultimpl,改为new(socket_type, domain, protocol),所有调用方均正确传入三元组。各 socket 类型的参数值(TCP: 1/2/6, UDP: 2/2/17, Raw: 3/2/protocol, Unix: */1/0, Vsock: */40/0)均正确。 - syscall 层映射正确:通过
call_dispatch!宏将(SOL_SOCKET, SO_TYPE/SO_PROTOCOL/SO_DOMAIN)映射到对应枚举变体,使用Int<i32>转换,类型正确。 - 代码风格一致:
domain/protocol为构造后不可变的i32,socket_type为AtomicI32(与其他原子字段风格一致),get用Ordering::Relaxed读取,无竞态风险。
测试覆盖
- 新增
test-sockopt测试套件,覆盖 SO_TYPE/SO_PROTOCOL/SO_DOMAIN 的 get 返回值(TCP+UDP)和 set 拒绝(ENOPROTOOPT),共 9 个检查点。 - QEMU 配置文件覆盖 x86_64/riscv64/aarch64/loongarch64 四架构。
success_regex和fail_regex设置正确,能可靠区分通过/失败。
建议改进(非阻塞)
- 测试仅覆盖 AF_INET (TCP/UDP),未覆盖 AF_UNIX 和 AF_VSOCK socket。如后续有 Unix socket 测试环境,建议补充。
- 魔数(1, 2, 3, 6, 17, 40)可以考虑定义常量或引用
linux_raw_sys中的SOCK_*/AF_*/IPPROTO_*常量,提高可读性。但当前风格与已有代码一致,可后续统一重构。
CI 状态
CI 全部 skipped,为外部 fork PR 的正常行为(GitHub Actions 需手动批准运行)。本地检查:
cargo fmt --check:本 PR 未引入新的格式问题(base 分支已有的 let-chain 警告非本 PR 引入)。
重复/重叠分析
- base 分支 (
origin/dev) 无 SO_TYPE/SO_PROTOCOL/SO_DOMAIN 实现。 - 检查所有 open PR(#882 xattr, #885 thread snapshot, #865 shm, #867 membarrier 等),均不涉及 socket option 实现,无重复或冲突。
结论
实现正确、测试充分、无重复、无阻塞问题。Approve。
Powered by glm-5.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pip install时,直接报错,因为Python 3.12
ssl.SSLSocket._create()使用getsockopt(SO_TYPE)验证 socket 类型, StarryOS 未实现该选项导致 TLS 握手失败。于是我选择支持了
SO_TYPE,同时还有两个有可能在pip中使用的option,SO_PROTOCOL,SO_DOMAIN,我也加入了支持。然后我分析option时发现好几个存在bug的option,已经加上todo标签,需要时修改。给未支持的option加上了注释。
添加了三个option有关的测试文件
Summary
实现
SO_TYPE、SO_PROTOCOL、SO_DOMAIN三个只读 socket option,解决 pip 等软件因getsockopt(SO_TYPE)返回ENOPROTOOPT而阻塞的问题。设计
GeneralOptions新增domain和protocol字段,构造签名扩展为:各协议 socket 在构造时传入正确的三元组,值在 socket 生命周期内不变:
u8::from(ip_protocol)(如 ICMP=1)三个 option 均为只读,
setsockopt返回ENOPROTOOPT,符合 Linux 语义。syscall 层
call_dispatch!宏将 Linux 常量映射到GetSocketOption枚举,通过Configurabletrait 分发到各 socket 实现变更文件
options.rsSocketType、SocketProtocol、SocketDomain枚举变体general.rsdomain/protocol字段,构造函数签名扩展,get 返回存储值,set 返回ENOPROTOOPTopt.rsSO_TYPE/SO_PROTOCOL/SO_DOMAIN映射,SO_LINGER移入待支持列表tcp.rs/udp.rs/raw.rs(type, domain, protocol)三元组unix/dgram.rs/unix/stream.rs/vsock/stream.rstest-sockopt/test_framework.h