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

📄 clnp_options.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_options.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_options.c,v 5.1 89/02/09 16:20:37 hagens Exp $ *//* $Source: /var/src/sys/netiso/RCS/clnp_options.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 <net/if.h>#include <net/route.h>#include <netiso/iso.h>#include <netiso/clnp.h>#include <netiso/clnp_stat.h>#include <netiso/argo_debug.h>/* * FUNCTION:		clnp_update_srcrt * * PURPOSE:			Process src rt option accompanying a clnp datagram. *						- bump src route ptr if src routing and *							we appear current in src route list. * * RETURNS:			none * * SIDE EFFECTS:	 * * NOTES:			If source routing has been terminated, do nothing. */clnp_update_srcrt(options, oidx)struct mbuf			*options;	/* ptr to options mbuf */struct clnp_optidx	*oidx;		/* ptr to option index */{	u_char			len;	/* length of current address */	struct iso_addr	isoa;	/* copy current address into here */	if (CLNPSRCRT_TERM(oidx, options)) {		IFDEBUG(D_OPTIONS)			printf("clnp_update_srcrt: src rt terminated\n");		ENDDEBUG		return;	}	len = CLNPSRCRT_CLEN(oidx, options);	bcopy(CLNPSRCRT_CADDR(oidx, options), (caddr_t)&isoa, len);	isoa.isoa_len = len;			IFDEBUG(D_OPTIONS)		printf("clnp_update_srcrt: current src rt: %s\n", 			clnp_iso_addrp(&isoa));	ENDDEBUG	if (clnp_ours(&isoa)) {		IFDEBUG(D_OPTIONS)			printf("clnp_update_srcrt: updating src rt\n");		ENDDEBUG		/* update pointer to next src route */		len++;	/* count length byte too! */		CLNPSRCRT_OFF(oidx, options) += len;	}}/* * FUNCTION:		clnp_dooptions * * PURPOSE:			Process options accompanying a clnp datagram. *					Processing includes *						- log our address if recording route * * RETURNS:			none * * SIDE EFFECTS:	 * * NOTES:			 */clnp_dooptions(options, oidx, ifp, isoa)struct mbuf			*options;	/* ptr to options mbuf */struct clnp_optidx	*oidx;		/* ptr to option index */struct ifnet		*ifp;		/* ptr to interface pkt is leaving on */struct iso_addr		*isoa;		/* ptr to our address for this ifp */{	/*	 *	If record route is specified, move all	 *	existing records over, and insert the address of	 *	interface passed	 */	if (oidx->cni_recrtp) {		char 	*opt;			/* ptr to beginning of recrt option */		u_char	off;			/* offset from opt of first free byte */		char	*rec_start;		/* beginning of new rt recorded */		opt = CLNP_OFFTOOPT(options, oidx->cni_recrtp);		off = *(opt + 1);		rec_start = opt + off - 1;		IFDEBUG(D_OPTIONS)			printf("clnp_dooptions: record route: option x%x for %d bytes\n",				opt, oidx->cni_recrt_len);			printf("\tfree slot offset x%x\n", off);			printf("clnp_dooptions: recording %s\n", clnp_iso_addrp(isoa));			printf("clnp_dooptions: option dump:\n");			dump_buf(opt, oidx->cni_recrt_len);		ENDDEBUG		/* proceed only if recording has not been terminated */		if (off != 0xff) {			int new_addrlen = isoa->isoa_len + 1;			/* 			 *	if there is insufficient room to store the next address,			 *	then terminate recording. Plus 1 on isoa_len is for the			 *	length byte itself			 */			if (oidx->cni_recrt_len - (off - 1) < new_addrlen) {				*(opt + 1) = 0xff;	/* terminate recording */			} else {				IFDEBUG(D_OPTIONS)					printf("clnp_dooptions: new addr at x%x for %d\n",						rec_start, new_addrlen);				ENDDEBUG				bcopy((caddr_t)isoa, rec_start, new_addrlen);				/* update offset field */				*(opt + 1) += new_addrlen;				IFDEBUG(D_OPTIONS)					printf("clnp_dooptions: new option dump:\n");					dump_buf(opt, oidx->cni_recrt_len);				ENDDEBUG			}		}	}}/* * FUNCTION:		clnp_set_opts * * PURPOSE:			Check the data mbuf passed for option sanity. If it is *					ok, then set the options ptr to address the data mbuf. *					If an options mbuf exists, free it. This implies that *					any old options will be lost. If data is NULL, simply *					free any old options. * * RETURNS:			unix error code * * SIDE EFFECTS:	 * * NOTES:			 */clnp_set_opts(options, data)struct mbuf	**options;	/* target for option information */struct mbuf	**data;		/* source of option information */{	int					error = 0;	/* error return value */	struct clnp_optidx	dummy;		/* dummy index - not used */	/*	 *	remove any existing options	 */	if (*options != NULL) {		m_freem(*options);		*options = NULL;	}	if (*data != NULL) {		/*		 *	Insure that the options are reasonable.		 *		 *	Also, we do not support security, priority,		 *	nor do we allow one to send an ER option		 *		 *	The QOS parameter is checked for the DECBIT.		 */		if ((clnp_opt_sanity(*data, mtod(*data, caddr_t), (*data)->m_len, 			&dummy) != 0) ||				(dummy.cni_securep) ||				(dummy.cni_priorp) ||				(dummy.cni_er_reason != ER_INVALREAS)) {			error = EINVAL;		} else {			*options = *data;			*data = NULL;	/* so caller won't free mbuf @ *data */		}	}	return error;}/* * FUNCTION:		clnp_opt_sanity * * PURPOSE:			Check the options (beginning at opts for len bytes) for *					sanity. In addition, fill in the option index structure  *					in with information about each option discovered. * * RETURNS:			success (options check out) - 0 *					failure - an ER pdu error code describing failure * * SIDE EFFECTS:	 * * NOTES:			Each pointer field of the option index is filled in with

⌨️ 快捷键说明

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