Commit | Line | Data |
---|---|---|
5ff67f98 DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
6 | ||
5919db1b | 7 | #ifndef lint |
4ff053a6 | 8 | static char sccsid[] = "@(#)timer.c 5.3 (Berkeley) %G%"; |
5ff67f98 | 9 | #endif not lint |
5919db1b SL |
10 | |
11 | /* | |
12 | * Routing Table Management Daemon | |
13 | */ | |
7fe7fe74 | 14 | #include "defs.h" |
5919db1b SL |
15 | |
16 | int timeval = -TIMER_RATE; | |
17 | ||
18 | /* | |
19 | * Timer routine. Performs routing information supply | |
20 | * duties and manages timers on routing table entries. | |
21 | */ | |
22 | timer() | |
23 | { | |
24 | register struct rthash *rh; | |
25 | register struct rt_entry *rt; | |
26 | struct rthash *base = hosthash; | |
27 | int doinghost = 1, timetobroadcast; | |
604bfd52 | 28 | extern int externalinterfaces; |
5919db1b SL |
29 | |
30 | timeval += TIMER_RATE; | |
31 | if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0) | |
32 | ifinit(); | |
33 | timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0; | |
34 | again: | |
35 | for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { | |
36 | rt = rh->rt_forw; | |
37 | for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { | |
38 | /* | |
39 | * We don't advance time on a routing entry for | |
4ff053a6 MK |
40 | * a passive gateway, or any interface if we're |
41 | * not acting as supplier. | |
5919db1b SL |
42 | */ |
43 | if (!(rt->rt_state & RTS_PASSIVE) && | |
4ff053a6 | 44 | (supplier || !(rt->rt_state & RTS_INTERFACE))) |
5919db1b SL |
45 | rt->rt_timer += TIMER_RATE; |
46 | if (rt->rt_timer >= EXPIRE_TIME) | |
47 | rt->rt_metric = HOPCNT_INFINITY; | |
48 | if (rt->rt_timer >= GARBAGE_TIME) { | |
49 | rt = rt->rt_back; | |
50 | rtdelete(rt->rt_forw); | |
51 | continue; | |
52 | } | |
53 | if (rt->rt_state & RTS_CHANGED) { | |
54 | rt->rt_state &= ~RTS_CHANGED; | |
55 | /* don't send extraneous packets */ | |
56 | if (!supplier || timetobroadcast) | |
57 | continue; | |
58 | msg->rip_cmd = RIPCMD_RESPONSE; | |
55d340a4 | 59 | msg->rip_vers = RIPVERSION; |
5919db1b | 60 | msg->rip_nets[0].rip_dst = rt->rt_dst; |
55d340a4 SL |
61 | msg->rip_nets[0].rip_dst.sa_family = |
62 | htons(msg->rip_nets[0].rip_dst.sa_family); | |
63 | msg->rip_nets[0].rip_metric = | |
9b1c54bf | 64 | htonl(min(rt->rt_metric+1, HOPCNT_INFINITY)); |
5919db1b SL |
65 | toall(sendmsg); |
66 | } | |
67 | } | |
68 | } | |
69 | if (doinghost) { | |
70 | doinghost = 0; | |
71 | base = nethash; | |
72 | goto again; | |
73 | } | |
74 | if (timetobroadcast) | |
75 | toall(supply); | |
76 | alarm(TIMER_RATE); | |
77 | } | |
b7e4f8be MK |
78 | |
79 | /* | |
80 | * On hangup, let everyone know we're going away. | |
81 | */ | |
82 | hup() | |
83 | { | |
84 | register struct rthash *rh; | |
85 | register struct rt_entry *rt; | |
86 | struct rthash *base = hosthash; | |
87 | int doinghost = 1; | |
88 | ||
89 | if (supplier) { | |
90 | again: | |
91 | for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) { | |
92 | rt = rh->rt_forw; | |
93 | for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) | |
94 | rt->rt_metric = HOPCNT_INFINITY; | |
95 | } | |
96 | if (doinghost) { | |
97 | doinghost = 0; | |
98 | base = nethash; | |
99 | goto again; | |
100 | } | |
101 | toall(supply); | |
102 | } | |
103 | exit(1); | |
104 | } |