add ssize_t, required by POSIX 1003.1
[unix-history] / usr / src / sys / netccitt / hd_input.c
index 1a295b3..ed76f17 100644 (file)
@@ -1,20 +1,32 @@
-/* Copyright (c) University of British Columbia, 1984 */
-
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/mbuf.h"
-#include "../h/domain.h"
-#include "../h/socket.h"
-#include "../h/protosw.h"
-#include "../h/errno.h"
-#include "../h/time.h"
-#include "../h/kernel.h"
+/*
+ * Copyright (c) University of British Columbia, 1984
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Laboratory for Computation Vision and the Computer Science Department
+ * of the University of British Columbia.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)hd_input.c  7.7 (Berkeley) %G%
+ */
+
+#include "param.h"
+#include "systm.h"
+#include "mbuf.h"
+#include "domain.h"
+#include "socket.h"
+#include "protosw.h"
+#include "errno.h"
+#include "time.h"
+#include "kernel.h"
 
 #include "../net/if.h"
 
 
 #include "../net/if.h"
 
-#include "../netccitt/hdlc.h"
-#include "../netccitt/hd_var.h"
-#include "../netccitt/x25.h"
+#include "hdlc.h"
+#include "hd_var.h"
+#include "x25.h"
 
 /*
  *      HDLC INPUT INTERFACE
 
 /*
  *      HDLC INPUT INTERFACE
@@ -29,12 +41,13 @@ hdintr ()
        register struct hdcb *hdp;
        register struct ifnet *ifp;
        register int s;
        register struct hdcb *hdp;
        register struct ifnet *ifp;
        register int s;
+       extern struct ifqueue pkintrq;
        static struct ifnet *lastifp;
        static struct hdcb *lasthdp;
 
        for (;;) {
                s = splimp ();
        static struct ifnet *lastifp;
        static struct hdcb *lasthdp;
 
        for (;;) {
                s = splimp ();
-               IF_DEQUEUEIF(&hdintrq, m, ifp);
+               IF_DEQUEUE (&hdintrq, m);
                splx (s);
                if (m == 0)
                        break;
                splx (s);
                if (m == 0)
                        break;
@@ -44,6 +57,9 @@ hdintr ()
                        m_freem (m);
                        continue;
                }
                        m_freem (m);
                        continue;
                }
+               if ((m->m_flags & M_PKTHDR) == 0)
+                       panic("hdintr");
+               ifp = m->m_pkthdr.rcvif;
 
                /*
                 * look up the appropriate hdlc control block
 
                /*
                 * look up the appropriate hdlc control block
@@ -69,6 +85,8 @@ hdintr ()
                if (process_rxframe (hdp, m) == FALSE)
                        m_freem (m);
        }
                if (process_rxframe (hdp, m) == FALSE)
                        m_freem (m);
        }
+       if (pkintrq.ifq_len)
+               pkintr ();
 }
 
 process_rxframe (hdp, fbuf)
 }
 
 process_rxframe (hdp, fbuf)
@@ -118,7 +136,7 @@ register struct mbuf *fbuf;
                hdp->hd_state = ABM;
                hd_message (hdp, "Link level operational");
                /* Notify the packet level - to send RESTART. */
                hdp->hd_state = ABM;
                hd_message (hdp, "Link level operational");
                /* Notify the packet level - to send RESTART. */
-               (void) pk_ctlinput (PRC_LINKUP, hdp->hd_xcp);
+               (void) pk_ctlinput (PRC_LINKUP, hdp->hd_pkp);
                break;
 
        case SABM + SABM_SENT: 
                break;
 
        case SABM + SABM_SENT: 
@@ -137,7 +155,7 @@ register struct mbuf *fbuf;
                hd_flush (hdp->hd_ifp);
                hd_writeinternal (hdp, UA, pf);
                hd_initvars (hdp);
                hd_flush (hdp->hd_ifp);
                hd_writeinternal (hdp, UA, pf);
                hd_initvars (hdp);
-               (void) pk_ctlinput (PRC_LINKRESET, hdp->hd_xcp);
+               (void) pk_ctlinput (PRC_LINKRESET, hdp->hd_pkp);
                hdp->hd_resets++;
                break;
 
                hdp->hd_resets++;
                break;
 
@@ -150,7 +168,7 @@ register struct mbuf *fbuf;
 #ifdef HDLCDEBUG
                hd_dumptrace (hdp);
 #endif
 #ifdef HDLCDEBUG
                hd_dumptrace (hdp);
 #endif
-               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_xcp);
+               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp);
                hd_flush (hdp->hd_ifp);
        case DM + DM_SENT: 
        case DM + WAIT_SABM: 
                hd_flush (hdp->hd_ifp);
        case DM + DM_SENT: 
        case DM + WAIT_SABM: 
@@ -178,7 +196,7 @@ register struct mbuf *fbuf;
 
        case DISC + ABM: 
                hd_message (hdp, "DISC received: link down");
 
        case DISC + ABM: 
                hd_message (hdp, "DISC received: link down");
-               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_xcp);
+               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp);
        case DISC + WAIT_SABM: 
                hd_writeinternal (hdp, UA, pf);
                hdp->hd_state = DM_SENT;
        case DISC + WAIT_SABM: 
                hd_writeinternal (hdp, UA, pf);
                hdp->hd_state = DM_SENT;
@@ -187,7 +205,7 @@ register struct mbuf *fbuf;
 
        case UA + ABM: 
                hd_message (hdp, "UA received: link down");
 
        case UA + ABM: 
                hd_message (hdp, "UA received: link down");
-               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_xcp);
+               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp);
        case UA + WAIT_SABM: 
                hd_writeinternal (hdp, DM, pf);
                hdp->hd_state = DM_SENT;
        case UA + WAIT_SABM: 
                hd_writeinternal (hdp, DM, pf);
                hdp->hd_state = DM_SENT;
@@ -208,7 +226,7 @@ register struct mbuf *fbuf;
 
        case FRMR + ABM: 
                hd_message (hdp, "FRMR received: link down");
 
        case FRMR + ABM: 
                hd_message (hdp, "FRMR received: link down");
-               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_xcp);
+               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp);
 #ifdef HDLCDEBUG
                hd_dumptrace (hdp);
 #endif
 #ifdef HDLCDEBUG
                hd_dumptrace (hdp);
 #endif
@@ -254,7 +272,7 @@ register struct mbuf *fbuf;
 
        case ILLEGAL + ABM: 
                hd_message (hdp, "Unknown frame received: link down");
 
        case ILLEGAL + ABM: 
                hd_message (hdp, "Unknown frame received: link down");
-               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_xcp);
+               (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp);
        case ILLEGAL + WAIT_SABM:
                hdp->hd_unknown++;
 #ifdef HDLCDEBUG
        case ILLEGAL + WAIT_SABM:
                hdp->hd_unknown++;
 #ifdef HDLCDEBUG
@@ -323,8 +341,8 @@ register struct Hdlc_iframe *frame;
         *  it is queued for the packet level.
         */
 
         *  it is queued for the packet level.
         */
 
-       if (ns != (hdp->hd_lasttxnr + hdp->hd_xcp->xc_lwsize) % MODULUS) {
-               hdp->hd_vr = (hdp->hd_vr + 1) % MODULUS;
+       if (ns != (hdp -> hd_lasttxnr + hdp -> hd_xcp -> xc_lwsize) % MODULUS) {
+               hdp -> hd_vr = (hdp -> hd_vr + 1) % MODULUS;
                if (pf == 1) {
                        /* Must generate a RR or RNR with final bit on. */
                        hd_writeinternal (hdp, RR, POLLON);
                if (pf == 1) {
                        /* Must generate a RR or RNR with final bit on. */
                        hd_writeinternal (hdp, RR, POLLON);
@@ -337,8 +355,10 @@ register struct Hdlc_iframe *frame;
                                hdp->hd_rrtimer = hd_t3;
 
                /* Forward iframe to packet level of X.25. */
                                hdp->hd_rrtimer = hd_t3;
 
                /* Forward iframe to packet level of X.25. */
-               fbuf -> m_off += HDHEADERLN;
+               fbuf -> m_data += HDHEADERLN;
                fbuf -> m_len -= HDHEADERLN;
                fbuf -> m_len -= HDHEADERLN;
+               fbuf -> m_pkthdr.len -= HDHEADERLN;
+               fbuf -> m_pkthdr.rcvif = (struct ifnet *)hdp -> hd_pkp;
 #ifdef BSD4_3
                fbuf->m_act = 0;        /* probably not necessary */
 #else
 #ifdef BSD4_3
                fbuf->m_act = 0;        /* probably not necessary */
 #else
@@ -350,7 +370,7 @@ register struct Hdlc_iframe *frame;
                        m -> m_act = (struct mbuf *) 1;
                }
 #endif
                        m -> m_act = (struct mbuf *) 1;
                }
 #endif
-               pk_input (fbuf, hdp->hd_xcp);
+               pk_input (fbuf);
                queued = TRUE;
                hd_start (hdp);
        } else {
                queued = TRUE;
                hd_start (hdp);
        } else {
@@ -469,6 +489,10 @@ int frametype;
                        hdp->hd_retxcnt = 0;
                        hdp->hd_condition &= ~TIMER_RECOVERY_CONDITION;
 
                        hdp->hd_retxcnt = 0;
                        hdp->hd_condition &= ~TIMER_RECOVERY_CONDITION;
 
+                       if (frametype == RR && hdp->hd_lastrxnr == hdp->hd_vs
+                               && hdp->hd_timer == 0 && hdp->hd_txq.head == 0)
+                               hd_writeinternal(hdp, RR, pf);
+                       else
                        /* If any iframes have been queued because of the
                           timer condition, transmit then now. */
                        if (hdp->hd_condition & REMOTE_RNR_CONDITION) {
                        /* If any iframes have been queued because of the
                           timer condition, transmit then now. */
                        if (hdp->hd_condition & REMOTE_RNR_CONDITION) {