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

📄 clnp_subr.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_subr.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_subr.c,v 5.1 89/02/09 16:20:46 hagens Exp $ *//* $Source: /var/src/sys/netiso/RCS/clnp_subr.c,v $ */#ifdef ISO#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/route.h>#include <net/if_dl.h>#include <netiso/iso.h>#include <netiso/iso_var.h>#include <netiso/iso_pcb.h>#include <netiso/iso_snpac.h>#include <netiso/clnp.h>#include <netiso/clnp_stat.h>#include <netiso/argo_debug.h>/* * FUNCTION:		clnp_data_ck * * PURPOSE:			Check that the amount of data in the mbuf chain is *					at least as much as the clnp header would have us *					expect. Trim mbufs if longer than expected, drop *					packet if shorter than expected. * * RETURNS:			success - ptr to mbuf chain *					failure - 0 * * SIDE EFFECTS:	 * * NOTES:			 */struct mbuf *clnp_data_ck(m, length)register struct mbuf	*m;		/* ptr to mbuf chain containing hdr & data */int						length;	/* length (in bytes) of packet */ {	register int 			len;		/* length of data */	register struct mbuf	*mhead;		/* ptr to head of chain */	len = -length;	mhead = m;	for (;;) {		len += m->m_len;		if (m->m_next == 0)			break;		m = m->m_next;	}	if (len != 0) {		if (len < 0) {			INCSTAT(cns_toosmall);			clnp_discard(mhead, GEN_INCOMPLETE);			return 0;		}		if (len <= m->m_len)			m->m_len -= len;		else			m_adj(mhead, -len);	}	return mhead;}#ifdef notdef/* * FUNCTION:		clnp_extract_addr * * PURPOSE:			Extract the source and destination address from the *					supplied buffer. Place them in the supplied address buffers. *					If insufficient data is supplied, then fail. * * RETURNS:			success - Address of first byte in the packet past  *						the address part. *					failure - 0 * * SIDE EFFECTS:	 * * NOTES:			 */caddr_tclnp_extract_addr(bufp, buflen, srcp, destp)caddr_t					bufp;		/* ptr to buffer containing addresses */int						buflen;		/* length of buffer */register struct iso_addr	*srcp;		/* ptr to source address buffer */register struct iso_addr	*destp;		/* ptr to destination address buffer */ {	int	len;		/* argument to bcopy */	/* 	 *	check that we have enough data. Plus1 is for length octet	 */	if ((u_char)*bufp + 1 > buflen) {		return((caddr_t)0);	}	len = destp->isoa_len = (u_char)*bufp++;	(void) bcopy(bufp, (caddr_t)destp, len);	buflen -= len;	bufp += len;	/* 	 *	check that we have enough data. Plus1 is for length octet	 */	if ((u_char)*bufp + 1 > buflen) {		return((caddr_t)0);	}	len = srcp->isoa_len = (u_char)* bufp++;	(void) bcopy(bufp, (caddr_t)srcp, len);	bufp += len;	/*	 *	Insure that the addresses make sense	 */	if (iso_ck_addr(srcp) && iso_ck_addr(destp))		return bufp;	else		return (caddr_t) 0;}#endif	/* notdef *//* * FUNCTION:		clnp_ours * * PURPOSE:			Decide whether the supplied packet is destined for *					us, or that it should be forwarded on. * * RETURNS:			packet is for us - 1 *					packet is not for us - 0 * * SIDE EFFECTS:	 * * NOTES:			 */clnp_ours(dst)register struct iso_addr *dst;		/* ptr to destination address */{	register struct iso_ifaddr *ia;	/* scan through interface addresses */	for (ia = iso_ifaddr; ia; ia = ia->ia_next) {		IFDEBUG(D_ROUTE)			printf("clnp_ours: ia_sis x%x, dst x%x\n", &ia->ia_addr, 				dst);		ENDDEBUG		/*		 * XXX Warning:		 * We are overloading siso_tlen in the if's address, as an nsel length.		 */		if (dst->isoa_len == ia->ia_addr.siso_nlen &&			bcmp((caddr_t)ia->ia_addr.siso_addr.isoa_genaddr,				 (caddr_t)dst->isoa_genaddr,				 ia->ia_addr.siso_nlen - ia->ia_addr.siso_tlen) == 0)					return 1;	}	return 0;}/* Dec bit set if ifp qlen is greater than congest_threshold */int congest_threshold = 0;/* * FUNCTION:		clnp_forward * * PURPOSE:			Forward the datagram passed *					clnpintr guarantees that the header will be *					contigious (a cluster mbuf will be used if necessary). * *					If oidx is NULL, no options are present. * * RETURNS:			nothing * * SIDE EFFECTS:	 * * NOTES:			 */clnp_forward(m, len, dst, oidx, seg_off, inbound_shp)struct mbuf			*m;		/* pkt to forward */int					len;	/* length of pkt */struct iso_addr		*dst;	/* destination address */struct clnp_optidx	*oidx;	/* option index */int					seg_off;/* offset of segmentation part */struct snpa_hdr		*inbound_shp;	/* subnetwork header of inbound packet */{	struct clnp_fixed		*clnp;	/* ptr to fixed part of header */	int						error;	/* return value of route function */	struct sockaddr			*next_hop;	/* next hop for dgram */	struct ifnet			*ifp;	/* ptr to outgoing interface */	struct iso_ifaddr		*ia = 0;/* ptr to iso name for ifp */	struct route_iso		route;	/* filled in by clnp_route */	extern int				iso_systype;	clnp = mtod(m, struct clnp_fixed *);	bzero((caddr_t)&route, sizeof(route)); /* MUST be done before "bad:" */	/*	 *	Don't forward multicast or broadcast packets	 */	if ((inbound_shp) && (IS_MULTICAST(inbound_shp->snh_dhost))) {		IFDEBUG(D_FORWARD)			printf("clnp_forward: dropping multicast packet\n");		ENDDEBUG		clnp->cnf_type &= ~CNF_ERR_OK; /* so we don't generate an ER */		clnp_discard(m, 0);		INCSTAT(cns_cantforward);		goto done;	}	IFDEBUG(D_FORWARD)		printf("clnp_forward: %d bytes, to %s, options x%x\n", len,			clnp_iso_addrp(dst), oidx);	ENDDEBUG	/*	 *	Decrement ttl, and if zero drop datagram	 *	Can't compare ttl as less than zero 'cause its a unsigned	 */	if ((clnp->cnf_ttl == 0) || (--clnp->cnf_ttl == 0)) {		IFDEBUG(D_FORWARD)			printf("clnp_forward: discarding datagram because ttl is zero\n");		ENDDEBUG		INCSTAT(cns_ttlexpired);		clnp_discard(m, TTL_EXPTRANSIT);		goto done;	}	/*	 *	Route packet; special case for source rt	 */	if CLNPSRCRT_VALID(oidx) {		/*		 *	Update src route first		 */		clnp_update_srcrt(m, oidx);		error = clnp_srcroute(m, oidx, &route, &next_hop, &ia, dst);	} else {		error = clnp_route(dst, &route, 0, &next_hop, &ia);	}	if (error || ia == 0) {		IFDEBUG(D_FORWARD)			printf("clnp_forward: can't route packet (errno %d)\n", error);		ENDDEBUG		clnp_discard(m, ADDR_DESTUNREACH);		INCSTAT(cns_cantforward);		goto done;	}	ifp = ia->ia_ifp;	IFDEBUG(D_FORWARD)		printf("clnp_forward: packet routed to %s\n", 			clnp_iso_addrp(&((struct sockaddr_iso *)next_hop)->siso_addr));	ENDDEBUG	INCSTAT(cns_forward);	/*	 *	If we are an intermediate system and	 *	we are routing outbound on the same ifp that the packet	 *	arrived upon, and we know the next hop snpa, 	 *	then generate a redirect request	 */	if ((iso_systype & SNPA_IS) && (inbound_shp) && 		(ifp == inbound_shp->snh_ifp))		    esis_rdoutput(inbound_shp, m, oidx, dst, route.ro_rt);	/*

⌨️ 快捷键说明

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