File 4882-ssl-Handle-shutdown-in-DTLS-context.patch of Package erlang
From 112a148ad89026e4acc425a15b0e1cde0490eaa4 Mon Sep 17 00:00:00 2001
From: Ingela Anderton Andin <ingela@erlang.org>
Date: Fri, 2 Jun 2023 12:19:08 +0200
Subject: [PATCH 2/3] ssl: Handle shutdown in DTLS context
This is really a TCP feature so make it default not supported
but allow callback transport module to make its own logic if
desired.
---
lib/ssl/src/ssl.erl | 17 +++++++++++++++--
lib/ssl/src/ssl_gen_statem.erl | 5 ++++-
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/lib/ssl/src/ssl.erl b/lib/ssl/src/ssl.erl
index 393b80a17e..6b6933e9a7 100644
--- a/lib/ssl/src/ssl.erl
+++ b/lib/ssl/src/ssl.erl
@@ -1265,8 +1265,21 @@ getstat(#sslsocket{pid = [Pid|_], fd = {Transport, Socket, _}},
%%
%% Description: Same as gen_tcp:shutdown/2
%%--------------------------------------------------------------------
-shutdown(#sslsocket{pid = {dtls, #config{}}},_) ->
- {error, enotconn};
+shutdown(#sslsocket{pid = {dtls, #config{transport_info = Info}}}, _) ->
+ Transport = element(1, Info),
+ %% enotconn is what gen_tcp:shutdown on a listen socket will result with.
+ %% shutdown really is handling TCP functionality not present
+ %% with gen_udp or gen_sctp, but if a callback wrapper is supplied let
+ %% the error be the same as for gen_tcp as a wrapper could have
+ %% supplied it own logic and this is backwards compatible.
+ case Transport of
+ gen_udp ->
+ {error, notsup};
+ gen_sctp ->
+ {error, notsup};
+ _ ->
+ {error, enotconn}
+ end;
shutdown(#sslsocket{pid = {Listen, #config{transport_info = Info}}}, How) ->
Transport = element(1, Info),
Transport:shutdown(Listen, How);
diff --git a/lib/ssl/src/ssl_gen_statem.erl b/lib/ssl/src/ssl_gen_statem.erl
index 0f99dbaf15..5553f3c260 100644
--- a/lib/ssl/src/ssl_gen_statem.erl
+++ b/lib/ssl/src/ssl_gen_statem.erl
@@ -753,7 +753,7 @@ handle_call({shutdown, read_write = How}, From, StateName,
try send_alert(?ALERT_REC(?WARNING, ?CLOSE_NOTIFY),
StateName, State) of
_ ->
- case Transport:shutdown(Socket, How) of
+ try Transport:shutdown(Socket, How) of
ok ->
{next_state, StateName, State#state{connection_env =
CEnv#connection_env{socket_terminated = true}},
@@ -761,6 +761,9 @@ handle_call({shutdown, read_write = How}, From, StateName,
Error ->
{stop_and_reply, {shutdown, normal}, {reply, From, Error},
State#state{connection_env = CEnv#connection_env{socket_terminated = true}}}
+ catch error:{undef, _} ->
+ {stop_and_reply, {shutdown, normal}, {reply, From, {error, notsup}},
+ State#state{connection_env = CEnv#connection_env{socket_terminated = true}}}
end
catch
throw:Return ->
--
2.35.3