⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tp_subr2.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*- * 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_subr2.c	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 *//*  * ARGO TP * * $Header: tp_subr2.c,v 5.5 88/11/18 17:28:55 nhall Exp $ * $Source: /usr/argo/sys/netiso/RCS/tp_subr2.c,v $ * * Some auxiliary routines: * 	tp_protocol_error: required by xebec- called when a combo of state, *	    event, predicate isn't covered for by the transition file. *	tp_indicate: gives indications(signals) to the user process *	tp_getoptions: initializes variables that are affected by the options *	    chosen. *//* this def'n is to cause the expansion of this macro in the * routine tp_local_credit : */#define LOCAL_CREDIT_EXPAND#include <sys/param.h>#include <sys/systm.h>#include <sys/mbuf.h>#include <sys/socket.h>#include <sys/socketvar.h>#include <sys/domain.h>#include <sys/protosw.h>#include <sys/errno.h>#include <sys/time.h>#include <sys/kernel.h>#undef MNULL#include <netiso/argo_debug.h>#include <netiso/tp_param.h>#include <netiso/tp_ip.h>#include <netiso/iso.h>#include <netiso/iso_errno.h>#include <netiso/iso_pcb.h>#include <netiso/tp_timer.h>#include <netiso/tp_stat.h>#include <netiso/tp_tpdu.h>#include <netiso/tp_pcb.h>#include <netiso/tp_seq.h>#include <netiso/tp_trace.h>#include <netiso/tp_user.h>#include <netiso/cons.h>#include <net/if.h>#include <net/if_types.h>#ifdef TRUE#undef FALSE#undef TRUE#endif#include <netccitt/x25.h>#include <netccitt/pk.h>#include <netccitt/pk_var.h>void tp_rsyset();/* * NAME: 	tp_local_credit() * * CALLED FROM: *  tp_emit(), tp_usrreq() * * FUNCTION and ARGUMENTS: *	Computes the local credit and stashes it in tpcb->tp_lcredit. *  It's a macro in the production system rather than a procdure. * * RETURNS: * * SIDE EFFECTS: * * NOTES: *  This doesn't actually get called in a production system -  *  the macro gets expanded instead in place of calls to this proc. *  But for debugging, we call this and that allows us to add *  debugging messages easily here. */voidtp_local_credit(tpcb)	struct tp_pcb *tpcb;{	LOCAL_CREDIT(tpcb);	IFDEBUG(D_CREDIT)		printf("ref 0x%x lcdt 0x%x l_tpdusize 0x%x decbit 0x%x\n",			tpcb->tp_lref, 			tpcb->tp_lcredit, 			tpcb->tp_l_tpdusize, 			tpcb->tp_decbit, 			tpcb->tp_cong_win			);	ENDDEBUG	IFTRACE(D_CREDIT)		tptraceTPCB(TPPTmisc,			"lcdt tpdusz \n",			 tpcb->tp_lcredit, tpcb->tp_l_tpdusize, 0, 0);	ENDTRACE}/* * NAME:  tp_protocol_error() * * CALLED FROM: *  tp_driver(), when it doesn't know what to do with * 	a combo of event, state, predicate * * FUNCTION and ARGUMENTS: *  print error mesg  * * RETURN VALUE: *  EIO - always * * SIDE EFFECTS: * * NOTES: */inttp_protocol_error(e,tpcb)	struct tp_event	*e;	struct tp_pcb	*tpcb;{	printf("TP PROTOCOL ERROR! tpcb 0x%x event 0x%x, state 0x%x\n",		tpcb, e->ev_number, tpcb->tp_state);	IFTRACE(D_DRIVER)		tptraceTPCB(TPPTmisc, "PROTOCOL ERROR tpcb event state",			tpcb, e->ev_number, tpcb->tp_state, 0 );	ENDTRACE	return EIO; /* for lack of anything better */}/* Not used at the moment */ProtoHooktp_drain(){	return 0;}/* * NAME: tp_indicate() * * CALLED FROM: * 	tp.trans when XPD arrive, when a connection is being disconnected by *  the arrival of a DR or ER, and when a connection times out. * * FUNCTION and ARGUMENTS: *  (ind) is the type of indication : T_DISCONNECT, T_XPD *  (error) is an E* value that will be put in the socket structure *  to be passed along to the user later. * 	Gives a SIGURG to the user process or group indicated by the socket * 	attached to the tpcb. * * RETURNS:  Rien *  * SIDE EFFECTS: * * NOTES: */voidtp_indicate(ind, tpcb, error)	int				ind; 	u_short			error;	register struct tp_pcb	*tpcb;{	register struct socket *so = tpcb->tp_sock;	IFTRACE(D_INDICATION)		tptraceTPCB(TPPTindicate, ind, *(u_short *)(tpcb->tp_lsuffix), 			*(u_short *)(tpcb->tp_fsuffix), error,so->so_pgid);	ENDTRACE	IFDEBUG(D_INDICATION)		char *ls, *fs;		ls = tpcb->tp_lsuffix, 		fs = tpcb->tp_fsuffix, 		printf("indicate 0x%x lsuf 0x%02x%02x fsuf 0x%02x%02x err 0x%x  noind 0x%x ref 0x%x\n",		ind, 		*ls, *(ls+1), *fs, *(fs+1),		error, /*so->so_pgrp,*/		tpcb->tp_no_disc_indications,		tpcb->tp_lref);	ENDDEBUG	if (ind == ER_TPDU) {		register struct mbuf *m;		struct tp_disc_reason x;		if ((so->so_state & SS_CANTRCVMORE) == 0 &&				(m = m_get(M_DONTWAIT, MT_OOBDATA)) != 0) {			x.dr_hdr.cmsg_len = m->m_len = sizeof(x);			x.dr_hdr.cmsg_level = SOL_TRANSPORT;			x.dr_hdr.cmsg_type= TPOPT_DISC_REASON;			x.dr_reason = error;			*mtod(m, struct tp_disc_reason *) = x;			sbappendrecord(&tpcb->tp_Xrcv, m);			error = 0;		} else			error = ECONNRESET;	}	so->so_error = error;	if (ind == T_DISCONNECT)  {		if (error == 0)			so->so_error = ENOTCONN;		if ( tpcb->tp_no_disc_indications )			return;	}	IFTRACE(D_INDICATION)		tptraceTPCB(TPPTmisc, "doing sohasoutofband(so)", so,0,0,0);	ENDTRACE	sohasoutofband(so);}/* * NAME : tp_getoptions() * * CALLED FROM: * 	tp.trans whenever we go into OPEN state  * * FUNCTION and ARGUMENTS: *  sets the proper flags and values in the tpcb, to control *  the appropriate actions for the given class, options, *  sequence space, etc, etc. *  * RETURNS: Nada *  * SIDE EFFECTS: * * NOTES: */voidtp_getoptions(tpcb)struct tp_pcb *tpcb;{	tpcb->tp_seqmask = 		tpcb->tp_xtd_format ?	TP_XTD_FMT_MASK :	TP_NML_FMT_MASK ;	tpcb->tp_seqbit =		tpcb->tp_xtd_format ?	TP_XTD_FMT_BIT :	TP_NML_FMT_BIT ;	tpcb->tp_seqhalf = tpcb->tp_seqbit >> 1;	tpcb->tp_dt_ticks =		max(tpcb->tp_dt_ticks, (tpcb->tp_peer_acktime + 2));	tp_rsyset(tpcb);	}/* * NAME:  tp_recycle_tsuffix() * * CALLED FROM: *  Called when a ref is frozen. * * FUNCTION and ARGUMENTS: *  allows the suffix to be reused.  * * RETURNS: zilch * * SIDE EFFECTS: * * NOTES: */voidtp_recycle_tsuffix(tpcb)	struct tp_pcb	*tpcb;{	bzero((caddr_t)tpcb->tp_lsuffix, sizeof( tpcb->tp_lsuffix));	bzero((caddr_t)tpcb->tp_fsuffix, sizeof( tpcb->tp_fsuffix));	tpcb->tp_fsuffixlen = tpcb->tp_lsuffixlen = 0;	(tpcb->tp_nlproto->nlp_recycle_suffix)(tpcb->tp_npcb);}/* * NAME: tp_quench() * * CALLED FROM: *  tp{af}_quench() when ICMP source quench or similar thing arrives. * * FUNCTION and ARGUMENTS: *  Drop the congestion window back to 1. *  Congestion window scheme: *  Initial value is 1.  ("slow start" as Nagle, et. al. call it) *  For each good ack that arrives, the congestion window is increased *  by 1 (up to max size of logical infinity, which is to say,  *	it doesn't wrap around). *  Source quench causes it to drop back to 1. *  tp_send() uses the smaller of (regular window, congestion window).  *  One retransmission strategy option is to have any retransmission  *	cause reset the congestion window back  to 1. * *	(cmd) is either PRC_QUENCH: source quench, or *		PRC_QUENCH2: dest. quench (dec bit) * * RETURNS: *  * SIDE EFFECTS: *  * NOTES: */voidtp_quench( tpcb, cmd )	struct tp_pcb *tpcb;	int cmd;{	IFDEBUG(D_QUENCH)		printf("tp_quench tpcb 0x%x ref 0x%x sufx 0x%x\n",			tpcb, tpcb->tp_lref, *(u_short *)(tpcb->tp_lsuffix));		printf("cong_win 0x%x decbit 0x%x \n",			tpcb->tp_cong_win, tpcb->tp_decbit);	ENDDEBUG	switch(cmd) {		case PRC_QUENCH:			tpcb->tp_cong_win = tpcb->tp_l_tpdusize;			IncStat(ts_quench);			break;		case PRC_QUENCH2:			tpcb->tp_cong_win = tpcb->tp_l_tpdusize; /* might as well quench source also */			tpcb->tp_decbit = TP_DECBIT_CLEAR_COUNT;			IncStat(ts_rcvdecbit);			break;	}}/* * NAME:	tp_netcmd() * * CALLED FROM:			 * * FUNCTION and ARGUMENTS:			 * * RETURNS:			 * * SIDE EFFECTS:	 * * NOTES:			 */tp_netcmd( tpcb, cmd )	struct tp_pcb *tpcb;	int cmd;{#ifdef TPCONS	struct isopcb *isop;	struct pklcd *lcp;	if (tpcb->tp_netservice != ISO_CONS)		return;	isop = (struct isopcb *)tpcb->tp_npcb;	lcp = (struct pklcd *)isop->isop_chan;	switch (cmd) {	case CONN_CLOSE:	case CONN_REFUSE:		if (isop->isop_refcnt == 1) {			/* This is really superfluous, since it would happen			   anyway in iso_pcbdetach, although it is a courtesy			   to free up the x.25 channel before the refwait timer			   expires. */			lcp->lcd_upper = 0;			lcp->lcd_upnext = 0;			pk_disconnect(lcp);			isop->isop_chan = 0;			isop->isop_refcnt = 0;		}		break;	default:		printf("tp_netcmd(0x%x, 0x%x) NOT IMPLEMENTED\n", tpcb, cmd);		break;	}#else /* TPCONS */	printf("tp_netcmd(): X25 NOT CONFIGURED!!\n");#endif}/* * CALLED FROM: *  tp_ctloutput() and tp_emit() * FUNCTION and ARGUMENTS: * 	Convert a class mask to the highest numeric value it represents.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -