Skip to content

Conversation

@levkropp
Copy link
Contributor

@levkropp levkropp commented Oct 9, 2025

This pull request introduces a new strategy for generating bridge names in the Linux backend to ensure uniqueness when interface names are long by truncating long interface names and appending a short hash. This ensures that bridge names are both readable and unique.

  • Updated the bridge creation logic in create_bridge_with to use the new generate_bridge_name function, replacing the previous simple truncation method.
  • Added QCryptographicHash includes to both backend_utils.cpp and test_backend_utils.cpp to support the new hashing logic for bridge name generation.

Originally:

  • eth123456789abcbr-eth123456789 (truncated to 15 chars)
  • eth123456789xyzbr-eth123456789 (same name - collision)

With the fix:

  • eth123456789abcbr-eth12345-8f9 (unique hash suffix)
  • eth123456789xyzbr-eth12345-a2c (different hash - no collision)

Short names (unchanged, fully readable):

  • eth0br-eth0
  • wlan0br-wlan0
  • enp0s3br-enp0s3

resolves #2158

@levkropp levkropp force-pushed the injective-bridge-names branch from 5c52c7d to a6bb1bd Compare October 9, 2025 17:02
@codecov
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.39%. Comparing base (96a02d6) to head (4a070df).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4422   +/-   ##
=======================================
  Coverage   89.39%   89.39%           
=======================================
  Files         253      253           
  Lines       16457    16468   +11     
=======================================
+ Hits        14711    14722   +11     
  Misses       1746     1746           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@levkropp levkropp force-pushed the injective-bridge-names branch from a6bb1bd to 5e437ad Compare October 15, 2025 19:49
@levkropp levkropp force-pushed the injective-bridge-names branch from 5e437ad to 4a070df Compare October 16, 2025 13:36
@levkropp levkropp marked this pull request as ready for review October 16, 2025 14:10
@levkropp levkropp requested a review from ricab October 16, 2025 14:10
Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

The implementation looks good, but I don't think we should copy paste the code into tests. It shouldn't be hard to pick up and adapt.

Comment on lines -189 to +216
return (QString{"br-"} + child).left(15);
// This must match the logic in generate_bridge_name() in backend_utils.cpp
static constexpr auto base_name = "br-";
static constexpr auto base_name_len = 3;
static constexpr auto max_bridge_name_len = 15;

auto full_name = QString("%1%2").arg(base_name).arg(child);

// If it fits within the limit, use it as-is (most readable)
if (full_name.length() <= max_bridge_name_len)
return full_name;

// Otherwise, truncate and add hash suffix for uniqueness
static constexpr auto hash_suffix_len = 3;
static constexpr auto separator_len = 1;
constexpr auto max_iface_portion =
max_bridge_name_len - base_name_len - separator_len - hash_suffix_len;

// Generate a short hash of the full interface name to ensure uniqueness
QCryptographicHash hash(QCryptographicHash::Md5);
hash.addData(child, strlen(child));
auto hash_result = hash.result().toHex();
auto hash_suffix = hash_result.left(hash_suffix_len);

// Use as much of the interface name as possible for readability
auto iface_portion = QString(child).left(max_iface_portion);

return QString("%1%2-%3").arg(base_name).arg(iface_portion).arg(hash_suffix);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is basically a repetition of the same code. I think test expectations should be adapted instead.

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.

Mapping of interface name to bridge name not injective

3 participants