Skip to content

Network Namespace Implementation#1805

Merged
jluebbe merged 8 commits intolabgrid-project:masterfrom
JoshuaWatt:netns
Apr 1, 2026
Merged

Network Namespace Implementation#1805
jluebbe merged 8 commits intolabgrid-project:masterfrom
JoshuaWatt:netns

Conversation

@JoshuaWatt
Copy link
Copy Markdown
Contributor

Description

Adds support for network namespaces that can be used to give a client access to a NetworkInterface on an exporter. The data is streamed between a tap on client and exporter over SSH

Checklist

  • Documentation for the feature
  • Tests for the feature
  • 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
  • Man pages have been regenerated

JoshuaWatt and others added 4 commits March 14, 2026 21:20
Add support for Target to be used in a `with` statement. When the
statement exits, the target will automatically cleanup

Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
Add support for network namespaces that can be used to give a client
access to a NetworkInterface on an exporter. The data is streamed over
SSH between a tap in the netns on the client and a macvtap on the
exporter.

An agent process is used to initialize the user and network namespaces
and to keep them open for further operations.

This is not optimised for high throughput or low latency, but for
flexibility and ease-of-use. For cases where performance is more
important, this could be extended to support a macvlan interface in a
network namespace on the exporter.

The approach is still a bit experimental, so we might need to change
things in incompatible ways.

Co-developed-by: Joshua Watt <Joshua.Watt@garmin.com>
Co-developed-by: Rouven Czerwinski <rouven.czerwinski@linaro.org>
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
This makes it easy to enter a netns from multiple shells.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
@jluebbe
Copy link
Copy Markdown
Member

jluebbe commented Mar 14, 2026

@JPEWdev As discussed via matrix, I've squashed our commits. I've squashed some minor fixes and doc updates as well. Support for socks5 is still as separate commits.

The tests fail because autodoc can't import the netns agent (due to the missing s2py globals in s2py = s2py). Do you have a better idea to handle that?

Also, the netns tests are currently skipped in CI, as we seem to be missing privileges for the mount namespace. Perhaps we can adjust the workflow configuration to allow that.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 14, 2026

Codecov Report

❌ Patch coverage is 15.60694% with 438 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.8%. Comparing base (5e74a80) to head (b07ef1c).
⚠️ Report is 13 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/tapfwd.py 0.0% 142 Missing ⚠️
labgrid/util/agents/netns.py 0.0% 111 Missing ⚠️
labgrid/util/netns.py 33.5% 87 Missing ⚠️
labgrid/driver/rawnetworkinterfacedriver.py 16.4% 56 Missing ⚠️
labgrid/remote/client.py 7.4% 25 Missing ⚠️
labgrid/util/agent.py 31.8% 15 Missing ⚠️
labgrid/target.py 50.0% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1805     +/-   ##
========================================
- Coverage    46.7%   45.8%   -1.0%     
========================================
  Files         179     182      +3     
  Lines       14198   14718    +520     
========================================
+ Hits         6635    6743    +108     
- Misses       7563    7975    +412     
Flag Coverage Δ
3.10 45.8% <15.6%> (-1.0%) ⬇️
3.11 45.8% <15.6%> (-1.0%) ⬇️
3.12 45.8% <15.6%> (-1.0%) ⬇️
3.13 45.7% <15.6%> (-1.0%) ⬇️
3.14 45.7% <15.6%> (-1.0%) ⬇️

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

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

@JoshuaWatt
Copy link
Copy Markdown
Contributor Author

@JPEWdev As discussed via matrix, I've squashed our commits. I've squashed some minor fixes and doc updates as well. Support for socks5 is still as separate commits.

The tests fail because autodoc can't import the netns agent (due to the missing s2py globals in s2py = s2py). Do you have a better idea to handle that?

Probably just inline them instead of share them. I'll take a look

Also, the netns tests are currently skipped in CI, as we seem to be missing privileges for the mount namespace. Perhaps we can adjust the workflow configuration to allow that.

Using the definition from the agent module breaks documentation
building. Since these functions aren't very complicated, move them into
the module.

Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
Unprivledged user namespaces are required for the netns tests to run

Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
Removes creating a separate mount namespace with the network namespace.
The mount namespace is not technically required to use the networking
portion of the namespace, and it can fail depending on the mount
propagation settings of the system, which would require system
administration to fix.

Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
Updates the man pages for the new wrapper script

Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
@JoshuaWatt
Copy link
Copy Markdown
Contributor Author

@jluebbe Ok, it's working now. FYI, the reason for the unshare failure was two fold:

  1. There is a sysctl that needs to be set to allow unprivileged users to create user namespaces; I added this to the CI setup
  2. A mount can prevent itself from being shared into a new mount namespace, which causes a failure. I don't think there is a "reasonable" (that is, a way normal users can fix this without admin permissions) way for users to work around this, and I was always skeptical that the sysfs mount was even strictly required, so I removed it. Perhaps something that can be revisited later, but it's not needed ATM.

@jluebbe
Copy link
Copy Markdown
Member

jluebbe commented Apr 1, 2026

Thanks! The sysfs mount was needed to find the tap interface name in the namespace so that it could be opened. As we no longer need that, don't need to mount sysfs in the namespace.

@jluebbe jluebbe merged commit 3912486 into labgrid-project:master Apr 1, 2026
8 of 10 checks passed
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.

2 participants