diff options
author | Micael Karlberg <[email protected]> | 2018-07-09 15:28:09 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2018-09-18 14:50:18 +0200 |
commit | 6031321a78e3df5304f555ba356a4482469e7d56 (patch) | |
tree | b75a85a7d100eef2bfd395e22fd9651300dde62d /erts | |
parent | 7ed2af8dcfd62a051686ac1e1326fbeca0b18334 (diff) | |
download | otp-6031321a78e3df5304f555ba356a4482469e7d56.tar.gz otp-6031321a78e3df5304f555ba356a4482469e7d56.tar.bz2 otp-6031321a78e3df5304f555ba356a4482469e7d56.zip |
[socket-nif] Add support for socket (level socket) option debug
The socket option (level socket) debug is now supported.
To actually set this option, the user must have the proper
"authority" (CAP_NET_ADMIN capability or an effective user ID of 0).
OTP-14831
Diffstat (limited to 'erts')
-rw-r--r-- | erts/emulator/nifs/common/socket_nif.c | 62 | ||||
-rw-r--r-- | erts/preloaded/ebin/socket.beam | bin | 43616 -> 43652 bytes | |||
-rw-r--r-- | erts/preloaded/src/socket.erl | 8 |
3 files changed, 60 insertions, 10 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index 73da6455c3..c2a8170227 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -348,16 +348,17 @@ typedef union { #define SOCKET_OPT_SOCK_ACCEPTCONN 1 #define SOCKET_OPT_SOCK_BROADCAST 4 +#define SOCKET_OPT_SOCK_DEBUG 6 #define SOCKET_OPT_SOCK_DOMAIN 7 #define SOCKET_OPT_SOCK_DONTROUTE 8 #define SOCKET_OPT_SOCK_KEEPALIVE 10 #define SOCKET_OPT_SOCK_LINGER 11 -#define SOCKET_OPT_SOCK_PRIORITY 17 -#define SOCKET_OPT_SOCK_PROTOCOL 18 -#define SOCKET_OPT_SOCK_RCVBUF 19 -#define SOCKET_OPT_SOCK_REUSEADDR 23 -#define SOCKET_OPT_SOCK_SNDBUF 29 -#define SOCKET_OPT_SOCK_TYPE 34 +#define SOCKET_OPT_SOCK_PRIORITY 18 +#define SOCKET_OPT_SOCK_PROTOCOL 19 +#define SOCKET_OPT_SOCK_RCVBUF 20 +#define SOCKET_OPT_SOCK_REUSEADDR 24 +#define SOCKET_OPT_SOCK_SNDBUF 30 +#define SOCKET_OPT_SOCK_TYPE 35 #define SOCKET_OPT_IP_RECVTOS 25 #define SOCKET_OPT_IP_ROUTER_ALERT 28 @@ -786,6 +787,11 @@ static ERL_NIF_TERM nsetopt_lvl_sock_broadcast(ErlNifEnv* env, SocketDescriptor* descP, ERL_NIF_TERM eVal); #endif +#if defined(SO_DEBUG) +static ERL_NIF_TERM nsetopt_lvl_sock_debug(ErlNifEnv* env, + SocketDescriptor* descP, + ERL_NIF_TERM eVal); +#endif #if defined(SO_DONTROUTE) static ERL_NIF_TERM nsetopt_lvl_sock_dontroute(ErlNifEnv* env, SocketDescriptor* descP, @@ -938,6 +944,10 @@ static ERL_NIF_TERM ngetopt_lvl_sock_acceptconn(ErlNifEnv* env, static ERL_NIF_TERM ngetopt_lvl_sock_broadcast(ErlNifEnv* env, SocketDescriptor* descP); #endif +#if defined(SO_DEBUG) +static ERL_NIF_TERM ngetopt_lvl_sock_debug(ErlNifEnv* env, + SocketDescriptor* descP); +#endif #if defined(SO_DOMAIN) static ERL_NIF_TERM ngetopt_lvl_sock_domain(ErlNifEnv* env, SocketDescriptor* descP); @@ -3677,6 +3687,11 @@ ERL_NIF_TERM nsetopt_lvl_socket(ErlNifEnv* env, { ERL_NIF_TERM result; + SSDBG( descP, + ("SOCKET", "nsetopt_lvl_socket -> entry with" + "\r\n opt: %d" + "\r\n", eOpt) ); + switch (eOpt) { #if defined(SO_BROADCAST) case SOCKET_OPT_SOCK_BROADCAST: @@ -3684,6 +3699,12 @@ ERL_NIF_TERM nsetopt_lvl_socket(ErlNifEnv* env, break; #endif +#if defined(SO_DEBUG) + case SOCKET_OPT_SOCK_DEBUG: + result = nsetopt_lvl_sock_debug(env, descP, eVal); + break; +#endif + #if defined(SO_DONTROUTE) case SOCKET_OPT_SOCK_DONTROUTE: result = nsetopt_lvl_sock_dontroute(env, descP, eVal); @@ -3746,6 +3767,17 @@ ERL_NIF_TERM nsetopt_lvl_sock_broadcast(ErlNifEnv* env, #endif +#if defined(SO_DEBUG) +static +ERL_NIF_TERM nsetopt_lvl_sock_debug(ErlNifEnv* env, + SocketDescriptor* descP, + ERL_NIF_TERM eVal) +{ + return nsetopt_int_opt(env, descP, SOL_SOCKET, SO_DEBUG, eVal); +} +#endif + + #if defined(SO_DONTROUTE) static ERL_NIF_TERM nsetopt_lvl_sock_dontroute(ErlNifEnv* env, @@ -4277,7 +4309,7 @@ ERL_NIF_TERM nsetopt_int_opt(ErlNifEnv* env, int res = socket_setopt(descP->sock, level, opt, &val, sizeof(val)); if (res != 0) - result = esock_make_error_errno(env, res); + result = esock_make_error_errno(env, sock_errno()); else result = esock_atom_ok; @@ -4736,6 +4768,12 @@ ERL_NIF_TERM ngetopt_lvl_socket(ErlNifEnv* env, break; #endif +#if defined(SO_DEBUG) + case SOCKET_OPT_SOCK_DEBUG: + result = ngetopt_lvl_sock_debug(env, descP); + break; +#endif + #if defined(SO_DOMAIN) case SOCKET_OPT_SOCK_DOMAIN: result = ngetopt_lvl_sock_domain(env, descP); @@ -4825,6 +4863,16 @@ ERL_NIF_TERM ngetopt_lvl_sock_broadcast(ErlNifEnv* env, #endif +#if defined(SO_DEBUG) +static +ERL_NIF_TERM ngetopt_lvl_sock_debug(ErlNifEnv* env, + SocketDescriptor* descP) +{ + return ngetopt_int_opt(env, descP, SOL_SOCKET, SO_DEBUG); +} +#endif + + #if defined(SO_DOMAIN) static ERL_NIF_TERM ngetopt_lvl_sock_domain(ErlNifEnv* env, diff --git a/erts/preloaded/ebin/socket.beam b/erts/preloaded/ebin/socket.beam Binary files differindex f5248d8622..508c669895 100644 --- a/erts/preloaded/ebin/socket.beam +++ b/erts/preloaded/ebin/socket.beam diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index f22f9e5072..66ae9c7fd8 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -469,7 +469,7 @@ %% -define(SOCKET_OPT_SOCK_BINDTODEVICE, 3). -define(SOCKET_OPT_SOCK_BROADCAST, 4). %% -define(SOCKET_OPT_SOCK_BUSY_POLL, 5). -%% -define(SOCKET_OPT_SOCK_DEBUG, 6). +-define(SOCKET_OPT_SOCK_DEBUG, 6). -define(SOCKET_OPT_SOCK_DOMAIN, 7). -define(SOCKET_OPT_SOCK_DONTROUTE, 8). %% -define(SOCKET_OPT_SOCK_ERROR, 9). @@ -1831,6 +1831,8 @@ enc_setopt_value(otp = L, Opt, V, _D, _T, _P) -> enc_setopt_value(socket, broadcast, V, _D, _T, _P) when is_boolean(V) -> V; +enc_setopt_value(socket, debug, V, _D, _T, _P) when is_integer(V) -> + V; enc_setopt_value(socket, keepalive, V, _D, _T, _P) when is_boolean(V) -> V; enc_setopt_value(socket, linger, abort, D, T, P) -> @@ -2045,8 +2047,8 @@ enc_sockopt_key(socket, broadcast = _Opt, _Dir, _D, dgram = _T, _P) -> ?SOCKET_OPT_SOCK_BROADCAST; enc_sockopt_key(socket = L, busy_poll = Opt, _Dir, _D, _T, _P) -> not_supported({L, Opt}); -enc_sockopt_key(socket = L, debug = Opt, _Dir, _D, _T, _P) -> - not_supported({L, Opt}); +enc_sockopt_key(socket = _L, debug = _Opt, _Dir, _D, _T, _P) -> + ?SOCKET_OPT_SOCK_DEBUG; enc_sockopt_key(socket, domain = _Opt, get = _Dir, _D, _T, _P) -> ?SOCKET_OPT_SOCK_DOMAIN; enc_sockopt_key(socket, dontroute = _Opt, _Dir, _D, _T, _P) -> |