Fall back for invalid Node interface port IDs - #520
Open
shin4141 wants to merge 1 commit into
Open
Conversation
lo-simon
requested changes
Aug 21, 2026
| @@ -1,3 +1,3 @@ | |||
| #include "nmos/node_interfaces.h" | |||
|
|
|||
| #include <boost/range/adaptor/transformed.hpp> | |||
Collaborator
There was a problem hiding this comment.
Suggested change
| #include <boost/range/adaptor/transformed.hpp> | |
| #include "bst/regex.h" | |
| #include "cpprest/basic_utils.h" |
Collaborator
There was a problem hiding this comment.
It is better to use regex to validate port_id, see the suggestion in is_valid_node_interfaces_port_id()
Comment on lines
+23
to
+41
| bool is_valid_node_interfaces_port_id(const utility::string_t& port_id) | ||
| { | ||
| if (17 != port_id.size()) return false; | ||
|
|
||
| for (size_t index = 0; index < port_id.size(); ++index) | ||
| { | ||
| const auto character = port_id[index]; | ||
| if (2 == index % 3) | ||
| { | ||
| if (U('-') != character) return false; | ||
| } | ||
| else if (!((U('0') <= character && character <= U('9')) || (U('a') <= character && character <= U('f')))) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| bool is_valid_node_interfaces_port_id(const utility::string_t& port_id) | |
| { | |
| if (17 != port_id.size()) return false; | |
| for (size_t index = 0; index < port_id.size(); ++index) | |
| { | |
| const auto character = port_id[index]; | |
| if (2 == index % 3) | |
| { | |
| if (U('-') != character) return false; | |
| } | |
| else if (!((U('0') <= character && character <= U('9')) || (U('a') <= character && character <= U('f')))) | |
| { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| // Port ID must be a MAC address, strictly following the lowercase hexadecimal format and separated by hyphens (not colons) | |
| // It should match the regular expression pattern ^([0-9a-f]{2}-){5}([0-9a-f]{2})$ | |
| // see https://specs.amwa.tv/is-04/branches/v1.2.x/APIs/schemas/with-refs/node.html | |
| bool is_valid_node_interfaces_port_id(const utility::string_t& port_id) | |
| { | |
| static const bst::regex port_id_regex(R"(([0-9a-f]{2}-){5}[0-9a-f]{2}$)"); | |
| return bst::regex_match(utility::us2s(port_id), port_id_regex); | |
| } |
Comment on lines
+80
to
+85
| U("00-00-00-00"), | ||
| U("00-00-00-00-00"), | ||
| U("00-00-00-00-00-00-00"), | ||
| U("gg-00-00-00-00-00"), | ||
| U("AA-BB-CC-DD-EE-FF"), | ||
| U("00:00:00:00:00:00") |
Collaborator
There was a problem hiding this comment.
Suggested change
| U("00-00-00-00"), | |
| U("00-00-00-00-00"), | |
| U("00-00-00-00-00-00-00"), | |
| U("gg-00-00-00-00-00"), | |
| U("AA-BB-CC-DD-EE-FF"), | |
| U("00:00:00:00:00:00") | |
| // Uppercase MAC addresses | |
| U("AA-BB-CC-DD-EE-FF"), | |
| U("AA-bb-cc-dd-ee-ff"), | |
| // Colon-separated MAC addresses | |
| U("00:00:00:00:00:00"), | |
| U("aa:bb:cc:dd:ee:ff"), | |
| U("12:34:56:78:9a:bc"), | |
| // Various malformed MAC addresses | |
| // Wrong length | |
| U("00-00-00-00"), | |
| U("00-00-00-00-00"), | |
| U("00-00-00-00-00-00-00"), | |
| U("aa-bb-cc-dd-ee"), | |
| U("aa-bb-cc-dd-ee-ff-gg"), | |
| // Invalid hex characters | |
| U("gg-00-00-00-00-00"), | |
| U("aa-bb-cc-dd-ee-GG"), | |
| // Missing separators | |
| U("aabbccddeeff"), | |
| U("00000000000000"), | |
| // Wrong separator positions | |
| U("aab-bcc-dde-eff"), | |
| U("aa-bbccdd-ee-ff"), | |
| // Mixed separators | |
| U("aa:bb-cc-dd-ee-ff"), | |
| U("aa-bb:cc:dd-ee-ff"), | |
| // Extra characters | |
| U(" aa-bb-cc-dd-ee-ff"), | |
| U("aa-bb-cc-dd-ee-ff "), | |
| U("aa-bb-cc-dd-ee-ff-"), | |
| U("-aa-bb-cc-dd-ee-ff"), | |
| // Special characters | |
| U("aa.bb.cc.dd.ee.ff"), | |
| U("aa_bb_cc_dd_ee_ff"), | |
| // Empty octets | |
| U("--bb-cc-dd-ee-ff"), | |
| U("aa--cc-dd-ee-ff"), | |
| // Single character octets | |
| U("a-b-c-d-e-f"), | |
| U("0-0-0-0-0-0"), | |
| // Three character octets | |
| U("aaa-bbb-ccc-ddd-eee-fff") |
Collaborator
There was a problem hiding this comment.
Extend the test to cover various malformed port IDs
- Wrong lengths (too short/too long)
- Invalid hex characters
- Missing/wrong separators
- Mixed separators
- Extra whitespace/characters
- Special characters
- Empty/single/triple character octets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
00-00-00-00-00-00fallback when a Node interface port ID cannot be represented in the IS-04 six-octet lowercase-hyphen formFixes #496.
Why
Tunnel and virtual interfaces may expose non-6-octet link-layer addresses. Since
interfaces[].port_idrequires the IS-04 six-octet lowercase-hyphen form, those values can make the Node resource schema-invalid. This change addresses the invalidport_idpath reported in #496 by applying the existing null-address fallback at serialization.Verification
git diff --checkScope
The regression uses controlled inputs and does not claim a Linux
tunl0end-to-end reproduction. This PR does not claim a maintainer preference for normalize over exclude, Sony adoption or acceptance, or cross-platform execution beyond the tested macOS arm64 / Apple clang 21 environment.