fix(network): filter virtual network interfaces correctly on Windows#723
fix(network): filter virtual network interfaces correctly on Windows#723lzwind merged 2 commits intolinuxdeepin:masterfrom
Conversation
Reviewer's GuideRefactors IP selection to centralize virtual network interface filtering into a reusable helper that considers both the technical and human-readable interface names, improving detection of virtual/bridge adapters (including Windows-only cases) so that the application chooses a real, reachable IPv4 address for data transfer and web server binding. Sequence diagram for getFirstIp interface filtering with isVirtualInterfacesequenceDiagram
participant CommonUitls
participant QNetworkInterface
participant isVirtualInterface
CommonUitls->>QNetworkInterface: allInterfaces()
loop for each netInterface
CommonUitls->>QNetworkInterface: flags()
QNetworkInterface-->>CommonUitls: interfaceFlags
alt not up or not running or loopback
CommonUitls-->>CommonUitls: continue to next interface
else valid interface flags
CommonUitls->>isVirtualInterface: isVirtualInterface(netInterface)
alt is virtual
isVirtualInterface-->>CommonUitls: true
CommonUitls-->>CommonUitls: skip virtual interface
else not virtual
isVirtualInterface-->>CommonUitls: false
CommonUitls->>QNetworkInterface: addressEntries()
QNetworkInterface-->>CommonUitls: entries
loop for each entry
CommonUitls-->>CommonUitls: check IPv4 and not LocalHost
alt matches criteria
CommonUitls-->>CommonUitls: select IP
CommonUitls-->>CommonUitls: log IP and interface name
CommonUitls-->>CommonUitls: return IP string
end
end
end
end
end
Flow diagram for updated getFirstIp virtual interface filteringflowchart TD
A[Start getFirstIp] --> B[Initialize empty ip string]
B --> C[Get list of all network interfaces]
C --> D[For each netInterface in interfaces]
D --> E{netInterface.flags contains IsUp
and contains IsRunning
and does not contain IsLoopBack?}
E -- No --> D
E -- Yes --> F{isVirtualInterface netInterface?}
F -- Yes --> D
F -- No --> G[Get all addressEntries of netInterface]
G --> H[For each entry in addressEntries]
H --> I{entry.ip protocol is IPv4
and entry.ip is not LocalHost?}
I -- No --> H
I -- Yes --> J[Set ip to entry.ip string]
J --> K[Log Found available IP with interface name]
K --> L[Return ip as std::string]
H -->|No more entries| D
D -->|No more interfaces| M[Return empty std::string]
M --> N[End getFirstIp]
Flow diagram for isVirtualInterface helper logicflowchart TD
A[Start isVirtualInterface] --> B[Read netInterface.name and toLower]
B --> C{name starts with virbr
or vmnet
or docker
or veth
or br-?}
C -- Yes --> D[Log Filtering virtual interface by name]
D --> E[Return true]
C -- No --> F[Read netInterface.humanReadableName and toLower]
F --> G{humanName contains vmware
or virtualbox
or hyper-v
or virtual ethernet
or vethernet
or bluetooth?}
G -- Yes --> H[Log Filtering virtual interface by humanReadableName]
H --> I[Return true]
G -- No --> J[Return false]
J --> K[End isVirtualInterface]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
isVirtualInterfacehelper is duplicated in two compilation units; consider moving it to a shared header/source to avoid divergence between platform builds over time. - The new
qInfo()logging insideisVirtualInterfacewill log on every filtered interface; if this runs frequently, consider lowering the log level or adding a one-time debug summary to reduce log noise.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `isVirtualInterface` helper is duplicated in two compilation units; consider moving it to a shared header/source to avoid divergence between platform builds over time.
- The new `qInfo()` logging inside `isVirtualInterface` will log on every filtered interface; if this runs frequently, consider lowering the log level or adding a one-time debug summary to reduce log noise.
## Individual Comments
### Comment 1
<location path="src/common/commonutils.cpp" line_range="33-41" />
<code_context>
+ if (name.startsWith("virbr") || name.startsWith("vmnet")
+ || name.startsWith("docker") || name.startsWith("veth")
+ || name.startsWith("br-")) {
+ qInfo() << "Filtering virtual interface (by name):" << netInterface.name();
+ return true;
+ }
+
+ QString humanName = netInterface.humanReadableName().toLower();
+ if (humanName.contains("vmware") || humanName.contains("virtualbox")
+ || humanName.contains("hyper-v") || humanName.contains("virtual ethernet")
+ || humanName.contains("vethernet") || humanName.contains("bluetooth")) {
+ qInfo() << "Filtering virtual interface (by humanReadableName):" << netInterface.humanReadableName();
+ return true;
+ }
</code_context>
<issue_to_address>
**suggestion (performance):** Verbose logging for every filtered interface may be noisy in normal operation.
At `qInfo` level this may generate excessive logs on hosts with many virtual/container interfaces, especially if `getFirstIp` runs often. Please consider moving these to a debug-level log or guarding them with a debug/verbose flag to avoid log spam in normal deployments.
Suggested implementation:
```cpp
if (name.startsWith("virbr") || name.startsWith("vmnet")
|| name.startsWith("docker") || name.startsWith("veth")
|| name.startsWith("br-")) {
qDebug() << "Filtering virtual interface (by name):" << netInterface.name();
return true;
}
```
```cpp
QString humanName = netInterface.humanReadableName().toLower();
if (humanName.contains("vmware") || humanName.contains("virtualbox")
|| humanName.contains("hyper-v") || humanName.contains("virtual ethernet")
|| humanName.contains("vethernet") || humanName.contains("bluetooth")) {
qDebug() << "Filtering virtual interface (by humanReadableName):" << netInterface.humanReadableName();
return true;
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
TAG Bot TAG: 1.2.3 |
Refactor the virtual interface detection logic into a dedicated function and add checks for additional virtual interfaces (e.g., veth, br-, VMware, VirtualBox, Hyper-V, Bluetooth) based on both name and human-readable name. This improves IP address retrieval by more accurately skipping virtual network interfaces.
- bump version to 1.2.3 Log : bump version to 1.2.3
deepin pr auto review这份 1. 代码逻辑与功能审查优点:
潜在问题与建议:
2. 代码质量与可维护性
3. 性能分析
4. 代码安全
5. 具体改进建议代码示例针对代码重复和可维护性,建议将 针对 static bool isVirtualInterface(const QNetworkInterface &netInterface)
{
// 1. 检查接口名称 (Linux/MacOS 主要依赖此项)
QString name = netInterface.name().toLower();
const QStringList virtualPrefixes = {"virbr", "vmnet", "docker", "veth", "br-"};
for (const QString &prefix : virtualPrefixes) {
if (name.startsWith(prefix)) {
qInfo() << "Filtering virtual interface (by name):" << netInterface.name();
return true;
}
}
// 2. 检查可读名称 (Windows 主要依赖此项)
QString humanName = netInterface.humanReadableName().toLower();
// 使用 QStringList 便于管理和扩展关键字
const QStringList virtualKeywords = {
"vmware", "virtualbox", "hyper-v",
"virtual ethernet", "vethernet", "bluetooth"
};
for (const QString &keyword : virtualKeywords) {
if (humanName.contains(keyword)) {
qInfo() << "Filtering virtual interface (by humanReadableName):" << netInterface.humanReadableName();
return true;
}
}
return false;
}改进点说明:
总结这段代码修改质量很高,主要解决了 Windows 平台下虚拟网卡识别不全的问题,并优化了代码结构。没有明显的安全漏洞或严重的性能问题。主要的改进空间在于消除跨文件的代码重复(如果架构允许)以及使用列表结构来管理过滤关键字以提高可维护性。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pppanghu77, re2zero The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
TAG Bot ✅ Tag created successfully 📋 Tag Details
|
Fix data migration failure when multiple network adapters exist, including virtual adapters like VMware Network Adapter VMnet1. On Windows, virtual adapter names in QNetworkInterface::name() are GUIDs, not "vmnet*", so the previous filter failed to exclude them, causing the app to select the wrong IP address (e.g., 192.168.199.1 instead of the real WLAN IP 192.168.43.204).
Changes:
This ensures the sender advertises the correct IP address and the web server binds to a reachable network interface, preventing 0B file transfers.
Summary by Sourcery
Filter out virtual and non-routable network interfaces more reliably when selecting the first available IP address.
Bug Fixes:
Enhancements: