Skip to content

Fall back for invalid Node interface port IDs - #520

Open
shin4141 wants to merge 1 commit into
sony:masterfrom
shin4141:codex/sony-496-port-id-fallback
Open

Fall back for invalid Node interface port IDs#520
shin4141 wants to merge 1 commit into
sony:masterfrom
shin4141:codex/sony-496-port-id-fallback

Conversation

@shin4141

Copy link
Copy Markdown

Summary

  • use the repository's existing 00-00-00-00-00-00 fallback when a Node interface port ID cannot be represented in the IS-04 six-octet lowercase-hyphen form
  • leave valid port IDs unchanged
  • keep host discovery and interface membership unchanged

Fixes #496.

Why

Tunnel and virtual interfaces may expose non-6-octet link-layer addresses. Since interfaces[].port_id requires the IS-04 six-octet lowercase-hyphen form, those values can make the Node resource schema-invalid. This change addresses the invalid port_id path reported in #496 by applying the existing null-address fallback at serialization.

Verification

  • valid lowercase-hyphen port ID remains unchanged
  • empty, 4/5/7-octet, malformed-hex, uppercase, and colon-separated inputs use the fallback
  • focused tests: 3 test cases / 8 assertions
  • affected NodeInterface tests: 6 test cases / 21 assertions
  • full native suite: 186 test cases / 2597 assertions
  • git diff --check

Scope

The regression uses controlled inputs and does not claim a Linux tunl0 end-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.

@lo-simon lo-simon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you, @shin4141, for your contribution. I have some suggestions to simplify the port ID validation and extend the test for various malformed port IDs.

@@ -1,3 +1,3 @@
#include "nmos/node_interfaces.h"

#include <boost/range/adaptor/transformed.hpp>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include <boost/range/adaptor/transformed.hpp>
#include "bst/regex.h"
#include "cpprest/basic_utils.h"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

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.

Node registration fails when host has tunnel/virtual interfaces with non-MAC port_id

2 participants