Skip to content

nl80211: add wiphy network namespace support - #1203

Open
mbaragiola wants to merge 2 commits into
vishvananda:mainfrom
mbaragiola:feat/nl80211-wiphy-netns
Open

nl80211: add wiphy network namespace support#1203
mbaragiola wants to merge 2 commits into
vishvananda:mainfrom
mbaragiola:feat/nl80211-wiphy-netns

Conversation

@mbaragiola

@mbaragiola mbaragiola commented Jul 20, 2026

Copy link
Copy Markdown

Summary

Add Linux-only helpers for moving a wireless PHY to another network namespace through the nl80211 generic-netlink family.

This provides the dependency-layer API needed by containernetworking/plugins#957, where host-device currently cannot move wireless devices with RTM_SETLINK/LinkSetNsFd.

The implementation sends NL80211_CMD_SET_WIPHY_NETNS with:

  • NL80211_ATTR_WIPHY
  • NL80211_ATTR_NETNS_FD

Both package-level and Handle methods are provided, following existing netlink API patterns.

Testing

  • go build . — passed
  • go test ./nl — passed
  • go vet ./nl — passed
  • In-memory request serialization tests were added; no real wireless device or host networking is required.
  • The root package test suite is currently blocked by a pre-existing compile error in handle_retry_linux_test.go referencing the missing Handle.RetryInterrupted method; this change does not reference that symbol.

Related downstream integration: containernetworking/plugins#957

Summary by CodeRabbit

  • New Features

    • Added Linux support for moving a wireless device into a specified network namespace.
    • Introduced package-level and handle-based APIs to set the wireless device’s target namespace.
  • Tests

    • Added coverage to ensure namespace-change requests are validated for invalid inputs and are built with the expected netlink/genetlink command, flags, and attributes.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 03ffc56b-338e-44b7-942c-5cd992f94d22

📥 Commits

Reviewing files that changed from the base of the PR and between f9f83d1 and 8079d6b.

📒 Files selected for processing (2)
  • wiphy_linux.go
  • wiphy_linux_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • wiphy_linux.go

📝 Walkthrough

Walkthrough

Adds Linux support for moving a wireless PHY into a network namespace using an nl80211 generic netlink request containing the PHY identifier and namespace file descriptor, with package and handle APIs plus request-validation tests.

Changes

Wiphy network namespace operation

Layer / File(s) Summary
Build the nl80211 request
wiphy_linux.go
Defines the command and attribute constants and constructs the generic netlink request with the wiphy and network namespace file descriptor.
Expose and execute the operation
wiphy_linux.go, wiphy_linux_test.go
Adds package-level and handle methods, validates arguments, resolves the nl80211 family, executes the request with acknowledgement, and verifies request fields, attributes, and validation errors.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Handle.WiphySetNsFd
  participant nl80211
  participant Kernel
  Caller->>Handle.WiphySetNsFd: wiphy and netns fd
  Handle.WiphySetNsFd->>nl80211: resolve generic netlink family
  Handle.WiphySetNsFd->>nl80211: send SetWiphyNetns request with ACK
  nl80211->>Kernel: apply wiphy and netnsFD attributes
  Kernel-->>Handle.WiphySetNsFd: ACK or error
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding nl80211-based wiphy network namespace support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mbaragiola

Copy link
Copy Markdown
Author

Downstream integration draft: containernetworking/plugins#1274

That draft uses WiphySetNsFd for wireless host-device moves and is intentionally waiting on this API dependency.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@wiphy_linux.go`:
- Around line 27-38: Update Handle.WiphySetNsFd to validate wiphy and fd are
non-negative before calling newWiphySetNsFdRequest, returning an appropriate
error for invalid values. Add the required fmt import and preserve the existing
family lookup and request execution flow for valid inputs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 43d5fea8-e9fc-4a42-b5f8-a8f355070a82

📥 Commits

Reviewing files that changed from the base of the PR and between 4e35dc9 and f9f83d1.

📒 Files selected for processing (2)
  • wiphy_linux.go
  • wiphy_linux_test.go

Comment thread wiphy_linux.go
@mbaragiola

Copy link
Copy Markdown
Author

Addressed the CodeRabbit finding in 8079d6b:

  • WiphySetNsFd now rejects negative wiphy indices and namespace FDs before family lookup/request construction.
  • Added regression coverage for both invalid-argument cases.
  • Focused tests, build, nl tests, vet, and diff checks pass when excluding the repository's pre-existing handle_retry_linux_test.go compile failure.

The Linux CI failure in the previous run was that unrelated baseline error; macOS passed.

@mbaragiola

Copy link
Copy Markdown
Author

CI rerun after 8079d6b:

  • build-macos: passed
  • CodeRabbit: passed
  • Linux build: still fails before running the root package because handle_retry_linux_test.go:60 references the missing Handle.RetryInterrupted method. The same failure occurred on the previous commit and is unrelated to the two changed wiphy files.
  • Focused wiphy tests pass locally when that pre-existing broken test file is excluded temporarily.

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.

1 participant