|
|
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_subr2.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: * Some auxiliary routines: ! 90: * tp_protocol_error: required by xebec- called when a combo of state, ! 91: * event, predicate isn't covered for by the transition file. ! 92: * tp_indicate: gives indications(signals) to the user process ! 93: * tp_getoptions: initializes variables that are affected by the options ! 94: * chosen. ! 95: */ ! 96: ! 97: /* this def'n is to cause the expansion of this macro in the ! 98: * routine tp_local_credit : ! 99: */ ! 100: #define LOCAL_CREDIT_EXPAND ! 101: ! 102: #include <sys/param.h> ! 103: #include <sys/systm.h> ! 104: #include <sys/mbuf.h> ! 105: #include <sys/socket.h> ! 106: #include <sys/socketvar.h> ! 107: #include <sys/domain.h> ! 108: #include <sys/protosw.h> ! 109: #include <sys/errno.h> ! 110: #include <sys/time.h> ! 111: #include <sys/kernel.h> ! 112: ! 113: #undef MNULL ! 114: #include <netiso/argo_debug.h> ! 115: #include <netiso/tp_param.h> ! 116: #include <netiso/tp_ip.h> ! 117: #include <netiso/iso.h> ! 118: #include <netiso/iso_errno.h> ! 119: #include <netiso/iso_pcb.h> ! 120: #include <netiso/tp_timer.h> ! 121: #include <netiso/tp_stat.h> ! 122: #include <netiso/tp_tpdu.h> ! 123: #include <netiso/tp_pcb.h> ! 124: #include <netiso/tp_seq.h> ! 125: #include <netiso/tp_trace.h> ! 126: #include <netiso/tp_user.h> ! 127: #include <netiso/cons.h> ! 128: ! 129: #include <net/if.h> ! 130: #include <net/if_types.h> ! 131: #ifdef TRUE ! 132: #undef FALSE ! 133: #undef TRUE ! 134: #endif ! 135: #include <netccitt/x25.h> ! 136: #include <netccitt/pk.h> ! 137: #include <netccitt/pk_var.h> ! 138: ! 139: void tp_rsyset(); ! 140: ! 141: /* ! 142: * NAME: tp_local_credit() ! 143: * ! 144: * CALLED FROM: ! 145: * tp_emit(), tp_usrreq() ! 146: * ! 147: * FUNCTION and ARGUMENTS: ! 148: * Computes the local credit and stashes it in tpcb->tp_lcredit. ! 149: * It's a macro in the production system rather than a procdure. ! 150: * ! 151: * RETURNS: ! 152: * ! 153: * SIDE EFFECTS: ! 154: * ! 155: * NOTES: ! 156: * This doesn't actually get called in a production system - ! 157: * the macro gets expanded instead in place of calls to this proc. ! 158: * But for debugging, we call this and that allows us to add ! 159: * debugging messages easily here. ! 160: */ ! 161: void ! 162: tp_local_credit(tpcb) ! 163: struct tp_pcb *tpcb; ! 164: { ! 165: LOCAL_CREDIT(tpcb); ! 166: IFDEBUG(D_CREDIT) ! 167: printf("ref 0x%x lcdt 0x%x l_tpdusize 0x%x decbit 0x%x\n", ! 168: tpcb->tp_lref, ! 169: tpcb->tp_lcredit, ! 170: tpcb->tp_l_tpdusize, ! 171: tpcb->tp_decbit, ! 172: tpcb->tp_cong_win ! 173: ); ! 174: ENDDEBUG ! 175: IFTRACE(D_CREDIT) ! 176: tptraceTPCB(TPPTmisc, ! 177: "lcdt tpdusz \n", ! 178: tpcb->tp_lcredit, tpcb->tp_l_tpdusize, 0, 0); ! 179: ENDTRACE ! 180: } ! 181: ! 182: /* ! 183: * NAME: tp_protocol_error() ! 184: * ! 185: * CALLED FROM: ! 186: * tp_driver(), when it doesn't know what to do with ! 187: * a combo of event, state, predicate ! 188: * ! 189: * FUNCTION and ARGUMENTS: ! 190: * print error mesg ! 191: * ! 192: * RETURN VALUE: ! 193: * EIO - always ! 194: * ! 195: * SIDE EFFECTS: ! 196: * ! 197: * NOTES: ! 198: */ ! 199: int ! 200: tp_protocol_error(e,tpcb) ! 201: struct tp_event *e; ! 202: struct tp_pcb *tpcb; ! 203: { ! 204: printf("TP PROTOCOL ERROR! tpcb 0x%x event 0x%x, state 0x%x\n", ! 205: tpcb, e->ev_number, tpcb->tp_state); ! 206: IFTRACE(D_DRIVER) ! 207: tptraceTPCB(TPPTmisc, "PROTOCOL ERROR tpcb event state", ! 208: tpcb, e->ev_number, tpcb->tp_state, 0 ); ! 209: ENDTRACE ! 210: return EIO; /* for lack of anything better */ ! 211: } ! 212: ! 213: ! 214: /* Not used at the moment */ ! 215: ProtoHook ! 216: tp_drain() ! 217: { ! 218: return 0; ! 219: } ! 220: ! 221: ! 222: /* ! 223: * NAME: tp_indicate() ! 224: * ! 225: * CALLED FROM: ! 226: * tp.trans when XPD arrive, when a connection is being disconnected by ! 227: * the arrival of a DR or ER, and when a connection times out. ! 228: * ! 229: * FUNCTION and ARGUMENTS: ! 230: * (ind) is the type of indication : T_DISCONNECT, T_XPD ! 231: * (error) is an E* value that will be put in the socket structure ! 232: * to be passed along to the user later. ! 233: * Gives a SIGURG to the user process or group indicated by the socket ! 234: * attached to the tpcb. ! 235: * ! 236: * RETURNS: Rien ! 237: * ! 238: * SIDE EFFECTS: ! 239: * ! 240: * NOTES: ! 241: */ ! 242: void ! 243: tp_indicate(ind, tpcb, error) ! 244: int ind; ! 245: u_short error; ! 246: register struct tp_pcb *tpcb; ! 247: { ! 248: register struct socket *so = tpcb->tp_sock; ! 249: IFTRACE(D_INDICATION) ! 250: tptraceTPCB(TPPTindicate, ind, *(u_short *)(tpcb->tp_lsuffix), ! 251: *(u_short *)(tpcb->tp_fsuffix), error,so->so_pgid); ! 252: ENDTRACE ! 253: IFDEBUG(D_INDICATION) ! 254: char *ls, *fs; ! 255: ls = tpcb->tp_lsuffix, ! 256: fs = tpcb->tp_fsuffix, ! 257: ! 258: printf( ! 259: "indicate 0x%x lsuf 0x%02x%02x fsuf 0x%02x%02x err 0x%x noind 0x%x ref 0x%x\n", ! 260: ind, ! 261: *ls, *(ls+1), *fs, *(fs+1), ! 262: error, /*so->so_pgrp,*/ ! 263: tpcb->tp_no_disc_indications, ! 264: tpcb->tp_lref); ! 265: ENDDEBUG ! 266: ! 267: if (ind == ER_TPDU) { ! 268: register struct mbuf *m; ! 269: struct tp_disc_reason x; ! 270: ! 271: if ((so->so_state & SS_CANTRCVMORE) == 0 && ! 272: (m = m_get(M_DONTWAIT, MT_OOBDATA)) != 0) { ! 273: ! 274: x.dr_hdr.cmsg_len = m->m_len = sizeof(x); ! 275: x.dr_hdr.cmsg_level = SOL_TRANSPORT; ! 276: x.dr_hdr.cmsg_type= TPOPT_DISC_REASON; ! 277: x.dr_reason = error; ! 278: *mtod(m, struct tp_disc_reason *) = x; ! 279: sbappendrecord(&tpcb->tp_Xrcv, m); ! 280: error = 0; ! 281: } else ! 282: error = ECONNRESET; ! 283: } ! 284: so->so_error = error; ! 285: ! 286: if (ind == T_DISCONNECT) { ! 287: if (error == 0) ! 288: so->so_error = ENOTCONN; ! 289: if ( tpcb->tp_no_disc_indications ) ! 290: return; ! 291: } ! 292: IFTRACE(D_INDICATION) ! 293: tptraceTPCB(TPPTmisc, "doing sohasoutofband(so)", so,0,0,0); ! 294: ENDTRACE ! 295: sohasoutofband(so); ! 296: } ! 297: ! 298: /* ! 299: * NAME : tp_getoptions() ! 300: * ! 301: * CALLED FROM: ! 302: * tp.trans whenever we go into OPEN state ! 303: * ! 304: * FUNCTION and ARGUMENTS: ! 305: * sets the proper flags and values in the tpcb, to control ! 306: * the appropriate actions for the given class, options, ! 307: * sequence space, etc, etc. ! 308: * ! 309: * RETURNS: Nada ! 310: * ! 311: * SIDE EFFECTS: ! 312: * ! 313: * NOTES: ! 314: */ ! 315: void ! 316: tp_getoptions(tpcb) ! 317: struct tp_pcb *tpcb; ! 318: { ! 319: tpcb->tp_seqmask = ! 320: tpcb->tp_xtd_format ? TP_XTD_FMT_MASK : TP_NML_FMT_MASK ; ! 321: tpcb->tp_seqbit = ! 322: tpcb->tp_xtd_format ? TP_XTD_FMT_BIT : TP_NML_FMT_BIT ; ! 323: tpcb->tp_seqhalf = tpcb->tp_seqbit >> 1; ! 324: tpcb->tp_dt_ticks = ! 325: max(tpcb->tp_dt_ticks, (tpcb->tp_peer_acktime + 2)); ! 326: tp_rsyset(tpcb); ! 327: ! 328: } ! 329: ! 330: /* ! 331: * NAME: tp_recycle_tsuffix() ! 332: * ! 333: * CALLED FROM: ! 334: * Called when a ref is frozen. ! 335: * ! 336: * FUNCTION and ARGUMENTS: ! 337: * allows the suffix to be reused. ! 338: * ! 339: * RETURNS: zilch ! 340: * ! 341: * SIDE EFFECTS: ! 342: * ! 343: * NOTES: ! 344: */ ! 345: void ! 346: tp_recycle_tsuffix(tpcb) ! 347: struct tp_pcb *tpcb; ! 348: { ! 349: bzero((caddr_t)tpcb->tp_lsuffix, sizeof( tpcb->tp_lsuffix)); ! 350: bzero((caddr_t)tpcb->tp_fsuffix, sizeof( tpcb->tp_fsuffix)); ! 351: tpcb->tp_fsuffixlen = tpcb->tp_lsuffixlen = 0; ! 352: ! 353: (tpcb->tp_nlproto->nlp_recycle_suffix)(tpcb->tp_npcb); ! 354: } ! 355: ! 356: /* ! 357: * NAME: tp_quench() ! 358: * ! 359: * CALLED FROM: ! 360: * tp{af}_quench() when ICMP source quench or similar thing arrives. ! 361: * ! 362: * FUNCTION and ARGUMENTS: ! 363: * Drop the congestion window back to 1. ! 364: * Congestion window scheme: ! 365: * Initial value is 1. ("slow start" as Nagle, et. al. call it) ! 366: * For each good ack that arrives, the congestion window is increased ! 367: * by 1 (up to max size of logical infinity, which is to say, ! 368: * it doesn't wrap around). ! 369: * Source quench causes it to drop back to 1. ! 370: * tp_send() uses the smaller of (regular window, congestion window). ! 371: * One retransmission strategy option is to have any retransmission ! 372: * cause reset the congestion window back to 1. ! 373: * ! 374: * (cmd) is either PRC_QUENCH: source quench, or ! 375: * PRC_QUENCH2: dest. quench (dec bit) ! 376: * ! 377: * RETURNS: ! 378: * ! 379: * SIDE EFFECTS: ! 380: * ! 381: * NOTES: ! 382: */ ! 383: void ! 384: tp_quench( tpcb, cmd ) ! 385: struct tp_pcb *tpcb; ! 386: int cmd; ! 387: { ! 388: IFDEBUG(D_QUENCH) ! 389: printf("tp_quench tpcb 0x%x ref 0x%x sufx 0x%x\n", ! 390: tpcb, tpcb->tp_lref, *(u_short *)(tpcb->tp_lsuffix)); ! 391: printf("cong_win 0x%x decbit 0x%x \n", ! 392: tpcb->tp_cong_win, tpcb->tp_decbit); ! 393: ENDDEBUG ! 394: switch(cmd) { ! 395: case PRC_QUENCH: ! 396: tpcb->tp_cong_win = tpcb->tp_l_tpdusize; ! 397: IncStat(ts_quench); ! 398: break; ! 399: case PRC_QUENCH2: ! 400: tpcb->tp_cong_win = tpcb->tp_l_tpdusize; /* might as well quench source also */ ! 401: tpcb->tp_decbit = TP_DECBIT_CLEAR_COUNT; ! 402: IncStat(ts_rcvdecbit); ! 403: break; ! 404: } ! 405: } ! 406: ! 407: ! 408: /* ! 409: * NAME: tp_netcmd() ! 410: * ! 411: * CALLED FROM: ! 412: * ! 413: * FUNCTION and ARGUMENTS: ! 414: * ! 415: * RETURNS: ! 416: * ! 417: * SIDE EFFECTS: ! 418: * ! 419: * NOTES: ! 420: */ ! 421: tp_netcmd( tpcb, cmd ) ! 422: struct tp_pcb *tpcb; ! 423: int cmd; ! 424: { ! 425: #if TPCONS ! 426: struct isopcb *isop; ! 427: struct pklcd *lcp; ! 428: ! 429: if (tpcb->tp_netservice != ISO_CONS) ! 430: return; ! 431: isop = (struct isopcb *)tpcb->tp_npcb; ! 432: lcp = (struct pklcd *)isop->isop_chan; ! 433: switch (cmd) { ! 434: ! 435: case CONN_CLOSE: ! 436: case CONN_REFUSE: ! 437: if (isop->isop_refcnt == 1) { ! 438: /* This is really superfluous, since it would happen ! 439: anyway in iso_pcbdetach, although it is a courtesy ! 440: to free up the x.25 channel before the refwait timer ! 441: expires. */ ! 442: lcp->lcd_upper = 0; ! 443: lcp->lcd_upnext = 0; ! 444: pk_disconnect(lcp); ! 445: isop->isop_chan = 0; ! 446: isop->isop_refcnt = 0; ! 447: } ! 448: break; ! 449: ! 450: default: ! 451: printf("tp_netcmd(0x%x, 0x%x) NOT IMPLEMENTED\n", tpcb, cmd); ! 452: break; ! 453: } ! 454: #else /* TPCONS */ ! 455: printf("tp_netcmd(): X25 NOT CONFIGURED!!\n"); ! 456: #endif ! 457: } ! 458: /* ! 459: * CALLED FROM: ! 460: * tp_ctloutput() and tp_emit() ! 461: * FUNCTION and ARGUMENTS: ! 462: * Convert a class mask to the highest numeric value it represents. ! 463: */ ! 464: ! 465: int ! 466: tp_mask_to_num(x) ! 467: u_char x; ! 468: { ! 469: register int j; ! 470: ! 471: for(j = 4; j>=0 ;j--) { ! 472: if(x & (1<<j)) ! 473: break; ! 474: } ! 475: ASSERT( (j == 4) || (j == 0) ); /* for now */ ! 476: if( (j != 4) && (j != 0) ) { ! 477: printf("ASSERTION ERROR: tp_mask_to_num: x 0x%x j %d\n", ! 478: x, j); ! 479: } ! 480: IFTRACE(D_TPINPUT) ! 481: tptrace(TPPTmisc, "tp_mask_to_num(x) returns j", x, j, 0, 0); ! 482: ENDTRACE ! 483: IFDEBUG(D_TPINPUT) ! 484: printf("tp_mask_to_num(0x%x) returns 0x%x\n", x, j); ! 485: ENDDEBUG ! 486: return j; ! 487: } ! 488: ! 489: static ! 490: copyQOSparms(src, dst) ! 491: struct tp_conn_param *src, *dst; ! 492: { ! 493: /* copy all but the bits stuff at the end */ ! 494: #define COPYSIZE (12 * sizeof(short)) ! 495: ! 496: bcopy((caddr_t)src, (caddr_t)dst, COPYSIZE); ! 497: dst->p_tpdusize = src->p_tpdusize; ! 498: dst->p_ack_strat = src->p_ack_strat; ! 499: dst->p_rx_strat = src->p_rx_strat; ! 500: #undef COPYSIZE ! 501: } ! 502: /* ! 503: * Determine a reasonable value for maxseg size. ! 504: * If the route is known, check route for mtu. ! 505: * We also initialize the congestion/slow start ! 506: * window to be a single segment if the destination isn't local. ! 507: * While looking at the routing entry, we also initialize other path-dependent ! 508: * parameters from pre-set or cached values in the routing entry. ! 509: */ ! 510: void ! 511: tp_mss(tpcb, nhdr_size) ! 512: register struct tp_pcb *tpcb; ! 513: int nhdr_size; ! 514: { ! 515: register struct rtentry *rt; ! 516: struct ifnet *ifp; ! 517: register int rtt, mss; ! 518: u_long bufsize; ! 519: int i, ssthresh = 0, rt_mss; ! 520: struct socket *so; ! 521: ! 522: if (tpcb->tp_ptpdusize) ! 523: mss = tpcb->tp_ptpdusize << 7; ! 524: else ! 525: mss = 1 << tpcb->tp_tpdusize; ! 526: so = tpcb->tp_sock; ! 527: if ((rt = *(tpcb->tp_routep)) == 0) { ! 528: bufsize = so->so_rcv.sb_hiwat; ! 529: goto punt_route; ! 530: } ! 531: ifp = rt->rt_ifp; ! 532: ! 533: #ifdef RTV_MTU /* if route characteristics exist ... */ ! 534: /* ! 535: * While we're here, check if there's an initial rtt ! 536: * or rttvar. Convert from the route-table units ! 537: * to hz ticks for the smoothed timers and slow-timeout units ! 538: * for other inital variables. ! 539: */ ! 540: if (tpcb->tp_rtt == 0 && (rtt = rt->rt_rmx.rmx_rtt)) { ! 541: tpcb->tp_rtt = rtt * hz / RTM_RTTUNIT; ! 542: if (rt->rt_rmx.rmx_rttvar) ! 543: tpcb->tp_rtv = rt->rt_rmx.rmx_rttvar ! 544: * hz / RTM_RTTUNIT; ! 545: else ! 546: tpcb->tp_rtv = tpcb->tp_rtt; ! 547: } ! 548: /* ! 549: * if there's an mtu associated with the route, use it ! 550: */ ! 551: if (rt->rt_rmx.rmx_mtu) ! 552: rt_mss = rt->rt_rmx.rmx_mtu - nhdr_size; ! 553: else ! 554: #endif /* RTV_MTU */ ! 555: rt_mss = (ifp->if_mtu - nhdr_size); ! 556: if (tpcb->tp_ptpdusize == 0 || /* assume application doesn't care */ ! 557: mss > rt_mss /* network won't support what was asked for */) ! 558: mss = rt_mss; ! 559: /* can propose mtu which are multiples of 128 */ ! 560: mss &= ~0x7f; ! 561: /* ! 562: * If there's a pipesize, change the socket buffer ! 563: * to that size. ! 564: */ ! 565: #ifdef RTV_SPIPE ! 566: if ((bufsize = rt->rt_rmx.rmx_sendpipe) > 0) { ! 567: #endif ! 568: bufsize = min(bufsize, so->so_snd.sb_hiwat); ! 569: (void) sbreserve(&so->so_snd, bufsize); ! 570: } ! 571: #ifdef RTV_SPIPE ! 572: if ((bufsize = rt->rt_rmx.rmx_recvpipe) > 0) { ! 573: #endif ! 574: bufsize = min(bufsize, so->so_rcv.sb_hiwat); ! 575: (void) sbreserve(&so->so_rcv, bufsize); ! 576: } else ! 577: bufsize = so->so_rcv.sb_hiwat; ! 578: #ifdef RTV_SSTHRESH ! 579: /* ! 580: * There's some sort of gateway or interface ! 581: * buffer limit on the path. Use this to set ! 582: * the slow start threshhold, but set the ! 583: * threshold to no less than 2*mss. ! 584: */ ! 585: ssthresh = rt->rt_rmx.rmx_ssthresh; ! 586: punt_route: ! 587: /* ! 588: * The current mss is initialized to the default value. ! 589: * If we compute a smaller value, reduce the current mss. ! 590: * If we compute a larger value, return it for use in sending ! 591: * a max seg size option. ! 592: * If we received an offer, don't exceed it. ! 593: * However, do not accept offers under 128 bytes. ! 594: */ ! 595: if (tpcb->tp_l_tpdusize) ! 596: mss = min(mss, tpcb->tp_l_tpdusize); ! 597: /* ! 598: * We want a minimum recv window of 4 packets to ! 599: * signal packet loss by duplicate acks. ! 600: */ ! 601: mss = min(mss, bufsize >> 2) & ~0x7f; ! 602: mss = max(mss, 128); /* sanity */ ! 603: tpcb->tp_cong_win = ! 604: (rt == 0 || (rt->rt_flags & RTF_GATEWAY)) ? mss : bufsize; ! 605: tpcb->tp_l_tpdusize = mss; ! 606: tp_rsyset(tpcb); ! 607: tpcb->tp_ssthresh = max(2 * mss, ssthresh); ! 608: /* Calculate log2 of mss */ ! 609: for (i = TP_MIN_TPDUSIZE + 1; i <= TP_MAX_TPDUSIZE; i++) ! 610: if ((1 << i) > mss) ! 611: break; ! 612: i--; ! 613: tpcb->tp_tpdusize = i; ! 614: #endif /* RTV_MTU */ ! 615: } ! 616: ! 617: /* ! 618: * CALLED FROM: ! 619: * tp_usrreq on PRU_CONNECT and tp_input on receipt of CR ! 620: * ! 621: * FUNCTION and ARGUMENTS: ! 622: * -- An mbuf containing the peer's network address. ! 623: * -- Our control block, which will be modified ! 624: * -- In the case of cons, a control block for that layer. ! 625: * ! 626: * ! 627: * RETURNS: ! 628: * errno value : ! 629: * EAFNOSUPPORT if can't find an nl_protosw for x.25 (really could panic) ! 630: * ECONNREFUSED if trying to run TP0 with non-type 37 address ! 631: * possibly other E* returned from cons_netcmd() ! 632: * ! 633: * SIDE EFFECTS: ! 634: * Determines recommended tpdusize, buffering and intial delays ! 635: * based on information cached on the route. ! 636: */ ! 637: int ! 638: tp_route_to( m, tpcb, channel) ! 639: struct mbuf *m; ! 640: register struct tp_pcb *tpcb; ! 641: caddr_t channel; ! 642: { ! 643: register struct sockaddr_iso *siso; /* NOTE: this may be a sockaddr_in */ ! 644: extern struct tp_conn_param tp_conn_param[]; ! 645: int error = 0, save_netservice = tpcb->tp_netservice; ! 646: register struct rtentry *rt = 0; ! 647: int nhdr_size, mtu, bufsize; ! 648: ! 649: siso = mtod(m, struct sockaddr_iso *); ! 650: IFTRACE(D_CONN) ! 651: tptraceTPCB(TPPTmisc, ! 652: "route_to: so afi netservice class", ! 653: tpcb->tp_sock, siso->siso_addr.isoa_genaddr[0], tpcb->tp_netservice, ! 654: tpcb->tp_class); ! 655: ENDTRACE ! 656: IFDEBUG(D_CONN) ! 657: printf("tp_route_to( m x%x, channel 0x%x, tpcb 0x%x netserv 0x%x)\n", ! 658: m, channel, tpcb, tpcb->tp_netservice); ! 659: printf("m->mlen x%x, m->m_data:\n", m->m_len); ! 660: dump_buf(mtod(m, caddr_t), m->m_len); ! 661: ENDDEBUG ! 662: if (channel) { ! 663: #if TPCONS ! 664: struct pklcd *lcp = (struct pklcd *)channel; ! 665: struct isopcb *isop = (struct isopcb *)lcp->lcd_upnext, ! 666: *isop_new = (struct isopcb *)tpcb->tp_npcb; ! 667: /* The next 2 lines believe that you haven't ! 668: set any network level options or done a pcbconnect ! 669: and XXXXXXX'edly apply to both inpcb's and isopcb's */ ! 670: remque(isop_new); ! 671: free(isop_new, M_PCB); ! 672: tpcb->tp_npcb = (caddr_t)isop; ! 673: tpcb->tp_netservice = ISO_CONS; ! 674: tpcb->tp_nlproto = nl_protosw + ISO_CONS; ! 675: if (isop->isop_refcnt++ == 0) { ! 676: iso_putsufx(isop, tpcb->tp_lsuffix, tpcb->tp_lsuffixlen, TP_LOCAL); ! 677: isop->isop_socket = tpcb->tp_sock; ! 678: } else ! 679: /* there are already connections sharing this */; ! 680: #endif ! 681: } else { ! 682: switch (siso->siso_family) { ! 683: default: ! 684: error = EAFNOSUPPORT; ! 685: goto done; ! 686: #if ISO ! 687: case AF_ISO: ! 688: { ! 689: struct isopcb *isop = (struct isopcb *)tpcb->tp_npcb; ! 690: int flags = tpcb->tp_sock->so_options & SO_DONTROUTE; ! 691: tpcb->tp_netservice = ISO_CLNS; ! 692: if (clnp_route(&siso->siso_addr, &isop->isop_route, ! 693: flags, (void **)0, (void **)0) == 0) { ! 694: rt = isop->isop_route.ro_rt; ! 695: if (rt && rt->rt_flags & RTF_PROTO1) ! 696: tpcb->tp_netservice = ISO_CONS; ! 697: } ! 698: } break; ! 699: #endif ! 700: #if INET ! 701: case AF_INET: ! 702: tpcb->tp_netservice = IN_CLNS; ! 703: #endif ! 704: } ! 705: if (tpcb->tp_nlproto->nlp_afamily != siso->siso_family) { ! 706: IFDEBUG(D_CONN) ! 707: printf("tp_route_to( CHANGING nlproto old 0x%x new 0x%x)\n", ! 708: save_netservice, tpcb->tp_netservice); ! 709: ENDDEBUG ! 710: if (error = tp_set_npcb(tpcb)) ! 711: goto done; ! 712: } ! 713: IFDEBUG(D_CONN) ! 714: printf("tp_route_to calling nlp_pcbconn, netserv %d\n", ! 715: tpcb->tp_netservice); ! 716: ENDDEBUG ! 717: tpcb->tp_nlproto = nl_protosw + tpcb->tp_netservice; ! 718: error = (tpcb->tp_nlproto->nlp_pcbconn)(tpcb->tp_npcb, m); ! 719: } ! 720: if (error) ! 721: goto done; ! 722: nhdr_size = tpcb->tp_nlproto->nlp_mtu(tpcb); /* only gets common info */ ! 723: tp_mss(tpcb, nhdr_size); ! 724: done: ! 725: IFDEBUG(D_CONN) ! 726: printf("tp_route_to returns 0x%x\n", error); ! 727: ENDDEBUG ! 728: IFTRACE(D_CONN) ! 729: tptraceTPCB(TPPTmisc, "route_to: returns: error netserv class", error, ! 730: tpcb->tp_netservice, tpcb->tp_class, 0); ! 731: ENDTRACE ! 732: return error; ! 733: } ! 734: ! 735: ! 736: /* class zero version */ ! 737: void ! 738: tp0_stash( tpcb, e ) ! 739: register struct tp_pcb *tpcb; ! 740: register struct tp_event *e; ! 741: { ! 742: #ifndef lint ! 743: #define E e->ATTR(DT_TPDU) ! 744: #else /* lint */ ! 745: #define E e->ev_union.EV_DT_TPDU ! 746: #endif /* lint */ ! 747: ! 748: register struct sockbuf *sb = &tpcb->tp_sock->so_rcv; ! 749: register struct isopcb *isop = (struct isopcb *)tpcb->tp_npcb; ! 750: ! 751: IFPERF(tpcb) ! 752: PStat(tpcb, Nb_from_ll) += E.e_datalen; ! 753: tpmeas(tpcb->tp_lref, TPtime_from_ll, &e->e_time, ! 754: E.e_seq, PStat(tpcb, Nb_from_ll), E.e_datalen); ! 755: ENDPERF ! 756: ! 757: IFDEBUG(D_STASH) ! 758: printf("stash EQ: seq 0x%x datalen 0x%x eot 0x%x", ! 759: E.e_seq, E.e_datalen, E.e_eot); ! 760: ENDDEBUG ! 761: ! 762: IFTRACE(D_STASH) ! 763: tptraceTPCB(TPPTmisc, "stash EQ: seq len eot", ! 764: E.e_seq, E.e_datalen, E.e_eot, 0); ! 765: ENDTRACE ! 766: ! 767: if ( E.e_eot ) { ! 768: register struct mbuf *n = E.e_data; ! 769: n->m_flags |= M_EOR; ! 770: n->m_act = MNULL; /* set on tp_input */ ! 771: } ! 772: sbappend(sb, E.e_data); ! 773: IFDEBUG(D_STASH) ! 774: dump_mbuf(sb->sb_mb, "stash 0: so_rcv after appending"); ! 775: ENDDEBUG ! 776: if (tpcb->tp_netservice != ISO_CONS) ! 777: printf("tp0_stash: tp running over something wierd\n"); ! 778: else { ! 779: register struct pklcd *lcp = (struct pklcd *)isop->isop_chan; ! 780: pk_flowcontrol(lcp, sbspace(sb) <= 0, 1); ! 781: } ! 782: } ! 783: ! 784: void ! 785: tp0_openflow(tpcb) ! 786: register struct tp_pcb *tpcb; ! 787: { ! 788: register struct isopcb *isop = (struct isopcb *)tpcb->tp_npcb; ! 789: if (tpcb->tp_netservice != ISO_CONS) ! 790: printf("tp0_openflow: tp running over something wierd\n"); ! 791: else { ! 792: register struct pklcd *lcp = (struct pklcd *)isop->isop_chan; ! 793: if (lcp->lcd_rxrnr_condition) ! 794: pk_flowcontrol(lcp, 0, 0); ! 795: } ! 796: } ! 797: #ifndef TPCONS ! 798: static ! 799: pk_flowcontrol() {} ! 800: #endif ! 801: ! 802: #ifdef TP_PERF_MEAS ! 803: /* ! 804: * CALLED FROM: ! 805: * tp_ctloutput() when the user sets TPOPT_PERF_MEAS on ! 806: * and tp_newsocket() when a new connection is made from ! 807: * a listening socket with tp_perf_on == true. ! 808: * FUNCTION and ARGUMENTS: ! 809: * (tpcb) is the usual; this procedure gets a clear cluster mbuf for ! 810: * a tp_pmeas structure, and makes tpcb->tp_p_meas point to it. ! 811: * RETURN VALUE: ! 812: * ENOBUFS if it cannot get a cluster mbuf. ! 813: */ ! 814: ! 815: int ! 816: tp_setup_perf(tpcb) ! 817: register struct tp_pcb *tpcb; ! 818: { ! 819: register struct mbuf *q; ! 820: ! 821: if( tpcb->tp_p_meas == 0 ) { ! 822: MGET(q, M_WAITOK, MT_PCB); ! 823: if (q == 0) ! 824: return ENOBUFS; ! 825: MCLGET(q, M_WAITOK); ! 826: if ((q->m_flags & M_EXT) == 0) { ! 827: (void) m_free(q); ! 828: return ENOBUFS; ! 829: } ! 830: q->m_len = sizeof (struct tp_pmeas); ! 831: tpcb->tp_p_mbuf = q; ! 832: tpcb->tp_p_meas = mtod(q, struct tp_pmeas *); ! 833: bzero( (caddr_t)tpcb->tp_p_meas, sizeof (struct tp_pmeas) ); ! 834: IFDEBUG(D_PERF_MEAS) ! 835: printf( ! 836: "tpcb 0x%x so 0x%x ref 0x%x tp_p_meas 0x%x tp_perf_on 0x%x\n", ! 837: tpcb, tpcb->tp_sock, tpcb->tp_lref, ! 838: tpcb->tp_p_meas, tpcb->tp_perf_on); ! 839: ENDDEBUG ! 840: tpcb->tp_perf_on = 1; ! 841: } ! 842: return 0; ! 843: } ! 844: #endif /* TP_PERF_MEAS */ ! 845: ! 846: #ifdef ARGO_DEBUG ! 847: dump_addr (addr) ! 848: register struct sockaddr *addr; ! 849: { ! 850: switch( addr->sa_family ) { ! 851: case AF_INET: ! 852: dump_inaddr((struct sockaddr_in *)addr); ! 853: break; ! 854: #if ISO ! 855: case AF_ISO: ! 856: dump_isoaddr((struct sockaddr_iso *)addr); ! 857: break; ! 858: #endif /* ISO */ ! 859: default: ! 860: printf("BAD AF: 0x%x\n", addr->sa_family); ! 861: break; ! 862: } ! 863: } ! 864: ! 865: #define MAX_COLUMNS 8 ! 866: /* ! 867: * Dump the buffer to the screen in a readable format. Format is: ! 868: * ! 869: * hex/dec where hex is the hex format, dec is the decimal format. ! 870: * columns of hex/dec numbers will be printed, followed by the ! 871: * character representations (if printable). ! 872: */ ! 873: Dump_buf(buf, len) ! 874: caddr_t buf; ! 875: int len; ! 876: { ! 877: int i,j; ! 878: #define Buf ((u_char *)buf) ! 879: printf("Dump buf 0x%x len 0x%x\n", buf, len); ! 880: for (i = 0; i < len; i += MAX_COLUMNS) { ! 881: printf("+%d:\t", i); ! 882: for (j = 0; j < MAX_COLUMNS; j++) { ! 883: if (i + j < len) { ! 884: printf("%x/%d\t", Buf[i+j], Buf[i+j]); ! 885: } else { ! 886: printf(" "); ! 887: } ! 888: } ! 889: ! 890: for (j = 0; j < MAX_COLUMNS; j++) { ! 891: if (i + j < len) { ! 892: if (((Buf[i+j]) > 31) && ((Buf[i+j]) < 128)) ! 893: printf("%c", Buf[i+j]); ! 894: else ! 895: printf("."); ! 896: } ! 897: } ! 898: printf("\n"); ! 899: } ! 900: } ! 901: #endif /* ARGO_DEBUG */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.