1 #ifndef lint 2 static char sccsid[] = "@(#)timer.c 4.3 (Berkeley) 05/25/83"; 3 #endif 4 5 /* 6 * Routing Table Management Daemon 7 */ 8 #include "defs.h" 9 10 int timeval = -TIMER_RATE; 11 12 /* 13 * Timer routine. Performs routing information supply 14 * duties and manages timers on routing table entries. 15 */ 16 timer() 17 { 18 register struct rthash *rh; 19 register struct rt_entry *rt; 20 struct rthash *base = hosthash; 21 int doinghost = 1, timetobroadcast; 22 23 timeval += TIMER_RATE; 24 if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0) 25 ifinit(); 26 timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0; 27 again: 28 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { 29 rt = rh->rt_forw; 30 for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { 31 /* 32 * We don't advance time on a routing entry for 33 * a passive gateway or that for our only interface. 34 * The latter is excused because we don't act as 35 * a routing information supplier and hence would 36 * time it out. This is fair as if it's down 37 * we're cut off from the world anyway and it's 38 * not likely we'll grow any new hardware in 39 * the mean time. 40 */ 41 if (!(rt->rt_state & RTS_PASSIVE) && 42 (supplier || !(rt->rt_state & RTS_INTERFACE))) 43 rt->rt_timer += TIMER_RATE; 44 if (rt->rt_timer >= EXPIRE_TIME) 45 rt->rt_metric = HOPCNT_INFINITY; 46 if (rt->rt_timer >= GARBAGE_TIME) { 47 rt = rt->rt_back; 48 rtdelete(rt->rt_forw); 49 continue; 50 } 51 if (rt->rt_state & RTS_CHANGED) { 52 rt->rt_state &= ~RTS_CHANGED; 53 /* don't send extraneous packets */ 54 if (!supplier || timetobroadcast) 55 continue; 56 msg->rip_cmd = RIPCMD_RESPONSE; 57 msg->rip_vers = RIPVERSION; 58 msg->rip_nets[0].rip_dst = rt->rt_dst; 59 msg->rip_nets[0].rip_metric = 60 min(rt->rt_metric+1, HOPCNT_INFINITY); 61 #ifdef notyet 62 msg->rip_nets[0].rip_dst.sa_family = 63 htons(msg->rip_nets[0].rip_dst.sa_family); 64 msg->rip_nets[0].rip_metric = 65 htonl(msg->rip_nets[0].rip_metric); 66 #endif 67 toall(sendmsg); 68 } 69 } 70 } 71 if (doinghost) { 72 doinghost = 0; 73 base = nethash; 74 goto again; 75 } 76 if (timetobroadcast) 77 toall(supply); 78 alarm(TIMER_RATE); 79 } 80