Sv: Sv: Setting Dscp (tos, QoS) for ssh sockets

Christofer Tornkvist (ctornkvi) ctornkvi@REDACTED
Wed Feb 19 15:25:30 CET 2020


Hi Hans,

is the SshConnection the same as the Pid of the Connection Handler ?

Or put otherwise, is it so that, my callback channel module should know about this SshConnection ?

If that is the case, then this solution would be great.

Regards
/Christofer
________________________________
Från: erlang-questions <erlang-questions-bounces@REDACTED> för Hans Nilsson R <hans.r.nilsson@REDACTED>
Skickat: den 19 februari 2020 13:45
Till: Per Hedeland <per@REDACTED>; erlang-questions@REDACTED <erlang-questions@REDACTED>
Ämne: Sv: Sv: Setting Dscp (tos, QoS) for ssh sockets

Hej Per!

So an ssh:setopts(SshConnection, InetOptions) and an ssh:getopts similar to two functions in inet would solve the problem?

/Hans

________________________________
Från: erlang-questions <erlang-questions-bounces@REDACTED> för Per Hedeland <per@REDACTED>
Skickat: den 18 februari 2020 14:08
Till: erlang-questions@REDACTED <erlang-questions@REDACTED>
Ämne: Re: Sv: Setting Dscp (tos, QoS) for ssh sockets

On 2020-02-18 12:58, Hans Nilsson R wrote:
> It is both possible and documented to give the gen_tcp:connect_options() in a call to ssh:connect.
>
> See
>     https://protect2.fireeye.com/v1/url?k=6eb80c5a-326c0004-6eb84cc1-8691959ed9b7-0b75d45a9ce427c8&q=1&e=1e4ceab2-3f29-4036-8a8c-cc4774d3d176&u=https%3A%2F%2Ferlang.org%2Fdoc%2Fman%2Fssh.html%23type-client_option
>
> where second from last is a link to
>     https://protect2.fireeye.com/v1/url?k=a1d9ada1-fd0da1ff-a1d9ed3a-8691959ed9b7-d0da1a82086ec97e&q=1&e=1e4ceab2-3f29-4036-8a8c-cc4774d3d176&u=https%3A%2F%2Ferlang.org%2Fdoc%2Fman%2Fgen_tcp.html%23type-connect_option

Sorry, don't know how I missed that - too much going back and forth
between the "textual" man pages for ssh and gen_tcp, perhaps... And
indeed gen_tcp:listen_option() is also listed for daemon_option(). So
there is no problem whatsoever with setting DSCP at the start of a
connection.

Is there also some "clean" way within ssh to address Christofer's and
Dmytro's original question (below), which I managed to obscure - i.e.
setting DSCP for an already established connection? (Which is needed
for an implementation of RFC 8639.)

--Per

> Let's try:
>
> Eshell V10.6.4  (abort with ^G)
> 1> ssh:start().
> ok
> 2> dbg:start().
> {ok,<0.92.0>}
> 3> dbg:tracer().
> {ok,<0.92.0>}
> 4> dbg:p(all,c).
> {ok,[{matched,nonode@REDACTED,46}]}
> 5> dbg:tp(gen_tcp,connect,x).
> {ok,[{matched,nonode@REDACTED,2},{saved,x}]}
> 6>
> 6> ssh:connect(loopback, 22, [{nodelay,true}, {tos,14}, {raw,1,2,<<3>>}]).
> (<0.80.0>) call gen_tcp:connect({127,0,0,1},22,[{active,false},{raw,1,2,<<3>>},{tos,14},{nodelay,true}],infinity)
> (<0.80.0>) returned from gen_tcp:connect/4 -> {ok,#Port<0.6>}
> {ok,<0.99.0>}
> 7>
>
> The gen_tcp options in 6> are really passed down to gen_tcp:connect.
>
> /Hans
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *Från:* erlang-questions <erlang-questions-bounces@REDACTED> för Per Hedeland <per@REDACTED>
> *Skickat:* den 17 februari 2020 20:44
> *Till:* erlang-questions@REDACTED <erlang-questions@REDACTED>
> *Ämne:* Re: Setting Dscp (tos, QoS) for ssh sockets
>
> On 2020-02-17 16:03, Per Hedeland wrote:
>  > On 2020-02-17 11:22, Dmytro Lytovchenko wrote:
>  >  > As we discussed with you before, there are two options right now:
>  >  >
>  >  > 1. From SSH connection handler, using sys module, request its state (private #data{} record) which contains the socket in its 9th field.
>  >  > 2. (Christofer's idea) to replace the socket transport module using undocumented option {transport, {_, Module, _}}
>  >  >
>  >  > Maybe someone sees other ways to do it?
>  >
>  > Why would you need to use inet:setopts/2 specifically? Changing DSCP
>  > on the fly is probably not meaningful in general, and from what I know
>  > about your application, not required there (but maybe I'm wrong about
>  > that).
>
> I learned off-list that this requirement comes from RFC 8639, where a
> NETCONF client/subscriber can request that the server uses a specific
> DSCP value in the "establish-subscription" RPC (which is sent in an
> already established session a.k.a. SSH channel). Surely OTP ssh should
> support this in a "nice/clean" way...?
>
>  > IMHO it would be reasonable to allow most/all options that can be
>  > given to gen_tcp:connect/3,4 and gen_tcp:listen/2 (which both have
>  > 'tos' as option), respectively, also for ssh:connect/2,3,4 and
>  > ssh:daemon/2,3 - maybe it is allowed, but if so not documented, as far
>  > as I can see.
>  >
>  > Alternatively you can at least for ssh:connect/2,3 apparently pass an
>  > already connected socket from gen_tcp:connect(), where you can pass
>  > 'tos' to the latter. It seems the socket that can be passed to
>  > ssh:daemon/2,3 should be from gen_tcp:accept() - it would seem more
>  > natural to me to pass a "listen socket" from gen_tcp:listen() (which
>  > can be passed 'tos'), but I guess you can do the accept-loop outside
>  > ssh and use inet:setopts/2 on the socket from gen_tcp:accept() before
>  > passing it to ssh:daemon/2,3.
>
> For this alternative, the way to go would rather be to pass the 'tos'
> option to gen_tcp:listen(), and have it be "inherited" by the sockets
> returned from gen_tcp:accept() - i.e. no need for inet:setopts/2
> there. But of course neither alternative supports changing the DSCP
> value for an already established connection.
>
> --Per
>
>  >  > On Mon, 17 Feb 2020 at 11:12, Christofer Tornkvist (ctornkvi) <ctornkvi@REDACTED <mailto:ctornkvi@REDACTED>> wrote:
>  >  >
>  >  >     Hi,
>  >  >
>  >  >     I would like to set the quality of service flag Dscp of the Tos field in the IP packet
>  >  >     of an Ssh socket with the function inet:setopts(Socket, [{tos, Dscp}]).
>  >  >
>  >  >     It should be possible to set the Dscp per IP packet sent.
>  >  >
>  >  >     How do I get hold of the Ssh socket down in my Ssh channel module ?
>  >  >
>  >  >
>  >  >     Regards
>  >  >     /Christofer
>  >  >
>  >  >
>  >  >
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200219/5df76a54/attachment.htm>


More information about the erlang-questions mailing list