[net.unix-wizards] Dialing in and out

bobvan (09/21/82)

There has been much talk recently in this news group about using tty
lines both for dialing in and dialing out.  I have been watching with
great interest as our site has such a Vadic VA811 dialer and four
triple modems in a MACS configuration.  Up until recently, we had
been using one modem for dialing out and the other three for incoming
calls.

Three weeks ago, I installed changes that allow us to dial in or out on
any of the four modems.  Most of the proposals I've seen here led me to
believe that this would difficult job requiring changes to many
different programs.

To my surprise, the change required only 25 new lines of code and
changes to 11 existing lines -- all in one file!!  It took less than
one day and worked the first time (somebody pinch me!).  No changes are
required for cu, uucp, getty, login, tty.c, or init.  There are no shell
scripts running around editing /etc/ttys and sending signals or doing
local ioctl's.

Boy, do I wish I could take credit for thinking this up, but I can't.
In among all of those complex proposals, I found an idea from Web Dove
(dove@mit-dspg@sri-unix).  He did it all under 2.8BSD and never gave
much detail when describing his scheme.  I'm writing this note to give
a little more detail and describe my 4.1BSD implementation.

So how is it done? Simple, all of the changes are in dz.c -- the DZ
device driver.  As others have suggested, you also create new inodes
for /dev/cul? that have the 128 bit set in the minor number, but are
otherwise the same as /dev/tty??.  Dzopen() can then easily tell if
this is an "incoming open" or an "outgoing open".  Incoming opens
(from init) sleep if the line is in use outgoing.  Outgoing opens fail
with EBUSY if the line is in use incoming.  Dzclose() wakes up anyone
who was sleeping, as does dzscan() when the carrier changes state.  The
fact that a line is in use outgoing is automatically recorded when
dzopen() copies the device number (with the 128 bit set) into t_dev.  A
handy fringe benefit of having two inodes for the same device is that
it is easy to control access to the dialers without having to give
excessive privilege to uucp.

There are some limitations to this idea:  you can't have more than 128
DZ lines, all of the changes are in the kernel (but they are so small),
and this only works for modems, not hard wired lines.

The code has been in operation for three weeks without any problems,
however, I am still somewhat nervous about it.  I am most concerned
about having the 128 bit set in the t_dev field of the tty struct.
I've greped for references, and they all seem to take either the major
number or the low three bits to determine the unit.  Ps, pstat and
friends who go digging thru the kernel all seem to work.  Can anyone
spot problems with this idea that I may have missed?

				Bob Van Valzah
				(...!decvax!ittvax!tpdcvax!bobvan)

henry (09/24/82)

The scheme that Bob Van Valzah discusses works fine.  We have been
running an essentially-identical setup, invented independently earlier
this year, for several months.  There is one thing you must watch,
however:  having two /dev entries sharing a tty structure and a
physical device can lead to problems with initializing and finalizing
the structure and the line.  Not unsolvable, but it needs to be thought
through carefully.  Also, the V7 tty.c does a few unfriendly things
here and there like zeroing the tty flags field on close -- not good
if you have another process waiting for the device!  Easy to work
around but you must be aware of the problem.

						Henry Spencer
						U of Toronto