1 2 #include "../h/param.h" 3 #include "../h/systm.h" 4 #include "../h/mbuf.h" 5 #include "../h/protosw.h" 6 #include "../h/socket.h" 7 #include "../h/socketvar.h" 8 #include "../net/dn_systm.h" 9 #include "../net/nsp.h" 10 #include "../net/nsp_var.h" 11 #include "../errno.h" 12 13 extern int nspidebug; 14 #define printd if(nspidebug)printf 15 16 /* 17 * NSP initialization 18 */ 19 nsp_init() 20 { 21 init queues 22 what else? 23 } 24 25 /* 26 * Nsp_chkaddr performs many functions common to the processing 27 * of input packets. The arguments are: 28 * m - the mbuf with the packet in it 29 * srcnode - the srcnode from the transport header 30 * type - the packet type, one of: 31 * NSP_DATA, NSP_LS, NSP_INTR, NSP_DATACK, NSP_OTHACK 32 * sp - pointer to a short to receive the segment number 33 * 34 * It performs the following functions: 35 * 1. verify that the packet is of the correct minimum length 36 * 2. find the associated NSP control block (by calling dn_addrtonspcb()) 37 * 3. process any ack or nak and force retransmission or remove 38 * acked data from the retransmit queue, as required 39 * 4. update the mbuf to point past the segnum field 40 * 5. return the segnum and nspcb pointer 41 */ 42 struct nspcb * 43 nsp_chkaddr(m, srcnode, type, sp) 44 struct mbuf *m; 45 short srcnode; 46 int type; 47 u_short *sp; 48 { 49 register struct nspcb *np; 50 struct nspd *n; 51 u_short dstaddr; 52 int ack, qual, num; 53 54 /* make sure we are accessing valid data */ 55 if (m->m_len < sizeof (struct nspd) - sizeof (d_short)) { 56 m_freem(m); 57 return (0); 58 } 59 n = mtod(m, struct nspd *); 60 dstaddr = D_SHORT(n->nsp_dstaddr); 61 np = dn_addrtonspcb(dstaddr); 62 if (np == 0) { 63 no such address, return "no link" message 64 } 65 if (np->n_node != srcnode) { 66 printf("nsp_chkaddr: n_node %d, srcnode %d\n", np->n_node, 67 scrnode); 68 m_freem(m); 69 return (0); 70 } 71 /* make sure remote addresses match (consistency check) */ 72 if (np->n_rem != D_SHORT(n->nsp_srcaddr)) { 73 printf("nsp_chkaddr: n_rem %d, srcaddr %d\n", np->n_rem, 74 D_SHORT(n->nsp_srcaddr)); 75 m_freem(m); 76 return (0); 77 } 78 ack = D_SHORT(n->nsp_acknum); 79 if (ack & NSPA_ACK) { 80 qual = ack & NSPA_QUAL; 81 num = ack & NSPA_NUM; 82 printd(", qual 0x%x, num %d", qual, num); 83 /* make sure there's room for a segnum */ 84 if (m->m_len < sizeof (struct nspd)) { 85 m_freem(m); 86 return (0); 87 } 88 if (type == NSP_DATA) { 89 if (SEQ_GTR(num, np->na_rcvdat) && 90 SEQ_LEQ(num, np->nn_high)) { 91 np->n_retrans = 0; 92 np->nf_remdat -= SEQ_SUB(num, np->na_rcvdat); 93 } 94 if (qual == NSPA_NAK || SEQ_LEQ(np->nn_dat, num)) 95 np->nn_dat = SEQ_ADD(num, 1); 96 np->na_rcvdat = num; 97 nsp_purgertq(np, type); 98 } else if (n == np->nn_oth && (np->n_flags&NF_OTHSENT)) { 99 if (qual == NSPA_NAK) { 100 /* force retransmission of other data seg */ 101 printf("nsp_chkaddr: NAK other\n"); 102 } else { 103 np->n_flags &= ~NF_OTHSENT; 104 np->nn_oth = SEQ_ADD(np->nn_oth, 1); 105 if (np->n_flags & NF_OTHINTR) { 106 np->n_flags &= 107 ~(NF_OTHINTR|NF_INTAVAIL); 108 if (np->nb_xmt) 109 m_freem(np->nb_xmt); 110 } else 111 np->nf_locdat = 0; 112 nsp_purgertq(np, type); 113 } 114 } 115 *sp = D_SHORT(n->nsp_segnum); 116 num = sizeof (struct nspd); 117 } else { 118 *sp = (u_short)ack; 119 num = sizeof (struct nspd) - sizeof (u_short); 120 } 121 m->m_len -= num; 122 m->m_off += num; 123 return (np); 124 } 125