4 * Copyright (c) 1987, 1989, 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)if_sl.c 8.6 (Berkeley) 2/1/94
32 * $FreeBSD: src/sys/net/if_sl.c,v 1.84.2.2 2002/02/13 00:43:10 dillon Exp $
36 * Serial Line interface
39 * Center for Seismic Studies
40 * 1300 N 17th Street, Suite 1450
41 * Arlington, Virginia 22209
46 * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
47 * N.B.: this belongs in netinet, not net, the way it stands now.
48 * Should have a link-layer type designation, but wouldn't be
49 * backwards-compatible.
51 * Converted to 4.3BSD Beta by Chris Torek.
52 * Other changes made at Berkeley, based in part on code by Kirk Smith.
53 * W. Jolitz added slip abort.
55 * Hacked almost beyond recognition by Van Jacobson (van@helios.ee.lbl.gov).
56 * Added priority queuing for "interactive" traffic; hooks for TCP
57 * header compression; ICMP filtering (at 2400 baud, some cretin
58 * pinging you can use up all your bandwidth). Made low clist behavior
59 * more robust and slightly less likely to hang serial line.
60 * Sped up a bunch of things.
66 #if !defined(KLD_MODULE)
69 #include <sys/param.h>
70 #include <sys/systm.h>
73 #include <sys/malloc.h>
75 #include <sys/dkstat.h>
76 #include <sys/socket.h>
77 #include <sys/sockio.h>
78 #include <sys/fcntl.h>
79 #include <sys/signalvar.h>
81 #include <sys/clist.h>
82 #include <sys/kernel.h>
84 #include <sys/thread2.h>
87 #include <net/if_types.h>
88 #include <net/ifq_var.h>
89 #include <net/netisr.h>
92 #include <netinet/in.h>
93 #include <netinet/in_systm.h>
94 #include <netinet/in_var.h>
95 #include <netinet/ip.h>
97 #error "Huh? Slip without inet?"
100 #include <net/slcompress.h>
101 #include "if_slvar.h"
102 #include <net/slip.h>
106 static void slattach (void *);
107 PSEUDO_SET(slattach, if_sl);
110 * SLRMAX is a hard limit on input packet size. To simplify the code
111 * and improve performance, we require that packets fit in an mbuf
112 * cluster, and if we get a compressed packet, there's enough extra
113 * room to expand the header into a max length tcp/ip header (128
114 * bytes). So, SLRMAX can be at most
117 * SLMTU is the default transmit MTU. The transmit MTU should be kept
118 * small enough so that interactive use doesn't suffer, but large
119 * enough to provide good performance. 552 is a good choice for SLMTU
120 * because it is high enough to not fragment TCP packets being routed
121 * through this host. Packet fragmentation is bad with SLIP because
122 * fragment headers aren't compressed. The previous assumptions about
123 * the best MTU value don't really hold when using modern modems with
124 * BTLZ data compression because the modem buffers play a much larger
125 * role in interactive performance than the MTU. The MTU can be changed
126 * at any time to suit the specific environment with ifconfig(8), and
127 * its maximum value is defined as SLTMAX. SLTMAX must not be so large
128 * that it would overflow the stack if BPF is configured (XXX; if_ppp.c
129 * handles this better).
131 * SLIP_HIWAT is the amount of data that will be queued 'downstream'
132 * of us (i.e., in clists waiting to be picked up by the tty output
133 * interrupt). If we queue a lot of data downstream, it's immune to
134 * our t.o.s. queuing.
135 * E.g., if SLIP_HIWAT is 1024, the interactive traffic in mixed
136 * telnet/ftp will see a 1 sec wait, independent of the mtu (the
137 * wait is dependent on the ftp window size but that's typically
138 * 1k - 4k). So, we want SLIP_HIWAT just big enough to amortize
139 * the cost (in idle time on the wire) of the tty driver running
140 * off the end of its clists & having to call back slstart for a
141 * new packet. For a tty interface with any buffering at all, this
142 * cost will be zero. Even with a totally brain dead interface (like
143 * the one on a typical workstation), the cost will be <= 1 character
144 * time. So, setting SLIP_HIWAT to ~100 guarantees that we'll lose
145 * at most 1% while maintaining good interactive response.
147 #define BUFOFFSET (128+sizeof(struct ifnet **)+SLIP_HDRLEN)
148 #define SLRMAX (MCLBYTES - BUFOFFSET)
149 #define SLBUFSIZE (SLRMAX + BUFOFFSET)
151 #define SLMTU 552 /* default MTU */
153 #define SLTMAX 1500 /* maximum MTU */
154 #define SLIP_HIWAT roundup(50,CBSIZE)
155 #define CLISTRESERVE 1024 /* Can't let clists get too low */
158 * SLIP ABORT ESCAPE MECHANISM:
159 * (inspired by HAYES modem escape arrangement)
160 * 1sec escape 1sec escape 1sec escape { 1sec escape 1sec escape }
161 * within window time signals a "soft" exit from slip mode by remote end
162 * if the IFF_DEBUG flag is on.
164 #define ABT_ESC '\033' /* can't be t_intr - distant host must know it*/
165 #define ABT_IDLE 1 /* in seconds - idle before an escape */
166 #define ABT_COUNT 3 /* count of escapes for abort */
167 #define ABT_WINDOW (ABT_COUNT*2+2) /* in seconds - time to count */
169 static struct sl_softc sl_softc[NSL];
171 #define FRAME_END 0xc0 /* Frame End */
172 #define FRAME_ESCAPE 0xdb /* Frame Esc */
173 #define TRANS_FRAME_END 0xdc /* transposed frame end */
174 #define TRANS_FRAME_ESCAPE 0xdd /* transposed frame esc */
176 static int slinit (struct sl_softc *);
177 static struct mbuf *sl_btom (struct sl_softc *, int);
178 static timeout_t sl_keepalive;
179 static timeout_t sl_outfill;
180 static int slclose (struct tty *,int);
181 static int slinput (int, struct tty *);
182 static int slioctl (struct ifnet *, u_long, caddr_t, struct ucred *);
183 static int sltioctl (struct tty *, u_long, caddr_t, int, struct ucred *);
184 static int slopen (cdev_t, struct tty *);
185 static int sloutput (struct ifnet *,
186 struct mbuf *, struct sockaddr *, struct rtentry *);
187 static int slstart (struct tty *);
189 static struct linesw slipdisc = {
190 slopen, slclose, l_noread, l_nowrite,
191 sltioctl, slinput, slstart, ttymodem,
196 * Called from boot code to establish sl interfaces.
199 slattach(void *dummy)
204 lwkt_gettoken(&tty_token);
205 linesw[SLIPDISC] = slipdisc;
207 for (sc = sl_softc; i < NSL; sc++) {
208 if_initname(&(sc->sc_if), "sl", i++);
209 sc->sc_if.if_mtu = SLMTU;
214 IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST;
216 sc->sc_if.if_type = IFT_SLIP;
217 sc->sc_if.if_ioctl = slioctl;
218 sc->sc_if.if_output = sloutput;
219 ifq_set_maxlen(&sc->sc_if.if_snd, 50);
220 ifq_set_ready(&sc->sc_if.if_snd);
221 sc->sc_fastq.ifq_maxlen = 32;
222 sc->sc_if.if_linkmib = sc;
223 sc->sc_if.if_linkmiblen = sizeof *sc;
224 callout_init_mp(&sc->sc_oftimeout);
225 callout_init_mp(&sc->sc_katimeout);
226 if_attach(&sc->sc_if, NULL);
227 bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
229 lwkt_reltoken(&tty_token);
233 slinit(struct sl_softc *sc)
235 lwkt_gettoken(&tty_token);
236 if (sc->sc_ep == NULL)
237 sc->sc_ep = kmalloc(SLBUFSIZE, M_DEVBUF, M_WAITOK);
238 sc->sc_buf = sc->sc_ep + SLBUFSIZE - SLRMAX;
239 sc->sc_mp = sc->sc_buf;
240 sl_compress_init(&sc->sc_comp, -1);
241 lwkt_reltoken(&tty_token);
246 * Line specific open routine.
247 * Attach the given tty to the first available sl unit.
251 slopen(cdev_t dev, struct tty *tp)
256 struct thread *td = curthread; /* XXX */
258 error = priv_check(td, PRIV_ROOT);
262 lwkt_gettoken(&tty_token);
263 if (tp->t_line == SLIPDISC) {
264 lwkt_reltoken(&tty_token);
268 for (nsl = NSL, sc = sl_softc; --nsl >= 0; sc++)
269 if (sc->sc_ttyp == NULL && !(sc->sc_flags & SC_STATIC)) {
270 if (slinit(sc) == 0) {
271 lwkt_reltoken(&tty_token);
274 tp->t_sc = (caddr_t)sc;
276 sc->sc_if.if_baudrate = tp->t_ospeed;
277 ttyflush(tp, FREAD | FWRITE);
279 tp->t_line = SLIPDISC;
281 * We don't use t_canq or t_rawq, so reduce their
282 * cblock resources to 0. Reserve enough cblocks
283 * for t_outq to guarantee that we can fit a full
284 * packet if the SLIP_HIWAT check allows slstart()
285 * to loop. Use the same value for the cblock
286 * limit since the reserved blocks should always
287 * be enough. Reserving cblocks probably makes
288 * the CLISTRESERVE check unnecessary and wasteful.
290 clist_alloc_cblocks(&tp->t_canq, 0, 0);
291 clist_alloc_cblocks(&tp->t_outq,
292 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1,
293 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1);
294 clist_alloc_cblocks(&tp->t_rawq, 0, 0);
299 lwkt_reltoken(&tty_token);
302 lwkt_reltoken(&tty_token);
307 * Line specific close routine.
308 * Detach the tty from the sl unit.
311 slclose(struct tty *tp, int flag)
315 lwkt_gettoken(&tty_token);
316 ttyflush(tp, FREAD | FWRITE);
319 clist_free_cblocks(&tp->t_outq);
321 sc = (struct sl_softc *)tp->t_sc;
323 if (sc->sc_outfill) {
325 callout_stop(&sc->sc_oftimeout);
327 if (sc->sc_keepalive) {
328 sc->sc_keepalive = 0;
329 callout_stop(&sc->sc_katimeout);
332 sc->sc_flags &= SC_STATIC;
336 kfree(sc->sc_ep, M_DEVBUF);
343 lwkt_reltoken(&tty_token);
348 * Line specific (tty) ioctl routine.
349 * Provide a way to get the sl unit number.
353 sltioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct ucred *cred)
355 struct sl_softc *sc = (struct sl_softc *)tp->t_sc, *nc, *tmpnc;
359 lwkt_gettoken(&tty_token);
363 *(int *)data = sc->sc_if.if_dunit;
367 if (sc->sc_if.if_dunit != *(u_int *)data) {
368 for (nsl = NSL, nc = sl_softc; --nsl >= 0; nc++) {
369 if ( nc->sc_if.if_dunit == *(u_int *)data
370 && nc->sc_ttyp == NULL
372 tmpnc = kmalloc(sizeof *tmpnc, M_TEMP,
376 nc->sc_if = tmpnc->sc_if;
377 tmpnc->sc_if = sc->sc_if;
379 kfree(tmpnc, M_TEMP);
380 if (sc->sc_if.if_flags & IFF_UP) {
382 if (!(nc->sc_if.if_flags & IFF_UP))
384 } else if (nc->sc_if.if_flags & IFF_UP)
386 sc->sc_flags &= ~SC_STATIC;
387 sc->sc_flags |= (nc->sc_flags & SC_STATIC);
389 clist_alloc_cblocks(&tp->t_outq,
390 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1,
391 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1);
392 sl_compress_init(&sc->sc_comp, -1);
396 lwkt_reltoken(&tty_token);
401 sc->sc_flags |= SC_STATIC;
405 sc->sc_keepalive = *(u_int *)data * hz;
406 if (sc->sc_keepalive) {
407 sc->sc_flags |= SC_KEEPALIVE;
408 callout_reset(&sc->sc_katimeout, sc->sc_keepalive,
411 if ((sc->sc_flags & SC_KEEPALIVE) != 0) {
412 callout_stop(&sc->sc_katimeout);
413 sc->sc_flags &= ~SC_KEEPALIVE;
419 *(int *)data = sc->sc_keepalive / hz;
423 sc->sc_outfill = *(u_int *)data * hz;
424 if (sc->sc_outfill) {
425 sc->sc_flags |= SC_OUTWAIT;
426 callout_reset(&sc->sc_oftimeout, sc->sc_outfill,
429 if ((sc->sc_flags & SC_OUTWAIT) != 0) {
430 callout_stop(&sc->sc_oftimeout);
431 sc->sc_flags &= ~SC_OUTWAIT;
437 *(int *)data = sc->sc_outfill / hz;
441 lwkt_reltoken(&tty_token);
445 lwkt_reltoken(&tty_token);
451 * Queue a packet. Start transmission if not active.
452 * Compression happens in slstart; if we do it here, IP TOS
453 * will cause us to not compress "background" packets, because
454 * ordering gets trashed. It can be done for all packets in slstart.
457 sloutput_serialized(struct ifnet *ifp, struct ifaltq_subque *ifsq,
458 struct mbuf *m, struct sockaddr *dst, struct rtentry *rtp)
460 struct sl_softc *sc = &sl_softc[ifp->if_dunit];
463 struct altq_pktattr pktattr;
465 ifq_classify(&ifp->if_snd, m, dst->sa_family, &pktattr);
468 * `Cannot happen' (see slioctl). Someday we will extend
469 * the line protocol to support other address families.
471 if (dst->sa_family != AF_INET) {
472 kprintf("%s: af%d not supported\n", sc->sc_if.if_xname,
475 IFNET_STAT_INC(&sc->sc_if, noproto, 1);
476 return (EAFNOSUPPORT);
479 if (sc->sc_ttyp == NULL || !(ifp->if_flags & IFF_UP)) {
483 if ((sc->sc_ttyp->t_state & TS_CONNECTED) == 0) {
485 return (EHOSTUNREACH);
487 ip = mtod(m, struct ip *);
488 if (sc->sc_if.if_flags & SC_NOICMP && ip->ip_p == IPPROTO_ICMP) {
490 return (ENETRESET); /* XXX ? */
495 if ((ip->ip_tos & IPTOS_LOWDELAY) && !ifq_is_enabled(&sc->sc_if.if_snd)) {
496 if (IF_QFULL(&sc->sc_fastq)) {
497 IF_DROP(&sc->sc_fastq);
501 IF_ENQUEUE(&sc->sc_fastq, m);
505 error = ifsq_enqueue(ifsq, m, &pktattr);
508 IFNET_STAT_INC(&sc->sc_if, oerrors, 1);
512 if (sc->sc_ttyp->t_outq.c_cc == 0)
513 slstart(sc->sc_ttyp);
519 sloutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
522 struct ifaltq_subque *ifsq = ifq_get_subq_default(&ifp->if_snd);
525 ifsq_serialize_hw(ifsq);
526 error = sloutput_serialized(ifp, ifsq, m, dst, rtp);
527 ifsq_deserialize_hw(ifsq);
533 * Start output on interface. Get another datagram
534 * to send from the interface queue and map it to
535 * the interface before starting output.
538 slstart(struct tty *tp)
540 struct sl_softc *sc = (struct sl_softc *)tp->t_sc;
541 struct ifaltq_subque *ifsq = ifq_get_subq_default(&sc->sc_if.if_snd);
545 u_char bpfbuf[SLTMAX + SLIP_HDRLEN];
548 lwkt_gettoken(&tty_token);
551 * Call output process whether or not there is more in the
552 * output queue. We are being called in lieu of ttstart
553 * and must do what it would.
557 if (tp->t_outq.c_cc != 0) {
559 sc->sc_flags &= ~SC_OUTWAIT;
560 if (tp->t_outq.c_cc > SLIP_HIWAT) {
561 lwkt_reltoken(&tty_token);
567 * This happens briefly when the line shuts down.
570 lwkt_reltoken(&tty_token);
575 * Get a packet and send it to the interface.
578 IF_DEQUEUE(&sc->sc_fastq, m);
580 IFNET_STAT_INC(&sc->sc_if, omcasts, 1); /* XXX */
582 m = ifsq_dequeue(ifsq);
585 lwkt_reltoken(&tty_token);
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).
605 u_char *cp = bpfbuf + SLIP_HDRLEN;
609 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) {
625 if (sc->sc_if.if_bpf) {
627 * Put the SLIP pseudo-"link header" in place.
628 * The compressed header is now at the
629 * beginning of the mbuf.
631 bpfbuf[SLX_DIR] = SLIPDIR_OUT;
632 bcopy(mtod(m, caddr_t), &bpfbuf[SLX_CHDR],
634 bpf_tap(sc->sc_if.if_bpf, bpfbuf,
642 * If system is getting low on clists, just flush our
643 * output queue (if the stuff was important, it'll get
644 * retransmitted). Note that SLTMAX is used instead of
645 * the current if_mtu setting because connections that
646 * have already been established still use the original
647 * (possibly larger) mss.
649 if (cfreecount < CLISTRESERVE + SLTMAX) {
651 IFNET_STAT_INC(&sc->sc_if, collisions, 1);
655 sc->sc_flags &= ~SC_OUTWAIT;
657 * The extra FRAME_END will start up a new packet, and thus
658 * will flush any accumulated garbage. We do this whenever
659 * the line may have been idle for some time.
661 if (tp->t_outq.c_cc == 0) {
662 IFNET_STAT_INC(&sc->sc_if, obytes, 1);
663 clist_putc(FRAME_END, &tp->t_outq);
669 cp = mtod(m, u_char *); ep = cp + m->m_len;
672 * Find out how many bytes in the string we can
673 * handle without doing something special.
688 * Put n characters at once
689 * into the tty output queue.
691 if (b_to_q((char *)bp, cp - bp,
694 IFNET_STAT_INC(&sc->sc_if, obytes,
698 * If there are characters left in the mbuf,
699 * the first one must be special..
700 * Put it out in a different form.
703 if (clist_putc(FRAME_ESCAPE, &tp->t_outq))
705 if (clist_putc(*cp++ == FRAME_ESCAPE ?
706 TRANS_FRAME_ESCAPE : TRANS_FRAME_END,
708 clist_unputc(&tp->t_outq);
711 IFNET_STAT_INC(&sc->sc_if, obytes, 2);
717 if (clist_putc(FRAME_END, &tp->t_outq)) {
719 * Not enough room. Remove a char to make room
720 * and end the packet normally.
721 * If you get many collisions (more than one or two
722 * a day) you probably do not have enough clists
723 * and you should increase "nclist" in param.c.
725 clist_unputc(&tp->t_outq);
726 clist_putc(FRAME_END, &tp->t_outq);
727 IFNET_STAT_INC(&sc->sc_if, collisions, 1);
729 IFNET_STAT_INC(&sc->sc_if, obytes, 1);
730 IFNET_STAT_INC(&sc->sc_if, opackets, 1);
733 lwkt_reltoken(&tty_token);
738 * Copy data buffer to mbuf chain; add ifnet pointer.
741 sl_btom(struct sl_softc *sc, int len)
748 MGETHDR(m, M_NOWAIT, MT_DATA);
753 * If we have more than MHLEN bytes, it's cheaper to
754 * queue the cluster we just filled & allocate a new one
755 * for the input buffer. Otherwise, fill the mbuf we
756 * allocated above. Note that code in the input routine
757 * guarantees that packet will fit in a cluster.
761 if ((m->m_flags & M_EXT) == 0) {
763 * we couldn't get a cluster - if memory's this
764 * low, it's time to start dropping packets.
770 bcopy((caddr_t)sc->sc_buf, mtod(m, caddr_t), len);
772 m->m_pkthdr.len = len;
773 m->m_pkthdr.rcvif = &sc->sc_if;
778 * tty interface receiver interrupt.
781 slinput(int c, struct tty *tp)
786 u_char chdr[CHDR_LEN];
788 lwkt_gettoken(&tty_token);
790 sc = (struct sl_softc *)tp->t_sc;
792 lwkt_reltoken(&tty_token);
795 if (c & TTY_ERRORMASK || (tp->t_state & TS_CONNECTED) == 0) {
796 sc->sc_flags |= SC_ERROR;
797 lwkt_reltoken(&tty_token);
802 IFNET_STAT_INC(&sc->sc_if, ibytes, 1);
804 if (sc->sc_if.if_flags & IFF_DEBUG) {
807 * If we have a previous abort, see whether
808 * this one is within the time limit.
810 if (sc->sc_abortcount &&
811 time_uptime >= sc->sc_starttime + ABT_WINDOW)
812 sc->sc_abortcount = 0;
814 * If we see an abort after "idle" time, count it;
815 * record when the first abort escape arrived.
817 if (time_uptime >= sc->sc_lasttime + ABT_IDLE) {
818 if (++sc->sc_abortcount == 1)
819 sc->sc_starttime = time_uptime;
820 if (sc->sc_abortcount >= ABT_COUNT) {
822 lwkt_reltoken(&tty_token);
827 sc->sc_abortcount = 0;
828 sc->sc_lasttime = time_uptime;
833 case TRANS_FRAME_ESCAPE:
838 case TRANS_FRAME_END:
845 lwkt_reltoken(&tty_token);
849 sc->sc_flags &= ~SC_KEEPALIVE;
850 if(sc->sc_flags & SC_ERROR) {
851 sc->sc_flags &= ~SC_ERROR;
854 len = sc->sc_mp - sc->sc_buf;
856 /* less than min length packet - ignore */
859 if (sc->sc_if.if_bpf) {
861 * Save the compressed header, so we
862 * can tack it on later. Note that we
863 * will end up copying garbage in some
864 * cases but this is okay. We remember
865 * where the buffer started so we can
866 * compute the new header length.
868 bcopy(sc->sc_buf, chdr, CHDR_LEN);
871 if ((c = (*sc->sc_buf & 0xf0)) != (IPVERSION << 4)) {
873 c = TYPE_COMPRESSED_TCP;
874 else if (c == TYPE_UNCOMPRESSED_TCP)
875 *sc->sc_buf &= 0x4f; /* XXX */
877 * We've got something that's not an IP packet.
878 * If compression is enabled, try to decompress it.
879 * Otherwise, if `auto-enable' compression is on and
880 * it's a reasonable packet, decompress it and then
881 * enable compression. Otherwise, drop it.
883 if (sc->sc_if.if_flags & SC_COMPRESS) {
884 len = sl_uncompress_tcp(&sc->sc_buf, len,
885 (u_int)c, &sc->sc_comp);
888 } else if ((sc->sc_if.if_flags & SC_AUTOCOMP) &&
889 c == TYPE_UNCOMPRESSED_TCP && len >= 40) {
890 len = sl_uncompress_tcp(&sc->sc_buf, len,
891 (u_int)c, &sc->sc_comp);
894 sc->sc_if.if_flags |= SC_COMPRESS;
898 if (sc->sc_if.if_bpf) {
901 if (sc->sc_if.if_bpf) {
903 * Put the SLIP pseudo-"link header" in place.
904 * We couldn't do this any earlier since
905 * decompression probably moved the buffer
906 * pointer. Then, invoke BPF.
908 u_char *hp = sc->sc_buf - SLIP_HDRLEN;
910 hp[SLX_DIR] = SLIPDIR_IN;
911 bcopy(chdr, &hp[SLX_CHDR], CHDR_LEN);
912 bpf_tap(sc->sc_if.if_bpf, hp,
918 m = sl_btom(sc, len);
922 IFNET_STAT_INC(&sc->sc_if, ipackets, 1);
924 if ((sc->sc_if.if_flags & IFF_UP) == 0) {
929 if (netisr_queue(NETISR_IP, m)) {
930 IFNET_STAT_INC(&sc->sc_if, ierrors, 1);
931 IFNET_STAT_INC(&sc->sc_if, iqdrops, 1);
936 if (sc->sc_mp < sc->sc_ep + SLBUFSIZE) {
939 lwkt_reltoken(&tty_token);
943 /* can't put lower; would miss an extra frame */
944 sc->sc_flags |= SC_ERROR;
947 IFNET_STAT_INC(&sc->sc_if, ierrors, 1);
949 sc->sc_mp = sc->sc_buf = sc->sc_ep + SLBUFSIZE - SLRMAX;
951 lwkt_reltoken(&tty_token);
956 * Process an ioctl request.
959 slioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
961 struct ifaddr *ifa = (struct ifaddr *)data;
962 struct ifreq *ifr = (struct ifreq *)data;
971 * if.c will set the interface up even if we
974 if (sl_softc[ifp->if_dunit].sc_ttyp == NULL) {
975 ifp->if_flags &= ~IFF_UP;
980 * This is "historical" - set the interface up when
981 * setting the address.
983 if (ifa->ifa_addr->sa_family == AF_INET) {
984 if (sl_softc[ifp->if_dunit].sc_ttyp != NULL)
985 ifp->if_flags |= IFF_UP;
987 error = EAFNOSUPPORT;
992 if (ifa->ifa_addr->sa_family != AF_INET)
993 error = EAFNOSUPPORT;
1002 * Set the interface MTU.
1004 if (ifr->ifr_mtu > SLTMAX)
1009 ifp->if_mtu = ifr->ifr_mtu;
1010 tp = sl_softc[ifp->if_dunit].sc_ttyp;
1012 clist_alloc_cblocks(&tp->t_outq,
1013 SLIP_HIWAT + 2 * ifp->if_mtu + 1,
1014 SLIP_HIWAT + 2 * ifp->if_mtu + 1);
1027 sl_keepalive(void *chan)
1029 struct sl_softc *sc = chan;
1032 lwkt_gettoken(&tty_token);
1033 if (sc->sc_keepalive) {
1034 if (sc->sc_flags & SC_KEEPALIVE) {
1035 pg = sc->sc_ttyp->t_pgrp;
1038 pgsignal (pg, SIGURG, 1);
1042 sc->sc_flags |= SC_KEEPALIVE;
1044 callout_reset(&sc->sc_katimeout, sc->sc_keepalive,
1047 sc->sc_flags &= ~SC_KEEPALIVE;
1049 lwkt_reltoken(&tty_token);
1053 sl_outfill(void *chan)
1055 struct sl_softc *sc = chan;
1056 struct tty *tp = sc->sc_ttyp;
1058 lwkt_gettoken(&tty_token);
1060 if (sc->sc_outfill && tp != NULL) {
1061 if (sc->sc_flags & SC_OUTWAIT) {
1063 IFNET_STAT_INC(&sc->sc_if, obytes, 1);
1064 clist_putc(FRAME_END, &tp->t_outq);
1068 sc->sc_flags |= SC_OUTWAIT;
1069 callout_reset(&sc->sc_oftimeout, sc->sc_outfill,
1072 sc->sc_flags &= ~SC_OUTWAIT;
1074 lwkt_reltoken(&tty_token);