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 * $Id: if_sl.c,v 1.69 1998/06/07 17:12:05 dfr Exp $
38 * Serial Line interface
41 * Center for Seismic Studies
42 * 1300 N 17th Street, Suite 1450
43 * Arlington, Virginia 22209
48 * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
49 * N.B.: this belongs in netinet, not net, the way it stands now.
50 * Should have a link-layer type designation, but wouldn't be
51 * backwards-compatible.
53 * Converted to 4.3BSD Beta by Chris Torek.
54 * Other changes made at Berkeley, based in part on code by Kirk Smith.
55 * W. Jolitz added slip abort.
57 * Hacked almost beyond recognition by Van Jacobson (van@helios.ee.lbl.gov).
58 * Added priority queuing for "interactive" traffic; hooks for TCP
59 * header compression; ICMP filtering (at 2400 baud, some cretin
60 * pinging you can use up all your bandwidth). Made low clist behavior
61 * more robust and slightly less likely to hang serial line.
62 * Sped up a bunch of things.
64 * Note that splimp() is used throughout to block both (tty) input
65 * interrupts and network activity; thus, splimp must be >= spltty.
74 #include <sys/param.h>
75 #include <sys/systm.h>
77 #include <sys/malloc.h>
79 #include <sys/dkstat.h>
80 #include <sys/socket.h>
81 #include <sys/sockio.h>
82 #include <sys/fcntl.h>
83 #include <sys/signalvar.h>
85 #include <sys/clist.h>
86 #include <sys/kernel.h>
90 #include <net/if_types.h>
91 #include <net/netisr.h>
94 #include <netinet/in.h>
95 #include <netinet/in_systm.h>
96 #include <netinet/in_var.h>
97 #include <netinet/ip.h>
99 #error "Huh? Slip without inet?"
102 #include <net/slcompress.h>
103 #include <net/if_slvar.h>
104 #include <net/slip.h>
110 static void slattach __P((void *));
111 PSEUDO_SET(slattach, if_sl);
114 * SLRMAX is a hard limit on input packet size. To simplify the code
115 * and improve performance, we require that packets fit in an mbuf
116 * cluster, and if we get a compressed packet, there's enough extra
117 * room to expand the header into a max length tcp/ip header (128
118 * bytes). So, SLRMAX can be at most
121 * SLMTU is the default transmit MTU. The transmit MTU should be kept
122 * small enough so that interactive use doesn't suffer, but large
123 * enough to provide good performance. 552 is a good choice for SLMTU
124 * because it is high enough to not fragment TCP packets being routed
125 * through this host. Packet fragmentation is bad with SLIP because
126 * fragment headers aren't compressed. The previous assumptions about
127 * the best MTU value don't really hold when using modern modems with
128 * BTLZ data compression because the modem buffers play a much larger
129 * role in interactive performance than the MTU. The MTU can be changed
130 * at any time to suit the specific environment with ifconfig(8), and
131 * its maximum value is defined as SLTMAX. SLTMAX must not be so large
132 * that it would overflow the stack if BPF is configured (XXX; if_ppp.c
133 * handles this better).
135 * SLIP_HIWAT is the amount of data that will be queued 'downstream'
136 * of us (i.e., in clists waiting to be picked up by the tty output
137 * interrupt). If we queue a lot of data downstream, it's immune to
138 * our t.o.s. queuing.
139 * E.g., if SLIP_HIWAT is 1024, the interactive traffic in mixed
140 * telnet/ftp will see a 1 sec wait, independent of the mtu (the
141 * wait is dependent on the ftp window size but that's typically
142 * 1k - 4k). So, we want SLIP_HIWAT just big enough to amortize
143 * the cost (in idle time on the wire) of the tty driver running
144 * off the end of its clists & having to call back slstart for a
145 * new packet. For a tty interface with any buffering at all, this
146 * cost will be zero. Even with a totally brain dead interface (like
147 * the one on a typical workstation), the cost will be <= 1 character
148 * time. So, setting SLIP_HIWAT to ~100 guarantees that we'll lose
149 * at most 1% while maintaining good interactive response.
152 #define BUFOFFSET (128+sizeof(struct ifnet **)+SLIP_HDRLEN)
154 #define BUFOFFSET (128+sizeof(struct ifnet **))
156 #define SLRMAX (MCLBYTES - BUFOFFSET)
157 #define SLBUFSIZE (SLRMAX + BUFOFFSET)
159 #define SLMTU 552 /* default MTU */
161 #define SLTMAX 1500 /* maximum MTU */
162 #define SLIP_HIWAT roundup(50,CBSIZE)
163 #define CLISTRESERVE 1024 /* Can't let clists get too low */
166 * SLIP ABORT ESCAPE MECHANISM:
167 * (inspired by HAYES modem escape arrangement)
168 * 1sec escape 1sec escape 1sec escape { 1sec escape 1sec escape }
169 * within window time signals a "soft" exit from slip mode by remote end
170 * if the IFF_DEBUG flag is on.
172 #define ABT_ESC '\033' /* can't be t_intr - distant host must know it*/
173 #define ABT_IDLE 1 /* in seconds - idle before an escape */
174 #define ABT_COUNT 3 /* count of escapes for abort */
175 #define ABT_WINDOW (ABT_COUNT*2+2) /* in seconds - time to count */
177 static struct sl_softc sl_softc[NSL];
179 #define FRAME_END 0xc0 /* Frame End */
180 #define FRAME_ESCAPE 0xdb /* Frame Esc */
181 #define TRANS_FRAME_END 0xdc /* transposed frame end */
182 #define TRANS_FRAME_ESCAPE 0xdd /* transposed frame esc */
184 static int slinit __P((struct sl_softc *));
185 static struct mbuf *sl_btom __P((struct sl_softc *, int));
186 static timeout_t sl_keepalive;
187 static timeout_t sl_outfill;
188 static int slclose __P((struct tty *,int));
189 static int slinput __P((int, struct tty *));
190 static int slioctl __P((struct ifnet *, u_long, caddr_t));
191 static int sltioctl __P((struct tty *, u_long, caddr_t, int, struct proc *));
192 static int slopen __P((dev_t, struct tty *));
193 static int sloutput __P((struct ifnet *,
194 struct mbuf *, struct sockaddr *, struct rtentry *));
195 static int slstart __P((struct tty *));
197 static struct linesw slipdisc = {
198 slopen, slclose, l_noread, l_nowrite,
199 sltioctl, slinput, slstart, ttymodem,
204 * Called from boot code to establish sl interfaces.
210 register struct sl_softc *sc;
213 linesw[SLIPDISC] = slipdisc;
215 for (sc = sl_softc; i < NSL; sc++) {
216 sc->sc_if.if_name = "sl";
217 sc->sc_if.if_unit = i++;
218 sc->sc_if.if_mtu = SLMTU;
220 IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST;
221 sc->sc_if.if_type = IFT_SLIP;
222 sc->sc_if.if_ioctl = slioctl;
223 sc->sc_if.if_output = sloutput;
224 sc->sc_if.if_snd.ifq_maxlen = 50;
225 sc->sc_fastq.ifq_maxlen = 32;
226 sc->sc_if.if_linkmib = sc;
227 sc->sc_if.if_linkmiblen = sizeof *sc;
228 if_attach(&sc->sc_if);
230 bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
237 register struct sl_softc *sc;
241 if (sc->sc_ep == (u_char *) 0) {
244 sc->sc_ep = (u_char *)p + SLBUFSIZE;
246 printf("sl%d: can't allocate buffer\n", sc - sl_softc);
250 sc->sc_buf = sc->sc_ep - SLRMAX;
251 sc->sc_mp = sc->sc_buf;
252 sl_compress_init(&sc->sc_comp, -1);
257 * Line specific open routine.
258 * Attach the given tty to the first available sl unit.
264 register struct tty *tp;
266 struct proc *p = curproc; /* XXX */
267 register struct sl_softc *sc;
271 error = suser(p->p_ucred, &p->p_acflag);
275 if (tp->t_line == SLIPDISC)
278 for (nsl = NSL, sc = sl_softc; --nsl >= 0; sc++)
279 if (sc->sc_ttyp == NULL && !(sc->sc_flags & SC_STATIC)) {
282 tp->t_sc = (caddr_t)sc;
284 sc->sc_if.if_baudrate = tp->t_ospeed;
285 ttyflush(tp, FREAD | FWRITE);
287 tp->t_line = SLIPDISC;
289 * We don't use t_canq or t_rawq, so reduce their
290 * cblock resources to 0. Reserve enough cblocks
291 * for t_outq to guarantee that we can fit a full
292 * packet if the SLIP_HIWAT check allows slstart()
293 * to loop. Use the same value for the cblock
294 * limit since the reserved blocks should always
295 * be enough. Reserving cblocks probably makes
296 * the CLISTRESERVE check unnecessary and wasteful.
298 clist_alloc_cblocks(&tp->t_canq, 0, 0);
299 clist_alloc_cblocks(&tp->t_outq,
300 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1,
301 SLIP_HIWAT + 2 * sc->sc_if.if_mtu + 1);
302 clist_alloc_cblocks(&tp->t_rawq, 0, 0);
313 * Line specific close routine.
314 * Detach the tty from the sl unit.
321 register struct sl_softc *sc;
324 ttyflush(tp, FREAD | FWRITE);
326 * XXX the placement of the following spl is misleading. tty
327 * interrupts must be blocked across line discipline switches
328 * and throughout closes to avoid races.
330 s = splimp(); /* actually, max(spltty, splnet) */
331 clist_free_cblocks(&tp->t_outq);
333 sc = (struct sl_softc *)tp->t_sc;
335 if (sc->sc_outfill) {
337 untimeout(sl_outfill, sc, sc->sc_ofhandle);
339 if (sc->sc_keepalive) {
340 sc->sc_keepalive = 0;
341 untimeout(sl_keepalive, sc, sc->sc_kahandle);
344 sc->sc_flags &= SC_STATIC;
347 MCLFREE((caddr_t)(sc->sc_ep - SLBUFSIZE));
357 * Line specific (tty) ioctl routine.
358 * Provide a way to get the sl unit number.
362 sltioctl(tp, cmd, data, flag, p)
369 struct sl_softc *sc = (struct sl_softc *)tp->t_sc, *nc, *tmpnc;
375 *(int *)data = sc->sc_if.if_unit;
379 if (sc->sc_if.if_unit != *(u_int *)data) {
380 for (nsl = NSL, nc = sl_softc; --nsl >= 0; nc++) {
381 if ( nc->sc_if.if_unit == *(u_int *)data
382 && nc->sc_ttyp == NULL
384 tmpnc = malloc(sizeof *tmpnc, M_TEMP,
392 nc->sc_if = tmpnc->sc_if;
393 tmpnc->sc_if = sc->sc_if;
396 if (sc->sc_if.if_flags & IFF_UP) {
398 if (!(nc->sc_if.if_flags & IFF_UP))
400 } else if (nc->sc_if.if_flags & IFF_UP)
402 sc->sc_flags &= ~SC_STATIC;
403 sc->sc_flags |= (nc->sc_flags & SC_STATIC);
412 sc->sc_flags |= SC_STATIC;
416 sc->sc_keepalive = *(u_int *)data * hz;
417 if (sc->sc_keepalive) {
418 sc->sc_flags |= SC_KEEPALIVE;
419 sc->sc_kahandle = timeout(sl_keepalive, sc,
422 if ((sc->sc_flags & SC_KEEPALIVE) != 0) {
423 untimeout(sl_keepalive, sc, sc->sc_kahandle);
424 sc->sc_flags &= ~SC_KEEPALIVE;
430 *(int *)data = sc->sc_keepalive / hz;
434 sc->sc_outfill = *(u_int *)data * hz;
435 if (sc->sc_outfill) {
436 sc->sc_flags |= SC_OUTWAIT;
437 sc->sc_ofhandle = timeout(sl_outfill, sc,
440 if ((sc->sc_flags & SC_OUTWAIT) != 0) {
441 untimeout(sl_outfill, sc, sc->sc_ofhandle);
442 sc->sc_flags &= ~SC_OUTWAIT;
448 *(int *)data = sc->sc_outfill / hz;
460 * Queue a packet. Start transmission if not active.
461 * Compression happens in slstart; if we do it here, IP TOS
462 * will cause us to not compress "background" packets, because
463 * ordering gets trashed. It can be done for all packets in slstart.
466 sloutput(ifp, m, dst, rtp)
468 register struct mbuf *m;
469 struct sockaddr *dst;
472 register struct sl_softc *sc = &sl_softc[ifp->if_unit];
473 register struct ip *ip;
474 register struct ifqueue *ifq;
478 * `Cannot happen' (see slioctl). Someday we will extend
479 * the line protocol to support other address families.
481 if (dst->sa_family != AF_INET) {
482 printf("sl%d: af%d not supported\n", sc->sc_if.if_unit,
485 sc->sc_if.if_noproto++;
486 return (EAFNOSUPPORT);
489 if (sc->sc_ttyp == NULL || !(ifp->if_flags & IFF_UP)) {
493 if ((sc->sc_ttyp->t_state & TS_CONNECTED) == 0) {
495 return (EHOSTUNREACH);
497 ifq = &sc->sc_if.if_snd;
498 ip = mtod(m, struct ip *);
499 if (sc->sc_if.if_flags & SC_NOICMP && ip->ip_p == IPPROTO_ICMP) {
501 return (ENETRESET); /* XXX ? */
503 if (ip->ip_tos & IPTOS_LOWDELAY)
510 sc->sc_if.if_oerrors++;
514 if (sc->sc_ttyp->t_outq.c_cc == 0)
515 slstart(sc->sc_ttyp);
521 * Start output on interface. Get another datagram
522 * to send from the interface queue and map it to
523 * the interface before starting output.
527 register struct tty *tp;
529 register struct sl_softc *sc = (struct sl_softc *)tp->t_sc;
530 register struct mbuf *m;
532 register struct ip *ip;
536 u_char bpfbuf[SLTMAX + SLIP_HDRLEN];
537 register int len = 0;
542 * Call output process whether or not there is more in the
543 * output queue. We are being called in lieu of ttstart
544 * and must do what it would.
548 if (tp->t_outq.c_cc != 0) {
550 sc->sc_flags &= ~SC_OUTWAIT;
551 if (tp->t_outq.c_cc > SLIP_HIWAT)
556 * This happens briefly when the line shuts down.
562 * Get a packet and send it to the interface.
565 IF_DEQUEUE(&sc->sc_fastq, m);
567 sc->sc_if.if_omcasts++; /* XXX */
569 IF_DEQUEUE(&sc->sc_if.if_snd, m);
575 * We do the header compression here rather than in sloutput
576 * because the packets will be out of order if we are using TOS
577 * queueing, and the connection id compression will get
578 * munged when this happens.
581 if (sc->sc_if.if_bpf) {
583 * We need to save the TCP/IP header before it's
584 * compressed. To avoid complicated code, we just
585 * copy the entire packet into a stack buffer (since
586 * this is a serial line, packets should be short
587 * and/or the copy should be negligible cost compared
588 * to the packet transmission time).
590 register struct mbuf *m1 = m;
591 register u_char *cp = bpfbuf + SLIP_HDRLEN;
595 register int mlen = m1->m_len;
597 bcopy(mtod(m1, caddr_t), cp, mlen);
600 } while (m1 = m1->m_next);
603 ip = mtod(m, struct ip *);
604 if (ip->ip_v == IPVERSION && ip->ip_p == IPPROTO_TCP) {
605 if (sc->sc_if.if_flags & SC_COMPRESS)
606 *mtod(m, u_char *) |= sl_compress_tcp(m, ip,
610 if (sc->sc_if.if_bpf) {
612 * Put the SLIP pseudo-"link header" in place. The
613 * compressed header is now at the beginning of the
616 bpfbuf[SLX_DIR] = SLIPDIR_OUT;
617 bcopy(mtod(m, caddr_t), &bpfbuf[SLX_CHDR], CHDR_LEN);
618 bpf_tap(&sc->sc_if, bpfbuf, len + SLIP_HDRLEN);
623 * If system is getting low on clists, just flush our
624 * output queue (if the stuff was important, it'll get
625 * retransmitted). Note that SLTMAX is used instead of
626 * the current if_mtu setting because connections that
627 * have already been established still use the original
628 * (possibly larger) mss.
630 if (cfreecount < CLISTRESERVE + SLTMAX) {
632 sc->sc_if.if_collisions++;
636 sc->sc_flags &= ~SC_OUTWAIT;
638 * The extra FRAME_END will start up a new packet, and thus
639 * will flush any accumulated garbage. We do this whenever
640 * the line may have been idle for some time.
642 if (tp->t_outq.c_cc == 0) {
643 ++sc->sc_if.if_obytes;
644 (void) putc(FRAME_END, &tp->t_outq);
650 cp = mtod(m, u_char *); ep = cp + m->m_len;
653 * Find out how many bytes in the string we can
654 * handle without doing something special.
656 register u_char *bp = cp;
669 * Put n characters at once
670 * into the tty output queue.
672 if (b_to_q((char *)bp, cp - bp,
675 sc->sc_if.if_obytes += cp - bp;
678 * If there are characters left in the mbuf,
679 * the first one must be special..
680 * Put it out in a different form.
683 if (putc(FRAME_ESCAPE, &tp->t_outq))
685 if (putc(*cp++ == FRAME_ESCAPE ?
686 TRANS_FRAME_ESCAPE : TRANS_FRAME_END,
688 (void) unputc(&tp->t_outq);
691 sc->sc_if.if_obytes += 2;
698 if (putc(FRAME_END, &tp->t_outq)) {
700 * Not enough room. Remove a char to make room
701 * and end the packet normally.
702 * If you get many collisions (more than one or two
703 * a day) you probably do not have enough clists
704 * and you should increase "nclist" in param.c.
706 (void) unputc(&tp->t_outq);
707 (void) putc(FRAME_END, &tp->t_outq);
708 sc->sc_if.if_collisions++;
710 ++sc->sc_if.if_obytes;
711 sc->sc_if.if_opackets++;
718 * Copy data buffer to mbuf chain; add ifnet pointer.
722 register struct sl_softc *sc;
725 register struct mbuf *m;
727 MGETHDR(m, M_DONTWAIT, MT_DATA);
732 * If we have more than MHLEN bytes, it's cheaper to
733 * queue the cluster we just filled & allocate a new one
734 * for the input buffer. Otherwise, fill the mbuf we
735 * allocated above. Note that code in the input routine
736 * guarantees that packet will fit in a cluster.
739 MCLGET(m, M_DONTWAIT);
740 if ((m->m_flags & M_EXT) == 0) {
742 * we couldn't get a cluster - if memory's this
743 * low, it's time to start dropping packets.
748 sc->sc_ep = mtod(m, u_char *) + SLBUFSIZE;
749 m->m_data = (caddr_t)sc->sc_buf;
750 m->m_ext.ext_buf = (caddr_t)((intptr_t)sc->sc_buf &~ MCLOFSET);
752 bcopy((caddr_t)sc->sc_buf, mtod(m, caddr_t), len);
755 m->m_pkthdr.len = len;
756 m->m_pkthdr.rcvif = &sc->sc_if;
761 * tty interface receiver interrupt.
766 register struct tty *tp;
768 register struct sl_softc *sc;
769 register struct mbuf *m;
773 u_char chdr[CHDR_LEN];
777 sc = (struct sl_softc *)tp->t_sc;
780 if (c & TTY_ERRORMASK || (tp->t_state & TS_CONNECTED) == 0) {
781 sc->sc_flags |= SC_ERROR;
786 ++sc->sc_if.if_ibytes;
788 if (sc->sc_if.if_flags & IFF_DEBUG) {
791 * If we have a previous abort, see whether
792 * this one is within the time limit.
794 if (sc->sc_abortcount &&
795 time_second >= sc->sc_starttime + ABT_WINDOW)
796 sc->sc_abortcount = 0;
798 * If we see an abort after "idle" time, count it;
799 * record when the first abort escape arrived.
801 if (time_second >= sc->sc_lasttime + ABT_IDLE) {
802 if (++sc->sc_abortcount == 1)
803 sc->sc_starttime = time_second;
804 if (sc->sc_abortcount >= ABT_COUNT) {
810 sc->sc_abortcount = 0;
811 sc->sc_lasttime = time_second;
816 case TRANS_FRAME_ESCAPE:
821 case TRANS_FRAME_END:
831 sc->sc_flags &= ~SC_KEEPALIVE;
832 if(sc->sc_flags & SC_ERROR) {
833 sc->sc_flags &= ~SC_ERROR;
836 len = sc->sc_mp - sc->sc_buf;
838 /* less than min length packet - ignore */
842 if (sc->sc_if.if_bpf) {
844 * Save the compressed header, so we
845 * can tack it on later. Note that we
846 * will end up copying garbage in some
847 * cases but this is okay. We remember
848 * where the buffer started so we can
849 * compute the new header length.
851 bcopy(sc->sc_buf, chdr, CHDR_LEN);
855 if ((c = (*sc->sc_buf & 0xf0)) != (IPVERSION << 4)) {
857 c = TYPE_COMPRESSED_TCP;
858 else if (c == TYPE_UNCOMPRESSED_TCP)
859 *sc->sc_buf &= 0x4f; /* XXX */
861 * We've got something that's not an IP packet.
862 * If compression is enabled, try to decompress it.
863 * Otherwise, if `auto-enable' compression is on and
864 * it's a reasonable packet, decompress it and then
865 * enable compression. Otherwise, drop it.
867 if (sc->sc_if.if_flags & SC_COMPRESS) {
868 len = sl_uncompress_tcp(&sc->sc_buf, len,
869 (u_int)c, &sc->sc_comp);
872 } else if ((sc->sc_if.if_flags & SC_AUTOCOMP) &&
873 c == TYPE_UNCOMPRESSED_TCP && len >= 40) {
874 len = sl_uncompress_tcp(&sc->sc_buf, len,
875 (u_int)c, &sc->sc_comp);
878 sc->sc_if.if_flags |= SC_COMPRESS;
883 if (sc->sc_if.if_bpf) {
885 * Put the SLIP pseudo-"link header" in place.
886 * We couldn't do this any earlier since
887 * decompression probably moved the buffer
888 * pointer. Then, invoke BPF.
890 register u_char *hp = sc->sc_buf - SLIP_HDRLEN;
892 hp[SLX_DIR] = SLIPDIR_IN;
893 bcopy(chdr, &hp[SLX_CHDR], CHDR_LEN);
894 bpf_tap(&sc->sc_if, hp, len + SLIP_HDRLEN);
897 m = sl_btom(sc, len);
901 sc->sc_if.if_ipackets++;
903 if ((sc->sc_if.if_flags & IFF_UP) == 0) {
909 if (IF_QFULL(&ipintrq)) {
911 sc->sc_if.if_ierrors++;
912 sc->sc_if.if_iqdrops++;
915 IF_ENQUEUE(&ipintrq, m);
916 schednetisr(NETISR_IP);
921 if (sc->sc_mp < sc->sc_ep) {
927 /* can't put lower; would miss an extra frame */
928 sc->sc_flags |= SC_ERROR;
931 sc->sc_if.if_ierrors++;
933 sc->sc_mp = sc->sc_buf = sc->sc_ep - SLRMAX;
939 * Process an ioctl request.
942 slioctl(ifp, cmd, data)
943 register struct ifnet *ifp;
947 register struct ifaddr *ifa = (struct ifaddr *)data;
948 register struct ifreq *ifr = (struct ifreq *)data;
949 register int s, error = 0;
957 * if.c will set the interface up even if we
960 if (sl_softc[ifp->if_unit].sc_ttyp == NULL) {
961 ifp->if_flags &= ~IFF_UP;
966 * This is "historical" - set the interface up when
967 * setting the address.
969 if (ifa->ifa_addr->sa_family == AF_INET) {
970 if (sl_softc[ifp->if_unit].sc_ttyp != NULL)
973 error = EAFNOSUPPORT;
978 if (ifa->ifa_addr->sa_family != AF_INET)
979 error = EAFNOSUPPORT;
988 * Set the interface MTU.
990 if (ifr->ifr_mtu > SLTMAX)
995 ifp->if_mtu = ifr->ifr_mtu;
996 tp = sl_softc[ifp->if_unit].sc_ttyp;
998 clist_alloc_cblocks(&tp->t_outq,
999 SLIP_HIWAT + 2 * ifp->if_mtu + 1,
1000 SLIP_HIWAT + 2 * ifp->if_mtu + 1);
1015 struct sl_softc *sc = chan;
1017 if (sc->sc_keepalive) {
1018 if (sc->sc_flags & SC_KEEPALIVE)
1019 pgsignal (sc->sc_ttyp->t_pgrp, SIGURG, 1);
1021 sc->sc_flags |= SC_KEEPALIVE;
1022 sc->sc_kahandle = timeout(sl_keepalive, sc, sc->sc_keepalive);
1024 sc->sc_flags &= ~SC_KEEPALIVE;
1032 struct sl_softc *sc = chan;
1033 register struct tty *tp = sc->sc_ttyp;
1036 if (sc->sc_outfill && tp != NULL) {
1037 if (sc->sc_flags & SC_OUTWAIT) {
1039 ++sc->sc_if.if_obytes;
1040 (void) putc(FRAME_END, &tp->t_outq);
1044 sc->sc_flags |= SC_OUTWAIT;
1045 sc->sc_ofhandle = timeout(sl_outfill, sc, sc->sc_outfill);
1047 sc->sc_flags &= ~SC_OUTWAIT;