Skip to content

Conversation

@caixr23
Copy link
Contributor

@caixr23 caixr23 commented Nov 19, 2025

  1. Added validation to ensure only one gateway can be configured in manual mode for both IPv4 and IPv6
  2. Fixed gateway property type in IPv6 from string to array to support per-address gateway tracking
  3. Enhanced error handling to display specific error messages when multiple gateways are detected
  4. Improved gateway counting logic to prevent configuration errors

Log: Fixed network configuration to prevent setting multiple gateways

Influence:

  1. Test manual network configuration with multiple IP addresses
  2. Verify that only one gateway can be set across all addresses
  3. Test error message display when attempting to set multiple gateways
  4. Validate both IPv4 and IPv6 manual configuration scenarios
  5. Check that automatic and disabled modes don't retain gateway settings

fix: 修复手动网络配置中多个网关设置问题

  1. 添加验证逻辑确保手动模式下IPv4和IPv6只能配置一个网关
  2. 修复IPv6网关属性类型从字符串改为数组以支持按地址跟踪网关
  3. 增强错误处理,在检测到多个网关时显示具体错误信息
  4. 改进网关计数逻辑以防止配置错误

Log: 修复网络配置中设置多个网关的问题

Influence:

  1. 测试包含多个IP地址的手动网络配置
  2. 验证所有地址中只能设置一个网关
  3. 测试尝试设置多个网关时的错误消息显示
  4. 验证IPv4和IPv6手动配置场景
  5. 检查自动和禁用模式不会保留网关设置

PMS: BUG-312351

Summary by Sourcery

Prevent configuring multiple gateways in manual network settings by converting the IPv6 gateway property to an array, adding validation to enforce a single gateway for both IPv4 and IPv6, and surfacing specific error messages when duplicates are detected.

Bug Fixes:

  • Ensure only one gateway can be configured in manual mode for both IPv4 and IPv6.
  • Show clear error messages when multiple gateways are detected.

Enhancements:

  • Change IPv6 gateway property type to array to support per-address gateway tracking.
  • Refine gateway counting and assignment logic in configuration serialization and validation.

@caixr23 caixr23 requested a review from robertkill November 19, 2025 06:58
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 19, 2025

Reviewer's Guide

This PR transforms the gateway field into an address-indexed array, updates serialization and UI bindings to work with multiple address slots, and enforces a single-gateway constraint through enhanced counting and error messaging for both IPv4 and IPv6 in manual mode.

Class diagram for updated IPv6 and IPv4 configuration models

classDiagram
class SectionIPv6 {
  +var addressData
  +bool isEdit
  +string method
  +var gateway  // changed from string to array
  +string errorKey
  +string errorMsg
  +getConfig()
  +validate()
}
class SectionIPv4 {
  +var addressData
  +bool isEdit
  +string method
  +string gateway
  +string errorKey
  +string errorMsg
  +getConfig()
  +validate()
}
SectionIPv6 --> "addressData[]" AddressData
SectionIPv6 --> "gateway[]" Gateway
SectionIPv4 --> "addressData[]" AddressData
SectionIPv4 --> "gateway" Gateway

class AddressData {
  +string address
  +string netmask
}
class Gateway {
  +string value
}
Loading

File-Level Changes

Change Details Files
Convert gateway property to an array for per-address tracking
  • Changed gateway QML property from string to var array
  • Initialized gateway as an array when loading or resetting config
  • Set the first array element from existing config gateway value
SectionIPv6.qml
Serialize only the first non-empty gateway in manual mode
  • Loop through gateway array in getConfig and assign the first non-empty entry
  • Delete gateway field for non-manual modes
SectionIPv6.qml
SectionIPv4.qml
Enforce single-gateway constraint with counting logic
  • Introduced gatewayCount variable in validation for IPv4 and IPv6
  • Increment count for each non-empty gateway and error out on count ≥2
SectionIPv6.qml
SectionIPv4.qml
Refine UI bindings to support gateway array
  • Bind LineEdit text to gateway[index] instead of single string
  • Update onAcceptInput to compare and assign gateway[index]
  • Add alertText property to show specific error messages
SectionIPv6.qml
SectionIPv4.qml
Enhance error messaging for gateway validation
  • Specify "Only one gateway is allowed" when multiple gateways detected
  • Retain validation of IP format with clear errorKey and errorMsg
SectionIPv6.qml
SectionIPv4.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider extracting the gateway‐counting and validation logic in both SectionIPv4 and SectionIPv6 into a shared helper to reduce duplication and keep behavior consistent.
  • Instead of managing a sparse array for gateways, track a single gateway value or explicit index to simplify getConfig and binding logic and avoid edge cases.
  • Remove the console.log in the IPv6 validation block to prevent spurious debug output in production.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the gateway‐counting and validation logic in both SectionIPv4 and SectionIPv6 into a shared helper to reduce duplication and keep behavior consistent.
- Instead of managing a sparse array for gateways, track a single gateway value or explicit index to simplify getConfig and binding logic and avoid edge cases.
- Remove the console.log in the IPv6 validation block to prevent spurious debug output in production.

## Individual Comments

### Comment 1
<location> `dcc-network/qml/SectionIPv6.qml:93` </location>
<code_context>
                 }
                 // 检查网关
-                if (k === "0" && gateway.length !== 0 && !NetUtils.ipv6RegExp.test(gateway)) {
+                console.log("gateway =====", k, gateway[k])
+                if (gateway[k].length !== 0) {
+                    gatewayCount++
</code_context>

<issue_to_address>
**issue:** Debug logging should be removed or gated before merging.

Console.log statements in production may clutter logs or expose sensitive data. Please remove or conditionally enable this debug output.
</issue_to_address>

### Comment 2
<location> `dcc-network/qml/SectionIPv4.qml:71` </location>
<code_context>
         errorKey = ""
         errorMsg = ""
         if (method === "manual") {
+            let gatewayCount = 0
             for (let k in addressData) {
                 if (!NetUtils.ipRegExp.test(addressData[k][0])) {
</code_context>

<issue_to_address>
**suggestion:** Gateway count logic for IPv4 may not handle malformed addressData entries.

Add validation to ensure addressData[k][2] exists and is a string before accessing it to prevent runtime errors.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 4, 2025

TAG Bot

New tag: 2.0.75
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #443

@caixr23 caixr23 force-pushed the BUG-312351 branch 2 times, most recently from 19c9d90 to e8c27a5 Compare December 9, 2025 06:44
1. Added validation to ensure only one gateway can be configured in
manual mode for both IPv4 and IPv6
2. Fixed gateway property type in IPv6 from string to array to support
per-address gateway tracking
3. Enhanced error handling to display specific error messages when
multiple gateways are detected
4. Improved gateway counting logic to prevent configuration errors

Log: Fixed network configuration to prevent setting multiple gateways

Influence:
1. Test manual network configuration with multiple IP addresses
2. Verify that only one gateway can be set across all addresses
3. Test error message display when attempting to set multiple gateways
4. Validate both IPv4 and IPv6 manual configuration scenarios
5. Check that automatic and disabled modes don't retain gateway settings

fix: 修复手动网络配置中多个网关设置问题

1. 添加验证逻辑确保手动模式下IPv4和IPv6只能配置一个网关
2. 修复IPv6网关属性类型从字符串改为数组以支持按地址跟踪网关
3. 增强错误处理,在检测到多个网关时显示具体错误信息
4. 改进网关计数逻辑以防止配置错误

Log: 修复网络配置中设置多个网关的问题

Influence:
1. 测试包含多个IP地址的手动网络配置
2. 验证所有地址中只能设置一个网关
3. 测试尝试设置多个网关时的错误消息显示
4. 验证IPv4和IPv6手动配置场景
5. 检查自动和禁用模式不会保留网关设置

PMS: BUG-312351
@deepin-ci-robot
Copy link

deepin pr auto review

我来帮你审查这段代码的变更。主要涉及 IPv4 和 IPv6 配置的网络设置部分。让我从多个维度进行分析:

  1. 语法逻辑:
  • 代码整体语法正确,没有明显的语法错误
  • 逻辑判断结构清晰,特别是对网关数量的检查逻辑合理
  1. 代码质量:
  • 添加了网关数量检查,提高了配置的健壮性
  • 将 gateway 从字符串改为数组,统一了 IPv4 和 IPv6 的处理方式
  • 代码格式进行了统一,缩进更加规范
  1. 代码性能:
  • 性能方面没有明显问题
  • 建议可以考虑以下几点优化:
    • gateway 数组初始化时可以预先设置长度
    • 可以将网关数量检查的逻辑抽取为单独函数,提高代码复用性
  1. 代码安全:
  • 增加了对网关数量的限制,防止配置多个网关
  • IP 地址验证使用了正则表达式,确保输入合法性
  • 建议增加以下安全措施:
    • 对 gateway 数组进行边界检查
    • 在设置网关时增加空值检查

具体改进建议:

  1. IPv4 部分:
// 可以将网关检查逻辑抽取为单独函数
function validateGateway(addressData) {
    let gatewayCount = 0
    for (let k in addressData) {
        if (addressData[k][2].length !== 0) {
            gatewayCount++
            if (gatewayCount >= 2) {
                return {
                    valid: false,
                    key: k + "gateway",
                    message: qsTr("Only one gateway is allowed")
                }
            }
        }
    }
    return { valid: true }
}
  1. IPv6 部分:
// 初始化时设置数组长度
gateway: new Array(maxGatewayCount)

// 增加边界检查
function setGateway(index, value) {
    if (index < 0 || index >= gateway.length) {
        return false
    }
    gateway[index] = value
    return true
}
  1. 通用改进:
// 添加输入验证函数
function validateInput(value, pattern, fieldName) {
    if (value.length !== 0 && !pattern.test(value)) {
        return {
            valid: false,
            key: fieldName,
            message: qsTr("Invalid " + fieldName)
        }
    }
    return { valid: true }
}
  1. 错误处理:
// 统一错误处理机制
function handleError(errorKey, errorMsg) {
    root.errorKey = errorKey
    root.errorMsg = errorMsg
    return false
}

这些改进建议主要围绕:

  1. 提高代码复用性
  2. 增强错误处理
  3. 提升代码安全性
  4. 优化性能

总体来说,这次变更是积极的,提高了代码的健壮性和可维护性。建议采纳上述改进建议以进一步提升代码质量。

@deepin-ci-robot
Copy link

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@caixr23 caixr23 merged commit f0efed2 into linuxdeepin:master Dec 10, 2025
16 of 18 checks passed
@caixr23 caixr23 deleted the BUG-312351 branch December 10, 2025 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants