Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 04 Oct 1998 21:24:42 -0400 (EDT)
From:      Tom Rush <tom@chattpiano.com>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   Loadable line disciplines
Message-ID:  <199810050124.VAA00729@chattpiano.com>

next in thread | raw e-mail | index | archive | help

I have written a pseudo-device driver and assorted support programs for
using IP on an Amateur Packet Radio network, and have been running it
since about 2.1.5-RELEASE (I'm using -stable now).  The driver uses
a variant of the SLIP line discipline to communicate with a TNC, a kind
of "radio modem".

Since writing the driver, I have had a couple of ideas about the line
discipline handling.  One, putting the "hotchar" in the linesw struct
and thus eliminating the check for SLIPDISC and PPPDISC in the serial
drivers, has already been implemented in -current by someone else.  The
other, concerning the loadable line discipline setup, has not been dealt
with; a search of the -hackers archive shows that the topic came up
earlier this year, but nothing has changed.

The problem, basically, is that if the "ldisc_register()" function is
used for a non-standard line discipline, a user program cannot determine
which slot in the linesw table it was assigned to, and thus cannot set
up the tty to use that discipline.

Obviously, no one has been losing sleep over this, since there aren't
too many line discipline implementations being written these days; and
if you aren't involved with maintaining tty drivers, you might want to
move on to the next message.  But if the loadable discipline feature is
going to be in there, it ought to at least be useful; and it may have
application for some of the current discussions about graphics tablets,
etc.  (see kern/tty_tb.c; it's apparently broken now, but how badly?)

In order to fix this in a way that affects the smallest number of lines
of code, I think a couple of fields should be added to the linesw struct,
(sys/conf.h) as follows:

struct linesw {
        l_open_t        *l_open;
        l_close_t       *l_close;
        l_read_t        *l_read;
        l_write_t       *l_write;
        l_ioctl_t       *l_ioctl;
        l_rint_t        *l_rint;
        l_start_t       *l_start;
        l_modem_t       *l_modem;
+       int             l_disc;
+       char    l_name[7];
        u_char  l_hotchar;
};

"l_disc" would be used as an identifier, e.g., TTYDISC or SLIPDISC.
This would allow any discipline to occupy any position in the table.
Any positive integer (not just 0-7) would be a valid ID; an empty slot
in the table would have l_disc = NULLDISC, #define'd as -1.

"l_name" would contain a name for the discipline, e.g. "ppp" or "slip".
This field is not necessary, but it eliminates the switch statement in
pstat that displays the discipline name. (This means that a discipline
would not have to have it's ID in ttycom.h, and a case added to that
switch statement, to have it's name displayed.)

In kern/tty_conf.c, only TTYDISC (termios), and NTTYDISC if COMPAT_43
is defined, are loaded by default.  TTYDISC must be #define'd as 0 and
go in slot 0; it is the only discipline that maintains the original
"discipline = slot" relationship.

"ldisc_register()" (which could get rid of the "discipline" argument,
since that would be contained in the linesw struct) would check for a
valid discipline ID, and then check the linesw table for duplicate ID's.
The first vacant slot would be used for the new discipline if no dupes
were found.

In kern/tty.c, TIOCGETD would return linesw[tp->t_line].l_disc rather
than tp->t_line.  TIOCSETD would scan the linesw table looking for a
matching discipline, then set tp->t_line to the corresponding slot
number.

Each line discipline module would have to call ldisc_register() in it's
init routine to be assigned a slot in the linesw table.

After that, the main things to look for are references to t_line
(in the tty struct) that use it as a value rather than just an index.
There are actually not too many of these, particularly since the hotchar
field was placed in the linesw struct.

Rather that post a bunch of diffs here, I packaged them up and put them
at ftp://ftp.mindspring.com/users/tarush/ldiscload.tar.gz.  Note that
these diffs are for -stable; they may or may not patch cleanly on -current.

If anyone cares, please take a look at these and let me know what you
think.

Thanks,

---
Tom Rush
tom@chattpiano.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810050124.VAA00729>