ifdef ohpuxssig under COMPAT_OHPUX
[unix-history] / usr / src / sys / net / if_sl.c
CommitLineData
5b519e94 1/*
1db6ff40 2 * Copyright (c) 1987, 1989, 1992 Regents of the University of California.
5b519e94
KB
3 * All rights reserved.
4 *
dbf0c423 5 * %sccs.include.redist.c%
5b519e94 6 *
78cafbd4 7 * @(#)if_sl.c 7.29 (Berkeley) %G%
5b519e94 8 */
7c2732d1 9
41b6e003
MK
10/*
11 * Serial Line interface
12 *
13 * Rick Adams
14 * Center for Seismic Studies
15 * 1300 N 17th Street, Suite 1450
16 * Arlington, Virginia 22209
17 * (703)276-7900
18 * rick@seismo.ARPA
19 * seismo!rick
20 *
41b6e003 21 * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
8011f5df 22 * N.B.: this belongs in netinet, not net, the way it stands now.
7c2732d1
MK
23 * Should have a link-layer type designation, but wouldn't be
24 * backwards-compatible.
41b6e003
MK
25 *
26 * Converted to 4.3BSD Beta by Chris Torek.
8011f5df 27 * Other changes made at Berkeley, based in part on code by Kirk Smith.
270f7144
MK
28 * W. Jolitz added slip abort.
29 *
30 * Hacked almost beyond recognition by Van Jacobson (van@helios.ee.lbl.gov).
31 * Added priority queuing for "interactive" traffic; hooks for TCP
32 * header compression; ICMP filtering (at 2400 baud, some cretin
33 * pinging you can use up all your bandwidth). Made low clist behavior
34 * more robust and slightly less likely to hang serial line.
35 * Sped up a bunch of things.
36 *
37 * Note that splimp() is used throughout to block both (tty) input
38 * interrupts and network activity; thus, splimp must be >= spltty.
41b6e003
MK
39 */
40
41b6e003
MK
41#include "sl.h"
42#if NSL > 0
43
44#include "param.h"
06242857 45#include "proc.h"
41b6e003
MK
46#include "mbuf.h"
47#include "buf.h"
8672a1f0 48#include "dk.h"
41b6e003
MK
49#include "socket.h"
50#include "ioctl.h"
8011f5df 51#include "file.h"
41b6e003 52#include "tty.h"
4a23a8aa
WN
53#include "kernel.h"
54#include "conf.h"
f81dc893 55#include "machine/cpu.h"
41b6e003 56
8011f5df 57#include "if.h"
4dcb4b06 58#include "if_types.h"
8011f5df
MK
59#include "netisr.h"
60#include "route.h"
f81dc893 61
8011f5df 62#if INET
06242857
MK
63#include "netinet/in.h"
64#include "netinet/in_systm.h"
65#include "netinet/in_var.h"
66#include "netinet/ip.h"
67#else
68Huh? Slip without inet?
8011f5df 69#endif
41b6e003 70
270f7144
MK
71#include "slcompress.h"
72#include "if_slvar.h"
73
41b6e003 74/*
af951bc0 75 * SLMAX is a hard limit on input packet size. To simplify the code
270f7144 76 * and improve performance, we require that packets fit in an mbuf
af951bc0
SL
77 * cluster, and if we get a compressed packet, there's enough extra
78 * room to expand the header into a max length tcp/ip header (128
79 * bytes). So, SLMAX can be at most
80 * MCLBYTES - 128
270f7144 81 *
af951bc0
SL
82 * SLMTU is a hard limit on output packet size. To insure good
83 * interactive response, SLMTU wants to be the smallest size that
84 * amortizes the header cost. (Remember that even with
85 * type-of-service queuing, we have to wait for any in-progress
86 * packet to finish. I.e., we wait, on the average, 1/2 * mtu /
87 * cps, where cps is the line speed in characters per second.
88 * E.g., 533ms wait for a 1024 byte MTU on a 9600 baud line. The
89 * average compressed header size is 6-8 bytes so any MTU > 90
90 * bytes will give us 90% of the line bandwidth. A 100ms wait is
91 * tolerable (500ms is not), so want an MTU around 296. (Since TCP
92 * will send 256 byte segments (to allow for 40 byte headers), the
93 * typical packet size on the wire will be around 260 bytes). In
94 * 4.3tahoe+ systems, we can set an MTU in a route so we do that &
95 * leave the interface MTU relatively high (so we don't IP fragment
96 * when acting as a gateway to someone using a stupid MTU).
97 *
98 * Similar considerations apply to SLIP_HIWAT: It's the amount of
99 * data that will be queued 'downstream' of us (i.e., in clists
100 * waiting to be picked up by the tty output interrupt). If we
101 * queue a lot of data downstream, it's immune to our t.o.s. queuing.
102 * E.g., if SLIP_HIWAT is 1024, the interactive traffic in mixed
103 * telnet/ftp will see a 1 sec wait, independent of the mtu (the
104 * wait is dependent on the ftp window size but that's typically
105 * 1k - 4k). So, we want SLIP_HIWAT just big enough to amortize
106 * the cost (in idle time on the wire) of the tty driver running
107 * off the end of its clists & having to call back slstart for a
108 * new packet. For a tty interface with any buffering at all, this
109 * cost will be zero. Even with a totally brain dead interface (like
110 * the one on a typical workstation), the cost will be <= 1 character
111 * time. So, setting SLIP_HIWAT to ~100 guarantees that we'll lose
112 * at most 1% while maintaining good interactive response.
41b6e003 113 */
b25c0eeb 114#define BUFOFFSET 128
af951bc0
SL
115#define SLMAX (MCLBYTES - BUFOFFSET)
116#define SLBUFSIZE (SLMAX + BUFOFFSET)
117#define SLMTU 296
118#define SLIP_HIWAT roundup(50,CBSIZE)
270f7144 119#define CLISTRESERVE 1024 /* Can't let clists get too low */
b25c0eeb 120
4a23a8aa
WN
121/*
122 * SLIP ABORT ESCAPE MECHANISM:
123 * (inspired by HAYES modem escape arrangement)
124 * 1sec escape 1sec escape 1sec escape { 1sec escape 1sec escape }
db1ff792 125 * within window time signals a "soft" exit from slip mode by remote end
1db6ff40 126 * if the IFF_DEBUG flag is on.
4a23a8aa 127 */
4a23a8aa 128#define ABT_ESC '\033' /* can't be t_intr - distant host must know it*/
db1ff792
MK
129#define ABT_IDLE 1 /* in seconds - idle before an escape */
130#define ABT_COUNT 3 /* count of escapes for abort */
131#define ABT_WINDOW (ABT_COUNT*2+2) /* in seconds - time to count */
4a23a8aa 132
270f7144 133struct sl_softc sl_softc[NSL];
4a23a8aa 134
270f7144
MK
135#define FRAME_END 0xc0 /* Frame End */
136#define FRAME_ESCAPE 0xdb /* Frame Esc */
137#define TRANS_FRAME_END 0xdc /* transposed frame end */
138#define TRANS_FRAME_ESCAPE 0xdd /* transposed frame esc */
41b6e003
MK
139
140#define t_sc T_LINEP
141
142int sloutput(), slioctl(), ttrstrt();
4dcb4b06 143extern struct timeval time;
41b6e003
MK
144
145/*
146 * Called from boot code to establish sl interfaces.
147 */
148slattach()
149{
150 register struct sl_softc *sc;
151 register int i = 0;
152
153 for (sc = sl_softc; i < NSL; sc++) {
154 sc->sc_if.if_name = "sl";
c1d0eac5 155 sc->sc_if.if_next = NULL;
41b6e003
MK
156 sc->sc_if.if_unit = i++;
157 sc->sc_if.if_mtu = SLMTU;
78cafbd4
KS
158#ifdef MULTICAST
159 sc->sc_if.if_flags =
160 IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST;
161#else
1db6ff40 162 sc->sc_if.if_flags = IFF_POINTOPOINT | SC_AUTOCOMP;
78cafbd4 163#endif
4dcb4b06 164 sc->sc_if.if_type = IFT_SLIP;
41b6e003
MK
165 sc->sc_if.if_ioctl = slioctl;
166 sc->sc_if.if_output = sloutput;
270f7144
MK
167 sc->sc_if.if_snd.ifq_maxlen = 50;
168 sc->sc_fastq.ifq_maxlen = 32;
41b6e003
MK
169 if_attach(&sc->sc_if);
170 }
171}
172
270f7144
MK
173static int
174slinit(sc)
175 register struct sl_softc *sc;
176{
177 register caddr_t p;
178
179 if (sc->sc_ep == (u_char *) 0) {
180 MCLALLOC(p, M_WAIT);
181 if (p)
b25c0eeb 182 sc->sc_ep = (u_char *)p + SLBUFSIZE;
270f7144
MK
183 else {
184 printf("sl%d: can't allocate buffer\n", sc - sl_softc);
185 sc->sc_if.if_flags &= ~IFF_UP;
186 return (0);
187 }
188 }
af951bc0 189 sc->sc_buf = sc->sc_ep - SLMAX;
270f7144
MK
190 sc->sc_mp = sc->sc_buf;
191 sl_compress_init(&sc->sc_comp);
192 return (1);
193}
194
41b6e003
MK
195/*
196 * Line specific open routine.
197 * Attach the given tty to the first available sl unit.
198 */
8011f5df 199/* ARGSUSED */
41b6e003
MK
200slopen(dev, tp)
201 dev_t dev;
202 register struct tty *tp;
203{
06242857 204 struct proc *p = curproc; /* XXX */
41b6e003
MK
205 register struct sl_softc *sc;
206 register int nsl;
06c16dfa 207 int error;
41b6e003 208
06242857 209 if (error = suser(p->p_ucred, &p->p_acflag))
06c16dfa 210 return (error);
270f7144 211
8011f5df 212 if (tp->t_line == SLIPDISC)
b25c0eeb 213 return (0);
41b6e003 214
270f7144 215 for (nsl = NSL, sc = sl_softc; --nsl >= 0; sc++)
41b6e003 216 if (sc->sc_ttyp == NULL) {
8011f5df
MK
217 if (slinit(sc) == 0)
218 return (ENOBUFS);
41b6e003
MK
219 tp->t_sc = (caddr_t)sc;
220 sc->sc_ttyp = tp;
4dcb4b06 221 sc->sc_if.if_baudrate = tp->t_ospeed;
8011f5df 222 ttyflush(tp, FREAD | FWRITE);
41b6e003
MK
223 return (0);
224 }
8011f5df 225 return (ENXIO);
41b6e003
MK
226}
227
228/*
229 * Line specific close routine.
230 * Detach the tty from the sl unit.
231 * Mimics part of ttyclose().
232 */
233slclose(tp)
234 struct tty *tp;
235{
236 register struct sl_softc *sc;
237 int s;
238
239 ttywflush(tp);
270f7144 240 s = splimp(); /* actually, max(spltty, splnet) */
41b6e003 241 tp->t_line = 0;
41b6e003
MK
242 sc = (struct sl_softc *)tp->t_sc;
243 if (sc != NULL) {
244 if_down(&sc->sc_if);
245 sc->sc_ttyp = NULL;
246 tp->t_sc = NULL;
b25c0eeb 247 MCLFREE((caddr_t)(sc->sc_ep - SLBUFSIZE));
270f7144
MK
248 sc->sc_ep = 0;
249 sc->sc_mp = 0;
8011f5df 250 sc->sc_buf = 0;
41b6e003
MK
251 }
252 splx(s);
253}
254
255/*
256 * Line specific (tty) ioctl routine.
257 * Provide a way to get the sl unit number.
258 */
8011f5df 259/* ARGSUSED */
41b6e003
MK
260sltioctl(tp, cmd, data, flag)
261 struct tty *tp;
4d8438d7 262 int cmd;
41b6e003 263 caddr_t data;
4d8438d7 264 int flag;
41b6e003 265{
4a23a8aa
WN
266 struct sl_softc *sc = (struct sl_softc *)tp->t_sc;
267 int s;
41b6e003 268
4a23a8aa 269 switch (cmd) {
06242857 270 case SLIOCGUNIT:
4a23a8aa
WN
271 *(int *)data = sc->sc_if.if_unit;
272 break;
4a23a8aa 273
4a23a8aa
WN
274 default:
275 return (-1);
fc62c320 276 }
4a23a8aa 277 return (0);
41b6e003
MK
278}
279
280/*
281 * Queue a packet. Start transmission if not active.
282 */
283sloutput(ifp, m, dst)
b25c0eeb 284 struct ifnet *ifp;
41b6e003
MK
285 register struct mbuf *m;
286 struct sockaddr *dst;
287{
b25c0eeb 288 register struct sl_softc *sc = &sl_softc[ifp->if_unit];
270f7144
MK
289 register struct ip *ip;
290 register struct ifqueue *ifq;
1db6ff40 291 register int p;
41b6e003
MK
292 int s;
293
294 /*
295 * `Cannot happen' (see slioctl). Someday we will extend
296 * the line protocol to support other address families.
297 */
298 if (dst->sa_family != AF_INET) {
b25c0eeb 299 printf("sl%d: af%d not supported\n", sc->sc_if.if_unit,
41b6e003
MK
300 dst->sa_family);
301 m_freem(m);
db1ff792 302 sc->sc_if.if_noproto++;
41b6e003
MK
303 return (EAFNOSUPPORT);
304 }
305
41b6e003
MK
306 if (sc->sc_ttyp == NULL) {
307 m_freem(m);
308 return (ENETDOWN); /* sort of */
309 }
eadd9817
MK
310 if ((sc->sc_ttyp->t_state & TS_CARR_ON) == 0) {
311 m_freem(m);
312 return (EHOSTUNREACH);
313 }
b25c0eeb 314 ifq = &sc->sc_if.if_snd;
4d8438d7 315 ip = mtod(m, struct ip *);
1db6ff40
MK
316 if (ip->ip_tos & IPTOS_LOWDELAY) {
317 ifq = &sc->sc_fastq;
318 p = 1;
319 } else
320 p = 0;
4d8438d7 321 if (ip->ip_p == IPPROTO_TCP) {
0e97cde8 322 if (sc->sc_if.if_flags & SC_COMPRESS) {
af951bc0
SL
323 /*
324 * The last parameter turns off connection id
325 * compression for background traffic: Since
326 * fastq traffic can jump ahead of the background
327 * traffic, we don't know what order packets will
328 * go on the line.
329 */
330 p = sl_compress_tcp(m, ip, &sc->sc_comp, p);
270f7144 331 *mtod(m, u_char *) |= p;
4a23a8aa 332 }
0e97cde8 333 } else if (sc->sc_if.if_flags & SC_NOICMP && ip->ip_p == IPPROTO_ICMP) {
270f7144 334 m_freem(m);
db1ff792 335 return (ENETRESET); /* XXX ? */
4a23a8aa 336 }
270f7144
MK
337 s = splimp();
338 if (IF_QFULL(ifq)) {
339 IF_DROP(ifq);
41b6e003 340 m_freem(m);
270f7144 341 splx(s);
8011f5df 342 sc->sc_if.if_oerrors++;
41b6e003
MK
343 return (ENOBUFS);
344 }
270f7144 345 IF_ENQUEUE(ifq, m);
4dcb4b06 346 sc->sc_if.if_lastchange = time;
b25c0eeb 347 if (sc->sc_ttyp->t_outq.c_cc == 0)
41b6e003 348 slstart(sc->sc_ttyp);
b25c0eeb 349 splx(s);
41b6e003
MK
350 return (0);
351}
352
353/*
354 * Start output on interface. Get another datagram
355 * to send from the interface queue and map it to
356 * the interface before starting output.
357 */
358slstart(tp)
359 register struct tty *tp;
360{
361 register struct sl_softc *sc = (struct sl_softc *)tp->t_sc;
362 register struct mbuf *m;
8011f5df 363 register u_char *cp;
270f7144 364 int s;
8011f5df
MK
365 struct mbuf *m2;
366 extern int cfreecount;
41b6e003 367
8011f5df
MK
368 for (;;) {
369 /*
370 * If there is more in the output queue, just send it now.
371 * We are being called in lieu of ttstart and must do what
372 * it would.
373 */
270f7144
MK
374 if (tp->t_outq.c_cc != 0) {
375 (*tp->t_oproc)(tp);
376 if (tp->t_outq.c_cc > SLIP_HIWAT)
377 return;
378 }
8011f5df
MK
379 /*
380 * This happens briefly when the line shuts down.
381 */
382 if (sc == NULL)
383 return;
41b6e003 384
8011f5df
MK
385 /*
386 * Get a packet and send it to the interface.
387 */
388 s = splimp();
270f7144 389 IF_DEQUEUE(&sc->sc_fastq, m);
db1ff792
MK
390 if (m)
391 sc->sc_if.if_omcasts++; /* XXX */
392 else
270f7144 393 IF_DEQUEUE(&sc->sc_if.if_snd, m);
8011f5df 394 splx(s);
e8e27e8e
MK
395 if (m == NULL)
396 return;
4dcb4b06 397 sc->sc_if.if_lastchange = time;
0e97cde8 398
270f7144
MK
399 /*
400 * If system is getting low on clists, just flush our
401 * output queue (if the stuff was important, it'll get
402 * retransmitted).
403 */
404 if (cfreecount < CLISTRESERVE + SLMTU) {
405 m_freem(m);
406 sc->sc_if.if_collisions++;
407 continue;
408 }
41b6e003 409 /*
8011f5df
MK
410 * The extra FRAME_END will start up a new packet, and thus
411 * will flush any accumulated garbage. We do this whenever
412 * the line may have been idle for some time.
41b6e003 413 */
270f7144 414 if (tp->t_outq.c_cc == 0) {
db1ff792 415 ++sc->sc_if.if_obytes;
8011f5df 416 (void) putc(FRAME_END, &tp->t_outq);
270f7144 417 }
8011f5df
MK
418
419 while (m) {
270f7144
MK
420 register u_char *ep;
421
422 cp = mtod(m, u_char *); ep = cp + m->m_len;
423 while (cp < ep) {
8011f5df
MK
424 /*
425 * Find out how many bytes in the string we can
426 * handle without doing something special.
427 */
270f7144
MK
428 register u_char *bp = cp;
429
430 while (cp < ep) {
431 switch (*cp++) {
432 case FRAME_ESCAPE:
433 case FRAME_END:
434 --cp;
435 goto out;
436 }
437 }
438 out:
439 if (cp > bp) {
8011f5df
MK
440 /*
441 * Put n characters at once
442 * into the tty output queue.
443 */
270f7144 444 if (b_to_q((char *)bp, cp - bp, &tp->t_outq))
8011f5df 445 break;
db1ff792 446 sc->sc_if.if_obytes += cp - bp;
8011f5df
MK
447 }
448 /*
449 * If there are characters left in the mbuf,
450 * the first one must be special..
451 * Put it out in a different form.
452 */
270f7144 453 if (cp < ep) {
8011f5df
MK
454 if (putc(FRAME_ESCAPE, &tp->t_outq))
455 break;
270f7144 456 if (putc(*cp++ == FRAME_ESCAPE ?
8011f5df
MK
457 TRANS_FRAME_ESCAPE : TRANS_FRAME_END,
458 &tp->t_outq)) {
459 (void) unputc(&tp->t_outq);
460 break;
461 }
db1ff792 462 sc->sc_if.if_obytes += 2;
8011f5df
MK
463 }
464 }
465 MFREE(m, m2);
466 m = m2;
467 }
41b6e003 468
8011f5df
MK
469 if (putc(FRAME_END, &tp->t_outq)) {
470 /*
471 * Not enough room. Remove a char to make room
472 * and end the packet normally.
473 * If you get many collisions (more than one or two
474 * a day) you probably do not have enough clists
475 * and you should increase "nclist" in param.c.
476 */
477 (void) unputc(&tp->t_outq);
478 (void) putc(FRAME_END, &tp->t_outq);
479 sc->sc_if.if_collisions++;
8011f5df 480 } else {
db1ff792 481 ++sc->sc_if.if_obytes;
270f7144 482 sc->sc_if.if_opackets++;
8011f5df
MK
483 }
484 }
41b6e003
MK
485}
486
487/*
270f7144 488 * Copy data buffer to mbuf chain; add ifnet pointer.
41b6e003 489 */
270f7144
MK
490static struct mbuf *
491sl_btom(sc, len)
492 register struct sl_softc *sc;
41b6e003 493 register int len;
41b6e003 494{
270f7144 495 register struct mbuf *m;
41b6e003 496
270f7144
MK
497 MGETHDR(m, M_DONTWAIT, MT_DATA);
498 if (m == NULL)
499 return (NULL);
fc62c320 500
270f7144 501 /*
b25c0eeb 502 * If we have more than MHLEN bytes, it's cheaper to
270f7144
MK
503 * queue the cluster we just filled & allocate a new one
504 * for the input buffer. Otherwise, fill the mbuf we
505 * allocated above. Note that code in the input routine
506 * guarantees that packet will fit in a cluster.
507 */
270f7144
MK
508 if (len >= MHLEN) {
509 MCLGET(m, M_DONTWAIT);
510 if ((m->m_flags & M_EXT) == 0) {
b25c0eeb
MK
511 /*
512 * we couldn't get a cluster - if memory's this
513 * low, it's time to start dropping packets.
514 */
515 (void) m_free(m);
41b6e003
MK
516 return (NULL);
517 }
b25c0eeb
MK
518 sc->sc_ep = mtod(m, u_char *) + SLBUFSIZE;
519 m->m_data = (caddr_t)sc->sc_buf;
520 m->m_ext.ext_buf = (caddr_t)((int)sc->sc_buf &~ MCLOFSET);
270f7144 521 } else
b25c0eeb 522 bcopy((caddr_t)sc->sc_buf, mtod(m, caddr_t), len);
270f7144
MK
523
524 m->m_len = len;
525 m->m_pkthdr.len = len;
526 m->m_pkthdr.rcvif = &sc->sc_if;
527 return (m);
41b6e003
MK
528}
529
530/*
531 * tty interface receiver interrupt.
532 */
533slinput(c, tp)
534 register int c;
535 register struct tty *tp;
536{
537 register struct sl_softc *sc;
538 register struct mbuf *m;
270f7144 539 register int len;
41b6e003
MK
540 int s;
541
8011f5df 542 tk_nin++;
41b6e003
MK
543 sc = (struct sl_softc *)tp->t_sc;
544 if (sc == NULL)
545 return;
270f7144 546 if (!(tp->t_state&TS_CARR_ON)) /* XXX */
4a23a8aa 547 return;
41b6e003 548
4dcb4b06 549 ++sc->sc_if.if_ibytes;
270f7144
MK
550 c &= 0xff; /* XXX */
551
552#ifdef ABT_ESC
db1ff792
MK
553 if (sc->sc_if.if_flags & IFF_DEBUG) {
554 if (c == ABT_ESC) {
555 /*
556 * If we have a previous abort, see whether
557 * this one is within the time limit.
558 */
559 if (sc->sc_abortcount &&
560 time.tv_sec >= sc->sc_starttime + ABT_WINDOW)
270f7144 561 sc->sc_abortcount = 0;
db1ff792
MK
562 /*
563 * If we see an abort after "idle" time, count it;
564 * record when the first abort escape arrived.
565 */
566 if (time.tv_sec >= sc->sc_lasttime + ABT_IDLE) {
567 if (++sc->sc_abortcount == 1)
568 sc->sc_starttime = time.tv_sec;
569 if (sc->sc_abortcount >= ABT_COUNT) {
570 slclose(tp);
571 return;
572 }
270f7144 573 }
db1ff792
MK
574 } else
575 sc->sc_abortcount = 0;
270f7144 576 sc->sc_lasttime = time.tv_sec;
4a23a8aa 577 }
270f7144 578#endif
4a23a8aa 579
270f7144 580 switch (c) {
41b6e003 581
270f7144
MK
582 case TRANS_FRAME_ESCAPE:
583 if (sc->sc_escape)
41b6e003 584 c = FRAME_ESCAPE;
270f7144 585 break;
41b6e003 586
270f7144
MK
587 case TRANS_FRAME_END:
588 if (sc->sc_escape)
41b6e003 589 c = FRAME_END;
270f7144 590 break;
41b6e003 591
270f7144
MK
592 case FRAME_ESCAPE:
593 sc->sc_escape = 1;
594 return;
41b6e003 595
270f7144
MK
596 case FRAME_END:
597 len = sc->sc_mp - sc->sc_buf;
598 if (len < 3)
599 /* less than min length packet - ignore */
600 goto newpack;
601
602 if ((c = (*sc->sc_buf & 0xf0)) != (IPVERSION << 4)) {
603 if (c & 0x80)
604 c = TYPE_COMPRESSED_TCP;
605 else if (c == TYPE_UNCOMPRESSED_TCP)
606 *sc->sc_buf &= 0x4f; /* XXX */
af951bc0
SL
607 /*
608 * We've got something that's not an IP packet.
609 * If compression is enabled, try to decompress it.
610 * Otherwise, if `auto-enable' compression is on and
611 * it's a reasonable packet, decompress it and then
612 * enable compression. Otherwise, drop it.
613 */
0e97cde8 614 if (sc->sc_if.if_flags & SC_COMPRESS) {
af951bc0
SL
615 len = sl_uncompress_tcp(&sc->sc_buf, len,
616 (u_int)c, &sc->sc_comp);
617 if (len <= 0)
618 goto error;
0e97cde8 619 } else if ((sc->sc_if.if_flags & SC_AUTOCOMP) &&
af951bc0
SL
620 c == TYPE_UNCOMPRESSED_TCP && len >= 40) {
621 len = sl_uncompress_tcp(&sc->sc_buf, len,
622 (u_int)c, &sc->sc_comp);
623 if (len <= 0)
624 goto error;
0e97cde8 625 sc->sc_if.if_flags |= SC_COMPRESS;
af951bc0 626 } else
270f7144
MK
627 goto error;
628 }
629 m = sl_btom(sc, len);
630 if (m == NULL)
631 goto error;
41b6e003 632
270f7144 633 sc->sc_if.if_ipackets++;
4dcb4b06 634 sc->sc_if.if_lastchange = time;
270f7144
MK
635 s = splimp();
636 if (IF_QFULL(&ipintrq)) {
637 IF_DROP(&ipintrq);
638 sc->sc_if.if_ierrors++;
4dcb4b06 639 sc->sc_if.if_iqdrops++;
270f7144
MK
640 m_freem(m);
641 } else {
642 IF_ENQUEUE(&ipintrq, m);
643 schednetisr(NETISR_IP);
41b6e003 644 }
270f7144
MK
645 splx(s);
646 goto newpack;
41b6e003 647 }
270f7144
MK
648 if (sc->sc_mp < sc->sc_ep) {
649 *sc->sc_mp++ = c;
650 sc->sc_escape = 0;
41b6e003
MK
651 return;
652 }
270f7144
MK
653error:
654 sc->sc_if.if_ierrors++;
655newpack:
af951bc0 656 sc->sc_mp = sc->sc_buf = sc->sc_ep - SLMAX;
270f7144 657 sc->sc_escape = 0;
41b6e003
MK
658}
659
660/*
661 * Process an ioctl request.
662 */
663slioctl(ifp, cmd, data)
664 register struct ifnet *ifp;
665 int cmd;
666 caddr_t data;
667{
668 register struct ifaddr *ifa = (struct ifaddr *)data;
78cafbd4
KS
669#ifdef MULTICAST
670 register struct ifreq *ifr;
671#endif
672 register int s = splimp(), error = 0;
41b6e003
MK
673
674 switch (cmd) {
675
676 case SIOCSIFADDR:
b72a6efb 677 if (ifa->ifa_addr->sa_family == AF_INET)
41b6e003
MK
678 ifp->if_flags |= IFF_UP;
679 else
680 error = EAFNOSUPPORT;
681 break;
682
683 case SIOCSIFDSTADDR:
b72a6efb 684 if (ifa->ifa_addr->sa_family != AF_INET)
41b6e003
MK
685 error = EAFNOSUPPORT;
686 break;
687
78cafbd4
KS
688#ifdef MULTICAST
689 case SIOCADDMULTI:
690 case SIOCDELMULTI:
691 ifr = (struct ifreq *)data;
692 if (ifr == 0) {
693 error = EAFNOSUPPORT; /* XXX */
694 break;
695 }
696 switch (ifr->ifr_addr.sa_family) {
697
698#ifdef INET
699 case AF_INET:
700 break;
701#endif
702
703 default:
704 error = EAFNOSUPPORT;
705 break;
706 }
707 break;
708#endif
709
41b6e003
MK
710 default:
711 error = EINVAL;
712 }
713 splx(s);
714 return (error);
715}
716#endif