|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /*- ! 26: * Copyright (c) 1991, 1993 ! 27: * The Regents of the University of California. All rights reserved. ! 28: * ! 29: * Redistribution and use in source and binary forms, with or without ! 30: * modification, are permitted provided that the following conditions ! 31: * are met: ! 32: * 1. Redistributions of source code must retain the above copyright ! 33: * notice, this list of conditions and the following disclaimer. ! 34: * 2. Redistributions in binary form must reproduce the above copyright ! 35: * notice, this list of conditions and the following disclaimer in the ! 36: * documentation and/or other materials provided with the distribution. ! 37: * 3. All advertising materials mentioning features or use of this software ! 38: * must display the following acknowledgement: ! 39: * This product includes software developed by the University of ! 40: * California, Berkeley and its contributors. ! 41: * 4. Neither the name of the University nor the names of its contributors ! 42: * may be used to endorse or promote products derived from this software ! 43: * without specific prior written permission. ! 44: * ! 45: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 46: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 47: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 48: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 49: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 50: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 51: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 52: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 53: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 54: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 55: * SUCH DAMAGE. ! 56: * ! 57: * @(#)tp_input.c 8.1 (Berkeley) 6/10/93 ! 58: */ ! 59: ! 60: /*********************************************************** ! 61: Copyright IBM Corporation 1987 ! 62: ! 63: All Rights Reserved ! 64: ! 65: Permission to use, copy, modify, and distribute this software and its ! 66: documentation for any purpose and without fee is hereby granted, ! 67: provided that the above copyright notice appear in all copies and that ! 68: both that copyright notice and this permission notice appear in ! 69: supporting documentation, and that the name of IBM not be ! 70: used in advertising or publicity pertaining to distribution of the ! 71: software without specific, written prior permission. ! 72: ! 73: IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ! 74: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ! 75: IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 76: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ! 77: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ! 78: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ! 79: SOFTWARE. ! 80: ! 81: ******************************************************************/ ! 82: ! 83: /* ! 84: * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison ! 85: */ ! 86: /* ! 87: * ARGO TP ! 88: * ! 89: * tp_input() gets an mbuf chain from ip. Actually, not directly ! 90: * from ip, because ip calls a net-level routine that strips off ! 91: * the net header and then calls tp_input(), passing the proper type ! 92: * of addresses for the address family in use (how it figures out ! 93: * which AF is not yet determined.) ! 94: * ! 95: * Decomposing the tpdu is some of the most laughable code. The variable-length ! 96: * parameters and the problem of non-aligned memory references ! 97: * necessitates such abominations as the macros WHILE_OPTIONS (q.v. below) ! 98: * to loop through the header and decompose it. ! 99: * ! 100: * The routine tp_newsocket() is called when a CR comes in for a listening ! 101: * socket. tp_input calls sonewconn() and tp_newsocket() to set up the ! 102: * "child" socket. Most tpcb values are copied from the parent tpcb into ! 103: * the child. ! 104: * ! 105: * Also in here is tp_headersize() (grot) which tells the expected size ! 106: * of a tp header, to be used by other layers. It's in here because it ! 107: * uses the static structure tpdu_info. ! 108: */ ! 109: ! 110: #include <sys/param.h> ! 111: #include <sys/systm.h> ! 112: #include <sys/mbuf.h> ! 113: #include <sys/socket.h> ! 114: #include <sys/socketvar.h> ! 115: #include <sys/domain.h> ! 116: #include <sys/protosw.h> ! 117: #include <sys/errno.h> ! 118: #include <sys/time.h> ! 119: #include <sys/kernel.h> ! 120: ! 121: #include <netiso/iso.h> ! 122: #include <netiso/iso_errno.h> ! 123: #include <netiso/iso_pcb.h> ! 124: #include <netiso/tp_param.h> ! 125: #include <netiso/tp_timer.h> ! 126: #include <netiso/tp_stat.h> ! 127: #include <netiso/tp_pcb.h> ! 128: #include <netiso/argo_debug.h> ! 129: #include <netiso/tp_trace.h> ! 130: #include <netiso/tp_tpdu.h> ! 131: ! 132: #include <net/if.h> ! 133: #ifdef TRUE ! 134: #undef FALSE ! 135: #undef TRUE ! 136: #endif ! 137: #include <netccitt/x25.h> ! 138: #include <netccitt/pk.h> ! 139: #include <netccitt/pk_var.h> ! 140: ! 141: int iso_check_csum(), tp_driver(), tp_headersize(), tp_error_emit(); ! 142: ! 143: /* ! 144: #ifdef lint ! 145: #undef ATTR ! 146: #define ATTR(X)ev_number ! 147: #endif lint ! 148: */ ! 149: ! 150: struct mbuf * ! 151: tp_inputprep(m) ! 152: register struct mbuf *m; ! 153: { ! 154: int hdrlen; ! 155: ! 156: IFDEBUG(D_TPINPUT) ! 157: printf("tp_inputprep: m 0x%x\n", m) ; ! 158: ENDDEBUG ! 159: ! 160: while( m->m_len < 1 ) { ! 161: /* The "m_free" logic ! 162: * if( (m = m_free(m)) == MNULL ) ! 163: * return (struct mbuf *)0; ! 164: * would cause a system crash if ever executed. ! 165: * This logic will be executed if the first mbuf ! 166: * in the chain only contains a CLNP header. The m_free routine ! 167: * will release the mbuf containing the CLNP header from the ! 168: * chain and the new head of the chain will not have the ! 169: * M_PKTHDR bit set. This routine, tp_inputprep, will ! 170: * eventually call the "sbappendaddr" routine. "sbappendaddr" ! 171: * calls "panic" if M_PKTHDR is not set. m_pullup is a cheap ! 172: * way of keeping the head of the chain from being freed. ! 173: */ ! 174: if((m = m_pullup(m, 1)) == MNULL) ! 175: return (MNULL); ! 176: } ! 177: if(((int)m->m_data) & 0x3) { ! 178: /* If we are not 4-byte aligned, we have to be ! 179: * above the beginning of the mbuf, and it is ok just ! 180: * to slide it back. ! 181: */ ! 182: caddr_t ocp = m->m_data; ! 183: ! 184: m->m_data = (caddr_t)(((int)m->m_data) & ~0x3); ! 185: bcopy(ocp, m->m_data, (unsigned)m->m_len); ! 186: } ! 187: CHANGE_MTYPE(m, TPMT_DATA); ! 188: ! 189: /* we KNOW that there is at least 1 byte in this mbuf ! 190: and that it is hdr->tpdu_li XXXXXXX! */ ! 191: ! 192: hdrlen = 1 + *mtod( m, u_char *); ! 193: ! 194: /* ! 195: * now pull up the whole tp header ! 196: */ ! 197: if ( m->m_len < hdrlen) { ! 198: if ((m = m_pullup(m, hdrlen)) == MNULL ) { ! 199: IncStat(ts_recv_drop); ! 200: return (struct mbuf *)0; ! 201: } ! 202: } ! 203: IFDEBUG(D_INPUT) ! 204: printf( ! 205: " at end: m 0x%x hdr->tpdu_li 0x%x m_len 0x%x\n",m, ! 206: hdrlen, m->m_len); ! 207: ENDDEBUG ! 208: return m; ! 209: } ! 210: ! 211: /* begin groan ! 212: * -- this array and the following macros allow you to step through the ! 213: * parameters of the variable part of a header ! 214: * note that if for any reason the values of the **_TPDU macros (in tp_events.h) ! 215: * should change, this array has to be rearranged ! 216: */ ! 217: ! 218: #define TP_LEN_CLASS_0_INDEX 2 ! 219: #define TP_MAX_DATA_INDEX 3 ! 220: ! 221: static u_char tpdu_info[][4] = ! 222: { ! 223: /* length max data len */ ! 224: /* reg fmt xtd fmt class 0 */ ! 225: /* UNUSED 0x0 */ 0x0 , 0x0, 0x0, 0x0, ! 226: /* XPD_TPDU_type 0x1 */ 0x5, 0x8, 0x0, TP_MAX_XPD_DATA, ! 227: /* XAK_TPDU_type 0x2 */ 0x5 , 0x8, 0x0, 0x0, ! 228: /* GR_TPDU_type 0x3 */ 0x0 , 0x0, 0x0, 0x0, ! 229: /* UNUSED 0x4 */ 0x0 , 0x0, 0x0, 0x0, ! 230: /* UNUSED 0x5 */ 0x0 , 0x0, 0x0, 0x0, ! 231: /* AK_TPDU_type 0x6 */ 0x5, 0xa, 0x0, 0x0, ! 232: /* ER_TPDU_type 0x7 */ 0x5, 0x5, 0x0, 0x0, ! 233: /* DR_TPDU_type 0x8 */ 0x7, 0x7, 0x7, TP_MAX_DR_DATA, ! 234: /* UNUSED 0x9 */ 0x0 , 0x0, 0x0, 0x0, ! 235: /* UNUSED 0xa */ 0x0 , 0x0, 0x0, 0x0, ! 236: /* UNUSED 0xb */ 0x0 , 0x0, 0x0, 0x0, ! 237: /* DC_TPDU_type 0xc */ 0x6, 0x6, 0x0, 0x0, ! 238: /* CC_TPDU_type 0xd */ 0x7, 0x7, 0x7, TP_MAX_CC_DATA, ! 239: /* CR_TPDU_type 0xe */ 0x7, 0x7, 0x7, TP_MAX_CR_DATA, ! 240: /* DT_TPDU_type 0xf */ 0x5, 0x8, 0x3, 0x0, ! 241: }; ! 242: ! 243: #define CHECK(Phrase, Erval, Stat, Whattodo, Loc)\ ! 244: if (Phrase) {error = (Erval); errlen = (int)(Loc); IncStat(Stat);\ ! 245: goto Whattodo; } ! 246: ! 247: /* ! 248: * WHENEVER YOU USE THE FOLLOWING MACRO, ! 249: * BE SURE THE TPDUTYPE IS A LEGIT VALUE FIRST! ! 250: */ ! 251: ! 252: #define WHILE_OPTIONS(P, hdr, format)\ ! 253: { register caddr_t P = tpdu_info[(hdr)->tpdu_type][(format)] + (caddr_t)hdr;\ ! 254: caddr_t PLIM = 1 + hdr->tpdu_li + (caddr_t)hdr;\ ! 255: for (;; P += 2 + ((struct tp_vbp *)P)->tpv_len) {\ ! 256: CHECK((P > PLIM), E_TP_LENGTH_INVAL, ts_inv_length,\ ! 257: respond, P - (caddr_t)hdr);\ ! 258: if (P == PLIM) break; ! 259: ! 260: #define END_WHILE_OPTIONS(P) } } ! 261: ! 262: /* end groan */ ! 263: ! 264: /* ! 265: * NAME: tp_newsocket() ! 266: * ! 267: * CALLED FROM: ! 268: * tp_input() on incoming CR, when a socket w/ the called suffix ! 269: * is awaiting a connection request ! 270: * ! 271: * FUNCTION and ARGUMENTS: ! 272: * Create a new socket structure, attach to it a new transport pcb, ! 273: * using a copy of the net level pcb for the parent socket. ! 274: * (so) is the parent socket. ! 275: * (fname) is the foreign address (all that's used is the nsap portion) ! 276: * ! 277: * RETURN VALUE: ! 278: * a new socket structure, being this end of the newly formed connection. ! 279: * ! 280: * SIDE EFFECTS: ! 281: * Sets a few things in the tpcb and net level pcb ! 282: * ! 283: * NOTES: ! 284: */ ! 285: static struct socket * ! 286: tp_newsocket(so, fname, cons_channel, class_to_use, netservice) ! 287: struct socket *so; ! 288: struct sockaddr *fname; ! 289: caddr_t cons_channel; ! 290: u_char class_to_use; ! 291: u_int netservice; ! 292: { ! 293: register struct tp_pcb *tpcb = sototpcb(so); /* old tpcb, needed below */ ! 294: register struct tp_pcb *newtpcb; ! 295: ! 296: /* ! 297: * sonewconn() gets a new socket structure, ! 298: * a new lower layer pcb and a new tpcb, ! 299: * but the pcbs are unnamed (not bound) ! 300: */ ! 301: IFTRACE(D_NEWSOCK) ! 302: tptraceTPCB(TPPTmisc, "newsock: listg_so, _tpcb, so_head", ! 303: so, tpcb, so->so_head, 0); ! 304: ENDTRACE ! 305: ! 306: if ((so = sonewconn(so, SS_ISCONFIRMING)) == (struct socket *)0) ! 307: return so; ! 308: IFTRACE(D_NEWSOCK) ! 309: tptraceTPCB(TPPTmisc, "newsock: after newconn so, so_head", ! 310: so, so->so_head, 0, 0); ! 311: ENDTRACE ! 312: ! 313: IFDEBUG(D_NEWSOCK) ! 314: printf("tp_newsocket(channel 0x%x) after sonewconn so 0x%x \n", ! 315: cons_channel, so); ! 316: dump_addr(fname); ! 317: { ! 318: struct socket *t, *head ; ! 319: ! 320: head = so->so_head; ! 321: t = so; ! 322: printf("so 0x%x so_head 0x%x so_q0 0x%x, q0len %d\n", ! 323: t, t->so_head, t->so_q0, t->so_q0len); ! 324: while( (t=t->so_q0) && t!= so && t!= head) ! 325: printf("so 0x%x so_head 0x%x so_q0 0x%x, q0len %d\n", ! 326: t, t->so_head, t->so_q0, t->so_q0len); ! 327: } ! 328: ENDDEBUG ! 329: ! 330: /* ! 331: * before we clobber the old tpcb ptr, get these items from the parent pcb ! 332: */ ! 333: newtpcb = sototpcb(so); ! 334: newtpcb->_tp_param = tpcb->_tp_param; ! 335: newtpcb->tp_flags = tpcb->tp_flags; ! 336: newtpcb->tp_lcredit = tpcb->tp_lcredit; ! 337: newtpcb->tp_l_tpdusize = tpcb->tp_l_tpdusize; ! 338: newtpcb->tp_lsuffixlen = tpcb->tp_lsuffixlen; ! 339: bcopy( tpcb->tp_lsuffix, newtpcb->tp_lsuffix, newtpcb->tp_lsuffixlen); ! 340: ! 341: if( /* old */ tpcb->tp_ucddata) { ! 342: /* ! 343: * These data are the connect- , confirm- or disconnect- data. ! 344: */ ! 345: struct mbuf *conndata; ! 346: ! 347: conndata = m_copy(tpcb->tp_ucddata, 0, (int)M_COPYALL); ! 348: IFDEBUG(D_CONN) ! 349: dump_mbuf(conndata, "conndata after mcopy"); ! 350: ENDDEBUG ! 351: newtpcb->tp_ucddata = conndata; ! 352: } ! 353: ! 354: tpcb = newtpcb; ! 355: tpcb->tp_state = TP_LISTENING; ! 356: tpcb->tp_class = class_to_use; ! 357: tpcb->tp_netservice = netservice; ! 358: ! 359: ! 360: ASSERT( fname != 0 ) ; /* just checking */ ! 361: if ( fname ) { ! 362: /* ! 363: * tp_route_to takes its address argument in the form of an mbuf. ! 364: */ ! 365: struct mbuf *m; ! 366: int err; ! 367: ! 368: MGET(m, M_DONTWAIT, MT_SONAME); /* mbuf type used is confusing */ ! 369: if (m) { ! 370: /* ! 371: * this seems a bit grotesque, but tp_route_to expects ! 372: * an mbuf * instead of simply a sockaddr; it calls the ll ! 373: * pcb_connect, which expects the name/addr in an mbuf as well. ! 374: * sigh. ! 375: */ ! 376: bcopy((caddr_t)fname, mtod(m, caddr_t), fname->sa_len); ! 377: m->m_len = fname->sa_len; ! 378: ! 379: /* grot : have to say the kernel can override params in ! 380: * the passive open case ! 381: */ ! 382: tpcb->tp_dont_change_params = 0; ! 383: err = tp_route_to( m, tpcb, cons_channel); ! 384: m_free(m); ! 385: ! 386: if (!err) ! 387: goto ok; ! 388: } ! 389: IFDEBUG(D_CONN) ! 390: printf("tp_route_to FAILED! detaching tpcb 0x%x, so 0x%x\n", ! 391: tpcb, so); ! 392: ENDDEBUG ! 393: (void) tp_detach(tpcb); ! 394: return 0; ! 395: } ! 396: ok: ! 397: IFDEBUG(D_TPINPUT) ! 398: printf("tp_newsocket returning so 0x%x, sototpcb(so) 0x%x\n", ! 399: so, sototpcb(so)); ! 400: ENDDEBUG ! 401: return so; ! 402: } ! 403: ! 404: #ifndef TPCONS ! 405: tpcons_output() ! 406: { ! 407: return(0); ! 408: } ! 409: #endif /* !CONS */ ! 410: ! 411: /* ! 412: * NAME: tp_input() ! 413: * ! 414: * CALLED FROM: ! 415: * net layer input routine ! 416: * ! 417: * FUNCTION and ARGUMENTS: ! 418: * Process an incoming TPDU (m), finding the associated tpcb if there ! 419: * is one. Create the appropriate type of event and call the driver. ! 420: * (faddr) and (laddr) are the foreign and local addresses. ! 421: * ! 422: * When tp_input() is called we KNOW that the ENTIRE TP HEADER ! 423: * has been m_pullup-ed. ! 424: * ! 425: * RETURN VALUE: Nada ! 426: * ! 427: * SIDE EFFECTS: ! 428: * When using COSNS it may affect the state of the net-level pcb ! 429: * ! 430: * NOTE: ! 431: * The initial value of acktime is 2 so that we will never ! 432: * have a 0 value for tp_peer_acktime. It gets used in the ! 433: * computation of the retransmission timer value, and so it ! 434: * mustn't be zero. ! 435: * 2 seems like a reasonable minimum. ! 436: */ ! 437: ProtoHook ! 438: tp_input(m, faddr, laddr, cons_channel, dgout_routine, ce_bit) ! 439: register struct mbuf *m; ! 440: struct sockaddr *faddr, *laddr; /* NSAP addresses */ ! 441: caddr_t cons_channel; ! 442: int (*dgout_routine)(); ! 443: int ce_bit; ! 444: ! 445: { ! 446: register struct tp_pcb *tpcb; ! 447: register struct tpdu *hdr; ! 448: struct socket *so; ! 449: struct tp_event e; ! 450: int error; ! 451: unsigned dutype; ! 452: u_short dref, sref, acktime, subseq; ! 453: u_char preferred_class, class_to_use, pdusize; ! 454: u_char opt, dusize, addlopt, version; ! 455: #ifdef TP_PERF_MEAS ! 456: u_char perf_meas; ! 457: #endif /* TP_PERF_MEAS */ ! 458: u_char fsufxlen, lsufxlen; ! 459: caddr_t fsufxloc, lsufxloc; ! 460: int tpdu_len; ! 461: u_int takes_data; ! 462: u_int fcc_present; ! 463: int errlen; ! 464: struct tp_conn_param tpp; ! 465: int tpcons_output(); ! 466: ! 467: again: ! 468: hdr = mtod(m, struct tpdu *); ! 469: tpcb = 0; ! 470: error = errlen = tpdu_len = 0; ! 471: takes_data = fcc_present = FALSE; ! 472: acktime = 2; sref = subseq = 0; ! 473: fsufxloc = lsufxloc = NULL; ! 474: fsufxlen = lsufxlen = ! 475: preferred_class = class_to_use = pdusize = addlopt = 0; ! 476: dusize = TP_DFL_TPDUSIZE; ! 477: #ifdef TP_PERF_MEAS ! 478: GET_CUR_TIME( &e.e_time ); perf_meas = 0; ! 479: #endif /* TP_PERF_MEAS */ ! 480: ! 481: IFDEBUG(D_TPINPUT) ! 482: printf("tp_input(0x%x, ... 0x%x)\n", m, cons_channel); ! 483: ENDDEBUG ! 484: ! 485: ! 486: /* ! 487: * get the actual tpdu length - necessary for monitoring ! 488: * and for checksumming ! 489: * ! 490: * Also, maybe measure the mbuf chain lengths and sizes. ! 491: */ ! 492: ! 493: { register struct mbuf *n=m; ! 494: # ifdef ARGO_DEBUG ! 495: int chain_length = 0; ! 496: # endif ARGO_DEBUG ! 497: ! 498: for(;;) { ! 499: tpdu_len += n->m_len; ! 500: IFDEBUG(D_MBUF_MEAS) ! 501: if( n->m_flags & M_EXT) { ! 502: IncStat(ts_mb_cluster); ! 503: } else { ! 504: IncStat(ts_mb_small); ! 505: } ! 506: chain_length ++; ! 507: ENDDEBUG ! 508: if (n->m_next == MNULL ) { ! 509: break; ! 510: } ! 511: n = n->m_next; ! 512: } ! 513: IFDEBUG(D_MBUF_MEAS) ! 514: if(chain_length > 16) ! 515: chain_length = 0; /* zero used for anything > 16 */ ! 516: tp_stat.ts_mb_len_distr[chain_length] ++; ! 517: ENDDEBUG ! 518: } ! 519: IFTRACE(D_TPINPUT) ! 520: tptraceTPCB(TPPTtpduin, hdr->tpdu_type, hdr, hdr->tpdu_li+1, tpdu_len, ! 521: 0); ! 522: ENDTRACE ! 523: ! 524: dref = ntohs((short)hdr->tpdu_dref); ! 525: sref = ntohs((short)hdr->tpdu_sref); ! 526: dutype = (int)hdr->tpdu_type; ! 527: ! 528: IFDEBUG(D_TPINPUT) ! 529: printf("input: dutype 0x%x cons_channel 0x%x dref 0x%x\n", dutype, ! 530: cons_channel, dref); ! 531: printf("input: dref 0x%x sref 0x%x\n", dref, sref); ! 532: ENDDEBUG ! 533: IFTRACE(D_TPINPUT) ! 534: tptrace(TPPTmisc, "channel dutype dref ", ! 535: cons_channel, dutype, dref, 0); ! 536: ENDTRACE ! 537: ! 538: ! 539: #ifdef ARGO_DEBUG ! 540: if( (dutype < TP_MIN_TPDUTYPE) || (dutype > TP_MAX_TPDUTYPE)) { ! 541: printf("BAD dutype! 0x%x, channel 0x%x dref 0x%x\n", ! 542: dutype, cons_channel, dref); ! 543: dump_buf (m, sizeof( struct mbuf )); ! 544: ! 545: IncStat(ts_inv_dutype); ! 546: goto discard; ! 547: } ! 548: #endif /* ARGO_DEBUG */ ! 549: ! 550: CHECK( (dutype < TP_MIN_TPDUTYPE || dutype > TP_MAX_TPDUTYPE), ! 551: E_TP_INV_TPDU, ts_inv_dutype, respond, ! 552: 2 ); ! 553: /* unfortunately we can't take the address of the tpdu_type field, ! 554: * since it's a bit field - so we just use the constant offset 2 ! 555: */ ! 556: ! 557: /* Now this isn't very neat but since you locate a pcb one way ! 558: * at the beginning of connection establishment, and by ! 559: * the dref for each tpdu after that, we have to treat CRs differently ! 560: */ ! 561: if ( dutype == CR_TPDU_type ) { ! 562: u_char alt_classes = 0; ! 563: ! 564: preferred_class = 1 << hdr->tpdu_CRclass; ! 565: opt = hdr->tpdu_CRoptions; ! 566: ! 567: WHILE_OPTIONS(P, hdr, 1 ) /* { */ ! 568: ! 569: switch( vbptr(P)->tpv_code ) { ! 570: ! 571: case TPP_tpdu_size: ! 572: vb_getval(P, u_char, dusize); ! 573: IFDEBUG(D_TPINPUT) ! 574: printf("CR dusize 0x%x\n", dusize); ! 575: ENDDEBUG ! 576: /* COS tests: NBS IA (Dec. 1987) Sec. 4.5.2.1 */ ! 577: if (dusize < TP_MIN_TPDUSIZE || dusize > TP_MAX_TPDUSIZE) ! 578: dusize = TP_DFL_TPDUSIZE; ! 579: break; ! 580: case TPP_ptpdu_size: ! 581: switch (vbptr(P)->tpv_len) { ! 582: case 1: pdusize = vbval(P, u_char); break; ! 583: case 2: pdusize = ntohs(vbval(P, u_short)); break; ! 584: default: ; ! 585: IFDEBUG(D_TPINPUT) ! 586: printf("malformed prefered TPDU option\n"); ! 587: ENDDEBUG ! 588: } ! 589: break; ! 590: case TPP_addl_opt: ! 591: vb_getval(P, u_char, addlopt); ! 592: break; ! 593: case TPP_calling_sufx: ! 594: /* could use vb_getval, but we want to save the loc & len ! 595: * for later use ! 596: */ ! 597: fsufxloc = (caddr_t) &vbptr(P)->tpv_val; ! 598: fsufxlen = vbptr(P)->tpv_len; ! 599: IFDEBUG(D_TPINPUT) ! 600: printf("CR fsufx:"); ! 601: { register int j; ! 602: for(j=0; j<fsufxlen; j++ ) { ! 603: printf(" 0x%x. ", *((caddr_t)(fsufxloc+j)) ); ! 604: } ! 605: printf("\n"); ! 606: } ! 607: ENDDEBUG ! 608: break; ! 609: case TPP_called_sufx: ! 610: /* could use vb_getval, but we want to save the loc & len ! 611: * for later use ! 612: */ ! 613: lsufxloc = (caddr_t) &vbptr(P)->tpv_val; ! 614: lsufxlen = vbptr(P)->tpv_len; ! 615: IFDEBUG(D_TPINPUT) ! 616: printf("CR lsufx:"); ! 617: { register int j; ! 618: for(j=0; j<lsufxlen; j++ ) { ! 619: printf(" 0x%x. ", *((u_char *)(lsufxloc+j)) ); ! 620: } ! 621: printf("\n"); ! 622: } ! 623: ENDDEBUG ! 624: break; ! 625: ! 626: #ifdef TP_PERF_MEAS ! 627: case TPP_perf_meas: ! 628: vb_getval(P, u_char, perf_meas); ! 629: break; ! 630: #endif /* TP_PERF_MEAS */ ! 631: ! 632: case TPP_vers: ! 633: /* not in class 0; 1 octet; in CR_TPDU only */ ! 634: /* COS tests says if version wrong, use default version!?XXX */ ! 635: CHECK( (vbval(P, u_char) != TP_VERSION ), ! 636: E_TP_INV_PVAL, ts_inv_pval, setversion, ! 637: (1 + (caddr_t)&vbptr(P)->tpv_val - (caddr_t)hdr) ); ! 638: setversion: ! 639: version = vbval(P, u_char); ! 640: break; ! 641: case TPP_acktime: ! 642: vb_getval(P, u_short, acktime); ! 643: acktime = ntohs(acktime); ! 644: acktime = acktime/500; /* convert to slowtimo ticks */ ! 645: if((short)acktime <=0 ) ! 646: acktime = 2; /* don't allow a bad peer to screw us up */ ! 647: IFDEBUG(D_TPINPUT) ! 648: printf("CR acktime 0x%x\n", acktime); ! 649: ENDDEBUG ! 650: break; ! 651: ! 652: case TPP_alt_class: ! 653: { ! 654: u_char *aclass = 0; ! 655: register int i; ! 656: static u_char bad_alt_classes[5] = ! 657: { ~0, ~3, ~5, ~0xf, ~0x1f}; ! 658: ! 659: aclass = ! 660: (u_char *) &(((struct tp_vbp *)P)->tpv_val); ! 661: for (i = ((struct tp_vbp *)P)->tpv_len; i>0; i--) { ! 662: alt_classes |= (1<<((*aclass++)>>4)); ! 663: } ! 664: CHECK( (bad_alt_classes[hdr->tpdu_CRclass] & alt_classes), ! 665: E_TP_INV_PVAL, ts_inv_aclass, respond, ! 666: ((caddr_t)aclass) - (caddr_t)hdr); ! 667: IFDEBUG(D_TPINPUT) ! 668: printf("alt_classes 0x%x\n", alt_classes); ! 669: ENDDEBUG ! 670: } ! 671: break; ! 672: ! 673: case TPP_security: ! 674: case TPP_residER: ! 675: case TPP_priority: ! 676: case TPP_transdelay: ! 677: case TPP_throughput: ! 678: case TPP_addl_info: ! 679: case TPP_subseq: ! 680: default: ! 681: IFDEBUG(D_TPINPUT) ! 682: printf("param ignored CR_TPDU code= 0x%x\n", ! 683: vbptr(P)->tpv_code); ! 684: ENDDEBUG ! 685: IncStat(ts_param_ignored); ! 686: break; ! 687: ! 688: case TPP_checksum: ! 689: IFDEBUG(D_TPINPUT) ! 690: printf("CR before cksum\n"); ! 691: ENDDEBUG ! 692: ! 693: CHECK( iso_check_csum(m, tpdu_len), ! 694: E_TP_INV_PVAL, ts_bad_csum, discard, 0) ! 695: ! 696: IFDEBUG(D_TPINPUT) ! 697: printf("CR before cksum\n"); ! 698: ENDDEBUG ! 699: break; ! 700: } ! 701: ! 702: /* } */ END_WHILE_OPTIONS(P) ! 703: ! 704: if (lsufxlen == 0) { ! 705: /* can't look for a tpcb w/o any called sufx */ ! 706: error = E_TP_LENGTH_INVAL; ! 707: IncStat(ts_inv_sufx); ! 708: goto respond; ! 709: } else { ! 710: register struct tp_pcb *t; ! 711: /* ! 712: * The intention here is to trap all CR requests ! 713: * to a given nsap, for constructing transport ! 714: * service bridges at user level; so these ! 715: * intercepts should precede the normal listens. ! 716: * Phrasing the logic in this way also allows for ! 717: * mop-up listeners, which we don't currently implement. ! 718: * We also wish to have a single socket be able to ! 719: * listen over any network service provider, ! 720: * (cons or clns or ip). ! 721: */ ! 722: for (t = tp_listeners; t ; t = t->tp_nextlisten) ! 723: if ((t->tp_lsuffixlen == 0 || ! 724: (lsufxlen == t->tp_lsuffixlen && ! 725: bcmp(lsufxloc, t->tp_lsuffix, lsufxlen) == 0)) && ! 726: ((t->tp_flags & TPF_GENERAL_ADDR) || ! 727: (laddr->sa_family == t->tp_domain && ! 728: (*t->tp_nlproto->nlp_cmpnetaddr) ! 729: (t->tp_npcb, laddr, TP_LOCAL)))) ! 730: break; ! 731: ! 732: CHECK(t == 0, E_TP_NO_SESSION, ts_inv_sufx, respond, ! 733: (1 + 2 + (caddr_t)&hdr->_tpduf - (caddr_t)hdr)) ! 734: /* _tpduf is the fixed part; add 2 to get the dref bits of ! 735: * the fixed part (can't take the address of a bit field) ! 736: */ ! 737: IFDEBUG(D_TPINPUT) ! 738: printf("checking if dup CR\n"); ! 739: ENDDEBUG ! 740: tpcb = t; ! 741: for (t = tpcb->tp_next; t != tpcb; t = t->tp_next) { ! 742: if (sref != t->tp_fref) ! 743: continue; ! 744: if ((*tpcb->tp_nlproto->nlp_cmpnetaddr)( ! 745: t->tp_npcb, faddr, TP_FOREIGN)) { ! 746: IFDEBUG(D_TPINPUT) ! 747: printf("duplicate CR discarded\n"); ! 748: ENDDEBUG ! 749: goto discard; ! 750: } ! 751: } ! 752: IFTRACE(D_TPINPUT) ! 753: tptrace(TPPTmisc, "tp_input: tpcb *lsufxloc tpstate", ! 754: tpcb, *lsufxloc, tpcb->tp_state, 0); ! 755: ENDTRACE ! 756: } ! 757: ! 758: /* ! 759: * WE HAVE A TPCB ! 760: * already know that the classes in the CR match at least ! 761: * one class implemented, but we don't know yet if they ! 762: * include any classes permitted by this server. ! 763: */ ! 764: ! 765: IFDEBUG(D_TPINPUT) ! 766: printf("HAVE A TPCB 1: 0x%x\n", tpcb); ! 767: ENDDEBUG ! 768: IFDEBUG(D_CONN) ! 769: printf( ! 770: "CR: bef CHKS: flags 0x%x class_to_use 0x%x alt 0x%x opt 0x%x tp_class 0x%x\n", ! 771: tpcb->tp_flags, class_to_use, alt_classes, opt, tpcb->tp_class); ! 772: ENDDEBUG ! 773: /* tpcb->tp_class doesn't include any classes not implemented */ ! 774: class_to_use = (preferred_class & tpcb->tp_class); ! 775: if( (class_to_use = preferred_class & tpcb->tp_class) == 0 ) ! 776: class_to_use = alt_classes & tpcb->tp_class; ! 777: ! 778: class_to_use = 1 << tp_mask_to_num(class_to_use); ! 779: ! 780: { ! 781: tpp = tpcb->_tp_param; ! 782: tpp.p_class = class_to_use; ! 783: tpp.p_tpdusize = dusize; ! 784: tpp.p_ptpdusize = pdusize; ! 785: tpp.p_xtd_format = (opt & TPO_XTD_FMT) == TPO_XTD_FMT; ! 786: tpp.p_xpd_service = (addlopt & TPAO_USE_TXPD) == TPAO_USE_TXPD; ! 787: tpp.p_use_checksum = (tpp.p_class == TP_CLASS_0)?0: ! 788: (addlopt & TPAO_NO_CSUM) == 0; ! 789: tpp.p_version = version; ! 790: #ifdef notdef ! 791: tpp.p_use_efc = (opt & TPO_USE_EFC) == TPO_USE_EFC; ! 792: tpp.p_use_nxpd = (addlopt & TPAO_USE_NXPD) == TPAO_USE_NXPD; ! 793: tpp.p_use_rcc = (addlopt & TPAO_USE_RCC) == TPAO_USE_RCC; ! 794: #endif /* notdef */ ! 795: ! 796: CHECK( ! 797: tp_consistency(tpcb, 0 /* not force or strict */, &tpp) != 0, ! 798: E_TP_NEGOT_FAILED, ts_negotfailed, clear_parent_tcb, ! 799: (1 + 2 + (caddr_t)&hdr->_tpdufr.CRCC - (caddr_t)hdr) ! 800: /* ^ more or less the location of class */ ! 801: ) ! 802: } ! 803: IFTRACE(D_CONN) ! 804: tptrace(TPPTmisc, ! 805: "after 1 consist class_to_use class, out, tpconsout", ! 806: class_to_use, ! 807: tpcb->tp_class, dgout_routine, tpcons_output ! 808: ); ! 809: ENDTRACE ! 810: CHECK( ! 811: ((class_to_use == TP_CLASS_0)&&(dgout_routine != tpcons_output)), ! 812: E_TP_NEGOT_FAILED, ts_negotfailed, clear_parent_tcb, ! 813: (1 + 2 + (caddr_t)&hdr->_tpdufr.CRCC - (caddr_t)hdr) ! 814: /* ^ more or less the location of class */ ! 815: ) ! 816: IFDEBUG(D_CONN) ! 817: printf("CR: after CRCCCHECKS: tpcb 0x%x, flags 0x%x\n", ! 818: tpcb, tpcb->tp_flags); ! 819: ENDDEBUG ! 820: takes_data = TRUE; ! 821: e.ATTR(CR_TPDU).e_cdt = hdr->tpdu_CRcdt; ! 822: e.ev_number = CR_TPDU; ! 823: ! 824: so = tpcb->tp_sock; ! 825: if (so->so_options & SO_ACCEPTCONN) { ! 826: struct tp_pcb *parent_tpcb = tpcb; ! 827: /* ! 828: * Create a socket, tpcb, ll pcb, etc. ! 829: * for this newborn connection, and fill in all the values. ! 830: */ ! 831: IFDEBUG(D_CONN) ! 832: printf("abt to call tp_newsocket(0x%x, 0x%x, 0x%x, 0x%x)\n", ! 833: so, laddr, faddr, cons_channel); ! 834: ENDDEBUG ! 835: if( (so = ! 836: tp_newsocket(so, faddr, cons_channel, ! 837: class_to_use, ! 838: ((tpcb->tp_netservice == IN_CLNS) ? IN_CLNS : ! 839: (dgout_routine == tpcons_output)?ISO_CONS:ISO_CLNS)) ! 840: ) == (struct socket *)0 ) { ! 841: /* note - even if netservice is IN_CLNS, as far as ! 842: * the tp entity is concerned, the only differences ! 843: * are CO vs CL ! 844: */ ! 845: IFDEBUG(D_CONN) ! 846: printf("tp_newsocket returns 0\n"); ! 847: ENDDEBUG ! 848: goto discard; ! 849: clear_parent_tcb: ! 850: tpcb = 0; ! 851: goto respond; ! 852: } ! 853: tpcb = sototpcb(so); ! 854: insque(tpcb, parent_tpcb); ! 855: ! 856: /* ! 857: * Stash the addresses in the net level pcb ! 858: * kind of like a pcbconnect() but don't need ! 859: * or want all those checks. ! 860: */ ! 861: (tpcb->tp_nlproto->nlp_putnetaddr)(tpcb->tp_npcb, faddr, TP_FOREIGN); ! 862: (tpcb->tp_nlproto->nlp_putnetaddr)(tpcb->tp_npcb, laddr, TP_LOCAL); ! 863: ! 864: /* stash the f suffix in the new tpcb */ ! 865: if (tpcb->tp_fsuffixlen = fsufxlen) { ! 866: bcopy(fsufxloc, tpcb->tp_fsuffix, fsufxlen); ! 867: (tpcb->tp_nlproto->nlp_putsufx) ! 868: (tpcb->tp_npcb, fsufxloc, fsufxlen, TP_FOREIGN); ! 869: } ! 870: /* stash the l suffix in the new tpcb */ ! 871: tpcb->tp_lsuffixlen = lsufxlen; ! 872: bcopy(lsufxloc, tpcb->tp_lsuffix, lsufxlen); ! 873: (tpcb->tp_nlproto->nlp_putsufx) ! 874: (tpcb->tp_npcb, lsufxloc, lsufxlen, TP_LOCAL); ! 875: #ifdef TP_PERF_MEAS ! 876: if( tpcb->tp_perf_on = perf_meas ) { /* assignment */ ! 877: /* ok, let's create an mbuf for stashing the ! 878: * statistics if one doesn't already exist ! 879: */ ! 880: (void) tp_setup_perf(tpcb); ! 881: } ! 882: #endif /* TP_PERF_MEAS */ ! 883: tpcb->tp_fref = sref; ! 884: ! 885: /* We've already checked for consistency with the options ! 886: * set in tpp, but we couldn't set them earlier because ! 887: * we didn't want to change options in the LISTENING tpcb. ! 888: * Now we set the options in the new socket's tpcb. ! 889: */ ! 890: (void) tp_consistency( tpcb, TP_FORCE, &tpp); ! 891: ! 892: if(!tpcb->tp_use_checksum) ! 893: IncStat(ts_csum_off); ! 894: if(tpcb->tp_xpd_service) ! 895: IncStat(ts_use_txpd); ! 896: if(tpcb->tp_xtd_format) ! 897: IncStat(ts_xtd_fmt); ! 898: ! 899: tpcb->tp_peer_acktime = acktime; ! 900: ! 901: /* ! 902: * The following kludge is used to test retransmissions and ! 903: * timeout during connection establishment. ! 904: */ ! 905: IFDEBUG(D_ZDREF) ! 906: IncStat(ts_zdebug); ! 907: /*tpcb->tp_fref = 0;*/ ! 908: ENDDEBUG ! 909: } ! 910: LOCAL_CREDIT(tpcb); ! 911: IncStat(ts_CR_rcvd); ! 912: if (!tpcb->tp_cebit_off) { ! 913: tpcb->tp_win_recv = tp_start_win << 8; ! 914: tpcb->tp_cong_sample.cs_size = 0; ! 915: CONG_INIT_SAMPLE(tpcb); ! 916: CONG_UPDATE_SAMPLE(tpcb, ce_bit); ! 917: } ! 918: } else if ( dutype == ER_TPDU_type ) { ! 919: /* ! 920: * ER TPDUs have to be recognized separately ! 921: * because they don't necessarily have a tpcb ! 922: * with them and we don't want err out looking for such ! 923: * a beast. ! 924: * We could put a bunch of little kludges in the ! 925: * next section of code so it would avoid references to tpcb ! 926: * if dutype == ER_TPDU_type but we don't want code for ERs to ! 927: * mess up code for data transfer. ! 928: */ ! 929: IncStat(ts_ER_rcvd); ! 930: e.ev_number = ER_TPDU; ! 931: e.ATTR(ER_TPDU).e_reason = (u_char)hdr->tpdu_ERreason; ! 932: CHECK (((int)dref <= 0 || dref >= tp_refinfo.tpr_size || ! 933: (tpcb = tp_ref[dref].tpr_pcb ) == (struct tp_pcb *) 0 || ! 934: tpcb->tp_refstate == REF_FREE || ! 935: tpcb->tp_refstate == REF_FROZEN), ! 936: E_TP_MISM_REFS, ts_inv_dref, discard, 0) ! 937: ! 938: } else { ! 939: /* tpdu type is CC, XPD, XAK, GR, AK, DR, DC, or DT */ ! 940: ! 941: /* In the next 4 checks, ! 942: * _tpduf is the fixed part; add 2 to get the dref bits of ! 943: * the fixed part (can't take the address of a bit field) ! 944: */ ! 945: #if TPCONS ! 946: if (cons_channel && dutype == DT_TPDU_type) { ! 947: struct isopcb *isop = ((struct isopcb *) ! 948: ((struct pklcd *)cons_channel)->lcd_upnext); ! 949: if (isop && isop->isop_refcnt == 1 && isop->isop_socket && ! 950: (tpcb = sototpcb(isop->isop_socket)) && ! 951: (tpcb->tp_class == TP_CLASS_0/* || == CLASS_1 */)) { ! 952: IFDEBUG(D_TPINPUT) ! 953: printf("tpinput_dt: class 0 short circuit\n"); ! 954: ENDDEBUG ! 955: dref = tpcb->tp_lref; ! 956: sref = tpcb->tp_fref; ! 957: CHECK( (tpcb->tp_refstate == REF_FREE), ! 958: E_TP_MISM_REFS,ts_inv_dref, nonx_dref, ! 959: (1 + 2 + (caddr_t)&hdr->_tpduf - (caddr_t)hdr)) ! 960: goto tp0_data; ! 961: } ! 962: ! 963: } ! 964: #endif ! 965: { ! 966: ! 967: CHECK( ((int)dref <= 0 || dref >= tp_refinfo.tpr_size) , ! 968: E_TP_MISM_REFS,ts_inv_dref, nonx_dref, ! 969: (1 + 2 + (caddr_t)&hdr->_tpduf - (caddr_t)hdr)) ! 970: CHECK( ((tpcb = tp_ref[dref].tpr_pcb ) == (struct tp_pcb *) 0 ), ! 971: E_TP_MISM_REFS,ts_inv_dref, nonx_dref, ! 972: (1 + 2 + (caddr_t)&hdr->_tpduf - (caddr_t)hdr)) ! 973: CHECK( (tpcb->tp_refstate == REF_FREE), ! 974: E_TP_MISM_REFS,ts_inv_dref, nonx_dref, ! 975: (1 + 2 + (caddr_t)&hdr->_tpduf - (caddr_t)hdr)) ! 976: } ! 977: ! 978: IFDEBUG(D_TPINPUT) ! 979: printf("HAVE A TPCB 2: 0x%x\n", tpcb); ! 980: ENDDEBUG ! 981: ! 982: /* causes a DR to be sent for CC; ER for all else */ ! 983: CHECK( (tpcb->tp_refstate == REF_FROZEN), ! 984: (dutype == CC_TPDU_type?E_TP_NO_SESSION:E_TP_MISM_REFS), ! 985: ts_inv_dref, respond, ! 986: (1 + 2 + (caddr_t)&hdr->_tpduf - (caddr_t)hdr)) ! 987: ! 988: IFDEBUG(D_TPINPUT) ! 989: printf("state of dref %d ok, tpcb 0x%x\n", dref,tpcb); ! 990: ENDDEBUG ! 991: /* ! 992: * At this point the state of the dref could be ! 993: * FROZEN: tpr_pcb == NULL, has ( reference only) timers ! 994: * for example, DC may arrive after the close() has detached ! 995: * the tpcb (e.g., if user turned off SO_LISTEN option) ! 996: * OPENING : a tpcb exists but no timers yet ! 997: * OPEN : tpcb exists & timers are outstanding ! 998: */ ! 999: ! 1000: if (!tpcb->tp_cebit_off) ! 1001: CONG_UPDATE_SAMPLE(tpcb, ce_bit); ! 1002: ! 1003: dusize = tpcb->tp_tpdusize; ! 1004: pdusize = tpcb->tp_ptpdusize; ! 1005: ! 1006: dutype = hdr->tpdu_type << 8; /* for the switch below */ ! 1007: ! 1008: WHILE_OPTIONS(P, hdr, tpcb->tp_xtd_format) /* { */ ! 1009: ! 1010: #define caseof(x,y) case (((x)<<8)+(y)) ! 1011: switch( dutype | vbptr(P)->tpv_code ) { ! 1012: ! 1013: caseof( CC_TPDU_type, TPP_addl_opt ): ! 1014: /* not in class 0; 1 octet */ ! 1015: vb_getval(P, u_char, addlopt); ! 1016: break; ! 1017: caseof( CC_TPDU_type, TPP_tpdu_size ): ! 1018: { ! 1019: u_char odusize = dusize; ! 1020: vb_getval(P, u_char, dusize); ! 1021: CHECK( (dusize < TP_MIN_TPDUSIZE || ! 1022: dusize > TP_MAX_TPDUSIZE || dusize > odusize), ! 1023: E_TP_INV_PVAL, ts_inv_pval, respond, ! 1024: (1 + (caddr_t)&vbptr(P)->tpv_val - (caddr_t)hdr) ) ! 1025: IFDEBUG(D_TPINPUT) ! 1026: printf("CC dusize 0x%x\n", dusize); ! 1027: ENDDEBUG ! 1028: } ! 1029: break; ! 1030: caseof( CC_TPDU_type, TPP_ptpdu_size ): ! 1031: { ! 1032: u_short opdusize = pdusize; ! 1033: switch (vbptr(P)->tpv_len) { ! 1034: case 1: pdusize = vbval(P, u_char); break; ! 1035: case 2: pdusize = ntohs(vbval(P, u_short)); break; ! 1036: default: ; ! 1037: IFDEBUG(D_TPINPUT) ! 1038: printf("malformed prefered TPDU option\n"); ! 1039: ENDDEBUG ! 1040: } ! 1041: CHECK( (pdusize == 0 || ! 1042: (opdusize && (pdusize > opdusize))), ! 1043: E_TP_INV_PVAL, ts_inv_pval, respond, ! 1044: (1 + (caddr_t)&vbptr(P)->tpv_val - (caddr_t)hdr) ) ! 1045: } ! 1046: break; ! 1047: caseof( CC_TPDU_type, TPP_calling_sufx): ! 1048: IFDEBUG(D_TPINPUT) ! 1049: printf("CC calling (local) sufxlen 0x%x\n", lsufxlen); ! 1050: ENDDEBUG ! 1051: lsufxloc = (caddr_t) &vbptr(P)->tpv_val; ! 1052: lsufxlen = vbptr(P)->tpv_len; ! 1053: break; ! 1054: caseof( CC_TPDU_type, TPP_acktime ): ! 1055: /* class 4 only, 2 octets */ ! 1056: vb_getval(P, u_short, acktime); ! 1057: acktime = ntohs(acktime); ! 1058: acktime = acktime/500; /* convert to slowtimo ticks */ ! 1059: if( (short)acktime <=0 ) ! 1060: acktime = 2; ! 1061: break; ! 1062: caseof( CC_TPDU_type, TPP_called_sufx): ! 1063: fsufxloc = (caddr_t) &vbptr(P)->tpv_val; ! 1064: fsufxlen = vbptr(P)->tpv_len; ! 1065: IFDEBUG(D_TPINPUT) ! 1066: printf("CC called (foreign) sufx len %d\n", fsufxlen); ! 1067: ENDDEBUG ! 1068: break; ! 1069: ! 1070: caseof( CC_TPDU_type, TPP_checksum): ! 1071: caseof( DR_TPDU_type, TPP_checksum): ! 1072: caseof( DT_TPDU_type, TPP_checksum): ! 1073: caseof( XPD_TPDU_type, TPP_checksum): ! 1074: if( tpcb->tp_use_checksum ) { ! 1075: CHECK( iso_check_csum(m, tpdu_len), ! 1076: E_TP_INV_PVAL, ts_bad_csum, discard, 0) ! 1077: } ! 1078: break; ! 1079: ! 1080: /* this is different from the above because in the context ! 1081: * of concat/ sep tpdu_len might not be the same as hdr len ! 1082: */ ! 1083: caseof( AK_TPDU_type, TPP_checksum): ! 1084: caseof( XAK_TPDU_type, TPP_checksum): ! 1085: caseof( DC_TPDU_type, TPP_checksum): ! 1086: if( tpcb->tp_use_checksum ) { ! 1087: CHECK( iso_check_csum(m, (int)hdr->tpdu_li + 1), ! 1088: E_TP_INV_PVAL, ts_bad_csum, discard, 0) ! 1089: } ! 1090: break; ! 1091: #ifdef notdef ! 1092: caseof( DR_TPDU_type, TPP_addl_info ): ! 1093: /* ignore - its length and meaning are ! 1094: * user defined and there's no way ! 1095: * to pass this info to the user anyway ! 1096: */ ! 1097: break; ! 1098: #endif /* notdef */ ! 1099: ! 1100: caseof( AK_TPDU_type, TPP_subseq ): ! 1101: /* used after reduction of window */ ! 1102: vb_getval(P, u_short, subseq); ! 1103: subseq = ntohs(subseq); ! 1104: IFDEBUG(D_ACKRECV) ! 1105: printf("AK dref 0x%x Subseq 0x%x\n", dref, subseq); ! 1106: ENDDEBUG ! 1107: break; ! 1108: ! 1109: caseof( AK_TPDU_type, TPP_flow_cntl_conf ): ! 1110: { ! 1111: u_int ylwe; ! 1112: u_short ysubseq, ycredit; ! 1113: ! 1114: fcc_present = TRUE; ! 1115: vb_getval(P, u_int, ylwe); ! 1116: vb_getval(P, u_short, ysubseq); ! 1117: vb_getval(P, u_short, ycredit); ! 1118: ylwe = ntohl(ylwe); ! 1119: ysubseq = ntohs(ysubseq); ! 1120: ycredit = ntohs(ycredit); ! 1121: IFDEBUG(D_ACKRECV) ! 1122: printf("%s%x, subseq 0x%x, cdt 0x%x dref 0x%x\n", ! 1123: "AK FCC lwe 0x", ylwe, ysubseq, ycredit, dref); ! 1124: ENDDEBUG ! 1125: } ! 1126: break; ! 1127: ! 1128: default: ! 1129: IFDEBUG(D_TPINPUT) ! 1130: printf("param ignored dutype 0x%x, code 0x%x\n", ! 1131: dutype, vbptr(P)->tpv_code); ! 1132: ENDDEBUG ! 1133: IFTRACE(D_TPINPUT) ! 1134: tptrace(TPPTmisc, "param ignored dutype code ", ! 1135: dutype, vbptr(P)->tpv_code ,0,0); ! 1136: ENDTRACE ! 1137: IncStat(ts_param_ignored); ! 1138: break; ! 1139: #undef caseof ! 1140: } ! 1141: /* } */ END_WHILE_OPTIONS(P) ! 1142: ! 1143: /* NOTE: the variable dutype has been shifted left! */ ! 1144: ! 1145: switch( hdr->tpdu_type ) { ! 1146: case CC_TPDU_type: ! 1147: /* If CC comes back with an unacceptable class ! 1148: * respond with a DR or ER ! 1149: */ ! 1150: ! 1151: opt = hdr->tpdu_CCoptions; /* 1 byte */ ! 1152: ! 1153: { ! 1154: tpp = tpcb->_tp_param; ! 1155: tpp.p_class = (1<<hdr->tpdu_CCclass); ! 1156: tpp.p_tpdusize = dusize; ! 1157: tpp.p_ptpdusize = pdusize; ! 1158: tpp.p_dont_change_params = 0; ! 1159: tpp.p_xtd_format = (opt & TPO_XTD_FMT) == TPO_XTD_FMT; ! 1160: tpp.p_xpd_service = (addlopt & TPAO_USE_TXPD) == TPAO_USE_TXPD; ! 1161: tpp.p_use_checksum = (addlopt & TPAO_NO_CSUM) == 0; ! 1162: #ifdef notdef ! 1163: tpp.p_use_efc = (opt & TPO_USE_EFC) == TPO_USE_EFC; ! 1164: tpp.p_use_nxpd = (addlopt & TPAO_USE_NXPD) == TPAO_USE_NXPD; ! 1165: tpp.p_use_rcc = (addlopt & TPAO_USE_RCC) == TPAO_USE_RCC; ! 1166: #endif /* notdef */ ! 1167: ! 1168: CHECK( ! 1169: tp_consistency(tpcb, TP_FORCE, &tpp) != 0, ! 1170: E_TP_NEGOT_FAILED, ts_negotfailed, respond, ! 1171: (1 + 2 + (caddr_t)&hdr->_tpdufr.CRCC - (caddr_t)hdr) ! 1172: /* ^ more or less the location of class */ ! 1173: ) ! 1174: IFTRACE(D_CONN) ! 1175: tptrace(TPPTmisc, ! 1176: "after 1 consist class, out, tpconsout", ! 1177: tpcb->tp_class, dgout_routine, tpcons_output, 0 ! 1178: ); ! 1179: ENDTRACE ! 1180: CHECK( ! 1181: ((class_to_use == TP_CLASS_0)&& ! 1182: (dgout_routine != tpcons_output)), ! 1183: E_TP_NEGOT_FAILED, ts_negotfailed, respond, ! 1184: (1 + 2 + (caddr_t)&hdr->_tpdufr.CRCC - (caddr_t)hdr) ! 1185: /* ^ more or less the location of class */ ! 1186: ) ! 1187: #if TPCONS ! 1188: if (tpcb->tp_netservice == ISO_CONS && ! 1189: class_to_use == TP_CLASS_0) { ! 1190: struct isopcb *isop = (struct isopcb *)tpcb->tp_npcb; ! 1191: struct pklcd *lcp = (struct pklcd *)isop->isop_chan; ! 1192: lcp->lcd_flags &= ~X25_DG_CIRCUIT; ! 1193: } ! 1194: #endif ! 1195: } ! 1196: if( ! tpcb->tp_use_checksum) ! 1197: IncStat(ts_csum_off); ! 1198: if(tpcb->tp_xpd_service) ! 1199: IncStat(ts_use_txpd); ! 1200: if(tpcb->tp_xtd_format) ! 1201: IncStat(ts_xtd_fmt); ! 1202: ! 1203: IFTRACE(D_CONN) ! 1204: tptrace(TPPTmisc, "after CC class flags dusize CCclass", ! 1205: tpcb->tp_class, tpcb->tp_flags, tpcb->tp_tpdusize, ! 1206: hdr->tpdu_CCclass); ! 1207: ENDTRACE ! 1208: ! 1209: /* if called or calling suffices appeared on the CC, ! 1210: * they'd better jive with what's in the pcb ! 1211: */ ! 1212: if( fsufxlen ) { ! 1213: CHECK( ((tpcb->tp_fsuffixlen != fsufxlen) || ! 1214: bcmp(fsufxloc, tpcb->tp_fsuffix, fsufxlen)), ! 1215: E_TP_INV_PVAL,ts_inv_sufx, respond, ! 1216: (1+fsufxloc - (caddr_t)hdr)) ! 1217: } ! 1218: if( lsufxlen ) { ! 1219: CHECK( ((tpcb->tp_lsuffixlen != lsufxlen) || ! 1220: bcmp(lsufxloc, tpcb->tp_lsuffix, lsufxlen)), ! 1221: E_TP_INV_PVAL,ts_inv_sufx, respond, ! 1222: (1+lsufxloc - (caddr_t)hdr)) ! 1223: } ! 1224: ! 1225: e.ATTR(CC_TPDU).e_sref = sref; ! 1226: e.ATTR(CC_TPDU).e_cdt = hdr->tpdu_CCcdt; ! 1227: takes_data = TRUE; ! 1228: e.ev_number = CC_TPDU; ! 1229: IncStat(ts_CC_rcvd); ! 1230: break; ! 1231: ! 1232: case DC_TPDU_type: ! 1233: if (sref != tpcb->tp_fref) ! 1234: printf("INPUT: inv sufx DCsref 0x%x, tp_fref 0x%x\n", ! 1235: sref, tpcb->tp_fref); ! 1236: ! 1237: CHECK( (sref != tpcb->tp_fref), ! 1238: E_TP_MISM_REFS, ts_inv_sufx, discard, ! 1239: (1 + (caddr_t)&hdr->tpdu_DCsref - (caddr_t)hdr)) ! 1240: ! 1241: e.ev_number = DC_TPDU; ! 1242: IncStat(ts_DC_rcvd); ! 1243: break; ! 1244: ! 1245: case DR_TPDU_type: ! 1246: IFTRACE(D_TPINPUT) ! 1247: tptrace(TPPTmisc, "DR recvd", hdr->tpdu_DRreason, 0, 0, 0); ! 1248: ENDTRACE ! 1249: if (sref != tpcb->tp_fref) { ! 1250: printf("INPUT: inv sufx DRsref 0x%x tp_fref 0x%x\n", ! 1251: sref, tpcb->tp_fref); ! 1252: } ! 1253: ! 1254: CHECK( (sref != 0 && sref != tpcb->tp_fref && ! 1255: tpcb->tp_state != TP_CRSENT), ! 1256: (TP_ERROR_SNDC | E_TP_MISM_REFS),ts_inv_sufx, respond, ! 1257: (1 + (caddr_t)&hdr->tpdu_DRsref - (caddr_t)hdr)) ! 1258: ! 1259: e.ATTR(DR_TPDU).e_reason = hdr->tpdu_DRreason; ! 1260: e.ATTR(DR_TPDU).e_sref = (u_short)sref; ! 1261: takes_data = TRUE; ! 1262: e.ev_number = DR_TPDU; ! 1263: IncStat(ts_DR_rcvd); ! 1264: break; ! 1265: ! 1266: case ER_TPDU_type: ! 1267: IFTRACE(D_TPINPUT) ! 1268: tptrace(TPPTmisc, "ER recvd", hdr->tpdu_ERreason,0,0,0); ! 1269: ENDTRACE ! 1270: e.ev_number = ER_TPDU; ! 1271: e.ATTR(ER_TPDU).e_reason = hdr->tpdu_ERreason; ! 1272: IncStat(ts_ER_rcvd); ! 1273: break; ! 1274: ! 1275: case AK_TPDU_type: ! 1276: ! 1277: e.ATTR(AK_TPDU).e_subseq = subseq; ! 1278: e.ATTR(AK_TPDU).e_fcc_present = fcc_present; ! 1279: ! 1280: if (tpcb->tp_xtd_format) { ! 1281: #ifdef BYTE_ORDER ! 1282: union seq_type seqeotX; ! 1283: ! 1284: seqeotX.s_seqeot = ntohl(hdr->tpdu_seqeotX); ! 1285: e.ATTR(AK_TPDU).e_seq = seqeotX.s_seq; ! 1286: e.ATTR(AK_TPDU).e_cdt = ntohs(hdr->tpdu_AKcdtX); ! 1287: #else ! 1288: e.ATTR(AK_TPDU).e_cdt = hdr->tpdu_AKcdtX; ! 1289: e.ATTR(AK_TPDU).e_seq = hdr->tpdu_AKseqX; ! 1290: #endif /* BYTE_ORDER */ ! 1291: } else { ! 1292: e.ATTR(AK_TPDU).e_cdt = hdr->tpdu_AKcdt; ! 1293: e.ATTR(AK_TPDU).e_seq = hdr->tpdu_AKseq; ! 1294: } ! 1295: IFTRACE(D_TPINPUT) ! 1296: tptrace(TPPTmisc, "AK recvd seq cdt subseq fcc_pres", ! 1297: e.ATTR(AK_TPDU).e_seq, e.ATTR(AK_TPDU).e_cdt, ! 1298: subseq, fcc_present); ! 1299: ENDTRACE ! 1300: ! 1301: e.ev_number = AK_TPDU; ! 1302: IncStat(ts_AK_rcvd); ! 1303: IncPStat(tpcb, tps_AK_rcvd); ! 1304: break; ! 1305: ! 1306: case XAK_TPDU_type: ! 1307: if (tpcb->tp_xtd_format) { ! 1308: #ifdef BYTE_ORDER ! 1309: union seq_type seqeotX; ! 1310: ! 1311: seqeotX.s_seqeot = ntohl(hdr->tpdu_seqeotX); ! 1312: e.ATTR(XAK_TPDU).e_seq = seqeotX.s_seq; ! 1313: #else ! 1314: e.ATTR(XAK_TPDU).e_seq = hdr->tpdu_XAKseqX; ! 1315: #endif /* BYTE_ORDER */ ! 1316: } else { ! 1317: e.ATTR(XAK_TPDU).e_seq = hdr->tpdu_XAKseq; ! 1318: } ! 1319: e.ev_number = XAK_TPDU; ! 1320: IncStat(ts_XAK_rcvd); ! 1321: IncPStat(tpcb, tps_XAK_rcvd); ! 1322: break; ! 1323: ! 1324: case XPD_TPDU_type: ! 1325: if (tpcb->tp_xtd_format) { ! 1326: #ifdef BYTE_ORDER ! 1327: union seq_type seqeotX; ! 1328: ! 1329: seqeotX.s_seqeot = ntohl(hdr->tpdu_seqeotX); ! 1330: e.ATTR(XPD_TPDU).e_seq = seqeotX.s_seq; ! 1331: #else ! 1332: e.ATTR(XPD_TPDU).e_seq = hdr->tpdu_XPDseqX; ! 1333: #endif /* BYTE_ORDER */ ! 1334: } else { ! 1335: e.ATTR(XPD_TPDU).e_seq = hdr->tpdu_XPDseq; ! 1336: } ! 1337: takes_data = TRUE; ! 1338: e.ev_number = XPD_TPDU; ! 1339: IncStat(ts_XPD_rcvd); ! 1340: IncPStat(tpcb, tps_XPD_rcvd); ! 1341: break; ! 1342: ! 1343: case DT_TPDU_type: ! 1344: { /* the y option will cause occasional packets to be dropped. ! 1345: * A little crude but it works. ! 1346: */ ! 1347: ! 1348: IFDEBUG(D_DROP) ! 1349: if(time.tv_usec & 0x4 && hdr->tpdu_DTseq & 0x1) { ! 1350: IncStat(ts_ydebug); ! 1351: goto discard; ! 1352: } ! 1353: ENDDEBUG ! 1354: } ! 1355: if (tpcb->tp_class == TP_CLASS_0) { ! 1356: tp0_data: ! 1357: e.ATTR(DT_TPDU).e_seq = 0; /* actually don't care */ ! 1358: e.ATTR(DT_TPDU).e_eot = (((struct tp0du *)hdr)->tp0du_eot); ! 1359: } else if (tpcb->tp_xtd_format) { ! 1360: #ifdef BYTE_ORDER ! 1361: union seq_type seqeotX; ! 1362: ! 1363: seqeotX.s_seqeot = ntohl(hdr->tpdu_seqeotX); ! 1364: e.ATTR(DT_TPDU).e_seq = seqeotX.s_seq; ! 1365: e.ATTR(DT_TPDU).e_eot = seqeotX.s_eot; ! 1366: #else ! 1367: e.ATTR(DT_TPDU).e_seq = hdr->tpdu_DTseqX; ! 1368: e.ATTR(DT_TPDU).e_eot = hdr->tpdu_DTeotX; ! 1369: #endif /* BYTE_ORDER */ ! 1370: } else { ! 1371: e.ATTR(DT_TPDU).e_seq = hdr->tpdu_DTseq; ! 1372: e.ATTR(DT_TPDU).e_eot = hdr->tpdu_DTeot; ! 1373: } ! 1374: if(e.ATTR(DT_TPDU).e_eot) ! 1375: IncStat(ts_eot_input); ! 1376: takes_data = TRUE; ! 1377: e.ev_number = DT_TPDU; ! 1378: IncStat(ts_DT_rcvd); ! 1379: IncPStat(tpcb, tps_DT_rcvd); ! 1380: break; ! 1381: ! 1382: case GR_TPDU_type: ! 1383: tp_indicate(T_DISCONNECT, tpcb, ECONNABORTED); ! 1384: /* drop through */ ! 1385: default: ! 1386: /* this should NEVER happen because there is a ! 1387: * check for dutype well above here ! 1388: */ ! 1389: error = E_TP_INV_TPDU; /* causes an ER */ ! 1390: IFDEBUG(D_TPINPUT) ! 1391: printf("INVALID dutype 0x%x\n", hdr->tpdu_type); ! 1392: ENDDEBUG ! 1393: IncStat(ts_inv_dutype); ! 1394: goto respond; ! 1395: } ! 1396: } ! 1397: /* peel off the tp header; ! 1398: * remember that the du_li doesn't count itself. ! 1399: * This may leave us w/ an empty mbuf at the front of a chain. ! 1400: * We can't just throw away the empty mbuf because hdr still points ! 1401: * into the mbuf's data area and we're still using hdr (the tpdu header) ! 1402: */ ! 1403: m->m_len -= ((int)hdr->tpdu_li + 1); ! 1404: m->m_data += ((int)hdr->tpdu_li + 1); ! 1405: ! 1406: if (takes_data) { ! 1407: int max = tpdu_info[ hdr->tpdu_type ] [TP_MAX_DATA_INDEX]; ! 1408: int datalen = tpdu_len - hdr->tpdu_li - 1, mbtype = MT_DATA; ! 1409: struct { ! 1410: struct tp_disc_reason dr; ! 1411: struct cmsghdr x_hdr; ! 1412: } x; ! 1413: #define c_hdr x.x_hdr ! 1414: register struct mbuf *n; ! 1415: ! 1416: CHECK( (max && datalen > max), E_TP_LENGTH_INVAL, ! 1417: ts_inv_length, respond, (max + hdr->tpdu_li + 1) ); ! 1418: switch( hdr->tpdu_type ) { ! 1419: ! 1420: case CR_TPDU_type: ! 1421: c_hdr.cmsg_type = TPOPT_CONN_DATA; ! 1422: goto make_control_msg; ! 1423: ! 1424: case CC_TPDU_type: ! 1425: c_hdr.cmsg_type = TPOPT_CFRM_DATA; ! 1426: goto make_control_msg; ! 1427: ! 1428: case DR_TPDU_type: ! 1429: x.dr.dr_hdr.cmsg_len = sizeof(x) - sizeof(c_hdr); ! 1430: x.dr.dr_hdr.cmsg_type = TPOPT_DISC_REASON; ! 1431: x.dr.dr_hdr.cmsg_level = SOL_TRANSPORT; ! 1432: x.dr.dr_reason = hdr->tpdu_DRreason; ! 1433: c_hdr.cmsg_type = TPOPT_DISC_DATA; ! 1434: make_control_msg: ! 1435: datalen += sizeof(c_hdr); ! 1436: c_hdr.cmsg_len = datalen; ! 1437: c_hdr.cmsg_level = SOL_TRANSPORT; ! 1438: mbtype = MT_CONTROL; ! 1439: MGET(n, M_DONTWAIT, MT_DATA); ! 1440: if (n == 0) ! 1441: {m_freem(m); m = 0; datalen = 0; goto invoke; } ! 1442: if (hdr->tpdu_type == DR_TPDU_type) { ! 1443: datalen += sizeof(x) - sizeof(c_hdr); ! 1444: bcopy((caddr_t)&x, mtod(n, caddr_t), n->m_len = sizeof(x)); ! 1445: } else ! 1446: bcopy((caddr_t)&c_hdr, mtod(n, caddr_t), ! 1447: n->m_len = sizeof(c_hdr)); ! 1448: n->m_next = m; ! 1449: m = n; ! 1450: /* FALLTHROUGH */ ! 1451: ! 1452: case XPD_TPDU_type: ! 1453: if (mbtype != MT_CONTROL) ! 1454: mbtype = MT_OOBDATA; ! 1455: m->m_flags |= M_EOR; ! 1456: /* FALLTHROUGH */ ! 1457: ! 1458: case DT_TPDU_type: ! 1459: for (n = m; n; n = n->m_next) { ! 1460: MCHTYPE(n, mbtype); ! 1461: } ! 1462: invoke: ! 1463: e.ATTR(DT_TPDU).e_datalen = datalen; ! 1464: e.ATTR(DT_TPDU).e_data = m; ! 1465: break; ! 1466: ! 1467: default: ! 1468: printf( ! 1469: "ERROR in tp_input! hdr->tpdu_type 0x%x takes_data 0x%x m 0x%x\n", ! 1470: hdr->tpdu_type, takes_data, m); ! 1471: break; ! 1472: } ! 1473: /* prevent m_freem() after tp_driver() from throwing it all away */ ! 1474: m = MNULL; ! 1475: } ! 1476: ! 1477: IncStat(ts_tpdu_rcvd); ! 1478: ! 1479: IFDEBUG(D_TPINPUT) ! 1480: printf( "tp_input: before driver, state 0x%x event 0x%x m 0x%x", ! 1481: tpcb->tp_state, e.ev_number, m ); ! 1482: printf(" e.e_data 0x%x\n", e.ATTR(DT_TPDU).e_data); ! 1483: printf("takes_data 0x%x m_len 0x%x, tpdu_len 0x%x\n", ! 1484: takes_data, (m==MNULL)?0:m->m_len, tpdu_len); ! 1485: ENDDEBUG ! 1486: ! 1487: error = tp_driver(tpcb, &e); ! 1488: ! 1489: ASSERT(tpcb != (struct tp_pcb *)0); ! 1490: ASSERT(tpcb->tp_sock != (struct socket *)0); ! 1491: if( tpcb->tp_sock->so_error == 0 ) ! 1492: tpcb->tp_sock->so_error = error; ! 1493: ! 1494: /* Kludge to keep the state tables under control (adding ! 1495: * data on connect & disconnect & freeing the mbuf containing ! 1496: * the data would have exploded the tables and made a big mess ). ! 1497: */ ! 1498: switch(e.ev_number) { ! 1499: case CC_TPDU: ! 1500: case DR_TPDU: ! 1501: case CR_TPDU: ! 1502: m = e.ATTR(CC_TPDU).e_data; /* same field for all three dutypes */ ! 1503: IFDEBUG(D_TPINPUT) ! 1504: printf("after driver, restoring m to 0x%x, takes_data 0x%x\n", ! 1505: m, takes_data); ! 1506: ENDDEBUG ! 1507: break; ! 1508: default: ! 1509: break; ! 1510: } ! 1511: /* Concatenated sequences are terminated by any tpdu that ! 1512: * carries data: CR, CC, DT, XPD, DR. ! 1513: * All other tpdu types may be concatenated: AK, XAK, DC, ER. ! 1514: */ ! 1515: ! 1516: separate: ! 1517: if ( takes_data == 0 ) { ! 1518: ASSERT( m != MNULL ); ! 1519: /* ! 1520: * we already peeled off the prev. tp header so ! 1521: * we can just pull up some more and repeat ! 1522: */ ! 1523: ! 1524: if( m = tp_inputprep(m) ) { ! 1525: IFDEBUG(D_TPINPUT) ! 1526: hdr = mtod(m, struct tpdu *); ! 1527: printf("tp_input @ separate: hdr 0x%x size %d m 0x%x\n", ! 1528: hdr, (int) hdr->tpdu_li + 1, m); ! 1529: dump_mbuf(m, "tp_input after driver, at separate"); ! 1530: ENDDEBUG ! 1531: ! 1532: IncStat(ts_concat_rcvd); ! 1533: goto again; ! 1534: } ! 1535: } ! 1536: if ( m != MNULL ) { ! 1537: IFDEBUG(D_TPINPUT) ! 1538: printf("tp_input : m_freem(0x%x)\n", m); ! 1539: ENDDEBUG ! 1540: m_freem(m); ! 1541: IFDEBUG(D_TPINPUT) ! 1542: printf("tp_input : after m_freem 0x%x\n", m); ! 1543: ENDDEBUG ! 1544: } ! 1545: return (ProtoHook) tpcb; ! 1546: ! 1547: discard: ! 1548: /* class 4: drop the tpdu */ ! 1549: /* class 2,0: Should drop the net connection, if you can figure out ! 1550: * to which connection it applies ! 1551: */ ! 1552: IFDEBUG(D_TPINPUT) ! 1553: printf("tp_input DISCARD\n"); ! 1554: ENDDEBUG ! 1555: IFTRACE(D_TPINPUT) ! 1556: tptrace(TPPTmisc, "tp_input DISCARD m", m,0,0,0); ! 1557: ENDTRACE ! 1558: m_freem(m); ! 1559: IncStat(ts_recv_drop); ! 1560: return (ProtoHook)0; ! 1561: ! 1562: nonx_dref: ! 1563: switch (dutype) { ! 1564: default: ! 1565: goto discard; ! 1566: case CC_TPDU_type: ! 1567: /* error = E_TP_MISM_REFS; */ ! 1568: break; ! 1569: case DR_TPDU_type: ! 1570: error |= TP_ERROR_SNDC; ! 1571: } ! 1572: respond: ! 1573: IFDEBUG(D_TPINPUT) ! 1574: printf("RESPOND: error 0x%x, errlen 0x%x\n", error, errlen); ! 1575: ENDDEBUG ! 1576: IFTRACE(D_TPINPUT) ! 1577: tptrace(TPPTmisc, "tp_input RESPOND m error sref", m, error, sref, 0); ! 1578: ENDTRACE ! 1579: if (sref == 0) ! 1580: goto discard; ! 1581: (void) tp_error_emit(error, (u_long)sref, (struct sockaddr_iso *)faddr, ! 1582: (struct sockaddr_iso *)laddr, m, errlen, tpcb, ! 1583: cons_channel, dgout_routine); ! 1584: IFDEBUG(D_ERROR_EMIT) ! 1585: printf("tp_input after error_emit\n"); ! 1586: ENDDEBUG ! 1587: ! 1588: #ifdef lint ! 1589: printf("",sref,opt); ! 1590: #endif /* lint */ ! 1591: IncStat(ts_recv_drop); ! 1592: return (ProtoHook)0; ! 1593: } ! 1594: ! 1595: ! 1596: /* ! 1597: * NAME: tp_headersize() ! 1598: * ! 1599: * CALLED FROM: ! 1600: * tp_emit() and tp_sbsend() ! 1601: * TP needs to know the header size so it can figure out how ! 1602: * much data to put in each tpdu. ! 1603: * ! 1604: * FUNCTION, ARGUMENTS, and RETURN VALUE: ! 1605: * For a given connection, represented by (tpcb), and ! 1606: * tpdu type (dutype), return the size of a tp header. ! 1607: * ! 1608: * RETURNS: the expected size of the heade in bytesr ! 1609: * ! 1610: * SIDE EFFECTS: ! 1611: * ! 1612: * NOTES: It would be nice if it got the network header size as well. ! 1613: */ ! 1614: int ! 1615: tp_headersize(dutype, tpcb) ! 1616: int dutype; ! 1617: struct tp_pcb *tpcb; ! 1618: { ! 1619: register int size = 0; ! 1620: ! 1621: IFTRACE(D_CONN) ! 1622: tptrace(TPPTmisc, "tp_headersize dutype class xtd_format", ! 1623: dutype, tpcb->tp_class, tpcb->tp_xtd_format, 0); ! 1624: ENDTRACE ! 1625: if( !( (tpcb->tp_class == TP_CLASS_0) || ! 1626: (tpcb->tp_class == TP_CLASS_4) || ! 1627: (dutype == DR_TPDU_type) || ! 1628: (dutype == CR_TPDU_type) )) { ! 1629: printf("tp_headersize:dutype 0x%x, class 0x%x", ! 1630: dutype, tpcb->tp_class); ! 1631: /* TODO: identify this and GET RID OF IT */ ! 1632: } ! 1633: ASSERT( (tpcb->tp_class == TP_CLASS_0) || ! 1634: (tpcb->tp_class == TP_CLASS_4) || ! 1635: (dutype == DR_TPDU_type) || ! 1636: (dutype == CR_TPDU_type) ); ! 1637: ! 1638: if( tpcb->tp_class == TP_CLASS_0 ) { ! 1639: size = tpdu_info[ dutype ] [TP_LEN_CLASS_0_INDEX]; ! 1640: } else { ! 1641: size = tpdu_info[ dutype ] [tpcb->tp_xtd_format]; ! 1642: } ! 1643: return size; ! 1644: /* caller must get network level header size separately */ ! 1645: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.