feat(network): add full IPv6 DNS support and fix persistence issues#354
feat(network): add full IPv6 DNS support and fix persistence issues#354robertkill merged 1 commit intolinuxdeepin:masterfrom
Conversation
deepin pr auto review代码审查意见: dcc-network/operation/dccnetwork.cpp:
dcc-network/qml/NetUtils.js:
dcc-network/qml/PageDSLSettings.qml, PageSettings.qml, PageVPNSettings.qml:
dcc-network/qml/SectionDNS.qml:
net-view/operation/private/netmanagerthreadprivate.cpp:
|
Reviewer's GuideThis PR implements full IPv6 DNS support and fixes persistence by refactoring the back-end to consistently fetch and store IPv6 gateway and DNS via DBus, extending the dccnetwork layer to parse and persist both IPv4/IPv6 DNS addresses with ignore-auto-dns flags, and updating QML frontend (NetUtils.js, SectionDNS.qml, and page components) to validate, display, merge, and split mixed DNS entries. Sequence Diagram for Retrieving IPv6 DNS ConfigurationsequenceDiagram
participant QMLUI as QML UI
participant NMTP as NetManagerThreadPrivate
participant NM as NetworkManager (DBus)
QMLUI->>NMTP: Request Connection Info (id)
activate NMTP
NMTP->>NM: Call GetSettings (org.freedesktop.NetworkManager.Settings.Connection)
activate NM
NM-->>NMTP: Return DBusSettingsMap (with ipv6.dns as QList<QHostAddress> or StringList)
deactivate NM
NMTP-->>NMTP: Process response, convert IPv6 DNS to QStringList if needed
NMTP-->>QMLUI: Emit request(NetManager::ConnectInfo, id, params_with_ipv6_dns)
deactivate NMTP
Sequence Diagram for Setting IPv6 DNS ConfigurationsequenceDiagram
actor User
participant PageQML as Page*.qml
participant SectionDNSQML as SectionDNS.qml
participant DccNetworkSvc as DccNetwork
participant NMTP as NetManagerThreadPrivate
participant NM as NetworkManager (DBus)
User->>PageQML: Input/Modify DNS (IPv4/IPv6) & Save
activate PageQML
PageQML->>SectionDNSQML: getConfig()
activate SectionDNSQML
SectionDNSQML-->>PageQML: Return mixed DNS list (numbers for IPv4, strings for IPv6)
deactivate SectionDNSQML
PageQML-->>PageQML: Prepare nConfig (separate ipv4.dns and ipv6.dns)
PageQML->>DccNetworkSvc: exec(NetManager.SetConnectInfo, id, nConfig)
deactivate PageQML
activate DccNetworkSvc
DccNetworkSvc-->>DccNetworkSvc: Process ipv6.dns (convert to QList<QHostAddress>, then to QStringList for NM, set ignore-auto-dns=true)
DccNetworkSvc->>NMTP: m_manager->exec(SetConnectInfo, id, processedParams)
deactivate DccNetworkSvc
activate NMTP
NMTP-->>NMTP: Convert QStringList IPv6 DNS to QList<QHostAddress>
NMTP-->>NMTP: Update Ipv6Setting (ipv6Setting->setDns(), ipv6Setting->setIgnoreAutoDns(true))
NMTP->>NM: Update Connection Settings (via NM API)
activate NM
NM-->>NMTP: Settings Updated Confirmation
deactivate NM
NMTP-->>DccNetworkSvc: Result
deactivate NMTP
Class Diagram for Backend C++ Components (Network IPv6 DNS Handling)classDiagram
class NetManagerThreadPrivate {
<<Modified>>
+doGetConnectInfo(const QString& id, NetType::NetItemType type) void
+doSetConnectInfo(const QString& id, NetType::NetItemType type, const QVariantMap& param) void
}
class DccNetwork {
<<Modified>>
+exec(NetManager::CmdType cmd, const QString& id, const QVariantMap& param) void
}
class Ipv6Setting {
%% NetworkManager Library Class (Conceptual)
+setDns(QList~QHostAddress~ dns)
+setIgnoreAutoDns(bool ignore)
+dns() QList~QHostAddress~
+method() Method
}
NetManagerThreadPrivate ..> Ipv6Setting : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @robertkill - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
ipv6RegExpis not defined (link)
General comments:
- There’s a lot of duplicated DBus-fetching and IPv6 mapping logic in NetManagerThreadPrivate—consider extracting that into a shared helper to reduce code duplication and simplify maintenance.
- The backend still logs a warning for “IPv6 DNS not fully implemented”—you should implement the numeric/packed representation or define a clear fallback so users actually get full IPv6 DNS support.
- The numerous console.log calls in NetUtils.js and QML will flood production logs—either remove them or guard them behind a debug‐mode flag.
Here's what I looked at during the review
- 🔴 General issues: 1 blocking issue, 4 other issues
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if (!settingsMap.isError() && settingsMap.value().contains("ipv6") && settingsMap.value().value("ipv6").contains("gateway")) { | ||
| QString gateway = settingsMap.value().value("ipv6").value("gateway").toString(); | ||
| QVariantMap ipv6Map = retParam["ipv6"].value<QVariantMap>(); | ||
| // 手动获取IPv6配置(包括gateway和DNS) |
There was a problem hiding this comment.
suggestion: IPv6 settings retrieval logic is duplicated
Refactor the repeated IPv6 gateway and DNS retrieval logic into a helper function for better maintainability.
Suggested implementation:
if (!dbusSettingsMap.isError() && dbusSettingsMap.value().contains("ipv6")) {
QVariantMap ipv6Data = dbusSettingsMap.value().value("ipv6");
QVariantMap ipv6Map = retParam["ipv6"].value<QVariantMap>();
// 使用辅助函数处理IPv6 gateway和DNS
insertIpv6GatewayAndDns(ipv6, ipv6Data, ipv6Map);
/**
* Helper function to insert IPv6 gateway and DNS into the provided map.
*/
static void insertIpv6GatewayAndDns(const Ipv6Setting::Ptr& ipv6, const QVariantMap& ipv6Data, QVariantMap& ipv6Map)
{
// 处理IPv6 gateway
if (ipv6->method() == Ipv6Setting::Manual && ipv6Data.contains("gateway")) {
QString gateway = ipv6Data.value("gateway").toString();
ipv6Map.insert("gateway", gateway);
}
// 处理IPv6 DNS
if (ipv6Data.contains("dns")) {
QVariant dnsVariant = ipv6Data.value("dns");
if (dnsVariant.canConvert<QVariantList>()) {
QVariantList dnsList = dnsVariant.toList();
ipv6Map.insert("dns", dnsList);
}
}
}
- Replace any other duplicated logic for extracting IPv6 gateway and DNS elsewhere in the file with calls to
insertIpv6GatewayAndDns. - Ensure the helper function is placed in an appropriate location (e.g., near the top of the file or in an anonymous namespace if needed).
- If the DNS logic is more complex elsewhere, adjust the helper accordingly.
| // 手动处理IPv6 DNS设置 - 确保正确初始化 | ||
| if (map.contains("ipv6")) { | ||
| QVariant ipv6Variant = map["ipv6"]; | ||
| if (ipv6Variant.type() == QVariant::Map) { |
There was a problem hiding this comment.
suggestion: Use of QVariant::type() is deprecated
QVariant::type() is deprecated in Qt 6. Use QVariant::userType() or canConvert()/toMap with appropriate checks instead.
| dns.append(addr.toIPv4Address()); | ||
| } else if (addr.protocol() == QAbstractSocket::IPv6Protocol) { | ||
| // IPv6地址转换为128位表示(当前系统可能不支持,先跳过) | ||
| qWarning() << "IPv6 DNS not fully implemented in backend, DNS:" << dnsStr; |
There was a problem hiding this comment.
issue: IPv6 DNS handling is unimplemented and skipped
If IPv6 DNS support is needed, please implement full handling or add a fallback to avoid skipped records.
|
|
||
| // 验证IP地址是否为IPv6 | ||
| function isIpv6Address(ip) { | ||
| var result = ipv6RegExp.test(ip) |
There was a problem hiding this comment.
issue (bug_risk): ipv6RegExp is not defined
This will cause a runtime error. Please define or import ipv6RegExp.
| // 移除正则验证器,改用手动验证以支持IPv6 | ||
| // 显式允许所有字符输入,包括冒号 | ||
| inputMethodHints: Qt.ImhNone | ||
| onTextChanged: { | ||
| console.log("[DNS-Input] Text changed in DNS field", index, ":", text) |
There was a problem hiding this comment.
suggestion: Removing validator may hurt user experience
Disabling input method hints removes the numeric keypad for IPv4 entry. Dynamically set hints based on the input type (IPv4 or IPv6) to maintain optimal user experience.
| // 移除正则验证器,改用手动验证以支持IPv6 | |
| // 显式允许所有字符输入,包括冒号 | |
| inputMethodHints: Qt.ImhNone | |
| onTextChanged: { | |
| console.log("[DNS-Input] Text changed in DNS field", index, ":", text) | |
| // 移除正则验证器,改用手动验证以支持IPv6 | |
| // 根据输入内容动态设置 inputMethodHints:IPv4 用数字键盘,IPv6/其他用默认键盘 | |
| inputMethodHints: { | |
| // 简单判断:只包含数字和点,认为是 IPv4 | |
| if (/^[0-9.]*$/.test(text)) { | |
| return Qt.ImhDigitsOnly | |
| } | |
| // 其他情况(如包含冒号等),允许所有字符 | |
| return Qt.ImhNone | |
| } | |
| onTextChanged: { | |
| console.log("[DNS-Input] Text changed in DNS field", index, ":", text) |
| let num = parseInt(octet, 10) | ||
| for (var j = 0; j < octets.length; j++) { | ||
| var octet = octets[j] | ||
| var num = parseInt(octet, 10) |
There was a problem hiding this comment.
issue (code-quality): Use const or let instead of var. (avoid-using-var)
Explanation
`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.From the Airbnb JavaScript Style Guide
| return new Uint8Array(hexArr.match(/[\da-f]{2}/gi).map(bb => { | ||
| return parseInt(bb, 16) | ||
| })).buffer | ||
| var arr = str.split(":") |
There was a problem hiding this comment.
issue (code-quality): Use const or let instead of var. (avoid-using-var)
Explanation
`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.From the Airbnb JavaScript Style Guide
| return parseInt(bb, 16) | ||
| })).buffer | ||
| var arr = str.split(":") | ||
| var hexArr = arr.join("") |
There was a problem hiding this comment.
issue (code-quality): Use const or let instead of var. (avoid-using-var)
Explanation
`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.From the Airbnb JavaScript Style Guide
| var arr = [] | ||
| for (var i = 0; i < data.length; ++i) { | ||
| let charcode = data.charCodeAt(i) | ||
| var charcode = data.charCodeAt(i) |
There was a problem hiding this comment.
issue (code-quality): Use const or let instead of var. (avoid-using-var)
Explanation
`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.From the Airbnb JavaScript Style Guide
| return new Uint8Array(arr).buffer | ||
| } else if (data instanceof ArrayBuffer) { | ||
| const uint8Array = new Uint8Array(data) | ||
| var uint8Array = new Uint8Array(data) |
There was a problem hiding this comment.
issue (code-quality): Use const or let instead of var. (avoid-using-var)
Explanation
`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.From the Airbnb JavaScript Style Guide
- Implement IPv6 validation in NetUtils.js for DNS input fields - Fix backend storage in dccnetwork.cpp to use QHostAddress format - Add ignore-auto-dns=true setting for proper NetworkManager persistence - Update frontend QML components to handle mixed IPv4/IPv6 DNS - Enhance netmanagerthreadprivate.cpp to read IPv6 DNS from NM settings Fixes issues with IPv6 DNS input, saving and display in Control Center. pms: BUG-319129
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: caixr23, robertkill 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 |
Fixes issues with IPv6 DNS input, saving and display in Control Center.
pms: BUG-319129
Summary by Sourcery
Enable comprehensive IPv6 DNS support and persistence by updating validation, UI, backend storage, and NetworkManager settings handling
New Features:
Bug Fixes:
Enhancements: