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

📄 tp_input.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
/*- * 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_input.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_input.c,v 5.6 88/11/18 17:27:38 nhall Exp $ * $Source: /usr/argo/sys/netiso/RCS/tp_input.c,v $ * * tp_input() gets an mbuf chain from ip.  Actually, not directly * from ip, because ip calls a net-level routine that strips off * the net header and then calls tp_input(), passing the proper type * of addresses for the address family in use (how it figures out * which AF is not yet determined.) * * Decomposing the tpdu is some of the most laughable code.  The variable-length * parameters and the problem of non-aligned memory references * necessitates such abominations as the macros WHILE_OPTIONS (q.v. below) * to loop through the header and decompose it. * * The routine tp_newsocket() is called when a CR comes in for a listening * socket.  tp_input calls sonewconn() and tp_newsocket() to set up the * "child" socket.  Most tpcb values are copied from the parent tpcb into * the child. *  * Also in here is tp_headersize() (grot) which tells the expected size * of a tp header, to be used by other layers.  It's in here because it * uses the static structure tpdu_info. */#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>#include <netiso/iso.h>#include <netiso/iso_errno.h>#include <netiso/iso_pcb.h>#include <netiso/tp_param.h>#include <netiso/tp_timer.h>#include <netiso/tp_stat.h>#include <netiso/tp_pcb.h>#include <netiso/argo_debug.h>#include <netiso/tp_trace.h>#include <netiso/tp_tpdu.h>#include <net/if.h>#ifdef TRUE#undef FALSE#undef TRUE#endif#include <netccitt/x25.h>#include <netccitt/pk.h>#include <netccitt/pk_var.h>int 	iso_check_csum(), tp_driver(), tp_headersize(), tp_error_emit();/*	#ifdef lint	#undef ATTR	#define ATTR(X)ev_number	#endif lint*/struct mbuf *tp_inputprep(m) 	register struct mbuf *m;{	int hdrlen;	IFDEBUG(D_TPINPUT)		printf("tp_inputprep: m 0x%x\n", m) ;	ENDDEBUG	while(  m->m_len < 1 ) {	    /* The "m_free" logic	     * if( (m = m_free(m)) == MNULL )	     *      return (struct mbuf *)0;		 * would cause a system crash if ever executed.		 * This logic will be executed if the first mbuf	     * in the chain only contains a CLNP header. The m_free routine	     * will release the mbuf containing the CLNP header from the	     * chain and the new head of the chain will not have the	     * M_PKTHDR bit set. This routine, tp_inputprep, will	     * eventually call the "sbappendaddr" routine. "sbappendaddr"	     * calls "panic" if M_PKTHDR is not set. m_pullup is a cheap	     * way of keeping the head of the chain from being freed.		 */		if((m = m_pullup(m, 1)) == MNULL)			return (MNULL);	}	if(((int)m->m_data) & 0x3) {		/* If we are not 4-byte aligned, we have to be		 * above the beginning of the mbuf, and it is ok just		 * to slide it back. 		 */		caddr_t ocp = m->m_data;		m->m_data = (caddr_t)(((int)m->m_data) & ~0x3);		bcopy(ocp, m->m_data, (unsigned)m->m_len);	}	CHANGE_MTYPE(m, TPMT_DATA);	/* we KNOW that there is at least 1 byte in this mbuf	   and that it is hdr->tpdu_li XXXXXXX!  */	hdrlen = 1 + *mtod( m, u_char *);	/*	 * now pull up the whole tp header 	 */	if ( m->m_len < hdrlen) {		if ((m = m_pullup(m, hdrlen)) == MNULL ) {			IncStat(ts_recv_drop);			return (struct mbuf *)0;		}	}	IFDEBUG(D_INPUT)	printf(	" at end: m 0x%x hdr->tpdu_li 0x%x m_len 0x%x\n",m,		hdrlen, m->m_len);	ENDDEBUG	return m;}/* begin groan * -- this array and the following macros allow you to step through the * parameters of the variable part of a header * note that if for any reason the values of the **_TPDU macros (in tp_events.h) * should change, this array has to be rearranged */#define TP_LEN_CLASS_0_INDEX	2#define TP_MAX_DATA_INDEX 3static u_char tpdu_info[][4] ={/*								length						 max data len *//*								reg fmt 	xtd fmt  class 0  		 	  */ 	/* UNUSED		0x0 */		0x0 ,		0x0,	0x0,		0x0, 	/* XPD_TPDU_type 0x1 */		0x5,		0x8,	0x0,		TP_MAX_XPD_DATA, 	/* XAK_TPDU_type 0x2 */		0x5 ,		0x8,	0x0,		0x0, 	/* GR_TPDU_type	0x3 */		0x0 ,		0x0,	0x0,		0x0, 	/* UNUSED		0x4 */		0x0 ,		0x0,	0x0,		0x0, 	/* UNUSED		0x5 */		0x0 ,		0x0,	0x0,		0x0, 	/* AK_TPDU_type 0x6 */		0x5,		0xa,	0x0,		0x0,	/* ER_TPDU_type 0x7 */		0x5,		0x5,	0x0,		0x0, 	/* DR_TPDU_type 0x8 */		0x7,		0x7,	0x7,		TP_MAX_DR_DATA, 	/* UNUSED		0x9 */		0x0 ,		0x0,	0x0,		0x0, 	/* UNUSED		0xa */		0x0 ,		0x0,	0x0,		0x0, 	/* UNUSED		0xb */		0x0 ,		0x0,	0x0,		0x0, 	/* DC_TPDU_type 0xc */		0x6,		0x6,	0x0,		0x0, 	/* CC_TPDU_type 0xd */		0x7,		0x7,	0x7,		TP_MAX_CC_DATA, 	/* CR_TPDU_type 0xe */		0x7,		0x7,	0x7,		TP_MAX_CR_DATA, 	/* DT_TPDU_type 0xf */		0x5,		0x8,	0x3,		0x0,};#define CHECK(Phrase, Erval, Stat, Whattodo, Loc)\	if (Phrase) {error = (Erval); errlen = (int)(Loc); IncStat(Stat);\	goto Whattodo; }/*  * WHENEVER YOU USE THE FOLLOWING MACRO, * BE SURE THE TPDUTYPE IS A LEGIT VALUE FIRST!  */#define WHILE_OPTIONS(P, hdr, format)\{	register caddr_t P = tpdu_info[(hdr)->tpdu_type][(format)] + (caddr_t)hdr;\	caddr_t PLIM = 1 + hdr->tpdu_li + (caddr_t)hdr;\	for (;; P += 2 + ((struct tp_vbp *)P)->tpv_len) {\		CHECK((P > PLIM), E_TP_LENGTH_INVAL, ts_inv_length,\				respond, P - (caddr_t)hdr);\		if (P == PLIM) break;#define END_WHILE_OPTIONS(P) } }/* end groan *//* * NAME:  tp_newsocket() * * CALLED FROM: *  tp_input() on incoming CR, when a socket w/ the called suffix * is awaiting a  connection request * * FUNCTION and ARGUMENTS: *  Create a new socket structure, attach to it a new transport pcb, *  using a copy of the net level pcb for the parent socket. *  (so) is the parent socket. *  (fname) is the foreign address (all that's used is the nsap portion) * * RETURN VALUE: *  a new socket structure, being this end of the newly formed connection. * * SIDE EFFECTS: *  Sets a few things in the tpcb and net level pcb * * NOTES: */static struct socket *tp_newsocket(so, fname, cons_channel, class_to_use, netservice)	struct socket				*so;	struct sockaddr				*fname;	caddr_t						cons_channel;	u_char						class_to_use;	u_int						netservice;{	register struct tp_pcb	*tpcb = sototpcb(so); /* old tpcb, needed below */	register struct tp_pcb	*newtpcb;	/* 	 * sonewconn() gets a new socket structure,	 * a new lower layer pcb and a new tpcb,	 * but the pcbs are unnamed (not bound)	 */	IFTRACE(D_NEWSOCK)		tptraceTPCB(TPPTmisc, "newsock: listg_so, _tpcb, so_head",			so, tpcb, so->so_head, 0);	ENDTRACE		if ((so = sonewconn(so, SS_ISCONFIRMING)) == (struct socket *)0)		return so;	IFTRACE(D_NEWSOCK)		tptraceTPCB(TPPTmisc, "newsock: after newconn so, so_head",			so, so->so_head, 0, 0);	ENDTRACE		IFDEBUG(D_NEWSOCK)		printf("tp_newsocket(channel 0x%x)  after sonewconn so 0x%x \n",				cons_channel, so);		dump_addr(fname);		{ 			struct socket *t, *head ;			head = so->so_head;			t = so;			printf("so 0x%x so_head 0x%x so_q0 0x%x, q0len %d\n",					t, t->so_head, t->so_q0, t->so_q0len);			while( (t=t->so_q0)  && t!= so  && t!= head)				printf("so 0x%x so_head 0x%x so_q0 0x%x, q0len %d\n",					t, t->so_head, t->so_q0, t->so_q0len);		}	ENDDEBUG	/* 	 * before we clobber the old tpcb ptr, get these items from the parent pcb 	 */	newtpcb = sototpcb(so);	newtpcb->_tp_param = tpcb->_tp_param;	newtpcb->tp_flags = tpcb->tp_flags;	newtpcb->tp_lcredit = tpcb->tp_lcredit;	newtpcb->tp_l_tpdusize = tpcb->tp_l_tpdusize;	newtpcb->tp_lsuffixlen = tpcb->tp_lsuffixlen;	bcopy( tpcb->tp_lsuffix, newtpcb->tp_lsuffix, newtpcb->tp_lsuffixlen);	if( /* old */ tpcb->tp_ucddata) {		/* 		 * These data are the connect- , confirm- or disconnect- data.		 */		struct mbuf *conndata;		conndata = m_copy(tpcb->tp_ucddata, 0, (int)M_COPYALL);		IFDEBUG(D_CONN)			dump_mbuf(conndata, "conndata after mcopy");		ENDDEBUG		newtpcb->tp_ucddata = conndata;	}	tpcb = newtpcb;	tpcb->tp_state = TP_LISTENING;	tpcb->tp_class = class_to_use;	tpcb->tp_netservice = netservice;	ASSERT( fname != 0 ) ; /* just checking */	if ( fname ) {		/*		 *	tp_route_to takes its address argument in the form of an mbuf.		 */		struct mbuf	*m;		int			err;		MGET(m, M_DONTWAIT, MT_SONAME);	/* mbuf type used is confusing */		if (m) {			/*			 * this seems a bit grotesque, but tp_route_to expects			 * an mbuf * instead of simply a sockaddr; it calls the ll			 * pcb_connect, which expects the name/addr in an mbuf as well.			 * sigh.			 */			bcopy((caddr_t)fname, mtod(m, caddr_t), fname->sa_len);			m->m_len = fname->sa_len;			/* grot  : have to say the kernel can override params in			 * the passive open case			 */			tpcb->tp_dont_change_params = 0;			err = tp_route_to( m, tpcb, cons_channel);			m_free(m);			if (!err)				goto ok;		}		IFDEBUG(D_CONN)			printf("tp_route_to FAILED! detaching tpcb 0x%x, so 0x%x\n",				tpcb, so);		ENDDEBUG		(void) tp_detach(tpcb); 		return 0;	}ok:	IFDEBUG(D_TPINPUT)		printf("tp_newsocket returning so 0x%x, sototpcb(so) 0x%x\n",			so, sototpcb(so));	ENDDEBUG	return so;}#ifndef TPCONStpcons_output(){	return(0);}#endif /* !CONS *//*  * NAME: 	tp_input() * * CALLED FROM: *  net layer input routine * * FUNCTION and ARGUMENTS: *  Process an incoming TPDU (m), finding the associated tpcb if there *  is one. Create the appropriate type of event and call the driver. *  (faddr) and (laddr) are the foreign and local addresses. *  * 	When tp_input() is called we KNOW that the ENTIRE TP HEADER * 	has been m_pullup-ed. * * RETURN VALUE: Nada *   * SIDE EFFECTS: *	When using COSNS it may affect the state of the net-level pcb

⌨️ 快捷键说明

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