fix(net): 解决dhcp偶尔失败的问题 (#1205)

原因是unified init导致网卡顺序不一样了,原本固定写死id的方式不对.现在改用名称匹配

Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
LoGin
2025-06-12 14:22:27 +08:00
committed by GitHub
parent 478d68a4de
commit 523d2a97d9

View File

@ -45,10 +45,17 @@ pub fn net_init() -> Result<(), SystemError> {
fn dhcp_query() -> Result<(), SystemError> {
let binding = NET_DEVICES.write_irqsave();
//由于现在os未实现在用户态为网卡动态分配内存而lo网卡的id最先分配且ip固定不能被分配
//所以特判取用id为1的网卡也就是virto_net
let net_face = binding.get(&1).ok_or(SystemError::ENODEV)?.clone();
let net_face = binding
.iter()
.find(|(_, iface)| iface.name().starts_with("eth"))
.map(|(_, iface)| iface.clone());
if net_face.is_none() {
warn!("dhcp_query: No net device found!");
return Err(SystemError::ENODEV);
}
let net_face = net_face.unwrap();
log::debug!("dhcp_query: net_face={}", net_face.name());
drop(binding);
// Create sockets