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

📄 rrrcirc.c

📁 用于嵌入式系统的TCP/IP协议栈及若干服务
💻 C
字号:
/**            Copyright (c) 1998-2001 by NETsilicon Inc.**  This software is copyrighted by and is the sole property of*  NETsilicon.  All rights, title, ownership, or other interests*  in the software remain the property of NETsilicon.  This*  software may only be used in accordance with the corresponding*  license agreement.  Any unauthorized use, duplication, transmission,*  distribution, or disclosure of this software is expressly forbidden.**  This Copyright notice may not be removed or modified without prior*  written consent of NETsilicon.**  NETsilicon, reserves the right to modify this software*  without notice.**  NETsilicon*  411 Waverley Oaks Road                  USA 781.647.1234*  Suite 227                               http://www.netsilicon.com*  Waltham, MA 02452                       AmericaSales@netsilicon.com***************************************************************************  $Name: Fusion 6.52 Fusion 6.51 $*  $Date: 2001/11/29 17:22:15 $*  $Source: M:/psisrc/routing/rrfdb/rcs/rrrcirc.c $*  $Revision: 1.19 $**************************************************************************  File Description:  Circuit creation and deletion utilities for RIP*************************************************************************/#include "riproute.h"#include "icirc.h"#include "debug.h"#if defined(RIP_PROTOCOL)fnc_prot(rcirc_pt, ripCircFromId, (int))fnc_prot(iproute_ent_pt, ipFindBestRouteByOwner,(rripa,int))int ripCircuitInit(rcirc_pt circuit,int type){	int cid = circuit->rc_id;		rrFillMem(circuit,0,sizeof(RCIRC));		circuit->rc_id = cid;		circuit->rc_type= type;    circuit->rc_talk = FALSE;    circuit->rc_listen = FALSE;	circuit->rc_r2txmode = R2M_TXV2;    circuit->rc_r2rxmode = R2M_RXV2;	circuit->rc_auth_type = RIP_DEF_AUTH;	/* routing metric may or may not be supported */		circuit->rc_met = RIP_DEF_MET;	return(1);}/* node */RNODE *r_node = (RNODE *)0;RNODE r_node_tpl ={	8,				/* import metric */	0,				/* trigger flag */	RIP_DEF_TIMER,		/* timer */	ROUTER_OFF,		/* rip state */	0,				/* domain */	0,				/* counter */	0				/* counter */	/* EMBEDDED STRUCTS FOLLOW */};/*****************************************ripinit:initialize RIP.*****************************************/void ripinit(void){	int i;	int errp;		if( (r_node = (RNODE *)ipRipNodeAlloc()) == 0){		OS_PANIC0("rip: cant alloc main node");		return;	}	/* init node struct */	rrFillMem(r_node,0,sizeof(RNODE));	r_node->rn_impmet = 8;	r_node->rn_riptimer = RIP_DEF_TIMER;	r_node->rn_radmst = ROUTER_OFF;	rip_clock = 10;	/* circuit hash table */	for (i = 0; i < CIRC_HASHES; i++){		rip_circ_hash[i].dll_fwd = 0;		rip_circ_hash[i].dll_bwd = 0;	}	/* init timer list */	ripTimers.dll_fwd = ripTimers.dll_bwd = 0;#ifdef RIP_PROTOCOL	{		IPNA ipmcast;		/* register with UDP */   		/* Commented out. Done elsewhere in fnsrr.c in env			udpreg(RIP_PORT, riprx);		*/		DWTOPDU(&ipmcast.ip_add,RIPV2_MCAST);		ipRegLocalMcast(ipmcast.ip_add);	}#endif	/*** FOR NOW MAKE SURE IP ALWAYS "LEAKS" LOCAL AND	     STATIC ROUTES TO RIP 	 ***/	/*									add/del */				    /* to        from     = add         */	ipRedistAddDel( IPRT_RIP, IPRT_LOCAL,  1, (void *)0, &errp);	ipRedistAddDel( IPRT_RIP, IPRT_STATIC, 1, (void *)0,  &errp);}/************************************************ripCircCreate:create a circuit.returns 0 or ptr to circuit structReference: utility************************************************/rcirc_pt ripCircCreate(int type,int rcid){	rcirc_pt circuit,sc;	int si;	/* must have rcid */	if(!rcid) return(0);	if( (circuit= (rcirc_pt)ripCircuitAlloc(sizeof(RCIRC))) == NULL){		return(0);	}	else{		/* verify doesnt exist */		if (ripCircFromId(rcid)) {			/* already used */			ripCircuitFree(circuit);			return (0);		}		circuit->rc_id = rcid;		sc = 0;		/* initialize */		if(!ripCircuitInit(circuit,type)){			ripCircuitFree(circuit);			return(0);		}		/* link it to hash list */		si = circuit->rc_id & (CIRC_HASHES - 1);		ipGenLink((dll_pt)circuit, (dll_pt)sc,		 (dll_pt)&rip_circ_hash[si]);	}	return(circuit);}/********************************************ripCircDelete:deletes a circuit. The circuit must be in the OFFstate before deletion can take place.Reference: utility**********************************************/int ripCircDelete(int cid){	rcirc_pt c;	if( (c= ripCircFromId(cid)) == 0){		return(-1);	}	if(c->rc_state != RCIRC_DOWN){		return(-1);	}	/* free the circuit itself */	ipULink((dll_pt)c, 	 (dll_pt)&rip_circ_hash[c->rc_id & (CIRC_HASHES -1)].dll_fwd);	ripCircuitFree(c);	return(0);}/*****************************************ripCircFromId:   returns circuit ptr with specified idReference: utility********************************************/rcirc_pt ripCircFromId(int id){	int i,index;	rcirc_pt c;	/* go through the hash list */	index = id & (CIRC_HASHES -1);	for(i= 0,c= (rcirc_pt)rip_circ_hash[index].dll_fwd; i<MAX_CIRCUIT && c;	 i++,c= c->rc_fwd){		if(c->rc_id== id){			return(c);		}	}	return(0);}/*************************************************ipPurgeStaticRoutesByCirc:**************************************************/void ipPurgeStaticRoutesByCircId(int cid){	iproute_ent_pt iprt;    rcirc_pt c = ripCircFromId(cid);	RT_TABLEWALK			if((RT_OWNER(iprt) != IPRT_LOCAL) &&               (RT_OWNER(iprt) != IPRT_RIP) &&			   (                 (iprt->iprt_cid == c->rc_id) ||                 (RT_TOS0_NHCID(iprt) == c->rc_id))                ) {				ipDelRoute(iprt);			}	RT_TABLEWALKEND}/**************************************************ripCircEvent:a circuit signals the engine of an operational statechange or other event.Reference: utility*************************************************/void ripCircEvent(int cid, int event, void *param,void *parm2){	rcirc_pt 		c = ripCircFromId(cid);	int             old_state;	ipna_pt		ipna;	if(!c) return;	switch (event) {	case RCEVENT_STATE:		old_state = c->rc_state;		c->rc_state = *(int *) param;		/* look for change */		if (c->rc_state == old_state) {			return;		}		if(c->rc_state == RCIRC_UP){			/* a new ip address may be provided here */			ipna = (ipna_pt)parm2;  			c->rc_ipa[0].ip_add = ipna->ip_add;			c->rc_ipa[0].ip_mask = ipna->ip_mask;#ifdef RIP_PROTOCOL			/* send update right away */			riptx(c->rc_ipa, c->rc_id, 0,(rripa)0,0,0);			/* send rip general request */			RipTxReq(c->rc_ipa,c->rc_id);#endif		}		else{#ifdef RIP_PROTOCOL			/* del routes learned via this circ */			RipPurgeRouteByCirc(c);#endif                       /* The RIP code actually encompasses the code to              create and maintain the forwarding database.                Included are static routes.  So when the circuit              goes down we purge all routes as well as RIP              routes.  RIP must also send updates.            */            ipPurgeStaticRoutesByCircId(cid);		}		break;	default:		break;	}}/******************************************ripCircNextId:gets next greater used id value.used primarily by snmp getnext.Reference: utility******************************************/int ripCircNextId(int old_id){	int next_id = MAX_CIRCUIT +1;	int i;	rcirc_pt c;	/* go through hash list */	for(i= 0; i < CIRC_HASHES; i++){		for( c= (rcirc_pt)rip_circ_hash[i].dll_fwd;c;c= c->rc_fwd){			/* see if this ID is lower than last suspect */			if( (c->rc_id > old_id) && (c->rc_id < next_id) ){				next_id = c->rc_id;			}		}	}	if( next_id < MAX_CIRCUIT +1){		return(next_id);	}	else{		return(0);	}}#endif /* RIP_PROTOCOL *//******************************************** * * These utility functions have been moved * from rrutil.c to facilitate building * Fusion with no RIP protocol but a forwarding * database (for static routes) with the  * minimum set of files.  07-19-00 *//********************************************rrLink:link object to dll at list head.Reference: utility*********************************************//* head is address of ptr to first element */void rrLink(dll_pt object,dll_pt head){	object->dll_fwd= head->dll_fwd;	head->dll_fwd= object;	object->dll_bwd= 0;	if(object->dll_fwd){			object->dll_fwd->dll_bwd= object;	}	else{			head->dll_bwd= object;	/* first on list */	}}/****************************************rrGenLink:   link object to dll, links anywhere in chain   object= thing to link   prev=   object to link after   head=   chain headReference: utility******************************************/void rrGenLink(dll_pt object,dll_pt prev,dll_pt head){	if(!head->dll_fwd){		/* only in chain */		head->dll_fwd= object;		head->dll_bwd= object;		object->dll_fwd= 0;		object->dll_bwd= 0;	}	else if(!prev){		/* first in chain */		object->dll_fwd= head->dll_fwd;		object->dll_bwd= 0;		head->dll_fwd= object;		if(object->dll_fwd){			object->dll_fwd->dll_bwd = object;		}		else{			head->dll_bwd = object;		}	}	else{		object->dll_fwd= prev->dll_fwd;		prev->dll_fwd= object;		if(object->dll_fwd){			object->dll_bwd= object->dll_fwd->dll_bwd;			object->dll_fwd->dll_bwd= object;		}		else{			/* end of chain */			object->dll_bwd= prev;			head->dll_bwd= object;		}	}}/*****************************************rrULink:unlink object from dll.Reference: utility******************************************/void rrULink(dll_pt object,dll_pt head){	if(object->dll_fwd){		object->dll_fwd->dll_bwd= object->dll_bwd;	}	else{		head->dll_bwd= object->dll_bwd;	}	if(object->dll_bwd){		object->dll_bwd->dll_fwd= object->dll_fwd;	}	else{		head->dll_fwd= object->dll_fwd;	}	}

⌨️ 快捷键说明

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