-
Notifications
You must be signed in to change notification settings - Fork 80
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
Setting network namespace #36
Comments
I tried the following snippet, but, bind function returns
Commands I have used to create namespace:
|
This is a great question. About the failure: we're returned the 1> {ok,Port} = gen_udp:open(0,[{netns,"/var/run/netns/blue"}]).
{ok,#Port<0.37928>}
2> {ok, Fd} = inet:getfd(Port).
{ok,12}
3> Ifindex = packet:ifindex(Fd,"veth1").
6
4> packet:bind(Fd, Ifindex).
{error,eafnosupport}
5> SA = <<2:16/native, 0:16, 6:32/native, 0:96>>.
<<2,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>
6> procket:bind(Fd, SA).
{error,eaddrnotavail} For namespace support, we'd probably want to support any type of socket. 1> {ok, S} = procket:open(0, [{protocol, 16#0008}, {type, raw}, {family, packet}, {namespace, "/var/run/netns/blue"}]).
{ok,14}
2> {ok, Q} = procket:read(S, 16#ffff).
{ok,<<1,0,94,0,0,251,246,255,141,18,35,1,8,0,69,0,0,68,
51,22,64,0,1,17,90,51,10,...>>}
3> pkt:decode(Q).
{ok,{[{ether,<<1,0,94,0,0,251>>,
<<246,255,141,18,35,1>>,
2048,0},
{ipv4,4,5,0,68,13078,1,0,0,1,17,23091,
{10,1,1,100},
{224,0,0,251},
<<>>},
{udp,5353,5353,48,60577}],
<<0,0,0,0,0,1,0,0,0,0,0,0,11,95,103,111,111,103,108,101,
99,97,115,116,4,...>>}} Here is patch to support namespaces (without tests or portability goop):
|
Thanks. Actually, I have a patch which is working. I just did a pull request can you take a look? |
Add support for setns(2) to the setuid helper. The helper is used to: * avoid running beam with root privs * avoid the beam process joining the namespace Unlike inet(3), the option tuple is {namespace, NS} vs {netns, NS}. A future change may allow the caller to specify the namespaces, e.g.: {namespace, NS, [net,ipc]} Currently all namespaces are joined. #36 Thanks @vasu-dasari!
Hello,
Is there a way I can specify network namespace to use for the socket? For example, gen_udp/gen_tcp has an option to specify netns via {netns,NS} tuple. Is there anything similar to that while using procket? If this is achieved by some other means, can someone point me to the fist or snippet?
Thanks
-Vasu
The text was updated successfully, but these errors were encountered: