📄 tp.trans
字号:
/* NEW *//*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)tp.trans 8.1 (Berkeley) 6/10/93 *//*********************************************************** Copyright IBM Corporation 1987 All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the name of IBM not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLIBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************//* * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison *//* $Header: tp.trans,v 5.1 88/10/12 12:22:07 root Exp $ * * Transition file for TP. * * DO NOT: * - change the order of any of the events or states. to do so will * make tppt, netstat, etc. cease working. * * NOTE: * some hooks exist for data on (dis)connect, but it's ***NOT***SUPPORTED*** * (read: may not work!) * * I tried to put everything that causes a change of state in here, hence * there are some seemingly trivial events like T_DETACH and T_LISTEN_req. * * Almost everything having to do w/ setting & cancelling timers is here * but once it was debugged, I moved the setting of the * keepalive (sendack) timer to tp_emit(), where an AK_TPDU is sent. * This is so the code wouldn't be duplicated all over creation in here. * */*PROTOCOL tp*INCLUDE{/* @(#)tp.trans 8.1 (Berkeley) 6/10/93 */#include <sys/param.h>#include <sys/systm.h>#include <sys/socket.h>#include <sys/socketvar.h>#include <sys/protosw.h>#include <sys/mbuf.h>#include <sys/time.h>#include <sys/errno.h>#include <netiso/tp_param.h>#include <netiso/tp_stat.h>#include <netiso/tp_pcb.h>#include <netiso/tp_tpdu.h>#include <netiso/argo_debug.h>#include <netiso/tp_trace.h>#include <netiso/iso_errno.h>#include <netiso/tp_seq.h>#include <netiso/cons.h>#define DRIVERTRACE TPPTdriver#define sbwakeup(sb) sowakeup(p->tp_sock, sb);#define MCPY(d, w) (d ? m_copym(d, 0, (int)M_COPYALL, w): 0)static trick_hc = 1;int tp_emit(), tp_goodack(), tp_goodXack(), tp_stash();void tp_indicate(), tp_getoptions(), tp_soisdisconnecting(), tp_soisdisconnected(), tp_recycle_tsuffix(), #ifdef TP_DEBUG_TIMERS tp_etimeout(), tp_euntimeout(), tp_ctimeout(), tp_cuntimeout(), tp_ctimeout_MIN(),#endif tp_freeref(), tp_detach(), tp0_stash(), tp0_send(), tp_netcmd(), tp_send();typedef struct tp_pcb tpcb_struct;}*PCB tpcb_struct SYNONYM P*STATESTP_CLOSED TP_CRSENTTP_AKWAITTP_OPENTP_CLOSING TP_REFWAITTP_LISTENING /* Local to this implementation */TP_CONFIRMING /* Local to this implementation */*EVENTS { struct timeval e_time; } SYNONYM E /* * C (typically cancelled) timers - * * let these be the first ones so for the sake of convenience * their values are 0--> n-1 * DO NOT CHANGE THE ORDER OF THESE TIMER EVENTS!! */ TM_inact TM_retrans /* TM_retrans is used for all * simple retransmissions - CR,CC,XPD,DR */ TM_sendack /* TM_sendack does dual duty - keepalive AND closed-window * Probes. * It's set w/ keepalive-ticks every time an ack is sent. * (this is done in (void) tp_emit() ). * Whenever a DT arrives which doesn't require immediate acking, * a separate fast-timeout flag is set ensuring 200ms response. */ TM_notused /* * E (typically expired) timers - these may be in any order. * These cause procedures to be executed directly; may not * cause an 'event' as we know them here. */ TM_reference { SeqNum e_low; SeqNum e_high; int e_retrans; } TM_data_retrans { SeqNum e_low; SeqNum e_high; int e_retrans; }/* NOTE: in tp_input is a minor optimization that assumes that * for all tpdu types that can take e_data and e_datalen, these * fields fall in the same place in the event structure, that is, * e_data is the first field and e_datalen is the 2nd field. */ ER_TPDU { u_char e_reason; } CR_TPDU { struct mbuf *e_data; /* first field */ int e_datalen; /* 2nd field */ u_int e_cdt; } DR_TPDU { struct mbuf *e_data; /* first field */ int e_datalen; /* 2nd field */ u_short e_sref; u_char e_reason; } DC_TPDU CC_TPDU { struct mbuf *e_data; /* first field */ int e_datalen; /* 2nd field */ u_short e_sref; u_int e_cdt; } AK_TPDU { u_int e_cdt; SeqNum e_seq; SeqNum e_subseq; u_char e_fcc_present; } DT_TPDU { struct mbuf *e_data; /* first field */ int e_datalen; /* 2nd field */ u_int e_eot; SeqNum e_seq; } XPD_TPDU { struct mbuf *e_data; /* first field */ int e_datalen; /* 2nd field */ SeqNum e_seq; } XAK_TPDU { SeqNum e_seq; } T_CONN_req T_DISC_req { u_char e_reason; } T_LISTEN_req T_DATA_req T_XPD_req T_USR_rcvd T_USR_Xrcvd T_DETACH T_NETRESET T_ACPT_req*TRANSITIONS/* TP_AKWAIT doesn't exist in TP 0 */SAME <== TP_AKWAIT [ CC_TPDU, DC_TPDU, XAK_TPDU ] DEFAULT NULLACTION;/* applicable in TP4, TP0 */SAME <== TP_REFWAIT DR_TPDU ( $$.e_sref != 0 ) { (void) tp_emit(DC_TPDU_type, $P, 0, 0, MNULL); }; /* applicable in TP4, TP0 */SAME <== TP_REFWAIT [ CR_TPDU, CC_TPDU, DT_TPDU, DR_TPDU, XPD_TPDU, AK_TPDU, XAK_TPDU, DC_TPDU, ER_TPDU ] DEFAULT {# ifdef TP_DEBUG if( $E.ev_number != AK_TPDU ) printf("TPDU 0x%x in REFWAIT!!!!\n", $E.ev_number);# endif TP_DEBUG };/* applicable in TP4, TP0 */SAME <== TP_REFWAIT [ T_DETACH, T_DISC_req ] DEFAULT NULLACTION;/* applicable in TP4, TP0 */SAME <== TP_CRSENT AK_TPDU ($P.tp_class == TP_CLASS_0) { /* oh, man is this grotesque or what? */ (void) tp_goodack($P, $$.e_cdt, $$.e_seq, $$.e_subseq); /* but it's necessary because this pseudo-ack may happen * before the CC arrives, but we HAVE to adjust the * snduna as a result of the ack, WHENEVER it arrives */ };/* applicable in TP4, TP0 */SAME <== TP_CRSENT [ CR_TPDU, DC_TPDU, DT_TPDU, XPD_TPDU, XAK_TPDU ] DEFAULT NULLACTION;/* applicable in TP4, TP0 */SAME <== TP_CLOSED [ DT_TPDU, XPD_TPDU, ER_TPDU, DC_TPDU, AK_TPDU, XAK_TPDU ] DEFAULT NULLACTION;/* TP_CLOSING doesn't exist in TP 0 */SAME <== TP_CLOSING [ CC_TPDU, CR_TPDU, DT_TPDU, XPD_TPDU, AK_TPDU, XAK_TPDU ] DEFAULT NULLACTION;/* DC_TPDU doesn't exist in TP 0 */SAME <== TP_OPEN DC_TPDU DEFAULT NULLACTION;/* applicable in TP4, TP0 */SAME <== TP_LISTENING [DR_TPDU, CC_TPDU, DT_TPDU, XPD_TPDU, ER_TPDU, DC_TPDU, AK_TPDU, XAK_TPDU ] DEFAULT NULLACTION;/* applicable in TP4, TP0 */TP_LISTENING <== TP_CLOSED T_LISTEN_req DEFAULT NULLACTION;/* applicable in TP4, TP0 */TP_CLOSED <== [ TP_LISTENING, TP_CLOSED ] T_DETACH DEFAULT { tp_detach($P); };TP_CONFIRMING <== TP_LISTENING CR_TPDU ( $P.tp_class == TP_CLASS_0) { $P.tp_refstate = REF_OPEN; /* has timers ??? */ };TP_CONFIRMING <== TP_LISTENING CR_TPDU DEFAULT { IFTRACE(D_CONN) tptrace(TPPTmisc, "CR datalen data", $$.e_datalen, $$.e_data,0,0); ENDTRACE IFDEBUG(D_CONN) printf("CR datalen 0x%x data 0x%x", $$.e_datalen, $$.e_data); ENDDEBUG $P.tp_refstate = REF_OPEN; /* has timers */ $P.tp_fcredit = $$.e_cdt; if ($$.e_datalen > 0) { /* n/a for class 0 */ ASSERT($P.tp_Xrcv.sb_cc == 0); sbappendrecord(&$P.tp_Xrcv, $$.e_data); $$.e_data = MNULL; } };TP_OPEN <== TP_CONFIRMING T_ACPT_req ( $P.tp_class == TP_CLASS_0 ) { IncStat(ts_tp0_conn); IFTRACE(D_CONN) tptrace(TPPTmisc, "Confiming", $P, 0,0,0); ENDTRACE IFDEBUG(D_CONN) printf("Confirming connection: $P" ); ENDDEBUG soisconnected($P.tp_sock); (void) tp_emit(CC_TPDU_type, $P, 0,0, MNULL) ; $P.tp_fcredit = 1; };TP_AKWAIT <== TP_CONFIRMING T_ACPT_req (tp_emit(CC_TPDU_type, $P, 0,0, MCPY($P.tp_ucddata, M_NOWAIT)) == 0) { IncStat(ts_tp4_conn); /* even though not quite open */ IFTRACE(D_CONN) tptrace(TPPTmisc, "Confiming", $P, 0,0,0); ENDTRACE IFDEBUG(D_CONN) printf("Confirming connection: $P" ); ENDDEBUG tp_getoptions($P); soisconnecting($P.tp_sock); if (($P.tp_rx_strat & TPRX_FASTSTART) && ($P.tp_fcredit > 0)) $P.tp_cong_win = $P.tp_fcredit * $P.tp_l_tpdusize; $P.tp_retrans = $P.tp_Nretrans; tp_ctimeout($P, TM_retrans, (int)$P.tp_cc_ticks); };/* TP4 only */TP_CLOSED <== TP_CONFIRMING T_ACPT_req DEFAULT /* emit failed */ { IFDEBUG(D_CONN) printf("event: CR_TPDU emit CC failed done " ); ENDDEBUG soisdisconnected($P.tp_sock); tp_recycle_tsuffix($P); tp_freeref($P.tp_lref); tp_detach($P); };/* applicable in TP4, TP0 */TP_CRSENT <== TP_CLOSED T_CONN_req DEFAULT { int error; struct mbuf *data = MNULL; IFTRACE(D_CONN) tptrace(TPPTmisc, "T_CONN_req flags ucddata", (int)$P.tp_flags, $P.tp_ucddata, 0, 0); ENDTRACE data = MCPY($P.tp_ucddata, M_WAIT); if (data) { IFDEBUG(D_CONN) printf("T_CONN_req.trans m_copy cc 0x%x\n", $P.tp_ucddata); dump_mbuf(data, "sosnd @ T_CONN_req"); ENDDEBUG } if (error = tp_emit(CR_TPDU_type, $P, 0, 0, data) ) return error; /* driver WON'T change state; will return error */ $P.tp_refstate = REF_OPEN; /* has timers */ if($P.tp_class != TP_CLASS_0) { $P.tp_retrans = $P.tp_Nretrans; tp_ctimeout($P, TM_retrans, (int)$P.tp_cr_ticks); } };/* applicable in TP4, TP0, but state TP_AKWAIT doesn't apply to TP0 */TP_REFWAIT <== [ TP_CRSENT, TP_AKWAIT, TP_OPEN ] DR_TPDU DEFAULT { sbflush(&$P.tp_Xrcv); /* purge non-delivered data data */ if ($$.e_datalen > 0) { sbappendrecord(&$P.tp_Xrcv, $$.e_data); $$.e_data = MNULL; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -