Skip to content

fix(network): prefer permanent MAC address from hwinfo#672

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
tianming-1996:fix/prefer-permanent-mac-address-363471
May 29, 2026
Merged

fix(network): prefer permanent MAC address from hwinfo#672
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
tianming-1996:fix/prefer-permanent-mac-address-363471

Conversation

@tianming-1996
Copy link
Copy Markdown

@tianming-1996 tianming-1996 commented May 29, 2026

Prefer the permanent hardware address when parsing network device info.

解析网卡信息时优先使用永久硬件地址。

Fall back to the current MAC address when the permanent address is empty or zero.

当永久地址为空或全零时,回退使用当前MAC地址。

Log: 修复网卡MAC地址显示优先级
PMS: Bug: https://pms.uniontech.com/bug-view-363471.html
Influence: 网卡详情页优先显示永久物理地址,永久地址无效时显示当前MAC地址。

Summary by Sourcery

Prefer permanent hardware MAC addresses from hwinfo when populating network device info, falling back to the current MAC when the permanent address is missing or invalid.

Bug Fixes:

  • Ensure network MAC address and unique ID use the permanent hardware address when available and non-zero.
  • Fall back to the current hardware MAC address when the permanent address is empty or all zeros to avoid invalid display.

Tests:

  • Add unit tests covering preference of permanent MAC address and fallback behavior when it is missing or all zeros.

@deepin-ci-robot
Copy link
Copy Markdown

Hi @tianming-1996. Thanks for your PR. 😃

@deepin-ci-robot
Copy link
Copy Markdown

Hi @tianming-1996. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 29, 2026

Reviewer's Guide

Adjusts DeviceNetwork::setInfoFromHwinfo to prefer the permanent hardware MAC address when available and non-zero, falling back to the current MAC, and adds unit tests to verify the new precedence rules.

Flow diagram for MAC address selection in setInfoFromHwinfo

flowchart TD
    A[setInfoFromHwinfo receives mapInfo] --> B[setAttribute mapInfo Permanent_HW_Address m_MACAddress]
    B --> C{m_MACAddress == 00:00:00:00:00:00?}
    C -- Yes --> D[clear m_MACAddress]
    C -- No --> E[keep m_MACAddress]
    D --> F[setAttribute mapInfo HW_Address m_MACAddress optional:false]
    E --> F
    F --> G[setAttribute mapInfo Permanent_HW_Address m_UniqueID]
    G --> H[setAttribute mapInfo SysFS_Device_Link m_SysPath]
    H --> I[setAttribute mapInfo Driver m_Driver]
Loading

File-Level Changes

Change Details Files
Update MAC address selection logic in setInfoFromHwinfo to prefer permanent hardware address with a fallback to current MAC when needed.
  • Change primary MAC population to read from 'Permanent HW Address' into m_MACAddress.
  • Clear m_MACAddress when the permanent hardware address is all zeros to mark it invalid.
  • Re-populate m_MACAddress from 'HW Address' without overwriting an already valid permanent address by disabling the default behavior in setAttribute.
  • Keep m_UniqueID bound to 'Permanent HW Address' so the permanent address remains the canonical unique ID.
deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp
Add unit tests covering MAC address preference and fallback behavior.
  • Add a test ensuring permanent hardware address is preferred for m_MACAddress and m_UniqueID when present.
  • Add a test verifying m_MACAddress falls back to the current 'HW Address' when no permanent address is provided.
  • Add a test verifying fallback to 'HW Address' when the permanent address is all zeros.
deepin-devicemanager/tests/src/DeviceManager/ut_devicenetwork.cpp

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
Copy Markdown

@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 - I've left some high level feedback:

  • In setInfoFromHwinfo, m_UniqueID is still sourced directly from "Permanent HW Address" even when you’ve implemented fallback logic for m_MACAddress; consider deriving m_UniqueID from the already-resolved m_MACAddress (or applying the same fallback logic) so the two stay consistent in cases where the permanent address is missing or zero.
  • The all-zero MAC check ("00:00:00:00:00:00") is done with a literal string comparison; if setAttribute can introduce case differences, extra whitespace, or different delimiter styles, it may be safer to normalize the MAC string before comparison or centralize the "is zero MAC" check in a helper.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `setInfoFromHwinfo`, `m_UniqueID` is still sourced directly from "Permanent HW Address" even when you’ve implemented fallback logic for `m_MACAddress`; consider deriving `m_UniqueID` from the already-resolved `m_MACAddress` (or applying the same fallback logic) so the two stay consistent in cases where the permanent address is missing or zero.
- The all-zero MAC check (`"00:00:00:00:00:00"`) is done with a literal string comparison; if `setAttribute` can introduce case differences, extra whitespace, or different delimiter styles, it may be safer to normalize the MAC string before comparison or centralize the "is zero MAC" check in a helper.

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.

Prefer the permanent hardware address when parsing network device info.

解析网卡信息时优先使用永久硬件地址。

Fall back to the current MAC address when the permanent address is empty or zero.

当永久地址为空或全零时,回退使用当前MAC地址。

Log: 修复网卡MAC地址显示优先级
PMS: Bug: https://pms.uniontech.com/bug-view-363471.html
Influence: 网卡详情页优先显示永久物理地址,永久地址无效时显示当前MAC地址。
@tianming-1996 tianming-1996 force-pushed the fix/prefer-permanent-mac-address-363471 branch from 9c91f8d to 6e35e8f Compare May 29, 2026 09:02
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: max-lvs, tianming-1996

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

@tianming-1996
Copy link
Copy Markdown
Author

/merge

@deepin-bot deepin-bot Bot merged commit 074f581 into linuxdeepin:develop/eagle May 29, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants