Commit | Line | Data |
---|---|---|
5919db1b SL |
1 | #ifndef lint |
2 | static char sccsid[] = "@(#)timer.c 4.1 %G%"; | |
3 | #endif | |
4 | ||
5 | /* | |
6 | * Routing Table Management Daemon | |
7 | */ | |
8 | #include "router.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_nets[0].rip_dst = rt->rt_dst; | |
58 | msg->rip_nets[0].rip_metric = | |
59 | min(rt->rt_metric+1, HOPCNT_INFINITY); | |
60 | toall(sendmsg); | |
61 | } | |
62 | } | |
63 | } | |
64 | if (doinghost) { | |
65 | doinghost = 0; | |
66 | base = nethash; | |
67 | goto again; | |
68 | } | |
69 | if (timetobroadcast) | |
70 | toall(supply); | |
71 | alarm(TIMER_RATE); | |
72 | } |