2 * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 /*---------------------------------------------------------------------------
28 * i4b_ipr.c - isdn4bsd IP over raw HDLC ISDN network driver
29 * ---------------------------------------------------------
30 * last edit-date: [Sun Mar 17 09:32:58 2002]
32 *---------------------------------------------------------------------------*
34 * statistics counter usage (interface lifetime):
35 * ----------------------------------------------
36 * sc->sc_ifp->if_ipackets # of received packets
37 * sc->sc_ifp->if_ierrors # of error packets not going to upper layers
38 * sc->sc_ifp->if_opackets # of transmitted packets
39 * sc->sc_ifp->if_oerrors # of error packets not being transmitted
40 * sc->sc_ifp->if_collisions # of invalid ip packets after VJ decompression
41 * sc->sc_ifp->if_ibytes # of bytes coming in from the line (before VJ)
42 * sc->sc_ifp->if_obytes # of bytes going out to the line (after VJ)
43 * sc->sc_ifp->if_imcasts (currently unused)
44 * sc->sc_ifp->if_omcasts # of frames sent out of the fastqueue
45 * sc->sc_ifp->if_iqdrops # of frames dropped on input because queue full
46 * sc->sc_ifp->if_noproto # of frames dropped on output because !AF_INET
48 * statistics counter usage (connection lifetime):
49 * -----------------------------------------------
50 * sc->sc_iinb # of ISDN incoming bytes from HSCX
51 * sc->sc_ioutb # of ISDN outgoing bytes from HSCX
52 * sc->sc_inb # of incoming bytes after decompression
53 * sc->sc_outb # of outgoing bytes before compression
55 *---------------------------------------------------------------------------*/
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
62 #include <sys/param.h>
63 #include <sys/systm.h>
65 #include <sys/socket.h>
66 #include <sys/errno.h>
67 #include <sys/ioccom.h>
68 #include <sys/sockio.h>
69 #include <sys/kernel.h>
71 #include <net/if_types.h>
72 #include <net/netisr.h>
73 #include <netinet/in.h>
74 #include <netinet/in_systm.h>
75 #include <netinet/in_var.h>
76 #include <netinet/ip.h>
79 #include <sys/malloc.h>
80 #include <net/slcompress.h>
81 #define IPR_COMPRESS IFF_LINK0 /* compress TCP traffic */
82 #define IPR_AUTOCOMP IFF_LINK1 /* auto-enable TCP compression */
84 /*---------------------------------------------------------------------------
85 * NOTICE: using NO separate buffer relies on the assumption, that the HSCX
86 * IRQ handler _always_ allocates a single, continuous mbuf cluster large
87 * enough to hold the maximum MTU size if the ipr interface !
89 * CAUTION: i have re-defined IPR_VJ_USEBUFFER because it makes problems
90 * with 2 i4b's back to back running cvs over ssh, cvs simply
91 * aborts because it gets bad data. Everything else (telnet/ftp?etc)
93 *---------------------------------------------------------------------------*/
94 #define IPR_VJ_USEBUFFER /* define to use an allocated separate buffer*/
95 /* undef to uncompress in the mbuf itself */
101 #include <i4b/include/i4b_ioctl.h>
102 #include <i4b/include/i4b_debug.h>
104 #include <i4b/include/i4b_global.h>
105 #include <i4b/include/i4b_l3l4.h>
107 #include <i4b/layer4/i4b_l4.h>
109 #error "Cannot be used until I4B is locked."
111 #define I4BIPRMTU 1500 /* regular MTU */
112 #define I4BIPRMAXMTU 2000 /* max MTU */
113 #define I4BIPRMINMTU 500 /* min MTU */
115 #define I4BIPRMAXQLEN 50 /* max queue length */
117 #define I4BIPRACCT 1 /* enable accounting messages */
118 #define I4BIPRACCTINTVL 2 /* accounting msg interval in secs */
119 #define I4BIPRADJFRXP 1 /* adjust 1st rxd packet */
121 /* initialized by L4 */
123 static drvr_link_t ipr_drvr_linktab[NI4BIPR];
124 static isdn_link_t *isdn_linktab[NI4BIPR];
127 struct ifnet *sc_ifp; /* network-visible interface */
128 int sc_state; /* state of the interface */
129 call_desc_t *sc_cdp; /* ptr to call descriptor */
130 int sc_updown; /* soft state of interface */
131 struct ifqueue sc_fastq; /* interactive traffic */
132 int sc_dialresp; /* dialresponse */
133 int sc_lastdialresp;/* last dialresponse */
134 struct callout_handle sc_callout;
137 int sc_iinb; /* isdn driver # of inbytes */
138 int sc_ioutb; /* isdn driver # of outbytes */
139 int sc_inb; /* # of bytes rx'd */
140 int sc_outb; /* # of bytes tx'd */
141 int sc_linb; /* last # of bytes rx'd */
142 int sc_loutb; /* last # of bytes tx'd */
143 int sc_fn; /* flag, first null acct */
147 int sc_first_pkt; /* flag, first rxd packet */
151 int sc_log_first; /* log first n packets */
155 struct slcompress sc_compr; /* tcp compression data */
156 #ifdef IPR_VJ_USEBUFFER
157 u_char *sc_cbuf; /* tcp decompression buffer */
161 } ipr_softc[NI4BIPR];
164 ST_IDLE, /* initialized, ready, idle */
165 ST_DIALING, /* dialling out to remote */
166 ST_CONNECTED_W, /* connected to remote */
167 ST_CONNECTED_A, /* connected to remote */
170 static void i4biprattach(void *);
171 PSEUDO_SET(i4biprattach, i4b_ipr);
172 static int i4biprioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
174 static void iprwatchdog(struct ifnet *ifp);
175 static void ipr_init_linktab(int unit);
176 static void ipr_tx_queue_empty(int unit);
177 static int i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rtp);
178 static void iprclearqueues(struct ipr_softc *sc);
180 /*===========================================================================*
181 * DEVICE DRIVER ROUTINES
182 *===========================================================================*/
184 /*---------------------------------------------------------------------------*
185 * interface attach routine at kernel boot time
186 *---------------------------------------------------------------------------*/
188 i4biprattach(void *dummy)
190 struct ipr_softc *sc = ipr_softc;
194 printf("i4bipr: %d IP over raw HDLC ISDN device(s) attached (VJ header compression)\n", NI4BIPR);
196 printf("i4bipr: %d IP over raw HDLC ISDN device(s) attached\n", NI4BIPR);
199 for(i=0; i < NI4BIPR; sc++, i++)
203 NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
205 sc->sc_ifp = if_alloc(IFT_ISDNBASIC);
206 if (sc->sc_ifp == NULL)
207 panic("i4b_ipr.c, i4biprattach: cannot if_alloc()");
209 sc->sc_ifp->if_softc = sc;
210 sc->sc_state = ST_IDLE;
211 if_initname(sc->sc_ifp, "ipr", i);
215 sc->sc_ifp->if_flags = IFF_POINTOPOINT | IFF_SIMPLEX | IPR_AUTOCOMP;
217 sc->sc_ifp->if_flags = IFF_POINTOPOINT | IFF_SIMPLEX;
220 sc->sc_ifp->if_mtu = I4BIPRMTU;
221 sc->sc_ifp->if_ioctl = i4biprioctl;
222 sc->sc_ifp->if_output = i4biproutput;
224 sc->sc_ifp->if_snd.ifq_maxlen = I4BIPRMAXQLEN;
225 sc->sc_fastq.ifq_maxlen = I4BIPRMAXQLEN;
227 if(!mtx_initialized(&sc->sc_fastq.ifq_mtx))
228 mtx_init(&sc->sc_fastq.ifq_mtx, "i4b_ipr_fastq", NULL, MTX_DEF);
230 sc->sc_ifp->if_ipackets = 0;
231 sc->sc_ifp->if_ierrors = 0;
232 sc->sc_ifp->if_opackets = 0;
233 sc->sc_ifp->if_oerrors = 0;
234 sc->sc_ifp->if_collisions = 0;
235 sc->sc_ifp->if_ibytes = 0;
236 sc->sc_ifp->if_obytes = 0;
237 sc->sc_ifp->if_imcasts = 0;
238 sc->sc_ifp->if_omcasts = 0;
239 sc->sc_ifp->if_iqdrops = 0;
240 sc->sc_ifp->if_noproto = 0;
243 sc->sc_ifp->if_timer = 0;
244 sc->sc_ifp->if_watchdog = iprwatchdog;
255 sc->sc_log_first = IPR_LOG;
259 sl_compress_init(&sc->sc_compr, -1);
261 #ifdef IPR_VJ_USEBUFFER
263 (u_char *)malloc(I4BIPRMAXMTU+128, M_DEVBUF, M_WAITOK))))
265 panic("i4b_ipr.c, i4biprattach: VJ malloc failed");
269 sc->sc_updown = SOFT_ENA; /* soft enabled */
270 sc->sc_dialresp = DSTAT_NONE; /* no response */
271 sc->sc_lastdialresp = DSTAT_NONE;
273 if_attach(sc->sc_ifp);
275 bpfattach(sc->sc_ifp, DLT_NULL, sizeof(u_int32_t));
279 /*---------------------------------------------------------------------------*
280 * output a packet to the ISDN B-channel
281 *---------------------------------------------------------------------------*/
283 i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
286 struct ipr_softc *sc;
296 unit = ifp->if_dunit;
298 /* BPF writes need to be handled specially. */
299 if(dst->sa_family == AF_UNSPEC)
301 bcopy(dst->sa_data, &af, sizeof(af));
307 if(dst->sa_family != AF_INET)
309 if_printf(ifp, "af%d not supported\n", dst->sa_family);
312 sc->sc_ifp->if_noproto++;
313 sc->sc_ifp->if_oerrors++;
314 return(EAFNOSUPPORT);
317 /* check interface state = UP */
319 if(!(ifp->if_flags & IFF_UP))
321 NDBGL4(L4_IPRDBG, "ipr%d: interface is DOWN!", unit);
324 sc->sc_ifp->if_oerrors++;
328 /* dial if necessary */
330 if(sc->sc_state == ST_IDLE || sc->sc_state == ST_DIALING)
334 switch(sc->sc_dialresp)
336 case DSTAT_TFAIL: /* transient failure */
337 NDBGL4(L4_IPRDBG, "ipr%d: transient dial failure!", unit);
340 sc->sc_dialresp = DSTAT_NONE;
342 sc->sc_ifp->if_oerrors++;
346 case DSTAT_PFAIL: /* permanent failure */
347 NDBGL4(L4_IPRDBG, "ipr%d: permanent dial failure!", unit);
350 sc->sc_dialresp = DSTAT_NONE;
352 sc->sc_ifp->if_oerrors++;
353 return(EHOSTUNREACH);
356 case DSTAT_INONLY: /* no dialout allowed*/
357 NDBGL4(L4_IPRDBG, "ipr%d: dialout not allowed failure!", unit);
360 sc->sc_dialresp = DSTAT_NONE;
362 sc->sc_ifp->if_oerrors++;
363 return(EHOSTUNREACH);
368 NDBGL4(L4_IPRDBG, "ipr%d: send dial request message!", unit);
369 NDBGL4(L4_DIALST, "ipr%d: setting dial state to ST_DIALING", unit);
370 i4b_l4_dialout(BDRV_IPR, unit);
371 sc->sc_state = ST_DIALING;
375 if(sc->sc_log_first > 0)
377 --(sc->sc_log_first);
378 i4b_l4_packet_ind(BDRV_IPR, unit, 1, m );
382 /* update access time */
384 microtime(&sc->sc_ifp->if_lastchange);
387 * check, if type of service indicates interactive, i.e. telnet,
388 * traffic. in case it is interactive, put it into the fast queue,
389 * else (i.e. ftp traffic) put it into the "normal" queue
392 ip = mtod(m, struct ip *); /* get ptr to ip header */
394 if(ip->ip_tos & IPTOS_LOWDELAY)
397 ifq = (struct ifqueue *)&sc->sc_ifp->if_snd;
399 /* check for space in choosen send queue */
401 if(! IF_HANDOFF(ifq, m, NULL))
403 NDBGL4(L4_IPRDBG, "ipr%d: send queue full!", unit);
405 sc->sc_ifp->if_oerrors++;
409 NDBGL4(L4_IPRDBG, "ipr%d: add packet to send queue!", unit);
411 ipr_tx_queue_empty(unit);
418 /*---------------------------------------------------------------------------*
420 *---------------------------------------------------------------------------*/
422 i4biprioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
424 struct ipr_softc *sc = ifp->if_softc;
425 struct ifreq *ifr = (struct ifreq *)data;
426 struct ifaddr *ifa = (struct ifaddr *)data;
434 case SIOCAIFADDR: /* add interface address */
435 case SIOCSIFADDR: /* set interface address */
436 case SIOCSIFDSTADDR: /* set interface destination address */
437 if(ifa->ifa_addr->sa_family != AF_INET)
438 error = EAFNOSUPPORT;
440 sc->sc_ifp->if_flags |= IFF_UP;
441 microtime(&sc->sc_ifp->if_lastchange);
444 case SIOCSIFFLAGS: /* set interface flags */
445 if(!(ifr->ifr_flags & IFF_UP))
447 if(sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
449 /* disconnect ISDN line */
450 i4b_l4_drvrdisc(BDRV_IPR,
452 sc->sc_ifp->if_drv_flags &=
456 sc->sc_state = ST_IDLE;
463 if(ifr->ifr_flags & IFF_DEBUG)
465 /* enable debug messages */
468 microtime(&sc->sc_ifp->if_lastchange);
471 case SIOCSIFMTU: /* set interface MTU */
472 if(ifr->ifr_mtu > I4BIPRMAXMTU)
474 else if(ifr->ifr_mtu < I4BIPRMINMTU)
478 ifp->if_mtu = ifr->ifr_mtu;
479 microtime(&sc->sc_ifp->if_lastchange);
483 /* not needed for FreeBSD, done in sl_compress_init() (-hm) */
485 /* need to add an ioctl: set VJ max slot ID
486 * #define IPRIOCSMAXCID _IOW('I', XXX, int)
491 struct thread *td = curthread; /* XXX */
493 if((error = priv_check(td, PRIV_DRIVER)))
495 sl_compress_setup(sc->sc_compr, *(int *)data);
509 /*---------------------------------------------------------------------------*
510 * clear the interface's send queues
511 *---------------------------------------------------------------------------*/
513 iprclearqueues(struct ipr_softc *sc)
518 IF_DRAIN(&sc->sc_fastq);
519 IF_DRAIN(&sc->sc_ifp->if_snd);
524 /*---------------------------------------------------------------------------*
526 *---------------------------------------------------------------------------*/
528 iprwatchdog(struct ifnet *ifp)
530 int unit = ifp->if_dunit;
531 struct ipr_softc *sc = ifp->if_softc;
532 bchan_statistics_t bs;
534 /* get # of bytes in and out from the HSCX driver */
536 (*isdn_linktab[unit]->bch_stat)
537 (isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
539 sc->sc_ioutb += bs.outbytes;
540 sc->sc_iinb += bs.inbytes;
542 if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
544 int ri = (sc->sc_iinb - sc->sc_linb)/I4BIPRACCTINTVL;
545 int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BIPRACCTINTVL;
547 if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
552 sc->sc_linb = sc->sc_iinb;
553 sc->sc_loutb = sc->sc_ioutb;
555 i4b_l4_accounting(BDRV_IPR, unit, ACCT_DURING,
556 sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_outb, sc->sc_inb);
558 sc->sc_ifp->if_timer = I4BIPRACCTINTVL;
560 #endif /* I4BIPRACCT */
562 /*===========================================================================*
563 * ISDN INTERFACE ROUTINES
564 *===========================================================================*/
566 /*---------------------------------------------------------------------------*
567 * start transmitting after connect
568 *---------------------------------------------------------------------------*/
570 i4bipr_connect_startio(struct ipr_softc *sc)
574 if(sc->sc_state == ST_CONNECTED_W)
576 sc->sc_state = ST_CONNECTED_A;
577 ipr_tx_queue_empty(sc->sc_ifp->if_dunit);
583 /*---------------------------------------------------------------------------*
584 * this routine is called from L4 handler at connect time
585 *---------------------------------------------------------------------------*/
587 ipr_connect(int unit, void *cdp)
589 struct ipr_softc *sc = &ipr_softc[unit];
592 sc->sc_cdp = (call_desc_t *)cdp;
596 NDBGL4(L4_DIALST, "ipr%d: setting dial state to ST_CONNECTED", unit);
598 sc->sc_ifp->if_drv_flags |= IFF_DRV_RUNNING;
599 sc->sc_state = ST_CONNECTED_W;
601 sc->sc_dialresp = DSTAT_NONE;
602 sc->sc_lastdialresp = DSTAT_NONE;
611 sc->sc_ifp->if_timer = I4BIPRACCTINTVL;
615 sc->sc_first_pkt = 1;
619 * Sometimes ISDN B-channels are switched thru asymmetic. This
620 * means that under such circumstances B-channel data (the first
621 * three packets of a TCP connection in my case) may get lost,
622 * causing a large delay until the connection is started.
623 * When the sending of the very first packet of a TCP connection
624 * is delayed for a to be empirically determined delay (close
625 * to a second in my case) those packets go thru and the TCP
626 * connection comes up "almost" immediately (-hm).
629 if(sc->sc_cdp->isdntxdelay > 0)
634 delay = sc->sc_cdp->isdntxdelay; /* avoid any rounding */
636 delay = sc->sc_cdp->isdntxdelay*hz;
640 START_TIMER(sc->sc_callout, (TIMEOUT_FUNC_T)i4bipr_connect_startio, (void *)sc, delay);
644 sc->sc_state = ST_CONNECTED_A;
645 ipr_tx_queue_empty(unit);
650 /* we don't need any negotiation - pass event back right now */
651 i4b_l4_negcomplete(sc->sc_cdp);
654 /*---------------------------------------------------------------------------*
655 * this routine is called from L4 handler at disconnect time
656 *---------------------------------------------------------------------------*/
658 ipr_disconnect(int unit, void *cdp)
660 call_desc_t *cd = (call_desc_t *)cdp;
661 struct ipr_softc *sc = &ipr_softc[unit];
663 /* new stuff to check that the active channel is being closed */
665 if (cd != sc->sc_cdp)
667 NDBGL4(L4_IPRDBG, "ipr%d: channel %d not active",
668 cd->driver_unit, cd->channelid);
673 sc->sc_ifp->if_timer = 0;
677 /* show next IPR_LOG packets again */
678 sc->sc_log_first = IPR_LOG;
681 i4b_l4_accounting(BDRV_IPR, cd->driver_unit, ACCT_FINAL,
682 sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_outb, sc->sc_inb);
684 sc->sc_cdp = (call_desc_t *)0;
686 NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
688 sc->sc_dialresp = DSTAT_NONE;
689 sc->sc_lastdialresp = DSTAT_NONE;
691 sc->sc_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
692 sc->sc_state = ST_IDLE;
695 /*---------------------------------------------------------------------------*
696 * this routine is used to give a feedback from userland daemon
697 * in case of dial problems
698 *---------------------------------------------------------------------------*/
700 ipr_dialresponse(int unit, int status, cause_t cause)
702 struct ipr_softc *sc = &ipr_softc[unit];
703 sc->sc_dialresp = status;
705 NDBGL4(L4_IPRDBG, "ipr%d: last=%d, this=%d",
706 unit, sc->sc_lastdialresp, sc->sc_dialresp);
708 if(status != DSTAT_NONE)
710 NDBGL4(L4_IPRDBG, "ipr%d: clearing queues", unit);
715 /*---------------------------------------------------------------------------*
716 * interface soft up/down
717 *---------------------------------------------------------------------------*/
719 ipr_updown(int unit, int updown)
721 struct ipr_softc *sc = &ipr_softc[unit];
722 sc->sc_updown = updown;
725 /*---------------------------------------------------------------------------*
726 * this routine is called from the HSCX interrupt handler
727 * when a new frame (mbuf) has been received and was put on
728 * the rx queue. It is assumed that this routines runs at
729 * pri level splimp() ! Keep it short !
730 *---------------------------------------------------------------------------*/
732 ipr_rx_data_rdy(int unit)
734 register struct ipr_softc *sc = &ipr_softc[unit];
735 register struct mbuf *m;
738 #ifdef IPR_VJ_USEBUFFER
739 u_char *cp = sc->sc_cbuf;
744 if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
747 m->m_pkthdr.rcvif = sc->sc_ifp;
749 m->m_pkthdr.len = m->m_len;
751 microtime(&sc->sc_ifp->if_lastchange);
756 * The very first packet after the B channel is switched thru
757 * has very often several bytes of random data prepended. This
758 * routine looks where the IP header starts and removes the
764 unsigned char *mp = m->m_data;
767 sc->sc_first_pkt = 0;
769 for(i = 0; i < m->m_len; i++, mp++)
771 if( ((*mp & 0xf0) == 0x40) &&
772 ((*mp & 0x0f) >= 0x05) )
775 m->m_pkthdr.len -= i;
782 sc->sc_ifp->if_ipackets++;
783 sc->sc_ifp->if_ibytes += m->m_pkthdr.len;
786 if((c = (*(mtod(m, u_char *)) & 0xf0)) != (IPVERSION << 4))
788 /* copy data to buffer */
792 #ifdef IPR_VJ_USEBUFFER
793 /* XXX */ m_copydata(m, 0, len, cp);
798 c = TYPE_COMPRESSED_TCP;
800 else if(c == TYPE_UNCOMPRESSED_TCP)
802 #ifdef IPR_VJ_USEBUFFER
803 *cp &= 0x4f; /* XXX */
805 *(mtod(m, u_char *)) &= 0x4f;
810 * We've got something that's not an IP packet.
811 * If compression is enabled, try to decompress it.
812 * Otherwise, if `auto-enable' compression is on and
813 * it's a reasonable packet, decompress it and then
814 * enable compression. Otherwise, drop it.
816 if(sc->sc_ifp->if_flags & IPR_COMPRESS)
818 #ifdef IPR_VJ_USEBUFFER
819 len = sl_uncompress_tcp(&cp,len,(u_int)c,&sc->sc_compr);
821 len = sl_uncompress_tcp((u_char **)&m->m_data, len,
822 (u_int)c, &sc->sc_compr);
828 printf("i4b_ipr, ipr_rx_data_rdy: len <= 0 IPR_COMPRESS!\n");
833 else if((sc->sc_ifp->if_flags & IPR_AUTOCOMP) &&
834 (c == TYPE_UNCOMPRESSED_TCP) && (len >= 40))
836 #ifdef IPR_VJ_USEBUFFER
837 len = sl_uncompress_tcp(&cp,len,(u_int)c,&sc->sc_compr);
839 len = sl_uncompress_tcp((u_char **)&m->m_data, len,
840 (u_int)c, &sc->sc_compr);
846 printf("i4b_ipr, ipr_rx_data_rdy: len <= 0 IPR_AUTOCOMP!\n");
851 sc->sc_ifp->if_flags |= IPR_COMPRESS;
856 printf("i4b_ipr, ipr_input: invalid ip packet!\n");
860 sc->sc_ifp->if_ierrors++;
861 sc->sc_ifp->if_collisions++;
865 #ifdef IPR_VJ_USEBUFFER
866 /* XXX */ m_copyback(m, 0, len, cp);
868 m->m_len = m->m_pkthdr.len = len;
874 /* NB. do the accounting after decompression! */
875 sc->sc_inb += m->m_pkthdr.len;
879 if(sc->sc_log_first > 0)
881 --(sc->sc_log_first);
882 i4b_l4_packet_ind(BDRV_IPR, unit, 0, m );
886 if(bpf_peers_present(sc->sc_ifp->if_bpf))
888 /* prepend the address family as a four byte field */
893 mm.m_data = (char *)⁡
894 bpf_mtap(sc->sc_ifp->if_bpf, &mm);
897 if(netisr_queue(NETISR_IP, m)) /* (0) on success. */
899 NDBGL4(L4_IPRDBG, "ipr%d: ipintrq full!", unit);
900 sc->sc_ifp->if_ierrors++;
901 sc->sc_ifp->if_iqdrops++;
905 /*---------------------------------------------------------------------------*
906 * this routine is called from the HSCX interrupt handler
907 * when the last frame has been sent out and there is no
908 * further frame (mbuf) in the tx queue.
909 *---------------------------------------------------------------------------*/
911 ipr_tx_queue_empty(int unit)
913 register struct ipr_softc *sc = &ipr_softc[unit];
914 register struct mbuf *m;
920 if(sc->sc_state != ST_CONNECTED_A)
925 IF_DEQUEUE(&sc->sc_fastq, m);
928 sc->sc_ifp->if_omcasts++;
932 IF_DEQUEUE(&sc->sc_ifp->if_snd, m);
937 microtime(&sc->sc_ifp->if_lastchange);
939 if(bpf_peers_present(sc->sc_ifp->if_bpf))
941 /* prepend the address family as a four byte field */
947 mm.m_data = (char *)⁡
948 bpf_mtap(sc->sc_ifp->if_bpf, &mm);
952 sc->sc_outb += m->m_pkthdr.len; /* size before compression */
956 if((ip = mtod(m, struct ip *))->ip_p == IPPROTO_TCP)
958 if(sc->sc_ifp->if_flags & IPR_COMPRESS)
960 *mtod(m, u_char *) |= sl_compress_tcp(m, ip,
967 IF_LOCK(isdn_linktab[unit]->tx_queue);
968 if(_IF_QFULL(isdn_linktab[unit]->tx_queue))
970 NDBGL4(L4_IPRDBG, "ipr%d: tx queue full!", unit);
975 sc->sc_ifp->if_obytes += m->m_pkthdr.len;
977 sc->sc_ifp->if_opackets++;
979 _IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
982 IF_UNLOCK(isdn_linktab[unit]->tx_queue);
986 (*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
989 /*---------------------------------------------------------------------------*
990 * this routine is called from the HSCX interrupt handler
991 * each time a packet is received or transmitted. It should
992 * be used to implement an activity timeout mechanism.
993 *---------------------------------------------------------------------------*/
995 ipr_activity(int unit, int rxtx)
997 ipr_softc[unit].sc_cdp->last_active_time = SECOND;
1000 /*---------------------------------------------------------------------------*
1001 * return this drivers linktab address
1002 *---------------------------------------------------------------------------*/
1004 ipr_ret_linktab(int unit)
1006 return(&ipr_drvr_linktab[unit]);
1009 /*---------------------------------------------------------------------------*
1010 * setup the isdn_linktab for this driver
1011 *---------------------------------------------------------------------------*/
1013 ipr_set_linktab(int unit, isdn_link_t *ilt)
1015 isdn_linktab[unit] = ilt;
1018 /*---------------------------------------------------------------------------*
1019 * initialize this drivers linktab
1020 *---------------------------------------------------------------------------*/
1022 ipr_init_linktab(int unit)
1024 ipr_drvr_linktab[unit].unit = unit;
1025 ipr_drvr_linktab[unit].bch_rx_data_ready = ipr_rx_data_rdy;
1026 ipr_drvr_linktab[unit].bch_tx_queue_empty = ipr_tx_queue_empty;
1027 ipr_drvr_linktab[unit].bch_activity = ipr_activity;
1028 ipr_drvr_linktab[unit].line_connected = ipr_connect;
1029 ipr_drvr_linktab[unit].line_disconnected = ipr_disconnect;
1030 ipr_drvr_linktab[unit].dial_response = ipr_dialresponse;
1031 ipr_drvr_linktab[unit].updown_ind = ipr_updown;
1034 /*===========================================================================*/