📄 riptimer.c
字号:
/* ripTimer.c - routines to handle RIP periodic updates*//* Copyright 1984 - 1998 Wind River Systems, Inc. */#include "copyright_wrs.h"/* * Copyright (c) 1983, 1988, 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. * @(#)timer.c 8.1 (Berkeley) 6/5/93 *//*modification history--------------------01h,11sep98,spm moved expanded ripShutdown routine to ripLib.c (SPR #22352); added mutual exclusion to prevent collisions with RIP message processing (SPR #22350)01g,01sep98,spm corrected error preventing expiration of routes stored in hosthash table (SPR #22066)01f,06oct97,gnn fixed SPR 9211 and cleaned up warnings01e,11aug97,gnn name change.01d,02jun97,gnn fixed SPR 8685 so that the timer task does not respawn.01c,12mar97,gnn added multicast support. added time variables.01b,24feb97,gnn fixed bugs in interface aging.01a,26nov96,gnn created from BSD4.4 routed*//*DESCRIPTION*//* * Routing Table Management Daemon */#include "vxWorks.h"#include "rip/defs.h"#include "wdLib.h"#include "semLib.h"#include "intLib.h"#include "logLib.h"extern struct interface *ripIfNet;/* forward declarations. */void ripTimerArm (long timeout);void routedIfInit();IMPORT void ripTimeSet (struct timeval *pTimer);/* * Timer routine. Performs routing information supply * duties and manages timers on routing table entries. * Management of the RTS_CHANGED bit assumes that we broadcast * each time called. */voidripTimer() { register struct rthash *rh; register struct rt_entry *rt; struct rthash *base; int doinghost; int timetobroadcast; IMPORT int routedDebug; IMPORT RIP ripState; FOREVER { /* Wait for the semaphore given by the watchdog routine. */ semTake(ripState.timerSem, WAIT_FOREVER); /* * Block until any processing of incoming messages has completed. * This exclusion guarantees that the routing entries are stable * during updates and that the timer values shared with the * triggered update scheduling will be set atomically. */ semTake (ripLockSem, WAIT_FOREVER); ripTimeSet (&ripState.now); ripState.faketime += ripState.timerRate; if (ripState.lookforinterfaces) { if (routedDebug) logMsg ("Calling routedIfInit.\n", 0, 0, 0, 0, 0, 0); routedIfInit(); } timetobroadcast = ripState.supplier && ((ripState.faketime % ripState.supplyInterval) == 0); base = hosthash; doinghost = 1; again: for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { rt = rh->rt_forw; for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { /* * We don't advance time on a routing entry for * a passive gateway, or any interface. */ if (!(rt->rt_state & RTS_PASSIVE) && !(rt->rt_state & RTS_INTERFACE)) rt->rt_timer += ripState.timerRate; if (rt->rt_timer >= ripState.garbage) { rt = rt->rt_back; rtdelete (rt->rt_forw); continue; } if (rt->rt_timer >= ripState.expire && rt->rt_metric < HOPCNT_INFINITY) rtchange(rt, &rt->rt_router, HOPCNT_INFINITY, NULL); rt->rt_state &= ~RTS_CHANGED; } } if (doinghost) { doinghost = 0; base = nethash; goto again; } /* * Send a periodic update if necessary and reset the timer * and flag settings to suppress any pending triggered updates. */ if (timetobroadcast) { toall (supply, 0, (struct interface *)NULL); ripState.lastbcast = ripState.now; ripState.lastfullupdate = ripState.now; ripState.needupdate = 0; ripState.nextbcast.tv_sec = 0; } semGive (ripLockSem); /* End of critical section. */ /* Restart the timer. */ ripTimerArm (ripState.timerRate); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -