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

Hans Nilsson R hans.r.nilsson@REDACTED
Tue Feb 18 12:58:17 CET 2020


It is both possible and documented to give the gen_tcp:connect_options() in a call to ssh:connect.

See
    https://erlang.org/doc/man/ssh.html#type-client_option

where second from last is a link to
    https://erlang.org/doc/man/gen_tcp.html#type-connect_option

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/20200218/c98c7fa3/attachment.htm>


More information about the erlang-questions mailing list