Re: Question about linemode implementation...

David Borman <dab@berserkly.cray.com> Wed, 27 April 1994 15:18 UTC

Received: from ietf.nri.reston.va.us by IETF.CNRI.Reston.VA.US id aa06496; 27 Apr 94 11:18 EDT
Received: from CNRI.RESTON.VA.US by IETF.CNRI.Reston.VA.US id aa06491; 27 Apr 94 11:18 EDT
Received: from timbuk.cray.com by CNRI.Reston.VA.US id aa08962; 27 Apr 94 11:18 EDT
Received: from sdiv.cray.com (ironwood.cray.com) by cray.com (Bob mailer 1.2) id AA07274; Wed, 27 Apr 94 10:09:16 CDT
Received: from berserkly.cray.com by sdiv.cray.com (5.0/CRI-5.14 Sdiv) id AA05797; Wed, 27 Apr 1994 10:09:08 +0600
Received: by berserkly.cray.com id AA08644; 5.64/CRI-4.9; Wed, 27 Apr 94 10:08:46 -0500
Received: by berserkly.cray.com id AA08638; 5.64/CRI-4.9; Wed, 27 Apr 94 10:08:33 -0500
Date: Wed, 27 Apr 1994 10:08:33 -0500
Sender: ietf-archive-request@IETF.CNRI.Reston.VA.US
From: David Borman <dab@berserkly.cray.com>
Message-Id: <9404271508.AA08638@berserkly.cray.com>
To: sparker@damrak.eng.sun.com
Subject: Re: Question about linemode implementation...
Cc: telnet-ietf@cray.com
Content-Length: 4670

Mike said it correctly, having the telnet client able to
change the state of the ECHO(TRAPSIG,EDIT) bits is like
doing
	"stty -echo(isig,icanon) </dev/tty_whatever"

> So when should it look at its pty state?  Before now there hasn't been
> anything turning on and shutting off bits like "ECHO" and "ICANON".
> The application isn't _notified_ when this stuff gets changed.  And
> applications shouldn't have to be changed to work with telnet.

Normally it isn't real useful, and can (will) confuse applications
because they don't know that the state of the pty/tty has changed.

> If the application allows echo, then it seems perfectly fine if telnet
> negotiates echo back and forth between local and remote.  It doesn't
> seem fine to me if the client can re-arrange virtual terminal behavior
> my application has specified.  It also doesn't seem right to me that
> the application should see the "echo bit" off, just because echoing
> is being done by the telnet client.

Oh my.  By these statements it now becomes clear to me that you do
not have a clear understanding of how linemode works, and what
support is needed in the terminal driver on the server to allow
linemode to work.

The goal of linemode is to offload the input character processing
from the server to the client, without any noticable change to
the application that is attached to the slave side of the pty.
The meaning of the "echo", "isig", "icanon", "oxtabs", "ixany" bits
should not change as far as the application is concerned.

On BSD systems, this is acheived via the EXTPROC bit.  This bit
is set by the telnet server when it is running in linemode.  Most
of the input processing is then skipped, because it knows that that
has already happened externally (in the client).

The usage of the ECHO option can be especially confusing if you
don't think it through.  When the server is WILL ECHO, it means
that the server will be echoing back any characters of the input
stream that need to be echoed back to the screen.  When the server
is WONT ECHO, it means that the server will not be echoing back
any of the input characters, so the client will be responsabile
for doing any character echo back to the screen that needs to be
done.

So, with this in mind, with the EXTPROC bit set the terminal
driver on the server will never echo any characters, no matter
what the state of the "echo" bit in the tty.  When the "echo"
bit is set in the tty, the server will negotiate "WONT ECHO",
which tells the client that it needs to do any terminal echo.
When the "echo" is off, the server will negotiate "WILL ECHO",
which tells the client that it should not do any terminal echo,
because the server will take care of any that needs to be done.
But the server doesn't do any echoing, so you get the effect that
you want, no terminal echo.  When the application turns the "echo"
bit back on, the server negotiates "WONT ECHO" again.

As an example, here is what happens on a BSD system when turning
off and on various state bits in the tty, when telnet option
debugging is turned on:

	% stty -icanon
	RCVD IAC SB LINEMODE MODE TRAPSIG|SOFT_TAB
	SENT IAC SB LINEMODE MODE TRAPSIG|SOFT_TAB|ACK
	% stty icanon
	RCVD IAC SB LINEMODE MODE EDIT|TRAPSIG|SOFT_TAB
	SENT IAC SB LINEMODE MODE EDIT|TRAPSIG|SOFT_TAB|ACK
	% stty -echo
	RCVD WILL ECHO
	SENT DO ECHO
	% <typed "stty echo">
	RCVD WONT ECHO
	SENT DONT ECHO
	% stty -isig
	RCVD IAC SB LINEMODE MODE EDIT|SOFT_TAB
	SENT IAC SB LINEMODE MODE EDIT|SOFT_TAB|ACK
	% stty isig
	RCVD IAC SB LINEMODE MODE EDIT|TRAPSIG|SOFT_TAB
	SENT IAC SB LINEMODE MODE EDIT|TRAPSIG|SOFT_TAB|ACK
	% stty -oxtabs
	RCVD IAC SB LINEMODE MODE EDIT|TRAPSIG
	SENT IAC SB LINEMODE MODE EDIT|TRAPSIG|ACK
	% stty oxtabs
	RCVD IAC SB LINEMODE MODE EDIT|TRAPSIG|SOFT_TAB
	SENT IAC SB LINEMODE MODE EDIT|TRAPSIG|SOFT_TAB|ACK
	% stty -ixon
	RCVD IAC SB TOGGLE-FLOW-CONTROL OFF
	% stty ixon
	RCVD IAC SB TOGGLE-FLOW-CONTROL ON
	% stty -ixany
	RCVD IAC SB TOGGLE-FLOW-CONTROL RESTART-XON
	% stty ixany
	RCVD IAC SB TOGGLE-FLOW-CONTROL RESTART-ANY

The two features that need to be implemented in the terminal driver
on the server is:
	1) The ability to turn off input character processing
	   (including character echo), by having the terminal
	   driver ignore those state bits (icanon, echo, isig,
	   etc.)  In BSD this is done through the EXTPROC bit.
	2) The application on the master pty side has to be
	   notified whenever the state of the pty changes, so
	   that it can negotiate the appropriate new state with
	   the client.

Without both of these features, you cannot do a transparent (to
the application) implementation of server linemode.

		-David Borman, dab@cray.com