aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2018-07-20 15:14:06 +0200
committerMicael Karlberg <[email protected]>2018-09-18 14:50:18 +0200
commit1c26ae984a79224ce64b40dbc7239bf9721bb096 (patch)
treebc01665931d21620dc152eeb402ad47f21bd0aac /erts/preloaded
parent84f62ae80dd08874d0d5fbedc532605394e897c1 (diff)
downloadotp-1c26ae984a79224ce64b40dbc7239bf9721bb096.tar.gz
otp-1c26ae984a79224ce64b40dbc7239bf9721bb096.tar.bz2
otp-1c26ae984a79224ce64b40dbc7239bf9721bb096.zip
[socket-nif] Add support for socket (level ip) option freebind
Added support for ip level socket option FREEBIND. Note that there is an option available on FreeBSD called IP_BINDANY, which seems to have similar properties (FREEBIND is *not* available on FreeBSD). There are some restrictions for this option though (which is not mentioned in the Linux man page). OTP-14831
Diffstat (limited to 'erts/preloaded')
-rw-r--r--erts/preloaded/ebin/socket.beambin56432 -> 56564 bytes
-rw-r--r--erts/preloaded/src/socket.erl17
2 files changed, 13 insertions, 4 deletions
diff --git a/erts/preloaded/ebin/socket.beam b/erts/preloaded/ebin/socket.beam
index 8799f07bc0..3657212f81 100644
--- a/erts/preloaded/ebin/socket.beam
+++ b/erts/preloaded/ebin/socket.beam
Binary files differ
diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl
index c231647f8c..329223c443 100644
--- a/erts/preloaded/src/socket.erl
+++ b/erts/preloaded/src/socket.erl
@@ -87,6 +87,7 @@
tcp_socket_option/0,
udp_socket_option/0,
sctp_socket_option/0,
+ raw_socket_option/0,
timeval/0,
ip_tos_flag/0,
@@ -258,7 +259,7 @@
%% Int - Raw level, sent down and used "as is".
-type sockopt_level() :: otp |
socket |
- ip | ipv6 | tcp | udp | sctp |
+ ip | ipv6 | tcp | udp | sctp | raw |
non_neg_integer().
%% There are some options that are 'read-only'.
@@ -434,6 +435,8 @@
status |
use_ext_recvinfo.
+-type raw_socket_option() :: filter.
+
%% -type plain_socket_option() :: integer().
%% -type sockopt() :: otp_socket_option() |
%% socket_option() |
@@ -442,6 +445,7 @@
%% tcp_socket_option() |
%% udp_socket_option() |
%% sctp_socket_option() |
+%% raw_socket_option() |
%% plain_socket_option().
-type socket_info() :: #{domain => domain(),
@@ -594,7 +598,7 @@
%% -define(SOCKET_OPT_IP_DONTFRAG, 4).
-define(SOCKET_OPT_IP_DROP_MEMBERSHIP, 5).
-define(SOCKET_OPT_IP_DROP_SOURCE_MEMBERSHIP, 6).
-%% -define(SOCKET_OPT_IP_FREEBIND, 7).
+-define(SOCKET_OPT_IP_FREEBIND, 7).
%% -define(SOCKET_OPT_IP_HDRINCL, 8).
-define(SOCKET_OPT_IP_MINTTL, 9).
%% -define(SOCKET_OPT_IP_MSFILTER, 10).
@@ -2177,6 +2181,8 @@ enc_setopt_value(ip, drop_source_membership, #{multiaddr := MA,
(is_tuple(IF) andalso (size(IF) =:= 4)) andalso
(is_tuple(SA) andalso (size(SA) =:= 4)) ->
V;
+enc_setopt_value(ip, freebind, V, _D, _T, _P) when is_boolean(V) ->
+ V;
enc_setopt_value(ip, minttl, V, _D, _T, _P) when is_integer(V) ->
V;
enc_setopt_value(ip, mtu_discover, V, _D, _T, _P)
@@ -2358,6 +2364,9 @@ enc_setopt_value(sctp, rtoinfo, #{assoc_id := AssocId,
enc_setopt_value(sctp = L, Opt, V, _D, _T, _P) ->
not_supported({L, Opt, V});
+enc_setopt_value(raw = L, Opt, _V, _D, _T, _P) ->
+ not_supported({L, Opt});
+
%% Is this correct? What about getopt?
enc_setopt_value(L, Opt, V, _, _, _)
when is_integer(L) andalso is_integer(Opt) andalso is_binary(V) ->
@@ -2574,8 +2583,8 @@ enc_sockopt_key(ip = _L, drop_membership = _Opt, set = _Dir, _D, _T, _P) ->
enc_sockopt_key(ip = _L, drop_source_membership = _Opt, set = _Dir, _D, _T, _P) ->
?SOCKET_OPT_IP_DROP_SOURCE_MEMBERSHIP;
%% Linux only?
-enc_sockopt_key(ip = L, free_bind = Opt, _Dir, _D, _T, _P) ->
- not_supported({L, Opt});
+enc_sockopt_key(ip = _L, freebind = _Opt, _Dir, _D, _T, _P) ->
+ ?SOCKET_OPT_IP_FREEBIND;
enc_sockopt_key(ip = L, hdrincl = Opt, _Dir, _D, raw = _T, _P) ->
not_supported({L, Opt});
%% FreeBSD only?