1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1987, 1989, 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)if_sl.c 8.6 (Berkeley) 2/1/94
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Serial Line interface
|
|
|
|
*
|
|
|
|
* Rick Adams
|
|
|
|
* Center for Seismic Studies
|
|
|
|
* 1300 N 17th Street, Suite 1450
|
|
|
|
* Arlington, Virginia 22209
|
|
|
|
* (703)276-7900
|
|
|
|
* rick@seismo.ARPA
|
|
|
|
* seismo!rick
|
|
|
|
*
|
|
|
|
* Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
|
|
|
|
* N.B.: this belongs in netinet, not net, the way it stands now.
|
|
|
|
* Should have a link-layer type designation, but wouldn't be
|
|
|
|
* backwards-compatible.
|
|
|
|
*
|
|
|
|
* Converted to 4.3BSD Beta by Chris Torek.
|
|
|
|
* Other changes made at Berkeley, based in part on code by Kirk Smith.
|
|
|
|
* W. Jolitz added slip abort.
|
|
|
|
*
|
|
|
|
* Hacked almost beyond recognition by Van Jacobson (van@helios.ee.lbl.gov).
|
|
|
|
* Added priority queuing for "interactive" traffic; hooks for TCP
|
|
|
|
* header compression; ICMP filtering (at 2400 baud, some cretin
|
|
|
|
* pinging you can use up all your bandwidth). Made low clist behavior
|
|
|
|
* more robust and slightly less likely to hang serial line.
|
|
|
|
* Sped up a bunch of things.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-05-24 10:09:53 +00:00
|
|
|
* Note that splimp() is used throughout to block both (tty) input
|
|
|
|
* interrupts and network activity; thus, splimp must be >= spltty.
|
|
|
|
*/
|
|
|
|
|
1998-01-08 23:42:31 +00:00
|
|
|
#include "opt_inet.h"
|
1999-01-21 08:29:12 +00:00
|
|
|
#include "opt_slip.h"
|
2000-09-26 18:34:30 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
1994-08-18 22:36:09 +00:00
|
|
|
#include <sys/systm.h>
|
1997-07-28 14:57:10 +00:00
|
|
|
#include <sys/malloc.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/mbuf.h>
|
2001-09-12 08:38:13 +00:00
|
|
|
#include <sys/proc.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/socket.h>
|
1997-03-24 11:33:46 +00:00
|
|
|
#include <sys/sockio.h>
|
1997-03-23 03:37:54 +00:00
|
|
|
#include <sys/fcntl.h>
|
1995-04-02 00:11:48 +00:00
|
|
|
#include <sys/signalvar.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/tty.h>
|
1995-03-16 18:17:34 +00:00
|
|
|
#include <sys/clist.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
2001-01-31 07:58:58 +00:00
|
|
|
#include <sys/module.h>
|
2002-02-23 11:12:57 +00:00
|
|
|
#include <sys/proc.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
|
|
|
|
#if INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#else
|
1998-01-08 23:42:31 +00:00
|
|
|
#error "Huh? Slip without inet?"
|
1994-05-24 10:09:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <net/slcompress.h>
|
|
|
|
#include <net/if_slvar.h>
|
|
|
|
#include <net/slip.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
2000-05-30 13:47:03 +00:00
|
|
|
static MALLOC_DEFINE(M_SL, "sl", "SLIP Interface");
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1994-09-13 16:05:50 +00:00
|
|
|
* SLRMAX is a hard limit on input packet size. To simplify the code
|
1994-05-24 10:09:53 +00:00
|
|
|
* and improve performance, we require that packets fit in an mbuf
|
|
|
|
* cluster, and if we get a compressed packet, there's enough extra
|
|
|
|
* room to expand the header into a max length tcp/ip header (128
|
1994-09-13 16:05:50 +00:00
|
|
|
* bytes). So, SLRMAX can be at most
|
1994-05-24 10:09:53 +00:00
|
|
|
* MCLBYTES - 128
|
|
|
|
*
|
1994-09-13 16:05:50 +00:00
|
|
|
* SLMTU is the default transmit MTU. The transmit MTU should be kept
|
|
|
|
* small enough so that interactive use doesn't suffer, but large
|
|
|
|
* enough to provide good performance. 552 is a good choice for SLMTU
|
|
|
|
* because it is high enough to not fragment TCP packets being routed
|
|
|
|
* through this host. Packet fragmentation is bad with SLIP because
|
|
|
|
* fragment headers aren't compressed. The previous assumptions about
|
|
|
|
* the best MTU value don't really hold when using modern modems with
|
|
|
|
* BTLZ data compression because the modem buffers play a much larger
|
|
|
|
* role in interactive performance than the MTU. The MTU can be changed
|
|
|
|
* at any time to suit the specific environment with ifconfig(8), and
|
|
|
|
* its maximum value is defined as SLTMAX. SLTMAX must not be so large
|
1994-11-26 19:24:13 +00:00
|
|
|
* that it would overflow the stack if BPF is configured (XXX; if_ppp.c
|
|
|
|
* handles this better).
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
1994-09-13 16:05:50 +00:00
|
|
|
* SLIP_HIWAT is the amount of data that will be queued 'downstream'
|
|
|
|
* of us (i.e., in clists waiting to be picked up by the tty output
|
|
|
|
* interrupt). If we queue a lot of data downstream, it's immune to
|
|
|
|
* our t.o.s. queuing.
|
1994-05-24 10:09:53 +00:00
|
|
|
* E.g., if SLIP_HIWAT is 1024, the interactive traffic in mixed
|
|
|
|
* telnet/ftp will see a 1 sec wait, independent of the mtu (the
|
|
|
|
* wait is dependent on the ftp window size but that's typically
|
|
|
|
* 1k - 4k). So, we want SLIP_HIWAT just big enough to amortize
|
|
|
|
* the cost (in idle time on the wire) of the tty driver running
|
|
|
|
* off the end of its clists & having to call back slstart for a
|
|
|
|
* new packet. For a tty interface with any buffering at all, this
|
|
|
|
* cost will be zero. Even with a totally brain dead interface (like
|
|
|
|
* the one on a typical workstation), the cost will be <= 1 character
|
|
|
|
* time. So, setting SLIP_HIWAT to ~100 guarantees that we'll lose
|
|
|
|
* at most 1% while maintaining good interactive response.
|
|
|
|
*/
|
|
|
|
#define BUFOFFSET (128+sizeof(struct ifnet **)+SLIP_HDRLEN)
|
1994-09-13 16:05:50 +00:00
|
|
|
#define SLRMAX (MCLBYTES - BUFOFFSET)
|
|
|
|
#define SLBUFSIZE (SLRMAX + BUFOFFSET)
|
1994-09-09 12:58:10 +00:00
|
|
|
#ifndef SLMTU
|
1994-09-13 16:05:50 +00:00
|
|
|
#define SLMTU 552 /* default MTU */
|
1994-09-09 12:58:10 +00:00
|
|
|
#endif
|
1994-11-26 19:24:13 +00:00
|
|
|
#define SLTMAX 1500 /* maximum MTU */
|
1994-05-24 10:09:53 +00:00
|
|
|
#define SLIP_HIWAT roundup(50,CBSIZE)
|
1994-09-13 16:05:50 +00:00
|
|
|
#define CLISTRESERVE 1024 /* Can't let clists get too low */
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* SLIP ABORT ESCAPE MECHANISM:
|
|
|
|
* (inspired by HAYES modem escape arrangement)
|
|
|
|
* 1sec escape 1sec escape 1sec escape { 1sec escape 1sec escape }
|
|
|
|
* within window time signals a "soft" exit from slip mode by remote end
|
|
|
|
* if the IFF_DEBUG flag is on.
|
|
|
|
*/
|
|
|
|
#define ABT_ESC '\033' /* can't be t_intr - distant host must know it*/
|
|
|
|
#define ABT_IDLE 1 /* in seconds - idle before an escape */
|
|
|
|
#define ABT_COUNT 3 /* count of escapes for abort */
|
|
|
|
#define ABT_WINDOW (ABT_COUNT*2+2) /* in seconds - time to count */
|
|
|
|
|
2002-01-08 10:30:09 +00:00
|
|
|
static LIST_HEAD(sl_list, sl_softc) sl_list;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#define FRAME_END 0xc0 /* Frame End */
|
|
|
|
#define FRAME_ESCAPE 0xdb /* Frame Esc */
|
|
|
|
#define TRANS_FRAME_END 0xdc /* transposed frame end */
|
|
|
|
#define TRANS_FRAME_ESCAPE 0xdd /* transposed frame esc */
|
|
|
|
|
2002-03-19 21:54:18 +00:00
|
|
|
static int slisstatic(int);
|
|
|
|
static void slmarkstatic(int);
|
|
|
|
static struct sl_softc *slcreate(void);
|
|
|
|
static void sldestroy(struct sl_softc *sc);
|
|
|
|
static struct mbuf *sl_btom(struct sl_softc *, int);
|
1995-04-02 00:11:48 +00:00
|
|
|
static timeout_t sl_keepalive;
|
|
|
|
static timeout_t sl_outfill;
|
2001-09-12 08:38:13 +00:00
|
|
|
static l_close_t slclose;
|
|
|
|
static l_rint_t slinput;
|
|
|
|
static l_ioctl_t sltioctl;
|
2002-03-19 21:54:18 +00:00
|
|
|
static int slioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static int slopen(dev_t, struct tty *);
|
|
|
|
static int sloutput(struct ifnet *,
|
|
|
|
struct mbuf *, struct sockaddr *, struct rtentry *);
|
|
|
|
static int slstart(struct tty *);
|
1994-10-05 21:22:45 +00:00
|
|
|
|
1995-11-05 20:25:59 +00:00
|
|
|
static struct linesw slipdisc = {
|
|
|
|
slopen, slclose, l_noread, l_nowrite,
|
1998-02-13 12:46:28 +00:00
|
|
|
sltioctl, slinput, slstart, ttymodem,
|
|
|
|
FRAME_END
|
1995-11-05 20:25:59 +00:00
|
|
|
};
|
1994-10-05 21:22:45 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Called from boot code to establish sl interfaces.
|
|
|
|
*/
|
2001-01-31 07:58:58 +00:00
|
|
|
static int
|
|
|
|
sl_modevent(module_t mod, int type, void *data)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
linesw[SLIPDISC] = slipdisc;
|
|
|
|
LIST_INIT(&sl_list);
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
printf("if_sl module unload - not possible for this module type\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static moduledata_t sl_mod = {
|
|
|
|
"if_sl",
|
|
|
|
sl_modevent,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_MODULE(if_sl, sl_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2000-05-30 13:47:03 +00:00
|
|
|
static int *st_unit_list;
|
|
|
|
static size_t st_unit_max = 0;
|
|
|
|
|
2001-01-31 07:58:58 +00:00
|
|
|
static int
|
|
|
|
slisstatic(unit)
|
2000-05-30 13:47:03 +00:00
|
|
|
int unit;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2000-05-30 13:47:03 +00:00
|
|
|
size_t i;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2000-05-30 13:47:03 +00:00
|
|
|
for (i = 0; i < st_unit_max; i++)
|
|
|
|
if (st_unit_list[i] == unit)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-31 07:58:58 +00:00
|
|
|
static void
|
|
|
|
slmarkstatic(unit)
|
2000-05-30 13:47:03 +00:00
|
|
|
int unit;
|
|
|
|
{
|
|
|
|
int *t;
|
|
|
|
|
|
|
|
if (slisstatic(unit))
|
|
|
|
return;
|
|
|
|
|
|
|
|
MALLOC(t, int *, sizeof(int) * (st_unit_max+1), M_SL, M_NOWAIT);
|
|
|
|
if (t == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (st_unit_list) {
|
|
|
|
bcopy(st_unit_list, t, sizeof(int) * st_unit_max);
|
2002-04-04 06:03:17 +00:00
|
|
|
free(st_unit_list, M_SL);
|
2000-05-30 13:47:03 +00:00
|
|
|
}
|
|
|
|
st_unit_list = t;
|
|
|
|
st_unit_list[st_unit_max] = unit;
|
|
|
|
st_unit_max++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sl_softc *
|
|
|
|
slcreate()
|
|
|
|
{
|
|
|
|
struct sl_softc *sc, *nc;
|
|
|
|
int unit;
|
2000-08-18 08:02:31 +00:00
|
|
|
struct mbuf *m;
|
2000-05-30 13:47:03 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
MALLOC(sc, struct sl_softc *, sizeof(*sc), M_SL, M_WAITOK | M_ZERO);
|
2000-05-30 13:47:03 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
m = m_gethdr(M_TRYWAIT, MT_DATA);
|
2000-08-18 08:02:31 +00:00
|
|
|
if (m != NULL) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(m, M_TRYWAIT);
|
2000-08-18 08:02:31 +00:00
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_free(m);
|
|
|
|
m = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m == NULL) {
|
2000-05-30 13:47:03 +00:00
|
|
|
printf("sl: can't allocate buffer\n");
|
2002-04-04 06:03:17 +00:00
|
|
|
free(sc, M_SL);
|
2000-05-30 13:47:03 +00:00
|
|
|
return (NULL);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2000-05-30 13:47:03 +00:00
|
|
|
|
2000-08-18 08:02:31 +00:00
|
|
|
sc->sc_ep = mtod(m, u_char *) + SLBUFSIZE;
|
|
|
|
sc->sc_mbuf = m;
|
1994-09-13 16:05:50 +00:00
|
|
|
sc->sc_buf = sc->sc_ep - SLRMAX;
|
1994-05-24 10:09:53 +00:00
|
|
|
sc->sc_mp = sc->sc_buf;
|
1995-10-31 19:22:32 +00:00
|
|
|
sl_compress_init(&sc->sc_comp, -1);
|
2000-05-30 13:47:03 +00:00
|
|
|
|
|
|
|
sc->sc_if.if_softc = sc;
|
|
|
|
sc->sc_if.if_name = "sl";
|
|
|
|
sc->sc_if.if_mtu = SLMTU;
|
|
|
|
sc->sc_if.if_flags =
|
|
|
|
#ifdef SLIP_IFF_OPTS
|
|
|
|
SLIP_IFF_OPTS;
|
|
|
|
#else
|
|
|
|
IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST;
|
|
|
|
#endif
|
|
|
|
sc->sc_if.if_type = IFT_SLIP;
|
|
|
|
sc->sc_if.if_ioctl = slioctl;
|
|
|
|
sc->sc_if.if_output = sloutput;
|
|
|
|
sc->sc_if.if_snd.ifq_maxlen = 50;
|
|
|
|
sc->sc_fastq.ifq_maxlen = 32;
|
|
|
|
sc->sc_if.if_linkmib = sc;
|
|
|
|
sc->sc_if.if_linkmiblen = sizeof *sc;
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&sc->sc_fastq.ifq_mtx, "sl_fastq", NULL, MTX_DEF);
|
2000-05-30 13:47:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a suitable unit number.
|
|
|
|
*/
|
|
|
|
for (unit=0; ; unit++) {
|
|
|
|
if (slisstatic(unit))
|
|
|
|
continue;
|
|
|
|
LIST_FOREACH(nc, &sl_list, sl_next) {
|
|
|
|
if (nc->sc_if.if_unit == unit)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_if.if_unit = unit;
|
|
|
|
LIST_INSERT_HEAD(&sl_list, sc, sl_next);
|
|
|
|
|
|
|
|
if_attach(&sc->sc_if);
|
|
|
|
bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
|
|
|
|
|
|
|
|
return sc;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2000-05-30 13:47:03 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Line specific open routine.
|
|
|
|
* Attach the given tty to the first available sl unit.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
slopen(dev, tp)
|
|
|
|
dev_t dev;
|
|
|
|
register struct tty *tp;
|
|
|
|
{
|
|
|
|
register struct sl_softc *sc;
|
1995-06-21 09:11:22 +00:00
|
|
|
int s, error;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2002-04-01 21:31:13 +00:00
|
|
|
error = suser(curthread);
|
1994-10-08 01:40:23 +00:00
|
|
|
if (error)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (tp->t_line == SLIPDISC)
|
|
|
|
return (0);
|
|
|
|
|
2000-05-30 13:47:03 +00:00
|
|
|
if ((sc = slcreate()) == NULL)
|
|
|
|
return (ENOBUFS);
|
1994-09-13 16:05:50 +00:00
|
|
|
|
2000-05-30 13:47:03 +00:00
|
|
|
tp->t_sc = (caddr_t)sc;
|
|
|
|
sc->sc_ttyp = tp;
|
|
|
|
sc->sc_if.if_baudrate = tp->t_ospeed;
|
|
|
|
ttyflush(tp, FREAD | FWRITE);
|
|
|
|
tp->t_line = SLIPDISC;
|
1994-09-13 16:05:50 +00:00
|
|
|
|
2000-05-30 13:47:03 +00:00
|
|
|
/*
|
|
|
|
* We don't use t_canq or t_rawq, so reduce their
|
|
|
|
* cblock resources to 0. Reserve enough cblocks
|
|
|
|
* for t_outq to guarantee that we can fit a full
|
|
|
|
* packet if the SLIP_HIWAT check allows slstart()
|
|
|
|
* to loop. Use the same value for the cblock
|
|
|
|
* limit since the reserved blocks should always
|
|
|
|
* be enough. Reserving cblocks probably makes
|
|
|
|
* the CLISTRESERVE check unnecessary and wasteful.
|
|
|
|
*/
|
|
|
|
clist_alloc_cblocks(&tp->t_canq, 0, 0);
|
|
|
|
clist_alloc_cblocks(&tp->t_outq,
|
|
|
|
SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1,
|
|
|
|
SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1);
|
|
|
|
clist_alloc_cblocks(&tp->t_rawq, 0, 0);
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
if_up(&sc->sc_if);
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-10-16 10:45:53 +00:00
|
|
|
static void
|
2001-01-31 07:58:58 +00:00
|
|
|
sldestroy(struct sl_softc *sc)
|
|
|
|
{
|
2000-05-30 13:47:03 +00:00
|
|
|
bpfdetach(&sc->sc_if);
|
|
|
|
if_detach(&sc->sc_if);
|
|
|
|
LIST_REMOVE(sc, sl_next);
|
2000-08-18 08:02:31 +00:00
|
|
|
m_free(sc->sc_mbuf);
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
mtx_destroy(&sc->sc_fastq.ifq_mtx);
|
2001-08-16 17:16:31 +00:00
|
|
|
if (sc->bpfbuf)
|
2002-04-04 06:03:17 +00:00
|
|
|
free(sc->bpfbuf, M_SL);
|
|
|
|
free(sc, M_SL);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Line specific close routine.
|
|
|
|
* Detach the tty from the sl unit.
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
1994-10-08 01:40:23 +00:00
|
|
|
slclose(tp,flag)
|
1994-05-24 10:09:53 +00:00
|
|
|
struct tty *tp;
|
1994-10-08 01:40:23 +00:00
|
|
|
int flag;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
register struct sl_softc *sc;
|
|
|
|
int s;
|
|
|
|
|
1995-09-10 12:22:59 +00:00
|
|
|
ttyflush(tp, FREAD | FWRITE);
|
1994-11-26 19:24:13 +00:00
|
|
|
/*
|
|
|
|
* XXX the placement of the following spl is misleading. tty
|
|
|
|
* interrupts must be blocked across line discipline switches
|
|
|
|
* and throughout closes to avoid races.
|
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
s = splimp(); /* actually, max(spltty, splnet) */
|
1994-11-26 19:24:13 +00:00
|
|
|
clist_free_cblocks(&tp->t_outq);
|
1994-05-24 10:09:53 +00:00
|
|
|
tp->t_line = 0;
|
|
|
|
sc = (struct sl_softc *)tp->t_sc;
|
|
|
|
if (sc != NULL) {
|
1995-03-30 20:43:32 +00:00
|
|
|
if (sc->sc_outfill) {
|
|
|
|
sc->sc_outfill = 0;
|
1997-09-21 22:02:25 +00:00
|
|
|
untimeout(sl_outfill, sc, sc->sc_ofhandle);
|
1995-03-30 20:43:32 +00:00
|
|
|
}
|
|
|
|
if (sc->sc_keepalive) {
|
|
|
|
sc->sc_keepalive = 0;
|
1997-09-21 22:02:25 +00:00
|
|
|
untimeout(sl_keepalive, sc, sc->sc_kahandle);
|
1995-03-30 20:43:32 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
if_down(&sc->sc_if);
|
|
|
|
sc->sc_ttyp = NULL;
|
|
|
|
tp->t_sc = NULL;
|
2000-05-30 13:47:03 +00:00
|
|
|
sldestroy(sc);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
splx(s);
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Line specific (tty) ioctl routine.
|
|
|
|
* Provide a way to get the sl unit number.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
sltioctl(tp, cmd, data, flag, td)
|
1994-05-24 10:09:53 +00:00
|
|
|
struct tty *tp;
|
1998-06-07 17:13:14 +00:00
|
|
|
u_long cmd;
|
1994-05-24 10:09:53 +00:00
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2000-05-30 13:47:03 +00:00
|
|
|
struct sl_softc *sc = (struct sl_softc *)tp->t_sc, *nc;
|
|
|
|
int s, unit, wasup;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-03-30 20:43:32 +00:00
|
|
|
s = splimp();
|
1994-05-24 10:09:53 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case SLIOCGUNIT:
|
|
|
|
*(int *)data = sc->sc_if.if_unit;
|
|
|
|
break;
|
|
|
|
|
1995-04-28 18:47:29 +00:00
|
|
|
case SLIOCSUNIT:
|
2000-05-30 13:47:03 +00:00
|
|
|
unit = *(u_int *)data;
|
|
|
|
if (unit < 0) {
|
|
|
|
splx(s);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
if (sc->sc_if.if_unit != unit) {
|
|
|
|
LIST_FOREACH(nc, &sl_list, sl_next) {
|
|
|
|
if (nc->sc_if.if_unit == *(u_int *)data) {
|
1997-12-19 09:48:57 +00:00
|
|
|
splx(s);
|
2000-05-30 13:47:03 +00:00
|
|
|
return (ENXIO);
|
1996-05-13 14:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-30 13:47:03 +00:00
|
|
|
|
|
|
|
wasup = sc->sc_if.if_flags & IFF_UP;
|
|
|
|
bpfdetach(&sc->sc_if);
|
|
|
|
if_detach(&sc->sc_if);
|
|
|
|
LIST_REMOVE(sc, sl_next);
|
|
|
|
sc->sc_if.if_unit = unit;
|
|
|
|
LIST_INSERT_HEAD(&sl_list, sc, sl_next);
|
|
|
|
if_attach(&sc->sc_if);
|
|
|
|
bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
|
|
|
|
if (wasup)
|
|
|
|
if_up(&sc->sc_if);
|
|
|
|
else
|
|
|
|
if_down(&sc->sc_if);
|
|
|
|
clist_alloc_cblocks(&tp->t_outq,
|
|
|
|
SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1,
|
|
|
|
SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1);
|
1996-05-13 14:09:34 +00:00
|
|
|
}
|
2000-05-30 13:47:03 +00:00
|
|
|
slmarkstatic(unit);
|
1995-04-28 18:47:29 +00:00
|
|
|
break;
|
|
|
|
|
1995-03-30 20:43:32 +00:00
|
|
|
case SLIOCSKEEPAL:
|
|
|
|
sc->sc_keepalive = *(u_int *)data * hz;
|
|
|
|
if (sc->sc_keepalive) {
|
|
|
|
sc->sc_flags |= SC_KEEPALIVE;
|
1997-09-21 22:02:25 +00:00
|
|
|
sc->sc_kahandle = timeout(sl_keepalive, sc,
|
|
|
|
sc->sc_keepalive);
|
1995-03-30 20:43:32 +00:00
|
|
|
} else {
|
1997-09-21 22:02:25 +00:00
|
|
|
if ((sc->sc_flags & SC_KEEPALIVE) != 0) {
|
|
|
|
untimeout(sl_keepalive, sc, sc->sc_kahandle);
|
|
|
|
sc->sc_flags &= ~SC_KEEPALIVE;
|
|
|
|
}
|
1995-03-30 20:43:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLIOCGKEEPAL:
|
|
|
|
*(int *)data = sc->sc_keepalive / hz;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLIOCSOUTFILL:
|
|
|
|
sc->sc_outfill = *(u_int *)data * hz;
|
|
|
|
if (sc->sc_outfill) {
|
|
|
|
sc->sc_flags |= SC_OUTWAIT;
|
1997-09-21 22:02:25 +00:00
|
|
|
sc->sc_ofhandle = timeout(sl_outfill, sc,
|
|
|
|
sc->sc_outfill);
|
1995-03-30 20:43:32 +00:00
|
|
|
} else {
|
1997-09-21 22:02:25 +00:00
|
|
|
if ((sc->sc_flags & SC_OUTWAIT) != 0) {
|
|
|
|
untimeout(sl_outfill, sc, sc->sc_ofhandle);
|
|
|
|
sc->sc_flags &= ~SC_OUTWAIT;
|
|
|
|
}
|
1995-03-30 20:43:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLIOCGOUTFILL:
|
|
|
|
*(int *)data = sc->sc_outfill / hz;
|
|
|
|
break;
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
default:
|
1995-03-30 20:43:32 +00:00
|
|
|
splx(s);
|
1997-12-06 13:25:01 +00:00
|
|
|
return (ENOIOCTL);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1995-03-30 20:43:32 +00:00
|
|
|
splx(s);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue a packet. Start transmission if not active.
|
|
|
|
* Compression happens in slstart; if we do it here, IP TOS
|
|
|
|
* will cause us to not compress "background" packets, because
|
|
|
|
* ordering gets trashed. It can be done for all packets in slstart.
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
sloutput(ifp, m, dst, rtp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
register struct mbuf *m;
|
|
|
|
struct sockaddr *dst;
|
|
|
|
struct rtentry *rtp;
|
|
|
|
{
|
2000-05-30 13:47:03 +00:00
|
|
|
register struct sl_softc *sc = ifp->if_softc;
|
1994-05-24 10:09:53 +00:00
|
|
|
register struct ip *ip;
|
|
|
|
register struct ifqueue *ifq;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* `Cannot happen' (see slioctl). Someday we will extend
|
|
|
|
* the line protocol to support other address families.
|
|
|
|
*/
|
|
|
|
if (dst->sa_family != AF_INET) {
|
2002-10-21 03:35:25 +00:00
|
|
|
if_printf(ifp, "af%d not supported\n", dst->sa_family);
|
1994-05-24 10:09:53 +00:00
|
|
|
m_freem(m);
|
|
|
|
sc->sc_if.if_noproto++;
|
|
|
|
return (EAFNOSUPPORT);
|
|
|
|
}
|
|
|
|
|
1995-06-21 08:48:19 +00:00
|
|
|
if (sc->sc_ttyp == NULL || !(ifp->if_flags & IFF_UP)) {
|
1994-05-24 10:09:53 +00:00
|
|
|
m_freem(m);
|
1995-06-21 08:48:19 +00:00
|
|
|
return (ENETDOWN);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1995-07-31 21:02:00 +00:00
|
|
|
if ((sc->sc_ttyp->t_state & TS_CONNECTED) == 0) {
|
1994-05-24 10:09:53 +00:00
|
|
|
m_freem(m);
|
|
|
|
return (EHOSTUNREACH);
|
|
|
|
}
|
|
|
|
ifq = &sc->sc_if.if_snd;
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
if (sc->sc_if.if_flags & SC_NOICMP && ip->ip_p == IPPROTO_ICMP) {
|
|
|
|
m_freem(m);
|
|
|
|
return (ENETRESET); /* XXX ? */
|
|
|
|
}
|
|
|
|
if (ip->ip_tos & IPTOS_LOWDELAY)
|
|
|
|
ifq = &sc->sc_fastq;
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if (! IF_HANDOFF(ifq, m, NULL)) {
|
1994-05-24 10:09:53 +00:00
|
|
|
sc->sc_if.if_oerrors++;
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
s = splimp();
|
1994-05-24 10:09:53 +00:00
|
|
|
if (sc->sc_ttyp->t_outq.c_cc == 0)
|
|
|
|
slstart(sc->sc_ttyp);
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start output on interface. Get another datagram
|
|
|
|
* to send from the interface queue and map it to
|
|
|
|
* the interface before starting output.
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
slstart(tp)
|
|
|
|
register struct tty *tp;
|
|
|
|
{
|
|
|
|
register struct sl_softc *sc = (struct sl_softc *)tp->t_sc;
|
|
|
|
register struct mbuf *m;
|
|
|
|
register u_char *cp;
|
|
|
|
register struct ip *ip;
|
|
|
|
int s;
|
1994-05-25 09:21:21 +00:00
|
|
|
register int len = 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/*
|
1995-09-10 12:22:59 +00:00
|
|
|
* Call output process whether or not there is more in the
|
|
|
|
* output queue. We are being called in lieu of ttstart
|
|
|
|
* and must do what it would.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1995-09-10 12:22:59 +00:00
|
|
|
(*tp->t_oproc)(tp);
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
if (tp->t_outq.c_cc != 0) {
|
1995-03-30 20:43:32 +00:00
|
|
|
if (sc != NULL)
|
|
|
|
sc->sc_flags &= ~SC_OUTWAIT;
|
1994-05-24 10:09:53 +00:00
|
|
|
if (tp->t_outq.c_cc > SLIP_HIWAT)
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1995-09-10 12:22:59 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* This happens briefly when the line shuts down.
|
|
|
|
*/
|
|
|
|
if (sc == NULL)
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a packet and send it to the interface.
|
|
|
|
*/
|
|
|
|
s = splimp();
|
|
|
|
IF_DEQUEUE(&sc->sc_fastq, m);
|
|
|
|
if (m)
|
|
|
|
sc->sc_if.if_omcasts++; /* XXX */
|
|
|
|
else
|
|
|
|
IF_DEQUEUE(&sc->sc_if.if_snd, m);
|
|
|
|
splx(s);
|
|
|
|
if (m == NULL)
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We do the header compression here rather than in sloutput
|
|
|
|
* because the packets will be out of order if we are using TOS
|
|
|
|
* queueing, and the connection id compression will get
|
|
|
|
* munged when this happens.
|
|
|
|
*/
|
1996-02-06 18:51:28 +00:00
|
|
|
if (sc->sc_if.if_bpf) {
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* We need to save the TCP/IP header before it's
|
|
|
|
* compressed. To avoid complicated code, we just
|
|
|
|
* copy the entire packet into a stack buffer (since
|
|
|
|
* this is a serial line, packets should be short
|
|
|
|
* and/or the copy should be negligible cost compared
|
|
|
|
* to the packet transmission time).
|
|
|
|
*/
|
|
|
|
register struct mbuf *m1 = m;
|
2001-08-16 17:16:31 +00:00
|
|
|
register u_char *cp;
|
|
|
|
|
|
|
|
if (sc->bpfbuf == NULL)
|
|
|
|
MALLOC(sc->bpfbuf, u_char *,
|
|
|
|
SLTMAX + SLIP_HDRLEN, M_SL, M_NOWAIT);
|
|
|
|
|
|
|
|
if (sc->bpfbuf) {
|
|
|
|
cp = sc->bpfbuf + SLIP_HDRLEN;
|
|
|
|
len = 0;
|
|
|
|
do {
|
|
|
|
register int mlen = m1->m_len;
|
|
|
|
|
|
|
|
bcopy(mtod(m1, caddr_t), cp, mlen);
|
|
|
|
cp += mlen;
|
|
|
|
len += mlen;
|
|
|
|
} while ((m1 = m1->m_next) != NULL);
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1996-04-25 02:34:37 +00:00
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
if (ip->ip_v == IPVERSION && ip->ip_p == IPPROTO_TCP) {
|
1994-05-24 10:09:53 +00:00
|
|
|
if (sc->sc_if.if_flags & SC_COMPRESS)
|
|
|
|
*mtod(m, u_char *) |= sl_compress_tcp(m, ip,
|
|
|
|
&sc->sc_comp, 1);
|
|
|
|
}
|
2001-08-16 17:16:31 +00:00
|
|
|
if (sc->sc_if.if_bpf && sc->bpfbuf) {
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Put the SLIP pseudo-"link header" in place. The
|
|
|
|
* compressed header is now at the beginning of the
|
|
|
|
* mbuf.
|
|
|
|
*/
|
2001-08-15 23:59:00 +00:00
|
|
|
sc->bpfbuf[SLX_DIR] = SLIPDIR_OUT;
|
|
|
|
bcopy(mtod(m, caddr_t), &sc->bpfbuf[SLX_CHDR], CHDR_LEN);
|
2002-11-15 00:00:15 +00:00
|
|
|
BPF_TAP(&sc->sc_if, sc->bpfbuf, len + SLIP_HDRLEN);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If system is getting low on clists, just flush our
|
|
|
|
* output queue (if the stuff was important, it'll get
|
1994-09-13 16:05:50 +00:00
|
|
|
* retransmitted). Note that SLTMAX is used instead of
|
|
|
|
* the current if_mtu setting because connections that
|
|
|
|
* have already been established still use the original
|
|
|
|
* (possibly larger) mss.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1994-09-13 16:05:50 +00:00
|
|
|
if (cfreecount < CLISTRESERVE + SLTMAX) {
|
1994-05-24 10:09:53 +00:00
|
|
|
m_freem(m);
|
|
|
|
sc->sc_if.if_collisions++;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-12 11:49:49 +00:00
|
|
|
|
1995-09-17 23:38:29 +00:00
|
|
|
sc->sc_flags &= ~SC_OUTWAIT;
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* The extra FRAME_END will start up a new packet, and thus
|
|
|
|
* will flush any accumulated garbage. We do this whenever
|
|
|
|
* the line may have been idle for some time.
|
|
|
|
*/
|
|
|
|
if (tp->t_outq.c_cc == 0) {
|
|
|
|
++sc->sc_if.if_obytes;
|
|
|
|
(void) putc(FRAME_END, &tp->t_outq);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (m) {
|
|
|
|
register u_char *ep;
|
|
|
|
|
|
|
|
cp = mtod(m, u_char *); ep = cp + m->m_len;
|
|
|
|
while (cp < ep) {
|
|
|
|
/*
|
|
|
|
* Find out how many bytes in the string we can
|
|
|
|
* handle without doing something special.
|
|
|
|
*/
|
|
|
|
register u_char *bp = cp;
|
|
|
|
|
|
|
|
while (cp < ep) {
|
|
|
|
switch (*cp++) {
|
|
|
|
case FRAME_ESCAPE:
|
|
|
|
case FRAME_END:
|
|
|
|
--cp;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (cp > bp) {
|
|
|
|
/*
|
|
|
|
* Put n characters at once
|
|
|
|
* into the tty output queue.
|
|
|
|
*/
|
|
|
|
if (b_to_q((char *)bp, cp - bp,
|
|
|
|
&tp->t_outq))
|
|
|
|
break;
|
|
|
|
sc->sc_if.if_obytes += cp - bp;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If there are characters left in the mbuf,
|
|
|
|
* the first one must be special..
|
|
|
|
* Put it out in a different form.
|
|
|
|
*/
|
|
|
|
if (cp < ep) {
|
|
|
|
if (putc(FRAME_ESCAPE, &tp->t_outq))
|
|
|
|
break;
|
|
|
|
if (putc(*cp++ == FRAME_ESCAPE ?
|
|
|
|
TRANS_FRAME_ESCAPE : TRANS_FRAME_END,
|
|
|
|
&tp->t_outq)) {
|
|
|
|
(void) unputc(&tp->t_outq);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_if.if_obytes += 2;
|
|
|
|
}
|
|
|
|
}
|
2002-02-05 02:00:56 +00:00
|
|
|
m = m_free(m);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (putc(FRAME_END, &tp->t_outq)) {
|
|
|
|
/*
|
|
|
|
* Not enough room. Remove a char to make room
|
|
|
|
* and end the packet normally.
|
|
|
|
* If you get many collisions (more than one or two
|
|
|
|
* a day) you probably do not have enough clists
|
|
|
|
* and you should increase "nclist" in param.c.
|
|
|
|
*/
|
|
|
|
(void) unputc(&tp->t_outq);
|
|
|
|
(void) putc(FRAME_END, &tp->t_outq);
|
|
|
|
sc->sc_if.if_collisions++;
|
|
|
|
} else {
|
|
|
|
++sc->sc_if.if_obytes;
|
|
|
|
sc->sc_if.if_opackets++;
|
|
|
|
}
|
|
|
|
}
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy data buffer to mbuf chain; add ifnet pointer.
|
|
|
|
*/
|
|
|
|
static struct mbuf *
|
|
|
|
sl_btom(sc, len)
|
|
|
|
register struct sl_softc *sc;
|
|
|
|
register int len;
|
|
|
|
{
|
2000-08-18 08:02:31 +00:00
|
|
|
struct mbuf *m, *newm;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (m == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have more than MHLEN bytes, it's cheaper to
|
|
|
|
* queue the cluster we just filled & allocate a new one
|
|
|
|
* for the input buffer. Otherwise, fill the mbuf we
|
|
|
|
* allocated above. Note that code in the input routine
|
|
|
|
* guarantees that packet will fit in a cluster.
|
|
|
|
*/
|
|
|
|
if (len >= MHLEN) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
1994-05-24 10:09:53 +00:00
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
/*
|
|
|
|
* we couldn't get a cluster - if memory's this
|
|
|
|
* low, it's time to start dropping packets.
|
|
|
|
*/
|
|
|
|
(void) m_free(m);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2000-08-18 08:02:31 +00:00
|
|
|
/* Swap the new and old clusters */
|
|
|
|
newm = m;
|
|
|
|
m = sc->sc_mbuf;
|
|
|
|
sc->sc_mbuf = newm;
|
|
|
|
sc->sc_ep = mtod(newm, u_char *) + SLBUFSIZE;
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
m->m_data = (caddr_t)sc->sc_buf;
|
|
|
|
} else
|
|
|
|
bcopy((caddr_t)sc->sc_buf, mtod(m, caddr_t), len);
|
|
|
|
|
|
|
|
m->m_len = len;
|
|
|
|
m->m_pkthdr.len = len;
|
|
|
|
m->m_pkthdr.rcvif = &sc->sc_if;
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tty interface receiver interrupt.
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
slinput(c, tp)
|
|
|
|
register int c;
|
|
|
|
register struct tty *tp;
|
|
|
|
{
|
|
|
|
register struct sl_softc *sc;
|
|
|
|
register struct mbuf *m;
|
|
|
|
register int len;
|
|
|
|
u_char chdr[CHDR_LEN];
|
|
|
|
|
|
|
|
tk_nin++;
|
|
|
|
sc = (struct sl_softc *)tp->t_sc;
|
|
|
|
if (sc == NULL)
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1995-07-31 21:02:00 +00:00
|
|
|
if (c & TTY_ERRORMASK || (tp->t_state & TS_CONNECTED) == 0) {
|
1994-05-24 10:09:53 +00:00
|
|
|
sc->sc_flags |= SC_ERROR;
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
c &= TTY_CHARMASK;
|
|
|
|
|
|
|
|
++sc->sc_if.if_ibytes;
|
|
|
|
|
|
|
|
if (sc->sc_if.if_flags & IFF_DEBUG) {
|
|
|
|
if (c == ABT_ESC) {
|
|
|
|
/*
|
|
|
|
* If we have a previous abort, see whether
|
|
|
|
* this one is within the time limit.
|
|
|
|
*/
|
|
|
|
if (sc->sc_abortcount &&
|
1998-03-30 09:56:58 +00:00
|
|
|
time_second >= sc->sc_starttime + ABT_WINDOW)
|
1994-05-24 10:09:53 +00:00
|
|
|
sc->sc_abortcount = 0;
|
|
|
|
/*
|
|
|
|
* If we see an abort after "idle" time, count it;
|
|
|
|
* record when the first abort escape arrived.
|
|
|
|
*/
|
1998-03-30 09:56:58 +00:00
|
|
|
if (time_second >= sc->sc_lasttime + ABT_IDLE) {
|
1994-05-24 10:09:53 +00:00
|
|
|
if (++sc->sc_abortcount == 1)
|
1998-03-30 09:56:58 +00:00
|
|
|
sc->sc_starttime = time_second;
|
1994-05-24 10:09:53 +00:00
|
|
|
if (sc->sc_abortcount >= ABT_COUNT) {
|
1994-10-08 01:40:23 +00:00
|
|
|
slclose(tp,0);
|
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
sc->sc_abortcount = 0;
|
1998-03-30 09:56:58 +00:00
|
|
|
sc->sc_lasttime = time_second;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
|
|
|
case TRANS_FRAME_ESCAPE:
|
|
|
|
if (sc->sc_escape)
|
|
|
|
c = FRAME_ESCAPE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRANS_FRAME_END:
|
|
|
|
if (sc->sc_escape)
|
|
|
|
c = FRAME_END;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRAME_ESCAPE:
|
|
|
|
sc->sc_escape = 1;
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
case FRAME_END:
|
1995-03-30 20:43:32 +00:00
|
|
|
sc->sc_flags &= ~SC_KEEPALIVE;
|
1994-05-24 10:09:53 +00:00
|
|
|
if(sc->sc_flags & SC_ERROR) {
|
|
|
|
sc->sc_flags &= ~SC_ERROR;
|
|
|
|
goto newpack;
|
|
|
|
}
|
|
|
|
len = sc->sc_mp - sc->sc_buf;
|
|
|
|
if (len < 3)
|
|
|
|
/* less than min length packet - ignore */
|
|
|
|
goto newpack;
|
|
|
|
|
1996-02-06 18:51:28 +00:00
|
|
|
if (sc->sc_if.if_bpf) {
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Save the compressed header, so we
|
|
|
|
* can tack it on later. Note that we
|
|
|
|
* will end up copying garbage in some
|
|
|
|
* cases but this is okay. We remember
|
|
|
|
* where the buffer started so we can
|
|
|
|
* compute the new header length.
|
|
|
|
*/
|
|
|
|
bcopy(sc->sc_buf, chdr, CHDR_LEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((c = (*sc->sc_buf & 0xf0)) != (IPVERSION << 4)) {
|
|
|
|
if (c & 0x80)
|
|
|
|
c = TYPE_COMPRESSED_TCP;
|
|
|
|
else if (c == TYPE_UNCOMPRESSED_TCP)
|
|
|
|
*sc->sc_buf &= 0x4f; /* XXX */
|
|
|
|
/*
|
|
|
|
* We've got something that's not an IP packet.
|
|
|
|
* If compression is enabled, try to decompress it.
|
|
|
|
* Otherwise, if `auto-enable' compression is on and
|
|
|
|
* it's a reasonable packet, decompress it and then
|
|
|
|
* enable compression. Otherwise, drop it.
|
|
|
|
*/
|
|
|
|
if (sc->sc_if.if_flags & SC_COMPRESS) {
|
|
|
|
len = sl_uncompress_tcp(&sc->sc_buf, len,
|
|
|
|
(u_int)c, &sc->sc_comp);
|
|
|
|
if (len <= 0)
|
|
|
|
goto error;
|
|
|
|
} else if ((sc->sc_if.if_flags & SC_AUTOCOMP) &&
|
|
|
|
c == TYPE_UNCOMPRESSED_TCP && len >= 40) {
|
|
|
|
len = sl_uncompress_tcp(&sc->sc_buf, len,
|
|
|
|
(u_int)c, &sc->sc_comp);
|
|
|
|
if (len <= 0)
|
|
|
|
goto error;
|
|
|
|
sc->sc_if.if_flags |= SC_COMPRESS;
|
|
|
|
} else
|
|
|
|
goto error;
|
|
|
|
}
|
1996-02-06 18:51:28 +00:00
|
|
|
if (sc->sc_if.if_bpf) {
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Put the SLIP pseudo-"link header" in place.
|
|
|
|
* We couldn't do this any earlier since
|
|
|
|
* decompression probably moved the buffer
|
|
|
|
* pointer. Then, invoke BPF.
|
|
|
|
*/
|
|
|
|
register u_char *hp = sc->sc_buf - SLIP_HDRLEN;
|
|
|
|
|
|
|
|
hp[SLX_DIR] = SLIPDIR_IN;
|
|
|
|
bcopy(chdr, &hp[SLX_CHDR], CHDR_LEN);
|
2002-11-15 00:00:15 +00:00
|
|
|
BPF_TAP(&sc->sc_if, hp, len + SLIP_HDRLEN);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
m = sl_btom(sc, len);
|
|
|
|
if (m == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
sc->sc_if.if_ipackets++;
|
1995-06-21 08:48:19 +00:00
|
|
|
|
|
|
|
if ((sc->sc_if.if_flags & IFF_UP) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
goto newpack;
|
|
|
|
}
|
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if (! IF_HANDOFF(&ipintrq, m, NULL)) {
|
1994-05-24 10:09:53 +00:00
|
|
|
sc->sc_if.if_ierrors++;
|
|
|
|
sc->sc_if.if_iqdrops++;
|
|
|
|
} else {
|
|
|
|
schednetisr(NETISR_IP);
|
|
|
|
}
|
|
|
|
goto newpack;
|
|
|
|
}
|
|
|
|
if (sc->sc_mp < sc->sc_ep) {
|
|
|
|
*sc->sc_mp++ = c;
|
|
|
|
sc->sc_escape = 0;
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* can't put lower; would miss an extra frame */
|
|
|
|
sc->sc_flags |= SC_ERROR;
|
|
|
|
|
|
|
|
error:
|
|
|
|
sc->sc_if.if_ierrors++;
|
|
|
|
newpack:
|
1994-09-13 16:05:50 +00:00
|
|
|
sc->sc_mp = sc->sc_buf = sc->sc_ep - SLRMAX;
|
1994-05-24 10:09:53 +00:00
|
|
|
sc->sc_escape = 0;
|
1994-10-08 01:40:23 +00:00
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
1994-05-24 10:09:53 +00:00
|
|
|
slioctl(ifp, cmd, data)
|
|
|
|
register struct ifnet *ifp;
|
1998-06-07 17:13:14 +00:00
|
|
|
u_long cmd;
|
1994-05-24 10:09:53 +00:00
|
|
|
caddr_t data;
|
|
|
|
{
|
|
|
|
register struct ifaddr *ifa = (struct ifaddr *)data;
|
1994-09-13 16:05:50 +00:00
|
|
|
register struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
register int s, error = 0;
|
2000-05-30 13:47:03 +00:00
|
|
|
struct sl_softc *sc = ifp->if_softc;
|
1994-09-13 16:05:50 +00:00
|
|
|
|
|
|
|
s = splimp();
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
1995-07-07 01:13:49 +00:00
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
/*
|
|
|
|
* if.c will set the interface up even if we
|
|
|
|
* don't want it to.
|
|
|
|
*/
|
2000-05-30 13:47:03 +00:00
|
|
|
if (sc->sc_ttyp == NULL) {
|
1995-07-07 01:13:49 +00:00
|
|
|
ifp->if_flags &= ~IFF_UP;
|
|
|
|
}
|
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
case SIOCSIFADDR:
|
1995-07-07 01:13:49 +00:00
|
|
|
/*
|
|
|
|
* This is "historical" - set the interface up when
|
|
|
|
* setting the address.
|
|
|
|
*/
|
1995-07-06 11:55:18 +00:00
|
|
|
if (ifa->ifa_addr->sa_family == AF_INET) {
|
2000-05-30 13:47:03 +00:00
|
|
|
if (sc->sc_ttyp != NULL)
|
1999-09-14 01:17:30 +00:00
|
|
|
ifp->if_flags |= IFF_UP;
|
1995-07-06 11:55:18 +00:00
|
|
|
} else {
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
case SIOCSIFDSTADDR:
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET)
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
break;
|
|
|
|
|
1994-09-13 16:05:50 +00:00
|
|
|
case SIOCSIFMTU:
|
|
|
|
/*
|
|
|
|
* Set the interface MTU.
|
|
|
|
*/
|
1994-11-26 19:24:13 +00:00
|
|
|
if (ifr->ifr_mtu > SLTMAX)
|
1994-09-13 16:05:50 +00:00
|
|
|
error = EINVAL;
|
1994-11-26 19:24:13 +00:00
|
|
|
else {
|
1994-11-27 15:29:57 +00:00
|
|
|
struct tty *tp;
|
|
|
|
|
1994-09-13 16:05:50 +00:00
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
2000-05-30 13:47:03 +00:00
|
|
|
tp = sc->sc_ttyp;
|
1994-11-27 15:29:57 +00:00
|
|
|
if (tp != NULL)
|
|
|
|
clist_alloc_cblocks(&tp->t_outq,
|
1997-03-11 19:39:21 +00:00
|
|
|
SLIP_HIWAT + 2 * ifp->if_mtu + 1,
|
|
|
|
SLIP_HIWAT + 2 * ifp->if_mtu + 1);
|
1994-09-13 16:05:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
1995-03-30 20:43:32 +00:00
|
|
|
|
1995-04-02 00:11:48 +00:00
|
|
|
static void
|
|
|
|
sl_keepalive(chan)
|
|
|
|
void *chan;
|
1995-03-30 20:43:32 +00:00
|
|
|
{
|
1995-04-02 00:11:48 +00:00
|
|
|
struct sl_softc *sc = chan;
|
|
|
|
|
1995-03-30 20:43:32 +00:00
|
|
|
if (sc->sc_keepalive) {
|
2002-02-23 11:12:57 +00:00
|
|
|
if (sc->sc_flags & SC_KEEPALIVE) {
|
|
|
|
if (sc->sc_ttyp->t_pgrp != NULL) {
|
|
|
|
PGRP_LOCK(sc->sc_ttyp->t_pgrp);
|
|
|
|
pgsignal (sc->sc_ttyp->t_pgrp, SIGURG, 1);
|
|
|
|
PGRP_UNLOCK(sc->sc_ttyp->t_pgrp);
|
|
|
|
}
|
|
|
|
} else
|
1995-03-30 20:43:32 +00:00
|
|
|
sc->sc_flags |= SC_KEEPALIVE;
|
1997-09-21 22:02:25 +00:00
|
|
|
sc->sc_kahandle = timeout(sl_keepalive, sc, sc->sc_keepalive);
|
1995-03-30 20:43:32 +00:00
|
|
|
} else {
|
|
|
|
sc->sc_flags &= ~SC_KEEPALIVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-04-02 00:11:48 +00:00
|
|
|
static void
|
|
|
|
sl_outfill(chan)
|
|
|
|
void *chan;
|
1995-03-30 20:43:32 +00:00
|
|
|
{
|
1995-04-02 00:11:48 +00:00
|
|
|
struct sl_softc *sc = chan;
|
1995-03-30 20:43:32 +00:00
|
|
|
register struct tty *tp = sc->sc_ttyp;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
if (sc->sc_outfill && tp != NULL) {
|
|
|
|
if (sc->sc_flags & SC_OUTWAIT) {
|
|
|
|
s = splimp ();
|
|
|
|
++sc->sc_if.if_obytes;
|
1995-03-31 11:01:29 +00:00
|
|
|
(void) putc(FRAME_END, &tp->t_outq);
|
1995-03-30 20:43:32 +00:00
|
|
|
(*tp->t_oproc)(tp);
|
|
|
|
splx (s);
|
|
|
|
} else
|
|
|
|
sc->sc_flags |= SC_OUTWAIT;
|
1997-09-21 22:02:25 +00:00
|
|
|
sc->sc_ofhandle = timeout(sl_outfill, sc, sc->sc_outfill);
|
1995-03-30 20:43:32 +00:00
|
|
|
} else {
|
|
|
|
sc->sc_flags &= ~SC_OUTWAIT;
|
|
|
|
}
|
|
|
|
}
|