Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@RaimoNiskanen
Copy link
Contributor

This PR adds namespace support to inet:getifaddrs/ and friends.

The namespace option is as far as I know only valid on Linux that has got a setns() OS API function.

This PR changes the signature of the previously undocumented function inet:getifaddrs/1 to accept an option list [{netns,NS}]. Before this change it accepted a port that is an UDP socket that was used to access inet_drv.c, and it was an internal function not used anywhere in OTP.

A question is whether to keep the legacy function variant. Has anyone used it?

I think it is safest to keep the legacy function variant. I changed the documentation format to the style not using the type spec, and thereby I could document only the new option list variant. The type spec specifies the complete implemented function, though.

Some more undocumented functions that is inet:getif/1,getiflist/1,ifget/2,ifset/2 were changed in the process, for completeness...

Also implement the same option for the legacy undocumented functions
inet:getif/1,getiflist/1,ifget/2,ifset/2.

The arity 1 functions had before this change got signatures that
took a socket port that was used to do the needed syscall, so now
the signature was extended to also take an option list with the
only supported option {netns,Namespace}.  The Socket argument
variant remains unsupported.

For inet:getifaddrs/1 the documentation file was changed to old
style function name definition so be able to hide the Socket
argument variant that is visible in the type spec.

The arity 2 functions had got an option list as second argument.
This list had to be partitioned into one list for the namespace
option(s) and the other for the rest.

The namespace option list was then fed to the already existing
namespace support for socket opening, which places the socket
in a namespace and hence made all these functions that in
inet_drv.c used getsockopt() work without change.

The functions that used getifaddrs() in inet_drv.c had to be
changed in inet_drv.c to swap namespaces around the
getifaddrs() syscall.  This functionality was separated into
a new function call_getifaddrs().
@RaimoNiskanen RaimoNiskanen self-assigned this Oct 3, 2018
@RaimoNiskanen RaimoNiskanen added the team:PS Assigned to OTP team PS label Oct 3, 2018
@RaimoNiskanen RaimoNiskanen merged commit ac243ae into erlang:maint Oct 12, 2018
@RaimoNiskanen RaimoNiskanen deleted the raimo/getifaddrs-netns/ERIERL-189/OTP-15121 branch October 12, 2018 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:PS Assigned to OTP team PS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants