-
Notifications
You must be signed in to change notification settings - Fork 745
[network] Bridges with long names use hash suffix #4422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
5c52c7d to
a6bb1bd
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
a6bb1bd to
5e437ad
Compare
5e437ad to
4a070df
Compare
ricab
left a comment
There was a problem hiding this 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.
| 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); |
There was a problem hiding this comment.
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.
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.
create_bridge_withto use the newgenerate_bridge_namefunction, replacing the previous simple truncation method.QCryptographicHashincludes to bothbackend_utils.cppandtest_backend_utils.cppto support the new hashing logic for bridge name generation.Originally:
eth123456789abc→br-eth123456789(truncated to 15 chars)eth123456789xyz→br-eth123456789(same name - collision)With the fix:
eth123456789abc→br-eth12345-8f9(unique hash suffix)eth123456789xyz→br-eth12345-a2c(different hash - no collision)Short names (unchanged, fully readable):
eth0→br-eth0wlan0→br-wlan0enp0s3→br-enp0s3resolves #2158