19021Ssam #ifndef lint 2*12726Ssam static char sccsid[] = "@(#)timer.c 4.3 (Berkeley) 05/25/83"; 39021Ssam #endif 49021Ssam 59021Ssam /* 69021Ssam * Routing Table Management Daemon 79021Ssam */ 810245Ssam #include "defs.h" 99021Ssam 109021Ssam int timeval = -TIMER_RATE; 119021Ssam 129021Ssam /* 139021Ssam * Timer routine. Performs routing information supply 149021Ssam * duties and manages timers on routing table entries. 159021Ssam */ 169021Ssam timer() 179021Ssam { 189021Ssam register struct rthash *rh; 199021Ssam register struct rt_entry *rt; 209021Ssam struct rthash *base = hosthash; 219021Ssam int doinghost = 1, timetobroadcast; 229021Ssam 239021Ssam timeval += TIMER_RATE; 249021Ssam if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0) 259021Ssam ifinit(); 269021Ssam timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0; 279021Ssam again: 289021Ssam for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { 299021Ssam rt = rh->rt_forw; 309021Ssam for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { 319021Ssam /* 329021Ssam * We don't advance time on a routing entry for 339021Ssam * a passive gateway or that for our only interface. 349021Ssam * The latter is excused because we don't act as 359021Ssam * a routing information supplier and hence would 369021Ssam * time it out. This is fair as if it's down 379021Ssam * we're cut off from the world anyway and it's 389021Ssam * not likely we'll grow any new hardware in 399021Ssam * the mean time. 409021Ssam */ 419021Ssam if (!(rt->rt_state & RTS_PASSIVE) && 429021Ssam (supplier || !(rt->rt_state & RTS_INTERFACE))) 439021Ssam rt->rt_timer += TIMER_RATE; 449021Ssam if (rt->rt_timer >= EXPIRE_TIME) 459021Ssam rt->rt_metric = HOPCNT_INFINITY; 469021Ssam if (rt->rt_timer >= GARBAGE_TIME) { 479021Ssam rt = rt->rt_back; 489021Ssam rtdelete(rt->rt_forw); 499021Ssam continue; 509021Ssam } 519021Ssam if (rt->rt_state & RTS_CHANGED) { 529021Ssam rt->rt_state &= ~RTS_CHANGED; 539021Ssam /* don't send extraneous packets */ 549021Ssam if (!supplier || timetobroadcast) 559021Ssam continue; 569021Ssam msg->rip_cmd = RIPCMD_RESPONSE; 57*12726Ssam msg->rip_vers = RIPVERSION; 589021Ssam msg->rip_nets[0].rip_dst = rt->rt_dst; 599021Ssam msg->rip_nets[0].rip_metric = 60*12726Ssam min(rt->rt_metric+1, HOPCNT_INFINITY); 61*12726Ssam #ifdef notyet 62*12726Ssam msg->rip_nets[0].rip_dst.sa_family = 63*12726Ssam htons(msg->rip_nets[0].rip_dst.sa_family); 64*12726Ssam msg->rip_nets[0].rip_metric = 65*12726Ssam htonl(msg->rip_nets[0].rip_metric); 66*12726Ssam #endif 679021Ssam toall(sendmsg); 689021Ssam } 699021Ssam } 709021Ssam } 719021Ssam if (doinghost) { 729021Ssam doinghost = 0; 739021Ssam base = nethash; 749021Ssam goto again; 759021Ssam } 769021Ssam if (timetobroadcast) 779021Ssam toall(supply); 789021Ssam alarm(TIMER_RATE); 799021Ssam } 80