Skip to content

Network Namespace Improvements - #2101

Merged
Emantor merged 2 commits into
labgrid-project:masterfrom
SmithChart:netns-improvements
Dec 1, 2026
Merged

Emantor merged 2 commits into
labgrid-project:masterfrom
SmithChart:netns-improvements

Conversation

@SmithChart

@SmithChart SmithChart commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Description

This is a combination of two (more or less unrelated) changes, both in the RawNetworkInterface part of labgrid:

agents/netns: set address before bringing the interface up

By setting the address first and then setting the interface up MAC address and IPv6 link-local address match. This makes logs easier to read since it matches the expectation.
This is mainly a quality-of-life improvement.

helpers/labgrid-raw-interface: fix race in macvtap naming

This addresses a race between checking and using of available interface names. Setup of the namespaces can fail with multiple processes setting up forwarding at the same time.

Checklist

  • Documentation for the feature
  • Tests for the feature
  • Release notes added
  • The arguments and description in doc/configuration.rst have been updated
  • Add a section on how to use the feature to doc/usage.rst
  • Add a section on how to use the feature to doc/development.rst
  • PR has been tested

Tested in my homelab with three test suites in parallel running on three different targets.
In about 20 runs I did not observe any race.

  • Man pages have been regenerated

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.1%. Comparing base (b6ae8a9) to head (87b1718).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/util/agents/netns.py 0.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #2101     +/-   ##
========================================
- Coverage    66.1%   66.1%   -0.1%     
========================================
  Files         194     194             
  Lines       16204   16204             
========================================
- Hits        10724   10716      -8     
- Misses       5480    5488      +8     
Flag Coverage Δ
3.11 66.1% <0.0%> (-0.1%) ⬇️
3.12 66.1% <0.0%> (ø)
3.13 66.0% <0.0%> (-0.1%) ⬇️
3.14 66.0% <0.0%> (-0.1%) ⬇️
3.15 66.0% <0.0%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ozan956 ozan956 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me!

You can also add a release note to this PR. We recently switched to the reno. See -> https://labgrid.readthedocs.io/en/latest/development.html#workflow

If the change needs a release note (e.g. it fixes a bug, adds a new feature, requires integration, etc.), a release note should be added using reno new SLUG, where SLUG is a descriptive title of the change (e.g. add-foo-driver). Edit the resulting YAML file generated by reno to describe the change.

Emantor
Emantor previously approved these changes Dec 1, 2026

@Emantor Emantor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes look good, thanks. Do you want to add release notes or do you want to leave that to us?

@Emantor Emantor added fix pick to stable Needs a pick to the latest stable branch labels Dec 1, 2026
@Emantor Emantor self-assigned this Dec 1, 2026
@SmithChart

SmithChart commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

If you think this should be in the release notes, I'll prepare a reno-file.

Reno-release notes added.

When bringing the tap-interface up before setting the MAC-address the
kernel will assign a random MAC address to the interface and use it as
base for the IPv6 link-local address. This means that the IPv6
link-local address and the MAC address differ.

By setting the address first and then setting the interface up MAC
address and IPv6 link-local address match.
This makes logs easier to read since it matches the expectation.
Also the address does not change in case IPv6 addresses on the interface
were to be reset.

Signed-off-by: Chris Fiege <chris@tinyhost.de>
With the previous implementation multiple processes creating namespaces
at once (e.g. when running multiple test suites in parallel) could lead
to a race between checking and using of names.

This does not happen often, but failed namespace setups with
    RTNETLINK answers: File exists
error messages could be observed.
Starting the test runs staggered by a few seconds worked around this
issue, hinting at the race.

Instead of searching for a free name use the PID of the process to
generate a unique name.
Since the script already removes interfaces where the setup fails
half-way it is very unlikely that the name already exists.

This changes the name of the temporary interface from `macvtap<N>` to
`lgmvtap<pid>`. The name in the namespace is still `macvtap0`.

Additionally let the try-except-block cover some more statements that
could, in theory, go wrong, to reduce the chance of a leftover interface
in the root namespace.

Signed-off-by: Chris Fiege <chris@tinyhost.de>
@Emantor
Emantor merged commit 991408a into labgrid-project:master Dec 1, 2026
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix pick to stable Needs a pick to the latest stable branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants