1 /* 2 * Copyright (c) 1983, 1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)timer.c 5.9 (Berkeley) 06/01/90"; 10 #endif /* not lint */ 11 12 /* 13 * Routing Table Management Daemon 14 */ 15 #include "defs.h" 16 17 int faketime; 18 19 /* 20 * Timer routine. Performs routing information supply 21 * duties and manages timers on routing table entries. 22 * Management of the RTS_CHANGED bit assumes that we broadcast 23 * each time called. 24 */ 25 timer() 26 { 27 register struct rthash *rh; 28 register struct rt_entry *rt; 29 struct rthash *base = hosthash; 30 int doinghost = 1, timetobroadcast; 31 extern int externalinterfaces; 32 33 (void) gettimeofday(&now, (struct timezone *)NULL); 34 faketime += TIMER_RATE; 35 if (lookforinterfaces && (faketime % CHECK_INTERVAL) == 0) 36 ifinit(); 37 timetobroadcast = supplier && (faketime % SUPPLY_INTERVAL) == 0; 38 again: 39 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { 40 rt = rh->rt_forw; 41 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { 42 /* 43 * We don't advance time on a routing entry for 44 * a passive gateway, or any interface if we're 45 * not acting as supplier. 46 */ 47 if (!(rt->rt_state & RTS_PASSIVE) && 48 (supplier || !(rt->rt_state & RTS_INTERFACE))) 49 rt->rt_timer += TIMER_RATE; 50 if (rt->rt_timer >= GARBAGE_TIME) { 51 rt = rt->rt_back; 52 rtdelete(rt->rt_forw); 53 continue; 54 } 55 if (rt->rt_timer >= EXPIRE_TIME && 56 rt->rt_metric < HOPCNT_INFINITY) 57 rtchange(rt, &rt->rt_router, HOPCNT_INFINITY); 58 rt->rt_state &= ~RTS_CHANGED; 59 } 60 } 61 if (doinghost) { 62 doinghost = 0; 63 base = nethash; 64 goto again; 65 } 66 if (timetobroadcast) { 67 toall(supply, 0, (struct interface *)NULL); 68 lastbcast = now; 69 lastfullupdate = now; 70 needupdate = 0; /* cancel any pending dynamic update */ 71 nextbcast.tv_sec = 0; 72 } 73 } 74 75 /* 76 * On hangup, let everyone know we're going away. 77 */ 78 hup() 79 { 80 register struct rthash *rh; 81 register struct rt_entry *rt; 82 struct rthash *base = hosthash; 83 int doinghost = 1; 84 85 if (supplier) { 86 again: 87 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { 88 rt = rh->rt_forw; 89 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) 90 rt->rt_metric = HOPCNT_INFINITY; 91 } 92 if (doinghost) { 93 doinghost = 0; 94 base = nethash; 95 goto again; 96 } 97 toall(supply, 0, (struct interface *)NULL); 98 } 99 exit(1); 100 } 101