From d2f4de0a8e36e6a25cfd7446ea6fc3623b7f1495 Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Thu, 26 Apr 2018 11:50:11 +0200 Subject: ssh: ssh_daemon_channel replaced by ssh_server_channel --- lib/ssh/doc/src/Makefile | 15 ++- lib/ssh/doc/src/ref_man.xml | 3 +- lib/ssh/doc/src/specs.xml | 7 +- lib/ssh/doc/src/ssh.xml | 6 +- lib/ssh/doc/src/ssh_channel.xml | 5 +- lib/ssh/doc/src/ssh_daemon_channel.xml | 127 +------------------ lib/ssh/doc/src/ssh_protocol.xml | 2 +- lib/ssh/doc/src/ssh_server_channel.xml | 176 ++++++++++++++++++++++++++ lib/ssh/doc/src/ssh_sftpd.xml | 2 +- lib/ssh/doc/src/using_ssh.xml | 2 +- lib/ssh/src/Makefile | 42 +++--- lib/ssh/src/ssh.app.src | 3 +- lib/ssh/src/ssh_cli.erl | 6 +- lib/ssh/src/ssh_connection.erl | 4 +- lib/ssh/src/ssh_daemon_channel.erl | 4 +- lib/ssh/src/ssh_daemon_channel_sup.erl | 62 --------- lib/ssh/src/ssh_info.erl | 8 +- lib/ssh/src/ssh_server_channel.erl | 55 ++++++++ lib/ssh/src/ssh_server_channel_sup.erl | 62 +++++++++ lib/ssh/src/ssh_sftpd.erl | 2 +- lib/ssh/src/ssh_shell.erl | 6 +- lib/ssh/src/ssh_subsystem_sup.erl | 12 +- lib/ssh/test/property_test/ssh_eqc_subsys.erl | 2 +- lib/ssh/test/ssh_bench_dev_null.erl | 2 +- lib/ssh/test/ssh_echo_server.erl | 2 +- lib/ssh/test/ssh_peername_sockname_server.erl | 2 +- lib/ssh/test/ssh_sup_SUITE.erl | 12 +- 27 files changed, 377 insertions(+), 254 deletions(-) create mode 100644 lib/ssh/doc/src/ssh_server_channel.xml delete mode 100644 lib/ssh/src/ssh_daemon_channel_sup.erl create mode 100644 lib/ssh/src/ssh_server_channel.erl create mode 100644 lib/ssh/src/ssh_server_channel_sup.erl diff --git a/lib/ssh/doc/src/Makefile b/lib/ssh/doc/src/Makefile index f47a1bfb40..9b5bee34fa 100644 --- a/lib/ssh/doc/src/Makefile +++ b/lib/ssh/doc/src/Makefile @@ -38,20 +38,23 @@ RELSYSDIR = $(RELEASE_PATH)/lib/$(APPLICATION)-$(VSN) # Target Specs # ---------------------------------------------------- XML_APPLICATION_FILES = ref_man.xml -XML_REF3_FILES = ssh.xml \ +XML_REF3_FILES = \ + ssh.xml \ ssh_channel.xml \ - ssh_daemon_channel.xml \ - ssh_connection.xml \ ssh_client_key_api.xml \ + ssh_connection.xml \ + ssh_daemon_channel.xml \ + ssh_server_channel.xml \ ssh_server_key_api.xml \ ssh_sftp.xml \ ssh_sftpd.xml \ XML_REF6_FILES = ssh_app.xml -XML_PART_FILES = \ - usersguide.xml -XML_CHAPTER_FILES = notes.xml \ +XML_PART_FILES = usersguide.xml + +XML_CHAPTER_FILES = \ + notes.xml \ introduction.xml \ using_ssh.xml \ configure_algos.xml diff --git a/lib/ssh/doc/src/ref_man.xml b/lib/ssh/doc/src/ref_man.xml index 1e1cff9119..3351699c66 100644 --- a/lib/ssh/doc/src/ref_man.xml +++ b/lib/ssh/doc/src/ref_man.xml @@ -36,7 +36,8 @@ - + + diff --git a/lib/ssh/doc/src/specs.xml b/lib/ssh/doc/src/specs.xml index f7837f9c5c..15e76cb5fa 100644 --- a/lib/ssh/doc/src/specs.xml +++ b/lib/ssh/doc/src/specs.xml @@ -1,13 +1,14 @@ + - + + - - + diff --git a/lib/ssh/doc/src/ssh.xml b/lib/ssh/doc/src/ssh.xml index c403989ba9..da122b6081 100644 --- a/lib/ssh/doc/src/ssh.xml +++ b/lib/ssh/doc/src/ssh.xml @@ -68,8 +68,8 @@ ssh_sftp:start_channel/1,2,3.

To write your own client channel handler, use the behaviour - ssh_channel. and server channel handlers use - ssh_daemon_channel behaviour. + ssh_channel. For server channel handlers use + ssh_server_channel behaviour (replaces ssh_daemon_channel).

Both clients and daemons accepts options that controls the exact behaviour. Some options are common to both. The three sets are called @@ -379,7 +379,7 @@ ssh_connection:subsystem/4.

The channel_callback is the module that implements the - ssh_daemon_channel + ssh_server_channel (replaces ssh_daemon_channel) behaviour in the daemon. See the section Creating a Subsystem in the User's Guide for more information and an example. diff --git a/lib/ssh/doc/src/ssh_channel.xml b/lib/ssh/doc/src/ssh_channel.xml index b4bcd148f3..63a480d747 100644 --- a/lib/ssh/doc/src/ssh_channel.xml +++ b/lib/ssh/doc/src/ssh_channel.xml @@ -47,7 +47,8 @@

When implementing a ssh subsystem for daemons, use - -behaviour(ssh_daemon_channel) instead. + -behaviour(ssh_server_channel) (Replaces ssh_daemon_channel) + instead.

@@ -223,7 +224,7 @@ Callback Functions

The following functions are to be exported from a - ssh_daemon_channel callback module. + ssh_channel callback module.

diff --git a/lib/ssh/doc/src/ssh_daemon_channel.xml b/lib/ssh/doc/src/ssh_daemon_channel.xml index 8b0ff93f5f..254f75a4de 100644 --- a/lib/ssh/doc/src/ssh_daemon_channel.xml +++ b/lib/ssh/doc/src/ssh_daemon_channel.xml @@ -33,137 +33,20 @@ -behaviour(ssh_daemon_channel). -

SSH services (clients and servers) are implemented as channels - that are multiplexed over an SSH connection and communicates over - the SSH - Connection Protocol. This module provides a callback API - that takes care of generic channel aspects for daemons, such as flow control - and close messages. It lets the callback functions take care of - the service (application) specific parts. This behavior also ensures - that the channel process honors the principal of an OTP-process so - that it can be part of a supervisor tree. This is a requirement of - channel processes implementing a subsystem that will be added to - the ssh applications supervisor tree. +

This behaviour should NOT be used for new programs but is kept for compatibility.

- -

When implementing a client subsystem handler, use - -behaviour(ssh_channel) instead. -

-
- +

It is replaced by ssh_server_channel.

-
- Callback Functions -

- The following functions are to be exported from a - ssh_daemon_channel callback module. -

-
- - Module:init(Args) -> {ok, State} | {ok, State, timeout()} | - {stop, Reason} - Makes necessary initializations and returns the - initial channel state if the initializations succeed. - - Args = term() - Last argument to start_link/4. - State = term() - Reason = term() - - -

Makes necessary initializations and returns the initial channel - state if the initializations succeed. -

-

The time-out values that can be returned - have the same semantics as in a gen_server. - If the time-out occurs, handle_msg/2 - is called as handle_msg(timeout, State). -

-
-
- - - Module:handle_msg(Msg, State) -> {ok, State} | - {stop, ChannelId, State} - - Handles other messages than SSH connection protocol, - call, or cast messages sent to the channel. - - Msg = timeout | term() - ChannelId = ssh:channel_id() - State = term() - - -

Handles other messages than SSH Connection Protocol, call, or - cast messages sent to the channel. -

- -

Possible Erlang 'EXIT' messages is to be handled by this - function and all channels are to handle the following message.

- - - {ssh_channel_up, ssh:channel_id(), ssh:connection_ref()} -

This is the first message that the channel receives. - This is especially useful if the - server wants to send a message to the client without first - receiving a message from it. If the message is not - useful for your particular scenario, ignore it by - immediately returning {ok, State}. -

-
-
-
- - - Module:handle_ssh_msg(Msg, State) -> {ok, State} | {stop, - ChannelId, State} - Handles ssh connection protocol messages. - - Msg = ssh_connection:event() - ChannelId = ssh:channel_id() - State = term() - - -

Handles SSH Connection Protocol messages that may need - service-specific attention. For details, - see ssh_connection:event(). -

- -

The following message is taken care of by the - ssh_daemon_channel behavior.

- - - {closed, ssh:channel_id()} -

The channel behavior sends a close message to the - other side, if such a message has not already been sent. - Then it terminates the channel with reason normal.

-
-
-
- - - Module:terminate(Reason, State) -> _ - Does cleaning up before channel process termination. - - - Reason = term() - State = term() - + Module:CALLBACK(..) + ssh_daemon_channel is replaced by ssh_server_channel -

This function is called by a channel process when it is - about to terminate. Before this function is called, ssh_connection:close/2 - is called, if it has not been called earlier. - This function does any necessary cleaning - up. When it returns, the channel process terminates with - reason Reason. The return value is ignored. +

See ssh_server_channel which replaces this module.

-
diff --git a/lib/ssh/doc/src/ssh_protocol.xml b/lib/ssh/doc/src/ssh_protocol.xml index 21c755b48e..4548d7bbb6 100644 --- a/lib/ssh/doc/src/ssh_protocol.xml +++ b/lib/ssh/doc/src/ssh_protocol.xml @@ -89,7 +89,7 @@ data/"control information" and when it is done close the channel. The ssh_channel / - ssh_daemon_channel + ssh_server_channel (Replaces ssh_daemon_channel) behaviours makes it easy to write your own SSH client/server processes that use flow control. It handles generic parts of SSH channel management and diff --git a/lib/ssh/doc/src/ssh_server_channel.xml b/lib/ssh/doc/src/ssh_server_channel.xml new file mode 100644 index 0000000000..19fc20fcda --- /dev/null +++ b/lib/ssh/doc/src/ssh_server_channel.xml @@ -0,0 +1,176 @@ + + + + +
+ + 2009 + 2016 + Ericsson AB, All Rights Reserved + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + The Initial Developer of the Original Code is Ericsson AB. + + ssh_server_channel + + + + +
+ ssh_server_channel + -behaviour(ssh_server_channel). (Replaces ssh_daemon_channel) + + + +

This module replaces ssh_daemon_channel.

+

The old module is still available for compatibility, but should not be used for new programs. + The old module will not be maintained except for some error corrections +

+
+ +

SSH services (clients and servers) are implemented as channels + that are multiplexed over an SSH connection and communicates over + the SSH + Connection Protocol. This module provides a callback API + that takes care of generic channel aspects for daemons, such as flow control + and close messages. It lets the callback functions take care of + the service (application) specific parts. This behavior also ensures + that the channel process honors the principal of an OTP-process so + that it can be part of a supervisor tree. This is a requirement of + channel processes implementing a subsystem that will be added to + the ssh applications supervisor tree. +

+ +

When implementing a client subsystem handler, use + -behaviour(ssh_channel) instead. +

+
+ +
+ +
+ Callback Functions +

+ The following functions are to be exported from a + ssh_server_channel callback module. +

+
+ + + + Module:init(Args) -> {ok, State} | {ok, State, timeout()} | + {stop, Reason} + Makes necessary initializations and returns the + initial channel state if the initializations succeed. + + Args = term() + Last argument to start_link/4. + State = term() + Reason = term() + + +

Makes necessary initializations and returns the initial channel + state if the initializations succeed. +

+

The time-out values that can be returned + have the same semantics as in a gen_server. + If the time-out occurs, handle_msg/2 + is called as handle_msg(timeout, State). +

+
+
+ + + Module:handle_msg(Msg, State) -> {ok, State} | + {stop, ChannelId, State} + + Handles other messages than SSH connection protocol, + call, or cast messages sent to the channel. + + Msg = timeout | term() + ChannelId = ssh:channel_id() + State = term() + + +

Handles other messages than SSH Connection Protocol, call, or + cast messages sent to the channel. +

+ +

Possible Erlang 'EXIT' messages is to be handled by this + function and all channels are to handle the following message.

+ + + {ssh_channel_up, ssh:channel_id(), ssh:connection_ref()} +

This is the first message that the channel receives. + This is especially useful if the + server wants to send a message to the client without first + receiving a message from it. If the message is not + useful for your particular scenario, ignore it by + immediately returning {ok, State}. +

+
+
+
+ + + Module:handle_ssh_msg(Msg, State) -> {ok, State} | {stop, + ChannelId, State} + Handles ssh connection protocol messages. + + Msg = ssh_connection:event() + ChannelId = ssh:channel_id() + State = term() + + +

Handles SSH Connection Protocol messages that may need + service-specific attention. For details, + see ssh_connection:event(). +

+ +

The following message is taken care of by the + ssh_server_channel behavior.

+ + + {closed, ssh:channel_id()} +

The channel behavior sends a close message to the + other side, if such a message has not already been sent. + Then it terminates the channel with reason normal.

+
+
+
+ + + Module:terminate(Reason, State) -> _ + Does cleaning up before channel process termination. + + + Reason = term() + State = term() + + +

This function is called by a channel process when it is + about to terminate. Before this function is called, ssh_connection:close/2 + is called, if it has not been called earlier. + This function does any necessary cleaning + up. When it returns, the channel process terminates with + reason Reason. The return value is ignored. +

+
+
+ +
+ +
diff --git a/lib/ssh/doc/src/ssh_sftpd.xml b/lib/ssh/doc/src/ssh_sftpd.xml index 4c599a7fb9..a25ce123b3 100644 --- a/lib/ssh/doc/src/ssh_sftpd.xml +++ b/lib/ssh/doc/src/ssh_sftpd.xml @@ -44,7 +44,7 @@

"sftp"

channel_callback() =

atom() - Name of the Erlang module implementing the subsystem using the - ssh_daemon_channel behaviour.

+ ssh_server_channel (replaces ssh_daemon_channel) behaviour.

channel_init_args() =

list() - The one given as argument to function subsystem_spec/1.

diff --git a/lib/ssh/doc/src/using_ssh.xml b/lib/ssh/doc/src/using_ssh.xml index bde2aaaf99..fef0784eb6 100644 --- a/lib/ssh/doc/src/using_ssh.xml +++ b/lib/ssh/doc/src/using_ssh.xml @@ -306,7 +306,7 @@ ok = erl_tar:close(HandleRead), -module(ssh_echo_server). --behaviour(ssh_daemon_channel). +-behaviour(ssh_server_channel). % replaces ssh_daemon_channel -record(state, { n, id, diff --git a/lib/ssh/src/Makefile b/lib/ssh/src/Makefile index a2cefe7c15..1665e8b554 100644 --- a/lib/ssh/src/Makefile +++ b/lib/ssh/src/Makefile @@ -40,42 +40,43 @@ RELSYSDIR = $(RELEASE_PATH)/lib/ssh-$(VSN) # Behaviour (api) modules are first so they are compiled when # the compiler reaches a callback module using them. BEHAVIOUR_MODULES= \ - ssh_sftpd_file_api \ - ssh_channel \ - ssh_daemon_channel \ ssh_client_key_api \ - ssh_server_key_api + ssh_daemon_channel \ + ssh_server_channel \ + ssh_server_key_api \ + ssh_sftpd_file_api \ + ssh_channel MODULES= \ ssh \ - ssh_sup \ - sshc_sup \ - sshd_sup \ - ssh_options \ - ssh_connection_sup \ - ssh_connection \ - ssh_connection_handler \ - ssh_dbg \ - ssh_shell \ - ssh_system_sup \ - ssh_subsystem_sup \ - ssh_daemon_channel_sup \ - ssh_acceptor_sup \ ssh_acceptor \ + ssh_acceptor_sup \ ssh_app \ ssh_auth\ ssh_bits \ ssh_cli \ + ssh_connection \ + ssh_connection_handler \ + ssh_connection_sup \ + ssh_dbg \ ssh_file \ - ssh_io \ ssh_info \ + ssh_io \ ssh_message \ ssh_no_io \ + ssh_options \ + ssh_server_channel_sup \ ssh_sftp \ ssh_sftpd \ ssh_sftpd_file\ + ssh_shell \ + ssh_subsystem_sup \ + ssh_sup \ + ssh_system_sup \ ssh_transport \ - ssh_xfer + ssh_xfer \ + sshc_sup \ + sshd_sup HRL_FILES = @@ -169,7 +170,7 @@ $(EBIN)/ssh_connection_handler.$(EMULATOR): ssh_connection_handler.erl ssh.hrl \ $(EBIN)/ssh_shell.$(EMULATOR): ssh_shell.erl ssh_connect.hrl $(EBIN)/ssh_system_sup.$(EMULATOR): ssh_system_sup.erl ssh.hrl $(EBIN)/ssh_subsystem_sup.$(EMULATOR): ssh_subsystem_sup.erl -$(EBIN)/ssh_daemon_channel_sup.$(EMULATOR): ssh_daemon_channel_sup.erl +$(EBIN)/ssh_server_channel_sup.$(EMULATOR): ssh_server_channel_sup.erl $(EBIN)/ssh_acceptor_sup.$(EMULATOR): ssh_acceptor_sup.erl ssh.hrl $(EBIN)/ssh_acceptor.$(EMULATOR): ssh_acceptor.erl ssh.hrl $(EBIN)/ssh_app.$(EMULATOR): ssh_app.erl @@ -210,6 +211,7 @@ $(EBIN)/ssh_xfer.$(EMULATOR): ssh_xfer.erl ssh.hrl ssh_xfer.hrl $(EBIN)/ssh_sftpd_file_api.$(EMULATOR): ssh_sftpd_file_api.erl $(EBIN)/ssh_channel.$(EMULATOR): ssh_channel.erl ssh_connect.hrl $(EBIN)/ssh_daemon_channel.$(EMULATOR): ssh_daemon_channel.erl +$(EBIN)/ssh_server_channel.$(EMULATOR): ssh_server_channel.erl $(EBIN)/ssh_client_key_api.$(EMULATOR): ssh_client_key_api.erl \ ../../public_key/include/public_key.hrl \ ../../public_key/include/OTP-PUB-KEY.hrl \ diff --git a/lib/ssh/src/ssh.app.src b/lib/ssh/src/ssh.app.src index b935ea94d5..897235e054 100644 --- a/lib/ssh/src/ssh.app.src +++ b/lib/ssh/src/ssh.app.src @@ -14,7 +14,6 @@ ssh_cli, ssh_client_key_api, ssh_channel, - ssh_daemon_channel_sup, ssh_connection, ssh_connection_handler, ssh_connection_sup, @@ -27,6 +26,8 @@ ssh_io, ssh_info, ssh_no_io, + ssh_server_channel, + ssh_server_channel_sup, ssh_server_key_api, ssh_sftp, ssh_sftpd, diff --git a/lib/ssh/src/ssh_cli.erl b/lib/ssh/src/ssh_cli.erl index 31f6194bf9..fcc1d3d59f 100644 --- a/lib/ssh/src/ssh_cli.erl +++ b/lib/ssh/src/ssh_cli.erl @@ -25,12 +25,12 @@ -module(ssh_cli). --behaviour(ssh_daemon_channel). +-behaviour(ssh_server_channel). -include("ssh.hrl"). -include("ssh_connect.hrl"). -%% ssh_daemon_channel callbacks +%% ssh_server_channel callbacks -export([init/1, handle_ssh_msg/2, handle_msg/2, terminate/2]). -export([dbg_trace/3]). @@ -47,7 +47,7 @@ }). %%==================================================================== -%% ssh_daemon_channel callbacks +%% ssh_server_channel callbacks %%==================================================================== %%-------------------------------------------------------------------- diff --git a/lib/ssh/src/ssh_connection.erl b/lib/ssh/src/ssh_connection.erl index 0a07ea778d..cff9ec3a61 100644 --- a/lib/ssh/src/ssh_connection.erl +++ b/lib/ssh/src/ssh_connection.erl @@ -822,14 +822,14 @@ start_channel(Cb, Id, Args, SubSysSup, Exec, Opts) -> ChannelSup = ssh_subsystem_sup:channel_supervisor(SubSysSup), case max_num_channels_not_exceeded(ChannelSup, Opts) of true -> - ssh_daemon_channel_sup:start_child(ChannelSup, Cb, Id, Args, Exec); + ssh_server_channel_sup:start_child(ChannelSup, Cb, Id, Args, Exec); false -> throw(max_num_channels_exceeded) end. max_num_channels_not_exceeded(ChannelSup, Opts) -> MaxNumChannels = ?GET_OPT(max_channels, Opts), - NumChannels = length([x || {_,_,worker,[ssh_daemon_channel]} <- + NumChannels = length([x || {_,_,worker,[ssh_server_channel]} <- supervisor:which_children(ChannelSup)]), %% Note that NumChannels is BEFORE starting a new one NumChannels < MaxNumChannels. diff --git a/lib/ssh/src/ssh_daemon_channel.erl b/lib/ssh/src/ssh_daemon_channel.erl index e1d6906bbc..fdb6c10971 100644 --- a/lib/ssh/src/ssh_daemon_channel.erl +++ b/lib/ssh/src/ssh_daemon_channel.erl @@ -48,8 +48,8 @@ ]). start_link(ConnectionManager, ChannelId, CallBack, CbInitArgs, Exec) -> - ssh_channel:start_link(ConnectionManager, ChannelId, CallBack, CbInitArgs, Exec). + ssh_server_channel:start_link(ConnectionManager, ChannelId, CallBack, CbInitArgs, Exec). get_print_info(Pid) -> - ssh_channel:get_print_info(Pid). + ssh_server_channel:get_print_info(Pid). diff --git a/lib/ssh/src/ssh_daemon_channel_sup.erl b/lib/ssh/src/ssh_daemon_channel_sup.erl deleted file mode 100644 index cd86347501..0000000000 --- a/lib/ssh/src/ssh_daemon_channel_sup.erl +++ /dev/null @@ -1,62 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2016. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%% -%% %CopyrightEnd% -%% - -%% -%%---------------------------------------------------------------------- -%% Purpose: Ssh channel supervisor. -%%---------------------------------------------------------------------- --module(ssh_daemon_channel_sup). - --behaviour(supervisor). - --export([start_link/1, start_child/5]). - -%% Supervisor callback --export([init/1]). - -%%%========================================================================= -%%% Internal API -%%%========================================================================= -start_link(Args) -> - supervisor:start_link(?MODULE, [Args]). - -start_child(Sup, Callback, Id, Args, Exec) -> - ChildSpec = - #{id => make_ref(), - start => {ssh_daemon_channel, start_link, [self(), Id, Callback, Args, Exec]}, - restart => temporary, - type => worker, - modules => [ssh_daemon_channel] - }, - supervisor:start_child(Sup, ChildSpec). - -%%%========================================================================= -%%% Supervisor callback -%%%========================================================================= -init(_Args) -> - RestartStrategy = one_for_one, - MaxR = 10, - MaxT = 3600, - Children = [], - {ok, {{RestartStrategy, MaxR, MaxT}, Children}}. - -%%%========================================================================= -%%% Internal functions -%%%========================================================================= diff --git a/lib/ssh/src/ssh_info.erl b/lib/ssh/src/ssh_info.erl index e1613f0599..ee244f1432 100644 --- a/lib/ssh/src/ssh_info.erl +++ b/lib/ssh/src/ssh_info.erl @@ -140,15 +140,15 @@ print_system_sup({{ssh_acceptor_sup,_LocalHost,_LocalPort,_Profile}, Pid, superv -print_channels({{server,ssh_daemon_channel_sup,_,_},Pid,supervisor,[ssh_daemon_channel_sup]}) when is_pid(Pid) -> +print_channels({{server,ssh_server_channel_sup,_,_},Pid,supervisor,[ssh_server_channel_sup]}) when is_pid(Pid) -> Children = supervisor:which_children(Pid), - ChannelPids = [P || {R,P,worker,[ssh_daemon_channel]} <- Children, + ChannelPids = [P || {R,P,worker,[ssh_server_channel]} <- Children, is_pid(P), is_reference(R)], case ChannelPids of [] -> io_lib:format(?INDENT?INDENT"No channels~n",[]); [Ch1Pid|_] -> - {{ConnManager,_}, _Str} = ssh_daemon_channel:get_print_info(Ch1Pid), + {{ConnManager,_}, _Str} = ssh_server_channel:get_print_info(Ch1Pid), {{_,Remote},_} = ssh_connection_handler:get_print_info(ConnManager), [io_lib:format(?INDENT?INDENT"Remote: ~s ConnectionRef = ~p~n",[fmt_host_port(Remote),ConnManager]), lists:map(fun print_ch/1, ChannelPids) @@ -159,7 +159,7 @@ print_channels({{server,ssh_connection_sup,_,_},Pid,supervisor,[ssh_connection_s print_ch(Pid) -> try - {{ConnManager,ChannelID}, Str} = ssh_daemon_channel:get_print_info(Pid), + {{ConnManager,ChannelID}, Str} = ssh_server_channel:get_print_info(Pid), {_LocalRemote,StrM} = ssh_connection_handler:get_print_info(ConnManager), io_lib:format(?INDENT?INDENT?INDENT"ch ~p ~p: ~s ~s~n",[ChannelID, Pid, StrM, Str]) catch diff --git a/lib/ssh/src/ssh_server_channel.erl b/lib/ssh/src/ssh_server_channel.erl new file mode 100644 index 0000000000..117b7855e2 --- /dev/null +++ b/lib/ssh/src/ssh_server_channel.erl @@ -0,0 +1,55 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2013-2016. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +%% +%% Description: a gen_server implementing a simple +%% terminal (using the group module) for a CLI +%% over SSH + +-module(ssh_server_channel). + +%% API to server side channel that can be pluged into the erlang ssh daemeon +-callback init(Args :: term()) -> + {ok, State :: term()} | {ok, State :: term(), timeout() | hibernate} | + {stop, Reason :: term()} | ignore. + +-callback terminate(Reason :: (normal | shutdown | {shutdown, term()} | + term()), + State :: term()) -> + term(). + +-callback handle_msg(Msg ::term(), State :: term()) -> + {ok, State::term()} | {stop, ChannelId::ssh:channel_id(), State::term()}. +-callback handle_ssh_msg({ssh_cm, ConnectionRef::ssh:connection_ref(), SshMsg::term()}, + State::term()) -> {ok, State::term()} | + {stop, ChannelId::ssh:channel_id(), + State::term()}. + +%%% Internal API +-export([start_link/5, + get_print_info/1 + ]). + +start_link(ConnectionManager, ChannelId, CallBack, CbInitArgs, Exec) -> + ssh_channel:start_link(ConnectionManager, ChannelId, CallBack, CbInitArgs, Exec). + + +get_print_info(Pid) -> + ssh_channel:get_print_info(Pid). diff --git a/lib/ssh/src/ssh_server_channel_sup.erl b/lib/ssh/src/ssh_server_channel_sup.erl new file mode 100644 index 0000000000..70799db714 --- /dev/null +++ b/lib/ssh/src/ssh_server_channel_sup.erl @@ -0,0 +1,62 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2008-2016. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +%% +%%---------------------------------------------------------------------- +%% Purpose: Ssh channel supervisor. +%%---------------------------------------------------------------------- +-module(ssh_server_channel_sup). + +-behaviour(supervisor). + +-export([start_link/1, start_child/5]). + +%% Supervisor callback +-export([init/1]). + +%%%========================================================================= +%%% Internal API +%%%========================================================================= +start_link(Args) -> + supervisor:start_link(?MODULE, [Args]). + +start_child(Sup, Callback, Id, Args, Exec) -> + ChildSpec = + #{id => make_ref(), + start => {ssh_server_channel, start_link, [self(), Id, Callback, Args, Exec]}, + restart => temporary, + type => worker, + modules => [ssh_server_channel] + }, + supervisor:start_child(Sup, ChildSpec). + +%%%========================================================================= +%%% Supervisor callback +%%%========================================================================= +init(_Args) -> + RestartStrategy = one_for_one, + MaxR = 10, + MaxT = 3600, + Children = [], + {ok, {{RestartStrategy, MaxR, MaxT}, Children}}. + +%%%========================================================================= +%%% Internal functions +%%%========================================================================= diff --git a/lib/ssh/src/ssh_sftpd.erl b/lib/ssh/src/ssh_sftpd.erl index fda9a38a43..cb2eab1fec 100644 --- a/lib/ssh/src/ssh_sftpd.erl +++ b/lib/ssh/src/ssh_sftpd.erl @@ -24,7 +24,7 @@ -module(ssh_sftpd). --behaviour(ssh_daemon_channel). +-behaviour(ssh_server_channel). -include_lib("kernel/include/file.hrl"). diff --git a/lib/ssh/src/ssh_shell.erl b/lib/ssh/src/ssh_shell.erl index 6470f4c492..084daa6821 100644 --- a/lib/ssh/src/ssh_shell.erl +++ b/lib/ssh/src/ssh_shell.erl @@ -27,9 +27,9 @@ %%% As this is an user interactive client it behaves like a daemon %%% channel inspite of it being a client. --behaviour(ssh_daemon_channel). +-behaviour(ssh_server_channel). -%% ssh_daemon_channel callbacks +%% ssh_server_channel callbacks -export([init/1, handle_msg/2, handle_ssh_msg/2, terminate/2]). %% Spawn export @@ -46,7 +46,7 @@ ). %%==================================================================== -%% ssh_daemon_channel callbacks +%% ssh_server_channel callbacks %%==================================================================== %%-------------------------------------------------------------------- diff --git a/lib/ssh/src/ssh_subsystem_sup.erl b/lib/ssh/src/ssh_subsystem_sup.erl index f1e74a24ac..f80be7f20b 100644 --- a/lib/ssh/src/ssh_subsystem_sup.erl +++ b/lib/ssh/src/ssh_subsystem_sup.erl @@ -48,7 +48,7 @@ connection_supervisor(SupPid) -> channel_supervisor(SupPid) -> Children = supervisor:which_children(SupPid), - ssh_daemon_channel_sup(Children). + ssh_server_channel_sup(Children). %%%========================================================================= %%% Supervisor callback @@ -78,8 +78,8 @@ ssh_connection_child_spec(Role, Address, Port, _Profile, Options) -> }. ssh_channel_child_spec(Role, Address, Port, _Profile, Options) -> - #{id => id(Role, ssh_daemon_channel_sup, Address, Port), - start => {ssh_daemon_channel_sup, start_link, [Options]}, + #{id => id(Role, ssh_server_channel_sup, Address, Port), + start => {ssh_server_channel_sup, start_link, [Options]}, restart => temporary, type => supervisor }. @@ -92,10 +92,10 @@ ssh_connection_sup([{_, Child, _, [ssh_connection_sup]} | _]) -> ssh_connection_sup([_ | Rest]) -> ssh_connection_sup(Rest). -ssh_daemon_channel_sup([{_, Child, _, [ssh_daemon_channel_sup]} | _]) -> +ssh_server_channel_sup([{_, Child, _, [ssh_server_channel_sup]} | _]) -> Child; -ssh_daemon_channel_sup([_ | Rest]) -> - ssh_daemon_channel_sup(Rest). +ssh_server_channel_sup([_ | Rest]) -> + ssh_server_channel_sup(Rest). diff --git a/lib/ssh/test/property_test/ssh_eqc_subsys.erl b/lib/ssh/test/property_test/ssh_eqc_subsys.erl index 30b254b9c0..e7de3ea068 100644 --- a/lib/ssh/test/property_test/ssh_eqc_subsys.erl +++ b/lib/ssh/test/property_test/ssh_eqc_subsys.erl @@ -21,7 +21,7 @@ -module(ssh_eqc_subsys). --behaviour(ssh_daemon_channel). +-behaviour(ssh_server_channel). -export([init/1, handle_msg/2, handle_ssh_msg/2, terminate/2]). diff --git a/lib/ssh/test/ssh_bench_dev_null.erl b/lib/ssh/test/ssh_bench_dev_null.erl index 5166247714..f9da80b6d7 100644 --- a/lib/ssh/test/ssh_bench_dev_null.erl +++ b/lib/ssh/test/ssh_bench_dev_null.erl @@ -22,7 +22,7 @@ %%% Description: Example ssh server -module(ssh_bench_dev_null). --behaviour(ssh_daemon_channel). +-behaviour(ssh_server_channel). -record(state, { cm, diff --git a/lib/ssh/test/ssh_echo_server.erl b/lib/ssh/test/ssh_echo_server.erl index 5387d21efd..d03fe9543e 100644 --- a/lib/ssh/test/ssh_echo_server.erl +++ b/lib/ssh/test/ssh_echo_server.erl @@ -22,7 +22,7 @@ %%% Description: Example ssh server -module(ssh_echo_server). --behaviour(ssh_daemon_channel). +-behaviour(ssh_server_channel). -record(state, { n, id, diff --git a/lib/ssh/test/ssh_peername_sockname_server.erl b/lib/ssh/test/ssh_peername_sockname_server.erl index 8731d80f62..5e35fd6612 100644 --- a/lib/ssh/test/ssh_peername_sockname_server.erl +++ b/lib/ssh/test/ssh_peername_sockname_server.erl @@ -26,7 +26,7 @@ %% ssh connection. --behaviour(ssh_daemon_channel). +-behaviour(ssh_server_channel). -record(state, {}). -export([init/1, handle_msg/2, handle_ssh_msg/2, terminate/2]). diff --git a/lib/ssh/test/ssh_sup_SUITE.erl b/lib/ssh/test/ssh_sup_SUITE.erl index ed1840640b..b81f66948d 100644 --- a/lib/ssh/test/ssh_sup_SUITE.erl +++ b/lib/ssh/test/ssh_sup_SUITE.erl @@ -290,7 +290,7 @@ shell_channel_tree(Config) -> {ok, ChannelId0} = ssh_connection:session_channel(ConnectionRef, infinity), ok = ssh_connection:shell(ConnectionRef,ChannelId0), - ?wait_match([{_, GroupPid,worker,[ssh_daemon_channel]}], + ?wait_match([{_, GroupPid,worker,[ssh_server_channel]}], supervisor:which_children(ChannelSup), [GroupPid]), {links,GroupLinks} = erlang:process_info(GroupPid, links), @@ -339,9 +339,9 @@ chk_empty_con_daemon(Daemon) -> ?wait_match([{{server,ssh_connection_sup, _,_}, ConnectionSup, supervisor, [ssh_connection_sup]}, - {{server,ssh_daemon_channel_sup,_ ,_}, + {{server,ssh_server_channel_sup,_ ,_}, ChannelSup,supervisor, - [ssh_daemon_channel_sup]}], + [ssh_server_channel_sup]}], supervisor:which_children(SubSysSup), [ConnectionSup,ChannelSup]), ?wait_match([{{ssh_acceptor_sup,_,_,_},_,worker,[ssh_acceptor]}], @@ -372,9 +372,9 @@ check_sshd_system_tree(Daemon, Config) -> ?wait_match([{{server,ssh_connection_sup, _,_}, ConnectionSup, supervisor, [ssh_connection_sup]}, - {{server,ssh_daemon_channel_sup,_ ,_}, + {{server,ssh_server_channel_sup,_ ,_}, ChannelSup,supervisor, - [ssh_daemon_channel_sup]}], + [ssh_server_channel_sup]}], supervisor:which_children(SubSysSup), [ConnectionSup,ChannelSup]), @@ -388,7 +388,7 @@ check_sshd_system_tree(Daemon, Config) -> ssh_sftp:start_channel(Client), - ?wait_match([{_, _,worker,[ssh_daemon_channel]}], + ?wait_match([{_, _,worker,[ssh_server_channel]}], supervisor:which_children(ChannelSup)), ssh:close(Client). -- cgit v1.2.3