aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2018-07-25 12:00:34 +0200
committerMicael Karlberg <[email protected]>2018-09-18 14:50:18 +0200
commit587d3a9a76b6ef2c88b850d007d39d34c37b5825 (patch)
tree796aa8a07bd8fecc0bf8219ae130f07da3969c4f
parent5d9de1cdc46c75117f15f1ab17f017cdb700eb4c (diff)
downloadotp-587d3a9a76b6ef2c88b850d007d39d34c37b5825.tar.gz
otp-587d3a9a76b6ef2c88b850d007d39d34c37b5825.tar.bz2
otp-587d3a9a76b6ef2c88b850d007d39d34c37b5825.zip
[socket-nif] Add support for socket (level ip) option hdrincl
Added support for ip level socket option HDRINCL. As this option is raw only, it has not yet been tested! OTP-14831
-rw-r--r--erts/doc/src/socket_usage.xml7
-rw-r--r--erts/emulator/nifs/common/socket_nif.c60
-rw-r--r--erts/preloaded/ebin/socket.beambin59008 -> 59016 bytes
-rw-r--r--erts/preloaded/src/socket.erl11
4 files changed, 73 insertions, 5 deletions
diff --git a/erts/doc/src/socket_usage.xml b/erts/doc/src/socket_usage.xml
index e7e27629ac..2ddd51d1e6 100644
--- a/erts/doc/src/socket_usage.xml
+++ b/erts/doc/src/socket_usage.xml
@@ -296,6 +296,13 @@
<cell>none</cell>
</row>
<row>
+ <cell>hdrincl</cell>
+ <cell>boolean()</cell>
+ <cell>yes</cell>
+ <cell>yes</cell>
+ <cell>type = raw</cell>
+ </row>
+ <row>
<cell>minttl</cell>
<cell>integer()</cell>
<cell>yes</cell>
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c
index ae14e6b4ab..19b40920d3 100644
--- a/erts/emulator/nifs/common/socket_nif.c
+++ b/erts/emulator/nifs/common/socket_nif.c
@@ -520,6 +520,7 @@ typedef union {
#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_HDRINCL 8
#define SOCKET_OPT_IP_MINTTL 9
#define SOCKET_OPT_IP_MSFILTER 10
#define SOCKET_OPT_IP_MTU 11
@@ -1110,6 +1111,11 @@ static ERL_NIF_TERM nsetopt_lvl_ip_freebind(ErlNifEnv* env,
SocketDescriptor* descP,
ERL_NIF_TERM eVal);
#endif
+#if defined(IP_HDRINCL)
+static ERL_NIF_TERM nsetopt_lvl_ip_hdrincl(ErlNifEnv* env,
+ SocketDescriptor* descP,
+ ERL_NIF_TERM eVal);
+#endif
#if defined(IP_MINTTL)
static ERL_NIF_TERM nsetopt_lvl_ip_minttl(ErlNifEnv* env,
SocketDescriptor* descP,
@@ -1528,6 +1534,10 @@ static ERL_NIF_TERM ngetopt_lvl_ip(ErlNifEnv* env,
static ERL_NIF_TERM ngetopt_lvl_ip_freebind(ErlNifEnv* env,
SocketDescriptor* descP);
#endif
+#if defined(IP_HDRINCL)
+static ERL_NIF_TERM ngetopt_lvl_ip_hdrincl(ErlNifEnv* env,
+ SocketDescriptor* descP);
+#endif
#if defined(IP_MINTTL)
static ERL_NIF_TERM ngetopt_lvl_ip_minttl(ErlNifEnv* env,
SocketDescriptor* descP);
@@ -4951,6 +4961,12 @@ ERL_NIF_TERM nsetopt_lvl_ip(ErlNifEnv* env,
break;
#endif
+#if defined(IP_HDRINCL)
+ case SOCKET_OPT_IP_HDRINCL:
+ result = nsetopt_lvl_ip_hdrincl(env, descP, eVal);
+ break;
+#endif
+
#if defined(IP_MINTTL)
case SOCKET_OPT_IP_MINTTL:
result = nsetopt_lvl_ip_minttl(env, descP, eVal);
@@ -5187,6 +5203,26 @@ ERL_NIF_TERM nsetopt_lvl_ip_freebind(ErlNifEnv* env,
+/* nsetopt_lvl_ip_hdrincl - Level IP HDRINCL option
+ */
+#if defined(IP_HDRINCL)
+static
+ERL_NIF_TERM nsetopt_lvl_ip_hdrincl(ErlNifEnv* env,
+ SocketDescriptor* descP,
+ ERL_NIF_TERM eVal)
+{
+#if defined(SOL_IP)
+ int level = SOL_IP;
+#else
+ int level = IPPROTO_IP;
+#endif
+
+ return nsetopt_bool_opt(env, descP, level, IP_HDRINCL, eVal);
+}
+#endif
+
+
+
/* nsetopt_lvl_ip_minttl - Level IP MINTTL option
*/
#if defined(IP_MINTTL)
@@ -8086,6 +8122,12 @@ ERL_NIF_TERM ngetopt_lvl_ip(ErlNifEnv* env,
break;
#endif
+#if defined(IP_HDRINCL)
+ case SOCKET_OPT_IP_HDRINCL:
+ result = ngetopt_lvl_ip_hdrincl(env, descP);
+ break;
+#endif
+
#if defined(IP_MINTTL)
case SOCKET_OPT_IP_MINTTL:
result = ngetopt_lvl_ip_minttl(env, descP);
@@ -8233,6 +8275,24 @@ ERL_NIF_TERM ngetopt_lvl_ip_freebind(ErlNifEnv* env,
#endif
+/* ngetopt_lvl_ip_hdrincl - Level IP HDRINCL option
+ */
+#if defined(IP_HDRINCL)
+static
+ERL_NIF_TERM ngetopt_lvl_ip_hdrincl(ErlNifEnv* env,
+ SocketDescriptor* descP)
+{
+#if defined(SOL_IP)
+ int level = SOL_IP;
+#else
+ int level = IPPROTO_IP;
+#endif
+
+ return ngetopt_bool_opt(env, descP, level, IP_HDRINCL);
+}
+#endif
+
+
/* ngetopt_lvl_ip_mtu - Level IP MTU option
*/
#if defined(IP_MTU)
diff --git a/erts/preloaded/ebin/socket.beam b/erts/preloaded/ebin/socket.beam
index 14ee41257b..be5413e116 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 acda4e3811..4028fa9191 100644
--- a/erts/preloaded/src/socket.erl
+++ b/erts/preloaded/src/socket.erl
@@ -621,7 +621,7 @@
-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_HDRINCL, 8).
+-define(SOCKET_OPT_IP_HDRINCL, 8).
-define(SOCKET_OPT_IP_MINTTL, 9).
-define(SOCKET_OPT_IP_MSFILTER, 10).
-define(SOCKET_OPT_IP_MTU, 11).
@@ -631,7 +631,7 @@
-define(SOCKET_OPT_IP_MULTICAST_LOOP, 15).
-define(SOCKET_OPT_IP_MULTICAST_TTL, 16).
-define(SOCKET_OPT_IP_NODEFRAG, 17).
-%% -define(SOCKET_OPT_IP_OPTIONS, 18).
+%% -define(SOCKET_OPT_IP_OPTIONS, 18). % FreeBSD
%% -define(SOCKET_OPT_IP_PKTINFO, 19).
-define(SOCKET_OPT_IP_RECVERR, 20).
-define(SOCKET_OPT_IP_RECVIF, 21).
@@ -2208,6 +2208,8 @@ enc_setopt_value(ip, drop_source_membership, #{multiaddr := MA,
V;
enc_setopt_value(ip, freebind, V, _D, _T, _P) when is_boolean(V) ->
V;
+enc_setopt_value(ip, hdrincl, 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, msfilter, null = V, _D, _T, _P) ->
@@ -2676,9 +2678,8 @@ enc_sockopt_key(ip = _L, drop_source_membership = _Opt, set = _Dir, _D, _T, _P)
%% Linux only?
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?
+enc_sockopt_key(ip = _L, hdrincl = _Opt, _Dir, _D, raw = _T, _P) ->
+ ?SOCKET_OPT_IP_HDRINCL;
enc_sockopt_key(ip = _L, minttl = _Opt, _Dir, _D, raw = _T, _P) ->
?SOCKET_OPT_IP_MINTTL;
enc_sockopt_key(ip = _L, msfilter = _Opt, set = _Dir, _D, _T, _P) ->