timer.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 171 行
C
171 行
#ifndef lintstatic char *sccsid = "@(#)timer.c 4.1 (ULTRIX) 7/2/90";#endif lint/************************************************************************ * * * Copyright (c) 1984,1988 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* * Copyright (c) 1983 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. *//************************************************************************ * Modification History * * * 07/07/89 R. Bhanukitsiri * Decrease the frequency of SNMP registry. * * 06/01/89 R. Bhanukitsiri * Don't register SNMP variables if no SNMP socket. * * 03/09/89 R. Bhanukitsiri * Register our SNMP variables every timer interval. * * ************************************************************************//*#ifndef lintstatic char sccsid[] = "timer.c 5.4 (Berkeley) 4/2/87";#endif not lint*//* * Routing Table Management Daemon */#include "defs.h"#ifdef SNMPextern int snmp_socket;#endif SNMPint timeval = -TIMER_RATE;#ifdef SNMPint snmptimer = SNMP_TIME; /* SNMP registration interval time */#endif SNMP/* * Timer routine. Performs routing information supply * duties and manages timers on routing table entries. */timer(){ register struct rthash *rh; register struct rt_entry *rt; struct rthash *base = hosthash; int doinghost = 1, timetobroadcast; extern int externalinterfaces; timeval += TIMER_RATE; if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0) ifinit(); timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0;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 we're * not acting as supplier. *//* Supplier may have to go here! */ if (!(rt->rt_state & RTS_PASSIVE) && (supplier || !(rt->rt_state & RTS_INTERFACE))) rt->rt_timer += TIMER_RATE; if (rt->rt_timer >= GARBAGE_TIME) { rt = rt->rt_back; rtdelete(rt->rt_forw); continue; } if (rt->rt_timer >= EXPIRE_TIME) rtchange(rt, &rt->rt_router, HOPCNT_INFINITY); if (rt->rt_state & RTS_CHANGED) { rt->rt_state &= ~RTS_CHANGED; /* don't send extraneous packets */ if (!supplier || timetobroadcast) continue; msg->rip_cmd = RIPCMD_RESPONSE; msg->rip_vers = RIPVERSION; msg->rip_nets[0].rip_dst = rt->rt_dst; msg->rip_nets[0].rip_dst.sa_family = htons(msg->rip_nets[0].rip_dst.sa_family); msg->rip_nets[0].rip_metric = htonl(min(rt->rt_metric + rt->rt_ifmetric, HOPCNT_INFINITY)); toall(sendmsg); } } } if (doinghost) { doinghost = 0; base = nethash; goto again; } if (timetobroadcast) toall(supply);#ifdef SNMP /* * Since we don't know if the SNMP Agent is alive, we send a message * to SNMPD every timer interval to register our SNMP variables. */ snmptimer += TIMER_RATE; if (snmptimer >= SNMP_TIME) { if (snmp_socket != -1) register_snmp_vars(); snmptimer = 0; }#endif SNMP alarm(TIMER_RATE);}/* * On hangup, let everyone know we're going away. */hup(){ register struct rthash *rh; register struct rt_entry *rt; struct rthash *base = hosthash; int doinghost = 1; if (supplier) {again: for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { rt = rh->rt_forw; for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) rt->rt_metric = HOPCNT_INFINITY; } if (doinghost) { doinghost = 0; base = nethash; goto again; } toall(supply); } exit(1);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?