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
25 *---------------------------------------------------------------------------
27 * i4b_ipr.c - isdn4bsd IP over raw HDLC ISDN network driver
28 * ---------------------------------------------------------
29 * last edit-date: [Sun Mar 17 09:32:58 2002]
31 *---------------------------------------------------------------------------*
33 * statistics counter usage (interface lifetime):
34 * ----------------------------------------------
35 * sc->sc_if.if_ipackets # of received packets
36 * sc->sc_if.if_ierrors # of error packets not going to upper layers
37 * sc->sc_if.if_opackets # of transmitted packets
38 * sc->sc_if.if_oerrors # of error packets not being transmitted
39 * sc->sc_if.if_collisions # of invalid ip packets after VJ decompression
40 * sc->sc_if.if_ibytes # of bytes coming in from the line (before VJ)
41 * sc->sc_if.if_obytes # of bytes going out to the line (after VJ)
42 * sc->sc_if.if_imcasts (currently unused)
43 * sc->sc_if.if_omcasts # of frames sent out of the fastqueue
44 * sc->sc_if.if_iqdrops # of frames dropped on input because queue full
45 * sc->sc_if.if_noproto # of frames dropped on output because !AF_INET
47 * statistics counter usage (connection lifetime):
48 * -----------------------------------------------
49 * sc->sc_iinb # of ISDN incoming bytes from HSCX
50 * sc->sc_ioutb # of ISDN outgoing bytes from HSCX
51 * sc->sc_inb # of incoming bytes after decompression
52 * sc->sc_outb # of outgoing bytes before compression
54 *---------------------------------------------------------------------------*/
56 #include <sys/cdefs.h>
57 __FBSDID("$FreeBSD$");
63 #include <sys/param.h>
64 #include <sys/systm.h>
66 #include <sys/socket.h>
67 #include <sys/errno.h>
68 #include <sys/ioccom.h>
69 #include <sys/sockio.h>
70 #include <sys/kernel.h>
72 #include <net/if_types.h>
73 #include <net/netisr.h>
74 #include <netinet/in.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/in_var.h>
77 #include <netinet/ip.h>
80 #include <sys/malloc.h>
81 #include <net/slcompress.h>
82 #define IPR_COMPRESS IFF_LINK0 /* compress TCP traffic */
83 #define IPR_AUTOCOMP IFF_LINK1 /* auto-enable TCP compression */
85 /*---------------------------------------------------------------------------
86 * NOTICE: using NO separate buffer relies on the assumption, that the HSCX
87 * IRQ handler _always_ allocates a single, continuous mbuf cluster large
88 * enough to hold the maximum MTU size if the ipr interface !
90 * CAUTION: i have re-defined IPR_VJ_USEBUFFER because it makes problems
91 * with 2 i4b's back to back running cvs over ssh, cvs simply
92 * aborts because it gets bad data. Everything else (telnet/ftp?etc)
94 *---------------------------------------------------------------------------*/
95 #define IPR_VJ_USEBUFFER /* define to use an allocated separate buffer*/
96 /* undef to uncompress in the mbuf itself */
102 #include <machine/i4b_ioctl.h>
103 #include <machine/i4b_debug.h>
105 #include <i4b/include/i4b_global.h>
106 #include <i4b/include/i4b_l3l4.h>
108 #include <i4b/layer4/i4b_l4.h>
110 #define I4BIPRMTU 1500 /* regular MTU */
111 #define I4BIPRMAXMTU 2000 /* max MTU */
112 #define I4BIPRMINMTU 500 /* min MTU */
114 #define I4BIPRMAXQLEN 50 /* max queue length */
116 #define I4BIPRACCT 1 /* enable accounting messages */
117 #define I4BIPRACCTINTVL 2 /* accounting msg interval in secs */
118 #define I4BIPRADJFRXP 1 /* adjust 1st rxd packet */
120 /* initialized by L4 */
122 static drvr_link_t ipr_drvr_linktab[NI4BIPR];
123 static isdn_link_t *isdn_linktab[NI4BIPR];
126 struct ifnet sc_if; /* network-visible interface */
127 int sc_state; /* state of the interface */
128 call_desc_t *sc_cdp; /* ptr to call descriptor */
129 int sc_updown; /* soft state of interface */
130 struct ifqueue sc_fastq; /* interactive traffic */
131 int sc_dialresp; /* dialresponse */
132 int sc_lastdialresp;/* last dialresponse */
133 struct callout_handle sc_callout;
136 int sc_iinb; /* isdn driver # of inbytes */
137 int sc_ioutb; /* isdn driver # of outbytes */
138 int sc_inb; /* # of bytes rx'd */
139 int sc_outb; /* # of bytes tx'd */
140 int sc_linb; /* last # of bytes rx'd */
141 int sc_loutb; /* last # of bytes tx'd */
142 int sc_fn; /* flag, first null acct */
146 int sc_first_pkt; /* flag, first rxd packet */
150 int sc_log_first; /* log first n packets */
154 struct slcompress sc_compr; /* tcp compression data */
155 #ifdef IPR_VJ_USEBUFFER
156 u_char *sc_cbuf; /* tcp decompression buffer */
160 } ipr_softc[NI4BIPR];
163 ST_IDLE, /* initialized, ready, idle */
164 ST_DIALING, /* dialling out to remote */
165 ST_CONNECTED_W, /* connected to remote */
166 ST_CONNECTED_A, /* connected to remote */
169 static void i4biprattach(void *);
170 PSEUDO_SET(i4biprattach, i4b_ipr);
171 static int i4biprioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
173 static void iprwatchdog(struct ifnet *ifp);
174 static void ipr_init_linktab(int unit);
175 static void ipr_tx_queue_empty(int unit);
176 static int i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rtp);
177 static void iprclearqueues(struct ipr_softc *sc);
179 /*===========================================================================*
180 * DEVICE DRIVER ROUTINES
181 *===========================================================================*/
183 /*---------------------------------------------------------------------------*
184 * interface attach routine at kernel boot time
185 *---------------------------------------------------------------------------*/
187 i4biprattach(void *dummy)
189 struct ipr_softc *sc = ipr_softc;
193 printf("i4bipr: %d IP over raw HDLC ISDN device(s) attached (VJ header compression)\n", NI4BIPR);
195 printf("i4bipr: %d IP over raw HDLC ISDN device(s) attached\n", NI4BIPR);
198 for(i=0; i < NI4BIPR; sc++, i++)
202 NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
204 sc->sc_if.if_softc = sc;
205 sc->sc_state = ST_IDLE;
206 if_initname(&sc->sc_if, "ipr", i);
210 sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_SIMPLEX | IPR_AUTOCOMP;
212 sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_SIMPLEX;
215 sc->sc_if.if_mtu = I4BIPRMTU;
216 sc->sc_if.if_type = IFT_ISDNBASIC;
217 sc->sc_if.if_ioctl = i4biprioctl;
218 sc->sc_if.if_output = i4biproutput;
220 sc->sc_if.if_snd.ifq_maxlen = I4BIPRMAXQLEN;
221 sc->sc_fastq.ifq_maxlen = I4BIPRMAXQLEN;
223 if(!mtx_initialized(&sc->sc_fastq.ifq_mtx))
224 mtx_init(&sc->sc_fastq.ifq_mtx, "i4b_ipr_fastq", NULL, MTX_DEF);
226 sc->sc_if.if_ipackets = 0;
227 sc->sc_if.if_ierrors = 0;
228 sc->sc_if.if_opackets = 0;
229 sc->sc_if.if_oerrors = 0;
230 sc->sc_if.if_collisions = 0;
231 sc->sc_if.if_ibytes = 0;
232 sc->sc_if.if_obytes = 0;
233 sc->sc_if.if_imcasts = 0;
234 sc->sc_if.if_omcasts = 0;
235 sc->sc_if.if_iqdrops = 0;
236 sc->sc_if.if_noproto = 0;
239 sc->sc_if.if_timer = 0;
240 sc->sc_if.if_watchdog = iprwatchdog;
251 sc->sc_log_first = IPR_LOG;
255 sl_compress_init(&sc->sc_compr, -1);
257 #ifdef IPR_VJ_USEBUFFER
259 (u_char *)malloc(I4BIPRMAXMTU+128, M_DEVBUF, M_WAITOK))))
261 panic("if_ipr.c, ipr_attach: VJ malloc failed");
265 sc->sc_updown = SOFT_ENA; /* soft enabled */
266 sc->sc_dialresp = DSTAT_NONE; /* no response */
267 sc->sc_lastdialresp = DSTAT_NONE;
269 if_attach(&sc->sc_if);
271 bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int));
275 /*---------------------------------------------------------------------------*
276 * output a packet to the ISDN B-channel
277 *---------------------------------------------------------------------------*/
279 i4biproutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
282 struct ipr_softc *sc;
291 unit = ifp->if_dunit;
295 if(dst->sa_family != AF_INET)
297 if_printf(ifp, "af%d not supported\n", dst->sa_family);
300 sc->sc_if.if_noproto++;
301 sc->sc_if.if_oerrors++;
302 return(EAFNOSUPPORT);
305 /* check interface state = UP */
307 if(!(ifp->if_flags & IFF_UP))
309 NDBGL4(L4_IPRDBG, "ipr%d: interface is DOWN!", unit);
312 sc->sc_if.if_oerrors++;
316 /* dial if necessary */
318 if(sc->sc_state == ST_IDLE || sc->sc_state == ST_DIALING)
322 switch(sc->sc_dialresp)
324 case DSTAT_TFAIL: /* transient failure */
325 NDBGL4(L4_IPRDBG, "ipr%d: transient dial failure!", unit);
328 sc->sc_dialresp = DSTAT_NONE;
330 sc->sc_if.if_oerrors++;
334 case DSTAT_PFAIL: /* permanent failure */
335 NDBGL4(L4_IPRDBG, "ipr%d: permanent dial failure!", unit);
338 sc->sc_dialresp = DSTAT_NONE;
340 sc->sc_if.if_oerrors++;
341 return(EHOSTUNREACH);
344 case DSTAT_INONLY: /* no dialout allowed*/
345 NDBGL4(L4_IPRDBG, "ipr%d: dialout not allowed failure!", unit);
348 sc->sc_dialresp = DSTAT_NONE;
350 sc->sc_if.if_oerrors++;
351 return(EHOSTUNREACH);
356 NDBGL4(L4_IPRDBG, "ipr%d: send dial request message!", unit);
357 NDBGL4(L4_DIALST, "ipr%d: setting dial state to ST_DIALING", unit);
358 i4b_l4_dialout(BDRV_IPR, unit);
359 sc->sc_state = ST_DIALING;
363 if(sc->sc_log_first > 0)
365 --(sc->sc_log_first);
366 i4b_l4_packet_ind(BDRV_IPR, unit, 1, m );
370 /* update access time */
372 microtime(&sc->sc_if.if_lastchange);
375 * check, if type of service indicates interactive, i.e. telnet,
376 * traffic. in case it is interactive, put it into the fast queue,
377 * else (i.e. ftp traffic) put it into the "normal" queue
380 ip = mtod(m, struct ip *); /* get ptr to ip header */
382 if(ip->ip_tos & IPTOS_LOWDELAY)
385 ifq = (struct ifqueue *)&sc->sc_if.if_snd;
387 /* check for space in choosen send queue */
389 if(! IF_HANDOFF(ifq, m, NULL))
391 NDBGL4(L4_IPRDBG, "ipr%d: send queue full!", unit);
393 sc->sc_if.if_oerrors++;
397 NDBGL4(L4_IPRDBG, "ipr%d: add packet to send queue!", unit);
399 ipr_tx_queue_empty(unit);
406 /*---------------------------------------------------------------------------*
408 *---------------------------------------------------------------------------*/
410 i4biprioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
412 struct ipr_softc *sc = ifp->if_softc;
413 struct ifreq *ifr = (struct ifreq *)data;
414 struct ifaddr *ifa = (struct ifaddr *)data;
422 case SIOCAIFADDR: /* add interface address */
423 case SIOCSIFADDR: /* set interface address */
424 case SIOCSIFDSTADDR: /* set interface destination address */
425 if(ifa->ifa_addr->sa_family != AF_INET)
426 error = EAFNOSUPPORT;
428 sc->sc_if.if_flags |= IFF_UP;
429 microtime(&sc->sc_if.if_lastchange);
432 case SIOCSIFFLAGS: /* set interface flags */
433 if(!(ifr->ifr_flags & IFF_UP))
435 if(sc->sc_if.if_flags & IFF_RUNNING)
437 /* disconnect ISDN line */
438 i4b_l4_drvrdisc(BDRV_IPR,
440 sc->sc_if.if_flags &= ~IFF_RUNNING;
443 sc->sc_state = ST_IDLE;
450 if(ifr->ifr_flags & IFF_DEBUG)
452 /* enable debug messages */
455 microtime(&sc->sc_if.if_lastchange);
458 case SIOCSIFMTU: /* set interface MTU */
459 if(ifr->ifr_mtu > I4BIPRMAXMTU)
461 else if(ifr->ifr_mtu < I4BIPRMINMTU)
465 ifp->if_mtu = ifr->ifr_mtu;
466 microtime(&sc->sc_if.if_lastchange);
470 /* not needed for FreeBSD, done in sl_compress_init() (-hm) */
472 /* need to add an ioctl: set VJ max slot ID
473 * #define IPRIOCSMAXCID _IOW('I', XXX, int)
478 struct thread *td = curthread; /* XXX */
480 if((error = suser(td)))
482 sl_compress_setup(sc->sc_compr, *(int *)data);
496 /*---------------------------------------------------------------------------*
497 * clear the interface's send queues
498 *---------------------------------------------------------------------------*/
500 iprclearqueues(struct ipr_softc *sc)
505 IF_DRAIN(&sc->sc_fastq);
506 IF_DRAIN(&sc->sc_if.if_snd);
511 /*---------------------------------------------------------------------------*
513 *---------------------------------------------------------------------------*/
515 iprwatchdog(struct ifnet *ifp)
517 int unit = ifp->if_dunit;
518 struct ipr_softc *sc = ifp->if_softc;
519 bchan_statistics_t bs;
521 /* get # of bytes in and out from the HSCX driver */
523 (*isdn_linktab[unit]->bch_stat)
524 (isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
526 sc->sc_ioutb += bs.outbytes;
527 sc->sc_iinb += bs.inbytes;
529 if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
531 int ri = (sc->sc_iinb - sc->sc_linb)/I4BIPRACCTINTVL;
532 int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BIPRACCTINTVL;
534 if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
539 sc->sc_linb = sc->sc_iinb;
540 sc->sc_loutb = sc->sc_ioutb;
542 i4b_l4_accounting(BDRV_IPR, unit, ACCT_DURING,
543 sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_outb, sc->sc_inb);
545 sc->sc_if.if_timer = I4BIPRACCTINTVL;
547 #endif /* I4BIPRACCT */
549 /*===========================================================================*
550 * ISDN INTERFACE ROUTINES
551 *===========================================================================*/
553 /*---------------------------------------------------------------------------*
554 * start transmitting after connect
555 *---------------------------------------------------------------------------*/
557 i4bipr_connect_startio(struct ipr_softc *sc)
561 if(sc->sc_state == ST_CONNECTED_W)
563 sc->sc_state = ST_CONNECTED_A;
564 ipr_tx_queue_empty(sc->sc_if.if_dunit);
570 /*---------------------------------------------------------------------------*
571 * this routine is called from L4 handler at connect time
572 *---------------------------------------------------------------------------*/
574 ipr_connect(int unit, void *cdp)
576 struct ipr_softc *sc = &ipr_softc[unit];
579 sc->sc_cdp = (call_desc_t *)cdp;
583 NDBGL4(L4_DIALST, "ipr%d: setting dial state to ST_CONNECTED", unit);
585 sc->sc_if.if_flags |= IFF_RUNNING;
586 sc->sc_state = ST_CONNECTED_W;
588 sc->sc_dialresp = DSTAT_NONE;
589 sc->sc_lastdialresp = DSTAT_NONE;
598 sc->sc_if.if_timer = I4BIPRACCTINTVL;
602 sc->sc_first_pkt = 1;
606 * Sometimes ISDN B-channels are switched thru asymmetic. This
607 * means that under such circumstances B-channel data (the first
608 * three packets of a TCP connection in my case) may get lost,
609 * causing a large delay until the connection is started.
610 * When the sending of the very first packet of a TCP connection
611 * is delayed for a to be empirically determined delay (close
612 * to a second in my case) those packets go thru and the TCP
613 * connection comes up "almost" immediately (-hm).
616 if(sc->sc_cdp->isdntxdelay > 0)
621 delay = sc->sc_cdp->isdntxdelay; /* avoid any rounding */
623 delay = sc->sc_cdp->isdntxdelay*hz;
627 START_TIMER(sc->sc_callout, (TIMEOUT_FUNC_T)i4bipr_connect_startio, (void *)sc, delay);
631 sc->sc_state = ST_CONNECTED_A;
632 ipr_tx_queue_empty(unit);
637 /* we don't need any negotiation - pass event back right now */
638 i4b_l4_negcomplete(sc->sc_cdp);
641 /*---------------------------------------------------------------------------*
642 * this routine is called from L4 handler at disconnect time
643 *---------------------------------------------------------------------------*/
645 ipr_disconnect(int unit, void *cdp)
647 call_desc_t *cd = (call_desc_t *)cdp;
648 struct ipr_softc *sc = &ipr_softc[unit];
650 /* new stuff to check that the active channel is being closed */
652 if (cd != sc->sc_cdp)
654 NDBGL4(L4_IPRDBG, "ipr%d: channel %d not active",
655 cd->driver_unit, cd->channelid);
660 sc->sc_if.if_timer = 0;
664 /* show next IPR_LOG packets again */
665 sc->sc_log_first = IPR_LOG;
668 i4b_l4_accounting(BDRV_IPR, cd->driver_unit, ACCT_FINAL,
669 sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_outb, sc->sc_inb);
671 sc->sc_cdp = (call_desc_t *)0;
673 NDBGL4(L4_DIALST, "setting dial state to ST_IDLE");
675 sc->sc_dialresp = DSTAT_NONE;
676 sc->sc_lastdialresp = DSTAT_NONE;
678 sc->sc_if.if_flags &= ~IFF_RUNNING;
679 sc->sc_state = ST_IDLE;
682 /*---------------------------------------------------------------------------*
683 * this routine is used to give a feedback from userland daemon
684 * in case of dial problems
685 *---------------------------------------------------------------------------*/
687 ipr_dialresponse(int unit, int status, cause_t cause)
689 struct ipr_softc *sc = &ipr_softc[unit];
690 sc->sc_dialresp = status;
692 NDBGL4(L4_IPRDBG, "ipr%d: last=%d, this=%d",
693 unit, sc->sc_lastdialresp, sc->sc_dialresp);
695 if(status != DSTAT_NONE)
697 NDBGL4(L4_IPRDBG, "ipr%d: clearing queues", unit);
702 /*---------------------------------------------------------------------------*
703 * interface soft up/down
704 *---------------------------------------------------------------------------*/
706 ipr_updown(int unit, int updown)
708 struct ipr_softc *sc = &ipr_softc[unit];
709 sc->sc_updown = updown;
712 /*---------------------------------------------------------------------------*
713 * this routine is called from the HSCX interrupt handler
714 * when a new frame (mbuf) has been received and was put on
715 * the rx queue. It is assumed that this routines runs at
716 * pri level splimp() ! Keep it short !
717 *---------------------------------------------------------------------------*/
719 ipr_rx_data_rdy(int unit)
721 register struct ipr_softc *sc = &ipr_softc[unit];
722 register struct mbuf *m;
725 #ifdef IPR_VJ_USEBUFFER
726 u_char *cp = sc->sc_cbuf;
731 if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
734 m->m_pkthdr.rcvif = &sc->sc_if;
736 m->m_pkthdr.len = m->m_len;
738 microtime(&sc->sc_if.if_lastchange);
743 * The very first packet after the B channel is switched thru
744 * has very often several bytes of random data prepended. This
745 * routine looks where the IP header starts and removes the
751 unsigned char *mp = m->m_data;
754 sc->sc_first_pkt = 0;
756 for(i = 0; i < m->m_len; i++, mp++)
758 if( ((*mp & 0xf0) == 0x40) &&
759 ((*mp & 0x0f) >= 0x05) )
762 m->m_pkthdr.len -= i;
769 sc->sc_if.if_ipackets++;
770 sc->sc_if.if_ibytes += m->m_pkthdr.len;
773 if((c = (*(mtod(m, u_char *)) & 0xf0)) != (IPVERSION << 4))
775 /* copy data to buffer */
779 #ifdef IPR_VJ_USEBUFFER
780 /* XXX */ m_copydata(m, 0, len, cp);
785 c = TYPE_COMPRESSED_TCP;
787 else if(c == TYPE_UNCOMPRESSED_TCP)
789 #ifdef IPR_VJ_USEBUFFER
790 *cp &= 0x4f; /* XXX */
792 *(mtod(m, u_char *)) &= 0x4f;
797 * We've got something that's not an IP packet.
798 * If compression is enabled, try to decompress it.
799 * Otherwise, if `auto-enable' compression is on and
800 * it's a reasonable packet, decompress it and then
801 * enable compression. Otherwise, drop it.
803 if(sc->sc_if.if_flags & IPR_COMPRESS)
805 #ifdef IPR_VJ_USEBUFFER
806 len = sl_uncompress_tcp(&cp,len,(u_int)c,&sc->sc_compr);
808 len = sl_uncompress_tcp((u_char **)&m->m_data, len,
809 (u_int)c, &sc->sc_compr);
815 printf("i4b_ipr, ipr_rx_data_rdy: len <= 0 IPR_COMPRESS!\n");
820 else if((sc->sc_if.if_flags & IPR_AUTOCOMP) &&
821 (c == TYPE_UNCOMPRESSED_TCP) && (len >= 40))
823 #ifdef IPR_VJ_USEBUFFER
824 len = sl_uncompress_tcp(&cp,len,(u_int)c,&sc->sc_compr);
826 len = sl_uncompress_tcp((u_char **)&m->m_data, len,
827 (u_int)c, &sc->sc_compr);
833 printf("i4b_ipr, ipr_rx_data_rdy: len <= 0 IPR_AUTOCOMP!\n");
838 sc->sc_if.if_flags |= IPR_COMPRESS;
843 printf("i4b_ipr, ipr_input: invalid ip packet!\n");
847 sc->sc_if.if_ierrors++;
848 sc->sc_if.if_collisions++;
852 #ifdef IPR_VJ_USEBUFFER
853 /* XXX */ m_copyback(m, 0, len, cp);
855 m->m_len = m->m_pkthdr.len = len;
861 /* NB. do the accounting after decompression! */
862 sc->sc_inb += m->m_pkthdr.len;
866 if(sc->sc_log_first > 0)
868 --(sc->sc_log_first);
869 i4b_l4_packet_ind(BDRV_IPR, unit, 0, m );
875 /* prepend the address family as a four byte field */
880 mm.m_data = (char *)⁡
881 BPF_MTAP(&sc->sc_if, &mm);
884 if(netisr_queue(NETISR_IP, m)) /* (0) on success. */
886 NDBGL4(L4_IPRDBG, "ipr%d: ipintrq full!", unit);
887 sc->sc_if.if_ierrors++;
888 sc->sc_if.if_iqdrops++;
892 /*---------------------------------------------------------------------------*
893 * this routine is called from the HSCX interrupt handler
894 * when the last frame has been sent out and there is no
895 * further frame (mbuf) in the tx queue.
896 *---------------------------------------------------------------------------*/
898 ipr_tx_queue_empty(int unit)
900 register struct ipr_softc *sc = &ipr_softc[unit];
901 register struct mbuf *m;
907 if(sc->sc_state != ST_CONNECTED_A)
912 IF_DEQUEUE(&sc->sc_fastq, m);
915 sc->sc_if.if_omcasts++;
919 IF_DEQUEUE(&sc->sc_if.if_snd, m);
924 microtime(&sc->sc_if.if_lastchange);
928 /* prepend the address family as a four byte field */
934 mm.m_data = (char *)⁡
935 BPF_MTAP(&sc->sc_if, &mm);
939 sc->sc_outb += m->m_pkthdr.len; /* size before compression */
943 if((ip = mtod(m, struct ip *))->ip_p == IPPROTO_TCP)
945 if(sc->sc_if.if_flags & IPR_COMPRESS)
947 *mtod(m, u_char *) |= sl_compress_tcp(m, ip,
954 IF_LOCK(isdn_linktab[unit]->tx_queue);
955 if(_IF_QFULL(isdn_linktab[unit]->tx_queue))
957 NDBGL4(L4_IPRDBG, "ipr%d: tx queue full!", unit);
962 sc->sc_if.if_obytes += m->m_pkthdr.len;
964 sc->sc_if.if_opackets++;
966 _IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
969 IF_UNLOCK(isdn_linktab[unit]->tx_queue);
973 (*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
976 /*---------------------------------------------------------------------------*
977 * this routine is called from the HSCX interrupt handler
978 * each time a packet is received or transmitted. It should
979 * be used to implement an activity timeout mechanism.
980 *---------------------------------------------------------------------------*/
982 ipr_activity(int unit, int rxtx)
984 ipr_softc[unit].sc_cdp->last_active_time = SECOND;
987 /*---------------------------------------------------------------------------*
988 * return this drivers linktab address
989 *---------------------------------------------------------------------------*/
991 ipr_ret_linktab(int unit)
993 return(&ipr_drvr_linktab[unit]);
996 /*---------------------------------------------------------------------------*
997 * setup the isdn_linktab for this driver
998 *---------------------------------------------------------------------------*/
1000 ipr_set_linktab(int unit, isdn_link_t *ilt)
1002 isdn_linktab[unit] = ilt;
1005 /*---------------------------------------------------------------------------*
1006 * initialize this drivers linktab
1007 *---------------------------------------------------------------------------*/
1009 ipr_init_linktab(int unit)
1011 ipr_drvr_linktab[unit].unit = unit;
1012 ipr_drvr_linktab[unit].bch_rx_data_ready = ipr_rx_data_rdy;
1013 ipr_drvr_linktab[unit].bch_tx_queue_empty = ipr_tx_queue_empty;
1014 ipr_drvr_linktab[unit].bch_activity = ipr_activity;
1015 ipr_drvr_linktab[unit].line_connected = ipr_connect;
1016 ipr_drvr_linktab[unit].line_disconnected = ipr_disconnect;
1017 ipr_drvr_linktab[unit].dial_response = ipr_dialresponse;
1018 ipr_drvr_linktab[unit].updown_ind = ipr_updown;
1021 /*===========================================================================*/