Ver Fonte

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

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

Signed-off-by: longjin <longjin@DragonOS.org>
LoGin há 3 semanas atrás
pai
commit
523d2a97d9
1 ficheiros alterados com 10 adições e 3 exclusões
  1. 10 3
      kernel/src/net/net_core.rs

+ 10 - 3
kernel/src/net/net_core.rs

@@ -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