Skip to content

Commit ac97ec7

Browse files
committed
Make kTLS activation more resilient
1 parent dc6a918 commit ac97ec7

File tree

4 files changed

+12
-40
lines changed

4 files changed

+12
-40
lines changed

lib/ssl/src/inet_tls_dist.erl

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -932,8 +932,7 @@ inet_set_ktls(
932932
ok ?=
933933
set_ktls(
934934
KtlsInfo
935-
#{ setopt_fun => fun ?MODULE:inet_ktls_setopt/3,
936-
getopt_fun => fun ?MODULE:inet_ktls_getopt/3 }),
935+
#{ setopt_fun => fun ?MODULE:inet_ktls_setopt/3}),
937936
%%
938937
#socket_options{
939938
mode = _Mode,
@@ -985,23 +984,11 @@ set_ktls(KtlsInfo) ->
985984

986985
set_ktls_ulp(
987986
#{ socket := Socket,
988-
setopt_fun := SetoptFun,
989-
getopt_fun := GetoptFun },
987+
setopt_fun := SetoptFun },
990988
OS) ->
991989
%%
992990
{Option, Value} = ktls_opt_ulp(OS),
993-
Size = byte_size(Value),
994-
_ = SetoptFun(Socket, Option, Value),
995-
%%
996-
%% Check if kernel module loaded,
997-
%% i.e if getopts Level, Opt returns Value
998-
%%
999-
case GetoptFun(Socket, Option, Size + 1) of
1000-
{ok, <<Value:Size/binary, 0>>} ->
1001-
ok;
1002-
Other ->
1003-
{error, {ktls_set_ulp_failed, Option, Value, Other}}
1004-
end.
991+
SetoptFun(Socket, Option, Value).
1005992

1006993
%% Set kTLS cipher
1007994
%%
@@ -1011,26 +998,13 @@ set_ktls_cipher(
1011998
cipher_suite := CipherSuite,
1012999
%%
10131000
socket := Socket,
1014-
setopt_fun := SetoptFun,
1015-
getopt_fun := GetoptFun },
1001+
setopt_fun := SetoptFun },
10161002
OS, CipherState, CipherSeq, TxRx) ->
10171003
maybe
10181004
{ok, {Option, Value}} ?=
10191005
ktls_opt_cipher(
10201006
OS, TLS_version, CipherSuite, CipherState, CipherSeq, TxRx),
1021-
_ = SetoptFun(Socket, Option, Value),
1022-
case TxRx of
1023-
tx ->
1024-
Size = byte_size(Value),
1025-
case GetoptFun(Socket, Option, Size) of
1026-
{ok, Value} ->
1027-
ok;
1028-
Other ->
1029-
{error, {ktls_set_cipher_failed, Other}}
1030-
end;
1031-
rx ->
1032-
ok
1033-
end
1007+
SetoptFun(Socket, Option, Value)
10341008
end.
10351009

10361010
ktls_os() ->

lib/ssl/test/inet_epmd_cryptcookie_inet_ktls.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,4 @@ supported() ->
286286
inet_ktls_info(Socket, KtlsInfo) ->
287287
KtlsInfo
288288
#{ socket => Socket,
289-
setopt_fun => fun inet_tls_dist:inet_ktls_setopt/3,
290-
getopt_fun => fun inet_tls_dist:inet_ktls_getopt/3 }.
289+
setopt_fun => fun inet_tls_dist:inet_ktls_setopt/3 }.

lib/ssl/test/inet_epmd_cryptcookie_socket_ktls.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ stream_send(OutStream = [_ | Socket], Data) ->
233233
case socket:sendmsg(Socket, #{ iov => Data }) of
234234
ok ->
235235
OutStream;
236-
{error, closed} ->
236+
{error, Reason}
237+
when Reason =:= closed;
238+
Reason =:= econnreset ->
237239
[closed | OutStream];
238240
{error, Reason} ->
239241
erlang:error({?MODULE, ?FUNCTION_NAME, Reason, [OutStream, Data]})
@@ -273,5 +275,4 @@ supported() ->
273275
socket_ktls_info(Socket, KtlsInfo) ->
274276
KtlsInfo
275277
#{ socket => Socket,
276-
setopt_fun => fun socket:setopt_native/3,
277-
getopt_fun => fun socket:getopt_native/3 }.
278+
setopt_fun => fun socket:setopt_native/3 }.

lib/ssl/test/ssl_test_lib.erl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,8 +4369,7 @@ ktls_os() ->
43694369
ktls_set_ulp(Socket, OS) ->
43704370
inet_tls_dist:set_ktls_ulp(
43714371
#{ socket => Socket,
4372-
setopt_fun => fun inet_tls_dist:inet_ktls_setopt/3,
4373-
getopt_fun => fun inet_tls_dist:inet_ktls_getopt/3 },
4372+
setopt_fun => fun inet_tls_dist:inet_ktls_setopt/3 },
43744373
OS).
43754374

43764375
ktls_set_cipher(Socket, OS, TxRx, Seed) ->
@@ -4383,8 +4382,7 @@ ktls_set_cipher(Socket, OS, TxRx, Seed) ->
43834382
#{ socket => Socket,
43844383
tls_version => TLS_version,
43854384
cipher_suite => TLS_cipher,
4386-
setopt_fun => fun inet_tls_dist:inet_ktls_setopt/3,
4387-
getopt_fun => fun inet_tls_dist:inet_ktls_getopt/3 },
4385+
setopt_fun => fun inet_tls_dist:inet_ktls_setopt/3 },
43884386
CipherState =
43894387
#cipher_state{
43904388
key = TLS_KEY,

0 commit comments

Comments
 (0)