+
+/*
+ * tp_rsyflush - drop all the packets on the reassembly queue.
+ * Do this when closing the socket, or when somebody has changed
+ * the space avaible in the receive socket (XXX).
+ */
+tp_rsyflush(tpcb)
+register struct tp_pcb *tpcb;
+{
+ register struct mbuf *m, **mp;
+ if (tpcb->tp_rsycnt) {
+ for (mp == tpcb->tp_rsyq + tpcb->tp_maxlcredit;
+ --mp >= tpcb->tp_rsyq; )
+ if (*mp) {
+ tpcb->tp_rsycnt--;
+ m_freem(*mp);
+ }
+ if (tpcb->tp_rsycnt)
+ panic("tp_rsyflush");
+ }
+ free((caddr_t)tpcb->tp_rsyq, M_PCB);
+ tpcb->tp_rsyq = 0;
+}
+
+tp_rsyset(tpcb)
+register struct tp_pcb *tpcb;
+{
+ register struct socket *so = tpcb->tp_sock;
+ int maxcredit = tpcb->tp_xtd_format ? 0xffff : 0xf;
+ caddr_t rsyq;
+
+ tpcb->tp_sbmax = so->so_rcv.sb_hiwat;
+ tpcb->tp_maxlcredit = maxcredit = min(maxcredit,
+ (so->so_rcv.sb_hiwat + tpcb->tp_l_tpdusize)/ tpcb->tp_l_tpdusize);
+
+ maxcredit *= sizeof(struct mbuf *);
+ if (tpcb->tp_rsyq)
+ tp_rsyflush(tpcb);
+ if (rsyq = (caddr_t)malloc(maxcredit, M_PCB, M_NOWAIT))
+ bzero(rsyq, maxcredit);
+ tpcb->tp_rsyq = (struct mbuf **)rsyq;
+}
+
+tpsbcheck(tpcb, i)
+struct tp_pcb *tpcb;
+{
+ register struct mbuf *n, *m;
+ register int len = 0, mbcnt = 0, pktlen;
+ struct sockbuf *sb = &tpcb->tp_sock->so_snd;
+
+ for (n = sb->sb_mb; n; n = n->m_nextpkt) {
+ if ((n->m_flags & M_PKTHDR) == 0)
+ panic("tpsbcheck nohdr");
+ pktlen = len + n->m_pkthdr.len;
+ for (m = n; m; m = m->m_next) {
+ len += m->m_len;
+ mbcnt += MSIZE;
+ if (m->m_flags & M_EXT)
+ mbcnt += m->m_ext.ext_size;
+ }
+ if (len != pktlen) {
+ printf("test %d; len %d != pktlen %d on mbuf 0x%x\n",
+ i, len, pktlen, n);
+ panic("tpsbcheck short");
+ }
+ }
+ if (len != sb->sb_cc || mbcnt != sb->sb_mbcnt) {
+ printf("test %d: cc %d != %d || mbcnt %d != %d\n", i, len, sb->sb_cc,
+ mbcnt, sb->sb_mbcnt);
+ panic("tpsbcheck");
+ }
+}