# #include "util.h" #include "pkts.h" #include "buf.h" struct que frq; /* Free buffers */ struct que rseqq; /* Buffers w. sequenced tcp rcv data */ struct que rwaitq; /* Buffers w. unsequenced tcp rcv data */ static struct que *queloc[] = { &frq, &rseqq, &rwaitq }; #define NQUE 3 que_init() { register struct que *pque; register int i; register struct rcvpkt *rp; register struct rcvpkt *rpe; for (i = 0; i < NQUE; i++) { pque = queloc[i]; pque->q_head.q_fwd = pque; pque->q_head.q_bwd = pque; pque->q_items = 0; } for (rp = &buff[0], rpe = &buff[NBUF]; rp < rpe; rp++) enque(&frq, rp); return(TRUE); } /* * enque put pitem on end of pque */ enque(pque, pitem) register struct que *pque; register struct item *pitem; { pitem->q_bwd = pque->q_head.q_bwd; pitem->q_fwd = pque; pque->q_head.q_bwd->q_fwd = pitem; pque->q_head.q_bwd = pitem; pque->q_items++; } /* * deque remove pitem form pque */ deque(pque, pitem) struct que *pque; register struct item *pitem; { pitem->q_bwd->q_fwd = pitem->q_fwd; pitem->q_fwd->q_bwd = pitem->q_bwd; pitem->q_fwd = 0; pitem->q_bwd = 0; pque->q_items--; } /* * gtque remove and return item from front of pque */ struct item *gtque(pque) struct que *pque; { struct item *pitem; if (pque->q_head.q_fwd == (struct item *) pque) return(NULL); pitem = pque->q_head.q_fwd; deque(pque, pitem); return(pitem); } /* * nxtque return pointer to item following pitem on pque * if input pitem is NULL, return first item on pque * if pitem not found or last on que, return NULL */ struct item *nxtque(pque, pitem) register struct que *pque; register struct item *pitem; { register struct item *pitemr; if (pitem == NULL) pitemr = pque->q_head.q_fwd; else { for (pitemr = pque->q_head.q_fwd; (pitemr != (struct item *) pque) && (pitemr != pitem); pitemr = pitemr->q_fwd) ; if (pitemr != (struct item *) pque) pitemr = pitemr->q_fwd; } if (pitemr == (struct item *) pque) pitemr = NULL; return(pitemr); } /* preque put pitem1 on pque before pitem2 */ preque(pque, pitem2, pitem1) struct que *pque; register struct item *pitem2, *pitem1; { pitem1->q_fwd = pitem2; pitem1->q_bwd = pitem2->q_bwd; pitem2->q_bwd->q_fwd = pitem1; pitem2->q_bwd = pitem1; pque->q_items++; } /* postque put pitem2 on pque after pitem1 */ postque(pque, pitem1, pitem2) struct que *pque; register struct item *pitem1, *pitem2; { pitem2->q_fwd = pitem1->q_fwd; pitem2->q_bwd = pitem1; pitem1->q_fwd->q_bwd = pitem2; pitem1->q_fwd = pitem2; pque->q_items++; } dmp_state() { register struct tcb *ptcb; register struct sndcbuf *sbp; ptcb = &tcb; fprintf(log, "\nTcb %o %o %O %o %o\n", ptcb->t_state, ptcb->t_flags, ptcb->t_urgseq, ptcb->t_maxdata, ptcb->t_maxsdata); fprintf(log, "%O %O %O %o %O %O\n", ptcb->t_iss, ptcb->t_snxt, ptcb->t_suna, ptcb->t_swnd, ptcb->t_swseq, ptcb->t_swack); fprintf(log, "%O %O %o %O %O %O %O %o\n", ptcb->t_irs, ptcb->t_rnxt, ptcb->t_rwnd, ptcb->t_rlast, ptcb->t_acktime, ptcb->t_fintime, ptcb->t_sndtime, ptcb->t_ntrans); sbp = &sndcbuf; fprintf(log, "Sndcbuf %o %o %o %o\n", sbp->sb_flags, sbp->sb_len, sbp->sb_datp, sbp->sb_date); fprintf(log, "%O %o %o %o\n", sbp->sb_seqno, sbp->sb_urg, sbp->sb_bbuff, sbp->sb_ebuff); } dmp_pkt(str, ppkt, iplen) char *str; char *ppkt; int iplen; { register struct tcp_hdr *tcp; struct inet_hdr *inp; register char *chp, *che; char *chpt; fprintf(log, "%s", str); inp = ppkt + NETHSIZ; fprintf(log, "Inet hdr\n%o %o %o (%d) %o %o %o %o %o %X %X\n", inp->ip_ihlver, inp->ip_tsrv, inp->ip_len, iplen, inp->ip_id, inp->ip_frag, inp->ip_time, inp->ip_prot, inp->ip_chksum, inp->ip_src, inp->ip_dest); tcp = (char *) inp + ((inp->ip_ihlver & 017) << 2); fprintf(log, "Tcp hdr\n%o %o %O %O %o %o %o %o %o\n", tcp->tc_sskt, tcp->tc_dskt, tcp->tc_seqno, tcp->tc_ackno, tcp->tc_off, tcp->tc_flags, tcp->tc_window, tcp->tc_cksum, tcp->tc_urgp); chp = (char *) tcp + TCPHSIZ; chpt = chp; che = iplen < 60 ? (char *) inp + iplen: (char *) inp + 60; while (chp < che) fprintf(log,"%c ",*chp++); fprintf(log,"\n"); chp = chpt; while (chp < che) fprintf(log,"%o ",*chp++); fprintf(log,"\n"); fflush(log); } dmp_sts() { register struct stats *pst; pst = &stats; seek(fileno(log), 0, 2); fprintf(log, "rpkt %D spkt %D rercv %d resnd %d badorder %d retrans %d\n", pst->s_rpkt, pst->s_spkt, pst->s_rercv, pst->s_resnd, pst->s_badord, tcb.t_retrans); fprintf(log, " net write errors eio %d refuse %d other %d\n", pst->s_errs[WEIO], pst->s_errs[WREFUSE], pst->s_errs[WERR]); fflush(log); }