Skip to content

[lib]: Add shared interface name validator - #4844

Closed
ashutosh-agrawal wants to merge 1 commit into
sonic-net:masterfrom
ashutosh-agrawal:fix/shared-interface-name-validation
Closed

ashutosh-agrawal wants to merge 1 commit into
sonic-net:masterfrom
ashutosh-agrawal:fix/shared-interface-name-validation

Conversation

@ashutosh-agrawal

@ashutosh-agrawal ashutosh-agrawal commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

What I did

Added a header-only swss::isValidIfname helper and focused unit tests for shared interface-name syntax validation.

The exact accepted format is:

  • Length is 1 through 15 bytes (< IFNAMSIZ).
  • Every byte is an ASCII letter, digit, underscore, period, or hyphen: [A-Za-z0-9_.-].
  • The complete name is not . or ...
  • The first character is not a hyphen.

There is no letter-first rule and no SONiC prefix requirement. Names such as 1Ethernet, _eth0, and .eth0 match the format. Interface category, parent existence, and naming conventions remain the responsibility of YANG and component-specific parsers.

Implementation and coverage: lib/ifname.h and tests/ifname_ut.cpp.

Why I did it

A shared helper gives SWSS components one interface-name syntax rule while leaving interface-category rules to the existing YANG models and component parsers.

Linux dev_valid_name and SONiC's YANG interface_name typedef provide the underlying length and naming constraints. Physical-interface and VLAN-subinterface semantics remain defined by sonic-interface.yang and sonic-vlan-sub-interface.yang.

How I verified it

Built and ran the focused tests in the Bookworm build environment:

[==========] 2 tests from 1 test suite ran.
[  PASSED  ] 2 tests.

The tests cover names that match the exact format and each nonmatching length, character, whole-name, and first-character case.

Details if related

Dependent draft PRs #4845, #4846, and #4847 are intentionally paused. After this helper merges, each consumer branch will be rebuilt from current master so its review diff contains only the dependent integration.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@ashutosh-agrawal
ashutosh-agrawal marked this pull request as ready for review August 26, 2026 05:18
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Provide a shared interface-name syntax check and focused unit coverage for accepted and rejected values.

Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@ashutosh-agrawal
ashutosh-agrawal force-pushed the fix/shared-interface-name-validation branch from cd8bfc8 to 2fbb87b Compare August 26, 2026 05:36
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread lib/ifname.h
// This validates interface-name syntax only. Category semantics remain in the
// YANG models and component-specific parsers. IFNAMSIZ includes the
// terminating NUL.
inline bool isValidIfname(const std::string &name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ashutosh-agrawal ashutosh-agrawal Aug 26, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, agreed. I audited the current isInterfaceNameValid() callers in sonic-utilities (PortChannel, VRF, VXLAN, and subinterface validation) against the stricter rule; their supported names continue to pass. The implementation now strengthens the existing function in sonic-swss-common and adds focused C++ and Python regression coverage, including current caller categories and the length boundaries. Replacement PR: sonic-net/sonic-swss-common#1240

@ashutosh-agrawal

Copy link
Copy Markdown
Member Author

Replaced by sonic-net/sonic-swss-common#1240

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