<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
It is both possible and documented to give the gen_tcp:connect_options() in a call to ssh:connect.</div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
See</div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
<a href="https://erlang.org/doc/man/ssh.html#type-client_option" id="LPlnk322752">
https://erlang.org/doc/man/ssh.html#type-client_option</a></div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
where second from last is a link to</div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
<a href="https://erlang.org/doc/man/gen_tcp.html#type-connect_option" id="LPlnk370944">
https://erlang.org/doc/man/gen_tcp.html#type-connect_option</a></div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
Let's try:</div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: "Courier New", monospace; font-size: 10pt; color: rgb(0, 0, 0);">
<span>Eshell V10.6.4 (abort with ^G)<br>
</span>
<div>1> ssh:start().<br>
</div>
<div>ok<br>
</div>
<div>2> dbg:start().<br>
</div>
<div>{ok,<0.92.0>}<br>
</div>
<div>3> dbg:tracer().<br>
</div>
<div>{ok,<0.92.0>}<br>
</div>
<div>4> dbg:p(all,c).<br>
</div>
<div>{ok,[{matched,nonode@nohost,46}]}<br>
</div>
<div>5> dbg:tp(gen_tcp,connect,x).<br>
</div>
<div>{ok,[{matched,nonode@nohost,2},{saved,x}]}<br>
</div>
<div>6> <br>
</div>
<div>6> ssh:connect(loopback, 22, [{nodelay,true}, {tos,14}, {raw,1,2,<<3>>}]).<br>
</div>
<div>(<0.80.0>) call gen_tcp:connect({127,0,0,1},22,[{active,false},{raw,1,2,<<3>>},{tos,14},{nodelay,true}],infinity)<br>
</div>
<div>(<0.80.0>) returned from gen_tcp:connect/4 -> {ok,#Port<0.6>}<br>
</div>
<div>{ok,<0.99.0>}<br>
</div>
<div>7></div>
<div><br>
</div>
<div>The gen_tcp options in 6> are really passed down to gen_tcp:connect.</div>
<div><br>
</div>
<div>/Hans<br>
</div>
<span></span><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Från:</b> erlang-questions <erlang-questions-bounces@erlang.org> för Per Hedeland <per@hedeland.org><br>
<b>Skickat:</b> den 17 februari 2020 20:44<br>
<b>Till:</b> erlang-questions@erlang.org <erlang-questions@erlang.org><br>
<b>Ämne:</b> Re: Setting Dscp (tos, QoS) for ssh sockets</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On 2020-02-17 16:03, Per Hedeland wrote:<br>
> On 2020-02-17 11:22, Dmytro Lytovchenko wrote:<br>
> > As we discussed with you before, there are two options right now:<br>
> ><br>
> > 1. From SSH connection handler, using sys module, request its state (private #data{} record) which contains the socket in its 9th field.<br>
> > 2. (Christofer's idea) to replace the socket transport module using undocumented option {transport, {_, Module, _}}<br>
> ><br>
> > Maybe someone sees other ways to do it?<br>
><br>
> Why would you need to use inet:setopts/2 specifically? Changing DSCP<br>
> on the fly is probably not meaningful in general, and from what I know<br>
> about your application, not required there (but maybe I'm wrong about<br>
> that).<br>
<br>
I learned off-list that this requirement comes from RFC 8639, where a<br>
NETCONF client/subscriber can request that the server uses a specific<br>
DSCP value in the "establish-subscription" RPC (which is sent in an<br>
already established session a.k.a. SSH channel). Surely OTP ssh should<br>
support this in a "nice/clean" way...?<br>
<br>
> IMHO it would be reasonable to allow most/all options that can be<br>
> given to gen_tcp:connect/3,4 and gen_tcp:listen/2 (which both have<br>
> 'tos' as option), respectively, also for ssh:connect/2,3,4 and<br>
> ssh:daemon/2,3 - maybe it is allowed, but if so not documented, as far<br>
> as I can see.<br>
><br>
> Alternatively you can at least for ssh:connect/2,3 apparently pass an<br>
> already connected socket from gen_tcp:connect(), where you can pass<br>
> 'tos' to the latter. It seems the socket that can be passed to<br>
> ssh:daemon/2,3 should be from gen_tcp:accept() - it would seem more<br>
> natural to me to pass a "listen socket" from gen_tcp:listen() (which<br>
> can be passed 'tos'), but I guess you can do the accept-loop outside<br>
> ssh and use inet:setopts/2 on the socket from gen_tcp:accept() before<br>
> passing it to ssh:daemon/2,3.<br>
<br>
For this alternative, the way to go would rather be to pass the 'tos'<br>
option to gen_tcp:listen(), and have it be "inherited" by the sockets<br>
returned from gen_tcp:accept() - i.e. no need for inet:setopts/2<br>
there. But of course neither alternative supports changing the DSCP<br>
value for an already established connection.<br>
<br>
--Per<br>
<br>
> > On Mon, 17 Feb 2020 at 11:12, Christofer Tornkvist (ctornkvi) <ctornkvi@cisco.com <<a href="mailto:ctornkvi@cisco.com">mailto:ctornkvi@cisco.com</a>>> wrote:<br>
> ><br>
> > Hi,<br>
> ><br>
> > I would like to set the quality of service flag Dscp of the Tos field in the IP packet<br>
> > of an Ssh socket with the function inet:setopts(Socket, [{tos, Dscp}]).<br>
> ><br>
> > It should be possible to set the Dscp per IP packet sent.<br>
> ><br>
> > How do I get hold of the Ssh socket down in my Ssh channel module ?<br>
> ><br>
> ><br>
> > Regards<br>
> > /Christofer<br>
> ><br>
> ><br>
> ><br>
<br>
</div>
</span></font></div>
</body>
</html>