jow- / ucode

JavaScript-like language with optional templating
ISC License
90 stars 30 forks source link

rtnl: add IFLA_IF_NETNSID for operating in other namespaces #171

Closed pktpls closed 1 year ago

pktpls commented 1 year ago

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 commented 1 year ago

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- commented 1 year ago

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- commented 1 year ago

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

pktpls commented 1 year ago

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.

pktpls commented 1 year ago

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.