aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/inet.erl
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2013-07-16 09:34:54 +0200
committerRaimo Niskanen <[email protected]>2013-07-17 10:20:18 +0200
commita9f92f3d024feffe23303af141dc4b13c7c17aa5 (patch)
treebae677bb2165b8262abebdc688a26ad84ed6a9ac /lib/kernel/src/inet.erl
parent41989072fdfa766916489088aa7eae48a7d89961 (diff)
downloadotp-a9f92f3d024feffe23303af141dc4b13c7c17aa5.tar.gz
otp-a9f92f3d024feffe23303af141dc4b13c7c17aa5.tar.bz2
otp-a9f92f3d024feffe23303af141dc4b13c7c17aa5.zip
Implement netns option for TCP and UDP
Diffstat (limited to 'lib/kernel/src/inet.erl')
-rw-r--r--lib/kernel/src/inet.erl36
1 files changed, 32 insertions, 4 deletions
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index 3ea530a366..0ee3234b05 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -634,6 +634,13 @@ con_opt([Opt | Opts], R, As) ->
{tcp_module,_} -> con_opt(Opts, R, As);
inet -> con_opt(Opts, R, As);
inet6 -> con_opt(Opts, R, As);
+ {netns,NS} ->
+ case prim_inet:is_sockopt_val(netns, NS) of
+ true ->
+ con_opt(Opts, R#connect_opts { fd = [Opt] }, As);
+ false ->
+ {error, badarg}
+ end;
{Name,Val} when is_atom(Name) -> con_add(Name, Val, R, Opts, As);
_ -> {error, badarg}
end;
@@ -692,6 +699,13 @@ list_opt([Opt | Opts], R, As) ->
{tcp_module,_} -> list_opt(Opts, R, As);
inet -> list_opt(Opts, R, As);
inet6 -> list_opt(Opts, R, As);
+ {netns,NS} ->
+ case prim_inet:is_sockopt_val(netns, NS) of
+ true ->
+ list_opt(Opts, R#listen_opts { fd = [Opt] }, As);
+ false ->
+ {error, badarg}
+ end;
{Name,Val} when is_atom(Name) -> list_add(Name, Val, R, Opts, As);
_ -> {error, badarg}
end;
@@ -738,6 +752,13 @@ udp_opt([Opt | Opts], R, As) ->
{udp_module,_} -> udp_opt(Opts, R, As);
inet -> udp_opt(Opts, R, As);
inet6 -> udp_opt(Opts, R, As);
+ {netns,NS} ->
+ case prim_inet:is_sockopt_val(netns, NS) of
+ true ->
+ list_opt(Opts, R#udp_opts { fd = [Opt] }, As);
+ false ->
+ {error, badarg}
+ end;
{Name,Val} when is_atom(Name) -> udp_add(Name, Val, R, Opts, As);
_ -> {error, badarg}
end;
@@ -1063,7 +1084,7 @@ gethostbyaddr_tm_native(Addr, Timer, Opts) ->
Result -> Result
end.
--spec open(Fd :: integer(),
+-spec open(Fd_or_OpenOpts :: integer() | list(),
Addr :: ip_address(),
Port :: port_number(),
Opts :: [socket_setopt()],
@@ -1073,8 +1094,14 @@ gethostbyaddr_tm_native(Addr, Timer, Opts) ->
Module :: atom()) ->
{'ok', socket()} | {'error', posix()}.
-open(Fd, Addr, Port, Opts, Protocol, Family, Type, Module) when Fd < 0 ->
- case prim_inet:open(Protocol, Family, Type) of
+open(FdO, Addr, Port, Opts, Protocol, Family, Type, Module)
+ when is_integer(FdO), FdO < 0;
+ is_list(FdO) ->
+ OpenOpts =
+ if is_list(FdO) -> FdO;
+ true -> []
+ end,
+ case prim_inet:open(Protocol, Family, Type, OpenOpts) of
{ok,S} ->
case prim_inet:setopts(S, Opts) of
ok ->
@@ -1097,7 +1124,8 @@ open(Fd, Addr, Port, Opts, Protocol, Family, Type, Module) when Fd < 0 ->
Error ->
Error
end;
-open(Fd, _Addr, _Port, Opts, Protocol, Family, Type, Module) ->
+open(Fd, _Addr, _Port, Opts, Protocol, Family, Type, Module)
+ when is_integer(Fd) ->
fdopen(Fd, Opts, Protocol, Family, Type, Module).
bindx(S, [Addr], Port0) ->