|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)timer.c 4.4 (Berkeley) 6/1/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_dst.sa_family = ! 60: htons(msg->rip_nets[0].rip_dst.sa_family); ! 61: msg->rip_nets[0].rip_metric = ! 62: htonl(min(rt->rt_metric+1, HOPCNT_INFINITY)); ! 63: toall(sendmsg); ! 64: } ! 65: } ! 66: } ! 67: if (doinghost) { ! 68: doinghost = 0; ! 69: base = nethash; ! 70: goto again; ! 71: } ! 72: if (timetobroadcast) ! 73: toall(supply); ! 74: alarm(TIMER_RATE); ! 75: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.