2 * Copyright (c) 1987, 1989, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)if_sl.c 8.6 (Berkeley) 2/1/94
34 * $FreeBSD: src/sys/net/if_sl.c,v 1.84.2.2 2002/02/13 00:43:10 dillon Exp $
35 * $DragonFly: src/sys/net/sl/if_sl.c,v 1.2 2003/06/17 04:28:48 dillon Exp $
39 * Serial Line interface
42 * Center for Seismic Studies
43 * 1300 N 17th Street, Suite 1450
44 * Arlington, Virginia 22209
49 * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
50 * N.B.: this belongs in netinet, not net, the way it stands now.
51 * Should have a link-layer type designation, but wouldn't be
52 * backwards-compatible.
54 * Converted to 4.3BSD Beta by Chris Torek.
55 * Other changes made at Berkeley, based in part on code by Kirk Smith.
56 * W. Jolitz added slip abort.
58 * Hacked almost beyond recognition by Van Jacobson (van@helios.ee.lbl.gov).
59 * Added priority queuing for "interactive" traffic; hooks for TCP
60 * header compression; ICMP filtering (at 2400 baud, some cretin
61 * pinging you can use up all your bandwidth). Made low clist behavior
62 * more robust and slightly less likely to hang serial line.
63 * Sped up a bunch of things.
65 * Note that splimp() is used throughout to block both (tty) input
66 * interrupts and network activity; thus, splimp must be >= spltty.
72 #if !defined(KLD_MODULE)
75 #include <sys/param.h>
76 #include <sys/systm.h>
78 #include <sys/malloc.h>
80 #include <sys/dkstat.h>
81 #include <sys/socket.h>
82 #include <sys/sockio.h>
83 #include <sys/fcntl.h>
84 #include <sys/signalvar.h>
86 #include <sys/clist.h>
87 #include <sys/kernel.h>
91 #include <net/if_types.h>
92 #include <net/netisr.h>
95 #include <netinet/in.h>
96 #include <netinet/in_systm.h>
97 #include <netinet/in_var.h>
98 #include <netinet/ip.h>
100 #error "Huh? Slip without inet?"
103 #include <net/slcompress.h>
104 #include <net/if_slvar.h>
105 #include <net/slip.h>
110 #include <i386/isa/intr_machdep.h>
113 static void slattach __P((void *));
114 PSEUDO_SET(slattach, if_sl);
117 * SLRMAX is a hard limit on input packet size. To simplify the code
118 * and improve performance, we require that packets fit in an mbuf
119 * cluster, and if we get a compressed packet, there's enough extra
120 * room to expand the header into a max length tcp/ip header (128
121 * bytes). So, SLRMAX can be at most
124 * SLMTU is the default transmit MTU. The transmit MTU should be kept
125 * small enough so that interactive use doesn't suffer, but large
126 * enough to provide good performance. 552 is a good choice for SLMTU
127 * because it is high enough to not fragment TCP packets being routed
128 * through this host. Packet fragmentation is bad with SLIP because
129 * fragment headers aren't compressed. The previous assumptions about
130 * the best MTU value don't really hold when using modern modems with
131 * BTLZ data compression because the modem buffers play a much larger
132 * role in interactive performance than the MTU. The MTU can be changed
133 * at any time to suit the specific environment with ifconfig(8), and
134 * its maximum value is defined as SLTMAX. SLTMAX must not be so large
135 * that it would overflow the stack if BPF is configured (XXX; if_ppp.c
136 * handles this better).
138 * SLIP_HIWAT is the amount of data that will be queued 'downstream'
139 * of us (i.e., in clists waiting to be picked up by the tty output
140 * interrupt). If we queue a lot of data downstream, it's immune to
141 * our t.o.s. queuing.
142 * E.g., if SLIP_HIWAT is 1024, the interactive traffic in mixed
143 * telnet/ftp will see a 1 sec wait, independent of the mtu (the
144 * wait is dependent on the ftp window size but that's typically
145 * 1k - 4k). So, we want SLIP_HIWAT just big enough to amortize
146 * the cost (in idle time on the wire) of the tty driver running
147 * off the end of its clists & having to call back slstart for a
148 * new packet. For a tty interface with any buffering at all, this
149 * cost will be zero. Even with a totally brain dead interface (like
150 * the one on a typical workstation), the cost will be <= 1 character
151 * time. So, setting SLIP_HIWAT to ~100 guarantees that we'll lose
152 * at most 1% while maintaining good interactive response.
154 #define BUFOFFSET (128+sizeof(struct ifnet **)+SLIP_HDRLEN)
155 #define SLRMAX (MCLBYTES - BUFOFFSET)
156 #define SLBUFSIZE (SLRMAX + BUFOFFSET)
158 #define SLMTU 552 /* default MTU */
160 #define SLTMAX 1500 /* maximum MTU */
161 #define SLIP_HIWAT roundup(50,CBSIZE)
162 #define CLISTRESERVE 1024 /* Can't let clists get too low */
165 * SLIP ABORT ESCAPE MECHANISM:
166 * (inspired by HAYES modem escape arrangement)
167 * 1sec escape 1sec escape 1sec escape { 1sec escape 1sec escape }
168 * within window time signals a "soft" exit from slip mode by remote end
169 * if the IFF_DEBUG flag is on.
171 #define ABT_ESC '\033' /* can't be t_intr - distant host must know it*/
172 #define ABT_IDLE 1 /* in seconds - idle before an escape */
173 #define ABT_COUNT 3 /* count of escapes for abort */
174 #define ABT_WINDOW (ABT_COUNT*2+2) /* in seconds - time to count */
176 static struct sl_softc sl_softc[NSL];
178 #define FRAME_END 0xc0 /* Frame End */
179 #define FRAME_ESCAPE 0xdb /* Frame Esc */
180 #define TRANS_FRAME_END 0xdc /* transposed frame end */
181 #define TRANS_FRAME_ESCAPE 0xdd /* transposed frame esc */
183 static int slinit __P((struct sl_softc *));
184 static struct mbuf *sl_btom __P((struct sl_softc *, int));
185 static timeout_t sl_keepalive;
186 static timeout_t sl_outfill;
187 static int slclose __P((struct tty *,int));
188 static int slinput __P((int, struct tty *));
189 static int slioctl __P((struct ifnet *, u_long, caddr_t));
190 static int sltioctl __P((struct tty *, u_long, caddr_t, int, struct proc *));
191 static int slopen __P((dev_t, struct tty *));
192 static int sloutput __P((struct ifnet *,
193 struct mbuf *, struct sockaddr *, struct rtentry *));
194 static int slstart __P((struct tty *));
196 static struct linesw slipdisc = {
197 slopen, slclose, l_noread, l_nowrite,
198 sltioctl, slinput, slstart, ttymodem,
203 * Called from boot code to establish sl interfaces.
209 register struct sl_softc *sc;
212 linesw[SLIPDISC] = slipdisc;
214 for (sc = sl_softc; i < NSL; sc++) {
215 sc->sc_if.if_name = "sl";
216 sc->sc_if.if_unit = i++;
217 sc->sc_if.if_mtu = SLMTU;
222 IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST;
224 sc->sc_if.if_type = IFT_SLIP;
225 sc->sc_if.if_ioctl = slioctl;
226 sc->sc_if.if_output = sloutput;
227 sc->sc_if.if_snd.ifq_maxlen = 50;
228 sc->sc_fastq.ifq_maxlen = 32;
229 sc->sc_if.if_linkmib = sc;
230 sc->sc_if.if_linkmiblen = sizeof *sc;
231 if_attach(&sc->sc_if);
232 bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
238 register struct sl_softc *sc;
246 tty_imask |= net_imask;
247 net_imask = tty_imask;
251 printf("new imasks: bio %x, tty %x, net %x\n",
252 bio_imask, tty_imask, net_imask);
254 if (sc->sc_ep == (u_char *) 0) {
257 sc->sc_ep = (u_char *)p + SLBUFSIZE;
259 printf("sl%ld: can't allocate buffer\n",
260 (long)(sc - sl_softc));
264 sc->sc_buf = sc->sc_ep - SLRMAX;
265 sc->sc_mp = sc->sc_buf;
266 sl_compress_init(&sc->sc_comp, -1);
271 * Line specific open routine.
272 * Attach the given tty to the first available sl unit.
278 register struct tty *tp;
280 struct proc *p = curproc; /* XXX */
281 register struct sl_softc *sc;
289 if (tp->t_line == SLIPDISC)
292 for (nsl = NSL, sc = sl_softc; --nsl >= 0; sc++)
293 if (sc->sc_ttyp == NULL && !(sc->sc_flags & SC_STATIC)) {
296 tp->t_sc = (caddr_t)sc;
298 sc->sc_if.if_baudrate = tp->t_ospeed;
299 ttyflush(tp, FREAD | FWRITE);
301 tp->t_line = SLIPDISC;
303 * We don't use t_canq or t_rawq, so reduce their
304 * cblock resources to 0. Reserve enough cblocks
305 * for t_outq to guarantee that we can fit a full
306 * packet if the SLIP_HIWAT check allows slstart()
307 * to loop. Use the same value for the cblock
308 * limit since the reserved blocks should always
309 * be enough. Reserving cblocks probably makes
310 * the CLISTRESERVE check unnecessary and wasteful.
312 clist_alloc_cblocks(&tp->t_canq, 0, 0);
313 clist_alloc_cblocks(&tp->t_outq,
314 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1,
315 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1);
316 clist_alloc_cblocks(&tp->t_rawq, 0, 0);
327 * Line specific close routine.
328 * Detach the tty from the sl unit.
335 register struct sl_softc *sc;
338 ttyflush(tp, FREAD | FWRITE);
340 * XXX the placement of the following spl is misleading. tty
341 * interrupts must be blocked across line discipline switches
342 * and throughout closes to avoid races.
344 s = splimp(); /* actually, max(spltty, splnet) */
345 clist_free_cblocks(&tp->t_outq);
347 sc = (struct sl_softc *)tp->t_sc;
349 if (sc->sc_outfill) {
351 untimeout(sl_outfill, sc, sc->sc_ofhandle);
353 if (sc->sc_keepalive) {
354 sc->sc_keepalive = 0;
355 untimeout(sl_keepalive, sc, sc->sc_kahandle);
358 sc->sc_flags &= SC_STATIC;
361 MCLFREE((caddr_t)(sc->sc_ep - SLBUFSIZE));
371 * Line specific (tty) ioctl routine.
372 * Provide a way to get the sl unit number.
376 sltioctl(tp, cmd, data, flag, p)
383 struct sl_softc *sc = (struct sl_softc *)tp->t_sc, *nc, *tmpnc;
389 *(int *)data = sc->sc_if.if_unit;
393 if (sc->sc_if.if_unit != *(u_int *)data) {
394 for (nsl = NSL, nc = sl_softc; --nsl >= 0; nc++) {
395 if ( nc->sc_if.if_unit == *(u_int *)data
396 && nc->sc_ttyp == NULL
398 tmpnc = malloc(sizeof *tmpnc, M_TEMP,
406 nc->sc_if = tmpnc->sc_if;
407 tmpnc->sc_if = sc->sc_if;
410 if (sc->sc_if.if_flags & IFF_UP) {
412 if (!(nc->sc_if.if_flags & IFF_UP))
414 } else if (nc->sc_if.if_flags & IFF_UP)
416 sc->sc_flags &= ~SC_STATIC;
417 sc->sc_flags |= (nc->sc_flags & SC_STATIC);
419 clist_alloc_cblocks(&tp->t_outq,
420 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1,
421 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1);
422 sl_compress_init(&sc->sc_comp, -1);
430 sc->sc_flags |= SC_STATIC;
434 sc->sc_keepalive = *(u_int *)data * hz;
435 if (sc->sc_keepalive) {
436 sc->sc_flags |= SC_KEEPALIVE;
437 sc->sc_kahandle = timeout(sl_keepalive, sc,
440 if ((sc->sc_flags & SC_KEEPALIVE) != 0) {
441 untimeout(sl_keepalive, sc, sc->sc_kahandle);
442 sc->sc_flags &= ~SC_KEEPALIVE;
448 *(int *)data = sc->sc_keepalive / hz;
452 sc->sc_outfill = *(u_int *)data * hz;
453 if (sc->sc_outfill) {
454 sc->sc_flags |= SC_OUTWAIT;
455 sc->sc_ofhandle = timeout(sl_outfill, sc,
458 if ((sc->sc_flags & SC_OUTWAIT) != 0) {
459 untimeout(sl_outfill, sc, sc->sc_ofhandle);
460 sc->sc_flags &= ~SC_OUTWAIT;
466 *(int *)data = sc->sc_outfill / hz;
478 * Queue a packet. Start transmission if not active.
479 * Compression happens in slstart; if we do it here, IP TOS
480 * will cause us to not compress "background" packets, because
481 * ordering gets trashed. It can be done for all packets in slstart.
484 sloutput(ifp, m, dst, rtp)
486 register struct mbuf *m;
487 struct sockaddr *dst;
490 register struct sl_softc *sc = &sl_softc[ifp->if_unit];
491 register struct ip *ip;
492 register struct ifqueue *ifq;
496 * `Cannot happen' (see slioctl). Someday we will extend
497 * the line protocol to support other address families.
499 if (dst->sa_family != AF_INET) {
500 printf("sl%d: af%d not supported\n", sc->sc_if.if_unit,
503 sc->sc_if.if_noproto++;
504 return (EAFNOSUPPORT);
507 if (sc->sc_ttyp == NULL || !(ifp->if_flags & IFF_UP)) {
511 if ((sc->sc_ttyp->t_state & TS_CONNECTED) == 0) {
513 return (EHOSTUNREACH);
515 ifq = &sc->sc_if.if_snd;
516 ip = mtod(m, struct ip *);
517 if (sc->sc_if.if_flags & SC_NOICMP && ip->ip_p == IPPROTO_ICMP) {
519 return (ENETRESET); /* XXX ? */
521 if (ip->ip_tos & IPTOS_LOWDELAY)
528 sc->sc_if.if_oerrors++;
532 if (sc->sc_ttyp->t_outq.c_cc == 0)
533 slstart(sc->sc_ttyp);
539 * Start output on interface. Get another datagram
540 * to send from the interface queue and map it to
541 * the interface before starting output.
545 register struct tty *tp;
547 register struct sl_softc *sc = (struct sl_softc *)tp->t_sc;
548 register struct mbuf *m;
550 register struct ip *ip;
552 u_char bpfbuf[SLTMAX + SLIP_HDRLEN];
553 register int len = 0;
557 * Call output process whether or not there is more in the
558 * output queue. We are being called in lieu of ttstart
559 * and must do what it would.
563 if (tp->t_outq.c_cc != 0) {
565 sc->sc_flags &= ~SC_OUTWAIT;
566 if (tp->t_outq.c_cc > SLIP_HIWAT)
571 * This happens briefly when the line shuts down.
577 * Get a packet and send it to the interface.
580 IF_DEQUEUE(&sc->sc_fastq, m);
582 sc->sc_if.if_omcasts++; /* XXX */
584 IF_DEQUEUE(&sc->sc_if.if_snd, m);
590 * We do the header compression here rather than in sloutput
591 * because the packets will be out of order if we are using TOS
592 * queueing, and the connection id compression will get
593 * munged when this happens.
595 if (sc->sc_if.if_bpf) {
597 * We need to save the TCP/IP header before it's
598 * compressed. To avoid complicated code, we just
599 * copy the entire packet into a stack buffer (since
600 * this is a serial line, packets should be short
601 * and/or the copy should be negligible cost compared
602 * to the packet transmission time).
604 register struct mbuf *m1 = m;
605 register u_char *cp = bpfbuf + SLIP_HDRLEN;
609 register int mlen = m1->m_len;
611 bcopy(mtod(m1, caddr_t), cp, mlen);
614 } while ((m1 = m1->m_next) != NULL);
616 ip = mtod(m, struct ip *);
617 if (ip->ip_v == IPVERSION && ip->ip_p == IPPROTO_TCP) {
618 if (sc->sc_if.if_flags & SC_COMPRESS)
619 *mtod(m, u_char *) |= sl_compress_tcp(m, ip,
622 if (sc->sc_if.if_bpf) {
624 * Put the SLIP pseudo-"link header" in place. The
625 * compressed header is now at the beginning of the
628 bpfbuf[SLX_DIR] = SLIPDIR_OUT;
629 bcopy(mtod(m, caddr_t), &bpfbuf[SLX_CHDR], CHDR_LEN);
630 bpf_tap(&sc->sc_if, bpfbuf, len + SLIP_HDRLEN);
634 * If system is getting low on clists, just flush our
635 * output queue (if the stuff was important, it'll get
636 * retransmitted). Note that SLTMAX is used instead of
637 * the current if_mtu setting because connections that
638 * have already been established still use the original
639 * (possibly larger) mss.
641 if (cfreecount < CLISTRESERVE + SLTMAX) {
643 sc->sc_if.if_collisions++;
647 sc->sc_flags &= ~SC_OUTWAIT;
649 * The extra FRAME_END will start up a new packet, and thus
650 * will flush any accumulated garbage. We do this whenever
651 * the line may have been idle for some time.
653 if (tp->t_outq.c_cc == 0) {
654 ++sc->sc_if.if_obytes;
655 (void) putc(FRAME_END, &tp->t_outq);
661 cp = mtod(m, u_char *); ep = cp + m->m_len;
664 * Find out how many bytes in the string we can
665 * handle without doing something special.
667 register u_char *bp = cp;
680 * Put n characters at once
681 * into the tty output queue.
683 if (b_to_q((char *)bp, cp - bp,
686 sc->sc_if.if_obytes += cp - bp;
689 * If there are characters left in the mbuf,
690 * the first one must be special..
691 * Put it out in a different form.
694 if (putc(FRAME_ESCAPE, &tp->t_outq))
696 if (putc(*cp++ == FRAME_ESCAPE ?
697 TRANS_FRAME_ESCAPE : TRANS_FRAME_END,
699 (void) unputc(&tp->t_outq);
702 sc->sc_if.if_obytes += 2;
708 if (putc(FRAME_END, &tp->t_outq)) {
710 * Not enough room. Remove a char to make room
711 * and end the packet normally.
712 * If you get many collisions (more than one or two
713 * a day) you probably do not have enough clists
714 * and you should increase "nclist" in param.c.
716 (void) unputc(&tp->t_outq);
717 (void) putc(FRAME_END, &tp->t_outq);
718 sc->sc_if.if_collisions++;
720 ++sc->sc_if.if_obytes;
721 sc->sc_if.if_opackets++;
728 * Copy data buffer to mbuf chain; add ifnet pointer.
732 register struct sl_softc *sc;
735 register struct mbuf *m;
737 MGETHDR(m, M_DONTWAIT, MT_DATA);
742 * If we have more than MHLEN bytes, it's cheaper to
743 * queue the cluster we just filled & allocate a new one
744 * for the input buffer. Otherwise, fill the mbuf we
745 * allocated above. Note that code in the input routine
746 * guarantees that packet will fit in a cluster.
749 MCLGET(m, M_DONTWAIT);
750 if ((m->m_flags & M_EXT) == 0) {
752 * we couldn't get a cluster - if memory's this
753 * low, it's time to start dropping packets.
758 sc->sc_ep = mtod(m, u_char *) + SLBUFSIZE;
759 m->m_data = (caddr_t)sc->sc_buf;
760 m->m_ext.ext_buf = (caddr_t)((intptr_t)sc->sc_buf &~ MCLOFSET);
762 bcopy((caddr_t)sc->sc_buf, mtod(m, caddr_t), len);
765 m->m_pkthdr.len = len;
766 m->m_pkthdr.rcvif = &sc->sc_if;
771 * tty interface receiver interrupt.
776 register struct tty *tp;
778 register struct sl_softc *sc;
779 register struct mbuf *m;
782 u_char chdr[CHDR_LEN];
785 sc = (struct sl_softc *)tp->t_sc;
788 if (c & TTY_ERRORMASK || (tp->t_state & TS_CONNECTED) == 0) {
789 sc->sc_flags |= SC_ERROR;
794 ++sc->sc_if.if_ibytes;
796 if (sc->sc_if.if_flags & IFF_DEBUG) {
799 * If we have a previous abort, see whether
800 * this one is within the time limit.
802 if (sc->sc_abortcount &&
803 time_second >= sc->sc_starttime + ABT_WINDOW)
804 sc->sc_abortcount = 0;
806 * If we see an abort after "idle" time, count it;
807 * record when the first abort escape arrived.
809 if (time_second >= sc->sc_lasttime + ABT_IDLE) {
810 if (++sc->sc_abortcount == 1)
811 sc->sc_starttime = time_second;
812 if (sc->sc_abortcount >= ABT_COUNT) {
818 sc->sc_abortcount = 0;
819 sc->sc_lasttime = time_second;
824 case TRANS_FRAME_ESCAPE:
829 case TRANS_FRAME_END:
839 sc->sc_flags &= ~SC_KEEPALIVE;
840 if(sc->sc_flags & SC_ERROR) {
841 sc->sc_flags &= ~SC_ERROR;
844 len = sc->sc_mp - sc->sc_buf;
846 /* less than min length packet - ignore */
849 if (sc->sc_if.if_bpf) {
851 * Save the compressed header, so we
852 * can tack it on later. Note that we
853 * will end up copying garbage in some
854 * cases but this is okay. We remember
855 * where the buffer started so we can
856 * compute the new header length.
858 bcopy(sc->sc_buf, chdr, CHDR_LEN);
861 if ((c = (*sc->sc_buf & 0xf0)) != (IPVERSION << 4)) {
863 c = TYPE_COMPRESSED_TCP;
864 else if (c == TYPE_UNCOMPRESSED_TCP)
865 *sc->sc_buf &= 0x4f; /* XXX */
867 * We've got something that's not an IP packet.
868 * If compression is enabled, try to decompress it.
869 * Otherwise, if `auto-enable' compression is on and
870 * it's a reasonable packet, decompress it and then
871 * enable compression. Otherwise, drop it.
873 if (sc->sc_if.if_flags & SC_COMPRESS) {
874 len = sl_uncompress_tcp(&sc->sc_buf, len,
875 (u_int)c, &sc->sc_comp);
878 } else if ((sc->sc_if.if_flags & SC_AUTOCOMP) &&
879 c == TYPE_UNCOMPRESSED_TCP && len >= 40) {
880 len = sl_uncompress_tcp(&sc->sc_buf, len,
881 (u_int)c, &sc->sc_comp);
884 sc->sc_if.if_flags |= SC_COMPRESS;
888 if (sc->sc_if.if_bpf) {
890 * Put the SLIP pseudo-"link header" in place.
891 * We couldn't do this any earlier since
892 * decompression probably moved the buffer
893 * pointer. Then, invoke BPF.
895 register u_char *hp = sc->sc_buf - SLIP_HDRLEN;
897 hp[SLX_DIR] = SLIPDIR_IN;
898 bcopy(chdr, &hp[SLX_CHDR], CHDR_LEN);
899 bpf_tap(&sc->sc_if, hp, len + SLIP_HDRLEN);
901 m = sl_btom(sc, len);
905 sc->sc_if.if_ipackets++;
907 if ((sc->sc_if.if_flags & IFF_UP) == 0) {
913 if (IF_QFULL(&ipintrq)) {
915 sc->sc_if.if_ierrors++;
916 sc->sc_if.if_iqdrops++;
919 IF_ENQUEUE(&ipintrq, m);
920 schednetisr(NETISR_IP);
925 if (sc->sc_mp < sc->sc_ep) {
931 /* can't put lower; would miss an extra frame */
932 sc->sc_flags |= SC_ERROR;
935 sc->sc_if.if_ierrors++;
937 sc->sc_mp = sc->sc_buf = sc->sc_ep - SLRMAX;
943 * Process an ioctl request.
946 slioctl(ifp, cmd, data)
947 register struct ifnet *ifp;
951 register struct ifaddr *ifa = (struct ifaddr *)data;
952 register struct ifreq *ifr = (struct ifreq *)data;
953 register int s, error = 0;
961 * if.c will set the interface up even if we
964 if (sl_softc[ifp->if_unit].sc_ttyp == NULL) {
965 ifp->if_flags &= ~IFF_UP;
970 * This is "historical" - set the interface up when
971 * setting the address.
973 if (ifa->ifa_addr->sa_family == AF_INET) {
974 if (sl_softc[ifp->if_unit].sc_ttyp != NULL)
975 ifp->if_flags |= IFF_UP;
977 error = EAFNOSUPPORT;
982 if (ifa->ifa_addr->sa_family != AF_INET)
983 error = EAFNOSUPPORT;
992 * Set the interface MTU.
994 if (ifr->ifr_mtu > SLTMAX)
999 ifp->if_mtu = ifr->ifr_mtu;
1000 tp = sl_softc[ifp->if_unit].sc_ttyp;
1002 clist_alloc_cblocks(&tp->t_outq,
1003 SLIP_HIWAT + 2 * ifp->if_mtu + 1,
1004 SLIP_HIWAT + 2 * ifp->if_mtu + 1);
1019 struct sl_softc *sc = chan;
1021 if (sc->sc_keepalive) {
1022 if (sc->sc_flags & SC_KEEPALIVE)
1023 pgsignal (sc->sc_ttyp->t_pgrp, SIGURG, 1);
1025 sc->sc_flags |= SC_KEEPALIVE;
1026 sc->sc_kahandle = timeout(sl_keepalive, sc, sc->sc_keepalive);
1028 sc->sc_flags &= ~SC_KEEPALIVE;
1036 struct sl_softc *sc = chan;
1037 register struct tty *tp = sc->sc_ttyp;
1040 if (sc->sc_outfill && tp != NULL) {
1041 if (sc->sc_flags & SC_OUTWAIT) {
1043 ++sc->sc_if.if_obytes;
1044 (void) putc(FRAME_END, &tp->t_outq);
1048 sc->sc_flags |= SC_OUTWAIT;
1049 sc->sc_ofhandle = timeout(sl_outfill, sc, sc->sc_outfill);
1051 sc->sc_flags &= ~SC_OUTWAIT;