Skip to content
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

rtnl: add IFLA_IF_NETNSID for operating in other namespaces #171

Merged
merged 2 commits into from
Sep 25, 2023

Conversation

pktpls
Copy link
Contributor

@pktpls pktpls commented Sep 11, 2023

IFLA_IF_NETNSID allows RTM_GETLINK et. al. to operate in other network namespaces. For example I use it to check if a given interface exists in a given namespace.

  let reply = rtnl.request(rtnl.const.RTM_GETLINK, rtnl.const.NLM_F_REQUEST, {
    "ifname": ifname,
    "if_netnsid": nsid,
  });

The nsid is set with ip netns set <nsname> <nsid> and obtained with ip -j netns list-id.

@pktpls
Copy link
Contributor Author

pktpls commented Sep 11, 2023

Btw I noticed that the IFLA_NETNS_PID spec attribute is commented out, I assume because it doesn't work yet? I think it has a typo and should be called IFLA_NET_NS_PID, there's also an equivalent for /var/run/netns/ file descriptors called IFLA_NET_NS_FD.

@jow-
Copy link
Owner

jow- commented Sep 12, 2023

I don't exactly remember why I left this attribute commented out, I think because I thought it entails more work than just passing through the integer value as-is, but maybe I was mistaken.

If you have a use-case for it and are able to test it out then I'd appreciate a patch implementing it.

@jow-
Copy link
Owner

jow- commented Sep 12, 2023

Btw, upstream renamed IFLA_IF_NETNSID to IFLA_TARGET_NETNSID - maybe it makes sense to go with the new attribute name right away?

@pktpls
Copy link
Contributor Author

pktpls commented Sep 12, 2023

Ah yes I noticed that, but thought it was the other way around. It makes sense, I'll test and push.

And I do actually have a use-case for IFLA_NET_NS_PID - moving an interface from a custom namespace into the default namespace, which is usually identified by PID 1.

I'll get back to you with that.

Signed-off-by: Packet Please <pktpls@systemli.org>
Signed-off-by: Packet Please <pktpls@systemli.org>
@pktpls
Copy link
Contributor Author

pktpls commented Sep 22, 2023

Okay let's leave it at only IFLA_TARGET_NETNSID for now :-)

I noticed that the combination of IFLA_TARGET_NETNSID and IFLA_NET_NS_PID (or _FD) actually isn't supported yet (which is what I wanted to try and test). There was a kernel patch proposed in 2019 to allow it, but it stalled.

But I will probably eventually get to testing IFLA_NET_NS_PID and _FD on their own.

@jow- jow- merged commit 9f9959c into jow-:master Sep 25, 2023
@pktpls pktpls deleted the rtnl-netnsid branch September 25, 2023 14:34
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