Skip to contentSkip to conversation

netns: export get_net_ns_by_id()

PATCH In review Sergey Ryazanov 4 participants 6 messages May 12, 2021 – May 17, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netns: export get_net_ns_by_id()

No one loadable module is able to obtain netns by id since the corresponding function has not been exported. Export it to be able to use netns id API in loadable modules too as already done for peernet2id_alloc().

---
 net/core/net_namespace.c | 1 +
 1 file changed, 1 insertion(+)
net/core/net_namespace.c +1 -0
index 43b6ac4c4439..0414406ed664 100644
@@ -306,6 +306,7 @@ struct net *get_net_ns_by_id(const struct net *net, int id)
 
 	return peer;
 }
+EXPORT_SYMBOL_GPL(get_net_ns_by_id);
 
 /*
  * setup_net runs the initializers for the network namespace object.
Signature · 1 line
2.26.3
maintainer
#1 lore raw
Quoted 4 lines · On Thu, 13 May 2021 00:29:56 +0300 Sergey Ryazanov wrote:

No one loadable module is able to obtain netns by id since the corresponding function has not been exported. Export it to be able to use netns id API in loadable modules too as already done for peernet2id_alloc().

peernet2id_alloc() is used by OvS, what's the user for get_net_ns_by_id()?

#2 lore raw
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 13 May 2021 00:29:56 +0300 Sergey Ryazanov wrote:

No one loadable module is able to obtain netns by id since the corresponding function has not been exported. Export it to be able to use netns id API in loadable modules too as already done for peernet2id_alloc().

peernet2id_alloc() is used by OvS, what's the user for get_net_ns_by_id()?

There are currently no active users of get_net_ns_by_id(), that is why I did not add a "Fix" tag. Missed function export does not break existing code in any way.

On the other hand netns id API is incomplete without this export. You have no way to write and test a code that uses netns id API without manual kernel patching and rebuilding. This is annoying, but could be trivially fixed.

Accounting for the fact that this change is trivial, closer to a fix than to a new functionality, I prefered net tree over the net-next tree. This way I expect the new API to reach mainstream distros faster than over 5 years :)

Signature · 1 line
Sergey
#3 lore raw
Quoted 7 lines · Sergey Ryazanov
Quoted 6 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 13 May 2021 00:29:56 +0300 Sergey Ryazanov wrote:

No one loadable module is able to obtain netns by id since the corresponding function has not been exported. Export it to be able to use netns id API in loadable modules too as already done for peernet2id_alloc().

Quoted 5 lines
Quoted 1 line

peernet2id_alloc() is used by OvS, what's the user for get_net_ns_by_id()?

There are currently no active users of get_net_ns_by_id(), that is why I did not add a "Fix" tag. Missed function export does not break existing code in any way.

It is against kernel rule to do not expose APIs, even internal to the kernel, without real users. There are many patches every cycle that remove such EXPORT_*()s.

EXPORT_*() creates extra entries in Module.symvers and can be seen as unnecessary namespace pollution.

Thanks

#4 lore raw

Hello Leon,

Quoted 14 lines · Leon Romanovsky
Quoted 7 lines · Sergey Ryazanov
Quoted 6 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 13 May 2021 00:29:56 +0300 Sergey Ryazanov wrote:

No one loadable module is able to obtain netns by id since the corresponding function has not been exported. Export it to be able to use netns id API in loadable modules too as already done for peernet2id_alloc().

Quoted 5 lines
Quoted 1 line

peernet2id_alloc() is used by OvS, what's the user for get_net_ns_by_id()?

There are currently no active users of get_net_ns_by_id(), that is why I did not add a "Fix" tag. Missed function export does not break existing code in any way.

Quoted 5 lines

It is against kernel rule to do not expose APIs, even internal to the kernel, without real users. There are many patches every cycle that remove such EXPORT_*()s.

EXPORT_*() creates extra entries in Module.symvers and can be seen as unnecessary namespace pollution.

Ok, I got it. Maintainers do not like uncontrollable API experiments :) I have no more arguments and I give up. Jakub, please drop this patch.

BTW, for those who might be interested in experimenting with netnsid. I found another way to search netns by its id without the kernel rebuild. get_net_ns_by_id() is a simple container for the idr_found() invocation, which is wrapped with the RCU lock. So it is no big deal to implement this function locally to a module.

--
Sergey

#5 lore raw
In reply to Leon Romanovsky

Le 16/05/2021 à 13:05, Leon Romanovsky a écrit :

Quoted 8 lines · Sergey Ryazanov
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Thu, 13 May 2021 00:29:56 +0300 Sergey Ryazanov wrote:
Quoted 4 lines

No one loadable module is able to obtain netns by id since the corresponding function has not been exported. Export it to be able to use netns id API in loadable modules too as already done for peernet2id_alloc().

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

peernet2id_alloc() is used by OvS, what's the user for get_net_ns_by_id()?

There are currently no active users of get_net_ns_by_id(), that is why I did not add a "Fix" tag. Missed function export does not break existing code in any way.

It is against kernel rule to do not expose APIs, even internal to the kernel,

Yep, there was no internal user, it's why I didn't add this EXPORT_*() at the beginning.

Regards,
Nicolas