libct: fix netDevices rename with %d template by samridh10exe · Pull Request #5554 · opencontainers/runc · GitHub
Skip to content

libct: fix netDevices rename with %d template - #5554

Open
samridh10exe wants to merge 2 commits into
opencontainers:mainfrom
samridh10exe:samridh/netdev-name-template
Open

samridh10exe wants to merge 2 commits into
opencontainers:mainfrom
samridh10exe:samridh/netdev-name-template

Conversation

@samridh10exe

Copy link
Copy Markdown

The runtime-spec allows a netDevices name such as eth%d, in which case the kernel replaces %d with the lowest number not yet used in the target network namespace. runc passed the template to the kernel as is, but then looked up the moved interface by the template itself, so creating the container failed with link not found for interface eth%d.

When the new name has %d, record the interface names in the target namespace before the move, and afterwards pick the new interface whose name matches the template. Add integration tests for both a new and a precreated network namespace (with the first name already taken).

Tested with make localintegration TESTPATH=/netdev.bats: the two new tests fail on main and all 11 pass with this change.

Fixes #5548

The runtime-spec allows a netDevices name such as "eth%d", in which case
the kernel replaces %d with the lowest number not yet used in the target
network namespace. runc passed the template to the kernel as is, but
then looked up the moved interface by the template itself, so creating
the container failed with "link not found for interface eth%d".

When the new name has %d, record the interface names in the target
namespace before the move, and afterwards pick the new interface whose
name matches the template. Add integration tests for both a new and a
precreated network namespace (with the first name already taken).

Fixes: opencontainers#5548
Signed-off-by: Samridh <109811970+samridh10exe@users.noreply.github.com>
@kolyshkin kolyshkin added the llm-generated Used to tag LLM-generated issues or PRs, which some maintainers may choose to de-prioritise. label Oct 22, 2026
The previous commit found the moved interface by diffing the names in
the target network namespace before and after the move. When two
containers move devices into the same network namespace at the same
time, both can see the other's new interface as new, and both pick the
same one.

Instead, move the device under a unique temporary name, look it up by
that name, and then rename it with the template inside the target
namespace, where the kernel resolves %d. The link is then read back by
its ifindex, which does not change while it stays in that namespace.

Signed-off-by: Samridh <109811970+samridh10exe@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-generated Used to tag LLM-generated issues or PRs, which some maintainers may choose to de-prioritise.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runc fails creation when netDevices.name contains the supported %d template

2 participants