Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport erlang/otp#7110 to wa/otp/26.0/main, allow dist input_handler to use an internal port #1

Open
wants to merge 5 commits into
base: wa/otp/26.0/main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert test hook in inet_tls_dist
  • Loading branch information
RaimoNiskanen committed May 3, 2023
commit cef93e8bffba8cc15f2b35fc97bb86d1f7c2fb9c
12 changes: 2 additions & 10 deletions lib/ssl/src/inet_tls_dist.erl
Original file line number Diff line number Diff line change
@@ -528,7 +528,7 @@ do_accept(
timer = Timer,
this_flags = 0,
allowed = NewAllowed},
dist_util:handshake_other_started(trace(hs_data_finalize(HSData)));
dist_util:handshake_other_started(trace(HSData));
{AcceptPid, exit} ->
%% this can happen when connection was initiated, but dropped
%% between TLS handshake completion and dist handshake start
@@ -677,7 +677,7 @@ do_setup(
this_flags = 0,
other_version = Version,
request_type = Type},
dist_util:handshake_we_started(trace(hs_data_finalize(HSData)))
dist_util:handshake_we_started(trace(HSData))
else
Other ->
%% Other Node may have closed since
@@ -1088,14 +1088,6 @@ ktls_opt_cipher(
{error,
{ktls_notsup, {cipher, TLS_version, CipherSpec, _CipherState}}}.

hs_data_finalize(HSData) ->
case application:get_env(kernel, dist_hs_data_finalize_fun) of
{ok, Fun} when is_function(Fun) ->
Fun(HSData);
_ ->
HSData
end.


%% -------------------------------------------------------------------------

56 changes: 0 additions & 56 deletions lib/ssl/test/ssl_dist_SUITE.erl
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@

-behaviour(ct_suite).

-include_lib("kernel/include/dist_util.hrl").
-include_lib("kernel/include/net_address.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("public_key/include/public_key.hrl").
@@ -360,7 +359,6 @@ ktls_verify(Config) ->
basic_test(NH1, NH2, KTLSConfig),
0 = ktls_count_tls_dist(NH1),
0 = ktls_count_tls_dist(NH2),
input_handler_test(NH1, NH2, KTLSConfig),
ok
end, KTLSConfig).

@@ -383,60 +381,6 @@ ktls_count_tls_dist(Node) ->
0
end.

%% Verify that dist input handler can be set if dist_ctrl is port;
%% and can send pessage properly
input_handler_test(NH1, NH2, KTLSConfig) ->
#node_handle{nodename = Node2} = NH2,
apply_on_ssl_node(NH1, application, set_env, [
kernel, dist_hs_data_finalize_fun, fun ktls_hs_data_finalize/1
]),
true = apply_on_ssl_node(NH1, erlang, disconnect_node, [Node2]),
true = apply_on_ssl_node(NH1, net_kernel, connect_node, [Node2]),
basic_test(NH1, NH2, KTLSConfig),
true = apply_on_ssl_node(NH1, persistent_term, get, [ktls_input_handler_received]).

ktls_hs_data_finalize(HSData = #hs_data{socket = Socket}) ->
Receiver = spawn_link(fun ktls_input_handler/0),
ok = gen_tcp:controlling_process(Socket, Receiver),
HSData#hs_data{
f_setopts_post_nodeup = fun (_) -> ok end,
f_handshake_complete = fun (S, _Node, DHandle) ->
Receiver ! {handshake_complete, S, DHandle, self()}
end
}.


ktls_input_handler() ->
receive
{handshake_complete, Socket, DHandle, DistUtil} ->
ok = erlang:dist_ctrl_input_handler(DHandle, self()),
inet:setopts(
Socket,
[
{active, true},
{deliver, term},
{packet, 4},
binary,
{nodelay, true}
]
),
ktls_input_handler_loop(Socket, DHandle, DistUtil)
end.

ktls_input_handler_loop(Socket, DHandle, DistUtil) ->
receive
{tcp, Socket, Data} ->
persistent_term:put(ktls_input_handler_received, true),
erlang:dist_ctrl_put_data(DHandle, Data),
ktls_input_handler_loop(Socket, DHandle, DistUtil);
{tcp_error, Socket, _Error} ->
DistUtil ! {tcp_closed, Socket},
inet:tcp_close(Socket);
{tcp_closed, Socket} ->
DistUtil ! {tcp_closed, Socket},
inet:tcp_close(Socket)
end.

%%--------------------------------------------------------------------
%% Test net_kernel:monitor_nodes with nodedown_reason (OTP-17838)
monitor_nodes(Config) when is_list(Config) ->