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