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

📄 clnp_input.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. * *	@(#)clnp_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 *//* $Header: /var/src/sys/netiso/RCS/clnp_input.c,v 5.1 89/02/09 16:20:32 hagens Exp $ *//* $Source: /var/src/sys/netiso/RCS/clnp_input.c,v $ */#include <sys/param.h>#include <sys/mbuf.h>#include <sys/domain.h>#include <sys/protosw.h>#include <sys/socket.h>#include <sys/socketvar.h>#include <sys/errno.h>#include <sys/time.h>#include <net/if.h>#include <net/if_types.h>#include <net/route.h>#include <netiso/iso.h>#include <netiso/iso_var.h>#include <netiso/iso_snpac.h>#include <netiso/clnp.h>#include <netiso/clnl.h>#include <netiso/esis.h>#include <netinet/in_systm.h>#include <netinet/ip.h>#include <netinet/if_ether.h>#include <netiso/eonvar.h>#include <netiso/clnp_stat.h>#include <netiso/argo_debug.h>#ifdef ISOu_char		clnp_protox[ISOPROTO_MAX];struct clnl_protosw clnl_protox[256];int			clnpqmaxlen = IFQ_MAXLEN;	/* RAH? why is this a variable */struct mbuf	*clnp_data_ck();int	clnp_input();int	esis_input();#ifdef	ISO_X25ESISint	x25esis_input();#endif	/* ISO_X25ESIS *//* * FUNCTION:		clnp_init * * PURPOSE:			clnp initialization. Fill in clnp switch tables. * * RETURNS:			none * * SIDE EFFECTS:	fills in clnp_protox table with correct offsets into *					the isosw table. * * NOTES:			 */clnp_init(){	register struct protosw *pr;	/*	 *	CLNP protox initialization	 */	if ((pr = pffindproto(PF_ISO, ISOPROTO_RAW, SOCK_RAW)) == 0)		printf("clnl_init: no raw CLNP\n");	else		clnp_protox[ISOPROTO_RAW] = pr - isosw;	if ((pr = pffindproto(PF_ISO, ISOPROTO_TP, SOCK_SEQPACKET)) == 0)		printf("clnl_init: no tp/clnp\n");	else		clnp_protox[ISOPROTO_TP] = pr - isosw;	/*	 *	CLNL protox initialization	 */	clnl_protox[ISO8473_CLNP].clnl_input = clnp_input;	clnlintrq.ifq_maxlen = clnpqmaxlen;}/* * FUNCTION:		clnlintr * * PURPOSE:			Process a packet on the clnl input queue * * RETURNS:			nothing. * * SIDE EFFECTS:	 * * NOTES:			 */clnlintr(){	register struct mbuf		*m;		/* ptr to first mbuf of pkt */	register struct clnl_fixed	*clnl;	/* ptr to fixed part of clnl hdr */	int							s;		/* save and restore priority */	struct clnl_protosw			*clnlsw;/* ptr to protocol switch */	struct snpa_hdr				sh;		/* subnetwork hdr */	/*	 *	Get next datagram off clnl input queue	 */next:	s = splimp();	/* IF_DEQUEUESNPAHDR(&clnlintrq, m, sh);*/	IF_DEQUEUE(&clnlintrq, m);	splx(s);	if (m == 0)		/* nothing to do */		return;	if ((m->m_flags & M_PKTHDR) == 0 || m->m_pkthdr.rcvif == 0) {		m_freem(m);		goto next;	} else {		register struct ifaddr *ifa;		for (ifa = m->m_pkthdr.rcvif->if_addrlist; ifa; ifa = ifa->ifa_next)			if (ifa->ifa_addr->sa_family == AF_ISO)				break;		if (ifa == 0) {			m_freem(m);			goto next;		}	}	bzero((caddr_t)&sh, sizeof(sh));	sh.snh_flags = m->m_flags & (M_MCAST|M_BCAST);	switch((sh.snh_ifp = m->m_pkthdr.rcvif)->if_type) {		extern int ether_output();	case IFT_EON:		bcopy(mtod(m, caddr_t), (caddr_t)sh.snh_dhost, sizeof(u_long));		bcopy(sizeof(u_long) + mtod(m, caddr_t),					(caddr_t)sh.snh_shost, sizeof(u_long));		sh.snh_dhost[4] = mtod(m, u_char *)[sizeof(struct ip) +								_offsetof(struct eon_hdr, eonh_class)];		m->m_data += EONIPLEN;		m->m_len -= EONIPLEN;		m->m_pkthdr.len -= EONIPLEN;		break;	default:		if (sh.snh_ifp->if_output == ether_output) {			bcopy((caddr_t)(mtod(m, struct ether_header *)->ether_dhost),				(caddr_t)sh.snh_dhost, 2*sizeof(sh.snh_dhost));			m->m_data += sizeof (struct ether_header);			m->m_len -= sizeof (struct ether_header);			m->m_pkthdr.len -= sizeof (struct ether_header);		}	}	IFDEBUG(D_INPUT)		int i;		printf("clnlintr: src:");		for (i=0; i<6; i++)			printf("%x%c", sh.snh_shost[i] & 0xff, (i<5) ? ':' : ' ');		printf(" dst:");		for (i=0; i<6; i++)			printf("%x%c", sh.snh_dhost[i] & 0xff, (i<5) ? ':' : ' ');		printf("\n");	ENDDEBUG	/*	 *	Get the fixed part of the clnl header into the first mbuf.	 *	Drop the packet if this fails.	 *	Do not call m_pullup if we have a cluster mbuf or the	 *	data is not there.	 */	if ((IS_CLUSTER(m) || (m->m_len < sizeof(struct clnl_fixed))) &&		((m = m_pullup(m, sizeof(struct clnl_fixed))) == 0)) {		INCSTAT(cns_toosmall);	/* TODO: use clnl stats */		goto next;				/* m_pullup discards mbuf */	}	clnl = mtod(m, struct clnl_fixed *);	/*	 *	Drop packet if the length of the header is not reasonable.	 */	if ((clnl->cnf_hdr_len < CLNP_HDR_MIN) || 		(clnl->cnf_hdr_len > CLNP_HDR_MAX)) {		INCSTAT(cns_badhlen);	/* TODO: use clnl stats */		m_freem(m);		goto next;	}	/*	 *	If the header is not contained in this mbuf, make it so.	 *	Drop packet if this fails.	 *	Note: m_pullup will allocate a cluster mbuf if necessary	 */	if (clnl->cnf_hdr_len > m->m_len) {		if ((m = m_pullup(m, (int)clnl->cnf_hdr_len)) == 0) {			INCSTAT(cns_badhlen);	/* TODO: use clnl stats */			goto next;	/* m_pullup discards mbuf */		}		clnl = mtod(m, struct clnl_fixed *);	}	clnlsw = &clnl_protox[clnl->cnf_proto_id];	if (clnlsw->clnl_input)		(*clnlsw->clnl_input) (m, &sh);	else		m_freem(m);	goto next;}/* * FUNCTION:		clnp_input * * PURPOSE:			process an incoming clnp packet * * RETURNS:			nothing * * SIDE EFFECTS:	increments fields of clnp_stat structure.

⌨️ 快捷键说明

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